phy_lcn.c 127 KB

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