2 * This file is part of the LinuxBIOS 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>
34 uint8_t SiS_SiS7502_init[7][3]={
41 {0x00, 0x00, 0x00} //End of table
44 static int set_bits(uint8_t *port, uint32_t mask, uint32_t val)
60 } while ((dword != val) && --count);
69 uint32_t send_verb(uint8_t *base, uint32_t verb)
75 dword = readl(base + 0x68);
76 dword=dword|(unsigned long)0x0002;
77 writel(dword,base + 0x68);
79 dword = readl(base + 0x68);
80 } while ((dword & 1)!=0);
81 writel(verb, base + 0x60);
83 dword = readl(base + 0x68);
85 writel(dword, base + 0x68);
88 dword = readl(base + 0x68);
89 } while ((dword & 3) != 2);
91 dword = readl(base + 0x64);
97 static int codec_detect(uint8_t *base)
102 /* 1 */ // controller reset
103 printk_debug("controller reset\n");
105 set_bits(base + 0x08, 1, 1);
108 dword = readl(base + 0x08)&0x1;
109 if(idx++>1000) { printk_debug("controller reset fail !!! \n"); break;}
112 dword=send_verb(base,0x000F0000); // get codec VendorId and DeviceId
115 printk_debug("No codec!\n");
119 printk_debug("Codec ID = %lx\n", dword);
127 static uint32_t verb_data[] = {
191 static unsigned find_verb(uint32_t viddid, uint32_t **verb)
193 if((viddid == 0x10ec0883) || (viddid == 0x10ec0882) || (viddid == 0x10ec0880)) return 0;
194 *verb = (uint32_t *)verb_data;
195 return sizeof(verb_data)/sizeof(uint32_t);
199 static void codec_init(uint8_t *base, int addr)
208 dword = readl(base + 0x68);
211 dword = (addr<<28) | 0x000f0000;
212 writel(dword, base + 0x60);
215 dword = readl(base + 0x68);
216 } while ((dword & 3)!=2);
218 dword = readl(base + 0x64);
221 printk_debug("codec viddid: %08x\n", dword);
222 verb_size = find_verb(dword, &verb);
225 printk_debug("No verb!\n");
229 printk_debug("verb_size: %d\n", verb_size);
231 for(i=0; i<verb_size; i++) {
232 send_verb(base,verb[i]);
234 printk_debug("verb loaded!\n");
237 static void codecs_init(uint8_t *base, uint32_t codec_mask)
242 for(i=2; i>=0; i--) {
243 if( codec_mask & (1<<i) )
248 static void aza_init(struct device *dev)
251 struct resource *res;
254 print_debug("AZALIA_INIT:---------->\n");
256 //-------------- enable AZA (SiS7502) -------------------------
260 while(SiS_SiS7502_init[i][0] != 0)
262 temp8 = pci_read_config8(dev, SiS_SiS7502_init[i][0]);
263 temp8 &= SiS_SiS7502_init[i][1];
264 temp8 |= SiS_SiS7502_init[i][2];
265 pci_write_config8(dev, SiS_SiS7502_init[i][0], temp8);
269 //-----------------------------------------------------------
272 // put audio to D0 state
273 pci_write_config8(dev, 0x54,0x00);
279 print_debug("****** Azalia PCI config ******");
280 print_debug("\n 03020100 07060504 0B0A0908 0F0E0D0C");
282 for(i=0;i<0xff;i+=4){
288 print_debug_hex32(pci_read_config32(dev,i));
295 res = find_resource(dev, 0x10);
299 base =(uint8_t *) res->base;
300 printk_debug("base = %08x\n", base);
302 codec_mask = codec_detect(base);
305 printk_debug("codec_mask = %02x\n", codec_mask);
306 codecs_init(base, codec_mask);
309 print_debug("AZALIA_INIT:<----------\n");
312 static void lpci_set_subsystem(device_t dev, unsigned vendor, unsigned device)
314 pci_write_config32(dev, 0x40,
315 ((device & 0xffff) << 16) | (vendor & 0xffff));
318 static struct pci_operations lops_pci = {
319 .set_subsystem = lpci_set_subsystem,
322 static struct device_operations aza_audio_ops = {
323 .read_resources = pci_dev_read_resources,
324 .set_resources = pci_dev_set_resources,
325 .enable_resources = pci_dev_enable_resources,
326 // .enable = sis966_enable,
329 .ops_pci = &lops_pci,
332 static const struct pci_driver azaaudio_driver __pci_driver = {
333 .ops = &aza_audio_ops,
334 .vendor = PCI_VENDOR_ID_SIS,
335 .device = PCI_DEVICE_ID_SIS_SIS966_AZA,