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
46 #if !defined(__UPC_H__)
49 #if !defined(__TMACRO_H__)
52 #if !defined(__TBIT_H__)
55 #if !defined(__TETHER_H__)
58 #if !defined(__MAC_H__)
61 #if !defined(__SROM_H__)
68 /*--------------------- Static Definitions -------------------------*/
70 /*--------------------- Static Classes ----------------------------*/
72 /*--------------------- Static Variables --------------------------*/
74 /*--------------------- Static Functions --------------------------*/
76 /*--------------------- Export Variables --------------------------*/
78 /*--------------------- Export Functions --------------------------*/
84 * Description: Read a byte from EEPROM, by MAC I2C
88 * dwIoBase - I/O base address
89 * byContntOffset - address of EEPROM
93 * Return Value: data read
96 BYTE
SROMbyReadEmbedded(DWORD_PTR dwIoBase
, BYTE byContntOffset
)
104 VNSvInPortB(dwIoBase
+ MAC_REG_I2MCFG
, &byOrg
);
105 // turn off hardware retry for getting NACK
106 VNSvOutPortB(dwIoBase
+ MAC_REG_I2MCFG
, (byOrg
& (~I2MCFG_NORETRY
)));
107 for (wNoACK
= 0; wNoACK
< W_MAX_I2CRETRY
; wNoACK
++) {
108 VNSvOutPortB(dwIoBase
+ MAC_REG_I2MTGID
, EEP_I2C_DEV_ID
);
109 VNSvOutPortB(dwIoBase
+ MAC_REG_I2MTGAD
, byContntOffset
);
111 // issue read command
112 VNSvOutPortB(dwIoBase
+ MAC_REG_I2MCSR
, I2MCSR_EEMR
);
114 for (wDelay
= 0; wDelay
< W_MAX_TIMEOUT
; wDelay
++) {
115 VNSvInPortB(dwIoBase
+ MAC_REG_I2MCSR
, &byWait
);
116 if (BITbIsAnyBitsOn(byWait
, (I2MCSR_DONE
| I2MCSR_NACK
)))
118 PCAvDelayByIO(CB_DELAY_LOOP_WAIT
);
120 if ((wDelay
< W_MAX_TIMEOUT
) &&
121 (BITbIsBitOff(byWait
, I2MCSR_NACK
))) {
125 VNSvInPortB(dwIoBase
+ MAC_REG_I2MDIPT
, &byData
);
126 VNSvOutPortB(dwIoBase
+ MAC_REG_I2MCFG
, byOrg
);
132 * Description: Write a byte to EEPROM, by MAC I2C
136 * dwIoBase - I/O base address
137 * byContntOffset - address of EEPROM
138 * wData - data to write
142 * Return Value: TRUE if succeeded; FALSE if failed.
145 BOOL
SROMbWriteEmbedded (DWORD_PTR dwIoBase
, BYTE byContntOffset
, BYTE byData
)
152 VNSvInPortB(dwIoBase
+ MAC_REG_I2MCFG
, &byOrg
);
153 // turn off hardware retry for getting NACK
154 VNSvOutPortB(dwIoBase
+ MAC_REG_I2MCFG
, (byOrg
& (~I2MCFG_NORETRY
)));
155 for (wNoACK
= 0; wNoACK
< W_MAX_I2CRETRY
; wNoACK
++) {
156 VNSvOutPortB(dwIoBase
+ MAC_REG_I2MTGID
, EEP_I2C_DEV_ID
);
157 VNSvOutPortB(dwIoBase
+ MAC_REG_I2MTGAD
, byContntOffset
);
158 VNSvOutPortB(dwIoBase
+ MAC_REG_I2MDOPT
, byData
);
160 // issue write command
161 VNSvOutPortB(dwIoBase
+ MAC_REG_I2MCSR
, I2MCSR_EEMW
);
163 for (wDelay
= 0; wDelay
< W_MAX_TIMEOUT
; wDelay
++) {
164 VNSvInPortB(dwIoBase
+ MAC_REG_I2MCSR
, &byWait
);
165 if (BITbIsAnyBitsOn(byWait
, (I2MCSR_DONE
| I2MCSR_NACK
)))
167 PCAvDelayByIO(CB_DELAY_LOOP_WAIT
);
170 if ((wDelay
< W_MAX_TIMEOUT
) &&
171 (BITbIsBitOff(byWait
, I2MCSR_NACK
))) {
175 if (wNoACK
== W_MAX_I2CRETRY
) {
176 VNSvOutPortB(dwIoBase
+ MAC_REG_I2MCFG
, byOrg
);
179 VNSvOutPortB(dwIoBase
+ MAC_REG_I2MCFG
, byOrg
);
185 * Description: Turn bits on in eeprom
189 * dwIoBase - I/O base address
190 * byContntOffset - address of EEPROM
191 * byBits - bits to turn on
198 void SROMvRegBitsOn (DWORD_PTR dwIoBase
, BYTE byContntOffset
, BYTE byBits
)
202 byOrgData
= SROMbyReadEmbedded(dwIoBase
, byContntOffset
);
203 SROMbWriteEmbedded(dwIoBase
, byContntOffset
,(BYTE
)(byOrgData
| byBits
));
208 * Description: Turn bits off in eeprom
212 * dwIoBase - I/O base address
213 * byContntOffset - address of EEPROM
214 * byBits - bits to turn off
219 void SROMvRegBitsOff (DWORD_PTR dwIoBase
, BYTE byContntOffset
, BYTE byBits
)
223 byOrgData
= SROMbyReadEmbedded(dwIoBase
, byContntOffset
);
224 SROMbWriteEmbedded(dwIoBase
, byContntOffset
,(BYTE
)(byOrgData
& (~byBits
)));
229 * Description: Test if bits on in eeprom
233 * dwIoBase - I/O base address
234 * byContntOffset - address of EEPROM
235 * byTestBits - bits to test
239 * Return Value: TRUE if all test bits on; otherwise FALSE
242 BOOL
SROMbIsRegBitsOn (DWORD_PTR dwIoBase
, BYTE byContntOffset
, BYTE byTestBits
)
246 byOrgData
= SROMbyReadEmbedded(dwIoBase
, byContntOffset
);
247 return BITbIsAllBitsOn(byOrgData
, byTestBits
);
252 * Description: Test if bits off in eeprom
256 * dwIoBase - I/O base address
257 * byContntOffset - address of EEPROM
258 * byTestBits - bits to test
262 * Return Value: TRUE if all test bits off; otherwise FALSE
265 BOOL
SROMbIsRegBitsOff (DWORD_PTR dwIoBase
, BYTE byContntOffset
, BYTE byTestBits
)
269 byOrgData
= SROMbyReadEmbedded(dwIoBase
, byContntOffset
);
270 return BITbIsAllBitsOff(byOrgData
, byTestBits
);
275 * Description: Read all contents of eeprom to buffer
279 * dwIoBase - I/O base address
281 * pbyEepromRegs - EEPROM content Buffer
286 void SROMvReadAllContents (DWORD_PTR dwIoBase
, PBYTE pbyEepromRegs
)
291 for (ii
= 0; ii
< EEP_MAX_CONTEXT_SIZE
; ii
++) {
292 *pbyEepromRegs
= SROMbyReadEmbedded(dwIoBase
,(BYTE
) ii
);
299 * Description: Write all contents of buffer to eeprom
303 * dwIoBase - I/O base address
304 * pbyEepromRegs - EEPROM content Buffer
311 void SROMvWriteAllContents (DWORD_PTR dwIoBase
, PBYTE pbyEepromRegs
)
316 for (ii
= 0; ii
< EEP_MAX_CONTEXT_SIZE
; ii
++) {
317 SROMbWriteEmbedded(dwIoBase
,(BYTE
) ii
, *pbyEepromRegs
);
324 * Description: Read Ethernet Address from eeprom to buffer
328 * dwIoBase - I/O base address
330 * pbyEtherAddress - Ethernet Address buffer
335 void SROMvReadEtherAddress (DWORD_PTR dwIoBase
, PBYTE pbyEtherAddress
)
340 for (ii
= 0; ii
< U_ETHER_ADDR_LEN
; ii
++) {
341 *pbyEtherAddress
= SROMbyReadEmbedded(dwIoBase
, ii
);
348 * Description: Write Ethernet Address from buffer to eeprom
352 * dwIoBase - I/O base address
353 * pbyEtherAddress - Ethernet Address buffer
360 void SROMvWriteEtherAddress (DWORD_PTR dwIoBase
, PBYTE pbyEtherAddress
)
365 for (ii
= 0; ii
< U_ETHER_ADDR_LEN
; ii
++) {
366 SROMbWriteEmbedded(dwIoBase
, ii
, *pbyEtherAddress
);
373 * Description: Read Sub_VID and Sub_SysId from eeprom to buffer
377 * dwIoBase - I/O base address
379 * pdwSubSysVenId - Sub_VID and Sub_SysId read
384 void SROMvReadSubSysVenId (DWORD_PTR dwIoBase
, PDWORD pdwSubSysVenId
)
388 pbyData
= (PBYTE
)pdwSubSysVenId
;
390 *pbyData
= SROMbyReadEmbedded(dwIoBase
, 6);
391 *(pbyData
+1) = SROMbyReadEmbedded(dwIoBase
, 7);
393 *(pbyData
+2) = SROMbyReadEmbedded(dwIoBase
, 8);
394 *(pbyData
+3) = SROMbyReadEmbedded(dwIoBase
, 9);
398 * Description: Auto Load EEPROM to MAC register
402 * dwIoBase - I/O base address
406 * Return Value: TRUE if success; otherwise FALSE
409 BOOL
SROMbAutoLoad (DWORD_PTR dwIoBase
)
416 VNSvInPortB(dwIoBase
+ MAC_REG_I2MCFG
, &byOrg
);
417 // turn on hardware retry
418 VNSvOutPortB(dwIoBase
+ MAC_REG_I2MCFG
, (byOrg
| I2MCFG_NORETRY
));
420 MACvRegBitsOn(dwIoBase
, MAC_REG_I2MCSR
, I2MCSR_AUTOLD
);
423 for (ii
= 0; ii
< EEP_MAX_CONTEXT_SIZE
; ii
++) {
424 MACvTimer0MicroSDelay(dwIoBase
, CB_EEPROM_READBYTE_WAIT
);
425 VNSvInPortB(dwIoBase
+ MAC_REG_I2MCSR
, &byWait
);
426 if (BITbIsBitOff(byWait
, I2MCSR_AUTOLD
))
430 VNSvOutPortB(dwIoBase
+ MAC_REG_I2MCFG
, byOrg
);
432 if (ii
== EEP_MAX_CONTEXT_SIZE
)