halbtc8821a2ant.c 140 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584
  1. /* ************************************************************
  2. * Description:
  3. *
  4. * This file is for RTL8821A 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 (RTL8821A_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_8821a_2ant glcoex_dm_8821a_2ant;
  21. static struct coex_dm_8821a_2ant *coex_dm = &glcoex_dm_8821a_2ant;
  22. static struct coex_sta_8821a_2ant glcoex_sta_8821a_2ant;
  23. static struct coex_sta_8821a_2ant *coex_sta = &glcoex_sta_8821a_2ant;
  24. const char *const glbt_info_src_8821a_2ant[] = {
  25. "BT Info[wifi fw]",
  26. "BT Info[bt rsp]",
  27. "BT Info[bt auto report]",
  28. };
  29. u32 glcoex_ver_date_8821a_2ant = 20161128;
  30. u32 glcoex_ver_8821a_2ant = 0x60;
  31. u32 glcoex_ver_btdesired_8821a_2ant = 0x5c;
  32. /* modify 20140903v43 a2dpandhid tdmaonoff a2dp glitch _ tdma off 778=3(case1)->778=1(case0)
  33. * and to improve tp while a2dphid case23->case25 , case123->case125 for asus spec
  34. * and modify for asus bt WHQL test _ tdma off_ 778=3->1_
  35. * ************************************************************
  36. * local function proto type if needed
  37. * ************************************************************
  38. * ************************************************************
  39. * local function start with halbtc8821a2ant_
  40. * ************************************************************ */
  41. u8 halbtc8821a2ant_bt_rssi_state(u8 level_num, u8 rssi_thresh, u8 rssi_thresh1)
  42. {
  43. s32 bt_rssi = 0;
  44. u8 bt_rssi_state = coex_sta->pre_bt_rssi_state;
  45. bt_rssi = coex_sta->bt_rssi;
  46. if (level_num == 2) {
  47. if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
  48. (coex_sta->pre_bt_rssi_state ==
  49. BTC_RSSI_STATE_STAY_LOW)) {
  50. if (bt_rssi >= (rssi_thresh +
  51. BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT))
  52. bt_rssi_state = BTC_RSSI_STATE_HIGH;
  53. else
  54. bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  55. } else {
  56. if (bt_rssi < rssi_thresh)
  57. bt_rssi_state = BTC_RSSI_STATE_LOW;
  58. else
  59. bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  60. }
  61. } else if (level_num == 3) {
  62. if (rssi_thresh > rssi_thresh1) {
  63. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  64. "[BTCoex], BT Rssi thresh error!!\n");
  65. BTC_TRACE(trace_buf);
  66. return coex_sta->pre_bt_rssi_state;
  67. }
  68. if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
  69. (coex_sta->pre_bt_rssi_state ==
  70. BTC_RSSI_STATE_STAY_LOW)) {
  71. if (bt_rssi >= (rssi_thresh +
  72. BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT))
  73. bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
  74. else
  75. bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  76. } else if ((coex_sta->pre_bt_rssi_state ==
  77. BTC_RSSI_STATE_MEDIUM) ||
  78. (coex_sta->pre_bt_rssi_state ==
  79. BTC_RSSI_STATE_STAY_MEDIUM)) {
  80. if (bt_rssi >= (rssi_thresh1 +
  81. BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT))
  82. bt_rssi_state = BTC_RSSI_STATE_HIGH;
  83. else if (bt_rssi < rssi_thresh)
  84. bt_rssi_state = BTC_RSSI_STATE_LOW;
  85. else
  86. bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
  87. } else {
  88. if (bt_rssi < rssi_thresh1)
  89. bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
  90. else
  91. bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  92. }
  93. }
  94. coex_sta->pre_bt_rssi_state = bt_rssi_state;
  95. return bt_rssi_state;
  96. }
  97. u8 halbtc8821a2ant_wifi_rssi_state(IN struct btc_coexist *btcoexist,
  98. IN u8 index, IN u8 level_num, IN u8 rssi_thresh, IN u8 rssi_thresh1)
  99. {
  100. s32 wifi_rssi = 0;
  101. u8 wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index];
  102. btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
  103. if (level_num == 2) {
  104. if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW)
  105. ||
  106. (coex_sta->pre_wifi_rssi_state[index] ==
  107. BTC_RSSI_STATE_STAY_LOW)) {
  108. if (wifi_rssi >= (rssi_thresh +
  109. BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT))
  110. wifi_rssi_state = BTC_RSSI_STATE_HIGH;
  111. else
  112. wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  113. } else {
  114. if (wifi_rssi < rssi_thresh)
  115. wifi_rssi_state = BTC_RSSI_STATE_LOW;
  116. else
  117. wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  118. }
  119. } else if (level_num == 3) {
  120. if (rssi_thresh > rssi_thresh1) {
  121. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  122. "[BTCoex], wifi RSSI thresh error!!\n");
  123. BTC_TRACE(trace_buf);
  124. return coex_sta->pre_wifi_rssi_state[index];
  125. }
  126. if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW)
  127. ||
  128. (coex_sta->pre_wifi_rssi_state[index] ==
  129. BTC_RSSI_STATE_STAY_LOW)) {
  130. if (wifi_rssi >= (rssi_thresh +
  131. BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT))
  132. wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
  133. else
  134. wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  135. } else if ((coex_sta->pre_wifi_rssi_state[index] ==
  136. BTC_RSSI_STATE_MEDIUM) ||
  137. (coex_sta->pre_wifi_rssi_state[index] ==
  138. BTC_RSSI_STATE_STAY_MEDIUM)) {
  139. if (wifi_rssi >= (rssi_thresh1 +
  140. BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT))
  141. wifi_rssi_state = BTC_RSSI_STATE_HIGH;
  142. else if (wifi_rssi < rssi_thresh)
  143. wifi_rssi_state = BTC_RSSI_STATE_LOW;
  144. else
  145. wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
  146. } else {
  147. if (wifi_rssi < rssi_thresh1)
  148. wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
  149. else
  150. wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  151. }
  152. }
  153. coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state;
  154. return wifi_rssi_state;
  155. }
  156. void halbtc8821a2ant_limited_rx(IN struct btc_coexist *btcoexist,
  157. IN boolean force_exec, IN boolean rej_ap_agg_pkt,
  158. IN boolean bt_ctrl_agg_buf_size, IN u8 agg_buf_size)
  159. {
  160. boolean reject_rx_agg = rej_ap_agg_pkt;
  161. boolean bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size;
  162. u8 rx_agg_size = agg_buf_size;
  163. /* ============================================ */
  164. /* Rx Aggregation related setting */
  165. /* ============================================ */
  166. btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT,
  167. &reject_rx_agg);
  168. /* decide BT control aggregation buf size or not */
  169. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE,
  170. &bt_ctrl_rx_agg_size);
  171. /* aggregation buf size, only work when BT control Rx aggregation size. */
  172. btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size);
  173. /* real update aggregation setting */
  174. btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
  175. }
  176. void halbtc8821a2ant_monitor_bt_ctr(IN struct btc_coexist *btcoexist)
  177. {
  178. u32 reg_hp_txrx, reg_lp_txrx, u32tmp;
  179. u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0;
  180. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  181. reg_hp_txrx = 0x770;
  182. reg_lp_txrx = 0x774;
  183. u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx);
  184. reg_hp_tx = u32tmp & MASKLWORD;
  185. reg_hp_rx = (u32tmp & MASKHWORD) >> 16;
  186. u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx);
  187. reg_lp_tx = u32tmp & MASKLWORD;
  188. reg_lp_rx = (u32tmp & MASKHWORD) >> 16;
  189. coex_sta->high_priority_tx = reg_hp_tx;
  190. coex_sta->high_priority_rx = reg_hp_rx;
  191. coex_sta->low_priority_tx = reg_lp_tx;
  192. coex_sta->low_priority_rx = reg_lp_rx;
  193. if ((coex_sta->low_priority_rx >= 950) &&
  194. (coex_sta->low_priority_rx >= coex_sta->low_priority_tx) &&
  195. (!coex_sta->under_ips))
  196. bt_link_info->slave_role = true;
  197. else
  198. bt_link_info->slave_role = false;
  199. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  200. "[BTCoex], High Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n",
  201. reg_hp_txrx, reg_hp_tx, reg_hp_tx, reg_hp_rx, reg_hp_rx);
  202. BTC_TRACE(trace_buf);
  203. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  204. "[BTCoex], Low Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n",
  205. reg_lp_txrx, reg_lp_tx, reg_lp_tx, reg_lp_rx, reg_lp_rx);
  206. BTC_TRACE(trace_buf);
  207. /* reset counter */
  208. btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
  209. }
  210. void halbtc8821a2ant_monitor_wifi_ctr(IN struct btc_coexist *btcoexist)
  211. {
  212. #if 1
  213. coex_sta->crc_ok_cck = btcoexist->btc_phydm_query_PHY_counter(
  214. btcoexist,
  215. PHYDM_INFO_CRC32_OK_CCK);
  216. coex_sta->crc_ok_11g = btcoexist->btc_phydm_query_PHY_counter(
  217. btcoexist,
  218. PHYDM_INFO_CRC32_OK_LEGACY);
  219. coex_sta->crc_ok_11n = btcoexist->btc_phydm_query_PHY_counter(
  220. btcoexist,
  221. PHYDM_INFO_CRC32_OK_HT);
  222. coex_sta->crc_ok_11n_vht =
  223. btcoexist->btc_phydm_query_PHY_counter(
  224. btcoexist,
  225. PHYDM_INFO_CRC32_OK_VHT);
  226. coex_sta->crc_err_cck = btcoexist->btc_phydm_query_PHY_counter(
  227. btcoexist,
  228. PHYDM_INFO_CRC32_ERROR_CCK);
  229. coex_sta->crc_err_11g = btcoexist->btc_phydm_query_PHY_counter(
  230. btcoexist,
  231. PHYDM_INFO_CRC32_ERROR_LEGACY);
  232. coex_sta->crc_err_11n = btcoexist->btc_phydm_query_PHY_counter(
  233. btcoexist,
  234. PHYDM_INFO_CRC32_ERROR_HT);
  235. coex_sta->crc_err_11n_vht =
  236. btcoexist->btc_phydm_query_PHY_counter(
  237. btcoexist,
  238. PHYDM_INFO_CRC32_ERROR_VHT);
  239. #endif
  240. }
  241. void halbtc8821a2ant_query_bt_info(IN struct btc_coexist *btcoexist)
  242. {
  243. u8 h2c_parameter[1] = {0};
  244. coex_sta->c2h_bt_info_req_sent = true;
  245. h2c_parameter[0] |= BIT(0); /* trigger */
  246. btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter);
  247. }
  248. boolean halbtc8821a2ant_is_wifi_status_changed(IN struct btc_coexist *btcoexist)
  249. {
  250. static boolean pre_wifi_busy = false, pre_under_4way = false,
  251. pre_bt_hs_on = false;
  252. boolean wifi_busy = false, under_4way = false, bt_hs_on = false;
  253. boolean wifi_connected = false;
  254. u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
  255. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  256. &wifi_connected);
  257. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  258. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  259. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
  260. &under_4way);
  261. if (wifi_connected) {
  262. if (wifi_busy != pre_wifi_busy) {
  263. pre_wifi_busy = wifi_busy;
  264. return true;
  265. }
  266. if (under_4way != pre_under_4way) {
  267. pre_under_4way = under_4way;
  268. return true;
  269. }
  270. if (bt_hs_on != pre_bt_hs_on) {
  271. pre_bt_hs_on = bt_hs_on;
  272. return true;
  273. }
  274. wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 3,
  275. 2, BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
  276. if ((BTC_RSSI_STATE_HIGH == wifi_rssi_state) ||
  277. (BTC_RSSI_STATE_LOW == wifi_rssi_state))
  278. return true;
  279. }
  280. return false;
  281. }
  282. void halbtc8821a2ant_monitor_bt_enable_disable(IN struct btc_coexist *btcoexist)
  283. {
  284. static u32 bt_disable_cnt = 0;
  285. boolean bt_active = true, bt_disabled = false;
  286. /* This function check if bt is disabled */
  287. if (coex_sta->high_priority_tx == 0 &&
  288. coex_sta->high_priority_rx == 0 &&
  289. coex_sta->low_priority_tx == 0 &&
  290. coex_sta->low_priority_rx == 0)
  291. bt_active = false;
  292. if (coex_sta->high_priority_tx == 0xffff &&
  293. coex_sta->high_priority_rx == 0xffff &&
  294. coex_sta->low_priority_tx == 0xffff &&
  295. coex_sta->low_priority_rx == 0xffff)
  296. bt_active = false;
  297. if (bt_active) {
  298. bt_disable_cnt = 0;
  299. bt_disabled = false;
  300. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
  301. &bt_disabled);
  302. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  303. "[BTCoex], BT is enabled !!\n");
  304. BTC_TRACE(trace_buf);
  305. } else {
  306. bt_disable_cnt++;
  307. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  308. "[BTCoex], bt all counters=0, %d times!!\n",
  309. bt_disable_cnt);
  310. BTC_TRACE(trace_buf);
  311. if (bt_disable_cnt >= 10) {
  312. bt_disabled = true;
  313. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
  314. &bt_disabled);
  315. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  316. "[BTCoex], BT is disabled !!\n");
  317. BTC_TRACE(trace_buf);
  318. }
  319. }
  320. if (coex_sta->bt_disabled != bt_disabled) {
  321. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  322. "[BTCoex], BT is from %s to %s!!\n",
  323. (coex_sta->bt_disabled ? "disabled" : "enabled"),
  324. (bt_disabled ? "disabled" : "enabled"));
  325. BTC_TRACE(trace_buf);
  326. coex_sta->bt_disabled = bt_disabled;
  327. /* if (!bt_disabled) {} else {} */
  328. }
  329. }
  330. void halbtc8821a2ant_update_bt_link_info(IN struct btc_coexist *btcoexist)
  331. {
  332. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  333. boolean bt_hs_on = false;
  334. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  335. bt_link_info->bt_link_exist = coex_sta->bt_link_exist;
  336. bt_link_info->sco_exist = coex_sta->sco_exist;
  337. bt_link_info->a2dp_exist = coex_sta->a2dp_exist;
  338. bt_link_info->pan_exist = coex_sta->pan_exist;
  339. bt_link_info->hid_exist = coex_sta->hid_exist;
  340. /* work around for HS mode. */
  341. if (bt_hs_on) {
  342. bt_link_info->pan_exist = true;
  343. bt_link_info->bt_link_exist = true;
  344. }
  345. /* check if Sco only */
  346. if (bt_link_info->sco_exist &&
  347. !bt_link_info->a2dp_exist &&
  348. !bt_link_info->pan_exist &&
  349. !bt_link_info->hid_exist)
  350. bt_link_info->sco_only = true;
  351. else
  352. bt_link_info->sco_only = false;
  353. /* check if A2dp only */
  354. if (!bt_link_info->sco_exist &&
  355. bt_link_info->a2dp_exist &&
  356. !bt_link_info->pan_exist &&
  357. !bt_link_info->hid_exist)
  358. bt_link_info->a2dp_only = true;
  359. else
  360. bt_link_info->a2dp_only = false;
  361. /* check if Pan only */
  362. if (!bt_link_info->sco_exist &&
  363. !bt_link_info->a2dp_exist &&
  364. bt_link_info->pan_exist &&
  365. !bt_link_info->hid_exist)
  366. bt_link_info->pan_only = true;
  367. else
  368. bt_link_info->pan_only = false;
  369. /* check if Hid only */
  370. if (!bt_link_info->sco_exist &&
  371. !bt_link_info->a2dp_exist &&
  372. !bt_link_info->pan_exist &&
  373. bt_link_info->hid_exist)
  374. bt_link_info->hid_only = true;
  375. else
  376. bt_link_info->hid_only = false;
  377. }
  378. u8 halbtc8821a2ant_action_algorithm(IN struct btc_coexist *btcoexist)
  379. {
  380. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  381. boolean bt_hs_on = false;
  382. u8 algorithm = BT_8821A_2ANT_COEX_ALGO_UNDEFINED;
  383. u8 num_of_diff_profile = 0;
  384. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  385. if (!bt_link_info->bt_link_exist) {
  386. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  387. "[BTCoex], No BT link exists!!!\n");
  388. BTC_TRACE(trace_buf);
  389. return algorithm;
  390. }
  391. if (bt_link_info->sco_exist)
  392. num_of_diff_profile++;
  393. if (bt_link_info->hid_exist)
  394. num_of_diff_profile++;
  395. if (bt_link_info->pan_exist)
  396. num_of_diff_profile++;
  397. if (bt_link_info->a2dp_exist)
  398. num_of_diff_profile++;
  399. if (num_of_diff_profile == 1) {
  400. if (bt_link_info->sco_exist) {
  401. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  402. "[BTCoex], SCO only\n");
  403. BTC_TRACE(trace_buf);
  404. algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
  405. } else {
  406. if (bt_link_info->hid_exist) {
  407. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  408. "[BTCoex], HID only\n");
  409. BTC_TRACE(trace_buf);
  410. algorithm = BT_8821A_2ANT_COEX_ALGO_HID;
  411. } else if (bt_link_info->a2dp_exist) {
  412. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  413. "[BTCoex], A2DP only\n");
  414. BTC_TRACE(trace_buf);
  415. algorithm = BT_8821A_2ANT_COEX_ALGO_A2DP;
  416. } else if (bt_link_info->pan_exist) {
  417. if (bt_hs_on) {
  418. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  419. "[BTCoex], PAN(HS) only\n");
  420. BTC_TRACE(trace_buf);
  421. algorithm =
  422. BT_8821A_2ANT_COEX_ALGO_PANHS;
  423. } else {
  424. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  425. "[BTCoex], PAN(EDR) only\n");
  426. BTC_TRACE(trace_buf);
  427. algorithm =
  428. BT_8821A_2ANT_COEX_ALGO_PANEDR;
  429. }
  430. }
  431. }
  432. } else if (num_of_diff_profile == 2) {
  433. if (bt_link_info->sco_exist) {
  434. if (bt_link_info->hid_exist) {
  435. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  436. "[BTCoex], SCO + HID\n");
  437. BTC_TRACE(trace_buf);
  438. algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
  439. } else if (bt_link_info->a2dp_exist) {
  440. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  441. "[BTCoex], SCO + A2DP ==> SCO\n");
  442. BTC_TRACE(trace_buf);
  443. algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
  444. } else if (bt_link_info->pan_exist) {
  445. if (bt_hs_on) {
  446. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  447. "[BTCoex], SCO + PAN(HS)\n");
  448. BTC_TRACE(trace_buf);
  449. algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
  450. } else {
  451. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  452. "[BTCoex], SCO + PAN(EDR)\n");
  453. BTC_TRACE(trace_buf);
  454. algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
  455. }
  456. }
  457. } else {
  458. if (bt_link_info->hid_exist &&
  459. bt_link_info->a2dp_exist) {
  460. {
  461. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  462. "[BTCoex], HID + A2DP\n");
  463. BTC_TRACE(trace_buf);
  464. algorithm =
  465. BT_8821A_2ANT_COEX_ALGO_HID_A2DP;
  466. }
  467. } else if (bt_link_info->hid_exist &&
  468. bt_link_info->pan_exist) {
  469. if (bt_hs_on) {
  470. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  471. "[BTCoex], HID + PAN(HS)\n");
  472. BTC_TRACE(trace_buf);
  473. algorithm = BT_8821A_2ANT_COEX_ALGO_HID;
  474. } else {
  475. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  476. "[BTCoex], HID + PAN(EDR)\n");
  477. BTC_TRACE(trace_buf);
  478. algorithm =
  479. BT_8821A_2ANT_COEX_ALGO_PANEDR_HID;
  480. }
  481. } else if (bt_link_info->pan_exist &&
  482. bt_link_info->a2dp_exist) {
  483. if (bt_hs_on) {
  484. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  485. "[BTCoex], A2DP + PAN(HS)\n");
  486. BTC_TRACE(trace_buf);
  487. algorithm =
  488. BT_8821A_2ANT_COEX_ALGO_A2DP_PANHS;
  489. } else {
  490. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  491. "[BTCoex], A2DP + PAN(EDR)\n");
  492. BTC_TRACE(trace_buf);
  493. algorithm =
  494. BT_8821A_2ANT_COEX_ALGO_PANEDR_A2DP;
  495. }
  496. }
  497. }
  498. } else if (num_of_diff_profile == 3) {
  499. if (bt_link_info->sco_exist) {
  500. if (bt_link_info->hid_exist &&
  501. bt_link_info->a2dp_exist) {
  502. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  503. "[BTCoex], SCO + HID + A2DP ==> SCO\n");
  504. BTC_TRACE(trace_buf);
  505. algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
  506. } else if (bt_link_info->hid_exist &&
  507. bt_link_info->pan_exist) {
  508. if (bt_hs_on) {
  509. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  510. "[BTCoex], SCO + HID + PAN(HS) ==> SCO\n");
  511. BTC_TRACE(trace_buf);
  512. algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
  513. } else {
  514. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  515. "[BTCoex], SCO + HID + PAN(EDR) ==> SCO\n");
  516. BTC_TRACE(trace_buf);
  517. algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
  518. }
  519. } else if (bt_link_info->pan_exist &&
  520. bt_link_info->a2dp_exist) {
  521. if (bt_hs_on) {
  522. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  523. "[BTCoex], SCO + A2DP + PAN(HS)\n");
  524. BTC_TRACE(trace_buf);
  525. algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
  526. } else {
  527. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  528. "[BTCoex], SCO + A2DP + PAN(EDR) ==> HID\n");
  529. BTC_TRACE(trace_buf);
  530. algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
  531. }
  532. }
  533. } else {
  534. if (bt_link_info->hid_exist &&
  535. bt_link_info->pan_exist &&
  536. bt_link_info->a2dp_exist) {
  537. if (bt_hs_on) {
  538. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  539. "[BTCoex], HID + A2DP + PAN(HS)\n");
  540. BTC_TRACE(trace_buf);
  541. algorithm =
  542. BT_8821A_2ANT_COEX_ALGO_HID_A2DP;
  543. } else {
  544. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  545. "[BTCoex], HID + A2DP + PAN(EDR)\n");
  546. BTC_TRACE(trace_buf);
  547. algorithm =
  548. BT_8821A_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
  549. }
  550. }
  551. }
  552. } else if (num_of_diff_profile >= 3) {
  553. if (bt_link_info->sco_exist) {
  554. if (bt_link_info->hid_exist &&
  555. bt_link_info->pan_exist &&
  556. bt_link_info->a2dp_exist) {
  557. if (bt_hs_on) {
  558. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  559. "[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n");
  560. BTC_TRACE(trace_buf);
  561. } else {
  562. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  563. "[BTCoex], SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n");
  564. BTC_TRACE(trace_buf);
  565. algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;
  566. }
  567. }
  568. }
  569. }
  570. return algorithm;
  571. }
  572. void halbtc8821a2ant_set_fw_dac_swing_level(IN struct btc_coexist *btcoexist,
  573. IN u8 dac_swing_lvl)
  574. {
  575. u8 h2c_parameter[1] = {0};
  576. /* There are several type of dacswing */
  577. /* 0x18/ 0x10/ 0xc/ 0x8/ 0x4/ 0x6 */
  578. h2c_parameter[0] = dac_swing_lvl;
  579. btcoexist->btc_fill_h2c(btcoexist, 0x64, 1, h2c_parameter);
  580. }
  581. void halbtc8821a2ant_set_fw_dec_bt_pwr(IN struct btc_coexist *btcoexist,
  582. IN u8 dec_bt_pwr_lvl)
  583. {
  584. u8 h2c_parameter[1] = {0};
  585. h2c_parameter[0] = dec_bt_pwr_lvl;
  586. btcoexist->btc_fill_h2c(btcoexist, 0x62, 1, h2c_parameter);
  587. }
  588. void halbtc8821a2ant_dec_bt_pwr(IN struct btc_coexist *btcoexist,
  589. IN boolean force_exec, IN u8 dec_bt_pwr_lvl)
  590. {
  591. coex_dm->cur_bt_dec_pwr_lvl = dec_bt_pwr_lvl;
  592. if (!force_exec) {
  593. if (coex_dm->pre_bt_dec_pwr_lvl == coex_dm->cur_bt_dec_pwr_lvl)
  594. return;
  595. }
  596. halbtc8821a2ant_set_fw_dec_bt_pwr(btcoexist,
  597. coex_dm->cur_bt_dec_pwr_lvl);
  598. coex_dm->pre_bt_dec_pwr_lvl = coex_dm->cur_bt_dec_pwr_lvl;
  599. }
  600. void halbtc8821a2ant_set_bt_auto_report(IN struct btc_coexist *btcoexist,
  601. IN boolean enable_auto_report)
  602. {
  603. u8 h2c_parameter[1] = {0};
  604. h2c_parameter[0] = 0;
  605. if (enable_auto_report)
  606. h2c_parameter[0] |= BIT(0);
  607. btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter);
  608. }
  609. void halbtc8821a2ant_bt_auto_report(IN struct btc_coexist *btcoexist,
  610. IN boolean force_exec, IN boolean enable_auto_report)
  611. {
  612. coex_dm->cur_bt_auto_report = enable_auto_report;
  613. if (!force_exec) {
  614. if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report)
  615. return;
  616. }
  617. halbtc8821a2ant_set_bt_auto_report(btcoexist,
  618. coex_dm->cur_bt_auto_report);
  619. coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report;
  620. }
  621. void halbtc8821a2ant_fw_dac_swing_lvl(IN struct btc_coexist *btcoexist,
  622. IN boolean force_exec, IN u8 fw_dac_swing_lvl)
  623. {
  624. coex_dm->cur_fw_dac_swing_lvl = fw_dac_swing_lvl;
  625. if (!force_exec) {
  626. if (coex_dm->pre_fw_dac_swing_lvl ==
  627. coex_dm->cur_fw_dac_swing_lvl)
  628. return;
  629. }
  630. halbtc8821a2ant_set_fw_dac_swing_level(btcoexist,
  631. coex_dm->cur_fw_dac_swing_lvl);
  632. coex_dm->pre_fw_dac_swing_lvl = coex_dm->cur_fw_dac_swing_lvl;
  633. }
  634. void halbtc8821a2ant_set_sw_rf_rx_lpf_corner(IN struct btc_coexist *btcoexist,
  635. IN boolean rx_rf_shrink_on)
  636. {
  637. if (rx_rf_shrink_on) {
  638. /* Shrink RF Rx LPF corner */
  639. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  640. "[BTCoex], Shrink RF Rx LPF corner!!\n");
  641. BTC_TRACE(trace_buf);
  642. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1e, 0xfffff,
  643. 0xffffc);
  644. } else {
  645. /* Resume RF Rx LPF corner */
  646. /* After initialized, we can use coex_dm->bt_rf_0x1e_backup */
  647. if (btcoexist->initilized) {
  648. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  649. "[BTCoex], Resume RF Rx LPF corner!!\n");
  650. BTC_TRACE(trace_buf);
  651. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1e,
  652. 0xfffff, coex_dm->bt_rf_0x1e_backup);
  653. }
  654. }
  655. }
  656. void halbtc8821a2ant_rf_shrink(IN struct btc_coexist *btcoexist,
  657. IN boolean force_exec, IN boolean rx_rf_shrink_on)
  658. {
  659. coex_dm->cur_rf_rx_lpf_shrink = rx_rf_shrink_on;
  660. if (!force_exec) {
  661. if (coex_dm->pre_rf_rx_lpf_shrink ==
  662. coex_dm->cur_rf_rx_lpf_shrink)
  663. return;
  664. }
  665. halbtc8821a2ant_set_sw_rf_rx_lpf_corner(btcoexist,
  666. coex_dm->cur_rf_rx_lpf_shrink);
  667. coex_dm->pre_rf_rx_lpf_shrink = coex_dm->cur_rf_rx_lpf_shrink;
  668. }
  669. void halbtc8821a2ant_set_sw_penalty_tx_rate_adaptive(IN struct btc_coexist
  670. *btcoexist, IN boolean low_penalty_ra)
  671. {
  672. u8 h2c_parameter[6] = {0};
  673. h2c_parameter[0] = 0x6; /* op_code, 0x6= Retry_Penalty */
  674. if (low_penalty_ra) {
  675. h2c_parameter[1] |= BIT(0);
  676. h2c_parameter[2] =
  677. 0x00; /* normal rate except MCS7/6/5, OFDM54/48/36 */
  678. h2c_parameter[3] = 0xf3; /* MCS7 or OFDM54 */
  679. h2c_parameter[4] = 0xa0; /* MCS6 or OFDM48 */
  680. h2c_parameter[5] = 0xa0; /* MCS5 or OFDM36 */
  681. /* h2c_parameter[3] = 0xf7; */ /*MCS7 or OFDM54 */
  682. /* h2c_parameter[4] = 0xf8; */ /*MCS6 or OFDM48 */
  683. /* h2c_parameter[5] = 0xf9; /MCS5 or OFDM36 */
  684. }
  685. btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, h2c_parameter);
  686. }
  687. void halbtc8821a2ant_low_penalty_ra(IN struct btc_coexist *btcoexist,
  688. IN boolean force_exec, IN boolean low_penalty_ra)
  689. {
  690. coex_dm->cur_low_penalty_ra = low_penalty_ra;
  691. if (!force_exec) {
  692. if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra)
  693. return;
  694. }
  695. halbtc8821a2ant_set_sw_penalty_tx_rate_adaptive(btcoexist,
  696. coex_dm->cur_low_penalty_ra);
  697. coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra;
  698. }
  699. void halbtc8821a2ant_set_dac_swing_reg(IN struct btc_coexist *btcoexist,
  700. IN u32 level)
  701. {
  702. u8 val = (u8)level;
  703. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  704. "[BTCoex], Write SwDacSwing = 0x%x\n", level);
  705. BTC_TRACE(trace_buf);
  706. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xc5b, 0x3e, val);
  707. }
  708. void halbtc8821a2ant_set_sw_full_time_dac_swing(IN struct btc_coexist
  709. *btcoexist, IN boolean sw_dac_swing_on, IN u32 sw_dac_swing_lvl)
  710. {
  711. if (sw_dac_swing_on)
  712. halbtc8821a2ant_set_dac_swing_reg(btcoexist, sw_dac_swing_lvl);
  713. else
  714. halbtc8821a2ant_set_dac_swing_reg(btcoexist, 0x18);
  715. }
  716. void halbtc8821a2ant_dac_swing(IN struct btc_coexist *btcoexist,
  717. IN boolean force_exec, IN boolean dac_swing_on, IN u32 dac_swing_lvl)
  718. {
  719. coex_dm->cur_dac_swing_on = dac_swing_on;
  720. coex_dm->cur_dac_swing_lvl = dac_swing_lvl;
  721. if (!force_exec) {
  722. if ((coex_dm->pre_dac_swing_on == coex_dm->cur_dac_swing_on) &&
  723. (coex_dm->pre_dac_swing_lvl ==
  724. coex_dm->cur_dac_swing_lvl))
  725. return;
  726. }
  727. delay_ms(30);
  728. halbtc8821a2ant_set_sw_full_time_dac_swing(btcoexist, dac_swing_on,
  729. dac_swing_lvl);
  730. coex_dm->pre_dac_swing_on = coex_dm->cur_dac_swing_on;
  731. coex_dm->pre_dac_swing_lvl = coex_dm->cur_dac_swing_lvl;
  732. }
  733. void halbtc8821a2ant_set_adc_back_off(IN struct btc_coexist *btcoexist,
  734. IN boolean adc_back_off)
  735. {
  736. if (adc_back_off) {
  737. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  738. "[BTCoex], BB BackOff Level On!\n");
  739. BTC_TRACE(trace_buf);
  740. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x8db, 0x60, 0x3);
  741. } else {
  742. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  743. "[BTCoex], BB BackOff Level Off!\n");
  744. BTC_TRACE(trace_buf);
  745. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x8db, 0x60, 0x1);
  746. }
  747. }
  748. void halbtc8821a2ant_adc_back_off(IN struct btc_coexist *btcoexist,
  749. IN boolean force_exec, IN boolean adc_back_off)
  750. {
  751. coex_dm->cur_adc_back_off = adc_back_off;
  752. if (!force_exec) {
  753. if (coex_dm->pre_adc_back_off == coex_dm->cur_adc_back_off)
  754. return;
  755. }
  756. halbtc8821a2ant_set_adc_back_off(btcoexist, coex_dm->cur_adc_back_off);
  757. coex_dm->pre_adc_back_off = coex_dm->cur_adc_back_off;
  758. }
  759. void halbtc8821a2ant_set_agc_table(IN struct btc_coexist *btcoexist,
  760. IN boolean agc_table_en)
  761. {
  762. u8 rssi_adjust_val = 0;
  763. /* =================BB AGC Gain Table */
  764. if (agc_table_en) {
  765. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  766. "[BTCoex], BB Agc Table On!\n");
  767. BTC_TRACE(trace_buf);
  768. btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x6e1A0001);
  769. btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x6d1B0001);
  770. btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x6c1C0001);
  771. btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x6b1D0001);
  772. btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x6a1E0001);
  773. btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x691F0001);
  774. btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x68200001);
  775. } else {
  776. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  777. "[BTCoex], BB Agc Table Off!\n");
  778. BTC_TRACE(trace_buf);
  779. btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xaa1A0001);
  780. btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa91B0001);
  781. btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa81C0001);
  782. btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa71D0001);
  783. btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa61E0001);
  784. btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa51F0001);
  785. btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa4200001);
  786. }
  787. /* =================RF Gain */
  788. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xef, 0xfffff, 0x02000);
  789. if (agc_table_en) {
  790. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  791. "[BTCoex], Agc Table On!\n");
  792. BTC_TRACE(trace_buf);
  793. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x3b, 0xfffff,
  794. 0x38fff);
  795. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x3b, 0xfffff,
  796. 0x38ffe);
  797. } else {
  798. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  799. "[BTCoex], Agc Table Off!\n");
  800. BTC_TRACE(trace_buf);
  801. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x3b, 0xfffff,
  802. 0x380c3);
  803. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x3b, 0xfffff,
  804. 0x28ce6);
  805. }
  806. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xef, 0xfffff, 0x0);
  807. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xed, 0xfffff, 0x1);
  808. if (agc_table_en) {
  809. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  810. "[BTCoex], Agc Table On!\n");
  811. BTC_TRACE(trace_buf);
  812. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x40, 0xfffff,
  813. 0x38fff);
  814. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x40, 0xfffff,
  815. 0x38ffe);
  816. } else {
  817. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  818. "[BTCoex], Agc Table Off!\n");
  819. BTC_TRACE(trace_buf);
  820. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x40, 0xfffff,
  821. 0x380c3);
  822. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x40, 0xfffff,
  823. 0x28ce6);
  824. }
  825. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xed, 0xfffff, 0x0);
  826. /* set rssi_adjust_val for wifi module. */
  827. if (agc_table_en)
  828. rssi_adjust_val = 8;
  829. btcoexist->btc_set(btcoexist, BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON,
  830. &rssi_adjust_val);
  831. }
  832. void halbtc8821a2ant_agc_table(IN struct btc_coexist *btcoexist,
  833. IN boolean force_exec, IN boolean agc_table_en)
  834. {
  835. coex_dm->cur_agc_table_en = agc_table_en;
  836. if (!force_exec) {
  837. if (coex_dm->pre_agc_table_en == coex_dm->cur_agc_table_en)
  838. return;
  839. }
  840. halbtc8821a2ant_set_agc_table(btcoexist, agc_table_en);
  841. coex_dm->pre_agc_table_en = coex_dm->cur_agc_table_en;
  842. }
  843. void halbtc8821a2ant_sw_mechanism1(IN struct btc_coexist *btcoexist,
  844. IN boolean shrink_rx_lpf, IN boolean low_penalty_ra,
  845. IN boolean limited_dig, IN boolean bt_lna_constrain)
  846. {
  847. /* halbtc8821a2ant_rf_shrink(btcoexist, NORMAL_EXEC, shrink_rx_lpf); */
  848. halbtc8821a2ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra);
  849. }
  850. void halbtc8821a2ant_sw_mechanism2(IN struct btc_coexist *btcoexist,
  851. IN boolean agc_table_shift, IN boolean adc_back_off,
  852. IN boolean sw_dac_swing, IN u32 dac_swing_lvl)
  853. {
  854. halbtc8821a2ant_dac_swing(btcoexist, NORMAL_EXEC, sw_dac_swing,
  855. dac_swing_lvl);
  856. }
  857. void halbtc8821a2ant_set_coex_table(IN struct btc_coexist *btcoexist,
  858. IN u32 val0x6c0, IN u32 val0x6c4, IN u32 val0x6c8, IN u8 val0x6cc)
  859. {
  860. btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0);
  861. btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4);
  862. btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8);
  863. btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc);
  864. }
  865. void halbtc8821a2ant_coex_table(IN struct btc_coexist *btcoexist,
  866. IN boolean force_exec, IN u32 val0x6c0, IN u32 val0x6c4,
  867. IN u32 val0x6c8, IN u8 val0x6cc)
  868. {
  869. coex_dm->cur_val0x6c0 = val0x6c0;
  870. coex_dm->cur_val0x6c4 = val0x6c4;
  871. coex_dm->cur_val0x6c8 = val0x6c8;
  872. coex_dm->cur_val0x6cc = val0x6cc;
  873. if (!force_exec) {
  874. if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) &&
  875. (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) &&
  876. (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) &&
  877. (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc))
  878. return;
  879. }
  880. halbtc8821a2ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8,
  881. val0x6cc);
  882. coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0;
  883. coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4;
  884. coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8;
  885. coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc;
  886. }
  887. void halbtc8821a2ant_coex_table_with_type(IN struct btc_coexist *btcoexist,
  888. IN boolean force_exec, IN u8 type)
  889. {
  890. coex_sta->coex_table_type = type;
  891. switch (type) {
  892. case 0:
  893. halbtc8821a2ant_coex_table(btcoexist, force_exec,
  894. 0x55555555, 0x55555555, 0xffffff, 0x3);
  895. break;
  896. case 1:
  897. halbtc8821a2ant_coex_table(btcoexist, force_exec,
  898. 0x55555555, 0x5afa5afa, 0xffffff, 0x3);
  899. break;
  900. case 2:
  901. halbtc8821a2ant_coex_table(btcoexist, force_exec,
  902. 0x5ada5ada, 0x5ada5ada, 0xffffff, 0x3);
  903. break;
  904. case 3:
  905. halbtc8821a2ant_coex_table(btcoexist, force_exec,
  906. 0xaaaaaaaa, 0xaaaaaaaa, 0xffffff, 0x3);
  907. break;
  908. case 4:
  909. halbtc8821a2ant_coex_table(btcoexist, force_exec,
  910. 0xffffffff, 0xffffffff, 0xffffff, 0x3);
  911. break;
  912. case 5:
  913. halbtc8821a2ant_coex_table(btcoexist, force_exec,
  914. 0x5fff5fff, 0x5fff5fff, 0xffffff, 0x3);
  915. break;
  916. case 6:
  917. halbtc8821a2ant_coex_table(btcoexist, force_exec,
  918. 0x55ff55ff, 0x5a5a5a5a, 0xffffff, 0x3);
  919. break;
  920. case 7:
  921. halbtc8821a2ant_coex_table(btcoexist, force_exec,
  922. 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3);
  923. break;
  924. case 8:
  925. halbtc8821a2ant_coex_table(btcoexist, force_exec,
  926. 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3);
  927. break;
  928. case 9:
  929. halbtc8821a2ant_coex_table(btcoexist, force_exec,
  930. 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3);
  931. break;
  932. case 10:
  933. halbtc8821a2ant_coex_table(btcoexist, force_exec,
  934. 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3);
  935. break;
  936. case 11:
  937. halbtc8821a2ant_coex_table(btcoexist, force_exec,
  938. 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3);
  939. break;
  940. case 12:
  941. halbtc8821a2ant_coex_table(btcoexist, force_exec,
  942. 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3);
  943. break;
  944. case 13:
  945. halbtc8821a2ant_coex_table(btcoexist, force_exec,
  946. 0x5fff5fff, 0xaaaaaaaa, 0xffffff, 0x3);
  947. break;
  948. case 14:
  949. halbtc8821a2ant_coex_table(btcoexist, force_exec,
  950. 0x5fff5fff, 0x5ada5ada, 0xffffff, 0x3);
  951. break;
  952. case 15:
  953. halbtc8821a2ant_coex_table(btcoexist, force_exec,
  954. 0x55dd55dd, 0xaaaaaaaa, 0xffffff, 0x3);
  955. break;
  956. case 16:
  957. halbtc8821a2ant_coex_table(btcoexist, force_exec,
  958. 0x5fdf5fdf, 0x5fdb5fdb, 0xffffff, 0x3);
  959. break;
  960. case 17:
  961. halbtc8821a2ant_coex_table(btcoexist, force_exec,
  962. 0xfafafafa, 0xfafafafa, 0xffffff, 0x3);
  963. break;
  964. case 18:
  965. halbtc8821a2ant_coex_table(btcoexist, force_exec,
  966. 0x5555555f, 0x5ada5ada, 0xffffff, 0x3);
  967. break;
  968. default:
  969. break;
  970. }
  971. }
  972. void halbtc8821a2ant_set_fw_ignore_wlan_act(IN struct btc_coexist *btcoexist,
  973. IN boolean enable)
  974. {
  975. u8 h2c_parameter[1] = {0};
  976. if (enable)
  977. h2c_parameter[0] |= BIT(0); /* function enable */
  978. btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter);
  979. }
  980. void halbtc8821a2ant_ignore_wlan_act(IN struct btc_coexist *btcoexist,
  981. IN boolean force_exec, IN boolean enable)
  982. {
  983. coex_dm->cur_ignore_wlan_act = enable;
  984. if (!force_exec) {
  985. if (coex_dm->pre_ignore_wlan_act ==
  986. coex_dm->cur_ignore_wlan_act)
  987. return;
  988. }
  989. halbtc8821a2ant_set_fw_ignore_wlan_act(btcoexist, enable);
  990. coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act;
  991. }
  992. void halbtc8821a2ant_set_lps_rpwm(IN struct btc_coexist *btcoexist,
  993. IN u8 lps_val, IN u8 rpwm_val)
  994. {
  995. u8 lps = lps_val;
  996. u8 rpwm = rpwm_val;
  997. btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps);
  998. btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
  999. }
  1000. void halbtc8821a2ant_lps_rpwm(IN struct btc_coexist *btcoexist,
  1001. IN boolean force_exec, IN u8 lps_val, IN u8 rpwm_val)
  1002. {
  1003. coex_dm->cur_lps = lps_val;
  1004. coex_dm->cur_rpwm = rpwm_val;
  1005. if (!force_exec) {
  1006. if ((coex_dm->pre_lps == coex_dm->cur_lps) &&
  1007. (coex_dm->pre_rpwm == coex_dm->cur_rpwm))
  1008. return;
  1009. }
  1010. halbtc8821a2ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val);
  1011. coex_dm->pre_lps = coex_dm->cur_lps;
  1012. coex_dm->pre_rpwm = coex_dm->cur_rpwm;
  1013. }
  1014. void halbtc8821a2ant_ps_tdma_check_for_power_save_state(
  1015. IN struct btc_coexist *btcoexist, IN boolean new_ps_state)
  1016. {
  1017. u8 lps_mode = 0x0;
  1018. u8 h2c_parameter[5] = {0x0, 0, 0, 48, 0};
  1019. btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode);
  1020. if (lps_mode) { /* already under LPS state */
  1021. if (new_ps_state) {
  1022. /* keep state under LPS, do nothing. */
  1023. } else {
  1024. btcoexist->btc_fill_h2c(btcoexist, 0x60, 5,
  1025. h2c_parameter);
  1026. }
  1027. } else { /* NO PS state */
  1028. if (new_ps_state) {
  1029. btcoexist->btc_fill_h2c(btcoexist, 0x60, 5,
  1030. h2c_parameter);
  1031. } else {
  1032. }
  1033. }
  1034. }
  1035. void halbtc8821a2ant_power_save_state(IN struct btc_coexist *btcoexist,
  1036. IN u8 ps_type, IN u8 lps_val, IN u8 rpwm_val)
  1037. {
  1038. boolean low_pwr_disable = false;
  1039. switch (ps_type) {
  1040. case BTC_PS_WIFI_NATIVE:
  1041. /* recover to original 32k low power setting */
  1042. low_pwr_disable = false;
  1043. btcoexist->btc_set(btcoexist,
  1044. BTC_SET_ACT_DISABLE_LOW_POWER,
  1045. &low_pwr_disable);
  1046. btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS,
  1047. NULL);
  1048. coex_sta->force_lps_on = false;
  1049. break;
  1050. case BTC_PS_LPS_ON:
  1051. halbtc8821a2ant_ps_tdma_check_for_power_save_state(
  1052. btcoexist, true);
  1053. halbtc8821a2ant_lps_rpwm(btcoexist, NORMAL_EXEC,
  1054. lps_val, rpwm_val);
  1055. /* when coex force to enter LPS, do not enter 32k low power. */
  1056. low_pwr_disable = true;
  1057. btcoexist->btc_set(btcoexist,
  1058. BTC_SET_ACT_DISABLE_LOW_POWER,
  1059. &low_pwr_disable);
  1060. /*power save must executed before psTdma*/
  1061. btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS,
  1062. NULL);
  1063. coex_sta->force_lps_on = true;
  1064. break;
  1065. case BTC_PS_LPS_OFF:
  1066. halbtc8821a2ant_ps_tdma_check_for_power_save_state(
  1067. btcoexist, false);
  1068. btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS,
  1069. NULL);
  1070. coex_sta->force_lps_on = false;
  1071. break;
  1072. default:
  1073. break;
  1074. }
  1075. }
  1076. void halbtc8821a2ant_set_fw_pstdma(IN struct btc_coexist *btcoexist,
  1077. IN u8 byte1, IN u8 byte2, IN u8 byte3, IN u8 byte4, IN u8 byte5)
  1078. {
  1079. u8 h2c_parameter[5] = {0};
  1080. u8 real_byte1 = byte1, real_byte5 = byte5;
  1081. boolean ap_enable = false;
  1082. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
  1083. &ap_enable);
  1084. if (ap_enable) {
  1085. if (byte1 & BIT(4) && !(byte1 & BIT(5))) {
  1086. real_byte1 &= ~BIT(4);
  1087. real_byte1 |= BIT(5);
  1088. real_byte5 |= BIT(5);
  1089. real_byte5 &= ~BIT(6);
  1090. halbtc8821a2ant_power_save_state(btcoexist,
  1091. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  1092. }
  1093. } else if (byte1 & BIT(4) && !(byte1 & BIT(5))) {
  1094. halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50, 0x4);
  1095. } else {
  1096. halbtc8821a2ant_power_save_state(btcoexist,
  1097. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  1098. }
  1099. h2c_parameter[0] = byte1;
  1100. h2c_parameter[1] = byte2;
  1101. h2c_parameter[2] = byte3;
  1102. h2c_parameter[3] = byte4;
  1103. h2c_parameter[4] = byte5;
  1104. coex_dm->ps_tdma_para[0] = byte1;
  1105. coex_dm->ps_tdma_para[1] = byte2;
  1106. coex_dm->ps_tdma_para[2] = byte3;
  1107. coex_dm->ps_tdma_para[3] = byte4;
  1108. coex_dm->ps_tdma_para[4] = byte5;
  1109. btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter);
  1110. }
  1111. void halbtc8821a2ant_ps_tdma(IN struct btc_coexist *btcoexist,
  1112. IN boolean force_exec, IN boolean turn_on, IN u8 type)
  1113. {
  1114. u8 wifi_rssi_state1, bt_rssi_state;
  1115. wifi_rssi_state1 = halbtc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
  1116. BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
  1117. bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2,
  1118. BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
  1119. if (!(BTC_RSSI_HIGH(wifi_rssi_state1) &&
  1120. BTC_RSSI_HIGH(bt_rssi_state)) && turn_on) {
  1121. type = type + 100; /* for WiFi RSSI low or BT RSSI low */
  1122. }
  1123. coex_dm->cur_ps_tdma_on = turn_on;
  1124. coex_dm->cur_ps_tdma = type;
  1125. if (!force_exec) {
  1126. if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) &&
  1127. (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma))
  1128. return;
  1129. }
  1130. if (turn_on) {
  1131. switch (type) {
  1132. case 1:
  1133. default:
  1134. /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x90); */
  1135. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1136. 0x3c, 0x03, 0xf1, 0x90);
  1137. break;
  1138. case 2:
  1139. /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x12, 0x12, 0xe1, 0x90); */
  1140. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1141. 0x2d, 0x03, 0xf1, 0x90);
  1142. break;
  1143. case 3:
  1144. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1145. 0x1c, 0x3, 0xf1, 0x90);
  1146. break;
  1147. case 4:
  1148. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1149. 0x10, 0x03, 0xf1, 0x90);
  1150. break;
  1151. case 5:
  1152. /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x1a, 0x1a, 0x60, 0x90); */
  1153. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1154. 0x3c, 0x3, 0x70, 0x90);
  1155. break;
  1156. case 6:
  1157. /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x12, 0x12, 0x60, 0x90); */
  1158. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1159. 0x2d, 0x3, 0x70, 0x90);
  1160. break;
  1161. case 7:
  1162. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1163. 0x1c, 0x3, 0x70, 0x90);
  1164. break;
  1165. case 8:
  1166. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xa3,
  1167. 0x10, 0x3, 0x70, 0x90);
  1168. break;
  1169. case 9:
  1170. /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x90); */
  1171. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1172. 0x3c, 0x03, 0xf1, 0x90);
  1173. break;
  1174. case 10:
  1175. /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x12, 0x12, 0xe1, 0x90); */
  1176. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1177. 0x2d, 0x03, 0xf1, 0x90);
  1178. break;
  1179. case 11:
  1180. /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0xa, 0xa, 0xe1, 0x90); */
  1181. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1182. 0x1c, 0x3, 0xf1, 0x90);
  1183. break;
  1184. case 12:
  1185. /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x5, 0x5, 0xe1, 0x90); */
  1186. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1187. 0x10, 0x3, 0xf1, 0x90);
  1188. break;
  1189. case 13:
  1190. /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x1a, 0x1a, 0x60, 0x90); */
  1191. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1192. 0x3c, 0x3, 0x70, 0x90);
  1193. break;
  1194. case 14:
  1195. /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x12, 0x12, 0x60, 0x90); */
  1196. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1197. 0x2d, 0x3, 0x70, 0x90);
  1198. break;
  1199. case 15:
  1200. /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0xa, 0xa, 0x60, 0x90); */
  1201. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1202. 0x1c, 0x3, 0x70, 0x90);
  1203. break;
  1204. case 16:
  1205. /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x5, 0x5, 0x60, 0x90); */
  1206. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1207. 0x10, 0x3, 0x70, 0x90);
  1208. break;
  1209. case 17:
  1210. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xa3,
  1211. 0x2f, 0x2f, 0x60, 0x90);
  1212. break;
  1213. case 18:
  1214. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1215. 0x5, 0x5, 0xe1, 0x90);
  1216. break;
  1217. case 19:
  1218. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1219. 0x25, 0x25, 0xe1, 0x90);
  1220. break;
  1221. case 20:
  1222. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1223. 0x25, 0x25, 0x60, 0x90);
  1224. break;
  1225. case 21:
  1226. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1227. 0x15, 0x03, 0x70, 0x90);
  1228. break;
  1229. case 23:
  1230. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1231. 0x1e, 0x03, 0xf1, 0x94);
  1232. break;
  1233. case 24:
  1234. case 124:
  1235. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xd3,
  1236. 0x3c, 0x03, 0x70, 0x50);
  1237. break;
  1238. /* case25/case125 : for lenovo bt pan tp degrade<30% while wifi downlink */
  1239. case 25:
  1240. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1241. 0x14, 0x03, 0xf1, 0x90);
  1242. break;
  1243. case 26:
  1244. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1245. 0x30, 0x03, 0xf1, 0x90);
  1246. break;
  1247. case 27:
  1248. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xd3,
  1249. 0x23, 0x03, 0x70, 0x50);
  1250. break;
  1251. case 28:
  1252. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1253. 0x1e, 0x03, 0xf1, 0x94);
  1254. break;
  1255. case 71:
  1256. /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x90); */
  1257. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1258. 0x3c, 0x03, 0xf1, 0x90);
  1259. break;
  1260. case 101:
  1261. case 105:
  1262. case 171:
  1263. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xd3,
  1264. 0x3a, 0x03, 0x70, 0x50);
  1265. break;
  1266. case 102:
  1267. case 106:
  1268. case 110:
  1269. case 114:
  1270. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xd3,
  1271. 0x2d, 0x03, 0x70, 0x50);
  1272. break;
  1273. case 103:
  1274. case 107:
  1275. case 111:
  1276. case 115:
  1277. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xd3,
  1278. 0x1c, 0x03, 0x70, 0x50);
  1279. break;
  1280. case 104:
  1281. case 108:
  1282. case 112:
  1283. case 116:
  1284. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xd3,
  1285. 0x10, 0x03, 0x70, 0x50);
  1286. break;
  1287. case 109:
  1288. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1289. 0x3c, 0x03, 0xf1, 0x90);
  1290. break;
  1291. case 113:
  1292. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1293. 0x3c, 0x03, 0x70, 0x90);
  1294. break;
  1295. case 121:
  1296. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1297. 0x15, 0x03, 0x70, 0x90);
  1298. break;
  1299. case 22:
  1300. case 122:
  1301. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1302. 0x35, 0x03, 0x71, 0x11);
  1303. break;
  1304. case 123:
  1305. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xd3,
  1306. 0x1e, 0x03, 0x70, 0x54);
  1307. break;
  1308. /* case25/case125 : for lenovo bt pan tp degrade<30% while wifi downlink */
  1309. case 125:
  1310. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xd3,
  1311. 0x14, 0x03, 0x70, 0x50);
  1312. break;
  1313. case 126:
  1314. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xd3,
  1315. 0x30, 0x03, 0x70, 0x50);
  1316. break;
  1317. case 127:
  1318. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xd3,
  1319. 0x28, 0x03, 0x70, 0x50);
  1320. break;
  1321. case 128:
  1322. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xd3,
  1323. 0x1e, 0x03, 0x70, 0x54);
  1324. break;
  1325. }
  1326. } else {
  1327. /* disable PS tdma */
  1328. switch (type) {
  1329. case 0:
  1330. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0x0,
  1331. 0x0, 0x0, 0x40, 0x0);
  1332. break;
  1333. case 1:
  1334. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0x0,
  1335. 0x0, 0x0, 0x48, 0x0);
  1336. break;
  1337. default:
  1338. halbtc8821a2ant_set_fw_pstdma(btcoexist, 0x0,
  1339. 0x0, 0x0, 0x40, 0x0);
  1340. break;
  1341. }
  1342. }
  1343. /* update pre state */
  1344. coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on;
  1345. coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma;
  1346. }
  1347. void halbtc8821a2ant_set_ant_path(IN struct btc_coexist *btcoexist,
  1348. IN u8 ant_pos_type, IN boolean init_hwcfg, IN boolean wifi_off)
  1349. {
  1350. struct btc_board_info *board_info = &btcoexist->board_info;
  1351. u32 u32tmp = 0;
  1352. u8 h2c_parameter[2] = {0};
  1353. if (init_hwcfg) {
  1354. /* 0x4c[23]=0, 0x4c[24]=1 Antenna control by WL/BT */
  1355. u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
  1356. u32tmp &= ~BIT(23);
  1357. u32tmp |= BIT(24);
  1358. btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp);
  1359. btcoexist->btc_write_4byte(btcoexist, 0x974, 0x3ff);
  1360. /* btcoexist->btc_write_1byte(btcoexist, 0xcb4, 0x77); */
  1361. if (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT) {
  1362. h2c_parameter[0] = 1;
  1363. h2c_parameter[1] = 1;
  1364. btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
  1365. h2c_parameter);
  1366. } else {
  1367. h2c_parameter[0] = 0;
  1368. h2c_parameter[1] = 1;
  1369. btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
  1370. h2c_parameter);
  1371. }
  1372. }
  1373. /* ext switch setting */
  1374. switch (ant_pos_type) {
  1375. case BTC_ANT_WIFI_AT_MAIN:
  1376. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7,
  1377. 0x30, 0x1);
  1378. break;
  1379. case BTC_ANT_WIFI_AT_AUX:
  1380. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7,
  1381. 0x30, 0x2);
  1382. break;
  1383. }
  1384. }
  1385. void halbtc8821a2ant_coex_all_off(IN struct btc_coexist *btcoexist)
  1386. {
  1387. /* fw all off */
  1388. halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
  1389. halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  1390. halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  1391. /* sw all off */
  1392. halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, false, false);
  1393. halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18);
  1394. /* hw all off */
  1395. /* btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); */
  1396. halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  1397. }
  1398. void halbtc8821a2ant_coex_under_5g(IN struct btc_coexist *btcoexist)
  1399. {
  1400. halbtc8821a2ant_coex_all_off(btcoexist);
  1401. halbtc8821a2ant_ignore_wlan_act(btcoexist, NORMAL_EXEC, true);
  1402. }
  1403. void halbtc8821a2ant_action_bt_inquiry(IN struct btc_coexist *btcoexist)
  1404. {
  1405. u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
  1406. boolean wifi_connected = false;
  1407. boolean low_pwr_disable = true;
  1408. boolean scan = false, link = false, roam = false;
  1409. wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15,
  1410. 0);
  1411. wifi_rssi_state1 = halbtc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
  1412. BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
  1413. bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2,
  1414. BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
  1415. btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
  1416. &low_pwr_disable);
  1417. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  1418. &wifi_connected);
  1419. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
  1420. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
  1421. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
  1422. if (scan || link || roam) {
  1423. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1424. "[BTCoex], Wifi link process + BT Inq/Page!!\n");
  1425. BTC_TRACE(trace_buf);
  1426. halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
  1427. 7);
  1428. halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22);
  1429. } else if (wifi_connected) {
  1430. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1431. "[BTCoex], Wifi connected + BT Inq/Page!!\n");
  1432. BTC_TRACE(trace_buf);
  1433. halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
  1434. 7);
  1435. halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22);
  1436. } else {
  1437. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1438. "[BTCoex], Wifi no-link + BT Inq/Page!!\n");
  1439. BTC_TRACE(trace_buf);
  1440. halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  1441. halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
  1442. }
  1443. halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 6);
  1444. halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  1445. halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, false, false);
  1446. halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18);
  1447. }
  1448. void halbtc8821a2ant_action_wifi_link_process(IN struct btc_coexist *btcoexist)
  1449. {
  1450. u8 u8tmpa, u8tmpb;
  1451. halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
  1452. halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22);
  1453. halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, false, false);
  1454. halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18);
  1455. u8tmpa = btcoexist->btc_read_1byte(btcoexist, 0x765);
  1456. u8tmpb = btcoexist->btc_read_1byte(btcoexist, 0x76e);
  1457. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1458. "############# [BTCoex], 0x765=0x%x, 0x76e=0x%x\n", u8tmpa,
  1459. u8tmpb);
  1460. BTC_TRACE(trace_buf);
  1461. }
  1462. boolean halbtc8821a2ant_action_wifi_idle_process(IN struct btc_coexist
  1463. *btcoexist)
  1464. {
  1465. u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
  1466. u8 ap_num = 0;
  1467. wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15,
  1468. 0);
  1469. /* wifi_rssi_state1 = halbtc8821a2ant_wifi_rssi_state(btcoexist, 1, 2, BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0); */
  1470. wifi_rssi_state1 = halbtc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
  1471. BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES - 20, 0);
  1472. bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2,
  1473. BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
  1474. btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, &ap_num);
  1475. /* define the office environment */
  1476. if (BTC_RSSI_HIGH(wifi_rssi_state1) &&
  1477. (coex_sta->hid_exist == true) &&
  1478. (coex_sta->a2dp_exist == true)) {
  1479. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1480. "[BTCoex], Wifi idle process for BT HID+A2DP exist!!\n");
  1481. BTC_TRACE(trace_buf);
  1482. halbtc8821a2ant_dac_swing(btcoexist, NORMAL_EXEC, true, 0x6);
  1483. halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  1484. /* sw all off */
  1485. halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, false,
  1486. false);
  1487. halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, false,
  1488. 0x18);
  1489. halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  1490. halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
  1491. return true;
  1492. }
  1493. /* */
  1494. else if (coex_sta->pan_exist == true) {
  1495. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1496. "[BTCoex], Wifi idle process for BT PAN exist!!\n");
  1497. BTC_TRACE(trace_buf);
  1498. halbtc8821a2ant_dac_swing(btcoexist, NORMAL_EXEC, true, 0x6);
  1499. halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  1500. /* sw all off */
  1501. halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, false,
  1502. false);
  1503. halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, false,
  1504. 0x18);
  1505. halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  1506. halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
  1507. return true;
  1508. }
  1509. else {
  1510. halbtc8821a2ant_dac_swing(btcoexist, NORMAL_EXEC, true, 0x18);
  1511. return false;
  1512. }
  1513. }
  1514. boolean halbtc8821a2ant_is_common_action(IN struct btc_coexist *btcoexist)
  1515. {
  1516. boolean common = false, wifi_connected = false, wifi_busy = false;
  1517. boolean bt_hs_on = false, low_pwr_disable = false;
  1518. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  1519. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  1520. &wifi_connected);
  1521. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  1522. if (!wifi_connected) {
  1523. low_pwr_disable = false;
  1524. btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
  1525. &low_pwr_disable);
  1526. halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
  1527. 0x8);
  1528. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1529. "[BTCoex], Wifi non-connected idle!!\n");
  1530. BTC_TRACE(trace_buf);
  1531. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff,
  1532. 0x0);
  1533. halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  1534. halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
  1535. halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  1536. halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  1537. halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, false,
  1538. false);
  1539. halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, false,
  1540. 0x18);
  1541. common = true;
  1542. } else {
  1543. if (BT_8821A_2ANT_BT_STATUS_NON_CONNECTED_IDLE ==
  1544. coex_dm->bt_status) {
  1545. low_pwr_disable = false;
  1546. btcoexist->btc_set(btcoexist,
  1547. BTC_SET_ACT_DISABLE_LOW_POWER,
  1548. &low_pwr_disable);
  1549. halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC,
  1550. false, false, 0x8);
  1551. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1552. "[BTCoex], Wifi connected + BT non connected-idle!!\n");
  1553. BTC_TRACE(trace_buf);
  1554. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1,
  1555. 0xfffff, 0x0);
  1556. halbtc8821a2ant_coex_table_with_type(btcoexist,
  1557. NORMAL_EXEC, 0);
  1558. halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
  1559. 1);
  1560. halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC,
  1561. 0xb);
  1562. halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  1563. halbtc8821a2ant_sw_mechanism1(btcoexist, false, false,
  1564. false,
  1565. false);
  1566. halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
  1567. false, 0x18);
  1568. common = true;
  1569. } else if (BT_8821A_2ANT_BT_STATUS_CONNECTED_IDLE ==
  1570. coex_dm->bt_status) {
  1571. low_pwr_disable = true;
  1572. btcoexist->btc_set(btcoexist,
  1573. BTC_SET_ACT_DISABLE_LOW_POWER,
  1574. &low_pwr_disable);
  1575. if (bt_hs_on)
  1576. return false;
  1577. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1578. "[BTCoex], Wifi connected + BT connected-idle!!\n");
  1579. BTC_TRACE(trace_buf);
  1580. halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC,
  1581. false, false, 0x8);
  1582. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1,
  1583. 0xfffff, 0x0);
  1584. halbtc8821a2ant_coex_table_with_type(btcoexist,
  1585. NORMAL_EXEC, 0);
  1586. halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
  1587. 1);
  1588. halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC,
  1589. 0xb);
  1590. halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  1591. halbtc8821a2ant_sw_mechanism1(btcoexist, true, false,
  1592. false, false);
  1593. halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
  1594. false, 0x18);
  1595. common = true;
  1596. } else {
  1597. low_pwr_disable = true;
  1598. btcoexist->btc_set(btcoexist,
  1599. BTC_SET_ACT_DISABLE_LOW_POWER,
  1600. &low_pwr_disable);
  1601. if (wifi_busy) {
  1602. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1603. "[BTCoex], Wifi Connected-Busy + BT Busy!!\n");
  1604. BTC_TRACE(trace_buf);
  1605. common = false;
  1606. /* common = halbtc8821a2ant_action_wifi_idle_process(btcoexist); */
  1607. } else {
  1608. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1609. "[BTCoex], Wifi Connected-Idle + BT Busy!!\n");
  1610. BTC_TRACE(trace_buf);
  1611. /* common = false; */
  1612. common = halbtc8821a2ant_action_wifi_idle_process(
  1613. btcoexist);
  1614. }
  1615. }
  1616. }
  1617. return common;
  1618. }
  1619. void halbtc8821a2ant_tdma_duration_adjust(IN struct btc_coexist *btcoexist,
  1620. IN boolean sco_hid, IN boolean tx_pause, IN u8 max_interval)
  1621. {
  1622. static s32 up, dn, m, n, wait_count;
  1623. s32 result; /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */
  1624. u8 retry_count = 0;
  1625. if (!coex_dm->auto_tdma_adjust) {
  1626. coex_dm->auto_tdma_adjust = true;
  1627. {
  1628. if (sco_hid) {
  1629. if (tx_pause) {
  1630. if (max_interval == 1) {
  1631. halbtc8821a2ant_ps_tdma(
  1632. btcoexist, NORMAL_EXEC,
  1633. true, 13);
  1634. coex_dm->ps_tdma_du_adj_type =
  1635. 13;
  1636. } else if (max_interval == 2) {
  1637. halbtc8821a2ant_ps_tdma(
  1638. btcoexist, NORMAL_EXEC,
  1639. true, 14);
  1640. coex_dm->ps_tdma_du_adj_type =
  1641. 14;
  1642. } else if (max_interval == 3) {
  1643. halbtc8821a2ant_ps_tdma(
  1644. btcoexist, NORMAL_EXEC,
  1645. true, 15);
  1646. coex_dm->ps_tdma_du_adj_type =
  1647. 15;
  1648. } else {
  1649. halbtc8821a2ant_ps_tdma(
  1650. btcoexist, NORMAL_EXEC,
  1651. true, 15);
  1652. coex_dm->ps_tdma_du_adj_type =
  1653. 15;
  1654. }
  1655. } else {
  1656. if (max_interval == 1) {
  1657. halbtc8821a2ant_ps_tdma(
  1658. btcoexist, NORMAL_EXEC,
  1659. true, 9);
  1660. coex_dm->ps_tdma_du_adj_type =
  1661. 9;
  1662. } else if (max_interval == 2) {
  1663. halbtc8821a2ant_ps_tdma(
  1664. btcoexist, NORMAL_EXEC,
  1665. true, 10);
  1666. coex_dm->ps_tdma_du_adj_type =
  1667. 10;
  1668. } else if (max_interval == 3) {
  1669. halbtc8821a2ant_ps_tdma(
  1670. btcoexist, NORMAL_EXEC,
  1671. true, 11);
  1672. coex_dm->ps_tdma_du_adj_type =
  1673. 11;
  1674. } else {
  1675. halbtc8821a2ant_ps_tdma(
  1676. btcoexist, NORMAL_EXEC,
  1677. true, 11);
  1678. coex_dm->ps_tdma_du_adj_type =
  1679. 11;
  1680. }
  1681. }
  1682. } else {
  1683. if (tx_pause) {
  1684. if (max_interval == 1) {
  1685. halbtc8821a2ant_ps_tdma(
  1686. btcoexist, NORMAL_EXEC,
  1687. true, 5);
  1688. coex_dm->ps_tdma_du_adj_type =
  1689. 5;
  1690. } else if (max_interval == 2) {
  1691. halbtc8821a2ant_ps_tdma(
  1692. btcoexist, NORMAL_EXEC,
  1693. true, 6);
  1694. coex_dm->ps_tdma_du_adj_type =
  1695. 6;
  1696. } else if (max_interval == 3) {
  1697. halbtc8821a2ant_ps_tdma(
  1698. btcoexist, NORMAL_EXEC,
  1699. true, 7);
  1700. coex_dm->ps_tdma_du_adj_type =
  1701. 7;
  1702. } else {
  1703. halbtc8821a2ant_ps_tdma(
  1704. btcoexist, NORMAL_EXEC,
  1705. true, 7);
  1706. coex_dm->ps_tdma_du_adj_type =
  1707. 7;
  1708. }
  1709. } else {
  1710. if (max_interval == 1) {
  1711. halbtc8821a2ant_ps_tdma(
  1712. btcoexist, NORMAL_EXEC,
  1713. true, 1);
  1714. coex_dm->ps_tdma_du_adj_type =
  1715. 1;
  1716. } else if (max_interval == 2) {
  1717. halbtc8821a2ant_ps_tdma(
  1718. btcoexist, NORMAL_EXEC,
  1719. true, 2);
  1720. coex_dm->ps_tdma_du_adj_type =
  1721. 2;
  1722. } else if (max_interval == 3) {
  1723. halbtc8821a2ant_ps_tdma(
  1724. btcoexist, NORMAL_EXEC,
  1725. true, 3);
  1726. coex_dm->ps_tdma_du_adj_type =
  1727. 3;
  1728. } else {
  1729. halbtc8821a2ant_ps_tdma(
  1730. btcoexist, NORMAL_EXEC,
  1731. true, 3);
  1732. coex_dm->ps_tdma_du_adj_type =
  1733. 3;
  1734. }
  1735. }
  1736. }
  1737. }
  1738. /* ============ */
  1739. up = 0;
  1740. dn = 0;
  1741. m = 1;
  1742. n = 3;
  1743. result = 0;
  1744. wait_count = 0;
  1745. } else {
  1746. /* acquire the BT TRx retry count from BT_Info byte2 */
  1747. retry_count = coex_sta->bt_retry_cnt;
  1748. result = 0;
  1749. wait_count++;
  1750. if (retry_count ==
  1751. 0) { /* no retry in the last 2-second duration */
  1752. up++;
  1753. dn--;
  1754. if (dn <= 0)
  1755. dn = 0;
  1756. if (up >= n) { /* if 連續 n 個2秒 retry count為0, 則調寬WiFi duration */
  1757. wait_count = 0;
  1758. n = 3;
  1759. up = 0;
  1760. dn = 0;
  1761. result = 1;
  1762. }
  1763. } else if (retry_count <=
  1764. 3) { /* <=3 retry in the last 2-second duration */
  1765. up--;
  1766. dn++;
  1767. if (up <= 0)
  1768. up = 0;
  1769. if (dn == 2) { /* if 連續 2 個2秒 retry count< 3, 則調窄WiFi duration */
  1770. if (wait_count <= 2)
  1771. m++; /* 避免一直在兩個level中來回 */
  1772. else
  1773. m = 1;
  1774. if (m >= 20) /* m 最大值 = 20 ' 最大120秒 recheck是否調整 WiFi duration. */
  1775. m = 20;
  1776. n = 3 * m;
  1777. up = 0;
  1778. dn = 0;
  1779. wait_count = 0;
  1780. result = -1;
  1781. }
  1782. } else { /* retry count > 3, 只要1次 retry count > 3, 則調窄WiFi duration */
  1783. if (wait_count == 1)
  1784. m++; /* 避免一直在兩個level中來回 */
  1785. else
  1786. m = 1;
  1787. if (m >= 20) /* m 最大值 = 20 ' 最大120秒 recheck是否調整 WiFi duration. */
  1788. m = 20;
  1789. n = 3 * m;
  1790. up = 0;
  1791. dn = 0;
  1792. wait_count = 0;
  1793. result = -1;
  1794. }
  1795. if (max_interval == 1) {
  1796. if (tx_pause) {
  1797. if (coex_dm->cur_ps_tdma == 71) {
  1798. halbtc8821a2ant_ps_tdma(btcoexist,
  1799. NORMAL_EXEC, true, 5);
  1800. coex_dm->ps_tdma_du_adj_type = 5;
  1801. } else if (coex_dm->cur_ps_tdma == 1) {
  1802. halbtc8821a2ant_ps_tdma(btcoexist,
  1803. NORMAL_EXEC, true, 5);
  1804. coex_dm->ps_tdma_du_adj_type = 5;
  1805. } else if (coex_dm->cur_ps_tdma == 2) {
  1806. halbtc8821a2ant_ps_tdma(btcoexist,
  1807. NORMAL_EXEC, true, 6);
  1808. coex_dm->ps_tdma_du_adj_type = 6;
  1809. } else if (coex_dm->cur_ps_tdma == 3) {
  1810. halbtc8821a2ant_ps_tdma(btcoexist,
  1811. NORMAL_EXEC, true, 7);
  1812. coex_dm->ps_tdma_du_adj_type = 7;
  1813. } else if (coex_dm->cur_ps_tdma == 4) {
  1814. halbtc8821a2ant_ps_tdma(btcoexist,
  1815. NORMAL_EXEC, true, 8);
  1816. coex_dm->ps_tdma_du_adj_type = 8;
  1817. }
  1818. if (coex_dm->cur_ps_tdma == 9) {
  1819. halbtc8821a2ant_ps_tdma(btcoexist,
  1820. NORMAL_EXEC, true, 13);
  1821. coex_dm->ps_tdma_du_adj_type = 13;
  1822. } else if (coex_dm->cur_ps_tdma == 10) {
  1823. halbtc8821a2ant_ps_tdma(btcoexist,
  1824. NORMAL_EXEC, true, 14);
  1825. coex_dm->ps_tdma_du_adj_type = 14;
  1826. } else if (coex_dm->cur_ps_tdma == 11) {
  1827. halbtc8821a2ant_ps_tdma(btcoexist,
  1828. NORMAL_EXEC, true, 15);
  1829. coex_dm->ps_tdma_du_adj_type = 15;
  1830. } else if (coex_dm->cur_ps_tdma == 12) {
  1831. halbtc8821a2ant_ps_tdma(btcoexist,
  1832. NORMAL_EXEC, true, 16);
  1833. coex_dm->ps_tdma_du_adj_type = 16;
  1834. }
  1835. if (result == -1) {
  1836. if (coex_dm->cur_ps_tdma == 5) {
  1837. halbtc8821a2ant_ps_tdma(
  1838. btcoexist, NORMAL_EXEC,
  1839. true, 6);
  1840. coex_dm->ps_tdma_du_adj_type =
  1841. 6;
  1842. } else if (coex_dm->cur_ps_tdma == 6) {
  1843. halbtc8821a2ant_ps_tdma(
  1844. btcoexist, NORMAL_EXEC,
  1845. true, 7);
  1846. coex_dm->ps_tdma_du_adj_type =
  1847. 7;
  1848. } else if (coex_dm->cur_ps_tdma == 7) {
  1849. halbtc8821a2ant_ps_tdma(
  1850. btcoexist, NORMAL_EXEC,
  1851. true, 8);
  1852. coex_dm->ps_tdma_du_adj_type =
  1853. 8;
  1854. } else if (coex_dm->cur_ps_tdma == 13) {
  1855. halbtc8821a2ant_ps_tdma(
  1856. btcoexist, NORMAL_EXEC,
  1857. true, 14);
  1858. coex_dm->ps_tdma_du_adj_type =
  1859. 14;
  1860. } else if (coex_dm->cur_ps_tdma == 14) {
  1861. halbtc8821a2ant_ps_tdma(
  1862. btcoexist, NORMAL_EXEC,
  1863. true, 15);
  1864. coex_dm->ps_tdma_du_adj_type =
  1865. 15;
  1866. } else if (coex_dm->cur_ps_tdma == 15) {
  1867. halbtc8821a2ant_ps_tdma(
  1868. btcoexist, NORMAL_EXEC,
  1869. true, 16);
  1870. coex_dm->ps_tdma_du_adj_type =
  1871. 16;
  1872. }
  1873. } else if (result == 1) {
  1874. if (coex_dm->cur_ps_tdma == 8) {
  1875. halbtc8821a2ant_ps_tdma(
  1876. btcoexist, NORMAL_EXEC,
  1877. true, 7);
  1878. coex_dm->ps_tdma_du_adj_type =
  1879. 7;
  1880. } else if (coex_dm->cur_ps_tdma == 7) {
  1881. halbtc8821a2ant_ps_tdma(
  1882. btcoexist, NORMAL_EXEC,
  1883. true, 6);
  1884. coex_dm->ps_tdma_du_adj_type =
  1885. 6;
  1886. } else if (coex_dm->cur_ps_tdma == 6) {
  1887. halbtc8821a2ant_ps_tdma(
  1888. btcoexist, NORMAL_EXEC,
  1889. true, 5);
  1890. coex_dm->ps_tdma_du_adj_type =
  1891. 5;
  1892. } else if (coex_dm->cur_ps_tdma == 16) {
  1893. halbtc8821a2ant_ps_tdma(
  1894. btcoexist, NORMAL_EXEC,
  1895. true, 15);
  1896. coex_dm->ps_tdma_du_adj_type =
  1897. 15;
  1898. } else if (coex_dm->cur_ps_tdma == 15) {
  1899. halbtc8821a2ant_ps_tdma(
  1900. btcoexist, NORMAL_EXEC,
  1901. true, 14);
  1902. coex_dm->ps_tdma_du_adj_type =
  1903. 14;
  1904. } else if (coex_dm->cur_ps_tdma == 14) {
  1905. halbtc8821a2ant_ps_tdma(
  1906. btcoexist, NORMAL_EXEC,
  1907. true, 13);
  1908. coex_dm->ps_tdma_du_adj_type =
  1909. 13;
  1910. }
  1911. }
  1912. } else {
  1913. if (coex_dm->cur_ps_tdma == 5) {
  1914. halbtc8821a2ant_ps_tdma(btcoexist,
  1915. NORMAL_EXEC, true, 71);
  1916. coex_dm->ps_tdma_du_adj_type = 71;
  1917. } else if (coex_dm->cur_ps_tdma == 6) {
  1918. halbtc8821a2ant_ps_tdma(btcoexist,
  1919. NORMAL_EXEC, true, 2);
  1920. coex_dm->ps_tdma_du_adj_type = 2;
  1921. } else if (coex_dm->cur_ps_tdma == 7) {
  1922. halbtc8821a2ant_ps_tdma(btcoexist,
  1923. NORMAL_EXEC, true, 3);
  1924. coex_dm->ps_tdma_du_adj_type = 3;
  1925. } else if (coex_dm->cur_ps_tdma == 8) {
  1926. halbtc8821a2ant_ps_tdma(btcoexist,
  1927. NORMAL_EXEC, true, 4);
  1928. coex_dm->ps_tdma_du_adj_type = 4;
  1929. }
  1930. if (coex_dm->cur_ps_tdma == 13) {
  1931. halbtc8821a2ant_ps_tdma(btcoexist,
  1932. NORMAL_EXEC, true, 9);
  1933. coex_dm->ps_tdma_du_adj_type = 9;
  1934. } else if (coex_dm->cur_ps_tdma == 14) {
  1935. halbtc8821a2ant_ps_tdma(btcoexist,
  1936. NORMAL_EXEC, true, 10);
  1937. coex_dm->ps_tdma_du_adj_type = 10;
  1938. } else if (coex_dm->cur_ps_tdma == 15) {
  1939. halbtc8821a2ant_ps_tdma(btcoexist,
  1940. NORMAL_EXEC, true, 11);
  1941. coex_dm->ps_tdma_du_adj_type = 11;
  1942. } else if (coex_dm->cur_ps_tdma == 16) {
  1943. halbtc8821a2ant_ps_tdma(btcoexist,
  1944. NORMAL_EXEC, true, 12);
  1945. coex_dm->ps_tdma_du_adj_type = 12;
  1946. }
  1947. if (result == -1) {
  1948. if (coex_dm->cur_ps_tdma == 71) {
  1949. halbtc8821a2ant_ps_tdma(
  1950. btcoexist, NORMAL_EXEC,
  1951. true, 1);
  1952. coex_dm->ps_tdma_du_adj_type =
  1953. 1;
  1954. } else if (coex_dm->cur_ps_tdma == 1) {
  1955. halbtc8821a2ant_ps_tdma(
  1956. btcoexist, NORMAL_EXEC,
  1957. true, 2);
  1958. coex_dm->ps_tdma_du_adj_type =
  1959. 2;
  1960. } else if (coex_dm->cur_ps_tdma == 2) {
  1961. halbtc8821a2ant_ps_tdma(
  1962. btcoexist, NORMAL_EXEC,
  1963. true, 3);
  1964. coex_dm->ps_tdma_du_adj_type =
  1965. 3;
  1966. } else if (coex_dm->cur_ps_tdma == 3) {
  1967. halbtc8821a2ant_ps_tdma(
  1968. btcoexist, NORMAL_EXEC,
  1969. true, 4);
  1970. coex_dm->ps_tdma_du_adj_type =
  1971. 4;
  1972. } else if (coex_dm->cur_ps_tdma == 9) {
  1973. halbtc8821a2ant_ps_tdma(
  1974. btcoexist, NORMAL_EXEC,
  1975. true, 10);
  1976. coex_dm->ps_tdma_du_adj_type =
  1977. 10;
  1978. } else if (coex_dm->cur_ps_tdma == 10) {
  1979. halbtc8821a2ant_ps_tdma(
  1980. btcoexist, NORMAL_EXEC,
  1981. true, 11);
  1982. coex_dm->ps_tdma_du_adj_type =
  1983. 11;
  1984. } else if (coex_dm->cur_ps_tdma == 11) {
  1985. halbtc8821a2ant_ps_tdma(
  1986. btcoexist, NORMAL_EXEC,
  1987. true, 12);
  1988. coex_dm->ps_tdma_du_adj_type =
  1989. 12;
  1990. }
  1991. } else if (result == 1) {
  1992. if (coex_dm->cur_ps_tdma == 4) {
  1993. halbtc8821a2ant_ps_tdma(
  1994. btcoexist, NORMAL_EXEC,
  1995. true, 3);
  1996. coex_dm->ps_tdma_du_adj_type =
  1997. 3;
  1998. } else if (coex_dm->cur_ps_tdma == 3) {
  1999. halbtc8821a2ant_ps_tdma(
  2000. btcoexist, NORMAL_EXEC,
  2001. true, 2);
  2002. coex_dm->ps_tdma_du_adj_type =
  2003. 2;
  2004. } else if (coex_dm->cur_ps_tdma == 2) {
  2005. halbtc8821a2ant_ps_tdma(
  2006. btcoexist, NORMAL_EXEC,
  2007. true, 1);
  2008. coex_dm->ps_tdma_du_adj_type =
  2009. 1;
  2010. } else if (coex_dm->cur_ps_tdma == 1) {
  2011. halbtc8821a2ant_ps_tdma(
  2012. btcoexist, NORMAL_EXEC,
  2013. true, 71);
  2014. coex_dm->ps_tdma_du_adj_type =
  2015. 71;
  2016. } else if (coex_dm->cur_ps_tdma == 12) {
  2017. halbtc8821a2ant_ps_tdma(
  2018. btcoexist, NORMAL_EXEC,
  2019. true, 11);
  2020. coex_dm->ps_tdma_du_adj_type =
  2021. 11;
  2022. } else if (coex_dm->cur_ps_tdma == 11) {
  2023. halbtc8821a2ant_ps_tdma(
  2024. btcoexist, NORMAL_EXEC,
  2025. true, 10);
  2026. coex_dm->ps_tdma_du_adj_type =
  2027. 10;
  2028. } else if (coex_dm->cur_ps_tdma == 10) {
  2029. halbtc8821a2ant_ps_tdma(
  2030. btcoexist, NORMAL_EXEC,
  2031. true, 9);
  2032. coex_dm->ps_tdma_du_adj_type =
  2033. 9;
  2034. }
  2035. }
  2036. }
  2037. } else if (max_interval == 2) {
  2038. if (tx_pause) {
  2039. if (coex_dm->cur_ps_tdma == 1) {
  2040. halbtc8821a2ant_ps_tdma(btcoexist,
  2041. NORMAL_EXEC, true, 6);
  2042. coex_dm->ps_tdma_du_adj_type = 6;
  2043. } else if (coex_dm->cur_ps_tdma == 2) {
  2044. halbtc8821a2ant_ps_tdma(btcoexist,
  2045. NORMAL_EXEC, true, 6);
  2046. coex_dm->ps_tdma_du_adj_type = 6;
  2047. } else if (coex_dm->cur_ps_tdma == 3) {
  2048. halbtc8821a2ant_ps_tdma(btcoexist,
  2049. NORMAL_EXEC, true, 7);
  2050. coex_dm->ps_tdma_du_adj_type = 7;
  2051. } else if (coex_dm->cur_ps_tdma == 4) {
  2052. halbtc8821a2ant_ps_tdma(btcoexist,
  2053. NORMAL_EXEC, true, 8);
  2054. coex_dm->ps_tdma_du_adj_type = 8;
  2055. }
  2056. if (coex_dm->cur_ps_tdma == 9) {
  2057. halbtc8821a2ant_ps_tdma(btcoexist,
  2058. NORMAL_EXEC, true, 14);
  2059. coex_dm->ps_tdma_du_adj_type = 14;
  2060. } else if (coex_dm->cur_ps_tdma == 10) {
  2061. halbtc8821a2ant_ps_tdma(btcoexist,
  2062. NORMAL_EXEC, true, 14);
  2063. coex_dm->ps_tdma_du_adj_type = 14;
  2064. } else if (coex_dm->cur_ps_tdma == 11) {
  2065. halbtc8821a2ant_ps_tdma(btcoexist,
  2066. NORMAL_EXEC, true, 15);
  2067. coex_dm->ps_tdma_du_adj_type = 15;
  2068. } else if (coex_dm->cur_ps_tdma == 12) {
  2069. halbtc8821a2ant_ps_tdma(btcoexist,
  2070. NORMAL_EXEC, true, 16);
  2071. coex_dm->ps_tdma_du_adj_type = 16;
  2072. }
  2073. if (result == -1) {
  2074. if (coex_dm->cur_ps_tdma == 5) {
  2075. halbtc8821a2ant_ps_tdma(
  2076. btcoexist, NORMAL_EXEC,
  2077. true, 6);
  2078. coex_dm->ps_tdma_du_adj_type =
  2079. 6;
  2080. } else if (coex_dm->cur_ps_tdma == 6) {
  2081. halbtc8821a2ant_ps_tdma(
  2082. btcoexist, NORMAL_EXEC,
  2083. true, 7);
  2084. coex_dm->ps_tdma_du_adj_type =
  2085. 7;
  2086. } else if (coex_dm->cur_ps_tdma == 7) {
  2087. halbtc8821a2ant_ps_tdma(
  2088. btcoexist, NORMAL_EXEC,
  2089. true, 8);
  2090. coex_dm->ps_tdma_du_adj_type =
  2091. 8;
  2092. } else if (coex_dm->cur_ps_tdma == 13) {
  2093. halbtc8821a2ant_ps_tdma(
  2094. btcoexist, NORMAL_EXEC,
  2095. true, 14);
  2096. coex_dm->ps_tdma_du_adj_type =
  2097. 14;
  2098. } else if (coex_dm->cur_ps_tdma == 14) {
  2099. halbtc8821a2ant_ps_tdma(
  2100. btcoexist, NORMAL_EXEC,
  2101. true, 15);
  2102. coex_dm->ps_tdma_du_adj_type =
  2103. 15;
  2104. } else if (coex_dm->cur_ps_tdma == 15) {
  2105. halbtc8821a2ant_ps_tdma(
  2106. btcoexist, NORMAL_EXEC,
  2107. true, 16);
  2108. coex_dm->ps_tdma_du_adj_type =
  2109. 16;
  2110. }
  2111. } else if (result == 1) {
  2112. if (coex_dm->cur_ps_tdma == 8) {
  2113. halbtc8821a2ant_ps_tdma(
  2114. btcoexist, NORMAL_EXEC,
  2115. true, 7);
  2116. coex_dm->ps_tdma_du_adj_type =
  2117. 7;
  2118. } else if (coex_dm->cur_ps_tdma == 7) {
  2119. halbtc8821a2ant_ps_tdma(
  2120. btcoexist, NORMAL_EXEC,
  2121. true, 6);
  2122. coex_dm->ps_tdma_du_adj_type =
  2123. 6;
  2124. } else if (coex_dm->cur_ps_tdma == 6) {
  2125. halbtc8821a2ant_ps_tdma(
  2126. btcoexist, NORMAL_EXEC,
  2127. true, 6);
  2128. coex_dm->ps_tdma_du_adj_type =
  2129. 6;
  2130. } else if (coex_dm->cur_ps_tdma == 16) {
  2131. halbtc8821a2ant_ps_tdma(
  2132. btcoexist, NORMAL_EXEC,
  2133. true, 15);
  2134. coex_dm->ps_tdma_du_adj_type =
  2135. 15;
  2136. } else if (coex_dm->cur_ps_tdma == 15) {
  2137. halbtc8821a2ant_ps_tdma(
  2138. btcoexist, NORMAL_EXEC,
  2139. true, 14);
  2140. coex_dm->ps_tdma_du_adj_type =
  2141. 14;
  2142. } else if (coex_dm->cur_ps_tdma == 14) {
  2143. halbtc8821a2ant_ps_tdma(
  2144. btcoexist, NORMAL_EXEC,
  2145. true, 14);
  2146. coex_dm->ps_tdma_du_adj_type =
  2147. 14;
  2148. }
  2149. }
  2150. } else {
  2151. if (coex_dm->cur_ps_tdma == 5) {
  2152. halbtc8821a2ant_ps_tdma(btcoexist,
  2153. NORMAL_EXEC, true, 2);
  2154. coex_dm->ps_tdma_du_adj_type = 2;
  2155. } else if (coex_dm->cur_ps_tdma == 6) {
  2156. halbtc8821a2ant_ps_tdma(btcoexist,
  2157. NORMAL_EXEC, true, 2);
  2158. coex_dm->ps_tdma_du_adj_type = 2;
  2159. } else if (coex_dm->cur_ps_tdma == 7) {
  2160. halbtc8821a2ant_ps_tdma(btcoexist,
  2161. NORMAL_EXEC, true, 3);
  2162. coex_dm->ps_tdma_du_adj_type = 3;
  2163. } else if (coex_dm->cur_ps_tdma == 8) {
  2164. halbtc8821a2ant_ps_tdma(btcoexist,
  2165. NORMAL_EXEC, true, 4);
  2166. coex_dm->ps_tdma_du_adj_type = 4;
  2167. }
  2168. if (coex_dm->cur_ps_tdma == 13) {
  2169. halbtc8821a2ant_ps_tdma(btcoexist,
  2170. NORMAL_EXEC, true, 10);
  2171. coex_dm->ps_tdma_du_adj_type = 10;
  2172. } else if (coex_dm->cur_ps_tdma == 14) {
  2173. halbtc8821a2ant_ps_tdma(btcoexist,
  2174. NORMAL_EXEC, true, 10);
  2175. coex_dm->ps_tdma_du_adj_type = 10;
  2176. } else if (coex_dm->cur_ps_tdma == 15) {
  2177. halbtc8821a2ant_ps_tdma(btcoexist,
  2178. NORMAL_EXEC, true, 11);
  2179. coex_dm->ps_tdma_du_adj_type = 11;
  2180. } else if (coex_dm->cur_ps_tdma == 16) {
  2181. halbtc8821a2ant_ps_tdma(btcoexist,
  2182. NORMAL_EXEC, true, 12);
  2183. coex_dm->ps_tdma_du_adj_type = 12;
  2184. }
  2185. if (result == -1) {
  2186. if (coex_dm->cur_ps_tdma == 1) {
  2187. halbtc8821a2ant_ps_tdma(
  2188. btcoexist, NORMAL_EXEC,
  2189. true, 2);
  2190. coex_dm->ps_tdma_du_adj_type =
  2191. 2;
  2192. } else if (coex_dm->cur_ps_tdma == 2) {
  2193. halbtc8821a2ant_ps_tdma(
  2194. btcoexist, NORMAL_EXEC,
  2195. true, 3);
  2196. coex_dm->ps_tdma_du_adj_type =
  2197. 3;
  2198. } else if (coex_dm->cur_ps_tdma == 3) {
  2199. halbtc8821a2ant_ps_tdma(
  2200. btcoexist, NORMAL_EXEC,
  2201. true, 4);
  2202. coex_dm->ps_tdma_du_adj_type =
  2203. 4;
  2204. } else if (coex_dm->cur_ps_tdma == 9) {
  2205. halbtc8821a2ant_ps_tdma(
  2206. btcoexist, NORMAL_EXEC,
  2207. true, 10);
  2208. coex_dm->ps_tdma_du_adj_type =
  2209. 10;
  2210. } else if (coex_dm->cur_ps_tdma == 10) {
  2211. halbtc8821a2ant_ps_tdma(
  2212. btcoexist, NORMAL_EXEC,
  2213. true, 11);
  2214. coex_dm->ps_tdma_du_adj_type =
  2215. 11;
  2216. } else if (coex_dm->cur_ps_tdma == 11) {
  2217. halbtc8821a2ant_ps_tdma(
  2218. btcoexist, NORMAL_EXEC,
  2219. true, 12);
  2220. coex_dm->ps_tdma_du_adj_type =
  2221. 12;
  2222. }
  2223. } else if (result == 1) {
  2224. if (coex_dm->cur_ps_tdma == 4) {
  2225. halbtc8821a2ant_ps_tdma(
  2226. btcoexist, NORMAL_EXEC,
  2227. true, 3);
  2228. coex_dm->ps_tdma_du_adj_type =
  2229. 3;
  2230. } else if (coex_dm->cur_ps_tdma == 3) {
  2231. halbtc8821a2ant_ps_tdma(
  2232. btcoexist, NORMAL_EXEC,
  2233. true, 2);
  2234. coex_dm->ps_tdma_du_adj_type =
  2235. 2;
  2236. } else if (coex_dm->cur_ps_tdma == 2) {
  2237. halbtc8821a2ant_ps_tdma(
  2238. btcoexist, NORMAL_EXEC,
  2239. true, 2);
  2240. coex_dm->ps_tdma_du_adj_type =
  2241. 2;
  2242. } else if (coex_dm->cur_ps_tdma == 12) {
  2243. halbtc8821a2ant_ps_tdma(
  2244. btcoexist, NORMAL_EXEC,
  2245. true, 11);
  2246. coex_dm->ps_tdma_du_adj_type =
  2247. 11;
  2248. } else if (coex_dm->cur_ps_tdma == 11) {
  2249. halbtc8821a2ant_ps_tdma(
  2250. btcoexist, NORMAL_EXEC,
  2251. true, 10);
  2252. coex_dm->ps_tdma_du_adj_type =
  2253. 10;
  2254. } else if (coex_dm->cur_ps_tdma == 10) {
  2255. halbtc8821a2ant_ps_tdma(
  2256. btcoexist, NORMAL_EXEC,
  2257. true, 10);
  2258. coex_dm->ps_tdma_du_adj_type =
  2259. 10;
  2260. }
  2261. }
  2262. }
  2263. } else if (max_interval == 3) {
  2264. if (tx_pause) {
  2265. if (coex_dm->cur_ps_tdma == 1) {
  2266. halbtc8821a2ant_ps_tdma(btcoexist,
  2267. NORMAL_EXEC, true, 7);
  2268. coex_dm->ps_tdma_du_adj_type = 7;
  2269. } else if (coex_dm->cur_ps_tdma == 2) {
  2270. halbtc8821a2ant_ps_tdma(btcoexist,
  2271. NORMAL_EXEC, true, 7);
  2272. coex_dm->ps_tdma_du_adj_type = 7;
  2273. } else if (coex_dm->cur_ps_tdma == 3) {
  2274. halbtc8821a2ant_ps_tdma(btcoexist,
  2275. NORMAL_EXEC, true, 7);
  2276. coex_dm->ps_tdma_du_adj_type = 7;
  2277. } else if (coex_dm->cur_ps_tdma == 4) {
  2278. halbtc8821a2ant_ps_tdma(btcoexist,
  2279. NORMAL_EXEC, true, 8);
  2280. coex_dm->ps_tdma_du_adj_type = 8;
  2281. }
  2282. if (coex_dm->cur_ps_tdma == 9) {
  2283. halbtc8821a2ant_ps_tdma(btcoexist,
  2284. NORMAL_EXEC, true, 15);
  2285. coex_dm->ps_tdma_du_adj_type = 15;
  2286. } else if (coex_dm->cur_ps_tdma == 10) {
  2287. halbtc8821a2ant_ps_tdma(btcoexist,
  2288. NORMAL_EXEC, true, 15);
  2289. coex_dm->ps_tdma_du_adj_type = 15;
  2290. } else if (coex_dm->cur_ps_tdma == 11) {
  2291. halbtc8821a2ant_ps_tdma(btcoexist,
  2292. NORMAL_EXEC, true, 15);
  2293. coex_dm->ps_tdma_du_adj_type = 15;
  2294. } else if (coex_dm->cur_ps_tdma == 12) {
  2295. halbtc8821a2ant_ps_tdma(btcoexist,
  2296. NORMAL_EXEC, true, 16);
  2297. coex_dm->ps_tdma_du_adj_type = 16;
  2298. }
  2299. if (result == -1) {
  2300. if (coex_dm->cur_ps_tdma == 5) {
  2301. halbtc8821a2ant_ps_tdma(
  2302. btcoexist, NORMAL_EXEC,
  2303. true, 7);
  2304. coex_dm->ps_tdma_du_adj_type =
  2305. 7;
  2306. } else if (coex_dm->cur_ps_tdma == 6) {
  2307. halbtc8821a2ant_ps_tdma(
  2308. btcoexist, NORMAL_EXEC,
  2309. true, 7);
  2310. coex_dm->ps_tdma_du_adj_type =
  2311. 7;
  2312. } else if (coex_dm->cur_ps_tdma == 7) {
  2313. halbtc8821a2ant_ps_tdma(
  2314. btcoexist, NORMAL_EXEC,
  2315. true, 8);
  2316. coex_dm->ps_tdma_du_adj_type =
  2317. 8;
  2318. } else if (coex_dm->cur_ps_tdma == 13) {
  2319. halbtc8821a2ant_ps_tdma(
  2320. btcoexist, NORMAL_EXEC,
  2321. true, 15);
  2322. coex_dm->ps_tdma_du_adj_type =
  2323. 15;
  2324. } else if (coex_dm->cur_ps_tdma == 14) {
  2325. halbtc8821a2ant_ps_tdma(
  2326. btcoexist, NORMAL_EXEC,
  2327. true, 15);
  2328. coex_dm->ps_tdma_du_adj_type =
  2329. 15;
  2330. } else if (coex_dm->cur_ps_tdma == 15) {
  2331. halbtc8821a2ant_ps_tdma(
  2332. btcoexist, NORMAL_EXEC,
  2333. true, 16);
  2334. coex_dm->ps_tdma_du_adj_type =
  2335. 16;
  2336. }
  2337. } else if (result == 1) {
  2338. if (coex_dm->cur_ps_tdma == 8) {
  2339. halbtc8821a2ant_ps_tdma(
  2340. btcoexist, NORMAL_EXEC,
  2341. true, 7);
  2342. coex_dm->ps_tdma_du_adj_type =
  2343. 7;
  2344. } else if (coex_dm->cur_ps_tdma == 7) {
  2345. halbtc8821a2ant_ps_tdma(
  2346. btcoexist, NORMAL_EXEC,
  2347. true, 7);
  2348. coex_dm->ps_tdma_du_adj_type =
  2349. 7;
  2350. } else if (coex_dm->cur_ps_tdma == 6) {
  2351. halbtc8821a2ant_ps_tdma(
  2352. btcoexist, NORMAL_EXEC,
  2353. true, 7);
  2354. coex_dm->ps_tdma_du_adj_type =
  2355. 7;
  2356. } else if (coex_dm->cur_ps_tdma == 16) {
  2357. halbtc8821a2ant_ps_tdma(
  2358. btcoexist, NORMAL_EXEC,
  2359. true, 15);
  2360. coex_dm->ps_tdma_du_adj_type =
  2361. 15;
  2362. } else if (coex_dm->cur_ps_tdma == 15) {
  2363. halbtc8821a2ant_ps_tdma(
  2364. btcoexist, NORMAL_EXEC,
  2365. true, 15);
  2366. coex_dm->ps_tdma_du_adj_type =
  2367. 15;
  2368. } else if (coex_dm->cur_ps_tdma == 14) {
  2369. halbtc8821a2ant_ps_tdma(
  2370. btcoexist, NORMAL_EXEC,
  2371. true, 15);
  2372. coex_dm->ps_tdma_du_adj_type =
  2373. 15;
  2374. }
  2375. }
  2376. } else {
  2377. if (coex_dm->cur_ps_tdma == 5) {
  2378. halbtc8821a2ant_ps_tdma(btcoexist,
  2379. NORMAL_EXEC, true, 3);
  2380. coex_dm->ps_tdma_du_adj_type = 3;
  2381. } else if (coex_dm->cur_ps_tdma == 6) {
  2382. halbtc8821a2ant_ps_tdma(btcoexist,
  2383. NORMAL_EXEC, true, 3);
  2384. coex_dm->ps_tdma_du_adj_type = 3;
  2385. } else if (coex_dm->cur_ps_tdma == 7) {
  2386. halbtc8821a2ant_ps_tdma(btcoexist,
  2387. NORMAL_EXEC, true, 3);
  2388. coex_dm->ps_tdma_du_adj_type = 3;
  2389. } else if (coex_dm->cur_ps_tdma == 8) {
  2390. halbtc8821a2ant_ps_tdma(btcoexist,
  2391. NORMAL_EXEC, true, 4);
  2392. coex_dm->ps_tdma_du_adj_type = 4;
  2393. }
  2394. if (coex_dm->cur_ps_tdma == 13) {
  2395. halbtc8821a2ant_ps_tdma(btcoexist,
  2396. NORMAL_EXEC, true, 11);
  2397. coex_dm->ps_tdma_du_adj_type = 11;
  2398. } else if (coex_dm->cur_ps_tdma == 14) {
  2399. halbtc8821a2ant_ps_tdma(btcoexist,
  2400. NORMAL_EXEC, true, 11);
  2401. coex_dm->ps_tdma_du_adj_type = 11;
  2402. } else if (coex_dm->cur_ps_tdma == 15) {
  2403. halbtc8821a2ant_ps_tdma(btcoexist,
  2404. NORMAL_EXEC, true, 11);
  2405. coex_dm->ps_tdma_du_adj_type = 11;
  2406. } else if (coex_dm->cur_ps_tdma == 16) {
  2407. halbtc8821a2ant_ps_tdma(btcoexist,
  2408. NORMAL_EXEC, true, 12);
  2409. coex_dm->ps_tdma_du_adj_type = 12;
  2410. }
  2411. if (result == -1) {
  2412. if (coex_dm->cur_ps_tdma == 1) {
  2413. halbtc8821a2ant_ps_tdma(
  2414. btcoexist, NORMAL_EXEC,
  2415. true, 3);
  2416. coex_dm->ps_tdma_du_adj_type =
  2417. 3;
  2418. } else if (coex_dm->cur_ps_tdma == 2) {
  2419. halbtc8821a2ant_ps_tdma(
  2420. btcoexist, NORMAL_EXEC,
  2421. true, 3);
  2422. coex_dm->ps_tdma_du_adj_type =
  2423. 3;
  2424. } else if (coex_dm->cur_ps_tdma == 3) {
  2425. halbtc8821a2ant_ps_tdma(
  2426. btcoexist, NORMAL_EXEC,
  2427. true, 4);
  2428. coex_dm->ps_tdma_du_adj_type =
  2429. 4;
  2430. } else if (coex_dm->cur_ps_tdma == 9) {
  2431. halbtc8821a2ant_ps_tdma(
  2432. btcoexist, NORMAL_EXEC,
  2433. true, 11);
  2434. coex_dm->ps_tdma_du_adj_type =
  2435. 11;
  2436. } else if (coex_dm->cur_ps_tdma == 10) {
  2437. halbtc8821a2ant_ps_tdma(
  2438. btcoexist, NORMAL_EXEC,
  2439. true, 11);
  2440. coex_dm->ps_tdma_du_adj_type =
  2441. 11;
  2442. } else if (coex_dm->cur_ps_tdma == 11) {
  2443. halbtc8821a2ant_ps_tdma(
  2444. btcoexist, NORMAL_EXEC,
  2445. true, 12);
  2446. coex_dm->ps_tdma_du_adj_type =
  2447. 12;
  2448. }
  2449. } else if (result == 1) {
  2450. if (coex_dm->cur_ps_tdma == 4) {
  2451. halbtc8821a2ant_ps_tdma(
  2452. btcoexist, NORMAL_EXEC,
  2453. true, 3);
  2454. coex_dm->ps_tdma_du_adj_type =
  2455. 3;
  2456. } else if (coex_dm->cur_ps_tdma == 3) {
  2457. halbtc8821a2ant_ps_tdma(
  2458. btcoexist, NORMAL_EXEC,
  2459. true, 3);
  2460. coex_dm->ps_tdma_du_adj_type =
  2461. 3;
  2462. } else if (coex_dm->cur_ps_tdma == 2) {
  2463. halbtc8821a2ant_ps_tdma(
  2464. btcoexist, NORMAL_EXEC,
  2465. true, 3);
  2466. coex_dm->ps_tdma_du_adj_type =
  2467. 3;
  2468. } else if (coex_dm->cur_ps_tdma == 12) {
  2469. halbtc8821a2ant_ps_tdma(
  2470. btcoexist, NORMAL_EXEC,
  2471. true, 11);
  2472. coex_dm->ps_tdma_du_adj_type =
  2473. 11;
  2474. } else if (coex_dm->cur_ps_tdma == 11) {
  2475. halbtc8821a2ant_ps_tdma(
  2476. btcoexist, NORMAL_EXEC,
  2477. true, 11);
  2478. coex_dm->ps_tdma_du_adj_type =
  2479. 11;
  2480. } else if (coex_dm->cur_ps_tdma == 10) {
  2481. halbtc8821a2ant_ps_tdma(
  2482. btcoexist, NORMAL_EXEC,
  2483. true, 11);
  2484. coex_dm->ps_tdma_du_adj_type =
  2485. 11;
  2486. }
  2487. }
  2488. }
  2489. }
  2490. }
  2491. /* if current PsTdma not match with the recorded one (when scan, dhcp...), */
  2492. /* then we have to adjust it back to the previous record one. */
  2493. if (coex_dm->cur_ps_tdma != coex_dm->ps_tdma_du_adj_type) {
  2494. boolean scan = false, link = false, roam = false;
  2495. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2496. "[BTCoex], PsTdma type dismatch!!!, cur_ps_tdma=%d, recordPsTdma=%d\n",
  2497. coex_dm->cur_ps_tdma, coex_dm->ps_tdma_du_adj_type);
  2498. BTC_TRACE(trace_buf);
  2499. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
  2500. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
  2501. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
  2502. if (!scan && !link && !roam)
  2503. halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2504. coex_dm->ps_tdma_du_adj_type);
  2505. else {
  2506. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2507. "[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n");
  2508. BTC_TRACE(trace_buf);
  2509. }
  2510. }
  2511. }
  2512. /* SCO only or SCO+PAN(HS) */
  2513. void halbtc8821a2ant_action_sco(IN struct btc_coexist *btcoexist)
  2514. {
  2515. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  2516. u8 wifi_rssi_state, bt_rssi_state;
  2517. u32 wifi_bw;
  2518. wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15,
  2519. 0);
  2520. bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2,
  2521. BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
  2522. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
  2523. halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
  2524. halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 4);
  2525. if (BTC_RSSI_HIGH(bt_rssi_state))
  2526. halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
  2527. else
  2528. halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2529. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  2530. if (BTC_WIFI_BW_LEGACY == wifi_bw) /* for SCO quality at 11b/g mode */
  2531. halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  2532. else { /* for SCO quality & wifi performance balance at 11n mode */
  2533. if (BTC_WIFI_BW_HT40 == wifi_bw)
  2534. halbtc8821a2ant_coex_table_with_type(btcoexist,
  2535. NORMAL_EXEC, 8);
  2536. else {
  2537. if (bt_link_info->sco_only)
  2538. halbtc8821a2ant_coex_table_with_type(btcoexist,
  2539. NORMAL_EXEC, 17);
  2540. else
  2541. halbtc8821a2ant_coex_table_with_type(btcoexist,
  2542. NORMAL_EXEC, 12);
  2543. }
  2544. }
  2545. halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
  2546. 0); /* for voice quality */
  2547. /* sw mechanism */
  2548. if (BTC_WIFI_BW_HT40 == wifi_bw) {
  2549. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2550. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2551. halbtc8821a2ant_sw_mechanism1(btcoexist, true, true,
  2552. false, false);
  2553. halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
  2554. true, 0x18);
  2555. } else {
  2556. halbtc8821a2ant_sw_mechanism1(btcoexist, true, true,
  2557. false, false);
  2558. halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
  2559. true, 0x18);
  2560. }
  2561. } else {
  2562. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2563. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2564. halbtc8821a2ant_sw_mechanism1(btcoexist, false, true,
  2565. false, false);
  2566. halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
  2567. true, 0x18);
  2568. } else {
  2569. halbtc8821a2ant_sw_mechanism1(btcoexist, false, true,
  2570. false, false);
  2571. halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
  2572. true, 0x18);
  2573. }
  2574. }
  2575. }
  2576. void halbtc8821a2ant_action_hid(IN struct btc_coexist *btcoexist)
  2577. {
  2578. u8 wifi_rssi_state, bt_rssi_state;
  2579. u32 wifi_bw;
  2580. btcoexist->btc_phydm_modify_RA_PCR_threshold(btcoexist, 0, 25);
  2581. wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15,
  2582. 0);
  2583. bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2,
  2584. BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
  2585. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
  2586. halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
  2587. halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  2588. if (BTC_RSSI_HIGH(bt_rssi_state))
  2589. halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
  2590. else
  2591. halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2592. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  2593. if (BTC_WIFI_BW_LEGACY == wifi_bw) /* for HID at 11b/g mode */
  2594. halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
  2595. else /* for HID quality & wifi performance balance at 11n mode */
  2596. halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  2597. halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 24);
  2598. /* sw mechanism */
  2599. if (BTC_WIFI_BW_HT40 == wifi_bw) {
  2600. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2601. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2602. halbtc8821a2ant_sw_mechanism1(btcoexist, true, true,
  2603. false, false);
  2604. halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
  2605. false, 0x18);
  2606. } else {
  2607. halbtc8821a2ant_sw_mechanism1(btcoexist, true, true,
  2608. false, false);
  2609. halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
  2610. false, 0x18);
  2611. }
  2612. } else {
  2613. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2614. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2615. halbtc8821a2ant_sw_mechanism1(btcoexist, false, true,
  2616. false, false);
  2617. halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
  2618. false, 0x18);
  2619. } else {
  2620. halbtc8821a2ant_sw_mechanism1(btcoexist, false, true,
  2621. false, false);
  2622. halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
  2623. false, 0x18);
  2624. }
  2625. }
  2626. }
  2627. /* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */
  2628. void halbtc8821a2ant_action_a2dp(IN struct btc_coexist *btcoexist)
  2629. {
  2630. u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
  2631. u32 wifi_bw;
  2632. u8 ap_num = 0;
  2633. wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15,
  2634. 0);
  2635. wifi_rssi_state1 = halbtc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
  2636. BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
  2637. bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2,
  2638. BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
  2639. btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, &ap_num);
  2640. /* define the office environment */
  2641. if ((ap_num >= 10) && BTC_RSSI_HIGH(wifi_rssi_state1) &&
  2642. BTC_RSSI_HIGH(bt_rssi_state)) {
  2643. /* dbg_print(" AP#>10(%d)\n", ap_num); */
  2644. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff,
  2645. 0x0);
  2646. halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
  2647. 0x8);
  2648. halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  2649. halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
  2650. halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  2651. /* halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1); */
  2652. halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 23);
  2653. /* sw mechanism */
  2654. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  2655. if (BTC_WIFI_BW_HT40 == wifi_bw) {
  2656. halbtc8821a2ant_sw_mechanism1(btcoexist, true, false,
  2657. false, false);
  2658. halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
  2659. true, 0x6);
  2660. } else {
  2661. halbtc8821a2ant_sw_mechanism1(btcoexist, false, false,
  2662. false, false);
  2663. halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
  2664. true, 0x6);
  2665. }
  2666. return;
  2667. }
  2668. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
  2669. halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
  2670. halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  2671. if (BTC_RSSI_HIGH(bt_rssi_state))
  2672. halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
  2673. else
  2674. halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2675. if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2676. (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2677. /* halbtc8821a2ant_tdma_duration_adjust(btcoexist, false, false, 1); */
  2678. halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 23);
  2679. } else {
  2680. /* halbtc8821a2ant_tdma_duration_adjust(btcoexist, false, true, 1); */
  2681. halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 23);
  2682. }
  2683. /* sw mechanism */
  2684. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  2685. if (BTC_WIFI_BW_HT40 == wifi_bw) {
  2686. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2687. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2688. halbtc8821a2ant_sw_mechanism1(btcoexist, true, false,
  2689. false, false);
  2690. halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
  2691. false, 0x18);
  2692. } else {
  2693. halbtc8821a2ant_sw_mechanism1(btcoexist, true, false,
  2694. false, false);
  2695. halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
  2696. false, 0x18);
  2697. }
  2698. } else {
  2699. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2700. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2701. halbtc8821a2ant_sw_mechanism1(btcoexist, false, false,
  2702. false, false);
  2703. halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
  2704. false, 0x18);
  2705. } else {
  2706. halbtc8821a2ant_sw_mechanism1(btcoexist, false, false,
  2707. false, false);
  2708. halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
  2709. false, 0x18);
  2710. }
  2711. }
  2712. }
  2713. void halbtc8821a2ant_action_a2dp_pan_hs(IN struct btc_coexist *btcoexist)
  2714. {
  2715. u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
  2716. u32 wifi_bw;
  2717. wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15,
  2718. 0);
  2719. wifi_rssi_state1 = halbtc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
  2720. BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
  2721. bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2,
  2722. BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
  2723. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
  2724. halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
  2725. halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  2726. if (BTC_RSSI_HIGH(bt_rssi_state))
  2727. halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
  2728. else
  2729. halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2730. if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) {
  2731. halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
  2732. } else {
  2733. halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
  2734. 13);
  2735. }
  2736. halbtc8821a2ant_tdma_duration_adjust(btcoexist, false, true, 2);
  2737. /* sw mechanism */
  2738. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  2739. if (BTC_WIFI_BW_HT40 == wifi_bw) {
  2740. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2741. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2742. halbtc8821a2ant_sw_mechanism1(btcoexist, true, false,
  2743. false, false);
  2744. halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
  2745. false, 0x18);
  2746. } else {
  2747. halbtc8821a2ant_sw_mechanism1(btcoexist, true, false,
  2748. false, false);
  2749. halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
  2750. false, 0x18);
  2751. }
  2752. } else {
  2753. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2754. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2755. halbtc8821a2ant_sw_mechanism1(btcoexist, false, false,
  2756. false, false);
  2757. halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
  2758. false, 0x18);
  2759. } else {
  2760. halbtc8821a2ant_sw_mechanism1(btcoexist, false, false,
  2761. false, false);
  2762. halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
  2763. false, 0x18);
  2764. }
  2765. }
  2766. }
  2767. void halbtc8821a2ant_action_pan_edr(IN struct btc_coexist *btcoexist)
  2768. {
  2769. u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
  2770. u32 wifi_bw;
  2771. wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15,
  2772. 0);
  2773. wifi_rssi_state1 = halbtc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
  2774. BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
  2775. bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2,
  2776. BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
  2777. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
  2778. halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
  2779. halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  2780. if (BTC_RSSI_HIGH(bt_rssi_state))
  2781. halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
  2782. else
  2783. halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2784. if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) {
  2785. halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
  2786. 10);
  2787. } else {
  2788. halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
  2789. 13);
  2790. }
  2791. if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2792. (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH))
  2793. halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 26);
  2794. else
  2795. halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 26);
  2796. /* sw mechanism */
  2797. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  2798. if (BTC_WIFI_BW_HT40 == wifi_bw) {
  2799. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2800. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2801. halbtc8821a2ant_sw_mechanism1(btcoexist, true, false,
  2802. false, false);
  2803. halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
  2804. false, 0x18);
  2805. } else {
  2806. halbtc8821a2ant_sw_mechanism1(btcoexist, true, false,
  2807. false, false);
  2808. halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
  2809. false, 0x18);
  2810. }
  2811. } else {
  2812. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2813. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2814. halbtc8821a2ant_sw_mechanism1(btcoexist, false, false,
  2815. false, false);
  2816. halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
  2817. false, 0x18);
  2818. } else {
  2819. halbtc8821a2ant_sw_mechanism1(btcoexist, false, false,
  2820. false, false);
  2821. halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
  2822. false, 0x18);
  2823. }
  2824. }
  2825. }
  2826. /* PAN(HS) only */
  2827. void halbtc8821a2ant_action_pan_hs(IN struct btc_coexist *btcoexist)
  2828. {
  2829. u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
  2830. u32 wifi_bw;
  2831. wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15,
  2832. 0);
  2833. wifi_rssi_state1 = halbtc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
  2834. BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
  2835. bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2,
  2836. BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
  2837. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
  2838. halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
  2839. halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  2840. if (BTC_RSSI_HIGH(bt_rssi_state))
  2841. halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
  2842. else
  2843. halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2844. halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
  2845. halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
  2846. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  2847. if (BTC_WIFI_BW_HT40 == wifi_bw) {
  2848. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2849. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2850. halbtc8821a2ant_sw_mechanism1(btcoexist, true, false,
  2851. false, false);
  2852. halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
  2853. false, 0x18);
  2854. } else {
  2855. halbtc8821a2ant_sw_mechanism1(btcoexist, true, false,
  2856. false, false);
  2857. halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
  2858. false, 0x18);
  2859. }
  2860. } else {
  2861. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2862. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2863. halbtc8821a2ant_sw_mechanism1(btcoexist, false, false,
  2864. false, false);
  2865. halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
  2866. false, 0x18);
  2867. } else {
  2868. halbtc8821a2ant_sw_mechanism1(btcoexist, false, false,
  2869. false, false);
  2870. halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
  2871. false, 0x18);
  2872. }
  2873. }
  2874. }
  2875. /* PAN(EDR)+A2DP */
  2876. void halbtc8821a2ant_action_pan_edr_a2dp(IN struct btc_coexist *btcoexist)
  2877. {
  2878. u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
  2879. u32 wifi_bw;
  2880. wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15,
  2881. 0);
  2882. wifi_rssi_state1 = halbtc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
  2883. BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
  2884. bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2,
  2885. BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
  2886. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
  2887. halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
  2888. halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  2889. if (BTC_RSSI_HIGH(bt_rssi_state))
  2890. halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
  2891. else
  2892. halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2893. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  2894. if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2895. (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2896. halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
  2897. 12);
  2898. if (BTC_WIFI_BW_HT40 == wifi_bw)
  2899. halbtc8821a2ant_tdma_duration_adjust(btcoexist, false,
  2900. true, 3);
  2901. else
  2902. halbtc8821a2ant_tdma_duration_adjust(btcoexist, false,
  2903. false, 3);
  2904. } else {
  2905. halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
  2906. 13);
  2907. halbtc8821a2ant_tdma_duration_adjust(btcoexist, false, true, 3);
  2908. }
  2909. /* sw mechanism */
  2910. if (BTC_WIFI_BW_HT40 == wifi_bw) {
  2911. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2912. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2913. halbtc8821a2ant_sw_mechanism1(btcoexist, true, false,
  2914. false, false);
  2915. halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
  2916. false, 0x18);
  2917. } else {
  2918. halbtc8821a2ant_sw_mechanism1(btcoexist, true, false,
  2919. false, false);
  2920. halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
  2921. false, 0x18);
  2922. }
  2923. } else {
  2924. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2925. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2926. halbtc8821a2ant_sw_mechanism1(btcoexist, false, false,
  2927. false, false);
  2928. halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
  2929. false, 0x18);
  2930. } else {
  2931. halbtc8821a2ant_sw_mechanism1(btcoexist, false, false,
  2932. false, false);
  2933. halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
  2934. false, 0x18);
  2935. }
  2936. }
  2937. }
  2938. void halbtc8821a2ant_action_pan_edr_hid(IN struct btc_coexist *btcoexist)
  2939. {
  2940. u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
  2941. u32 wifi_bw;
  2942. btcoexist->btc_phydm_modify_RA_PCR_threshold(btcoexist, 0, 25);
  2943. wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15,
  2944. 0);
  2945. wifi_rssi_state1 = halbtc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
  2946. BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
  2947. bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2,
  2948. BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
  2949. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  2950. halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
  2951. if (BTC_RSSI_HIGH(bt_rssi_state))
  2952. halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
  2953. else
  2954. halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2955. if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) {
  2956. halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
  2957. } else {
  2958. halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
  2959. 14);
  2960. }
  2961. if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2962. (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2963. if (BTC_WIFI_BW_HT40 == wifi_bw) {
  2964. halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC,
  2965. 3);
  2966. /* halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 11); */
  2967. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1,
  2968. 0xfffff, 0x780);
  2969. } else {
  2970. halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC,
  2971. 6);
  2972. /* halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); */
  2973. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1,
  2974. 0xfffff, 0x0);
  2975. }
  2976. halbtc8821a2ant_tdma_duration_adjust(btcoexist, true, false, 2);
  2977. } else {
  2978. halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  2979. /* halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 14); */
  2980. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff,
  2981. 0x0);
  2982. halbtc8821a2ant_tdma_duration_adjust(btcoexist, true, true, 2);
  2983. }
  2984. /* sw mechanism */
  2985. if (BTC_WIFI_BW_HT40 == wifi_bw) {
  2986. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2987. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2988. halbtc8821a2ant_sw_mechanism1(btcoexist, true, true,
  2989. false, false);
  2990. halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
  2991. false, 0x18);
  2992. } else {
  2993. halbtc8821a2ant_sw_mechanism1(btcoexist, true, true,
  2994. false, false);
  2995. halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
  2996. false, 0x18);
  2997. }
  2998. } else {
  2999. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  3000. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  3001. halbtc8821a2ant_sw_mechanism1(btcoexist, false, true,
  3002. false, false);
  3003. halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
  3004. false, 0x18);
  3005. } else {
  3006. halbtc8821a2ant_sw_mechanism1(btcoexist, false, true,
  3007. false, false);
  3008. halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
  3009. false, 0x18);
  3010. }
  3011. }
  3012. }
  3013. /* HID+A2DP+PAN(EDR) */
  3014. void halbtc8821a2ant_action_hid_a2dp_pan_edr(IN struct btc_coexist *btcoexist)
  3015. {
  3016. u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
  3017. u32 wifi_bw;
  3018. btcoexist->btc_phydm_modify_RA_PCR_threshold(btcoexist, 0, 25);
  3019. wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15,
  3020. 0);
  3021. wifi_rssi_state1 = halbtc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
  3022. BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
  3023. bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2,
  3024. BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);
  3025. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
  3026. halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
  3027. halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  3028. if (BTC_RSSI_HIGH(bt_rssi_state))
  3029. halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
  3030. else
  3031. halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  3032. if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) {
  3033. halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
  3034. } else {
  3035. halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
  3036. 14);
  3037. }
  3038. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  3039. if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
  3040. (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  3041. if (BTC_WIFI_BW_HT40 == wifi_bw)
  3042. halbtc8821a2ant_tdma_duration_adjust(btcoexist, true,
  3043. true, 3);
  3044. else
  3045. halbtc8821a2ant_tdma_duration_adjust(btcoexist, true,
  3046. false, 3);
  3047. } else
  3048. halbtc8821a2ant_tdma_duration_adjust(btcoexist, true, true, 3);
  3049. /* sw mechanism */
  3050. if (BTC_WIFI_BW_HT40 == wifi_bw) {
  3051. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  3052. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  3053. halbtc8821a2ant_sw_mechanism1(btcoexist, true, true,
  3054. false, false);
  3055. halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
  3056. false, 0x18);
  3057. } else {
  3058. halbtc8821a2ant_sw_mechanism1(btcoexist, true, true,
  3059. false, false);
  3060. halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
  3061. false, 0x18);
  3062. }
  3063. } else {
  3064. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  3065. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  3066. halbtc8821a2ant_sw_mechanism1(btcoexist, false, true,
  3067. false, false);
  3068. halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
  3069. false, 0x18);
  3070. } else {
  3071. halbtc8821a2ant_sw_mechanism1(btcoexist, false, true,
  3072. false, false);
  3073. halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
  3074. false, 0x18);
  3075. }
  3076. }
  3077. }
  3078. void halbtc8821a2ant_action_hid_a2dp(IN struct btc_coexist *btcoexist)
  3079. {
  3080. u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
  3081. u32 wifi_bw;
  3082. u8 ap_num = 0;
  3083. btcoexist->btc_phydm_modify_RA_PCR_threshold(btcoexist, 0, 25);
  3084. wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15,
  3085. 0);
  3086. /* bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, 29, 0); */
  3087. wifi_rssi_state1 = halbtc8821a2ant_wifi_rssi_state(btcoexist, 1, 2,
  3088. BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);
  3089. bt_rssi_state = halbtc8821a2ant_bt_rssi_state(3,
  3090. BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 37);
  3091. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
  3092. halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, true, 0x6);
  3093. halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  3094. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  3095. if (BTC_WIFI_BW_LEGACY == wifi_bw) {
  3096. if (BTC_RSSI_HIGH(bt_rssi_state))
  3097. halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
  3098. else if (BTC_RSSI_MEDIUM(bt_rssi_state))
  3099. halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
  3100. else
  3101. halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  3102. } else {
  3103. /* only 802.11N mode we have to dec bt power to 4 degree */
  3104. if (BTC_RSSI_HIGH(bt_rssi_state)) {
  3105. btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
  3106. &ap_num);
  3107. /* need to check ap Number of Not */
  3108. if (ap_num < 10)
  3109. halbtc8821a2ant_dec_bt_pwr(btcoexist,
  3110. NORMAL_EXEC, 4);
  3111. else
  3112. halbtc8821a2ant_dec_bt_pwr(btcoexist,
  3113. NORMAL_EXEC, 2);
  3114. } else if (BTC_RSSI_MEDIUM(bt_rssi_state))
  3115. halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
  3116. else
  3117. halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  3118. }
  3119. if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) {
  3120. halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
  3121. 18);
  3122. } else {
  3123. halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC,
  3124. 18);
  3125. }
  3126. if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
  3127. (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  3128. /* halbtc8821a2ant_tdma_duration_adjust(btcoexist, true, false, 3); */
  3129. halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 28);
  3130. } else {
  3131. /* halbtc8821a2ant_tdma_duration_adjust(btcoexist, true, true, 3); */
  3132. halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 28);
  3133. }
  3134. /* sw mechanism */
  3135. if (BTC_WIFI_BW_HT40 == wifi_bw) {
  3136. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  3137. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  3138. halbtc8821a2ant_sw_mechanism1(btcoexist, true, true,
  3139. false, false);
  3140. halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
  3141. false, 0x18);
  3142. } else {
  3143. halbtc8821a2ant_sw_mechanism1(btcoexist, true, true,
  3144. false, false);
  3145. halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
  3146. false, 0x18);
  3147. }
  3148. } else {
  3149. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  3150. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  3151. halbtc8821a2ant_sw_mechanism1(btcoexist, false, true,
  3152. false, false);
  3153. halbtc8821a2ant_sw_mechanism2(btcoexist, true, false,
  3154. false, 0x18);
  3155. } else {
  3156. halbtc8821a2ant_sw_mechanism1(btcoexist, false, true,
  3157. false, false);
  3158. halbtc8821a2ant_sw_mechanism2(btcoexist, false, false,
  3159. false, 0x18);
  3160. }
  3161. }
  3162. }
  3163. void halbtc8821a2ant_action_bt_whck_test(IN struct btc_coexist *btcoexist)
  3164. {
  3165. halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  3166. /* sw all off */
  3167. halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, false, false);
  3168. halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18);
  3169. halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
  3170. halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  3171. }
  3172. void halbtc8821a2ant_action_wifi_multi_port(IN struct btc_coexist *btcoexist)
  3173. {
  3174. halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  3175. halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  3176. /* sw all off */
  3177. halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, false, false);
  3178. halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18);
  3179. /* hw all off */
  3180. /* btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); */
  3181. halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  3182. halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
  3183. }
  3184. void halbtc8821a2ant_run_coexist_mechanism(IN struct btc_coexist *btcoexist)
  3185. {
  3186. boolean wifi_under_5g = false;
  3187. u8 algorithm = 0;
  3188. u32 num_of_wifi_link = 0;
  3189. u32 wifi_link_status = 0;
  3190. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  3191. boolean miracast_plus_bt = false;
  3192. boolean scan = false, link = false, roam = false;
  3193. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3194. "[BTCoex], RunCoexistMechanism()===>\n");
  3195. BTC_TRACE(trace_buf);
  3196. if (btcoexist->manual_control) {
  3197. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3198. "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
  3199. BTC_TRACE(trace_buf);
  3200. return;
  3201. }
  3202. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  3203. if (wifi_under_5g) {
  3204. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3205. "[BTCoex], RunCoexistMechanism(), run 5G coex setting!!<===\n");
  3206. BTC_TRACE(trace_buf);
  3207. halbtc8821a2ant_coex_under_5g(btcoexist);
  3208. return;
  3209. }
  3210. if (coex_sta->under_ips) {
  3211. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3212. "[BTCoex], wifi is under IPS !!!\n");
  3213. BTC_TRACE(trace_buf);
  3214. return;
  3215. }
  3216. if (coex_sta->bt_whck_test) {
  3217. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3218. "[BTCoex], BT is under WHCK TEST!!!\n");
  3219. BTC_TRACE(trace_buf);
  3220. halbtc8821a2ant_action_bt_whck_test(btcoexist);
  3221. return;
  3222. }
  3223. algorithm = halbtc8821a2ant_action_algorithm(btcoexist);
  3224. if (coex_sta->c2h_bt_inquiry_page &&
  3225. (BT_8821A_2ANT_COEX_ALGO_PANHS != algorithm)) {
  3226. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3227. "[BTCoex], BT is under inquiry/page scan !!\n");
  3228. BTC_TRACE(trace_buf);
  3229. halbtc8821a2ant_action_bt_inquiry(btcoexist);
  3230. return;
  3231. }
  3232. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
  3233. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
  3234. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
  3235. if (scan || link || roam) {
  3236. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3237. "[BTCoex], WiFi is under Link Process !!\n");
  3238. BTC_TRACE(trace_buf);
  3239. halbtc8821a2ant_action_wifi_link_process(btcoexist);
  3240. return;
  3241. }
  3242. /* for P2P */
  3243. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
  3244. &wifi_link_status);
  3245. num_of_wifi_link = wifi_link_status >> 16;
  3246. if ((num_of_wifi_link >= 2) ||
  3247. (wifi_link_status & WIFI_P2P_GO_CONNECTED)) {
  3248. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3249. "############# [BTCoex], Multi-Port num_of_wifi_link = %d, wifi_link_status = 0x%x\n",
  3250. num_of_wifi_link, wifi_link_status);
  3251. BTC_TRACE(trace_buf);
  3252. if (bt_link_info->bt_link_exist)
  3253. miracast_plus_bt = true;
  3254. else
  3255. miracast_plus_bt = false;
  3256. btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT,
  3257. &miracast_plus_bt);
  3258. halbtc8821a2ant_action_wifi_multi_port(btcoexist);
  3259. return;
  3260. }
  3261. miracast_plus_bt = false;
  3262. btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT,
  3263. &miracast_plus_bt);
  3264. coex_dm->cur_algorithm = algorithm;
  3265. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Algorithm = %d\n",
  3266. coex_dm->cur_algorithm);
  3267. BTC_TRACE(trace_buf);
  3268. if (halbtc8821a2ant_is_common_action(btcoexist)) {
  3269. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3270. "[BTCoex], Action 2-Ant common.\n");
  3271. BTC_TRACE(trace_buf);
  3272. coex_dm->auto_tdma_adjust = false;
  3273. } else {
  3274. if (coex_dm->cur_algorithm != coex_dm->pre_algorithm) {
  3275. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3276. "[BTCoex], pre_algorithm=%d, cur_algorithm=%d\n",
  3277. coex_dm->pre_algorithm, coex_dm->cur_algorithm);
  3278. BTC_TRACE(trace_buf);
  3279. coex_dm->auto_tdma_adjust = false;
  3280. }
  3281. switch (coex_dm->cur_algorithm) {
  3282. case BT_8821A_2ANT_COEX_ALGO_SCO:
  3283. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3284. "[BTCoex], Action 2-Ant, algorithm = SCO.\n");
  3285. BTC_TRACE(trace_buf);
  3286. halbtc8821a2ant_action_sco(btcoexist);
  3287. break;
  3288. case BT_8821A_2ANT_COEX_ALGO_HID:
  3289. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3290. "[BTCoex], Action 2-Ant, algorithm = HID.\n");
  3291. BTC_TRACE(trace_buf);
  3292. halbtc8821a2ant_action_hid(btcoexist);
  3293. break;
  3294. case BT_8821A_2ANT_COEX_ALGO_A2DP:
  3295. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3296. "[BTCoex], Action 2-Ant, algorithm = A2DP.\n");
  3297. BTC_TRACE(trace_buf);
  3298. halbtc8821a2ant_action_a2dp(btcoexist);
  3299. break;
  3300. case BT_8821A_2ANT_COEX_ALGO_A2DP_PANHS:
  3301. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3302. "[BTCoex], Action 2-Ant, algorithm = A2DP+PAN(HS).\n");
  3303. BTC_TRACE(trace_buf);
  3304. halbtc8821a2ant_action_a2dp_pan_hs(btcoexist);
  3305. break;
  3306. case BT_8821A_2ANT_COEX_ALGO_PANEDR:
  3307. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3308. "[BTCoex], Action 2-Ant, algorithm = PAN(EDR).\n");
  3309. BTC_TRACE(trace_buf);
  3310. halbtc8821a2ant_action_pan_edr(btcoexist);
  3311. break;
  3312. case BT_8821A_2ANT_COEX_ALGO_PANHS:
  3313. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3314. "[BTCoex], Action 2-Ant, algorithm = HS mode.\n");
  3315. BTC_TRACE(trace_buf);
  3316. halbtc8821a2ant_action_pan_hs(btcoexist);
  3317. break;
  3318. case BT_8821A_2ANT_COEX_ALGO_PANEDR_A2DP:
  3319. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3320. "[BTCoex], Action 2-Ant, algorithm = PAN+A2DP.\n");
  3321. BTC_TRACE(trace_buf);
  3322. halbtc8821a2ant_action_pan_edr_a2dp(btcoexist);
  3323. break;
  3324. case BT_8821A_2ANT_COEX_ALGO_PANEDR_HID:
  3325. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3326. "[BTCoex], Action 2-Ant, algorithm = PAN(EDR)+HID.\n");
  3327. BTC_TRACE(trace_buf);
  3328. halbtc8821a2ant_action_pan_edr_hid(btcoexist);
  3329. break;
  3330. case BT_8821A_2ANT_COEX_ALGO_HID_A2DP_PANEDR:
  3331. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3332. "[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN.\n");
  3333. BTC_TRACE(trace_buf);
  3334. halbtc8821a2ant_action_hid_a2dp_pan_edr(
  3335. btcoexist);
  3336. break;
  3337. case BT_8821A_2ANT_COEX_ALGO_HID_A2DP:
  3338. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3339. "[BTCoex], Action 2-Ant, algorithm = HID+A2DP.\n");
  3340. BTC_TRACE(trace_buf);
  3341. halbtc8821a2ant_action_hid_a2dp(btcoexist);
  3342. break;
  3343. default:
  3344. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3345. "[BTCoex], Action 2-Ant, algorithm = coexist All Off!!\n");
  3346. BTC_TRACE(trace_buf);
  3347. halbtc8821a2ant_coex_all_off(btcoexist);
  3348. break;
  3349. }
  3350. coex_dm->pre_algorithm = coex_dm->cur_algorithm;
  3351. }
  3352. }
  3353. void halbtc8821a2ant_wifi_off_hw_cfg(IN struct btc_coexist *btcoexist)
  3354. {
  3355. u8 h2c_parameter[2] = {0};
  3356. u32 fw_ver = 0;
  3357. /* set wlan_act to low */
  3358. btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4);
  3359. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff,
  3360. 0x780); /* WiFi goto standby while GNT_BT 0-->1 */
  3361. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
  3362. if (fw_ver >= 0x180000) {
  3363. /* Use H2C to set GNT_BT to HIGH */
  3364. h2c_parameter[0] = 1;
  3365. btcoexist->btc_fill_h2c(btcoexist, 0x6E, 1, h2c_parameter);
  3366. } else
  3367. btcoexist->btc_write_1byte(btcoexist, 0x765, 0x18);
  3368. }
  3369. void halbtc8821a2ant_init_coex_dm(IN struct btc_coexist *btcoexist)
  3370. {
  3371. /* force to reset coex mechanism */
  3372. halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  3373. halbtc8821a2ant_ps_tdma(btcoexist, FORCE_EXEC, false, 1);
  3374. halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 6);
  3375. halbtc8821a2ant_dec_bt_pwr(btcoexist, FORCE_EXEC, 0);
  3376. halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, false, false);
  3377. halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18);
  3378. }
  3379. void halbtc8821a2ant_init_hw_config(IN struct btc_coexist *btcoexist,
  3380. IN boolean back_up)
  3381. {
  3382. u8 u8tmp = 0;
  3383. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3384. "[BTCoex], 2Ant Init HW Config!!\n");
  3385. BTC_TRACE(trace_buf);
  3386. /* Give bt_coex_supported_version the default value */
  3387. coex_sta->bt_coex_supported_version = 0;
  3388. /* 0xf0[15:12] --> Chip Cut information */
  3389. coex_sta->cut_version = (btcoexist->btc_read_1byte(btcoexist,
  3390. 0xf1) & 0xf0) >> 4;
  3391. /* backup rf 0x1e value */
  3392. coex_dm->bt_rf_0x1e_backup =
  3393. btcoexist->btc_get_rf_reg(btcoexist, BTC_RF_A, 0x1e, 0xfffff);
  3394. /* 0x790[5:0]=0x5 */
  3395. u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x790);
  3396. u8tmp &= 0xc0;
  3397. u8tmp |= 0x5;
  3398. btcoexist->btc_write_1byte(btcoexist, 0x790, u8tmp);
  3399. /* Antenna config */
  3400. halbtc8821a2ant_set_ant_path(btcoexist, BTC_ANT_WIFI_AT_MAIN, true,
  3401. false);
  3402. coex_sta->dis_ver_info_cnt = 0;
  3403. /* PTA parameter */
  3404. halbtc8821a2ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
  3405. /* Enable counter statistics */
  3406. btcoexist->btc_write_1byte(btcoexist, 0x76e,
  3407. 0x4); /* 0x76e[3] =1, WLAN_Act control by PTA */
  3408. btcoexist->btc_write_1byte(btcoexist, 0x778, 0x3);
  3409. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1);
  3410. }
  3411. /* ************************************************************
  3412. * work around function start with wa_halbtc8821a2ant_
  3413. * ************************************************************
  3414. * ************************************************************
  3415. * extern function start with ex_halbtc8821a2ant_
  3416. * ************************************************************ */
  3417. void ex_halbtc8821a2ant_power_on_setting(IN struct btc_coexist *btcoexist)
  3418. {
  3419. }
  3420. void ex_halbtc8821a2ant_pre_load_firmware(IN struct btc_coexist *btcoexist)
  3421. {
  3422. struct btc_board_info *board_info = &btcoexist->board_info;
  3423. u8 u8tmp = 0x4; /* Set BIT2 by default since it's 2ant case */
  3424. /* */
  3425. /* S0 or S1 setting and Local register setting(By the setting fw can get ant number, S0/S1, ... info) */
  3426. /* Local setting bit define */
  3427. /* BIT0: "0" for no antenna inverse; "1" for antenna inverse */
  3428. /* BIT1: "0" for internal switch; "1" for external switch */
  3429. /* BIT2: "0" for one antenna; "1" for two antenna */
  3430. /* NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and BIT2=0 */
  3431. if (btcoexist->chip_interface == BTC_INTF_USB) {
  3432. /* fixed at S0 for USB interface */
  3433. u8tmp |= 0x1; /* antenna inverse */
  3434. btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp);
  3435. } else {
  3436. /* for PCIE and SDIO interface, we check efuse 0xc3[6] */
  3437. if (board_info->single_ant_path == 0) {
  3438. } else if (board_info->single_ant_path == 1) {
  3439. /* set to S0 */
  3440. u8tmp |= 0x1; /* antenna inverse */
  3441. }
  3442. if (btcoexist->chip_interface == BTC_INTF_PCI)
  3443. btcoexist->btc_write_local_reg_1byte(btcoexist, 0x384,
  3444. u8tmp);
  3445. else if (btcoexist->chip_interface == BTC_INTF_SDIO)
  3446. btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60,
  3447. u8tmp);
  3448. }
  3449. }
  3450. void ex_halbtc8821a2ant_init_hw_config(IN struct btc_coexist *btcoexist,
  3451. IN boolean wifi_only)
  3452. {
  3453. halbtc8821a2ant_init_hw_config(btcoexist, true);
  3454. }
  3455. void ex_halbtc8821a2ant_init_coex_dm(IN struct btc_coexist *btcoexist)
  3456. {
  3457. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3458. "[BTCoex], Coex Mechanism Init!!\n");
  3459. BTC_TRACE(trace_buf);
  3460. halbtc8821a2ant_init_coex_dm(btcoexist);
  3461. }
  3462. void ex_halbtc8821a2ant_display_coex_info(IN struct btc_coexist *btcoexist)
  3463. {
  3464. struct btc_board_info *board_info = &btcoexist->board_info;
  3465. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  3466. u8 *cli_buf = btcoexist->cli_buf;
  3467. u8 u8tmp[4], i, bt_info_ext, ps_tdma_case = 0;
  3468. u32 u32tmp[4];
  3469. u32 fw_ver = 0, bt_patch_ver = 0;
  3470. u32 bt_coex_ver = 0;
  3471. u32 phyver = 0;
  3472. u32 fa_ofdm, fa_cck, cca_ofdm, cca_cck;
  3473. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3474. "\r\n ============[BT Coexist info]============");
  3475. CL_PRINTF(cli_buf);
  3476. if (btcoexist->manual_control) {
  3477. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3478. "\r\n ============[Under Manual Control]============");
  3479. CL_PRINTF(cli_buf);
  3480. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3481. "\r\n ==========================================");
  3482. CL_PRINTF(cli_buf);
  3483. }
  3484. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ",
  3485. "Ant PG number/ Ant mechanism:",
  3486. board_info->pg_ant_num, board_info->btdm_ant_num);
  3487. CL_PRINTF(cli_buf);
  3488. /* btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver); */
  3489. bt_patch_ver = btcoexist->bt_info.bt_get_fw_ver;
  3490. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
  3491. phyver = btcoexist->btc_get_bt_phydm_version(btcoexist);
  3492. bt_coex_ver = coex_sta->bt_coex_supported_version & 0xff;
  3493. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3494. "\r\n %-35s = %d_%02x/ 0x%02x/ 0x%02x (%s)",
  3495. "CoexVer WL/ BT_Desired/ BT_Report",
  3496. glcoex_ver_date_8821a_2ant, glcoex_ver_8821a_2ant,
  3497. glcoex_ver_btdesired_8821a_2ant,
  3498. bt_coex_ver,
  3499. (bt_coex_ver == 0xff ? "Unknown" :
  3500. (bt_coex_ver >= glcoex_ver_btdesired_8821a_2ant ?
  3501. "Match" : "Mis-Match")));
  3502. CL_PRINTF(cli_buf);
  3503. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3504. "\r\n %-35s = 0x%x/ 0x%x/ v%d/ %c",
  3505. "W_FW/ B_FW/ Phy/ Kt",
  3506. fw_ver, bt_patch_ver, phyver,
  3507. coex_sta->cut_version + 65);
  3508. CL_PRINTF(cli_buf);
  3509. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ",
  3510. "Wifi channel informed to BT",
  3511. coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1],
  3512. coex_dm->wifi_chnl_info[2]);
  3513. CL_PRINTF(cli_buf);
  3514. /* wifi status */
  3515. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  3516. "============[Wifi Status]============");
  3517. CL_PRINTF(cli_buf);
  3518. btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS);
  3519. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  3520. "============[BT Status]============");
  3521. CL_PRINTF(cli_buf);
  3522. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %ddBm/ %d] ",
  3523. "BT [status/ rssi/ retryCnt]",
  3524. ((coex_sta->bt_disabled) ? ("disabled") : ((
  3525. coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan")
  3526. : ((BT_8821A_2ANT_BT_STATUS_NON_CONNECTED_IDLE ==
  3527. coex_dm->bt_status) ? "non-connected idle" :
  3528. ((BT_8821A_2ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)
  3529. ? "connected-idle" : "busy")))),
  3530. coex_sta->bt_rssi - 100, coex_sta->bt_retry_cnt);
  3531. CL_PRINTF(cli_buf);
  3532. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d",
  3533. "SCO/HID/PAN/A2DP",
  3534. bt_link_info->sco_exist, bt_link_info->hid_exist,
  3535. bt_link_info->pan_exist, bt_link_info->a2dp_exist);
  3536. CL_PRINTF(cli_buf);
  3537. {
  3538. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s",
  3539. "BT Role",
  3540. (bt_link_info->slave_role) ? "Slave" : "Master");
  3541. CL_PRINTF(cli_buf);
  3542. }
  3543. bt_info_ext = coex_sta->bt_info_ext;
  3544. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s",
  3545. "BT Info A2DP rate",
  3546. (bt_info_ext & BIT(0)) ? "Basic rate" : "EDR rate");
  3547. CL_PRINTF(cli_buf);
  3548. for (i = 0; i < BT_INFO_SRC_8821A_2ANT_MAX; i++) {
  3549. if (coex_sta->bt_info_c2h_cnt[i]) {
  3550. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3551. "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)",
  3552. glbt_info_src_8821a_2ant[i],
  3553. coex_sta->bt_info_c2h[i][0],
  3554. coex_sta->bt_info_c2h[i][1],
  3555. coex_sta->bt_info_c2h[i][2],
  3556. coex_sta->bt_info_c2h[i][3],
  3557. coex_sta->bt_info_c2h[i][4],
  3558. coex_sta->bt_info_c2h[i][5],
  3559. coex_sta->bt_info_c2h[i][6],
  3560. coex_sta->bt_info_c2h_cnt[i]);
  3561. CL_PRINTF(cli_buf);
  3562. }
  3563. }
  3564. /* Sw mechanism */
  3565. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  3566. "============[Sw mechanism]============");
  3567. CL_PRINTF(cli_buf);
  3568. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d ",
  3569. "SM1[ShRf/ LpRA/ LimDig]",
  3570. coex_dm->cur_rf_rx_lpf_shrink, coex_dm->cur_low_penalty_ra,
  3571. coex_dm->limited_dig);
  3572. CL_PRINTF(cli_buf);
  3573. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d(0x%x) ",
  3574. "SM2[AgcT/ AdcB/ SwDacSwing(lvl)]",
  3575. coex_dm->cur_agc_table_en, coex_dm->cur_adc_back_off,
  3576. coex_dm->cur_dac_swing_on, coex_dm->cur_dac_swing_lvl);
  3577. CL_PRINTF(cli_buf);
  3578. /* Fw mechanism */
  3579. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  3580. "============[Fw mechanism]============");
  3581. CL_PRINTF(cli_buf);
  3582. ps_tdma_case = coex_dm->cur_ps_tdma;
  3583. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3584. "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (auto:%d)",
  3585. "PS TDMA",
  3586. coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1],
  3587. coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3],
  3588. coex_dm->ps_tdma_para[4], ps_tdma_case,
  3589. coex_dm->auto_tdma_adjust);
  3590. CL_PRINTF(cli_buf);
  3591. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d",
  3592. "Coex Table Type",
  3593. coex_sta->coex_table_type);
  3594. CL_PRINTF(cli_buf);
  3595. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ",
  3596. "DecBtPwr/ IgnWlanAct",
  3597. coex_dm->cur_bt_dec_pwr_lvl, coex_dm->cur_ignore_wlan_act);
  3598. CL_PRINTF(cli_buf);
  3599. /* Hw setting */
  3600. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  3601. "============[Hw setting]============");
  3602. CL_PRINTF(cli_buf);
  3603. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x",
  3604. "RF-A, 0x1e initVal",
  3605. coex_dm->bt_rf_0x1e_backup);
  3606. CL_PRINTF(cli_buf);
  3607. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
  3608. u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xc5b);
  3609. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x880);
  3610. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
  3611. "0x778/0x880[29:25]/0xc58[29:25]",
  3612. u8tmp[0], (u32tmp[0] & 0x3e000000) >> 25,
  3613. ((u8tmp[1] & 0x3e) >> 1));
  3614. CL_PRINTF(cli_buf);
  3615. u32tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x764);
  3616. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x76e);
  3617. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
  3618. "0x764/ 0x765/ 0x76e",
  3619. (u32tmp[0] & 0xff), (u32tmp[0] & 0xff00) >> 8, u8tmp[0]);
  3620. CL_PRINTF(cli_buf);
  3621. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
  3622. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
  3623. "0xcb4[7:0](ctrl)/ 0xcb4[29:28](val)",
  3624. u32tmp[0] & 0xff, ((u32tmp[0] & 0x30000000) >> 28));
  3625. CL_PRINTF(cli_buf);
  3626. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x40);
  3627. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c);
  3628. u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x974);
  3629. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
  3630. "0x40/ 0x4c[24:23]/ 0x974",
  3631. u8tmp[0], ((u32tmp[0] & 0x01800000) >> 23), u32tmp[1]);
  3632. CL_PRINTF(cli_buf);
  3633. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
  3634. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
  3635. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
  3636. "0x550(bcn ctrl)/0x522",
  3637. u32tmp[0], u8tmp[0]);
  3638. CL_PRINTF(cli_buf);
  3639. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50);
  3640. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x49c);
  3641. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
  3642. "0xc50(dig)/0x49c(null-drop)",
  3643. u32tmp[0] & 0xff, u8tmp[0]);
  3644. CL_PRINTF(cli_buf);
  3645. fa_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
  3646. PHYDM_INFO_FA_OFDM);
  3647. fa_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
  3648. PHYDM_INFO_FA_CCK);
  3649. cca_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
  3650. PHYDM_INFO_CCA_OFDM);
  3651. cca_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
  3652. PHYDM_INFO_CCA_CCK);
  3653. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3654. "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
  3655. "CCK-CCA/CCK-FA/OFDM-CCA/OFDM-FA",
  3656. cca_cck, fa_cck, cca_ofdm, fa_ofdm);
  3657. CL_PRINTF(cli_buf);
  3658. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
  3659. "CRC_OK CCK/11g/11n/11n-agg",
  3660. coex_sta->crc_ok_cck, coex_sta->crc_ok_11g,
  3661. coex_sta->crc_ok_11n, coex_sta->crc_ok_11n_vht);
  3662. CL_PRINTF(cli_buf);
  3663. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
  3664. "CRC_Err CCK/11g/11n/11n-agg",
  3665. coex_sta->crc_err_cck, coex_sta->crc_err_11g,
  3666. coex_sta->crc_err_11n, coex_sta->crc_err_11n_vht);
  3667. CL_PRINTF(cli_buf);
  3668. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
  3669. u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
  3670. u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
  3671. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x6cc);
  3672. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3673. "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
  3674. "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)",
  3675. u32tmp[0], u32tmp[1], u32tmp[2], u8tmp[0]);
  3676. CL_PRINTF(cli_buf);
  3677. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
  3678. "0x770(high-pri rx/tx)",
  3679. coex_sta->high_priority_rx, coex_sta->high_priority_tx);
  3680. CL_PRINTF(cli_buf);
  3681. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
  3682. "0x774(low-pri rx/tx)",
  3683. coex_sta->low_priority_rx, coex_sta->low_priority_tx);
  3684. CL_PRINTF(cli_buf);
  3685. #if (BT_AUTO_REPORT_ONLY_8821A_2ANT == 1)
  3686. /* halbtc8821a2ant_monitor_bt_ctr(btcoexist); */
  3687. #endif
  3688. btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS);
  3689. }
  3690. void ex_halbtc8821a2ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type)
  3691. {
  3692. if (BTC_IPS_ENTER == type) {
  3693. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3694. "[BTCoex], IPS ENTER notify\n");
  3695. BTC_TRACE(trace_buf);
  3696. coex_sta->under_ips = true;
  3697. halbtc8821a2ant_wifi_off_hw_cfg(btcoexist);
  3698. halbtc8821a2ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
  3699. halbtc8821a2ant_coex_all_off(btcoexist);
  3700. } else if (BTC_IPS_LEAVE == type) {
  3701. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3702. "[BTCoex], IPS LEAVE notify\n");
  3703. BTC_TRACE(trace_buf);
  3704. coex_sta->under_ips = false;
  3705. halbtc8821a2ant_init_hw_config(btcoexist, false);
  3706. halbtc8821a2ant_init_coex_dm(btcoexist);
  3707. halbtc8821a2ant_query_bt_info(btcoexist);
  3708. }
  3709. }
  3710. void ex_halbtc8821a2ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type)
  3711. {
  3712. if (BTC_LPS_ENABLE == type) {
  3713. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3714. "[BTCoex], LPS ENABLE notify\n");
  3715. BTC_TRACE(trace_buf);
  3716. coex_sta->under_lps = true;
  3717. } else if (BTC_LPS_DISABLE == type) {
  3718. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3719. "[BTCoex], LPS DISABLE notify\n");
  3720. BTC_TRACE(trace_buf);
  3721. coex_sta->under_lps = false;
  3722. }
  3723. }
  3724. void ex_halbtc8821a2ant_scan_notify(IN struct btc_coexist *btcoexist,
  3725. IN u8 type)
  3726. {
  3727. u8 u8tmpa, u8tmpb;
  3728. u8tmpa = btcoexist->btc_read_1byte(btcoexist, 0x765);
  3729. u8tmpb = btcoexist->btc_read_1byte(btcoexist, 0x76e);
  3730. if (BTC_SCAN_START == type) {
  3731. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3732. "[BTCoex], SCAN START notify\n");
  3733. BTC_TRACE(trace_buf);
  3734. } else if (BTC_SCAN_FINISH == type) {
  3735. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3736. "[BTCoex], SCAN FINISH notify\n");
  3737. BTC_TRACE(trace_buf);
  3738. }
  3739. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3740. "############# [BTCoex], 0x765=0x%x, 0x76e=0x%x\n", u8tmpa,
  3741. u8tmpb);
  3742. BTC_TRACE(trace_buf);
  3743. }
  3744. /* copy scan notify content to switch band notify */
  3745. void ex_halbtc8821a2ant_switchband_notify(IN struct btc_coexist *btcoexist,
  3746. IN u8 type)
  3747. {
  3748. u8 u8tmpa, u8tmpb;
  3749. u8tmpa = btcoexist->btc_read_1byte(btcoexist, 0x765);
  3750. u8tmpb = btcoexist->btc_read_1byte(btcoexist, 0x76e);
  3751. if (BTC_SCAN_START == type) {
  3752. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3753. "[BTCoex], SCAN START notify\n");
  3754. BTC_TRACE(trace_buf);
  3755. } else if (BTC_SCAN_FINISH == type) {
  3756. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3757. "[BTCoex], SCAN FINISH notify\n");
  3758. BTC_TRACE(trace_buf);
  3759. }
  3760. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3761. "############# [BTCoex], 0x765=0x%x, 0x76e=0x%x\n", u8tmpa,
  3762. u8tmpb);
  3763. BTC_TRACE(trace_buf);
  3764. }
  3765. void ex_halbtc8821a2ant_connect_notify(IN struct btc_coexist *btcoexist,
  3766. IN u8 type)
  3767. {
  3768. if (BTC_ASSOCIATE_START == type) {
  3769. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3770. "[BTCoex], CONNECT START notify\n");
  3771. BTC_TRACE(trace_buf);
  3772. } else if (BTC_ASSOCIATE_FINISH == type) {
  3773. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3774. "[BTCoex], CONNECT FINISH notify\n");
  3775. BTC_TRACE(trace_buf);
  3776. }
  3777. }
  3778. void ex_halbtc8821a2ant_media_status_notify(IN struct btc_coexist *btcoexist,
  3779. IN u8 type)
  3780. {
  3781. u8 h2c_parameter[3] = {0};
  3782. u32 wifi_bw;
  3783. u8 wifi_central_chnl;
  3784. u8 ap_num = 0;
  3785. if (BTC_MEDIA_CONNECT == type) {
  3786. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3787. "[BTCoex], MEDIA connect notify\n");
  3788. BTC_TRACE(trace_buf);
  3789. } else {
  3790. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3791. "[BTCoex], MEDIA disconnect notify\n");
  3792. BTC_TRACE(trace_buf);
  3793. }
  3794. /* only 2.4G we need to inform bt the chnl mask */
  3795. btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL,
  3796. &wifi_central_chnl);
  3797. if ((BTC_MEDIA_CONNECT == type) &&
  3798. (wifi_central_chnl <= 14)) {
  3799. h2c_parameter[0] = 0x1;
  3800. h2c_parameter[1] = wifi_central_chnl;
  3801. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  3802. if (BTC_WIFI_BW_HT40 == wifi_bw)
  3803. h2c_parameter[2] = 0x30;
  3804. else {
  3805. btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
  3806. &ap_num);
  3807. if (ap_num < 10)
  3808. h2c_parameter[2] = 0x30;
  3809. else
  3810. h2c_parameter[2] = 0x20;
  3811. }
  3812. }
  3813. coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
  3814. coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
  3815. coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
  3816. btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter);
  3817. }
  3818. void ex_halbtc8821a2ant_specific_packet_notify(IN struct btc_coexist *btcoexist,
  3819. IN u8 type)
  3820. {
  3821. if (type == BTC_PACKET_DHCP) {
  3822. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3823. "[BTCoex], DHCP Packet notify\n");
  3824. BTC_TRACE(trace_buf);
  3825. }
  3826. }
  3827. void ex_halbtc8821a2ant_bt_info_notify(IN struct btc_coexist *btcoexist,
  3828. IN u8 *tmp_buf, IN u8 length)
  3829. {
  3830. u8 bt_info = 0;
  3831. u8 i, rsp_source = 0;
  3832. boolean bt_busy = false, limited_dig = false;
  3833. boolean wifi_connected = false, wifi_under_5g = false;
  3834. coex_sta->c2h_bt_info_req_sent = false;
  3835. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  3836. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  3837. &wifi_connected);
  3838. rsp_source = tmp_buf[0] & 0xf;
  3839. if (rsp_source >= BT_INFO_SRC_8821A_2ANT_MAX)
  3840. rsp_source = BT_INFO_SRC_8821A_2ANT_WIFI_FW;
  3841. coex_sta->bt_info_c2h_cnt[rsp_source]++;
  3842. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3843. "[BTCoex], Bt info[%d], length=%d, hex data=[", rsp_source,
  3844. length);
  3845. BTC_TRACE(trace_buf);
  3846. for (i = 0; i < length; i++) {
  3847. coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i];
  3848. if (i == 1)
  3849. bt_info = tmp_buf[i];
  3850. if (i == length - 1) {
  3851. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n",
  3852. tmp_buf[i]);
  3853. BTC_TRACE(trace_buf);
  3854. } else {
  3855. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ",
  3856. tmp_buf[i]);
  3857. BTC_TRACE(trace_buf);
  3858. }
  3859. }
  3860. if (btcoexist->manual_control) {
  3861. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3862. "[BTCoex], BtInfoNotify(), return for Manual CTRL<===\n");
  3863. BTC_TRACE(trace_buf);
  3864. return;
  3865. }
  3866. /* if 0xff, it means BT is under WHCK test */
  3867. if (bt_info == 0xff)
  3868. coex_sta->bt_whck_test = true;
  3869. else
  3870. coex_sta->bt_whck_test = false;
  3871. if (BT_INFO_SRC_8821A_2ANT_WIFI_FW != rsp_source) {
  3872. coex_sta->bt_retry_cnt = /* [3:0] */
  3873. coex_sta->bt_info_c2h[rsp_source][2] & 0xf;
  3874. coex_sta->bt_rssi =
  3875. coex_sta->bt_info_c2h[rsp_source][3] * 2 + 10;
  3876. coex_sta->bt_info_ext =
  3877. coex_sta->bt_info_c2h[rsp_source][4];
  3878. coex_sta->bt_tx_rx_mask = (coex_sta->bt_info_c2h[rsp_source][2]
  3879. & 0x40);
  3880. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TX_RX_MASK,
  3881. &coex_sta->bt_tx_rx_mask);
  3882. if (coex_sta->bt_tx_rx_mask) {
  3883. /* BT into is responded by BT FW and BT RF REG 0x3C != 0x01 => Need to switch BT TRx Mask */
  3884. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3885. "[BTCoex], Switch BT TRx Mask since BT RF REG 0x3C != 0x01\n");
  3886. BTC_TRACE(trace_buf);
  3887. btcoexist->btc_set_bt_reg(btcoexist, BTC_BT_REG_RF,
  3888. 0x3c, 0x01);
  3889. }
  3890. /* Here we need to resend some wifi info to BT */
  3891. /* because bt is reset and loss of the info. */
  3892. if ((coex_sta->bt_info_ext & BIT(1))) {
  3893. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3894. "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
  3895. BTC_TRACE(trace_buf);
  3896. if (wifi_connected)
  3897. ex_halbtc8821a2ant_media_status_notify(
  3898. btcoexist, BTC_MEDIA_CONNECT);
  3899. else
  3900. ex_halbtc8821a2ant_media_status_notify(
  3901. btcoexist, BTC_MEDIA_DISCONNECT);
  3902. }
  3903. if (!btcoexist->manual_control && !wifi_under_5g) {
  3904. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3905. "[BTCoex], BT ext info = 0x%x!!\n",
  3906. coex_sta->bt_info_ext);
  3907. BTC_TRACE(trace_buf);
  3908. if ((coex_sta->bt_info_ext & BIT(3))) {
  3909. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3910. "[BTCoex], BT ext info bit3=1, wifi_connected=%d\n",
  3911. wifi_connected);
  3912. BTC_TRACE(trace_buf);
  3913. if (wifi_connected) {
  3914. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3915. "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n");
  3916. BTC_TRACE(trace_buf);
  3917. halbtc8821a2ant_ignore_wlan_act(
  3918. btcoexist, FORCE_EXEC, false);
  3919. }
  3920. } else {
  3921. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3922. "[BTCoex], BT ext info bit3=0, wifi_connected=%d\n",
  3923. wifi_connected);
  3924. BTC_TRACE(trace_buf);
  3925. /* BT already NOT ignore Wlan active, do nothing here. */
  3926. if (!wifi_connected) {
  3927. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3928. "[BTCoex], BT ext info bit3 check, set BT to ignore Wlan active!!\n");
  3929. BTC_TRACE(trace_buf);
  3930. halbtc8821a2ant_ignore_wlan_act(
  3931. btcoexist, FORCE_EXEC, true);
  3932. }
  3933. }
  3934. }
  3935. #if (BT_AUTO_REPORT_ONLY_8821A_2ANT == 0)
  3936. if ((coex_sta->bt_info_ext & BIT(4))) {
  3937. /* BT auto report already enabled, do nothing */
  3938. } else
  3939. halbtc8821a2ant_bt_auto_report(btcoexist, FORCE_EXEC,
  3940. true);
  3941. #endif
  3942. }
  3943. /* check BIT2 first ==> check if bt is under inquiry or page scan */
  3944. if (bt_info & BT_INFO_8821A_2ANT_B_INQ_PAGE)
  3945. coex_sta->c2h_bt_inquiry_page = true;
  3946. else
  3947. coex_sta->c2h_bt_inquiry_page = false;
  3948. /* set link exist status */
  3949. if (!(bt_info & BT_INFO_8821A_2ANT_B_CONNECTION)) {
  3950. coex_sta->bt_link_exist = false;
  3951. coex_sta->pan_exist = false;
  3952. coex_sta->a2dp_exist = false;
  3953. coex_sta->hid_exist = false;
  3954. coex_sta->sco_exist = false;
  3955. } else { /* connection exists */
  3956. coex_sta->bt_link_exist = true;
  3957. if (bt_info & BT_INFO_8821A_2ANT_B_FTP)
  3958. coex_sta->pan_exist = true;
  3959. else
  3960. coex_sta->pan_exist = false;
  3961. if (bt_info & BT_INFO_8821A_2ANT_B_A2DP)
  3962. coex_sta->a2dp_exist = true;
  3963. else
  3964. coex_sta->a2dp_exist = false;
  3965. if (bt_info & BT_INFO_8821A_2ANT_B_HID)
  3966. coex_sta->hid_exist = true;
  3967. else
  3968. coex_sta->hid_exist = false;
  3969. if (bt_info & BT_INFO_8821A_2ANT_B_SCO_ESCO)
  3970. coex_sta->sco_exist = true;
  3971. else
  3972. coex_sta->sco_exist = false;
  3973. if ((coex_sta->hid_exist == false) &&
  3974. (coex_sta->c2h_bt_inquiry_page == false) &&
  3975. (coex_sta->sco_exist == false)) {
  3976. if (coex_sta->high_priority_tx +
  3977. coex_sta->high_priority_rx >= 160)
  3978. coex_sta->hid_exist = true;
  3979. }
  3980. }
  3981. halbtc8821a2ant_update_bt_link_info(btcoexist);
  3982. if (!(bt_info & BT_INFO_8821A_2ANT_B_CONNECTION)) {
  3983. coex_dm->bt_status = BT_8821A_2ANT_BT_STATUS_NON_CONNECTED_IDLE;
  3984. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3985. "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n");
  3986. BTC_TRACE(trace_buf);
  3987. } else if (bt_info ==
  3988. BT_INFO_8821A_2ANT_B_CONNECTION) { /* connection exists but no busy */
  3989. coex_dm->bt_status = BT_8821A_2ANT_BT_STATUS_CONNECTED_IDLE;
  3990. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3991. "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
  3992. BTC_TRACE(trace_buf);
  3993. } else if ((bt_info & BT_INFO_8821A_2ANT_B_SCO_ESCO) ||
  3994. (bt_info & BT_INFO_8821A_2ANT_B_SCO_BUSY)) {
  3995. coex_dm->bt_status = BT_8821A_2ANT_BT_STATUS_SCO_BUSY;
  3996. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3997. "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
  3998. BTC_TRACE(trace_buf);
  3999. } else if (bt_info & BT_INFO_8821A_2ANT_B_ACL_BUSY) {
  4000. coex_dm->bt_status = BT_8821A_2ANT_BT_STATUS_ACL_BUSY;
  4001. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4002. "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
  4003. BTC_TRACE(trace_buf);
  4004. } else {
  4005. coex_dm->bt_status = BT_8821A_2ANT_BT_STATUS_MAX;
  4006. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4007. "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n");
  4008. BTC_TRACE(trace_buf);
  4009. }
  4010. if ((BT_8821A_2ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
  4011. (BT_8821A_2ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
  4012. (BT_8821A_2ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) {
  4013. bt_busy = true;
  4014. limited_dig = true;
  4015. } else {
  4016. bt_busy = false;
  4017. limited_dig = false;
  4018. }
  4019. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
  4020. coex_dm->limited_dig = limited_dig;
  4021. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_LIMITED_DIG, &limited_dig);
  4022. halbtc8821a2ant_run_coexist_mechanism(btcoexist);
  4023. }
  4024. void ex_halbtc8821a2ant_halt_notify(IN struct btc_coexist *btcoexist)
  4025. {
  4026. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n");
  4027. BTC_TRACE(trace_buf);
  4028. halbtc8821a2ant_wifi_off_hw_cfg(btcoexist);
  4029. /* remove due to interrupt is disabled that polling c2h will fail and delay 100ms. */
  4030. /* btcoexist->btc_set_bt_reg(btcoexist, BTC_BT_REG_RF, 0x3c, 0x15); */ /*BT goto standby while GNT_BT 1-->0 */
  4031. halbtc8821a2ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
  4032. ex_halbtc8821a2ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT);
  4033. }
  4034. void ex_halbtc8821a2ant_pnp_notify(IN struct btc_coexist *btcoexist,
  4035. IN u8 pnp_state)
  4036. {
  4037. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Pnp notify\n");
  4038. BTC_TRACE(trace_buf);
  4039. if (BTC_WIFI_PNP_SLEEP == pnp_state) {
  4040. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4041. "[BTCoex], Pnp notify to SLEEP\n");
  4042. BTC_TRACE(trace_buf);
  4043. } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) {
  4044. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4045. "[BTCoex], Pnp notify to WAKE UP\n");
  4046. BTC_TRACE(trace_buf);
  4047. halbtc8821a2ant_init_hw_config(btcoexist, false);
  4048. halbtc8821a2ant_init_coex_dm(btcoexist);
  4049. halbtc8821a2ant_query_bt_info(btcoexist);
  4050. }
  4051. }
  4052. void ex_halbtc8821a2ant_periodical(IN struct btc_coexist *btcoexist)
  4053. {
  4054. u32 bt_patch_ver;
  4055. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4056. "[BTCoex], ==========================Periodical===========================\n");
  4057. BTC_TRACE(trace_buf);
  4058. if (coex_sta->dis_ver_info_cnt <= 5) {
  4059. coex_sta->dis_ver_info_cnt += 1;
  4060. if (coex_sta->dis_ver_info_cnt == 3) {
  4061. /* Antenna config to set 0x765 = 0x0 (GNT_BT control by PTA) after initial */
  4062. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4063. "[BTCoex], Set GNT_BT control by PTA\n");
  4064. BTC_TRACE(trace_buf);
  4065. halbtc8821a2ant_set_ant_path(btcoexist,
  4066. BTC_ANT_WIFI_AT_MAIN, false, false);
  4067. }
  4068. }
  4069. if (((coex_sta->bt_coex_supported_version == 0) ||
  4070. (coex_sta->bt_coex_supported_version == 0xffff)) && (!coex_sta->bt_disabled))
  4071. btcoexist->btc_get(btcoexist, BTC_GET_U4_SUPPORTED_VERSION, &coex_sta->bt_coex_supported_version);
  4072. btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
  4073. btcoexist->bt_info.bt_get_fw_ver = bt_patch_ver;
  4074. #if (BT_AUTO_REPORT_ONLY_8821A_2ANT == 0)
  4075. halbtc8821a2ant_query_bt_info(btcoexist);
  4076. halbtc8821a2ant_monitor_bt_enable_disable(btcoexist);
  4077. #else
  4078. halbtc8821a2ant_monitor_bt_ctr(btcoexist);
  4079. halbtc8821a2ant_monitor_wifi_ctr(btcoexist);
  4080. halbtc8821a2ant_monitor_bt_enable_disable(btcoexist);
  4081. if (halbtc8821a2ant_is_wifi_status_changed(btcoexist) ||
  4082. coex_dm->auto_tdma_adjust)
  4083. halbtc8821a2ant_run_coexist_mechanism(btcoexist);
  4084. #endif
  4085. }
  4086. #endif
  4087. #endif /* #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) */