MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / net / wireless / rtlink.org / eeprom.c
blob5fae9c80fda2cc6f93b0d5ce532be57077e0cd1a
1 /*
2 ***************************************************************************
3 * Ralink Tech Inc.
4 * 4F, No. 2 Technology 5th Rd.
5 * Science-based Industrial Park
6 * Hsin-chu, Taiwan, R.O.C.
8 * (c) Copyright 2002, Ralink Technology, Inc.
10 * All rights reserved. Ralink's source code is an unpublished work and the
11 * use of a copyright notice does not imply otherwise. This source code
12 * contains confidential trade secret material of Ralink Tech. Any attemp
13 * or participation in deciphering, decoding, reverse engineering or in any
14 * way altering the source code is stricitly prohibited, unless the prior
15 * written consent of Ralink Technology, Inc. is obtained.
16 ***************************************************************************/
17 #include "rt_config.h"
19 VOID RaiseClock(
20 IN PRTMP_ADAPTER pAd,
21 IN ULONG *x)
23 *x = *x | EESK;
24 RTMP_IO_WRITE32(pAd, CSR21, *x);
25 udelay(1);
28 VOID LowerClock(
29 IN PRTMP_ADAPTER pAd,
30 IN ULONG *x)
32 *x = *x & ~EESK;
33 RTMP_IO_WRITE32(pAd, CSR21, *x);
34 udelay(1);
37 USHORT ShiftInBits(
38 IN PRTMP_ADAPTER pAd)
40 ULONG x,i;
41 USHORT data=0;
43 RTMP_IO_READ32(pAd, CSR21, &x);
45 x &= ~( EEDO | EEDI);
47 for(i=0; i<16; i++)
49 data = data << 1;
50 RaiseClock(pAd, &x);
52 RTMP_IO_READ32(pAd, CSR21, &x);
54 x &= ~(EEDI);
55 if(x & EEDO)
56 data |= 1;
58 LowerClock(pAd, &x);
61 return data;
64 VOID ShiftOutBits(
65 IN PRTMP_ADAPTER pAd,
66 IN USHORT data,
67 IN USHORT count)
69 ULONG x,mask;
71 mask = 0x01 << (count - 1);
72 RTMP_IO_READ32(pAd, CSR21, &x);
74 x &= ~(EEDO | EEDI);
78 x &= ~EEDI;
79 if(data & mask) x |= EEDI;
81 RTMP_IO_WRITE32(pAd, CSR21, x);
83 RaiseClock(pAd, &x);
84 LowerClock(pAd, &x);
86 mask = mask >> 1;
87 } while(mask);
89 x &= ~EEDI;
90 RTMP_IO_WRITE32(pAd, CSR21, x);
93 VOID EEpromCleanup(
94 IN PRTMP_ADAPTER pAd)
96 ULONG x;
98 RTMP_IO_READ32(pAd, CSR21, &x);
100 x &= ~(EECS | EEDI);
101 RTMP_IO_WRITE32(pAd, CSR21, x);
103 RaiseClock(pAd, &x);
104 LowerClock(pAd, &x);
107 VOID EWEN(
108 IN PRTMP_ADAPTER pAd)
110 ULONG x;
112 // reset bits and set EECS
113 RTMP_IO_READ32(pAd, CSR21, &x);
114 x &= ~(EEDI | EEDO | EESK);
115 x |= EECS;
116 RTMP_IO_WRITE32(pAd, CSR21, x);
118 // kick a pulse
119 RaiseClock(pAd, &x);
120 LowerClock(pAd, &x);
122 // output the read_opcode and six pulse in that order
123 ShiftOutBits(pAd, EEPROM_EWEN_OPCODE, 5);
124 ShiftOutBits(pAd, 0, 6);
126 EEpromCleanup(pAd);
129 VOID EWDS(
130 IN PRTMP_ADAPTER pAd)
132 ULONG x;
134 // reset bits and set EECS
135 RTMP_IO_READ32(pAd, CSR21, &x);
136 x &= ~(EEDI | EEDO | EESK);
137 x |= EECS;
138 RTMP_IO_WRITE32(pAd, CSR21, x);
140 // kick a pulse
141 RaiseClock(pAd, &x);
142 LowerClock(pAd, &x);
144 // output the read_opcode and six pulse in that order
145 ShiftOutBits(pAd, EEPROM_EWDS_OPCODE, 5);
146 ShiftOutBits(pAd, 0, 6);
148 EEpromCleanup(pAd);
151 USHORT RTMP_EEPROM_READ16(
152 IN PRTMP_ADAPTER pAd,
153 IN USHORT Offset)
155 ULONG x;
156 USHORT data;
158 Offset /= 2;
159 // reset bits and set EECS
160 RTMP_IO_READ32(pAd, CSR21, &x);
161 x &= ~(EEDI | EEDO | EESK);
162 x |= EECS;
163 RTMP_IO_WRITE32(pAd, CSR21, x);
165 // kick a pulse
166 RaiseClock(pAd, &x);
167 LowerClock(pAd, &x);
169 // output the read_opcode and register number in that order
170 ShiftOutBits(pAd, EEPROM_READ_OPCODE, 3);
171 ShiftOutBits(pAd, Offset, pAd->EEPROMAddressNum);
173 // Now read the data (16 bits) in from the selected EEPROM word
174 data = ShiftInBits(pAd);
176 EEpromCleanup(pAd);
178 return data;
179 } //ReadEEprom
181 VOID RTMP_EEPROM_WRITE16(
182 IN PRTMP_ADAPTER pAd,
183 IN USHORT Offset,
184 IN USHORT Data)
186 ULONG i, x;
188 Offset /= 2;
190 EWEN(pAd);
192 // reset bits and set EECS
193 RTMP_IO_READ32(pAd, CSR21, &x);
194 x &= ~(EEDI | EEDO | EESK);
195 x |= EECS;
196 RTMP_IO_WRITE32(pAd, CSR21, x);
198 // kick a pulse
199 RaiseClock(pAd, &x);
200 LowerClock(pAd, &x);
202 // output the read_opcode ,register number and data in that order
203 ShiftOutBits(pAd, EEPROM_WRITE_OPCODE, 3);
204 ShiftOutBits(pAd, Offset, pAd->EEPROMAddressNum);
205 ShiftOutBits(pAd, Data, 16); // 16-bit access
207 // read DO status
208 RTMP_IO_READ32(pAd, CSR21, &x);
210 EEpromCleanup(pAd);
212 for(i=0; i<10; i++)
213 udelay(1000); //delay for twp(MAX)=10ms
215 EWDS(pAd);
217 EEpromCleanup(pAd);