phy_lcn.c 126 KB

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