halbtc8723b2ant.c 117 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717
  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. /* This call breaks BT when wireless is active -
  1158. * comment it out for now until a better fix is found:
  1159. * btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x1c,
  1160. * 0x3, 0xf1, 0x90);
  1161. */
  1162. break;
  1163. case 4:
  1164. btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x10,
  1165. 0x03, 0xf1, 0x90);
  1166. break;
  1167. case 5:
  1168. btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x1a,
  1169. 0x1a, 0x60, 0x90);
  1170. break;
  1171. case 6:
  1172. btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x12,
  1173. 0x12, 0x60, 0x90);
  1174. break;
  1175. case 7:
  1176. btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x1c,
  1177. 0x3, 0x70, 0x90);
  1178. break;
  1179. case 8:
  1180. btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xa3, 0x10,
  1181. 0x3, 0x70, 0x90);
  1182. break;
  1183. case 9:
  1184. btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x1a,
  1185. 0x1a, 0xe1, 0x90);
  1186. break;
  1187. case 10:
  1188. btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x12,
  1189. 0x12, 0xe1, 0x90);
  1190. break;
  1191. case 11:
  1192. btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0xa,
  1193. 0xa, 0xe1, 0x90);
  1194. break;
  1195. case 12:
  1196. btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x5,
  1197. 0x5, 0xe1, 0x90);
  1198. break;
  1199. case 13:
  1200. btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x1a,
  1201. 0x1a, 0x60, 0x90);
  1202. break;
  1203. case 14:
  1204. btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x12,
  1205. 0x12, 0x60, 0x90);
  1206. break;
  1207. case 15:
  1208. btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0xa,
  1209. 0xa, 0x60, 0x90);
  1210. break;
  1211. case 16:
  1212. btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x5,
  1213. 0x5, 0x60, 0x90);
  1214. break;
  1215. case 17:
  1216. btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xa3, 0x2f,
  1217. 0x2f, 0x60, 0x90);
  1218. break;
  1219. case 18:
  1220. btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x5,
  1221. 0x5, 0xe1, 0x90);
  1222. break;
  1223. case 19:
  1224. btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x25,
  1225. 0x25, 0xe1, 0x90);
  1226. break;
  1227. case 20:
  1228. btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x25,
  1229. 0x25, 0x60, 0x90);
  1230. break;
  1231. case 21:
  1232. btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x15,
  1233. 0x03, 0x70, 0x90);
  1234. break;
  1235. case 71:
  1236. btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x1a,
  1237. 0x1a, 0xe1, 0x90);
  1238. break;
  1239. }
  1240. } else {
  1241. /* disable PS tdma */
  1242. switch (type) {
  1243. case 0:
  1244. btc8723b2ant_set_fw_ps_tdma(btcoexist, 0x0, 0x0, 0x0,
  1245. 0x40, 0x0);
  1246. break;
  1247. case 1:
  1248. btc8723b2ant_set_fw_ps_tdma(btcoexist, 0x0, 0x0, 0x0,
  1249. 0x48, 0x0);
  1250. break;
  1251. default:
  1252. btc8723b2ant_set_fw_ps_tdma(btcoexist, 0x0, 0x0, 0x0,
  1253. 0x40, 0x0);
  1254. break;
  1255. }
  1256. }
  1257. /* update pre state */
  1258. coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on;
  1259. coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma;
  1260. }
  1261. static void btc8723b2ant_coex_alloff(struct btc_coexist *btcoexist)
  1262. {
  1263. /* fw all off */
  1264. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
  1265. btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  1266. btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
  1267. /* sw all off */
  1268. btc8723b2ant_sw_mechanism1(btcoexist, false, false, false, false);
  1269. btc8723b2ant_sw_mechanism2(btcoexist, false, false, false, 0x18);
  1270. /* hw all off */
  1271. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
  1272. btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 0);
  1273. }
  1274. static void btc8723b2ant_init_coex_dm(struct btc_coexist *btcoexist)
  1275. {
  1276. /* force to reset coex mechanism*/
  1277. btc8723b2ant_ps_tdma(btcoexist, FORCE_EXEC, false, 1);
  1278. btc8723b2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 6);
  1279. btc8723b2ant_dec_bt_pwr(btcoexist, FORCE_EXEC, false);
  1280. btc8723b2ant_sw_mechanism1(btcoexist, false, false, false, false);
  1281. btc8723b2ant_sw_mechanism2(btcoexist, false, false, false, 0x18);
  1282. }
  1283. static void btc8723b2ant_action_bt_inquiry(struct btc_coexist *btcoexist)
  1284. {
  1285. bool wifi_connected = false;
  1286. bool low_pwr_disable = true;
  1287. btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
  1288. &low_pwr_disable);
  1289. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  1290. &wifi_connected);
  1291. if (wifi_connected) {
  1292. btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 7);
  1293. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3);
  1294. } else {
  1295. btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 0);
  1296. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
  1297. }
  1298. btc8723b2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 6);
  1299. btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
  1300. btc8723b2ant_sw_mechanism1(btcoexist, false, false, false, false);
  1301. btc8723b2ant_sw_mechanism2(btcoexist, false, false, false, 0x18);
  1302. coex_dm->need_recover_0x948 = true;
  1303. coex_dm->backup_0x948 = btcoexist->btc_read_2byte(btcoexist, 0x948);
  1304. btc8723b2ant_set_ant_path(btcoexist, BTC_ANT_WIFI_AT_AUX,
  1305. false, false);
  1306. }
  1307. static bool btc8723b2ant_is_common_action(struct btc_coexist *btcoexist)
  1308. {
  1309. bool common = false, wifi_connected = false;
  1310. bool wifi_busy = false;
  1311. bool bt_hs_on = false, low_pwr_disable = false;
  1312. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  1313. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  1314. &wifi_connected);
  1315. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  1316. if (!wifi_connected) {
  1317. low_pwr_disable = false;
  1318. btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
  1319. &low_pwr_disable);
  1320. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  1321. "[BTCoex], Wifi non-connected idle!!\n");
  1322. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff,
  1323. 0x0);
  1324. btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 0);
  1325. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
  1326. btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  1327. btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
  1328. btc8723b2ant_sw_mechanism1(btcoexist, false, false, false,
  1329. false);
  1330. btc8723b2ant_sw_mechanism2(btcoexist, false, false, false,
  1331. 0x18);
  1332. common = true;
  1333. } else {
  1334. if (BT_8723B_2ANT_BT_STATUS_NON_CONNECTED_IDLE ==
  1335. coex_dm->bt_status) {
  1336. low_pwr_disable = false;
  1337. btcoexist->btc_set(btcoexist,
  1338. BTC_SET_ACT_DISABLE_LOW_POWER,
  1339. &low_pwr_disable);
  1340. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  1341. "[BTCoex], Wifi connected + "
  1342. "BT non connected-idle!!\n");
  1343. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1,
  1344. 0xfffff, 0x0);
  1345. btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 0);
  1346. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
  1347. btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC,
  1348. 0xb);
  1349. btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC,
  1350. false);
  1351. btc8723b2ant_sw_mechanism1(btcoexist, false, false,
  1352. false, false);
  1353. btc8723b2ant_sw_mechanism2(btcoexist, false, false,
  1354. false, 0x18);
  1355. common = true;
  1356. } else if (BT_8723B_2ANT_BT_STATUS_CONNECTED_IDLE ==
  1357. coex_dm->bt_status) {
  1358. low_pwr_disable = true;
  1359. btcoexist->btc_set(btcoexist,
  1360. BTC_SET_ACT_DISABLE_LOW_POWER,
  1361. &low_pwr_disable);
  1362. if (bt_hs_on)
  1363. return false;
  1364. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  1365. "[BTCoex], Wifi connected + "
  1366. "BT connected-idle!!\n");
  1367. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1,
  1368. 0xfffff, 0x0);
  1369. btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 0);
  1370. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
  1371. btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC,
  1372. 0xb);
  1373. btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC,
  1374. false);
  1375. btc8723b2ant_sw_mechanism1(btcoexist, true, false,
  1376. false, false);
  1377. btc8723b2ant_sw_mechanism2(btcoexist, false, false,
  1378. false, 0x18);
  1379. common = true;
  1380. } else {
  1381. low_pwr_disable = true;
  1382. btcoexist->btc_set(btcoexist,
  1383. BTC_SET_ACT_DISABLE_LOW_POWER,
  1384. &low_pwr_disable);
  1385. if (wifi_busy) {
  1386. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  1387. "[BTCoex], Wifi Connected-Busy + "
  1388. "BT Busy!!\n");
  1389. common = false;
  1390. } else {
  1391. if (bt_hs_on)
  1392. return false;
  1393. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  1394. "[BTCoex], Wifi Connected-Idle + "
  1395. "BT Busy!!\n");
  1396. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A,
  1397. 0x1, 0xfffff, 0x0);
  1398. btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC,
  1399. 7);
  1400. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1401. true, 21);
  1402. btc8723b2ant_fw_dac_swing_lvl(btcoexist,
  1403. NORMAL_EXEC,
  1404. 0xb);
  1405. if (btc8723b_need_dec_pwr(btcoexist))
  1406. btc8723b2ant_dec_bt_pwr(btcoexist,
  1407. NORMAL_EXEC,
  1408. true);
  1409. else
  1410. btc8723b2ant_dec_bt_pwr(btcoexist,
  1411. NORMAL_EXEC,
  1412. false);
  1413. btc8723b2ant_sw_mechanism1(btcoexist, false,
  1414. false, false,
  1415. false);
  1416. btc8723b2ant_sw_mechanism2(btcoexist, false,
  1417. false, false,
  1418. 0x18);
  1419. common = true;
  1420. }
  1421. }
  1422. }
  1423. return common;
  1424. }
  1425. static void set_tdma_int1(struct btc_coexist *btcoexist, bool tx_pause,
  1426. s32 result)
  1427. {
  1428. /* Set PS TDMA for max interval == 1 */
  1429. if (tx_pause) {
  1430. BTC_PRINT(BTC_MSG_ALGORITHM,
  1431. ALGO_TRACE_FW_DETAIL,
  1432. "[BTCoex], TxPause = 1\n");
  1433. if (coex_dm->cur_ps_tdma == 71) {
  1434. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1435. true, 5);
  1436. coex_dm->tdma_adj_type = 5;
  1437. } else if (coex_dm->cur_ps_tdma == 1) {
  1438. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1439. true, 5);
  1440. coex_dm->tdma_adj_type = 5;
  1441. } else if (coex_dm->cur_ps_tdma == 2) {
  1442. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1443. true, 6);
  1444. coex_dm->tdma_adj_type = 6;
  1445. } else if (coex_dm->cur_ps_tdma == 3) {
  1446. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1447. true, 7);
  1448. coex_dm->tdma_adj_type = 7;
  1449. } else if (coex_dm->cur_ps_tdma == 4) {
  1450. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1451. true, 8);
  1452. coex_dm->tdma_adj_type = 8;
  1453. }
  1454. if (coex_dm->cur_ps_tdma == 9) {
  1455. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1456. true, 13);
  1457. coex_dm->tdma_adj_type = 13;
  1458. } else if (coex_dm->cur_ps_tdma == 10) {
  1459. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1460. true, 14);
  1461. coex_dm->tdma_adj_type = 14;
  1462. } else if (coex_dm->cur_ps_tdma == 11) {
  1463. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1464. true, 15);
  1465. coex_dm->tdma_adj_type = 15;
  1466. } else if (coex_dm->cur_ps_tdma == 12) {
  1467. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1468. true, 16);
  1469. coex_dm->tdma_adj_type = 16;
  1470. }
  1471. if (result == -1) {
  1472. if (coex_dm->cur_ps_tdma == 5) {
  1473. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1474. true, 6);
  1475. coex_dm->tdma_adj_type = 6;
  1476. } else if (coex_dm->cur_ps_tdma == 6) {
  1477. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1478. true, 7);
  1479. coex_dm->tdma_adj_type = 7;
  1480. } else if (coex_dm->cur_ps_tdma == 7) {
  1481. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1482. true, 8);
  1483. coex_dm->tdma_adj_type = 8;
  1484. } else if (coex_dm->cur_ps_tdma == 13) {
  1485. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1486. true, 14);
  1487. coex_dm->tdma_adj_type = 14;
  1488. } else if (coex_dm->cur_ps_tdma == 14) {
  1489. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1490. true, 15);
  1491. coex_dm->tdma_adj_type = 15;
  1492. } else if (coex_dm->cur_ps_tdma == 15) {
  1493. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1494. true, 16);
  1495. coex_dm->tdma_adj_type = 16;
  1496. }
  1497. } else if (result == 1) {
  1498. if (coex_dm->cur_ps_tdma == 8) {
  1499. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1500. true, 7);
  1501. coex_dm->tdma_adj_type = 7;
  1502. } else if (coex_dm->cur_ps_tdma == 7) {
  1503. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1504. true, 6);
  1505. coex_dm->tdma_adj_type = 6;
  1506. } else if (coex_dm->cur_ps_tdma == 6) {
  1507. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1508. true, 5);
  1509. coex_dm->tdma_adj_type = 5;
  1510. } else if (coex_dm->cur_ps_tdma == 16) {
  1511. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1512. true, 15);
  1513. coex_dm->tdma_adj_type = 15;
  1514. } else if (coex_dm->cur_ps_tdma == 15) {
  1515. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1516. true, 14);
  1517. coex_dm->tdma_adj_type = 14;
  1518. } else if (coex_dm->cur_ps_tdma == 14) {
  1519. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1520. true, 13);
  1521. coex_dm->tdma_adj_type = 13;
  1522. }
  1523. }
  1524. } else {
  1525. BTC_PRINT(BTC_MSG_ALGORITHM,
  1526. ALGO_TRACE_FW_DETAIL,
  1527. "[BTCoex], TxPause = 0\n");
  1528. if (coex_dm->cur_ps_tdma == 5) {
  1529. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 71);
  1530. coex_dm->tdma_adj_type = 71;
  1531. } else if (coex_dm->cur_ps_tdma == 6) {
  1532. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 2);
  1533. coex_dm->tdma_adj_type = 2;
  1534. } else if (coex_dm->cur_ps_tdma == 7) {
  1535. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3);
  1536. coex_dm->tdma_adj_type = 3;
  1537. } else if (coex_dm->cur_ps_tdma == 8) {
  1538. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 4);
  1539. coex_dm->tdma_adj_type = 4;
  1540. }
  1541. if (coex_dm->cur_ps_tdma == 13) {
  1542. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 9);
  1543. coex_dm->tdma_adj_type = 9;
  1544. } else if (coex_dm->cur_ps_tdma == 14) {
  1545. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 10);
  1546. coex_dm->tdma_adj_type = 10;
  1547. } else if (coex_dm->cur_ps_tdma == 15) {
  1548. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 11);
  1549. coex_dm->tdma_adj_type = 11;
  1550. } else if (coex_dm->cur_ps_tdma == 16) {
  1551. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 12);
  1552. coex_dm->tdma_adj_type = 12;
  1553. }
  1554. if (result == -1) {
  1555. if (coex_dm->cur_ps_tdma == 71) {
  1556. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1557. true, 1);
  1558. coex_dm->tdma_adj_type = 1;
  1559. } else if (coex_dm->cur_ps_tdma == 1) {
  1560. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1561. true, 2);
  1562. coex_dm->tdma_adj_type = 2;
  1563. } else if (coex_dm->cur_ps_tdma == 2) {
  1564. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1565. true, 3);
  1566. coex_dm->tdma_adj_type = 3;
  1567. } else if (coex_dm->cur_ps_tdma == 3) {
  1568. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1569. true, 4);
  1570. coex_dm->tdma_adj_type = 4;
  1571. } else if (coex_dm->cur_ps_tdma == 9) {
  1572. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1573. true, 10);
  1574. coex_dm->tdma_adj_type = 10;
  1575. } else if (coex_dm->cur_ps_tdma == 10) {
  1576. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1577. true, 11);
  1578. coex_dm->tdma_adj_type = 11;
  1579. } else if (coex_dm->cur_ps_tdma == 11) {
  1580. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1581. true, 12);
  1582. coex_dm->tdma_adj_type = 12;
  1583. }
  1584. } else if (result == 1) {
  1585. if (coex_dm->cur_ps_tdma == 4) {
  1586. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1587. true, 3);
  1588. coex_dm->tdma_adj_type = 3;
  1589. } else if (coex_dm->cur_ps_tdma == 3) {
  1590. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1591. true, 2);
  1592. coex_dm->tdma_adj_type = 2;
  1593. } else if (coex_dm->cur_ps_tdma == 2) {
  1594. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1595. true, 1);
  1596. coex_dm->tdma_adj_type = 1;
  1597. } else if (coex_dm->cur_ps_tdma == 1) {
  1598. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1599. true, 71);
  1600. coex_dm->tdma_adj_type = 71;
  1601. } else if (coex_dm->cur_ps_tdma == 12) {
  1602. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1603. true, 11);
  1604. coex_dm->tdma_adj_type = 11;
  1605. } else if (coex_dm->cur_ps_tdma == 11) {
  1606. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1607. true, 10);
  1608. coex_dm->tdma_adj_type = 10;
  1609. } else if (coex_dm->cur_ps_tdma == 10) {
  1610. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1611. true, 9);
  1612. coex_dm->tdma_adj_type = 9;
  1613. }
  1614. }
  1615. }
  1616. }
  1617. static void set_tdma_int2(struct btc_coexist *btcoexist, bool tx_pause,
  1618. s32 result)
  1619. {
  1620. /* Set PS TDMA for max interval == 2 */
  1621. if (tx_pause) {
  1622. BTC_PRINT(BTC_MSG_ALGORITHM,
  1623. ALGO_TRACE_FW_DETAIL,
  1624. "[BTCoex], TxPause = 1\n");
  1625. if (coex_dm->cur_ps_tdma == 1) {
  1626. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 6);
  1627. coex_dm->tdma_adj_type = 6;
  1628. } else if (coex_dm->cur_ps_tdma == 2) {
  1629. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 6);
  1630. coex_dm->tdma_adj_type = 6;
  1631. } else if (coex_dm->cur_ps_tdma == 3) {
  1632. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 7);
  1633. coex_dm->tdma_adj_type = 7;
  1634. } else if (coex_dm->cur_ps_tdma == 4) {
  1635. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 8);
  1636. coex_dm->tdma_adj_type = 8;
  1637. }
  1638. if (coex_dm->cur_ps_tdma == 9) {
  1639. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14);
  1640. coex_dm->tdma_adj_type = 14;
  1641. } else if (coex_dm->cur_ps_tdma == 10) {
  1642. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14);
  1643. coex_dm->tdma_adj_type = 14;
  1644. } else if (coex_dm->cur_ps_tdma == 11) {
  1645. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 15);
  1646. coex_dm->tdma_adj_type = 15;
  1647. } else if (coex_dm->cur_ps_tdma == 12) {
  1648. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 16);
  1649. coex_dm->tdma_adj_type = 16;
  1650. }
  1651. if (result == -1) {
  1652. if (coex_dm->cur_ps_tdma == 5) {
  1653. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1654. true, 6);
  1655. coex_dm->tdma_adj_type = 6;
  1656. } else if (coex_dm->cur_ps_tdma == 6) {
  1657. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1658. true, 7);
  1659. coex_dm->tdma_adj_type = 7;
  1660. } else if (coex_dm->cur_ps_tdma == 7) {
  1661. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1662. true, 8);
  1663. coex_dm->tdma_adj_type = 8;
  1664. } else if (coex_dm->cur_ps_tdma == 13) {
  1665. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1666. true, 14);
  1667. coex_dm->tdma_adj_type = 14;
  1668. } else if (coex_dm->cur_ps_tdma == 14) {
  1669. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1670. true, 15);
  1671. coex_dm->tdma_adj_type = 15;
  1672. } else if (coex_dm->cur_ps_tdma == 15) {
  1673. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1674. true, 16);
  1675. coex_dm->tdma_adj_type = 16;
  1676. }
  1677. } else if (result == 1) {
  1678. if (coex_dm->cur_ps_tdma == 8) {
  1679. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1680. true, 7);
  1681. coex_dm->tdma_adj_type = 7;
  1682. } else if (coex_dm->cur_ps_tdma == 7) {
  1683. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1684. true, 6);
  1685. coex_dm->tdma_adj_type = 6;
  1686. } else if (coex_dm->cur_ps_tdma == 6) {
  1687. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1688. true, 6);
  1689. coex_dm->tdma_adj_type = 6;
  1690. } else if (coex_dm->cur_ps_tdma == 16) {
  1691. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1692. true, 15);
  1693. coex_dm->tdma_adj_type = 15;
  1694. } else if (coex_dm->cur_ps_tdma == 15) {
  1695. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1696. true, 14);
  1697. coex_dm->tdma_adj_type = 14;
  1698. } else if (coex_dm->cur_ps_tdma == 14) {
  1699. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1700. true, 14);
  1701. coex_dm->tdma_adj_type = 14;
  1702. }
  1703. }
  1704. } else {
  1705. BTC_PRINT(BTC_MSG_ALGORITHM,
  1706. ALGO_TRACE_FW_DETAIL,
  1707. "[BTCoex], TxPause = 0\n");
  1708. if (coex_dm->cur_ps_tdma == 5) {
  1709. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 2);
  1710. coex_dm->tdma_adj_type = 2;
  1711. } else if (coex_dm->cur_ps_tdma == 6) {
  1712. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 2);
  1713. coex_dm->tdma_adj_type = 2;
  1714. } else if (coex_dm->cur_ps_tdma == 7) {
  1715. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3);
  1716. coex_dm->tdma_adj_type = 3;
  1717. } else if (coex_dm->cur_ps_tdma == 8) {
  1718. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 4);
  1719. coex_dm->tdma_adj_type = 4;
  1720. }
  1721. if (coex_dm->cur_ps_tdma == 13) {
  1722. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 10);
  1723. coex_dm->tdma_adj_type = 10;
  1724. } else if (coex_dm->cur_ps_tdma == 14) {
  1725. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 10);
  1726. coex_dm->tdma_adj_type = 10;
  1727. } else if (coex_dm->cur_ps_tdma == 15) {
  1728. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 11);
  1729. coex_dm->tdma_adj_type = 11;
  1730. } else if (coex_dm->cur_ps_tdma == 16) {
  1731. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 12);
  1732. coex_dm->tdma_adj_type = 12;
  1733. }
  1734. if (result == -1) {
  1735. if (coex_dm->cur_ps_tdma == 1) {
  1736. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1737. true, 2);
  1738. coex_dm->tdma_adj_type = 2;
  1739. } else if (coex_dm->cur_ps_tdma == 2) {
  1740. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1741. true, 3);
  1742. coex_dm->tdma_adj_type = 3;
  1743. } else if (coex_dm->cur_ps_tdma == 3) {
  1744. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1745. true, 4);
  1746. coex_dm->tdma_adj_type = 4;
  1747. } else if (coex_dm->cur_ps_tdma == 9) {
  1748. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1749. true, 10);
  1750. coex_dm->tdma_adj_type = 10;
  1751. } else if (coex_dm->cur_ps_tdma == 10) {
  1752. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1753. true, 11);
  1754. coex_dm->tdma_adj_type = 11;
  1755. } else if (coex_dm->cur_ps_tdma == 11) {
  1756. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1757. true, 12);
  1758. coex_dm->tdma_adj_type = 12;
  1759. }
  1760. } else if (result == 1) {
  1761. if (coex_dm->cur_ps_tdma == 4) {
  1762. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1763. true, 3);
  1764. coex_dm->tdma_adj_type = 3;
  1765. } else if (coex_dm->cur_ps_tdma == 3) {
  1766. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1767. true, 2);
  1768. coex_dm->tdma_adj_type = 2;
  1769. } else if (coex_dm->cur_ps_tdma == 2) {
  1770. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1771. true, 2);
  1772. coex_dm->tdma_adj_type = 2;
  1773. } else if (coex_dm->cur_ps_tdma == 12) {
  1774. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1775. true, 11);
  1776. coex_dm->tdma_adj_type = 11;
  1777. } else if (coex_dm->cur_ps_tdma == 11) {
  1778. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1779. true, 10);
  1780. coex_dm->tdma_adj_type = 10;
  1781. } else if (coex_dm->cur_ps_tdma == 10) {
  1782. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1783. true, 10);
  1784. coex_dm->tdma_adj_type = 10;
  1785. }
  1786. }
  1787. }
  1788. }
  1789. static void set_tdma_int3(struct btc_coexist *btcoexist, bool tx_pause,
  1790. s32 result)
  1791. {
  1792. /* Set PS TDMA for max interval == 3 */
  1793. if (tx_pause) {
  1794. BTC_PRINT(BTC_MSG_ALGORITHM,
  1795. ALGO_TRACE_FW_DETAIL,
  1796. "[BTCoex], TxPause = 1\n");
  1797. if (coex_dm->cur_ps_tdma == 1) {
  1798. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 7);
  1799. coex_dm->tdma_adj_type = 7;
  1800. } else if (coex_dm->cur_ps_tdma == 2) {
  1801. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 7);
  1802. coex_dm->tdma_adj_type = 7;
  1803. } else if (coex_dm->cur_ps_tdma == 3) {
  1804. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 7);
  1805. coex_dm->tdma_adj_type = 7;
  1806. } else if (coex_dm->cur_ps_tdma == 4) {
  1807. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 8);
  1808. coex_dm->tdma_adj_type = 8;
  1809. }
  1810. if (coex_dm->cur_ps_tdma == 9) {
  1811. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 15);
  1812. coex_dm->tdma_adj_type = 15;
  1813. } else if (coex_dm->cur_ps_tdma == 10) {
  1814. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 15);
  1815. coex_dm->tdma_adj_type = 15;
  1816. } else if (coex_dm->cur_ps_tdma == 11) {
  1817. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 15);
  1818. coex_dm->tdma_adj_type = 15;
  1819. } else if (coex_dm->cur_ps_tdma == 12) {
  1820. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 16);
  1821. coex_dm->tdma_adj_type = 16;
  1822. }
  1823. if (result == -1) {
  1824. if (coex_dm->cur_ps_tdma == 5) {
  1825. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1826. true, 7);
  1827. coex_dm->tdma_adj_type = 7;
  1828. } else if (coex_dm->cur_ps_tdma == 6) {
  1829. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1830. true, 7);
  1831. coex_dm->tdma_adj_type = 7;
  1832. } else if (coex_dm->cur_ps_tdma == 7) {
  1833. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1834. true, 8);
  1835. coex_dm->tdma_adj_type = 8;
  1836. } else if (coex_dm->cur_ps_tdma == 13) {
  1837. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1838. true, 15);
  1839. coex_dm->tdma_adj_type = 15;
  1840. } else if (coex_dm->cur_ps_tdma == 14) {
  1841. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1842. true, 15);
  1843. coex_dm->tdma_adj_type = 15;
  1844. } else if (coex_dm->cur_ps_tdma == 15) {
  1845. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1846. true, 16);
  1847. coex_dm->tdma_adj_type = 16;
  1848. }
  1849. } else if (result == 1) {
  1850. if (coex_dm->cur_ps_tdma == 8) {
  1851. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1852. true, 7);
  1853. coex_dm->tdma_adj_type = 7;
  1854. } else if (coex_dm->cur_ps_tdma == 7) {
  1855. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1856. true, 7);
  1857. coex_dm->tdma_adj_type = 7;
  1858. } else if (coex_dm->cur_ps_tdma == 6) {
  1859. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1860. true, 7);
  1861. coex_dm->tdma_adj_type = 7;
  1862. } else if (coex_dm->cur_ps_tdma == 16) {
  1863. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1864. true, 15);
  1865. coex_dm->tdma_adj_type = 15;
  1866. } else if (coex_dm->cur_ps_tdma == 15) {
  1867. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1868. true, 15);
  1869. coex_dm->tdma_adj_type = 15;
  1870. } else if (coex_dm->cur_ps_tdma == 14) {
  1871. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1872. true, 15);
  1873. coex_dm->tdma_adj_type = 15;
  1874. }
  1875. }
  1876. } else {
  1877. BTC_PRINT(BTC_MSG_ALGORITHM,
  1878. ALGO_TRACE_FW_DETAIL,
  1879. "[BTCoex], TxPause = 0\n");
  1880. if (coex_dm->cur_ps_tdma == 5) {
  1881. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3);
  1882. coex_dm->tdma_adj_type = 3;
  1883. } else if (coex_dm->cur_ps_tdma == 6) {
  1884. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3);
  1885. coex_dm->tdma_adj_type = 3;
  1886. } else if (coex_dm->cur_ps_tdma == 7) {
  1887. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3);
  1888. coex_dm->tdma_adj_type = 3;
  1889. } else if (coex_dm->cur_ps_tdma == 8) {
  1890. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 4);
  1891. coex_dm->tdma_adj_type = 4;
  1892. }
  1893. if (coex_dm->cur_ps_tdma == 13) {
  1894. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 11);
  1895. coex_dm->tdma_adj_type = 11;
  1896. } else if (coex_dm->cur_ps_tdma == 14) {
  1897. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 11);
  1898. coex_dm->tdma_adj_type = 11;
  1899. } else if (coex_dm->cur_ps_tdma == 15) {
  1900. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 11);
  1901. coex_dm->tdma_adj_type = 11;
  1902. } else if (coex_dm->cur_ps_tdma == 16) {
  1903. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 12);
  1904. coex_dm->tdma_adj_type = 12;
  1905. }
  1906. if (result == -1) {
  1907. if (coex_dm->cur_ps_tdma == 1) {
  1908. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1909. true, 3);
  1910. coex_dm->tdma_adj_type = 3;
  1911. } else if (coex_dm->cur_ps_tdma == 2) {
  1912. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1913. true, 3);
  1914. coex_dm->tdma_adj_type = 3;
  1915. } else if (coex_dm->cur_ps_tdma == 3) {
  1916. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1917. true, 4);
  1918. coex_dm->tdma_adj_type = 4;
  1919. } else if (coex_dm->cur_ps_tdma == 9) {
  1920. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1921. true, 11);
  1922. coex_dm->tdma_adj_type = 11;
  1923. } else if (coex_dm->cur_ps_tdma == 10) {
  1924. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1925. true, 11);
  1926. coex_dm->tdma_adj_type = 11;
  1927. } else if (coex_dm->cur_ps_tdma == 11) {
  1928. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1929. true, 12);
  1930. coex_dm->tdma_adj_type = 12;
  1931. }
  1932. } else if (result == 1) {
  1933. if (coex_dm->cur_ps_tdma == 4) {
  1934. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1935. true, 3);
  1936. coex_dm->tdma_adj_type = 3;
  1937. } else if (coex_dm->cur_ps_tdma == 3) {
  1938. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1939. true, 3);
  1940. coex_dm->tdma_adj_type = 3;
  1941. } else if (coex_dm->cur_ps_tdma == 2) {
  1942. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1943. true, 3);
  1944. coex_dm->tdma_adj_type = 3;
  1945. } else if (coex_dm->cur_ps_tdma == 12) {
  1946. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1947. true, 11);
  1948. coex_dm->tdma_adj_type = 11;
  1949. } else if (coex_dm->cur_ps_tdma == 11) {
  1950. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1951. true, 11);
  1952. coex_dm->tdma_adj_type = 11;
  1953. } else if (coex_dm->cur_ps_tdma == 10) {
  1954. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1955. true, 11);
  1956. coex_dm->tdma_adj_type = 11;
  1957. }
  1958. }
  1959. }
  1960. }
  1961. static void btc8723b2ant_tdma_duration_adjust(struct btc_coexist *btcoexist,
  1962. bool sco_hid, bool tx_pause,
  1963. u8 max_interval)
  1964. {
  1965. static s32 up, dn, m, n, wait_count;
  1966. /*0: no change, +1: increase WiFi duration, -1: decrease WiFi duration*/
  1967. s32 result;
  1968. u8 retry_count = 0;
  1969. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW,
  1970. "[BTCoex], TdmaDurationAdjust()\n");
  1971. if (!coex_dm->auto_tdma_adjust) {
  1972. coex_dm->auto_tdma_adjust = true;
  1973. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
  1974. "[BTCoex], first run TdmaDurationAdjust()!!\n");
  1975. if (sco_hid) {
  1976. if (tx_pause) {
  1977. if (max_interval == 1) {
  1978. btc8723b2ant_ps_tdma(btcoexist,
  1979. NORMAL_EXEC,
  1980. true, 13);
  1981. coex_dm->tdma_adj_type = 13;
  1982. } else if (max_interval == 2) {
  1983. btc8723b2ant_ps_tdma(btcoexist,
  1984. NORMAL_EXEC,
  1985. true, 14);
  1986. coex_dm->tdma_adj_type = 14;
  1987. } else if (max_interval == 3) {
  1988. btc8723b2ant_ps_tdma(btcoexist,
  1989. NORMAL_EXEC,
  1990. true, 15);
  1991. coex_dm->tdma_adj_type = 15;
  1992. } else {
  1993. btc8723b2ant_ps_tdma(btcoexist,
  1994. NORMAL_EXEC,
  1995. true, 15);
  1996. coex_dm->tdma_adj_type = 15;
  1997. }
  1998. } else {
  1999. if (max_interval == 1) {
  2000. btc8723b2ant_ps_tdma(btcoexist,
  2001. NORMAL_EXEC,
  2002. true, 9);
  2003. coex_dm->tdma_adj_type = 9;
  2004. } else if (max_interval == 2) {
  2005. btc8723b2ant_ps_tdma(btcoexist,
  2006. NORMAL_EXEC,
  2007. true, 10);
  2008. coex_dm->tdma_adj_type = 10;
  2009. } else if (max_interval == 3) {
  2010. btc8723b2ant_ps_tdma(btcoexist,
  2011. NORMAL_EXEC,
  2012. true, 11);
  2013. coex_dm->tdma_adj_type = 11;
  2014. } else {
  2015. btc8723b2ant_ps_tdma(btcoexist,
  2016. NORMAL_EXEC,
  2017. true, 11);
  2018. coex_dm->tdma_adj_type = 11;
  2019. }
  2020. }
  2021. } else {
  2022. if (tx_pause) {
  2023. if (max_interval == 1) {
  2024. btc8723b2ant_ps_tdma(btcoexist,
  2025. NORMAL_EXEC,
  2026. true, 5);
  2027. coex_dm->tdma_adj_type = 5;
  2028. } else if (max_interval == 2) {
  2029. btc8723b2ant_ps_tdma(btcoexist,
  2030. NORMAL_EXEC,
  2031. true, 6);
  2032. coex_dm->tdma_adj_type = 6;
  2033. } else if (max_interval == 3) {
  2034. btc8723b2ant_ps_tdma(btcoexist,
  2035. NORMAL_EXEC,
  2036. true, 7);
  2037. coex_dm->tdma_adj_type = 7;
  2038. } else {
  2039. btc8723b2ant_ps_tdma(btcoexist,
  2040. NORMAL_EXEC,
  2041. true, 7);
  2042. coex_dm->tdma_adj_type = 7;
  2043. }
  2044. } else {
  2045. if (max_interval == 1) {
  2046. btc8723b2ant_ps_tdma(btcoexist,
  2047. NORMAL_EXEC,
  2048. true, 1);
  2049. coex_dm->tdma_adj_type = 1;
  2050. } else if (max_interval == 2) {
  2051. btc8723b2ant_ps_tdma(btcoexist,
  2052. NORMAL_EXEC,
  2053. true, 2);
  2054. coex_dm->tdma_adj_type = 2;
  2055. } else if (max_interval == 3) {
  2056. btc8723b2ant_ps_tdma(btcoexist,
  2057. NORMAL_EXEC,
  2058. true, 3);
  2059. coex_dm->tdma_adj_type = 3;
  2060. } else {
  2061. btc8723b2ant_ps_tdma(btcoexist,
  2062. NORMAL_EXEC,
  2063. true, 3);
  2064. coex_dm->tdma_adj_type = 3;
  2065. }
  2066. }
  2067. }
  2068. up = 0;
  2069. dn = 0;
  2070. m = 1;
  2071. n = 3;
  2072. result = 0;
  2073. wait_count = 0;
  2074. } else {
  2075. /*accquire the BT TRx retry count from BT_Info byte2*/
  2076. retry_count = coex_sta->bt_retry_cnt;
  2077. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
  2078. "[BTCoex], retry_count = %d\n", retry_count);
  2079. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
  2080. "[BTCoex], up=%d, dn=%d, m=%d, n=%d, wait_count=%d\n",
  2081. up, dn, m, n, wait_count);
  2082. result = 0;
  2083. wait_count++;
  2084. /* no retry in the last 2-second duration*/
  2085. if (retry_count == 0) {
  2086. up++;
  2087. dn--;
  2088. if (dn <= 0)
  2089. dn = 0;
  2090. if (up >= n) {
  2091. wait_count = 0;
  2092. n = 3;
  2093. up = 0;
  2094. dn = 0;
  2095. result = 1;
  2096. BTC_PRINT(BTC_MSG_ALGORITHM,
  2097. ALGO_TRACE_FW_DETAIL,
  2098. "[BTCoex], Increase wifi "
  2099. "duration!!\n");
  2100. } /* <=3 retry in the last 2-second duration*/
  2101. } else if (retry_count <= 3) {
  2102. up--;
  2103. dn++;
  2104. if (up <= 0)
  2105. up = 0;
  2106. if (dn == 2) {
  2107. if (wait_count <= 2)
  2108. m++;
  2109. else
  2110. m = 1;
  2111. if (m >= 20)
  2112. m = 20;
  2113. n = 3 * m;
  2114. up = 0;
  2115. dn = 0;
  2116. wait_count = 0;
  2117. result = -1;
  2118. BTC_PRINT(BTC_MSG_ALGORITHM,
  2119. ALGO_TRACE_FW_DETAIL,
  2120. "[BTCoex], Decrease wifi duration "
  2121. "for retry_counter<3!!\n");
  2122. }
  2123. } else {
  2124. if (wait_count == 1)
  2125. m++;
  2126. else
  2127. m = 1;
  2128. if (m >= 20)
  2129. m = 20;
  2130. n = 3 * m;
  2131. up = 0;
  2132. dn = 0;
  2133. wait_count = 0;
  2134. result = -1;
  2135. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
  2136. "[BTCoex], Decrease wifi duration "
  2137. "for retry_counter>3!!\n");
  2138. }
  2139. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
  2140. "[BTCoex], max Interval = %d\n", max_interval);
  2141. if (max_interval == 1)
  2142. set_tdma_int1(btcoexist, tx_pause, result);
  2143. else if (max_interval == 2)
  2144. set_tdma_int2(btcoexist, tx_pause, result);
  2145. else if (max_interval == 3)
  2146. set_tdma_int3(btcoexist, tx_pause, result);
  2147. }
  2148. /*if current PsTdma not match with the recorded one (when scan, dhcp..),
  2149. *then we have to adjust it back to the previous recorded one.
  2150. */
  2151. if (coex_dm->cur_ps_tdma != coex_dm->tdma_adj_type) {
  2152. bool scan = false, link = false, roam = false;
  2153. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
  2154. "[BTCoex], PsTdma type dismatch!!!, "
  2155. "curPsTdma=%d, recordPsTdma=%d\n",
  2156. coex_dm->cur_ps_tdma, coex_dm->tdma_adj_type);
  2157. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
  2158. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
  2159. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
  2160. if (!scan && !link && !roam)
  2161. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2162. coex_dm->tdma_adj_type);
  2163. else
  2164. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
  2165. "[BTCoex], roaming/link/scan is under"
  2166. " progress, will adjust next time!!!\n");
  2167. }
  2168. }
  2169. /* SCO only or SCO+PAN(HS) */
  2170. static void btc8723b2ant_action_sco(struct btc_coexist *btcoexist)
  2171. {
  2172. u8 wifi_rssi_state;
  2173. u32 wifi_bw;
  2174. wifi_rssi_state = btc8723b2ant_wifi_rssi_state(btcoexist,
  2175. 0, 2, 15, 0);
  2176. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
  2177. btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 4);
  2178. if (btc8723b_need_dec_pwr(btcoexist))
  2179. btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
  2180. else
  2181. btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
  2182. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  2183. /*for SCO quality at 11b/g mode*/
  2184. if (BTC_WIFI_BW_LEGACY == wifi_bw)
  2185. btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 2);
  2186. else /*for SCO quality & wifi performance balance at 11n mode*/
  2187. btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 8);
  2188. /*for voice quality */
  2189. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  2190. /* sw mechanism */
  2191. if (BTC_WIFI_BW_HT40 == wifi_bw) {
  2192. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2193. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2194. btc8723b2ant_sw_mechanism1(btcoexist, true, true,
  2195. false, false);
  2196. btc8723b2ant_sw_mechanism2(btcoexist, true, false,
  2197. true, 0x4);
  2198. } else {
  2199. btc8723b2ant_sw_mechanism1(btcoexist, true, true,
  2200. false, false);
  2201. btc8723b2ant_sw_mechanism2(btcoexist, false, false,
  2202. true, 0x4);
  2203. }
  2204. } else {
  2205. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2206. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2207. btc8723b2ant_sw_mechanism1(btcoexist, false, true,
  2208. false, false);
  2209. btc8723b2ant_sw_mechanism2(btcoexist, true, false,
  2210. true, 0x4);
  2211. } else {
  2212. btc8723b2ant_sw_mechanism1(btcoexist, false, true,
  2213. false, false);
  2214. btc8723b2ant_sw_mechanism2(btcoexist, false, false,
  2215. true, 0x4);
  2216. }
  2217. }
  2218. }
  2219. static void btc8723b2ant_action_hid(struct btc_coexist *btcoexist)
  2220. {
  2221. u8 wifi_rssi_state, bt_rssi_state;
  2222. u32 wifi_bw;
  2223. wifi_rssi_state = btc8723b2ant_wifi_rssi_state(btcoexist,
  2224. 0, 2, 15, 0);
  2225. bt_rssi_state = btc8723b2ant_bt_rssi_state(2, 29, 0);
  2226. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
  2227. btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  2228. if (btc8723b_need_dec_pwr(btcoexist))
  2229. btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
  2230. else
  2231. btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
  2232. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  2233. if (BTC_WIFI_BW_LEGACY == wifi_bw) /*/for HID at 11b/g mode*/
  2234. btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 7);
  2235. else /*for HID quality & wifi performance balance at 11n mode*/
  2236. btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 9);
  2237. if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2238. (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH))
  2239. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 9);
  2240. else
  2241. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 13);
  2242. /* sw mechanism */
  2243. if (BTC_WIFI_BW_HT40 == wifi_bw) {
  2244. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2245. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2246. btc8723b2ant_sw_mechanism1(btcoexist, true, true,
  2247. false, false);
  2248. btc8723b2ant_sw_mechanism2(btcoexist, true, false,
  2249. false, 0x18);
  2250. } else {
  2251. btc8723b2ant_sw_mechanism1(btcoexist, true, true,
  2252. false, false);
  2253. btc8723b2ant_sw_mechanism2(btcoexist, false, false,
  2254. false, 0x18);
  2255. }
  2256. } else {
  2257. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2258. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2259. btc8723b2ant_sw_mechanism1(btcoexist, false, true,
  2260. false, false);
  2261. btc8723b2ant_sw_mechanism2(btcoexist, true, false,
  2262. false, 0x18);
  2263. } else {
  2264. btc8723b2ant_sw_mechanism1(btcoexist, false, true,
  2265. false, false);
  2266. btc8723b2ant_sw_mechanism2(btcoexist, false, false,
  2267. false, 0x18);
  2268. }
  2269. }
  2270. }
  2271. /*A2DP only / PAN(EDR) only/ A2DP+PAN(HS)*/
  2272. static void btc8723b2ant_action_a2dp(struct btc_coexist *btcoexist)
  2273. {
  2274. u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state;
  2275. u32 wifi_bw;
  2276. u8 ap_num = 0;
  2277. wifi_rssi_state = btc8723b2ant_wifi_rssi_state(btcoexist,
  2278. 0, 2, 15, 0);
  2279. wifi_rssi_state1 = btc8723b2ant_wifi_rssi_state(btcoexist,
  2280. 1, 2, 40, 0);
  2281. bt_rssi_state = btc8723b2ant_bt_rssi_state(2, 29, 0);
  2282. btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, &ap_num);
  2283. /* define the office environment */
  2284. /* driver don't know AP num in Linux, so we will never enter this if */
  2285. if (ap_num >= 10 && BTC_RSSI_HIGH(wifi_rssi_state1)) {
  2286. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff,
  2287. 0x0);
  2288. btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  2289. btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
  2290. btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 0);
  2291. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
  2292. /* sw mechanism */
  2293. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  2294. if (BTC_WIFI_BW_HT40 == wifi_bw) {
  2295. btc8723b2ant_sw_mechanism1(btcoexist, true, false,
  2296. false, false);
  2297. btc8723b2ant_sw_mechanism2(btcoexist, true, false,
  2298. true, 0x18);
  2299. } else {
  2300. btc8723b2ant_sw_mechanism1(btcoexist, false, false,
  2301. false, false);
  2302. btc8723b2ant_sw_mechanism2(btcoexist, true, false,
  2303. true, 0x18);
  2304. }
  2305. return;
  2306. }
  2307. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
  2308. btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  2309. if (btc8723b_need_dec_pwr(btcoexist))
  2310. btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
  2311. else
  2312. btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
  2313. btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 7);
  2314. if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2315. (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH))
  2316. btc8723b2ant_tdma_duration_adjust(btcoexist, false,
  2317. false, 1);
  2318. else
  2319. btc8723b2ant_tdma_duration_adjust(btcoexist, false, true, 1);
  2320. /* sw mechanism */
  2321. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  2322. if (BTC_WIFI_BW_HT40 == wifi_bw) {
  2323. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2324. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2325. btc8723b2ant_sw_mechanism1(btcoexist, true, false,
  2326. false, false);
  2327. btc8723b2ant_sw_mechanism2(btcoexist, true, false,
  2328. false, 0x18);
  2329. } else {
  2330. btc8723b2ant_sw_mechanism1(btcoexist, true, false,
  2331. false, false);
  2332. btc8723b2ant_sw_mechanism2(btcoexist, false, false,
  2333. false, 0x18);
  2334. }
  2335. } else {
  2336. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2337. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2338. btc8723b2ant_sw_mechanism1(btcoexist, false, false,
  2339. false, false);
  2340. btc8723b2ant_sw_mechanism2(btcoexist, true, false,
  2341. false, 0x18);
  2342. } else {
  2343. btc8723b2ant_sw_mechanism1(btcoexist, false, false,
  2344. false, false);
  2345. btc8723b2ant_sw_mechanism2(btcoexist, false, false,
  2346. false, 0x18);
  2347. }
  2348. }
  2349. }
  2350. static void btc8723b2ant_action_a2dp_pan_hs(struct btc_coexist *btcoexist)
  2351. {
  2352. u8 wifi_rssi_state;
  2353. u32 wifi_bw;
  2354. wifi_rssi_state = btc8723b2ant_wifi_rssi_state(btcoexist,
  2355. 0, 2, 15, 0);
  2356. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
  2357. btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  2358. if (btc8723b_need_dec_pwr(btcoexist))
  2359. btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
  2360. else
  2361. btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
  2362. btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 7);
  2363. btc8723b2ant_tdma_duration_adjust(btcoexist, false, true, 2);
  2364. /* sw mechanism */
  2365. btcoexist->btc_get(btcoexist,
  2366. BTC_GET_U4_WIFI_BW, &wifi_bw);
  2367. if (BTC_WIFI_BW_HT40 == wifi_bw) {
  2368. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2369. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2370. btc8723b2ant_sw_mechanism1(btcoexist, true, false,
  2371. false, false);
  2372. btc8723b2ant_sw_mechanism2(btcoexist, true, false,
  2373. false, 0x18);
  2374. } else {
  2375. btc8723b2ant_sw_mechanism1(btcoexist, true, false,
  2376. false, false);
  2377. btc8723b2ant_sw_mechanism2(btcoexist, false, false,
  2378. false, 0x18);
  2379. }
  2380. } else {
  2381. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2382. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2383. btc8723b2ant_sw_mechanism1(btcoexist, false, false,
  2384. false, false);
  2385. btc8723b2ant_sw_mechanism2(btcoexist, true, false,
  2386. false, 0x18);
  2387. } else {
  2388. btc8723b2ant_sw_mechanism1(btcoexist, false, false,
  2389. false, false);
  2390. btc8723b2ant_sw_mechanism2(btcoexist, false, false,
  2391. false, 0x18);
  2392. }
  2393. }
  2394. }
  2395. static void btc8723b2ant_action_pan_edr(struct btc_coexist *btcoexist)
  2396. {
  2397. u8 wifi_rssi_state, bt_rssi_state;
  2398. u32 wifi_bw;
  2399. wifi_rssi_state = btc8723b2ant_wifi_rssi_state(btcoexist,
  2400. 0, 2, 15, 0);
  2401. bt_rssi_state = btc8723b2ant_bt_rssi_state(2, 29, 0);
  2402. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
  2403. btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  2404. if (btc8723b_need_dec_pwr(btcoexist))
  2405. btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
  2406. else
  2407. btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
  2408. btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 10);
  2409. if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2410. (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH))
  2411. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 1);
  2412. else
  2413. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
  2414. /* sw mechanism */
  2415. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  2416. if (BTC_WIFI_BW_HT40 == wifi_bw) {
  2417. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2418. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2419. btc8723b2ant_sw_mechanism1(btcoexist, true, false,
  2420. false, false);
  2421. btc8723b2ant_sw_mechanism2(btcoexist, true, false,
  2422. false, 0x18);
  2423. } else {
  2424. btc8723b2ant_sw_mechanism1(btcoexist, true, false,
  2425. false, false);
  2426. btc8723b2ant_sw_mechanism2(btcoexist, false, false,
  2427. false, 0x18);
  2428. }
  2429. } else {
  2430. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2431. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2432. btc8723b2ant_sw_mechanism1(btcoexist, false, false,
  2433. false, false);
  2434. btc8723b2ant_sw_mechanism2(btcoexist, true, false,
  2435. false, 0x18);
  2436. } else {
  2437. btc8723b2ant_sw_mechanism1(btcoexist, false, false,
  2438. false, false);
  2439. btc8723b2ant_sw_mechanism2(btcoexist, false, false,
  2440. false, 0x18);
  2441. }
  2442. }
  2443. }
  2444. /*PAN(HS) only*/
  2445. static void btc8723b2ant_action_pan_hs(struct btc_coexist *btcoexist)
  2446. {
  2447. u8 wifi_rssi_state;
  2448. u32 wifi_bw;
  2449. wifi_rssi_state = btc8723b2ant_wifi_rssi_state(btcoexist,
  2450. 0, 2, 15, 0);
  2451. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
  2452. btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  2453. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2454. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH))
  2455. btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
  2456. else
  2457. btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
  2458. btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 7);
  2459. btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
  2460. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  2461. if (BTC_WIFI_BW_HT40 == wifi_bw) {
  2462. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2463. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2464. btc8723b2ant_sw_mechanism1(btcoexist, true, false,
  2465. false, false);
  2466. btc8723b2ant_sw_mechanism2(btcoexist, true, false,
  2467. false, 0x18);
  2468. } else {
  2469. btc8723b2ant_sw_mechanism1(btcoexist, true, false,
  2470. false, false);
  2471. btc8723b2ant_sw_mechanism2(btcoexist, false, false,
  2472. false, 0x18);
  2473. }
  2474. } else {
  2475. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2476. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2477. btc8723b2ant_sw_mechanism1(btcoexist, false, false,
  2478. false, false);
  2479. btc8723b2ant_sw_mechanism2(btcoexist, true, false,
  2480. false, 0x18);
  2481. } else {
  2482. btc8723b2ant_sw_mechanism1(btcoexist, false, false,
  2483. false, false);
  2484. btc8723b2ant_sw_mechanism2(btcoexist, false, false,
  2485. false, 0x18);
  2486. }
  2487. }
  2488. }
  2489. /*PAN(EDR)+A2DP*/
  2490. static void btc8723b2ant_action_pan_edr_a2dp(struct btc_coexist *btcoexist)
  2491. {
  2492. u8 wifi_rssi_state, bt_rssi_state;
  2493. u32 wifi_bw;
  2494. wifi_rssi_state = btc8723b2ant_wifi_rssi_state(btcoexist,
  2495. 0, 2, 15, 0);
  2496. bt_rssi_state = btc8723b2ant_bt_rssi_state(2, 29, 0);
  2497. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
  2498. btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  2499. if (btc8723b_need_dec_pwr(btcoexist))
  2500. btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
  2501. else
  2502. btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
  2503. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  2504. if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2505. (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2506. btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 12);
  2507. if (BTC_WIFI_BW_HT40 == wifi_bw)
  2508. btc8723b2ant_tdma_duration_adjust(btcoexist, false,
  2509. true, 3);
  2510. else
  2511. btc8723b2ant_tdma_duration_adjust(btcoexist, false,
  2512. false, 3);
  2513. } else {
  2514. btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 7);
  2515. btc8723b2ant_tdma_duration_adjust(btcoexist, false, true, 3);
  2516. }
  2517. /* sw mechanism */
  2518. if (BTC_WIFI_BW_HT40 == wifi_bw) {
  2519. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2520. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2521. btc8723b2ant_sw_mechanism1(btcoexist, true, false,
  2522. false, false);
  2523. btc8723b2ant_sw_mechanism2(btcoexist, true, false,
  2524. false, 0x18);
  2525. } else {
  2526. btc8723b2ant_sw_mechanism1(btcoexist, true, false,
  2527. false, false);
  2528. btc8723b2ant_sw_mechanism2(btcoexist, false, false,
  2529. false, 0x18);
  2530. }
  2531. } else {
  2532. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2533. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2534. btc8723b2ant_sw_mechanism1(btcoexist, false, false,
  2535. false, false);
  2536. btc8723b2ant_sw_mechanism2(btcoexist, true, false,
  2537. false, 0x18);
  2538. } else {
  2539. btc8723b2ant_sw_mechanism1(btcoexist, false, false,
  2540. false, false);
  2541. btc8723b2ant_sw_mechanism2(btcoexist, false, false,
  2542. false, 0x18);
  2543. }
  2544. }
  2545. }
  2546. static void btc8723b2ant_action_pan_edr_hid(struct btc_coexist *btcoexist)
  2547. {
  2548. u8 wifi_rssi_state, bt_rssi_state;
  2549. u32 wifi_bw;
  2550. wifi_rssi_state = btc8723b2ant_wifi_rssi_state(btcoexist,
  2551. 0, 2, 15, 0);
  2552. bt_rssi_state = btc8723b2ant_bt_rssi_state(2, 29, 0);
  2553. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  2554. if (btc8723b_need_dec_pwr(btcoexist))
  2555. btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
  2556. else
  2557. btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
  2558. if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2559. (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2560. if (BTC_WIFI_BW_HT40 == wifi_bw) {
  2561. btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC,
  2562. 3);
  2563. btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 11);
  2564. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1,
  2565. 0xfffff, 0x780);
  2566. } else {
  2567. btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC,
  2568. 6);
  2569. btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 7);
  2570. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1,
  2571. 0xfffff, 0x0);
  2572. }
  2573. btc8723b2ant_tdma_duration_adjust(btcoexist, true, false, 2);
  2574. } else {
  2575. btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  2576. btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 11);
  2577. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff,
  2578. 0x0);
  2579. btc8723b2ant_tdma_duration_adjust(btcoexist, true, true, 2);
  2580. }
  2581. /* sw mechanism */
  2582. if (BTC_WIFI_BW_HT40 == wifi_bw) {
  2583. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2584. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2585. btc8723b2ant_sw_mechanism1(btcoexist, true, true,
  2586. false, false);
  2587. btc8723b2ant_sw_mechanism2(btcoexist, true, false,
  2588. false, 0x18);
  2589. } else {
  2590. btc8723b2ant_sw_mechanism1(btcoexist, true, true,
  2591. false, false);
  2592. btc8723b2ant_sw_mechanism2(btcoexist, false, false,
  2593. false, 0x18);
  2594. }
  2595. } else {
  2596. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2597. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2598. btc8723b2ant_sw_mechanism1(btcoexist, false, true,
  2599. false, false);
  2600. btc8723b2ant_sw_mechanism2(btcoexist, true, false,
  2601. false, 0x18);
  2602. } else {
  2603. btc8723b2ant_sw_mechanism1(btcoexist, false, true,
  2604. false, false);
  2605. btc8723b2ant_sw_mechanism2(btcoexist, false, false,
  2606. false, 0x18);
  2607. }
  2608. }
  2609. }
  2610. /* HID+A2DP+PAN(EDR) */
  2611. static void btc8723b2ant_action_hid_a2dp_pan_edr(struct btc_coexist *btcoexist)
  2612. {
  2613. u8 wifi_rssi_state, bt_rssi_state;
  2614. u32 wifi_bw;
  2615. wifi_rssi_state = btc8723b2ant_wifi_rssi_state(btcoexist,
  2616. 0, 2, 15, 0);
  2617. bt_rssi_state = btc8723b2ant_bt_rssi_state(2, 29, 0);
  2618. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
  2619. btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  2620. if (btc8723b_need_dec_pwr(btcoexist))
  2621. btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
  2622. else
  2623. btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
  2624. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  2625. btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 7);
  2626. if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2627. (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2628. if (BTC_WIFI_BW_HT40 == wifi_bw)
  2629. btc8723b2ant_tdma_duration_adjust(btcoexist, true,
  2630. true, 2);
  2631. else
  2632. btc8723b2ant_tdma_duration_adjust(btcoexist, true,
  2633. false, 3);
  2634. } else {
  2635. btc8723b2ant_tdma_duration_adjust(btcoexist, true, true, 3);
  2636. }
  2637. /* sw mechanism */
  2638. if (BTC_WIFI_BW_HT40 == wifi_bw) {
  2639. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2640. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2641. btc8723b2ant_sw_mechanism1(btcoexist, true, true,
  2642. false, false);
  2643. btc8723b2ant_sw_mechanism2(btcoexist, true, false,
  2644. false, 0x18);
  2645. } else {
  2646. btc8723b2ant_sw_mechanism1(btcoexist, true, true,
  2647. false, false);
  2648. btc8723b2ant_sw_mechanism2(btcoexist, false, false,
  2649. false, 0x18);
  2650. }
  2651. } else {
  2652. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2653. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2654. btc8723b2ant_sw_mechanism1(btcoexist, false, true,
  2655. false, false);
  2656. btc8723b2ant_sw_mechanism2(btcoexist, true, false,
  2657. false, 0x18);
  2658. } else {
  2659. btc8723b2ant_sw_mechanism1(btcoexist, false, true,
  2660. false, false);
  2661. btc8723b2ant_sw_mechanism2(btcoexist, false, false,
  2662. false, 0x18);
  2663. }
  2664. }
  2665. }
  2666. static void btc8723b2ant_action_hid_a2dp(struct btc_coexist *btcoexist)
  2667. {
  2668. u8 wifi_rssi_state, bt_rssi_state;
  2669. u32 wifi_bw;
  2670. wifi_rssi_state = btc8723b2ant_wifi_rssi_state(btcoexist,
  2671. 0, 2, 15, 0);
  2672. bt_rssi_state = btc8723b2ant_bt_rssi_state(2, 29, 0);
  2673. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
  2674. btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  2675. if (btc8723b_need_dec_pwr(btcoexist))
  2676. btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, true);
  2677. else
  2678. btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false);
  2679. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  2680. btc8723b_coex_tbl_type(btcoexist, NORMAL_EXEC, 7);
  2681. if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2682. (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH))
  2683. btc8723b2ant_tdma_duration_adjust(btcoexist, true, false, 2);
  2684. else
  2685. btc8723b2ant_tdma_duration_adjust(btcoexist, true, true, 2);
  2686. /* sw mechanism */
  2687. if (BTC_WIFI_BW_HT40 == wifi_bw) {
  2688. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2689. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2690. btc8723b2ant_sw_mechanism1(btcoexist, true, true,
  2691. false, false);
  2692. btc8723b2ant_sw_mechanism2(btcoexist, true, false,
  2693. false, 0x18);
  2694. } else {
  2695. btc8723b2ant_sw_mechanism1(btcoexist, true, true,
  2696. false, false);
  2697. btc8723b2ant_sw_mechanism2(btcoexist, false, false,
  2698. false, 0x18);
  2699. }
  2700. } else {
  2701. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2702. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2703. btc8723b2ant_sw_mechanism1(btcoexist, false, true,
  2704. false, false);
  2705. btc8723b2ant_sw_mechanism2(btcoexist, true, false,
  2706. false, 0x18);
  2707. } else {
  2708. btc8723b2ant_sw_mechanism1(btcoexist, false, true,
  2709. false, false);
  2710. btc8723b2ant_sw_mechanism2(btcoexist, false, false,
  2711. false, 0x18);
  2712. }
  2713. }
  2714. }
  2715. static void btc8723b2ant_run_coexist_mechanism(struct btc_coexist *btcoexist)
  2716. {
  2717. u8 algorithm = 0;
  2718. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  2719. "[BTCoex], RunCoexistMechanism()===>\n");
  2720. if (btcoexist->manual_control) {
  2721. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  2722. "[BTCoex], RunCoexistMechanism(), "
  2723. "return for Manual CTRL <===\n");
  2724. return;
  2725. }
  2726. if (coex_sta->under_ips) {
  2727. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  2728. "[BTCoex], wifi is under IPS !!!\n");
  2729. return;
  2730. }
  2731. algorithm = btc8723b2ant_action_algorithm(btcoexist);
  2732. if (coex_sta->c2h_bt_inquiry_page &&
  2733. (BT_8723B_2ANT_COEX_ALGO_PANHS != algorithm)) {
  2734. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  2735. "[BTCoex], BT is under inquiry/page scan !!\n");
  2736. btc8723b2ant_action_bt_inquiry(btcoexist);
  2737. return;
  2738. } else {
  2739. if (coex_dm->need_recover_0x948) {
  2740. coex_dm->need_recover_0x948 = false;
  2741. btcoexist->btc_write_2byte(btcoexist, 0x948,
  2742. coex_dm->backup_0x948);
  2743. }
  2744. }
  2745. coex_dm->cur_algorithm = algorithm;
  2746. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, "[BTCoex], Algorithm = %d\n",
  2747. coex_dm->cur_algorithm);
  2748. if (btc8723b2ant_is_common_action(btcoexist)) {
  2749. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  2750. "[BTCoex], Action 2-Ant common.\n");
  2751. coex_dm->auto_tdma_adjust = false;
  2752. } else {
  2753. if (coex_dm->cur_algorithm != coex_dm->pre_algorithm) {
  2754. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  2755. "[BTCoex], preAlgorithm=%d, "
  2756. "curAlgorithm=%d\n", coex_dm->pre_algorithm,
  2757. coex_dm->cur_algorithm);
  2758. coex_dm->auto_tdma_adjust = false;
  2759. }
  2760. switch (coex_dm->cur_algorithm) {
  2761. case BT_8723B_2ANT_COEX_ALGO_SCO:
  2762. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  2763. "[BTCoex], Action 2-Ant, algorithm = SCO.\n");
  2764. btc8723b2ant_action_sco(btcoexist);
  2765. break;
  2766. case BT_8723B_2ANT_COEX_ALGO_HID:
  2767. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  2768. "[BTCoex], Action 2-Ant, algorithm = HID.\n");
  2769. btc8723b2ant_action_hid(btcoexist);
  2770. break;
  2771. case BT_8723B_2ANT_COEX_ALGO_A2DP:
  2772. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  2773. "[BTCoex], Action 2-Ant, "
  2774. "algorithm = A2DP.\n");
  2775. btc8723b2ant_action_a2dp(btcoexist);
  2776. break;
  2777. case BT_8723B_2ANT_COEX_ALGO_A2DP_PANHS:
  2778. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  2779. "[BTCoex], Action 2-Ant, "
  2780. "algorithm = A2DP+PAN(HS).\n");
  2781. btc8723b2ant_action_a2dp_pan_hs(btcoexist);
  2782. break;
  2783. case BT_8723B_2ANT_COEX_ALGO_PANEDR:
  2784. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  2785. "[BTCoex], Action 2-Ant, "
  2786. "algorithm = PAN(EDR).\n");
  2787. btc8723b2ant_action_pan_edr(btcoexist);
  2788. break;
  2789. case BT_8723B_2ANT_COEX_ALGO_PANHS:
  2790. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  2791. "[BTCoex], Action 2-Ant, "
  2792. "algorithm = HS mode.\n");
  2793. btc8723b2ant_action_pan_hs(btcoexist);
  2794. break;
  2795. case BT_8723B_2ANT_COEX_ALGO_PANEDR_A2DP:
  2796. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  2797. "[BTCoex], Action 2-Ant, "
  2798. "algorithm = PAN+A2DP.\n");
  2799. btc8723b2ant_action_pan_edr_a2dp(btcoexist);
  2800. break;
  2801. case BT_8723B_2ANT_COEX_ALGO_PANEDR_HID:
  2802. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  2803. "[BTCoex], Action 2-Ant, "
  2804. "algorithm = PAN(EDR)+HID.\n");
  2805. btc8723b2ant_action_pan_edr_hid(btcoexist);
  2806. break;
  2807. case BT_8723B_2ANT_COEX_ALGO_HID_A2DP_PANEDR:
  2808. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  2809. "[BTCoex], Action 2-Ant, "
  2810. "algorithm = HID+A2DP+PAN.\n");
  2811. btc8723b2ant_action_hid_a2dp_pan_edr(btcoexist);
  2812. break;
  2813. case BT_8723B_2ANT_COEX_ALGO_HID_A2DP:
  2814. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  2815. "[BTCoex], Action 2-Ant, "
  2816. "algorithm = HID+A2DP.\n");
  2817. btc8723b2ant_action_hid_a2dp(btcoexist);
  2818. break;
  2819. default:
  2820. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  2821. "[BTCoex], Action 2-Ant, "
  2822. "algorithm = coexist All Off!!\n");
  2823. btc8723b2ant_coex_alloff(btcoexist);
  2824. break;
  2825. }
  2826. coex_dm->pre_algorithm = coex_dm->cur_algorithm;
  2827. }
  2828. }
  2829. static void btc8723b2ant_wifioff_hwcfg(struct btc_coexist *btcoexist)
  2830. {
  2831. /* set wlan_act to low */
  2832. btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4);
  2833. /* Force GNT_BT to High */
  2834. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x765, 0x18, 0x3);
  2835. /* BT select s0/s1 is controlled by BT */
  2836. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x20, 0x0);
  2837. }
  2838. /*********************************************************************
  2839. * work around function start with wa_btc8723b2ant_
  2840. *********************************************************************/
  2841. /*********************************************************************
  2842. * extern function start with EXbtc8723b2ant_
  2843. *********************************************************************/
  2844. void ex_btc8723b2ant_init_hwconfig(struct btc_coexist *btcoexist)
  2845. {
  2846. u8 u8tmp = 0;
  2847. BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT,
  2848. "[BTCoex], 2Ant Init HW Config!!\n");
  2849. coex_dm->bt_rf0x1e_backup =
  2850. btcoexist->btc_get_rf_reg(btcoexist, BTC_RF_A, 0x1e, 0xfffff);
  2851. /* 0x790[5:0] = 0x5 */
  2852. u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x790);
  2853. u8tmp &= 0xc0;
  2854. u8tmp |= 0x5;
  2855. btcoexist->btc_write_1byte(btcoexist, 0x790, u8tmp);
  2856. /*Antenna config */
  2857. btc8723b2ant_set_ant_path(btcoexist, BTC_ANT_WIFI_AT_MAIN,
  2858. true, false);
  2859. /* PTA parameter */
  2860. btc8723b_coex_tbl_type(btcoexist, FORCE_EXEC, 0);
  2861. /* Enable counter statistics */
  2862. /*0x76e[3] =1, WLAN_Act control by PTA*/
  2863. btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
  2864. btcoexist->btc_write_1byte(btcoexist, 0x778, 0x3);
  2865. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1);
  2866. }
  2867. void ex_btc8723b2ant_init_coex_dm(struct btc_coexist *btcoexist)
  2868. {
  2869. BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT,
  2870. "[BTCoex], Coex Mechanism Init!!\n");
  2871. btc8723b2ant_init_coex_dm(btcoexist);
  2872. }
  2873. void ex_btc8723b2ant_display_coex_info(struct btc_coexist *btcoexist)
  2874. {
  2875. struct btc_board_info *board_info = &btcoexist->board_info;
  2876. struct btc_stack_info *stack_info = &btcoexist->stack_info;
  2877. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  2878. struct rtl_priv *rtlpriv = btcoexist->adapter;
  2879. u8 u8tmp[4], i, bt_info_ext, ps_tdma_case = 0;
  2880. u32 u32tmp[4];
  2881. bool roam = false, scan = false;
  2882. bool link = false, wifi_under_5g = false;
  2883. bool bt_hs_on = false, wifi_busy = false;
  2884. s32 wifi_rssi = 0, bt_hs_rssi = 0;
  2885. u32 wifi_bw, wifi_traffic_dir, fa_ofdm, fa_cck;
  2886. u8 wifi_dot11_chnl, wifi_hs_chnl;
  2887. u32 fw_ver = 0, bt_patch_ver = 0;
  2888. u8 ap_num = 0;
  2889. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2890. "\r\n ============[BT Coexist info]============");
  2891. if (btcoexist->manual_control) {
  2892. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2893. "\r\n ==========[Under Manual Control]============");
  2894. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2895. "\r\n ==========================================");
  2896. }
  2897. if (!board_info->bt_exist) {
  2898. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n BT not exists !!!");
  2899. return;
  2900. }
  2901. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d ",
  2902. "Ant PG number/ Ant mechanism:",
  2903. board_info->pg_ant_num, board_info->btdm_ant_num);
  2904. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %s / %d",
  2905. "BT stack/ hci ext ver",
  2906. ((stack_info->profile_notified) ? "Yes" : "No"),
  2907. stack_info->hci_version);
  2908. btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
  2909. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
  2910. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2911. "\r\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)",
  2912. "CoexVer/ FwVer/ PatchVer",
  2913. glcoex_ver_date_8723b_2ant, glcoex_ver_8723b_2ant,
  2914. fw_ver, bt_patch_ver, bt_patch_ver);
  2915. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  2916. btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_DOT11_CHNL,
  2917. &wifi_dot11_chnl);
  2918. btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_HS_CHNL, &wifi_hs_chnl);
  2919. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d / %d(%d)",
  2920. "Dot11 channel / HsChnl(HsMode)",
  2921. wifi_dot11_chnl, wifi_hs_chnl, bt_hs_on);
  2922. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %02x %02x %02x ",
  2923. "H2C Wifi inform bt chnl Info", coex_dm->wifi_chnl_info[0],
  2924. coex_dm->wifi_chnl_info[1], coex_dm->wifi_chnl_info[2]);
  2925. btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
  2926. btcoexist->btc_get(btcoexist, BTC_GET_S4_HS_RSSI, &bt_hs_rssi);
  2927. btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, &ap_num);
  2928. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d/ %d",
  2929. "Wifi rssi/ HS rssi/ AP#", wifi_rssi, bt_hs_rssi, ap_num);
  2930. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
  2931. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
  2932. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
  2933. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d/ %d ",
  2934. "Wifi link/ roam/ scan", link, roam, scan);
  2935. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  2936. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  2937. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  2938. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION,
  2939. &wifi_traffic_dir);
  2940. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %s / %s/ %s ",
  2941. "Wifi status", (wifi_under_5g ? "5G" : "2.4G"),
  2942. ((BTC_WIFI_BW_LEGACY == wifi_bw) ? "Legacy" :
  2943. (((BTC_WIFI_BW_HT40 == wifi_bw) ? "HT40" : "HT20"))),
  2944. ((!wifi_busy) ? "idle" :
  2945. ((BTC_WIFI_TRAFFIC_TX == wifi_traffic_dir) ?
  2946. "uplink" : "downlink")));
  2947. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d / %d / %d / %d",
  2948. "SCO/HID/PAN/A2DP",
  2949. bt_link_info->sco_exist, bt_link_info->hid_exist,
  2950. bt_link_info->pan_exist, bt_link_info->a2dp_exist);
  2951. btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_BT_LINK_INFO);
  2952. bt_info_ext = coex_sta->bt_info_ext;
  2953. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %s",
  2954. "BT Info A2DP rate",
  2955. (bt_info_ext&BIT0) ? "Basic rate" : "EDR rate");
  2956. for (i = 0; i < BT_INFO_SRC_8723B_2ANT_MAX; i++) {
  2957. if (coex_sta->bt_info_c2h_cnt[i]) {
  2958. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2959. "\r\n %-35s = %02x %02x %02x "
  2960. "%02x %02x %02x %02x(%d)",
  2961. glbt_info_src_8723b_2ant[i],
  2962. coex_sta->bt_info_c2h[i][0],
  2963. coex_sta->bt_info_c2h[i][1],
  2964. coex_sta->bt_info_c2h[i][2],
  2965. coex_sta->bt_info_c2h[i][3],
  2966. coex_sta->bt_info_c2h[i][4],
  2967. coex_sta->bt_info_c2h[i][5],
  2968. coex_sta->bt_info_c2h[i][6],
  2969. coex_sta->bt_info_c2h_cnt[i]);
  2970. }
  2971. }
  2972. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %s/%s",
  2973. "PS state, IPS/LPS",
  2974. ((coex_sta->under_ips ? "IPS ON" : "IPS OFF")),
  2975. ((coex_sta->under_lps ? "LPS ON" : "LPS OFF")));
  2976. btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_FW_PWR_MODE_CMD);
  2977. /* Sw mechanism */
  2978. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2979. "\r\n %-35s", "============[Sw mechanism]============");
  2980. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d/ %d ",
  2981. "SM1[ShRf/ LpRA/ LimDig]", coex_dm->cur_rf_rx_lpf_shrink,
  2982. coex_dm->cur_low_penalty_ra, coex_dm->limited_dig);
  2983. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d/ %d(0x%x) ",
  2984. "SM2[AgcT/ AdcB/ SwDacSwing(lvl)]",
  2985. coex_dm->cur_agc_table_en, coex_dm->cur_adc_back_off,
  2986. coex_dm->cur_dac_swing_on, coex_dm->cur_dac_swing_lvl);
  2987. /* Fw mechanism */
  2988. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s",
  2989. "============[Fw mechanism]============");
  2990. ps_tdma_case = coex_dm->cur_ps_tdma;
  2991. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2992. "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (auto:%d)",
  2993. "PS TDMA", coex_dm->ps_tdma_para[0],
  2994. coex_dm->ps_tdma_para[1], coex_dm->ps_tdma_para[2],
  2995. coex_dm->ps_tdma_para[3], coex_dm->ps_tdma_para[4],
  2996. ps_tdma_case, coex_dm->auto_tdma_adjust);
  2997. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d ",
  2998. "DecBtPwr/ IgnWlanAct", coex_dm->cur_dec_bt_pwr,
  2999. coex_dm->cur_ignore_wlan_act);
  3000. /* Hw setting */
  3001. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s",
  3002. "============[Hw setting]============");
  3003. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x",
  3004. "RF-A, 0x1e initVal", coex_dm->bt_rf0x1e_backup);
  3005. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
  3006. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x880);
  3007. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x",
  3008. "0x778/0x880[29:25]", u8tmp[0],
  3009. (u32tmp[0]&0x3e000000) >> 25);
  3010. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x948);
  3011. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x67);
  3012. u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x765);
  3013. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
  3014. "0x948/ 0x67[5] / 0x765",
  3015. u32tmp[0], ((u8tmp[0]&0x20) >> 5), u8tmp[1]);
  3016. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x92c);
  3017. u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x930);
  3018. u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x944);
  3019. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
  3020. "0x92c[1:0]/ 0x930[7:0]/0x944[1:0]",
  3021. u32tmp[0]&0x3, u32tmp[1]&0xff, u32tmp[2]&0x3);
  3022. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x39);
  3023. u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x40);
  3024. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c);
  3025. u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0x64);
  3026. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  3027. "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
  3028. "0x38[11]/0x40/0x4c[24:23]/0x64[0]",
  3029. ((u8tmp[0] & 0x8)>>3), u8tmp[1],
  3030. ((u32tmp[0]&0x01800000)>>23), u8tmp[2]&0x1);
  3031. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
  3032. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
  3033. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x",
  3034. "0x550(bcn ctrl)/0x522", u32tmp[0], u8tmp[0]);
  3035. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50);
  3036. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x49c);
  3037. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x",
  3038. "0xc50(dig)/0x49c(null-drop)", u32tmp[0]&0xff, u8tmp[0]);
  3039. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xda0);
  3040. u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0xda4);
  3041. u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0xda8);
  3042. u32tmp[3] = btcoexist->btc_read_4byte(btcoexist, 0xcf0);
  3043. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xa5b);
  3044. u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xa5c);
  3045. fa_ofdm = ((u32tmp[0]&0xffff0000) >> 16) +
  3046. ((u32tmp[1]&0xffff0000) >> 16) +
  3047. (u32tmp[1] & 0xffff) +
  3048. (u32tmp[2] & 0xffff) +
  3049. ((u32tmp[3]&0xffff0000) >> 16) +
  3050. (u32tmp[3] & 0xffff);
  3051. fa_cck = (u8tmp[0] << 8) + u8tmp[1];
  3052. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
  3053. "OFDM-CCA/OFDM-FA/CCK-FA",
  3054. u32tmp[0]&0xffff, fa_ofdm, fa_cck);
  3055. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
  3056. u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
  3057. u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
  3058. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x6cc);
  3059. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  3060. "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
  3061. "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)",
  3062. u32tmp[0], u32tmp[1], u32tmp[2], u8tmp[0]);
  3063. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d",
  3064. "0x770(high-pri rx/tx)",
  3065. coex_sta->high_priority_rx, coex_sta->high_priority_tx);
  3066. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d",
  3067. "0x774(low-pri rx/tx)", coex_sta->low_priority_rx,
  3068. coex_sta->low_priority_tx);
  3069. #if (BT_AUTO_REPORT_ONLY_8723B_2ANT == 1)
  3070. btc8723b2ant_monitor_bt_ctr(btcoexist);
  3071. #endif
  3072. btcoexist->btc_disp_dbg_msg(btcoexist,
  3073. BTC_DBG_DISP_COEX_STATISTICS);
  3074. }
  3075. void ex_btc8723b2ant_ips_notify(struct btc_coexist *btcoexist, u8 type)
  3076. {
  3077. if (BTC_IPS_ENTER == type) {
  3078. BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
  3079. "[BTCoex], IPS ENTER notify\n");
  3080. coex_sta->under_ips = true;
  3081. btc8723b2ant_wifioff_hwcfg(btcoexist);
  3082. btc8723b2ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
  3083. btc8723b2ant_coex_alloff(btcoexist);
  3084. } else if (BTC_IPS_LEAVE == type) {
  3085. BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
  3086. "[BTCoex], IPS LEAVE notify\n");
  3087. coex_sta->under_ips = false;
  3088. ex_btc8723b2ant_init_hwconfig(btcoexist);
  3089. btc8723b2ant_init_coex_dm(btcoexist);
  3090. btc8723b2ant_query_bt_info(btcoexist);
  3091. }
  3092. }
  3093. void ex_btc8723b2ant_lps_notify(struct btc_coexist *btcoexist, u8 type)
  3094. {
  3095. if (BTC_LPS_ENABLE == type) {
  3096. BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
  3097. "[BTCoex], LPS ENABLE notify\n");
  3098. coex_sta->under_lps = true;
  3099. } else if (BTC_LPS_DISABLE == type) {
  3100. BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
  3101. "[BTCoex], LPS DISABLE notify\n");
  3102. coex_sta->under_lps = false;
  3103. }
  3104. }
  3105. void ex_btc8723b2ant_scan_notify(struct btc_coexist *btcoexist, u8 type)
  3106. {
  3107. if (BTC_SCAN_START == type)
  3108. BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
  3109. "[BTCoex], SCAN START notify\n");
  3110. else if (BTC_SCAN_FINISH == type)
  3111. BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
  3112. "[BTCoex], SCAN FINISH notify\n");
  3113. }
  3114. void ex_btc8723b2ant_connect_notify(struct btc_coexist *btcoexist, u8 type)
  3115. {
  3116. if (BTC_ASSOCIATE_START == type)
  3117. BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
  3118. "[BTCoex], CONNECT START notify\n");
  3119. else if (BTC_ASSOCIATE_FINISH == type)
  3120. BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
  3121. "[BTCoex], CONNECT FINISH notify\n");
  3122. }
  3123. void ex_btc8723b2ant_media_status_notify(struct btc_coexist *btcoexist,
  3124. u8 type)
  3125. {
  3126. u8 h2c_parameter[3] = {0};
  3127. u32 wifi_bw;
  3128. u8 wifi_central_chnl;
  3129. if (BTC_MEDIA_CONNECT == type)
  3130. BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
  3131. "[BTCoex], MEDIA connect notify\n");
  3132. else
  3133. BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
  3134. "[BTCoex], MEDIA disconnect notify\n");
  3135. /* only 2.4G we need to inform bt the chnl mask */
  3136. btcoexist->btc_get(btcoexist,
  3137. BTC_GET_U1_WIFI_CENTRAL_CHNL, &wifi_central_chnl);
  3138. if ((BTC_MEDIA_CONNECT == type) &&
  3139. (wifi_central_chnl <= 14)) {
  3140. h2c_parameter[0] = 0x1;
  3141. h2c_parameter[1] = wifi_central_chnl;
  3142. btcoexist->btc_get(btcoexist,
  3143. BTC_GET_U4_WIFI_BW, &wifi_bw);
  3144. if (BTC_WIFI_BW_HT40 == wifi_bw)
  3145. h2c_parameter[2] = 0x30;
  3146. else
  3147. h2c_parameter[2] = 0x20;
  3148. }
  3149. coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
  3150. coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
  3151. coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
  3152. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC,
  3153. "[BTCoex], FW write 0x66=0x%x\n",
  3154. h2c_parameter[0] << 16 | h2c_parameter[1] << 8 |
  3155. h2c_parameter[2]);
  3156. btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter);
  3157. }
  3158. void ex_btc8723b2ant_special_packet_notify(struct btc_coexist *btcoexist,
  3159. u8 type)
  3160. {
  3161. if (type == BTC_PACKET_DHCP)
  3162. BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
  3163. "[BTCoex], DHCP Packet notify\n");
  3164. }
  3165. void ex_btc8723b2ant_bt_info_notify(struct btc_coexist *btcoexist,
  3166. u8 *tmpbuf, u8 length)
  3167. {
  3168. u8 bt_info = 0;
  3169. u8 i, rsp_source = 0;
  3170. bool bt_busy = false, limited_dig = false;
  3171. bool wifi_connected = false;
  3172. coex_sta->c2h_bt_info_req_sent = false;
  3173. rsp_source = tmpbuf[0]&0xf;
  3174. if (rsp_source >= BT_INFO_SRC_8723B_2ANT_MAX)
  3175. rsp_source = BT_INFO_SRC_8723B_2ANT_WIFI_FW;
  3176. coex_sta->bt_info_c2h_cnt[rsp_source]++;
  3177. BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
  3178. "[BTCoex], Bt info[%d], length=%d, hex data=[",
  3179. rsp_source, length);
  3180. for (i = 0; i < length; i++) {
  3181. coex_sta->bt_info_c2h[rsp_source][i] = tmpbuf[i];
  3182. if (i == 1)
  3183. bt_info = tmpbuf[i];
  3184. if (i == length-1)
  3185. BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
  3186. "0x%02x]\n", tmpbuf[i]);
  3187. else
  3188. BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
  3189. "0x%02x, ", tmpbuf[i]);
  3190. }
  3191. if (btcoexist->manual_control) {
  3192. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  3193. "[BTCoex], BtInfoNotify(), "
  3194. "return for Manual CTRL<===\n");
  3195. return;
  3196. }
  3197. if (BT_INFO_SRC_8723B_2ANT_WIFI_FW != rsp_source) {
  3198. coex_sta->bt_retry_cnt = /* [3:0]*/
  3199. coex_sta->bt_info_c2h[rsp_source][2] & 0xf;
  3200. coex_sta->bt_rssi =
  3201. coex_sta->bt_info_c2h[rsp_source][3] * 2 + 10;
  3202. coex_sta->bt_info_ext =
  3203. coex_sta->bt_info_c2h[rsp_source][4];
  3204. /* Here we need to resend some wifi info to BT
  3205. because bt is reset and loss of the info.
  3206. */
  3207. if ((coex_sta->bt_info_ext & BIT1)) {
  3208. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  3209. "[BTCoex], BT ext info bit1 check,"
  3210. " send wifi BW&Chnl to BT!!\n");
  3211. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  3212. &wifi_connected);
  3213. if (wifi_connected)
  3214. ex_btc8723b2ant_media_status_notify(
  3215. btcoexist,
  3216. BTC_MEDIA_CONNECT);
  3217. else
  3218. ex_btc8723b2ant_media_status_notify(
  3219. btcoexist,
  3220. BTC_MEDIA_DISCONNECT);
  3221. }
  3222. if ((coex_sta->bt_info_ext & BIT3)) {
  3223. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  3224. "[BTCoex], BT ext info bit3 check, "
  3225. "set BT NOT to ignore Wlan active!!\n");
  3226. btc8723b2ant_ignore_wlan_act(btcoexist, FORCE_EXEC,
  3227. false);
  3228. } else {
  3229. /* BT already NOT ignore Wlan active, do nothing here.*/
  3230. }
  3231. #if (BT_AUTO_REPORT_ONLY_8723B_2ANT == 0)
  3232. if ((coex_sta->bt_info_ext & BIT4)) {
  3233. /* BT auto report already enabled, do nothing*/
  3234. } else {
  3235. btc8723b2ant_bt_auto_report(btcoexist, FORCE_EXEC,
  3236. true);
  3237. }
  3238. #endif
  3239. }
  3240. /* check BIT2 first ==> check if bt is under inquiry or page scan*/
  3241. if (bt_info & BT_INFO_8723B_2ANT_B_INQ_PAGE)
  3242. coex_sta->c2h_bt_inquiry_page = true;
  3243. else
  3244. coex_sta->c2h_bt_inquiry_page = false;
  3245. /* set link exist status*/
  3246. if (!(bt_info & BT_INFO_8723B_2ANT_B_CONNECTION)) {
  3247. coex_sta->bt_link_exist = false;
  3248. coex_sta->pan_exist = false;
  3249. coex_sta->a2dp_exist = false;
  3250. coex_sta->hid_exist = false;
  3251. coex_sta->sco_exist = false;
  3252. } else { /* connection exists */
  3253. coex_sta->bt_link_exist = true;
  3254. if (bt_info & BT_INFO_8723B_2ANT_B_FTP)
  3255. coex_sta->pan_exist = true;
  3256. else
  3257. coex_sta->pan_exist = false;
  3258. if (bt_info & BT_INFO_8723B_2ANT_B_A2DP)
  3259. coex_sta->a2dp_exist = true;
  3260. else
  3261. coex_sta->a2dp_exist = false;
  3262. if (bt_info & BT_INFO_8723B_2ANT_B_HID)
  3263. coex_sta->hid_exist = true;
  3264. else
  3265. coex_sta->hid_exist = false;
  3266. if (bt_info & BT_INFO_8723B_2ANT_B_SCO_ESCO)
  3267. coex_sta->sco_exist = true;
  3268. else
  3269. coex_sta->sco_exist = false;
  3270. }
  3271. btc8723b2ant_update_bt_link_info(btcoexist);
  3272. if (!(bt_info & BT_INFO_8723B_2ANT_B_CONNECTION)) {
  3273. coex_dm->bt_status = BT_8723B_2ANT_BT_STATUS_NON_CONNECTED_IDLE;
  3274. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  3275. "[BTCoex], BtInfoNotify(), "
  3276. "BT Non-Connected idle!!!\n");
  3277. /* connection exists but no busy */
  3278. } else if (bt_info == BT_INFO_8723B_2ANT_B_CONNECTION) {
  3279. coex_dm->bt_status = BT_8723B_2ANT_BT_STATUS_CONNECTED_IDLE;
  3280. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  3281. "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
  3282. } else if ((bt_info & BT_INFO_8723B_2ANT_B_SCO_ESCO) ||
  3283. (bt_info & BT_INFO_8723B_2ANT_B_SCO_BUSY)) {
  3284. coex_dm->bt_status = BT_8723B_2ANT_BT_STATUS_SCO_BUSY;
  3285. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  3286. "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
  3287. } else if (bt_info&BT_INFO_8723B_2ANT_B_ACL_BUSY) {
  3288. coex_dm->bt_status = BT_8723B_2ANT_BT_STATUS_ACL_BUSY;
  3289. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  3290. "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
  3291. } else {
  3292. coex_dm->bt_status = BT_8723B_2ANT_BT_STATUS_MAX;
  3293. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  3294. "[BTCoex], BtInfoNotify(), "
  3295. "BT Non-Defined state!!!\n");
  3296. }
  3297. if ((BT_8723B_2ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
  3298. (BT_8723B_2ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
  3299. (BT_8723B_2ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) {
  3300. bt_busy = true;
  3301. limited_dig = true;
  3302. } else {
  3303. bt_busy = false;
  3304. limited_dig = false;
  3305. }
  3306. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
  3307. coex_dm->limited_dig = limited_dig;
  3308. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_LIMITED_DIG, &limited_dig);
  3309. btc8723b2ant_run_coexist_mechanism(btcoexist);
  3310. }
  3311. void ex_btc8723b2ant_halt_notify(struct btc_coexist *btcoexist)
  3312. {
  3313. BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, "[BTCoex], Halt notify\n");
  3314. btc8723b2ant_wifioff_hwcfg(btcoexist);
  3315. btc8723b2ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
  3316. ex_btc8723b2ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT);
  3317. }
  3318. void ex_btc8723b2ant_periodical(struct btc_coexist *btcoexist)
  3319. {
  3320. struct btc_board_info *board_info = &btcoexist->board_info;
  3321. struct btc_stack_info *stack_info = &btcoexist->stack_info;
  3322. static u8 dis_ver_info_cnt;
  3323. u32 fw_ver = 0, bt_patch_ver = 0;
  3324. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  3325. "[BTCoex], =========================="
  3326. "Periodical===========================\n");
  3327. if (dis_ver_info_cnt <= 5) {
  3328. dis_ver_info_cnt += 1;
  3329. BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT,
  3330. "[BTCoex], ****************************"
  3331. "************************************\n");
  3332. BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT,
  3333. "[BTCoex], Ant PG Num/ Ant Mech/ "
  3334. "Ant Pos = %d/ %d/ %d\n", board_info->pg_ant_num,
  3335. board_info->btdm_ant_num, board_info->btdm_ant_pos);
  3336. BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT,
  3337. "[BTCoex], BT stack/ hci ext ver = %s / %d\n",
  3338. ((stack_info->profile_notified) ? "Yes" : "No"),
  3339. stack_info->hci_version);
  3340. btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER,
  3341. &bt_patch_ver);
  3342. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
  3343. BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT,
  3344. "[BTCoex], CoexVer/ fw_ver/ PatchVer = %d_%x/ 0x%x/ 0x%x(%d)\n",
  3345. glcoex_ver_date_8723b_2ant, glcoex_ver_8723b_2ant,
  3346. fw_ver, bt_patch_ver, bt_patch_ver);
  3347. BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT,
  3348. "[BTCoex], *****************************"
  3349. "***********************************\n");
  3350. }
  3351. #if (BT_AUTO_REPORT_ONLY_8723B_2ANT == 0)
  3352. btc8723b2ant_query_bt_info(btcoexist);
  3353. btc8723b2ant_monitor_bt_ctr(btcoexist);
  3354. btc8723b2ant_monitor_bt_enable_disable(btcoexist);
  3355. #else
  3356. if (btc8723b2ant_is_wifi_status_changed(btcoexist) ||
  3357. coex_dm->auto_tdma_adjust)
  3358. btc8723b2ant_run_coexist_mechanism(btcoexist);
  3359. #endif
  3360. }