phy.c 123 KB

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