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/smbus.h>
29 #include <device/pci.h>
30 #include <device/pci_ids.h>
31 #include <device/pci_ops.h>
37 u8 SiS_SiS191_init[6][3]={
43 {0x00, 0x00, 0x00} //End of table
49 #define SMI_REQUEST 0x10
56 static void writeApcByte(int addr, u8 value)
62 static u8 readApcByte(int addr)
70 static void readApcMacAddr(void)
74 // enable APC in south bridge sis966 D2F0
76 outl(0x80001048,0xcf8);
77 outl((inl(0xcfc) & 0xfffffffd),0xcfc ); // enable IO78/79h for APC Index/Data
79 printk(BIOS_DEBUG, "MAC addr in APC = ");
80 for(i = 0x9 ; i <=0xe ; i++)
82 printk(BIOS_DEBUG, "%2.2x",readApcByte(i));
84 printk(BIOS_DEBUG, "\n");
87 writeApcByte(0x7,readApcByte(0x7)&0xf7);
88 writeApcByte(0x7,readApcByte(0x7)|0x0a);
90 /* disable APC in south bridge */
91 outl(0x80001048,0xcf8);
92 outl(inl(0xcfc)&0xffffffbf,0xcfc);
95 static void set_apc(struct device *dev)
101 /* enable APC in south bridge sis966 D2F0 */
102 outl(0x80001048,0xcf8);
103 outl((inl(0xcfc) & 0xfffffffd),0xcfc ); // enable IO78/79h for APC Index/Data
105 for(i = 0 ; i <3; i++)
108 writeApcByte(addr,(u8)(MacAddr[i]&0xFF));
109 writeApcByte(addr+1L,(u8)((MacAddr[i]>>8)&0xFF));
110 // printf("%x - ",readMacAddrByte(0x59+i));
114 writeApcByte(0x7,readApcByte(0x7)&0xf7);
115 writeApcByte(0x7,readApcByte(0x7)|0x0a);
117 /* disable APC in south bridge */
118 outl(0x80001048,0xcf8);
119 outl(inl(0xcfc)&0xffffffbf,0xcfc);
121 // CFG reg0x73 bit=1, tell driver MAC Address load to APC
122 bTmp = pci_read_config8(dev, 0x73);
124 pci_write_config8(dev, 0x73, bTmp);
128 * Read one word out of the serial EEPROM.
132 * @param Reg EEPROM word to read.
133 * @return Contents of EEPROM word (Reg).
136 static unsigned long ReadEEprom( struct device *dev, u32 base, u32 Reg)
143 ulValue = (0x80 | (0x2 << 8) | (Reg << 10)); //BIT_7
145 write32(base+0x3c, ulValue);
149 for(i=0 ; i <= LoopNum; i++)
151 ulValue=read32(base+0x3c);
153 if(!(ulValue & 0x0080)) //BIT_7
161 if(i==LoopNum) data=0x10000;
163 ulValue=read32(base+0x3c);
164 data = ((ulValue & 0xffff0000) >> 16);
170 static int phy_read(u32 base, unsigned phy_addr, unsigned phy_reg)
178 Read_Cmd = ((phy_reg << 11) |
183 // SmiMgtInterface Reg is the SMI management interface register(offset 44h) of MAC
184 write32(base+0x44, Read_Cmd);
186 // Polling SMI_REQ bit to be deasserted indicated read command completed
189 // Wait 20 usec before checking status
191 ulValue = read32(base+0x44);
192 } while((ulValue & SMI_REQUEST) != 0);
193 //printk(BIOS_DEBUG, "base %x cmd %lx ret val %lx\n", tmp,Read_Cmd,ulValue);
194 usData=(ulValue>>16);
202 // Detect a valid PHY
203 // If there exist a valid PHY then return TRUE, else return FALSE
204 static int phy_detect(u32 base,u16 *PhyAddr) //BOOL PHY_Detect()
206 int bFoundPhy = FALSE;
211 // Scan all PHY address(0 ~ 31) to find a valid PHY
212 for(PhyAddress = 0; PhyAddress < 32; PhyAddress++)
214 usData=phy_read(base,PhyAddress,StatusReg); // Status register is a PHY's register(offset 01h)
218 if((usData != 0x0) && (usData != 0xffff))
228 printk(BIOS_DEBUG, "PHY not found !!!! \n");
237 static void nic_init(struct device *dev)
242 struct resource *res;
244 print_debug("NIC_INIT:---------->\n");
246 //-------------- enable NIC (SiS19x) -------------------------
250 while(SiS_SiS191_init[i][0] != 0)
252 temp8 = pci_read_config8(dev, SiS_SiS191_init[i][0]);
253 temp8 &= SiS_SiS191_init[i][1];
254 temp8 |= SiS_SiS191_init[i][2];
255 pci_write_config8(dev, SiS_SiS191_init[i][0], temp8);
259 //-----------------------------------------------------------
263 unsigned long ulValue;
265 res = find_resource(dev, 0x10);
269 printk(BIOS_DEBUG, "NIC Cannot find resource..\n");
273 printk(BIOS_DEBUG, "NIC base address %x\n",base);
275 if(!(val=phy_detect(base,&PhyAddr)))
277 printk(BIOS_DEBUG, "PHY detect fail !!!!\n");
281 ulValue=read32(base + 0x38L); // check EEPROM existing
283 if((ulValue & 0x0002))
286 // read MAC address from EEPROM at first
288 // if that is valid we will use that
290 printk(BIOS_DEBUG, "EEPROM contents %lx \n",ReadEEprom( dev, base, 0LL));
292 //status = smbus_read_byte(dev_eeprom, i);
293 ulValue=ReadEEprom( dev, base, i+3L);
294 if (ulValue ==0x10000) break; // error
296 MacAddr[i] =ulValue & 0xFFFF;
300 // read MAC address from firmware
301 printk(BIOS_DEBUG, "EEPROM invalid!!\nReg 0x38h=%.8lx \n",ulValue);
302 MacAddr[0]=read16(0xffffffc0); // mac address store at here
303 MacAddr[1]=read16(0xffffffc2);
304 MacAddr[2]=read16(0xffffffc4);
315 print_debug("****** NIC PCI config ******");
316 print_debug("\n 03020100 07060504 0B0A0908 0F0E0D0C");
318 for(i=0;i<0xff;i+=4){
324 print_debug_hex32(pci_read_config32(dev,i));
335 print_debug("NIC_INIT:<----------\n");
341 static void lpci_set_subsystem(device_t dev, unsigned vendor, unsigned device)
343 pci_write_config32(dev, 0x40,
344 ((device & 0xffff) << 16) | (vendor & 0xffff));
347 static struct pci_operations lops_pci = {
348 .set_subsystem = lpci_set_subsystem,
351 static struct device_operations nic_ops = {
352 .read_resources = pci_dev_read_resources,
353 .set_resources = pci_dev_set_resources,
354 .enable_resources = pci_dev_enable_resources,
357 // .enable = sis966_enable,
358 .ops_pci = &lops_pci,
361 static const struct pci_driver nic_driver __pci_driver = {
363 .vendor = PCI_VENDOR_ID_SIS,
364 .device = PCI_DEVICE_ID_SIS_SIS966_NIC,