Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 2 | |
| 3 | #include <console/console.h> |
| 4 | #include <device/device.h> |
| 5 | #include <device/pci.h> |
| 6 | #include <device/pci_ids.h> |
| 7 | #include <device/pci_ops.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 8 | #include <device/mmio.h> |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 9 | #include <delay.h> |
Vladimir Serbinenko | 75c8387 | 2014-09-05 01:01:31 +0200 | [diff] [blame] | 10 | #include <device/azalia_device.h> |
Kyösti Mälkki | 12b121c | 2019-08-18 16:33:39 +0300 | [diff] [blame] | 11 | #include "chip.h" |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 12 | #include "i82801gx.h" |
| 13 | |
| 14 | #define HDA_ICII_REG 0x68 |
Andrew Wu | ae8d069 | 2013-08-02 19:29:17 +0800 | [diff] [blame] | 15 | #define HDA_ICII_BUSY (1 << 0) |
| 16 | #define HDA_ICII_VALID (1 << 1) |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 17 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 18 | static int set_bits(void *port, u32 mask, u32 val) |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 19 | { |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 20 | u32 reg32; |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 21 | int count; |
| 22 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 23 | /* Write (val & mask) to port */ |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 24 | val &= mask; |
Stefan Reinauer | 9fe4d79 | 2010-01-16 17:53:38 +0000 | [diff] [blame] | 25 | reg32 = read32(port); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 26 | reg32 &= ~mask; |
| 27 | reg32 |= val; |
Stefan Reinauer | 9fe4d79 | 2010-01-16 17:53:38 +0000 | [diff] [blame] | 28 | write32(port, reg32); |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 29 | |
Elyes HAOUAS | 92646ea | 2020-04-04 13:43:03 +0200 | [diff] [blame] | 30 | /* Wait for readback of register to match what was just written to it */ |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 31 | count = 50; |
| 32 | do { |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 33 | /* Wait 1ms based on BKDG wait time */ |
| 34 | mdelay(1); |
Stefan Reinauer | 9fe4d79 | 2010-01-16 17:53:38 +0000 | [diff] [blame] | 35 | reg32 = read32(port); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 36 | reg32 &= mask; |
| 37 | } while ((reg32 != val) && --count); |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 38 | |
Stefan Reinauer | 0a58a7b | 2010-10-10 21:15:01 +0000 | [diff] [blame] | 39 | /* Timeout occurred */ |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 40 | if (!count) |
| 41 | return -1; |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 42 | return 0; |
| 43 | } |
| 44 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 45 | static int codec_detect(u8 *base) |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 46 | { |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 47 | u32 reg32; |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 48 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 49 | /* Set Bit0 to 0 to enter reset state (BAR + 0x8)[0] */ |
Stefan Reinauer | 109ab31 | 2009-08-12 16:08:05 +0000 | [diff] [blame] | 50 | if (set_bits(base + 0x08, 1, 0) == -1) |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 51 | goto no_codec; |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 52 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 53 | /* Set Bit 0 to 1 to exit reset state (BAR + 0x8)[0] */ |
Stefan Reinauer | 109ab31 | 2009-08-12 16:08:05 +0000 | [diff] [blame] | 54 | if (set_bits(base + 0x08, 1, 1) == -1) |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 55 | goto no_codec; |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 56 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 57 | /* Read in Codec location (BAR + 0xe)[2..0]*/ |
Stefan Reinauer | 9fe4d79 | 2010-01-16 17:53:38 +0000 | [diff] [blame] | 58 | reg32 = read32(base + 0xe); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 59 | reg32 &= 0x0f; |
| 60 | if (!reg32) |
| 61 | goto no_codec; |
Stefan Reinauer | 109ab31 | 2009-08-12 16:08:05 +0000 | [diff] [blame] | 62 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 63 | return reg32; |
| 64 | |
| 65 | no_codec: |
| 66 | /* Codec Not found */ |
| 67 | /* Put HDA back in reset (BAR + 0x8) [0] */ |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 68 | set_bits(base + 0x08, 1, 0); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 69 | printk(BIOS_DEBUG, "Azalia: No codec!\n"); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 70 | return 0; |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 71 | } |
| 72 | |
Arthur Heymans | 3f111b0 | 2017-03-09 12:02:52 +0100 | [diff] [blame] | 73 | static u32 find_verb(struct device *dev, u32 viddid, const u32 **verb) |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 74 | { |
Arthur Heymans | 3f111b0 | 2017-03-09 12:02:52 +0100 | [diff] [blame] | 75 | int idx = 0; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 76 | |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 77 | while (idx < (cim_verb_data_size / sizeof(u32))) { |
| 78 | u32 verb_size = 4 * cim_verb_data[idx+2]; // in u32 |
| 79 | if (cim_verb_data[idx] != viddid) { |
| 80 | idx += verb_size + 3; // skip verb + header |
| 81 | continue; |
| 82 | } |
| 83 | *verb = &cim_verb_data[idx+3]; |
| 84 | return verb_size; |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 85 | } |
| 86 | |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 87 | /* Not all codecs need to load another verb */ |
| 88 | return 0; |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | /** |
Stefan Reinauer | 0a58a7b | 2010-10-10 21:15:01 +0000 | [diff] [blame] | 92 | * Wait 50usec for the codec to indicate it is ready |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 93 | * no response would imply that the codec is non-operative |
| 94 | */ |
| 95 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 96 | static int wait_for_ready(u8 *base) |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 97 | { |
Elyes HAOUAS | 92646ea | 2020-04-04 13:43:03 +0200 | [diff] [blame] | 98 | /* Use a 50 usec timeout - the Linux kernel uses the same duration */ |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 99 | int timeout = 50; |
| 100 | |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 101 | while (timeout--) { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 102 | u32 reg32 = read32(base + HDA_ICII_REG); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 103 | if (!(reg32 & HDA_ICII_BUSY)) |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 104 | return 0; |
| 105 | udelay(1); |
| 106 | } |
| 107 | |
| 108 | return -1; |
| 109 | } |
| 110 | |
| 111 | /** |
Elyes HAOUAS | 92646ea | 2020-04-04 13:43:03 +0200 | [diff] [blame] | 112 | * Wait 50usec for the codec to indicate that it accepted the previous command. |
| 113 | * No response would imply that the code is non-operative. |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 114 | */ |
| 115 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 116 | static int wait_for_valid(u8 *base) |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 117 | { |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 118 | u32 reg32; |
| 119 | |
| 120 | /* Send the verb to the codec */ |
Stefan Reinauer | 9fe4d79 | 2010-01-16 17:53:38 +0000 | [diff] [blame] | 121 | reg32 = read32(base + 0x68); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 122 | reg32 |= (1 << 0) | (1 << 1); |
Stefan Reinauer | 9fe4d79 | 2010-01-16 17:53:38 +0000 | [diff] [blame] | 123 | write32(base + 0x68, reg32); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 124 | |
Elyes HAOUAS | 92646ea | 2020-04-04 13:43:03 +0200 | [diff] [blame] | 125 | /* Use a 50 usec timeout - the Linux kernel uses the same duration */ |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 126 | |
| 127 | int timeout = 50; |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 128 | while (timeout--) { |
Stefan Reinauer | 9fe4d79 | 2010-01-16 17:53:38 +0000 | [diff] [blame] | 129 | reg32 = read32(base + HDA_ICII_REG); |
Elyes HAOUAS | 92646ea | 2020-04-04 13:43:03 +0200 | [diff] [blame] | 130 | if ((reg32 & (HDA_ICII_VALID | HDA_ICII_BUSY)) == HDA_ICII_VALID) |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 131 | return 0; |
| 132 | udelay(1); |
| 133 | } |
| 134 | |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 135 | return -1; |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 138 | static void codec_init(struct device *dev, u8 *base, int addr) |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 139 | { |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 140 | u32 reg32; |
Stefan Reinauer | c4f1a77 | 2010-06-05 10:03:08 +0000 | [diff] [blame] | 141 | const u32 *verb; |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 142 | u32 verb_size; |
| 143 | int i; |
| 144 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 145 | printk(BIOS_DEBUG, "Azalia: Initializing codec #%d\n", addr); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 146 | |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 147 | /* 1 */ |
| 148 | if (wait_for_ready(base) == -1) |
| 149 | return; |
| 150 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 151 | reg32 = (addr << 28) | 0x000f0000; |
Stefan Reinauer | 9fe4d79 | 2010-01-16 17:53:38 +0000 | [diff] [blame] | 152 | write32(base + 0x60, reg32); |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 153 | |
| 154 | if (wait_for_valid(base) == -1) |
| 155 | return; |
| 156 | |
Stefan Reinauer | 9fe4d79 | 2010-01-16 17:53:38 +0000 | [diff] [blame] | 157 | reg32 = read32(base + 0x64); |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 158 | |
| 159 | /* 2 */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 160 | printk(BIOS_DEBUG, "Azalia: codec viddid: %08x\n", reg32); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 161 | verb_size = find_verb(dev, reg32, &verb); |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 162 | |
| 163 | if (!verb_size) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 164 | printk(BIOS_DEBUG, "Azalia: No verb!\n"); |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 165 | return; |
| 166 | } |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 167 | printk(BIOS_DEBUG, "Azalia: verb_size: %d\n", verb_size); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 168 | |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 169 | /* 3 */ |
| 170 | for (i = 0; i < verb_size; i++) { |
| 171 | if (wait_for_ready(base) == -1) |
| 172 | return; |
| 173 | |
Stefan Reinauer | 9fe4d79 | 2010-01-16 17:53:38 +0000 | [diff] [blame] | 174 | write32(base + 0x60, verb[i]); |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 175 | |
| 176 | if (wait_for_valid(base) == -1) |
| 177 | return; |
| 178 | } |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 179 | printk(BIOS_DEBUG, "Azalia: verb loaded.\n"); |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 180 | } |
| 181 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 182 | static void codecs_init(struct device *dev, u8 *base, u32 codec_mask) |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 183 | { |
| 184 | int i; |
| 185 | for (i = 2; i >= 0; i--) { |
| 186 | if (codec_mask & (1 << i)) |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 187 | codec_init(dev, base, i); |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 188 | } |
| 189 | } |
| 190 | |
| 191 | static void azalia_init(struct device *dev) |
| 192 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 193 | u8 *base; |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 194 | struct resource *res; |
| 195 | u32 codec_mask; |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 196 | u8 reg8; |
| 197 | u32 reg32; |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 198 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 199 | // ESD |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 200 | reg32 = pci_read_config32(dev, 0x134); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 201 | reg32 &= 0xff00ffff; |
| 202 | reg32 |= (2 << 16); |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 203 | pci_write_config32(dev, 0x134, reg32); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 204 | |
| 205 | // Link1 description |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 206 | reg32 = pci_read_config32(dev, 0x140); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 207 | reg32 &= 0xff00ffff; |
| 208 | reg32 |= (2 << 16); |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 209 | pci_write_config32(dev, 0x140, reg32); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 210 | |
| 211 | // Port VC0 Resource Control Register |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 212 | reg32 = pci_read_config32(dev, 0x114); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 213 | reg32 &= 0xffffff00; |
| 214 | reg32 |= 1; |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 215 | pci_write_config32(dev, 0x114, reg32); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 216 | |
| 217 | // VCi traffic class |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 218 | reg8 = pci_read_config8(dev, 0x44); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 219 | reg8 |= (7 << 0); // TC7 |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 220 | pci_write_config8(dev, 0x44, reg8); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 221 | |
| 222 | // VCi Resource Control |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 223 | reg32 = pci_read_config32(dev, 0x120); |
Stefan Reinauer | 109ab31 | 2009-08-12 16:08:05 +0000 | [diff] [blame] | 224 | reg32 |= (1 << 31); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 225 | reg32 |= (1 << 24); // VCi ID |
| 226 | reg32 |= (0x80 << 0); // VCi map |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 227 | pci_write_config32(dev, 0x120, reg32); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 228 | |
| 229 | /* Set Bus Master */ |
Elyes HAOUAS | 1234925 | 2020-04-27 05:08:26 +0200 | [diff] [blame] | 230 | pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 231 | |
| 232 | pci_write_config8(dev, 0x3c, 0x0a); // unused? |
| 233 | |
| 234 | // TODO Actually check if we're AC97 or HDA instead of hardcoding this |
Stefan Reinauer | 38f147e | 2010-02-08 12:20:50 +0000 | [diff] [blame] | 235 | // here, in devicetree.cb and/or romstage.c. |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 236 | reg8 = pci_read_config8(dev, 0x40); |
| 237 | reg8 |= (1 << 3); // Clear Clock Detect Bit |
| 238 | pci_write_config8(dev, 0x40, reg8); |
| 239 | reg8 &= ~(1 << 3); // Keep CLKDETCLR from clearing the bit over and over |
| 240 | pci_write_config8(dev, 0x40, reg8); |
| 241 | reg8 |= (1 << 2); // Enable clock detection |
| 242 | pci_write_config8(dev, 0x40, reg8); |
| 243 | mdelay(1); |
| 244 | reg8 = pci_read_config8(dev, 0x40); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 245 | printk(BIOS_DEBUG, "Azalia: codec type: %s\n", (reg8 & (1 << 1))?"Azalia":"AC97"); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 246 | |
| 247 | // |
| 248 | reg8 = pci_read_config8(dev, 0x40); // Audio Control |
Stefan Reinauer | 38f147e | 2010-02-08 12:20:50 +0000 | [diff] [blame] | 249 | reg8 |= 1; // Select Azalia mode. This needs to be controlled via devicetree.cb |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 250 | pci_write_config8(dev, 0x40, reg8); |
| 251 | |
| 252 | reg8 = pci_read_config8(dev, 0x4d); // Docking Status |
| 253 | reg8 &= ~(1 << 7); // Docking not supported |
| 254 | pci_write_config8(dev, 0x4d, reg8); |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 255 | |
| 256 | res = find_resource(dev, 0x10); |
| 257 | if (!res) |
| 258 | return; |
| 259 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 260 | // NOTE this will break as soon as the Azalia get's a bar above |
| 261 | // 4G. Is there anything we can do about it? |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 262 | base = res2mmio(res, 0, 0); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 263 | printk(BIOS_DEBUG, "Azalia: base = %08x\n", (u32)base); |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 264 | codec_mask = codec_detect(base); |
| 265 | |
| 266 | if (codec_mask) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 267 | printk(BIOS_DEBUG, "Azalia: codec_mask = %02x\n", codec_mask); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 268 | codecs_init(dev, base, codec_mask); |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 269 | } |
| 270 | } |
| 271 | |
| 272 | static struct device_operations azalia_ops = { |
| 273 | .read_resources = pci_dev_read_resources, |
| 274 | .set_resources = pci_dev_set_resources, |
| 275 | .enable_resources = pci_dev_enable_resources, |
| 276 | .init = azalia_init, |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 277 | .enable = i82801gx_enable, |
Angel Pons | 1fc0edd | 2020-05-31 00:03:28 +0200 | [diff] [blame] | 278 | .ops_pci = &pci_dev_ops_pci, |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 279 | }; |
| 280 | |
| 281 | /* 82801GB/GR/GDH/GBM/GHM (ICH7/ICH7R/ICH7DH/ICH7-M/ICH7-M DH) */ |
| 282 | static const struct pci_driver i82801gx_azalia __pci_driver = { |
| 283 | .ops = &azalia_ops, |
| 284 | .vendor = PCI_VENDOR_ID_INTEL, |
| 285 | .device = 0x27d8, |
| 286 | }; |