halbtc8723b1ant.c 99 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170
  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_1ant glcoex_dm_8723b_1ant;
  42. static struct coex_dm_8723b_1ant *coex_dm = &glcoex_dm_8723b_1ant;
  43. static struct coex_sta_8723b_1ant glcoex_sta_8723b_1ant;
  44. static struct coex_sta_8723b_1ant *coex_sta = &glcoex_sta_8723b_1ant;
  45. static const char *const GLBtInfoSrc8723b1Ant[] = {
  46. "BT Info[wifi fw]",
  47. "BT Info[bt rsp]",
  48. "BT Info[bt auto report]",
  49. };
  50. static u32 glcoex_ver_date_8723b_1ant = 20130918;
  51. static u32 glcoex_ver_8723b_1ant = 0x47;
  52. /***************************************************************
  53. * local function proto type if needed
  54. ***************************************************************/
  55. /***************************************************************
  56. * local function start with halbtc8723b1ant_
  57. ***************************************************************/
  58. static u8 halbtc8723b1ant_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_1ANT) {
  69. bt_rssi_state = BTC_RSSI_STATE_HIGH;
  70. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE,
  71. "[BTCoex], BT Rssi state switch to High\n");
  72. } else {
  73. bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  74. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE,
  75. "[BTCoex], BT Rssi state stay at Low\n");
  76. }
  77. } else {
  78. if (bt_rssi < rssi_thresh) {
  79. bt_rssi_state = BTC_RSSI_STATE_LOW;
  80. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE,
  81. "[BTCoex], BT Rssi state switch to Low\n");
  82. } else {
  83. bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  84. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE,
  85. "[BTCoex], BT Rssi state stay at High\n");
  86. }
  87. }
  88. } else if (level_num == 3) {
  89. if (rssi_thresh > rssi_thresh1) {
  90. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE,
  91. "[BTCoex], BT Rssi thresh error!!\n");
  92. return coex_sta->pre_bt_rssi_state;
  93. }
  94. if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
  95. (coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_STAY_LOW)) {
  96. if (bt_rssi >= rssi_thresh +
  97. BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT) {
  98. bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
  99. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE,
  100. "[BTCoex], BT Rssi state switch to Medium\n");
  101. } else {
  102. bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  103. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE,
  104. "[BTCoex], BT Rssi state stay at Low\n");
  105. }
  106. } else if ((coex_sta->pre_bt_rssi_state ==
  107. BTC_RSSI_STATE_MEDIUM) ||
  108. (coex_sta->pre_bt_rssi_state ==
  109. BTC_RSSI_STATE_STAY_MEDIUM)) {
  110. if (bt_rssi >= rssi_thresh1 +
  111. BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT) {
  112. bt_rssi_state = BTC_RSSI_STATE_HIGH;
  113. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE,
  114. "[BTCoex], BT Rssi state switch to High\n");
  115. } else if (bt_rssi < rssi_thresh) {
  116. bt_rssi_state = BTC_RSSI_STATE_LOW;
  117. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE,
  118. "[BTCoex], BT Rssi state switch to Low\n");
  119. } else {
  120. bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
  121. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE,
  122. "[BTCoex], BT Rssi state stay at Medium\n");
  123. }
  124. } else {
  125. if (bt_rssi < rssi_thresh1) {
  126. bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
  127. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE,
  128. "[BTCoex], BT Rssi state switch to Medium\n");
  129. } else {
  130. bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  131. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE,
  132. "[BTCoex], BT Rssi state stay at High\n");
  133. }
  134. }
  135. }
  136. coex_sta->pre_bt_rssi_state = bt_rssi_state;
  137. return bt_rssi_state;
  138. }
  139. static u8 halbtc8723b1ant_wifi_rssi_state(struct btc_coexist *btcoexist,
  140. u8 index, u8 level_num,
  141. u8 rssi_thresh, u8 rssi_thresh1)
  142. {
  143. s32 wifi_rssi = 0;
  144. u8 wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index];
  145. btcoexist->btc_get(btcoexist,
  146. BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
  147. if (level_num == 2) {
  148. if ((coex_sta->pre_wifi_rssi_state[index] ==
  149. BTC_RSSI_STATE_LOW) ||
  150. (coex_sta->pre_wifi_rssi_state[index] ==
  151. BTC_RSSI_STATE_STAY_LOW)) {
  152. if (wifi_rssi >= rssi_thresh +
  153. BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT) {
  154. wifi_rssi_state = BTC_RSSI_STATE_HIGH;
  155. BTC_PRINT(BTC_MSG_ALGORITHM,
  156. ALGO_WIFI_RSSI_STATE,
  157. "[BTCoex], wifi RSSI state switch to High\n");
  158. } else {
  159. wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  160. BTC_PRINT(BTC_MSG_ALGORITHM,
  161. ALGO_WIFI_RSSI_STATE,
  162. "[BTCoex], wifi RSSI state stay at Low\n");
  163. }
  164. } else {
  165. if (wifi_rssi < rssi_thresh) {
  166. wifi_rssi_state = BTC_RSSI_STATE_LOW;
  167. BTC_PRINT(BTC_MSG_ALGORITHM,
  168. ALGO_WIFI_RSSI_STATE,
  169. "[BTCoex], wifi RSSI state switch to Low\n");
  170. } else {
  171. wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  172. BTC_PRINT(BTC_MSG_ALGORITHM,
  173. ALGO_WIFI_RSSI_STATE,
  174. "[BTCoex], wifi RSSI state stay at High\n");
  175. }
  176. }
  177. } else if (level_num == 3) {
  178. if (rssi_thresh > rssi_thresh1) {
  179. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE,
  180. "[BTCoex], wifi RSSI thresh error!!\n");
  181. return coex_sta->pre_wifi_rssi_state[index];
  182. }
  183. if ((coex_sta->pre_wifi_rssi_state[index] ==
  184. BTC_RSSI_STATE_LOW) ||
  185. (coex_sta->pre_wifi_rssi_state[index] ==
  186. BTC_RSSI_STATE_STAY_LOW)) {
  187. if (wifi_rssi >= rssi_thresh +
  188. BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT) {
  189. wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
  190. BTC_PRINT(BTC_MSG_ALGORITHM,
  191. ALGO_WIFI_RSSI_STATE,
  192. "[BTCoex], wifi RSSI state switch to Medium\n");
  193. } else {
  194. wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  195. BTC_PRINT(BTC_MSG_ALGORITHM,
  196. ALGO_WIFI_RSSI_STATE,
  197. "[BTCoex], wifi RSSI state stay at Low\n");
  198. }
  199. } else if ((coex_sta->pre_wifi_rssi_state[index] ==
  200. BTC_RSSI_STATE_MEDIUM) ||
  201. (coex_sta->pre_wifi_rssi_state[index] ==
  202. BTC_RSSI_STATE_STAY_MEDIUM)) {
  203. if (wifi_rssi >= rssi_thresh1 +
  204. BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT) {
  205. wifi_rssi_state = BTC_RSSI_STATE_HIGH;
  206. BTC_PRINT(BTC_MSG_ALGORITHM,
  207. ALGO_WIFI_RSSI_STATE,
  208. "[BTCoex], wifi RSSI state switch to High\n");
  209. } else if (wifi_rssi < rssi_thresh) {
  210. wifi_rssi_state = BTC_RSSI_STATE_LOW;
  211. BTC_PRINT(BTC_MSG_ALGORITHM,
  212. ALGO_WIFI_RSSI_STATE,
  213. "[BTCoex], wifi RSSI state switch to Low\n");
  214. } else {
  215. wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
  216. BTC_PRINT(BTC_MSG_ALGORITHM,
  217. ALGO_WIFI_RSSI_STATE,
  218. "[BTCoex], wifi RSSI state stay at Medium\n");
  219. }
  220. } else {
  221. if (wifi_rssi < rssi_thresh1) {
  222. wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
  223. BTC_PRINT(BTC_MSG_ALGORITHM,
  224. ALGO_WIFI_RSSI_STATE,
  225. "[BTCoex], wifi RSSI state switch to Medium\n");
  226. } else {
  227. wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  228. BTC_PRINT(BTC_MSG_ALGORITHM,
  229. ALGO_WIFI_RSSI_STATE,
  230. "[BTCoex], wifi RSSI state stay at High\n");
  231. }
  232. }
  233. }
  234. coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state;
  235. return wifi_rssi_state;
  236. }
  237. static void halbtc8723b1ant_updatera_mask(struct btc_coexist *btcoexist,
  238. bool force_exec, u32 dis_rate_mask)
  239. {
  240. coex_dm->curra_mask = dis_rate_mask;
  241. if (force_exec || (coex_dm->prera_mask != coex_dm->curra_mask))
  242. btcoexist->btc_set(btcoexist, BTC_SET_ACT_UPDATE_ra_mask,
  243. &coex_dm->curra_mask);
  244. coex_dm->prera_mask = coex_dm->curra_mask;
  245. }
  246. static void btc8723b1ant_auto_rate_fb_retry(struct btc_coexist *btcoexist,
  247. bool force_exec, u8 type)
  248. {
  249. bool wifi_under_bmode = false;
  250. coex_dm->cur_arfr_type = type;
  251. if (force_exec || (coex_dm->pre_arfr_type != coex_dm->cur_arfr_type)) {
  252. switch (coex_dm->cur_arfr_type) {
  253. case 0: /* normal mode */
  254. btcoexist->btc_write_4byte(btcoexist, 0x430,
  255. coex_dm->backup_arfr_cnt1);
  256. btcoexist->btc_write_4byte(btcoexist, 0x434,
  257. coex_dm->backup_arfr_cnt2);
  258. break;
  259. case 1:
  260. btcoexist->btc_get(btcoexist,
  261. BTC_GET_BL_WIFI_UNDER_B_MODE,
  262. &wifi_under_bmode);
  263. if (wifi_under_bmode) {
  264. btcoexist->btc_write_4byte(btcoexist,
  265. 0x430, 0x0);
  266. btcoexist->btc_write_4byte(btcoexist,
  267. 0x434, 0x01010101);
  268. } else {
  269. btcoexist->btc_write_4byte(btcoexist,
  270. 0x430, 0x0);
  271. btcoexist->btc_write_4byte(btcoexist,
  272. 0x434, 0x04030201);
  273. }
  274. break;
  275. default:
  276. break;
  277. }
  278. }
  279. coex_dm->pre_arfr_type = coex_dm->cur_arfr_type;
  280. }
  281. static void halbtc8723b1ant_retry_limit(struct btc_coexist *btcoexist,
  282. bool force_exec, u8 type)
  283. {
  284. coex_dm->cur_retry_limit_type = type;
  285. if (force_exec || (coex_dm->pre_retry_limit_type !=
  286. coex_dm->cur_retry_limit_type)) {
  287. switch (coex_dm->cur_retry_limit_type) {
  288. case 0: /* normal mode */
  289. btcoexist->btc_write_2byte(btcoexist, 0x42a,
  290. coex_dm->backup_retry_limit);
  291. break;
  292. case 1: /* retry limit = 8 */
  293. btcoexist->btc_write_2byte(btcoexist, 0x42a, 0x0808);
  294. break;
  295. default:
  296. break;
  297. }
  298. }
  299. coex_dm->pre_retry_limit_type = coex_dm->cur_retry_limit_type;
  300. }
  301. static void halbtc8723b1ant_ampdu_maxtime(struct btc_coexist *btcoexist,
  302. bool force_exec, u8 type)
  303. {
  304. coex_dm->cur_ampdu_time_type = type;
  305. if (force_exec || (coex_dm->pre_ampdu_time_type !=
  306. coex_dm->cur_ampdu_time_type)) {
  307. switch (coex_dm->cur_ampdu_time_type) {
  308. case 0: /* normal mode */
  309. btcoexist->btc_write_1byte(btcoexist, 0x456,
  310. coex_dm->backup_ampdu_max_time);
  311. break;
  312. case 1: /* AMPDU timw = 0x38 * 32us */
  313. btcoexist->btc_write_1byte(btcoexist,
  314. 0x456, 0x38);
  315. break;
  316. default:
  317. break;
  318. }
  319. }
  320. coex_dm->pre_ampdu_time_type = coex_dm->cur_ampdu_time_type;
  321. }
  322. static void halbtc8723b1ant_limited_tx(struct btc_coexist *btcoexist,
  323. bool force_exec, u8 ra_masktype,
  324. u8 arfr_type, u8 retry_limit_type,
  325. u8 ampdu_time_type)
  326. {
  327. switch (ra_masktype) {
  328. case 0: /* normal mode */
  329. halbtc8723b1ant_updatera_mask(btcoexist, force_exec, 0x0);
  330. break;
  331. case 1: /* disable cck 1/2 */
  332. halbtc8723b1ant_updatera_mask(btcoexist, force_exec,
  333. 0x00000003);
  334. break;
  335. /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4*/
  336. case 2:
  337. halbtc8723b1ant_updatera_mask(btcoexist, force_exec,
  338. 0x0001f1f7);
  339. break;
  340. default:
  341. break;
  342. }
  343. btc8723b1ant_auto_rate_fb_retry(btcoexist, force_exec, arfr_type);
  344. halbtc8723b1ant_retry_limit(btcoexist, force_exec, retry_limit_type);
  345. halbtc8723b1ant_ampdu_maxtime(btcoexist, force_exec, ampdu_time_type);
  346. }
  347. static void halbtc8723b1ant_limited_rx(struct btc_coexist *btcoexist,
  348. bool force_exec, bool rej_ap_agg_pkt,
  349. bool bt_ctrl_agg_buf_size,
  350. u8 agg_buf_size)
  351. {
  352. bool reject_rx_agg = rej_ap_agg_pkt;
  353. bool bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size;
  354. u8 rxaggsize = agg_buf_size;
  355. /**********************************************
  356. * Rx Aggregation related setting
  357. **********************************************/
  358. btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT,
  359. &reject_rx_agg);
  360. /* decide BT control aggregation buf size or not */
  361. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE,
  362. &bt_ctrl_rx_agg_size);
  363. /* aggregation buf size, only work
  364. * when BT control Rx aggregation size.
  365. */
  366. btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rxaggsize);
  367. /* real update aggregation setting */
  368. btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
  369. }
  370. static void halbtc8723b1ant_monitor_bt_ctr(struct btc_coexist *btcoexist)
  371. {
  372. u32 reg_hp_txrx, reg_lp_txrx, u32tmp;
  373. u32 reg_hp_tx = 0, reg_hp_rx = 0;
  374. u32 reg_lp_tx = 0, reg_lp_rx = 0;
  375. reg_hp_txrx = 0x770;
  376. reg_lp_txrx = 0x774;
  377. u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx);
  378. reg_hp_tx = u32tmp & MASKLWORD;
  379. reg_hp_rx = (u32tmp & MASKHWORD) >> 16;
  380. u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx);
  381. reg_lp_tx = u32tmp & MASKLWORD;
  382. reg_lp_rx = (u32tmp & MASKHWORD) >> 16;
  383. coex_sta->high_priority_tx = reg_hp_tx;
  384. coex_sta->high_priority_rx = reg_hp_rx;
  385. coex_sta->low_priority_tx = reg_lp_tx;
  386. coex_sta->low_priority_rx = reg_lp_rx;
  387. /* reset counter */
  388. btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
  389. }
  390. static void halbtc8723b1ant_query_bt_info(struct btc_coexist *btcoexist)
  391. {
  392. u8 h2c_parameter[1] = {0};
  393. coex_sta->c2h_bt_info_req_sent = true;
  394. h2c_parameter[0] |= BIT0; /* trigger*/
  395. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC,
  396. "[BTCoex], Query Bt Info, FW write 0x61 = 0x%x\n",
  397. h2c_parameter[0]);
  398. btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter);
  399. }
  400. static bool btc8723b1ant_is_wifi_status_changed(struct btc_coexist *btcoexist)
  401. {
  402. static bool pre_wifi_busy;
  403. static bool pre_under_4way, pre_bt_hs_on;
  404. bool wifi_busy = false, under_4way = false, bt_hs_on = false;
  405. bool wifi_connected = false;
  406. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  407. &wifi_connected);
  408. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  409. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  410. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
  411. &under_4way);
  412. if (wifi_connected) {
  413. if (wifi_busy != pre_wifi_busy) {
  414. pre_wifi_busy = wifi_busy;
  415. return true;
  416. }
  417. if (under_4way != pre_under_4way) {
  418. pre_under_4way = under_4way;
  419. return true;
  420. }
  421. if (bt_hs_on != pre_bt_hs_on) {
  422. pre_bt_hs_on = bt_hs_on;
  423. return true;
  424. }
  425. }
  426. return false;
  427. }
  428. static void halbtc8723b1ant_update_bt_link_info(struct btc_coexist *btcoexist)
  429. {
  430. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  431. bool bt_hs_on = false;
  432. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  433. bt_link_info->bt_link_exist = coex_sta->bt_link_exist;
  434. bt_link_info->sco_exist = coex_sta->sco_exist;
  435. bt_link_info->a2dp_exist = coex_sta->a2dp_exist;
  436. bt_link_info->pan_exist = coex_sta->pan_exist;
  437. bt_link_info->hid_exist = coex_sta->hid_exist;
  438. /* work around for HS mode. */
  439. if (bt_hs_on) {
  440. bt_link_info->pan_exist = true;
  441. bt_link_info->bt_link_exist = true;
  442. }
  443. /* check if Sco only */
  444. if (bt_link_info->sco_exist && !bt_link_info->a2dp_exist &&
  445. !bt_link_info->pan_exist && !bt_link_info->hid_exist)
  446. bt_link_info->sco_only = true;
  447. else
  448. bt_link_info->sco_only = false;
  449. /* check if A2dp only */
  450. if (!bt_link_info->sco_exist && bt_link_info->a2dp_exist &&
  451. !bt_link_info->pan_exist && !bt_link_info->hid_exist)
  452. bt_link_info->a2dp_only = true;
  453. else
  454. bt_link_info->a2dp_only = false;
  455. /* check if Pan only */
  456. if (!bt_link_info->sco_exist && !bt_link_info->a2dp_exist &&
  457. bt_link_info->pan_exist && !bt_link_info->hid_exist)
  458. bt_link_info->pan_only = true;
  459. else
  460. bt_link_info->pan_only = false;
  461. /* check if Hid only */
  462. if (!bt_link_info->sco_exist && !bt_link_info->a2dp_exist &&
  463. !bt_link_info->pan_exist && bt_link_info->hid_exist)
  464. bt_link_info->hid_only = true;
  465. else
  466. bt_link_info->hid_only = false;
  467. }
  468. static u8 halbtc8723b1ant_action_algorithm(struct btc_coexist *btcoexist)
  469. {
  470. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  471. bool bt_hs_on = false;
  472. u8 algorithm = BT_8723B_1ANT_COEX_ALGO_UNDEFINED;
  473. u8 numdiffprofile = 0;
  474. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  475. if (!bt_link_info->bt_link_exist) {
  476. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  477. "[BTCoex], No BT link exists!!!\n");
  478. return algorithm;
  479. }
  480. if (bt_link_info->sco_exist)
  481. numdiffprofile++;
  482. if (bt_link_info->hid_exist)
  483. numdiffprofile++;
  484. if (bt_link_info->pan_exist)
  485. numdiffprofile++;
  486. if (bt_link_info->a2dp_exist)
  487. numdiffprofile++;
  488. if (numdiffprofile == 1) {
  489. if (bt_link_info->sco_exist) {
  490. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  491. "[BTCoex], BT Profile = SCO only\n");
  492. algorithm = BT_8723B_1ANT_COEX_ALGO_SCO;
  493. } else {
  494. if (bt_link_info->hid_exist) {
  495. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  496. "[BTCoex], BT Profile = HID only\n");
  497. algorithm = BT_8723B_1ANT_COEX_ALGO_HID;
  498. } else if (bt_link_info->a2dp_exist) {
  499. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  500. "[BTCoex], BT Profile = A2DP only\n");
  501. algorithm = BT_8723B_1ANT_COEX_ALGO_A2DP;
  502. } else if (bt_link_info->pan_exist) {
  503. if (bt_hs_on) {
  504. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  505. "[BTCoex], BT Profile = PAN(HS) only\n");
  506. algorithm =
  507. BT_8723B_1ANT_COEX_ALGO_PANHS;
  508. } else {
  509. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  510. "[BTCoex], BT Profile = PAN(EDR) only\n");
  511. algorithm =
  512. BT_8723B_1ANT_COEX_ALGO_PANEDR;
  513. }
  514. }
  515. }
  516. } else if (numdiffprofile == 2) {
  517. if (bt_link_info->sco_exist) {
  518. if (bt_link_info->hid_exist) {
  519. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  520. "[BTCoex], BT Profile = SCO + HID\n");
  521. algorithm = BT_8723B_1ANT_COEX_ALGO_HID;
  522. } else if (bt_link_info->a2dp_exist) {
  523. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  524. "[BTCoex], BT Profile = SCO + A2DP ==> SCO\n");
  525. algorithm = BT_8723B_1ANT_COEX_ALGO_SCO;
  526. } else if (bt_link_info->pan_exist) {
  527. if (bt_hs_on) {
  528. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  529. "[BTCoex], BT Profile = SCO + PAN(HS)\n");
  530. algorithm = BT_8723B_1ANT_COEX_ALGO_SCO;
  531. } else {
  532. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  533. "[BTCoex], BT Profile = SCO + PAN(EDR)\n");
  534. algorithm =
  535. BT_8723B_1ANT_COEX_ALGO_PANEDR_HID;
  536. }
  537. }
  538. } else {
  539. if (bt_link_info->hid_exist &&
  540. bt_link_info->a2dp_exist) {
  541. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  542. "[BTCoex], BT Profile = HID + A2DP\n");
  543. algorithm = BT_8723B_1ANT_COEX_ALGO_HID_A2DP;
  544. } else if (bt_link_info->hid_exist &&
  545. bt_link_info->pan_exist) {
  546. if (bt_hs_on) {
  547. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  548. "[BTCoex], BT Profile = HID + PAN(HS)\n");
  549. algorithm =
  550. BT_8723B_1ANT_COEX_ALGO_HID_A2DP;
  551. } else {
  552. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  553. "[BTCoex], BT Profile = HID + PAN(EDR)\n");
  554. algorithm =
  555. BT_8723B_1ANT_COEX_ALGO_PANEDR_HID;
  556. }
  557. } else if (bt_link_info->pan_exist &&
  558. bt_link_info->a2dp_exist) {
  559. if (bt_hs_on) {
  560. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  561. "[BTCoex], BT Profile = A2DP + PAN(HS)\n");
  562. algorithm =
  563. BT_8723B_1ANT_COEX_ALGO_A2DP_PANHS;
  564. } else {
  565. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  566. "[BTCoex], BT Profile = A2DP + PAN(EDR)\n");
  567. algorithm =
  568. BT_8723B_1ANT_COEX_ALGO_PANEDR_A2DP;
  569. }
  570. }
  571. }
  572. } else if (numdiffprofile == 3) {
  573. if (bt_link_info->sco_exist) {
  574. if (bt_link_info->hid_exist &&
  575. bt_link_info->a2dp_exist) {
  576. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  577. "[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n");
  578. algorithm = BT_8723B_1ANT_COEX_ALGO_HID;
  579. } else if (bt_link_info->hid_exist &&
  580. bt_link_info->pan_exist) {
  581. if (bt_hs_on) {
  582. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  583. "[BTCoex], BT Profile = SCO + HID + PAN(HS)\n");
  584. algorithm =
  585. BT_8723B_1ANT_COEX_ALGO_HID_A2DP;
  586. } else {
  587. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  588. "[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n");
  589. algorithm =
  590. BT_8723B_1ANT_COEX_ALGO_PANEDR_HID;
  591. }
  592. } else if (bt_link_info->pan_exist &&
  593. bt_link_info->a2dp_exist) {
  594. if (bt_hs_on) {
  595. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  596. "[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n");
  597. algorithm = BT_8723B_1ANT_COEX_ALGO_SCO;
  598. } else {
  599. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  600. "[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n");
  601. algorithm =
  602. BT_8723B_1ANT_COEX_ALGO_PANEDR_HID;
  603. }
  604. }
  605. } else {
  606. if (bt_link_info->hid_exist &&
  607. bt_link_info->pan_exist &&
  608. bt_link_info->a2dp_exist) {
  609. if (bt_hs_on) {
  610. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  611. "[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n");
  612. algorithm =
  613. BT_8723B_1ANT_COEX_ALGO_HID_A2DP;
  614. } else {
  615. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  616. "[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n");
  617. algorithm =
  618. BT_8723B_1ANT_COEX_ALGO_HID_A2DP_PANEDR;
  619. }
  620. }
  621. }
  622. } else if (numdiffprofile >= 3) {
  623. if (bt_link_info->sco_exist) {
  624. if (bt_link_info->hid_exist &&
  625. bt_link_info->pan_exist &&
  626. bt_link_info->a2dp_exist) {
  627. if (bt_hs_on) {
  628. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  629. "[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n");
  630. } else {
  631. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  632. "[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n");
  633. algorithm =
  634. BT_8723B_1ANT_COEX_ALGO_PANEDR_HID;
  635. }
  636. }
  637. }
  638. }
  639. return algorithm;
  640. }
  641. static void btc8723b1ant_set_sw_pen_tx_rate_adapt(struct btc_coexist *btcoexist,
  642. bool low_penalty_ra)
  643. {
  644. u8 h2c_parameter[6] = {0};
  645. h2c_parameter[0] = 0x6; /* opCode, 0x6= Retry_Penalty */
  646. if (low_penalty_ra) {
  647. h2c_parameter[1] |= BIT0;
  648. /*normal rate except MCS7/6/5, OFDM54/48/36 */
  649. h2c_parameter[2] = 0x00;
  650. h2c_parameter[3] = 0xf7; /*MCS7 or OFDM54 */
  651. h2c_parameter[4] = 0xf8; /*MCS6 or OFDM48 */
  652. h2c_parameter[5] = 0xf9; /*MCS5 or OFDM36 */
  653. }
  654. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC,
  655. "[BTCoex], set WiFi Low-Penalty Retry: %s",
  656. (low_penalty_ra ? "ON!!" : "OFF!!"));
  657. btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, h2c_parameter);
  658. }
  659. static void halbtc8723b1ant_low_penalty_ra(struct btc_coexist *btcoexist,
  660. bool force_exec, bool low_penalty_ra)
  661. {
  662. coex_dm->cur_low_penalty_ra = low_penalty_ra;
  663. if (!force_exec) {
  664. if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra)
  665. return;
  666. }
  667. btc8723b1ant_set_sw_pen_tx_rate_adapt(btcoexist,
  668. coex_dm->cur_low_penalty_ra);
  669. coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra;
  670. }
  671. static void halbtc8723b1ant_set_coex_table(struct btc_coexist *btcoexist,
  672. u32 val0x6c0, u32 val0x6c4,
  673. u32 val0x6c8, u8 val0x6cc)
  674. {
  675. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC,
  676. "[BTCoex], set coex table, set 0x6c0 = 0x%x\n", val0x6c0);
  677. btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0);
  678. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC,
  679. "[BTCoex], set coex table, set 0x6c4 = 0x%x\n", val0x6c4);
  680. btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4);
  681. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC,
  682. "[BTCoex], set coex table, set 0x6c8 = 0x%x\n", val0x6c8);
  683. btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8);
  684. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC,
  685. "[BTCoex], set coex table, set 0x6cc = 0x%x\n", val0x6cc);
  686. btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc);
  687. }
  688. static void halbtc8723b1ant_coex_table(struct btc_coexist *btcoexist,
  689. bool force_exec, u32 val0x6c0,
  690. u32 val0x6c4, u32 val0x6c8,
  691. u8 val0x6cc)
  692. {
  693. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW,
  694. "[BTCoex], %s write Coex Table 0x6c0 = 0x%x, 0x6c4 = 0x%x, 0x6cc = 0x%x\n",
  695. (force_exec ? "force to" : ""),
  696. val0x6c0, val0x6c4, val0x6cc);
  697. coex_dm->cur_val0x6c0 = val0x6c0;
  698. coex_dm->cur_val0x6c4 = val0x6c4;
  699. coex_dm->cur_val0x6c8 = val0x6c8;
  700. coex_dm->cur_val0x6cc = val0x6cc;
  701. if (!force_exec) {
  702. if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) &&
  703. (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) &&
  704. (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) &&
  705. (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc))
  706. return;
  707. }
  708. halbtc8723b1ant_set_coex_table(btcoexist, val0x6c0, val0x6c4,
  709. val0x6c8, val0x6cc);
  710. coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0;
  711. coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4;
  712. coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8;
  713. coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc;
  714. }
  715. static void halbtc8723b1ant_coex_table_with_type(struct btc_coexist *btcoexist,
  716. bool force_exec, u8 type)
  717. {
  718. switch (type) {
  719. case 0:
  720. halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x55555555,
  721. 0x55555555, 0xffffff, 0x3);
  722. break;
  723. case 1:
  724. halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x55555555,
  725. 0x5a5a5a5a, 0xffffff, 0x3);
  726. break;
  727. case 2:
  728. halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x5a5a5a5a,
  729. 0x5a5a5a5a, 0xffffff, 0x3);
  730. break;
  731. case 3:
  732. halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x55555555,
  733. 0xaaaaaaaa, 0xffffff, 0x3);
  734. break;
  735. case 4:
  736. halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x55555555,
  737. 0x5aaa5aaa, 0xffffff, 0x3);
  738. break;
  739. case 5:
  740. halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x5a5a5a5a,
  741. 0xaaaa5a5a, 0xffffff, 0x3);
  742. break;
  743. case 6:
  744. halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x55555555,
  745. 0xaaaa5a5a, 0xffffff, 0x3);
  746. break;
  747. case 7:
  748. halbtc8723b1ant_coex_table(btcoexist, force_exec, 0xaaaaaaaa,
  749. 0xaaaaaaaa, 0xffffff, 0x3);
  750. break;
  751. default:
  752. break;
  753. }
  754. }
  755. static void halbtc8723b1ant_SetFwIgnoreWlanAct(struct btc_coexist *btcoexist,
  756. bool enable)
  757. {
  758. u8 h2c_parameter[1] = {0};
  759. if (enable)
  760. h2c_parameter[0] |= BIT0; /* function enable */
  761. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC,
  762. "[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63 = 0x%x\n",
  763. h2c_parameter[0]);
  764. btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter);
  765. }
  766. static void halbtc8723b1ant_ignore_wlan_act(struct btc_coexist *btcoexist,
  767. bool force_exec, bool enable)
  768. {
  769. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW,
  770. "[BTCoex], %s turn Ignore WlanAct %s\n",
  771. (force_exec ? "force to" : ""), (enable ? "ON" : "OFF"));
  772. coex_dm->cur_ignore_wlan_act = enable;
  773. if (!force_exec) {
  774. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
  775. "[BTCoex], bPreIgnoreWlanAct = %d, bCurIgnoreWlanAct = %d!!\n",
  776. coex_dm->pre_ignore_wlan_act,
  777. coex_dm->cur_ignore_wlan_act);
  778. if (coex_dm->pre_ignore_wlan_act ==
  779. coex_dm->cur_ignore_wlan_act)
  780. return;
  781. }
  782. halbtc8723b1ant_SetFwIgnoreWlanAct(btcoexist, enable);
  783. coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act;
  784. }
  785. static void halbtc8723b1ant_set_fw_ps_tdma(struct btc_coexist *btcoexist,
  786. u8 byte1, u8 byte2, u8 byte3,
  787. u8 byte4, u8 byte5)
  788. {
  789. u8 h2c_parameter[5] = {0};
  790. u8 real_byte1 = byte1, real_byte5 = byte5;
  791. bool ap_enable = false;
  792. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
  793. &ap_enable);
  794. if (ap_enable) {
  795. if ((byte1 & BIT4) && !(byte1 & BIT5)) {
  796. BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
  797. "[BTCoex], FW for 1Ant AP mode\n");
  798. real_byte1 &= ~BIT4;
  799. real_byte1 |= BIT5;
  800. real_byte5 |= BIT5;
  801. real_byte5 &= ~BIT6;
  802. }
  803. }
  804. h2c_parameter[0] = real_byte1;
  805. h2c_parameter[1] = byte2;
  806. h2c_parameter[2] = byte3;
  807. h2c_parameter[3] = byte4;
  808. h2c_parameter[4] = real_byte5;
  809. coex_dm->ps_tdma_para[0] = real_byte1;
  810. coex_dm->ps_tdma_para[1] = byte2;
  811. coex_dm->ps_tdma_para[2] = byte3;
  812. coex_dm->ps_tdma_para[3] = byte4;
  813. coex_dm->ps_tdma_para[4] = real_byte5;
  814. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC,
  815. "[BTCoex], PS-TDMA H2C cmd =0x%x%08x\n",
  816. h2c_parameter[0],
  817. h2c_parameter[1] << 24 |
  818. h2c_parameter[2] << 16 |
  819. h2c_parameter[3] << 8 |
  820. h2c_parameter[4]);
  821. btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter);
  822. }
  823. static void halbtc8723b1ant_set_lps_rpwm(struct btc_coexist *btcoexist,
  824. u8 lps_val, u8 rpwm_val)
  825. {
  826. u8 lps = lps_val;
  827. u8 rpwm = rpwm_val;
  828. btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps);
  829. btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
  830. }
  831. static void halbtc8723b1ant_LpsRpwm(struct btc_coexist *btcoexist,
  832. bool force_exec,
  833. u8 lps_val, u8 rpwm_val)
  834. {
  835. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW,
  836. "[BTCoex], %s set lps/rpwm = 0x%x/0x%x\n",
  837. (force_exec ? "force to" : ""), lps_val, rpwm_val);
  838. coex_dm->cur_lps = lps_val;
  839. coex_dm->cur_rpwm = rpwm_val;
  840. if (!force_exec) {
  841. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
  842. "[BTCoex], LPS-RxBeaconMode = 0x%x , LPS-RPWM = 0x%x!!\n",
  843. coex_dm->cur_lps, coex_dm->cur_rpwm);
  844. if ((coex_dm->pre_lps == coex_dm->cur_lps) &&
  845. (coex_dm->pre_rpwm == coex_dm->cur_rpwm)) {
  846. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
  847. "[BTCoex], LPS-RPWM_Last = 0x%x , LPS-RPWM_Now = 0x%x!!\n",
  848. coex_dm->pre_rpwm, coex_dm->cur_rpwm);
  849. return;
  850. }
  851. }
  852. halbtc8723b1ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val);
  853. coex_dm->pre_lps = coex_dm->cur_lps;
  854. coex_dm->pre_rpwm = coex_dm->cur_rpwm;
  855. }
  856. static void halbtc8723b1ant_sw_mechanism(struct btc_coexist *btcoexist,
  857. bool low_penalty_ra)
  858. {
  859. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR,
  860. "[BTCoex], SM[LpRA] = %d\n", low_penalty_ra);
  861. halbtc8723b1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra);
  862. }
  863. static void halbtc8723b1ant_SetAntPath(struct btc_coexist *btcoexist,
  864. u8 ant_pos_type, bool init_hw_cfg,
  865. bool wifi_off)
  866. {
  867. struct btc_board_info *board_info = &btcoexist->board_info;
  868. u32 fw_ver = 0, u32tmp = 0;
  869. bool pg_ext_switch = false;
  870. bool use_ext_switch = false;
  871. u8 h2c_parameter[2] = {0};
  872. btcoexist->btc_get(btcoexist, BTC_GET_BL_EXT_SWITCH, &pg_ext_switch);
  873. /* [31:16] = fw ver, [15:0] = fw sub ver */
  874. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
  875. if ((fw_ver < 0xc0000) || pg_ext_switch)
  876. use_ext_switch = true;
  877. if (init_hw_cfg) {
  878. /*BT select s0/s1 is controlled by WiFi */
  879. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x20, 0x1);
  880. /*Force GNT_BT to Normal */
  881. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x765, 0x18, 0x0);
  882. } else if (wifi_off) {
  883. /*Force GNT_BT to High */
  884. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x765, 0x18, 0x3);
  885. /*BT select s0/s1 is controlled by BT */
  886. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x20, 0x0);
  887. /* 0x4c[24:23] = 00, Set Antenna control by BT_RFE_CTRL
  888. * BT Vendor 0xac = 0xf002
  889. */
  890. u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
  891. u32tmp &= ~BIT23;
  892. u32tmp &= ~BIT24;
  893. btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp);
  894. }
  895. if (use_ext_switch) {
  896. if (init_hw_cfg) {
  897. /* 0x4c[23] = 0, 0x4c[24] = 1
  898. * Antenna control by WL/BT
  899. */
  900. u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
  901. u32tmp &= ~BIT23;
  902. u32tmp |= BIT24;
  903. btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp);
  904. if (board_info->btdm_ant_pos ==
  905. BTC_ANTENNA_AT_MAIN_PORT) {
  906. /* Main Ant to BT for IPS case 0x4c[23] = 1 */
  907. btcoexist->btc_write_1byte_bitmask(btcoexist,
  908. 0x64, 0x1,
  909. 0x1);
  910. /*tell firmware "no antenna inverse"*/
  911. h2c_parameter[0] = 0;
  912. h2c_parameter[1] = 1; /*ext switch type*/
  913. btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
  914. h2c_parameter);
  915. } else {
  916. /*Aux Ant to BT for IPS case 0x4c[23] = 1 */
  917. btcoexist->btc_write_1byte_bitmask(btcoexist,
  918. 0x64, 0x1,
  919. 0x0);
  920. /*tell firmware "antenna inverse"*/
  921. h2c_parameter[0] = 1;
  922. h2c_parameter[1] = 1; /*ext switch type*/
  923. btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
  924. h2c_parameter);
  925. }
  926. }
  927. /* fixed internal switch first*/
  928. /* fixed internal switch S1->WiFi, S0->BT*/
  929. if (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT)
  930. btcoexist->btc_write_2byte(btcoexist, 0x948, 0x0);
  931. else/* fixed internal switch S0->WiFi, S1->BT*/
  932. btcoexist->btc_write_2byte(btcoexist, 0x948, 0x280);
  933. /* ext switch setting */
  934. switch (ant_pos_type) {
  935. case BTC_ANT_PATH_WIFI:
  936. if (board_info->btdm_ant_pos ==
  937. BTC_ANTENNA_AT_MAIN_PORT)
  938. btcoexist->btc_write_1byte_bitmask(btcoexist,
  939. 0x92c, 0x3,
  940. 0x1);
  941. else
  942. btcoexist->btc_write_1byte_bitmask(btcoexist,
  943. 0x92c, 0x3,
  944. 0x2);
  945. break;
  946. case BTC_ANT_PATH_BT:
  947. if (board_info->btdm_ant_pos ==
  948. BTC_ANTENNA_AT_MAIN_PORT)
  949. btcoexist->btc_write_1byte_bitmask(btcoexist,
  950. 0x92c, 0x3,
  951. 0x2);
  952. else
  953. btcoexist->btc_write_1byte_bitmask(btcoexist,
  954. 0x92c, 0x3,
  955. 0x1);
  956. break;
  957. default:
  958. case BTC_ANT_PATH_PTA:
  959. if (board_info->btdm_ant_pos ==
  960. BTC_ANTENNA_AT_MAIN_PORT)
  961. btcoexist->btc_write_1byte_bitmask(btcoexist,
  962. 0x92c, 0x3,
  963. 0x1);
  964. else
  965. btcoexist->btc_write_1byte_bitmask(btcoexist,
  966. 0x92c, 0x3,
  967. 0x2);
  968. break;
  969. }
  970. } else {
  971. if (init_hw_cfg) {
  972. /* 0x4c[23] = 1, 0x4c[24] = 0 Antenna control by 0x64*/
  973. u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
  974. u32tmp |= BIT23;
  975. u32tmp &= ~BIT24;
  976. btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp);
  977. if (board_info->btdm_ant_pos ==
  978. BTC_ANTENNA_AT_MAIN_PORT) {
  979. /*Main Ant to WiFi for IPS case 0x4c[23] = 1*/
  980. btcoexist->btc_write_1byte_bitmask(btcoexist,
  981. 0x64, 0x1,
  982. 0x0);
  983. /*tell firmware "no antenna inverse"*/
  984. h2c_parameter[0] = 0;
  985. h2c_parameter[1] = 0; /*internal switch type*/
  986. btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
  987. h2c_parameter);
  988. } else {
  989. /*Aux Ant to BT for IPS case 0x4c[23] = 1*/
  990. btcoexist->btc_write_1byte_bitmask(btcoexist,
  991. 0x64, 0x1,
  992. 0x1);
  993. /*tell firmware "antenna inverse"*/
  994. h2c_parameter[0] = 1;
  995. h2c_parameter[1] = 0; /*internal switch type*/
  996. btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
  997. h2c_parameter);
  998. }
  999. }
  1000. /* fixed external switch first*/
  1001. /*Main->WiFi, Aux->BT*/
  1002. if (board_info->btdm_ant_pos ==
  1003. BTC_ANTENNA_AT_MAIN_PORT)
  1004. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x92c,
  1005. 0x3, 0x1);
  1006. else/*Main->BT, Aux->WiFi */
  1007. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x92c,
  1008. 0x3, 0x2);
  1009. /* internal switch setting*/
  1010. switch (ant_pos_type) {
  1011. case BTC_ANT_PATH_WIFI:
  1012. if (board_info->btdm_ant_pos ==
  1013. BTC_ANTENNA_AT_MAIN_PORT)
  1014. btcoexist->btc_write_2byte(btcoexist, 0x948,
  1015. 0x0);
  1016. else
  1017. btcoexist->btc_write_2byte(btcoexist, 0x948,
  1018. 0x280);
  1019. break;
  1020. case BTC_ANT_PATH_BT:
  1021. if (board_info->btdm_ant_pos ==
  1022. BTC_ANTENNA_AT_MAIN_PORT)
  1023. btcoexist->btc_write_2byte(btcoexist, 0x948,
  1024. 0x280);
  1025. else
  1026. btcoexist->btc_write_2byte(btcoexist, 0x948,
  1027. 0x0);
  1028. break;
  1029. default:
  1030. case BTC_ANT_PATH_PTA:
  1031. if (board_info->btdm_ant_pos ==
  1032. BTC_ANTENNA_AT_MAIN_PORT)
  1033. btcoexist->btc_write_2byte(btcoexist, 0x948,
  1034. 0x200);
  1035. else
  1036. btcoexist->btc_write_2byte(btcoexist, 0x948,
  1037. 0x80);
  1038. break;
  1039. }
  1040. }
  1041. }
  1042. static void halbtc8723b1ant_ps_tdma(struct btc_coexist *btcoexist,
  1043. bool force_exec, bool turn_on, u8 type)
  1044. {
  1045. bool wifi_busy = false;
  1046. u8 rssi_adjust_val = 0;
  1047. coex_dm->cur_ps_tdma_on = turn_on;
  1048. coex_dm->cur_ps_tdma = type;
  1049. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  1050. if (!force_exec) {
  1051. if (coex_dm->cur_ps_tdma_on)
  1052. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
  1053. "[BTCoex], ******** TDMA(on, %d) *********\n",
  1054. coex_dm->cur_ps_tdma);
  1055. else
  1056. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
  1057. "[BTCoex], ******** TDMA(off, %d) ********\n",
  1058. coex_dm->cur_ps_tdma);
  1059. if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) &&
  1060. (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma))
  1061. return;
  1062. }
  1063. if (turn_on) {
  1064. switch (type) {
  1065. default:
  1066. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x1a,
  1067. 0x1a, 0x0, 0x50);
  1068. break;
  1069. case 1:
  1070. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x3a,
  1071. 0x03, 0x10, 0x50);
  1072. rssi_adjust_val = 11;
  1073. break;
  1074. case 2:
  1075. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x2b,
  1076. 0x03, 0x10, 0x50);
  1077. rssi_adjust_val = 14;
  1078. break;
  1079. case 3:
  1080. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x1d,
  1081. 0x1d, 0x0, 0x52);
  1082. break;
  1083. case 4:
  1084. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x93, 0x15,
  1085. 0x3, 0x14, 0x0);
  1086. rssi_adjust_val = 17;
  1087. break;
  1088. case 5:
  1089. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x61, 0x15,
  1090. 0x3, 0x11, 0x10);
  1091. break;
  1092. case 6:
  1093. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x61, 0x20,
  1094. 0x3, 0x11, 0x13);
  1095. break;
  1096. case 7:
  1097. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x13, 0xc,
  1098. 0x5, 0x0, 0x0);
  1099. break;
  1100. case 8:
  1101. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x93, 0x25,
  1102. 0x3, 0x10, 0x0);
  1103. break;
  1104. case 9:
  1105. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x21,
  1106. 0x3, 0x10, 0x50);
  1107. rssi_adjust_val = 18;
  1108. break;
  1109. case 10:
  1110. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x13, 0xa,
  1111. 0xa, 0x0, 0x40);
  1112. break;
  1113. case 11:
  1114. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x15,
  1115. 0x03, 0x10, 0x50);
  1116. rssi_adjust_val = 20;
  1117. break;
  1118. case 12:
  1119. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x0a,
  1120. 0x0a, 0x0, 0x50);
  1121. break;
  1122. case 13:
  1123. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x15,
  1124. 0x15, 0x0, 0x50);
  1125. break;
  1126. case 14:
  1127. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x21,
  1128. 0x3, 0x10, 0x52);
  1129. break;
  1130. case 15:
  1131. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x13, 0xa,
  1132. 0x3, 0x8, 0x0);
  1133. break;
  1134. case 16:
  1135. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x93, 0x15,
  1136. 0x3, 0x10, 0x0);
  1137. rssi_adjust_val = 18;
  1138. break;
  1139. case 18:
  1140. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x93, 0x25,
  1141. 0x3, 0x10, 0x0);
  1142. rssi_adjust_val = 14;
  1143. break;
  1144. case 20:
  1145. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x61, 0x35,
  1146. 0x03, 0x11, 0x10);
  1147. break;
  1148. case 21:
  1149. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x61, 0x25,
  1150. 0x03, 0x11, 0x11);
  1151. break;
  1152. case 22:
  1153. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x61, 0x25,
  1154. 0x03, 0x11, 0x10);
  1155. break;
  1156. case 23:
  1157. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x25,
  1158. 0x3, 0x31, 0x18);
  1159. rssi_adjust_val = 22;
  1160. break;
  1161. case 24:
  1162. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x15,
  1163. 0x3, 0x31, 0x18);
  1164. rssi_adjust_val = 22;
  1165. break;
  1166. case 25:
  1167. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xe3, 0xa,
  1168. 0x3, 0x31, 0x18);
  1169. rssi_adjust_val = 22;
  1170. break;
  1171. case 26:
  1172. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xe3, 0xa,
  1173. 0x3, 0x31, 0x18);
  1174. rssi_adjust_val = 22;
  1175. break;
  1176. case 27:
  1177. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x25,
  1178. 0x3, 0x31, 0x98);
  1179. rssi_adjust_val = 22;
  1180. break;
  1181. case 28:
  1182. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x69, 0x25,
  1183. 0x3, 0x31, 0x0);
  1184. break;
  1185. case 29:
  1186. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xab, 0x1a,
  1187. 0x1a, 0x1, 0x10);
  1188. break;
  1189. case 30:
  1190. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x14,
  1191. 0x3, 0x10, 0x50);
  1192. break;
  1193. case 31:
  1194. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xd3, 0x1a,
  1195. 0x1a, 0, 0x58);
  1196. break;
  1197. case 32:
  1198. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x61, 0xa,
  1199. 0x3, 0x10, 0x0);
  1200. break;
  1201. case 33:
  1202. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xa3, 0x25,
  1203. 0x3, 0x30, 0x90);
  1204. break;
  1205. case 34:
  1206. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x53, 0x1a,
  1207. 0x1a, 0x0, 0x10);
  1208. break;
  1209. case 35:
  1210. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x63, 0x1a,
  1211. 0x1a, 0x0, 0x10);
  1212. break;
  1213. case 36:
  1214. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xd3, 0x12,
  1215. 0x3, 0x14, 0x50);
  1216. break;
  1217. /* SoftAP only with no sta associated,BT disable ,
  1218. * TDMA mode for power saving
  1219. * here softap mode screen off will cost 70-80mA for phone
  1220. */
  1221. case 40:
  1222. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x23, 0x18,
  1223. 0x00, 0x10, 0x24);
  1224. break;
  1225. }
  1226. } else {
  1227. switch (type) {
  1228. case 8: /*PTA Control */
  1229. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x8, 0x0,
  1230. 0x0, 0x0, 0x0);
  1231. halbtc8723b1ant_SetAntPath(btcoexist, BTC_ANT_PATH_PTA,
  1232. false, false);
  1233. break;
  1234. case 0:
  1235. default: /*Software control, Antenna at BT side */
  1236. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x0, 0x0,
  1237. 0x0, 0x0, 0x0);
  1238. halbtc8723b1ant_SetAntPath(btcoexist, BTC_ANT_PATH_BT,
  1239. false, false);
  1240. break;
  1241. case 9: /*Software control, Antenna at WiFi side */
  1242. halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x0, 0x0,
  1243. 0x0, 0x0, 0x0);
  1244. halbtc8723b1ant_SetAntPath(btcoexist, BTC_ANT_PATH_WIFI,
  1245. false, false);
  1246. break;
  1247. }
  1248. }
  1249. rssi_adjust_val = 0;
  1250. btcoexist->btc_set(btcoexist,
  1251. BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE,
  1252. &rssi_adjust_val);
  1253. /* update pre state */
  1254. coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on;
  1255. coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma;
  1256. }
  1257. static bool halbtc8723b1ant_is_common_action(struct btc_coexist *btcoexist)
  1258. {
  1259. bool commom = false, wifi_connected = false;
  1260. bool wifi_busy = false;
  1261. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  1262. &wifi_connected);
  1263. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  1264. if (!wifi_connected &&
  1265. BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == coex_dm->bt_status) {
  1266. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  1267. "[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n");
  1268. halbtc8723b1ant_sw_mechanism(btcoexist, false);
  1269. commom = true;
  1270. } else if (wifi_connected &&
  1271. (BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
  1272. coex_dm->bt_status)) {
  1273. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  1274. "[BTCoex], Wifi connected + BT non connected-idle!!\n");
  1275. halbtc8723b1ant_sw_mechanism(btcoexist, false);
  1276. commom = true;
  1277. } else if (!wifi_connected &&
  1278. (BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE ==
  1279. coex_dm->bt_status)) {
  1280. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  1281. "[BTCoex], Wifi non connected-idle + BT connected-idle!!\n");
  1282. halbtc8723b1ant_sw_mechanism(btcoexist, false);
  1283. commom = true;
  1284. } else if (wifi_connected &&
  1285. (BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE ==
  1286. coex_dm->bt_status)) {
  1287. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  1288. "[BTCoex], Wifi connected + BT connected-idle!!\n");
  1289. halbtc8723b1ant_sw_mechanism(btcoexist, false);
  1290. commom = true;
  1291. } else if (!wifi_connected &&
  1292. (BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE !=
  1293. coex_dm->bt_status)) {
  1294. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  1295. ("[BTCoex], Wifi non connected-idle + BT Busy!!\n"));
  1296. halbtc8723b1ant_sw_mechanism(btcoexist, false);
  1297. commom = true;
  1298. } else {
  1299. if (wifi_busy)
  1300. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  1301. "[BTCoex], Wifi Connected-Busy + BT Busy!!\n");
  1302. else
  1303. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  1304. "[BTCoex], Wifi Connected-Idle + BT Busy!!\n");
  1305. commom = false;
  1306. }
  1307. return commom;
  1308. }
  1309. static void btc8723b1ant_tdma_dur_adj_for_acl(struct btc_coexist *btcoexist,
  1310. u8 wifi_status)
  1311. {
  1312. static s32 up, dn, m, n, wait_count;
  1313. /* 0: no change, +1: increase WiFi duration,
  1314. * -1: decrease WiFi duration
  1315. */
  1316. s32 result;
  1317. u8 retry_count = 0, bt_info_ext;
  1318. bool wifi_busy = false;
  1319. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW,
  1320. "[BTCoex], TdmaDurationAdjustForAcl()\n");
  1321. if (BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY == wifi_status)
  1322. wifi_busy = true;
  1323. else
  1324. wifi_busy = false;
  1325. if ((BT_8723B_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN ==
  1326. wifi_status) ||
  1327. (BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN == wifi_status) ||
  1328. (BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SPECIAL_PKT == wifi_status)) {
  1329. if (coex_dm->cur_ps_tdma != 1 && coex_dm->cur_ps_tdma != 2 &&
  1330. coex_dm->cur_ps_tdma != 3 && coex_dm->cur_ps_tdma != 9) {
  1331. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1332. true, 9);
  1333. coex_dm->tdma_adj_type = 9;
  1334. up = 0;
  1335. dn = 0;
  1336. m = 1;
  1337. n = 3;
  1338. result = 0;
  1339. wait_count = 0;
  1340. }
  1341. return;
  1342. }
  1343. if (!coex_dm->auto_tdma_adjust) {
  1344. coex_dm->auto_tdma_adjust = true;
  1345. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
  1346. "[BTCoex], first run TdmaDurationAdjust()!!\n");
  1347. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 2);
  1348. coex_dm->tdma_adj_type = 2;
  1349. up = 0;
  1350. dn = 0;
  1351. m = 1;
  1352. n = 3;
  1353. result = 0;
  1354. wait_count = 0;
  1355. } else {
  1356. /*accquire the BT TRx retry count from BT_Info byte2 */
  1357. retry_count = coex_sta->bt_retry_cnt;
  1358. bt_info_ext = coex_sta->bt_info_ext;
  1359. result = 0;
  1360. wait_count++;
  1361. /* no retry in the last 2-second duration */
  1362. if (retry_count == 0) {
  1363. up++;
  1364. dn--;
  1365. if (dn <= 0)
  1366. dn = 0;
  1367. if (up >= n) {
  1368. wait_count = 0;
  1369. n = 3;
  1370. up = 0;
  1371. dn = 0;
  1372. result = 1;
  1373. BTC_PRINT(BTC_MSG_ALGORITHM,
  1374. ALGO_TRACE_FW_DETAIL,
  1375. "[BTCoex], Increase wifi duration!!\n");
  1376. }
  1377. } else if (retry_count <= 3) {
  1378. up--;
  1379. dn++;
  1380. if (up <= 0)
  1381. up = 0;
  1382. if (dn == 2) {
  1383. if (wait_count <= 2)
  1384. m++;
  1385. else
  1386. m = 1;
  1387. if (m >= 20)
  1388. m = 20;
  1389. n = 3 * m;
  1390. up = 0;
  1391. dn = 0;
  1392. wait_count = 0;
  1393. result = -1;
  1394. BTC_PRINT(BTC_MSG_ALGORITHM,
  1395. ALGO_TRACE_FW_DETAIL,
  1396. "[BTCoex], Decrease wifi duration for retryCounter<3!!\n");
  1397. }
  1398. } else {
  1399. if (wait_count == 1)
  1400. m++;
  1401. else
  1402. m = 1;
  1403. if (m >= 20)
  1404. m = 20;
  1405. n = 3 * m;
  1406. up = 0;
  1407. dn = 0;
  1408. wait_count = 0;
  1409. result = -1;
  1410. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
  1411. "[BTCoex], Decrease wifi duration for retryCounter>3!!\n");
  1412. }
  1413. if (result == -1) {
  1414. if ((BT_INFO_8723B_1ANT_A2DP_BASIC_RATE(bt_info_ext)) &&
  1415. ((coex_dm->cur_ps_tdma == 1) ||
  1416. (coex_dm->cur_ps_tdma == 2))) {
  1417. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1418. true, 9);
  1419. coex_dm->tdma_adj_type = 9;
  1420. } else if (coex_dm->cur_ps_tdma == 1) {
  1421. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1422. true, 2);
  1423. coex_dm->tdma_adj_type = 2;
  1424. } else if (coex_dm->cur_ps_tdma == 2) {
  1425. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1426. true, 9);
  1427. coex_dm->tdma_adj_type = 9;
  1428. } else if (coex_dm->cur_ps_tdma == 9) {
  1429. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1430. true, 11);
  1431. coex_dm->tdma_adj_type = 11;
  1432. }
  1433. } else if (result == 1) {
  1434. if ((BT_INFO_8723B_1ANT_A2DP_BASIC_RATE(bt_info_ext)) &&
  1435. ((coex_dm->cur_ps_tdma == 1) ||
  1436. (coex_dm->cur_ps_tdma == 2))) {
  1437. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1438. true, 9);
  1439. coex_dm->tdma_adj_type = 9;
  1440. } else if (coex_dm->cur_ps_tdma == 11) {
  1441. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1442. true, 9);
  1443. coex_dm->tdma_adj_type = 9;
  1444. } else if (coex_dm->cur_ps_tdma == 9) {
  1445. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1446. true, 2);
  1447. coex_dm->tdma_adj_type = 2;
  1448. } else if (coex_dm->cur_ps_tdma == 2) {
  1449. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1450. true, 1);
  1451. coex_dm->tdma_adj_type = 1;
  1452. }
  1453. } else { /*no change */
  1454. /*if busy / idle change */
  1455. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL,
  1456. "[BTCoex],********* TDMA(on, %d) ********\n",
  1457. coex_dm->cur_ps_tdma);
  1458. }
  1459. if (coex_dm->cur_ps_tdma != 1 && coex_dm->cur_ps_tdma != 2 &&
  1460. coex_dm->cur_ps_tdma != 9 && coex_dm->cur_ps_tdma != 11) {
  1461. /* recover to previous adjust type */
  1462. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  1463. coex_dm->tdma_adj_type);
  1464. }
  1465. }
  1466. }
  1467. static void btc8723b1ant_pstdmachkpwrsave(struct btc_coexist *btcoexist,
  1468. bool new_ps_state)
  1469. {
  1470. u8 lps_mode = 0x0;
  1471. btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode);
  1472. if (lps_mode) { /* already under LPS state */
  1473. if (new_ps_state) {
  1474. /* keep state under LPS, do nothing. */
  1475. } else {
  1476. /* will leave LPS state, turn off psTdma first */
  1477. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1478. false, 0);
  1479. }
  1480. } else { /* NO PS state */
  1481. if (new_ps_state) {
  1482. /* will enter LPS state, turn off psTdma first */
  1483. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1484. false, 0);
  1485. } else {
  1486. /* keep state under NO PS state, do nothing. */
  1487. }
  1488. }
  1489. }
  1490. static void halbtc8723b1ant_power_save_state(struct btc_coexist *btcoexist,
  1491. u8 ps_type, u8 lps_val,
  1492. u8 rpwm_val)
  1493. {
  1494. bool low_pwr_disable = false;
  1495. switch (ps_type) {
  1496. case BTC_PS_WIFI_NATIVE:
  1497. /* recover to original 32k low power setting */
  1498. low_pwr_disable = false;
  1499. btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
  1500. &low_pwr_disable);
  1501. btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS, NULL);
  1502. break;
  1503. case BTC_PS_LPS_ON:
  1504. btc8723b1ant_pstdmachkpwrsave(btcoexist, true);
  1505. halbtc8723b1ant_LpsRpwm(btcoexist, NORMAL_EXEC, lps_val,
  1506. rpwm_val);
  1507. /* when coex force to enter LPS, do not enter 32k low power. */
  1508. low_pwr_disable = true;
  1509. btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
  1510. &low_pwr_disable);
  1511. /* power save must executed before psTdma. */
  1512. btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS, NULL);
  1513. break;
  1514. case BTC_PS_LPS_OFF:
  1515. btc8723b1ant_pstdmachkpwrsave(btcoexist, false);
  1516. btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS, NULL);
  1517. break;
  1518. default:
  1519. break;
  1520. }
  1521. }
  1522. /***************************************************
  1523. *
  1524. * Software Coex Mechanism start
  1525. *
  1526. ***************************************************/
  1527. /* SCO only or SCO+PAN(HS) */
  1528. static void halbtc8723b1ant_action_sco(struct btc_coexist *btcoexist)
  1529. {
  1530. halbtc8723b1ant_sw_mechanism(btcoexist, true);
  1531. }
  1532. static void halbtc8723b1ant_action_hid(struct btc_coexist *btcoexist)
  1533. {
  1534. halbtc8723b1ant_sw_mechanism(btcoexist, true);
  1535. }
  1536. /*A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */
  1537. static void halbtc8723b1ant_action_a2dp(struct btc_coexist *btcoexist)
  1538. {
  1539. halbtc8723b1ant_sw_mechanism(btcoexist, false);
  1540. }
  1541. static void halbtc8723b1ant_action_a2dp_pan_hs(struct btc_coexist *btcoexist)
  1542. {
  1543. halbtc8723b1ant_sw_mechanism(btcoexist, false);
  1544. }
  1545. static void halbtc8723b1ant_action_pan_edr(struct btc_coexist *btcoexist)
  1546. {
  1547. halbtc8723b1ant_sw_mechanism(btcoexist, false);
  1548. }
  1549. /* PAN(HS) only */
  1550. static void halbtc8723b1ant_action_pan_hs(struct btc_coexist *btcoexist)
  1551. {
  1552. halbtc8723b1ant_sw_mechanism(btcoexist, false);
  1553. }
  1554. /*PAN(EDR)+A2DP */
  1555. static void halbtc8723b1ant_action_pan_edr_a2dp(struct btc_coexist *btcoexist)
  1556. {
  1557. halbtc8723b1ant_sw_mechanism(btcoexist, false);
  1558. }
  1559. static void halbtc8723b1ant_action_pan_edr_hid(struct btc_coexist *btcoexist)
  1560. {
  1561. halbtc8723b1ant_sw_mechanism(btcoexist, true);
  1562. }
  1563. /* HID+A2DP+PAN(EDR) */
  1564. static void btc8723b1ant_action_hid_a2dp_pan_edr(struct btc_coexist *btcoexist)
  1565. {
  1566. halbtc8723b1ant_sw_mechanism(btcoexist, true);
  1567. }
  1568. static void halbtc8723b1ant_action_hid_a2dp(struct btc_coexist *btcoexist)
  1569. {
  1570. halbtc8723b1ant_sw_mechanism(btcoexist, true);
  1571. }
  1572. /*****************************************************
  1573. *
  1574. * Non-Software Coex Mechanism start
  1575. *
  1576. *****************************************************/
  1577. static void halbtc8723b1ant_action_wifi_multiport(struct btc_coexist *btcoexist)
  1578. {
  1579. halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  1580. 0x0, 0x0);
  1581. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  1582. halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  1583. }
  1584. static void halbtc8723b1ant_action_hs(struct btc_coexist *btcoexist)
  1585. {
  1586. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
  1587. halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  1588. }
  1589. static void halbtc8723b1ant_action_bt_inquiry(struct btc_coexist *btcoexist)
  1590. {
  1591. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1592. bool wifi_connected = false, ap_enable = false;
  1593. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
  1594. &ap_enable);
  1595. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  1596. &wifi_connected);
  1597. if (!wifi_connected) {
  1598. halbtc8723b1ant_power_save_state(btcoexist,
  1599. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  1600. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  1601. halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  1602. } else if (bt_link_info->sco_exist || bt_link_info->hid_only) {
  1603. /* SCO/HID-only busy */
  1604. halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  1605. 0x0, 0x0);
  1606. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
  1607. halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
  1608. } else {
  1609. if (ap_enable)
  1610. halbtc8723b1ant_power_save_state(btcoexist,
  1611. BTC_PS_WIFI_NATIVE,
  1612. 0x0, 0x0);
  1613. else
  1614. halbtc8723b1ant_power_save_state(btcoexist,
  1615. BTC_PS_LPS_ON,
  1616. 0x50, 0x4);
  1617. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 30);
  1618. halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
  1619. }
  1620. }
  1621. static void btc8723b1ant_act_bt_sco_hid_only_busy(struct btc_coexist *btcoexist,
  1622. u8 wifi_status)
  1623. {
  1624. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1625. bool wifi_connected = false;
  1626. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  1627. &wifi_connected);
  1628. /* tdma and coex table */
  1629. if (bt_link_info->sco_exist) {
  1630. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
  1631. halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  1632. } else { /* HID */
  1633. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 6);
  1634. halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
  1635. }
  1636. }
  1637. static void halbtc8723b1ant_action_wifi_connected_bt_acl_busy(
  1638. struct btc_coexist *btcoexist,
  1639. u8 wifi_status)
  1640. {
  1641. u8 bt_rssi_state;
  1642. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1643. bt_rssi_state = halbtc8723b1ant_bt_rssi_state(2, 28, 0);
  1644. if (bt_link_info->hid_only) { /*HID */
  1645. btc8723b1ant_act_bt_sco_hid_only_busy(btcoexist, wifi_status);
  1646. coex_dm->auto_tdma_adjust = false;
  1647. return;
  1648. } else if (bt_link_info->a2dp_only) { /*A2DP */
  1649. if (BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifi_status) {
  1650. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1651. false, 8);
  1652. halbtc8723b1ant_coex_table_with_type(btcoexist,
  1653. NORMAL_EXEC, 2);
  1654. coex_dm->auto_tdma_adjust = false;
  1655. } else if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
  1656. (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  1657. btc8723b1ant_tdma_dur_adj_for_acl(btcoexist,
  1658. wifi_status);
  1659. halbtc8723b1ant_coex_table_with_type(btcoexist,
  1660. NORMAL_EXEC, 1);
  1661. } else { /*for low BT RSSI */
  1662. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1663. true, 11);
  1664. halbtc8723b1ant_coex_table_with_type(btcoexist,
  1665. NORMAL_EXEC, 1);
  1666. coex_dm->auto_tdma_adjust = false;
  1667. }
  1668. } else if (bt_link_info->hid_exist &&
  1669. bt_link_info->a2dp_exist) { /*HID+A2DP */
  1670. if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
  1671. (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  1672. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1673. true, 14);
  1674. coex_dm->auto_tdma_adjust = false;
  1675. } else { /*for low BT RSSI*/
  1676. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1677. true, 14);
  1678. coex_dm->auto_tdma_adjust = false;
  1679. }
  1680. halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6);
  1681. /*PAN(OPP,FTP), HID+PAN(OPP,FTP) */
  1682. } else if (bt_link_info->pan_only ||
  1683. (bt_link_info->hid_exist && bt_link_info->pan_exist)) {
  1684. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3);
  1685. halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6);
  1686. coex_dm->auto_tdma_adjust = false;
  1687. /*A2DP+PAN(OPP,FTP), HID+A2DP+PAN(OPP,FTP)*/
  1688. } else if ((bt_link_info->a2dp_exist && bt_link_info->pan_exist) ||
  1689. (bt_link_info->hid_exist && bt_link_info->a2dp_exist &&
  1690. bt_link_info->pan_exist)) {
  1691. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 13);
  1692. halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
  1693. coex_dm->auto_tdma_adjust = false;
  1694. } else {
  1695. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 11);
  1696. halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
  1697. coex_dm->auto_tdma_adjust = false;
  1698. }
  1699. }
  1700. static void btc8723b1ant_action_wifi_not_conn(struct btc_coexist *btcoexist)
  1701. {
  1702. /* power save state */
  1703. halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  1704. 0x0, 0x0);
  1705. /* tdma and coex table */
  1706. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  1707. halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  1708. }
  1709. static void btc8723b1ant_action_wifi_not_conn_scan(struct btc_coexist *btcoex)
  1710. {
  1711. struct btc_bt_link_info *bt_link_info = &btcoex->bt_link_info;
  1712. halbtc8723b1ant_power_save_state(btcoex, BTC_PS_WIFI_NATIVE,
  1713. 0x0, 0x0);
  1714. /* tdma and coex table */
  1715. if (BT_8723B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
  1716. if (bt_link_info->a2dp_exist && bt_link_info->pan_exist) {
  1717. halbtc8723b1ant_ps_tdma(btcoex, NORMAL_EXEC,
  1718. true, 22);
  1719. halbtc8723b1ant_coex_table_with_type(btcoex,
  1720. NORMAL_EXEC, 1);
  1721. } else if (bt_link_info->pan_only) {
  1722. halbtc8723b1ant_ps_tdma(btcoex, NORMAL_EXEC,
  1723. true, 20);
  1724. halbtc8723b1ant_coex_table_with_type(btcoex,
  1725. NORMAL_EXEC, 2);
  1726. } else {
  1727. halbtc8723b1ant_ps_tdma(btcoex, NORMAL_EXEC,
  1728. true, 20);
  1729. halbtc8723b1ant_coex_table_with_type(btcoex,
  1730. NORMAL_EXEC, 1);
  1731. }
  1732. } else if ((BT_8723B_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
  1733. (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY ==
  1734. coex_dm->bt_status)){
  1735. btc8723b1ant_act_bt_sco_hid_only_busy(btcoex,
  1736. BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN);
  1737. } else {
  1738. halbtc8723b1ant_ps_tdma(btcoex, NORMAL_EXEC, false, 8);
  1739. halbtc8723b1ant_coex_table_with_type(btcoex, NORMAL_EXEC, 2);
  1740. }
  1741. }
  1742. static void btc8723b1ant_act_wifi_not_conn_asso_auth(struct btc_coexist *btcoex)
  1743. {
  1744. struct btc_bt_link_info *bt_link_info = &btcoex->bt_link_info;
  1745. halbtc8723b1ant_power_save_state(btcoex, BTC_PS_WIFI_NATIVE,
  1746. 0x0, 0x0);
  1747. if ((BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status) ||
  1748. (bt_link_info->sco_exist) || (bt_link_info->hid_only) ||
  1749. (bt_link_info->a2dp_only) || (bt_link_info->pan_only)) {
  1750. halbtc8723b1ant_ps_tdma(btcoex, NORMAL_EXEC, false, 8);
  1751. halbtc8723b1ant_coex_table_with_type(btcoex, NORMAL_EXEC, 7);
  1752. } else {
  1753. halbtc8723b1ant_ps_tdma(btcoex, NORMAL_EXEC, true, 20);
  1754. halbtc8723b1ant_coex_table_with_type(btcoex, NORMAL_EXEC, 1);
  1755. }
  1756. }
  1757. static void btc8723b1ant_action_wifi_conn_scan(struct btc_coexist *btcoexist)
  1758. {
  1759. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1760. halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  1761. 0x0, 0x0);
  1762. /* tdma and coex table */
  1763. if (BT_8723B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
  1764. if (bt_link_info->a2dp_exist && bt_link_info->pan_exist) {
  1765. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1766. true, 22);
  1767. halbtc8723b1ant_coex_table_with_type(btcoexist,
  1768. NORMAL_EXEC, 1);
  1769. } else if (bt_link_info->pan_only) {
  1770. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1771. true, 20);
  1772. halbtc8723b1ant_coex_table_with_type(btcoexist,
  1773. NORMAL_EXEC, 2);
  1774. } else {
  1775. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1776. true, 20);
  1777. halbtc8723b1ant_coex_table_with_type(btcoexist,
  1778. NORMAL_EXEC, 1);
  1779. }
  1780. } else if ((BT_8723B_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
  1781. (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY ==
  1782. coex_dm->bt_status)) {
  1783. btc8723b1ant_act_bt_sco_hid_only_busy(btcoexist,
  1784. BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN);
  1785. } else {
  1786. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  1787. halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  1788. }
  1789. }
  1790. static void halbtc8723b1ant_action_wifi_connected_special_packet(
  1791. struct btc_coexist *btcoexist)
  1792. {
  1793. bool hs_connecting = false;
  1794. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1795. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_CONNECTING, &hs_connecting);
  1796. halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  1797. 0x0, 0x0);
  1798. /* tdma and coex table */
  1799. if ((BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status) ||
  1800. (bt_link_info->sco_exist) || (bt_link_info->hid_only) ||
  1801. (bt_link_info->a2dp_only) || (bt_link_info->pan_only)) {
  1802. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  1803. halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
  1804. } else {
  1805. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
  1806. halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
  1807. }
  1808. }
  1809. static void halbtc8723b1ant_action_wifi_connected(struct btc_coexist *btcoexist)
  1810. {
  1811. bool wifi_busy = false;
  1812. bool scan = false, link = false, roam = false;
  1813. bool under_4way = false, ap_enable = false;
  1814. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  1815. "[BTCoex], CoexForWifiConnect()===>\n");
  1816. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
  1817. &under_4way);
  1818. if (under_4way) {
  1819. halbtc8723b1ant_action_wifi_connected_special_packet(btcoexist);
  1820. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  1821. "[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n");
  1822. return;
  1823. }
  1824. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
  1825. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
  1826. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
  1827. if (scan || link || roam) {
  1828. if (scan)
  1829. btc8723b1ant_action_wifi_conn_scan(btcoexist);
  1830. else
  1831. halbtc8723b1ant_action_wifi_connected_special_packet(
  1832. btcoexist);
  1833. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  1834. "[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n");
  1835. return;
  1836. }
  1837. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
  1838. &ap_enable);
  1839. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  1840. /* power save state */
  1841. if (!ap_enable &&
  1842. BT_8723B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status &&
  1843. !btcoexist->bt_link_info.hid_only) {
  1844. if (!wifi_busy && btcoexist->bt_link_info.a2dp_only)
  1845. halbtc8723b1ant_power_save_state(btcoexist,
  1846. BTC_PS_WIFI_NATIVE,
  1847. 0x0, 0x0);
  1848. else
  1849. halbtc8723b1ant_power_save_state(btcoexist,
  1850. BTC_PS_LPS_ON,
  1851. 0x50, 0x4);
  1852. } else {
  1853. halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  1854. 0x0, 0x0);
  1855. }
  1856. /* tdma and coex table */
  1857. if (!wifi_busy) {
  1858. if (BT_8723B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
  1859. halbtc8723b1ant_action_wifi_connected_bt_acl_busy(btcoexist,
  1860. BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE);
  1861. } else if ((BT_8723B_1ANT_BT_STATUS_SCO_BUSY ==
  1862. coex_dm->bt_status) ||
  1863. (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY ==
  1864. coex_dm->bt_status)) {
  1865. btc8723b1ant_act_bt_sco_hid_only_busy(btcoexist,
  1866. BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE);
  1867. } else {
  1868. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1869. false, 8);
  1870. halbtc8723b1ant_coex_table_with_type(btcoexist,
  1871. NORMAL_EXEC, 2);
  1872. }
  1873. } else {
  1874. if (BT_8723B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
  1875. halbtc8723b1ant_action_wifi_connected_bt_acl_busy(btcoexist,
  1876. BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY);
  1877. } else if ((BT_8723B_1ANT_BT_STATUS_SCO_BUSY ==
  1878. coex_dm->bt_status) ||
  1879. (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY ==
  1880. coex_dm->bt_status)) {
  1881. btc8723b1ant_act_bt_sco_hid_only_busy(btcoexist,
  1882. BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY);
  1883. } else {
  1884. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1885. false, 8);
  1886. halbtc8723b1ant_coex_table_with_type(btcoexist,
  1887. NORMAL_EXEC, 2);
  1888. }
  1889. }
  1890. }
  1891. static void btc8723b1ant_run_sw_coex_mech(struct btc_coexist *btcoexist)
  1892. {
  1893. u8 algorithm = 0;
  1894. algorithm = halbtc8723b1ant_action_algorithm(btcoexist);
  1895. coex_dm->cur_algorithm = algorithm;
  1896. if (!halbtc8723b1ant_is_common_action(btcoexist)) {
  1897. switch (coex_dm->cur_algorithm) {
  1898. case BT_8723B_1ANT_COEX_ALGO_SCO:
  1899. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  1900. "[BTCoex], Action algorithm = SCO.\n");
  1901. halbtc8723b1ant_action_sco(btcoexist);
  1902. break;
  1903. case BT_8723B_1ANT_COEX_ALGO_HID:
  1904. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  1905. "[BTCoex], Action algorithm = HID.\n");
  1906. halbtc8723b1ant_action_hid(btcoexist);
  1907. break;
  1908. case BT_8723B_1ANT_COEX_ALGO_A2DP:
  1909. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  1910. "[BTCoex], Action algorithm = A2DP.\n");
  1911. halbtc8723b1ant_action_a2dp(btcoexist);
  1912. break;
  1913. case BT_8723B_1ANT_COEX_ALGO_A2DP_PANHS:
  1914. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  1915. "[BTCoex], Action algorithm = A2DP+PAN(HS).\n");
  1916. halbtc8723b1ant_action_a2dp_pan_hs(btcoexist);
  1917. break;
  1918. case BT_8723B_1ANT_COEX_ALGO_PANEDR:
  1919. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  1920. "[BTCoex], Action algorithm = PAN(EDR).\n");
  1921. halbtc8723b1ant_action_pan_edr(btcoexist);
  1922. break;
  1923. case BT_8723B_1ANT_COEX_ALGO_PANHS:
  1924. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  1925. "[BTCoex], Action algorithm = HS mode.\n");
  1926. halbtc8723b1ant_action_pan_hs(btcoexist);
  1927. break;
  1928. case BT_8723B_1ANT_COEX_ALGO_PANEDR_A2DP:
  1929. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  1930. "[BTCoex], Action algorithm = PAN+A2DP.\n");
  1931. halbtc8723b1ant_action_pan_edr_a2dp(btcoexist);
  1932. break;
  1933. case BT_8723B_1ANT_COEX_ALGO_PANEDR_HID:
  1934. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  1935. "[BTCoex], Action algorithm = PAN(EDR)+HID.\n");
  1936. halbtc8723b1ant_action_pan_edr_hid(btcoexist);
  1937. break;
  1938. case BT_8723B_1ANT_COEX_ALGO_HID_A2DP_PANEDR:
  1939. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  1940. "[BTCoex], Action algorithm = HID+A2DP+PAN.\n");
  1941. btc8723b1ant_action_hid_a2dp_pan_edr(btcoexist);
  1942. break;
  1943. case BT_8723B_1ANT_COEX_ALGO_HID_A2DP:
  1944. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  1945. "[BTCoex], Action algorithm = HID+A2DP.\n");
  1946. halbtc8723b1ant_action_hid_a2dp(btcoexist);
  1947. break;
  1948. default:
  1949. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  1950. "[BTCoex], Action algorithm = coexist All Off!!\n");
  1951. break;
  1952. }
  1953. coex_dm->pre_algorithm = coex_dm->cur_algorithm;
  1954. }
  1955. }
  1956. static void halbtc8723b1ant_run_coexist_mechanism(struct btc_coexist *btcoexist)
  1957. {
  1958. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1959. bool wifi_connected = false, bt_hs_on = false;
  1960. bool increase_scan_dev_num = false;
  1961. bool bt_ctrl_agg_buf_size = false;
  1962. u8 agg_buf_size = 5;
  1963. u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
  1964. u32 wifi_link_status = 0;
  1965. u32 num_of_wifi_link = 0;
  1966. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  1967. "[BTCoex], RunCoexistMechanism()===>\n");
  1968. if (btcoexist->manual_control) {
  1969. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  1970. "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
  1971. return;
  1972. }
  1973. if (btcoexist->stop_coex_dm) {
  1974. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  1975. "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n");
  1976. return;
  1977. }
  1978. if (coex_sta->under_ips) {
  1979. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  1980. "[BTCoex], wifi is under IPS !!!\n");
  1981. return;
  1982. }
  1983. if ((BT_8723B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
  1984. (BT_8723B_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
  1985. (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) {
  1986. increase_scan_dev_num = true;
  1987. }
  1988. btcoexist->btc_set(btcoexist, BTC_SET_BL_INC_SCAN_DEV_NUM,
  1989. &increase_scan_dev_num);
  1990. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  1991. &wifi_connected);
  1992. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
  1993. &wifi_link_status);
  1994. num_of_wifi_link = wifi_link_status >> 16;
  1995. if (num_of_wifi_link >= 2) {
  1996. halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
  1997. halbtc8723b1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
  1998. bt_ctrl_agg_buf_size,
  1999. agg_buf_size);
  2000. halbtc8723b1ant_action_wifi_multiport(btcoexist);
  2001. return;
  2002. }
  2003. if (!bt_link_info->sco_exist && !bt_link_info->hid_exist) {
  2004. halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
  2005. } else {
  2006. if (wifi_connected) {
  2007. wifi_rssi_state =
  2008. halbtc8723b1ant_wifi_rssi_state(btcoexist,
  2009. 1, 2, 30, 0);
  2010. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  2011. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  2012. halbtc8723b1ant_limited_tx(btcoexist,
  2013. NORMAL_EXEC,
  2014. 1, 1, 1, 1);
  2015. } else {
  2016. halbtc8723b1ant_limited_tx(btcoexist,
  2017. NORMAL_EXEC,
  2018. 1, 1, 1, 1);
  2019. }
  2020. } else {
  2021. halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC,
  2022. 0, 0, 0, 0);
  2023. }
  2024. }
  2025. if (bt_link_info->sco_exist) {
  2026. bt_ctrl_agg_buf_size = true;
  2027. agg_buf_size = 0x3;
  2028. } else if (bt_link_info->hid_exist) {
  2029. bt_ctrl_agg_buf_size = true;
  2030. agg_buf_size = 0x5;
  2031. } else if (bt_link_info->a2dp_exist || bt_link_info->pan_exist) {
  2032. bt_ctrl_agg_buf_size = true;
  2033. agg_buf_size = 0x8;
  2034. }
  2035. halbtc8723b1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
  2036. bt_ctrl_agg_buf_size, agg_buf_size);
  2037. btc8723b1ant_run_sw_coex_mech(btcoexist);
  2038. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  2039. if (coex_sta->c2h_bt_inquiry_page) {
  2040. halbtc8723b1ant_action_bt_inquiry(btcoexist);
  2041. return;
  2042. } else if (bt_hs_on) {
  2043. halbtc8723b1ant_action_hs(btcoexist);
  2044. return;
  2045. }
  2046. if (!wifi_connected) {
  2047. bool scan = false, link = false, roam = false;
  2048. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  2049. "[BTCoex], wifi is non connected-idle !!!\n");
  2050. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
  2051. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
  2052. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
  2053. if (scan || link || roam) {
  2054. if (scan)
  2055. btc8723b1ant_action_wifi_not_conn_scan(
  2056. btcoexist);
  2057. else
  2058. btc8723b1ant_act_wifi_not_conn_asso_auth(
  2059. btcoexist);
  2060. } else {
  2061. btc8723b1ant_action_wifi_not_conn(btcoexist);
  2062. }
  2063. } else { /* wifi LPS/Busy */
  2064. halbtc8723b1ant_action_wifi_connected(btcoexist);
  2065. }
  2066. }
  2067. static void halbtc8723b1ant_init_coex_dm(struct btc_coexist *btcoexist)
  2068. {
  2069. /* sw all off */
  2070. halbtc8723b1ant_sw_mechanism(btcoexist, false);
  2071. halbtc8723b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8);
  2072. halbtc8723b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
  2073. }
  2074. static void halbtc8723b1ant_init_hw_config(struct btc_coexist *btcoexist,
  2075. bool backup)
  2076. {
  2077. u32 u32tmp = 0;
  2078. u8 u8tmp = 0;
  2079. u32 cnt_bt_cal_chk = 0;
  2080. BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT,
  2081. "[BTCoex], 1Ant Init HW Config!!\n");
  2082. if (backup) {/* backup rf 0x1e value */
  2083. coex_dm->backup_arfr_cnt1 =
  2084. btcoexist->btc_read_4byte(btcoexist, 0x430);
  2085. coex_dm->backup_arfr_cnt2 =
  2086. btcoexist->btc_read_4byte(btcoexist, 0x434);
  2087. coex_dm->backup_retry_limit =
  2088. btcoexist->btc_read_2byte(btcoexist, 0x42a);
  2089. coex_dm->backup_ampdu_max_time =
  2090. btcoexist->btc_read_1byte(btcoexist, 0x456);
  2091. }
  2092. /* WiFi goto standby while GNT_BT 0-->1 */
  2093. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x780);
  2094. /* BT goto standby while GNT_BT 1-->0 */
  2095. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x2, 0xfffff, 0x500);
  2096. btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff);
  2097. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x944, 0x3, 0x3);
  2098. btcoexist->btc_write_1byte(btcoexist, 0x930, 0x77);
  2099. /* BT calibration check */
  2100. while (cnt_bt_cal_chk <= 20) {
  2101. u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x49d);
  2102. cnt_bt_cal_chk++;
  2103. if (u32tmp & BIT0) {
  2104. BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT,
  2105. "[BTCoex], ########### BT calibration(cnt=%d) ###########\n",
  2106. cnt_bt_cal_chk);
  2107. mdelay(50);
  2108. } else {
  2109. BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT,
  2110. "[BTCoex], ********** BT NOT calibration (cnt=%d)**********\n",
  2111. cnt_bt_cal_chk);
  2112. break;
  2113. }
  2114. }
  2115. /* 0x790[5:0] = 0x5 */
  2116. u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x790);
  2117. u8tmp &= 0xc0;
  2118. u8tmp |= 0x5;
  2119. btcoexist->btc_write_1byte(btcoexist, 0x790, u8tmp);
  2120. /* Enable counter statistics */
  2121. /*0x76e[3] =1, WLAN_Act control by PTA */
  2122. btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
  2123. btcoexist->btc_write_1byte(btcoexist, 0x778, 0x1);
  2124. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1);
  2125. /*Antenna config */
  2126. halbtc8723b1ant_SetAntPath(btcoexist, BTC_ANT_PATH_PTA, true, false);
  2127. /* PTA parameter */
  2128. halbtc8723b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
  2129. }
  2130. static void halbtc8723b1ant_wifi_off_hw_cfg(struct btc_coexist *btcoexist)
  2131. {
  2132. /* set wlan_act to low */
  2133. btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4);
  2134. }
  2135. /**************************************************************
  2136. * work around function start with wa_halbtc8723b1ant_
  2137. **************************************************************/
  2138. /**************************************************************
  2139. * extern function start with EXhalbtc8723b1ant_
  2140. **************************************************************/
  2141. void ex_halbtc8723b1ant_init_hwconfig(struct btc_coexist *btcoexist)
  2142. {
  2143. halbtc8723b1ant_init_hw_config(btcoexist, true);
  2144. }
  2145. void ex_halbtc8723b1ant_init_coex_dm(struct btc_coexist *btcoexist)
  2146. {
  2147. BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT,
  2148. "[BTCoex], Coex Mechanism Init!!\n");
  2149. btcoexist->stop_coex_dm = false;
  2150. halbtc8723b1ant_init_coex_dm(btcoexist);
  2151. halbtc8723b1ant_query_bt_info(btcoexist);
  2152. }
  2153. void ex_halbtc8723b1ant_display_coex_info(struct btc_coexist *btcoexist)
  2154. {
  2155. struct btc_board_info *board_info = &btcoexist->board_info;
  2156. struct btc_stack_info *stack_info = &btcoexist->stack_info;
  2157. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  2158. struct rtl_priv *rtlpriv = btcoexist->adapter;
  2159. u8 u8tmp[4], i, bt_info_ext, pstdmacase = 0;
  2160. u16 u16tmp[4];
  2161. u32 u32tmp[4];
  2162. bool roam = false, scan = false;
  2163. bool link = false, wifi_under_5g = false;
  2164. bool bt_hs_on = false, wifi_busy = false;
  2165. s32 wifi_rssi = 0, bt_hs_rssi = 0;
  2166. u32 wifi_bw, wifi_traffic_dir, fa_ofdm, fa_cck, wifi_link_status;
  2167. u8 wifi_dot11_chnl, wifi_hs_chnl;
  2168. u32 fw_ver = 0, bt_patch_ver = 0;
  2169. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2170. "\r\n ============[BT Coexist info]============");
  2171. if (btcoexist->manual_control) {
  2172. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2173. "\r\n ============[Under Manual Control]==========");
  2174. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2175. "\r\n ==========================================");
  2176. }
  2177. if (btcoexist->stop_coex_dm) {
  2178. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2179. "\r\n ============[Coex is STOPPED]============");
  2180. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2181. "\r\n ==========================================");
  2182. }
  2183. if (!board_info->bt_exist) {
  2184. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n BT not exists !!!");
  2185. return;
  2186. }
  2187. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d/ %d",
  2188. "Ant PG Num/ Ant Mech/ Ant Pos:",
  2189. board_info->pg_ant_num, board_info->btdm_ant_num,
  2190. board_info->btdm_ant_pos);
  2191. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %s / %d",
  2192. "BT stack/ hci ext ver",
  2193. ((stack_info->profile_notified) ? "Yes" : "No"),
  2194. stack_info->hci_version);
  2195. btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
  2196. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
  2197. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2198. "\r\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)",
  2199. "CoexVer/ FwVer/ PatchVer",
  2200. glcoex_ver_date_8723b_1ant, glcoex_ver_8723b_1ant,
  2201. fw_ver, bt_patch_ver, bt_patch_ver);
  2202. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  2203. btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_DOT11_CHNL,
  2204. &wifi_dot11_chnl);
  2205. btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_HS_CHNL, &wifi_hs_chnl);
  2206. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d / %d(%d)",
  2207. "Dot11 channel / HsChnl(HsMode)",
  2208. wifi_dot11_chnl, wifi_hs_chnl, bt_hs_on);
  2209. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %02x %02x %02x ",
  2210. "H2C Wifi inform bt chnl Info",
  2211. coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1],
  2212. coex_dm->wifi_chnl_info[2]);
  2213. btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
  2214. btcoexist->btc_get(btcoexist, BTC_GET_S4_HS_RSSI, &bt_hs_rssi);
  2215. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d",
  2216. "Wifi rssi/ HS rssi", wifi_rssi, bt_hs_rssi);
  2217. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
  2218. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
  2219. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
  2220. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d/ %d ",
  2221. "Wifi link/ roam/ scan", link, roam, scan);
  2222. btcoexist->btc_get(btcoexist , BTC_GET_BL_WIFI_UNDER_5G,
  2223. &wifi_under_5g);
  2224. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  2225. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  2226. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION,
  2227. &wifi_traffic_dir);
  2228. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %s / %s/ %s ",
  2229. "Wifi status", (wifi_under_5g ? "5G" : "2.4G"),
  2230. ((BTC_WIFI_BW_LEGACY == wifi_bw) ? "Legacy" :
  2231. (((BTC_WIFI_BW_HT40 == wifi_bw) ? "HT40" : "HT20"))),
  2232. ((!wifi_busy) ? "idle" :
  2233. ((BTC_WIFI_TRAFFIC_TX == wifi_traffic_dir) ?
  2234. "uplink" : "downlink")));
  2235. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
  2236. &wifi_link_status);
  2237. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d/ %d/ %d/ %d",
  2238. "sta/vwifi/hs/p2pGo/p2pGc",
  2239. ((wifi_link_status & WIFI_STA_CONNECTED) ? 1 : 0),
  2240. ((wifi_link_status & WIFI_AP_CONNECTED) ? 1 : 0),
  2241. ((wifi_link_status & WIFI_HS_CONNECTED) ? 1 : 0),
  2242. ((wifi_link_status & WIFI_P2P_GO_CONNECTED) ? 1 : 0),
  2243. ((wifi_link_status & WIFI_P2P_GC_CONNECTED) ? 1 : 0));
  2244. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = [%s/ %d/ %d] ",
  2245. "BT [status/ rssi/ retryCnt]",
  2246. ((btcoexist->bt_info.bt_disabled) ? ("disabled") :
  2247. ((coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan") :
  2248. ((BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
  2249. coex_dm->bt_status) ?
  2250. "non-connected idle" :
  2251. ((BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE ==
  2252. coex_dm->bt_status) ?
  2253. "connected-idle" : "busy")))),
  2254. coex_sta->bt_rssi, coex_sta->bt_retry_cnt);
  2255. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2256. "\r\n %-35s = %d / %d / %d / %d",
  2257. "SCO/HID/PAN/A2DP", bt_link_info->sco_exist,
  2258. bt_link_info->hid_exist, bt_link_info->pan_exist,
  2259. bt_link_info->a2dp_exist);
  2260. btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_BT_LINK_INFO);
  2261. bt_info_ext = coex_sta->bt_info_ext;
  2262. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %s",
  2263. "BT Info A2DP rate",
  2264. (bt_info_ext & BIT0) ? "Basic rate" : "EDR rate");
  2265. for (i = 0; i < BT_INFO_SRC_8723B_1ANT_MAX; i++) {
  2266. if (coex_sta->bt_info_c2h_cnt[i]) {
  2267. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2268. "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)",
  2269. GLBtInfoSrc8723b1Ant[i],
  2270. coex_sta->bt_info_c2h[i][0],
  2271. coex_sta->bt_info_c2h[i][1],
  2272. coex_sta->bt_info_c2h[i][2],
  2273. coex_sta->bt_info_c2h[i][3],
  2274. coex_sta->bt_info_c2h[i][4],
  2275. coex_sta->bt_info_c2h[i][5],
  2276. coex_sta->bt_info_c2h[i][6],
  2277. coex_sta->bt_info_c2h_cnt[i]);
  2278. }
  2279. }
  2280. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2281. "\r\n %-35s = %s/%s, (0x%x/0x%x)",
  2282. "PS state, IPS/LPS, (lps/rpwm)",
  2283. ((coex_sta->under_ips ? "IPS ON" : "IPS OFF")),
  2284. ((coex_sta->under_lps ? "LPS ON" : "LPS OFF")),
  2285. btcoexist->bt_info.lps_val,
  2286. btcoexist->bt_info.rpwm_val);
  2287. btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_FW_PWR_MODE_CMD);
  2288. if (!btcoexist->manual_control) {
  2289. /* Sw mechanism */
  2290. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s",
  2291. "============[Sw mechanism]============");
  2292. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/",
  2293. "SM[LowPenaltyRA]", coex_dm->cur_low_penalty_ra);
  2294. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %s/ %s/ %d ",
  2295. "DelBA/ BtCtrlAgg/ AggSize",
  2296. (btcoexist->bt_info.reject_agg_pkt ? "Yes" : "No"),
  2297. (btcoexist->bt_info.bt_ctrl_buf_size ? "Yes" : "No"),
  2298. btcoexist->bt_info.agg_buf_size);
  2299. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x ",
  2300. "Rate Mask", btcoexist->bt_info.ra_mask);
  2301. /* Fw mechanism */
  2302. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s",
  2303. "============[Fw mechanism]============");
  2304. pstdmacase = coex_dm->cur_ps_tdma;
  2305. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2306. "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (auto:%d)",
  2307. "PS TDMA", coex_dm->ps_tdma_para[0],
  2308. coex_dm->ps_tdma_para[1], coex_dm->ps_tdma_para[2],
  2309. coex_dm->ps_tdma_para[3], coex_dm->ps_tdma_para[4],
  2310. pstdmacase, coex_dm->auto_tdma_adjust);
  2311. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d ",
  2312. "IgnWlanAct", coex_dm->cur_ignore_wlan_act);
  2313. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x ",
  2314. "Latest error condition(should be 0)",
  2315. coex_dm->error_condition);
  2316. }
  2317. /* Hw setting */
  2318. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s",
  2319. "============[Hw setting]============");
  2320. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
  2321. "backup ARFR1/ARFR2/RL/AMaxTime", coex_dm->backup_arfr_cnt1,
  2322. coex_dm->backup_arfr_cnt2, coex_dm->backup_retry_limit,
  2323. coex_dm->backup_ampdu_max_time);
  2324. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x430);
  2325. u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x434);
  2326. u16tmp[0] = btcoexist->btc_read_2byte(btcoexist, 0x42a);
  2327. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x456);
  2328. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
  2329. "0x430/0x434/0x42a/0x456",
  2330. u32tmp[0], u32tmp[1], u16tmp[0], u8tmp[0]);
  2331. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
  2332. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6cc);
  2333. u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x880);
  2334. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
  2335. "0x778/0x6cc/0x880[29:25]", u8tmp[0], u32tmp[0],
  2336. (u32tmp[1] & 0x3e000000) >> 25);
  2337. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x948);
  2338. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x67);
  2339. u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x765);
  2340. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
  2341. "0x948/ 0x67[5] / 0x765",
  2342. u32tmp[0], ((u8tmp[0] & 0x20) >> 5), u8tmp[1]);
  2343. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x92c);
  2344. u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x930);
  2345. u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x944);
  2346. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
  2347. "0x92c[1:0]/ 0x930[7:0]/0x944[1:0]",
  2348. u32tmp[0] & 0x3, u32tmp[1] & 0xff, u32tmp[2] & 0x3);
  2349. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x39);
  2350. u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x40);
  2351. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c);
  2352. u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0x64);
  2353. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  2354. "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
  2355. "0x38[11]/0x40/0x4c[24:23]/0x64[0]",
  2356. ((u8tmp[0] & 0x8)>>3), u8tmp[1],
  2357. ((u32tmp[0] & 0x01800000) >> 23), u8tmp[2] & 0x1);
  2358. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
  2359. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
  2360. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x",
  2361. "0x550(bcn ctrl)/0x522", u32tmp[0], u8tmp[0]);
  2362. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50);
  2363. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x49c);
  2364. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x",
  2365. "0xc50(dig)/0x49c(null-drop)", u32tmp[0] & 0xff, u8tmp[0]);
  2366. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xda0);
  2367. u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0xda4);
  2368. u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0xda8);
  2369. u32tmp[3] = btcoexist->btc_read_4byte(btcoexist, 0xcf0);
  2370. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xa5b);
  2371. u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xa5c);
  2372. fa_ofdm = ((u32tmp[0] & 0xffff0000) >> 16) +
  2373. ((u32tmp[1] & 0xffff0000) >> 16) +
  2374. (u32tmp[1] & 0xffff) +
  2375. (u32tmp[2] & 0xffff) +
  2376. ((u32tmp[3] & 0xffff0000) >> 16) +
  2377. (u32tmp[3] & 0xffff);
  2378. fa_cck = (u8tmp[0] << 8) + u8tmp[1];
  2379. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
  2380. "OFDM-CCA/OFDM-FA/CCK-FA",
  2381. u32tmp[0] & 0xffff, fa_ofdm, fa_cck);
  2382. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
  2383. u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
  2384. u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
  2385. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
  2386. "0x6c0/0x6c4/0x6c8(coexTable)",
  2387. u32tmp[0], u32tmp[1], u32tmp[2]);
  2388. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d",
  2389. "0x770(high-pri rx/tx)", coex_sta->high_priority_rx,
  2390. coex_sta->high_priority_tx);
  2391. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d",
  2392. "0x774(low-pri rx/tx)", coex_sta->low_priority_rx,
  2393. coex_sta->low_priority_tx);
  2394. #if (BT_AUTO_REPORT_ONLY_8723B_1ANT == 1)
  2395. halbtc8723b1ant_monitor_bt_ctr(btcoexist);
  2396. #endif
  2397. btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS);
  2398. }
  2399. void ex_halbtc8723b1ant_ips_notify(struct btc_coexist *btcoexist, u8 type)
  2400. {
  2401. if (btcoexist->manual_control || btcoexist->stop_coex_dm)
  2402. return;
  2403. if (BTC_IPS_ENTER == type) {
  2404. BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
  2405. "[BTCoex], IPS ENTER notify\n");
  2406. coex_sta->under_ips = true;
  2407. halbtc8723b1ant_SetAntPath(btcoexist, BTC_ANT_PATH_BT,
  2408. false, true);
  2409. /* set PTA control */
  2410. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  2411. halbtc8723b1ant_coex_table_with_type(btcoexist,
  2412. NORMAL_EXEC, 0);
  2413. halbtc8723b1ant_wifi_off_hw_cfg(btcoexist);
  2414. } else if (BTC_IPS_LEAVE == type) {
  2415. BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
  2416. "[BTCoex], IPS LEAVE notify\n");
  2417. coex_sta->under_ips = false;
  2418. halbtc8723b1ant_init_hw_config(btcoexist, false);
  2419. halbtc8723b1ant_init_coex_dm(btcoexist);
  2420. halbtc8723b1ant_query_bt_info(btcoexist);
  2421. }
  2422. }
  2423. void ex_halbtc8723b1ant_lps_notify(struct btc_coexist *btcoexist, u8 type)
  2424. {
  2425. if (btcoexist->manual_control || btcoexist->stop_coex_dm)
  2426. return;
  2427. if (BTC_LPS_ENABLE == type) {
  2428. BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
  2429. "[BTCoex], LPS ENABLE notify\n");
  2430. coex_sta->under_lps = true;
  2431. } else if (BTC_LPS_DISABLE == type) {
  2432. BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
  2433. "[BTCoex], LPS DISABLE notify\n");
  2434. coex_sta->under_lps = false;
  2435. }
  2436. }
  2437. void ex_halbtc8723b1ant_scan_notify(struct btc_coexist *btcoexist, u8 type)
  2438. {
  2439. bool wifi_connected = false, bt_hs_on = false;
  2440. u32 wifi_link_status = 0;
  2441. u32 num_of_wifi_link = 0;
  2442. bool bt_ctrl_agg_buf_size = false;
  2443. u8 agg_buf_size = 5;
  2444. if (btcoexist->manual_control || btcoexist->stop_coex_dm ||
  2445. btcoexist->bt_info.bt_disabled)
  2446. return;
  2447. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  2448. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  2449. &wifi_connected);
  2450. halbtc8723b1ant_query_bt_info(btcoexist);
  2451. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
  2452. &wifi_link_status);
  2453. num_of_wifi_link = wifi_link_status >> 16;
  2454. if (num_of_wifi_link >= 2) {
  2455. halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
  2456. halbtc8723b1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
  2457. bt_ctrl_agg_buf_size, agg_buf_size);
  2458. halbtc8723b1ant_action_wifi_multiport(btcoexist);
  2459. return;
  2460. }
  2461. if (coex_sta->c2h_bt_inquiry_page) {
  2462. halbtc8723b1ant_action_bt_inquiry(btcoexist);
  2463. return;
  2464. } else if (bt_hs_on) {
  2465. halbtc8723b1ant_action_hs(btcoexist);
  2466. return;
  2467. }
  2468. if (BTC_SCAN_START == type) {
  2469. BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
  2470. "[BTCoex], SCAN START notify\n");
  2471. if (!wifi_connected) /* non-connected scan */
  2472. btc8723b1ant_action_wifi_not_conn_scan(btcoexist);
  2473. else /* wifi is connected */
  2474. btc8723b1ant_action_wifi_conn_scan(btcoexist);
  2475. } else if (BTC_SCAN_FINISH == type) {
  2476. BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
  2477. "[BTCoex], SCAN FINISH notify\n");
  2478. if (!wifi_connected) /* non-connected scan */
  2479. btc8723b1ant_action_wifi_not_conn(btcoexist);
  2480. else
  2481. halbtc8723b1ant_action_wifi_connected(btcoexist);
  2482. }
  2483. }
  2484. void ex_halbtc8723b1ant_connect_notify(struct btc_coexist *btcoexist, u8 type)
  2485. {
  2486. bool wifi_connected = false, bt_hs_on = false;
  2487. u32 wifi_link_status = 0;
  2488. u32 num_of_wifi_link = 0;
  2489. bool bt_ctrl_agg_buf_size = false;
  2490. u8 agg_buf_size = 5;
  2491. if (btcoexist->manual_control || btcoexist->stop_coex_dm ||
  2492. btcoexist->bt_info.bt_disabled)
  2493. return;
  2494. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
  2495. &wifi_link_status);
  2496. num_of_wifi_link = wifi_link_status>>16;
  2497. if (num_of_wifi_link >= 2) {
  2498. halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
  2499. halbtc8723b1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
  2500. bt_ctrl_agg_buf_size, agg_buf_size);
  2501. halbtc8723b1ant_action_wifi_multiport(btcoexist);
  2502. return;
  2503. }
  2504. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  2505. if (coex_sta->c2h_bt_inquiry_page) {
  2506. halbtc8723b1ant_action_bt_inquiry(btcoexist);
  2507. return;
  2508. } else if (bt_hs_on) {
  2509. halbtc8723b1ant_action_hs(btcoexist);
  2510. return;
  2511. }
  2512. if (BTC_ASSOCIATE_START == type) {
  2513. BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
  2514. "[BTCoex], CONNECT START notify\n");
  2515. btc8723b1ant_act_wifi_not_conn_asso_auth(btcoexist);
  2516. } else if (BTC_ASSOCIATE_FINISH == type) {
  2517. BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
  2518. "[BTCoex], CONNECT FINISH notify\n");
  2519. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  2520. &wifi_connected);
  2521. if (!wifi_connected) /* non-connected scan */
  2522. btc8723b1ant_action_wifi_not_conn(btcoexist);
  2523. else
  2524. halbtc8723b1ant_action_wifi_connected(btcoexist);
  2525. }
  2526. }
  2527. void ex_halbtc8723b1ant_media_status_notify(struct btc_coexist *btcoexist,
  2528. u8 type)
  2529. {
  2530. u8 h2c_parameter[3] = {0};
  2531. u32 wifi_bw;
  2532. u8 wifiCentralChnl;
  2533. if (btcoexist->manual_control || btcoexist->stop_coex_dm ||
  2534. btcoexist->bt_info.bt_disabled)
  2535. return;
  2536. if (BTC_MEDIA_CONNECT == type)
  2537. BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
  2538. "[BTCoex], MEDIA connect notify\n");
  2539. else
  2540. BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
  2541. "[BTCoex], MEDIA disconnect notify\n");
  2542. /* only 2.4G we need to inform bt the chnl mask */
  2543. btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL,
  2544. &wifiCentralChnl);
  2545. if ((BTC_MEDIA_CONNECT == type) &&
  2546. (wifiCentralChnl <= 14)) {
  2547. h2c_parameter[0] = 0x0;
  2548. h2c_parameter[1] = wifiCentralChnl;
  2549. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  2550. if (BTC_WIFI_BW_HT40 == wifi_bw)
  2551. h2c_parameter[2] = 0x30;
  2552. else
  2553. h2c_parameter[2] = 0x20;
  2554. }
  2555. coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
  2556. coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
  2557. coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
  2558. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC,
  2559. "[BTCoex], FW write 0x66 = 0x%x\n",
  2560. h2c_parameter[0] << 16 | h2c_parameter[1] << 8 |
  2561. h2c_parameter[2]);
  2562. btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter);
  2563. }
  2564. void ex_halbtc8723b1ant_special_packet_notify(struct btc_coexist *btcoexist,
  2565. u8 type)
  2566. {
  2567. bool bt_hs_on = false;
  2568. u32 wifi_link_status = 0;
  2569. u32 num_of_wifi_link = 0;
  2570. bool bt_ctrl_agg_buf_size = false;
  2571. u8 agg_buf_size = 5;
  2572. if (btcoexist->manual_control || btcoexist->stop_coex_dm ||
  2573. btcoexist->bt_info.bt_disabled)
  2574. return;
  2575. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
  2576. &wifi_link_status);
  2577. num_of_wifi_link = wifi_link_status >> 16;
  2578. if (num_of_wifi_link >= 2) {
  2579. halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
  2580. halbtc8723b1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
  2581. bt_ctrl_agg_buf_size, agg_buf_size);
  2582. halbtc8723b1ant_action_wifi_multiport(btcoexist);
  2583. return;
  2584. }
  2585. coex_sta->special_pkt_period_cnt = 0;
  2586. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  2587. if (coex_sta->c2h_bt_inquiry_page) {
  2588. halbtc8723b1ant_action_bt_inquiry(btcoexist);
  2589. return;
  2590. } else if (bt_hs_on) {
  2591. halbtc8723b1ant_action_hs(btcoexist);
  2592. return;
  2593. }
  2594. if (BTC_PACKET_DHCP == type ||
  2595. BTC_PACKET_EAPOL == type) {
  2596. BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
  2597. "[BTCoex], special Packet(%d) notify\n", type);
  2598. halbtc8723b1ant_action_wifi_connected_special_packet(btcoexist);
  2599. }
  2600. }
  2601. void ex_halbtc8723b1ant_bt_info_notify(struct btc_coexist *btcoexist,
  2602. u8 *tmp_buf, u8 length)
  2603. {
  2604. u8 bt_info = 0;
  2605. u8 i, rsp_source = 0;
  2606. bool wifi_connected = false;
  2607. bool bt_busy = false;
  2608. coex_sta->c2h_bt_info_req_sent = false;
  2609. rsp_source = tmp_buf[0] & 0xf;
  2610. if (rsp_source >= BT_INFO_SRC_8723B_1ANT_MAX)
  2611. rsp_source = BT_INFO_SRC_8723B_1ANT_WIFI_FW;
  2612. coex_sta->bt_info_c2h_cnt[rsp_source]++;
  2613. BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
  2614. "[BTCoex], Bt info[%d], length=%d, hex data = [",
  2615. rsp_source, length);
  2616. for (i = 0; i < length; i++) {
  2617. coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i];
  2618. if (i == 1)
  2619. bt_info = tmp_buf[i];
  2620. if (i == length - 1)
  2621. BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
  2622. "0x%02x]\n", tmp_buf[i]);
  2623. else
  2624. BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
  2625. "0x%02x, ", tmp_buf[i]);
  2626. }
  2627. if (BT_INFO_SRC_8723B_1ANT_WIFI_FW != rsp_source) {
  2628. coex_sta->bt_retry_cnt = /* [3:0] */
  2629. coex_sta->bt_info_c2h[rsp_source][2] & 0xf;
  2630. coex_sta->bt_rssi =
  2631. coex_sta->bt_info_c2h[rsp_source][3] * 2 + 10;
  2632. coex_sta->bt_info_ext =
  2633. coex_sta->bt_info_c2h[rsp_source][4];
  2634. /* Here we need to resend some wifi info to BT
  2635. * because bt is reset and loss of the info.
  2636. */
  2637. if (coex_sta->bt_info_ext & BIT1) {
  2638. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  2639. "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
  2640. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  2641. &wifi_connected);
  2642. if (wifi_connected)
  2643. ex_halbtc8723b1ant_media_status_notify(btcoexist,
  2644. BTC_MEDIA_CONNECT);
  2645. else
  2646. ex_halbtc8723b1ant_media_status_notify(btcoexist,
  2647. BTC_MEDIA_DISCONNECT);
  2648. }
  2649. if (coex_sta->bt_info_ext & BIT3) {
  2650. if (!btcoexist->manual_control &&
  2651. !btcoexist->stop_coex_dm) {
  2652. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  2653. "[BTCoex], BT ext info bit3 check, set BT NOT ignore Wlan active!!\n");
  2654. halbtc8723b1ant_ignore_wlan_act(btcoexist,
  2655. FORCE_EXEC,
  2656. false);
  2657. }
  2658. } else {
  2659. /* BT already NOT ignore Wlan active, do nothing here.*/
  2660. }
  2661. #if (BT_AUTO_REPORT_ONLY_8723B_1ANT == 0)
  2662. if (coex_sta->bt_info_ext & BIT4) {
  2663. /* BT auto report already enabled, do nothing */
  2664. } else {
  2665. halbtc8723b1ant_bt_auto_report(btcoexist, FORCE_EXEC,
  2666. true);
  2667. }
  2668. #endif
  2669. }
  2670. /* check BIT2 first ==> check if bt is under inquiry or page scan */
  2671. if (bt_info & BT_INFO_8723B_1ANT_B_INQ_PAGE)
  2672. coex_sta->c2h_bt_inquiry_page = true;
  2673. else
  2674. coex_sta->c2h_bt_inquiry_page = false;
  2675. /* set link exist status */
  2676. if (!(bt_info & BT_INFO_8723B_1ANT_B_CONNECTION)) {
  2677. coex_sta->bt_link_exist = false;
  2678. coex_sta->pan_exist = false;
  2679. coex_sta->a2dp_exist = false;
  2680. coex_sta->hid_exist = false;
  2681. coex_sta->sco_exist = false;
  2682. } else { /* connection exists */
  2683. coex_sta->bt_link_exist = true;
  2684. if (bt_info & BT_INFO_8723B_1ANT_B_FTP)
  2685. coex_sta->pan_exist = true;
  2686. else
  2687. coex_sta->pan_exist = false;
  2688. if (bt_info & BT_INFO_8723B_1ANT_B_A2DP)
  2689. coex_sta->a2dp_exist = true;
  2690. else
  2691. coex_sta->a2dp_exist = false;
  2692. if (bt_info & BT_INFO_8723B_1ANT_B_HID)
  2693. coex_sta->hid_exist = true;
  2694. else
  2695. coex_sta->hid_exist = false;
  2696. if (bt_info & BT_INFO_8723B_1ANT_B_SCO_ESCO)
  2697. coex_sta->sco_exist = true;
  2698. else
  2699. coex_sta->sco_exist = false;
  2700. }
  2701. halbtc8723b1ant_update_bt_link_info(btcoexist);
  2702. if (!(bt_info&BT_INFO_8723B_1ANT_B_CONNECTION)) {
  2703. coex_dm->bt_status = BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE;
  2704. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  2705. "[BTCoex], BtInfoNotify(), BT Non-Connected idle!\n");
  2706. /* connection exists but no busy */
  2707. } else if (bt_info == BT_INFO_8723B_1ANT_B_CONNECTION) {
  2708. coex_dm->bt_status = BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE;
  2709. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  2710. "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
  2711. } else if ((bt_info & BT_INFO_8723B_1ANT_B_SCO_ESCO) ||
  2712. (bt_info & BT_INFO_8723B_1ANT_B_SCO_BUSY)) {
  2713. coex_dm->bt_status = BT_8723B_1ANT_BT_STATUS_SCO_BUSY;
  2714. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  2715. "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
  2716. } else if (bt_info & BT_INFO_8723B_1ANT_B_ACL_BUSY) {
  2717. if (BT_8723B_1ANT_BT_STATUS_ACL_BUSY != coex_dm->bt_status)
  2718. coex_dm->auto_tdma_adjust = false;
  2719. coex_dm->bt_status = BT_8723B_1ANT_BT_STATUS_ACL_BUSY;
  2720. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  2721. "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
  2722. } else {
  2723. coex_dm->bt_status =
  2724. BT_8723B_1ANT_BT_STATUS_MAX;
  2725. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  2726. "[BTCoex], BtInfoNotify(), BT Non-Defined state!!\n");
  2727. }
  2728. if ((BT_8723B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
  2729. (BT_8723B_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
  2730. (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
  2731. bt_busy = true;
  2732. else
  2733. bt_busy = false;
  2734. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
  2735. halbtc8723b1ant_run_coexist_mechanism(btcoexist);
  2736. }
  2737. void ex_halbtc8723b1ant_halt_notify(struct btc_coexist *btcoexist)
  2738. {
  2739. BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, "[BTCoex], Halt notify\n");
  2740. btcoexist->stop_coex_dm = true;
  2741. halbtc8723b1ant_SetAntPath(btcoexist, BTC_ANT_PATH_BT, false, true);
  2742. halbtc8723b1ant_wifi_off_hw_cfg(btcoexist);
  2743. halbtc8723b1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
  2744. halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  2745. 0x0, 0x0);
  2746. halbtc8723b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0);
  2747. ex_halbtc8723b1ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT);
  2748. }
  2749. void ex_halbtc8723b1ant_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state)
  2750. {
  2751. BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, "[BTCoex], Pnp notify\n");
  2752. if (BTC_WIFI_PNP_SLEEP == pnp_state) {
  2753. BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
  2754. "[BTCoex], Pnp notify to SLEEP\n");
  2755. btcoexist->stop_coex_dm = true;
  2756. halbtc8723b1ant_SetAntPath(btcoexist, BTC_ANT_PATH_BT, false,
  2757. true);
  2758. halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  2759. 0x0, 0x0);
  2760. halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  2761. halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  2762. halbtc8723b1ant_wifi_off_hw_cfg(btcoexist);
  2763. } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) {
  2764. BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY,
  2765. "[BTCoex], Pnp notify to WAKE UP\n");
  2766. btcoexist->stop_coex_dm = false;
  2767. halbtc8723b1ant_init_hw_config(btcoexist, false);
  2768. halbtc8723b1ant_init_coex_dm(btcoexist);
  2769. halbtc8723b1ant_query_bt_info(btcoexist);
  2770. }
  2771. }
  2772. void ex_halbtc8723b1ant_coex_dm_reset(struct btc_coexist *btcoexist)
  2773. {
  2774. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  2775. "[BTCoex], *****************Coex DM Reset****************\n");
  2776. halbtc8723b1ant_init_hw_config(btcoexist, false);
  2777. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
  2778. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x2, 0xfffff, 0x0);
  2779. halbtc8723b1ant_init_coex_dm(btcoexist);
  2780. }
  2781. void ex_halbtc8723b1ant_periodical(struct btc_coexist *btcoexist)
  2782. {
  2783. struct btc_board_info *board_info = &btcoexist->board_info;
  2784. struct btc_stack_info *stack_info = &btcoexist->stack_info;
  2785. static u8 dis_ver_info_cnt;
  2786. u32 fw_ver = 0, bt_patch_ver = 0;
  2787. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  2788. "[BTCoex], ==========================Periodical===========================\n");
  2789. if (dis_ver_info_cnt <= 5) {
  2790. dis_ver_info_cnt += 1;
  2791. BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT,
  2792. "[BTCoex], ****************************************************************\n");
  2793. BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT,
  2794. "[BTCoex], Ant PG Num/ Ant Mech/ Ant Pos = %d/ %d/ %d\n",
  2795. board_info->pg_ant_num, board_info->btdm_ant_num,
  2796. board_info->btdm_ant_pos);
  2797. BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT,
  2798. "[BTCoex], BT stack/ hci ext ver = %s / %d\n",
  2799. ((stack_info->profile_notified) ? "Yes" : "No"),
  2800. stack_info->hci_version);
  2801. btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER,
  2802. &bt_patch_ver);
  2803. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
  2804. BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT,
  2805. "[BTCoex], CoexVer/ FwVer/ PatchVer = %d_%x/ 0x%x/ 0x%x(%d)\n",
  2806. glcoex_ver_date_8723b_1ant,
  2807. glcoex_ver_8723b_1ant, fw_ver,
  2808. bt_patch_ver, bt_patch_ver);
  2809. BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT,
  2810. "[BTCoex], ****************************************************************\n");
  2811. }
  2812. #if (BT_AUTO_REPORT_ONLY_8723B_1ANT == 0)
  2813. halbtc8723b1ant_query_bt_info(btcoexist);
  2814. halbtc8723b1ant_monitor_bt_ctr(btcoexist);
  2815. halbtc8723b1ant_monitor_bt_enable_disable(btcoexist);
  2816. #else
  2817. if (btc8723b1ant_is_wifi_status_changed(btcoexist) ||
  2818. coex_dm->auto_tdma_adjust) {
  2819. halbtc8723b1ant_run_coexist_mechanism(btcoexist);
  2820. }
  2821. coex_sta->special_pkt_period_cnt++;
  2822. #endif
  2823. }