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