1 /******************************************************************************
3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 ******************************************************************************/
20 #define _RTL8188E_MP_C_
22 #include <drv_types.h>
24 #include <rtl8188e_hal.h>
25 #include <rtl8188e_dm.h>
27 s32 Hal_SetPowerTracking(struct adapter *padapter, u8 enable)
29 struct hal_data_8188e *pHalData = GET_HAL_DATA(padapter);
30 struct odm_dm_struct *pDM_Odm = &(pHalData->odmpriv);
32 if (!netif_running(padapter->pnetdev)) {
33 RT_TRACE(_module_mp_, _drv_warning_,
34 ("SetPowerTracking! Fail: interface not opened!\n"));
38 if (!check_fwstate(&padapter->mlmepriv, WIFI_MP_STATE)) {
39 RT_TRACE(_module_mp_, _drv_warning_,
40 ("SetPowerTracking! Fail: not in MP mode!\n"));
45 pDM_Odm->RFCalibrateInfo.bTXPowerTracking = true;
47 pDM_Odm->RFCalibrateInfo.bTXPowerTrackingInit = false;
52 void Hal_GetPowerTracking(struct adapter *padapter, u8 *enable)
54 struct hal_data_8188e *pHalData = GET_HAL_DATA(padapter);
55 struct odm_dm_struct *pDM_Odm = &(pHalData->odmpriv);
57 *enable = pDM_Odm->RFCalibrateInfo.TxPowerTrackControl;
60 /*-----------------------------------------------------------------------------
61 * Function: mpt_SwitchRfSetting
63 * Overview: Change RF Setting when we siwthc channel/rate/BW for MP.
65 * Input: struct adapter * pAdapter
73 * 01/08/2009 MHC Suggestion from SD3 Willis for 92S series.
74 * 01/09/2009 MHC Add CCK modification for 40MHZ. Suggestion from SD3.
76 *---------------------------------------------------------------------------*/
77 void Hal_mpt_SwitchRfSetting(struct adapter *pAdapter)
79 struct mp_priv *pmp = &pAdapter->mppriv;
81 /* <20120525, Kordan> Dynamic mechanism for APK, asked by Dennis. */
82 pmp->MptCtx.backup0x52_RF_A = (u8)PHY_QueryRFReg(pAdapter, RF_PATH_A, RF_0x52, 0x000F0);
83 pmp->MptCtx.backup0x52_RF_B = (u8)PHY_QueryRFReg(pAdapter, RF_PATH_B, RF_0x52, 0x000F0);
84 PHY_SetRFReg(pAdapter, RF_PATH_A, RF_0x52, 0x000F0, 0xD);
85 PHY_SetRFReg(pAdapter, RF_PATH_B, RF_0x52, 0x000F0, 0xD);
89 /*---------------------------hal\rtl8192c\MPT_Phy.c---------------------------*/
91 /*---------------------------hal\rtl8192c\MPT_HelperFunc.c---------------------------*/
92 void Hal_MPT_CCKTxPowerAdjust(struct adapter *Adapter, bool bInCH14)
94 u32 TempVal = 0, TempVal2 = 0, TempVal3 = 0;
95 u32 CurrCCKSwingVal = 0, CCKSwingIndex = 12;
98 /* get current cck swing value and check 0xa22 & 0xa23 later to match the table. */
99 CurrCCKSwingVal = read_bbreg(Adapter, rCCK0_TxFilter1, bMaskHWord);
102 /* Readback the current bb cck swing value and compare with the table to */
103 /* get the current swing index */
104 for (i = 0; i < CCK_TABLE_SIZE; i++) {
105 if (((CurrCCKSwingVal&0xff) == (u32)CCKSwingTable_Ch1_Ch13[i][0]) &&
106 (((CurrCCKSwingVal&0xff00)>>8) == (u32)CCKSwingTable_Ch1_Ch13[i][1])) {
112 /* Write 0xa22 0xa23 */
113 TempVal = CCKSwingTable_Ch1_Ch13[CCKSwingIndex][0] +
114 (CCKSwingTable_Ch1_Ch13[CCKSwingIndex][1]<<8);
116 /* Write 0xa24 ~ 0xa27 */
118 TempVal2 = CCKSwingTable_Ch1_Ch13[CCKSwingIndex][2] +
119 (CCKSwingTable_Ch1_Ch13[CCKSwingIndex][3]<<8) +
120 (CCKSwingTable_Ch1_Ch13[CCKSwingIndex][4]<<16)+
121 (CCKSwingTable_Ch1_Ch13[CCKSwingIndex][5]<<24);
123 /* Write 0xa28 0xa29 */
125 TempVal3 = CCKSwingTable_Ch1_Ch13[CCKSwingIndex][6] +
126 (CCKSwingTable_Ch1_Ch13[CCKSwingIndex][7]<<8);
128 for (i = 0; i < CCK_TABLE_SIZE; i++) {
129 if (((CurrCCKSwingVal&0xff) == (u32)CCKSwingTable_Ch14[i][0]) &&
130 (((CurrCCKSwingVal&0xff00)>>8) == (u32)CCKSwingTable_Ch14[i][1])) {
136 /* Write 0xa22 0xa23 */
137 TempVal = CCKSwingTable_Ch14[CCKSwingIndex][0] +
138 (CCKSwingTable_Ch14[CCKSwingIndex][1]<<8);
140 /* Write 0xa24 ~ 0xa27 */
142 TempVal2 = CCKSwingTable_Ch14[CCKSwingIndex][2] +
143 (CCKSwingTable_Ch14[CCKSwingIndex][3]<<8) +
144 (CCKSwingTable_Ch14[CCKSwingIndex][4]<<16)+
145 (CCKSwingTable_Ch14[CCKSwingIndex][5]<<24);
147 /* Write 0xa28 0xa29 */
149 TempVal3 = CCKSwingTable_Ch14[CCKSwingIndex][6] +
150 (CCKSwingTable_Ch14[CCKSwingIndex][7]<<8);
153 write_bbreg(Adapter, rCCK0_TxFilter1, bMaskHWord, TempVal);
154 write_bbreg(Adapter, rCCK0_TxFilter2, bMaskDWord, TempVal2);
155 write_bbreg(Adapter, rCCK0_DebugPort, bMaskLWord, TempVal3);
158 void Hal_MPT_CCKTxPowerAdjustbyIndex(struct adapter *pAdapter, bool beven)
160 struct hal_data_8188e *pHalData = GET_HAL_DATA(pAdapter);
161 struct mpt_context *pMptCtx = &pAdapter->mppriv.MptCtx;
162 struct odm_dm_struct *pDM_Odm = &(pHalData->odmpriv);
164 u8 CCK_index, CCK_index_old = 0;
165 u8 Action = 0; /* 0: no action, 1: even->odd, 2:odd->even */
168 if (!IS_92C_SERIAL(pHalData->VersionID))
170 if (beven && !pMptCtx->bMptIndexEven) {
173 pMptCtx->bMptIndexEven = true;
174 } else if (!beven && pMptCtx->bMptIndexEven) {
177 pMptCtx->bMptIndexEven = false;
181 /* Query CCK default setting From 0xa24 */
182 TempCCk = read_bbreg(pAdapter, rCCK0_TxFilter2, bMaskDWord) & bMaskCCK;
183 for (i = 0; i < CCK_TABLE_SIZE; i++) {
184 if (pDM_Odm->RFCalibrateInfo.bCCKinCH14) {
185 if (!memcmp((void *)&TempCCk, (void *)&CCKSwingTable_Ch14[i][2], 4)) {
186 CCK_index_old = (u8)i;
190 if (!memcmp((void *)&TempCCk, (void *)&CCKSwingTable_Ch1_Ch13[i][2], 4)) {
191 CCK_index_old = (u8)i;
198 CCK_index = CCK_index_old - 1;
200 CCK_index = CCK_index_old + 1;
202 /* Adjust CCK according to gain index */
203 if (!pDM_Odm->RFCalibrateInfo.bCCKinCH14) {
204 rtw_write8(pAdapter, 0xa22, CCKSwingTable_Ch1_Ch13[CCK_index][0]);
205 rtw_write8(pAdapter, 0xa23, CCKSwingTable_Ch1_Ch13[CCK_index][1]);
206 rtw_write8(pAdapter, 0xa24, CCKSwingTable_Ch1_Ch13[CCK_index][2]);
207 rtw_write8(pAdapter, 0xa25, CCKSwingTable_Ch1_Ch13[CCK_index][3]);
208 rtw_write8(pAdapter, 0xa26, CCKSwingTable_Ch1_Ch13[CCK_index][4]);
209 rtw_write8(pAdapter, 0xa27, CCKSwingTable_Ch1_Ch13[CCK_index][5]);
210 rtw_write8(pAdapter, 0xa28, CCKSwingTable_Ch1_Ch13[CCK_index][6]);
211 rtw_write8(pAdapter, 0xa29, CCKSwingTable_Ch1_Ch13[CCK_index][7]);
213 rtw_write8(pAdapter, 0xa22, CCKSwingTable_Ch14[CCK_index][0]);
214 rtw_write8(pAdapter, 0xa23, CCKSwingTable_Ch14[CCK_index][1]);
215 rtw_write8(pAdapter, 0xa24, CCKSwingTable_Ch14[CCK_index][2]);
216 rtw_write8(pAdapter, 0xa25, CCKSwingTable_Ch14[CCK_index][3]);
217 rtw_write8(pAdapter, 0xa26, CCKSwingTable_Ch14[CCK_index][4]);
218 rtw_write8(pAdapter, 0xa27, CCKSwingTable_Ch14[CCK_index][5]);
219 rtw_write8(pAdapter, 0xa28, CCKSwingTable_Ch14[CCK_index][6]);
220 rtw_write8(pAdapter, 0xa29, CCKSwingTable_Ch14[CCK_index][7]);
224 /*---------------------------hal\rtl8192c\MPT_HelperFunc.c---------------------------*/
229 * Use H2C command to change channel,
230 * not only modify rf register, but also other setting need to be done.
232 void Hal_SetChannel(struct adapter *pAdapter)
234 struct hal_data_8188e *pHalData = GET_HAL_DATA(pAdapter);
235 struct mp_priv *pmp = &pAdapter->mppriv;
236 struct odm_dm_struct *pDM_Odm = &(pHalData->odmpriv);
238 u8 channel = pmp->channel;
240 /* set RF channel register */
241 for (eRFPath = 0; eRFPath < pHalData->NumTotalRFPath; eRFPath++)
242 _write_rfreg(pAdapter, eRFPath, ODM_CHANNEL, 0x3FF, channel);
243 Hal_mpt_SwitchRfSetting(pAdapter);
245 SelectChannel(pAdapter, channel);
247 if (pHalData->CurrentChannel == 14 && !pDM_Odm->RFCalibrateInfo.bCCKinCH14) {
248 pDM_Odm->RFCalibrateInfo.bCCKinCH14 = true;
249 Hal_MPT_CCKTxPowerAdjust(pAdapter, pDM_Odm->RFCalibrateInfo.bCCKinCH14);
250 } else if (pHalData->CurrentChannel != 14 && pDM_Odm->RFCalibrateInfo.bCCKinCH14) {
251 pDM_Odm->RFCalibrateInfo.bCCKinCH14 = false;
252 Hal_MPT_CCKTxPowerAdjust(pAdapter, pDM_Odm->RFCalibrateInfo.bCCKinCH14);
258 * Switch bandwitdth may change center frequency(channel)
260 void Hal_SetBandwidth(struct adapter *pAdapter)
262 struct mp_priv *pmp = &pAdapter->mppriv;
264 SetBWMode(pAdapter, pmp->bandwidth, pmp->prime_channel_offset);
265 Hal_mpt_SwitchRfSetting(pAdapter);
268 void Hal_SetCCKTxPower(struct adapter *pAdapter, u8 *TxPower)
272 /* rf-A cck tx power */
273 write_bbreg(pAdapter, rTxAGC_A_CCK1_Mcs32, bMaskByte1, TxPower[RF_PATH_A]);
274 tmpval = (TxPower[RF_PATH_A]<<16) | (TxPower[RF_PATH_A]<<8) | TxPower[RF_PATH_A];
275 write_bbreg(pAdapter, rTxAGC_B_CCK11_A_CCK2_11, 0xffffff00, tmpval);
277 /* rf-B cck tx power */
278 write_bbreg(pAdapter, rTxAGC_B_CCK11_A_CCK2_11, bMaskByte0, TxPower[RF_PATH_B]);
279 tmpval = (TxPower[RF_PATH_B]<<16) | (TxPower[RF_PATH_B]<<8) | TxPower[RF_PATH_B];
280 write_bbreg(pAdapter, rTxAGC_B_CCK1_55_Mcs32, 0xffffff00, tmpval);
282 RT_TRACE(_module_mp_, _drv_notice_,
283 ("-SetCCKTxPower: A[0x%02x] B[0x%02x]\n",
284 TxPower[RF_PATH_A], TxPower[RF_PATH_B]));
287 void Hal_SetOFDMTxPower(struct adapter *pAdapter, u8 *TxPower)
293 tmpval = TxPower[RF_PATH_A];
294 TxAGC = (tmpval<<24) | (tmpval<<16) | (tmpval<<8) | tmpval;
296 write_bbreg(pAdapter, rTxAGC_A_Rate18_06, bMaskDWord, TxAGC);
297 write_bbreg(pAdapter, rTxAGC_A_Rate54_24, bMaskDWord, TxAGC);
298 write_bbreg(pAdapter, rTxAGC_A_Mcs03_Mcs00, bMaskDWord, TxAGC);
299 write_bbreg(pAdapter, rTxAGC_A_Mcs07_Mcs04, bMaskDWord, TxAGC);
300 write_bbreg(pAdapter, rTxAGC_A_Mcs11_Mcs08, bMaskDWord, TxAGC);
301 write_bbreg(pAdapter, rTxAGC_A_Mcs15_Mcs12, bMaskDWord, TxAGC);
304 tmpval = TxPower[RF_PATH_B];
305 TxAGC = (tmpval<<24) | (tmpval<<16) | (tmpval<<8) | tmpval;
307 write_bbreg(pAdapter, rTxAGC_B_Rate18_06, bMaskDWord, TxAGC);
308 write_bbreg(pAdapter, rTxAGC_B_Rate54_24, bMaskDWord, TxAGC);
309 write_bbreg(pAdapter, rTxAGC_B_Mcs03_Mcs00, bMaskDWord, TxAGC);
310 write_bbreg(pAdapter, rTxAGC_B_Mcs07_Mcs04, bMaskDWord, TxAGC);
311 write_bbreg(pAdapter, rTxAGC_B_Mcs11_Mcs08, bMaskDWord, TxAGC);
312 write_bbreg(pAdapter, rTxAGC_B_Mcs15_Mcs12, bMaskDWord, TxAGC);
315 void Hal_SetAntennaPathPower(struct adapter *pAdapter)
317 struct hal_data_8188e *pHalData = GET_HAL_DATA(pAdapter);
318 u8 TxPowerLevel[RF_PATH_MAX];
321 TxPowerLevel[RF_PATH_A] = pAdapter->mppriv.txpoweridx;
322 TxPowerLevel[RF_PATH_B] = pAdapter->mppriv.txpoweridx_b;
324 switch (pAdapter->mppriv.antenna_tx) {
337 switch (pHalData->rf_chip) {
341 Hal_SetCCKTxPower(pAdapter, TxPowerLevel);
342 if (pAdapter->mppriv.rateidx < MPT_RATE_6M) /* CCK rate */
343 Hal_MPT_CCKTxPowerAdjustbyIndex(pAdapter, TxPowerLevel[rfPath]%2 == 0);
344 Hal_SetOFDMTxPower(pAdapter, TxPowerLevel);
351 void Hal_SetTxPower(struct adapter *pAdapter)
353 struct hal_data_8188e *pHalData = GET_HAL_DATA(pAdapter);
354 u8 TxPower = pAdapter->mppriv.txpoweridx;
355 u8 TxPowerLevel[RF_PATH_MAX];
358 for (rf = 0; rf < RF_PATH_MAX; rf++)
359 TxPowerLevel[rf] = TxPower;
361 switch (pAdapter->mppriv.antenna_tx) {
374 switch (pHalData->rf_chip) {
375 /* 2008/09/12 MH Test only !! We enable the TX power tracking for MP!!!!! */
376 /* We should call normal driver API later!! */
380 Hal_SetCCKTxPower(pAdapter, TxPowerLevel);
381 if (pAdapter->mppriv.rateidx < MPT_RATE_6M) /* CCK rate */
382 Hal_MPT_CCKTxPowerAdjustbyIndex(pAdapter, TxPowerLevel[rfPath]%2 == 0);
383 Hal_SetOFDMTxPower(pAdapter, TxPowerLevel);
390 void Hal_SetDataRate(struct adapter *pAdapter)
392 Hal_mpt_SwitchRfSetting(pAdapter);
395 void Hal_SetAntenna(struct adapter *pAdapter)
397 struct hal_data_8188e *pHalData = GET_HAL_DATA(pAdapter);
399 struct ant_sel_ofdm *p_ofdm_tx; /* OFDM Tx register */
400 struct ant_sel_cck *p_cck_txrx;
401 u8 r_rx_antenna_ofdm = 0, r_ant_select_cck_val = 0;
402 u8 chgTx = 0, chgRx = 0;
403 u32 r_ant_select_ofdm_val = 0, r_ofdm_tx_en_val = 0;
405 p_ofdm_tx = (struct ant_sel_ofdm *)&r_ant_select_ofdm_val;
406 p_cck_txrx = (struct ant_sel_cck *)&r_ant_select_cck_val;
408 p_ofdm_tx->r_ant_ht1 = 0x1;
409 p_ofdm_tx->r_ant_ht2 = 0x2; /* Second TX RF path is A */
410 p_ofdm_tx->r_ant_non_ht = 0x3; /* 0x1+0x2=0x3 */
412 switch (pAdapter->mppriv.antenna_tx) {
414 p_ofdm_tx->r_tx_antenna = 0x1;
415 r_ofdm_tx_en_val = 0x1;
416 p_ofdm_tx->r_ant_l = 0x1;
417 p_ofdm_tx->r_ant_ht_s1 = 0x1;
418 p_ofdm_tx->r_ant_non_ht_s1 = 0x1;
419 p_cck_txrx->r_ccktx_enable = 0x8;
422 /* From SD3 Willis suggestion !!! Set RF A=TX and B as standby */
423 write_bbreg(pAdapter, rFPGA0_XA_HSSIParameter2, 0xe, 2);
424 write_bbreg(pAdapter, rFPGA0_XB_HSSIParameter2, 0xe, 1);
425 r_ofdm_tx_en_val = 0x3;
429 /* We need to close RFB by SW control */
430 if (pHalData->rf_type == RF_2T2R) {
431 PHY_SetBBReg(pAdapter, rFPGA0_XAB_RFInterfaceSW, BIT10, 0);
432 PHY_SetBBReg(pAdapter, rFPGA0_XAB_RFInterfaceSW, BIT26, 1);
433 PHY_SetBBReg(pAdapter, rFPGA0_XB_RFInterfaceOE, BIT10, 0);
434 PHY_SetBBReg(pAdapter, rFPGA0_XAB_RFParameter, BIT1, 1);
435 PHY_SetBBReg(pAdapter, rFPGA0_XAB_RFParameter, BIT17, 0);
439 p_ofdm_tx->r_tx_antenna = 0x2;
440 r_ofdm_tx_en_val = 0x2;
441 p_ofdm_tx->r_ant_l = 0x2;
442 p_ofdm_tx->r_ant_ht_s1 = 0x2;
443 p_ofdm_tx->r_ant_non_ht_s1 = 0x2;
444 p_cck_txrx->r_ccktx_enable = 0x4;
446 /* From SD3 Willis suggestion !!! Set RF A as standby */
447 PHY_SetBBReg(pAdapter, rFPGA0_XA_HSSIParameter2, 0xe, 1);
448 PHY_SetBBReg(pAdapter, rFPGA0_XB_HSSIParameter2, 0xe, 2);
451 /* cosa r_ant_select_ofdm_val = 0x22222222; */
453 /* 2008/10/31 MH From SD3 Willi's suggestion. We must read RF 1T table. */
454 /* 2009/01/08 MH From Sd3 Willis. We need to close RFA by SW control */
455 if (pHalData->rf_type == RF_2T2R || pHalData->rf_type == RF_1T2R) {
456 PHY_SetBBReg(pAdapter, rFPGA0_XAB_RFInterfaceSW, BIT10, 1);
457 PHY_SetBBReg(pAdapter, rFPGA0_XA_RFInterfaceOE, BIT10, 0);
458 PHY_SetBBReg(pAdapter, rFPGA0_XAB_RFInterfaceSW, BIT26, 0);
459 PHY_SetBBReg(pAdapter, rFPGA0_XAB_RFParameter, BIT1, 0);
460 PHY_SetBBReg(pAdapter, rFPGA0_XAB_RFParameter, BIT17, 1);
463 case ANTENNA_AB: /* For 8192S */
464 p_ofdm_tx->r_tx_antenna = 0x3;
465 r_ofdm_tx_en_val = 0x3;
466 p_ofdm_tx->r_ant_l = 0x3;
467 p_ofdm_tx->r_ant_ht_s1 = 0x3;
468 p_ofdm_tx->r_ant_non_ht_s1 = 0x3;
469 p_cck_txrx->r_ccktx_enable = 0xC;
472 /* From SD3 Willis suggestion !!! Set RF B as standby */
473 PHY_SetBBReg(pAdapter, rFPGA0_XA_HSSIParameter2, 0xe, 2);
474 PHY_SetBBReg(pAdapter, rFPGA0_XB_HSSIParameter2, 0xe, 2);
476 /* Disable Power save */
477 /* cosa r_ant_select_ofdm_val = 0x3321333; */
478 /* 2009/01/08 MH From Sd3 Willis. We need to enable RFA/B by SW control */
479 if (pHalData->rf_type == RF_2T2R) {
480 PHY_SetBBReg(pAdapter, rFPGA0_XAB_RFInterfaceSW, BIT10, 0);
481 PHY_SetBBReg(pAdapter, rFPGA0_XAB_RFInterfaceSW, BIT26, 0);
482 PHY_SetBBReg(pAdapter, rFPGA0_XAB_RFParameter, BIT1, 1);
483 PHY_SetBBReg(pAdapter, rFPGA0_XAB_RFParameter, BIT17, 1);
490 /* r_rx_antenna_ofdm, bit0=A, bit1=B, bit2=C, bit3=D */
491 /* r_cckrx_enable : CCK default, 0=A, 1=B, 2=C, 3=D */
492 /* r_cckrx_enable_2 : CCK option, 0=A, 1=B, 2=C, 3=D */
493 switch (pAdapter->mppriv.antenna_rx) {
495 r_rx_antenna_ofdm = 0x1; /* A */
496 p_cck_txrx->r_cckrx_enable = 0x0; /* default: A */
497 p_cck_txrx->r_cckrx_enable_2 = 0x0; /* option: A */
501 r_rx_antenna_ofdm = 0x2; /* B */
502 p_cck_txrx->r_cckrx_enable = 0x1; /* default: B */
503 p_cck_txrx->r_cckrx_enable_2 = 0x1; /* option: B */
507 r_rx_antenna_ofdm = 0x3; /* AB */
508 p_cck_txrx->r_cckrx_enable = 0x0; /* default:A */
509 p_cck_txrx->r_cckrx_enable_2 = 0x1; /* option:B */
516 if (chgTx && chgRx) {
517 switch (pHalData->rf_chip) {
521 /* r_ant_sel_cck_val = r_ant_select_cck_val; */
522 PHY_SetBBReg(pAdapter, rFPGA1_TxInfo, 0x7fffffff, r_ant_select_ofdm_val); /* OFDM Tx */
523 PHY_SetBBReg(pAdapter, rFPGA0_TxInfo, 0x0000000f, r_ofdm_tx_en_val); /* OFDM Tx */
524 PHY_SetBBReg(pAdapter, rOFDM0_TRxPathEnable, 0x0000000f, r_rx_antenna_ofdm); /* OFDM Rx */
525 PHY_SetBBReg(pAdapter, rOFDM1_TRxPathEnable, 0x0000000f, r_rx_antenna_ofdm); /* OFDM Rx */
526 PHY_SetBBReg(pAdapter, rCCK0_AFESetting, bMaskByte3, r_ant_select_cck_val); /* CCK TxRx */
534 RT_TRACE(_module_mp_, _drv_notice_, ("-SwitchAntenna: finished\n"));
537 s32 Hal_SetThermalMeter(struct adapter *pAdapter, u8 target_ther)
539 struct hal_data_8188e *pHalData = GET_HAL_DATA(pAdapter);
541 if (!netif_running(pAdapter->pnetdev)) {
542 RT_TRACE(_module_mp_, _drv_warning_, ("SetThermalMeter! Fail: interface not opened!\n"));
546 if (check_fwstate(&pAdapter->mlmepriv, WIFI_MP_STATE) == false) {
547 RT_TRACE(_module_mp_, _drv_warning_, ("SetThermalMeter: Fail! not in MP mode!\n"));
552 if (target_ther < 0x07)
554 else if (target_ther > 0x1d)
557 pHalData->EEPROMThermalMeter = target_ther;
562 void Hal_TriggerRFThermalMeter(struct adapter *pAdapter)
564 _write_rfreg(pAdapter, RF_PATH_A , RF_T_METER_88E , BIT17 | BIT16 , 0x03);
567 u8 Hal_ReadRFThermalMeter(struct adapter *pAdapter)
569 u32 ThermalValue = 0;
571 ThermalValue = _read_rfreg(pAdapter, RF_PATH_A, RF_T_METER_88E, 0xfc00);
572 return (u8)ThermalValue;
575 void Hal_GetThermalMeter(struct adapter *pAdapter, u8 *value)
577 Hal_TriggerRFThermalMeter(pAdapter);
579 *value = Hal_ReadRFThermalMeter(pAdapter);
582 void Hal_SetSingleCarrierTx(struct adapter *pAdapter, u8 bStart)
584 pAdapter->mppriv.MptCtx.bSingleCarrier = bStart;
586 /* Start Single Carrier. */
587 RT_TRACE(_module_mp_, _drv_alert_, ("SetSingleCarrierTx: test start\n"));
588 /* 1. if OFDM block on? */
589 if (!read_bbreg(pAdapter, rFPGA0_RFMOD, bOFDMEn))
590 write_bbreg(pAdapter, rFPGA0_RFMOD, bOFDMEn, bEnable);/* set OFDM block on */
592 /* 2. set CCK test mode off, set to CCK normal mode */
593 write_bbreg(pAdapter, rCCK0_System, bCCKBBMode, bDisable);
594 /* 3. turn on scramble setting */
595 write_bbreg(pAdapter, rCCK0_System, bCCKScramble, bEnable);
596 /* 4. Turn On Single Carrier Tx and turn off the other test modes. */
597 write_bbreg(pAdapter, rOFDM1_LSTF, bOFDMContinueTx, bDisable);
598 write_bbreg(pAdapter, rOFDM1_LSTF, bOFDMSingleCarrier, bEnable);
599 write_bbreg(pAdapter, rOFDM1_LSTF, bOFDMSingleTone, bDisable);
600 /* for dynamic set Power index. */
601 write_bbreg(pAdapter, rFPGA0_XA_HSSIParameter1, bMaskDWord, 0x01000500);
602 write_bbreg(pAdapter, rFPGA0_XB_HSSIParameter1, bMaskDWord, 0x01000500);
604 /* Stop Single Carrier. */
605 RT_TRACE(_module_mp_, _drv_alert_, ("SetSingleCarrierTx: test stop\n"));
607 /* Turn off all test modes. */
608 write_bbreg(pAdapter, rOFDM1_LSTF, bOFDMContinueTx, bDisable);
609 write_bbreg(pAdapter, rOFDM1_LSTF, bOFDMSingleCarrier, bDisable);
610 write_bbreg(pAdapter, rOFDM1_LSTF, bOFDMSingleTone, bDisable);
614 write_bbreg(pAdapter, rPMAC_Reset, bBBResetB, 0x0);
615 write_bbreg(pAdapter, rPMAC_Reset, bBBResetB, 0x1);
617 /* Stop for dynamic set Power index. */
618 write_bbreg(pAdapter, rFPGA0_XA_HSSIParameter1, bMaskDWord, 0x01000100);
619 write_bbreg(pAdapter, rFPGA0_XB_HSSIParameter1, bMaskDWord, 0x01000100);
623 void Hal_SetSingleToneTx(struct adapter *pAdapter, u8 bStart)
625 struct hal_data_8188e *pHalData = GET_HAL_DATA(pAdapter);
626 bool is92C = IS_92C_SERIAL(pHalData->VersionID);
630 switch (pAdapter->mppriv.antenna_tx) {
643 pAdapter->mppriv.MptCtx.bSingleTone = bStart;
645 /* Start Single Tone. */
646 RT_TRACE(_module_mp_, _drv_alert_, ("SetSingleToneTx: test start\n"));
647 /* <20120326, Kordan> To amplify the power of tone for Xtal calibration. (asked by Edlu) */
648 if (IS_HARDWARE_TYPE_8188E(pAdapter)) {
649 reg58 = PHY_QueryRFReg(pAdapter, RF_PATH_A, LNA_Low_Gain_3, bRFRegOffsetMask);
652 PHY_SetRFReg(pAdapter, RF_PATH_A, LNA_Low_Gain_3, bRFRegOffsetMask, reg58);
654 PHY_SetBBReg(pAdapter, rFPGA0_RFMOD, bCCKEn, 0x0);
655 PHY_SetBBReg(pAdapter, rFPGA0_RFMOD, bOFDMEn, 0x0);
658 _write_rfreg(pAdapter, RF_PATH_A, 0x21, BIT19, 0x01);
660 if (rfPath == RF_PATH_A)
661 write_rfreg(pAdapter, RF_PATH_B, 0x00, 0x10000); /* PAD all on. */
662 else if (rfPath == RF_PATH_B)
663 write_rfreg(pAdapter, RF_PATH_A, 0x00, 0x10000); /* PAD all on. */
664 write_rfreg(pAdapter, rfPath, 0x00, 0x2001f); /* PAD all on. */
667 write_rfreg(pAdapter, rfPath, 0x21, 0xd4000);
669 write_rfreg(pAdapter, rfPath, 0x00, 0x2001f); /* PAD all on. */
673 /* for dynamic set Power index. */
674 write_bbreg(pAdapter, rFPGA0_XA_HSSIParameter1, bMaskDWord, 0x01000500);
675 write_bbreg(pAdapter, rFPGA0_XB_HSSIParameter1, bMaskDWord, 0x01000500);
678 /* Stop Single Tone. */
679 RT_TRACE(_module_mp_, _drv_alert_, ("SetSingleToneTx: test stop\n"));
681 /* <20120326, Kordan> To amplify the power of tone for Xtal calibration. (asked by Edlu) */
682 /* <20120326, Kordan> Only in single tone mode. (asked by Edlu) */
683 if (IS_HARDWARE_TYPE_8188E(pAdapter)) {
684 reg58 = PHY_QueryRFReg(pAdapter, RF_PATH_A, LNA_Low_Gain_3, bRFRegOffsetMask);
686 PHY_SetRFReg(pAdapter, RF_PATH_A, LNA_Low_Gain_3, bRFRegOffsetMask, reg58);
688 write_bbreg(pAdapter, rFPGA0_RFMOD, bCCKEn, 0x1);
689 write_bbreg(pAdapter, rFPGA0_RFMOD, bOFDMEn, 0x1);
691 _write_rfreg(pAdapter, RF_PATH_A, 0x21, BIT19, 0x00);
693 write_rfreg(pAdapter, RF_PATH_A, 0x00, 0x32d75); /* PAD all on. */
694 write_rfreg(pAdapter, RF_PATH_B, 0x00, 0x32d75); /* PAD all on. */
697 write_rfreg(pAdapter, rfPath, 0x21, 0x54000);
699 write_rfreg(pAdapter, rfPath, 0x00, 0x30000); /* PAD all on. */
703 /* Stop for dynamic set Power index. */
704 write_bbreg(pAdapter, rFPGA0_XA_HSSIParameter1, bMaskDWord, 0x01000100);
705 write_bbreg(pAdapter, rFPGA0_XB_HSSIParameter1, bMaskDWord, 0x01000100);
709 void Hal_SetCarrierSuppressionTx(struct adapter *pAdapter, u8 bStart)
711 pAdapter->mppriv.MptCtx.bCarrierSuppression = bStart;
713 /* Start Carrier Suppression. */
714 RT_TRACE(_module_mp_, _drv_alert_, ("SetCarrierSuppressionTx: test start\n"));
715 if (pAdapter->mppriv.rateidx <= MPT_RATE_11M) {
716 /* 1. if CCK block on? */
717 if (!read_bbreg(pAdapter, rFPGA0_RFMOD, bCCKEn))
718 write_bbreg(pAdapter, rFPGA0_RFMOD, bCCKEn, bEnable);/* set CCK block on */
720 /* Turn Off All Test Mode */
721 write_bbreg(pAdapter, rOFDM1_LSTF, bOFDMContinueTx, bDisable);
722 write_bbreg(pAdapter, rOFDM1_LSTF, bOFDMSingleCarrier, bDisable);
723 write_bbreg(pAdapter, rOFDM1_LSTF, bOFDMSingleTone, bDisable);
725 write_bbreg(pAdapter, rCCK0_System, bCCKBBMode, 0x2); /* transmit mode */
726 write_bbreg(pAdapter, rCCK0_System, bCCKScramble, 0x0); /* turn off scramble setting */
728 /* Set CCK Tx Test Rate */
729 write_bbreg(pAdapter, rCCK0_System, bCCKTxRate, 0x0); /* Set FTxRate to 1Mbps */
732 /* for dynamic set Power index. */
733 write_bbreg(pAdapter, rFPGA0_XA_HSSIParameter1, bMaskDWord, 0x01000500);
734 write_bbreg(pAdapter, rFPGA0_XB_HSSIParameter1, bMaskDWord, 0x01000500);
736 /* Stop Carrier Suppression. */
737 RT_TRACE(_module_mp_, _drv_alert_, ("SetCarrierSuppressionTx: test stop\n"));
738 if (pAdapter->mppriv.rateidx <= MPT_RATE_11M) {
739 write_bbreg(pAdapter, rCCK0_System, bCCKBBMode, 0x0); /* normal mode */
740 write_bbreg(pAdapter, rCCK0_System, bCCKScramble, 0x1); /* turn on scramble setting */
743 write_bbreg(pAdapter, rPMAC_Reset, bBBResetB, 0x0);
744 write_bbreg(pAdapter, rPMAC_Reset, bBBResetB, 0x1);
747 /* Stop for dynamic set Power index. */
748 write_bbreg(pAdapter, rFPGA0_XA_HSSIParameter1, bMaskDWord, 0x01000100);
749 write_bbreg(pAdapter, rFPGA0_XB_HSSIParameter1, bMaskDWord, 0x01000100);
753 void Hal_SetCCKContinuousTx(struct adapter *pAdapter, u8 bStart)
758 RT_TRACE(_module_mp_, _drv_alert_,
759 ("SetCCKContinuousTx: test start\n"));
761 /* 1. if CCK block on? */
762 if (!read_bbreg(pAdapter, rFPGA0_RFMOD, bCCKEn))
763 write_bbreg(pAdapter, rFPGA0_RFMOD, bCCKEn, bEnable);/* set CCK block on */
765 /* Turn Off All Test Mode */
766 write_bbreg(pAdapter, rOFDM1_LSTF, bOFDMContinueTx, bDisable);
767 write_bbreg(pAdapter, rOFDM1_LSTF, bOFDMSingleCarrier, bDisable);
768 write_bbreg(pAdapter, rOFDM1_LSTF, bOFDMSingleTone, bDisable);
769 /* Set CCK Tx Test Rate */
770 cckrate = pAdapter->mppriv.rateidx;
771 write_bbreg(pAdapter, rCCK0_System, bCCKTxRate, cckrate);
772 write_bbreg(pAdapter, rCCK0_System, bCCKBBMode, 0x2); /* transmit mode */
773 write_bbreg(pAdapter, rCCK0_System, bCCKScramble, bEnable); /* turn on scramble setting */
775 /* for dynamic set Power index. */
776 write_bbreg(pAdapter, rFPGA0_XA_HSSIParameter1, bMaskDWord, 0x01000500);
777 write_bbreg(pAdapter, rFPGA0_XB_HSSIParameter1, bMaskDWord, 0x01000500);
779 RT_TRACE(_module_mp_, _drv_info_,
780 ("SetCCKContinuousTx: test stop\n"));
782 write_bbreg(pAdapter, rCCK0_System, bCCKBBMode, 0x0); /* normal mode */
783 write_bbreg(pAdapter, rCCK0_System, bCCKScramble, bEnable); /* turn on scramble setting */
786 write_bbreg(pAdapter, rPMAC_Reset, bBBResetB, 0x0);
787 write_bbreg(pAdapter, rPMAC_Reset, bBBResetB, 0x1);
789 /* Stop for dynamic set Power index. */
790 write_bbreg(pAdapter, rFPGA0_XA_HSSIParameter1, bMaskDWord, 0x01000100);
791 write_bbreg(pAdapter, rFPGA0_XB_HSSIParameter1, bMaskDWord, 0x01000100);
794 pAdapter->mppriv.MptCtx.bCckContTx = bStart;
795 pAdapter->mppriv.MptCtx.bOfdmContTx = false;
796 } /* mpt_StartCckContTx */
798 void Hal_SetOFDMContinuousTx(struct adapter *pAdapter, u8 bStart)
801 RT_TRACE(_module_mp_, _drv_info_, ("SetOFDMContinuousTx: test start\n"));
802 /* 1. if OFDM block on? */
803 if (!read_bbreg(pAdapter, rFPGA0_RFMOD, bOFDMEn))
804 write_bbreg(pAdapter, rFPGA0_RFMOD, bOFDMEn, bEnable);/* set OFDM block on */
806 /* 2. set CCK test mode off, set to CCK normal mode */
807 write_bbreg(pAdapter, rCCK0_System, bCCKBBMode, bDisable);
809 /* 3. turn on scramble setting */
810 write_bbreg(pAdapter, rCCK0_System, bCCKScramble, bEnable);
811 /* 4. Turn On Continue Tx and turn off the other test modes. */
812 write_bbreg(pAdapter, rOFDM1_LSTF, bOFDMContinueTx, bEnable);
813 write_bbreg(pAdapter, rOFDM1_LSTF, bOFDMSingleCarrier, bDisable);
814 write_bbreg(pAdapter, rOFDM1_LSTF, bOFDMSingleTone, bDisable);
816 /* for dynamic set Power index. */
817 write_bbreg(pAdapter, rFPGA0_XA_HSSIParameter1, bMaskDWord, 0x01000500);
818 write_bbreg(pAdapter, rFPGA0_XB_HSSIParameter1, bMaskDWord, 0x01000500);
821 RT_TRACE(_module_mp_, _drv_info_, ("SetOFDMContinuousTx: test stop\n"));
822 write_bbreg(pAdapter, rOFDM1_LSTF, bOFDMContinueTx, bDisable);
823 write_bbreg(pAdapter, rOFDM1_LSTF, bOFDMSingleCarrier, bDisable);
824 write_bbreg(pAdapter, rOFDM1_LSTF, bOFDMSingleTone, bDisable);
828 write_bbreg(pAdapter, rPMAC_Reset, bBBResetB, 0x0);
829 write_bbreg(pAdapter, rPMAC_Reset, bBBResetB, 0x1);
831 /* Stop for dynamic set Power index. */
832 write_bbreg(pAdapter, rFPGA0_XA_HSSIParameter1, bMaskDWord, 0x01000100);
833 write_bbreg(pAdapter, rFPGA0_XB_HSSIParameter1, bMaskDWord, 0x01000100);
836 pAdapter->mppriv.MptCtx.bCckContTx = false;
837 pAdapter->mppriv.MptCtx.bOfdmContTx = bStart;
838 } /* mpt_StartOfdmContTx */
840 void Hal_SetContinuousTx(struct adapter *pAdapter, u8 bStart)
842 RT_TRACE(_module_mp_, _drv_info_,
843 ("SetContinuousTx: rate:%d\n", pAdapter->mppriv.rateidx));
845 pAdapter->mppriv.MptCtx.bStartContTx = bStart;
846 if (pAdapter->mppriv.rateidx <= MPT_RATE_11M)
847 Hal_SetCCKContinuousTx(pAdapter, bStart);
848 else if ((pAdapter->mppriv.rateidx >= MPT_RATE_6M) &&
849 (pAdapter->mppriv.rateidx <= MPT_RATE_MCS15))
850 Hal_SetOFDMContinuousTx(pAdapter, bStart);