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.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 * Purpose:Implement functions to access eeprom
28 * SROMbyReadEmbedded - Embedded read eeprom via MAC
29 * SROMbWriteEmbedded - Embedded write eeprom via MAC
30 * SROMvRegBitsOn - Set Bits On in eeprom
31 * SROMvRegBitsOff - Clear Bits Off in eeprom
32 * SROMbIsRegBitsOn - Test if Bits On in eeprom
33 * SROMbIsRegBitsOff - Test if Bits Off in eeprom
34 * SROMvReadAllContents - Read all contents in eeprom
35 * SROMvWriteAllContents - Write all contents in eeprom
36 * SROMvReadEtherAddress - Read Ethernet Address in eeprom
37 * SROMvWriteEtherAddress - Write Ethernet Address in eeprom
38 * SROMvReadSubSysVenId - Read Sub_VID and Sub_SysId in eeprom
39 * SROMbAutoLoad - Auto Load eeprom to MAC register
50 /*--------------------- Static Definitions -------------------------*/
52 /*--------------------- Static Classes ----------------------------*/
54 /*--------------------- Static Variables --------------------------*/
56 /*--------------------- Static Functions --------------------------*/
58 /*--------------------- Export Variables --------------------------*/
60 /*--------------------- Export Functions --------------------------*/
63 * Description: Read a byte from EEPROM, by MAC I2C
67 * dwIoBase - I/O base address
68 * byContntOffset - address of EEPROM
72 * Return Value: data read
75 unsigned char SROMbyReadEmbedded(void __iomem *dwIoBase, unsigned char byContntOffset)
77 unsigned short wDelay, wNoACK;
83 VNSvInPortB(dwIoBase + MAC_REG_I2MCFG, &byOrg);
84 /* turn off hardware retry for getting NACK */
85 VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, (byOrg & (~I2MCFG_NORETRY)));
86 for (wNoACK = 0; wNoACK < W_MAX_I2CRETRY; wNoACK++) {
87 VNSvOutPortB(dwIoBase + MAC_REG_I2MTGID, EEP_I2C_DEV_ID);
88 VNSvOutPortB(dwIoBase + MAC_REG_I2MTGAD, byContntOffset);
90 /* issue read command */
91 VNSvOutPortB(dwIoBase + MAC_REG_I2MCSR, I2MCSR_EEMR);
92 /* wait DONE be set */
93 for (wDelay = 0; wDelay < W_MAX_TIMEOUT; wDelay++) {
94 VNSvInPortB(dwIoBase + MAC_REG_I2MCSR, &byWait);
95 if (byWait & (I2MCSR_DONE | I2MCSR_NACK))
97 PCAvDelayByIO(CB_DELAY_LOOP_WAIT);
99 if ((wDelay < W_MAX_TIMEOUT) &&
100 (!(byWait & I2MCSR_NACK))) {
104 VNSvInPortB(dwIoBase + MAC_REG_I2MDIPT, &byData);
105 VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg);
110 * Description: Write a byte to EEPROM, by MAC I2C
114 * dwIoBase - I/O base address
115 * byContntOffset - address of EEPROM
116 * wData - data to write
120 * Return Value: true if succeeded; false if failed.
123 bool SROMbWriteEmbedded(void __iomem *dwIoBase, unsigned char byContntOffset, unsigned char byData)
125 unsigned short wDelay, wNoACK;
126 unsigned char byWait;
130 VNSvInPortB(dwIoBase + MAC_REG_I2MCFG, &byOrg);
131 /* turn off hardware retry for getting NACK */
132 VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, (byOrg & (~I2MCFG_NORETRY)));
133 for (wNoACK = 0; wNoACK < W_MAX_I2CRETRY; wNoACK++) {
134 VNSvOutPortB(dwIoBase + MAC_REG_I2MTGID, EEP_I2C_DEV_ID);
135 VNSvOutPortB(dwIoBase + MAC_REG_I2MTGAD, byContntOffset);
136 VNSvOutPortB(dwIoBase + MAC_REG_I2MDOPT, byData);
138 /* issue write command */
139 VNSvOutPortB(dwIoBase + MAC_REG_I2MCSR, I2MCSR_EEMW);
140 /* wait DONE be set */
141 for (wDelay = 0; wDelay < W_MAX_TIMEOUT; wDelay++) {
142 VNSvInPortB(dwIoBase + MAC_REG_I2MCSR, &byWait);
143 if (byWait & (I2MCSR_DONE | I2MCSR_NACK))
145 PCAvDelayByIO(CB_DELAY_LOOP_WAIT);
148 if ((wDelay < W_MAX_TIMEOUT) &&
149 (!(byWait & I2MCSR_NACK))) {
153 if (wNoACK == W_MAX_I2CRETRY) {
154 VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg);
157 VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg);
162 * Description: Turn bits on in eeprom
166 * dwIoBase - I/O base address
167 * byContntOffset - address of EEPROM
168 * byBits - bits to turn on
175 void SROMvRegBitsOn(void __iomem *dwIoBase, unsigned char byContntOffset, unsigned char byBits)
177 unsigned char byOrgData;
179 byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset);
180 SROMbWriteEmbedded(dwIoBase, byContntOffset, (unsigned char)(byOrgData | byBits));
184 * Description: Turn bits off in eeprom
188 * dwIoBase - I/O base address
189 * byContntOffset - address of EEPROM
190 * byBits - bits to turn off
195 void SROMvRegBitsOff(void __iomem *dwIoBase, unsigned char byContntOffset, unsigned char byBits)
197 unsigned char byOrgData;
199 byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset);
200 SROMbWriteEmbedded(dwIoBase, byContntOffset, (unsigned char)(byOrgData & (~byBits)));
204 * Description: Test if bits on in eeprom
208 * dwIoBase - I/O base address
209 * byContntOffset - address of EEPROM
210 * byTestBits - bits to test
214 * Return Value: true if all test bits on; otherwise false
217 bool SROMbIsRegBitsOn(void __iomem *dwIoBase, unsigned char byContntOffset, unsigned char byTestBits)
219 unsigned char byOrgData;
221 byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset);
222 return (byOrgData & byTestBits) == byTestBits;
226 * Description: Test if bits off in eeprom
230 * dwIoBase - I/O base address
231 * byContntOffset - address of EEPROM
232 * byTestBits - bits to test
236 * Return Value: true if all test bits off; otherwise false
239 bool SROMbIsRegBitsOff(void __iomem *dwIoBase, unsigned char byContntOffset, unsigned char byTestBits)
241 unsigned char byOrgData;
243 byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset);
244 return !(byOrgData & byTestBits);
248 * Description: Read all contents of eeprom to buffer
252 * dwIoBase - I/O base address
254 * pbyEepromRegs - EEPROM content Buffer
259 void SROMvReadAllContents(void __iomem *dwIoBase, unsigned char *pbyEepromRegs)
263 /* ii = Rom Address */
264 for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) {
265 *pbyEepromRegs = SROMbyReadEmbedded(dwIoBase, (unsigned char)ii);
271 * Description: Write all contents of buffer to eeprom
275 * dwIoBase - I/O base address
276 * pbyEepromRegs - EEPROM content Buffer
283 void SROMvWriteAllContents(void __iomem *dwIoBase, unsigned char *pbyEepromRegs)
287 /* ii = Rom Address */
288 for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) {
289 SROMbWriteEmbedded(dwIoBase, (unsigned char)ii, *pbyEepromRegs);
295 * Description: Read Ethernet Address from eeprom to buffer
299 * dwIoBase - I/O base address
301 * pbyEtherAddress - Ethernet Address buffer
306 void SROMvReadEtherAddress(void __iomem *dwIoBase, unsigned char *pbyEtherAddress)
310 /* ii = Rom Address */
311 for (ii = 0; ii < ETH_ALEN; ii++) {
312 *pbyEtherAddress = SROMbyReadEmbedded(dwIoBase, ii);
318 * Description: Write Ethernet Address from buffer to eeprom
322 * dwIoBase - I/O base address
323 * pbyEtherAddress - Ethernet Address buffer
330 void SROMvWriteEtherAddress(void __iomem *dwIoBase, unsigned char *pbyEtherAddress)
334 /* ii = Rom Address */
335 for (ii = 0; ii < ETH_ALEN; ii++) {
336 SROMbWriteEmbedded(dwIoBase, ii, *pbyEtherAddress);
342 * Description: Read Sub_VID and Sub_SysId from eeprom to buffer
346 * dwIoBase - I/O base address
348 * pdwSubSysVenId - Sub_VID and Sub_SysId read
353 void SROMvReadSubSysVenId(void __iomem *dwIoBase, unsigned long *pdwSubSysVenId)
355 unsigned char *pbyData;
357 pbyData = (unsigned char *)pdwSubSysVenId;
359 *pbyData = SROMbyReadEmbedded(dwIoBase, 6);
360 *(pbyData+1) = SROMbyReadEmbedded(dwIoBase, 7);
362 *(pbyData+2) = SROMbyReadEmbedded(dwIoBase, 8);
363 *(pbyData+3) = SROMbyReadEmbedded(dwIoBase, 9);
367 * Description: Auto Load EEPROM to MAC register
371 * dwIoBase - I/O base address
375 * Return Value: true if success; otherwise false
378 bool SROMbAutoLoad(void __iomem *dwIoBase)
380 unsigned char byWait;
385 VNSvInPortB(dwIoBase + MAC_REG_I2MCFG, &byOrg);
386 /* turn on hardware retry */
387 VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, (byOrg | I2MCFG_NORETRY));
389 MACvRegBitsOn(dwIoBase, MAC_REG_I2MCSR, I2MCSR_AUTOLD);
391 /* ii = Rom Address */
392 for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) {
393 MACvTimer0MicroSDelay(dwIoBase, CB_EEPROM_READBYTE_WAIT);
394 VNSvInPortB(dwIoBase + MAC_REG_I2MCSR, &byWait);
395 if (!(byWait & I2MCSR_AUTOLD))
399 VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg);
401 if (ii == EEP_MAX_CONTEXT_SIZE)