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