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