phy.c 124 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2009-2010 Realtek Corporation.
  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. * The full GNU General Public License is included in this distribution in the
  19. * file called LICENSE.
  20. *
  21. * Contact Information:
  22. * wlanfae <wlanfae@realtek.com>
  23. * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
  24. * Hsinchu 300, Taiwan.
  25. *
  26. * Larry Finger <Larry.Finger@lwfinger.net>
  27. *
  28. *****************************************************************************/
  29. #include "../wifi.h"
  30. #include "../pci.h"
  31. #include "../ps.h"
  32. #include "reg.h"
  33. #include "def.h"
  34. #include "phy.h"
  35. #include "rf.h"
  36. #include "dm.h"
  37. #include "table.h"
  38. #include "sw.h"
  39. #include "hw.h"
  40. #define MAX_RF_IMR_INDEX 12
  41. #define MAX_RF_IMR_INDEX_NORMAL 13
  42. #define RF_REG_NUM_FOR_C_CUT_5G 6
  43. #define RF_REG_NUM_FOR_C_CUT_5G_INTERNALPA 7
  44. #define RF_REG_NUM_FOR_C_CUT_2G 5
  45. #define RF_CHNL_NUM_5G 19
  46. #define RF_CHNL_NUM_5G_40M 17
  47. #define TARGET_CHNL_NUM_5G 221
  48. #define TARGET_CHNL_NUM_2G 14
  49. #define CV_CURVE_CNT 64
  50. static u32 rf_reg_for_5g_swchnl_normal[MAX_RF_IMR_INDEX_NORMAL] = {
  51. 0, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x0
  52. };
  53. static u8 rf_reg_for_c_cut_5g[RF_REG_NUM_FOR_C_CUT_5G] = {
  54. RF_SYN_G1, RF_SYN_G2, RF_SYN_G3, RF_SYN_G4, RF_SYN_G5, RF_SYN_G6
  55. };
  56. static u8 rf_reg_for_c_cut_2g[RF_REG_NUM_FOR_C_CUT_2G] = {
  57. RF_SYN_G1, RF_SYN_G2, RF_SYN_G3, RF_SYN_G7, RF_SYN_G8
  58. };
  59. static u8 rf_for_c_cut_5g_internal_pa[RF_REG_NUM_FOR_C_CUT_5G_INTERNALPA] = {
  60. 0x0B, 0x48, 0x49, 0x4B, 0x03, 0x04, 0x0E
  61. };
  62. static u32 rf_reg_mask_for_c_cut_2g[RF_REG_NUM_FOR_C_CUT_2G] = {
  63. BIT(19) | BIT(18) | BIT(17) | BIT(14) | BIT(1),
  64. BIT(10) | BIT(9),
  65. BIT(18) | BIT(17) | BIT(16) | BIT(1),
  66. BIT(2) | BIT(1),
  67. BIT(15) | BIT(14) | BIT(13) | BIT(12) | BIT(11)
  68. };
  69. static u8 rf_chnl_5g[RF_CHNL_NUM_5G] = {
  70. 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108,
  71. 112, 116, 120, 124, 128, 132, 136, 140
  72. };
  73. static u8 rf_chnl_5g_40m[RF_CHNL_NUM_5G_40M] = {
  74. 38, 42, 46, 50, 54, 58, 62, 102, 106, 110, 114,
  75. 118, 122, 126, 130, 134, 138
  76. };
  77. static u32 rf_reg_pram_c_5g[5][RF_REG_NUM_FOR_C_CUT_5G] = {
  78. {0xE43BE, 0xFC638, 0x77C0A, 0xDE471, 0xd7110, 0x8EB04},
  79. {0xE43BE, 0xFC078, 0xF7C1A, 0xE0C71, 0xD7550, 0xAEB04},
  80. {0xE43BF, 0xFF038, 0xF7C0A, 0xDE471, 0xE5550, 0xAEB04},
  81. {0xE43BF, 0xFF079, 0xF7C1A, 0xDE471, 0xE5550, 0xAEB04},
  82. {0xE43BF, 0xFF038, 0xF7C1A, 0xDE471, 0xd7550, 0xAEB04}
  83. };
  84. static u32 rf_reg_param_for_c_cut_2g[3][RF_REG_NUM_FOR_C_CUT_2G] = {
  85. {0x643BC, 0xFC038, 0x77C1A, 0x41289, 0x01840},
  86. {0x643BC, 0xFC038, 0x07C1A, 0x41289, 0x01840},
  87. {0x243BC, 0xFC438, 0x07C1A, 0x4128B, 0x0FC41}
  88. };
  89. static u32 rf_syn_g4_for_c_cut_2g = 0xD1C31 & 0x7FF;
  90. static u32 rf_pram_c_5g_int_pa[3][RF_REG_NUM_FOR_C_CUT_5G_INTERNALPA] = {
  91. {0x01a00, 0x40443, 0x00eb5, 0x89bec, 0x94a12, 0x94a12, 0x94a12},
  92. {0x01800, 0xc0443, 0x00730, 0x896ee, 0x94a52, 0x94a52, 0x94a52},
  93. {0x01800, 0xc0443, 0x00730, 0x896ee, 0x94a12, 0x94a12, 0x94a12}
  94. };
  95. /* [mode][patha+b][reg] */
  96. static u32 rf_imr_param_normal[1][3][MAX_RF_IMR_INDEX_NORMAL] = {
  97. {
  98. /* channel 1-14. */
  99. {
  100. 0x70000, 0x00ff0, 0x4400f, 0x00ff0, 0x0, 0x0, 0x0,
  101. 0x0, 0x0, 0x64888, 0xe266c, 0x00090, 0x22fff
  102. },
  103. /* path 36-64 */
  104. {
  105. 0x70000, 0x22880, 0x4470f, 0x55880, 0x00070, 0x88000,
  106. 0x0, 0x88080, 0x70000, 0x64a82, 0xe466c, 0x00090,
  107. 0x32c9a
  108. },
  109. /* 100 -165 */
  110. {
  111. 0x70000, 0x44880, 0x4477f, 0x77880, 0x00070, 0x88000,
  112. 0x0, 0x880b0, 0x0, 0x64b82, 0xe466c, 0x00090, 0x32c9a
  113. }
  114. }
  115. };
  116. static u32 curveindex_5g[TARGET_CHNL_NUM_5G] = {0};
  117. static u32 curveindex_2g[TARGET_CHNL_NUM_2G] = {0};
  118. static u32 targetchnl_5g[TARGET_CHNL_NUM_5G] = {
  119. 25141, 25116, 25091, 25066, 25041,
  120. 25016, 24991, 24966, 24941, 24917,
  121. 24892, 24867, 24843, 24818, 24794,
  122. 24770, 24765, 24721, 24697, 24672,
  123. 24648, 24624, 24600, 24576, 24552,
  124. 24528, 24504, 24480, 24457, 24433,
  125. 24409, 24385, 24362, 24338, 24315,
  126. 24291, 24268, 24245, 24221, 24198,
  127. 24175, 24151, 24128, 24105, 24082,
  128. 24059, 24036, 24013, 23990, 23967,
  129. 23945, 23922, 23899, 23876, 23854,
  130. 23831, 23809, 23786, 23764, 23741,
  131. 23719, 23697, 23674, 23652, 23630,
  132. 23608, 23586, 23564, 23541, 23519,
  133. 23498, 23476, 23454, 23432, 23410,
  134. 23388, 23367, 23345, 23323, 23302,
  135. 23280, 23259, 23237, 23216, 23194,
  136. 23173, 23152, 23130, 23109, 23088,
  137. 23067, 23046, 23025, 23003, 22982,
  138. 22962, 22941, 22920, 22899, 22878,
  139. 22857, 22837, 22816, 22795, 22775,
  140. 22754, 22733, 22713, 22692, 22672,
  141. 22652, 22631, 22611, 22591, 22570,
  142. 22550, 22530, 22510, 22490, 22469,
  143. 22449, 22429, 22409, 22390, 22370,
  144. 22350, 22336, 22310, 22290, 22271,
  145. 22251, 22231, 22212, 22192, 22173,
  146. 22153, 22134, 22114, 22095, 22075,
  147. 22056, 22037, 22017, 21998, 21979,
  148. 21960, 21941, 21921, 21902, 21883,
  149. 21864, 21845, 21826, 21807, 21789,
  150. 21770, 21751, 21732, 21713, 21695,
  151. 21676, 21657, 21639, 21620, 21602,
  152. 21583, 21565, 21546, 21528, 21509,
  153. 21491, 21473, 21454, 21436, 21418,
  154. 21400, 21381, 21363, 21345, 21327,
  155. 21309, 21291, 21273, 21255, 21237,
  156. 21219, 21201, 21183, 21166, 21148,
  157. 21130, 21112, 21095, 21077, 21059,
  158. 21042, 21024, 21007, 20989, 20972,
  159. 25679, 25653, 25627, 25601, 25575,
  160. 25549, 25523, 25497, 25471, 25446,
  161. 25420, 25394, 25369, 25343, 25318,
  162. 25292, 25267, 25242, 25216, 25191,
  163. 25166
  164. };
  165. /* channel 1~14 */
  166. static u32 targetchnl_2g[TARGET_CHNL_NUM_2G] = {
  167. 26084, 26030, 25976, 25923, 25869, 25816, 25764,
  168. 25711, 25658, 25606, 25554, 25502, 25451, 25328
  169. };
  170. static u32 _rtl92d_phy_calculate_bit_shift(u32 bitmask)
  171. {
  172. u32 i;
  173. for (i = 0; i <= 31; i++) {
  174. if (((bitmask >> i) & 0x1) == 1)
  175. break;
  176. }
  177. return i;
  178. }
  179. u32 rtl92d_phy_query_bb_reg(struct ieee80211_hw *hw, u32 regaddr, u32 bitmask)
  180. {
  181. struct rtl_priv *rtlpriv = rtl_priv(hw);
  182. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  183. u32 returnvalue, originalvalue, bitshift;
  184. u8 dbi_direct;
  185. RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE, ("regaddr(%#x), "
  186. "bitmask(%#x)\n", regaddr, bitmask));
  187. if (rtlhal->during_mac1init_radioa || rtlhal->during_mac0init_radiob) {
  188. /* mac1 use phy0 read radio_b. */
  189. /* mac0 use phy1 read radio_b. */
  190. if (rtlhal->during_mac1init_radioa)
  191. dbi_direct = BIT(3);
  192. else if (rtlhal->during_mac0init_radiob)
  193. dbi_direct = BIT(3) | BIT(2);
  194. originalvalue = rtl92de_read_dword_dbi(hw, (u16)regaddr,
  195. dbi_direct);
  196. } else {
  197. originalvalue = rtl_read_dword(rtlpriv, regaddr);
  198. }
  199. bitshift = _rtl92d_phy_calculate_bit_shift(bitmask);
  200. returnvalue = (originalvalue & bitmask) >> bitshift;
  201. RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE, ("BBR MASK=0x%x "
  202. "Addr[0x%x]=0x%x\n", bitmask, regaddr, originalvalue));
  203. return returnvalue;
  204. }
  205. void rtl92d_phy_set_bb_reg(struct ieee80211_hw *hw,
  206. u32 regaddr, u32 bitmask, u32 data)
  207. {
  208. struct rtl_priv *rtlpriv = rtl_priv(hw);
  209. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  210. u8 dbi_direct = 0;
  211. u32 originalvalue, bitshift;
  212. RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE, ("regaddr(%#x), bitmask(%#x),"
  213. " data(%#x)\n", regaddr, bitmask, data));
  214. if (rtlhal->during_mac1init_radioa)
  215. dbi_direct = BIT(3);
  216. else if (rtlhal->during_mac0init_radiob)
  217. /* mac0 use phy1 write radio_b. */
  218. dbi_direct = BIT(3) | BIT(2);
  219. if (bitmask != BMASKDWORD) {
  220. if (rtlhal->during_mac1init_radioa ||
  221. rtlhal->during_mac0init_radiob)
  222. originalvalue = rtl92de_read_dword_dbi(hw,
  223. (u16) regaddr,
  224. dbi_direct);
  225. else
  226. originalvalue = rtl_read_dword(rtlpriv, regaddr);
  227. bitshift = _rtl92d_phy_calculate_bit_shift(bitmask);
  228. data = ((originalvalue & (~bitmask)) | (data << bitshift));
  229. }
  230. if (rtlhal->during_mac1init_radioa || rtlhal->during_mac0init_radiob)
  231. rtl92de_write_dword_dbi(hw, (u16) regaddr, data, dbi_direct);
  232. else
  233. rtl_write_dword(rtlpriv, regaddr, data);
  234. RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE, ("regaddr(%#x), bitmask(%#x),"
  235. " data(%#x)\n", regaddr, bitmask, data));
  236. }
  237. static u32 _rtl92d_phy_rf_serial_read(struct ieee80211_hw *hw,
  238. enum radio_path rfpath, u32 offset)
  239. {
  240. struct rtl_priv *rtlpriv = rtl_priv(hw);
  241. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  242. struct bb_reg_def *pphyreg = &rtlphy->phyreg_def[rfpath];
  243. u32 newoffset;
  244. u32 tmplong, tmplong2;
  245. u8 rfpi_enable = 0;
  246. u32 retvalue;
  247. newoffset = offset;
  248. tmplong = rtl_get_bbreg(hw, RFPGA0_XA_HSSIPARAMETER2, BMASKDWORD);
  249. if (rfpath == RF90_PATH_A)
  250. tmplong2 = tmplong;
  251. else
  252. tmplong2 = rtl_get_bbreg(hw, pphyreg->rfhssi_para2, BMASKDWORD);
  253. tmplong2 = (tmplong2 & (~BLSSIREADADDRESS)) |
  254. (newoffset << 23) | BLSSIREADEDGE;
  255. rtl_set_bbreg(hw, RFPGA0_XA_HSSIPARAMETER2, BMASKDWORD,
  256. tmplong & (~BLSSIREADEDGE));
  257. udelay(10);
  258. rtl_set_bbreg(hw, pphyreg->rfhssi_para2, BMASKDWORD, tmplong2);
  259. udelay(50);
  260. udelay(50);
  261. rtl_set_bbreg(hw, RFPGA0_XA_HSSIPARAMETER2, BMASKDWORD,
  262. tmplong | BLSSIREADEDGE);
  263. udelay(10);
  264. if (rfpath == RF90_PATH_A)
  265. rfpi_enable = (u8) rtl_get_bbreg(hw, RFPGA0_XA_HSSIPARAMETER1,
  266. BIT(8));
  267. else if (rfpath == RF90_PATH_B)
  268. rfpi_enable = (u8) rtl_get_bbreg(hw, RFPGA0_XB_HSSIPARAMETER1,
  269. BIT(8));
  270. if (rfpi_enable)
  271. retvalue = rtl_get_bbreg(hw, pphyreg->rflssi_readbackpi,
  272. BLSSIREADBACKDATA);
  273. else
  274. retvalue = rtl_get_bbreg(hw, pphyreg->rflssi_readback,
  275. BLSSIREADBACKDATA);
  276. RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE, ("RFR-%d Addr[0x%x] = 0x%x\n",
  277. rfpath, pphyreg->rflssi_readback, retvalue));
  278. return retvalue;
  279. }
  280. static void _rtl92d_phy_rf_serial_write(struct ieee80211_hw *hw,
  281. enum radio_path rfpath,
  282. u32 offset, u32 data)
  283. {
  284. u32 data_and_addr;
  285. u32 newoffset;
  286. struct rtl_priv *rtlpriv = rtl_priv(hw);
  287. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  288. struct bb_reg_def *pphyreg = &rtlphy->phyreg_def[rfpath];
  289. newoffset = offset;
  290. /* T65 RF */
  291. data_and_addr = ((newoffset << 20) | (data & 0x000fffff)) & 0x0fffffff;
  292. rtl_set_bbreg(hw, pphyreg->rf3wire_offset, BMASKDWORD, data_and_addr);
  293. RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE, ("RFW-%d Addr[0x%x]=0x%x\n",
  294. rfpath, pphyreg->rf3wire_offset, data_and_addr));
  295. }
  296. u32 rtl92d_phy_query_rf_reg(struct ieee80211_hw *hw,
  297. enum radio_path rfpath, u32 regaddr, u32 bitmask)
  298. {
  299. struct rtl_priv *rtlpriv = rtl_priv(hw);
  300. u32 original_value, readback_value, bitshift;
  301. unsigned long flags;
  302. RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE, ("regaddr(%#x), "
  303. "rfpath(%#x), bitmask(%#x)\n",
  304. regaddr, rfpath, bitmask));
  305. spin_lock_irqsave(&rtlpriv->locks.rf_lock, flags);
  306. original_value = _rtl92d_phy_rf_serial_read(hw, rfpath, regaddr);
  307. bitshift = _rtl92d_phy_calculate_bit_shift(bitmask);
  308. readback_value = (original_value & bitmask) >> bitshift;
  309. spin_unlock_irqrestore(&rtlpriv->locks.rf_lock, flags);
  310. RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE, ("regaddr(%#x), rfpath(%#x), "
  311. "bitmask(%#x), original_value(%#x)\n",
  312. regaddr, rfpath, bitmask, original_value));
  313. return readback_value;
  314. }
  315. void rtl92d_phy_set_rf_reg(struct ieee80211_hw *hw, enum radio_path rfpath,
  316. u32 regaddr, u32 bitmask, u32 data)
  317. {
  318. struct rtl_priv *rtlpriv = rtl_priv(hw);
  319. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  320. u32 original_value, bitshift;
  321. unsigned long flags;
  322. RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE,
  323. ("regaddr(%#x), bitmask(%#x), data(%#x), rfpath(%#x)\n",
  324. regaddr, bitmask, data, rfpath));
  325. if (bitmask == 0)
  326. return;
  327. spin_lock_irqsave(&rtlpriv->locks.rf_lock, flags);
  328. if (rtlphy->rf_mode != RF_OP_BY_FW) {
  329. if (bitmask != BRFREGOFFSETMASK) {
  330. original_value = _rtl92d_phy_rf_serial_read(hw,
  331. rfpath, regaddr);
  332. bitshift = _rtl92d_phy_calculate_bit_shift(bitmask);
  333. data = ((original_value & (~bitmask)) |
  334. (data << bitshift));
  335. }
  336. _rtl92d_phy_rf_serial_write(hw, rfpath, regaddr, data);
  337. }
  338. spin_unlock_irqrestore(&rtlpriv->locks.rf_lock, flags);
  339. RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE, ("regaddr(%#x), "
  340. "bitmask(%#x), data(%#x), rfpath(%#x)\n",
  341. regaddr, bitmask, data, rfpath));
  342. }
  343. bool rtl92d_phy_mac_config(struct ieee80211_hw *hw)
  344. {
  345. struct rtl_priv *rtlpriv = rtl_priv(hw);
  346. u32 i;
  347. u32 arraylength;
  348. u32 *ptrarray;
  349. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, ("Read Rtl819XMACPHY_Array\n"));
  350. arraylength = MAC_2T_ARRAYLENGTH;
  351. ptrarray = rtl8192de_mac_2tarray;
  352. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, ("Img:Rtl819XMAC_Array\n"));
  353. for (i = 0; i < arraylength; i = i + 2)
  354. rtl_write_byte(rtlpriv, ptrarray[i], (u8) ptrarray[i + 1]);
  355. if (rtlpriv->rtlhal.macphymode == SINGLEMAC_SINGLEPHY) {
  356. /* improve 2-stream TX EVM */
  357. /* rtl_write_byte(rtlpriv, 0x14,0x71); */
  358. /* AMPDU aggregation number 9 */
  359. /* rtl_write_word(rtlpriv, REG_MAX_AGGR_NUM, MAX_AGGR_NUM); */
  360. rtl_write_byte(rtlpriv, REG_MAX_AGGR_NUM, 0x0B);
  361. } else {
  362. /* 92D need to test to decide the num. */
  363. rtl_write_byte(rtlpriv, REG_MAX_AGGR_NUM, 0x07);
  364. }
  365. return true;
  366. }
  367. static void _rtl92d_phy_init_bb_rf_register_definition(struct ieee80211_hw *hw)
  368. {
  369. struct rtl_priv *rtlpriv = rtl_priv(hw);
  370. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  371. /* RF Interface Sowrtware Control */
  372. /* 16 LSBs if read 32-bit from 0x870 */
  373. rtlphy->phyreg_def[RF90_PATH_A].rfintfs = RFPGA0_XAB_RFINTERFACESW;
  374. /* 16 MSBs if read 32-bit from 0x870 (16-bit for 0x872) */
  375. rtlphy->phyreg_def[RF90_PATH_B].rfintfs = RFPGA0_XAB_RFINTERFACESW;
  376. /* 16 LSBs if read 32-bit from 0x874 */
  377. rtlphy->phyreg_def[RF90_PATH_C].rfintfs = RFPGA0_XCD_RFINTERFACESW;
  378. /* 16 MSBs if read 32-bit from 0x874 (16-bit for 0x876) */
  379. rtlphy->phyreg_def[RF90_PATH_D].rfintfs = RFPGA0_XCD_RFINTERFACESW;
  380. /* RF Interface Readback Value */
  381. /* 16 LSBs if read 32-bit from 0x8E0 */
  382. rtlphy->phyreg_def[RF90_PATH_A].rfintfi = RFPGA0_XAB_RFINTERFACERB;
  383. /* 16 MSBs if read 32-bit from 0x8E0 (16-bit for 0x8E2) */
  384. rtlphy->phyreg_def[RF90_PATH_B].rfintfi = RFPGA0_XAB_RFINTERFACERB;
  385. /* 16 LSBs if read 32-bit from 0x8E4 */
  386. rtlphy->phyreg_def[RF90_PATH_C].rfintfi = RFPGA0_XCD_RFINTERFACERB;
  387. /* 16 MSBs if read 32-bit from 0x8E4 (16-bit for 0x8E6) */
  388. rtlphy->phyreg_def[RF90_PATH_D].rfintfi = RFPGA0_XCD_RFINTERFACERB;
  389. /* RF Interface Output (and Enable) */
  390. /* 16 LSBs if read 32-bit from 0x860 */
  391. rtlphy->phyreg_def[RF90_PATH_A].rfintfo = RFPGA0_XA_RFINTERFACEOE;
  392. /* 16 LSBs if read 32-bit from 0x864 */
  393. rtlphy->phyreg_def[RF90_PATH_B].rfintfo = RFPGA0_XB_RFINTERFACEOE;
  394. /* RF Interface (Output and) Enable */
  395. /* 16 MSBs if read 32-bit from 0x860 (16-bit for 0x862) */
  396. rtlphy->phyreg_def[RF90_PATH_A].rfintfe = RFPGA0_XA_RFINTERFACEOE;
  397. /* 16 MSBs if read 32-bit from 0x864 (16-bit for 0x866) */
  398. rtlphy->phyreg_def[RF90_PATH_B].rfintfe = RFPGA0_XB_RFINTERFACEOE;
  399. /* Addr of LSSI. Wirte RF register by driver */
  400. /* LSSI Parameter */
  401. rtlphy->phyreg_def[RF90_PATH_A].rf3wire_offset =
  402. RFPGA0_XA_LSSIPARAMETER;
  403. rtlphy->phyreg_def[RF90_PATH_B].rf3wire_offset =
  404. RFPGA0_XB_LSSIPARAMETER;
  405. /* RF parameter */
  406. /* BB Band Select */
  407. rtlphy->phyreg_def[RF90_PATH_A].rflssi_select = RFPGA0_XAB_RFPARAMETER;
  408. rtlphy->phyreg_def[RF90_PATH_B].rflssi_select = RFPGA0_XAB_RFPARAMETER;
  409. rtlphy->phyreg_def[RF90_PATH_C].rflssi_select = RFPGA0_XCD_RFPARAMETER;
  410. rtlphy->phyreg_def[RF90_PATH_D].rflssi_select = RFPGA0_XCD_RFPARAMETER;
  411. /* Tx AGC Gain Stage (same for all path. Should we remove this?) */
  412. /* Tx gain stage */
  413. rtlphy->phyreg_def[RF90_PATH_A].rftxgain_stage = RFPGA0_TXGAINSTAGE;
  414. /* Tx gain stage */
  415. rtlphy->phyreg_def[RF90_PATH_B].rftxgain_stage = RFPGA0_TXGAINSTAGE;
  416. /* Tx gain stage */
  417. rtlphy->phyreg_def[RF90_PATH_C].rftxgain_stage = RFPGA0_TXGAINSTAGE;
  418. /* Tx gain stage */
  419. rtlphy->phyreg_def[RF90_PATH_D].rftxgain_stage = RFPGA0_TXGAINSTAGE;
  420. /* Tranceiver A~D HSSI Parameter-1 */
  421. /* wire control parameter1 */
  422. rtlphy->phyreg_def[RF90_PATH_A].rfhssi_para1 = RFPGA0_XA_HSSIPARAMETER1;
  423. /* wire control parameter1 */
  424. rtlphy->phyreg_def[RF90_PATH_B].rfhssi_para1 = RFPGA0_XB_HSSIPARAMETER1;
  425. /* Tranceiver A~D HSSI Parameter-2 */
  426. /* wire control parameter2 */
  427. rtlphy->phyreg_def[RF90_PATH_A].rfhssi_para2 = RFPGA0_XA_HSSIPARAMETER2;
  428. /* wire control parameter2 */
  429. rtlphy->phyreg_def[RF90_PATH_B].rfhssi_para2 = RFPGA0_XB_HSSIPARAMETER2;
  430. /* RF switch Control */
  431. /* TR/Ant switch control */
  432. rtlphy->phyreg_def[RF90_PATH_A].rfswitch_control =
  433. RFPGA0_XAB_SWITCHCONTROL;
  434. rtlphy->phyreg_def[RF90_PATH_B].rfswitch_control =
  435. RFPGA0_XAB_SWITCHCONTROL;
  436. rtlphy->phyreg_def[RF90_PATH_C].rfswitch_control =
  437. RFPGA0_XCD_SWITCHCONTROL;
  438. rtlphy->phyreg_def[RF90_PATH_D].rfswitch_control =
  439. RFPGA0_XCD_SWITCHCONTROL;
  440. /* AGC control 1 */
  441. rtlphy->phyreg_def[RF90_PATH_A].rfagc_control1 = ROFDM0_XAAGCCORE1;
  442. rtlphy->phyreg_def[RF90_PATH_B].rfagc_control1 = ROFDM0_XBAGCCORE1;
  443. rtlphy->phyreg_def[RF90_PATH_C].rfagc_control1 = ROFDM0_XCAGCCORE1;
  444. rtlphy->phyreg_def[RF90_PATH_D].rfagc_control1 = ROFDM0_XDAGCCORE1;
  445. /* AGC control 2 */
  446. rtlphy->phyreg_def[RF90_PATH_A].rfagc_control2 = ROFDM0_XAAGCCORE2;
  447. rtlphy->phyreg_def[RF90_PATH_B].rfagc_control2 = ROFDM0_XBAGCCORE2;
  448. rtlphy->phyreg_def[RF90_PATH_C].rfagc_control2 = ROFDM0_XCAGCCORE2;
  449. rtlphy->phyreg_def[RF90_PATH_D].rfagc_control2 = ROFDM0_XDAGCCORE2;
  450. /* RX AFE control 1 */
  451. rtlphy->phyreg_def[RF90_PATH_A].rfrxiq_imbalance =
  452. ROFDM0_XARXIQIMBALANCE;
  453. rtlphy->phyreg_def[RF90_PATH_B].rfrxiq_imbalance =
  454. ROFDM0_XBRXIQIMBALANCE;
  455. rtlphy->phyreg_def[RF90_PATH_C].rfrxiq_imbalance =
  456. ROFDM0_XCRXIQIMBALANCE;
  457. rtlphy->phyreg_def[RF90_PATH_D].rfrxiq_imbalance =
  458. ROFDM0_XDRXIQIMBALANCE;
  459. /*RX AFE control 1 */
  460. rtlphy->phyreg_def[RF90_PATH_A].rfrx_afe = ROFDM0_XARXAFE;
  461. rtlphy->phyreg_def[RF90_PATH_B].rfrx_afe = ROFDM0_XBRXAFE;
  462. rtlphy->phyreg_def[RF90_PATH_C].rfrx_afe = ROFDM0_XCRXAFE;
  463. rtlphy->phyreg_def[RF90_PATH_D].rfrx_afe = ROFDM0_XDRXAFE;
  464. /* Tx AFE control 1 */
  465. rtlphy->phyreg_def[RF90_PATH_A].rftxiq_imbalance =
  466. ROFDM0_XATxIQIMBALANCE;
  467. rtlphy->phyreg_def[RF90_PATH_B].rftxiq_imbalance =
  468. ROFDM0_XBTxIQIMBALANCE;
  469. rtlphy->phyreg_def[RF90_PATH_C].rftxiq_imbalance =
  470. ROFDM0_XCTxIQIMBALANCE;
  471. rtlphy->phyreg_def[RF90_PATH_D].rftxiq_imbalance =
  472. ROFDM0_XDTxIQIMBALANCE;
  473. /* Tx AFE control 2 */
  474. rtlphy->phyreg_def[RF90_PATH_A].rftx_afe = ROFDM0_XATxAFE;
  475. rtlphy->phyreg_def[RF90_PATH_B].rftx_afe = ROFDM0_XBTxAFE;
  476. rtlphy->phyreg_def[RF90_PATH_C].rftx_afe = ROFDM0_XCTxAFE;
  477. rtlphy->phyreg_def[RF90_PATH_D].rftx_afe = ROFDM0_XDTxAFE;
  478. /* Tranceiver LSSI Readback SI mode */
  479. rtlphy->phyreg_def[RF90_PATH_A].rflssi_readback =
  480. RFPGA0_XA_LSSIREADBACK;
  481. rtlphy->phyreg_def[RF90_PATH_B].rflssi_readback =
  482. RFPGA0_XB_LSSIREADBACK;
  483. rtlphy->phyreg_def[RF90_PATH_C].rflssi_readback =
  484. RFPGA0_XC_LSSIREADBACK;
  485. rtlphy->phyreg_def[RF90_PATH_D].rflssi_readback =
  486. RFPGA0_XD_LSSIREADBACK;
  487. /* Tranceiver LSSI Readback PI mode */
  488. rtlphy->phyreg_def[RF90_PATH_A].rflssi_readbackpi =
  489. TRANSCEIVERA_HSPI_READBACK;
  490. rtlphy->phyreg_def[RF90_PATH_B].rflssi_readbackpi =
  491. TRANSCEIVERB_HSPI_READBACK;
  492. }
  493. static bool _rtl92d_phy_config_bb_with_headerfile(struct ieee80211_hw *hw,
  494. u8 configtype)
  495. {
  496. int i;
  497. u32 *phy_regarray_table;
  498. u32 *agctab_array_table = NULL;
  499. u32 *agctab_5garray_table;
  500. u16 phy_reg_arraylen, agctab_arraylen = 0, agctab_5garraylen;
  501. struct rtl_priv *rtlpriv = rtl_priv(hw);
  502. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  503. /* Normal chip,Mac0 use AGC_TAB.txt for 2G and 5G band. */
  504. if (rtlhal->interfaceindex == 0) {
  505. agctab_arraylen = AGCTAB_ARRAYLENGTH;
  506. agctab_array_table = rtl8192de_agctab_array;
  507. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  508. (" ===> phy:MAC0, Rtl819XAGCTAB_Array\n"));
  509. } else {
  510. if (rtlhal->current_bandtype == BAND_ON_2_4G) {
  511. agctab_arraylen = AGCTAB_2G_ARRAYLENGTH;
  512. agctab_array_table = rtl8192de_agctab_2garray;
  513. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  514. (" ===> phy:MAC1, Rtl819XAGCTAB_2GArray\n"));
  515. } else {
  516. agctab_5garraylen = AGCTAB_5G_ARRAYLENGTH;
  517. agctab_5garray_table = rtl8192de_agctab_5garray;
  518. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  519. (" ===> phy:MAC1, Rtl819XAGCTAB_5GArray\n"));
  520. }
  521. }
  522. phy_reg_arraylen = PHY_REG_2T_ARRAYLENGTH;
  523. phy_regarray_table = rtl8192de_phy_reg_2tarray;
  524. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  525. (" ===> phy:Rtl819XPHY_REG_Array_PG\n"));
  526. if (configtype == BASEBAND_CONFIG_PHY_REG) {
  527. for (i = 0; i < phy_reg_arraylen; i = i + 2) {
  528. if (phy_regarray_table[i] == 0xfe)
  529. mdelay(50);
  530. else if (phy_regarray_table[i] == 0xfd)
  531. mdelay(5);
  532. else if (phy_regarray_table[i] == 0xfc)
  533. mdelay(1);
  534. else if (phy_regarray_table[i] == 0xfb)
  535. udelay(50);
  536. else if (phy_regarray_table[i] == 0xfa)
  537. udelay(5);
  538. else if (phy_regarray_table[i] == 0xf9)
  539. udelay(1);
  540. rtl_set_bbreg(hw, phy_regarray_table[i], BMASKDWORD,
  541. phy_regarray_table[i + 1]);
  542. udelay(1);
  543. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  544. ("The phy_regarray_table[0] is %x"
  545. " Rtl819XPHY_REGArray[1] is %x\n",
  546. phy_regarray_table[i],
  547. phy_regarray_table[i + 1]));
  548. }
  549. } else if (configtype == BASEBAND_CONFIG_AGC_TAB) {
  550. if (rtlhal->interfaceindex == 0) {
  551. for (i = 0; i < agctab_arraylen; i = i + 2) {
  552. rtl_set_bbreg(hw, agctab_array_table[i],
  553. BMASKDWORD,
  554. agctab_array_table[i + 1]);
  555. /* Add 1us delay between BB/RF register
  556. * setting. */
  557. udelay(1);
  558. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  559. ("The Rtl819XAGCTAB_Array_"
  560. "Table[0] is %ul "
  561. "Rtl819XPHY_REGArray[1] is %ul\n",
  562. agctab_array_table[i],
  563. agctab_array_table[i + 1]));
  564. }
  565. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  566. ("Normal Chip, MAC0, load "
  567. "Rtl819XAGCTAB_Array\n"));
  568. } else {
  569. if (rtlhal->current_bandtype == BAND_ON_2_4G) {
  570. for (i = 0; i < agctab_arraylen; i = i + 2) {
  571. rtl_set_bbreg(hw, agctab_array_table[i],
  572. BMASKDWORD,
  573. agctab_array_table[i + 1]);
  574. /* Add 1us delay between BB/RF register
  575. * setting. */
  576. udelay(1);
  577. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  578. ("The Rtl819XAGCTAB_Array_"
  579. "Table[0] is %ul Rtl819XPHY_"
  580. "REGArray[1] is %ul\n",
  581. agctab_array_table[i],
  582. agctab_array_table[i + 1]));
  583. }
  584. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  585. ("Load Rtl819XAGCTAB_2GArray\n"));
  586. } else {
  587. for (i = 0; i < agctab_5garraylen; i = i + 2) {
  588. rtl_set_bbreg(hw,
  589. agctab_5garray_table[i],
  590. BMASKDWORD,
  591. agctab_5garray_table[i + 1]);
  592. /* Add 1us delay between BB/RF registeri
  593. * setting. */
  594. udelay(1);
  595. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  596. ("The Rtl819XAGCTAB_5GArray_"
  597. "Table[0] is %ul Rtl819XPHY_"
  598. "REGArray[1] is %ul\n",
  599. agctab_5garray_table[i],
  600. agctab_5garray_table[i + 1]));
  601. }
  602. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  603. ("Load Rtl819XAGCTAB_5GArray\n"));
  604. }
  605. }
  606. }
  607. return true;
  608. }
  609. static void _rtl92d_store_pwrindex_diffrate_offset(struct ieee80211_hw *hw,
  610. u32 regaddr, u32 bitmask,
  611. u32 data)
  612. {
  613. struct rtl_priv *rtlpriv = rtl_priv(hw);
  614. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  615. if (regaddr == RTXAGC_A_RATE18_06) {
  616. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][0] =
  617. data;
  618. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  619. ("MCSTxPowerLevelOriginalOffset[%d][0] = 0x%ulx\n",
  620. rtlphy->pwrgroup_cnt,
  621. rtlphy->mcs_txpwrlevel_origoffset
  622. [rtlphy->pwrgroup_cnt][0]));
  623. }
  624. if (regaddr == RTXAGC_A_RATE54_24) {
  625. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][1] =
  626. data;
  627. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  628. ("MCSTxPowerLevelOriginalOffset[%d][1] = 0x%ulx\n",
  629. rtlphy->pwrgroup_cnt,
  630. rtlphy->mcs_txpwrlevel_origoffset
  631. [rtlphy->pwrgroup_cnt][1]));
  632. }
  633. if (regaddr == RTXAGC_A_CCK1_MCS32) {
  634. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][6] =
  635. data;
  636. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  637. ("MCSTxPowerLevelOriginalOffset[%d][6] = 0x%ulx\n",
  638. rtlphy->pwrgroup_cnt,
  639. rtlphy->mcs_txpwrlevel_origoffset
  640. [rtlphy->pwrgroup_cnt][6]));
  641. }
  642. if (regaddr == RTXAGC_B_CCK11_A_CCK2_11 && bitmask == 0xffffff00) {
  643. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][7] =
  644. data;
  645. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  646. ("MCSTxPowerLevelOriginalOffset[%d][7] = 0x%ulx\n",
  647. rtlphy->pwrgroup_cnt,
  648. rtlphy->mcs_txpwrlevel_origoffset
  649. [rtlphy->pwrgroup_cnt][7]));
  650. }
  651. if (regaddr == RTXAGC_A_MCS03_MCS00) {
  652. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][2] =
  653. data;
  654. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  655. ("MCSTxPowerLevelOriginalOffset[%d][2] = 0x%ulx\n",
  656. rtlphy->pwrgroup_cnt,
  657. rtlphy->mcs_txpwrlevel_origoffset
  658. [rtlphy->pwrgroup_cnt][2]));
  659. }
  660. if (regaddr == RTXAGC_A_MCS07_MCS04) {
  661. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][3] =
  662. data;
  663. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  664. ("MCSTxPowerLevelOriginalOffset[%d][3] = 0x%ulx\n",
  665. rtlphy->pwrgroup_cnt,
  666. rtlphy->mcs_txpwrlevel_origoffset
  667. [rtlphy->pwrgroup_cnt][3]));
  668. }
  669. if (regaddr == RTXAGC_A_MCS11_MCS08) {
  670. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][4] =
  671. data;
  672. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  673. ("MCSTxPowerLevelOriginalOffset[%d][4] = 0x%ulx\n",
  674. rtlphy->pwrgroup_cnt,
  675. rtlphy->mcs_txpwrlevel_origoffset
  676. [rtlphy->pwrgroup_cnt][4]));
  677. }
  678. if (regaddr == RTXAGC_A_MCS15_MCS12) {
  679. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][5] =
  680. data;
  681. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  682. ("MCSTxPowerLevelOriginalOffset[%d][5] = 0x%ulx\n",
  683. rtlphy->pwrgroup_cnt,
  684. rtlphy->mcs_txpwrlevel_origoffset
  685. [rtlphy->pwrgroup_cnt][5]));
  686. }
  687. if (regaddr == RTXAGC_B_RATE18_06) {
  688. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][8] =
  689. data;
  690. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  691. ("MCSTxPowerLevelOriginalOffset[%d][8] = 0x%ulx\n",
  692. rtlphy->pwrgroup_cnt,
  693. rtlphy->mcs_txpwrlevel_origoffset
  694. [rtlphy->pwrgroup_cnt][8]));
  695. }
  696. if (regaddr == RTXAGC_B_RATE54_24) {
  697. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][9] =
  698. data;
  699. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  700. ("MCSTxPowerLevelOriginalOffset[%d][9] = 0x%ulx\n",
  701. rtlphy->pwrgroup_cnt,
  702. rtlphy->mcs_txpwrlevel_origoffset
  703. [rtlphy->pwrgroup_cnt][9]));
  704. }
  705. if (regaddr == RTXAGC_B_CCK1_55_MCS32) {
  706. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][14] =
  707. data;
  708. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  709. ("MCSTxPowerLevelOriginalOffset[%d][14] = 0x%ulx\n",
  710. rtlphy->pwrgroup_cnt,
  711. rtlphy->mcs_txpwrlevel_origoffset
  712. [rtlphy->pwrgroup_cnt][14]));
  713. }
  714. if (regaddr == RTXAGC_B_CCK11_A_CCK2_11 && bitmask == 0x000000ff) {
  715. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][15] =
  716. data;
  717. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  718. ("MCSTxPowerLevelOriginalOffset[%d][15] = 0x%ulx\n",
  719. rtlphy->pwrgroup_cnt,
  720. rtlphy->mcs_txpwrlevel_origoffset
  721. [rtlphy->pwrgroup_cnt][15]));
  722. }
  723. if (regaddr == RTXAGC_B_MCS03_MCS00) {
  724. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][10] =
  725. data;
  726. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  727. ("MCSTxPowerLevelOriginalOffset[%d][10] = 0x%ulx\n",
  728. rtlphy->pwrgroup_cnt,
  729. rtlphy->mcs_txpwrlevel_origoffset
  730. [rtlphy->pwrgroup_cnt][10]));
  731. }
  732. if (regaddr == RTXAGC_B_MCS07_MCS04) {
  733. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][11] =
  734. data;
  735. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  736. ("MCSTxPowerLevelOriginalOffset[%d][11] = 0x%ulx\n",
  737. rtlphy->pwrgroup_cnt,
  738. rtlphy->mcs_txpwrlevel_origoffset
  739. [rtlphy->pwrgroup_cnt][11]));
  740. }
  741. if (regaddr == RTXAGC_B_MCS11_MCS08) {
  742. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][12] =
  743. data;
  744. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  745. ("MCSTxPowerLevelOriginalOffset[%d][12] = 0x%ulx\n",
  746. rtlphy->pwrgroup_cnt,
  747. rtlphy->mcs_txpwrlevel_origoffset
  748. [rtlphy->pwrgroup_cnt][12]));
  749. }
  750. if (regaddr == RTXAGC_B_MCS15_MCS12) {
  751. rtlphy->mcs_txpwrlevel_origoffset[rtlphy->pwrgroup_cnt][13] =
  752. data;
  753. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  754. ("MCSTxPowerLevelOriginalOffset[%d][13] = 0x%ulx\n",
  755. rtlphy->pwrgroup_cnt,
  756. rtlphy->mcs_txpwrlevel_origoffset
  757. [rtlphy->pwrgroup_cnt][13]));
  758. rtlphy->pwrgroup_cnt++;
  759. }
  760. }
  761. static bool _rtl92d_phy_config_bb_with_pgheaderfile(struct ieee80211_hw *hw,
  762. u8 configtype)
  763. {
  764. struct rtl_priv *rtlpriv = rtl_priv(hw);
  765. int i;
  766. u32 *phy_regarray_table_pg;
  767. u16 phy_regarray_pg_len;
  768. phy_regarray_pg_len = PHY_REG_ARRAY_PG_LENGTH;
  769. phy_regarray_table_pg = rtl8192de_phy_reg_array_pg;
  770. if (configtype == BASEBAND_CONFIG_PHY_REG) {
  771. for (i = 0; i < phy_regarray_pg_len; i = i + 3) {
  772. if (phy_regarray_table_pg[i] == 0xfe)
  773. mdelay(50);
  774. else if (phy_regarray_table_pg[i] == 0xfd)
  775. mdelay(5);
  776. else if (phy_regarray_table_pg[i] == 0xfc)
  777. mdelay(1);
  778. else if (phy_regarray_table_pg[i] == 0xfb)
  779. udelay(50);
  780. else if (phy_regarray_table_pg[i] == 0xfa)
  781. udelay(5);
  782. else if (phy_regarray_table_pg[i] == 0xf9)
  783. udelay(1);
  784. _rtl92d_store_pwrindex_diffrate_offset(hw,
  785. phy_regarray_table_pg[i],
  786. phy_regarray_table_pg[i + 1],
  787. phy_regarray_table_pg[i + 2]);
  788. }
  789. } else {
  790. RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
  791. ("configtype != BaseBand_Config_PHY_REG\n"));
  792. }
  793. return true;
  794. }
  795. static bool _rtl92d_phy_bb_config(struct ieee80211_hw *hw)
  796. {
  797. struct rtl_priv *rtlpriv = rtl_priv(hw);
  798. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  799. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  800. bool rtstatus = true;
  801. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, ("==>\n"));
  802. rtstatus = _rtl92d_phy_config_bb_with_headerfile(hw,
  803. BASEBAND_CONFIG_PHY_REG);
  804. if (rtstatus != true) {
  805. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, ("Write BB Reg Fail!!"));
  806. return false;
  807. }
  808. /* if (rtlphy->rf_type == RF_1T2R) {
  809. * _rtl92c_phy_bb_config_1t(hw);
  810. * RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, ("Config to 1T!!\n"));
  811. *} */
  812. if (rtlefuse->autoload_failflag == false) {
  813. rtlphy->pwrgroup_cnt = 0;
  814. rtstatus = _rtl92d_phy_config_bb_with_pgheaderfile(hw,
  815. BASEBAND_CONFIG_PHY_REG);
  816. }
  817. if (rtstatus != true) {
  818. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, ("BB_PG Reg Fail!!"));
  819. return false;
  820. }
  821. rtstatus = _rtl92d_phy_config_bb_with_headerfile(hw,
  822. BASEBAND_CONFIG_AGC_TAB);
  823. if (rtstatus != true) {
  824. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, ("AGC Table Fail\n"));
  825. return false;
  826. }
  827. rtlphy->cck_high_power = (bool) (rtl_get_bbreg(hw,
  828. RFPGA0_XA_HSSIPARAMETER2, 0x200));
  829. return true;
  830. }
  831. bool rtl92d_phy_bb_config(struct ieee80211_hw *hw)
  832. {
  833. struct rtl_priv *rtlpriv = rtl_priv(hw);
  834. u16 regval;
  835. u32 regvaldw;
  836. u8 value;
  837. _rtl92d_phy_init_bb_rf_register_definition(hw);
  838. regval = rtl_read_word(rtlpriv, REG_SYS_FUNC_EN);
  839. rtl_write_word(rtlpriv, REG_SYS_FUNC_EN,
  840. regval | BIT(13) | BIT(0) | BIT(1));
  841. rtl_write_byte(rtlpriv, REG_AFE_PLL_CTRL, 0x83);
  842. rtl_write_byte(rtlpriv, REG_AFE_PLL_CTRL + 1, 0xdb);
  843. /* 0x1f bit7 bit6 represent for mac0/mac1 driver ready */
  844. value = rtl_read_byte(rtlpriv, REG_RF_CTRL);
  845. rtl_write_byte(rtlpriv, REG_RF_CTRL, value | RF_EN | RF_RSTB |
  846. RF_SDMRSTB);
  847. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, FEN_PPLL | FEN_PCIEA |
  848. FEN_DIO_PCIE | FEN_BB_GLB_RSTn | FEN_BBRSTB);
  849. rtl_write_byte(rtlpriv, REG_AFE_XTAL_CTRL + 1, 0x80);
  850. if (!(IS_92D_SINGLEPHY(rtlpriv->rtlhal.version))) {
  851. regvaldw = rtl_read_dword(rtlpriv, REG_LEDCFG0);
  852. rtl_write_dword(rtlpriv, REG_LEDCFG0, regvaldw | BIT(23));
  853. }
  854. return _rtl92d_phy_bb_config(hw);
  855. }
  856. bool rtl92d_phy_rf_config(struct ieee80211_hw *hw)
  857. {
  858. return rtl92d_phy_rf6052_config(hw);
  859. }
  860. bool rtl92d_phy_config_rf_with_headerfile(struct ieee80211_hw *hw,
  861. enum rf_content content,
  862. enum radio_path rfpath)
  863. {
  864. int i, j;
  865. u32 *radioa_array_table;
  866. u32 *radiob_array_table;
  867. u16 radioa_arraylen, radiob_arraylen;
  868. struct rtl_priv *rtlpriv = rtl_priv(hw);
  869. radioa_arraylen = RADIOA_2T_ARRAYLENGTH;
  870. radioa_array_table = rtl8192de_radioa_2tarray;
  871. radiob_arraylen = RADIOB_2T_ARRAYLENGTH;
  872. radiob_array_table = rtl8192de_radiob_2tarray;
  873. if (rtlpriv->efuse.internal_pa_5g[0]) {
  874. radioa_arraylen = RADIOA_2T_INT_PA_ARRAYLENGTH;
  875. radioa_array_table = rtl8192de_radioa_2t_int_paarray;
  876. }
  877. if (rtlpriv->efuse.internal_pa_5g[1]) {
  878. radiob_arraylen = RADIOB_2T_INT_PA_ARRAYLENGTH;
  879. radiob_array_table = rtl8192de_radiob_2t_int_paarray;
  880. }
  881. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  882. ("PHY_ConfigRFWithHeaderFile() "
  883. "Radio_A:Rtl819XRadioA_1TArray\n"));
  884. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  885. ("PHY_ConfigRFWithHeaderFile() "
  886. "Radio_B:Rtl819XRadioB_1TArray\n"));
  887. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, ("Radio No %x\n", rfpath));
  888. /* this only happens when DMDP, mac0 start on 2.4G,
  889. * mac1 start on 5G, mac 0 has to set phy0&phy1
  890. * pathA or mac1 has to set phy0&phy1 pathA */
  891. if ((content == radiob_txt) && (rfpath == RF90_PATH_A)) {
  892. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  893. (" ===> althougth Path A, we load radiob.txt\n"));
  894. radioa_arraylen = radiob_arraylen;
  895. radioa_array_table = radiob_array_table;
  896. }
  897. switch (rfpath) {
  898. case RF90_PATH_A:
  899. for (i = 0; i < radioa_arraylen; i = i + 2) {
  900. if (radioa_array_table[i] == 0xfe) {
  901. mdelay(50);
  902. } else if (radioa_array_table[i] == 0xfd) {
  903. /* delay_ms(5); */
  904. for (j = 0; j < 100; j++)
  905. udelay(MAX_STALL_TIME);
  906. } else if (radioa_array_table[i] == 0xfc) {
  907. /* delay_ms(1); */
  908. for (j = 0; j < 20; j++)
  909. udelay(MAX_STALL_TIME);
  910. } else if (radioa_array_table[i] == 0xfb) {
  911. udelay(50);
  912. } else if (radioa_array_table[i] == 0xfa) {
  913. udelay(5);
  914. } else if (radioa_array_table[i] == 0xf9) {
  915. udelay(1);
  916. } else {
  917. rtl_set_rfreg(hw, rfpath, radioa_array_table[i],
  918. BRFREGOFFSETMASK,
  919. radioa_array_table[i + 1]);
  920. /* Add 1us delay between BB/RF register set. */
  921. udelay(1);
  922. }
  923. }
  924. break;
  925. case RF90_PATH_B:
  926. for (i = 0; i < radiob_arraylen; i = i + 2) {
  927. if (radiob_array_table[i] == 0xfe) {
  928. /* Delay specific ms. Only RF configuration
  929. * requires delay. */
  930. mdelay(50);
  931. } else if (radiob_array_table[i] == 0xfd) {
  932. /* delay_ms(5); */
  933. for (j = 0; j < 100; j++)
  934. udelay(MAX_STALL_TIME);
  935. } else if (radiob_array_table[i] == 0xfc) {
  936. /* delay_ms(1); */
  937. for (j = 0; j < 20; j++)
  938. udelay(MAX_STALL_TIME);
  939. } else if (radiob_array_table[i] == 0xfb) {
  940. udelay(50);
  941. } else if (radiob_array_table[i] == 0xfa) {
  942. udelay(5);
  943. } else if (radiob_array_table[i] == 0xf9) {
  944. udelay(1);
  945. } else {
  946. rtl_set_rfreg(hw, rfpath, radiob_array_table[i],
  947. BRFREGOFFSETMASK,
  948. radiob_array_table[i + 1]);
  949. /* Add 1us delay between BB/RF register set. */
  950. udelay(1);
  951. }
  952. }
  953. break;
  954. case RF90_PATH_C:
  955. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  956. ("switch case not process\n"));
  957. break;
  958. case RF90_PATH_D:
  959. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  960. ("switch case not process\n"));
  961. break;
  962. }
  963. return true;
  964. }
  965. void rtl92d_phy_get_hw_reg_originalvalue(struct ieee80211_hw *hw)
  966. {
  967. struct rtl_priv *rtlpriv = rtl_priv(hw);
  968. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  969. rtlphy->default_initialgain[0] =
  970. (u8) rtl_get_bbreg(hw, ROFDM0_XAAGCCORE1, BMASKBYTE0);
  971. rtlphy->default_initialgain[1] =
  972. (u8) rtl_get_bbreg(hw, ROFDM0_XBAGCCORE1, BMASKBYTE0);
  973. rtlphy->default_initialgain[2] =
  974. (u8) rtl_get_bbreg(hw, ROFDM0_XCAGCCORE1, BMASKBYTE0);
  975. rtlphy->default_initialgain[3] =
  976. (u8) rtl_get_bbreg(hw, ROFDM0_XDAGCCORE1, BMASKBYTE0);
  977. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  978. ("Default initial gain (c50=0x%x, "
  979. "c58=0x%x, c60=0x%x, c68=0x%x\n",
  980. rtlphy->default_initialgain[0],
  981. rtlphy->default_initialgain[1],
  982. rtlphy->default_initialgain[2],
  983. rtlphy->default_initialgain[3]));
  984. rtlphy->framesync = (u8)rtl_get_bbreg(hw, ROFDM0_RXDETECTOR3,
  985. BMASKBYTE0);
  986. rtlphy->framesync_c34 = rtl_get_bbreg(hw, ROFDM0_RXDETECTOR2,
  987. BMASKDWORD);
  988. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  989. ("Default framesync (0x%x) = 0x%x\n",
  990. ROFDM0_RXDETECTOR3, rtlphy->framesync));
  991. }
  992. static void _rtl92d_get_txpower_index(struct ieee80211_hw *hw, u8 channel,
  993. u8 *cckpowerlevel, u8 *ofdmpowerlevel)
  994. {
  995. struct rtl_priv *rtlpriv = rtl_priv(hw);
  996. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  997. struct rtl_hal *rtlhal = &(rtlpriv->rtlhal);
  998. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  999. u8 index = (channel - 1);
  1000. /* 1. CCK */
  1001. if (rtlhal->current_bandtype == BAND_ON_2_4G) {
  1002. /* RF-A */
  1003. cckpowerlevel[RF90_PATH_A] =
  1004. rtlefuse->txpwrlevel_cck[RF90_PATH_A][index];
  1005. /* RF-B */
  1006. cckpowerlevel[RF90_PATH_B] =
  1007. rtlefuse->txpwrlevel_cck[RF90_PATH_B][index];
  1008. } else {
  1009. cckpowerlevel[RF90_PATH_A] = 0;
  1010. cckpowerlevel[RF90_PATH_B] = 0;
  1011. }
  1012. /* 2. OFDM for 1S or 2S */
  1013. if (rtlphy->rf_type == RF_1T2R || rtlphy->rf_type == RF_1T1R) {
  1014. /* Read HT 40 OFDM TX power */
  1015. ofdmpowerlevel[RF90_PATH_A] =
  1016. rtlefuse->txpwrlevel_ht40_1s[RF90_PATH_A][index];
  1017. ofdmpowerlevel[RF90_PATH_B] =
  1018. rtlefuse->txpwrlevel_ht40_1s[RF90_PATH_B][index];
  1019. } else if (rtlphy->rf_type == RF_2T2R) {
  1020. /* Read HT 40 OFDM TX power */
  1021. ofdmpowerlevel[RF90_PATH_A] =
  1022. rtlefuse->txpwrlevel_ht40_2s[RF90_PATH_A][index];
  1023. ofdmpowerlevel[RF90_PATH_B] =
  1024. rtlefuse->txpwrlevel_ht40_2s[RF90_PATH_B][index];
  1025. }
  1026. }
  1027. static void _rtl92d_ccxpower_index_check(struct ieee80211_hw *hw,
  1028. u8 channel, u8 *cckpowerlevel, u8 *ofdmpowerlevel)
  1029. {
  1030. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1031. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  1032. rtlphy->cur_cck_txpwridx = cckpowerlevel[0];
  1033. rtlphy->cur_ofdm24g_txpwridx = ofdmpowerlevel[0];
  1034. }
  1035. static u8 _rtl92c_phy_get_rightchnlplace(u8 chnl)
  1036. {
  1037. u8 channel_5g[59] = {
  1038. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  1039. 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58,
  1040. 60, 62, 64, 100, 102, 104, 106, 108, 110, 112,
  1041. 114, 116, 118, 120, 122, 124, 126, 128,
  1042. 130, 132, 134, 136, 138, 140, 149, 151,
  1043. 153, 155, 157, 159, 161, 163, 165
  1044. };
  1045. u8 place = chnl;
  1046. if (chnl > 14) {
  1047. for (place = 14; place < sizeof(channel_5g); place++) {
  1048. if (channel_5g[place] == chnl) {
  1049. place++;
  1050. break;
  1051. }
  1052. }
  1053. }
  1054. return place;
  1055. }
  1056. void rtl92d_phy_set_txpower_level(struct ieee80211_hw *hw, u8 channel)
  1057. {
  1058. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  1059. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1060. u8 cckpowerlevel[2], ofdmpowerlevel[2];
  1061. if (rtlefuse->txpwr_fromeprom == false)
  1062. return;
  1063. channel = _rtl92c_phy_get_rightchnlplace(channel);
  1064. _rtl92d_get_txpower_index(hw, channel, &cckpowerlevel[0],
  1065. &ofdmpowerlevel[0]);
  1066. if (rtlpriv->rtlhal.current_bandtype == BAND_ON_2_4G)
  1067. _rtl92d_ccxpower_index_check(hw, channel, &cckpowerlevel[0],
  1068. &ofdmpowerlevel[0]);
  1069. if (rtlpriv->rtlhal.current_bandtype == BAND_ON_2_4G)
  1070. rtl92d_phy_rf6052_set_cck_txpower(hw, &cckpowerlevel[0]);
  1071. rtl92d_phy_rf6052_set_ofdm_txpower(hw, &ofdmpowerlevel[0], channel);
  1072. }
  1073. void rtl92d_phy_scan_operation_backup(struct ieee80211_hw *hw, u8 operation)
  1074. {
  1075. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1076. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1077. enum io_type iotype;
  1078. if (!is_hal_stop(rtlhal)) {
  1079. switch (operation) {
  1080. case SCAN_OPT_BACKUP:
  1081. rtlhal->current_bandtypebackup =
  1082. rtlhal->current_bandtype;
  1083. iotype = IO_CMD_PAUSE_DM_BY_SCAN;
  1084. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_IO_CMD,
  1085. (u8 *)&iotype);
  1086. break;
  1087. case SCAN_OPT_RESTORE:
  1088. iotype = IO_CMD_RESUME_DM_BY_SCAN;
  1089. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_IO_CMD,
  1090. (u8 *)&iotype);
  1091. break;
  1092. default:
  1093. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1094. ("Unknown Scan Backup operation.\n"));
  1095. break;
  1096. }
  1097. }
  1098. }
  1099. void rtl92d_phy_set_bw_mode(struct ieee80211_hw *hw,
  1100. enum nl80211_channel_type ch_type)
  1101. {
  1102. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1103. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  1104. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1105. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1106. unsigned long flag = 0;
  1107. u8 reg_prsr_rsc;
  1108. u8 reg_bw_opmode;
  1109. if (rtlphy->set_bwmode_inprogress)
  1110. return;
  1111. if ((is_hal_stop(rtlhal)) || (RT_CANNOT_IO(hw))) {
  1112. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  1113. ("FALSE driver sleep or unload\n"));
  1114. return;
  1115. }
  1116. rtlphy->set_bwmode_inprogress = true;
  1117. RT_TRACE(rtlpriv, COMP_SCAN, DBG_TRACE,
  1118. ("Switch to %s bandwidth\n",
  1119. rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20 ?
  1120. "20MHz" : "40MHz"));
  1121. reg_bw_opmode = rtl_read_byte(rtlpriv, REG_BWOPMODE);
  1122. reg_prsr_rsc = rtl_read_byte(rtlpriv, REG_RRSR + 2);
  1123. switch (rtlphy->current_chan_bw) {
  1124. case HT_CHANNEL_WIDTH_20:
  1125. reg_bw_opmode |= BW_OPMODE_20MHZ;
  1126. rtl_write_byte(rtlpriv, REG_BWOPMODE, reg_bw_opmode);
  1127. break;
  1128. case HT_CHANNEL_WIDTH_20_40:
  1129. reg_bw_opmode &= ~BW_OPMODE_20MHZ;
  1130. rtl_write_byte(rtlpriv, REG_BWOPMODE, reg_bw_opmode);
  1131. reg_prsr_rsc = (reg_prsr_rsc & 0x90) |
  1132. (mac->cur_40_prime_sc << 5);
  1133. rtl_write_byte(rtlpriv, REG_RRSR + 2, reg_prsr_rsc);
  1134. break;
  1135. default:
  1136. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1137. ("unknown bandwidth: %#X\n", rtlphy->current_chan_bw));
  1138. break;
  1139. }
  1140. switch (rtlphy->current_chan_bw) {
  1141. case HT_CHANNEL_WIDTH_20:
  1142. rtl_set_bbreg(hw, RFPGA0_RFMOD, BRFMOD, 0x0);
  1143. rtl_set_bbreg(hw, RFPGA1_RFMOD, BRFMOD, 0x0);
  1144. /* SET BIT10 BIT11 for receive cck */
  1145. rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER2, BIT(10) |
  1146. BIT(11), 3);
  1147. break;
  1148. case HT_CHANNEL_WIDTH_20_40:
  1149. rtl_set_bbreg(hw, RFPGA0_RFMOD, BRFMOD, 0x1);
  1150. rtl_set_bbreg(hw, RFPGA1_RFMOD, BRFMOD, 0x1);
  1151. /* Set Control channel to upper or lower.
  1152. * These settings are required only for 40MHz */
  1153. if (rtlhal->current_bandtype == BAND_ON_2_4G) {
  1154. rtl92d_acquire_cckandrw_pagea_ctl(hw, &flag);
  1155. rtl_set_bbreg(hw, RCCK0_SYSTEM, BCCKSIDEBAND,
  1156. (mac->cur_40_prime_sc >> 1));
  1157. rtl92d_release_cckandrw_pagea_ctl(hw, &flag);
  1158. }
  1159. rtl_set_bbreg(hw, ROFDM1_LSTF, 0xC00, mac->cur_40_prime_sc);
  1160. /* SET BIT10 BIT11 for receive cck */
  1161. rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER2, BIT(10) |
  1162. BIT(11), 0);
  1163. rtl_set_bbreg(hw, 0x818, (BIT(26) | BIT(27)),
  1164. (mac->cur_40_prime_sc ==
  1165. HAL_PRIME_CHNL_OFFSET_LOWER) ? 2 : 1);
  1166. break;
  1167. default:
  1168. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1169. ("unknown bandwidth: %#X\n", rtlphy->current_chan_bw));
  1170. break;
  1171. }
  1172. rtl92d_phy_rf6052_set_bandwidth(hw, rtlphy->current_chan_bw);
  1173. rtlphy->set_bwmode_inprogress = false;
  1174. RT_TRACE(rtlpriv, COMP_SCAN, DBG_TRACE, ("<==\n"));
  1175. }
  1176. static void _rtl92d_phy_stop_trx_before_changeband(struct ieee80211_hw *hw)
  1177. {
  1178. rtl_set_bbreg(hw, RFPGA0_RFMOD, BCCKEN, 0);
  1179. rtl_set_bbreg(hw, RFPGA0_RFMOD, BOFDMEN, 0);
  1180. rtl_set_bbreg(hw, ROFDM0_TRXPATHENABLE, BMASKBYTE0, 0x00);
  1181. rtl_set_bbreg(hw, ROFDM1_TRXPATHENABLE, BDWORD, 0x0);
  1182. }
  1183. static void rtl92d_phy_switch_wirelessband(struct ieee80211_hw *hw, u8 band)
  1184. {
  1185. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1186. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1187. u8 i, value8;
  1188. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, ("==>\n"));
  1189. rtlhal->bandset = band;
  1190. rtlhal->current_bandtype = band;
  1191. if (IS_92D_SINGLEPHY(rtlhal->version))
  1192. rtlhal->bandset = BAND_ON_BOTH;
  1193. /* stop RX/Tx */
  1194. _rtl92d_phy_stop_trx_before_changeband(hw);
  1195. /* reconfig BB/RF according to wireless mode */
  1196. if (rtlhal->current_bandtype == BAND_ON_2_4G) {
  1197. /* BB & RF Config */
  1198. RT_TRACE(rtlpriv, COMP_CMD, DBG_DMESG, ("====>2.4G\n"));
  1199. if (rtlhal->interfaceindex == 1)
  1200. _rtl92d_phy_config_bb_with_headerfile(hw,
  1201. BASEBAND_CONFIG_AGC_TAB);
  1202. } else {
  1203. /* 5G band */
  1204. RT_TRACE(rtlpriv, COMP_CMD, DBG_DMESG, ("====>5G\n"));
  1205. if (rtlhal->interfaceindex == 1)
  1206. _rtl92d_phy_config_bb_with_headerfile(hw,
  1207. BASEBAND_CONFIG_AGC_TAB);
  1208. }
  1209. rtl92d_update_bbrf_configuration(hw);
  1210. if (rtlhal->current_bandtype == BAND_ON_2_4G)
  1211. rtl_set_bbreg(hw, RFPGA0_RFMOD, BCCKEN, 0x1);
  1212. rtl_set_bbreg(hw, RFPGA0_RFMOD, BOFDMEN, 0x1);
  1213. /* 20M BW. */
  1214. /* rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER2, BIT(10), 1); */
  1215. rtlhal->reloadtxpowerindex = true;
  1216. /* notice fw know band status 0x81[1]/0x53[1] = 0: 5G, 1: 2G */
  1217. if (rtlhal->current_bandtype == BAND_ON_2_4G) {
  1218. value8 = rtl_read_byte(rtlpriv, (rtlhal->interfaceindex ==
  1219. 0 ? REG_MAC0 : REG_MAC1));
  1220. value8 |= BIT(1);
  1221. rtl_write_byte(rtlpriv, (rtlhal->interfaceindex ==
  1222. 0 ? REG_MAC0 : REG_MAC1), value8);
  1223. } else {
  1224. value8 = rtl_read_byte(rtlpriv, (rtlhal->interfaceindex ==
  1225. 0 ? REG_MAC0 : REG_MAC1));
  1226. value8 &= (~BIT(1));
  1227. rtl_write_byte(rtlpriv, (rtlhal->interfaceindex ==
  1228. 0 ? REG_MAC0 : REG_MAC1), value8);
  1229. }
  1230. for (i = 0; i < 20; i++)
  1231. udelay(MAX_STALL_TIME);
  1232. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, ("<==Switch Band OK.\n"));
  1233. }
  1234. static void _rtl92d_phy_reload_imr_setting(struct ieee80211_hw *hw,
  1235. u8 channel, u8 rfpath)
  1236. {
  1237. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1238. u32 imr_num = MAX_RF_IMR_INDEX;
  1239. u32 rfmask = BRFREGOFFSETMASK;
  1240. u8 group, i;
  1241. unsigned long flag = 0;
  1242. RT_TRACE(rtlpriv, COMP_CMD, DBG_LOUD, ("====>path %d\n", rfpath));
  1243. if (rtlpriv->rtlhal.current_bandtype == BAND_ON_5G) {
  1244. RT_TRACE(rtlpriv, COMP_CMD, DBG_LOUD, ("====>5G\n"));
  1245. rtl_set_bbreg(hw, RFPGA0_RFMOD, BIT(25) | BIT(24), 0);
  1246. rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER4, 0x00f00000, 0xf);
  1247. /* fc area 0xd2c */
  1248. if (channel > 99)
  1249. rtl_set_bbreg(hw, ROFDM1_CFOTRACKING, BIT(13) |
  1250. BIT(14), 2);
  1251. else
  1252. rtl_set_bbreg(hw, ROFDM1_CFOTRACKING, BIT(13) |
  1253. BIT(14), 1);
  1254. /* leave 0 for channel1-14. */
  1255. group = channel <= 64 ? 1 : 2;
  1256. imr_num = MAX_RF_IMR_INDEX_NORMAL;
  1257. for (i = 0; i < imr_num; i++)
  1258. rtl_set_rfreg(hw, (enum radio_path)rfpath,
  1259. rf_reg_for_5g_swchnl_normal[i], rfmask,
  1260. rf_imr_param_normal[0][group][i]);
  1261. rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER4, 0x00f00000, 0);
  1262. rtl_set_bbreg(hw, RFPGA0_RFMOD, BOFDMEN, 1);
  1263. } else {
  1264. /* G band. */
  1265. RT_TRACE(rtlpriv, COMP_SCAN, DBG_LOUD,
  1266. ("Load RF IMR parameters for G band. IMR already "
  1267. "setting %d\n",
  1268. rtlpriv->rtlhal.load_imrandiqk_setting_for2g));
  1269. RT_TRACE(rtlpriv, COMP_CMD, DBG_LOUD, ("====>2.4G\n"));
  1270. if (!rtlpriv->rtlhal.load_imrandiqk_setting_for2g) {
  1271. RT_TRACE(rtlpriv, COMP_SCAN, DBG_LOUD,
  1272. ("Load RF IMR parameters "
  1273. "for G band. %d\n", rfpath));
  1274. rtl92d_acquire_cckandrw_pagea_ctl(hw, &flag);
  1275. rtl_set_bbreg(hw, RFPGA0_RFMOD, BIT(25) | BIT(24), 0);
  1276. rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER4,
  1277. 0x00f00000, 0xf);
  1278. imr_num = MAX_RF_IMR_INDEX_NORMAL;
  1279. for (i = 0; i < imr_num; i++) {
  1280. rtl_set_rfreg(hw, (enum radio_path)rfpath,
  1281. rf_reg_for_5g_swchnl_normal[i],
  1282. BRFREGOFFSETMASK,
  1283. rf_imr_param_normal[0][0][i]);
  1284. }
  1285. rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER4,
  1286. 0x00f00000, 0);
  1287. rtl_set_bbreg(hw, RFPGA0_RFMOD, BOFDMEN | BCCKEN, 3);
  1288. rtl92d_release_cckandrw_pagea_ctl(hw, &flag);
  1289. }
  1290. }
  1291. RT_TRACE(rtlpriv, COMP_CMD, DBG_LOUD, ("<====\n"));
  1292. }
  1293. static void _rtl92d_phy_enable_rf_env(struct ieee80211_hw *hw,
  1294. u8 rfpath, u32 *pu4_regval)
  1295. {
  1296. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1297. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  1298. struct bb_reg_def *pphyreg = &rtlphy->phyreg_def[rfpath];
  1299. RT_TRACE(rtlpriv, COMP_RF, DBG_LOUD, ("====>\n"));
  1300. /*----Store original RFENV control type----*/
  1301. switch (rfpath) {
  1302. case RF90_PATH_A:
  1303. case RF90_PATH_C:
  1304. *pu4_regval = rtl_get_bbreg(hw, pphyreg->rfintfs, BRFSI_RFENV);
  1305. break;
  1306. case RF90_PATH_B:
  1307. case RF90_PATH_D:
  1308. *pu4_regval =
  1309. rtl_get_bbreg(hw, pphyreg->rfintfs, BRFSI_RFENV << 16);
  1310. break;
  1311. }
  1312. /*----Set RF_ENV enable----*/
  1313. rtl_set_bbreg(hw, pphyreg->rfintfe, BRFSI_RFENV << 16, 0x1);
  1314. udelay(1);
  1315. /*----Set RF_ENV output high----*/
  1316. rtl_set_bbreg(hw, pphyreg->rfintfo, BRFSI_RFENV, 0x1);
  1317. udelay(1);
  1318. /* Set bit number of Address and Data for RF register */
  1319. /* Set 1 to 4 bits for 8255 */
  1320. rtl_set_bbreg(hw, pphyreg->rfhssi_para2, B3WIREADDRESSLENGTH, 0x0);
  1321. udelay(1);
  1322. /*Set 0 to 12 bits for 8255 */
  1323. rtl_set_bbreg(hw, pphyreg->rfhssi_para2, B3WIREDATALENGTH, 0x0);
  1324. udelay(1);
  1325. RT_TRACE(rtlpriv, COMP_RF, DBG_LOUD, ("<====\n"));
  1326. }
  1327. static void _rtl92d_phy_restore_rf_env(struct ieee80211_hw *hw, u8 rfpath,
  1328. u32 *pu4_regval)
  1329. {
  1330. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1331. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  1332. struct bb_reg_def *pphyreg = &rtlphy->phyreg_def[rfpath];
  1333. RT_TRACE(rtlpriv, COMP_RF, DBG_LOUD, ("=====>\n"));
  1334. /*----Restore RFENV control type----*/ ;
  1335. switch (rfpath) {
  1336. case RF90_PATH_A:
  1337. case RF90_PATH_C:
  1338. rtl_set_bbreg(hw, pphyreg->rfintfs, BRFSI_RFENV, *pu4_regval);
  1339. break;
  1340. case RF90_PATH_B:
  1341. case RF90_PATH_D:
  1342. rtl_set_bbreg(hw, pphyreg->rfintfs, BRFSI_RFENV << 16,
  1343. *pu4_regval);
  1344. break;
  1345. }
  1346. RT_TRACE(rtlpriv, COMP_RF, DBG_LOUD, ("<=====\n"));
  1347. }
  1348. static void _rtl92d_phy_switch_rf_setting(struct ieee80211_hw *hw, u8 channel)
  1349. {
  1350. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1351. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  1352. struct rtl_hal *rtlhal = &(rtlpriv->rtlhal);
  1353. u8 path = rtlhal->current_bandtype ==
  1354. BAND_ON_5G ? RF90_PATH_A : RF90_PATH_B;
  1355. u8 index = 0, i = 0, rfpath = RF90_PATH_A;
  1356. bool need_pwr_down = false, internal_pa = false;
  1357. u32 u4regvalue, mask = 0x1C000, value = 0, u4tmp, u4tmp2;
  1358. RT_TRACE(rtlpriv, COMP_CMD, DBG_LOUD, ("====>\n"));
  1359. /* config path A for 5G */
  1360. if (rtlhal->current_bandtype == BAND_ON_5G) {
  1361. RT_TRACE(rtlpriv, COMP_CMD, DBG_LOUD, ("====>5G\n"));
  1362. u4tmp = curveindex_5g[channel - 1];
  1363. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("ver 1 set RF-A, 5G, "
  1364. "0x28 = 0x%x !!\n", u4tmp));
  1365. for (i = 0; i < RF_CHNL_NUM_5G; i++) {
  1366. if (channel == rf_chnl_5g[i] && channel <= 140)
  1367. index = 0;
  1368. }
  1369. for (i = 0; i < RF_CHNL_NUM_5G_40M; i++) {
  1370. if (channel == rf_chnl_5g_40m[i] && channel <= 140)
  1371. index = 1;
  1372. }
  1373. if (channel == 149 || channel == 155 || channel == 161)
  1374. index = 2;
  1375. else if (channel == 151 || channel == 153 || channel == 163
  1376. || channel == 165)
  1377. index = 3;
  1378. else if (channel == 157 || channel == 159)
  1379. index = 4;
  1380. if (rtlhal->macphymode == DUALMAC_DUALPHY
  1381. && rtlhal->interfaceindex == 1) {
  1382. need_pwr_down = rtl92d_phy_enable_anotherphy(hw, false);
  1383. rtlhal->during_mac1init_radioa = true;
  1384. /* asume no this case */
  1385. if (need_pwr_down)
  1386. _rtl92d_phy_enable_rf_env(hw, path,
  1387. &u4regvalue);
  1388. }
  1389. for (i = 0; i < RF_REG_NUM_FOR_C_CUT_5G; i++) {
  1390. if (i == 0 && (rtlhal->macphymode == DUALMAC_DUALPHY)) {
  1391. rtl_set_rfreg(hw, (enum radio_path)path,
  1392. rf_reg_for_c_cut_5g[i],
  1393. BRFREGOFFSETMASK, 0xE439D);
  1394. } else if (rf_reg_for_c_cut_5g[i] == RF_SYN_G4) {
  1395. u4tmp2 = (rf_reg_pram_c_5g[index][i] &
  1396. 0x7FF) | (u4tmp << 11);
  1397. if (channel == 36)
  1398. u4tmp2 &= ~(BIT(7) | BIT(6));
  1399. rtl_set_rfreg(hw, (enum radio_path)path,
  1400. rf_reg_for_c_cut_5g[i],
  1401. BRFREGOFFSETMASK, u4tmp2);
  1402. } else {
  1403. rtl_set_rfreg(hw, (enum radio_path)path,
  1404. rf_reg_for_c_cut_5g[i],
  1405. BRFREGOFFSETMASK,
  1406. rf_reg_pram_c_5g[index][i]);
  1407. }
  1408. RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE,
  1409. ("offset 0x%x value 0x%x "
  1410. "path %d index %d readback 0x%x\n",
  1411. rf_reg_for_c_cut_5g[i],
  1412. rf_reg_pram_c_5g[index][i], path,
  1413. index, rtl_get_rfreg(hw, (enum radio_path)path,
  1414. rf_reg_for_c_cut_5g[i], BRFREGOFFSETMASK)));
  1415. }
  1416. if (need_pwr_down)
  1417. _rtl92d_phy_restore_rf_env(hw, path, &u4regvalue);
  1418. if (rtlhal->during_mac1init_radioa)
  1419. rtl92d_phy_powerdown_anotherphy(hw, false);
  1420. if (channel < 149)
  1421. value = 0x07;
  1422. else if (channel >= 149)
  1423. value = 0x02;
  1424. if (channel >= 36 && channel <= 64)
  1425. index = 0;
  1426. else if (channel >= 100 && channel <= 140)
  1427. index = 1;
  1428. else
  1429. index = 2;
  1430. for (rfpath = RF90_PATH_A; rfpath < rtlphy->num_total_rfpath;
  1431. rfpath++) {
  1432. if (rtlhal->macphymode == DUALMAC_DUALPHY &&
  1433. rtlhal->interfaceindex == 1) /* MAC 1 5G */
  1434. internal_pa = rtlpriv->efuse.internal_pa_5g[1];
  1435. else
  1436. internal_pa =
  1437. rtlpriv->efuse.internal_pa_5g[rfpath];
  1438. if (internal_pa) {
  1439. for (i = 0;
  1440. i < RF_REG_NUM_FOR_C_CUT_5G_INTERNALPA;
  1441. i++) {
  1442. rtl_set_rfreg(hw, rfpath,
  1443. rf_for_c_cut_5g_internal_pa[i],
  1444. BRFREGOFFSETMASK,
  1445. rf_pram_c_5g_int_pa[index][i]);
  1446. RT_TRACE(rtlpriv, COMP_RF, DBG_LOUD,
  1447. ("offset 0x%x value 0x%x "
  1448. "path %d index %d\n",
  1449. rf_for_c_cut_5g_internal_pa[i],
  1450. rf_pram_c_5g_int_pa[index][i],
  1451. rfpath, index));
  1452. }
  1453. } else {
  1454. rtl_set_rfreg(hw, (enum radio_path)rfpath, 0x0B,
  1455. mask, value);
  1456. }
  1457. }
  1458. } else if (rtlhal->current_bandtype == BAND_ON_2_4G) {
  1459. RT_TRACE(rtlpriv, COMP_CMD, DBG_LOUD, ("====>2.4G\n"));
  1460. u4tmp = curveindex_2g[channel - 1];
  1461. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("ver 3 set RF-B, 2G, "
  1462. "0x28 = 0x%x !!\n", u4tmp));
  1463. if (channel == 1 || channel == 2 || channel == 4 || channel == 9
  1464. || channel == 10 || channel == 11 || channel == 12)
  1465. index = 0;
  1466. else if (channel == 3 || channel == 13 || channel == 14)
  1467. index = 1;
  1468. else if (channel >= 5 && channel <= 8)
  1469. index = 2;
  1470. if (rtlhal->macphymode == DUALMAC_DUALPHY) {
  1471. path = RF90_PATH_A;
  1472. if (rtlhal->interfaceindex == 0) {
  1473. need_pwr_down =
  1474. rtl92d_phy_enable_anotherphy(hw, true);
  1475. rtlhal->during_mac0init_radiob = true;
  1476. if (need_pwr_down)
  1477. _rtl92d_phy_enable_rf_env(hw, path,
  1478. &u4regvalue);
  1479. }
  1480. }
  1481. for (i = 0; i < RF_REG_NUM_FOR_C_CUT_2G; i++) {
  1482. if (rf_reg_for_c_cut_2g[i] == RF_SYN_G7)
  1483. rtl_set_rfreg(hw, (enum radio_path)path,
  1484. rf_reg_for_c_cut_2g[i],
  1485. BRFREGOFFSETMASK,
  1486. (rf_reg_param_for_c_cut_2g[index][i] |
  1487. BIT(17)));
  1488. else
  1489. rtl_set_rfreg(hw, (enum radio_path)path,
  1490. rf_reg_for_c_cut_2g[i],
  1491. BRFREGOFFSETMASK,
  1492. rf_reg_param_for_c_cut_2g
  1493. [index][i]);
  1494. RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE,
  1495. ("offset 0x%x value 0x%x mak 0x%x path %d "
  1496. "index %d readback 0x%x\n",
  1497. rf_reg_for_c_cut_2g[i],
  1498. rf_reg_param_for_c_cut_2g[index][i],
  1499. rf_reg_mask_for_c_cut_2g[i], path, index,
  1500. rtl_get_rfreg(hw, (enum radio_path)path,
  1501. rf_reg_for_c_cut_2g[i],
  1502. BRFREGOFFSETMASK)));
  1503. }
  1504. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  1505. ("cosa ver 3 set RF-B, 2G, 0x28 = 0x%x !!\n",
  1506. rf_syn_g4_for_c_cut_2g | (u4tmp << 11)));
  1507. rtl_set_rfreg(hw, (enum radio_path)path, RF_SYN_G4,
  1508. BRFREGOFFSETMASK,
  1509. rf_syn_g4_for_c_cut_2g | (u4tmp << 11));
  1510. if (need_pwr_down)
  1511. _rtl92d_phy_restore_rf_env(hw, path, &u4regvalue);
  1512. if (rtlhal->during_mac0init_radiob)
  1513. rtl92d_phy_powerdown_anotherphy(hw, true);
  1514. }
  1515. RT_TRACE(rtlpriv, COMP_CMD, DBG_LOUD, ("<====\n"));
  1516. }
  1517. u8 rtl92d_get_rightchnlplace_for_iqk(u8 chnl)
  1518. {
  1519. u8 channel_all[59] = {
  1520. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  1521. 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58,
  1522. 60, 62, 64, 100, 102, 104, 106, 108, 110, 112,
  1523. 114, 116, 118, 120, 122, 124, 126, 128, 130,
  1524. 132, 134, 136, 138, 140, 149, 151, 153, 155,
  1525. 157, 159, 161, 163, 165
  1526. };
  1527. u8 place = chnl;
  1528. if (chnl > 14) {
  1529. for (place = 14; place < sizeof(channel_all); place++) {
  1530. if (channel_all[place] == chnl)
  1531. return place - 13;
  1532. }
  1533. }
  1534. return 0;
  1535. }
  1536. #define MAX_TOLERANCE 5
  1537. #define IQK_DELAY_TIME 1 /* ms */
  1538. #define MAX_TOLERANCE_92D 3
  1539. /* bit0 = 1 => Tx OK, bit1 = 1 => Rx OK */
  1540. static u8 _rtl92d_phy_patha_iqk(struct ieee80211_hw *hw, bool configpathb)
  1541. {
  1542. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1543. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1544. u32 regeac, rege94, rege9c, regea4;
  1545. u8 result = 0;
  1546. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("Path A IQK!\n"));
  1547. /* path-A IQK setting */
  1548. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("Path-A IQK setting!\n"));
  1549. if (rtlhal->interfaceindex == 0) {
  1550. rtl_set_bbreg(hw, 0xe30, BMASKDWORD, 0x10008c1f);
  1551. rtl_set_bbreg(hw, 0xe34, BMASKDWORD, 0x10008c1f);
  1552. } else {
  1553. rtl_set_bbreg(hw, 0xe30, BMASKDWORD, 0x10008c22);
  1554. rtl_set_bbreg(hw, 0xe34, BMASKDWORD, 0x10008c22);
  1555. }
  1556. rtl_set_bbreg(hw, 0xe38, BMASKDWORD, 0x82140102);
  1557. rtl_set_bbreg(hw, 0xe3c, BMASKDWORD, 0x28160206);
  1558. /* path-B IQK setting */
  1559. if (configpathb) {
  1560. rtl_set_bbreg(hw, 0xe50, BMASKDWORD, 0x10008c22);
  1561. rtl_set_bbreg(hw, 0xe54, BMASKDWORD, 0x10008c22);
  1562. rtl_set_bbreg(hw, 0xe58, BMASKDWORD, 0x82140102);
  1563. rtl_set_bbreg(hw, 0xe5c, BMASKDWORD, 0x28160206);
  1564. }
  1565. /* LO calibration setting */
  1566. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("LO calibration setting!\n"));
  1567. rtl_set_bbreg(hw, 0xe4c, BMASKDWORD, 0x00462911);
  1568. /* One shot, path A LOK & IQK */
  1569. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("One shot, path A LOK & IQK!\n"));
  1570. rtl_set_bbreg(hw, 0xe48, BMASKDWORD, 0xf9000000);
  1571. rtl_set_bbreg(hw, 0xe48, BMASKDWORD, 0xf8000000);
  1572. /* delay x ms */
  1573. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  1574. ("Delay %d ms for One shot, path A LOK & IQK.\n",
  1575. IQK_DELAY_TIME));
  1576. mdelay(IQK_DELAY_TIME);
  1577. /* Check failed */
  1578. regeac = rtl_get_bbreg(hw, 0xeac, BMASKDWORD);
  1579. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("0xeac = 0x%x\n", regeac));
  1580. rege94 = rtl_get_bbreg(hw, 0xe94, BMASKDWORD);
  1581. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("0xe94 = 0x%x\n", rege94));
  1582. rege9c = rtl_get_bbreg(hw, 0xe9c, BMASKDWORD);
  1583. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("0xe9c = 0x%x\n", rege9c));
  1584. regea4 = rtl_get_bbreg(hw, 0xea4, BMASKDWORD);
  1585. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("0xea4 = 0x%x\n", regea4));
  1586. if (!(regeac & BIT(28)) && (((rege94 & 0x03FF0000) >> 16) != 0x142) &&
  1587. (((rege9c & 0x03FF0000) >> 16) != 0x42))
  1588. result |= 0x01;
  1589. else /* if Tx not OK, ignore Rx */
  1590. return result;
  1591. /* if Tx is OK, check whether Rx is OK */
  1592. if (!(regeac & BIT(27)) && (((regea4 & 0x03FF0000) >> 16) != 0x132) &&
  1593. (((regeac & 0x03FF0000) >> 16) != 0x36))
  1594. result |= 0x02;
  1595. else
  1596. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("Path A Rx IQK fail!!\n"));
  1597. return result;
  1598. }
  1599. /* bit0 = 1 => Tx OK, bit1 = 1 => Rx OK */
  1600. static u8 _rtl92d_phy_patha_iqk_5g_normal(struct ieee80211_hw *hw,
  1601. bool configpathb)
  1602. {
  1603. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1604. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1605. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  1606. u32 regeac, rege94, rege9c, regea4;
  1607. u8 result = 0;
  1608. u8 i;
  1609. u8 retrycount = 2;
  1610. u32 TxOKBit = BIT(28), RxOKBit = BIT(27);
  1611. if (rtlhal->interfaceindex == 1) { /* PHY1 */
  1612. TxOKBit = BIT(31);
  1613. RxOKBit = BIT(30);
  1614. }
  1615. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("Path A IQK!\n"));
  1616. /* path-A IQK setting */
  1617. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("Path-A IQK setting!\n"));
  1618. rtl_set_bbreg(hw, 0xe30, BMASKDWORD, 0x18008c1f);
  1619. rtl_set_bbreg(hw, 0xe34, BMASKDWORD, 0x18008c1f);
  1620. rtl_set_bbreg(hw, 0xe38, BMASKDWORD, 0x82140307);
  1621. rtl_set_bbreg(hw, 0xe3c, BMASKDWORD, 0x68160960);
  1622. /* path-B IQK setting */
  1623. if (configpathb) {
  1624. rtl_set_bbreg(hw, 0xe50, BMASKDWORD, 0x18008c2f);
  1625. rtl_set_bbreg(hw, 0xe54, BMASKDWORD, 0x18008c2f);
  1626. rtl_set_bbreg(hw, 0xe58, BMASKDWORD, 0x82110000);
  1627. rtl_set_bbreg(hw, 0xe5c, BMASKDWORD, 0x68110000);
  1628. }
  1629. /* LO calibration setting */
  1630. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("LO calibration setting!\n"));
  1631. rtl_set_bbreg(hw, 0xe4c, BMASKDWORD, 0x00462911);
  1632. /* path-A PA on */
  1633. rtl_set_bbreg(hw, RFPGA0_XAB_RFINTERFACESW, BMASKDWORD, 0x07000f60);
  1634. rtl_set_bbreg(hw, RFPGA0_XA_RFINTERFACEOE, BMASKDWORD, 0x66e60e30);
  1635. for (i = 0; i < retrycount; i++) {
  1636. /* One shot, path A LOK & IQK */
  1637. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  1638. ("One shot, path A LOK & IQK!\n"));
  1639. rtl_set_bbreg(hw, 0xe48, BMASKDWORD, 0xf9000000);
  1640. rtl_set_bbreg(hw, 0xe48, BMASKDWORD, 0xf8000000);
  1641. /* delay x ms */
  1642. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  1643. ("Delay %d ms for One shot, path A LOK & IQK.\n",
  1644. IQK_DELAY_TIME));
  1645. mdelay(IQK_DELAY_TIME * 10);
  1646. /* Check failed */
  1647. regeac = rtl_get_bbreg(hw, 0xeac, BMASKDWORD);
  1648. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("0xeac = 0x%x\n", regeac));
  1649. rege94 = rtl_get_bbreg(hw, 0xe94, BMASKDWORD);
  1650. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("0xe94 = 0x%x\n", rege94));
  1651. rege9c = rtl_get_bbreg(hw, 0xe9c, BMASKDWORD);
  1652. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("0xe9c = 0x%x\n", rege9c));
  1653. regea4 = rtl_get_bbreg(hw, 0xea4, BMASKDWORD);
  1654. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("0xea4 = 0x%x\n", regea4));
  1655. if (!(regeac & TxOKBit) &&
  1656. (((rege94 & 0x03FF0000) >> 16) != 0x142)) {
  1657. result |= 0x01;
  1658. } else { /* if Tx not OK, ignore Rx */
  1659. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  1660. ("Path A Tx IQK fail!!\n"));
  1661. continue;
  1662. }
  1663. /* if Tx is OK, check whether Rx is OK */
  1664. if (!(regeac & RxOKBit) &&
  1665. (((regea4 & 0x03FF0000) >> 16) != 0x132)) {
  1666. result |= 0x02;
  1667. break;
  1668. } else {
  1669. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  1670. ("Path A Rx IQK fail!!\n"));
  1671. }
  1672. }
  1673. /* path A PA off */
  1674. rtl_set_bbreg(hw, RFPGA0_XAB_RFINTERFACESW, BMASKDWORD,
  1675. rtlphy->iqk_bb_backup[0]);
  1676. rtl_set_bbreg(hw, RFPGA0_XA_RFINTERFACEOE, BMASKDWORD,
  1677. rtlphy->iqk_bb_backup[1]);
  1678. return result;
  1679. }
  1680. /* bit0 = 1 => Tx OK, bit1 = 1 => Rx OK */
  1681. static u8 _rtl92d_phy_pathb_iqk(struct ieee80211_hw *hw)
  1682. {
  1683. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1684. u32 regeac, regeb4, regebc, regec4, regecc;
  1685. u8 result = 0;
  1686. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("Path B IQK!\n"));
  1687. /* One shot, path B LOK & IQK */
  1688. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("One shot, path A LOK & IQK!\n"));
  1689. rtl_set_bbreg(hw, 0xe60, BMASKDWORD, 0x00000002);
  1690. rtl_set_bbreg(hw, 0xe60, BMASKDWORD, 0x00000000);
  1691. /* delay x ms */
  1692. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  1693. ("Delay %d ms for One shot, path B LOK & IQK.\n",
  1694. IQK_DELAY_TIME));
  1695. mdelay(IQK_DELAY_TIME);
  1696. /* Check failed */
  1697. regeac = rtl_get_bbreg(hw, 0xeac, BMASKDWORD);
  1698. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("0xeac = 0x%x\n", regeac));
  1699. regeb4 = rtl_get_bbreg(hw, 0xeb4, BMASKDWORD);
  1700. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("0xeb4 = 0x%x\n", regeb4));
  1701. regebc = rtl_get_bbreg(hw, 0xebc, BMASKDWORD);
  1702. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("0xebc = 0x%x\n", regebc));
  1703. regec4 = rtl_get_bbreg(hw, 0xec4, BMASKDWORD);
  1704. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("0xec4 = 0x%x\n", regec4));
  1705. regecc = rtl_get_bbreg(hw, 0xecc, BMASKDWORD);
  1706. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("0xecc = 0x%x\n", regecc));
  1707. if (!(regeac & BIT(31)) && (((regeb4 & 0x03FF0000) >> 16) != 0x142) &&
  1708. (((regebc & 0x03FF0000) >> 16) != 0x42))
  1709. result |= 0x01;
  1710. else
  1711. return result;
  1712. if (!(regeac & BIT(30)) && (((regec4 & 0x03FF0000) >> 16) != 0x132) &&
  1713. (((regecc & 0x03FF0000) >> 16) != 0x36))
  1714. result |= 0x02;
  1715. else
  1716. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("Path B Rx IQK fail!!\n"));
  1717. return result;
  1718. }
  1719. /* bit0 = 1 => Tx OK, bit1 = 1 => Rx OK */
  1720. static u8 _rtl92d_phy_pathb_iqk_5g_normal(struct ieee80211_hw *hw)
  1721. {
  1722. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1723. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  1724. u32 regeac, regeb4, regebc, regec4, regecc;
  1725. u8 result = 0;
  1726. u8 i;
  1727. u8 retrycount = 2;
  1728. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("Path B IQK!\n"));
  1729. /* path-A IQK setting */
  1730. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("Path-A IQK setting!\n"));
  1731. rtl_set_bbreg(hw, 0xe30, BMASKDWORD, 0x18008c1f);
  1732. rtl_set_bbreg(hw, 0xe34, BMASKDWORD, 0x18008c1f);
  1733. rtl_set_bbreg(hw, 0xe38, BMASKDWORD, 0x82110000);
  1734. rtl_set_bbreg(hw, 0xe3c, BMASKDWORD, 0x68110000);
  1735. /* path-B IQK setting */
  1736. rtl_set_bbreg(hw, 0xe50, BMASKDWORD, 0x18008c2f);
  1737. rtl_set_bbreg(hw, 0xe54, BMASKDWORD, 0x18008c2f);
  1738. rtl_set_bbreg(hw, 0xe58, BMASKDWORD, 0x82140307);
  1739. rtl_set_bbreg(hw, 0xe5c, BMASKDWORD, 0x68160960);
  1740. /* LO calibration setting */
  1741. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("LO calibration setting!\n"));
  1742. rtl_set_bbreg(hw, 0xe4c, BMASKDWORD, 0x00462911);
  1743. /* path-B PA on */
  1744. rtl_set_bbreg(hw, RFPGA0_XAB_RFINTERFACESW, BMASKDWORD, 0x0f600700);
  1745. rtl_set_bbreg(hw, RFPGA0_XB_RFINTERFACEOE, BMASKDWORD, 0x061f0d30);
  1746. for (i = 0; i < retrycount; i++) {
  1747. /* One shot, path B LOK & IQK */
  1748. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  1749. ("One shot, path A LOK & IQK!\n"));
  1750. rtl_set_bbreg(hw, 0xe48, BMASKDWORD, 0xfa000000);
  1751. rtl_set_bbreg(hw, 0xe48, BMASKDWORD, 0xf8000000);
  1752. /* delay x ms */
  1753. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  1754. ("Delay %d ms for One shot, path B LOK & IQK.\n", 10));
  1755. mdelay(IQK_DELAY_TIME * 10);
  1756. /* Check failed */
  1757. regeac = rtl_get_bbreg(hw, 0xeac, BMASKDWORD);
  1758. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("0xeac = 0x%x\n", regeac));
  1759. regeb4 = rtl_get_bbreg(hw, 0xeb4, BMASKDWORD);
  1760. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("0xeb4 = 0x%x\n", regeb4));
  1761. regebc = rtl_get_bbreg(hw, 0xebc, BMASKDWORD);
  1762. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("0xebc = 0x%x\n", regebc));
  1763. regec4 = rtl_get_bbreg(hw, 0xec4, BMASKDWORD);
  1764. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("0xec4 = 0x%x\n", regec4));
  1765. regecc = rtl_get_bbreg(hw, 0xecc, BMASKDWORD);
  1766. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("0xecc = 0x%x\n", regecc));
  1767. if (!(regeac & BIT(31)) &&
  1768. (((regeb4 & 0x03FF0000) >> 16) != 0x142))
  1769. result |= 0x01;
  1770. else
  1771. continue;
  1772. if (!(regeac & BIT(30)) &&
  1773. (((regec4 & 0x03FF0000) >> 16) != 0x132)) {
  1774. result |= 0x02;
  1775. break;
  1776. } else {
  1777. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  1778. ("Path B Rx IQK fail!!\n"));
  1779. }
  1780. }
  1781. /* path B PA off */
  1782. rtl_set_bbreg(hw, RFPGA0_XAB_RFINTERFACESW, BMASKDWORD,
  1783. rtlphy->iqk_bb_backup[0]);
  1784. rtl_set_bbreg(hw, RFPGA0_XB_RFINTERFACEOE, BMASKDWORD,
  1785. rtlphy->iqk_bb_backup[2]);
  1786. return result;
  1787. }
  1788. static void _rtl92d_phy_save_adda_registers(struct ieee80211_hw *hw,
  1789. u32 *adda_reg, u32 *adda_backup,
  1790. u32 regnum)
  1791. {
  1792. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1793. u32 i;
  1794. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("Save ADDA parameters.\n"));
  1795. for (i = 0; i < regnum; i++)
  1796. adda_backup[i] = rtl_get_bbreg(hw, adda_reg[i], BMASKDWORD);
  1797. }
  1798. static void _rtl92d_phy_save_mac_registers(struct ieee80211_hw *hw,
  1799. u32 *macreg, u32 *macbackup)
  1800. {
  1801. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1802. u32 i;
  1803. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("Save MAC parameters.\n"));
  1804. for (i = 0; i < (IQK_MAC_REG_NUM - 1); i++)
  1805. macbackup[i] = rtl_read_byte(rtlpriv, macreg[i]);
  1806. macbackup[i] = rtl_read_dword(rtlpriv, macreg[i]);
  1807. }
  1808. static void _rtl92d_phy_reload_adda_registers(struct ieee80211_hw *hw,
  1809. u32 *adda_reg, u32 *adda_backup,
  1810. u32 regnum)
  1811. {
  1812. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1813. u32 i;
  1814. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  1815. ("Reload ADDA power saving parameters !\n"));
  1816. for (i = 0; i < regnum; i++)
  1817. rtl_set_bbreg(hw, adda_reg[i], BMASKDWORD, adda_backup[i]);
  1818. }
  1819. static void _rtl92d_phy_reload_mac_registers(struct ieee80211_hw *hw,
  1820. u32 *macreg, u32 *macbackup)
  1821. {
  1822. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1823. u32 i;
  1824. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("Reload MAC parameters !\n"));
  1825. for (i = 0; i < (IQK_MAC_REG_NUM - 1); i++)
  1826. rtl_write_byte(rtlpriv, macreg[i], (u8) macbackup[i]);
  1827. rtl_write_byte(rtlpriv, macreg[i], macbackup[i]);
  1828. }
  1829. static void _rtl92d_phy_path_adda_on(struct ieee80211_hw *hw,
  1830. u32 *adda_reg, bool patha_on, bool is2t)
  1831. {
  1832. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1833. u32 pathon;
  1834. u32 i;
  1835. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("ADDA ON.\n"));
  1836. pathon = patha_on ? 0x04db25a4 : 0x0b1b25a4;
  1837. if (patha_on)
  1838. pathon = rtlpriv->rtlhal.interfaceindex == 0 ?
  1839. 0x04db25a4 : 0x0b1b25a4;
  1840. for (i = 0; i < IQK_ADDA_REG_NUM; i++)
  1841. rtl_set_bbreg(hw, adda_reg[i], BMASKDWORD, pathon);
  1842. }
  1843. static void _rtl92d_phy_mac_setting_calibration(struct ieee80211_hw *hw,
  1844. u32 *macreg, u32 *macbackup)
  1845. {
  1846. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1847. u32 i;
  1848. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("MAC settings for Calibration.\n"));
  1849. rtl_write_byte(rtlpriv, macreg[0], 0x3F);
  1850. for (i = 1; i < (IQK_MAC_REG_NUM - 1); i++)
  1851. rtl_write_byte(rtlpriv, macreg[i], (u8)(macbackup[i] &
  1852. (~BIT(3))));
  1853. rtl_write_byte(rtlpriv, macreg[i], (u8) (macbackup[i] & (~BIT(5))));
  1854. }
  1855. static void _rtl92d_phy_patha_standby(struct ieee80211_hw *hw)
  1856. {
  1857. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1858. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("Path-A standby mode!\n"));
  1859. rtl_set_bbreg(hw, 0xe28, BMASKDWORD, 0x0);
  1860. rtl_set_bbreg(hw, RFPGA0_XA_LSSIPARAMETER, BMASKDWORD, 0x00010000);
  1861. rtl_set_bbreg(hw, 0xe28, BMASKDWORD, 0x80800000);
  1862. }
  1863. static void _rtl92d_phy_pimode_switch(struct ieee80211_hw *hw, bool pi_mode)
  1864. {
  1865. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1866. u32 mode;
  1867. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  1868. ("BB Switch to %s mode!\n", (pi_mode ? "PI" : "SI")));
  1869. mode = pi_mode ? 0x01000100 : 0x01000000;
  1870. rtl_set_bbreg(hw, 0x820, BMASKDWORD, mode);
  1871. rtl_set_bbreg(hw, 0x828, BMASKDWORD, mode);
  1872. }
  1873. static void _rtl92d_phy_iq_calibrate(struct ieee80211_hw *hw, long result[][8],
  1874. u8 t, bool is2t)
  1875. {
  1876. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1877. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  1878. u32 i;
  1879. u8 patha_ok, pathb_ok;
  1880. static u32 adda_reg[IQK_ADDA_REG_NUM] = {
  1881. RFPGA0_XCD_SWITCHCONTROL, 0xe6c, 0xe70, 0xe74,
  1882. 0xe78, 0xe7c, 0xe80, 0xe84,
  1883. 0xe88, 0xe8c, 0xed0, 0xed4,
  1884. 0xed8, 0xedc, 0xee0, 0xeec
  1885. };
  1886. static u32 iqk_mac_reg[IQK_MAC_REG_NUM] = {
  1887. 0x522, 0x550, 0x551, 0x040
  1888. };
  1889. static u32 iqk_bb_reg[IQK_BB_REG_NUM] = {
  1890. RFPGA0_XAB_RFINTERFACESW, RFPGA0_XA_RFINTERFACEOE,
  1891. RFPGA0_XB_RFINTERFACEOE, ROFDM0_TRMUXPAR,
  1892. RFPGA0_XCD_RFINTERFACESW, ROFDM0_TRXPATHENABLE,
  1893. RFPGA0_RFMOD, RFPGA0_ANALOGPARAMETER4,
  1894. ROFDM0_XAAGCCORE1, ROFDM0_XBAGCCORE1
  1895. };
  1896. const u32 retrycount = 2;
  1897. u32 bbvalue;
  1898. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("IQK for 2.4G :Start!!!\n"));
  1899. if (t == 0) {
  1900. bbvalue = rtl_get_bbreg(hw, RFPGA0_RFMOD, BMASKDWORD);
  1901. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("==>0x%08x\n", bbvalue));
  1902. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("IQ Calibration for %s\n",
  1903. (is2t ? "2T2R" : "1T1R")));
  1904. /* Save ADDA parameters, turn Path A ADDA on */
  1905. _rtl92d_phy_save_adda_registers(hw, adda_reg,
  1906. rtlphy->adda_backup, IQK_ADDA_REG_NUM);
  1907. _rtl92d_phy_save_mac_registers(hw, iqk_mac_reg,
  1908. rtlphy->iqk_mac_backup);
  1909. _rtl92d_phy_save_adda_registers(hw, iqk_bb_reg,
  1910. rtlphy->iqk_bb_backup, IQK_BB_REG_NUM);
  1911. }
  1912. _rtl92d_phy_path_adda_on(hw, adda_reg, true, is2t);
  1913. if (t == 0)
  1914. rtlphy->rfpi_enable = (u8) rtl_get_bbreg(hw,
  1915. RFPGA0_XA_HSSIPARAMETER1, BIT(8));
  1916. /* Switch BB to PI mode to do IQ Calibration. */
  1917. if (!rtlphy->rfpi_enable)
  1918. _rtl92d_phy_pimode_switch(hw, true);
  1919. rtl_set_bbreg(hw, RFPGA0_RFMOD, BIT(24), 0x00);
  1920. rtl_set_bbreg(hw, ROFDM0_TRXPATHENABLE, BMASKDWORD, 0x03a05600);
  1921. rtl_set_bbreg(hw, ROFDM0_TRMUXPAR, BMASKDWORD, 0x000800e4);
  1922. rtl_set_bbreg(hw, RFPGA0_XCD_RFINTERFACESW, BMASKDWORD, 0x22204000);
  1923. rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER4, 0xf00000, 0x0f);
  1924. if (is2t) {
  1925. rtl_set_bbreg(hw, RFPGA0_XA_LSSIPARAMETER, BMASKDWORD,
  1926. 0x00010000);
  1927. rtl_set_bbreg(hw, RFPGA0_XB_LSSIPARAMETER, BMASKDWORD,
  1928. 0x00010000);
  1929. }
  1930. /* MAC settings */
  1931. _rtl92d_phy_mac_setting_calibration(hw, iqk_mac_reg,
  1932. rtlphy->iqk_mac_backup);
  1933. /* Page B init */
  1934. rtl_set_bbreg(hw, 0xb68, BMASKDWORD, 0x0f600000);
  1935. if (is2t)
  1936. rtl_set_bbreg(hw, 0xb6c, BMASKDWORD, 0x0f600000);
  1937. /* IQ calibration setting */
  1938. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("IQK setting!\n"));
  1939. rtl_set_bbreg(hw, 0xe28, BMASKDWORD, 0x80800000);
  1940. rtl_set_bbreg(hw, 0xe40, BMASKDWORD, 0x01007c00);
  1941. rtl_set_bbreg(hw, 0xe44, BMASKDWORD, 0x01004800);
  1942. for (i = 0; i < retrycount; i++) {
  1943. patha_ok = _rtl92d_phy_patha_iqk(hw, is2t);
  1944. if (patha_ok == 0x03) {
  1945. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  1946. ("Path A IQK Success!!\n"));
  1947. result[t][0] = (rtl_get_bbreg(hw, 0xe94, BMASKDWORD) &
  1948. 0x3FF0000) >> 16;
  1949. result[t][1] = (rtl_get_bbreg(hw, 0xe9c, BMASKDWORD) &
  1950. 0x3FF0000) >> 16;
  1951. result[t][2] = (rtl_get_bbreg(hw, 0xea4, BMASKDWORD) &
  1952. 0x3FF0000) >> 16;
  1953. result[t][3] = (rtl_get_bbreg(hw, 0xeac, BMASKDWORD) &
  1954. 0x3FF0000) >> 16;
  1955. break;
  1956. } else if (i == (retrycount - 1) && patha_ok == 0x01) {
  1957. /* Tx IQK OK */
  1958. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  1959. ("Path A IQK Only Tx Success!!\n"));
  1960. result[t][0] = (rtl_get_bbreg(hw, 0xe94, BMASKDWORD) &
  1961. 0x3FF0000) >> 16;
  1962. result[t][1] = (rtl_get_bbreg(hw, 0xe9c, BMASKDWORD) &
  1963. 0x3FF0000) >> 16;
  1964. }
  1965. }
  1966. if (0x00 == patha_ok)
  1967. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("Path A IQK failed!!\n"));
  1968. if (is2t) {
  1969. _rtl92d_phy_patha_standby(hw);
  1970. /* Turn Path B ADDA on */
  1971. _rtl92d_phy_path_adda_on(hw, adda_reg, false, is2t);
  1972. for (i = 0; i < retrycount; i++) {
  1973. pathb_ok = _rtl92d_phy_pathb_iqk(hw);
  1974. if (pathb_ok == 0x03) {
  1975. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  1976. ("Path B IQK Success!!\n"));
  1977. result[t][4] = (rtl_get_bbreg(hw, 0xeb4,
  1978. BMASKDWORD) & 0x3FF0000) >> 16;
  1979. result[t][5] = (rtl_get_bbreg(hw, 0xebc,
  1980. BMASKDWORD) & 0x3FF0000) >> 16;
  1981. result[t][6] = (rtl_get_bbreg(hw, 0xec4,
  1982. BMASKDWORD) & 0x3FF0000) >> 16;
  1983. result[t][7] = (rtl_get_bbreg(hw, 0xecc,
  1984. BMASKDWORD) & 0x3FF0000) >> 16;
  1985. break;
  1986. } else if (i == (retrycount - 1) && pathb_ok == 0x01) {
  1987. /* Tx IQK OK */
  1988. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  1989. ("Path B Only Tx IQK Success!!\n"));
  1990. result[t][4] = (rtl_get_bbreg(hw, 0xeb4,
  1991. BMASKDWORD) & 0x3FF0000) >> 16;
  1992. result[t][5] = (rtl_get_bbreg(hw, 0xebc,
  1993. BMASKDWORD) & 0x3FF0000) >> 16;
  1994. }
  1995. }
  1996. if (0x00 == pathb_ok)
  1997. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  1998. ("Path B IQK failed!!\n"));
  1999. }
  2000. /* Back to BB mode, load original value */
  2001. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  2002. ("IQK:Back to BB mode, load original value!\n"));
  2003. rtl_set_bbreg(hw, 0xe28, BMASKDWORD, 0);
  2004. if (t != 0) {
  2005. /* Switch back BB to SI mode after finish IQ Calibration. */
  2006. if (!rtlphy->rfpi_enable)
  2007. _rtl92d_phy_pimode_switch(hw, false);
  2008. /* Reload ADDA power saving parameters */
  2009. _rtl92d_phy_reload_adda_registers(hw, adda_reg,
  2010. rtlphy->adda_backup, IQK_ADDA_REG_NUM);
  2011. /* Reload MAC parameters */
  2012. _rtl92d_phy_reload_mac_registers(hw, iqk_mac_reg,
  2013. rtlphy->iqk_mac_backup);
  2014. if (is2t)
  2015. _rtl92d_phy_reload_adda_registers(hw, iqk_bb_reg,
  2016. rtlphy->iqk_bb_backup,
  2017. IQK_BB_REG_NUM);
  2018. else
  2019. _rtl92d_phy_reload_adda_registers(hw, iqk_bb_reg,
  2020. rtlphy->iqk_bb_backup,
  2021. IQK_BB_REG_NUM - 1);
  2022. /* load 0xe30 IQC default value */
  2023. rtl_set_bbreg(hw, 0xe30, BMASKDWORD, 0x01008c00);
  2024. rtl_set_bbreg(hw, 0xe34, BMASKDWORD, 0x01008c00);
  2025. }
  2026. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("<==\n"));
  2027. }
  2028. static void _rtl92d_phy_iq_calibrate_5g_normal(struct ieee80211_hw *hw,
  2029. long result[][8], u8 t)
  2030. {
  2031. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2032. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  2033. struct rtl_hal *rtlhal = &(rtlpriv->rtlhal);
  2034. u8 patha_ok, pathb_ok;
  2035. static u32 adda_reg[IQK_ADDA_REG_NUM] = {
  2036. RFPGA0_XCD_SWITCHCONTROL, 0xe6c, 0xe70, 0xe74,
  2037. 0xe78, 0xe7c, 0xe80, 0xe84,
  2038. 0xe88, 0xe8c, 0xed0, 0xed4,
  2039. 0xed8, 0xedc, 0xee0, 0xeec
  2040. };
  2041. static u32 iqk_mac_reg[IQK_MAC_REG_NUM] = {
  2042. 0x522, 0x550, 0x551, 0x040
  2043. };
  2044. static u32 iqk_bb_reg[IQK_BB_REG_NUM] = {
  2045. RFPGA0_XAB_RFINTERFACESW, RFPGA0_XA_RFINTERFACEOE,
  2046. RFPGA0_XB_RFINTERFACEOE, ROFDM0_TRMUXPAR,
  2047. RFPGA0_XCD_RFINTERFACESW, ROFDM0_TRXPATHENABLE,
  2048. RFPGA0_RFMOD, RFPGA0_ANALOGPARAMETER4,
  2049. ROFDM0_XAAGCCORE1, ROFDM0_XBAGCCORE1
  2050. };
  2051. u32 bbvalue;
  2052. bool is2t = IS_92D_SINGLEPHY(rtlhal->version);
  2053. /* Note: IQ calibration must be performed after loading
  2054. * PHY_REG.txt , and radio_a, radio_b.txt */
  2055. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("IQK for 5G NORMAL:Start!!!\n"));
  2056. mdelay(IQK_DELAY_TIME * 20);
  2057. if (t == 0) {
  2058. bbvalue = rtl_get_bbreg(hw, RFPGA0_RFMOD, BMASKDWORD);
  2059. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("==>0x%08x\n", bbvalue));
  2060. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("IQ Calibration for %s\n",
  2061. (is2t ? "2T2R" : "1T1R")));
  2062. /* Save ADDA parameters, turn Path A ADDA on */
  2063. _rtl92d_phy_save_adda_registers(hw, adda_reg,
  2064. rtlphy->adda_backup,
  2065. IQK_ADDA_REG_NUM);
  2066. _rtl92d_phy_save_mac_registers(hw, iqk_mac_reg,
  2067. rtlphy->iqk_mac_backup);
  2068. if (is2t)
  2069. _rtl92d_phy_save_adda_registers(hw, iqk_bb_reg,
  2070. rtlphy->iqk_bb_backup,
  2071. IQK_BB_REG_NUM);
  2072. else
  2073. _rtl92d_phy_save_adda_registers(hw, iqk_bb_reg,
  2074. rtlphy->iqk_bb_backup,
  2075. IQK_BB_REG_NUM - 1);
  2076. }
  2077. _rtl92d_phy_path_adda_on(hw, adda_reg, true, is2t);
  2078. /* MAC settings */
  2079. _rtl92d_phy_mac_setting_calibration(hw, iqk_mac_reg,
  2080. rtlphy->iqk_mac_backup);
  2081. if (t == 0)
  2082. rtlphy->rfpi_enable = (u8) rtl_get_bbreg(hw,
  2083. RFPGA0_XA_HSSIPARAMETER1, BIT(8));
  2084. /* Switch BB to PI mode to do IQ Calibration. */
  2085. if (!rtlphy->rfpi_enable)
  2086. _rtl92d_phy_pimode_switch(hw, true);
  2087. rtl_set_bbreg(hw, RFPGA0_RFMOD, BIT(24), 0x00);
  2088. rtl_set_bbreg(hw, ROFDM0_TRXPATHENABLE, BMASKDWORD, 0x03a05600);
  2089. rtl_set_bbreg(hw, ROFDM0_TRMUXPAR, BMASKDWORD, 0x000800e4);
  2090. rtl_set_bbreg(hw, RFPGA0_XCD_RFINTERFACESW, BMASKDWORD, 0x22208000);
  2091. rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER4, 0xf00000, 0x0f);
  2092. /* Page B init */
  2093. rtl_set_bbreg(hw, 0xb68, BMASKDWORD, 0x0f600000);
  2094. if (is2t)
  2095. rtl_set_bbreg(hw, 0xb6c, BMASKDWORD, 0x0f600000);
  2096. /* IQ calibration setting */
  2097. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("IQK setting!\n"));
  2098. rtl_set_bbreg(hw, 0xe28, BMASKDWORD, 0x80800000);
  2099. rtl_set_bbreg(hw, 0xe40, BMASKDWORD, 0x10007c00);
  2100. rtl_set_bbreg(hw, 0xe44, BMASKDWORD, 0x01004800);
  2101. patha_ok = _rtl92d_phy_patha_iqk_5g_normal(hw, is2t);
  2102. if (patha_ok == 0x03) {
  2103. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("Path A IQK Success!!\n"));
  2104. result[t][0] = (rtl_get_bbreg(hw, 0xe94, BMASKDWORD) &
  2105. 0x3FF0000) >> 16;
  2106. result[t][1] = (rtl_get_bbreg(hw, 0xe9c, BMASKDWORD) &
  2107. 0x3FF0000) >> 16;
  2108. result[t][2] = (rtl_get_bbreg(hw, 0xea4, BMASKDWORD) &
  2109. 0x3FF0000) >> 16;
  2110. result[t][3] = (rtl_get_bbreg(hw, 0xeac, BMASKDWORD) &
  2111. 0x3FF0000) >> 16;
  2112. } else if (patha_ok == 0x01) { /* Tx IQK OK */
  2113. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  2114. ("Path A IQK Only Tx Success!!\n"));
  2115. result[t][0] = (rtl_get_bbreg(hw, 0xe94, BMASKDWORD) &
  2116. 0x3FF0000) >> 16;
  2117. result[t][1] = (rtl_get_bbreg(hw, 0xe9c, BMASKDWORD) &
  2118. 0x3FF0000) >> 16;
  2119. } else {
  2120. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("Path A IQK Fail!!\n"));
  2121. }
  2122. if (is2t) {
  2123. /* _rtl92d_phy_patha_standby(hw); */
  2124. /* Turn Path B ADDA on */
  2125. _rtl92d_phy_path_adda_on(hw, adda_reg, false, is2t);
  2126. pathb_ok = _rtl92d_phy_pathb_iqk_5g_normal(hw);
  2127. if (pathb_ok == 0x03) {
  2128. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  2129. ("Path B IQK Success!!\n"));
  2130. result[t][4] = (rtl_get_bbreg(hw, 0xeb4, BMASKDWORD) &
  2131. 0x3FF0000) >> 16;
  2132. result[t][5] = (rtl_get_bbreg(hw, 0xebc, BMASKDWORD) &
  2133. 0x3FF0000) >> 16;
  2134. result[t][6] = (rtl_get_bbreg(hw, 0xec4, BMASKDWORD) &
  2135. 0x3FF0000) >> 16;
  2136. result[t][7] = (rtl_get_bbreg(hw, 0xecc, BMASKDWORD) &
  2137. 0x3FF0000) >> 16;
  2138. } else if (pathb_ok == 0x01) { /* Tx IQK OK */
  2139. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  2140. ("Path B Only Tx IQK Success!!\n"));
  2141. result[t][4] = (rtl_get_bbreg(hw, 0xeb4, BMASKDWORD) &
  2142. 0x3FF0000) >> 16;
  2143. result[t][5] = (rtl_get_bbreg(hw, 0xebc, BMASKDWORD) &
  2144. 0x3FF0000) >> 16;
  2145. } else {
  2146. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  2147. ("Path B IQK failed!!\n"));
  2148. }
  2149. }
  2150. /* Back to BB mode, load original value */
  2151. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  2152. ("IQK:Back to BB mode, load original value!\n"));
  2153. rtl_set_bbreg(hw, 0xe28, BMASKDWORD, 0);
  2154. if (t != 0) {
  2155. if (is2t)
  2156. _rtl92d_phy_reload_adda_registers(hw, iqk_bb_reg,
  2157. rtlphy->iqk_bb_backup,
  2158. IQK_BB_REG_NUM);
  2159. else
  2160. _rtl92d_phy_reload_adda_registers(hw, iqk_bb_reg,
  2161. rtlphy->iqk_bb_backup,
  2162. IQK_BB_REG_NUM - 1);
  2163. /* Reload MAC parameters */
  2164. _rtl92d_phy_reload_mac_registers(hw, iqk_mac_reg,
  2165. rtlphy->iqk_mac_backup);
  2166. /* Switch back BB to SI mode after finish IQ Calibration. */
  2167. if (!rtlphy->rfpi_enable)
  2168. _rtl92d_phy_pimode_switch(hw, false);
  2169. /* Reload ADDA power saving parameters */
  2170. _rtl92d_phy_reload_adda_registers(hw, adda_reg,
  2171. rtlphy->adda_backup,
  2172. IQK_ADDA_REG_NUM);
  2173. }
  2174. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("<==\n"));
  2175. }
  2176. static bool _rtl92d_phy_simularity_compare(struct ieee80211_hw *hw,
  2177. long result[][8], u8 c1, u8 c2)
  2178. {
  2179. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2180. struct rtl_hal *rtlhal = &(rtlpriv->rtlhal);
  2181. u32 i, j, diff, sim_bitmap, bound;
  2182. u8 final_candidate[2] = {0xFF, 0xFF}; /* for path A and path B */
  2183. bool bresult = true;
  2184. bool is2t = IS_92D_SINGLEPHY(rtlhal->version);
  2185. if (is2t)
  2186. bound = 8;
  2187. else
  2188. bound = 4;
  2189. sim_bitmap = 0;
  2190. for (i = 0; i < bound; i++) {
  2191. diff = (result[c1][i] > result[c2][i]) ? (result[c1][i] -
  2192. result[c2][i]) : (result[c2][i] - result[c1][i]);
  2193. if (diff > MAX_TOLERANCE_92D) {
  2194. if ((i == 2 || i == 6) && !sim_bitmap) {
  2195. if (result[c1][i] + result[c1][i + 1] == 0)
  2196. final_candidate[(i / 4)] = c2;
  2197. else if (result[c2][i] + result[c2][i + 1] == 0)
  2198. final_candidate[(i / 4)] = c1;
  2199. else
  2200. sim_bitmap = sim_bitmap | (1 << i);
  2201. } else {
  2202. sim_bitmap = sim_bitmap | (1 << i);
  2203. }
  2204. }
  2205. }
  2206. if (sim_bitmap == 0) {
  2207. for (i = 0; i < (bound / 4); i++) {
  2208. if (final_candidate[i] != 0xFF) {
  2209. for (j = i * 4; j < (i + 1) * 4 - 2; j++)
  2210. result[3][j] =
  2211. result[final_candidate[i]][j];
  2212. bresult = false;
  2213. }
  2214. }
  2215. return bresult;
  2216. }
  2217. if (!(sim_bitmap & 0x0F)) { /* path A OK */
  2218. for (i = 0; i < 4; i++)
  2219. result[3][i] = result[c1][i];
  2220. } else if (!(sim_bitmap & 0x03)) { /* path A, Tx OK */
  2221. for (i = 0; i < 2; i++)
  2222. result[3][i] = result[c1][i];
  2223. }
  2224. if (!(sim_bitmap & 0xF0) && is2t) { /* path B OK */
  2225. for (i = 4; i < 8; i++)
  2226. result[3][i] = result[c1][i];
  2227. } else if (!(sim_bitmap & 0x30)) { /* path B, Tx OK */
  2228. for (i = 4; i < 6; i++)
  2229. result[3][i] = result[c1][i];
  2230. }
  2231. return false;
  2232. }
  2233. static void _rtl92d_phy_patha_fill_iqk_matrix(struct ieee80211_hw *hw,
  2234. bool iqk_ok, long result[][8],
  2235. u8 final_candidate, bool txonly)
  2236. {
  2237. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2238. struct rtl_hal *rtlhal = &(rtlpriv->rtlhal);
  2239. u32 oldval_0, val_x, tx0_a, reg;
  2240. long val_y, tx0_c;
  2241. bool is2t = IS_92D_SINGLEPHY(rtlhal->version) ||
  2242. rtlhal->macphymode == DUALMAC_DUALPHY;
  2243. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  2244. ("Path A IQ Calibration %s !\n",
  2245. (iqk_ok) ? "Success" : "Failed"));
  2246. if (final_candidate == 0xFF) {
  2247. return;
  2248. } else if (iqk_ok) {
  2249. oldval_0 = (rtl_get_bbreg(hw, ROFDM0_XATxIQIMBALANCE,
  2250. BMASKDWORD) >> 22) & 0x3FF; /* OFDM0_D */
  2251. val_x = result[final_candidate][0];
  2252. if ((val_x & 0x00000200) != 0)
  2253. val_x = val_x | 0xFFFFFC00;
  2254. tx0_a = (val_x * oldval_0) >> 8;
  2255. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("X = 0x%x, tx0_a = 0x%x,"
  2256. " oldval_0 0x%x\n", val_x, tx0_a, oldval_0));
  2257. rtl_set_bbreg(hw, ROFDM0_XATxIQIMBALANCE, 0x3FF, tx0_a);
  2258. rtl_set_bbreg(hw, ROFDM0_ECCATHRESHOLD, BIT(24),
  2259. ((val_x * oldval_0 >> 7) & 0x1));
  2260. val_y = result[final_candidate][1];
  2261. if ((val_y & 0x00000200) != 0)
  2262. val_y = val_y | 0xFFFFFC00;
  2263. /* path B IQK result + 3 */
  2264. if (rtlhal->interfaceindex == 1 &&
  2265. rtlhal->current_bandtype == BAND_ON_5G)
  2266. val_y += 3;
  2267. tx0_c = (val_y * oldval_0) >> 8;
  2268. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("Y = 0x%lx, tx0_c = 0x%lx\n",
  2269. val_y, tx0_c));
  2270. rtl_set_bbreg(hw, ROFDM0_XCTxAFE, 0xF0000000,
  2271. ((tx0_c & 0x3C0) >> 6));
  2272. rtl_set_bbreg(hw, ROFDM0_XATxIQIMBALANCE, 0x003F0000,
  2273. (tx0_c & 0x3F));
  2274. if (is2t)
  2275. rtl_set_bbreg(hw, ROFDM0_ECCATHRESHOLD, BIT(26),
  2276. ((val_y * oldval_0 >> 7) & 0x1));
  2277. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("0xC80 = 0x%x\n",
  2278. rtl_get_bbreg(hw, ROFDM0_XATxIQIMBALANCE,
  2279. BMASKDWORD)));
  2280. if (txonly) {
  2281. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("only Tx OK\n"));
  2282. return;
  2283. }
  2284. reg = result[final_candidate][2];
  2285. rtl_set_bbreg(hw, ROFDM0_XARXIQIMBALANCE, 0x3FF, reg);
  2286. reg = result[final_candidate][3] & 0x3F;
  2287. rtl_set_bbreg(hw, ROFDM0_XARXIQIMBALANCE, 0xFC00, reg);
  2288. reg = (result[final_candidate][3] >> 6) & 0xF;
  2289. rtl_set_bbreg(hw, 0xca0, 0xF0000000, reg);
  2290. }
  2291. }
  2292. static void _rtl92d_phy_pathb_fill_iqk_matrix(struct ieee80211_hw *hw,
  2293. bool iqk_ok, long result[][8], u8 final_candidate, bool txonly)
  2294. {
  2295. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2296. struct rtl_hal *rtlhal = &(rtlpriv->rtlhal);
  2297. u32 oldval_1, val_x, tx1_a, reg;
  2298. long val_y, tx1_c;
  2299. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("Path B IQ Calibration %s !\n",
  2300. (iqk_ok) ? "Success" : "Failed"));
  2301. if (final_candidate == 0xFF) {
  2302. return;
  2303. } else if (iqk_ok) {
  2304. oldval_1 = (rtl_get_bbreg(hw, ROFDM0_XBTxIQIMBALANCE,
  2305. BMASKDWORD) >> 22) & 0x3FF;
  2306. val_x = result[final_candidate][4];
  2307. if ((val_x & 0x00000200) != 0)
  2308. val_x = val_x | 0xFFFFFC00;
  2309. tx1_a = (val_x * oldval_1) >> 8;
  2310. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("X = 0x%x, tx1_a = 0x%x\n",
  2311. val_x, tx1_a));
  2312. rtl_set_bbreg(hw, ROFDM0_XBTxIQIMBALANCE, 0x3FF, tx1_a);
  2313. rtl_set_bbreg(hw, ROFDM0_ECCATHRESHOLD, BIT(28),
  2314. ((val_x * oldval_1 >> 7) & 0x1));
  2315. val_y = result[final_candidate][5];
  2316. if ((val_y & 0x00000200) != 0)
  2317. val_y = val_y | 0xFFFFFC00;
  2318. if (rtlhal->current_bandtype == BAND_ON_5G)
  2319. val_y += 3;
  2320. tx1_c = (val_y * oldval_1) >> 8;
  2321. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("Y = 0x%lx, tx1_c = 0x%lx\n",
  2322. val_y, tx1_c));
  2323. rtl_set_bbreg(hw, ROFDM0_XDTxAFE, 0xF0000000,
  2324. ((tx1_c & 0x3C0) >> 6));
  2325. rtl_set_bbreg(hw, ROFDM0_XBTxIQIMBALANCE, 0x003F0000,
  2326. (tx1_c & 0x3F));
  2327. rtl_set_bbreg(hw, ROFDM0_ECCATHRESHOLD, BIT(30),
  2328. ((val_y * oldval_1 >> 7) & 0x1));
  2329. if (txonly)
  2330. return;
  2331. reg = result[final_candidate][6];
  2332. rtl_set_bbreg(hw, ROFDM0_XBRXIQIMBALANCE, 0x3FF, reg);
  2333. reg = result[final_candidate][7] & 0x3F;
  2334. rtl_set_bbreg(hw, ROFDM0_XBRXIQIMBALANCE, 0xFC00, reg);
  2335. reg = (result[final_candidate][7] >> 6) & 0xF;
  2336. rtl_set_bbreg(hw, ROFDM0_AGCRSSITABLE, 0x0000F000, reg);
  2337. }
  2338. }
  2339. void rtl92d_phy_iq_calibrate(struct ieee80211_hw *hw)
  2340. {
  2341. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2342. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  2343. struct rtl_hal *rtlhal = &(rtlpriv->rtlhal);
  2344. long result[4][8];
  2345. u8 i, final_candidate, indexforchannel;
  2346. bool patha_ok, pathb_ok;
  2347. long rege94, rege9c, regea4, regeac, regeb4;
  2348. long regebc, regec4, regecc, regtmp = 0;
  2349. bool is12simular, is13simular, is23simular;
  2350. unsigned long flag = 0;
  2351. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  2352. ("IQK:Start!!!channel %d\n", rtlphy->current_channel));
  2353. for (i = 0; i < 8; i++) {
  2354. result[0][i] = 0;
  2355. result[1][i] = 0;
  2356. result[2][i] = 0;
  2357. result[3][i] = 0;
  2358. }
  2359. final_candidate = 0xff;
  2360. patha_ok = false;
  2361. pathb_ok = false;
  2362. is12simular = false;
  2363. is23simular = false;
  2364. is13simular = false;
  2365. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  2366. ("IQK !!!currentband %d\n", rtlhal->current_bandtype));
  2367. rtl92d_acquire_cckandrw_pagea_ctl(hw, &flag);
  2368. for (i = 0; i < 3; i++) {
  2369. if (rtlhal->current_bandtype == BAND_ON_5G) {
  2370. _rtl92d_phy_iq_calibrate_5g_normal(hw, result, i);
  2371. } else if (rtlhal->current_bandtype == BAND_ON_2_4G) {
  2372. if (IS_92D_SINGLEPHY(rtlhal->version))
  2373. _rtl92d_phy_iq_calibrate(hw, result, i, true);
  2374. else
  2375. _rtl92d_phy_iq_calibrate(hw, result, i, false);
  2376. }
  2377. if (i == 1) {
  2378. is12simular = _rtl92d_phy_simularity_compare(hw, result,
  2379. 0, 1);
  2380. if (is12simular) {
  2381. final_candidate = 0;
  2382. break;
  2383. }
  2384. }
  2385. if (i == 2) {
  2386. is13simular = _rtl92d_phy_simularity_compare(hw, result,
  2387. 0, 2);
  2388. if (is13simular) {
  2389. final_candidate = 0;
  2390. break;
  2391. }
  2392. is23simular = _rtl92d_phy_simularity_compare(hw, result,
  2393. 1, 2);
  2394. if (is23simular) {
  2395. final_candidate = 1;
  2396. } else {
  2397. for (i = 0; i < 8; i++)
  2398. regtmp += result[3][i];
  2399. if (regtmp != 0)
  2400. final_candidate = 3;
  2401. else
  2402. final_candidate = 0xFF;
  2403. }
  2404. }
  2405. }
  2406. rtl92d_release_cckandrw_pagea_ctl(hw, &flag);
  2407. for (i = 0; i < 4; i++) {
  2408. rege94 = result[i][0];
  2409. rege9c = result[i][1];
  2410. regea4 = result[i][2];
  2411. regeac = result[i][3];
  2412. regeb4 = result[i][4];
  2413. regebc = result[i][5];
  2414. regec4 = result[i][6];
  2415. regecc = result[i][7];
  2416. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  2417. ("IQK: rege94=%lx rege9c=%lx regea4=%lx regeac=%lx "
  2418. "regeb4=%lx regebc=%lx regec4=%lx regecc=%lx\n ",
  2419. rege94, rege9c, regea4, regeac, regeb4, regebc, regec4,
  2420. regecc));
  2421. }
  2422. if (final_candidate != 0xff) {
  2423. rtlphy->reg_e94 = rege94 = result[final_candidate][0];
  2424. rtlphy->reg_e9c = rege9c = result[final_candidate][1];
  2425. regea4 = result[final_candidate][2];
  2426. regeac = result[final_candidate][3];
  2427. rtlphy->reg_eb4 = regeb4 = result[final_candidate][4];
  2428. rtlphy->reg_ebc = regebc = result[final_candidate][5];
  2429. regec4 = result[final_candidate][6];
  2430. regecc = result[final_candidate][7];
  2431. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  2432. ("IQK: final_candidate is %x\n", final_candidate));
  2433. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  2434. ("IQK: rege94=%lx rege9c=%lx regea4=%lx regeac=%lx "
  2435. "regeb4=%lx regebc=%lx regec4=%lx regecc=%lx\n ",
  2436. rege94, rege9c, regea4, regeac, regeb4, regebc, regec4,
  2437. regecc));
  2438. patha_ok = pathb_ok = true;
  2439. } else {
  2440. rtlphy->reg_e94 = rtlphy->reg_eb4 = 0x100; /* X default value */
  2441. rtlphy->reg_e9c = rtlphy->reg_ebc = 0x0; /* Y default value */
  2442. }
  2443. if ((rege94 != 0) /*&&(regea4 != 0) */)
  2444. _rtl92d_phy_patha_fill_iqk_matrix(hw, patha_ok, result,
  2445. final_candidate, (regea4 == 0));
  2446. if (IS_92D_SINGLEPHY(rtlhal->version)) {
  2447. if ((regeb4 != 0) /*&&(regec4 != 0) */)
  2448. _rtl92d_phy_pathb_fill_iqk_matrix(hw, pathb_ok, result,
  2449. final_candidate, (regec4 == 0));
  2450. }
  2451. if (final_candidate != 0xFF) {
  2452. indexforchannel = rtl92d_get_rightchnlplace_for_iqk(
  2453. rtlphy->current_channel);
  2454. for (i = 0; i < IQK_MATRIX_REG_NUM; i++)
  2455. rtlphy->iqk_matrix_regsetting[indexforchannel].
  2456. value[0][i] = result[final_candidate][i];
  2457. rtlphy->iqk_matrix_regsetting[indexforchannel].iqk_done =
  2458. true;
  2459. RT_TRACE(rtlpriv, COMP_SCAN | COMP_MLME, DBG_LOUD,
  2460. ("\nIQK OK indexforchannel %d.\n", indexforchannel));
  2461. }
  2462. }
  2463. void rtl92d_phy_reload_iqk_setting(struct ieee80211_hw *hw, u8 channel)
  2464. {
  2465. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2466. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  2467. struct rtl_hal *rtlhal = &(rtlpriv->rtlhal);
  2468. u8 indexforchannel;
  2469. RT_TRACE(rtlpriv, COMP_CMD, DBG_LOUD, ("channel %d\n", channel));
  2470. /*------Do IQK for normal chip and test chip 5G band------- */
  2471. indexforchannel = rtl92d_get_rightchnlplace_for_iqk(channel);
  2472. RT_TRACE(rtlpriv, COMP_CMD, DBG_LOUD,
  2473. ("indexforchannel %d done %d\n", indexforchannel,
  2474. rtlphy->iqk_matrix_regsetting[indexforchannel].iqk_done));
  2475. if (0 && !rtlphy->iqk_matrix_regsetting[indexforchannel].iqk_done &&
  2476. rtlphy->need_iqk) {
  2477. /* Re Do IQK. */
  2478. RT_TRACE(rtlpriv, COMP_SCAN | COMP_INIT, DBG_LOUD,
  2479. ("Do IQK Matrix reg for channel:%d....\n", channel));
  2480. rtl92d_phy_iq_calibrate(hw);
  2481. } else {
  2482. /* Just load the value. */
  2483. /* 2G band just load once. */
  2484. if (((!rtlhal->load_imrandiqk_setting_for2g) &&
  2485. indexforchannel == 0) || indexforchannel > 0) {
  2486. RT_TRACE(rtlpriv, COMP_SCAN, DBG_LOUD,
  2487. ("Just Read IQK Matrix reg for channel:%d"
  2488. "....\n", channel));
  2489. if ((rtlphy->iqk_matrix_regsetting[indexforchannel].
  2490. value[0] != NULL)
  2491. /*&&(regea4 != 0) */)
  2492. _rtl92d_phy_patha_fill_iqk_matrix(hw, true,
  2493. rtlphy->iqk_matrix_regsetting[
  2494. indexforchannel].value, 0,
  2495. (rtlphy->iqk_matrix_regsetting[
  2496. indexforchannel].value[0][2] == 0));
  2497. if (IS_92D_SINGLEPHY(rtlhal->version)) {
  2498. if ((rtlphy->iqk_matrix_regsetting[
  2499. indexforchannel].value[0][4] != 0)
  2500. /*&&(regec4 != 0) */)
  2501. _rtl92d_phy_pathb_fill_iqk_matrix(hw,
  2502. true,
  2503. rtlphy->iqk_matrix_regsetting[
  2504. indexforchannel].value, 0,
  2505. (rtlphy->iqk_matrix_regsetting[
  2506. indexforchannel].value[0][6]
  2507. == 0));
  2508. }
  2509. }
  2510. }
  2511. rtlphy->need_iqk = false;
  2512. RT_TRACE(rtlpriv, COMP_CMD, DBG_LOUD, ("<====\n"));
  2513. }
  2514. static u32 _rtl92d_phy_get_abs(u32 val1, u32 val2)
  2515. {
  2516. u32 ret;
  2517. if (val1 >= val2)
  2518. ret = val1 - val2;
  2519. else
  2520. ret = val2 - val1;
  2521. return ret;
  2522. }
  2523. static bool _rtl92d_is_legal_5g_channel(struct ieee80211_hw *hw, u8 channel)
  2524. {
  2525. int i;
  2526. u8 channel_5g[45] = {
  2527. 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58,
  2528. 60, 62, 64, 100, 102, 104, 106, 108, 110, 112,
  2529. 114, 116, 118, 120, 122, 124, 126, 128, 130, 132,
  2530. 134, 136, 138, 140, 149, 151, 153, 155, 157, 159,
  2531. 161, 163, 165
  2532. };
  2533. for (i = 0; i < sizeof(channel_5g); i++)
  2534. if (channel == channel_5g[i])
  2535. return true;
  2536. return false;
  2537. }
  2538. static void _rtl92d_phy_calc_curvindex(struct ieee80211_hw *hw,
  2539. u32 *targetchnl, u32 * curvecount_val,
  2540. bool is5g, u32 *curveindex)
  2541. {
  2542. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2543. u32 smallest_abs_val = 0xffffffff, u4tmp;
  2544. u8 i, j;
  2545. u8 chnl_num = is5g ? TARGET_CHNL_NUM_5G : TARGET_CHNL_NUM_2G;
  2546. for (i = 0; i < chnl_num; i++) {
  2547. if (is5g && !_rtl92d_is_legal_5g_channel(hw, i + 1))
  2548. continue;
  2549. curveindex[i] = 0;
  2550. for (j = 0; j < (CV_CURVE_CNT * 2); j++) {
  2551. u4tmp = _rtl92d_phy_get_abs(targetchnl[i],
  2552. curvecount_val[j]);
  2553. if (u4tmp < smallest_abs_val) {
  2554. curveindex[i] = j;
  2555. smallest_abs_val = u4tmp;
  2556. }
  2557. }
  2558. smallest_abs_val = 0xffffffff;
  2559. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("curveindex[%d] = %x\n", i,
  2560. curveindex[i]));
  2561. }
  2562. }
  2563. static void _rtl92d_phy_reload_lck_setting(struct ieee80211_hw *hw,
  2564. u8 channel)
  2565. {
  2566. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2567. u8 erfpath = rtlpriv->rtlhal.current_bandtype ==
  2568. BAND_ON_5G ? RF90_PATH_A :
  2569. IS_92D_SINGLEPHY(rtlpriv->rtlhal.version) ?
  2570. RF90_PATH_B : RF90_PATH_A;
  2571. u32 u4tmp = 0, u4regvalue = 0;
  2572. bool bneed_powerdown_radio = false;
  2573. RT_TRACE(rtlpriv, COMP_CMD, DBG_LOUD, ("path %d\n", erfpath));
  2574. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("band type = %d\n",
  2575. rtlpriv->rtlhal.current_bandtype));
  2576. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("channel = %d\n", channel));
  2577. if (rtlpriv->rtlhal.current_bandtype == BAND_ON_5G) {/* Path-A for 5G */
  2578. u4tmp = curveindex_5g[channel-1];
  2579. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  2580. ("ver 1 set RF-A, 5G, 0x28 = 0x%ulx !!\n", u4tmp));
  2581. if (rtlpriv->rtlhal.macphymode == DUALMAC_DUALPHY &&
  2582. rtlpriv->rtlhal.interfaceindex == 1) {
  2583. bneed_powerdown_radio =
  2584. rtl92d_phy_enable_anotherphy(hw, false);
  2585. rtlpriv->rtlhal.during_mac1init_radioa = true;
  2586. /* asume no this case */
  2587. if (bneed_powerdown_radio)
  2588. _rtl92d_phy_enable_rf_env(hw, erfpath,
  2589. &u4regvalue);
  2590. }
  2591. rtl_set_rfreg(hw, erfpath, RF_SYN_G4, 0x3f800, u4tmp);
  2592. if (bneed_powerdown_radio)
  2593. _rtl92d_phy_restore_rf_env(hw, erfpath, &u4regvalue);
  2594. if (rtlpriv->rtlhal.during_mac1init_radioa)
  2595. rtl92d_phy_powerdown_anotherphy(hw, false);
  2596. } else if (rtlpriv->rtlhal.current_bandtype == BAND_ON_2_4G) {
  2597. u4tmp = curveindex_2g[channel-1];
  2598. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  2599. ("ver 3 set RF-B, 2G, 0x28 = 0x%ulx !!\n", u4tmp));
  2600. if (rtlpriv->rtlhal.macphymode == DUALMAC_DUALPHY &&
  2601. rtlpriv->rtlhal.interfaceindex == 0) {
  2602. bneed_powerdown_radio =
  2603. rtl92d_phy_enable_anotherphy(hw, true);
  2604. rtlpriv->rtlhal.during_mac0init_radiob = true;
  2605. if (bneed_powerdown_radio)
  2606. _rtl92d_phy_enable_rf_env(hw, erfpath,
  2607. &u4regvalue);
  2608. }
  2609. rtl_set_rfreg(hw, erfpath, RF_SYN_G4, 0x3f800, u4tmp);
  2610. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  2611. ("ver 3 set RF-B, 2G, 0x28 = 0x%ulx !!\n",
  2612. rtl_get_rfreg(hw, erfpath, RF_SYN_G4, 0x3f800)));
  2613. if (bneed_powerdown_radio)
  2614. _rtl92d_phy_restore_rf_env(hw, erfpath, &u4regvalue);
  2615. if (rtlpriv->rtlhal.during_mac0init_radiob)
  2616. rtl92d_phy_powerdown_anotherphy(hw, true);
  2617. }
  2618. RT_TRACE(rtlpriv, COMP_CMD, DBG_LOUD, ("<====\n"));
  2619. }
  2620. static void _rtl92d_phy_lc_calibrate_sw(struct ieee80211_hw *hw, bool is2t)
  2621. {
  2622. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2623. struct rtl_hal *rtlhal = &(rtlpriv->rtlhal);
  2624. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  2625. u8 tmpreg, index, rf_mode[2];
  2626. u8 path = is2t ? 2 : 1;
  2627. u8 i;
  2628. u32 u4tmp, offset;
  2629. u32 curvecount_val[CV_CURVE_CNT * 2] = {0};
  2630. u16 timeout = 800, timecount = 0;
  2631. /* Check continuous TX and Packet TX */
  2632. tmpreg = rtl_read_byte(rtlpriv, 0xd03);
  2633. /* if Deal with contisuous TX case, disable all continuous TX */
  2634. /* if Deal with Packet TX case, block all queues */
  2635. if ((tmpreg & 0x70) != 0)
  2636. rtl_write_byte(rtlpriv, 0xd03, tmpreg & 0x8F);
  2637. else
  2638. rtl_write_byte(rtlpriv, REG_TXPAUSE, 0xFF);
  2639. rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER4, 0xF00000, 0x0F);
  2640. for (index = 0; index < path; index++) {
  2641. /* 1. Read original RF mode */
  2642. offset = index == 0 ? ROFDM0_XAAGCCORE1 : ROFDM0_XBAGCCORE1;
  2643. rf_mode[index] = rtl_read_byte(rtlpriv, offset);
  2644. /* 2. Set RF mode = standby mode */
  2645. rtl_set_rfreg(hw, (enum radio_path)index, RF_AC,
  2646. BRFREGOFFSETMASK, 0x010000);
  2647. if (rtlpci->init_ready) {
  2648. /* switch CV-curve control by LC-calibration */
  2649. rtl_set_rfreg(hw, (enum radio_path)index, RF_SYN_G7,
  2650. BIT(17), 0x0);
  2651. /* 4. Set LC calibration begin */
  2652. rtl_set_rfreg(hw, (enum radio_path)index, RF_CHNLBW,
  2653. 0x08000, 0x01);
  2654. }
  2655. u4tmp = rtl_get_rfreg(hw, (enum radio_path)index, RF_SYN_G6,
  2656. BRFREGOFFSETMASK);
  2657. while ((!(u4tmp & BIT(11))) && timecount <= timeout) {
  2658. mdelay(50);
  2659. timecount += 50;
  2660. u4tmp = rtl_get_rfreg(hw, (enum radio_path)index,
  2661. RF_SYN_G6, BRFREGOFFSETMASK);
  2662. }
  2663. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  2664. ("PHY_LCK finish delay for %d ms=2\n", timecount));
  2665. u4tmp = rtl_get_rfreg(hw, index, RF_SYN_G4, BRFREGOFFSETMASK);
  2666. if (index == 0 && rtlhal->interfaceindex == 0) {
  2667. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  2668. ("path-A / 5G LCK\n"));
  2669. } else {
  2670. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  2671. ("path-B / 2.4G LCK\n"));
  2672. }
  2673. memset(&curvecount_val[0], 0, CV_CURVE_CNT * 2);
  2674. /* Set LC calibration off */
  2675. rtl_set_rfreg(hw, (enum radio_path)index, RF_CHNLBW,
  2676. 0x08000, 0x0);
  2677. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("set RF 0x18[15] = 0\n"));
  2678. /* save Curve-counting number */
  2679. for (i = 0; i < CV_CURVE_CNT; i++) {
  2680. u32 readval = 0, readval2 = 0;
  2681. rtl_set_rfreg(hw, (enum radio_path)index, 0x3F,
  2682. 0x7f, i);
  2683. rtl_set_rfreg(hw, (enum radio_path)index, 0x4D,
  2684. BRFREGOFFSETMASK, 0x0);
  2685. readval = rtl_get_rfreg(hw, (enum radio_path)index,
  2686. 0x4F, BRFREGOFFSETMASK);
  2687. curvecount_val[2 * i + 1] = (readval & 0xfffe0) >> 5;
  2688. /* reg 0x4f [4:0] */
  2689. /* reg 0x50 [19:10] */
  2690. readval2 = rtl_get_rfreg(hw, (enum radio_path)index,
  2691. 0x50, 0xffc00);
  2692. curvecount_val[2 * i] = (((readval & 0x1F) << 10) |
  2693. readval2);
  2694. }
  2695. if (index == 0 && rtlhal->interfaceindex == 0)
  2696. _rtl92d_phy_calc_curvindex(hw, targetchnl_5g,
  2697. curvecount_val,
  2698. true, curveindex_5g);
  2699. else
  2700. _rtl92d_phy_calc_curvindex(hw, targetchnl_2g,
  2701. curvecount_val,
  2702. false, curveindex_2g);
  2703. /* switch CV-curve control mode */
  2704. rtl_set_rfreg(hw, (enum radio_path)index, RF_SYN_G7,
  2705. BIT(17), 0x1);
  2706. }
  2707. /* Restore original situation */
  2708. for (index = 0; index < path; index++) {
  2709. offset = index == 0 ? ROFDM0_XAAGCCORE1 : ROFDM0_XBAGCCORE1;
  2710. rtl_write_byte(rtlpriv, offset, 0x50);
  2711. rtl_write_byte(rtlpriv, offset, rf_mode[index]);
  2712. }
  2713. if ((tmpreg & 0x70) != 0)
  2714. rtl_write_byte(rtlpriv, 0xd03, tmpreg);
  2715. else /*Deal with Packet TX case */
  2716. rtl_write_byte(rtlpriv, REG_TXPAUSE, 0x00);
  2717. rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER4, 0xF00000, 0x00);
  2718. _rtl92d_phy_reload_lck_setting(hw, rtlpriv->phy.current_channel);
  2719. }
  2720. static void _rtl92d_phy_lc_calibrate(struct ieee80211_hw *hw, bool is2t)
  2721. {
  2722. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2723. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("cosa PHY_LCK ver=2\n"));
  2724. _rtl92d_phy_lc_calibrate_sw(hw, is2t);
  2725. }
  2726. void rtl92d_phy_lc_calibrate(struct ieee80211_hw *hw)
  2727. {
  2728. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2729. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  2730. struct rtl_hal *rtlhal = &(rtlpriv->rtlhal);
  2731. u32 timeout = 2000, timecount = 0;
  2732. while (rtlpriv->mac80211.act_scanning && timecount < timeout) {
  2733. udelay(50);
  2734. timecount += 50;
  2735. }
  2736. rtlphy->lck_inprogress = true;
  2737. RTPRINT(rtlpriv, FINIT, INIT_IQK,
  2738. ("LCK:Start!!! currentband %x delay %d ms\n",
  2739. rtlhal->current_bandtype, timecount));
  2740. if (IS_92D_SINGLEPHY(rtlhal->version)) {
  2741. _rtl92d_phy_lc_calibrate(hw, true);
  2742. } else {
  2743. /* For 1T1R */
  2744. _rtl92d_phy_lc_calibrate(hw, false);
  2745. }
  2746. rtlphy->lck_inprogress = false;
  2747. RTPRINT(rtlpriv, FINIT, INIT_IQK, ("LCK:Finish!!!\n"));
  2748. }
  2749. void rtl92d_phy_ap_calibrate(struct ieee80211_hw *hw, char delta)
  2750. {
  2751. return;
  2752. }
  2753. static bool _rtl92d_phy_set_sw_chnl_cmdarray(struct swchnlcmd *cmdtable,
  2754. u32 cmdtableidx, u32 cmdtablesz, enum swchnlcmd_id cmdid,
  2755. u32 para1, u32 para2, u32 msdelay)
  2756. {
  2757. struct swchnlcmd *pcmd;
  2758. if (cmdtable == NULL) {
  2759. RT_ASSERT(false, ("cmdtable cannot be NULL.\n"));
  2760. return false;
  2761. }
  2762. if (cmdtableidx >= cmdtablesz)
  2763. return false;
  2764. pcmd = cmdtable + cmdtableidx;
  2765. pcmd->cmdid = cmdid;
  2766. pcmd->para1 = para1;
  2767. pcmd->para2 = para2;
  2768. pcmd->msdelay = msdelay;
  2769. return true;
  2770. }
  2771. void rtl92d_phy_reset_iqk_result(struct ieee80211_hw *hw)
  2772. {
  2773. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2774. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  2775. u8 i;
  2776. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  2777. ("settings regs %d default regs %d\n",
  2778. (int)(sizeof(rtlphy->iqk_matrix_regsetting) /
  2779. sizeof(struct iqk_matrix_regs)),
  2780. IQK_MATRIX_REG_NUM));
  2781. /* 0xe94, 0xe9c, 0xea4, 0xeac, 0xeb4, 0xebc, 0xec4, 0xecc */
  2782. for (i = 0; i < IQK_MATRIX_SETTINGS_NUM; i++) {
  2783. rtlphy->iqk_matrix_regsetting[i].value[0][0] = 0x100;
  2784. rtlphy->iqk_matrix_regsetting[i].value[0][2] = 0x100;
  2785. rtlphy->iqk_matrix_regsetting[i].value[0][4] = 0x100;
  2786. rtlphy->iqk_matrix_regsetting[i].value[0][6] = 0x100;
  2787. rtlphy->iqk_matrix_regsetting[i].value[0][1] = 0x0;
  2788. rtlphy->iqk_matrix_regsetting[i].value[0][3] = 0x0;
  2789. rtlphy->iqk_matrix_regsetting[i].value[0][5] = 0x0;
  2790. rtlphy->iqk_matrix_regsetting[i].value[0][7] = 0x0;
  2791. rtlphy->iqk_matrix_regsetting[i].iqk_done = false;
  2792. }
  2793. }
  2794. static bool _rtl92d_phy_sw_chnl_step_by_step(struct ieee80211_hw *hw,
  2795. u8 channel, u8 *stage, u8 *step,
  2796. u32 *delay)
  2797. {
  2798. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2799. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  2800. struct swchnlcmd precommoncmd[MAX_PRECMD_CNT];
  2801. u32 precommoncmdcnt;
  2802. struct swchnlcmd postcommoncmd[MAX_POSTCMD_CNT];
  2803. u32 postcommoncmdcnt;
  2804. struct swchnlcmd rfdependcmd[MAX_RFDEPENDCMD_CNT];
  2805. u32 rfdependcmdcnt;
  2806. struct swchnlcmd *currentcmd = NULL;
  2807. u8 rfpath;
  2808. u8 num_total_rfpath = rtlphy->num_total_rfpath;
  2809. precommoncmdcnt = 0;
  2810. _rtl92d_phy_set_sw_chnl_cmdarray(precommoncmd, precommoncmdcnt++,
  2811. MAX_PRECMD_CNT,
  2812. CMDID_SET_TXPOWEROWER_LEVEL, 0, 0, 0);
  2813. _rtl92d_phy_set_sw_chnl_cmdarray(precommoncmd, precommoncmdcnt++,
  2814. MAX_PRECMD_CNT, CMDID_END, 0, 0, 0);
  2815. postcommoncmdcnt = 0;
  2816. _rtl92d_phy_set_sw_chnl_cmdarray(postcommoncmd, postcommoncmdcnt++,
  2817. MAX_POSTCMD_CNT, CMDID_END, 0, 0, 0);
  2818. rfdependcmdcnt = 0;
  2819. _rtl92d_phy_set_sw_chnl_cmdarray(rfdependcmd, rfdependcmdcnt++,
  2820. MAX_RFDEPENDCMD_CNT, CMDID_RF_WRITEREG,
  2821. RF_CHNLBW, channel, 0);
  2822. _rtl92d_phy_set_sw_chnl_cmdarray(rfdependcmd, rfdependcmdcnt++,
  2823. MAX_RFDEPENDCMD_CNT, CMDID_END,
  2824. 0, 0, 0);
  2825. do {
  2826. switch (*stage) {
  2827. case 0:
  2828. currentcmd = &precommoncmd[*step];
  2829. break;
  2830. case 1:
  2831. currentcmd = &rfdependcmd[*step];
  2832. break;
  2833. case 2:
  2834. currentcmd = &postcommoncmd[*step];
  2835. break;
  2836. }
  2837. if (currentcmd->cmdid == CMDID_END) {
  2838. if ((*stage) == 2) {
  2839. return true;
  2840. } else {
  2841. (*stage)++;
  2842. (*step) = 0;
  2843. continue;
  2844. }
  2845. }
  2846. switch (currentcmd->cmdid) {
  2847. case CMDID_SET_TXPOWEROWER_LEVEL:
  2848. rtl92d_phy_set_txpower_level(hw, channel);
  2849. break;
  2850. case CMDID_WRITEPORT_ULONG:
  2851. rtl_write_dword(rtlpriv, currentcmd->para1,
  2852. currentcmd->para2);
  2853. break;
  2854. case CMDID_WRITEPORT_USHORT:
  2855. rtl_write_word(rtlpriv, currentcmd->para1,
  2856. (u16)currentcmd->para2);
  2857. break;
  2858. case CMDID_WRITEPORT_UCHAR:
  2859. rtl_write_byte(rtlpriv, currentcmd->para1,
  2860. (u8)currentcmd->para2);
  2861. break;
  2862. case CMDID_RF_WRITEREG:
  2863. for (rfpath = 0; rfpath < num_total_rfpath; rfpath++) {
  2864. rtlphy->rfreg_chnlval[rfpath] =
  2865. ((rtlphy->rfreg_chnlval[rfpath] &
  2866. 0xffffff00) | currentcmd->para2);
  2867. if (rtlpriv->rtlhal.current_bandtype ==
  2868. BAND_ON_5G) {
  2869. if (currentcmd->para2 > 99)
  2870. rtlphy->rfreg_chnlval[rfpath] =
  2871. rtlphy->rfreg_chnlval
  2872. [rfpath] | (BIT(18));
  2873. else
  2874. rtlphy->rfreg_chnlval[rfpath] =
  2875. rtlphy->rfreg_chnlval
  2876. [rfpath] & (~BIT(18));
  2877. rtlphy->rfreg_chnlval[rfpath] |=
  2878. (BIT(16) | BIT(8));
  2879. } else {
  2880. rtlphy->rfreg_chnlval[rfpath] &=
  2881. ~(BIT(8) | BIT(16) | BIT(18));
  2882. }
  2883. rtl_set_rfreg(hw, (enum radio_path)rfpath,
  2884. currentcmd->para1,
  2885. BRFREGOFFSETMASK,
  2886. rtlphy->rfreg_chnlval[rfpath]);
  2887. _rtl92d_phy_reload_imr_setting(hw, channel,
  2888. rfpath);
  2889. }
  2890. _rtl92d_phy_switch_rf_setting(hw, channel);
  2891. /* do IQK when all parameters are ready */
  2892. rtl92d_phy_reload_iqk_setting(hw, channel);
  2893. break;
  2894. default:
  2895. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  2896. ("switch case not process\n"));
  2897. break;
  2898. }
  2899. break;
  2900. } while (true);
  2901. (*delay) = currentcmd->msdelay;
  2902. (*step)++;
  2903. return false;
  2904. }
  2905. u8 rtl92d_phy_sw_chnl(struct ieee80211_hw *hw)
  2906. {
  2907. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2908. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  2909. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  2910. u32 delay;
  2911. u32 timeout = 1000, timecount = 0;
  2912. u8 channel = rtlphy->current_channel;
  2913. u32 ret_value;
  2914. if (rtlphy->sw_chnl_inprogress)
  2915. return 0;
  2916. if (rtlphy->set_bwmode_inprogress)
  2917. return 0;
  2918. if ((is_hal_stop(rtlhal)) || (RT_CANNOT_IO(hw))) {
  2919. RT_TRACE(rtlpriv, COMP_CHAN, DBG_LOUD,
  2920. ("sw_chnl_inprogress false driver sleep or unload\n"));
  2921. return 0;
  2922. }
  2923. while (rtlphy->lck_inprogress && timecount < timeout) {
  2924. mdelay(50);
  2925. timecount += 50;
  2926. }
  2927. if (rtlhal->macphymode == SINGLEMAC_SINGLEPHY &&
  2928. rtlhal->bandset == BAND_ON_BOTH) {
  2929. ret_value = rtl_get_bbreg(hw, RFPGA0_XAB_RFPARAMETER,
  2930. BMASKDWORD);
  2931. if (rtlphy->current_channel > 14 && !(ret_value & BIT(0)))
  2932. rtl92d_phy_switch_wirelessband(hw, BAND_ON_5G);
  2933. else if (rtlphy->current_channel <= 14 && (ret_value & BIT(0)))
  2934. rtl92d_phy_switch_wirelessband(hw, BAND_ON_2_4G);
  2935. }
  2936. switch (rtlhal->current_bandtype) {
  2937. case BAND_ON_5G:
  2938. /* Get first channel error when change between
  2939. * 5G and 2.4G band. */
  2940. if (channel <= 14)
  2941. return 0;
  2942. RT_ASSERT((channel > 14), ("5G but channel<=14"));
  2943. break;
  2944. case BAND_ON_2_4G:
  2945. /* Get first channel error when change between
  2946. * 5G and 2.4G band. */
  2947. if (channel > 14)
  2948. return 0;
  2949. RT_ASSERT((channel <= 14), ("2G but channel>14"));
  2950. break;
  2951. default:
  2952. RT_ASSERT(false,
  2953. ("Invalid WirelessMode(%#x)!!\n",
  2954. rtlpriv->mac80211.mode));
  2955. break;
  2956. }
  2957. rtlphy->sw_chnl_inprogress = true;
  2958. if (channel == 0)
  2959. channel = 1;
  2960. rtlphy->sw_chnl_stage = 0;
  2961. rtlphy->sw_chnl_step = 0;
  2962. RT_TRACE(rtlpriv, COMP_SCAN, DBG_TRACE,
  2963. ("switch to channel%d\n", rtlphy->current_channel));
  2964. do {
  2965. if (!rtlphy->sw_chnl_inprogress)
  2966. break;
  2967. if (!_rtl92d_phy_sw_chnl_step_by_step(hw,
  2968. rtlphy->current_channel,
  2969. &rtlphy->sw_chnl_stage, &rtlphy->sw_chnl_step, &delay)) {
  2970. if (delay > 0)
  2971. mdelay(delay);
  2972. else
  2973. continue;
  2974. } else {
  2975. rtlphy->sw_chnl_inprogress = false;
  2976. }
  2977. break;
  2978. } while (true);
  2979. RT_TRACE(rtlpriv, COMP_SCAN, DBG_TRACE, ("<==\n"));
  2980. rtlphy->sw_chnl_inprogress = false;
  2981. return 1;
  2982. }
  2983. static void rtl92d_phy_set_io(struct ieee80211_hw *hw)
  2984. {
  2985. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2986. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  2987. RT_TRACE(rtlpriv, COMP_CMD, DBG_TRACE,
  2988. ("--->Cmd(%#x), set_io_inprogress(%d)\n",
  2989. rtlphy->current_io_type, rtlphy->set_io_inprogress));
  2990. switch (rtlphy->current_io_type) {
  2991. case IO_CMD_RESUME_DM_BY_SCAN:
  2992. de_digtable.cur_igvalue = rtlphy->initgain_backup.xaagccore1;
  2993. rtl92d_dm_write_dig(hw);
  2994. rtl92d_phy_set_txpower_level(hw, rtlphy->current_channel);
  2995. break;
  2996. case IO_CMD_PAUSE_DM_BY_SCAN:
  2997. rtlphy->initgain_backup.xaagccore1 = de_digtable.cur_igvalue;
  2998. de_digtable.cur_igvalue = 0x17;
  2999. rtl92d_dm_write_dig(hw);
  3000. break;
  3001. default:
  3002. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  3003. ("switch case not process\n"));
  3004. break;
  3005. }
  3006. rtlphy->set_io_inprogress = false;
  3007. RT_TRACE(rtlpriv, COMP_CMD, DBG_TRACE,
  3008. ("<---(%#x)\n", rtlphy->current_io_type));
  3009. }
  3010. bool rtl92d_phy_set_io_cmd(struct ieee80211_hw *hw, enum io_type iotype)
  3011. {
  3012. struct rtl_priv *rtlpriv = rtl_priv(hw);
  3013. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  3014. bool postprocessing = false;
  3015. RT_TRACE(rtlpriv, COMP_CMD, DBG_TRACE,
  3016. ("-->IO Cmd(%#x), set_io_inprogress(%d)\n",
  3017. iotype, rtlphy->set_io_inprogress));
  3018. do {
  3019. switch (iotype) {
  3020. case IO_CMD_RESUME_DM_BY_SCAN:
  3021. RT_TRACE(rtlpriv, COMP_CMD, DBG_TRACE,
  3022. ("[IO CMD] Resume DM after scan.\n"));
  3023. postprocessing = true;
  3024. break;
  3025. case IO_CMD_PAUSE_DM_BY_SCAN:
  3026. RT_TRACE(rtlpriv, COMP_CMD, DBG_TRACE,
  3027. ("[IO CMD] Pause DM before scan.\n"));
  3028. postprocessing = true;
  3029. break;
  3030. default:
  3031. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  3032. ("switch case not process\n"));
  3033. break;
  3034. }
  3035. } while (false);
  3036. if (postprocessing && !rtlphy->set_io_inprogress) {
  3037. rtlphy->set_io_inprogress = true;
  3038. rtlphy->current_io_type = iotype;
  3039. } else {
  3040. return false;
  3041. }
  3042. rtl92d_phy_set_io(hw);
  3043. RT_TRACE(rtlpriv, COMP_CMD, DBG_TRACE, ("<--IO Type(%#x)\n", iotype));
  3044. return true;
  3045. }
  3046. static void _rtl92d_phy_set_rfon(struct ieee80211_hw *hw)
  3047. {
  3048. struct rtl_priv *rtlpriv = rtl_priv(hw);
  3049. /* a. SYS_CLKR 0x08[11] = 1 restore MAC clock */
  3050. /* b. SPS_CTRL 0x11[7:0] = 0x2b */
  3051. if (rtlpriv->rtlhal.macphymode == SINGLEMAC_SINGLEPHY)
  3052. rtl_write_byte(rtlpriv, REG_SPS0_CTRL, 0x2b);
  3053. /* c. For PCIE: SYS_FUNC_EN 0x02[7:0] = 0xE3 enable BB TRX function */
  3054. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE3);
  3055. /* RF_ON_EXCEP(d~g): */
  3056. /* d. APSD_CTRL 0x600[7:0] = 0x00 */
  3057. rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x00);
  3058. /* e. SYS_FUNC_EN 0x02[7:0] = 0xE2 reset BB TRX function again */
  3059. /* f. SYS_FUNC_EN 0x02[7:0] = 0xE3 enable BB TRX function*/
  3060. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE2);
  3061. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE3);
  3062. /* g. txpause 0x522[7:0] = 0x00 enable mac tx queue */
  3063. rtl_write_byte(rtlpriv, REG_TXPAUSE, 0x00);
  3064. }
  3065. static void _rtl92d_phy_set_rfsleep(struct ieee80211_hw *hw)
  3066. {
  3067. struct rtl_priv *rtlpriv = rtl_priv(hw);
  3068. u32 u4btmp;
  3069. u8 delay = 5;
  3070. /* a. TXPAUSE 0x522[7:0] = 0xFF Pause MAC TX queue */
  3071. rtl_write_byte(rtlpriv, REG_TXPAUSE, 0xFF);
  3072. /* b. RF path 0 offset 0x00 = 0x00 disable RF */
  3073. rtl_set_rfreg(hw, RF90_PATH_A, 0x00, BRFREGOFFSETMASK, 0x00);
  3074. /* c. APSD_CTRL 0x600[7:0] = 0x40 */
  3075. rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x40);
  3076. /* d. APSD_CTRL 0x600[7:0] = 0x00
  3077. * APSD_CTRL 0x600[7:0] = 0x00
  3078. * RF path 0 offset 0x00 = 0x00
  3079. * APSD_CTRL 0x600[7:0] = 0x40
  3080. * */
  3081. u4btmp = rtl_get_rfreg(hw, RF90_PATH_A, 0, BRFREGOFFSETMASK);
  3082. while (u4btmp != 0 && delay > 0) {
  3083. rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x0);
  3084. rtl_set_rfreg(hw, RF90_PATH_A, 0x00, BRFREGOFFSETMASK, 0x00);
  3085. rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x40);
  3086. u4btmp = rtl_get_rfreg(hw, RF90_PATH_A, 0, BRFREGOFFSETMASK);
  3087. delay--;
  3088. }
  3089. if (delay == 0) {
  3090. /* Jump out the LPS turn off sequence to RF_ON_EXCEP */
  3091. rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x00);
  3092. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE2);
  3093. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE3);
  3094. rtl_write_byte(rtlpriv, REG_TXPAUSE, 0x00);
  3095. RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
  3096. ("Fail !!! Switch RF timeout.\n"));
  3097. return;
  3098. }
  3099. /* e. For PCIE: SYS_FUNC_EN 0x02[7:0] = 0xE2 reset BB TRX function */
  3100. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE2);
  3101. /* f. SPS_CTRL 0x11[7:0] = 0x22 */
  3102. if (rtlpriv->rtlhal.macphymode == SINGLEMAC_SINGLEPHY)
  3103. rtl_write_byte(rtlpriv, REG_SPS0_CTRL, 0x22);
  3104. /* g. SYS_CLKR 0x08[11] = 0 gated MAC clock */
  3105. }
  3106. bool rtl92d_phy_set_rf_power_state(struct ieee80211_hw *hw,
  3107. enum rf_pwrstate rfpwr_state)
  3108. {
  3109. bool bresult = true;
  3110. struct rtl_priv *rtlpriv = rtl_priv(hw);
  3111. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  3112. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  3113. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  3114. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  3115. u8 i, queue_id;
  3116. struct rtl8192_tx_ring *ring = NULL;
  3117. if (rfpwr_state == ppsc->rfpwr_state)
  3118. return false;
  3119. switch (rfpwr_state) {
  3120. case ERFON:
  3121. if ((ppsc->rfpwr_state == ERFOFF) &&
  3122. RT_IN_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC)) {
  3123. bool rtstatus;
  3124. u32 InitializeCount = 0;
  3125. do {
  3126. InitializeCount++;
  3127. RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
  3128. ("IPS Set eRf nic enable\n"));
  3129. rtstatus = rtl_ps_enable_nic(hw);
  3130. } while ((rtstatus != true) &&
  3131. (InitializeCount < 10));
  3132. RT_CLEAR_PS_LEVEL(ppsc,
  3133. RT_RF_OFF_LEVL_HALT_NIC);
  3134. } else {
  3135. RT_TRACE(rtlpriv, COMP_POWER, DBG_DMESG,
  3136. ("awake, sleeped:%d ms state_"
  3137. "inap:%x\n",
  3138. jiffies_to_msecs(jiffies -
  3139. ppsc->last_sleep_jiffies),
  3140. rtlpriv->psc.state_inap));
  3141. ppsc->last_awake_jiffies = jiffies;
  3142. _rtl92d_phy_set_rfon(hw);
  3143. }
  3144. if (mac->link_state == MAC80211_LINKED)
  3145. rtlpriv->cfg->ops->led_control(hw,
  3146. LED_CTL_LINK);
  3147. else
  3148. rtlpriv->cfg->ops->led_control(hw,
  3149. LED_CTL_NO_LINK);
  3150. break;
  3151. case ERFOFF:
  3152. if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_HALT_NIC) {
  3153. RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
  3154. ("IPS Set eRf nic disable\n"));
  3155. rtl_ps_disable_nic(hw);
  3156. RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC);
  3157. } else {
  3158. if (ppsc->rfoff_reason == RF_CHANGE_BY_IPS)
  3159. rtlpriv->cfg->ops->led_control(hw,
  3160. LED_CTL_NO_LINK);
  3161. else
  3162. rtlpriv->cfg->ops->led_control(hw,
  3163. LED_CTL_POWER_OFF);
  3164. }
  3165. break;
  3166. case ERFSLEEP:
  3167. if (ppsc->rfpwr_state == ERFOFF)
  3168. break;
  3169. for (queue_id = 0, i = 0;
  3170. queue_id < RTL_PCI_MAX_TX_QUEUE_COUNT;) {
  3171. ring = &pcipriv->dev.tx_ring[queue_id];
  3172. if (skb_queue_len(&ring->queue) == 0 ||
  3173. queue_id == BEACON_QUEUE) {
  3174. queue_id++;
  3175. continue;
  3176. } else if (rtlpci->pdev->current_state != PCI_D0) {
  3177. RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
  3178. ("eRf Off/Sleep: %d times TcbBusyQueu"
  3179. "e[%d] !=0 but lower power state!\n",
  3180. (i + 1), queue_id));
  3181. break;
  3182. } else {
  3183. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  3184. ("eRf Off/Sleep: %d times TcbBusyQueu"
  3185. "e[%d] =%d "
  3186. "before doze!\n", (i + 1), queue_id,
  3187. skb_queue_len(&ring->queue)));
  3188. udelay(10);
  3189. i++;
  3190. }
  3191. if (i >= MAX_DOZE_WAITING_TIMES_9x) {
  3192. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  3193. ("\nERFOFF: %d times TcbBusyQueue[%d] "
  3194. "= %d !\n",
  3195. MAX_DOZE_WAITING_TIMES_9x, queue_id,
  3196. skb_queue_len(&ring->queue)));
  3197. break;
  3198. }
  3199. }
  3200. RT_TRACE(rtlpriv, COMP_POWER, DBG_DMESG,
  3201. ("Set rfsleep awaked:%d ms\n",
  3202. jiffies_to_msecs(jiffies - ppsc->last_awake_jiffies)));
  3203. RT_TRACE(rtlpriv, COMP_POWER, DBG_DMESG, ("sleep awaked:%d ms "
  3204. "state_inap:%x\n", jiffies_to_msecs(jiffies -
  3205. ppsc->last_awake_jiffies), rtlpriv->psc.state_inap));
  3206. ppsc->last_sleep_jiffies = jiffies;
  3207. _rtl92d_phy_set_rfsleep(hw);
  3208. break;
  3209. default:
  3210. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  3211. ("switch case not process\n"));
  3212. bresult = false;
  3213. break;
  3214. }
  3215. if (bresult)
  3216. ppsc->rfpwr_state = rfpwr_state;
  3217. return bresult;
  3218. }
  3219. void rtl92d_phy_config_macphymode(struct ieee80211_hw *hw)
  3220. {
  3221. struct rtl_priv *rtlpriv = rtl_priv(hw);
  3222. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  3223. u8 offset = REG_MAC_PHY_CTRL_NORMAL;
  3224. switch (rtlhal->macphymode) {
  3225. case DUALMAC_DUALPHY:
  3226. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  3227. ("MacPhyMode: DUALMAC_DUALPHY\n"));
  3228. rtl_write_byte(rtlpriv, offset, 0xF3);
  3229. break;
  3230. case SINGLEMAC_SINGLEPHY:
  3231. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  3232. ("MacPhyMode: SINGLEMAC_SINGLEPHY\n"));
  3233. rtl_write_byte(rtlpriv, offset, 0xF4);
  3234. break;
  3235. case DUALMAC_SINGLEPHY:
  3236. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  3237. ("MacPhyMode: DUALMAC_SINGLEPHY\n"));
  3238. rtl_write_byte(rtlpriv, offset, 0xF1);
  3239. break;
  3240. }
  3241. }
  3242. void rtl92d_phy_config_macphymode_info(struct ieee80211_hw *hw)
  3243. {
  3244. struct rtl_priv *rtlpriv = rtl_priv(hw);
  3245. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  3246. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  3247. switch (rtlhal->macphymode) {
  3248. case DUALMAC_SINGLEPHY:
  3249. rtlphy->rf_type = RF_2T2R;
  3250. rtlhal->version |= CHIP_92D_SINGLEPHY;
  3251. rtlhal->bandset = BAND_ON_BOTH;
  3252. rtlhal->current_bandtype = BAND_ON_2_4G;
  3253. break;
  3254. case SINGLEMAC_SINGLEPHY:
  3255. rtlphy->rf_type = RF_2T2R;
  3256. rtlhal->version |= CHIP_92D_SINGLEPHY;
  3257. rtlhal->bandset = BAND_ON_BOTH;
  3258. rtlhal->current_bandtype = BAND_ON_2_4G;
  3259. break;
  3260. case DUALMAC_DUALPHY:
  3261. rtlphy->rf_type = RF_1T1R;
  3262. rtlhal->version &= (~CHIP_92D_SINGLEPHY);
  3263. /* Now we let MAC0 run on 5G band. */
  3264. if (rtlhal->interfaceindex == 0) {
  3265. rtlhal->bandset = BAND_ON_5G;
  3266. rtlhal->current_bandtype = BAND_ON_5G;
  3267. } else {
  3268. rtlhal->bandset = BAND_ON_2_4G;
  3269. rtlhal->current_bandtype = BAND_ON_2_4G;
  3270. }
  3271. break;
  3272. default:
  3273. break;
  3274. }
  3275. }
  3276. u8 rtl92d_get_chnlgroup_fromarray(u8 chnl)
  3277. {
  3278. u8 group;
  3279. u8 channel_info[59] = {
  3280. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  3281. 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56,
  3282. 58, 60, 62, 64, 100, 102, 104, 106, 108,
  3283. 110, 112, 114, 116, 118, 120, 122, 124,
  3284. 126, 128, 130, 132, 134, 136, 138, 140,
  3285. 149, 151, 153, 155, 157, 159, 161, 163,
  3286. 165
  3287. };
  3288. if (channel_info[chnl] <= 3)
  3289. group = 0;
  3290. else if (channel_info[chnl] <= 9)
  3291. group = 1;
  3292. else if (channel_info[chnl] <= 14)
  3293. group = 2;
  3294. else if (channel_info[chnl] <= 44)
  3295. group = 3;
  3296. else if (channel_info[chnl] <= 54)
  3297. group = 4;
  3298. else if (channel_info[chnl] <= 64)
  3299. group = 5;
  3300. else if (channel_info[chnl] <= 112)
  3301. group = 6;
  3302. else if (channel_info[chnl] <= 126)
  3303. group = 7;
  3304. else if (channel_info[chnl] <= 140)
  3305. group = 8;
  3306. else if (channel_info[chnl] <= 153)
  3307. group = 9;
  3308. else if (channel_info[chnl] <= 159)
  3309. group = 10;
  3310. else
  3311. group = 11;
  3312. return group;
  3313. }
  3314. void rtl92d_phy_set_poweron(struct ieee80211_hw *hw)
  3315. {
  3316. struct rtl_priv *rtlpriv = rtl_priv(hw);
  3317. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  3318. unsigned long flags;
  3319. u8 value8;
  3320. u16 i;
  3321. u32 mac_reg = (rtlhal->interfaceindex == 0 ? REG_MAC0 : REG_MAC1);
  3322. /* notice fw know band status 0x81[1]/0x53[1] = 0: 5G, 1: 2G */
  3323. if (rtlhal->current_bandtype == BAND_ON_2_4G) {
  3324. value8 = rtl_read_byte(rtlpriv, mac_reg);
  3325. value8 |= BIT(1);
  3326. rtl_write_byte(rtlpriv, mac_reg, value8);
  3327. } else {
  3328. value8 = rtl_read_byte(rtlpriv, mac_reg);
  3329. value8 &= (~BIT(1));
  3330. rtl_write_byte(rtlpriv, mac_reg, value8);
  3331. }
  3332. if (rtlhal->macphymode == SINGLEMAC_SINGLEPHY) {
  3333. value8 = rtl_read_byte(rtlpriv, REG_MAC0);
  3334. rtl_write_byte(rtlpriv, REG_MAC0, value8 | MAC0_ON);
  3335. } else {
  3336. spin_lock_irqsave(&globalmutex_power, flags);
  3337. if (rtlhal->interfaceindex == 0) {
  3338. value8 = rtl_read_byte(rtlpriv, REG_MAC0);
  3339. rtl_write_byte(rtlpriv, REG_MAC0, value8 | MAC0_ON);
  3340. } else {
  3341. value8 = rtl_read_byte(rtlpriv, REG_MAC1);
  3342. rtl_write_byte(rtlpriv, REG_MAC1, value8 | MAC1_ON);
  3343. }
  3344. value8 = rtl_read_byte(rtlpriv, REG_POWER_OFF_IN_PROCESS);
  3345. spin_unlock_irqrestore(&globalmutex_power, flags);
  3346. for (i = 0; i < 200; i++) {
  3347. if ((value8 & BIT(7)) == 0) {
  3348. break;
  3349. } else {
  3350. udelay(500);
  3351. spin_lock_irqsave(&globalmutex_power, flags);
  3352. value8 = rtl_read_byte(rtlpriv,
  3353. REG_POWER_OFF_IN_PROCESS);
  3354. spin_unlock_irqrestore(&globalmutex_power,
  3355. flags);
  3356. }
  3357. }
  3358. if (i == 200)
  3359. RT_ASSERT(false, ("Another mac power off over time\n"));
  3360. }
  3361. }
  3362. void rtl92d_phy_config_maccoexist_rfpage(struct ieee80211_hw *hw)
  3363. {
  3364. struct rtl_priv *rtlpriv = rtl_priv(hw);
  3365. switch (rtlpriv->rtlhal.macphymode) {
  3366. case DUALMAC_DUALPHY:
  3367. rtl_write_byte(rtlpriv, REG_DMC, 0x0);
  3368. rtl_write_byte(rtlpriv, REG_RX_PKT_LIMIT, 0x08);
  3369. rtl_write_word(rtlpriv, REG_TRXFF_BNDY + 2, 0x13ff);
  3370. break;
  3371. case DUALMAC_SINGLEPHY:
  3372. rtl_write_byte(rtlpriv, REG_DMC, 0xf8);
  3373. rtl_write_byte(rtlpriv, REG_RX_PKT_LIMIT, 0x08);
  3374. rtl_write_word(rtlpriv, REG_TRXFF_BNDY + 2, 0x13ff);
  3375. break;
  3376. case SINGLEMAC_SINGLEPHY:
  3377. rtl_write_byte(rtlpriv, REG_DMC, 0x0);
  3378. rtl_write_byte(rtlpriv, REG_RX_PKT_LIMIT, 0x10);
  3379. rtl_write_word(rtlpriv, (REG_TRXFF_BNDY + 2), 0x27FF);
  3380. break;
  3381. default:
  3382. break;
  3383. }
  3384. }
  3385. void rtl92d_update_bbrf_configuration(struct ieee80211_hw *hw)
  3386. {
  3387. struct rtl_priv *rtlpriv = rtl_priv(hw);
  3388. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  3389. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  3390. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  3391. u8 rfpath, i;
  3392. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, ("==>\n"));
  3393. /* r_select_5G for path_A/B 0 for 2.4G, 1 for 5G */
  3394. if (rtlhal->current_bandtype == BAND_ON_2_4G) {
  3395. /* r_select_5G for path_A/B,0x878 */
  3396. rtl_set_bbreg(hw, RFPGA0_XAB_RFPARAMETER, BIT(0), 0x0);
  3397. rtl_set_bbreg(hw, RFPGA0_XAB_RFPARAMETER, BIT(15), 0x0);
  3398. if (rtlhal->macphymode != DUALMAC_DUALPHY) {
  3399. rtl_set_bbreg(hw, RFPGA0_XAB_RFPARAMETER, BIT(16), 0x0);
  3400. rtl_set_bbreg(hw, RFPGA0_XAB_RFPARAMETER, BIT(31), 0x0);
  3401. }
  3402. /* rssi_table_select:index 0 for 2.4G.1~3 for 5G,0xc78 */
  3403. rtl_set_bbreg(hw, ROFDM0_AGCRSSITABLE, BIT(6) | BIT(7), 0x0);
  3404. /* fc_area 0xd2c */
  3405. rtl_set_bbreg(hw, ROFDM1_CFOTRACKING, BIT(14) | BIT(13), 0x0);
  3406. /* 5G LAN ON */
  3407. rtl_set_bbreg(hw, 0xB30, 0x00F00000, 0xa);
  3408. /* TX BB gain shift*1,Just for testchip,0xc80,0xc88 */
  3409. rtl_set_bbreg(hw, ROFDM0_XATxIQIMBALANCE, BMASKDWORD,
  3410. 0x40000100);
  3411. rtl_set_bbreg(hw, ROFDM0_XBTxIQIMBALANCE, BMASKDWORD,
  3412. 0x40000100);
  3413. if (rtlhal->macphymode == DUALMAC_DUALPHY) {
  3414. rtl_set_bbreg(hw, RFPGA0_XAB_RFINTERFACESW,
  3415. BIT(10) | BIT(6) | BIT(5),
  3416. ((rtlefuse->eeprom_c9 & BIT(3)) >> 3) |
  3417. (rtlefuse->eeprom_c9 & BIT(1)) |
  3418. ((rtlefuse->eeprom_cc & BIT(1)) << 4));
  3419. rtl_set_bbreg(hw, RFPGA0_XA_RFINTERFACEOE,
  3420. BIT(10) | BIT(6) | BIT(5),
  3421. ((rtlefuse->eeprom_c9 & BIT(2)) >> 2) |
  3422. ((rtlefuse->eeprom_c9 & BIT(0)) << 1) |
  3423. ((rtlefuse->eeprom_cc & BIT(0)) << 5));
  3424. rtl_set_bbreg(hw, RFPGA0_XAB_RFPARAMETER, BIT(15), 0);
  3425. } else {
  3426. rtl_set_bbreg(hw, RFPGA0_XAB_RFINTERFACESW,
  3427. BIT(26) | BIT(22) | BIT(21) | BIT(10) |
  3428. BIT(6) | BIT(5),
  3429. ((rtlefuse->eeprom_c9 & BIT(3)) >> 3) |
  3430. (rtlefuse->eeprom_c9 & BIT(1)) |
  3431. ((rtlefuse->eeprom_cc & BIT(1)) << 4) |
  3432. ((rtlefuse->eeprom_c9 & BIT(7)) << 9) |
  3433. ((rtlefuse->eeprom_c9 & BIT(5)) << 12) |
  3434. ((rtlefuse->eeprom_cc & BIT(3)) << 18));
  3435. rtl_set_bbreg(hw, RFPGA0_XA_RFINTERFACEOE,
  3436. BIT(10) | BIT(6) | BIT(5),
  3437. ((rtlefuse->eeprom_c9 & BIT(2)) >> 2) |
  3438. ((rtlefuse->eeprom_c9 & BIT(0)) << 1) |
  3439. ((rtlefuse->eeprom_cc & BIT(0)) << 5));
  3440. rtl_set_bbreg(hw, RFPGA0_XB_RFINTERFACEOE,
  3441. BIT(10) | BIT(6) | BIT(5),
  3442. ((rtlefuse->eeprom_c9 & BIT(6)) >> 6) |
  3443. ((rtlefuse->eeprom_c9 & BIT(4)) >> 3) |
  3444. ((rtlefuse->eeprom_cc & BIT(2)) << 3));
  3445. rtl_set_bbreg(hw, RFPGA0_XAB_RFPARAMETER,
  3446. BIT(31) | BIT(15), 0);
  3447. }
  3448. /* 1.5V_LDO */
  3449. } else {
  3450. /* r_select_5G for path_A/B */
  3451. rtl_set_bbreg(hw, RFPGA0_XAB_RFPARAMETER, BIT(0), 0x1);
  3452. rtl_set_bbreg(hw, RFPGA0_XAB_RFPARAMETER, BIT(15), 0x1);
  3453. if (rtlhal->macphymode != DUALMAC_DUALPHY) {
  3454. rtl_set_bbreg(hw, RFPGA0_XAB_RFPARAMETER, BIT(16), 0x1);
  3455. rtl_set_bbreg(hw, RFPGA0_XAB_RFPARAMETER, BIT(31), 0x1);
  3456. }
  3457. /* rssi_table_select:index 0 for 2.4G.1~3 for 5G */
  3458. rtl_set_bbreg(hw, ROFDM0_AGCRSSITABLE, BIT(6) | BIT(7), 0x1);
  3459. /* fc_area */
  3460. rtl_set_bbreg(hw, ROFDM1_CFOTRACKING, BIT(14) | BIT(13), 0x1);
  3461. /* 5G LAN ON */
  3462. rtl_set_bbreg(hw, 0xB30, 0x00F00000, 0x0);
  3463. /* TX BB gain shift,Just for testchip,0xc80,0xc88 */
  3464. if (rtlefuse->internal_pa_5g[0])
  3465. rtl_set_bbreg(hw, ROFDM0_XATxIQIMBALANCE, BMASKDWORD,
  3466. 0x2d4000b5);
  3467. else
  3468. rtl_set_bbreg(hw, ROFDM0_XATxIQIMBALANCE, BMASKDWORD,
  3469. 0x20000080);
  3470. if (rtlefuse->internal_pa_5g[1])
  3471. rtl_set_bbreg(hw, ROFDM0_XBTxIQIMBALANCE, BMASKDWORD,
  3472. 0x2d4000b5);
  3473. else
  3474. rtl_set_bbreg(hw, ROFDM0_XBTxIQIMBALANCE, BMASKDWORD,
  3475. 0x20000080);
  3476. if (rtlhal->macphymode == DUALMAC_DUALPHY) {
  3477. rtl_set_bbreg(hw, RFPGA0_XAB_RFINTERFACESW,
  3478. BIT(10) | BIT(6) | BIT(5),
  3479. (rtlefuse->eeprom_cc & BIT(5)));
  3480. rtl_set_bbreg(hw, RFPGA0_XA_RFINTERFACEOE, BIT(10),
  3481. ((rtlefuse->eeprom_cc & BIT(4)) >> 4));
  3482. rtl_set_bbreg(hw, RFPGA0_XAB_RFPARAMETER, BIT(15),
  3483. (rtlefuse->eeprom_cc & BIT(4)) >> 4);
  3484. } else {
  3485. rtl_set_bbreg(hw, RFPGA0_XAB_RFINTERFACESW,
  3486. BIT(26) | BIT(22) | BIT(21) | BIT(10) |
  3487. BIT(6) | BIT(5),
  3488. (rtlefuse->eeprom_cc & BIT(5)) |
  3489. ((rtlefuse->eeprom_cc & BIT(7)) << 14));
  3490. rtl_set_bbreg(hw, RFPGA0_XA_RFINTERFACEOE, BIT(10),
  3491. ((rtlefuse->eeprom_cc & BIT(4)) >> 4));
  3492. rtl_set_bbreg(hw, RFPGA0_XB_RFINTERFACEOE, BIT(10),
  3493. ((rtlefuse->eeprom_cc & BIT(6)) >> 6));
  3494. rtl_set_bbreg(hw, RFPGA0_XAB_RFPARAMETER,
  3495. BIT(31) | BIT(15),
  3496. ((rtlefuse->eeprom_cc & BIT(4)) >> 4) |
  3497. ((rtlefuse->eeprom_cc & BIT(6)) << 10));
  3498. }
  3499. }
  3500. /* update IQK related settings */
  3501. rtl_set_bbreg(hw, ROFDM0_XARXIQIMBALANCE, BMASKDWORD, 0x40000100);
  3502. rtl_set_bbreg(hw, ROFDM0_XBRXIQIMBALANCE, BMASKDWORD, 0x40000100);
  3503. rtl_set_bbreg(hw, ROFDM0_XCTxAFE, 0xF0000000, 0x00);
  3504. rtl_set_bbreg(hw, ROFDM0_ECCATHRESHOLD, BIT(30) | BIT(28) |
  3505. BIT(26) | BIT(24), 0x00);
  3506. rtl_set_bbreg(hw, ROFDM0_XDTxAFE, 0xF0000000, 0x00);
  3507. rtl_set_bbreg(hw, 0xca0, 0xF0000000, 0x00);
  3508. rtl_set_bbreg(hw, ROFDM0_AGCRSSITABLE, 0x0000F000, 0x00);
  3509. /* Update RF */
  3510. for (rfpath = RF90_PATH_A; rfpath < rtlphy->num_total_rfpath;
  3511. rfpath++) {
  3512. if (rtlhal->current_bandtype == BAND_ON_2_4G) {
  3513. /* MOD_AG for RF paht_A 0x18 BIT8,BIT16 */
  3514. rtl_set_rfreg(hw, rfpath, RF_CHNLBW, BIT(8) | BIT(16) |
  3515. BIT(18), 0);
  3516. /* RF0x0b[16:14] =3b'111 */
  3517. rtl_set_rfreg(hw, (enum radio_path)rfpath, 0x0B,
  3518. 0x1c000, 0x07);
  3519. } else {
  3520. /* MOD_AG for RF paht_A 0x18 BIT8,BIT16 */
  3521. rtl_set_rfreg(hw, rfpath, RF_CHNLBW, BIT(8) |
  3522. BIT(16) | BIT(18),
  3523. (BIT(16) | BIT(8)) >> 8);
  3524. }
  3525. }
  3526. /* Update for all band. */
  3527. /* DMDP */
  3528. if (rtlphy->rf_type == RF_1T1R) {
  3529. /* Use antenna 0,0xc04,0xd04 */
  3530. rtl_set_bbreg(hw, ROFDM0_TRXPATHENABLE, BMASKBYTE0, 0x11);
  3531. rtl_set_bbreg(hw, ROFDM1_TRXPATHENABLE, BDWORD, 0x1);
  3532. /* enable ad/da clock1 for dual-phy reg0x888 */
  3533. if (rtlhal->interfaceindex == 0) {
  3534. rtl_set_bbreg(hw, RFPGA0_ADDALLOCKEN, BIT(12) |
  3535. BIT(13), 0x3);
  3536. } else {
  3537. rtl92d_phy_enable_anotherphy(hw, false);
  3538. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  3539. ("MAC1 use DBI to update 0x888"));
  3540. /* 0x888 */
  3541. rtl92de_write_dword_dbi(hw, RFPGA0_ADDALLOCKEN,
  3542. rtl92de_read_dword_dbi(hw,
  3543. RFPGA0_ADDALLOCKEN,
  3544. BIT(3)) | BIT(12) | BIT(13),
  3545. BIT(3));
  3546. rtl92d_phy_powerdown_anotherphy(hw, false);
  3547. }
  3548. } else {
  3549. /* Single PHY */
  3550. /* Use antenna 0 & 1,0xc04,0xd04 */
  3551. rtl_set_bbreg(hw, ROFDM0_TRXPATHENABLE, BMASKBYTE0, 0x33);
  3552. rtl_set_bbreg(hw, ROFDM1_TRXPATHENABLE, BDWORD, 0x3);
  3553. /* disable ad/da clock1,0x888 */
  3554. rtl_set_bbreg(hw, RFPGA0_ADDALLOCKEN, BIT(12) | BIT(13), 0);
  3555. }
  3556. for (rfpath = RF90_PATH_A; rfpath < rtlphy->num_total_rfpath;
  3557. rfpath++) {
  3558. rtlphy->rfreg_chnlval[rfpath] = rtl_get_rfreg(hw, rfpath,
  3559. RF_CHNLBW, BRFREGOFFSETMASK);
  3560. rtlphy->reg_rf3c[rfpath] = rtl_get_rfreg(hw, rfpath, 0x3C,
  3561. BRFREGOFFSETMASK);
  3562. }
  3563. for (i = 0; i < 2; i++)
  3564. RT_TRACE(rtlpriv, COMP_RF, DBG_LOUD, ("RF 0x18 = 0x%x\n",
  3565. rtlphy->rfreg_chnlval[i]));
  3566. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, ("<==\n"));
  3567. }
  3568. bool rtl92d_phy_check_poweroff(struct ieee80211_hw *hw)
  3569. {
  3570. struct rtl_priv *rtlpriv = rtl_priv(hw);
  3571. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  3572. u8 u1btmp;
  3573. unsigned long flags;
  3574. if (rtlhal->macphymode == SINGLEMAC_SINGLEPHY) {
  3575. u1btmp = rtl_read_byte(rtlpriv, REG_MAC0);
  3576. rtl_write_byte(rtlpriv, REG_MAC0, u1btmp & (~MAC0_ON));
  3577. return true;
  3578. }
  3579. spin_lock_irqsave(&globalmutex_power, flags);
  3580. if (rtlhal->interfaceindex == 0) {
  3581. u1btmp = rtl_read_byte(rtlpriv, REG_MAC0);
  3582. rtl_write_byte(rtlpriv, REG_MAC0, u1btmp & (~MAC0_ON));
  3583. u1btmp = rtl_read_byte(rtlpriv, REG_MAC1);
  3584. u1btmp &= MAC1_ON;
  3585. } else {
  3586. u1btmp = rtl_read_byte(rtlpriv, REG_MAC1);
  3587. rtl_write_byte(rtlpriv, REG_MAC1, u1btmp & (~MAC1_ON));
  3588. u1btmp = rtl_read_byte(rtlpriv, REG_MAC0);
  3589. u1btmp &= MAC0_ON;
  3590. }
  3591. if (u1btmp) {
  3592. spin_unlock_irqrestore(&globalmutex_power, flags);
  3593. return false;
  3594. }
  3595. u1btmp = rtl_read_byte(rtlpriv, REG_POWER_OFF_IN_PROCESS);
  3596. u1btmp |= BIT(7);
  3597. rtl_write_byte(rtlpriv, REG_POWER_OFF_IN_PROCESS, u1btmp);
  3598. spin_unlock_irqrestore(&globalmutex_power, flags);
  3599. return true;
  3600. }