Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. |
| 4 | * |
| 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. |
| 8 | * |
| 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 |
| 12 | * more details. |
| 13 | * |
| 14 | ******************************************************************************/ |
| 15 | /* Description: */ |
| 16 | /* This file is for 92CE/92CU dynamic mechanism only */ |
| 17 | |
| 18 | /* include files */ |
| 19 | |
| 20 | #include "odm_precomp.h" |
Jes Sorensen | 050abc4 | 2014-05-16 10:05:08 +0200 | [diff] [blame] | 21 | #include <usb_ops_linux.h> |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 22 | |
| 23 | #define DPK_DELTA_MAPPING_NUM 13 |
| 24 | #define index_mapping_HP_NUM 15 |
| 25 | /* 091212 chiyokolin */ |
Jes Sorensen | f1508fe | 2015-02-27 15:45:31 -0500 | [diff] [blame] | 26 | static void |
| 27 | odm_TXPowerTrackingCallback_ThermalMeter_92C(struct rtw_adapter *Adapter) |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 28 | { |
| 29 | struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter); |
| 30 | struct dm_priv *pdmpriv = &pHalData->dmpriv; |
| 31 | u8 ThermalValue = 0, delta, delta_LCK, delta_IQK, delta_HP; |
| 32 | int ele_A, ele_D, TempCCk, X, value32; |
| 33 | int Y, ele_C; |
| 34 | s8 OFDM_index[2], CCK_index = 0, OFDM_index_old[2] = {0}; |
| 35 | s8 CCK_index_old = 0; |
| 36 | int i = 0; |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 37 | u8 OFDM_min_index = 6, rf; /* OFDM BB Swing should be less than +3.0dB*/ |
| 38 | u8 ThermalValue_HP_count = 0; |
| 39 | u32 ThermalValue_HP = 0; |
| 40 | s32 index_mapping_HP[index_mapping_HP_NUM] = { |
| 41 | 0, 1, 3, 4, 6, |
| 42 | 7, 9, 10, 12, 13, |
| 43 | 15, 16, 18, 19, 21 |
| 44 | }; |
| 45 | s8 index_HP; |
| 46 | |
| 47 | pdmpriv->TXPowerTrackingCallbackCnt++; /* cosa add for debug */ |
| 48 | pdmpriv->bTXPowerTrackingInit = true; |
| 49 | |
| 50 | if (pHalData->CurrentChannel == 14 && !pdmpriv->bCCKinCH14) |
| 51 | pdmpriv->bCCKinCH14 = true; |
| 52 | else if (pHalData->CurrentChannel != 14 && pdmpriv->bCCKinCH14) |
| 53 | pdmpriv->bCCKinCH14 = false; |
| 54 | |
| 55 | ThermalValue = (u8)PHY_QueryRFReg(Adapter, RF_PATH_A, RF_T_METER, |
| 56 | 0x1f);/* 0x24: RF Reg[4:0] */ |
| 57 | |
| 58 | rtl8723a_phy_ap_calibrate(Adapter, (ThermalValue - |
| 59 | pHalData->EEPROMThermalMeter)); |
| 60 | |
Jes Sorensen | f1508fe | 2015-02-27 15:45:31 -0500 | [diff] [blame] | 61 | if (pHalData->rf_type == RF_2T2R) |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 62 | rf = 2; |
| 63 | else |
| 64 | rf = 1; |
| 65 | |
| 66 | if (ThermalValue) { |
| 67 | /* Query OFDM path A default setting */ |
| 68 | ele_D = PHY_QueryBBReg(Adapter, rOFDM0_XATxIQImbalance, |
| 69 | bMaskDWord)&bMaskOFDM_D; |
| 70 | for (i = 0; i < OFDM_TABLE_SIZE_92C; i++) { |
| 71 | /* find the index */ |
| 72 | if (ele_D == (OFDMSwingTable23A[i]&bMaskOFDM_D)) { |
| 73 | OFDM_index_old[0] = (u8)i; |
| 74 | break; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | /* Query OFDM path B default setting */ |
Jes Sorensen | f1508fe | 2015-02-27 15:45:31 -0500 | [diff] [blame] | 79 | if (pHalData->rf_type == RF_2T2R) { |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 80 | ele_D = PHY_QueryBBReg(Adapter, rOFDM0_XBTxIQImbalance, |
| 81 | bMaskDWord)&bMaskOFDM_D; |
| 82 | for (i = 0; i < OFDM_TABLE_SIZE_92C; i++) { /* find the index */ |
| 83 | if (ele_D == (OFDMSwingTable23A[i]&bMaskOFDM_D)) { |
| 84 | OFDM_index_old[1] = (u8)i; |
| 85 | break; |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | /* Query CCK default setting From 0xa24 */ |
| 91 | TempCCk = PHY_QueryBBReg(Adapter, rCCK0_TxFilter2, |
| 92 | bMaskDWord)&bMaskCCK; |
| 93 | for (i = 0 ; i < CCK_TABLE_SIZE ; i++) { |
| 94 | if (pdmpriv->bCCKinCH14) { |
| 95 | if (!memcmp(&TempCCk, |
| 96 | &CCKSwingTable_Ch1423A[i][2], 4)) { |
| 97 | CCK_index_old = (u8)i; |
| 98 | break; |
| 99 | } |
| 100 | } else { |
| 101 | if (!memcmp(&TempCCk, |
| 102 | &CCKSwingTable_Ch1_Ch1323A[i][2], 4)) { |
| 103 | CCK_index_old = (u8)i; |
| 104 | break; |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | if (!pdmpriv->ThermalValue) { |
| 110 | pdmpriv->ThermalValue = pHalData->EEPROMThermalMeter; |
| 111 | pdmpriv->ThermalValue_LCK = ThermalValue; |
| 112 | pdmpriv->ThermalValue_IQK = ThermalValue; |
| 113 | pdmpriv->ThermalValue_DPK = pHalData->EEPROMThermalMeter; |
| 114 | |
| 115 | for (i = 0; i < rf; i++) { |
| 116 | pdmpriv->OFDM_index_HP[i] = OFDM_index_old[i]; |
| 117 | pdmpriv->OFDM_index[i] = OFDM_index_old[i]; |
| 118 | } |
| 119 | pdmpriv->CCK_index_HP = CCK_index_old; |
| 120 | pdmpriv->CCK_index = CCK_index_old; |
| 121 | } |
| 122 | |
| 123 | if (pHalData->BoardType == BOARD_USB_High_PA) { |
| 124 | pdmpriv->ThermalValue_HP[pdmpriv->ThermalValue_HP_index] = ThermalValue; |
| 125 | pdmpriv->ThermalValue_HP_index++; |
| 126 | if (pdmpriv->ThermalValue_HP_index == HP_THERMAL_NUM) |
| 127 | pdmpriv->ThermalValue_HP_index = 0; |
| 128 | |
| 129 | for (i = 0; i < HP_THERMAL_NUM; i++) { |
| 130 | if (pdmpriv->ThermalValue_HP[i]) { |
| 131 | ThermalValue_HP += pdmpriv->ThermalValue_HP[i]; |
| 132 | ThermalValue_HP_count++; |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | if (ThermalValue_HP_count) |
| 137 | ThermalValue = (u8)(ThermalValue_HP / ThermalValue_HP_count); |
| 138 | } |
| 139 | |
| 140 | delta = (ThermalValue > pdmpriv->ThermalValue) ? |
| 141 | (ThermalValue - pdmpriv->ThermalValue) : |
| 142 | (pdmpriv->ThermalValue - ThermalValue); |
| 143 | if (pHalData->BoardType == BOARD_USB_High_PA) { |
| 144 | if (pdmpriv->bDoneTxpower) |
| 145 | delta_HP = (ThermalValue > pdmpriv->ThermalValue) ? |
| 146 | (ThermalValue - pdmpriv->ThermalValue) : |
| 147 | (pdmpriv->ThermalValue - ThermalValue); |
| 148 | else |
| 149 | delta_HP = ThermalValue > pHalData->EEPROMThermalMeter ? |
| 150 | (ThermalValue - pHalData->EEPROMThermalMeter) : |
| 151 | (pHalData->EEPROMThermalMeter - ThermalValue); |
| 152 | } else { |
| 153 | delta_HP = 0; |
| 154 | } |
| 155 | delta_LCK = (ThermalValue > pdmpriv->ThermalValue_LCK) ? |
| 156 | (ThermalValue - pdmpriv->ThermalValue_LCK) : |
| 157 | (pdmpriv->ThermalValue_LCK - ThermalValue); |
| 158 | delta_IQK = (ThermalValue > pdmpriv->ThermalValue_IQK) ? |
| 159 | (ThermalValue - pdmpriv->ThermalValue_IQK) : |
| 160 | (pdmpriv->ThermalValue_IQK - ThermalValue); |
| 161 | |
| 162 | if (delta_LCK > 1) { |
| 163 | pdmpriv->ThermalValue_LCK = ThermalValue; |
| 164 | rtl8723a_phy_lc_calibrate(Adapter); |
| 165 | } |
| 166 | |
| 167 | if ((delta > 0 || delta_HP > 0) && pdmpriv->TxPowerTrackControl) { |
| 168 | if (pHalData->BoardType == BOARD_USB_High_PA) { |
| 169 | pdmpriv->bDoneTxpower = true; |
| 170 | delta_HP = ThermalValue > pHalData->EEPROMThermalMeter ? |
| 171 | (ThermalValue - pHalData->EEPROMThermalMeter) : |
| 172 | (pHalData->EEPROMThermalMeter - ThermalValue); |
| 173 | |
| 174 | if (delta_HP > index_mapping_HP_NUM-1) |
| 175 | index_HP = index_mapping_HP[index_mapping_HP_NUM-1]; |
| 176 | else |
| 177 | index_HP = index_mapping_HP[delta_HP]; |
| 178 | |
| 179 | if (ThermalValue > pHalData->EEPROMThermalMeter) { |
| 180 | /* set larger Tx power */ |
| 181 | for (i = 0; i < rf; i++) |
| 182 | OFDM_index[i] = pdmpriv->OFDM_index_HP[i] - index_HP; |
| 183 | CCK_index = pdmpriv->CCK_index_HP - index_HP; |
| 184 | } else { |
| 185 | for (i = 0; i < rf; i++) |
| 186 | OFDM_index[i] = pdmpriv->OFDM_index_HP[i] + index_HP; |
| 187 | CCK_index = pdmpriv->CCK_index_HP + index_HP; |
| 188 | } |
| 189 | |
| 190 | delta_HP = (ThermalValue > pdmpriv->ThermalValue) ? |
| 191 | (ThermalValue - pdmpriv->ThermalValue) : |
| 192 | (pdmpriv->ThermalValue - ThermalValue); |
| 193 | } else { |
| 194 | if (ThermalValue > pdmpriv->ThermalValue) { |
| 195 | for (i = 0; i < rf; i++) |
| 196 | pdmpriv->OFDM_index[i] -= delta; |
| 197 | pdmpriv->CCK_index -= delta; |
| 198 | } else { |
| 199 | for (i = 0; i < rf; i++) |
| 200 | pdmpriv->OFDM_index[i] += delta; |
| 201 | pdmpriv->CCK_index += delta; |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | /* no adjust */ |
| 206 | if (pHalData->BoardType != BOARD_USB_High_PA) { |
| 207 | if (ThermalValue > pHalData->EEPROMThermalMeter) { |
| 208 | for (i = 0; i < rf; i++) |
| 209 | OFDM_index[i] = pdmpriv->OFDM_index[i]+1; |
| 210 | CCK_index = pdmpriv->CCK_index+1; |
| 211 | } else { |
| 212 | for (i = 0; i < rf; i++) |
| 213 | OFDM_index[i] = pdmpriv->OFDM_index[i]; |
| 214 | CCK_index = pdmpriv->CCK_index; |
| 215 | } |
| 216 | } |
| 217 | for (i = 0; i < rf; i++) { |
| 218 | if (OFDM_index[i] > (OFDM_TABLE_SIZE_92C-1)) |
| 219 | OFDM_index[i] = (OFDM_TABLE_SIZE_92C-1); |
| 220 | else if (OFDM_index[i] < OFDM_min_index) |
| 221 | OFDM_index[i] = OFDM_min_index; |
| 222 | } |
| 223 | |
| 224 | if (CCK_index > (CCK_TABLE_SIZE-1)) |
| 225 | CCK_index = (CCK_TABLE_SIZE-1); |
| 226 | else if (CCK_index < 0) |
| 227 | CCK_index = 0; |
| 228 | } |
| 229 | |
| 230 | if (pdmpriv->TxPowerTrackControl && (delta != 0 || delta_HP != 0)) { |
| 231 | /* Adujst OFDM Ant_A according to IQK result */ |
| 232 | ele_D = (OFDMSwingTable23A[OFDM_index[0]] & 0xFFC00000)>>22; |
| 233 | X = pdmpriv->RegE94; |
| 234 | Y = pdmpriv->RegE9C; |
| 235 | |
| 236 | if (X != 0) { |
| 237 | if ((X & 0x00000200) != 0) |
| 238 | X = X | 0xFFFFFC00; |
| 239 | ele_A = ((X * ele_D)>>8)&0x000003FF; |
| 240 | |
| 241 | /* new element C = element D x Y */ |
| 242 | if ((Y & 0x00000200) != 0) |
| 243 | Y = Y | 0xFFFFFC00; |
| 244 | ele_C = ((Y * ele_D)>>8)&0x000003FF; |
| 245 | |
| 246 | /* write new elements A, C, D to regC80 and regC94, element B is always 0 */ |
| 247 | value32 = (ele_D<<22)|((ele_C&0x3F)<<16)|ele_A; |
| 248 | PHY_SetBBReg(Adapter, rOFDM0_XATxIQImbalance, bMaskDWord, value32); |
| 249 | |
| 250 | value32 = (ele_C&0x000003C0)>>6; |
| 251 | PHY_SetBBReg(Adapter, rOFDM0_XCTxAFE, bMaskH4Bits, value32); |
| 252 | |
| 253 | value32 = ((X * ele_D)>>7)&0x01; |
Jes Sorensen | a3f2146 | 2014-05-16 10:03:47 +0200 | [diff] [blame] | 254 | PHY_SetBBReg(Adapter, rOFDM0_ECCAThreshold, |
| 255 | BIT(31), value32); |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 256 | |
| 257 | value32 = ((Y * ele_D)>>7)&0x01; |
Jes Sorensen | a3f2146 | 2014-05-16 10:03:47 +0200 | [diff] [blame] | 258 | PHY_SetBBReg(Adapter, rOFDM0_ECCAThreshold, |
| 259 | BIT(29), value32); |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 260 | } else { |
Jes Sorensen | a3f2146 | 2014-05-16 10:03:47 +0200 | [diff] [blame] | 261 | PHY_SetBBReg(Adapter, rOFDM0_XATxIQImbalance, |
| 262 | bMaskDWord, |
| 263 | OFDMSwingTable23A[OFDM_index[0]]); |
| 264 | PHY_SetBBReg(Adapter, rOFDM0_XCTxAFE, |
| 265 | bMaskH4Bits, 0x00); |
| 266 | PHY_SetBBReg(Adapter, rOFDM0_ECCAThreshold, |
| 267 | BIT(31) | BIT(29), 0x00); |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | /* Adjust CCK according to IQK result */ |
| 271 | if (!pdmpriv->bCCKinCH14) { |
Jes Sorensen | edbfd67 | 2014-05-16 10:05:09 +0200 | [diff] [blame] | 272 | rtl8723au_write8(Adapter, 0xa22, CCKSwingTable_Ch1_Ch1323A[CCK_index][0]); |
| 273 | rtl8723au_write8(Adapter, 0xa23, CCKSwingTable_Ch1_Ch1323A[CCK_index][1]); |
| 274 | rtl8723au_write8(Adapter, 0xa24, CCKSwingTable_Ch1_Ch1323A[CCK_index][2]); |
| 275 | rtl8723au_write8(Adapter, 0xa25, CCKSwingTable_Ch1_Ch1323A[CCK_index][3]); |
| 276 | rtl8723au_write8(Adapter, 0xa26, CCKSwingTable_Ch1_Ch1323A[CCK_index][4]); |
| 277 | rtl8723au_write8(Adapter, 0xa27, CCKSwingTable_Ch1_Ch1323A[CCK_index][5]); |
| 278 | rtl8723au_write8(Adapter, 0xa28, CCKSwingTable_Ch1_Ch1323A[CCK_index][6]); |
| 279 | rtl8723au_write8(Adapter, 0xa29, CCKSwingTable_Ch1_Ch1323A[CCK_index][7]); |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 280 | } else { |
Jes Sorensen | edbfd67 | 2014-05-16 10:05:09 +0200 | [diff] [blame] | 281 | rtl8723au_write8(Adapter, 0xa22, CCKSwingTable_Ch1423A[CCK_index][0]); |
| 282 | rtl8723au_write8(Adapter, 0xa23, CCKSwingTable_Ch1423A[CCK_index][1]); |
| 283 | rtl8723au_write8(Adapter, 0xa24, CCKSwingTable_Ch1423A[CCK_index][2]); |
| 284 | rtl8723au_write8(Adapter, 0xa25, CCKSwingTable_Ch1423A[CCK_index][3]); |
| 285 | rtl8723au_write8(Adapter, 0xa26, CCKSwingTable_Ch1423A[CCK_index][4]); |
| 286 | rtl8723au_write8(Adapter, 0xa27, CCKSwingTable_Ch1423A[CCK_index][5]); |
| 287 | rtl8723au_write8(Adapter, 0xa28, CCKSwingTable_Ch1423A[CCK_index][6]); |
| 288 | rtl8723au_write8(Adapter, 0xa29, CCKSwingTable_Ch1423A[CCK_index][7]); |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 289 | } |
| 290 | |
Jes Sorensen | f1508fe | 2015-02-27 15:45:31 -0500 | [diff] [blame] | 291 | if (pHalData->rf_type == RF_2T2R) { |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 292 | ele_D = (OFDMSwingTable23A[(u8)OFDM_index[1]] & 0xFFC00000)>>22; |
| 293 | |
| 294 | /* new element A = element D x X */ |
| 295 | X = pdmpriv->RegEB4; |
| 296 | Y = pdmpriv->RegEBC; |
| 297 | |
| 298 | if (X != 0) { |
| 299 | if ((X & 0x00000200) != 0) /* consider minus */ |
| 300 | X = X | 0xFFFFFC00; |
| 301 | ele_A = ((X * ele_D)>>8)&0x000003FF; |
| 302 | |
| 303 | /* new element C = element D x Y */ |
| 304 | if ((Y & 0x00000200) != 0) |
| 305 | Y = Y | 0xFFFFFC00; |
| 306 | ele_C = ((Y * ele_D)>>8)&0x00003FF; |
| 307 | |
| 308 | /* write new elements A, C, D to regC88 and regC9C, element B is always 0 */ |
| 309 | value32 = (ele_D<<22)|((ele_C&0x3F)<<16) | ele_A; |
| 310 | PHY_SetBBReg(Adapter, rOFDM0_XBTxIQImbalance, bMaskDWord, value32); |
| 311 | |
| 312 | value32 = (ele_C&0x000003C0)>>6; |
| 313 | PHY_SetBBReg(Adapter, rOFDM0_XDTxAFE, bMaskH4Bits, value32); |
| 314 | |
| 315 | value32 = ((X * ele_D)>>7)&0x01; |
Jes Sorensen | a3f2146 | 2014-05-16 10:03:47 +0200 | [diff] [blame] | 316 | PHY_SetBBReg(Adapter, |
| 317 | rOFDM0_ECCAThreshold, |
| 318 | BIT(27), value32); |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 319 | |
| 320 | value32 = ((Y * ele_D)>>7)&0x01; |
Jes Sorensen | a3f2146 | 2014-05-16 10:03:47 +0200 | [diff] [blame] | 321 | PHY_SetBBReg(Adapter, |
| 322 | rOFDM0_ECCAThreshold, |
| 323 | BIT(25), value32); |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 324 | } else { |
Jes Sorensen | a3f2146 | 2014-05-16 10:03:47 +0200 | [diff] [blame] | 325 | PHY_SetBBReg(Adapter, |
| 326 | rOFDM0_XBTxIQImbalance, |
| 327 | bMaskDWord, |
| 328 | OFDMSwingTable23A[OFDM_index[1]]); |
| 329 | PHY_SetBBReg(Adapter, |
| 330 | rOFDM0_XDTxAFE, |
| 331 | bMaskH4Bits, 0x00); |
| 332 | PHY_SetBBReg(Adapter, |
| 333 | rOFDM0_ECCAThreshold, |
| 334 | BIT(27) | BIT(25), 0x00); |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 335 | } |
| 336 | } |
| 337 | |
| 338 | } |
| 339 | if (delta_IQK > 3) { |
| 340 | pdmpriv->ThermalValue_IQK = ThermalValue; |
| 341 | rtl8723a_phy_iq_calibrate(Adapter, false); |
| 342 | } |
| 343 | |
| 344 | /* update thermal meter value */ |
| 345 | if (pdmpriv->TxPowerTrackControl) |
| 346 | pdmpriv->ThermalValue = ThermalValue; |
| 347 | } |
| 348 | pdmpriv->TXPowercount = 0; |
| 349 | } |
| 350 | |
| 351 | /* Description: */ |
| 352 | /* - Dispatch TxPower Tracking direct call ONLY for 92s. */ |
| 353 | /* - We shall NOT schedule Workitem within PASSIVE LEVEL, which will cause system resource */ |
| 354 | /* leakage under some platform. */ |
| 355 | /* Assumption: */ |
| 356 | /* PASSIVE_LEVEL when this routine is called. */ |
| 357 | static void ODM_TXPowerTracking92CDirectCall(struct rtw_adapter *Adapter) |
| 358 | { |
| 359 | odm_TXPowerTrackingCallback_ThermalMeter_92C(Adapter); |
| 360 | } |
| 361 | |
Jes Sorensen | 4be419e | 2015-03-02 15:24:46 -0500 | [diff] [blame] | 362 | void rtl8723a_odm_check_tx_power_tracking(struct rtw_adapter *Adapter) |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 363 | { |
| 364 | struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter); |
| 365 | struct dm_priv *pdmpriv = &pHalData->dmpriv; |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 366 | |
| 367 | if (!pdmpriv->TM_Trigger) { /* at least delay 1 sec */ |
| 368 | PHY_SetRFReg(Adapter, RF_PATH_A, RF_T_METER, bRFRegOffsetMask, 0x60); |
| 369 | |
| 370 | pdmpriv->TM_Trigger = 1; |
| 371 | return; |
| 372 | } else { |
| 373 | ODM_TXPowerTracking92CDirectCall(Adapter); |
| 374 | pdmpriv->TM_Trigger = 0; |
| 375 | } |
| 376 | } |
| 377 | |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 378 | /* IQK */ |
| 379 | #define MAX_TOLERANCE 5 |
| 380 | #define IQK_DELAY_TIME 1 /* ms */ |
| 381 | |
| 382 | static u8 _PHY_PathA_IQK(struct rtw_adapter *pAdapter, bool configPathB) |
| 383 | { |
| 384 | u32 regEAC, regE94, regE9C, regEA4; |
| 385 | u8 result = 0x00; |
| 386 | struct hal_data_8723a *pHalData = GET_HAL_DATA(pAdapter); |
| 387 | |
| 388 | /* path-A IQK setting */ |
| 389 | PHY_SetBBReg(pAdapter, rTx_IQK_Tone_A, bMaskDWord, 0x10008c1f); |
| 390 | PHY_SetBBReg(pAdapter, rRx_IQK_Tone_A, bMaskDWord, 0x10008c1f); |
| 391 | PHY_SetBBReg(pAdapter, rTx_IQK_PI_A, bMaskDWord, 0x82140102); |
| 392 | |
| 393 | PHY_SetBBReg(pAdapter, rRx_IQK_PI_A, bMaskDWord, configPathB ? 0x28160202 : |
| 394 | IS_81xxC_VENDOR_UMC_B_CUT(pHalData->VersionID)?0x28160202:0x28160502); |
| 395 | |
| 396 | /* path-B IQK setting */ |
| 397 | if (configPathB) { |
| 398 | PHY_SetBBReg(pAdapter, rTx_IQK_Tone_B, bMaskDWord, 0x10008c22); |
| 399 | PHY_SetBBReg(pAdapter, rRx_IQK_Tone_B, bMaskDWord, 0x10008c22); |
| 400 | PHY_SetBBReg(pAdapter, rTx_IQK_PI_B, bMaskDWord, 0x82140102); |
| 401 | PHY_SetBBReg(pAdapter, rRx_IQK_PI_B, bMaskDWord, 0x28160202); |
| 402 | } |
| 403 | |
| 404 | /* LO calibration setting */ |
| 405 | PHY_SetBBReg(pAdapter, rIQK_AGC_Rsp, bMaskDWord, 0x001028d1); |
| 406 | |
| 407 | /* One shot, path A LOK & IQK */ |
| 408 | PHY_SetBBReg(pAdapter, rIQK_AGC_Pts, bMaskDWord, 0xf9000000); |
| 409 | PHY_SetBBReg(pAdapter, rIQK_AGC_Pts, bMaskDWord, 0xf8000000); |
| 410 | |
| 411 | /* delay x ms */ |
| 412 | udelay(IQK_DELAY_TIME*1000);/* PlatformStallExecution(IQK_DELAY_TIME*1000); */ |
| 413 | |
| 414 | /* Check failed */ |
| 415 | regEAC = PHY_QueryBBReg(pAdapter, rRx_Power_After_IQK_A_2, bMaskDWord); |
| 416 | regE94 = PHY_QueryBBReg(pAdapter, rTx_Power_Before_IQK_A, bMaskDWord); |
| 417 | regE9C = PHY_QueryBBReg(pAdapter, rTx_Power_After_IQK_A, bMaskDWord); |
| 418 | regEA4 = PHY_QueryBBReg(pAdapter, rRx_Power_Before_IQK_A_2, bMaskDWord); |
| 419 | |
Jes Sorensen | a3f2146 | 2014-05-16 10:03:47 +0200 | [diff] [blame] | 420 | if (!(regEAC & BIT(28)) && |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 421 | (((regE94 & 0x03FF0000)>>16) != 0x142) && |
| 422 | (((regE9C & 0x03FF0000)>>16) != 0x42)) |
| 423 | result |= 0x01; |
| 424 | else /* if Tx not OK, ignore Rx */ |
| 425 | return result; |
| 426 | |
Jes Sorensen | a3f2146 | 2014-05-16 10:03:47 +0200 | [diff] [blame] | 427 | if (!(regEAC & BIT(27)) && /* if Tx is OK, check whether Rx is OK */ |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 428 | (((regEA4 & 0x03FF0000)>>16) != 0x132) && |
| 429 | (((regEAC & 0x03FF0000)>>16) != 0x36)) |
| 430 | result |= 0x02; |
| 431 | else |
| 432 | DBG_8723A("Path A Rx IQK fail!!\n"); |
| 433 | return result; |
| 434 | } |
| 435 | |
| 436 | static u8 _PHY_PathB_IQK(struct rtw_adapter *pAdapter) |
| 437 | { |
| 438 | u32 regEAC, regEB4, regEBC, regEC4, regECC; |
| 439 | u8 result = 0x00; |
| 440 | |
| 441 | /* One shot, path B LOK & IQK */ |
| 442 | PHY_SetBBReg(pAdapter, rIQK_AGC_Cont, bMaskDWord, 0x00000002); |
| 443 | PHY_SetBBReg(pAdapter, rIQK_AGC_Cont, bMaskDWord, 0x00000000); |
| 444 | |
| 445 | /* delay x ms */ |
| 446 | udelay(IQK_DELAY_TIME*1000); |
| 447 | |
| 448 | /* Check failed */ |
| 449 | regEAC = PHY_QueryBBReg(pAdapter, rRx_Power_After_IQK_A_2, bMaskDWord); |
| 450 | regEB4 = PHY_QueryBBReg(pAdapter, rTx_Power_Before_IQK_B, bMaskDWord); |
| 451 | regEBC = PHY_QueryBBReg(pAdapter, rTx_Power_After_IQK_B, bMaskDWord); |
| 452 | regEC4 = PHY_QueryBBReg(pAdapter, rRx_Power_Before_IQK_B_2, bMaskDWord); |
| 453 | regECC = PHY_QueryBBReg(pAdapter, rRx_Power_After_IQK_B_2, bMaskDWord); |
| 454 | |
Jes Sorensen | a3f2146 | 2014-05-16 10:03:47 +0200 | [diff] [blame] | 455 | if (!(regEAC & BIT(31)) && |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 456 | (((regEB4 & 0x03FF0000)>>16) != 0x142) && |
| 457 | (((regEBC & 0x03FF0000)>>16) != 0x42)) |
| 458 | result |= 0x01; |
| 459 | else |
| 460 | return result; |
| 461 | |
Jes Sorensen | a3f2146 | 2014-05-16 10:03:47 +0200 | [diff] [blame] | 462 | if (!(regEAC & BIT(30)) && |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 463 | (((regEC4 & 0x03FF0000)>>16) != 0x132) && |
| 464 | (((regECC & 0x03FF0000)>>16) != 0x36)) |
| 465 | result |= 0x02; |
| 466 | else |
| 467 | DBG_8723A("Path B Rx IQK fail!!\n"); |
| 468 | return result; |
| 469 | } |
| 470 | |
| 471 | static void _PHY_PathAFillIQKMatrix(struct rtw_adapter *pAdapter, |
| 472 | bool bIQKOK, |
| 473 | int result[][8], |
| 474 | u8 final_candidate, |
| 475 | bool bTxOnly |
| 476 | ) |
| 477 | { |
| 478 | u32 Oldval_0, X, TX0_A, reg; |
| 479 | s32 Y, TX0_C; |
| 480 | |
| 481 | DBG_8723A("Path A IQ Calibration %s !\n", (bIQKOK)?"Success":"Failed"); |
| 482 | |
| 483 | if (final_candidate == 0xFF) { |
| 484 | return; |
| 485 | } else if (bIQKOK) { |
| 486 | Oldval_0 = (PHY_QueryBBReg(pAdapter, rOFDM0_XATxIQImbalance, bMaskDWord) >> 22) & 0x3FF; |
| 487 | |
| 488 | X = result[final_candidate][0]; |
| 489 | if ((X & 0x00000200) != 0) |
| 490 | X = X | 0xFFFFFC00; |
| 491 | TX0_A = (X * Oldval_0) >> 8; |
| 492 | PHY_SetBBReg(pAdapter, rOFDM0_XATxIQImbalance, 0x3FF, TX0_A); |
| 493 | PHY_SetBBReg(pAdapter, rOFDM0_ECCAThreshold, BIT(31), ((X * Oldval_0>>7) & 0x1)); |
| 494 | |
| 495 | Y = result[final_candidate][1]; |
| 496 | if ((Y & 0x00000200) != 0) |
| 497 | Y = Y | 0xFFFFFC00; |
| 498 | TX0_C = (Y * Oldval_0) >> 8; |
| 499 | PHY_SetBBReg(pAdapter, rOFDM0_XCTxAFE, 0xF0000000, ((TX0_C&0x3C0)>>6)); |
| 500 | PHY_SetBBReg(pAdapter, rOFDM0_XATxIQImbalance, 0x003F0000, (TX0_C&0x3F)); |
| 501 | PHY_SetBBReg(pAdapter, rOFDM0_ECCAThreshold, BIT(29), ((Y * Oldval_0>>7) & 0x1)); |
| 502 | |
| 503 | if (bTxOnly) { |
| 504 | DBG_8723A("_PHY_PathAFillIQKMatrix only Tx OK\n"); |
| 505 | return; |
| 506 | } |
| 507 | |
| 508 | reg = result[final_candidate][2]; |
| 509 | PHY_SetBBReg(pAdapter, rOFDM0_XARxIQImbalance, 0x3FF, reg); |
| 510 | |
| 511 | reg = result[final_candidate][3] & 0x3F; |
| 512 | PHY_SetBBReg(pAdapter, rOFDM0_XARxIQImbalance, 0xFC00, reg); |
| 513 | |
| 514 | reg = (result[final_candidate][3] >> 6) & 0xF; |
| 515 | PHY_SetBBReg(pAdapter, rOFDM0_RxIQExtAnta, 0xF0000000, reg); |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | static void _PHY_PathBFillIQKMatrix(struct rtw_adapter *pAdapter, bool bIQKOK, int result[][8], u8 final_candidate, bool bTxOnly) |
| 520 | { |
| 521 | u32 Oldval_1, X, TX1_A, reg; |
| 522 | s32 Y, TX1_C; |
| 523 | |
| 524 | DBG_8723A("Path B IQ Calibration %s !\n", (bIQKOK)?"Success":"Failed"); |
| 525 | |
| 526 | if (final_candidate == 0xFF) { |
| 527 | return; |
| 528 | } else if (bIQKOK) { |
| 529 | Oldval_1 = (PHY_QueryBBReg(pAdapter, rOFDM0_XBTxIQImbalance, bMaskDWord) >> 22) & 0x3FF; |
| 530 | |
| 531 | X = result[final_candidate][4]; |
| 532 | if ((X & 0x00000200) != 0) |
| 533 | X = X | 0xFFFFFC00; |
| 534 | TX1_A = (X * Oldval_1) >> 8; |
| 535 | PHY_SetBBReg(pAdapter, rOFDM0_XBTxIQImbalance, 0x3FF, TX1_A); |
| 536 | PHY_SetBBReg(pAdapter, rOFDM0_ECCAThreshold, BIT(27), ((X * Oldval_1>>7) & 0x1)); |
| 537 | |
| 538 | Y = result[final_candidate][5]; |
| 539 | if ((Y & 0x00000200) != 0) |
| 540 | Y = Y | 0xFFFFFC00; |
| 541 | TX1_C = (Y * Oldval_1) >> 8; |
| 542 | PHY_SetBBReg(pAdapter, rOFDM0_XDTxAFE, 0xF0000000, ((TX1_C&0x3C0)>>6)); |
| 543 | PHY_SetBBReg(pAdapter, rOFDM0_XBTxIQImbalance, 0x003F0000, (TX1_C&0x3F)); |
| 544 | PHY_SetBBReg(pAdapter, rOFDM0_ECCAThreshold, BIT(25), ((Y * Oldval_1>>7) & 0x1)); |
| 545 | |
| 546 | if (bTxOnly) |
| 547 | return; |
| 548 | |
| 549 | reg = result[final_candidate][6]; |
| 550 | PHY_SetBBReg(pAdapter, rOFDM0_XBRxIQImbalance, 0x3FF, reg); |
| 551 | |
| 552 | reg = result[final_candidate][7] & 0x3F; |
| 553 | PHY_SetBBReg(pAdapter, rOFDM0_XBRxIQImbalance, 0xFC00, reg); |
| 554 | |
| 555 | reg = (result[final_candidate][7] >> 6) & 0xF; |
| 556 | PHY_SetBBReg(pAdapter, rOFDM0_AGCRSSITable, 0x0000F000, reg); |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | static void _PHY_SaveADDARegisters(struct rtw_adapter *pAdapter, u32 *ADDAReg, u32 *ADDABackup, u32 RegisterNum) |
| 561 | { |
| 562 | u32 i; |
| 563 | |
| 564 | for (i = 0 ; i < RegisterNum ; i++) { |
| 565 | ADDABackup[i] = PHY_QueryBBReg(pAdapter, ADDAReg[i], bMaskDWord); |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | static void _PHY_SaveMACRegisters(struct rtw_adapter *pAdapter, u32 *MACReg, u32 *MACBackup) |
| 570 | { |
| 571 | u32 i; |
| 572 | |
| 573 | for (i = 0 ; i < (IQK_MAC_REG_NUM - 1); i++) { |
Jes Sorensen | 050abc4 | 2014-05-16 10:05:08 +0200 | [diff] [blame] | 574 | MACBackup[i] = rtl8723au_read8(pAdapter, MACReg[i]); |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 575 | } |
Jes Sorensen | 050abc4 | 2014-05-16 10:05:08 +0200 | [diff] [blame] | 576 | MACBackup[i] = rtl8723au_read32(pAdapter, MACReg[i]); |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | static void _PHY_ReloadADDARegisters(struct rtw_adapter *pAdapter, u32 *ADDAReg, u32 *ADDABackup, u32 RegiesterNum) |
| 580 | { |
| 581 | u32 i; |
| 582 | |
| 583 | for (i = 0 ; i < RegiesterNum ; i++) { |
| 584 | PHY_SetBBReg(pAdapter, ADDAReg[i], bMaskDWord, ADDABackup[i]); |
| 585 | } |
| 586 | } |
| 587 | |
| 588 | static void _PHY_ReloadMACRegisters(struct rtw_adapter *pAdapter, u32 *MACReg, u32 *MACBackup) |
| 589 | { |
| 590 | u32 i; |
| 591 | |
Jes Sorensen | edbfd67 | 2014-05-16 10:05:09 +0200 | [diff] [blame] | 592 | for (i = 0 ; i < (IQK_MAC_REG_NUM - 1); i++) |
| 593 | rtl8723au_write8(pAdapter, MACReg[i], (u8)MACBackup[i]); |
| 594 | |
| 595 | rtl8723au_write32(pAdapter, MACReg[i], MACBackup[i]); |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | static void _PHY_PathADDAOn(struct rtw_adapter *pAdapter, u32 *ADDAReg, bool isPathAOn, bool is2T) |
| 599 | { |
| 600 | u32 pathOn; |
| 601 | u32 i; |
| 602 | |
| 603 | pathOn = isPathAOn ? 0x04db25a4 : 0x0b1b25a4; |
Roberta Dobrescu | 08551cb | 2014-10-26 23:30:05 +0200 | [diff] [blame] | 604 | if (!is2T) { |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 605 | pathOn = 0x0bdb25a0; |
| 606 | PHY_SetBBReg(pAdapter, ADDAReg[0], bMaskDWord, 0x0b1b25a0); |
| 607 | } else { |
| 608 | PHY_SetBBReg(pAdapter, ADDAReg[0], bMaskDWord, pathOn); |
| 609 | } |
| 610 | |
| 611 | for (i = 1 ; i < IQK_ADDA_REG_NUM ; i++) |
| 612 | PHY_SetBBReg(pAdapter, ADDAReg[i], bMaskDWord, pathOn); |
| 613 | } |
| 614 | |
| 615 | static void _PHY_MACSettingCalibration(struct rtw_adapter *pAdapter, u32 *MACReg, u32 *MACBackup) |
| 616 | { |
| 617 | u32 i = 0; |
| 618 | |
Jes Sorensen | edbfd67 | 2014-05-16 10:05:09 +0200 | [diff] [blame] | 619 | rtl8723au_write8(pAdapter, MACReg[i], 0x3F); |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 620 | |
| 621 | for (i = 1 ; i < (IQK_MAC_REG_NUM - 1); i++) { |
Jes Sorensen | edbfd67 | 2014-05-16 10:05:09 +0200 | [diff] [blame] | 622 | rtl8723au_write8(pAdapter, MACReg[i], |
| 623 | (u8)(MACBackup[i] & ~BIT(3))); |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 624 | } |
Jes Sorensen | edbfd67 | 2014-05-16 10:05:09 +0200 | [diff] [blame] | 625 | rtl8723au_write8(pAdapter, MACReg[i], (u8)(MACBackup[i] & ~BIT(5))); |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | static void _PHY_PathAStandBy(struct rtw_adapter *pAdapter) |
| 629 | { |
| 630 | PHY_SetBBReg(pAdapter, rFPGA0_IQK, bMaskDWord, 0x0); |
| 631 | PHY_SetBBReg(pAdapter, 0x840, bMaskDWord, 0x00010000); |
| 632 | PHY_SetBBReg(pAdapter, rFPGA0_IQK, bMaskDWord, 0x80800000); |
| 633 | } |
| 634 | |
| 635 | static void _PHY_PIModeSwitch(struct rtw_adapter *pAdapter, bool PIMode) |
| 636 | { |
| 637 | u32 mode; |
| 638 | |
| 639 | mode = PIMode ? 0x01000100 : 0x01000000; |
| 640 | PHY_SetBBReg(pAdapter, 0x820, bMaskDWord, mode); |
| 641 | PHY_SetBBReg(pAdapter, 0x828, bMaskDWord, mode); |
| 642 | } |
| 643 | |
| 644 | /* |
| 645 | return false => do IQK again |
| 646 | */ |
| 647 | static bool _PHY_SimularityCompare(struct rtw_adapter *pAdapter, int result[][8], u8 c1, u8 c2) |
| 648 | { |
| 649 | u32 i, j, diff, SimularityBitMap, bound = 0; |
| 650 | struct hal_data_8723a *pHalData = GET_HAL_DATA(pAdapter); |
| 651 | u8 final_candidate[2] = {0xFF, 0xFF}; /* for path A and path B */ |
Jes Sorensen | f1508fe | 2015-02-27 15:45:31 -0500 | [diff] [blame] | 652 | bool bResult = true; |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 653 | |
Jes Sorensen | f1508fe | 2015-02-27 15:45:31 -0500 | [diff] [blame] | 654 | if (pHalData->rf_type == RF_2T2R) |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 655 | bound = 8; |
| 656 | else |
| 657 | bound = 4; |
| 658 | |
| 659 | SimularityBitMap = 0; |
| 660 | |
| 661 | for (i = 0; i < bound; i++) { |
| 662 | diff = (result[c1][i] > result[c2][i]) ? (result[c1][i] - result[c2][i]) : (result[c2][i] - result[c1][i]); |
| 663 | if (diff > MAX_TOLERANCE) { |
| 664 | if ((i == 2 || i == 6) && !SimularityBitMap) { |
| 665 | if (result[c1][i]+result[c1][i+1] == 0) |
| 666 | final_candidate[(i/4)] = c2; |
| 667 | else if (result[c2][i]+result[c2][i+1] == 0) |
| 668 | final_candidate[(i/4)] = c1; |
| 669 | else |
| 670 | SimularityBitMap = SimularityBitMap|(1<<i); |
| 671 | } else { |
| 672 | SimularityBitMap = SimularityBitMap|(1<<i); |
| 673 | } |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | if (SimularityBitMap == 0) { |
| 678 | for (i = 0; i < (bound/4); i++) { |
| 679 | if (final_candidate[i] != 0xFF) { |
| 680 | for (j = i*4; j < (i+1)*4-2; j++) |
| 681 | result[3][j] = result[final_candidate[i]][j]; |
| 682 | bResult = false; |
| 683 | } |
| 684 | } |
| 685 | return bResult; |
| 686 | } else if (!(SimularityBitMap & 0x0F)) { |
| 687 | /* path A OK */ |
| 688 | for (i = 0; i < 4; i++) |
| 689 | result[3][i] = result[c1][i]; |
| 690 | return false; |
Jes Sorensen | f1508fe | 2015-02-27 15:45:31 -0500 | [diff] [blame] | 691 | } else if (!(SimularityBitMap & 0xF0) && pHalData->rf_type == RF_2T2R) { |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 692 | /* path B OK */ |
| 693 | for (i = 4; i < 8; i++) |
| 694 | result[3][i] = result[c1][i]; |
| 695 | return false; |
| 696 | } else { |
| 697 | return false; |
| 698 | } |
| 699 | } |
| 700 | |
| 701 | static void _PHY_IQCalibrate(struct rtw_adapter *pAdapter, int result[][8], u8 t, bool is2T) |
| 702 | { |
| 703 | struct hal_data_8723a *pHalData = GET_HAL_DATA(pAdapter); |
| 704 | struct dm_priv *pdmpriv = &pHalData->dmpriv; |
| 705 | u32 i; |
| 706 | u8 PathAOK, PathBOK; |
| 707 | u32 ADDA_REG[IQK_ADDA_REG_NUM] = { |
| 708 | rFPGA0_XCD_SwitchControl, rBlue_Tooth, |
| 709 | rRx_Wait_CCA, rTx_CCK_RFON, |
| 710 | rTx_CCK_BBON, rTx_OFDM_RFON, |
| 711 | rTx_OFDM_BBON, rTx_To_Rx, |
| 712 | rTx_To_Tx, rRx_CCK, |
| 713 | rRx_OFDM, rRx_Wait_RIFS, |
| 714 | rRx_TO_Rx, rStandby, |
| 715 | rSleep, rPMPD_ANAEN |
| 716 | }; |
| 717 | |
| 718 | u32 IQK_MAC_REG[IQK_MAC_REG_NUM] = { |
| 719 | REG_TXPAUSE, REG_BCN_CTRL, |
| 720 | REG_BCN_CTRL_1, REG_GPIO_MUXCFG |
| 721 | }; |
| 722 | |
| 723 | u32 IQK_BB_REG_92C[IQK_BB_REG_NUM] = { |
| 724 | rOFDM0_TRxPathEnable, rOFDM0_TRMuxPar, |
| 725 | rFPGA0_XCD_RFInterfaceSW, rConfig_AntA, rConfig_AntB, |
| 726 | rFPGA0_XAB_RFInterfaceSW, rFPGA0_XA_RFInterfaceOE, |
| 727 | rFPGA0_XB_RFInterfaceOE, rFPGA0_RFMOD |
| 728 | }; |
| 729 | |
| 730 | const u32 retryCount = 2; |
| 731 | |
| 732 | /* Note: IQ calibration must be performed after loading */ |
| 733 | /* PHY_REG.txt , and radio_a, radio_b.txt */ |
| 734 | |
| 735 | u32 bbvalue; |
| 736 | |
| 737 | if (t == 0) { |
| 738 | bbvalue = PHY_QueryBBReg(pAdapter, rFPGA0_RFMOD, bMaskDWord); |
| 739 | |
| 740 | /* Save ADDA parameters, turn Path A ADDA on */ |
| 741 | _PHY_SaveADDARegisters(pAdapter, ADDA_REG, pdmpriv->ADDA_backup, IQK_ADDA_REG_NUM); |
| 742 | _PHY_SaveMACRegisters(pAdapter, IQK_MAC_REG, pdmpriv->IQK_MAC_backup); |
| 743 | _PHY_SaveADDARegisters(pAdapter, IQK_BB_REG_92C, pdmpriv->IQK_BB_backup, IQK_BB_REG_NUM); |
| 744 | } |
| 745 | _PHY_PathADDAOn(pAdapter, ADDA_REG, true, is2T); |
| 746 | |
| 747 | if (t == 0) |
Jes Sorensen | a3f2146 | 2014-05-16 10:03:47 +0200 | [diff] [blame] | 748 | pdmpriv->bRfPiEnable = (u8) |
| 749 | PHY_QueryBBReg(pAdapter, rFPGA0_XA_HSSIParameter1, |
| 750 | BIT(8)); |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 751 | |
| 752 | if (!pdmpriv->bRfPiEnable) { |
| 753 | /* Switch BB to PI mode to do IQ Calibration. */ |
| 754 | _PHY_PIModeSwitch(pAdapter, true); |
| 755 | } |
| 756 | |
Jes Sorensen | a3f2146 | 2014-05-16 10:03:47 +0200 | [diff] [blame] | 757 | PHY_SetBBReg(pAdapter, rFPGA0_RFMOD, BIT(24), 0x00); |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 758 | PHY_SetBBReg(pAdapter, rOFDM0_TRxPathEnable, bMaskDWord, 0x03a05600); |
| 759 | PHY_SetBBReg(pAdapter, rOFDM0_TRMuxPar, bMaskDWord, 0x000800e4); |
| 760 | PHY_SetBBReg(pAdapter, rFPGA0_XCD_RFInterfaceSW, bMaskDWord, 0x22204000); |
Jes Sorensen | a3f2146 | 2014-05-16 10:03:47 +0200 | [diff] [blame] | 761 | PHY_SetBBReg(pAdapter, rFPGA0_XAB_RFInterfaceSW, BIT(10), 0x01); |
| 762 | PHY_SetBBReg(pAdapter, rFPGA0_XAB_RFInterfaceSW, BIT(26), 0x01); |
| 763 | PHY_SetBBReg(pAdapter, rFPGA0_XA_RFInterfaceOE, BIT(10), 0x00); |
| 764 | PHY_SetBBReg(pAdapter, rFPGA0_XB_RFInterfaceOE, BIT(10), 0x00); |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 765 | |
| 766 | if (is2T) { |
| 767 | PHY_SetBBReg(pAdapter, rFPGA0_XA_LSSIParameter, bMaskDWord, 0x00010000); |
| 768 | PHY_SetBBReg(pAdapter, rFPGA0_XB_LSSIParameter, bMaskDWord, 0x00010000); |
| 769 | } |
| 770 | |
| 771 | /* MAC settings */ |
| 772 | _PHY_MACSettingCalibration(pAdapter, IQK_MAC_REG, pdmpriv->IQK_MAC_backup); |
| 773 | |
| 774 | /* Page B init */ |
| 775 | PHY_SetBBReg(pAdapter, rConfig_AntA, bMaskDWord, 0x00080000); |
| 776 | |
| 777 | if (is2T) |
| 778 | PHY_SetBBReg(pAdapter, rConfig_AntB, bMaskDWord, 0x00080000); |
| 779 | |
| 780 | /* IQ calibration setting */ |
| 781 | PHY_SetBBReg(pAdapter, rFPGA0_IQK, bMaskDWord, 0x80800000); |
| 782 | PHY_SetBBReg(pAdapter, rTx_IQK, bMaskDWord, 0x01007c00); |
| 783 | PHY_SetBBReg(pAdapter, rRx_IQK, bMaskDWord, 0x01004800); |
| 784 | |
| 785 | for (i = 0 ; i < retryCount ; i++) { |
| 786 | PathAOK = _PHY_PathA_IQK(pAdapter, is2T); |
| 787 | if (PathAOK == 0x03) { |
| 788 | DBG_8723A("Path A IQK Success!!\n"); |
| 789 | result[t][0] = (PHY_QueryBBReg(pAdapter, rTx_Power_Before_IQK_A, bMaskDWord)&0x3FF0000)>>16; |
| 790 | result[t][1] = (PHY_QueryBBReg(pAdapter, rTx_Power_After_IQK_A, bMaskDWord)&0x3FF0000)>>16; |
| 791 | result[t][2] = (PHY_QueryBBReg(pAdapter, rRx_Power_Before_IQK_A_2, bMaskDWord)&0x3FF0000)>>16; |
| 792 | result[t][3] = (PHY_QueryBBReg(pAdapter, rRx_Power_After_IQK_A_2, bMaskDWord)&0x3FF0000)>>16; |
| 793 | break; |
| 794 | } else if (i == (retryCount-1) && PathAOK == 0x01) { |
| 795 | /* Tx IQK OK */ |
| 796 | DBG_8723A("Path A IQK Only Tx Success!!\n"); |
| 797 | |
| 798 | result[t][0] = (PHY_QueryBBReg(pAdapter, rTx_Power_Before_IQK_A, bMaskDWord)&0x3FF0000)>>16; |
| 799 | result[t][1] = (PHY_QueryBBReg(pAdapter, rTx_Power_After_IQK_A, bMaskDWord)&0x3FF0000)>>16; |
| 800 | } |
| 801 | } |
| 802 | |
| 803 | if (0x00 == PathAOK) { |
| 804 | DBG_8723A("Path A IQK failed!!\n"); |
| 805 | } |
| 806 | |
| 807 | if (is2T) { |
| 808 | _PHY_PathAStandBy(pAdapter); |
| 809 | |
| 810 | /* Turn Path B ADDA on */ |
| 811 | _PHY_PathADDAOn(pAdapter, ADDA_REG, false, is2T); |
| 812 | |
| 813 | for (i = 0 ; i < retryCount ; i++) { |
| 814 | PathBOK = _PHY_PathB_IQK(pAdapter); |
| 815 | if (PathBOK == 0x03) { |
| 816 | DBG_8723A("Path B IQK Success!!\n"); |
| 817 | result[t][4] = (PHY_QueryBBReg(pAdapter, rTx_Power_Before_IQK_B, bMaskDWord)&0x3FF0000)>>16; |
| 818 | result[t][5] = (PHY_QueryBBReg(pAdapter, rTx_Power_After_IQK_B, bMaskDWord)&0x3FF0000)>>16; |
| 819 | result[t][6] = (PHY_QueryBBReg(pAdapter, rRx_Power_Before_IQK_B_2, bMaskDWord)&0x3FF0000)>>16; |
| 820 | result[t][7] = (PHY_QueryBBReg(pAdapter, rRx_Power_After_IQK_B_2, bMaskDWord)&0x3FF0000)>>16; |
| 821 | break; |
| 822 | } else if (i == (retryCount - 1) && PathBOK == 0x01) { |
| 823 | /* Tx IQK OK */ |
| 824 | DBG_8723A("Path B Only Tx IQK Success!!\n"); |
| 825 | result[t][4] = (PHY_QueryBBReg(pAdapter, rTx_Power_Before_IQK_B, bMaskDWord)&0x3FF0000)>>16; |
| 826 | result[t][5] = (PHY_QueryBBReg(pAdapter, rTx_Power_After_IQK_B, bMaskDWord)&0x3FF0000)>>16; |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | if (0x00 == PathBOK) { |
| 831 | DBG_8723A("Path B IQK failed!!\n"); |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | /* Back to BB mode, load original value */ |
| 836 | PHY_SetBBReg(pAdapter, rFPGA0_IQK, bMaskDWord, 0); |
| 837 | |
| 838 | if (t != 0) { |
| 839 | if (!pdmpriv->bRfPiEnable) { |
| 840 | /* Switch back BB to SI mode after finish IQ Calibration. */ |
| 841 | _PHY_PIModeSwitch(pAdapter, false); |
| 842 | } |
| 843 | |
| 844 | /* Reload ADDA power saving parameters */ |
| 845 | _PHY_ReloadADDARegisters(pAdapter, ADDA_REG, pdmpriv->ADDA_backup, IQK_ADDA_REG_NUM); |
| 846 | |
| 847 | /* Reload MAC parameters */ |
| 848 | _PHY_ReloadMACRegisters(pAdapter, IQK_MAC_REG, pdmpriv->IQK_MAC_backup); |
| 849 | |
| 850 | /* Reload BB parameters */ |
| 851 | _PHY_ReloadADDARegisters(pAdapter, IQK_BB_REG_92C, pdmpriv->IQK_BB_backup, IQK_BB_REG_NUM); |
| 852 | |
| 853 | /* Restore RX initial gain */ |
| 854 | PHY_SetBBReg(pAdapter, rFPGA0_XA_LSSIParameter, bMaskDWord, 0x00032ed3); |
| 855 | if (is2T) { |
| 856 | PHY_SetBBReg(pAdapter, rFPGA0_XB_LSSIParameter, bMaskDWord, 0x00032ed3); |
| 857 | } |
| 858 | |
| 859 | /* load 0xe30 IQC default value */ |
| 860 | PHY_SetBBReg(pAdapter, rTx_IQK_Tone_A, bMaskDWord, 0x01008c00); |
| 861 | PHY_SetBBReg(pAdapter, rRx_IQK_Tone_A, bMaskDWord, 0x01008c00); |
| 862 | |
| 863 | } |
| 864 | } |
| 865 | |
| 866 | static void _PHY_LCCalibrate(struct rtw_adapter *pAdapter, bool is2T) |
| 867 | { |
| 868 | u8 tmpReg; |
| 869 | u32 RF_Amode = 0, RF_Bmode = 0, LC_Cal; |
| 870 | |
| 871 | /* Check continuous TX and Packet TX */ |
Jes Sorensen | 050abc4 | 2014-05-16 10:05:08 +0200 | [diff] [blame] | 872 | tmpReg = rtl8723au_read8(pAdapter, 0xd03); |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 873 | |
Jes Sorensen | edbfd67 | 2014-05-16 10:05:09 +0200 | [diff] [blame] | 874 | if ((tmpReg&0x70) != 0) { |
| 875 | /* Deal with contisuous TX case */ |
| 876 | /* disable all continuous TX */ |
| 877 | rtl8723au_write8(pAdapter, 0xd03, tmpReg&0x8F); |
| 878 | } else { |
| 879 | /* Deal with Packet TX case */ |
| 880 | /* block all queues */ |
| 881 | rtl8723au_write8(pAdapter, REG_TXPAUSE, 0xFF); |
| 882 | } |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 883 | |
| 884 | if ((tmpReg&0x70) != 0) { |
| 885 | /* 1. Read original RF mode */ |
| 886 | /* Path-A */ |
| 887 | RF_Amode = PHY_QueryRFReg(pAdapter, RF_PATH_A, RF_AC, bMask12Bits); |
| 888 | |
| 889 | /* Path-B */ |
| 890 | if (is2T) |
| 891 | RF_Bmode = PHY_QueryRFReg(pAdapter, RF_PATH_B, RF_AC, bMask12Bits); |
| 892 | |
| 893 | /* 2. Set RF mode = standby mode */ |
| 894 | /* Path-A */ |
| 895 | PHY_SetRFReg(pAdapter, RF_PATH_A, RF_AC, bMask12Bits, (RF_Amode&0x8FFFF)|0x10000); |
| 896 | |
| 897 | /* Path-B */ |
| 898 | if (is2T) |
| 899 | PHY_SetRFReg(pAdapter, RF_PATH_B, RF_AC, bMask12Bits, (RF_Bmode&0x8FFFF)|0x10000); |
| 900 | } |
| 901 | |
| 902 | /* 3. Read RF reg18 */ |
| 903 | LC_Cal = PHY_QueryRFReg(pAdapter, RF_PATH_A, RF_CHNLBW, bMask12Bits); |
| 904 | |
| 905 | /* 4. Set LC calibration begin */ |
| 906 | PHY_SetRFReg(pAdapter, RF_PATH_A, RF_CHNLBW, bMask12Bits, LC_Cal|0x08000); |
| 907 | |
| 908 | msleep(100); |
| 909 | |
| 910 | /* Restore original situation */ |
| 911 | if ((tmpReg&0x70) != 0) { /* Deal with contuous TX case */ |
| 912 | /* Path-A */ |
Jes Sorensen | edbfd67 | 2014-05-16 10:05:09 +0200 | [diff] [blame] | 913 | rtl8723au_write8(pAdapter, 0xd03, tmpReg); |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 914 | PHY_SetRFReg(pAdapter, RF_PATH_A, RF_AC, bMask12Bits, RF_Amode); |
| 915 | |
| 916 | /* Path-B */ |
| 917 | if (is2T) |
| 918 | PHY_SetRFReg(pAdapter, RF_PATH_B, RF_AC, bMask12Bits, RF_Bmode); |
Jes Sorensen | edbfd67 | 2014-05-16 10:05:09 +0200 | [diff] [blame] | 919 | } else /* Deal with Packet TX case */ |
| 920 | rtl8723au_write8(pAdapter, REG_TXPAUSE, 0x00); |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | /* Analog Pre-distortion calibration */ |
| 924 | #define APK_BB_REG_NUM 8 |
| 925 | #define APK_CURVE_REG_NUM 4 |
| 926 | #define PATH_NUM 2 |
| 927 | |
| 928 | void rtl8723a_phy_iq_calibrate(struct rtw_adapter *pAdapter, bool bReCovery) |
| 929 | { |
| 930 | struct hal_data_8723a *pHalData = GET_HAL_DATA(pAdapter); |
| 931 | struct dm_priv *pdmpriv = &pHalData->dmpriv; |
| 932 | s32 result[4][8]; /* last is final result */ |
| 933 | u8 i, final_candidate; |
| 934 | bool bPathAOK, bPathBOK; |
| 935 | s32 RegE94, RegE9C, RegEA4, RegEAC, RegEB4, RegEBC, RegEC4; |
| 936 | s32 RegECC, RegTmp = 0; |
| 937 | bool is12simular, is13simular, is23simular; |
| 938 | bool bStartContTx = false, bSingleTone = false; |
| 939 | bool bCarrierSuppression = false; |
| 940 | u32 IQK_BB_REG_92C[IQK_BB_REG_NUM] = { |
| 941 | rOFDM0_XARxIQImbalance, rOFDM0_XBRxIQImbalance, |
| 942 | rOFDM0_ECCAThreshold, rOFDM0_AGCRSSITable, |
| 943 | rOFDM0_XATxIQImbalance, rOFDM0_XBTxIQImbalance, |
| 944 | rOFDM0_XCTxAFE, rOFDM0_XDTxAFE, |
| 945 | rOFDM0_RxIQExtAnta |
| 946 | }; |
| 947 | |
| 948 | /* ignore IQK when continuous Tx */ |
| 949 | if (bStartContTx || bSingleTone || bCarrierSuppression) |
| 950 | return; |
| 951 | |
| 952 | if (bReCovery) { |
| 953 | _PHY_ReloadADDARegisters(pAdapter, IQK_BB_REG_92C, pdmpriv->IQK_BB_backup_recover, 9); |
| 954 | return; |
| 955 | } |
| 956 | DBG_8723A("IQK:Start!!!\n"); |
| 957 | |
| 958 | for (i = 0; i < 8; i++) { |
| 959 | result[0][i] = 0; |
| 960 | result[1][i] = 0; |
| 961 | result[2][i] = 0; |
| 962 | result[3][i] = 0; |
| 963 | } |
| 964 | final_candidate = 0xff; |
| 965 | bPathAOK = false; |
| 966 | bPathBOK = false; |
| 967 | is12simular = false; |
| 968 | is23simular = false; |
| 969 | is13simular = false; |
| 970 | |
| 971 | for (i = 0; i < 3; i++) { |
Jes Sorensen | 277c722 | 2015-02-27 15:45:32 -0500 | [diff] [blame] | 972 | if (pHalData->rf_type == RF_2T2R) |
| 973 | _PHY_IQCalibrate(pAdapter, result, i, true); |
| 974 | else /* For 88C 1T1R */ |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 975 | _PHY_IQCalibrate(pAdapter, result, i, false); |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 976 | |
| 977 | if (i == 1) { |
| 978 | is12simular = _PHY_SimularityCompare(pAdapter, result, 0, 1); |
| 979 | if (is12simular) { |
| 980 | final_candidate = 0; |
| 981 | break; |
| 982 | } |
| 983 | } |
| 984 | |
| 985 | if (i == 2) { |
| 986 | is13simular = _PHY_SimularityCompare(pAdapter, result, 0, 2); |
| 987 | if (is13simular) { |
| 988 | final_candidate = 0; |
| 989 | break; |
| 990 | } |
| 991 | |
| 992 | is23simular = _PHY_SimularityCompare(pAdapter, result, 1, 2); |
| 993 | if (is23simular) { |
| 994 | final_candidate = 1; |
| 995 | } else { |
| 996 | for (i = 0; i < 8; i++) |
| 997 | RegTmp += result[3][i]; |
| 998 | |
| 999 | if (RegTmp != 0) |
| 1000 | final_candidate = 3; |
| 1001 | else |
| 1002 | final_candidate = 0xFF; |
| 1003 | } |
| 1004 | } |
| 1005 | } |
| 1006 | |
| 1007 | for (i = 0; i < 4; i++) { |
| 1008 | RegE94 = result[i][0]; |
| 1009 | RegE9C = result[i][1]; |
| 1010 | RegEA4 = result[i][2]; |
| 1011 | RegEAC = result[i][3]; |
| 1012 | RegEB4 = result[i][4]; |
| 1013 | RegEBC = result[i][5]; |
| 1014 | RegEC4 = result[i][6]; |
| 1015 | RegECC = result[i][7]; |
| 1016 | } |
| 1017 | |
| 1018 | if (final_candidate != 0xff) { |
| 1019 | RegE94 = result[final_candidate][0]; |
| 1020 | pdmpriv->RegE94 = RegE94; |
| 1021 | RegE9C = result[final_candidate][1]; |
| 1022 | pdmpriv->RegE9C = RegE9C; |
| 1023 | RegEA4 = result[final_candidate][2]; |
| 1024 | RegEAC = result[final_candidate][3]; |
| 1025 | RegEB4 = result[final_candidate][4]; |
| 1026 | pdmpriv->RegEB4 = RegEB4; |
| 1027 | RegEBC = result[final_candidate][5]; |
| 1028 | pdmpriv->RegEBC = RegEBC; |
| 1029 | RegEC4 = result[final_candidate][6]; |
| 1030 | RegECC = result[final_candidate][7]; |
| 1031 | DBG_8723A("IQK: final_candidate is %x\n", final_candidate); |
| 1032 | DBG_8723A("IQK: RegE94 =%x RegE9C =%x RegEA4 =%x RegEAC =%x RegEB4 =%x RegEBC =%x RegEC4 =%x RegECC =%x\n ", |
| 1033 | RegE94, RegE9C, RegEA4, RegEAC, RegEB4, RegEBC, RegEC4, RegECC); |
| 1034 | bPathAOK = bPathBOK = true; |
| 1035 | } else { |
| 1036 | RegE94 = RegEB4 = pdmpriv->RegE94 = pdmpriv->RegEB4 = 0x100; /* X default value */ |
| 1037 | RegE9C = RegEBC = pdmpriv->RegE9C = pdmpriv->RegEBC = 0x0; /* Y default value */ |
| 1038 | } |
| 1039 | |
| 1040 | if ((RegE94 != 0)/*&&(RegEA4 != 0)*/) |
| 1041 | _PHY_PathAFillIQKMatrix(pAdapter, bPathAOK, result, final_candidate, (RegEA4 == 0)); |
| 1042 | |
Jes Sorensen | 277c722 | 2015-02-27 15:45:32 -0500 | [diff] [blame] | 1043 | if (pHalData->rf_type == RF_2T2R) { |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 1044 | if ((RegEB4 != 0)/*&&(RegEC4 != 0)*/) |
Jes Sorensen | 277c722 | 2015-02-27 15:45:32 -0500 | [diff] [blame] | 1045 | _PHY_PathBFillIQKMatrix(pAdapter, bPathBOK, result, |
| 1046 | final_candidate, (RegEC4 == 0)); |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 1047 | } |
| 1048 | |
| 1049 | _PHY_SaveADDARegisters(pAdapter, IQK_BB_REG_92C, pdmpriv->IQK_BB_backup_recover, 9); |
| 1050 | } |
| 1051 | |
| 1052 | void rtl8723a_phy_lc_calibrate(struct rtw_adapter *pAdapter) |
| 1053 | { |
| 1054 | struct hal_data_8723a *pHalData = GET_HAL_DATA(pAdapter); |
| 1055 | struct mlme_ext_priv *pmlmeext = &pAdapter->mlmeextpriv; |
| 1056 | bool bStartContTx = false, bSingleTone = false, bCarrierSuppression = false; |
| 1057 | |
| 1058 | /* ignore IQK when continuous Tx */ |
| 1059 | if (bStartContTx || bSingleTone || bCarrierSuppression) |
| 1060 | return; |
| 1061 | |
| 1062 | if (pmlmeext->sitesurvey_res.state == SCAN_PROCESS) |
| 1063 | return; |
| 1064 | |
Jes Sorensen | 277c722 | 2015-02-27 15:45:32 -0500 | [diff] [blame] | 1065 | if (pHalData->rf_type == RF_2T2R) |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 1066 | _PHY_LCCalibrate(pAdapter, true); |
Jes Sorensen | 277c722 | 2015-02-27 15:45:32 -0500 | [diff] [blame] | 1067 | else /* For 88C 1T1R */ |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 1068 | _PHY_LCCalibrate(pAdapter, false); |
Larry Finger | f7c92d2 | 2014-03-28 21:37:39 -0500 | [diff] [blame] | 1069 | } |
| 1070 | |
| 1071 | void |
| 1072 | rtl8723a_phy_ap_calibrate(struct rtw_adapter *pAdapter, char delta) |
| 1073 | { |
| 1074 | } |