HalPhyRf_8821A.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404
  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. * 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
  17. *
  18. *
  19. ******************************************************************************/
  20. //#include "Mp_Precomp.h"
  21. #include "../odm_precomp.h"
  22. /*---------------------------Define Local Constant---------------------------*/
  23. // 2010/04/25 MH Define the max tx power tracking tx agc power.
  24. #define ODM_TXPWRTRACK_MAX_IDX8821A 6
  25. /*---------------------------Define Local Constant---------------------------*/
  26. //3 ============================================================
  27. //3 Tx Power Tracking
  28. //3 ============================================================
  29. void setIqkMatrix_8821A(
  30. PDM_ODM_T pDM_Odm,
  31. u1Byte OFDM_index,
  32. u1Byte RFPath,
  33. s4Byte IqkResult_X,
  34. s4Byte IqkResult_Y
  35. )
  36. {
  37. s4Byte ele_A=0, ele_D, ele_C=0, value32;
  38. ele_D = (OFDMSwingTable_New[OFDM_index] & 0xFFC00000)>>22;
  39. //new element A = element D x X
  40. if((IqkResult_X != 0) && (*(pDM_Odm->pBandType) == ODM_BAND_2_4G))
  41. {
  42. if ((IqkResult_X & 0x00000200) != 0) //consider minus
  43. IqkResult_X = IqkResult_X | 0xFFFFFC00;
  44. ele_A = ((IqkResult_X * ele_D)>>8)&0x000003FF;
  45. //new element C = element D x Y
  46. if ((IqkResult_Y & 0x00000200) != 0)
  47. IqkResult_Y = IqkResult_Y | 0xFFFFFC00;
  48. ele_C = ((IqkResult_Y * ele_D)>>8)&0x000003FF;
  49. if (RFPath == ODM_RF_PATH_A)
  50. switch (RFPath)
  51. {
  52. case ODM_RF_PATH_A:
  53. //wirte new elements A, C, D to regC80 and regC94, element B is always 0
  54. value32 = (ele_D<<22)|((ele_C&0x3F)<<16)|ele_A;
  55. ODM_SetBBReg(pDM_Odm, rOFDM0_XATxIQImbalance, bMaskDWord, value32);
  56. value32 = (ele_C&0x000003C0)>>6;
  57. ODM_SetBBReg(pDM_Odm, rOFDM0_XCTxAFE, bMaskH4Bits, value32);
  58. value32 = ((IqkResult_X * ele_D)>>7)&0x01;
  59. ODM_SetBBReg(pDM_Odm, rOFDM0_ECCAThreshold, BIT24, value32);
  60. break;
  61. default:
  62. break;
  63. }
  64. }
  65. else
  66. {
  67. switch (RFPath)
  68. {
  69. case ODM_RF_PATH_A:
  70. ODM_SetBBReg(pDM_Odm, rOFDM0_XATxIQImbalance, bMaskDWord, OFDMSwingTable_New[OFDM_index]);
  71. ODM_SetBBReg(pDM_Odm, rOFDM0_XCTxAFE, bMaskH4Bits, 0x00);
  72. ODM_SetBBReg(pDM_Odm, rOFDM0_ECCAThreshold, BIT24, 0x00);
  73. break;
  74. default:
  75. break;
  76. }
  77. }
  78. ODM_RT_TRACE(pDM_Odm,ODM_COMP_TX_PWR_TRACK, ODM_DBG_LOUD, ("TxPwrTracking path B: X = 0x%x, Y = 0x%x ele_A = 0x%x ele_C = 0x%x ele_D = 0x%x 0xeb4 = 0x%x 0xebc = 0x%x\n",
  79. (u4Byte)IqkResult_X, (u4Byte)IqkResult_Y, (u4Byte)ele_A, (u4Byte)ele_C, (u4Byte)ele_D, (u4Byte)IqkResult_X, (u4Byte)IqkResult_Y));
  80. }
  81. void DoIQK_8821A(
  82. PDM_ODM_T pDM_Odm,
  83. u1Byte DeltaThermalIndex,
  84. u1Byte ThermalValue,
  85. u1Byte Threshold
  86. )
  87. {
  88. #if !(DM_ODM_SUPPORT_TYPE & ODM_AP)
  89. PADAPTER Adapter = pDM_Odm->Adapter;
  90. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  91. #endif
  92. ODM_ResetIQKResult(pDM_Odm);
  93. #if(DM_ODM_SUPPORT_TYPE & ODM_WIN)
  94. #if (DEV_BUS_TYPE == RT_PCI_INTERFACE)
  95. #if USE_WORKITEM
  96. PlatformAcquireMutex(&pHalData->mxChnlBwControl);
  97. #else
  98. PlatformAcquireSpinLock(Adapter, RT_CHANNEL_AND_BANDWIDTH_SPINLOCK);
  99. #endif
  100. #elif((DEV_BUS_TYPE == RT_USB_INTERFACE) || (DEV_BUS_TYPE == RT_SDIO_INTERFACE))
  101. PlatformAcquireMutex(&pHalData->mxChnlBwControl);
  102. #endif
  103. #endif
  104. pDM_Odm->RFCalibrateInfo.ThermalValue_IQK= ThermalValue;
  105. PHY_IQCalibrate_8821A(Adapter, FALSE);
  106. #if(DM_ODM_SUPPORT_TYPE & ODM_WIN)
  107. #if (DEV_BUS_TYPE == RT_PCI_INTERFACE)
  108. #if USE_WORKITEM
  109. PlatformReleaseMutex(&pHalData->mxChnlBwControl);
  110. #else
  111. PlatformReleaseSpinLock(Adapter, RT_CHANNEL_AND_BANDWIDTH_SPINLOCK);
  112. #endif
  113. #elif((DEV_BUS_TYPE == RT_USB_INTERFACE) || (DEV_BUS_TYPE == RT_SDIO_INTERFACE))
  114. PlatformReleaseMutex(&pHalData->mxChnlBwControl);
  115. #endif
  116. #endif
  117. }
  118. VOID
  119. ODM_TxPwrTrackSetPwr8821A(
  120. PDM_ODM_T pDM_Odm,
  121. PWRTRACK_METHOD Method,
  122. u1Byte RFPath,
  123. u1Byte ChannelMappedIndex
  124. )
  125. {
  126. PADAPTER Adapter = pDM_Odm->Adapter;
  127. PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
  128. u1Byte PwrTrackingLimit = 26; //+1.0dB
  129. u1Byte TxRate = 0xFF;
  130. s1Byte Final_OFDM_Swing_Index = 0;
  131. s1Byte Final_CCK_Swing_Index = 0;
  132. u1Byte i = 0;
  133. u4Byte finalBbSwingIdx[1];
  134. #if 0 //gtemp
  135. #if (MP_DRIVER==1)
  136. //PMPT_CONTEXT pMptCtx = &(Adapter->MptCtx);
  137. PMPT_CONTEXT pMptCtx = &Adapter->mppriv.MptCtx;
  138. TxRate = MptToMgntRate(pMptCtx->MptRateIndex);
  139. #else
  140. PMGNT_INFO pMgntInfo = &(Adapter->MgntInfo);
  141. if(!pMgntInfo->ForcedDataRate) //auto rate
  142. {
  143. if(pDM_Odm->TxRate != 0xFF)
  144. TxRate = HwRateToMRate8812(pDM_Odm->TxRate);
  145. }
  146. else //force rate
  147. {
  148. TxRate = (u1Byte) pMgntInfo->ForcedDataRate;
  149. }
  150. #endif
  151. #endif
  152. ODM_RT_TRACE(pDM_Odm,ODM_COMP_TX_PWR_TRACK, ODM_DBG_LOUD,("===>ODM_TxPwrTrackSetPwr8821A\n"));
  153. if(TxRate != 0xFF)
  154. {
  155. //2 CCK
  156. if((TxRate >= MGN_1M)&&(TxRate <= MGN_11M))
  157. PwrTrackingLimit = 32; //+4dB
  158. //2 OFDM
  159. else if((TxRate >= MGN_6M)&&(TxRate <= MGN_48M))
  160. PwrTrackingLimit = 32; //+4dB
  161. else if(TxRate == MGN_54M)
  162. PwrTrackingLimit = 30; //+3dB
  163. //2 HT
  164. else if((TxRate >= MGN_MCS0)&&(TxRate <= MGN_MCS2)) //QPSK/BPSK
  165. PwrTrackingLimit = 34; //+5dB
  166. else if((TxRate >= MGN_MCS3)&&(TxRate <= MGN_MCS4)) //16QAM
  167. PwrTrackingLimit = 32; //+4dB
  168. else if((TxRate >= MGN_MCS5)&&(TxRate <= MGN_MCS7)) //64QAM
  169. PwrTrackingLimit = 30; //+3dB
  170. //2 VHT
  171. else if((TxRate >= MGN_VHT1SS_MCS0)&&(TxRate <= MGN_VHT1SS_MCS2)) //QPSK/BPSK
  172. PwrTrackingLimit = 34; //+5dB
  173. else if((TxRate >= MGN_VHT1SS_MCS3)&&(TxRate <= MGN_VHT1SS_MCS4)) //16QAM
  174. PwrTrackingLimit = 32; //+4dB
  175. else if((TxRate >= MGN_VHT1SS_MCS5)&&(TxRate <= MGN_VHT1SS_MCS6)) //64QAM
  176. PwrTrackingLimit = 30; //+3dB
  177. else if(TxRate == MGN_VHT1SS_MCS7) //64QAM
  178. PwrTrackingLimit = 28; //+2dB
  179. else if(TxRate == MGN_VHT1SS_MCS8) //256QAM
  180. PwrTrackingLimit = 26; //+1dB
  181. else if(TxRate == MGN_VHT1SS_MCS9) //256QAM
  182. PwrTrackingLimit = 24; //+0dB
  183. else
  184. PwrTrackingLimit = 24;
  185. }
  186. ODM_RT_TRACE(pDM_Odm,ODM_COMP_TX_PWR_TRACK, ODM_DBG_LOUD,("TxRate=0x%x, PwrTrackingLimit=%d\n", TxRate, PwrTrackingLimit));
  187. if (Method == BBSWING)
  188. {
  189. if (RFPath == ODM_RF_PATH_A)
  190. {
  191. finalBbSwingIdx[ODM_RF_PATH_A] = (pDM_Odm->RFCalibrateInfo.OFDM_index[ODM_RF_PATH_A] > PwrTrackingLimit) ? PwrTrackingLimit : pDM_Odm->RFCalibrateInfo.OFDM_index[ODM_RF_PATH_A];
  192. ODM_RT_TRACE(pDM_Odm,ODM_COMP_TX_PWR_TRACK, ODM_DBG_LOUD,("pDM_Odm->RFCalibrateInfo.OFDM_index[ODM_RF_PATH_A]=%d, pDM_Odm->RealBbSwingIdx[ODM_RF_PATH_A]=%d\n",
  193. pDM_Odm->RFCalibrateInfo.OFDM_index[ODM_RF_PATH_A], finalBbSwingIdx[ODM_RF_PATH_A]));
  194. ODM_SetBBReg(pDM_Odm, rA_TxScale_Jaguar, 0xFFE00000, TxScalingTable_Jaguar[finalBbSwingIdx[ODM_RF_PATH_A]]);
  195. }
  196. }
  197. else if (Method == MIX_MODE)
  198. {
  199. ODM_RT_TRACE(pDM_Odm,ODM_COMP_TX_PWR_TRACK, ODM_DBG_LOUD,("pDM_Odm->DefaultOfdmIndex=%d, pDM_Odm->Aboslute_OFDMSwingIdx[RFPath]=%d, RF_Path = %d\n",
  200. pDM_Odm->DefaultOfdmIndex, pDM_Odm->Aboslute_OFDMSwingIdx[RFPath],RFPath ));
  201. Final_OFDM_Swing_Index = pDM_Odm->DefaultOfdmIndex + pDM_Odm->Aboslute_OFDMSwingIdx[RFPath];
  202. if (RFPath == ODM_RF_PATH_A)
  203. {
  204. if(Final_OFDM_Swing_Index > PwrTrackingLimit) //BBSwing higher then Limit
  205. {
  206. pDM_Odm->Remnant_CCKSwingIdx= Final_OFDM_Swing_Index - PwrTrackingLimit; // CCK Follow the same compensate value as Path A
  207. pDM_Odm->Remnant_OFDMSwingIdx[RFPath] = Final_OFDM_Swing_Index - PwrTrackingLimit;
  208. ODM_SetBBReg(pDM_Odm, rA_TxScale_Jaguar, 0xFFE00000, TxScalingTable_Jaguar[PwrTrackingLimit]);
  209. pDM_Odm->Modify_TxAGC_Flag_PathA= TRUE;
  210. //Set TxAGC Page C{};
  211. //Adapter->HalFunc.SetTxPowerLevelHandler(Adapter, pHalData->CurrentChannel);
  212. PHY_SetTxPowerLevel8812(Adapter, pHalData->CurrentChannel);
  213. ODM_RT_TRACE(pDM_Odm,ODM_COMP_TX_PWR_TRACK, ODM_DBG_LOUD,("******Path_A Over BBSwing Limit , PwrTrackingLimit = %d , Remnant TxAGC Value = %d \n", PwrTrackingLimit, pDM_Odm->Remnant_OFDMSwingIdx[RFPath]));
  214. }
  215. else if (Final_OFDM_Swing_Index < 0)
  216. {
  217. pDM_Odm->Remnant_CCKSwingIdx= Final_OFDM_Swing_Index; // CCK Follow the same compensate value as Path A
  218. pDM_Odm->Remnant_OFDMSwingIdx[RFPath] = Final_OFDM_Swing_Index;
  219. ODM_SetBBReg(pDM_Odm, rA_TxScale_Jaguar, 0xFFE00000, TxScalingTable_Jaguar[0]);
  220. pDM_Odm->Modify_TxAGC_Flag_PathA= TRUE;
  221. //Set TxAGC Page C{};
  222. //Adapter->HalFunc.SetTxPowerLevelHandler(Adapter, pHalData->CurrentChannel);
  223. PHY_SetTxPowerLevel8812(Adapter, pHalData->CurrentChannel);
  224. ODM_RT_TRACE(pDM_Odm,ODM_COMP_TX_PWR_TRACK, ODM_DBG_LOUD,("******Path_A Lower then BBSwing lower bound 0 , Remnant TxAGC Value = %d \n", pDM_Odm->Remnant_OFDMSwingIdx[RFPath]));
  225. }
  226. else
  227. {
  228. ODM_SetBBReg(pDM_Odm, rA_TxScale_Jaguar, 0xFFE00000, TxScalingTable_Jaguar[Final_OFDM_Swing_Index]);
  229. ODM_RT_TRACE(pDM_Odm,ODM_COMP_TX_PWR_TRACK, ODM_DBG_LOUD,("******Path_A Compensate with BBSwing , Final_OFDM_Swing_Index = %d \n", Final_OFDM_Swing_Index));
  230. if(pDM_Odm->Modify_TxAGC_Flag_PathA) //If TxAGC has changed, reset TxAGC again
  231. {
  232. pDM_Odm->Remnant_CCKSwingIdx= 0;
  233. pDM_Odm->Remnant_OFDMSwingIdx[RFPath] = 0;
  234. //Set TxAGC Page C{};
  235. //Adapter->HalFunc.SetTxPowerLevelHandler(Adapter, pHalData->CurrentChannel);
  236. PHY_SetTxPowerLevel8812(Adapter, pHalData->CurrentChannel);
  237. pDM_Odm->Modify_TxAGC_Flag_PathA= FALSE;
  238. ODM_RT_TRACE(pDM_Odm,ODM_COMP_TX_PWR_TRACK, ODM_DBG_LOUD,("******Path_A pDM_Odm->Modify_TxAGC_Flag = FALSE \n"));
  239. }
  240. }
  241. }
  242. }
  243. else
  244. {
  245. return;
  246. }
  247. } // odm_TxPwrTrackSetPwr88E
  248. VOID
  249. GetDeltaSwingTable_8821A(
  250. IN PDM_ODM_T pDM_Odm,
  251. OUT pu1Byte *TemperatureUP_A,
  252. OUT pu1Byte *TemperatureDOWN_A,
  253. OUT pu1Byte *TemperatureUP_B,
  254. OUT pu1Byte *TemperatureDOWN_B
  255. )
  256. {
  257. PADAPTER Adapter = pDM_Odm->Adapter;
  258. PODM_RF_CAL_T pRFCalibrateInfo = &(pDM_Odm->RFCalibrateInfo);
  259. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  260. //u2Byte rate = pMgntInfo->ForcedDataRate;
  261. u2Byte rate = 0;
  262. u1Byte channel = pHalData->CurrentChannel;
  263. if ( 1 <= channel && channel <= 14) {
  264. if (IS_CCK_RATE(rate)) {
  265. *TemperatureUP_A = pRFCalibrateInfo->DeltaSwingTableIdx_2GCCKA_P;
  266. *TemperatureDOWN_A = pRFCalibrateInfo->DeltaSwingTableIdx_2GCCKA_N;
  267. *TemperatureUP_B = pRFCalibrateInfo->DeltaSwingTableIdx_2GCCKB_P;
  268. *TemperatureDOWN_B = pRFCalibrateInfo->DeltaSwingTableIdx_2GCCKB_N;
  269. } else {
  270. *TemperatureUP_A = pRFCalibrateInfo->DeltaSwingTableIdx_2GA_P;
  271. *TemperatureDOWN_A = pRFCalibrateInfo->DeltaSwingTableIdx_2GA_N;
  272. *TemperatureUP_B = pRFCalibrateInfo->DeltaSwingTableIdx_2GB_P;
  273. *TemperatureDOWN_B = pRFCalibrateInfo->DeltaSwingTableIdx_2GB_N;
  274. }
  275. } else if ( 36 <= channel && channel <= 64) {
  276. *TemperatureUP_A = pRFCalibrateInfo->DeltaSwingTableIdx_5GA_P[0];
  277. *TemperatureDOWN_A = pRFCalibrateInfo->DeltaSwingTableIdx_5GA_N[0];
  278. *TemperatureUP_B = pRFCalibrateInfo->DeltaSwingTableIdx_5GB_P[0];
  279. *TemperatureDOWN_B = pRFCalibrateInfo->DeltaSwingTableIdx_5GB_N[0];
  280. } else if ( 100 <= channel && channel <= 140) {
  281. *TemperatureUP_A = pRFCalibrateInfo->DeltaSwingTableIdx_5GA_P[1];
  282. *TemperatureDOWN_A = pRFCalibrateInfo->DeltaSwingTableIdx_5GA_N[1];
  283. *TemperatureUP_B = pRFCalibrateInfo->DeltaSwingTableIdx_5GB_P[1];
  284. *TemperatureDOWN_B = pRFCalibrateInfo->DeltaSwingTableIdx_5GB_N[1];
  285. } else if ( 149 <= channel && channel <= 173) {
  286. *TemperatureUP_A = pRFCalibrateInfo->DeltaSwingTableIdx_5GA_P[2];
  287. *TemperatureDOWN_A = pRFCalibrateInfo->DeltaSwingTableIdx_5GA_N[2];
  288. *TemperatureUP_B = pRFCalibrateInfo->DeltaSwingTableIdx_5GB_P[2];
  289. *TemperatureDOWN_B = pRFCalibrateInfo->DeltaSwingTableIdx_5GB_N[2];
  290. } else {
  291. *TemperatureUP_A = (pu1Byte)DeltaSwingTableIdx_2GA_P_8188E;
  292. *TemperatureDOWN_A = (pu1Byte)DeltaSwingTableIdx_2GA_N_8188E;
  293. *TemperatureUP_B = (pu1Byte)DeltaSwingTableIdx_2GA_P_8188E;
  294. *TemperatureDOWN_B = (pu1Byte)DeltaSwingTableIdx_2GA_N_8188E;
  295. }
  296. return;
  297. }
  298. void ConfigureTxpowerTrack_8821A(
  299. PTXPWRTRACK_CFG pConfig
  300. )
  301. {
  302. pConfig->SwingTableSize_CCK = TXSCALE_TABLE_SIZE;
  303. pConfig->SwingTableSize_OFDM = TXSCALE_TABLE_SIZE;
  304. pConfig->Threshold_IQK = IQK_THRESHOLD;
  305. pConfig->AverageThermalNum = AVG_THERMAL_NUM_8812A;
  306. pConfig->RfPathCount = MAX_PATH_NUM_8821A;
  307. pConfig->ThermalRegAddr = RF_T_METER_8812A;
  308. pConfig->ODM_TxPwrTrackSetPwr = ODM_TxPwrTrackSetPwr8821A;
  309. pConfig->DoIQK = DoIQK_8821A;
  310. pConfig->PHY_LCCalibrate = PHY_LCCalibrate_8821A;
  311. pConfig->GetDeltaSwingTable = GetDeltaSwingTable_8821A;
  312. }
  313. //1 7. IQK
  314. #define MAX_TOLERANCE 5
  315. #define IQK_DELAY_TIME 1 //ms
  316. void _IQK_RX_FillIQC_8821A(
  317. IN PDM_ODM_T pDM_Odm,
  318. IN ODM_RF_RADIO_PATH_E Path,
  319. IN unsigned int RX_X,
  320. IN unsigned int RX_Y
  321. )
  322. {
  323. switch (Path) {
  324. case ODM_RF_PATH_A:
  325. {
  326. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  327. ODM_SetBBReg(pDM_Odm, 0xc10, 0x000003ff, RX_X>>1);
  328. ODM_SetBBReg(pDM_Odm, 0xc10, 0x03ff0000, RX_Y>>1);
  329. ODM_RT_TRACE(pDM_Odm,ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("RX_X = %x;;RX_Y = %x ====>fill to IQC\n", RX_X>>1, RX_Y>>1));
  330. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("0xc10 = %x ====>fill to IQC\n", ODM_Read4Byte(pDM_Odm, 0xc10)));
  331. }
  332. break;
  333. default:
  334. break;
  335. };
  336. }
  337. void _IQK_TX_FillIQC_8821A(
  338. IN PDM_ODM_T pDM_Odm,
  339. IN ODM_RF_RADIO_PATH_E Path,
  340. IN unsigned int TX_X,
  341. IN unsigned int TX_Y
  342. )
  343. {
  344. switch (Path) {
  345. case ODM_RF_PATH_A:
  346. {
  347. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x1); // [31] = 1 --> Page C1
  348. ODM_Write4Byte(pDM_Odm, 0xc90, 0x00000080);
  349. ODM_Write4Byte(pDM_Odm, 0xcc4, 0x20040000);
  350. ODM_Write4Byte(pDM_Odm, 0xcc8, 0x20000000);
  351. ODM_SetBBReg(pDM_Odm, 0xccc, 0x000007ff, TX_Y);
  352. ODM_SetBBReg(pDM_Odm, 0xcd4, 0x000007ff, TX_X);
  353. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("TX_X = %x;;TX_Y = %x =====> fill to IQC\n", TX_X, TX_Y));
  354. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("0xcd4 = %x;;0xccc = %x ====>fill to IQC\n", ODM_GetBBReg(pDM_Odm, 0xcd4, 0x000007ff), ODM_GetBBReg(pDM_Odm, 0xccc, 0x000007ff)));
  355. }
  356. break;
  357. default:
  358. break;
  359. };
  360. }
  361. void _IQK_BackupMacBB_8821A(
  362. IN PDM_ODM_T pDM_Odm,
  363. IN pu4Byte MACBB_backup,
  364. IN pu4Byte Backup_MACBB_REG,
  365. IN u4Byte MACBB_NUM
  366. )
  367. {
  368. u4Byte i;
  369. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  370. //save MACBB default value
  371. for (i = 0; i < MACBB_NUM; i++){
  372. MACBB_backup[i] = ODM_Read4Byte(pDM_Odm, Backup_MACBB_REG[i]);
  373. }
  374. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("BackupMacBB Success!!!!\n"));
  375. }
  376. void _IQK_BackupRF_8821A(
  377. IN PDM_ODM_T pDM_Odm,
  378. IN pu4Byte RFA_backup,
  379. IN pu4Byte RFB_backup,
  380. IN pu4Byte Backup_RF_REG,
  381. IN u4Byte RF_NUM
  382. )
  383. {
  384. u4Byte i;
  385. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  386. //Save RF Parameters
  387. for (i = 0; i < RF_NUM; i++){
  388. RFA_backup[i] = ODM_GetRFReg(pDM_Odm, ODM_RF_PATH_A, Backup_RF_REG[i], bMaskDWord);
  389. }
  390. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("BackupRF Success!!!!\n"));
  391. }
  392. void _IQK_BackupAFE_8821A(
  393. IN PDM_ODM_T pDM_Odm,
  394. IN pu4Byte AFE_backup,
  395. IN pu4Byte Backup_AFE_REG,
  396. IN u4Byte AFE_NUM
  397. )
  398. {
  399. u4Byte i;
  400. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  401. //Save AFE Parameters
  402. for (i = 0; i < AFE_NUM; i++){
  403. AFE_backup[i] = ODM_Read4Byte(pDM_Odm, Backup_AFE_REG[i]);
  404. }
  405. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("BackupAFE Success!!!!\n"));
  406. }
  407. void _IQK_RestoreMacBB_8821A(
  408. IN PDM_ODM_T pDM_Odm,
  409. IN pu4Byte MACBB_backup,
  410. IN pu4Byte Backup_MACBB_REG,
  411. IN u4Byte MACBB_NUM
  412. )
  413. {
  414. u4Byte i;
  415. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  416. //Reload MacBB Parameters
  417. for (i = 0; i < MACBB_NUM; i++){
  418. ODM_Write4Byte(pDM_Odm, Backup_MACBB_REG[i], MACBB_backup[i]);
  419. }
  420. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("RestoreMacBB Success!!!!\n"));
  421. }
  422. void _IQK_RestoreRF_8821A(
  423. IN PDM_ODM_T pDM_Odm,
  424. IN ODM_RF_RADIO_PATH_E Path,
  425. IN pu4Byte Backup_RF_REG,
  426. IN pu4Byte RF_backup,
  427. IN u4Byte RF_REG_NUM
  428. )
  429. {
  430. u4Byte i;
  431. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  432. for (i = 0; i < RF_REG_NUM; i++)
  433. ODM_SetRFReg(pDM_Odm, Path, Backup_RF_REG[i], bRFRegOffsetMask, RF_backup[i]);
  434. switch(Path){
  435. case ODM_RF_PATH_A:
  436. {
  437. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("RestoreRF Path A Success!!!!\n"));
  438. }
  439. break;
  440. default:
  441. break;
  442. }
  443. }
  444. void _IQK_RestoreAFE_8821A(
  445. IN PDM_ODM_T pDM_Odm,
  446. IN pu4Byte AFE_backup,
  447. IN pu4Byte Backup_AFE_REG,
  448. IN u4Byte AFE_NUM
  449. )
  450. {
  451. u4Byte i;
  452. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  453. //Reload AFE Parameters
  454. for (i = 0; i < AFE_NUM; i++){
  455. ODM_Write4Byte(pDM_Odm, Backup_AFE_REG[i], AFE_backup[i]);
  456. }
  457. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x1); // [31] = 1 --> Page C1
  458. ODM_Write4Byte(pDM_Odm, 0xc80, 0x0);
  459. ODM_Write4Byte(pDM_Odm, 0xc84, 0x0);
  460. ODM_Write4Byte(pDM_Odm, 0xc88, 0x0);
  461. ODM_Write4Byte(pDM_Odm, 0xc8c, 0x3c000000);
  462. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x0);
  463. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("RestoreAFE Success!!!!\n"));
  464. }
  465. void _IQK_ConfigureMAC_8821A(
  466. IN PDM_ODM_T pDM_Odm
  467. )
  468. {
  469. // ========MAC register setting========
  470. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  471. ODM_Write1Byte(pDM_Odm, 0x522, 0x3f);
  472. ODM_SetBBReg(pDM_Odm, 0x550, BIT(3), 0x0);
  473. ODM_SetBBReg(pDM_Odm, 0x551, BIT(3), 0x0);
  474. ODM_SetBBReg(pDM_Odm, 0x808, BIT(28), 0x0); // CCK Off
  475. ODM_Write1Byte(pDM_Odm, 0x808, 0x00); // RX ante off
  476. ODM_SetBBReg(pDM_Odm, 0x838, 0xf, 0xc); // CCA off
  477. }
  478. #define cal_num 3
  479. void _IQK_Tx_8821A(
  480. IN PDM_ODM_T pDM_Odm,
  481. IN ODM_RF_RADIO_PATH_E Path
  482. )
  483. {
  484. u4Byte TX_fail, RX_fail, delay_count, IQK_ready, cal_retry, cal = 0, temp_reg65;
  485. int TX_X = 0, TX_Y = 0, RX_X = 0, RX_Y = 0, TX_Average = 0, RX_Average = 0;
  486. int TX_X0[cal_num], TX_Y0[cal_num], TX_X0_RXK[cal_num], TX_Y0_RXK[cal_num], RX_X0[cal_num], RX_Y0[cal_num];
  487. BOOLEAN TX0IQKOK = FALSE, RX0IQKOK = FALSE;
  488. BOOLEAN VDF_enable = FALSE;
  489. int i, k, VDF_Y[3], VDF_X[3], Tx_dt[3], Rx_dt[3], ii, dx = 0, dy = 0, TX_finish = 0, RX_finish = 0;
  490. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("BandWidth = %d\n", *pDM_Odm->pBandWidth));
  491. if (*pDM_Odm->pBandWidth == 2){
  492. VDF_enable = TRUE;
  493. }
  494. while (cal < cal_num){
  495. switch (Path) {
  496. case ODM_RF_PATH_A:
  497. {
  498. temp_reg65 = ODM_GetRFReg(pDM_Odm, Path, 0x65, bMaskDWord);
  499. if (pDM_Odm->ExtPA){
  500. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  501. ODM_SetRFReg(pDM_Odm, Path, 0x65, bRFRegOffsetMask, 0x931d5);
  502. }
  503. //Path-A LOK
  504. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  505. // ========Path-A AFE all on========
  506. // Port 0 DAC/ADC on
  507. ODM_Write4Byte(pDM_Odm, 0xc60, 0x77777777);
  508. ODM_Write4Byte(pDM_Odm, 0xc64, 0x77777777);
  509. ODM_Write4Byte(pDM_Odm, 0xc68, 0x19791979);
  510. ODM_Write4Byte(pDM_Odm, 0xc6c, 0x19791979);
  511. ODM_Write4Byte(pDM_Odm, 0xc70, 0x19791979);
  512. ODM_Write4Byte(pDM_Odm, 0xc74, 0x19791979);
  513. ODM_Write4Byte(pDM_Odm, 0xc78, 0x19791979);
  514. ODM_Write4Byte(pDM_Odm, 0xc7c, 0x19791979);
  515. ODM_Write4Byte(pDM_Odm, 0xc80, 0x19791979);
  516. ODM_Write4Byte(pDM_Odm, 0xc84, 0x19791979);
  517. ODM_SetBBReg(pDM_Odm, 0xc00, 0xf, 0x4);// hardware 3-wire off
  518. // LOK Setting
  519. //====== LOK ======
  520. // 1. DAC/ADC sampling rate (160 MHz)
  521. ODM_SetBBReg(pDM_Odm, 0xc5c, BIT(26)|BIT(25)|BIT(24), 0x7);
  522. // 2. LoK RF Setting (at BW = 20M)
  523. ODM_SetRFReg(pDM_Odm, Path, 0xef, bRFRegOffsetMask, 0x80002);
  524. ODM_SetRFReg(pDM_Odm, Path, 0x18, 0x00c00, 0x3); // BW 20M
  525. ODM_SetRFReg(pDM_Odm, Path, 0x30, bRFRegOffsetMask, 0x20000);
  526. ODM_SetRFReg(pDM_Odm, Path, 0x31, bRFRegOffsetMask, 0x0003f);
  527. ODM_SetRFReg(pDM_Odm, Path, 0x32, bRFRegOffsetMask, 0xf3fc3);
  528. ODM_SetRFReg(pDM_Odm, Path, 0x65, bRFRegOffsetMask, 0x931d5);
  529. ODM_SetRFReg(pDM_Odm, Path, 0x8f, bRFRegOffsetMask, 0x8a001);
  530. ODM_SetBBReg(pDM_Odm, 0xcb8, 0xf, 0xd);
  531. ODM_Write4Byte(pDM_Odm, 0x90c, 0x00008000);
  532. ODM_Write4Byte(pDM_Odm, 0xb00, 0x03000100);
  533. ODM_SetBBReg(pDM_Odm, 0xc94, BIT(0), 0x1);
  534. ODM_Write4Byte(pDM_Odm, 0x978, 0x29002000);// TX (X,Y)
  535. ODM_Write4Byte(pDM_Odm, 0x97c, 0xa9002000);// RX (X,Y)
  536. ODM_Write4Byte(pDM_Odm, 0x984, 0x00462910);// [0]:AGC_en, [15]:idac_K_Mask
  537. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x1); // [31] = 1 --> Page C1
  538. if (pDM_Odm->ExtPA)
  539. ODM_Write4Byte(pDM_Odm, 0xc88, 0x821403f7);
  540. else
  541. ODM_Write4Byte(pDM_Odm, 0xc88, 0x821403f4);
  542. if (*pDM_Odm->pBandType)
  543. ODM_Write4Byte(pDM_Odm, 0xc8c, 0x68163e96);
  544. else
  545. ODM_Write4Byte(pDM_Odm, 0xc8c, 0x28163e96);
  546. ODM_Write4Byte(pDM_Odm, 0xc80, 0x18008c10);// TX_Tone_idx[9:0], TxK_Mask[29] TX_Tone = 16
  547. ODM_Write4Byte(pDM_Odm, 0xc84, 0x38008c10);// RX_Tone_idx[9:0], RxK_Mask[29]
  548. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x00100000);// cb8[20] 將 SI/PI 使用權切給 iqk_dpk module
  549. ODM_Write4Byte(pDM_Odm, 0x980, 0xfa000000);
  550. ODM_Write4Byte(pDM_Odm, 0x980, 0xf8000000);
  551. ODM_delay_ms(10); //Delay 10ms
  552. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x00000000);
  553. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  554. ODM_SetRFReg(pDM_Odm, Path, 0x58, 0x7fe00, ODM_GetRFReg(pDM_Odm, Path, 0x8, 0xffc00)); // Load LOK
  555. switch (*pDM_Odm->pBandWidth)
  556. {
  557. case 1:
  558. {
  559. ODM_SetRFReg(pDM_Odm, Path, 0x18, 0x00c00, 0x1);
  560. }
  561. break;
  562. case 2:
  563. {
  564. ODM_SetRFReg(pDM_Odm, Path, 0x18, 0x00c00, 0x0);
  565. }
  566. break;
  567. default:
  568. break;
  569. }
  570. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x1); // [31] = 1 --> Page C1
  571. // 3. TX RF Setting
  572. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  573. ODM_SetRFReg(pDM_Odm, Path, 0xef, bRFRegOffsetMask, 0x80000);
  574. ODM_SetRFReg(pDM_Odm, Path, 0x30, bRFRegOffsetMask, 0x20000);
  575. ODM_SetRFReg(pDM_Odm, Path, 0x31, bRFRegOffsetMask, 0x0003f);
  576. ODM_SetRFReg(pDM_Odm, Path, 0x32, bRFRegOffsetMask, 0xf3fc3);
  577. ODM_SetRFReg(pDM_Odm, Path, 0x65, bRFRegOffsetMask, 0x931d5);
  578. ODM_SetRFReg(pDM_Odm, Path, 0x8f, bRFRegOffsetMask, 0x8a001);
  579. ODM_SetRFReg(pDM_Odm, Path, 0xef, bRFRegOffsetMask, 0x00000);
  580. ODM_SetBBReg(pDM_Odm, 0xcb8, 0xf, 0xd);
  581. ODM_Write4Byte(pDM_Odm, 0x90c, 0x00008000);
  582. ODM_Write4Byte(pDM_Odm, 0xb00, 0x03000100);
  583. ODM_SetBBReg(pDM_Odm, 0xc94, BIT(0), 0x1);
  584. ODM_Write4Byte(pDM_Odm, 0x978, 0x29002000);// TX (X,Y)
  585. ODM_Write4Byte(pDM_Odm, 0x97c, 0xa9002000);// RX (X,Y)
  586. ODM_Write4Byte(pDM_Odm, 0x984, 0x0046a910);// [0]:AGC_en, [15]:idac_K_Mask
  587. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x1); // [31] = 1 --> Page C1
  588. if (pDM_Odm->ExtPA)
  589. ODM_Write4Byte(pDM_Odm, 0xc88, 0x821403f7);
  590. else
  591. ODM_Write4Byte(pDM_Odm, 0xc88, 0x821403f1);
  592. if (*pDM_Odm->pBandType)
  593. ODM_Write4Byte(pDM_Odm, 0xc8c, 0x40163e96);
  594. else
  595. ODM_Write4Byte(pDM_Odm, 0xc8c, 0x00163e96);
  596. if (VDF_enable == 1){
  597. DbgPrint("VDF_enable\n");
  598. for (k = 0;k <= 2; k++){
  599. switch (k){
  600. case 0:
  601. {
  602. ODM_Write4Byte(pDM_Odm, 0xc80, 0x18008c38);// TX_Tone_idx[9:0], TxK_Mask[29] TX_Tone = 16
  603. ODM_Write4Byte(pDM_Odm, 0xc84, 0x38008c38);// RX_Tone_idx[9:0], RxK_Mask[29]
  604. ODM_SetBBReg(pDM_Odm, 0xce8, BIT(31), 0x0);
  605. }
  606. break;
  607. case 1:
  608. {
  609. ODM_SetBBReg(pDM_Odm, 0xc80, BIT(28), 0x0);
  610. ODM_SetBBReg(pDM_Odm, 0xc84, BIT(28), 0x0);
  611. ODM_SetBBReg(pDM_Odm, 0xce8, BIT(31), 0x0);
  612. }
  613. break;
  614. case 2:
  615. {
  616. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("VDF_Y[1] = %x;;;VDF_Y[0] = %x\n", VDF_Y[1]>>21 & 0x00007ff, VDF_Y[0]>>21 & 0x00007ff));
  617. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("VDF_X[1] = %x;;;VDF_X[0] = %x\n", VDF_X[1]>>21 & 0x00007ff, VDF_X[0]>>21 & 0x00007ff));
  618. Tx_dt[cal] = (VDF_Y[1]>>20)-(VDF_Y[0]>>20);
  619. Tx_dt[cal] = ((16*Tx_dt[cal])*10000/15708);
  620. Tx_dt[cal] = (Tx_dt[cal] >> 1 )+(Tx_dt[cal] & BIT(0));
  621. ODM_Write4Byte(pDM_Odm, 0xc80, 0x18008c20);// TX_Tone_idx[9:0], TxK_Mask[29] TX_Tone = 16
  622. ODM_Write4Byte(pDM_Odm, 0xc84, 0x38008c20);// RX_Tone_idx[9:0], RxK_Mask[29]
  623. ODM_SetBBReg(pDM_Odm, 0xce8, BIT(31), 0x1);
  624. ODM_SetBBReg(pDM_Odm, 0xce8, 0x3fff0000, Tx_dt[cal] & 0x00003fff);
  625. }
  626. break;
  627. default:
  628. break;
  629. }
  630. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x00100000);// cb8[20] 將 SI/PI 使用權切給 iqk_dpk module
  631. cal_retry = 0;
  632. while(1){
  633. // one shot
  634. ODM_Write4Byte(pDM_Odm, 0x980, 0xfa000000);
  635. ODM_Write4Byte(pDM_Odm, 0x980, 0xf8000000);
  636. ODM_delay_ms(10); //Delay 10ms
  637. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x00000000);
  638. delay_count = 0;
  639. while (1){
  640. IQK_ready = ODM_GetBBReg(pDM_Odm, 0xd00, BIT(10));
  641. if ((~IQK_ready) || (delay_count>20)){
  642. break;
  643. }
  644. else{
  645. ODM_delay_ms(1);
  646. delay_count++;
  647. }
  648. }
  649. if (delay_count < 20){ // If 20ms No Result, then cal_retry++
  650. // ============TXIQK Check==============
  651. TX_fail = ODM_GetBBReg(pDM_Odm, 0xd00, BIT(12));
  652. if (~TX_fail){
  653. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x02000000);
  654. VDF_X[k] = ODM_GetBBReg(pDM_Odm, 0xd00, 0x07ff0000)<<21;
  655. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x04000000);
  656. VDF_Y[k] = ODM_GetBBReg(pDM_Odm, 0xd00, 0x07ff0000)<<21;
  657. TX0IQKOK = TRUE;
  658. break;
  659. }
  660. else{
  661. ODM_SetBBReg(pDM_Odm, 0xccc, 0x000007ff, 0x0);
  662. ODM_SetBBReg(pDM_Odm, 0xcd4, 0x000007ff, 0x200);
  663. TX0IQKOK = FALSE;
  664. cal_retry++;
  665. if (cal_retry == 10) {
  666. break;
  667. }
  668. }
  669. }
  670. else{
  671. TX0IQKOK = FALSE;
  672. cal_retry++;
  673. if (cal_retry == 10){
  674. break;
  675. }
  676. }
  677. }
  678. }
  679. if (k == 3){
  680. TX_X0[cal] = VDF_X[k-1] ;
  681. TX_Y0[cal] = VDF_Y[k-1];
  682. }
  683. }
  684. else{
  685. ODM_Write4Byte(pDM_Odm, 0xc80, 0x18008c10);// TX_Tone_idx[9:0], TxK_Mask[29] TX_Tone = 16
  686. ODM_Write4Byte(pDM_Odm, 0xc84, 0x38008c10);// RX_Tone_idx[9:0], RxK_Mask[29]
  687. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x00100000);// cb8[20] 將 SI/PI 使用權切給 iqk_dpk module
  688. cal_retry = 0;
  689. while(1){
  690. // one shot
  691. ODM_Write4Byte(pDM_Odm, 0x980, 0xfa000000);
  692. ODM_Write4Byte(pDM_Odm, 0x980, 0xf8000000);
  693. ODM_delay_ms(10); //Delay 10ms
  694. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x00000000);
  695. delay_count = 0;
  696. while (1){
  697. IQK_ready = ODM_GetBBReg(pDM_Odm, 0xd00, BIT(10));
  698. if ((~IQK_ready) || (delay_count>20)) {
  699. break;
  700. }
  701. else{
  702. ODM_delay_ms(1);
  703. delay_count++;
  704. }
  705. }
  706. if (delay_count < 20){ // If 20ms No Result, then cal_retry++
  707. // ============TXIQK Check==============
  708. TX_fail = ODM_GetBBReg(pDM_Odm, 0xd00, BIT(12));
  709. if (~TX_fail){
  710. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x02000000);
  711. TX_X0[cal] = ODM_GetBBReg(pDM_Odm, 0xd00, 0x07ff0000)<<21;
  712. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x04000000);
  713. TX_Y0[cal] = ODM_GetBBReg(pDM_Odm, 0xd00, 0x07ff0000)<<21;
  714. TX0IQKOK = TRUE;
  715. break;
  716. }
  717. else{
  718. ODM_SetBBReg(pDM_Odm, 0xccc, 0x000007ff, 0x0);
  719. ODM_SetBBReg(pDM_Odm, 0xcd4, 0x000007ff, 0x200);
  720. TX0IQKOK = FALSE;
  721. cal_retry++;
  722. if (cal_retry == 10) {
  723. break;
  724. }
  725. }
  726. }
  727. else{
  728. TX0IQKOK = FALSE;
  729. cal_retry++;
  730. if (cal_retry == 10)
  731. break;
  732. }
  733. }
  734. }
  735. if (TX0IQKOK == FALSE)
  736. break; // TXK fail, Don't do RXK
  737. if (VDF_enable == 1){
  738. ODM_SetBBReg(pDM_Odm, 0xce8, BIT(31), 0x0); // TX VDF Disable
  739. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("RXVDF Start\n"));
  740. for (k = 0;k <= 2; k++){
  741. //====== RX mode TXK (RXK Step 1) ======
  742. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  743. // 1. TX RF Setting
  744. ODM_SetRFReg(pDM_Odm, Path, 0xef, bRFRegOffsetMask, 0x80000);
  745. ODM_SetRFReg(pDM_Odm, Path, 0x30, bRFRegOffsetMask, 0x30000);
  746. ODM_SetRFReg(pDM_Odm, Path, 0x31, bRFRegOffsetMask, 0x00029);
  747. ODM_SetRFReg(pDM_Odm, Path, 0x32, bRFRegOffsetMask, 0xd7ffb);
  748. ODM_SetRFReg(pDM_Odm, Path, 0x65, bRFRegOffsetMask, temp_reg65);
  749. ODM_SetRFReg(pDM_Odm, Path, 0x8f, bRFRegOffsetMask, 0x8a001);
  750. ODM_SetRFReg(pDM_Odm, Path, 0xef, bRFRegOffsetMask, 0x00000);
  751. ODM_SetBBReg(pDM_Odm, 0xcb8, 0xf, 0xd);
  752. ODM_Write4Byte(pDM_Odm, 0x978, 0x29002000);// TX (X,Y)
  753. ODM_Write4Byte(pDM_Odm, 0x97c, 0xa9002000);// RX (X,Y)
  754. ODM_Write4Byte(pDM_Odm, 0x984, 0x0046a910);// [0]:AGC_en, [15]:idac_K_Mask
  755. ODM_Write4Byte(pDM_Odm, 0x90c, 0x00008000);
  756. ODM_Write4Byte(pDM_Odm, 0xb00, 0x03000100);
  757. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x1); // [31] = 1 --> Page C1
  758. switch (k){
  759. case 0:
  760. {
  761. ODM_Write4Byte(pDM_Odm, 0xc80, 0x18008c38);// TX_Tone_idx[9:0], TxK_Mask[29] TX_Tone = 16
  762. ODM_Write4Byte(pDM_Odm, 0xc84, 0x38008c38);// RX_Tone_idx[9:0], RxK_Mask[29]
  763. ODM_SetBBReg(pDM_Odm, 0xce8, BIT(30), 0x0);
  764. }
  765. break;
  766. case 1:
  767. {
  768. ODM_Write4Byte(pDM_Odm, 0xc80, 0x08008c38);// TX_Tone_idx[9:0], TxK_Mask[29] TX_Tone = 16
  769. ODM_Write4Byte(pDM_Odm, 0xc84, 0x28008c38);// RX_Tone_idx[9:0], RxK_Mask[29]
  770. ODM_SetBBReg(pDM_Odm, 0xce8, BIT(30), 0x0);
  771. }
  772. break;
  773. case 2:
  774. {
  775. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("VDF_Y[1] = %x;;;VDF_Y[0] = %x\n", VDF_Y[1]>>21 & 0x00007ff, VDF_Y[0]>>21 & 0x00007ff));
  776. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("VDF_X[1] = %x;;;VDF_X[0] = %x\n", VDF_X[1]>>21 & 0x00007ff, VDF_X[0]>>21 & 0x00007ff));
  777. Rx_dt[cal] = (VDF_Y[1]>>20)-(VDF_Y[0]>>20);
  778. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("Rx_dt = %d\n", Rx_dt[cal]));
  779. Rx_dt[cal] = ((16*Rx_dt[cal])*10000/13823);
  780. Rx_dt[cal] = (Rx_dt[cal] >> 1 )+(Rx_dt[cal] & BIT(0));
  781. ODM_Write4Byte(pDM_Odm, 0xc80, 0x18008c20);// TX_Tone_idx[9:0], TxK_Mask[29] TX_Tone = 16
  782. ODM_Write4Byte(pDM_Odm, 0xc84, 0x38008c20);// RX_Tone_idx[9:0], RxK_Mask[29]
  783. ODM_SetBBReg(pDM_Odm, 0xce8, 0x00003fff, Rx_dt[cal] & 0x00003fff);
  784. }
  785. break;
  786. default:
  787. break;
  788. }
  789. ODM_Write4Byte(pDM_Odm, 0xc88, 0x821603e0);
  790. ODM_Write4Byte(pDM_Odm, 0xc8c, 0x68163e96);
  791. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x00100000);// cb8[20] 將 SI/PI 使用權切給 iqk_dpk module
  792. cal_retry = 0;
  793. while(1){
  794. // one shot
  795. ODM_Write4Byte(pDM_Odm, 0x980, 0xfa000000);
  796. ODM_Write4Byte(pDM_Odm, 0x980, 0xf8000000);
  797. ODM_delay_ms(10); //Delay 10ms
  798. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x00000000);
  799. delay_count = 0;
  800. while (1){
  801. IQK_ready = ODM_GetBBReg(pDM_Odm, 0xd00, BIT(10));
  802. if ((~IQK_ready)||(delay_count>20)){
  803. break;
  804. }
  805. else{
  806. ODM_delay_ms(1);
  807. delay_count++;
  808. }
  809. }
  810. if (delay_count < 20){ // If 20ms No Result, then cal_retry++
  811. // ============TXIQK Check==============
  812. TX_fail = ODM_GetBBReg(pDM_Odm, 0xd00, BIT(12));
  813. if (~TX_fail){
  814. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x02000000);
  815. TX_X0_RXK[cal] = ODM_GetBBReg(pDM_Odm, 0xd00, 0x07ff0000)<<21;
  816. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x04000000);
  817. TX_Y0_RXK[cal] = ODM_GetBBReg(pDM_Odm, 0xd00, 0x07ff0000)<<21;
  818. TX0IQKOK = TRUE;
  819. break;
  820. }
  821. else{
  822. TX0IQKOK = FALSE;
  823. cal_retry++;
  824. if (cal_retry == 10)
  825. break;
  826. }
  827. }
  828. else{
  829. TX0IQKOK = FALSE;
  830. cal_retry++;
  831. if (cal_retry == 10)
  832. break;
  833. }
  834. }
  835. if (TX0IQKOK == FALSE){ //If RX mode TXK fail, then take TXK Result
  836. TX_X0_RXK[cal] = TX_X0[cal];
  837. TX_Y0_RXK[cal] = TX_Y0[cal];
  838. TX0IQKOK = TRUE;
  839. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("RXK Step 1 fail\n"));
  840. }
  841. //====== RX IQK ======
  842. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  843. // 1. RX RF Setting
  844. ODM_SetRFReg(pDM_Odm, Path, 0xef, bRFRegOffsetMask, 0x80000);
  845. ODM_SetRFReg(pDM_Odm, Path, 0x30, bRFRegOffsetMask, 0x30000);
  846. ODM_SetRFReg(pDM_Odm, Path, 0x31, bRFRegOffsetMask, 0x0002f);
  847. ODM_SetRFReg(pDM_Odm, Path, 0x32, bRFRegOffsetMask, 0xfffbb);
  848. ODM_SetRFReg(pDM_Odm, Path, 0x8f, bRFRegOffsetMask, 0x88001);
  849. ODM_SetRFReg(pDM_Odm, Path, 0x65, bRFRegOffsetMask, 0x931d8);
  850. ODM_SetRFReg(pDM_Odm, Path, 0xef, bRFRegOffsetMask, 0x00000);
  851. ODM_SetBBReg(pDM_Odm, 0x978, 0x03FF8000, (TX_X0_RXK[cal])>>21&0x000007ff);
  852. ODM_SetBBReg(pDM_Odm, 0x978, 0x000007FF, (TX_Y0_RXK[cal])>>21&0x000007ff);
  853. ODM_SetBBReg(pDM_Odm, 0x978, BIT(31), 0x1);
  854. ODM_SetBBReg(pDM_Odm, 0x97c, BIT(31), 0x0);
  855. ODM_SetBBReg(pDM_Odm, 0xcb8, 0xF, 0xe);
  856. ODM_Write4Byte(pDM_Odm, 0x90c, 0x00008000);
  857. ODM_Write4Byte(pDM_Odm, 0x984, 0x0046a911);
  858. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x1); // [31] = 1 --> Page C1
  859. ODM_SetBBReg(pDM_Odm, 0xc80, BIT(29), 0x1);
  860. ODM_SetBBReg(pDM_Odm, 0xc84, BIT(29), 0x0);
  861. ODM_Write4Byte(pDM_Odm, 0xc88, 0x02140119);
  862. ODM_Write4Byte(pDM_Odm, 0xc8c, 0x28161420);
  863. if (k==2){
  864. ODM_SetBBReg(pDM_Odm, 0xce8, BIT(30), 0x1); //RX VDF Enable
  865. }
  866. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x00100000);// cb8[20] 將 SI/PI 使用權切給 iqk_dpk module
  867. cal_retry = 0;
  868. while(1){
  869. // one shot
  870. ODM_Write4Byte(pDM_Odm, 0x980, 0xfa000000);
  871. ODM_Write4Byte(pDM_Odm, 0x980, 0xf8000000);
  872. ODM_delay_ms(10); //Delay 10ms
  873. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x00000000);
  874. delay_count = 0;
  875. while (1){
  876. IQK_ready = ODM_GetBBReg(pDM_Odm, 0xd00, BIT(10));
  877. if ((~IQK_ready)||(delay_count>20)){
  878. break;
  879. }
  880. else{
  881. ODM_delay_ms(1);
  882. delay_count++;
  883. }
  884. }
  885. if (delay_count < 20){ // If 20ms No Result, then cal_retry++
  886. // ============RXIQK Check==============
  887. RX_fail = ODM_GetBBReg(pDM_Odm, 0xd00, BIT(11));
  888. if (RX_fail == 0){
  889. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x06000000);
  890. VDF_X[k] = ODM_GetBBReg(pDM_Odm, 0xd00, 0x07ff0000)<<21;
  891. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x08000000);
  892. VDF_Y[k] = ODM_GetBBReg(pDM_Odm, 0xd00, 0x07ff0000)<<21;
  893. RX0IQKOK = TRUE;
  894. break;
  895. }
  896. else{
  897. ODM_SetBBReg(pDM_Odm, 0xc10, 0x000003ff, 0x200>>1);
  898. ODM_SetBBReg(pDM_Odm, 0xc10, 0x03ff0000, 0x0>>1);
  899. RX0IQKOK = FALSE;
  900. cal_retry++;
  901. if (cal_retry == 10)
  902. break;
  903. }
  904. }
  905. else{
  906. RX0IQKOK = FALSE;
  907. cal_retry++;
  908. if (cal_retry == 10)
  909. break;
  910. }
  911. }
  912. }
  913. if (k == 3){
  914. RX_X0[cal] = VDF_X[k-1] ;
  915. RX_Y0[cal] = VDF_Y[k-1];
  916. }
  917. ODM_SetBBReg(pDM_Odm, 0xce8, BIT(31), 0x1); // TX VDF Enable
  918. }
  919. else{
  920. //====== RX mode TXK (RXK Step 1) ======
  921. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  922. // 1. TX RF Setting
  923. ODM_SetRFReg(pDM_Odm, Path, 0xef, bRFRegOffsetMask, 0x80000);
  924. ODM_SetRFReg(pDM_Odm, Path, 0x30, bRFRegOffsetMask, 0x30000);
  925. ODM_SetRFReg(pDM_Odm, Path, 0x31, bRFRegOffsetMask, 0x00029);
  926. ODM_SetRFReg(pDM_Odm, Path, 0x32, bRFRegOffsetMask, 0xd7ffb);
  927. ODM_SetRFReg(pDM_Odm, Path, 0x65, bRFRegOffsetMask, temp_reg65);
  928. ODM_SetRFReg(pDM_Odm, Path, 0x8f, bRFRegOffsetMask, 0x8a001);
  929. ODM_SetRFReg(pDM_Odm, Path, 0xef, bRFRegOffsetMask, 0x00000);
  930. ODM_Write4Byte(pDM_Odm, 0x90c, 0x00008000);
  931. ODM_Write4Byte(pDM_Odm, 0xb00, 0x03000100);
  932. ODM_Write4Byte(pDM_Odm, 0x984, 0x0046a910);// [0]:AGC_en, [15]:idac_K_Mask
  933. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x1); // [31] = 1 --> Page C1
  934. ODM_Write4Byte(pDM_Odm, 0xc80, 0x18008c10);// TX_Tone_idx[9:0], TxK_Mask[29] TX_Tone = 16
  935. ODM_Write4Byte(pDM_Odm, 0xc84, 0x38008c10);// RX_Tone_idx[9:0], RxK_Mask[29]
  936. ODM_Write4Byte(pDM_Odm, 0xc88, 0x821603e0);
  937. //ODM_Write4Byte(pDM_Odm, 0xc8c, 0x68163e96);
  938. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x00100000);// cb8[20] 將 SI/PI 使用權切給 iqk_dpk module
  939. cal_retry = 0;
  940. while(1){
  941. // one shot
  942. ODM_Write4Byte(pDM_Odm, 0x980, 0xfa000000);
  943. ODM_Write4Byte(pDM_Odm, 0x980, 0xf8000000);
  944. ODM_delay_ms(10); //Delay 10ms
  945. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x00000000);
  946. delay_count = 0;
  947. while (1){
  948. IQK_ready = ODM_GetBBReg(pDM_Odm, 0xd00, BIT(10));
  949. if ((~IQK_ready)||(delay_count>20)){
  950. break;
  951. }
  952. else{
  953. ODM_delay_ms(1);
  954. delay_count++;
  955. }
  956. }
  957. if (delay_count < 20){ // If 20ms No Result, then cal_retry++
  958. // ============TXIQK Check==============
  959. TX_fail = ODM_GetBBReg(pDM_Odm, 0xd00, BIT(12));
  960. if (~TX_fail){
  961. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x02000000);
  962. TX_X0_RXK[cal] = ODM_GetBBReg(pDM_Odm, 0xd00, 0x07ff0000)<<21;
  963. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x04000000);
  964. TX_Y0_RXK[cal] = ODM_GetBBReg(pDM_Odm, 0xd00, 0x07ff0000)<<21;
  965. TX0IQKOK = TRUE;
  966. break;
  967. }
  968. else{
  969. TX0IQKOK = FALSE;
  970. cal_retry++;
  971. if (cal_retry == 10)
  972. break;
  973. }
  974. }
  975. else{
  976. TX0IQKOK = FALSE;
  977. cal_retry++;
  978. if (cal_retry == 10)
  979. break;
  980. }
  981. }
  982. if (TX0IQKOK == FALSE){ //If RX mode TXK fail, then take TXK Result
  983. TX_X0_RXK[cal] = TX_X0[cal];
  984. TX_Y0_RXK[cal] = TX_Y0[cal];
  985. TX0IQKOK = TRUE;
  986. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("1"));
  987. }
  988. //====== RX IQK ======
  989. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  990. // 1. RX RF Setting
  991. ODM_SetRFReg(pDM_Odm, Path, 0xef, bRFRegOffsetMask, 0x80000);
  992. ODM_SetRFReg(pDM_Odm, Path, 0x30, bRFRegOffsetMask, 0x30000);
  993. ODM_SetRFReg(pDM_Odm, Path, 0x31, bRFRegOffsetMask, 0x0002f);
  994. ODM_SetRFReg(pDM_Odm, Path, 0x32, bRFRegOffsetMask, 0xfffbb);
  995. ODM_SetRFReg(pDM_Odm, Path, 0x8f, bRFRegOffsetMask, 0x88001);
  996. ODM_SetRFReg(pDM_Odm, Path, 0x65, bRFRegOffsetMask, 0x931d8);
  997. ODM_SetRFReg(pDM_Odm, Path, 0xef, bRFRegOffsetMask, 0x00000);
  998. ODM_SetBBReg(pDM_Odm, 0x978, 0x03FF8000, (TX_X0_RXK[cal])>>21&0x000007ff);
  999. ODM_SetBBReg(pDM_Odm, 0x978, 0x000007FF, (TX_Y0_RXK[cal])>>21&0x000007ff);
  1000. ODM_SetBBReg(pDM_Odm, 0x978, BIT(31), 0x1);
  1001. ODM_SetBBReg(pDM_Odm, 0x97c, BIT(31), 0x0);
  1002. ODM_SetBBReg(pDM_Odm, 0xcb8, 0xF, 0xe);
  1003. ODM_Write4Byte(pDM_Odm, 0x90c, 0x00008000);
  1004. ODM_Write4Byte(pDM_Odm, 0x984, 0x0046a911);
  1005. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x1); // [31] = 1 --> Page C1
  1006. ODM_Write4Byte(pDM_Odm, 0xc80, 0x38008c10);// TX_Tone_idx[9:0], TxK_Mask[29] TX_Tone = 16
  1007. ODM_Write4Byte(pDM_Odm, 0xc84, 0x18008c10);// RX_Tone_idx[9:0], RxK_Mask[29]
  1008. ODM_Write4Byte(pDM_Odm, 0xc88, 0x02140119);
  1009. ODM_Write4Byte(pDM_Odm, 0xc8c, 0x28161440);
  1010. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x00100000);// cb8[20] 將 SI/PI 使用權切給 iqk_dpk module
  1011. cal_retry = 0;
  1012. while(1){
  1013. // one shot
  1014. ODM_Write4Byte(pDM_Odm, 0x980, 0xfa000000);
  1015. ODM_Write4Byte(pDM_Odm, 0x980, 0xf8000000);
  1016. ODM_delay_ms(10); //Delay 10ms
  1017. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x00000000);
  1018. delay_count = 0;
  1019. while (1){
  1020. IQK_ready = ODM_GetBBReg(pDM_Odm, 0xd00, BIT(10));
  1021. if ((~IQK_ready)||(delay_count>20)){
  1022. break;
  1023. }
  1024. else{
  1025. ODM_delay_ms(1);
  1026. delay_count++;
  1027. }
  1028. }
  1029. if (delay_count < 20){ // If 20ms No Result, then cal_retry++
  1030. // ============RXIQK Check==============
  1031. RX_fail = ODM_GetBBReg(pDM_Odm, 0xd00, BIT(11));
  1032. if (RX_fail == 0){
  1033. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x06000000);
  1034. RX_X0[cal] = ODM_GetBBReg(pDM_Odm, 0xd00, 0x07ff0000)<<21;
  1035. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x08000000);
  1036. RX_Y0[cal] = ODM_GetBBReg(pDM_Odm, 0xd00, 0x07ff0000)<<21;
  1037. RX0IQKOK = TRUE;
  1038. break;
  1039. }
  1040. else{
  1041. ODM_SetBBReg(pDM_Odm, 0xc10, 0x000003ff, 0x200>>1);
  1042. ODM_SetBBReg(pDM_Odm, 0xc10, 0x03ff0000, 0x0>>1);
  1043. RX0IQKOK = FALSE;
  1044. cal_retry++;
  1045. if (cal_retry == 10)
  1046. break;
  1047. }
  1048. }
  1049. else{
  1050. RX0IQKOK = FALSE;
  1051. cal_retry++;
  1052. if (cal_retry == 10)
  1053. break;
  1054. }
  1055. }
  1056. }
  1057. if (TX0IQKOK)
  1058. TX_Average++;
  1059. if (RX0IQKOK)
  1060. RX_Average++;
  1061. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  1062. ODM_SetRFReg(pDM_Odm, Path, 0x65, bRFRegOffsetMask, temp_reg65);
  1063. }
  1064. break;
  1065. default:
  1066. break;
  1067. }
  1068. cal++;
  1069. }
  1070. // FillIQK Result
  1071. switch (Path){
  1072. case ODM_RF_PATH_A:
  1073. {
  1074. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("========Path_A =======\n"));
  1075. if (TX_Average == 0)
  1076. break;
  1077. for (i = 0; i < TX_Average; i++){
  1078. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, (" TX_X0_RXK[%d] = %x ;; TX_Y0_RXK[%d] = %x\n", i, (TX_X0_RXK[i])>>21&0x000007ff, i, (TX_Y0_RXK[i])>>21&0x000007ff));
  1079. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("TX_X0[%d] = %x ;; TX_Y0[%d] = %x\n", i, (TX_X0[i])>>21&0x000007ff, i, (TX_Y0[i])>>21&0x000007ff));
  1080. }
  1081. for (i = 0; i < TX_Average; i++){
  1082. for (ii = i+1; ii <TX_Average; ii++){
  1083. dx = (TX_X0[i]>>21) - (TX_X0[ii]>>21);
  1084. if (dx < 3 && dx > -3){
  1085. dy = (TX_Y0[i]>>21) - (TX_Y0[ii]>>21);
  1086. if (dy < 3 && dy > -3){
  1087. TX_X = ((TX_X0[i]>>21) + (TX_X0[ii]>>21))/2;
  1088. TX_Y = ((TX_Y0[i]>>21) + (TX_Y0[ii]>>21))/2;
  1089. TX_finish = 1;
  1090. break;
  1091. }
  1092. }
  1093. }
  1094. if (TX_finish == 1)
  1095. break;
  1096. }
  1097. if (TX_finish == 1){
  1098. _IQK_TX_FillIQC_8821A(pDM_Odm, Path, TX_X, TX_Y);
  1099. }
  1100. else{
  1101. _IQK_TX_FillIQC_8821A(pDM_Odm, Path, 0x200, 0x0);
  1102. }
  1103. if (RX_Average == 0)
  1104. break;
  1105. for (i = 0; i < RX_Average; i++){
  1106. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("RX_X0[%d] = %x ;; RX_Y0[%d] = %x\n", i, (RX_X0[i])>>21&0x000007ff, i, (RX_Y0[i])>>21&0x000007ff));
  1107. }
  1108. for (i = 0; i < RX_Average; i++){
  1109. for (ii = i+1; ii <RX_Average; ii++){
  1110. dx = (RX_X0[i]>>21) - (RX_X0[ii]>>21);
  1111. if (dx < 3 && dx > -3){
  1112. dy = (RX_Y0[i]>>21) - (RX_Y0[ii]>>21);
  1113. if (dy < 3 && dy > -3){
  1114. RX_X = ((RX_X0[i]>>21) + (RX_X0[ii]>>21))/2;
  1115. RX_Y = ((RX_Y0[i]>>21) + (RX_Y0[ii]>>21))/2;
  1116. RX_finish = 1;
  1117. break;
  1118. }
  1119. }
  1120. }
  1121. if (RX_finish == 1)
  1122. break;
  1123. }
  1124. if (RX_finish == 1){
  1125. _IQK_RX_FillIQC_8821A(pDM_Odm, Path, RX_X, RX_Y);
  1126. }
  1127. else{
  1128. _IQK_RX_FillIQC_8821A(pDM_Odm, Path, 0x200, 0x0);
  1129. }
  1130. }
  1131. break;
  1132. default:
  1133. break;
  1134. }
  1135. }
  1136. #define MACBB_REG_NUM 11
  1137. #define AFE_REG_NUM 12
  1138. #define RF_REG_NUM 3
  1139. VOID
  1140. phy_IQCalibrate_By_FW_8821A(
  1141. IN PADAPTER pAdapter
  1142. )
  1143. {
  1144. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  1145. u1Byte IQKcmd[3] = {pHalData->CurrentChannel, 0x0, 0x0};
  1146. u1Byte Buf1 = 0x0;
  1147. u1Byte Buf2 = 0x0;
  1148. //Byte 2, Bit 4 ~ Bit 5 : BandType
  1149. if(pHalData->CurrentBandType)
  1150. Buf1 = 0x2<<4;
  1151. else
  1152. Buf1 = 0x1<<4;
  1153. //Byte 2, Bit 0 ~ Bit 3 : Bandwidth
  1154. if(pHalData->CurrentChannelBW == CHANNEL_WIDTH_20)
  1155. Buf2 = 0x1;
  1156. else if(pHalData->CurrentChannelBW == CHANNEL_WIDTH_40)
  1157. Buf2 = 0x1<<1;
  1158. else if(pHalData->CurrentChannelBW == CHANNEL_WIDTH_80)
  1159. Buf2 = 0x1<<2;
  1160. else
  1161. Buf2 = 0x1<<3;
  1162. IQKcmd[1] = Buf1 | Buf2;
  1163. IQKcmd[2] = pHalData->ExternalPA_5G | pHalData->ExternalLNA_5G<<1;
  1164. //RT_TRACE(COMP_MP, DBG_LOUD, ("== IQK Start ==\n"));
  1165. //FillH2CCmd_8812(pAdapter, 0x45, 3, IQKcmd);
  1166. }
  1167. VOID
  1168. phy_IQCalibrate_8821A(
  1169. IN PDM_ODM_T pDM_Odm
  1170. )
  1171. {
  1172. u4Byte MACBB_backup[MACBB_REG_NUM], AFE_backup[AFE_REG_NUM], RFA_backup[RF_REG_NUM], RFB_backup[RF_REG_NUM];
  1173. u4Byte Backup_MACBB_REG[MACBB_REG_NUM] = {0xb00, 0x520, 0x550, 0x808, 0x90c, 0xc00, 0xc50, 0xe00, 0xe50, 0x838, 0x82c};
  1174. u4Byte Backup_AFE_REG[AFE_REG_NUM] = {0xc5c, 0xc60, 0xc64, 0xc68, 0xc6c, 0xc70, 0xc74, 0xc78, 0xc7c, 0xc80, 0xc84, 0xcb8};
  1175. u4Byte Backup_RF_REG[RF_REG_NUM] = {0x65, 0x8f, 0x0};
  1176. _IQK_BackupMacBB_8821A(pDM_Odm, MACBB_backup, Backup_MACBB_REG, MACBB_REG_NUM);
  1177. _IQK_BackupAFE_8821A(pDM_Odm, AFE_backup, Backup_AFE_REG, AFE_REG_NUM);
  1178. _IQK_BackupRF_8821A(pDM_Odm, RFA_backup, RFB_backup, Backup_RF_REG, RF_REG_NUM);
  1179. _IQK_ConfigureMAC_8821A(pDM_Odm);
  1180. _IQK_Tx_8821A(pDM_Odm, ODM_RF_PATH_A);
  1181. _IQK_RestoreRF_8821A(pDM_Odm, ODM_RF_PATH_A, Backup_RF_REG, RFA_backup, RF_REG_NUM);
  1182. _IQK_RestoreAFE_8821A(pDM_Odm, AFE_backup, Backup_AFE_REG, AFE_REG_NUM);
  1183. _IQK_RestoreMacBB_8821A(pDM_Odm, MACBB_backup, Backup_MACBB_REG, MACBB_REG_NUM);
  1184. //_IQK_Exit_8821A(pDM_Odm);
  1185. //_IQK_TX_CheckResult_8821A
  1186. }
  1187. #define DP_BB_REG_NUM 7
  1188. #define DP_RF_REG_NUM 1
  1189. #define DP_RETRY_LIMIT 10
  1190. #define DP_PATH_NUM 2
  1191. #define DP_DPK_NUM 3
  1192. #define DP_DPK_VALUE_NUM 2
  1193. VOID
  1194. PHY_IQCalibrate_8821A(
  1195. IN PADAPTER pAdapter,
  1196. IN BOOLEAN bReCovery
  1197. )
  1198. {
  1199. #if !(DM_ODM_SUPPORT_TYPE & ODM_AP)
  1200. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  1201. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  1202. PDM_ODM_T pDM_Odm = &pHalData->DM_OutSrc;
  1203. #else // (DM_ODM_SUPPORT_TYPE == ODM_CE)
  1204. PDM_ODM_T pDM_Odm = &pHalData->odmpriv;
  1205. #endif
  1206. #endif
  1207. #if (MP_DRIVER == 1)
  1208. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  1209. PMPT_CONTEXT pMptCtx = &(pAdapter->MptCtx);
  1210. #else// (DM_ODM_SUPPORT_TYPE == ODM_CE)
  1211. PMPT_CONTEXT pMptCtx = &(pAdapter->mppriv.MptCtx);
  1212. #endif
  1213. #endif//(MP_DRIVER == 1)
  1214. #if 0 //ODM_CheckPowerStatus always return TRUE currently!
  1215. #if (DM_ODM_SUPPORT_TYPE & (ODM_WIN|ODM_CE) )
  1216. if (ODM_CheckPowerStatus(pAdapter) == FALSE)
  1217. return;
  1218. #endif
  1219. #endif //gtemp
  1220. #if MP_DRIVER == 1
  1221. if( ! (pMptCtx->bSingleTone || pMptCtx->bCarrierSuppression) )
  1222. #endif
  1223. {
  1224. //if(pMgntInfo->RegIQKFWOffload)
  1225. // phy_IQCalibrate_By_FW_8821A(pAdapter);
  1226. //else
  1227. phy_IQCalibrate_8821A(pDM_Odm);
  1228. }
  1229. }
  1230. VOID
  1231. PHY_LCCalibrate_8821A(
  1232. IN PDM_ODM_T pDM_Odm
  1233. )
  1234. {
  1235. PHY_LCCalibrate_8812A(pDM_Odm);
  1236. }