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 Ralink Wireless driver RF related functions
35 -------- ---------- ----------------------------------------------
38 #include "../rt_config.h"
40 #ifdef RTMP_RF_RW_SUPPORT
42 ========================================================================
44 Routine Description: Write RT30xx RF register through MAC
54 ========================================================================
56 int RT30xxWriteRFRegister(struct rt_rtmp_adapter *pAd,
59 RF_CSR_CFG_STRUC rfcsr;
63 RTMP_IO_READ32(pAd, RF_CSR_CFG, &rfcsr.word);
65 if (!rfcsr.field.RF_CSR_KICK)
69 while ((i < RETRY_LIMIT)
70 && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)));
72 if ((i == RETRY_LIMIT)
73 || (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) {
74 DBGPRINT_RAW(RT_DEBUG_ERROR,
75 ("Retry count exhausted or device removed!\n"));
76 return STATUS_UNSUCCESSFUL;
79 rfcsr.field.RF_CSR_WR = 1;
80 rfcsr.field.RF_CSR_KICK = 1;
81 rfcsr.field.TESTCSR_RFACC_REGNUM = regID;
82 rfcsr.field.RF_CSR_DATA = value;
84 RTMP_IO_WRITE32(pAd, RF_CSR_CFG, rfcsr.word);
86 return NDIS_STATUS_SUCCESS;
90 ========================================================================
92 Routine Description: Read RT30xx RF register through MAC
102 ========================================================================
104 int RT30xxReadRFRegister(struct rt_rtmp_adapter *pAd,
105 u8 regID, u8 *pValue)
107 RF_CSR_CFG_STRUC rfcsr;
110 for (i = 0; i < MAX_BUSY_COUNT; i++) {
111 RTMP_IO_READ32(pAd, RF_CSR_CFG, &rfcsr.word);
113 if (rfcsr.field.RF_CSR_KICK == BUSY) {
117 rfcsr.field.RF_CSR_WR = 0;
118 rfcsr.field.RF_CSR_KICK = 1;
119 rfcsr.field.TESTCSR_RFACC_REGNUM = regID;
120 RTMP_IO_WRITE32(pAd, RF_CSR_CFG, rfcsr.word);
121 for (k = 0; k < MAX_BUSY_COUNT; k++) {
122 RTMP_IO_READ32(pAd, RF_CSR_CFG, &rfcsr.word);
124 if (rfcsr.field.RF_CSR_KICK == IDLE)
127 if ((rfcsr.field.RF_CSR_KICK == IDLE) &&
128 (rfcsr.field.TESTCSR_RFACC_REGNUM == regID)) {
129 *pValue = (u8)rfcsr.field.RF_CSR_DATA;
133 if (rfcsr.field.RF_CSR_KICK == BUSY) {
134 DBGPRINT_ERR("RF read R%d=0x%x fail, i[%d], k[%d]\n", regID, rfcsr.word, i, k);
135 return STATUS_UNSUCCESSFUL;
138 return STATUS_SUCCESS;
141 void NICInitRFRegisters(struct rt_rtmp_adapter *pAd)
143 if (pAd->chipOps.AsicRfInit)
144 pAd->chipOps.AsicRfInit(pAd);
147 void RtmpChipOpsRFHook(struct rt_rtmp_adapter *pAd)
149 struct rt_rtmp_chip_op *pChipOps = &pAd->chipOps;
151 pChipOps->pRFRegTable = NULL;
152 pChipOps->AsicRfInit = NULL;
153 pChipOps->AsicRfTurnOn = NULL;
154 pChipOps->AsicRfTurnOff = NULL;
155 pChipOps->AsicReverseRfFromSleepMode = NULL;
156 pChipOps->AsicHaltAction = NULL;
157 /* We depends on RfICType and MACVersion to assign the corresponding operation callbacks. */
160 if (IS_RT30xx(pAd)) {
161 pChipOps->pRFRegTable = RT30xx_RFRegTable;
162 pChipOps->AsicHaltAction = RT30xxHaltAction;
164 if ((IS_RT3070(pAd) || IS_RT3071(pAd))
165 && (pAd->infType == RTMP_DEV_INF_USB)) {
166 pChipOps->AsicRfInit = NICInitRT3070RFRegisters;
167 if (IS_RT3071(pAd)) {
168 pChipOps->AsicRfTurnOff =
169 RT30xxLoadRFSleepModeSetup;
170 pChipOps->AsicReverseRfFromSleepMode =
171 RT30xxReverseRFSleepModeSetup;
174 #endif /* RT3070 // */
176 if (IS_RT3090(pAd) && (pAd->infType == RTMP_DEV_INF_PCI)) {
177 pChipOps->AsicRfTurnOff = RT30xxLoadRFSleepModeSetup;
178 pChipOps->AsicRfInit = NICInitRT3090RFRegisters;
179 pChipOps->AsicReverseRfFromSleepMode =
180 RT30xxReverseRFSleepModeSetup;
182 #endif /* RT3090 // */
184 #endif /* RT30xx // */
187 #endif /* RTMP_RF_RW_SUPPORT // */