MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / net / wireless / rtlink / eeprom.c
blob122b25a776a90ec5beba4c5eafa648cc6d8da9d7
1 /*************************************************************************
2 * Ralink Tech Inc. *
3 * 4F, No. 2 Technology 5th Rd. *
4 * Science-based Industrial Park *
5 * Hsin-chu, Taiwan, R.O.C. *
6 * *
7 * (c) Copyright 2002, Ralink Technology, Inc. *
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 * This program is distributed in the hope that it will be useful, *
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17 * GNU General Public License for more details. *
18 * *
19 * You should have received a copy of the GNU General Public License *
20 * along with this program; if not, write to the *
21 * Free Software Foundation, Inc., *
22 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
23 * *
24 ************************************************************************/
25 #include "rt_config.h"
27 VOID RaiseClock(
28 IN PRTMP_ADAPTER pAd,
29 IN ULONG *x)
31 *x = *x | EESK;
32 RTMP_IO_WRITE32(pAd, CSR21, *x);
33 udelay(1);
36 VOID LowerClock(
37 IN PRTMP_ADAPTER pAd,
38 IN ULONG *x)
40 *x = *x & ~EESK;
41 RTMP_IO_WRITE32(pAd, CSR21, *x);
42 udelay(1);
45 USHORT ShiftInBits(
46 IN PRTMP_ADAPTER pAd)
48 ULONG x,i;
49 USHORT data=0;
51 RTMP_IO_READ32(pAd, CSR21, &x);
53 x &= ~( EEDO | EEDI);
55 for(i=0; i<16; i++)
57 data = data << 1;
58 RaiseClock(pAd, &x);
60 RTMP_IO_READ32(pAd, CSR21, &x);
62 x &= ~(EEDI);
63 if(x & EEDO)
64 data |= 1;
66 LowerClock(pAd, &x);
69 return data;
72 VOID ShiftOutBits(
73 IN PRTMP_ADAPTER pAd,
74 IN USHORT data,
75 IN USHORT count)
77 ULONG x,mask;
79 mask = 0x01 << (count - 1);
80 RTMP_IO_READ32(pAd, CSR21, &x);
82 x &= ~(EEDO | EEDI);
86 x &= ~EEDI;
87 if(data & mask) x |= EEDI;
89 RTMP_IO_WRITE32(pAd, CSR21, x);
91 RaiseClock(pAd, &x);
92 LowerClock(pAd, &x);
94 mask = mask >> 1;
95 } while(mask);
97 x &= ~EEDI;
98 RTMP_IO_WRITE32(pAd, CSR21, x);
101 VOID EEpromCleanup(
102 IN PRTMP_ADAPTER pAd)
104 ULONG x;
106 RTMP_IO_READ32(pAd, CSR21, &x);
108 x &= ~(EECS | EEDI);
109 RTMP_IO_WRITE32(pAd, CSR21, x);
111 RaiseClock(pAd, &x);
112 LowerClock(pAd, &x);
115 VOID EWEN(
116 IN PRTMP_ADAPTER pAd)
118 ULONG x;
120 // reset bits and set EECS
121 RTMP_IO_READ32(pAd, CSR21, &x);
122 x &= ~(EEDI | EEDO | EESK);
123 x |= EECS;
124 RTMP_IO_WRITE32(pAd, CSR21, x);
126 // kick a pulse
127 RaiseClock(pAd, &x);
128 LowerClock(pAd, &x);
130 // output the read_opcode and six pulse in that order
131 ShiftOutBits(pAd, EEPROM_EWEN_OPCODE, 5);
132 ShiftOutBits(pAd, 0, 6);
134 EEpromCleanup(pAd);
137 VOID EWDS(
138 IN PRTMP_ADAPTER pAd)
140 ULONG x;
142 // reset bits and set EECS
143 RTMP_IO_READ32(pAd, CSR21, &x);
144 x &= ~(EEDI | EEDO | EESK);
145 x |= EECS;
146 RTMP_IO_WRITE32(pAd, CSR21, x);
148 // kick a pulse
149 RaiseClock(pAd, &x);
150 LowerClock(pAd, &x);
152 // output the read_opcode and six pulse in that order
153 ShiftOutBits(pAd, EEPROM_EWDS_OPCODE, 5);
154 ShiftOutBits(pAd, 0, 6);
156 EEpromCleanup(pAd);
159 USHORT RTMP_EEPROM_READ16(
160 IN PRTMP_ADAPTER pAd,
161 IN USHORT Offset)
163 ULONG x;
164 USHORT data;
166 Offset /= 2;
167 // reset bits and set EECS
168 RTMP_IO_READ32(pAd, CSR21, &x);
169 x &= ~(EEDI | EEDO | EESK);
170 x |= EECS;
171 RTMP_IO_WRITE32(pAd, CSR21, x);
173 // kick a pulse
174 RaiseClock(pAd, &x);
175 LowerClock(pAd, &x);
177 // output the read_opcode and register number in that order
178 ShiftOutBits(pAd, EEPROM_READ_OPCODE, 3);
179 ShiftOutBits(pAd, Offset, pAd->EEPROMAddressNum);
181 // Now read the data (16 bits) in from the selected EEPROM word
182 data = ShiftInBits(pAd);
184 EEpromCleanup(pAd);
186 return data;
187 } //ReadEEprom
189 VOID RTMP_EEPROM_WRITE16(
190 IN PRTMP_ADAPTER pAd,
191 IN USHORT Offset,
192 IN USHORT Data)
194 ULONG i, x;
196 Offset /= 2;
198 EWEN(pAd);
200 // reset bits and set EECS
201 RTMP_IO_READ32(pAd, CSR21, &x);
202 x &= ~(EEDI | EEDO | EESK);
203 x |= EECS;
204 RTMP_IO_WRITE32(pAd, CSR21, x);
206 // kick a pulse
207 RaiseClock(pAd, &x);
208 LowerClock(pAd, &x);
210 // output the read_opcode ,register number and data in that order
211 ShiftOutBits(pAd, EEPROM_WRITE_OPCODE, 3);
212 ShiftOutBits(pAd, Offset, pAd->EEPROMAddressNum);
213 ShiftOutBits(pAd, Data, 16); // 16-bit access
215 // read DO status
216 RTMP_IO_READ32(pAd, CSR21, &x);
218 EEpromCleanup(pAd);
220 for(i=0; i<10; i++)
221 udelay(1000); //delay for twp(MAX)=10ms
223 EWDS(pAd);
225 EEpromCleanup(pAd);