HalPhyRf_8812A.c 108 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842
  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 "../odm_precomp.h"
  21. /*---------------------------Define Local Constant---------------------------*/
  22. // 2010/04/25 MH Define the max tx power tracking tx agc power.
  23. #define ODM_TXPWRTRACK_MAX_IDX8812A 6
  24. /*---------------------------Define Local Constant---------------------------*/
  25. //3============================================================
  26. //3 Tx Power Tracking
  27. //3============================================================
  28. void DoIQK_8812A(
  29. PDM_ODM_T pDM_Odm,
  30. u1Byte DeltaThermalIndex,
  31. u1Byte ThermalValue,
  32. u1Byte Threshold
  33. )
  34. {
  35. #if !(DM_ODM_SUPPORT_TYPE & ODM_AP)
  36. PADAPTER Adapter = pDM_Odm->Adapter;
  37. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  38. #endif
  39. ODM_ResetIQKResult(pDM_Odm);
  40. #if(DM_ODM_SUPPORT_TYPE & ODM_WIN)
  41. #if (DEV_BUS_TYPE == RT_PCI_INTERFACE)
  42. #if USE_WORKITEM
  43. PlatformAcquireMutex(&pHalData->mxChnlBwControl);
  44. #else
  45. PlatformAcquireSpinLock(Adapter, RT_CHANNEL_AND_BANDWIDTH_SPINLOCK);
  46. #endif
  47. #elif((DEV_BUS_TYPE == RT_USB_INTERFACE) || (DEV_BUS_TYPE == RT_SDIO_INTERFACE))
  48. PlatformAcquireMutex(&pHalData->mxChnlBwControl);
  49. #endif
  50. #endif
  51. pDM_Odm->RFCalibrateInfo.ThermalValue_IQK= ThermalValue;
  52. PHY_IQCalibrate_8812A(Adapter, FALSE);
  53. #if(DM_ODM_SUPPORT_TYPE & ODM_WIN)
  54. #if (DEV_BUS_TYPE == RT_PCI_INTERFACE)
  55. #if USE_WORKITEM
  56. PlatformReleaseMutex(&pHalData->mxChnlBwControl);
  57. #else
  58. PlatformReleaseSpinLock(Adapter, RT_CHANNEL_AND_BANDWIDTH_SPINLOCK);
  59. #endif
  60. #elif((DEV_BUS_TYPE == RT_USB_INTERFACE) || (DEV_BUS_TYPE == RT_SDIO_INTERFACE))
  61. PlatformReleaseMutex(&pHalData->mxChnlBwControl);
  62. #endif
  63. #endif
  64. }
  65. /*-----------------------------------------------------------------------------
  66. * Function: odm_TxPwrTrackSetPwr88E()
  67. *
  68. * Overview: 88E change all channel tx power accordign to flag.
  69. * OFDM & CCK are all different.
  70. *
  71. * Input: NONE
  72. *
  73. * Output: NONE
  74. *
  75. * Return: NONE
  76. *
  77. * Revised History:
  78. * When Who Remark
  79. * 04/23/2012 MHC Create Version 0.
  80. *
  81. *---------------------------------------------------------------------------*/
  82. VOID
  83. ODM_TxPwrTrackSetPwr8812A(
  84. PDM_ODM_T pDM_Odm,
  85. PWRTRACK_METHOD Method,
  86. u1Byte RFPath,
  87. u1Byte ChannelMappedIndex
  88. )
  89. {
  90. u4Byte finalBbSwingIdx[2];
  91. PADAPTER Adapter = pDM_Odm->Adapter;
  92. PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
  93. u1Byte PwrTrackingLimit = 26; //+1.0dB
  94. u1Byte TxRate = 0xFF;
  95. s1Byte Final_OFDM_Swing_Index = 0;
  96. s1Byte Final_CCK_Swing_Index = 0;
  97. u1Byte i = 0;
  98. #if 0
  99. #if (MP_DRIVER==1)
  100. PMPT_CONTEXT pMptCtx = &(Adapter->MptCtx);
  101. TxRate = MptToMgntRate(pMptCtx->MptRateIndex);
  102. #else
  103. u2Byte rate = *(pDM_Odm->pForcedDataRate);
  104. if(!rate) //auto rate
  105. {
  106. if(pDM_Odm->TxRate != 0xFF)
  107. TxRate = HwRateToMRate8812(pDM_Odm->TxRate);
  108. }
  109. else //force rate
  110. {
  111. TxRate = (u1Byte) rate;
  112. }
  113. #endif
  114. ODM_RT_TRACE(pDM_Odm,ODM_COMP_TX_PWR_TRACK, ODM_DBG_LOUD,("===>ODM_TxPwrTrackSetPwr8812A\n"));
  115. #endif
  116. if(TxRate != 0xFF)
  117. {
  118. //2 CCK
  119. if((TxRate >= MGN_1M)&&(TxRate <= MGN_11M))
  120. PwrTrackingLimit = 32; //+4dB
  121. //2 OFDM
  122. else if((TxRate >= MGN_6M)&&(TxRate <= MGN_48M))
  123. PwrTrackingLimit = 32; //+4dB
  124. else if(TxRate == MGN_54M)
  125. PwrTrackingLimit = 30; //+3dB
  126. //2 HT
  127. else if((TxRate >= MGN_MCS0)&&(TxRate <= MGN_MCS2)) //QPSK/BPSK
  128. PwrTrackingLimit = 34; //+5dB
  129. else if((TxRate >= MGN_MCS3)&&(TxRate <= MGN_MCS4)) //16QAM
  130. PwrTrackingLimit = 32; //+4dB
  131. else if((TxRate >= MGN_MCS5)&&(TxRate <= MGN_MCS7)) //64QAM
  132. PwrTrackingLimit = 30; //+3dB
  133. else if((TxRate >= MGN_MCS8)&&(TxRate <= MGN_MCS10)) //QPSK/BPSK
  134. PwrTrackingLimit = 34; //+5dB
  135. else if((TxRate >= MGN_MCS11)&&(TxRate <= MGN_MCS12)) //16QAM
  136. PwrTrackingLimit = 32; //+4dB
  137. else if((TxRate >= MGN_MCS13)&&(TxRate <= MGN_MCS15)) //64QAM
  138. PwrTrackingLimit = 30; //+3dB
  139. //2 VHT
  140. else if((TxRate >= MGN_VHT1SS_MCS0)&&(TxRate <= MGN_VHT1SS_MCS2)) //QPSK/BPSK
  141. PwrTrackingLimit = 34; //+5dB
  142. else if((TxRate >= MGN_VHT1SS_MCS3)&&(TxRate <= MGN_VHT1SS_MCS4)) //16QAM
  143. PwrTrackingLimit = 32; //+4dB
  144. else if((TxRate >= MGN_VHT1SS_MCS5)&&(TxRate <= MGN_VHT1SS_MCS6)) //64QAM
  145. PwrTrackingLimit = 30; //+3dB
  146. else if(TxRate == MGN_VHT1SS_MCS7) //64QAM
  147. PwrTrackingLimit = 28; //+2dB
  148. else if(TxRate == MGN_VHT1SS_MCS8) //256QAM
  149. PwrTrackingLimit = 26; //+1dB
  150. else if(TxRate == MGN_VHT1SS_MCS9) //256QAM
  151. PwrTrackingLimit = 24; //+0dB
  152. else if((TxRate >= MGN_VHT2SS_MCS0)&&(TxRate <= MGN_VHT2SS_MCS2)) //QPSK/BPSK
  153. PwrTrackingLimit = 34; //+5dB
  154. else if((TxRate >= MGN_VHT2SS_MCS3)&&(TxRate <= MGN_VHT2SS_MCS4)) //16QAM
  155. PwrTrackingLimit = 32; //+4dB
  156. else if((TxRate >= MGN_VHT2SS_MCS5)&&(TxRate <= MGN_VHT2SS_MCS6)) //64QAM
  157. PwrTrackingLimit = 30; //+3dB
  158. else if(TxRate == MGN_VHT2SS_MCS7) //64QAM
  159. PwrTrackingLimit = 28; //+2dB
  160. else if(TxRate == MGN_VHT2SS_MCS8) //256QAM
  161. PwrTrackingLimit = 26; //+1dB
  162. else if(TxRate == MGN_VHT2SS_MCS9) //256QAM
  163. PwrTrackingLimit = 24; //+0dB
  164. else
  165. PwrTrackingLimit = 24;
  166. }
  167. ODM_RT_TRACE(pDM_Odm,ODM_COMP_TX_PWR_TRACK, ODM_DBG_LOUD,("TxRate=0x%x, PwrTrackingLimit=%d\n", TxRate, PwrTrackingLimit));
  168. if (Method == BBSWING)
  169. {
  170. ODM_RT_TRACE(pDM_Odm,ODM_COMP_TX_PWR_TRACK, ODM_DBG_LOUD,("===>ODM_TxPwrTrackSetPwr8812A\n"));
  171. if (RFPath == ODM_RF_PATH_A)
  172. {
  173. 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];
  174. 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",
  175. pDM_Odm->RFCalibrateInfo.OFDM_index[ODM_RF_PATH_A], finalBbSwingIdx[ODM_RF_PATH_A]));
  176. ODM_SetBBReg(pDM_Odm, rA_TxScale_Jaguar, 0xFFE00000, TxScalingTable_Jaguar[finalBbSwingIdx[ODM_RF_PATH_A]]);
  177. }
  178. else
  179. {
  180. finalBbSwingIdx[ODM_RF_PATH_B] = (pDM_Odm->RFCalibrateInfo.OFDM_index[ODM_RF_PATH_B] > PwrTrackingLimit) ? PwrTrackingLimit : pDM_Odm->RFCalibrateInfo.OFDM_index[ODM_RF_PATH_B];
  181. ODM_RT_TRACE(pDM_Odm,ODM_COMP_TX_PWR_TRACK, ODM_DBG_LOUD,("pDM_Odm->RFCalibrateInfo.OFDM_index[ODM_RF_PATH_B]=%d, pDM_Odm->RealBbSwingIdx[ODM_RF_PATH_B]=%d\n",
  182. pDM_Odm->RFCalibrateInfo.OFDM_index[ODM_RF_PATH_B], finalBbSwingIdx[ODM_RF_PATH_B]));
  183. ODM_SetBBReg(pDM_Odm, rB_TxScale_Jaguar, 0xFFE00000, TxScalingTable_Jaguar[finalBbSwingIdx[ODM_RF_PATH_B]]);
  184. }
  185. /*
  186. // <20121120> +2.5dB clipping, asked by Jerry Chang.
  187. pDM_Odm->BbSwingIdxOfdm[ODM_RF_PATH_A] = (pDM_Odm->BbSwingIdxOfdm[ODM_RF_PATH_A] > 29) ? 29 : pDM_Odm->BbSwingIdxOfdm[ODM_RF_PATH_A];
  188. pDM_Odm->BbSwingIdxOfdm[ODM_RF_PATH_B] = (pDM_Odm->BbSwingIdxOfdm[ODM_RF_PATH_B] > 29) ? 29 : pDM_Odm->BbSwingIdxOfdm[ODM_RF_PATH_B];
  189. //2013.01.28 LukeLee: This is for debug request by Joe, otherwise BbSwingOffsetA and BbSwingOffsetB is 0 in normal & MP driver
  190. if(pDM_Odm->IsBbSwingOffsetPositiveA)
  191. {
  192. finalBbSwingIdx[ODM_RF_PATH_A] = pDM_Odm->BbSwingIdxOfdm[ODM_RF_PATH_A] + pDM_Odm->BbSwingOffsetA;
  193. finalBbSwingIdx[ODM_RF_PATH_A] = (finalBbSwingIdx[ODM_RF_PATH_A] > 29) ? 29 : finalBbSwingIdx[ODM_RF_PATH_A];
  194. }
  195. else
  196. finalBbSwingIdx[ODM_RF_PATH_A] = pDM_Odm->BbSwingIdxOfdm[ODM_RF_PATH_A] - pDM_Odm->BbSwingOffsetA;
  197. if(pDM_Odm->IsBbSwingOffsetPositiveB)
  198. {
  199. finalBbSwingIdx[ODM_RF_PATH_B] = pDM_Odm->BbSwingIdxOfdm[ODM_RF_PATH_B] + pDM_Odm->BbSwingOffsetB;
  200. finalBbSwingIdx[ODM_RF_PATH_B] = (finalBbSwingIdx[ODM_RF_PATH_B] > 29) ? 29 : finalBbSwingIdx[ODM_RF_PATH_B];
  201. }
  202. else
  203. finalBbSwingIdx[ODM_RF_PATH_B] = pDM_Odm->BbSwingIdxOfdm[ODM_RF_PATH_B] - pDM_Odm->BbSwingOffsetB;
  204. // Adjust BB swing by Tx scaling, no matter CCK or OFDM.
  205. if (RFPath == ODM_RF_PATH_A)
  206. ODM_SetBBReg(pDM_Odm, rA_TxScale_Jaguar, 0xFFE00000, TxScalingTable_Jaguar[finalBbSwingIdx[ODM_RF_PATH_A]]);
  207. else if (RFPath == ODM_RF_PATH_B)
  208. ODM_SetBBReg(pDM_Odm, rB_TxScale_Jaguar, 0xFFE00000, TxScalingTable_Jaguar[finalBbSwingIdx[ODM_RF_PATH_B]]);
  209. */
  210. }
  211. else if (Method == MIX_MODE)
  212. {
  213. 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",
  214. pDM_Odm->DefaultOfdmIndex, pDM_Odm->Aboslute_OFDMSwingIdx[RFPath],RFPath ));
  215. Final_OFDM_Swing_Index = pDM_Odm->DefaultOfdmIndex + pDM_Odm->Aboslute_OFDMSwingIdx[RFPath];
  216. if (RFPath == ODM_RF_PATH_A)
  217. {
  218. if(Final_OFDM_Swing_Index > PwrTrackingLimit) //BBSwing higher then Limit
  219. {
  220. pDM_Odm->Remnant_CCKSwingIdx= Final_OFDM_Swing_Index - PwrTrackingLimit; // CCK Follow the same compensate value as Path A
  221. pDM_Odm->Remnant_OFDMSwingIdx[RFPath] = Final_OFDM_Swing_Index - PwrTrackingLimit;
  222. ODM_SetBBReg(pDM_Odm, rA_TxScale_Jaguar, 0xFFE00000, TxScalingTable_Jaguar[PwrTrackingLimit]);
  223. pDM_Odm->Modify_TxAGC_Flag_PathA= TRUE;
  224. //Set TxAGC Page C{};
  225. //Adapter->HalFunc.SetTxPowerLevelHandler(Adapter, pHalData->CurrentChannel);
  226. PHY_SetTxPowerLevel8812(Adapter, pHalData->CurrentChannel);
  227. 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]));
  228. }
  229. else if (Final_OFDM_Swing_Index < 0)
  230. {
  231. pDM_Odm->Remnant_CCKSwingIdx= Final_OFDM_Swing_Index; // CCK Follow the same compensate value as Path A
  232. pDM_Odm->Remnant_OFDMSwingIdx[RFPath] = Final_OFDM_Swing_Index;
  233. ODM_SetBBReg(pDM_Odm, rA_TxScale_Jaguar, 0xFFE00000, TxScalingTable_Jaguar[0]);
  234. pDM_Odm->Modify_TxAGC_Flag_PathA= TRUE;
  235. //Set TxAGC Page C{};
  236. //Adapter->HalFunc.SetTxPowerLevelHandler(Adapter, pHalData->CurrentChannel);
  237. PHY_SetTxPowerLevel8812(Adapter, pHalData->CurrentChannel);
  238. 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]));
  239. }
  240. else
  241. {
  242. ODM_SetBBReg(pDM_Odm, rA_TxScale_Jaguar, 0xFFE00000, TxScalingTable_Jaguar[Final_OFDM_Swing_Index]);
  243. 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));
  244. if(pDM_Odm->Modify_TxAGC_Flag_PathA) //If TxAGC has changed, reset TxAGC again
  245. {
  246. pDM_Odm->Remnant_CCKSwingIdx= 0;
  247. pDM_Odm->Remnant_OFDMSwingIdx[RFPath] = 0;
  248. //Set TxAGC Page C{};
  249. //Adapter->HalFunc.SetTxPowerLevelHandler(Adapter, pHalData->CurrentChannel);
  250. PHY_SetTxPowerLevel8812(Adapter, pHalData->CurrentChannel);
  251. pDM_Odm->Modify_TxAGC_Flag_PathA= FALSE;
  252. ODM_RT_TRACE(pDM_Odm,ODM_COMP_TX_PWR_TRACK, ODM_DBG_LOUD,("******Path_A pDM_Odm->Modify_TxAGC_Flag = FALSE \n"));
  253. }
  254. }
  255. }
  256. if (RFPath == ODM_RF_PATH_B)
  257. {
  258. if(Final_OFDM_Swing_Index > PwrTrackingLimit) //BBSwing higher then Limit
  259. {
  260. pDM_Odm->Remnant_OFDMSwingIdx[RFPath] = Final_OFDM_Swing_Index - PwrTrackingLimit;
  261. ODM_SetBBReg(pDM_Odm, rB_TxScale_Jaguar, 0xFFE00000, TxScalingTable_Jaguar[PwrTrackingLimit]);
  262. pDM_Odm->Modify_TxAGC_Flag_PathB= TRUE;
  263. //Set TxAGC Page E{};
  264. ODM_RT_TRACE(pDM_Odm,ODM_COMP_TX_PWR_TRACK, ODM_DBG_LOUD,("******Path_B Over BBSwing Limit , PwrTrackingLimit = %d , Remnant TxAGC Value = %d \n", PwrTrackingLimit, pDM_Odm->Remnant_OFDMSwingIdx[RFPath]));
  265. }
  266. else if (Final_OFDM_Swing_Index < 0)
  267. {
  268. pDM_Odm->Remnant_OFDMSwingIdx[RFPath] = Final_OFDM_Swing_Index;
  269. ODM_SetBBReg(pDM_Odm, rB_TxScale_Jaguar, 0xFFE00000, TxScalingTable_Jaguar[0]);
  270. pDM_Odm->Modify_TxAGC_Flag_PathB = TRUE;
  271. //Set TxAGC Page E{};
  272. ODM_RT_TRACE(pDM_Odm,ODM_COMP_TX_PWR_TRACK, ODM_DBG_LOUD,("******Path_B Lower then BBSwing lower bound 0 , Remnant TxAGC Value = %d \n", pDM_Odm->Remnant_OFDMSwingIdx[RFPath]));
  273. }
  274. else
  275. {
  276. ODM_SetBBReg(pDM_Odm, rB_TxScale_Jaguar, 0xFFE00000, TxScalingTable_Jaguar[Final_OFDM_Swing_Index]);
  277. ODM_RT_TRACE(pDM_Odm,ODM_COMP_TX_PWR_TRACK, ODM_DBG_LOUD,("******Path_B Compensate with BBSwing , Final_OFDM_Swing_Index = %d \n", Final_OFDM_Swing_Index));
  278. if(pDM_Odm->Modify_TxAGC_Flag_PathB) //If TxAGC has changed, reset TxAGC again
  279. {
  280. pDM_Odm->Remnant_CCKSwingIdx= 0;
  281. pDM_Odm->Remnant_OFDMSwingIdx[RFPath] = 0;
  282. //Set TxAGC Page E{};
  283. pDM_Odm->Modify_TxAGC_Flag_PathB = FALSE;
  284. ODM_RT_TRACE(pDM_Odm,ODM_COMP_TX_PWR_TRACK, ODM_DBG_LOUD,("******Path_B pDM_Odm->Modify_TxAGC_Flag = FALSE \n"));
  285. }
  286. }
  287. }
  288. }
  289. else
  290. {
  291. return;
  292. }
  293. }
  294. VOID
  295. GetDeltaSwingTable_8812A(
  296. IN PDM_ODM_T pDM_Odm,
  297. OUT pu1Byte *TemperatureUP_A,
  298. OUT pu1Byte *TemperatureDOWN_A,
  299. OUT pu1Byte *TemperatureUP_B,
  300. OUT pu1Byte *TemperatureDOWN_B
  301. )
  302. {
  303. PADAPTER Adapter = pDM_Odm->Adapter;
  304. PODM_RF_CAL_T pRFCalibrateInfo = &(pDM_Odm->RFCalibrateInfo);
  305. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  306. u2Byte rate = *(pDM_Odm->pForcedDataRate);
  307. u1Byte channel = pHalData->CurrentChannel;
  308. if ( 1 <= channel && channel <= 14) {
  309. if (IS_CCK_RATE(rate)) {
  310. *TemperatureUP_A = pRFCalibrateInfo->DeltaSwingTableIdx_2GCCKA_P;
  311. *TemperatureDOWN_A = pRFCalibrateInfo->DeltaSwingTableIdx_2GCCKA_N;
  312. *TemperatureUP_B = pRFCalibrateInfo->DeltaSwingTableIdx_2GCCKB_P;
  313. *TemperatureDOWN_B = pRFCalibrateInfo->DeltaSwingTableIdx_2GCCKB_N;
  314. } else {
  315. *TemperatureUP_A = pRFCalibrateInfo->DeltaSwingTableIdx_2GA_P;
  316. *TemperatureDOWN_A = pRFCalibrateInfo->DeltaSwingTableIdx_2GA_N;
  317. *TemperatureUP_B = pRFCalibrateInfo->DeltaSwingTableIdx_2GB_P;
  318. *TemperatureDOWN_B = pRFCalibrateInfo->DeltaSwingTableIdx_2GB_N;
  319. }
  320. } else if ( 36 <= channel && channel <= 64) {
  321. *TemperatureUP_A = pRFCalibrateInfo->DeltaSwingTableIdx_5GA_P[0];
  322. *TemperatureDOWN_A = pRFCalibrateInfo->DeltaSwingTableIdx_5GA_N[0];
  323. *TemperatureUP_B = pRFCalibrateInfo->DeltaSwingTableIdx_5GB_P[0];
  324. *TemperatureDOWN_B = pRFCalibrateInfo->DeltaSwingTableIdx_5GB_N[0];
  325. } else if ( 100 <= channel && channel <= 140) {
  326. *TemperatureUP_A = pRFCalibrateInfo->DeltaSwingTableIdx_5GA_P[1];
  327. *TemperatureDOWN_A = pRFCalibrateInfo->DeltaSwingTableIdx_5GA_N[1];
  328. *TemperatureUP_B = pRFCalibrateInfo->DeltaSwingTableIdx_5GB_P[1];
  329. *TemperatureDOWN_B = pRFCalibrateInfo->DeltaSwingTableIdx_5GB_N[1];
  330. } else if ( 149 <= channel && channel <= 173) {
  331. *TemperatureUP_A = pRFCalibrateInfo->DeltaSwingTableIdx_5GA_P[2];
  332. *TemperatureDOWN_A = pRFCalibrateInfo->DeltaSwingTableIdx_5GA_N[2];
  333. *TemperatureUP_B = pRFCalibrateInfo->DeltaSwingTableIdx_5GB_P[2];
  334. *TemperatureDOWN_B = pRFCalibrateInfo->DeltaSwingTableIdx_5GB_N[2];
  335. } else {
  336. *TemperatureUP_A = (pu1Byte)DeltaSwingTableIdx_2GA_P_8188E;
  337. *TemperatureDOWN_A = (pu1Byte)DeltaSwingTableIdx_2GA_N_8188E;
  338. *TemperatureUP_B = (pu1Byte)DeltaSwingTableIdx_2GA_P_8188E;
  339. *TemperatureDOWN_B = (pu1Byte)DeltaSwingTableIdx_2GA_N_8188E;
  340. }
  341. return;
  342. }
  343. void ConfigureTxpowerTrack_8812A(
  344. PTXPWRTRACK_CFG pConfig
  345. )
  346. {
  347. pConfig->SwingTableSize_CCK = TXSCALE_TABLE_SIZE;
  348. pConfig->SwingTableSize_OFDM = TXSCALE_TABLE_SIZE;
  349. pConfig->Threshold_IQK = IQK_THRESHOLD;
  350. pConfig->AverageThermalNum = AVG_THERMAL_NUM_8812A;
  351. pConfig->RfPathCount = MAX_PATH_NUM_8812A;
  352. pConfig->ThermalRegAddr = RF_T_METER_8812A;
  353. pConfig->ODM_TxPwrTrackSetPwr = ODM_TxPwrTrackSetPwr8812A;
  354. pConfig->DoIQK = DoIQK_8812A;
  355. pConfig->PHY_LCCalibrate = PHY_LCCalibrate_8812A;
  356. pConfig->GetDeltaSwingTable = GetDeltaSwingTable_8812A;
  357. }
  358. //
  359. // 2011/07/26 MH Add an API for testing IQK fail case.
  360. //
  361. // MP Already declare in odm.c
  362. #if !(DM_ODM_SUPPORT_TYPE & ODM_WIN)
  363. BOOLEAN
  364. ODM_CheckPowerStatus(
  365. IN PADAPTER Adapter)
  366. {
  367. /*
  368. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
  369. PDM_ODM_T pDM_Odm = &pHalData->DM_OutSrc;
  370. RT_RF_POWER_STATE rtState;
  371. PMGNT_INFO pMgntInfo = &(Adapter->MgntInfo);
  372. // 2011/07/27 MH We are not testing ready~~!! We may fail to get correct value when init sequence.
  373. if (pMgntInfo->init_adpt_in_progress == TRUE)
  374. {
  375. ODM_RT_TRACE(pDM_Odm,COMP_INIT, DBG_LOUD, ("ODM_CheckPowerStatus Return TRUE, due to initadapter"));
  376. return TRUE;
  377. }
  378. //
  379. // 2011/07/19 MH We can not execute tx pwoer tracking/ LLC calibrate or IQK.
  380. //
  381. Adapter->HalFunc.GetHwRegHandler(Adapter, HW_VAR_RF_STATE, (pu1Byte)(&rtState));
  382. if(Adapter->bDriverStopped || Adapter->bDriverIsGoingToPnpSetPowerSleep || rtState == eRfOff)
  383. {
  384. ODM_RT_TRACE(pDM_Odm,COMP_INIT, DBG_LOUD, ("ODM_CheckPowerStatus Return FALSE, due to %d/%d/%d\n",
  385. Adapter->bDriverStopped, Adapter->bDriverIsGoingToPnpSetPowerSleep, rtState));
  386. return FALSE;
  387. }
  388. */
  389. return TRUE;
  390. }
  391. #endif
  392. #define BW_20M 0
  393. #define BW_40M 1
  394. #define BW_80M 2
  395. void _IQK_RX_FillIQC_8812A(
  396. IN PDM_ODM_T pDM_Odm,
  397. IN ODM_RF_RADIO_PATH_E Path,
  398. IN unsigned int RX_X,
  399. IN unsigned int RX_Y
  400. )
  401. {
  402. switch (Path) {
  403. case ODM_RF_PATH_A:
  404. {
  405. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  406. if (RX_X>>1 ==0x112 || RX_Y>>1 == 0x3ee){
  407. ODM_SetBBReg(pDM_Odm, 0xc10, 0x000003ff, 0x100);
  408. ODM_SetBBReg(pDM_Odm, 0xc10, 0x03ff0000, 0);
  409. ODM_RT_TRACE(pDM_Odm,ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("RX_X = %x;;RX_Y = %x ====>fill to IQC\n", RX_X>>1&0x000003ff, RX_Y>>1&0x000003ff));
  410. }
  411. else{
  412. ODM_SetBBReg(pDM_Odm, 0xc10, 0x000003ff, RX_X>>1);
  413. ODM_SetBBReg(pDM_Odm, 0xc10, 0x03ff0000, RX_Y>>1);
  414. ODM_RT_TRACE(pDM_Odm,ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("RX_X = %x;;RX_Y = %x ====>fill to IQC\n", RX_X>>1&0x000003ff, RX_Y>>1&0x000003ff));
  415. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("0xc10 = %x ====>fill to IQC\n", ODM_Read4Byte(pDM_Odm, 0xc10)));
  416. }
  417. }
  418. break;
  419. case ODM_RF_PATH_B:
  420. {
  421. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  422. if (RX_X>>1 ==0x112 || RX_Y>>1 == 0x3ee){
  423. ODM_SetBBReg(pDM_Odm, 0xe10, 0x000003ff, 0x100);
  424. ODM_SetBBReg(pDM_Odm, 0xe10, 0x03ff0000, 0);
  425. ODM_RT_TRACE(pDM_Odm,ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("RX_X = %x;;RX_Y = %x ====>fill to IQC\n", RX_X>>1&0x000003ff, RX_Y>>1&0x000003ff));
  426. }
  427. else{
  428. ODM_SetBBReg(pDM_Odm, 0xe10, 0x000003ff, RX_X>>1);
  429. ODM_SetBBReg(pDM_Odm, 0xe10, 0x03ff0000, RX_Y>>1);
  430. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("RX_X = %x;;RX_Y = %x====>fill to IQC\n ", RX_X>>1&0x000003ff, RX_Y>>1&0x000003ff));
  431. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("0xe10 = %x====>fill to IQC\n", ODM_Read4Byte(pDM_Odm, 0xe10)));
  432. }
  433. }
  434. break;
  435. default:
  436. break;
  437. };
  438. }
  439. void _IQK_TX_FillIQC_8812A(
  440. IN PDM_ODM_T pDM_Odm,
  441. IN ODM_RF_RADIO_PATH_E Path,
  442. IN unsigned int TX_X,
  443. IN unsigned int TX_Y
  444. )
  445. {
  446. switch (Path) {
  447. case ODM_RF_PATH_A:
  448. {
  449. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x1); // [31] = 1 --> Page C1
  450. ODM_Write4Byte(pDM_Odm, 0xc90, 0x00000080);
  451. ODM_Write4Byte(pDM_Odm, 0xcc4, 0x20040000);
  452. ODM_Write4Byte(pDM_Odm, 0xcc8, 0x20000000);
  453. ODM_SetBBReg(pDM_Odm, 0xccc, 0x000007ff, TX_Y);
  454. ODM_SetBBReg(pDM_Odm, 0xcd4, 0x000007ff, TX_X);
  455. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("TX_X = %x;;TX_Y = %x =====> fill to IQC\n", TX_X&0x000007ff, TX_Y&0x000007ff));
  456. 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)));
  457. }
  458. break;
  459. case ODM_RF_PATH_B:
  460. {
  461. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x1); // [31] = 1 --> Page C1
  462. ODM_Write4Byte(pDM_Odm, 0xe90, 0x00000080);
  463. ODM_Write4Byte(pDM_Odm, 0xec4, 0x20040000);
  464. ODM_Write4Byte(pDM_Odm, 0xec8, 0x20000000);
  465. ODM_SetBBReg(pDM_Odm, 0xecc, 0x000007ff, TX_Y);
  466. ODM_SetBBReg(pDM_Odm, 0xed4, 0x000007ff, TX_X);
  467. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("TX_X = %x;;TX_Y = %x =====> fill to IQC\n", TX_X&0x000007ff, TX_Y&0x000007ff));
  468. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("0xed4 = %x;;0xecc = %x ====>fill to IQC\n", ODM_GetBBReg(pDM_Odm, 0xed4, 0x000007ff), ODM_GetBBReg(pDM_Odm, 0xecc, 0x000007ff)));
  469. }
  470. break;
  471. default:
  472. break;
  473. };
  474. }
  475. void _IQK_BackupMacBB_8812A(
  476. IN PDM_ODM_T pDM_Odm,
  477. IN pu4Byte MACBB_backup,
  478. IN pu4Byte Backup_MACBB_REG,
  479. IN u4Byte MACBB_NUM
  480. )
  481. {
  482. u4Byte i;
  483. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  484. //save MACBB default value
  485. for (i = 0; i < MACBB_NUM; i++){
  486. MACBB_backup[i] = ODM_Read4Byte(pDM_Odm, Backup_MACBB_REG[i]);
  487. }
  488. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("BackupMacBB Success!!!!\n"));
  489. }
  490. void _IQK_BackupRF_8812A(
  491. IN PDM_ODM_T pDM_Odm,
  492. IN pu4Byte RFA_backup,
  493. IN pu4Byte RFB_backup,
  494. IN pu4Byte Backup_RF_REG,
  495. IN u4Byte RF_NUM
  496. )
  497. {
  498. u4Byte i;
  499. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  500. //Save RF Parameters
  501. for (i = 0; i < RF_NUM; i++){
  502. RFA_backup[i] = ODM_GetRFReg(pDM_Odm, ODM_RF_PATH_A, Backup_RF_REG[i], bMaskDWord);
  503. RFB_backup[i] = ODM_GetRFReg(pDM_Odm, ODM_RF_PATH_B, Backup_RF_REG[i], bMaskDWord);
  504. }
  505. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("BackupRF Success!!!!\n"));
  506. }
  507. void _IQK_BackupAFE_8812A(
  508. IN PDM_ODM_T pDM_Odm,
  509. IN pu4Byte AFE_backup,
  510. IN pu4Byte Backup_AFE_REG,
  511. IN u4Byte AFE_NUM
  512. )
  513. {
  514. u4Byte i;
  515. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  516. //Save AFE Parameters
  517. for (i = 0; i < AFE_NUM; i++){
  518. AFE_backup[i] = ODM_Read4Byte(pDM_Odm, Backup_AFE_REG[i]);
  519. }
  520. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("BackupAFE Success!!!!\n"));
  521. }
  522. void _IQK_RestoreMacBB_8812A(
  523. IN PDM_ODM_T pDM_Odm,
  524. IN pu4Byte MACBB_backup,
  525. IN pu4Byte Backup_MACBB_REG,
  526. IN u4Byte MACBB_NUM
  527. )
  528. {
  529. u4Byte i;
  530. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  531. //Reload MacBB Parameters
  532. for (i = 0; i < MACBB_NUM; i++){
  533. ODM_Write4Byte(pDM_Odm, Backup_MACBB_REG[i], MACBB_backup[i]);
  534. }
  535. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("RestoreMacBB Success!!!!\n"));
  536. }
  537. void _IQK_RestoreRF_8812A(
  538. IN PDM_ODM_T pDM_Odm,
  539. IN ODM_RF_RADIO_PATH_E Path,
  540. IN pu4Byte Backup_RF_REG,
  541. IN pu4Byte RF_backup,
  542. IN u4Byte RF_REG_NUM
  543. )
  544. {
  545. u4Byte i;
  546. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  547. for (i = 0; i < RF_REG_NUM; i++)
  548. ODM_SetRFReg(pDM_Odm, Path, Backup_RF_REG[i], bRFRegOffsetMask, RF_backup[i]);
  549. ODM_SetRFReg(pDM_Odm, Path, 0xef, bRFRegOffsetMask, 0x0);
  550. switch(Path){
  551. case ODM_RF_PATH_A:
  552. {
  553. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("RestoreRF Path A Success!!!!\n"));
  554. }
  555. break;
  556. case ODM_RF_PATH_B:
  557. {
  558. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("RestoreRF Path B Success!!!!\n"));
  559. }
  560. break;
  561. default:
  562. break;
  563. }
  564. }
  565. void _IQK_RestoreAFE_8812A(
  566. IN PDM_ODM_T pDM_Odm,
  567. IN pu4Byte AFE_backup,
  568. IN pu4Byte Backup_AFE_REG,
  569. IN u4Byte AFE_NUM
  570. )
  571. {
  572. u4Byte i;
  573. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  574. //Reload AFE Parameters
  575. for (i = 0; i < AFE_NUM; i++){
  576. ODM_Write4Byte(pDM_Odm, Backup_AFE_REG[i], AFE_backup[i]);
  577. }
  578. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x1); // [31] = 1 --> Page C1
  579. ODM_Write4Byte(pDM_Odm, 0xc80, 0x0);
  580. ODM_Write4Byte(pDM_Odm, 0xc84, 0x0);
  581. ODM_Write4Byte(pDM_Odm, 0xc88, 0x0);
  582. ODM_Write4Byte(pDM_Odm, 0xc8c, 0x3c000000);
  583. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x0);
  584. ODM_Write4Byte(pDM_Odm, 0xe80, 0x0);
  585. ODM_Write4Byte(pDM_Odm, 0xe84, 0x0);
  586. ODM_Write4Byte(pDM_Odm, 0xe88, 0x0);
  587. ODM_Write4Byte(pDM_Odm, 0xe8c, 0x3c000000);
  588. ODM_Write4Byte(pDM_Odm, 0xeb8, 0x0);
  589. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("RestoreAFE Success!!!!\n"));
  590. }
  591. void _IQK_ConfigureMAC_8812A(
  592. IN PDM_ODM_T pDM_Odm
  593. )
  594. {
  595. // ========MAC register setting========
  596. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  597. ODM_Write1Byte(pDM_Odm, 0x522, 0x3f);
  598. ODM_SetBBReg(pDM_Odm, 0x550, BIT(11)|BIT(3), 0x0);
  599. ODM_SetBBReg(pDM_Odm, 0x808, BIT(28), 0x0); // CCK Off
  600. ODM_Write1Byte(pDM_Odm, 0x808, 0x00); // RX ante off
  601. ODM_SetBBReg(pDM_Odm, 0x838, 0xf, 0xc); // CCA off
  602. }
  603. #define cal_num 3
  604. void _IQK_Tx_8812A(
  605. IN PDM_ODM_T pDM_Odm,
  606. IN ODM_RF_RADIO_PATH_E Path,
  607. IN u1Byte chnlIdx
  608. )
  609. {
  610. u4Byte TX_fail,RX_fail, delay_count, IQK_ready, cal_retry, cal = 0, temp_reg65;
  611. int TX_X = 0, TX_Y = 0, RX_X = 0, RX_Y = 0, TX_Average = 0, RX_Average = 0;
  612. int TX_X0[cal_num], TX_Y0[cal_num], RX_X0[cal_num], RX_Y0[cal_num];
  613. BOOLEAN TX0IQKOK = FALSE, RX0IQKOK = FALSE;
  614. int TX_X1[cal_num], TX_Y1[cal_num], RX_X1[cal_num], RX_Y1[cal_num];
  615. BOOLEAN TX1IQKOK = FALSE, RX1IQKOK = FALSE, VDF_enable = FALSE;
  616. 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, dt = 0;
  617. PODM_RF_CAL_T pRFCalibrateInfo = &(pDM_Odm->RFCalibrateInfo);
  618. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("BandWidth = %d, ExtPA5G = %d, ExtPA2G = %d\n", *pDM_Odm->pBandWidth, pDM_Odm->ExtPA5G, pDM_Odm->ExtPA));
  619. if (*pDM_Odm->pBandWidth == 2){
  620. VDF_enable = TRUE;
  621. }
  622. VDF_enable = FALSE;
  623. temp_reg65 = ODM_GetRFReg(pDM_Odm, Path, 0x65, bMaskDWord);
  624. switch(Path){
  625. case ODM_RF_PATH_A:
  626. {
  627. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  628. // ========Path-A AFE all on========
  629. // Port 0 DAC/ADC on
  630. ODM_Write4Byte(pDM_Odm, 0xc60, 0x77777777);
  631. ODM_Write4Byte(pDM_Odm, 0xc64, 0x77777777);
  632. // Port 1 DAC/ADC off
  633. ODM_Write4Byte(pDM_Odm, 0xe60, 0x00000000);
  634. ODM_Write4Byte(pDM_Odm, 0xe64, 0x00000000);
  635. ODM_Write4Byte(pDM_Odm, 0xc68, 0x19791979);
  636. ODM_SetBBReg(pDM_Odm, 0xc00, 0xf, 0x4);// hardware 3-wire off
  637. // DAC/ADC sampling rate (160 MHz)
  638. ODM_SetBBReg(pDM_Odm, 0xc5c, BIT(26)|BIT(25)|BIT(24), 0x7);
  639. ODM_SetBBReg(pDM_Odm, 0x8c4, BIT(30), 0x1);
  640. //ODM_SetBBReg(pDM_Odm, 0xcb0, 0x00ff0000, 0x77);
  641. //ODM_SetBBReg(pDM_Odm, 0xcb4, 0x03000000, 0x0);
  642. }
  643. break;
  644. case ODM_RF_PATH_B:
  645. {ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  646. // ========Path-B AFE all on========
  647. // Port 0 DAC/ADC off
  648. ODM_Write4Byte(pDM_Odm, 0xc60, 0x00000000);
  649. ODM_Write4Byte(pDM_Odm, 0xc64, 0x00000000);
  650. // Port 1 DAC/ADC on
  651. ODM_Write4Byte(pDM_Odm, 0xe60, 0x77777777);
  652. ODM_Write4Byte(pDM_Odm, 0xe64, 0x77777777);
  653. ODM_Write4Byte(pDM_Odm, 0xe68, 0x19791979);
  654. ODM_SetBBReg(pDM_Odm, 0xe00, 0xf, 0x4);// hardware 3-wire off
  655. // DAC/ADC sampling rate (160 MHz)
  656. ODM_SetBBReg(pDM_Odm, 0xe5c, BIT(26)|BIT(25)|BIT(24), 0x7);
  657. ODM_SetBBReg(pDM_Odm, 0x8c4, BIT(30), 0x1);
  658. //ODM_SetBBReg(pDM_Odm, 0xeb0, 0x00ff0000, 0x77);
  659. //ODM_SetBBReg(pDM_Odm, 0xeb4, 0x03000000, 0x0);
  660. }
  661. break;
  662. default:
  663. break;
  664. }
  665. switch (Path) {
  666. case ODM_RF_PATH_A:
  667. {
  668. //====== TX IQK ======
  669. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  670. ODM_SetRFReg(pDM_Odm, Path, 0xef, bRFRegOffsetMask, 0x80002);
  671. ODM_SetRFReg(pDM_Odm, Path, 0x30, bRFRegOffsetMask, 0x20000);
  672. ODM_SetRFReg(pDM_Odm, Path, 0x31, bRFRegOffsetMask, 0x3fffd);
  673. ODM_SetRFReg(pDM_Odm, Path, 0x32, bRFRegOffsetMask, 0xfe83f);
  674. ODM_SetRFReg(pDM_Odm, Path, 0x65, bRFRegOffsetMask, 0x931d5);
  675. ODM_SetRFReg(pDM_Odm, Path, 0x8f, bRFRegOffsetMask, 0x8a001);
  676. ODM_Write4Byte(pDM_Odm, 0x90c, 0x00008000);
  677. ODM_Write4Byte(pDM_Odm, 0xb00, 0x03000100);
  678. ODM_SetBBReg(pDM_Odm, 0xc94, BIT(0), 0x1);
  679. ODM_Write4Byte(pDM_Odm, 0x978, 0x29002000);// TX (X,Y)
  680. ODM_Write4Byte(pDM_Odm, 0x97c, 0xa9002000);// RX (X,Y)
  681. ODM_Write4Byte(pDM_Odm, 0x984, 0x00462910);// [0]:AGC_en, [15]:idac_K_Mask
  682. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x1); // [31] = 1 --> Page C1
  683. if (pDM_Odm->ExtPA5G)
  684. ODM_Write4Byte(pDM_Odm, 0xc88, 0x821403f7);
  685. else
  686. ODM_Write4Byte(pDM_Odm, 0xc88, 0x821403f1);
  687. if (*pDM_Odm->pBandType)
  688. ODM_Write4Byte(pDM_Odm, 0xc8c, 0x68163e96);
  689. else{
  690. ODM_Write4Byte(pDM_Odm, 0xc8c, 0x28163e96);
  691. if (pDM_Odm->RFEType == 3)
  692. { if (pDM_Odm->ExtPA)
  693. ODM_Write4Byte(pDM_Odm, 0xc88, 0x821403e3);
  694. else
  695. ODM_Write4Byte(pDM_Odm, 0xc88, 0x821403f7);
  696. }
  697. }
  698. if (VDF_enable == 1){
  699. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("TXVDF Start\n"));
  700. for (k = 0;k <= 2; k++){
  701. switch (k){
  702. case 0:
  703. {
  704. ODM_Write4Byte(pDM_Odm, 0xc80, 0x18008c38);// TX_Tone_idx[9:0], TxK_Mask[29] TX_Tone = 16
  705. ODM_Write4Byte(pDM_Odm, 0xc84, 0x38008c38);// RX_Tone_idx[9:0], RxK_Mask[29]
  706. ODM_Write4Byte(pDM_Odm, 0x984, 0x00462910);// [0]:AGC_en, [15]:idac_K_Mask
  707. ODM_SetBBReg(pDM_Odm, 0xce8, BIT(31), 0x0);
  708. }
  709. break;
  710. case 1:
  711. {
  712. ODM_SetBBReg(pDM_Odm, 0xc80, BIT(28), 0x0);
  713. ODM_SetBBReg(pDM_Odm, 0xc84, BIT(28), 0x0);
  714. ODM_Write4Byte(pDM_Odm, 0x984, 0x0046a910);// [0]:AGC_en, [15]:idac_K_Mask
  715. }
  716. break;
  717. case 2:
  718. {
  719. 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));
  720. 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));
  721. Tx_dt[cal] = (VDF_Y[1]>>20)-(VDF_Y[0]>>20);
  722. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("Tx_dt = %d\n", Tx_dt[cal]));
  723. Tx_dt[cal] = ((16*Tx_dt[cal])*10000/15708);
  724. Tx_dt[cal] = (Tx_dt[cal] >> 1 )+(Tx_dt[cal] & BIT(0));
  725. ODM_Write4Byte(pDM_Odm, 0xc80, 0x18008c20);// TX_Tone_idx[9:0], TxK_Mask[29] TX_Tone = 16
  726. ODM_Write4Byte(pDM_Odm, 0xc84, 0x38008c20);// RX_Tone_idx[9:0], RxK_Mask[29]
  727. ODM_SetBBReg(pDM_Odm, 0xce8, BIT(31), 0x1);
  728. ODM_SetBBReg(pDM_Odm, 0xce8, 0x3fff0000, Tx_dt[cal] & 0x00003fff);
  729. }
  730. break;
  731. default:
  732. break;
  733. }
  734. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x00100000);// cb8[20] 將 SI/PI 使用權切給 iqk_dpk module
  735. cal_retry = 0;
  736. while(1){
  737. // one shot
  738. ODM_Write4Byte(pDM_Odm, 0x980, 0xfa000000);
  739. ODM_Write4Byte(pDM_Odm, 0x980, 0xf8000000);
  740. ODM_delay_ms(10); //Delay 10ms
  741. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x00000000);
  742. delay_count = 0;
  743. while (1){
  744. IQK_ready = ODM_GetBBReg(pDM_Odm, 0xd00, BIT(10));
  745. if ((IQK_ready) || (delay_count>20)){
  746. break;
  747. }
  748. else{
  749. ODM_delay_ms(1);
  750. delay_count++;
  751. }
  752. }
  753. if (delay_count < 20){ // If 20ms No Result, then cal_retry++
  754. // ============TXIQK Check==============
  755. TX_fail = ODM_GetBBReg(pDM_Odm, 0xd00, BIT(12));
  756. if (~TX_fail){
  757. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x02000000);
  758. VDF_X[k] = ODM_GetBBReg(pDM_Odm, 0xd00, 0x07ff0000)<<21;
  759. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x04000000);
  760. VDF_Y[k] = ODM_GetBBReg(pDM_Odm, 0xd00, 0x07ff0000)<<21;
  761. TX0IQKOK = TRUE;
  762. break;
  763. }
  764. else{
  765. TX0IQKOK = FALSE;
  766. cal_retry++;
  767. if (cal_retry == 10) {
  768. break;
  769. }
  770. }
  771. }
  772. else{
  773. TX0IQKOK = FALSE;
  774. cal_retry++;
  775. if (cal_retry == 10){
  776. break;
  777. }
  778. }
  779. }
  780. }
  781. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("TXA_VDF_cal_retry = %d\n", cal_retry));
  782. TX_X0[cal] = VDF_X[k-1] ;
  783. TX_Y0[cal] = VDF_Y[k-1];
  784. }
  785. else{
  786. ODM_Write4Byte(pDM_Odm, 0xc80, 0x18008c10);// TX_Tone_idx[9:0], TxK_Mask[29] TX_Tone = 16
  787. ODM_Write4Byte(pDM_Odm, 0xc84, 0x38008c10);// RX_Tone_idx[9:0], RxK_Mask[29]
  788. ODM_Write4Byte(pDM_Odm, 0xce8, 0x00000000);
  789. for(cal = 0; cal < cal_num; cal++){
  790. cal_retry = 0;
  791. while(1){
  792. // one shot
  793. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x00100000);// cb8[20] 將 SI/PI 使用權切給 iqk_dpk module
  794. ODM_Write4Byte(pDM_Odm, 0x980, 0xfa000000);
  795. ODM_Write4Byte(pDM_Odm, 0x980, 0xf8000000);
  796. ODM_delay_ms(10); //Delay 25ms
  797. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x00000000);
  798. delay_count = 0;
  799. while (1){
  800. IQK_ready = ODM_GetBBReg(pDM_Odm, 0xd00, BIT(10));
  801. if ((IQK_ready) || (delay_count>20)) {
  802. break;
  803. }
  804. else{
  805. ODM_delay_ms(1);
  806. delay_count++;
  807. }
  808. }
  809. if (delay_count < 20){ // If 20ms No Result, then cal_retry++
  810. // ============TXIQK Check==============
  811. TX_fail = ODM_GetBBReg(pDM_Odm, 0xd00, BIT(12));
  812. if (~TX_fail){
  813. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x02000000);
  814. TX_X0[cal] = ODM_GetBBReg(pDM_Odm, 0xd00, 0x07ff0000)<<21;
  815. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x04000000);
  816. TX_Y0[cal] = ODM_GetBBReg(pDM_Odm, 0xd00, 0x07ff0000)<<21;
  817. TX0IQKOK = TRUE;
  818. /*
  819. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x01000000);
  820. reg1 = ODM_GetBBReg(pDM_Odm, 0xd00, 0xffffffff);
  821. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x02000000);
  822. reg2 = ODM_GetBBReg(pDM_Odm, 0xd00, 0x0000001f);
  823. Image_Power = (reg2<<32)+reg1;
  824. DbgPrint("Before PW = %d\n", Image_Power);
  825. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x03000000);
  826. reg1 = ODM_GetBBReg(pDM_Odm, 0xd00, 0xffffffff);
  827. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x04000000);
  828. reg2 = ODM_GetBBReg(pDM_Odm, 0xd00, 0x0000001f);
  829. Image_Power = (reg2<<32)+reg1;
  830. DbgPrint("After PW = %d\n", Image_Power);
  831. */
  832. break;
  833. }
  834. else{
  835. TX0IQKOK = FALSE;
  836. cal_retry++;
  837. if (cal_retry == 10) {
  838. break;
  839. }
  840. }
  841. }
  842. else{
  843. TX0IQKOK = FALSE;
  844. cal_retry++;
  845. if (cal_retry == 10)
  846. break;
  847. }
  848. }
  849. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("TXA_cal_retry = %d\n", cal_retry));
  850. if (TX0IQKOK)
  851. TX_Average++;
  852. }
  853. }
  854. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  855. ODM_SetRFReg(pDM_Odm, Path, 0x58, 0x7fe00, ODM_GetRFReg(pDM_Odm, Path, 0x8, 0xffc00)); // Load LOK
  856. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x1); // [31] = 1 --> Page C1
  857. if (TX0IQKOK == FALSE)
  858. break; // TXK fail, Don't do RXK
  859. if (VDF_enable == 1){
  860. ODM_SetBBReg(pDM_Odm, 0xce8, BIT(31), 0x0); // TX VDF Disable
  861. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("RXVDF Start\n"));
  862. //====== RX IQK ======
  863. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  864. ODM_SetRFReg(pDM_Odm, Path, 0xef, bRFRegOffsetMask, 0x80000);
  865. ODM_SetRFReg(pDM_Odm, Path, 0x30, bRFRegOffsetMask, 0x30000);
  866. ODM_SetRFReg(pDM_Odm, Path, 0x31, bRFRegOffsetMask, 0x3f7ff);
  867. ODM_SetRFReg(pDM_Odm, Path, 0x32, bRFRegOffsetMask, 0xfe7bf);
  868. ODM_SetRFReg(pDM_Odm, Path, 0x8f, bRFRegOffsetMask, 0x88001);
  869. ODM_SetRFReg(pDM_Odm, Path, 0x65, bRFRegOffsetMask, 0x931d0);
  870. ODM_SetRFReg(pDM_Odm, Path, 0xef, bRFRegOffsetMask, 0x00000);
  871. ODM_SetBBReg(pDM_Odm, 0x978, BIT(31), 0x1);
  872. ODM_SetBBReg(pDM_Odm, 0x97c, BIT(31), 0x0);
  873. ODM_Write4Byte(pDM_Odm, 0x984, 0x0046a911);
  874. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x1); // [31] = 1 --> Page C1
  875. ODM_Write4Byte(pDM_Odm, 0xc88, 0x02140119);
  876. ODM_Write4Byte(pDM_Odm, 0xc8c, 0x28161420);
  877. for (k = 0;k <= 2; k++){
  878. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  879. ODM_SetBBReg(pDM_Odm, 0x978, 0x03FF8000, (VDF_X[k])>>21&0x000007ff);
  880. ODM_SetBBReg(pDM_Odm, 0x978, 0x000007FF, (VDF_Y[k])>>21&0x000007ff);
  881. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x1); // [31] = 1 --> Page C1
  882. switch (k){
  883. case 0:
  884. {
  885. ODM_Write4Byte(pDM_Odm, 0xc80, 0x38008c38);// TX_Tone_idx[9:0], TxK_Mask[29] TX_Tone = 16
  886. ODM_Write4Byte(pDM_Odm, 0xc84, 0x18008c38);// RX_Tone_idx[9:0], RxK_Mask[29]
  887. ODM_SetBBReg(pDM_Odm, 0xce8, BIT(30), 0x0);
  888. }
  889. break;
  890. case 1:
  891. {
  892. ODM_Write4Byte(pDM_Odm, 0xc80, 0x28008c38);// TX_Tone_idx[9:0], TxK_Mask[29] TX_Tone = 16
  893. ODM_Write4Byte(pDM_Odm, 0xc84, 0x08008c38);// RX_Tone_idx[9:0], RxK_Mask[29]
  894. }
  895. break;
  896. case 2:
  897. {
  898. 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));
  899. 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));
  900. Rx_dt[cal] = (VDF_Y[1]>>20)-(VDF_Y[0]>>20);
  901. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("Rx_dt = %d\n", Rx_dt[cal]));
  902. Rx_dt[cal] = ((16*Rx_dt[cal])*10000/13823);
  903. Rx_dt[cal] = (Rx_dt[cal] >> 1 )+(Rx_dt[cal] & BIT(0));
  904. ODM_Write4Byte(pDM_Odm, 0xc80, 0x38008c20);// TX_Tone_idx[9:0], TxK_Mask[29] TX_Tone = 16
  905. ODM_Write4Byte(pDM_Odm, 0xc84, 0x18008c20);// RX_Tone_idx[9:0], RxK_Mask[29]
  906. ODM_SetBBReg(pDM_Odm, 0xce8, 0x00003fff, Rx_dt[cal] & 0x00003fff);
  907. }
  908. break;
  909. default:
  910. break;
  911. }
  912. if (k==2){
  913. ODM_SetBBReg(pDM_Odm, 0xce8, BIT(30), 0x1); //RX VDF Enable
  914. }
  915. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x00100000);// cb8[20] 將 SI/PI 使用權切給 iqk_dpk module
  916. cal_retry = 0;
  917. while(1){
  918. // one shot
  919. ODM_Write4Byte(pDM_Odm, 0x980, 0xfa000000);
  920. ODM_Write4Byte(pDM_Odm, 0x980, 0xf8000000);
  921. ODM_delay_ms(10); //Delay 10ms
  922. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x00000000);
  923. delay_count = 0;
  924. while (1){
  925. IQK_ready = ODM_GetBBReg(pDM_Odm, 0xd00, BIT(10));
  926. if ((IQK_ready)||(delay_count>20)){
  927. break;
  928. }
  929. else{
  930. ODM_delay_ms(1);
  931. delay_count++;
  932. }
  933. }
  934. if (delay_count < 20){ // If 20ms No Result, then cal_retry++
  935. // ============RXIQK Check==============
  936. RX_fail = ODM_GetBBReg(pDM_Odm, 0xd00, BIT(11));
  937. if (RX_fail == 0){
  938. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x06000000);
  939. VDF_X[k] = ODM_GetBBReg(pDM_Odm, 0xd00, 0x07ff0000)<<21;
  940. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x08000000);
  941. VDF_Y[k] = ODM_GetBBReg(pDM_Odm, 0xd00, 0x07ff0000)<<21;
  942. RX0IQKOK = TRUE;
  943. break;
  944. }
  945. else{
  946. ODM_SetBBReg(pDM_Odm, 0xc10, 0x000003ff, 0x200>>1);
  947. ODM_SetBBReg(pDM_Odm, 0xc10, 0x03ff0000, 0x0>>1);
  948. RX0IQKOK = FALSE;
  949. cal_retry++;
  950. if (cal_retry == 10)
  951. break;
  952. }
  953. }
  954. else{
  955. RX0IQKOK = FALSE;
  956. cal_retry++;
  957. if (cal_retry == 10)
  958. break;
  959. }
  960. }
  961. }
  962. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("RXA_VDF_cal_retry = %d\n", cal_retry));
  963. RX_X0[cal] = VDF_X[k-1] ;
  964. RX_Y0[cal] = VDF_Y[k-1];
  965. ODM_SetBBReg(pDM_Odm, 0xce8, BIT(31), 0x1); // TX VDF Enable
  966. }
  967. else{
  968. //====== RX IQK ======
  969. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  970. // 1. RX RF Setting
  971. ODM_SetRFReg(pDM_Odm, Path, 0xef, bRFRegOffsetMask, 0x80000);
  972. ODM_SetRFReg(pDM_Odm, Path, 0x30, bRFRegOffsetMask, 0x30000);
  973. ODM_SetRFReg(pDM_Odm, Path, 0x31, bRFRegOffsetMask, 0x3f7ff);
  974. ODM_SetRFReg(pDM_Odm, Path, 0x32, bRFRegOffsetMask, 0xfe7bf);
  975. ODM_SetRFReg(pDM_Odm, Path, 0x8f, bRFRegOffsetMask, 0x88001);
  976. ODM_SetRFReg(pDM_Odm, Path, 0x65, bRFRegOffsetMask, 0x931d0);
  977. ODM_SetRFReg(pDM_Odm, Path, 0xef, bRFRegOffsetMask, 0x00000);
  978. ODM_SetBBReg(pDM_Odm, 0x978, BIT(31), 0x1);
  979. ODM_SetBBReg(pDM_Odm, 0x97c, BIT(31), 0x0);
  980. ODM_Write4Byte(pDM_Odm, 0x90c, 0x00008000);
  981. //ODM_Write4Byte(pDM_Odm, 0x984, 0x0046a911);
  982. ODM_Write4Byte(pDM_Odm, 0x984, 0x0046a891);
  983. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x1); // [31] = 1 --> Page C1
  984. ODM_Write4Byte(pDM_Odm, 0xc80, 0x38008c10);// TX_Tone_idx[9:0], TxK_Mask[29] TX_Tone = 16
  985. ODM_Write4Byte(pDM_Odm, 0xc84, 0x18008c10);// RX_Tone_idx[9:0], RxK_Mask[29]
  986. ODM_Write4Byte(pDM_Odm, 0xc88, 0x02140119);
  987. ODM_Write4Byte(pDM_Odm, 0xc8c, 0x28160d40);
  988. for(cal = 0; cal < cal_num; cal++){
  989. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  990. ODM_SetBBReg(pDM_Odm, 0x978, 0x03FF8000, (TX_X0[cal])>>21&0x000007ff);
  991. ODM_SetBBReg(pDM_Odm, 0x978, 0x000007FF, (TX_Y0[cal])>>21&0x000007ff);
  992. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x1); // [31] = 1 --> Page C1
  993. cal_retry = 0;
  994. while(1){
  995. // one shot
  996. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x00100000);// cb8[20] 將 SI/PI 使用權切給 iqk_dpk module
  997. ODM_Write4Byte(pDM_Odm, 0x980, 0xfa000000);
  998. ODM_Write4Byte(pDM_Odm, 0x980, 0xf8000000);
  999. ODM_delay_ms(10); //Delay 10ms
  1000. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x00000000);
  1001. delay_count = 0;
  1002. while (1){
  1003. IQK_ready = ODM_GetBBReg(pDM_Odm, 0xd00, BIT(10));
  1004. if ((IQK_ready)||(delay_count>20)){
  1005. break;
  1006. }
  1007. else{
  1008. ODM_delay_ms(1);
  1009. delay_count++;
  1010. }
  1011. }
  1012. if (delay_count < 20){ // If 20ms No Result, then cal_retry++
  1013. // ============RXIQK Check==============
  1014. RX_fail = ODM_GetBBReg(pDM_Odm, 0xd00, BIT(11));
  1015. if (RX_fail == 0){
  1016. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x06000000);
  1017. RX_X0[cal] = ODM_GetBBReg(pDM_Odm, 0xd00, 0x07ff0000)<<21;
  1018. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x08000000);
  1019. RX_Y0[cal] = ODM_GetBBReg(pDM_Odm, 0xd00, 0x07ff0000)<<21;
  1020. RX0IQKOK = TRUE;
  1021. /*
  1022. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x05000000);
  1023. reg1 = ODM_GetBBReg(pDM_Odm, 0xd00, 0xffffffff);
  1024. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x06000000);
  1025. reg2 = ODM_GetBBReg(pDM_Odm, 0xd00, 0x0000001f);
  1026. DbgPrint("reg1 = %d, reg2 = %d", reg1, reg2);
  1027. Image_Power = (reg2<<32)+reg1;
  1028. DbgPrint("Before PW = %d\n", Image_Power);
  1029. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x07000000);
  1030. reg1 = ODM_GetBBReg(pDM_Odm, 0xd00, 0xffffffff);
  1031. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x08000000);
  1032. reg2 = ODM_GetBBReg(pDM_Odm, 0xd00, 0x0000001f);
  1033. Image_Power = (reg2<<32)+reg1;
  1034. DbgPrint("After PW = %d\n", Image_Power);
  1035. */
  1036. break;
  1037. }
  1038. else{
  1039. ODM_SetBBReg(pDM_Odm, 0xc10, 0x000003ff, 0x200>>1);
  1040. ODM_SetBBReg(pDM_Odm, 0xc10, 0x03ff0000, 0x0>>1);
  1041. RX0IQKOK = FALSE;
  1042. cal_retry++;
  1043. if (cal_retry == 10)
  1044. break;
  1045. }
  1046. }
  1047. else{
  1048. RX0IQKOK = FALSE;
  1049. cal_retry++;
  1050. if (cal_retry == 10)
  1051. break;
  1052. }
  1053. }
  1054. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("RXA_cal_retry = %d\n", cal_retry));
  1055. if (RX0IQKOK)
  1056. RX_Average++;
  1057. }
  1058. }
  1059. }
  1060. break;
  1061. case ODM_RF_PATH_B:
  1062. {
  1063. //Path-B TX/RX IQK
  1064. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  1065. ODM_SetRFReg(pDM_Odm, Path, 0xef, bRFRegOffsetMask, 0x80002);
  1066. ODM_SetRFReg(pDM_Odm, Path, 0x30, bRFRegOffsetMask, 0x20000);
  1067. ODM_SetRFReg(pDM_Odm, Path, 0x31, bRFRegOffsetMask, 0x3fffd);
  1068. ODM_SetRFReg(pDM_Odm, Path, 0x32, bRFRegOffsetMask, 0xfe83f);
  1069. ODM_SetRFReg(pDM_Odm, Path, 0x65, bRFRegOffsetMask, 0x931d5);
  1070. ODM_SetRFReg(pDM_Odm, Path, 0x8f, bRFRegOffsetMask, 0x8a001);
  1071. ODM_Write4Byte(pDM_Odm, 0x90c, 0x00008000);
  1072. ODM_Write4Byte(pDM_Odm, 0xb00, 0x03000100);
  1073. ODM_SetBBReg(pDM_Odm, 0xe94, BIT(0), 0x1);
  1074. ODM_Write4Byte(pDM_Odm, 0x978, 0x29002000);// TX (X,Y)
  1075. ODM_Write4Byte(pDM_Odm, 0x97c, 0xa9002000);// RX (X,Y)
  1076. ODM_Write4Byte(pDM_Odm, 0x984, 0x00462910);// [0]:AGC_en, [15]:idac_K_Mask
  1077. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x1); // [31] = 1 --> Page C1
  1078. if (pDM_Odm->ExtPA5G)
  1079. ODM_Write4Byte(pDM_Odm, 0xe88, 0x821403f7);
  1080. else
  1081. ODM_Write4Byte(pDM_Odm, 0xe88, 0x821403f1);
  1082. if (*pDM_Odm->pBandType)
  1083. ODM_Write4Byte(pDM_Odm, 0xe8c, 0x68163e96);
  1084. else
  1085. ODM_Write4Byte(pDM_Odm, 0xe8c, 0x28163e96);
  1086. if (VDF_enable == 1){
  1087. for (k = 0;k <= 2; k++){
  1088. switch (k){
  1089. case 0:
  1090. {
  1091. ODM_Write4Byte(pDM_Odm, 0xe80, 0x18008c38);// TX_Tone_idx[9:0], TxK_Mask[29] TX_Tone = 16
  1092. ODM_Write4Byte(pDM_Odm, 0xe84, 0x38008c38);// RX_Tone_idx[9:0], RxK_Mask[29]
  1093. ODM_Write4Byte(pDM_Odm, 0x984, 0x00462910);
  1094. ODM_SetBBReg(pDM_Odm, 0xee8, BIT(31), 0x0);
  1095. }
  1096. break;
  1097. case 1:
  1098. {
  1099. ODM_SetBBReg(pDM_Odm, 0xe80, BIT(28), 0x0);
  1100. ODM_SetBBReg(pDM_Odm, 0xe84, BIT(28), 0x0);
  1101. ODM_Write4Byte(pDM_Odm, 0x984, 0x0046a910);
  1102. ODM_SetBBReg(pDM_Odm, 0xee8, BIT(31), 0x0);
  1103. }
  1104. break;
  1105. case 2:
  1106. {
  1107. 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));
  1108. 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));
  1109. Tx_dt[cal] = (VDF_Y[1]>>20)-(VDF_Y[0]>>20);
  1110. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("Tx_dt = %d\n", Tx_dt[cal]));
  1111. Tx_dt[cal] = ((16*Tx_dt[cal])*10000/15708);
  1112. Tx_dt[cal] = (Tx_dt[cal] >> 1 )+(Tx_dt[cal] & BIT(0));
  1113. ODM_Write4Byte(pDM_Odm, 0xe80, 0x18008c20);// TX_Tone_idx[9:0], TxK_Mask[29] TX_Tone = 16
  1114. ODM_Write4Byte(pDM_Odm, 0xe84, 0x38008c20);// RX_Tone_idx[9:0], RxK_Mask[29]
  1115. ODM_SetBBReg(pDM_Odm, 0xee8, BIT(31), 0x1);
  1116. ODM_SetBBReg(pDM_Odm, 0xee8, 0x3fff0000, Tx_dt[cal] & 0x00003fff);
  1117. }
  1118. break;
  1119. default:
  1120. break;
  1121. }
  1122. ODM_Write4Byte(pDM_Odm, 0xeb8, 0x00100000);// cb8[20] 將 SI/PI 使用權切給 iqk_dpk module
  1123. cal_retry = 0;
  1124. while(1){
  1125. // one shot
  1126. ODM_Write4Byte(pDM_Odm, 0x980, 0xfa000000);
  1127. ODM_Write4Byte(pDM_Odm, 0x980, 0xf8000000);
  1128. ODM_delay_ms(10); //Delay 10ms
  1129. ODM_Write4Byte(pDM_Odm, 0xeb8, 0x00000000);
  1130. delay_count = 0;
  1131. while (1){
  1132. IQK_ready = ODM_GetBBReg(pDM_Odm, 0xd40, BIT(10));
  1133. if ((IQK_ready) || (delay_count>20)) {
  1134. break;
  1135. }
  1136. else {
  1137. ODM_delay_ms(1);
  1138. delay_count++;
  1139. }
  1140. }
  1141. if (delay_count < 20){ // If 20ms No Result, then cal_retry++
  1142. // ============TXIQK Check==============
  1143. TX_fail = ODM_GetBBReg(pDM_Odm, 0xd40, BIT(12));
  1144. if (~TX_fail){
  1145. ODM_Write4Byte(pDM_Odm, 0xeb8, 0x02000000);
  1146. VDF_X[k] = ODM_GetBBReg(pDM_Odm, 0xd40, 0x07ff0000)<<21;
  1147. ODM_Write4Byte(pDM_Odm, 0xeb8, 0x04000000);
  1148. VDF_Y[k] = ODM_GetBBReg(pDM_Odm, 0xd40, 0x07ff0000)<<21;
  1149. TX1IQKOK = TRUE;
  1150. break;
  1151. }
  1152. else{
  1153. TX1IQKOK = FALSE;
  1154. cal_retry++;
  1155. if (cal_retry == 10) {
  1156. break;
  1157. }
  1158. }
  1159. }
  1160. else{
  1161. TX1IQKOK = FALSE;
  1162. cal_retry++;
  1163. if (cal_retry == 10){
  1164. break;
  1165. }
  1166. }
  1167. }
  1168. }
  1169. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("TXB_VDF_cal_retry = %d\n", cal_retry));
  1170. TX_X1[cal] = VDF_X[k-1] ;
  1171. TX_Y1[cal] = VDF_Y[k-1];
  1172. }
  1173. else{
  1174. ODM_Write4Byte(pDM_Odm, 0xe80, 0x18008c10);// TX_Tone_idx[9:0], TxK_Mask[29] TX_Tone = 16
  1175. ODM_Write4Byte(pDM_Odm, 0xe84, 0x38008c10);// RX_Tone_idx[9:0], RxK_Mask[29]
  1176. ODM_Write4Byte(pDM_Odm, 0xee8, 0x00000000);
  1177. for(cal = 0; cal < cal_num; cal++){
  1178. cal_retry = 0;
  1179. while(1){
  1180. // one shot
  1181. ODM_Write4Byte(pDM_Odm, 0xeb8, 0x00100000);// cb8[20] 將 SI/PI 使用權切給 iqk_dpk module
  1182. ODM_Write4Byte(pDM_Odm, 0x980, 0xfa000000);
  1183. ODM_Write4Byte(pDM_Odm, 0x980, 0xf8000000);
  1184. ODM_delay_ms(10); //Delay 25ms
  1185. ODM_Write4Byte(pDM_Odm, 0xeb8, 0x00000000);
  1186. delay_count = 0;
  1187. while (1){
  1188. IQK_ready = ODM_GetBBReg(pDM_Odm, 0xd40, BIT(10));
  1189. if ((IQK_ready)||(delay_count>20)){
  1190. break;
  1191. }
  1192. else{
  1193. ODM_delay_ms(1);
  1194. delay_count++;
  1195. }
  1196. }
  1197. if (delay_count < 20){ // If 20ms No Result, then cal_retry++
  1198. // ============TXIQK Check==============
  1199. TX_fail = ODM_GetBBReg(pDM_Odm, 0xd40, BIT(12));
  1200. if (~TX_fail){
  1201. ODM_Write4Byte(pDM_Odm, 0xeb8, 0x02000000);
  1202. TX_X1[cal] = ODM_GetBBReg(pDM_Odm, 0xd40, 0x07ff0000)<<21;
  1203. ODM_Write4Byte(pDM_Odm, 0xeb8, 0x04000000);
  1204. TX_Y1[cal] = ODM_GetBBReg(pDM_Odm, 0xd40, 0x07ff0000)<<21;
  1205. TX1IQKOK = TRUE;
  1206. /*
  1207. int reg1 = 0, reg2 = 0, Image_Power = 0;
  1208. ODM_Write4Byte(pDM_Odm, 0xeb8, 0x01000000);
  1209. reg1 = ODM_GetBBReg(pDM_Odm, 0xd40, 0xffffffff);
  1210. ODM_Write4Byte(pDM_Odm, 0xeb8, 0x02000000);
  1211. reg2 = ODM_GetBBReg(pDM_Odm, 0xd40, 0x0000001f);
  1212. Image_Power = (reg2<<32)+reg1;
  1213. DbgPrint("Before PW = %d\n", Image_Power);
  1214. ODM_Write4Byte(pDM_Odm, 0xeb8, 0x03000000);
  1215. reg1 = ODM_GetBBReg(pDM_Odm, 0xd40, 0xffffffff);
  1216. ODM_Write4Byte(pDM_Odm, 0xeb8, 0x04000000);
  1217. reg2 = ODM_GetBBReg(pDM_Odm, 0xd40, 0x0000001f);
  1218. Image_Power = (reg2<<32)+reg1;
  1219. DbgPrint("After PW = %d\n", Image_Power);
  1220. */
  1221. break;
  1222. }
  1223. else{
  1224. TX1IQKOK = FALSE;
  1225. cal_retry++;
  1226. if (cal_retry == 10){
  1227. break;
  1228. }
  1229. }
  1230. }
  1231. else {
  1232. TX1IQKOK = FALSE;
  1233. cal_retry++;
  1234. if (cal_retry == 10){
  1235. break;
  1236. }
  1237. }
  1238. }
  1239. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("TXB_cal_retry = %d\n", cal_retry));
  1240. if (TX1IQKOK)
  1241. TX_Average++;
  1242. }
  1243. }
  1244. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  1245. ODM_SetRFReg(pDM_Odm, Path, 0x58, 0x7fe00, ODM_GetRFReg(pDM_Odm, Path, 0x8, 0xffc00)); // Load LOK
  1246. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x1); // [31] = 1 --> Page C1
  1247. if (TX1IQKOK == FALSE)
  1248. break; // TXK fail, Don't do RXK
  1249. if (VDF_enable == 1){
  1250. ODM_SetBBReg(pDM_Odm, 0xee8, BIT(31), 0x0); // TX VDF Disable
  1251. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("RXVDF Start\n"));
  1252. //====== RX IQK ======
  1253. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  1254. ODM_SetRFReg(pDM_Odm, Path, 0xef, bRFRegOffsetMask, 0x80000);
  1255. ODM_SetRFReg(pDM_Odm, Path, 0x30, bRFRegOffsetMask, 0x30000);
  1256. ODM_SetRFReg(pDM_Odm, Path, 0x31, bRFRegOffsetMask, 0x3f7ff);
  1257. ODM_SetRFReg(pDM_Odm, Path, 0x32, bRFRegOffsetMask, 0xfe7bf);
  1258. ODM_SetRFReg(pDM_Odm, Path, 0x8f, bRFRegOffsetMask, 0x88001);
  1259. ODM_SetRFReg(pDM_Odm, Path, 0x65, bRFRegOffsetMask, 0x931d0);
  1260. ODM_SetRFReg(pDM_Odm, Path, 0xef, bRFRegOffsetMask, 0x00000);
  1261. ODM_SetBBReg(pDM_Odm, 0x978, BIT(31), 0x1);
  1262. ODM_SetBBReg(pDM_Odm, 0x97c, BIT(31), 0x0);
  1263. ODM_Write4Byte(pDM_Odm, 0x984, 0x0046a911);
  1264. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x1); // [31] = 1 --> Page C1
  1265. ODM_Write4Byte(pDM_Odm, 0xe88, 0x02140119);
  1266. ODM_Write4Byte(pDM_Odm, 0xe8c, 0x28161420);
  1267. for (k = 0;k <= 2; k++){
  1268. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  1269. ODM_SetBBReg(pDM_Odm, 0x978, 0x03FF8000, (VDF_X[k])>>21&0x000007ff);
  1270. ODM_SetBBReg(pDM_Odm, 0x978, 0x000007FF, (VDF_Y[k])>>21&0x000007ff);
  1271. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x1); // [31] = 1 --> Page C1
  1272. switch (k){
  1273. case 0:
  1274. {
  1275. ODM_Write4Byte(pDM_Odm, 0xe80, 0x38008c38);// TX_Tone_idx[9:0], TxK_Mask[29] TX_Tone = 16
  1276. ODM_Write4Byte(pDM_Odm, 0xe84, 0x18008c38);// RX_Tone_idx[9:0], RxK_Mask[29]
  1277. ODM_SetBBReg(pDM_Odm, 0xee8, BIT(30), 0x0);
  1278. }
  1279. break;
  1280. case 1:
  1281. {
  1282. ODM_Write4Byte(pDM_Odm, 0xe80, 0x28008c38);// TX_Tone_idx[9:0], TxK_Mask[29] TX_Tone = 16
  1283. ODM_Write4Byte(pDM_Odm, 0xe84, 0x08008c38);// RX_Tone_idx[9:0], RxK_Mask[29]
  1284. ODM_SetBBReg(pDM_Odm, 0xee8, BIT(30), 0x0);
  1285. }
  1286. break;
  1287. case 2:
  1288. {
  1289. 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));
  1290. 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));
  1291. Rx_dt[cal] = (VDF_Y[1]>>20)-(VDF_Y[0]>>20);
  1292. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("Rx_dt = %d\n", Rx_dt[cal]));
  1293. Rx_dt[cal] = ((16*Rx_dt[cal])*10000/13823);
  1294. Rx_dt[cal] = (Rx_dt[cal] >> 1 )+(Rx_dt[cal] & BIT(0));
  1295. ODM_Write4Byte(pDM_Odm, 0xe80, 0x38008c20);// TX_Tone_idx[9:0], TxK_Mask[29] TX_Tone = 16
  1296. ODM_Write4Byte(pDM_Odm, 0xe84, 0x18008c20);// RX_Tone_idx[9:0], RxK_Mask[29]
  1297. ODM_SetBBReg(pDM_Odm, 0xee8, 0x00003fff, Rx_dt[cal] & 0x00003fff);
  1298. }
  1299. break;
  1300. default:
  1301. break;
  1302. }
  1303. if (k==2){
  1304. ODM_SetBBReg(pDM_Odm, 0xee8, BIT(30), 0x1); //RX VDF Enable
  1305. }
  1306. ODM_Write4Byte(pDM_Odm, 0xeb8, 0x00100000);// cb8[20] 將 SI/PI 使用權切給 iqk_dpk module
  1307. cal_retry = 0;
  1308. while(1){
  1309. // one shot
  1310. ODM_Write4Byte(pDM_Odm, 0x980, 0xfa000000);
  1311. ODM_Write4Byte(pDM_Odm, 0x980, 0xf8000000);
  1312. ODM_delay_ms(10); //Delay 10ms
  1313. ODM_Write4Byte(pDM_Odm, 0xeb8, 0x00000000);
  1314. delay_count = 0;
  1315. while (1){
  1316. IQK_ready = ODM_GetBBReg(pDM_Odm, 0xd40, BIT(10));
  1317. if ((IQK_ready)||(delay_count>20)){
  1318. break;
  1319. }
  1320. else{
  1321. ODM_delay_ms(1);
  1322. delay_count++;
  1323. }
  1324. }
  1325. if (delay_count < 20){ // If 20ms No Result, then cal_retry++
  1326. // ============RXIQK Check==============
  1327. RX_fail = ODM_GetBBReg(pDM_Odm, 0xd40, BIT(11));
  1328. if (RX_fail == 0){
  1329. ODM_Write4Byte(pDM_Odm, 0xeb8, 0x06000000);
  1330. VDF_X[k] = ODM_GetBBReg(pDM_Odm, 0xd40, 0x07ff0000)<<21;
  1331. ODM_Write4Byte(pDM_Odm, 0xeb8, 0x08000000);
  1332. VDF_Y[k] = ODM_GetBBReg(pDM_Odm, 0xd40, 0x07ff0000)<<21;
  1333. RX1IQKOK = TRUE;
  1334. break;
  1335. }
  1336. else{
  1337. ODM_SetBBReg(pDM_Odm, 0xe10, 0x000003ff, 0x200>>1);
  1338. ODM_SetBBReg(pDM_Odm, 0xe10, 0x03ff0000, 0x0>>1);
  1339. RX1IQKOK = FALSE;
  1340. cal_retry++;
  1341. if (cal_retry == 10)
  1342. break;
  1343. }
  1344. }
  1345. else{
  1346. RX1IQKOK = FALSE;
  1347. cal_retry++;
  1348. if (cal_retry == 10)
  1349. break;
  1350. }
  1351. }
  1352. }
  1353. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("RXB_VDF_cal_retry = %d\n", cal_retry));
  1354. RX_X1[cal] = VDF_X[k-1] ;
  1355. RX_Y1[cal] = VDF_Y[k-1];
  1356. ODM_SetBBReg(pDM_Odm, 0xee8, BIT(31), 0x1); // TX VDF Enable
  1357. }
  1358. else{
  1359. //====== RX IQK ======
  1360. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  1361. ODM_SetRFReg(pDM_Odm, Path, 0xef, bRFRegOffsetMask, 0x80000);
  1362. ODM_SetRFReg(pDM_Odm, Path, 0x30, bRFRegOffsetMask, 0x30000);
  1363. ODM_SetRFReg(pDM_Odm, Path, 0x31, bRFRegOffsetMask, 0x3f7ff);
  1364. ODM_SetRFReg(pDM_Odm, Path, 0x32, bRFRegOffsetMask, 0xfe7bf);
  1365. ODM_SetRFReg(pDM_Odm, Path, 0x8f, bRFRegOffsetMask, 0x88001);
  1366. ODM_SetRFReg(pDM_Odm, Path, 0x65, bRFRegOffsetMask, 0x931d0);
  1367. ODM_SetRFReg(pDM_Odm, Path, 0xef, bRFRegOffsetMask, 0x00000);
  1368. ODM_SetBBReg(pDM_Odm, 0x978, BIT(31), 0x1);
  1369. ODM_SetBBReg(pDM_Odm, 0x97c, BIT(31), 0x0);
  1370. ODM_Write4Byte(pDM_Odm, 0x90c, 0x00008000);
  1371. //ODM_Write4Byte(pDM_Odm, 0x984, 0x0046a911);
  1372. ODM_Write4Byte(pDM_Odm, 0x984, 0x0046a891);
  1373. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x1); // [31] = 1 --> Page C1
  1374. ODM_Write4Byte(pDM_Odm, 0xe80, 0x38008c10);// TX_Tone_idx[9:0], TxK_Mask[29] TX_Tone = 16
  1375. ODM_Write4Byte(pDM_Odm, 0xe84, 0x18008c10);// RX_Tone_idx[9:0], RxK_Mask[29]
  1376. ODM_Write4Byte(pDM_Odm, 0xe88, 0x02140119);
  1377. ODM_Write4Byte(pDM_Odm, 0xe8c, 0x28161180);
  1378. for(cal = 0; cal < cal_num; cal++){
  1379. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  1380. ODM_SetBBReg(pDM_Odm, 0x978, 0x03FF8000, (TX_X1[cal])>>21&0x000007ff);
  1381. ODM_SetBBReg(pDM_Odm, 0x978, 0x000007FF, (TX_Y1[cal])>>21&0x000007ff);
  1382. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x1); // [31] = 1 --> Page C1
  1383. cal_retry = 0;
  1384. while(1){
  1385. // one shot
  1386. ODM_Write4Byte(pDM_Odm, 0xeb8, 0x00100000);// cb8[20] 將 SI/PI 使用權切給 iqk_dpk module
  1387. ODM_Write4Byte(pDM_Odm, 0x980, 0xfa000000);
  1388. ODM_Write4Byte(pDM_Odm, 0x980, 0xf8000000);
  1389. ODM_delay_ms(10); //Delay 10ms
  1390. ODM_Write4Byte(pDM_Odm, 0xeb8, 0x00000000);
  1391. delay_count = 0;
  1392. while (1){
  1393. IQK_ready = ODM_GetBBReg(pDM_Odm, 0xd40, BIT(10));
  1394. if ((IQK_ready)||(delay_count>20)){
  1395. break;
  1396. }
  1397. else {
  1398. ODM_delay_ms(1);
  1399. delay_count++;
  1400. }
  1401. }
  1402. if (delay_count < 20){ // If 20ms No Result, then cal_retry++
  1403. // ============RXIQK Check==============
  1404. RX_fail = ODM_GetBBReg(pDM_Odm, 0xd40, BIT(11));
  1405. if (RX_fail == 0){
  1406. ODM_Write4Byte(pDM_Odm, 0xeb8, 0x06000000);
  1407. RX_X1[cal] = ODM_GetBBReg(pDM_Odm, 0xd40, 0x07ff0000)<<21;
  1408. ODM_Write4Byte(pDM_Odm, 0xeb8, 0x08000000);
  1409. RX_Y1[cal] = ODM_GetBBReg(pDM_Odm, 0xd40, 0x07ff0000)<<21;
  1410. RX1IQKOK = TRUE;
  1411. /*
  1412. ODM_Write4Byte(pDM_Odm, 0xeb8, 0x05000000);
  1413. reg1 = ODM_GetBBReg(pDM_Odm, 0xd40, 0xffffffff);
  1414. ODM_Write4Byte(pDM_Odm, 0xeb8, 0x06000000);
  1415. reg2 = ODM_GetBBReg(pDM_Odm, 0xd40, 0x0000001f);
  1416. DbgPrint("reg1 = %d, reg2 = %d", reg1, reg2);
  1417. Image_Power = (reg2<<32)+reg1;
  1418. DbgPrint("Before PW = %d\n", Image_Power);
  1419. ODM_Write4Byte(pDM_Odm, 0xeb8, 0x07000000);
  1420. reg1 = ODM_GetBBReg(pDM_Odm, 0xd40, 0xffffffff);
  1421. ODM_Write4Byte(pDM_Odm, 0xeb8, 0x08000000);
  1422. reg2 = ODM_GetBBReg(pDM_Odm, 0xd40, 0x0000001f);
  1423. Image_Power = (reg2<<32)+reg1;
  1424. DbgPrint("After PW = %d\n", Image_Power);
  1425. */
  1426. break;
  1427. }
  1428. else{
  1429. ODM_SetBBReg(pDM_Odm, 0xe10, 0x000003ff, 0x200>>1);
  1430. ODM_SetBBReg(pDM_Odm, 0xe10, 0x03ff0000, 0x0>>1);
  1431. RX1IQKOK = FALSE;
  1432. cal_retry++;
  1433. if (cal_retry == 10)
  1434. break;
  1435. }
  1436. }
  1437. else{
  1438. RX1IQKOK = FALSE;
  1439. cal_retry++;
  1440. if (cal_retry == 10)
  1441. break;
  1442. }
  1443. }
  1444. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("RXB_cal_retry = %d\n", cal_retry));
  1445. if (RX1IQKOK)
  1446. RX_Average++;
  1447. }
  1448. }
  1449. }
  1450. break;
  1451. default:
  1452. break;
  1453. }
  1454. // FillIQK Result
  1455. switch (Path){
  1456. case ODM_RF_PATH_A:
  1457. {
  1458. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("========Path_A =======\n"));
  1459. if (TX_Average == 0){
  1460. _IQK_TX_FillIQC_8812A(pDM_Odm, Path, 0x200, 0x0);
  1461. break;
  1462. }
  1463. for (i = 0; i < TX_Average; i++){
  1464. 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));
  1465. }
  1466. for (i = 0; i < TX_Average; i++){
  1467. for (ii = i+1; ii <TX_Average; ii++){
  1468. dx = (TX_X0[i]>>21) - (TX_X0[ii]>>21);
  1469. if (dx < 4 && dx > -4){
  1470. dy = (TX_Y0[i]>>21) - (TX_Y0[ii]>>21);
  1471. if (dy < 4 && dy > -4){
  1472. TX_X = ((TX_X0[i]>>21) + (TX_X0[ii]>>21))/2;
  1473. TX_Y = ((TX_Y0[i]>>21) + (TX_Y0[ii]>>21))/2;
  1474. if (*pDM_Odm->pBandWidth == 2){
  1475. Tx_dt[0] = (Tx_dt[i] + Tx_dt[ii])/2;
  1476. }
  1477. TX_finish = 1;
  1478. break;
  1479. }
  1480. }
  1481. }
  1482. if (TX_finish == 1)
  1483. break;
  1484. }
  1485. if (*pDM_Odm->pBandWidth == 2){
  1486. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x1); // [31] = 0 --> Page C
  1487. ODM_SetBBReg(pDM_Odm, 0xce8, 0x3fff0000, Tx_dt[0] & 0x00003fff);
  1488. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  1489. }
  1490. if (TX_finish == 1){
  1491. _IQK_TX_FillIQC_8812A(pDM_Odm, Path, TX_X, TX_Y);
  1492. }
  1493. else{
  1494. _IQK_TX_FillIQC_8812A(pDM_Odm, Path, 0x200, 0x0);
  1495. }
  1496. if (RX_Average == 0){
  1497. _IQK_RX_FillIQC_8812A(pDM_Odm, Path, 0x200, 0x0);
  1498. break;
  1499. }
  1500. for (i = 0; i < RX_Average; i++){
  1501. 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));
  1502. }
  1503. for (i = 0; i < RX_Average; i++){
  1504. for (ii = i+1; ii <RX_Average; ii++){
  1505. dx = (RX_X0[i]>>21) - (RX_X0[ii]>>21);
  1506. if (dx < 4 && dx > -4){
  1507. dy = (RX_Y0[i]>>21) - (RX_Y0[ii]>>21);
  1508. if (dy < 4 && dy > -4){
  1509. RX_X = ((RX_X0[i]>>21) + (RX_X0[ii]>>21))/2;
  1510. RX_Y = ((RX_Y0[i]>>21) + (RX_Y0[ii]>>21))/2;
  1511. if (*pDM_Odm->pBandWidth == 2){
  1512. Rx_dt[0] = (Rx_dt[i] + Rx_dt[ii])/2;
  1513. }
  1514. RX_finish = 1;
  1515. break;
  1516. }
  1517. }
  1518. }
  1519. if (RX_finish == 1)
  1520. break;
  1521. }
  1522. if (*pDM_Odm->pBandWidth == 2){
  1523. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x1); // [31] = 0 --> Page C
  1524. ODM_SetBBReg(pDM_Odm, 0xce8, 0x00003fff, Rx_dt[0] & 0x00003fff);
  1525. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  1526. }
  1527. if (RX_finish == 1){
  1528. _IQK_RX_FillIQC_8812A(pDM_Odm, Path, RX_X, RX_Y);
  1529. }
  1530. else{
  1531. _IQK_RX_FillIQC_8812A(pDM_Odm, Path, 0x200, 0x0);
  1532. }
  1533. if (TX_finish && RX_finish){
  1534. pRFCalibrateInfo->bNeedIQK = FALSE;
  1535. pRFCalibrateInfo->IQKMatrixRegSetting[chnlIdx].Value[*pDM_Odm->pBandWidth][0] = ((TX_X & 0x000007ff) << 16) + (TX_Y & 0x000007ff); //Path A TX
  1536. pRFCalibrateInfo->IQKMatrixRegSetting[chnlIdx].Value[*pDM_Odm->pBandWidth][1] = ((RX_X & 0x000007ff) << 16) + (RX_Y & 0x000007ff); //Path A RX
  1537. if (*pDM_Odm->pBandWidth == 2){
  1538. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x1); // [31] = 0 --> Page C
  1539. pRFCalibrateInfo->IQKMatrixRegSetting[chnlIdx].Value[*pDM_Odm->pBandWidth][4] = ODM_Read4Byte( pDM_Odm, 0xce8); //Path B VDF
  1540. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  1541. }
  1542. }
  1543. }
  1544. break;
  1545. case ODM_RF_PATH_B:
  1546. {
  1547. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("========Path_B =======\n"));
  1548. if (TX_Average == 0){
  1549. _IQK_TX_FillIQC_8812A(pDM_Odm, Path, 0x200, 0x0);
  1550. break;
  1551. }
  1552. for (i = 0; i < TX_Average; i++){
  1553. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("TX_X1[%d] = %x ;; TX_Y1[%d] = %x\n", i, (TX_X1[i])>>21&0x000007ff, i, (TX_Y1[i])>>21&0x000007ff));
  1554. }
  1555. for (i = 0; i < TX_Average; i++){
  1556. for (ii = i+1; ii <TX_Average; ii++){
  1557. dx = (TX_X1[i]>>21) - (TX_X1[ii]>>21);
  1558. if (dx < 4 && dx > -4){
  1559. dy = (TX_Y1[i]>>21) - (TX_Y1[ii]>>21);
  1560. if (dy < 4 && dy > -4){
  1561. TX_X = ((TX_X1[i]>>21) + (TX_X1[ii]>>21))/2;
  1562. TX_Y = ((TX_Y1[i]>>21) + (TX_Y1[ii]>>21))/2;
  1563. if (*pDM_Odm->pBandWidth == 2){
  1564. Tx_dt[0] = (Tx_dt[i] + Tx_dt[ii])/2;
  1565. }
  1566. TX_finish = 1;
  1567. break;
  1568. }
  1569. }
  1570. }
  1571. if (TX_finish == 1)
  1572. break;
  1573. }
  1574. if (*pDM_Odm->pBandWidth == 2){
  1575. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x1); // [31] = 0 --> Page C
  1576. ODM_SetBBReg(pDM_Odm, 0xee8, 0x3fff0000, Tx_dt[0] & 0x00003fff);
  1577. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  1578. }
  1579. if (TX_finish == 1){
  1580. _IQK_TX_FillIQC_8812A(pDM_Odm, Path, TX_X, TX_Y);
  1581. }
  1582. else{
  1583. _IQK_TX_FillIQC_8812A(pDM_Odm, Path, 0x200, 0x0);
  1584. }
  1585. if (RX_Average == 0){
  1586. _IQK_RX_FillIQC_8812A(pDM_Odm, Path, 0x200, 0x0);
  1587. break;
  1588. }
  1589. for (i = 0; i < RX_Average; i++){
  1590. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("RX_X1[%d] = %x ;; RX_Y1[%d] = %x\n", i, (RX_X1[i])>>21&0x000007ff, i, (RX_Y1[i])>>21&0x000007ff));
  1591. }
  1592. for (i = 0; i < RX_Average; i++){
  1593. for (ii = i+1; ii <RX_Average; ii++){
  1594. dx = (RX_X1[i]>>21) - (RX_X1[ii]>>21);
  1595. if (dx < 4 && dx > -4){
  1596. dy = (RX_Y1[i]>>21) - (RX_Y1[ii]>>21);
  1597. if (dy < 4 && dy > -4){
  1598. RX_X = ((RX_X1[i]>>21) + (RX_X1[ii]>>21))/2;
  1599. RX_Y = ((RX_Y1[i]>>21) + (RX_Y1[ii]>>21))/2;
  1600. if (*pDM_Odm->pBandWidth == 2){
  1601. Rx_dt[0] = (Rx_dt[i] + Rx_dt[ii])/2;
  1602. }
  1603. RX_finish = 1;
  1604. break;
  1605. }
  1606. }
  1607. }
  1608. if (RX_finish == 1)
  1609. break;
  1610. }
  1611. if (*pDM_Odm->pBandWidth == 2){
  1612. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x1); // [31] = 0 --> Page C
  1613. ODM_SetBBReg(pDM_Odm, 0xee8, 0x00003fff, Rx_dt[0] & 0x00003fff);
  1614. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  1615. }
  1616. if (RX_finish == 1){
  1617. _IQK_RX_FillIQC_8812A(pDM_Odm, Path, RX_X, RX_Y);
  1618. }
  1619. else{
  1620. _IQK_RX_FillIQC_8812A(pDM_Odm, Path, 0x200, 0x0);
  1621. }
  1622. if (TX_finish && RX_finish){
  1623. //pRFCalibrateInfo->IQKMatrixRegSetting[chnlIdx].bIQKDone= TRUE;
  1624. pRFCalibrateInfo->bNeedIQK = FALSE;
  1625. pRFCalibrateInfo->IQKMatrixRegSetting[chnlIdx].Value[*pDM_Odm->pBandWidth][2] = ((TX_X & 0x000007ff) << 16) + (TX_Y & 0x000007ff); //Path B TX
  1626. pRFCalibrateInfo->IQKMatrixRegSetting[chnlIdx].Value[*pDM_Odm->pBandWidth][3] = ((RX_X & 0x000007ff) << 16) + (RX_Y & 0x000007ff); //Path B RX
  1627. if (*pDM_Odm->pBandWidth == 2){
  1628. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x1); // [31] = 0 --> Page C
  1629. pRFCalibrateInfo->IQKMatrixRegSetting[chnlIdx].Value[*pDM_Odm->pBandWidth][5] = ODM_Read4Byte( pDM_Odm, 0xee8); //Path B VDF
  1630. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  1631. }
  1632. }
  1633. }
  1634. break;
  1635. default:
  1636. break;
  1637. }
  1638. }
  1639. #define MACBB_REG_NUM 10
  1640. #define AFE_REG_NUM 14
  1641. #define RF_REG_NUM 3
  1642. // Maintained by BB James.
  1643. VOID
  1644. phy_IQCalibrate_8812A(
  1645. IN PDM_ODM_T pDM_Odm,
  1646. IN u1Byte Channel
  1647. )
  1648. {
  1649. u4Byte MACBB_backup[MACBB_REG_NUM], AFE_backup[AFE_REG_NUM], RFA_backup[RF_REG_NUM], RFB_backup[RF_REG_NUM];
  1650. u4Byte Backup_MACBB_REG[MACBB_REG_NUM] = {0xb00, 0x520, 0x550, 0x808, 0x90c, 0xc00, 0xe00, 0x8c4,0x838, 0x82c};
  1651. u4Byte Backup_AFE_REG[AFE_REG_NUM] = {0xc5c, 0xc60, 0xc64, 0xc68, 0xcb8, 0xcb0, 0xcb4,
  1652. 0xe5c, 0xe60, 0xe64, 0xe68, 0xeb8, 0xeb0, 0xeb4};
  1653. u4Byte Backup_RF_REG[RF_REG_NUM] = {0x65, 0x8f, 0x0};
  1654. u1Byte chnlIdx = ODM_GetRightChnlPlaceforIQK(Channel);
  1655. _IQK_BackupMacBB_8812A(pDM_Odm, MACBB_backup, Backup_MACBB_REG, MACBB_REG_NUM);
  1656. _IQK_BackupAFE_8812A(pDM_Odm, AFE_backup, Backup_AFE_REG, AFE_REG_NUM);
  1657. _IQK_BackupRF_8812A(pDM_Odm, RFA_backup, RFB_backup, Backup_RF_REG, RF_REG_NUM);
  1658. _IQK_ConfigureMAC_8812A(pDM_Odm);
  1659. _IQK_Tx_8812A(pDM_Odm, ODM_RF_PATH_A, chnlIdx);
  1660. _IQK_RestoreRF_8812A(pDM_Odm, ODM_RF_PATH_A, Backup_RF_REG, RFA_backup, RF_REG_NUM);
  1661. _IQK_Tx_8812A(pDM_Odm, ODM_RF_PATH_B, chnlIdx);
  1662. _IQK_RestoreRF_8812A(pDM_Odm, ODM_RF_PATH_B, Backup_RF_REG, RFB_backup, RF_REG_NUM);
  1663. _IQK_RestoreAFE_8812A(pDM_Odm, AFE_backup, Backup_AFE_REG, AFE_REG_NUM);
  1664. _IQK_RestoreMacBB_8812A(pDM_Odm, MACBB_backup, Backup_MACBB_REG, MACBB_REG_NUM);
  1665. }
  1666. VOID
  1667. phy_LCCalibrate_8812A(
  1668. IN PDM_ODM_T pDM_Odm,
  1669. IN BOOLEAN is2T
  1670. )
  1671. {
  1672. u4Byte /*RF_Amode=0, RF_Bmode=0,*/ LC_Cal = 0, tmp = 0;
  1673. //Check continuous TX and Packet TX
  1674. u4Byte reg0x914 = ODM_Read4Byte(pDM_Odm, rSingleTone_ContTx_Jaguar);;
  1675. // Backup RF reg18.
  1676. LC_Cal = ODM_GetRFReg(pDM_Odm, ODM_RF_PATH_A, RF_CHNLBW, bRFRegOffsetMask);
  1677. if((reg0x914 & 0x70000) != 0) //If contTx, disable all continuous TX. 0x914[18:16]
  1678. // <20121121, Kordan> A workaround: If we set 0x914[18:16] as zero, BB turns off ContTx
  1679. // until another packet comes in. To avoid ContTx being turned off, we skip this step.
  1680. ;//ODM_Write4Byte(pDM_Odm, rSingleTone_ContTx_Jaguar, reg0x914 & (~0x70000));
  1681. else // If packet Tx-ing, pause Tx.
  1682. ODM_Write1Byte(pDM_Odm, REG_TXPAUSE, 0xFF);
  1683. /*
  1684. //3 1. Read original RF mode
  1685. RF_Amode = ODM_GetRFReg(pDM_Odm, ODM_RF_PATH_A, RF_AC, bRFRegOffsetMask);
  1686. if(is2T)
  1687. RF_Bmode = ODM_GetRFReg(pDM_Odm, ODM_RF_PATH_B, RF_AC, bRFRegOffsetMask);
  1688. //3 2. Set RF mode = standby mode
  1689. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_A, RF_AC, bRFRegOffsetMask, (RF_Amode&0x8FFFF)|0x10000);
  1690. if(is2T)
  1691. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_B, RF_AC, bRFRegOffsetMask, (RF_Bmode&0x8FFFF)|0x10000);
  1692. */
  1693. // Enter LCK mode
  1694. tmp = ODM_GetRFReg(pDM_Odm, ODM_RF_PATH_A, RF_LCK, bRFRegOffsetMask);
  1695. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_A, RF_LCK, bRFRegOffsetMask, tmp | BIT14);
  1696. //3 3. Read RF reg18
  1697. LC_Cal = ODM_GetRFReg(pDM_Odm, ODM_RF_PATH_A, RF_CHNLBW, bRFRegOffsetMask);
  1698. //3 4. Set LC calibration begin bit15
  1699. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_A, RF_CHNLBW, bRFRegOffsetMask, LC_Cal|0x08000);
  1700. // Leave LCK mode
  1701. tmp = ODM_GetRFReg(pDM_Odm, ODM_RF_PATH_A, RF_LCK, bRFRegOffsetMask);
  1702. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_A, RF_LCK, bRFRegOffsetMask, tmp & ~BIT14);
  1703. ODM_delay_ms(100);
  1704. //3 Restore original situation
  1705. if((reg0x914 & 70000) != 0) //Deal with contisuous TX case, 0x914[18:16]
  1706. {
  1707. // <20121121, Kordan> A workaround: If we set 0x914[18:16] as zero, BB turns off ContTx
  1708. // until another packet comes in. To avoid ContTx being turned off, we skip this step.
  1709. //ODM_Write4Byte(pDM_Odm, rSingleTone_ContTx_Jaguar, reg0x914);
  1710. }
  1711. else // Deal with Packet TX case
  1712. {
  1713. ODM_Write1Byte(pDM_Odm, REG_TXPAUSE, 0x00);
  1714. }
  1715. // Recover channel number
  1716. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_A, RF_CHNLBW, bRFRegOffsetMask, LC_Cal);
  1717. /*
  1718. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_A, RF_AC, bRFRegOffsetMask, RF_Amode);
  1719. if(is2T)
  1720. ODM_SetRFReg(pDM_Odm, ODM_RF_PATH_B, RF_AC, bRFRegOffsetMask, RF_Bmode);
  1721. */
  1722. }
  1723. #define DP_BB_REG_NUM 7
  1724. #define DP_RF_REG_NUM 1
  1725. #define DP_RETRY_LIMIT 10
  1726. #define DP_PATH_NUM 2
  1727. #define DP_DPK_NUM 3
  1728. #define DP_DPK_VALUE_NUM 2
  1729. VOID
  1730. phy_ReloadIQKSetting_8812A(
  1731. IN PDM_ODM_T pDM_Odm,
  1732. IN u1Byte Channel
  1733. )
  1734. {
  1735. PODM_RF_CAL_T pRFCalibrateInfo = &(pDM_Odm->RFCalibrateInfo);
  1736. u1Byte chnlIdx = ODM_GetRightChnlPlaceforIQK(Channel);
  1737. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x1); // [31] = 1 --> Page C1
  1738. ODM_SetBBReg(pDM_Odm, 0xccc, 0x000007ff, pRFCalibrateInfo->IQKMatrixRegSetting[chnlIdx].Value[*pDM_Odm->pBandWidth][0]&0x7ff);
  1739. ODM_SetBBReg(pDM_Odm, 0xcd4, 0x000007ff, (pRFCalibrateInfo->IQKMatrixRegSetting[chnlIdx].Value[*pDM_Odm->pBandWidth][0]&0x7ff0000)>>16);
  1740. ODM_SetBBReg(pDM_Odm, 0xecc, 0x000007ff, pRFCalibrateInfo->IQKMatrixRegSetting[chnlIdx].Value[*pDM_Odm->pBandWidth][2]&0x7ff);
  1741. ODM_SetBBReg(pDM_Odm, 0xed4, 0x000007ff, (pRFCalibrateInfo->IQKMatrixRegSetting[chnlIdx].Value[*pDM_Odm->pBandWidth][2]&0x7ff0000)>>16);
  1742. if (*pDM_Odm->pBandWidth != 2){
  1743. ODM_Write4Byte(pDM_Odm, 0xce8, 0x0);
  1744. ODM_Write4Byte(pDM_Odm, 0xee8, 0x0);
  1745. }
  1746. else{
  1747. ODM_Write4Byte(pDM_Odm, 0xce8, pRFCalibrateInfo->IQKMatrixRegSetting[chnlIdx].Value[*pDM_Odm->pBandWidth][4]);
  1748. ODM_Write4Byte(pDM_Odm, 0xee8, pRFCalibrateInfo->IQKMatrixRegSetting[chnlIdx].Value[*pDM_Odm->pBandWidth][5]);
  1749. }
  1750. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  1751. ODM_SetBBReg(pDM_Odm, 0xc10, 0x000003ff, (pRFCalibrateInfo->IQKMatrixRegSetting[chnlIdx].Value[*pDM_Odm->pBandWidth][1]&0x7ff0000)>>17);
  1752. ODM_SetBBReg(pDM_Odm, 0xc10, 0x03ff0000, (pRFCalibrateInfo->IQKMatrixRegSetting[chnlIdx].Value[*pDM_Odm->pBandWidth][1]&0x7ff)>>1);
  1753. ODM_SetBBReg(pDM_Odm, 0xe10, 0x000003ff, (pRFCalibrateInfo->IQKMatrixRegSetting[chnlIdx].Value[*pDM_Odm->pBandWidth][3]&0x7ff0000)>>17);
  1754. ODM_SetBBReg(pDM_Odm, 0xe10, 0x03ff0000, (pRFCalibrateInfo->IQKMatrixRegSetting[chnlIdx].Value[*pDM_Odm->pBandWidth][3]&0x7ff)>>1);
  1755. }
  1756. VOID
  1757. PHY_ResetIQKResult_8812A(
  1758. IN PDM_ODM_T pDM_Odm
  1759. )
  1760. {
  1761. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x1); // [31] = 1 --> Page C1
  1762. ODM_SetBBReg(pDM_Odm, 0xccc, 0x000007ff, 0x0);
  1763. ODM_SetBBReg(pDM_Odm, 0xcd4, 0x000007ff, 0x200);
  1764. ODM_SetBBReg(pDM_Odm, 0xecc, 0x000007ff, 0x0);
  1765. ODM_SetBBReg(pDM_Odm, 0xed4, 0x000007ff, 0x200);
  1766. ODM_Write4Byte(pDM_Odm, 0xce8, 0x0);
  1767. ODM_Write4Byte(pDM_Odm, 0xee8, 0x0);
  1768. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  1769. ODM_SetBBReg(pDM_Odm, 0xc10, 0x000003ff, 0x100);
  1770. ODM_SetBBReg(pDM_Odm, 0xe10, 0x000003ff, 0x100);
  1771. }
  1772. VOID
  1773. phy_IQCalibrate_By_FW_8812A(
  1774. IN PADAPTER pAdapter
  1775. )
  1776. {
  1777. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  1778. u1Byte IQKcmd[3] = {pHalData->CurrentChannel, 0x0, 0x0};
  1779. u1Byte Buf1 = 0x0;
  1780. u1Byte Buf2 = 0x0;
  1781. //Byte 2, Bit 4 ~ Bit 5 : BandType
  1782. if(pHalData->CurrentBandType)
  1783. Buf1 = 0x2<<4;
  1784. else
  1785. Buf1 = 0x1<<4;
  1786. //Byte 2, Bit 0 ~ Bit 3 : Bandwidth
  1787. if(pHalData->CurrentChannelBW == CHANNEL_WIDTH_20)
  1788. Buf2 = 0x1;
  1789. else if(pHalData->CurrentChannelBW == CHANNEL_WIDTH_40)
  1790. Buf2 = 0x1<<1;
  1791. else if(pHalData->CurrentChannelBW == CHANNEL_WIDTH_80)
  1792. Buf2 = 0x1<<2;
  1793. else
  1794. Buf2 = 0x1<<3;
  1795. IQKcmd[1] = Buf1 | Buf2;
  1796. IQKcmd[2] = pHalData->ExternalPA_5G | pHalData->ExternalLNA_5G<<1;
  1797. RT_TRACE(COMP_MP, DBG_LOUD, ("== Start ==\n"));
  1798. //FillH2CCmd_8812(pAdapter, 0x45, 3, IQKcmd);
  1799. }
  1800. VOID
  1801. PHY_IQCalibrate_8812A(
  1802. IN PADAPTER pAdapter,
  1803. IN BOOLEAN bReCovery
  1804. )
  1805. {
  1806. #if !(DM_ODM_SUPPORT_TYPE & ODM_AP)
  1807. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  1808. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  1809. PDM_ODM_T pDM_Odm = &pHalData->DM_OutSrc;
  1810. #else // (DM_ODM_SUPPORT_TYPE == ODM_CE)
  1811. PDM_ODM_T pDM_Odm = &pHalData->odmpriv;
  1812. #endif
  1813. #endif
  1814. #if (MP_DRIVER == 1)
  1815. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  1816. PMPT_CONTEXT pMptCtx = &(pAdapter->MptCtx);
  1817. #else// (DM_ODM_SUPPORT_TYPE == ODM_CE)
  1818. PMPT_CONTEXT pMptCtx = &(pAdapter->mppriv.MptCtx);
  1819. #endif
  1820. #endif//(MP_DRIVER == 1)
  1821. #if (DM_ODM_SUPPORT_TYPE & (ODM_WIN|ODM_CE) )
  1822. if (ODM_CheckPowerStatus(pAdapter) == FALSE)
  1823. return;
  1824. #endif
  1825. #if MP_DRIVER == 1
  1826. if( ! (pMptCtx->bSingleTone || pMptCtx->bCarrierSuppression) )
  1827. #endif
  1828. {
  1829. //if(pMgntInfo->RegIQKFWOffload)
  1830. // phy_IQCalibrate_By_FW_8812A(pAdapter);
  1831. //else
  1832. phy_IQCalibrate_8812A(pDM_Odm, pHalData->CurrentChannel);
  1833. }
  1834. }
  1835. VOID
  1836. PHY_LCCalibrate_8812A(
  1837. IN PDM_ODM_T pDM_Odm
  1838. )
  1839. {
  1840. BOOLEAN bStartContTx = FALSE, bSingleTone = FALSE, bCarrierSuppression = FALSE;
  1841. #if !(DM_ODM_SUPPORT_TYPE & ODM_AP)
  1842. PADAPTER pAdapter = pDM_Odm->Adapter;
  1843. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  1844. #if (MP_DRIVER == 1)
  1845. #if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  1846. PMPT_CONTEXT pMptCtx = &(pAdapter->MptCtx);
  1847. #else// (DM_ODM_SUPPORT_TYPE == ODM_CE)
  1848. PMPT_CONTEXT pMptCtx = &(pAdapter->mppriv.MptCtx);
  1849. #endif
  1850. bStartContTx = pMptCtx->bStartContTx;
  1851. bSingleTone = pMptCtx->bSingleTone;
  1852. bCarrierSuppression = pMptCtx->bCarrierSuppression;
  1853. #endif//(MP_DRIVER == 1)
  1854. #endif
  1855. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("===> PHY_LCCalibrate_8812A\n"));
  1856. #if (MP_DRIVER == 1)
  1857. phy_LCCalibrate_8812A(pDM_Odm, TRUE);
  1858. #endif
  1859. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("<=== PHY_LCCalibrate_8812A\n"));
  1860. }
  1861. VOID phy_SetRFPathSwitch_8812A(
  1862. #if (DM_ODM_SUPPORT_TYPE & ODM_AP)
  1863. IN PDM_ODM_T pDM_Odm,
  1864. #else
  1865. IN PADAPTER pAdapter,
  1866. #endif
  1867. IN BOOLEAN bMain,
  1868. IN BOOLEAN is2T
  1869. )
  1870. {
  1871. #if !(DM_ODM_SUPPORT_TYPE & ODM_AP)
  1872. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(pAdapter);
  1873. #if (DM_ODM_SUPPORT_TYPE == ODM_CE)
  1874. PDM_ODM_T pDM_Odm = &pHalData->odmpriv;
  1875. #elif (DM_ODM_SUPPORT_TYPE == ODM_WIN)
  1876. PDM_ODM_T pDM_Odm = &pHalData->DM_OutSrc;
  1877. #endif
  1878. #endif
  1879. if (IS_HARDWARE_TYPE_8821(pAdapter))
  1880. {
  1881. if(bMain)
  1882. ODM_SetBBReg(pDM_Odm, rA_RFE_Pinmux_Jaguar+4, BIT29|BIT28, 0x1); //Main
  1883. else
  1884. ODM_SetBBReg(pDM_Odm, rA_RFE_Pinmux_Jaguar+4, BIT29|BIT28, 0x2); //Aux
  1885. }
  1886. else if (IS_HARDWARE_TYPE_8812(pAdapter))
  1887. {
  1888. if (pHalData->RFEType == 5)
  1889. {
  1890. if(bMain) {
  1891. //WiFi
  1892. ODM_SetBBReg(pDM_Odm, r_ANTSEL_SW_Jaguar, BIT1|BIT0, 0x2);
  1893. ODM_SetBBReg(pDM_Odm, r_ANTSEL_SW_Jaguar, BIT9|BIT8, 0x3);
  1894. } else {
  1895. // BT
  1896. ODM_SetBBReg(pDM_Odm, r_ANTSEL_SW_Jaguar, BIT1|BIT0, 0x1);
  1897. ODM_SetBBReg(pDM_Odm, r_ANTSEL_SW_Jaguar, BIT9|BIT8, 0x3);
  1898. }
  1899. }
  1900. }
  1901. }
  1902. VOID PHY_SetRFPathSwitch_8812A(
  1903. #if (DM_ODM_SUPPORT_TYPE & ODM_AP)
  1904. IN PDM_ODM_T pDM_Odm,
  1905. #else
  1906. IN PADAPTER pAdapter,
  1907. #endif
  1908. IN BOOLEAN bMain
  1909. )
  1910. {
  1911. #if DISABLE_BB_RF
  1912. return;
  1913. #endif
  1914. #if !(DM_ODM_SUPPORT_TYPE & ODM_AP)
  1915. phy_SetRFPathSwitch_8812A(pAdapter, bMain, TRUE);
  1916. #endif
  1917. }
  1918. VOID
  1919. _DPK_ThermalCompensation(
  1920. IN PDM_ODM_T pDM_Odm
  1921. )
  1922. {
  1923. }
  1924. VOID
  1925. _DPK_parareload(
  1926. IN PDM_ODM_T pDM_Odm,
  1927. IN pu4Byte MACBB_backup,
  1928. IN pu4Byte Backup_MACBB_REG,
  1929. IN u4Byte MACBB_NUM
  1930. )
  1931. {
  1932. u4Byte i;
  1933. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  1934. //save MACBB default value
  1935. for (i = 0; i < MACBB_NUM; i++){
  1936. ODM_Write4Byte(pDM_Odm, Backup_MACBB_REG[i], MACBB_backup[i]);
  1937. }
  1938. }
  1939. VOID
  1940. _DPK_parabackup(
  1941. IN PDM_ODM_T pDM_Odm,
  1942. IN pu4Byte MACBB_backup,
  1943. IN pu4Byte Backup_MACBB_REG,
  1944. IN u4Byte MACBB_NUM
  1945. )
  1946. {
  1947. u4Byte i;
  1948. ODM_SetBBReg(pDM_Odm, 0x82c, BIT(31), 0x0); // [31] = 0 --> Page C
  1949. //save MACBB default value
  1950. for (i = 0; i < MACBB_NUM; i++){
  1951. MACBB_backup[i] = ODM_Read4Byte(pDM_Odm, Backup_MACBB_REG[i]);
  1952. }
  1953. }
  1954. VOID
  1955. _DPK_Globalparaset(
  1956. IN PDM_ODM_T pDM_Odm
  1957. )
  1958. {
  1959. //***************************************//
  1960. //set MAC register
  1961. //***************************************//
  1962. //TX pause
  1963. ODM_Write4Byte(pDM_Odm, 0x520, 0x007f3F0F);
  1964. //***************************************//
  1965. //set BB register
  1966. //***************************************//
  1967. // reg82c[31] = b'0, 切換到 page C
  1968. ODM_Write4Byte(pDM_Odm, 0x82c, 0x002083d5);
  1969. // test pin in/out control
  1970. ODM_Write4Byte(pDM_Odm, 0x970, 0x00000000);
  1971. // path A regcb8[3:0] = h'd, TRSW to TX
  1972. ODM_Write4Byte(pDM_Odm, 0xcb8, 0x0050824d);
  1973. // path B regeb8[3:0] = h'd, TRSW to TX
  1974. ODM_Write4Byte(pDM_Odm, 0xeb8, 0x0050824d);
  1975. // reg838[3:0] = h'c, CCA off
  1976. ODM_Write4Byte(pDM_Odm, 0x838, 0x06c8d24c);
  1977. // path A 3-wire off
  1978. ODM_Write4Byte(pDM_Odm, 0xc00, 0x00000004);
  1979. // path B 3-wire off
  1980. ODM_Write4Byte(pDM_Odm, 0xe00, 0x00000004);
  1981. // reg90c[15] = b'1, DAC fifo reset by CSWU
  1982. ODM_Write4Byte(pDM_Odm, 0x90c, 0x00008000);
  1983. // reset DPK circuit
  1984. ODM_Write4Byte(pDM_Odm, 0xb00, 0x03000100);
  1985. // path A regc94[0] = b'1 (r_gothrough_iqkdpk), 將 DPK 切進 normal path
  1986. ODM_Write4Byte(pDM_Odm, 0xc94, 0x01000001);
  1987. // path B rege94[0] = b'1 (r_gothrough_iqkdpk), 將 DPK 切進 normal path
  1988. ODM_Write4Byte(pDM_Odm, 0xe94, 0x01000001);
  1989. //***************************************//
  1990. //set AFE register
  1991. //***************************************//
  1992. //path A
  1993. //regc68 到 regc84應該是要跟正常 Tx mode 時的設定一致
  1994. ODM_Write4Byte(pDM_Odm, 0xc68, 0x19791979);
  1995. ODM_Write4Byte(pDM_Odm, 0xc6c, 0x19791979);
  1996. ODM_Write4Byte(pDM_Odm, 0xc70, 0x19791979);
  1997. ODM_Write4Byte(pDM_Odm, 0xc74, 0x19791979);
  1998. ODM_Write4Byte(pDM_Odm, 0xc78, 0x19791979);
  1999. ODM_Write4Byte(pDM_Odm, 0xc7c, 0x19791979);
  2000. ODM_Write4Byte(pDM_Odm, 0xc80, 0x19791979);
  2001. ODM_Write4Byte(pDM_Odm, 0xc84, 0x19791979);
  2002. // force DAC/ADC power on
  2003. ODM_Write4Byte(pDM_Odm, 0xc60, 0x77777777);
  2004. ODM_Write4Byte(pDM_Odm, 0xc64, 0x77777777);
  2005. //path B
  2006. //rege68 到 rege84應該是要跟正常 Tx mode 時的設定一致
  2007. ODM_Write4Byte(pDM_Odm, 0xe68, 0x19791979);
  2008. ODM_Write4Byte(pDM_Odm, 0xe6c, 0x19791979);
  2009. ODM_Write4Byte(pDM_Odm, 0xe70, 0x19791979);
  2010. ODM_Write4Byte(pDM_Odm, 0xe74, 0x19791979);
  2011. ODM_Write4Byte(pDM_Odm, 0xe78, 0x19791979);
  2012. ODM_Write4Byte(pDM_Odm, 0xe7c, 0x19791979);
  2013. ODM_Write4Byte(pDM_Odm, 0xe80, 0x19791979);
  2014. ODM_Write4Byte(pDM_Odm, 0xe84, 0x19791979);
  2015. // force DAC/ADC power on
  2016. ODM_Write4Byte(pDM_Odm, 0xe60, 0x77777777);
  2017. ODM_Write4Byte(pDM_Odm, 0xe64, 0x77777777);
  2018. }
  2019. VOID
  2020. _DPK_GetGainLoss(
  2021. IN PDM_ODM_T pDM_Odm,
  2022. IN u1Byte path
  2023. )
  2024. {
  2025. u4Byte GL_I=0,GL_Q=0;
  2026. u4Byte GL_I_tmp=0,GL_Q_tmp=0;
  2027. u4Byte Power_GL;
  2028. u2Byte Scaler[]={0x4000, 0x41db, 0x43c7, 0x45c3, 0x47cf, 0x49ec, 0x4c19, 0x4e46, 0x5093,0x52f2, //10
  2029. 0x5560, 0x57cf, 0x5a7f, 0x5d0e, 0x5fbe
  2030. };
  2031. u1Byte sindex=0;
  2032. u4Byte pagesel = 0,regsel = 0;
  2033. if(path == 0) //pathA
  2034. {
  2035. pagesel = 0;
  2036. regsel = 0;
  2037. }
  2038. else //pathB
  2039. {
  2040. pagesel = 0x200;
  2041. regsel = 0x40;
  2042. }
  2043. ODM_Write4Byte(pDM_Odm, 0xc90+pagesel, 0x0601f0bf);
  2044. ODM_Write4Byte(pDM_Odm, 0xcb8+pagesel, 0x0c000000);
  2045. GL_I_tmp = ODM_GetBBReg(pDM_Odm, 0xd00+regsel, 0xffff0000);
  2046. GL_Q_tmp = ODM_GetBBReg(pDM_Odm, 0xd00+regsel, 0x0000ffff);
  2047. if(GL_I_tmp >= 0x8000)
  2048. GL_I = (GL_I_tmp-0x8000+0x1);
  2049. else
  2050. GL_I = GL_I_tmp;
  2051. if(GL_Q_tmp >= 0x8000)
  2052. GL_Q = (GL_Q_tmp-0x8000+0x1);
  2053. else
  2054. GL_Q = GL_Q_tmp;
  2055. Power_GL = ((GL_I*GL_I)+(GL_Q*GL_Q))/4;
  2056. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("Power_GL = 0x%x", Power_GL));
  2057. if (Power_GL > 63676){
  2058. sindex = 0;
  2059. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("Gainloss = 0 dB\n"));
  2060. }
  2061. else if (63676 >= Power_GL && Power_GL > 60114){
  2062. sindex = 1;
  2063. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("Gainloss = 0.25 dB\n"));
  2064. }
  2065. else if (60114 >= Power_GL && Power_GL> 56751){
  2066. sindex = 2;
  2067. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("Gainloss = 0.5 dB\n"));
  2068. }
  2069. else if (56751 >= Power_GL && Power_GL> 53577){
  2070. sindex = 3;
  2071. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("Gainloss = 0.75 dB\n"));
  2072. }
  2073. else if (53577 >= Power_GL && Power_GL> 49145){
  2074. sindex = 4;
  2075. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("Gainloss = 1 dB\n"));
  2076. }
  2077. else if (49145 >= Power_GL && Power_GL> 47750){
  2078. sindex = 5;
  2079. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("Gainloss = 1.25 dB\n"));
  2080. }
  2081. else if (47750 >= Power_GL && Power_GL> 45079){
  2082. sindex = 6;
  2083. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("Gainloss = 1.5 dB\n"));
  2084. }
  2085. else if (45079 >= Power_GL && Power_GL> 42557){
  2086. sindex = 7;
  2087. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("Gainloss = 1.75 dB\n"));
  2088. }
  2089. else if (42557 >= Power_GL && Power_GL> 40177){
  2090. sindex = 8;
  2091. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("Gainloss = 2 dB\n"));
  2092. }
  2093. else if (40177 >= Power_GL && Power_GL> 37929){
  2094. sindex = 9;
  2095. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("Gainloss = 2.25 dB\n"));
  2096. }
  2097. else if (37929 >= Power_GL && Power_GL> 35807){
  2098. sindex = 10;
  2099. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("Gainloss = 2.5 dB\n"));
  2100. }
  2101. else if (35807 >= Power_GL && Power_GL> 33804){
  2102. sindex = 11;
  2103. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("Gainloss = 2.75 dB\n"));
  2104. }
  2105. else if (33804 >= Power_GL && Power_GL> 31913){
  2106. sindex = 12;
  2107. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("Gainloss = 3 dB\n"));
  2108. }
  2109. else if (31913 >= Power_GL && Power_GL> 30128){
  2110. sindex = 13;
  2111. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("Gainloss = 3.25 dB\n"));
  2112. }
  2113. else if (30128 >= Power_GL){
  2114. sindex = 14;
  2115. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("Gainloss = 3.5 dB\n"));
  2116. }
  2117. ODM_Write4Byte(pDM_Odm, 0xc98+pagesel, (Scaler[sindex] << 16) | Scaler[sindex]);
  2118. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("Set Gainloss reg 0xc98(0xe98)= 0x%x\n",ODM_Read4Byte(pDM_Odm, 0xc98+pagesel)));
  2119. }
  2120. VOID
  2121. _DPK_EnableDP(
  2122. IN PDM_ODM_T pDM_Odm,
  2123. IN u1Byte path,
  2124. IN u4Byte TXindex
  2125. )
  2126. {
  2127. //***************************************//
  2128. //Enable DP
  2129. //***************************************//
  2130. //PWSF[6] = 0x40 = 0dB, set the address represented TXindex as 0dB
  2131. u1Byte PWSF[] = { 0xff, 0xca, 0xa1, 0x80, 0x65, 0x51, 0x40, //6~0dB
  2132. 0x33, 0x28, 0x20, 0x19, 0x14, 0x10, 0x0d, //-1~-7dB
  2133. 0x0a, 0x08, 0x06, 0x05, 0x04, 0x03, 0x03, //-8~-14dB
  2134. 0x02, 0x02, 0x01, 0x01,
  2135. };
  2136. u1Byte zeropoint;
  2137. u1Byte pwsf1,pwsf2;
  2138. u1Byte i;
  2139. u4Byte pagesel = 0,regsel = 0;
  2140. if(path == 0)
  2141. {
  2142. pagesel = 0;
  2143. regsel = 0;
  2144. }
  2145. else
  2146. {
  2147. pagesel = 0x200;
  2148. regsel = 0x40;
  2149. }
  2150. //=========//
  2151. // DPK setting //
  2152. //=========//
  2153. // reg82c[31] = b'1, 切換到 page C1
  2154. ODM_Write4Byte(pDM_Odm, 0x82c, 0x802083d5);
  2155. ODM_Write4Byte(pDM_Odm, 0xc90+pagesel, 0x0000f098);
  2156. ODM_Write4Byte(pDM_Odm, 0xc94+pagesel, 0x776c9f84);
  2157. ODM_Write4Byte(pDM_Odm, 0xcc4+pagesel, 0x08840000);
  2158. ODM_Write4Byte(pDM_Odm, 0xcc8+pagesel, 0x20000000);
  2159. ODM_Write4Byte(pDM_Odm, 0xc8c+pagesel, 0x3c000000);
  2160. // 寫PWSF table in 1st SRAM for PA = 11 use
  2161. ODM_Write4Byte(pDM_Odm, 0xc20+pagesel, 0x00000800);
  2162. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("Write PWSF table\n"));
  2163. if(TXindex == 0x1f)
  2164. zeropoint = 0;
  2165. else if(TXindex == 0x1e)
  2166. zeropoint = 1;
  2167. else if(TXindex == 0x1d)
  2168. zeropoint = 2;
  2169. else if(TXindex == 0x1c)
  2170. zeropoint = 3;
  2171. else if(TXindex == 0x1b)
  2172. zeropoint = 4;
  2173. else if(TXindex == 0x1a)
  2174. zeropoint = 5;
  2175. else if(TXindex == 0x19)
  2176. zeropoint = 6;
  2177. else
  2178. zeropoint = 6;
  2179. for(i=0;i<16;i++)
  2180. {
  2181. if((6-zeropoint)+i*2 > 24)
  2182. pwsf1 = 24;
  2183. else
  2184. pwsf1 = (6-zeropoint)+i*2;
  2185. if((6-zeropoint-1)+i*2 > 24)
  2186. pwsf2 = 24;
  2187. else
  2188. pwsf2 = (6-zeropoint-1)+i*2;
  2189. ODM_Write4Byte(pDM_Odm, 0xce4+pagesel, 0x00000001 | i<<1 | (PWSF[pwsf1]<<8) | (PWSF[pwsf2]<<16));
  2190. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("0x%x\n", ODM_Read4Byte(pDM_Odm, 0xce4+pagesel)));
  2191. ODM_SetBBReg(pDM_Odm, 0xce4+pagesel, 0xff, 0x0);
  2192. }
  2193. ODM_Write4Byte(pDM_Odm, 0xce4+pagesel, 0x00000000);
  2194. // reg82c[31] = b'0, 切換到 page C
  2195. ODM_Write4Byte(pDM_Odm, 0x82c, 0x002083d5);
  2196. }
  2197. VOID
  2198. _DPK_pathABDPK(
  2199. IN PDM_ODM_T pDM_Odm
  2200. )
  2201. {
  2202. u4Byte TXindex = 0;
  2203. u1Byte path = 0;
  2204. u4Byte pagesel = 0,regsel = 0;
  2205. u4Byte i=0,j=0;
  2206. for(path=0;path<2;path ++) //path A = 0; path B = 1;
  2207. {
  2208. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("path %s DPK start!!!\n", (path==0)?"A":"B"));
  2209. if(path == 0)
  2210. {
  2211. pagesel = 0;
  2212. regsel = 0;
  2213. }
  2214. else
  2215. {
  2216. pagesel = 0x200;
  2217. regsel = 0x40;
  2218. }
  2219. //***************************************//
  2220. //find compress-2.5dB TX index
  2221. //***************************************//
  2222. // reg82c[31] = b'1, 切換到 page C1
  2223. ODM_Write4Byte(pDM_Odm, 0x82c, 0x802083d5);
  2224. // regc20[15:13] = dB sel, 告訴 Gain Loss function 去尋找 dB_sel 所設定的PA gain loss目標所對應的 Tx AGC 為何.
  2225. // dB_sel = b'000 ' 1.0 dB PA gain loss
  2226. // dB_sel = b'001 ' 1.5 dB PA gain loss
  2227. // dB_sel = b'010 ' 2.0 dB PA gain loss
  2228. // dB_sel = b'011 ' 2.5 dB PA gain loss
  2229. // dB_sel = b'100 ' 3.0 dB PA gain loss
  2230. // dB_sel = b'101 ' 3.5 dB PA gain loss
  2231. // dB_sel = b'110 ' 4.0 dB PA gain loss
  2232. ODM_Write4Byte(pDM_Odm, 0xc20+pagesel, 0x00006000);
  2233. ODM_Write4Byte(pDM_Odm, 0xc90+pagesel, 0x0401e038);
  2234. ODM_Write4Byte(pDM_Odm, 0xc94+pagesel, 0xf76c9f84);
  2235. ODM_Write4Byte(pDM_Odm, 0xcc8+pagesel, 0x000c5599);
  2236. ODM_Write4Byte(pDM_Odm, 0xcc4+pagesel, 0x148b0000);
  2237. ODM_Write4Byte(pDM_Odm, 0xc8c+pagesel, 0x3c000000);
  2238. // tx_amp ' 決定 Ramp 中各弦波的振幅大小
  2239. ODM_Write4Byte(pDM_Odm, 0xc98+pagesel, 0x41382e21);
  2240. ODM_Write4Byte(pDM_Odm, 0xc9c+pagesel, 0x5b554f48);
  2241. ODM_Write4Byte(pDM_Odm, 0xca0+pagesel, 0x6f6b6661);
  2242. ODM_Write4Byte(pDM_Odm, 0xca4+pagesel, 0x817d7874);
  2243. ODM_Write4Byte(pDM_Odm, 0xca8+pagesel, 0x908c8884);
  2244. ODM_Write4Byte(pDM_Odm, 0xcac+pagesel, 0x9d9a9793);
  2245. ODM_Write4Byte(pDM_Odm, 0xcb0+pagesel, 0xaaa7a4a1);
  2246. ODM_Write4Byte(pDM_Odm, 0xcb4+pagesel, 0xb6b3b0ad);
  2247. // tx_inverse ' Ramp 中各弦波power 的倒數, 以計算出 PA 的 gain report??
  2248. ODM_Write4Byte(pDM_Odm, 0xc40+pagesel, 0x02ce03e9);
  2249. ODM_Write4Byte(pDM_Odm, 0xc44+pagesel, 0x01fd0249);
  2250. ODM_Write4Byte(pDM_Odm, 0xc48+pagesel, 0x01a101c9);
  2251. ODM_Write4Byte(pDM_Odm, 0xc4c+pagesel, 0x016a0181);
  2252. ODM_Write4Byte(pDM_Odm, 0xc50+pagesel, 0x01430155);
  2253. ODM_Write4Byte(pDM_Odm, 0xc54+pagesel, 0x01270135);
  2254. ODM_Write4Byte(pDM_Odm, 0xc58+pagesel, 0x0112011c);
  2255. ODM_Write4Byte(pDM_Odm, 0xc5c+pagesel, 0x01000108);
  2256. ODM_Write4Byte(pDM_Odm, 0xc60+pagesel, 0x00f100f8);
  2257. ODM_Write4Byte(pDM_Odm, 0xc64+pagesel, 0x00e500eb);
  2258. ODM_Write4Byte(pDM_Odm, 0xc68+pagesel, 0x00db00e0);
  2259. ODM_Write4Byte(pDM_Odm, 0xc6c+pagesel, 0x00d100d5);
  2260. ODM_Write4Byte(pDM_Odm, 0xc70+pagesel, 0x00c900cd);
  2261. ODM_Write4Byte(pDM_Odm, 0xc74+pagesel, 0x00c200c5);
  2262. ODM_Write4Byte(pDM_Odm, 0xc78+pagesel, 0x00bb00be);
  2263. ODM_Write4Byte(pDM_Odm, 0xc7c+pagesel, 0x00b500b8);
  2264. //============//
  2265. // RF setting for DPK //
  2266. //============//
  2267. //pathA,pathB standby mode
  2268. ODM_SetRFReg(pDM_Odm, (ODM_RF_RADIO_PATH_E)0x0, 0x0, bRFRegOffsetMask, 0x10000);
  2269. ODM_SetRFReg(pDM_Odm, (ODM_RF_RADIO_PATH_E)0x1, 0x0, bRFRegOffsetMask, 0x10000);
  2270. // 00[4:0] = Tx AGC, 00[9:5] = Rx AGC (BB), 00[12:10] = Rx AGC (LNA)
  2271. ODM_SetRFReg(pDM_Odm, (ODM_RF_RADIO_PATH_E)(0x0+path), 0x0, bRFRegOffsetMask, 0x50bff);
  2272. // 64[14:12] = loop back attenuation
  2273. ODM_SetRFReg(pDM_Odm, (ODM_RF_RADIO_PATH_E)(0x0+path), 0x64, bRFRegOffsetMask, 0x19aac);
  2274. // 8f[14:13] = PGA2 gain
  2275. ODM_SetRFReg(pDM_Odm, (ODM_RF_RADIO_PATH_E)(0x0+path), 0x8f, bRFRegOffsetMask, 0x8e001);
  2276. // one shot
  2277. ODM_Write4Byte(pDM_Odm, 0xcc8+pagesel, 0x800c5599);
  2278. ODM_Write4Byte(pDM_Odm, 0xcc8+pagesel, 0x000c5599);
  2279. // delay 100 ms
  2280. ODM_delay_ms(100);
  2281. // read back
  2282. ODM_Write4Byte(pDM_Odm, 0xc90+pagesel, 0x0109f018);
  2283. ODM_Write4Byte(pDM_Odm, 0xcb8+pagesel, 0x09000000);
  2284. // 可以在 d00[3:0] 中讀回, dB_sel 中所設定的 gain loss 會落在哪一個 Tx AGC 設定
  2285. // 讀回d00[3:0] = h'1 ' Tx AGC = 15
  2286. // 讀回d00[3:0] = h'2 ' Tx AGC = 16
  2287. // 讀回d00[3:0] = h'3 ' Tx AGC = 17
  2288. // 讀回d00[3:0] = h'4 ' Tx AGC = 18
  2289. // 讀回d00[3:0] = h'5 ' Tx AGC = 19
  2290. // 讀回d00[3:0] = h'6 ' Tx AGC = 1a
  2291. // 讀回d00[3:0] = h'7 ' Tx AGC = 1b
  2292. // 讀回d00[3:0] = h'8 ' Tx AGC = 1c
  2293. // 讀回d00[3:0] = h'9 ' Tx AGC = 1d
  2294. // 讀回d00[3:0] = h'a ' Tx AGC = 1e
  2295. // 讀回d00[3:0] = h'b ' Tx AGC = 1f
  2296. TXindex = ODM_GetBBReg(pDM_Odm, 0xd00+regsel, 0x0000000f);
  2297. //***************************************//
  2298. //get LUT
  2299. //***************************************//
  2300. ODM_Write4Byte(pDM_Odm, 0xc90+pagesel, 0x0001e038);
  2301. ODM_Write4Byte(pDM_Odm, 0xc94+pagesel, 0xf76c9f84);
  2302. ODM_Write4Byte(pDM_Odm, 0xcc8+pagesel, 0x400c5599);
  2303. ODM_Write4Byte(pDM_Odm, 0xcc4+pagesel, 0x11930080); //0xcc4[9:4]= DPk fail threshold
  2304. ODM_Write4Byte(pDM_Odm, 0xc8c+pagesel, 0x3c000000);
  2305. // tx_amp ' 決定 Ramp 中各弦波的振幅大小
  2306. ODM_Write4Byte(pDM_Odm, 0xc98+pagesel, 0x41382e21);
  2307. ODM_Write4Byte(pDM_Odm, 0xc9c+pagesel, 0x5b554f48);
  2308. ODM_Write4Byte(pDM_Odm, 0xca0+pagesel, 0x6f6b6661);
  2309. ODM_Write4Byte(pDM_Odm, 0xca4+pagesel, 0x817d7874);
  2310. ODM_Write4Byte(pDM_Odm, 0xca8+pagesel, 0x908c8884);
  2311. ODM_Write4Byte(pDM_Odm, 0xcac+pagesel, 0x9d9a9793);
  2312. ODM_Write4Byte(pDM_Odm, 0xcb0+pagesel, 0xaaa7a4a1);
  2313. ODM_Write4Byte(pDM_Odm, 0xcb4+pagesel, 0xb6b3b0ad);
  2314. // tx_inverse ' Ramp 中各弦波power 的倒數, 以計算出 PA 的 gain
  2315. ODM_Write4Byte(pDM_Odm, 0xc40+pagesel, 0x02ce03e9);
  2316. ODM_Write4Byte(pDM_Odm, 0xc44+pagesel, 0x01fd0249);
  2317. ODM_Write4Byte(pDM_Odm, 0xc48+pagesel, 0x01a101c9);
  2318. ODM_Write4Byte(pDM_Odm, 0xc4c+pagesel, 0x016a0181);
  2319. ODM_Write4Byte(pDM_Odm, 0xc50+pagesel, 0x01430155);
  2320. ODM_Write4Byte(pDM_Odm, 0xc54+pagesel, 0x01270135);
  2321. ODM_Write4Byte(pDM_Odm, 0xc58+pagesel, 0x0112011c);
  2322. ODM_Write4Byte(pDM_Odm, 0xc5c+pagesel, 0x01000108);
  2323. ODM_Write4Byte(pDM_Odm, 0xc60+pagesel, 0x00f100f8);
  2324. ODM_Write4Byte(pDM_Odm, 0xc64+pagesel, 0x00e500eb);
  2325. ODM_Write4Byte(pDM_Odm, 0xc68+pagesel, 0x00db00e0);
  2326. ODM_Write4Byte(pDM_Odm, 0xc6c+pagesel, 0x00d100d5);
  2327. ODM_Write4Byte(pDM_Odm, 0xc70+pagesel, 0x00c900cd);
  2328. ODM_Write4Byte(pDM_Odm, 0xc74+pagesel, 0x00c200c5);
  2329. ODM_Write4Byte(pDM_Odm, 0xc78+pagesel, 0x00bb00be);
  2330. ODM_Write4Byte(pDM_Odm, 0xc7c+pagesel, 0x00b500b8);
  2331. //fill BB TX index for the DPK reference
  2332. // reg82c[31] =1b'0, 切換到 page C
  2333. ODM_Write4Byte(pDM_Odm, 0x82c, 0x002083d5);
  2334. ODM_Write4Byte(pDM_Odm, 0xc20+pagesel, 0x3c3c3c3c);
  2335. ODM_Write4Byte(pDM_Odm, 0xc24+pagesel, 0x3c3c3c3c);
  2336. ODM_Write4Byte(pDM_Odm, 0xc28+pagesel, 0x3c3c3c3c);
  2337. ODM_Write4Byte(pDM_Odm, 0xc2c+pagesel, 0x3c3c3c3c);
  2338. ODM_Write4Byte(pDM_Odm, 0xc30+pagesel, 0x3c3c3c3c);
  2339. ODM_Write4Byte(pDM_Odm, 0xc34+pagesel, 0x3c3c3c3c);
  2340. ODM_Write4Byte(pDM_Odm, 0xc38+pagesel, 0x3c3c3c3c);
  2341. ODM_Write4Byte(pDM_Odm, 0xc3c+pagesel, 0x3c3c3c3c);
  2342. ODM_Write4Byte(pDM_Odm, 0xc40+pagesel, 0x3c3c3c3c);
  2343. ODM_Write4Byte(pDM_Odm, 0xc44+pagesel, 0x3c3c3c3c);
  2344. ODM_Write4Byte(pDM_Odm, 0xc48+pagesel, 0x3c3c3c3c);
  2345. ODM_Write4Byte(pDM_Odm, 0xc4c+pagesel, 0x3c3c3c3c);
  2346. // reg82c[31] =1b'1, 切換到 page C1
  2347. ODM_Write4Byte(pDM_Odm, 0x82c, 0x802083d5);
  2348. // r_agc_boudary
  2349. // PA gain = 11 對應 tx_agc 從1f 到11 boundary = b'11111 ' PageC1 的 bc0[4:0] = 11111
  2350. // PA gain = 10 對應 tx_agc 從11 到11 ? boundary = b'10011 ' PageC1 的 bc0[9:5] = 10001
  2351. // PA gain = 01 對應 tx_agc 從10 到0e ? boundary = b'10000 ' PageC1 的 bc0[14:10] = 10000
  2352. // PA gain = 00 對應 tx_agc 從0d 到00 ? boundary = b'01101 ' PageC1 的 bc0[19:15] = 01101
  2353. ODM_Write4Byte(pDM_Odm, 0xcbc+pagesel, 0x0006c23f);
  2354. // r_bnd, 另外4塊 PWSF (power scaling factor) 的 boundary, 因為目前只有在 PA gain = 11 時才做補償, 所以設成 h'fffff 即可.
  2355. ODM_Write4Byte(pDM_Odm, 0xcb8+pagesel, 0x000fffff);
  2356. //============//
  2357. // RF setting for DPK //
  2358. //============//
  2359. // 00[4:0] = Tx AGC, 00[9:5] = Rx AGC (BB), 00[12:10] = Rx AGC (LNA)
  2360. // 此處 reg00[4:0] = h'1d, 是由前面 gain loss function 得到的結果.
  2361. ODM_SetRFReg(pDM_Odm, (ODM_RF_RADIO_PATH_E)(0x0+path), 0x0, bRFRegOffsetMask, 0x517e0 | TXindex);
  2362. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("RF 0x0 = 0x%x\n", 0x517e0 | TXindex));
  2363. // one shot
  2364. ODM_Write4Byte(pDM_Odm, 0xcc8+pagesel, 0xc00c5599);
  2365. ODM_Write4Byte(pDM_Odm, 0xcc8+pagesel, 0x400c5599);
  2366. // delay 100 ms
  2367. ODM_delay_ms(100);
  2368. // read back dp_fail report
  2369. ODM_Write4Byte(pDM_Odm, 0xcb8+pagesel, 0x00000000);
  2370. //if d00[6] = 1, DPK fail
  2371. if(ODM_GetBBReg(pDM_Odm, 0xd00+regsel, BIT6))
  2372. {
  2373. //bypass DPK
  2374. ODM_Write4Byte(pDM_Odm, 0xcc4+pagesel, 0x28848000);
  2375. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("path %s DPK fail!!!!!!!!!!!!!!!!!!!!!\n", (path==0)?"A":"B"));
  2376. return;
  2377. }
  2378. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("path %s DPK ok!!!!!!!!!!!!!!!!!!!!!\n", (path==0)?"A":"B"));
  2379. //read LMS table -->debug message only
  2380. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("read LMS\n"));
  2381. for(i=0;i<8;i++){
  2382. ODM_Write4Byte(pDM_Odm, 0xc90+pagesel, 0x0601f0b8+i);
  2383. for(j=0;j<4;j++){
  2384. ODM_Write4Byte(pDM_Odm, 0xcb8+pagesel, 0x09000000+(j<<24));
  2385. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("0x%x", ODM_Read4Byte(pDM_Odm, 0xd00+regsel)));
  2386. }
  2387. }
  2388. //***************************************//
  2389. //get gain loss
  2390. //***************************************//
  2391. _DPK_GetGainLoss(pDM_Odm,path);
  2392. //***************************************//
  2393. //Enable DP
  2394. //***************************************//
  2395. _DPK_EnableDP(pDM_Odm, path, TXindex);
  2396. }
  2397. }
  2398. VOID
  2399. phy_DPCalibrate_8812A(
  2400. IN PDM_ODM_T pDM_Odm
  2401. )
  2402. {
  2403. u4Byte backupRegAddrs[] = {
  2404. 0x970, 0xcb8, 0x838, 0xc00, 0x90c, 0xb00, 0xc94, 0x82c, 0x520, 0xc60, // 10
  2405. 0xc64, 0xc68, 0xc6c, 0xc70, 0xc74, 0xc78, 0xc7c, 0xc80, 0xc84, 0xc50, // 20
  2406. 0xc20, 0xc24, 0xc28, 0xc2c, 0xc30, 0xc34, 0xc38, 0xc3c, 0xc40, 0xc44, // 30
  2407. 0xc48, 0xc4c, 0xe50, 0xe20, 0xe24, 0xe28, 0xe2c, 0xe30, 0xe34, 0xe38, // 40
  2408. 0xe3c, 0xe40, 0xe44, 0xe48, 0xe4c, 0xeb8, 0xe00, 0xe94, 0xe60, 0xe64, //50
  2409. 0xe68, 0xe6c, 0xe70, 0xe74, 0xe78, 0xe7c, 0xe80, 0xe84
  2410. };
  2411. u4Byte backupRegData[sizeof(backupRegAddrs)/sizeof(u4Byte)];
  2412. //backup BB&MAC default value
  2413. _DPK_parabackup(pDM_Odm,backupRegAddrs, backupRegData, sizeof(backupRegAddrs)/sizeof(u4Byte));
  2414. //set global parameters
  2415. _DPK_Globalparaset(pDM_Odm);
  2416. //DPK
  2417. _DPK_pathABDPK(pDM_Odm);
  2418. // TH_DPK=thermalmeter
  2419. //reload BB&MAC defaul value;
  2420. _DPK_parareload(pDM_Odm,backupRegAddrs, backupRegData, sizeof(backupRegAddrs)/sizeof(u4Byte));
  2421. }
  2422. VOID
  2423. PHY_DPCalibrate_8812A(
  2424. IN PDM_ODM_T pDM_Odm
  2425. )
  2426. {
  2427. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("===> PHY_DPCalibrate_8812A\n"));
  2428. phy_DPCalibrate_8812A(pDM_Odm);
  2429. ODM_RT_TRACE(pDM_Odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, ("<=== PHY_DPCalibrate_8812A\n"));
  2430. }