halbtc8822b1ant.c 197 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002
  1. /* ************************************************************
  2. * Description:
  3. *
  4. * This file is for RTL8822B Co-exist mechanism
  5. *
  6. * History
  7. * 2012/11/15 Cosa first check in.
  8. *
  9. * ************************************************************ */
  10. /* ************************************************************
  11. * include files
  12. * ************************************************************ */
  13. /*only for rf4ce*/
  14. #include "mp_precomp.h"
  15. /*#include "mp_precomp.h" */
  16. #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1)
  17. #if (RTL8822B_SUPPORT == 1)
  18. /* ************************************************************
  19. * Global variables, these are static variables
  20. * ************************************************************ */
  21. static u8 *trace_buf = &gl_btc_trace_buf[0];
  22. static struct coex_dm_8822b_1ant glcoex_dm_8822b_1ant;
  23. static struct coex_dm_8822b_1ant *coex_dm = &glcoex_dm_8822b_1ant;
  24. static struct coex_sta_8822b_1ant glcoex_sta_8822b_1ant;
  25. static struct coex_sta_8822b_1ant *coex_sta = &glcoex_sta_8822b_1ant;
  26. static struct psdscan_sta_8822b_1ant gl_psd_scan_8822b_1ant;
  27. static struct psdscan_sta_8822b_1ant *psd_scan = &gl_psd_scan_8822b_1ant;
  28. static struct rfe_type_8822b_1ant gl_rfe_type_8822b_1ant;
  29. static struct rfe_type_8822b_1ant *rfe_type = &gl_rfe_type_8822b_1ant;
  30. const char *const glbt_info_src_8822b_1ant[] = {
  31. "BT Info[wifi fw]",
  32. "BT Info[bt rsp]",
  33. "BT Info[bt auto report]",
  34. };
  35. u32 glcoex_ver_date_8822b_1ant = 20161124;
  36. u32 glcoex_ver_8822b_1ant = 0x3f;
  37. u32 glcoex_ver_btdesired_8822b_1ant = 0x28;
  38. /* ************************************************************
  39. * local function proto type if needed
  40. * ************************************************************
  41. * ************************************************************
  42. * local function start with halbtc8822b1ant_
  43. * ************************************************************ */
  44. u8 halbtc8822b1ant_bt_rssi_state(u8 level_num, u8 rssi_thresh, u8 rssi_thresh1)
  45. {
  46. s32 bt_rssi = 0;
  47. u8 bt_rssi_state = coex_sta->pre_bt_rssi_state;
  48. bt_rssi = coex_sta->bt_rssi;
  49. if (level_num == 2) {
  50. if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
  51. (coex_sta->pre_bt_rssi_state ==
  52. BTC_RSSI_STATE_STAY_LOW)) {
  53. if (bt_rssi >= (rssi_thresh +
  54. BTC_RSSI_COEX_THRESH_TOL_8822B_1ANT))
  55. bt_rssi_state = BTC_RSSI_STATE_HIGH;
  56. else
  57. bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  58. } else {
  59. if (bt_rssi < rssi_thresh)
  60. bt_rssi_state = BTC_RSSI_STATE_LOW;
  61. else
  62. bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  63. }
  64. } else if (level_num == 3) {
  65. if (rssi_thresh > rssi_thresh1) {
  66. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  67. "[BTCoex], BT Rssi thresh error!!\n");
  68. BTC_TRACE(trace_buf);
  69. return coex_sta->pre_bt_rssi_state;
  70. }
  71. if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
  72. (coex_sta->pre_bt_rssi_state ==
  73. BTC_RSSI_STATE_STAY_LOW)) {
  74. if (bt_rssi >= (rssi_thresh +
  75. BTC_RSSI_COEX_THRESH_TOL_8822B_1ANT))
  76. bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
  77. else
  78. bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  79. } else if ((coex_sta->pre_bt_rssi_state ==
  80. BTC_RSSI_STATE_MEDIUM) ||
  81. (coex_sta->pre_bt_rssi_state ==
  82. BTC_RSSI_STATE_STAY_MEDIUM)) {
  83. if (bt_rssi >= (rssi_thresh1 +
  84. BTC_RSSI_COEX_THRESH_TOL_8822B_1ANT))
  85. bt_rssi_state = BTC_RSSI_STATE_HIGH;
  86. else if (bt_rssi < rssi_thresh)
  87. bt_rssi_state = BTC_RSSI_STATE_LOW;
  88. else
  89. bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
  90. } else {
  91. if (bt_rssi < rssi_thresh1)
  92. bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
  93. else
  94. bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  95. }
  96. }
  97. coex_sta->pre_bt_rssi_state = bt_rssi_state;
  98. return bt_rssi_state;
  99. }
  100. u8 halbtc8822b1ant_wifi_rssi_state(IN struct btc_coexist *btcoexist,
  101. IN u8 index, IN u8 level_num, IN u8 rssi_thresh, IN u8 rssi_thresh1)
  102. {
  103. s32 wifi_rssi = 0;
  104. u8 wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index];
  105. btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
  106. if (level_num == 2) {
  107. if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW)
  108. ||
  109. (coex_sta->pre_wifi_rssi_state[index] ==
  110. BTC_RSSI_STATE_STAY_LOW)) {
  111. if (wifi_rssi >= (rssi_thresh +
  112. BTC_RSSI_COEX_THRESH_TOL_8822B_1ANT))
  113. wifi_rssi_state = BTC_RSSI_STATE_HIGH;
  114. else
  115. wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  116. } else {
  117. if (wifi_rssi < rssi_thresh)
  118. wifi_rssi_state = BTC_RSSI_STATE_LOW;
  119. else
  120. wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  121. }
  122. } else if (level_num == 3) {
  123. if (rssi_thresh > rssi_thresh1) {
  124. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  125. "[BTCoex], wifi RSSI thresh error!!\n");
  126. BTC_TRACE(trace_buf);
  127. return coex_sta->pre_wifi_rssi_state[index];
  128. }
  129. if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW)
  130. ||
  131. (coex_sta->pre_wifi_rssi_state[index] ==
  132. BTC_RSSI_STATE_STAY_LOW)) {
  133. if (wifi_rssi >= (rssi_thresh +
  134. BTC_RSSI_COEX_THRESH_TOL_8822B_1ANT))
  135. wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
  136. else
  137. wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  138. } else if ((coex_sta->pre_wifi_rssi_state[index] ==
  139. BTC_RSSI_STATE_MEDIUM) ||
  140. (coex_sta->pre_wifi_rssi_state[index] ==
  141. BTC_RSSI_STATE_STAY_MEDIUM)) {
  142. if (wifi_rssi >= (rssi_thresh1 +
  143. BTC_RSSI_COEX_THRESH_TOL_8822B_1ANT))
  144. wifi_rssi_state = BTC_RSSI_STATE_HIGH;
  145. else if (wifi_rssi < rssi_thresh)
  146. wifi_rssi_state = BTC_RSSI_STATE_LOW;
  147. else
  148. wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
  149. } else {
  150. if (wifi_rssi < rssi_thresh1)
  151. wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
  152. else
  153. wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  154. }
  155. }
  156. coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state;
  157. return wifi_rssi_state;
  158. }
  159. void halbtc8822b1ant_update_ra_mask(IN struct btc_coexist *btcoexist,
  160. IN boolean force_exec, IN u32 dis_rate_mask)
  161. {
  162. coex_dm->cur_ra_mask = dis_rate_mask;
  163. if (force_exec || (coex_dm->pre_ra_mask != coex_dm->cur_ra_mask))
  164. btcoexist->btc_set(btcoexist, BTC_SET_ACT_UPDATE_RAMASK,
  165. &coex_dm->cur_ra_mask);
  166. coex_dm->pre_ra_mask = coex_dm->cur_ra_mask;
  167. }
  168. void halbtc8822b1ant_auto_rate_fallback_retry(IN struct btc_coexist *btcoexist,
  169. IN boolean force_exec, IN u8 type)
  170. {
  171. boolean wifi_under_b_mode = false;
  172. coex_dm->cur_arfr_type = type;
  173. if (force_exec || (coex_dm->pre_arfr_type != coex_dm->cur_arfr_type)) {
  174. switch (coex_dm->cur_arfr_type) {
  175. case 0: /* normal mode */
  176. btcoexist->btc_write_4byte(btcoexist, 0x430,
  177. coex_dm->backup_arfr_cnt1);
  178. btcoexist->btc_write_4byte(btcoexist, 0x434,
  179. coex_dm->backup_arfr_cnt2);
  180. break;
  181. case 1:
  182. btcoexist->btc_get(btcoexist,
  183. BTC_GET_BL_WIFI_UNDER_B_MODE,
  184. &wifi_under_b_mode);
  185. if (wifi_under_b_mode) {
  186. btcoexist->btc_write_4byte(btcoexist,
  187. 0x430, 0x0);
  188. btcoexist->btc_write_4byte(btcoexist,
  189. 0x434, 0x01010101);
  190. } else {
  191. btcoexist->btc_write_4byte(btcoexist,
  192. 0x430, 0x0);
  193. btcoexist->btc_write_4byte(btcoexist,
  194. 0x434, 0x04030201);
  195. }
  196. break;
  197. default:
  198. break;
  199. }
  200. }
  201. coex_dm->pre_arfr_type = coex_dm->cur_arfr_type;
  202. }
  203. void halbtc8822b1ant_retry_limit(IN struct btc_coexist *btcoexist,
  204. IN boolean force_exec, IN u8 type)
  205. {
  206. coex_dm->cur_retry_limit_type = type;
  207. if (force_exec ||
  208. (coex_dm->pre_retry_limit_type !=
  209. coex_dm->cur_retry_limit_type)) {
  210. switch (coex_dm->cur_retry_limit_type) {
  211. case 0: /* normal mode */
  212. btcoexist->btc_write_2byte(btcoexist, 0x42a,
  213. coex_dm->backup_retry_limit);
  214. break;
  215. case 1: /* retry limit=8 */
  216. btcoexist->btc_write_2byte(btcoexist, 0x42a,
  217. 0x0808);
  218. break;
  219. default:
  220. break;
  221. }
  222. }
  223. coex_dm->pre_retry_limit_type = coex_dm->cur_retry_limit_type;
  224. }
  225. void halbtc8822b1ant_ampdu_max_time(IN struct btc_coexist *btcoexist,
  226. IN boolean force_exec, IN u8 type)
  227. {
  228. coex_dm->cur_ampdu_time_type = type;
  229. if (force_exec ||
  230. (coex_dm->pre_ampdu_time_type != coex_dm->cur_ampdu_time_type)) {
  231. switch (coex_dm->cur_ampdu_time_type) {
  232. case 0: /* normal mode */
  233. btcoexist->btc_write_1byte(btcoexist, 0x456,
  234. coex_dm->backup_ampdu_max_time);
  235. break;
  236. case 1: /* AMPDU timw = 0x38 * 32us */
  237. btcoexist->btc_write_1byte(btcoexist, 0x456,
  238. 0x38);
  239. break;
  240. default:
  241. break;
  242. }
  243. }
  244. coex_dm->pre_ampdu_time_type = coex_dm->cur_ampdu_time_type;
  245. }
  246. void halbtc8822b1ant_limited_tx(IN struct btc_coexist *btcoexist,
  247. IN boolean force_exec, IN u8 ra_mask_type, IN u8 arfr_type,
  248. IN u8 retry_limit_type, IN u8 ampdu_time_type)
  249. {
  250. switch (ra_mask_type) {
  251. case 0: /* normal mode */
  252. halbtc8822b1ant_update_ra_mask(btcoexist, force_exec,
  253. 0x0);
  254. break;
  255. case 1: /* disable cck 1/2 */
  256. halbtc8822b1ant_update_ra_mask(btcoexist, force_exec,
  257. 0x00000003);
  258. break;
  259. case 2: /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */
  260. halbtc8822b1ant_update_ra_mask(btcoexist, force_exec,
  261. 0x0001f1f7);
  262. break;
  263. default:
  264. break;
  265. }
  266. halbtc8822b1ant_auto_rate_fallback_retry(btcoexist, force_exec,
  267. arfr_type);
  268. halbtc8822b1ant_retry_limit(btcoexist, force_exec, retry_limit_type);
  269. halbtc8822b1ant_ampdu_max_time(btcoexist, force_exec, ampdu_time_type);
  270. }
  271. /*
  272. rx agg size setting :
  273. 1: true / don't care / don't care
  274. max: false / false / don't care
  275. 7: false / true / 7
  276. */
  277. void halbtc8822b1ant_limited_rx(IN struct btc_coexist *btcoexist,
  278. IN boolean force_exec, IN boolean rej_ap_agg_pkt,
  279. IN boolean bt_ctrl_agg_buf_size, IN u8 agg_buf_size)
  280. {
  281. boolean reject_rx_agg = rej_ap_agg_pkt;
  282. boolean bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size;
  283. u8 rx_agg_size = agg_buf_size;
  284. /* ============================================ */
  285. /* Rx Aggregation related setting */
  286. /* ============================================ */
  287. btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT,
  288. &reject_rx_agg);
  289. /* decide BT control aggregation buf size or not */
  290. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE,
  291. &bt_ctrl_rx_agg_size);
  292. /* aggregation buf size, only work when BT control Rx aggregation size. */
  293. btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size);
  294. /* real update aggregation setting */
  295. btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
  296. }
  297. void halbtc8822b1ant_query_bt_info(IN struct btc_coexist *btcoexist)
  298. {
  299. u8 h2c_parameter[1] = {0};
  300. coex_sta->c2h_bt_info_req_sent = true;
  301. h2c_parameter[0] |= BIT(0); /* trigger */
  302. btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter);
  303. }
  304. void halbtc8822b1ant_monitor_bt_ctr(IN struct btc_coexist *btcoexist)
  305. {
  306. u32 reg_hp_txrx, reg_lp_txrx, u32tmp;
  307. u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0;
  308. static u8 num_of_bt_counter_chk = 0, cnt_slave = 0;
  309. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  310. /* to avoid 0x76e[3] = 1 (WLAN_Act control by PTA) during IPS */
  311. /* if (! (btcoexist->btc_read_1byte(btcoexist, 0x76e) & 0x8) ) */
  312. if (coex_sta->under_ips) {
  313. /* coex_sta->high_priority_tx = 65535; */
  314. /* coex_sta->high_priority_rx = 65535; */
  315. /* coex_sta->low_priority_tx = 65535; */
  316. /* coex_sta->low_priority_rx = 65535; */
  317. /* return; */
  318. }
  319. reg_hp_txrx = 0x770;
  320. reg_lp_txrx = 0x774;
  321. u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx);
  322. reg_hp_tx = u32tmp & MASKLWORD;
  323. reg_hp_rx = (u32tmp & MASKHWORD) >> 16;
  324. u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx);
  325. reg_lp_tx = u32tmp & MASKLWORD;
  326. reg_lp_rx = (u32tmp & MASKHWORD) >> 16;
  327. coex_sta->high_priority_tx = reg_hp_tx;
  328. coex_sta->high_priority_rx = reg_hp_rx;
  329. coex_sta->low_priority_tx = reg_lp_tx;
  330. coex_sta->low_priority_rx = reg_lp_rx;
  331. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  332. "[BTCoex], Hi-Pri Rx/Tx: %d/%d, Lo-Pri Rx/Tx: %d/%d\n",
  333. reg_hp_rx, reg_hp_tx, reg_lp_rx, reg_lp_tx);
  334. BTC_TRACE(trace_buf);
  335. /* reset counter */
  336. btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
  337. if ((coex_sta->low_priority_tx > 1150) &&
  338. (!coex_sta->c2h_bt_inquiry_page))
  339. coex_sta->pop_event_cnt++;
  340. if ((coex_sta->low_priority_rx >= 1150) &&
  341. (coex_sta->low_priority_rx >= coex_sta->low_priority_tx)
  342. && (!coex_sta->under_ips) &&
  343. (!coex_sta->c2h_bt_inquiry_page) &&
  344. (coex_sta->bt_link_exist)) {
  345. if (cnt_slave >= 3) {
  346. bt_link_info->slave_role = true;
  347. cnt_slave = 3;
  348. } else
  349. cnt_slave++;
  350. } else {
  351. if (cnt_slave == 0) {
  352. bt_link_info->slave_role = false;
  353. cnt_slave = 0;
  354. } else
  355. cnt_slave--;
  356. }
  357. if ((coex_sta->high_priority_tx == 0) &&
  358. (coex_sta->high_priority_rx == 0) &&
  359. (coex_sta->low_priority_tx == 0) &&
  360. (coex_sta->low_priority_rx == 0)) {
  361. num_of_bt_counter_chk++;
  362. if (num_of_bt_counter_chk >= 3) {
  363. halbtc8822b1ant_query_bt_info(
  364. btcoexist);
  365. num_of_bt_counter_chk = 0;
  366. }
  367. }
  368. #if 0
  369. /* Add Hi-Pri Tx/Rx counter to avoid false detection */
  370. if (((coex_sta->hid_exist) || (coex_sta->sco_exist)) &&
  371. (coex_sta->high_priority_tx + coex_sta->high_priority_rx
  372. >= 160)
  373. && (!coex_sta->c2h_bt_inquiry_page))
  374. coex_sta->bt_hi_pri_link_exist = true;
  375. else
  376. coex_sta->bt_hi_pri_link_exist = false;
  377. if ((coex_sta->acl_busy) &&
  378. (coex_sta->num_of_profile == 0)) {
  379. if (coex_sta->low_priority_tx +
  380. coex_sta->low_priority_rx >= 160) {
  381. coex_sta->pan_exist = true;
  382. coex_sta->num_of_profile++;
  383. coex_sta->wrong_profile_notification++;
  384. }
  385. }
  386. #endif
  387. }
  388. void halbtc8822b1ant_monitor_wifi_ctr(IN struct btc_coexist *btcoexist)
  389. {
  390. s32 wifi_rssi = 0;
  391. boolean wifi_busy = false, wifi_under_b_mode = false;
  392. static u8 cck_lock_counter = 0;
  393. u32 total_cnt;
  394. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  395. btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
  396. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
  397. &wifi_under_b_mode);
  398. if (coex_sta->under_ips) {
  399. coex_sta->crc_ok_cck = 0;
  400. coex_sta->crc_ok_11g = 0;
  401. coex_sta->crc_ok_11n = 0;
  402. coex_sta->crc_ok_11n_agg = 0;
  403. coex_sta->crc_err_cck = 0;
  404. coex_sta->crc_err_11g = 0;
  405. coex_sta->crc_err_11n = 0;
  406. coex_sta->crc_err_11n_agg = 0;
  407. } else {
  408. coex_sta->crc_ok_cck = btcoexist->btc_read_2byte(
  409. btcoexist,
  410. 0xf04);
  411. coex_sta->crc_ok_11g = btcoexist->btc_read_2byte(
  412. btcoexist,
  413. 0xf14);
  414. coex_sta->crc_ok_11n = btcoexist->btc_read_2byte(
  415. btcoexist,
  416. 0xf10);
  417. coex_sta->crc_ok_11n_agg = btcoexist->btc_read_2byte(
  418. btcoexist,
  419. 0xf0c);
  420. coex_sta->crc_err_cck = btcoexist->btc_read_2byte(
  421. btcoexist, 0xf00) + btcoexist->btc_read_2byte(
  422. btcoexist, 0xf06);
  423. coex_sta->crc_err_11g = btcoexist->btc_read_2byte(
  424. btcoexist,
  425. 0xf16);
  426. coex_sta->crc_err_11n = btcoexist->btc_read_2byte(
  427. btcoexist,
  428. 0xf12);
  429. coex_sta->crc_err_11n_agg = btcoexist->btc_read_2byte(
  430. btcoexist,
  431. 0xf0e);
  432. }
  433. /* reset counter */
  434. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xb58, 0x1, 0x1);
  435. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xb58, 0x1, 0x0);
  436. if ((wifi_busy) && (wifi_rssi >= 30) && (!wifi_under_b_mode)) {
  437. total_cnt = coex_sta->crc_ok_cck + coex_sta->crc_ok_11g
  438. +
  439. coex_sta->crc_ok_11n +
  440. coex_sta->crc_ok_11n_agg;
  441. if ((coex_dm->bt_status ==
  442. BT_8822B_1ANT_BT_STATUS_ACL_BUSY) ||
  443. (coex_dm->bt_status ==
  444. BT_8822B_1ANT_BT_STATUS_ACL_SCO_BUSY) ||
  445. (coex_dm->bt_status ==
  446. BT_8822B_1ANT_BT_STATUS_SCO_BUSY)) {
  447. if (coex_sta->crc_ok_cck > (total_cnt -
  448. coex_sta->crc_ok_cck)) {
  449. if (cck_lock_counter < 3)
  450. cck_lock_counter++;
  451. } else {
  452. if (cck_lock_counter > 0)
  453. cck_lock_counter--;
  454. }
  455. } else {
  456. if (cck_lock_counter > 0)
  457. cck_lock_counter--;
  458. }
  459. } else {
  460. if (cck_lock_counter > 0)
  461. cck_lock_counter--;
  462. }
  463. if (!coex_sta->pre_ccklock) {
  464. if (cck_lock_counter >= 3)
  465. coex_sta->cck_lock = true;
  466. else
  467. coex_sta->cck_lock = false;
  468. } else {
  469. if (cck_lock_counter == 0)
  470. coex_sta->cck_lock = false;
  471. else
  472. coex_sta->cck_lock = true;
  473. }
  474. if (coex_sta->cck_lock)
  475. coex_sta->cck_ever_lock = true;
  476. coex_sta->pre_ccklock = coex_sta->cck_lock;
  477. }
  478. boolean halbtc8822b1ant_is_wifi_status_changed(IN struct btc_coexist *btcoexist)
  479. {
  480. static boolean pre_wifi_busy = false, pre_under_4way = false,
  481. pre_bt_hs_on = false, pre_rf4ce_enabled = false, pre_bt_off = false;
  482. boolean wifi_busy = false, under_4way = false, bt_hs_on = false, rf4ce_enabled = false;
  483. boolean wifi_connected = false;
  484. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  485. &wifi_connected);
  486. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  487. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  488. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
  489. &under_4way);
  490. if (coex_sta->bt_disabled != pre_bt_off) {
  491. pre_bt_off = coex_sta->bt_disabled;
  492. if (coex_sta->bt_disabled)
  493. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  494. "[BTCoex], BT is disabled !!\n");
  495. else
  496. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  497. "[BTCoex], BT is enabled !!\n");
  498. BTC_TRACE(trace_buf);
  499. coex_sta->bt_coex_supported_feature = 0;
  500. coex_sta->bt_coex_supported_version = 0;
  501. return true;
  502. }
  503. btcoexist->btc_get(btcoexist, BTC_GET_BL_RF4CE_CONNECTED, &rf4ce_enabled);
  504. if (rf4ce_enabled != pre_rf4ce_enabled) {
  505. pre_rf4ce_enabled = rf4ce_enabled;
  506. if (rf4ce_enabled)
  507. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  508. "[BTCoex], rf4ce is enabled !!\n");
  509. else
  510. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  511. "[BTCoex], rf4ce is disabled !!\n");
  512. BTC_TRACE(trace_buf);
  513. return true;
  514. }
  515. if (wifi_connected) {
  516. if (wifi_busy != pre_wifi_busy) {
  517. pre_wifi_busy = wifi_busy;
  518. return true;
  519. }
  520. if (under_4way != pre_under_4way) {
  521. pre_under_4way = under_4way;
  522. return true;
  523. }
  524. if (bt_hs_on != pre_bt_hs_on) {
  525. pre_bt_hs_on = bt_hs_on;
  526. return true;
  527. }
  528. }
  529. return false;
  530. }
  531. void halbtc8822b1ant_update_bt_link_info(IN struct btc_coexist *btcoexist)
  532. {
  533. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  534. boolean bt_hs_on = false;
  535. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  536. bt_link_info->bt_link_exist = coex_sta->bt_link_exist;
  537. bt_link_info->sco_exist = coex_sta->sco_exist;
  538. bt_link_info->a2dp_exist = coex_sta->a2dp_exist;
  539. bt_link_info->pan_exist = coex_sta->pan_exist;
  540. bt_link_info->hid_exist = coex_sta->hid_exist;
  541. bt_link_info->bt_hi_pri_link_exist = coex_sta->bt_hi_pri_link_exist;
  542. bt_link_info->acl_busy = coex_sta->acl_busy;
  543. /* work around for HS mode. */
  544. if (bt_hs_on) {
  545. bt_link_info->pan_exist = true;
  546. bt_link_info->bt_link_exist = true;
  547. }
  548. /* check if Sco only */
  549. if (bt_link_info->sco_exist &&
  550. !bt_link_info->a2dp_exist &&
  551. !bt_link_info->pan_exist &&
  552. !bt_link_info->hid_exist)
  553. bt_link_info->sco_only = true;
  554. else
  555. bt_link_info->sco_only = false;
  556. /* check if A2dp only */
  557. if (!bt_link_info->sco_exist &&
  558. bt_link_info->a2dp_exist &&
  559. !bt_link_info->pan_exist &&
  560. !bt_link_info->hid_exist)
  561. bt_link_info->a2dp_only = true;
  562. else
  563. bt_link_info->a2dp_only = false;
  564. /* check if Pan only */
  565. if (!bt_link_info->sco_exist &&
  566. !bt_link_info->a2dp_exist &&
  567. bt_link_info->pan_exist &&
  568. !bt_link_info->hid_exist)
  569. bt_link_info->pan_only = true;
  570. else
  571. bt_link_info->pan_only = false;
  572. /* check if Hid only */
  573. if (!bt_link_info->sco_exist &&
  574. !bt_link_info->a2dp_exist &&
  575. !bt_link_info->pan_exist &&
  576. bt_link_info->hid_exist)
  577. bt_link_info->hid_only = true;
  578. else
  579. bt_link_info->hid_only = false;
  580. }
  581. void halbtc8822b1ant_update_wifi_channel_info(IN struct btc_coexist *btcoexist,
  582. IN u8 type)
  583. {
  584. u8 h2c_parameter[3] = {0};
  585. u32 wifi_bw;
  586. u8 wifi_central_chnl;
  587. /* only 2.4G we need to inform bt the chnl mask */
  588. btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL,
  589. &wifi_central_chnl);
  590. if ((BTC_MEDIA_CONNECT == type) &&
  591. (wifi_central_chnl <= 14)) {
  592. h2c_parameter[0] =
  593. 0x1; /* enable BT AFH skip WL channel for 8822b because BT Rx LO interference */
  594. h2c_parameter[1] = wifi_central_chnl;
  595. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  596. if (BTC_WIFI_BW_HT40 == wifi_bw)
  597. h2c_parameter[2] = 0x30;
  598. else
  599. h2c_parameter[2] = 0x20;
  600. }
  601. coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
  602. coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
  603. coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
  604. btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter);
  605. }
  606. u8 halbtc8822b1ant_action_algorithm(IN struct btc_coexist *btcoexist)
  607. {
  608. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  609. boolean bt_hs_on = false;
  610. u8 algorithm = BT_8822B_1ANT_COEX_ALGO_UNDEFINED;
  611. u8 num_of_diff_profile = 0;
  612. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  613. if (!bt_link_info->bt_link_exist) {
  614. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  615. "[BTCoex], No BT link exists!!!\n");
  616. BTC_TRACE(trace_buf);
  617. return algorithm;
  618. }
  619. if (bt_link_info->sco_exist)
  620. num_of_diff_profile++;
  621. if (bt_link_info->hid_exist)
  622. num_of_diff_profile++;
  623. if (bt_link_info->pan_exist)
  624. num_of_diff_profile++;
  625. if (bt_link_info->a2dp_exist)
  626. num_of_diff_profile++;
  627. if (num_of_diff_profile == 1) {
  628. if (bt_link_info->sco_exist) {
  629. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  630. "[BTCoex], BT Profile = SCO only\n");
  631. BTC_TRACE(trace_buf);
  632. algorithm = BT_8822B_1ANT_COEX_ALGO_SCO;
  633. } else {
  634. if (bt_link_info->hid_exist) {
  635. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  636. "[BTCoex], BT Profile = HID only\n");
  637. BTC_TRACE(trace_buf);
  638. algorithm = BT_8822B_1ANT_COEX_ALGO_HID;
  639. } else if (bt_link_info->a2dp_exist) {
  640. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  641. "[BTCoex], BT Profile = A2DP only\n");
  642. BTC_TRACE(trace_buf);
  643. algorithm = BT_8822B_1ANT_COEX_ALGO_A2DP;
  644. } else if (bt_link_info->pan_exist) {
  645. if (bt_hs_on) {
  646. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  647. "[BTCoex], BT Profile = PAN(HS) only\n");
  648. BTC_TRACE(trace_buf);
  649. algorithm =
  650. BT_8822B_1ANT_COEX_ALGO_PANHS;
  651. } else {
  652. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  653. "[BTCoex], BT Profile = PAN(EDR) only\n");
  654. BTC_TRACE(trace_buf);
  655. algorithm =
  656. BT_8822B_1ANT_COEX_ALGO_PANEDR;
  657. }
  658. }
  659. }
  660. } else if (num_of_diff_profile == 2) {
  661. if (bt_link_info->sco_exist) {
  662. if (bt_link_info->hid_exist) {
  663. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  664. "[BTCoex], BT Profile = SCO + HID\n");
  665. BTC_TRACE(trace_buf);
  666. algorithm = BT_8822B_1ANT_COEX_ALGO_HID;
  667. } else if (bt_link_info->a2dp_exist) {
  668. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  669. "[BTCoex], BT Profile = SCO + A2DP ==> SCO\n");
  670. BTC_TRACE(trace_buf);
  671. algorithm = BT_8822B_1ANT_COEX_ALGO_SCO;
  672. } else if (bt_link_info->pan_exist) {
  673. if (bt_hs_on) {
  674. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  675. "[BTCoex], BT Profile = SCO + PAN(HS)\n");
  676. BTC_TRACE(trace_buf);
  677. algorithm = BT_8822B_1ANT_COEX_ALGO_SCO;
  678. } else {
  679. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  680. "[BTCoex], BT Profile = SCO + PAN(EDR)\n");
  681. BTC_TRACE(trace_buf);
  682. algorithm =
  683. BT_8822B_1ANT_COEX_ALGO_PANEDR_HID;
  684. }
  685. }
  686. } else {
  687. if (bt_link_info->hid_exist &&
  688. bt_link_info->a2dp_exist) {
  689. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  690. "[BTCoex], BT Profile = HID + A2DP\n");
  691. BTC_TRACE(trace_buf);
  692. algorithm = BT_8822B_1ANT_COEX_ALGO_HID_A2DP;
  693. } else if (bt_link_info->hid_exist &&
  694. bt_link_info->pan_exist) {
  695. if (bt_hs_on) {
  696. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  697. "[BTCoex], BT Profile = HID + PAN(HS)\n");
  698. BTC_TRACE(trace_buf);
  699. algorithm =
  700. BT_8822B_1ANT_COEX_ALGO_HID_A2DP;
  701. } else {
  702. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  703. "[BTCoex], BT Profile = HID + PAN(EDR)\n");
  704. BTC_TRACE(trace_buf);
  705. algorithm =
  706. BT_8822B_1ANT_COEX_ALGO_PANEDR_HID;
  707. }
  708. } else if (bt_link_info->pan_exist &&
  709. bt_link_info->a2dp_exist) {
  710. if (bt_hs_on) {
  711. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  712. "[BTCoex], BT Profile = A2DP + PAN(HS)\n");
  713. BTC_TRACE(trace_buf);
  714. algorithm =
  715. BT_8822B_1ANT_COEX_ALGO_A2DP_PANHS;
  716. } else {
  717. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  718. "[BTCoex], BT Profile = A2DP + PAN(EDR)\n");
  719. BTC_TRACE(trace_buf);
  720. algorithm =
  721. BT_8822B_1ANT_COEX_ALGO_PANEDR_A2DP;
  722. }
  723. }
  724. }
  725. } else if (num_of_diff_profile == 3) {
  726. if (bt_link_info->sco_exist) {
  727. if (bt_link_info->hid_exist &&
  728. bt_link_info->a2dp_exist) {
  729. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  730. "[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n");
  731. BTC_TRACE(trace_buf);
  732. algorithm = BT_8822B_1ANT_COEX_ALGO_HID;
  733. } else if (bt_link_info->hid_exist &&
  734. bt_link_info->pan_exist) {
  735. if (bt_hs_on) {
  736. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  737. "[BTCoex], BT Profile = SCO + HID + PAN(HS)\n");
  738. BTC_TRACE(trace_buf);
  739. algorithm =
  740. BT_8822B_1ANT_COEX_ALGO_HID_A2DP;
  741. } else {
  742. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  743. "[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n");
  744. BTC_TRACE(trace_buf);
  745. algorithm =
  746. BT_8822B_1ANT_COEX_ALGO_PANEDR_HID;
  747. }
  748. } else if (bt_link_info->pan_exist &&
  749. bt_link_info->a2dp_exist) {
  750. if (bt_hs_on) {
  751. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  752. "[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n");
  753. BTC_TRACE(trace_buf);
  754. algorithm = BT_8822B_1ANT_COEX_ALGO_SCO;
  755. } else {
  756. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  757. "[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n");
  758. BTC_TRACE(trace_buf);
  759. algorithm =
  760. BT_8822B_1ANT_COEX_ALGO_PANEDR_HID;
  761. }
  762. }
  763. } else {
  764. if (bt_link_info->hid_exist &&
  765. bt_link_info->pan_exist &&
  766. bt_link_info->a2dp_exist) {
  767. if (bt_hs_on) {
  768. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  769. "[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n");
  770. BTC_TRACE(trace_buf);
  771. algorithm =
  772. BT_8822B_1ANT_COEX_ALGO_HID_A2DP;
  773. } else {
  774. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  775. "[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n");
  776. BTC_TRACE(trace_buf);
  777. algorithm =
  778. BT_8822B_1ANT_COEX_ALGO_HID_A2DP_PANEDR;
  779. }
  780. }
  781. }
  782. } else if (num_of_diff_profile >= 3) {
  783. if (bt_link_info->sco_exist) {
  784. if (bt_link_info->hid_exist &&
  785. bt_link_info->pan_exist &&
  786. bt_link_info->a2dp_exist) {
  787. if (bt_hs_on) {
  788. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  789. "[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n");
  790. BTC_TRACE(trace_buf);
  791. } else {
  792. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  793. "[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n");
  794. BTC_TRACE(trace_buf);
  795. algorithm =
  796. BT_8822B_1ANT_COEX_ALGO_PANEDR_HID;
  797. }
  798. }
  799. }
  800. }
  801. return algorithm;
  802. }
  803. void halbtc8822b1ant_set_bt_auto_report(IN struct btc_coexist *btcoexist,
  804. IN boolean enable_auto_report)
  805. {
  806. u8 h2c_parameter[1] = {0};
  807. h2c_parameter[0] = 0;
  808. if (enable_auto_report)
  809. h2c_parameter[0] |= BIT(0);
  810. btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter);
  811. }
  812. void halbtc8822b1ant_bt_auto_report(IN struct btc_coexist *btcoexist,
  813. IN boolean force_exec, IN boolean enable_auto_report)
  814. {
  815. coex_dm->cur_bt_auto_report = enable_auto_report;
  816. if (!force_exec) {
  817. if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report)
  818. return;
  819. }
  820. halbtc8822b1ant_set_bt_auto_report(btcoexist,
  821. coex_dm->cur_bt_auto_report);
  822. coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report;
  823. }
  824. void halbtc8822b1ant_set_sw_penalty_tx_rate_adaptive(IN struct btc_coexist
  825. *btcoexist, IN boolean low_penalty_ra)
  826. {
  827. u8 h2c_parameter[6] = {0};
  828. h2c_parameter[0] = 0x6; /* op_code, 0x6= Retry_Penalty */
  829. if (low_penalty_ra) {
  830. h2c_parameter[1] |= BIT(0);
  831. h2c_parameter[2] =
  832. 0x00; /* normal rate except MCS7/6/5, OFDM54/48/36 */
  833. h2c_parameter[3] = 0xf7; /* MCS7 or OFDM54 */
  834. h2c_parameter[4] = 0xf8; /* MCS6 or OFDM48 */
  835. h2c_parameter[5] = 0xf9; /* MCS5 or OFDM36 */
  836. }
  837. btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, h2c_parameter);
  838. }
  839. void halbtc8822b1ant_low_penalty_ra(IN struct btc_coexist *btcoexist,
  840. IN boolean force_exec, IN boolean low_penalty_ra)
  841. {
  842. #if 1
  843. coex_dm->cur_low_penalty_ra = low_penalty_ra;
  844. if (!force_exec) {
  845. if (coex_dm->pre_low_penalty_ra ==
  846. coex_dm->cur_low_penalty_ra)
  847. return;
  848. }
  849. if (low_penalty_ra)
  850. btcoexist->btc_phydm_modify_RA_PCR_threshold(btcoexist, 0, 25);
  851. else
  852. btcoexist->btc_phydm_modify_RA_PCR_threshold(btcoexist, 0, 0);
  853. coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra;
  854. #endif
  855. }
  856. void halbtc8822b1ant_write_score_board(
  857. IN struct btc_coexist *btcoexist,
  858. IN u16 bitpos,
  859. IN boolean state
  860. )
  861. {
  862. static u16 originalval = 0x8002;
  863. if (state)
  864. originalval = originalval | bitpos;
  865. else
  866. originalval = originalval & (~bitpos);
  867. btcoexist->btc_write_2byte(btcoexist, 0xaa, originalval);
  868. }
  869. void halbtc8822b1ant_read_score_board(
  870. IN struct btc_coexist *btcoexist,
  871. IN u16 *score_board_val
  872. )
  873. {
  874. *score_board_val = (btcoexist->btc_read_2byte(btcoexist,
  875. 0xaa)) & 0x7fff;
  876. }
  877. void halbtc8822b1ant_post_state_to_bt(
  878. IN struct btc_coexist *btcoexist,
  879. IN u16 type,
  880. IN boolean state
  881. )
  882. {
  883. halbtc8822b1ant_write_score_board(btcoexist, (u16) type, state);
  884. }
  885. void halbtc8822b1ant_monitor_bt_enable_disable(IN struct btc_coexist *btcoexist)
  886. {
  887. static u32 bt_disable_cnt = 0;
  888. boolean bt_active = true, bt_disabled = false,
  889. wifi_under_5g = false;
  890. u16 u16tmp;
  891. /* This function check if bt is disabled */
  892. #if 0
  893. if (coex_sta->high_priority_tx == 0 &&
  894. coex_sta->high_priority_rx == 0 &&
  895. coex_sta->low_priority_tx == 0 &&
  896. coex_sta->low_priority_rx == 0)
  897. bt_active = false;
  898. if (coex_sta->high_priority_tx == 0xffff &&
  899. coex_sta->high_priority_rx == 0xffff &&
  900. coex_sta->low_priority_tx == 0xffff &&
  901. coex_sta->low_priority_rx == 0xffff)
  902. bt_active = false;
  903. #else
  904. /* Read BT on/off status from scoreboard[1], enable this only if BT patch support this feature */
  905. halbtc8822b1ant_read_score_board(btcoexist, &u16tmp);
  906. bt_active = u16tmp & BIT(1);
  907. #endif
  908. if (bt_active) {
  909. bt_disable_cnt = 0;
  910. bt_disabled = false;
  911. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
  912. &bt_disabled);
  913. } else {
  914. bt_disable_cnt++;
  915. if (bt_disable_cnt >= 2) {
  916. bt_disabled = true;
  917. bt_disable_cnt = 2;
  918. }
  919. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
  920. &bt_disabled);
  921. }
  922. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G,
  923. &wifi_under_5g);
  924. if ((wifi_under_5g) || (bt_disabled))
  925. halbtc8822b1ant_low_penalty_ra(btcoexist,
  926. NORMAL_EXEC, false);
  927. else
  928. halbtc8822b1ant_low_penalty_ra(btcoexist,
  929. NORMAL_EXEC, true);
  930. if (coex_sta->bt_disabled != bt_disabled) {
  931. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  932. "[BTCoex], BT is from %s to %s!!\n",
  933. (coex_sta->bt_disabled ? "disabled" :
  934. "enabled"),
  935. (bt_disabled ? "disabled" : "enabled"));
  936. BTC_TRACE(trace_buf);
  937. coex_sta->bt_disabled = bt_disabled;
  938. }
  939. }
  940. void halbtc8822b1ant_enable_gnt_to_gpio(IN struct btc_coexist *btcoexist,
  941. boolean isenable)
  942. {
  943. static u8 bitVal[5] = {0, 0, 0, 0, 0};
  944. static boolean state = false;
  945. if (state == isenable)
  946. return;
  947. state = isenable;
  948. if (isenable) {
  949. /* enable GNT_WL, GNT_BT to GPIO for debug */
  950. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x8, 0x1);
  951. /* store original value */
  952. bitVal[0] = (btcoexist->btc_read_1byte(btcoexist,
  953. 0x66) & BIT(4)) >> 4; /*0x66[4] */
  954. bitVal[1] = (btcoexist->btc_read_1byte(btcoexist,
  955. 0x67) & BIT(0)); /*0x66[8] */
  956. bitVal[2] = (btcoexist->btc_read_1byte(btcoexist,
  957. 0x42) & BIT(3)) >> 3; /*0x40[19] */
  958. bitVal[3] = (btcoexist->btc_read_1byte(btcoexist,
  959. 0x65) & BIT(7)) >> 7; /*0x64[15] */
  960. bitVal[4] = (btcoexist->btc_read_1byte(btcoexist,
  961. 0x72) & BIT(2)) >> 2; /*0x70[18] */
  962. /* switch GPIO Mux */
  963. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x66, BIT(4),
  964. 0x0); /*0x66[4] = 0 */
  965. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, BIT(0),
  966. 0x0); /*0x66[8] = 0 */
  967. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x42, BIT(3),
  968. 0x0); /*0x40[19] = 0 */
  969. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x65, BIT(7),
  970. 0x0); /*0x64[15] = 0 */
  971. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x72, BIT(2),
  972. 0x0); /*0x70[18] = 0 */
  973. } else {
  974. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x8, 0x0);
  975. /* Restore original value */
  976. /* switch GPIO Mux */
  977. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x66, BIT(4),
  978. bitVal[0]); /*0x66[4] = 0 */
  979. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, BIT(0),
  980. bitVal[1]); /*0x66[8] = 0 */
  981. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x42, BIT(3),
  982. bitVal[2]); /*0x40[19] = 0 */
  983. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x65, BIT(7),
  984. bitVal[3]); /*0x64[15] = 0 */
  985. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x72, BIT(2),
  986. bitVal[4]); /*0x70[18] = 0 */
  987. }
  988. }
  989. u32 halbtc8822b1ant_ltecoex_indirect_read_reg(IN struct btc_coexist *btcoexist,
  990. IN u16 reg_addr)
  991. {
  992. u32 j = 0, delay_count = 0;
  993. /* wait for ready bit before access 0x1700 */
  994. btcoexist->btc_write_4byte(btcoexist, 0x1700, 0x800F0000 | reg_addr);
  995. #if 0
  996. do {
  997. j++;
  998. } while (((btcoexist->btc_read_1byte(btcoexist,
  999. 0x1703) & BIT(5)) == 0) &&
  1000. (j < BT_8822B_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT));
  1001. #endif
  1002. while (1) {
  1003. if ((btcoexist->btc_read_1byte(btcoexist, 0x1703)&BIT(5)) == 0) {
  1004. delay_ms(50);
  1005. delay_count++;
  1006. if (delay_count >= 10) {
  1007. delay_count = 0;
  1008. break;
  1009. }
  1010. } else
  1011. break;
  1012. }
  1013. return btcoexist->btc_read_4byte(btcoexist,
  1014. 0x1708); /* get read data */
  1015. }
  1016. void halbtc8822b1ant_ltecoex_indirect_write_reg(IN struct btc_coexist
  1017. *btcoexist,
  1018. IN u16 reg_addr, IN u32 bit_mask, IN u32 reg_value)
  1019. {
  1020. u32 val, i = 0, j = 0, bitpos = 0, delay_count = 0;
  1021. if (bit_mask == 0x0)
  1022. return;
  1023. if (bit_mask == 0xffffffff) {
  1024. btcoexist->btc_write_4byte(btcoexist, 0x1704,
  1025. reg_value); /* put write data */
  1026. /* wait for ready bit before access 0x1700 */
  1027. #if 0
  1028. do {
  1029. j++;
  1030. } while (((btcoexist->btc_read_1byte(btcoexist,
  1031. 0x1703) & BIT(5)) == 0) &&
  1032. (j < BT_8822B_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT));
  1033. #endif
  1034. while (1) {
  1035. if ((btcoexist->btc_read_1byte(btcoexist, 0x1703)&BIT(5)) == 0) {
  1036. delay_ms(50);
  1037. delay_count++;
  1038. if (delay_count >= 10) {
  1039. delay_count = 0;
  1040. break;
  1041. }
  1042. } else
  1043. break;
  1044. }
  1045. btcoexist->btc_write_4byte(btcoexist, 0x1700,
  1046. 0xc00F0000 | reg_addr);
  1047. } else {
  1048. for (i = 0; i <= 31; i++) {
  1049. if (((bit_mask >> i) & 0x1) == 0x1) {
  1050. bitpos = i;
  1051. break;
  1052. }
  1053. }
  1054. /* read back register value before write */
  1055. val = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
  1056. reg_addr);
  1057. val = (val & (~bit_mask)) | (reg_value << bitpos);
  1058. /* put write data value */
  1059. btcoexist->btc_write_4byte(btcoexist, 0x1704,
  1060. val); /* put write data */
  1061. /* wait for ready bit before access 0x1700 */
  1062. #if 0
  1063. do {
  1064. j++;
  1065. } while (((btcoexist->btc_read_1byte(btcoexist,
  1066. 0x1703) & BIT(5)) == 0) &&
  1067. (j < BT_8822B_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT));
  1068. #endif
  1069. while (1) {
  1070. if ((btcoexist->btc_read_1byte(btcoexist, 0x1703)&BIT(5)) == 0) {
  1071. delay_ms(50);
  1072. delay_count++;
  1073. if (delay_count >= 10) {
  1074. delay_count = 0;
  1075. break;
  1076. }
  1077. } else
  1078. break;
  1079. }
  1080. btcoexist->btc_write_4byte(btcoexist, 0x1700,
  1081. 0xc00F0000 | reg_addr);
  1082. }
  1083. }
  1084. void halbtc8822b1ant_ltecoex_enable(IN struct btc_coexist *btcoexist,
  1085. IN boolean enable)
  1086. {
  1087. u8 val;
  1088. val = (enable) ? 1 : 0;
  1089. /* 0x38[7] */
  1090. halbtc8822b1ant_ltecoex_indirect_write_reg(btcoexist, 0x38, 0x80,
  1091. val); /* 0x38[7] */
  1092. }
  1093. void halbtc8822b1ant_ltecoex_pathcontrol_owner(IN struct btc_coexist *btcoexist,
  1094. IN boolean wifi_control)
  1095. {
  1096. u8 val;
  1097. val = (wifi_control) ? 1 : 0;
  1098. /* 0x70[26] */
  1099. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x4,
  1100. val); /* 0x70[26] */
  1101. }
  1102. void halbtc8822b1ant_ltecoex_set_gnt_bt(IN struct btc_coexist *btcoexist,
  1103. IN u8 control_block, IN boolean sw_control, IN u8 state)
  1104. {
  1105. u32 val = 0, bit_mask;
  1106. state = state & 0x1;
  1107. /*LTE indirect 0x38=0xccxx (sw : gnt_wl=1,sw gnt_bt=1)
  1108. 0x38=0xddxx (sw : gnt_bt=1 , sw gnt_wl=0)
  1109. 0x38=0x55xx(hw pta :gnt_wl /gnt_bt ) */
  1110. val = (sw_control) ? ((state << 1) | 0x1) : 0;
  1111. switch (control_block) {
  1112. case BT_8822B_1ANT_GNT_BLOCK_RFC_BB:
  1113. default:
  1114. bit_mask = 0xc000;
  1115. halbtc8822b1ant_ltecoex_indirect_write_reg(btcoexist,
  1116. 0x38, bit_mask, val); /* 0x38[15:14] */
  1117. bit_mask = 0x0c00;
  1118. halbtc8822b1ant_ltecoex_indirect_write_reg(btcoexist,
  1119. 0x38, bit_mask, val); /* 0x38[11:10] */
  1120. break;
  1121. case BT_8822B_1ANT_GNT_BLOCK_RFC:
  1122. bit_mask = 0xc000;
  1123. halbtc8822b1ant_ltecoex_indirect_write_reg(btcoexist,
  1124. 0x38, bit_mask, val); /* 0x38[15:14] */
  1125. break;
  1126. case BT_8822B_1ANT_GNT_BLOCK_BB:
  1127. bit_mask = 0x0c00;
  1128. halbtc8822b1ant_ltecoex_indirect_write_reg(btcoexist,
  1129. 0x38, bit_mask, val); /* 0x38[11:10] */
  1130. break;
  1131. }
  1132. }
  1133. void halbtc8822b1ant_ltecoex_set_gnt_wl(IN struct btc_coexist *btcoexist,
  1134. IN u8 control_block, IN boolean sw_control, IN u8 state)
  1135. {
  1136. u32 val = 0, bit_mask;
  1137. /*LTE indirect 0x38=0xccxx (sw : gnt_wl=1,sw gnt_bt=1)
  1138. 0x38=0xddxx (sw : gnt_bt=1 , sw gnt_wl=0)
  1139. 0x38=0x55xx(hw pta :gnt_wl /gnt_bt ) */
  1140. state = state & 0x1;
  1141. val = (sw_control) ? ((state << 1) | 0x1) : 0;
  1142. switch (control_block) {
  1143. case BT_8822B_1ANT_GNT_BLOCK_RFC_BB:
  1144. default:
  1145. bit_mask = 0x3000;
  1146. halbtc8822b1ant_ltecoex_indirect_write_reg(btcoexist,
  1147. 0x38, bit_mask, val); /* 0x38[13:12] */
  1148. bit_mask = 0x0300;
  1149. halbtc8822b1ant_ltecoex_indirect_write_reg(btcoexist,
  1150. 0x38, bit_mask, val); /* 0x38[9:8] */
  1151. break;
  1152. case BT_8822B_1ANT_GNT_BLOCK_RFC:
  1153. bit_mask = 0x3000;
  1154. halbtc8822b1ant_ltecoex_indirect_write_reg(btcoexist,
  1155. 0x38, bit_mask, val); /* 0x38[13:12] */
  1156. break;
  1157. case BT_8822B_1ANT_GNT_BLOCK_BB:
  1158. bit_mask = 0x0300;
  1159. halbtc8822b1ant_ltecoex_indirect_write_reg(btcoexist,
  1160. 0x38, bit_mask, val); /* 0x38[9:8] */
  1161. break;
  1162. }
  1163. }
  1164. void halbtc8822b1ant_ltecoex_set_coex_table(IN struct btc_coexist *btcoexist,
  1165. IN u8 table_type, IN u16 table_content)
  1166. {
  1167. u16 reg_addr = 0x0000;
  1168. switch (table_type) {
  1169. case BT_8822B_1ANT_CTT_WL_VS_LTE:
  1170. reg_addr = 0xa0;
  1171. break;
  1172. case BT_8822B_1ANT_CTT_BT_VS_LTE:
  1173. reg_addr = 0xa4;
  1174. break;
  1175. }
  1176. if (reg_addr != 0x0000)
  1177. halbtc8822b1ant_ltecoex_indirect_write_reg(btcoexist, reg_addr,
  1178. 0xffff, table_content); /* 0xa0[15:0] or 0xa4[15:0] */
  1179. }
  1180. void halbtc8822b1ant_ltcoex_set_break_table(IN struct btc_coexist *btcoexist,
  1181. IN u8 table_type, IN u8 table_content)
  1182. {
  1183. u16 reg_addr = 0x0000;
  1184. switch (table_type) {
  1185. case BT_8822B_1ANT_LBTT_WL_BREAK_LTE:
  1186. reg_addr = 0xa8;
  1187. break;
  1188. case BT_8822B_1ANT_LBTT_BT_BREAK_LTE:
  1189. reg_addr = 0xac;
  1190. break;
  1191. case BT_8822B_1ANT_LBTT_LTE_BREAK_WL:
  1192. reg_addr = 0xb0;
  1193. break;
  1194. case BT_8822B_1ANT_LBTT_LTE_BREAK_BT:
  1195. reg_addr = 0xb4;
  1196. break;
  1197. }
  1198. if (reg_addr != 0x0000)
  1199. halbtc8822b1ant_ltecoex_indirect_write_reg(btcoexist, reg_addr,
  1200. 0xff, table_content); /* 0xa8[15:0] or 0xb4[15:0] */
  1201. }
  1202. void halbtc8822b1ant_set_wltoggle_coex_table(IN struct btc_coexist *btcoexist,
  1203. IN boolean force_exec, IN u8 interval,
  1204. IN u8 val0x6c4_b0, IN u8 val0x6c4_b1, IN u8 val0x6c4_b2,
  1205. IN u8 val0x6c4_b3)
  1206. {
  1207. static u8 pre_h2c_parameter[6] = {0};
  1208. u8 cur_h2c_parameter[6] = {0};
  1209. u8 i, match_cnt = 0;
  1210. cur_h2c_parameter[0] = 0x7; /* op_code, 0x7= wlan toggle slot*/
  1211. cur_h2c_parameter[1] = interval;
  1212. cur_h2c_parameter[2] = val0x6c4_b0;
  1213. cur_h2c_parameter[3] = val0x6c4_b1;
  1214. cur_h2c_parameter[4] = val0x6c4_b2;
  1215. cur_h2c_parameter[5] = val0x6c4_b3;
  1216. if (!force_exec) {
  1217. for (i = 1; i <= 5; i++) {
  1218. if (cur_h2c_parameter[i] != pre_h2c_parameter[i])
  1219. break;
  1220. match_cnt++;
  1221. }
  1222. if (match_cnt == 5)
  1223. return;
  1224. }
  1225. for (i = 1; i <= 5; i++)
  1226. pre_h2c_parameter[i] = cur_h2c_parameter[i];
  1227. btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, cur_h2c_parameter);
  1228. }
  1229. void halbtc8822b1ant_set_coex_table(IN struct btc_coexist *btcoexist,
  1230. IN u32 val0x6c0, IN u32 val0x6c4, IN u32 val0x6c8, IN u8 val0x6cc)
  1231. {
  1232. btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0);
  1233. btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4);
  1234. btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8);
  1235. btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc);
  1236. }
  1237. void halbtc8822b1ant_coex_table(IN struct btc_coexist *btcoexist,
  1238. IN boolean force_exec, IN u32 val0x6c0, IN u32 val0x6c4,
  1239. IN u32 val0x6c8, IN u8 val0x6cc)
  1240. {
  1241. coex_dm->cur_val0x6c0 = val0x6c0;
  1242. coex_dm->cur_val0x6c4 = val0x6c4;
  1243. coex_dm->cur_val0x6c8 = val0x6c8;
  1244. coex_dm->cur_val0x6cc = val0x6cc;
  1245. if (!force_exec) {
  1246. if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) &&
  1247. (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) &&
  1248. (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) &&
  1249. (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc))
  1250. return;
  1251. }
  1252. halbtc8822b1ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8,
  1253. val0x6cc);
  1254. coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0;
  1255. coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4;
  1256. coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8;
  1257. coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc;
  1258. }
  1259. void halbtc8822b1ant_coex_table_with_type(IN struct btc_coexist *btcoexist,
  1260. IN boolean force_exec, IN u8 type)
  1261. {
  1262. u32 break_table;
  1263. u8 select_table;
  1264. coex_sta->coex_table_type = type;
  1265. if (coex_sta->concurrent_rx_mode_on == true) {
  1266. break_table = 0xf0ffffff; /* set WL hi-pri can break BT */
  1267. select_table = 0x3; /* set Tx response = Hi-Pri (ex: Transmitting ACK,BA,CTS) */
  1268. } else {
  1269. break_table = 0xffffff;
  1270. select_table = 0x3;
  1271. }
  1272. switch (type) {
  1273. case 0:
  1274. halbtc8822b1ant_coex_table(btcoexist, force_exec,
  1275. 0x55555555, 0x55555555, break_table,
  1276. select_table);
  1277. break;
  1278. case 1:
  1279. halbtc8822b1ant_coex_table(btcoexist, force_exec,
  1280. 0x55555555, 0x5a5a5a5a, break_table,
  1281. select_table);
  1282. break;
  1283. case 2:
  1284. halbtc8822b1ant_coex_table(btcoexist, force_exec,
  1285. 0xaa5a5a5a, 0xaa5a5a5a, break_table,
  1286. select_table);
  1287. break;
  1288. case 3:
  1289. halbtc8822b1ant_coex_table(btcoexist, force_exec,
  1290. 0x55555555, 0xaa5a5a5a, break_table,
  1291. select_table);
  1292. break;
  1293. case 4:
  1294. halbtc8822b1ant_coex_table(btcoexist,
  1295. force_exec, 0xaa555555, 0xaa5a5a5a,
  1296. break_table, select_table);
  1297. break;
  1298. case 5:
  1299. halbtc8822b1ant_coex_table(btcoexist,
  1300. force_exec, 0x5a5a5a5a, 0x5a5a5a5a,
  1301. break_table, select_table);
  1302. break;
  1303. case 6:
  1304. halbtc8822b1ant_coex_table(btcoexist, force_exec,
  1305. 0x55555555, 0xaaaaaaaa, break_table,
  1306. select_table);
  1307. break;
  1308. case 7:
  1309. halbtc8822b1ant_coex_table(btcoexist, force_exec,
  1310. 0xaaaaaaaa, 0xaaaaaaaa, break_table,
  1311. select_table);
  1312. break;
  1313. case 8:
  1314. halbtc8822b1ant_coex_table(btcoexist, force_exec,
  1315. 0xffffffff, 0xffffffff, break_table,
  1316. select_table);
  1317. break;
  1318. case 9:
  1319. halbtc8822b1ant_coex_table(btcoexist, force_exec,
  1320. 0x5a5a5555, 0xaaaa5a5a, break_table,
  1321. select_table);
  1322. break;
  1323. case 10:
  1324. halbtc8822b1ant_coex_table(btcoexist, force_exec,
  1325. 0xaaaa5aaa, 0xaaaa5aaa, break_table,
  1326. select_table);
  1327. break;
  1328. case 11:
  1329. halbtc8822b1ant_coex_table(btcoexist, force_exec,
  1330. 0xaaaaa5aa, 0xaaaaaaaa, break_table,
  1331. select_table);
  1332. break;
  1333. case 12:
  1334. halbtc8822b1ant_coex_table(btcoexist, force_exec,
  1335. 0xaaaaa5aa, 0xaaaaa5aa, break_table,
  1336. select_table);
  1337. break;
  1338. case 13:
  1339. halbtc8822b1ant_coex_table(btcoexist, force_exec,
  1340. 0x55555555, 0xaaaa5a5a, break_table,
  1341. select_table);
  1342. break;
  1343. case 14:
  1344. halbtc8822b1ant_coex_table(btcoexist, force_exec,
  1345. 0x5a5a555a, 0xaaaa5a5a, break_table,
  1346. select_table);
  1347. break;
  1348. case 15:
  1349. halbtc8822b1ant_coex_table(btcoexist, force_exec,
  1350. 0x55555555, 0xaaaa55aa, break_table,
  1351. select_table);
  1352. break;
  1353. case 16:
  1354. halbtc8822b1ant_coex_table(btcoexist, force_exec,
  1355. 0x5a5a555a, 0x5a5a555a, break_table,
  1356. select_table);
  1357. break;
  1358. case 17:
  1359. halbtc8822b1ant_coex_table(btcoexist, force_exec,
  1360. 0xaaaa55aa, 0xaaaa55aa, break_table,
  1361. select_table);
  1362. break;
  1363. default:
  1364. break;
  1365. }
  1366. }
  1367. void halbtc8822b1ant_set_fw_ignore_wlan_act(IN struct btc_coexist *btcoexist,
  1368. IN boolean enable)
  1369. {
  1370. u8 h2c_parameter[1] = {0};
  1371. if (enable)
  1372. h2c_parameter[0] |= BIT(0); /* function enable */
  1373. btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter);
  1374. }
  1375. void halbtc8822b1ant_ignore_wlan_act(IN struct btc_coexist *btcoexist,
  1376. IN boolean force_exec, IN boolean enable)
  1377. {
  1378. coex_dm->cur_ignore_wlan_act = enable;
  1379. if (!force_exec) {
  1380. if (coex_dm->pre_ignore_wlan_act ==
  1381. coex_dm->cur_ignore_wlan_act) {
  1382. coex_dm->pre_ignore_wlan_act =
  1383. coex_dm->cur_ignore_wlan_act;
  1384. return;
  1385. }
  1386. }
  1387. halbtc8822b1ant_set_fw_ignore_wlan_act(btcoexist, enable);
  1388. coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act;
  1389. }
  1390. void halbtc8822b1ant_set_lps_rpwm(IN struct btc_coexist *btcoexist,
  1391. IN u8 lps_val, IN u8 rpwm_val)
  1392. {
  1393. u8 lps = lps_val;
  1394. u8 rpwm = rpwm_val;
  1395. btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps);
  1396. btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
  1397. }
  1398. void halbtc8822b1ant_lps_rpwm(IN struct btc_coexist *btcoexist,
  1399. IN boolean force_exec, IN u8 lps_val, IN u8 rpwm_val)
  1400. {
  1401. coex_dm->cur_lps = lps_val;
  1402. coex_dm->cur_rpwm = rpwm_val;
  1403. if (!force_exec) {
  1404. if ((coex_dm->pre_lps == coex_dm->cur_lps) &&
  1405. (coex_dm->pre_rpwm == coex_dm->cur_rpwm))
  1406. return;
  1407. }
  1408. halbtc8822b1ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val);
  1409. coex_dm->pre_lps = coex_dm->cur_lps;
  1410. coex_dm->pre_rpwm = coex_dm->cur_rpwm;
  1411. }
  1412. void halbtc8822b1ant_ps_tdma_check_for_power_save_state(
  1413. IN struct btc_coexist *btcoexist, IN boolean new_ps_state)
  1414. {
  1415. u8 lps_mode = 0x0;
  1416. u8 h2c_parameter[5] = {0x8, 0, 0, 0, 0};
  1417. btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode);
  1418. if (lps_mode) { /* already under LPS state */
  1419. if (new_ps_state) {
  1420. /* keep state under LPS, do nothing. */
  1421. } else {
  1422. /* will leave LPS state, turn off psTdma first */
  1423. btcoexist->btc_fill_h2c(btcoexist, 0x60, 5,
  1424. h2c_parameter);
  1425. }
  1426. } else { /* NO PS state */
  1427. if (new_ps_state) {
  1428. /* will enter LPS state, turn off psTdma first */
  1429. btcoexist->btc_fill_h2c(btcoexist, 0x60, 5,
  1430. h2c_parameter);
  1431. } else {
  1432. /* keep state under NO PS state, do nothing. */
  1433. }
  1434. }
  1435. }
  1436. void halbtc8822b1ant_power_save_state(IN struct btc_coexist *btcoexist,
  1437. IN u8 ps_type, IN u8 lps_val, IN u8 rpwm_val)
  1438. {
  1439. boolean low_pwr_disable = false;
  1440. switch (ps_type) {
  1441. case BTC_PS_WIFI_NATIVE:
  1442. /* recover to original 32k low power setting */
  1443. coex_sta->force_lps_on = false;
  1444. low_pwr_disable = false;
  1445. btcoexist->btc_set(btcoexist,
  1446. BTC_SET_ACT_DISABLE_LOW_POWER,
  1447. &low_pwr_disable);
  1448. btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS,
  1449. NULL);
  1450. coex_sta->force_lps_on = false;
  1451. break;
  1452. case BTC_PS_LPS_ON:
  1453. coex_sta->force_lps_on = true;
  1454. halbtc8822b1ant_ps_tdma_check_for_power_save_state(
  1455. btcoexist, true);
  1456. halbtc8822b1ant_lps_rpwm(btcoexist, NORMAL_EXEC,
  1457. lps_val, rpwm_val);
  1458. /* when coex force to enter LPS, do not enter 32k low power. */
  1459. low_pwr_disable = true;
  1460. btcoexist->btc_set(btcoexist,
  1461. BTC_SET_ACT_DISABLE_LOW_POWER,
  1462. &low_pwr_disable);
  1463. /* power save must executed before psTdma. */
  1464. btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS,
  1465. NULL);
  1466. coex_sta->force_lps_on = true;
  1467. break;
  1468. case BTC_PS_LPS_OFF:
  1469. coex_sta->force_lps_on = false;
  1470. halbtc8822b1ant_ps_tdma_check_for_power_save_state(
  1471. btcoexist, false);
  1472. btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS,
  1473. NULL);
  1474. coex_sta->force_lps_on = false;
  1475. break;
  1476. default:
  1477. break;
  1478. }
  1479. }
  1480. void halbtc8822b1ant_set_fw_pstdma(IN struct btc_coexist *btcoexist,
  1481. IN u8 byte1, IN u8 byte2, IN u8 byte3, IN u8 byte4, IN u8 byte5)
  1482. {
  1483. u8 h2c_parameter[5] = {0};
  1484. u8 real_byte1 = byte1, real_byte5 = byte5;
  1485. boolean ap_enable = false;
  1486. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
  1487. &ap_enable);
  1488. if (ap_enable) {
  1489. if (byte1 & BIT(4) && !(byte1 & BIT(5))) {
  1490. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1491. "[BTCoex], FW for 1Ant AP mode\n");
  1492. BTC_TRACE(trace_buf);
  1493. real_byte1 &= ~BIT(4);
  1494. real_byte1 |= BIT(5);
  1495. real_byte5 |= BIT(5);
  1496. real_byte5 &= ~BIT(6);
  1497. halbtc8822b1ant_power_save_state(btcoexist,
  1498. BTC_PS_WIFI_NATIVE, 0x0,
  1499. 0x0);
  1500. }
  1501. } else if (byte1 & BIT(4) && !(byte1 & BIT(5))) {
  1502. halbtc8822b1ant_power_save_state(btcoexist,
  1503. BTC_PS_LPS_ON, 0x50,
  1504. 0x4);
  1505. } else {
  1506. halbtc8822b1ant_power_save_state(btcoexist,
  1507. BTC_PS_WIFI_NATIVE, 0x0,
  1508. 0x0);
  1509. }
  1510. h2c_parameter[0] = real_byte1;
  1511. h2c_parameter[1] = byte2;
  1512. h2c_parameter[2] = byte3;
  1513. h2c_parameter[3] = byte4;
  1514. h2c_parameter[4] = real_byte5;
  1515. coex_dm->ps_tdma_para[0] = real_byte1;
  1516. coex_dm->ps_tdma_para[1] = byte2;
  1517. coex_dm->ps_tdma_para[2] = byte3;
  1518. coex_dm->ps_tdma_para[3] = byte4;
  1519. coex_dm->ps_tdma_para[4] = real_byte5;
  1520. btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter);
  1521. }
  1522. void halbtc8822b1ant_ps_tdma(IN struct btc_coexist *btcoexist,
  1523. IN boolean force_exec, IN boolean turn_on, IN u8 type)
  1524. {
  1525. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1526. struct btc_board_info *board_info = &btcoexist->board_info;
  1527. boolean wifi_busy = false;
  1528. static u8 psTdmaByte4Modify = 0x0, pre_psTdmaByte4Modify = 0x0;
  1529. static boolean pre_wifi_busy = false;
  1530. coex_dm->cur_ps_tdma_on = turn_on;
  1531. coex_dm->cur_ps_tdma = type;
  1532. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  1533. if (wifi_busy != pre_wifi_busy) {
  1534. force_exec = true;
  1535. pre_wifi_busy = wifi_busy;
  1536. }
  1537. /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */
  1538. if ((bt_link_info->slave_role) && (bt_link_info->a2dp_exist))
  1539. psTdmaByte4Modify = 0x1;
  1540. else
  1541. psTdmaByte4Modify = 0x0;
  1542. if (pre_psTdmaByte4Modify != psTdmaByte4Modify) {
  1543. force_exec = true;
  1544. pre_psTdmaByte4Modify = psTdmaByte4Modify;
  1545. }
  1546. if (coex_dm->cur_ps_tdma_on) {
  1547. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1548. "[BTCoex], ********TDMA(on, %d) **********\n",
  1549. coex_dm->cur_ps_tdma);
  1550. BTC_TRACE(trace_buf);
  1551. } else {
  1552. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1553. "[BTCoex], **********TDMA(off, %d) **********\n",
  1554. coex_dm->cur_ps_tdma);
  1555. BTC_TRACE(trace_buf);
  1556. }
  1557. if (!force_exec) {
  1558. if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) &&
  1559. (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma)) {
  1560. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1561. "[BTCoex], return for no-TDMA case change\n");
  1562. BTC_TRACE(trace_buf);
  1563. return;
  1564. }
  1565. }
  1566. if (turn_on) {
  1567. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x550, 0x8,
  1568. 0x1); /* enable TBTT nterrupt */
  1569. switch (type) {
  1570. default:
  1571. halbtc8822b1ant_set_fw_pstdma(btcoexist,
  1572. 0x51, 0x1a, 0x1a, 0x0, 0x10);
  1573. break;
  1574. case 1:
  1575. halbtc8822b1ant_set_fw_pstdma(btcoexist,
  1576. 0x61, 0x3a, 0x03, 0x11, 0x10);
  1577. break;
  1578. case 3:
  1579. halbtc8822b1ant_set_fw_pstdma(btcoexist,
  1580. 0x51, 0x3a, 0x03, 0x10, 0x10);
  1581. break;
  1582. case 4:
  1583. halbtc8822b1ant_set_fw_pstdma(btcoexist,
  1584. 0x51, 0x21, 0x03, 0x10, 0x10);
  1585. break;
  1586. case 5:
  1587. halbtc8822b1ant_set_fw_pstdma(btcoexist,
  1588. 0x61, 0x15, 0x3, 0x11, 0x11);
  1589. break;
  1590. case 7:
  1591. halbtc8822b1ant_set_fw_pstdma(btcoexist,
  1592. 0x61, 0x10, 0x03, 0x10, 0x14 |
  1593. psTdmaByte4Modify);
  1594. break;
  1595. case 8:
  1596. halbtc8822b1ant_set_fw_pstdma(btcoexist,
  1597. 0x51, 0x10, 0x03, 0x10, 0x14 |
  1598. psTdmaByte4Modify);
  1599. break;
  1600. case 13:
  1601. halbtc8822b1ant_set_fw_pstdma(btcoexist,
  1602. 0x51, 0x25, 0x03, 0x10, 0x10 |
  1603. psTdmaByte4Modify);
  1604. break;
  1605. case 14:
  1606. halbtc8822b1ant_set_fw_pstdma(btcoexist,
  1607. 0x51, 0x15, 0x03, 0x10, 0x10 |
  1608. psTdmaByte4Modify);
  1609. break;
  1610. case 15:
  1611. halbtc8822b1ant_set_fw_pstdma(btcoexist,
  1612. 0x51, 0x20, 0x03, 0x10, 0x10 |
  1613. psTdmaByte4Modify);
  1614. break;
  1615. case 17:
  1616. halbtc8822b1ant_set_fw_pstdma(btcoexist,
  1617. 0x61, 0x10, 0x03, 0x11, 0x14 |
  1618. psTdmaByte4Modify);
  1619. break;
  1620. case 20:
  1621. halbtc8822b1ant_set_fw_pstdma(btcoexist,
  1622. 0x61, 0x30, 0x03, 0x11, 0x10);
  1623. break;
  1624. case 22:
  1625. halbtc8822b1ant_set_fw_pstdma(btcoexist,
  1626. 0x61, 0x25, 0x03, 0x11, 0x10);
  1627. break;
  1628. case 32:
  1629. halbtc8822b1ant_set_fw_pstdma(btcoexist,
  1630. 0x61, 0x35, 0x3, 0x11, 0x11);
  1631. break;
  1632. case 33:
  1633. halbtc8822b1ant_set_fw_pstdma(btcoexist,
  1634. 0x61, 0x35, 0x03, 0x11, 0x10);
  1635. break;
  1636. case 41:
  1637. halbtc8822b1ant_set_fw_pstdma(btcoexist,
  1638. 0x51, 0x45, 0x3, 0x11, 0x11);
  1639. break;
  1640. case 42:
  1641. halbtc8822b1ant_set_fw_pstdma(btcoexist,
  1642. 0x51, 0x1e, 0x3, 0x10, 0x14 |
  1643. psTdmaByte4Modify);
  1644. break;
  1645. case 43:
  1646. halbtc8822b1ant_set_fw_pstdma(btcoexist,
  1647. 0x51, 0x45, 0x3, 0x10, 0x14);
  1648. break;
  1649. case 44:
  1650. halbtc8822b1ant_set_fw_pstdma(btcoexist,
  1651. 0x51, 0x25, 0x3, 0x10, 0x10);
  1652. break;
  1653. case 45:
  1654. halbtc8822b1ant_set_fw_pstdma(btcoexist,
  1655. 0x51, 0x29, 0x3, 0x10, 0x10);
  1656. break;
  1657. case 46:
  1658. halbtc8822b1ant_set_fw_pstdma(btcoexist,
  1659. 0x51, 0x1a, 0x3, 0x10, 0x10);
  1660. break;
  1661. case 47:
  1662. halbtc8822b1ant_set_fw_pstdma(btcoexist,
  1663. 0x51, 0x32, 0x3, 0x10, 0x10);
  1664. break;
  1665. case 48:
  1666. halbtc8822b1ant_set_fw_pstdma(btcoexist,
  1667. 0x51, 0x29, 0x3, 0x10, 0x10);
  1668. break;
  1669. case 49:
  1670. halbtc8822b1ant_set_fw_pstdma(btcoexist,
  1671. 0x55, 0x1e, 0x3, 0x10, 0x54);
  1672. break;
  1673. case 50:
  1674. halbtc8822b1ant_set_fw_pstdma(btcoexist,
  1675. 0x51, 0x4a, 0x3, 0x10, 0x10);
  1676. break;
  1677. }
  1678. } else {
  1679. switch (type) {
  1680. case 0:
  1681. default: /* Software control, Antenna at BT side */
  1682. halbtc8822b1ant_set_fw_pstdma(btcoexist,
  1683. 0x0, 0x0, 0x0, 0x0, 0x0);
  1684. /*
  1685. halbtc8822b1ant_set_ant_path(btcoexist,
  1686. BTC_ANT_PATH_BT, FORCE_EXEC, false,
  1687. false); */
  1688. break;
  1689. case 8: /* PTA Control */
  1690. halbtc8822b1ant_set_fw_pstdma(btcoexist,
  1691. 0x8, 0x0, 0x0, 0x0, 0x0);
  1692. /*
  1693. halbtc8822b1ant_set_ant_path(btcoexist,
  1694. BTC_ANT_PATH_PTA, FORCE_EXEC, false,
  1695. false); */
  1696. break;
  1697. case 9: /* Software control, Antenna at WiFi side */
  1698. halbtc8822b1ant_set_fw_pstdma(btcoexist,
  1699. 0x0, 0x0, 0x0, 0x0, 0x0);
  1700. /*
  1701. halbtc8822b1ant_set_ant_path(btcoexist,
  1702. BTC_ANT_PATH_WIFI, FORCE_EXEC,false,false); */
  1703. break;
  1704. case 10: /* under 5G , 0x778=1*/
  1705. halbtc8822b1ant_set_fw_pstdma(btcoexist,
  1706. 0x0, 0x0, 0x0, 0x0, 0x0);
  1707. /*
  1708. halbtc8822b1ant_set_ant_path(btcoexist,
  1709. BTC_ANT_PATH_WIFI5G, FORCE_EXEC, false,
  1710. false); */
  1711. break;
  1712. }
  1713. }
  1714. /* update pre state */
  1715. coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on;
  1716. coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma;
  1717. }
  1718. void halbtc8822b1ant_sw_mechanism(IN struct btc_coexist *btcoexist,
  1719. IN boolean low_penalty_ra)
  1720. {
  1721. halbtc8822b1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra);
  1722. }
  1723. /*rf4 type by efuse , and for ant at main aux inverse use , because is 2x2 ,and control types are the same ,does not need */
  1724. void halbtc8822b1ant_set_rfe_type(IN struct btc_coexist *btcoexist)
  1725. {
  1726. struct btc_board_info *board_info = &btcoexist->board_info;
  1727. /* Ext switch buffer mux */
  1728. btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff);
  1729. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991, 0x3, 0x0);
  1730. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe, 0x8, 0x0);
  1731. /* the following setup should be got from Efuse in the future */
  1732. rfe_type->rfe_module_type = board_info->rfe_type;
  1733. rfe_type->ext_ant_switch_ctrl_polarity = 0;
  1734. switch (rfe_type->rfe_module_type) {
  1735. case 0:
  1736. default:
  1737. rfe_type->ext_ant_switch_exist = true;
  1738. rfe_type->ext_ant_switch_type =
  1739. BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SPDT;
  1740. break;
  1741. case 1:
  1742. rfe_type->ext_ant_switch_exist = true;
  1743. rfe_type->ext_ant_switch_type =
  1744. BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SPDT;
  1745. break;
  1746. case 2:
  1747. rfe_type->ext_ant_switch_exist = true;
  1748. rfe_type->ext_ant_switch_type =
  1749. BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SPDT;
  1750. break;
  1751. case 3:
  1752. rfe_type->ext_ant_switch_exist = true;
  1753. rfe_type->ext_ant_switch_type =
  1754. BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SPDT;
  1755. break;
  1756. case 4:
  1757. rfe_type->ext_ant_switch_exist = true;
  1758. rfe_type->ext_ant_switch_type =
  1759. BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SPDT;
  1760. break;
  1761. case 5:
  1762. rfe_type->ext_ant_switch_exist = true;
  1763. rfe_type->ext_ant_switch_type =
  1764. BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SPDT;
  1765. break;
  1766. case 6:
  1767. rfe_type->ext_ant_switch_exist = true;
  1768. rfe_type->ext_ant_switch_type =
  1769. BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SPDT;
  1770. break;
  1771. case 7:
  1772. rfe_type->ext_ant_switch_exist = true;
  1773. rfe_type->ext_ant_switch_type =
  1774. BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SPDT;
  1775. break;
  1776. }
  1777. }
  1778. /*anttenna control by bb mac bt antdiv pta to write 0x4c 0xcb4,0xcbd*/
  1779. void halbtc8822b1ant_set_ext_ant_switch(IN struct btc_coexist *btcoexist,
  1780. IN boolean force_exec, IN u8 ctrl_type, IN u8 pos_type)
  1781. {
  1782. struct btc_board_info *board_info = &btcoexist->board_info;
  1783. boolean switch_polatiry_inverse = false;
  1784. u8 regval_0xcbd = 0, regval_0x64;
  1785. u32 u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0;
  1786. /* Ext switch buffer mux */
  1787. btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff);
  1788. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991, 0x3, 0x0);
  1789. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe, 0x8, 0x0);
  1790. if (!rfe_type->ext_ant_switch_exist)
  1791. return;
  1792. coex_dm->cur_ext_ant_switch_status = (ctrl_type << 8) + pos_type;
  1793. if (!force_exec) {
  1794. if (coex_dm->pre_ext_ant_switch_status ==
  1795. coex_dm->cur_ext_ant_switch_status)
  1796. return;
  1797. }
  1798. coex_dm->pre_ext_ant_switch_status = coex_dm->cur_ext_ant_switch_status;
  1799. /* swap control polarity if use different switch control polarity*/
  1800. /* Normal switch polarity for SPDT, 0xcbd[1:0] = 2b'01 => Ant to BTG, 0xcbd[1:0] = 2b'10 => Ant to WLG */
  1801. switch_polatiry_inverse = (rfe_type->ext_ant_switch_ctrl_polarity == 1 ?
  1802. ~switch_polatiry_inverse : switch_polatiry_inverse);
  1803. switch (pos_type) {
  1804. default:
  1805. case BT_8822B_1ANT_EXT_ANT_SWITCH_TO_BT:
  1806. case BT_8822B_1ANT_EXT_ANT_SWITCH_TO_NOCARE:
  1807. break;
  1808. case BT_8822B_1ANT_EXT_ANT_SWITCH_TO_WLG:
  1809. break;
  1810. case BT_8822B_1ANT_EXT_ANT_SWITCH_TO_WLA:
  1811. break;
  1812. }
  1813. if (rfe_type->ext_ant_switch_type ==
  1814. BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SPDT) {
  1815. switch (ctrl_type) {
  1816. default:
  1817. case BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW:
  1818. btcoexist->btc_write_1byte_bitmask(
  1819. btcoexist, 0x4e, 0x80,
  1820. 0x0); /* 0x4c[23] = 0 */
  1821. btcoexist->btc_write_1byte_bitmask(
  1822. btcoexist, 0x4f, 0x01,
  1823. 0x1); /* 0x4c[24] = 1 */
  1824. btcoexist->btc_write_1byte_bitmask(
  1825. btcoexist, 0xcb4, 0xff,
  1826. 0x77); /* BB SW, DPDT use RFE_ctrl8 and RFE_ctrl9 as conctrol pin */
  1827. regval_0xcbd = (switch_polatiry_inverse
  1828. == false ? 0x1 :
  1829. 0x2); /* 0xcbd[1:0] = 2b'01 for no switch_polatiry_inverse, ANTSWB =1, ANTSW =0 */
  1830. btcoexist->btc_write_1byte_bitmask(
  1831. btcoexist, 0xcbd, 0x3,
  1832. regval_0xcbd);
  1833. break;
  1834. case BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_PTA:
  1835. btcoexist->btc_write_1byte_bitmask(
  1836. btcoexist, 0x4e, 0x80,
  1837. 0x0); /* 0x4c[23] = 0 */
  1838. btcoexist->btc_write_1byte_bitmask(
  1839. btcoexist, 0x4f, 0x01,
  1840. 0x1); /* 0x4c[24] = 1 */
  1841. btcoexist->btc_write_1byte_bitmask(
  1842. btcoexist, 0xcb4, 0xff,
  1843. 0x66); /* PTA, DPDT use RFE_ctrl8 and RFE_ctrl9 as conctrol pin */
  1844. regval_0xcbd = (switch_polatiry_inverse
  1845. == false ? 0x2 :
  1846. 0x1); /* 0xcbd[1:0] = 2b'10 for no switch_polatiry_inverse, ANTSWB =1, ANTSW =0 @ GNT_BT=1 */
  1847. btcoexist->btc_write_1byte_bitmask(
  1848. btcoexist, 0xcbd, 0x3,
  1849. regval_0xcbd);
  1850. break;
  1851. case BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_ANTDIV
  1852. :
  1853. btcoexist->btc_write_1byte_bitmask(
  1854. btcoexist, 0x4e, 0x80,
  1855. 0x0); /* 0x4c[23] = 0 */
  1856. btcoexist->btc_write_1byte_bitmask(
  1857. btcoexist, 0x4f, 0x01,
  1858. 0x1); /* 0x4c[24] = 1 */
  1859. btcoexist->btc_write_1byte_bitmask(
  1860. btcoexist, 0xcb4, 0xff,
  1861. 0x88); /* */
  1862. /* no regval_0xcbd setup required, because antenna switch control value by antenna diversity */
  1863. break;
  1864. case BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_MAC:
  1865. btcoexist->btc_write_1byte_bitmask(
  1866. btcoexist, 0x4e, 0x80,
  1867. 0x1); /* 0x4c[23] = 1 */
  1868. regval_0x64 = (switch_polatiry_inverse
  1869. == false ? 0x0 :
  1870. 0x1); /* 0x64[0] = 1b'0 for no switch_polatiry_inverse, DPDT_SEL_N =1, DPDT_SEL_P =0 */
  1871. btcoexist->btc_write_1byte_bitmask(
  1872. btcoexist, 0x64, 0x1,
  1873. regval_0x64);
  1874. break;
  1875. case BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_BT:
  1876. btcoexist->btc_write_1byte_bitmask(
  1877. btcoexist, 0x4e, 0x80,
  1878. 0x0); /* 0x4c[23] = 0 */
  1879. btcoexist->btc_write_1byte_bitmask(
  1880. btcoexist, 0x4f, 0x01,
  1881. 0x0); /* 0x4c[24] = 0 */
  1882. /* no setup required, because antenna switch control value by BT vendor 0xac[1:0] */
  1883. break;
  1884. }
  1885. }
  1886. u32tmp1 = btcoexist->btc_read_4byte(btcoexist, 0xcbc);
  1887. u32tmp2 = btcoexist->btc_read_4byte(btcoexist, 0x4c);
  1888. u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0x64) & 0xff;
  1889. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1890. "[BTCoex], ********** (After Ext Ant switch setup) 0xcbc = 0x%08x, 0x4c = 0x%08x, 0x64= 0x%02x**********\n",
  1891. u32tmp1, u32tmp2, u32tmp3);
  1892. BTC_TRACE(trace_buf);
  1893. }
  1894. /*set gnt_wl gnt_bt control by sw high low , or hwpta while in power on,ini,wlan off,wlan only ,wl2g non-currrent ,wl2g current,wl5g*/
  1895. void halbtc8822b1ant_set_ant_path(IN struct btc_coexist *btcoexist,
  1896. IN u8 ant_pos_type, IN boolean force_exec,
  1897. IN u8 phase)
  1898. {
  1899. struct btc_board_info *board_info = &btcoexist->board_info;
  1900. u8 u8tmp = 0;
  1901. u32 u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0;
  1902. /* Ext switch buffer mux */
  1903. btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff);
  1904. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991, 0x3, 0x0);
  1905. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe, 0x8, 0x0);
  1906. coex_dm->cur_ant_pos_type = (ant_pos_type << 8) + phase;
  1907. if (!force_exec) {
  1908. if (coex_dm->cur_ant_pos_type ==
  1909. coex_dm->pre_ant_pos_type)
  1910. return;
  1911. }
  1912. coex_dm->pre_ant_pos_type = coex_dm->cur_ant_pos_type;
  1913. #if 1
  1914. u32tmp1 = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
  1915. 0x38);
  1916. u32tmp2 = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
  1917. 0x54);
  1918. u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
  1919. u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x73);
  1920. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1921. "[BTCoex], ********** (Before Ant Setup) 0xcb4 = 0x%x, 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x**********\n",
  1922. u32tmp3, u8tmp, u32tmp1, u32tmp2);
  1923. BTC_TRACE(trace_buf);
  1924. #endif
  1925. switch (phase) {
  1926. case BT_8822B_1ANT_PHASE_COEX_INIT:
  1927. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1928. "[BTCoex], ********** (set_ant_path - 1ANT_PHASE_COEX_INIT) **********\n");
  1929. BTC_TRACE(trace_buf);
  1930. /* Disable LTE Coex Function in WiFi side (this should be on if LTE coex is required) */
  1931. halbtc8822b1ant_ltecoex_enable(btcoexist, 0x0);
  1932. /* GNT_WL_LTE always = 1 (this should be config if LTE coex is required) */
  1933. halbtc8822b1ant_ltecoex_set_coex_table(btcoexist,
  1934. BT_8822B_1ANT_CTT_WL_VS_LTE,
  1935. 0xffff);
  1936. /* GNT_BT_LTE always = 1 (this should be config if LTE coex is required) */
  1937. halbtc8822b1ant_ltecoex_set_coex_table(btcoexist,
  1938. BT_8822B_1ANT_CTT_BT_VS_LTE,
  1939. 0xffff);
  1940. /* set GNT_BT to SW high */
  1941. halbtc8822b1ant_ltecoex_set_gnt_bt(btcoexist,
  1942. BT_8822B_1ANT_GNT_BLOCK_RFC_BB,
  1943. BT_8822B_1ANT_GNT_CTRL_BY_SW,
  1944. BT_8822B_1ANT_SIG_STA_SET_TO_HIGH);
  1945. /* set GNT_WL to SW low */
  1946. halbtc8822b1ant_ltecoex_set_gnt_wl(btcoexist,
  1947. BT_8822B_1ANT_GNT_BLOCK_RFC_BB,
  1948. BT_8822B_1ANT_GNT_CTRL_BY_SW,
  1949. BT_8822B_1ANT_SIG_STA_SET_TO_LOW);
  1950. /* set Path control owner to WL at initial step */
  1951. halbtc8822b1ant_ltecoex_pathcontrol_owner(btcoexist,
  1952. BT_8822B_1ANT_PCO_WLSIDE);
  1953. coex_sta->run_time_state = false;
  1954. /* Ext switch buffer mux */
  1955. btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff);
  1956. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991,
  1957. 0x3, 0x0);
  1958. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe,
  1959. 0x8, 0x0);
  1960. if (BTC_ANT_PATH_AUTO == ant_pos_type)
  1961. ant_pos_type = BTC_ANT_PATH_BT;
  1962. break;
  1963. case BT_8822B_1ANT_PHASE_WLANONLY_INIT:
  1964. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1965. "[BTCoex], ********** (set_ant_path - 1ANT_PHASE_WLANONLY_INIT) **********\n");
  1966. BTC_TRACE(trace_buf);
  1967. /* Disable LTE Coex Function in WiFi side (this should be on if LTE coex is required) */
  1968. halbtc8822b1ant_ltecoex_enable(btcoexist, 0x0);
  1969. /* GNT_WL_LTE always = 1 (this should be config if LTE coex is required) */
  1970. halbtc8822b1ant_ltecoex_set_coex_table(btcoexist,
  1971. BT_8822B_1ANT_CTT_WL_VS_LTE,
  1972. 0xffff);
  1973. /* GNT_BT_LTE always = 1 (this should be config if LTE coex is required) */
  1974. halbtc8822b1ant_ltecoex_set_coex_table(btcoexist,
  1975. BT_8822B_1ANT_CTT_BT_VS_LTE,
  1976. 0xffff);
  1977. /* set GNT_BT to SW Low */
  1978. halbtc8822b1ant_ltecoex_set_gnt_bt(btcoexist,
  1979. BT_8822B_1ANT_GNT_BLOCK_RFC_BB,
  1980. BT_8822B_1ANT_GNT_CTRL_BY_SW,
  1981. BT_8822B_1ANT_SIG_STA_SET_TO_LOW);
  1982. /* Set GNT_WL to SW high */
  1983. halbtc8822b1ant_ltecoex_set_gnt_wl(btcoexist,
  1984. BT_8822B_1ANT_GNT_BLOCK_RFC_BB,
  1985. BT_8822B_1ANT_GNT_CTRL_BY_SW,
  1986. BT_8822B_1ANT_SIG_STA_SET_TO_HIGH);
  1987. /* set Path control owner to WL at initial step */
  1988. halbtc8822b1ant_ltecoex_pathcontrol_owner(btcoexist,
  1989. BT_8822B_1ANT_PCO_WLSIDE);
  1990. coex_sta->run_time_state = false;
  1991. /* Ext switch buffer mux */
  1992. btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff);
  1993. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991,
  1994. 0x3, 0x0);
  1995. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe,
  1996. 0x8, 0x0);
  1997. if (BTC_ANT_PATH_AUTO == ant_pos_type)
  1998. ant_pos_type = BTC_ANT_PATH_WIFI;
  1999. break;
  2000. case BT_8822B_1ANT_PHASE_WLAN_OFF:
  2001. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2002. "[BTCoex], ********** (set_ant_path - 1ANT_PHASE_WLAN_OFF) **********\n");
  2003. BTC_TRACE(trace_buf);
  2004. /* Disable LTE Coex Function in WiFi side */
  2005. halbtc8822b1ant_ltecoex_enable(btcoexist, 0x0);
  2006. /* set Path control owner to BT */
  2007. halbtc8822b1ant_ltecoex_pathcontrol_owner(btcoexist,
  2008. BT_8822B_1ANT_PCO_BTSIDE);
  2009. /* Set Ext Ant Switch to BT control at wifi off step */
  2010. halbtc8822b1ant_set_ext_ant_switch(btcoexist,
  2011. FORCE_EXEC,
  2012. BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_BT,
  2013. BT_8822B_1ANT_EXT_ANT_SWITCH_TO_NOCARE);
  2014. coex_sta->run_time_state = false;
  2015. break;
  2016. case BT_8822B_1ANT_PHASE_2G_RUNTIME:
  2017. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2018. "[BTCoex], ********** (set_ant_path - 1ANT_PHASE_2G_RUNTIME) **********\n");
  2019. BTC_TRACE(trace_buf);
  2020. /* set GNT_BT to PTA */
  2021. halbtc8822b1ant_ltecoex_set_gnt_bt(btcoexist,
  2022. BT_8822B_1ANT_GNT_BLOCK_RFC_BB,
  2023. BT_8822B_1ANT_GNT_CTRL_BY_PTA,
  2024. BT_8822B_1ANT_SIG_STA_SET_BY_HW);
  2025. /* Set GNT_WL to PTA */
  2026. halbtc8822b1ant_ltecoex_set_gnt_wl(btcoexist,
  2027. BT_8822B_1ANT_GNT_BLOCK_RFC_BB,
  2028. BT_8822B_1ANT_GNT_CTRL_BY_PTA,
  2029. BT_8822B_1ANT_SIG_STA_SET_BY_HW);
  2030. /* set Path control owner to WL at runtime step */
  2031. halbtc8822b1ant_ltecoex_pathcontrol_owner(btcoexist,
  2032. BT_8822B_1ANT_PCO_WLSIDE);
  2033. coex_sta->run_time_state = true;
  2034. if (BTC_ANT_PATH_AUTO == ant_pos_type)
  2035. ant_pos_type = BTC_ANT_PATH_PTA;
  2036. break;
  2037. case BT_8822B_1ANT_PHASE_5G_RUNTIME:
  2038. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2039. "[BTCoex], ********** (set_ant_path - 1ANT_PHASE_5G_RUNTIME) **********\n");
  2040. BTC_TRACE(trace_buf);
  2041. /* set GNT_BT to SW Hi */
  2042. halbtc8822b1ant_ltecoex_set_gnt_bt(btcoexist,
  2043. BT_8822B_1ANT_GNT_BLOCK_RFC_BB,
  2044. BT_8822B_1ANT_GNT_CTRL_BY_SW,
  2045. BT_8822B_1ANT_SIG_STA_SET_TO_HIGH);
  2046. /* Set GNT_WL to SW Hi */
  2047. halbtc8822b1ant_ltecoex_set_gnt_wl(btcoexist,
  2048. BT_8822B_1ANT_GNT_BLOCK_RFC_BB,
  2049. BT_8822B_1ANT_GNT_CTRL_BY_SW,
  2050. BT_8822B_1ANT_SIG_STA_SET_TO_HIGH);
  2051. /* set Path control owner to WL at runtime step */
  2052. halbtc8822b1ant_ltecoex_pathcontrol_owner(btcoexist,
  2053. BT_8822B_1ANT_PCO_WLSIDE);
  2054. coex_sta->run_time_state = true;
  2055. if (BTC_ANT_PATH_AUTO == ant_pos_type)
  2056. ant_pos_type =
  2057. BTC_ANT_PATH_WIFI5G;
  2058. break;
  2059. case BT_8822B_1ANT_PHASE_BTMPMODE:
  2060. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2061. "[BTCoex], ********** (set_ant_path - 1ANT_PHASE_BTMPMODE) **********\n");
  2062. BTC_TRACE(trace_buf);
  2063. /* Disable LTE Coex Function in WiFi side */
  2064. halbtc8822b1ant_ltecoex_enable(btcoexist, 0x0);
  2065. /* set GNT_BT to SW Hi */
  2066. halbtc8822b1ant_ltecoex_set_gnt_bt(btcoexist,
  2067. BT_8822B_1ANT_GNT_BLOCK_RFC_BB,
  2068. BT_8822B_1ANT_GNT_CTRL_BY_SW,
  2069. BT_8822B_1ANT_SIG_STA_SET_TO_HIGH);
  2070. /* Set GNT_WL to SW Lo */
  2071. halbtc8822b1ant_ltecoex_set_gnt_wl(btcoexist,
  2072. BT_8822B_1ANT_GNT_BLOCK_RFC_BB,
  2073. BT_8822B_1ANT_GNT_CTRL_BY_SW,
  2074. BT_8822B_1ANT_SIG_STA_SET_TO_LOW);
  2075. /* set Path control owner to WL */
  2076. halbtc8822b1ant_ltecoex_pathcontrol_owner(btcoexist,
  2077. BT_8822B_1ANT_PCO_WLSIDE);
  2078. coex_sta->run_time_state = false;
  2079. /* Set Ext Ant Switch to BT side at BT MP mode */
  2080. if (BTC_ANT_PATH_AUTO == ant_pos_type)
  2081. ant_pos_type = BTC_ANT_PATH_BT;
  2082. break;
  2083. }
  2084. if (phase != BT_8822B_1ANT_PHASE_WLAN_OFF) {
  2085. switch (ant_pos_type) {
  2086. case BTC_ANT_PATH_WIFI:
  2087. halbtc8822b1ant_set_ext_ant_switch(
  2088. btcoexist,
  2089. force_exec,
  2090. BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW,
  2091. BT_8822B_1ANT_EXT_ANT_SWITCH_TO_WLG);
  2092. break;
  2093. case BTC_ANT_PATH_WIFI5G
  2094. :
  2095. halbtc8822b1ant_set_ext_ant_switch(
  2096. btcoexist,
  2097. force_exec,
  2098. BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW,
  2099. BT_8822B_1ANT_EXT_ANT_SWITCH_TO_WLA);
  2100. break;
  2101. case BTC_ANT_PATH_BT:
  2102. halbtc8822b1ant_set_ext_ant_switch(
  2103. btcoexist,
  2104. force_exec,
  2105. BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW,
  2106. BT_8822B_1ANT_EXT_ANT_SWITCH_TO_BT);
  2107. break;
  2108. default:
  2109. case BTC_ANT_PATH_PTA:
  2110. halbtc8822b1ant_set_ext_ant_switch(
  2111. btcoexist,
  2112. force_exec,
  2113. BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_PTA,
  2114. BT_8822B_1ANT_EXT_ANT_SWITCH_TO_NOCARE);
  2115. break;
  2116. }
  2117. }
  2118. #if 1
  2119. u32tmp1 = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, 0x38);
  2120. u32tmp2 = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, 0x54);
  2121. u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
  2122. u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x73);
  2123. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2124. "[BTCoex], ********** (After Ant Setup) 0xcb4 = 0x%x, 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x**********\n",
  2125. u32tmp3, u8tmp, u32tmp1, u32tmp2);
  2126. BTC_TRACE(trace_buf);
  2127. #endif
  2128. }
  2129. void halbtc8822b1ant_coex_all_off(IN struct btc_coexist *btcoexist)
  2130. {
  2131. /* sw all off */
  2132. halbtc8822b1ant_sw_mechanism(btcoexist, false);
  2133. /* hw all off */
  2134. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  2135. }
  2136. boolean halbtc8822b1ant_is_common_action(IN struct btc_coexist *btcoexist)
  2137. {
  2138. boolean common = false, wifi_connected = false, wifi_busy = false;
  2139. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  2140. &wifi_connected);
  2141. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  2142. if (!wifi_connected &&
  2143. BT_8822B_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
  2144. coex_dm->bt_status) {
  2145. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2146. "[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n");
  2147. BTC_TRACE(trace_buf);
  2148. /* halbtc8822b1ant_sw_mechanism(btcoexist, false); */
  2149. common = true;
  2150. } else if (wifi_connected &&
  2151. (BT_8822B_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
  2152. coex_dm->bt_status)) {
  2153. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2154. "[BTCoex], Wifi connected + BT non connected-idle!!\n");
  2155. BTC_TRACE(trace_buf);
  2156. /* halbtc8822b1ant_sw_mechanism(btcoexist, false); */
  2157. common = true;
  2158. } else if (!wifi_connected &&
  2159. (BT_8822B_1ANT_BT_STATUS_CONNECTED_IDLE ==
  2160. coex_dm->bt_status)) {
  2161. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2162. "[BTCoex], Wifi non connected-idle + BT connected-idle!!\n");
  2163. BTC_TRACE(trace_buf);
  2164. /* halbtc8822b1ant_sw_mechanism(btcoexist, false); */
  2165. common = true;
  2166. } else if (wifi_connected &&
  2167. (BT_8822B_1ANT_BT_STATUS_CONNECTED_IDLE ==
  2168. coex_dm->bt_status)) {
  2169. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2170. "[BTCoex], Wifi connected + BT connected-idle!!\n");
  2171. BTC_TRACE(trace_buf);
  2172. /* halbtc8822b1ant_sw_mechanism(btcoexist, false); */
  2173. common = true;
  2174. } else if (!wifi_connected &&
  2175. (BT_8822B_1ANT_BT_STATUS_CONNECTED_IDLE !=
  2176. coex_dm->bt_status)) {
  2177. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2178. "[BTCoex], Wifi non connected-idle + BT Busy!!\n");
  2179. BTC_TRACE(trace_buf);
  2180. /* halbtc8822b1ant_sw_mechanism(btcoexist, false); */
  2181. common = true;
  2182. } else {
  2183. if (wifi_busy) {
  2184. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2185. "[BTCoex], Wifi Connected-Busy + BT Busy!!\n");
  2186. BTC_TRACE(trace_buf);
  2187. } else {
  2188. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2189. "[BTCoex], Wifi Connected-Idle + BT Busy!!\n");
  2190. BTC_TRACE(trace_buf);
  2191. }
  2192. common = false;
  2193. }
  2194. return common;
  2195. }
  2196. void halbtc8822b1ant_action_wifi_under5g(IN struct btc_coexist *btcoexist)
  2197. {
  2198. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2199. "[BTCoex], under 5g start\n");
  2200. BTC_TRACE(trace_buf);
  2201. /* for test : s3 bt disappear , fail rate 1/600*/
  2202. /*
  2203. halbtc8822b1ant_ignore_wlan_act(btcoexist, NORMAL_EXEC, true);
  2204. */
  2205. /*set sw gnt wl bt high*/
  2206. halbtc8822b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC,
  2207. BT_8822B_1ANT_PHASE_5G_RUNTIME);
  2208. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  2209. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  2210. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd,
  2211. 0x3, 1);
  2212. /*
  2213. halbtc8822b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
  2214. halbtc8822b1ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 5);
  2215. */
  2216. }
  2217. void halbtc8822b1ant_action_wifi_only(IN struct btc_coexist *btcoexist)
  2218. {
  2219. boolean wifi_under_5g = false, rf4ce_enabled = false;
  2220. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  2221. if (wifi_under_5g) {
  2222. halbtc8822b1ant_action_wifi_under5g(btcoexist);
  2223. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2224. "[BTCoex], ********** (wlan only -- under 5g ) **********\n");
  2225. BTC_TRACE(trace_buf);
  2226. return;
  2227. }
  2228. if (rf4ce_enabled) {
  2229. btcoexist->btc_write_1byte_bitmask(
  2230. btcoexist, 0x45e, 0x8, 0x1);
  2231. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2232. true,
  2233. 50);
  2234. halbtc8822b1ant_coex_table_with_type(btcoexist,
  2235. NORMAL_EXEC, 1);
  2236. return;
  2237. }
  2238. halbtc8822b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
  2239. halbtc8822b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8);
  2240. halbtc8822b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC,
  2241. BT_8822B_1ANT_PHASE_2G_RUNTIME);
  2242. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2243. "[BTCoex], ********** (wlan only -- under 2g ) **********\n");
  2244. BTC_TRACE(trace_buf);
  2245. }
  2246. /* *********************************************
  2247. *
  2248. * Software Coex Mechanism start
  2249. *
  2250. * ********************************************* */
  2251. /* SCO only or SCO+PAN(HS) */
  2252. /*
  2253. void halbtc8822b1ant_action_sco(IN struct btc_coexist* btcoexist)
  2254. {
  2255. halbtc8822b1ant_sw_mechanism(btcoexist, true);
  2256. }
  2257. void halbtc8822b1ant_action_hid(IN struct btc_coexist* btcoexist)
  2258. {
  2259. halbtc8822b1ant_sw_mechanism(btcoexist, true);
  2260. }
  2261. void halbtc8822b1ant_action_a2dp(IN struct btc_coexist* btcoexist)
  2262. {
  2263. halbtc8822b1ant_sw_mechanism(btcoexist, false);
  2264. }
  2265. void halbtc8822b1ant_action_a2dp_pan_hs(IN struct btc_coexist* btcoexist)
  2266. {
  2267. halbtc8822b1ant_sw_mechanism(btcoexist, false);
  2268. }
  2269. void halbtc8822b1ant_action_pan_edr(IN struct btc_coexist* btcoexist)
  2270. {
  2271. halbtc8822b1ant_sw_mechanism(btcoexist, false);
  2272. }
  2273. void halbtc8822b1ant_action_pan_hs(IN struct btc_coexist* btcoexist)
  2274. {
  2275. halbtc8822b1ant_sw_mechanism(btcoexist, false);
  2276. }
  2277. void halbtc8822b1ant_action_pan_edr_a2dp(IN struct btc_coexist* btcoexist)
  2278. {
  2279. halbtc8822b1ant_sw_mechanism(btcoexist, false);
  2280. }
  2281. void halbtc8822b1ant_action_pan_edr_hid(IN struct btc_coexist* btcoexist)
  2282. {
  2283. halbtc8822b1ant_sw_mechanism(btcoexist, true);
  2284. }
  2285. void halbtc8822b1ant_action_hid_a2dp_pan_edr(IN struct btc_coexist* btcoexist)
  2286. {
  2287. halbtc8822b1ant_sw_mechanism(btcoexist, true);
  2288. }
  2289. void halbtc8822b1ant_action_hid_a2dp(IN struct btc_coexist* btcoexist)
  2290. {
  2291. halbtc8822b1ant_sw_mechanism(btcoexist, true);
  2292. }
  2293. */
  2294. /* *********************************************
  2295. *
  2296. * Non-Software Coex Mechanism start
  2297. *
  2298. * ********************************************* */
  2299. void halbtc8822b1ant_action_bt_whck_test(IN struct btc_coexist *btcoexist)
  2300. {
  2301. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2302. "[BTCoex],action_bt_whck_test\n");
  2303. BTC_TRACE(trace_buf);
  2304. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  2305. halbtc8822b1ant_set_ant_path(btcoexist,
  2306. BTC_ANT_PATH_AUTO,
  2307. NORMAL_EXEC,
  2308. BT_8822B_1ANT_PHASE_2G_RUNTIME);
  2309. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  2310. }
  2311. void halbtc8822b1ant_action_wifi_multi_port(IN struct btc_coexist *btcoexist)
  2312. {
  2313. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2314. "[BTCoex],action_wifi_multi_port\n");
  2315. BTC_TRACE(trace_buf);
  2316. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  2317. halbtc8822b1ant_set_ant_path(btcoexist,
  2318. BTC_ANT_PATH_AUTO,
  2319. NORMAL_EXEC,
  2320. BT_8822B_1ANT_PHASE_2G_RUNTIME);
  2321. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  2322. }
  2323. void halbtc8822b1ant_action_hs(IN struct btc_coexist *btcoexist)
  2324. {
  2325. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2326. "[BTCoex], action_hs\n");
  2327. BTC_TRACE(trace_buf);
  2328. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
  2329. halbtc8822b1ant_set_ant_path(btcoexist,
  2330. BTC_ANT_PATH_AUTO,
  2331. NORMAL_EXEC,
  2332. BT_8822B_1ANT_PHASE_2G_RUNTIME);
  2333. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
  2334. }
  2335. /*"""bt inquiry"""" + wifi any + bt any*/
  2336. void halbtc8822b1ant_action_bt_inquiry(IN struct btc_coexist *btcoexist)
  2337. {
  2338. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  2339. boolean wifi_connected = false, ap_enable = false, wifi_busy = false,
  2340. bt_busy = false, rf4ce_enabled = false;
  2341. boolean wifi_scan = false, link = false, roam = false;
  2342. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2343. "[BTCoex], ********** (bt inquiry) **********\n");
  2344. BTC_TRACE(trace_buf);
  2345. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
  2346. &ap_enable);
  2347. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  2348. &wifi_connected);
  2349. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  2350. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
  2351. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &wifi_scan);
  2352. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
  2353. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
  2354. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2355. "[BTCoex], ********** scan = %d, link =%d, roam = %d**********\n",
  2356. wifi_scan, link, roam);
  2357. BTC_TRACE(trace_buf);
  2358. if ((link) || (roam) || (coex_sta->wifi_is_high_pri_task)) {
  2359. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2360. "[BTCoex], ********** (bt inquiry wifi connect or scan ) **********\n");
  2361. BTC_TRACE(trace_buf);
  2362. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 1);
  2363. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6);
  2364. } else if ((wifi_scan) && (coex_sta->bt_create_connection)) {
  2365. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22);
  2366. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6);
  2367. } else if ((!wifi_connected) && (!wifi_scan)) {
  2368. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2369. "[BTCoex], ********** (bt inquiry wifi non connect) **********\n");
  2370. BTC_TRACE(trace_buf);
  2371. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  2372. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  2373. } else if ((bt_link_info->a2dp_exist) && (bt_link_info->pan_exist)) {
  2374. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22);
  2375. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  2376. } else if (bt_link_info->a2dp_exist) {
  2377. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
  2378. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3);
  2379. } else if (wifi_scan) {
  2380. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
  2381. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  2382. } else if (wifi_busy) {
  2383. /* for BT inquiry/page fail after S4 resume */
  2384. /* halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); */
  2385. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
  2386. /*aaaa->55aa for bt connect while wl busy*/
  2387. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
  2388. 15);
  2389. if (rf4ce_enabled) {
  2390. btcoexist->btc_write_1byte_bitmask(
  2391. btcoexist, 0x45e, 0x8, 0x1);
  2392. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2393. true,
  2394. 50);
  2395. halbtc8822b1ant_coex_table_with_type(btcoexist,
  2396. NORMAL_EXEC, 0);
  2397. }
  2398. } else {
  2399. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2400. "[BTCoex], ********** (bt inquiry wifi connect) **********\n");
  2401. BTC_TRACE(trace_buf);
  2402. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22);
  2403. halbtc8822b1ant_set_ant_path(btcoexist,
  2404. BTC_ANT_PATH_AUTO,
  2405. NORMAL_EXEC,
  2406. BT_8822B_1ANT_PHASE_2G_RUNTIME);
  2407. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
  2408. 4);
  2409. }
  2410. /*
  2411. if ((wifi_link) || (wifi_roam) || (coex_sta->wifi_is_high_pri_task)) {
  2412. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 33);
  2413. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6);
  2414. } else if ((wifi_scan) && (coex_sta->bt_create_connection)) {
  2415. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22);
  2416. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6);
  2417. } else if ((!wifi_connected) && (!wifi_scan)) {
  2418. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  2419. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  2420. } else if ((bt_link_info->a2dp_exist) && (bt_link_info->pan_exist)) {
  2421. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22);
  2422. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  2423. } else if (bt_link_info->a2dp_exist) {
  2424. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
  2425. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  2426. } else if (wifi_scan) {
  2427. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
  2428. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  2429. } else if (wifi_busy) {
  2430. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 21);
  2431. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  2432. } else {
  2433. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 19);
  2434. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  2435. }
  2436. */
  2437. }
  2438. void halbtc8822b1ant_action_bt_sco_hid_only_busy(IN struct btc_coexist
  2439. *btcoexist, IN u8 wifi_status)
  2440. {
  2441. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  2442. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x45e, 0x8, 0x1);
  2443. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2444. "[BTCoex], ********** (bt sco hid only busy) **********\n");
  2445. BTC_TRACE(trace_buf);
  2446. /*SCO + wifi connected idle or busy / 0x778=1@wifi slot*/
  2447. if (bt_link_info->sco_exist) {
  2448. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x45e, 0x8, 0x1);
  2449. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
  2450. /*case16 for connect SCO first then connect a2sp fail issue*/
  2451. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 16);
  2452. } else { /* HID + wifi connected idle or busy / 0x778=1@wifi slot */
  2453. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x45e, 0x8, 0x1);
  2454. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
  2455. /*case16 for connect HID first then connect a2sp fail issue*/
  2456. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 16);
  2457. }
  2458. }
  2459. /*wifi connected + bt acl busy*/
  2460. void halbtc8822b1ant_action_wifi_connected_bt_acl_busy(IN struct btc_coexist
  2461. *btcoexist, IN u8 wifi_status)
  2462. {
  2463. u8 bt_rssi_state;
  2464. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  2465. boolean wifi_busy = false, wifi_turbo = false;
  2466. u32 wifi_bw = 1;
  2467. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW,
  2468. &wifi_bw);
  2469. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  2470. btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
  2471. &coex_sta->scan_ap_num);
  2472. bt_rssi_state = halbtc8822b1ant_bt_rssi_state(2, 28, 0);
  2473. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2474. "[BTCoex], ********** (wifi connect acl busy) **********\n");
  2475. BTC_TRACE(trace_buf);
  2476. if (bt_link_info->hid_only) { /* HID + wifi connected idle or busy / 0x778=1@wifi slot */
  2477. btcoexist->btc_write_1byte_bitmask(
  2478. btcoexist, 0x45e, 0x8, 0x1);
  2479. halbtc8822b1ant_action_bt_sco_hid_only_busy(btcoexist,
  2480. wifi_status);
  2481. return;
  2482. } else if (
  2483. bt_link_info->a2dp_only) { /* A2DP + wifi connected idle or busy */
  2484. if (BT_8822B_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifi_status) {
  2485. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x45e,
  2486. 0x8, 0x1);
  2487. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2488. 32);
  2489. halbtc8822b1ant_coex_table_with_type(btcoexist,
  2490. NORMAL_EXEC, 0);
  2491. } else {
  2492. if (coex_sta->scan_ap_num >=
  2493. BT_8822B_1ANT_WIFI_NOISY_THRESH) {
  2494. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2495. true,
  2496. 17);
  2497. } else {
  2498. btcoexist->btc_write_1byte_bitmask(
  2499. btcoexist, 0x45e, 0x8, 0x1);
  2500. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2501. true,
  2502. 42);
  2503. halbtc8822b1ant_coex_table_with_type(btcoexist,
  2504. NORMAL_EXEC, 1);
  2505. }
  2506. /*
  2507. halbtc8822b1ant_coex_table_with_type(btcoexist,
  2508. NORMAL_EXEC, 1);
  2509. */
  2510. coex_dm->auto_tdma_adjust = true;
  2511. }
  2512. /* A2DP+PAN(OPP,FTP), HID+A2DP+PAN(OPP,FTP) */
  2513. } else if (((bt_link_info->a2dp_exist) && (bt_link_info->pan_exist)) ||
  2514. (bt_link_info->hid_exist && bt_link_info->a2dp_exist &&
  2515. bt_link_info->pan_exist)) { /* A2DP+PAN(OPP,FTP), HID+A2DP+PAN(OPP,FTP) */
  2516. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x45e, 0x8, 0x1);
  2517. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 47);
  2518. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
  2519. 6);
  2520. } else if (bt_link_info->hid_exist &&
  2521. bt_link_info->a2dp_exist) { /* HID+A2DP */
  2522. btcoexist->btc_write_1byte_bitmask(
  2523. btcoexist, 0x45e, 0x8, 0x1);
  2524. if (!wifi_busy) {
  2525. /*a2dp glitch while wl idle , change the 0x6c0=5a5a5a5a->5555or aaaa55aa*/
  2526. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  2527. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2528. true,
  2529. 32);
  2530. } else if (wifi_bw == 0) { /* 11bg mode */
  2531. halbtc8822b1ant_coex_table_with_type(btcoexist,
  2532. NORMAL_EXEC, 1);
  2533. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2534. true,
  2535. 42);
  2536. } else {
  2537. /*if in open space , and ask wl tp , 0x60=6135031111,55555555,aaaa55aa*/
  2538. halbtc8822b1ant_coex_table_with_type(btcoexist,
  2539. NORMAL_EXEC, 1);
  2540. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 42);
  2541. }
  2542. /*
  2543. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
  2544. 1);
  2545. */
  2546. } else if ((bt_link_info->pan_only) || (bt_link_info->hid_exist &&
  2547. bt_link_info->pan_exist)) { /* PAN(OPP,FTP), HID+PAN(OPP,FTP)*/
  2548. /*
  2549. if (BT_8723D_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifi_status)
  2550. halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2551. 4);
  2552. else
  2553. */
  2554. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x45e, 0x8, 0x1);
  2555. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 47);
  2556. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
  2557. 1);
  2558. } else {
  2559. /* BT no-profile busy (0x9) */
  2560. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x45e, 0x8, 0x1);
  2561. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 33);
  2562. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
  2563. 1);
  2564. }
  2565. }
  2566. /*wifi not connected + bt action*/
  2567. void halbtc8822b1ant_action_wifi_not_connected(IN struct btc_coexist *btcoexist)
  2568. {
  2569. boolean wifi_under_5g = false, rf4ce_enabled = false;
  2570. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2571. "[BTCoex], ********** (wifi not connect) **********\n");
  2572. BTC_TRACE(trace_buf);
  2573. /* tdma and coex table */
  2574. if (rf4ce_enabled) {
  2575. btcoexist->btc_write_1byte_bitmask(
  2576. btcoexist, 0x45e, 0x8, 0x1);
  2577. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2578. true,
  2579. 50);
  2580. halbtc8822b1ant_coex_table_with_type(btcoexist,
  2581. NORMAL_EXEC, 1);
  2582. return;
  2583. }
  2584. halbtc8822b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8);
  2585. halbtc8822b1ant_set_ant_path(btcoexist,
  2586. BTC_ANT_PATH_AUTO,
  2587. NORMAL_EXEC,
  2588. BT_8822B_1ANT_PHASE_2G_RUNTIME);
  2589. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  2590. }
  2591. /*""""wl not connected scan"""" + bt action*/
  2592. void halbtc8822b1ant_action_wifi_not_connected_scan(IN struct btc_coexist
  2593. *btcoexist)
  2594. {
  2595. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  2596. boolean wifi_connected = false, bt_hs_on = false;
  2597. u32 wifi_link_status = 0;
  2598. u32 num_of_wifi_link = 0;
  2599. boolean bt_ctrl_agg_buf_size = false;
  2600. u8 agg_buf_size = 5;
  2601. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2602. "[BTCoex], ********** (wifi non connect scan) **********\n");
  2603. BTC_TRACE(trace_buf);
  2604. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  2605. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
  2606. &wifi_link_status);
  2607. num_of_wifi_link = wifi_link_status >> 16;
  2608. if (num_of_wifi_link >= 2) {
  2609. halbtc8822b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
  2610. halbtc8822b1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
  2611. bt_ctrl_agg_buf_size, agg_buf_size);
  2612. if (coex_sta->c2h_bt_inquiry_page) {
  2613. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2614. "############# [BTCoex], BT Is Inquirying\n");
  2615. BTC_TRACE(trace_buf);
  2616. halbtc8822b1ant_action_bt_inquiry(btcoexist);
  2617. } else
  2618. halbtc8822b1ant_action_wifi_multi_port(btcoexist);
  2619. return;
  2620. }
  2621. if (coex_sta->c2h_bt_inquiry_page) {
  2622. halbtc8822b1ant_action_bt_inquiry(btcoexist);
  2623. return;
  2624. } else if (bt_hs_on) {
  2625. halbtc8822b1ant_action_hs(btcoexist);
  2626. return;
  2627. }
  2628. /* tdma and coex table */
  2629. if (BT_8822B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
  2630. if (bt_link_info->a2dp_exist) {
  2631. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2632. 32);
  2633. halbtc8822b1ant_coex_table_with_type(btcoexist,
  2634. NORMAL_EXEC, 1);
  2635. } else if (bt_link_info->a2dp_exist &&
  2636. bt_link_info->pan_exist) {
  2637. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2638. 22);
  2639. halbtc8822b1ant_coex_table_with_type(btcoexist,
  2640. NORMAL_EXEC, 1);
  2641. } else {
  2642. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2643. 20);
  2644. halbtc8822b1ant_coex_table_with_type(btcoexist,
  2645. NORMAL_EXEC, 1);
  2646. }
  2647. } else if ((BT_8822B_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
  2648. (BT_8822B_1ANT_BT_STATUS_ACL_SCO_BUSY ==
  2649. coex_dm->bt_status)) {
  2650. halbtc8822b1ant_action_bt_sco_hid_only_busy(btcoexist,
  2651. BT_8822B_1ANT_WIFI_STATUS_CONNECTED_SCAN);
  2652. } else {
  2653. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  2654. halbtc8822b1ant_set_ant_path(btcoexist,
  2655. BTC_ANT_PATH_AUTO,
  2656. NORMAL_EXEC,
  2657. BT_8822B_1ANT_PHASE_2G_RUNTIME);
  2658. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
  2659. 5);
  2660. }
  2661. }
  2662. /*""""wl not connected asso"""" + bt action*/
  2663. void halbtc8822b1ant_action_wifi_not_connected_asso_auth(
  2664. IN struct btc_coexist *btcoexist)
  2665. {
  2666. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  2667. boolean wifi_connected = false, bt_hs_on = false;
  2668. u32 wifi_link_status = 0;
  2669. u32 num_of_wifi_link = 0;
  2670. boolean bt_ctrl_agg_buf_size = false;
  2671. u8 agg_buf_size = 5;
  2672. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2673. "[BTCoex], ********** (wifi non connect asso_auth) **********\n");
  2674. BTC_TRACE(trace_buf);
  2675. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  2676. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
  2677. &wifi_link_status);
  2678. num_of_wifi_link = wifi_link_status >> 16;
  2679. if (num_of_wifi_link >= 2) {
  2680. halbtc8822b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
  2681. halbtc8822b1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
  2682. bt_ctrl_agg_buf_size,
  2683. agg_buf_size);
  2684. if (coex_sta->c2h_bt_inquiry_page) {
  2685. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2686. "############# [BTCoex], BT Is Inquirying\n");
  2687. BTC_TRACE(trace_buf);
  2688. halbtc8822b1ant_action_bt_inquiry(btcoexist);
  2689. } else
  2690. halbtc8822b1ant_action_wifi_multi_port(
  2691. btcoexist);
  2692. return;
  2693. }
  2694. if (coex_sta->c2h_bt_inquiry_page) {
  2695. halbtc8822b1ant_action_bt_inquiry(btcoexist);
  2696. return;
  2697. } else if (bt_hs_on) {
  2698. halbtc8822b1ant_action_hs(btcoexist);
  2699. return;
  2700. }
  2701. /* tdma and coex table */
  2702. if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) ||
  2703. (bt_link_info->a2dp_exist)) {
  2704. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
  2705. halbtc8822b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 4);
  2706. } else if (bt_link_info->pan_exist) {
  2707. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
  2708. halbtc8822b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 4);
  2709. } else {
  2710. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  2711. halbtc8822b1ant_set_ant_path(btcoexist,
  2712. BTC_ANT_PATH_AUTO,
  2713. NORMAL_EXEC,
  2714. BT_8822B_1ANT_PHASE_2G_RUNTIME);
  2715. halbtc8822b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 2);
  2716. }
  2717. }
  2718. /*""""wl connected scan"""" + bt action*/
  2719. void halbtc8822b1ant_action_wifi_connected_scan(IN struct btc_coexist
  2720. *btcoexist)
  2721. {
  2722. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  2723. boolean wifi_connected = false, bt_hs_on = false;
  2724. u32 wifi_link_status = 0;
  2725. u32 num_of_wifi_link = 0;
  2726. boolean bt_ctrl_agg_buf_size = false;
  2727. u8 agg_buf_size = 5;
  2728. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2729. "[BTCoex], ********** (wifi connect scan) **********\n");
  2730. BTC_TRACE(trace_buf);
  2731. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  2732. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
  2733. &wifi_link_status);
  2734. num_of_wifi_link = wifi_link_status >> 16;
  2735. if (num_of_wifi_link >= 2) {
  2736. halbtc8822b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
  2737. halbtc8822b1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
  2738. bt_ctrl_agg_buf_size, agg_buf_size);
  2739. if (coex_sta->c2h_bt_inquiry_page) {
  2740. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2741. "############# [BTCoex], BT Is Inquirying\n");
  2742. BTC_TRACE(trace_buf);
  2743. halbtc8822b1ant_action_bt_inquiry(btcoexist);
  2744. } else
  2745. halbtc8822b1ant_action_wifi_multi_port(btcoexist);
  2746. return;
  2747. }
  2748. if (coex_sta->c2h_bt_inquiry_page) {
  2749. halbtc8822b1ant_action_bt_inquiry(btcoexist);
  2750. return;
  2751. } else if (bt_hs_on) {
  2752. halbtc8822b1ant_action_hs(btcoexist);
  2753. return;
  2754. }
  2755. /* tdma and coex table */
  2756. if (BT_8822B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
  2757. if (bt_link_info->a2dp_exist) {
  2758. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2759. 32);
  2760. halbtc8822b1ant_coex_table_with_type(btcoexist,
  2761. NORMAL_EXEC, 1);
  2762. } else if (bt_link_info->a2dp_exist &&
  2763. bt_link_info->pan_exist) {
  2764. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2765. 22);
  2766. halbtc8822b1ant_coex_table_with_type(btcoexist,
  2767. NORMAL_EXEC, 1);
  2768. } else {
  2769. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2770. 20);
  2771. halbtc8822b1ant_coex_table_with_type(btcoexist,
  2772. NORMAL_EXEC, 1);
  2773. }
  2774. } else if ((BT_8822B_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
  2775. (BT_8822B_1ANT_BT_STATUS_ACL_SCO_BUSY ==
  2776. coex_dm->bt_status)) {
  2777. halbtc8822b1ant_action_bt_sco_hid_only_busy(btcoexist,
  2778. BT_8822B_1ANT_WIFI_STATUS_CONNECTED_SCAN);
  2779. } else {
  2780. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  2781. halbtc8822b1ant_set_ant_path(btcoexist,
  2782. BTC_ANT_PATH_AUTO,
  2783. NORMAL_EXEC,
  2784. BT_8822B_1ANT_PHASE_2G_RUNTIME);
  2785. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
  2786. 6);
  2787. }
  2788. }
  2789. /*""""wl connected specific packet"""" + bt action*/
  2790. void halbtc8822b1ant_action_wifi_connected_specific_packet(
  2791. IN struct btc_coexist *btcoexist)
  2792. {
  2793. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  2794. boolean wifi_connected = false, bt_hs_on = false;
  2795. u32 wifi_link_status = 0;
  2796. u32 num_of_wifi_link = 0;
  2797. boolean bt_ctrl_agg_buf_size = false;
  2798. u8 agg_buf_size = 5;
  2799. boolean wifi_busy = false;
  2800. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2801. "[BTCoex], ********** (wifi connect specific packet) **********\n");
  2802. BTC_TRACE(trace_buf);
  2803. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  2804. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
  2805. &wifi_link_status);
  2806. num_of_wifi_link = wifi_link_status >> 16;
  2807. if (num_of_wifi_link >= 2) {
  2808. halbtc8822b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
  2809. halbtc8822b1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
  2810. bt_ctrl_agg_buf_size, agg_buf_size);
  2811. if (coex_sta->c2h_bt_inquiry_page) {
  2812. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2813. "############# [BTCoex], BT Is Inquirying\n");
  2814. BTC_TRACE(trace_buf);
  2815. halbtc8822b1ant_action_bt_inquiry(btcoexist);
  2816. } else
  2817. halbtc8822b1ant_action_wifi_multi_port(btcoexist);
  2818. return;
  2819. }
  2820. if (coex_sta->c2h_bt_inquiry_page) {
  2821. halbtc8822b1ant_action_bt_inquiry(btcoexist);
  2822. return;
  2823. } else if (bt_hs_on) {
  2824. halbtc8822b1ant_action_hs(btcoexist);
  2825. return;
  2826. }
  2827. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  2828. /* no specific packet process for both WiFi and BT very busy */
  2829. if ((wifi_busy) && ((bt_link_info->pan_exist) ||
  2830. (coex_sta->num_of_profile >= 2)))
  2831. return;
  2832. /* tdma and coex table */
  2833. if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist)) {
  2834. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
  2835. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
  2836. } else if (bt_link_info->a2dp_exist) {
  2837. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
  2838. /*for a2dp glitch,change from 1 to 15*/
  2839. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
  2840. 15);
  2841. } else if (bt_link_info->pan_exist) {
  2842. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
  2843. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
  2844. 1);
  2845. } else {
  2846. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  2847. halbtc8822b1ant_set_ant_path(btcoexist,
  2848. BTC_ANT_PATH_AUTO,
  2849. NORMAL_EXEC,
  2850. BT_8822B_1ANT_PHASE_2G_RUNTIME);
  2851. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
  2852. 5);
  2853. }
  2854. }
  2855. /*wifi connected input point : to set different ps and tdma case (+bt different case)*/
  2856. void halbtc8822b1ant_action_wifi_connected(IN struct btc_coexist *btcoexist)
  2857. {
  2858. boolean wifi_busy = false, rf4ce_enabled = false;
  2859. boolean scan = false, link = false, roam = false;
  2860. boolean under_4way = false, ap_enable = false, wifi_under_5g = false;
  2861. u8 wifi_rssi_state;
  2862. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2863. "[BTCoex], CoexForWifiConnect()===>\n");
  2864. BTC_TRACE(trace_buf);
  2865. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  2866. if (wifi_under_5g) {
  2867. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2868. "[BTCoex], CoexForWifiConnect(), return for wifi is under 5g<===\n");
  2869. BTC_TRACE(trace_buf);
  2870. halbtc8822b1ant_action_wifi_under5g(btcoexist);
  2871. return;
  2872. }
  2873. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2874. "[BTCoex], CoexForWifiConnect(), return for wifi is under 2g<===\n");
  2875. BTC_TRACE(trace_buf);
  2876. halbtc8822b1ant_set_ant_path(btcoexist,
  2877. BTC_ANT_PATH_AUTO,
  2878. NORMAL_EXEC,
  2879. BT_8822B_1ANT_PHASE_2G_RUNTIME);
  2880. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
  2881. &under_4way);
  2882. if (under_4way) {
  2883. halbtc8822b1ant_action_wifi_connected_specific_packet(
  2884. btcoexist);
  2885. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2886. "[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n");
  2887. BTC_TRACE(trace_buf);
  2888. return;
  2889. }
  2890. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
  2891. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
  2892. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
  2893. if (scan || link || roam) {
  2894. if (scan)
  2895. halbtc8822b1ant_action_wifi_connected_scan(btcoexist);
  2896. else
  2897. halbtc8822b1ant_action_wifi_connected_specific_packet(
  2898. btcoexist);
  2899. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2900. "[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n");
  2901. BTC_TRACE(trace_buf);
  2902. return;
  2903. }
  2904. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
  2905. &ap_enable);
  2906. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  2907. /* tdma and coex table */
  2908. if (!wifi_busy) {
  2909. if (BT_8822B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
  2910. halbtc8822b1ant_action_wifi_connected_bt_acl_busy(
  2911. btcoexist,
  2912. BT_8822B_1ANT_WIFI_STATUS_CONNECTED_IDLE);
  2913. } else if ((BT_8822B_1ANT_BT_STATUS_SCO_BUSY ==
  2914. coex_dm->bt_status) ||
  2915. (BT_8822B_1ANT_BT_STATUS_ACL_SCO_BUSY ==
  2916. coex_dm->bt_status)) {
  2917. halbtc8822b1ant_action_bt_sco_hid_only_busy(btcoexist,
  2918. BT_8822B_1ANT_WIFI_STATUS_CONNECTED_IDLE);
  2919. } else {
  2920. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
  2921. 8);
  2922. halbtc8822b1ant_set_ant_path(btcoexist,
  2923. BTC_ANT_PATH_AUTO,
  2924. NORMAL_EXEC,
  2925. BT_8822B_1ANT_PHASE_2G_RUNTIME);
  2926. if ((coex_sta->high_priority_tx) +
  2927. (coex_sta->high_priority_rx) <= 60)
  2928. /*sy modify case16 -> case17*/
  2929. halbtc8822b1ant_coex_table_with_type(btcoexist,
  2930. NORMAL_EXEC, 1);
  2931. else
  2932. halbtc8822b1ant_coex_table_with_type(btcoexist,
  2933. NORMAL_EXEC, 1);
  2934. }
  2935. } else {
  2936. if (BT_8822B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
  2937. halbtc8822b1ant_action_wifi_connected_bt_acl_busy(
  2938. btcoexist,
  2939. BT_8822B_1ANT_WIFI_STATUS_CONNECTED_BUSY);
  2940. } else if ((BT_8822B_1ANT_BT_STATUS_SCO_BUSY ==
  2941. coex_dm->bt_status) ||
  2942. (BT_8822B_1ANT_BT_STATUS_ACL_SCO_BUSY ==
  2943. coex_dm->bt_status)) {
  2944. halbtc8822b1ant_action_bt_sco_hid_only_busy(btcoexist,
  2945. BT_8822B_1ANT_WIFI_STATUS_CONNECTED_BUSY);
  2946. } else {
  2947. if (rf4ce_enabled) {
  2948. btcoexist->btc_write_1byte_bitmask(
  2949. btcoexist, 0x45e, 0x8, 0x1);
  2950. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2951. true,
  2952. 50);
  2953. halbtc8822b1ant_coex_table_with_type(btcoexist,
  2954. NORMAL_EXEC, 1);
  2955. return;
  2956. }
  2957. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
  2958. 8);
  2959. halbtc8822b1ant_set_ant_path(btcoexist,
  2960. BTC_ANT_PATH_AUTO,
  2961. NORMAL_EXEC,
  2962. BT_8822B_1ANT_PHASE_2G_RUNTIME);
  2963. /*
  2964. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2965. 32);
  2966. halbtc8822b1ant_set_ant_path(btcoexist,
  2967. BTC_ANT_PATH_AUTO, NORMAL_EXEC, BT_8822B_1ANT_PHASE_2G_RUNTIME);
  2968. */
  2969. wifi_rssi_state = halbtc8822b1ant_wifi_rssi_state(
  2970. btcoexist, 1, 2, 25, 0);
  2971. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2972. "[BTCoex], ********** before **********\n");
  2973. BTC_TRACE(trace_buf);
  2974. /*
  2975. if ((BT_8822B_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
  2976. coex_dm->bt_status) &&
  2977. (coex_sta->scan_ap_num <= 3) &&
  2978. (wifi_rssi_state == BTC_RSSI_STATE_LOW ||
  2979. wifi_rssi_state == BTC_RSSI_STATE_STAY_LOW)) {
  2980. */
  2981. if (BT_8822B_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
  2982. coex_dm->bt_status) {
  2983. if (rf4ce_enabled) {
  2984. btcoexist->btc_write_1byte_bitmask(
  2985. btcoexist, 0x45e, 0x8, 0x1);
  2986. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2987. true,
  2988. 50);
  2989. halbtc8822b1ant_coex_table_with_type(btcoexist,
  2990. NORMAL_EXEC, 1);
  2991. return;
  2992. }
  2993. halbtc8822b1ant_coex_table_with_type(btcoexist,
  2994. NORMAL_EXEC, 7);
  2995. } else
  2996. halbtc8822b1ant_coex_table_with_type(btcoexist,
  2997. NORMAL_EXEC, 1);
  2998. /*
  2999. else if ((coex_sta->high_priority_tx +
  3000. coex_sta->high_priority_rx) <= 60)
  3001. halbtc8822b1ant_coex_table_with_type(btcoexist,
  3002. NORMAL_EXEC, 1);
  3003. else
  3004. halbtc8822b1ant_coex_table_with_type(btcoexist,
  3005. NORMAL_EXEC, 4);
  3006. */
  3007. }
  3008. }
  3009. }
  3010. void halbtc8822b1ant_run_sw_coexist_mechanism(IN struct btc_coexist *btcoexist)
  3011. {
  3012. u8 algorithm = 0;
  3013. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3014. "[BTCoex], ********** (runswcoexmech) **********\n");
  3015. BTC_TRACE(trace_buf);
  3016. algorithm = halbtc8822b1ant_action_algorithm(btcoexist);
  3017. coex_dm->cur_algorithm = algorithm;
  3018. if (halbtc8822b1ant_is_common_action(btcoexist)) {
  3019. } else {
  3020. switch (coex_dm->cur_algorithm) {
  3021. case BT_8822B_1ANT_COEX_ALGO_SCO:
  3022. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3023. "[BTCoex], Action algorithm = SCO.\n");
  3024. BTC_TRACE(trace_buf);
  3025. /* halbtc8822b1ant_action_sco(btcoexist); */
  3026. break;
  3027. case BT_8822B_1ANT_COEX_ALGO_HID:
  3028. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3029. "[BTCoex], Action algorithm = HID.\n");
  3030. BTC_TRACE(trace_buf);
  3031. /* halbtc8822b1ant_action_hid(btcoexist); */
  3032. break;
  3033. case BT_8822B_1ANT_COEX_ALGO_A2DP:
  3034. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3035. "[BTCoex], Action algorithm = A2DP.\n");
  3036. BTC_TRACE(trace_buf);
  3037. /* halbtc8822b1ant_action_a2dp(btcoexist); */
  3038. break;
  3039. case BT_8822B_1ANT_COEX_ALGO_A2DP_PANHS:
  3040. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3041. "[BTCoex], Action algorithm = A2DP+PAN(HS).\n");
  3042. BTC_TRACE(trace_buf);
  3043. /* halbtc8822b1ant_action_a2dp_pan_hs(btcoexist); */
  3044. break;
  3045. case BT_8822B_1ANT_COEX_ALGO_PANEDR:
  3046. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3047. "[BTCoex], Action algorithm = PAN(EDR).\n");
  3048. BTC_TRACE(trace_buf);
  3049. /* halbtc8822b1ant_action_pan_edr(btcoexist); */
  3050. break;
  3051. case BT_8822B_1ANT_COEX_ALGO_PANHS:
  3052. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3053. "[BTCoex], Action algorithm = HS mode.\n");
  3054. BTC_TRACE(trace_buf);
  3055. /* halbtc8822b1ant_action_pan_hs(btcoexist); */
  3056. break;
  3057. case BT_8822B_1ANT_COEX_ALGO_PANEDR_A2DP:
  3058. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3059. "[BTCoex], Action algorithm = PAN+A2DP.\n");
  3060. BTC_TRACE(trace_buf);
  3061. /* halbtc8822b1ant_action_pan_edr_a2dp(btcoexist); */
  3062. break;
  3063. case BT_8822B_1ANT_COEX_ALGO_PANEDR_HID:
  3064. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3065. "[BTCoex], Action algorithm = PAN(EDR)+HID.\n");
  3066. BTC_TRACE(trace_buf);
  3067. /* halbtc8822b1ant_action_pan_edr_hid(btcoexist); */
  3068. break;
  3069. case BT_8822B_1ANT_COEX_ALGO_HID_A2DP_PANEDR:
  3070. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3071. "[BTCoex], Action algorithm = HID+A2DP+PAN.\n");
  3072. BTC_TRACE(trace_buf);
  3073. /* halbtc8822b1ant_action_hid_a2dp_pan_edr(btcoexist); */
  3074. break;
  3075. case BT_8822B_1ANT_COEX_ALGO_HID_A2DP:
  3076. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3077. "[BTCoex], Action algorithm = HID+A2DP.\n");
  3078. BTC_TRACE(trace_buf);
  3079. /* halbtc8822b1ant_action_hid_a2dp(btcoexist); */
  3080. break;
  3081. default:
  3082. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3083. "[BTCoex], Action algorithm = coexist All Off!!\n");
  3084. BTC_TRACE(trace_buf);
  3085. /* halbtc8822b1ant_coex_all_off(btcoexist); */
  3086. break;
  3087. }
  3088. coex_dm->pre_algorithm = coex_dm->cur_algorithm;
  3089. }
  3090. }
  3091. void halbtc8822b1ant_run_coexist_mechanism(IN struct btc_coexist *btcoexist)
  3092. {
  3093. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  3094. boolean wifi_connected = false, bt_hs_on = false;
  3095. boolean increase_scan_dev_num = false;
  3096. boolean bt_ctrl_agg_buf_size = false;
  3097. boolean miracast_plus_bt = false;
  3098. u8 agg_buf_size = 5;
  3099. u32 wifi_link_status = 0;
  3100. u32 num_of_wifi_link = 0, wifi_bw;
  3101. u8 iot_peer = BTC_IOT_PEER_UNKNOWN;
  3102. boolean wifi_under_5g = false;
  3103. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3104. "[BTCoex], RunCoexistMechanism()===>\n");
  3105. BTC_TRACE(trace_buf);
  3106. if (btcoexist->manual_control) {
  3107. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3108. "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
  3109. BTC_TRACE(trace_buf);
  3110. return;
  3111. }
  3112. if (btcoexist->stop_coex_dm) {
  3113. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3114. "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n");
  3115. BTC_TRACE(trace_buf);
  3116. return;
  3117. }
  3118. if (coex_sta->under_ips) {
  3119. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3120. "[BTCoex], wifi is under IPS !!!\n");
  3121. BTC_TRACE(trace_buf);
  3122. return;
  3123. }
  3124. if (!coex_sta->run_time_state) {
  3125. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3126. "[BTCoex], return for run_time_state = false !!!\n");
  3127. BTC_TRACE(trace_buf);
  3128. return;
  3129. }
  3130. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  3131. if (wifi_under_5g) {
  3132. halbtc8822b1ant_action_wifi_under5g(btcoexist);
  3133. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3134. "[BTCoex], WiFi is under 5G!!!\n");
  3135. BTC_TRACE(trace_buf);
  3136. return;
  3137. }
  3138. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3139. "[BTCoex], WiFi is under 2G!!!\n");
  3140. BTC_TRACE(trace_buf);
  3141. halbtc8822b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
  3142. NORMAL_EXEC,
  3143. BT_8822B_1ANT_PHASE_2G_RUNTIME);
  3144. if (coex_sta->bt_whck_test) {
  3145. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3146. "[BTCoex], BT is under WHCK TEST!!!\n");
  3147. BTC_TRACE(trace_buf);
  3148. halbtc8822b1ant_action_bt_whck_test(btcoexist);
  3149. return;
  3150. }
  3151. if (coex_sta->bt_disabled) {
  3152. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3153. "[BTCoex], BT is disabled !!!\n");
  3154. halbtc8822b1ant_action_wifi_only(btcoexist);
  3155. return;
  3156. }
  3157. if ((BT_8822B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
  3158. (BT_8822B_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
  3159. (BT_8822B_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
  3160. increase_scan_dev_num = true;
  3161. btcoexist->btc_set(btcoexist, BTC_SET_BL_INC_SCAN_DEV_NUM,
  3162. &increase_scan_dev_num);
  3163. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  3164. &wifi_connected);
  3165. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
  3166. &wifi_link_status);
  3167. num_of_wifi_link = wifi_link_status >> 16;
  3168. if ((num_of_wifi_link >= 2) ||
  3169. (wifi_link_status & WIFI_P2P_GO_CONNECTED)) {
  3170. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3171. "############# [BTCoex], Multi-Port num_of_wifi_link = %d, wifi_link_status = 0x%x\n",
  3172. num_of_wifi_link, wifi_link_status);
  3173. BTC_TRACE(trace_buf);
  3174. if (bt_link_info->bt_link_exist) {
  3175. halbtc8822b1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1,
  3176. 0, 1);
  3177. miracast_plus_bt = true;
  3178. } else {
  3179. halbtc8822b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0,
  3180. 0, 0);
  3181. miracast_plus_bt = false;
  3182. }
  3183. btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT,
  3184. &miracast_plus_bt);
  3185. halbtc8822b1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
  3186. bt_ctrl_agg_buf_size, agg_buf_size);
  3187. if ((bt_link_info->a2dp_exist) &&
  3188. (coex_sta->c2h_bt_inquiry_page)) {
  3189. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3190. "############# [BTCoex], BT Is Inquirying\n");
  3191. BTC_TRACE(trace_buf);
  3192. halbtc8822b1ant_action_bt_inquiry(btcoexist);
  3193. } else
  3194. halbtc8822b1ant_action_wifi_multi_port(btcoexist);
  3195. return;
  3196. }
  3197. miracast_plus_bt = false;
  3198. btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT,
  3199. &miracast_plus_bt);
  3200. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  3201. if ((bt_link_info->bt_link_exist) && (wifi_connected)) {
  3202. halbtc8822b1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1, 0, 1);
  3203. btcoexist->btc_get(btcoexist, BTC_GET_U1_IOT_PEER, &iot_peer);
  3204. if (BTC_IOT_PEER_CISCO != iot_peer) {
  3205. if (bt_link_info->sco_exist) /* if (bt_link_info->bt_hi_pri_link_exist) */
  3206. halbtc8822b1ant_limited_rx(btcoexist,
  3207. NORMAL_EXEC, true, false, 0x5);
  3208. else
  3209. halbtc8822b1ant_limited_rx(btcoexist,
  3210. NORMAL_EXEC, false, false, 0x5);
  3211. } else {
  3212. if (bt_link_info->sco_exist)
  3213. halbtc8822b1ant_limited_rx(btcoexist,
  3214. NORMAL_EXEC, true, false, 0x5);
  3215. else {
  3216. if (BTC_WIFI_BW_HT40 == wifi_bw)
  3217. halbtc8822b1ant_limited_rx(btcoexist,
  3218. NORMAL_EXEC, false, true, 0x10);
  3219. else
  3220. halbtc8822b1ant_limited_rx(btcoexist,
  3221. NORMAL_EXEC, false, true, 0x8);
  3222. }
  3223. }
  3224. halbtc8822b1ant_sw_mechanism(btcoexist, true);
  3225. halbtc8822b1ant_run_sw_coexist_mechanism(
  3226. btcoexist); /* just print debug message */
  3227. } else {
  3228. halbtc8822b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
  3229. halbtc8822b1ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
  3230. 0x5);
  3231. halbtc8822b1ant_sw_mechanism(btcoexist, false);
  3232. halbtc8822b1ant_run_sw_coexist_mechanism(
  3233. btcoexist); /* just print debug message */
  3234. }
  3235. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  3236. if (coex_sta->c2h_bt_inquiry_page) {
  3237. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3238. "############# [BTCoex], BT Is Inquirying\n");
  3239. BTC_TRACE(trace_buf);
  3240. halbtc8822b1ant_action_bt_inquiry(btcoexist);
  3241. return;
  3242. } else if (bt_hs_on) {
  3243. halbtc8822b1ant_action_hs(btcoexist);
  3244. return;
  3245. }
  3246. if (!wifi_connected) {
  3247. boolean scan = false, link = false, roam = false;
  3248. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3249. "[BTCoex], wifi is non connected-idle !!!\n");
  3250. BTC_TRACE(trace_buf);
  3251. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
  3252. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
  3253. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
  3254. if (scan || link || roam) {
  3255. if (scan)
  3256. halbtc8822b1ant_action_wifi_not_connected_scan(
  3257. btcoexist);
  3258. else
  3259. halbtc8822b1ant_action_wifi_not_connected_asso_auth(
  3260. btcoexist);
  3261. } else
  3262. halbtc8822b1ant_action_wifi_not_connected(btcoexist);
  3263. } else /* wifi LPS/Busy */
  3264. halbtc8822b1ant_action_wifi_connected(btcoexist);
  3265. }
  3266. u32 halbtc8822b1ant_psd_log2base(IN struct btc_coexist *btcoexist, IN u32 val)
  3267. {
  3268. u8 j;
  3269. u32 tmp, tmp2, val_integerd_b = 0, tindex, shiftcount = 0;
  3270. u32 result, val_fractiond_b = 0, table_fraction[21] = {0, 432, 332, 274, 232, 200,
  3271. 174, 151, 132, 115, 100, 86, 74, 62, 51, 42,
  3272. 32, 23, 15, 7, 0
  3273. };
  3274. if (val == 0)
  3275. return 0;
  3276. tmp = val;
  3277. while (1) {
  3278. if (tmp == 1)
  3279. break;
  3280. tmp = (tmp >> 1);
  3281. shiftcount++;
  3282. }
  3283. val_integerd_b = shiftcount + 1;
  3284. tmp2 = 1;
  3285. for (j = 1; j <= val_integerd_b; j++)
  3286. tmp2 = tmp2 * 2;
  3287. tmp = (val * 100) / tmp2;
  3288. tindex = tmp / 5;
  3289. if (tindex > 20)
  3290. tindex = 20;
  3291. val_fractiond_b = table_fraction[tindex];
  3292. result = val_integerd_b * 100 - val_fractiond_b;
  3293. return result;
  3294. }
  3295. void halbtc8822b1ant_init_coex_dm(IN struct btc_coexist *btcoexist)
  3296. {
  3297. /* force to reset coex mechanism */
  3298. halbtc8822b1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, false);
  3299. /* sw all off */
  3300. halbtc8822b1ant_sw_mechanism(btcoexist, false);
  3301. /* halbtc8822b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); */
  3302. /* halbtc8822b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0); */
  3303. coex_sta->pop_event_cnt = 0;
  3304. }
  3305. void halbtc8822b1ant_init_hw_config(IN struct btc_coexist *btcoexist,
  3306. IN boolean back_up, IN boolean wifi_only)
  3307. {
  3308. u8 u8tmp = 0;
  3309. boolean wifi_under_5g = false;
  3310. u32 u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0;
  3311. u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
  3312. u32tmp1 = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, 0x38);
  3313. u32tmp2 = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, 0x54);
  3314. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3315. "[BTCoex], ********** (Before Init HW config) 0xcb4 = 0x%x, 0x38= 0x%x, 0x54= 0x%x**********\n",
  3316. u32tmp3, u32tmp1, u32tmp2);
  3317. BTC_TRACE(trace_buf);
  3318. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3319. "[BTCoex], 1Ant Init HW Config!!\n");
  3320. BTC_TRACE(trace_buf);
  3321. coex_sta->bt_coex_supported_feature = 0;
  3322. coex_sta->bt_coex_supported_version = 0;
  3323. /* Setup RF front end type */
  3324. halbtc8822b1ant_set_rfe_type(btcoexist);
  3325. /* 0xf0[15:12] --> Chip Cut information */
  3326. coex_sta->cut_version = (btcoexist->btc_read_1byte(btcoexist,
  3327. 0xf1) & 0xf0) >> 4;
  3328. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x550, 0x8,
  3329. 0x1); /* enable TBTT nterrupt */
  3330. /* BT report packet sample rate */
  3331. /* 0x790[5:0]=0x5 */
  3332. u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x790);
  3333. u8tmp &= 0xc0;
  3334. u8tmp |= 0x5;
  3335. btcoexist->btc_write_1byte(btcoexist, 0x790, u8tmp);
  3336. /* Enable BT counter statistics */
  3337. btcoexist->btc_write_1byte(btcoexist, 0x778, 0x1);
  3338. /* Enable PTA (3-wire function form BT side) */
  3339. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1);
  3340. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x41, 0x02, 0x1);
  3341. /* Enable PTA (tx/rx signal form WiFi side) */
  3342. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4c6, 0x10, 0x1);
  3343. /*GNT_BT=1 while select both */
  3344. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x763, 0x10, 0x1);
  3345. /* enable GNT_WL/GNT_BT debug signal to GPIO14/15 */
  3346. /*btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x8, 0x1);*/
  3347. /* enable GNT_WL */
  3348. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, 0x40, 0x0);
  3349. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x1, 0x0);
  3350. if (btcoexist->btc_read_1byte(btcoexist, 0x80) == 0xc6)
  3351. halbtc8822b1ant_post_state_to_bt(btcoexist,
  3352. BT_8822B_1ANT_SCOREBOARD_ONOFF, true);
  3353. /* Antenna config */
  3354. if (wifi_only) {
  3355. coex_sta->concurrent_rx_mode_on = false;
  3356. halbtc8822b1ant_set_ant_path(btcoexist,
  3357. BTC_ANT_PATH_WIFI,
  3358. FORCE_EXEC,
  3359. BT_8822B_1ANT_PHASE_WLANONLY_INIT);
  3360. } else {
  3361. coex_sta->concurrent_rx_mode_on = true;
  3362. halbtc8822b1ant_set_ant_path(btcoexist,
  3363. BTC_ANT_PATH_AUTO,
  3364. FORCE_EXEC,
  3365. BT_8822B_1ANT_PHASE_COEX_INIT);
  3366. }
  3367. /* PTA parameter */
  3368. halbtc8822b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
  3369. halbtc8822b1ant_enable_gnt_to_gpio(btcoexist, true);
  3370. }
  3371. void halbtc8822b1ant_init_hw_config_without_bt(IN struct btc_coexist *btcoexist,
  3372. IN boolean back_up, IN boolean wifi_only)
  3373. {
  3374. u8 u8tmp = 0;
  3375. boolean wifi_under_5g = false;
  3376. u32 u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0;
  3377. /* 0xf0[15:12] --> Chip Cut information */
  3378. coex_sta->cut_version = (btcoexist->btc_read_1byte(btcoexist,
  3379. 0xf1) & 0xf0) >> 4;
  3380. /* enable TBTT interrupt */
  3381. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x550, 0x8,
  3382. 0x1);
  3383. /* enable GNT_WL */
  3384. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, 0x40, 0x0);
  3385. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x1, 0x0);
  3386. /* Antenna config */
  3387. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, 0x80,
  3388. 0x0); /* 0x4c[23] = 0 */
  3389. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f, 0x01,
  3390. 0x1); /* 0x4c[24] = 1 */
  3391. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb4, 0xff,
  3392. 0x77); /* BB SW, DPDT use RFE_ctrl8 and RFE_ctrl9 as conctrol pin */
  3393. /* Ext switch buffer mux */
  3394. btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff);
  3395. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991, 0x3, 0x0);
  3396. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe, 0x8, 0x0);
  3397. /*enable sw control gnt_wl=1 / gnt_bt=1 */
  3398. btcoexist->btc_write_1byte(btcoexist, 0x73, 0x0e);
  3399. btcoexist->btc_write_4byte(btcoexist, 0x1704, 0x0000ff00);
  3400. btcoexist->btc_write_4byte(btcoexist, 0x1700, 0xc00f0038);
  3401. /* ant switch WL2G or WL5G*/
  3402. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G,
  3403. &wifi_under_5g);
  3404. if (wifi_under_5g)
  3405. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd,
  3406. 0x3, 1);
  3407. else
  3408. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd,
  3409. 0x3, 2);
  3410. }
  3411. void halbtc8822b1ant_psd_showdata(IN struct btc_coexist *btcoexist)
  3412. {
  3413. u8 *cli_buf = btcoexist->cli_buf;
  3414. u32 delta_freq_per_point;
  3415. u32 freq, freq1, freq2, n = 0, i = 0, j = 0, m = 0, psd_rep1, psd_rep2;
  3416. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3417. "\r\n\n============[PSD info] (%d)============\n",
  3418. psd_scan->psd_gen_count);
  3419. CL_PRINTF(cli_buf);
  3420. if (psd_scan->psd_gen_count == 0) {
  3421. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n No data !!\n");
  3422. CL_PRINTF(cli_buf);
  3423. return;
  3424. }
  3425. if (psd_scan->psd_point == 0)
  3426. delta_freq_per_point = 0;
  3427. else
  3428. delta_freq_per_point = psd_scan->psd_band_width /
  3429. psd_scan->psd_point;
  3430. /* if (psd_scan->is_psd_show_max_only) */
  3431. if (0) {
  3432. psd_rep1 = psd_scan->psd_max_value / 100;
  3433. psd_rep2 = psd_scan->psd_max_value - psd_rep1 * 100;
  3434. freq = ((psd_scan->real_cent_freq - 20) * 1000000 +
  3435. psd_scan->psd_max_value_point * delta_freq_per_point);
  3436. freq1 = freq / 1000000;
  3437. freq2 = freq / 1000 - freq1 * 1000;
  3438. if (freq2 < 100)
  3439. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3440. "\r\n Freq = %d.0%d MHz",
  3441. freq1, freq2);
  3442. else
  3443. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3444. "\r\n Freq = %d.%d MHz",
  3445. freq1, freq2);
  3446. if (psd_rep2 < 10)
  3447. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3448. ", Value = %d.0%d dB, (%d)\n",
  3449. psd_rep1, psd_rep2, psd_scan->psd_max_value);
  3450. else
  3451. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3452. ", Value = %d.%d dB, (%d)\n",
  3453. psd_rep1, psd_rep2, psd_scan->psd_max_value);
  3454. CL_PRINTF(cli_buf);
  3455. } else {
  3456. m = psd_scan->psd_start_point;
  3457. n = psd_scan->psd_start_point;
  3458. i = 1;
  3459. j = 1;
  3460. while (1) {
  3461. do {
  3462. freq = ((psd_scan->real_cent_freq - 20) *
  3463. 1000000 + m *
  3464. delta_freq_per_point);
  3465. freq1 = freq / 1000000;
  3466. freq2 = freq / 1000 - freq1 * 1000;
  3467. if (i == 1) {
  3468. if (freq2 == 0)
  3469. CL_SPRINTF(cli_buf,
  3470. BT_TMP_BUF_SIZE,
  3471. "\r\n Freq%6d.000",
  3472. freq1);
  3473. else if (freq2 < 100)
  3474. CL_SPRINTF(cli_buf,
  3475. BT_TMP_BUF_SIZE,
  3476. "\r\n Freq%6d.0%2d",
  3477. freq1,
  3478. freq2);
  3479. else
  3480. CL_SPRINTF(cli_buf,
  3481. BT_TMP_BUF_SIZE,
  3482. "\r\n Freq%6d.%3d",
  3483. freq1,
  3484. freq2);
  3485. } else if ((i % 8 == 0) ||
  3486. (m == psd_scan->psd_stop_point)) {
  3487. if (freq2 == 0)
  3488. CL_SPRINTF(cli_buf,
  3489. BT_TMP_BUF_SIZE,
  3490. "%6d.000\n", freq1);
  3491. else if (freq2 < 100)
  3492. CL_SPRINTF(cli_buf,
  3493. BT_TMP_BUF_SIZE,
  3494. "%6d.0%2d\n", freq1,
  3495. freq2);
  3496. else
  3497. CL_SPRINTF(cli_buf,
  3498. BT_TMP_BUF_SIZE,
  3499. "%6d.%3d\n", freq1,
  3500. freq2);
  3501. } else {
  3502. if (freq2 == 0)
  3503. CL_SPRINTF(cli_buf,
  3504. BT_TMP_BUF_SIZE,
  3505. "%6d.000", freq1);
  3506. else if (freq2 < 100)
  3507. CL_SPRINTF(cli_buf,
  3508. BT_TMP_BUF_SIZE,
  3509. "%6d.0%2d", freq1,
  3510. freq2);
  3511. else
  3512. CL_SPRINTF(cli_buf,
  3513. BT_TMP_BUF_SIZE,
  3514. "%6d.%3d", freq1,
  3515. freq2);
  3516. }
  3517. i++;
  3518. m++;
  3519. CL_PRINTF(cli_buf);
  3520. } while ((i <= 8) && (m <= psd_scan->psd_stop_point));
  3521. do {
  3522. psd_rep1 = psd_scan->psd_report_max_hold[n] /
  3523. 100;
  3524. psd_rep2 = psd_scan->psd_report_max_hold[n] -
  3525. psd_rep1 *
  3526. 100;
  3527. if (j == 1) {
  3528. if (psd_rep2 < 10)
  3529. CL_SPRINTF(cli_buf,
  3530. BT_TMP_BUF_SIZE,
  3531. "\r\n Val %7d.0%d",
  3532. psd_rep1,
  3533. psd_rep2);
  3534. else
  3535. CL_SPRINTF(cli_buf,
  3536. BT_TMP_BUF_SIZE,
  3537. "\r\n Val %7d.%d",
  3538. psd_rep1,
  3539. psd_rep2);
  3540. } else if ((j % 8 == 0) ||
  3541. (n == psd_scan->psd_stop_point)) {
  3542. if (psd_rep2 < 10)
  3543. CL_SPRINTF(cli_buf,
  3544. BT_TMP_BUF_SIZE,
  3545. "%7d.0%d\n", psd_rep1,
  3546. psd_rep2);
  3547. else
  3548. CL_SPRINTF(cli_buf,
  3549. BT_TMP_BUF_SIZE,
  3550. "%7d.%d\n", psd_rep1,
  3551. psd_rep2);
  3552. } else {
  3553. if (psd_rep2 < 10)
  3554. CL_SPRINTF(cli_buf,
  3555. BT_TMP_BUF_SIZE,
  3556. "%7d.0%d", psd_rep1,
  3557. psd_rep2);
  3558. else
  3559. CL_SPRINTF(cli_buf,
  3560. BT_TMP_BUF_SIZE,
  3561. "%7d.%d", psd_rep1,
  3562. psd_rep2);
  3563. }
  3564. j++;
  3565. n++;
  3566. CL_PRINTF(cli_buf);
  3567. } while ((j <= 8) && (n <= psd_scan->psd_stop_point));
  3568. if ((m > psd_scan->psd_stop_point) ||
  3569. (n > psd_scan->psd_stop_point))
  3570. break;
  3571. i = 1;
  3572. j = 1;
  3573. }
  3574. }
  3575. }
  3576. void halbtc8822b1ant_psd_max_holddata(IN struct btc_coexist *btcoexist,
  3577. IN u32 gen_count)
  3578. {
  3579. u32 i = 0, i_max = 0, val_max = 0;
  3580. if (gen_count == 1) {
  3581. memcpy(psd_scan->psd_report_max_hold,
  3582. psd_scan->psd_report,
  3583. BT_8822B_1ANT_ANTDET_PSD_POINTS * sizeof(u32));
  3584. for (i = psd_scan->psd_start_point;
  3585. i <= psd_scan->psd_stop_point; i++) {
  3586. }
  3587. psd_scan->psd_max_value_point = 0;
  3588. psd_scan->psd_max_value = 0;
  3589. } else {
  3590. for (i = psd_scan->psd_start_point;
  3591. i <= psd_scan->psd_stop_point; i++) {
  3592. if (psd_scan->psd_report[i] >
  3593. psd_scan->psd_report_max_hold[i])
  3594. psd_scan->psd_report_max_hold[i] =
  3595. psd_scan->psd_report[i];
  3596. /* search Max Value */
  3597. if (i == psd_scan->psd_start_point) {
  3598. i_max = i;
  3599. val_max = psd_scan->psd_report_max_hold[i];
  3600. } else {
  3601. if (psd_scan->psd_report_max_hold[i] >
  3602. val_max) {
  3603. i_max = i;
  3604. val_max = psd_scan->psd_report_max_hold[i];
  3605. }
  3606. }
  3607. }
  3608. psd_scan->psd_max_value_point = i_max;
  3609. psd_scan->psd_max_value = val_max;
  3610. }
  3611. }
  3612. u32 halbtc8822b1ant_psd_getdata(IN struct btc_coexist *btcoexist, IN u32 point)
  3613. {
  3614. /* reg 0x808[9:0]: FFT data x */
  3615. /* reg 0x808[22]: 0-->1 to get 1 FFT data y */
  3616. /* reg 0x8b4[15:0]: FFT data y report */
  3617. u32 val = 0, psd_report = 0;
  3618. val = btcoexist->btc_read_4byte(btcoexist, 0x808);
  3619. val &= 0xffbffc00;
  3620. val |= point;
  3621. btcoexist->btc_write_4byte(btcoexist, 0x808, val);
  3622. val |= 0x00400000;
  3623. btcoexist->btc_write_4byte(btcoexist, 0x808, val);
  3624. val = btcoexist->btc_read_4byte(btcoexist, 0x8b4);
  3625. psd_report = val & 0x0000ffff;
  3626. return psd_report;
  3627. }
  3628. void halbtc8822b1ant_psd_sweep_point(IN struct btc_coexist *btcoexist,
  3629. IN u32 cent_freq, IN s32 offset, IN u32 span, IN u32 points,
  3630. IN u32 avgnum)
  3631. {
  3632. u32 i, val, n, k = 0;
  3633. u32 points1 = 0, psd_report = 0;
  3634. u32 start_p = 0, stop_p = 0, delta_freq_per_point = 156250;
  3635. u32 psd_center_freq = 20 * 10 ^ 6, freq, freq1, freq2;
  3636. boolean outloop = false;
  3637. u8 flag = 0;
  3638. u32 tmp, psd_rep1, psd_rep2;
  3639. u32 wifi_original_channel = 1;
  3640. psd_scan->is_psd_running = true;
  3641. do {
  3642. switch (flag) {
  3643. case 0: /* Get PSD parameters */
  3644. default:
  3645. psd_scan->psd_band_width = 40 * 1000000;
  3646. psd_scan->psd_point = points;
  3647. psd_scan->psd_start_base = points / 2;
  3648. psd_scan->psd_avg_num = avgnum;
  3649. psd_scan->real_cent_freq = cent_freq;
  3650. psd_scan->real_offset = offset;
  3651. psd_scan->real_span = span;
  3652. points1 = psd_scan->psd_point;
  3653. delta_freq_per_point = psd_scan->psd_band_width /
  3654. psd_scan->psd_point;
  3655. /* PSD point setup */
  3656. val = btcoexist->btc_read_4byte(btcoexist, 0x808);
  3657. val &= 0xffff0fff;
  3658. switch (psd_scan->psd_point) {
  3659. case 128:
  3660. val |= 0x0;
  3661. break;
  3662. case 256:
  3663. default:
  3664. val |= 0x00004000;
  3665. break;
  3666. case 512:
  3667. val |= 0x00008000;
  3668. break;
  3669. case 1024:
  3670. val |= 0x0000c000;
  3671. break;
  3672. }
  3673. switch (psd_scan->psd_avg_num) {
  3674. case 1:
  3675. val |= 0x0;
  3676. break;
  3677. case 8:
  3678. val |= 0x00001000;
  3679. break;
  3680. case 16:
  3681. val |= 0x00002000;
  3682. break;
  3683. case 32:
  3684. default:
  3685. val |= 0x00003000;
  3686. break;
  3687. }
  3688. btcoexist->btc_write_4byte(btcoexist, 0x808, val);
  3689. flag = 1;
  3690. break;
  3691. case 1: /* calculate the PSD point index from freq/offset/span */
  3692. psd_center_freq = psd_scan->psd_band_width / 2 +
  3693. offset * (1000000);
  3694. start_p = psd_scan->psd_start_base + (psd_center_freq -
  3695. span * (1000000) / 2) / delta_freq_per_point;
  3696. psd_scan->psd_start_point = start_p -
  3697. psd_scan->psd_start_base;
  3698. stop_p = psd_scan->psd_start_base + (psd_center_freq +
  3699. span * (1000000) / 2) / delta_freq_per_point;
  3700. psd_scan->psd_stop_point = stop_p -
  3701. psd_scan->psd_start_base - 1;
  3702. flag = 2;
  3703. break;
  3704. case 2: /* set RF channel/BW/Mode */
  3705. /* set 3-wire off */
  3706. val = btcoexist->btc_read_4byte(btcoexist, 0x88c);
  3707. val |= 0x00300000;
  3708. btcoexist->btc_write_4byte(btcoexist, 0x88c, val);
  3709. /* CCK off */
  3710. val = btcoexist->btc_read_4byte(btcoexist, 0x800);
  3711. val &= 0xfeffffff;
  3712. btcoexist->btc_write_4byte(btcoexist, 0x800, val);
  3713. /* store WiFi original channel */
  3714. wifi_original_channel = btcoexist->btc_get_rf_reg(
  3715. btcoexist, BTC_RF_A, 0x18, 0x3ff);
  3716. /* Set RF channel */
  3717. if (cent_freq == 2484)
  3718. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A,
  3719. 0x18, 0x3ff, 0xe);
  3720. else
  3721. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A,
  3722. 0x18, 0x3ff, (cent_freq - 2412) / 5 +
  3723. 1); /* WiFi TRx Mask on */
  3724. /* Set RF mode = Rx, RF Gain = 0x8a0 */
  3725. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x0,
  3726. 0xfffff, 0x308a0);
  3727. /* Set RF Rx filter corner */
  3728. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1e,
  3729. 0xfffff, 0x3e4);
  3730. /* Set TRx mask off */
  3731. /* un-lock TRx Mask setup */
  3732. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xdd,
  3733. 0x80, 0x1);
  3734. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xdf,
  3735. 0x1, 0x1);
  3736. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1,
  3737. 0xfffff, 0x0);
  3738. flag = 3;
  3739. break;
  3740. case 3:
  3741. memset(psd_scan->psd_report, 0,
  3742. psd_scan->psd_point * sizeof(u32));
  3743. start_p = psd_scan->psd_start_point +
  3744. psd_scan->psd_start_base;
  3745. stop_p = psd_scan->psd_stop_point +
  3746. psd_scan->psd_start_base + 1;
  3747. i = start_p;
  3748. while (i < stop_p) {
  3749. if (i >= points1)
  3750. psd_report =
  3751. halbtc8822b1ant_psd_getdata(
  3752. btcoexist, i - points1);
  3753. else
  3754. psd_report =
  3755. halbtc8822b1ant_psd_getdata(
  3756. btcoexist, i);
  3757. if (psd_report == 0)
  3758. tmp = 0;
  3759. else
  3760. /* tmp = 20*log10((double)psd_report); */
  3761. /* 20*log2(x)/log2(10), log2Base return theresult of the psd_report*100 */
  3762. tmp = 6 * halbtc8822b1ant_psd_log2base(
  3763. btcoexist, psd_report);
  3764. n = i - psd_scan->psd_start_base;
  3765. psd_scan->psd_report[n] = tmp;
  3766. psd_rep1 = psd_scan->psd_report[n] / 100;
  3767. psd_rep2 = psd_scan->psd_report[n] - psd_rep1 *
  3768. 100;
  3769. freq = ((cent_freq - 20) * 1000000 + n *
  3770. delta_freq_per_point);
  3771. freq1 = freq / 1000000;
  3772. freq2 = freq / 1000 - freq1 * 1000;
  3773. i++;
  3774. k = 0;
  3775. /* Add Delay between PSD point */
  3776. while (1) {
  3777. if (k++ > 20000)
  3778. break;
  3779. }
  3780. }
  3781. flag = 100;
  3782. break;
  3783. case 99: /* error */
  3784. outloop = true;
  3785. break;
  3786. case 100: /* recovery */
  3787. /* set 3-wire on */
  3788. val = btcoexist->btc_read_4byte(btcoexist, 0x88c);
  3789. val &= 0xffcfffff;
  3790. btcoexist->btc_write_4byte(btcoexist, 0x88c, val);
  3791. /* CCK on */
  3792. val = btcoexist->btc_read_4byte(btcoexist, 0x800);
  3793. val |= 0x01000000;
  3794. btcoexist->btc_write_4byte(btcoexist, 0x800, val);
  3795. /* PSD off */
  3796. val = btcoexist->btc_read_4byte(btcoexist, 0x808);
  3797. val &= 0xffbfffff;
  3798. btcoexist->btc_write_4byte(btcoexist, 0x808, val);
  3799. /* TRx Mask on */
  3800. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1,
  3801. 0xfffff, 0x780);
  3802. /* lock TRx Mask setup */
  3803. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xdd,
  3804. 0x80, 0x0);
  3805. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xdf,
  3806. 0x1, 0x0);
  3807. /* Set RF Rx filter corner */
  3808. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1e,
  3809. 0xfffff, 0x0);
  3810. /* restore WiFi original channel */
  3811. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x18,
  3812. 0x3ff, wifi_original_channel);
  3813. outloop = true;
  3814. break;
  3815. }
  3816. } while (!outloop);
  3817. psd_scan->is_psd_running = false;
  3818. }
  3819. #if (BTC_COEX_OFFLOAD == 1)
  3820. void halbtc8822b1ant_wifi_info_notify(IN struct btc_coexist *btcoexist)
  3821. {
  3822. u8 h2c_para[4] = {0};
  3823. u8 opcode_ver = 0;
  3824. u8 ap_num = 0;
  3825. s32 wifi_rssi = 0;
  3826. boolean wifi_busy = false;
  3827. btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
  3828. btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, &ap_num);
  3829. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  3830. h2c_para[0] = ap_num; /* AP number */
  3831. h2c_para[1] = (u8)wifi_busy; /* Busy */
  3832. h2c_para[2] = (u8)wifi_rssi; /* RSSI */
  3833. btcoexist->btc_coex_h2c_process(btcoexist, COL_OP_WIFI_INFO_NOTIFY,
  3834. opcode_ver, &h2c_para[0], 3);
  3835. }
  3836. void halbtc8822b1ant_setManual(IN struct btc_coexist *btcoexist,
  3837. IN boolean manual)
  3838. {
  3839. u8 h2c_para[4] = {0};
  3840. u8 opcode_ver = 0;
  3841. u8 set_type = 0;
  3842. if (manual)
  3843. set_type = 1;
  3844. else
  3845. set_type = 0;
  3846. h2c_para[0] = set_type; /* set_type */
  3847. btcoexist->btc_coex_h2c_process(btcoexist, COL_OP_SET_CONTROL,
  3848. opcode_ver,
  3849. &h2c_para[0], 1);
  3850. }
  3851. /* ************************************************************
  3852. * work around function start with wa_halbtc8822b1ant_
  3853. * ************************************************************
  3854. * ************************************************************
  3855. * extern function start with ex_halbtc8822b1ant_
  3856. * ************************************************************ */
  3857. void ex_halbtc8822b1ant_power_on_setting(IN struct btc_coexist *btcoexist)
  3858. {}
  3859. void ex_halbtc8822b1ant_pre_load_firmware(IN struct btc_coexist *btcoexist)
  3860. {}
  3861. void ex_halbtc8822b1ant_init_hw_config(IN struct btc_coexist *btcoexist,
  3862. IN boolean wifi_only)
  3863. {}
  3864. void ex_halbtc8822b1ant_init_coex_dm(IN struct btc_coexist *btcoexist)
  3865. {}
  3866. void ex_halbtc8822b1ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type)
  3867. {
  3868. u8 h2c_para[4] = {0};
  3869. u8 opcode_ver = 0;
  3870. u8 ips_notify = 0;
  3871. if (BTC_IPS_ENTER == type) {
  3872. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3873. "[BTCoex], IPS ENTER notify\n");
  3874. BTC_TRACE(trace_buf);
  3875. ips_notify = 1;
  3876. } else if (BTC_IPS_LEAVE == type) {
  3877. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3878. "[BTCoex], IPS LEAVE notify\n");
  3879. BTC_TRACE(trace_buf);
  3880. }
  3881. h2c_para[0] = ips_notify; /* IPS notify */
  3882. h2c_para[1] = 0xff; /* LPS notify */
  3883. h2c_para[2] = 0xff; /* RF state notify */
  3884. h2c_para[3] = 0xff; /* pnp notify */
  3885. btcoexist->btc_coex_h2c_process(btcoexist,
  3886. COL_OP_WIFI_POWER_STATE_NOTIFY,
  3887. opcode_ver, &h2c_para[0], 4);
  3888. }
  3889. void ex_halbtc8822b1ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type)
  3890. {
  3891. u8 h2c_para[4] = {0};
  3892. u8 opcode_ver = 0;
  3893. u8 lps_notify = 0;
  3894. if (BTC_LPS_ENABLE == type) {
  3895. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3896. "[BTCoex], LPS ENABLE notify\n");
  3897. BTC_TRACE(trace_buf);
  3898. lps_notify = 1;
  3899. } else if (BTC_LPS_DISABLE == type) {
  3900. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3901. "[BTCoex], LPS DISABLE notify\n");
  3902. BTC_TRACE(trace_buf);
  3903. }
  3904. h2c_para[0] = 0xff; /* IPS notify */
  3905. h2c_para[1] = lps_notify; /* LPS notify */
  3906. h2c_para[2] = 0xff; /* RF state notify */
  3907. h2c_para[3] = 0xff; /* pnp notify */
  3908. btcoexist->btc_coex_h2c_process(btcoexist,
  3909. COL_OP_WIFI_POWER_STATE_NOTIFY,
  3910. opcode_ver, &h2c_para[0], 4);
  3911. }
  3912. void ex_halbtc8822b1ant_scan_notify(IN struct btc_coexist *btcoexist,
  3913. IN u8 type)
  3914. {
  3915. u8 h2c_para[4] = {0};
  3916. u8 opcode_ver = 0;
  3917. u8 scan_start = 0;
  3918. boolean under_4way = false;
  3919. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
  3920. &under_4way);
  3921. if (BTC_SCAN_START == type) {
  3922. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3923. "[BTCoex], SCAN START notify\n");
  3924. BTC_TRACE(trace_buf);
  3925. scan_start = 1;
  3926. } else {
  3927. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3928. "[BTCoex], SCAN FINISH notify\n");
  3929. BTC_TRACE(trace_buf);
  3930. }
  3931. h2c_para[0] = scan_start; /* scan notify */
  3932. h2c_para[1] = 0xff; /* connect notify */
  3933. h2c_para[2] = 0xff; /* specific packet notify */
  3934. if (under_4way)
  3935. h2c_para[3] = 1; /* under 4way progress */
  3936. else
  3937. h2c_para[3] = 0;
  3938. btcoexist->btc_coex_h2c_process(btcoexist, COL_OP_WIFI_PROGRESS_NOTIFY,
  3939. opcode_ver, &h2c_para[0], 4);
  3940. }
  3941. void ex_halbtc8822b1ant_connect_notify(IN struct btc_coexist *btcoexist,
  3942. IN u8 type)
  3943. {
  3944. u8 h2c_para[4] = {0};
  3945. u8 opcode_ver = 0;
  3946. u8 connect_start = 0;
  3947. boolean under_4way = false;
  3948. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
  3949. &under_4way);
  3950. if (BTC_ASSOCIATE_START == type) {
  3951. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3952. "[BTCoex], CONNECT START notify\n");
  3953. BTC_TRACE(trace_buf);
  3954. connect_start = 1;
  3955. } else {
  3956. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3957. "[BTCoex], CONNECT FINISH notify\n");
  3958. BTC_TRACE(trace_buf);
  3959. }
  3960. h2c_para[0] = 0xff; /* scan notify */
  3961. h2c_para[1] = connect_start; /* connect notify */
  3962. h2c_para[2] = 0xff; /* specific packet notify */
  3963. if (under_4way)
  3964. h2c_para[3] = 1; /* under 4way progress */
  3965. else
  3966. h2c_para[3] = 0;
  3967. btcoexist->btc_coex_h2c_process(btcoexist, COL_OP_WIFI_PROGRESS_NOTIFY,
  3968. opcode_ver, &h2c_para[0], 4);
  3969. }
  3970. void ex_halbtc8822b1ant_media_status_notify(IN struct btc_coexist *btcoexist,
  3971. IN u8 type)
  3972. {
  3973. u32 wifi_bw;
  3974. u8 wifi_central_chnl;
  3975. u8 h2c_para[5] = {0};
  3976. u8 opcode_ver = 0;
  3977. u8 port = 0, connected = 0, freq = 0, bandwidth = 0, iot_peer = 0;
  3978. boolean wifi_under_5g = false;
  3979. if (BTC_MEDIA_CONNECT == type)
  3980. connected = 1;
  3981. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  3982. bandwidth = (u8)wifi_bw;
  3983. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  3984. if (wifi_under_5g)
  3985. freq = 1;
  3986. else
  3987. freq = 0;
  3988. btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL,
  3989. &wifi_central_chnl);
  3990. btcoexist->btc_get(btcoexist, BTC_GET_U1_IOT_PEER, &iot_peer);
  3991. h2c_para[0] = (connected << 4) |
  3992. port; /* port need to be implemented in the future (p2p port, ...) */
  3993. h2c_para[1] = (freq << 4) | bandwidth;
  3994. h2c_para[2] = wifi_central_chnl;
  3995. h2c_para[3] = iot_peer;
  3996. btcoexist->btc_coex_h2c_process(btcoexist, COL_OP_WIFI_STATUS_NOTIFY,
  3997. opcode_ver, &h2c_para[0], 4);
  3998. }
  3999. void ex_halbtc8822b1ant_specific_packet_notify(IN struct btc_coexist *btcoexist,
  4000. IN u8 type)
  4001. {
  4002. u8 h2c_para[4] = {0};
  4003. u8 opcode_ver = 0;
  4004. u8 connect_start = 0;
  4005. boolean under_4way = false;
  4006. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
  4007. &under_4way);
  4008. h2c_para[0] = 0xff; /* scan notify */
  4009. h2c_para[1] = 0xff; /* connect notify */
  4010. h2c_para[2] = type; /* specific packet notify */
  4011. if (under_4way)
  4012. h2c_para[3] = 1; /* under 4way progress */
  4013. else
  4014. h2c_para[3] = 0;
  4015. btcoexist->btc_coex_h2c_process(btcoexist, COL_OP_WIFI_PROGRESS_NOTIFY,
  4016. opcode_ver, &h2c_para[0], 4);
  4017. }
  4018. void ex_halbtc8822b1ant_bt_info_notify(IN struct btc_coexist *btcoexist,
  4019. IN u8 *tmp_buf, IN u8 length)
  4020. {}
  4021. void ex_halbtc8822b1ant_rf_status_notify(IN struct btc_coexist *btcoexist,
  4022. IN u8 type)
  4023. {
  4024. u8 h2c_para[4] = {0};
  4025. u8 opcode_ver = 0;
  4026. u8 rfstate_notify = 0;
  4027. if (BTC_RF_ON == type) {
  4028. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4029. "[BTCoex], RF is turned ON!!\n");
  4030. BTC_TRACE(trace_buf);
  4031. rfstate_notify = 1;
  4032. } else if (BTC_RF_OFF == type) {
  4033. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4034. "[BTCoex], RF is turned OFF!!\n");
  4035. BTC_TRACE(trace_buf);
  4036. }
  4037. h2c_para[0] = 0xff; /* IPS notify */
  4038. h2c_para[1] = 0xff; /* LPS notify */
  4039. h2c_para[2] = rfstate_notify; /* RF state notify */
  4040. h2c_para[3] = 0xff; /* pnp notify */
  4041. btcoexist->btc_coex_h2c_process(btcoexist,
  4042. COL_OP_WIFI_POWER_STATE_NOTIFY,
  4043. opcode_ver, &h2c_para[0], 4);
  4044. }
  4045. void ex_halbtc8822b1ant_halt_notify(IN struct btc_coexist *btcoexist)
  4046. {}
  4047. void ex_halbtc8822b1ant_pnp_notify(IN struct btc_coexist *btcoexist,
  4048. IN u8 pnp_state)
  4049. {
  4050. u8 h2c_para[4] = {0};
  4051. u8 opcode_ver = 0;
  4052. u8 pnp_notify = 0;
  4053. if (BTC_WIFI_PNP_SLEEP == pnp_state) {
  4054. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4055. "[BTCoex], Pnp notify to SLEEP\n");
  4056. BTC_TRACE(trace_buf);
  4057. pnp_notify = 1;
  4058. } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) {
  4059. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4060. "[BTCoex], Pnp notify to WAKE UP\n");
  4061. BTC_TRACE(trace_buf);
  4062. }
  4063. h2c_para[0] = 0xff; /* IPS notify */
  4064. h2c_para[1] = 0xff; /* LPS notify */
  4065. h2c_para[2] = 0xff; /* RF state notify */
  4066. h2c_para[3] = pnp_notify; /* pnp notify */
  4067. btcoexist->btc_coex_h2c_process(btcoexist,
  4068. COL_OP_WIFI_POWER_STATE_NOTIFY,
  4069. opcode_ver, &h2c_para[0], 4);
  4070. }
  4071. void ex_halbtc8822b1ant_coex_dm_reset(IN struct btc_coexist *btcoexist)
  4072. {}
  4073. void ex_halbtc8822b1ant_periodical(IN struct btc_coexist *btcoexist)
  4074. {
  4075. halbtc8822b1ant_wifi_info_notify(btcoexist);
  4076. }
  4077. void ex_halbtc8822b1ant_display_coex_info(IN struct btc_coexist *btcoexist)
  4078. {
  4079. struct btc_board_info *board_info = &btcoexist->board_info;
  4080. struct btc_stack_info *stack_info = &btcoexist->stack_info;
  4081. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  4082. u8 *cli_buf = btcoexist->cli_buf;
  4083. u8 u8tmp[4], i, bt_info_ext, ps_tdma_case = 0;
  4084. u16 u16tmp[4];
  4085. u32 u32tmp[4];
  4086. u32 fa_ofdm, fa_cck, cca_ofdm, cca_cck;
  4087. u32 fw_ver = 0, bt_patch_ver = 0, bt_coex_ver = 0;
  4088. static u8 pop_report_in_10s = 0;
  4089. u32 phyver = 0;
  4090. boolean lte_coex_on = false;
  4091. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4092. "\r\n ============[BT Coexist info]============");
  4093. CL_PRINTF(cli_buf);
  4094. if (btcoexist->manual_control) {
  4095. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4096. "\r\n ============[Under Manual Control]============");
  4097. CL_PRINTF(cli_buf);
  4098. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4099. "\r\n ==========================================");
  4100. CL_PRINTF(cli_buf);
  4101. }
  4102. if (btcoexist->stop_coex_dm) {
  4103. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4104. "\r\n ============[Coex is STOPPED]============");
  4105. CL_PRINTF(cli_buf);
  4106. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4107. "\r\n ==========================================");
  4108. CL_PRINTF(cli_buf);
  4109. }
  4110. if (psd_scan->ant_det_try_count == 0) {
  4111. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4112. "\r\n %-35s = %d/ %d/ %s / %d",
  4113. "Ant PG Num/ Mech/ Pos/ RFE",
  4114. board_info->pg_ant_num, board_info->btdm_ant_num,
  4115. (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT
  4116. ? "Main" : "Aux"),
  4117. rfe_type->rfe_module_type);
  4118. CL_PRINTF(cli_buf);
  4119. } else {
  4120. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4121. "\r\n %-35s = %d/ %d/ %s/ %d (%d/%d/%d)",
  4122. "Ant PG Num/ Mech(Ant_Det)/ Pos/ RFE",
  4123. board_info->pg_ant_num,
  4124. board_info->btdm_ant_num_by_ant_det,
  4125. (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT
  4126. ? "Main" : "Aux"),
  4127. rfe_type->rfe_module_type,
  4128. psd_scan->ant_det_try_count,
  4129. psd_scan->ant_det_fail_count,
  4130. psd_scan->ant_det_result);
  4131. CL_PRINTF(cli_buf);
  4132. if (board_info->btdm_ant_det_finish) {
  4133. if (psd_scan->ant_det_result != 12)
  4134. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s",
  4135. "Ant Det PSD Value",
  4136. psd_scan->ant_det_peak_val);
  4137. else
  4138. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4139. "\r\n %-35s = %d",
  4140. "Ant Det PSD Value",
  4141. psd_scan->ant_det_psd_scan_peak_val / 100);
  4142. CL_PRINTF(cli_buf);
  4143. }
  4144. }
  4145. btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
  4146. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
  4147. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4148. "\r\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)",
  4149. "CoexVer/ FwVer/ PatchVer",
  4150. glcoex_ver_date_8822b_1ant, glcoex_ver_8822b_1ant, fw_ver,
  4151. bt_patch_ver, bt_patch_ver);
  4152. CL_PRINTF(cli_buf);
  4153. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ",
  4154. "Wifi channel informed to BT",
  4155. coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1],
  4156. coex_dm->wifi_chnl_info[2]);
  4157. CL_PRINTF(cli_buf);
  4158. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s",
  4159. "WifibHiPri/ Ccklock/ CckEverLock",
  4160. (coex_sta->wifi_is_high_pri_task ? "Yes" : "No"),
  4161. (coex_sta->cck_lock ? "Yes" : "No"),
  4162. (coex_sta->cck_ever_lock ? "Yes" : "No"));
  4163. CL_PRINTF(cli_buf);
  4164. /* wifi status */
  4165. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  4166. "============[Wifi Status]============");
  4167. CL_PRINTF(cli_buf);
  4168. btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS);
  4169. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  4170. "============[BT Status]============");
  4171. CL_PRINTF(cli_buf);
  4172. pop_report_in_10s++;
  4173. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d/ %d] ",
  4174. "BT [status/ rssi/ retryCnt/ popCnt]",
  4175. ((coex_sta->bt_disabled) ? ("disabled") : ((
  4176. coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan")
  4177. : ((BT_8822B_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
  4178. coex_dm->bt_status) ? "non-connected idle" :
  4179. ((BT_8822B_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)
  4180. ? "connected-idle" : "busy")))),
  4181. coex_sta->bt_rssi - 100, coex_sta->bt_retry_cnt,
  4182. coex_sta->pop_event_cnt);
  4183. CL_PRINTF(cli_buf);
  4184. if (pop_report_in_10s >= 5) {
  4185. coex_sta->pop_event_cnt = 0;
  4186. pop_report_in_10s = 0;
  4187. }
  4188. if (coex_sta->num_of_profile != 0)
  4189. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4190. "\r\n %-35s = %s%s%s%s%s",
  4191. "Profiles",
  4192. ((bt_link_info->a2dp_exist) ? "A2DP," : ""),
  4193. ((bt_link_info->sco_exist) ? "SCO," : ""),
  4194. ((bt_link_info->hid_exist) ?
  4195. ((coex_sta->hid_busy_num >= 2) ? "HID(4/18)," : "HID(2/18),") : ""),
  4196. ((bt_link_info->pan_exist) ? "PAN," : ""),
  4197. ((coex_sta->voice_over_HOGP) ? "Voice" : ""));
  4198. else
  4199. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4200. "\r\n %-35s = None", "Profiles");
  4201. CL_PRINTF(cli_buf);
  4202. if (bt_link_info->a2dp_exist) {
  4203. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %s",
  4204. "A2DP Rate/Bitpool/Auto_Slot",
  4205. ((coex_sta->is_A2DP_3M) ? "3M" : "No_3M"),
  4206. coex_sta->a2dp_bit_pool,
  4207. ((coex_sta->is_autoslot) ? "On" : "Off"));
  4208. CL_PRINTF(cli_buf);
  4209. }
  4210. if (bt_link_info->hid_exist) {
  4211. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
  4212. "HID PairNum/Forbid_Slot",
  4213. coex_sta->hid_pair_cnt,
  4214. coex_sta->forbidden_slot
  4215. );
  4216. CL_PRINTF(cli_buf);
  4217. }
  4218. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %s/ 0x%x/ 0x%x",
  4219. "Role/IgnWlanAct/Feature/BLEScan",
  4220. ((bt_link_info->slave_role) ? "Slave" : "Master"),
  4221. ((coex_dm->cur_ignore_wlan_act) ? "Yes":"No"),
  4222. coex_sta->bt_coex_supported_feature,
  4223. coex_sta->bt_ble_scan_type);
  4224. CL_PRINTF(cli_buf);
  4225. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d",
  4226. "ReInit/ReLink/IgnWlact/Page/NameReq",
  4227. coex_sta->cnt_ReInit,
  4228. coex_sta->cnt_setupLink,
  4229. coex_sta->cnt_IgnWlanAct,
  4230. coex_sta->cnt_Page,
  4231. coex_sta->cnt_RemoteNameReq
  4232. );
  4233. CL_PRINTF(cli_buf);
  4234. halbtc8822b1ant_read_score_board(btcoexist, &u16tmp[0]);
  4235. if ((coex_sta->bt_reg_vendor_ae == 0xffff) ||
  4236. (coex_sta->bt_reg_vendor_ac == 0xffff))
  4237. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = x/ x/ %04x",
  4238. "0xae[4]/0xac[1:0]/Scoreboard", u16tmp[0]);
  4239. else
  4240. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4241. "\r\n %-35s = 0x%x/ 0x%x/ %04x",
  4242. "0xae[4]/0xac[1:0]/Scoreboard",
  4243. ((coex_sta->bt_reg_vendor_ae & BIT(4))>>4),
  4244. coex_sta->bt_reg_vendor_ac & 0x3, u16tmp[0]);
  4245. CL_PRINTF(cli_buf);
  4246. for (i = 0; i < BT_INFO_SRC_8822B_1ANT_MAX; i++) {
  4247. if (coex_sta->bt_info_c2h_cnt[i]) {
  4248. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4249. "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)",
  4250. glbt_info_src_8822b_1ant[i],
  4251. coex_sta->bt_info_c2h[i][0],
  4252. coex_sta->bt_info_c2h[i][1],
  4253. coex_sta->bt_info_c2h[i][2],
  4254. coex_sta->bt_info_c2h[i][3],
  4255. coex_sta->bt_info_c2h[i][4],
  4256. coex_sta->bt_info_c2h[i][5],
  4257. coex_sta->bt_info_c2h[i][6],
  4258. coex_sta->bt_info_c2h_cnt[i]);
  4259. CL_PRINTF(cli_buf);
  4260. }
  4261. }
  4262. if (btcoexist->manual_control)
  4263. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  4264. "============[mechanisms] (before Manual)============");
  4265. else
  4266. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  4267. "============[mechanisms]============");
  4268. CL_PRINTF(cli_buf);
  4269. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d",
  4270. "SM[LowPenaltyRA]",
  4271. coex_dm->cur_low_penalty_ra);
  4272. CL_PRINTF(cli_buf);
  4273. ps_tdma_case = coex_dm->cur_ps_tdma;
  4274. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4275. "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (%s,%s)",
  4276. "PS TDMA",
  4277. coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1],
  4278. coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3],
  4279. coex_dm->ps_tdma_para[4], ps_tdma_case,
  4280. (coex_dm->cur_ps_tdma_on ? "On" : "Off"),
  4281. (coex_dm->auto_tdma_adjust ? "Adj" : "Fix"));
  4282. CL_PRINTF(cli_buf);
  4283. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d",
  4284. "WL/BT Coex Table Type",
  4285. coex_sta->coex_table_type);
  4286. CL_PRINTF(cli_buf);
  4287. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
  4288. u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
  4289. u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
  4290. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4291. "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
  4292. "0x6c0/0x6c4/0x6c8(coexTable)",
  4293. u32tmp[0], u32tmp[1], u32tmp[2]);
  4294. CL_PRINTF(cli_buf);
  4295. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
  4296. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6cc);
  4297. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4298. "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
  4299. "0x778/0x6cc/IgnWlanAct",
  4300. u8tmp[0], u32tmp[0], coex_dm->cur_ignore_wlan_act);
  4301. CL_PRINTF(cli_buf);
  4302. u32tmp[0] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
  4303. 0xa0);
  4304. u32tmp[1] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
  4305. 0xa4);
  4306. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
  4307. "LTE Coex Table W_L/B_L",
  4308. u32tmp[0] & 0xffff, u32tmp[1] & 0xffff);
  4309. CL_PRINTF(cli_buf);
  4310. u32tmp[0] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
  4311. 0xa8);
  4312. u32tmp[1] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
  4313. 0xac);
  4314. u32tmp[2] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
  4315. 0xb0);
  4316. u32tmp[3] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
  4317. 0xb4);
  4318. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4319. "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
  4320. "LTE Break Table W_L/B_L/L_W/L_B",
  4321. u32tmp[0] & 0xffff, u32tmp[1] & 0xffff,
  4322. u32tmp[2] & 0xffff, u32tmp[3] & 0xffff);
  4323. CL_PRINTF(cli_buf);
  4324. /* Hw setting */
  4325. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  4326. "============[Hw setting]============");
  4327. CL_PRINTF(cli_buf);
  4328. /*
  4329. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x430);
  4330. u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x434);
  4331. u16tmp[0] = btcoexist->btc_read_2byte(btcoexist, 0x42a);
  4332. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x456);
  4333. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
  4334. "0x430/0x434/0x42a/0x456",
  4335. u32tmp[0], u32tmp[1], u16tmp[0], u8tmp[0]);
  4336. CL_PRINTF(cli_buf);
  4337. */
  4338. u32tmp[0] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, 0x38);
  4339. u32tmp[1] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, 0x54);
  4340. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x73);
  4341. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %s",
  4342. "LTE CoexOn/Path Ctrl Owner",
  4343. (int)((u32tmp[0]&BIT(7)) >> 7),
  4344. ((u8tmp[0]&BIT(2)) ? "WL" : "BT"));
  4345. CL_PRINTF(cli_buf);
  4346. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
  4347. "LTE 3Wire/OPMode/UART/UARTMode",
  4348. (int)((u32tmp[0]&BIT(6)) >> 6),
  4349. (int)((u32tmp[0] & (BIT(5) | BIT(4))) >> 4),
  4350. (int)((u32tmp[0]&BIT(3)) >> 3),
  4351. (int)(u32tmp[0] & (BIT(2) | BIT(1) | BIT(0))));
  4352. CL_PRINTF(cli_buf);
  4353. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %s",
  4354. "GNT_WL_SWCtrl/GNT_BT_SWCtrl/Dbg",
  4355. (int)((u32tmp[0]&BIT(12)) >> 12),
  4356. (int)((u32tmp[0]&BIT(14)) >> 14),
  4357. ((u8tmp[0]&BIT(3)) ? "On" : "Off"));
  4358. CL_PRINTF(cli_buf);
  4359. u32tmp[0] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, 0x54);
  4360. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
  4361. "GNT_WL/GNT_BT/LTE_Busy/UART_Busy",
  4362. (int)((u32tmp[0]&BIT(2)) >> 2),
  4363. (int)((u32tmp[0]&BIT(3)) >> 3),
  4364. (int)((u32tmp[0]&BIT(1)) >> 1), (int)(u32tmp[0]&BIT(0)));
  4365. CL_PRINTF(cli_buf);
  4366. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x4c6);
  4367. u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x40);
  4368. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
  4369. "0x4c6[4]/0x40[5] (WL/BT PTA)",
  4370. (int)((u8tmp[0] & BIT(4)) >> 4),
  4371. (int)((u8tmp[1] & BIT(5)) >> 5));
  4372. CL_PRINTF(cli_buf);
  4373. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
  4374. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
  4375. u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x953);
  4376. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ %s",
  4377. "0x550(bcn ctrl)/0x522/4-RxAGC",
  4378. u32tmp[0], u8tmp[0], (u8tmp[1] & 0x2) ? "On" : "Off");
  4379. CL_PRINTF(cli_buf);
  4380. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xda0);
  4381. u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0xda4);
  4382. u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0xda8);
  4383. u32tmp[3] = btcoexist->btc_read_4byte(btcoexist, 0xcf0);
  4384. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xa5b);
  4385. u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xa5c);
  4386. fa_ofdm = ((u32tmp[0] & 0xffff0000) >> 16) + ((u32tmp[1] & 0xffff0000)
  4387. >> 16) + (u32tmp[1] & 0xffff) + (u32tmp[2] & 0xffff) +
  4388. ((u32tmp[3] & 0xffff0000) >> 16) + (u32tmp[3] &
  4389. 0xffff);
  4390. fa_cck = (u8tmp[0] << 8) + u8tmp[1];
  4391. u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0xc50);
  4392. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4393. "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
  4394. "0xc50/OFDM-CCA/OFDM-FA/CCK-FA",
  4395. u32tmp[1] & 0xff, u32tmp[0] & 0xffff, fa_ofdm, fa_cck);
  4396. CL_PRINTF(cli_buf);
  4397. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
  4398. "CRC_OK CCK/11g/11n/11n-Agg",
  4399. coex_sta->crc_ok_cck, coex_sta->crc_ok_11g,
  4400. coex_sta->crc_ok_11n, coex_sta->crc_ok_11n_agg);
  4401. CL_PRINTF(cli_buf);
  4402. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
  4403. "CRC_Err CCK/11g/11n/11n-Agg",
  4404. coex_sta->crc_err_cck, coex_sta->crc_err_11g,
  4405. coex_sta->crc_err_11n, coex_sta->crc_err_11n_agg);
  4406. CL_PRINTF(cli_buf);
  4407. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
  4408. "0x770(high-pri rx/tx)",
  4409. coex_sta->high_priority_rx, coex_sta->high_priority_tx);
  4410. CL_PRINTF(cli_buf);
  4411. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
  4412. "0x774(low-pri rx/tx)",
  4413. coex_sta->low_priority_rx, coex_sta->low_priority_tx);
  4414. CL_PRINTF(cli_buf);
  4415. #if (BT_AUTO_REPORT_ONLY_8822B_1ANT == 1)
  4416. /* halbtc8822b1ant_monitor_bt_ctr(btcoexist); */
  4417. #endif
  4418. btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS);
  4419. }
  4420. void ex_halbtc8822b1ant_antenna_detection(IN struct btc_coexist *btcoexist,
  4421. IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds)
  4422. {}
  4423. void ex_halbtc8822b1ant_display_ant_detection(IN struct btc_coexist *btcoexist)
  4424. {}
  4425. void ex_halbtc8822b1ant_dbg_control(IN struct btc_coexist *btcoexist,
  4426. IN u8 op_code, IN u8 op_len, IN u8 *pdata)
  4427. {
  4428. switch (op_code) {
  4429. case BTC_DBG_SET_COEX_MANUAL_CTRL: {
  4430. boolean manual = (boolean) *pdata;
  4431. halbtc8822b1ant_setManual(btcoexist, manual);
  4432. }
  4433. break;
  4434. default:
  4435. break;
  4436. }
  4437. }
  4438. #else
  4439. void ex_halbtc8822b1ant_power_on_setting(IN struct btc_coexist *btcoexist)
  4440. {
  4441. struct btc_board_info *board_info = &btcoexist->board_info;
  4442. u8 u8tmp = 0x0;
  4443. u16 u16tmp = 0x0;
  4444. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4445. "xxxxxxxxxxxxxxxx Execute 8822b 1-Ant PowerOn Setting!! xxxxxxxxxxxxxxxx\n");
  4446. BTC_TRACE(trace_buf);
  4447. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4448. "Ant Det Finish = %s, Ant Det Number = %d\n",
  4449. board_info->btdm_ant_det_finish ? "Yes" : "No",
  4450. board_info->btdm_ant_num_by_ant_det);
  4451. BTC_TRACE(trace_buf);
  4452. btcoexist->stop_coex_dm = true;
  4453. /* enable BB, REG_SYS_FUNC_EN such that we can write 0x948 correctly. */
  4454. u16tmp = btcoexist->btc_read_2byte(btcoexist, 0x2);
  4455. btcoexist->btc_write_2byte(btcoexist, 0x2, u16tmp | BIT(0) | BIT(1));
  4456. /* set Path control owner to WiFi */
  4457. halbtc8822b1ant_ltecoex_pathcontrol_owner(btcoexist,
  4458. BT_8822B_1ANT_PCO_WLSIDE);
  4459. /* set GNT_BT to high */
  4460. halbtc8822b1ant_ltecoex_set_gnt_bt(btcoexist,
  4461. BT_8822B_1ANT_GNT_BLOCK_RFC_BB,
  4462. BT_8822B_1ANT_GNT_CTRL_BY_SW,
  4463. BT_8822B_1ANT_SIG_STA_SET_TO_HIGH);
  4464. /* Set GNT_WL to low */
  4465. halbtc8822b1ant_ltecoex_set_gnt_wl(btcoexist,
  4466. BT_8822B_1ANT_GNT_BLOCK_RFC_BB,
  4467. BT_8822B_1ANT_GNT_CTRL_BY_SW,
  4468. BT_8822B_1ANT_SIG_STA_SET_TO_LOW);
  4469. /* set WLAN_ACT = 0 */
  4470. /* btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4); */
  4471. /* SD1 Chunchu red x issue */
  4472. btcoexist->btc_write_1byte(btcoexist, 0xff1a, 0x0);
  4473. halbtc8822b1ant_enable_gnt_to_gpio(btcoexist, true);
  4474. /* */
  4475. /* S0 or S1 setting and Local register setting(By the setting fw can get ant number, S0/S1, ... info) */
  4476. /* Local setting bit define */
  4477. /* BIT0: "0" for no antenna inverse; "1" for antenna inverse */
  4478. /* BIT1: "0" for internal switch; "1" for external switch */
  4479. /* BIT2: "0" for one antenna; "1" for two antenna */
  4480. /* NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and BIT2=0 */
  4481. u8tmp = 0;
  4482. board_info->btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
  4483. if (btcoexist->chip_interface == BTC_INTF_USB)
  4484. btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp);
  4485. else if (btcoexist->chip_interface == BTC_INTF_SDIO)
  4486. btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60, u8tmp);
  4487. BTC_TRACE(trace_buf);
  4488. }
  4489. void ex_halbtc8822b1ant_power_on_setting_without_bt(IN struct btc_coexist
  4490. *btcoexist)
  4491. {
  4492. struct btc_board_info *board_info = &btcoexist->board_info;
  4493. u8 u8tmp = 0x0;
  4494. u16 u16tmp = 0x0;
  4495. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4496. " 8822b 1-Ant PowerOn Setting without bt\n");
  4497. BTC_TRACE(trace_buf);
  4498. btcoexist->stop_coex_dm = true;
  4499. /* enable BB, REG_SYS_FUNC_EN such that we can write 0x948 correctly. */
  4500. u16tmp = btcoexist->btc_read_2byte(btcoexist, 0x2);
  4501. btcoexist->btc_write_2byte(btcoexist, 0x2, u16tmp | BIT(0) | BIT(1));
  4502. /* SD1 Chunchu red x issue */
  4503. btcoexist->btc_write_1byte(btcoexist, 0xff1a, 0x0);
  4504. u8tmp = 0;
  4505. board_info->btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
  4506. if (btcoexist->chip_interface == BTC_INTF_USB)
  4507. btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp);
  4508. else if (btcoexist->chip_interface == BTC_INTF_SDIO)
  4509. btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60, u8tmp);
  4510. }
  4511. void ex_halbtc8822b1ant_pre_load_firmware(IN struct btc_coexist *btcoexist)
  4512. {
  4513. }
  4514. void ex_halbtc8822b1ant_init_hw_config(IN struct btc_coexist *btcoexist,
  4515. IN boolean wifi_only)
  4516. {
  4517. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4518. "[BTCoex], ********** (ini hw config) **********\n");
  4519. halbtc8822b1ant_init_hw_config(btcoexist, true, wifi_only);
  4520. btcoexist->stop_coex_dm = false;
  4521. }
  4522. void ex_halbtc8822b1ant_init_hw_config_without_bt(IN struct btc_coexist
  4523. *btcoexist,
  4524. IN boolean wifi_only)
  4525. {
  4526. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4527. "[BTCoex], ********** (ini hw config) **********\n");
  4528. halbtc8822b1ant_init_hw_config_without_bt(btcoexist, true, wifi_only);
  4529. btcoexist->stop_coex_dm = true;
  4530. }
  4531. void ex_halbtc8822b1ant_antenna_switch_without_bt(IN struct btc_coexist
  4532. *btcoexist)
  4533. {
  4534. boolean wifi_under_5g = false;
  4535. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  4536. if (wifi_under_5g)
  4537. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd,
  4538. 0x3, 1);
  4539. else
  4540. btcoexist->btc_write_1byte_bitmask(btcoexist,
  4541. 0xcbd, 0x3, 2);
  4542. }
  4543. void ex_halbtc8822b1ant_init_coex_dm(IN struct btc_coexist *btcoexist)
  4544. {
  4545. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4546. "[BTCoex], Coex Mechanism Init!!\n");
  4547. BTC_TRACE(trace_buf);
  4548. btcoexist->stop_coex_dm = false;
  4549. halbtc8822b1ant_init_coex_dm(btcoexist);
  4550. halbtc8822b1ant_query_bt_info(btcoexist);
  4551. }
  4552. void ex_halbtc8822b1ant_display_coex_info(IN struct btc_coexist *btcoexist)
  4553. {
  4554. struct btc_board_info *board_info = &btcoexist->board_info;
  4555. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  4556. u8 *cli_buf = btcoexist->cli_buf;
  4557. u8 u8tmp[4], i, bt_info_ext, ps_tdma_case = 0;
  4558. u16 u16tmp[4];
  4559. u32 fa_ofdm, fa_cck, cca_ofdm, cca_cck;
  4560. u32 u32tmp[4];
  4561. u32 fa_of_dm;
  4562. u32 fw_ver = 0, bt_patch_ver = 0;
  4563. static u8 pop_report_in_10s = 0;
  4564. u32 phyver = 0;
  4565. /*u32 pnp_wake_cnt=0;*/
  4566. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4567. "[BTCoex], ********** (display coexinfo) **********\n");
  4568. BTC_TRACE(trace_buf);
  4569. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4570. "[BTCoex], ********** displaycoexinfostart, 0xcb4/0xcbd = 0x%x/0x%x\n",
  4571. btcoexist->btc_read_1byte(btcoexist, 0xcb4),
  4572. btcoexist->btc_read_1byte(btcoexist, 0xcbd));
  4573. BTC_TRACE(trace_buf);
  4574. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4575. "\r\n ============[BT Coexist info]============");
  4576. CL_PRINTF(cli_buf);
  4577. if (btcoexist->manual_control) {
  4578. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4579. "\r\n ============[Under Manual Control]============");
  4580. CL_PRINTF(cli_buf);
  4581. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4582. "\r\n ==========================================");
  4583. CL_PRINTF(cli_buf);
  4584. }
  4585. if (btcoexist->stop_coex_dm) {
  4586. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4587. "\r\n ============[Coex is STOPPED]============");
  4588. CL_PRINTF(cli_buf);
  4589. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4590. "\r\n ==========================================");
  4591. CL_PRINTF(cli_buf);
  4592. }
  4593. if (psd_scan->ant_det_try_count == 0) {
  4594. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4595. "\r\n %-35s = %d/ %d/ %d/ %d",
  4596. "Ant PG Num/ Mech/ Pos/ RFE",
  4597. board_info->pg_ant_num, board_info->btdm_ant_num,
  4598. board_info->btdm_ant_pos,
  4599. rfe_type->rfe_module_type);
  4600. CL_PRINTF(cli_buf);
  4601. } else {
  4602. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4603. "\r\n %-35s = %d/ %d/ %d/ %d (%d/%d/%d)",
  4604. "Ant PG Num/ Mech(Ant_Det)/ Pos/ RFE",
  4605. board_info->pg_ant_num,
  4606. board_info->btdm_ant_num_by_ant_det,
  4607. board_info->btdm_ant_pos,
  4608. rfe_type->rfe_module_type,
  4609. psd_scan->ant_det_try_count,
  4610. psd_scan->ant_det_fail_count,
  4611. psd_scan->ant_det_result);
  4612. CL_PRINTF(cli_buf);
  4613. if (board_info->btdm_ant_det_finish) {
  4614. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s",
  4615. "Ant Det PSD Value",
  4616. psd_scan->ant_det_peak_val);
  4617. CL_PRINTF(cli_buf);
  4618. }
  4619. }
  4620. /*btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);*/
  4621. bt_patch_ver = btcoexist->bt_info.bt_get_fw_ver;
  4622. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
  4623. phyver = btcoexist->btc_get_bt_phydm_version(btcoexist);
  4624. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4625. "\r\n %-35s = %d_%02x/ 0x%02x/ 0x%02x (%s)",
  4626. "CoexVer WL/ BT_Desired/ BT_Report",
  4627. glcoex_ver_date_8822b_1ant, glcoex_ver_8822b_1ant,
  4628. glcoex_ver_btdesired_8822b_1ant,
  4629. ((coex_sta->bt_coex_supported_version & 0xff00) >>
  4630. 8),
  4631. (((coex_sta->bt_coex_supported_version & 0xff00) >>
  4632. 8) >=
  4633. glcoex_ver_btdesired_8822b_1ant ? "Match" :
  4634. "Mis-Match"));
  4635. CL_PRINTF(cli_buf);
  4636. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4637. "\r\n %-35s = 0x%x/ 0x%x/ v%d/ %c",
  4638. "W_FW/ B_FW/ Phy/ Kt",
  4639. fw_ver, bt_patch_ver, phyver,
  4640. coex_sta->cut_version + 65);
  4641. CL_PRINTF(cli_buf);
  4642. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ",
  4643. "Wifi channel informed to BT",
  4644. coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1],
  4645. coex_dm->wifi_chnl_info[2]);
  4646. CL_PRINTF(cli_buf);
  4647. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s",
  4648. "WifibHiPri/ Ccklock/ CckEverLock",
  4649. (coex_sta->wifi_is_high_pri_task ? "Yes" : "No"),
  4650. (coex_sta->cck_lock ? "Yes" : "No"),
  4651. (coex_sta->cck_ever_lock ? "Yes" : "No"));
  4652. CL_PRINTF(cli_buf);
  4653. /* wifi status */
  4654. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  4655. "============[Wifi Status]============");
  4656. CL_PRINTF(cli_buf);
  4657. btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS);
  4658. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  4659. "============[BT Status]============");
  4660. CL_PRINTF(cli_buf);
  4661. pop_report_in_10s++;
  4662. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d/ %d] ",
  4663. "BT [status/ rssi/ retryCnt/ popCnt]",
  4664. ((coex_sta->bt_disabled) ? ("disabled") : ((
  4665. coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan")
  4666. : ((BT_8822B_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
  4667. coex_dm->bt_status) ? "non-connected idle" :
  4668. ((BT_8822B_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)
  4669. ? "connected-idle" : "busy")))),
  4670. coex_sta->bt_rssi - 100, coex_sta->bt_retry_cnt,
  4671. coex_sta->pop_event_cnt);
  4672. CL_PRINTF(cli_buf);
  4673. /*bt rssi */
  4674. /*bt pop_even_cnt : bt retry*/
  4675. if (pop_report_in_10s >= 5) {
  4676. coex_sta->pop_event_cnt = 0;
  4677. pop_report_in_10s = 0;
  4678. }
  4679. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4680. "\r\n %-35s = %d / %d / %d / %d / %d",
  4681. "SCO/HID/PAN/A2DP/Hi-Pri",
  4682. bt_link_info->sco_exist, bt_link_info->hid_exist,
  4683. bt_link_info->pan_exist, bt_link_info->a2dp_exist,
  4684. bt_link_info->bt_hi_pri_link_exist);
  4685. CL_PRINTF(cli_buf);
  4686. {
  4687. bt_info_ext = coex_sta->bt_info_ext;
  4688. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4689. "\r\n %-35s = %s / %s / %d/ %x/ %02x",
  4690. "Role/A2DP Rate/Bitpool/Feature/Ver",
  4691. ((bt_link_info->slave_role) ? "Slave" : "Master"),
  4692. (bt_info_ext & BIT(0)) ? "BR" : "EDR",
  4693. coex_sta->a2dp_bit_pool,
  4694. coex_sta->bt_coex_supported_feature,
  4695. ((coex_sta->bt_coex_supported_version & 0xff00) >> 8));
  4696. CL_PRINTF(cli_buf);
  4697. }
  4698. /*bt info*/
  4699. for (i = 0; i < BT_INFO_SRC_8822B_1ANT_MAX; i++) {
  4700. if (coex_sta->bt_info_c2h_cnt[i]) {
  4701. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4702. "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)",
  4703. glbt_info_src_8822b_1ant[i],
  4704. coex_sta->bt_info_c2h[i][0],
  4705. coex_sta->bt_info_c2h[i][1],
  4706. coex_sta->bt_info_c2h[i][2],
  4707. coex_sta->bt_info_c2h[i][3],
  4708. coex_sta->bt_info_c2h[i][4],
  4709. coex_sta->bt_info_c2h[i][5],
  4710. coex_sta->bt_info_c2h[i][6],
  4711. coex_sta->bt_info_c2h_cnt[i]);
  4712. CL_PRINTF(cli_buf);
  4713. }
  4714. }
  4715. if (btcoexist->manual_control)
  4716. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  4717. "============[mechanisms] (before Manual)============");
  4718. else
  4719. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  4720. "============[mechanisms]============");
  4721. CL_PRINTF(cli_buf);
  4722. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d",
  4723. "SM[LowPenaltyRA]",
  4724. coex_dm->cur_low_penalty_ra);
  4725. CL_PRINTF(cli_buf);
  4726. /*(ps)tdma*/
  4727. ps_tdma_case = coex_dm->cur_ps_tdma;
  4728. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4729. "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (%s,%s)",
  4730. "PS TDMA",
  4731. coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1],
  4732. coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3],
  4733. coex_dm->ps_tdma_para[4], ps_tdma_case,
  4734. (coex_dm->cur_ps_tdma_on ? "On" : "Off"),
  4735. (coex_dm->auto_tdma_adjust ? "Adj" : "Fix"));
  4736. CL_PRINTF(cli_buf);
  4737. /*coex table type*/
  4738. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d",
  4739. "WL/BT Coex Table Type",
  4740. coex_sta->coex_table_type);
  4741. CL_PRINTF(cli_buf);
  4742. /*coex table :0x6c0 0x6c4 , break table: 0x6c8*/
  4743. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
  4744. u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
  4745. u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
  4746. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4747. "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
  4748. "0x6c0/0x6c4/0x6c8(coexTable)",
  4749. u32tmp[0], u32tmp[1], u32tmp[2]);
  4750. CL_PRINTF(cli_buf);
  4751. /*PTA : 0x778=1/3/d , WL BA,RTS,CTS :0x6cc H/L pri */
  4752. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
  4753. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6cc);
  4754. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4755. "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
  4756. "0x778/0x6cc/IgnWlanAct",
  4757. u8tmp[0], u32tmp[0], coex_dm->cur_ignore_wlan_act);
  4758. CL_PRINTF(cli_buf);
  4759. /*LTE : WL/LTE coex table : 0xa0 */
  4760. u32tmp[0] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
  4761. 0xa0);
  4762. /*LTE : BT/LTE coex table : 0xa4 */
  4763. u32tmp[1] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
  4764. 0xa4);
  4765. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
  4766. "LTE Coex Table W_L/B_L",
  4767. u32tmp[0] & 0xffff, u32tmp[1] & 0xffff);
  4768. CL_PRINTF(cli_buf);
  4769. /*LTE : WL/LTE break table : 0xa8 */
  4770. u32tmp[0] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
  4771. 0xa8);
  4772. /*LTE : WL/LTE break table : 0xac */
  4773. u32tmp[1] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
  4774. 0xac);
  4775. /*LTE : LTE/WL break table : 0xb0 */
  4776. u32tmp[2] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
  4777. 0xb0);
  4778. /*LTE : LTE/BT break table : 0xb4 */
  4779. u32tmp[3] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist,
  4780. 0xb4);
  4781. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4782. "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
  4783. "LTE Break Table W_L/B_L/L_W/L_B",
  4784. u32tmp[0] & 0xffff, u32tmp[1] & 0xffff,
  4785. u32tmp[2] & 0xffff, u32tmp[3] & 0xffff);
  4786. CL_PRINTF(cli_buf);
  4787. /* Hw setting */
  4788. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  4789. "============[Hw setting]============");
  4790. CL_PRINTF(cli_buf);
  4791. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x430);
  4792. u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x434);
  4793. u16tmp[0] = btcoexist->btc_read_2byte(btcoexist, 0x42a);
  4794. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x456);
  4795. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
  4796. "0x430/0x434/0x42a/0x456",
  4797. u32tmp[0], u32tmp[1], u16tmp[0], u8tmp[0]);
  4798. CL_PRINTF(cli_buf);
  4799. /*ANT setting*/
  4800. u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xcb4);
  4801. u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0xcbd);
  4802. u8tmp[3] = btcoexist->btc_read_1byte(btcoexist, 0x1991);
  4803. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
  4804. "0xcb4/0xcbd/0x1991",
  4805. u8tmp[1], u8tmp[2], u8tmp[3]);
  4806. CL_PRINTF(cli_buf);
  4807. /*LTE on/off , Path ctrl owner*/
  4808. /*sy add*/
  4809. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c);
  4810. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x73);
  4811. u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x64);
  4812. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
  4813. "0x73/ 0x4c/ 0x64[0]", u8tmp[0],
  4814. (u32tmp[0] & (BIT(24) | BIT(23))) >> 23,
  4815. u8tmp[1] & 0x1);
  4816. CL_PRINTF(cli_buf);
  4817. u32tmp[0] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, 0x38);
  4818. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %s",
  4819. "LTE CoexOn/Path Ctrl Owner",
  4820. (int)((u32tmp[0]&BIT(7)) >> 7),
  4821. ((u8tmp[0]&BIT(2)) ? "WL" : "BT"));
  4822. CL_PRINTF(cli_buf);
  4823. /*LTE mode*/
  4824. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
  4825. "LTE 3Wire/OPMode/UART/UARTMode",
  4826. (int)((u32tmp[0]&BIT(6)) >> 6),
  4827. (int)((u32tmp[0] & (BIT(5) | BIT(4))) >> 4),
  4828. (int)((u32tmp[0]&BIT(3)) >> 3),
  4829. (int)(u32tmp[0] & (BIT(2) | BIT(1) | BIT(0))));
  4830. CL_PRINTF(cli_buf);
  4831. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %s",
  4832. "GNT_WL_SWCtrl/GNT_BT_SWCtrl/Dbg",
  4833. (int)((u32tmp[0]&BIT(12)) >> 12),
  4834. (int)((u32tmp[0]&BIT(14)) >> 14),
  4835. ((u8tmp[0]&BIT(3)) ? "On" : "Off"));
  4836. CL_PRINTF(cli_buf);
  4837. u32tmp[0] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, 0x54);
  4838. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
  4839. "GNT_WL/GNT_BT/LTE_Busy/UART_Busy",
  4840. (int)((u32tmp[0]&BIT(2)) >> 2),
  4841. (int)((u32tmp[0]&BIT(3)) >> 3),
  4842. (int)((u32tmp[0]&BIT(1)) >> 1), (int)(u32tmp[0]&BIT(0)));
  4843. CL_PRINTF(cli_buf);
  4844. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x4c6);
  4845. u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x40);
  4846. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
  4847. "0x4c6[4]/0x40[5] (WL/BT PTA)",
  4848. (int)((u8tmp[0] & BIT(4)) >> 4),
  4849. (int)((u8tmp[1] & BIT(5)) >> 5));
  4850. CL_PRINTF(cli_buf);
  4851. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
  4852. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
  4853. u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x953);
  4854. u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0xc50);
  4855. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4856. "\r\n %-35s = 0x%x/ 0x%x/ %s/ 0x%x",
  4857. "0x550/0x522/4-RxAGC/0xc50",
  4858. u32tmp[0], u8tmp[0], (u8tmp[1] & 0x2) ? "On" : "Off", u8tmp[2]);
  4859. CL_PRINTF(cli_buf);
  4860. #if 0 /* phydm v008 doesn't support this feature */
  4861. fa_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
  4862. PHYDM_INFO_FA_OFDM);
  4863. fa_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
  4864. PHYDM_INFO_FA_CCK);
  4865. cca_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
  4866. PHYDM_INFO_CCA_OFDM);
  4867. cca_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
  4868. PHYDM_INFO_CCA_CCK);
  4869. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4870. "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
  4871. "CCK-CCA/CCK-FA/OFDM-CCA/OFDM-FA",
  4872. cca_cck, fa_cck, cca_ofdm, fa_ofdm);
  4873. CL_PRINTF(cli_buf);
  4874. #endif
  4875. #if 1
  4876. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
  4877. "CRC_OK CCK/11g/11n/11ac",
  4878. coex_sta->crc_ok_cck, coex_sta->crc_ok_11g,
  4879. coex_sta->crc_ok_11n, coex_sta->crc_ok_11n_vht);
  4880. CL_PRINTF(cli_buf);
  4881. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
  4882. "CRC_Err CCK/11g/11n/11ac",
  4883. coex_sta->crc_err_cck, coex_sta->crc_err_11g,
  4884. coex_sta->crc_err_11n, coex_sta->crc_err_11n_vht);
  4885. CL_PRINTF(cli_buf);
  4886. #endif
  4887. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s",
  4888. "Wifi-HiPri/ Ccklock/ CckEverLock",
  4889. (coex_sta->wifi_is_high_pri_task ? "Yes" : "No"),
  4890. (coex_sta->cck_lock ? "Yes" : "No"),
  4891. (coex_sta->cck_ever_lock ? "Yes" : "No"));
  4892. CL_PRINTF(cli_buf);
  4893. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
  4894. "0x770(high-pri rx/tx)",
  4895. coex_sta->high_priority_rx, coex_sta->high_priority_tx);
  4896. CL_PRINTF(cli_buf);
  4897. /*0x774:bt low pri trx*/
  4898. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
  4899. "0x774(low-pri rx/tx)",
  4900. coex_sta->low_priority_rx, coex_sta->low_priority_tx);
  4901. CL_PRINTF(cli_buf);
  4902. halbtc8822b1ant_read_score_board(btcoexist, &u16tmp[0]);
  4903. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %04x",
  4904. "ScoreBoard[14:0] (from BT)", u16tmp[0]);
  4905. btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS);
  4906. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4907. "[BTCoex], ********** displaycoexinfo end, 0xcb4/0xcbd = 0x%x/0x%x\n",
  4908. btcoexist->btc_read_1byte(btcoexist, 0xcb4),
  4909. btcoexist->btc_read_1byte(btcoexist, 0xcbd));
  4910. BTC_TRACE(trace_buf);
  4911. /*
  4912. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4913. "[BTCoex], ********** pnp_wake_cnt = %d\n", pnp_wake_cnt);
  4914. BTC_TRACE(trace_buf);
  4915. */
  4916. }
  4917. void ex_halbtc8822b1ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type)
  4918. {
  4919. if (btcoexist->manual_control || btcoexist->stop_coex_dm)
  4920. return;
  4921. if (BTC_IPS_ENTER == type) {
  4922. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4923. "[BTCoex], IPS ENTER notify\n");
  4924. BTC_TRACE(trace_buf);
  4925. coex_sta->under_ips = true;
  4926. /* Write WL "Active" in Score-board for LPS off */
  4927. halbtc8822b1ant_post_state_to_bt(btcoexist,
  4928. BT_8822B_1ANT_SCOREBOARD_ACTIVE, false);
  4929. halbtc8822b1ant_post_state_to_bt(btcoexist,
  4930. BT_8822B_1ANT_SCOREBOARD_ONOFF, false);
  4931. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  4932. halbtc8822b1ant_set_ant_path(btcoexist,
  4933. BTC_ANT_PATH_AUTO,
  4934. FORCE_EXEC,
  4935. BT_8822B_1ANT_PHASE_WLAN_OFF);
  4936. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  4937. } else if (BTC_IPS_LEAVE == type) {
  4938. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4939. "[BTCoex], IPS LEAVE notify\n");
  4940. BTC_TRACE(trace_buf);
  4941. halbtc8822b1ant_post_state_to_bt(btcoexist,
  4942. BT_8822B_1ANT_SCOREBOARD_ACTIVE, true);
  4943. halbtc8822b1ant_post_state_to_bt(btcoexist,
  4944. BT_8822B_1ANT_SCOREBOARD_ONOFF, true);
  4945. /*leave IPS : run ini hw config (exclude wifi only)*/
  4946. halbtc8822b1ant_init_hw_config(btcoexist, false, false);
  4947. /*sw all off*/
  4948. halbtc8822b1ant_init_coex_dm(btcoexist);
  4949. /*leave IPS : Query bt info*/
  4950. halbtc8822b1ant_query_bt_info(btcoexist);
  4951. coex_sta->under_ips = false;
  4952. }
  4953. }
  4954. void ex_halbtc8822b1ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type)
  4955. {
  4956. if (btcoexist->manual_control || btcoexist->stop_coex_dm)
  4957. return;
  4958. if (BTC_LPS_ENABLE == type) {
  4959. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4960. "[BTCoex], LPS ENABLE notify\n");
  4961. BTC_TRACE(trace_buf);
  4962. coex_sta->under_lps = true;
  4963. if (coex_sta->force_lps_on == true) { /* LPS No-32K */
  4964. /* Write WL "Active" in Score-board for PS-TDMA */
  4965. halbtc8822b1ant_post_state_to_bt(btcoexist,
  4966. BT_8822B_1ANT_SCOREBOARD_ACTIVE, true);
  4967. } else { /* LPS-32K, need check if this h2c 0x71 can work?? (2015/08/28) */
  4968. /* Write WL "Non-Active" in Score-board for Native-PS */
  4969. halbtc8822b1ant_post_state_to_bt(btcoexist,
  4970. BT_8822B_1ANT_SCOREBOARD_ACTIVE, false);
  4971. }
  4972. } else if (BTC_LPS_DISABLE == type) {
  4973. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4974. "[BTCoex], LPS DISABLE notify\n");
  4975. BTC_TRACE(trace_buf);
  4976. coex_sta->under_lps = false;
  4977. /* Write WL "Active" in Score-board for LPS off */
  4978. halbtc8822b1ant_post_state_to_bt(btcoexist,
  4979. BT_8822B_1ANT_SCOREBOARD_ACTIVE, true);
  4980. }
  4981. }
  4982. void ex_halbtc8822b1ant_scan_notify(IN struct btc_coexist *btcoexist,
  4983. IN u8 type)
  4984. {
  4985. boolean wifi_connected = false;
  4986. boolean wifi_under_5g = false;
  4987. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4988. "[BTCoex], SCAN notify()\n");
  4989. BTC_TRACE(trace_buf);
  4990. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  4991. &wifi_connected);
  4992. if (btcoexist->manual_control ||
  4993. btcoexist->stop_coex_dm)
  4994. return;
  4995. if (BTC_SCAN_START == type) {
  4996. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  4997. if (wifi_under_5g) {
  4998. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4999. "[BTCoex], ********** (scan_notify_5g_scan_start) **********\n");
  5000. BTC_TRACE(trace_buf);
  5001. halbtc8822b1ant_action_wifi_under5g(btcoexist);
  5002. return;
  5003. }
  5004. /* under 2.4G */
  5005. coex_sta->wifi_is_high_pri_task = true;
  5006. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5007. "[BTCoex], ********** (scan_notify_2g_scan_start) **********\n");
  5008. BTC_TRACE(trace_buf);
  5009. if (!wifi_connected) { /* non-connected scan */
  5010. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5011. "[BTCoex], ********** wifi is not connected scan **********\n");
  5012. BTC_TRACE(trace_buf);
  5013. halbtc8822b1ant_action_wifi_not_connected_scan(
  5014. btcoexist);
  5015. } else { /* wifi is connected */
  5016. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5017. "[BTCoex], ********** wifi is connected scan **********\n");
  5018. BTC_TRACE(trace_buf);
  5019. halbtc8822b1ant_action_wifi_connected_scan(
  5020. btcoexist);
  5021. }
  5022. return;
  5023. }
  5024. if (BTC_SCAN_START_2G == type) {
  5025. coex_sta->wifi_is_high_pri_task = true;
  5026. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5027. "[BTCoex], ********** (scan_notify_2g_sacn_start_for_switch_band_used) **********\n");
  5028. BTC_TRACE(trace_buf);
  5029. if (!wifi_connected) { /* non-connected scan */
  5030. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5031. "[BTCoex], ********** wifi is not connected **********\n");
  5032. BTC_TRACE(trace_buf);
  5033. halbtc8822b1ant_action_wifi_not_connected_scan(
  5034. btcoexist);
  5035. } else { /* wifi is connected */
  5036. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5037. "[BTCoex], ********** wifi is connected **********\n");
  5038. BTC_TRACE(trace_buf);
  5039. halbtc8822b1ant_action_wifi_connected_scan(btcoexist);
  5040. }
  5041. } else {
  5042. coex_sta->wifi_is_high_pri_task = false;
  5043. /*WL scan finish , then get and update sacn ap numbers */
  5044. btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
  5045. &coex_sta->scan_ap_num);
  5046. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5047. "[BTCoex], ********** (scan_finish_notify) **********\n");
  5048. BTC_TRACE(trace_buf);
  5049. if (!wifi_connected) /* non-connected scan */
  5050. halbtc8822b1ant_action_wifi_not_connected(btcoexist);
  5051. else {
  5052. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5053. "[BTCoex], ********** scan_finish_notify wifi is connected **********\n");
  5054. BTC_TRACE(trace_buf);
  5055. halbtc8822b1ant_action_wifi_connected(btcoexist);
  5056. }
  5057. }
  5058. }
  5059. void ex_halbtc8822b1ant_scan_notify_without_bt(IN struct btc_coexist *btcoexist,
  5060. IN u8 type)
  5061. {
  5062. boolean wifi_under_5g = false;
  5063. if (BTC_SCAN_START == type) {
  5064. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  5065. if (wifi_under_5g) {
  5066. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd,
  5067. 0x3, 1);
  5068. return;
  5069. }
  5070. /* under 2.4G */
  5071. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd,
  5072. 0x3, 2);
  5073. return;
  5074. }
  5075. if (BTC_SCAN_START_2G == type)
  5076. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd, 0x3, 2);
  5077. }
  5078. void ex_halbtc8822b1ant_switchband_notify(IN struct btc_coexist *btcoexist,
  5079. IN u8 type)
  5080. {
  5081. boolean wifi_connected = false;
  5082. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5083. "[BTCoex], ********** (switchband_notify) **********\n");
  5084. BTC_TRACE(trace_buf);
  5085. if (btcoexist->manual_control ||
  5086. btcoexist->stop_coex_dm)
  5087. return;
  5088. if (type == BTC_SWITCH_TO_5G) {
  5089. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5090. "[BTCoex], ********** (switchband_notify BTC_SWITCH_TO_5G) **********\n");
  5091. BTC_TRACE(trace_buf);
  5092. halbtc8822b1ant_action_wifi_under5g(btcoexist);
  5093. return;
  5094. } else if (type == BTC_SWITCH_TO_24G_NOFORSCAN) {
  5095. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5096. "[BTCoex], ********** (switchband_notify BTC_SWITCH_TO_2G (no for scan)) **********\n");
  5097. BTC_TRACE(trace_buf);
  5098. halbtc8822b1ant_run_coexist_mechanism(btcoexist);
  5099. } else {
  5100. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5101. "[BTCoex], ********** (switchband_notify BTC_SWITCH_TO_2G) **********\n");
  5102. BTC_TRACE(trace_buf);
  5103. ex_halbtc8822b1ant_scan_notify(btcoexist,
  5104. BTC_SCAN_START_2G);
  5105. }
  5106. }
  5107. void ex_halbtc8822b1ant_switchband_notify_without_bt(IN struct btc_coexist
  5108. *btcoexist,
  5109. IN u8 type)
  5110. {
  5111. boolean wifi_under_5g = false;
  5112. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  5113. if (type == BTC_SWITCH_TO_5G) {
  5114. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd,
  5115. 0x3, 1);
  5116. return;
  5117. } else if (type == BTC_SWITCH_TO_24G_NOFORSCAN) {
  5118. if (wifi_under_5g)
  5119. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd,
  5120. 0x3, 1);
  5121. else
  5122. btcoexist->btc_write_1byte_bitmask(btcoexist,
  5123. 0xcbd, 0x3, 2);
  5124. } else {
  5125. ex_halbtc8822b1ant_scan_notify_without_bt(btcoexist,
  5126. BTC_SCAN_START_2G);
  5127. }
  5128. }
  5129. void ex_halbtc8822b1ant_connect_notify(IN struct btc_coexist *btcoexist,
  5130. IN u8 type)
  5131. {
  5132. boolean wifi_connected = false;
  5133. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5134. "[BTCoex], ********** (connect notify) **********\n");
  5135. BTC_TRACE(trace_buf);
  5136. halbtc8822b1ant_post_state_to_bt(btcoexist,
  5137. BT_8822B_1ANT_SCOREBOARD_SCAN, true);
  5138. if (btcoexist->manual_control ||
  5139. btcoexist->stop_coex_dm)
  5140. return;
  5141. if ((BTC_ASSOCIATE_5G_START == type) ||
  5142. (BTC_ASSOCIATE_5G_FINISH == type)) {
  5143. if (BTC_ASSOCIATE_5G_START == type) {
  5144. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5145. "[BTCoex], ********** (5G associate start notify) **********\n");
  5146. BTC_TRACE(trace_buf);
  5147. halbtc8822b1ant_action_wifi_under5g(btcoexist);
  5148. } else if (BTC_ASSOCIATE_5G_FINISH == type) {
  5149. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5150. "[BTCoex], ********** (5G associate finish notify) **********\n");
  5151. BTC_TRACE(trace_buf);
  5152. }
  5153. return;
  5154. }
  5155. if (BTC_ASSOCIATE_START == type) {
  5156. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5157. "[BTCoex], 2G CONNECT START notify\n");
  5158. BTC_TRACE(trace_buf);
  5159. coex_sta->wifi_is_high_pri_task = true;
  5160. halbtc8822b1ant_set_ant_path(btcoexist,
  5161. BTC_ANT_PATH_AUTO,
  5162. FORCE_EXEC,
  5163. BT_8822B_1ANT_PHASE_2G_RUNTIME);
  5164. coex_dm->arp_cnt = 0;
  5165. halbtc8822b1ant_action_wifi_not_connected_asso_auth(btcoexist);
  5166. } else {
  5167. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5168. "[BTCoex], 2G CONNECT Finish notify\n");
  5169. BTC_TRACE(trace_buf);
  5170. coex_sta->wifi_is_high_pri_task = false;
  5171. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  5172. &wifi_connected);
  5173. if (!wifi_connected) /* non-connected scan */
  5174. halbtc8822b1ant_action_wifi_not_connected(btcoexist);
  5175. else
  5176. halbtc8822b1ant_action_wifi_connected(btcoexist);
  5177. }
  5178. }
  5179. void ex_halbtc8822b1ant_media_status_notify(IN struct btc_coexist *btcoexist,
  5180. IN u8 type)
  5181. {
  5182. boolean wifi_under_b_mode = false;
  5183. boolean wifi_under_5g = false;
  5184. u32 cnt_bt_cal_chk = 0;
  5185. boolean is_in_mp_mode = false;
  5186. u8 u8tmp = 0;
  5187. u32 u32tmp1 = 0, u32tmp2 = 0;
  5188. if (btcoexist->manual_control ||
  5189. btcoexist->stop_coex_dm)
  5190. return;
  5191. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  5192. if (BTC_MEDIA_CONNECT == type) {
  5193. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5194. "[BTCoex], 2g media connect notify");
  5195. BTC_TRACE(trace_buf);
  5196. halbtc8822b1ant_post_state_to_bt(btcoexist,
  5197. BT_8822B_1ANT_SCOREBOARD_ACTIVE, true);
  5198. if (wifi_under_5g) {
  5199. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5200. "[BTCoex], 5g media notify\n");
  5201. BTC_TRACE(trace_buf);
  5202. halbtc8822b1ant_action_wifi_under5g(btcoexist);
  5203. return;
  5204. }
  5205. /* Force antenna setup for no scan result issue */
  5206. halbtc8822b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
  5207. FORCE_EXEC,
  5208. BT_8822B_1ANT_PHASE_2G_RUNTIME);
  5209. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
  5210. &wifi_under_b_mode);
  5211. /* Set CCK Tx/Rx high Pri except 11b mode */
  5212. if (wifi_under_b_mode) {
  5213. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5214. "[BTCoex], ********** (media status notity under b mode) **********\n");
  5215. BTC_TRACE(trace_buf);
  5216. btcoexist->btc_write_1byte(btcoexist, 0x6cd,
  5217. 0x00); /* CCK Tx */
  5218. btcoexist->btc_write_1byte(btcoexist, 0x6cf,
  5219. 0x00); /* CCK Rx */
  5220. } else {
  5221. /* btcoexist->btc_write_1byte(btcoexist, 0x6cd, 0x10); */ /*CCK Tx */
  5222. /* btcoexist->btc_write_1byte(btcoexist, 0x6cf, 0x10); */ /*CCK Rx */
  5223. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5224. "[BTCoex], ********** (media status notity not under b mode) **********\n");
  5225. BTC_TRACE(trace_buf);
  5226. btcoexist->btc_write_1byte(btcoexist, 0x6cd,
  5227. 0x00); /* CCK Tx */
  5228. btcoexist->btc_write_1byte(btcoexist, 0x6cf,
  5229. 0x10); /* CCK Rx */
  5230. }
  5231. coex_dm->backup_arfr_cnt1 = btcoexist->btc_read_4byte(btcoexist,
  5232. 0x430);
  5233. coex_dm->backup_arfr_cnt2 = btcoexist->btc_read_4byte(btcoexist,
  5234. 0x434);
  5235. coex_dm->backup_retry_limit = btcoexist->btc_read_2byte(
  5236. btcoexist, 0x42a);
  5237. coex_dm->backup_ampdu_max_time = btcoexist->btc_read_1byte(
  5238. btcoexist, 0x456);
  5239. } else {
  5240. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5241. "[BTCoex], 2g media disconnect notify\n");
  5242. BTC_TRACE(trace_buf);
  5243. coex_dm->arp_cnt = 0;
  5244. halbtc8822b1ant_post_state_to_bt(btcoexist,
  5245. BT_8822B_1ANT_SCOREBOARD_ACTIVE, false);
  5246. btcoexist->btc_write_1byte(btcoexist, 0x6cd, 0x0); /* CCK Tx */
  5247. btcoexist->btc_write_1byte(btcoexist, 0x6cf, 0x0); /* CCK Rx */
  5248. coex_sta->cck_ever_lock = false;
  5249. }
  5250. halbtc8822b1ant_update_wifi_channel_info(btcoexist, type);
  5251. }
  5252. void ex_halbtc8822b1ant_specific_packet_notify(IN struct btc_coexist *btcoexist,
  5253. IN u8 type)
  5254. {
  5255. boolean under_4way = false, wifi_under_5g = false;
  5256. if (btcoexist->manual_control ||
  5257. btcoexist->stop_coex_dm)
  5258. return;
  5259. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  5260. if (wifi_under_5g) {
  5261. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5262. "[BTCoex], 5g special packet notify\n");
  5263. BTC_TRACE(trace_buf);
  5264. halbtc8822b1ant_action_wifi_under5g(btcoexist);
  5265. return;
  5266. }
  5267. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
  5268. &under_4way);
  5269. if (under_4way) {
  5270. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5271. "[BTCoex], specific Packet ---- under_4way!!\n");
  5272. BTC_TRACE(trace_buf);
  5273. coex_sta->wifi_is_high_pri_task = true;
  5274. coex_sta->specific_pkt_period_cnt = 2;
  5275. } else if (BTC_PACKET_ARP == type) {
  5276. coex_dm->arp_cnt++;
  5277. if (coex_sta->wifi_is_high_pri_task) {
  5278. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5279. "[BTCoex], specific Packet ARP notify -cnt = %d\n",
  5280. coex_dm->arp_cnt);
  5281. BTC_TRACE(trace_buf);
  5282. }
  5283. } else {
  5284. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5285. "[BTCoex], specific Packet DHCP or EAPOL notify [Type = %d]\n",
  5286. type);
  5287. BTC_TRACE(trace_buf);
  5288. coex_sta->wifi_is_high_pri_task = true;
  5289. coex_sta->specific_pkt_period_cnt = 2;
  5290. }
  5291. if (coex_sta->wifi_is_high_pri_task)
  5292. halbtc8822b1ant_action_wifi_connected_specific_packet(
  5293. btcoexist);
  5294. }
  5295. void ex_halbtc8822b1ant_bt_info_notify(IN struct btc_coexist *btcoexist,
  5296. IN u8 *tmp_buf, IN u8 length)
  5297. {
  5298. u8 bt_info = 0;
  5299. u8 i, rsp_source = 0;
  5300. boolean bt_busy = false;
  5301. boolean wifi_connected = false;
  5302. boolean wifi_under_5g = false;
  5303. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  5304. coex_sta->c2h_bt_info_req_sent = false;
  5305. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5306. "[BTCoex], ********** (BtInfo Notify) **********\n");
  5307. BTC_TRACE(trace_buf);
  5308. rsp_source = tmp_buf[0] & 0xf;
  5309. if (rsp_source >= BT_INFO_SRC_8822B_1ANT_MAX)
  5310. rsp_source = BT_INFO_SRC_8822B_1ANT_WIFI_FW;
  5311. coex_sta->bt_info_c2h_cnt[rsp_source]++;
  5312. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5313. "[BTCoex], Bt info[%d], length=%d, hex data=[", rsp_source,
  5314. length);
  5315. BTC_TRACE(trace_buf);
  5316. for (i = 0; i < length; i++) {
  5317. coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i];
  5318. if (i == 1)
  5319. bt_info = tmp_buf[i];
  5320. if (i == length - 1) {
  5321. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n",
  5322. tmp_buf[i]);
  5323. BTC_TRACE(trace_buf);
  5324. } else {
  5325. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ",
  5326. tmp_buf[i]);
  5327. BTC_TRACE(trace_buf);
  5328. }
  5329. }
  5330. if (BT_INFO_SRC_8822B_1ANT_WIFI_FW != rsp_source) {
  5331. /* if 0xff, it means BT is under WHCK test */
  5332. if (bt_info == 0xff)
  5333. coex_sta->bt_whck_test = true;
  5334. else
  5335. coex_sta->bt_whck_test = false;
  5336. coex_sta->bt_retry_cnt = /* [3:0] */
  5337. coex_sta->bt_info_c2h[rsp_source][2] & 0xf;
  5338. if (coex_sta->bt_retry_cnt >= 1)
  5339. coex_sta->pop_event_cnt++;
  5340. if (coex_sta->bt_info_c2h[rsp_source][2] & 0x20)
  5341. coex_sta->c2h_bt_page = true;
  5342. else
  5343. coex_sta->c2h_bt_page = false;
  5344. if (coex_sta->bt_info_c2h[rsp_source][2] & 0x80)
  5345. coex_sta->bt_create_connection = true;
  5346. else
  5347. coex_sta->bt_create_connection = false;
  5348. /* unit: %, value-100 to translate to unit: dBm */
  5349. coex_sta->bt_rssi = coex_sta->bt_info_c2h[rsp_source][3] * 2 +
  5350. 10;
  5351. /* coex_sta->bt_info_c2h[rsp_source][3] * 2 - 90; */
  5352. if ((coex_sta->bt_info_c2h[rsp_source][1] & 0x49) == 0x49) {
  5353. coex_sta->a2dp_bit_pool =
  5354. coex_sta->bt_info_c2h[rsp_source][6];
  5355. } else
  5356. coex_sta->a2dp_bit_pool = 0;
  5357. if (coex_sta->bt_info_c2h[rsp_source][1] & 0x9)
  5358. coex_sta->acl_busy = true;
  5359. else
  5360. coex_sta->acl_busy = false;
  5361. coex_sta->bt_info_ext =
  5362. coex_sta->bt_info_c2h[rsp_source][4];
  5363. /* Here we need to resend some wifi info to BT */
  5364. /* because bt is reset and loss of the info. */
  5365. if ((!btcoexist->manual_control) &&
  5366. (!btcoexist->stop_coex_dm)) {
  5367. /* Re-Init */
  5368. if (coex_sta->bt_info_ext & BIT(1)) {
  5369. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5370. "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
  5371. BTC_TRACE(trace_buf);
  5372. btcoexist->btc_get(btcoexist,
  5373. BTC_GET_BL_WIFI_CONNECTED,
  5374. &wifi_connected);
  5375. if (wifi_connected)
  5376. halbtc8822b1ant_update_wifi_channel_info(
  5377. btcoexist,
  5378. BTC_MEDIA_CONNECT);
  5379. else
  5380. halbtc8822b1ant_update_wifi_channel_info(
  5381. btcoexist,
  5382. BTC_MEDIA_DISCONNECT);
  5383. }
  5384. /* If Ignore_WLanAct && not SetUp_Link */
  5385. if ((coex_sta->bt_info_ext & BIT(3)) &&
  5386. (!(coex_sta->bt_info_ext & BIT(2)))) {
  5387. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5388. "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n");
  5389. BTC_TRACE(trace_buf);
  5390. halbtc8822b1ant_ignore_wlan_act(btcoexist,
  5391. FORCE_EXEC,
  5392. false);
  5393. }
  5394. }
  5395. /* check BIT2 first ==> check if bt is under inquiry or page scan */
  5396. if (bt_info & BT_INFO_8822B_1ANT_B_INQ_PAGE)
  5397. coex_sta->c2h_bt_inquiry_page = true;
  5398. else
  5399. coex_sta->c2h_bt_inquiry_page = false;
  5400. }
  5401. coex_sta->num_of_profile = 0;
  5402. /* set link exist status */
  5403. if (!(bt_info & BT_INFO_8822B_1ANT_B_CONNECTION)) {
  5404. coex_sta->bt_link_exist = false;
  5405. coex_sta->pan_exist = false;
  5406. coex_sta->a2dp_exist = false;
  5407. coex_sta->hid_exist = false;
  5408. coex_sta->sco_exist = false;
  5409. coex_sta->bt_hi_pri_link_exist = false;
  5410. } else { /* connection exists */
  5411. coex_sta->bt_link_exist = true;
  5412. if (bt_info & BT_INFO_8822B_1ANT_B_FTP) {
  5413. coex_sta->pan_exist = true;
  5414. coex_sta->num_of_profile++;
  5415. } else
  5416. coex_sta->pan_exist = false;
  5417. if (bt_info & BT_INFO_8822B_1ANT_B_A2DP) {
  5418. coex_sta->a2dp_exist = true;
  5419. coex_sta->num_of_profile++;
  5420. } else
  5421. coex_sta->a2dp_exist = false;
  5422. if (bt_info & BT_INFO_8822B_1ANT_B_HID) {
  5423. coex_sta->hid_exist = true;
  5424. coex_sta->num_of_profile++;
  5425. } else
  5426. coex_sta->hid_exist = false;
  5427. if (bt_info & BT_INFO_8822B_1ANT_B_SCO_ESCO) {
  5428. coex_sta->sco_exist = true;
  5429. coex_sta->num_of_profile++;
  5430. } else
  5431. coex_sta->sco_exist = false;
  5432. }
  5433. halbtc8822b1ant_update_bt_link_info(btcoexist);
  5434. bt_info = bt_info &
  5435. 0x1f; /* mask profile bit for connect-ilde identification ( for CSR case: A2DP idle --> 0x41) */
  5436. if (!(bt_info & BT_INFO_8822B_1ANT_B_CONNECTION)) {
  5437. coex_dm->bt_status = BT_8822B_1ANT_BT_STATUS_NON_CONNECTED_IDLE;
  5438. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5439. "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n");
  5440. BTC_TRACE(trace_buf);
  5441. } else if (bt_info ==
  5442. BT_INFO_8822B_1ANT_B_CONNECTION) { /* connection exists but no busy */
  5443. coex_dm->bt_status = BT_8822B_1ANT_BT_STATUS_CONNECTED_IDLE;
  5444. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5445. "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
  5446. BTC_TRACE(trace_buf);
  5447. } else if ((bt_info & BT_INFO_8822B_1ANT_B_SCO_ESCO) ||
  5448. (bt_info & BT_INFO_8822B_1ANT_B_SCO_BUSY)) {
  5449. coex_dm->bt_status = BT_8822B_1ANT_BT_STATUS_SCO_BUSY;
  5450. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5451. "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
  5452. BTC_TRACE(trace_buf);
  5453. } else if (bt_info & BT_INFO_8822B_1ANT_B_ACL_BUSY) {
  5454. if (BT_8822B_1ANT_BT_STATUS_ACL_BUSY != coex_dm->bt_status)
  5455. coex_dm->bt_status = BT_8822B_1ANT_BT_STATUS_ACL_BUSY;
  5456. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5457. "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
  5458. BTC_TRACE(trace_buf);
  5459. } else {
  5460. coex_dm->bt_status = BT_8822B_1ANT_BT_STATUS_MAX;
  5461. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5462. "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n");
  5463. BTC_TRACE(trace_buf);
  5464. }
  5465. if ((BT_8822B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
  5466. (BT_8822B_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
  5467. (BT_8822B_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
  5468. bt_busy = true;
  5469. else
  5470. bt_busy = false;
  5471. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
  5472. halbtc8822b1ant_run_coexist_mechanism(btcoexist);
  5473. }
  5474. void ex_halbtc8822b1ant_rf_status_notify(IN struct btc_coexist *btcoexist,
  5475. IN u8 type)
  5476. {
  5477. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], RF Status notify\n");
  5478. BTC_TRACE(trace_buf);
  5479. if (BTC_RF_ON == type) {
  5480. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5481. "[BTCoex], RF is turned ON!!\n");
  5482. BTC_TRACE(trace_buf);
  5483. btcoexist->stop_coex_dm = false;
  5484. halbtc8822b1ant_post_state_to_bt(btcoexist,
  5485. BT_8822B_1ANT_SCOREBOARD_ACTIVE, true);
  5486. halbtc8822b1ant_post_state_to_bt(btcoexist,
  5487. BT_8822B_1ANT_SCOREBOARD_ONOFF, true);
  5488. } else if (BTC_RF_OFF == type) {
  5489. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5490. "[BTCoex], RF is turned OFF!!\n");
  5491. BTC_TRACE(trace_buf);
  5492. halbtc8822b1ant_post_state_to_bt(btcoexist,
  5493. BT_8822B_1ANT_SCOREBOARD_ACTIVE, false);
  5494. halbtc8822b1ant_post_state_to_bt(btcoexist,
  5495. BT_8822B_1ANT_SCOREBOARD_ONOFF, false);
  5496. halbtc8822b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0);
  5497. halbtc8822b1ant_set_ant_path(btcoexist,
  5498. BTC_ANT_PATH_AUTO,
  5499. FORCE_EXEC,
  5500. BT_8822B_1ANT_PHASE_WLAN_OFF);
  5501. /* for test : s3 bt disppear , fail rate 1/600*/
  5502. halbtc8822b1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
  5503. btcoexist->stop_coex_dm = true;
  5504. }
  5505. }
  5506. void ex_halbtc8822b1ant_halt_notify(IN struct btc_coexist *btcoexist)
  5507. {
  5508. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n");
  5509. BTC_TRACE(trace_buf);
  5510. halbtc8822b1ant_post_state_to_bt(btcoexist,
  5511. BT_8822B_1ANT_SCOREBOARD_ACTIVE, false);
  5512. halbtc8822b1ant_post_state_to_bt(btcoexist,
  5513. BT_8822B_1ANT_SCOREBOARD_ONOFF, false);
  5514. halbtc8822b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0);
  5515. halbtc8822b1ant_set_ant_path(btcoexist,
  5516. BTC_ANT_PATH_AUTO,
  5517. FORCE_EXEC,
  5518. BT_8822B_1ANT_PHASE_WLAN_OFF);
  5519. /* for test : s3 bt disppear , fail rate 1/600*/
  5520. halbtc8822b1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
  5521. ex_halbtc8822b1ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT);
  5522. halbtc8822b1ant_enable_gnt_to_gpio(btcoexist, false);
  5523. btcoexist->stop_coex_dm = true;
  5524. }
  5525. void ex_halbtc8822b1ant_pnp_notify(IN struct btc_coexist *btcoexist,
  5526. IN u8 pnp_state)
  5527. {
  5528. boolean wifi_under_5g = false;
  5529. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Pnp notify\n");
  5530. BTC_TRACE(trace_buf);
  5531. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  5532. if (BTC_WIFI_PNP_SLEEP == pnp_state) {
  5533. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5534. "[BTCoex], Pnp notify to SLEEP\n");
  5535. BTC_TRACE(trace_buf);
  5536. halbtc8822b1ant_post_state_to_bt(btcoexist,
  5537. BT_8822B_1ANT_SCOREBOARD_ACTIVE, false);
  5538. halbtc8822b1ant_post_state_to_bt(btcoexist,
  5539. BT_8822B_1ANT_SCOREBOARD_ONOFF, false);
  5540. /*
  5541. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  5542. halbtc8822b1ant_set_ant_path(btcoexist,
  5543. BTC_ANT_PATH_AUTO,
  5544. FORCE_EXEC,
  5545. BT_8822B_1ANT_PHASE_WLAN_OFF);
  5546. halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
  5547. 5);
  5548. halbtc8822b1ant_enable_gnt_to_gpio(btcoexist, false);
  5549. */
  5550. btcoexist->stop_coex_dm = true;
  5551. } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) {
  5552. /*pnp_wake_cnt++;*/
  5553. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5554. "[BTCoex], Pnp notify to WAKE UP\n");
  5555. BTC_TRACE(trace_buf);
  5556. halbtc8822b1ant_post_state_to_bt(btcoexist,
  5557. BT_8822B_1ANT_SCOREBOARD_ACTIVE, true);
  5558. halbtc8822b1ant_post_state_to_bt(btcoexist,
  5559. BT_8822B_1ANT_SCOREBOARD_ONOFF, true);
  5560. btcoexist->stop_coex_dm = false;
  5561. }
  5562. }
  5563. void ex_halbtc8822b1ant_coex_dm_reset(IN struct btc_coexist *btcoexist)
  5564. {
  5565. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5566. "[BTCoex], *****************Coex DM Reset*****************\n");
  5567. BTC_TRACE(trace_buf);
  5568. halbtc8822b1ant_init_hw_config(btcoexist, false, false);
  5569. halbtc8822b1ant_init_coex_dm(btcoexist);
  5570. }
  5571. void ex_halbtc8822b1ant_periodical(IN struct btc_coexist *btcoexist)
  5572. {
  5573. struct btc_board_info *board_info = &btcoexist->board_info;
  5574. boolean wifi_busy = false;
  5575. u16 bt_scoreboard_val = 0;
  5576. u32 bt_patch_ver;
  5577. static u8 cnt = 0;
  5578. boolean bt_relink_finish = false;
  5579. boolean rf4ce_connected = false;
  5580. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5581. "[BTCoex], ==========================Periodical===========================\n");
  5582. BTC_TRACE(trace_buf);
  5583. #if (BT_AUTO_REPORT_ONLY_8822B_1ANT == 0)
  5584. halbtc8822b1ant_query_bt_info(btcoexist);
  5585. #endif
  5586. halbtc8822b1ant_monitor_bt_ctr(btcoexist);
  5587. halbtc8822b1ant_monitor_wifi_ctr(btcoexist);
  5588. halbtc8822b1ant_monitor_bt_enable_disable(btcoexist);
  5589. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  5590. halbtc8822b1ant_read_score_board(btcoexist, &bt_scoreboard_val);
  5591. /*RF4CE for arris , rf4ce always on*/
  5592. /*
  5593. btcoexist->btc_get(btcoexist, BTC_GET_BL_RF4CE_CONNECTED, &rf4ce_connected);
  5594. if (rf4ce_connected){
  5595. btcoexist->btc_write_1byte_bitmask(
  5596. btcoexist, 0x45e, 0x8, 0x1);
  5597. halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  5598. true,
  5599. 50);
  5600. halbtc8822b1ant_coex_table_with_type(btcoexist,
  5601. NORMAL_EXEC, 1);
  5602. return;
  5603. }
  5604. */
  5605. if (wifi_busy) {
  5606. /*WL scoreboard to BT,BT see WL Ccoreboard bit[6]=1 WL BUSY*/
  5607. halbtc8822b1ant_post_state_to_bt(btcoexist,
  5608. BT_8822B_1ANT_SCOREBOARD_WLBUSY, true);
  5609. /*BT scoreboard to WL , let WL see BT scoreboard bit[6]=1*/
  5610. if (bt_scoreboard_val & BIT(6))
  5611. /*btcoexist->btc_set_bt_wake(btcoexist, 45, 1);*/
  5612. halbtc8822b1ant_query_bt_info(btcoexist);
  5613. } else {
  5614. halbtc8822b1ant_post_state_to_bt(btcoexist,
  5615. BT_8822B_1ANT_SCOREBOARD_WLBUSY, false);
  5616. }
  5617. /* for 4-way, DHCP, EAPOL packet */
  5618. if (coex_sta->specific_pkt_period_cnt > 0) {
  5619. coex_sta->specific_pkt_period_cnt--;
  5620. if ((coex_sta->specific_pkt_period_cnt == 0) &&
  5621. (coex_sta->wifi_is_high_pri_task))
  5622. coex_sta->wifi_is_high_pri_task = false;
  5623. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5624. "[BTCoex], ***************** Hi-Pri Task = %s*****************\n",
  5625. (coex_sta->wifi_is_high_pri_task ? "Yes" :
  5626. "No"));
  5627. BTC_TRACE(trace_buf);
  5628. }
  5629. if (!coex_sta->bt_disabled) {
  5630. if (coex_sta->bt_coex_supported_feature == 0)
  5631. btcoexist->btc_get(btcoexist, BTC_GET_U4_SUPPORTED_FEATURE, &coex_sta->bt_coex_supported_feature);
  5632. if ((coex_sta->bt_coex_supported_version == 0) ||
  5633. (coex_sta->bt_coex_supported_version == 0xffff))
  5634. btcoexist->btc_get(btcoexist, BTC_GET_U4_SUPPORTED_VERSION, &coex_sta->bt_coex_supported_version);
  5635. btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
  5636. btcoexist->bt_info.bt_get_fw_ver = bt_patch_ver;
  5637. if (halbtc8822b1ant_is_wifi_status_changed(btcoexist))
  5638. halbtc8822b1ant_run_coexist_mechanism(btcoexist);
  5639. }
  5640. }
  5641. void ex_halbtc8822b1ant_antenna_detection(IN struct btc_coexist *btcoexist,
  5642. IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds)
  5643. {
  5644. }
  5645. void ex_halbtc8822b1ant_antenna_isolation(IN struct btc_coexist *btcoexist,
  5646. IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds)
  5647. {
  5648. }
  5649. void ex_halbtc8822b1ant_psd_scan(IN struct btc_coexist *btcoexist,
  5650. IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds)
  5651. {
  5652. }
  5653. void ex_halbtc8822b1ant_display_ant_detection(IN struct btc_coexist *btcoexist)
  5654. {
  5655. }
  5656. void ex_halbtc8822b1ant_dbg_control(IN struct btc_coexist *btcoexist,
  5657. IN u8 op_code, IN u8 op_len, IN u8 *pdata)
  5658. {}
  5659. #endif /* #if(BTC_COEX_OFFLOAD == 1) */
  5660. #endif
  5661. #else
  5662. void ex_halbtc8822b1ant_switch_band_without_bt(IN struct btc_coexist *btcoexist,
  5663. IN boolean wifi_only_5g)
  5664. {
  5665. /* ant switch WL2G or WL5G*/
  5666. if (wifi_only_5g)
  5667. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd, 0x3, 1);
  5668. else
  5669. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd, 0x3, 2);
  5670. }
  5671. void ex_halbtc8822b1ant_init_hw_config_without_bt(IN struct btc_coexist
  5672. *btcoexist)
  5673. {
  5674. /* enable GNT_WL */
  5675. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x1,
  5676. 0x0);
  5677. /* Antenna config */
  5678. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e,
  5679. 0x80, 0x0); /* 0x4c[23] = 0 */
  5680. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f,
  5681. 0x01, 0x1); /* 0x4c[24] = 1 */
  5682. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb4,
  5683. 0xff, 0x77); /* BB SW, DPDT use RFE_ctrl8 and RFE_ctrl9 as conctrol pin */
  5684. /* Ext switch buffer mux */
  5685. btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff);
  5686. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991,
  5687. 0x3, 0x0);
  5688. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe,
  5689. 0x8, 0x0);
  5690. /*enable sw control gnt_wl=1 / gnt_bt=1 */
  5691. btcoexist->btc_write_1byte(btcoexist, 0x73, 0x0e);
  5692. btcoexist->btc_write_4byte(btcoexist, 0x1704,
  5693. 0x0000ff00);
  5694. btcoexist->btc_write_4byte(btcoexist, 0x1700,
  5695. 0xc00f0038);
  5696. }
  5697. #endif /* #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) */