halbtc8822b2ant.c 162 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583
  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. #include "mp_precomp.h"
  14. #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1)
  15. #if (RTL8822B_SUPPORT == 1)
  16. /* ************************************************************
  17. * Global variables, these are static variables
  18. * ************************************************************ */
  19. static u8 *trace_buf = &gl_btc_trace_buf[0];
  20. static struct coex_dm_8822b_2ant glcoex_dm_8822b_2ant;
  21. static struct coex_dm_8822b_2ant *coex_dm = &glcoex_dm_8822b_2ant;
  22. static struct coex_sta_8822b_2ant glcoex_sta_8822b_2ant;
  23. static struct coex_sta_8822b_2ant *coex_sta = &glcoex_sta_8822b_2ant;
  24. static struct psdscan_sta_8822b_2ant gl_psd_scan_8822b_2ant;
  25. static struct psdscan_sta_8822b_2ant *psd_scan = &gl_psd_scan_8822b_2ant;
  26. static struct rfe_type_8822b_2ant gl_rfe_type_8822b_2ant;
  27. static struct rfe_type_8822b_2ant *rfe_type = &gl_rfe_type_8822b_2ant;
  28. const char *const glbt_info_src_8822b_2ant[] = {
  29. "BT Info[wifi fw]",
  30. "BT Info[bt rsp]",
  31. "BT Info[bt auto report]",
  32. };
  33. u32 glcoex_ver_date_8822b_2ant = 20161124;
  34. u32 glcoex_ver_8822b_2ant = 0x3f;
  35. u32 glcoex_ver_btdesired_8822b_2ant = 0x28;
  36. /* ************************************************************
  37. * local function proto type if needed
  38. * ************************************************************
  39. * ************************************************************
  40. * local function start with halbtc8822b2ant_
  41. * ************************************************************ */
  42. u8 halbtc8822b2ant_bt_rssi_state(u8 *ppre_bt_rssi_state, u8 level_num,
  43. u8 rssi_thresh, u8 rssi_thresh1)
  44. {
  45. s32 bt_rssi = 0;
  46. u8 bt_rssi_state = *ppre_bt_rssi_state;
  47. bt_rssi = coex_sta->bt_rssi;
  48. if (level_num == 2) {
  49. if ((*ppre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
  50. (*ppre_bt_rssi_state == BTC_RSSI_STATE_STAY_LOW)) {
  51. if (bt_rssi >= (rssi_thresh +
  52. BTC_RSSI_COEX_THRESH_TOL_8822B_2ANT))
  53. bt_rssi_state = BTC_RSSI_STATE_HIGH;
  54. else
  55. bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  56. } else {
  57. if (bt_rssi < rssi_thresh)
  58. bt_rssi_state = BTC_RSSI_STATE_LOW;
  59. else
  60. bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  61. }
  62. } else if (level_num == 3) {
  63. if (rssi_thresh > rssi_thresh1) {
  64. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  65. "[BTCoex], BT Rssi thresh error!!\n");
  66. BTC_TRACE(trace_buf);
  67. return *ppre_bt_rssi_state;
  68. }
  69. if ((*ppre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
  70. (*ppre_bt_rssi_state == BTC_RSSI_STATE_STAY_LOW)) {
  71. if (bt_rssi >= (rssi_thresh +
  72. BTC_RSSI_COEX_THRESH_TOL_8822B_2ANT))
  73. bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
  74. else
  75. bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  76. } else if ((*ppre_bt_rssi_state == BTC_RSSI_STATE_MEDIUM) ||
  77. (*ppre_bt_rssi_state == BTC_RSSI_STATE_STAY_MEDIUM)) {
  78. if (bt_rssi >= (rssi_thresh1 +
  79. BTC_RSSI_COEX_THRESH_TOL_8822B_2ANT))
  80. bt_rssi_state = BTC_RSSI_STATE_HIGH;
  81. else if (bt_rssi < rssi_thresh)
  82. bt_rssi_state = BTC_RSSI_STATE_LOW;
  83. else
  84. bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
  85. } else {
  86. if (bt_rssi < rssi_thresh1)
  87. bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
  88. else
  89. bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  90. }
  91. }
  92. *ppre_bt_rssi_state = bt_rssi_state;
  93. return bt_rssi_state;
  94. }
  95. u8 halbtc8822b2ant_wifi_rssi_state(IN struct btc_coexist *btcoexist,
  96. IN u8 *pprewifi_rssi_state, IN u8 level_num, IN u8 rssi_thresh,
  97. IN u8 rssi_thresh1)
  98. {
  99. s32 wifi_rssi = 0;
  100. u8 wifi_rssi_state = *pprewifi_rssi_state;
  101. btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
  102. if (level_num == 2) {
  103. if ((*pprewifi_rssi_state == BTC_RSSI_STATE_LOW) ||
  104. (*pprewifi_rssi_state == BTC_RSSI_STATE_STAY_LOW)) {
  105. if (wifi_rssi >= (rssi_thresh +
  106. BTC_RSSI_COEX_THRESH_TOL_8822B_2ANT))
  107. wifi_rssi_state = BTC_RSSI_STATE_HIGH;
  108. else
  109. wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  110. } else {
  111. if (wifi_rssi < rssi_thresh)
  112. wifi_rssi_state = BTC_RSSI_STATE_LOW;
  113. else
  114. wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  115. }
  116. } else if (level_num == 3) {
  117. if (rssi_thresh > rssi_thresh1) {
  118. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  119. "[BTCoex], wifi RSSI thresh error!!\n");
  120. BTC_TRACE(trace_buf);
  121. return *pprewifi_rssi_state;
  122. }
  123. if ((*pprewifi_rssi_state == BTC_RSSI_STATE_LOW) ||
  124. (*pprewifi_rssi_state == BTC_RSSI_STATE_STAY_LOW)) {
  125. if (wifi_rssi >= (rssi_thresh +
  126. BTC_RSSI_COEX_THRESH_TOL_8822B_2ANT))
  127. wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
  128. else
  129. wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  130. } else if ((*pprewifi_rssi_state == BTC_RSSI_STATE_MEDIUM) ||
  131. (*pprewifi_rssi_state == BTC_RSSI_STATE_STAY_MEDIUM)) {
  132. if (wifi_rssi >= (rssi_thresh1 +
  133. BTC_RSSI_COEX_THRESH_TOL_8822B_2ANT))
  134. wifi_rssi_state = BTC_RSSI_STATE_HIGH;
  135. else if (wifi_rssi < rssi_thresh)
  136. wifi_rssi_state = BTC_RSSI_STATE_LOW;
  137. else
  138. wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
  139. } else {
  140. if (wifi_rssi < rssi_thresh1)
  141. wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
  142. else
  143. wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  144. }
  145. }
  146. *pprewifi_rssi_state = wifi_rssi_state;
  147. return wifi_rssi_state;
  148. }
  149. void halbtc8822b2ant_coex_switch_threshold(IN struct btc_coexist *btcoexist,
  150. IN u8 isolation_measuared)
  151. {
  152. s8 interference_wl_tx = 0, interference_bt_tx = 0;
  153. interference_wl_tx = BT_8822B_2ANT_WIFI_MAX_TX_POWER -
  154. isolation_measuared;
  155. interference_bt_tx = BT_8822B_2ANT_BT_MAX_TX_POWER -
  156. isolation_measuared;
  157. coex_sta->wifi_coex_thres = BT_8822B_2ANT_WIFI_RSSI_COEXSWITCH_THRES1;
  158. coex_sta->wifi_coex_thres2 = BT_8822B_2ANT_WIFI_RSSI_COEXSWITCH_THRES2;
  159. coex_sta->bt_coex_thres = BT_8822B_2ANT_BT_RSSI_COEXSWITCH_THRES1;
  160. coex_sta->bt_coex_thres2 = BT_8822B_2ANT_BT_RSSI_COEXSWITCH_THRES2;
  161. /*
  162. coex_sta->wifi_coex_thres = interference_wl_tx + BT_8822B_2ANT_WIFI_SIR_THRES1;
  163. coex_sta->wifi_coex_thres2 = interference_wl_tx + BT_8822B_2ANT_WIFI_SIR_THRES2;
  164. coex_sta->bt_coex_thres = interference_bt_tx + BT_8822B_2ANT_BT_SIR_THRES1;
  165. coex_sta->bt_coex_thres2 = interference_bt_tx + BT_8822B_2ANT_BT_SIR_THRES2;
  166. */
  167. /*
  168. if ( BT_8822B_2ANT_WIFI_RSSI_COEXSWITCH_THRES1 < (isolation_measuared -
  169. BT_8822B_2ANT_DEFAULT_ISOLATION) )
  170. coex_sta->wifi_coex_thres = BT_8822B_2ANT_WIFI_RSSI_COEXSWITCH_THRES1;
  171. else
  172. coex_sta->wifi_coex_thres = BT_8822B_2ANT_WIFI_RSSI_COEXSWITCH_THRES1 - (isolation_measuared -
  173. BT_8822B_2ANT_DEFAULT_ISOLATION);
  174. if ( BT_8822B_2ANT_BT_RSSI_COEXSWITCH_THRES1 < (isolation_measuared -
  175. BT_8822B_2ANT_DEFAULT_ISOLATION) )
  176. coex_sta->bt_coex_thres = BT_8822B_2ANT_BT_RSSI_COEXSWITCH_THRES1;
  177. else
  178. coex_sta->bt_coex_thres = BT_8822B_2ANT_BT_RSSI_COEXSWITCH_THRES1 - (isolation_measuared -
  179. BT_8822B_2ANT_DEFAULT_ISOLATION);
  180. */
  181. }
  182. void halbtc8822b2ant_limited_rx(IN struct btc_coexist *btcoexist,
  183. IN boolean force_exec, IN boolean rej_ap_agg_pkt,
  184. IN boolean bt_ctrl_agg_buf_size, IN u8 agg_buf_size)
  185. {
  186. boolean reject_rx_agg = rej_ap_agg_pkt;
  187. boolean bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size;
  188. u8 rx_agg_size = agg_buf_size;
  189. /* ============================================ */
  190. /* Rx Aggregation related setting */
  191. /* ============================================ */
  192. btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT,
  193. &reject_rx_agg);
  194. /* decide BT control aggregation buf size or not */
  195. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE,
  196. &bt_ctrl_rx_agg_size);
  197. /* aggregation buf size, only work when BT control Rx aggregation size. */
  198. btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size);
  199. /* real update aggregation setting */
  200. btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
  201. }
  202. void halbtc8822b2ant_query_bt_info(IN struct btc_coexist *btcoexist)
  203. {
  204. u8 h2c_parameter[1] = {0};
  205. boolean RTL97F_8822B = false;
  206. if (RTL97F_8822B == true)
  207. return;
  208. coex_sta->c2h_bt_info_req_sent = true;
  209. h2c_parameter[0] |= BIT(0); /* trigger */
  210. btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter);
  211. }
  212. void halbtc8822b2ant_monitor_bt_ctr(IN struct btc_coexist *btcoexist)
  213. {
  214. u32 reg_hp_txrx, reg_lp_txrx, u32tmp;
  215. u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0;
  216. static u8 num_of_bt_counter_chk = 0, cnt_slave = 0;
  217. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  218. reg_hp_txrx = 0x770;
  219. reg_lp_txrx = 0x774;
  220. u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx);
  221. reg_hp_tx = u32tmp & MASKLWORD;
  222. reg_hp_rx = (u32tmp & MASKHWORD) >> 16;
  223. u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx);
  224. reg_lp_tx = u32tmp & MASKLWORD;
  225. reg_lp_rx = (u32tmp & MASKHWORD) >> 16;
  226. coex_sta->high_priority_tx = reg_hp_tx;
  227. coex_sta->high_priority_rx = reg_hp_rx;
  228. coex_sta->low_priority_tx = reg_lp_tx;
  229. coex_sta->low_priority_rx = reg_lp_rx;
  230. /* reset counter */
  231. btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
  232. if ((coex_sta->low_priority_tx > 1050) &&
  233. (!coex_sta->c2h_bt_inquiry_page))
  234. coex_sta->pop_event_cnt++;
  235. if ((coex_sta->low_priority_rx >= 950) &&
  236. (coex_sta->low_priority_rx >= coex_sta->low_priority_tx)
  237. && (!coex_sta->under_ips) && (!coex_sta->c2h_bt_inquiry_page) &&
  238. (coex_sta->bt_link_exist)) {
  239. if (cnt_slave >= 2) {
  240. bt_link_info->slave_role = true;
  241. cnt_slave = 2;
  242. } else
  243. cnt_slave++;
  244. } else {
  245. if (cnt_slave == 0) {
  246. bt_link_info->slave_role = false;
  247. cnt_slave = 0;
  248. } else
  249. cnt_slave--;
  250. }
  251. if ((coex_sta->high_priority_tx == 0) &&
  252. (coex_sta->high_priority_rx == 0) &&
  253. (coex_sta->low_priority_tx == 0) &&
  254. (coex_sta->low_priority_rx == 0)) {
  255. num_of_bt_counter_chk++;
  256. if (num_of_bt_counter_chk >= 3) {
  257. halbtc8822b2ant_query_bt_info(btcoexist);
  258. num_of_bt_counter_chk = 0;
  259. }
  260. }
  261. }
  262. void halbtc8822b2ant_monitor_wifi_ctr(IN struct btc_coexist *btcoexist)
  263. {
  264. #if 0
  265. s32 wifi_rssi = 0;
  266. boolean wifi_busy = false, wifi_under_b_mode = false;
  267. static u8 cck_lock_counter = 0;
  268. u32 total_cnt, reg_val1, reg_val2;
  269. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  270. btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
  271. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
  272. &wifi_under_b_mode);
  273. if (coex_sta->under_ips) {
  274. coex_sta->crc_ok_cck = 0;
  275. coex_sta->crc_ok_11g = 0;
  276. coex_sta->crc_ok_11n = 0;
  277. coex_sta->crc_ok_11n_agg = 0;
  278. coex_sta->crc_err_cck = 0;
  279. coex_sta->crc_err_11g = 0;
  280. coex_sta->crc_err_11n = 0;
  281. coex_sta->crc_err_11n_agg = 0;
  282. } else {
  283. reg_val1 = btcoexist->btc_read_4byte(btcoexist, 0xf00);
  284. reg_val2 = btcoexist->btc_read_4byte(btcoexist, 0xf04);
  285. coex_sta->crc_ok_cck = reg_val2 & 0xffff;
  286. coex_sta->crc_err_cck = (reg_val1 & 0xffff) + ((reg_val2
  287. & 0xffff0000) >> 16);
  288. reg_val1 = btcoexist->btc_read_4byte(btcoexist, 0xf0c);
  289. coex_sta->crc_ok_11n_agg = reg_val1 & 0xffff;
  290. coex_sta->crc_err_11n_agg = (reg_val1 & 0xffff0000) >>
  291. 16;
  292. reg_val1 = btcoexist->btc_read_4byte(btcoexist, 0xf10);
  293. coex_sta->crc_ok_11n = reg_val1 & 0xffff;
  294. coex_sta->crc_err_11n = (reg_val1 & 0xffff0000) >> 16;
  295. reg_val1 = btcoexist->btc_read_4byte(btcoexist, 0xf14);
  296. coex_sta->crc_ok_11g = reg_val1 & 0xffff;
  297. coex_sta->crc_err_11n = (reg_val1 & 0xffff0000) >> 16;
  298. }
  299. /* reset counter */
  300. /*btcoexist->btc_write_1byte_bitmask(btcoexist, 0xb58, 0x1, 0x1);*/
  301. /*btcoexist->btc_write_1byte_bitmask(btcoexist, 0xb58, 0x1, 0x0);*/
  302. if ((wifi_busy) && (wifi_rssi >= 30) && (!wifi_under_b_mode)) {
  303. total_cnt = coex_sta->crc_ok_cck + coex_sta->crc_ok_11g
  304. +
  305. coex_sta->crc_ok_11n +
  306. coex_sta->crc_ok_11n_agg;
  307. if ((coex_dm->bt_status ==
  308. BT_8822B_2ANT_BT_STATUS_ACL_BUSY) ||
  309. (coex_dm->bt_status ==
  310. BT_8822B_2ANT_BT_STATUS_ACL_SCO_BUSY) ||
  311. (coex_dm->bt_status ==
  312. BT_8822B_2ANT_BT_STATUS_SCO_BUSY)) {
  313. if (coex_sta->crc_ok_cck > (total_cnt -
  314. coex_sta->crc_ok_cck)) {
  315. if (cck_lock_counter < 3)
  316. cck_lock_counter++;
  317. } else {
  318. if (cck_lock_counter > 0)
  319. cck_lock_counter--;
  320. }
  321. } else {
  322. if (cck_lock_counter > 0)
  323. cck_lock_counter--;
  324. }
  325. } else {
  326. if (cck_lock_counter > 0)
  327. cck_lock_counter--;
  328. }
  329. if (!coex_sta->pre_ccklock) {
  330. if (cck_lock_counter >= 3)
  331. coex_sta->cck_lock = true;
  332. else
  333. coex_sta->cck_lock = false;
  334. } else {
  335. if (cck_lock_counter == 0)
  336. coex_sta->cck_lock = false;
  337. else
  338. coex_sta->cck_lock = true;
  339. }
  340. if (coex_sta->cck_lock)
  341. coex_sta->cck_ever_lock = true;
  342. coex_sta->pre_ccklock = coex_sta->cck_lock;
  343. #endif
  344. }
  345. boolean halbtc8822b2ant_is_wifibt_status_changed(IN struct btc_coexist
  346. *btcoexist)
  347. {
  348. static boolean pre_wifi_busy = false, pre_under_4way = false,
  349. pre_bt_hs_on = false, pre_bt_off = false;
  350. static u8 pre_hid_busy_num = 0;
  351. boolean wifi_busy = false, under_4way = false, bt_hs_on = false;
  352. boolean wifi_connected = false;
  353. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  354. &wifi_connected);
  355. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  356. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  357. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
  358. &under_4way);
  359. if (coex_sta->bt_disabled != pre_bt_off) {
  360. pre_bt_off = coex_sta->bt_disabled;
  361. if (coex_sta->bt_disabled)
  362. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  363. "[BTCoex], BT is disabled !!\n");
  364. else
  365. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  366. "[BTCoex], BT is enabled !!\n");
  367. BTC_TRACE(trace_buf);
  368. coex_sta->bt_coex_supported_feature = 0;
  369. coex_sta->bt_coex_supported_version = 0;
  370. coex_sta->bt_ble_scan_type = 0;
  371. coex_sta->bt_ble_scan_para[0] = 0;
  372. coex_sta->bt_ble_scan_para[1] = 0;
  373. coex_sta->bt_ble_scan_para[2] = 0;
  374. coex_sta->bt_reg_vendor_ac = 0xffff;
  375. coex_sta->bt_reg_vendor_ae = 0xffff;
  376. return true;
  377. }
  378. if (wifi_connected) {
  379. if (wifi_busy != pre_wifi_busy) {
  380. pre_wifi_busy = wifi_busy;
  381. return true;
  382. }
  383. if (under_4way != pre_under_4way) {
  384. pre_under_4way = under_4way;
  385. return true;
  386. }
  387. if (bt_hs_on != pre_bt_hs_on) {
  388. pre_bt_hs_on = bt_hs_on;
  389. return true;
  390. }
  391. if (!coex_sta->bt_disabled) {
  392. if (coex_sta->hid_busy_num != pre_hid_busy_num) {
  393. pre_hid_busy_num = coex_sta->hid_busy_num;
  394. return true;
  395. }
  396. }
  397. }
  398. return false;
  399. }
  400. void halbtc8822b2ant_update_bt_link_info(IN struct btc_coexist *btcoexist)
  401. {
  402. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  403. boolean bt_hs_on = false;
  404. boolean bt_busy = false;
  405. coex_sta->num_of_profile = 0;
  406. /* set link exist status */
  407. if (!(coex_sta->bt_info & BT_INFO_8822B_1ANT_B_CONNECTION)) {
  408. coex_sta->bt_link_exist = false;
  409. coex_sta->pan_exist = false;
  410. coex_sta->a2dp_exist = false;
  411. coex_sta->hid_exist = false;
  412. coex_sta->sco_exist = false;
  413. } else { /* connection exists */
  414. coex_sta->bt_link_exist = true;
  415. if (coex_sta->bt_info & BT_INFO_8822B_1ANT_B_FTP) {
  416. coex_sta->pan_exist = true;
  417. coex_sta->num_of_profile++;
  418. } else
  419. coex_sta->pan_exist = false;
  420. if (coex_sta->bt_info & BT_INFO_8822B_1ANT_B_A2DP) {
  421. coex_sta->a2dp_exist = true;
  422. coex_sta->num_of_profile++;
  423. } else
  424. coex_sta->a2dp_exist = false;
  425. if (coex_sta->bt_info & BT_INFO_8822B_1ANT_B_HID) {
  426. coex_sta->hid_exist = true;
  427. coex_sta->num_of_profile++;
  428. } else
  429. coex_sta->hid_exist = false;
  430. if (coex_sta->bt_info & BT_INFO_8822B_1ANT_B_SCO_ESCO) {
  431. coex_sta->sco_exist = true;
  432. coex_sta->num_of_profile++;
  433. } else
  434. coex_sta->sco_exist = false;
  435. }
  436. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  437. bt_link_info->bt_link_exist = coex_sta->bt_link_exist;
  438. bt_link_info->sco_exist = coex_sta->sco_exist;
  439. bt_link_info->a2dp_exist = coex_sta->a2dp_exist;
  440. bt_link_info->pan_exist = coex_sta->pan_exist;
  441. bt_link_info->hid_exist = coex_sta->hid_exist;
  442. bt_link_info->acl_busy = coex_sta->acl_busy;
  443. /* work around for HS mode. */
  444. if (bt_hs_on) {
  445. bt_link_info->pan_exist = true;
  446. bt_link_info->bt_link_exist = true;
  447. }
  448. /* check if Sco only */
  449. if (bt_link_info->sco_exist &&
  450. !bt_link_info->a2dp_exist &&
  451. !bt_link_info->pan_exist &&
  452. !bt_link_info->hid_exist)
  453. bt_link_info->sco_only = true;
  454. else
  455. bt_link_info->sco_only = false;
  456. /* check if A2dp only */
  457. if (!bt_link_info->sco_exist &&
  458. bt_link_info->a2dp_exist &&
  459. !bt_link_info->pan_exist &&
  460. !bt_link_info->hid_exist)
  461. bt_link_info->a2dp_only = true;
  462. else
  463. bt_link_info->a2dp_only = false;
  464. /* check if Pan only */
  465. if (!bt_link_info->sco_exist &&
  466. !bt_link_info->a2dp_exist &&
  467. bt_link_info->pan_exist &&
  468. !bt_link_info->hid_exist)
  469. bt_link_info->pan_only = true;
  470. else
  471. bt_link_info->pan_only = false;
  472. /* check if Hid only */
  473. if (!bt_link_info->sco_exist &&
  474. !bt_link_info->a2dp_exist &&
  475. !bt_link_info->pan_exist &&
  476. bt_link_info->hid_exist)
  477. bt_link_info->hid_only = true;
  478. else
  479. bt_link_info->hid_only = false;
  480. if (!(coex_sta->bt_info & BT_INFO_8822B_2ANT_B_CONNECTION)) {
  481. coex_dm->bt_status = BT_8822B_2ANT_BT_STATUS_NON_CONNECTED_IDLE;
  482. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  483. "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n");
  484. } else if (coex_sta->bt_info == BT_INFO_8822B_2ANT_B_CONNECTION) {
  485. /* connection exists but no busy */
  486. coex_dm->bt_status = BT_8822B_2ANT_BT_STATUS_CONNECTED_IDLE;
  487. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  488. "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
  489. } else if (((coex_sta->bt_info & BT_INFO_8822B_2ANT_B_SCO_ESCO) ||
  490. (coex_sta->bt_info & BT_INFO_8822B_2ANT_B_SCO_BUSY)) &&
  491. (coex_sta->bt_info & BT_INFO_8822B_2ANT_B_ACL_BUSY)) {
  492. coex_dm->bt_status = BT_8822B_2ANT_BT_STATUS_ACL_SCO_BUSY;
  493. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  494. "[BTCoex], BtInfoNotify(), BT ACL SCO busy!!!\n");
  495. } else if ((coex_sta->bt_info & BT_INFO_8822B_2ANT_B_SCO_ESCO) ||
  496. (coex_sta->bt_info & BT_INFO_8822B_2ANT_B_SCO_BUSY)) {
  497. coex_dm->bt_status = BT_8822B_2ANT_BT_STATUS_SCO_BUSY;
  498. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  499. "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
  500. } else if (coex_sta->bt_info & BT_INFO_8822B_2ANT_B_ACL_BUSY) {
  501. coex_dm->bt_status = BT_8822B_2ANT_BT_STATUS_ACL_BUSY;
  502. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  503. "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
  504. } else {
  505. coex_dm->bt_status = BT_8822B_2ANT_BT_STATUS_MAX;
  506. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  507. "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n");
  508. }
  509. BTC_TRACE(trace_buf);
  510. if ((BT_8822B_2ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
  511. (BT_8822B_2ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
  512. (BT_8822B_2ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
  513. bt_busy = true;
  514. else
  515. bt_busy = false;
  516. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
  517. }
  518. void halbtc8822b2ant_update_wifi_channel_info(IN struct btc_coexist *btcoexist,
  519. IN u8 type)
  520. {
  521. u8 h2c_parameter[3] = {0};
  522. u32 wifi_bw;
  523. u8 wifi_central_chnl;
  524. u32 RTL97F_8822B = 0;
  525. if (RTL97F_8822B == true)
  526. return;
  527. /* only 2.4G we need to inform bt the chnl mask */
  528. btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL,
  529. &wifi_central_chnl);
  530. if ((BTC_MEDIA_CONNECT == type) &&
  531. (wifi_central_chnl <= 14)) {
  532. h2c_parameter[0] =
  533. 0x1; /* enable BT AFH skip WL channel for 8822b because BT Rx LO interference */
  534. /* h2c_parameter[0] = 0x0; */
  535. h2c_parameter[1] = wifi_central_chnl;
  536. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  537. if (BTC_WIFI_BW_HT40 == wifi_bw)
  538. h2c_parameter[2] = 0x30;
  539. else
  540. h2c_parameter[2] = 0x20;
  541. }
  542. coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
  543. coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
  544. coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
  545. btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter);
  546. }
  547. void halbtc8822b2ant_set_fw_dac_swing_level(IN struct btc_coexist *btcoexist,
  548. IN u8 dac_swing_lvl)
  549. {
  550. u8 h2c_parameter[1] = {0};
  551. u32 RTL97F_8822B = 0;
  552. if (RTL97F_8822B == true)
  553. return;
  554. /* There are several type of dacswing */
  555. /* 0x18/ 0x10/ 0xc/ 0x8/ 0x4/ 0x6 */
  556. h2c_parameter[0] = dac_swing_lvl;
  557. btcoexist->btc_fill_h2c(btcoexist, 0x64, 1, h2c_parameter);
  558. }
  559. void halbtc8822b2ant_fw_dac_swing_lvl(IN struct btc_coexist *btcoexist,
  560. IN boolean force_exec, IN u8 fw_dac_swing_lvl)
  561. {
  562. u32 RTL97F_8822B = 0;
  563. if (RTL97F_8822B == true)
  564. return;
  565. coex_dm->cur_fw_dac_swing_lvl = fw_dac_swing_lvl;
  566. if (!force_exec) {
  567. if (coex_dm->pre_fw_dac_swing_lvl ==
  568. coex_dm->cur_fw_dac_swing_lvl)
  569. return;
  570. }
  571. halbtc8822b2ant_set_fw_dac_swing_level(btcoexist,
  572. coex_dm->cur_fw_dac_swing_lvl);
  573. coex_dm->pre_fw_dac_swing_lvl = coex_dm->cur_fw_dac_swing_lvl;
  574. }
  575. void halbtc8822b2ant_set_fw_dec_bt_pwr(IN struct btc_coexist *btcoexist,
  576. IN u8 dec_bt_pwr_lvl)
  577. {
  578. u32 RTL97F_8822B = 0;
  579. u8 h2c_parameter[1] = {0};
  580. if (RTL97F_8822B == true)
  581. return;
  582. h2c_parameter[0] = dec_bt_pwr_lvl;
  583. btcoexist->btc_fill_h2c(btcoexist, 0x62, 1, h2c_parameter);
  584. }
  585. void halbtc8822b2ant_dec_bt_pwr(IN struct btc_coexist *btcoexist,
  586. IN boolean force_exec, IN u8 dec_bt_pwr_lvl)
  587. {
  588. coex_dm->cur_bt_dec_pwr_lvl = dec_bt_pwr_lvl;
  589. if (!force_exec) {
  590. if (coex_dm->pre_bt_dec_pwr_lvl == coex_dm->cur_bt_dec_pwr_lvl)
  591. return;
  592. }
  593. halbtc8822b2ant_set_fw_dec_bt_pwr(btcoexist,
  594. coex_dm->cur_bt_dec_pwr_lvl);
  595. coex_dm->pre_bt_dec_pwr_lvl = coex_dm->cur_bt_dec_pwr_lvl;
  596. }
  597. void halbtc8822b2ant_low_penalty_ra(IN struct btc_coexist *btcoexist,
  598. IN boolean force_exec, IN boolean low_penalty_ra)
  599. {
  600. #if 1
  601. coex_dm->cur_low_penalty_ra = low_penalty_ra;
  602. if (!force_exec) {
  603. if (coex_dm->pre_low_penalty_ra ==
  604. coex_dm->cur_low_penalty_ra)
  605. return;
  606. }
  607. if (low_penalty_ra)
  608. btcoexist->btc_phydm_modify_RA_PCR_threshold(btcoexist, 0, 50);
  609. else
  610. btcoexist->btc_phydm_modify_RA_PCR_threshold(btcoexist, 0, 0);
  611. coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra;
  612. #endif
  613. }
  614. void halbtc8822b2ant_set_bt_auto_report(IN struct btc_coexist *btcoexist,
  615. IN boolean enable_auto_report)
  616. {
  617. u8 h2c_parameter[1] = {0};
  618. u32 RTL97F_8822B = 0;
  619. if (RTL97F_8822B == true)
  620. return;
  621. h2c_parameter[0] = 0;
  622. if (enable_auto_report)
  623. h2c_parameter[0] |= BIT(0);
  624. btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter);
  625. }
  626. void halbtc8822b2ant_bt_auto_report(IN struct btc_coexist *btcoexist,
  627. IN boolean force_exec, IN boolean enable_auto_report)
  628. {
  629. coex_dm->cur_bt_auto_report = enable_auto_report;
  630. if (!force_exec) {
  631. if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report)
  632. return;
  633. }
  634. halbtc8822b2ant_set_bt_auto_report(btcoexist,
  635. coex_dm->cur_bt_auto_report);
  636. coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report;
  637. }
  638. void halbtc8822b2ant_write_score_board(
  639. IN struct btc_coexist *btcoexist,
  640. IN u16 bitpos,
  641. IN boolean state
  642. )
  643. {
  644. static u16 originalval = 0x8002;
  645. if (state)
  646. originalval = originalval | bitpos;
  647. else
  648. originalval = originalval & (~bitpos);
  649. btcoexist->btc_write_2byte(btcoexist, 0xaa, originalval);
  650. }
  651. void halbtc8822b2ant_read_score_board(
  652. IN struct btc_coexist *btcoexist,
  653. IN u16 *score_board_val
  654. )
  655. {
  656. *score_board_val = (btcoexist->btc_read_2byte(btcoexist,
  657. 0xaa)) & 0x7fff;
  658. }
  659. void halbtc8822b2ant_post_state_to_bt(
  660. IN struct btc_coexist *btcoexist,
  661. IN u16 type,
  662. IN BOOLEAN state
  663. )
  664. {
  665. halbtc8822b2ant_write_score_board(btcoexist, (u16) type, state);
  666. }
  667. void halbtc8822b2ant_monitor_bt_enable_disable(IN struct btc_coexist *btcoexist)
  668. {
  669. static u32 bt_disable_cnt = 0;
  670. boolean bt_active = true, bt_disabled = false, wifi_under_5g = false;
  671. u16 u16tmp;
  672. /* This function check if bt is disabled */
  673. #if 0
  674. if (coex_sta->high_priority_tx == 0 &&
  675. coex_sta->high_priority_rx == 0 &&
  676. coex_sta->low_priority_tx == 0 &&
  677. coex_sta->low_priority_rx == 0)
  678. bt_active = false;
  679. if (coex_sta->high_priority_tx == 0xffff &&
  680. coex_sta->high_priority_rx == 0xffff &&
  681. coex_sta->low_priority_tx == 0xffff &&
  682. coex_sta->low_priority_rx == 0xffff)
  683. bt_active = false;
  684. #else
  685. /* Read BT on/off status from scoreboard[1], enable this only if BT patch support this feature */
  686. halbtc8822b2ant_read_score_board(btcoexist, &u16tmp);
  687. bt_active = u16tmp & BIT(1);
  688. #endif
  689. if (bt_active) {
  690. bt_disable_cnt = 0;
  691. bt_disabled = false;
  692. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
  693. &bt_disabled);
  694. } else {
  695. bt_disable_cnt++;
  696. if (bt_disable_cnt >= 10) {
  697. bt_disabled = true;
  698. bt_disable_cnt = 10;
  699. }
  700. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
  701. &bt_disabled);
  702. }
  703. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  704. if ((wifi_under_5g) || (bt_disabled))
  705. halbtc8822b2ant_low_penalty_ra(btcoexist, NORMAL_EXEC, false);
  706. else
  707. halbtc8822b2ant_low_penalty_ra(btcoexist, NORMAL_EXEC, true);
  708. if (coex_sta->bt_disabled != bt_disabled) {
  709. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  710. "[BTCoex], BT is from %s to %s!!\n",
  711. (coex_sta->bt_disabled ? "disabled" : "enabled"),
  712. (bt_disabled ? "disabled" : "enabled"));
  713. BTC_TRACE(trace_buf);
  714. coex_sta->bt_disabled = bt_disabled;
  715. }
  716. }
  717. void halbtc8822b2ant_enable_gnt_to_gpio(IN struct btc_coexist *btcoexist,
  718. boolean isenable)
  719. {
  720. #if BT_8822B_2ANT_COEX_DBG
  721. static u8 bitVal[5] = {0, 0, 0, 0, 0};
  722. static boolean state = false;
  723. /*
  724. if (state ==isenable)
  725. return;
  726. else
  727. state = isenable;
  728. */
  729. if (isenable) {
  730. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  731. "[BTCoex], enable_gnt_to_gpio!!\n");
  732. BTC_TRACE(trace_buf);
  733. /* enable GNT_WL, GNT_BT to GPIO for debug */
  734. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x8, 0x1);
  735. /* store original value */
  736. bitVal[0] = (btcoexist->btc_read_1byte(btcoexist,
  737. 0x66) & BIT(4)) >> 4; /*0x66[4] */
  738. bitVal[1] = (btcoexist->btc_read_1byte(btcoexist,
  739. 0x67) & BIT(0)); /*0x66[8] */
  740. bitVal[2] = (btcoexist->btc_read_1byte(btcoexist,
  741. 0x42) & BIT(3)) >> 3; /*0x40[19] */
  742. bitVal[3] = (btcoexist->btc_read_1byte(btcoexist,
  743. 0x65) & BIT(7)) >> 7; /*0x64[15] */
  744. bitVal[4] = (btcoexist->btc_read_1byte(btcoexist,
  745. 0x72) & BIT(2)) >> 2; /*0x70[18] */
  746. /* switch GPIO Mux */
  747. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x66, BIT(4),
  748. 0x0); /*0x66[4] = 0 */
  749. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, BIT(0),
  750. 0x0); /*0x66[8] = 0 */
  751. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x42, BIT(3),
  752. 0x0); /*0x40[19] = 0 */
  753. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x65, BIT(7),
  754. 0x0); /*0x64[15] = 0 */
  755. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x72, BIT(2),
  756. 0x0); /*0x70[18] = 0 */
  757. } else {
  758. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  759. "[BTCoex], disable_gnt_to_gpio!!\n");
  760. BTC_TRACE(trace_buf);
  761. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x8, 0x0);
  762. /* Restore original value */
  763. /* switch GPIO Mux */
  764. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x66, BIT(4),
  765. bitVal[0]); /*0x66[4] = 0 */
  766. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, BIT(0),
  767. bitVal[1]); /*0x66[8] = 0 */
  768. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x42, BIT(3),
  769. bitVal[2]); /*0x40[19] = 0 */
  770. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x65, BIT(7),
  771. bitVal[3]); /*0x64[15] = 0 */
  772. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x72, BIT(2),
  773. bitVal[4]); /*0x70[18] = 0 */
  774. }
  775. #endif
  776. }
  777. u32 halbtc8822b2ant_ltecoex_indirect_read_reg(IN struct btc_coexist *btcoexist,
  778. IN u16 reg_addr)
  779. {
  780. u32 j = 0, delay_count = 0;
  781. /* wait for ready bit before access 0x1700 */
  782. btcoexist->btc_write_4byte(btcoexist, 0x1700, 0x800F0000 | reg_addr);
  783. #if 0
  784. do {
  785. j++;
  786. } while (((btcoexist->btc_read_1byte(btcoexist,
  787. 0x1703)&BIT(5)) == 0) &&
  788. (j < BT_8822B_2ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT));
  789. #endif
  790. while (1) {
  791. if ((btcoexist->btc_read_1byte(btcoexist, 0x1703)&BIT(5)) == 0) {
  792. delay_ms(50);
  793. delay_count++;
  794. if (delay_count >= 10) {
  795. delay_count = 0;
  796. break;
  797. }
  798. } else
  799. break;
  800. }
  801. return btcoexist->btc_read_4byte(btcoexist,
  802. 0x1708); /* get read data */
  803. }
  804. void halbtc8822b2ant_ltecoex_indirect_write_reg(IN struct btc_coexist
  805. *btcoexist,
  806. IN u16 reg_addr, IN u32 bit_mask, IN u32 reg_value)
  807. {
  808. u32 val, i = 0, j = 0, bitpos = 0, delay_count = 0;
  809. if (bit_mask == 0x0)
  810. return;
  811. if (bit_mask == 0xffffffff) {
  812. btcoexist->btc_write_4byte(btcoexist, 0x1704,
  813. reg_value); /* put write data */
  814. /* wait for ready bit before access 0x1700 */
  815. #if 0
  816. do {
  817. j++;
  818. } while (((btcoexist->btc_read_1byte(btcoexist,
  819. 0x1703)&BIT(5)) == 0) &&
  820. (j < BT_8822B_2ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT));
  821. #endif
  822. while (1) {
  823. if ((btcoexist->btc_read_1byte(btcoexist, 0x1703)&BIT(5)) == 0) {
  824. delay_ms(50);
  825. delay_count++;
  826. if (delay_count >= 10) {
  827. delay_count = 0;
  828. break;
  829. }
  830. } else
  831. break;
  832. }
  833. btcoexist->btc_write_4byte(btcoexist, 0x1700,
  834. 0xc00F0000 | reg_addr);
  835. } else {
  836. for (i = 0; i <= 31; i++) {
  837. if (((bit_mask >> i) & 0x1) == 0x1) {
  838. bitpos = i;
  839. break;
  840. }
  841. }
  842. /* read back register value before write */
  843. val = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist,
  844. reg_addr);
  845. val = (val & (~bit_mask)) | (reg_value << bitpos);
  846. btcoexist->btc_write_4byte(btcoexist, 0x1704,
  847. val); /* put write data */
  848. /* wait for ready bit before access 0x7c0 */
  849. #if 0
  850. do {
  851. j++;
  852. } while (((btcoexist->btc_read_1byte(btcoexist,
  853. 0x1703)&BIT(5)) == 0) &&
  854. (j < BT_8822B_2ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT));
  855. #endif
  856. while (1) {
  857. if ((btcoexist->btc_read_1byte(btcoexist, 0x1703)&BIT(5)) == 0) {
  858. delay_ms(50);
  859. delay_count++;
  860. if (delay_count >= 10) {
  861. delay_count = 0;
  862. break;
  863. }
  864. } else
  865. break;
  866. }
  867. btcoexist->btc_write_4byte(btcoexist, 0x1700,
  868. 0xc00F0000 | reg_addr);
  869. }
  870. }
  871. void halbtc8822b2ant_ltecoex_enable(IN struct btc_coexist *btcoexist,
  872. IN boolean enable)
  873. {
  874. u8 val;
  875. val = (enable) ? 1 : 0;
  876. halbtc8822b2ant_ltecoex_indirect_write_reg(btcoexist, 0x38, 0x80,
  877. val); /* 0x38[7] */
  878. }
  879. void halbtc8822b2ant_ltecoex_pathcontrol_owner(IN struct btc_coexist *btcoexist,
  880. IN boolean wifi_control)
  881. {
  882. u8 val;
  883. val = (wifi_control) ? 1 : 0;
  884. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x4,
  885. val); /* 0x70[26] */
  886. }
  887. void halbtc8822b2ant_ltecoex_set_gnt_bt(IN struct btc_coexist *btcoexist,
  888. IN u8 control_block, IN boolean sw_control, IN u8 state)
  889. {
  890. u32 val = 0, bit_mask;
  891. state = state & 0x1;
  892. val = (sw_control) ? ((state << 1) | 0x1) : 0;
  893. switch (control_block) {
  894. case BT_8822B_2ANT_GNT_BLOCK_RFC_BB:
  895. default:
  896. bit_mask = 0xc000;
  897. halbtc8822b2ant_ltecoex_indirect_write_reg(btcoexist,
  898. 0x38, bit_mask, val); /* 0x38[15:14] */
  899. bit_mask = 0x0c00;
  900. halbtc8822b2ant_ltecoex_indirect_write_reg(btcoexist,
  901. 0x38, bit_mask, val); /* 0x38[11:10] */
  902. break;
  903. case BT_8822B_2ANT_GNT_BLOCK_RFC:
  904. bit_mask = 0xc000;
  905. halbtc8822b2ant_ltecoex_indirect_write_reg(btcoexist,
  906. 0x38, bit_mask, val); /* 0x38[15:14] */
  907. break;
  908. case BT_8822B_2ANT_GNT_BLOCK_BB:
  909. bit_mask = 0x0c00;
  910. halbtc8822b2ant_ltecoex_indirect_write_reg(btcoexist,
  911. 0x38, bit_mask, val); /* 0x38[11:10] */
  912. break;
  913. }
  914. }
  915. void halbtc8822b2ant_ltecoex_set_gnt_wl(IN struct btc_coexist *btcoexist,
  916. IN u8 control_block, IN boolean sw_control, IN u8 state)
  917. {
  918. u32 val = 0, bit_mask;
  919. state = state & 0x1;
  920. val = (sw_control) ? ((state << 1) | 0x1) : 0;
  921. switch (control_block) {
  922. case BT_8822B_2ANT_GNT_BLOCK_RFC_BB:
  923. default:
  924. bit_mask = 0x3000;
  925. halbtc8822b2ant_ltecoex_indirect_write_reg(btcoexist,
  926. 0x38, bit_mask, val); /* 0x38[13:12] */
  927. bit_mask = 0x0300;
  928. halbtc8822b2ant_ltecoex_indirect_write_reg(btcoexist,
  929. 0x38, bit_mask, val); /* 0x38[9:8] */
  930. break;
  931. case BT_8822B_2ANT_GNT_BLOCK_RFC:
  932. bit_mask = 0x3000;
  933. halbtc8822b2ant_ltecoex_indirect_write_reg(btcoexist,
  934. 0x38, bit_mask, val); /* 0x38[13:12] */
  935. break;
  936. case BT_8822B_2ANT_GNT_BLOCK_BB:
  937. bit_mask = 0x0300;
  938. halbtc8822b2ant_ltecoex_indirect_write_reg(btcoexist,
  939. 0x38, bit_mask, val); /* 0x38[9:8] */
  940. break;
  941. }
  942. }
  943. void halbtc8822b2ant_ltecoex_set_coex_table(IN struct btc_coexist *btcoexist,
  944. IN u8 table_type, IN u16 table_content)
  945. {
  946. u16 reg_addr = 0x0000;
  947. switch (table_type) {
  948. case BT_8822B_2ANT_CTT_WL_VS_LTE:
  949. reg_addr = 0xa0;
  950. break;
  951. case BT_8822B_2ANT_CTT_BT_VS_LTE:
  952. reg_addr = 0xa4;
  953. break;
  954. }
  955. if (reg_addr != 0x0000)
  956. halbtc8822b2ant_ltecoex_indirect_write_reg(btcoexist, reg_addr,
  957. 0xffff, table_content); /* 0xa0[15:0] or 0xa4[15:0] */
  958. }
  959. void halbtc8822b2ant_ltecoex_set_break_table(IN struct btc_coexist *btcoexist,
  960. IN u8 table_type, IN u8 table_content)
  961. {
  962. u16 reg_addr = 0x0000;
  963. switch (table_type) {
  964. case BT_8822B_2ANT_LBTT_WL_BREAK_LTE:
  965. reg_addr = 0xa8;
  966. break;
  967. case BT_8822B_2ANT_LBTT_BT_BREAK_LTE:
  968. reg_addr = 0xac;
  969. break;
  970. case BT_8822B_2ANT_LBTT_LTE_BREAK_WL:
  971. reg_addr = 0xb0;
  972. break;
  973. case BT_8822B_2ANT_LBTT_LTE_BREAK_BT:
  974. reg_addr = 0xb4;
  975. break;
  976. }
  977. if (reg_addr != 0x0000)
  978. halbtc8822b2ant_ltecoex_indirect_write_reg(btcoexist, reg_addr,
  979. 0xff, table_content); /* 0xa8[15:0] or 0xb4[15:0] */
  980. }
  981. void halbtc8822b2ant_set_coex_table(IN struct btc_coexist *btcoexist,
  982. IN u32 val0x6c0, IN u32 val0x6c4, IN u32 val0x6c8, IN u8 val0x6cc)
  983. {
  984. btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0);
  985. btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4);
  986. btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8);
  987. btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc);
  988. }
  989. void halbtc8822b2ant_coex_table(IN struct btc_coexist *btcoexist,
  990. IN boolean force_exec, IN u32 val0x6c0, IN u32 val0x6c4,
  991. IN u32 val0x6c8, IN u8 val0x6cc)
  992. {
  993. coex_dm->cur_val0x6c0 = val0x6c0;
  994. coex_dm->cur_val0x6c4 = val0x6c4;
  995. coex_dm->cur_val0x6c8 = val0x6c8;
  996. coex_dm->cur_val0x6cc = val0x6cc;
  997. if (!force_exec) {
  998. if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) &&
  999. (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) &&
  1000. (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) &&
  1001. (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc))
  1002. return;
  1003. }
  1004. halbtc8822b2ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8,
  1005. val0x6cc);
  1006. coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0;
  1007. coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4;
  1008. coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8;
  1009. coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc;
  1010. }
  1011. void halbtc8822b2ant_coex_table_with_type(IN struct btc_coexist *btcoexist,
  1012. IN boolean force_exec, IN u8 type)
  1013. {
  1014. u32 break_table;
  1015. u8 select_table;
  1016. coex_sta->coex_table_type = type;
  1017. if (coex_sta->concurrent_rx_mode_on == true) {
  1018. break_table = 0xf0ffffff; /* set WL hi-pri can break BT */
  1019. select_table =
  1020. 0x3; /* 0xb/0x3,set Tx response = Hi-Pri/LO-Pri (ex: Transmitting ACK,BA,CTS) */
  1021. } else {
  1022. break_table = 0xffffff;
  1023. select_table = 0x3;
  1024. }
  1025. switch (type) {
  1026. case 0:
  1027. halbtc8822b2ant_coex_table(btcoexist, force_exec,
  1028. 0x55555555, 0x55555555, break_table, select_table);
  1029. break;
  1030. case 1:
  1031. halbtc8822b2ant_coex_table(btcoexist, force_exec,
  1032. 0x55555555, 0x5a5a5a5a, break_table, select_table);
  1033. break;
  1034. case 2:
  1035. halbtc8822b2ant_coex_table(btcoexist, force_exec,
  1036. 0x5a5a5a5a, 0x5a5a5a5a, break_table, select_table);
  1037. break;
  1038. case 3:
  1039. halbtc8822b2ant_coex_table(btcoexist, force_exec,
  1040. 0x5a5a5a5a, 0x5a5a5a5a, break_table, select_table);
  1041. break;
  1042. case 4:
  1043. halbtc8822b2ant_coex_table(btcoexist, force_exec,
  1044. 0x55555555, 0x5a5a5a5a, break_table, select_table);
  1045. break;
  1046. case 5:
  1047. halbtc8822b2ant_coex_table(btcoexist, force_exec,
  1048. 0x55555555, 0x5a5a5a5a, break_table, select_table);
  1049. break;
  1050. case 6:
  1051. halbtc8822b2ant_coex_table(btcoexist, force_exec,
  1052. 0x55555555, 0xaaaa5aaa, break_table, select_table);
  1053. break;
  1054. case 7:
  1055. halbtc8822b2ant_coex_table(btcoexist, force_exec,
  1056. 0xa5555555, 0xaa5a5a5a, break_table, select_table);
  1057. break;
  1058. case 8:
  1059. halbtc8822b2ant_coex_table(btcoexist, force_exec,
  1060. 0x55555555, 0x5a5a5a5a, break_table, select_table);
  1061. break;
  1062. case 9:
  1063. halbtc8822b2ant_coex_table(btcoexist, force_exec,
  1064. 0x55555555, 0xaaaa555a, break_table, select_table);
  1065. break;
  1066. case 10:
  1067. halbtc8822b2ant_coex_table(btcoexist, force_exec,
  1068. 0x55555555, 0xaaaa5aaa, break_table, select_table);
  1069. break;
  1070. case 11:
  1071. halbtc8822b2ant_coex_table(btcoexist, force_exec,
  1072. 0x55555555, 0xaaaaa5aa, break_table, select_table);
  1073. break;
  1074. case 12:
  1075. halbtc8822b2ant_coex_table(btcoexist, force_exec,
  1076. 0x55555555, 0xaaaa55aa, break_table, select_table);
  1077. break;
  1078. default:
  1079. break;
  1080. }
  1081. }
  1082. void halbtc8822b2ant_set_fw_ignore_wlan_act(IN struct btc_coexist *btcoexist,
  1083. IN boolean enable)
  1084. {
  1085. u8 h2c_parameter[1] = {0};
  1086. u32 RTL97F_8822B = 0;
  1087. if (RTL97F_8822B == true)
  1088. return;
  1089. if (enable)
  1090. h2c_parameter[0] |= BIT(0); /* function enable */
  1091. btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter);
  1092. }
  1093. void halbtc8822b2ant_ignore_wlan_act(IN struct btc_coexist *btcoexist,
  1094. IN boolean force_exec, IN boolean enable)
  1095. {
  1096. coex_dm->cur_ignore_wlan_act = enable;
  1097. if (!force_exec) {
  1098. if (coex_dm->pre_ignore_wlan_act ==
  1099. coex_dm->cur_ignore_wlan_act)
  1100. return;
  1101. }
  1102. halbtc8822b2ant_set_fw_ignore_wlan_act(btcoexist, enable);
  1103. coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act;
  1104. }
  1105. void halbtc8822b2ant_set_lps_rpwm(IN struct btc_coexist *btcoexist,
  1106. IN u8 lps_val, IN u8 rpwm_val)
  1107. {
  1108. u8 lps = lps_val;
  1109. u8 rpwm = rpwm_val;
  1110. btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps);
  1111. btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
  1112. }
  1113. void halbtc8822b2ant_lps_rpwm(IN struct btc_coexist *btcoexist,
  1114. IN boolean force_exec, IN u8 lps_val, IN u8 rpwm_val)
  1115. {
  1116. coex_dm->cur_lps = lps_val;
  1117. coex_dm->cur_rpwm = rpwm_val;
  1118. if (!force_exec) {
  1119. if ((coex_dm->pre_lps == coex_dm->cur_lps) &&
  1120. (coex_dm->pre_rpwm == coex_dm->cur_rpwm))
  1121. return;
  1122. }
  1123. halbtc8822b2ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val);
  1124. coex_dm->pre_lps = coex_dm->cur_lps;
  1125. coex_dm->pre_rpwm = coex_dm->cur_rpwm;
  1126. }
  1127. void halbtc8822b2ant_ps_tdma_check_for_power_save_state(
  1128. IN struct btc_coexist *btcoexist, IN boolean new_ps_state)
  1129. {
  1130. u8 lps_mode = 0x0;
  1131. u8 h2c_parameter[5] = {0, 0, 0, 0x40, 0};
  1132. u32 RTL97F_8822B = 0;
  1133. if (RTL97F_8822B == true)
  1134. return;
  1135. btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode);
  1136. if (lps_mode) { /* already under LPS state */
  1137. if (new_ps_state) {
  1138. /* keep state under LPS, do nothing. */
  1139. } else {
  1140. /* will leave LPS state, turn off psTdma first */
  1141. /*halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
  1142. 8); */
  1143. btcoexist->btc_fill_h2c(btcoexist, 0x60, 5,
  1144. h2c_parameter);
  1145. }
  1146. } else { /* NO PS state */
  1147. if (new_ps_state) {
  1148. /* will enter LPS state, turn off psTdma first */
  1149. /*halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
  1150. 8);*/
  1151. btcoexist->btc_fill_h2c(btcoexist, 0x60, 5,
  1152. h2c_parameter);
  1153. } else {
  1154. /* keep state under NO PS state, do nothing. */
  1155. }
  1156. }
  1157. }
  1158. void halbtc8822b2ant_power_save_state(IN struct btc_coexist *btcoexist,
  1159. IN u8 ps_type, IN u8 lps_val, IN u8 rpwm_val)
  1160. {
  1161. boolean low_pwr_disable = false;
  1162. switch (ps_type) {
  1163. case BTC_PS_WIFI_NATIVE:
  1164. /* recover to original 32k low power setting */
  1165. low_pwr_disable = false;
  1166. btcoexist->btc_set(btcoexist,
  1167. BTC_SET_ACT_DISABLE_LOW_POWER,
  1168. &low_pwr_disable);
  1169. btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS,
  1170. NULL);
  1171. coex_sta->force_lps_on = false;
  1172. break;
  1173. case BTC_PS_LPS_ON:
  1174. halbtc8822b2ant_ps_tdma_check_for_power_save_state(
  1175. btcoexist, true);
  1176. halbtc8822b2ant_lps_rpwm(btcoexist, NORMAL_EXEC,
  1177. lps_val, rpwm_val);
  1178. /* when coex force to enter LPS, do not enter 32k low power. */
  1179. low_pwr_disable = true;
  1180. btcoexist->btc_set(btcoexist,
  1181. BTC_SET_ACT_DISABLE_LOW_POWER,
  1182. &low_pwr_disable);
  1183. /* power save must executed before psTdma. */
  1184. btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS,
  1185. NULL);
  1186. coex_sta->force_lps_on = true;
  1187. break;
  1188. case BTC_PS_LPS_OFF:
  1189. halbtc8822b2ant_ps_tdma_check_for_power_save_state(
  1190. btcoexist, false);
  1191. btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS,
  1192. NULL);
  1193. coex_sta->force_lps_on = false;
  1194. break;
  1195. default:
  1196. break;
  1197. }
  1198. }
  1199. void halbtc8822b2ant_set_fw_pstdma(IN struct btc_coexist *btcoexist,
  1200. IN u8 byte1, IN u8 byte2, IN u8 byte3, IN u8 byte4, IN u8 byte5)
  1201. {
  1202. u8 h2c_parameter[5] = {0};
  1203. u8 real_byte1 = byte1, real_byte5 = byte5;
  1204. boolean ap_enable = false;
  1205. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
  1206. &ap_enable);
  1207. if (ap_enable) {
  1208. if (byte1 & BIT(4) && !(byte1 & BIT(5))) {
  1209. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1210. "[BTCoex], FW for AP mode\n");
  1211. BTC_TRACE(trace_buf);
  1212. real_byte1 &= ~BIT(4);
  1213. real_byte1 |= BIT(5);
  1214. real_byte5 |= BIT(5);
  1215. real_byte5 &= ~BIT(6);
  1216. halbtc8822b2ant_power_save_state(btcoexist,
  1217. BTC_PS_WIFI_NATIVE, 0x0,
  1218. 0x0);
  1219. }
  1220. } else if (byte1 & BIT(4) && !(byte1 & BIT(5))) {
  1221. halbtc8822b2ant_power_save_state(
  1222. btcoexist, BTC_PS_LPS_ON, 0x50,
  1223. 0x4);
  1224. } else {
  1225. halbtc8822b2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  1226. 0x0,
  1227. 0x0);
  1228. }
  1229. h2c_parameter[0] = real_byte1;
  1230. h2c_parameter[1] = byte2;
  1231. h2c_parameter[2] = byte3;
  1232. h2c_parameter[3] = byte4;
  1233. h2c_parameter[4] = real_byte5;
  1234. coex_dm->ps_tdma_para[0] = real_byte1;
  1235. coex_dm->ps_tdma_para[1] = byte2;
  1236. coex_dm->ps_tdma_para[2] = byte3;
  1237. coex_dm->ps_tdma_para[3] = byte4;
  1238. coex_dm->ps_tdma_para[4] = real_byte5;
  1239. btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter);
  1240. }
  1241. void halbtc8822b2ant_ps_tdma(IN struct btc_coexist *btcoexist,
  1242. IN boolean force_exec, IN boolean turn_on, IN u8 type)
  1243. {
  1244. static u8 psTdmaByte4Modify = 0x0, pre_psTdmaByte4Modify = 0x0;
  1245. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1246. coex_dm->cur_ps_tdma_on = turn_on;
  1247. coex_dm->cur_ps_tdma = type;
  1248. /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */
  1249. if ((bt_link_info->slave_role) && (bt_link_info->a2dp_exist))
  1250. psTdmaByte4Modify = 0x1;
  1251. else
  1252. psTdmaByte4Modify = 0x0;
  1253. if (pre_psTdmaByte4Modify != psTdmaByte4Modify) {
  1254. force_exec = true;
  1255. pre_psTdmaByte4Modify = psTdmaByte4Modify;
  1256. }
  1257. if (!force_exec) {
  1258. if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) &&
  1259. (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma))
  1260. return;
  1261. }
  1262. if (coex_dm->cur_ps_tdma_on) {
  1263. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1264. "[BTCoex], ********** TDMA(on, %d) **********\n",
  1265. coex_dm->cur_ps_tdma);
  1266. BTC_TRACE(trace_buf);
  1267. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x550, 0x8,
  1268. 0x1); /* enable TBTT nterrupt */
  1269. } else {
  1270. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1271. "[BTCoex], ********** TDMA(off, %d) **********\n",
  1272. coex_dm->cur_ps_tdma);
  1273. BTC_TRACE(trace_buf);
  1274. }
  1275. if (turn_on) {
  1276. switch (type) {
  1277. case 1:
  1278. halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xe3,
  1279. 0x10, 0x03, 0xf1,
  1280. 0x54 | psTdmaByte4Modify);
  1281. break;
  1282. case 2:
  1283. default:
  1284. halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xe3,
  1285. 0x35, 0x03, 0x71,
  1286. 0x11 | psTdmaByte4Modify);
  1287. break;
  1288. case 3:
  1289. halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xe3,
  1290. 0x3a, 0x3, 0xf1,
  1291. 0x10 | psTdmaByte4Modify);
  1292. break;
  1293. case 4:
  1294. halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xe3,
  1295. 0x21, 0x3, 0xf1,
  1296. 0x10 | psTdmaByte4Modify);
  1297. break;
  1298. case 5:
  1299. halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xe3,
  1300. 0x25, 0x3, 0xf1,
  1301. 0x10 | psTdmaByte4Modify);
  1302. break;
  1303. case 6:
  1304. halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xe3,
  1305. 0x10, 0x3, 0xf1,
  1306. 0x10 | psTdmaByte4Modify);
  1307. break;
  1308. case 7:
  1309. halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xe3,
  1310. 0x20, 0x3, 0xf1,
  1311. 0x10 | psTdmaByte4Modify);
  1312. break;
  1313. case 11:
  1314. halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xe3,
  1315. 0x30, 0x03, 0x71,
  1316. 0x10 | psTdmaByte4Modify);
  1317. break;
  1318. case 12:
  1319. halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xe3,
  1320. 0x21, 0x03, 0x71,
  1321. 0x11 | psTdmaByte4Modify);
  1322. break;
  1323. case 13:
  1324. halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xe3,
  1325. 0x1c, 0x03, 0x71,
  1326. 0x10 | psTdmaByte4Modify);
  1327. break;
  1328. case 14:
  1329. halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xe3,
  1330. 0x30, 0x03, 0x71,
  1331. 0x11);
  1332. break;
  1333. case 51:
  1334. halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xe3,
  1335. 0x10, 0x03, 0xf1,
  1336. 0x10 | psTdmaByte4Modify);
  1337. break;
  1338. case 101:
  1339. halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xd3,
  1340. 0x10, 0x03, 0x70,
  1341. 0x54 | psTdmaByte4Modify);
  1342. break;
  1343. case 102:
  1344. halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xe3,
  1345. 0x35, 0x03, 0x71,
  1346. 0x11 | psTdmaByte4Modify);
  1347. break;
  1348. case 103:
  1349. halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xd3,
  1350. 0x3a, 0x3, 0x70,
  1351. 0x50 | psTdmaByte4Modify);
  1352. break;
  1353. case 104:
  1354. halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xd3,
  1355. 0x21, 0x3, 0x70,
  1356. 0x50 | psTdmaByte4Modify);
  1357. break;
  1358. case 105:
  1359. halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xd3,
  1360. 0x25, 0x3, 0x70,
  1361. 0x50 | psTdmaByte4Modify);
  1362. break;
  1363. case 106:
  1364. halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xd3,
  1365. 0x10, 0x3, 0x70,
  1366. 0x50 | psTdmaByte4Modify);
  1367. break;
  1368. case 107:
  1369. halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xd3,
  1370. 0x20, 0x3, 0x70,
  1371. 0x50 | psTdmaByte4Modify);
  1372. break;
  1373. case 151:
  1374. halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xd3,
  1375. 0x10, 0x03, 0x70,
  1376. 0x50 | psTdmaByte4Modify);
  1377. break;
  1378. }
  1379. } else {
  1380. /* disable PS tdma */
  1381. switch (type) {
  1382. case 0:
  1383. halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x0,
  1384. 0x0, 0x0, 0x40, 0x0);
  1385. break;
  1386. case 1:
  1387. halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x0,
  1388. 0x0, 0x0, 0x48, 0x0);
  1389. break;
  1390. default:
  1391. halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x0,
  1392. 0x0, 0x0, 0x40, 0x0);
  1393. break;
  1394. }
  1395. }
  1396. /* update pre state */
  1397. coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on;
  1398. coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma;
  1399. }
  1400. void halbtc8822b2ant_set_ext_band_switch(IN struct btc_coexist *btcoexist,
  1401. IN boolean force_exec, IN u8 pos_type)
  1402. {
  1403. #if 0
  1404. boolean switch_polatiry_inverse = false;
  1405. u8 regval_0xcb6;
  1406. u32 u32tmp1 = 0, u32tmp2 = 0;
  1407. if (!rfe_type->ext_band_switch_exist)
  1408. return;
  1409. coex_dm->cur_ext_band_switch_status = pos_type;
  1410. if (!force_exec) {
  1411. if (coex_dm->pre_ext_band_switch_status ==
  1412. coex_dm->cur_ext_band_switch_status)
  1413. return;
  1414. }
  1415. coex_dm->pre_ext_band_switch_status =
  1416. coex_dm->cur_ext_band_switch_status;
  1417. /* swap control polarity if use different switch control polarity*/
  1418. switch_polatiry_inverse = (rfe_type->ext_band_switch_ctrl_polarity == 1
  1419. ? ~switch_polatiry_inverse : switch_polatiry_inverse);
  1420. /*swap control polarity for WL_A, default polarity 0xcb4[21] = 0 && 0xcb4[23] = 1 is for WL_G */
  1421. switch_polatiry_inverse = (pos_type ==
  1422. BT_8822B_2ANT_EXT_BAND_SWITCH_TO_WLA ? ~switch_polatiry_inverse
  1423. : switch_polatiry_inverse);
  1424. regval_0xcb6 = btcoexist->btc_read_1byte(btcoexist, 0xcb6);
  1425. /* for normal switch polrity, 0xcb4[21] =1 && 0xcb4[23] = 0 for WL_A, vice versa */
  1426. regval_0xcb6 = (switch_polatiry_inverse == 1 ? ((regval_0xcb6 & (~(BIT(
  1427. 7)))) | BIT(5)) : ((regval_0xcb6 & (~(BIT(5)))) | BIT(7)));
  1428. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb6, 0xff,
  1429. regval_0xcb6);
  1430. u32tmp1 = btcoexist->btc_read_4byte(btcoexist, 0xcb0);
  1431. u32tmp2 = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
  1432. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1433. "[BTCoex], ********** (After Ext Band switch setup) 0xcb0 = 0x%08x, 0xcb4 = 0x%08x**********\n",
  1434. u32tmp1, u32tmp2);
  1435. BTC_TRACE(trace_buf);
  1436. #endif
  1437. }
  1438. /*anttenna control by bb mac bt antdiv pta to write 0x4c 0xcb4,0xcbd*/
  1439. void halbtc8822b2ant_set_ext_ant_switch(IN struct btc_coexist *btcoexist,
  1440. IN boolean force_exec, IN u8 ctrl_type, IN u8 pos_type)
  1441. {
  1442. struct btc_board_info *board_info = &btcoexist->board_info;
  1443. boolean switch_polatiry_inverse = false;
  1444. u8 regval_0xcbc = 0, regval_0x64;
  1445. u32 u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0;
  1446. if (!rfe_type->ext_ant_switch_exist)
  1447. return;
  1448. coex_dm->cur_ext_ant_switch_status = (ctrl_type << 8) + pos_type;
  1449. if (!force_exec) {
  1450. if (coex_dm->pre_ext_ant_switch_status ==
  1451. coex_dm->cur_ext_ant_switch_status)
  1452. return;
  1453. }
  1454. coex_dm->pre_ext_ant_switch_status = coex_dm->cur_ext_ant_switch_status;
  1455. /*
  1456. switch (pos_type) {
  1457. default:
  1458. case BT_8822B_2ANT_EXT_ANT_SWITCH_MAIN_TO_BT:
  1459. case BT_8822B_2ANT_EXT_ANT_SWITCH_MAIN_TO_NOCARE:
  1460. break;
  1461. case BT_8822B_2ANT_EXT_ANT_SWITCH_MAIN_TO_WLG:
  1462. break;
  1463. case BT_8822B_2ANT_EXT_ANT_SWITCH_MAIN_TO_WLA:
  1464. break;
  1465. }
  1466. */
  1467. if (board_info->ant_div_cfg)
  1468. /*ctrl_type = BT_8822B_2ANT_EXT_ANT_SWITCH_CTRL_BY_ANTDIV;*/
  1469. /* Ext switch buffer mux */
  1470. btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff);
  1471. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991, 0x3, 0x0);
  1472. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe, 0x8, 0x0);
  1473. switch (ctrl_type) {
  1474. default:
  1475. case BT_8822B_2ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW:
  1476. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e,
  1477. 0x80, 0x0); /* 0x4c[23] = 0 */
  1478. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f,
  1479. 0x01, 0x1); /* 0x4c[24] = 1 */
  1480. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb4,
  1481. 0xff, 0x77); /* BB SW, DPDT use RFE_ctrl8 and RFE_ctrl9 as conctrol pin */
  1482. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd,
  1483. 0x03, 01);
  1484. break;
  1485. case BT_8822B_2ANT_EXT_ANT_SWITCH_CTRL_BY_PTA:
  1486. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e,
  1487. 0x80, 0x0); /* 0x4c[23] = 0 */
  1488. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f,
  1489. 0x01, 0x1); /* 0x4c[24] = 1 */
  1490. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb4,
  1491. 0xff, 0x66); /* PTA, DPDT use RFE_ctrl8 and RFE_ctrl9 as conctrol pin */
  1492. regval_0xcbc = (switch_polatiry_inverse == false ?
  1493. 0x2 : 0x1); /* 0xcb4[29:28] = 2b'10 for no switch_polatiry_inverse, DPDT_SEL_N =1, DPDT_SEL_P =0 @ GNT_BT=1 */
  1494. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbc,
  1495. 0x03, regval_0xcbc);
  1496. break;
  1497. case BT_8822B_2ANT_EXT_ANT_SWITCH_CTRL_BY_ANTDIV:
  1498. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e,
  1499. 0x80, 0x0); /* 0x4c[23] = 0 */
  1500. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f,
  1501. 0x01, 0x1);/* 0x4c[24] = 1 */
  1502. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb4, 0xff, 0x88);
  1503. break;
  1504. case BT_8822B_2ANT_EXT_ANT_SWITCH_CTRL_BY_MAC:
  1505. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e,
  1506. 0x80, 0x1); /* 0x4c[23] = 1 */
  1507. regval_0x64 = (switch_polatiry_inverse == false ? 0x0 :
  1508. 0x1); /* 0x64[0] = 1b'0 for no switch_polatiry_inverse, DPDT_SEL_N =1, DPDT_SEL_P =0 */
  1509. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x64, 0x1,
  1510. regval_0x64);
  1511. break;
  1512. case BT_8822B_2ANT_EXT_ANT_SWITCH_CTRL_BY_BT:
  1513. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e,
  1514. 0x80, 0x0); /* 0x4c[23] = 0 */
  1515. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f,
  1516. 0x01, 0x0); /* 0x4c[24] = 0 */
  1517. /* no setup required, because antenna switch control value by BT vendor 0x1c[1:0] */
  1518. break;
  1519. }
  1520. /* PAPE, LNA_ON control by BT while WLAN off for current leakage issue */
  1521. if (ctrl_type == BT_8822B_2ANT_EXT_ANT_SWITCH_CTRL_BY_BT) {
  1522. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x20,
  1523. 0x0); /* PAPE 0x64[29] = 0 */
  1524. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x10,
  1525. 0x0); /* LNA_ON 0x64[28] = 0 */
  1526. } else {
  1527. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x20,
  1528. 0x1); /* PAPE 0x64[29] = 1 */
  1529. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x10,
  1530. 0x1); /* LNA_ON 0x64[28] = 1 */
  1531. }
  1532. #if BT_8822B_2ANT_COEX_DBG
  1533. u32tmp1 = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
  1534. u32tmp2 = btcoexist->btc_read_4byte(btcoexist, 0x4c);
  1535. u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0x64) & 0xff;
  1536. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1537. "[BTCoex], (After Ext Ant switch setup) 0xcb4 = 0x%08x, 0x4c = 0x%08x, 0x64= 0x%02x\n",
  1538. u32tmp1, u32tmp2, u32tmp3);
  1539. BTC_TRACE(trace_buf);
  1540. #endif
  1541. }
  1542. /*rf4 type by efuse , and for ant at main aux inverse use , because is 2x2 ,and control types are the same ,does not need */
  1543. void halbtc8822b2ant_set_rfe_type(IN struct btc_coexist *btcoexist)
  1544. {
  1545. struct btc_board_info *board_info = &btcoexist->board_info;
  1546. rfe_type->ext_band_switch_exist = false;
  1547. rfe_type->ext_band_switch_type =
  1548. BT_8822B_2ANT_EXT_BAND_SWITCH_USE_SPDT; /* SPDT; */
  1549. rfe_type->ext_band_switch_ctrl_polarity = 0;
  1550. /* Ext switch buffer mux */
  1551. btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff);
  1552. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991, 0x3, 0x0);
  1553. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe, 0x8, 0x0);
  1554. if (rfe_type->ext_band_switch_exist) {
  1555. /* band switch use RFE_ctrl1 (pin name: PAPE_A) and RFE_ctrl3 (pin name: LNAON_A) */
  1556. /* set RFE_ctrl1 as software control */
  1557. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb0, 0xf0, 0x7);
  1558. /* set RFE_ctrl3 as software control */
  1559. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb1, 0xf0, 0x7);
  1560. }
  1561. /* the following setup should be got from Efuse in the future */
  1562. rfe_type->rfe_module_type = board_info->rfe_type;
  1563. rfe_type->ext_ant_switch_ctrl_polarity = 0;
  1564. switch (rfe_type->rfe_module_type) {
  1565. case 0:
  1566. default:
  1567. rfe_type->ext_ant_switch_exist = true;
  1568. rfe_type->ext_ant_switch_type = BT_8822B_2ANT_EXT_ANT_SWITCH_USE_SPDT;
  1569. break;
  1570. case 1:
  1571. rfe_type->ext_ant_switch_exist = true;
  1572. rfe_type->ext_ant_switch_type = BT_8822B_2ANT_EXT_ANT_SWITCH_USE_SPDT;
  1573. break;
  1574. case 2:
  1575. rfe_type->ext_ant_switch_exist = true;
  1576. rfe_type->ext_ant_switch_type = BT_8822B_2ANT_EXT_ANT_SWITCH_USE_SPDT;
  1577. break;
  1578. case 3:
  1579. rfe_type->ext_ant_switch_exist = true;
  1580. rfe_type->ext_ant_switch_type = BT_8822B_2ANT_EXT_ANT_SWITCH_USE_SPDT;
  1581. break;
  1582. case 4:
  1583. rfe_type->ext_ant_switch_exist = true;
  1584. rfe_type->ext_ant_switch_type =
  1585. BT_8822B_2ANT_EXT_ANT_SWITCH_USE_SPDT;
  1586. break;
  1587. case 5:
  1588. rfe_type->ext_ant_switch_exist = true;
  1589. rfe_type->ext_ant_switch_type = BT_8822B_2ANT_EXT_ANT_SWITCH_USE_SPDT;
  1590. break;
  1591. case 6:
  1592. rfe_type->ext_ant_switch_exist = true;
  1593. rfe_type->ext_ant_switch_type = BT_8822B_2ANT_EXT_ANT_SWITCH_USE_SPDT;
  1594. break;
  1595. case 7:
  1596. rfe_type->ext_ant_switch_exist = true;
  1597. rfe_type->ext_ant_switch_type = BT_8822B_2ANT_EXT_ANT_SWITCH_USE_SPDT;
  1598. break;
  1599. }
  1600. #if 0
  1601. if (rfe_type->wlg_Locate_at_btg)
  1602. halbtc8822b2ant_set_int_block(btcoexist, FORCE_EXEC,
  1603. BT_8822B_2ANT_INT_BLOCK_SWITCH_TO_WLG_OF_BTG);
  1604. else
  1605. halbtc8822b2ant_set_int_block(btcoexist, FORCE_EXEC,
  1606. BT_8822B_2ANT_INT_BLOCK_SWITCH_TO_WLG_OF_WLAG);
  1607. #endif
  1608. }
  1609. /*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*/
  1610. void halbtc8822b2ant_set_ant_path(IN struct btc_coexist *btcoexist,
  1611. IN u8 ant_pos_type, IN boolean force_exec,
  1612. IN u8 phase)
  1613. {
  1614. struct btc_board_info *board_info = &btcoexist->board_info;
  1615. u32 cnt_bt_cal_chk = 0;
  1616. boolean is_in_mp_mode = false;
  1617. u8 u8tmp = 0;
  1618. u32 u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0;
  1619. u16 u16tmp1 = 0;
  1620. /* Ext switch buffer mux */
  1621. btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff);
  1622. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991, 0x3, 0x0);
  1623. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe, 0x8, 0x0);
  1624. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e,
  1625. 0x80, 0x0); /* 0x4c[23] = 0 */
  1626. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f,
  1627. 0x01, 0x1); /* 0x4c[24] = 1 */
  1628. coex_dm->cur_ant_pos_type = (ant_pos_type << 8) + phase;
  1629. if (!force_exec) {
  1630. if (coex_dm->cur_ant_pos_type == coex_dm->pre_ant_pos_type)
  1631. return;
  1632. }
  1633. coex_dm->pre_ant_pos_type = coex_dm->cur_ant_pos_type;
  1634. #if BT_8822B_2ANT_COEX_DBG
  1635. u32tmp1 = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist,
  1636. 0x38);
  1637. u32tmp2 = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist,
  1638. 0x54);
  1639. u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x73);
  1640. u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
  1641. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1642. "[BTCoex], (Before Ant Setup) 0xcb4 = 0x%x, 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x\n",
  1643. u32tmp3, u8tmp, u32tmp1, u32tmp2);
  1644. BTC_TRACE(trace_buf);
  1645. #endif
  1646. switch (phase) {
  1647. case BT_8822B_2ANT_PHASE_COEX_POWERON:
  1648. /* set Path control owner to WL at initial step */
  1649. halbtc8822b2ant_ltecoex_pathcontrol_owner(btcoexist,
  1650. BT_8822B_2ANT_PCO_BTSIDE);
  1651. /* set GNT_BT to SW high */
  1652. halbtc8822b2ant_ltecoex_set_gnt_bt(btcoexist,
  1653. BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
  1654. BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
  1655. BT_8822B_2ANT_SIG_STA_SET_TO_HIGH);
  1656. /* Set GNT_WL to SW high */
  1657. halbtc8822b2ant_ltecoex_set_gnt_wl(btcoexist,
  1658. BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
  1659. BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
  1660. BT_8822B_2ANT_SIG_STA_SET_TO_HIGH);
  1661. coex_sta->run_time_state = false;
  1662. break;
  1663. case BT_8822B_2ANT_PHASE_COEX_INIT:
  1664. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e,
  1665. 0x80, 0x0); /* 0x4c[23] = 0 */
  1666. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f,
  1667. 0x01, 0x1); /* 0x4c[24] = 1 */
  1668. /* Disable LTE Coex Function in WiFi side (this should be on if LTE coex is required) */
  1669. halbtc8822b2ant_ltecoex_enable(btcoexist, 0x0);
  1670. /* GNT_WL_LTE always = 1 (this should be config if LTE coex is required) */
  1671. halbtc8822b2ant_ltecoex_set_coex_table(
  1672. btcoexist,
  1673. BT_8822B_2ANT_CTT_WL_VS_LTE,
  1674. 0xffff);
  1675. /* GNT_BT_LTE always = 1 (this should be config if LTE coex is required) */
  1676. halbtc8822b2ant_ltecoex_set_coex_table(
  1677. btcoexist,
  1678. BT_8822B_2ANT_CTT_BT_VS_LTE,
  1679. 0xffff);
  1680. /* set Path control owner to WL at initial step */
  1681. halbtc8822b2ant_ltecoex_pathcontrol_owner(
  1682. btcoexist,
  1683. BT_8822B_2ANT_PCO_WLSIDE);
  1684. /* set GNT_BT to SW high */
  1685. halbtc8822b2ant_ltecoex_set_gnt_bt(btcoexist,
  1686. BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
  1687. BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
  1688. BT_8822B_2ANT_SIG_STA_SET_TO_HIGH);
  1689. /* Set GNT_WL to SW high */
  1690. halbtc8822b2ant_ltecoex_set_gnt_wl(btcoexist,
  1691. BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
  1692. BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
  1693. BT_8822B_2ANT_SIG_STA_SET_TO_HIGH);
  1694. coex_sta->run_time_state = false;
  1695. break;
  1696. case BT_8822B_2ANT_PHASE_WLANONLY_INIT:
  1697. /* Disable LTE Coex Function in WiFi side (this should be on if LTE coex is required) */
  1698. halbtc8822b2ant_ltecoex_enable(btcoexist, 0x0);
  1699. /* GNT_WL_LTE always = 1 (this should be config if LTE coex is required) */
  1700. halbtc8822b2ant_ltecoex_set_coex_table(
  1701. btcoexist,
  1702. BT_8822B_2ANT_CTT_WL_VS_LTE,
  1703. 0xffff);
  1704. /* GNT_BT_LTE always = 1 (this should be config if LTE coex is required) */
  1705. halbtc8822b2ant_ltecoex_set_coex_table(
  1706. btcoexist,
  1707. BT_8822B_2ANT_CTT_BT_VS_LTE,
  1708. 0xffff);
  1709. /* set Path control owner to WL at initial step */
  1710. halbtc8822b2ant_ltecoex_pathcontrol_owner(
  1711. btcoexist,
  1712. BT_8822B_2ANT_PCO_WLSIDE);
  1713. /* set GNT_BT to SW Low */
  1714. halbtc8822b2ant_ltecoex_set_gnt_bt(btcoexist,
  1715. BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
  1716. BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
  1717. BT_8822B_2ANT_SIG_STA_SET_TO_LOW);
  1718. /* Set GNT_WL to SW high */
  1719. halbtc8822b2ant_ltecoex_set_gnt_wl(btcoexist,
  1720. BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
  1721. BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
  1722. BT_8822B_2ANT_SIG_STA_SET_TO_HIGH);
  1723. coex_sta->run_time_state = false;
  1724. break;
  1725. case BT_8822B_2ANT_PHASE_WLAN_OFF:
  1726. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e,
  1727. 0x80, 0x0); /* 0x4c[23] = 0 */
  1728. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f,
  1729. 0x01, 0x0); /* 0x4c[24] = 0 */
  1730. /* Disable LTE Coex Function in WiFi side */
  1731. halbtc8822b2ant_ltecoex_enable(btcoexist, 0x0);
  1732. /* set Path control owner to BT */
  1733. halbtc8822b2ant_ltecoex_pathcontrol_owner(
  1734. btcoexist,
  1735. BT_8822B_2ANT_PCO_BTSIDE);
  1736. /* Set Ext Ant Switch to BT control at wifi off step */
  1737. halbtc8822b2ant_set_ext_ant_switch(btcoexist,
  1738. FORCE_EXEC,
  1739. BT_8822B_2ANT_EXT_ANT_SWITCH_CTRL_BY_BT,
  1740. BT_8822B_2ANT_EXT_ANT_SWITCH_MAIN_TO_NOCARE);
  1741. coex_sta->run_time_state = false;
  1742. break;
  1743. case BT_8822B_2ANT_PHASE_2G_RUNTIME:
  1744. case BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT:
  1745. /* set Path control owner to WL at runtime step */
  1746. halbtc8822b2ant_ltecoex_pathcontrol_owner(
  1747. btcoexist,
  1748. BT_8822B_2ANT_PCO_WLSIDE);
  1749. if (phase ==
  1750. BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT) {
  1751. /* set GNT_BT to PTA */
  1752. halbtc8822b2ant_ltecoex_set_gnt_bt(
  1753. btcoexist,
  1754. BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
  1755. BT_8822B_2ANT_GNT_TYPE_CTRL_BY_PTA,
  1756. BT_8822B_2ANT_SIG_STA_SET_BY_HW);
  1757. /* Set GNT_WL to SW High */
  1758. halbtc8822b2ant_ltecoex_set_gnt_wl(
  1759. btcoexist,
  1760. BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
  1761. BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
  1762. BT_8822B_2ANT_SIG_STA_SET_TO_HIGH);
  1763. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1764. "[BTCoex], ************* under2g 0xcbd setting =2 *************\n");
  1765. BTC_TRACE(trace_buf);
  1766. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd,
  1767. 0x03, 02);
  1768. } else {
  1769. /* set GNT_BT to PTA */
  1770. halbtc8822b2ant_ltecoex_set_gnt_bt(
  1771. btcoexist,
  1772. BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
  1773. BT_8822B_2ANT_GNT_TYPE_CTRL_BY_PTA,
  1774. BT_8822B_2ANT_SIG_STA_SET_BY_HW);
  1775. /* Set GNT_WL to PTA */
  1776. halbtc8822b2ant_ltecoex_set_gnt_wl(
  1777. btcoexist,
  1778. BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
  1779. BT_8822B_2ANT_GNT_TYPE_CTRL_BY_PTA,
  1780. BT_8822B_2ANT_SIG_STA_SET_BY_HW);
  1781. }
  1782. coex_sta->run_time_state = true;
  1783. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1784. "[BTCoex], ************* under2g 0xcbd setting =2 *************\n");
  1785. BTC_TRACE(trace_buf);
  1786. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd, 0x03, 02);
  1787. break;
  1788. case BT_8822B_2ANT_PHASE_5G_RUNTIME:
  1789. /* set Path control owner to WL at runtime step */
  1790. halbtc8822b2ant_ltecoex_pathcontrol_owner(
  1791. btcoexist,
  1792. BT_8822B_2ANT_PCO_WLSIDE);
  1793. /* set GNT_BT to SW Hi */
  1794. halbtc8822b2ant_ltecoex_set_gnt_bt(btcoexist,
  1795. BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
  1796. BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
  1797. BT_8822B_2ANT_SIG_STA_SET_TO_HIGH);
  1798. /* Set GNT_WL to SW Hi */
  1799. halbtc8822b2ant_ltecoex_set_gnt_wl(btcoexist,
  1800. BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
  1801. BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
  1802. BT_8822B_2ANT_SIG_STA_SET_TO_HIGH);
  1803. coex_sta->run_time_state = true;
  1804. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1805. "[BTCoex], ************* under5g 0xcbd setting =1 *************\n");
  1806. BTC_TRACE(trace_buf);
  1807. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd,
  1808. 0x03, 01);
  1809. break;
  1810. case BT_8822B_2ANT_PHASE_BTMPMODE:
  1811. /* Disable LTE Coex Function in WiFi side */
  1812. halbtc8822b2ant_ltecoex_enable(btcoexist, 0x0);
  1813. /* set Path control owner to WL */
  1814. halbtc8822b2ant_ltecoex_pathcontrol_owner(
  1815. btcoexist,
  1816. BT_8822B_2ANT_PCO_WLSIDE);
  1817. /* set GNT_BT to SW Hi */
  1818. halbtc8822b2ant_ltecoex_set_gnt_bt(btcoexist,
  1819. BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
  1820. BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
  1821. BT_8822B_2ANT_SIG_STA_SET_TO_HIGH);
  1822. /* Set GNT_WL to SW Lo */
  1823. halbtc8822b2ant_ltecoex_set_gnt_wl(btcoexist,
  1824. BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
  1825. BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
  1826. BT_8822B_2ANT_SIG_STA_SET_TO_LOW);
  1827. coex_sta->run_time_state = false;
  1828. break;
  1829. }
  1830. #if BT_8822B_2ANT_COEX_DBG
  1831. u32tmp1 = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, 0x38);
  1832. u32tmp2 = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, 0x54);
  1833. u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
  1834. u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x73);
  1835. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1836. "[BTCoex], (After Ant-Setup phase---%d) 0xcb4 = 0x%x, 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x\n",
  1837. phase, u32tmp3, u8tmp, u32tmp1, u32tmp2);
  1838. BTC_TRACE(trace_buf);
  1839. #endif
  1840. }
  1841. u8 halbtc8822b2ant_action_algorithm(IN struct btc_coexist *btcoexist)
  1842. {
  1843. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1844. boolean bt_hs_on = false;
  1845. u8 algorithm = BT_8822B_2ANT_COEX_ALGO_UNDEFINED;
  1846. u8 num_of_diff_profile = 0;
  1847. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  1848. if (!bt_link_info->bt_link_exist) {
  1849. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1850. "[BTCoex], No BT link exists!!!\n");
  1851. BTC_TRACE(trace_buf);
  1852. return algorithm;
  1853. }
  1854. if (bt_link_info->sco_exist)
  1855. num_of_diff_profile++;
  1856. if (bt_link_info->hid_exist)
  1857. num_of_diff_profile++;
  1858. if (bt_link_info->pan_exist)
  1859. num_of_diff_profile++;
  1860. if (bt_link_info->a2dp_exist)
  1861. num_of_diff_profile++;
  1862. if (num_of_diff_profile == 0) {
  1863. if (bt_link_info->acl_busy) {
  1864. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1865. "[BTCoex], No-Profile busy\n");
  1866. BTC_TRACE(trace_buf);
  1867. algorithm = BT_8822B_2ANT_COEX_ALGO_NOPROFILEBUSY;
  1868. }
  1869. } else if (num_of_diff_profile == 1) {
  1870. if (bt_link_info->sco_exist) {
  1871. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1872. "[BTCoex], SCO only\n");
  1873. BTC_TRACE(trace_buf);
  1874. algorithm = BT_8822B_2ANT_COEX_ALGO_SCO;
  1875. } else {
  1876. if (bt_link_info->hid_exist) {
  1877. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1878. "[BTCoex], HID only\n");
  1879. BTC_TRACE(trace_buf);
  1880. algorithm = BT_8822B_2ANT_COEX_ALGO_HID;
  1881. } else if (bt_link_info->a2dp_exist) {
  1882. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1883. "[BTCoex], A2DP only\n");
  1884. BTC_TRACE(trace_buf);
  1885. algorithm = BT_8822B_2ANT_COEX_ALGO_A2DP;
  1886. } else if (bt_link_info->pan_exist) {
  1887. if (bt_hs_on) {
  1888. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1889. "[BTCoex], PAN(HS) only\n");
  1890. BTC_TRACE(trace_buf);
  1891. algorithm =
  1892. BT_8822B_2ANT_COEX_ALGO_PANHS;
  1893. } else {
  1894. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1895. "[BTCoex], PAN(EDR) only\n");
  1896. BTC_TRACE(trace_buf);
  1897. algorithm =
  1898. BT_8822B_2ANT_COEX_ALGO_PANEDR;
  1899. }
  1900. }
  1901. }
  1902. } else if (num_of_diff_profile == 2) {
  1903. if (bt_link_info->sco_exist) {
  1904. if (bt_link_info->hid_exist) {
  1905. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1906. "[BTCoex], SCO + HID\n");
  1907. BTC_TRACE(trace_buf);
  1908. algorithm = BT_8822B_2ANT_COEX_ALGO_SCO;
  1909. } else if (bt_link_info->a2dp_exist) {
  1910. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1911. "[BTCoex], SCO + A2DP ==> A2DP\n");
  1912. BTC_TRACE(trace_buf);
  1913. algorithm = BT_8822B_2ANT_COEX_ALGO_A2DP;
  1914. } else if (bt_link_info->pan_exist) {
  1915. if (bt_hs_on) {
  1916. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1917. "[BTCoex], SCO + PAN(HS)\n");
  1918. BTC_TRACE(trace_buf);
  1919. algorithm = BT_8822B_2ANT_COEX_ALGO_SCO;
  1920. } else {
  1921. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1922. "[BTCoex], SCO + PAN(EDR)\n");
  1923. BTC_TRACE(trace_buf);
  1924. algorithm =
  1925. BT_8822B_2ANT_COEX_ALGO_PANEDR;
  1926. }
  1927. }
  1928. } else {
  1929. if (bt_link_info->hid_exist &&
  1930. bt_link_info->a2dp_exist) {
  1931. {
  1932. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1933. "[BTCoex], HID + A2DP\n");
  1934. BTC_TRACE(trace_buf);
  1935. algorithm =
  1936. BT_8822B_2ANT_COEX_ALGO_HID_A2DP;
  1937. }
  1938. } else if (bt_link_info->hid_exist &&
  1939. bt_link_info->pan_exist) {
  1940. if (bt_hs_on) {
  1941. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1942. "[BTCoex], HID + PAN(HS)\n");
  1943. BTC_TRACE(trace_buf);
  1944. algorithm = BT_8822B_2ANT_COEX_ALGO_HID;
  1945. } else {
  1946. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1947. "[BTCoex], HID + PAN(EDR)\n");
  1948. BTC_TRACE(trace_buf);
  1949. algorithm =
  1950. BT_8822B_2ANT_COEX_ALGO_PANEDR_HID;
  1951. }
  1952. } else if (bt_link_info->pan_exist &&
  1953. bt_link_info->a2dp_exist) {
  1954. if (bt_hs_on) {
  1955. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1956. "[BTCoex], A2DP + PAN(HS)\n");
  1957. BTC_TRACE(trace_buf);
  1958. algorithm =
  1959. BT_8822B_2ANT_COEX_ALGO_A2DP_PANHS;
  1960. } else {
  1961. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1962. "[BTCoex], A2DP + PAN(EDR)\n");
  1963. BTC_TRACE(trace_buf);
  1964. algorithm =
  1965. BT_8822B_2ANT_COEX_ALGO_PANEDR_A2DP;
  1966. }
  1967. }
  1968. }
  1969. } else if (num_of_diff_profile == 3) {
  1970. if (bt_link_info->sco_exist) {
  1971. if (bt_link_info->hid_exist &&
  1972. bt_link_info->a2dp_exist) {
  1973. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1974. "[BTCoex], SCO + HID + A2DP ==> HID + A2DP\n");
  1975. BTC_TRACE(trace_buf);
  1976. algorithm = BT_8822B_2ANT_COEX_ALGO_HID_A2DP;
  1977. } else if (bt_link_info->hid_exist &&
  1978. bt_link_info->pan_exist) {
  1979. if (bt_hs_on) {
  1980. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1981. "[BTCoex], SCO + HID + PAN(HS)\n");
  1982. BTC_TRACE(trace_buf);
  1983. algorithm =
  1984. BT_8822B_2ANT_COEX_ALGO_PANEDR_HID;
  1985. } else {
  1986. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1987. "[BTCoex], SCO + HID + PAN(EDR)\n");
  1988. BTC_TRACE(trace_buf);
  1989. algorithm =
  1990. BT_8822B_2ANT_COEX_ALGO_PANEDR_HID;
  1991. }
  1992. } else if (bt_link_info->pan_exist &&
  1993. bt_link_info->a2dp_exist) {
  1994. if (bt_hs_on) {
  1995. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1996. "[BTCoex], SCO + A2DP + PAN(HS)\n");
  1997. BTC_TRACE(trace_buf);
  1998. algorithm =
  1999. BT_8822B_2ANT_COEX_ALGO_PANEDR_A2DP;
  2000. } else {
  2001. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2002. "[BTCoex], SCO + A2DP + PAN(EDR) ==> HID\n");
  2003. BTC_TRACE(trace_buf);
  2004. algorithm =
  2005. BT_8822B_2ANT_COEX_ALGO_PANEDR_A2DP;
  2006. }
  2007. }
  2008. } else {
  2009. if (bt_link_info->hid_exist &&
  2010. bt_link_info->pan_exist &&
  2011. bt_link_info->a2dp_exist) {
  2012. if (bt_hs_on) {
  2013. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2014. "[BTCoex], HID + A2DP + PAN(HS)\n");
  2015. BTC_TRACE(trace_buf);
  2016. algorithm =
  2017. BT_8822B_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
  2018. } else {
  2019. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2020. "[BTCoex], HID + A2DP + PAN(EDR)\n");
  2021. BTC_TRACE(trace_buf);
  2022. algorithm =
  2023. BT_8822B_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
  2024. }
  2025. }
  2026. }
  2027. } else if (num_of_diff_profile >= 3) {
  2028. if (bt_link_info->sco_exist) {
  2029. if (bt_link_info->hid_exist &&
  2030. bt_link_info->pan_exist &&
  2031. bt_link_info->a2dp_exist) {
  2032. if (bt_hs_on) {
  2033. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2034. "[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n");
  2035. BTC_TRACE(trace_buf);
  2036. algorithm =
  2037. BT_8822B_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
  2038. } else {
  2039. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2040. "[BTCoex], SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n");
  2041. BTC_TRACE(trace_buf);
  2042. algorithm =
  2043. BT_8822B_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
  2044. }
  2045. }
  2046. }
  2047. }
  2048. return algorithm;
  2049. }
  2050. void halbtc8822b2ant_action_coex_all_off(IN struct btc_coexist *btcoexist)
  2051. {
  2052. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  2053. halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC,
  2054. BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT);
  2055. /* fw all off */
  2056. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  2057. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
  2058. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2059. }
  2060. void halbtc8822b2ant_action_wifi_under5g(IN struct btc_coexist *btcoexist)
  2061. {
  2062. /* fw all off */
  2063. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2064. "[BTCoex], ************* under5g *************\n");
  2065. BTC_TRACE(trace_buf);
  2066. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  2067. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  2068. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
  2069. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2070. halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC,
  2071. BT_8822B_2ANT_PHASE_5G_RUNTIME);
  2072. }
  2073. void halbtc8822b2ant_action_bt_inquiry(IN struct btc_coexist *btcoexist)
  2074. {
  2075. boolean wifi_connected = false;
  2076. boolean scan = false, link = false, roam = false;
  2077. boolean wifi_busy = false;
  2078. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  2079. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  2080. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  2081. &wifi_connected);
  2082. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
  2083. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
  2084. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
  2085. if (link || roam || coex_sta->wifi_is_high_pri_task) {
  2086. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2087. "[BTCoex], Wifi link/roam/hi-pri-task process + BT Inq/Page!!\n");
  2088. BTC_TRACE(trace_buf);
  2089. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
  2090. 8);
  2091. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 11);
  2092. } else if (scan) {
  2093. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2094. "[BTCoex], Wifi scan process + BT Inq/Page!!\n");
  2095. BTC_TRACE(trace_buf);
  2096. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
  2097. 8);
  2098. if (coex_sta->bt_create_connection)
  2099. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2100. 12);
  2101. else
  2102. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2103. 11);
  2104. } else if (wifi_connected) {
  2105. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2106. "[BTCoex], Wifi connected + BT Inq/Page!!\n");
  2107. BTC_TRACE(trace_buf);
  2108. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
  2109. 8);
  2110. if (wifi_busy) {
  2111. if ((bt_link_info->a2dp_exist) &&
  2112. (bt_link_info->acl_busy))
  2113. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2114. true, 13);
  2115. else
  2116. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2117. true, 11);
  2118. } else
  2119. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2120. 13);
  2121. } else {
  2122. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2123. "[BTCoex], Wifi no-link + BT Inq/Page!!\n");
  2124. BTC_TRACE(trace_buf);
  2125. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  2126. halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
  2127. NORMAL_EXEC,
  2128. BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT);
  2129. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  2130. }
  2131. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 0xd8);
  2132. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2133. }
  2134. void halbtc8822b2ant_action_wifi_link_process(IN struct btc_coexist *btcoexist)
  2135. {
  2136. u32 u32tmp, u32tmpb;
  2137. u8 u8tmpa;
  2138. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  2139. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 0xd8);
  2140. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2141. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
  2142. if ((bt_link_info->a2dp_exist) && (bt_link_info->acl_busy))
  2143. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14);
  2144. else
  2145. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 11);
  2146. }
  2147. void halbtc8822b2ant_action_wifi_nonconnected(IN struct btc_coexist *btcoexist)
  2148. {
  2149. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  2150. halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC,
  2151. BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT);
  2152. /* fw all off */
  2153. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  2154. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
  2155. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2156. }
  2157. void halbtc8822b2ant_action_bt_idle(IN struct btc_coexist *btcoexist)
  2158. {
  2159. static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW;
  2160. static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW;
  2161. u8 wifi_rssi_state, bt_rssi_state;
  2162. static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW;
  2163. static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW;
  2164. u8 wifi_rssi_state2, bt_rssi_state2;
  2165. boolean wifi_connected = false;
  2166. boolean scan = false, link = false, roam = false;
  2167. boolean wifi_busy = false;
  2168. wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(btcoexist,
  2169. &prewifi_rssi_state, 2,
  2170. coex_sta->wifi_coex_thres , 0);
  2171. wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(btcoexist,
  2172. &prewifi_rssi_state2, 2,
  2173. coex_sta->wifi_coex_thres2 , 0);
  2174. bt_rssi_state = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state, 2,
  2175. coex_sta->bt_coex_thres , 0);
  2176. bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state2, 2,
  2177. coex_sta->bt_coex_thres2 , 0);
  2178. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  2179. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  2180. &wifi_connected);
  2181. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
  2182. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
  2183. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
  2184. if (scan || link || roam) {
  2185. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2186. "[BTCoex], Wifi link process + BT Idle!!\n");
  2187. BTC_TRACE(trace_buf);
  2188. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
  2189. 7);
  2190. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 11);
  2191. } else if (wifi_connected) {
  2192. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2193. "[BTCoex], Wifi connected + BT Idle!!\n");
  2194. BTC_TRACE(trace_buf);
  2195. if (wifi_busy) {
  2196. halbtc8822b2ant_coex_table_with_type(btcoexist,
  2197. NORMAL_EXEC, 0);
  2198. halbtc8822b2ant_set_ant_path(btcoexist,
  2199. BTC_ANT_PATH_AUTO, NORMAL_EXEC,
  2200. BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT);
  2201. /*
  2202. if (!BTC_RSSI_HIGH(bt_rssi_state2))
  2203. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  2204. else {
  2205. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  2206. halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC,
  2207. BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT);
  2208. }
  2209. */
  2210. } else {
  2211. halbtc8822b2ant_coex_table_with_type(btcoexist,
  2212. NORMAL_EXEC, 0);
  2213. halbtc8822b2ant_set_ant_path(btcoexist,
  2214. BTC_ANT_PATH_AUTO, NORMAL_EXEC,
  2215. BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT);
  2216. }
  2217. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  2218. } else {
  2219. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2220. "[BTCoex], Wifi no-link + BT Idle!!\n");
  2221. BTC_TRACE(trace_buf);
  2222. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  2223. halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
  2224. NORMAL_EXEC,
  2225. BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT);
  2226. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  2227. }
  2228. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 0xd8);
  2229. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2230. }
  2231. /* SCO only or SCO+PAN(HS) */
  2232. void halbtc8822b2ant_action_sco(IN struct btc_coexist *btcoexist)
  2233. {
  2234. static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW;
  2235. static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW;
  2236. u8 wifi_rssi_state, bt_rssi_state;
  2237. static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW;
  2238. static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW;
  2239. u8 wifi_rssi_state2, bt_rssi_state2;
  2240. boolean wifi_busy = false;
  2241. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  2242. wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(btcoexist,
  2243. &prewifi_rssi_state, 2,
  2244. coex_sta->wifi_coex_thres , 0);
  2245. wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(btcoexist,
  2246. &prewifi_rssi_state2, 2,
  2247. coex_sta->wifi_coex_thres2 , 0);
  2248. bt_rssi_state = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state, 2,
  2249. coex_sta->bt_coex_thres , 0);
  2250. bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state2, 2,
  2251. coex_sta->bt_coex_thres2 , 0);
  2252. if (BTC_RSSI_HIGH(wifi_rssi_state) &&
  2253. BTC_RSSI_HIGH(bt_rssi_state)) {
  2254. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
  2255. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2256. coex_dm->is_switch_to_1dot5_ant = false;
  2257. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  2258. halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
  2259. NORMAL_EXEC,
  2260. BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT);
  2261. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  2262. } else {
  2263. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
  2264. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2265. coex_dm->is_switch_to_1dot5_ant = false;
  2266. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3);
  2267. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  2268. }
  2269. }
  2270. void halbtc8822b2ant_action_hid(IN struct btc_coexist *btcoexist)
  2271. {
  2272. static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW;
  2273. static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW;
  2274. u8 wifi_rssi_state, bt_rssi_state;
  2275. static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW;
  2276. static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW;
  2277. u8 wifi_rssi_state2, bt_rssi_state2;
  2278. boolean wifi_busy = false;
  2279. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  2280. wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(btcoexist,
  2281. &prewifi_rssi_state, 2,
  2282. coex_sta->wifi_coex_thres , 0);
  2283. wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(btcoexist,
  2284. &prewifi_rssi_state2, 2,
  2285. coex_sta->wifi_coex_thres2 , 0);
  2286. bt_rssi_state = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state, 2,
  2287. coex_sta->bt_coex_thres , 0);
  2288. bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state2, 2,
  2289. coex_sta->bt_coex_thres2 , 0);
  2290. if (BTC_RSSI_HIGH(wifi_rssi_state) &&
  2291. BTC_RSSI_HIGH(bt_rssi_state)) {
  2292. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
  2293. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2294. coex_dm->is_switch_to_1dot5_ant = false;
  2295. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  2296. halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
  2297. NORMAL_EXEC,
  2298. BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT);
  2299. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  2300. } else {
  2301. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
  2302. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2303. coex_dm->is_switch_to_1dot5_ant = false;
  2304. /*
  2305. halbtc8822b2ant_coex_table_with_type(btcoexist,
  2306. NORMAL_EXEC, 0);
  2307. halbtc8822b2ant_set_ant_path(btcoexist,
  2308. BTC_ANT_PATH_AUTO, NORMAL_EXEC,
  2309. BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT);
  2310. */
  2311. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3);
  2312. /*
  2313. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 10);
  2314. */
  2315. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  2316. }
  2317. }
  2318. /* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */
  2319. void halbtc8822b2ant_action_a2dp(IN struct btc_coexist *btcoexist)
  2320. {
  2321. static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW;
  2322. static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW;
  2323. u8 wifi_rssi_state, bt_rssi_state;
  2324. static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW;
  2325. static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW;
  2326. u8 wifi_rssi_state2, bt_rssi_state2;
  2327. boolean wifi_busy = false, wifi_turbo = false;
  2328. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  2329. btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
  2330. &coex_sta->scan_ap_num);
  2331. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2332. "############# [BTCoex], scan_ap_num = %d\n",
  2333. coex_sta->scan_ap_num);
  2334. BTC_TRACE(trace_buf);
  2335. #if 1
  2336. if ((wifi_busy) && (coex_sta->scan_ap_num <= 4))
  2337. wifi_turbo = true;
  2338. #endif
  2339. wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(btcoexist,
  2340. &prewifi_rssi_state, 2,
  2341. coex_sta->wifi_coex_thres , 0);
  2342. wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(btcoexist,
  2343. &prewifi_rssi_state2, 2,
  2344. coex_sta->wifi_coex_thres2 , 0);
  2345. bt_rssi_state = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state, 2,
  2346. coex_sta->bt_coex_thres , 0);
  2347. bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state2, 2,
  2348. coex_sta->bt_coex_thres2 , 0);
  2349. if (BTC_RSSI_HIGH(wifi_rssi_state) &&
  2350. BTC_RSSI_HIGH(bt_rssi_state)) {
  2351. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
  2352. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2353. coex_dm->is_switch_to_1dot5_ant = false;
  2354. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  2355. halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
  2356. NORMAL_EXEC,
  2357. BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT);
  2358. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  2359. } else if (BTC_RSSI_HIGH(wifi_rssi_state2) &&
  2360. BTC_RSSI_HIGH(bt_rssi_state2)) {
  2361. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xc8);
  2362. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
  2363. coex_dm->is_switch_to_1dot5_ant = false;
  2364. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  2365. if (wifi_busy) {
  2366. if (coex_sta->is_setupLink)
  2367. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2368. true, 51);
  2369. else {
  2370. halbtc8822b2ant_coex_table_with_type(btcoexist,
  2371. NORMAL_EXEC, 12);
  2372. halbtc8822b2ant_set_ant_path(btcoexist,
  2373. BTC_ANT_PATH_AUTO, NORMAL_EXEC,
  2374. BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT);
  2375. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2376. true, 1);
  2377. }
  2378. } else
  2379. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2380. 2);
  2381. } else {
  2382. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
  2383. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2384. coex_dm->is_switch_to_1dot5_ant = true;
  2385. if (wifi_turbo)
  2386. halbtc8822b2ant_coex_table_with_type(btcoexist,
  2387. NORMAL_EXEC, 6);
  2388. else
  2389. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
  2390. 7);
  2391. if (wifi_busy) {
  2392. if (coex_sta->is_setupLink)
  2393. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2394. true, 151);
  2395. else
  2396. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2397. true, 101);
  2398. } else
  2399. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2400. 102);
  2401. }
  2402. }
  2403. void halbtc8822b2ant_action_pan_edr(IN struct btc_coexist *btcoexist)
  2404. {
  2405. static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW;
  2406. static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW;
  2407. u8 wifi_rssi_state, bt_rssi_state;
  2408. static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW;
  2409. static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW;
  2410. u8 wifi_rssi_state2, bt_rssi_state2;
  2411. boolean wifi_busy = false, wifi_turbo = false;
  2412. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  2413. btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
  2414. &coex_sta->scan_ap_num);
  2415. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2416. "############# [BTCoex], scan_ap_num = %d\n",
  2417. coex_sta->scan_ap_num);
  2418. BTC_TRACE(trace_buf);
  2419. #if 1
  2420. if ((wifi_busy) && (coex_sta->scan_ap_num <= 4))
  2421. wifi_turbo = true;
  2422. #endif
  2423. wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(btcoexist,
  2424. &prewifi_rssi_state, 2,
  2425. coex_sta->wifi_coex_thres , 0);
  2426. wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(btcoexist,
  2427. &prewifi_rssi_state2, 2,
  2428. coex_sta->wifi_coex_thres2 , 0);
  2429. bt_rssi_state = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state, 2,
  2430. coex_sta->bt_coex_thres , 0);
  2431. bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state2, 2,
  2432. coex_sta->bt_coex_thres2 , 0);
  2433. #if 0
  2434. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
  2435. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2436. coex_dm->is_switch_to_1dot5_ant = false;
  2437. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  2438. halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC,
  2439. BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT);
  2440. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  2441. #endif
  2442. #if 1
  2443. if (BTC_RSSI_HIGH(wifi_rssi_state) &&
  2444. BTC_RSSI_HIGH(bt_rssi_state)) {
  2445. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
  2446. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2447. coex_dm->is_switch_to_1dot5_ant = false;
  2448. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  2449. halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
  2450. NORMAL_EXEC,
  2451. BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT);
  2452. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  2453. } else if (BTC_RSSI_HIGH(wifi_rssi_state2) &&
  2454. BTC_RSSI_HIGH(bt_rssi_state2)) {
  2455. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xc8);
  2456. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
  2457. coex_dm->is_switch_to_1dot5_ant = false;
  2458. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  2459. if (wifi_busy) {
  2460. halbtc8822b2ant_coex_table_with_type(btcoexist,
  2461. NORMAL_EXEC, 0);
  2462. halbtc8822b2ant_set_ant_path(btcoexist,
  2463. BTC_ANT_PATH_AUTO, NORMAL_EXEC,
  2464. BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT);
  2465. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2466. 3);
  2467. } else
  2468. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2469. 4);
  2470. } else {
  2471. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
  2472. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2473. coex_dm->is_switch_to_1dot5_ant = true;
  2474. if (wifi_turbo)
  2475. halbtc8822b2ant_coex_table_with_type(btcoexist,
  2476. NORMAL_EXEC, 6);
  2477. else
  2478. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
  2479. 7);
  2480. if (wifi_busy)
  2481. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2482. 103);
  2483. else
  2484. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2485. 104);
  2486. }
  2487. #endif
  2488. }
  2489. /* PAN(HS) only */
  2490. void halbtc8822b2ant_action_pan_hs(IN struct btc_coexist *btcoexist)
  2491. {
  2492. static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW;
  2493. static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW;
  2494. u8 wifi_rssi_state, bt_rssi_state;
  2495. static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW;
  2496. static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW;
  2497. u8 wifi_rssi_state2, bt_rssi_state2;
  2498. boolean wifi_busy = false, wifi_turbo = false;
  2499. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  2500. btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
  2501. &coex_sta->scan_ap_num);
  2502. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2503. "############# [BTCoex], scan_ap_num = %d\n",
  2504. coex_sta->scan_ap_num);
  2505. BTC_TRACE(trace_buf);
  2506. #if 1
  2507. if ((wifi_busy) && (coex_sta->scan_ap_num <= 4))
  2508. wifi_turbo = true;
  2509. #endif
  2510. wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(btcoexist,
  2511. &prewifi_rssi_state, 2,
  2512. coex_sta->wifi_coex_thres , 0);
  2513. wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(btcoexist,
  2514. &prewifi_rssi_state2, 2,
  2515. coex_sta->wifi_coex_thres2 , 0);
  2516. bt_rssi_state = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state, 2,
  2517. coex_sta->bt_coex_thres , 0);
  2518. bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state2, 2,
  2519. coex_sta->bt_coex_thres2 , 0);
  2520. if (BTC_RSSI_HIGH(wifi_rssi_state) &&
  2521. BTC_RSSI_HIGH(bt_rssi_state)) {
  2522. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
  2523. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2524. coex_dm->is_switch_to_1dot5_ant = false;
  2525. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  2526. halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
  2527. NORMAL_EXEC,
  2528. BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT);
  2529. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  2530. } else if (BTC_RSSI_HIGH(wifi_rssi_state2) &&
  2531. BTC_RSSI_HIGH(bt_rssi_state2)) {
  2532. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xc8);
  2533. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
  2534. coex_dm->is_switch_to_1dot5_ant = false;
  2535. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  2536. halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
  2537. NORMAL_EXEC,
  2538. BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT);
  2539. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  2540. } else {
  2541. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
  2542. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2543. coex_dm->is_switch_to_1dot5_ant = true;
  2544. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  2545. halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
  2546. NORMAL_EXEC,
  2547. BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT);
  2548. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  2549. }
  2550. }
  2551. void halbtc8822b2ant_action_hid_a2dp(IN struct btc_coexist *btcoexist)
  2552. {
  2553. static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW;
  2554. static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW;
  2555. u8 wifi_rssi_state, bt_rssi_state;
  2556. static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW;
  2557. static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW;
  2558. u8 wifi_rssi_state2, bt_rssi_state2;
  2559. boolean wifi_busy = false;
  2560. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  2561. wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(btcoexist,
  2562. &prewifi_rssi_state, 2,
  2563. coex_sta->wifi_coex_thres , 0);
  2564. wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(btcoexist,
  2565. &prewifi_rssi_state2, 2,
  2566. coex_sta->wifi_coex_thres2 , 0);
  2567. bt_rssi_state = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state, 2,
  2568. coex_sta->bt_coex_thres , 0);
  2569. bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state2, 2,
  2570. coex_sta->bt_coex_thres2 , 0);
  2571. if (BTC_RSSI_HIGH(wifi_rssi_state) &&
  2572. BTC_RSSI_HIGH(bt_rssi_state)) {
  2573. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
  2574. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2575. coex_dm->is_switch_to_1dot5_ant = false;
  2576. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  2577. halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
  2578. NORMAL_EXEC,
  2579. BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT);
  2580. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  2581. } else if (BTC_RSSI_HIGH(wifi_rssi_state2) &&
  2582. BTC_RSSI_HIGH(bt_rssi_state2)) {
  2583. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xc8);
  2584. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
  2585. coex_dm->is_switch_to_1dot5_ant = false;
  2586. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  2587. if (wifi_busy) {
  2588. if (coex_sta->is_setupLink)
  2589. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2590. true, 51);
  2591. else
  2592. halbtc8822b2ant_coex_table_with_type(btcoexist,
  2593. NORMAL_EXEC, 12);
  2594. halbtc8822b2ant_set_ant_path(btcoexist,
  2595. BTC_ANT_PATH_AUTO, NORMAL_EXEC,
  2596. BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT);
  2597. /*
  2598. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 1);
  2599. */
  2600. } else
  2601. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2602. 2);
  2603. } else {
  2604. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
  2605. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2606. coex_dm->is_switch_to_1dot5_ant = true;
  2607. if ((wifi_busy) && (coex_sta->hid_busy_num >= 2))
  2608. halbtc8822b2ant_coex_table_with_type(btcoexist,
  2609. NORMAL_EXEC, 6);
  2610. else
  2611. /*
  2612. halbtc8822b2ant_coex_table_with_type(btcoexist,
  2613. NORMAL_EXEC, 9);
  2614. */
  2615. halbtc8822b2ant_coex_table_with_type(btcoexist,
  2616. NORMAL_EXEC, 4);
  2617. if (wifi_busy) {
  2618. if (coex_sta->is_setupLink)
  2619. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2620. true, 151);
  2621. else
  2622. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2623. true, 101);
  2624. } else
  2625. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2626. 102);
  2627. }
  2628. }
  2629. void halbtc8822b2ant_action_a2dp_pan_hs(IN struct btc_coexist *btcoexist)
  2630. {
  2631. static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW;
  2632. static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW;
  2633. u8 wifi_rssi_state, bt_rssi_state;
  2634. static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW;
  2635. static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW;
  2636. u8 wifi_rssi_state2, bt_rssi_state2;
  2637. boolean wifi_busy = false, wifi_turbo = false;
  2638. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  2639. btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
  2640. &coex_sta->scan_ap_num);
  2641. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2642. "############# [BTCoex], scan_ap_num = %d\n",
  2643. coex_sta->scan_ap_num);
  2644. BTC_TRACE(trace_buf);
  2645. #if 1
  2646. if ((wifi_busy) && (coex_sta->scan_ap_num <= 4))
  2647. wifi_turbo = true;
  2648. #endif
  2649. wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(btcoexist,
  2650. &prewifi_rssi_state, 2,
  2651. coex_sta->wifi_coex_thres , 0);
  2652. wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(btcoexist,
  2653. &prewifi_rssi_state2, 2,
  2654. coex_sta->wifi_coex_thres2 , 0);
  2655. bt_rssi_state = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state, 2,
  2656. coex_sta->bt_coex_thres , 0);
  2657. bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state2, 2,
  2658. coex_sta->bt_coex_thres2 , 0);
  2659. if (BTC_RSSI_HIGH(wifi_rssi_state) &&
  2660. BTC_RSSI_HIGH(bt_rssi_state)) {
  2661. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
  2662. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2663. coex_dm->is_switch_to_1dot5_ant = false;
  2664. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  2665. halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
  2666. NORMAL_EXEC,
  2667. BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT);
  2668. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  2669. } else if (BTC_RSSI_HIGH(wifi_rssi_state2) &&
  2670. BTC_RSSI_HIGH(bt_rssi_state2)) {
  2671. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xc8);
  2672. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
  2673. coex_dm->is_switch_to_1dot5_ant = false;
  2674. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  2675. if (wifi_busy) {
  2676. if ((coex_sta->a2dp_bit_pool > 40) &&
  2677. (coex_sta->a2dp_bit_pool < 255))
  2678. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2679. true, 7);
  2680. else
  2681. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2682. true, 5);
  2683. } else
  2684. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2685. 6);
  2686. } else {
  2687. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
  2688. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2689. coex_dm->is_switch_to_1dot5_ant = true;
  2690. if (wifi_turbo)
  2691. halbtc8822b2ant_coex_table_with_type(btcoexist,
  2692. NORMAL_EXEC, 6);
  2693. else
  2694. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
  2695. 7);
  2696. if (wifi_busy) {
  2697. if ((coex_sta->a2dp_bit_pool > 40) &&
  2698. (coex_sta->a2dp_bit_pool < 255))
  2699. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2700. true, 107);
  2701. else
  2702. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2703. true, 105);
  2704. } else
  2705. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2706. 106);
  2707. }
  2708. }
  2709. /* PAN(EDR)+A2DP */
  2710. void halbtc8822b2ant_action_pan_edr_a2dp(IN struct btc_coexist *btcoexist)
  2711. {
  2712. static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW;
  2713. static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW;
  2714. u8 wifi_rssi_state, bt_rssi_state;
  2715. static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW;
  2716. static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW;
  2717. u8 wifi_rssi_state2, bt_rssi_state2;
  2718. boolean wifi_busy = false, wifi_turbo = false;
  2719. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  2720. btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
  2721. &coex_sta->scan_ap_num);
  2722. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2723. "############# [BTCoex], scan_ap_num = %d\n",
  2724. coex_sta->scan_ap_num);
  2725. BTC_TRACE(trace_buf);
  2726. #if 1
  2727. if ((wifi_busy) && (coex_sta->scan_ap_num <= 4))
  2728. wifi_turbo = true;
  2729. #endif
  2730. wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(btcoexist,
  2731. &prewifi_rssi_state, 2,
  2732. coex_sta->wifi_coex_thres , 0);
  2733. wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(btcoexist,
  2734. &prewifi_rssi_state2, 2,
  2735. coex_sta->wifi_coex_thres2 , 0);
  2736. bt_rssi_state = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state, 2,
  2737. coex_sta->bt_coex_thres , 0);
  2738. bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state2, 2,
  2739. coex_sta->bt_coex_thres2 , 0);
  2740. if (BTC_RSSI_HIGH(wifi_rssi_state) &&
  2741. BTC_RSSI_HIGH(bt_rssi_state)) {
  2742. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
  2743. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2744. coex_dm->is_switch_to_1dot5_ant = false;
  2745. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  2746. halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
  2747. NORMAL_EXEC,
  2748. BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT);
  2749. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  2750. } else if (BTC_RSSI_HIGH(wifi_rssi_state2) &&
  2751. BTC_RSSI_HIGH(bt_rssi_state2)) {
  2752. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xc8);
  2753. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
  2754. coex_dm->is_switch_to_1dot5_ant = false;
  2755. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  2756. if (wifi_busy) {
  2757. if (((coex_sta->a2dp_bit_pool > 40) &&
  2758. (coex_sta->a2dp_bit_pool < 255)) ||
  2759. (!coex_sta->is_A2DP_3M))
  2760. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2761. true, 7);
  2762. else
  2763. halbtc8822b2ant_coex_table_with_type(btcoexist,
  2764. NORMAL_EXEC, 0);
  2765. halbtc8822b2ant_set_ant_path(btcoexist,
  2766. BTC_ANT_PATH_AUTO, NORMAL_EXEC,
  2767. BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT);
  2768. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2769. true, 5);
  2770. } else
  2771. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2772. 6);
  2773. } else {
  2774. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
  2775. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2776. coex_dm->is_switch_to_1dot5_ant = true;
  2777. if (wifi_turbo)
  2778. halbtc8822b2ant_coex_table_with_type(btcoexist,
  2779. NORMAL_EXEC, 6);
  2780. else
  2781. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
  2782. 7);
  2783. if (wifi_busy) {
  2784. if ((coex_sta->a2dp_bit_pool > 40) &&
  2785. (coex_sta->a2dp_bit_pool < 255))
  2786. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2787. true, 107);
  2788. else
  2789. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2790. true, 105);
  2791. } else
  2792. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2793. 106);
  2794. }
  2795. }
  2796. void halbtc8822b2ant_action_pan_edr_hid(IN struct btc_coexist *btcoexist)
  2797. {
  2798. static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW;
  2799. static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW;
  2800. u8 wifi_rssi_state, bt_rssi_state;
  2801. static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW;
  2802. static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW;
  2803. u8 wifi_rssi_state2, bt_rssi_state2;
  2804. boolean wifi_busy = false;
  2805. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  2806. wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(btcoexist,
  2807. &prewifi_rssi_state, 2,
  2808. coex_sta->wifi_coex_thres , 0);
  2809. wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(btcoexist,
  2810. &prewifi_rssi_state2, 2,
  2811. coex_sta->wifi_coex_thres2 , 0);
  2812. bt_rssi_state = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state, 2,
  2813. coex_sta->bt_coex_thres , 0);
  2814. bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state2, 2,
  2815. coex_sta->bt_coex_thres2 , 0);
  2816. if (BTC_RSSI_HIGH(wifi_rssi_state) &&
  2817. BTC_RSSI_HIGH(bt_rssi_state)) {
  2818. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
  2819. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2820. coex_dm->is_switch_to_1dot5_ant = false;
  2821. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  2822. halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
  2823. NORMAL_EXEC,
  2824. BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT);
  2825. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  2826. } else if (BTC_RSSI_HIGH(wifi_rssi_state2) &&
  2827. BTC_RSSI_HIGH(bt_rssi_state2)) {
  2828. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xc8);
  2829. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
  2830. coex_dm->is_switch_to_1dot5_ant = false;
  2831. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  2832. if (wifi_busy)
  2833. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2834. 3);
  2835. else
  2836. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2837. 4);
  2838. } else {
  2839. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
  2840. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2841. coex_dm->is_switch_to_1dot5_ant = true;
  2842. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
  2843. if (wifi_busy)
  2844. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2845. 103);
  2846. else
  2847. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2848. 104);
  2849. }
  2850. }
  2851. /* HID+A2DP+PAN(EDR) */
  2852. void halbtc8822b2ant_action_hid_a2dp_pan_edr(IN struct btc_coexist *btcoexist)
  2853. {
  2854. static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW;
  2855. static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW;
  2856. u8 wifi_rssi_state, bt_rssi_state;
  2857. static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW;
  2858. static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW;
  2859. u8 wifi_rssi_state2, bt_rssi_state2;
  2860. boolean wifi_busy = false;
  2861. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  2862. wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(btcoexist,
  2863. &prewifi_rssi_state, 2,
  2864. coex_sta->wifi_coex_thres , 0);
  2865. wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(btcoexist,
  2866. &prewifi_rssi_state2, 2,
  2867. coex_sta->wifi_coex_thres2 , 0);
  2868. bt_rssi_state = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state, 2,
  2869. coex_sta->bt_coex_thres , 0);
  2870. bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state2, 2,
  2871. coex_sta->bt_coex_thres2 , 0);
  2872. if (BTC_RSSI_HIGH(wifi_rssi_state) &&
  2873. BTC_RSSI_HIGH(bt_rssi_state)) {
  2874. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
  2875. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2876. coex_dm->is_switch_to_1dot5_ant = false;
  2877. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  2878. halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
  2879. NORMAL_EXEC,
  2880. BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT);
  2881. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  2882. } else if (BTC_RSSI_HIGH(wifi_rssi_state2) &&
  2883. BTC_RSSI_HIGH(bt_rssi_state2)) {
  2884. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xc8);
  2885. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
  2886. coex_dm->is_switch_to_1dot5_ant = false;
  2887. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  2888. if (wifi_busy) {
  2889. if (((coex_sta->a2dp_bit_pool > 40) &&
  2890. (coex_sta->a2dp_bit_pool < 255)) ||
  2891. (!coex_sta->is_A2DP_3M))
  2892. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2893. true, 7);
  2894. else
  2895. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2896. true, 5);
  2897. } else
  2898. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2899. 6);
  2900. } else {
  2901. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
  2902. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2903. coex_dm->is_switch_to_1dot5_ant = true;
  2904. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
  2905. if (wifi_busy) {
  2906. if ((coex_sta->a2dp_bit_pool > 40) &&
  2907. (coex_sta->a2dp_bit_pool < 255))
  2908. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2909. true, 107);
  2910. else
  2911. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2912. true, 105);
  2913. } else
  2914. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2915. 106);
  2916. }
  2917. }
  2918. void halbtc8822b2ant_action_bt_whck_test(IN struct btc_coexist *btcoexist)
  2919. {
  2920. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
  2921. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2922. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  2923. halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC,
  2924. BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT);
  2925. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  2926. }
  2927. void halbtc8822b2ant_action_wifi_multi_port(IN struct btc_coexist *btcoexist)
  2928. {
  2929. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
  2930. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2931. /* hw all off */
  2932. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  2933. halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC,
  2934. BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT);
  2935. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  2936. }
  2937. void halbtc8822b2ant_run_coexist_mechanism(IN struct btc_coexist *btcoexist)
  2938. {
  2939. u8 algorithm = 0;
  2940. u32 num_of_wifi_link = 0;
  2941. u32 wifi_link_status = 0;
  2942. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  2943. boolean miracast_plus_bt = false;
  2944. boolean scan = false, link = false, roam = false,
  2945. wifi_connected = false, wifi_under_5g = false;
  2946. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2947. "[BTCoex], RunCoexistMechanism()===>\n");
  2948. BTC_TRACE(trace_buf);
  2949. if (btcoexist->manual_control) {
  2950. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2951. "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
  2952. BTC_TRACE(trace_buf);
  2953. return;
  2954. }
  2955. if (btcoexist->stop_coex_dm) {
  2956. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2957. "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n");
  2958. BTC_TRACE(trace_buf);
  2959. return;
  2960. }
  2961. if (coex_sta->under_ips) {
  2962. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2963. "[BTCoex], wifi is under IPS !!!\n");
  2964. BTC_TRACE(trace_buf);
  2965. return;
  2966. }
  2967. if (!coex_sta->run_time_state) {
  2968. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2969. "[BTCoex], return for run_time_state = false !!!\n");
  2970. BTC_TRACE(trace_buf);
  2971. return;
  2972. }
  2973. if (coex_sta->freeze_coexrun_by_btinfo) {
  2974. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2975. "[BTCoex], BtInfoNotify(), return for freeze_coexrun_by_btinfo\n");
  2976. BTC_TRACE(trace_buf);
  2977. return;
  2978. }
  2979. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  2980. if (wifi_under_5g) {
  2981. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2982. "[BTCoex], WiFi is under 5G!!!\n");
  2983. BTC_TRACE(trace_buf);
  2984. halbtc8822b2ant_action_wifi_under5g(btcoexist);
  2985. return;
  2986. }
  2987. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2988. "[BTCoex], WiFi is under 2G!!!\n");
  2989. BTC_TRACE(trace_buf);
  2990. halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
  2991. NORMAL_EXEC,
  2992. BT_8822B_2ANT_PHASE_2G_RUNTIME);
  2993. if (coex_sta->bt_whck_test) {
  2994. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2995. "[BTCoex], BT is under WHCK TEST!!!\n");
  2996. BTC_TRACE(trace_buf);
  2997. halbtc8822b2ant_action_bt_whck_test(btcoexist);
  2998. return;
  2999. }
  3000. if (coex_sta->bt_disabled) {
  3001. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3002. "[BTCoex], BT is disabled!!!\n");
  3003. BTC_TRACE(trace_buf);
  3004. halbtc8822b2ant_action_coex_all_off(btcoexist);
  3005. return;
  3006. }
  3007. if (coex_sta->c2h_bt_inquiry_page) {
  3008. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3009. "[BTCoex], BT is under inquiry/page scan !!\n");
  3010. BTC_TRACE(trace_buf);
  3011. halbtc8822b2ant_action_bt_inquiry(btcoexist);
  3012. return;
  3013. }
  3014. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
  3015. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
  3016. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
  3017. if (scan || link || roam) {
  3018. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3019. "[BTCoex], WiFi is under Link Process !!\n");
  3020. BTC_TRACE(trace_buf);
  3021. halbtc8822b2ant_action_wifi_link_process(btcoexist);
  3022. return;
  3023. }
  3024. /* for P2P */
  3025. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
  3026. &wifi_link_status);
  3027. num_of_wifi_link = wifi_link_status >> 16;
  3028. if ((num_of_wifi_link >= 2) ||
  3029. (wifi_link_status & WIFI_P2P_GO_CONNECTED)) {
  3030. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3031. "############# [BTCoex], Multi-Port num_of_wifi_link = %d, wifi_link_status = 0x%x\n",
  3032. num_of_wifi_link, wifi_link_status);
  3033. BTC_TRACE(trace_buf);
  3034. if (bt_link_info->bt_link_exist)
  3035. miracast_plus_bt = true;
  3036. else
  3037. miracast_plus_bt = false;
  3038. btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT,
  3039. &miracast_plus_bt);
  3040. halbtc8822b2ant_action_wifi_multi_port(btcoexist);
  3041. return;
  3042. }
  3043. miracast_plus_bt = false;
  3044. btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT,
  3045. &miracast_plus_bt);
  3046. algorithm = halbtc8822b2ant_action_algorithm(btcoexist);
  3047. coex_dm->cur_algorithm = algorithm;
  3048. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Algorithm = %d\n",
  3049. coex_dm->cur_algorithm);
  3050. BTC_TRACE(trace_buf);
  3051. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  3052. &wifi_connected);
  3053. if (!wifi_connected) {
  3054. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3055. "[BTCoex], Action 2-Ant, wifi non-connected!!.\n");
  3056. BTC_TRACE(trace_buf);
  3057. halbtc8822b2ant_action_wifi_nonconnected(btcoexist);
  3058. } else if ((BT_8822B_2ANT_BT_STATUS_NON_CONNECTED_IDLE ==
  3059. coex_dm->bt_status) ||
  3060. (BT_8822B_2ANT_BT_STATUS_CONNECTED_IDLE ==
  3061. coex_dm->bt_status)) {
  3062. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3063. "[BTCoex], Action 2-Ant, bt idle!!.\n");
  3064. BTC_TRACE(trace_buf);
  3065. halbtc8822b2ant_action_bt_idle(btcoexist);
  3066. } else {
  3067. if (coex_dm->cur_algorithm != coex_dm->pre_algorithm) {
  3068. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3069. "[BTCoex], pre_algorithm=%d, cur_algorithm=%d\n",
  3070. coex_dm->pre_algorithm, coex_dm->cur_algorithm);
  3071. BTC_TRACE(trace_buf);
  3072. }
  3073. switch (coex_dm->cur_algorithm) {
  3074. case BT_8822B_2ANT_COEX_ALGO_SCO:
  3075. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3076. "[BTCoex], Action 2-Ant, algorithm = SCO.\n");
  3077. BTC_TRACE(trace_buf);
  3078. halbtc8822b2ant_action_sco(btcoexist);
  3079. break;
  3080. case BT_8822B_2ANT_COEX_ALGO_HID:
  3081. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3082. "[BTCoex], Action 2-Ant, algorithm = HID.\n");
  3083. BTC_TRACE(trace_buf);
  3084. halbtc8822b2ant_action_hid(btcoexist);
  3085. break;
  3086. case BT_8822B_2ANT_COEX_ALGO_A2DP:
  3087. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3088. "[BTCoex], Action 2-Ant, algorithm = A2DP.\n");
  3089. BTC_TRACE(trace_buf);
  3090. halbtc8822b2ant_action_a2dp(btcoexist);
  3091. break;
  3092. case BT_8822B_2ANT_COEX_ALGO_A2DP_PANHS:
  3093. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3094. "[BTCoex], Action 2-Ant, algorithm = A2DP+PAN(HS).\n");
  3095. BTC_TRACE(trace_buf);
  3096. halbtc8822b2ant_action_a2dp_pan_hs(btcoexist);
  3097. break;
  3098. case BT_8822B_2ANT_COEX_ALGO_PANEDR:
  3099. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3100. "[BTCoex], Action 2-Ant, algorithm = PAN(EDR).\n");
  3101. BTC_TRACE(trace_buf);
  3102. halbtc8822b2ant_action_pan_edr(btcoexist);
  3103. break;
  3104. case BT_8822B_2ANT_COEX_ALGO_PANHS:
  3105. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3106. "[BTCoex], Action 2-Ant, algorithm = HS mode.\n");
  3107. BTC_TRACE(trace_buf);
  3108. halbtc8822b2ant_action_pan_hs(btcoexist);
  3109. break;
  3110. case BT_8822B_2ANT_COEX_ALGO_PANEDR_A2DP:
  3111. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3112. "[BTCoex], Action 2-Ant, algorithm = PAN+A2DP.\n");
  3113. BTC_TRACE(trace_buf);
  3114. halbtc8822b2ant_action_pan_edr_a2dp(btcoexist);
  3115. break;
  3116. case BT_8822B_2ANT_COEX_ALGO_PANEDR_HID:
  3117. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3118. "[BTCoex], Action 2-Ant, algorithm = PAN(EDR)+HID.\n");
  3119. BTC_TRACE(trace_buf);
  3120. halbtc8822b2ant_action_pan_edr_hid(btcoexist);
  3121. break;
  3122. case BT_8822B_2ANT_COEX_ALGO_HID_A2DP_PANEDR:
  3123. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3124. "[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN.\n");
  3125. BTC_TRACE(trace_buf);
  3126. halbtc8822b2ant_action_hid_a2dp_pan_edr(
  3127. btcoexist);
  3128. break;
  3129. case BT_8822B_2ANT_COEX_ALGO_HID_A2DP:
  3130. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3131. "[BTCoex], Action 2-Ant, algorithm = HID+A2DP.\n");
  3132. BTC_TRACE(trace_buf);
  3133. halbtc8822b2ant_action_hid_a2dp(btcoexist);
  3134. break;
  3135. case BT_8822B_2ANT_COEX_ALGO_NOPROFILEBUSY:
  3136. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3137. "[BTCoex], Action 2-Ant, algorithm = No-Profile busy.\n");
  3138. BTC_TRACE(trace_buf);
  3139. halbtc8822b2ant_action_bt_idle(btcoexist);
  3140. break;
  3141. default:
  3142. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3143. "[BTCoex], Action 2-Ant, algorithm = coexist All Off!!\n");
  3144. BTC_TRACE(trace_buf);
  3145. halbtc8822b2ant_action_coex_all_off(btcoexist);
  3146. break;
  3147. }
  3148. coex_dm->pre_algorithm = coex_dm->cur_algorithm;
  3149. }
  3150. }
  3151. void halbtc8822b2ant_init_coex_dm(IN struct btc_coexist *btcoexist)
  3152. {
  3153. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3154. "[BTCoex], Coex Mechanism Init!!\n");
  3155. BTC_TRACE(trace_buf);
  3156. halbtc8822b2ant_low_penalty_ra(btcoexist, NORMAL_EXEC, false);
  3157. halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  3158. halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC,
  3159. BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT);
  3160. /* fw all off */
  3161. halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  3162. halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8);
  3163. halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  3164. coex_sta->pop_event_cnt = 0;
  3165. coex_sta->cnt_RemoteNameReq = 0;
  3166. coex_sta->cnt_ReInit = 0;
  3167. coex_sta->cnt_setupLink = 0;
  3168. coex_sta->cnt_IgnWlanAct = 0;
  3169. coex_sta->cnt_Page = 0;
  3170. halbtc8822b2ant_query_bt_info(btcoexist);
  3171. }
  3172. void halbtc8822b2ant_init_hw_config(IN struct btc_coexist *btcoexist,
  3173. IN boolean wifi_only)
  3174. {
  3175. u8 u8tmp = 0;
  3176. u32 vendor;
  3177. u32 u32tmp0 = 0, u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0;
  3178. u32 RTL97F_8822B = 0;
  3179. u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
  3180. u32tmp1 = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, 0x38);
  3181. u32tmp2 = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, 0x54);
  3182. if (RTL97F_8822B == true) {
  3183. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x66, 0x04, 0x0);
  3184. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x41, 0x02, 0x0);
  3185. /* set GNT_BT to SW high */
  3186. halbtc8822b2ant_ltecoex_set_gnt_bt(btcoexist,
  3187. BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
  3188. BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
  3189. BT_8822B_2ANT_SIG_STA_SET_TO_HIGH);
  3190. /* Set GNT_WL to SW high */
  3191. halbtc8822b2ant_ltecoex_set_gnt_wl(btcoexist,
  3192. BT_8822B_2ANT_GNT_BLOCK_RFC_BB,
  3193. BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW,
  3194. BT_8822B_2ANT_SIG_STA_SET_TO_HIGH);
  3195. return;
  3196. }
  3197. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3198. "[BTCoex], (Before Init HW config) 0xcb4 = 0x%x, 0x38= 0x%x, 0x54= 0x%x\n",
  3199. u32tmp3, u32tmp1, u32tmp2);
  3200. BTC_TRACE(trace_buf);
  3201. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3202. "[BTCoex], 2Ant Init HW Config!!\n");
  3203. BTC_TRACE(trace_buf);
  3204. coex_sta->bt_coex_supported_feature = 0;
  3205. coex_sta->bt_coex_supported_version = 0;
  3206. coex_sta->bt_ble_scan_type = 0;
  3207. coex_sta->bt_ble_scan_para[0] = 0;
  3208. coex_sta->bt_ble_scan_para[1] = 0;
  3209. coex_sta->bt_ble_scan_para[2] = 0;
  3210. coex_sta->bt_reg_vendor_ac = 0xffff;
  3211. coex_sta->bt_reg_vendor_ae = 0xffff;
  3212. coex_sta->isolation_btween_wb = BT_8822B_2ANT_DEFAULT_ISOLATION;
  3213. /* 0xf0[15:12] --> Chip Cut information */
  3214. coex_sta->cut_version = (btcoexist->btc_read_1byte(btcoexist,
  3215. 0xf1) & 0xf0) >> 4;
  3216. coex_sta->dis_ver_info_cnt = 0;
  3217. halbtc8822b2ant_coex_switch_threshold(btcoexist,
  3218. coex_sta->isolation_btween_wb);
  3219. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x550, 0x8,
  3220. 0x1); /* enable TBTT nterrupt */
  3221. /* BT report packet sample rate */
  3222. btcoexist->btc_write_1byte(btcoexist, 0x790, 0x5);
  3223. /* Init 0x778 = 0x1 for 2-Ant */
  3224. btcoexist->btc_write_1byte(btcoexist, 0x778, 0x1);
  3225. /* Enable PTA (3-wire function form BT side) */
  3226. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1);
  3227. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x41, 0x02, 0x1);
  3228. /* Enable PTA (tx/rx signal form WiFi side) */
  3229. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4c6, 0x10, 0x1);
  3230. halbtc8822b2ant_enable_gnt_to_gpio(btcoexist, true);
  3231. /*GNT_BT=1 while select both */
  3232. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x763, 0x10, 0x1);
  3233. /* check if WL firmware download ok */
  3234. /*if (btcoexist->btc_read_1byte(btcoexist, 0x80) == 0xc6)*/
  3235. halbtc8822b2ant_post_state_to_bt(btcoexist,
  3236. BT_8822B_2ANT_SCOREBOARD_ONOFF, true);
  3237. /* Enable counter statistics */
  3238. btcoexist->btc_write_1byte(btcoexist, 0x76e,
  3239. 0x4); /* 0x76e[3] =1, WLAN_Act control by PTA */
  3240. /* WLAN_Tx by GNT_WL 0x950[29] = 0 */
  3241. /* btcoexist->btc_write_1byte_bitmask(btcoexist, 0x953, 0x20, 0x0); */
  3242. halbtc8822b2ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
  3243. halbtc8822b2ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0);
  3244. psd_scan->ant_det_is_ant_det_available = true;
  3245. if (wifi_only) {
  3246. coex_sta->concurrent_rx_mode_on = false;
  3247. /* Path config */
  3248. /* Set Antenna Path */
  3249. halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
  3250. FORCE_EXEC,
  3251. BT_8822B_2ANT_PHASE_WLANONLY_INIT);
  3252. btcoexist->stop_coex_dm = true;
  3253. } else {
  3254. /*Set BT polluted packet on for Tx rate adaptive not including Tx retry break by PTA, 0x45c[19] =1 */
  3255. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x45e, 0x8, 0x1);
  3256. coex_sta->concurrent_rx_mode_on = true;
  3257. /* btcoexist->btc_write_1byte_bitmask(btcoexist, 0x953, 0x2, 0x1); */
  3258. /* RF 0x1[1] = 0->Set GNT_WL_RF_Rx always = 1 for con-current Rx, mask Tx only */
  3259. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0x2, 0x0);
  3260. /* Set Antenna Path */
  3261. halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
  3262. FORCE_EXEC,
  3263. BT_8822B_2ANT_PHASE_COEX_INIT);
  3264. btcoexist->stop_coex_dm = false;
  3265. }
  3266. }
  3267. /* ************************************************************
  3268. * work around function start with wa_halbtc8822b2ant_
  3269. * ************************************************************
  3270. * ************************************************************
  3271. * extern function start with ex_halbtc8822b2ant_
  3272. * ************************************************************ */
  3273. void ex_halbtc8822b2ant_power_on_setting(IN struct btc_coexist *btcoexist)
  3274. {
  3275. struct btc_board_info *board_info = &btcoexist->board_info;
  3276. u8 u8tmp = 0x0;
  3277. u16 u16tmp = 0x0;
  3278. u32 value = 0;
  3279. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3280. "xxxxxxxxxxxxxxxx Execute 8822b 2-Ant PowerOn Setting xxxxxxxxxxxxxxxx!!\n");
  3281. BTC_TRACE(trace_buf);
  3282. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3283. "Ant Det Finish = %s, Ant Det Number = %d\n",
  3284. (board_info->btdm_ant_det_finish ? "Yes" : "No"),
  3285. board_info->btdm_ant_num_by_ant_det);
  3286. BTC_TRACE(trace_buf);
  3287. btcoexist->stop_coex_dm = true;
  3288. psd_scan->ant_det_is_ant_det_available = false;
  3289. /* enable BB, REG_SYS_FUNC_EN such that we can write BB Register correctly. */
  3290. u16tmp = btcoexist->btc_read_2byte(btcoexist, 0x2);
  3291. btcoexist->btc_write_2byte(btcoexist, 0x2, u16tmp | BIT(0) | BIT(1));
  3292. /* Local setting bit define */
  3293. /* BIT0: "0" for no antenna inverse; "1" for antenna inverse */
  3294. /* BIT1: "0" for internal switch; "1" for external switch */
  3295. /* BIT2: "0" for one antenna; "1" for two antenna */
  3296. /* NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and BIT2=0 */
  3297. /* Check efuse 0xc3[6] for Single Antenna Path */
  3298. if (board_info->single_ant_path == 0) {
  3299. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3300. "[BTCoex], ********** Single Antenna, Antenna at Aux Port\n");
  3301. BTC_TRACE(trace_buf);
  3302. board_info->btdm_ant_pos = BTC_ANTENNA_AT_AUX_PORT;
  3303. u8tmp = 7;
  3304. } else if (board_info->single_ant_path == 1) {
  3305. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3306. "[BTCoex], ********** Single Antenna, Antenna at Main Port\n");
  3307. BTC_TRACE(trace_buf);
  3308. board_info->btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
  3309. u8tmp = 6;
  3310. }
  3311. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3312. "[BTCoex], ********** (Power On) single_ant_path = %d, btdm_ant_pos = %d\n",
  3313. board_info->single_ant_path , board_info->btdm_ant_pos);
  3314. BTC_TRACE(trace_buf);
  3315. /* Setup RF front end type */
  3316. halbtc8822b2ant_set_rfe_type(btcoexist);
  3317. /* Set Antenna Path to BT side */
  3318. halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC,
  3319. BT_8822B_2ANT_PHASE_COEX_POWERON);
  3320. /* Save"single antenna position" info in Local register setting for FW reading, because FW may not ready at power on */
  3321. if (btcoexist->chip_interface == BTC_INTF_PCI)
  3322. btcoexist->btc_write_local_reg_1byte(btcoexist, 0x3e0, u8tmp);
  3323. else if (btcoexist->chip_interface == BTC_INTF_USB)
  3324. btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp);
  3325. else if (btcoexist->chip_interface == BTC_INTF_SDIO)
  3326. btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60, u8tmp);
  3327. /* enable GNT_WL/GNT_BT debug signal to GPIO14/15 */
  3328. halbtc8822b2ant_enable_gnt_to_gpio(btcoexist, true);
  3329. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3330. "[BTCoex], ********** LTE coex Reg 0x38 (Power-On) = 0x%x**********\n",
  3331. halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, 0x38));
  3332. BTC_TRACE(trace_buf);
  3333. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3334. "[BTCoex], ********** MAC Reg 0x70/ BB Reg 0xcb4 (Power-On) = 0x%x / 0x%x\n",
  3335. btcoexist->btc_read_4byte(btcoexist, 0x70),
  3336. btcoexist->btc_read_4byte(btcoexist, 0xcb4));
  3337. BTC_TRACE(trace_buf);
  3338. }
  3339. void ex_halbtc8822b2ant_pre_load_firmware(IN struct btc_coexist *btcoexist)
  3340. {
  3341. struct btc_board_info *board_info = &btcoexist->board_info;
  3342. u8 u8tmp = 0x4; /* Set BIT2 by default since it's 2ant case */
  3343. /* */
  3344. /* S0 or S1 setting and Local register setting(By the setting fw can get ant number, S0/S1, ... info) */
  3345. /* Local setting bit define */
  3346. /* BIT0: "0" for no antenna inverse; "1" for antenna inverse */
  3347. /* BIT1: "0" for internal switch; "1" for external switch */
  3348. /* BIT2: "0" for one antenna; "1" for two antenna */
  3349. /* NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and BIT2=0 */
  3350. if (btcoexist->chip_interface == BTC_INTF_USB) {
  3351. /* fixed at S0 for USB interface */
  3352. u8tmp |= 0x1; /* antenna inverse */
  3353. btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp);
  3354. } else {
  3355. /* for PCIE and SDIO interface, we check efuse 0xc3[6] */
  3356. if (board_info->single_ant_path == 0) {
  3357. } else if (board_info->single_ant_path == 1) {
  3358. /* set to S0 */
  3359. u8tmp |= 0x1; /* antenna inverse */
  3360. }
  3361. if (btcoexist->chip_interface == BTC_INTF_PCI)
  3362. btcoexist->btc_write_local_reg_1byte(btcoexist, 0x3e0,
  3363. u8tmp);
  3364. else if (btcoexist->chip_interface == BTC_INTF_SDIO)
  3365. btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60,
  3366. u8tmp);
  3367. }
  3368. }
  3369. void ex_halbtc8822b2ant_init_hw_config(IN struct btc_coexist *btcoexist,
  3370. IN boolean wifi_only)
  3371. {
  3372. halbtc8822b2ant_init_hw_config(btcoexist, wifi_only);
  3373. }
  3374. void ex_halbtc8822b2ant_init_coex_dm(IN struct btc_coexist *btcoexist)
  3375. {
  3376. halbtc8822b2ant_init_coex_dm(btcoexist);
  3377. }
  3378. void ex_halbtc8822b2ant_display_coex_info(IN struct btc_coexist *btcoexist)
  3379. {
  3380. struct btc_board_info *board_info = &btcoexist->board_info;
  3381. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  3382. u8 *cli_buf = btcoexist->cli_buf;
  3383. u8 u8tmp[4], i, ps_tdma_case = 0;
  3384. u32 u32tmp[4];
  3385. u16 u16tmp[4];
  3386. u32 fa_ofdm, fa_cck, cca_ofdm, cca_cck;
  3387. u32 fw_ver = 0, bt_patch_ver = 0, bt_coex_ver = 0;
  3388. static u8 pop_report_in_10s = 0;
  3389. u32 phyver = 0;
  3390. boolean lte_coex_on = false;
  3391. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3392. "\r\n ============[BT Coexist info]============");
  3393. CL_PRINTF(cli_buf);
  3394. if (btcoexist->manual_control) {
  3395. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3396. "\r\n ============[Under Manual Control]============");
  3397. CL_PRINTF(cli_buf);
  3398. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3399. "\r\n ==========================================");
  3400. CL_PRINTF(cli_buf);
  3401. }
  3402. if (psd_scan->ant_det_try_count == 0) {
  3403. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3404. "\r\n %-35s = %d/ %d/ %s / %d",
  3405. "Ant PG Num/ Mech/ Pos/ RFE",
  3406. board_info->pg_ant_num, board_info->btdm_ant_num,
  3407. (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT
  3408. ? "Main" : "Aux"),
  3409. rfe_type->rfe_module_type);
  3410. CL_PRINTF(cli_buf);
  3411. } else {
  3412. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3413. "\r\n %-35s = %d/ %d/ %s/ %d (%d/%d/%d)",
  3414. "Ant PG Num/ Mech(Ant_Det)/ Pos/ RFE",
  3415. board_info->pg_ant_num,
  3416. board_info->btdm_ant_num_by_ant_det,
  3417. (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT
  3418. ? "Main" : "Aux"),
  3419. rfe_type->rfe_module_type,
  3420. psd_scan->ant_det_try_count,
  3421. psd_scan->ant_det_fail_count,
  3422. psd_scan->ant_det_result);
  3423. CL_PRINTF(cli_buf);
  3424. if (board_info->btdm_ant_det_finish) {
  3425. if (psd_scan->ant_det_result != 12)
  3426. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s",
  3427. "Ant Det PSD Value",
  3428. psd_scan->ant_det_peak_val);
  3429. else
  3430. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3431. "\r\n %-35s = %d",
  3432. "Ant Det PSD Value",
  3433. psd_scan->ant_det_psd_scan_peak_val
  3434. / 100);
  3435. CL_PRINTF(cli_buf);
  3436. }
  3437. }
  3438. /*bt_patch_ver = btcoexist->bt_info.bt_get_fw_ver;*/
  3439. bt_patch_ver = btcoexist->bt_info.bt_get_fw_ver;
  3440. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
  3441. phyver = btcoexist->btc_get_bt_phydm_version(btcoexist);
  3442. bt_coex_ver = (coex_sta->bt_coex_supported_version & 0xff);
  3443. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3444. "\r\n %-35s = %d_%02x/ 0x%02x/ 0x%02x (%s)",
  3445. "CoexVer WL/ BT_Desired/ BT_Report",
  3446. glcoex_ver_date_8822b_2ant, glcoex_ver_8822b_2ant,
  3447. glcoex_ver_btdesired_8822b_2ant,
  3448. bt_coex_ver,
  3449. (bt_coex_ver == 0xff ? "Unknown" :
  3450. (bt_coex_ver >= glcoex_ver_btdesired_8822b_2ant ?
  3451. "Match" : "Mis-Match")));
  3452. CL_PRINTF(cli_buf);
  3453. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3454. "\r\n %-35s = 0x%x/ 0x%x/ v%d/ %c",
  3455. "W_FW/ B_FW/ Phy/ Kt",
  3456. fw_ver, bt_patch_ver, phyver,
  3457. coex_sta->cut_version + 65);
  3458. CL_PRINTF(cli_buf);
  3459. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ",
  3460. "AFH Map to BT",
  3461. coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1],
  3462. coex_dm->wifi_chnl_info[2]);
  3463. CL_PRINTF(cli_buf);
  3464. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d ",
  3465. "Isolation/WL_Thres/BT_Thres",
  3466. coex_sta->isolation_btween_wb,
  3467. coex_sta->wifi_coex_thres,
  3468. coex_sta->bt_coex_thres);
  3469. CL_PRINTF(cli_buf);
  3470. /* wifi status */
  3471. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  3472. "============[Wifi Status]============");
  3473. CL_PRINTF(cli_buf);
  3474. btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS);
  3475. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  3476. "============[BT Status]============");
  3477. CL_PRINTF(cli_buf);
  3478. pop_report_in_10s++;
  3479. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3480. "\r\n %-35s = [%s/ %d dBm/ %d/ %d] ",
  3481. "BT [status/ rssi/ retryCnt/ popCnt]",
  3482. ((coex_sta->bt_disabled) ? ("disabled") : ((
  3483. coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page")
  3484. : ((BT_8822B_2ANT_BT_STATUS_NON_CONNECTED_IDLE ==
  3485. coex_dm->bt_status) ? "non-connected idle" :
  3486. ((BT_8822B_2ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)
  3487. ? "connected-idle" : "busy")))),
  3488. coex_sta->bt_rssi - 100, coex_sta->bt_retry_cnt,
  3489. coex_sta->pop_event_cnt);
  3490. CL_PRINTF(cli_buf);
  3491. if (pop_report_in_10s >= 5) {
  3492. coex_sta->pop_event_cnt = 0;
  3493. pop_report_in_10s = 0;
  3494. }
  3495. if (coex_sta->num_of_profile != 0)
  3496. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3497. "\r\n %-35s = %s%s%s%s%s",
  3498. "Profiles",
  3499. ((bt_link_info->a2dp_exist) ? "A2DP," : ""),
  3500. ((bt_link_info->sco_exist) ? "SCO," : ""),
  3501. ((bt_link_info->hid_exist) ?
  3502. ((coex_sta->hid_busy_num >= 2) ? "HID(4/18)," :
  3503. "HID(2/18),") : ""),
  3504. ((bt_link_info->pan_exist) ? "PAN," : ""),
  3505. ((coex_sta->voice_over_HOGP) ? "Voice" : ""));
  3506. else
  3507. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3508. "\r\n %-35s = None", "Profiles");
  3509. CL_PRINTF(cli_buf);
  3510. if (bt_link_info->a2dp_exist) {
  3511. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %s",
  3512. "A2DP Rate/Bitpool/Auto_Slot",
  3513. ((coex_sta->is_A2DP_3M) ? "3M" : "No_3M"),
  3514. coex_sta->a2dp_bit_pool,
  3515. ((coex_sta->is_autoslot) ? "On" : "Off")
  3516. );
  3517. CL_PRINTF(cli_buf);
  3518. }
  3519. if (bt_link_info->hid_exist) {
  3520. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
  3521. "HID PairNum/Forbid_Slot",
  3522. coex_sta->hid_pair_cnt,
  3523. coex_sta->forbidden_slot
  3524. );
  3525. CL_PRINTF(cli_buf);
  3526. }
  3527. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %s/ 0x%x",
  3528. "Role/IgnWlanAct/Feature",
  3529. ((bt_link_info->slave_role) ? "Slave" : "Master"),
  3530. ((coex_dm->cur_ignore_wlan_act) ? "Yes" : "No"),
  3531. coex_sta->bt_coex_supported_feature);
  3532. CL_PRINTF(cli_buf);
  3533. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d",
  3534. "ReInit/ReLink/IgnWlact/Page/NameReq",
  3535. coex_sta->cnt_ReInit,
  3536. coex_sta->cnt_setupLink,
  3537. coex_sta->cnt_IgnWlanAct,
  3538. coex_sta->cnt_Page,
  3539. coex_sta->cnt_RemoteNameReq
  3540. );
  3541. CL_PRINTF(cli_buf);
  3542. halbtc8822b2ant_read_score_board(btcoexist, &u16tmp[0]);
  3543. if ((coex_sta->bt_reg_vendor_ae == 0xffff) ||
  3544. (coex_sta->bt_reg_vendor_ac == 0xffff))
  3545. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = x/ x/ %04x",
  3546. "0xae[4]/0xac[1:0]/Scoreboard", u16tmp[0]);
  3547. else
  3548. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3549. "\r\n %-35s = 0x%x/ 0x%x/ %04x",
  3550. "0xae[4]/0xac[1:0]/Scoreboard",
  3551. ((coex_sta->bt_reg_vendor_ae & BIT(4)) >> 4),
  3552. coex_sta->bt_reg_vendor_ac & 0x3, u16tmp[0]);
  3553. CL_PRINTF(cli_buf);
  3554. for (i = 0; i < BT_INFO_SRC_8822B_2ANT_MAX; i++) {
  3555. if (coex_sta->bt_info_c2h_cnt[i]) {
  3556. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3557. "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)",
  3558. glbt_info_src_8822b_2ant[i],
  3559. coex_sta->bt_info_c2h[i][0],
  3560. coex_sta->bt_info_c2h[i][1],
  3561. coex_sta->bt_info_c2h[i][2],
  3562. coex_sta->bt_info_c2h[i][3],
  3563. coex_sta->bt_info_c2h[i][4],
  3564. coex_sta->bt_info_c2h[i][5],
  3565. coex_sta->bt_info_c2h[i][6],
  3566. coex_sta->bt_info_c2h_cnt[i]);
  3567. CL_PRINTF(cli_buf);
  3568. }
  3569. }
  3570. /* Sw mechanism */
  3571. if (btcoexist->manual_control)
  3572. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  3573. "============[mechanism] (before Manual)============");
  3574. else
  3575. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  3576. "============[Mechanism]============");
  3577. CL_PRINTF(cli_buf);
  3578. ps_tdma_case = coex_dm->cur_ps_tdma;
  3579. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3580. "\r\n %-35s = %02x %02x %02x %02x %02x (case-%d, %s, %s)",
  3581. "TDMA",
  3582. coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1],
  3583. coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3],
  3584. coex_dm->ps_tdma_para[4], ps_tdma_case,
  3585. (coex_dm->cur_ps_tdma_on ? "TDMA On" : "TDMA Off"),
  3586. (coex_dm->is_switch_to_1dot5_ant ? "1.5Ant" : "2Ant"));
  3587. CL_PRINTF(cli_buf);
  3588. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
  3589. u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
  3590. u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
  3591. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3592. "\r\n %-35s = %d/ 0x%x/ 0x%x/ 0x%x",
  3593. "Table/0x6c0/0x6c4/0x6c8",
  3594. coex_sta->coex_table_type, u32tmp[0], u32tmp[1], u32tmp[2]);
  3595. CL_PRINTF(cli_buf);
  3596. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
  3597. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6cc);
  3598. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3599. "\r\n %-35s = 0x%x/ 0x%x",
  3600. "0x778/0x6cc",
  3601. u8tmp[0], u32tmp[0]);
  3602. CL_PRINTF(cli_buf);
  3603. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s",
  3604. "AntDiv/ForceLPS/LPRA",
  3605. ((board_info->ant_div_cfg) ? "On" : "Off"),
  3606. ((coex_sta->force_lps_on) ? "On" : "Off"),
  3607. ((coex_dm->cur_low_penalty_ra) ? "On" : "Off"));
  3608. CL_PRINTF(cli_buf);
  3609. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
  3610. "WL_DACSwing/ BT_Dec_Pwr", coex_dm->cur_fw_dac_swing_lvl,
  3611. coex_dm->cur_bt_dec_pwr_lvl);
  3612. CL_PRINTF(cli_buf);
  3613. u32tmp[0] = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, 0x38);
  3614. lte_coex_on = ((u32tmp[0] & BIT(7)) >> 7) ? true : false;
  3615. if (lte_coex_on) {
  3616. u32tmp[0] = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist,
  3617. 0xa0);
  3618. u32tmp[1] = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist,
  3619. 0xa4);
  3620. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
  3621. "LTE Coex Table W_L/B_L",
  3622. u32tmp[0] & 0xffff, u32tmp[1] & 0xffff);
  3623. CL_PRINTF(cli_buf);
  3624. u32tmp[0] = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist,
  3625. 0xa8);
  3626. u32tmp[1] = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist,
  3627. 0xac);
  3628. u32tmp[2] = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist,
  3629. 0xb0);
  3630. u32tmp[3] = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist,
  3631. 0xb4);
  3632. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3633. "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
  3634. "LTE Break Table W_L/B_L/L_W/L_B",
  3635. u32tmp[0] & 0xffff, u32tmp[1] & 0xffff,
  3636. u32tmp[2] & 0xffff, u32tmp[3] & 0xffff);
  3637. CL_PRINTF(cli_buf);
  3638. }
  3639. /* Hw setting */
  3640. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  3641. "============[Hw setting]============");
  3642. CL_PRINTF(cli_buf);
  3643. /*
  3644. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x430);
  3645. u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x434);
  3646. u16tmp[0] = btcoexist->btc_read_2byte(btcoexist, 0x42a);
  3647. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x456);
  3648. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
  3649. "0x430/0x434/0x42a/0x456",
  3650. u32tmp[0], u32tmp[1], u16tmp[0], u8tmp[0]);
  3651. CL_PRINTF(cli_buf);
  3652. */
  3653. u32tmp[0] = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, 0x38);
  3654. u32tmp[1] = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, 0x54);
  3655. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x73);
  3656. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s",
  3657. "LTE Coex/Path Owner",
  3658. ((lte_coex_on) ? "On" : "Off") ,
  3659. ((u8tmp[0] & BIT(2)) ? "WL" : "BT"));
  3660. CL_PRINTF(cli_buf);
  3661. if (lte_coex_on) {
  3662. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
  3663. "LTE 3Wire/OPMode/UART/UARTMode",
  3664. (int)((u32tmp[0] & BIT(6)) >> 6),
  3665. (int)((u32tmp[0] & (BIT(5) | BIT(4))) >> 4),
  3666. (int)((u32tmp[0] & BIT(3)) >> 3),
  3667. (int)(u32tmp[0] & (BIT(2) | BIT(1) | BIT(0))));
  3668. CL_PRINTF(cli_buf);
  3669. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
  3670. "LTE_Busy/UART_Busy",
  3671. (int)((u32tmp[1] & BIT(1)) >> 1), (int)(u32tmp[1] & BIT(0)));
  3672. CL_PRINTF(cli_buf);
  3673. }
  3674. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3675. "\r\n %-35s = %s (BB:%s)/ %s (BB:%s)/ %s",
  3676. "GNT_WL_Ctrl/GNT_BT_Ctrl/Dbg",
  3677. ((u32tmp[0] & BIT(12)) ? "SW" : "HW"),
  3678. ((u32tmp[0] & BIT(8)) ? "SW" : "HW"),
  3679. ((u32tmp[0] & BIT(14)) ? "SW" : "HW"),
  3680. ((u32tmp[0] & BIT(10)) ? "SW" : "HW"),
  3681. ((u8tmp[0] & BIT(3)) ? "On" : "Off"));
  3682. CL_PRINTF(cli_buf);
  3683. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
  3684. "GNT_WL/GNT_BT",
  3685. (int)((u32tmp[1] & BIT(2)) >> 2),
  3686. (int)((u32tmp[1] & BIT(3)) >> 3));
  3687. CL_PRINTF(cli_buf);
  3688. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xcb0);
  3689. u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
  3690. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xcbd);
  3691. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3692. "\r\n %-35s = 0x%04x/ 0x%04x/ 0x%x",
  3693. "0xcb0/0xcb4/0xcbd",
  3694. u32tmp[0], u32tmp[1], u8tmp[0]);
  3695. CL_PRINTF(cli_buf);
  3696. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c);
  3697. u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0x64);
  3698. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x4c6);
  3699. u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x40);
  3700. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3701. "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
  3702. "0x4c[24:23]/0x64[0]/x4c6[4]/0x40[5]",
  3703. (u32tmp[0] & (BIT(24) | BIT(23))) >> 23 , u8tmp[2] & 0x1 ,
  3704. (int)((u8tmp[0] & BIT(4)) >> 4),
  3705. (int)((u8tmp[1] & BIT(5)) >> 5));
  3706. CL_PRINTF(cli_buf);
  3707. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
  3708. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
  3709. u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x953);
  3710. u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0xc50);
  3711. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3712. "\r\n %-35s = 0x%x/ 0x%x/ %s/ 0x%x",
  3713. "0x550/0x522/4-RxAGC/0xc50",
  3714. u32tmp[0], u8tmp[0], (u8tmp[1] & 0x2) ? "On" : "Off", u8tmp[2]);
  3715. CL_PRINTF(cli_buf);
  3716. fa_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
  3717. PHYDM_INFO_FA_OFDM);
  3718. fa_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
  3719. PHYDM_INFO_FA_CCK);
  3720. cca_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
  3721. PHYDM_INFO_CCA_OFDM);
  3722. cca_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
  3723. PHYDM_INFO_CCA_CCK);
  3724. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3725. "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
  3726. "CCK-CCA/CCK-FA/OFDM-CCA/OFDM-FA",
  3727. cca_cck, fa_cck, cca_ofdm, fa_ofdm);
  3728. CL_PRINTF(cli_buf);
  3729. #if 1
  3730. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
  3731. "CRC_OK CCK/11g/11n/11ac",
  3732. coex_sta->crc_ok_cck, coex_sta->crc_ok_11g,
  3733. coex_sta->crc_ok_11n, coex_sta->crc_ok_11n_vht);
  3734. CL_PRINTF(cli_buf);
  3735. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
  3736. "CRC_Err CCK/11g/11n/11ac",
  3737. coex_sta->crc_err_cck, coex_sta->crc_err_11g,
  3738. coex_sta->crc_err_11n, coex_sta->crc_err_11n_vht);
  3739. CL_PRINTF(cli_buf);
  3740. #endif
  3741. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
  3742. "0x770(Hi-pri rx/tx)",
  3743. coex_sta->high_priority_rx, coex_sta->high_priority_tx);
  3744. CL_PRINTF(cli_buf);
  3745. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
  3746. "0x774(Lo-pri rx/tx)",
  3747. coex_sta->low_priority_rx, coex_sta->low_priority_tx);
  3748. CL_PRINTF(cli_buf);
  3749. btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS);
  3750. }
  3751. void ex_halbtc8822b2ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type)
  3752. {
  3753. if (btcoexist->manual_control || btcoexist->stop_coex_dm)
  3754. return;
  3755. if (BTC_IPS_ENTER == type) {
  3756. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3757. "[BTCoex], IPS ENTER notify\n");
  3758. BTC_TRACE(trace_buf);
  3759. coex_sta->under_ips = true;
  3760. coex_sta->under_lps = false;
  3761. halbtc8822b2ant_post_state_to_bt(btcoexist,
  3762. BT_8822B_2ANT_SCOREBOARD_ACTIVE, false);
  3763. halbtc8822b2ant_post_state_to_bt(btcoexist,
  3764. BT_8822B_2ANT_SCOREBOARD_ONOFF, false);
  3765. halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
  3766. FORCE_EXEC,
  3767. BT_8822B_2ANT_PHASE_WLAN_OFF);
  3768. halbtc8822b2ant_action_coex_all_off(btcoexist);
  3769. } else if (BTC_IPS_LEAVE == type) {
  3770. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3771. "[BTCoex], IPS LEAVE notify\n");
  3772. BTC_TRACE(trace_buf);
  3773. coex_sta->under_ips = false;
  3774. halbtc8822b2ant_post_state_to_bt(btcoexist,
  3775. BT_8822B_2ANT_SCOREBOARD_ACTIVE, true);
  3776. halbtc8822b2ant_post_state_to_bt(btcoexist,
  3777. BT_8822B_2ANT_SCOREBOARD_ONOFF, true);
  3778. halbtc8822b2ant_init_hw_config(btcoexist, false);
  3779. halbtc8822b2ant_init_coex_dm(btcoexist);
  3780. halbtc8822b2ant_query_bt_info(btcoexist);
  3781. }
  3782. }
  3783. void ex_halbtc8822b2ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type)
  3784. {
  3785. if (btcoexist->manual_control || btcoexist->stop_coex_dm)
  3786. return;
  3787. if (BTC_LPS_ENABLE == type) {
  3788. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3789. "[BTCoex], LPS ENABLE notify\n");
  3790. BTC_TRACE(trace_buf);
  3791. coex_sta->under_lps = true;
  3792. coex_sta->under_ips = false;
  3793. if (coex_sta->force_lps_on == true) { /* LPS No-32K */
  3794. /* Write WL "Active" in Score-board for PS-TDMA */
  3795. halbtc8822b2ant_post_state_to_bt(btcoexist,
  3796. BT_8822B_2ANT_SCOREBOARD_ACTIVE, true);
  3797. } else { /* LPS-32K, need check if this h2c 0x71 can work?? (2015/08/28) */
  3798. /* Write WL "Non-Active" in Score-board for Native-PS */
  3799. halbtc8822b2ant_post_state_to_bt(btcoexist,
  3800. BT_8822B_2ANT_SCOREBOARD_ACTIVE, false);
  3801. }
  3802. } else if (BTC_LPS_DISABLE == type) {
  3803. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3804. "[BTCoex], LPS DISABLE notify\n");
  3805. BTC_TRACE(trace_buf);
  3806. coex_sta->under_lps = false;
  3807. halbtc8822b2ant_post_state_to_bt(btcoexist,
  3808. BT_8822B_2ANT_SCOREBOARD_ACTIVE, true);
  3809. }
  3810. }
  3811. void ex_halbtc8822b2ant_scan_notify(IN struct btc_coexist *btcoexist,
  3812. IN u8 type)
  3813. {
  3814. boolean wifi_connected = false;
  3815. boolean wifi_under_5g = false;
  3816. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3817. "[BTCoex], SCAN notify()\n");
  3818. BTC_TRACE(trace_buf);
  3819. halbtc8822b2ant_post_state_to_bt(btcoexist,
  3820. BT_8822B_2ANT_SCOREBOARD_ACTIVE, true);
  3821. if (btcoexist->manual_control ||
  3822. btcoexist->stop_coex_dm)
  3823. return;
  3824. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  3825. &wifi_connected);
  3826. /* this can't be removed for RF off_on event, or BT would dis-connect */
  3827. halbtc8822b2ant_query_bt_info(btcoexist);
  3828. if (BTC_SCAN_START == type) {
  3829. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G,
  3830. &wifi_under_5g);
  3831. if (wifi_under_5g) {
  3832. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3833. "[BTCoex], ********** SCAN START notify (5g)\n");
  3834. BTC_TRACE(trace_buf);
  3835. halbtc8822b2ant_action_wifi_under5g(btcoexist);
  3836. return;
  3837. }
  3838. coex_sta->wifi_is_high_pri_task = true;
  3839. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3840. "[BTCoex], ********** SCAN START notify (2g)\n");
  3841. BTC_TRACE(trace_buf);
  3842. halbtc8822b2ant_run_coexist_mechanism(
  3843. btcoexist);
  3844. return;
  3845. }
  3846. if (BTC_SCAN_START_2G == type) {
  3847. if (!wifi_connected)
  3848. coex_sta->wifi_is_high_pri_task = true;
  3849. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3850. "[BTCoex], SCAN START notify (2G)\n");
  3851. BTC_TRACE(trace_buf);
  3852. halbtc8822b2ant_post_state_to_bt(btcoexist,
  3853. BT_8822B_2ANT_SCOREBOARD_SCAN, true);
  3854. halbtc8822b2ant_post_state_to_bt(btcoexist,
  3855. BT_8822B_2ANT_SCOREBOARD_ACTIVE, true);
  3856. halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
  3857. FORCE_EXEC,
  3858. BT_8822B_2ANT_PHASE_2G_RUNTIME);
  3859. halbtc8822b2ant_run_coexist_mechanism(btcoexist);
  3860. } else if (BTC_SCAN_FINISH == type) {
  3861. coex_sta->wifi_is_high_pri_task = false;
  3862. btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
  3863. &coex_sta->scan_ap_num);
  3864. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3865. "[BTCoex], SCAN FINISH notify (Scan-AP = %d)\n",
  3866. coex_sta->scan_ap_num);
  3867. BTC_TRACE(trace_buf);
  3868. halbtc8822b2ant_post_state_to_bt(btcoexist,
  3869. BT_8822B_2ANT_SCOREBOARD_SCAN, false);
  3870. halbtc8822b2ant_run_coexist_mechanism(btcoexist);
  3871. }
  3872. }
  3873. void ex_halbtc8822b2ant_switchband_notify(IN struct btc_coexist *btcoexist,
  3874. IN u8 type)
  3875. {
  3876. boolean wifi_connected = false, bt_hs_on = false;
  3877. u32 wifi_link_status = 0;
  3878. u32 num_of_wifi_link = 0;
  3879. boolean bt_ctrl_agg_buf_size = false;
  3880. u8 agg_buf_size = 5;
  3881. if (btcoexist->manual_control ||
  3882. btcoexist->stop_coex_dm)
  3883. return;
  3884. if (type == BTC_SWITCH_TO_5G) {
  3885. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3886. "[BTCoex], switchband_notify --- switch to 5G\n");
  3887. BTC_TRACE(trace_buf);
  3888. halbtc8822b2ant_action_wifi_under5g(btcoexist);
  3889. } else if (type == BTC_SWITCH_TO_24G_NOFORSCAN) {
  3890. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3891. "[BTCoex], ********** switchband_notify BTC_SWITCH_TO_2G (no for scan)\n");
  3892. BTC_TRACE(trace_buf);
  3893. halbtc8822b2ant_run_coexist_mechanism(btcoexist);
  3894. } else {
  3895. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3896. "[BTCoex], switchband_notify --- switch to 2G\n");
  3897. BTC_TRACE(trace_buf);
  3898. ex_halbtc8822b2ant_scan_notify(btcoexist,
  3899. BTC_SCAN_START_2G);
  3900. }
  3901. }
  3902. void ex_halbtc8822b2ant_connect_notify(IN struct btc_coexist *btcoexist,
  3903. IN u8 type)
  3904. {
  3905. halbtc8822b2ant_post_state_to_bt(btcoexist,
  3906. BT_8822B_2ANT_SCOREBOARD_ACTIVE, true);
  3907. if (btcoexist->manual_control ||
  3908. btcoexist->stop_coex_dm)
  3909. return;
  3910. if ((BTC_ASSOCIATE_5G_START == type) ||
  3911. (BTC_ASSOCIATE_5G_FINISH == type)) {
  3912. if (BTC_ASSOCIATE_5G_START == type)
  3913. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3914. "[BTCoex], connect_notify --- 5G start\n");
  3915. else
  3916. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3917. "[BTCoex], connect_notify --- 5G finish\n");
  3918. BTC_TRACE(trace_buf);
  3919. halbtc8822b2ant_action_wifi_under5g(btcoexist);
  3920. return;
  3921. }
  3922. if (BTC_ASSOCIATE_START == type) {
  3923. coex_sta->wifi_is_high_pri_task = true;
  3924. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3925. "[BTCoex], CONNECT START notify (2G)\n");
  3926. BTC_TRACE(trace_buf);
  3927. halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
  3928. FORCE_EXEC,
  3929. BT_8822B_2ANT_PHASE_2G_RUNTIME);
  3930. halbtc8822b2ant_action_wifi_link_process(btcoexist);
  3931. /* To keep TDMA case during connect process,
  3932. to avoid changed by Btinfo and runcoexmechanism */
  3933. coex_sta->freeze_coexrun_by_btinfo = true;
  3934. coex_dm->arp_cnt = 0;
  3935. } else if (BTC_ASSOCIATE_FINISH == type) {
  3936. coex_sta->wifi_is_high_pri_task = false;
  3937. coex_sta->freeze_coexrun_by_btinfo = false;
  3938. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3939. "[BTCoex], CONNECT FINISH notify (2G)\n");
  3940. BTC_TRACE(trace_buf);
  3941. halbtc8822b2ant_run_coexist_mechanism(btcoexist);
  3942. }
  3943. }
  3944. void ex_halbtc8822b2ant_media_status_notify(IN struct btc_coexist *btcoexist,
  3945. IN u8 type)
  3946. {
  3947. u8 h2c_parameter[3] = {0};
  3948. u32 wifi_bw;
  3949. u8 wifi_central_chnl;
  3950. u8 ap_num = 0;
  3951. boolean wifi_under_b_mode = false, wifi_under_5g = false;
  3952. if (btcoexist->manual_control ||
  3953. btcoexist->stop_coex_dm)
  3954. return;
  3955. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  3956. if (BTC_MEDIA_CONNECT == type) {
  3957. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3958. "[BTCoex], MEDIA connect notify\n");
  3959. BTC_TRACE(trace_buf);
  3960. halbtc8822b2ant_post_state_to_bt(btcoexist,
  3961. BT_8822B_2ANT_SCOREBOARD_ACTIVE, true);
  3962. if (wifi_under_5g) {
  3963. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3964. "[BTCoex], WiFi is under 5G!!!\n");
  3965. BTC_TRACE(trace_buf);
  3966. halbtc8822b2ant_action_wifi_under5g(btcoexist);
  3967. return;
  3968. }
  3969. halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
  3970. FORCE_EXEC,
  3971. BT_8822B_2ANT_PHASE_2G_RUNTIME);
  3972. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
  3973. &wifi_under_b_mode);
  3974. /* Set CCK Tx/Rx high Pri except 11b mode */
  3975. if (wifi_under_b_mode) {
  3976. btcoexist->btc_write_1byte(btcoexist, 0x6cd,
  3977. 0x00); /* CCK Tx */
  3978. btcoexist->btc_write_1byte(btcoexist, 0x6cf,
  3979. 0x00); /* CCK Rx */
  3980. } else {
  3981. btcoexist->btc_write_1byte(btcoexist, 0x6cd,
  3982. 0x00); /* CCK Tx */
  3983. btcoexist->btc_write_1byte(btcoexist, 0x6cf,
  3984. 0x10); /* CCK Rx */
  3985. }
  3986. } else {
  3987. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3988. "[BTCoex], MEDIA disconnect notify\n");
  3989. BTC_TRACE(trace_buf);
  3990. btcoexist->btc_write_1byte(btcoexist, 0x6cd, 0x0); /* CCK Tx */
  3991. btcoexist->btc_write_1byte(btcoexist, 0x6cf, 0x0); /* CCK Rx */
  3992. halbtc8822b2ant_post_state_to_bt(btcoexist,
  3993. BT_8822B_2ANT_SCOREBOARD_ACTIVE, false);
  3994. }
  3995. halbtc8822b2ant_update_wifi_channel_info(btcoexist, type);
  3996. }
  3997. void ex_halbtc8822b2ant_specific_packet_notify(IN struct btc_coexist *btcoexist,
  3998. IN u8 type)
  3999. {
  4000. boolean under_4way = false, wifi_under_5g = false;
  4001. if (btcoexist->manual_control ||
  4002. btcoexist->stop_coex_dm)
  4003. return;
  4004. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  4005. if (wifi_under_5g) {
  4006. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4007. "[BTCoex], WiFi is under 5G!!!\n");
  4008. BTC_TRACE(trace_buf);
  4009. halbtc8822b2ant_action_wifi_under5g(btcoexist);
  4010. return;
  4011. }
  4012. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
  4013. &under_4way);
  4014. if (under_4way) {
  4015. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4016. "[BTCoex], specific Packet ---- under_4way!!\n");
  4017. BTC_TRACE(trace_buf);
  4018. coex_sta->wifi_is_high_pri_task = true;
  4019. coex_sta->specific_pkt_period_cnt = 2;
  4020. } else if (BTC_PACKET_ARP == type) {
  4021. coex_dm->arp_cnt++;
  4022. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4023. "[BTCoex], specific Packet ARP notify -cnt = %d\n",
  4024. coex_dm->arp_cnt);
  4025. BTC_TRACE(trace_buf);
  4026. } else {
  4027. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4028. "[BTCoex], specific Packet DHCP or EAPOL notify [Type = %d]\n",
  4029. type);
  4030. BTC_TRACE(trace_buf);
  4031. coex_sta->wifi_is_high_pri_task = true;
  4032. coex_sta->specific_pkt_period_cnt = 2;
  4033. }
  4034. if (coex_sta->wifi_is_high_pri_task)
  4035. halbtc8822b2ant_run_coexist_mechanism(btcoexist);
  4036. }
  4037. void ex_halbtc8822b2ant_bt_info_notify(IN struct btc_coexist *btcoexist,
  4038. IN u8 *tmp_buf, IN u8 length)
  4039. {
  4040. u8 i, rsp_source = 0;
  4041. boolean wifi_connected = false;
  4042. if (psd_scan->is_AntDet_running == true) {
  4043. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4044. "[BTCoex], bt_info_notify return for AntDet is running\n");
  4045. BTC_TRACE(trace_buf);
  4046. return;
  4047. }
  4048. rsp_source = tmp_buf[0] & 0xf;
  4049. if (rsp_source >= BT_INFO_SRC_8822B_2ANT_MAX)
  4050. rsp_source = BT_INFO_SRC_8822B_2ANT_WIFI_FW;
  4051. coex_sta->bt_info_c2h_cnt[rsp_source]++;
  4052. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4053. "[BTCoex], Bt_info[%d], len=%d, data=[", rsp_source,
  4054. length);
  4055. BTC_TRACE(trace_buf);
  4056. for (i = 0; i < length; i++) {
  4057. coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i];
  4058. if (i == length - 1) {
  4059. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n",
  4060. tmp_buf[i]);
  4061. BTC_TRACE(trace_buf);
  4062. } else {
  4063. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ",
  4064. tmp_buf[i]);
  4065. BTC_TRACE(trace_buf);
  4066. }
  4067. }
  4068. coex_sta->bt_info = coex_sta->bt_info_c2h[rsp_source][1];
  4069. coex_sta->bt_info_ext = coex_sta->bt_info_c2h[rsp_source][4];
  4070. coex_sta->bt_info_ext2 = coex_sta->bt_info_c2h[rsp_source][5];
  4071. if (BT_INFO_SRC_8822B_2ANT_WIFI_FW != rsp_source) {
  4072. /* if 0xff, it means BT is under WHCK test */
  4073. coex_sta->bt_whck_test = ((coex_sta->bt_info == 0xff) ? true :
  4074. false);
  4075. coex_sta->bt_create_connection = ((
  4076. coex_sta->bt_info_c2h[rsp_source][2] & 0x80) ? true :
  4077. false);
  4078. /* unit: %, value-100 to translate to unit: dBm */
  4079. coex_sta->bt_rssi = coex_sta->bt_info_c2h[rsp_source][3] * 2 +
  4080. 10;
  4081. coex_sta->c2h_bt_remote_name_req = ((
  4082. coex_sta->bt_info_c2h[rsp_source][2] & 0x20) ? true :
  4083. false);
  4084. coex_sta->is_A2DP_3M = ((coex_sta->bt_info_c2h[rsp_source][2] &
  4085. 0x10) ? true : false);
  4086. coex_sta->acl_busy = ((coex_sta->bt_info_c2h[rsp_source][1] &
  4087. 0x9) ? true : false);
  4088. coex_sta->voice_over_HOGP = ((coex_sta->bt_info_ext & 0x10) ?
  4089. true : false);
  4090. coex_sta->c2h_bt_inquiry_page = ((coex_sta->bt_info &
  4091. BT_INFO_8822B_2ANT_B_INQ_PAGE) ? true : false);
  4092. coex_sta->a2dp_bit_pool = (((
  4093. coex_sta->bt_info_c2h[rsp_source][1] & 0x49) == 0x49) ?
  4094. coex_sta->bt_info_c2h[rsp_source][6] : 0);
  4095. coex_sta->bt_retry_cnt = coex_sta->bt_info_c2h[rsp_source][2] &
  4096. 0xf;
  4097. coex_sta->is_autoslot = coex_sta->bt_info_ext2 & 0x8;
  4098. coex_sta->forbidden_slot = coex_sta->bt_info_ext2 & 0x7;
  4099. coex_sta->hid_busy_num = (coex_sta->bt_info_ext2 & 0x30) >> 4;
  4100. coex_sta->hid_pair_cnt = (coex_sta->bt_info_ext2 & 0xc0) >> 6;
  4101. if (coex_sta->bt_retry_cnt >= 1)
  4102. coex_sta->pop_event_cnt++;
  4103. if (coex_sta->c2h_bt_remote_name_req)
  4104. coex_sta->cnt_RemoteNameReq++;
  4105. if (coex_sta->bt_info_ext & BIT(1))
  4106. coex_sta->cnt_ReInit++;
  4107. if (coex_sta->bt_info_ext & BIT(2)) {
  4108. coex_sta->cnt_setupLink++;
  4109. coex_sta->is_setupLink = true;
  4110. } else
  4111. coex_sta->is_setupLink = false;
  4112. if (coex_sta->bt_info_ext & BIT(3))
  4113. coex_sta->cnt_IgnWlanAct++;
  4114. if (coex_sta->bt_create_connection)
  4115. coex_sta->cnt_Page++;
  4116. /* Here we need to resend some wifi info to BT */
  4117. /* because bt is reset and loss of the info. */
  4118. if ((!btcoexist->manual_control) &&
  4119. (!btcoexist->stop_coex_dm)) {
  4120. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  4121. &wifi_connected);
  4122. /* Re-Init */
  4123. if ((coex_sta->bt_info_ext & BIT(1))) {
  4124. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4125. "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
  4126. BTC_TRACE(trace_buf);
  4127. if (wifi_connected)
  4128. halbtc8822b2ant_update_wifi_channel_info(
  4129. btcoexist, BTC_MEDIA_CONNECT);
  4130. else
  4131. halbtc8822b2ant_update_wifi_channel_info(
  4132. btcoexist,
  4133. BTC_MEDIA_DISCONNECT);
  4134. }
  4135. /* If Ignore_WLanAct && not SetUp_Link */
  4136. if ((coex_sta->bt_info_ext & BIT(3)) &&
  4137. (!(coex_sta->bt_info_ext & BIT(2)))) {
  4138. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4139. "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n");
  4140. BTC_TRACE(trace_buf);
  4141. halbtc8822b2ant_ignore_wlan_act(btcoexist,
  4142. FORCE_EXEC, false);
  4143. }
  4144. }
  4145. }
  4146. halbtc8822b2ant_update_bt_link_info(btcoexist);
  4147. if (btcoexist->manual_control) {
  4148. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4149. "[BTCoex], BtInfoNotify(), No run_coexist_mechanism for Manual CTRL\n");
  4150. BTC_TRACE(trace_buf);
  4151. return;
  4152. }
  4153. if (btcoexist->stop_coex_dm) {
  4154. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4155. "[BTCoex], BtInfoNotify(), No run_coexist_mechanism for Stop Coex DM\n");
  4156. BTC_TRACE(trace_buf);
  4157. return;
  4158. }
  4159. coex_sta->c2h_bt_info_req_sent = false;
  4160. halbtc8822b2ant_run_coexist_mechanism(btcoexist);
  4161. }
  4162. void ex_halbtc8822b2ant_rf_status_notify(IN struct btc_coexist *btcoexist,
  4163. IN u8 type)
  4164. {
  4165. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], RF Status notify\n");
  4166. BTC_TRACE(trace_buf);
  4167. if (BTC_RF_ON == type) {
  4168. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4169. "[BTCoex], RF is turned ON!!\n");
  4170. BTC_TRACE(trace_buf);
  4171. coex_sta->wl_rf_off_on_event = true;
  4172. btcoexist->stop_coex_dm = false;
  4173. halbtc8822b2ant_post_state_to_bt(btcoexist,
  4174. BT_8822B_2ANT_SCOREBOARD_ACTIVE, true);
  4175. halbtc8822b2ant_post_state_to_bt(btcoexist,
  4176. BT_8822B_2ANT_SCOREBOARD_ONOFF, true);
  4177. } else if (BTC_RF_OFF == type) {
  4178. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4179. "[BTCoex], RF is turned OFF!!\n");
  4180. BTC_TRACE(trace_buf);
  4181. halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
  4182. FORCE_EXEC,
  4183. BT_8822B_2ANT_PHASE_WLAN_OFF);
  4184. halbtc8822b2ant_action_coex_all_off(btcoexist);
  4185. halbtc8822b2ant_post_state_to_bt(btcoexist,
  4186. BT_8822B_2ANT_SCOREBOARD_ACTIVE, false);
  4187. halbtc8822b2ant_post_state_to_bt(btcoexist,
  4188. BT_8822B_2ANT_SCOREBOARD_ONOFF, false);
  4189. btcoexist->stop_coex_dm = true;
  4190. coex_sta->wl_rf_off_on_event = false;
  4191. }
  4192. }
  4193. void ex_halbtc8822b2ant_halt_notify(IN struct btc_coexist *btcoexist)
  4194. {
  4195. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n");
  4196. BTC_TRACE(trace_buf);
  4197. halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC,
  4198. BT_8822B_2ANT_PHASE_WLAN_OFF);
  4199. ex_halbtc8822b2ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT);
  4200. halbtc8822b2ant_post_state_to_bt(btcoexist,
  4201. BT_8822B_2ANT_SCOREBOARD_ACTIVE, false);
  4202. halbtc8822b2ant_post_state_to_bt(btcoexist,
  4203. BT_8822B_2ANT_SCOREBOARD_ONOFF, false);
  4204. }
  4205. void ex_halbtc8822b2ant_pnp_notify(IN struct btc_coexist *btcoexist,
  4206. IN u8 pnp_state)
  4207. {
  4208. boolean wifi_under_5g = false;
  4209. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Pnp notify\n");
  4210. BTC_TRACE(trace_buf);
  4211. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  4212. if ((BTC_WIFI_PNP_SLEEP == pnp_state) ||
  4213. (BTC_WIFI_PNP_SLEEP_KEEP_ANT == pnp_state)) {
  4214. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4215. "[BTCoex], Pnp notify to SLEEP\n");
  4216. BTC_TRACE(trace_buf);
  4217. /* Sinda 20150819, workaround for driver skip leave IPS/LPS to speed up sleep time. */
  4218. /* Driver do not leave IPS/LPS when driver is going to sleep, so BTCoexistence think wifi is still under IPS/LPS */
  4219. /* BT should clear UnderIPS/UnderLPS state to avoid mismatch state after wakeup. */
  4220. coex_sta->under_ips = false;
  4221. coex_sta->under_lps = false;
  4222. halbtc8822b2ant_post_state_to_bt(btcoexist,
  4223. BT_8822B_2ANT_SCOREBOARD_ACTIVE, false);
  4224. halbtc8822b2ant_post_state_to_bt(btcoexist,
  4225. BT_8822B_2ANT_SCOREBOARD_ONOFF, false);
  4226. if (BTC_WIFI_PNP_SLEEP_KEEP_ANT == pnp_state) {
  4227. if (wifi_under_5g)
  4228. halbtc8822b2ant_set_ant_path(btcoexist,
  4229. BTC_ANT_PATH_AUTO, FORCE_EXEC,
  4230. BT_8822B_2ANT_PHASE_5G_RUNTIME);
  4231. else
  4232. halbtc8822b2ant_set_ant_path(btcoexist,
  4233. BTC_ANT_PATH_AUTO, FORCE_EXEC,
  4234. BT_8822B_2ANT_PHASE_2G_RUNTIME);
  4235. } else {
  4236. halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO,
  4237. FORCE_EXEC,
  4238. BT_8822B_2ANT_PHASE_WLAN_OFF);
  4239. }
  4240. } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) {
  4241. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4242. "[BTCoex], Pnp notify to WAKE UP\n");
  4243. BTC_TRACE(trace_buf);
  4244. halbtc8822b2ant_post_state_to_bt(btcoexist,
  4245. BT_8822B_2ANT_SCOREBOARD_ACTIVE, true);
  4246. halbtc8822b2ant_post_state_to_bt(btcoexist,
  4247. BT_8822B_2ANT_SCOREBOARD_ONOFF, true);
  4248. }
  4249. }
  4250. void ex_halbtc8822b2ant_periodical(IN struct btc_coexist *btcoexist)
  4251. {
  4252. struct btc_board_info *board_info = &btcoexist->board_info;
  4253. boolean wifi_busy = false;
  4254. u32 bt_patch_ver;
  4255. u16 bt_scoreboard_val = 0;
  4256. static u8 cnt = 0;
  4257. boolean bt_relink_finish = false;
  4258. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4259. "[BTCoex], ************* Periodical *************\n");
  4260. BTC_TRACE(trace_buf);
  4261. #if (BT_AUTO_REPORT_ONLY_8822B_2ANT == 0)
  4262. halbtc8822b2ant_query_bt_info(btcoexist);
  4263. #endif
  4264. halbtc8822b2ant_monitor_bt_ctr(btcoexist);
  4265. halbtc8822b2ant_monitor_wifi_ctr(btcoexist);
  4266. halbtc8822b2ant_monitor_bt_enable_disable(btcoexist);
  4267. #if 1
  4268. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  4269. halbtc8822b2ant_read_score_board(btcoexist, &bt_scoreboard_val);
  4270. if (wifi_busy) {
  4271. halbtc8822b2ant_post_state_to_bt(btcoexist,
  4272. BT_8822B_2ANT_SCOREBOARD_UNDERTEST, true);
  4273. /*for bt lps32 clock offset*/
  4274. if (bt_scoreboard_val & BIT(6))
  4275. halbtc8822b2ant_query_bt_info(btcoexist);
  4276. } else {
  4277. halbtc8822b2ant_post_state_to_bt(btcoexist,
  4278. BT_8822B_2ANT_SCOREBOARD_UNDERTEST, false);
  4279. /*
  4280. halbtc8822b2ant_post_state_to_bt(btcoexist,
  4281. BT_8822B_2ANT_SCOREBOARD_WLBUSY,
  4282. false); */
  4283. }
  4284. #endif
  4285. if (coex_sta->bt_relink_downcount != 0) {
  4286. coex_sta->bt_relink_downcount--;
  4287. if (coex_sta->bt_relink_downcount == 0)
  4288. bt_relink_finish = true;
  4289. }
  4290. /* for 4-way, DHCP, EAPOL packet */
  4291. if (coex_sta->specific_pkt_period_cnt > 0) {
  4292. coex_sta->specific_pkt_period_cnt--;
  4293. if ((coex_sta->specific_pkt_period_cnt == 0) &&
  4294. (coex_sta->wifi_is_high_pri_task))
  4295. coex_sta->wifi_is_high_pri_task = false;
  4296. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4297. "[BTCoex], ***************** Hi-Pri Task = %s*****************\n",
  4298. (coex_sta->wifi_is_high_pri_task ? "Yes" :
  4299. "No"));
  4300. BTC_TRACE(trace_buf);
  4301. }
  4302. if (!coex_sta->bt_disabled) {
  4303. if (coex_sta->bt_coex_supported_feature == 0)
  4304. btcoexist->btc_get(btcoexist, BTC_GET_U4_SUPPORTED_FEATURE, &coex_sta->bt_coex_supported_feature);
  4305. if ((coex_sta->bt_coex_supported_version == 0) ||
  4306. (coex_sta->bt_coex_supported_version == 0xffff))
  4307. btcoexist->btc_get(btcoexist, BTC_GET_U4_SUPPORTED_VERSION, &coex_sta->bt_coex_supported_version);
  4308. /*coex_sta->bt_ble_scan_type = btcoexist->btc_get_ble_scan_type_from_bt(btcoexist);*/
  4309. btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
  4310. btcoexist->bt_info.bt_get_fw_ver = bt_patch_ver;
  4311. if (coex_sta->bt_reg_vendor_ac == 0xffff)
  4312. coex_sta->bt_reg_vendor_ac = (u16)(
  4313. btcoexist->btc_get_bt_reg(btcoexist, 3,
  4314. 0xac) & 0xffff);
  4315. if (coex_sta->bt_reg_vendor_ae == 0xffff)
  4316. coex_sta->bt_reg_vendor_ae = (u16)(
  4317. btcoexist->btc_get_bt_reg(btcoexist, 3,
  4318. 0xae) & 0xffff);
  4319. }
  4320. if (halbtc8822b2ant_is_wifibt_status_changed(btcoexist))
  4321. halbtc8822b2ant_run_coexist_mechanism(btcoexist);
  4322. }
  4323. /*#pragma optimize( "", off )*/
  4324. void ex_halbtc8822b2ant_antenna_detection(IN struct btc_coexist *btcoexist,
  4325. IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds)
  4326. {
  4327. #if 0
  4328. static u32 ant_det_count = 0, ant_det_fail_count = 0;
  4329. struct btc_board_info *board_info = &btcoexist->board_info;
  4330. u16 u16tmp;
  4331. u8 AntDetval = 0;
  4332. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4333. "xxxxxxxxxxxxxxxx Ext Call AntennaDetect()!!\n");
  4334. BTC_TRACE(trace_buf);
  4335. #if BT_8822B_2ANT_ANTDET_ENABLE
  4336. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4337. "xxxxxxxxxxxxxxxx Call AntennaDetect()!!\n");
  4338. BTC_TRACE(trace_buf);
  4339. if (seconds == 0) {
  4340. psd_scan->ant_det_try_count = 0;
  4341. psd_scan->ant_det_fail_count = 0;
  4342. ant_det_count = 0;
  4343. ant_det_fail_count = 0;
  4344. board_info->btdm_ant_det_finish = false;
  4345. board_info->btdm_ant_num_by_ant_det = 1;
  4346. return;
  4347. }
  4348. if (!board_info->btdm_ant_det_finish) {
  4349. psd_scan->ant_det_inteval_count =
  4350. psd_scan->ant_det_inteval_count + 2;
  4351. if (psd_scan->ant_det_inteval_count >=
  4352. BT_8822B_2ANT_ANTDET_RETRY_INTERVAL) {
  4353. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4354. "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Timer is up, Try Detect!!\n");
  4355. BTC_TRACE(trace_buf);
  4356. psd_scan->is_AntDet_running = true;
  4357. halbtc8822b2ant_read_score_board(btcoexist, &u16tmp);
  4358. if (u16tmp & BIT(
  4359. 2)) { /* Antenna detection is already done before last WL power on */
  4360. board_info->btdm_ant_det_finish = true;
  4361. psd_scan->ant_det_try_count = 1;
  4362. psd_scan->ant_det_fail_count = 0;
  4363. board_info->btdm_ant_num_by_ant_det = (u16tmp &
  4364. BIT(3)) ? 1 : 2;
  4365. psd_scan->ant_det_result = 12;
  4366. psd_scan->ant_det_psd_scan_peak_val =
  4367. btcoexist->btc_get_ant_det_val_from_bt(
  4368. btcoexist) * 100;
  4369. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4370. "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Result from BT (%d-Ant)\n",
  4371. board_info->btdm_ant_num_by_ant_det);
  4372. BTC_TRACE(trace_buf);
  4373. } else
  4374. board_info->btdm_ant_det_finish =
  4375. halbtc8822b2ant_psd_antenna_detection_check(
  4376. btcoexist);
  4377. btcoexist->bdontenterLPS = false;
  4378. if (board_info->btdm_ant_det_finish) {
  4379. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4380. "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Success!!\n");
  4381. BTC_TRACE(trace_buf);
  4382. /*for 8822b, btc_set_bt_trx_mask is just used to
  4383. notify BT stop le tx and Ant Det Result , not set BT RF TRx Mask */
  4384. if (psd_scan->ant_det_result != 12) {
  4385. AntDetval = (u8)((
  4386. psd_scan->ant_det_psd_scan_peak_val
  4387. / 100) & 0x7f);
  4388. AntDetval =
  4389. (board_info->btdm_ant_num_by_ant_det
  4390. == 1) ? (AntDetval | 0x80) :
  4391. AntDetval;
  4392. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4393. "xxxxxx AntennaDetect(), Ant Count = %d, PSD Val = %d\n",
  4394. ((AntDetval &
  4395. 0x80) ? 1
  4396. : 2), AntDetval
  4397. & 0x7f);
  4398. BTC_TRACE(trace_buf);
  4399. if (btcoexist->btc_set_bt_trx_mask(
  4400. btcoexist, AntDetval))
  4401. BTC_SPRINTF(trace_buf,
  4402. BT_TMP_BUF_SIZE,
  4403. "xxxxxx AntennaDetect(), Notify BT stop le tx by set_bt_trx_mask ok!\n");
  4404. else
  4405. BTC_SPRINTF(trace_buf,
  4406. BT_TMP_BUF_SIZE,
  4407. "xxxxxx AntennaDetect(), Notify BT stop le tx by set_bt_trx_mask fail!\n");
  4408. BTC_TRACE(trace_buf);
  4409. }
  4410. } else {
  4411. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4412. "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Fail!!\n");
  4413. BTC_TRACE(trace_buf);
  4414. }
  4415. psd_scan->ant_det_inteval_count = 0;
  4416. psd_scan->is_AntDet_running = false;
  4417. /* stimulate coex running */
  4418. halbtc8822b2ant_run_coexist_mechanism(
  4419. btcoexist);
  4420. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4421. "xxxxxxxxxxxxxxxx AntennaDetect(), Stimulate Coex running\n!!");
  4422. BTC_TRACE(trace_buf);
  4423. } else {
  4424. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4425. "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Timer is not up! (%d)\n",
  4426. psd_scan->ant_det_inteval_count);
  4427. BTC_TRACE(trace_buf);
  4428. if (psd_scan->ant_det_inteval_count == 8)
  4429. btcoexist->bdontenterLPS = true;
  4430. else
  4431. btcoexist->bdontenterLPS = false;
  4432. }
  4433. }
  4434. #endif
  4435. #endif
  4436. }
  4437. void ex_halbtc8822b2ant_display_ant_detection(IN struct btc_coexist *btcoexist)
  4438. {
  4439. #if 0
  4440. #if BT_8822B_2ANT_ANTDET_ENABLE
  4441. struct btc_board_info *board_info = &btcoexist->board_info;
  4442. if (psd_scan->ant_det_try_count != 0) {
  4443. halbtc8822b2ant_psd_show_antenna_detect_result(btcoexist);
  4444. if (board_info->btdm_ant_det_finish)
  4445. halbtc8822b2ant_psd_showdata(btcoexist);
  4446. }
  4447. #endif
  4448. #endif
  4449. }
  4450. #endif
  4451. #endif /* #if (RTL8822B_SUPPORT == 1) */