halbtc8821a2ant.c 128 KB

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