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);
98 static int codec_detect(uint8_t *base)
103 /* 1 */ // controller reset
104 printk_debug("controller reset\n");
106 set_bits(base + 0x08, 1, 1);
109 dword = readl(base + 0x08)&0x1;
110 if(idx++>1000) { printk_debug("controller reset fail !!! \n"); break;}
113 dword=send_verb(base,0x000F0000); // get codec VendorId and DeviceId
116 printk_debug("No codec!\n");
120 printk_debug("Codec ID = %lx\n", dword);
124 dword = readl(base + 0x0e);
126 writel(dword, base + 0x0e);
129 set_bits(base + 0x08, 1, 0);
132 set_bits(base + 0x08, 1, 1);
135 dword = readl(base + 0xe);
140 set_bits(base + 0x08, 1, 0);
141 printk_debug("No codec!\n");
152 static int codec_detect(uint8_t *base)
157 set_bits(base + 0x08, 1, 1);
160 dword = readl(base + 0x0e);
162 writel(dword, base + 0x0e);
165 set_bits(base + 0x08, 1, 0);
168 set_bits(base + 0x08, 1, 1);
171 dword = readl(base + 0xe);
176 set_bits(base + 0x08, 1, 0);
177 printk_debug("No codec!\n");
188 // For SiS demo board PinConfig
189 static uint32_t verb_data[] = {
259 // orginal codec pin configuration setting
261 static uint32_t verb_data[] = {
331 static unsigned find_verb(uint32_t viddid, uint32_t **verb)
333 if((viddid == 0x10ec0883) || (viddid == 0x10ec0882) || (viddid == 0x10ec0880)) return 0;
334 *verb = (uint32_t *)verb_data;
335 return sizeof(verb_data)/sizeof(uint32_t);
339 static void codec_init(uint8_t *base, int addr)
348 dword = readl(base + 0x68);
351 dword = (addr<<28) | 0x000f0000;
352 writel(dword, base + 0x60);
355 dword = readl(base + 0x68);
356 } while ((dword & 3)!=2);
358 dword = readl(base + 0x64);
361 printk_debug("codec viddid: %08x\n", dword);
362 verb_size = find_verb(dword, &verb);
365 printk_debug("No verb!\n");
369 printk_debug("verb_size: %d\n", verb_size);
371 for(i=0; i<verb_size; i++) {
372 send_verb(base,verb[i]);
375 dword = readl(base + 0x68);
378 writel(verb[i], base + 0x60);
381 dword = readl(base + 0x68);
382 } while ((dword & 3) != 2);
385 printk_debug("verb loaded!\n");
388 static void codecs_init(uint8_t *base, uint32_t codec_mask)
393 for(i=2; i>=0; i--) {
394 if( codec_mask & (1<<i) )
399 static void aza_init(struct device *dev)
402 struct resource *res;
406 //-------------- enable AZA (SiS7502) -------------------------
410 while(SiS_SiS7502_init[i][0] != 0)
411 { temp8 = pci_read_config8(dev, SiS_SiS7502_init[i][0]);
412 temp8 &= SiS_SiS7502_init[i][1];
413 temp8 |= SiS_SiS7502_init[i][2];
414 pci_write_config8(dev, SiS_SiS7502_init[i][0], temp8);
418 //-----------------------------------------------------------
421 // put audio to D0 state
422 pci_write_config8(dev, 0x54,0x00);
427 printk_debug("Azalia PCI config \n");
432 print_debug("\r\n");print_debug_hex8(i);print_debug(" ");
434 print_debug_hex32(pci_read_config32(dev,i));
441 res = find_resource(dev, 0x10);
445 base =(uint8_t *) res->base;
446 printk_debug("base = %08x\n", base);
448 codec_mask = codec_detect(base);
451 printk_debug("codec_mask = %02x\n", codec_mask);
452 codecs_init(base, codec_mask);
458 printk_debug("Azalia PCI config \n");
463 print_debug("\r\n");print_debug_hex8(i);print_debug(" ");
465 outl(0x80000800+i,0xcf8);
466 print_debug_hex32(inl(0xcfc));
475 static void lpci_set_subsystem(device_t dev, unsigned vendor, unsigned device)
477 pci_write_config32(dev, 0x40,
478 ((device & 0xffff) << 16) | (vendor & 0xffff));
481 static struct pci_operations lops_pci = {
482 .set_subsystem = lpci_set_subsystem,
485 static struct device_operations aza_audio_ops = {
486 .read_resources = pci_dev_read_resources,
487 .set_resources = pci_dev_set_resources,
488 .enable_resources = pci_dev_enable_resources,
489 // .enable = sis966_enable,
492 .ops_pci = &lops_pci,
495 static const struct pci_driver azaaudio_driver __pci_driver = {
496 .ops = &aza_audio_ops,
497 .vendor = PCI_VENDOR_ID_SIS,
498 .device = PCI_DEVICE_ID_SIS_SIS966_AZA,