mtd: nand: brcmnand: Check flash #WP pin status before nand erase/program
[linux/fpc-iii.git] / drivers / staging / vt6655 / srom.c
blobee992772066f8f522fa1b8c80ea885ec0d27f835
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 "mac.h"
48 #include "srom.h"
50 /*--------------------- Static Definitions -------------------------*/
52 /*--------------------- Static Classes ----------------------------*/
54 /*--------------------- Static Variables --------------------------*/
56 /*--------------------- Static Functions --------------------------*/
58 /*--------------------- Export Variables --------------------------*/
60 /*--------------------- Export Functions --------------------------*/
63 * Description: Read a byte from EEPROM, by MAC I2C
65 * Parameters:
66 * In:
67 * dwIoBase - I/O base address
68 * byContntOffset - address of EEPROM
69 * Out:
70 * none
72 * Return Value: data read
75 unsigned char SROMbyReadEmbedded(void __iomem *dwIoBase,
76 unsigned char byContntOffset)
78 unsigned short wDelay, wNoACK;
79 unsigned char byWait;
80 unsigned char byData;
81 unsigned char byOrg;
83 byData = 0xFF;
84 VNSvInPortB(dwIoBase + MAC_REG_I2MCFG, &byOrg);
85 /* turn off hardware retry for getting NACK */
86 VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, (byOrg & (~I2MCFG_NORETRY)));
87 for (wNoACK = 0; wNoACK < W_MAX_I2CRETRY; wNoACK++) {
88 VNSvOutPortB(dwIoBase + MAC_REG_I2MTGID, EEP_I2C_DEV_ID);
89 VNSvOutPortB(dwIoBase + MAC_REG_I2MTGAD, byContntOffset);
91 /* issue read command */
92 VNSvOutPortB(dwIoBase + MAC_REG_I2MCSR, I2MCSR_EEMR);
93 /* wait DONE be set */
94 for (wDelay = 0; wDelay < W_MAX_TIMEOUT; wDelay++) {
95 VNSvInPortB(dwIoBase + MAC_REG_I2MCSR, &byWait);
96 if (byWait & (I2MCSR_DONE | I2MCSR_NACK))
97 break;
98 PCAvDelayByIO(CB_DELAY_LOOP_WAIT);
100 if ((wDelay < W_MAX_TIMEOUT) &&
101 (!(byWait & I2MCSR_NACK))) {
102 break;
105 VNSvInPortB(dwIoBase + MAC_REG_I2MDIPT, &byData);
106 VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg);
107 return byData;
111 * Description: Read all contents of eeprom to buffer
113 * Parameters:
114 * In:
115 * dwIoBase - I/O base address
116 * Out:
117 * pbyEepromRegs - EEPROM content Buffer
119 * Return Value: none
122 void SROMvReadAllContents(void __iomem *dwIoBase, unsigned char *pbyEepromRegs)
124 int ii;
126 /* ii = Rom Address */
127 for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) {
128 *pbyEepromRegs = SROMbyReadEmbedded(dwIoBase,
129 (unsigned char)ii);
130 pbyEepromRegs++;
135 * Description: Read Ethernet Address from eeprom to buffer
137 * Parameters:
138 * In:
139 * dwIoBase - I/O base address
140 * Out:
141 * pbyEtherAddress - Ethernet Address buffer
143 * Return Value: none
146 void SROMvReadEtherAddress(void __iomem *dwIoBase,
147 unsigned char *pbyEtherAddress)
149 unsigned char ii;
151 /* ii = Rom Address */
152 for (ii = 0; ii < ETH_ALEN; ii++) {
153 *pbyEtherAddress = SROMbyReadEmbedded(dwIoBase, ii);
154 pbyEtherAddress++;