2 * This file is part of the coreboot project.
4 * Copyright (C) 2004 Tyan Computer
5 * Written by Yinghai Lu <yhlu@tyan.com> for Tyan Computer.
6 * Copyright (C) 2006,2007 AMD
7 * Written by Yinghai Lu <yinghai.lu@amd.com> for AMD.
8 * Copyright (C) 2007 Silicon Integrated Systems Corp. (SiS)
9 * Written by Morgan Tsai <my_tsai@sis.com> for SiS.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #include <console/console.h>
27 #include <device/device.h>
28 #include <device/pci.h>
29 #include <device/pci_ids.h>
30 #include <device/pci_ops.h>
35 u8 SiS_SiS7502_init[7][3]={
42 {0x00, 0x00, 0x00} //End of table
45 static int set_bits(u32 port, u32 mask, u32 val)
61 } while ((dword != val) && --count);
70 static u32 send_verb(u32 base, u32 verb)
74 dword = read32(base + 0x68);
75 dword=dword|(unsigned long)0x0002;
76 write32(base + 0x68, dword);
78 dword = read32(base + 0x68);
79 } while ((dword & 1)!=0);
80 write32(base + 0x60, verb);
82 dword = read32(base + 0x68);
84 write32(base + 0x68, dword);
87 dword = read32(base + 0x68);
88 } while ((dword & 3) != 2);
90 dword = read32(base + 0x64);
95 static int codec_detect(u32 base)
100 /* 1 */ // controller reset
101 printk(BIOS_DEBUG, "controller reset\n");
103 set_bits(base + 0x08, 1, 1);
106 dword = read32(base + 0x08)&0x1;
107 if(idx++>1000) { printk(BIOS_DEBUG, "controller reset fail !!! \n"); break;}
110 dword=send_verb(base,0x000F0000); // get codec VendorId and DeviceId
113 printk(BIOS_DEBUG, "No codec!\n");
117 printk(BIOS_DEBUG, "Codec ID = %x\n", dword);
125 static u32 verb_data[] = {
189 static unsigned find_verb(u32 viddid, u32 **verb)
191 if((viddid == 0x10ec0883) || (viddid == 0x10ec0882) || (viddid == 0x10ec0880)) return 0;
192 *verb = (u32 *)verb_data;
193 return sizeof(verb_data)/sizeof(u32);
197 static void codec_init(u32 base, int addr)
206 dword = read32(base + 0x68);
209 dword = (addr<<28) | 0x000f0000;
210 write32(base + 0x60, dword);
213 dword = read32(base + 0x68);
214 } while ((dword & 3)!=2);
216 dword = read32(base + 0x64);
219 printk(BIOS_DEBUG, "codec viddid: %08x\n", dword);
220 verb_size = find_verb(dword, &verb);
223 printk(BIOS_DEBUG, "No verb!\n");
227 printk(BIOS_DEBUG, "verb_size: %d\n", verb_size);
229 for(i=0; i<verb_size; i++) {
230 send_verb(base,verb[i]);
232 printk(BIOS_DEBUG, "verb loaded!\n");
235 static void codecs_init(u32 base, u32 codec_mask)
241 static void aza_init(struct device *dev)
244 struct resource *res;
247 print_debug("AZALIA_INIT:---------->\n");
249 //-------------- enable AZA (SiS7502) -------------------------
253 while(SiS_SiS7502_init[i][0] != 0)
255 temp8 = pci_read_config8(dev, SiS_SiS7502_init[i][0]);
256 temp8 &= SiS_SiS7502_init[i][1];
257 temp8 |= SiS_SiS7502_init[i][2];
258 pci_write_config8(dev, SiS_SiS7502_init[i][0], temp8);
262 //-----------------------------------------------------------
265 // put audio to D0 state
266 pci_write_config8(dev, 0x54,0x00);
272 print_debug("****** Azalia PCI config ******");
273 print_debug("\n 03020100 07060504 0B0A0908 0F0E0D0C");
275 for(i=0;i<0xff;i+=4){
281 print_debug_hex32(pci_read_config32(dev,i));
288 res = find_resource(dev, 0x10);
293 printk(BIOS_DEBUG, "base = 0x%08x\n", base);
295 codec_mask = codec_detect(base);
298 printk(BIOS_DEBUG, "codec_mask = %02x\n", codec_mask);
299 codecs_init(base, codec_mask);
302 print_debug("AZALIA_INIT:<----------\n");
305 static void lpci_set_subsystem(device_t dev, unsigned vendor, unsigned device)
307 pci_write_config32(dev, 0x40,
308 ((device & 0xffff) << 16) | (vendor & 0xffff));
311 static struct pci_operations lops_pci = {
312 .set_subsystem = lpci_set_subsystem,
315 static struct device_operations aza_audio_ops = {
316 .read_resources = pci_dev_read_resources,
317 .set_resources = pci_dev_set_resources,
318 .enable_resources = pci_dev_enable_resources,
319 // .enable = sis966_enable,
322 .ops_pci = &lops_pci,
325 static const struct pci_driver azaaudio_driver __pci_driver = {
326 .ops = &aza_audio_ops,
327 .vendor = PCI_VENDOR_ID_SIS,
328 .device = PCI_DEVICE_ID_SIS_SIS966_HD_AUDIO,