phy.c 124 KB

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