nfsd: Add fh_{want,drop}_write()
[linux/fpc-iii.git] / drivers / staging / vt6655 / srom.c
blob6a0a232d1a0c80b14d53f9312f0fb870a31a3b7e
1 /*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
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.
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.
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.
19 * File: srom.c
21 * Purpose:Implement functions to access eeprom
23 * Author: Jerry Chen
25 * Date: Jan 29, 2003
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
41 * Revision History:
45 #include "upc.h"
46 #include "tmacro.h"
47 #include "tether.h"
48 #include "mac.h"
49 #include "srom.h"
51 /*--------------------- Static Definitions -------------------------*/
53 /*--------------------- Static Classes ----------------------------*/
55 /*--------------------- Static Variables --------------------------*/
57 /*--------------------- Static Functions --------------------------*/
59 /*--------------------- Export Variables --------------------------*/
61 /*--------------------- Export Functions --------------------------*/
67 * Description: Read a byte from EEPROM, by MAC I2C
69 * Parameters:
70 * In:
71 * dwIoBase - I/O base address
72 * byContntOffset - address of EEPROM
73 * Out:
74 * none
76 * Return Value: data read
79 unsigned char SROMbyReadEmbedded(unsigned long dwIoBase, unsigned char byContntOffset)
81 unsigned short wDelay, wNoACK;
82 unsigned char byWait;
83 unsigned char byData;
84 unsigned char byOrg;
86 byData = 0xFF;
87 VNSvInPortB(dwIoBase + MAC_REG_I2MCFG, &byOrg);
88 /* turn off hardware retry for getting NACK */
89 VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, (byOrg & (~I2MCFG_NORETRY)));
90 for (wNoACK = 0; wNoACK < W_MAX_I2CRETRY; wNoACK++) {
91 VNSvOutPortB(dwIoBase + MAC_REG_I2MTGID, EEP_I2C_DEV_ID);
92 VNSvOutPortB(dwIoBase + MAC_REG_I2MTGAD, byContntOffset);
94 /* issue read command */
95 VNSvOutPortB(dwIoBase + MAC_REG_I2MCSR, I2MCSR_EEMR);
96 /* wait DONE be set */
97 for (wDelay = 0; wDelay < W_MAX_TIMEOUT; wDelay++) {
98 VNSvInPortB(dwIoBase + MAC_REG_I2MCSR, &byWait);
99 if (byWait & (I2MCSR_DONE | I2MCSR_NACK))
100 break;
101 PCAvDelayByIO(CB_DELAY_LOOP_WAIT);
103 if ((wDelay < W_MAX_TIMEOUT) &&
104 ( !(byWait & I2MCSR_NACK))) {
105 break;
108 VNSvInPortB(dwIoBase + MAC_REG_I2MDIPT, &byData);
109 VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg);
110 return byData;
115 * Description: Write a byte to EEPROM, by MAC I2C
117 * Parameters:
118 * In:
119 * dwIoBase - I/O base address
120 * byContntOffset - address of EEPROM
121 * wData - data to write
122 * Out:
123 * none
125 * Return Value: true if succeeded; false if failed.
128 bool SROMbWriteEmbedded(unsigned long dwIoBase, unsigned char byContntOffset, unsigned char byData)
130 unsigned short wDelay, wNoACK;
131 unsigned char byWait;
133 unsigned char byOrg;
135 VNSvInPortB(dwIoBase + MAC_REG_I2MCFG, &byOrg);
136 /* turn off hardware retry for getting NACK */
137 VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, (byOrg & (~I2MCFG_NORETRY)));
138 for (wNoACK = 0; wNoACK < W_MAX_I2CRETRY; wNoACK++) {
139 VNSvOutPortB(dwIoBase + MAC_REG_I2MTGID, EEP_I2C_DEV_ID);
140 VNSvOutPortB(dwIoBase + MAC_REG_I2MTGAD, byContntOffset);
141 VNSvOutPortB(dwIoBase + MAC_REG_I2MDOPT, byData);
143 /* issue write command */
144 VNSvOutPortB(dwIoBase + MAC_REG_I2MCSR, I2MCSR_EEMW);
145 /* wait DONE be set */
146 for (wDelay = 0; wDelay < W_MAX_TIMEOUT; wDelay++) {
147 VNSvInPortB(dwIoBase + MAC_REG_I2MCSR, &byWait);
148 if (byWait & (I2MCSR_DONE | I2MCSR_NACK))
149 break;
150 PCAvDelayByIO(CB_DELAY_LOOP_WAIT);
153 if ((wDelay < W_MAX_TIMEOUT) &&
154 ( !(byWait & I2MCSR_NACK))) {
155 break;
158 if (wNoACK == W_MAX_I2CRETRY) {
159 VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg);
160 return false;
162 VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg);
163 return true;
168 * Description: Turn bits on in eeprom
170 * Parameters:
171 * In:
172 * dwIoBase - I/O base address
173 * byContntOffset - address of EEPROM
174 * byBits - bits to turn on
175 * Out:
176 * none
178 * Return Value: none
181 void SROMvRegBitsOn(unsigned long dwIoBase, unsigned char byContntOffset, unsigned char byBits)
183 unsigned char byOrgData;
185 byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset);
186 SROMbWriteEmbedded(dwIoBase, byContntOffset,(unsigned char)(byOrgData | byBits));
191 * Description: Turn bits off in eeprom
193 * Parameters:
194 * In:
195 * dwIoBase - I/O base address
196 * byContntOffset - address of EEPROM
197 * byBits - bits to turn off
198 * Out:
199 * none
202 void SROMvRegBitsOff(unsigned long dwIoBase, unsigned char byContntOffset, unsigned char byBits)
204 unsigned char byOrgData;
206 byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset);
207 SROMbWriteEmbedded(dwIoBase, byContntOffset,(unsigned char)(byOrgData & (~byBits)));
212 * Description: Test if bits on in eeprom
214 * Parameters:
215 * In:
216 * dwIoBase - I/O base address
217 * byContntOffset - address of EEPROM
218 * byTestBits - bits to test
219 * Out:
220 * none
222 * Return Value: true if all test bits on; otherwise false
225 bool SROMbIsRegBitsOn(unsigned long dwIoBase, unsigned char byContntOffset, unsigned char byTestBits)
227 unsigned char byOrgData;
229 byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset);
230 return (byOrgData & byTestBits) == byTestBits;
235 * Description: Test if bits off in eeprom
237 * Parameters:
238 * In:
239 * dwIoBase - I/O base address
240 * byContntOffset - address of EEPROM
241 * byTestBits - bits to test
242 * Out:
243 * none
245 * Return Value: true if all test bits off; otherwise false
248 bool SROMbIsRegBitsOff(unsigned long dwIoBase, unsigned char byContntOffset, unsigned char byTestBits)
250 unsigned char byOrgData;
252 byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset);
253 return !(byOrgData & byTestBits);
258 * Description: Read all contents of eeprom to buffer
260 * Parameters:
261 * In:
262 * dwIoBase - I/O base address
263 * Out:
264 * pbyEepromRegs - EEPROM content Buffer
266 * Return Value: none
269 void SROMvReadAllContents(unsigned long dwIoBase, unsigned char *pbyEepromRegs)
271 int ii;
273 /* ii = Rom Address */
274 for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) {
275 *pbyEepromRegs = SROMbyReadEmbedded(dwIoBase,(unsigned char) ii);
276 pbyEepromRegs++;
282 * Description: Write all contents of buffer to eeprom
284 * Parameters:
285 * In:
286 * dwIoBase - I/O base address
287 * pbyEepromRegs - EEPROM content Buffer
288 * Out:
289 * none
291 * Return Value: none
294 void SROMvWriteAllContents(unsigned long dwIoBase, unsigned char *pbyEepromRegs)
296 int ii;
298 /* ii = Rom Address */
299 for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) {
300 SROMbWriteEmbedded(dwIoBase,(unsigned char) ii, *pbyEepromRegs);
301 pbyEepromRegs++;
307 * Description: Read Ethernet Address from eeprom to buffer
309 * Parameters:
310 * In:
311 * dwIoBase - I/O base address
312 * Out:
313 * pbyEtherAddress - Ethernet Address buffer
315 * Return Value: none
318 void SROMvReadEtherAddress(unsigned long dwIoBase, unsigned char *pbyEtherAddress)
320 unsigned char ii;
322 /* ii = Rom Address */
323 for (ii = 0; ii < ETH_ALEN; ii++) {
324 *pbyEtherAddress = SROMbyReadEmbedded(dwIoBase, ii);
325 pbyEtherAddress++;
331 * Description: Write Ethernet Address from buffer to eeprom
333 * Parameters:
334 * In:
335 * dwIoBase - I/O base address
336 * pbyEtherAddress - Ethernet Address buffer
337 * Out:
338 * none
340 * Return Value: none
343 void SROMvWriteEtherAddress(unsigned long dwIoBase, unsigned char *pbyEtherAddress)
345 unsigned char ii;
347 /* ii = Rom Address */
348 for (ii = 0; ii < ETH_ALEN; ii++) {
349 SROMbWriteEmbedded(dwIoBase, ii, *pbyEtherAddress);
350 pbyEtherAddress++;
356 * Description: Read Sub_VID and Sub_SysId from eeprom to buffer
358 * Parameters:
359 * In:
360 * dwIoBase - I/O base address
361 * Out:
362 * pdwSubSysVenId - Sub_VID and Sub_SysId read
364 * Return Value: none
367 void SROMvReadSubSysVenId(unsigned long dwIoBase, unsigned long *pdwSubSysVenId)
369 unsigned char *pbyData;
371 pbyData = (unsigned char *)pdwSubSysVenId;
372 /* sub vendor */
373 *pbyData = SROMbyReadEmbedded(dwIoBase, 6);
374 *(pbyData+1) = SROMbyReadEmbedded(dwIoBase, 7);
375 /* sub system */
376 *(pbyData+2) = SROMbyReadEmbedded(dwIoBase, 8);
377 *(pbyData+3) = SROMbyReadEmbedded(dwIoBase, 9);
381 * Description: Auto Load EEPROM to MAC register
383 * Parameters:
384 * In:
385 * dwIoBase - I/O base address
386 * Out:
387 * none
389 * Return Value: true if success; otherwise false
392 bool SROMbAutoLoad(unsigned long dwIoBase)
394 unsigned char byWait;
395 int ii;
397 unsigned char byOrg;
399 VNSvInPortB(dwIoBase + MAC_REG_I2MCFG, &byOrg);
400 /* turn on hardware retry */
401 VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, (byOrg | I2MCFG_NORETRY));
403 MACvRegBitsOn(dwIoBase, MAC_REG_I2MCSR, I2MCSR_AUTOLD);
405 /* ii = Rom Address */
406 for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) {
407 MACvTimer0MicroSDelay(dwIoBase, CB_EEPROM_READBYTE_WAIT);
408 VNSvInPortB(dwIoBase + MAC_REG_I2MCSR, &byWait);
409 if ( !(byWait & I2MCSR_AUTOLD))
410 break;
413 VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg);
415 if (ii == EEP_MAX_CONTEXT_SIZE)
416 return false;
417 return true;