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 Chip PHY(BBP/RF) related definition & structures
35 -------- ---------- ----------------------------------------------
38 #ifndef __RTMP_PHY_H__
39 #define __RTMP_PHY_H__
79 // value domain of pAd->RfIcType
80 #define RFIC_2820 1 // 2.4G 2T3R
81 #define RFIC_2850 2 // 2.4G/5G 2T3R
82 #define RFIC_2720 3 // 2.4G 1T2R
83 #define RFIC_2750 4 // 2.4G/5G 1T2R
84 #define RFIC_3020 5 // 2.4G 1T1R
85 #define RFIC_2020 6 // 2.4G B/G
86 #define RFIC_3021 7 // 2.4G 1T2R
87 #define RFIC_3022 8 // 2.4G 2T2R
88 #define RFIC_3052 9 // 2.4G/5G 2T2R
93 #define BBP_R0 0 // version
94 #define BBP_R1 1 // TSSI
95 #define BBP_R2 2 // TX configure
100 #define BBP_R14 14 // RX configure
102 #define BBP_R17 17 // RX sensibility
111 #define BBP_R49 49 //TSSI
116 #define BBP_R62 62 // Rx SQ0 Threshold HIGH
124 #define BBP_R70 70 // Rx AGC SQ CCK Xcorr threshold
138 #define BBP_R94 94 // Tx Gain Control
154 #define BBP_R138 138 // add by johnli, RF power sequence setup, ADC dynamic on/off control
157 #define BBPR94_DEFAULT 0x06 // Add 1 value will gain 1db
160 // BBP & RF are using indirect access. Before write any value into it.
161 // We have to make sure there is no outstanding command pending via checking busy bit.
163 #define MAX_BUSY_COUNT 100 // Number of retry before failing access BBP & RF indirect register
165 //#define PHY_TR_SWITCH_TIME 5 // usec
167 //#define BBP_R17_LOW_SENSIBILITY 0x50
168 //#define BBP_R17_MID_SENSIBILITY 0x41
169 //#define BBP_R17_DYNAMIC_UP_BOUND 0x40
171 #define RSSI_FOR_VERY_LOW_SENSIBILITY -35
172 #define RSSI_FOR_LOW_SENSIBILITY -58
173 #define RSSI_FOR_MID_LOW_SENSIBILITY -80
174 #define RSSI_FOR_MID_SENSIBILITY -90
176 /*****************************************************************************
177 RF register Read/Write marco definition
178 *****************************************************************************/
180 #define RTMP_RF_IO_WRITE32(_A, _V) \
182 if ((_A)->bPCIclkOff == FALSE) \
184 PHY_CSR4_STRUC _value; \
185 ULONG _busyCnt = 0; \
188 RTMP_IO_READ32((_A), RF_CSR_CFG0, &_value.word); \
189 if (_value.field.Busy == IDLE) \
192 }while (_busyCnt < MAX_BUSY_COUNT); \
193 if(_busyCnt < MAX_BUSY_COUNT) \
195 RTMP_IO_WRITE32((_A), RF_CSR_CFG0, (_V)); \
199 #endif // RTMP_MAC_PCI //
201 #define RTMP_RF_IO_WRITE32(_A, _V) RTUSBWriteRFRegister(_A, _V)
202 #endif // RTMP_MAC_USB //
205 #define RTMP_RF_IO_READ8_BY_REG_ID(_A, _I, _pV) RT30xxReadRFRegister(_A, _I, _pV)
206 #define RTMP_RF_IO_WRITE8_BY_REG_ID(_A, _I, _V) RT30xxWriteRFRegister(_A, _I, _V)
209 /*****************************************************************************
210 BBP register Read/Write marco definitions.
211 we read/write the bbp value by register's ID.
212 Generate PER to test BA
213 *****************************************************************************/
216 basic marco for BBP read operation.
217 _pAd: the data structure pointer of RTMP_ADAPTER
218 _bbpID : the bbp register ID
219 _pV: data pointer used to save the value of queried bbp register.
220 _bViaMCU: if we need access the bbp via the MCU.
222 #define RTMP_BBP_IO_READ8(_pAd, _bbpID, _pV, _bViaMCU) \
224 BBP_CSR_CFG_STRUC BbpCsr; \
225 int _busyCnt, _secCnt, _regID; \
227 _regID = ((_bViaMCU) == TRUE ? H2M_BBP_AGENT : BBP_CSR_CFG); \
228 for (_busyCnt=0; _busyCnt<MAX_BUSY_COUNT; _busyCnt++) \
230 RTMP_IO_READ32(_pAd, _regID, &BbpCsr.word); \
231 if (BbpCsr.field.Busy == BUSY) \
234 BbpCsr.field.fRead = 1; \
235 BbpCsr.field.BBP_RW_MODE = 1; \
236 BbpCsr.field.Busy = 1; \
237 BbpCsr.field.RegNum = _bbpID; \
238 RTMP_IO_WRITE32(_pAd, _regID, BbpCsr.word); \
239 if ((_bViaMCU) == TRUE) \
241 AsicSendCommandToMcu(_pAd, 0x80, 0xff, 0x0, 0x0); \
242 RTMPusecDelay(1000); \
244 for (_secCnt=0; _secCnt<MAX_BUSY_COUNT; _secCnt++) \
246 RTMP_IO_READ32(_pAd, _regID, &BbpCsr.word); \
247 if (BbpCsr.field.Busy == IDLE) \
250 if ((BbpCsr.field.Busy == IDLE) && \
251 (BbpCsr.field.RegNum == _bbpID)) \
253 *(_pV) = (UCHAR)BbpCsr.field.Value; \
257 if (BbpCsr.field.Busy == BUSY) \
259 DBGPRINT_ERR(("BBP(viaMCU=%d) read R%d fail\n", (_bViaMCU), _bbpID)); \
260 *(_pV) = (_pAd)->BbpWriteLatch[_bbpID]; \
261 if ((_bViaMCU) == TRUE) \
263 RTMP_IO_READ32(_pAd, _regID, &BbpCsr.word); \
264 BbpCsr.field.Busy = 0; \
265 RTMP_IO_WRITE32(_pAd, _regID, BbpCsr.word); \
271 This marco used for the BBP read operation which didn't need via MCU.
273 #define BBP_IO_READ8_BY_REG_ID(_A, _I, _pV) \
274 RTMP_BBP_IO_READ8((_A), (_I), (_pV), FALSE)
277 This marco used for the BBP read operation which need via MCU.
278 But for some chipset which didn't have mcu (e.g., RBUS based chipset), we
279 will use this function too and didn't access the bbp register via the MCU.
281 // Read BBP register by register's ID. Generate PER to test BA
282 #define RTMP_BBP_IO_READ8_BY_REG_ID(_A, _I, _pV) \
284 BBP_CSR_CFG_STRUC BbpCsr; \
287 BbpCsr.field.Busy = IDLE; \
288 if ((IS_RT3090((_A)) || IS_RT3572((_A)) || IS_RT3390((_A))) && ((_A)->StaCfg.PSControl.field.rt30xxPowerMode == 3) \
289 && ((_A)->StaCfg.PSControl.field.EnableNewPS == TRUE) \
290 && ((_A)->bPCIclkOff == FALSE) \
291 && ((_A)->brt30xxBanMcuCmd == FALSE)) \
293 for (i=0; i<MAX_BUSY_COUNT; i++) \
295 RTMP_IO_READ32(_A, H2M_BBP_AGENT, &BbpCsr.word); \
296 if (BbpCsr.field.Busy == BUSY) \
301 BbpCsr.field.fRead = 1; \
302 BbpCsr.field.BBP_RW_MODE = 1; \
303 BbpCsr.field.Busy = 1; \
304 BbpCsr.field.RegNum = _I; \
305 RTMP_IO_WRITE32(_A, H2M_BBP_AGENT, BbpCsr.word); \
306 brc = AsicSendCommandToMcu(_A, 0x80, 0xff, 0x0, 0x0); \
309 for (k=0; k<MAX_BUSY_COUNT; k++) \
311 RTMP_IO_READ32(_A, H2M_BBP_AGENT, &BbpCsr.word); \
312 if (BbpCsr.field.Busy == IDLE) \
315 if ((BbpCsr.field.Busy == IDLE) && \
316 (BbpCsr.field.RegNum == _I)) \
318 *(_pV) = (UCHAR)BbpCsr.field.Value; \
324 BbpCsr.field.Busy = 0; \
325 RTMP_IO_WRITE32(_A, H2M_BBP_AGENT, BbpCsr.word); \
329 else if (!((IS_RT3090((_A)) || IS_RT3572((_A)) || IS_RT3390((_A))) && ((_A)->StaCfg.PSControl.field.rt30xxPowerMode == 3) \
330 && ((_A)->StaCfg.PSControl.field.EnableNewPS == TRUE)) \
331 && ((_A)->bPCIclkOff == FALSE)) \
333 for (i=0; i<MAX_BUSY_COUNT; i++) \
335 RTMP_IO_READ32(_A, H2M_BBP_AGENT, &BbpCsr.word); \
336 if (BbpCsr.field.Busy == BUSY) \
341 BbpCsr.field.fRead = 1; \
342 BbpCsr.field.BBP_RW_MODE = 1; \
343 BbpCsr.field.Busy = 1; \
344 BbpCsr.field.RegNum = _I; \
345 RTMP_IO_WRITE32(_A, H2M_BBP_AGENT, BbpCsr.word); \
346 AsicSendCommandToMcu(_A, 0x80, 0xff, 0x0, 0x0); \
347 for (k=0; k<MAX_BUSY_COUNT; k++) \
349 RTMP_IO_READ32(_A, H2M_BBP_AGENT, &BbpCsr.word); \
350 if (BbpCsr.field.Busy == IDLE) \
353 if ((BbpCsr.field.Busy == IDLE) && \
354 (BbpCsr.field.RegNum == _I)) \
356 *(_pV) = (UCHAR)BbpCsr.field.Value; \
363 DBGPRINT_ERR((" , brt30xxBanMcuCmd = %d, Read BBP %d \n", (_A)->brt30xxBanMcuCmd, (_I))); \
364 *(_pV) = (_A)->BbpWriteLatch[_I]; \
366 if ((BbpCsr.field.Busy == BUSY) || ((_A)->bPCIclkOff == TRUE)) \
368 DBGPRINT_ERR(("BBP read R%d=0x%x fail\n", _I, BbpCsr.word)); \
369 *(_pV) = (_A)->BbpWriteLatch[_I]; \
374 basic marco for BBP write operation.
375 _pAd: the data structure pointer of RTMP_ADAPTER
376 _bbpID : the bbp register ID
377 _pV: data used to save the value of queried bbp register.
378 _bViaMCU: if we need access the bbp via the MCU.
380 #define RTMP_BBP_IO_WRITE8(_pAd, _bbpID, _pV, _bViaMCU) \
382 BBP_CSR_CFG_STRUC BbpCsr; \
383 int _busyCnt, _regID; \
385 _regID = ((_bViaMCU) == TRUE ? H2M_BBP_AGENT : BBP_CSR_CFG); \
386 for (_busyCnt=0; _busyCnt<MAX_BUSY_COUNT; _busyCnt++) \
388 RTMP_IO_READ32((_pAd), BBP_CSR_CFG, &BbpCsr.word); \
389 if (BbpCsr.field.Busy == BUSY) \
392 BbpCsr.field.fRead = 0; \
393 BbpCsr.field.BBP_RW_MODE = 1; \
394 BbpCsr.field.Busy = 1; \
395 BbpCsr.field.Value = _pV; \
396 BbpCsr.field.RegNum = _bbpID; \
397 RTMP_IO_WRITE32((_pAd), BBP_CSR_CFG, BbpCsr.word); \
398 if ((_bViaMCU) == TRUE) \
400 AsicSendCommandToMcu(_pAd, 0x80, 0xff, 0x0, 0x0); \
401 if ((_pAd)->OpMode == OPMODE_AP) \
402 RTMPusecDelay(1000); \
404 (_pAd)->BbpWriteLatch[_bbpID] = _pV; \
407 if (_busyCnt == MAX_BUSY_COUNT) \
409 DBGPRINT_ERR(("BBP write R%d fail\n", _bbpID)); \
410 if((_bViaMCU) == TRUE) \
412 RTMP_IO_READ32(_pAd, H2M_BBP_AGENT, &BbpCsr.word); \
413 BbpCsr.field.Busy = 0; \
414 RTMP_IO_WRITE32(_pAd, H2M_BBP_AGENT, BbpCsr.word); \
421 This marco used for the BBP write operation which didn't need via MCU.
423 #define BBP_IO_WRITE8_BY_REG_ID(_A, _I, _pV) \
424 RTMP_BBP_IO_WRITE8((_A), (_I), (_pV), FALSE)
427 This marco used for the BBP write operation which need via MCU.
428 But for some chipset which didn't have mcu (e.g., RBUS based chipset), we
429 will use this function too and didn't access the bbp register via the MCU.
431 // Write BBP register by register's ID & value
432 #define RTMP_BBP_IO_WRITE8_BY_REG_ID(_A, _I, _V) \
434 BBP_CSR_CFG_STRUC BbpCsr; \
437 if (_I < MAX_NUM_OF_BBP_LATCH) \
439 if ((IS_RT3090((_A)) || IS_RT3572((_A)) || IS_RT3390((_A))) && ((_A)->StaCfg.PSControl.field.rt30xxPowerMode == 3) \
440 && ((_A)->StaCfg.PSControl.field.EnableNewPS == TRUE) \
441 && ((_A)->bPCIclkOff == FALSE) \
442 && ((_A)->brt30xxBanMcuCmd == FALSE)) \
444 if (_A->AccessBBPFailCount > 20) \
446 AsicResetBBPAgent(_A); \
447 _A->AccessBBPFailCount = 0; \
449 for (BusyCnt=0; BusyCnt<MAX_BUSY_COUNT; BusyCnt++) \
451 RTMP_IO_READ32(_A, H2M_BBP_AGENT, &BbpCsr.word); \
452 if (BbpCsr.field.Busy == BUSY) \
455 BbpCsr.field.fRead = 0; \
456 BbpCsr.field.BBP_RW_MODE = 1; \
457 BbpCsr.field.Busy = 1; \
458 BbpCsr.field.Value = _V; \
459 BbpCsr.field.RegNum = _I; \
460 RTMP_IO_WRITE32(_A, H2M_BBP_AGENT, BbpCsr.word); \
461 brc = AsicSendCommandToMcu(_A, 0x80, 0xff, 0x0, 0x0); \
464 (_A)->BbpWriteLatch[_I] = _V; \
468 BbpCsr.field.Busy = 0; \
469 RTMP_IO_WRITE32(_A, H2M_BBP_AGENT, BbpCsr.word); \
474 else if (!((IS_RT3090((_A)) || IS_RT3572((_A)) || IS_RT3390((_A))) && ((_A)->StaCfg.PSControl.field.rt30xxPowerMode == 3) \
475 && ((_A)->StaCfg.PSControl.field.EnableNewPS == TRUE)) \
476 && ((_A)->bPCIclkOff == FALSE)) \
478 if (_A->AccessBBPFailCount > 20) \
480 AsicResetBBPAgent(_A); \
481 _A->AccessBBPFailCount = 0; \
483 for (BusyCnt=0; BusyCnt<MAX_BUSY_COUNT; BusyCnt++) \
485 RTMP_IO_READ32(_A, H2M_BBP_AGENT, &BbpCsr.word); \
486 if (BbpCsr.field.Busy == BUSY) \
489 BbpCsr.field.fRead = 0; \
490 BbpCsr.field.BBP_RW_MODE = 1; \
491 BbpCsr.field.Busy = 1; \
492 BbpCsr.field.Value = _V; \
493 BbpCsr.field.RegNum = _I; \
494 RTMP_IO_WRITE32(_A, H2M_BBP_AGENT, BbpCsr.word); \
495 AsicSendCommandToMcu(_A, 0x80, 0xff, 0x0, 0x0); \
496 (_A)->BbpWriteLatch[_I] = _V; \
502 DBGPRINT_ERR((" brt30xxBanMcuCmd = %d. Write BBP %d \n", (_A)->brt30xxBanMcuCmd, (_I))); \
504 if ((BusyCnt == MAX_BUSY_COUNT) || ((_A)->bPCIclkOff == TRUE)) \
506 if (BusyCnt == MAX_BUSY_COUNT) \
507 (_A)->AccessBBPFailCount++; \
508 DBGPRINT_ERR(("BBP write R%d=0x%x fail. BusyCnt= %d.bPCIclkOff = %d. \n", _I, BbpCsr.word, BusyCnt, (_A)->bPCIclkOff )); \
513 DBGPRINT_ERR(("****** BBP_Write_Latch Buffer exceeds max boundry ****** \n")); \
516 #endif // RTMP_MAC_PCI //
519 #define RTMP_BBP_IO_READ8_BY_REG_ID(_A, _I, _pV) RTUSBReadBBPRegister(_A, _I, _pV)
520 #define RTMP_BBP_IO_WRITE8_BY_REG_ID(_A, _I, _V) RTUSBWriteBBPRegister(_A, _I, _V)
522 #define BBP_IO_WRITE8_BY_REG_ID(_A, _I, _V) RTUSBWriteBBPRegister(_A, _I, _V)
523 #define BBP_IO_READ8_BY_REG_ID(_A, _I, _pV) RTUSBReadBBPRegister(_A, _I, _pV)
524 #endif // RTMP_MAC_USB //
527 #define RTMP_ASIC_MMPS_DISABLE(_pAd) \
530 UCHAR _bbpData = 0; \
531 /* disable MMPS BBP control register */ \
532 RTMP_BBP_IO_READ8_BY_REG_ID(_pAd, BBP_R3, &_bbpData); \
533 _bbpData &= ~(0x04); /*bit 2*/ \
534 RTMP_BBP_IO_WRITE8_BY_REG_ID(_pAd, BBP_R3, _bbpData); \
536 /* disable MMPS MAC control register */ \
537 RTMP_IO_READ32(_pAd, 0x1210, &_macData); \
538 _macData &= ~(0x09); /*bit 0, 3*/ \
539 RTMP_IO_WRITE32(_pAd, 0x1210, _macData); \
543 #define RTMP_ASIC_MMPS_ENABLE(_pAd) \
546 UCHAR _bbpData = 0; \
547 /* enable MMPS BBP control register */ \
548 RTMP_BBP_IO_READ8_BY_REG_ID(_pAd, BBP_R3, &_bbpData); \
549 _bbpData |= (0x04); /*bit 2*/ \
550 RTMP_BBP_IO_WRITE8_BY_REG_ID(_pAd, BBP_R3, _bbpData); \
552 /* enable MMPS MAC control register */ \
553 RTMP_IO_READ32(_pAd, 0x1210, &_macData); \
554 _macData |= (0x09); /*bit 0, 3*/ \
555 RTMP_IO_WRITE32(_pAd, 0x1210, _macData); \
560 #endif // __RTMP_PHY_H__ //