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
20 #include <console/console.h>
21 #include <device/device.h>
22 #include <device/pci.h>
23 #include <device/pci_ids.h>
24 #include <device/pci_ops.h>
29 static int set_bits(u8 * port, u32 mask, u32 val)
45 } while ((dword != val) && --count);
54 static int codec_detect(u8 * base)
59 set_bits(base + 0x08, 1, 1);
62 dword = readl(base + 0x0e);
64 writel(dword, base + 0x0e);
67 set_bits(base + 0x08, 1, 0);
70 set_bits(base + 0x08, 1, 1);
73 dword = readl(base + 0xe);
78 set_bits(base + 0x08, 1, 0);
79 printk_debug("No codec!\n");
86 static u32 cim_verb_data[] = {
147 static unsigned find_verb(u32 viddid, u32 ** verb)
149 device_t azalia_dev = dev_find_slot(0, PCI_DEVFN(0x14, 2));
150 struct southbridge_amd_sb600_config *cfg =
151 (struct southbridge_amd_sb600_config *)azalia_dev->chip_info;
152 printk_debug("Dev=%s\n", dev_path(azalia_dev));
153 printk_debug("Default viddid=%x\n", cfg->hda_viddid);
154 printk_debug("Reading viddid=%x\n", viddid);
157 if (viddid != cfg->hda_viddid)
159 *verb = (u32 *) cim_verb_data;
160 return sizeof(cim_verb_data) / sizeof(u32);
163 static void codec_init(u8 * base, int addr)
172 dword = readl(base + 0x68);
175 dword = (addr << 28) | 0x000f0000;
176 writel(dword, base + 0x60);
179 dword = readl(base + 0x68);
180 } while ((dword & 3) != 2);
182 dword = readl(base + 0x64);
185 printk_debug("codec viddid: %08x\n", dword);
186 verb_size = find_verb(dword, &verb);
189 printk_debug("No verb!\n");
193 printk_debug("verb_size: %d\n", verb_size);
195 for (i = 0; i < verb_size; i++) {
197 dword = readl(base + 0x68);
200 writel(verb[i], base + 0x60);
203 dword = readl(base + 0x68);
204 } while ((dword & 3) != 2);
206 printk_debug("verb loaded!\n");
209 static void codecs_init(u8 * base, u32 codec_mask)
212 for (i = 2; i >= 0; i--) {
213 if (codec_mask & (1 << i))
218 static void hda_init(struct device *dev)
221 struct resource *res;
226 hda_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0));
227 /* Set routing pin */
228 pci_write_config32(dev, 0xf8, 0x0);
229 pci_write_config8(dev, 0xfc, 0xAA);
231 pci_write_config8(dev, 0x63, 0x0);
232 /* Enable azalia, disable ac97 */
233 pm_iowrite(0x59, 0xB);
235 res = find_resource(dev, 0x10);
239 base = (u8 *) ((u32)res->base);
240 printk_debug("base = %08x\n", base);
241 codec_mask = codec_detect(base);
244 printk_debug("codec_mask = %02x\n", codec_mask);
245 codecs_init(base, codec_mask);
249 static struct pci_operations lops_pci = {
250 .set_subsystem = pci_dev_set_subsystem,
253 static struct device_operations hda_audio_ops = {
254 .read_resources = pci_dev_read_resources,
255 .set_resources = pci_dev_set_resources,
256 .enable_resources = pci_dev_enable_resources,
257 /*.enable = sb600_enable, */
260 .ops_pci = &lops_pci,
263 static struct pci_driver hdaaudio_driver __pci_driver = {
264 .ops = &hda_audio_ops,
265 .vendor = PCI_VENDOR_ID_ATI,
266 .device = PCI_DEVICE_ID_ATI_SB600_HDA,