Linux 4.16.11
[linux/fpc-iii.git] / drivers / staging / vt6655 / srom.c
blobdf57d120ed30eb508686ed4970224914b72366e9
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
4 * All rights reserved.
6 * File: srom.c
8 * Purpose:Implement functions to access eeprom
10 * Author: Jerry Chen
12 * Date: Jan 29, 2003
14 * Functions:
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
28 * Revision History:
32 #include "upc.h"
33 #include "tmacro.h"
34 #include "mac.h"
35 #include "srom.h"
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
52 * Parameters:
53 * In:
54 * iobase - I/O base address
55 * byContntOffset - address of EEPROM
56 * Out:
57 * none
59 * Return Value: data read
62 unsigned char SROMbyReadEmbedded(void __iomem *iobase,
63 unsigned char byContntOffset)
65 unsigned short wDelay, wNoACK;
66 unsigned char byWait;
67 unsigned char byData;
68 unsigned char byOrg;
70 byData = 0xFF;
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))
84 break;
85 PCAvDelayByIO(CB_DELAY_LOOP_WAIT);
87 if ((wDelay < W_MAX_TIMEOUT) &&
88 (!(byWait & I2MCSR_NACK))) {
89 break;
92 VNSvInPortB(iobase + MAC_REG_I2MDIPT, &byData);
93 VNSvOutPortB(iobase + MAC_REG_I2MCFG, byOrg);
94 return byData;
98 * Description: Read all contents of eeprom to buffer
100 * Parameters:
101 * In:
102 * iobase - I/O base address
103 * Out:
104 * pbyEepromRegs - EEPROM content Buffer
106 * Return Value: none
109 void SROMvReadAllContents(void __iomem *iobase, unsigned char *pbyEepromRegs)
111 int ii;
113 /* ii = Rom Address */
114 for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) {
115 *pbyEepromRegs = SROMbyReadEmbedded(iobase,
116 (unsigned char)ii);
117 pbyEepromRegs++;
122 * Description: Read Ethernet Address from eeprom to buffer
124 * Parameters:
125 * In:
126 * iobase - I/O base address
127 * Out:
128 * pbyEtherAddress - Ethernet Address buffer
130 * Return Value: none
133 void SROMvReadEtherAddress(void __iomem *iobase,
134 unsigned char *pbyEtherAddress)
136 unsigned char ii;
138 /* ii = Rom Address */
139 for (ii = 0; ii < ETH_ALEN; ii++) {
140 *pbyEtherAddress = SROMbyReadEmbedded(iobase, ii);
141 pbyEtherAddress++;