phy_lcn.c 126 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154
  1. /*
  2. * Copyright (c) 2010 Broadcom Corporation
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  11. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  13. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/delay.h>
  18. #include <linux/cordic.h>
  19. #include <pmu.h>
  20. #include <d11.h>
  21. #include <phy_shim.h>
  22. #include "phy_qmath.h"
  23. #include "phy_hal.h"
  24. #include "phy_radio.h"
  25. #include "phytbl_lcn.h"
  26. #include "phy_lcn.h"
  27. #define PLL_2064_NDIV 90
  28. #define PLL_2064_LOW_END_VCO 3000
  29. #define PLL_2064_LOW_END_KVCO 27
  30. #define PLL_2064_HIGH_END_VCO 4200
  31. #define PLL_2064_HIGH_END_KVCO 68
  32. #define PLL_2064_LOOP_BW_DOUBLER 200
  33. #define PLL_2064_D30_DOUBLER 10500
  34. #define PLL_2064_LOOP_BW 260
  35. #define PLL_2064_D30 8000
  36. #define PLL_2064_CAL_REF_TO 8
  37. #define PLL_2064_MHZ 1000000
  38. #define PLL_2064_OPEN_LOOP_DELAY 5
  39. #define TEMPSENSE 1
  40. #define VBATSENSE 2
  41. #define NOISE_IF_UPD_CHK_INTERVAL 1
  42. #define NOISE_IF_UPD_RST_INTERVAL 60
  43. #define NOISE_IF_UPD_THRESHOLD_CNT 1
  44. #define NOISE_IF_UPD_TRHRESHOLD 50
  45. #define NOISE_IF_UPD_TIMEOUT 1000
  46. #define NOISE_IF_OFF 0
  47. #define NOISE_IF_CHK 1
  48. #define NOISE_IF_ON 2
  49. #define PAPD_BLANKING_PROFILE 3
  50. #define PAPD2LUT 0
  51. #define PAPD_CORR_NORM 0
  52. #define PAPD_BLANKING_THRESHOLD 0
  53. #define PAPD_STOP_AFTER_LAST_UPDATE 0
  54. #define LCN_TARGET_PWR 60
  55. #define LCN_VBAT_OFFSET_433X 34649679
  56. #define LCN_VBAT_SLOPE_433X 8258032
  57. #define LCN_VBAT_SCALE_NOM 53
  58. #define LCN_VBAT_SCALE_DEN 432
  59. #define LCN_TEMPSENSE_OFFSET 80812
  60. #define LCN_TEMPSENSE_DEN 2647
  61. #define LCN_BW_LMT 200
  62. #define LCN_CUR_LMT 1250
  63. #define LCN_MULT 1
  64. #define LCN_VCO_DIV 30
  65. #define LCN_OFFSET 680
  66. #define LCN_FACT 490
  67. #define LCN_CUR_DIV 2640
  68. #define LCNPHY_txgainctrlovrval1_pagain_ovr_val1_SHIFT \
  69. (0 + 8)
  70. #define LCNPHY_txgainctrlovrval1_pagain_ovr_val1_MASK \
  71. (0x7f << LCNPHY_txgainctrlovrval1_pagain_ovr_val1_SHIFT)
  72. #define LCNPHY_stxtxgainctrlovrval1_pagain_ovr_val1_SHIFT \
  73. (0 + 8)
  74. #define LCNPHY_stxtxgainctrlovrval1_pagain_ovr_val1_MASK \
  75. (0x7f << LCNPHY_stxtxgainctrlovrval1_pagain_ovr_val1_SHIFT)
  76. #define wlc_lcnphy_enable_tx_gain_override(pi) \
  77. wlc_lcnphy_set_tx_gain_override(pi, true)
  78. #define wlc_lcnphy_disable_tx_gain_override(pi) \
  79. wlc_lcnphy_set_tx_gain_override(pi, false)
  80. #define wlc_lcnphy_iqcal_active(pi) \
  81. (read_phy_reg((pi), 0x451) & \
  82. ((0x1 << 15) | (0x1 << 14)))
  83. #define txpwrctrl_off(pi) (0x7 != ((read_phy_reg(pi, 0x4a4) & 0xE000) >> 13))
  84. #define wlc_lcnphy_tempsense_based_pwr_ctrl_enabled(pi) \
  85. (pi->temppwrctrl_capable)
  86. #define wlc_lcnphy_tssi_based_pwr_ctrl_enabled(pi) \
  87. (pi->hwpwrctrl_capable)
  88. #define SWCTRL_BT_TX 0x18
  89. #define SWCTRL_OVR_DISABLE 0x40
  90. #define AFE_CLK_INIT_MODE_TXRX2X 1
  91. #define AFE_CLK_INIT_MODE_PAPD 0
  92. #define LCNPHY_TBL_ID_IQLOCAL 0x00
  93. #define LCNPHY_TBL_ID_RFSEQ 0x08
  94. #define LCNPHY_TBL_ID_GAIN_IDX 0x0d
  95. #define LCNPHY_TBL_ID_SW_CTRL 0x0f
  96. #define LCNPHY_TBL_ID_GAIN_TBL 0x12
  97. #define LCNPHY_TBL_ID_SPUR 0x14
  98. #define LCNPHY_TBL_ID_SAMPLEPLAY 0x15
  99. #define LCNPHY_TBL_ID_SAMPLEPLAY1 0x16
  100. #define LCNPHY_TX_PWR_CTRL_RATE_OFFSET 832
  101. #define LCNPHY_TX_PWR_CTRL_MAC_OFFSET 128
  102. #define LCNPHY_TX_PWR_CTRL_GAIN_OFFSET 192
  103. #define LCNPHY_TX_PWR_CTRL_IQ_OFFSET 320
  104. #define LCNPHY_TX_PWR_CTRL_LO_OFFSET 448
  105. #define LCNPHY_TX_PWR_CTRL_PWR_OFFSET 576
  106. #define LCNPHY_TX_PWR_CTRL_START_INDEX_2G_4313 140
  107. #define LCNPHY_TX_PWR_CTRL_START_NPT 1
  108. #define LCNPHY_TX_PWR_CTRL_MAX_NPT 7
  109. #define LCNPHY_NOISE_SAMPLES_DEFAULT 5000
  110. #define LCNPHY_ACI_DETECT_START 1
  111. #define LCNPHY_ACI_DETECT_PROGRESS 2
  112. #define LCNPHY_ACI_DETECT_STOP 3
  113. #define LCNPHY_ACI_CRSHIFRMLO_TRSH 100
  114. #define LCNPHY_ACI_GLITCH_TRSH 2000
  115. #define LCNPHY_ACI_TMOUT 250
  116. #define LCNPHY_ACI_DETECT_TIMEOUT 2
  117. #define LCNPHY_ACI_START_DELAY 0
  118. #define wlc_lcnphy_tx_gain_override_enabled(pi) \
  119. (0 != (read_phy_reg((pi), 0x43b) & (0x1 << 6)))
  120. #define wlc_lcnphy_total_tx_frames(pi) \
  121. wlapi_bmac_read_shm((pi)->sh->physhim, M_UCODE_MACSTAT + \
  122. offsetof(struct macstat, txallfrm))
  123. struct lcnphy_txgains {
  124. u16 gm_gain;
  125. u16 pga_gain;
  126. u16 pad_gain;
  127. u16 dac_gain;
  128. };
  129. enum lcnphy_cal_mode {
  130. LCNPHY_CAL_FULL,
  131. LCNPHY_CAL_RECAL,
  132. LCNPHY_CAL_CURRECAL,
  133. LCNPHY_CAL_DIGCAL,
  134. LCNPHY_CAL_GCTRL
  135. };
  136. struct lcnphy_rx_iqcomp {
  137. u8 chan;
  138. s16 a;
  139. s16 b;
  140. };
  141. struct lcnphy_spb_tone {
  142. s16 re;
  143. s16 im;
  144. };
  145. struct lcnphy_unsign16_struct {
  146. u16 re;
  147. u16 im;
  148. };
  149. struct lcnphy_iq_est {
  150. u32 iq_prod;
  151. u32 i_pwr;
  152. u32 q_pwr;
  153. };
  154. struct lcnphy_sfo_cfg {
  155. u16 ptcentreTs20;
  156. u16 ptcentreFactor;
  157. };
  158. enum lcnphy_papd_cal_type {
  159. LCNPHY_PAPD_CAL_CW,
  160. LCNPHY_PAPD_CAL_OFDM
  161. };
  162. typedef u16 iqcal_gain_params_lcnphy[9];
  163. static const iqcal_gain_params_lcnphy tbl_iqcal_gainparams_lcnphy_2G[] = {
  164. {0, 0, 0, 0, 0, 0, 0, 0, 0},
  165. };
  166. static const iqcal_gain_params_lcnphy *tbl_iqcal_gainparams_lcnphy[1] = {
  167. tbl_iqcal_gainparams_lcnphy_2G,
  168. };
  169. static const u16 iqcal_gainparams_numgains_lcnphy[1] = {
  170. sizeof(tbl_iqcal_gainparams_lcnphy_2G) /
  171. sizeof(*tbl_iqcal_gainparams_lcnphy_2G),
  172. };
  173. static const struct lcnphy_sfo_cfg lcnphy_sfo_cfg[] = {
  174. {965, 1087},
  175. {967, 1085},
  176. {969, 1082},
  177. {971, 1080},
  178. {973, 1078},
  179. {975, 1076},
  180. {977, 1073},
  181. {979, 1071},
  182. {981, 1069},
  183. {983, 1067},
  184. {985, 1065},
  185. {987, 1063},
  186. {989, 1060},
  187. {994, 1055}
  188. };
  189. static const
  190. u16 lcnphy_iqcal_loft_gainladder[] = {
  191. ((2 << 8) | 0),
  192. ((3 << 8) | 0),
  193. ((4 << 8) | 0),
  194. ((6 << 8) | 0),
  195. ((8 << 8) | 0),
  196. ((11 << 8) | 0),
  197. ((16 << 8) | 0),
  198. ((16 << 8) | 1),
  199. ((16 << 8) | 2),
  200. ((16 << 8) | 3),
  201. ((16 << 8) | 4),
  202. ((16 << 8) | 5),
  203. ((16 << 8) | 6),
  204. ((16 << 8) | 7),
  205. ((23 << 8) | 7),
  206. ((32 << 8) | 7),
  207. ((45 << 8) | 7),
  208. ((64 << 8) | 7),
  209. ((91 << 8) | 7),
  210. ((128 << 8) | 7)
  211. };
  212. static const
  213. u16 lcnphy_iqcal_ir_gainladder[] = {
  214. ((1 << 8) | 0),
  215. ((2 << 8) | 0),
  216. ((4 << 8) | 0),
  217. ((6 << 8) | 0),
  218. ((8 << 8) | 0),
  219. ((11 << 8) | 0),
  220. ((16 << 8) | 0),
  221. ((23 << 8) | 0),
  222. ((32 << 8) | 0),
  223. ((45 << 8) | 0),
  224. ((64 << 8) | 0),
  225. ((64 << 8) | 1),
  226. ((64 << 8) | 2),
  227. ((64 << 8) | 3),
  228. ((64 << 8) | 4),
  229. ((64 << 8) | 5),
  230. ((64 << 8) | 6),
  231. ((64 << 8) | 7),
  232. ((91 << 8) | 7),
  233. ((128 << 8) | 7)
  234. };
  235. static const
  236. struct lcnphy_spb_tone lcnphy_spb_tone_3750[] = {
  237. {88, 0},
  238. {73, 49},
  239. {34, 81},
  240. {-17, 86},
  241. {-62, 62},
  242. {-86, 17},
  243. {-81, -34},
  244. {-49, -73},
  245. {0, -88},
  246. {49, -73},
  247. {81, -34},
  248. {86, 17},
  249. {62, 62},
  250. {17, 86},
  251. {-34, 81},
  252. {-73, 49},
  253. {-88, 0},
  254. {-73, -49},
  255. {-34, -81},
  256. {17, -86},
  257. {62, -62},
  258. {86, -17},
  259. {81, 34},
  260. {49, 73},
  261. {0, 88},
  262. {-49, 73},
  263. {-81, 34},
  264. {-86, -17},
  265. {-62, -62},
  266. {-17, -86},
  267. {34, -81},
  268. {73, -49},
  269. };
  270. static const
  271. u16 iqlo_loopback_rf_regs[20] = {
  272. RADIO_2064_REG036,
  273. RADIO_2064_REG11A,
  274. RADIO_2064_REG03A,
  275. RADIO_2064_REG025,
  276. RADIO_2064_REG028,
  277. RADIO_2064_REG005,
  278. RADIO_2064_REG112,
  279. RADIO_2064_REG0FF,
  280. RADIO_2064_REG11F,
  281. RADIO_2064_REG00B,
  282. RADIO_2064_REG113,
  283. RADIO_2064_REG007,
  284. RADIO_2064_REG0FC,
  285. RADIO_2064_REG0FD,
  286. RADIO_2064_REG012,
  287. RADIO_2064_REG057,
  288. RADIO_2064_REG059,
  289. RADIO_2064_REG05C,
  290. RADIO_2064_REG078,
  291. RADIO_2064_REG092,
  292. };
  293. static const
  294. u16 tempsense_phy_regs[14] = {
  295. 0x503,
  296. 0x4a4,
  297. 0x4d0,
  298. 0x4d9,
  299. 0x4da,
  300. 0x4a6,
  301. 0x938,
  302. 0x939,
  303. 0x4d8,
  304. 0x4d0,
  305. 0x4d7,
  306. 0x4a5,
  307. 0x40d,
  308. 0x4a2,
  309. };
  310. static const
  311. u16 rxiq_cal_rf_reg[11] = {
  312. RADIO_2064_REG098,
  313. RADIO_2064_REG116,
  314. RADIO_2064_REG12C,
  315. RADIO_2064_REG06A,
  316. RADIO_2064_REG00B,
  317. RADIO_2064_REG01B,
  318. RADIO_2064_REG113,
  319. RADIO_2064_REG01D,
  320. RADIO_2064_REG114,
  321. RADIO_2064_REG02E,
  322. RADIO_2064_REG12A,
  323. };
  324. static const
  325. struct lcnphy_rx_iqcomp lcnphy_rx_iqcomp_table_rev0[] = {
  326. {1, 0, 0},
  327. {2, 0, 0},
  328. {3, 0, 0},
  329. {4, 0, 0},
  330. {5, 0, 0},
  331. {6, 0, 0},
  332. {7, 0, 0},
  333. {8, 0, 0},
  334. {9, 0, 0},
  335. {10, 0, 0},
  336. {11, 0, 0},
  337. {12, 0, 0},
  338. {13, 0, 0},
  339. {14, 0, 0},
  340. {34, 0, 0},
  341. {38, 0, 0},
  342. {42, 0, 0},
  343. {46, 0, 0},
  344. {36, 0, 0},
  345. {40, 0, 0},
  346. {44, 0, 0},
  347. {48, 0, 0},
  348. {52, 0, 0},
  349. {56, 0, 0},
  350. {60, 0, 0},
  351. {64, 0, 0},
  352. {100, 0, 0},
  353. {104, 0, 0},
  354. {108, 0, 0},
  355. {112, 0, 0},
  356. {116, 0, 0},
  357. {120, 0, 0},
  358. {124, 0, 0},
  359. {128, 0, 0},
  360. {132, 0, 0},
  361. {136, 0, 0},
  362. {140, 0, 0},
  363. {149, 0, 0},
  364. {153, 0, 0},
  365. {157, 0, 0},
  366. {161, 0, 0},
  367. {165, 0, 0},
  368. {184, 0, 0},
  369. {188, 0, 0},
  370. {192, 0, 0},
  371. {196, 0, 0},
  372. {200, 0, 0},
  373. {204, 0, 0},
  374. {208, 0, 0},
  375. {212, 0, 0},
  376. {216, 0, 0},
  377. };
  378. static const u32 lcnphy_23bitgaincode_table[] = {
  379. 0x200100,
  380. 0x200200,
  381. 0x200004,
  382. 0x200014,
  383. 0x200024,
  384. 0x200034,
  385. 0x200134,
  386. 0x200234,
  387. 0x200334,
  388. 0x200434,
  389. 0x200037,
  390. 0x200137,
  391. 0x200237,
  392. 0x200337,
  393. 0x200437,
  394. 0x000035,
  395. 0x000135,
  396. 0x000235,
  397. 0x000037,
  398. 0x000137,
  399. 0x000237,
  400. 0x000337,
  401. 0x00013f,
  402. 0x00023f,
  403. 0x00033f,
  404. 0x00034f,
  405. 0x00044f,
  406. 0x00144f,
  407. 0x00244f,
  408. 0x00254f,
  409. 0x00354f,
  410. 0x00454f,
  411. 0x00464f,
  412. 0x01464f,
  413. 0x02464f,
  414. 0x03464f,
  415. 0x04464f,
  416. };
  417. static const s8 lcnphy_gain_table[] = {
  418. -16,
  419. -13,
  420. 10,
  421. 7,
  422. 4,
  423. 0,
  424. 3,
  425. 6,
  426. 9,
  427. 12,
  428. 15,
  429. 18,
  430. 21,
  431. 24,
  432. 27,
  433. 30,
  434. 33,
  435. 36,
  436. 39,
  437. 42,
  438. 45,
  439. 48,
  440. 50,
  441. 53,
  442. 56,
  443. 59,
  444. 62,
  445. 65,
  446. 68,
  447. 71,
  448. 74,
  449. 77,
  450. 80,
  451. 83,
  452. 86,
  453. 89,
  454. 92,
  455. };
  456. static const s8 lcnphy_gain_index_offset_for_rssi[] = {
  457. 7,
  458. 7,
  459. 7,
  460. 7,
  461. 7,
  462. 7,
  463. 7,
  464. 8,
  465. 7,
  466. 7,
  467. 6,
  468. 7,
  469. 7,
  470. 4,
  471. 4,
  472. 4,
  473. 4,
  474. 4,
  475. 4,
  476. 4,
  477. 4,
  478. 3,
  479. 3,
  480. 3,
  481. 3,
  482. 3,
  483. 3,
  484. 4,
  485. 2,
  486. 2,
  487. 2,
  488. 2,
  489. 2,
  490. 2,
  491. -1,
  492. -2,
  493. -2,
  494. -2
  495. };
  496. struct chan_info_2064_lcnphy {
  497. uint chan;
  498. uint freq;
  499. u8 logen_buftune;
  500. u8 logen_rccr_tx;
  501. u8 txrf_mix_tune_ctrl;
  502. u8 pa_input_tune_g;
  503. u8 logen_rccr_rx;
  504. u8 pa_rxrf_lna1_freq_tune;
  505. u8 pa_rxrf_lna2_freq_tune;
  506. u8 rxrf_rxrf_spare1;
  507. };
  508. static const struct chan_info_2064_lcnphy chan_info_2064_lcnphy[] = {
  509. {1, 2412, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
  510. {2, 2417, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
  511. {3, 2422, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
  512. {4, 2427, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
  513. {5, 2432, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
  514. {6, 2437, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
  515. {7, 2442, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
  516. {8, 2447, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
  517. {9, 2452, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
  518. {10, 2457, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
  519. {11, 2462, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
  520. {12, 2467, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
  521. {13, 2472, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
  522. {14, 2484, 0x0B, 0x0A, 0x00, 0x07, 0x0A, 0x88, 0x88, 0x80},
  523. };
  524. static const struct lcnphy_radio_regs lcnphy_radio_regs_2064[] = {
  525. {0x00, 0, 0, 0, 0},
  526. {0x01, 0x64, 0x64, 0, 0},
  527. {0x02, 0x20, 0x20, 0, 0},
  528. {0x03, 0x66, 0x66, 0, 0},
  529. {0x04, 0xf8, 0xf8, 0, 0},
  530. {0x05, 0, 0, 0, 0},
  531. {0x06, 0x10, 0x10, 0, 0},
  532. {0x07, 0, 0, 0, 0},
  533. {0x08, 0, 0, 0, 0},
  534. {0x09, 0, 0, 0, 0},
  535. {0x0A, 0x37, 0x37, 0, 0},
  536. {0x0B, 0x6, 0x6, 0, 0},
  537. {0x0C, 0x55, 0x55, 0, 0},
  538. {0x0D, 0x8b, 0x8b, 0, 0},
  539. {0x0E, 0, 0, 0, 0},
  540. {0x0F, 0x5, 0x5, 0, 0},
  541. {0x10, 0, 0, 0, 0},
  542. {0x11, 0xe, 0xe, 0, 0},
  543. {0x12, 0, 0, 0, 0},
  544. {0x13, 0xb, 0xb, 0, 0},
  545. {0x14, 0x2, 0x2, 0, 0},
  546. {0x15, 0x12, 0x12, 0, 0},
  547. {0x16, 0x12, 0x12, 0, 0},
  548. {0x17, 0xc, 0xc, 0, 0},
  549. {0x18, 0xc, 0xc, 0, 0},
  550. {0x19, 0xc, 0xc, 0, 0},
  551. {0x1A, 0x8, 0x8, 0, 0},
  552. {0x1B, 0x2, 0x2, 0, 0},
  553. {0x1C, 0, 0, 0, 0},
  554. {0x1D, 0x1, 0x1, 0, 0},
  555. {0x1E, 0x12, 0x12, 0, 0},
  556. {0x1F, 0x6e, 0x6e, 0, 0},
  557. {0x20, 0x2, 0x2, 0, 0},
  558. {0x21, 0x23, 0x23, 0, 0},
  559. {0x22, 0x8, 0x8, 0, 0},
  560. {0x23, 0, 0, 0, 0},
  561. {0x24, 0, 0, 0, 0},
  562. {0x25, 0xc, 0xc, 0, 0},
  563. {0x26, 0x33, 0x33, 0, 0},
  564. {0x27, 0x55, 0x55, 0, 0},
  565. {0x28, 0, 0, 0, 0},
  566. {0x29, 0x30, 0x30, 0, 0},
  567. {0x2A, 0xb, 0xb, 0, 0},
  568. {0x2B, 0x1b, 0x1b, 0, 0},
  569. {0x2C, 0x3, 0x3, 0, 0},
  570. {0x2D, 0x1b, 0x1b, 0, 0},
  571. {0x2E, 0, 0, 0, 0},
  572. {0x2F, 0x20, 0x20, 0, 0},
  573. {0x30, 0xa, 0xa, 0, 0},
  574. {0x31, 0, 0, 0, 0},
  575. {0x32, 0x62, 0x62, 0, 0},
  576. {0x33, 0x19, 0x19, 0, 0},
  577. {0x34, 0x33, 0x33, 0, 0},
  578. {0x35, 0x77, 0x77, 0, 0},
  579. {0x36, 0, 0, 0, 0},
  580. {0x37, 0x70, 0x70, 0, 0},
  581. {0x38, 0x3, 0x3, 0, 0},
  582. {0x39, 0xf, 0xf, 0, 0},
  583. {0x3A, 0x6, 0x6, 0, 0},
  584. {0x3B, 0xcf, 0xcf, 0, 0},
  585. {0x3C, 0x1a, 0x1a, 0, 0},
  586. {0x3D, 0x6, 0x6, 0, 0},
  587. {0x3E, 0x42, 0x42, 0, 0},
  588. {0x3F, 0, 0, 0, 0},
  589. {0x40, 0xfb, 0xfb, 0, 0},
  590. {0x41, 0x9a, 0x9a, 0, 0},
  591. {0x42, 0x7a, 0x7a, 0, 0},
  592. {0x43, 0x29, 0x29, 0, 0},
  593. {0x44, 0, 0, 0, 0},
  594. {0x45, 0x8, 0x8, 0, 0},
  595. {0x46, 0xce, 0xce, 0, 0},
  596. {0x47, 0x27, 0x27, 0, 0},
  597. {0x48, 0x62, 0x62, 0, 0},
  598. {0x49, 0x6, 0x6, 0, 0},
  599. {0x4A, 0x58, 0x58, 0, 0},
  600. {0x4B, 0xf7, 0xf7, 0, 0},
  601. {0x4C, 0, 0, 0, 0},
  602. {0x4D, 0xb3, 0xb3, 0, 0},
  603. {0x4E, 0, 0, 0, 0},
  604. {0x4F, 0x2, 0x2, 0, 0},
  605. {0x50, 0, 0, 0, 0},
  606. {0x51, 0x9, 0x9, 0, 0},
  607. {0x52, 0x5, 0x5, 0, 0},
  608. {0x53, 0x17, 0x17, 0, 0},
  609. {0x54, 0x38, 0x38, 0, 0},
  610. {0x55, 0, 0, 0, 0},
  611. {0x56, 0, 0, 0, 0},
  612. {0x57, 0xb, 0xb, 0, 0},
  613. {0x58, 0, 0, 0, 0},
  614. {0x59, 0, 0, 0, 0},
  615. {0x5A, 0, 0, 0, 0},
  616. {0x5B, 0, 0, 0, 0},
  617. {0x5C, 0, 0, 0, 0},
  618. {0x5D, 0, 0, 0, 0},
  619. {0x5E, 0x88, 0x88, 0, 0},
  620. {0x5F, 0xcc, 0xcc, 0, 0},
  621. {0x60, 0x74, 0x74, 0, 0},
  622. {0x61, 0x74, 0x74, 0, 0},
  623. {0x62, 0x74, 0x74, 0, 0},
  624. {0x63, 0x44, 0x44, 0, 0},
  625. {0x64, 0x77, 0x77, 0, 0},
  626. {0x65, 0x44, 0x44, 0, 0},
  627. {0x66, 0x77, 0x77, 0, 0},
  628. {0x67, 0x55, 0x55, 0, 0},
  629. {0x68, 0x77, 0x77, 0, 0},
  630. {0x69, 0x77, 0x77, 0, 0},
  631. {0x6A, 0, 0, 0, 0},
  632. {0x6B, 0x7f, 0x7f, 0, 0},
  633. {0x6C, 0x8, 0x8, 0, 0},
  634. {0x6D, 0, 0, 0, 0},
  635. {0x6E, 0x88, 0x88, 0, 0},
  636. {0x6F, 0x66, 0x66, 0, 0},
  637. {0x70, 0x66, 0x66, 0, 0},
  638. {0x71, 0x28, 0x28, 0, 0},
  639. {0x72, 0x55, 0x55, 0, 0},
  640. {0x73, 0x4, 0x4, 0, 0},
  641. {0x74, 0, 0, 0, 0},
  642. {0x75, 0, 0, 0, 0},
  643. {0x76, 0, 0, 0, 0},
  644. {0x77, 0x1, 0x1, 0, 0},
  645. {0x78, 0xd6, 0xd6, 0, 0},
  646. {0x79, 0, 0, 0, 0},
  647. {0x7A, 0, 0, 0, 0},
  648. {0x7B, 0, 0, 0, 0},
  649. {0x7C, 0, 0, 0, 0},
  650. {0x7D, 0, 0, 0, 0},
  651. {0x7E, 0, 0, 0, 0},
  652. {0x7F, 0, 0, 0, 0},
  653. {0x80, 0, 0, 0, 0},
  654. {0x81, 0, 0, 0, 0},
  655. {0x82, 0, 0, 0, 0},
  656. {0x83, 0xb4, 0xb4, 0, 0},
  657. {0x84, 0x1, 0x1, 0, 0},
  658. {0x85, 0x20, 0x20, 0, 0},
  659. {0x86, 0x5, 0x5, 0, 0},
  660. {0x87, 0xff, 0xff, 0, 0},
  661. {0x88, 0x7, 0x7, 0, 0},
  662. {0x89, 0x77, 0x77, 0, 0},
  663. {0x8A, 0x77, 0x77, 0, 0},
  664. {0x8B, 0x77, 0x77, 0, 0},
  665. {0x8C, 0x77, 0x77, 0, 0},
  666. {0x8D, 0x8, 0x8, 0, 0},
  667. {0x8E, 0xa, 0xa, 0, 0},
  668. {0x8F, 0x8, 0x8, 0, 0},
  669. {0x90, 0x18, 0x18, 0, 0},
  670. {0x91, 0x5, 0x5, 0, 0},
  671. {0x92, 0x1f, 0x1f, 0, 0},
  672. {0x93, 0x10, 0x10, 0, 0},
  673. {0x94, 0x3, 0x3, 0, 0},
  674. {0x95, 0, 0, 0, 0},
  675. {0x96, 0, 0, 0, 0},
  676. {0x97, 0xaa, 0xaa, 0, 0},
  677. {0x98, 0, 0, 0, 0},
  678. {0x99, 0x23, 0x23, 0, 0},
  679. {0x9A, 0x7, 0x7, 0, 0},
  680. {0x9B, 0xf, 0xf, 0, 0},
  681. {0x9C, 0x10, 0x10, 0, 0},
  682. {0x9D, 0x3, 0x3, 0, 0},
  683. {0x9E, 0x4, 0x4, 0, 0},
  684. {0x9F, 0x20, 0x20, 0, 0},
  685. {0xA0, 0, 0, 0, 0},
  686. {0xA1, 0, 0, 0, 0},
  687. {0xA2, 0, 0, 0, 0},
  688. {0xA3, 0, 0, 0, 0},
  689. {0xA4, 0x1, 0x1, 0, 0},
  690. {0xA5, 0x77, 0x77, 0, 0},
  691. {0xA6, 0x77, 0x77, 0, 0},
  692. {0xA7, 0x77, 0x77, 0, 0},
  693. {0xA8, 0x77, 0x77, 0, 0},
  694. {0xA9, 0x8c, 0x8c, 0, 0},
  695. {0xAA, 0x88, 0x88, 0, 0},
  696. {0xAB, 0x78, 0x78, 0, 0},
  697. {0xAC, 0x57, 0x57, 0, 0},
  698. {0xAD, 0x88, 0x88, 0, 0},
  699. {0xAE, 0, 0, 0, 0},
  700. {0xAF, 0x8, 0x8, 0, 0},
  701. {0xB0, 0x88, 0x88, 0, 0},
  702. {0xB1, 0, 0, 0, 0},
  703. {0xB2, 0x1b, 0x1b, 0, 0},
  704. {0xB3, 0x3, 0x3, 0, 0},
  705. {0xB4, 0x24, 0x24, 0, 0},
  706. {0xB5, 0x3, 0x3, 0, 0},
  707. {0xB6, 0x1b, 0x1b, 0, 0},
  708. {0xB7, 0x24, 0x24, 0, 0},
  709. {0xB8, 0x3, 0x3, 0, 0},
  710. {0xB9, 0, 0, 0, 0},
  711. {0xBA, 0xaa, 0xaa, 0, 0},
  712. {0xBB, 0, 0, 0, 0},
  713. {0xBC, 0x4, 0x4, 0, 0},
  714. {0xBD, 0, 0, 0, 0},
  715. {0xBE, 0x8, 0x8, 0, 0},
  716. {0xBF, 0x11, 0x11, 0, 0},
  717. {0xC0, 0, 0, 0, 0},
  718. {0xC1, 0, 0, 0, 0},
  719. {0xC2, 0x62, 0x62, 0, 0},
  720. {0xC3, 0x1e, 0x1e, 0, 0},
  721. {0xC4, 0x33, 0x33, 0, 0},
  722. {0xC5, 0x37, 0x37, 0, 0},
  723. {0xC6, 0, 0, 0, 0},
  724. {0xC7, 0x70, 0x70, 0, 0},
  725. {0xC8, 0x1e, 0x1e, 0, 0},
  726. {0xC9, 0x6, 0x6, 0, 0},
  727. {0xCA, 0x4, 0x4, 0, 0},
  728. {0xCB, 0x2f, 0x2f, 0, 0},
  729. {0xCC, 0xf, 0xf, 0, 0},
  730. {0xCD, 0, 0, 0, 0},
  731. {0xCE, 0xff, 0xff, 0, 0},
  732. {0xCF, 0x8, 0x8, 0, 0},
  733. {0xD0, 0x3f, 0x3f, 0, 0},
  734. {0xD1, 0x3f, 0x3f, 0, 0},
  735. {0xD2, 0x3f, 0x3f, 0, 0},
  736. {0xD3, 0, 0, 0, 0},
  737. {0xD4, 0, 0, 0, 0},
  738. {0xD5, 0, 0, 0, 0},
  739. {0xD6, 0xcc, 0xcc, 0, 0},
  740. {0xD7, 0, 0, 0, 0},
  741. {0xD8, 0x8, 0x8, 0, 0},
  742. {0xD9, 0x8, 0x8, 0, 0},
  743. {0xDA, 0x8, 0x8, 0, 0},
  744. {0xDB, 0x11, 0x11, 0, 0},
  745. {0xDC, 0, 0, 0, 0},
  746. {0xDD, 0x87, 0x87, 0, 0},
  747. {0xDE, 0x88, 0x88, 0, 0},
  748. {0xDF, 0x8, 0x8, 0, 0},
  749. {0xE0, 0x8, 0x8, 0, 0},
  750. {0xE1, 0x8, 0x8, 0, 0},
  751. {0xE2, 0, 0, 0, 0},
  752. {0xE3, 0, 0, 0, 0},
  753. {0xE4, 0, 0, 0, 0},
  754. {0xE5, 0xf5, 0xf5, 0, 0},
  755. {0xE6, 0x30, 0x30, 0, 0},
  756. {0xE7, 0x1, 0x1, 0, 0},
  757. {0xE8, 0, 0, 0, 0},
  758. {0xE9, 0xff, 0xff, 0, 0},
  759. {0xEA, 0, 0, 0, 0},
  760. {0xEB, 0, 0, 0, 0},
  761. {0xEC, 0x22, 0x22, 0, 0},
  762. {0xED, 0, 0, 0, 0},
  763. {0xEE, 0, 0, 0, 0},
  764. {0xEF, 0, 0, 0, 0},
  765. {0xF0, 0x3, 0x3, 0, 0},
  766. {0xF1, 0x1, 0x1, 0, 0},
  767. {0xF2, 0, 0, 0, 0},
  768. {0xF3, 0, 0, 0, 0},
  769. {0xF4, 0, 0, 0, 0},
  770. {0xF5, 0, 0, 0, 0},
  771. {0xF6, 0, 0, 0, 0},
  772. {0xF7, 0x6, 0x6, 0, 0},
  773. {0xF8, 0, 0, 0, 0},
  774. {0xF9, 0, 0, 0, 0},
  775. {0xFA, 0x40, 0x40, 0, 0},
  776. {0xFB, 0, 0, 0, 0},
  777. {0xFC, 0x1, 0x1, 0, 0},
  778. {0xFD, 0x80, 0x80, 0, 0},
  779. {0xFE, 0x2, 0x2, 0, 0},
  780. {0xFF, 0x10, 0x10, 0, 0},
  781. {0x100, 0x2, 0x2, 0, 0},
  782. {0x101, 0x1e, 0x1e, 0, 0},
  783. {0x102, 0x1e, 0x1e, 0, 0},
  784. {0x103, 0, 0, 0, 0},
  785. {0x104, 0x1f, 0x1f, 0, 0},
  786. {0x105, 0, 0x8, 0, 1},
  787. {0x106, 0x2a, 0x2a, 0, 0},
  788. {0x107, 0xf, 0xf, 0, 0},
  789. {0x108, 0, 0, 0, 0},
  790. {0x109, 0, 0, 0, 0},
  791. {0x10A, 0, 0, 0, 0},
  792. {0x10B, 0, 0, 0, 0},
  793. {0x10C, 0, 0, 0, 0},
  794. {0x10D, 0, 0, 0, 0},
  795. {0x10E, 0, 0, 0, 0},
  796. {0x10F, 0, 0, 0, 0},
  797. {0x110, 0, 0, 0, 0},
  798. {0x111, 0, 0, 0, 0},
  799. {0x112, 0, 0, 0, 0},
  800. {0x113, 0, 0, 0, 0},
  801. {0x114, 0, 0, 0, 0},
  802. {0x115, 0, 0, 0, 0},
  803. {0x116, 0, 0, 0, 0},
  804. {0x117, 0, 0, 0, 0},
  805. {0x118, 0, 0, 0, 0},
  806. {0x119, 0, 0, 0, 0},
  807. {0x11A, 0, 0, 0, 0},
  808. {0x11B, 0, 0, 0, 0},
  809. {0x11C, 0x1, 0x1, 0, 0},
  810. {0x11D, 0, 0, 0, 0},
  811. {0x11E, 0, 0, 0, 0},
  812. {0x11F, 0, 0, 0, 0},
  813. {0x120, 0, 0, 0, 0},
  814. {0x121, 0, 0, 0, 0},
  815. {0x122, 0x80, 0x80, 0, 0},
  816. {0x123, 0, 0, 0, 0},
  817. {0x124, 0xf8, 0xf8, 0, 0},
  818. {0x125, 0, 0, 0, 0},
  819. {0x126, 0, 0, 0, 0},
  820. {0x127, 0, 0, 0, 0},
  821. {0x128, 0, 0, 0, 0},
  822. {0x129, 0, 0, 0, 0},
  823. {0x12A, 0, 0, 0, 0},
  824. {0x12B, 0, 0, 0, 0},
  825. {0x12C, 0, 0, 0, 0},
  826. {0x12D, 0, 0, 0, 0},
  827. {0x12E, 0, 0, 0, 0},
  828. {0x12F, 0, 0, 0, 0},
  829. {0x130, 0, 0, 0, 0},
  830. {0xFFFF, 0, 0, 0, 0}
  831. };
  832. #define LCNPHY_NUM_DIG_FILT_COEFFS 16
  833. #define LCNPHY_NUM_TX_DIG_FILTERS_CCK 13
  834. static const u16 LCNPHY_txdigfiltcoeffs_cck[LCNPHY_NUM_TX_DIG_FILTERS_CCK]
  835. [LCNPHY_NUM_DIG_FILT_COEFFS + 1] = {
  836. {0, 1, 415, 1874, 64, 128, 64, 792, 1656, 64, 128, 64, 778, 1582, 64,
  837. 128, 64,},
  838. {1, 1, 402, 1847, 259, 59, 259, 671, 1794, 68, 54, 68, 608, 1863, 93,
  839. 167, 93,},
  840. {2, 1, 415, 1874, 64, 128, 64, 792, 1656, 192, 384, 192, 778, 1582, 64,
  841. 128, 64,},
  842. {3, 1, 302, 1841, 129, 258, 129, 658, 1720, 205, 410, 205, 754, 1760,
  843. 170, 340, 170,},
  844. {20, 1, 360, 1884, 242, 1734, 242, 752, 1720, 205, 1845, 205, 767, 1760,
  845. 256, 185, 256,},
  846. {21, 1, 360, 1884, 149, 1874, 149, 752, 1720, 205, 1883, 205, 767, 1760,
  847. 256, 273, 256,},
  848. {22, 1, 360, 1884, 98, 1948, 98, 752, 1720, 205, 1924, 205, 767, 1760,
  849. 256, 352, 256,},
  850. {23, 1, 350, 1884, 116, 1966, 116, 752, 1720, 205, 2008, 205, 767, 1760,
  851. 128, 233, 128,},
  852. {24, 1, 325, 1884, 32, 40, 32, 756, 1720, 256, 471, 256, 766, 1760, 256,
  853. 1881, 256,},
  854. {25, 1, 299, 1884, 51, 64, 51, 736, 1720, 256, 471, 256, 765, 1760, 256,
  855. 1881, 256,},
  856. {26, 1, 277, 1943, 39, 117, 88, 637, 1838, 64, 192, 144, 614, 1864, 128,
  857. 384, 288,},
  858. {27, 1, 245, 1943, 49, 147, 110, 626, 1838, 256, 768, 576, 613, 1864,
  859. 128, 384, 288,},
  860. {30, 1, 302, 1841, 61, 122, 61, 658, 1720, 205, 410, 205, 754, 1760,
  861. 170, 340, 170,},
  862. };
  863. #define LCNPHY_NUM_TX_DIG_FILTERS_OFDM 3
  864. static const u16 LCNPHY_txdigfiltcoeffs_ofdm[LCNPHY_NUM_TX_DIG_FILTERS_OFDM]
  865. [LCNPHY_NUM_DIG_FILT_COEFFS + 1] = {
  866. {0, 0, 0xa2, 0x0, 0x100, 0x100, 0x0, 0x0, 0x0, 0x100, 0x0, 0x0,
  867. 0x278, 0xfea0, 0x80, 0x100, 0x80,},
  868. {1, 0, 374, 0xFF79, 16, 32, 16, 799, 0xFE74, 50, 32, 50,
  869. 750, 0xFE2B, 212, 0xFFCE, 212,},
  870. {2, 0, 375, 0xFF16, 37, 76, 37, 799, 0xFE74, 32, 20, 32, 748,
  871. 0xFEF2, 128, 0xFFE2, 128}
  872. };
  873. #define wlc_lcnphy_set_start_tx_pwr_idx(pi, idx) \
  874. mod_phy_reg(pi, 0x4a4, \
  875. (0x1ff << 0), \
  876. (u16)(idx) << 0)
  877. #define wlc_lcnphy_set_tx_pwr_npt(pi, npt) \
  878. mod_phy_reg(pi, 0x4a5, \
  879. (0x7 << 8), \
  880. (u16)(npt) << 8)
  881. #define wlc_lcnphy_get_tx_pwr_ctrl(pi) \
  882. (read_phy_reg((pi), 0x4a4) & \
  883. ((0x1 << 15) | \
  884. (0x1 << 14) | \
  885. (0x1 << 13)))
  886. #define wlc_lcnphy_get_tx_pwr_npt(pi) \
  887. ((read_phy_reg(pi, 0x4a5) & \
  888. (0x7 << 8)) >> \
  889. 8)
  890. #define wlc_lcnphy_get_current_tx_pwr_idx_if_pwrctrl_on(pi) \
  891. (read_phy_reg(pi, 0x473) & 0x1ff)
  892. #define wlc_lcnphy_get_target_tx_pwr(pi) \
  893. ((read_phy_reg(pi, 0x4a7) & \
  894. (0xff << 0)) >> \
  895. 0)
  896. #define wlc_lcnphy_set_target_tx_pwr(pi, target) \
  897. mod_phy_reg(pi, 0x4a7, \
  898. (0xff << 0), \
  899. (u16)(target) << 0)
  900. #define wlc_radio_2064_rcal_done(pi) \
  901. (0 != (read_radio_reg(pi, RADIO_2064_REG05C) & 0x20))
  902. #define tempsense_done(pi) \
  903. (0x8000 == (read_phy_reg(pi, 0x476) & 0x8000))
  904. #define LCNPHY_IQLOCC_READ(val) \
  905. ((u8)(-(s8)(((val) & 0xf0) >> 4) + (s8)((val) & 0x0f)))
  906. #define FIXED_TXPWR 78
  907. #define LCNPHY_TEMPSENSE(val) ((s16)((val > 255) ? (val - 512) : val))
  908. void wlc_lcnphy_write_table(struct brcms_phy *pi, const struct phytbl_info *pti)
  909. {
  910. wlc_phy_write_table(pi, pti, 0x455, 0x457, 0x456);
  911. }
  912. void wlc_lcnphy_read_table(struct brcms_phy *pi, struct phytbl_info *pti)
  913. {
  914. wlc_phy_read_table(pi, pti, 0x455, 0x457, 0x456);
  915. }
  916. static void
  917. wlc_lcnphy_common_read_table(struct brcms_phy *pi, u32 tbl_id,
  918. const u16 *tbl_ptr, u32 tbl_len,
  919. u32 tbl_width, u32 tbl_offset)
  920. {
  921. struct phytbl_info tab;
  922. tab.tbl_id = tbl_id;
  923. tab.tbl_ptr = tbl_ptr;
  924. tab.tbl_len = tbl_len;
  925. tab.tbl_width = tbl_width;
  926. tab.tbl_offset = tbl_offset;
  927. wlc_lcnphy_read_table(pi, &tab);
  928. }
  929. static void
  930. wlc_lcnphy_common_write_table(struct brcms_phy *pi, u32 tbl_id,
  931. const u16 *tbl_ptr, u32 tbl_len,
  932. u32 tbl_width, u32 tbl_offset)
  933. {
  934. struct phytbl_info tab;
  935. tab.tbl_id = tbl_id;
  936. tab.tbl_ptr = tbl_ptr;
  937. tab.tbl_len = tbl_len;
  938. tab.tbl_width = tbl_width;
  939. tab.tbl_offset = tbl_offset;
  940. wlc_lcnphy_write_table(pi, &tab);
  941. }
  942. static u32
  943. wlc_lcnphy_qdiv_roundup(u32 dividend, u32 divisor, u8 precision)
  944. {
  945. u32 quotient, remainder, roundup, rbit;
  946. quotient = dividend / divisor;
  947. remainder = dividend % divisor;
  948. rbit = divisor & 1;
  949. roundup = (divisor >> 1) + rbit;
  950. while (precision--) {
  951. quotient <<= 1;
  952. if (remainder >= roundup) {
  953. quotient++;
  954. remainder = ((remainder - roundup) << 1) + rbit;
  955. } else {
  956. remainder <<= 1;
  957. }
  958. }
  959. if (remainder >= roundup)
  960. quotient++;
  961. return quotient;
  962. }
  963. static int wlc_lcnphy_calc_floor(s16 coeff_x, int type)
  964. {
  965. int k;
  966. k = 0;
  967. if (type == 0) {
  968. if (coeff_x < 0)
  969. k = (coeff_x - 1) / 2;
  970. else
  971. k = coeff_x / 2;
  972. }
  973. if (type == 1) {
  974. if ((coeff_x + 1) < 0)
  975. k = (coeff_x) / 2;
  976. else
  977. k = (coeff_x + 1) / 2;
  978. }
  979. return k;
  980. }
  981. static void
  982. wlc_lcnphy_get_tx_gain(struct brcms_phy *pi, struct lcnphy_txgains *gains)
  983. {
  984. u16 dac_gain, rfgain0, rfgain1;
  985. dac_gain = read_phy_reg(pi, 0x439) >> 0;
  986. gains->dac_gain = (dac_gain & 0x380) >> 7;
  987. rfgain0 = (read_phy_reg(pi, 0x4b5) & (0xffff << 0)) >> 0;
  988. rfgain1 = (read_phy_reg(pi, 0x4fb) & (0x7fff << 0)) >> 0;
  989. gains->gm_gain = rfgain0 & 0xff;
  990. gains->pga_gain = (rfgain0 >> 8) & 0xff;
  991. gains->pad_gain = rfgain1 & 0xff;
  992. }
  993. static void wlc_lcnphy_set_dac_gain(struct brcms_phy *pi, u16 dac_gain)
  994. {
  995. u16 dac_ctrl;
  996. dac_ctrl = (read_phy_reg(pi, 0x439) >> 0);
  997. dac_ctrl = dac_ctrl & 0xc7f;
  998. dac_ctrl = dac_ctrl | (dac_gain << 7);
  999. mod_phy_reg(pi, 0x439, (0xfff << 0), (dac_ctrl) << 0);
  1000. }
  1001. static void wlc_lcnphy_set_tx_gain_override(struct brcms_phy *pi, bool bEnable)
  1002. {
  1003. u16 bit = bEnable ? 1 : 0;
  1004. mod_phy_reg(pi, 0x4b0, (0x1 << 7), bit << 7);
  1005. mod_phy_reg(pi, 0x4b0, (0x1 << 14), bit << 14);
  1006. mod_phy_reg(pi, 0x43b, (0x1 << 6), bit << 6);
  1007. }
  1008. static void
  1009. wlc_lcnphy_rx_gain_override_enable(struct brcms_phy *pi, bool enable)
  1010. {
  1011. u16 ebit = enable ? 1 : 0;
  1012. mod_phy_reg(pi, 0x4b0, (0x1 << 8), ebit << 8);
  1013. mod_phy_reg(pi, 0x44c, (0x1 << 0), ebit << 0);
  1014. if (LCNREV_LT(pi->pubpi.phy_rev, 2)) {
  1015. mod_phy_reg(pi, 0x44c, (0x1 << 4), ebit << 4);
  1016. mod_phy_reg(pi, 0x44c, (0x1 << 6), ebit << 6);
  1017. mod_phy_reg(pi, 0x4b0, (0x1 << 5), ebit << 5);
  1018. mod_phy_reg(pi, 0x4b0, (0x1 << 6), ebit << 6);
  1019. } else {
  1020. mod_phy_reg(pi, 0x4b0, (0x1 << 12), ebit << 12);
  1021. mod_phy_reg(pi, 0x4b0, (0x1 << 13), ebit << 13);
  1022. mod_phy_reg(pi, 0x4b0, (0x1 << 5), ebit << 5);
  1023. }
  1024. if (CHSPEC_IS2G(pi->radio_chanspec)) {
  1025. mod_phy_reg(pi, 0x4b0, (0x1 << 10), ebit << 10);
  1026. mod_phy_reg(pi, 0x4e5, (0x1 << 3), ebit << 3);
  1027. }
  1028. }
  1029. static void
  1030. wlc_lcnphy_set_rx_gain_by_distribution(struct brcms_phy *pi,
  1031. u16 trsw,
  1032. u16 ext_lna,
  1033. u16 biq2,
  1034. u16 biq1,
  1035. u16 tia, u16 lna2, u16 lna1)
  1036. {
  1037. u16 gain0_15, gain16_19;
  1038. gain16_19 = biq2 & 0xf;
  1039. gain0_15 = ((biq1 & 0xf) << 12) |
  1040. ((tia & 0xf) << 8) |
  1041. ((lna2 & 0x3) << 6) |
  1042. ((lna2 &
  1043. 0x3) << 4) | ((lna1 & 0x3) << 2) | ((lna1 & 0x3) << 0);
  1044. mod_phy_reg(pi, 0x4b6, (0xffff << 0), gain0_15 << 0);
  1045. mod_phy_reg(pi, 0x4b7, (0xf << 0), gain16_19 << 0);
  1046. mod_phy_reg(pi, 0x4b1, (0x3 << 11), lna1 << 11);
  1047. if (LCNREV_LT(pi->pubpi.phy_rev, 2)) {
  1048. mod_phy_reg(pi, 0x4b1, (0x1 << 9), ext_lna << 9);
  1049. mod_phy_reg(pi, 0x4b1, (0x1 << 10), ext_lna << 10);
  1050. } else {
  1051. mod_phy_reg(pi, 0x4b1, (0x1 << 10), 0 << 10);
  1052. mod_phy_reg(pi, 0x4b1, (0x1 << 15), 0 << 15);
  1053. mod_phy_reg(pi, 0x4b1, (0x1 << 9), ext_lna << 9);
  1054. }
  1055. mod_phy_reg(pi, 0x44d, (0x1 << 0), (!trsw) << 0);
  1056. }
  1057. static void wlc_lcnphy_set_trsw_override(struct brcms_phy *pi, bool tx, bool rx)
  1058. {
  1059. mod_phy_reg(pi, 0x44d,
  1060. (0x1 << 1) |
  1061. (0x1 << 0), (tx ? (0x1 << 1) : 0) | (rx ? (0x1 << 0) : 0));
  1062. or_phy_reg(pi, 0x44c, (0x1 << 1) | (0x1 << 0));
  1063. }
  1064. static void wlc_lcnphy_clear_trsw_override(struct brcms_phy *pi)
  1065. {
  1066. and_phy_reg(pi, 0x44c, (u16) ~((0x1 << 1) | (0x1 << 0)));
  1067. }
  1068. static void wlc_lcnphy_set_rx_iq_comp(struct brcms_phy *pi, u16 a, u16 b)
  1069. {
  1070. mod_phy_reg(pi, 0x645, (0x3ff << 0), (a) << 0);
  1071. mod_phy_reg(pi, 0x646, (0x3ff << 0), (b) << 0);
  1072. mod_phy_reg(pi, 0x647, (0x3ff << 0), (a) << 0);
  1073. mod_phy_reg(pi, 0x648, (0x3ff << 0), (b) << 0);
  1074. mod_phy_reg(pi, 0x649, (0x3ff << 0), (a) << 0);
  1075. mod_phy_reg(pi, 0x64a, (0x3ff << 0), (b) << 0);
  1076. }
  1077. static bool
  1078. wlc_lcnphy_rx_iq_est(struct brcms_phy *pi,
  1079. u16 num_samps,
  1080. u8 wait_time, struct lcnphy_iq_est *iq_est)
  1081. {
  1082. int wait_count = 0;
  1083. bool result = true;
  1084. u8 phybw40;
  1085. phybw40 = CHSPEC_IS40(pi->radio_chanspec);
  1086. mod_phy_reg(pi, 0x6da, (0x1 << 5), (1) << 5);
  1087. mod_phy_reg(pi, 0x410, (0x1 << 3), (0) << 3);
  1088. mod_phy_reg(pi, 0x482, (0xffff << 0), (num_samps) << 0);
  1089. mod_phy_reg(pi, 0x481, (0xff << 0), ((u16) wait_time) << 0);
  1090. mod_phy_reg(pi, 0x481, (0x1 << 8), (0) << 8);
  1091. mod_phy_reg(pi, 0x481, (0x1 << 9), (1) << 9);
  1092. while (read_phy_reg(pi, 0x481) & (0x1 << 9)) {
  1093. if (wait_count > (10 * 500)) {
  1094. result = false;
  1095. goto cleanup;
  1096. }
  1097. udelay(100);
  1098. wait_count++;
  1099. }
  1100. iq_est->iq_prod = ((u32) read_phy_reg(pi, 0x483) << 16) |
  1101. (u32) read_phy_reg(pi, 0x484);
  1102. iq_est->i_pwr = ((u32) read_phy_reg(pi, 0x485) << 16) |
  1103. (u32) read_phy_reg(pi, 0x486);
  1104. iq_est->q_pwr = ((u32) read_phy_reg(pi, 0x487) << 16) |
  1105. (u32) read_phy_reg(pi, 0x488);
  1106. cleanup:
  1107. mod_phy_reg(pi, 0x410, (0x1 << 3), (1) << 3);
  1108. mod_phy_reg(pi, 0x6da, (0x1 << 5), (0) << 5);
  1109. return result;
  1110. }
  1111. static bool wlc_lcnphy_calc_rx_iq_comp(struct brcms_phy *pi, u16 num_samps)
  1112. {
  1113. #define LCNPHY_MIN_RXIQ_PWR 2
  1114. bool result;
  1115. u16 a0_new, b0_new;
  1116. struct lcnphy_iq_est iq_est = { 0, 0, 0 };
  1117. s32 a, b, temp;
  1118. s16 iq_nbits, qq_nbits, arsh, brsh;
  1119. s32 iq;
  1120. u32 ii, qq;
  1121. struct brcms_phy_lcnphy *pi_lcn = pi->u.pi_lcnphy;
  1122. a0_new = ((read_phy_reg(pi, 0x645) & (0x3ff << 0)) >> 0);
  1123. b0_new = ((read_phy_reg(pi, 0x646) & (0x3ff << 0)) >> 0);
  1124. mod_phy_reg(pi, 0x6d1, (0x1 << 2), (0) << 2);
  1125. mod_phy_reg(pi, 0x64b, (0x1 << 6), (1) << 6);
  1126. wlc_lcnphy_set_rx_iq_comp(pi, 0, 0);
  1127. result = wlc_lcnphy_rx_iq_est(pi, num_samps, 32, &iq_est);
  1128. if (!result)
  1129. goto cleanup;
  1130. iq = (s32) iq_est.iq_prod;
  1131. ii = iq_est.i_pwr;
  1132. qq = iq_est.q_pwr;
  1133. if ((ii + qq) < LCNPHY_MIN_RXIQ_PWR) {
  1134. result = false;
  1135. goto cleanup;
  1136. }
  1137. iq_nbits = wlc_phy_nbits(iq);
  1138. qq_nbits = wlc_phy_nbits(qq);
  1139. arsh = 10 - (30 - iq_nbits);
  1140. if (arsh >= 0) {
  1141. a = (-(iq << (30 - iq_nbits)) + (ii >> (1 + arsh)));
  1142. temp = (s32) (ii >> arsh);
  1143. if (temp == 0)
  1144. return false;
  1145. } else {
  1146. a = (-(iq << (30 - iq_nbits)) + (ii << (-1 - arsh)));
  1147. temp = (s32) (ii << -arsh);
  1148. if (temp == 0)
  1149. return false;
  1150. }
  1151. a /= temp;
  1152. brsh = qq_nbits - 31 + 20;
  1153. if (brsh >= 0) {
  1154. b = (qq << (31 - qq_nbits));
  1155. temp = (s32) (ii >> brsh);
  1156. if (temp == 0)
  1157. return false;
  1158. } else {
  1159. b = (qq << (31 - qq_nbits));
  1160. temp = (s32) (ii << -brsh);
  1161. if (temp == 0)
  1162. return false;
  1163. }
  1164. b /= temp;
  1165. b -= a * a;
  1166. b = (s32) int_sqrt((unsigned long) b);
  1167. b -= (1 << 10);
  1168. a0_new = (u16) (a & 0x3ff);
  1169. b0_new = (u16) (b & 0x3ff);
  1170. cleanup:
  1171. wlc_lcnphy_set_rx_iq_comp(pi, a0_new, b0_new);
  1172. mod_phy_reg(pi, 0x64b, (0x1 << 0), (1) << 0);
  1173. mod_phy_reg(pi, 0x64b, (0x1 << 3), (1) << 3);
  1174. pi_lcn->lcnphy_cal_results.rxiqcal_coeff_a0 = a0_new;
  1175. pi_lcn->lcnphy_cal_results.rxiqcal_coeff_b0 = b0_new;
  1176. return result;
  1177. }
  1178. static u32 wlc_lcnphy_measure_digital_power(struct brcms_phy *pi, u16 nsamples)
  1179. {
  1180. struct lcnphy_iq_est iq_est = { 0, 0, 0 };
  1181. if (!wlc_lcnphy_rx_iq_est(pi, nsamples, 32, &iq_est))
  1182. return 0;
  1183. return (iq_est.i_pwr + iq_est.q_pwr) / nsamples;
  1184. }
  1185. static bool
  1186. wlc_lcnphy_rx_iq_cal(struct brcms_phy *pi,
  1187. const struct lcnphy_rx_iqcomp *iqcomp,
  1188. int iqcomp_sz, bool tx_switch, bool rx_switch, int module,
  1189. int tx_gain_idx)
  1190. {
  1191. struct lcnphy_txgains old_gains;
  1192. u16 tx_pwr_ctrl;
  1193. u8 tx_gain_index_old = 0;
  1194. bool result = false, tx_gain_override_old = false;
  1195. u16 i, Core1TxControl_old, RFOverride0_old,
  1196. RFOverrideVal0_old, rfoverride2_old, rfoverride2val_old,
  1197. rfoverride3_old, rfoverride3val_old, rfoverride4_old,
  1198. rfoverride4val_old, afectrlovr_old, afectrlovrval_old;
  1199. int tia_gain;
  1200. u32 received_power, rx_pwr_threshold;
  1201. u16 old_sslpnCalibClkEnCtrl, old_sslpnRxFeClkEnCtrl;
  1202. u16 values_to_save[11];
  1203. s16 *ptr;
  1204. struct brcms_phy_lcnphy *pi_lcn = pi->u.pi_lcnphy;
  1205. ptr = kmalloc(sizeof(s16) * 131, GFP_ATOMIC);
  1206. if (NULL == ptr)
  1207. return false;
  1208. if (module == 2) {
  1209. while (iqcomp_sz--) {
  1210. if (iqcomp[iqcomp_sz].chan ==
  1211. CHSPEC_CHANNEL(pi->radio_chanspec)) {
  1212. wlc_lcnphy_set_rx_iq_comp(pi,
  1213. (u16)
  1214. iqcomp[iqcomp_sz].a,
  1215. (u16)
  1216. iqcomp[iqcomp_sz].b);
  1217. result = true;
  1218. break;
  1219. }
  1220. }
  1221. goto cal_done;
  1222. }
  1223. if (module == 1) {
  1224. tx_pwr_ctrl = wlc_lcnphy_get_tx_pwr_ctrl(pi);
  1225. wlc_lcnphy_set_tx_pwr_ctrl(pi, LCNPHY_TX_PWR_CTRL_OFF);
  1226. for (i = 0; i < 11; i++)
  1227. values_to_save[i] =
  1228. read_radio_reg(pi, rxiq_cal_rf_reg[i]);
  1229. Core1TxControl_old = read_phy_reg(pi, 0x631);
  1230. or_phy_reg(pi, 0x631, 0x0015);
  1231. RFOverride0_old = read_phy_reg(pi, 0x44c);
  1232. RFOverrideVal0_old = read_phy_reg(pi, 0x44d);
  1233. rfoverride2_old = read_phy_reg(pi, 0x4b0);
  1234. rfoverride2val_old = read_phy_reg(pi, 0x4b1);
  1235. rfoverride3_old = read_phy_reg(pi, 0x4f9);
  1236. rfoverride3val_old = read_phy_reg(pi, 0x4fa);
  1237. rfoverride4_old = read_phy_reg(pi, 0x938);
  1238. rfoverride4val_old = read_phy_reg(pi, 0x939);
  1239. afectrlovr_old = read_phy_reg(pi, 0x43b);
  1240. afectrlovrval_old = read_phy_reg(pi, 0x43c);
  1241. old_sslpnCalibClkEnCtrl = read_phy_reg(pi, 0x6da);
  1242. old_sslpnRxFeClkEnCtrl = read_phy_reg(pi, 0x6db);
  1243. tx_gain_override_old = wlc_lcnphy_tx_gain_override_enabled(pi);
  1244. if (tx_gain_override_old) {
  1245. wlc_lcnphy_get_tx_gain(pi, &old_gains);
  1246. tx_gain_index_old = pi_lcn->lcnphy_current_index;
  1247. }
  1248. wlc_lcnphy_set_tx_pwr_by_index(pi, tx_gain_idx);
  1249. mod_phy_reg(pi, 0x4f9, (0x1 << 0), 1 << 0);
  1250. mod_phy_reg(pi, 0x4fa, (0x1 << 0), 0 << 0);
  1251. mod_phy_reg(pi, 0x43b, (0x1 << 1), 1 << 1);
  1252. mod_phy_reg(pi, 0x43c, (0x1 << 1), 0 << 1);
  1253. write_radio_reg(pi, RADIO_2064_REG116, 0x06);
  1254. write_radio_reg(pi, RADIO_2064_REG12C, 0x07);
  1255. write_radio_reg(pi, RADIO_2064_REG06A, 0xd3);
  1256. write_radio_reg(pi, RADIO_2064_REG098, 0x03);
  1257. write_radio_reg(pi, RADIO_2064_REG00B, 0x7);
  1258. mod_radio_reg(pi, RADIO_2064_REG113, 1 << 4, 1 << 4);
  1259. write_radio_reg(pi, RADIO_2064_REG01D, 0x01);
  1260. write_radio_reg(pi, RADIO_2064_REG114, 0x01);
  1261. write_radio_reg(pi, RADIO_2064_REG02E, 0x10);
  1262. write_radio_reg(pi, RADIO_2064_REG12A, 0x08);
  1263. mod_phy_reg(pi, 0x938, (0x1 << 0), 1 << 0);
  1264. mod_phy_reg(pi, 0x939, (0x1 << 0), 0 << 0);
  1265. mod_phy_reg(pi, 0x938, (0x1 << 1), 1 << 1);
  1266. mod_phy_reg(pi, 0x939, (0x1 << 1), 1 << 1);
  1267. mod_phy_reg(pi, 0x938, (0x1 << 2), 1 << 2);
  1268. mod_phy_reg(pi, 0x939, (0x1 << 2), 1 << 2);
  1269. mod_phy_reg(pi, 0x938, (0x1 << 3), 1 << 3);
  1270. mod_phy_reg(pi, 0x939, (0x1 << 3), 1 << 3);
  1271. mod_phy_reg(pi, 0x938, (0x1 << 5), 1 << 5);
  1272. mod_phy_reg(pi, 0x939, (0x1 << 5), 0 << 5);
  1273. mod_phy_reg(pi, 0x43b, (0x1 << 0), 1 << 0);
  1274. mod_phy_reg(pi, 0x43c, (0x1 << 0), 0 << 0);
  1275. wlc_lcnphy_start_tx_tone(pi, 2000, 120, 0);
  1276. write_phy_reg(pi, 0x6da, 0xffff);
  1277. or_phy_reg(pi, 0x6db, 0x3);
  1278. wlc_lcnphy_set_trsw_override(pi, tx_switch, rx_switch);
  1279. wlc_lcnphy_rx_gain_override_enable(pi, true);
  1280. tia_gain = 8;
  1281. rx_pwr_threshold = 950;
  1282. while (tia_gain > 0) {
  1283. tia_gain -= 1;
  1284. wlc_lcnphy_set_rx_gain_by_distribution(pi,
  1285. 0, 0, 2, 2,
  1286. (u16)
  1287. tia_gain, 1, 0);
  1288. udelay(500);
  1289. received_power =
  1290. wlc_lcnphy_measure_digital_power(pi, 2000);
  1291. if (received_power < rx_pwr_threshold)
  1292. break;
  1293. }
  1294. result = wlc_lcnphy_calc_rx_iq_comp(pi, 0xffff);
  1295. wlc_lcnphy_stop_tx_tone(pi);
  1296. write_phy_reg(pi, 0x631, Core1TxControl_old);
  1297. write_phy_reg(pi, 0x44c, RFOverrideVal0_old);
  1298. write_phy_reg(pi, 0x44d, RFOverrideVal0_old);
  1299. write_phy_reg(pi, 0x4b0, rfoverride2_old);
  1300. write_phy_reg(pi, 0x4b1, rfoverride2val_old);
  1301. write_phy_reg(pi, 0x4f9, rfoverride3_old);
  1302. write_phy_reg(pi, 0x4fa, rfoverride3val_old);
  1303. write_phy_reg(pi, 0x938, rfoverride4_old);
  1304. write_phy_reg(pi, 0x939, rfoverride4val_old);
  1305. write_phy_reg(pi, 0x43b, afectrlovr_old);
  1306. write_phy_reg(pi, 0x43c, afectrlovrval_old);
  1307. write_phy_reg(pi, 0x6da, old_sslpnCalibClkEnCtrl);
  1308. write_phy_reg(pi, 0x6db, old_sslpnRxFeClkEnCtrl);
  1309. wlc_lcnphy_clear_trsw_override(pi);
  1310. mod_phy_reg(pi, 0x44c, (0x1 << 2), 0 << 2);
  1311. for (i = 0; i < 11; i++)
  1312. write_radio_reg(pi, rxiq_cal_rf_reg[i],
  1313. values_to_save[i]);
  1314. if (tx_gain_override_old)
  1315. wlc_lcnphy_set_tx_pwr_by_index(pi, tx_gain_index_old);
  1316. else
  1317. wlc_lcnphy_disable_tx_gain_override(pi);
  1318. wlc_lcnphy_set_tx_pwr_ctrl(pi, tx_pwr_ctrl);
  1319. wlc_lcnphy_rx_gain_override_enable(pi, false);
  1320. }
  1321. cal_done:
  1322. kfree(ptr);
  1323. return result;
  1324. }
  1325. s8 wlc_lcnphy_get_current_tx_pwr_idx(struct brcms_phy *pi)
  1326. {
  1327. s8 index;
  1328. struct brcms_phy_lcnphy *pi_lcn = pi->u.pi_lcnphy;
  1329. if (txpwrctrl_off(pi))
  1330. index = pi_lcn->lcnphy_current_index;
  1331. else if (wlc_lcnphy_tssi_based_pwr_ctrl_enabled(pi))
  1332. index = (s8) (wlc_lcnphy_get_current_tx_pwr_idx_if_pwrctrl_on(
  1333. pi) / 2);
  1334. else
  1335. index = pi_lcn->lcnphy_current_index;
  1336. return index;
  1337. }
  1338. void wlc_lcnphy_crsuprs(struct brcms_phy *pi, int channel)
  1339. {
  1340. u16 afectrlovr, afectrlovrval;
  1341. afectrlovr = read_phy_reg(pi, 0x43b);
  1342. afectrlovrval = read_phy_reg(pi, 0x43c);
  1343. if (channel != 0) {
  1344. mod_phy_reg(pi, 0x43b, (0x1 << 1), (1) << 1);
  1345. mod_phy_reg(pi, 0x43c, (0x1 << 1), (0) << 1);
  1346. mod_phy_reg(pi, 0x43b, (0x1 << 4), (1) << 4);
  1347. mod_phy_reg(pi, 0x43c, (0x1 << 6), (0) << 6);
  1348. write_phy_reg(pi, 0x44b, 0xffff);
  1349. wlc_lcnphy_tx_pu(pi, 1);
  1350. mod_phy_reg(pi, 0x634, (0xff << 8), (0) << 8);
  1351. or_phy_reg(pi, 0x6da, 0x0080);
  1352. or_phy_reg(pi, 0x00a, 0x228);
  1353. } else {
  1354. and_phy_reg(pi, 0x00a, ~(0x228));
  1355. and_phy_reg(pi, 0x6da, 0xFF7F);
  1356. write_phy_reg(pi, 0x43b, afectrlovr);
  1357. write_phy_reg(pi, 0x43c, afectrlovrval);
  1358. }
  1359. }
  1360. static void wlc_lcnphy_toggle_afe_pwdn(struct brcms_phy *pi)
  1361. {
  1362. u16 save_AfeCtrlOvrVal, save_AfeCtrlOvr;
  1363. save_AfeCtrlOvrVal = read_phy_reg(pi, 0x43c);
  1364. save_AfeCtrlOvr = read_phy_reg(pi, 0x43b);
  1365. write_phy_reg(pi, 0x43c, save_AfeCtrlOvrVal | 0x1);
  1366. write_phy_reg(pi, 0x43b, save_AfeCtrlOvr | 0x1);
  1367. write_phy_reg(pi, 0x43c, save_AfeCtrlOvrVal & 0xfffe);
  1368. write_phy_reg(pi, 0x43b, save_AfeCtrlOvr & 0xfffe);
  1369. write_phy_reg(pi, 0x43c, save_AfeCtrlOvrVal);
  1370. write_phy_reg(pi, 0x43b, save_AfeCtrlOvr);
  1371. }
  1372. static void
  1373. wlc_lcnphy_txrx_spur_avoidance_mode(struct brcms_phy *pi, bool enable)
  1374. {
  1375. if (enable) {
  1376. write_phy_reg(pi, 0x942, 0x7);
  1377. write_phy_reg(pi, 0x93b, ((1 << 13) + 23));
  1378. write_phy_reg(pi, 0x93c, ((1 << 13) + 1989));
  1379. write_phy_reg(pi, 0x44a, 0x084);
  1380. write_phy_reg(pi, 0x44a, 0x080);
  1381. write_phy_reg(pi, 0x6d3, 0x2222);
  1382. write_phy_reg(pi, 0x6d3, 0x2220);
  1383. } else {
  1384. write_phy_reg(pi, 0x942, 0x0);
  1385. write_phy_reg(pi, 0x93b, ((0 << 13) + 23));
  1386. write_phy_reg(pi, 0x93c, ((0 << 13) + 1989));
  1387. }
  1388. wlapi_switch_macfreq(pi->sh->physhim, enable);
  1389. }
  1390. static void
  1391. wlc_lcnphy_set_chanspec_tweaks(struct brcms_phy *pi, u16 chanspec)
  1392. {
  1393. u8 channel = CHSPEC_CHANNEL(chanspec);
  1394. struct brcms_phy_lcnphy *pi_lcn = pi->u.pi_lcnphy;
  1395. if (channel == 14)
  1396. mod_phy_reg(pi, 0x448, (0x3 << 8), (2) << 8);
  1397. else
  1398. mod_phy_reg(pi, 0x448, (0x3 << 8), (1) << 8);
  1399. pi_lcn->lcnphy_bandedge_corr = 2;
  1400. if (channel == 1)
  1401. pi_lcn->lcnphy_bandedge_corr = 4;
  1402. if (channel == 1 || channel == 2 || channel == 3 ||
  1403. channel == 4 || channel == 9 ||
  1404. channel == 10 || channel == 11 || channel == 12) {
  1405. si_pmu_pllcontrol(pi->sh->sih, 0x2, 0xffffffff, 0x03000c04);
  1406. si_pmu_pllcontrol(pi->sh->sih, 0x3, 0xffffff, 0x0);
  1407. si_pmu_pllcontrol(pi->sh->sih, 0x4, 0xffffffff, 0x200005c0);
  1408. si_pmu_pllupd(pi->sh->sih);
  1409. write_phy_reg(pi, 0x942, 0);
  1410. wlc_lcnphy_txrx_spur_avoidance_mode(pi, false);
  1411. pi_lcn->lcnphy_spurmod = 0;
  1412. mod_phy_reg(pi, 0x424, (0xff << 8), (0x1b) << 8);
  1413. write_phy_reg(pi, 0x425, 0x5907);
  1414. } else {
  1415. si_pmu_pllcontrol(pi->sh->sih, 0x2, 0xffffffff, 0x03140c04);
  1416. si_pmu_pllcontrol(pi->sh->sih, 0x3, 0xffffff, 0x333333);
  1417. si_pmu_pllcontrol(pi->sh->sih, 0x4, 0xffffffff, 0x202c2820);
  1418. si_pmu_pllupd(pi->sh->sih);
  1419. write_phy_reg(pi, 0x942, 0);
  1420. wlc_lcnphy_txrx_spur_avoidance_mode(pi, true);
  1421. pi_lcn->lcnphy_spurmod = 0;
  1422. mod_phy_reg(pi, 0x424, (0xff << 8), (0x1f) << 8);
  1423. write_phy_reg(pi, 0x425, 0x590a);
  1424. }
  1425. or_phy_reg(pi, 0x44a, 0x44);
  1426. write_phy_reg(pi, 0x44a, 0x80);
  1427. }
  1428. static void
  1429. wlc_lcnphy_radio_2064_channel_tune_4313(struct brcms_phy *pi, u8 channel)
  1430. {
  1431. uint i;
  1432. const struct chan_info_2064_lcnphy *ci;
  1433. u8 rfpll_doubler = 0;
  1434. u8 pll_pwrup, pll_pwrup_ovr;
  1435. s32 qFxtal, qFref, qFvco, qFcal;
  1436. u8 d15, d16, f16, e44, e45;
  1437. u32 div_int, div_frac, fvco3, fpfd, fref3, fcal_div;
  1438. u16 loop_bw, d30, setCount;
  1439. u8 h29, h28_ten, e30, h30_ten, cp_current;
  1440. u16 g30, d28;
  1441. ci = &chan_info_2064_lcnphy[0];
  1442. rfpll_doubler = 1;
  1443. mod_radio_reg(pi, RADIO_2064_REG09D, 0x4, 0x1 << 2);
  1444. write_radio_reg(pi, RADIO_2064_REG09E, 0xf);
  1445. if (!rfpll_doubler) {
  1446. loop_bw = PLL_2064_LOOP_BW;
  1447. d30 = PLL_2064_D30;
  1448. } else {
  1449. loop_bw = PLL_2064_LOOP_BW_DOUBLER;
  1450. d30 = PLL_2064_D30_DOUBLER;
  1451. }
  1452. if (CHSPEC_IS2G(pi->radio_chanspec)) {
  1453. for (i = 0; i < ARRAY_SIZE(chan_info_2064_lcnphy); i++)
  1454. if (chan_info_2064_lcnphy[i].chan == channel)
  1455. break;
  1456. if (i >= ARRAY_SIZE(chan_info_2064_lcnphy))
  1457. return;
  1458. ci = &chan_info_2064_lcnphy[i];
  1459. }
  1460. write_radio_reg(pi, RADIO_2064_REG02A, ci->logen_buftune);
  1461. mod_radio_reg(pi, RADIO_2064_REG030, 0x3, ci->logen_rccr_tx);
  1462. mod_radio_reg(pi, RADIO_2064_REG091, 0x3, ci->txrf_mix_tune_ctrl);
  1463. mod_radio_reg(pi, RADIO_2064_REG038, 0xf, ci->pa_input_tune_g);
  1464. mod_radio_reg(pi, RADIO_2064_REG030, 0x3 << 2,
  1465. (ci->logen_rccr_rx) << 2);
  1466. mod_radio_reg(pi, RADIO_2064_REG05E, 0xf, ci->pa_rxrf_lna1_freq_tune);
  1467. mod_radio_reg(pi, RADIO_2064_REG05E, (0xf) << 4,
  1468. (ci->pa_rxrf_lna2_freq_tune) << 4);
  1469. write_radio_reg(pi, RADIO_2064_REG06C, ci->rxrf_rxrf_spare1);
  1470. pll_pwrup = (u8) read_radio_reg(pi, RADIO_2064_REG044);
  1471. pll_pwrup_ovr = (u8) read_radio_reg(pi, RADIO_2064_REG12B);
  1472. or_radio_reg(pi, RADIO_2064_REG044, 0x07);
  1473. or_radio_reg(pi, RADIO_2064_REG12B, (0x07) << 1);
  1474. e44 = 0;
  1475. e45 = 0;
  1476. fpfd = rfpll_doubler ? (pi->xtalfreq << 1) : (pi->xtalfreq);
  1477. if (pi->xtalfreq > 26000000)
  1478. e44 = 1;
  1479. if (pi->xtalfreq > 52000000)
  1480. e45 = 1;
  1481. if (e44 == 0)
  1482. fcal_div = 1;
  1483. else if (e45 == 0)
  1484. fcal_div = 2;
  1485. else
  1486. fcal_div = 4;
  1487. fvco3 = (ci->freq * 3);
  1488. fref3 = 2 * fpfd;
  1489. qFxtal = wlc_lcnphy_qdiv_roundup(pi->xtalfreq, PLL_2064_MHZ, 16);
  1490. qFref = wlc_lcnphy_qdiv_roundup(fpfd, PLL_2064_MHZ, 16);
  1491. qFcal = pi->xtalfreq * fcal_div / PLL_2064_MHZ;
  1492. qFvco = wlc_lcnphy_qdiv_roundup(fvco3, 2, 16);
  1493. write_radio_reg(pi, RADIO_2064_REG04F, 0x02);
  1494. d15 = (pi->xtalfreq * fcal_div * 4 / 5) / PLL_2064_MHZ - 1;
  1495. write_radio_reg(pi, RADIO_2064_REG052, (0x07 & (d15 >> 2)));
  1496. write_radio_reg(pi, RADIO_2064_REG053, (d15 & 0x3) << 5);
  1497. d16 = (qFcal * 8 / (d15 + 1)) - 1;
  1498. write_radio_reg(pi, RADIO_2064_REG051, d16);
  1499. f16 = ((d16 + 1) * (d15 + 1)) / qFcal;
  1500. setCount = f16 * 3 * (ci->freq) / 32 - 1;
  1501. mod_radio_reg(pi, RADIO_2064_REG053, (0x0f << 0),
  1502. (u8) (setCount >> 8));
  1503. or_radio_reg(pi, RADIO_2064_REG053, 0x10);
  1504. write_radio_reg(pi, RADIO_2064_REG054, (u8) (setCount & 0xff));
  1505. div_int = ((fvco3 * (PLL_2064_MHZ >> 4)) / fref3) << 4;
  1506. div_frac = ((fvco3 * (PLL_2064_MHZ >> 4)) % fref3) << 4;
  1507. while (div_frac >= fref3) {
  1508. div_int++;
  1509. div_frac -= fref3;
  1510. }
  1511. div_frac = wlc_lcnphy_qdiv_roundup(div_frac, fref3, 20);
  1512. mod_radio_reg(pi, RADIO_2064_REG045, (0x1f << 0),
  1513. (u8) (div_int >> 4));
  1514. mod_radio_reg(pi, RADIO_2064_REG046, (0x1f << 4),
  1515. (u8) (div_int << 4));
  1516. mod_radio_reg(pi, RADIO_2064_REG046, (0x0f << 0),
  1517. (u8) (div_frac >> 16));
  1518. write_radio_reg(pi, RADIO_2064_REG047, (u8) (div_frac >> 8) & 0xff);
  1519. write_radio_reg(pi, RADIO_2064_REG048, (u8) div_frac & 0xff);
  1520. write_radio_reg(pi, RADIO_2064_REG040, 0xfb);
  1521. write_radio_reg(pi, RADIO_2064_REG041, 0x9A);
  1522. write_radio_reg(pi, RADIO_2064_REG042, 0xA3);
  1523. write_radio_reg(pi, RADIO_2064_REG043, 0x0C);
  1524. h29 = LCN_BW_LMT / loop_bw;
  1525. d28 = (((PLL_2064_HIGH_END_KVCO - PLL_2064_LOW_END_KVCO) *
  1526. (fvco3 / 2 - PLL_2064_LOW_END_VCO)) /
  1527. (PLL_2064_HIGH_END_VCO - PLL_2064_LOW_END_VCO))
  1528. + PLL_2064_LOW_END_KVCO;
  1529. h28_ten = (d28 * 10) / LCN_VCO_DIV;
  1530. e30 = (d30 - LCN_OFFSET) / LCN_FACT;
  1531. g30 = LCN_OFFSET + (e30 * LCN_FACT);
  1532. h30_ten = (g30 * 10) / LCN_CUR_DIV;
  1533. cp_current = ((LCN_CUR_LMT * h29 * LCN_MULT * 100) / h28_ten) / h30_ten;
  1534. mod_radio_reg(pi, RADIO_2064_REG03C, 0x3f, cp_current);
  1535. if (channel >= 1 && channel <= 5)
  1536. write_radio_reg(pi, RADIO_2064_REG03C, 0x8);
  1537. else
  1538. write_radio_reg(pi, RADIO_2064_REG03C, 0x7);
  1539. write_radio_reg(pi, RADIO_2064_REG03D, 0x3);
  1540. mod_radio_reg(pi, RADIO_2064_REG044, 0x0c, 0x0c);
  1541. udelay(1);
  1542. wlc_2064_vco_cal(pi);
  1543. write_radio_reg(pi, RADIO_2064_REG044, pll_pwrup);
  1544. write_radio_reg(pi, RADIO_2064_REG12B, pll_pwrup_ovr);
  1545. if (LCNREV_IS(pi->pubpi.phy_rev, 1)) {
  1546. write_radio_reg(pi, RADIO_2064_REG038, 3);
  1547. write_radio_reg(pi, RADIO_2064_REG091, 7);
  1548. }
  1549. }
  1550. static int
  1551. wlc_lcnphy_load_tx_iir_filter(struct brcms_phy *pi, bool is_ofdm, s16 filt_type)
  1552. {
  1553. s16 filt_index = -1;
  1554. int j;
  1555. u16 addr[] = {
  1556. 0x910,
  1557. 0x91e,
  1558. 0x91f,
  1559. 0x924,
  1560. 0x925,
  1561. 0x926,
  1562. 0x920,
  1563. 0x921,
  1564. 0x927,
  1565. 0x928,
  1566. 0x929,
  1567. 0x922,
  1568. 0x923,
  1569. 0x930,
  1570. 0x931,
  1571. 0x932
  1572. };
  1573. u16 addr_ofdm[] = {
  1574. 0x90f,
  1575. 0x900,
  1576. 0x901,
  1577. 0x906,
  1578. 0x907,
  1579. 0x908,
  1580. 0x902,
  1581. 0x903,
  1582. 0x909,
  1583. 0x90a,
  1584. 0x90b,
  1585. 0x904,
  1586. 0x905,
  1587. 0x90c,
  1588. 0x90d,
  1589. 0x90e
  1590. };
  1591. if (!is_ofdm) {
  1592. for (j = 0; j < LCNPHY_NUM_TX_DIG_FILTERS_CCK; j++) {
  1593. if (filt_type == LCNPHY_txdigfiltcoeffs_cck[j][0]) {
  1594. filt_index = (s16) j;
  1595. break;
  1596. }
  1597. }
  1598. if (filt_index != -1) {
  1599. for (j = 0; j < LCNPHY_NUM_DIG_FILT_COEFFS; j++)
  1600. write_phy_reg(pi, addr[j],
  1601. LCNPHY_txdigfiltcoeffs_cck
  1602. [filt_index][j + 1]);
  1603. }
  1604. } else {
  1605. for (j = 0; j < LCNPHY_NUM_TX_DIG_FILTERS_OFDM; j++) {
  1606. if (filt_type == LCNPHY_txdigfiltcoeffs_ofdm[j][0]) {
  1607. filt_index = (s16) j;
  1608. break;
  1609. }
  1610. }
  1611. if (filt_index != -1) {
  1612. for (j = 0; j < LCNPHY_NUM_DIG_FILT_COEFFS; j++)
  1613. write_phy_reg(pi, addr_ofdm[j],
  1614. LCNPHY_txdigfiltcoeffs_ofdm
  1615. [filt_index][j + 1]);
  1616. }
  1617. }
  1618. return (filt_index != -1) ? 0 : -1;
  1619. }
  1620. void wlc_phy_chanspec_set_lcnphy(struct brcms_phy *pi, u16 chanspec)
  1621. {
  1622. u8 channel = CHSPEC_CHANNEL(chanspec);
  1623. wlc_phy_chanspec_radio_set((struct brcms_phy_pub *) pi, chanspec);
  1624. wlc_lcnphy_set_chanspec_tweaks(pi, pi->radio_chanspec);
  1625. or_phy_reg(pi, 0x44a, 0x44);
  1626. write_phy_reg(pi, 0x44a, 0x80);
  1627. wlc_lcnphy_radio_2064_channel_tune_4313(pi, channel);
  1628. udelay(1000);
  1629. wlc_lcnphy_toggle_afe_pwdn(pi);
  1630. write_phy_reg(pi, 0x657, lcnphy_sfo_cfg[channel - 1].ptcentreTs20);
  1631. write_phy_reg(pi, 0x658, lcnphy_sfo_cfg[channel - 1].ptcentreFactor);
  1632. if (CHSPEC_CHANNEL(pi->radio_chanspec) == 14) {
  1633. mod_phy_reg(pi, 0x448, (0x3 << 8), (2) << 8);
  1634. wlc_lcnphy_load_tx_iir_filter(pi, false, 3);
  1635. } else {
  1636. mod_phy_reg(pi, 0x448, (0x3 << 8), (1) << 8);
  1637. wlc_lcnphy_load_tx_iir_filter(pi, false, 2);
  1638. }
  1639. wlc_lcnphy_load_tx_iir_filter(pi, true, 0);
  1640. mod_phy_reg(pi, 0x4eb, (0x7 << 3), (1) << 3);
  1641. }
  1642. static u16 wlc_lcnphy_get_pa_gain(struct brcms_phy *pi)
  1643. {
  1644. u16 pa_gain;
  1645. pa_gain = (read_phy_reg(pi, 0x4fb) &
  1646. LCNPHY_txgainctrlovrval1_pagain_ovr_val1_MASK) >>
  1647. LCNPHY_txgainctrlovrval1_pagain_ovr_val1_SHIFT;
  1648. return pa_gain;
  1649. }
  1650. static void wlc_lcnphy_set_tx_gain(struct brcms_phy *pi,
  1651. struct lcnphy_txgains *target_gains)
  1652. {
  1653. u16 pa_gain = wlc_lcnphy_get_pa_gain(pi);
  1654. mod_phy_reg(
  1655. pi, 0x4b5,
  1656. (0xffff << 0),
  1657. ((target_gains->gm_gain) |
  1658. (target_gains->pga_gain << 8)) <<
  1659. 0);
  1660. mod_phy_reg(pi, 0x4fb,
  1661. (0x7fff << 0),
  1662. ((target_gains->pad_gain) | (pa_gain << 8)) << 0);
  1663. mod_phy_reg(
  1664. pi, 0x4fc,
  1665. (0xffff << 0),
  1666. ((target_gains->gm_gain) |
  1667. (target_gains->pga_gain << 8)) <<
  1668. 0);
  1669. mod_phy_reg(pi, 0x4fd,
  1670. (0x7fff << 0),
  1671. ((target_gains->pad_gain) | (pa_gain << 8)) << 0);
  1672. wlc_lcnphy_set_dac_gain(pi, target_gains->dac_gain);
  1673. wlc_lcnphy_enable_tx_gain_override(pi);
  1674. }
  1675. static void wlc_lcnphy_set_bbmult(struct brcms_phy *pi, u8 m0)
  1676. {
  1677. u16 m0m1 = (u16) m0 << 8;
  1678. struct phytbl_info tab;
  1679. tab.tbl_ptr = &m0m1;
  1680. tab.tbl_len = 1;
  1681. tab.tbl_id = LCNPHY_TBL_ID_IQLOCAL;
  1682. tab.tbl_offset = 87;
  1683. tab.tbl_width = 16;
  1684. wlc_lcnphy_write_table(pi, &tab);
  1685. }
  1686. static void wlc_lcnphy_clear_tx_power_offsets(struct brcms_phy *pi)
  1687. {
  1688. u32 data_buf[64];
  1689. struct phytbl_info tab;
  1690. memset(data_buf, 0, sizeof(data_buf));
  1691. tab.tbl_id = LCNPHY_TBL_ID_TXPWRCTL;
  1692. tab.tbl_width = 32;
  1693. tab.tbl_ptr = data_buf;
  1694. if (!wlc_lcnphy_tempsense_based_pwr_ctrl_enabled(pi)) {
  1695. tab.tbl_len = 30;
  1696. tab.tbl_offset = LCNPHY_TX_PWR_CTRL_RATE_OFFSET;
  1697. wlc_lcnphy_write_table(pi, &tab);
  1698. }
  1699. tab.tbl_len = 64;
  1700. tab.tbl_offset = LCNPHY_TX_PWR_CTRL_MAC_OFFSET;
  1701. wlc_lcnphy_write_table(pi, &tab);
  1702. }
  1703. enum lcnphy_tssi_mode {
  1704. LCNPHY_TSSI_PRE_PA,
  1705. LCNPHY_TSSI_POST_PA,
  1706. LCNPHY_TSSI_EXT
  1707. };
  1708. static void
  1709. wlc_lcnphy_set_tssi_mux(struct brcms_phy *pi, enum lcnphy_tssi_mode pos)
  1710. {
  1711. mod_phy_reg(pi, 0x4d7, (0x1 << 0), (0x1) << 0);
  1712. mod_phy_reg(pi, 0x4d7, (0x1 << 6), (1) << 6);
  1713. if (LCNPHY_TSSI_POST_PA == pos) {
  1714. mod_phy_reg(pi, 0x4d9, (0x1 << 2), (0) << 2);
  1715. mod_phy_reg(pi, 0x4d9, (0x1 << 3), (1) << 3);
  1716. if (LCNREV_IS(pi->pubpi.phy_rev, 2)) {
  1717. mod_radio_reg(pi, RADIO_2064_REG086, 0x4, 0x4);
  1718. } else {
  1719. mod_radio_reg(pi, RADIO_2064_REG03A, 1, 0x1);
  1720. mod_radio_reg(pi, RADIO_2064_REG11A, 0x8, 0x8);
  1721. }
  1722. } else {
  1723. mod_phy_reg(pi, 0x4d9, (0x1 << 2), (0x1) << 2);
  1724. mod_phy_reg(pi, 0x4d9, (0x1 << 3), (0) << 3);
  1725. if (LCNREV_IS(pi->pubpi.phy_rev, 2)) {
  1726. mod_radio_reg(pi, RADIO_2064_REG086, 0x4, 0x4);
  1727. } else {
  1728. mod_radio_reg(pi, RADIO_2064_REG03A, 1, 0);
  1729. mod_radio_reg(pi, RADIO_2064_REG11A, 0x8, 0x8);
  1730. }
  1731. }
  1732. mod_phy_reg(pi, 0x637, (0x3 << 14), (0) << 14);
  1733. if (LCNPHY_TSSI_EXT == pos) {
  1734. write_radio_reg(pi, RADIO_2064_REG07F, 1);
  1735. mod_radio_reg(pi, RADIO_2064_REG005, 0x7, 0x2);
  1736. mod_radio_reg(pi, RADIO_2064_REG112, 0x80, 0x1 << 7);
  1737. mod_radio_reg(pi, RADIO_2064_REG028, 0x1f, 0x3);
  1738. }
  1739. }
  1740. static u16 wlc_lcnphy_rfseq_tbl_adc_pwrup(struct brcms_phy *pi)
  1741. {
  1742. u16 N1, N2, N3, N4, N5, N6, N;
  1743. N1 = ((read_phy_reg(pi, 0x4a5) & (0xff << 0))
  1744. >> 0);
  1745. N2 = 1 << ((read_phy_reg(pi, 0x4a5) & (0x7 << 12))
  1746. >> 12);
  1747. N3 = ((read_phy_reg(pi, 0x40d) & (0xff << 0))
  1748. >> 0);
  1749. N4 = 1 << ((read_phy_reg(pi, 0x40d) & (0x7 << 8))
  1750. >> 8);
  1751. N5 = ((read_phy_reg(pi, 0x4a2) & (0xff << 0))
  1752. >> 0);
  1753. N6 = 1 << ((read_phy_reg(pi, 0x4a2) & (0x7 << 8))
  1754. >> 8);
  1755. N = 2 * (N1 + N2 + N3 + N4 + 2 * (N5 + N6)) + 80;
  1756. if (N < 1600)
  1757. N = 1600;
  1758. return N;
  1759. }
  1760. static void wlc_lcnphy_pwrctrl_rssiparams(struct brcms_phy *pi)
  1761. {
  1762. u16 auxpga_vmid, auxpga_vmid_temp, auxpga_gain_temp;
  1763. struct brcms_phy_lcnphy *pi_lcn = pi->u.pi_lcnphy;
  1764. auxpga_vmid = (2 << 8) |
  1765. (pi_lcn->lcnphy_rssi_vc << 4) | pi_lcn->lcnphy_rssi_vf;
  1766. auxpga_vmid_temp = (2 << 8) | (8 << 4) | 4;
  1767. auxpga_gain_temp = 2;
  1768. mod_phy_reg(pi, 0x4d8, (0x1 << 0), (0) << 0);
  1769. mod_phy_reg(pi, 0x4d8, (0x1 << 1), (0) << 1);
  1770. mod_phy_reg(pi, 0x4d7, (0x1 << 3), (0) << 3);
  1771. mod_phy_reg(pi, 0x4db,
  1772. (0x3ff << 0) |
  1773. (0x7 << 12),
  1774. (auxpga_vmid << 0) | (pi_lcn->lcnphy_rssi_gs << 12));
  1775. mod_phy_reg(pi, 0x4dc,
  1776. (0x3ff << 0) |
  1777. (0x7 << 12),
  1778. (auxpga_vmid << 0) | (pi_lcn->lcnphy_rssi_gs << 12));
  1779. mod_phy_reg(pi, 0x40a,
  1780. (0x3ff << 0) |
  1781. (0x7 << 12),
  1782. (auxpga_vmid << 0) | (pi_lcn->lcnphy_rssi_gs << 12));
  1783. mod_phy_reg(pi, 0x40b,
  1784. (0x3ff << 0) |
  1785. (0x7 << 12),
  1786. (auxpga_vmid_temp << 0) | (auxpga_gain_temp << 12));
  1787. mod_phy_reg(pi, 0x40c,
  1788. (0x3ff << 0) |
  1789. (0x7 << 12),
  1790. (auxpga_vmid_temp << 0) | (auxpga_gain_temp << 12));
  1791. mod_radio_reg(pi, RADIO_2064_REG082, (1 << 5), (1 << 5));
  1792. }
  1793. static void wlc_lcnphy_tssi_setup(struct brcms_phy *pi)
  1794. {
  1795. struct phytbl_info tab;
  1796. u32 rfseq, ind;
  1797. tab.tbl_id = LCNPHY_TBL_ID_TXPWRCTL;
  1798. tab.tbl_width = 32;
  1799. tab.tbl_ptr = &ind;
  1800. tab.tbl_len = 1;
  1801. tab.tbl_offset = 0;
  1802. for (ind = 0; ind < 128; ind++) {
  1803. wlc_lcnphy_write_table(pi, &tab);
  1804. tab.tbl_offset++;
  1805. }
  1806. tab.tbl_offset = 704;
  1807. for (ind = 0; ind < 128; ind++) {
  1808. wlc_lcnphy_write_table(pi, &tab);
  1809. tab.tbl_offset++;
  1810. }
  1811. mod_phy_reg(pi, 0x503, (0x1 << 0), (0) << 0);
  1812. mod_phy_reg(pi, 0x503, (0x1 << 2), (0) << 2);
  1813. mod_phy_reg(pi, 0x503, (0x1 << 4), (1) << 4);
  1814. wlc_lcnphy_set_tssi_mux(pi, LCNPHY_TSSI_EXT);
  1815. mod_phy_reg(pi, 0x4a4, (0x1 << 14), (0) << 14);
  1816. mod_phy_reg(pi, 0x4a4, (0x1 << 15), (1) << 15);
  1817. mod_phy_reg(pi, 0x4d0, (0x1 << 5), (0) << 5);
  1818. mod_phy_reg(pi, 0x4a4, (0x1ff << 0), (0) << 0);
  1819. mod_phy_reg(pi, 0x4a5, (0xff << 0), (255) << 0);
  1820. mod_phy_reg(pi, 0x4a5, (0x7 << 12), (5) << 12);
  1821. mod_phy_reg(pi, 0x4a5, (0x7 << 8), (0) << 8);
  1822. mod_phy_reg(pi, 0x40d, (0xff << 0), (64) << 0);
  1823. mod_phy_reg(pi, 0x40d, (0x7 << 8), (4) << 8);
  1824. mod_phy_reg(pi, 0x4a2, (0xff << 0), (64) << 0);
  1825. mod_phy_reg(pi, 0x4a2, (0x7 << 8), (4) << 8);
  1826. mod_phy_reg(pi, 0x4d0, (0x1ff << 6), (0) << 6);
  1827. mod_phy_reg(pi, 0x4a8, (0xff << 0), (0x1) << 0);
  1828. wlc_lcnphy_clear_tx_power_offsets(pi);
  1829. mod_phy_reg(pi, 0x4a6, (0x1 << 15), (1) << 15);
  1830. mod_phy_reg(pi, 0x4a6, (0x1ff << 0), (0xff) << 0);
  1831. mod_phy_reg(pi, 0x49a, (0x1ff << 0), (0xff) << 0);
  1832. if (LCNREV_IS(pi->pubpi.phy_rev, 2)) {
  1833. mod_radio_reg(pi, RADIO_2064_REG028, 0xf, 0xe);
  1834. mod_radio_reg(pi, RADIO_2064_REG086, 0x4, 0x4);
  1835. } else {
  1836. mod_radio_reg(pi, RADIO_2064_REG03A, 0x1, 1);
  1837. mod_radio_reg(pi, RADIO_2064_REG11A, 0x8, 1 << 3);
  1838. }
  1839. write_radio_reg(pi, RADIO_2064_REG025, 0xc);
  1840. if (LCNREV_IS(pi->pubpi.phy_rev, 2)) {
  1841. mod_radio_reg(pi, RADIO_2064_REG03A, 0x1, 1);
  1842. } else {
  1843. if (CHSPEC_IS2G(pi->radio_chanspec))
  1844. mod_radio_reg(pi, RADIO_2064_REG03A, 0x2, 1 << 1);
  1845. else
  1846. mod_radio_reg(pi, RADIO_2064_REG03A, 0x2, 0 << 1);
  1847. }
  1848. if (LCNREV_IS(pi->pubpi.phy_rev, 2))
  1849. mod_radio_reg(pi, RADIO_2064_REG03A, 0x2, 1 << 1);
  1850. else
  1851. mod_radio_reg(pi, RADIO_2064_REG03A, 0x4, 1 << 2);
  1852. mod_radio_reg(pi, RADIO_2064_REG11A, 0x1, 1 << 0);
  1853. mod_radio_reg(pi, RADIO_2064_REG005, 0x8, 1 << 3);
  1854. if (!wlc_lcnphy_tempsense_based_pwr_ctrl_enabled(pi))
  1855. mod_phy_reg(pi, 0x4d7,
  1856. (0x1 << 3) | (0x7 << 12), 0 << 3 | 2 << 12);
  1857. rfseq = wlc_lcnphy_rfseq_tbl_adc_pwrup(pi);
  1858. tab.tbl_id = LCNPHY_TBL_ID_RFSEQ;
  1859. tab.tbl_width = 16;
  1860. tab.tbl_ptr = &rfseq;
  1861. tab.tbl_len = 1;
  1862. tab.tbl_offset = 6;
  1863. wlc_lcnphy_write_table(pi, &tab);
  1864. mod_phy_reg(pi, 0x938, (0x1 << 2), (1) << 2);
  1865. mod_phy_reg(pi, 0x939, (0x1 << 2), (1) << 2);
  1866. mod_phy_reg(pi, 0x4a4, (0x1 << 12), (1) << 12);
  1867. mod_phy_reg(pi, 0x4d7, (0x1 << 2), (1) << 2);
  1868. mod_phy_reg(pi, 0x4d7, (0xf << 8), (0) << 8);
  1869. wlc_lcnphy_pwrctrl_rssiparams(pi);
  1870. }
  1871. void wlc_lcnphy_tx_pwr_update_npt(struct brcms_phy *pi)
  1872. {
  1873. u16 tx_cnt, tx_total, npt;
  1874. struct brcms_phy_lcnphy *pi_lcn = pi->u.pi_lcnphy;
  1875. tx_total = wlc_lcnphy_total_tx_frames(pi);
  1876. tx_cnt = tx_total - pi_lcn->lcnphy_tssi_tx_cnt;
  1877. npt = wlc_lcnphy_get_tx_pwr_npt(pi);
  1878. if (tx_cnt > (1 << npt)) {
  1879. pi_lcn->lcnphy_tssi_tx_cnt = tx_total;
  1880. pi_lcn->lcnphy_tssi_idx = wlc_lcnphy_get_current_tx_pwr_idx(pi);
  1881. pi_lcn->lcnphy_tssi_npt = npt;
  1882. }
  1883. }
  1884. s32 wlc_lcnphy_tssi2dbm(s32 tssi, s32 a1, s32 b0, s32 b1)
  1885. {
  1886. s32 a, b, p;
  1887. a = 32768 + (a1 * tssi);
  1888. b = (1024 * b0) + (64 * b1 * tssi);
  1889. p = ((2 * b) + a) / (2 * a);
  1890. return p;
  1891. }
  1892. static void wlc_lcnphy_txpower_reset_npt(struct brcms_phy *pi)
  1893. {
  1894. struct brcms_phy_lcnphy *pi_lcn = pi->u.pi_lcnphy;
  1895. if (wlc_lcnphy_tempsense_based_pwr_ctrl_enabled(pi))
  1896. return;
  1897. pi_lcn->lcnphy_tssi_idx = LCNPHY_TX_PWR_CTRL_START_INDEX_2G_4313;
  1898. pi_lcn->lcnphy_tssi_npt = LCNPHY_TX_PWR_CTRL_START_NPT;
  1899. }
  1900. void wlc_lcnphy_txpower_recalc_target(struct brcms_phy *pi)
  1901. {
  1902. struct phytbl_info tab;
  1903. u32 rate_table[BRCMS_NUM_RATES_CCK + BRCMS_NUM_RATES_OFDM +
  1904. BRCMS_NUM_RATES_MCS_1_STREAM];
  1905. uint i, j;
  1906. if (wlc_lcnphy_tempsense_based_pwr_ctrl_enabled(pi))
  1907. return;
  1908. for (i = 0, j = 0; i < ARRAY_SIZE(rate_table); i++, j++) {
  1909. if (i == BRCMS_NUM_RATES_CCK + BRCMS_NUM_RATES_OFDM)
  1910. j = TXP_FIRST_MCS_20_SISO;
  1911. rate_table[i] = (u32) ((s32) (-pi->tx_power_offset[j]));
  1912. }
  1913. tab.tbl_id = LCNPHY_TBL_ID_TXPWRCTL;
  1914. tab.tbl_width = 32;
  1915. tab.tbl_len = ARRAY_SIZE(rate_table);
  1916. tab.tbl_ptr = rate_table;
  1917. tab.tbl_offset = LCNPHY_TX_PWR_CTRL_RATE_OFFSET;
  1918. wlc_lcnphy_write_table(pi, &tab);
  1919. if (wlc_lcnphy_get_target_tx_pwr(pi) != pi->tx_power_min) {
  1920. wlc_lcnphy_set_target_tx_pwr(pi, pi->tx_power_min);
  1921. wlc_lcnphy_txpower_reset_npt(pi);
  1922. }
  1923. }
  1924. static void wlc_lcnphy_set_tx_pwr_soft_ctrl(struct brcms_phy *pi, s8 index)
  1925. {
  1926. u32 cck_offset[4] = { 22, 22, 22, 22 };
  1927. u32 ofdm_offset, reg_offset_cck;
  1928. int i;
  1929. u16 index2;
  1930. struct phytbl_info tab;
  1931. if (wlc_lcnphy_tssi_based_pwr_ctrl_enabled(pi))
  1932. return;
  1933. mod_phy_reg(pi, 0x4a4, (0x1 << 14), (0x1) << 14);
  1934. mod_phy_reg(pi, 0x4a4, (0x1 << 14), (0x0) << 14);
  1935. or_phy_reg(pi, 0x6da, 0x0040);
  1936. reg_offset_cck = 0;
  1937. for (i = 0; i < 4; i++)
  1938. cck_offset[i] -= reg_offset_cck;
  1939. tab.tbl_id = LCNPHY_TBL_ID_TXPWRCTL;
  1940. tab.tbl_width = 32;
  1941. tab.tbl_len = 4;
  1942. tab.tbl_ptr = cck_offset;
  1943. tab.tbl_offset = LCNPHY_TX_PWR_CTRL_RATE_OFFSET;
  1944. wlc_lcnphy_write_table(pi, &tab);
  1945. ofdm_offset = 0;
  1946. tab.tbl_len = 1;
  1947. tab.tbl_ptr = &ofdm_offset;
  1948. for (i = 836; i < 862; i++) {
  1949. tab.tbl_offset = i;
  1950. wlc_lcnphy_write_table(pi, &tab);
  1951. }
  1952. mod_phy_reg(pi, 0x4a4, (0x1 << 15), (0x1) << 15);
  1953. mod_phy_reg(pi, 0x4a4, (0x1 << 14), (0x1) << 14);
  1954. mod_phy_reg(pi, 0x4a4, (0x1 << 13), (0x1) << 13);
  1955. mod_phy_reg(pi, 0x4b0, (0x1 << 7), (0) << 7);
  1956. mod_phy_reg(pi, 0x43b, (0x1 << 6), (0) << 6);
  1957. mod_phy_reg(pi, 0x4a9, (0x1 << 15), (1) << 15);
  1958. index2 = (u16) (index * 2);
  1959. mod_phy_reg(pi, 0x4a9, (0x1ff << 0), (index2) << 0);
  1960. mod_phy_reg(pi, 0x6a3, (0x1 << 4), (0) << 4);
  1961. }
  1962. static s8 wlc_lcnphy_tempcompensated_txpwrctrl(struct brcms_phy *pi)
  1963. {
  1964. s8 index, delta_brd, delta_temp, new_index, tempcorrx;
  1965. s16 manp, meas_temp, temp_diff;
  1966. bool neg = 0;
  1967. u16 temp;
  1968. struct brcms_phy_lcnphy *pi_lcn = pi->u.pi_lcnphy;
  1969. if (wlc_lcnphy_tssi_based_pwr_ctrl_enabled(pi))
  1970. return pi_lcn->lcnphy_current_index;
  1971. index = FIXED_TXPWR;
  1972. if (pi_lcn->lcnphy_tempsense_slope == 0)
  1973. return index;
  1974. temp = (u16) wlc_lcnphy_tempsense(pi, 0);
  1975. meas_temp = LCNPHY_TEMPSENSE(temp);
  1976. if (pi->tx_power_min != 0)
  1977. delta_brd = (pi_lcn->lcnphy_measPower - pi->tx_power_min);
  1978. else
  1979. delta_brd = 0;
  1980. manp = LCNPHY_TEMPSENSE(pi_lcn->lcnphy_rawtempsense);
  1981. temp_diff = manp - meas_temp;
  1982. if (temp_diff < 0) {
  1983. neg = 1;
  1984. temp_diff = -temp_diff;
  1985. }
  1986. delta_temp = (s8) wlc_lcnphy_qdiv_roundup((u32) (temp_diff * 192),
  1987. (u32) (pi_lcn->
  1988. lcnphy_tempsense_slope
  1989. * 10), 0);
  1990. if (neg)
  1991. delta_temp = -delta_temp;
  1992. if (pi_lcn->lcnphy_tempsense_option == 3
  1993. && LCNREV_IS(pi->pubpi.phy_rev, 0))
  1994. delta_temp = 0;
  1995. if (pi_lcn->lcnphy_tempcorrx > 31)
  1996. tempcorrx = (s8) (pi_lcn->lcnphy_tempcorrx - 64);
  1997. else
  1998. tempcorrx = (s8) pi_lcn->lcnphy_tempcorrx;
  1999. if (LCNREV_IS(pi->pubpi.phy_rev, 1))
  2000. tempcorrx = 4;
  2001. new_index =
  2002. index + delta_brd + delta_temp - pi_lcn->lcnphy_bandedge_corr;
  2003. new_index += tempcorrx;
  2004. if (LCNREV_IS(pi->pubpi.phy_rev, 1))
  2005. index = 127;
  2006. if (new_index < 0 || new_index > 126)
  2007. return index;
  2008. return new_index;
  2009. }
  2010. static u16 wlc_lcnphy_set_tx_pwr_ctrl_mode(struct brcms_phy *pi, u16 mode)
  2011. {
  2012. u16 current_mode = mode;
  2013. if (wlc_lcnphy_tempsense_based_pwr_ctrl_enabled(pi) &&
  2014. mode == LCNPHY_TX_PWR_CTRL_HW)
  2015. current_mode = LCNPHY_TX_PWR_CTRL_TEMPBASED;
  2016. if (wlc_lcnphy_tssi_based_pwr_ctrl_enabled(pi) &&
  2017. mode == LCNPHY_TX_PWR_CTRL_TEMPBASED)
  2018. current_mode = LCNPHY_TX_PWR_CTRL_HW;
  2019. return current_mode;
  2020. }
  2021. void wlc_lcnphy_set_tx_pwr_ctrl(struct brcms_phy *pi, u16 mode)
  2022. {
  2023. u16 old_mode = wlc_lcnphy_get_tx_pwr_ctrl(pi);
  2024. s8 index;
  2025. struct brcms_phy_lcnphy *pi_lcn = pi->u.pi_lcnphy;
  2026. mode = wlc_lcnphy_set_tx_pwr_ctrl_mode(pi, mode);
  2027. old_mode = wlc_lcnphy_set_tx_pwr_ctrl_mode(pi, old_mode);
  2028. mod_phy_reg(pi, 0x6da, (0x1 << 6),
  2029. ((LCNPHY_TX_PWR_CTRL_HW == mode) ? 1 : 0) << 6);
  2030. mod_phy_reg(pi, 0x6a3, (0x1 << 4),
  2031. ((LCNPHY_TX_PWR_CTRL_HW == mode) ? 0 : 1) << 4);
  2032. if (old_mode != mode) {
  2033. if (LCNPHY_TX_PWR_CTRL_HW == old_mode) {
  2034. wlc_lcnphy_tx_pwr_update_npt(pi);
  2035. wlc_lcnphy_clear_tx_power_offsets(pi);
  2036. }
  2037. if (LCNPHY_TX_PWR_CTRL_HW == mode) {
  2038. wlc_lcnphy_txpower_recalc_target(pi);
  2039. wlc_lcnphy_set_start_tx_pwr_idx(pi,
  2040. pi_lcn->
  2041. lcnphy_tssi_idx);
  2042. wlc_lcnphy_set_tx_pwr_npt(pi, pi_lcn->lcnphy_tssi_npt);
  2043. mod_radio_reg(pi, RADIO_2064_REG11F, 0x4, 0);
  2044. pi_lcn->lcnphy_tssi_tx_cnt =
  2045. wlc_lcnphy_total_tx_frames(pi);
  2046. wlc_lcnphy_disable_tx_gain_override(pi);
  2047. pi_lcn->lcnphy_tx_power_idx_override = -1;
  2048. } else
  2049. wlc_lcnphy_enable_tx_gain_override(pi);
  2050. mod_phy_reg(pi, 0x4a4,
  2051. ((0x1 << 15) | (0x1 << 14) | (0x1 << 13)), mode);
  2052. if (mode == LCNPHY_TX_PWR_CTRL_TEMPBASED) {
  2053. index = wlc_lcnphy_tempcompensated_txpwrctrl(pi);
  2054. wlc_lcnphy_set_tx_pwr_soft_ctrl(pi, index);
  2055. pi_lcn->lcnphy_current_index = (s8)
  2056. ((read_phy_reg(pi,
  2057. 0x4a9) &
  2058. 0xFF) / 2);
  2059. }
  2060. }
  2061. }
  2062. static void
  2063. wlc_lcnphy_tx_iqlo_loopback(struct brcms_phy *pi, u16 *values_to_save)
  2064. {
  2065. u16 vmid;
  2066. int i;
  2067. for (i = 0; i < 20; i++)
  2068. values_to_save[i] =
  2069. read_radio_reg(pi, iqlo_loopback_rf_regs[i]);
  2070. mod_phy_reg(pi, 0x44c, (0x1 << 12), 1 << 12);
  2071. mod_phy_reg(pi, 0x44d, (0x1 << 14), 1 << 14);
  2072. mod_phy_reg(pi, 0x44c, (0x1 << 11), 1 << 11);
  2073. mod_phy_reg(pi, 0x44d, (0x1 << 13), 0 << 13);
  2074. mod_phy_reg(pi, 0x43b, (0x1 << 1), 1 << 1);
  2075. mod_phy_reg(pi, 0x43c, (0x1 << 1), 0 << 1);
  2076. mod_phy_reg(pi, 0x43b, (0x1 << 0), 1 << 0);
  2077. mod_phy_reg(pi, 0x43c, (0x1 << 0), 0 << 0);
  2078. if (LCNREV_IS(pi->pubpi.phy_rev, 2))
  2079. and_radio_reg(pi, RADIO_2064_REG03A, 0xFD);
  2080. else
  2081. and_radio_reg(pi, RADIO_2064_REG03A, 0xF9);
  2082. or_radio_reg(pi, RADIO_2064_REG11A, 0x1);
  2083. or_radio_reg(pi, RADIO_2064_REG036, 0x01);
  2084. or_radio_reg(pi, RADIO_2064_REG11A, 0x18);
  2085. udelay(20);
  2086. if (LCNREV_IS(pi->pubpi.phy_rev, 2)) {
  2087. if (CHSPEC_IS5G(pi->radio_chanspec))
  2088. mod_radio_reg(pi, RADIO_2064_REG03A, 1, 0);
  2089. else
  2090. or_radio_reg(pi, RADIO_2064_REG03A, 1);
  2091. } else {
  2092. if (CHSPEC_IS5G(pi->radio_chanspec))
  2093. mod_radio_reg(pi, RADIO_2064_REG03A, 3, 1);
  2094. else
  2095. or_radio_reg(pi, RADIO_2064_REG03A, 0x3);
  2096. }
  2097. udelay(20);
  2098. write_radio_reg(pi, RADIO_2064_REG025, 0xF);
  2099. if (LCNREV_IS(pi->pubpi.phy_rev, 2)) {
  2100. if (CHSPEC_IS5G(pi->radio_chanspec))
  2101. mod_radio_reg(pi, RADIO_2064_REG028, 0xF, 0x4);
  2102. else
  2103. mod_radio_reg(pi, RADIO_2064_REG028, 0xF, 0x6);
  2104. } else {
  2105. if (CHSPEC_IS5G(pi->radio_chanspec))
  2106. mod_radio_reg(pi, RADIO_2064_REG028, 0x1e, 0x4 << 1);
  2107. else
  2108. mod_radio_reg(pi, RADIO_2064_REG028, 0x1e, 0x6 << 1);
  2109. }
  2110. udelay(20);
  2111. write_radio_reg(pi, RADIO_2064_REG005, 0x8);
  2112. or_radio_reg(pi, RADIO_2064_REG112, 0x80);
  2113. udelay(20);
  2114. or_radio_reg(pi, RADIO_2064_REG0FF, 0x10);
  2115. or_radio_reg(pi, RADIO_2064_REG11F, 0x44);
  2116. udelay(20);
  2117. or_radio_reg(pi, RADIO_2064_REG00B, 0x7);
  2118. or_radio_reg(pi, RADIO_2064_REG113, 0x10);
  2119. udelay(20);
  2120. write_radio_reg(pi, RADIO_2064_REG007, 0x1);
  2121. udelay(20);
  2122. vmid = 0x2A6;
  2123. mod_radio_reg(pi, RADIO_2064_REG0FC, 0x3 << 0, (vmid >> 8) & 0x3);
  2124. write_radio_reg(pi, RADIO_2064_REG0FD, (vmid & 0xff));
  2125. or_radio_reg(pi, RADIO_2064_REG11F, 0x44);
  2126. udelay(20);
  2127. or_radio_reg(pi, RADIO_2064_REG0FF, 0x10);
  2128. udelay(20);
  2129. write_radio_reg(pi, RADIO_2064_REG012, 0x02);
  2130. or_radio_reg(pi, RADIO_2064_REG112, 0x06);
  2131. write_radio_reg(pi, RADIO_2064_REG036, 0x11);
  2132. write_radio_reg(pi, RADIO_2064_REG059, 0xcc);
  2133. write_radio_reg(pi, RADIO_2064_REG05C, 0x2e);
  2134. write_radio_reg(pi, RADIO_2064_REG078, 0xd7);
  2135. write_radio_reg(pi, RADIO_2064_REG092, 0x15);
  2136. }
  2137. static bool wlc_lcnphy_iqcal_wait(struct brcms_phy *pi)
  2138. {
  2139. uint delay_count = 0;
  2140. while (wlc_lcnphy_iqcal_active(pi)) {
  2141. udelay(100);
  2142. delay_count++;
  2143. if (delay_count > (10 * 500))
  2144. break;
  2145. }
  2146. return (0 == wlc_lcnphy_iqcal_active(pi));
  2147. }
  2148. static void
  2149. wlc_lcnphy_tx_iqlo_loopback_cleanup(struct brcms_phy *pi, u16 *values_to_save)
  2150. {
  2151. int i;
  2152. and_phy_reg(pi, 0x44c, 0x0 >> 11);
  2153. and_phy_reg(pi, 0x43b, 0xC);
  2154. for (i = 0; i < 20; i++)
  2155. write_radio_reg(pi, iqlo_loopback_rf_regs[i],
  2156. values_to_save[i]);
  2157. }
  2158. static void
  2159. wlc_lcnphy_tx_iqlo_cal(struct brcms_phy *pi,
  2160. struct lcnphy_txgains *target_gains,
  2161. enum lcnphy_cal_mode cal_mode, bool keep_tone)
  2162. {
  2163. struct lcnphy_txgains cal_gains, temp_gains;
  2164. u16 hash;
  2165. u8 band_idx;
  2166. int j;
  2167. u16 ncorr_override[5];
  2168. u16 syst_coeffs[] = { 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  2169. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000};
  2170. u16 commands_fullcal[] = {
  2171. 0x8434, 0x8334, 0x8084, 0x8267, 0x8056, 0x8234
  2172. };
  2173. u16 commands_recal[] = {
  2174. 0x8434, 0x8334, 0x8084, 0x8267, 0x8056, 0x8234
  2175. };
  2176. u16 command_nums_fullcal[] = {
  2177. 0x7a97, 0x7a97, 0x7a97, 0x7a87, 0x7a87, 0x7b97
  2178. };
  2179. u16 command_nums_recal[] = {
  2180. 0x7a97, 0x7a97, 0x7a97, 0x7a87, 0x7a87, 0x7b97
  2181. };
  2182. u16 *command_nums = command_nums_fullcal;
  2183. u16 *start_coeffs = NULL, *cal_cmds = NULL, cal_type, diq_start;
  2184. u16 tx_pwr_ctrl_old, save_txpwrctrlrfctrl2;
  2185. u16 save_sslpnCalibClkEnCtrl, save_sslpnRxFeClkEnCtrl;
  2186. bool tx_gain_override_old;
  2187. struct lcnphy_txgains old_gains;
  2188. uint i, n_cal_cmds = 0, n_cal_start = 0;
  2189. u16 *values_to_save;
  2190. struct brcms_phy_lcnphy *pi_lcn = pi->u.pi_lcnphy;
  2191. values_to_save = kmalloc(sizeof(u16) * 20, GFP_ATOMIC);
  2192. if (NULL == values_to_save)
  2193. return;
  2194. save_sslpnRxFeClkEnCtrl = read_phy_reg(pi, 0x6db);
  2195. save_sslpnCalibClkEnCtrl = read_phy_reg(pi, 0x6da);
  2196. or_phy_reg(pi, 0x6da, 0x40);
  2197. or_phy_reg(pi, 0x6db, 0x3);
  2198. switch (cal_mode) {
  2199. case LCNPHY_CAL_FULL:
  2200. start_coeffs = syst_coeffs;
  2201. cal_cmds = commands_fullcal;
  2202. n_cal_cmds = ARRAY_SIZE(commands_fullcal);
  2203. break;
  2204. case LCNPHY_CAL_RECAL:
  2205. start_coeffs = syst_coeffs;
  2206. cal_cmds = commands_recal;
  2207. n_cal_cmds = ARRAY_SIZE(commands_recal);
  2208. command_nums = command_nums_recal;
  2209. break;
  2210. default:
  2211. break;
  2212. }
  2213. wlc_lcnphy_common_write_table(pi, LCNPHY_TBL_ID_IQLOCAL,
  2214. start_coeffs, 11, 16, 64);
  2215. write_phy_reg(pi, 0x6da, 0xffff);
  2216. mod_phy_reg(pi, 0x503, (0x1 << 3), (1) << 3);
  2217. tx_pwr_ctrl_old = wlc_lcnphy_get_tx_pwr_ctrl(pi);
  2218. mod_phy_reg(pi, 0x4a4, (0x1 << 12), (1) << 12);
  2219. wlc_lcnphy_set_tx_pwr_ctrl(pi, LCNPHY_TX_PWR_CTRL_OFF);
  2220. save_txpwrctrlrfctrl2 = read_phy_reg(pi, 0x4db);
  2221. mod_phy_reg(pi, 0x4db, (0x3ff << 0), (0x2a6) << 0);
  2222. mod_phy_reg(pi, 0x4db, (0x7 << 12), (2) << 12);
  2223. wlc_lcnphy_tx_iqlo_loopback(pi, values_to_save);
  2224. tx_gain_override_old = wlc_lcnphy_tx_gain_override_enabled(pi);
  2225. if (tx_gain_override_old)
  2226. wlc_lcnphy_get_tx_gain(pi, &old_gains);
  2227. if (!target_gains) {
  2228. if (!tx_gain_override_old)
  2229. wlc_lcnphy_set_tx_pwr_by_index(pi,
  2230. pi_lcn->lcnphy_tssi_idx);
  2231. wlc_lcnphy_get_tx_gain(pi, &temp_gains);
  2232. target_gains = &temp_gains;
  2233. }
  2234. hash = (target_gains->gm_gain << 8) |
  2235. (target_gains->pga_gain << 4) | (target_gains->pad_gain);
  2236. band_idx = (CHSPEC_IS5G(pi->radio_chanspec) ? 1 : 0);
  2237. cal_gains = *target_gains;
  2238. memset(ncorr_override, 0, sizeof(ncorr_override));
  2239. for (j = 0; j < iqcal_gainparams_numgains_lcnphy[band_idx]; j++) {
  2240. if (hash == tbl_iqcal_gainparams_lcnphy[band_idx][j][0]) {
  2241. cal_gains.gm_gain =
  2242. tbl_iqcal_gainparams_lcnphy[band_idx][j][1];
  2243. cal_gains.pga_gain =
  2244. tbl_iqcal_gainparams_lcnphy[band_idx][j][2];
  2245. cal_gains.pad_gain =
  2246. tbl_iqcal_gainparams_lcnphy[band_idx][j][3];
  2247. memcpy(ncorr_override,
  2248. &tbl_iqcal_gainparams_lcnphy[band_idx][j][3],
  2249. sizeof(ncorr_override));
  2250. break;
  2251. }
  2252. }
  2253. wlc_lcnphy_set_tx_gain(pi, &cal_gains);
  2254. write_phy_reg(pi, 0x453, 0xaa9);
  2255. write_phy_reg(pi, 0x93d, 0xc0);
  2256. wlc_lcnphy_common_write_table(pi, LCNPHY_TBL_ID_IQLOCAL,
  2257. lcnphy_iqcal_loft_gainladder,
  2258. ARRAY_SIZE(lcnphy_iqcal_loft_gainladder),
  2259. 16, 0);
  2260. wlc_lcnphy_common_write_table(pi, LCNPHY_TBL_ID_IQLOCAL,
  2261. lcnphy_iqcal_ir_gainladder,
  2262. ARRAY_SIZE(
  2263. lcnphy_iqcal_ir_gainladder), 16,
  2264. 32);
  2265. if (pi->phy_tx_tone_freq) {
  2266. wlc_lcnphy_stop_tx_tone(pi);
  2267. udelay(5);
  2268. wlc_lcnphy_start_tx_tone(pi, 3750, 88, 1);
  2269. } else {
  2270. wlc_lcnphy_start_tx_tone(pi, 3750, 88, 1);
  2271. }
  2272. write_phy_reg(pi, 0x6da, 0xffff);
  2273. for (i = n_cal_start; i < n_cal_cmds; i++) {
  2274. u16 zero_diq = 0;
  2275. u16 best_coeffs[11];
  2276. u16 command_num;
  2277. cal_type = (cal_cmds[i] & 0x0f00) >> 8;
  2278. command_num = command_nums[i];
  2279. if (ncorr_override[cal_type])
  2280. command_num =
  2281. ncorr_override[cal_type] << 8 | (command_num &
  2282. 0xff);
  2283. write_phy_reg(pi, 0x452, command_num);
  2284. if ((cal_type == 3) || (cal_type == 4)) {
  2285. wlc_lcnphy_common_read_table(pi, LCNPHY_TBL_ID_IQLOCAL,
  2286. &diq_start, 1, 16, 69);
  2287. wlc_lcnphy_common_write_table(pi, LCNPHY_TBL_ID_IQLOCAL,
  2288. &zero_diq, 1, 16, 69);
  2289. }
  2290. write_phy_reg(pi, 0x451, cal_cmds[i]);
  2291. if (!wlc_lcnphy_iqcal_wait(pi))
  2292. goto cleanup;
  2293. wlc_lcnphy_common_read_table(pi, LCNPHY_TBL_ID_IQLOCAL,
  2294. best_coeffs,
  2295. ARRAY_SIZE(best_coeffs), 16, 96);
  2296. wlc_lcnphy_common_write_table(pi, LCNPHY_TBL_ID_IQLOCAL,
  2297. best_coeffs,
  2298. ARRAY_SIZE(best_coeffs), 16, 64);
  2299. if ((cal_type == 3) || (cal_type == 4))
  2300. wlc_lcnphy_common_write_table(pi, LCNPHY_TBL_ID_IQLOCAL,
  2301. &diq_start, 1, 16, 69);
  2302. wlc_lcnphy_common_read_table(pi, LCNPHY_TBL_ID_IQLOCAL,
  2303. pi_lcn->lcnphy_cal_results.
  2304. txiqlocal_bestcoeffs,
  2305. ARRAY_SIZE(pi_lcn->
  2306. lcnphy_cal_results.
  2307. txiqlocal_bestcoeffs),
  2308. 16, 96);
  2309. }
  2310. wlc_lcnphy_common_read_table(pi, LCNPHY_TBL_ID_IQLOCAL,
  2311. pi_lcn->lcnphy_cal_results.
  2312. txiqlocal_bestcoeffs,
  2313. ARRAY_SIZE(pi_lcn->lcnphy_cal_results.
  2314. txiqlocal_bestcoeffs), 16, 96);
  2315. pi_lcn->lcnphy_cal_results.txiqlocal_bestcoeffs_valid = true;
  2316. wlc_lcnphy_common_write_table(pi, LCNPHY_TBL_ID_IQLOCAL,
  2317. &pi_lcn->lcnphy_cal_results.
  2318. txiqlocal_bestcoeffs[0], 4, 16, 80);
  2319. wlc_lcnphy_common_write_table(pi, LCNPHY_TBL_ID_IQLOCAL,
  2320. &pi_lcn->lcnphy_cal_results.
  2321. txiqlocal_bestcoeffs[5], 2, 16, 85);
  2322. cleanup:
  2323. wlc_lcnphy_tx_iqlo_loopback_cleanup(pi, values_to_save);
  2324. kfree(values_to_save);
  2325. if (!keep_tone)
  2326. wlc_lcnphy_stop_tx_tone(pi);
  2327. write_phy_reg(pi, 0x4db, save_txpwrctrlrfctrl2);
  2328. write_phy_reg(pi, 0x453, 0);
  2329. if (tx_gain_override_old)
  2330. wlc_lcnphy_set_tx_gain(pi, &old_gains);
  2331. wlc_lcnphy_set_tx_pwr_ctrl(pi, tx_pwr_ctrl_old);
  2332. write_phy_reg(pi, 0x6da, save_sslpnCalibClkEnCtrl);
  2333. write_phy_reg(pi, 0x6db, save_sslpnRxFeClkEnCtrl);
  2334. }
  2335. static void wlc_lcnphy_idle_tssi_est(struct brcms_phy_pub *ppi)
  2336. {
  2337. bool suspend, tx_gain_override_old;
  2338. struct lcnphy_txgains old_gains;
  2339. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  2340. u16 idleTssi, idleTssi0_2C, idleTssi0_OB, idleTssi0_regvalue_OB,
  2341. idleTssi0_regvalue_2C;
  2342. u16 SAVE_txpwrctrl = wlc_lcnphy_get_tx_pwr_ctrl(pi);
  2343. u16 SAVE_lpfgain = read_radio_reg(pi, RADIO_2064_REG112);
  2344. u16 SAVE_jtag_bb_afe_switch =
  2345. read_radio_reg(pi, RADIO_2064_REG007) & 1;
  2346. u16 SAVE_jtag_auxpga = read_radio_reg(pi, RADIO_2064_REG0FF) & 0x10;
  2347. u16 SAVE_iqadc_aux_en = read_radio_reg(pi, RADIO_2064_REG11F) & 4;
  2348. idleTssi = read_phy_reg(pi, 0x4ab);
  2349. suspend =
  2350. (0 ==
  2351. (R_REG(&((struct brcms_phy *) pi)->regs->maccontrol) &
  2352. MCTL_EN_MAC));
  2353. if (!suspend)
  2354. wlapi_suspend_mac_and_wait(pi->sh->physhim);
  2355. wlc_lcnphy_set_tx_pwr_ctrl(pi, LCNPHY_TX_PWR_CTRL_OFF);
  2356. tx_gain_override_old = wlc_lcnphy_tx_gain_override_enabled(pi);
  2357. wlc_lcnphy_get_tx_gain(pi, &old_gains);
  2358. wlc_lcnphy_enable_tx_gain_override(pi);
  2359. wlc_lcnphy_set_tx_pwr_by_index(pi, 127);
  2360. write_radio_reg(pi, RADIO_2064_REG112, 0x6);
  2361. mod_radio_reg(pi, RADIO_2064_REG007, 0x1, 1);
  2362. mod_radio_reg(pi, RADIO_2064_REG0FF, 0x10, 1 << 4);
  2363. mod_radio_reg(pi, RADIO_2064_REG11F, 0x4, 1 << 2);
  2364. wlc_lcnphy_tssi_setup(pi);
  2365. wlc_phy_do_dummy_tx(pi, true, OFF);
  2366. idleTssi = ((read_phy_reg(pi, 0x4ab) & (0x1ff << 0))
  2367. >> 0);
  2368. idleTssi0_2C = ((read_phy_reg(pi, 0x63e) & (0x1ff << 0))
  2369. >> 0);
  2370. if (idleTssi0_2C >= 256)
  2371. idleTssi0_OB = idleTssi0_2C - 256;
  2372. else
  2373. idleTssi0_OB = idleTssi0_2C + 256;
  2374. idleTssi0_regvalue_OB = idleTssi0_OB;
  2375. if (idleTssi0_regvalue_OB >= 256)
  2376. idleTssi0_regvalue_2C = idleTssi0_regvalue_OB - 256;
  2377. else
  2378. idleTssi0_regvalue_2C = idleTssi0_regvalue_OB + 256;
  2379. mod_phy_reg(pi, 0x4a6, (0x1ff << 0), (idleTssi0_regvalue_2C) << 0);
  2380. mod_phy_reg(pi, 0x44c, (0x1 << 12), (0) << 12);
  2381. wlc_lcnphy_set_tx_gain_override(pi, tx_gain_override_old);
  2382. wlc_lcnphy_set_tx_gain(pi, &old_gains);
  2383. wlc_lcnphy_set_tx_pwr_ctrl(pi, SAVE_txpwrctrl);
  2384. write_radio_reg(pi, RADIO_2064_REG112, SAVE_lpfgain);
  2385. mod_radio_reg(pi, RADIO_2064_REG007, 0x1, SAVE_jtag_bb_afe_switch);
  2386. mod_radio_reg(pi, RADIO_2064_REG0FF, 0x10, SAVE_jtag_auxpga);
  2387. mod_radio_reg(pi, RADIO_2064_REG11F, 0x4, SAVE_iqadc_aux_en);
  2388. mod_radio_reg(pi, RADIO_2064_REG112, 0x80, 1 << 7);
  2389. if (!suspend)
  2390. wlapi_enable_mac(pi->sh->physhim);
  2391. }
  2392. static void wlc_lcnphy_vbat_temp_sense_setup(struct brcms_phy *pi, u8 mode)
  2393. {
  2394. bool suspend;
  2395. u16 save_txpwrCtrlEn;
  2396. u8 auxpga_vmidcourse, auxpga_vmidfine, auxpga_gain;
  2397. u16 auxpga_vmid;
  2398. struct phytbl_info tab;
  2399. u32 val;
  2400. u8 save_reg007, save_reg0FF, save_reg11F, save_reg005, save_reg025,
  2401. save_reg112;
  2402. u16 values_to_save[14];
  2403. s8 index;
  2404. int i;
  2405. struct brcms_phy_lcnphy *pi_lcn = pi->u.pi_lcnphy;
  2406. udelay(999);
  2407. save_reg007 = (u8) read_radio_reg(pi, RADIO_2064_REG007);
  2408. save_reg0FF = (u8) read_radio_reg(pi, RADIO_2064_REG0FF);
  2409. save_reg11F = (u8) read_radio_reg(pi, RADIO_2064_REG11F);
  2410. save_reg005 = (u8) read_radio_reg(pi, RADIO_2064_REG005);
  2411. save_reg025 = (u8) read_radio_reg(pi, RADIO_2064_REG025);
  2412. save_reg112 = (u8) read_radio_reg(pi, RADIO_2064_REG112);
  2413. for (i = 0; i < 14; i++)
  2414. values_to_save[i] = read_phy_reg(pi, tempsense_phy_regs[i]);
  2415. suspend = (0 == (R_REG(&pi->regs->maccontrol) & MCTL_EN_MAC));
  2416. if (!suspend)
  2417. wlapi_suspend_mac_and_wait(pi->sh->physhim);
  2418. save_txpwrCtrlEn = read_radio_reg(pi, 0x4a4);
  2419. wlc_lcnphy_set_tx_pwr_ctrl(pi, LCNPHY_TX_PWR_CTRL_OFF);
  2420. index = pi_lcn->lcnphy_current_index;
  2421. wlc_lcnphy_set_tx_pwr_by_index(pi, 127);
  2422. mod_radio_reg(pi, RADIO_2064_REG007, 0x1, 0x1);
  2423. mod_radio_reg(pi, RADIO_2064_REG0FF, 0x10, 0x1 << 4);
  2424. mod_radio_reg(pi, RADIO_2064_REG11F, 0x4, 0x1 << 2);
  2425. mod_phy_reg(pi, 0x503, (0x1 << 0), (0) << 0);
  2426. mod_phy_reg(pi, 0x503, (0x1 << 2), (0) << 2);
  2427. mod_phy_reg(pi, 0x4a4, (0x1 << 14), (0) << 14);
  2428. mod_phy_reg(pi, 0x4a4, (0x1 << 15), (0) << 15);
  2429. mod_phy_reg(pi, 0x4d0, (0x1 << 5), (0) << 5);
  2430. mod_phy_reg(pi, 0x4a5, (0xff << 0), (255) << 0);
  2431. mod_phy_reg(pi, 0x4a5, (0x7 << 12), (5) << 12);
  2432. mod_phy_reg(pi, 0x4a5, (0x7 << 8), (0) << 8);
  2433. mod_phy_reg(pi, 0x40d, (0xff << 0), (64) << 0);
  2434. mod_phy_reg(pi, 0x40d, (0x7 << 8), (6) << 8);
  2435. mod_phy_reg(pi, 0x4a2, (0xff << 0), (64) << 0);
  2436. mod_phy_reg(pi, 0x4a2, (0x7 << 8), (6) << 8);
  2437. mod_phy_reg(pi, 0x4d9, (0x7 << 4), (2) << 4);
  2438. mod_phy_reg(pi, 0x4d9, (0x7 << 8), (3) << 8);
  2439. mod_phy_reg(pi, 0x4d9, (0x7 << 12), (1) << 12);
  2440. mod_phy_reg(pi, 0x4da, (0x1 << 12), (0) << 12);
  2441. mod_phy_reg(pi, 0x4da, (0x1 << 13), (1) << 13);
  2442. mod_phy_reg(pi, 0x4a6, (0x1 << 15), (1) << 15);
  2443. write_radio_reg(pi, RADIO_2064_REG025, 0xC);
  2444. mod_radio_reg(pi, RADIO_2064_REG005, 0x8, 0x1 << 3);
  2445. mod_phy_reg(pi, 0x938, (0x1 << 2), (1) << 2);
  2446. mod_phy_reg(pi, 0x939, (0x1 << 2), (1) << 2);
  2447. mod_phy_reg(pi, 0x4a4, (0x1 << 12), (1) << 12);
  2448. val = wlc_lcnphy_rfseq_tbl_adc_pwrup(pi);
  2449. tab.tbl_id = LCNPHY_TBL_ID_RFSEQ;
  2450. tab.tbl_width = 16;
  2451. tab.tbl_len = 1;
  2452. tab.tbl_ptr = &val;
  2453. tab.tbl_offset = 6;
  2454. wlc_lcnphy_write_table(pi, &tab);
  2455. if (mode == TEMPSENSE) {
  2456. mod_phy_reg(pi, 0x4d7, (0x1 << 3), (1) << 3);
  2457. mod_phy_reg(pi, 0x4d7, (0x7 << 12), (1) << 12);
  2458. auxpga_vmidcourse = 8;
  2459. auxpga_vmidfine = 0x4;
  2460. auxpga_gain = 2;
  2461. mod_radio_reg(pi, RADIO_2064_REG082, 0x20, 1 << 5);
  2462. } else {
  2463. mod_phy_reg(pi, 0x4d7, (0x1 << 3), (1) << 3);
  2464. mod_phy_reg(pi, 0x4d7, (0x7 << 12), (3) << 12);
  2465. auxpga_vmidcourse = 7;
  2466. auxpga_vmidfine = 0xa;
  2467. auxpga_gain = 2;
  2468. }
  2469. auxpga_vmid =
  2470. (u16) ((2 << 8) | (auxpga_vmidcourse << 4) | auxpga_vmidfine);
  2471. mod_phy_reg(pi, 0x4d8, (0x1 << 0), (1) << 0);
  2472. mod_phy_reg(pi, 0x4d8, (0x3ff << 2), (auxpga_vmid) << 2);
  2473. mod_phy_reg(pi, 0x4d8, (0x1 << 1), (1) << 1);
  2474. mod_phy_reg(pi, 0x4d8, (0x7 << 12), (auxpga_gain) << 12);
  2475. mod_phy_reg(pi, 0x4d0, (0x1 << 5), (1) << 5);
  2476. write_radio_reg(pi, RADIO_2064_REG112, 0x6);
  2477. wlc_phy_do_dummy_tx(pi, true, OFF);
  2478. if (!tempsense_done(pi))
  2479. udelay(10);
  2480. write_radio_reg(pi, RADIO_2064_REG007, (u16) save_reg007);
  2481. write_radio_reg(pi, RADIO_2064_REG0FF, (u16) save_reg0FF);
  2482. write_radio_reg(pi, RADIO_2064_REG11F, (u16) save_reg11F);
  2483. write_radio_reg(pi, RADIO_2064_REG005, (u16) save_reg005);
  2484. write_radio_reg(pi, RADIO_2064_REG025, (u16) save_reg025);
  2485. write_radio_reg(pi, RADIO_2064_REG112, (u16) save_reg112);
  2486. for (i = 0; i < 14; i++)
  2487. write_phy_reg(pi, tempsense_phy_regs[i], values_to_save[i]);
  2488. wlc_lcnphy_set_tx_pwr_by_index(pi, (int)index);
  2489. write_radio_reg(pi, 0x4a4, save_txpwrCtrlEn);
  2490. if (!suspend)
  2491. wlapi_enable_mac(pi->sh->physhim);
  2492. udelay(999);
  2493. }
  2494. static void wlc_lcnphy_tx_pwr_ctrl_init(struct brcms_phy_pub *ppi)
  2495. {
  2496. struct lcnphy_txgains tx_gains;
  2497. u8 bbmult;
  2498. struct phytbl_info tab;
  2499. s32 a1, b0, b1;
  2500. s32 tssi, pwr, maxtargetpwr, mintargetpwr;
  2501. bool suspend;
  2502. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  2503. suspend =
  2504. (0 == (R_REG(&pi->regs->maccontrol) & MCTL_EN_MAC));
  2505. if (!suspend)
  2506. wlapi_suspend_mac_and_wait(pi->sh->physhim);
  2507. if (!pi->hwpwrctrl_capable) {
  2508. if (CHSPEC_IS2G(pi->radio_chanspec)) {
  2509. tx_gains.gm_gain = 4;
  2510. tx_gains.pga_gain = 12;
  2511. tx_gains.pad_gain = 12;
  2512. tx_gains.dac_gain = 0;
  2513. bbmult = 150;
  2514. } else {
  2515. tx_gains.gm_gain = 7;
  2516. tx_gains.pga_gain = 15;
  2517. tx_gains.pad_gain = 14;
  2518. tx_gains.dac_gain = 0;
  2519. bbmult = 150;
  2520. }
  2521. wlc_lcnphy_set_tx_gain(pi, &tx_gains);
  2522. wlc_lcnphy_set_bbmult(pi, bbmult);
  2523. wlc_lcnphy_vbat_temp_sense_setup(pi, TEMPSENSE);
  2524. } else {
  2525. wlc_lcnphy_idle_tssi_est(ppi);
  2526. wlc_lcnphy_clear_tx_power_offsets(pi);
  2527. b0 = pi->txpa_2g[0];
  2528. b1 = pi->txpa_2g[1];
  2529. a1 = pi->txpa_2g[2];
  2530. maxtargetpwr = wlc_lcnphy_tssi2dbm(10, a1, b0, b1);
  2531. mintargetpwr = wlc_lcnphy_tssi2dbm(125, a1, b0, b1);
  2532. tab.tbl_id = LCNPHY_TBL_ID_TXPWRCTL;
  2533. tab.tbl_width = 32;
  2534. tab.tbl_ptr = &pwr;
  2535. tab.tbl_len = 1;
  2536. tab.tbl_offset = 0;
  2537. for (tssi = 0; tssi < 128; tssi++) {
  2538. pwr = wlc_lcnphy_tssi2dbm(tssi, a1, b0, b1);
  2539. pwr = (pwr < mintargetpwr) ? mintargetpwr : pwr;
  2540. wlc_lcnphy_write_table(pi, &tab);
  2541. tab.tbl_offset++;
  2542. }
  2543. mod_phy_reg(pi, 0x410, (0x1 << 7), (0) << 7);
  2544. write_phy_reg(pi, 0x4a8, 10);
  2545. wlc_lcnphy_set_target_tx_pwr(pi, LCN_TARGET_PWR);
  2546. wlc_lcnphy_set_tx_pwr_ctrl(pi, LCNPHY_TX_PWR_CTRL_HW);
  2547. }
  2548. if (!suspend)
  2549. wlapi_enable_mac(pi->sh->physhim);
  2550. }
  2551. static u8 wlc_lcnphy_get_bbmult(struct brcms_phy *pi)
  2552. {
  2553. u16 m0m1;
  2554. struct phytbl_info tab;
  2555. tab.tbl_ptr = &m0m1;
  2556. tab.tbl_len = 1;
  2557. tab.tbl_id = LCNPHY_TBL_ID_IQLOCAL;
  2558. tab.tbl_offset = 87;
  2559. tab.tbl_width = 16;
  2560. wlc_lcnphy_read_table(pi, &tab);
  2561. return (u8) ((m0m1 & 0xff00) >> 8);
  2562. }
  2563. static void wlc_lcnphy_set_pa_gain(struct brcms_phy *pi, u16 gain)
  2564. {
  2565. mod_phy_reg(pi, 0x4fb,
  2566. LCNPHY_txgainctrlovrval1_pagain_ovr_val1_MASK,
  2567. gain << LCNPHY_txgainctrlovrval1_pagain_ovr_val1_SHIFT);
  2568. mod_phy_reg(pi, 0x4fd,
  2569. LCNPHY_stxtxgainctrlovrval1_pagain_ovr_val1_MASK,
  2570. gain << LCNPHY_stxtxgainctrlovrval1_pagain_ovr_val1_SHIFT);
  2571. }
  2572. void
  2573. wlc_lcnphy_get_radio_loft(struct brcms_phy *pi,
  2574. u8 *ei0, u8 *eq0, u8 *fi0, u8 *fq0)
  2575. {
  2576. *ei0 = LCNPHY_IQLOCC_READ(read_radio_reg(pi, RADIO_2064_REG089));
  2577. *eq0 = LCNPHY_IQLOCC_READ(read_radio_reg(pi, RADIO_2064_REG08A));
  2578. *fi0 = LCNPHY_IQLOCC_READ(read_radio_reg(pi, RADIO_2064_REG08B));
  2579. *fq0 = LCNPHY_IQLOCC_READ(read_radio_reg(pi, RADIO_2064_REG08C));
  2580. }
  2581. void wlc_lcnphy_set_tx_iqcc(struct brcms_phy *pi, u16 a, u16 b)
  2582. {
  2583. struct phytbl_info tab;
  2584. u16 iqcc[2];
  2585. iqcc[0] = a;
  2586. iqcc[1] = b;
  2587. tab.tbl_id = LCNPHY_TBL_ID_IQLOCAL;
  2588. tab.tbl_width = 16;
  2589. tab.tbl_ptr = iqcc;
  2590. tab.tbl_len = 2;
  2591. tab.tbl_offset = 80;
  2592. wlc_lcnphy_write_table(pi, &tab);
  2593. }
  2594. void wlc_lcnphy_set_tx_locc(struct brcms_phy *pi, u16 didq)
  2595. {
  2596. struct phytbl_info tab;
  2597. tab.tbl_id = LCNPHY_TBL_ID_IQLOCAL;
  2598. tab.tbl_width = 16;
  2599. tab.tbl_ptr = &didq;
  2600. tab.tbl_len = 1;
  2601. tab.tbl_offset = 85;
  2602. wlc_lcnphy_write_table(pi, &tab);
  2603. }
  2604. void wlc_lcnphy_set_tx_pwr_by_index(struct brcms_phy *pi, int index)
  2605. {
  2606. struct phytbl_info tab;
  2607. u16 a, b;
  2608. u8 bb_mult;
  2609. u32 bbmultiqcomp, txgain, locoeffs, rfpower;
  2610. struct lcnphy_txgains gains;
  2611. struct brcms_phy_lcnphy *pi_lcn = pi->u.pi_lcnphy;
  2612. pi_lcn->lcnphy_tx_power_idx_override = (s8) index;
  2613. pi_lcn->lcnphy_current_index = (u8) index;
  2614. tab.tbl_id = LCNPHY_TBL_ID_TXPWRCTL;
  2615. tab.tbl_width = 32;
  2616. tab.tbl_len = 1;
  2617. wlc_lcnphy_set_tx_pwr_ctrl(pi, LCNPHY_TX_PWR_CTRL_OFF);
  2618. tab.tbl_offset = LCNPHY_TX_PWR_CTRL_IQ_OFFSET + index;
  2619. tab.tbl_ptr = &bbmultiqcomp;
  2620. wlc_lcnphy_read_table(pi, &tab);
  2621. tab.tbl_offset = LCNPHY_TX_PWR_CTRL_GAIN_OFFSET + index;
  2622. tab.tbl_width = 32;
  2623. tab.tbl_ptr = &txgain;
  2624. wlc_lcnphy_read_table(pi, &tab);
  2625. gains.gm_gain = (u16) (txgain & 0xff);
  2626. gains.pga_gain = (u16) (txgain >> 8) & 0xff;
  2627. gains.pad_gain = (u16) (txgain >> 16) & 0xff;
  2628. gains.dac_gain = (u16) (bbmultiqcomp >> 28) & 0x07;
  2629. wlc_lcnphy_set_tx_gain(pi, &gains);
  2630. wlc_lcnphy_set_pa_gain(pi, (u16) (txgain >> 24) & 0x7f);
  2631. bb_mult = (u8) ((bbmultiqcomp >> 20) & 0xff);
  2632. wlc_lcnphy_set_bbmult(pi, bb_mult);
  2633. wlc_lcnphy_enable_tx_gain_override(pi);
  2634. if (!wlc_lcnphy_tempsense_based_pwr_ctrl_enabled(pi)) {
  2635. a = (u16) ((bbmultiqcomp >> 10) & 0x3ff);
  2636. b = (u16) (bbmultiqcomp & 0x3ff);
  2637. wlc_lcnphy_set_tx_iqcc(pi, a, b);
  2638. tab.tbl_offset = LCNPHY_TX_PWR_CTRL_LO_OFFSET + index;
  2639. tab.tbl_ptr = &locoeffs;
  2640. wlc_lcnphy_read_table(pi, &tab);
  2641. wlc_lcnphy_set_tx_locc(pi, (u16) locoeffs);
  2642. tab.tbl_offset = LCNPHY_TX_PWR_CTRL_PWR_OFFSET + index;
  2643. tab.tbl_ptr = &rfpower;
  2644. wlc_lcnphy_read_table(pi, &tab);
  2645. mod_phy_reg(pi, 0x6a6, (0x1fff << 0), (rfpower * 8) << 0);
  2646. }
  2647. }
  2648. static void wlc_lcnphy_clear_papd_comptable(struct brcms_phy *pi)
  2649. {
  2650. u32 j;
  2651. struct phytbl_info tab;
  2652. u32 temp_offset[128];
  2653. tab.tbl_ptr = temp_offset;
  2654. tab.tbl_len = 128;
  2655. tab.tbl_id = LCNPHY_TBL_ID_PAPDCOMPDELTATBL;
  2656. tab.tbl_width = 32;
  2657. tab.tbl_offset = 0;
  2658. memset(temp_offset, 0, sizeof(temp_offset));
  2659. for (j = 1; j < 128; j += 2)
  2660. temp_offset[j] = 0x80000;
  2661. wlc_lcnphy_write_table(pi, &tab);
  2662. return;
  2663. }
  2664. void wlc_lcnphy_tx_pu(struct brcms_phy *pi, bool bEnable)
  2665. {
  2666. if (!bEnable) {
  2667. and_phy_reg(pi, 0x43b, ~(u16) ((0x1 << 1) | (0x1 << 4)));
  2668. mod_phy_reg(pi, 0x43c, (0x1 << 1), 1 << 1);
  2669. and_phy_reg(pi, 0x44c,
  2670. ~(u16) ((0x1 << 3) |
  2671. (0x1 << 5) |
  2672. (0x1 << 12) |
  2673. (0x1 << 0) | (0x1 << 1) | (0x1 << 2)));
  2674. and_phy_reg(pi, 0x44d,
  2675. ~(u16) ((0x1 << 3) | (0x1 << 5) | (0x1 << 14)));
  2676. mod_phy_reg(pi, 0x44d, (0x1 << 2), 1 << 2);
  2677. mod_phy_reg(pi, 0x44d, (0x1 << 1) | (0x1 << 0), (0x1 << 0));
  2678. and_phy_reg(pi, 0x4f9,
  2679. ~(u16) ((0x1 << 0) | (0x1 << 1) | (0x1 << 2)));
  2680. and_phy_reg(pi, 0x4fa,
  2681. ~(u16) ((0x1 << 0) | (0x1 << 1) | (0x1 << 2)));
  2682. } else {
  2683. mod_phy_reg(pi, 0x43b, (0x1 << 1), 1 << 1);
  2684. mod_phy_reg(pi, 0x43c, (0x1 << 1), 0 << 1);
  2685. mod_phy_reg(pi, 0x43b, (0x1 << 4), 1 << 4);
  2686. mod_phy_reg(pi, 0x43c, (0x1 << 6), 0 << 6);
  2687. mod_phy_reg(pi, 0x44c, (0x1 << 12), 1 << 12);
  2688. mod_phy_reg(pi, 0x44d, (0x1 << 14), 1 << 14);
  2689. wlc_lcnphy_set_trsw_override(pi, true, false);
  2690. mod_phy_reg(pi, 0x44d, (0x1 << 2), 0 << 2);
  2691. mod_phy_reg(pi, 0x44c, (0x1 << 2), 1 << 2);
  2692. if (CHSPEC_IS2G(pi->radio_chanspec)) {
  2693. mod_phy_reg(pi, 0x44c, (0x1 << 3), 1 << 3);
  2694. mod_phy_reg(pi, 0x44d, (0x1 << 3), 1 << 3);
  2695. mod_phy_reg(pi, 0x44c, (0x1 << 5), 1 << 5);
  2696. mod_phy_reg(pi, 0x44d, (0x1 << 5), 0 << 5);
  2697. mod_phy_reg(pi, 0x4f9, (0x1 << 1), 1 << 1);
  2698. mod_phy_reg(pi, 0x4fa, (0x1 << 1), 1 << 1);
  2699. mod_phy_reg(pi, 0x4f9, (0x1 << 2), 1 << 2);
  2700. mod_phy_reg(pi, 0x4fa, (0x1 << 2), 1 << 2);
  2701. mod_phy_reg(pi, 0x4f9, (0x1 << 0), 1 << 0);
  2702. mod_phy_reg(pi, 0x4fa, (0x1 << 0), 1 << 0);
  2703. } else {
  2704. mod_phy_reg(pi, 0x44c, (0x1 << 3), 1 << 3);
  2705. mod_phy_reg(pi, 0x44d, (0x1 << 3), 0 << 3);
  2706. mod_phy_reg(pi, 0x44c, (0x1 << 5), 1 << 5);
  2707. mod_phy_reg(pi, 0x44d, (0x1 << 5), 1 << 5);
  2708. mod_phy_reg(pi, 0x4f9, (0x1 << 1), 1 << 1);
  2709. mod_phy_reg(pi, 0x4fa, (0x1 << 1), 0 << 1);
  2710. mod_phy_reg(pi, 0x4f9, (0x1 << 2), 1 << 2);
  2711. mod_phy_reg(pi, 0x4fa, (0x1 << 2), 0 << 2);
  2712. mod_phy_reg(pi, 0x4f9, (0x1 << 0), 1 << 0);
  2713. mod_phy_reg(pi, 0x4fa, (0x1 << 0), 0 << 0);
  2714. }
  2715. }
  2716. }
  2717. static void
  2718. wlc_lcnphy_run_samples(struct brcms_phy *pi,
  2719. u16 num_samps,
  2720. u16 num_loops, u16 wait, bool iqcalmode)
  2721. {
  2722. or_phy_reg(pi, 0x6da, 0x8080);
  2723. mod_phy_reg(pi, 0x642, (0x7f << 0), (num_samps - 1) << 0);
  2724. if (num_loops != 0xffff)
  2725. num_loops--;
  2726. mod_phy_reg(pi, 0x640, (0xffff << 0), num_loops << 0);
  2727. mod_phy_reg(pi, 0x641, (0xffff << 0), wait << 0);
  2728. if (iqcalmode) {
  2729. and_phy_reg(pi, 0x453, (u16) ~(0x1 << 15));
  2730. or_phy_reg(pi, 0x453, (0x1 << 15));
  2731. } else {
  2732. write_phy_reg(pi, 0x63f, 1);
  2733. wlc_lcnphy_tx_pu(pi, 1);
  2734. }
  2735. or_radio_reg(pi, RADIO_2064_REG112, 0x6);
  2736. }
  2737. void wlc_lcnphy_deaf_mode(struct brcms_phy *pi, bool mode)
  2738. {
  2739. u8 phybw40;
  2740. phybw40 = CHSPEC_IS40(pi->radio_chanspec);
  2741. if (LCNREV_LT(pi->pubpi.phy_rev, 2)) {
  2742. mod_phy_reg(pi, 0x4b0, (0x1 << 5), (mode) << 5);
  2743. mod_phy_reg(pi, 0x4b1, (0x1 << 9), 0 << 9);
  2744. } else {
  2745. mod_phy_reg(pi, 0x4b0, (0x1 << 5), (mode) << 5);
  2746. mod_phy_reg(pi, 0x4b1, (0x1 << 9), 0 << 9);
  2747. }
  2748. if (phybw40 == 0) {
  2749. mod_phy_reg((pi), 0x410,
  2750. (0x1 << 6) |
  2751. (0x1 << 5),
  2752. ((CHSPEC_IS2G(
  2753. pi->radio_chanspec)) ? (!mode) : 0) <<
  2754. 6 | (!mode) << 5);
  2755. mod_phy_reg(pi, 0x410, (0x1 << 7), (mode) << 7);
  2756. }
  2757. }
  2758. void
  2759. wlc_lcnphy_start_tx_tone(struct brcms_phy *pi, s32 f_kHz, u16 max_val,
  2760. bool iqcalmode)
  2761. {
  2762. u8 phy_bw;
  2763. u16 num_samps, t, k;
  2764. u32 bw;
  2765. s32 theta = 0, rot = 0;
  2766. struct cordic_iq tone_samp;
  2767. u32 data_buf[64];
  2768. u16 i_samp, q_samp;
  2769. struct phytbl_info tab;
  2770. struct brcms_phy_lcnphy *pi_lcn = pi->u.pi_lcnphy;
  2771. pi->phy_tx_tone_freq = f_kHz;
  2772. wlc_lcnphy_deaf_mode(pi, true);
  2773. phy_bw = 40;
  2774. if (pi_lcn->lcnphy_spurmod) {
  2775. write_phy_reg(pi, 0x942, 0x2);
  2776. write_phy_reg(pi, 0x93b, 0x0);
  2777. write_phy_reg(pi, 0x93c, 0x0);
  2778. wlc_lcnphy_txrx_spur_avoidance_mode(pi, false);
  2779. }
  2780. if (f_kHz) {
  2781. k = 1;
  2782. do {
  2783. bw = phy_bw * 1000 * k;
  2784. num_samps = bw / abs(f_kHz);
  2785. k++;
  2786. } while ((num_samps * (u32) (abs(f_kHz))) != bw);
  2787. } else
  2788. num_samps = 2;
  2789. rot = ((f_kHz * 36) / phy_bw) / 100;
  2790. theta = 0;
  2791. for (t = 0; t < num_samps; t++) {
  2792. tone_samp = cordic_calc_iq(theta);
  2793. theta += rot;
  2794. i_samp = (u16) (FLOAT(tone_samp.i * max_val) & 0x3ff);
  2795. q_samp = (u16) (FLOAT(tone_samp.q * max_val) & 0x3ff);
  2796. data_buf[t] = (i_samp << 10) | q_samp;
  2797. }
  2798. mod_phy_reg(pi, 0x6d6, (0x3 << 0), 0 << 0);
  2799. mod_phy_reg(pi, 0x6da, (0x1 << 3), 1 << 3);
  2800. tab.tbl_ptr = data_buf;
  2801. tab.tbl_len = num_samps;
  2802. tab.tbl_id = LCNPHY_TBL_ID_SAMPLEPLAY;
  2803. tab.tbl_offset = 0;
  2804. tab.tbl_width = 32;
  2805. wlc_lcnphy_write_table(pi, &tab);
  2806. wlc_lcnphy_run_samples(pi, num_samps, 0xffff, 0, iqcalmode);
  2807. }
  2808. void wlc_lcnphy_stop_tx_tone(struct brcms_phy *pi)
  2809. {
  2810. s16 playback_status;
  2811. struct brcms_phy_lcnphy *pi_lcn = pi->u.pi_lcnphy;
  2812. pi->phy_tx_tone_freq = 0;
  2813. if (pi_lcn->lcnphy_spurmod) {
  2814. write_phy_reg(pi, 0x942, 0x7);
  2815. write_phy_reg(pi, 0x93b, 0x2017);
  2816. write_phy_reg(pi, 0x93c, 0x27c5);
  2817. wlc_lcnphy_txrx_spur_avoidance_mode(pi, true);
  2818. }
  2819. playback_status = read_phy_reg(pi, 0x644);
  2820. if (playback_status & (0x1 << 0)) {
  2821. wlc_lcnphy_tx_pu(pi, 0);
  2822. mod_phy_reg(pi, 0x63f, (0x1 << 1), 1 << 1);
  2823. } else if (playback_status & (0x1 << 1))
  2824. mod_phy_reg(pi, 0x453, (0x1 << 15), 0 << 15);
  2825. mod_phy_reg(pi, 0x6d6, (0x3 << 0), 1 << 0);
  2826. mod_phy_reg(pi, 0x6da, (0x1 << 3), 0 << 3);
  2827. mod_phy_reg(pi, 0x6da, (0x1 << 7), 0 << 7);
  2828. and_radio_reg(pi, RADIO_2064_REG112, 0xFFF9);
  2829. wlc_lcnphy_deaf_mode(pi, false);
  2830. }
  2831. static void
  2832. wlc_lcnphy_set_cc(struct brcms_phy *pi, int cal_type, s16 coeff_x, s16 coeff_y)
  2833. {
  2834. u16 di0dq0;
  2835. u16 x, y, data_rf;
  2836. int k;
  2837. switch (cal_type) {
  2838. case 0:
  2839. wlc_lcnphy_set_tx_iqcc(pi, coeff_x, coeff_y);
  2840. break;
  2841. case 2:
  2842. di0dq0 = (coeff_x & 0xff) << 8 | (coeff_y & 0xff);
  2843. wlc_lcnphy_set_tx_locc(pi, di0dq0);
  2844. break;
  2845. case 3:
  2846. k = wlc_lcnphy_calc_floor(coeff_x, 0);
  2847. y = 8 + k;
  2848. k = wlc_lcnphy_calc_floor(coeff_x, 1);
  2849. x = 8 - k;
  2850. data_rf = (x * 16 + y);
  2851. write_radio_reg(pi, RADIO_2064_REG089, data_rf);
  2852. k = wlc_lcnphy_calc_floor(coeff_y, 0);
  2853. y = 8 + k;
  2854. k = wlc_lcnphy_calc_floor(coeff_y, 1);
  2855. x = 8 - k;
  2856. data_rf = (x * 16 + y);
  2857. write_radio_reg(pi, RADIO_2064_REG08A, data_rf);
  2858. break;
  2859. case 4:
  2860. k = wlc_lcnphy_calc_floor(coeff_x, 0);
  2861. y = 8 + k;
  2862. k = wlc_lcnphy_calc_floor(coeff_x, 1);
  2863. x = 8 - k;
  2864. data_rf = (x * 16 + y);
  2865. write_radio_reg(pi, RADIO_2064_REG08B, data_rf);
  2866. k = wlc_lcnphy_calc_floor(coeff_y, 0);
  2867. y = 8 + k;
  2868. k = wlc_lcnphy_calc_floor(coeff_y, 1);
  2869. x = 8 - k;
  2870. data_rf = (x * 16 + y);
  2871. write_radio_reg(pi, RADIO_2064_REG08C, data_rf);
  2872. break;
  2873. }
  2874. }
  2875. static struct lcnphy_unsign16_struct
  2876. wlc_lcnphy_get_cc(struct brcms_phy *pi, int cal_type)
  2877. {
  2878. u16 a, b, didq;
  2879. u8 di0, dq0, ei, eq, fi, fq;
  2880. struct lcnphy_unsign16_struct cc;
  2881. cc.re = 0;
  2882. cc.im = 0;
  2883. switch (cal_type) {
  2884. case 0:
  2885. wlc_lcnphy_get_tx_iqcc(pi, &a, &b);
  2886. cc.re = a;
  2887. cc.im = b;
  2888. break;
  2889. case 2:
  2890. didq = wlc_lcnphy_get_tx_locc(pi);
  2891. di0 = (((didq & 0xff00) << 16) >> 24);
  2892. dq0 = (((didq & 0x00ff) << 24) >> 24);
  2893. cc.re = (u16) di0;
  2894. cc.im = (u16) dq0;
  2895. break;
  2896. case 3:
  2897. wlc_lcnphy_get_radio_loft(pi, &ei, &eq, &fi, &fq);
  2898. cc.re = (u16) ei;
  2899. cc.im = (u16) eq;
  2900. break;
  2901. case 4:
  2902. wlc_lcnphy_get_radio_loft(pi, &ei, &eq, &fi, &fq);
  2903. cc.re = (u16) fi;
  2904. cc.im = (u16) fq;
  2905. break;
  2906. }
  2907. return cc;
  2908. }
  2909. static void
  2910. wlc_lcnphy_samp_cap(struct brcms_phy *pi, int clip_detect_algo, u16 thresh,
  2911. s16 *ptr, int mode)
  2912. {
  2913. u32 curval1, curval2, stpptr, curptr, strptr, val;
  2914. u16 sslpnCalibClkEnCtrl, timer;
  2915. u16 old_sslpnCalibClkEnCtrl;
  2916. s16 imag, real;
  2917. struct brcms_phy_lcnphy *pi_lcn = pi->u.pi_lcnphy;
  2918. timer = 0;
  2919. old_sslpnCalibClkEnCtrl = read_phy_reg(pi, 0x6da);
  2920. curval1 = R_REG(&pi->regs->psm_corectlsts);
  2921. ptr[130] = 0;
  2922. W_REG(&pi->regs->psm_corectlsts, ((1 << 6) | curval1));
  2923. W_REG(&pi->regs->smpl_clct_strptr, 0x7E00);
  2924. W_REG(&pi->regs->smpl_clct_stpptr, 0x8000);
  2925. udelay(20);
  2926. curval2 = R_REG(&pi->regs->psm_phy_hdr_param);
  2927. W_REG(&pi->regs->psm_phy_hdr_param, curval2 | 0x30);
  2928. write_phy_reg(pi, 0x555, 0x0);
  2929. write_phy_reg(pi, 0x5a6, 0x5);
  2930. write_phy_reg(pi, 0x5a2, (u16) (mode | mode << 6));
  2931. write_phy_reg(pi, 0x5cf, 3);
  2932. write_phy_reg(pi, 0x5a5, 0x3);
  2933. write_phy_reg(pi, 0x583, 0x0);
  2934. write_phy_reg(pi, 0x584, 0x0);
  2935. write_phy_reg(pi, 0x585, 0x0fff);
  2936. write_phy_reg(pi, 0x586, 0x0000);
  2937. write_phy_reg(pi, 0x580, 0x4501);
  2938. sslpnCalibClkEnCtrl = read_phy_reg(pi, 0x6da);
  2939. write_phy_reg(pi, 0x6da, (u32) (sslpnCalibClkEnCtrl | 0x2008));
  2940. stpptr = R_REG(&pi->regs->smpl_clct_stpptr);
  2941. curptr = R_REG(&pi->regs->smpl_clct_curptr);
  2942. do {
  2943. udelay(10);
  2944. curptr = R_REG(&pi->regs->smpl_clct_curptr);
  2945. timer++;
  2946. } while ((curptr != stpptr) && (timer < 500));
  2947. W_REG(&pi->regs->psm_phy_hdr_param, 0x2);
  2948. strptr = 0x7E00;
  2949. W_REG(&pi->regs->tplatewrptr, strptr);
  2950. while (strptr < 0x8000) {
  2951. val = R_REG(&pi->regs->tplatewrdata);
  2952. imag = ((val >> 16) & 0x3ff);
  2953. real = ((val) & 0x3ff);
  2954. if (imag > 511)
  2955. imag -= 1024;
  2956. if (real > 511)
  2957. real -= 1024;
  2958. if (pi_lcn->lcnphy_iqcal_swp_dis)
  2959. ptr[(strptr - 0x7E00) / 4] = real;
  2960. else
  2961. ptr[(strptr - 0x7E00) / 4] = imag;
  2962. if (clip_detect_algo) {
  2963. if (imag > thresh || imag < -thresh) {
  2964. strptr = 0x8000;
  2965. ptr[130] = 1;
  2966. }
  2967. }
  2968. strptr += 4;
  2969. }
  2970. write_phy_reg(pi, 0x6da, old_sslpnCalibClkEnCtrl);
  2971. W_REG(&pi->regs->psm_phy_hdr_param, curval2);
  2972. W_REG(&pi->regs->psm_corectlsts, curval1);
  2973. }
  2974. static void
  2975. wlc_lcnphy_a1(struct brcms_phy *pi, int cal_type, int num_levels,
  2976. int step_size_lg2)
  2977. {
  2978. const struct lcnphy_spb_tone *phy_c1;
  2979. struct lcnphy_spb_tone phy_c2;
  2980. struct lcnphy_unsign16_struct phy_c3;
  2981. int phy_c4, phy_c5, k, l, j, phy_c6;
  2982. u16 phy_c7, phy_c8, phy_c9;
  2983. s16 phy_c10, phy_c11, phy_c12, phy_c13, phy_c14, phy_c15, phy_c16;
  2984. s16 *ptr, phy_c17;
  2985. s32 phy_c18, phy_c19;
  2986. u32 phy_c20, phy_c21;
  2987. bool phy_c22, phy_c23, phy_c24, phy_c25;
  2988. u16 phy_c26, phy_c27;
  2989. u16 phy_c28, phy_c29, phy_c30;
  2990. u16 phy_c31;
  2991. u16 *phy_c32;
  2992. phy_c21 = 0;
  2993. phy_c10 = phy_c13 = phy_c14 = phy_c8 = 0;
  2994. ptr = kmalloc(sizeof(s16) * 131, GFP_ATOMIC);
  2995. if (NULL == ptr)
  2996. return;
  2997. phy_c32 = kmalloc(sizeof(u16) * 20, GFP_ATOMIC);
  2998. if (NULL == phy_c32) {
  2999. kfree(ptr);
  3000. return;
  3001. }
  3002. phy_c26 = read_phy_reg(pi, 0x6da);
  3003. phy_c27 = read_phy_reg(pi, 0x6db);
  3004. phy_c31 = read_radio_reg(pi, RADIO_2064_REG026);
  3005. write_phy_reg(pi, 0x93d, 0xC0);
  3006. wlc_lcnphy_start_tx_tone(pi, 3750, 88, 0);
  3007. write_phy_reg(pi, 0x6da, 0xffff);
  3008. or_phy_reg(pi, 0x6db, 0x3);
  3009. wlc_lcnphy_tx_iqlo_loopback(pi, phy_c32);
  3010. udelay(500);
  3011. phy_c28 = read_phy_reg(pi, 0x938);
  3012. phy_c29 = read_phy_reg(pi, 0x4d7);
  3013. phy_c30 = read_phy_reg(pi, 0x4d8);
  3014. or_phy_reg(pi, 0x938, 0x1 << 2);
  3015. or_phy_reg(pi, 0x4d7, 0x1 << 2);
  3016. or_phy_reg(pi, 0x4d7, 0x1 << 3);
  3017. mod_phy_reg(pi, 0x4d7, (0x7 << 12), 0x2 << 12);
  3018. or_phy_reg(pi, 0x4d8, 1 << 0);
  3019. or_phy_reg(pi, 0x4d8, 1 << 1);
  3020. mod_phy_reg(pi, 0x4d8, (0x3ff << 2), 0x23A << 2);
  3021. mod_phy_reg(pi, 0x4d8, (0x7 << 12), 0x7 << 12);
  3022. phy_c1 = &lcnphy_spb_tone_3750[0];
  3023. phy_c4 = 32;
  3024. if (num_levels == 0) {
  3025. if (cal_type != 0)
  3026. num_levels = 4;
  3027. else
  3028. num_levels = 9;
  3029. }
  3030. if (step_size_lg2 == 0) {
  3031. if (cal_type != 0)
  3032. step_size_lg2 = 3;
  3033. else
  3034. step_size_lg2 = 8;
  3035. }
  3036. phy_c7 = (1 << step_size_lg2);
  3037. phy_c3 = wlc_lcnphy_get_cc(pi, cal_type);
  3038. phy_c15 = (s16) phy_c3.re;
  3039. phy_c16 = (s16) phy_c3.im;
  3040. if (cal_type == 2) {
  3041. if (phy_c3.re > 127)
  3042. phy_c15 = phy_c3.re - 256;
  3043. if (phy_c3.im > 127)
  3044. phy_c16 = phy_c3.im - 256;
  3045. }
  3046. wlc_lcnphy_set_cc(pi, cal_type, phy_c15, phy_c16);
  3047. udelay(20);
  3048. for (phy_c8 = 0; phy_c7 != 0 && phy_c8 < num_levels; phy_c8++) {
  3049. phy_c23 = 1;
  3050. phy_c22 = 0;
  3051. switch (cal_type) {
  3052. case 0:
  3053. phy_c10 = 511;
  3054. break;
  3055. case 2:
  3056. phy_c10 = 127;
  3057. break;
  3058. case 3:
  3059. phy_c10 = 15;
  3060. break;
  3061. case 4:
  3062. phy_c10 = 15;
  3063. break;
  3064. }
  3065. phy_c9 = read_phy_reg(pi, 0x93d);
  3066. phy_c9 = 2 * phy_c9;
  3067. phy_c24 = 0;
  3068. phy_c5 = 7;
  3069. phy_c25 = 1;
  3070. while (1) {
  3071. write_radio_reg(pi, RADIO_2064_REG026,
  3072. (phy_c5 & 0x7) | ((phy_c5 & 0x7) << 4));
  3073. udelay(50);
  3074. phy_c22 = 0;
  3075. ptr[130] = 0;
  3076. wlc_lcnphy_samp_cap(pi, 1, phy_c9, &ptr[0], 2);
  3077. if (ptr[130] == 1)
  3078. phy_c22 = 1;
  3079. if (phy_c22)
  3080. phy_c5 -= 1;
  3081. if ((phy_c22 != phy_c24) && (!phy_c25))
  3082. break;
  3083. if (!phy_c22)
  3084. phy_c5 += 1;
  3085. if (phy_c5 <= 0 || phy_c5 >= 7)
  3086. break;
  3087. phy_c24 = phy_c22;
  3088. phy_c25 = 0;
  3089. }
  3090. if (phy_c5 < 0)
  3091. phy_c5 = 0;
  3092. else if (phy_c5 > 7)
  3093. phy_c5 = 7;
  3094. for (k = -phy_c7; k <= phy_c7; k += phy_c7) {
  3095. for (l = -phy_c7; l <= phy_c7; l += phy_c7) {
  3096. phy_c11 = phy_c15 + k;
  3097. phy_c12 = phy_c16 + l;
  3098. if (phy_c11 < -phy_c10)
  3099. phy_c11 = -phy_c10;
  3100. else if (phy_c11 > phy_c10)
  3101. phy_c11 = phy_c10;
  3102. if (phy_c12 < -phy_c10)
  3103. phy_c12 = -phy_c10;
  3104. else if (phy_c12 > phy_c10)
  3105. phy_c12 = phy_c10;
  3106. wlc_lcnphy_set_cc(pi, cal_type, phy_c11,
  3107. phy_c12);
  3108. udelay(20);
  3109. wlc_lcnphy_samp_cap(pi, 0, 0, ptr, 2);
  3110. phy_c18 = 0;
  3111. phy_c19 = 0;
  3112. for (j = 0; j < 128; j++) {
  3113. if (cal_type != 0)
  3114. phy_c6 = j % phy_c4;
  3115. else
  3116. phy_c6 = (2 * j) % phy_c4;
  3117. phy_c2.re = phy_c1[phy_c6].re;
  3118. phy_c2.im = phy_c1[phy_c6].im;
  3119. phy_c17 = ptr[j];
  3120. phy_c18 = phy_c18 + phy_c17 * phy_c2.re;
  3121. phy_c19 = phy_c19 + phy_c17 * phy_c2.im;
  3122. }
  3123. phy_c18 = phy_c18 >> 10;
  3124. phy_c19 = phy_c19 >> 10;
  3125. phy_c20 = ((phy_c18 * phy_c18) +
  3126. (phy_c19 * phy_c19));
  3127. if (phy_c23 || phy_c20 < phy_c21) {
  3128. phy_c21 = phy_c20;
  3129. phy_c13 = phy_c11;
  3130. phy_c14 = phy_c12;
  3131. }
  3132. phy_c23 = 0;
  3133. }
  3134. }
  3135. phy_c23 = 1;
  3136. phy_c15 = phy_c13;
  3137. phy_c16 = phy_c14;
  3138. phy_c7 = phy_c7 >> 1;
  3139. wlc_lcnphy_set_cc(pi, cal_type, phy_c15, phy_c16);
  3140. udelay(20);
  3141. }
  3142. goto cleanup;
  3143. cleanup:
  3144. wlc_lcnphy_tx_iqlo_loopback_cleanup(pi, phy_c32);
  3145. wlc_lcnphy_stop_tx_tone(pi);
  3146. write_phy_reg(pi, 0x6da, phy_c26);
  3147. write_phy_reg(pi, 0x6db, phy_c27);
  3148. write_phy_reg(pi, 0x938, phy_c28);
  3149. write_phy_reg(pi, 0x4d7, phy_c29);
  3150. write_phy_reg(pi, 0x4d8, phy_c30);
  3151. write_radio_reg(pi, RADIO_2064_REG026, phy_c31);
  3152. kfree(phy_c32);
  3153. kfree(ptr);
  3154. }
  3155. void wlc_lcnphy_get_tx_iqcc(struct brcms_phy *pi, u16 *a, u16 *b)
  3156. {
  3157. u16 iqcc[2];
  3158. struct phytbl_info tab;
  3159. tab.tbl_ptr = iqcc;
  3160. tab.tbl_len = 2;
  3161. tab.tbl_id = 0;
  3162. tab.tbl_offset = 80;
  3163. tab.tbl_width = 16;
  3164. wlc_lcnphy_read_table(pi, &tab);
  3165. *a = iqcc[0];
  3166. *b = iqcc[1];
  3167. }
  3168. static void wlc_lcnphy_tx_iqlo_soft_cal_full(struct brcms_phy *pi)
  3169. {
  3170. struct lcnphy_unsign16_struct iqcc0, locc2, locc3, locc4;
  3171. wlc_lcnphy_set_cc(pi, 0, 0, 0);
  3172. wlc_lcnphy_set_cc(pi, 2, 0, 0);
  3173. wlc_lcnphy_set_cc(pi, 3, 0, 0);
  3174. wlc_lcnphy_set_cc(pi, 4, 0, 0);
  3175. wlc_lcnphy_a1(pi, 4, 0, 0);
  3176. wlc_lcnphy_a1(pi, 3, 0, 0);
  3177. wlc_lcnphy_a1(pi, 2, 3, 2);
  3178. wlc_lcnphy_a1(pi, 0, 5, 8);
  3179. wlc_lcnphy_a1(pi, 2, 2, 1);
  3180. wlc_lcnphy_a1(pi, 0, 4, 3);
  3181. iqcc0 = wlc_lcnphy_get_cc(pi, 0);
  3182. locc2 = wlc_lcnphy_get_cc(pi, 2);
  3183. locc3 = wlc_lcnphy_get_cc(pi, 3);
  3184. locc4 = wlc_lcnphy_get_cc(pi, 4);
  3185. }
  3186. u16 wlc_lcnphy_get_tx_locc(struct brcms_phy *pi)
  3187. {
  3188. struct phytbl_info tab;
  3189. u16 didq;
  3190. tab.tbl_id = 0;
  3191. tab.tbl_width = 16;
  3192. tab.tbl_ptr = &didq;
  3193. tab.tbl_len = 1;
  3194. tab.tbl_offset = 85;
  3195. wlc_lcnphy_read_table(pi, &tab);
  3196. return didq;
  3197. }
  3198. static void wlc_lcnphy_txpwrtbl_iqlo_cal(struct brcms_phy *pi)
  3199. {
  3200. struct lcnphy_txgains target_gains, old_gains;
  3201. u8 save_bb_mult;
  3202. u16 a, b, didq, save_pa_gain = 0;
  3203. uint idx, SAVE_txpwrindex = 0xFF;
  3204. u32 val;
  3205. u16 SAVE_txpwrctrl = wlc_lcnphy_get_tx_pwr_ctrl(pi);
  3206. struct phytbl_info tab;
  3207. u8 ei0, eq0, fi0, fq0;
  3208. struct brcms_phy_lcnphy *pi_lcn = pi->u.pi_lcnphy;
  3209. wlc_lcnphy_get_tx_gain(pi, &old_gains);
  3210. save_pa_gain = wlc_lcnphy_get_pa_gain(pi);
  3211. save_bb_mult = wlc_lcnphy_get_bbmult(pi);
  3212. if (SAVE_txpwrctrl == LCNPHY_TX_PWR_CTRL_OFF)
  3213. SAVE_txpwrindex = wlc_lcnphy_get_current_tx_pwr_idx(pi);
  3214. wlc_lcnphy_set_tx_pwr_ctrl(pi, LCNPHY_TX_PWR_CTRL_OFF);
  3215. target_gains.gm_gain = 7;
  3216. target_gains.pga_gain = 0;
  3217. target_gains.pad_gain = 21;
  3218. target_gains.dac_gain = 0;
  3219. wlc_lcnphy_set_tx_gain(pi, &target_gains);
  3220. wlc_lcnphy_set_tx_pwr_by_index(pi, 16);
  3221. if (LCNREV_IS(pi->pubpi.phy_rev, 1) || pi_lcn->lcnphy_hw_iqcal_en) {
  3222. wlc_lcnphy_set_tx_pwr_by_index(pi, 30);
  3223. wlc_lcnphy_tx_iqlo_cal(pi, &target_gains,
  3224. (pi_lcn->
  3225. lcnphy_recal ? LCNPHY_CAL_RECAL :
  3226. LCNPHY_CAL_FULL), false);
  3227. } else {
  3228. wlc_lcnphy_tx_iqlo_soft_cal_full(pi);
  3229. }
  3230. wlc_lcnphy_get_radio_loft(pi, &ei0, &eq0, &fi0, &fq0);
  3231. if ((abs((s8) fi0) == 15) && (abs((s8) fq0) == 15)) {
  3232. if (CHSPEC_IS5G(pi->radio_chanspec)) {
  3233. target_gains.gm_gain = 255;
  3234. target_gains.pga_gain = 255;
  3235. target_gains.pad_gain = 0xf0;
  3236. target_gains.dac_gain = 0;
  3237. } else {
  3238. target_gains.gm_gain = 7;
  3239. target_gains.pga_gain = 45;
  3240. target_gains.pad_gain = 186;
  3241. target_gains.dac_gain = 0;
  3242. }
  3243. if (LCNREV_IS(pi->pubpi.phy_rev, 1)
  3244. || pi_lcn->lcnphy_hw_iqcal_en) {
  3245. target_gains.pga_gain = 0;
  3246. target_gains.pad_gain = 30;
  3247. wlc_lcnphy_set_tx_pwr_by_index(pi, 16);
  3248. wlc_lcnphy_tx_iqlo_cal(pi, &target_gains,
  3249. LCNPHY_CAL_FULL, false);
  3250. } else {
  3251. wlc_lcnphy_tx_iqlo_soft_cal_full(pi);
  3252. }
  3253. }
  3254. wlc_lcnphy_get_tx_iqcc(pi, &a, &b);
  3255. didq = wlc_lcnphy_get_tx_locc(pi);
  3256. tab.tbl_id = LCNPHY_TBL_ID_TXPWRCTL;
  3257. tab.tbl_width = 32;
  3258. tab.tbl_ptr = &val;
  3259. tab.tbl_len = 1;
  3260. tab.tbl_offset = LCNPHY_TX_PWR_CTRL_RATE_OFFSET;
  3261. for (idx = 0; idx < 128; idx++) {
  3262. tab.tbl_offset = LCNPHY_TX_PWR_CTRL_IQ_OFFSET + idx;
  3263. wlc_lcnphy_read_table(pi, &tab);
  3264. val = (val & 0xfff00000) |
  3265. ((u32) (a & 0x3FF) << 10) | (b & 0x3ff);
  3266. wlc_lcnphy_write_table(pi, &tab);
  3267. val = didq;
  3268. tab.tbl_offset = LCNPHY_TX_PWR_CTRL_LO_OFFSET + idx;
  3269. wlc_lcnphy_write_table(pi, &tab);
  3270. }
  3271. pi_lcn->lcnphy_cal_results.txiqlocal_a = a;
  3272. pi_lcn->lcnphy_cal_results.txiqlocal_b = b;
  3273. pi_lcn->lcnphy_cal_results.txiqlocal_didq = didq;
  3274. pi_lcn->lcnphy_cal_results.txiqlocal_ei0 = ei0;
  3275. pi_lcn->lcnphy_cal_results.txiqlocal_eq0 = eq0;
  3276. pi_lcn->lcnphy_cal_results.txiqlocal_fi0 = fi0;
  3277. pi_lcn->lcnphy_cal_results.txiqlocal_fq0 = fq0;
  3278. wlc_lcnphy_set_bbmult(pi, save_bb_mult);
  3279. wlc_lcnphy_set_pa_gain(pi, save_pa_gain);
  3280. wlc_lcnphy_set_tx_gain(pi, &old_gains);
  3281. if (SAVE_txpwrctrl != LCNPHY_TX_PWR_CTRL_OFF)
  3282. wlc_lcnphy_set_tx_pwr_ctrl(pi, SAVE_txpwrctrl);
  3283. else
  3284. wlc_lcnphy_set_tx_pwr_by_index(pi, SAVE_txpwrindex);
  3285. }
  3286. s16 wlc_lcnphy_tempsense_new(struct brcms_phy *pi, bool mode)
  3287. {
  3288. u16 tempsenseval1, tempsenseval2;
  3289. s16 avg = 0;
  3290. bool suspend = 0;
  3291. if (mode == 1) {
  3292. suspend =
  3293. (0 ==
  3294. (R_REG(&pi->regs->maccontrol) & MCTL_EN_MAC));
  3295. if (!suspend)
  3296. wlapi_suspend_mac_and_wait(pi->sh->physhim);
  3297. wlc_lcnphy_vbat_temp_sense_setup(pi, TEMPSENSE);
  3298. }
  3299. tempsenseval1 = read_phy_reg(pi, 0x476) & 0x1FF;
  3300. tempsenseval2 = read_phy_reg(pi, 0x477) & 0x1FF;
  3301. if (tempsenseval1 > 255)
  3302. avg = (s16) (tempsenseval1 - 512);
  3303. else
  3304. avg = (s16) tempsenseval1;
  3305. if (tempsenseval2 > 255)
  3306. avg += (s16) (tempsenseval2 - 512);
  3307. else
  3308. avg += (s16) tempsenseval2;
  3309. avg /= 2;
  3310. if (mode == 1) {
  3311. mod_phy_reg(pi, 0x448, (0x1 << 14), (1) << 14);
  3312. udelay(100);
  3313. mod_phy_reg(pi, 0x448, (0x1 << 14), (0) << 14);
  3314. if (!suspend)
  3315. wlapi_enable_mac(pi->sh->physhim);
  3316. }
  3317. return avg;
  3318. }
  3319. u16 wlc_lcnphy_tempsense(struct brcms_phy *pi, bool mode)
  3320. {
  3321. u16 tempsenseval1, tempsenseval2;
  3322. s32 avg = 0;
  3323. bool suspend = 0;
  3324. u16 SAVE_txpwrctrl = wlc_lcnphy_get_tx_pwr_ctrl(pi);
  3325. struct brcms_phy_lcnphy *pi_lcn = pi->u.pi_lcnphy;
  3326. if (mode == 1) {
  3327. suspend =
  3328. (0 ==
  3329. (R_REG(&pi->regs->maccontrol) & MCTL_EN_MAC));
  3330. if (!suspend)
  3331. wlapi_suspend_mac_and_wait(pi->sh->physhim);
  3332. wlc_lcnphy_vbat_temp_sense_setup(pi, TEMPSENSE);
  3333. }
  3334. tempsenseval1 = read_phy_reg(pi, 0x476) & 0x1FF;
  3335. tempsenseval2 = read_phy_reg(pi, 0x477) & 0x1FF;
  3336. if (tempsenseval1 > 255)
  3337. avg = (int)(tempsenseval1 - 512);
  3338. else
  3339. avg = (int)tempsenseval1;
  3340. if (pi_lcn->lcnphy_tempsense_option == 1 || pi->hwpwrctrl_capable) {
  3341. if (tempsenseval2 > 255)
  3342. avg = (int)(avg - tempsenseval2 + 512);
  3343. else
  3344. avg = (int)(avg - tempsenseval2);
  3345. } else {
  3346. if (tempsenseval2 > 255)
  3347. avg = (int)(avg + tempsenseval2 - 512);
  3348. else
  3349. avg = (int)(avg + tempsenseval2);
  3350. avg = avg / 2;
  3351. }
  3352. if (avg < 0)
  3353. avg = avg + 512;
  3354. if (pi_lcn->lcnphy_tempsense_option == 2)
  3355. avg = tempsenseval1;
  3356. if (mode)
  3357. wlc_lcnphy_set_tx_pwr_ctrl(pi, SAVE_txpwrctrl);
  3358. if (mode == 1) {
  3359. mod_phy_reg(pi, 0x448, (0x1 << 14), (1) << 14);
  3360. udelay(100);
  3361. mod_phy_reg(pi, 0x448, (0x1 << 14), (0) << 14);
  3362. if (!suspend)
  3363. wlapi_enable_mac(pi->sh->physhim);
  3364. }
  3365. return (u16) avg;
  3366. }
  3367. s8 wlc_lcnphy_tempsense_degree(struct brcms_phy *pi, bool mode)
  3368. {
  3369. s32 degree = wlc_lcnphy_tempsense_new(pi, mode);
  3370. degree =
  3371. ((degree <<
  3372. 10) + LCN_TEMPSENSE_OFFSET + (LCN_TEMPSENSE_DEN >> 1))
  3373. / LCN_TEMPSENSE_DEN;
  3374. return (s8) degree;
  3375. }
  3376. s8 wlc_lcnphy_vbatsense(struct brcms_phy *pi, bool mode)
  3377. {
  3378. u16 vbatsenseval;
  3379. s32 avg = 0;
  3380. bool suspend = 0;
  3381. if (mode == 1) {
  3382. suspend =
  3383. (0 ==
  3384. (R_REG(&pi->regs->maccontrol) & MCTL_EN_MAC));
  3385. if (!suspend)
  3386. wlapi_suspend_mac_and_wait(pi->sh->physhim);
  3387. wlc_lcnphy_vbat_temp_sense_setup(pi, VBATSENSE);
  3388. }
  3389. vbatsenseval = read_phy_reg(pi, 0x475) & 0x1FF;
  3390. if (vbatsenseval > 255)
  3391. avg = (s32) (vbatsenseval - 512);
  3392. else
  3393. avg = (s32) vbatsenseval;
  3394. avg = (avg * LCN_VBAT_SCALE_NOM +
  3395. (LCN_VBAT_SCALE_DEN >> 1)) / LCN_VBAT_SCALE_DEN;
  3396. if (mode == 1) {
  3397. if (!suspend)
  3398. wlapi_enable_mac(pi->sh->physhim);
  3399. }
  3400. return (s8) avg;
  3401. }
  3402. static void wlc_lcnphy_afe_clk_init(struct brcms_phy *pi, u8 mode)
  3403. {
  3404. u8 phybw40;
  3405. phybw40 = CHSPEC_IS40(pi->radio_chanspec);
  3406. mod_phy_reg(pi, 0x6d1, (0x1 << 7), (1) << 7);
  3407. if (((mode == AFE_CLK_INIT_MODE_PAPD) && (phybw40 == 0)) ||
  3408. (mode == AFE_CLK_INIT_MODE_TXRX2X))
  3409. write_phy_reg(pi, 0x6d0, 0x7);
  3410. wlc_lcnphy_toggle_afe_pwdn(pi);
  3411. }
  3412. static void wlc_lcnphy_temp_adj(struct brcms_phy *pi)
  3413. {
  3414. }
  3415. static void wlc_lcnphy_glacial_timer_based_cal(struct brcms_phy *pi)
  3416. {
  3417. bool suspend;
  3418. s8 index;
  3419. u16 SAVE_pwrctrl = wlc_lcnphy_get_tx_pwr_ctrl(pi);
  3420. struct brcms_phy_lcnphy *pi_lcn = pi->u.pi_lcnphy;
  3421. suspend =
  3422. (0 == (R_REG(&pi->regs->maccontrol) & MCTL_EN_MAC));
  3423. if (!suspend)
  3424. wlapi_suspend_mac_and_wait(pi->sh->physhim);
  3425. wlc_lcnphy_deaf_mode(pi, true);
  3426. pi->phy_lastcal = pi->sh->now;
  3427. pi->phy_forcecal = false;
  3428. index = pi_lcn->lcnphy_current_index;
  3429. wlc_lcnphy_txpwrtbl_iqlo_cal(pi);
  3430. wlc_lcnphy_set_tx_pwr_by_index(pi, index);
  3431. wlc_lcnphy_set_tx_pwr_ctrl(pi, SAVE_pwrctrl);
  3432. wlc_lcnphy_deaf_mode(pi, false);
  3433. if (!suspend)
  3434. wlapi_enable_mac(pi->sh->physhim);
  3435. }
  3436. static void wlc_lcnphy_periodic_cal(struct brcms_phy *pi)
  3437. {
  3438. bool suspend, full_cal;
  3439. const struct lcnphy_rx_iqcomp *rx_iqcomp;
  3440. int rx_iqcomp_sz;
  3441. u16 SAVE_pwrctrl = wlc_lcnphy_get_tx_pwr_ctrl(pi);
  3442. s8 index;
  3443. struct phytbl_info tab;
  3444. s32 a1, b0, b1;
  3445. s32 tssi, pwr, maxtargetpwr, mintargetpwr;
  3446. struct brcms_phy_lcnphy *pi_lcn = pi->u.pi_lcnphy;
  3447. pi->phy_lastcal = pi->sh->now;
  3448. pi->phy_forcecal = false;
  3449. full_cal =
  3450. (pi_lcn->lcnphy_full_cal_channel !=
  3451. CHSPEC_CHANNEL(pi->radio_chanspec));
  3452. pi_lcn->lcnphy_full_cal_channel = CHSPEC_CHANNEL(pi->radio_chanspec);
  3453. index = pi_lcn->lcnphy_current_index;
  3454. suspend =
  3455. (0 == (R_REG(&pi->regs->maccontrol) & MCTL_EN_MAC));
  3456. if (!suspend) {
  3457. wlapi_bmac_write_shm(pi->sh->physhim, M_CTS_DURATION, 10000);
  3458. wlapi_suspend_mac_and_wait(pi->sh->physhim);
  3459. }
  3460. wlc_lcnphy_deaf_mode(pi, true);
  3461. wlc_lcnphy_txpwrtbl_iqlo_cal(pi);
  3462. rx_iqcomp = lcnphy_rx_iqcomp_table_rev0;
  3463. rx_iqcomp_sz = ARRAY_SIZE(lcnphy_rx_iqcomp_table_rev0);
  3464. if (LCNREV_IS(pi->pubpi.phy_rev, 1))
  3465. wlc_lcnphy_rx_iq_cal(pi, NULL, 0, true, false, 1, 40);
  3466. else
  3467. wlc_lcnphy_rx_iq_cal(pi, NULL, 0, true, false, 1, 127);
  3468. if (wlc_lcnphy_tssi_based_pwr_ctrl_enabled(pi)) {
  3469. wlc_lcnphy_idle_tssi_est((struct brcms_phy_pub *) pi);
  3470. b0 = pi->txpa_2g[0];
  3471. b1 = pi->txpa_2g[1];
  3472. a1 = pi->txpa_2g[2];
  3473. maxtargetpwr = wlc_lcnphy_tssi2dbm(10, a1, b0, b1);
  3474. mintargetpwr = wlc_lcnphy_tssi2dbm(125, a1, b0, b1);
  3475. tab.tbl_id = LCNPHY_TBL_ID_TXPWRCTL;
  3476. tab.tbl_width = 32;
  3477. tab.tbl_ptr = &pwr;
  3478. tab.tbl_len = 1;
  3479. tab.tbl_offset = 0;
  3480. for (tssi = 0; tssi < 128; tssi++) {
  3481. pwr = wlc_lcnphy_tssi2dbm(tssi, a1, b0, b1);
  3482. pwr = (pwr < mintargetpwr) ? mintargetpwr : pwr;
  3483. wlc_lcnphy_write_table(pi, &tab);
  3484. tab.tbl_offset++;
  3485. }
  3486. }
  3487. wlc_lcnphy_set_tx_pwr_by_index(pi, index);
  3488. wlc_lcnphy_set_tx_pwr_ctrl(pi, SAVE_pwrctrl);
  3489. wlc_lcnphy_deaf_mode(pi, false);
  3490. if (!suspend)
  3491. wlapi_enable_mac(pi->sh->physhim);
  3492. }
  3493. void wlc_lcnphy_calib_modes(struct brcms_phy *pi, uint mode)
  3494. {
  3495. u16 temp_new;
  3496. int temp1, temp2, temp_diff;
  3497. struct brcms_phy_lcnphy *pi_lcn = pi->u.pi_lcnphy;
  3498. switch (mode) {
  3499. case PHY_PERICAL_CHAN:
  3500. break;
  3501. case PHY_FULLCAL:
  3502. wlc_lcnphy_periodic_cal(pi);
  3503. break;
  3504. case PHY_PERICAL_PHYINIT:
  3505. wlc_lcnphy_periodic_cal(pi);
  3506. break;
  3507. case PHY_PERICAL_WATCHDOG:
  3508. if (wlc_lcnphy_tempsense_based_pwr_ctrl_enabled(pi)) {
  3509. temp_new = wlc_lcnphy_tempsense(pi, 0);
  3510. temp1 = LCNPHY_TEMPSENSE(temp_new);
  3511. temp2 = LCNPHY_TEMPSENSE(pi_lcn->lcnphy_cal_temper);
  3512. temp_diff = temp1 - temp2;
  3513. if ((pi_lcn->lcnphy_cal_counter > 90) ||
  3514. (temp_diff > 60) || (temp_diff < -60)) {
  3515. wlc_lcnphy_glacial_timer_based_cal(pi);
  3516. wlc_2064_vco_cal(pi);
  3517. pi_lcn->lcnphy_cal_temper = temp_new;
  3518. pi_lcn->lcnphy_cal_counter = 0;
  3519. } else
  3520. pi_lcn->lcnphy_cal_counter++;
  3521. }
  3522. break;
  3523. case LCNPHY_PERICAL_TEMPBASED_TXPWRCTRL:
  3524. if (wlc_lcnphy_tempsense_based_pwr_ctrl_enabled(pi))
  3525. wlc_lcnphy_tx_power_adjustment(
  3526. (struct brcms_phy_pub *) pi);
  3527. break;
  3528. }
  3529. }
  3530. void wlc_lcnphy_get_tssi(struct brcms_phy *pi, s8 *ofdm_pwr, s8 *cck_pwr)
  3531. {
  3532. s8 cck_offset;
  3533. u16 status;
  3534. status = (read_phy_reg(pi, 0x4ab));
  3535. if (wlc_lcnphy_tssi_based_pwr_ctrl_enabled(pi) &&
  3536. (status & (0x1 << 15))) {
  3537. *ofdm_pwr = (s8) (((read_phy_reg(pi, 0x4ab) & (0x1ff << 0))
  3538. >> 0) >> 1);
  3539. if (wlc_phy_tpc_isenabled_lcnphy(pi))
  3540. cck_offset = pi->tx_power_offset[TXP_FIRST_CCK];
  3541. else
  3542. cck_offset = 0;
  3543. *cck_pwr = *ofdm_pwr + cck_offset;
  3544. } else {
  3545. *cck_pwr = 0;
  3546. *ofdm_pwr = 0;
  3547. }
  3548. }
  3549. void wlc_phy_cal_init_lcnphy(struct brcms_phy *pi)
  3550. {
  3551. return;
  3552. }
  3553. void wlc_lcnphy_tx_power_adjustment(struct brcms_phy_pub *ppi)
  3554. {
  3555. s8 index;
  3556. u16 index2;
  3557. struct brcms_phy *pi = (struct brcms_phy *) ppi;
  3558. struct brcms_phy_lcnphy *pi_lcn = pi->u.pi_lcnphy;
  3559. u16 SAVE_txpwrctrl = wlc_lcnphy_get_tx_pwr_ctrl(pi);
  3560. if (wlc_lcnphy_tempsense_based_pwr_ctrl_enabled(pi) &&
  3561. SAVE_txpwrctrl) {
  3562. index = wlc_lcnphy_tempcompensated_txpwrctrl(pi);
  3563. index2 = (u16) (index * 2);
  3564. mod_phy_reg(pi, 0x4a9, (0x1ff << 0), (index2) << 0);
  3565. pi_lcn->lcnphy_current_index =
  3566. (s8)((read_phy_reg(pi, 0x4a9) & 0xFF) / 2);
  3567. }
  3568. }
  3569. static void
  3570. wlc_lcnphy_load_tx_gain_table(struct brcms_phy *pi,
  3571. const struct lcnphy_tx_gain_tbl_entry *gain_table)
  3572. {
  3573. u32 j;
  3574. struct phytbl_info tab;
  3575. u32 val;
  3576. u16 pa_gain;
  3577. u16 gm_gain;
  3578. if (CHSPEC_IS5G(pi->radio_chanspec))
  3579. pa_gain = 0x70;
  3580. else
  3581. pa_gain = 0x70;
  3582. if (pi->sh->boardflags & BFL_FEM)
  3583. pa_gain = 0x10;
  3584. tab.tbl_id = LCNPHY_TBL_ID_TXPWRCTL;
  3585. tab.tbl_width = 32;
  3586. tab.tbl_len = 1;
  3587. tab.tbl_ptr = &val;
  3588. for (j = 0; j < 128; j++) {
  3589. gm_gain = gain_table[j].gm;
  3590. val = (((u32) pa_gain << 24) |
  3591. (gain_table[j].pad << 16) |
  3592. (gain_table[j].pga << 8) | gm_gain);
  3593. tab.tbl_offset = LCNPHY_TX_PWR_CTRL_GAIN_OFFSET + j;
  3594. wlc_lcnphy_write_table(pi, &tab);
  3595. val = (gain_table[j].dac << 28) | (gain_table[j].bb_mult << 20);
  3596. tab.tbl_offset = LCNPHY_TX_PWR_CTRL_IQ_OFFSET + j;
  3597. wlc_lcnphy_write_table(pi, &tab);
  3598. }
  3599. }
  3600. static void wlc_lcnphy_load_rfpower(struct brcms_phy *pi)
  3601. {
  3602. struct phytbl_info tab;
  3603. u32 val, bbmult, rfgain;
  3604. u8 index;
  3605. u8 scale_factor = 1;
  3606. s16 temp, temp1, temp2, qQ, qQ1, qQ2, shift;
  3607. tab.tbl_id = LCNPHY_TBL_ID_TXPWRCTL;
  3608. tab.tbl_width = 32;
  3609. tab.tbl_len = 1;
  3610. for (index = 0; index < 128; index++) {
  3611. tab.tbl_ptr = &bbmult;
  3612. tab.tbl_offset = LCNPHY_TX_PWR_CTRL_IQ_OFFSET + index;
  3613. wlc_lcnphy_read_table(pi, &tab);
  3614. bbmult = bbmult >> 20;
  3615. tab.tbl_ptr = &rfgain;
  3616. tab.tbl_offset = LCNPHY_TX_PWR_CTRL_GAIN_OFFSET + index;
  3617. wlc_lcnphy_read_table(pi, &tab);
  3618. qm_log10((s32) (bbmult), 0, &temp1, &qQ1);
  3619. qm_log10((s32) (1 << 6), 0, &temp2, &qQ2);
  3620. if (qQ1 < qQ2) {
  3621. temp2 = qm_shr16(temp2, qQ2 - qQ1);
  3622. qQ = qQ1;
  3623. } else {
  3624. temp1 = qm_shr16(temp1, qQ1 - qQ2);
  3625. qQ = qQ2;
  3626. }
  3627. temp = qm_sub16(temp1, temp2);
  3628. if (qQ >= 4)
  3629. shift = qQ - 4;
  3630. else
  3631. shift = 4 - qQ;
  3632. val = (((index << shift) + (5 * temp) +
  3633. (1 << (scale_factor + shift - 3))) >> (scale_factor +
  3634. shift - 2));
  3635. tab.tbl_ptr = &val;
  3636. tab.tbl_offset = LCNPHY_TX_PWR_CTRL_PWR_OFFSET + index;
  3637. wlc_lcnphy_write_table(pi, &tab);
  3638. }
  3639. }
  3640. static void wlc_lcnphy_bu_tweaks(struct brcms_phy *pi)
  3641. {
  3642. or_phy_reg(pi, 0x805, 0x1);
  3643. mod_phy_reg(pi, 0x42f, (0x7 << 0), (0x3) << 0);
  3644. mod_phy_reg(pi, 0x030, (0x7 << 0), (0x3) << 0);
  3645. write_phy_reg(pi, 0x414, 0x1e10);
  3646. write_phy_reg(pi, 0x415, 0x0640);
  3647. mod_phy_reg(pi, 0x4df, (0xff << 8), -9 << 8);
  3648. or_phy_reg(pi, 0x44a, 0x44);
  3649. write_phy_reg(pi, 0x44a, 0x80);
  3650. mod_phy_reg(pi, 0x434, (0xff << 0), (0xFD) << 0);
  3651. mod_phy_reg(pi, 0x420, (0xff << 0), (16) << 0);
  3652. if (!(pi->sh->boardrev < 0x1204))
  3653. mod_radio_reg(pi, RADIO_2064_REG09B, 0xF0, 0xF0);
  3654. write_phy_reg(pi, 0x7d6, 0x0902);
  3655. mod_phy_reg(pi, 0x429, (0xf << 0), (0x9) << 0);
  3656. mod_phy_reg(pi, 0x429, (0x3f << 4), (0xe) << 4);
  3657. if (LCNREV_IS(pi->pubpi.phy_rev, 1)) {
  3658. mod_phy_reg(pi, 0x423, (0xff << 0), (0x46) << 0);
  3659. mod_phy_reg(pi, 0x411, (0xff << 0), (1) << 0);
  3660. mod_phy_reg(pi, 0x434, (0xff << 0), (0xFF) << 0);
  3661. mod_phy_reg(pi, 0x656, (0xf << 0), (2) << 0);
  3662. mod_phy_reg(pi, 0x44d, (0x1 << 2), (1) << 2);
  3663. mod_radio_reg(pi, RADIO_2064_REG0F7, 0x4, 0x4);
  3664. mod_radio_reg(pi, RADIO_2064_REG0F1, 0x3, 0);
  3665. mod_radio_reg(pi, RADIO_2064_REG0F2, 0xF8, 0x90);
  3666. mod_radio_reg(pi, RADIO_2064_REG0F3, 0x3, 0x2);
  3667. mod_radio_reg(pi, RADIO_2064_REG0F3, 0xf0, 0xa0);
  3668. mod_radio_reg(pi, RADIO_2064_REG11F, 0x2, 0x2);
  3669. wlc_lcnphy_clear_tx_power_offsets(pi);
  3670. mod_phy_reg(pi, 0x4d0, (0x1ff << 6), (10) << 6);
  3671. }
  3672. }
  3673. static void wlc_lcnphy_rcal(struct brcms_phy *pi)
  3674. {
  3675. u8 rcal_value;
  3676. and_radio_reg(pi, RADIO_2064_REG05B, 0xfD);
  3677. or_radio_reg(pi, RADIO_2064_REG004, 0x40);
  3678. or_radio_reg(pi, RADIO_2064_REG120, 0x10);
  3679. or_radio_reg(pi, RADIO_2064_REG078, 0x80);
  3680. or_radio_reg(pi, RADIO_2064_REG129, 0x02);
  3681. or_radio_reg(pi, RADIO_2064_REG057, 0x01);
  3682. or_radio_reg(pi, RADIO_2064_REG05B, 0x02);
  3683. mdelay(5);
  3684. SPINWAIT(!wlc_radio_2064_rcal_done(pi), 10 * 1000 * 1000);
  3685. if (wlc_radio_2064_rcal_done(pi)) {
  3686. rcal_value = (u8) read_radio_reg(pi, RADIO_2064_REG05C);
  3687. rcal_value = rcal_value & 0x1f;
  3688. }
  3689. and_radio_reg(pi, RADIO_2064_REG05B, 0xfD);
  3690. and_radio_reg(pi, RADIO_2064_REG057, 0xFE);
  3691. }
  3692. static void wlc_lcnphy_rc_cal(struct brcms_phy *pi)
  3693. {
  3694. u8 dflt_rc_cal_val;
  3695. u16 flt_val;
  3696. dflt_rc_cal_val = 7;
  3697. if (LCNREV_IS(pi->pubpi.phy_rev, 1))
  3698. dflt_rc_cal_val = 11;
  3699. flt_val =
  3700. (dflt_rc_cal_val << 10) | (dflt_rc_cal_val << 5) |
  3701. (dflt_rc_cal_val);
  3702. write_phy_reg(pi, 0x933, flt_val);
  3703. write_phy_reg(pi, 0x934, flt_val);
  3704. write_phy_reg(pi, 0x935, flt_val);
  3705. write_phy_reg(pi, 0x936, flt_val);
  3706. write_phy_reg(pi, 0x937, (flt_val & 0x1FF));
  3707. return;
  3708. }
  3709. static void wlc_radio_2064_init(struct brcms_phy *pi)
  3710. {
  3711. u32 i;
  3712. const struct lcnphy_radio_regs *lcnphyregs = NULL;
  3713. lcnphyregs = lcnphy_radio_regs_2064;
  3714. for (i = 0; lcnphyregs[i].address != 0xffff; i++)
  3715. if (CHSPEC_IS5G(pi->radio_chanspec) && lcnphyregs[i].do_init_a)
  3716. write_radio_reg(pi,
  3717. ((lcnphyregs[i].address & 0x3fff) |
  3718. RADIO_DEFAULT_CORE),
  3719. (u16) lcnphyregs[i].init_a);
  3720. else if (lcnphyregs[i].do_init_g)
  3721. write_radio_reg(pi,
  3722. ((lcnphyregs[i].address & 0x3fff) |
  3723. RADIO_DEFAULT_CORE),
  3724. (u16) lcnphyregs[i].init_g);
  3725. write_radio_reg(pi, RADIO_2064_REG032, 0x62);
  3726. write_radio_reg(pi, RADIO_2064_REG033, 0x19);
  3727. write_radio_reg(pi, RADIO_2064_REG090, 0x10);
  3728. write_radio_reg(pi, RADIO_2064_REG010, 0x00);
  3729. if (LCNREV_IS(pi->pubpi.phy_rev, 1)) {
  3730. write_radio_reg(pi, RADIO_2064_REG060, 0x7f);
  3731. write_radio_reg(pi, RADIO_2064_REG061, 0x72);
  3732. write_radio_reg(pi, RADIO_2064_REG062, 0x7f);
  3733. }
  3734. write_radio_reg(pi, RADIO_2064_REG01D, 0x02);
  3735. write_radio_reg(pi, RADIO_2064_REG01E, 0x06);
  3736. mod_phy_reg(pi, 0x4ea, (0x7 << 0), 0 << 0);
  3737. mod_phy_reg(pi, 0x4ea, (0x7 << 3), 1 << 3);
  3738. mod_phy_reg(pi, 0x4ea, (0x7 << 6), 2 << 6);
  3739. mod_phy_reg(pi, 0x4ea, (0x7 << 9), 3 << 9);
  3740. mod_phy_reg(pi, 0x4ea, (0x7 << 12), 4 << 12);
  3741. write_phy_reg(pi, 0x4ea, 0x4688);
  3742. mod_phy_reg(pi, 0x4eb, (0x7 << 0), 2 << 0);
  3743. mod_phy_reg(pi, 0x4eb, (0x7 << 6), 0 << 6);
  3744. mod_phy_reg(pi, 0x46a, (0xffff << 0), 25 << 0);
  3745. wlc_lcnphy_set_tx_locc(pi, 0);
  3746. wlc_lcnphy_rcal(pi);
  3747. wlc_lcnphy_rc_cal(pi);
  3748. }
  3749. static void wlc_lcnphy_radio_init(struct brcms_phy *pi)
  3750. {
  3751. wlc_radio_2064_init(pi);
  3752. }
  3753. static void wlc_lcnphy_tbl_init(struct brcms_phy *pi)
  3754. {
  3755. uint idx;
  3756. u8 phybw40;
  3757. struct phytbl_info tab;
  3758. u32 val;
  3759. phybw40 = CHSPEC_IS40(pi->radio_chanspec);
  3760. for (idx = 0; idx < dot11lcnphytbl_info_sz_rev0; idx++)
  3761. wlc_lcnphy_write_table(pi, &dot11lcnphytbl_info_rev0[idx]);
  3762. if (pi->sh->boardflags & BFL_FEM_BT) {
  3763. tab.tbl_id = LCNPHY_TBL_ID_RFSEQ;
  3764. tab.tbl_width = 16;
  3765. tab.tbl_ptr = &val;
  3766. tab.tbl_len = 1;
  3767. val = 100;
  3768. tab.tbl_offset = 4;
  3769. wlc_lcnphy_write_table(pi, &tab);
  3770. }
  3771. tab.tbl_id = LCNPHY_TBL_ID_RFSEQ;
  3772. tab.tbl_width = 16;
  3773. tab.tbl_ptr = &val;
  3774. tab.tbl_len = 1;
  3775. val = 114;
  3776. tab.tbl_offset = 0;
  3777. wlc_lcnphy_write_table(pi, &tab);
  3778. val = 130;
  3779. tab.tbl_offset = 1;
  3780. wlc_lcnphy_write_table(pi, &tab);
  3781. val = 6;
  3782. tab.tbl_offset = 8;
  3783. wlc_lcnphy_write_table(pi, &tab);
  3784. if (CHSPEC_IS2G(pi->radio_chanspec)) {
  3785. if (pi->sh->boardflags & BFL_FEM)
  3786. wlc_lcnphy_load_tx_gain_table(
  3787. pi,
  3788. dot11lcnphy_2GHz_extPA_gaintable_rev0);
  3789. else
  3790. wlc_lcnphy_load_tx_gain_table(
  3791. pi,
  3792. dot11lcnphy_2GHz_gaintable_rev0);
  3793. }
  3794. if (LCNREV_IS(pi->pubpi.phy_rev, 2)) {
  3795. const struct phytbl_info *tb;
  3796. int l;
  3797. if (CHSPEC_IS2G(pi->radio_chanspec)) {
  3798. l = dot11lcnphytbl_rx_gain_info_2G_rev2_sz;
  3799. if (pi->sh->boardflags & BFL_EXTLNA)
  3800. tb = dot11lcnphytbl_rx_gain_info_extlna_2G_rev2;
  3801. else
  3802. tb = dot11lcnphytbl_rx_gain_info_2G_rev2;
  3803. } else {
  3804. l = dot11lcnphytbl_rx_gain_info_5G_rev2_sz;
  3805. if (pi->sh->boardflags & BFL_EXTLNA_5GHz)
  3806. tb = dot11lcnphytbl_rx_gain_info_extlna_5G_rev2;
  3807. else
  3808. tb = dot11lcnphytbl_rx_gain_info_5G_rev2;
  3809. }
  3810. for (idx = 0; idx < l; idx++)
  3811. wlc_lcnphy_write_table(pi, &tb[idx]);
  3812. }
  3813. if ((pi->sh->boardflags & BFL_FEM)
  3814. && !(pi->sh->boardflags & BFL_FEM_BT))
  3815. wlc_lcnphy_write_table(pi, &dot11lcn_sw_ctrl_tbl_info_4313_epa);
  3816. else if (pi->sh->boardflags & BFL_FEM_BT) {
  3817. if (pi->sh->boardrev < 0x1250)
  3818. wlc_lcnphy_write_table(
  3819. pi,
  3820. &dot11lcn_sw_ctrl_tbl_info_4313_bt_epa);
  3821. else
  3822. wlc_lcnphy_write_table(
  3823. pi,
  3824. &dot11lcn_sw_ctrl_tbl_info_4313_bt_epa_p250);
  3825. } else
  3826. wlc_lcnphy_write_table(pi, &dot11lcn_sw_ctrl_tbl_info_4313);
  3827. wlc_lcnphy_load_rfpower(pi);
  3828. wlc_lcnphy_clear_papd_comptable(pi);
  3829. }
  3830. static void wlc_lcnphy_rev0_baseband_init(struct brcms_phy *pi)
  3831. {
  3832. u16 afectrl1;
  3833. struct brcms_phy_lcnphy *pi_lcn = pi->u.pi_lcnphy;
  3834. write_radio_reg(pi, RADIO_2064_REG11C, 0x0);
  3835. write_phy_reg(pi, 0x43b, 0x0);
  3836. write_phy_reg(pi, 0x43c, 0x0);
  3837. write_phy_reg(pi, 0x44c, 0x0);
  3838. write_phy_reg(pi, 0x4e6, 0x0);
  3839. write_phy_reg(pi, 0x4f9, 0x0);
  3840. write_phy_reg(pi, 0x4b0, 0x0);
  3841. write_phy_reg(pi, 0x938, 0x0);
  3842. write_phy_reg(pi, 0x4b0, 0x0);
  3843. write_phy_reg(pi, 0x44e, 0);
  3844. or_phy_reg(pi, 0x567, 0x03);
  3845. or_phy_reg(pi, 0x44a, 0x44);
  3846. write_phy_reg(pi, 0x44a, 0x80);
  3847. if (!(pi->sh->boardflags & BFL_FEM))
  3848. wlc_lcnphy_set_tx_pwr_by_index(pi, 52);
  3849. if (0) {
  3850. afectrl1 = 0;
  3851. afectrl1 = (u16) ((pi_lcn->lcnphy_rssi_vf) |
  3852. (pi_lcn->lcnphy_rssi_vc << 4) |
  3853. (pi_lcn->lcnphy_rssi_gs << 10));
  3854. write_phy_reg(pi, 0x43e, afectrl1);
  3855. }
  3856. mod_phy_reg(pi, 0x634, (0xff << 0), 0xC << 0);
  3857. if (pi->sh->boardflags & BFL_FEM) {
  3858. mod_phy_reg(pi, 0x634, (0xff << 0), 0xA << 0);
  3859. write_phy_reg(pi, 0x910, 0x1);
  3860. }
  3861. mod_phy_reg(pi, 0x448, (0x3 << 8), 1 << 8);
  3862. mod_phy_reg(pi, 0x608, (0xff << 0), 0x17 << 0);
  3863. mod_phy_reg(pi, 0x604, (0x7ff << 0), 0x3EA << 0);
  3864. }
  3865. static void wlc_lcnphy_rev2_baseband_init(struct brcms_phy *pi)
  3866. {
  3867. if (CHSPEC_IS5G(pi->radio_chanspec)) {
  3868. mod_phy_reg(pi, 0x416, (0xff << 0), 80 << 0);
  3869. mod_phy_reg(pi, 0x416, (0xff << 8), 80 << 8);
  3870. }
  3871. }
  3872. static void wlc_lcnphy_agc_temp_init(struct brcms_phy *pi)
  3873. {
  3874. s16 temp;
  3875. struct phytbl_info tab;
  3876. u32 tableBuffer[2];
  3877. struct brcms_phy_lcnphy *pi_lcn = pi->u.pi_lcnphy;
  3878. temp = (s16) read_phy_reg(pi, 0x4df);
  3879. pi_lcn->lcnphy_ofdmgainidxtableoffset = (temp & (0xff << 0)) >> 0;
  3880. if (pi_lcn->lcnphy_ofdmgainidxtableoffset > 127)
  3881. pi_lcn->lcnphy_ofdmgainidxtableoffset -= 256;
  3882. pi_lcn->lcnphy_dsssgainidxtableoffset = (temp & (0xff << 8)) >> 8;
  3883. if (pi_lcn->lcnphy_dsssgainidxtableoffset > 127)
  3884. pi_lcn->lcnphy_dsssgainidxtableoffset -= 256;
  3885. tab.tbl_ptr = tableBuffer;
  3886. tab.tbl_len = 2;
  3887. tab.tbl_id = 17;
  3888. tab.tbl_offset = 59;
  3889. tab.tbl_width = 32;
  3890. wlc_lcnphy_read_table(pi, &tab);
  3891. if (tableBuffer[0] > 63)
  3892. tableBuffer[0] -= 128;
  3893. pi_lcn->lcnphy_tr_R_gain_val = tableBuffer[0];
  3894. if (tableBuffer[1] > 63)
  3895. tableBuffer[1] -= 128;
  3896. pi_lcn->lcnphy_tr_T_gain_val = tableBuffer[1];
  3897. temp = (s16) (read_phy_reg(pi, 0x434) & (0xff << 0));
  3898. if (temp > 127)
  3899. temp -= 256;
  3900. pi_lcn->lcnphy_input_pwr_offset_db = (s8) temp;
  3901. pi_lcn->lcnphy_Med_Low_Gain_db =
  3902. (read_phy_reg(pi, 0x424) & (0xff << 8)) >> 8;
  3903. pi_lcn->lcnphy_Very_Low_Gain_db =
  3904. (read_phy_reg(pi, 0x425) & (0xff << 0)) >> 0;
  3905. tab.tbl_ptr = tableBuffer;
  3906. tab.tbl_len = 2;
  3907. tab.tbl_id = LCNPHY_TBL_ID_GAIN_IDX;
  3908. tab.tbl_offset = 28;
  3909. tab.tbl_width = 32;
  3910. wlc_lcnphy_read_table(pi, &tab);
  3911. pi_lcn->lcnphy_gain_idx_14_lowword = tableBuffer[0];
  3912. pi_lcn->lcnphy_gain_idx_14_hiword = tableBuffer[1];
  3913. }
  3914. static void wlc_lcnphy_baseband_init(struct brcms_phy *pi)
  3915. {
  3916. wlc_lcnphy_tbl_init(pi);
  3917. wlc_lcnphy_rev0_baseband_init(pi);
  3918. if (LCNREV_IS(pi->pubpi.phy_rev, 2))
  3919. wlc_lcnphy_rev2_baseband_init(pi);
  3920. wlc_lcnphy_bu_tweaks(pi);
  3921. }
  3922. void wlc_phy_init_lcnphy(struct brcms_phy *pi)
  3923. {
  3924. u8 phybw40;
  3925. struct brcms_phy_lcnphy *pi_lcn = pi->u.pi_lcnphy;
  3926. phybw40 = CHSPEC_IS40(pi->radio_chanspec);
  3927. pi_lcn->lcnphy_cal_counter = 0;
  3928. pi_lcn->lcnphy_cal_temper = pi_lcn->lcnphy_rawtempsense;
  3929. or_phy_reg(pi, 0x44a, 0x80);
  3930. and_phy_reg(pi, 0x44a, 0x7f);
  3931. wlc_lcnphy_afe_clk_init(pi, AFE_CLK_INIT_MODE_TXRX2X);
  3932. write_phy_reg(pi, 0x60a, 160);
  3933. write_phy_reg(pi, 0x46a, 25);
  3934. wlc_lcnphy_baseband_init(pi);
  3935. wlc_lcnphy_radio_init(pi);
  3936. if (CHSPEC_IS2G(pi->radio_chanspec))
  3937. wlc_lcnphy_tx_pwr_ctrl_init((struct brcms_phy_pub *) pi);
  3938. wlc_phy_chanspec_set((struct brcms_phy_pub *) pi, pi->radio_chanspec);
  3939. si_pmu_regcontrol(pi->sh->sih, 0, 0xf, 0x9);
  3940. si_pmu_chipcontrol(pi->sh->sih, 0, 0xffffffff, 0x03CDDDDD);
  3941. if ((pi->sh->boardflags & BFL_FEM)
  3942. && wlc_lcnphy_tempsense_based_pwr_ctrl_enabled(pi))
  3943. wlc_lcnphy_set_tx_pwr_by_index(pi, FIXED_TXPWR);
  3944. wlc_lcnphy_agc_temp_init(pi);
  3945. wlc_lcnphy_temp_adj(pi);
  3946. mod_phy_reg(pi, 0x448, (0x1 << 14), (1) << 14);
  3947. udelay(100);
  3948. mod_phy_reg(pi, 0x448, (0x1 << 14), (0) << 14);
  3949. wlc_lcnphy_set_tx_pwr_ctrl(pi, LCNPHY_TX_PWR_CTRL_HW);
  3950. pi_lcn->lcnphy_noise_samples = LCNPHY_NOISE_SAMPLES_DEFAULT;
  3951. wlc_lcnphy_calib_modes(pi, PHY_PERICAL_PHYINIT);
  3952. }
  3953. static bool wlc_phy_txpwr_srom_read_lcnphy(struct brcms_phy *pi)
  3954. {
  3955. s8 txpwr = 0;
  3956. int i;
  3957. struct brcms_phy_lcnphy *pi_lcn = pi->u.pi_lcnphy;
  3958. struct phy_shim_info *shim = pi->sh->physhim;
  3959. if (CHSPEC_IS2G(pi->radio_chanspec)) {
  3960. u16 cckpo = 0;
  3961. u32 offset_ofdm, offset_mcs;
  3962. pi_lcn->lcnphy_tr_isolation_mid =
  3963. (u8)wlapi_getintvar(shim, BRCMS_SROM_TRISO2G);
  3964. pi_lcn->lcnphy_rx_power_offset =
  3965. (u8)wlapi_getintvar(shim, BRCMS_SROM_RXPO2G);
  3966. pi->txpa_2g[0] = (s16)wlapi_getintvar(shim, BRCMS_SROM_PA0B0);
  3967. pi->txpa_2g[1] = (s16)wlapi_getintvar(shim, BRCMS_SROM_PA0B1);
  3968. pi->txpa_2g[2] = (s16)wlapi_getintvar(shim, BRCMS_SROM_PA0B2);
  3969. pi_lcn->lcnphy_rssi_vf =
  3970. (u8)wlapi_getintvar(shim, BRCMS_SROM_RSSISMF2G);
  3971. pi_lcn->lcnphy_rssi_vc =
  3972. (u8)wlapi_getintvar(shim, BRCMS_SROM_RSSISMC2G);
  3973. pi_lcn->lcnphy_rssi_gs =
  3974. (u8)wlapi_getintvar(shim, BRCMS_SROM_RSSISAV2G);
  3975. pi_lcn->lcnphy_rssi_vf_lowtemp = pi_lcn->lcnphy_rssi_vf;
  3976. pi_lcn->lcnphy_rssi_vc_lowtemp = pi_lcn->lcnphy_rssi_vc;
  3977. pi_lcn->lcnphy_rssi_gs_lowtemp = pi_lcn->lcnphy_rssi_gs;
  3978. pi_lcn->lcnphy_rssi_vf_hightemp = pi_lcn->lcnphy_rssi_vf;
  3979. pi_lcn->lcnphy_rssi_vc_hightemp = pi_lcn->lcnphy_rssi_vc;
  3980. pi_lcn->lcnphy_rssi_gs_hightemp = pi_lcn->lcnphy_rssi_gs;
  3981. txpwr = (s8)wlapi_getintvar(shim, BRCMS_SROM_MAXP2GA0);
  3982. pi->tx_srom_max_2g = txpwr;
  3983. for (i = 0; i < PWRTBL_NUM_COEFF; i++) {
  3984. pi->txpa_2g_low_temp[i] = pi->txpa_2g[i];
  3985. pi->txpa_2g_high_temp[i] = pi->txpa_2g[i];
  3986. }
  3987. cckpo = (u16)wlapi_getintvar(shim, BRCMS_SROM_CCK2GPO);
  3988. offset_ofdm = (u32)wlapi_getintvar(shim, BRCMS_SROM_OFDM2GPO);
  3989. if (cckpo) {
  3990. uint max_pwr_chan = txpwr;
  3991. for (i = TXP_FIRST_CCK; i <= TXP_LAST_CCK; i++) {
  3992. pi->tx_srom_max_rate_2g[i] =
  3993. max_pwr_chan - ((cckpo & 0xf) * 2);
  3994. cckpo >>= 4;
  3995. }
  3996. for (i = TXP_FIRST_OFDM; i <= TXP_LAST_OFDM; i++) {
  3997. pi->tx_srom_max_rate_2g[i] =
  3998. max_pwr_chan -
  3999. ((offset_ofdm & 0xf) * 2);
  4000. offset_ofdm >>= 4;
  4001. }
  4002. } else {
  4003. u8 opo = 0;
  4004. opo = (u8)wlapi_getintvar(shim, BRCMS_SROM_OPO);
  4005. for (i = TXP_FIRST_CCK; i <= TXP_LAST_CCK; i++)
  4006. pi->tx_srom_max_rate_2g[i] = txpwr;
  4007. for (i = TXP_FIRST_OFDM; i <= TXP_LAST_OFDM; i++) {
  4008. pi->tx_srom_max_rate_2g[i] = txpwr -
  4009. ((offset_ofdm & 0xf) * 2);
  4010. offset_ofdm >>= 4;
  4011. }
  4012. offset_mcs =
  4013. wlapi_getintvar(shim,
  4014. BRCMS_SROM_MCS2GPO1) << 16;
  4015. offset_mcs |=
  4016. (u16) wlapi_getintvar(shim,
  4017. BRCMS_SROM_MCS2GPO0);
  4018. pi_lcn->lcnphy_mcs20_po = offset_mcs;
  4019. for (i = TXP_FIRST_SISO_MCS_20;
  4020. i <= TXP_LAST_SISO_MCS_20; i++) {
  4021. pi->tx_srom_max_rate_2g[i] =
  4022. txpwr - ((offset_mcs & 0xf) * 2);
  4023. offset_mcs >>= 4;
  4024. }
  4025. }
  4026. pi_lcn->lcnphy_rawtempsense =
  4027. (u16)wlapi_getintvar(shim, BRCMS_SROM_RAWTEMPSENSE);
  4028. pi_lcn->lcnphy_measPower =
  4029. (u8)wlapi_getintvar(shim, BRCMS_SROM_MEASPOWER);
  4030. pi_lcn->lcnphy_tempsense_slope =
  4031. (u8)wlapi_getintvar(shim, BRCMS_SROM_TEMPSENSE_SLOPE);
  4032. pi_lcn->lcnphy_hw_iqcal_en =
  4033. (bool)wlapi_getintvar(shim, BRCMS_SROM_HW_IQCAL_EN);
  4034. pi_lcn->lcnphy_iqcal_swp_dis =
  4035. (bool)wlapi_getintvar(shim, BRCMS_SROM_IQCAL_SWP_DIS);
  4036. pi_lcn->lcnphy_tempcorrx =
  4037. (u8)wlapi_getintvar(shim, BRCMS_SROM_TEMPCORRX);
  4038. pi_lcn->lcnphy_tempsense_option =
  4039. (u8)wlapi_getintvar(shim, BRCMS_SROM_TEMPSENSE_OPTION);
  4040. pi_lcn->lcnphy_freqoffset_corr =
  4041. (u8)wlapi_getintvar(shim, BRCMS_SROM_FREQOFFSET_CORR);
  4042. if ((u8)wlapi_getintvar(shim, BRCMS_SROM_AA2G) > 1)
  4043. wlc_phy_ant_rxdiv_set((struct brcms_phy_pub *) pi,
  4044. (u8) wlapi_getintvar(shim, BRCMS_SROM_AA2G));
  4045. }
  4046. pi_lcn->lcnphy_cck_dig_filt_type = -1;
  4047. return true;
  4048. }
  4049. void wlc_2064_vco_cal(struct brcms_phy *pi)
  4050. {
  4051. u8 calnrst;
  4052. mod_radio_reg(pi, RADIO_2064_REG057, 1 << 3, 1 << 3);
  4053. calnrst = (u8) read_radio_reg(pi, RADIO_2064_REG056) & 0xf8;
  4054. write_radio_reg(pi, RADIO_2064_REG056, calnrst);
  4055. udelay(1);
  4056. write_radio_reg(pi, RADIO_2064_REG056, calnrst | 0x03);
  4057. udelay(1);
  4058. write_radio_reg(pi, RADIO_2064_REG056, calnrst | 0x07);
  4059. udelay(300);
  4060. mod_radio_reg(pi, RADIO_2064_REG057, 1 << 3, 0);
  4061. }
  4062. bool wlc_phy_tpc_isenabled_lcnphy(struct brcms_phy *pi)
  4063. {
  4064. if (wlc_lcnphy_tempsense_based_pwr_ctrl_enabled(pi))
  4065. return 0;
  4066. else
  4067. return (LCNPHY_TX_PWR_CTRL_HW ==
  4068. wlc_lcnphy_get_tx_pwr_ctrl((pi)));
  4069. }
  4070. void wlc_phy_txpower_recalc_target_lcnphy(struct brcms_phy *pi)
  4071. {
  4072. u16 pwr_ctrl;
  4073. if (wlc_lcnphy_tempsense_based_pwr_ctrl_enabled(pi)) {
  4074. wlc_lcnphy_calib_modes(pi, LCNPHY_PERICAL_TEMPBASED_TXPWRCTRL);
  4075. } else if (wlc_lcnphy_tssi_based_pwr_ctrl_enabled(pi)) {
  4076. pwr_ctrl = wlc_lcnphy_get_tx_pwr_ctrl(pi);
  4077. wlc_lcnphy_set_tx_pwr_ctrl(pi, LCNPHY_TX_PWR_CTRL_OFF);
  4078. wlc_lcnphy_txpower_recalc_target(pi);
  4079. wlc_lcnphy_set_tx_pwr_ctrl(pi, pwr_ctrl);
  4080. }
  4081. }
  4082. void wlc_phy_detach_lcnphy(struct brcms_phy *pi)
  4083. {
  4084. kfree(pi->u.pi_lcnphy);
  4085. }
  4086. bool wlc_phy_attach_lcnphy(struct brcms_phy *pi)
  4087. {
  4088. struct brcms_phy_lcnphy *pi_lcn;
  4089. pi->u.pi_lcnphy = kzalloc(sizeof(struct brcms_phy_lcnphy), GFP_ATOMIC);
  4090. if (pi->u.pi_lcnphy == NULL)
  4091. return false;
  4092. pi_lcn = pi->u.pi_lcnphy;
  4093. if (0 == (pi->sh->boardflags & BFL_NOPA)) {
  4094. pi->hwpwrctrl = true;
  4095. pi->hwpwrctrl_capable = true;
  4096. }
  4097. pi->xtalfreq = si_pmu_alp_clock(pi->sh->sih);
  4098. pi_lcn->lcnphy_papd_rxGnCtrl_init = 0;
  4099. pi->pi_fptr.init = wlc_phy_init_lcnphy;
  4100. pi->pi_fptr.calinit = wlc_phy_cal_init_lcnphy;
  4101. pi->pi_fptr.chanset = wlc_phy_chanspec_set_lcnphy;
  4102. pi->pi_fptr.txpwrrecalc = wlc_phy_txpower_recalc_target_lcnphy;
  4103. pi->pi_fptr.txiqccget = wlc_lcnphy_get_tx_iqcc;
  4104. pi->pi_fptr.txiqccset = wlc_lcnphy_set_tx_iqcc;
  4105. pi->pi_fptr.txloccget = wlc_lcnphy_get_tx_locc;
  4106. pi->pi_fptr.radioloftget = wlc_lcnphy_get_radio_loft;
  4107. pi->pi_fptr.detach = wlc_phy_detach_lcnphy;
  4108. if (!wlc_phy_txpwr_srom_read_lcnphy(pi))
  4109. return false;
  4110. if ((pi->sh->boardflags & BFL_FEM) &&
  4111. (LCNREV_IS(pi->pubpi.phy_rev, 1))) {
  4112. if (pi_lcn->lcnphy_tempsense_option == 3) {
  4113. pi->hwpwrctrl = true;
  4114. pi->hwpwrctrl_capable = true;
  4115. pi->temppwrctrl_capable = false;
  4116. } else {
  4117. pi->hwpwrctrl = false;
  4118. pi->hwpwrctrl_capable = false;
  4119. pi->temppwrctrl_capable = true;
  4120. }
  4121. }
  4122. return true;
  4123. }
  4124. static void wlc_lcnphy_set_rx_gain(struct brcms_phy *pi, u32 gain)
  4125. {
  4126. u16 trsw, ext_lna, lna1, lna2, tia, biq0, biq1, gain0_15, gain16_19;
  4127. trsw = (gain & ((u32) 1 << 28)) ? 0 : 1;
  4128. ext_lna = (u16) (gain >> 29) & 0x01;
  4129. lna1 = (u16) (gain >> 0) & 0x0f;
  4130. lna2 = (u16) (gain >> 4) & 0x0f;
  4131. tia = (u16) (gain >> 8) & 0xf;
  4132. biq0 = (u16) (gain >> 12) & 0xf;
  4133. biq1 = (u16) (gain >> 16) & 0xf;
  4134. gain0_15 = (u16) ((lna1 & 0x3) | ((lna1 & 0x3) << 2) |
  4135. ((lna2 & 0x3) << 4) | ((lna2 & 0x3) << 6) |
  4136. ((tia & 0xf) << 8) | ((biq0 & 0xf) << 12));
  4137. gain16_19 = biq1;
  4138. mod_phy_reg(pi, 0x44d, (0x1 << 0), trsw << 0);
  4139. mod_phy_reg(pi, 0x4b1, (0x1 << 9), ext_lna << 9);
  4140. mod_phy_reg(pi, 0x4b1, (0x1 << 10), ext_lna << 10);
  4141. mod_phy_reg(pi, 0x4b6, (0xffff << 0), gain0_15 << 0);
  4142. mod_phy_reg(pi, 0x4b7, (0xf << 0), gain16_19 << 0);
  4143. if (CHSPEC_IS2G(pi->radio_chanspec)) {
  4144. mod_phy_reg(pi, 0x4b1, (0x3 << 11), lna1 << 11);
  4145. mod_phy_reg(pi, 0x4e6, (0x3 << 3), lna1 << 3);
  4146. }
  4147. wlc_lcnphy_rx_gain_override_enable(pi, true);
  4148. }
  4149. static u32 wlc_lcnphy_get_receive_power(struct brcms_phy *pi, s32 *gain_index)
  4150. {
  4151. u32 received_power = 0;
  4152. s32 max_index = 0;
  4153. u32 gain_code = 0;
  4154. struct brcms_phy_lcnphy *pi_lcn = pi->u.pi_lcnphy;
  4155. max_index = 36;
  4156. if (*gain_index >= 0)
  4157. gain_code = lcnphy_23bitgaincode_table[*gain_index];
  4158. if (-1 == *gain_index) {
  4159. *gain_index = 0;
  4160. while ((*gain_index <= (s32) max_index)
  4161. && (received_power < 700)) {
  4162. wlc_lcnphy_set_rx_gain(pi,
  4163. lcnphy_23bitgaincode_table
  4164. [*gain_index]);
  4165. received_power =
  4166. wlc_lcnphy_measure_digital_power(
  4167. pi,
  4168. pi_lcn->
  4169. lcnphy_noise_samples);
  4170. (*gain_index)++;
  4171. }
  4172. (*gain_index)--;
  4173. } else {
  4174. wlc_lcnphy_set_rx_gain(pi, gain_code);
  4175. received_power =
  4176. wlc_lcnphy_measure_digital_power(pi,
  4177. pi_lcn->
  4178. lcnphy_noise_samples);
  4179. }
  4180. return received_power;
  4181. }
  4182. s32 wlc_lcnphy_rx_signal_power(struct brcms_phy *pi, s32 gain_index)
  4183. {
  4184. s32 gain = 0;
  4185. s32 nominal_power_db;
  4186. s32 log_val, gain_mismatch, desired_gain, input_power_offset_db,
  4187. input_power_db;
  4188. s32 received_power, temperature;
  4189. u32 power;
  4190. u32 msb1, msb2, val1, val2, diff1, diff2;
  4191. uint freq;
  4192. struct brcms_phy_lcnphy *pi_lcn = pi->u.pi_lcnphy;
  4193. received_power = wlc_lcnphy_get_receive_power(pi, &gain_index);
  4194. gain = lcnphy_gain_table[gain_index];
  4195. nominal_power_db = read_phy_reg(pi, 0x425) >> 8;
  4196. power = (received_power * 16);
  4197. msb1 = ffs(power) - 1;
  4198. msb2 = msb1 + 1;
  4199. val1 = 1 << msb1;
  4200. val2 = 1 << msb2;
  4201. diff1 = (power - val1);
  4202. diff2 = (val2 - power);
  4203. if (diff1 < diff2)
  4204. log_val = msb1;
  4205. else
  4206. log_val = msb2;
  4207. log_val = log_val * 3;
  4208. gain_mismatch = (nominal_power_db / 2) - (log_val);
  4209. desired_gain = gain + gain_mismatch;
  4210. input_power_offset_db = read_phy_reg(pi, 0x434) & 0xFF;
  4211. if (input_power_offset_db > 127)
  4212. input_power_offset_db -= 256;
  4213. input_power_db = input_power_offset_db - desired_gain;
  4214. input_power_db =
  4215. input_power_db + lcnphy_gain_index_offset_for_rssi[gain_index];
  4216. freq = wlc_phy_channel2freq(CHSPEC_CHANNEL(pi->radio_chanspec));
  4217. if ((freq > 2427) && (freq <= 2467))
  4218. input_power_db = input_power_db - 1;
  4219. temperature = pi_lcn->lcnphy_lastsensed_temperature;
  4220. if ((temperature - 15) < -30)
  4221. input_power_db =
  4222. input_power_db +
  4223. (((temperature - 10 - 25) * 286) >> 12) -
  4224. 7;
  4225. else if ((temperature - 15) < 4)
  4226. input_power_db =
  4227. input_power_db +
  4228. (((temperature - 10 - 25) * 286) >> 12) -
  4229. 3;
  4230. else
  4231. input_power_db = input_power_db +
  4232. (((temperature - 10 - 25) * 286) >> 12);
  4233. wlc_lcnphy_rx_gain_override_enable(pi, 0);
  4234. return input_power_db;
  4235. }