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 uint8_t SiS_SiS7502_init[7][3]={
42 {0x00, 0x00, 0x00} //End of table
45 static int set_bits(uint8_t *port, uint32_t mask, uint32_t val)
61 } while ((dword != val) && --count);
70 uint32_t send_verb(uint8_t *base, uint32_t verb)
76 dword = read32(base + 0x68);
77 dword=dword|(unsigned long)0x0002;
78 write32(base + 0x68, dword);
80 dword = read32(base + 0x68);
81 } while ((dword & 1)!=0);
82 write32(base + 0x60, verb);
84 dword = read32(base + 0x68);
86 write32(base + 0x68, dword);
89 dword = read32(base + 0x68);
90 } while ((dword & 3) != 2);
92 dword = read32(base + 0x64);
98 static int codec_detect(uint8_t *base)
103 /* 1 */ // controller reset
104 printk(BIOS_DEBUG, "controller reset\n");
106 set_bits(base + 0x08, 1, 1);
109 dword = read32(base + 0x08)&0x1;
110 if(idx++>1000) { printk(BIOS_DEBUG, "controller reset fail !!! \n"); break;}
113 dword=send_verb(base,0x000F0000); // get codec VendorId and DeviceId
116 printk(BIOS_DEBUG, "No codec!\n");
120 printk(BIOS_DEBUG, "Codec ID = %lx\n", dword);
128 static uint32_t verb_data[] = {
192 static unsigned find_verb(uint32_t viddid, uint32_t **verb)
194 if((viddid == 0x10ec0883) || (viddid == 0x10ec0882) || (viddid == 0x10ec0880)) return 0;
195 *verb = (uint32_t *)verb_data;
196 return sizeof(verb_data)/sizeof(uint32_t);
200 static void codec_init(uint8_t *base, int addr)
209 dword = read32(base + 0x68);
212 dword = (addr<<28) | 0x000f0000;
213 write32(base + 0x60, dword);
216 dword = read32(base + 0x68);
217 } while ((dword & 3)!=2);
219 dword = read32(base + 0x64);
222 printk(BIOS_DEBUG, "codec viddid: %08x\n", dword);
223 verb_size = find_verb(dword, &verb);
226 printk(BIOS_DEBUG, "No verb!\n");
230 printk(BIOS_DEBUG, "verb_size: %d\n", verb_size);
232 for(i=0; i<verb_size; i++) {
233 send_verb(base,verb[i]);
235 printk(BIOS_DEBUG, "verb loaded!\n");
238 static void codecs_init(uint8_t *base, uint32_t codec_mask)
244 static void aza_init(struct device *dev)
247 struct resource *res;
250 print_debug("AZALIA_INIT:---------->\n");
252 //-------------- enable AZA (SiS7502) -------------------------
256 while(SiS_SiS7502_init[i][0] != 0)
258 temp8 = pci_read_config8(dev, SiS_SiS7502_init[i][0]);
259 temp8 &= SiS_SiS7502_init[i][1];
260 temp8 |= SiS_SiS7502_init[i][2];
261 pci_write_config8(dev, SiS_SiS7502_init[i][0], temp8);
265 //-----------------------------------------------------------
268 // put audio to D0 state
269 pci_write_config8(dev, 0x54,0x00);
275 print_debug("****** Azalia PCI config ******");
276 print_debug("\n 03020100 07060504 0B0A0908 0F0E0D0C");
278 for(i=0;i<0xff;i+=4){
284 print_debug_hex32(pci_read_config32(dev,i));
291 res = find_resource(dev, 0x10);
295 base =(uint8_t *) res->base;
296 printk(BIOS_DEBUG, "base = %08x\n", base);
298 codec_mask = codec_detect(base);
301 printk(BIOS_DEBUG, "codec_mask = %02x\n", codec_mask);
302 codecs_init(base, codec_mask);
305 print_debug("AZALIA_INIT:<----------\n");
308 static void lpci_set_subsystem(device_t dev, unsigned vendor, unsigned device)
310 pci_write_config32(dev, 0x40,
311 ((device & 0xffff) << 16) | (vendor & 0xffff));
314 static struct pci_operations lops_pci = {
315 .set_subsystem = lpci_set_subsystem,
318 static struct device_operations aza_audio_ops = {
319 .read_resources = pci_dev_read_resources,
320 .set_resources = pci_dev_set_resources,
321 .enable_resources = pci_dev_enable_resources,
322 // .enable = sis966_enable,
325 .ops_pci = &lops_pci,
328 static const struct pci_driver azaaudio_driver __pci_driver = {
329 .ops = &aza_audio_ops,
330 .vendor = PCI_VENDOR_ID_SIS,
331 .device = PCI_DEVICE_ID_SIS_SIS966_HD_AUDIO,