2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
17 * Purpose:Implement functions to access eeprom
24 * SROMbyReadEmbedded - Embedded read eeprom via MAC
25 * SROMbWriteEmbedded - Embedded write eeprom via MAC
26 * SROMvRegBitsOn - Set Bits On in eeprom
27 * SROMvRegBitsOff - Clear Bits Off in eeprom
28 * SROMbIsRegBitsOn - Test if Bits On in eeprom
29 * SROMbIsRegBitsOff - Test if Bits Off in eeprom
30 * SROMvReadAllContents - Read all contents in eeprom
31 * SROMvWriteAllContents - Write all contents in eeprom
32 * SROMvReadEtherAddress - Read Ethernet Address in eeprom
33 * SROMvWriteEtherAddress - Write Ethernet Address in eeprom
34 * SROMvReadSubSysVenId - Read Sub_VID and Sub_SysId in eeprom
35 * SROMbAutoLoad - Auto Load eeprom to MAC register
46 /*--------------------- Static Definitions -------------------------*/
48 /*--------------------- Static Classes ----------------------------*/
50 /*--------------------- Static Variables --------------------------*/
52 /*--------------------- Static Functions --------------------------*/
54 /*--------------------- Export Variables --------------------------*/
56 /*--------------------- Export Functions --------------------------*/
59 * Description: Read a byte from EEPROM, by MAC I2C
63 * iobase - I/O base address
64 * byContntOffset - address of EEPROM
68 * Return Value: data read
71 unsigned char SROMbyReadEmbedded(void __iomem *iobase,
72 unsigned char byContntOffset)
74 unsigned short wDelay, wNoACK;
80 VNSvInPortB(iobase + MAC_REG_I2MCFG, &byOrg);
81 /* turn off hardware retry for getting NACK */
82 VNSvOutPortB(iobase + MAC_REG_I2MCFG, (byOrg & (~I2MCFG_NORETRY)));
83 for (wNoACK = 0; wNoACK < W_MAX_I2CRETRY; wNoACK++) {
84 VNSvOutPortB(iobase + MAC_REG_I2MTGID, EEP_I2C_DEV_ID);
85 VNSvOutPortB(iobase + MAC_REG_I2MTGAD, byContntOffset);
87 /* issue read command */
88 VNSvOutPortB(iobase + MAC_REG_I2MCSR, I2MCSR_EEMR);
89 /* wait DONE be set */
90 for (wDelay = 0; wDelay < W_MAX_TIMEOUT; wDelay++) {
91 VNSvInPortB(iobase + MAC_REG_I2MCSR, &byWait);
92 if (byWait & (I2MCSR_DONE | I2MCSR_NACK))
94 PCAvDelayByIO(CB_DELAY_LOOP_WAIT);
96 if ((wDelay < W_MAX_TIMEOUT) &&
97 (!(byWait & I2MCSR_NACK))) {
101 VNSvInPortB(iobase + MAC_REG_I2MDIPT, &byData);
102 VNSvOutPortB(iobase + MAC_REG_I2MCFG, byOrg);
107 * Description: Read all contents of eeprom to buffer
111 * iobase - I/O base address
113 * pbyEepromRegs - EEPROM content Buffer
118 void SROMvReadAllContents(void __iomem *iobase, unsigned char *pbyEepromRegs)
122 /* ii = Rom Address */
123 for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) {
124 *pbyEepromRegs = SROMbyReadEmbedded(iobase,
131 * Description: Read Ethernet Address from eeprom to buffer
135 * iobase - I/O base address
137 * pbyEtherAddress - Ethernet Address buffer
142 void SROMvReadEtherAddress(void __iomem *iobase,
143 unsigned char *pbyEtherAddress)
147 /* ii = Rom Address */
148 for (ii = 0; ii < ETH_ALEN; ii++) {
149 *pbyEtherAddress = SROMbyReadEmbedded(iobase, ii);