Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 3 | |
| 4 | #include <console/console.h> |
| 5 | #include <device/device.h> |
| 6 | #include <device/pci.h> |
| 7 | #include <device/pci_ids.h> |
| 8 | #include <device/pci_ops.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 9 | #include <device/mmio.h> |
Vladimir Serbinenko | 75c8387 | 2014-09-05 01:01:31 +0200 | [diff] [blame] | 10 | #include <device/azalia_device.h> |
Elyes HAOUAS | bf0970e | 2019-03-21 11:10:03 +0100 | [diff] [blame] | 11 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 12 | #include "pch.h" |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 13 | #include "hda_verb.h" |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 14 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 15 | static void codecs_init(u8 *base, u32 codec_mask) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 16 | { |
| 17 | int i; |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 18 | |
| 19 | /* Can support up to 4 codecs */ |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 20 | for (i = 3; i >= 0; i--) { |
| 21 | if (codec_mask & (1 << i)) |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 22 | hda_codec_init(base, i, |
| 23 | cim_verb_data_size, |
| 24 | cim_verb_data); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 25 | } |
| 26 | |
Vladimir Serbinenko | 75c8387 | 2014-09-05 01:01:31 +0200 | [diff] [blame] | 27 | if (pc_beep_verbs_size) |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 28 | hda_codec_write(base, pc_beep_verbs_size, pc_beep_verbs); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 29 | } |
| 30 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 31 | static void azalia_pch_init(struct device *dev, u8 *base) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 32 | { |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 33 | u8 reg8; |
| 34 | u16 reg16; |
| 35 | u32 reg32; |
| 36 | |
Ryan Salsamendi | 0d9b360 | 2017-06-30 17:15:57 -0700 | [diff] [blame] | 37 | if (RCBA32(0x2030) & (1UL << 31)) { |
Kyösti Mälkki | 386b3e6 | 2013-07-26 08:52:49 +0300 | [diff] [blame] | 38 | reg32 = pci_read_config32(dev, 0x120); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 39 | reg32 &= 0xf8ffff01; |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 40 | reg32 |= (1 << 25); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 41 | reg32 |= RCBA32(0x2030) & 0xfe; |
Kyösti Mälkki | 386b3e6 | 2013-07-26 08:52:49 +0300 | [diff] [blame] | 42 | pci_write_config32(dev, 0x120, reg32); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 43 | |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 44 | if (!pch_is_lp()) { |
| 45 | reg16 = pci_read_config16(dev, 0x78); |
| 46 | reg16 &= ~(1 << 11); |
| 47 | pci_write_config16(dev, 0x78, reg16); |
| 48 | } |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 49 | } else |
| 50 | printk(BIOS_DEBUG, "Azalia: V1CTL disabled.\n"); |
| 51 | |
Kyösti Mälkki | 386b3e6 | 2013-07-26 08:52:49 +0300 | [diff] [blame] | 52 | reg32 = pci_read_config32(dev, 0x114); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 53 | reg32 &= ~0xfe; |
Kyösti Mälkki | 386b3e6 | 2013-07-26 08:52:49 +0300 | [diff] [blame] | 54 | pci_write_config32(dev, 0x114, reg32); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 55 | |
| 56 | // Set VCi enable bit |
Kyösti Mälkki | 386b3e6 | 2013-07-26 08:52:49 +0300 | [diff] [blame] | 57 | if (pci_read_config32(dev, 0x120) & ((1 << 24) | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 58 | (1 << 25) | (1 << 26))) { |
Kyösti Mälkki | 386b3e6 | 2013-07-26 08:52:49 +0300 | [diff] [blame] | 59 | reg32 = pci_read_config32(dev, 0x120); |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 60 | if (pch_is_lp()) |
Ryan Salsamendi | 0d9b360 | 2017-06-30 17:15:57 -0700 | [diff] [blame] | 61 | reg32 &= ~(1UL << 31); |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 62 | else |
Ryan Salsamendi | 0d9b360 | 2017-06-30 17:15:57 -0700 | [diff] [blame] | 63 | reg32 |= (1UL << 31); |
Kyösti Mälkki | 386b3e6 | 2013-07-26 08:52:49 +0300 | [diff] [blame] | 64 | pci_write_config32(dev, 0x120, reg32); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 65 | } |
| 66 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 67 | reg8 = pci_read_config8(dev, 0x43); |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 68 | if (pch_is_lp()) |
| 69 | reg8 &= ~(1 << 6); |
| 70 | else |
| 71 | reg8 |= (1 << 4); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 72 | pci_write_config8(dev, 0x43, reg8); |
| 73 | |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 74 | if (!pch_is_lp()) { |
| 75 | reg32 = pci_read_config32(dev, 0xc0); |
| 76 | reg32 |= (1 << 17); |
| 77 | pci_write_config32(dev, 0xc0, reg32); |
| 78 | } |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 79 | |
| 80 | /* Additional programming steps */ |
| 81 | reg32 = pci_read_config32(dev, 0xc4); |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 82 | if (pch_is_lp()) |
| 83 | reg32 |= (1 << 24); |
| 84 | else |
| 85 | reg32 |= (1 << 14); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 86 | pci_write_config32(dev, 0xc4, reg32); |
| 87 | |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 88 | if (!pch_is_lp()) { |
| 89 | reg32 = pci_read_config32(dev, 0xd0); |
Ryan Salsamendi | 0d9b360 | 2017-06-30 17:15:57 -0700 | [diff] [blame] | 90 | reg32 &= ~(1UL << 31); |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 91 | pci_write_config32(dev, 0xd0, reg32); |
| 92 | } |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 93 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 94 | reg8 = pci_read_config8(dev, 0x40); // Audio Control |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 95 | reg8 |= 1; // Select Azalia mode |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 96 | pci_write_config8(dev, 0x40, reg8); |
| 97 | |
| 98 | reg8 = pci_read_config8(dev, 0x4d); // Docking Status |
| 99 | reg8 &= ~(1 << 7); // Docking not supported |
| 100 | pci_write_config8(dev, 0x4d, reg8); |
| 101 | |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 102 | if (pch_is_lp()) { |
| 103 | reg16 = read32(base + 0x0012); |
| 104 | reg16 |= (1 << 0); |
| 105 | write32(base + 0x0012, reg16); |
| 106 | |
| 107 | /* disable Auto Voltage Detector */ |
| 108 | reg8 = pci_read_config8(dev, 0x42); |
| 109 | reg8 |= (1 << 2); |
| 110 | pci_write_config8(dev, 0x42, reg8); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | static void azalia_init(struct device *dev) |
| 115 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 116 | u8 *base; |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 117 | struct resource *res; |
| 118 | u32 codec_mask; |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 119 | |
| 120 | /* Find base address */ |
| 121 | res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 122 | if (!res) |
| 123 | return; |
| 124 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 125 | base = res2mmio(res, 0, 0); |
| 126 | printk(BIOS_DEBUG, "Azalia: base = %p\n", base); |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 127 | |
| 128 | /* Set Bus Master */ |
Elyes HAOUAS | 73ae076 | 2020-04-28 10:13:05 +0200 | [diff] [blame^] | 129 | pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER); |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 130 | |
| 131 | azalia_pch_init(dev, base); |
| 132 | |
| 133 | codec_mask = hda_codec_detect(base); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 134 | |
| 135 | if (codec_mask) { |
| 136 | printk(BIOS_DEBUG, "Azalia: codec_mask = %02x\n", codec_mask); |
Duncan Laurie | 0a7c49e | 2013-06-20 12:40:55 -0700 | [diff] [blame] | 137 | codecs_init(base, codec_mask); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 138 | } |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 139 | } |
| 140 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 141 | static struct pci_operations azalia_pci_ops = { |
Subrata Banik | 4a0f071 | 2019-03-20 14:29:47 +0530 | [diff] [blame] | 142 | .set_subsystem = pci_dev_set_subsystem, |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 143 | }; |
| 144 | |
| 145 | static struct device_operations azalia_ops = { |
| 146 | .read_resources = pci_dev_read_resources, |
| 147 | .set_resources = pci_dev_set_resources, |
| 148 | .enable_resources = pci_dev_enable_resources, |
| 149 | .init = azalia_init, |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 150 | .ops_pci = &azalia_pci_ops, |
| 151 | }; |
| 152 | |
Aaron Durbin | ed095ca | 2013-05-20 15:57:16 -0500 | [diff] [blame] | 153 | static const unsigned short pci_device_ids[] = { 0x8c20, 0x9c20, 0 }; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 154 | |
| 155 | static const struct pci_driver pch_azalia __pci_driver = { |
| 156 | .ops = &azalia_ops, |
| 157 | .vendor = PCI_VENDOR_ID_INTEL, |
| 158 | .devices = pci_device_ids, |
| 159 | }; |