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