Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2008 Advanced Micro Devices, Inc. |
| 5 | * Copyright (C) 2008-2009 coresystems GmbH |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
Paul Menzel | a46a712 | 2013-02-23 18:37:27 +0100 | [diff] [blame] | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #include <console/console.h> |
| 22 | #include <device/device.h> |
| 23 | #include <device/pci.h> |
| 24 | #include <device/pci_ids.h> |
| 25 | #include <device/pci_ops.h> |
| 26 | #include <arch/io.h> |
| 27 | #include <delay.h> |
| 28 | #include "i82801gx.h" |
| 29 | |
| 30 | #define HDA_ICII_REG 0x68 |
Andrew Wu | ae8d069 | 2013-08-02 19:29:17 +0800 | [diff] [blame] | 31 | #define HDA_ICII_BUSY (1 << 0) |
| 32 | #define HDA_ICII_VALID (1 << 1) |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 33 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 34 | typedef struct southbridge_intel_i82801gx_config config_t; |
| 35 | |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 36 | static int set_bits(u32 port, u32 mask, u32 val) |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 37 | { |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 38 | u32 reg32; |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 39 | int count; |
| 40 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 41 | /* Write (val & mask) to port */ |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 42 | val &= mask; |
Stefan Reinauer | 9fe4d79 | 2010-01-16 17:53:38 +0000 | [diff] [blame] | 43 | reg32 = read32(port); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 44 | reg32 &= ~mask; |
| 45 | reg32 |= val; |
Stefan Reinauer | 9fe4d79 | 2010-01-16 17:53:38 +0000 | [diff] [blame] | 46 | write32(port, reg32); |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 47 | |
Stefan Reinauer | 109ab31 | 2009-08-12 16:08:05 +0000 | [diff] [blame] | 48 | /* Wait for readback of register to |
| 49 | * match what was just written to it |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 50 | */ |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 51 | count = 50; |
| 52 | do { |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 53 | /* Wait 1ms based on BKDG wait time */ |
| 54 | mdelay(1); |
Stefan Reinauer | 9fe4d79 | 2010-01-16 17:53:38 +0000 | [diff] [blame] | 55 | reg32 = read32(port); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 56 | reg32 &= mask; |
| 57 | } while ((reg32 != val) && --count); |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 58 | |
Stefan Reinauer | 0a58a7b | 2010-10-10 21:15:01 +0000 | [diff] [blame] | 59 | /* Timeout occurred */ |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 60 | if (!count) |
| 61 | return -1; |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 62 | return 0; |
| 63 | } |
| 64 | |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 65 | static int codec_detect(u32 base) |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 66 | { |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 67 | u32 reg32; |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 68 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 69 | /* Set Bit0 to 0 to enter reset state (BAR + 0x8)[0] */ |
Stefan Reinauer | 109ab31 | 2009-08-12 16:08:05 +0000 | [diff] [blame] | 70 | if (set_bits(base + 0x08, 1, 0) == -1) |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 71 | goto no_codec; |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 72 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 73 | /* Set Bit 0 to 1 to exit reset state (BAR + 0x8)[0] */ |
Stefan Reinauer | 109ab31 | 2009-08-12 16:08:05 +0000 | [diff] [blame] | 74 | if (set_bits(base + 0x08, 1, 1) == -1) |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 75 | goto no_codec; |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 76 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 77 | /* Read in Codec location (BAR + 0xe)[2..0]*/ |
Stefan Reinauer | 9fe4d79 | 2010-01-16 17:53:38 +0000 | [diff] [blame] | 78 | reg32 = read32(base + 0xe); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 79 | reg32 &= 0x0f; |
| 80 | if (!reg32) |
| 81 | goto no_codec; |
Stefan Reinauer | 109ab31 | 2009-08-12 16:08:05 +0000 | [diff] [blame] | 82 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 83 | return reg32; |
| 84 | |
| 85 | no_codec: |
| 86 | /* Codec Not found */ |
| 87 | /* Put HDA back in reset (BAR + 0x8) [0] */ |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 88 | set_bits(base + 0x08, 1, 0); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 89 | printk(BIOS_DEBUG, "Azalia: No codec!\n"); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 90 | return 0; |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 91 | } |
| 92 | |
Stefan Reinauer | c4f1a77 | 2010-06-05 10:03:08 +0000 | [diff] [blame] | 93 | const u32 * cim_verb_data = NULL; |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 94 | u32 cim_verb_data_size = 0; |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 95 | |
Stefan Reinauer | c4f1a77 | 2010-06-05 10:03:08 +0000 | [diff] [blame] | 96 | static u32 find_verb(struct device *dev, u32 viddid, const u32 ** verb) |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 97 | { |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 98 | int idx=0; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 99 | |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 100 | while (idx < (cim_verb_data_size / sizeof(u32))) { |
| 101 | u32 verb_size = 4 * cim_verb_data[idx+2]; // in u32 |
| 102 | if (cim_verb_data[idx] != viddid) { |
| 103 | idx += verb_size + 3; // skip verb + header |
| 104 | continue; |
| 105 | } |
| 106 | *verb = &cim_verb_data[idx+3]; |
| 107 | return verb_size; |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 108 | } |
| 109 | |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 110 | /* Not all codecs need to load another verb */ |
| 111 | return 0; |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | /** |
Stefan Reinauer | 0a58a7b | 2010-10-10 21:15:01 +0000 | [diff] [blame] | 115 | * Wait 50usec for the codec to indicate it is ready |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 116 | * no response would imply that the codec is non-operative |
| 117 | */ |
| 118 | |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 119 | static int wait_for_ready(u32 base) |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 120 | { |
| 121 | /* Use a 50 usec timeout - the Linux kernel uses the |
| 122 | * same duration */ |
| 123 | |
| 124 | int timeout = 50; |
| 125 | |
| 126 | while(timeout--) { |
Stefan Reinauer | 9fe4d79 | 2010-01-16 17:53:38 +0000 | [diff] [blame] | 127 | u32 reg32 = read32(base + HDA_ICII_REG); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 128 | if (!(reg32 & HDA_ICII_BUSY)) |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 129 | return 0; |
| 130 | udelay(1); |
| 131 | } |
| 132 | |
| 133 | return -1; |
| 134 | } |
| 135 | |
| 136 | /** |
Stefan Reinauer | 0a58a7b | 2010-10-10 21:15:01 +0000 | [diff] [blame] | 137 | * Wait 50usec for the codec to indicate that it accepted |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 138 | * the previous command. No response would imply that the code |
| 139 | * is non-operative |
| 140 | */ |
| 141 | |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 142 | static int wait_for_valid(u32 base) |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 143 | { |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 144 | u32 reg32; |
| 145 | |
| 146 | /* Send the verb to the codec */ |
Stefan Reinauer | 9fe4d79 | 2010-01-16 17:53:38 +0000 | [diff] [blame] | 147 | reg32 = read32(base + 0x68); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 148 | reg32 |= (1 << 0) | (1 << 1); |
Stefan Reinauer | 9fe4d79 | 2010-01-16 17:53:38 +0000 | [diff] [blame] | 149 | write32(base + 0x68, reg32); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 150 | |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 151 | /* Use a 50 usec timeout - the Linux kernel uses the |
| 152 | * same duration */ |
| 153 | |
| 154 | int timeout = 50; |
| 155 | while(timeout--) { |
Stefan Reinauer | 9fe4d79 | 2010-01-16 17:53:38 +0000 | [diff] [blame] | 156 | reg32 = read32(base + HDA_ICII_REG); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 157 | if ((reg32 & (HDA_ICII_VALID | HDA_ICII_BUSY)) == |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 158 | HDA_ICII_VALID) |
| 159 | return 0; |
| 160 | udelay(1); |
| 161 | } |
| 162 | |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 163 | return -1; |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 164 | } |
| 165 | |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 166 | static void codec_init(struct device *dev, u32 base, int addr) |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 167 | { |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 168 | u32 reg32; |
Stefan Reinauer | c4f1a77 | 2010-06-05 10:03:08 +0000 | [diff] [blame] | 169 | const u32 *verb; |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 170 | u32 verb_size; |
| 171 | int i; |
| 172 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 173 | printk(BIOS_DEBUG, "Azalia: Initializing codec #%d\n", addr); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 174 | |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 175 | /* 1 */ |
| 176 | if (wait_for_ready(base) == -1) |
| 177 | return; |
| 178 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 179 | reg32 = (addr << 28) | 0x000f0000; |
Stefan Reinauer | 9fe4d79 | 2010-01-16 17:53:38 +0000 | [diff] [blame] | 180 | write32(base + 0x60, reg32); |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 181 | |
| 182 | if (wait_for_valid(base) == -1) |
| 183 | return; |
| 184 | |
Stefan Reinauer | 9fe4d79 | 2010-01-16 17:53:38 +0000 | [diff] [blame] | 185 | reg32 = read32(base + 0x64); |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 186 | |
| 187 | /* 2 */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 188 | printk(BIOS_DEBUG, "Azalia: codec viddid: %08x\n", reg32); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 189 | verb_size = find_verb(dev, reg32, &verb); |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 190 | |
| 191 | if (!verb_size) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 192 | printk(BIOS_DEBUG, "Azalia: No verb!\n"); |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 193 | return; |
| 194 | } |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 195 | printk(BIOS_DEBUG, "Azalia: verb_size: %d\n", verb_size); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 196 | |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 197 | /* 3 */ |
| 198 | for (i = 0; i < verb_size; i++) { |
| 199 | if (wait_for_ready(base) == -1) |
| 200 | return; |
| 201 | |
Stefan Reinauer | 9fe4d79 | 2010-01-16 17:53:38 +0000 | [diff] [blame] | 202 | write32(base + 0x60, verb[i]); |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 203 | |
| 204 | if (wait_for_valid(base) == -1) |
| 205 | return; |
| 206 | } |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 207 | printk(BIOS_DEBUG, "Azalia: verb loaded.\n"); |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 208 | } |
| 209 | |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 210 | static void codecs_init(struct device *dev, u32 base, u32 codec_mask) |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 211 | { |
| 212 | int i; |
| 213 | for (i = 2; i >= 0; i--) { |
| 214 | if (codec_mask & (1 << i)) |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 215 | codec_init(dev, base, i); |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 216 | } |
| 217 | } |
| 218 | |
| 219 | static void azalia_init(struct device *dev) |
| 220 | { |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 221 | u32 base; |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 222 | struct resource *res; |
| 223 | u32 codec_mask; |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 224 | u8 reg8; |
| 225 | u32 reg32; |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 226 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 227 | // ESD |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 228 | reg32 = pci_read_config32(dev, 0x134); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 229 | reg32 &= 0xff00ffff; |
| 230 | reg32 |= (2 << 16); |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 231 | pci_write_config32(dev, 0x134, reg32); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 232 | |
| 233 | // Link1 description |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 234 | reg32 = pci_read_config32(dev, 0x140); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 235 | reg32 &= 0xff00ffff; |
| 236 | reg32 |= (2 << 16); |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 237 | pci_write_config32(dev, 0x140, reg32); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 238 | |
| 239 | // Port VC0 Resource Control Register |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 240 | reg32 = pci_read_config32(dev, 0x114); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 241 | reg32 &= 0xffffff00; |
| 242 | reg32 |= 1; |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 243 | pci_write_config32(dev, 0x114, reg32); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 244 | |
| 245 | // VCi traffic class |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 246 | reg8 = pci_read_config8(dev, 0x44); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 247 | reg8 |= (7 << 0); // TC7 |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 248 | pci_write_config8(dev, 0x44, reg8); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 249 | |
| 250 | // VCi Resource Control |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 251 | reg32 = pci_read_config32(dev, 0x120); |
Stefan Reinauer | 109ab31 | 2009-08-12 16:08:05 +0000 | [diff] [blame] | 252 | reg32 |= (1 << 31); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 253 | reg32 |= (1 << 24); // VCi ID |
| 254 | reg32 |= (0x80 << 0); // VCi map |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 255 | pci_write_config32(dev, 0x120, reg32); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 256 | |
| 257 | /* Set Bus Master */ |
| 258 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 259 | pci_write_config32(dev, PCI_COMMAND, reg32 | PCI_COMMAND_MASTER); |
| 260 | |
| 261 | pci_write_config8(dev, 0x3c, 0x0a); // unused? |
| 262 | |
| 263 | // 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] | 264 | // here, in devicetree.cb and/or romstage.c. |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 265 | reg8 = pci_read_config8(dev, 0x40); |
| 266 | reg8 |= (1 << 3); // Clear Clock Detect Bit |
| 267 | pci_write_config8(dev, 0x40, reg8); |
| 268 | reg8 &= ~(1 << 3); // Keep CLKDETCLR from clearing the bit over and over |
| 269 | pci_write_config8(dev, 0x40, reg8); |
| 270 | reg8 |= (1 << 2); // Enable clock detection |
| 271 | pci_write_config8(dev, 0x40, reg8); |
| 272 | mdelay(1); |
| 273 | reg8 = pci_read_config8(dev, 0x40); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 274 | 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] | 275 | |
| 276 | // |
| 277 | reg8 = pci_read_config8(dev, 0x40); // Audio Control |
Stefan Reinauer | 38f147e | 2010-02-08 12:20:50 +0000 | [diff] [blame] | 278 | 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] | 279 | pci_write_config8(dev, 0x40, reg8); |
| 280 | |
| 281 | reg8 = pci_read_config8(dev, 0x4d); // Docking Status |
| 282 | reg8 &= ~(1 << 7); // Docking not supported |
| 283 | pci_write_config8(dev, 0x4d, reg8); |
| 284 | #if 0 |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 285 | /* Set routing pin */ |
| 286 | pci_write_config32(dev, 0xf8, 0x0); |
| 287 | pci_write_config8(dev, 0xfc, 0xAA); |
| 288 | |
| 289 | /* Set INTA */ |
| 290 | pci_write_config8(dev, 0x63, 0x0); |
| 291 | |
| 292 | /* Enable azalia, disable ac97 */ |
| 293 | // pm_iowrite(0x59, 0xB); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 294 | #endif |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 295 | |
| 296 | res = find_resource(dev, 0x10); |
| 297 | if (!res) |
| 298 | return; |
| 299 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 300 | // NOTE this will break as soon as the Azalia get's a bar above |
| 301 | // 4G. Is there anything we can do about it? |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 302 | base = (u32)res->base; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 303 | printk(BIOS_DEBUG, "Azalia: base = %08x\n", (u32)base); |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 304 | codec_mask = codec_detect(base); |
| 305 | |
| 306 | if (codec_mask) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 307 | printk(BIOS_DEBUG, "Azalia: codec_mask = %02x\n", codec_mask); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 308 | codecs_init(dev, base, codec_mask); |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 309 | } |
| 310 | } |
| 311 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 312 | static void azalia_set_subsystem(device_t dev, unsigned vendor, unsigned device) |
| 313 | { |
| 314 | if (!vendor || !device) { |
| 315 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 316 | pci_read_config32(dev, PCI_VENDOR_ID)); |
| 317 | } else { |
| 318 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 319 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | static struct pci_operations azalia_pci_ops = { |
| 324 | .set_subsystem = azalia_set_subsystem, |
| 325 | }; |
| 326 | |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 327 | static struct device_operations azalia_ops = { |
| 328 | .read_resources = pci_dev_read_resources, |
| 329 | .set_resources = pci_dev_set_resources, |
| 330 | .enable_resources = pci_dev_enable_resources, |
| 331 | .init = azalia_init, |
| 332 | .scan_bus = 0, |
| 333 | .enable = i82801gx_enable, |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 334 | .ops_pci = &azalia_pci_ops, |
Stefan Reinauer | 679c9f9 | 2009-01-20 22:54:59 +0000 | [diff] [blame] | 335 | }; |
| 336 | |
| 337 | /* 82801GB/GR/GDH/GBM/GHM (ICH7/ICH7R/ICH7DH/ICH7-M/ICH7-M DH) */ |
| 338 | static const struct pci_driver i82801gx_azalia __pci_driver = { |
| 339 | .ops = &azalia_ops, |
| 340 | .vendor = PCI_VENDOR_ID_INTEL, |
| 341 | .device = 0x27d8, |
| 342 | }; |