halbtc8723b2ant.c 117 KB

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