2 * This file is part of the coreboot project.
4 * Copyright (C) 2008 Advanced Micro Devices, Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <device/pci.h>
26 #include <device/pci_ids.h>
27 #include <statictree.h>
31 static int set_bits(u8 * port, u32 mask, u32 val)
47 } while ((dword != val) && --count);
56 static int codec_detect(u8 * base)
61 set_bits(base + 0x08, 1, 1);
64 dword = readl(base + 0x0e);
66 writel(dword, base + 0x0e);
69 set_bits(base + 0x08, 1, 0);
72 set_bits(base + 0x08, 1, 1);
75 dword = readl(base + 0xe);
80 set_bits(base + 0x08, 1, 0);
81 printk(BIOS_DEBUG, "No codec!\n");
88 static u32 cim_verb_data[] = {
149 static unsigned find_verb(u32 viddid, u32 ** verb)
151 struct device * azalia_dev = dev_find_slot(0, PCI_DEVFN(0x14, 2));
152 struct southbridge_amd_sb600_dts_config *cfg =
153 (struct southbridge_amd_sb600_config *)azalia_dev->chip_info;
154 printk(BIOS_DEBUG, "Dev=%s\n", dev_path(azalia_dev));
155 printk(BIOS_DEBUG, "Default viddid=%x\n", cfg->hda_viddid);
156 printk(BIOS_DEBUG, "Reading viddid=%x\n", viddid);
159 if (viddid != cfg->hda_viddid)
161 *verb = (u32 *) cim_verb_data;
162 return sizeof(cim_verb_data) / sizeof(u32);
165 static void codec_init(u8 * base, int addr)
174 dword = readl(base + 0x68);
177 dword = (addr << 28) | 0x000f0000;
178 writel(dword, base + 0x60);
181 dword = readl(base + 0x68);
182 } while ((dword & 3) != 2);
184 dword = readl(base + 0x64);
187 printk(BIOS_DEBUG, "codec viddid: %08x\n", dword);
188 verb_size = find_verb(dword, &verb);
191 printk(BIOS_DEBUG, "No verb!\n");
195 printk(BIOS_DEBUG, "verb_size: %d\n", verb_size);
197 for (i = 0; i < verb_size; i++) {
199 dword = readl(base + 0x68);
202 writel(verb[i], base + 0x60);
205 dword = readl(base + 0x68);
206 } while ((dword & 3) != 2);
208 printk(BIOS_DEBUG, "verb loaded!\n");
211 static void codecs_init(u8 * base, u32 codec_mask)
214 for (i = 2; i >= 0; i--) {
215 if (codec_mask & (1 << i))
220 static void hda_init(struct device *dev)
223 struct resource *res;
227 struct device * hda_dev;
228 hda_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0));
229 /* Set routing pin */
230 pci_write_config32(dev, 0xf8, 0x0);
231 pci_write_config8(dev, 0xfc, 0xAA);
233 pci_write_config8(dev, 0x63, 0x0);
234 /* Enable azalia, disable ac97 */
235 pm_iowrite(0x59, 0xB);
237 res = find_resource(dev, 0x10);
241 base = (u8 *) ((u32)res->base);
242 printk(BIOS_DEBUG, "base = %08x\n", base);
243 codec_mask = codec_detect(base);
246 printk(BIOS_DEBUG, "codec_mask = %02x\n", codec_mask);
247 codecs_init(base, codec_mask);
251 static struct pci_operations lops_pci = {
252 .set_subsystem = pci_dev_set_subsystem,
255 struct device_operations sb600_hda = {
256 .id = {.type = DEVICE_ID_PCI,
257 {.pci = {.vendor = PCI_VENDOR_ID_ATI,
258 .device = PCI_DEVICE_ID_ATI_SB600_HDA}}},
259 .constructor = default_device_constructor,
260 .phase4_read_resources = pci_dev_read_resources,
261 .phase4_set_resources = pci_dev_set_resources,
262 .phase5_enable_resources = pci_dev_enable_resources,
263 .phase6_init = hda_init,