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
51 /*--------------------- Static Definitions -------------------------*/
53 /*--------------------- Static Classes ----------------------------*/
55 /*--------------------- Static Variables --------------------------*/
57 /*--------------------- Static Functions --------------------------*/
59 /*--------------------- Export Variables --------------------------*/
61 /*--------------------- Export Functions --------------------------*/
67 * Description: Read a byte from EEPROM, by MAC I2C
71 * dwIoBase - I/O base address
72 * byContntOffset - address of EEPROM
76 * Return Value: data read
79 unsigned char SROMbyReadEmbedded(unsigned long dwIoBase
, unsigned char byContntOffset
)
81 unsigned short wDelay
, wNoACK
;
87 VNSvInPortB(dwIoBase
+ MAC_REG_I2MCFG
, &byOrg
);
88 /* turn off hardware retry for getting NACK */
89 VNSvOutPortB(dwIoBase
+ MAC_REG_I2MCFG
, (byOrg
& (~I2MCFG_NORETRY
)));
90 for (wNoACK
= 0; wNoACK
< W_MAX_I2CRETRY
; wNoACK
++) {
91 VNSvOutPortB(dwIoBase
+ MAC_REG_I2MTGID
, EEP_I2C_DEV_ID
);
92 VNSvOutPortB(dwIoBase
+ MAC_REG_I2MTGAD
, byContntOffset
);
94 /* issue read command */
95 VNSvOutPortB(dwIoBase
+ MAC_REG_I2MCSR
, I2MCSR_EEMR
);
96 /* wait DONE be set */
97 for (wDelay
= 0; wDelay
< W_MAX_TIMEOUT
; wDelay
++) {
98 VNSvInPortB(dwIoBase
+ MAC_REG_I2MCSR
, &byWait
);
99 if (byWait
& (I2MCSR_DONE
| I2MCSR_NACK
))
101 PCAvDelayByIO(CB_DELAY_LOOP_WAIT
);
103 if ((wDelay
< W_MAX_TIMEOUT
) &&
104 ( !(byWait
& I2MCSR_NACK
))) {
108 VNSvInPortB(dwIoBase
+ MAC_REG_I2MDIPT
, &byData
);
109 VNSvOutPortB(dwIoBase
+ MAC_REG_I2MCFG
, byOrg
);
115 * Description: Write a byte to EEPROM, by MAC I2C
119 * dwIoBase - I/O base address
120 * byContntOffset - address of EEPROM
121 * wData - data to write
125 * Return Value: true if succeeded; false if failed.
128 bool SROMbWriteEmbedded(unsigned long dwIoBase
, unsigned char byContntOffset
, unsigned char byData
)
130 unsigned short wDelay
, wNoACK
;
131 unsigned char byWait
;
135 VNSvInPortB(dwIoBase
+ MAC_REG_I2MCFG
, &byOrg
);
136 /* turn off hardware retry for getting NACK */
137 VNSvOutPortB(dwIoBase
+ MAC_REG_I2MCFG
, (byOrg
& (~I2MCFG_NORETRY
)));
138 for (wNoACK
= 0; wNoACK
< W_MAX_I2CRETRY
; wNoACK
++) {
139 VNSvOutPortB(dwIoBase
+ MAC_REG_I2MTGID
, EEP_I2C_DEV_ID
);
140 VNSvOutPortB(dwIoBase
+ MAC_REG_I2MTGAD
, byContntOffset
);
141 VNSvOutPortB(dwIoBase
+ MAC_REG_I2MDOPT
, byData
);
143 /* issue write command */
144 VNSvOutPortB(dwIoBase
+ MAC_REG_I2MCSR
, I2MCSR_EEMW
);
145 /* wait DONE be set */
146 for (wDelay
= 0; wDelay
< W_MAX_TIMEOUT
; wDelay
++) {
147 VNSvInPortB(dwIoBase
+ MAC_REG_I2MCSR
, &byWait
);
148 if (byWait
& (I2MCSR_DONE
| I2MCSR_NACK
))
150 PCAvDelayByIO(CB_DELAY_LOOP_WAIT
);
153 if ((wDelay
< W_MAX_TIMEOUT
) &&
154 ( !(byWait
& I2MCSR_NACK
))) {
158 if (wNoACK
== W_MAX_I2CRETRY
) {
159 VNSvOutPortB(dwIoBase
+ MAC_REG_I2MCFG
, byOrg
);
162 VNSvOutPortB(dwIoBase
+ MAC_REG_I2MCFG
, byOrg
);
168 * Description: Turn bits on in eeprom
172 * dwIoBase - I/O base address
173 * byContntOffset - address of EEPROM
174 * byBits - bits to turn on
181 void SROMvRegBitsOn(unsigned long dwIoBase
, unsigned char byContntOffset
, unsigned char byBits
)
183 unsigned char byOrgData
;
185 byOrgData
= SROMbyReadEmbedded(dwIoBase
, byContntOffset
);
186 SROMbWriteEmbedded(dwIoBase
, byContntOffset
,(unsigned char)(byOrgData
| byBits
));
191 * Description: Turn bits off in eeprom
195 * dwIoBase - I/O base address
196 * byContntOffset - address of EEPROM
197 * byBits - bits to turn off
202 void SROMvRegBitsOff(unsigned long dwIoBase
, unsigned char byContntOffset
, unsigned char byBits
)
204 unsigned char byOrgData
;
206 byOrgData
= SROMbyReadEmbedded(dwIoBase
, byContntOffset
);
207 SROMbWriteEmbedded(dwIoBase
, byContntOffset
,(unsigned char)(byOrgData
& (~byBits
)));
212 * Description: Test if bits on in eeprom
216 * dwIoBase - I/O base address
217 * byContntOffset - address of EEPROM
218 * byTestBits - bits to test
222 * Return Value: true if all test bits on; otherwise false
225 bool SROMbIsRegBitsOn(unsigned long dwIoBase
, unsigned char byContntOffset
, unsigned char byTestBits
)
227 unsigned char byOrgData
;
229 byOrgData
= SROMbyReadEmbedded(dwIoBase
, byContntOffset
);
230 return (byOrgData
& byTestBits
) == byTestBits
;
235 * Description: Test if bits off in eeprom
239 * dwIoBase - I/O base address
240 * byContntOffset - address of EEPROM
241 * byTestBits - bits to test
245 * Return Value: true if all test bits off; otherwise false
248 bool SROMbIsRegBitsOff(unsigned long dwIoBase
, unsigned char byContntOffset
, unsigned char byTestBits
)
250 unsigned char byOrgData
;
252 byOrgData
= SROMbyReadEmbedded(dwIoBase
, byContntOffset
);
253 return !(byOrgData
& byTestBits
);
258 * Description: Read all contents of eeprom to buffer
262 * dwIoBase - I/O base address
264 * pbyEepromRegs - EEPROM content Buffer
269 void SROMvReadAllContents(unsigned long dwIoBase
, unsigned char *pbyEepromRegs
)
273 /* ii = Rom Address */
274 for (ii
= 0; ii
< EEP_MAX_CONTEXT_SIZE
; ii
++) {
275 *pbyEepromRegs
= SROMbyReadEmbedded(dwIoBase
,(unsigned char) ii
);
282 * Description: Write all contents of buffer to eeprom
286 * dwIoBase - I/O base address
287 * pbyEepromRegs - EEPROM content Buffer
294 void SROMvWriteAllContents(unsigned long dwIoBase
, unsigned char *pbyEepromRegs
)
298 /* ii = Rom Address */
299 for (ii
= 0; ii
< EEP_MAX_CONTEXT_SIZE
; ii
++) {
300 SROMbWriteEmbedded(dwIoBase
,(unsigned char) ii
, *pbyEepromRegs
);
307 * Description: Read Ethernet Address from eeprom to buffer
311 * dwIoBase - I/O base address
313 * pbyEtherAddress - Ethernet Address buffer
318 void SROMvReadEtherAddress(unsigned long dwIoBase
, unsigned char *pbyEtherAddress
)
322 /* ii = Rom Address */
323 for (ii
= 0; ii
< ETH_ALEN
; ii
++) {
324 *pbyEtherAddress
= SROMbyReadEmbedded(dwIoBase
, ii
);
331 * Description: Write Ethernet Address from buffer to eeprom
335 * dwIoBase - I/O base address
336 * pbyEtherAddress - Ethernet Address buffer
343 void SROMvWriteEtherAddress(unsigned long dwIoBase
, unsigned char *pbyEtherAddress
)
347 /* ii = Rom Address */
348 for (ii
= 0; ii
< ETH_ALEN
; ii
++) {
349 SROMbWriteEmbedded(dwIoBase
, ii
, *pbyEtherAddress
);
356 * Description: Read Sub_VID and Sub_SysId from eeprom to buffer
360 * dwIoBase - I/O base address
362 * pdwSubSysVenId - Sub_VID and Sub_SysId read
367 void SROMvReadSubSysVenId(unsigned long dwIoBase
, unsigned long *pdwSubSysVenId
)
369 unsigned char *pbyData
;
371 pbyData
= (unsigned char *)pdwSubSysVenId
;
373 *pbyData
= SROMbyReadEmbedded(dwIoBase
, 6);
374 *(pbyData
+1) = SROMbyReadEmbedded(dwIoBase
, 7);
376 *(pbyData
+2) = SROMbyReadEmbedded(dwIoBase
, 8);
377 *(pbyData
+3) = SROMbyReadEmbedded(dwIoBase
, 9);
381 * Description: Auto Load EEPROM to MAC register
385 * dwIoBase - I/O base address
389 * Return Value: true if success; otherwise false
392 bool SROMbAutoLoad(unsigned long dwIoBase
)
394 unsigned char byWait
;
399 VNSvInPortB(dwIoBase
+ MAC_REG_I2MCFG
, &byOrg
);
400 /* turn on hardware retry */
401 VNSvOutPortB(dwIoBase
+ MAC_REG_I2MCFG
, (byOrg
| I2MCFG_NORETRY
));
403 MACvRegBitsOn(dwIoBase
, MAC_REG_I2MCSR
, I2MCSR_AUTOLD
);
405 /* ii = Rom Address */
406 for (ii
= 0; ii
< EEP_MAX_CONTEXT_SIZE
; ii
++) {
407 MACvTimer0MicroSDelay(dwIoBase
, CB_EEPROM_READBYTE_WAIT
);
408 VNSvInPortB(dwIoBase
+ MAC_REG_I2MCSR
, &byWait
);
409 if ( !(byWait
& I2MCSR_AUTOLD
))
413 VNSvOutPortB(dwIoBase
+ MAC_REG_I2MCFG
, byOrg
);
415 if (ii
== EEP_MAX_CONTEXT_SIZE
)