halbtc8821a2ant.c 119 KB

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