Bartlomiej Zolnierkiewicz | ca97b83 | 2009-09-22 20:44:07 +0200 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************* |
| 3 | * Ralink Tech Inc. |
| 4 | * 5F., No.36, Taiyuan St., Jhubei City, |
| 5 | * Hsinchu County 302, |
| 6 | * Taiwan, R.O.C. |
| 7 | * |
| 8 | * (c) Copyright 2002-2007, Ralink Technology, Inc. |
| 9 | * |
| 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. * |
| 14 | * * |
| 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. * |
| 19 | * * |
| 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. * |
| 24 | * * |
| 25 | ************************************************************************* |
| 26 | |
| 27 | Module Name: |
| 28 | rt_rf.c |
| 29 | |
| 30 | Abstract: |
| 31 | Ralink Wireless driver RF related functions |
| 32 | |
| 33 | Revision History: |
| 34 | Who When What |
| 35 | -------- ---------- ---------------------------------------------- |
| 36 | */ |
| 37 | |
Bartlomiej Zolnierkiewicz | ca97b83 | 2009-09-22 20:44:07 +0200 | [diff] [blame] | 38 | #include "../rt_config.h" |
| 39 | |
Bartlomiej Zolnierkiewicz | ca97b83 | 2009-09-22 20:44:07 +0200 | [diff] [blame] | 40 | #ifdef RTMP_RF_RW_SUPPORT |
| 41 | /* |
| 42 | ======================================================================== |
| 43 | |
| 44 | Routine Description: Write RT30xx RF register through MAC |
| 45 | |
| 46 | Arguments: |
| 47 | |
| 48 | Return Value: |
| 49 | |
| 50 | IRQL = |
| 51 | |
| 52 | Note: |
| 53 | |
| 54 | ======================================================================== |
| 55 | */ |
Bartlomiej Zolnierkiewicz | 62eb734 | 2009-12-11 12:23:16 -0800 | [diff] [blame] | 56 | int RT30xxWriteRFRegister(struct rt_rtmp_adapter *pAd, |
Bartlomiej Zolnierkiewicz | 51126de | 2009-12-11 12:23:15 -0800 | [diff] [blame] | 57 | u8 regID, u8 value) |
Bartlomiej Zolnierkiewicz | ca97b83 | 2009-09-22 20:44:07 +0200 | [diff] [blame] | 58 | { |
Bartlomiej Zolnierkiewicz | 96b3c83d | 2009-12-11 12:23:13 -0800 | [diff] [blame] | 59 | RF_CSR_CFG_STRUC rfcsr; |
Bartlomiej Zolnierkiewicz | 51126de | 2009-12-11 12:23:15 -0800 | [diff] [blame] | 60 | u32 i = 0; |
Bartlomiej Zolnierkiewicz | ca97b83 | 2009-09-22 20:44:07 +0200 | [diff] [blame] | 61 | |
Bartlomiej Zolnierkiewicz | 96b3c83d | 2009-12-11 12:23:13 -0800 | [diff] [blame] | 62 | do { |
Bartlomiej Zolnierkiewicz | ca97b83 | 2009-09-22 20:44:07 +0200 | [diff] [blame] | 63 | RTMP_IO_READ32(pAd, RF_CSR_CFG, &rfcsr.word); |
| 64 | |
| 65 | if (!rfcsr.field.RF_CSR_KICK) |
| 66 | break; |
| 67 | i++; |
| 68 | } |
Bartlomiej Zolnierkiewicz | 96b3c83d | 2009-12-11 12:23:13 -0800 | [diff] [blame] | 69 | while ((i < RETRY_LIMIT) |
| 70 | && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))); |
Bartlomiej Zolnierkiewicz | ca97b83 | 2009-09-22 20:44:07 +0200 | [diff] [blame] | 71 | |
Bartlomiej Zolnierkiewicz | 96b3c83d | 2009-12-11 12:23:13 -0800 | [diff] [blame] | 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")); |
Bartlomiej Zolnierkiewicz | ca97b83 | 2009-09-22 20:44:07 +0200 | [diff] [blame] | 76 | return STATUS_UNSUCCESSFUL; |
| 77 | } |
| 78 | |
| 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; |
| 83 | |
| 84 | RTMP_IO_WRITE32(pAd, RF_CSR_CFG, rfcsr.word); |
| 85 | |
| 86 | return NDIS_STATUS_SUCCESS; |
| 87 | } |
| 88 | |
Bartlomiej Zolnierkiewicz | ca97b83 | 2009-09-22 20:44:07 +0200 | [diff] [blame] | 89 | /* |
| 90 | ======================================================================== |
| 91 | |
| 92 | Routine Description: Read RT30xx RF register through MAC |
| 93 | |
| 94 | Arguments: |
| 95 | |
| 96 | Return Value: |
| 97 | |
| 98 | IRQL = |
| 99 | |
| 100 | Note: |
| 101 | |
| 102 | ======================================================================== |
| 103 | */ |
Bartlomiej Zolnierkiewicz | 62eb734 | 2009-12-11 12:23:16 -0800 | [diff] [blame] | 104 | int RT30xxReadRFRegister(struct rt_rtmp_adapter *pAd, |
Bartlomiej Zolnierkiewicz | 51126de | 2009-12-11 12:23:15 -0800 | [diff] [blame] | 105 | u8 regID, u8 *pValue) |
Bartlomiej Zolnierkiewicz | ca97b83 | 2009-09-22 20:44:07 +0200 | [diff] [blame] | 106 | { |
Bartlomiej Zolnierkiewicz | 96b3c83d | 2009-12-11 12:23:13 -0800 | [diff] [blame] | 107 | RF_CSR_CFG_STRUC rfcsr; |
Bartlomiej Zolnierkiewicz | 51126de | 2009-12-11 12:23:15 -0800 | [diff] [blame] | 108 | u32 i = 0, k = 0; |
Bartlomiej Zolnierkiewicz | ca97b83 | 2009-09-22 20:44:07 +0200 | [diff] [blame] | 109 | |
Bartlomiej Zolnierkiewicz | 96b3c83d | 2009-12-11 12:23:13 -0800 | [diff] [blame] | 110 | for (i = 0; i < MAX_BUSY_COUNT; i++) { |
Bartlomiej Zolnierkiewicz | ca97b83 | 2009-09-22 20:44:07 +0200 | [diff] [blame] | 111 | RTMP_IO_READ32(pAd, RF_CSR_CFG, &rfcsr.word); |
| 112 | |
Bartlomiej Zolnierkiewicz | 96b3c83d | 2009-12-11 12:23:13 -0800 | [diff] [blame] | 113 | if (rfcsr.field.RF_CSR_KICK == BUSY) { |
Bartlomiej Zolnierkiewicz | ca97b83 | 2009-09-22 20:44:07 +0200 | [diff] [blame] | 114 | continue; |
| 115 | } |
| 116 | rfcsr.word = 0; |
| 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); |
Bartlomiej Zolnierkiewicz | 96b3c83d | 2009-12-11 12:23:13 -0800 | [diff] [blame] | 121 | for (k = 0; k < MAX_BUSY_COUNT; k++) { |
Bartlomiej Zolnierkiewicz | ca97b83 | 2009-09-22 20:44:07 +0200 | [diff] [blame] | 122 | RTMP_IO_READ32(pAd, RF_CSR_CFG, &rfcsr.word); |
| 123 | |
| 124 | if (rfcsr.field.RF_CSR_KICK == IDLE) |
| 125 | break; |
| 126 | } |
| 127 | if ((rfcsr.field.RF_CSR_KICK == IDLE) && |
Bartlomiej Zolnierkiewicz | 96b3c83d | 2009-12-11 12:23:13 -0800 | [diff] [blame] | 128 | (rfcsr.field.TESTCSR_RFACC_REGNUM == regID)) { |
Bartlomiej Zolnierkiewicz | 51126de | 2009-12-11 12:23:15 -0800 | [diff] [blame] | 129 | *pValue = (u8)rfcsr.field.RF_CSR_DATA; |
Bartlomiej Zolnierkiewicz | ca97b83 | 2009-09-22 20:44:07 +0200 | [diff] [blame] | 130 | break; |
| 131 | } |
| 132 | } |
Bartlomiej Zolnierkiewicz | 96b3c83d | 2009-12-11 12:23:13 -0800 | [diff] [blame] | 133 | if (rfcsr.field.RF_CSR_KICK == BUSY) { |
| 134 | DBGPRINT_ERR(("RF read R%d=0x%x fail, i[%d], k[%d]\n", regID, |
| 135 | rfcsr.word, i, k)); |
Bartlomiej Zolnierkiewicz | ca97b83 | 2009-09-22 20:44:07 +0200 | [diff] [blame] | 136 | return STATUS_UNSUCCESSFUL; |
| 137 | } |
| 138 | |
| 139 | return STATUS_SUCCESS; |
| 140 | } |
| 141 | |
Bartlomiej Zolnierkiewicz | 62eb734 | 2009-12-11 12:23:16 -0800 | [diff] [blame] | 142 | void NICInitRFRegisters(struct rt_rtmp_adapter *pAd) |
Bartlomiej Zolnierkiewicz | ca97b83 | 2009-09-22 20:44:07 +0200 | [diff] [blame] | 143 | { |
| 144 | if (pAd->chipOps.AsicRfInit) |
| 145 | pAd->chipOps.AsicRfInit(pAd); |
| 146 | } |
| 147 | |
Bartlomiej Zolnierkiewicz | 62eb734 | 2009-12-11 12:23:16 -0800 | [diff] [blame] | 148 | void RtmpChipOpsRFHook(struct rt_rtmp_adapter *pAd) |
Bartlomiej Zolnierkiewicz | ca97b83 | 2009-09-22 20:44:07 +0200 | [diff] [blame] | 149 | { |
Bartlomiej Zolnierkiewicz | 62eb734 | 2009-12-11 12:23:16 -0800 | [diff] [blame] | 150 | struct rt_rtmp_chip_op *pChipOps = &pAd->chipOps; |
Bartlomiej Zolnierkiewicz | ca97b83 | 2009-09-22 20:44:07 +0200 | [diff] [blame] | 151 | |
| 152 | pChipOps->pRFRegTable = NULL; |
| 153 | pChipOps->AsicRfInit = NULL; |
| 154 | pChipOps->AsicRfTurnOn = NULL; |
| 155 | pChipOps->AsicRfTurnOff = NULL; |
| 156 | pChipOps->AsicReverseRfFromSleepMode = NULL; |
| 157 | pChipOps->AsicHaltAction = NULL; |
| 158 | /* We depends on RfICType and MACVersion to assign the corresponding operation callbacks. */ |
| 159 | |
| 160 | #ifdef RT30xx |
Bartlomiej Zolnierkiewicz | 96b3c83d | 2009-12-11 12:23:13 -0800 | [diff] [blame] | 161 | if (IS_RT30xx(pAd)) { |
Bartlomiej Zolnierkiewicz | ca97b83 | 2009-09-22 20:44:07 +0200 | [diff] [blame] | 162 | pChipOps->pRFRegTable = RT30xx_RFRegTable; |
| 163 | pChipOps->AsicHaltAction = RT30xxHaltAction; |
| 164 | #ifdef RT3070 |
Bartlomiej Zolnierkiewicz | 96b3c83d | 2009-12-11 12:23:13 -0800 | [diff] [blame] | 165 | if ((IS_RT3070(pAd) || IS_RT3071(pAd)) |
| 166 | && (pAd->infType == RTMP_DEV_INF_USB)) { |
Bartlomiej Zolnierkiewicz | ca97b83 | 2009-09-22 20:44:07 +0200 | [diff] [blame] | 167 | pChipOps->AsicRfInit = NICInitRT3070RFRegisters; |
Bartlomiej Zolnierkiewicz | 96b3c83d | 2009-12-11 12:23:13 -0800 | [diff] [blame] | 168 | if (IS_RT3071(pAd)) { |
| 169 | pChipOps->AsicRfTurnOff = |
| 170 | RT30xxLoadRFSleepModeSetup; |
| 171 | pChipOps->AsicReverseRfFromSleepMode = |
| 172 | RT30xxReverseRFSleepModeSetup; |
Bartlomiej Zolnierkiewicz | ca97b83 | 2009-09-22 20:44:07 +0200 | [diff] [blame] | 173 | } |
| 174 | } |
Bartlomiej Zolnierkiewicz | ec278fa | 2009-12-11 12:23:15 -0800 | [diff] [blame] | 175 | #endif /* RT3070 // */ |
Bartlomiej Zolnierkiewicz | e44fd1c | 2009-09-22 20:44:24 +0200 | [diff] [blame] | 176 | #ifdef RT3090 |
Bartlomiej Zolnierkiewicz | 96b3c83d | 2009-12-11 12:23:13 -0800 | [diff] [blame] | 177 | if (IS_RT3090(pAd) && (pAd->infType == RTMP_DEV_INF_PCI)) { |
Bartlomiej Zolnierkiewicz | e44fd1c | 2009-09-22 20:44:24 +0200 | [diff] [blame] | 178 | pChipOps->AsicRfTurnOff = RT30xxLoadRFSleepModeSetup; |
| 179 | pChipOps->AsicRfInit = NICInitRT3090RFRegisters; |
Bartlomiej Zolnierkiewicz | 96b3c83d | 2009-12-11 12:23:13 -0800 | [diff] [blame] | 180 | pChipOps->AsicReverseRfFromSleepMode = |
| 181 | RT30xxReverseRFSleepModeSetup; |
Bartlomiej Zolnierkiewicz | e44fd1c | 2009-09-22 20:44:24 +0200 | [diff] [blame] | 182 | } |
Bartlomiej Zolnierkiewicz | ec278fa | 2009-12-11 12:23:15 -0800 | [diff] [blame] | 183 | #endif /* RT3090 // */ |
Bartlomiej Zolnierkiewicz | ca97b83 | 2009-09-22 20:44:07 +0200 | [diff] [blame] | 184 | } |
Bartlomiej Zolnierkiewicz | ec278fa | 2009-12-11 12:23:15 -0800 | [diff] [blame] | 185 | #endif /* RT30xx // */ |
Bartlomiej Zolnierkiewicz | ca97b83 | 2009-09-22 20:44:07 +0200 | [diff] [blame] | 186 | } |
| 187 | |
Bartlomiej Zolnierkiewicz | ec278fa | 2009-12-11 12:23:15 -0800 | [diff] [blame] | 188 | #endif /* RTMP_RF_RW_SUPPORT // */ |