phy_lcn.c 127 KB

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