1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
8 * Purpose:Implement functions to access eeprom
15 * SROMbyReadEmbedded - Embedded read eeprom via MAC
16 * SROMbWriteEmbedded - Embedded write eeprom via MAC
17 * SROMvRegBitsOn - Set Bits On in eeprom
18 * SROMvRegBitsOff - Clear Bits Off in eeprom
19 * SROMbIsRegBitsOn - Test if Bits On in eeprom
20 * SROMbIsRegBitsOff - Test if Bits Off in eeprom
21 * SROMvReadAllContents - Read all contents in eeprom
22 * SROMvWriteAllContents - Write all contents in eeprom
23 * SROMvReadEtherAddress - Read Ethernet Address in eeprom
24 * SROMvWriteEtherAddress - Write Ethernet Address in eeprom
25 * SROMvReadSubSysVenId - Read Sub_VID and Sub_SysId in eeprom
26 * SROMbAutoLoad - Auto Load eeprom to MAC register
37 /*--------------------- Static Definitions -------------------------*/
39 /*--------------------- Static Classes ----------------------------*/
41 /*--------------------- Static Variables --------------------------*/
43 /*--------------------- Static Functions --------------------------*/
45 /*--------------------- Export Variables --------------------------*/
47 /*--------------------- Export Functions --------------------------*/
50 * Description: Read a byte from EEPROM, by MAC I2C
54 * iobase - I/O base address
55 * byContntOffset - address of EEPROM
59 * Return Value: data read
62 unsigned char SROMbyReadEmbedded(void __iomem *iobase,
63 unsigned char byContntOffset)
65 unsigned short wDelay, wNoACK;
71 VNSvInPortB(iobase + MAC_REG_I2MCFG, &byOrg);
72 /* turn off hardware retry for getting NACK */
73 VNSvOutPortB(iobase + MAC_REG_I2MCFG, (byOrg & (~I2MCFG_NORETRY)));
74 for (wNoACK = 0; wNoACK < W_MAX_I2CRETRY; wNoACK++) {
75 VNSvOutPortB(iobase + MAC_REG_I2MTGID, EEP_I2C_DEV_ID);
76 VNSvOutPortB(iobase + MAC_REG_I2MTGAD, byContntOffset);
78 /* issue read command */
79 VNSvOutPortB(iobase + MAC_REG_I2MCSR, I2MCSR_EEMR);
80 /* wait DONE be set */
81 for (wDelay = 0; wDelay < W_MAX_TIMEOUT; wDelay++) {
82 VNSvInPortB(iobase + MAC_REG_I2MCSR, &byWait);
83 if (byWait & (I2MCSR_DONE | I2MCSR_NACK))
85 PCAvDelayByIO(CB_DELAY_LOOP_WAIT);
87 if ((wDelay < W_MAX_TIMEOUT) &&
88 (!(byWait & I2MCSR_NACK))) {
92 VNSvInPortB(iobase + MAC_REG_I2MDIPT, &byData);
93 VNSvOutPortB(iobase + MAC_REG_I2MCFG, byOrg);
98 * Description: Read all contents of eeprom to buffer
102 * iobase - I/O base address
104 * pbyEepromRegs - EEPROM content Buffer
109 void SROMvReadAllContents(void __iomem *iobase, unsigned char *pbyEepromRegs)
113 /* ii = Rom Address */
114 for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) {
115 *pbyEepromRegs = SROMbyReadEmbedded(iobase,
122 * Description: Read Ethernet Address from eeprom to buffer
126 * iobase - I/O base address
128 * pbyEtherAddress - Ethernet Address buffer
133 void SROMvReadEtherAddress(void __iomem *iobase,
134 unsigned char *pbyEtherAddress)
138 /* ii = Rom Address */
139 for (ii = 0; ii < ETH_ALEN; ii++) {
140 *pbyEtherAddress = SROMbyReadEmbedded(iobase, ii);