1 // SPDX-License-Identifier: GPL-2.0+ 2 /* 3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. 4 * All rights reserved. 5 * 6 * Purpose:Implement functions to access eeprom 7 * 8 * Author: Jerry Chen 9 * 10 * Date: Jan 29, 2003 11 * 12 * Functions: 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 25 * 26 * Revision History: 27 * 28 */ 29 30 #include "upc.h" 31 #include "tmacro.h" 32 #include "mac.h" 33 #include "srom.h" 34 35 /*--------------------- Static Definitions -------------------------*/ 36 37 /*--------------------- Static Classes ----------------------------*/ 38 39 /*--------------------- Static Variables --------------------------*/ 40 41 /*--------------------- Static Functions --------------------------*/ 42 43 /*--------------------- Export Variables --------------------------*/ 44 45 /*--------------------- Export Functions --------------------------*/ 46 47 /* 48 * Description: Read a byte from EEPROM, by MAC I2C 49 * 50 * Parameters: 51 * In: 52 * iobase - I/O base address 53 * byContntOffset - address of EEPROM 54 * Out: 55 * none 56 * 57 * Return Value: data read 58 * 59 */ 60 unsigned char SROMbyReadEmbedded(void __iomem *iobase, 61 unsigned char byContntOffset) 62 { 63 unsigned short wDelay, wNoACK; 64 unsigned char byWait; 65 unsigned char byData; 66 unsigned char byOrg; 67 68 byData = 0xFF; 69 VNSvInPortB(iobase + MAC_REG_I2MCFG, &byOrg); 70 /* turn off hardware retry for getting NACK */ 71 VNSvOutPortB(iobase + MAC_REG_I2MCFG, (byOrg & (~I2MCFG_NORETRY))); 72 for (wNoACK = 0; wNoACK < W_MAX_I2CRETRY; wNoACK++) { 73 VNSvOutPortB(iobase + MAC_REG_I2MTGID, EEP_I2C_DEV_ID); 74 VNSvOutPortB(iobase + MAC_REG_I2MTGAD, byContntOffset); 75 76 /* issue read command */ 77 VNSvOutPortB(iobase + MAC_REG_I2MCSR, I2MCSR_EEMR); 78 /* wait DONE be set */ 79 for (wDelay = 0; wDelay < W_MAX_TIMEOUT; wDelay++) { 80 VNSvInPortB(iobase + MAC_REG_I2MCSR, &byWait); 81 if (byWait & (I2MCSR_DONE | I2MCSR_NACK)) 82 break; 83 PCAvDelayByIO(CB_DELAY_LOOP_WAIT); 84 } 85 if ((wDelay < W_MAX_TIMEOUT) && 86 (!(byWait & I2MCSR_NACK))) { 87 break; 88 } 89 } 90 VNSvInPortB(iobase + MAC_REG_I2MDIPT, &byData); 91 VNSvOutPortB(iobase + MAC_REG_I2MCFG, byOrg); 92 return byData; 93 } 94 95 /* 96 * Description: Read all contents of eeprom to buffer 97 * 98 * Parameters: 99 * In: 100 * iobase - I/O base address 101 * Out: 102 * pbyEepromRegs - EEPROM content Buffer 103 * 104 * Return Value: none 105 * 106 */ 107 void SROMvReadAllContents(void __iomem *iobase, unsigned char *pbyEepromRegs) 108 { 109 int ii; 110 111 /* ii = Rom Address */ 112 for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) { 113 *pbyEepromRegs = SROMbyReadEmbedded(iobase, 114 (unsigned char)ii); 115 pbyEepromRegs++; 116 } 117 } 118 119 /* 120 * Description: Read Ethernet Address from eeprom to buffer 121 * 122 * Parameters: 123 * In: 124 * iobase - I/O base address 125 * Out: 126 * pbyEtherAddress - Ethernet Address buffer 127 * 128 * Return Value: none 129 * 130 */ 131 void SROMvReadEtherAddress(void __iomem *iobase, 132 unsigned char *pbyEtherAddress) 133 { 134 unsigned char ii; 135 136 /* ii = Rom Address */ 137 for (ii = 0; ii < ETH_ALEN; ii++) { 138 *pbyEtherAddress = SROMbyReadEmbedded(iobase, ii); 139 pbyEtherAddress++; 140 } 141 } 142