phy_n.c 199 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727
  1. /*
  2. Broadcom B43 wireless driver
  3. IEEE 802.11n PHY support
  4. Copyright (c) 2008 Michael Buesch <m@bues.ch>
  5. Copyright (c) 2010-2011 Rafał Miłecki <zajec5@gmail.com>
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; see the file COPYING. If not, write to
  16. the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
  17. Boston, MA 02110-1301, USA.
  18. */
  19. #include <linux/delay.h>
  20. #include <linux/slab.h>
  21. #include <linux/types.h>
  22. #include "b43.h"
  23. #include "phy_n.h"
  24. #include "tables_nphy.h"
  25. #include "radio_2055.h"
  26. #include "radio_2056.h"
  27. #include "radio_2057.h"
  28. #include "main.h"
  29. #include "ppr.h"
  30. struct nphy_txgains {
  31. u16 tx_lpf[2];
  32. u16 txgm[2];
  33. u16 pga[2];
  34. u16 pad[2];
  35. u16 ipa[2];
  36. };
  37. struct nphy_iqcal_params {
  38. u16 tx_lpf;
  39. u16 txgm;
  40. u16 pga;
  41. u16 pad;
  42. u16 ipa;
  43. u16 cal_gain;
  44. u16 ncorr[5];
  45. };
  46. struct nphy_iq_est {
  47. s32 iq0_prod;
  48. u32 i0_pwr;
  49. u32 q0_pwr;
  50. s32 iq1_prod;
  51. u32 i1_pwr;
  52. u32 q1_pwr;
  53. };
  54. enum b43_nphy_rf_sequence {
  55. B43_RFSEQ_RX2TX,
  56. B43_RFSEQ_TX2RX,
  57. B43_RFSEQ_RESET2RX,
  58. B43_RFSEQ_UPDATE_GAINH,
  59. B43_RFSEQ_UPDATE_GAINL,
  60. B43_RFSEQ_UPDATE_GAINU,
  61. };
  62. enum n_rf_ctl_over_cmd {
  63. N_RF_CTL_OVER_CMD_RXRF_PU = 0,
  64. N_RF_CTL_OVER_CMD_RX_PU = 1,
  65. N_RF_CTL_OVER_CMD_TX_PU = 2,
  66. N_RF_CTL_OVER_CMD_RX_GAIN = 3,
  67. N_RF_CTL_OVER_CMD_TX_GAIN = 4,
  68. };
  69. enum n_intc_override {
  70. N_INTC_OVERRIDE_OFF = 0,
  71. N_INTC_OVERRIDE_TRSW = 1,
  72. N_INTC_OVERRIDE_PA = 2,
  73. N_INTC_OVERRIDE_EXT_LNA_PU = 3,
  74. N_INTC_OVERRIDE_EXT_LNA_GAIN = 4,
  75. };
  76. enum n_rssi_type {
  77. N_RSSI_W1 = 0,
  78. N_RSSI_W2,
  79. N_RSSI_NB,
  80. N_RSSI_IQ,
  81. N_RSSI_TSSI_2G,
  82. N_RSSI_TSSI_5G,
  83. N_RSSI_TBD,
  84. };
  85. enum n_rail_type {
  86. N_RAIL_I = 0,
  87. N_RAIL_Q = 1,
  88. };
  89. static inline bool b43_nphy_ipa(struct b43_wldev *dev)
  90. {
  91. enum nl80211_band band = b43_current_band(dev->wl);
  92. return ((dev->phy.n->ipa2g_on && band == NL80211_BAND_2GHZ) ||
  93. (dev->phy.n->ipa5g_on && band == NL80211_BAND_5GHZ));
  94. }
  95. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/RxCoreGetState */
  96. static u8 b43_nphy_get_rx_core_state(struct b43_wldev *dev)
  97. {
  98. return (b43_phy_read(dev, B43_NPHY_RFSEQCA) & B43_NPHY_RFSEQCA_RXEN) >>
  99. B43_NPHY_RFSEQCA_RXEN_SHIFT;
  100. }
  101. /**************************************************
  102. * RF (just without b43_nphy_rf_ctl_intc_override)
  103. **************************************************/
  104. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/ForceRFSeq */
  105. static void b43_nphy_force_rf_sequence(struct b43_wldev *dev,
  106. enum b43_nphy_rf_sequence seq)
  107. {
  108. static const u16 trigger[] = {
  109. [B43_RFSEQ_RX2TX] = B43_NPHY_RFSEQTR_RX2TX,
  110. [B43_RFSEQ_TX2RX] = B43_NPHY_RFSEQTR_TX2RX,
  111. [B43_RFSEQ_RESET2RX] = B43_NPHY_RFSEQTR_RST2RX,
  112. [B43_RFSEQ_UPDATE_GAINH] = B43_NPHY_RFSEQTR_UPGH,
  113. [B43_RFSEQ_UPDATE_GAINL] = B43_NPHY_RFSEQTR_UPGL,
  114. [B43_RFSEQ_UPDATE_GAINU] = B43_NPHY_RFSEQTR_UPGU,
  115. };
  116. int i;
  117. u16 seq_mode = b43_phy_read(dev, B43_NPHY_RFSEQMODE);
  118. B43_WARN_ON(seq >= ARRAY_SIZE(trigger));
  119. b43_phy_set(dev, B43_NPHY_RFSEQMODE,
  120. B43_NPHY_RFSEQMODE_CAOVER | B43_NPHY_RFSEQMODE_TROVER);
  121. b43_phy_set(dev, B43_NPHY_RFSEQTR, trigger[seq]);
  122. for (i = 0; i < 200; i++) {
  123. if (!(b43_phy_read(dev, B43_NPHY_RFSEQST) & trigger[seq]))
  124. goto ok;
  125. msleep(1);
  126. }
  127. b43err(dev->wl, "RF sequence status timeout\n");
  128. ok:
  129. b43_phy_write(dev, B43_NPHY_RFSEQMODE, seq_mode);
  130. }
  131. static void b43_nphy_rf_ctl_override_rev19(struct b43_wldev *dev, u16 field,
  132. u16 value, u8 core, bool off,
  133. u8 override_id)
  134. {
  135. /* TODO */
  136. }
  137. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/RFCtrlOverrideRev7 */
  138. static void b43_nphy_rf_ctl_override_rev7(struct b43_wldev *dev, u16 field,
  139. u16 value, u8 core, bool off,
  140. u8 override)
  141. {
  142. struct b43_phy *phy = &dev->phy;
  143. const struct nphy_rf_control_override_rev7 *e;
  144. u16 en_addrs[3][2] = {
  145. { 0x0E7, 0x0EC }, { 0x342, 0x343 }, { 0x346, 0x347 }
  146. };
  147. u16 en_addr;
  148. u16 en_mask = field;
  149. u16 val_addr;
  150. u8 i;
  151. if (phy->rev >= 19 || phy->rev < 3) {
  152. B43_WARN_ON(1);
  153. return;
  154. }
  155. /* Remember: we can get NULL! */
  156. e = b43_nphy_get_rf_ctl_over_rev7(dev, field, override);
  157. for (i = 0; i < 2; i++) {
  158. if (override >= ARRAY_SIZE(en_addrs)) {
  159. b43err(dev->wl, "Invalid override value %d\n", override);
  160. return;
  161. }
  162. en_addr = en_addrs[override][i];
  163. if (e)
  164. val_addr = (i == 0) ? e->val_addr_core0 : e->val_addr_core1;
  165. if (off) {
  166. b43_phy_mask(dev, en_addr, ~en_mask);
  167. if (e) /* Do it safer, better than wl */
  168. b43_phy_mask(dev, val_addr, ~e->val_mask);
  169. } else {
  170. if (!core || (core & (1 << i))) {
  171. b43_phy_set(dev, en_addr, en_mask);
  172. if (e)
  173. b43_phy_maskset(dev, val_addr, ~e->val_mask, (value << e->val_shift));
  174. }
  175. }
  176. }
  177. }
  178. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/RFCtrlOverideOneToMany */
  179. static void b43_nphy_rf_ctl_override_one_to_many(struct b43_wldev *dev,
  180. enum n_rf_ctl_over_cmd cmd,
  181. u16 value, u8 core, bool off)
  182. {
  183. struct b43_phy *phy = &dev->phy;
  184. u16 tmp;
  185. B43_WARN_ON(phy->rev < 7);
  186. switch (cmd) {
  187. case N_RF_CTL_OVER_CMD_RXRF_PU:
  188. b43_nphy_rf_ctl_override_rev7(dev, 0x20, value, core, off, 1);
  189. b43_nphy_rf_ctl_override_rev7(dev, 0x10, value, core, off, 1);
  190. b43_nphy_rf_ctl_override_rev7(dev, 0x08, value, core, off, 1);
  191. break;
  192. case N_RF_CTL_OVER_CMD_RX_PU:
  193. b43_nphy_rf_ctl_override_rev7(dev, 0x4, value, core, off, 1);
  194. b43_nphy_rf_ctl_override_rev7(dev, 0x2, value, core, off, 1);
  195. b43_nphy_rf_ctl_override_rev7(dev, 0x1, value, core, off, 1);
  196. b43_nphy_rf_ctl_override_rev7(dev, 0x2, value, core, off, 2);
  197. b43_nphy_rf_ctl_override_rev7(dev, 0x0800, 0, core, off, 1);
  198. break;
  199. case N_RF_CTL_OVER_CMD_TX_PU:
  200. b43_nphy_rf_ctl_override_rev7(dev, 0x4, value, core, off, 0);
  201. b43_nphy_rf_ctl_override_rev7(dev, 0x2, value, core, off, 1);
  202. b43_nphy_rf_ctl_override_rev7(dev, 0x1, value, core, off, 2);
  203. b43_nphy_rf_ctl_override_rev7(dev, 0x0800, 1, core, off, 1);
  204. break;
  205. case N_RF_CTL_OVER_CMD_RX_GAIN:
  206. tmp = value & 0xFF;
  207. b43_nphy_rf_ctl_override_rev7(dev, 0x0800, tmp, core, off, 0);
  208. tmp = value >> 8;
  209. b43_nphy_rf_ctl_override_rev7(dev, 0x6000, tmp, core, off, 0);
  210. break;
  211. case N_RF_CTL_OVER_CMD_TX_GAIN:
  212. tmp = value & 0x7FFF;
  213. b43_nphy_rf_ctl_override_rev7(dev, 0x1000, tmp, core, off, 0);
  214. tmp = value >> 14;
  215. b43_nphy_rf_ctl_override_rev7(dev, 0x4000, tmp, core, off, 0);
  216. break;
  217. }
  218. }
  219. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/RFCtrlOverride */
  220. static void b43_nphy_rf_ctl_override(struct b43_wldev *dev, u16 field,
  221. u16 value, u8 core, bool off)
  222. {
  223. int i;
  224. u8 index = fls(field);
  225. u8 addr, en_addr, val_addr;
  226. /* we expect only one bit set */
  227. B43_WARN_ON(field & (~(1 << (index - 1))));
  228. if (dev->phy.rev >= 3) {
  229. const struct nphy_rf_control_override_rev3 *rf_ctrl;
  230. for (i = 0; i < 2; i++) {
  231. if (index == 0 || index == 16) {
  232. b43err(dev->wl,
  233. "Unsupported RF Ctrl Override call\n");
  234. return;
  235. }
  236. rf_ctrl = &tbl_rf_control_override_rev3[index - 1];
  237. en_addr = B43_PHY_N((i == 0) ?
  238. rf_ctrl->en_addr0 : rf_ctrl->en_addr1);
  239. val_addr = B43_PHY_N((i == 0) ?
  240. rf_ctrl->val_addr0 : rf_ctrl->val_addr1);
  241. if (off) {
  242. b43_phy_mask(dev, en_addr, ~(field));
  243. b43_phy_mask(dev, val_addr,
  244. ~(rf_ctrl->val_mask));
  245. } else {
  246. if (core == 0 || ((1 << i) & core)) {
  247. b43_phy_set(dev, en_addr, field);
  248. b43_phy_maskset(dev, val_addr,
  249. ~(rf_ctrl->val_mask),
  250. (value << rf_ctrl->val_shift));
  251. }
  252. }
  253. }
  254. } else {
  255. const struct nphy_rf_control_override_rev2 *rf_ctrl;
  256. if (off) {
  257. b43_phy_mask(dev, B43_NPHY_RFCTL_OVER, ~(field));
  258. value = 0;
  259. } else {
  260. b43_phy_set(dev, B43_NPHY_RFCTL_OVER, field);
  261. }
  262. for (i = 0; i < 2; i++) {
  263. if (index <= 1 || index == 16) {
  264. b43err(dev->wl,
  265. "Unsupported RF Ctrl Override call\n");
  266. return;
  267. }
  268. if (index == 2 || index == 10 ||
  269. (index >= 13 && index <= 15)) {
  270. core = 1;
  271. }
  272. rf_ctrl = &tbl_rf_control_override_rev2[index - 2];
  273. addr = B43_PHY_N((i == 0) ?
  274. rf_ctrl->addr0 : rf_ctrl->addr1);
  275. if ((1 << i) & core)
  276. b43_phy_maskset(dev, addr, ~(rf_ctrl->bmask),
  277. (value << rf_ctrl->shift));
  278. b43_phy_set(dev, B43_NPHY_RFCTL_OVER, 0x1);
  279. b43_phy_set(dev, B43_NPHY_RFCTL_CMD,
  280. B43_NPHY_RFCTL_CMD_START);
  281. udelay(1);
  282. b43_phy_mask(dev, B43_NPHY_RFCTL_OVER, 0xFFFE);
  283. }
  284. }
  285. }
  286. static void b43_nphy_rf_ctl_intc_override_rev7(struct b43_wldev *dev,
  287. enum n_intc_override intc_override,
  288. u16 value, u8 core_sel)
  289. {
  290. u16 reg, tmp, tmp2, val;
  291. int core;
  292. /* TODO: What about rev19+? Revs 3+ and 7+ are a bit similar */
  293. for (core = 0; core < 2; core++) {
  294. if ((core_sel == 1 && core != 0) ||
  295. (core_sel == 2 && core != 1))
  296. continue;
  297. reg = (core == 0) ? B43_NPHY_RFCTL_INTC1 : B43_NPHY_RFCTL_INTC2;
  298. switch (intc_override) {
  299. case N_INTC_OVERRIDE_OFF:
  300. b43_phy_write(dev, reg, 0);
  301. b43_phy_mask(dev, 0x2ff, ~0x2000);
  302. b43_nphy_force_rf_sequence(dev, B43_RFSEQ_RESET2RX);
  303. break;
  304. case N_INTC_OVERRIDE_TRSW:
  305. b43_phy_maskset(dev, reg, ~0xC0, value << 6);
  306. b43_phy_set(dev, reg, 0x400);
  307. b43_phy_mask(dev, 0x2ff, ~0xC000 & 0xFFFF);
  308. b43_phy_set(dev, 0x2ff, 0x2000);
  309. b43_phy_set(dev, 0x2ff, 0x0001);
  310. break;
  311. case N_INTC_OVERRIDE_PA:
  312. tmp = 0x0030;
  313. if (b43_current_band(dev->wl) == NL80211_BAND_5GHZ)
  314. val = value << 5;
  315. else
  316. val = value << 4;
  317. b43_phy_maskset(dev, reg, ~tmp, val);
  318. b43_phy_set(dev, reg, 0x1000);
  319. break;
  320. case N_INTC_OVERRIDE_EXT_LNA_PU:
  321. if (b43_current_band(dev->wl) == NL80211_BAND_5GHZ) {
  322. tmp = 0x0001;
  323. tmp2 = 0x0004;
  324. val = value;
  325. } else {
  326. tmp = 0x0004;
  327. tmp2 = 0x0001;
  328. val = value << 2;
  329. }
  330. b43_phy_maskset(dev, reg, ~tmp, val);
  331. b43_phy_mask(dev, reg, ~tmp2);
  332. break;
  333. case N_INTC_OVERRIDE_EXT_LNA_GAIN:
  334. if (b43_current_band(dev->wl) == NL80211_BAND_5GHZ) {
  335. tmp = 0x0002;
  336. tmp2 = 0x0008;
  337. val = value << 1;
  338. } else {
  339. tmp = 0x0008;
  340. tmp2 = 0x0002;
  341. val = value << 3;
  342. }
  343. b43_phy_maskset(dev, reg, ~tmp, val);
  344. b43_phy_mask(dev, reg, ~tmp2);
  345. break;
  346. }
  347. }
  348. }
  349. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/RFCtrlIntcOverride */
  350. static void b43_nphy_rf_ctl_intc_override(struct b43_wldev *dev,
  351. enum n_intc_override intc_override,
  352. u16 value, u8 core)
  353. {
  354. u8 i, j;
  355. u16 reg, tmp, val;
  356. if (dev->phy.rev >= 7) {
  357. b43_nphy_rf_ctl_intc_override_rev7(dev, intc_override, value,
  358. core);
  359. return;
  360. }
  361. B43_WARN_ON(dev->phy.rev < 3);
  362. for (i = 0; i < 2; i++) {
  363. if ((core == 1 && i == 1) || (core == 2 && !i))
  364. continue;
  365. reg = (i == 0) ?
  366. B43_NPHY_RFCTL_INTC1 : B43_NPHY_RFCTL_INTC2;
  367. b43_phy_set(dev, reg, 0x400);
  368. switch (intc_override) {
  369. case N_INTC_OVERRIDE_OFF:
  370. b43_phy_write(dev, reg, 0);
  371. b43_nphy_force_rf_sequence(dev, B43_RFSEQ_RESET2RX);
  372. break;
  373. case N_INTC_OVERRIDE_TRSW:
  374. if (!i) {
  375. b43_phy_maskset(dev, B43_NPHY_RFCTL_INTC1,
  376. 0xFC3F, (value << 6));
  377. b43_phy_maskset(dev, B43_NPHY_TXF_40CO_B1S1,
  378. 0xFFFE, 1);
  379. b43_phy_set(dev, B43_NPHY_RFCTL_CMD,
  380. B43_NPHY_RFCTL_CMD_START);
  381. for (j = 0; j < 100; j++) {
  382. if (!(b43_phy_read(dev, B43_NPHY_RFCTL_CMD) & B43_NPHY_RFCTL_CMD_START)) {
  383. j = 0;
  384. break;
  385. }
  386. udelay(10);
  387. }
  388. if (j)
  389. b43err(dev->wl,
  390. "intc override timeout\n");
  391. b43_phy_mask(dev, B43_NPHY_TXF_40CO_B1S1,
  392. 0xFFFE);
  393. } else {
  394. b43_phy_maskset(dev, B43_NPHY_RFCTL_INTC2,
  395. 0xFC3F, (value << 6));
  396. b43_phy_maskset(dev, B43_NPHY_RFCTL_OVER,
  397. 0xFFFE, 1);
  398. b43_phy_set(dev, B43_NPHY_RFCTL_CMD,
  399. B43_NPHY_RFCTL_CMD_RXTX);
  400. for (j = 0; j < 100; j++) {
  401. if (!(b43_phy_read(dev, B43_NPHY_RFCTL_CMD) & B43_NPHY_RFCTL_CMD_RXTX)) {
  402. j = 0;
  403. break;
  404. }
  405. udelay(10);
  406. }
  407. if (j)
  408. b43err(dev->wl,
  409. "intc override timeout\n");
  410. b43_phy_mask(dev, B43_NPHY_RFCTL_OVER,
  411. 0xFFFE);
  412. }
  413. break;
  414. case N_INTC_OVERRIDE_PA:
  415. if (b43_current_band(dev->wl) == NL80211_BAND_5GHZ) {
  416. tmp = 0x0020;
  417. val = value << 5;
  418. } else {
  419. tmp = 0x0010;
  420. val = value << 4;
  421. }
  422. b43_phy_maskset(dev, reg, ~tmp, val);
  423. break;
  424. case N_INTC_OVERRIDE_EXT_LNA_PU:
  425. if (b43_current_band(dev->wl) == NL80211_BAND_5GHZ) {
  426. tmp = 0x0001;
  427. val = value;
  428. } else {
  429. tmp = 0x0004;
  430. val = value << 2;
  431. }
  432. b43_phy_maskset(dev, reg, ~tmp, val);
  433. break;
  434. case N_INTC_OVERRIDE_EXT_LNA_GAIN:
  435. if (b43_current_band(dev->wl) == NL80211_BAND_5GHZ) {
  436. tmp = 0x0002;
  437. val = value << 1;
  438. } else {
  439. tmp = 0x0008;
  440. val = value << 3;
  441. }
  442. b43_phy_maskset(dev, reg, ~tmp, val);
  443. break;
  444. }
  445. }
  446. }
  447. /**************************************************
  448. * Various PHY ops
  449. **************************************************/
  450. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/clip-detection */
  451. static void b43_nphy_write_clip_detection(struct b43_wldev *dev,
  452. const u16 *clip_st)
  453. {
  454. b43_phy_write(dev, B43_NPHY_C1_CLIP1THRES, clip_st[0]);
  455. b43_phy_write(dev, B43_NPHY_C2_CLIP1THRES, clip_st[1]);
  456. }
  457. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/clip-detection */
  458. static void b43_nphy_read_clip_detection(struct b43_wldev *dev, u16 *clip_st)
  459. {
  460. clip_st[0] = b43_phy_read(dev, B43_NPHY_C1_CLIP1THRES);
  461. clip_st[1] = b43_phy_read(dev, B43_NPHY_C2_CLIP1THRES);
  462. }
  463. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/classifier */
  464. static u16 b43_nphy_classifier(struct b43_wldev *dev, u16 mask, u16 val)
  465. {
  466. u16 tmp;
  467. if (dev->dev->core_rev == 16)
  468. b43_mac_suspend(dev);
  469. tmp = b43_phy_read(dev, B43_NPHY_CLASSCTL);
  470. tmp &= (B43_NPHY_CLASSCTL_CCKEN | B43_NPHY_CLASSCTL_OFDMEN |
  471. B43_NPHY_CLASSCTL_WAITEDEN);
  472. tmp &= ~mask;
  473. tmp |= (val & mask);
  474. b43_phy_maskset(dev, B43_NPHY_CLASSCTL, 0xFFF8, tmp);
  475. if (dev->dev->core_rev == 16)
  476. b43_mac_enable(dev);
  477. return tmp;
  478. }
  479. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/CCA */
  480. static void b43_nphy_reset_cca(struct b43_wldev *dev)
  481. {
  482. u16 bbcfg;
  483. b43_phy_force_clock(dev, 1);
  484. bbcfg = b43_phy_read(dev, B43_NPHY_BBCFG);
  485. b43_phy_write(dev, B43_NPHY_BBCFG, bbcfg | B43_NPHY_BBCFG_RSTCCA);
  486. udelay(1);
  487. b43_phy_write(dev, B43_NPHY_BBCFG, bbcfg & ~B43_NPHY_BBCFG_RSTCCA);
  488. b43_phy_force_clock(dev, 0);
  489. b43_nphy_force_rf_sequence(dev, B43_RFSEQ_RESET2RX);
  490. }
  491. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/carriersearch */
  492. static void b43_nphy_stay_in_carrier_search(struct b43_wldev *dev, bool enable)
  493. {
  494. struct b43_phy *phy = &dev->phy;
  495. struct b43_phy_n *nphy = phy->n;
  496. if (enable) {
  497. static const u16 clip[] = { 0xFFFF, 0xFFFF };
  498. if (nphy->deaf_count++ == 0) {
  499. nphy->classifier_state = b43_nphy_classifier(dev, 0, 0);
  500. b43_nphy_classifier(dev, 0x7,
  501. B43_NPHY_CLASSCTL_WAITEDEN);
  502. b43_nphy_read_clip_detection(dev, nphy->clip_state);
  503. b43_nphy_write_clip_detection(dev, clip);
  504. }
  505. b43_nphy_reset_cca(dev);
  506. } else {
  507. if (--nphy->deaf_count == 0) {
  508. b43_nphy_classifier(dev, 0x7, nphy->classifier_state);
  509. b43_nphy_write_clip_detection(dev, nphy->clip_state);
  510. }
  511. }
  512. }
  513. /* http://bcm-v4.sipsolutions.net/PHY/N/Read_Lpf_Bw_Ctl */
  514. static u16 b43_nphy_read_lpf_ctl(struct b43_wldev *dev, u16 offset)
  515. {
  516. if (!offset)
  517. offset = b43_is_40mhz(dev) ? 0x159 : 0x154;
  518. return b43_ntab_read(dev, B43_NTAB16(7, offset)) & 0x7;
  519. }
  520. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/AdjustLnaGainTbl */
  521. static void b43_nphy_adjust_lna_gain_table(struct b43_wldev *dev)
  522. {
  523. struct b43_phy_n *nphy = dev->phy.n;
  524. u8 i;
  525. s16 tmp;
  526. u16 data[4];
  527. s16 gain[2];
  528. u16 minmax[2];
  529. static const u16 lna_gain[4] = { -2, 10, 19, 25 };
  530. if (nphy->hang_avoid)
  531. b43_nphy_stay_in_carrier_search(dev, 1);
  532. if (nphy->gain_boost) {
  533. if (b43_current_band(dev->wl) == NL80211_BAND_2GHZ) {
  534. gain[0] = 6;
  535. gain[1] = 6;
  536. } else {
  537. tmp = 40370 - 315 * dev->phy.channel;
  538. gain[0] = ((tmp >> 13) + ((tmp >> 12) & 1));
  539. tmp = 23242 - 224 * dev->phy.channel;
  540. gain[1] = ((tmp >> 13) + ((tmp >> 12) & 1));
  541. }
  542. } else {
  543. gain[0] = 0;
  544. gain[1] = 0;
  545. }
  546. for (i = 0; i < 2; i++) {
  547. if (nphy->elna_gain_config) {
  548. data[0] = 19 + gain[i];
  549. data[1] = 25 + gain[i];
  550. data[2] = 25 + gain[i];
  551. data[3] = 25 + gain[i];
  552. } else {
  553. data[0] = lna_gain[0] + gain[i];
  554. data[1] = lna_gain[1] + gain[i];
  555. data[2] = lna_gain[2] + gain[i];
  556. data[3] = lna_gain[3] + gain[i];
  557. }
  558. b43_ntab_write_bulk(dev, B43_NTAB16(i, 8), 4, data);
  559. minmax[i] = 23 + gain[i];
  560. }
  561. b43_phy_maskset(dev, B43_NPHY_C1_MINMAX_GAIN, ~B43_NPHY_C1_MINGAIN,
  562. minmax[0] << B43_NPHY_C1_MINGAIN_SHIFT);
  563. b43_phy_maskset(dev, B43_NPHY_C2_MINMAX_GAIN, ~B43_NPHY_C2_MINGAIN,
  564. minmax[1] << B43_NPHY_C2_MINGAIN_SHIFT);
  565. if (nphy->hang_avoid)
  566. b43_nphy_stay_in_carrier_search(dev, 0);
  567. }
  568. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/SetRfSeq */
  569. static void b43_nphy_set_rf_sequence(struct b43_wldev *dev, u8 cmd,
  570. u8 *events, u8 *delays, u8 length)
  571. {
  572. struct b43_phy_n *nphy = dev->phy.n;
  573. u8 i;
  574. u8 end = (dev->phy.rev >= 3) ? 0x1F : 0x0F;
  575. u16 offset1 = cmd << 4;
  576. u16 offset2 = offset1 + 0x80;
  577. if (nphy->hang_avoid)
  578. b43_nphy_stay_in_carrier_search(dev, true);
  579. b43_ntab_write_bulk(dev, B43_NTAB8(7, offset1), length, events);
  580. b43_ntab_write_bulk(dev, B43_NTAB8(7, offset2), length, delays);
  581. for (i = length; i < 16; i++) {
  582. b43_ntab_write(dev, B43_NTAB8(7, offset1 + i), end);
  583. b43_ntab_write(dev, B43_NTAB8(7, offset2 + i), 1);
  584. }
  585. if (nphy->hang_avoid)
  586. b43_nphy_stay_in_carrier_search(dev, false);
  587. }
  588. /**************************************************
  589. * Radio 0x2057
  590. **************************************************/
  591. static void b43_radio_2057_chantab_upload(struct b43_wldev *dev,
  592. const struct b43_nphy_chantabent_rev7 *e_r7,
  593. const struct b43_nphy_chantabent_rev7_2g *e_r7_2g)
  594. {
  595. if (e_r7_2g) {
  596. b43_radio_write(dev, R2057_VCOCAL_COUNTVAL0, e_r7_2g->radio_vcocal_countval0);
  597. b43_radio_write(dev, R2057_VCOCAL_COUNTVAL1, e_r7_2g->radio_vcocal_countval1);
  598. b43_radio_write(dev, R2057_RFPLL_REFMASTER_SPAREXTALSIZE, e_r7_2g->radio_rfpll_refmaster_sparextalsize);
  599. b43_radio_write(dev, R2057_RFPLL_LOOPFILTER_R1, e_r7_2g->radio_rfpll_loopfilter_r1);
  600. b43_radio_write(dev, R2057_RFPLL_LOOPFILTER_C2, e_r7_2g->radio_rfpll_loopfilter_c2);
  601. b43_radio_write(dev, R2057_RFPLL_LOOPFILTER_C1, e_r7_2g->radio_rfpll_loopfilter_c1);
  602. b43_radio_write(dev, R2057_CP_KPD_IDAC, e_r7_2g->radio_cp_kpd_idac);
  603. b43_radio_write(dev, R2057_RFPLL_MMD0, e_r7_2g->radio_rfpll_mmd0);
  604. b43_radio_write(dev, R2057_RFPLL_MMD1, e_r7_2g->radio_rfpll_mmd1);
  605. b43_radio_write(dev, R2057_VCOBUF_TUNE, e_r7_2g->radio_vcobuf_tune);
  606. b43_radio_write(dev, R2057_LOGEN_MX2G_TUNE, e_r7_2g->radio_logen_mx2g_tune);
  607. b43_radio_write(dev, R2057_LOGEN_INDBUF2G_TUNE, e_r7_2g->radio_logen_indbuf2g_tune);
  608. b43_radio_write(dev, R2057_TXMIX2G_TUNE_BOOST_PU_CORE0, e_r7_2g->radio_txmix2g_tune_boost_pu_core0);
  609. b43_radio_write(dev, R2057_PAD2G_TUNE_PUS_CORE0, e_r7_2g->radio_pad2g_tune_pus_core0);
  610. b43_radio_write(dev, R2057_LNA2G_TUNE_CORE0, e_r7_2g->radio_lna2g_tune_core0);
  611. b43_radio_write(dev, R2057_TXMIX2G_TUNE_BOOST_PU_CORE1, e_r7_2g->radio_txmix2g_tune_boost_pu_core1);
  612. b43_radio_write(dev, R2057_PAD2G_TUNE_PUS_CORE1, e_r7_2g->radio_pad2g_tune_pus_core1);
  613. b43_radio_write(dev, R2057_LNA2G_TUNE_CORE1, e_r7_2g->radio_lna2g_tune_core1);
  614. } else {
  615. b43_radio_write(dev, R2057_VCOCAL_COUNTVAL0, e_r7->radio_vcocal_countval0);
  616. b43_radio_write(dev, R2057_VCOCAL_COUNTVAL1, e_r7->radio_vcocal_countval1);
  617. b43_radio_write(dev, R2057_RFPLL_REFMASTER_SPAREXTALSIZE, e_r7->radio_rfpll_refmaster_sparextalsize);
  618. b43_radio_write(dev, R2057_RFPLL_LOOPFILTER_R1, e_r7->radio_rfpll_loopfilter_r1);
  619. b43_radio_write(dev, R2057_RFPLL_LOOPFILTER_C2, e_r7->radio_rfpll_loopfilter_c2);
  620. b43_radio_write(dev, R2057_RFPLL_LOOPFILTER_C1, e_r7->radio_rfpll_loopfilter_c1);
  621. b43_radio_write(dev, R2057_CP_KPD_IDAC, e_r7->radio_cp_kpd_idac);
  622. b43_radio_write(dev, R2057_RFPLL_MMD0, e_r7->radio_rfpll_mmd0);
  623. b43_radio_write(dev, R2057_RFPLL_MMD1, e_r7->radio_rfpll_mmd1);
  624. b43_radio_write(dev, R2057_VCOBUF_TUNE, e_r7->radio_vcobuf_tune);
  625. b43_radio_write(dev, R2057_LOGEN_MX2G_TUNE, e_r7->radio_logen_mx2g_tune);
  626. b43_radio_write(dev, R2057_LOGEN_MX5G_TUNE, e_r7->radio_logen_mx5g_tune);
  627. b43_radio_write(dev, R2057_LOGEN_INDBUF2G_TUNE, e_r7->radio_logen_indbuf2g_tune);
  628. b43_radio_write(dev, R2057_LOGEN_INDBUF5G_TUNE, e_r7->radio_logen_indbuf5g_tune);
  629. b43_radio_write(dev, R2057_TXMIX2G_TUNE_BOOST_PU_CORE0, e_r7->radio_txmix2g_tune_boost_pu_core0);
  630. b43_radio_write(dev, R2057_PAD2G_TUNE_PUS_CORE0, e_r7->radio_pad2g_tune_pus_core0);
  631. b43_radio_write(dev, R2057_PGA_BOOST_TUNE_CORE0, e_r7->radio_pga_boost_tune_core0);
  632. b43_radio_write(dev, R2057_TXMIX5G_BOOST_TUNE_CORE0, e_r7->radio_txmix5g_boost_tune_core0);
  633. b43_radio_write(dev, R2057_PAD5G_TUNE_MISC_PUS_CORE0, e_r7->radio_pad5g_tune_misc_pus_core0);
  634. b43_radio_write(dev, R2057_LNA2G_TUNE_CORE0, e_r7->radio_lna2g_tune_core0);
  635. b43_radio_write(dev, R2057_LNA5G_TUNE_CORE0, e_r7->radio_lna5g_tune_core0);
  636. b43_radio_write(dev, R2057_TXMIX2G_TUNE_BOOST_PU_CORE1, e_r7->radio_txmix2g_tune_boost_pu_core1);
  637. b43_radio_write(dev, R2057_PAD2G_TUNE_PUS_CORE1, e_r7->radio_pad2g_tune_pus_core1);
  638. b43_radio_write(dev, R2057_PGA_BOOST_TUNE_CORE1, e_r7->radio_pga_boost_tune_core1);
  639. b43_radio_write(dev, R2057_TXMIX5G_BOOST_TUNE_CORE1, e_r7->radio_txmix5g_boost_tune_core1);
  640. b43_radio_write(dev, R2057_PAD5G_TUNE_MISC_PUS_CORE1, e_r7->radio_pad5g_tune_misc_pus_core1);
  641. b43_radio_write(dev, R2057_LNA2G_TUNE_CORE1, e_r7->radio_lna2g_tune_core1);
  642. b43_radio_write(dev, R2057_LNA5G_TUNE_CORE1, e_r7->radio_lna5g_tune_core1);
  643. }
  644. }
  645. static void b43_radio_2057_setup(struct b43_wldev *dev,
  646. const struct b43_nphy_chantabent_rev7 *tabent_r7,
  647. const struct b43_nphy_chantabent_rev7_2g *tabent_r7_2g)
  648. {
  649. struct b43_phy *phy = &dev->phy;
  650. b43_radio_2057_chantab_upload(dev, tabent_r7, tabent_r7_2g);
  651. switch (phy->radio_rev) {
  652. case 0 ... 4:
  653. case 6:
  654. if (b43_current_band(dev->wl) == NL80211_BAND_2GHZ) {
  655. b43_radio_write(dev, R2057_RFPLL_LOOPFILTER_R1, 0x3f);
  656. b43_radio_write(dev, R2057_CP_KPD_IDAC, 0x3f);
  657. b43_radio_write(dev, R2057_RFPLL_LOOPFILTER_C1, 0x8);
  658. b43_radio_write(dev, R2057_RFPLL_LOOPFILTER_C2, 0x8);
  659. } else {
  660. b43_radio_write(dev, R2057_RFPLL_LOOPFILTER_R1, 0x1f);
  661. b43_radio_write(dev, R2057_CP_KPD_IDAC, 0x3f);
  662. b43_radio_write(dev, R2057_RFPLL_LOOPFILTER_C1, 0x8);
  663. b43_radio_write(dev, R2057_RFPLL_LOOPFILTER_C2, 0x8);
  664. }
  665. break;
  666. case 9: /* e.g. PHY rev 16 */
  667. b43_radio_write(dev, R2057_LOGEN_PTAT_RESETS, 0x20);
  668. b43_radio_write(dev, R2057_VCOBUF_IDACS, 0x18);
  669. if (b43_current_band(dev->wl) == NL80211_BAND_5GHZ) {
  670. b43_radio_write(dev, R2057_LOGEN_PTAT_RESETS, 0x38);
  671. b43_radio_write(dev, R2057_VCOBUF_IDACS, 0x0f);
  672. if (b43_is_40mhz(dev)) {
  673. /* TODO */
  674. } else {
  675. b43_radio_write(dev,
  676. R2057_PAD_BIAS_FILTER_BWS_CORE0,
  677. 0x3c);
  678. b43_radio_write(dev,
  679. R2057_PAD_BIAS_FILTER_BWS_CORE1,
  680. 0x3c);
  681. }
  682. }
  683. break;
  684. case 14: /* 2 GHz only */
  685. b43_radio_write(dev, R2057_RFPLL_LOOPFILTER_R1, 0x1b);
  686. b43_radio_write(dev, R2057_CP_KPD_IDAC, 0x3f);
  687. b43_radio_write(dev, R2057_RFPLL_LOOPFILTER_C1, 0x1f);
  688. b43_radio_write(dev, R2057_RFPLL_LOOPFILTER_C2, 0x1f);
  689. break;
  690. }
  691. if (b43_current_band(dev->wl) == NL80211_BAND_2GHZ) {
  692. u16 txmix2g_tune_boost_pu = 0;
  693. u16 pad2g_tune_pus = 0;
  694. if (b43_nphy_ipa(dev)) {
  695. switch (phy->radio_rev) {
  696. case 9:
  697. txmix2g_tune_boost_pu = 0x0041;
  698. /* TODO */
  699. break;
  700. case 14:
  701. txmix2g_tune_boost_pu = 0x21;
  702. pad2g_tune_pus = 0x23;
  703. break;
  704. }
  705. }
  706. if (txmix2g_tune_boost_pu)
  707. b43_radio_write(dev, R2057_TXMIX2G_TUNE_BOOST_PU_CORE0,
  708. txmix2g_tune_boost_pu);
  709. if (pad2g_tune_pus)
  710. b43_radio_write(dev, R2057_PAD2G_TUNE_PUS_CORE0,
  711. pad2g_tune_pus);
  712. if (txmix2g_tune_boost_pu)
  713. b43_radio_write(dev, R2057_TXMIX2G_TUNE_BOOST_PU_CORE1,
  714. txmix2g_tune_boost_pu);
  715. if (pad2g_tune_pus)
  716. b43_radio_write(dev, R2057_PAD2G_TUNE_PUS_CORE1,
  717. pad2g_tune_pus);
  718. }
  719. usleep_range(50, 100);
  720. /* VCO calibration */
  721. b43_radio_mask(dev, R2057_RFPLL_MISC_EN, ~0x01);
  722. b43_radio_mask(dev, R2057_RFPLL_MISC_CAL_RESETN, ~0x04);
  723. b43_radio_set(dev, R2057_RFPLL_MISC_CAL_RESETN, 0x4);
  724. b43_radio_set(dev, R2057_RFPLL_MISC_EN, 0x01);
  725. usleep_range(300, 600);
  726. }
  727. /* Calibrate resistors in LPF of PLL?
  728. * http://bcm-v4.sipsolutions.net/PHY/radio205x_rcal
  729. */
  730. static u8 b43_radio_2057_rcal(struct b43_wldev *dev)
  731. {
  732. struct b43_phy *phy = &dev->phy;
  733. u16 saved_regs_phy[12];
  734. u16 saved_regs_phy_rf[6];
  735. u16 saved_regs_radio[2] = { };
  736. static const u16 phy_to_store[] = {
  737. B43_NPHY_RFCTL_RSSIO1, B43_NPHY_RFCTL_RSSIO2,
  738. B43_NPHY_RFCTL_LUT_TRSW_LO1, B43_NPHY_RFCTL_LUT_TRSW_LO2,
  739. B43_NPHY_RFCTL_RXG1, B43_NPHY_RFCTL_RXG2,
  740. B43_NPHY_RFCTL_TXG1, B43_NPHY_RFCTL_TXG2,
  741. B43_NPHY_REV7_RF_CTL_MISC_REG3, B43_NPHY_REV7_RF_CTL_MISC_REG4,
  742. B43_NPHY_REV7_RF_CTL_MISC_REG5, B43_NPHY_REV7_RF_CTL_MISC_REG6,
  743. };
  744. static const u16 phy_to_store_rf[] = {
  745. B43_NPHY_REV3_RFCTL_OVER0, B43_NPHY_REV3_RFCTL_OVER1,
  746. B43_NPHY_REV7_RF_CTL_OVER3, B43_NPHY_REV7_RF_CTL_OVER4,
  747. B43_NPHY_REV7_RF_CTL_OVER5, B43_NPHY_REV7_RF_CTL_OVER6,
  748. };
  749. u16 tmp;
  750. int i;
  751. /* Save */
  752. for (i = 0; i < ARRAY_SIZE(phy_to_store); i++)
  753. saved_regs_phy[i] = b43_phy_read(dev, phy_to_store[i]);
  754. for (i = 0; i < ARRAY_SIZE(phy_to_store_rf); i++)
  755. saved_regs_phy_rf[i] = b43_phy_read(dev, phy_to_store_rf[i]);
  756. /* Set */
  757. for (i = 0; i < ARRAY_SIZE(phy_to_store); i++)
  758. b43_phy_write(dev, phy_to_store[i], 0);
  759. b43_phy_write(dev, B43_NPHY_REV3_RFCTL_OVER0, 0x07ff);
  760. b43_phy_write(dev, B43_NPHY_REV3_RFCTL_OVER1, 0x07ff);
  761. b43_phy_write(dev, B43_NPHY_REV7_RF_CTL_OVER3, 0x07ff);
  762. b43_phy_write(dev, B43_NPHY_REV7_RF_CTL_OVER4, 0x07ff);
  763. b43_phy_write(dev, B43_NPHY_REV7_RF_CTL_OVER5, 0x007f);
  764. b43_phy_write(dev, B43_NPHY_REV7_RF_CTL_OVER6, 0x007f);
  765. switch (phy->radio_rev) {
  766. case 5:
  767. b43_phy_mask(dev, B43_NPHY_REV7_RF_CTL_OVER3, ~0x2);
  768. udelay(10);
  769. b43_radio_set(dev, R2057_IQTEST_SEL_PU, 0x1);
  770. b43_radio_maskset(dev, R2057v7_IQTEST_SEL_PU2, ~0x2, 0x1);
  771. break;
  772. case 9:
  773. b43_phy_set(dev, B43_NPHY_REV7_RF_CTL_OVER3, 0x2);
  774. b43_phy_set(dev, B43_NPHY_REV7_RF_CTL_MISC_REG3, 0x2);
  775. saved_regs_radio[0] = b43_radio_read(dev, R2057_IQTEST_SEL_PU);
  776. b43_radio_write(dev, R2057_IQTEST_SEL_PU, 0x11);
  777. break;
  778. case 14:
  779. saved_regs_radio[0] = b43_radio_read(dev, R2057_IQTEST_SEL_PU);
  780. saved_regs_radio[1] = b43_radio_read(dev, R2057v7_IQTEST_SEL_PU2);
  781. b43_phy_set(dev, B43_NPHY_REV7_RF_CTL_MISC_REG3, 0x2);
  782. b43_phy_set(dev, B43_NPHY_REV7_RF_CTL_OVER3, 0x2);
  783. b43_radio_write(dev, R2057v7_IQTEST_SEL_PU2, 0x2);
  784. b43_radio_write(dev, R2057_IQTEST_SEL_PU, 0x1);
  785. break;
  786. }
  787. /* Enable */
  788. b43_radio_set(dev, R2057_RCAL_CONFIG, 0x1);
  789. udelay(10);
  790. /* Start */
  791. b43_radio_set(dev, R2057_RCAL_CONFIG, 0x2);
  792. usleep_range(100, 200);
  793. /* Stop */
  794. b43_radio_mask(dev, R2057_RCAL_CONFIG, ~0x2);
  795. /* Wait and check for result */
  796. if (!b43_radio_wait_value(dev, R2057_RCAL_STATUS, 1, 1, 100, 1000000)) {
  797. b43err(dev->wl, "Radio 0x2057 rcal timeout\n");
  798. return 0;
  799. }
  800. tmp = b43_radio_read(dev, R2057_RCAL_STATUS) & 0x3E;
  801. /* Disable */
  802. b43_radio_mask(dev, R2057_RCAL_CONFIG, ~0x1);
  803. /* Restore */
  804. for (i = 0; i < ARRAY_SIZE(phy_to_store_rf); i++)
  805. b43_phy_write(dev, phy_to_store_rf[i], saved_regs_phy_rf[i]);
  806. for (i = 0; i < ARRAY_SIZE(phy_to_store); i++)
  807. b43_phy_write(dev, phy_to_store[i], saved_regs_phy[i]);
  808. switch (phy->radio_rev) {
  809. case 0 ... 4:
  810. case 6:
  811. b43_radio_maskset(dev, R2057_TEMPSENSE_CONFIG, ~0x3C, tmp);
  812. b43_radio_maskset(dev, R2057_BANDGAP_RCAL_TRIM, ~0xF0,
  813. tmp << 2);
  814. break;
  815. case 5:
  816. b43_radio_mask(dev, R2057_IPA2G_CASCONV_CORE0, ~0x1);
  817. b43_radio_mask(dev, R2057v7_IQTEST_SEL_PU2, ~0x2);
  818. break;
  819. case 9:
  820. b43_radio_write(dev, R2057_IQTEST_SEL_PU, saved_regs_radio[0]);
  821. break;
  822. case 14:
  823. b43_radio_write(dev, R2057_IQTEST_SEL_PU, saved_regs_radio[0]);
  824. b43_radio_write(dev, R2057v7_IQTEST_SEL_PU2, saved_regs_radio[1]);
  825. break;
  826. }
  827. return tmp & 0x3e;
  828. }
  829. /* Calibrate the internal RC oscillator?
  830. * http://bcm-v4.sipsolutions.net/PHY/radio2057_rccal
  831. */
  832. static u16 b43_radio_2057_rccal(struct b43_wldev *dev)
  833. {
  834. struct b43_phy *phy = &dev->phy;
  835. bool special = (phy->radio_rev == 3 || phy->radio_rev == 4 ||
  836. phy->radio_rev == 6);
  837. u16 tmp;
  838. /* Setup cal */
  839. if (special) {
  840. b43_radio_write(dev, R2057_RCCAL_MASTER, 0x61);
  841. b43_radio_write(dev, R2057_RCCAL_TRC0, 0xC0);
  842. } else {
  843. b43_radio_write(dev, R2057v7_RCCAL_MASTER, 0x61);
  844. b43_radio_write(dev, R2057_RCCAL_TRC0, 0xE9);
  845. }
  846. b43_radio_write(dev, R2057_RCCAL_X1, 0x6E);
  847. /* Start, wait, stop */
  848. b43_radio_write(dev, R2057_RCCAL_START_R1_Q1_P1, 0x55);
  849. if (!b43_radio_wait_value(dev, R2057_RCCAL_DONE_OSCCAP, 2, 2, 500,
  850. 5000000))
  851. b43dbg(dev->wl, "Radio 0x2057 rccal timeout\n");
  852. usleep_range(35, 70);
  853. b43_radio_write(dev, R2057_RCCAL_START_R1_Q1_P1, 0x15);
  854. usleep_range(70, 140);
  855. /* Setup cal */
  856. if (special) {
  857. b43_radio_write(dev, R2057_RCCAL_MASTER, 0x69);
  858. b43_radio_write(dev, R2057_RCCAL_TRC0, 0xB0);
  859. } else {
  860. b43_radio_write(dev, R2057v7_RCCAL_MASTER, 0x69);
  861. b43_radio_write(dev, R2057_RCCAL_TRC0, 0xD5);
  862. }
  863. b43_radio_write(dev, R2057_RCCAL_X1, 0x6E);
  864. /* Start, wait, stop */
  865. usleep_range(35, 70);
  866. b43_radio_write(dev, R2057_RCCAL_START_R1_Q1_P1, 0x55);
  867. usleep_range(70, 140);
  868. if (!b43_radio_wait_value(dev, R2057_RCCAL_DONE_OSCCAP, 2, 2, 500,
  869. 5000000))
  870. b43dbg(dev->wl, "Radio 0x2057 rccal timeout\n");
  871. usleep_range(35, 70);
  872. b43_radio_write(dev, R2057_RCCAL_START_R1_Q1_P1, 0x15);
  873. usleep_range(70, 140);
  874. /* Setup cal */
  875. if (special) {
  876. b43_radio_write(dev, R2057_RCCAL_MASTER, 0x73);
  877. b43_radio_write(dev, R2057_RCCAL_X1, 0x28);
  878. b43_radio_write(dev, R2057_RCCAL_TRC0, 0xB0);
  879. } else {
  880. b43_radio_write(dev, R2057v7_RCCAL_MASTER, 0x73);
  881. b43_radio_write(dev, R2057_RCCAL_X1, 0x6E);
  882. b43_radio_write(dev, R2057_RCCAL_TRC0, 0x99);
  883. }
  884. /* Start, wait, stop */
  885. usleep_range(35, 70);
  886. b43_radio_write(dev, R2057_RCCAL_START_R1_Q1_P1, 0x55);
  887. usleep_range(70, 140);
  888. if (!b43_radio_wait_value(dev, R2057_RCCAL_DONE_OSCCAP, 2, 2, 500,
  889. 5000000)) {
  890. b43err(dev->wl, "Radio 0x2057 rcal timeout\n");
  891. return 0;
  892. }
  893. tmp = b43_radio_read(dev, R2057_RCCAL_DONE_OSCCAP);
  894. usleep_range(35, 70);
  895. b43_radio_write(dev, R2057_RCCAL_START_R1_Q1_P1, 0x15);
  896. usleep_range(70, 140);
  897. if (special)
  898. b43_radio_mask(dev, R2057_RCCAL_MASTER, ~0x1);
  899. else
  900. b43_radio_mask(dev, R2057v7_RCCAL_MASTER, ~0x1);
  901. return tmp;
  902. }
  903. static void b43_radio_2057_init_pre(struct b43_wldev *dev)
  904. {
  905. b43_phy_mask(dev, B43_NPHY_RFCTL_CMD, ~B43_NPHY_RFCTL_CMD_CHIP0PU);
  906. /* Maybe wl meant to reset and set (order?) RFCTL_CMD_OEPORFORCE? */
  907. b43_phy_mask(dev, B43_NPHY_RFCTL_CMD, B43_NPHY_RFCTL_CMD_OEPORFORCE);
  908. b43_phy_set(dev, B43_NPHY_RFCTL_CMD, ~B43_NPHY_RFCTL_CMD_OEPORFORCE);
  909. b43_phy_set(dev, B43_NPHY_RFCTL_CMD, B43_NPHY_RFCTL_CMD_CHIP0PU);
  910. }
  911. static void b43_radio_2057_init_post(struct b43_wldev *dev)
  912. {
  913. b43_radio_set(dev, R2057_XTALPUOVR_PINCTRL, 0x1);
  914. if (0) /* FIXME: Is this BCM43217 specific? */
  915. b43_radio_set(dev, R2057_XTALPUOVR_PINCTRL, 0x2);
  916. b43_radio_set(dev, R2057_RFPLL_MISC_CAL_RESETN, 0x78);
  917. b43_radio_set(dev, R2057_XTAL_CONFIG2, 0x80);
  918. usleep_range(2000, 3000);
  919. b43_radio_mask(dev, R2057_RFPLL_MISC_CAL_RESETN, ~0x78);
  920. b43_radio_mask(dev, R2057_XTAL_CONFIG2, ~0x80);
  921. if (dev->phy.do_full_init) {
  922. b43_radio_2057_rcal(dev);
  923. b43_radio_2057_rccal(dev);
  924. }
  925. b43_radio_mask(dev, R2057_RFPLL_MASTER, ~0x8);
  926. }
  927. /* http://bcm-v4.sipsolutions.net/802.11/Radio/2057/Init */
  928. static void b43_radio_2057_init(struct b43_wldev *dev)
  929. {
  930. b43_radio_2057_init_pre(dev);
  931. r2057_upload_inittabs(dev);
  932. b43_radio_2057_init_post(dev);
  933. }
  934. /**************************************************
  935. * Radio 0x2056
  936. **************************************************/
  937. static void b43_chantab_radio_2056_upload(struct b43_wldev *dev,
  938. const struct b43_nphy_channeltab_entry_rev3 *e)
  939. {
  940. b43_radio_write(dev, B2056_SYN_PLL_VCOCAL1, e->radio_syn_pll_vcocal1);
  941. b43_radio_write(dev, B2056_SYN_PLL_VCOCAL2, e->radio_syn_pll_vcocal2);
  942. b43_radio_write(dev, B2056_SYN_PLL_REFDIV, e->radio_syn_pll_refdiv);
  943. b43_radio_write(dev, B2056_SYN_PLL_MMD2, e->radio_syn_pll_mmd2);
  944. b43_radio_write(dev, B2056_SYN_PLL_MMD1, e->radio_syn_pll_mmd1);
  945. b43_radio_write(dev, B2056_SYN_PLL_LOOPFILTER1,
  946. e->radio_syn_pll_loopfilter1);
  947. b43_radio_write(dev, B2056_SYN_PLL_LOOPFILTER2,
  948. e->radio_syn_pll_loopfilter2);
  949. b43_radio_write(dev, B2056_SYN_PLL_LOOPFILTER3,
  950. e->radio_syn_pll_loopfilter3);
  951. b43_radio_write(dev, B2056_SYN_PLL_LOOPFILTER4,
  952. e->radio_syn_pll_loopfilter4);
  953. b43_radio_write(dev, B2056_SYN_PLL_LOOPFILTER5,
  954. e->radio_syn_pll_loopfilter5);
  955. b43_radio_write(dev, B2056_SYN_RESERVED_ADDR27,
  956. e->radio_syn_reserved_addr27);
  957. b43_radio_write(dev, B2056_SYN_RESERVED_ADDR28,
  958. e->radio_syn_reserved_addr28);
  959. b43_radio_write(dev, B2056_SYN_RESERVED_ADDR29,
  960. e->radio_syn_reserved_addr29);
  961. b43_radio_write(dev, B2056_SYN_LOGEN_VCOBUF1,
  962. e->radio_syn_logen_vcobuf1);
  963. b43_radio_write(dev, B2056_SYN_LOGEN_MIXER2, e->radio_syn_logen_mixer2);
  964. b43_radio_write(dev, B2056_SYN_LOGEN_BUF3, e->radio_syn_logen_buf3);
  965. b43_radio_write(dev, B2056_SYN_LOGEN_BUF4, e->radio_syn_logen_buf4);
  966. b43_radio_write(dev, B2056_RX0 | B2056_RX_LNAA_TUNE,
  967. e->radio_rx0_lnaa_tune);
  968. b43_radio_write(dev, B2056_RX0 | B2056_RX_LNAG_TUNE,
  969. e->radio_rx0_lnag_tune);
  970. b43_radio_write(dev, B2056_TX0 | B2056_TX_INTPAA_BOOST_TUNE,
  971. e->radio_tx0_intpaa_boost_tune);
  972. b43_radio_write(dev, B2056_TX0 | B2056_TX_INTPAG_BOOST_TUNE,
  973. e->radio_tx0_intpag_boost_tune);
  974. b43_radio_write(dev, B2056_TX0 | B2056_TX_PADA_BOOST_TUNE,
  975. e->radio_tx0_pada_boost_tune);
  976. b43_radio_write(dev, B2056_TX0 | B2056_TX_PADG_BOOST_TUNE,
  977. e->radio_tx0_padg_boost_tune);
  978. b43_radio_write(dev, B2056_TX0 | B2056_TX_PGAA_BOOST_TUNE,
  979. e->radio_tx0_pgaa_boost_tune);
  980. b43_radio_write(dev, B2056_TX0 | B2056_TX_PGAG_BOOST_TUNE,
  981. e->radio_tx0_pgag_boost_tune);
  982. b43_radio_write(dev, B2056_TX0 | B2056_TX_MIXA_BOOST_TUNE,
  983. e->radio_tx0_mixa_boost_tune);
  984. b43_radio_write(dev, B2056_TX0 | B2056_TX_MIXG_BOOST_TUNE,
  985. e->radio_tx0_mixg_boost_tune);
  986. b43_radio_write(dev, B2056_RX1 | B2056_RX_LNAA_TUNE,
  987. e->radio_rx1_lnaa_tune);
  988. b43_radio_write(dev, B2056_RX1 | B2056_RX_LNAG_TUNE,
  989. e->radio_rx1_lnag_tune);
  990. b43_radio_write(dev, B2056_TX1 | B2056_TX_INTPAA_BOOST_TUNE,
  991. e->radio_tx1_intpaa_boost_tune);
  992. b43_radio_write(dev, B2056_TX1 | B2056_TX_INTPAG_BOOST_TUNE,
  993. e->radio_tx1_intpag_boost_tune);
  994. b43_radio_write(dev, B2056_TX1 | B2056_TX_PADA_BOOST_TUNE,
  995. e->radio_tx1_pada_boost_tune);
  996. b43_radio_write(dev, B2056_TX1 | B2056_TX_PADG_BOOST_TUNE,
  997. e->radio_tx1_padg_boost_tune);
  998. b43_radio_write(dev, B2056_TX1 | B2056_TX_PGAA_BOOST_TUNE,
  999. e->radio_tx1_pgaa_boost_tune);
  1000. b43_radio_write(dev, B2056_TX1 | B2056_TX_PGAG_BOOST_TUNE,
  1001. e->radio_tx1_pgag_boost_tune);
  1002. b43_radio_write(dev, B2056_TX1 | B2056_TX_MIXA_BOOST_TUNE,
  1003. e->radio_tx1_mixa_boost_tune);
  1004. b43_radio_write(dev, B2056_TX1 | B2056_TX_MIXG_BOOST_TUNE,
  1005. e->radio_tx1_mixg_boost_tune);
  1006. }
  1007. /* http://bcm-v4.sipsolutions.net/802.11/PHY/Radio/2056Setup */
  1008. static void b43_radio_2056_setup(struct b43_wldev *dev,
  1009. const struct b43_nphy_channeltab_entry_rev3 *e)
  1010. {
  1011. struct b43_phy *phy = &dev->phy;
  1012. struct ssb_sprom *sprom = dev->dev->bus_sprom;
  1013. enum nl80211_band band = b43_current_band(dev->wl);
  1014. u16 offset;
  1015. u8 i;
  1016. u16 bias, cbias;
  1017. u16 pag_boost, padg_boost, pgag_boost, mixg_boost;
  1018. u16 paa_boost, pada_boost, pgaa_boost, mixa_boost;
  1019. bool is_pkg_fab_smic;
  1020. B43_WARN_ON(dev->phy.rev < 3);
  1021. is_pkg_fab_smic =
  1022. ((dev->dev->chip_id == BCMA_CHIP_ID_BCM43224 ||
  1023. dev->dev->chip_id == BCMA_CHIP_ID_BCM43225 ||
  1024. dev->dev->chip_id == BCMA_CHIP_ID_BCM43421) &&
  1025. dev->dev->chip_pkg == BCMA_PKG_ID_BCM43224_FAB_SMIC);
  1026. b43_chantab_radio_2056_upload(dev, e);
  1027. b2056_upload_syn_pll_cp2(dev, band == NL80211_BAND_5GHZ);
  1028. if (sprom->boardflags2_lo & B43_BFL2_GPLL_WAR &&
  1029. b43_current_band(dev->wl) == NL80211_BAND_2GHZ) {
  1030. b43_radio_write(dev, B2056_SYN_PLL_LOOPFILTER1, 0x1F);
  1031. b43_radio_write(dev, B2056_SYN_PLL_LOOPFILTER2, 0x1F);
  1032. if (dev->dev->chip_id == BCMA_CHIP_ID_BCM4716 ||
  1033. dev->dev->chip_id == BCMA_CHIP_ID_BCM47162) {
  1034. b43_radio_write(dev, B2056_SYN_PLL_LOOPFILTER4, 0x14);
  1035. b43_radio_write(dev, B2056_SYN_PLL_CP2, 0);
  1036. } else {
  1037. b43_radio_write(dev, B2056_SYN_PLL_LOOPFILTER4, 0x0B);
  1038. b43_radio_write(dev, B2056_SYN_PLL_CP2, 0x14);
  1039. }
  1040. }
  1041. if (sprom->boardflags2_hi & B43_BFH2_GPLL_WAR2 &&
  1042. b43_current_band(dev->wl) == NL80211_BAND_2GHZ) {
  1043. b43_radio_write(dev, B2056_SYN_PLL_LOOPFILTER1, 0x1f);
  1044. b43_radio_write(dev, B2056_SYN_PLL_LOOPFILTER2, 0x1f);
  1045. b43_radio_write(dev, B2056_SYN_PLL_LOOPFILTER4, 0x0b);
  1046. b43_radio_write(dev, B2056_SYN_PLL_CP2, 0x20);
  1047. }
  1048. if (sprom->boardflags2_lo & B43_BFL2_APLL_WAR &&
  1049. b43_current_band(dev->wl) == NL80211_BAND_5GHZ) {
  1050. b43_radio_write(dev, B2056_SYN_PLL_LOOPFILTER1, 0x1F);
  1051. b43_radio_write(dev, B2056_SYN_PLL_LOOPFILTER2, 0x1F);
  1052. b43_radio_write(dev, B2056_SYN_PLL_LOOPFILTER4, 0x05);
  1053. b43_radio_write(dev, B2056_SYN_PLL_CP2, 0x0C);
  1054. }
  1055. if (dev->phy.n->ipa2g_on && band == NL80211_BAND_2GHZ) {
  1056. for (i = 0; i < 2; i++) {
  1057. offset = i ? B2056_TX1 : B2056_TX0;
  1058. if (dev->phy.rev >= 5) {
  1059. b43_radio_write(dev,
  1060. offset | B2056_TX_PADG_IDAC, 0xcc);
  1061. if (dev->dev->chip_id == BCMA_CHIP_ID_BCM4716 ||
  1062. dev->dev->chip_id == BCMA_CHIP_ID_BCM47162) {
  1063. bias = 0x40;
  1064. cbias = 0x45;
  1065. pag_boost = 0x5;
  1066. pgag_boost = 0x33;
  1067. mixg_boost = 0x55;
  1068. } else {
  1069. bias = 0x25;
  1070. cbias = 0x20;
  1071. if (is_pkg_fab_smic) {
  1072. bias = 0x2a;
  1073. cbias = 0x38;
  1074. }
  1075. pag_boost = 0x4;
  1076. pgag_boost = 0x03;
  1077. mixg_boost = 0x65;
  1078. }
  1079. padg_boost = 0x77;
  1080. b43_radio_write(dev,
  1081. offset | B2056_TX_INTPAG_IMAIN_STAT,
  1082. bias);
  1083. b43_radio_write(dev,
  1084. offset | B2056_TX_INTPAG_IAUX_STAT,
  1085. bias);
  1086. b43_radio_write(dev,
  1087. offset | B2056_TX_INTPAG_CASCBIAS,
  1088. cbias);
  1089. b43_radio_write(dev,
  1090. offset | B2056_TX_INTPAG_BOOST_TUNE,
  1091. pag_boost);
  1092. b43_radio_write(dev,
  1093. offset | B2056_TX_PGAG_BOOST_TUNE,
  1094. pgag_boost);
  1095. b43_radio_write(dev,
  1096. offset | B2056_TX_PADG_BOOST_TUNE,
  1097. padg_boost);
  1098. b43_radio_write(dev,
  1099. offset | B2056_TX_MIXG_BOOST_TUNE,
  1100. mixg_boost);
  1101. } else {
  1102. bias = b43_is_40mhz(dev) ? 0x40 : 0x20;
  1103. b43_radio_write(dev,
  1104. offset | B2056_TX_INTPAG_IMAIN_STAT,
  1105. bias);
  1106. b43_radio_write(dev,
  1107. offset | B2056_TX_INTPAG_IAUX_STAT,
  1108. bias);
  1109. b43_radio_write(dev,
  1110. offset | B2056_TX_INTPAG_CASCBIAS,
  1111. 0x30);
  1112. }
  1113. b43_radio_write(dev, offset | B2056_TX_PA_SPARE1, 0xee);
  1114. }
  1115. } else if (dev->phy.n->ipa5g_on && band == NL80211_BAND_5GHZ) {
  1116. u16 freq = phy->chandef->chan->center_freq;
  1117. if (freq < 5100) {
  1118. paa_boost = 0xA;
  1119. pada_boost = 0x77;
  1120. pgaa_boost = 0xF;
  1121. mixa_boost = 0xF;
  1122. } else if (freq < 5340) {
  1123. paa_boost = 0x8;
  1124. pada_boost = 0x77;
  1125. pgaa_boost = 0xFB;
  1126. mixa_boost = 0xF;
  1127. } else if (freq < 5650) {
  1128. paa_boost = 0x0;
  1129. pada_boost = 0x77;
  1130. pgaa_boost = 0xB;
  1131. mixa_boost = 0xF;
  1132. } else {
  1133. paa_boost = 0x0;
  1134. pada_boost = 0x77;
  1135. if (freq != 5825)
  1136. pgaa_boost = -(freq - 18) / 36 + 168;
  1137. else
  1138. pgaa_boost = 6;
  1139. mixa_boost = 0xF;
  1140. }
  1141. cbias = is_pkg_fab_smic ? 0x35 : 0x30;
  1142. for (i = 0; i < 2; i++) {
  1143. offset = i ? B2056_TX1 : B2056_TX0;
  1144. b43_radio_write(dev,
  1145. offset | B2056_TX_INTPAA_BOOST_TUNE, paa_boost);
  1146. b43_radio_write(dev,
  1147. offset | B2056_TX_PADA_BOOST_TUNE, pada_boost);
  1148. b43_radio_write(dev,
  1149. offset | B2056_TX_PGAA_BOOST_TUNE, pgaa_boost);
  1150. b43_radio_write(dev,
  1151. offset | B2056_TX_MIXA_BOOST_TUNE, mixa_boost);
  1152. b43_radio_write(dev,
  1153. offset | B2056_TX_TXSPARE1, 0x30);
  1154. b43_radio_write(dev,
  1155. offset | B2056_TX_PA_SPARE2, 0xee);
  1156. b43_radio_write(dev,
  1157. offset | B2056_TX_PADA_CASCBIAS, 0x03);
  1158. b43_radio_write(dev,
  1159. offset | B2056_TX_INTPAA_IAUX_STAT, 0x30);
  1160. b43_radio_write(dev,
  1161. offset | B2056_TX_INTPAA_IMAIN_STAT, 0x30);
  1162. b43_radio_write(dev,
  1163. offset | B2056_TX_INTPAA_CASCBIAS, cbias);
  1164. }
  1165. }
  1166. udelay(50);
  1167. /* VCO calibration */
  1168. b43_radio_write(dev, B2056_SYN_PLL_VCOCAL12, 0x00);
  1169. b43_radio_write(dev, B2056_TX_INTPAA_PA_MISC, 0x38);
  1170. b43_radio_write(dev, B2056_TX_INTPAA_PA_MISC, 0x18);
  1171. b43_radio_write(dev, B2056_TX_INTPAA_PA_MISC, 0x38);
  1172. b43_radio_write(dev, B2056_TX_INTPAA_PA_MISC, 0x39);
  1173. udelay(300);
  1174. }
  1175. static u8 b43_radio_2056_rcal(struct b43_wldev *dev)
  1176. {
  1177. struct b43_phy *phy = &dev->phy;
  1178. u16 mast2, tmp;
  1179. if (phy->rev != 3)
  1180. return 0;
  1181. mast2 = b43_radio_read(dev, B2056_SYN_PLL_MAST2);
  1182. b43_radio_write(dev, B2056_SYN_PLL_MAST2, mast2 | 0x7);
  1183. udelay(10);
  1184. b43_radio_write(dev, B2056_SYN_RCAL_MASTER, 0x01);
  1185. udelay(10);
  1186. b43_radio_write(dev, B2056_SYN_RCAL_MASTER, 0x09);
  1187. if (!b43_radio_wait_value(dev, B2056_SYN_RCAL_CODE_OUT, 0x80, 0x80, 100,
  1188. 1000000)) {
  1189. b43err(dev->wl, "Radio recalibration timeout\n");
  1190. return 0;
  1191. }
  1192. b43_radio_write(dev, B2056_SYN_RCAL_MASTER, 0x01);
  1193. tmp = b43_radio_read(dev, B2056_SYN_RCAL_CODE_OUT);
  1194. b43_radio_write(dev, B2056_SYN_RCAL_MASTER, 0x00);
  1195. b43_radio_write(dev, B2056_SYN_PLL_MAST2, mast2);
  1196. return tmp & 0x1f;
  1197. }
  1198. static void b43_radio_init2056_pre(struct b43_wldev *dev)
  1199. {
  1200. b43_phy_mask(dev, B43_NPHY_RFCTL_CMD,
  1201. ~B43_NPHY_RFCTL_CMD_CHIP0PU);
  1202. /* Maybe wl meant to reset and set (order?) RFCTL_CMD_OEPORFORCE? */
  1203. b43_phy_mask(dev, B43_NPHY_RFCTL_CMD,
  1204. B43_NPHY_RFCTL_CMD_OEPORFORCE);
  1205. b43_phy_set(dev, B43_NPHY_RFCTL_CMD,
  1206. ~B43_NPHY_RFCTL_CMD_OEPORFORCE);
  1207. b43_phy_set(dev, B43_NPHY_RFCTL_CMD,
  1208. B43_NPHY_RFCTL_CMD_CHIP0PU);
  1209. }
  1210. static void b43_radio_init2056_post(struct b43_wldev *dev)
  1211. {
  1212. b43_radio_set(dev, B2056_SYN_COM_CTRL, 0xB);
  1213. b43_radio_set(dev, B2056_SYN_COM_PU, 0x2);
  1214. b43_radio_set(dev, B2056_SYN_COM_RESET, 0x2);
  1215. msleep(1);
  1216. b43_radio_mask(dev, B2056_SYN_COM_RESET, ~0x2);
  1217. b43_radio_mask(dev, B2056_SYN_PLL_MAST2, ~0xFC);
  1218. b43_radio_mask(dev, B2056_SYN_RCCAL_CTRL0, ~0x1);
  1219. if (dev->phy.do_full_init)
  1220. b43_radio_2056_rcal(dev);
  1221. }
  1222. /*
  1223. * Initialize a Broadcom 2056 N-radio
  1224. * http://bcm-v4.sipsolutions.net/802.11/Radio/2056/Init
  1225. */
  1226. static void b43_radio_init2056(struct b43_wldev *dev)
  1227. {
  1228. b43_radio_init2056_pre(dev);
  1229. b2056_upload_inittabs(dev, 0, 0);
  1230. b43_radio_init2056_post(dev);
  1231. }
  1232. /**************************************************
  1233. * Radio 0x2055
  1234. **************************************************/
  1235. static void b43_chantab_radio_upload(struct b43_wldev *dev,
  1236. const struct b43_nphy_channeltab_entry_rev2 *e)
  1237. {
  1238. b43_radio_write(dev, B2055_PLL_REF, e->radio_pll_ref);
  1239. b43_radio_write(dev, B2055_RF_PLLMOD0, e->radio_rf_pllmod0);
  1240. b43_radio_write(dev, B2055_RF_PLLMOD1, e->radio_rf_pllmod1);
  1241. b43_radio_write(dev, B2055_VCO_CAPTAIL, e->radio_vco_captail);
  1242. b43_read32(dev, B43_MMIO_MACCTL); /* flush writes */
  1243. b43_radio_write(dev, B2055_VCO_CAL1, e->radio_vco_cal1);
  1244. b43_radio_write(dev, B2055_VCO_CAL2, e->radio_vco_cal2);
  1245. b43_radio_write(dev, B2055_PLL_LFC1, e->radio_pll_lfc1);
  1246. b43_radio_write(dev, B2055_PLL_LFR1, e->radio_pll_lfr1);
  1247. b43_read32(dev, B43_MMIO_MACCTL); /* flush writes */
  1248. b43_radio_write(dev, B2055_PLL_LFC2, e->radio_pll_lfc2);
  1249. b43_radio_write(dev, B2055_LGBUF_CENBUF, e->radio_lgbuf_cenbuf);
  1250. b43_radio_write(dev, B2055_LGEN_TUNE1, e->radio_lgen_tune1);
  1251. b43_radio_write(dev, B2055_LGEN_TUNE2, e->radio_lgen_tune2);
  1252. b43_read32(dev, B43_MMIO_MACCTL); /* flush writes */
  1253. b43_radio_write(dev, B2055_C1_LGBUF_ATUNE, e->radio_c1_lgbuf_atune);
  1254. b43_radio_write(dev, B2055_C1_LGBUF_GTUNE, e->radio_c1_lgbuf_gtune);
  1255. b43_radio_write(dev, B2055_C1_RX_RFR1, e->radio_c1_rx_rfr1);
  1256. b43_radio_write(dev, B2055_C1_TX_PGAPADTN, e->radio_c1_tx_pgapadtn);
  1257. b43_read32(dev, B43_MMIO_MACCTL); /* flush writes */
  1258. b43_radio_write(dev, B2055_C1_TX_MXBGTRIM, e->radio_c1_tx_mxbgtrim);
  1259. b43_radio_write(dev, B2055_C2_LGBUF_ATUNE, e->radio_c2_lgbuf_atune);
  1260. b43_radio_write(dev, B2055_C2_LGBUF_GTUNE, e->radio_c2_lgbuf_gtune);
  1261. b43_radio_write(dev, B2055_C2_RX_RFR1, e->radio_c2_rx_rfr1);
  1262. b43_read32(dev, B43_MMIO_MACCTL); /* flush writes */
  1263. b43_radio_write(dev, B2055_C2_TX_PGAPADTN, e->radio_c2_tx_pgapadtn);
  1264. b43_radio_write(dev, B2055_C2_TX_MXBGTRIM, e->radio_c2_tx_mxbgtrim);
  1265. }
  1266. /* http://bcm-v4.sipsolutions.net/802.11/PHY/Radio/2055Setup */
  1267. static void b43_radio_2055_setup(struct b43_wldev *dev,
  1268. const struct b43_nphy_channeltab_entry_rev2 *e)
  1269. {
  1270. B43_WARN_ON(dev->phy.rev >= 3);
  1271. b43_chantab_radio_upload(dev, e);
  1272. udelay(50);
  1273. b43_radio_write(dev, B2055_VCO_CAL10, 0x05);
  1274. b43_radio_write(dev, B2055_VCO_CAL10, 0x45);
  1275. b43_read32(dev, B43_MMIO_MACCTL); /* flush writes */
  1276. b43_radio_write(dev, B2055_VCO_CAL10, 0x65);
  1277. udelay(300);
  1278. }
  1279. static void b43_radio_init2055_pre(struct b43_wldev *dev)
  1280. {
  1281. b43_phy_mask(dev, B43_NPHY_RFCTL_CMD,
  1282. ~B43_NPHY_RFCTL_CMD_PORFORCE);
  1283. b43_phy_set(dev, B43_NPHY_RFCTL_CMD,
  1284. B43_NPHY_RFCTL_CMD_CHIP0PU |
  1285. B43_NPHY_RFCTL_CMD_OEPORFORCE);
  1286. b43_phy_set(dev, B43_NPHY_RFCTL_CMD,
  1287. B43_NPHY_RFCTL_CMD_PORFORCE);
  1288. }
  1289. static void b43_radio_init2055_post(struct b43_wldev *dev)
  1290. {
  1291. struct b43_phy_n *nphy = dev->phy.n;
  1292. struct ssb_sprom *sprom = dev->dev->bus_sprom;
  1293. bool workaround = false;
  1294. if (sprom->revision < 4)
  1295. workaround = (dev->dev->board_vendor != PCI_VENDOR_ID_BROADCOM
  1296. && dev->dev->board_type == SSB_BOARD_CB2_4321
  1297. && dev->dev->board_rev >= 0x41);
  1298. else
  1299. workaround =
  1300. !(sprom->boardflags2_lo & B43_BFL2_RXBB_INT_REG_DIS);
  1301. b43_radio_mask(dev, B2055_MASTER1, 0xFFF3);
  1302. if (workaround) {
  1303. b43_radio_mask(dev, B2055_C1_RX_BB_REG, 0x7F);
  1304. b43_radio_mask(dev, B2055_C2_RX_BB_REG, 0x7F);
  1305. }
  1306. b43_radio_maskset(dev, B2055_RRCCAL_NOPTSEL, 0xFFC0, 0x2C);
  1307. b43_radio_write(dev, B2055_CAL_MISC, 0x3C);
  1308. b43_radio_mask(dev, B2055_CAL_MISC, 0xFFBE);
  1309. b43_radio_set(dev, B2055_CAL_LPOCTL, 0x80);
  1310. b43_radio_set(dev, B2055_CAL_MISC, 0x1);
  1311. msleep(1);
  1312. b43_radio_set(dev, B2055_CAL_MISC, 0x40);
  1313. if (!b43_radio_wait_value(dev, B2055_CAL_COUT2, 0x80, 0x80, 10, 2000))
  1314. b43err(dev->wl, "radio post init timeout\n");
  1315. b43_radio_mask(dev, B2055_CAL_LPOCTL, 0xFF7F);
  1316. b43_switch_channel(dev, dev->phy.channel);
  1317. b43_radio_write(dev, B2055_C1_RX_BB_LPF, 0x9);
  1318. b43_radio_write(dev, B2055_C2_RX_BB_LPF, 0x9);
  1319. b43_radio_write(dev, B2055_C1_RX_BB_MIDACHP, 0x83);
  1320. b43_radio_write(dev, B2055_C2_RX_BB_MIDACHP, 0x83);
  1321. b43_radio_maskset(dev, B2055_C1_LNA_GAINBST, 0xFFF8, 0x6);
  1322. b43_radio_maskset(dev, B2055_C2_LNA_GAINBST, 0xFFF8, 0x6);
  1323. if (!nphy->gain_boost) {
  1324. b43_radio_set(dev, B2055_C1_RX_RFSPC1, 0x2);
  1325. b43_radio_set(dev, B2055_C2_RX_RFSPC1, 0x2);
  1326. } else {
  1327. b43_radio_mask(dev, B2055_C1_RX_RFSPC1, 0xFFFD);
  1328. b43_radio_mask(dev, B2055_C2_RX_RFSPC1, 0xFFFD);
  1329. }
  1330. udelay(2);
  1331. }
  1332. /*
  1333. * Initialize a Broadcom 2055 N-radio
  1334. * http://bcm-v4.sipsolutions.net/802.11/Radio/2055/Init
  1335. */
  1336. static void b43_radio_init2055(struct b43_wldev *dev)
  1337. {
  1338. b43_radio_init2055_pre(dev);
  1339. if (b43_status(dev) < B43_STAT_INITIALIZED) {
  1340. /* Follow wl, not specs. Do not force uploading all regs */
  1341. b2055_upload_inittab(dev, 0, 0);
  1342. } else {
  1343. bool ghz5 = b43_current_band(dev->wl) == NL80211_BAND_5GHZ;
  1344. b2055_upload_inittab(dev, ghz5, 0);
  1345. }
  1346. b43_radio_init2055_post(dev);
  1347. }
  1348. /**************************************************
  1349. * Samples
  1350. **************************************************/
  1351. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/LoadSampleTable */
  1352. static int b43_nphy_load_samples(struct b43_wldev *dev,
  1353. struct b43_c32 *samples, u16 len) {
  1354. struct b43_phy_n *nphy = dev->phy.n;
  1355. u16 i;
  1356. u32 *data;
  1357. data = kcalloc(len, sizeof(u32), GFP_KERNEL);
  1358. if (!data) {
  1359. b43err(dev->wl, "allocation for samples loading failed\n");
  1360. return -ENOMEM;
  1361. }
  1362. if (nphy->hang_avoid)
  1363. b43_nphy_stay_in_carrier_search(dev, 1);
  1364. for (i = 0; i < len; i++) {
  1365. data[i] = (samples[i].i & 0x3FF << 10);
  1366. data[i] |= samples[i].q & 0x3FF;
  1367. }
  1368. b43_ntab_write_bulk(dev, B43_NTAB32(17, 0), len, data);
  1369. kfree(data);
  1370. if (nphy->hang_avoid)
  1371. b43_nphy_stay_in_carrier_search(dev, 0);
  1372. return 0;
  1373. }
  1374. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/GenLoadSamples */
  1375. static u16 b43_nphy_gen_load_samples(struct b43_wldev *dev, u32 freq, u16 max,
  1376. bool test)
  1377. {
  1378. int i;
  1379. u16 bw, len, rot, angle;
  1380. struct b43_c32 *samples;
  1381. bw = b43_is_40mhz(dev) ? 40 : 20;
  1382. len = bw << 3;
  1383. if (test) {
  1384. if (b43_phy_read(dev, B43_NPHY_BBCFG) & B43_NPHY_BBCFG_RSTRX)
  1385. bw = 82;
  1386. else
  1387. bw = 80;
  1388. if (b43_is_40mhz(dev))
  1389. bw <<= 1;
  1390. len = bw << 1;
  1391. }
  1392. samples = kcalloc(len, sizeof(struct b43_c32), GFP_KERNEL);
  1393. if (!samples) {
  1394. b43err(dev->wl, "allocation for samples generation failed\n");
  1395. return 0;
  1396. }
  1397. rot = (((freq * 36) / bw) << 16) / 100;
  1398. angle = 0;
  1399. for (i = 0; i < len; i++) {
  1400. samples[i] = b43_cordic(angle);
  1401. angle += rot;
  1402. samples[i].q = CORDIC_CONVERT(samples[i].q * max);
  1403. samples[i].i = CORDIC_CONVERT(samples[i].i * max);
  1404. }
  1405. i = b43_nphy_load_samples(dev, samples, len);
  1406. kfree(samples);
  1407. return (i < 0) ? 0 : len;
  1408. }
  1409. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/RunSamples */
  1410. static void b43_nphy_run_samples(struct b43_wldev *dev, u16 samps, u16 loops,
  1411. u16 wait, bool iqmode, bool dac_test,
  1412. bool modify_bbmult)
  1413. {
  1414. struct b43_phy *phy = &dev->phy;
  1415. struct b43_phy_n *nphy = dev->phy.n;
  1416. int i;
  1417. u16 seq_mode;
  1418. u32 tmp;
  1419. b43_nphy_stay_in_carrier_search(dev, true);
  1420. if (phy->rev >= 7) {
  1421. bool lpf_bw3, lpf_bw4;
  1422. lpf_bw3 = b43_phy_read(dev, B43_NPHY_REV7_RF_CTL_OVER3) & 0x80;
  1423. lpf_bw4 = b43_phy_read(dev, B43_NPHY_REV7_RF_CTL_OVER4) & 0x80;
  1424. if (lpf_bw3 || lpf_bw4) {
  1425. /* TODO */
  1426. } else {
  1427. u16 value = b43_nphy_read_lpf_ctl(dev, 0);
  1428. if (phy->rev >= 19)
  1429. b43_nphy_rf_ctl_override_rev19(dev, 0x80, value,
  1430. 0, false, 1);
  1431. else
  1432. b43_nphy_rf_ctl_override_rev7(dev, 0x80, value,
  1433. 0, false, 1);
  1434. nphy->lpf_bw_overrode_for_sample_play = true;
  1435. }
  1436. }
  1437. if ((nphy->bb_mult_save & 0x80000000) == 0) {
  1438. tmp = b43_ntab_read(dev, B43_NTAB16(15, 87));
  1439. nphy->bb_mult_save = (tmp & 0xFFFF) | 0x80000000;
  1440. }
  1441. if (modify_bbmult) {
  1442. tmp = !b43_is_40mhz(dev) ? 0x6464 : 0x4747;
  1443. b43_ntab_write(dev, B43_NTAB16(15, 87), tmp);
  1444. }
  1445. b43_phy_write(dev, B43_NPHY_SAMP_DEPCNT, (samps - 1));
  1446. if (loops != 0xFFFF)
  1447. b43_phy_write(dev, B43_NPHY_SAMP_LOOPCNT, (loops - 1));
  1448. else
  1449. b43_phy_write(dev, B43_NPHY_SAMP_LOOPCNT, loops);
  1450. b43_phy_write(dev, B43_NPHY_SAMP_WAITCNT, wait);
  1451. seq_mode = b43_phy_read(dev, B43_NPHY_RFSEQMODE);
  1452. b43_phy_set(dev, B43_NPHY_RFSEQMODE, B43_NPHY_RFSEQMODE_CAOVER);
  1453. if (iqmode) {
  1454. b43_phy_mask(dev, B43_NPHY_IQLOCAL_CMDGCTL, 0x7FFF);
  1455. b43_phy_set(dev, B43_NPHY_IQLOCAL_CMDGCTL, 0x8000);
  1456. } else {
  1457. tmp = dac_test ? 5 : 1;
  1458. b43_phy_write(dev, B43_NPHY_SAMP_CMD, tmp);
  1459. }
  1460. for (i = 0; i < 100; i++) {
  1461. if (!(b43_phy_read(dev, B43_NPHY_RFSEQST) & 1)) {
  1462. i = 0;
  1463. break;
  1464. }
  1465. udelay(10);
  1466. }
  1467. if (i)
  1468. b43err(dev->wl, "run samples timeout\n");
  1469. b43_phy_write(dev, B43_NPHY_RFSEQMODE, seq_mode);
  1470. b43_nphy_stay_in_carrier_search(dev, false);
  1471. }
  1472. /**************************************************
  1473. * RSSI
  1474. **************************************************/
  1475. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/ScaleOffsetRssi */
  1476. static void b43_nphy_scale_offset_rssi(struct b43_wldev *dev, u16 scale,
  1477. s8 offset, u8 core,
  1478. enum n_rail_type rail,
  1479. enum n_rssi_type rssi_type)
  1480. {
  1481. u16 tmp;
  1482. bool core1or5 = (core == 1) || (core == 5);
  1483. bool core2or5 = (core == 2) || (core == 5);
  1484. offset = clamp_val(offset, -32, 31);
  1485. tmp = ((scale & 0x3F) << 8) | (offset & 0x3F);
  1486. switch (rssi_type) {
  1487. case N_RSSI_NB:
  1488. if (core1or5 && rail == N_RAIL_I)
  1489. b43_phy_write(dev, B43_NPHY_RSSIMC_0I_RSSI_Z, tmp);
  1490. if (core1or5 && rail == N_RAIL_Q)
  1491. b43_phy_write(dev, B43_NPHY_RSSIMC_0Q_RSSI_Z, tmp);
  1492. if (core2or5 && rail == N_RAIL_I)
  1493. b43_phy_write(dev, B43_NPHY_RSSIMC_1I_RSSI_Z, tmp);
  1494. if (core2or5 && rail == N_RAIL_Q)
  1495. b43_phy_write(dev, B43_NPHY_RSSIMC_1Q_RSSI_Z, tmp);
  1496. break;
  1497. case N_RSSI_W1:
  1498. if (core1or5 && rail == N_RAIL_I)
  1499. b43_phy_write(dev, B43_NPHY_RSSIMC_0I_RSSI_X, tmp);
  1500. if (core1or5 && rail == N_RAIL_Q)
  1501. b43_phy_write(dev, B43_NPHY_RSSIMC_0Q_RSSI_X, tmp);
  1502. if (core2or5 && rail == N_RAIL_I)
  1503. b43_phy_write(dev, B43_NPHY_RSSIMC_1I_RSSI_X, tmp);
  1504. if (core2or5 && rail == N_RAIL_Q)
  1505. b43_phy_write(dev, B43_NPHY_RSSIMC_1Q_RSSI_X, tmp);
  1506. break;
  1507. case N_RSSI_W2:
  1508. if (core1or5 && rail == N_RAIL_I)
  1509. b43_phy_write(dev, B43_NPHY_RSSIMC_0I_RSSI_Y, tmp);
  1510. if (core1or5 && rail == N_RAIL_Q)
  1511. b43_phy_write(dev, B43_NPHY_RSSIMC_0Q_RSSI_Y, tmp);
  1512. if (core2or5 && rail == N_RAIL_I)
  1513. b43_phy_write(dev, B43_NPHY_RSSIMC_1I_RSSI_Y, tmp);
  1514. if (core2or5 && rail == N_RAIL_Q)
  1515. b43_phy_write(dev, B43_NPHY_RSSIMC_1Q_RSSI_Y, tmp);
  1516. break;
  1517. case N_RSSI_TBD:
  1518. if (core1or5 && rail == N_RAIL_I)
  1519. b43_phy_write(dev, B43_NPHY_RSSIMC_0I_TBD, tmp);
  1520. if (core1or5 && rail == N_RAIL_Q)
  1521. b43_phy_write(dev, B43_NPHY_RSSIMC_0Q_TBD, tmp);
  1522. if (core2or5 && rail == N_RAIL_I)
  1523. b43_phy_write(dev, B43_NPHY_RSSIMC_1I_TBD, tmp);
  1524. if (core2or5 && rail == N_RAIL_Q)
  1525. b43_phy_write(dev, B43_NPHY_RSSIMC_1Q_TBD, tmp);
  1526. break;
  1527. case N_RSSI_IQ:
  1528. if (core1or5 && rail == N_RAIL_I)
  1529. b43_phy_write(dev, B43_NPHY_RSSIMC_0I_PWRDET, tmp);
  1530. if (core1or5 && rail == N_RAIL_Q)
  1531. b43_phy_write(dev, B43_NPHY_RSSIMC_0Q_PWRDET, tmp);
  1532. if (core2or5 && rail == N_RAIL_I)
  1533. b43_phy_write(dev, B43_NPHY_RSSIMC_1I_PWRDET, tmp);
  1534. if (core2or5 && rail == N_RAIL_Q)
  1535. b43_phy_write(dev, B43_NPHY_RSSIMC_1Q_PWRDET, tmp);
  1536. break;
  1537. case N_RSSI_TSSI_2G:
  1538. if (core1or5)
  1539. b43_phy_write(dev, B43_NPHY_RSSIMC_0I_TSSI, tmp);
  1540. if (core2or5)
  1541. b43_phy_write(dev, B43_NPHY_RSSIMC_1I_TSSI, tmp);
  1542. break;
  1543. case N_RSSI_TSSI_5G:
  1544. if (core1or5)
  1545. b43_phy_write(dev, B43_NPHY_RSSIMC_0Q_TSSI, tmp);
  1546. if (core2or5)
  1547. b43_phy_write(dev, B43_NPHY_RSSIMC_1Q_TSSI, tmp);
  1548. break;
  1549. }
  1550. }
  1551. static void b43_nphy_rssi_select_rev19(struct b43_wldev *dev, u8 code,
  1552. enum n_rssi_type rssi_type)
  1553. {
  1554. /* TODO */
  1555. }
  1556. static void b43_nphy_rev3_rssi_select(struct b43_wldev *dev, u8 code,
  1557. enum n_rssi_type rssi_type)
  1558. {
  1559. u8 i;
  1560. u16 reg, val;
  1561. if (code == 0) {
  1562. b43_phy_mask(dev, B43_NPHY_AFECTL_OVER1, 0xFDFF);
  1563. b43_phy_mask(dev, B43_NPHY_AFECTL_OVER, 0xFDFF);
  1564. b43_phy_mask(dev, B43_NPHY_AFECTL_C1, 0xFCFF);
  1565. b43_phy_mask(dev, B43_NPHY_AFECTL_C2, 0xFCFF);
  1566. b43_phy_mask(dev, B43_NPHY_TXF_40CO_B1S0, 0xFFDF);
  1567. b43_phy_mask(dev, B43_NPHY_TXF_40CO_B32S1, 0xFFDF);
  1568. b43_phy_mask(dev, B43_NPHY_RFCTL_LUT_TRSW_UP1, 0xFFC3);
  1569. b43_phy_mask(dev, B43_NPHY_RFCTL_LUT_TRSW_UP2, 0xFFC3);
  1570. } else {
  1571. for (i = 0; i < 2; i++) {
  1572. if ((code == 1 && i == 1) || (code == 2 && !i))
  1573. continue;
  1574. reg = (i == 0) ?
  1575. B43_NPHY_AFECTL_OVER1 : B43_NPHY_AFECTL_OVER;
  1576. b43_phy_maskset(dev, reg, 0xFDFF, 0x0200);
  1577. if (rssi_type == N_RSSI_W1 ||
  1578. rssi_type == N_RSSI_W2 ||
  1579. rssi_type == N_RSSI_NB) {
  1580. reg = (i == 0) ?
  1581. B43_NPHY_AFECTL_C1 :
  1582. B43_NPHY_AFECTL_C2;
  1583. b43_phy_maskset(dev, reg, 0xFCFF, 0);
  1584. reg = (i == 0) ?
  1585. B43_NPHY_RFCTL_LUT_TRSW_UP1 :
  1586. B43_NPHY_RFCTL_LUT_TRSW_UP2;
  1587. b43_phy_maskset(dev, reg, 0xFFC3, 0);
  1588. if (rssi_type == N_RSSI_W1)
  1589. val = (b43_current_band(dev->wl) == NL80211_BAND_5GHZ) ? 4 : 8;
  1590. else if (rssi_type == N_RSSI_W2)
  1591. val = 16;
  1592. else
  1593. val = 32;
  1594. b43_phy_set(dev, reg, val);
  1595. reg = (i == 0) ?
  1596. B43_NPHY_TXF_40CO_B1S0 :
  1597. B43_NPHY_TXF_40CO_B32S1;
  1598. b43_phy_set(dev, reg, 0x0020);
  1599. } else {
  1600. if (rssi_type == N_RSSI_TBD)
  1601. val = 0x0100;
  1602. else if (rssi_type == N_RSSI_IQ)
  1603. val = 0x0200;
  1604. else
  1605. val = 0x0300;
  1606. reg = (i == 0) ?
  1607. B43_NPHY_AFECTL_C1 :
  1608. B43_NPHY_AFECTL_C2;
  1609. b43_phy_maskset(dev, reg, 0xFCFF, val);
  1610. b43_phy_maskset(dev, reg, 0xF3FF, val << 2);
  1611. if (rssi_type != N_RSSI_IQ &&
  1612. rssi_type != N_RSSI_TBD) {
  1613. enum nl80211_band band =
  1614. b43_current_band(dev->wl);
  1615. if (dev->phy.rev < 7) {
  1616. if (b43_nphy_ipa(dev))
  1617. val = (band == NL80211_BAND_5GHZ) ? 0xC : 0xE;
  1618. else
  1619. val = 0x11;
  1620. reg = (i == 0) ? B2056_TX0 : B2056_TX1;
  1621. reg |= B2056_TX_TX_SSI_MUX;
  1622. b43_radio_write(dev, reg, val);
  1623. }
  1624. reg = (i == 0) ?
  1625. B43_NPHY_AFECTL_OVER1 :
  1626. B43_NPHY_AFECTL_OVER;
  1627. b43_phy_set(dev, reg, 0x0200);
  1628. }
  1629. }
  1630. }
  1631. }
  1632. }
  1633. static void b43_nphy_rev2_rssi_select(struct b43_wldev *dev, u8 code,
  1634. enum n_rssi_type rssi_type)
  1635. {
  1636. u16 val;
  1637. bool rssi_w1_w2_nb = false;
  1638. switch (rssi_type) {
  1639. case N_RSSI_W1:
  1640. case N_RSSI_W2:
  1641. case N_RSSI_NB:
  1642. val = 0;
  1643. rssi_w1_w2_nb = true;
  1644. break;
  1645. case N_RSSI_TBD:
  1646. val = 1;
  1647. break;
  1648. case N_RSSI_IQ:
  1649. val = 2;
  1650. break;
  1651. default:
  1652. val = 3;
  1653. }
  1654. val = (val << 12) | (val << 14);
  1655. b43_phy_maskset(dev, B43_NPHY_AFECTL_C1, 0x0FFF, val);
  1656. b43_phy_maskset(dev, B43_NPHY_AFECTL_C2, 0x0FFF, val);
  1657. if (rssi_w1_w2_nb) {
  1658. b43_phy_maskset(dev, B43_NPHY_RFCTL_RSSIO1, 0xFFCF,
  1659. (rssi_type + 1) << 4);
  1660. b43_phy_maskset(dev, B43_NPHY_RFCTL_RSSIO2, 0xFFCF,
  1661. (rssi_type + 1) << 4);
  1662. }
  1663. if (code == 0) {
  1664. b43_phy_mask(dev, B43_NPHY_AFECTL_OVER, ~0x3000);
  1665. if (rssi_w1_w2_nb) {
  1666. b43_phy_mask(dev, B43_NPHY_RFCTL_CMD,
  1667. ~(B43_NPHY_RFCTL_CMD_RXEN |
  1668. B43_NPHY_RFCTL_CMD_CORESEL));
  1669. b43_phy_mask(dev, B43_NPHY_RFCTL_OVER,
  1670. ~(0x1 << 12 |
  1671. 0x1 << 5 |
  1672. 0x1 << 1 |
  1673. 0x1));
  1674. b43_phy_mask(dev, B43_NPHY_RFCTL_CMD,
  1675. ~B43_NPHY_RFCTL_CMD_START);
  1676. udelay(20);
  1677. b43_phy_mask(dev, B43_NPHY_RFCTL_OVER, ~0x1);
  1678. }
  1679. } else {
  1680. b43_phy_set(dev, B43_NPHY_AFECTL_OVER, 0x3000);
  1681. if (rssi_w1_w2_nb) {
  1682. b43_phy_maskset(dev, B43_NPHY_RFCTL_CMD,
  1683. ~(B43_NPHY_RFCTL_CMD_RXEN |
  1684. B43_NPHY_RFCTL_CMD_CORESEL),
  1685. (B43_NPHY_RFCTL_CMD_RXEN |
  1686. code << B43_NPHY_RFCTL_CMD_CORESEL_SHIFT));
  1687. b43_phy_set(dev, B43_NPHY_RFCTL_OVER,
  1688. (0x1 << 12 |
  1689. 0x1 << 5 |
  1690. 0x1 << 1 |
  1691. 0x1));
  1692. b43_phy_set(dev, B43_NPHY_RFCTL_CMD,
  1693. B43_NPHY_RFCTL_CMD_START);
  1694. udelay(20);
  1695. b43_phy_mask(dev, B43_NPHY_RFCTL_OVER, ~0x1);
  1696. }
  1697. }
  1698. }
  1699. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/RSSISel */
  1700. static void b43_nphy_rssi_select(struct b43_wldev *dev, u8 code,
  1701. enum n_rssi_type type)
  1702. {
  1703. if (dev->phy.rev >= 19)
  1704. b43_nphy_rssi_select_rev19(dev, code, type);
  1705. else if (dev->phy.rev >= 3)
  1706. b43_nphy_rev3_rssi_select(dev, code, type);
  1707. else
  1708. b43_nphy_rev2_rssi_select(dev, code, type);
  1709. }
  1710. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/SetRssi2055Vcm */
  1711. static void b43_nphy_set_rssi_2055_vcm(struct b43_wldev *dev,
  1712. enum n_rssi_type rssi_type, u8 *buf)
  1713. {
  1714. int i;
  1715. for (i = 0; i < 2; i++) {
  1716. if (rssi_type == N_RSSI_NB) {
  1717. if (i == 0) {
  1718. b43_radio_maskset(dev, B2055_C1_B0NB_RSSIVCM,
  1719. 0xFC, buf[0]);
  1720. b43_radio_maskset(dev, B2055_C1_RX_BB_RSSICTL5,
  1721. 0xFC, buf[1]);
  1722. } else {
  1723. b43_radio_maskset(dev, B2055_C2_B0NB_RSSIVCM,
  1724. 0xFC, buf[2 * i]);
  1725. b43_radio_maskset(dev, B2055_C2_RX_BB_RSSICTL5,
  1726. 0xFC, buf[2 * i + 1]);
  1727. }
  1728. } else {
  1729. if (i == 0)
  1730. b43_radio_maskset(dev, B2055_C1_RX_BB_RSSICTL5,
  1731. 0xF3, buf[0] << 2);
  1732. else
  1733. b43_radio_maskset(dev, B2055_C2_RX_BB_RSSICTL5,
  1734. 0xF3, buf[2 * i + 1] << 2);
  1735. }
  1736. }
  1737. }
  1738. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/PollRssi */
  1739. static int b43_nphy_poll_rssi(struct b43_wldev *dev, enum n_rssi_type rssi_type,
  1740. s32 *buf, u8 nsamp)
  1741. {
  1742. int i;
  1743. int out;
  1744. u16 save_regs_phy[9];
  1745. u16 s[2];
  1746. /* TODO: rev7+ is treated like rev3+, what about rev19+? */
  1747. if (dev->phy.rev >= 3) {
  1748. save_regs_phy[0] = b43_phy_read(dev, B43_NPHY_AFECTL_C1);
  1749. save_regs_phy[1] = b43_phy_read(dev, B43_NPHY_AFECTL_C2);
  1750. save_regs_phy[2] = b43_phy_read(dev,
  1751. B43_NPHY_RFCTL_LUT_TRSW_UP1);
  1752. save_regs_phy[3] = b43_phy_read(dev,
  1753. B43_NPHY_RFCTL_LUT_TRSW_UP2);
  1754. save_regs_phy[4] = b43_phy_read(dev, B43_NPHY_AFECTL_OVER1);
  1755. save_regs_phy[5] = b43_phy_read(dev, B43_NPHY_AFECTL_OVER);
  1756. save_regs_phy[6] = b43_phy_read(dev, B43_NPHY_TXF_40CO_B1S0);
  1757. save_regs_phy[7] = b43_phy_read(dev, B43_NPHY_TXF_40CO_B32S1);
  1758. save_regs_phy[8] = 0;
  1759. } else {
  1760. save_regs_phy[0] = b43_phy_read(dev, B43_NPHY_AFECTL_C1);
  1761. save_regs_phy[1] = b43_phy_read(dev, B43_NPHY_AFECTL_C2);
  1762. save_regs_phy[2] = b43_phy_read(dev, B43_NPHY_AFECTL_OVER);
  1763. save_regs_phy[3] = b43_phy_read(dev, B43_NPHY_RFCTL_CMD);
  1764. save_regs_phy[4] = b43_phy_read(dev, B43_NPHY_RFCTL_OVER);
  1765. save_regs_phy[5] = b43_phy_read(dev, B43_NPHY_RFCTL_RSSIO1);
  1766. save_regs_phy[6] = b43_phy_read(dev, B43_NPHY_RFCTL_RSSIO2);
  1767. save_regs_phy[7] = 0;
  1768. save_regs_phy[8] = 0;
  1769. }
  1770. b43_nphy_rssi_select(dev, 5, rssi_type);
  1771. if (dev->phy.rev < 2) {
  1772. save_regs_phy[8] = b43_phy_read(dev, B43_NPHY_GPIO_SEL);
  1773. b43_phy_write(dev, B43_NPHY_GPIO_SEL, 5);
  1774. }
  1775. for (i = 0; i < 4; i++)
  1776. buf[i] = 0;
  1777. for (i = 0; i < nsamp; i++) {
  1778. if (dev->phy.rev < 2) {
  1779. s[0] = b43_phy_read(dev, B43_NPHY_GPIO_LOOUT);
  1780. s[1] = b43_phy_read(dev, B43_NPHY_GPIO_HIOUT);
  1781. } else {
  1782. s[0] = b43_phy_read(dev, B43_NPHY_RSSI1);
  1783. s[1] = b43_phy_read(dev, B43_NPHY_RSSI2);
  1784. }
  1785. buf[0] += ((s8)((s[0] & 0x3F) << 2)) >> 2;
  1786. buf[1] += ((s8)(((s[0] >> 8) & 0x3F) << 2)) >> 2;
  1787. buf[2] += ((s8)((s[1] & 0x3F) << 2)) >> 2;
  1788. buf[3] += ((s8)(((s[1] >> 8) & 0x3F) << 2)) >> 2;
  1789. }
  1790. out = (buf[0] & 0xFF) << 24 | (buf[1] & 0xFF) << 16 |
  1791. (buf[2] & 0xFF) << 8 | (buf[3] & 0xFF);
  1792. if (dev->phy.rev < 2)
  1793. b43_phy_write(dev, B43_NPHY_GPIO_SEL, save_regs_phy[8]);
  1794. if (dev->phy.rev >= 3) {
  1795. b43_phy_write(dev, B43_NPHY_AFECTL_C1, save_regs_phy[0]);
  1796. b43_phy_write(dev, B43_NPHY_AFECTL_C2, save_regs_phy[1]);
  1797. b43_phy_write(dev, B43_NPHY_RFCTL_LUT_TRSW_UP1,
  1798. save_regs_phy[2]);
  1799. b43_phy_write(dev, B43_NPHY_RFCTL_LUT_TRSW_UP2,
  1800. save_regs_phy[3]);
  1801. b43_phy_write(dev, B43_NPHY_AFECTL_OVER1, save_regs_phy[4]);
  1802. b43_phy_write(dev, B43_NPHY_AFECTL_OVER, save_regs_phy[5]);
  1803. b43_phy_write(dev, B43_NPHY_TXF_40CO_B1S0, save_regs_phy[6]);
  1804. b43_phy_write(dev, B43_NPHY_TXF_40CO_B32S1, save_regs_phy[7]);
  1805. } else {
  1806. b43_phy_write(dev, B43_NPHY_AFECTL_C1, save_regs_phy[0]);
  1807. b43_phy_write(dev, B43_NPHY_AFECTL_C2, save_regs_phy[1]);
  1808. b43_phy_write(dev, B43_NPHY_AFECTL_OVER, save_regs_phy[2]);
  1809. b43_phy_write(dev, B43_NPHY_RFCTL_CMD, save_regs_phy[3]);
  1810. b43_phy_write(dev, B43_NPHY_RFCTL_OVER, save_regs_phy[4]);
  1811. b43_phy_write(dev, B43_NPHY_RFCTL_RSSIO1, save_regs_phy[5]);
  1812. b43_phy_write(dev, B43_NPHY_RFCTL_RSSIO2, save_regs_phy[6]);
  1813. }
  1814. return out;
  1815. }
  1816. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/RSSICalRev3 */
  1817. static void b43_nphy_rev3_rssi_cal(struct b43_wldev *dev)
  1818. {
  1819. struct b43_phy *phy = &dev->phy;
  1820. struct b43_phy_n *nphy = dev->phy.n;
  1821. u16 saved_regs_phy_rfctl[2];
  1822. u16 saved_regs_phy[22];
  1823. u16 regs_to_store_rev3[] = {
  1824. B43_NPHY_AFECTL_OVER1, B43_NPHY_AFECTL_OVER,
  1825. B43_NPHY_AFECTL_C1, B43_NPHY_AFECTL_C2,
  1826. B43_NPHY_TXF_40CO_B1S1, B43_NPHY_RFCTL_OVER,
  1827. B43_NPHY_TXF_40CO_B1S0, B43_NPHY_TXF_40CO_B32S1,
  1828. B43_NPHY_RFCTL_CMD,
  1829. B43_NPHY_RFCTL_LUT_TRSW_UP1, B43_NPHY_RFCTL_LUT_TRSW_UP2,
  1830. B43_NPHY_RFCTL_RSSIO1, B43_NPHY_RFCTL_RSSIO2
  1831. };
  1832. u16 regs_to_store_rev7[] = {
  1833. B43_NPHY_AFECTL_OVER1, B43_NPHY_AFECTL_OVER,
  1834. B43_NPHY_AFECTL_C1, B43_NPHY_AFECTL_C2,
  1835. B43_NPHY_TXF_40CO_B1S1, B43_NPHY_RFCTL_OVER,
  1836. B43_NPHY_REV7_RF_CTL_OVER3, B43_NPHY_REV7_RF_CTL_OVER4,
  1837. B43_NPHY_REV7_RF_CTL_OVER5, B43_NPHY_REV7_RF_CTL_OVER6,
  1838. 0x2ff,
  1839. B43_NPHY_TXF_40CO_B1S0, B43_NPHY_TXF_40CO_B32S1,
  1840. B43_NPHY_RFCTL_CMD,
  1841. B43_NPHY_RFCTL_LUT_TRSW_UP1, B43_NPHY_RFCTL_LUT_TRSW_UP2,
  1842. B43_NPHY_REV7_RF_CTL_MISC_REG3, B43_NPHY_REV7_RF_CTL_MISC_REG4,
  1843. B43_NPHY_REV7_RF_CTL_MISC_REG5, B43_NPHY_REV7_RF_CTL_MISC_REG6,
  1844. B43_NPHY_RFCTL_RSSIO1, B43_NPHY_RFCTL_RSSIO2
  1845. };
  1846. u16 *regs_to_store;
  1847. int regs_amount;
  1848. u16 class;
  1849. u16 clip_state[2];
  1850. u16 clip_off[2] = { 0xFFFF, 0xFFFF };
  1851. u8 vcm_final = 0;
  1852. s32 offset[4];
  1853. s32 results[8][4] = { };
  1854. s32 results_min[4] = { };
  1855. s32 poll_results[4] = { };
  1856. u16 *rssical_radio_regs = NULL;
  1857. u16 *rssical_phy_regs = NULL;
  1858. u16 r; /* routing */
  1859. u8 rx_core_state;
  1860. int core, i, j, vcm;
  1861. if (dev->phy.rev >= 7) {
  1862. regs_to_store = regs_to_store_rev7;
  1863. regs_amount = ARRAY_SIZE(regs_to_store_rev7);
  1864. } else {
  1865. regs_to_store = regs_to_store_rev3;
  1866. regs_amount = ARRAY_SIZE(regs_to_store_rev3);
  1867. }
  1868. BUG_ON(regs_amount > ARRAY_SIZE(saved_regs_phy));
  1869. class = b43_nphy_classifier(dev, 0, 0);
  1870. b43_nphy_classifier(dev, 7, 4);
  1871. b43_nphy_read_clip_detection(dev, clip_state);
  1872. b43_nphy_write_clip_detection(dev, clip_off);
  1873. saved_regs_phy_rfctl[0] = b43_phy_read(dev, B43_NPHY_RFCTL_INTC1);
  1874. saved_regs_phy_rfctl[1] = b43_phy_read(dev, B43_NPHY_RFCTL_INTC2);
  1875. for (i = 0; i < regs_amount; i++)
  1876. saved_regs_phy[i] = b43_phy_read(dev, regs_to_store[i]);
  1877. b43_nphy_rf_ctl_intc_override(dev, N_INTC_OVERRIDE_OFF, 0, 7);
  1878. b43_nphy_rf_ctl_intc_override(dev, N_INTC_OVERRIDE_TRSW, 1, 7);
  1879. if (dev->phy.rev >= 7) {
  1880. b43_nphy_rf_ctl_override_one_to_many(dev,
  1881. N_RF_CTL_OVER_CMD_RXRF_PU,
  1882. 0, 0, false);
  1883. b43_nphy_rf_ctl_override_one_to_many(dev,
  1884. N_RF_CTL_OVER_CMD_RX_PU,
  1885. 1, 0, false);
  1886. b43_nphy_rf_ctl_override_rev7(dev, 0x80, 1, 0, false, 0);
  1887. b43_nphy_rf_ctl_override_rev7(dev, 0x40, 1, 0, false, 0);
  1888. if (b43_current_band(dev->wl) == NL80211_BAND_5GHZ) {
  1889. b43_nphy_rf_ctl_override_rev7(dev, 0x20, 0, 0, false,
  1890. 0);
  1891. b43_nphy_rf_ctl_override_rev7(dev, 0x10, 1, 0, false,
  1892. 0);
  1893. } else {
  1894. b43_nphy_rf_ctl_override_rev7(dev, 0x10, 0, 0, false,
  1895. 0);
  1896. b43_nphy_rf_ctl_override_rev7(dev, 0x20, 1, 0, false,
  1897. 0);
  1898. }
  1899. } else {
  1900. b43_nphy_rf_ctl_override(dev, 0x1, 0, 0, false);
  1901. b43_nphy_rf_ctl_override(dev, 0x2, 1, 0, false);
  1902. b43_nphy_rf_ctl_override(dev, 0x80, 1, 0, false);
  1903. b43_nphy_rf_ctl_override(dev, 0x40, 1, 0, false);
  1904. if (b43_current_band(dev->wl) == NL80211_BAND_5GHZ) {
  1905. b43_nphy_rf_ctl_override(dev, 0x20, 0, 0, false);
  1906. b43_nphy_rf_ctl_override(dev, 0x10, 1, 0, false);
  1907. } else {
  1908. b43_nphy_rf_ctl_override(dev, 0x10, 0, 0, false);
  1909. b43_nphy_rf_ctl_override(dev, 0x20, 1, 0, false);
  1910. }
  1911. }
  1912. rx_core_state = b43_nphy_get_rx_core_state(dev);
  1913. for (core = 0; core < 2; core++) {
  1914. if (!(rx_core_state & (1 << core)))
  1915. continue;
  1916. r = core ? B2056_RX1 : B2056_RX0;
  1917. b43_nphy_scale_offset_rssi(dev, 0, 0, core + 1, N_RAIL_I,
  1918. N_RSSI_NB);
  1919. b43_nphy_scale_offset_rssi(dev, 0, 0, core + 1, N_RAIL_Q,
  1920. N_RSSI_NB);
  1921. /* Grab RSSI results for every possible VCM */
  1922. for (vcm = 0; vcm < 8; vcm++) {
  1923. if (dev->phy.rev >= 7)
  1924. b43_radio_maskset(dev,
  1925. core ? R2057_NB_MASTER_CORE1 :
  1926. R2057_NB_MASTER_CORE0,
  1927. ~R2057_VCM_MASK, vcm);
  1928. else
  1929. b43_radio_maskset(dev, r | B2056_RX_RSSI_MISC,
  1930. 0xE3, vcm << 2);
  1931. b43_nphy_poll_rssi(dev, N_RSSI_NB, results[vcm], 8);
  1932. }
  1933. /* Find out which VCM got the best results */
  1934. for (i = 0; i < 4; i += 2) {
  1935. s32 currd;
  1936. s32 mind = 0x100000;
  1937. s32 minpoll = 249;
  1938. u8 minvcm = 0;
  1939. if (2 * core != i)
  1940. continue;
  1941. for (vcm = 0; vcm < 8; vcm++) {
  1942. currd = results[vcm][i] * results[vcm][i] +
  1943. results[vcm][i + 1] * results[vcm][i];
  1944. if (currd < mind) {
  1945. mind = currd;
  1946. minvcm = vcm;
  1947. }
  1948. if (results[vcm][i] < minpoll)
  1949. minpoll = results[vcm][i];
  1950. }
  1951. vcm_final = minvcm;
  1952. results_min[i] = minpoll;
  1953. }
  1954. /* Select the best VCM */
  1955. if (dev->phy.rev >= 7)
  1956. b43_radio_maskset(dev,
  1957. core ? R2057_NB_MASTER_CORE1 :
  1958. R2057_NB_MASTER_CORE0,
  1959. ~R2057_VCM_MASK, vcm);
  1960. else
  1961. b43_radio_maskset(dev, r | B2056_RX_RSSI_MISC,
  1962. 0xE3, vcm_final << 2);
  1963. for (i = 0; i < 4; i++) {
  1964. if (core != i / 2)
  1965. continue;
  1966. offset[i] = -results[vcm_final][i];
  1967. if (offset[i] < 0)
  1968. offset[i] = -((abs(offset[i]) + 4) / 8);
  1969. else
  1970. offset[i] = (offset[i] + 4) / 8;
  1971. if (results_min[i] == 248)
  1972. offset[i] = -32;
  1973. b43_nphy_scale_offset_rssi(dev, 0, offset[i],
  1974. (i / 2 == 0) ? 1 : 2,
  1975. (i % 2 == 0) ? N_RAIL_I : N_RAIL_Q,
  1976. N_RSSI_NB);
  1977. }
  1978. }
  1979. for (core = 0; core < 2; core++) {
  1980. if (!(rx_core_state & (1 << core)))
  1981. continue;
  1982. for (i = 0; i < 2; i++) {
  1983. b43_nphy_scale_offset_rssi(dev, 0, 0, core + 1,
  1984. N_RAIL_I, i);
  1985. b43_nphy_scale_offset_rssi(dev, 0, 0, core + 1,
  1986. N_RAIL_Q, i);
  1987. b43_nphy_poll_rssi(dev, i, poll_results, 8);
  1988. for (j = 0; j < 4; j++) {
  1989. if (j / 2 == core) {
  1990. offset[j] = 232 - poll_results[j];
  1991. if (offset[j] < 0)
  1992. offset[j] = -(abs(offset[j] + 4) / 8);
  1993. else
  1994. offset[j] = (offset[j] + 4) / 8;
  1995. b43_nphy_scale_offset_rssi(dev, 0,
  1996. offset[2 * core], core + 1, j % 2, i);
  1997. }
  1998. }
  1999. }
  2000. }
  2001. b43_phy_write(dev, B43_NPHY_RFCTL_INTC1, saved_regs_phy_rfctl[0]);
  2002. b43_phy_write(dev, B43_NPHY_RFCTL_INTC2, saved_regs_phy_rfctl[1]);
  2003. b43_nphy_force_rf_sequence(dev, B43_RFSEQ_RESET2RX);
  2004. b43_phy_set(dev, B43_NPHY_TXF_40CO_B1S1, 0x1);
  2005. b43_phy_set(dev, B43_NPHY_RFCTL_CMD, B43_NPHY_RFCTL_CMD_START);
  2006. b43_phy_mask(dev, B43_NPHY_TXF_40CO_B1S1, ~0x1);
  2007. b43_phy_set(dev, B43_NPHY_RFCTL_OVER, 0x1);
  2008. b43_phy_set(dev, B43_NPHY_RFCTL_CMD, B43_NPHY_RFCTL_CMD_RXTX);
  2009. b43_phy_mask(dev, B43_NPHY_RFCTL_OVER, ~0x1);
  2010. for (i = 0; i < regs_amount; i++)
  2011. b43_phy_write(dev, regs_to_store[i], saved_regs_phy[i]);
  2012. /* Store for future configuration */
  2013. if (b43_current_band(dev->wl) == NL80211_BAND_2GHZ) {
  2014. rssical_radio_regs = nphy->rssical_cache.rssical_radio_regs_2G;
  2015. rssical_phy_regs = nphy->rssical_cache.rssical_phy_regs_2G;
  2016. } else {
  2017. rssical_radio_regs = nphy->rssical_cache.rssical_radio_regs_5G;
  2018. rssical_phy_regs = nphy->rssical_cache.rssical_phy_regs_5G;
  2019. }
  2020. if (dev->phy.rev >= 7) {
  2021. rssical_radio_regs[0] = b43_radio_read(dev,
  2022. R2057_NB_MASTER_CORE0);
  2023. rssical_radio_regs[1] = b43_radio_read(dev,
  2024. R2057_NB_MASTER_CORE1);
  2025. } else {
  2026. rssical_radio_regs[0] = b43_radio_read(dev, B2056_RX0 |
  2027. B2056_RX_RSSI_MISC);
  2028. rssical_radio_regs[1] = b43_radio_read(dev, B2056_RX1 |
  2029. B2056_RX_RSSI_MISC);
  2030. }
  2031. rssical_phy_regs[0] = b43_phy_read(dev, B43_NPHY_RSSIMC_0I_RSSI_Z);
  2032. rssical_phy_regs[1] = b43_phy_read(dev, B43_NPHY_RSSIMC_0Q_RSSI_Z);
  2033. rssical_phy_regs[2] = b43_phy_read(dev, B43_NPHY_RSSIMC_1I_RSSI_Z);
  2034. rssical_phy_regs[3] = b43_phy_read(dev, B43_NPHY_RSSIMC_1Q_RSSI_Z);
  2035. rssical_phy_regs[4] = b43_phy_read(dev, B43_NPHY_RSSIMC_0I_RSSI_X);
  2036. rssical_phy_regs[5] = b43_phy_read(dev, B43_NPHY_RSSIMC_0Q_RSSI_X);
  2037. rssical_phy_regs[6] = b43_phy_read(dev, B43_NPHY_RSSIMC_1I_RSSI_X);
  2038. rssical_phy_regs[7] = b43_phy_read(dev, B43_NPHY_RSSIMC_1Q_RSSI_X);
  2039. rssical_phy_regs[8] = b43_phy_read(dev, B43_NPHY_RSSIMC_0I_RSSI_Y);
  2040. rssical_phy_regs[9] = b43_phy_read(dev, B43_NPHY_RSSIMC_0Q_RSSI_Y);
  2041. rssical_phy_regs[10] = b43_phy_read(dev, B43_NPHY_RSSIMC_1I_RSSI_Y);
  2042. rssical_phy_regs[11] = b43_phy_read(dev, B43_NPHY_RSSIMC_1Q_RSSI_Y);
  2043. /* Remember for which channel we store configuration */
  2044. if (b43_current_band(dev->wl) == NL80211_BAND_2GHZ)
  2045. nphy->rssical_chanspec_2G.center_freq = phy->chandef->chan->center_freq;
  2046. else
  2047. nphy->rssical_chanspec_5G.center_freq = phy->chandef->chan->center_freq;
  2048. /* End of calibration, restore configuration */
  2049. b43_nphy_classifier(dev, 7, class);
  2050. b43_nphy_write_clip_detection(dev, clip_state);
  2051. }
  2052. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/RSSICal */
  2053. static void b43_nphy_rev2_rssi_cal(struct b43_wldev *dev, enum n_rssi_type type)
  2054. {
  2055. int i, j, vcm;
  2056. u8 state[4];
  2057. u8 code, val;
  2058. u16 class, override;
  2059. u8 regs_save_radio[2];
  2060. u16 regs_save_phy[2];
  2061. s32 offset[4];
  2062. u8 core;
  2063. u8 rail;
  2064. u16 clip_state[2];
  2065. u16 clip_off[2] = { 0xFFFF, 0xFFFF };
  2066. s32 results_min[4] = { };
  2067. u8 vcm_final[4] = { };
  2068. s32 results[4][4] = { };
  2069. s32 miniq[4][2] = { };
  2070. if (type == N_RSSI_NB) {
  2071. code = 0;
  2072. val = 6;
  2073. } else if (type == N_RSSI_W1 || type == N_RSSI_W2) {
  2074. code = 25;
  2075. val = 4;
  2076. } else {
  2077. B43_WARN_ON(1);
  2078. return;
  2079. }
  2080. class = b43_nphy_classifier(dev, 0, 0);
  2081. b43_nphy_classifier(dev, 7, 4);
  2082. b43_nphy_read_clip_detection(dev, clip_state);
  2083. b43_nphy_write_clip_detection(dev, clip_off);
  2084. if (b43_current_band(dev->wl) == NL80211_BAND_5GHZ)
  2085. override = 0x140;
  2086. else
  2087. override = 0x110;
  2088. regs_save_phy[0] = b43_phy_read(dev, B43_NPHY_RFCTL_INTC1);
  2089. regs_save_radio[0] = b43_radio_read(dev, B2055_C1_PD_RXTX);
  2090. b43_phy_write(dev, B43_NPHY_RFCTL_INTC1, override);
  2091. b43_radio_write(dev, B2055_C1_PD_RXTX, val);
  2092. regs_save_phy[1] = b43_phy_read(dev, B43_NPHY_RFCTL_INTC2);
  2093. regs_save_radio[1] = b43_radio_read(dev, B2055_C2_PD_RXTX);
  2094. b43_phy_write(dev, B43_NPHY_RFCTL_INTC2, override);
  2095. b43_radio_write(dev, B2055_C2_PD_RXTX, val);
  2096. state[0] = b43_radio_read(dev, B2055_C1_PD_RSSIMISC) & 0x07;
  2097. state[1] = b43_radio_read(dev, B2055_C2_PD_RSSIMISC) & 0x07;
  2098. b43_radio_mask(dev, B2055_C1_PD_RSSIMISC, 0xF8);
  2099. b43_radio_mask(dev, B2055_C2_PD_RSSIMISC, 0xF8);
  2100. state[2] = b43_radio_read(dev, B2055_C1_SP_RSSI) & 0x07;
  2101. state[3] = b43_radio_read(dev, B2055_C2_SP_RSSI) & 0x07;
  2102. b43_nphy_rssi_select(dev, 5, type);
  2103. b43_nphy_scale_offset_rssi(dev, 0, 0, 5, N_RAIL_I, type);
  2104. b43_nphy_scale_offset_rssi(dev, 0, 0, 5, N_RAIL_Q, type);
  2105. for (vcm = 0; vcm < 4; vcm++) {
  2106. u8 tmp[4];
  2107. for (j = 0; j < 4; j++)
  2108. tmp[j] = vcm;
  2109. if (type != N_RSSI_W2)
  2110. b43_nphy_set_rssi_2055_vcm(dev, type, tmp);
  2111. b43_nphy_poll_rssi(dev, type, results[vcm], 8);
  2112. if (type == N_RSSI_W1 || type == N_RSSI_W2)
  2113. for (j = 0; j < 2; j++)
  2114. miniq[vcm][j] = min(results[vcm][2 * j],
  2115. results[vcm][2 * j + 1]);
  2116. }
  2117. for (i = 0; i < 4; i++) {
  2118. s32 mind = 0x100000;
  2119. u8 minvcm = 0;
  2120. s32 minpoll = 249;
  2121. s32 currd;
  2122. for (vcm = 0; vcm < 4; vcm++) {
  2123. if (type == N_RSSI_NB)
  2124. currd = abs(results[vcm][i] - code * 8);
  2125. else
  2126. currd = abs(miniq[vcm][i / 2] - code * 8);
  2127. if (currd < mind) {
  2128. mind = currd;
  2129. minvcm = vcm;
  2130. }
  2131. if (results[vcm][i] < minpoll)
  2132. minpoll = results[vcm][i];
  2133. }
  2134. results_min[i] = minpoll;
  2135. vcm_final[i] = minvcm;
  2136. }
  2137. if (type != N_RSSI_W2)
  2138. b43_nphy_set_rssi_2055_vcm(dev, type, vcm_final);
  2139. for (i = 0; i < 4; i++) {
  2140. offset[i] = (code * 8) - results[vcm_final[i]][i];
  2141. if (offset[i] < 0)
  2142. offset[i] = -((abs(offset[i]) + 4) / 8);
  2143. else
  2144. offset[i] = (offset[i] + 4) / 8;
  2145. if (results_min[i] == 248)
  2146. offset[i] = code - 32;
  2147. core = (i / 2) ? 2 : 1;
  2148. rail = (i % 2) ? N_RAIL_Q : N_RAIL_I;
  2149. b43_nphy_scale_offset_rssi(dev, 0, offset[i], core, rail,
  2150. type);
  2151. }
  2152. b43_radio_maskset(dev, B2055_C1_PD_RSSIMISC, 0xF8, state[0]);
  2153. b43_radio_maskset(dev, B2055_C2_PD_RSSIMISC, 0xF8, state[1]);
  2154. switch (state[2]) {
  2155. case 1:
  2156. b43_nphy_rssi_select(dev, 1, N_RSSI_NB);
  2157. break;
  2158. case 4:
  2159. b43_nphy_rssi_select(dev, 1, N_RSSI_W1);
  2160. break;
  2161. case 2:
  2162. b43_nphy_rssi_select(dev, 1, N_RSSI_W2);
  2163. break;
  2164. default:
  2165. b43_nphy_rssi_select(dev, 1, N_RSSI_W2);
  2166. break;
  2167. }
  2168. switch (state[3]) {
  2169. case 1:
  2170. b43_nphy_rssi_select(dev, 2, N_RSSI_NB);
  2171. break;
  2172. case 4:
  2173. b43_nphy_rssi_select(dev, 2, N_RSSI_W1);
  2174. break;
  2175. default:
  2176. b43_nphy_rssi_select(dev, 2, N_RSSI_W2);
  2177. break;
  2178. }
  2179. b43_nphy_rssi_select(dev, 0, type);
  2180. b43_phy_write(dev, B43_NPHY_RFCTL_INTC1, regs_save_phy[0]);
  2181. b43_radio_write(dev, B2055_C1_PD_RXTX, regs_save_radio[0]);
  2182. b43_phy_write(dev, B43_NPHY_RFCTL_INTC2, regs_save_phy[1]);
  2183. b43_radio_write(dev, B2055_C2_PD_RXTX, regs_save_radio[1]);
  2184. b43_nphy_classifier(dev, 7, class);
  2185. b43_nphy_write_clip_detection(dev, clip_state);
  2186. /* Specs don't say about reset here, but it makes wl and b43 dumps
  2187. identical, it really seems wl performs this */
  2188. b43_nphy_reset_cca(dev);
  2189. }
  2190. /*
  2191. * RSSI Calibration
  2192. * http://bcm-v4.sipsolutions.net/802.11/PHY/N/RSSICal
  2193. */
  2194. static void b43_nphy_rssi_cal(struct b43_wldev *dev)
  2195. {
  2196. if (dev->phy.rev >= 19) {
  2197. /* TODO */
  2198. } else if (dev->phy.rev >= 3) {
  2199. b43_nphy_rev3_rssi_cal(dev);
  2200. } else {
  2201. b43_nphy_rev2_rssi_cal(dev, N_RSSI_NB);
  2202. b43_nphy_rev2_rssi_cal(dev, N_RSSI_W1);
  2203. b43_nphy_rev2_rssi_cal(dev, N_RSSI_W2);
  2204. }
  2205. }
  2206. /**************************************************
  2207. * Workarounds
  2208. **************************************************/
  2209. static void b43_nphy_gain_ctl_workarounds_rev19(struct b43_wldev *dev)
  2210. {
  2211. /* TODO */
  2212. }
  2213. static void b43_nphy_gain_ctl_workarounds_rev7(struct b43_wldev *dev)
  2214. {
  2215. struct b43_phy *phy = &dev->phy;
  2216. switch (phy->rev) {
  2217. /* TODO */
  2218. }
  2219. }
  2220. static void b43_nphy_gain_ctl_workarounds_rev3(struct b43_wldev *dev)
  2221. {
  2222. struct ssb_sprom *sprom = dev->dev->bus_sprom;
  2223. bool ghz5;
  2224. bool ext_lna;
  2225. u16 rssi_gain;
  2226. struct nphy_gain_ctl_workaround_entry *e;
  2227. u8 lpf_gain[6] = { 0x00, 0x06, 0x0C, 0x12, 0x12, 0x12 };
  2228. u8 lpf_bits[6] = { 0, 1, 2, 3, 3, 3 };
  2229. /* Prepare values */
  2230. ghz5 = b43_phy_read(dev, B43_NPHY_BANDCTL)
  2231. & B43_NPHY_BANDCTL_5GHZ;
  2232. ext_lna = ghz5 ? sprom->boardflags_hi & B43_BFH_EXTLNA_5GHZ :
  2233. sprom->boardflags_lo & B43_BFL_EXTLNA;
  2234. e = b43_nphy_get_gain_ctl_workaround_ent(dev, ghz5, ext_lna);
  2235. if (ghz5 && dev->phy.rev >= 5)
  2236. rssi_gain = 0x90;
  2237. else
  2238. rssi_gain = 0x50;
  2239. b43_phy_set(dev, B43_NPHY_RXCTL, 0x0040);
  2240. /* Set Clip 2 detect */
  2241. b43_phy_set(dev, B43_NPHY_C1_CGAINI, B43_NPHY_C1_CGAINI_CL2DETECT);
  2242. b43_phy_set(dev, B43_NPHY_C2_CGAINI, B43_NPHY_C2_CGAINI_CL2DETECT);
  2243. b43_radio_write(dev, B2056_RX0 | B2056_RX_BIASPOLE_LNAG1_IDAC,
  2244. 0x17);
  2245. b43_radio_write(dev, B2056_RX1 | B2056_RX_BIASPOLE_LNAG1_IDAC,
  2246. 0x17);
  2247. b43_radio_write(dev, B2056_RX0 | B2056_RX_LNAG2_IDAC, 0xF0);
  2248. b43_radio_write(dev, B2056_RX1 | B2056_RX_LNAG2_IDAC, 0xF0);
  2249. b43_radio_write(dev, B2056_RX0 | B2056_RX_RSSI_POLE, 0x00);
  2250. b43_radio_write(dev, B2056_RX1 | B2056_RX_RSSI_POLE, 0x00);
  2251. b43_radio_write(dev, B2056_RX0 | B2056_RX_RSSI_GAIN,
  2252. rssi_gain);
  2253. b43_radio_write(dev, B2056_RX1 | B2056_RX_RSSI_GAIN,
  2254. rssi_gain);
  2255. b43_radio_write(dev, B2056_RX0 | B2056_RX_BIASPOLE_LNAA1_IDAC,
  2256. 0x17);
  2257. b43_radio_write(dev, B2056_RX1 | B2056_RX_BIASPOLE_LNAA1_IDAC,
  2258. 0x17);
  2259. b43_radio_write(dev, B2056_RX0 | B2056_RX_LNAA2_IDAC, 0xFF);
  2260. b43_radio_write(dev, B2056_RX1 | B2056_RX_LNAA2_IDAC, 0xFF);
  2261. b43_ntab_write_bulk(dev, B43_NTAB8(0, 8), 4, e->lna1_gain);
  2262. b43_ntab_write_bulk(dev, B43_NTAB8(1, 8), 4, e->lna1_gain);
  2263. b43_ntab_write_bulk(dev, B43_NTAB8(0, 16), 4, e->lna2_gain);
  2264. b43_ntab_write_bulk(dev, B43_NTAB8(1, 16), 4, e->lna2_gain);
  2265. b43_ntab_write_bulk(dev, B43_NTAB8(0, 32), 10, e->gain_db);
  2266. b43_ntab_write_bulk(dev, B43_NTAB8(1, 32), 10, e->gain_db);
  2267. b43_ntab_write_bulk(dev, B43_NTAB8(2, 32), 10, e->gain_bits);
  2268. b43_ntab_write_bulk(dev, B43_NTAB8(3, 32), 10, e->gain_bits);
  2269. b43_ntab_write_bulk(dev, B43_NTAB8(0, 0x40), 6, lpf_gain);
  2270. b43_ntab_write_bulk(dev, B43_NTAB8(1, 0x40), 6, lpf_gain);
  2271. b43_ntab_write_bulk(dev, B43_NTAB8(2, 0x40), 6, lpf_bits);
  2272. b43_ntab_write_bulk(dev, B43_NTAB8(3, 0x40), 6, lpf_bits);
  2273. b43_phy_write(dev, B43_NPHY_REV3_C1_INITGAIN_A, e->init_gain);
  2274. b43_phy_write(dev, B43_NPHY_REV3_C2_INITGAIN_A, e->init_gain);
  2275. b43_ntab_write_bulk(dev, B43_NTAB16(7, 0x106), 2,
  2276. e->rfseq_init);
  2277. b43_phy_write(dev, B43_NPHY_REV3_C1_CLIP_HIGAIN_A, e->cliphi_gain);
  2278. b43_phy_write(dev, B43_NPHY_REV3_C2_CLIP_HIGAIN_A, e->cliphi_gain);
  2279. b43_phy_write(dev, B43_NPHY_REV3_C1_CLIP_MEDGAIN_A, e->clipmd_gain);
  2280. b43_phy_write(dev, B43_NPHY_REV3_C2_CLIP_MEDGAIN_A, e->clipmd_gain);
  2281. b43_phy_write(dev, B43_NPHY_REV3_C1_CLIP_LOGAIN_A, e->cliplo_gain);
  2282. b43_phy_write(dev, B43_NPHY_REV3_C2_CLIP_LOGAIN_A, e->cliplo_gain);
  2283. b43_phy_maskset(dev, B43_NPHY_CRSMINPOWER0, 0xFF00, e->crsmin);
  2284. b43_phy_maskset(dev, B43_NPHY_CRSMINPOWERL0, 0xFF00, e->crsminl);
  2285. b43_phy_maskset(dev, B43_NPHY_CRSMINPOWERU0, 0xFF00, e->crsminu);
  2286. b43_phy_write(dev, B43_NPHY_C1_NBCLIPTHRES, e->nbclip);
  2287. b43_phy_write(dev, B43_NPHY_C2_NBCLIPTHRES, e->nbclip);
  2288. b43_phy_maskset(dev, B43_NPHY_C1_CLIPWBTHRES,
  2289. ~B43_NPHY_C1_CLIPWBTHRES_CLIP2, e->wlclip);
  2290. b43_phy_maskset(dev, B43_NPHY_C2_CLIPWBTHRES,
  2291. ~B43_NPHY_C2_CLIPWBTHRES_CLIP2, e->wlclip);
  2292. b43_phy_write(dev, B43_NPHY_CCK_SHIFTB_REF, 0x809C);
  2293. }
  2294. static void b43_nphy_gain_ctl_workarounds_rev1_2(struct b43_wldev *dev)
  2295. {
  2296. struct b43_phy_n *nphy = dev->phy.n;
  2297. u8 i, j;
  2298. u8 code;
  2299. u16 tmp;
  2300. u8 rfseq_events[3] = { 6, 8, 7 };
  2301. u8 rfseq_delays[3] = { 10, 30, 1 };
  2302. /* Set Clip 2 detect */
  2303. b43_phy_set(dev, B43_NPHY_C1_CGAINI, B43_NPHY_C1_CGAINI_CL2DETECT);
  2304. b43_phy_set(dev, B43_NPHY_C2_CGAINI, B43_NPHY_C2_CGAINI_CL2DETECT);
  2305. /* Set narrowband clip threshold */
  2306. b43_phy_write(dev, B43_NPHY_C1_NBCLIPTHRES, 0x84);
  2307. b43_phy_write(dev, B43_NPHY_C2_NBCLIPTHRES, 0x84);
  2308. if (!b43_is_40mhz(dev)) {
  2309. /* Set dwell lengths */
  2310. b43_phy_write(dev, B43_NPHY_CLIP1_NBDWELL_LEN, 0x002B);
  2311. b43_phy_write(dev, B43_NPHY_CLIP2_NBDWELL_LEN, 0x002B);
  2312. b43_phy_write(dev, B43_NPHY_W1CLIP1_DWELL_LEN, 0x0009);
  2313. b43_phy_write(dev, B43_NPHY_W1CLIP2_DWELL_LEN, 0x0009);
  2314. }
  2315. /* Set wideband clip 2 threshold */
  2316. b43_phy_maskset(dev, B43_NPHY_C1_CLIPWBTHRES,
  2317. ~B43_NPHY_C1_CLIPWBTHRES_CLIP2, 21);
  2318. b43_phy_maskset(dev, B43_NPHY_C2_CLIPWBTHRES,
  2319. ~B43_NPHY_C2_CLIPWBTHRES_CLIP2, 21);
  2320. if (!b43_is_40mhz(dev)) {
  2321. b43_phy_maskset(dev, B43_NPHY_C1_CGAINI,
  2322. ~B43_NPHY_C1_CGAINI_GAINBKOFF, 0x1);
  2323. b43_phy_maskset(dev, B43_NPHY_C2_CGAINI,
  2324. ~B43_NPHY_C2_CGAINI_GAINBKOFF, 0x1);
  2325. b43_phy_maskset(dev, B43_NPHY_C1_CCK_CGAINI,
  2326. ~B43_NPHY_C1_CCK_CGAINI_GAINBKOFF, 0x1);
  2327. b43_phy_maskset(dev, B43_NPHY_C2_CCK_CGAINI,
  2328. ~B43_NPHY_C2_CCK_CGAINI_GAINBKOFF, 0x1);
  2329. }
  2330. b43_phy_write(dev, B43_NPHY_CCK_SHIFTB_REF, 0x809C);
  2331. if (nphy->gain_boost) {
  2332. if (b43_current_band(dev->wl) == NL80211_BAND_2GHZ &&
  2333. b43_is_40mhz(dev))
  2334. code = 4;
  2335. else
  2336. code = 5;
  2337. } else {
  2338. code = b43_is_40mhz(dev) ? 6 : 7;
  2339. }
  2340. /* Set HPVGA2 index */
  2341. b43_phy_maskset(dev, B43_NPHY_C1_INITGAIN, ~B43_NPHY_C1_INITGAIN_HPVGA2,
  2342. code << B43_NPHY_C1_INITGAIN_HPVGA2_SHIFT);
  2343. b43_phy_maskset(dev, B43_NPHY_C2_INITGAIN, ~B43_NPHY_C2_INITGAIN_HPVGA2,
  2344. code << B43_NPHY_C2_INITGAIN_HPVGA2_SHIFT);
  2345. b43_phy_write(dev, B43_NPHY_TABLE_ADDR, 0x1D06);
  2346. /* specs say about 2 loops, but wl does 4 */
  2347. for (i = 0; i < 4; i++)
  2348. b43_phy_write(dev, B43_NPHY_TABLE_DATALO, (code << 8 | 0x7C));
  2349. b43_nphy_adjust_lna_gain_table(dev);
  2350. if (nphy->elna_gain_config) {
  2351. b43_phy_write(dev, B43_NPHY_TABLE_ADDR, 0x0808);
  2352. b43_phy_write(dev, B43_NPHY_TABLE_DATALO, 0x0);
  2353. b43_phy_write(dev, B43_NPHY_TABLE_DATALO, 0x1);
  2354. b43_phy_write(dev, B43_NPHY_TABLE_DATALO, 0x1);
  2355. b43_phy_write(dev, B43_NPHY_TABLE_DATALO, 0x1);
  2356. b43_phy_write(dev, B43_NPHY_TABLE_ADDR, 0x0C08);
  2357. b43_phy_write(dev, B43_NPHY_TABLE_DATALO, 0x0);
  2358. b43_phy_write(dev, B43_NPHY_TABLE_DATALO, 0x1);
  2359. b43_phy_write(dev, B43_NPHY_TABLE_DATALO, 0x1);
  2360. b43_phy_write(dev, B43_NPHY_TABLE_DATALO, 0x1);
  2361. b43_phy_write(dev, B43_NPHY_TABLE_ADDR, 0x1D06);
  2362. /* specs say about 2 loops, but wl does 4 */
  2363. for (i = 0; i < 4; i++)
  2364. b43_phy_write(dev, B43_NPHY_TABLE_DATALO,
  2365. (code << 8 | 0x74));
  2366. }
  2367. if (dev->phy.rev == 2) {
  2368. for (i = 0; i < 4; i++) {
  2369. b43_phy_write(dev, B43_NPHY_TABLE_ADDR,
  2370. (0x0400 * i) + 0x0020);
  2371. for (j = 0; j < 21; j++) {
  2372. tmp = j * (i < 2 ? 3 : 1);
  2373. b43_phy_write(dev,
  2374. B43_NPHY_TABLE_DATALO, tmp);
  2375. }
  2376. }
  2377. }
  2378. b43_nphy_set_rf_sequence(dev, 5, rfseq_events, rfseq_delays, 3);
  2379. b43_phy_maskset(dev, B43_NPHY_OVER_DGAIN1,
  2380. ~B43_NPHY_OVER_DGAIN_CCKDGECV & 0xFFFF,
  2381. 0x5A << B43_NPHY_OVER_DGAIN_CCKDGECV_SHIFT);
  2382. if (b43_current_band(dev->wl) == NL80211_BAND_2GHZ)
  2383. b43_phy_maskset(dev, B43_PHY_N(0xC5D), 0xFF80, 4);
  2384. }
  2385. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/WorkaroundsGainCtrl */
  2386. static void b43_nphy_gain_ctl_workarounds(struct b43_wldev *dev)
  2387. {
  2388. if (dev->phy.rev >= 19)
  2389. b43_nphy_gain_ctl_workarounds_rev19(dev);
  2390. else if (dev->phy.rev >= 7)
  2391. b43_nphy_gain_ctl_workarounds_rev7(dev);
  2392. else if (dev->phy.rev >= 3)
  2393. b43_nphy_gain_ctl_workarounds_rev3(dev);
  2394. else
  2395. b43_nphy_gain_ctl_workarounds_rev1_2(dev);
  2396. }
  2397. static void b43_nphy_workarounds_rev7plus(struct b43_wldev *dev)
  2398. {
  2399. struct ssb_sprom *sprom = dev->dev->bus_sprom;
  2400. struct b43_phy *phy = &dev->phy;
  2401. /* TX to RX */
  2402. u8 tx2rx_events[7] = { 4, 3, 5, 2, 1, 8, 31, };
  2403. u8 tx2rx_delays[7] = { 8, 4, 4, 4, 4, 6, 1, };
  2404. /* RX to TX */
  2405. u8 rx2tx_events_ipa[9] = { 0x0, 0x1, 0x2, 0x8, 0x5, 0x6, 0xF, 0x3,
  2406. 0x1F };
  2407. u8 rx2tx_delays_ipa[9] = { 8, 6, 6, 4, 4, 16, 43, 1, 1 };
  2408. static const u16 ntab7_15e_16e[] = { 0, 0x10f, 0x10f };
  2409. u8 ntab7_138_146[] = { 0x11, 0x11 };
  2410. u8 ntab7_133[] = { 0x77, 0x11, 0x11 };
  2411. u16 lpf_ofdm_20mhz[2], lpf_ofdm_40mhz[2], lpf_11b[2];
  2412. u16 bcap_val;
  2413. s16 bcap_val_11b[2], bcap_val_11n_20[2], bcap_val_11n_40[2];
  2414. u16 scap_val;
  2415. s16 scap_val_11b[2], scap_val_11n_20[2], scap_val_11n_40[2];
  2416. bool rccal_ovrd = false;
  2417. u16 bias, conv, filt;
  2418. u32 noise_tbl[2];
  2419. u32 tmp32;
  2420. u8 core;
  2421. b43_phy_write(dev, B43_NPHY_PHASETR_A0, 0x0125);
  2422. b43_phy_write(dev, B43_NPHY_PHASETR_A1, 0x01b3);
  2423. b43_phy_write(dev, B43_NPHY_PHASETR_A2, 0x0105);
  2424. b43_phy_write(dev, B43_NPHY_PHASETR_B0, 0x016e);
  2425. b43_phy_write(dev, B43_NPHY_PHASETR_B1, 0x00cd);
  2426. b43_phy_write(dev, B43_NPHY_PHASETR_B2, 0x0020);
  2427. if (phy->rev == 7) {
  2428. b43_phy_set(dev, B43_NPHY_FINERX2_CGC, 0x10);
  2429. b43_phy_maskset(dev, B43_NPHY_FREQGAIN0, 0xFF80, 0x0020);
  2430. b43_phy_maskset(dev, B43_NPHY_FREQGAIN0, 0x80FF, 0x2700);
  2431. b43_phy_maskset(dev, B43_NPHY_FREQGAIN1, 0xFF80, 0x002E);
  2432. b43_phy_maskset(dev, B43_NPHY_FREQGAIN1, 0x80FF, 0x3300);
  2433. b43_phy_maskset(dev, B43_NPHY_FREQGAIN2, 0xFF80, 0x0037);
  2434. b43_phy_maskset(dev, B43_NPHY_FREQGAIN2, 0x80FF, 0x3A00);
  2435. b43_phy_maskset(dev, B43_NPHY_FREQGAIN3, 0xFF80, 0x003C);
  2436. b43_phy_maskset(dev, B43_NPHY_FREQGAIN3, 0x80FF, 0x3E00);
  2437. b43_phy_maskset(dev, B43_NPHY_FREQGAIN4, 0xFF80, 0x003E);
  2438. b43_phy_maskset(dev, B43_NPHY_FREQGAIN4, 0x80FF, 0x3F00);
  2439. b43_phy_maskset(dev, B43_NPHY_FREQGAIN5, 0xFF80, 0x0040);
  2440. b43_phy_maskset(dev, B43_NPHY_FREQGAIN5, 0x80FF, 0x4000);
  2441. b43_phy_maskset(dev, B43_NPHY_FREQGAIN6, 0xFF80, 0x0040);
  2442. b43_phy_maskset(dev, B43_NPHY_FREQGAIN6, 0x80FF, 0x4000);
  2443. b43_phy_maskset(dev, B43_NPHY_FREQGAIN7, 0xFF80, 0x0040);
  2444. b43_phy_maskset(dev, B43_NPHY_FREQGAIN7, 0x80FF, 0x4000);
  2445. }
  2446. if (phy->rev >= 16) {
  2447. b43_phy_write(dev, B43_NPHY_FORCEFRONT0, 0x7ff);
  2448. b43_phy_write(dev, B43_NPHY_FORCEFRONT1, 0x7ff);
  2449. } else if (phy->rev <= 8) {
  2450. b43_phy_write(dev, B43_NPHY_FORCEFRONT0, 0x1B0);
  2451. b43_phy_write(dev, B43_NPHY_FORCEFRONT1, 0x1B0);
  2452. }
  2453. if (phy->rev >= 16)
  2454. b43_phy_maskset(dev, B43_NPHY_TXTAILCNT, ~0xFF, 0xa0);
  2455. else if (phy->rev >= 8)
  2456. b43_phy_maskset(dev, B43_NPHY_TXTAILCNT, ~0xFF, 0x72);
  2457. b43_ntab_write(dev, B43_NTAB16(8, 0x00), 2);
  2458. b43_ntab_write(dev, B43_NTAB16(8, 0x10), 2);
  2459. tmp32 = b43_ntab_read(dev, B43_NTAB32(30, 0));
  2460. tmp32 &= 0xffffff;
  2461. b43_ntab_write(dev, B43_NTAB32(30, 0), tmp32);
  2462. b43_ntab_write_bulk(dev, B43_NTAB16(7, 0x15d), 3, ntab7_15e_16e);
  2463. b43_ntab_write_bulk(dev, B43_NTAB16(7, 0x16d), 3, ntab7_15e_16e);
  2464. b43_nphy_set_rf_sequence(dev, 1, tx2rx_events, tx2rx_delays,
  2465. ARRAY_SIZE(tx2rx_events));
  2466. if (b43_nphy_ipa(dev))
  2467. b43_nphy_set_rf_sequence(dev, 0, rx2tx_events_ipa,
  2468. rx2tx_delays_ipa, ARRAY_SIZE(rx2tx_events_ipa));
  2469. b43_phy_maskset(dev, B43_NPHY_EPS_OVERRIDEI_0, 0x3FFF, 0x4000);
  2470. b43_phy_maskset(dev, B43_NPHY_EPS_OVERRIDEI_1, 0x3FFF, 0x4000);
  2471. for (core = 0; core < 2; core++) {
  2472. lpf_ofdm_20mhz[core] = b43_nphy_read_lpf_ctl(dev, 0x154 + core * 0x10);
  2473. lpf_ofdm_40mhz[core] = b43_nphy_read_lpf_ctl(dev, 0x159 + core * 0x10);
  2474. lpf_11b[core] = b43_nphy_read_lpf_ctl(dev, 0x152 + core * 0x10);
  2475. }
  2476. bcap_val = b43_radio_read(dev, R2057_RCCAL_BCAP_VAL);
  2477. scap_val = b43_radio_read(dev, R2057_RCCAL_SCAP_VAL);
  2478. if (b43_nphy_ipa(dev)) {
  2479. bool ghz2 = b43_current_band(dev->wl) == NL80211_BAND_2GHZ;
  2480. switch (phy->radio_rev) {
  2481. case 5:
  2482. /* Check radio version (to be 0) by PHY rev for now */
  2483. if (phy->rev == 8 && b43_is_40mhz(dev)) {
  2484. for (core = 0; core < 2; core++) {
  2485. scap_val_11b[core] = scap_val;
  2486. bcap_val_11b[core] = bcap_val;
  2487. scap_val_11n_20[core] = scap_val;
  2488. bcap_val_11n_20[core] = bcap_val;
  2489. scap_val_11n_40[core] = 0xc;
  2490. bcap_val_11n_40[core] = 0xc;
  2491. }
  2492. rccal_ovrd = true;
  2493. }
  2494. if (phy->rev == 9) {
  2495. /* TODO: Radio version 1 (e.g. BCM5357B0) */
  2496. }
  2497. break;
  2498. case 7:
  2499. case 8:
  2500. for (core = 0; core < 2; core++) {
  2501. scap_val_11b[core] = scap_val;
  2502. bcap_val_11b[core] = bcap_val;
  2503. lpf_ofdm_20mhz[core] = 4;
  2504. lpf_11b[core] = 1;
  2505. if (b43_current_band(dev->wl) == NL80211_BAND_2GHZ) {
  2506. scap_val_11n_20[core] = 0xc;
  2507. bcap_val_11n_20[core] = 0xc;
  2508. scap_val_11n_40[core] = 0xa;
  2509. bcap_val_11n_40[core] = 0xa;
  2510. } else {
  2511. scap_val_11n_20[core] = 0x14;
  2512. bcap_val_11n_20[core] = 0x14;
  2513. scap_val_11n_40[core] = 0xf;
  2514. bcap_val_11n_40[core] = 0xf;
  2515. }
  2516. }
  2517. rccal_ovrd = true;
  2518. break;
  2519. case 9:
  2520. for (core = 0; core < 2; core++) {
  2521. bcap_val_11b[core] = bcap_val;
  2522. scap_val_11b[core] = scap_val;
  2523. lpf_11b[core] = 1;
  2524. if (ghz2) {
  2525. bcap_val_11n_20[core] = bcap_val + 13;
  2526. scap_val_11n_20[core] = scap_val + 15;
  2527. } else {
  2528. bcap_val_11n_20[core] = bcap_val + 14;
  2529. scap_val_11n_20[core] = scap_val + 15;
  2530. }
  2531. lpf_ofdm_20mhz[core] = 4;
  2532. if (ghz2) {
  2533. bcap_val_11n_40[core] = bcap_val - 7;
  2534. scap_val_11n_40[core] = scap_val - 5;
  2535. } else {
  2536. bcap_val_11n_40[core] = bcap_val + 2;
  2537. scap_val_11n_40[core] = scap_val + 4;
  2538. }
  2539. lpf_ofdm_40mhz[core] = 4;
  2540. }
  2541. rccal_ovrd = true;
  2542. break;
  2543. case 14:
  2544. for (core = 0; core < 2; core++) {
  2545. bcap_val_11b[core] = bcap_val;
  2546. scap_val_11b[core] = scap_val;
  2547. lpf_11b[core] = 1;
  2548. }
  2549. bcap_val_11n_20[0] = bcap_val + 20;
  2550. scap_val_11n_20[0] = scap_val + 20;
  2551. lpf_ofdm_20mhz[0] = 3;
  2552. bcap_val_11n_20[1] = bcap_val + 16;
  2553. scap_val_11n_20[1] = scap_val + 16;
  2554. lpf_ofdm_20mhz[1] = 3;
  2555. bcap_val_11n_40[0] = bcap_val + 20;
  2556. scap_val_11n_40[0] = scap_val + 20;
  2557. lpf_ofdm_40mhz[0] = 4;
  2558. bcap_val_11n_40[1] = bcap_val + 10;
  2559. scap_val_11n_40[1] = scap_val + 10;
  2560. lpf_ofdm_40mhz[1] = 4;
  2561. rccal_ovrd = true;
  2562. break;
  2563. }
  2564. } else {
  2565. if (phy->radio_rev == 5) {
  2566. for (core = 0; core < 2; core++) {
  2567. lpf_ofdm_20mhz[core] = 1;
  2568. lpf_ofdm_40mhz[core] = 3;
  2569. scap_val_11b[core] = scap_val;
  2570. bcap_val_11b[core] = bcap_val;
  2571. scap_val_11n_20[core] = 0x11;
  2572. scap_val_11n_40[core] = 0x11;
  2573. bcap_val_11n_20[core] = 0x13;
  2574. bcap_val_11n_40[core] = 0x13;
  2575. }
  2576. rccal_ovrd = true;
  2577. }
  2578. }
  2579. if (rccal_ovrd) {
  2580. u16 rx2tx_lut_20_11b[2], rx2tx_lut_20_11n[2], rx2tx_lut_40_11n[2];
  2581. u8 rx2tx_lut_extra = 1;
  2582. for (core = 0; core < 2; core++) {
  2583. bcap_val_11b[core] = clamp_val(bcap_val_11b[core], 0, 0x1f);
  2584. scap_val_11b[core] = clamp_val(scap_val_11b[core], 0, 0x1f);
  2585. bcap_val_11n_20[core] = clamp_val(bcap_val_11n_20[core], 0, 0x1f);
  2586. scap_val_11n_20[core] = clamp_val(scap_val_11n_20[core], 0, 0x1f);
  2587. bcap_val_11n_40[core] = clamp_val(bcap_val_11n_40[core], 0, 0x1f);
  2588. scap_val_11n_40[core] = clamp_val(scap_val_11n_40[core], 0, 0x1f);
  2589. rx2tx_lut_20_11b[core] = (rx2tx_lut_extra << 13) |
  2590. (bcap_val_11b[core] << 8) |
  2591. (scap_val_11b[core] << 3) |
  2592. lpf_11b[core];
  2593. rx2tx_lut_20_11n[core] = (rx2tx_lut_extra << 13) |
  2594. (bcap_val_11n_20[core] << 8) |
  2595. (scap_val_11n_20[core] << 3) |
  2596. lpf_ofdm_20mhz[core];
  2597. rx2tx_lut_40_11n[core] = (rx2tx_lut_extra << 13) |
  2598. (bcap_val_11n_40[core] << 8) |
  2599. (scap_val_11n_40[core] << 3) |
  2600. lpf_ofdm_40mhz[core];
  2601. }
  2602. for (core = 0; core < 2; core++) {
  2603. b43_ntab_write(dev, B43_NTAB16(7, 0x152 + core * 16),
  2604. rx2tx_lut_20_11b[core]);
  2605. b43_ntab_write(dev, B43_NTAB16(7, 0x153 + core * 16),
  2606. rx2tx_lut_20_11n[core]);
  2607. b43_ntab_write(dev, B43_NTAB16(7, 0x154 + core * 16),
  2608. rx2tx_lut_20_11n[core]);
  2609. b43_ntab_write(dev, B43_NTAB16(7, 0x155 + core * 16),
  2610. rx2tx_lut_40_11n[core]);
  2611. b43_ntab_write(dev, B43_NTAB16(7, 0x156 + core * 16),
  2612. rx2tx_lut_40_11n[core]);
  2613. b43_ntab_write(dev, B43_NTAB16(7, 0x157 + core * 16),
  2614. rx2tx_lut_40_11n[core]);
  2615. b43_ntab_write(dev, B43_NTAB16(7, 0x158 + core * 16),
  2616. rx2tx_lut_40_11n[core]);
  2617. b43_ntab_write(dev, B43_NTAB16(7, 0x159 + core * 16),
  2618. rx2tx_lut_40_11n[core]);
  2619. }
  2620. }
  2621. b43_phy_write(dev, 0x32F, 0x3);
  2622. if (phy->radio_rev == 4 || phy->radio_rev == 6)
  2623. b43_nphy_rf_ctl_override_rev7(dev, 4, 1, 3, false, 0);
  2624. if (phy->radio_rev == 3 || phy->radio_rev == 4 || phy->radio_rev == 6) {
  2625. if (sprom->revision &&
  2626. sprom->boardflags2_hi & B43_BFH2_IPALVLSHIFT_3P3) {
  2627. b43_radio_write(dev, 0x5, 0x05);
  2628. b43_radio_write(dev, 0x6, 0x30);
  2629. b43_radio_write(dev, 0x7, 0x00);
  2630. b43_radio_set(dev, 0x4f, 0x1);
  2631. b43_radio_set(dev, 0xd4, 0x1);
  2632. bias = 0x1f;
  2633. conv = 0x6f;
  2634. filt = 0xaa;
  2635. } else {
  2636. bias = 0x2b;
  2637. conv = 0x7f;
  2638. filt = 0xee;
  2639. }
  2640. if (b43_current_band(dev->wl) == NL80211_BAND_2GHZ) {
  2641. for (core = 0; core < 2; core++) {
  2642. if (core == 0) {
  2643. b43_radio_write(dev, 0x5F, bias);
  2644. b43_radio_write(dev, 0x64, conv);
  2645. b43_radio_write(dev, 0x66, filt);
  2646. } else {
  2647. b43_radio_write(dev, 0xE8, bias);
  2648. b43_radio_write(dev, 0xE9, conv);
  2649. b43_radio_write(dev, 0xEB, filt);
  2650. }
  2651. }
  2652. }
  2653. }
  2654. if (b43_nphy_ipa(dev)) {
  2655. if (b43_current_band(dev->wl) == NL80211_BAND_2GHZ) {
  2656. if (phy->radio_rev == 3 || phy->radio_rev == 4 ||
  2657. phy->radio_rev == 6) {
  2658. for (core = 0; core < 2; core++) {
  2659. if (core == 0)
  2660. b43_radio_write(dev, 0x51,
  2661. 0x7f);
  2662. else
  2663. b43_radio_write(dev, 0xd6,
  2664. 0x7f);
  2665. }
  2666. }
  2667. switch (phy->radio_rev) {
  2668. case 3:
  2669. for (core = 0; core < 2; core++) {
  2670. if (core == 0) {
  2671. b43_radio_write(dev, 0x64,
  2672. 0x13);
  2673. b43_radio_write(dev, 0x5F,
  2674. 0x1F);
  2675. b43_radio_write(dev, 0x66,
  2676. 0xEE);
  2677. b43_radio_write(dev, 0x59,
  2678. 0x8A);
  2679. b43_radio_write(dev, 0x80,
  2680. 0x3E);
  2681. } else {
  2682. b43_radio_write(dev, 0x69,
  2683. 0x13);
  2684. b43_radio_write(dev, 0xE8,
  2685. 0x1F);
  2686. b43_radio_write(dev, 0xEB,
  2687. 0xEE);
  2688. b43_radio_write(dev, 0xDE,
  2689. 0x8A);
  2690. b43_radio_write(dev, 0x105,
  2691. 0x3E);
  2692. }
  2693. }
  2694. break;
  2695. case 7:
  2696. case 8:
  2697. if (!b43_is_40mhz(dev)) {
  2698. b43_radio_write(dev, 0x5F, 0x14);
  2699. b43_radio_write(dev, 0xE8, 0x12);
  2700. } else {
  2701. b43_radio_write(dev, 0x5F, 0x16);
  2702. b43_radio_write(dev, 0xE8, 0x16);
  2703. }
  2704. break;
  2705. case 14:
  2706. for (core = 0; core < 2; core++) {
  2707. int o = core ? 0x85 : 0;
  2708. b43_radio_write(dev, o + R2057_IPA2G_CASCONV_CORE0, 0x13);
  2709. b43_radio_write(dev, o + R2057_TXMIX2G_TUNE_BOOST_PU_CORE0, 0x21);
  2710. b43_radio_write(dev, o + R2057_IPA2G_BIAS_FILTER_CORE0, 0xff);
  2711. b43_radio_write(dev, o + R2057_PAD2G_IDACS_CORE0, 0x88);
  2712. b43_radio_write(dev, o + R2057_PAD2G_TUNE_PUS_CORE0, 0x23);
  2713. b43_radio_write(dev, o + R2057_IPA2G_IMAIN_CORE0, 0x16);
  2714. b43_radio_write(dev, o + R2057_PAD_BIAS_FILTER_BWS_CORE0, 0x3e);
  2715. b43_radio_write(dev, o + R2057_BACKUP1_CORE0, 0x10);
  2716. }
  2717. break;
  2718. }
  2719. } else {
  2720. u16 freq = phy->chandef->chan->center_freq;
  2721. if ((freq >= 5180 && freq <= 5230) ||
  2722. (freq >= 5745 && freq <= 5805)) {
  2723. b43_radio_write(dev, 0x7D, 0xFF);
  2724. b43_radio_write(dev, 0xFE, 0xFF);
  2725. }
  2726. }
  2727. } else {
  2728. if (phy->radio_rev != 5) {
  2729. for (core = 0; core < 2; core++) {
  2730. if (core == 0) {
  2731. b43_radio_write(dev, 0x5c, 0x61);
  2732. b43_radio_write(dev, 0x51, 0x70);
  2733. } else {
  2734. b43_radio_write(dev, 0xe1, 0x61);
  2735. b43_radio_write(dev, 0xd6, 0x70);
  2736. }
  2737. }
  2738. }
  2739. }
  2740. if (phy->radio_rev == 4) {
  2741. b43_ntab_write(dev, B43_NTAB16(8, 0x05), 0x20);
  2742. b43_ntab_write(dev, B43_NTAB16(8, 0x15), 0x20);
  2743. for (core = 0; core < 2; core++) {
  2744. if (core == 0) {
  2745. b43_radio_write(dev, 0x1a1, 0x00);
  2746. b43_radio_write(dev, 0x1a2, 0x3f);
  2747. b43_radio_write(dev, 0x1a6, 0x3f);
  2748. } else {
  2749. b43_radio_write(dev, 0x1a7, 0x00);
  2750. b43_radio_write(dev, 0x1ab, 0x3f);
  2751. b43_radio_write(dev, 0x1ac, 0x3f);
  2752. }
  2753. }
  2754. } else {
  2755. b43_phy_set(dev, B43_NPHY_AFECTL_C1, 0x4);
  2756. b43_phy_set(dev, B43_NPHY_AFECTL_OVER1, 0x4);
  2757. b43_phy_set(dev, B43_NPHY_AFECTL_C2, 0x4);
  2758. b43_phy_set(dev, B43_NPHY_AFECTL_OVER, 0x4);
  2759. b43_phy_mask(dev, B43_NPHY_AFECTL_C1, ~0x1);
  2760. b43_phy_set(dev, B43_NPHY_AFECTL_OVER1, 0x1);
  2761. b43_phy_mask(dev, B43_NPHY_AFECTL_C2, ~0x1);
  2762. b43_phy_set(dev, B43_NPHY_AFECTL_OVER, 0x1);
  2763. b43_ntab_write(dev, B43_NTAB16(8, 0x05), 0);
  2764. b43_ntab_write(dev, B43_NTAB16(8, 0x15), 0);
  2765. b43_phy_mask(dev, B43_NPHY_AFECTL_C1, ~0x4);
  2766. b43_phy_mask(dev, B43_NPHY_AFECTL_OVER1, ~0x4);
  2767. b43_phy_mask(dev, B43_NPHY_AFECTL_C2, ~0x4);
  2768. b43_phy_mask(dev, B43_NPHY_AFECTL_OVER, ~0x4);
  2769. }
  2770. b43_phy_write(dev, B43_NPHY_ENDROP_TLEN, 0x2);
  2771. b43_ntab_write(dev, B43_NTAB32(16, 0x100), 20);
  2772. b43_ntab_write_bulk(dev, B43_NTAB8(7, 0x138), 2, ntab7_138_146);
  2773. b43_ntab_write(dev, B43_NTAB16(7, 0x141), 0x77);
  2774. b43_ntab_write_bulk(dev, B43_NTAB8(7, 0x133), 3, ntab7_133);
  2775. b43_ntab_write_bulk(dev, B43_NTAB8(7, 0x146), 2, ntab7_138_146);
  2776. b43_ntab_write(dev, B43_NTAB16(7, 0x123), 0x77);
  2777. b43_ntab_write(dev, B43_NTAB16(7, 0x12A), 0x77);
  2778. b43_ntab_read_bulk(dev, B43_NTAB32(16, 0x02), 1, noise_tbl);
  2779. noise_tbl[1] = b43_is_40mhz(dev) ? 0x14D : 0x18D;
  2780. b43_ntab_write_bulk(dev, B43_NTAB32(16, 0x02), 2, noise_tbl);
  2781. b43_ntab_read_bulk(dev, B43_NTAB32(16, 0x7E), 1, noise_tbl);
  2782. noise_tbl[1] = b43_is_40mhz(dev) ? 0x14D : 0x18D;
  2783. b43_ntab_write_bulk(dev, B43_NTAB32(16, 0x7E), 2, noise_tbl);
  2784. b43_nphy_gain_ctl_workarounds(dev);
  2785. /* TODO
  2786. b43_ntab_write_bulk(dev, B43_NTAB16(8, 0x08), 4,
  2787. aux_adc_vmid_rev7_core0);
  2788. b43_ntab_write_bulk(dev, B43_NTAB16(8, 0x18), 4,
  2789. aux_adc_vmid_rev7_core1);
  2790. b43_ntab_write_bulk(dev, B43_NTAB16(8, 0x0C), 4,
  2791. aux_adc_gain_rev7);
  2792. b43_ntab_write_bulk(dev, B43_NTAB16(8, 0x1C), 4,
  2793. aux_adc_gain_rev7);
  2794. */
  2795. }
  2796. static void b43_nphy_workarounds_rev3plus(struct b43_wldev *dev)
  2797. {
  2798. struct b43_phy_n *nphy = dev->phy.n;
  2799. struct ssb_sprom *sprom = dev->dev->bus_sprom;
  2800. /* TX to RX */
  2801. u8 tx2rx_events[7] = { 0x4, 0x3, 0x5, 0x2, 0x1, 0x8, 0x1F };
  2802. u8 tx2rx_delays[7] = { 8, 4, 4, 4, 4, 6, 1 };
  2803. /* RX to TX */
  2804. u8 rx2tx_events_ipa[9] = { 0x0, 0x1, 0x2, 0x8, 0x5, 0x6, 0xF, 0x3,
  2805. 0x1F };
  2806. u8 rx2tx_delays_ipa[9] = { 8, 6, 6, 4, 4, 16, 43, 1, 1 };
  2807. u8 rx2tx_events[9] = { 0x0, 0x1, 0x2, 0x8, 0x5, 0x6, 0x3, 0x4, 0x1F };
  2808. u8 rx2tx_delays[9] = { 8, 6, 6, 4, 4, 18, 42, 1, 1 };
  2809. u16 vmids[5][4] = {
  2810. { 0xa2, 0xb4, 0xb4, 0x89, }, /* 0 */
  2811. { 0xb4, 0xb4, 0xb4, 0x24, }, /* 1 */
  2812. { 0xa2, 0xb4, 0xb4, 0x74, }, /* 2 */
  2813. { 0xa2, 0xb4, 0xb4, 0x270, }, /* 3 */
  2814. { 0xa2, 0xb4, 0xb4, 0x00, }, /* 4 and 5 */
  2815. };
  2816. u16 gains[5][4] = {
  2817. { 0x02, 0x02, 0x02, 0x00, }, /* 0 */
  2818. { 0x02, 0x02, 0x02, 0x02, }, /* 1 */
  2819. { 0x02, 0x02, 0x02, 0x04, }, /* 2 */
  2820. { 0x02, 0x02, 0x02, 0x00, }, /* 3 */
  2821. { 0x02, 0x02, 0x02, 0x00, }, /* 4 and 5 */
  2822. };
  2823. u16 *vmid, *gain;
  2824. u8 pdet_range;
  2825. u16 tmp16;
  2826. u32 tmp32;
  2827. b43_phy_write(dev, B43_NPHY_FORCEFRONT0, 0x1f8);
  2828. b43_phy_write(dev, B43_NPHY_FORCEFRONT1, 0x1f8);
  2829. tmp32 = b43_ntab_read(dev, B43_NTAB32(30, 0));
  2830. tmp32 &= 0xffffff;
  2831. b43_ntab_write(dev, B43_NTAB32(30, 0), tmp32);
  2832. b43_phy_write(dev, B43_NPHY_PHASETR_A0, 0x0125);
  2833. b43_phy_write(dev, B43_NPHY_PHASETR_A1, 0x01B3);
  2834. b43_phy_write(dev, B43_NPHY_PHASETR_A2, 0x0105);
  2835. b43_phy_write(dev, B43_NPHY_PHASETR_B0, 0x016E);
  2836. b43_phy_write(dev, B43_NPHY_PHASETR_B1, 0x00CD);
  2837. b43_phy_write(dev, B43_NPHY_PHASETR_B2, 0x0020);
  2838. b43_phy_write(dev, B43_NPHY_REV3_C1_CLIP_LOGAIN_B, 0x000C);
  2839. b43_phy_write(dev, B43_NPHY_REV3_C2_CLIP_LOGAIN_B, 0x000C);
  2840. /* TX to RX */
  2841. b43_nphy_set_rf_sequence(dev, 1, tx2rx_events, tx2rx_delays,
  2842. ARRAY_SIZE(tx2rx_events));
  2843. /* RX to TX */
  2844. if (b43_nphy_ipa(dev))
  2845. b43_nphy_set_rf_sequence(dev, 0, rx2tx_events_ipa,
  2846. rx2tx_delays_ipa, ARRAY_SIZE(rx2tx_events_ipa));
  2847. if (nphy->hw_phyrxchain != 3 &&
  2848. nphy->hw_phyrxchain != nphy->hw_phytxchain) {
  2849. if (b43_nphy_ipa(dev)) {
  2850. rx2tx_delays[5] = 59;
  2851. rx2tx_delays[6] = 1;
  2852. rx2tx_events[7] = 0x1F;
  2853. }
  2854. b43_nphy_set_rf_sequence(dev, 0, rx2tx_events, rx2tx_delays,
  2855. ARRAY_SIZE(rx2tx_events));
  2856. }
  2857. tmp16 = (b43_current_band(dev->wl) == NL80211_BAND_2GHZ) ?
  2858. 0x2 : 0x9C40;
  2859. b43_phy_write(dev, B43_NPHY_ENDROP_TLEN, tmp16);
  2860. b43_phy_maskset(dev, B43_NPHY_SGILTRNOFFSET, 0xF0FF, 0x0700);
  2861. if (!b43_is_40mhz(dev)) {
  2862. b43_ntab_write(dev, B43_NTAB32(16, 3), 0x18D);
  2863. b43_ntab_write(dev, B43_NTAB32(16, 127), 0x18D);
  2864. } else {
  2865. b43_ntab_write(dev, B43_NTAB32(16, 3), 0x14D);
  2866. b43_ntab_write(dev, B43_NTAB32(16, 127), 0x14D);
  2867. }
  2868. b43_nphy_gain_ctl_workarounds(dev);
  2869. b43_ntab_write(dev, B43_NTAB16(8, 0), 2);
  2870. b43_ntab_write(dev, B43_NTAB16(8, 16), 2);
  2871. if (b43_current_band(dev->wl) == NL80211_BAND_2GHZ)
  2872. pdet_range = sprom->fem.ghz2.pdet_range;
  2873. else
  2874. pdet_range = sprom->fem.ghz5.pdet_range;
  2875. vmid = vmids[min_t(u16, pdet_range, 4)];
  2876. gain = gains[min_t(u16, pdet_range, 4)];
  2877. switch (pdet_range) {
  2878. case 3:
  2879. if (!(dev->phy.rev >= 4 &&
  2880. b43_current_band(dev->wl) == NL80211_BAND_2GHZ))
  2881. break;
  2882. /* FALL THROUGH */
  2883. case 0:
  2884. case 1:
  2885. b43_ntab_write_bulk(dev, B43_NTAB16(8, 0x08), 4, vmid);
  2886. b43_ntab_write_bulk(dev, B43_NTAB16(8, 0x18), 4, vmid);
  2887. b43_ntab_write_bulk(dev, B43_NTAB16(8, 0x0c), 4, gain);
  2888. b43_ntab_write_bulk(dev, B43_NTAB16(8, 0x1c), 4, gain);
  2889. break;
  2890. case 2:
  2891. if (dev->phy.rev >= 6) {
  2892. if (b43_current_band(dev->wl) == NL80211_BAND_2GHZ)
  2893. vmid[3] = 0x94;
  2894. else
  2895. vmid[3] = 0x8e;
  2896. gain[3] = 3;
  2897. } else if (dev->phy.rev == 5) {
  2898. vmid[3] = 0x84;
  2899. gain[3] = 2;
  2900. }
  2901. b43_ntab_write_bulk(dev, B43_NTAB16(8, 0x08), 4, vmid);
  2902. b43_ntab_write_bulk(dev, B43_NTAB16(8, 0x18), 4, vmid);
  2903. b43_ntab_write_bulk(dev, B43_NTAB16(8, 0x0c), 4, gain);
  2904. b43_ntab_write_bulk(dev, B43_NTAB16(8, 0x1c), 4, gain);
  2905. break;
  2906. case 4:
  2907. case 5:
  2908. if (b43_current_band(dev->wl) != NL80211_BAND_2GHZ) {
  2909. if (pdet_range == 4) {
  2910. vmid[3] = 0x8e;
  2911. tmp16 = 0x96;
  2912. gain[3] = 0x2;
  2913. } else {
  2914. vmid[3] = 0x89;
  2915. tmp16 = 0x89;
  2916. gain[3] = 0;
  2917. }
  2918. } else {
  2919. if (pdet_range == 4) {
  2920. vmid[3] = 0x89;
  2921. tmp16 = 0x8b;
  2922. gain[3] = 0x2;
  2923. } else {
  2924. vmid[3] = 0x74;
  2925. tmp16 = 0x70;
  2926. gain[3] = 0;
  2927. }
  2928. }
  2929. b43_ntab_write_bulk(dev, B43_NTAB16(8, 0x08), 4, vmid);
  2930. b43_ntab_write_bulk(dev, B43_NTAB16(8, 0x0c), 4, gain);
  2931. vmid[3] = tmp16;
  2932. b43_ntab_write_bulk(dev, B43_NTAB16(8, 0x18), 4, vmid);
  2933. b43_ntab_write_bulk(dev, B43_NTAB16(8, 0x1c), 4, gain);
  2934. break;
  2935. }
  2936. b43_radio_write(dev, B2056_RX0 | B2056_RX_MIXA_MAST_BIAS, 0x00);
  2937. b43_radio_write(dev, B2056_RX1 | B2056_RX_MIXA_MAST_BIAS, 0x00);
  2938. b43_radio_write(dev, B2056_RX0 | B2056_RX_MIXA_BIAS_MAIN, 0x06);
  2939. b43_radio_write(dev, B2056_RX1 | B2056_RX_MIXA_BIAS_MAIN, 0x06);
  2940. b43_radio_write(dev, B2056_RX0 | B2056_RX_MIXA_BIAS_AUX, 0x07);
  2941. b43_radio_write(dev, B2056_RX1 | B2056_RX_MIXA_BIAS_AUX, 0x07);
  2942. b43_radio_write(dev, B2056_RX0 | B2056_RX_MIXA_LOB_BIAS, 0x88);
  2943. b43_radio_write(dev, B2056_RX1 | B2056_RX_MIXA_LOB_BIAS, 0x88);
  2944. b43_radio_write(dev, B2056_RX0 | B2056_RX_MIXA_CMFB_IDAC, 0x00);
  2945. b43_radio_write(dev, B2056_RX1 | B2056_RX_MIXA_CMFB_IDAC, 0x00);
  2946. b43_radio_write(dev, B2056_RX0 | B2056_RX_MIXG_CMFB_IDAC, 0x00);
  2947. b43_radio_write(dev, B2056_RX1 | B2056_RX_MIXG_CMFB_IDAC, 0x00);
  2948. /* N PHY WAR TX Chain Update with hw_phytxchain as argument */
  2949. if ((sprom->boardflags2_lo & B43_BFL2_APLL_WAR &&
  2950. b43_current_band(dev->wl) == NL80211_BAND_5GHZ) ||
  2951. (sprom->boardflags2_lo & B43_BFL2_GPLL_WAR &&
  2952. b43_current_band(dev->wl) == NL80211_BAND_2GHZ))
  2953. tmp32 = 0x00088888;
  2954. else
  2955. tmp32 = 0x88888888;
  2956. b43_ntab_write(dev, B43_NTAB32(30, 1), tmp32);
  2957. b43_ntab_write(dev, B43_NTAB32(30, 2), tmp32);
  2958. b43_ntab_write(dev, B43_NTAB32(30, 3), tmp32);
  2959. if (dev->phy.rev == 4 &&
  2960. b43_current_band(dev->wl) == NL80211_BAND_5GHZ) {
  2961. b43_radio_write(dev, B2056_TX0 | B2056_TX_GMBB_IDAC,
  2962. 0x70);
  2963. b43_radio_write(dev, B2056_TX1 | B2056_TX_GMBB_IDAC,
  2964. 0x70);
  2965. }
  2966. /* Dropped probably-always-true condition */
  2967. b43_phy_write(dev, B43_NPHY_ED_CRS40ASSERTTHRESH0, 0x03eb);
  2968. b43_phy_write(dev, B43_NPHY_ED_CRS40ASSERTTHRESH1, 0x03eb);
  2969. b43_phy_write(dev, B43_NPHY_ED_CRS40DEASSERTTHRESH0, 0x0341);
  2970. b43_phy_write(dev, B43_NPHY_ED_CRS40DEASSERTTHRESH1, 0x0341);
  2971. b43_phy_write(dev, B43_NPHY_ED_CRS20LASSERTTHRESH0, 0x042b);
  2972. b43_phy_write(dev, B43_NPHY_ED_CRS20LASSERTTHRESH1, 0x042b);
  2973. b43_phy_write(dev, B43_NPHY_ED_CRS20LDEASSERTTHRESH0, 0x0381);
  2974. b43_phy_write(dev, B43_NPHY_ED_CRS20LDEASSERTTHRESH1, 0x0381);
  2975. b43_phy_write(dev, B43_NPHY_ED_CRS20UASSERTTHRESH0, 0x042b);
  2976. b43_phy_write(dev, B43_NPHY_ED_CRS20UASSERTTHRESH1, 0x042b);
  2977. b43_phy_write(dev, B43_NPHY_ED_CRS20UDEASSERTTHRESH0, 0x0381);
  2978. b43_phy_write(dev, B43_NPHY_ED_CRS20UDEASSERTTHRESH1, 0x0381);
  2979. if (dev->phy.rev >= 6 && sprom->boardflags2_lo & B43_BFL2_SINGLEANT_CCK)
  2980. ; /* TODO: 0x0080000000000000 HF */
  2981. }
  2982. static void b43_nphy_workarounds_rev1_2(struct b43_wldev *dev)
  2983. {
  2984. struct ssb_sprom *sprom = dev->dev->bus_sprom;
  2985. struct b43_phy *phy = &dev->phy;
  2986. struct b43_phy_n *nphy = phy->n;
  2987. u8 events1[7] = { 0x0, 0x1, 0x2, 0x8, 0x4, 0x5, 0x3 };
  2988. u8 delays1[7] = { 0x8, 0x6, 0x6, 0x2, 0x4, 0x3C, 0x1 };
  2989. u8 events2[7] = { 0x0, 0x3, 0x5, 0x4, 0x2, 0x1, 0x8 };
  2990. u8 delays2[7] = { 0x8, 0x6, 0x2, 0x4, 0x4, 0x6, 0x1 };
  2991. if (sprom->boardflags2_lo & B43_BFL2_SKWRKFEM_BRD ||
  2992. dev->dev->board_type == BCMA_BOARD_TYPE_BCM943224M93) {
  2993. delays1[0] = 0x1;
  2994. delays1[5] = 0x14;
  2995. }
  2996. if (b43_current_band(dev->wl) == NL80211_BAND_5GHZ &&
  2997. nphy->band5g_pwrgain) {
  2998. b43_radio_mask(dev, B2055_C1_TX_RF_SPARE, ~0x8);
  2999. b43_radio_mask(dev, B2055_C2_TX_RF_SPARE, ~0x8);
  3000. } else {
  3001. b43_radio_set(dev, B2055_C1_TX_RF_SPARE, 0x8);
  3002. b43_radio_set(dev, B2055_C2_TX_RF_SPARE, 0x8);
  3003. }
  3004. b43_ntab_write(dev, B43_NTAB16(8, 0x00), 0x000A);
  3005. b43_ntab_write(dev, B43_NTAB16(8, 0x10), 0x000A);
  3006. if (dev->phy.rev < 3) {
  3007. b43_ntab_write(dev, B43_NTAB16(8, 0x02), 0xCDAA);
  3008. b43_ntab_write(dev, B43_NTAB16(8, 0x12), 0xCDAA);
  3009. }
  3010. if (dev->phy.rev < 2) {
  3011. b43_ntab_write(dev, B43_NTAB16(8, 0x08), 0x0000);
  3012. b43_ntab_write(dev, B43_NTAB16(8, 0x18), 0x0000);
  3013. b43_ntab_write(dev, B43_NTAB16(8, 0x07), 0x7AAB);
  3014. b43_ntab_write(dev, B43_NTAB16(8, 0x17), 0x7AAB);
  3015. b43_ntab_write(dev, B43_NTAB16(8, 0x06), 0x0800);
  3016. b43_ntab_write(dev, B43_NTAB16(8, 0x16), 0x0800);
  3017. }
  3018. b43_phy_write(dev, B43_NPHY_RFCTL_LUT_TRSW_LO1, 0x2D8);
  3019. b43_phy_write(dev, B43_NPHY_RFCTL_LUT_TRSW_UP1, 0x301);
  3020. b43_phy_write(dev, B43_NPHY_RFCTL_LUT_TRSW_LO2, 0x2D8);
  3021. b43_phy_write(dev, B43_NPHY_RFCTL_LUT_TRSW_UP2, 0x301);
  3022. b43_nphy_set_rf_sequence(dev, 0, events1, delays1, 7);
  3023. b43_nphy_set_rf_sequence(dev, 1, events2, delays2, 7);
  3024. b43_nphy_gain_ctl_workarounds(dev);
  3025. if (dev->phy.rev < 2) {
  3026. if (b43_phy_read(dev, B43_NPHY_RXCTL) & 0x2)
  3027. b43_hf_write(dev, b43_hf_read(dev) |
  3028. B43_HF_MLADVW);
  3029. } else if (dev->phy.rev == 2) {
  3030. b43_phy_write(dev, B43_NPHY_CRSCHECK2, 0);
  3031. b43_phy_write(dev, B43_NPHY_CRSCHECK3, 0);
  3032. }
  3033. if (dev->phy.rev < 2)
  3034. b43_phy_mask(dev, B43_NPHY_SCRAM_SIGCTL,
  3035. ~B43_NPHY_SCRAM_SIGCTL_SCM);
  3036. /* Set phase track alpha and beta */
  3037. b43_phy_write(dev, B43_NPHY_PHASETR_A0, 0x125);
  3038. b43_phy_write(dev, B43_NPHY_PHASETR_A1, 0x1B3);
  3039. b43_phy_write(dev, B43_NPHY_PHASETR_A2, 0x105);
  3040. b43_phy_write(dev, B43_NPHY_PHASETR_B0, 0x16E);
  3041. b43_phy_write(dev, B43_NPHY_PHASETR_B1, 0xCD);
  3042. b43_phy_write(dev, B43_NPHY_PHASETR_B2, 0x20);
  3043. if (dev->phy.rev < 3) {
  3044. b43_phy_mask(dev, B43_NPHY_PIL_DW1,
  3045. ~B43_NPHY_PIL_DW_64QAM & 0xFFFF);
  3046. b43_phy_write(dev, B43_NPHY_TXF_20CO_S2B1, 0xB5);
  3047. b43_phy_write(dev, B43_NPHY_TXF_20CO_S2B2, 0xA4);
  3048. b43_phy_write(dev, B43_NPHY_TXF_20CO_S2B3, 0x00);
  3049. }
  3050. if (dev->phy.rev == 2)
  3051. b43_phy_set(dev, B43_NPHY_FINERX2_CGC,
  3052. B43_NPHY_FINERX2_CGC_DECGC);
  3053. }
  3054. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/Workarounds */
  3055. static void b43_nphy_workarounds(struct b43_wldev *dev)
  3056. {
  3057. struct b43_phy *phy = &dev->phy;
  3058. struct b43_phy_n *nphy = phy->n;
  3059. if (b43_current_band(dev->wl) == NL80211_BAND_5GHZ)
  3060. b43_nphy_classifier(dev, 1, 0);
  3061. else
  3062. b43_nphy_classifier(dev, 1, 1);
  3063. if (nphy->hang_avoid)
  3064. b43_nphy_stay_in_carrier_search(dev, 1);
  3065. b43_phy_set(dev, B43_NPHY_IQFLIP,
  3066. B43_NPHY_IQFLIP_ADC1 | B43_NPHY_IQFLIP_ADC2);
  3067. /* TODO: rev19+ */
  3068. if (dev->phy.rev >= 7)
  3069. b43_nphy_workarounds_rev7plus(dev);
  3070. else if (dev->phy.rev >= 3)
  3071. b43_nphy_workarounds_rev3plus(dev);
  3072. else
  3073. b43_nphy_workarounds_rev1_2(dev);
  3074. if (nphy->hang_avoid)
  3075. b43_nphy_stay_in_carrier_search(dev, 0);
  3076. }
  3077. /**************************************************
  3078. * Tx/Rx common
  3079. **************************************************/
  3080. /*
  3081. * Transmits a known value for LO calibration
  3082. * http://bcm-v4.sipsolutions.net/802.11/PHY/N/TXTone
  3083. */
  3084. static int b43_nphy_tx_tone(struct b43_wldev *dev, u32 freq, u16 max_val,
  3085. bool iqmode, bool dac_test, bool modify_bbmult)
  3086. {
  3087. u16 samp = b43_nphy_gen_load_samples(dev, freq, max_val, dac_test);
  3088. if (samp == 0)
  3089. return -1;
  3090. b43_nphy_run_samples(dev, samp, 0xFFFF, 0, iqmode, dac_test,
  3091. modify_bbmult);
  3092. return 0;
  3093. }
  3094. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/Chains */
  3095. static void b43_nphy_update_txrx_chain(struct b43_wldev *dev)
  3096. {
  3097. struct b43_phy_n *nphy = dev->phy.n;
  3098. bool override = false;
  3099. u16 chain = 0x33;
  3100. if (nphy->txrx_chain == 0) {
  3101. chain = 0x11;
  3102. override = true;
  3103. } else if (nphy->txrx_chain == 1) {
  3104. chain = 0x22;
  3105. override = true;
  3106. }
  3107. b43_phy_maskset(dev, B43_NPHY_RFSEQCA,
  3108. ~(B43_NPHY_RFSEQCA_TXEN | B43_NPHY_RFSEQCA_RXEN),
  3109. chain);
  3110. if (override)
  3111. b43_phy_set(dev, B43_NPHY_RFSEQMODE,
  3112. B43_NPHY_RFSEQMODE_CAOVER);
  3113. else
  3114. b43_phy_mask(dev, B43_NPHY_RFSEQMODE,
  3115. ~B43_NPHY_RFSEQMODE_CAOVER);
  3116. }
  3117. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/stop-playback */
  3118. static void b43_nphy_stop_playback(struct b43_wldev *dev)
  3119. {
  3120. struct b43_phy *phy = &dev->phy;
  3121. struct b43_phy_n *nphy = dev->phy.n;
  3122. u16 tmp;
  3123. if (nphy->hang_avoid)
  3124. b43_nphy_stay_in_carrier_search(dev, 1);
  3125. tmp = b43_phy_read(dev, B43_NPHY_SAMP_STAT);
  3126. if (tmp & 0x1)
  3127. b43_phy_set(dev, B43_NPHY_SAMP_CMD, B43_NPHY_SAMP_CMD_STOP);
  3128. else if (tmp & 0x2)
  3129. b43_phy_mask(dev, B43_NPHY_IQLOCAL_CMDGCTL, 0x7FFF);
  3130. b43_phy_mask(dev, B43_NPHY_SAMP_CMD, ~0x0004);
  3131. if (nphy->bb_mult_save & 0x80000000) {
  3132. tmp = nphy->bb_mult_save & 0xFFFF;
  3133. b43_ntab_write(dev, B43_NTAB16(15, 87), tmp);
  3134. nphy->bb_mult_save = 0;
  3135. }
  3136. if (phy->rev >= 7 && nphy->lpf_bw_overrode_for_sample_play) {
  3137. if (phy->rev >= 19)
  3138. b43_nphy_rf_ctl_override_rev19(dev, 0x80, 0, 0, true,
  3139. 1);
  3140. else
  3141. b43_nphy_rf_ctl_override_rev7(dev, 0x80, 0, 0, true, 1);
  3142. nphy->lpf_bw_overrode_for_sample_play = false;
  3143. }
  3144. if (nphy->hang_avoid)
  3145. b43_nphy_stay_in_carrier_search(dev, 0);
  3146. }
  3147. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/IqCalGainParams */
  3148. static void b43_nphy_iq_cal_gain_params(struct b43_wldev *dev, u16 core,
  3149. struct nphy_txgains target,
  3150. struct nphy_iqcal_params *params)
  3151. {
  3152. struct b43_phy *phy = &dev->phy;
  3153. int i, j, indx;
  3154. u16 gain;
  3155. if (dev->phy.rev >= 3) {
  3156. params->tx_lpf = target.tx_lpf[core]; /* Rev 7+ */
  3157. params->txgm = target.txgm[core];
  3158. params->pga = target.pga[core];
  3159. params->pad = target.pad[core];
  3160. params->ipa = target.ipa[core];
  3161. if (phy->rev >= 19) {
  3162. /* TODO */
  3163. } else if (phy->rev >= 7) {
  3164. params->cal_gain = (params->txgm << 12) | (params->pga << 8) | (params->pad << 3) | (params->ipa) | (params->tx_lpf << 15);
  3165. } else {
  3166. params->cal_gain = (params->txgm << 12) | (params->pga << 8) | (params->pad << 4) | (params->ipa);
  3167. }
  3168. for (j = 0; j < 5; j++)
  3169. params->ncorr[j] = 0x79;
  3170. } else {
  3171. gain = (target.pad[core]) | (target.pga[core] << 4) |
  3172. (target.txgm[core] << 8);
  3173. indx = (b43_current_band(dev->wl) == NL80211_BAND_5GHZ) ?
  3174. 1 : 0;
  3175. for (i = 0; i < 9; i++)
  3176. if (tbl_iqcal_gainparams[indx][i][0] == gain)
  3177. break;
  3178. i = min(i, 8);
  3179. params->txgm = tbl_iqcal_gainparams[indx][i][1];
  3180. params->pga = tbl_iqcal_gainparams[indx][i][2];
  3181. params->pad = tbl_iqcal_gainparams[indx][i][3];
  3182. params->cal_gain = (params->txgm << 7) | (params->pga << 4) |
  3183. (params->pad << 2);
  3184. for (j = 0; j < 4; j++)
  3185. params->ncorr[j] = tbl_iqcal_gainparams[indx][i][4 + j];
  3186. }
  3187. }
  3188. /**************************************************
  3189. * Tx and Rx
  3190. **************************************************/
  3191. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/TxPwrCtrlEnable */
  3192. static void b43_nphy_tx_power_ctrl(struct b43_wldev *dev, bool enable)
  3193. {
  3194. struct b43_phy *phy = &dev->phy;
  3195. struct b43_phy_n *nphy = dev->phy.n;
  3196. u8 i;
  3197. u16 bmask, val, tmp;
  3198. enum nl80211_band band = b43_current_band(dev->wl);
  3199. if (nphy->hang_avoid)
  3200. b43_nphy_stay_in_carrier_search(dev, 1);
  3201. nphy->txpwrctrl = enable;
  3202. if (!enable) {
  3203. if (dev->phy.rev >= 3 &&
  3204. (b43_phy_read(dev, B43_NPHY_TXPCTL_CMD) &
  3205. (B43_NPHY_TXPCTL_CMD_COEFF |
  3206. B43_NPHY_TXPCTL_CMD_HWPCTLEN |
  3207. B43_NPHY_TXPCTL_CMD_PCTLEN))) {
  3208. /* We disable enabled TX pwr ctl, save it's state */
  3209. nphy->tx_pwr_idx[0] = b43_phy_read(dev,
  3210. B43_NPHY_C1_TXPCTL_STAT) & 0x7f;
  3211. nphy->tx_pwr_idx[1] = b43_phy_read(dev,
  3212. B43_NPHY_C2_TXPCTL_STAT) & 0x7f;
  3213. }
  3214. b43_phy_write(dev, B43_NPHY_TABLE_ADDR, 0x6840);
  3215. for (i = 0; i < 84; i++)
  3216. b43_phy_write(dev, B43_NPHY_TABLE_DATALO, 0);
  3217. b43_phy_write(dev, B43_NPHY_TABLE_ADDR, 0x6C40);
  3218. for (i = 0; i < 84; i++)
  3219. b43_phy_write(dev, B43_NPHY_TABLE_DATALO, 0);
  3220. tmp = B43_NPHY_TXPCTL_CMD_COEFF | B43_NPHY_TXPCTL_CMD_HWPCTLEN;
  3221. if (dev->phy.rev >= 3)
  3222. tmp |= B43_NPHY_TXPCTL_CMD_PCTLEN;
  3223. b43_phy_mask(dev, B43_NPHY_TXPCTL_CMD, ~tmp);
  3224. if (dev->phy.rev >= 3) {
  3225. b43_phy_set(dev, B43_NPHY_AFECTL_OVER1, 0x0100);
  3226. b43_phy_set(dev, B43_NPHY_AFECTL_OVER, 0x0100);
  3227. } else {
  3228. b43_phy_set(dev, B43_NPHY_AFECTL_OVER, 0x4000);
  3229. }
  3230. if (dev->phy.rev == 2)
  3231. b43_phy_maskset(dev, B43_NPHY_BPHY_CTL3,
  3232. ~B43_NPHY_BPHY_CTL3_SCALE, 0x53);
  3233. else if (dev->phy.rev < 2)
  3234. b43_phy_maskset(dev, B43_NPHY_BPHY_CTL3,
  3235. ~B43_NPHY_BPHY_CTL3_SCALE, 0x5A);
  3236. if (dev->phy.rev < 2 && b43_is_40mhz(dev))
  3237. b43_hf_write(dev, b43_hf_read(dev) | B43_HF_TSSIRPSMW);
  3238. } else {
  3239. b43_ntab_write_bulk(dev, B43_NTAB16(26, 64), 84,
  3240. nphy->adj_pwr_tbl);
  3241. b43_ntab_write_bulk(dev, B43_NTAB16(27, 64), 84,
  3242. nphy->adj_pwr_tbl);
  3243. bmask = B43_NPHY_TXPCTL_CMD_COEFF |
  3244. B43_NPHY_TXPCTL_CMD_HWPCTLEN;
  3245. /* wl does useless check for "enable" param here */
  3246. val = B43_NPHY_TXPCTL_CMD_COEFF | B43_NPHY_TXPCTL_CMD_HWPCTLEN;
  3247. if (dev->phy.rev >= 3) {
  3248. bmask |= B43_NPHY_TXPCTL_CMD_PCTLEN;
  3249. if (val)
  3250. val |= B43_NPHY_TXPCTL_CMD_PCTLEN;
  3251. }
  3252. b43_phy_maskset(dev, B43_NPHY_TXPCTL_CMD, ~(bmask), val);
  3253. if (band == NL80211_BAND_5GHZ) {
  3254. if (phy->rev >= 19) {
  3255. /* TODO */
  3256. } else if (phy->rev >= 7) {
  3257. b43_phy_maskset(dev, B43_NPHY_TXPCTL_CMD,
  3258. ~B43_NPHY_TXPCTL_CMD_INIT,
  3259. 0x32);
  3260. b43_phy_maskset(dev, B43_NPHY_TXPCTL_INIT,
  3261. ~B43_NPHY_TXPCTL_INIT_PIDXI1,
  3262. 0x32);
  3263. } else {
  3264. b43_phy_maskset(dev, B43_NPHY_TXPCTL_CMD,
  3265. ~B43_NPHY_TXPCTL_CMD_INIT,
  3266. 0x64);
  3267. if (phy->rev > 1)
  3268. b43_phy_maskset(dev,
  3269. B43_NPHY_TXPCTL_INIT,
  3270. ~B43_NPHY_TXPCTL_INIT_PIDXI1,
  3271. 0x64);
  3272. }
  3273. }
  3274. if (dev->phy.rev >= 3) {
  3275. if (nphy->tx_pwr_idx[0] != 128 &&
  3276. nphy->tx_pwr_idx[1] != 128) {
  3277. /* Recover TX pwr ctl state */
  3278. b43_phy_maskset(dev, B43_NPHY_TXPCTL_CMD,
  3279. ~B43_NPHY_TXPCTL_CMD_INIT,
  3280. nphy->tx_pwr_idx[0]);
  3281. if (dev->phy.rev > 1)
  3282. b43_phy_maskset(dev,
  3283. B43_NPHY_TXPCTL_INIT,
  3284. ~0xff, nphy->tx_pwr_idx[1]);
  3285. }
  3286. }
  3287. if (phy->rev >= 7) {
  3288. /* TODO */
  3289. }
  3290. if (dev->phy.rev >= 3) {
  3291. b43_phy_mask(dev, B43_NPHY_AFECTL_OVER1, ~0x100);
  3292. b43_phy_mask(dev, B43_NPHY_AFECTL_OVER, ~0x100);
  3293. } else {
  3294. b43_phy_mask(dev, B43_NPHY_AFECTL_OVER, ~0x4000);
  3295. }
  3296. if (dev->phy.rev == 2)
  3297. b43_phy_maskset(dev, B43_NPHY_BPHY_CTL3, ~0xFF, 0x3b);
  3298. else if (dev->phy.rev < 2)
  3299. b43_phy_maskset(dev, B43_NPHY_BPHY_CTL3, ~0xFF, 0x40);
  3300. if (dev->phy.rev < 2 && b43_is_40mhz(dev))
  3301. b43_hf_write(dev, b43_hf_read(dev) & ~B43_HF_TSSIRPSMW);
  3302. if (b43_nphy_ipa(dev)) {
  3303. b43_phy_mask(dev, B43_NPHY_PAPD_EN0, ~0x4);
  3304. b43_phy_mask(dev, B43_NPHY_PAPD_EN1, ~0x4);
  3305. }
  3306. }
  3307. if (nphy->hang_avoid)
  3308. b43_nphy_stay_in_carrier_search(dev, 0);
  3309. }
  3310. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/TxPwrFix */
  3311. static void b43_nphy_tx_power_fix(struct b43_wldev *dev)
  3312. {
  3313. struct b43_phy *phy = &dev->phy;
  3314. struct b43_phy_n *nphy = dev->phy.n;
  3315. struct ssb_sprom *sprom = dev->dev->bus_sprom;
  3316. u8 txpi[2], bbmult, i;
  3317. u16 tmp, radio_gain, dac_gain;
  3318. u16 freq = phy->chandef->chan->center_freq;
  3319. u32 txgain;
  3320. /* u32 gaintbl; rev3+ */
  3321. if (nphy->hang_avoid)
  3322. b43_nphy_stay_in_carrier_search(dev, 1);
  3323. /* TODO: rev19+ */
  3324. if (dev->phy.rev >= 7) {
  3325. txpi[0] = txpi[1] = 30;
  3326. } else if (dev->phy.rev >= 3) {
  3327. txpi[0] = 40;
  3328. txpi[1] = 40;
  3329. } else if (sprom->revision < 4) {
  3330. txpi[0] = 72;
  3331. txpi[1] = 72;
  3332. } else {
  3333. if (b43_current_band(dev->wl) == NL80211_BAND_2GHZ) {
  3334. txpi[0] = sprom->txpid2g[0];
  3335. txpi[1] = sprom->txpid2g[1];
  3336. } else if (freq >= 4900 && freq < 5100) {
  3337. txpi[0] = sprom->txpid5gl[0];
  3338. txpi[1] = sprom->txpid5gl[1];
  3339. } else if (freq >= 5100 && freq < 5500) {
  3340. txpi[0] = sprom->txpid5g[0];
  3341. txpi[1] = sprom->txpid5g[1];
  3342. } else if (freq >= 5500) {
  3343. txpi[0] = sprom->txpid5gh[0];
  3344. txpi[1] = sprom->txpid5gh[1];
  3345. } else {
  3346. txpi[0] = 91;
  3347. txpi[1] = 91;
  3348. }
  3349. }
  3350. if (dev->phy.rev < 7 &&
  3351. (txpi[0] < 40 || txpi[0] > 100 || txpi[1] < 40 || txpi[1] > 100))
  3352. txpi[0] = txpi[1] = 91;
  3353. /*
  3354. for (i = 0; i < 2; i++) {
  3355. nphy->txpwrindex[i].index_internal = txpi[i];
  3356. nphy->txpwrindex[i].index_internal_save = txpi[i];
  3357. }
  3358. */
  3359. for (i = 0; i < 2; i++) {
  3360. const u32 *table = b43_nphy_get_tx_gain_table(dev);
  3361. if (!table)
  3362. break;
  3363. txgain = *(table + txpi[i]);
  3364. if (dev->phy.rev >= 3)
  3365. radio_gain = (txgain >> 16) & 0x1FFFF;
  3366. else
  3367. radio_gain = (txgain >> 16) & 0x1FFF;
  3368. if (dev->phy.rev >= 7)
  3369. dac_gain = (txgain >> 8) & 0x7;
  3370. else
  3371. dac_gain = (txgain >> 8) & 0x3F;
  3372. bbmult = txgain & 0xFF;
  3373. if (dev->phy.rev >= 3) {
  3374. if (i == 0)
  3375. b43_phy_set(dev, B43_NPHY_AFECTL_OVER1, 0x0100);
  3376. else
  3377. b43_phy_set(dev, B43_NPHY_AFECTL_OVER, 0x0100);
  3378. } else {
  3379. b43_phy_set(dev, B43_NPHY_AFECTL_OVER, 0x4000);
  3380. }
  3381. if (i == 0)
  3382. b43_phy_write(dev, B43_NPHY_AFECTL_DACGAIN1, dac_gain);
  3383. else
  3384. b43_phy_write(dev, B43_NPHY_AFECTL_DACGAIN2, dac_gain);
  3385. b43_ntab_write(dev, B43_NTAB16(0x7, 0x110 + i), radio_gain);
  3386. tmp = b43_ntab_read(dev, B43_NTAB16(0xF, 0x57));
  3387. if (i == 0)
  3388. tmp = (tmp & 0x00FF) | (bbmult << 8);
  3389. else
  3390. tmp = (tmp & 0xFF00) | bbmult;
  3391. b43_ntab_write(dev, B43_NTAB16(0xF, 0x57), tmp);
  3392. if (b43_nphy_ipa(dev)) {
  3393. u32 tmp32;
  3394. u16 reg = (i == 0) ?
  3395. B43_NPHY_PAPD_EN0 : B43_NPHY_PAPD_EN1;
  3396. tmp32 = b43_ntab_read(dev, B43_NTAB32(26 + i,
  3397. 576 + txpi[i]));
  3398. b43_phy_maskset(dev, reg, 0xE00F, (u32) tmp32 << 4);
  3399. b43_phy_set(dev, reg, 0x4);
  3400. }
  3401. }
  3402. b43_phy_mask(dev, B43_NPHY_BPHY_CTL2, ~B43_NPHY_BPHY_CTL2_LUT);
  3403. if (nphy->hang_avoid)
  3404. b43_nphy_stay_in_carrier_search(dev, 0);
  3405. }
  3406. static void b43_nphy_ipa_internal_tssi_setup(struct b43_wldev *dev)
  3407. {
  3408. struct b43_phy *phy = &dev->phy;
  3409. u8 core;
  3410. u16 r; /* routing */
  3411. if (phy->rev >= 19) {
  3412. /* TODO */
  3413. } else if (phy->rev >= 7) {
  3414. for (core = 0; core < 2; core++) {
  3415. r = core ? 0x190 : 0x170;
  3416. if (b43_current_band(dev->wl) == NL80211_BAND_2GHZ) {
  3417. b43_radio_write(dev, r + 0x5, 0x5);
  3418. b43_radio_write(dev, r + 0x9, 0xE);
  3419. if (phy->rev != 5)
  3420. b43_radio_write(dev, r + 0xA, 0);
  3421. if (phy->rev != 7)
  3422. b43_radio_write(dev, r + 0xB, 1);
  3423. else
  3424. b43_radio_write(dev, r + 0xB, 0x31);
  3425. } else {
  3426. b43_radio_write(dev, r + 0x5, 0x9);
  3427. b43_radio_write(dev, r + 0x9, 0xC);
  3428. b43_radio_write(dev, r + 0xB, 0x0);
  3429. if (phy->rev != 5)
  3430. b43_radio_write(dev, r + 0xA, 1);
  3431. else
  3432. b43_radio_write(dev, r + 0xA, 0x31);
  3433. }
  3434. b43_radio_write(dev, r + 0x6, 0);
  3435. b43_radio_write(dev, r + 0x7, 0);
  3436. b43_radio_write(dev, r + 0x8, 3);
  3437. b43_radio_write(dev, r + 0xC, 0);
  3438. }
  3439. } else {
  3440. if (b43_current_band(dev->wl) == NL80211_BAND_2GHZ)
  3441. b43_radio_write(dev, B2056_SYN_RESERVED_ADDR31, 0x128);
  3442. else
  3443. b43_radio_write(dev, B2056_SYN_RESERVED_ADDR31, 0x80);
  3444. b43_radio_write(dev, B2056_SYN_RESERVED_ADDR30, 0);
  3445. b43_radio_write(dev, B2056_SYN_GPIO_MASTER1, 0x29);
  3446. for (core = 0; core < 2; core++) {
  3447. r = core ? B2056_TX1 : B2056_TX0;
  3448. b43_radio_write(dev, r | B2056_TX_IQCAL_VCM_HG, 0);
  3449. b43_radio_write(dev, r | B2056_TX_IQCAL_IDAC, 0);
  3450. b43_radio_write(dev, r | B2056_TX_TSSI_VCM, 3);
  3451. b43_radio_write(dev, r | B2056_TX_TX_AMP_DET, 0);
  3452. b43_radio_write(dev, r | B2056_TX_TSSI_MISC1, 8);
  3453. b43_radio_write(dev, r | B2056_TX_TSSI_MISC2, 0);
  3454. b43_radio_write(dev, r | B2056_TX_TSSI_MISC3, 0);
  3455. if (b43_current_band(dev->wl) == NL80211_BAND_2GHZ) {
  3456. b43_radio_write(dev, r | B2056_TX_TX_SSI_MASTER,
  3457. 0x5);
  3458. if (phy->rev != 5)
  3459. b43_radio_write(dev, r | B2056_TX_TSSIA,
  3460. 0x00);
  3461. if (phy->rev >= 5)
  3462. b43_radio_write(dev, r | B2056_TX_TSSIG,
  3463. 0x31);
  3464. else
  3465. b43_radio_write(dev, r | B2056_TX_TSSIG,
  3466. 0x11);
  3467. b43_radio_write(dev, r | B2056_TX_TX_SSI_MUX,
  3468. 0xE);
  3469. } else {
  3470. b43_radio_write(dev, r | B2056_TX_TX_SSI_MASTER,
  3471. 0x9);
  3472. b43_radio_write(dev, r | B2056_TX_TSSIA, 0x31);
  3473. b43_radio_write(dev, r | B2056_TX_TSSIG, 0x0);
  3474. b43_radio_write(dev, r | B2056_TX_TX_SSI_MUX,
  3475. 0xC);
  3476. }
  3477. }
  3478. }
  3479. }
  3480. /*
  3481. * Stop radio and transmit known signal. Then check received signal strength to
  3482. * get TSSI (Transmit Signal Strength Indicator).
  3483. * http://bcm-v4.sipsolutions.net/802.11/PHY/N/TxPwrCtrlIdleTssi
  3484. */
  3485. static void b43_nphy_tx_power_ctl_idle_tssi(struct b43_wldev *dev)
  3486. {
  3487. struct b43_phy *phy = &dev->phy;
  3488. struct b43_phy_n *nphy = dev->phy.n;
  3489. u32 tmp;
  3490. s32 rssi[4] = { };
  3491. if (phy->chandef->chan->flags & IEEE80211_CHAN_NO_IR)
  3492. return;
  3493. if (b43_nphy_ipa(dev))
  3494. b43_nphy_ipa_internal_tssi_setup(dev);
  3495. if (phy->rev >= 19)
  3496. b43_nphy_rf_ctl_override_rev19(dev, 0x1000, 0, 3, false, 0);
  3497. else if (phy->rev >= 7)
  3498. b43_nphy_rf_ctl_override_rev7(dev, 0x1000, 0, 3, false, 0);
  3499. else if (phy->rev >= 3)
  3500. b43_nphy_rf_ctl_override(dev, 0x2000, 0, 3, false);
  3501. b43_nphy_stop_playback(dev);
  3502. b43_nphy_tx_tone(dev, 4000, 0, false, false, false);
  3503. udelay(20);
  3504. tmp = b43_nphy_poll_rssi(dev, N_RSSI_TSSI_2G, rssi, 1);
  3505. b43_nphy_stop_playback(dev);
  3506. b43_nphy_rssi_select(dev, 0, N_RSSI_W1);
  3507. if (phy->rev >= 19)
  3508. b43_nphy_rf_ctl_override_rev19(dev, 0x1000, 0, 3, true, 0);
  3509. else if (phy->rev >= 7)
  3510. b43_nphy_rf_ctl_override_rev7(dev, 0x1000, 0, 3, true, 0);
  3511. else if (phy->rev >= 3)
  3512. b43_nphy_rf_ctl_override(dev, 0x2000, 0, 3, true);
  3513. if (phy->rev >= 19) {
  3514. /* TODO */
  3515. return;
  3516. } else if (phy->rev >= 3) {
  3517. nphy->pwr_ctl_info[0].idle_tssi_5g = (tmp >> 24) & 0xFF;
  3518. nphy->pwr_ctl_info[1].idle_tssi_5g = (tmp >> 8) & 0xFF;
  3519. } else {
  3520. nphy->pwr_ctl_info[0].idle_tssi_5g = (tmp >> 16) & 0xFF;
  3521. nphy->pwr_ctl_info[1].idle_tssi_5g = tmp & 0xFF;
  3522. }
  3523. nphy->pwr_ctl_info[0].idle_tssi_2g = (tmp >> 24) & 0xFF;
  3524. nphy->pwr_ctl_info[1].idle_tssi_2g = (tmp >> 8) & 0xFF;
  3525. }
  3526. /* http://bcm-v4.sipsolutions.net/PHY/N/TxPwrLimitToTbl */
  3527. static void b43_nphy_tx_prepare_adjusted_power_table(struct b43_wldev *dev)
  3528. {
  3529. struct b43_phy_n *nphy = dev->phy.n;
  3530. u8 idx, delta;
  3531. u8 i, stf_mode;
  3532. /* Array adj_pwr_tbl corresponds to the hardware table. It consists of
  3533. * 21 groups, each containing 4 entries.
  3534. *
  3535. * First group has entries for CCK modulation.
  3536. * The rest of groups has 1 entry per modulation (SISO, CDD, STBC, SDM).
  3537. *
  3538. * Group 0 is for CCK
  3539. * Groups 1..4 use BPSK (group per coding rate)
  3540. * Groups 5..8 use QPSK (group per coding rate)
  3541. * Groups 9..12 use 16-QAM (group per coding rate)
  3542. * Groups 13..16 use 64-QAM (group per coding rate)
  3543. * Groups 17..20 are unknown
  3544. */
  3545. for (i = 0; i < 4; i++)
  3546. nphy->adj_pwr_tbl[i] = nphy->tx_power_offset[i];
  3547. for (stf_mode = 0; stf_mode < 4; stf_mode++) {
  3548. delta = 0;
  3549. switch (stf_mode) {
  3550. case 0:
  3551. if (b43_is_40mhz(dev) && dev->phy.rev >= 5) {
  3552. idx = 68;
  3553. } else {
  3554. delta = 1;
  3555. idx = b43_is_40mhz(dev) ? 52 : 4;
  3556. }
  3557. break;
  3558. case 1:
  3559. idx = b43_is_40mhz(dev) ? 76 : 28;
  3560. break;
  3561. case 2:
  3562. idx = b43_is_40mhz(dev) ? 84 : 36;
  3563. break;
  3564. case 3:
  3565. idx = b43_is_40mhz(dev) ? 92 : 44;
  3566. break;
  3567. }
  3568. for (i = 0; i < 20; i++) {
  3569. nphy->adj_pwr_tbl[4 + 4 * i + stf_mode] =
  3570. nphy->tx_power_offset[idx];
  3571. if (i == 0)
  3572. idx += delta;
  3573. if (i == 14)
  3574. idx += 1 - delta;
  3575. if (i == 3 || i == 4 || i == 7 || i == 8 || i == 11 ||
  3576. i == 13)
  3577. idx += 1;
  3578. }
  3579. }
  3580. }
  3581. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/TxPwrCtrlSetup */
  3582. static void b43_nphy_tx_power_ctl_setup(struct b43_wldev *dev)
  3583. {
  3584. struct b43_phy *phy = &dev->phy;
  3585. struct b43_phy_n *nphy = dev->phy.n;
  3586. struct ssb_sprom *sprom = dev->dev->bus_sprom;
  3587. s16 a1[2], b0[2], b1[2];
  3588. u8 idle[2];
  3589. u8 ppr_max;
  3590. s8 target[2];
  3591. s32 num, den, pwr;
  3592. u32 regval[64];
  3593. u16 freq = phy->chandef->chan->center_freq;
  3594. u16 tmp;
  3595. u16 r; /* routing */
  3596. u8 i, c;
  3597. if (dev->dev->core_rev == 11 || dev->dev->core_rev == 12) {
  3598. b43_maskset32(dev, B43_MMIO_MACCTL, ~0, 0x200000);
  3599. b43_read32(dev, B43_MMIO_MACCTL);
  3600. udelay(1);
  3601. }
  3602. if (nphy->hang_avoid)
  3603. b43_nphy_stay_in_carrier_search(dev, true);
  3604. b43_phy_set(dev, B43_NPHY_TSSIMODE, B43_NPHY_TSSIMODE_EN);
  3605. if (dev->phy.rev >= 3)
  3606. b43_phy_mask(dev, B43_NPHY_TXPCTL_CMD,
  3607. ~B43_NPHY_TXPCTL_CMD_PCTLEN & 0xFFFF);
  3608. else
  3609. b43_phy_set(dev, B43_NPHY_TXPCTL_CMD,
  3610. B43_NPHY_TXPCTL_CMD_PCTLEN);
  3611. if (dev->dev->core_rev == 11 || dev->dev->core_rev == 12)
  3612. b43_maskset32(dev, B43_MMIO_MACCTL, ~0x200000, 0);
  3613. if (sprom->revision < 4) {
  3614. idle[0] = nphy->pwr_ctl_info[0].idle_tssi_2g;
  3615. idle[1] = nphy->pwr_ctl_info[1].idle_tssi_2g;
  3616. target[0] = target[1] = 52;
  3617. a1[0] = a1[1] = -424;
  3618. b0[0] = b0[1] = 5612;
  3619. b1[0] = b1[1] = -1393;
  3620. } else {
  3621. if (b43_current_band(dev->wl) == NL80211_BAND_2GHZ) {
  3622. for (c = 0; c < 2; c++) {
  3623. idle[c] = nphy->pwr_ctl_info[c].idle_tssi_2g;
  3624. target[c] = sprom->core_pwr_info[c].maxpwr_2g;
  3625. a1[c] = sprom->core_pwr_info[c].pa_2g[0];
  3626. b0[c] = sprom->core_pwr_info[c].pa_2g[1];
  3627. b1[c] = sprom->core_pwr_info[c].pa_2g[2];
  3628. }
  3629. } else if (freq >= 4900 && freq < 5100) {
  3630. for (c = 0; c < 2; c++) {
  3631. idle[c] = nphy->pwr_ctl_info[c].idle_tssi_5g;
  3632. target[c] = sprom->core_pwr_info[c].maxpwr_5gl;
  3633. a1[c] = sprom->core_pwr_info[c].pa_5gl[0];
  3634. b0[c] = sprom->core_pwr_info[c].pa_5gl[1];
  3635. b1[c] = sprom->core_pwr_info[c].pa_5gl[2];
  3636. }
  3637. } else if (freq >= 5100 && freq < 5500) {
  3638. for (c = 0; c < 2; c++) {
  3639. idle[c] = nphy->pwr_ctl_info[c].idle_tssi_5g;
  3640. target[c] = sprom->core_pwr_info[c].maxpwr_5g;
  3641. a1[c] = sprom->core_pwr_info[c].pa_5g[0];
  3642. b0[c] = sprom->core_pwr_info[c].pa_5g[1];
  3643. b1[c] = sprom->core_pwr_info[c].pa_5g[2];
  3644. }
  3645. } else if (freq >= 5500) {
  3646. for (c = 0; c < 2; c++) {
  3647. idle[c] = nphy->pwr_ctl_info[c].idle_tssi_5g;
  3648. target[c] = sprom->core_pwr_info[c].maxpwr_5gh;
  3649. a1[c] = sprom->core_pwr_info[c].pa_5gh[0];
  3650. b0[c] = sprom->core_pwr_info[c].pa_5gh[1];
  3651. b1[c] = sprom->core_pwr_info[c].pa_5gh[2];
  3652. }
  3653. } else {
  3654. idle[0] = nphy->pwr_ctl_info[0].idle_tssi_5g;
  3655. idle[1] = nphy->pwr_ctl_info[1].idle_tssi_5g;
  3656. target[0] = target[1] = 52;
  3657. a1[0] = a1[1] = -424;
  3658. b0[0] = b0[1] = 5612;
  3659. b1[0] = b1[1] = -1393;
  3660. }
  3661. }
  3662. ppr_max = b43_ppr_get_max(dev, &nphy->tx_pwr_max_ppr);
  3663. if (ppr_max) {
  3664. target[0] = ppr_max;
  3665. target[1] = ppr_max;
  3666. }
  3667. if (dev->phy.rev >= 3) {
  3668. if (sprom->fem.ghz2.tssipos)
  3669. b43_phy_set(dev, B43_NPHY_TXPCTL_ITSSI, 0x4000);
  3670. if (dev->phy.rev >= 7) {
  3671. for (c = 0; c < 2; c++) {
  3672. r = c ? 0x190 : 0x170;
  3673. if (b43_nphy_ipa(dev))
  3674. b43_radio_write(dev, r + 0x9, (b43_current_band(dev->wl) == NL80211_BAND_2GHZ) ? 0xE : 0xC);
  3675. }
  3676. } else {
  3677. if (b43_nphy_ipa(dev)) {
  3678. tmp = (b43_current_band(dev->wl) == NL80211_BAND_5GHZ) ? 0xC : 0xE;
  3679. b43_radio_write(dev,
  3680. B2056_TX0 | B2056_TX_TX_SSI_MUX, tmp);
  3681. b43_radio_write(dev,
  3682. B2056_TX1 | B2056_TX_TX_SSI_MUX, tmp);
  3683. } else {
  3684. b43_radio_write(dev,
  3685. B2056_TX0 | B2056_TX_TX_SSI_MUX, 0x11);
  3686. b43_radio_write(dev,
  3687. B2056_TX1 | B2056_TX_TX_SSI_MUX, 0x11);
  3688. }
  3689. }
  3690. }
  3691. if (dev->dev->core_rev == 11 || dev->dev->core_rev == 12) {
  3692. b43_maskset32(dev, B43_MMIO_MACCTL, ~0, 0x200000);
  3693. b43_read32(dev, B43_MMIO_MACCTL);
  3694. udelay(1);
  3695. }
  3696. if (phy->rev >= 19) {
  3697. /* TODO */
  3698. } else if (phy->rev >= 7) {
  3699. b43_phy_maskset(dev, B43_NPHY_TXPCTL_CMD,
  3700. ~B43_NPHY_TXPCTL_CMD_INIT, 0x19);
  3701. b43_phy_maskset(dev, B43_NPHY_TXPCTL_INIT,
  3702. ~B43_NPHY_TXPCTL_INIT_PIDXI1, 0x19);
  3703. } else {
  3704. b43_phy_maskset(dev, B43_NPHY_TXPCTL_CMD,
  3705. ~B43_NPHY_TXPCTL_CMD_INIT, 0x40);
  3706. if (dev->phy.rev > 1)
  3707. b43_phy_maskset(dev, B43_NPHY_TXPCTL_INIT,
  3708. ~B43_NPHY_TXPCTL_INIT_PIDXI1, 0x40);
  3709. }
  3710. if (dev->dev->core_rev == 11 || dev->dev->core_rev == 12)
  3711. b43_maskset32(dev, B43_MMIO_MACCTL, ~0x200000, 0);
  3712. b43_phy_write(dev, B43_NPHY_TXPCTL_N,
  3713. 0xF0 << B43_NPHY_TXPCTL_N_TSSID_SHIFT |
  3714. 3 << B43_NPHY_TXPCTL_N_NPTIL2_SHIFT);
  3715. b43_phy_write(dev, B43_NPHY_TXPCTL_ITSSI,
  3716. idle[0] << B43_NPHY_TXPCTL_ITSSI_0_SHIFT |
  3717. idle[1] << B43_NPHY_TXPCTL_ITSSI_1_SHIFT |
  3718. B43_NPHY_TXPCTL_ITSSI_BINF);
  3719. b43_phy_write(dev, B43_NPHY_TXPCTL_TPWR,
  3720. target[0] << B43_NPHY_TXPCTL_TPWR_0_SHIFT |
  3721. target[1] << B43_NPHY_TXPCTL_TPWR_1_SHIFT);
  3722. for (c = 0; c < 2; c++) {
  3723. for (i = 0; i < 64; i++) {
  3724. num = 8 * (16 * b0[c] + b1[c] * i);
  3725. den = 32768 + a1[c] * i;
  3726. pwr = max((4 * num + den / 2) / den, -8);
  3727. if (dev->phy.rev < 3 && (i <= (31 - idle[c] + 1)))
  3728. pwr = max(pwr, target[c] + 1);
  3729. regval[i] = pwr;
  3730. }
  3731. b43_ntab_write_bulk(dev, B43_NTAB32(26 + c, 0), 64, regval);
  3732. }
  3733. b43_nphy_tx_prepare_adjusted_power_table(dev);
  3734. b43_ntab_write_bulk(dev, B43_NTAB16(26, 64), 84, nphy->adj_pwr_tbl);
  3735. b43_ntab_write_bulk(dev, B43_NTAB16(27, 64), 84, nphy->adj_pwr_tbl);
  3736. if (nphy->hang_avoid)
  3737. b43_nphy_stay_in_carrier_search(dev, false);
  3738. }
  3739. static void b43_nphy_tx_gain_table_upload(struct b43_wldev *dev)
  3740. {
  3741. struct b43_phy *phy = &dev->phy;
  3742. const u32 *table = NULL;
  3743. u32 rfpwr_offset;
  3744. u8 pga_gain, pad_gain;
  3745. int i;
  3746. const s16 *uninitialized_var(rf_pwr_offset_table);
  3747. table = b43_nphy_get_tx_gain_table(dev);
  3748. if (!table)
  3749. return;
  3750. b43_ntab_write_bulk(dev, B43_NTAB32(26, 192), 128, table);
  3751. b43_ntab_write_bulk(dev, B43_NTAB32(27, 192), 128, table);
  3752. if (phy->rev < 3)
  3753. return;
  3754. #if 0
  3755. nphy->gmval = (table[0] >> 16) & 0x7000;
  3756. #endif
  3757. if (phy->rev >= 19) {
  3758. return;
  3759. } else if (phy->rev >= 7) {
  3760. rf_pwr_offset_table = b43_ntab_get_rf_pwr_offset_table(dev);
  3761. if (!rf_pwr_offset_table)
  3762. return;
  3763. /* TODO: Enable this once we have gains configured */
  3764. return;
  3765. }
  3766. for (i = 0; i < 128; i++) {
  3767. if (phy->rev >= 19) {
  3768. /* TODO */
  3769. return;
  3770. } else if (phy->rev >= 7) {
  3771. pga_gain = (table[i] >> 24) & 0xf;
  3772. pad_gain = (table[i] >> 19) & 0x1f;
  3773. if (b43_current_band(dev->wl) == NL80211_BAND_2GHZ)
  3774. rfpwr_offset = rf_pwr_offset_table[pad_gain];
  3775. else
  3776. rfpwr_offset = rf_pwr_offset_table[pga_gain];
  3777. } else {
  3778. pga_gain = (table[i] >> 24) & 0xF;
  3779. if (b43_current_band(dev->wl) == NL80211_BAND_2GHZ)
  3780. rfpwr_offset = b43_ntab_papd_pga_gain_delta_ipa_2g[pga_gain];
  3781. else
  3782. rfpwr_offset = 0; /* FIXME */
  3783. }
  3784. b43_ntab_write(dev, B43_NTAB32(26, 576 + i), rfpwr_offset);
  3785. b43_ntab_write(dev, B43_NTAB32(27, 576 + i), rfpwr_offset);
  3786. }
  3787. }
  3788. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/PA%20override */
  3789. static void b43_nphy_pa_override(struct b43_wldev *dev, bool enable)
  3790. {
  3791. struct b43_phy_n *nphy = dev->phy.n;
  3792. enum nl80211_band band;
  3793. u16 tmp;
  3794. if (!enable) {
  3795. nphy->rfctrl_intc1_save = b43_phy_read(dev,
  3796. B43_NPHY_RFCTL_INTC1);
  3797. nphy->rfctrl_intc2_save = b43_phy_read(dev,
  3798. B43_NPHY_RFCTL_INTC2);
  3799. band = b43_current_band(dev->wl);
  3800. if (dev->phy.rev >= 7) {
  3801. tmp = 0x1480;
  3802. } else if (dev->phy.rev >= 3) {
  3803. if (band == NL80211_BAND_5GHZ)
  3804. tmp = 0x600;
  3805. else
  3806. tmp = 0x480;
  3807. } else {
  3808. if (band == NL80211_BAND_5GHZ)
  3809. tmp = 0x180;
  3810. else
  3811. tmp = 0x120;
  3812. }
  3813. b43_phy_write(dev, B43_NPHY_RFCTL_INTC1, tmp);
  3814. b43_phy_write(dev, B43_NPHY_RFCTL_INTC2, tmp);
  3815. } else {
  3816. b43_phy_write(dev, B43_NPHY_RFCTL_INTC1,
  3817. nphy->rfctrl_intc1_save);
  3818. b43_phy_write(dev, B43_NPHY_RFCTL_INTC2,
  3819. nphy->rfctrl_intc2_save);
  3820. }
  3821. }
  3822. /*
  3823. * TX low-pass filter bandwidth setup
  3824. * http://bcm-v4.sipsolutions.net/802.11/PHY/N/TxLpFbw
  3825. */
  3826. static void b43_nphy_tx_lpf_bw(struct b43_wldev *dev)
  3827. {
  3828. u16 tmp;
  3829. if (dev->phy.rev < 3 || dev->phy.rev >= 7)
  3830. return;
  3831. if (b43_nphy_ipa(dev))
  3832. tmp = b43_is_40mhz(dev) ? 5 : 4;
  3833. else
  3834. tmp = b43_is_40mhz(dev) ? 3 : 1;
  3835. b43_phy_write(dev, B43_NPHY_TXF_40CO_B32S2,
  3836. (tmp << 9) | (tmp << 6) | (tmp << 3) | tmp);
  3837. if (b43_nphy_ipa(dev)) {
  3838. tmp = b43_is_40mhz(dev) ? 4 : 1;
  3839. b43_phy_write(dev, B43_NPHY_TXF_40CO_B1S2,
  3840. (tmp << 9) | (tmp << 6) | (tmp << 3) | tmp);
  3841. }
  3842. }
  3843. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/RxIqEst */
  3844. static void b43_nphy_rx_iq_est(struct b43_wldev *dev, struct nphy_iq_est *est,
  3845. u16 samps, u8 time, bool wait)
  3846. {
  3847. int i;
  3848. u16 tmp;
  3849. b43_phy_write(dev, B43_NPHY_IQEST_SAMCNT, samps);
  3850. b43_phy_maskset(dev, B43_NPHY_IQEST_WT, ~B43_NPHY_IQEST_WT_VAL, time);
  3851. if (wait)
  3852. b43_phy_set(dev, B43_NPHY_IQEST_CMD, B43_NPHY_IQEST_CMD_MODE);
  3853. else
  3854. b43_phy_mask(dev, B43_NPHY_IQEST_CMD, ~B43_NPHY_IQEST_CMD_MODE);
  3855. b43_phy_set(dev, B43_NPHY_IQEST_CMD, B43_NPHY_IQEST_CMD_START);
  3856. for (i = 1000; i; i--) {
  3857. tmp = b43_phy_read(dev, B43_NPHY_IQEST_CMD);
  3858. if (!(tmp & B43_NPHY_IQEST_CMD_START)) {
  3859. est->i0_pwr = (b43_phy_read(dev, B43_NPHY_IQEST_IPACC_HI0) << 16) |
  3860. b43_phy_read(dev, B43_NPHY_IQEST_IPACC_LO0);
  3861. est->q0_pwr = (b43_phy_read(dev, B43_NPHY_IQEST_QPACC_HI0) << 16) |
  3862. b43_phy_read(dev, B43_NPHY_IQEST_QPACC_LO0);
  3863. est->iq0_prod = (b43_phy_read(dev, B43_NPHY_IQEST_IQACC_HI0) << 16) |
  3864. b43_phy_read(dev, B43_NPHY_IQEST_IQACC_LO0);
  3865. est->i1_pwr = (b43_phy_read(dev, B43_NPHY_IQEST_IPACC_HI1) << 16) |
  3866. b43_phy_read(dev, B43_NPHY_IQEST_IPACC_LO1);
  3867. est->q1_pwr = (b43_phy_read(dev, B43_NPHY_IQEST_QPACC_HI1) << 16) |
  3868. b43_phy_read(dev, B43_NPHY_IQEST_QPACC_LO1);
  3869. est->iq1_prod = (b43_phy_read(dev, B43_NPHY_IQEST_IQACC_HI1) << 16) |
  3870. b43_phy_read(dev, B43_NPHY_IQEST_IQACC_LO1);
  3871. return;
  3872. }
  3873. udelay(10);
  3874. }
  3875. memset(est, 0, sizeof(*est));
  3876. }
  3877. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/RxIqCoeffs */
  3878. static void b43_nphy_rx_iq_coeffs(struct b43_wldev *dev, bool write,
  3879. struct b43_phy_n_iq_comp *pcomp)
  3880. {
  3881. if (write) {
  3882. b43_phy_write(dev, B43_NPHY_C1_RXIQ_COMPA0, pcomp->a0);
  3883. b43_phy_write(dev, B43_NPHY_C1_RXIQ_COMPB0, pcomp->b0);
  3884. b43_phy_write(dev, B43_NPHY_C2_RXIQ_COMPA1, pcomp->a1);
  3885. b43_phy_write(dev, B43_NPHY_C2_RXIQ_COMPB1, pcomp->b1);
  3886. } else {
  3887. pcomp->a0 = b43_phy_read(dev, B43_NPHY_C1_RXIQ_COMPA0);
  3888. pcomp->b0 = b43_phy_read(dev, B43_NPHY_C1_RXIQ_COMPB0);
  3889. pcomp->a1 = b43_phy_read(dev, B43_NPHY_C2_RXIQ_COMPA1);
  3890. pcomp->b1 = b43_phy_read(dev, B43_NPHY_C2_RXIQ_COMPB1);
  3891. }
  3892. }
  3893. #if 0
  3894. /* Ready but not used anywhere */
  3895. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/RxCalPhyCleanup */
  3896. static void b43_nphy_rx_cal_phy_cleanup(struct b43_wldev *dev, u8 core)
  3897. {
  3898. u16 *regs = dev->phy.n->tx_rx_cal_phy_saveregs;
  3899. b43_phy_write(dev, B43_NPHY_RFSEQCA, regs[0]);
  3900. if (core == 0) {
  3901. b43_phy_write(dev, B43_NPHY_AFECTL_C1, regs[1]);
  3902. b43_phy_write(dev, B43_NPHY_AFECTL_OVER1, regs[2]);
  3903. } else {
  3904. b43_phy_write(dev, B43_NPHY_AFECTL_C2, regs[1]);
  3905. b43_phy_write(dev, B43_NPHY_AFECTL_OVER, regs[2]);
  3906. }
  3907. b43_phy_write(dev, B43_NPHY_RFCTL_INTC1, regs[3]);
  3908. b43_phy_write(dev, B43_NPHY_RFCTL_INTC2, regs[4]);
  3909. b43_phy_write(dev, B43_NPHY_RFCTL_RSSIO1, regs[5]);
  3910. b43_phy_write(dev, B43_NPHY_RFCTL_RSSIO2, regs[6]);
  3911. b43_phy_write(dev, B43_NPHY_TXF_40CO_B1S1, regs[7]);
  3912. b43_phy_write(dev, B43_NPHY_RFCTL_OVER, regs[8]);
  3913. b43_phy_write(dev, B43_NPHY_PAPD_EN0, regs[9]);
  3914. b43_phy_write(dev, B43_NPHY_PAPD_EN1, regs[10]);
  3915. }
  3916. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/RxCalPhySetup */
  3917. static void b43_nphy_rx_cal_phy_setup(struct b43_wldev *dev, u8 core)
  3918. {
  3919. u8 rxval, txval;
  3920. u16 *regs = dev->phy.n->tx_rx_cal_phy_saveregs;
  3921. regs[0] = b43_phy_read(dev, B43_NPHY_RFSEQCA);
  3922. if (core == 0) {
  3923. regs[1] = b43_phy_read(dev, B43_NPHY_AFECTL_C1);
  3924. regs[2] = b43_phy_read(dev, B43_NPHY_AFECTL_OVER1);
  3925. } else {
  3926. regs[1] = b43_phy_read(dev, B43_NPHY_AFECTL_C2);
  3927. regs[2] = b43_phy_read(dev, B43_NPHY_AFECTL_OVER);
  3928. }
  3929. regs[3] = b43_phy_read(dev, B43_NPHY_RFCTL_INTC1);
  3930. regs[4] = b43_phy_read(dev, B43_NPHY_RFCTL_INTC2);
  3931. regs[5] = b43_phy_read(dev, B43_NPHY_RFCTL_RSSIO1);
  3932. regs[6] = b43_phy_read(dev, B43_NPHY_RFCTL_RSSIO2);
  3933. regs[7] = b43_phy_read(dev, B43_NPHY_TXF_40CO_B1S1);
  3934. regs[8] = b43_phy_read(dev, B43_NPHY_RFCTL_OVER);
  3935. regs[9] = b43_phy_read(dev, B43_NPHY_PAPD_EN0);
  3936. regs[10] = b43_phy_read(dev, B43_NPHY_PAPD_EN1);
  3937. b43_phy_mask(dev, B43_NPHY_PAPD_EN0, ~0x0001);
  3938. b43_phy_mask(dev, B43_NPHY_PAPD_EN1, ~0x0001);
  3939. b43_phy_maskset(dev, B43_NPHY_RFSEQCA,
  3940. ~B43_NPHY_RFSEQCA_RXDIS & 0xFFFF,
  3941. ((1 - core) << B43_NPHY_RFSEQCA_RXDIS_SHIFT));
  3942. b43_phy_maskset(dev, B43_NPHY_RFSEQCA, ~B43_NPHY_RFSEQCA_TXEN,
  3943. ((1 - core) << B43_NPHY_RFSEQCA_TXEN_SHIFT));
  3944. b43_phy_maskset(dev, B43_NPHY_RFSEQCA, ~B43_NPHY_RFSEQCA_RXEN,
  3945. (core << B43_NPHY_RFSEQCA_RXEN_SHIFT));
  3946. b43_phy_maskset(dev, B43_NPHY_RFSEQCA, ~B43_NPHY_RFSEQCA_TXDIS,
  3947. (core << B43_NPHY_RFSEQCA_TXDIS_SHIFT));
  3948. if (core == 0) {
  3949. b43_phy_mask(dev, B43_NPHY_AFECTL_C1, ~0x0007);
  3950. b43_phy_set(dev, B43_NPHY_AFECTL_OVER1, 0x0007);
  3951. } else {
  3952. b43_phy_mask(dev, B43_NPHY_AFECTL_C2, ~0x0007);
  3953. b43_phy_set(dev, B43_NPHY_AFECTL_OVER, 0x0007);
  3954. }
  3955. b43_nphy_rf_ctl_intc_override(dev, N_INTC_OVERRIDE_PA, 0, 3);
  3956. b43_nphy_rf_ctl_override(dev, 8, 0, 3, false);
  3957. b43_nphy_force_rf_sequence(dev, B43_RFSEQ_RX2TX);
  3958. if (core == 0) {
  3959. rxval = 1;
  3960. txval = 8;
  3961. } else {
  3962. rxval = 4;
  3963. txval = 2;
  3964. }
  3965. b43_nphy_rf_ctl_intc_override(dev, N_INTC_OVERRIDE_TRSW, rxval,
  3966. core + 1);
  3967. b43_nphy_rf_ctl_intc_override(dev, N_INTC_OVERRIDE_TRSW, txval,
  3968. 2 - core);
  3969. }
  3970. #endif
  3971. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/CalcRxIqComp */
  3972. static void b43_nphy_calc_rx_iq_comp(struct b43_wldev *dev, u8 mask)
  3973. {
  3974. int i;
  3975. s32 iq;
  3976. u32 ii;
  3977. u32 qq;
  3978. int iq_nbits, qq_nbits;
  3979. int arsh, brsh;
  3980. u16 tmp, a, b;
  3981. struct nphy_iq_est est;
  3982. struct b43_phy_n_iq_comp old;
  3983. struct b43_phy_n_iq_comp new = { };
  3984. bool error = false;
  3985. if (mask == 0)
  3986. return;
  3987. b43_nphy_rx_iq_coeffs(dev, false, &old);
  3988. b43_nphy_rx_iq_coeffs(dev, true, &new);
  3989. b43_nphy_rx_iq_est(dev, &est, 0x4000, 32, false);
  3990. new = old;
  3991. for (i = 0; i < 2; i++) {
  3992. if (i == 0 && (mask & 1)) {
  3993. iq = est.iq0_prod;
  3994. ii = est.i0_pwr;
  3995. qq = est.q0_pwr;
  3996. } else if (i == 1 && (mask & 2)) {
  3997. iq = est.iq1_prod;
  3998. ii = est.i1_pwr;
  3999. qq = est.q1_pwr;
  4000. } else {
  4001. continue;
  4002. }
  4003. if (ii + qq < 2) {
  4004. error = true;
  4005. break;
  4006. }
  4007. iq_nbits = fls(abs(iq));
  4008. qq_nbits = fls(qq);
  4009. arsh = iq_nbits - 20;
  4010. if (arsh >= 0) {
  4011. a = -((iq << (30 - iq_nbits)) + (ii >> (1 + arsh)));
  4012. tmp = ii >> arsh;
  4013. } else {
  4014. a = -((iq << (30 - iq_nbits)) + (ii << (-1 - arsh)));
  4015. tmp = ii << -arsh;
  4016. }
  4017. if (tmp == 0) {
  4018. error = true;
  4019. break;
  4020. }
  4021. a /= tmp;
  4022. brsh = qq_nbits - 11;
  4023. if (brsh >= 0) {
  4024. b = (qq << (31 - qq_nbits));
  4025. tmp = ii >> brsh;
  4026. } else {
  4027. b = (qq << (31 - qq_nbits));
  4028. tmp = ii << -brsh;
  4029. }
  4030. if (tmp == 0) {
  4031. error = true;
  4032. break;
  4033. }
  4034. b = int_sqrt(b / tmp - a * a) - (1 << 10);
  4035. if (i == 0 && (mask & 0x1)) {
  4036. if (dev->phy.rev >= 3) {
  4037. new.a0 = a & 0x3FF;
  4038. new.b0 = b & 0x3FF;
  4039. } else {
  4040. new.a0 = b & 0x3FF;
  4041. new.b0 = a & 0x3FF;
  4042. }
  4043. } else if (i == 1 && (mask & 0x2)) {
  4044. if (dev->phy.rev >= 3) {
  4045. new.a1 = a & 0x3FF;
  4046. new.b1 = b & 0x3FF;
  4047. } else {
  4048. new.a1 = b & 0x3FF;
  4049. new.b1 = a & 0x3FF;
  4050. }
  4051. }
  4052. }
  4053. if (error)
  4054. new = old;
  4055. b43_nphy_rx_iq_coeffs(dev, true, &new);
  4056. }
  4057. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/TxIqWar */
  4058. static void b43_nphy_tx_iq_workaround(struct b43_wldev *dev)
  4059. {
  4060. u16 array[4];
  4061. b43_ntab_read_bulk(dev, B43_NTAB16(0xF, 0x50), 4, array);
  4062. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_NPHY_TXIQW0, array[0]);
  4063. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_NPHY_TXIQW1, array[1]);
  4064. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_NPHY_TXIQW2, array[2]);
  4065. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_NPHY_TXIQW3, array[3]);
  4066. }
  4067. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/SpurWar */
  4068. static void b43_nphy_spur_workaround(struct b43_wldev *dev)
  4069. {
  4070. struct b43_phy_n *nphy = dev->phy.n;
  4071. u8 channel = dev->phy.channel;
  4072. int tone[2] = { 57, 58 };
  4073. u32 noise[2] = { 0x3FF, 0x3FF };
  4074. B43_WARN_ON(dev->phy.rev < 3);
  4075. if (nphy->hang_avoid)
  4076. b43_nphy_stay_in_carrier_search(dev, 1);
  4077. if (nphy->gband_spurwar_en) {
  4078. /* TODO: N PHY Adjust Analog Pfbw (7) */
  4079. if (channel == 11 && b43_is_40mhz(dev))
  4080. ; /* TODO: N PHY Adjust Min Noise Var(2, tone, noise)*/
  4081. else
  4082. ; /* TODO: N PHY Adjust Min Noise Var(0, NULL, NULL)*/
  4083. /* TODO: N PHY Adjust CRS Min Power (0x1E) */
  4084. }
  4085. if (nphy->aband_spurwar_en) {
  4086. if (channel == 54) {
  4087. tone[0] = 0x20;
  4088. noise[0] = 0x25F;
  4089. } else if (channel == 38 || channel == 102 || channel == 118) {
  4090. if (0 /* FIXME */) {
  4091. tone[0] = 0x20;
  4092. noise[0] = 0x21F;
  4093. } else {
  4094. tone[0] = 0;
  4095. noise[0] = 0;
  4096. }
  4097. } else if (channel == 134) {
  4098. tone[0] = 0x20;
  4099. noise[0] = 0x21F;
  4100. } else if (channel == 151) {
  4101. tone[0] = 0x10;
  4102. noise[0] = 0x23F;
  4103. } else if (channel == 153 || channel == 161) {
  4104. tone[0] = 0x30;
  4105. noise[0] = 0x23F;
  4106. } else {
  4107. tone[0] = 0;
  4108. noise[0] = 0;
  4109. }
  4110. if (!tone[0] && !noise[0])
  4111. ; /* TODO: N PHY Adjust Min Noise Var(1, tone, noise)*/
  4112. else
  4113. ; /* TODO: N PHY Adjust Min Noise Var(0, NULL, NULL)*/
  4114. }
  4115. if (nphy->hang_avoid)
  4116. b43_nphy_stay_in_carrier_search(dev, 0);
  4117. }
  4118. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/TxPwrCtrlCoefSetup */
  4119. static void b43_nphy_tx_pwr_ctrl_coef_setup(struct b43_wldev *dev)
  4120. {
  4121. struct b43_phy_n *nphy = dev->phy.n;
  4122. int i, j;
  4123. u32 tmp;
  4124. u32 cur_real, cur_imag, real_part, imag_part;
  4125. u16 buffer[7];
  4126. if (nphy->hang_avoid)
  4127. b43_nphy_stay_in_carrier_search(dev, true);
  4128. b43_ntab_read_bulk(dev, B43_NTAB16(15, 80), 7, buffer);
  4129. for (i = 0; i < 2; i++) {
  4130. tmp = ((buffer[i * 2] & 0x3FF) << 10) |
  4131. (buffer[i * 2 + 1] & 0x3FF);
  4132. b43_phy_write(dev, B43_NPHY_TABLE_ADDR,
  4133. (((i + 26) << 10) | 320));
  4134. for (j = 0; j < 128; j++) {
  4135. b43_phy_write(dev, B43_NPHY_TABLE_DATAHI,
  4136. ((tmp >> 16) & 0xFFFF));
  4137. b43_phy_write(dev, B43_NPHY_TABLE_DATALO,
  4138. (tmp & 0xFFFF));
  4139. }
  4140. }
  4141. for (i = 0; i < 2; i++) {
  4142. tmp = buffer[5 + i];
  4143. real_part = (tmp >> 8) & 0xFF;
  4144. imag_part = (tmp & 0xFF);
  4145. b43_phy_write(dev, B43_NPHY_TABLE_ADDR,
  4146. (((i + 26) << 10) | 448));
  4147. if (dev->phy.rev >= 3) {
  4148. cur_real = real_part;
  4149. cur_imag = imag_part;
  4150. tmp = ((cur_real & 0xFF) << 8) | (cur_imag & 0xFF);
  4151. }
  4152. for (j = 0; j < 128; j++) {
  4153. if (dev->phy.rev < 3) {
  4154. cur_real = (real_part * loscale[j] + 128) >> 8;
  4155. cur_imag = (imag_part * loscale[j] + 128) >> 8;
  4156. tmp = ((cur_real & 0xFF) << 8) |
  4157. (cur_imag & 0xFF);
  4158. }
  4159. b43_phy_write(dev, B43_NPHY_TABLE_DATAHI,
  4160. ((tmp >> 16) & 0xFFFF));
  4161. b43_phy_write(dev, B43_NPHY_TABLE_DATALO,
  4162. (tmp & 0xFFFF));
  4163. }
  4164. }
  4165. if (dev->phy.rev >= 3) {
  4166. b43_shm_write16(dev, B43_SHM_SHARED,
  4167. B43_SHM_SH_NPHY_TXPWR_INDX0, 0xFFFF);
  4168. b43_shm_write16(dev, B43_SHM_SHARED,
  4169. B43_SHM_SH_NPHY_TXPWR_INDX1, 0xFFFF);
  4170. }
  4171. if (nphy->hang_avoid)
  4172. b43_nphy_stay_in_carrier_search(dev, false);
  4173. }
  4174. /*
  4175. * Restore RSSI Calibration
  4176. * http://bcm-v4.sipsolutions.net/802.11/PHY/N/RestoreRssiCal
  4177. */
  4178. static void b43_nphy_restore_rssi_cal(struct b43_wldev *dev)
  4179. {
  4180. struct b43_phy_n *nphy = dev->phy.n;
  4181. u16 *rssical_radio_regs = NULL;
  4182. u16 *rssical_phy_regs = NULL;
  4183. if (b43_current_band(dev->wl) == NL80211_BAND_2GHZ) {
  4184. if (!nphy->rssical_chanspec_2G.center_freq)
  4185. return;
  4186. rssical_radio_regs = nphy->rssical_cache.rssical_radio_regs_2G;
  4187. rssical_phy_regs = nphy->rssical_cache.rssical_phy_regs_2G;
  4188. } else {
  4189. if (!nphy->rssical_chanspec_5G.center_freq)
  4190. return;
  4191. rssical_radio_regs = nphy->rssical_cache.rssical_radio_regs_5G;
  4192. rssical_phy_regs = nphy->rssical_cache.rssical_phy_regs_5G;
  4193. }
  4194. if (dev->phy.rev >= 19) {
  4195. /* TODO */
  4196. } else if (dev->phy.rev >= 7) {
  4197. b43_radio_maskset(dev, R2057_NB_MASTER_CORE0, ~R2057_VCM_MASK,
  4198. rssical_radio_regs[0]);
  4199. b43_radio_maskset(dev, R2057_NB_MASTER_CORE1, ~R2057_VCM_MASK,
  4200. rssical_radio_regs[1]);
  4201. } else {
  4202. b43_radio_maskset(dev, B2056_RX0 | B2056_RX_RSSI_MISC, 0xE3,
  4203. rssical_radio_regs[0]);
  4204. b43_radio_maskset(dev, B2056_RX1 | B2056_RX_RSSI_MISC, 0xE3,
  4205. rssical_radio_regs[1]);
  4206. }
  4207. b43_phy_write(dev, B43_NPHY_RSSIMC_0I_RSSI_Z, rssical_phy_regs[0]);
  4208. b43_phy_write(dev, B43_NPHY_RSSIMC_0Q_RSSI_Z, rssical_phy_regs[1]);
  4209. b43_phy_write(dev, B43_NPHY_RSSIMC_1I_RSSI_Z, rssical_phy_regs[2]);
  4210. b43_phy_write(dev, B43_NPHY_RSSIMC_1Q_RSSI_Z, rssical_phy_regs[3]);
  4211. b43_phy_write(dev, B43_NPHY_RSSIMC_0I_RSSI_X, rssical_phy_regs[4]);
  4212. b43_phy_write(dev, B43_NPHY_RSSIMC_0Q_RSSI_X, rssical_phy_regs[5]);
  4213. b43_phy_write(dev, B43_NPHY_RSSIMC_1I_RSSI_X, rssical_phy_regs[6]);
  4214. b43_phy_write(dev, B43_NPHY_RSSIMC_1Q_RSSI_X, rssical_phy_regs[7]);
  4215. b43_phy_write(dev, B43_NPHY_RSSIMC_0I_RSSI_Y, rssical_phy_regs[8]);
  4216. b43_phy_write(dev, B43_NPHY_RSSIMC_0Q_RSSI_Y, rssical_phy_regs[9]);
  4217. b43_phy_write(dev, B43_NPHY_RSSIMC_1I_RSSI_Y, rssical_phy_regs[10]);
  4218. b43_phy_write(dev, B43_NPHY_RSSIMC_1Q_RSSI_Y, rssical_phy_regs[11]);
  4219. }
  4220. static void b43_nphy_tx_cal_radio_setup_rev19(struct b43_wldev *dev)
  4221. {
  4222. /* TODO */
  4223. }
  4224. static void b43_nphy_tx_cal_radio_setup_rev7(struct b43_wldev *dev)
  4225. {
  4226. struct b43_phy *phy = &dev->phy;
  4227. struct b43_phy_n *nphy = dev->phy.n;
  4228. u16 *save = nphy->tx_rx_cal_radio_saveregs;
  4229. int core, off;
  4230. u16 r, tmp;
  4231. for (core = 0; core < 2; core++) {
  4232. r = core ? 0x20 : 0;
  4233. off = core * 11;
  4234. save[off + 0] = b43_radio_read(dev, r + R2057_TX0_TX_SSI_MASTER);
  4235. save[off + 1] = b43_radio_read(dev, r + R2057_TX0_IQCAL_VCM_HG);
  4236. save[off + 2] = b43_radio_read(dev, r + R2057_TX0_IQCAL_IDAC);
  4237. save[off + 3] = b43_radio_read(dev, r + R2057_TX0_TSSI_VCM);
  4238. save[off + 4] = 0;
  4239. save[off + 5] = b43_radio_read(dev, r + R2057_TX0_TX_SSI_MUX);
  4240. if (phy->radio_rev != 5)
  4241. save[off + 6] = b43_radio_read(dev, r + R2057_TX0_TSSIA);
  4242. save[off + 7] = b43_radio_read(dev, r + R2057_TX0_TSSIG);
  4243. save[off + 8] = b43_radio_read(dev, r + R2057_TX0_TSSI_MISC1);
  4244. if (b43_current_band(dev->wl) == NL80211_BAND_5GHZ) {
  4245. b43_radio_write(dev, r + R2057_TX0_TX_SSI_MASTER, 0xA);
  4246. b43_radio_write(dev, r + R2057_TX0_IQCAL_VCM_HG, 0x43);
  4247. b43_radio_write(dev, r + R2057_TX0_IQCAL_IDAC, 0x55);
  4248. b43_radio_write(dev, r + R2057_TX0_TSSI_VCM, 0);
  4249. b43_radio_write(dev, r + R2057_TX0_TSSIG, 0);
  4250. if (nphy->use_int_tx_iq_lo_cal) {
  4251. b43_radio_write(dev, r + R2057_TX0_TX_SSI_MUX, 0x4);
  4252. tmp = true ? 0x31 : 0x21; /* TODO */
  4253. b43_radio_write(dev, r + R2057_TX0_TSSIA, tmp);
  4254. }
  4255. b43_radio_write(dev, r + R2057_TX0_TSSI_MISC1, 0x00);
  4256. } else {
  4257. b43_radio_write(dev, r + R2057_TX0_TX_SSI_MASTER, 0x6);
  4258. b43_radio_write(dev, r + R2057_TX0_IQCAL_VCM_HG, 0x43);
  4259. b43_radio_write(dev, r + R2057_TX0_IQCAL_IDAC, 0x55);
  4260. b43_radio_write(dev, r + R2057_TX0_TSSI_VCM, 0);
  4261. if (phy->radio_rev != 5)
  4262. b43_radio_write(dev, r + R2057_TX0_TSSIA, 0);
  4263. if (nphy->use_int_tx_iq_lo_cal) {
  4264. b43_radio_write(dev, r + R2057_TX0_TX_SSI_MUX, 0x6);
  4265. tmp = true ? 0x31 : 0x21; /* TODO */
  4266. b43_radio_write(dev, r + R2057_TX0_TSSIG, tmp);
  4267. }
  4268. b43_radio_write(dev, r + R2057_TX0_TSSI_MISC1, 0);
  4269. }
  4270. }
  4271. }
  4272. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/TxCalRadioSetup */
  4273. static void b43_nphy_tx_cal_radio_setup(struct b43_wldev *dev)
  4274. {
  4275. struct b43_phy *phy = &dev->phy;
  4276. struct b43_phy_n *nphy = dev->phy.n;
  4277. u16 *save = nphy->tx_rx_cal_radio_saveregs;
  4278. u16 tmp;
  4279. u8 offset, i;
  4280. if (phy->rev >= 19) {
  4281. b43_nphy_tx_cal_radio_setup_rev19(dev);
  4282. } else if (phy->rev >= 7) {
  4283. b43_nphy_tx_cal_radio_setup_rev7(dev);
  4284. } else if (phy->rev >= 3) {
  4285. for (i = 0; i < 2; i++) {
  4286. tmp = (i == 0) ? 0x2000 : 0x3000;
  4287. offset = i * 11;
  4288. save[offset + 0] = b43_radio_read(dev, B2055_CAL_RVARCTL);
  4289. save[offset + 1] = b43_radio_read(dev, B2055_CAL_LPOCTL);
  4290. save[offset + 2] = b43_radio_read(dev, B2055_CAL_TS);
  4291. save[offset + 3] = b43_radio_read(dev, B2055_CAL_RCCALRTS);
  4292. save[offset + 4] = b43_radio_read(dev, B2055_CAL_RCALRTS);
  4293. save[offset + 5] = b43_radio_read(dev, B2055_PADDRV);
  4294. save[offset + 6] = b43_radio_read(dev, B2055_XOCTL1);
  4295. save[offset + 7] = b43_radio_read(dev, B2055_XOCTL2);
  4296. save[offset + 8] = b43_radio_read(dev, B2055_XOREGUL);
  4297. save[offset + 9] = b43_radio_read(dev, B2055_XOMISC);
  4298. save[offset + 10] = b43_radio_read(dev, B2055_PLL_LFC1);
  4299. if (b43_current_band(dev->wl) == NL80211_BAND_5GHZ) {
  4300. b43_radio_write(dev, tmp | B2055_CAL_RVARCTL, 0x0A);
  4301. b43_radio_write(dev, tmp | B2055_CAL_LPOCTL, 0x40);
  4302. b43_radio_write(dev, tmp | B2055_CAL_TS, 0x55);
  4303. b43_radio_write(dev, tmp | B2055_CAL_RCCALRTS, 0);
  4304. b43_radio_write(dev, tmp | B2055_CAL_RCALRTS, 0);
  4305. if (nphy->ipa5g_on) {
  4306. b43_radio_write(dev, tmp | B2055_PADDRV, 4);
  4307. b43_radio_write(dev, tmp | B2055_XOCTL1, 1);
  4308. } else {
  4309. b43_radio_write(dev, tmp | B2055_PADDRV, 0);
  4310. b43_radio_write(dev, tmp | B2055_XOCTL1, 0x2F);
  4311. }
  4312. b43_radio_write(dev, tmp | B2055_XOCTL2, 0);
  4313. } else {
  4314. b43_radio_write(dev, tmp | B2055_CAL_RVARCTL, 0x06);
  4315. b43_radio_write(dev, tmp | B2055_CAL_LPOCTL, 0x40);
  4316. b43_radio_write(dev, tmp | B2055_CAL_TS, 0x55);
  4317. b43_radio_write(dev, tmp | B2055_CAL_RCCALRTS, 0);
  4318. b43_radio_write(dev, tmp | B2055_CAL_RCALRTS, 0);
  4319. b43_radio_write(dev, tmp | B2055_XOCTL1, 0);
  4320. if (nphy->ipa2g_on) {
  4321. b43_radio_write(dev, tmp | B2055_PADDRV, 6);
  4322. b43_radio_write(dev, tmp | B2055_XOCTL2,
  4323. (dev->phy.rev < 5) ? 0x11 : 0x01);
  4324. } else {
  4325. b43_radio_write(dev, tmp | B2055_PADDRV, 0);
  4326. b43_radio_write(dev, tmp | B2055_XOCTL2, 0);
  4327. }
  4328. }
  4329. b43_radio_write(dev, tmp | B2055_XOREGUL, 0);
  4330. b43_radio_write(dev, tmp | B2055_XOMISC, 0);
  4331. b43_radio_write(dev, tmp | B2055_PLL_LFC1, 0);
  4332. }
  4333. } else {
  4334. save[0] = b43_radio_read(dev, B2055_C1_TX_RF_IQCAL1);
  4335. b43_radio_write(dev, B2055_C1_TX_RF_IQCAL1, 0x29);
  4336. save[1] = b43_radio_read(dev, B2055_C1_TX_RF_IQCAL2);
  4337. b43_radio_write(dev, B2055_C1_TX_RF_IQCAL2, 0x54);
  4338. save[2] = b43_radio_read(dev, B2055_C2_TX_RF_IQCAL1);
  4339. b43_radio_write(dev, B2055_C2_TX_RF_IQCAL1, 0x29);
  4340. save[3] = b43_radio_read(dev, B2055_C2_TX_RF_IQCAL2);
  4341. b43_radio_write(dev, B2055_C2_TX_RF_IQCAL2, 0x54);
  4342. save[3] = b43_radio_read(dev, B2055_C1_PWRDET_RXTX);
  4343. save[4] = b43_radio_read(dev, B2055_C2_PWRDET_RXTX);
  4344. if (!(b43_phy_read(dev, B43_NPHY_BANDCTL) &
  4345. B43_NPHY_BANDCTL_5GHZ)) {
  4346. b43_radio_write(dev, B2055_C1_PWRDET_RXTX, 0x04);
  4347. b43_radio_write(dev, B2055_C2_PWRDET_RXTX, 0x04);
  4348. } else {
  4349. b43_radio_write(dev, B2055_C1_PWRDET_RXTX, 0x20);
  4350. b43_radio_write(dev, B2055_C2_PWRDET_RXTX, 0x20);
  4351. }
  4352. if (dev->phy.rev < 2) {
  4353. b43_radio_set(dev, B2055_C1_TX_BB_MXGM, 0x20);
  4354. b43_radio_set(dev, B2055_C2_TX_BB_MXGM, 0x20);
  4355. } else {
  4356. b43_radio_mask(dev, B2055_C1_TX_BB_MXGM, ~0x20);
  4357. b43_radio_mask(dev, B2055_C2_TX_BB_MXGM, ~0x20);
  4358. }
  4359. }
  4360. }
  4361. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/UpdateTxCalLadder */
  4362. static void b43_nphy_update_tx_cal_ladder(struct b43_wldev *dev, u16 core)
  4363. {
  4364. struct b43_phy_n *nphy = dev->phy.n;
  4365. int i;
  4366. u16 scale, entry;
  4367. u16 tmp = nphy->txcal_bbmult;
  4368. if (core == 0)
  4369. tmp >>= 8;
  4370. tmp &= 0xff;
  4371. for (i = 0; i < 18; i++) {
  4372. scale = (ladder_lo[i].percent * tmp) / 100;
  4373. entry = ((scale & 0xFF) << 8) | ladder_lo[i].g_env;
  4374. b43_ntab_write(dev, B43_NTAB16(15, i), entry);
  4375. scale = (ladder_iq[i].percent * tmp) / 100;
  4376. entry = ((scale & 0xFF) << 8) | ladder_iq[i].g_env;
  4377. b43_ntab_write(dev, B43_NTAB16(15, i + 32), entry);
  4378. }
  4379. }
  4380. static void b43_nphy_pa_set_tx_dig_filter(struct b43_wldev *dev, u16 offset,
  4381. const s16 *filter)
  4382. {
  4383. int i;
  4384. offset = B43_PHY_N(offset);
  4385. for (i = 0; i < 15; i++, offset++)
  4386. b43_phy_write(dev, offset, filter[i]);
  4387. }
  4388. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/ExtPaSetTxDigiFilts */
  4389. static void b43_nphy_ext_pa_set_tx_dig_filters(struct b43_wldev *dev)
  4390. {
  4391. b43_nphy_pa_set_tx_dig_filter(dev, 0x2C5,
  4392. tbl_tx_filter_coef_rev4[2]);
  4393. }
  4394. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/IpaSetTxDigiFilts */
  4395. static void b43_nphy_int_pa_set_tx_dig_filters(struct b43_wldev *dev)
  4396. {
  4397. /* B43_NPHY_TXF_20CO_S0A1, B43_NPHY_TXF_40CO_S0A1, unknown */
  4398. static const u16 offset[] = { 0x186, 0x195, 0x2C5 };
  4399. static const s16 dig_filter_phy_rev16[] = {
  4400. -375, 136, -407, 208, -1527,
  4401. 956, 93, 186, 93, 230,
  4402. -44, 230, 201, -191, 201,
  4403. };
  4404. int i;
  4405. for (i = 0; i < 3; i++)
  4406. b43_nphy_pa_set_tx_dig_filter(dev, offset[i],
  4407. tbl_tx_filter_coef_rev4[i]);
  4408. /* Verified with BCM43227 and BCM43228 */
  4409. if (dev->phy.rev == 16)
  4410. b43_nphy_pa_set_tx_dig_filter(dev, 0x186, dig_filter_phy_rev16);
  4411. /* Verified with BCM43131 and BCM43217 */
  4412. if (dev->phy.rev == 17) {
  4413. b43_nphy_pa_set_tx_dig_filter(dev, 0x186, dig_filter_phy_rev16);
  4414. b43_nphy_pa_set_tx_dig_filter(dev, 0x195,
  4415. tbl_tx_filter_coef_rev4[1]);
  4416. }
  4417. if (b43_is_40mhz(dev)) {
  4418. b43_nphy_pa_set_tx_dig_filter(dev, 0x186,
  4419. tbl_tx_filter_coef_rev4[3]);
  4420. } else {
  4421. if (b43_current_band(dev->wl) == NL80211_BAND_5GHZ)
  4422. b43_nphy_pa_set_tx_dig_filter(dev, 0x186,
  4423. tbl_tx_filter_coef_rev4[5]);
  4424. if (dev->phy.channel == 14)
  4425. b43_nphy_pa_set_tx_dig_filter(dev, 0x186,
  4426. tbl_tx_filter_coef_rev4[6]);
  4427. }
  4428. }
  4429. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/GetTxGain */
  4430. static struct nphy_txgains b43_nphy_get_tx_gains(struct b43_wldev *dev)
  4431. {
  4432. struct b43_phy_n *nphy = dev->phy.n;
  4433. u16 curr_gain[2];
  4434. struct nphy_txgains target;
  4435. const u32 *table = NULL;
  4436. if (!nphy->txpwrctrl) {
  4437. int i;
  4438. if (nphy->hang_avoid)
  4439. b43_nphy_stay_in_carrier_search(dev, true);
  4440. b43_ntab_read_bulk(dev, B43_NTAB16(7, 0x110), 2, curr_gain);
  4441. if (nphy->hang_avoid)
  4442. b43_nphy_stay_in_carrier_search(dev, false);
  4443. for (i = 0; i < 2; ++i) {
  4444. if (dev->phy.rev >= 7) {
  4445. target.ipa[i] = curr_gain[i] & 0x0007;
  4446. target.pad[i] = (curr_gain[i] & 0x00F8) >> 3;
  4447. target.pga[i] = (curr_gain[i] & 0x0F00) >> 8;
  4448. target.txgm[i] = (curr_gain[i] & 0x7000) >> 12;
  4449. target.tx_lpf[i] = (curr_gain[i] & 0x8000) >> 15;
  4450. } else if (dev->phy.rev >= 3) {
  4451. target.ipa[i] = curr_gain[i] & 0x000F;
  4452. target.pad[i] = (curr_gain[i] & 0x00F0) >> 4;
  4453. target.pga[i] = (curr_gain[i] & 0x0F00) >> 8;
  4454. target.txgm[i] = (curr_gain[i] & 0x7000) >> 12;
  4455. } else {
  4456. target.ipa[i] = curr_gain[i] & 0x0003;
  4457. target.pad[i] = (curr_gain[i] & 0x000C) >> 2;
  4458. target.pga[i] = (curr_gain[i] & 0x0070) >> 4;
  4459. target.txgm[i] = (curr_gain[i] & 0x0380) >> 7;
  4460. }
  4461. }
  4462. } else {
  4463. int i;
  4464. u16 index[2];
  4465. index[0] = (b43_phy_read(dev, B43_NPHY_C1_TXPCTL_STAT) &
  4466. B43_NPHY_TXPCTL_STAT_BIDX) >>
  4467. B43_NPHY_TXPCTL_STAT_BIDX_SHIFT;
  4468. index[1] = (b43_phy_read(dev, B43_NPHY_C2_TXPCTL_STAT) &
  4469. B43_NPHY_TXPCTL_STAT_BIDX) >>
  4470. B43_NPHY_TXPCTL_STAT_BIDX_SHIFT;
  4471. for (i = 0; i < 2; ++i) {
  4472. table = b43_nphy_get_tx_gain_table(dev);
  4473. if (!table)
  4474. break;
  4475. if (dev->phy.rev >= 7) {
  4476. target.ipa[i] = (table[index[i]] >> 16) & 0x7;
  4477. target.pad[i] = (table[index[i]] >> 19) & 0x1F;
  4478. target.pga[i] = (table[index[i]] >> 24) & 0xF;
  4479. target.txgm[i] = (table[index[i]] >> 28) & 0x7;
  4480. target.tx_lpf[i] = (table[index[i]] >> 31) & 0x1;
  4481. } else if (dev->phy.rev >= 3) {
  4482. target.ipa[i] = (table[index[i]] >> 16) & 0xF;
  4483. target.pad[i] = (table[index[i]] >> 20) & 0xF;
  4484. target.pga[i] = (table[index[i]] >> 24) & 0xF;
  4485. target.txgm[i] = (table[index[i]] >> 28) & 0xF;
  4486. } else {
  4487. target.ipa[i] = (table[index[i]] >> 16) & 0x3;
  4488. target.pad[i] = (table[index[i]] >> 18) & 0x3;
  4489. target.pga[i] = (table[index[i]] >> 20) & 0x7;
  4490. target.txgm[i] = (table[index[i]] >> 23) & 0x7;
  4491. }
  4492. }
  4493. }
  4494. return target;
  4495. }
  4496. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/TxCalPhyCleanup */
  4497. static void b43_nphy_tx_cal_phy_cleanup(struct b43_wldev *dev)
  4498. {
  4499. u16 *regs = dev->phy.n->tx_rx_cal_phy_saveregs;
  4500. if (dev->phy.rev >= 3) {
  4501. b43_phy_write(dev, B43_NPHY_AFECTL_C1, regs[0]);
  4502. b43_phy_write(dev, B43_NPHY_AFECTL_C2, regs[1]);
  4503. b43_phy_write(dev, B43_NPHY_AFECTL_OVER1, regs[2]);
  4504. b43_phy_write(dev, B43_NPHY_AFECTL_OVER, regs[3]);
  4505. b43_phy_write(dev, B43_NPHY_BBCFG, regs[4]);
  4506. b43_ntab_write(dev, B43_NTAB16(8, 3), regs[5]);
  4507. b43_ntab_write(dev, B43_NTAB16(8, 19), regs[6]);
  4508. b43_phy_write(dev, B43_NPHY_RFCTL_INTC1, regs[7]);
  4509. b43_phy_write(dev, B43_NPHY_RFCTL_INTC2, regs[8]);
  4510. b43_phy_write(dev, B43_NPHY_PAPD_EN0, regs[9]);
  4511. b43_phy_write(dev, B43_NPHY_PAPD_EN1, regs[10]);
  4512. b43_nphy_reset_cca(dev);
  4513. } else {
  4514. b43_phy_maskset(dev, B43_NPHY_AFECTL_C1, 0x0FFF, regs[0]);
  4515. b43_phy_maskset(dev, B43_NPHY_AFECTL_C2, 0x0FFF, regs[1]);
  4516. b43_phy_write(dev, B43_NPHY_AFECTL_OVER, regs[2]);
  4517. b43_ntab_write(dev, B43_NTAB16(8, 2), regs[3]);
  4518. b43_ntab_write(dev, B43_NTAB16(8, 18), regs[4]);
  4519. b43_phy_write(dev, B43_NPHY_RFCTL_INTC1, regs[5]);
  4520. b43_phy_write(dev, B43_NPHY_RFCTL_INTC2, regs[6]);
  4521. }
  4522. }
  4523. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/TxCalPhySetup */
  4524. static void b43_nphy_tx_cal_phy_setup(struct b43_wldev *dev)
  4525. {
  4526. struct b43_phy *phy = &dev->phy;
  4527. struct b43_phy_n *nphy = dev->phy.n;
  4528. u16 *regs = dev->phy.n->tx_rx_cal_phy_saveregs;
  4529. u16 tmp;
  4530. regs[0] = b43_phy_read(dev, B43_NPHY_AFECTL_C1);
  4531. regs[1] = b43_phy_read(dev, B43_NPHY_AFECTL_C2);
  4532. if (dev->phy.rev >= 3) {
  4533. b43_phy_maskset(dev, B43_NPHY_AFECTL_C1, 0xF0FF, 0x0A00);
  4534. b43_phy_maskset(dev, B43_NPHY_AFECTL_C2, 0xF0FF, 0x0A00);
  4535. tmp = b43_phy_read(dev, B43_NPHY_AFECTL_OVER1);
  4536. regs[2] = tmp;
  4537. b43_phy_write(dev, B43_NPHY_AFECTL_OVER1, tmp | 0x0600);
  4538. tmp = b43_phy_read(dev, B43_NPHY_AFECTL_OVER);
  4539. regs[3] = tmp;
  4540. b43_phy_write(dev, B43_NPHY_AFECTL_OVER, tmp | 0x0600);
  4541. regs[4] = b43_phy_read(dev, B43_NPHY_BBCFG);
  4542. b43_phy_mask(dev, B43_NPHY_BBCFG,
  4543. ~B43_NPHY_BBCFG_RSTRX & 0xFFFF);
  4544. tmp = b43_ntab_read(dev, B43_NTAB16(8, 3));
  4545. regs[5] = tmp;
  4546. b43_ntab_write(dev, B43_NTAB16(8, 3), 0);
  4547. tmp = b43_ntab_read(dev, B43_NTAB16(8, 19));
  4548. regs[6] = tmp;
  4549. b43_ntab_write(dev, B43_NTAB16(8, 19), 0);
  4550. regs[7] = b43_phy_read(dev, B43_NPHY_RFCTL_INTC1);
  4551. regs[8] = b43_phy_read(dev, B43_NPHY_RFCTL_INTC2);
  4552. if (!nphy->use_int_tx_iq_lo_cal)
  4553. b43_nphy_rf_ctl_intc_override(dev, N_INTC_OVERRIDE_PA,
  4554. 1, 3);
  4555. else
  4556. b43_nphy_rf_ctl_intc_override(dev, N_INTC_OVERRIDE_PA,
  4557. 0, 3);
  4558. b43_nphy_rf_ctl_intc_override(dev, N_INTC_OVERRIDE_TRSW, 2, 1);
  4559. b43_nphy_rf_ctl_intc_override(dev, N_INTC_OVERRIDE_TRSW, 8, 2);
  4560. regs[9] = b43_phy_read(dev, B43_NPHY_PAPD_EN0);
  4561. regs[10] = b43_phy_read(dev, B43_NPHY_PAPD_EN1);
  4562. b43_phy_mask(dev, B43_NPHY_PAPD_EN0, ~0x0001);
  4563. b43_phy_mask(dev, B43_NPHY_PAPD_EN1, ~0x0001);
  4564. tmp = b43_nphy_read_lpf_ctl(dev, 0);
  4565. if (phy->rev >= 19)
  4566. b43_nphy_rf_ctl_override_rev19(dev, 0x80, tmp, 0, false,
  4567. 1);
  4568. else if (phy->rev >= 7)
  4569. b43_nphy_rf_ctl_override_rev7(dev, 0x80, tmp, 0, false,
  4570. 1);
  4571. if (nphy->use_int_tx_iq_lo_cal && true /* FIXME */) {
  4572. if (phy->rev >= 19) {
  4573. b43_nphy_rf_ctl_override_rev19(dev, 0x8, 0, 0x3,
  4574. false, 0);
  4575. } else if (phy->rev >= 8) {
  4576. b43_nphy_rf_ctl_override_rev7(dev, 0x8, 0, 0x3,
  4577. false, 0);
  4578. } else if (phy->rev == 7) {
  4579. b43_radio_maskset(dev, R2057_OVR_REG0, 1 << 4, 1 << 4);
  4580. if (b43_current_band(dev->wl) == NL80211_BAND_2GHZ) {
  4581. b43_radio_maskset(dev, R2057_PAD2G_TUNE_PUS_CORE0, ~1, 0);
  4582. b43_radio_maskset(dev, R2057_PAD2G_TUNE_PUS_CORE1, ~1, 0);
  4583. } else {
  4584. b43_radio_maskset(dev, R2057_IPA5G_CASCOFFV_PU_CORE0, ~1, 0);
  4585. b43_radio_maskset(dev, R2057_IPA5G_CASCOFFV_PU_CORE1, ~1, 0);
  4586. }
  4587. }
  4588. }
  4589. } else {
  4590. b43_phy_maskset(dev, B43_NPHY_AFECTL_C1, 0x0FFF, 0xA000);
  4591. b43_phy_maskset(dev, B43_NPHY_AFECTL_C2, 0x0FFF, 0xA000);
  4592. tmp = b43_phy_read(dev, B43_NPHY_AFECTL_OVER);
  4593. regs[2] = tmp;
  4594. b43_phy_write(dev, B43_NPHY_AFECTL_OVER, tmp | 0x3000);
  4595. tmp = b43_ntab_read(dev, B43_NTAB16(8, 2));
  4596. regs[3] = tmp;
  4597. tmp |= 0x2000;
  4598. b43_ntab_write(dev, B43_NTAB16(8, 2), tmp);
  4599. tmp = b43_ntab_read(dev, B43_NTAB16(8, 18));
  4600. regs[4] = tmp;
  4601. tmp |= 0x2000;
  4602. b43_ntab_write(dev, B43_NTAB16(8, 18), tmp);
  4603. regs[5] = b43_phy_read(dev, B43_NPHY_RFCTL_INTC1);
  4604. regs[6] = b43_phy_read(dev, B43_NPHY_RFCTL_INTC2);
  4605. if (b43_current_band(dev->wl) == NL80211_BAND_5GHZ)
  4606. tmp = 0x0180;
  4607. else
  4608. tmp = 0x0120;
  4609. b43_phy_write(dev, B43_NPHY_RFCTL_INTC1, tmp);
  4610. b43_phy_write(dev, B43_NPHY_RFCTL_INTC2, tmp);
  4611. }
  4612. }
  4613. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/SaveCal */
  4614. static void b43_nphy_save_cal(struct b43_wldev *dev)
  4615. {
  4616. struct b43_phy *phy = &dev->phy;
  4617. struct b43_phy_n *nphy = dev->phy.n;
  4618. struct b43_phy_n_iq_comp *rxcal_coeffs = NULL;
  4619. u16 *txcal_radio_regs = NULL;
  4620. struct b43_chanspec *iqcal_chanspec;
  4621. u16 *table = NULL;
  4622. if (nphy->hang_avoid)
  4623. b43_nphy_stay_in_carrier_search(dev, 1);
  4624. if (b43_current_band(dev->wl) == NL80211_BAND_2GHZ) {
  4625. rxcal_coeffs = &nphy->cal_cache.rxcal_coeffs_2G;
  4626. txcal_radio_regs = nphy->cal_cache.txcal_radio_regs_2G;
  4627. iqcal_chanspec = &nphy->iqcal_chanspec_2G;
  4628. table = nphy->cal_cache.txcal_coeffs_2G;
  4629. } else {
  4630. rxcal_coeffs = &nphy->cal_cache.rxcal_coeffs_5G;
  4631. txcal_radio_regs = nphy->cal_cache.txcal_radio_regs_5G;
  4632. iqcal_chanspec = &nphy->iqcal_chanspec_5G;
  4633. table = nphy->cal_cache.txcal_coeffs_5G;
  4634. }
  4635. b43_nphy_rx_iq_coeffs(dev, false, rxcal_coeffs);
  4636. /* TODO use some definitions */
  4637. if (phy->rev >= 19) {
  4638. /* TODO */
  4639. } else if (phy->rev >= 7) {
  4640. txcal_radio_regs[0] = b43_radio_read(dev,
  4641. R2057_TX0_LOFT_FINE_I);
  4642. txcal_radio_regs[1] = b43_radio_read(dev,
  4643. R2057_TX0_LOFT_FINE_Q);
  4644. txcal_radio_regs[4] = b43_radio_read(dev,
  4645. R2057_TX0_LOFT_COARSE_I);
  4646. txcal_radio_regs[5] = b43_radio_read(dev,
  4647. R2057_TX0_LOFT_COARSE_Q);
  4648. txcal_radio_regs[2] = b43_radio_read(dev,
  4649. R2057_TX1_LOFT_FINE_I);
  4650. txcal_radio_regs[3] = b43_radio_read(dev,
  4651. R2057_TX1_LOFT_FINE_Q);
  4652. txcal_radio_regs[6] = b43_radio_read(dev,
  4653. R2057_TX1_LOFT_COARSE_I);
  4654. txcal_radio_regs[7] = b43_radio_read(dev,
  4655. R2057_TX1_LOFT_COARSE_Q);
  4656. } else if (phy->rev >= 3) {
  4657. txcal_radio_regs[0] = b43_radio_read(dev, 0x2021);
  4658. txcal_radio_regs[1] = b43_radio_read(dev, 0x2022);
  4659. txcal_radio_regs[2] = b43_radio_read(dev, 0x3021);
  4660. txcal_radio_regs[3] = b43_radio_read(dev, 0x3022);
  4661. txcal_radio_regs[4] = b43_radio_read(dev, 0x2023);
  4662. txcal_radio_regs[5] = b43_radio_read(dev, 0x2024);
  4663. txcal_radio_regs[6] = b43_radio_read(dev, 0x3023);
  4664. txcal_radio_regs[7] = b43_radio_read(dev, 0x3024);
  4665. } else {
  4666. txcal_radio_regs[0] = b43_radio_read(dev, 0x8B);
  4667. txcal_radio_regs[1] = b43_radio_read(dev, 0xBA);
  4668. txcal_radio_regs[2] = b43_radio_read(dev, 0x8D);
  4669. txcal_radio_regs[3] = b43_radio_read(dev, 0xBC);
  4670. }
  4671. iqcal_chanspec->center_freq = dev->phy.chandef->chan->center_freq;
  4672. iqcal_chanspec->channel_type =
  4673. cfg80211_get_chandef_type(dev->phy.chandef);
  4674. b43_ntab_read_bulk(dev, B43_NTAB16(15, 80), 8, table);
  4675. if (nphy->hang_avoid)
  4676. b43_nphy_stay_in_carrier_search(dev, 0);
  4677. }
  4678. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/RestoreCal */
  4679. static void b43_nphy_restore_cal(struct b43_wldev *dev)
  4680. {
  4681. struct b43_phy *phy = &dev->phy;
  4682. struct b43_phy_n *nphy = dev->phy.n;
  4683. u16 coef[4];
  4684. u16 *loft = NULL;
  4685. u16 *table = NULL;
  4686. int i;
  4687. u16 *txcal_radio_regs = NULL;
  4688. struct b43_phy_n_iq_comp *rxcal_coeffs = NULL;
  4689. if (b43_current_band(dev->wl) == NL80211_BAND_2GHZ) {
  4690. if (!nphy->iqcal_chanspec_2G.center_freq)
  4691. return;
  4692. table = nphy->cal_cache.txcal_coeffs_2G;
  4693. loft = &nphy->cal_cache.txcal_coeffs_2G[5];
  4694. } else {
  4695. if (!nphy->iqcal_chanspec_5G.center_freq)
  4696. return;
  4697. table = nphy->cal_cache.txcal_coeffs_5G;
  4698. loft = &nphy->cal_cache.txcal_coeffs_5G[5];
  4699. }
  4700. b43_ntab_write_bulk(dev, B43_NTAB16(15, 80), 4, table);
  4701. for (i = 0; i < 4; i++) {
  4702. if (dev->phy.rev >= 3)
  4703. table[i] = coef[i];
  4704. else
  4705. coef[i] = 0;
  4706. }
  4707. b43_ntab_write_bulk(dev, B43_NTAB16(15, 88), 4, coef);
  4708. b43_ntab_write_bulk(dev, B43_NTAB16(15, 85), 2, loft);
  4709. b43_ntab_write_bulk(dev, B43_NTAB16(15, 93), 2, loft);
  4710. if (dev->phy.rev < 2)
  4711. b43_nphy_tx_iq_workaround(dev);
  4712. if (b43_current_band(dev->wl) == NL80211_BAND_2GHZ) {
  4713. txcal_radio_regs = nphy->cal_cache.txcal_radio_regs_2G;
  4714. rxcal_coeffs = &nphy->cal_cache.rxcal_coeffs_2G;
  4715. } else {
  4716. txcal_radio_regs = nphy->cal_cache.txcal_radio_regs_5G;
  4717. rxcal_coeffs = &nphy->cal_cache.rxcal_coeffs_5G;
  4718. }
  4719. /* TODO use some definitions */
  4720. if (phy->rev >= 19) {
  4721. /* TODO */
  4722. } else if (phy->rev >= 7) {
  4723. b43_radio_write(dev, R2057_TX0_LOFT_FINE_I,
  4724. txcal_radio_regs[0]);
  4725. b43_radio_write(dev, R2057_TX0_LOFT_FINE_Q,
  4726. txcal_radio_regs[1]);
  4727. b43_radio_write(dev, R2057_TX0_LOFT_COARSE_I,
  4728. txcal_radio_regs[4]);
  4729. b43_radio_write(dev, R2057_TX0_LOFT_COARSE_Q,
  4730. txcal_radio_regs[5]);
  4731. b43_radio_write(dev, R2057_TX1_LOFT_FINE_I,
  4732. txcal_radio_regs[2]);
  4733. b43_radio_write(dev, R2057_TX1_LOFT_FINE_Q,
  4734. txcal_radio_regs[3]);
  4735. b43_radio_write(dev, R2057_TX1_LOFT_COARSE_I,
  4736. txcal_radio_regs[6]);
  4737. b43_radio_write(dev, R2057_TX1_LOFT_COARSE_Q,
  4738. txcal_radio_regs[7]);
  4739. } else if (phy->rev >= 3) {
  4740. b43_radio_write(dev, 0x2021, txcal_radio_regs[0]);
  4741. b43_radio_write(dev, 0x2022, txcal_radio_regs[1]);
  4742. b43_radio_write(dev, 0x3021, txcal_radio_regs[2]);
  4743. b43_radio_write(dev, 0x3022, txcal_radio_regs[3]);
  4744. b43_radio_write(dev, 0x2023, txcal_radio_regs[4]);
  4745. b43_radio_write(dev, 0x2024, txcal_radio_regs[5]);
  4746. b43_radio_write(dev, 0x3023, txcal_radio_regs[6]);
  4747. b43_radio_write(dev, 0x3024, txcal_radio_regs[7]);
  4748. } else {
  4749. b43_radio_write(dev, 0x8B, txcal_radio_regs[0]);
  4750. b43_radio_write(dev, 0xBA, txcal_radio_regs[1]);
  4751. b43_radio_write(dev, 0x8D, txcal_radio_regs[2]);
  4752. b43_radio_write(dev, 0xBC, txcal_radio_regs[3]);
  4753. }
  4754. b43_nphy_rx_iq_coeffs(dev, true, rxcal_coeffs);
  4755. }
  4756. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/CalTxIqlo */
  4757. static int b43_nphy_cal_tx_iq_lo(struct b43_wldev *dev,
  4758. struct nphy_txgains target,
  4759. bool full, bool mphase)
  4760. {
  4761. struct b43_phy *phy = &dev->phy;
  4762. struct b43_phy_n *nphy = dev->phy.n;
  4763. int i;
  4764. int error = 0;
  4765. int freq;
  4766. bool avoid = false;
  4767. u8 length;
  4768. u16 tmp, core, type, count, max, numb, last = 0, cmd;
  4769. const u16 *table;
  4770. bool phy6or5x;
  4771. u16 buffer[11];
  4772. u16 diq_start = 0;
  4773. u16 save[2];
  4774. u16 gain[2];
  4775. struct nphy_iqcal_params params[2];
  4776. bool updated[2] = { };
  4777. b43_nphy_stay_in_carrier_search(dev, true);
  4778. if (dev->phy.rev >= 4) {
  4779. avoid = nphy->hang_avoid;
  4780. nphy->hang_avoid = false;
  4781. }
  4782. b43_ntab_read_bulk(dev, B43_NTAB16(7, 0x110), 2, save);
  4783. for (i = 0; i < 2; i++) {
  4784. b43_nphy_iq_cal_gain_params(dev, i, target, &params[i]);
  4785. gain[i] = params[i].cal_gain;
  4786. }
  4787. b43_ntab_write_bulk(dev, B43_NTAB16(7, 0x110), 2, gain);
  4788. b43_nphy_tx_cal_radio_setup(dev);
  4789. b43_nphy_tx_cal_phy_setup(dev);
  4790. phy6or5x = dev->phy.rev >= 6 ||
  4791. (dev->phy.rev == 5 && nphy->ipa2g_on &&
  4792. b43_current_band(dev->wl) == NL80211_BAND_2GHZ);
  4793. if (phy6or5x) {
  4794. if (b43_is_40mhz(dev)) {
  4795. b43_ntab_write_bulk(dev, B43_NTAB16(15, 0), 18,
  4796. tbl_tx_iqlo_cal_loft_ladder_40);
  4797. b43_ntab_write_bulk(dev, B43_NTAB16(15, 32), 18,
  4798. tbl_tx_iqlo_cal_iqimb_ladder_40);
  4799. } else {
  4800. b43_ntab_write_bulk(dev, B43_NTAB16(15, 0), 18,
  4801. tbl_tx_iqlo_cal_loft_ladder_20);
  4802. b43_ntab_write_bulk(dev, B43_NTAB16(15, 32), 18,
  4803. tbl_tx_iqlo_cal_iqimb_ladder_20);
  4804. }
  4805. }
  4806. if (phy->rev >= 19) {
  4807. /* TODO */
  4808. } else if (phy->rev >= 7) {
  4809. b43_phy_write(dev, B43_NPHY_IQLOCAL_CMDGCTL, 0x8AD9);
  4810. } else {
  4811. b43_phy_write(dev, B43_NPHY_IQLOCAL_CMDGCTL, 0x8AA9);
  4812. }
  4813. if (!b43_is_40mhz(dev))
  4814. freq = 2500;
  4815. else
  4816. freq = 5000;
  4817. if (nphy->mphase_cal_phase_id > 2)
  4818. b43_nphy_run_samples(dev, (b43_is_40mhz(dev) ? 40 : 20) * 8,
  4819. 0xFFFF, 0, true, false, false);
  4820. else
  4821. error = b43_nphy_tx_tone(dev, freq, 250, true, false, false);
  4822. if (error == 0) {
  4823. if (nphy->mphase_cal_phase_id > 2) {
  4824. table = nphy->mphase_txcal_bestcoeffs;
  4825. length = 11;
  4826. if (dev->phy.rev < 3)
  4827. length -= 2;
  4828. } else {
  4829. if (!full && nphy->txiqlocal_coeffsvalid) {
  4830. table = nphy->txiqlocal_bestc;
  4831. length = 11;
  4832. if (dev->phy.rev < 3)
  4833. length -= 2;
  4834. } else {
  4835. full = true;
  4836. if (dev->phy.rev >= 3) {
  4837. table = tbl_tx_iqlo_cal_startcoefs_nphyrev3;
  4838. length = B43_NTAB_TX_IQLO_CAL_STARTCOEFS_REV3;
  4839. } else {
  4840. table = tbl_tx_iqlo_cal_startcoefs;
  4841. length = B43_NTAB_TX_IQLO_CAL_STARTCOEFS;
  4842. }
  4843. }
  4844. }
  4845. b43_ntab_write_bulk(dev, B43_NTAB16(15, 64), length, table);
  4846. if (full) {
  4847. if (dev->phy.rev >= 3)
  4848. max = B43_NTAB_TX_IQLO_CAL_CMDS_FULLCAL_REV3;
  4849. else
  4850. max = B43_NTAB_TX_IQLO_CAL_CMDS_FULLCAL;
  4851. } else {
  4852. if (dev->phy.rev >= 3)
  4853. max = B43_NTAB_TX_IQLO_CAL_CMDS_RECAL_REV3;
  4854. else
  4855. max = B43_NTAB_TX_IQLO_CAL_CMDS_RECAL;
  4856. }
  4857. if (mphase) {
  4858. count = nphy->mphase_txcal_cmdidx;
  4859. numb = min(max,
  4860. (u16)(count + nphy->mphase_txcal_numcmds));
  4861. } else {
  4862. count = 0;
  4863. numb = max;
  4864. }
  4865. for (; count < numb; count++) {
  4866. if (full) {
  4867. if (dev->phy.rev >= 3)
  4868. cmd = tbl_tx_iqlo_cal_cmds_fullcal_nphyrev3[count];
  4869. else
  4870. cmd = tbl_tx_iqlo_cal_cmds_fullcal[count];
  4871. } else {
  4872. if (dev->phy.rev >= 3)
  4873. cmd = tbl_tx_iqlo_cal_cmds_recal_nphyrev3[count];
  4874. else
  4875. cmd = tbl_tx_iqlo_cal_cmds_recal[count];
  4876. }
  4877. core = (cmd & 0x3000) >> 12;
  4878. type = (cmd & 0x0F00) >> 8;
  4879. if (phy6or5x && updated[core] == 0) {
  4880. b43_nphy_update_tx_cal_ladder(dev, core);
  4881. updated[core] = true;
  4882. }
  4883. tmp = (params[core].ncorr[type] << 8) | 0x66;
  4884. b43_phy_write(dev, B43_NPHY_IQLOCAL_CMDNNUM, tmp);
  4885. if (type == 1 || type == 3 || type == 4) {
  4886. buffer[0] = b43_ntab_read(dev,
  4887. B43_NTAB16(15, 69 + core));
  4888. diq_start = buffer[0];
  4889. buffer[0] = 0;
  4890. b43_ntab_write(dev, B43_NTAB16(15, 69 + core),
  4891. 0);
  4892. }
  4893. b43_phy_write(dev, B43_NPHY_IQLOCAL_CMD, cmd);
  4894. for (i = 0; i < 2000; i++) {
  4895. tmp = b43_phy_read(dev, B43_NPHY_IQLOCAL_CMD);
  4896. if (tmp & 0xC000)
  4897. break;
  4898. udelay(10);
  4899. }
  4900. b43_ntab_read_bulk(dev, B43_NTAB16(15, 96), length,
  4901. buffer);
  4902. b43_ntab_write_bulk(dev, B43_NTAB16(15, 64), length,
  4903. buffer);
  4904. if (type == 1 || type == 3 || type == 4)
  4905. buffer[0] = diq_start;
  4906. }
  4907. if (mphase)
  4908. nphy->mphase_txcal_cmdidx = (numb >= max) ? 0 : numb;
  4909. last = (dev->phy.rev < 3) ? 6 : 7;
  4910. if (!mphase || nphy->mphase_cal_phase_id == last) {
  4911. b43_ntab_write_bulk(dev, B43_NTAB16(15, 96), 4, buffer);
  4912. b43_ntab_read_bulk(dev, B43_NTAB16(15, 80), 4, buffer);
  4913. if (dev->phy.rev < 3) {
  4914. buffer[0] = 0;
  4915. buffer[1] = 0;
  4916. buffer[2] = 0;
  4917. buffer[3] = 0;
  4918. }
  4919. b43_ntab_write_bulk(dev, B43_NTAB16(15, 88), 4,
  4920. buffer);
  4921. b43_ntab_read_bulk(dev, B43_NTAB16(15, 101), 2,
  4922. buffer);
  4923. b43_ntab_write_bulk(dev, B43_NTAB16(15, 85), 2,
  4924. buffer);
  4925. b43_ntab_write_bulk(dev, B43_NTAB16(15, 93), 2,
  4926. buffer);
  4927. length = 11;
  4928. if (dev->phy.rev < 3)
  4929. length -= 2;
  4930. b43_ntab_read_bulk(dev, B43_NTAB16(15, 96), length,
  4931. nphy->txiqlocal_bestc);
  4932. nphy->txiqlocal_coeffsvalid = true;
  4933. nphy->txiqlocal_chanspec.center_freq =
  4934. phy->chandef->chan->center_freq;
  4935. nphy->txiqlocal_chanspec.channel_type =
  4936. cfg80211_get_chandef_type(phy->chandef);
  4937. } else {
  4938. length = 11;
  4939. if (dev->phy.rev < 3)
  4940. length -= 2;
  4941. b43_ntab_read_bulk(dev, B43_NTAB16(15, 96), length,
  4942. nphy->mphase_txcal_bestcoeffs);
  4943. }
  4944. b43_nphy_stop_playback(dev);
  4945. b43_phy_write(dev, B43_NPHY_IQLOCAL_CMDGCTL, 0);
  4946. }
  4947. b43_nphy_tx_cal_phy_cleanup(dev);
  4948. b43_ntab_write_bulk(dev, B43_NTAB16(7, 0x110), 2, save);
  4949. if (dev->phy.rev < 2 && (!mphase || nphy->mphase_cal_phase_id == last))
  4950. b43_nphy_tx_iq_workaround(dev);
  4951. if (dev->phy.rev >= 4)
  4952. nphy->hang_avoid = avoid;
  4953. b43_nphy_stay_in_carrier_search(dev, false);
  4954. return error;
  4955. }
  4956. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/ReapplyTxCalCoeffs */
  4957. static void b43_nphy_reapply_tx_cal_coeffs(struct b43_wldev *dev)
  4958. {
  4959. struct b43_phy_n *nphy = dev->phy.n;
  4960. u8 i;
  4961. u16 buffer[7];
  4962. bool equal = true;
  4963. if (!nphy->txiqlocal_coeffsvalid ||
  4964. nphy->txiqlocal_chanspec.center_freq != dev->phy.chandef->chan->center_freq ||
  4965. nphy->txiqlocal_chanspec.channel_type != cfg80211_get_chandef_type(dev->phy.chandef))
  4966. return;
  4967. b43_ntab_read_bulk(dev, B43_NTAB16(15, 80), 7, buffer);
  4968. for (i = 0; i < 4; i++) {
  4969. if (buffer[i] != nphy->txiqlocal_bestc[i]) {
  4970. equal = false;
  4971. break;
  4972. }
  4973. }
  4974. if (!equal) {
  4975. b43_ntab_write_bulk(dev, B43_NTAB16(15, 80), 4,
  4976. nphy->txiqlocal_bestc);
  4977. for (i = 0; i < 4; i++)
  4978. buffer[i] = 0;
  4979. b43_ntab_write_bulk(dev, B43_NTAB16(15, 88), 4,
  4980. buffer);
  4981. b43_ntab_write_bulk(dev, B43_NTAB16(15, 85), 2,
  4982. &nphy->txiqlocal_bestc[5]);
  4983. b43_ntab_write_bulk(dev, B43_NTAB16(15, 93), 2,
  4984. &nphy->txiqlocal_bestc[5]);
  4985. }
  4986. }
  4987. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/CalRxIqRev2 */
  4988. static int b43_nphy_rev2_cal_rx_iq(struct b43_wldev *dev,
  4989. struct nphy_txgains target, u8 type, bool debug)
  4990. {
  4991. struct b43_phy_n *nphy = dev->phy.n;
  4992. int i, j, index;
  4993. u8 rfctl[2];
  4994. u8 afectl_core;
  4995. u16 tmp[6];
  4996. u16 uninitialized_var(cur_hpf1), uninitialized_var(cur_hpf2), cur_lna;
  4997. u32 real, imag;
  4998. enum nl80211_band band;
  4999. u8 use;
  5000. u16 cur_hpf;
  5001. u16 lna[3] = { 3, 3, 1 };
  5002. u16 hpf1[3] = { 7, 2, 0 };
  5003. u16 hpf2[3] = { 2, 0, 0 };
  5004. u32 power[3] = { };
  5005. u16 gain_save[2];
  5006. u16 cal_gain[2];
  5007. struct nphy_iqcal_params cal_params[2];
  5008. struct nphy_iq_est est;
  5009. int ret = 0;
  5010. bool playtone = true;
  5011. int desired = 13;
  5012. b43_nphy_stay_in_carrier_search(dev, 1);
  5013. if (dev->phy.rev < 2)
  5014. b43_nphy_reapply_tx_cal_coeffs(dev);
  5015. b43_ntab_read_bulk(dev, B43_NTAB16(7, 0x110), 2, gain_save);
  5016. for (i = 0; i < 2; i++) {
  5017. b43_nphy_iq_cal_gain_params(dev, i, target, &cal_params[i]);
  5018. cal_gain[i] = cal_params[i].cal_gain;
  5019. }
  5020. b43_ntab_write_bulk(dev, B43_NTAB16(7, 0x110), 2, cal_gain);
  5021. for (i = 0; i < 2; i++) {
  5022. if (i == 0) {
  5023. rfctl[0] = B43_NPHY_RFCTL_INTC1;
  5024. rfctl[1] = B43_NPHY_RFCTL_INTC2;
  5025. afectl_core = B43_NPHY_AFECTL_C1;
  5026. } else {
  5027. rfctl[0] = B43_NPHY_RFCTL_INTC2;
  5028. rfctl[1] = B43_NPHY_RFCTL_INTC1;
  5029. afectl_core = B43_NPHY_AFECTL_C2;
  5030. }
  5031. tmp[1] = b43_phy_read(dev, B43_NPHY_RFSEQCA);
  5032. tmp[2] = b43_phy_read(dev, afectl_core);
  5033. tmp[3] = b43_phy_read(dev, B43_NPHY_AFECTL_OVER);
  5034. tmp[4] = b43_phy_read(dev, rfctl[0]);
  5035. tmp[5] = b43_phy_read(dev, rfctl[1]);
  5036. b43_phy_maskset(dev, B43_NPHY_RFSEQCA,
  5037. ~B43_NPHY_RFSEQCA_RXDIS & 0xFFFF,
  5038. ((1 - i) << B43_NPHY_RFSEQCA_RXDIS_SHIFT));
  5039. b43_phy_maskset(dev, B43_NPHY_RFSEQCA, ~B43_NPHY_RFSEQCA_TXEN,
  5040. (1 - i));
  5041. b43_phy_set(dev, afectl_core, 0x0006);
  5042. b43_phy_set(dev, B43_NPHY_AFECTL_OVER, 0x0006);
  5043. band = b43_current_band(dev->wl);
  5044. if (nphy->rxcalparams & 0xFF000000) {
  5045. if (band == NL80211_BAND_5GHZ)
  5046. b43_phy_write(dev, rfctl[0], 0x140);
  5047. else
  5048. b43_phy_write(dev, rfctl[0], 0x110);
  5049. } else {
  5050. if (band == NL80211_BAND_5GHZ)
  5051. b43_phy_write(dev, rfctl[0], 0x180);
  5052. else
  5053. b43_phy_write(dev, rfctl[0], 0x120);
  5054. }
  5055. if (band == NL80211_BAND_5GHZ)
  5056. b43_phy_write(dev, rfctl[1], 0x148);
  5057. else
  5058. b43_phy_write(dev, rfctl[1], 0x114);
  5059. if (nphy->rxcalparams & 0x10000) {
  5060. b43_radio_maskset(dev, B2055_C1_GENSPARE2, 0xFC,
  5061. (i + 1));
  5062. b43_radio_maskset(dev, B2055_C2_GENSPARE2, 0xFC,
  5063. (2 - i));
  5064. }
  5065. for (j = 0; j < 4; j++) {
  5066. if (j < 3) {
  5067. cur_lna = lna[j];
  5068. cur_hpf1 = hpf1[j];
  5069. cur_hpf2 = hpf2[j];
  5070. } else {
  5071. if (power[1] > 10000) {
  5072. use = 1;
  5073. cur_hpf = cur_hpf1;
  5074. index = 2;
  5075. } else {
  5076. if (power[0] > 10000) {
  5077. use = 1;
  5078. cur_hpf = cur_hpf1;
  5079. index = 1;
  5080. } else {
  5081. index = 0;
  5082. use = 2;
  5083. cur_hpf = cur_hpf2;
  5084. }
  5085. }
  5086. cur_lna = lna[index];
  5087. cur_hpf1 = hpf1[index];
  5088. cur_hpf2 = hpf2[index];
  5089. cur_hpf += desired - hweight32(power[index]);
  5090. cur_hpf = clamp_val(cur_hpf, 0, 10);
  5091. if (use == 1)
  5092. cur_hpf1 = cur_hpf;
  5093. else
  5094. cur_hpf2 = cur_hpf;
  5095. }
  5096. tmp[0] = ((cur_hpf2 << 8) | (cur_hpf1 << 4) |
  5097. (cur_lna << 2));
  5098. b43_nphy_rf_ctl_override(dev, 0x400, tmp[0], 3,
  5099. false);
  5100. b43_nphy_force_rf_sequence(dev, B43_RFSEQ_RESET2RX);
  5101. b43_nphy_stop_playback(dev);
  5102. if (playtone) {
  5103. ret = b43_nphy_tx_tone(dev, 4000,
  5104. (nphy->rxcalparams & 0xFFFF),
  5105. false, false, true);
  5106. playtone = false;
  5107. } else {
  5108. b43_nphy_run_samples(dev, 160, 0xFFFF, 0, false,
  5109. false, true);
  5110. }
  5111. if (ret == 0) {
  5112. if (j < 3) {
  5113. b43_nphy_rx_iq_est(dev, &est, 1024, 32,
  5114. false);
  5115. if (i == 0) {
  5116. real = est.i0_pwr;
  5117. imag = est.q0_pwr;
  5118. } else {
  5119. real = est.i1_pwr;
  5120. imag = est.q1_pwr;
  5121. }
  5122. power[i] = ((real + imag) / 1024) + 1;
  5123. } else {
  5124. b43_nphy_calc_rx_iq_comp(dev, 1 << i);
  5125. }
  5126. b43_nphy_stop_playback(dev);
  5127. }
  5128. if (ret != 0)
  5129. break;
  5130. }
  5131. b43_radio_mask(dev, B2055_C1_GENSPARE2, 0xFC);
  5132. b43_radio_mask(dev, B2055_C2_GENSPARE2, 0xFC);
  5133. b43_phy_write(dev, rfctl[1], tmp[5]);
  5134. b43_phy_write(dev, rfctl[0], tmp[4]);
  5135. b43_phy_write(dev, B43_NPHY_AFECTL_OVER, tmp[3]);
  5136. b43_phy_write(dev, afectl_core, tmp[2]);
  5137. b43_phy_write(dev, B43_NPHY_RFSEQCA, tmp[1]);
  5138. if (ret != 0)
  5139. break;
  5140. }
  5141. b43_nphy_rf_ctl_override(dev, 0x400, 0, 3, true);
  5142. b43_nphy_force_rf_sequence(dev, B43_RFSEQ_RESET2RX);
  5143. b43_ntab_write_bulk(dev, B43_NTAB16(7, 0x110), 2, gain_save);
  5144. b43_nphy_stay_in_carrier_search(dev, 0);
  5145. return ret;
  5146. }
  5147. static int b43_nphy_rev3_cal_rx_iq(struct b43_wldev *dev,
  5148. struct nphy_txgains target, u8 type, bool debug)
  5149. {
  5150. return -1;
  5151. }
  5152. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/CalRxIq */
  5153. static int b43_nphy_cal_rx_iq(struct b43_wldev *dev,
  5154. struct nphy_txgains target, u8 type, bool debug)
  5155. {
  5156. if (dev->phy.rev >= 7)
  5157. type = 0;
  5158. if (dev->phy.rev >= 3)
  5159. return b43_nphy_rev3_cal_rx_iq(dev, target, type, debug);
  5160. else
  5161. return b43_nphy_rev2_cal_rx_iq(dev, target, type, debug);
  5162. }
  5163. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/RxCoreSetState */
  5164. static void b43_nphy_set_rx_core_state(struct b43_wldev *dev, u8 mask)
  5165. {
  5166. struct b43_phy *phy = &dev->phy;
  5167. struct b43_phy_n *nphy = phy->n;
  5168. /* u16 buf[16]; it's rev3+ */
  5169. nphy->phyrxchain = mask;
  5170. if (0 /* FIXME clk */)
  5171. return;
  5172. b43_mac_suspend(dev);
  5173. if (nphy->hang_avoid)
  5174. b43_nphy_stay_in_carrier_search(dev, true);
  5175. b43_phy_maskset(dev, B43_NPHY_RFSEQCA, ~B43_NPHY_RFSEQCA_RXEN,
  5176. (mask & 0x3) << B43_NPHY_RFSEQCA_RXEN_SHIFT);
  5177. if ((mask & 0x3) != 0x3) {
  5178. b43_phy_write(dev, B43_NPHY_HPANT_SWTHRES, 1);
  5179. if (dev->phy.rev >= 3) {
  5180. /* TODO */
  5181. }
  5182. } else {
  5183. b43_phy_write(dev, B43_NPHY_HPANT_SWTHRES, 0x1E);
  5184. if (dev->phy.rev >= 3) {
  5185. /* TODO */
  5186. }
  5187. }
  5188. b43_nphy_force_rf_sequence(dev, B43_RFSEQ_RESET2RX);
  5189. if (nphy->hang_avoid)
  5190. b43_nphy_stay_in_carrier_search(dev, false);
  5191. b43_mac_enable(dev);
  5192. }
  5193. static enum b43_txpwr_result b43_nphy_op_recalc_txpower(struct b43_wldev *dev,
  5194. bool ignore_tssi)
  5195. {
  5196. struct b43_phy *phy = &dev->phy;
  5197. struct b43_phy_n *nphy = dev->phy.n;
  5198. struct ieee80211_channel *channel = dev->wl->hw->conf.chandef.chan;
  5199. struct b43_ppr *ppr = &nphy->tx_pwr_max_ppr;
  5200. u8 max; /* qdBm */
  5201. bool tx_pwr_state;
  5202. if (nphy->tx_pwr_last_recalc_freq == channel->center_freq &&
  5203. nphy->tx_pwr_last_recalc_limit == phy->desired_txpower)
  5204. return B43_TXPWR_RES_DONE;
  5205. /* Make sure we have a clean PPR */
  5206. b43_ppr_clear(dev, ppr);
  5207. /* HW limitations */
  5208. b43_ppr_load_max_from_sprom(dev, ppr, B43_BAND_2G);
  5209. /* Regulatory & user settings */
  5210. max = INT_TO_Q52(phy->chandef->chan->max_power);
  5211. if (phy->desired_txpower)
  5212. max = min_t(u8, max, INT_TO_Q52(phy->desired_txpower));
  5213. b43_ppr_apply_max(dev, ppr, max);
  5214. if (b43_debug(dev, B43_DBG_XMITPOWER))
  5215. b43dbg(dev->wl, "Calculated TX power: " Q52_FMT "\n",
  5216. Q52_ARG(b43_ppr_get_max(dev, ppr)));
  5217. /* TODO: Enable this once we get gains working */
  5218. #if 0
  5219. /* Some extra gains */
  5220. hw_gain = 6; /* N-PHY specific */
  5221. if (b43_current_band(dev->wl) == NL80211_BAND_2GHZ)
  5222. hw_gain += sprom->antenna_gain.a0;
  5223. else
  5224. hw_gain += sprom->antenna_gain.a1;
  5225. b43_ppr_add(dev, ppr, -hw_gain);
  5226. #endif
  5227. /* Make sure we didn't go too low */
  5228. b43_ppr_apply_min(dev, ppr, INT_TO_Q52(8));
  5229. /* Apply */
  5230. tx_pwr_state = nphy->txpwrctrl;
  5231. b43_mac_suspend(dev);
  5232. b43_nphy_tx_power_ctl_setup(dev);
  5233. if (dev->dev->core_rev == 11 || dev->dev->core_rev == 12) {
  5234. b43_maskset32(dev, B43_MMIO_MACCTL, ~0, B43_MACCTL_PHY_LOCK);
  5235. b43_read32(dev, B43_MMIO_MACCTL);
  5236. udelay(1);
  5237. }
  5238. b43_nphy_tx_power_ctrl(dev, nphy->txpwrctrl);
  5239. if (dev->dev->core_rev == 11 || dev->dev->core_rev == 12)
  5240. b43_maskset32(dev, B43_MMIO_MACCTL, ~B43_MACCTL_PHY_LOCK, 0);
  5241. b43_mac_enable(dev);
  5242. nphy->tx_pwr_last_recalc_freq = channel->center_freq;
  5243. nphy->tx_pwr_last_recalc_limit = phy->desired_txpower;
  5244. return B43_TXPWR_RES_DONE;
  5245. }
  5246. /**************************************************
  5247. * N-PHY init
  5248. **************************************************/
  5249. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/MIMOConfig */
  5250. static void b43_nphy_update_mimo_config(struct b43_wldev *dev, s32 preamble)
  5251. {
  5252. u16 mimocfg = b43_phy_read(dev, B43_NPHY_MIMOCFG);
  5253. mimocfg |= B43_NPHY_MIMOCFG_AUTO;
  5254. if (preamble == 1)
  5255. mimocfg |= B43_NPHY_MIMOCFG_GFMIX;
  5256. else
  5257. mimocfg &= ~B43_NPHY_MIMOCFG_GFMIX;
  5258. b43_phy_write(dev, B43_NPHY_MIMOCFG, mimocfg);
  5259. }
  5260. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/BPHYInit */
  5261. static void b43_nphy_bphy_init(struct b43_wldev *dev)
  5262. {
  5263. unsigned int i;
  5264. u16 val;
  5265. val = 0x1E1F;
  5266. for (i = 0; i < 16; i++) {
  5267. b43_phy_write(dev, B43_PHY_N_BMODE(0x88 + i), val);
  5268. val -= 0x202;
  5269. }
  5270. val = 0x3E3F;
  5271. for (i = 0; i < 16; i++) {
  5272. b43_phy_write(dev, B43_PHY_N_BMODE(0x98 + i), val);
  5273. val -= 0x202;
  5274. }
  5275. b43_phy_write(dev, B43_PHY_N_BMODE(0x38), 0x668);
  5276. }
  5277. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/SuperSwitchInit */
  5278. static void b43_nphy_superswitch_init(struct b43_wldev *dev, bool init)
  5279. {
  5280. if (dev->phy.rev >= 7)
  5281. return;
  5282. if (dev->phy.rev >= 3) {
  5283. if (!init)
  5284. return;
  5285. if (0 /* FIXME */) {
  5286. b43_ntab_write(dev, B43_NTAB16(9, 2), 0x211);
  5287. b43_ntab_write(dev, B43_NTAB16(9, 3), 0x222);
  5288. b43_ntab_write(dev, B43_NTAB16(9, 8), 0x144);
  5289. b43_ntab_write(dev, B43_NTAB16(9, 12), 0x188);
  5290. }
  5291. } else {
  5292. b43_phy_write(dev, B43_NPHY_GPIO_LOOEN, 0);
  5293. b43_phy_write(dev, B43_NPHY_GPIO_HIOEN, 0);
  5294. switch (dev->dev->bus_type) {
  5295. #ifdef CONFIG_B43_BCMA
  5296. case B43_BUS_BCMA:
  5297. bcma_chipco_gpio_control(&dev->dev->bdev->bus->drv_cc,
  5298. 0xFC00, 0xFC00);
  5299. break;
  5300. #endif
  5301. #ifdef CONFIG_B43_SSB
  5302. case B43_BUS_SSB:
  5303. ssb_chipco_gpio_control(&dev->dev->sdev->bus->chipco,
  5304. 0xFC00, 0xFC00);
  5305. break;
  5306. #endif
  5307. }
  5308. b43_maskset32(dev, B43_MMIO_MACCTL, ~B43_MACCTL_GPOUTSMSK, 0);
  5309. b43_maskset16(dev, B43_MMIO_GPIO_MASK, ~0, 0xFC00);
  5310. b43_maskset16(dev, B43_MMIO_GPIO_CONTROL, (~0xFC00 & 0xFFFF),
  5311. 0);
  5312. if (init) {
  5313. b43_phy_write(dev, B43_NPHY_RFCTL_LUT_TRSW_LO1, 0x2D8);
  5314. b43_phy_write(dev, B43_NPHY_RFCTL_LUT_TRSW_UP1, 0x301);
  5315. b43_phy_write(dev, B43_NPHY_RFCTL_LUT_TRSW_LO2, 0x2D8);
  5316. b43_phy_write(dev, B43_NPHY_RFCTL_LUT_TRSW_UP2, 0x301);
  5317. }
  5318. }
  5319. }
  5320. /* http://bcm-v4.sipsolutions.net/802.11/PHY/Init/N */
  5321. static int b43_phy_initn(struct b43_wldev *dev)
  5322. {
  5323. struct ssb_sprom *sprom = dev->dev->bus_sprom;
  5324. struct b43_phy *phy = &dev->phy;
  5325. struct b43_phy_n *nphy = phy->n;
  5326. u8 tx_pwr_state;
  5327. struct nphy_txgains target;
  5328. u16 tmp;
  5329. enum nl80211_band tmp2;
  5330. bool do_rssi_cal;
  5331. u16 clip[2];
  5332. bool do_cal = false;
  5333. if ((dev->phy.rev >= 3) &&
  5334. (sprom->boardflags_lo & B43_BFL_EXTLNA) &&
  5335. (b43_current_band(dev->wl) == NL80211_BAND_2GHZ)) {
  5336. switch (dev->dev->bus_type) {
  5337. #ifdef CONFIG_B43_BCMA
  5338. case B43_BUS_BCMA:
  5339. bcma_cc_set32(&dev->dev->bdev->bus->drv_cc,
  5340. BCMA_CC_CHIPCTL, 0x40);
  5341. break;
  5342. #endif
  5343. #ifdef CONFIG_B43_SSB
  5344. case B43_BUS_SSB:
  5345. chipco_set32(&dev->dev->sdev->bus->chipco,
  5346. SSB_CHIPCO_CHIPCTL, 0x40);
  5347. break;
  5348. #endif
  5349. }
  5350. }
  5351. nphy->use_int_tx_iq_lo_cal = b43_nphy_ipa(dev) ||
  5352. phy->rev >= 7 ||
  5353. (phy->rev >= 5 &&
  5354. sprom->boardflags2_hi & B43_BFH2_INTERNDET_TXIQCAL);
  5355. nphy->deaf_count = 0;
  5356. b43_nphy_tables_init(dev);
  5357. nphy->crsminpwr_adjusted = false;
  5358. nphy->noisevars_adjusted = false;
  5359. /* Clear all overrides */
  5360. if (dev->phy.rev >= 3) {
  5361. b43_phy_write(dev, B43_NPHY_TXF_40CO_B1S1, 0);
  5362. b43_phy_write(dev, B43_NPHY_RFCTL_OVER, 0);
  5363. if (phy->rev >= 7) {
  5364. b43_phy_write(dev, B43_NPHY_REV7_RF_CTL_OVER3, 0);
  5365. b43_phy_write(dev, B43_NPHY_REV7_RF_CTL_OVER4, 0);
  5366. b43_phy_write(dev, B43_NPHY_REV7_RF_CTL_OVER5, 0);
  5367. b43_phy_write(dev, B43_NPHY_REV7_RF_CTL_OVER6, 0);
  5368. }
  5369. if (phy->rev >= 19) {
  5370. /* TODO */
  5371. }
  5372. b43_phy_write(dev, B43_NPHY_TXF_40CO_B1S0, 0);
  5373. b43_phy_write(dev, B43_NPHY_TXF_40CO_B32S1, 0);
  5374. } else {
  5375. b43_phy_write(dev, B43_NPHY_RFCTL_OVER, 0);
  5376. }
  5377. b43_phy_write(dev, B43_NPHY_RFCTL_INTC1, 0);
  5378. b43_phy_write(dev, B43_NPHY_RFCTL_INTC2, 0);
  5379. if (dev->phy.rev < 6) {
  5380. b43_phy_write(dev, B43_NPHY_RFCTL_INTC3, 0);
  5381. b43_phy_write(dev, B43_NPHY_RFCTL_INTC4, 0);
  5382. }
  5383. b43_phy_mask(dev, B43_NPHY_RFSEQMODE,
  5384. ~(B43_NPHY_RFSEQMODE_CAOVER |
  5385. B43_NPHY_RFSEQMODE_TROVER));
  5386. if (dev->phy.rev >= 3)
  5387. b43_phy_write(dev, B43_NPHY_AFECTL_OVER1, 0);
  5388. b43_phy_write(dev, B43_NPHY_AFECTL_OVER, 0);
  5389. if (dev->phy.rev <= 2) {
  5390. tmp = (dev->phy.rev == 2) ? 0x3B : 0x40;
  5391. b43_phy_maskset(dev, B43_NPHY_BPHY_CTL3,
  5392. ~B43_NPHY_BPHY_CTL3_SCALE,
  5393. tmp << B43_NPHY_BPHY_CTL3_SCALE_SHIFT);
  5394. }
  5395. b43_phy_write(dev, B43_NPHY_AFESEQ_TX2RX_PUD_20M, 0x20);
  5396. b43_phy_write(dev, B43_NPHY_AFESEQ_TX2RX_PUD_40M, 0x20);
  5397. if (sprom->boardflags2_lo & B43_BFL2_SKWRKFEM_BRD ||
  5398. (dev->dev->board_vendor == PCI_VENDOR_ID_APPLE &&
  5399. dev->dev->board_type == BCMA_BOARD_TYPE_BCM943224M93))
  5400. b43_phy_write(dev, B43_NPHY_TXREALFD, 0xA0);
  5401. else
  5402. b43_phy_write(dev, B43_NPHY_TXREALFD, 0xB8);
  5403. b43_phy_write(dev, B43_NPHY_MIMO_CRSTXEXT, 0xC8);
  5404. b43_phy_write(dev, B43_NPHY_PLOAD_CSENSE_EXTLEN, 0x50);
  5405. b43_phy_write(dev, B43_NPHY_TXRIFS_FRDEL, 0x30);
  5406. if (phy->rev < 8)
  5407. b43_nphy_update_mimo_config(dev, nphy->preamble_override);
  5408. b43_nphy_update_txrx_chain(dev);
  5409. if (phy->rev < 2) {
  5410. b43_phy_write(dev, B43_NPHY_DUP40_GFBL, 0xAA8);
  5411. b43_phy_write(dev, B43_NPHY_DUP40_BL, 0x9A4);
  5412. }
  5413. tmp2 = b43_current_band(dev->wl);
  5414. if (b43_nphy_ipa(dev)) {
  5415. b43_phy_set(dev, B43_NPHY_PAPD_EN0, 0x1);
  5416. b43_phy_maskset(dev, B43_NPHY_EPS_TABLE_ADJ0, 0x007F,
  5417. nphy->papd_epsilon_offset[0] << 7);
  5418. b43_phy_set(dev, B43_NPHY_PAPD_EN1, 0x1);
  5419. b43_phy_maskset(dev, B43_NPHY_EPS_TABLE_ADJ1, 0x007F,
  5420. nphy->papd_epsilon_offset[1] << 7);
  5421. b43_nphy_int_pa_set_tx_dig_filters(dev);
  5422. } else if (phy->rev >= 5) {
  5423. b43_nphy_ext_pa_set_tx_dig_filters(dev);
  5424. }
  5425. b43_nphy_workarounds(dev);
  5426. /* Reset CCA, in init code it differs a little from standard way */
  5427. b43_phy_force_clock(dev, 1);
  5428. tmp = b43_phy_read(dev, B43_NPHY_BBCFG);
  5429. b43_phy_write(dev, B43_NPHY_BBCFG, tmp | B43_NPHY_BBCFG_RSTCCA);
  5430. b43_phy_write(dev, B43_NPHY_BBCFG, tmp & ~B43_NPHY_BBCFG_RSTCCA);
  5431. b43_phy_force_clock(dev, 0);
  5432. b43_mac_phy_clock_set(dev, true);
  5433. if (phy->rev < 7) {
  5434. b43_nphy_pa_override(dev, false);
  5435. b43_nphy_force_rf_sequence(dev, B43_RFSEQ_RX2TX);
  5436. b43_nphy_force_rf_sequence(dev, B43_RFSEQ_RESET2RX);
  5437. b43_nphy_pa_override(dev, true);
  5438. }
  5439. b43_nphy_classifier(dev, 0, 0);
  5440. b43_nphy_read_clip_detection(dev, clip);
  5441. if (b43_current_band(dev->wl) == NL80211_BAND_2GHZ)
  5442. b43_nphy_bphy_init(dev);
  5443. tx_pwr_state = nphy->txpwrctrl;
  5444. b43_nphy_tx_power_ctrl(dev, false);
  5445. b43_nphy_tx_power_fix(dev);
  5446. b43_nphy_tx_power_ctl_idle_tssi(dev);
  5447. b43_nphy_tx_power_ctl_setup(dev);
  5448. b43_nphy_tx_gain_table_upload(dev);
  5449. if (nphy->phyrxchain != 3)
  5450. b43_nphy_set_rx_core_state(dev, nphy->phyrxchain);
  5451. if (nphy->mphase_cal_phase_id > 0)
  5452. ;/* TODO PHY Periodic Calibration Multi-Phase Restart */
  5453. do_rssi_cal = false;
  5454. if (phy->rev >= 3) {
  5455. if (b43_current_band(dev->wl) == NL80211_BAND_2GHZ)
  5456. do_rssi_cal = !nphy->rssical_chanspec_2G.center_freq;
  5457. else
  5458. do_rssi_cal = !nphy->rssical_chanspec_5G.center_freq;
  5459. if (do_rssi_cal)
  5460. b43_nphy_rssi_cal(dev);
  5461. else
  5462. b43_nphy_restore_rssi_cal(dev);
  5463. } else {
  5464. b43_nphy_rssi_cal(dev);
  5465. }
  5466. if (!((nphy->measure_hold & 0x6) != 0)) {
  5467. if (b43_current_band(dev->wl) == NL80211_BAND_2GHZ)
  5468. do_cal = !nphy->iqcal_chanspec_2G.center_freq;
  5469. else
  5470. do_cal = !nphy->iqcal_chanspec_5G.center_freq;
  5471. if (nphy->mute)
  5472. do_cal = false;
  5473. if (do_cal) {
  5474. target = b43_nphy_get_tx_gains(dev);
  5475. if (nphy->antsel_type == 2)
  5476. b43_nphy_superswitch_init(dev, true);
  5477. if (nphy->perical != 2) {
  5478. b43_nphy_rssi_cal(dev);
  5479. if (phy->rev >= 3) {
  5480. nphy->cal_orig_pwr_idx[0] =
  5481. nphy->txpwrindex[0].index_internal;
  5482. nphy->cal_orig_pwr_idx[1] =
  5483. nphy->txpwrindex[1].index_internal;
  5484. /* TODO N PHY Pre Calibrate TX Gain */
  5485. target = b43_nphy_get_tx_gains(dev);
  5486. }
  5487. if (!b43_nphy_cal_tx_iq_lo(dev, target, true, false))
  5488. if (b43_nphy_cal_rx_iq(dev, target, 2, 0) == 0)
  5489. b43_nphy_save_cal(dev);
  5490. } else if (nphy->mphase_cal_phase_id == 0)
  5491. ;/* N PHY Periodic Calibration with arg 3 */
  5492. } else {
  5493. b43_nphy_restore_cal(dev);
  5494. }
  5495. }
  5496. b43_nphy_tx_pwr_ctrl_coef_setup(dev);
  5497. b43_nphy_tx_power_ctrl(dev, tx_pwr_state);
  5498. b43_phy_write(dev, B43_NPHY_TXMACIF_HOLDOFF, 0x0015);
  5499. b43_phy_write(dev, B43_NPHY_TXMACDELAY, 0x0320);
  5500. if (phy->rev >= 3 && phy->rev <= 6)
  5501. b43_phy_write(dev, B43_NPHY_PLOAD_CSENSE_EXTLEN, 0x0032);
  5502. b43_nphy_tx_lpf_bw(dev);
  5503. if (phy->rev >= 3)
  5504. b43_nphy_spur_workaround(dev);
  5505. return 0;
  5506. }
  5507. /**************************************************
  5508. * Channel switching ops.
  5509. **************************************************/
  5510. static void b43_chantab_phy_upload(struct b43_wldev *dev,
  5511. const struct b43_phy_n_sfo_cfg *e)
  5512. {
  5513. b43_phy_write(dev, B43_NPHY_BW1A, e->phy_bw1a);
  5514. b43_phy_write(dev, B43_NPHY_BW2, e->phy_bw2);
  5515. b43_phy_write(dev, B43_NPHY_BW3, e->phy_bw3);
  5516. b43_phy_write(dev, B43_NPHY_BW4, e->phy_bw4);
  5517. b43_phy_write(dev, B43_NPHY_BW5, e->phy_bw5);
  5518. b43_phy_write(dev, B43_NPHY_BW6, e->phy_bw6);
  5519. }
  5520. /* http://bcm-v4.sipsolutions.net/802.11/PmuSpurAvoid */
  5521. static void b43_nphy_pmu_spur_avoid(struct b43_wldev *dev, bool avoid)
  5522. {
  5523. switch (dev->dev->bus_type) {
  5524. #ifdef CONFIG_B43_BCMA
  5525. case B43_BUS_BCMA:
  5526. bcma_pmu_spuravoid_pllupdate(&dev->dev->bdev->bus->drv_cc,
  5527. avoid);
  5528. break;
  5529. #endif
  5530. #ifdef CONFIG_B43_SSB
  5531. case B43_BUS_SSB:
  5532. ssb_pmu_spuravoid_pllupdate(&dev->dev->sdev->bus->chipco,
  5533. avoid);
  5534. break;
  5535. #endif
  5536. }
  5537. }
  5538. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/ChanspecSetup */
  5539. static void b43_nphy_channel_setup(struct b43_wldev *dev,
  5540. const struct b43_phy_n_sfo_cfg *e,
  5541. struct ieee80211_channel *new_channel)
  5542. {
  5543. struct b43_phy *phy = &dev->phy;
  5544. struct b43_phy_n *nphy = dev->phy.n;
  5545. int ch = new_channel->hw_value;
  5546. u16 tmp16;
  5547. if (new_channel->band == NL80211_BAND_5GHZ) {
  5548. /* Switch to 2 GHz for a moment to access B43_PHY_B_BBCFG */
  5549. b43_phy_mask(dev, B43_NPHY_BANDCTL, ~B43_NPHY_BANDCTL_5GHZ);
  5550. tmp16 = b43_read16(dev, B43_MMIO_PSM_PHY_HDR);
  5551. b43_write16(dev, B43_MMIO_PSM_PHY_HDR, tmp16 | 4);
  5552. /* Put BPHY in the reset */
  5553. b43_phy_set(dev, B43_PHY_B_BBCFG,
  5554. B43_PHY_B_BBCFG_RSTCCA | B43_PHY_B_BBCFG_RSTRX);
  5555. b43_write16(dev, B43_MMIO_PSM_PHY_HDR, tmp16);
  5556. b43_phy_set(dev, B43_NPHY_BANDCTL, B43_NPHY_BANDCTL_5GHZ);
  5557. } else if (new_channel->band == NL80211_BAND_2GHZ) {
  5558. b43_phy_mask(dev, B43_NPHY_BANDCTL, ~B43_NPHY_BANDCTL_5GHZ);
  5559. tmp16 = b43_read16(dev, B43_MMIO_PSM_PHY_HDR);
  5560. b43_write16(dev, B43_MMIO_PSM_PHY_HDR, tmp16 | 4);
  5561. /* Take BPHY out of the reset */
  5562. b43_phy_mask(dev, B43_PHY_B_BBCFG,
  5563. (u16)~(B43_PHY_B_BBCFG_RSTCCA | B43_PHY_B_BBCFG_RSTRX));
  5564. b43_write16(dev, B43_MMIO_PSM_PHY_HDR, tmp16);
  5565. }
  5566. b43_chantab_phy_upload(dev, e);
  5567. if (new_channel->hw_value == 14) {
  5568. b43_nphy_classifier(dev, 2, 0);
  5569. b43_phy_set(dev, B43_PHY_B_TEST, 0x0800);
  5570. } else {
  5571. b43_nphy_classifier(dev, 2, 2);
  5572. if (new_channel->band == NL80211_BAND_2GHZ)
  5573. b43_phy_mask(dev, B43_PHY_B_TEST, ~0x840);
  5574. }
  5575. if (!nphy->txpwrctrl)
  5576. b43_nphy_tx_power_fix(dev);
  5577. if (dev->phy.rev < 3)
  5578. b43_nphy_adjust_lna_gain_table(dev);
  5579. b43_nphy_tx_lpf_bw(dev);
  5580. if (dev->phy.rev >= 3 &&
  5581. dev->phy.n->spur_avoid != B43_SPUR_AVOID_DISABLE) {
  5582. u8 spuravoid = 0;
  5583. if (dev->phy.n->spur_avoid == B43_SPUR_AVOID_FORCE) {
  5584. spuravoid = 1;
  5585. } else if (phy->rev >= 19) {
  5586. /* TODO */
  5587. } else if (phy->rev >= 18) {
  5588. /* TODO */
  5589. } else if (phy->rev >= 17) {
  5590. /* TODO: Off for channels 1-11, but check 12-14! */
  5591. } else if (phy->rev >= 16) {
  5592. /* TODO: Off for 2 GHz, but check 5 GHz! */
  5593. } else if (phy->rev >= 7) {
  5594. if (!b43_is_40mhz(dev)) { /* 20MHz */
  5595. if (ch == 13 || ch == 14 || ch == 153)
  5596. spuravoid = 1;
  5597. } else { /* 40 MHz */
  5598. if (ch == 54)
  5599. spuravoid = 1;
  5600. }
  5601. } else {
  5602. if (!b43_is_40mhz(dev)) { /* 20MHz */
  5603. if ((ch >= 5 && ch <= 8) || ch == 13 || ch == 14)
  5604. spuravoid = 1;
  5605. } else { /* 40MHz */
  5606. if (nphy->aband_spurwar_en &&
  5607. (ch == 38 || ch == 102 || ch == 118))
  5608. spuravoid = dev->dev->chip_id == 0x4716;
  5609. }
  5610. }
  5611. b43_nphy_pmu_spur_avoid(dev, spuravoid);
  5612. b43_mac_switch_freq(dev, spuravoid);
  5613. if (dev->phy.rev == 3 || dev->phy.rev == 4)
  5614. b43_wireless_core_phy_pll_reset(dev);
  5615. if (spuravoid)
  5616. b43_phy_set(dev, B43_NPHY_BBCFG, B43_NPHY_BBCFG_RSTRX);
  5617. else
  5618. b43_phy_mask(dev, B43_NPHY_BBCFG,
  5619. ~B43_NPHY_BBCFG_RSTRX & 0xFFFF);
  5620. b43_nphy_reset_cca(dev);
  5621. /* wl sets useless phy_isspuravoid here */
  5622. }
  5623. b43_phy_write(dev, B43_NPHY_NDATAT_DUP40, 0x3830);
  5624. if (phy->rev >= 3)
  5625. b43_nphy_spur_workaround(dev);
  5626. }
  5627. /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/SetChanspec */
  5628. static int b43_nphy_set_channel(struct b43_wldev *dev,
  5629. struct ieee80211_channel *channel,
  5630. enum nl80211_channel_type channel_type)
  5631. {
  5632. struct b43_phy *phy = &dev->phy;
  5633. const struct b43_nphy_channeltab_entry_rev2 *tabent_r2 = NULL;
  5634. const struct b43_nphy_channeltab_entry_rev3 *tabent_r3 = NULL;
  5635. const struct b43_nphy_chantabent_rev7 *tabent_r7 = NULL;
  5636. const struct b43_nphy_chantabent_rev7_2g *tabent_r7_2g = NULL;
  5637. u8 tmp;
  5638. if (phy->rev >= 19) {
  5639. return -ESRCH;
  5640. /* TODO */
  5641. } else if (phy->rev >= 7) {
  5642. r2057_get_chantabent_rev7(dev, channel->center_freq,
  5643. &tabent_r7, &tabent_r7_2g);
  5644. if (!tabent_r7 && !tabent_r7_2g)
  5645. return -ESRCH;
  5646. } else if (phy->rev >= 3) {
  5647. tabent_r3 = b43_nphy_get_chantabent_rev3(dev,
  5648. channel->center_freq);
  5649. if (!tabent_r3)
  5650. return -ESRCH;
  5651. } else {
  5652. tabent_r2 = b43_nphy_get_chantabent_rev2(dev,
  5653. channel->hw_value);
  5654. if (!tabent_r2)
  5655. return -ESRCH;
  5656. }
  5657. /* Channel is set later in common code, but we need to set it on our
  5658. own to let this function's subcalls work properly. */
  5659. phy->channel = channel->hw_value;
  5660. #if 0
  5661. if (b43_channel_type_is_40mhz(phy->channel_type) !=
  5662. b43_channel_type_is_40mhz(channel_type))
  5663. ; /* TODO: BMAC BW Set (channel_type) */
  5664. #endif
  5665. if (channel_type == NL80211_CHAN_HT40PLUS) {
  5666. b43_phy_set(dev, B43_NPHY_RXCTL, B43_NPHY_RXCTL_BSELU20);
  5667. if (phy->rev >= 7)
  5668. b43_phy_set(dev, 0x310, 0x8000);
  5669. } else if (channel_type == NL80211_CHAN_HT40MINUS) {
  5670. b43_phy_mask(dev, B43_NPHY_RXCTL, ~B43_NPHY_RXCTL_BSELU20);
  5671. if (phy->rev >= 7)
  5672. b43_phy_mask(dev, 0x310, (u16)~0x8000);
  5673. }
  5674. if (phy->rev >= 19) {
  5675. /* TODO */
  5676. } else if (phy->rev >= 7) {
  5677. const struct b43_phy_n_sfo_cfg *phy_regs = tabent_r7 ?
  5678. &(tabent_r7->phy_regs) : &(tabent_r7_2g->phy_regs);
  5679. if (phy->radio_rev <= 4 || phy->radio_rev == 6) {
  5680. tmp = (channel->band == NL80211_BAND_5GHZ) ? 2 : 0;
  5681. b43_radio_maskset(dev, R2057_TIA_CONFIG_CORE0, ~2, tmp);
  5682. b43_radio_maskset(dev, R2057_TIA_CONFIG_CORE1, ~2, tmp);
  5683. }
  5684. b43_radio_2057_setup(dev, tabent_r7, tabent_r7_2g);
  5685. b43_nphy_channel_setup(dev, phy_regs, channel);
  5686. } else if (phy->rev >= 3) {
  5687. tmp = (channel->band == NL80211_BAND_5GHZ) ? 4 : 0;
  5688. b43_radio_maskset(dev, 0x08, 0xFFFB, tmp);
  5689. b43_radio_2056_setup(dev, tabent_r3);
  5690. b43_nphy_channel_setup(dev, &(tabent_r3->phy_regs), channel);
  5691. } else {
  5692. tmp = (channel->band == NL80211_BAND_5GHZ) ? 0x0020 : 0x0050;
  5693. b43_radio_maskset(dev, B2055_MASTER1, 0xFF8F, tmp);
  5694. b43_radio_2055_setup(dev, tabent_r2);
  5695. b43_nphy_channel_setup(dev, &(tabent_r2->phy_regs), channel);
  5696. }
  5697. return 0;
  5698. }
  5699. /**************************************************
  5700. * Basic PHY ops.
  5701. **************************************************/
  5702. static int b43_nphy_op_allocate(struct b43_wldev *dev)
  5703. {
  5704. struct b43_phy_n *nphy;
  5705. nphy = kzalloc(sizeof(*nphy), GFP_KERNEL);
  5706. if (!nphy)
  5707. return -ENOMEM;
  5708. dev->phy.n = nphy;
  5709. return 0;
  5710. }
  5711. static void b43_nphy_op_prepare_structs(struct b43_wldev *dev)
  5712. {
  5713. struct b43_phy *phy = &dev->phy;
  5714. struct b43_phy_n *nphy = phy->n;
  5715. struct ssb_sprom *sprom = dev->dev->bus_sprom;
  5716. memset(nphy, 0, sizeof(*nphy));
  5717. nphy->hang_avoid = (phy->rev == 3 || phy->rev == 4);
  5718. nphy->spur_avoid = (phy->rev >= 3) ?
  5719. B43_SPUR_AVOID_AUTO : B43_SPUR_AVOID_DISABLE;
  5720. nphy->gain_boost = true; /* this way we follow wl, assume it is true */
  5721. nphy->txrx_chain = 2; /* sth different than 0 and 1 for now */
  5722. nphy->phyrxchain = 3; /* to avoid b43_nphy_set_rx_core_state like wl */
  5723. nphy->perical = 2; /* avoid additional rssi cal on init (like wl) */
  5724. /* 128 can mean disabled-by-default state of TX pwr ctl. Max value is
  5725. * 0x7f == 127 and we check for 128 when restoring TX pwr ctl. */
  5726. nphy->tx_pwr_idx[0] = 128;
  5727. nphy->tx_pwr_idx[1] = 128;
  5728. /* Hardware TX power control and 5GHz power gain */
  5729. nphy->txpwrctrl = false;
  5730. nphy->pwg_gain_5ghz = false;
  5731. if (dev->phy.rev >= 3 ||
  5732. (dev->dev->board_vendor == PCI_VENDOR_ID_APPLE &&
  5733. (dev->dev->core_rev == 11 || dev->dev->core_rev == 12))) {
  5734. nphy->txpwrctrl = true;
  5735. nphy->pwg_gain_5ghz = true;
  5736. } else if (sprom->revision >= 4) {
  5737. if (dev->phy.rev >= 2 &&
  5738. (sprom->boardflags2_lo & B43_BFL2_TXPWRCTRL_EN)) {
  5739. nphy->txpwrctrl = true;
  5740. #ifdef CONFIG_B43_SSB
  5741. if (dev->dev->bus_type == B43_BUS_SSB &&
  5742. dev->dev->sdev->bus->bustype == SSB_BUSTYPE_PCI) {
  5743. struct pci_dev *pdev =
  5744. dev->dev->sdev->bus->host_pci;
  5745. if (pdev->device == 0x4328 ||
  5746. pdev->device == 0x432a)
  5747. nphy->pwg_gain_5ghz = true;
  5748. }
  5749. #endif
  5750. } else if (sprom->boardflags2_lo & B43_BFL2_5G_PWRGAIN) {
  5751. nphy->pwg_gain_5ghz = true;
  5752. }
  5753. }
  5754. if (dev->phy.rev >= 3) {
  5755. nphy->ipa2g_on = sprom->fem.ghz2.extpa_gain == 2;
  5756. nphy->ipa5g_on = sprom->fem.ghz5.extpa_gain == 2;
  5757. }
  5758. }
  5759. static void b43_nphy_op_free(struct b43_wldev *dev)
  5760. {
  5761. struct b43_phy *phy = &dev->phy;
  5762. struct b43_phy_n *nphy = phy->n;
  5763. kfree(nphy);
  5764. phy->n = NULL;
  5765. }
  5766. static int b43_nphy_op_init(struct b43_wldev *dev)
  5767. {
  5768. return b43_phy_initn(dev);
  5769. }
  5770. static inline void check_phyreg(struct b43_wldev *dev, u16 offset)
  5771. {
  5772. #if B43_DEBUG
  5773. if ((offset & B43_PHYROUTE) == B43_PHYROUTE_OFDM_GPHY) {
  5774. /* OFDM registers are onnly available on A/G-PHYs */
  5775. b43err(dev->wl, "Invalid OFDM PHY access at "
  5776. "0x%04X on N-PHY\n", offset);
  5777. dump_stack();
  5778. }
  5779. if ((offset & B43_PHYROUTE) == B43_PHYROUTE_EXT_GPHY) {
  5780. /* Ext-G registers are only available on G-PHYs */
  5781. b43err(dev->wl, "Invalid EXT-G PHY access at "
  5782. "0x%04X on N-PHY\n", offset);
  5783. dump_stack();
  5784. }
  5785. #endif /* B43_DEBUG */
  5786. }
  5787. static void b43_nphy_op_maskset(struct b43_wldev *dev, u16 reg, u16 mask,
  5788. u16 set)
  5789. {
  5790. check_phyreg(dev, reg);
  5791. b43_write16f(dev, B43_MMIO_PHY_CONTROL, reg);
  5792. b43_maskset16(dev, B43_MMIO_PHY_DATA, mask, set);
  5793. dev->phy.writes_counter = 1;
  5794. }
  5795. static u16 b43_nphy_op_radio_read(struct b43_wldev *dev, u16 reg)
  5796. {
  5797. /* Register 1 is a 32-bit register. */
  5798. B43_WARN_ON(dev->phy.rev < 7 && reg == 1);
  5799. if (dev->phy.rev >= 7)
  5800. reg |= 0x200; /* Radio 0x2057 */
  5801. else
  5802. reg |= 0x100;
  5803. b43_write16f(dev, B43_MMIO_RADIO_CONTROL, reg);
  5804. return b43_read16(dev, B43_MMIO_RADIO_DATA_LOW);
  5805. }
  5806. static void b43_nphy_op_radio_write(struct b43_wldev *dev, u16 reg, u16 value)
  5807. {
  5808. /* Register 1 is a 32-bit register. */
  5809. B43_WARN_ON(dev->phy.rev < 7 && reg == 1);
  5810. b43_write16f(dev, B43_MMIO_RADIO_CONTROL, reg);
  5811. b43_write16(dev, B43_MMIO_RADIO_DATA_LOW, value);
  5812. }
  5813. /* http://bcm-v4.sipsolutions.net/802.11/Radio/Switch%20Radio */
  5814. static void b43_nphy_op_software_rfkill(struct b43_wldev *dev,
  5815. bool blocked)
  5816. {
  5817. struct b43_phy *phy = &dev->phy;
  5818. if (b43_read32(dev, B43_MMIO_MACCTL) & B43_MACCTL_ENABLED)
  5819. b43err(dev->wl, "MAC not suspended\n");
  5820. if (blocked) {
  5821. if (phy->rev >= 19) {
  5822. /* TODO */
  5823. } else if (phy->rev >= 8) {
  5824. b43_phy_mask(dev, B43_NPHY_RFCTL_CMD,
  5825. ~B43_NPHY_RFCTL_CMD_CHIP0PU);
  5826. } else if (phy->rev >= 7) {
  5827. /* Nothing needed */
  5828. } else if (phy->rev >= 3) {
  5829. b43_phy_mask(dev, B43_NPHY_RFCTL_CMD,
  5830. ~B43_NPHY_RFCTL_CMD_CHIP0PU);
  5831. b43_radio_mask(dev, 0x09, ~0x2);
  5832. b43_radio_write(dev, 0x204D, 0);
  5833. b43_radio_write(dev, 0x2053, 0);
  5834. b43_radio_write(dev, 0x2058, 0);
  5835. b43_radio_write(dev, 0x205E, 0);
  5836. b43_radio_mask(dev, 0x2062, ~0xF0);
  5837. b43_radio_write(dev, 0x2064, 0);
  5838. b43_radio_write(dev, 0x304D, 0);
  5839. b43_radio_write(dev, 0x3053, 0);
  5840. b43_radio_write(dev, 0x3058, 0);
  5841. b43_radio_write(dev, 0x305E, 0);
  5842. b43_radio_mask(dev, 0x3062, ~0xF0);
  5843. b43_radio_write(dev, 0x3064, 0);
  5844. }
  5845. } else {
  5846. if (phy->rev >= 19) {
  5847. /* TODO */
  5848. } else if (phy->rev >= 7) {
  5849. if (!dev->phy.radio_on)
  5850. b43_radio_2057_init(dev);
  5851. b43_switch_channel(dev, dev->phy.channel);
  5852. } else if (phy->rev >= 3) {
  5853. if (!dev->phy.radio_on)
  5854. b43_radio_init2056(dev);
  5855. b43_switch_channel(dev, dev->phy.channel);
  5856. } else {
  5857. b43_radio_init2055(dev);
  5858. }
  5859. }
  5860. }
  5861. /* http://bcm-v4.sipsolutions.net/802.11/PHY/Anacore */
  5862. static void b43_nphy_op_switch_analog(struct b43_wldev *dev, bool on)
  5863. {
  5864. struct b43_phy *phy = &dev->phy;
  5865. u16 override = on ? 0x0 : 0x7FFF;
  5866. u16 core = on ? 0xD : 0x00FD;
  5867. if (phy->rev >= 19) {
  5868. /* TODO */
  5869. } else if (phy->rev >= 3) {
  5870. if (on) {
  5871. b43_phy_write(dev, B43_NPHY_AFECTL_C1, core);
  5872. b43_phy_write(dev, B43_NPHY_AFECTL_OVER1, override);
  5873. b43_phy_write(dev, B43_NPHY_AFECTL_C2, core);
  5874. b43_phy_write(dev, B43_NPHY_AFECTL_OVER, override);
  5875. } else {
  5876. b43_phy_write(dev, B43_NPHY_AFECTL_OVER1, override);
  5877. b43_phy_write(dev, B43_NPHY_AFECTL_C1, core);
  5878. b43_phy_write(dev, B43_NPHY_AFECTL_OVER, override);
  5879. b43_phy_write(dev, B43_NPHY_AFECTL_C2, core);
  5880. }
  5881. } else {
  5882. b43_phy_write(dev, B43_NPHY_AFECTL_OVER, override);
  5883. }
  5884. }
  5885. static int b43_nphy_op_switch_channel(struct b43_wldev *dev,
  5886. unsigned int new_channel)
  5887. {
  5888. struct ieee80211_channel *channel = dev->wl->hw->conf.chandef.chan;
  5889. enum nl80211_channel_type channel_type =
  5890. cfg80211_get_chandef_type(&dev->wl->hw->conf.chandef);
  5891. if (b43_current_band(dev->wl) == NL80211_BAND_2GHZ) {
  5892. if ((new_channel < 1) || (new_channel > 14))
  5893. return -EINVAL;
  5894. } else {
  5895. if (new_channel > 200)
  5896. return -EINVAL;
  5897. }
  5898. return b43_nphy_set_channel(dev, channel, channel_type);
  5899. }
  5900. static unsigned int b43_nphy_op_get_default_chan(struct b43_wldev *dev)
  5901. {
  5902. if (b43_current_band(dev->wl) == NL80211_BAND_2GHZ)
  5903. return 1;
  5904. return 36;
  5905. }
  5906. const struct b43_phy_operations b43_phyops_n = {
  5907. .allocate = b43_nphy_op_allocate,
  5908. .free = b43_nphy_op_free,
  5909. .prepare_structs = b43_nphy_op_prepare_structs,
  5910. .init = b43_nphy_op_init,
  5911. .phy_maskset = b43_nphy_op_maskset,
  5912. .radio_read = b43_nphy_op_radio_read,
  5913. .radio_write = b43_nphy_op_radio_write,
  5914. .software_rfkill = b43_nphy_op_software_rfkill,
  5915. .switch_analog = b43_nphy_op_switch_analog,
  5916. .switch_channel = b43_nphy_op_switch_channel,
  5917. .get_default_chan = b43_nphy_op_get_default_chan,
  5918. .recalc_txpower = b43_nphy_op_recalc_txpower,
  5919. };