1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
6 * Purpose:Implement functions to access eeprom
13 * SROMbyReadEmbedded - Embedded read eeprom via MAC
14 * SROMbWriteEmbedded - Embedded write eeprom via MAC
15 * SROMvRegBitsOn - Set Bits On in eeprom
16 * SROMvRegBitsOff - Clear Bits Off in eeprom
17 * SROMbIsRegBitsOn - Test if Bits On in eeprom
18 * SROMbIsRegBitsOff - Test if Bits Off in eeprom
19 * SROMvReadAllContents - Read all contents in eeprom
20 * SROMvWriteAllContents - Write all contents in eeprom
21 * SROMvReadEtherAddress - Read Ethernet Address in eeprom
22 * SROMvWriteEtherAddress - Write Ethernet Address in eeprom
23 * SROMvReadSubSysVenId - Read Sub_VID and Sub_SysId in eeprom
24 * SROMbAutoLoad - Auto Load eeprom to MAC register
34 /*--------------------- Static Definitions -------------------------*/
36 /*--------------------- Static Classes ----------------------------*/
38 /*--------------------- Static Variables --------------------------*/
40 /*--------------------- Static Functions --------------------------*/
42 /*--------------------- Export Variables --------------------------*/
44 /*--------------------- Export Functions --------------------------*/
47 * Description: Read a byte from EEPROM, by MAC I2C
51 * iobase - I/O base address
52 * contnt_offset - address of EEPROM
56 * Return Value: data read
59 unsigned char SROMbyReadEmbedded(void __iomem *iobase,
60 unsigned char contnt_offset)
62 unsigned short wDelay, wNoACK;
67 byOrg = ioread8(iobase + MAC_REG_I2MCFG);
68 /* turn off hardware retry for getting NACK */
69 iowrite8(byOrg & (~I2MCFG_NORETRY), iobase + MAC_REG_I2MCFG);
70 for (wNoACK = 0; wNoACK < W_MAX_I2CRETRY; wNoACK++) {
71 iowrite8(EEP_I2C_DEV_ID, iobase + MAC_REG_I2MTGID);
72 iowrite8(contnt_offset, iobase + MAC_REG_I2MTGAD);
74 /* issue read command */
75 iowrite8(I2MCSR_EEMR, iobase + MAC_REG_I2MCSR);
76 /* wait DONE be set */
77 for (wDelay = 0; wDelay < W_MAX_TIMEOUT; wDelay++) {
78 byWait = ioread8(iobase + MAC_REG_I2MCSR);
79 if (byWait & (I2MCSR_DONE | I2MCSR_NACK))
81 udelay(CB_DELAY_LOOP_WAIT);
83 if ((wDelay < W_MAX_TIMEOUT) &&
84 (!(byWait & I2MCSR_NACK))) {
88 byData = ioread8(iobase + MAC_REG_I2MDIPT);
89 iowrite8(byOrg, iobase + MAC_REG_I2MCFG);
94 * Description: Read all contents of eeprom to buffer
98 * iobase - I/O base address
100 * pbyEepromRegs - EEPROM content Buffer
105 void SROMvReadAllContents(void __iomem *iobase, unsigned char *pbyEepromRegs)
109 /* ii = Rom Address */
110 for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) {
111 *pbyEepromRegs = SROMbyReadEmbedded(iobase,
118 * Description: Read Ethernet Address from eeprom to buffer
122 * iobase - I/O base address
124 * pbyEtherAddress - Ethernet Address buffer
129 void SROMvReadEtherAddress(void __iomem *iobase,
130 unsigned char *pbyEtherAddress)
134 /* ii = Rom Address */
135 for (ii = 0; ii < ETH_ALEN; ii++) {
136 *pbyEtherAddress = SROMbyReadEmbedded(iobase, ii);