]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - drivers/staging/vt6655/srom.c
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 BYTE
SROMbyReadEmbedded(DWORD_PTR dwIoBase
, BYTE byContntOffset
)
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
);
95 VNSvOutPortB(dwIoBase
+ MAC_REG_I2MCSR
, I2MCSR_EEMR
);
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 (DWORD_PTR dwIoBase
, BYTE byContntOffset
, BYTE byData
)
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
);
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 (DWORD_PTR dwIoBase
, BYTE byContntOffset
, BYTE byBits
)
185 byOrgData
= SROMbyReadEmbedded(dwIoBase
, byContntOffset
);
186 SROMbWriteEmbedded(dwIoBase
, byContntOffset
,(BYTE
)(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 (DWORD_PTR dwIoBase
, BYTE byContntOffset
, BYTE byBits
)
206 byOrgData
= SROMbyReadEmbedded(dwIoBase
, byContntOffset
);
207 SROMbWriteEmbedded(dwIoBase
, byContntOffset
,(BYTE
)(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 (DWORD_PTR dwIoBase
, BYTE byContntOffset
, BYTE byTestBits
)
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 (DWORD_PTR dwIoBase
, BYTE byContntOffset
, BYTE byTestBits
)
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 (DWORD_PTR dwIoBase
, PBYTE pbyEepromRegs
)
274 for (ii
= 0; ii
< EEP_MAX_CONTEXT_SIZE
; ii
++) {
275 *pbyEepromRegs
= SROMbyReadEmbedded(dwIoBase
,(BYTE
) ii
);
282 * Description: Write all contents of buffer to eeprom
286 * dwIoBase - I/O base address
287 * pbyEepromRegs - EEPROM content Buffer
294 void SROMvWriteAllContents (DWORD_PTR dwIoBase
, PBYTE pbyEepromRegs
)
299 for (ii
= 0; ii
< EEP_MAX_CONTEXT_SIZE
; ii
++) {
300 SROMbWriteEmbedded(dwIoBase
,(BYTE
) 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 (DWORD_PTR dwIoBase
, PBYTE pbyEtherAddress
)
323 for (ii
= 0; ii
< U_ETHER_ADDR_LEN
; 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 (DWORD_PTR dwIoBase
, PBYTE pbyEtherAddress
)
348 for (ii
= 0; ii
< U_ETHER_ADDR_LEN
; 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 (DWORD_PTR dwIoBase
, PDWORD pdwSubSysVenId
)
371 pbyData
= (PBYTE
)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 (DWORD_PTR dwIoBase
)
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
);
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
)