2 *************************************************************************
4 * 5F., No.36, Taiyuan St., Jhubei City,
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
25 *************************************************************************
31 Miniport generic portion header file
35 -------- ---------- ----------------------------------------------
38 #include "../rt_config.h"
41 // IRQL = PASSIVE_LEVEL
42 static inline VOID RaiseClock(
47 RTMP_IO_WRITE32(pAd, E2PROM_CSR, *x);
48 RTMPusecDelay(1); // Max frequency = 1MHz in Spec. definition
51 // IRQL = PASSIVE_LEVEL
52 static inline VOID LowerClock(
57 RTMP_IO_WRITE32(pAd, E2PROM_CSR, *x);
61 // IRQL = PASSIVE_LEVEL
62 static inline USHORT ShiftInBits(
68 RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
77 RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
78 LowerClock(pAd, &x); //prevent read failed
89 // IRQL = PASSIVE_LEVEL
90 static inline VOID ShiftOutBits(
97 mask = 0x01 << (count - 1);
98 RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
105 if(data & mask) x |= EEDI;
107 RTMP_IO_WRITE32(pAd, E2PROM_CSR, x);
116 RTMP_IO_WRITE32(pAd, E2PROM_CSR, x);
120 // IRQL = PASSIVE_LEVEL
121 static inline VOID EEpromCleanup(
122 IN PRTMP_ADAPTER pAd)
126 RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
129 RTMP_IO_WRITE32(pAd, E2PROM_CSR, x);
136 static inline VOID EWEN(
137 IN PRTMP_ADAPTER pAd)
141 // reset bits and set EECS
142 RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
143 x &= ~(EEDI | EEDO | EESK);
145 RTMP_IO_WRITE32(pAd, E2PROM_CSR, x);
151 // output the read_opcode and six pulse in that order
152 ShiftOutBits(pAd, EEPROM_EWEN_OPCODE, 5);
153 ShiftOutBits(pAd, 0, 6);
159 static inline VOID EWDS(
160 IN PRTMP_ADAPTER pAd)
164 // reset bits and set EECS
165 RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
166 x &= ~(EEDI | EEDO | EESK);
168 RTMP_IO_WRITE32(pAd, E2PROM_CSR, x);
174 // output the read_opcode and six pulse in that order
175 ShiftOutBits(pAd, EEPROM_EWDS_OPCODE, 5);
176 ShiftOutBits(pAd, 0, 6);
182 // IRQL = PASSIVE_LEVEL
183 int rtmp_ee_prom_read16(
184 IN PRTMP_ADAPTER pAd,
192 #ifdef ANT_DIVERSITY_SUPPORT
193 if (pAd->NicConfig2.field.AntDiversity)
195 pAd->EepromAccess = TRUE;
197 #endif // ANT_DIVERSITY_SUPPORT //
201 // reset bits and set EECS
202 RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
203 x &= ~(EEDI | EEDO | EESK);
205 RTMP_IO_WRITE32(pAd, E2PROM_CSR, x);
207 // patch can not access e-Fuse issue
208 if (!(IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd)))
215 // output the read_opcode and register number in that order
216 ShiftOutBits(pAd, EEPROM_READ_OPCODE, 3);
217 ShiftOutBits(pAd, Offset, pAd->EEPROMAddressNum);
219 // Now read the data (16 bits) in from the selected EEPROM word
220 data = ShiftInBits(pAd);
225 #ifdef ANT_DIVERSITY_SUPPORT
226 // Antenna and EEPROM access are both using EESK pin,
227 // Therefor we should avoid accessing EESK at the same time
228 // Then restore antenna after EEPROM access
229 if ((pAd->NicConfig2.field.AntDiversity)/* || (pAd->RfIcType == RFIC_3020)*/)
231 pAd->EepromAccess = FALSE;
232 AsicSetRxAnt(pAd, pAd->RxAnt.Pair1PrimaryRxAnt);
234 #endif // ANT_DIVERSITY_SUPPORT //
239 return NDIS_STATUS_SUCCESS;
243 int rtmp_ee_prom_write16(
244 IN PRTMP_ADAPTER pAd,
251 #ifdef ANT_DIVERSITY_SUPPORT
252 if (pAd->NicConfig2.field.AntDiversity)
254 pAd->EepromAccess = TRUE;
256 #endif // ANT_DIVERSITY_SUPPORT //
263 // reset bits and set EECS
264 RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
265 x &= ~(EEDI | EEDO | EESK);
267 RTMP_IO_WRITE32(pAd, E2PROM_CSR, x);
269 // patch can not access e-Fuse issue
270 if (!(IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd)))
277 // output the read_opcode ,register number and data in that order
278 ShiftOutBits(pAd, EEPROM_WRITE_OPCODE, 3);
279 ShiftOutBits(pAd, Offset, pAd->EEPROMAddressNum);
280 ShiftOutBits(pAd, Data, 16); // 16-bit access
283 RTMP_IO_READ32(pAd, E2PROM_CSR, &x);
287 RTMPusecDelay(10000); //delay for twp(MAX)=10ms
294 #ifdef ANT_DIVERSITY_SUPPORT
295 // Antenna and EEPROM access are both using EESK pin,
296 // Therefor we should avoid accessing EESK at the same time
297 // Then restore antenna after EEPROM access
298 if ((pAd->NicConfig2.field.AntDiversity) /*|| (pAd->RfIcType == RFIC_3020)*/)
300 pAd->EepromAccess = FALSE;
301 AsicSetRxAnt(pAd, pAd->RxAnt.Pair1PrimaryRxAnt);
303 #endif // ANT_DIVERSITY_SUPPORT //
306 return NDIS_STATUS_SUCCESS;