Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | // SPDX-License-Identifier: GPL-2.0 /****************************************************************************** * * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. * ******************************************************************************/ /* include "Mp_Precomp.h" */ #include "odm_precomp.h" void ConfigureTxpowerTrack(struct dm_odm_t *pDM_Odm, struct txpwrtrack_cfg *pConfig) { ConfigureTxpowerTrack_8723B(pConfig); } /* */ /* <20121113, Kordan> This function should be called when TxAGC changed. */ /* Otherwise the previous compensation is gone, because we record the */ /* delta of temperature between two TxPowerTracking watch dogs. */ /* */ /* NOTE: If Tx BB swing or Tx scaling is varified during run-time, still */ /* need to call this function. */ /* */ void ODM_ClearTxPowerTrackingState(struct dm_odm_t *pDM_Odm) { struct hal_com_data *pHalData = GET_HAL_DATA(pDM_Odm->Adapter); u8 p = 0; pDM_Odm->BbSwingIdxCckBase = pDM_Odm->DefaultCckIndex; pDM_Odm->BbSwingIdxCck = pDM_Odm->DefaultCckIndex; pDM_Odm->RFCalibrateInfo.CCK_index = 0; for (p = RF_PATH_A; p < MAX_RF_PATH; ++p) { pDM_Odm->BbSwingIdxOfdmBase[p] = pDM_Odm->DefaultOfdmIndex; pDM_Odm->BbSwingIdxOfdm[p] = pDM_Odm->DefaultOfdmIndex; pDM_Odm->RFCalibrateInfo.OFDM_index[p] = pDM_Odm->DefaultOfdmIndex; pDM_Odm->RFCalibrateInfo.PowerIndexOffset[p] = 0; pDM_Odm->RFCalibrateInfo.DeltaPowerIndex[p] = 0; pDM_Odm->RFCalibrateInfo.DeltaPowerIndexLast[p] = 0; pDM_Odm->RFCalibrateInfo.PowerIndexOffset[p] = 0; /* Initial Mix mode power tracking */ pDM_Odm->Absolute_OFDMSwingIdx[p] = 0; pDM_Odm->Remnant_OFDMSwingIdx[p] = 0; } /* Initial at Modify Tx Scaling Mode */ pDM_Odm->Modify_TxAGC_Flag_PathA = false; /* Initial at Modify Tx Scaling Mode */ pDM_Odm->Modify_TxAGC_Flag_PathB = false; pDM_Odm->Remnant_CCKSwingIdx = 0; pDM_Odm->RFCalibrateInfo.ThermalValue = pHalData->EEPROMThermalMeter; pDM_Odm->RFCalibrateInfo.ThermalValue_IQK = pHalData->EEPROMThermalMeter; pDM_Odm->RFCalibrateInfo.ThermalValue_LCK = pHalData->EEPROMThermalMeter; } void ODM_TXPowerTrackingCallback_ThermalMeter(struct adapter *Adapter) { struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); struct dm_odm_t *pDM_Odm = &pHalData->odmpriv; u8 ThermalValue = 0, delta, delta_LCK, p = 0, i = 0; u8 ThermalValue_AVG_count = 0; u32 ThermalValue_AVG = 0; u8 OFDM_min_index = 0; /* OFDM BB Swing should be less than +3.0dB, which is required by Arthur */ u8 Indexforchannel = 0; /* GetRightChnlPlaceforIQK(pHalData->CurrentChannel) */ struct txpwrtrack_cfg c; /* 4 1. The following TWO tables decide the final index of OFDM/CCK swing table. */ u8 *deltaSwingTableIdx_TUP_A; u8 *deltaSwingTableIdx_TDOWN_A; u8 *deltaSwingTableIdx_TUP_B; u8 *deltaSwingTableIdx_TDOWN_B; /* 4 2. Initialization (7 steps in total) */ ConfigureTxpowerTrack(pDM_Odm, &c); (*c.GetDeltaSwingTable)( pDM_Odm, (u8 **)&deltaSwingTableIdx_TUP_A, (u8 **)&deltaSwingTableIdx_TDOWN_A, (u8 **)&deltaSwingTableIdx_TUP_B, (u8 **)&deltaSwingTableIdx_TDOWN_B ); /* cosa add for debug */ pDM_Odm->RFCalibrateInfo.TXPowerTrackingCallbackCnt++; pDM_Odm->RFCalibrateInfo.bTXPowerTrackingInit = true; ThermalValue = (u8)PHY_QueryRFReg(pDM_Odm->Adapter, RF_PATH_A, c.ThermalRegAddr, 0xfc00); /* 0x42: RF Reg[15:10] 88E */ if ( !pDM_Odm->RFCalibrateInfo.TxPowerTrackControl || pHalData->EEPROMThermalMeter == 0 || pHalData->EEPROMThermalMeter == 0xFF ) return; /* 4 3. Initialize ThermalValues of RFCalibrateInfo */ /* 4 4. Calculate average thermal meter */ pDM_Odm->RFCalibrateInfo.ThermalValue_AVG[pDM_Odm->RFCalibrateInfo.ThermalValue_AVG_index] = ThermalValue; pDM_Odm->RFCalibrateInfo.ThermalValue_AVG_index++; if (pDM_Odm->RFCalibrateInfo.ThermalValue_AVG_index == c.AverageThermalNum) /* Average times = c.AverageThermalNum */ pDM_Odm->RFCalibrateInfo.ThermalValue_AVG_index = 0; for (i = 0; i < c.AverageThermalNum; i++) { if (pDM_Odm->RFCalibrateInfo.ThermalValue_AVG[i]) { ThermalValue_AVG += pDM_Odm->RFCalibrateInfo.ThermalValue_AVG[i]; ThermalValue_AVG_count++; } } /* Calculate Average ThermalValue after average enough times */ if (ThermalValue_AVG_count) { ThermalValue = (u8)(ThermalValue_AVG / ThermalValue_AVG_count); } /* 4 5. Calculate delta, delta_LCK */ /* delta" here is used to determine whether thermal value changes or not. */ delta = (ThermalValue > pDM_Odm->RFCalibrateInfo.ThermalValue) ? (ThermalValue - pDM_Odm->RFCalibrateInfo.ThermalValue) : (pDM_Odm->RFCalibrateInfo.ThermalValue - ThermalValue); delta_LCK = (ThermalValue > pDM_Odm->RFCalibrateInfo.ThermalValue_LCK) ? (ThermalValue - pDM_Odm->RFCalibrateInfo.ThermalValue_LCK) : (pDM_Odm->RFCalibrateInfo.ThermalValue_LCK - ThermalValue); /* 4 6. If necessary, do LCK. */ /* Delta temperature is equal to or larger than 20 centigrade. */ if (delta_LCK >= c.Threshold_IQK) { pDM_Odm->RFCalibrateInfo.ThermalValue_LCK = ThermalValue; if (c.PHY_LCCalibrate) (*c.PHY_LCCalibrate)(pDM_Odm); } /* 3 7. If necessary, move the index of swing table to adjust Tx power. */ if (delta > 0 && pDM_Odm->RFCalibrateInfo.TxPowerTrackControl) { /* delta" here is used to record the absolute value of difference. */ delta = ThermalValue > pHalData->EEPROMThermalMeter ? (ThermalValue - pHalData->EEPROMThermalMeter) : (pHalData->EEPROMThermalMeter - ThermalValue); if (delta >= TXPWR_TRACK_TABLE_SIZE) delta = TXPWR_TRACK_TABLE_SIZE - 1; /* 4 7.1 The Final Power Index = BaseIndex + PowerIndexOffset */ if (ThermalValue > pHalData->EEPROMThermalMeter) { pDM_Odm->RFCalibrateInfo.DeltaPowerIndexLast[RF_PATH_A] = pDM_Odm->RFCalibrateInfo.DeltaPowerIndex[RF_PATH_A]; pDM_Odm->RFCalibrateInfo.DeltaPowerIndex[RF_PATH_A] = deltaSwingTableIdx_TUP_A[delta]; /* Record delta swing for mix mode power tracking */ pDM_Odm->Absolute_OFDMSwingIdx[RF_PATH_A] = deltaSwingTableIdx_TUP_A[delta]; if (c.RfPathCount > 1) { pDM_Odm->RFCalibrateInfo.DeltaPowerIndexLast[RF_PATH_B] = pDM_Odm->RFCalibrateInfo.DeltaPowerIndex[RF_PATH_B]; pDM_Odm->RFCalibrateInfo.DeltaPowerIndex[RF_PATH_B] = deltaSwingTableIdx_TUP_B[delta]; /* Record delta swing for mix mode power tracking */ pDM_Odm->Absolute_OFDMSwingIdx[RF_PATH_B] = deltaSwingTableIdx_TUP_B[delta]; } } else { pDM_Odm->RFCalibrateInfo.DeltaPowerIndexLast[RF_PATH_A] = pDM_Odm->RFCalibrateInfo.DeltaPowerIndex[RF_PATH_A]; pDM_Odm->RFCalibrateInfo.DeltaPowerIndex[RF_PATH_A] = -1 * deltaSwingTableIdx_TDOWN_A[delta]; /* Record delta swing for mix mode power tracking */ pDM_Odm->Absolute_OFDMSwingIdx[RF_PATH_A] = -1 * deltaSwingTableIdx_TDOWN_A[delta]; if (c.RfPathCount > 1) { pDM_Odm->RFCalibrateInfo.DeltaPowerIndexLast[RF_PATH_B] = pDM_Odm->RFCalibrateInfo.DeltaPowerIndex[RF_PATH_B]; pDM_Odm->RFCalibrateInfo.DeltaPowerIndex[RF_PATH_B] = -1 * deltaSwingTableIdx_TDOWN_B[delta]; /* Record delta swing for mix mode power tracking */ pDM_Odm->Absolute_OFDMSwingIdx[RF_PATH_B] = -1 * deltaSwingTableIdx_TDOWN_B[delta]; } } for (p = RF_PATH_A; p < c.RfPathCount; p++) { if ( pDM_Odm->RFCalibrateInfo.DeltaPowerIndex[p] == pDM_Odm->RFCalibrateInfo.DeltaPowerIndexLast[p] ) /* If Thermal value changes but lookup table value still the same */ pDM_Odm->RFCalibrateInfo.PowerIndexOffset[p] = 0; else pDM_Odm->RFCalibrateInfo.PowerIndexOffset[p] = pDM_Odm->RFCalibrateInfo.DeltaPowerIndex[p] - pDM_Odm->RFCalibrateInfo.DeltaPowerIndexLast[p]; /* Power Index Diff between 2 times Power Tracking */ pDM_Odm->RFCalibrateInfo.OFDM_index[p] = pDM_Odm->BbSwingIdxOfdmBase[p] + pDM_Odm->RFCalibrateInfo.PowerIndexOffset[p]; pDM_Odm->RFCalibrateInfo.CCK_index = pDM_Odm->BbSwingIdxCckBase + pDM_Odm->RFCalibrateInfo.PowerIndexOffset[p]; pDM_Odm->BbSwingIdxCck = pDM_Odm->RFCalibrateInfo.CCK_index; pDM_Odm->BbSwingIdxOfdm[p] = pDM_Odm->RFCalibrateInfo.OFDM_index[p]; /* 4 7.1 Handle boundary conditions of index. */ if (pDM_Odm->RFCalibrateInfo.OFDM_index[p] > c.SwingTableSize_OFDM-1) pDM_Odm->RFCalibrateInfo.OFDM_index[p] = c.SwingTableSize_OFDM-1; else if (pDM_Odm->RFCalibrateInfo.OFDM_index[p] < OFDM_min_index) pDM_Odm->RFCalibrateInfo.OFDM_index[p] = OFDM_min_index; } if (pDM_Odm->RFCalibrateInfo.CCK_index > c.SwingTableSize_CCK-1) pDM_Odm->RFCalibrateInfo.CCK_index = c.SwingTableSize_CCK-1; /* else if (pDM_Odm->RFCalibrateInfo.CCK_index < 0) */ /* pDM_Odm->RFCalibrateInfo.CCK_index = 0; */ } else { for (p = RF_PATH_A; p < c.RfPathCount; p++) pDM_Odm->RFCalibrateInfo.PowerIndexOffset[p] = 0; } /* Print Swing base & current */ for (p = RF_PATH_A; p < c.RfPathCount; p++) { } if ( (pDM_Odm->RFCalibrateInfo.PowerIndexOffset[RF_PATH_A] != 0 || pDM_Odm->RFCalibrateInfo.PowerIndexOffset[RF_PATH_B] != 0) && pDM_Odm->RFCalibrateInfo.TxPowerTrackControl ) { /* 4 7.2 Configure the Swing Table to adjust Tx Power. */ pDM_Odm->RFCalibrateInfo.bTxPowerChanged = true; /* Always true after Tx Power is adjusted by power tracking. */ /* */ /* 2012/04/23 MH According to Luke's suggestion, we can not write BB digital */ /* to increase TX power. Otherwise, EVM will be bad. */ /* */ /* 2012/04/25 MH Add for tx power tracking to set tx power in tx agc for 88E. */ if (ThermalValue > pHalData->EEPROMThermalMeter) { for (p = RF_PATH_A; p < c.RfPathCount; p++) (*c.ODM_TxPwrTrackSetPwr)(pDM_Odm, MIX_MODE, p, 0); } else { for (p = RF_PATH_A; p < c.RfPathCount; p++) (*c.ODM_TxPwrTrackSetPwr)(pDM_Odm, MIX_MODE, p, Indexforchannel); } /* Record last time Power Tracking result as base. */ pDM_Odm->BbSwingIdxCckBase = pDM_Odm->BbSwingIdxCck; for (p = RF_PATH_A; p < c.RfPathCount; p++) pDM_Odm->BbSwingIdxOfdmBase[p] = pDM_Odm->BbSwingIdxOfdm[p]; /* Record last Power Tracking Thermal Value */ pDM_Odm->RFCalibrateInfo.ThermalValue = ThermalValue; } pDM_Odm->RFCalibrateInfo.TXPowercount = 0; } |