halbtc8812a1ant.c 103 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461
  1. /* ************************************************************
  2. * Description:
  3. *
  4. * This file is for RTL8812A Co-exist mechanism
  5. *
  6. * History
  7. * 2012/11/15 Cosa first check in.
  8. *
  9. * ************************************************************ */
  10. /* ************************************************************
  11. * include files
  12. * ************************************************************ */
  13. #include "mp_precomp.h"
  14. #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1)
  15. #if (RTL8812A_SUPPORT == 1)
  16. /* ************************************************************
  17. * Global variables, these are static variables
  18. * ************************************************************ */
  19. static u8 *trace_buf = &gl_btc_trace_buf[0];
  20. static struct coex_dm_8812a_1ant glcoex_dm_8812a_1ant;
  21. static struct coex_dm_8812a_1ant *coex_dm = &glcoex_dm_8812a_1ant;
  22. static struct coex_sta_8812a_1ant glcoex_sta_8812a_1ant;
  23. static struct coex_sta_8812a_1ant *coex_sta = &glcoex_sta_8812a_1ant;
  24. const char *const glbt_info_src_8812a_1ant[] = {
  25. "BT Info[wifi fw]",
  26. "BT Info[bt rsp]",
  27. "BT Info[bt auto report]",
  28. };
  29. u32 glcoex_ver_date_8812a_1ant = 20140708;
  30. u32 glcoex_ver_8812a_1ant = 0x52;
  31. /* ************************************************************
  32. * local function proto type if needed
  33. * ************************************************************
  34. * ************************************************************
  35. * local function start with halbtc8812a1ant_
  36. * ************************************************************ */
  37. u8 halbtc8812a1ant_bt_rssi_state(u8 level_num, u8 rssi_thresh, u8 rssi_thresh1)
  38. {
  39. s32 bt_rssi = 0;
  40. u8 bt_rssi_state = coex_sta->pre_bt_rssi_state;
  41. bt_rssi = coex_sta->bt_rssi;
  42. if (level_num == 2) {
  43. if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
  44. (coex_sta->pre_bt_rssi_state ==
  45. BTC_RSSI_STATE_STAY_LOW)) {
  46. if (bt_rssi >= (rssi_thresh +
  47. BTC_RSSI_COEX_THRESH_TOL_8812A_1ANT))
  48. bt_rssi_state = BTC_RSSI_STATE_HIGH;
  49. else
  50. bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  51. } else {
  52. if (bt_rssi < rssi_thresh)
  53. bt_rssi_state = BTC_RSSI_STATE_LOW;
  54. else
  55. bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  56. }
  57. } else if (level_num == 3) {
  58. if (rssi_thresh > rssi_thresh1) {
  59. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  60. "[BTCoex], BT Rssi thresh error!!\n");
  61. BTC_TRACE(trace_buf);
  62. return coex_sta->pre_bt_rssi_state;
  63. }
  64. if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
  65. (coex_sta->pre_bt_rssi_state ==
  66. BTC_RSSI_STATE_STAY_LOW)) {
  67. if (bt_rssi >= (rssi_thresh +
  68. BTC_RSSI_COEX_THRESH_TOL_8812A_1ANT))
  69. bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
  70. else
  71. bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  72. } else if ((coex_sta->pre_bt_rssi_state ==
  73. BTC_RSSI_STATE_MEDIUM) ||
  74. (coex_sta->pre_bt_rssi_state ==
  75. BTC_RSSI_STATE_STAY_MEDIUM)) {
  76. if (bt_rssi >= (rssi_thresh1 +
  77. BTC_RSSI_COEX_THRESH_TOL_8812A_1ANT))
  78. bt_rssi_state = BTC_RSSI_STATE_HIGH;
  79. else if (bt_rssi < rssi_thresh)
  80. bt_rssi_state = BTC_RSSI_STATE_LOW;
  81. else
  82. bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
  83. } else {
  84. if (bt_rssi < rssi_thresh1)
  85. bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
  86. else
  87. bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  88. }
  89. }
  90. coex_sta->pre_bt_rssi_state = bt_rssi_state;
  91. return bt_rssi_state;
  92. }
  93. u8 halbtc8812a1ant_wifi_rssi_state(IN struct btc_coexist *btcoexist,
  94. IN u8 index, IN u8 level_num, IN u8 rssi_thresh, IN u8 rssi_thresh1)
  95. {
  96. s32 wifi_rssi = 0;
  97. u8 wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index];
  98. btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
  99. if (level_num == 2) {
  100. if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW)
  101. ||
  102. (coex_sta->pre_wifi_rssi_state[index] ==
  103. BTC_RSSI_STATE_STAY_LOW)) {
  104. if (wifi_rssi >= (rssi_thresh +
  105. BTC_RSSI_COEX_THRESH_TOL_8812A_1ANT))
  106. wifi_rssi_state = BTC_RSSI_STATE_HIGH;
  107. else
  108. wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  109. } else {
  110. if (wifi_rssi < rssi_thresh)
  111. wifi_rssi_state = BTC_RSSI_STATE_LOW;
  112. else
  113. wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  114. }
  115. } else if (level_num == 3) {
  116. if (rssi_thresh > rssi_thresh1) {
  117. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  118. "[BTCoex], wifi RSSI thresh error!!\n");
  119. BTC_TRACE(trace_buf);
  120. return coex_sta->pre_wifi_rssi_state[index];
  121. }
  122. if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW)
  123. ||
  124. (coex_sta->pre_wifi_rssi_state[index] ==
  125. BTC_RSSI_STATE_STAY_LOW)) {
  126. if (wifi_rssi >= (rssi_thresh +
  127. BTC_RSSI_COEX_THRESH_TOL_8812A_1ANT))
  128. wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
  129. else
  130. wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  131. } else if ((coex_sta->pre_wifi_rssi_state[index] ==
  132. BTC_RSSI_STATE_MEDIUM) ||
  133. (coex_sta->pre_wifi_rssi_state[index] ==
  134. BTC_RSSI_STATE_STAY_MEDIUM)) {
  135. if (wifi_rssi >= (rssi_thresh1 +
  136. BTC_RSSI_COEX_THRESH_TOL_8812A_1ANT))
  137. wifi_rssi_state = BTC_RSSI_STATE_HIGH;
  138. else if (wifi_rssi < rssi_thresh)
  139. wifi_rssi_state = BTC_RSSI_STATE_LOW;
  140. else
  141. wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
  142. } else {
  143. if (wifi_rssi < rssi_thresh1)
  144. wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
  145. else
  146. wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  147. }
  148. }
  149. coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state;
  150. return wifi_rssi_state;
  151. }
  152. void halbtc8812a1ant_update_ra_mask(IN struct btc_coexist *btcoexist,
  153. IN boolean force_exec, IN u32 dis_rate_mask)
  154. {
  155. coex_dm->cur_ra_mask = dis_rate_mask;
  156. if (force_exec || (coex_dm->pre_ra_mask != coex_dm->cur_ra_mask))
  157. btcoexist->btc_set(btcoexist, BTC_SET_ACT_UPDATE_RAMASK,
  158. &coex_dm->cur_ra_mask);
  159. coex_dm->pre_ra_mask = coex_dm->cur_ra_mask;
  160. }
  161. /* to check 0x430/0x434 is correct?? */
  162. void halbtc8812a1ant_auto_rate_fallback_retry(IN struct btc_coexist *btcoexist,
  163. IN boolean force_exec, IN u8 type)
  164. {
  165. boolean wifi_under_b_mode = false;
  166. coex_dm->cur_arfr_type = type;
  167. if (force_exec || (coex_dm->pre_arfr_type != coex_dm->cur_arfr_type)) {
  168. switch (coex_dm->cur_arfr_type) {
  169. case 0: /* normal mode */
  170. btcoexist->btc_write_4byte(btcoexist, 0x430,
  171. coex_dm->backup_arfr_cnt1);
  172. btcoexist->btc_write_4byte(btcoexist, 0x434,
  173. coex_dm->backup_arfr_cnt2);
  174. break;
  175. case 1:
  176. btcoexist->btc_get(btcoexist,
  177. BTC_GET_BL_WIFI_UNDER_B_MODE,
  178. &wifi_under_b_mode);
  179. if (wifi_under_b_mode) {
  180. btcoexist->btc_write_4byte(btcoexist,
  181. 0x430, 0x0);
  182. btcoexist->btc_write_4byte(btcoexist,
  183. 0x434, 0x01010101);
  184. } else {
  185. btcoexist->btc_write_4byte(btcoexist,
  186. 0x430, 0x0);
  187. btcoexist->btc_write_4byte(btcoexist,
  188. 0x434, 0x04030201);
  189. }
  190. break;
  191. default:
  192. break;
  193. }
  194. }
  195. coex_dm->pre_arfr_type = coex_dm->cur_arfr_type;
  196. }
  197. /* to check 0x42a ?? */
  198. void halbtc8812a1ant_retry_limit(IN struct btc_coexist *btcoexist,
  199. IN boolean force_exec, IN u8 type)
  200. {
  201. coex_dm->cur_retry_limit_type = type;
  202. if (force_exec ||
  203. (coex_dm->pre_retry_limit_type !=
  204. coex_dm->cur_retry_limit_type)) {
  205. switch (coex_dm->cur_retry_limit_type) {
  206. case 0: /* normal mode */
  207. btcoexist->btc_write_2byte(btcoexist, 0x42a,
  208. coex_dm->backup_retry_limit);
  209. break;
  210. case 1: /* retry limit=8 */
  211. btcoexist->btc_write_2byte(btcoexist, 0x42a,
  212. 0x0808);
  213. break;
  214. default:
  215. break;
  216. }
  217. }
  218. coex_dm->pre_retry_limit_type = coex_dm->cur_retry_limit_type;
  219. }
  220. /* to check 0x456?? */
  221. void halbtc8812a1ant_ampdu_max_time(IN struct btc_coexist *btcoexist,
  222. IN boolean force_exec, IN u8 type)
  223. {
  224. coex_dm->cur_ampdu_time_type = type;
  225. if (force_exec ||
  226. (coex_dm->pre_ampdu_time_type != coex_dm->cur_ampdu_time_type)) {
  227. switch (coex_dm->cur_ampdu_time_type) {
  228. case 0: /* normal mode */
  229. btcoexist->btc_write_1byte(btcoexist, 0x456,
  230. coex_dm->backup_ampdu_max_time);
  231. break;
  232. case 1: /* AMPDU timw = 0x38 * 32us */
  233. btcoexist->btc_write_1byte(btcoexist, 0x456,
  234. 0x38);
  235. break;
  236. default:
  237. break;
  238. }
  239. }
  240. coex_dm->pre_ampdu_time_type = coex_dm->cur_ampdu_time_type;
  241. }
  242. void halbtc8812a1ant_limited_tx(IN struct btc_coexist *btcoexist,
  243. IN boolean force_exec, IN u8 ra_mask_type, IN u8 arfr_type,
  244. IN u8 retry_limit_type, IN u8 ampdu_time_type)
  245. {
  246. switch (ra_mask_type) {
  247. case 0: /* normal mode */
  248. halbtc8812a1ant_update_ra_mask(btcoexist, force_exec,
  249. 0x0);
  250. break;
  251. case 1: /* disable cck 1/2 */
  252. halbtc8812a1ant_update_ra_mask(btcoexist, force_exec,
  253. 0x00000003);
  254. break;
  255. case 2: /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */
  256. halbtc8812a1ant_update_ra_mask(btcoexist, force_exec,
  257. 0x0001f1f7);
  258. break;
  259. default:
  260. break;
  261. }
  262. halbtc8812a1ant_auto_rate_fallback_retry(btcoexist, force_exec,
  263. arfr_type);
  264. halbtc8812a1ant_retry_limit(btcoexist, force_exec, retry_limit_type);
  265. halbtc8812a1ant_ampdu_max_time(btcoexist, force_exec, ampdu_time_type);
  266. }
  267. void halbtc8812a1ant_limited_rx(IN struct btc_coexist *btcoexist,
  268. IN boolean force_exec, IN boolean rej_ap_agg_pkt,
  269. IN boolean bt_ctrl_agg_buf_size, IN u8 agg_buf_size)
  270. {
  271. boolean reject_rx_agg = rej_ap_agg_pkt;
  272. boolean bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size;
  273. u8 rx_agg_size = agg_buf_size;
  274. /* ============================================ */
  275. /* Rx Aggregation related setting */
  276. /* ============================================ */
  277. btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT,
  278. &reject_rx_agg);
  279. /* decide BT control aggregation buf size or not */
  280. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE,
  281. &bt_ctrl_rx_agg_size);
  282. /* aggregation buf size, only work when BT control Rx aggregation size. */
  283. btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size);
  284. /* real update aggregation setting */
  285. btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
  286. }
  287. void halbtc8812a1ant_query_bt_info(IN struct btc_coexist *btcoexist)
  288. {
  289. u8 data_len = 3;
  290. u8 buf[5] = {0};
  291. if (!coex_sta->bt_disabled) {
  292. if (!coex_sta->bt_info_query_cnt ||
  293. (coex_sta->bt_info_c2h_cnt[BT_INFO_SRC_8812A_1ANT_BT_RSP]
  294. - coex_sta->bt_info_query_cnt) > 2) {
  295. buf[0] = data_len;
  296. buf[1] = 0x1; /* polling enable, 1=enable, 0=disable */
  297. buf[2] = 0x2; /* polling time in seconds */
  298. buf[3] = 0x1; /* auto report enable, 1=enable, 0=disable */
  299. btcoexist->btc_set(btcoexist, BTC_SET_ACT_CTRL_BT_INFO,
  300. (void *)&buf[0]);
  301. }
  302. }
  303. coex_sta->bt_info_query_cnt++;
  304. }
  305. void halbtc8812a1ant_monitor_bt_ctr(IN struct btc_coexist *btcoexist)
  306. {
  307. u32 reg_hp_txrx, reg_lp_txrx, u32tmp;
  308. u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0;
  309. static u8 num_of_bt_counter_chk = 0;
  310. reg_hp_txrx = 0x770;
  311. reg_lp_txrx = 0x774;
  312. u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx);
  313. reg_hp_tx = u32tmp & MASKLWORD;
  314. reg_hp_rx = (u32tmp & MASKHWORD) >> 16;
  315. u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx);
  316. reg_lp_tx = u32tmp & MASKLWORD;
  317. reg_lp_rx = (u32tmp & MASKHWORD) >> 16;
  318. coex_sta->high_priority_tx = reg_hp_tx;
  319. coex_sta->high_priority_rx = reg_hp_rx;
  320. coex_sta->low_priority_tx = reg_lp_tx;
  321. coex_sta->low_priority_rx = reg_lp_rx;
  322. if ((coex_sta->low_priority_tx > 1150) &&
  323. (!coex_sta->c2h_bt_inquiry_page))
  324. coex_sta->pop_event_cnt++;
  325. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  326. "[BTCoex], Hi-Pri Rx/Tx: %d/%d, Lo-Pri Rx/Tx: %d/%d\n",
  327. reg_hp_rx, reg_hp_tx, reg_lp_rx, reg_lp_tx);
  328. BTC_TRACE(trace_buf);
  329. /* reset counter */
  330. btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
  331. if ((reg_hp_tx == 0) && (reg_hp_rx == 0) && (reg_lp_tx == 0) &&
  332. (reg_lp_rx == 0)) {
  333. num_of_bt_counter_chk++;
  334. if (num_of_bt_counter_chk >= 3) {
  335. halbtc8812a1ant_query_bt_info(btcoexist);
  336. num_of_bt_counter_chk = 0;
  337. }
  338. }
  339. }
  340. /* to check registers */
  341. void halbtc8812a1ant_monitor_wifi_ctr(IN struct btc_coexist *btcoexist)
  342. {
  343. s32 wifi_rssi = 0;
  344. boolean wifi_busy = false, wifi_under_b_mode = false;
  345. static u8 cck_lock_counter = 0;
  346. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  347. btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
  348. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
  349. &wifi_under_b_mode);
  350. if (coex_sta->under_ips) {
  351. coex_sta->crc_ok_cck = 0;
  352. coex_sta->crc_ok_11g = 0;
  353. coex_sta->crc_ok_11n = 0;
  354. coex_sta->crc_ok_11n_agg = 0;
  355. coex_sta->crc_err_cck = 0;
  356. coex_sta->crc_err_11g = 0;
  357. coex_sta->crc_err_11n = 0;
  358. coex_sta->crc_err_11n_agg = 0;
  359. } else {
  360. coex_sta->crc_ok_cck = btcoexist->btc_read_2byte(btcoexist,
  361. 0xf04);
  362. coex_sta->crc_ok_11g = btcoexist->btc_read_2byte(btcoexist,
  363. 0xf14);
  364. coex_sta->crc_ok_11n = btcoexist->btc_read_2byte(btcoexist,
  365. 0xf10);
  366. coex_sta->crc_ok_11n_agg = btcoexist->btc_read_2byte(btcoexist,
  367. 0xf40);
  368. coex_sta->crc_err_cck = btcoexist->btc_read_2byte(btcoexist,
  369. 0xf06);
  370. coex_sta->crc_err_11g = btcoexist->btc_read_2byte(btcoexist,
  371. 0xf16);
  372. coex_sta->crc_err_11n = btcoexist->btc_read_2byte(btcoexist,
  373. 0xf12);
  374. coex_sta->crc_err_11n_agg = btcoexist->btc_read_2byte(btcoexist,
  375. 0xf42);
  376. }
  377. /* reset counter */
  378. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xb58, 0x1, 0x1);
  379. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xb58, 0x1, 0x0);
  380. if ((wifi_busy) && (wifi_rssi >= 30) && (!wifi_under_b_mode)) {
  381. if ((coex_dm->bt_status == BT_8812A_1ANT_BT_STATUS_ACL_BUSY) ||
  382. (coex_dm->bt_status ==
  383. BT_8812A_1ANT_BT_STATUS_ACL_SCO_BUSY) ||
  384. (coex_dm->bt_status ==
  385. BT_8812A_1ANT_BT_STATUS_SCO_BUSY)) {
  386. if (coex_sta->crc_ok_cck > (coex_sta->crc_ok_11g +
  387. coex_sta->crc_ok_11n +
  388. coex_sta->crc_ok_11n_agg)) {
  389. if (cck_lock_counter < 5)
  390. cck_lock_counter++;
  391. } else {
  392. if (cck_lock_counter > 0)
  393. cck_lock_counter--;
  394. }
  395. } else {
  396. if (cck_lock_counter > 0)
  397. cck_lock_counter--;
  398. }
  399. } else {
  400. if (cck_lock_counter > 0)
  401. cck_lock_counter--;
  402. }
  403. if (!coex_sta->pre_ccklock) {
  404. if (cck_lock_counter >= 5)
  405. coex_sta->cck_lock = true;
  406. else
  407. coex_sta->cck_lock = false;
  408. } else {
  409. if (cck_lock_counter == 0)
  410. coex_sta->cck_lock = false;
  411. else
  412. coex_sta->cck_lock = true;
  413. }
  414. coex_sta->pre_ccklock = coex_sta->cck_lock;
  415. }
  416. boolean halbtc8812a1ant_is_wifi_status_changed(IN struct btc_coexist *btcoexist)
  417. {
  418. static boolean pre_wifi_busy = false, pre_under_4way = false,
  419. pre_bt_hs_on = false;
  420. boolean wifi_busy = false, under_4way = false, bt_hs_on = false;
  421. boolean wifi_connected = false;
  422. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  423. &wifi_connected);
  424. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  425. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  426. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
  427. &under_4way);
  428. if (wifi_connected) {
  429. if (wifi_busy != pre_wifi_busy) {
  430. pre_wifi_busy = wifi_busy;
  431. return true;
  432. }
  433. if (under_4way != pre_under_4way) {
  434. pre_under_4way = under_4way;
  435. return true;
  436. }
  437. if (bt_hs_on != pre_bt_hs_on) {
  438. pre_bt_hs_on = bt_hs_on;
  439. return true;
  440. }
  441. }
  442. return false;
  443. }
  444. void halbtc8812a1ant_update_bt_link_info(IN struct btc_coexist *btcoexist)
  445. {
  446. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  447. boolean bt_hs_on = false;
  448. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  449. bt_link_info->bt_link_exist = coex_sta->bt_link_exist;
  450. bt_link_info->sco_exist = coex_sta->sco_exist;
  451. bt_link_info->a2dp_exist = coex_sta->a2dp_exist;
  452. bt_link_info->pan_exist = coex_sta->pan_exist;
  453. bt_link_info->hid_exist = coex_sta->hid_exist;
  454. /* work around for HS mode. */
  455. if (bt_hs_on) {
  456. bt_link_info->pan_exist = true;
  457. bt_link_info->bt_link_exist = true;
  458. }
  459. /* check if Sco only */
  460. if (bt_link_info->sco_exist &&
  461. !bt_link_info->a2dp_exist &&
  462. !bt_link_info->pan_exist &&
  463. !bt_link_info->hid_exist)
  464. bt_link_info->sco_only = true;
  465. else
  466. bt_link_info->sco_only = false;
  467. /* check if A2dp only */
  468. if (!bt_link_info->sco_exist &&
  469. bt_link_info->a2dp_exist &&
  470. !bt_link_info->pan_exist &&
  471. !bt_link_info->hid_exist)
  472. bt_link_info->a2dp_only = true;
  473. else
  474. bt_link_info->a2dp_only = false;
  475. /* check if Pan only */
  476. if (!bt_link_info->sco_exist &&
  477. !bt_link_info->a2dp_exist &&
  478. bt_link_info->pan_exist &&
  479. !bt_link_info->hid_exist)
  480. bt_link_info->pan_only = true;
  481. else
  482. bt_link_info->pan_only = false;
  483. /* check if Hid only */
  484. if (!bt_link_info->sco_exist &&
  485. !bt_link_info->a2dp_exist &&
  486. !bt_link_info->pan_exist &&
  487. bt_link_info->hid_exist)
  488. bt_link_info->hid_only = true;
  489. else
  490. bt_link_info->hid_only = false;
  491. }
  492. u8 halbtc8812a1ant_action_algorithm(IN struct btc_coexist *btcoexist)
  493. {
  494. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  495. boolean bt_hs_on = false;
  496. u8 algorithm = BT_8812A_1ANT_COEX_ALGO_UNDEFINED;
  497. u8 num_of_diff_profile = 0;
  498. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  499. if (!bt_link_info->bt_link_exist) {
  500. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  501. "[BTCoex], No BT link exists!!!\n");
  502. BTC_TRACE(trace_buf);
  503. return algorithm;
  504. }
  505. if (bt_link_info->sco_exist)
  506. num_of_diff_profile++;
  507. if (bt_link_info->hid_exist)
  508. num_of_diff_profile++;
  509. if (bt_link_info->pan_exist)
  510. num_of_diff_profile++;
  511. if (bt_link_info->a2dp_exist)
  512. num_of_diff_profile++;
  513. if (num_of_diff_profile == 1) {
  514. if (bt_link_info->sco_exist) {
  515. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  516. "[BTCoex], BT Profile = SCO only\n");
  517. BTC_TRACE(trace_buf);
  518. algorithm = BT_8812A_1ANT_COEX_ALGO_SCO;
  519. } else {
  520. if (bt_link_info->hid_exist) {
  521. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  522. "[BTCoex], BT Profile = HID only\n");
  523. BTC_TRACE(trace_buf);
  524. algorithm = BT_8812A_1ANT_COEX_ALGO_HID;
  525. } else if (bt_link_info->a2dp_exist) {
  526. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  527. "[BTCoex], BT Profile = A2DP only\n");
  528. BTC_TRACE(trace_buf);
  529. algorithm = BT_8812A_1ANT_COEX_ALGO_A2DP;
  530. } else if (bt_link_info->pan_exist) {
  531. if (bt_hs_on) {
  532. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  533. "[BTCoex], BT Profile = PAN(HS) only\n");
  534. BTC_TRACE(trace_buf);
  535. algorithm =
  536. BT_8812A_1ANT_COEX_ALGO_PANHS;
  537. } else {
  538. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  539. "[BTCoex], BT Profile = PAN(EDR) only\n");
  540. BTC_TRACE(trace_buf);
  541. algorithm =
  542. BT_8812A_1ANT_COEX_ALGO_PANEDR;
  543. }
  544. }
  545. }
  546. } else if (num_of_diff_profile == 2) {
  547. if (bt_link_info->sco_exist) {
  548. if (bt_link_info->hid_exist) {
  549. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  550. "[BTCoex], BT Profile = SCO + HID\n");
  551. BTC_TRACE(trace_buf);
  552. algorithm = BT_8812A_1ANT_COEX_ALGO_HID;
  553. } else if (bt_link_info->a2dp_exist) {
  554. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  555. "[BTCoex], BT Profile = SCO + A2DP ==> SCO\n");
  556. BTC_TRACE(trace_buf);
  557. algorithm = BT_8812A_1ANT_COEX_ALGO_SCO;
  558. } else if (bt_link_info->pan_exist) {
  559. if (bt_hs_on) {
  560. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  561. "[BTCoex], BT Profile = SCO + PAN(HS)\n");
  562. BTC_TRACE(trace_buf);
  563. algorithm = BT_8812A_1ANT_COEX_ALGO_SCO;
  564. } else {
  565. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  566. "[BTCoex], BT Profile = SCO + PAN(EDR)\n");
  567. BTC_TRACE(trace_buf);
  568. algorithm =
  569. BT_8812A_1ANT_COEX_ALGO_PANEDR_HID;
  570. }
  571. }
  572. } else {
  573. if (bt_link_info->hid_exist &&
  574. bt_link_info->a2dp_exist) {
  575. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  576. "[BTCoex], BT Profile = HID + A2DP\n");
  577. BTC_TRACE(trace_buf);
  578. algorithm = BT_8812A_1ANT_COEX_ALGO_HID_A2DP;
  579. } else if (bt_link_info->hid_exist &&
  580. bt_link_info->pan_exist) {
  581. if (bt_hs_on) {
  582. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  583. "[BTCoex], BT Profile = HID + PAN(HS)\n");
  584. BTC_TRACE(trace_buf);
  585. algorithm =
  586. BT_8812A_1ANT_COEX_ALGO_HID_A2DP;
  587. } else {
  588. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  589. "[BTCoex], BT Profile = HID + PAN(EDR)\n");
  590. BTC_TRACE(trace_buf);
  591. algorithm =
  592. BT_8812A_1ANT_COEX_ALGO_PANEDR_HID;
  593. }
  594. } else if (bt_link_info->pan_exist &&
  595. bt_link_info->a2dp_exist) {
  596. if (bt_hs_on) {
  597. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  598. "[BTCoex], BT Profile = A2DP + PAN(HS)\n");
  599. BTC_TRACE(trace_buf);
  600. algorithm =
  601. BT_8812A_1ANT_COEX_ALGO_A2DP_PANHS;
  602. } else {
  603. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  604. "[BTCoex], BT Profile = A2DP + PAN(EDR)\n");
  605. BTC_TRACE(trace_buf);
  606. algorithm =
  607. BT_8812A_1ANT_COEX_ALGO_PANEDR_A2DP;
  608. }
  609. }
  610. }
  611. } else if (num_of_diff_profile == 3) {
  612. if (bt_link_info->sco_exist) {
  613. if (bt_link_info->hid_exist &&
  614. bt_link_info->a2dp_exist) {
  615. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  616. "[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n");
  617. BTC_TRACE(trace_buf);
  618. algorithm = BT_8812A_1ANT_COEX_ALGO_HID;
  619. } else if (bt_link_info->hid_exist &&
  620. bt_link_info->pan_exist) {
  621. if (bt_hs_on) {
  622. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  623. "[BTCoex], BT Profile = SCO + HID + PAN(HS)\n");
  624. BTC_TRACE(trace_buf);
  625. algorithm =
  626. BT_8812A_1ANT_COEX_ALGO_HID_A2DP;
  627. } else {
  628. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  629. "[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n");
  630. BTC_TRACE(trace_buf);
  631. algorithm =
  632. BT_8812A_1ANT_COEX_ALGO_PANEDR_HID;
  633. }
  634. } else if (bt_link_info->pan_exist &&
  635. bt_link_info->a2dp_exist) {
  636. if (bt_hs_on) {
  637. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  638. "[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n");
  639. BTC_TRACE(trace_buf);
  640. algorithm = BT_8812A_1ANT_COEX_ALGO_SCO;
  641. } else {
  642. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  643. "[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n");
  644. BTC_TRACE(trace_buf);
  645. algorithm =
  646. BT_8812A_1ANT_COEX_ALGO_PANEDR_HID;
  647. }
  648. }
  649. } else {
  650. if (bt_link_info->hid_exist &&
  651. bt_link_info->pan_exist &&
  652. bt_link_info->a2dp_exist) {
  653. if (bt_hs_on) {
  654. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  655. "[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n");
  656. BTC_TRACE(trace_buf);
  657. algorithm =
  658. BT_8812A_1ANT_COEX_ALGO_HID_A2DP;
  659. } else {
  660. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  661. "[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n");
  662. BTC_TRACE(trace_buf);
  663. algorithm =
  664. BT_8812A_1ANT_COEX_ALGO_HID_A2DP_PANEDR;
  665. }
  666. }
  667. }
  668. } else if (num_of_diff_profile >= 3) {
  669. if (bt_link_info->sco_exist) {
  670. if (bt_link_info->hid_exist &&
  671. bt_link_info->pan_exist &&
  672. bt_link_info->a2dp_exist) {
  673. if (bt_hs_on) {
  674. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  675. "[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n");
  676. BTC_TRACE(trace_buf);
  677. } else {
  678. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  679. "[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n");
  680. BTC_TRACE(trace_buf);
  681. algorithm =
  682. BT_8812A_1ANT_COEX_ALGO_PANEDR_HID;
  683. }
  684. }
  685. }
  686. }
  687. return algorithm;
  688. }
  689. void halbtc8812a1ant_set_bt_auto_report(IN struct btc_coexist *btcoexist,
  690. IN boolean enable_auto_report)
  691. {
  692. u8 h2c_parameter[1] = {0};
  693. h2c_parameter[0] = 0;
  694. if (enable_auto_report)
  695. h2c_parameter[0] |= BIT(0);
  696. btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter);
  697. }
  698. void halbtc8812a1ant_bt_auto_report(IN struct btc_coexist *btcoexist,
  699. IN boolean force_exec, IN boolean enable_auto_report)
  700. {
  701. coex_dm->cur_bt_auto_report = enable_auto_report;
  702. if (!force_exec) {
  703. if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report)
  704. return;
  705. }
  706. halbtc8812a1ant_set_bt_auto_report(btcoexist,
  707. coex_dm->cur_bt_auto_report);
  708. coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report;
  709. }
  710. /* to check */
  711. void halbtc8812a1ant_set_sw_penalty_tx_rate_adaptive(IN struct btc_coexist
  712. *btcoexist, IN boolean low_penalty_ra)
  713. {
  714. u8 tmp_u1;
  715. tmp_u1 = btcoexist->btc_read_1byte(btcoexist, 0x4fd);
  716. tmp_u1 |= BIT(0);
  717. if (low_penalty_ra) {
  718. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  719. "[BTCoex], Tx rate adaptive, set low penalty!!\n");
  720. BTC_TRACE(trace_buf);
  721. tmp_u1 &= ~BIT(2);
  722. } else {
  723. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  724. "[BTCoex], Tx rate adaptive, set normal!!\n");
  725. BTC_TRACE(trace_buf);
  726. tmp_u1 |= BIT(2);
  727. }
  728. btcoexist->btc_write_1byte(btcoexist, 0x4fd, tmp_u1);
  729. }
  730. void halbtc8812a1ant_low_penalty_ra(IN struct btc_coexist *btcoexist,
  731. IN boolean force_exec, IN boolean low_penalty_ra)
  732. {
  733. coex_dm->cur_low_penalty_ra = low_penalty_ra;
  734. if (!force_exec) {
  735. if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra)
  736. return;
  737. }
  738. halbtc8812a1ant_set_sw_penalty_tx_rate_adaptive(btcoexist,
  739. coex_dm->cur_low_penalty_ra);
  740. coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra;
  741. }
  742. void halbtc8812a1ant_set_coex_table(IN struct btc_coexist *btcoexist,
  743. IN u32 val0x6c0, IN u32 val0x6c4, IN u32 val0x6c8, IN u8 val0x6cc)
  744. {
  745. btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0);
  746. btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4);
  747. btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8);
  748. btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc);
  749. }
  750. void halbtc8812a1ant_coex_table(IN struct btc_coexist *btcoexist,
  751. IN boolean force_exec, IN u32 val0x6c0, IN u32 val0x6c4,
  752. IN u32 val0x6c8, IN u8 val0x6cc)
  753. {
  754. coex_dm->cur_val0x6c0 = val0x6c0;
  755. coex_dm->cur_val0x6c4 = val0x6c4;
  756. coex_dm->cur_val0x6c8 = val0x6c8;
  757. coex_dm->cur_val0x6cc = val0x6cc;
  758. if (!force_exec) {
  759. if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) &&
  760. (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) &&
  761. (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) &&
  762. (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc))
  763. return;
  764. }
  765. halbtc8812a1ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8,
  766. val0x6cc);
  767. coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0;
  768. coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4;
  769. coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8;
  770. coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc;
  771. }
  772. void halbtc8812a1ant_coex_table_with_type(IN struct btc_coexist *btcoexist,
  773. IN boolean force_exec, IN u8 type)
  774. {
  775. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  776. "[BTCoex], ********** CoexTable(%d) **********\n", type);
  777. BTC_TRACE(trace_buf);
  778. coex_sta->coex_table_type = type;
  779. switch (type) {
  780. case 0:
  781. halbtc8812a1ant_coex_table(btcoexist, force_exec,
  782. 0x55555555, 0x55555555, 0xffffff, 0x3);
  783. break;
  784. case 1:
  785. halbtc8812a1ant_coex_table(btcoexist, force_exec,
  786. 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3);
  787. break;
  788. case 2:
  789. halbtc8812a1ant_coex_table(btcoexist, force_exec,
  790. 0x5a5a5a5a, 0x5a5a5a5a, 0xffffff, 0x3);
  791. break;
  792. case 3:
  793. halbtc8812a1ant_coex_table(btcoexist, force_exec,
  794. 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3);
  795. break;
  796. case 4:
  797. halbtc8812a1ant_coex_table(btcoexist, force_exec,
  798. 0x55555555, 0xaaaa5a5a, 0xffffff, 0x3);
  799. break;
  800. case 5:
  801. halbtc8812a1ant_coex_table(btcoexist, force_exec,
  802. 0x5a5a5a5a, 0xaa5a5a5a, 0xffffff, 0x3);
  803. break;
  804. case 6:
  805. halbtc8812a1ant_coex_table(btcoexist, force_exec,
  806. 0x55555555, 0xaaaaaaaa, 0xffffff, 0x3);
  807. break;
  808. case 7:
  809. halbtc8812a1ant_coex_table(btcoexist, force_exec,
  810. 0xaaaaaaaa, 0xaaaaaaaa, 0xffffff, 0x3);
  811. break;
  812. default:
  813. break;
  814. }
  815. }
  816. void halbtc8812a1ant_set_fw_ignore_wlan_act(IN struct btc_coexist *btcoexist,
  817. IN boolean enable)
  818. {
  819. u8 data_len = 3;
  820. u8 buf[5] = {0};
  821. buf[0] = data_len;
  822. buf[1] = 0x1; /* OP_Code */
  823. buf[2] = 0x1; /* OP_Code_Length */
  824. if (enable)
  825. buf[3] = 0x1; /* OP_Code_Content */
  826. else
  827. buf[3] = 0x0;
  828. btcoexist->btc_set(btcoexist, BTC_SET_ACT_CTRL_BT_COEX,
  829. (void *)&buf[0]);
  830. }
  831. void halbtc8812a1ant_ignore_wlan_act(IN struct btc_coexist *btcoexist,
  832. IN boolean force_exec, IN boolean enable)
  833. {
  834. coex_dm->cur_ignore_wlan_act = enable;
  835. if (!force_exec) {
  836. if (coex_dm->pre_ignore_wlan_act ==
  837. coex_dm->cur_ignore_wlan_act)
  838. return;
  839. }
  840. halbtc8812a1ant_set_fw_ignore_wlan_act(btcoexist, enable);
  841. coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act;
  842. }
  843. void halbtc8812a1ant_set_lps_rpwm(IN struct btc_coexist *btcoexist,
  844. IN u8 lps_val, IN u8 rpwm_val)
  845. {
  846. u8 lps = lps_val;
  847. u8 rpwm = rpwm_val;
  848. btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps);
  849. btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
  850. }
  851. void halbtc8812a1ant_lps_rpwm(IN struct btc_coexist *btcoexist,
  852. IN boolean force_exec, IN u8 lps_val, IN u8 rpwm_val)
  853. {
  854. coex_dm->cur_lps = lps_val;
  855. coex_dm->cur_rpwm = rpwm_val;
  856. if (!force_exec) {
  857. if ((coex_dm->pre_lps == coex_dm->cur_lps) &&
  858. (coex_dm->pre_rpwm == coex_dm->cur_rpwm))
  859. return;
  860. }
  861. halbtc8812a1ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val);
  862. coex_dm->pre_lps = coex_dm->cur_lps;
  863. coex_dm->pre_rpwm = coex_dm->cur_rpwm;
  864. }
  865. void halbtc8812a1ant_sw_mechanism(IN struct btc_coexist *btcoexist,
  866. IN boolean low_penalty_ra)
  867. {
  868. halbtc8812a1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra);
  869. }
  870. /* to check force_exec */
  871. void halbtc8812a1ant_set_ant_path(IN struct btc_coexist *btcoexist,
  872. IN u8 ant_pos_type, IN boolean force_exec, IN boolean init_hwcfg,
  873. IN boolean wifi_off)
  874. {
  875. u8 u8tmp = 0;
  876. coex_dm->cur_ant_pos_type = ant_pos_type;
  877. if (init_hwcfg) {
  878. btcoexist->btc_write_1byte(btcoexist, 0xcb3, 0x77);
  879. btcoexist->btc_write_4byte(btcoexist, 0x900, 0x00000400);
  880. btcoexist->btc_write_1byte(btcoexist, 0x76d, 0x1);
  881. } else if (wifi_off) {
  882. btcoexist->btc_write_1byte(btcoexist, 0xcb3, 0x77);
  883. u8tmp = btcoexist->btc_read_1byte(btcoexist, 0xcb7);
  884. u8tmp &= ~BIT(3);
  885. u8tmp |= BIT(2);
  886. btcoexist->btc_write_1byte(btcoexist, 0xcb7, u8tmp);
  887. }
  888. if (force_exec ||
  889. (coex_dm->cur_ant_pos_type != coex_dm->pre_ant_pos_type)) {
  890. /* ext switch setting */
  891. switch (ant_pos_type) {
  892. case BTC_ANT_PATH_WIFI:
  893. u8tmp = btcoexist->btc_read_1byte(btcoexist,
  894. 0xcb7);
  895. u8tmp |= BIT(3);
  896. u8tmp &= ~BIT(2);
  897. btcoexist->btc_write_1byte(btcoexist, 0xcb7,
  898. u8tmp);
  899. break;
  900. case BTC_ANT_PATH_BT:
  901. u8tmp = btcoexist->btc_read_1byte(btcoexist,
  902. 0xcb7);
  903. u8tmp &= ~BIT(3);
  904. u8tmp |= BIT(2);
  905. btcoexist->btc_write_1byte(btcoexist, 0xcb7,
  906. u8tmp);
  907. break;
  908. default:
  909. case BTC_ANT_PATH_PTA:
  910. u8tmp = btcoexist->btc_read_1byte(btcoexist,
  911. 0xcb7);
  912. u8tmp |= BIT(3);
  913. u8tmp &= ~BIT(2);
  914. btcoexist->btc_write_1byte(btcoexist, 0xcb7,
  915. u8tmp);
  916. break;
  917. }
  918. }
  919. coex_dm->pre_ant_pos_type = coex_dm->cur_ant_pos_type;
  920. }
  921. void halbtc8812a1ant_set_fw_pstdma(IN struct btc_coexist *btcoexist,
  922. IN u8 byte1, IN u8 byte2, IN u8 byte3, IN u8 byte4, IN u8 byte5)
  923. {
  924. u8 h2c_parameter[5] = {0};
  925. u8 real_byte1 = byte1, real_byte5 = byte5;
  926. boolean ap_enable = false;
  927. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
  928. &ap_enable);
  929. if (ap_enable) {
  930. if (byte1 & BIT(4) && !(byte1 & BIT(5))) {
  931. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  932. "[BTCoex], FW for 1Ant AP mode\n");
  933. BTC_TRACE(trace_buf);
  934. real_byte1 &= ~BIT(4);
  935. real_byte1 |= BIT(5);
  936. real_byte5 |= BIT(5);
  937. real_byte5 &= ~BIT(6);
  938. }
  939. }
  940. h2c_parameter[0] = real_byte1;
  941. h2c_parameter[1] = byte2;
  942. h2c_parameter[2] = byte3;
  943. h2c_parameter[3] = byte4;
  944. h2c_parameter[4] = real_byte5;
  945. coex_dm->ps_tdma_para[0] = real_byte1;
  946. coex_dm->ps_tdma_para[1] = byte2;
  947. coex_dm->ps_tdma_para[2] = byte3;
  948. coex_dm->ps_tdma_para[3] = byte4;
  949. coex_dm->ps_tdma_para[4] = real_byte5;
  950. btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter);
  951. }
  952. void halbtc8812a1ant_ps_tdma(IN struct btc_coexist *btcoexist,
  953. IN boolean force_exec, IN boolean turn_on, IN u8 type)
  954. {
  955. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  956. boolean wifi_busy = false;
  957. u8 rssi_adjust_val = 0;
  958. u8 ps_tdma_byte4_val = 0x50, ps_tdma_byte0_val = 0x51,
  959. ps_tdma_byte3_val = 0x10;
  960. s8 wifi_duration_adjust = 0x0;
  961. static boolean pre_wifi_busy = false;
  962. coex_dm->cur_ps_tdma_on = turn_on;
  963. coex_dm->cur_ps_tdma = type;
  964. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  965. if (wifi_busy != pre_wifi_busy) {
  966. force_exec = true;
  967. pre_wifi_busy = wifi_busy;
  968. }
  969. if (coex_dm->cur_ps_tdma_on) {
  970. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  971. "[BTCoex], ********** TDMA(on, %d) **********\n",
  972. coex_dm->cur_ps_tdma);
  973. BTC_TRACE(trace_buf);
  974. } else {
  975. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  976. "[BTCoex], ********** TDMA(off, %d) **********\n",
  977. coex_dm->cur_ps_tdma);
  978. BTC_TRACE(trace_buf);
  979. }
  980. if (!force_exec) {
  981. if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) &&
  982. (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma))
  983. return;
  984. }
  985. if (coex_sta->scan_ap_num <= 5)
  986. wifi_duration_adjust = 2;
  987. else if (coex_sta->scan_ap_num >= 40)
  988. wifi_duration_adjust = -15;
  989. else if (coex_sta->scan_ap_num >= 20)
  990. wifi_duration_adjust = -10;
  991. if (!coex_sta->force_lps_on) { /* only for A2DP-only case 1/2/9/11 while wifi noisy threshold > 30 */
  992. ps_tdma_byte0_val = 0x61; /* no null-pkt */
  993. ps_tdma_byte3_val = 0x11; /* no tx-pause at BT-slot */
  994. ps_tdma_byte4_val = 0x10; /* 0x778 = d/1 toggle */
  995. }
  996. if ((type == 3) || (type == 13) || (type == 14)) {
  997. ps_tdma_byte4_val = ps_tdma_byte4_val &
  998. 0xbf; /* no dynamic slot for multi-profile */
  999. if (!wifi_busy)
  1000. ps_tdma_byte4_val = ps_tdma_byte4_val |
  1001. 0x1; /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */
  1002. }
  1003. if (bt_link_info->slave_role == true)
  1004. ps_tdma_byte4_val = ps_tdma_byte4_val |
  1005. 0x1; /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */
  1006. if (turn_on) {
  1007. switch (type) {
  1008. default:
  1009. halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x51,
  1010. 0x1a, 0x1a, 0x0, ps_tdma_byte4_val);
  1011. break;
  1012. case 1:
  1013. halbtc8812a1ant_set_fw_pstdma(btcoexist,
  1014. ps_tdma_byte0_val, 0x3a +
  1015. wifi_duration_adjust, 0x03,
  1016. ps_tdma_byte3_val, ps_tdma_byte4_val);
  1017. break;
  1018. case 2:
  1019. halbtc8812a1ant_set_fw_pstdma(btcoexist,
  1020. ps_tdma_byte0_val, 0x2d +
  1021. wifi_duration_adjust, 0x03,
  1022. ps_tdma_byte3_val, ps_tdma_byte4_val);
  1023. break;
  1024. case 3:
  1025. halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x51,
  1026. 0x1d, 0x1d, 0x0, ps_tdma_byte4_val);
  1027. break;
  1028. case 4:
  1029. halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x93,
  1030. 0x15, 0x3, 0x14, 0x0);
  1031. break;
  1032. case 5:
  1033. halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x61,
  1034. 0x15, 0x3, 0x11, 0x11);
  1035. break;
  1036. case 6:
  1037. halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x61,
  1038. 0x20, 0x3, 0x11, 0x11);
  1039. break;
  1040. case 7:
  1041. halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x13,
  1042. 0xc, 0x5, 0x0, 0x0);
  1043. break;
  1044. case 8:
  1045. halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x93,
  1046. 0x25, 0x3, 0x10, 0x0);
  1047. break;
  1048. case 9:
  1049. halbtc8812a1ant_set_fw_pstdma(btcoexist,
  1050. ps_tdma_byte0_val, 0x21, 0x3,
  1051. ps_tdma_byte3_val, ps_tdma_byte4_val);
  1052. break;
  1053. case 10:
  1054. halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x13,
  1055. 0xa, 0xa, 0x0, 0x40);
  1056. break;
  1057. case 11:
  1058. halbtc8812a1ant_set_fw_pstdma(btcoexist,
  1059. ps_tdma_byte0_val, 0x21, 0x03,
  1060. ps_tdma_byte3_val, ps_tdma_byte4_val);
  1061. break;
  1062. case 12:
  1063. halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x51,
  1064. 0x0a, 0x0a, 0x0, 0x50);
  1065. break;
  1066. case 13:
  1067. halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x51,
  1068. 0x12, 0x12, 0x0, ps_tdma_byte4_val);
  1069. break;
  1070. case 14:
  1071. halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x51,
  1072. 0x21, 0x3, 0x10, ps_tdma_byte4_val);
  1073. break;
  1074. case 15:
  1075. halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x13,
  1076. 0xa, 0x3, 0x8, 0x0);
  1077. break;
  1078. case 16:
  1079. halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x93,
  1080. 0x15, 0x3, 0x10, 0x0);
  1081. break;
  1082. case 18:
  1083. halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x93,
  1084. 0x25, 0x3, 0x10, 0x0);
  1085. break;
  1086. case 20:
  1087. halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x61,
  1088. 0x3f, 0x03, 0x11, 0x10);
  1089. break;
  1090. case 21:
  1091. halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x61,
  1092. 0x25, 0x03, 0x11, 0x11);
  1093. break;
  1094. case 22:
  1095. halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x61,
  1096. 0x25, 0x03, 0x11, 0x10);
  1097. break;
  1098. case 23:
  1099. halbtc8812a1ant_set_fw_pstdma(btcoexist, 0xe3,
  1100. 0x25, 0x3, 0x31, 0x18);
  1101. break;
  1102. case 24:
  1103. halbtc8812a1ant_set_fw_pstdma(btcoexist, 0xe3,
  1104. 0x15, 0x3, 0x31, 0x18);
  1105. break;
  1106. case 25:
  1107. halbtc8812a1ant_set_fw_pstdma(btcoexist, 0xe3,
  1108. 0xa, 0x3, 0x31, 0x18);
  1109. break;
  1110. case 26:
  1111. halbtc8812a1ant_set_fw_pstdma(btcoexist, 0xe3,
  1112. 0xa, 0x3, 0x31, 0x18);
  1113. break;
  1114. case 27:
  1115. halbtc8812a1ant_set_fw_pstdma(btcoexist, 0xe3,
  1116. 0x25, 0x3, 0x31, 0x98);
  1117. break;
  1118. case 28:
  1119. halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x69,
  1120. 0x25, 0x3, 0x31, 0x0);
  1121. break;
  1122. case 29:
  1123. halbtc8812a1ant_set_fw_pstdma(btcoexist, 0xab,
  1124. 0x1a, 0x1a, 0x1, 0x10);
  1125. break;
  1126. case 30:
  1127. halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x51,
  1128. 0x30, 0x3, 0x10, 0x10);
  1129. break;
  1130. case 31:
  1131. halbtc8812a1ant_set_fw_pstdma(btcoexist, 0xd3,
  1132. 0x1a, 0x1a, 0, 0x58);
  1133. break;
  1134. case 32:
  1135. halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x61,
  1136. 0x35, 0x3, 0x11, 0x11);
  1137. break;
  1138. case 33:
  1139. halbtc8812a1ant_set_fw_pstdma(btcoexist, 0xa3,
  1140. 0x25, 0x3, 0x30, 0x90);
  1141. break;
  1142. case 34:
  1143. halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x53,
  1144. 0x1a, 0x1a, 0x0, 0x10);
  1145. break;
  1146. case 35:
  1147. halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x63,
  1148. 0x1a, 0x1a, 0x0, 0x10);
  1149. break;
  1150. case 36:
  1151. halbtc8812a1ant_set_fw_pstdma(btcoexist, 0xd3,
  1152. 0x12, 0x3, 0x14, 0x50);
  1153. break;
  1154. case 40: /* SoftAP only with no sta associated,BT disable ,TDMA mode for power saving */
  1155. /* here softap mode screen off will cost 70-80mA for phone */
  1156. halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x23,
  1157. 0x18, 0x00, 0x10, 0x24);
  1158. break;
  1159. }
  1160. } else {
  1161. /* disable PS tdma */
  1162. switch (type) {
  1163. case 8: /* PTA Control */
  1164. halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x8,
  1165. 0x0, 0x0, 0x0, 0x0);
  1166. break;
  1167. case 0:
  1168. default: /* Software control, Antenna at BT side */
  1169. halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x0,
  1170. 0x0, 0x0, 0x0, 0x0);
  1171. break;
  1172. }
  1173. }
  1174. rssi_adjust_val = 0;
  1175. btcoexist->btc_set(btcoexist,
  1176. BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE, &rssi_adjust_val);
  1177. /* update pre state */
  1178. coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on;
  1179. coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma;
  1180. }
  1181. boolean halbtc8812a1ant_is_common_action(IN struct btc_coexist *btcoexist)
  1182. {
  1183. boolean common = false, wifi_connected = false, wifi_busy = false;
  1184. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  1185. &wifi_connected);
  1186. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  1187. if (!wifi_connected &&
  1188. BT_8812A_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
  1189. coex_dm->bt_status) {
  1190. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1191. "[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n");
  1192. BTC_TRACE(trace_buf);
  1193. /* halbtc8812a1ant_sw_mechanism(btcoexist, false); */
  1194. common = true;
  1195. } else if (wifi_connected &&
  1196. (BT_8812A_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
  1197. coex_dm->bt_status)) {
  1198. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1199. "[BTCoex], Wifi connected + BT non connected-idle!!\n");
  1200. BTC_TRACE(trace_buf);
  1201. /* halbtc8812a1ant_sw_mechanism(btcoexist, false); */
  1202. common = true;
  1203. } else if (!wifi_connected &&
  1204. (BT_8812A_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)) {
  1205. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1206. "[BTCoex], Wifi non connected-idle + BT connected-idle!!\n");
  1207. BTC_TRACE(trace_buf);
  1208. /* halbtc8812a1ant_sw_mechanism(btcoexist, false); */
  1209. common = true;
  1210. } else if (wifi_connected &&
  1211. (BT_8812A_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)) {
  1212. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1213. "[BTCoex], Wifi connected + BT connected-idle!!\n");
  1214. BTC_TRACE(trace_buf);
  1215. /* halbtc8812a1ant_sw_mechanism(btcoexist, false); */
  1216. common = true;
  1217. } else if (!wifi_connected &&
  1218. (BT_8812A_1ANT_BT_STATUS_CONNECTED_IDLE != coex_dm->bt_status)) {
  1219. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1220. "[BTCoex], Wifi non connected-idle + BT Busy!!\n");
  1221. BTC_TRACE(trace_buf);
  1222. /* halbtc8812a1ant_sw_mechanism(btcoexist, false); */
  1223. common = true;
  1224. } else {
  1225. if (wifi_busy) {
  1226. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1227. "[BTCoex], Wifi Connected-Busy + BT Busy!!\n");
  1228. BTC_TRACE(trace_buf);
  1229. } else {
  1230. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1231. "[BTCoex], Wifi Connected-Idle + BT Busy!!\n");
  1232. BTC_TRACE(trace_buf);
  1233. }
  1234. common = false;
  1235. }
  1236. return common;
  1237. }
  1238. void halbtc8812a1ant_tdma_duration_adjust_for_acl(IN struct btc_coexist
  1239. *btcoexist, IN u8 wifi_status)
  1240. {
  1241. static s32 up, dn, m, n, wait_count;
  1242. s32 result; /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */
  1243. u8 retry_count = 0, bt_info_ext;
  1244. boolean wifi_busy = false;
  1245. if (BT_8812A_1ANT_WIFI_STATUS_CONNECTED_BUSY == wifi_status)
  1246. wifi_busy = true;
  1247. else
  1248. wifi_busy = false;
  1249. if ((BT_8812A_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN ==
  1250. wifi_status) ||
  1251. (BT_8812A_1ANT_WIFI_STATUS_CONNECTED_SCAN == wifi_status) ||
  1252. (BT_8812A_1ANT_WIFI_STATUS_CONNECTED_SPECIFIC_PKT ==
  1253. wifi_status)) {
  1254. if (coex_dm->cur_ps_tdma != 1 &&
  1255. coex_dm->cur_ps_tdma != 2 &&
  1256. coex_dm->cur_ps_tdma != 3 &&
  1257. coex_dm->cur_ps_tdma != 9) {
  1258. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  1259. 9);
  1260. coex_dm->ps_tdma_du_adj_type = 9;
  1261. up = 0;
  1262. dn = 0;
  1263. m = 1;
  1264. n = 3;
  1265. result = 0;
  1266. wait_count = 0;
  1267. }
  1268. return;
  1269. }
  1270. if (!coex_dm->auto_tdma_adjust) {
  1271. coex_dm->auto_tdma_adjust = true;
  1272. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 2);
  1273. coex_dm->ps_tdma_du_adj_type = 2;
  1274. /* ============ */
  1275. up = 0;
  1276. dn = 0;
  1277. m = 1;
  1278. n = 3;
  1279. result = 0;
  1280. wait_count = 0;
  1281. } else {
  1282. /* acquire the BT TRx retry count from BT_Info byte2 */
  1283. retry_count = coex_sta->bt_retry_cnt;
  1284. bt_info_ext = coex_sta->bt_info_ext;
  1285. if ((coex_sta->low_priority_tx) > 1150 ||
  1286. (coex_sta->low_priority_rx) > 1250)
  1287. retry_count++;
  1288. result = 0;
  1289. wait_count++;
  1290. if (retry_count ==
  1291. 0) { /* no retry in the last 2-second duration */
  1292. up++;
  1293. dn--;
  1294. if (dn <= 0)
  1295. dn = 0;
  1296. if (up >= n) { /* if retry count during continuous n*2 seconds is 0, enlarge WiFi duration */
  1297. wait_count = 0;
  1298. n = 3;
  1299. up = 0;
  1300. dn = 0;
  1301. result = 1;
  1302. }
  1303. } else if (retry_count <=
  1304. 3) { /* <=3 retry in the last 2-second duration */
  1305. up--;
  1306. dn++;
  1307. if (up <= 0)
  1308. up = 0;
  1309. if (dn == 2) { /* if continuous 2 retry count(every 2 seconds) >0 and < 3, reduce WiFi duration */
  1310. if (wait_count <= 2)
  1311. m++; /* to avoid loop between the two levels */
  1312. else
  1313. m = 1;
  1314. if (m >= 20) /* maximum of m = 20 ' will recheck if need to adjust wifi duration in maximum time interval 120 seconds */
  1315. m = 20;
  1316. n = 3 * m;
  1317. up = 0;
  1318. dn = 0;
  1319. wait_count = 0;
  1320. result = -1;
  1321. }
  1322. } else { /* retry count > 3, once retry count > 3, to reduce WiFi duration */
  1323. if (wait_count == 1)
  1324. m++; /* to avoid loop between the two levels */
  1325. else
  1326. m = 1;
  1327. if (m >= 20) /* maximum of m = 20 ' will recheck if need to adjust wifi duration in maximum time interval 120 seconds */
  1328. m = 20;
  1329. n = 3 * m;
  1330. up = 0;
  1331. dn = 0;
  1332. wait_count = 0;
  1333. result = -1;
  1334. }
  1335. if (result == -1) {
  1336. if ((BT_INFO_8812A_1ANT_A2DP_BASIC_RATE(bt_info_ext)) &&
  1337. ((coex_dm->cur_ps_tdma == 1) ||
  1338. (coex_dm->cur_ps_tdma == 2))) {
  1339. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1340. true, 9);
  1341. coex_dm->ps_tdma_du_adj_type = 9;
  1342. } else if (coex_dm->cur_ps_tdma == 1) {
  1343. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1344. true, 2);
  1345. coex_dm->ps_tdma_du_adj_type = 2;
  1346. } else if (coex_dm->cur_ps_tdma == 2) {
  1347. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1348. true, 9);
  1349. coex_dm->ps_tdma_du_adj_type = 9;
  1350. } else if (coex_dm->cur_ps_tdma == 9) {
  1351. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1352. true, 11);
  1353. coex_dm->ps_tdma_du_adj_type = 11;
  1354. }
  1355. } else if (result == 1) {
  1356. if ((BT_INFO_8812A_1ANT_A2DP_BASIC_RATE(bt_info_ext)) &&
  1357. ((coex_dm->cur_ps_tdma == 1) ||
  1358. (coex_dm->cur_ps_tdma == 2))) {
  1359. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1360. true, 9);
  1361. coex_dm->ps_tdma_du_adj_type = 9;
  1362. } else if (coex_dm->cur_ps_tdma == 11) {
  1363. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1364. true, 9);
  1365. coex_dm->ps_tdma_du_adj_type = 9;
  1366. } else if (coex_dm->cur_ps_tdma == 9) {
  1367. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1368. true, 2);
  1369. coex_dm->ps_tdma_du_adj_type = 2;
  1370. } else if (coex_dm->cur_ps_tdma == 2) {
  1371. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1372. true, 1);
  1373. coex_dm->ps_tdma_du_adj_type = 1;
  1374. }
  1375. } else { /* no change */
  1376. /* Bryant Modify
  1377. if(wifi_busy != pre_wifi_busy)
  1378. {
  1379. pre_wifi_busy = wifi_busy;
  1380. halbtc8812a1ant_ps_tdma(btcoexist, FORCE_EXEC, true, coex_dm->cur_ps_tdma);
  1381. }
  1382. */
  1383. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1384. "[BTCoex], ********** TDMA(on, %d) **********\n",
  1385. coex_dm->cur_ps_tdma);
  1386. BTC_TRACE(trace_buf);
  1387. }
  1388. if (coex_dm->cur_ps_tdma != 1 &&
  1389. coex_dm->cur_ps_tdma != 2 &&
  1390. coex_dm->cur_ps_tdma != 9 &&
  1391. coex_dm->cur_ps_tdma != 11) {
  1392. /* recover to previous adjust type */
  1393. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  1394. coex_dm->ps_tdma_du_adj_type);
  1395. }
  1396. }
  1397. }
  1398. void halbtc8812a1ant_ps_tdma_check_for_power_save_state(
  1399. IN struct btc_coexist *btcoexist, IN boolean new_ps_state)
  1400. {
  1401. u8 lps_mode = 0x0;
  1402. btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode);
  1403. if (lps_mode) { /* already under LPS state */
  1404. if (new_ps_state) {
  1405. /* keep state under LPS, do nothing. */
  1406. } else {
  1407. /* will leave LPS state, turn off psTdma first */
  1408. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
  1409. 8);
  1410. }
  1411. } else { /* NO PS state */
  1412. if (new_ps_state) {
  1413. /* will enter LPS state, turn off psTdma first */
  1414. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
  1415. 8);
  1416. } else {
  1417. /* keep state under NO PS state, do nothing. */
  1418. }
  1419. }
  1420. }
  1421. void halbtc8812a1ant_power_save_state(IN struct btc_coexist *btcoexist,
  1422. IN u8 ps_type, IN u8 lps_val, IN u8 rpwm_val)
  1423. {
  1424. boolean low_pwr_disable = false;
  1425. switch (ps_type) {
  1426. case BTC_PS_WIFI_NATIVE:
  1427. /* recover to original 32k low power setting */
  1428. low_pwr_disable = false;
  1429. btcoexist->btc_set(btcoexist,
  1430. BTC_SET_ACT_DISABLE_LOW_POWER,
  1431. &low_pwr_disable);
  1432. btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS,
  1433. NULL);
  1434. coex_sta->force_lps_on = false;
  1435. break;
  1436. case BTC_PS_LPS_ON:
  1437. halbtc8812a1ant_ps_tdma_check_for_power_save_state(
  1438. btcoexist, true);
  1439. halbtc8812a1ant_lps_rpwm(btcoexist, NORMAL_EXEC,
  1440. lps_val, rpwm_val);
  1441. /* when coex force to enter LPS, do not enter 32k low power. */
  1442. low_pwr_disable = true;
  1443. btcoexist->btc_set(btcoexist,
  1444. BTC_SET_ACT_DISABLE_LOW_POWER,
  1445. &low_pwr_disable);
  1446. /* power save must executed before psTdma. */
  1447. btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS,
  1448. NULL);
  1449. coex_sta->force_lps_on = true;
  1450. break;
  1451. case BTC_PS_LPS_OFF:
  1452. halbtc8812a1ant_ps_tdma_check_for_power_save_state(
  1453. btcoexist, false);
  1454. btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS,
  1455. NULL);
  1456. coex_sta->force_lps_on = false;
  1457. break;
  1458. default:
  1459. break;
  1460. }
  1461. }
  1462. void halbtc8812a1ant_action_wifi_only(IN struct btc_coexist *btcoexist)
  1463. {
  1464. halbtc8812a1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
  1465. halbtc8812a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8);
  1466. halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, FORCE_EXEC,
  1467. false, false);
  1468. }
  1469. void halbtc8812a1ant_monitor_bt_enable_disable(IN struct btc_coexist *btcoexist)
  1470. {
  1471. static u32 bt_disable_cnt = 0;
  1472. boolean bt_active = true, bt_disabled = false;
  1473. /* This function check if bt is disabled */
  1474. if (coex_sta->high_priority_tx == 0 &&
  1475. coex_sta->high_priority_rx == 0 &&
  1476. coex_sta->low_priority_tx == 0 &&
  1477. coex_sta->low_priority_rx == 0)
  1478. bt_active = false;
  1479. if (coex_sta->high_priority_tx == 0xffff &&
  1480. coex_sta->high_priority_rx == 0xffff &&
  1481. coex_sta->low_priority_tx == 0xffff &&
  1482. coex_sta->low_priority_rx == 0xffff)
  1483. bt_active = false;
  1484. if (bt_active) {
  1485. bt_disable_cnt = 0;
  1486. bt_disabled = false;
  1487. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
  1488. &bt_disabled);
  1489. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1490. "[BTCoex], BT is enabled !!\n");
  1491. BTC_TRACE(trace_buf);
  1492. } else {
  1493. bt_disable_cnt++;
  1494. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1495. "[BTCoex], bt all counters=0, %d times!!\n",
  1496. bt_disable_cnt);
  1497. BTC_TRACE(trace_buf);
  1498. if (bt_disable_cnt >= 2) {
  1499. bt_disabled = true;
  1500. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
  1501. &bt_disabled);
  1502. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1503. "[BTCoex], BT is disabled !!\n");
  1504. BTC_TRACE(trace_buf);
  1505. halbtc8812a1ant_action_wifi_only(btcoexist);
  1506. }
  1507. }
  1508. if (coex_sta->bt_disabled != bt_disabled) {
  1509. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1510. "[BTCoex], BT is from %s to %s!!\n",
  1511. (coex_sta->bt_disabled ? "disabled" : "enabled"),
  1512. (bt_disabled ? "disabled" : "enabled"));
  1513. BTC_TRACE(trace_buf);
  1514. coex_sta->bt_disabled = bt_disabled;
  1515. if (!bt_disabled) {
  1516. } else {
  1517. btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS,
  1518. NULL);
  1519. btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS,
  1520. NULL);
  1521. }
  1522. }
  1523. }
  1524. /* *********************************************
  1525. *
  1526. * Software Coex Mechanism start
  1527. *
  1528. * ********************************************* */
  1529. /* SCO only or SCO+PAN(HS) */
  1530. /*
  1531. void halbtc8812a1ant_action_sco(IN struct btc_coexist* btcoexist)
  1532. {
  1533. halbtc8812a1ant_sw_mechanism(btcoexist, true);
  1534. }
  1535. void halbtc8812a1ant_action_hid(IN struct btc_coexist* btcoexist)
  1536. {
  1537. halbtc8812a1ant_sw_mechanism(btcoexist, true);
  1538. }
  1539. void halbtc8812a1ant_action_a2dp(IN struct btc_coexist* btcoexist)
  1540. {
  1541. halbtc8812a1ant_sw_mechanism(btcoexist, false);
  1542. }
  1543. void halbtc8812a1ant_action_a2dp_pan_hs(IN struct btc_coexist* btcoexist)
  1544. {
  1545. halbtc8812a1ant_sw_mechanism(btcoexist, false);
  1546. }
  1547. void halbtc8812a1ant_action_pan_edr(IN struct btc_coexist* btcoexist)
  1548. {
  1549. halbtc8812a1ant_sw_mechanism(btcoexist, false);
  1550. }
  1551. void halbtc8812a1ant_action_pan_hs(IN struct btc_coexist* btcoexist)
  1552. {
  1553. halbtc8812a1ant_sw_mechanism(btcoexist, false);
  1554. }
  1555. void halbtc8812a1ant_action_pan_edr_a2dp(IN struct btc_coexist* btcoexist)
  1556. {
  1557. halbtc8812a1ant_sw_mechanism(btcoexist, false);
  1558. }
  1559. void halbtc8812a1ant_action_pan_edr_hid(IN struct btc_coexist* btcoexist)
  1560. {
  1561. halbtc8812a1ant_sw_mechanism(btcoexist, true);
  1562. }
  1563. void halbtc8812a1ant_action_hid_a2dp_pan_edr(IN struct btc_coexist* btcoexist)
  1564. {
  1565. halbtc8812a1ant_sw_mechanism(btcoexist, true);
  1566. }
  1567. void halbtc8812a1ant_action_hid_a2dp(IN struct btc_coexist* btcoexist)
  1568. {
  1569. halbtc8812a1ant_sw_mechanism(btcoexist, true);
  1570. }
  1571. */
  1572. /* *********************************************
  1573. *
  1574. * Non-Software Coex Mechanism start
  1575. *
  1576. * ********************************************* */
  1577. void halbtc8812a1ant_action_wifi_multi_port(IN struct btc_coexist *btcoexist)
  1578. {
  1579. halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
  1580. 0x0);
  1581. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  1582. halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC,
  1583. false, false);
  1584. halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  1585. }
  1586. void halbtc8812a1ant_action_hs(IN struct btc_coexist *btcoexist)
  1587. {
  1588. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
  1589. halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  1590. }
  1591. void halbtc8812a1ant_action_bt_inquiry(IN struct btc_coexist *btcoexist)
  1592. {
  1593. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1594. boolean wifi_connected = false, ap_enable = false, wifi_busy = false,
  1595. bt_busy = false;
  1596. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
  1597. &ap_enable);
  1598. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  1599. &wifi_connected);
  1600. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  1601. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
  1602. if ((!wifi_connected) && (!coex_sta->wifi_is_high_pri_task)) {
  1603. halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  1604. 0x0, 0x0);
  1605. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  1606. halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA,
  1607. NORMAL_EXEC, false, false);
  1608. halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  1609. } else if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) ||
  1610. (bt_link_info->a2dp_exist)) {
  1611. /* SCO/HID/A2DP busy */
  1612. halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  1613. 0x0, 0x0);
  1614. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
  1615. halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  1616. } else if ((bt_link_info->pan_exist) || (wifi_busy)) {
  1617. halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  1618. 0x0, 0x0);
  1619. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
  1620. halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  1621. } else {
  1622. halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  1623. 0x0, 0x0);
  1624. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  1625. halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA,
  1626. NORMAL_EXEC, false, false);
  1627. halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
  1628. }
  1629. }
  1630. void halbtc8812a1ant_action_bt_sco_hid_only_busy(IN struct btc_coexist
  1631. *btcoexist, IN u8 wifi_status)
  1632. {
  1633. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1634. boolean wifi_connected = false;
  1635. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  1636. &wifi_connected);
  1637. /* tdma and coex table */
  1638. if (bt_link_info->sco_exist) {
  1639. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
  1640. halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
  1641. } else { /* HID */
  1642. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 6);
  1643. halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
  1644. }
  1645. }
  1646. void halbtc8812a1ant_action_wifi_connected_bt_acl_busy(IN struct btc_coexist
  1647. *btcoexist, IN u8 wifi_status)
  1648. {
  1649. u8 bt_rssi_state;
  1650. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1651. bt_rssi_state = halbtc8812a1ant_bt_rssi_state(2, 28, 0);
  1652. if ((coex_sta->low_priority_rx >= 950) && (!coex_sta->under_ips))
  1653. bt_link_info->slave_role = true;
  1654. else
  1655. bt_link_info->slave_role = false;
  1656. if (bt_link_info->hid_only) { /* HID */
  1657. halbtc8812a1ant_action_bt_sco_hid_only_busy(btcoexist,
  1658. wifi_status);
  1659. coex_dm->auto_tdma_adjust = false;
  1660. return;
  1661. } else if (bt_link_info->a2dp_only) { /* A2DP */
  1662. if (BT_8812A_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifi_status) {
  1663. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  1664. 32);
  1665. halbtc8812a1ant_coex_table_with_type(btcoexist,
  1666. NORMAL_EXEC, 4);
  1667. coex_dm->auto_tdma_adjust = false;
  1668. } else {
  1669. halbtc8812a1ant_tdma_duration_adjust_for_acl(btcoexist,
  1670. wifi_status);
  1671. halbtc8812a1ant_coex_table_with_type(btcoexist,
  1672. NORMAL_EXEC, 4);
  1673. coex_dm->auto_tdma_adjust = true;
  1674. }
  1675. } else if (((bt_link_info->a2dp_exist) && (bt_link_info->pan_exist)) ||
  1676. (bt_link_info->hid_exist && bt_link_info->a2dp_exist &&
  1677. bt_link_info->pan_exist)) { /* A2DP+PAN(OPP,FTP), HID+A2DP+PAN(OPP,FTP) */
  1678. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 13);
  1679. halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  1680. coex_dm->auto_tdma_adjust = false;
  1681. } else if (bt_link_info->hid_exist &&
  1682. bt_link_info->a2dp_exist) { /* HID+A2DP */
  1683. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14);
  1684. coex_dm->auto_tdma_adjust = false;
  1685. halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3);
  1686. } else if ((bt_link_info->pan_only) || (bt_link_info->hid_exist &&
  1687. bt_link_info->pan_exist)) { /* PAN(OPP,FTP), HID+PAN(OPP,FTP) */
  1688. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3);
  1689. halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  1690. coex_dm->auto_tdma_adjust = false;
  1691. } else {
  1692. /* BT no-profile busy (0x9) */
  1693. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
  1694. halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  1695. coex_dm->auto_tdma_adjust = false;
  1696. }
  1697. }
  1698. void halbtc8812a1ant_action_wifi_not_connected(IN struct btc_coexist *btcoexist)
  1699. {
  1700. /* power save state */
  1701. halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
  1702. 0x0);
  1703. /* tdma and coex table */
  1704. halbtc8812a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8);
  1705. halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC,
  1706. false, false);
  1707. halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  1708. }
  1709. void halbtc8812a1ant_action_wifi_not_connected_scan(IN struct btc_coexist
  1710. *btcoexist)
  1711. {
  1712. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1713. halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
  1714. 0x0);
  1715. /* tdma and coex table */
  1716. if (BT_8812A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
  1717. if (bt_link_info->a2dp_exist) {
  1718. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  1719. 32);
  1720. halbtc8812a1ant_coex_table_with_type(btcoexist,
  1721. NORMAL_EXEC, 4);
  1722. } else if (bt_link_info->a2dp_exist &&
  1723. bt_link_info->pan_exist) {
  1724. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  1725. 22);
  1726. halbtc8812a1ant_coex_table_with_type(btcoexist,
  1727. NORMAL_EXEC, 4);
  1728. } else {
  1729. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  1730. 20);
  1731. halbtc8812a1ant_coex_table_with_type(btcoexist,
  1732. NORMAL_EXEC, 4);
  1733. }
  1734. } else if ((BT_8812A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
  1735. (BT_8812A_1ANT_BT_STATUS_ACL_SCO_BUSY ==
  1736. coex_dm->bt_status)) {
  1737. halbtc8812a1ant_action_bt_sco_hid_only_busy(btcoexist,
  1738. BT_8812A_1ANT_WIFI_STATUS_CONNECTED_SCAN);
  1739. } else {
  1740. /* Bryant Add */
  1741. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  1742. halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA,
  1743. NORMAL_EXEC, false, false);
  1744. halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  1745. }
  1746. }
  1747. void halbtc8812a1ant_action_wifi_not_connected_asso_auth(
  1748. IN struct btc_coexist *btcoexist)
  1749. {
  1750. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1751. halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
  1752. 0x0);
  1753. /* tdma and coex table */
  1754. if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) ||
  1755. (bt_link_info->a2dp_exist)) {
  1756. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
  1757. halbtc8812a1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 4);
  1758. } else if (bt_link_info->pan_exist) {
  1759. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
  1760. halbtc8812a1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 4);
  1761. } else {
  1762. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  1763. halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA,
  1764. NORMAL_EXEC, false, false);
  1765. halbtc8812a1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 2);
  1766. }
  1767. }
  1768. void halbtc8812a1ant_action_wifi_connected_scan(IN struct btc_coexist
  1769. *btcoexist)
  1770. {
  1771. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1772. halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
  1773. 0x0);
  1774. /* tdma and coex table */
  1775. if (BT_8812A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
  1776. if (bt_link_info->a2dp_exist) {
  1777. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  1778. 32);
  1779. halbtc8812a1ant_coex_table_with_type(btcoexist,
  1780. NORMAL_EXEC, 4);
  1781. } else if (bt_link_info->a2dp_exist &&
  1782. bt_link_info->pan_exist) {
  1783. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  1784. 22);
  1785. halbtc8812a1ant_coex_table_with_type(btcoexist,
  1786. NORMAL_EXEC, 4);
  1787. } else {
  1788. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  1789. 20);
  1790. halbtc8812a1ant_coex_table_with_type(btcoexist,
  1791. NORMAL_EXEC, 4);
  1792. }
  1793. } else if ((BT_8812A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
  1794. (BT_8812A_1ANT_BT_STATUS_ACL_SCO_BUSY ==
  1795. coex_dm->bt_status)) {
  1796. halbtc8812a1ant_action_bt_sco_hid_only_busy(btcoexist,
  1797. BT_8812A_1ANT_WIFI_STATUS_CONNECTED_SCAN);
  1798. } else {
  1799. /* Bryant Add */
  1800. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  1801. halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA,
  1802. NORMAL_EXEC, false, false);
  1803. halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  1804. }
  1805. }
  1806. void halbtc8812a1ant_action_wifi_connected_specific_packet(
  1807. IN struct btc_coexist *btcoexist)
  1808. {
  1809. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1810. halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
  1811. 0x0);
  1812. /* tdma and coex table */
  1813. if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) ||
  1814. (bt_link_info->a2dp_exist)) {
  1815. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
  1816. halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  1817. } else if (bt_link_info->pan_exist) {
  1818. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
  1819. halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  1820. } else {
  1821. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  1822. halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA,
  1823. NORMAL_EXEC, false, false);
  1824. halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  1825. }
  1826. }
  1827. void halbtc8812a1ant_action_wifi_connected(IN struct btc_coexist *btcoexist)
  1828. {
  1829. boolean wifi_busy = false;
  1830. boolean scan = false, link = false, roam = false;
  1831. boolean under_4way = false, ap_enable = false;
  1832. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1833. "[BTCoex], CoexForWifiConnect()===>\n");
  1834. BTC_TRACE(trace_buf);
  1835. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
  1836. &under_4way);
  1837. if (under_4way) {
  1838. halbtc8812a1ant_action_wifi_connected_specific_packet(btcoexist);
  1839. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1840. "[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n");
  1841. BTC_TRACE(trace_buf);
  1842. return;
  1843. }
  1844. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
  1845. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
  1846. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
  1847. if (scan || link || roam) {
  1848. if (scan)
  1849. halbtc8812a1ant_action_wifi_connected_scan(btcoexist);
  1850. else
  1851. halbtc8812a1ant_action_wifi_connected_specific_packet(
  1852. btcoexist);
  1853. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1854. "[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n");
  1855. BTC_TRACE(trace_buf);
  1856. return;
  1857. }
  1858. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
  1859. &ap_enable);
  1860. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  1861. /* power save state */
  1862. if (!ap_enable &&
  1863. BT_8812A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status &&
  1864. !btcoexist->bt_link_info.hid_only) {
  1865. if (btcoexist->bt_link_info.a2dp_only) { /* A2DP */
  1866. if (!wifi_busy)
  1867. halbtc8812a1ant_power_save_state(btcoexist,
  1868. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  1869. else { /* busy */
  1870. if (coex_sta->scan_ap_num >=
  1871. BT_8812A_1ANT_WIFI_NOISY_THRESH) /* no force LPS, no PS-TDMA, use pure TDMA */
  1872. halbtc8812a1ant_power_save_state(
  1873. btcoexist, BTC_PS_WIFI_NATIVE,
  1874. 0x0, 0x0);
  1875. else
  1876. halbtc8812a1ant_power_save_state(
  1877. btcoexist, BTC_PS_LPS_ON, 0x50,
  1878. 0x4);
  1879. }
  1880. } else if ((coex_sta->pan_exist == false) &&
  1881. (coex_sta->a2dp_exist == false) &&
  1882. (coex_sta->hid_exist == false))
  1883. halbtc8812a1ant_power_save_state(btcoexist,
  1884. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  1885. else
  1886. halbtc8812a1ant_power_save_state(btcoexist,
  1887. BTC_PS_LPS_ON, 0x50, 0x4);
  1888. } else
  1889. halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  1890. 0x0, 0x0);
  1891. /* tdma and coex table */
  1892. if (!wifi_busy) {
  1893. if (BT_8812A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
  1894. halbtc8812a1ant_action_wifi_connected_bt_acl_busy(
  1895. btcoexist,
  1896. BT_8812A_1ANT_WIFI_STATUS_CONNECTED_IDLE);
  1897. } else if ((BT_8812A_1ANT_BT_STATUS_SCO_BUSY ==
  1898. coex_dm->bt_status) ||
  1899. (BT_8812A_1ANT_BT_STATUS_ACL_SCO_BUSY ==
  1900. coex_dm->bt_status)) {
  1901. halbtc8812a1ant_action_bt_sco_hid_only_busy(btcoexist,
  1902. BT_8812A_1ANT_WIFI_STATUS_CONNECTED_IDLE);
  1903. } else {
  1904. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
  1905. 8);
  1906. halbtc8812a1ant_set_ant_path(btcoexist,
  1907. BTC_ANT_PATH_PTA, NORMAL_EXEC, false, false);
  1908. if ((coex_sta->high_priority_tx) +
  1909. (coex_sta->high_priority_rx) <= 60)
  1910. halbtc8812a1ant_coex_table_with_type(btcoexist,
  1911. NORMAL_EXEC, 2);
  1912. else
  1913. halbtc8812a1ant_coex_table_with_type(btcoexist,
  1914. NORMAL_EXEC, 7);
  1915. }
  1916. } else {
  1917. if (BT_8812A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
  1918. halbtc8812a1ant_action_wifi_connected_bt_acl_busy(
  1919. btcoexist,
  1920. BT_8812A_1ANT_WIFI_STATUS_CONNECTED_BUSY);
  1921. } else if ((BT_8812A_1ANT_BT_STATUS_SCO_BUSY ==
  1922. coex_dm->bt_status) ||
  1923. (BT_8812A_1ANT_BT_STATUS_ACL_SCO_BUSY ==
  1924. coex_dm->bt_status)) {
  1925. halbtc8812a1ant_action_bt_sco_hid_only_busy(btcoexist,
  1926. BT_8812A_1ANT_WIFI_STATUS_CONNECTED_BUSY);
  1927. } else {
  1928. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
  1929. 8);
  1930. halbtc8812a1ant_set_ant_path(btcoexist,
  1931. BTC_ANT_PATH_PTA, NORMAL_EXEC, false, false);
  1932. if ((coex_sta->high_priority_tx) +
  1933. (coex_sta->high_priority_rx) <= 60)
  1934. halbtc8812a1ant_coex_table_with_type(btcoexist,
  1935. NORMAL_EXEC, 2);
  1936. else
  1937. halbtc8812a1ant_coex_table_with_type(btcoexist,
  1938. NORMAL_EXEC, 7);
  1939. }
  1940. }
  1941. }
  1942. void halbtc8812a1ant_run_sw_coexist_mechanism(IN struct btc_coexist *btcoexist)
  1943. {
  1944. u8 algorithm = 0;
  1945. algorithm = halbtc8812a1ant_action_algorithm(btcoexist);
  1946. coex_dm->cur_algorithm = algorithm;
  1947. if (halbtc8812a1ant_is_common_action(btcoexist)) {
  1948. } else {
  1949. switch (coex_dm->cur_algorithm) {
  1950. case BT_8812A_1ANT_COEX_ALGO_SCO:
  1951. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1952. "[BTCoex], Action algorithm = SCO.\n");
  1953. BTC_TRACE(trace_buf);
  1954. /* halbtc8812a1ant_action_sco(btcoexist); */
  1955. break;
  1956. case BT_8812A_1ANT_COEX_ALGO_HID:
  1957. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1958. "[BTCoex], Action algorithm = HID.\n");
  1959. BTC_TRACE(trace_buf);
  1960. /* halbtc8812a1ant_action_hid(btcoexist); */
  1961. break;
  1962. case BT_8812A_1ANT_COEX_ALGO_A2DP:
  1963. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1964. "[BTCoex], Action algorithm = A2DP.\n");
  1965. BTC_TRACE(trace_buf);
  1966. /* halbtc8812a1ant_action_a2dp(btcoexist); */
  1967. break;
  1968. case BT_8812A_1ANT_COEX_ALGO_A2DP_PANHS:
  1969. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1970. "[BTCoex], Action algorithm = A2DP+PAN(HS).\n");
  1971. BTC_TRACE(trace_buf);
  1972. /* halbtc8812a1ant_action_a2dp_pan_hs(btcoexist); */
  1973. break;
  1974. case BT_8812A_1ANT_COEX_ALGO_PANEDR:
  1975. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1976. "[BTCoex], Action algorithm = PAN(EDR).\n");
  1977. BTC_TRACE(trace_buf);
  1978. /* halbtc8812a1ant_action_pan_edr(btcoexist); */
  1979. break;
  1980. case BT_8812A_1ANT_COEX_ALGO_PANHS:
  1981. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1982. "[BTCoex], Action algorithm = HS mode.\n");
  1983. BTC_TRACE(trace_buf);
  1984. /* halbtc8812a1ant_action_pan_hs(btcoexist); */
  1985. break;
  1986. case BT_8812A_1ANT_COEX_ALGO_PANEDR_A2DP:
  1987. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1988. "[BTCoex], Action algorithm = PAN+A2DP.\n");
  1989. BTC_TRACE(trace_buf);
  1990. /* halbtc8812a1ant_action_pan_edr_a2dp(btcoexist); */
  1991. break;
  1992. case BT_8812A_1ANT_COEX_ALGO_PANEDR_HID:
  1993. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1994. "[BTCoex], Action algorithm = PAN(EDR)+HID.\n");
  1995. BTC_TRACE(trace_buf);
  1996. /* halbtc8812a1ant_action_pan_edr_hid(btcoexist); */
  1997. break;
  1998. case BT_8812A_1ANT_COEX_ALGO_HID_A2DP_PANEDR:
  1999. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2000. "[BTCoex], Action algorithm = HID+A2DP+PAN.\n");
  2001. BTC_TRACE(trace_buf);
  2002. /* halbtc8812a1ant_action_hid_a2dp_pan_edr(btcoexist); */
  2003. break;
  2004. case BT_8812A_1ANT_COEX_ALGO_HID_A2DP:
  2005. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2006. "[BTCoex], Action algorithm = HID+A2DP.\n");
  2007. BTC_TRACE(trace_buf);
  2008. /* halbtc8812a1ant_action_hid_a2dp(btcoexist); */
  2009. break;
  2010. default:
  2011. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2012. "[BTCoex], Action algorithm = coexist All Off!!\n");
  2013. BTC_TRACE(trace_buf);
  2014. /* halbtc8812a1ant_coex_all_off(btcoexist); */
  2015. break;
  2016. }
  2017. coex_dm->pre_algorithm = coex_dm->cur_algorithm;
  2018. }
  2019. }
  2020. void halbtc8812a1ant_run_coexist_mechanism(IN struct btc_coexist *btcoexist)
  2021. {
  2022. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  2023. boolean wifi_connected = false, bt_hs_on = false;
  2024. boolean increase_scan_dev_num = false;
  2025. boolean bt_ctrl_agg_buf_size = false;
  2026. boolean miracast_plus_bt = false;
  2027. u8 agg_buf_size = 5;
  2028. u32 wifi_link_status = 0;
  2029. u32 num_of_wifi_link = 0, wifi_bw;
  2030. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2031. "[BTCoex], RunCoexistMechanism()===>\n");
  2032. BTC_TRACE(trace_buf);
  2033. if (btcoexist->manual_control) {
  2034. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2035. "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
  2036. BTC_TRACE(trace_buf);
  2037. return;
  2038. }
  2039. if (btcoexist->stop_coex_dm) {
  2040. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2041. "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n");
  2042. BTC_TRACE(trace_buf);
  2043. return;
  2044. }
  2045. if (coex_sta->under_ips) {
  2046. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2047. "[BTCoex], wifi is under IPS !!!\n");
  2048. BTC_TRACE(trace_buf);
  2049. return;
  2050. }
  2051. if ((BT_8812A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
  2052. (BT_8812A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
  2053. (BT_8812A_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
  2054. increase_scan_dev_num = true;
  2055. btcoexist->btc_set(btcoexist, BTC_SET_BL_INC_SCAN_DEV_NUM,
  2056. &increase_scan_dev_num);
  2057. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  2058. &wifi_connected);
  2059. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
  2060. &wifi_link_status);
  2061. num_of_wifi_link = wifi_link_status >> 16;
  2062. if ((num_of_wifi_link >= 2) ||
  2063. (wifi_link_status & WIFI_P2P_GO_CONNECTED)) {
  2064. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2065. "############# [BTCoex], Multi-Port num_of_wifi_link = %d, wifi_link_status = 0x%x\n",
  2066. num_of_wifi_link, wifi_link_status);
  2067. BTC_TRACE(trace_buf);
  2068. if (bt_link_info->bt_link_exist) {
  2069. halbtc8812a1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1,
  2070. 0, 1);
  2071. miracast_plus_bt = true;
  2072. } else {
  2073. halbtc8812a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0,
  2074. 0, 0);
  2075. miracast_plus_bt = false;
  2076. }
  2077. btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT,
  2078. &miracast_plus_bt);
  2079. halbtc8812a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
  2080. bt_ctrl_agg_buf_size, agg_buf_size);
  2081. if ((bt_link_info->a2dp_exist) &&
  2082. (coex_sta->c2h_bt_inquiry_page)) {
  2083. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2084. "############# [BTCoex], BT Is Inquirying\n");
  2085. BTC_TRACE(trace_buf);
  2086. halbtc8812a1ant_action_bt_inquiry(btcoexist);
  2087. } else
  2088. halbtc8812a1ant_action_wifi_multi_port(btcoexist);
  2089. return;
  2090. }
  2091. miracast_plus_bt = false;
  2092. btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT,
  2093. &miracast_plus_bt);
  2094. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  2095. if ((bt_link_info->bt_link_exist) && (wifi_connected)) {
  2096. halbtc8812a1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1, 0, 1);
  2097. if (bt_link_info->sco_exist)
  2098. halbtc8812a1ant_limited_rx(btcoexist, NORMAL_EXEC, true,
  2099. false, 0x5);
  2100. else {
  2101. if (BTC_WIFI_BW_HT40 == wifi_bw)
  2102. halbtc8812a1ant_limited_rx(btcoexist, NORMAL_EXEC,
  2103. false, true, 0x10);
  2104. else
  2105. halbtc8812a1ant_limited_rx(btcoexist, NORMAL_EXEC,
  2106. false, true, 0x8);
  2107. }
  2108. halbtc8812a1ant_sw_mechanism(btcoexist, true);
  2109. halbtc8812a1ant_run_sw_coexist_mechanism(
  2110. btcoexist); /* just print debug message */
  2111. } else {
  2112. halbtc8812a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
  2113. halbtc8812a1ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
  2114. 0x5);
  2115. halbtc8812a1ant_sw_mechanism(btcoexist, false);
  2116. halbtc8812a1ant_run_sw_coexist_mechanism(
  2117. btcoexist); /* //just print debug message */
  2118. }
  2119. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  2120. if (coex_sta->c2h_bt_inquiry_page) {
  2121. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2122. "############# [BTCoex], BT Is Inquirying\n");
  2123. BTC_TRACE(trace_buf);
  2124. halbtc8812a1ant_action_bt_inquiry(btcoexist);
  2125. return;
  2126. } else if (bt_hs_on) {
  2127. halbtc8812a1ant_action_hs(btcoexist);
  2128. return;
  2129. }
  2130. if (!wifi_connected) {
  2131. boolean scan = false, link = false, roam = false;
  2132. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2133. "[BTCoex], wifi is non connected-idle !!!\n");
  2134. BTC_TRACE(trace_buf);
  2135. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
  2136. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
  2137. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
  2138. if (scan || link || roam) {
  2139. if (scan)
  2140. halbtc8812a1ant_action_wifi_not_connected_scan(
  2141. btcoexist);
  2142. else
  2143. halbtc8812a1ant_action_wifi_not_connected_asso_auth(
  2144. btcoexist);
  2145. } else
  2146. halbtc8812a1ant_action_wifi_not_connected(btcoexist);
  2147. } else /* wifi LPS/Busy */
  2148. halbtc8812a1ant_action_wifi_connected(btcoexist);
  2149. }
  2150. void halbtc8812a1ant_init_coex_dm(IN struct btc_coexist *btcoexist)
  2151. {
  2152. /* force to reset coex mechanism */
  2153. /* sw all off */
  2154. halbtc8812a1ant_sw_mechanism(btcoexist, false);
  2155. /* halbtc8812a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); */
  2156. /* halbtc8812a1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0); */
  2157. coex_sta->pop_event_cnt = 0;
  2158. }
  2159. void halbtc8812a1ant_init_hw_config(IN struct btc_coexist *btcoexist,
  2160. IN boolean back_up, IN boolean wifi_only)
  2161. {
  2162. u8 u8tmp = 0;
  2163. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2164. "[BTCoex], 1Ant Init HW Config!!\n");
  2165. BTC_TRACE(trace_buf);
  2166. /* ant sw control to BT */
  2167. halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, FORCE_EXEC,
  2168. true, false);
  2169. /* 0x790[5:0]=0x5 */
  2170. u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x790);
  2171. u8tmp &= 0xc0;
  2172. u8tmp |= 0x5;
  2173. btcoexist->btc_write_1byte(btcoexist, 0x790, u8tmp);
  2174. /* PTA parameter */
  2175. btcoexist->btc_write_1byte(btcoexist, 0x6cc, 0x0);
  2176. btcoexist->btc_write_4byte(btcoexist, 0x6c8, 0xffff);
  2177. btcoexist->btc_write_4byte(btcoexist, 0x6c4, 0x55555555);
  2178. btcoexist->btc_write_4byte(btcoexist, 0x6c0, 0x55555555);
  2179. /* coex parameters */
  2180. btcoexist->btc_write_1byte(btcoexist, 0x778, 0x1);
  2181. /* enable counter statistics */
  2182. btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4);
  2183. /* enable PTA */
  2184. btcoexist->btc_write_1byte(btcoexist, 0x40, 0x20);
  2185. /* bt clock related */
  2186. u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x4);
  2187. u8tmp |= BIT(7);
  2188. btcoexist->btc_write_1byte(btcoexist, 0x4, u8tmp);
  2189. /* bt clock related */
  2190. u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x7);
  2191. u8tmp |= BIT(1);
  2192. btcoexist->btc_write_1byte(btcoexist, 0x7, u8tmp);
  2193. }
  2194. /* ************************************************************
  2195. * work around function start with wa_halbtc8812a1ant_
  2196. * ************************************************************
  2197. * ************************************************************
  2198. * extern function start with ex_halbtc8812a1ant_
  2199. * ************************************************************ */
  2200. void ex_halbtc8812a1ant_power_on_setting(IN struct btc_coexist *btcoexist)
  2201. {
  2202. }
  2203. void ex_halbtc8812a1ant_pre_load_firmware(IN struct btc_coexist *btcoexist)
  2204. {
  2205. }
  2206. void ex_halbtc8812a1ant_init_hw_config(IN struct btc_coexist *btcoexist,
  2207. IN boolean wifi_only)
  2208. {
  2209. halbtc8812a1ant_init_hw_config(btcoexist, true, wifi_only);
  2210. btcoexist->stop_coex_dm = false;
  2211. }
  2212. void ex_halbtc8812a1ant_init_coex_dm(IN struct btc_coexist *btcoexist)
  2213. {
  2214. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2215. "[BTCoex], Coex Mechanism Init!!\n");
  2216. BTC_TRACE(trace_buf);
  2217. btcoexist->stop_coex_dm = false;
  2218. halbtc8812a1ant_init_coex_dm(btcoexist);
  2219. halbtc8812a1ant_query_bt_info(btcoexist);
  2220. }
  2221. void ex_halbtc8812a1ant_display_coex_info(IN struct btc_coexist *btcoexist)
  2222. {
  2223. struct btc_board_info *board_info = &btcoexist->board_info;
  2224. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  2225. u8 *cli_buf = btcoexist->cli_buf;
  2226. u8 u8tmp[4], i, bt_info_ext, ps_tdma_case = 0;
  2227. u32 u32tmp[4];
  2228. u32 fw_ver = 0, bt_patch_ver = 0;
  2229. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  2230. "\r\n ============[BT Coexist info]============");
  2231. CL_PRINTF(cli_buf);
  2232. if (btcoexist->manual_control) {
  2233. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  2234. "\r\n ============[Under Manual Control]============");
  2235. CL_PRINTF(cli_buf);
  2236. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  2237. "\r\n ==========================================");
  2238. CL_PRINTF(cli_buf);
  2239. }
  2240. if (btcoexist->stop_coex_dm) {
  2241. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  2242. "\r\n ============[Coex is STOPPED]============");
  2243. CL_PRINTF(cli_buf);
  2244. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  2245. "\r\n ==========================================");
  2246. CL_PRINTF(cli_buf);
  2247. }
  2248. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ",
  2249. "Ant PG number/ Ant mechanism:",
  2250. board_info->pg_ant_num, board_info->btdm_ant_num);
  2251. CL_PRINTF(cli_buf);
  2252. btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
  2253. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
  2254. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  2255. "\r\n %-35s = %d_%d/ 0x%x/ 0x%x(%d)",
  2256. "CoexVer/ FwVer/ PatchVer",
  2257. glcoex_ver_date_8812a_1ant, glcoex_ver_8812a_1ant, fw_ver,
  2258. bt_patch_ver, bt_patch_ver);
  2259. CL_PRINTF(cli_buf);
  2260. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ",
  2261. "Wifi channel informed to BT",
  2262. coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1],
  2263. coex_dm->wifi_chnl_info[2]);
  2264. CL_PRINTF(cli_buf);
  2265. /* wifi status */
  2266. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  2267. "============[Wifi Status]============");
  2268. CL_PRINTF(cli_buf);
  2269. btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS);
  2270. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  2271. "============[BT Status]============");
  2272. CL_PRINTF(cli_buf);
  2273. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d] ",
  2274. "BT [status/ rssi/ retryCnt]",
  2275. ((coex_sta->bt_disabled) ? ("disabled") : ((
  2276. coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan")
  2277. : ((BT_8812A_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
  2278. coex_dm->bt_status) ? "non-connected idle" :
  2279. ((BT_8812A_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)
  2280. ? "connected-idle" : "busy")))),
  2281. coex_sta->bt_rssi, coex_sta->bt_retry_cnt);
  2282. CL_PRINTF(cli_buf);
  2283. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d",
  2284. "SCO/HID/PAN/A2DP",
  2285. bt_link_info->sco_exist, bt_link_info->hid_exist,
  2286. bt_link_info->pan_exist, bt_link_info->a2dp_exist);
  2287. CL_PRINTF(cli_buf);
  2288. btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_BT_LINK_INFO);
  2289. bt_info_ext = coex_sta->bt_info_ext;
  2290. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s",
  2291. "BT Info A2DP rate",
  2292. (bt_info_ext & BIT(0)) ? "Basic rate" : "EDR rate");
  2293. CL_PRINTF(cli_buf);
  2294. for (i = 0; i < BT_INFO_SRC_8812A_1ANT_MAX; i++) {
  2295. if (coex_sta->bt_info_c2h_cnt[i]) {
  2296. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  2297. "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)",
  2298. glbt_info_src_8812a_1ant[i],
  2299. coex_sta->bt_info_c2h[i][0],
  2300. coex_sta->bt_info_c2h[i][1],
  2301. coex_sta->bt_info_c2h[i][2],
  2302. coex_sta->bt_info_c2h[i][3],
  2303. coex_sta->bt_info_c2h[i][4],
  2304. coex_sta->bt_info_c2h[i][5],
  2305. coex_sta->bt_info_c2h[i][6],
  2306. coex_sta->bt_info_c2h_cnt[i]);
  2307. CL_PRINTF(cli_buf);
  2308. }
  2309. }
  2310. if (!btcoexist->manual_control) {
  2311. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  2312. "============[mechanisms]============");
  2313. CL_PRINTF(cli_buf);
  2314. ps_tdma_case = coex_dm->cur_ps_tdma;
  2315. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  2316. "\r\n %-35s = %02x %02x %02x %02x %02x case-%d",
  2317. "PS TDMA",
  2318. coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1],
  2319. coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3],
  2320. coex_dm->ps_tdma_para[4], ps_tdma_case);
  2321. CL_PRINTF(cli_buf);
  2322. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ",
  2323. "Latest error condition(should be 0)",
  2324. coex_dm->error_condition);
  2325. CL_PRINTF(cli_buf);
  2326. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ",
  2327. "IgnWlanAct",
  2328. coex_dm->cur_ignore_wlan_act);
  2329. CL_PRINTF(cli_buf);
  2330. }
  2331. /* Hw setting */
  2332. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  2333. "============[Hw setting]============");
  2334. CL_PRINTF(cli_buf);
  2335. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
  2336. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x778",
  2337. u8tmp[0]);
  2338. CL_PRINTF(cli_buf);
  2339. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xcb3);
  2340. u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xcb7);
  2341. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x900);
  2342. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
  2343. "0xcb3/0xcb7/0x900",
  2344. u8tmp[0], u8tmp[1], u32tmp[0]);
  2345. CL_PRINTF(cli_buf);
  2346. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x40);
  2347. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x40",
  2348. u8tmp[0]);
  2349. CL_PRINTF(cli_buf);
  2350. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
  2351. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
  2352. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
  2353. "0x550(bcn ctrl)/0x522",
  2354. u32tmp[0], u8tmp[0]);
  2355. CL_PRINTF(cli_buf);
  2356. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50);
  2357. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0xc50(dig)",
  2358. u32tmp[0]);
  2359. CL_PRINTF(cli_buf);
  2360. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
  2361. u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
  2362. u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
  2363. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x6cc);
  2364. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  2365. "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
  2366. "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)",
  2367. u32tmp[0], u32tmp[1], u32tmp[2], u8tmp[0]);
  2368. CL_PRINTF(cli_buf);
  2369. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
  2370. "0x770(hp rx[31:16]/tx[15:0])",
  2371. coex_sta->high_priority_rx, coex_sta->high_priority_tx);
  2372. CL_PRINTF(cli_buf);
  2373. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
  2374. "0x774(lp rx[31:16]/tx[15:0])",
  2375. coex_sta->low_priority_rx, coex_sta->low_priority_tx);
  2376. CL_PRINTF(cli_buf);
  2377. btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS);
  2378. }
  2379. void ex_halbtc8812a1ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type)
  2380. {
  2381. if (btcoexist->manual_control || btcoexist->stop_coex_dm)
  2382. return;
  2383. if (BTC_IPS_ENTER == type) {
  2384. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2385. "[BTCoex], IPS ENTER notify\n");
  2386. BTC_TRACE(trace_buf);
  2387. coex_sta->under_ips = true;
  2388. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  2389. halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT,
  2390. FORCE_EXEC, false, true);
  2391. halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  2392. } else if (BTC_IPS_LEAVE == type) {
  2393. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2394. "[BTCoex], IPS LEAVE notify\n");
  2395. BTC_TRACE(trace_buf);
  2396. halbtc8812a1ant_init_hw_config(btcoexist, false, false);
  2397. halbtc8812a1ant_init_coex_dm(btcoexist);
  2398. halbtc8812a1ant_query_bt_info(btcoexist);
  2399. coex_sta->under_ips = false;
  2400. }
  2401. }
  2402. void ex_halbtc8812a1ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type)
  2403. {
  2404. if (btcoexist->manual_control || btcoexist->stop_coex_dm)
  2405. return;
  2406. if (BTC_LPS_ENABLE == type) {
  2407. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2408. "[BTCoex], LPS ENABLE notify\n");
  2409. BTC_TRACE(trace_buf);
  2410. coex_sta->under_lps = true;
  2411. } else if (BTC_LPS_DISABLE == type) {
  2412. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2413. "[BTCoex], LPS DISABLE notify\n");
  2414. BTC_TRACE(trace_buf);
  2415. coex_sta->under_lps = false;
  2416. }
  2417. }
  2418. void ex_halbtc8812a1ant_scan_notify(IN struct btc_coexist *btcoexist,
  2419. IN u8 type)
  2420. {
  2421. boolean wifi_connected = false, bt_hs_on = false;
  2422. u32 wifi_link_status = 0;
  2423. u32 num_of_wifi_link = 0;
  2424. boolean bt_ctrl_agg_buf_size = false;
  2425. u8 agg_buf_size = 5;
  2426. if (btcoexist->manual_control ||
  2427. btcoexist->stop_coex_dm)
  2428. return;
  2429. if (BTC_SCAN_START == type) {
  2430. coex_sta->wifi_is_high_pri_task = true;
  2431. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2432. "[BTCoex], SCAN START notify\n");
  2433. BTC_TRACE(trace_buf);
  2434. halbtc8812a1ant_ps_tdma(btcoexist, FORCE_EXEC, false,
  2435. 8); /* Force antenna setup for no scan result issue */
  2436. halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA,
  2437. FORCE_EXEC, false, false);
  2438. } else {
  2439. coex_sta->wifi_is_high_pri_task = false;
  2440. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2441. "[BTCoex], SCAN FINISH notify\n");
  2442. BTC_TRACE(trace_buf);
  2443. btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
  2444. &coex_sta->scan_ap_num);
  2445. }
  2446. if (coex_sta->bt_disabled)
  2447. return;
  2448. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  2449. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  2450. &wifi_connected);
  2451. halbtc8812a1ant_query_bt_info(btcoexist);
  2452. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
  2453. &wifi_link_status);
  2454. num_of_wifi_link = wifi_link_status >> 16;
  2455. if (num_of_wifi_link >= 2) {
  2456. halbtc8812a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
  2457. halbtc8812a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
  2458. bt_ctrl_agg_buf_size, agg_buf_size);
  2459. halbtc8812a1ant_action_wifi_multi_port(btcoexist);
  2460. return;
  2461. }
  2462. if (coex_sta->c2h_bt_inquiry_page) {
  2463. halbtc8812a1ant_action_bt_inquiry(btcoexist);
  2464. return;
  2465. } else if (bt_hs_on) {
  2466. halbtc8812a1ant_action_hs(btcoexist);
  2467. return;
  2468. }
  2469. if (BTC_SCAN_START == type) {
  2470. if (!wifi_connected) /* non-connected scan */
  2471. halbtc8812a1ant_action_wifi_not_connected_scan(
  2472. btcoexist);
  2473. else /* wifi is connected */
  2474. halbtc8812a1ant_action_wifi_connected_scan(btcoexist);
  2475. } else if (BTC_SCAN_FINISH == type) {
  2476. if (!wifi_connected) /* non-connected scan */
  2477. halbtc8812a1ant_action_wifi_not_connected(btcoexist);
  2478. else
  2479. halbtc8812a1ant_action_wifi_connected(btcoexist);
  2480. }
  2481. }
  2482. void ex_halbtc8812a1ant_connect_notify(IN struct btc_coexist *btcoexist,
  2483. IN u8 type)
  2484. {
  2485. boolean wifi_connected = false, bt_hs_on = false;
  2486. u32 wifi_link_status = 0;
  2487. u32 num_of_wifi_link = 0;
  2488. boolean bt_ctrl_agg_buf_size = false;
  2489. u8 agg_buf_size = 5;
  2490. if (btcoexist->manual_control ||
  2491. btcoexist->stop_coex_dm ||
  2492. coex_sta->bt_disabled)
  2493. return;
  2494. if (BTC_ASSOCIATE_START == type) {
  2495. coex_sta->wifi_is_high_pri_task = true;
  2496. halbtc8812a1ant_ps_tdma(btcoexist, FORCE_EXEC, false,
  2497. 8); /* Force antenna setup for no scan result issue */
  2498. halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA,
  2499. FORCE_EXEC, false, false);
  2500. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2501. "[BTCoex], CONNECT START notify\n");
  2502. BTC_TRACE(trace_buf);
  2503. coex_dm->arp_cnt = 0;
  2504. } else {
  2505. coex_sta->wifi_is_high_pri_task = false;
  2506. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2507. "[BTCoex], CONNECT FINISH notify\n");
  2508. BTC_TRACE(trace_buf);
  2509. /* coex_dm->arp_cnt = 0; */
  2510. }
  2511. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
  2512. &wifi_link_status);
  2513. num_of_wifi_link = wifi_link_status >> 16;
  2514. if (num_of_wifi_link >= 2) {
  2515. halbtc8812a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
  2516. halbtc8812a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
  2517. bt_ctrl_agg_buf_size, agg_buf_size);
  2518. halbtc8812a1ant_action_wifi_multi_port(btcoexist);
  2519. return;
  2520. }
  2521. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  2522. if (coex_sta->c2h_bt_inquiry_page) {
  2523. halbtc8812a1ant_action_bt_inquiry(btcoexist);
  2524. return;
  2525. } else if (bt_hs_on) {
  2526. halbtc8812a1ant_action_hs(btcoexist);
  2527. return;
  2528. }
  2529. if (BTC_ASSOCIATE_START == type)
  2530. halbtc8812a1ant_action_wifi_not_connected_asso_auth(btcoexist);
  2531. else if (BTC_ASSOCIATE_FINISH == type) {
  2532. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  2533. &wifi_connected);
  2534. if (!wifi_connected) /* non-connected scan */
  2535. halbtc8812a1ant_action_wifi_not_connected(btcoexist);
  2536. else
  2537. halbtc8812a1ant_action_wifi_connected(btcoexist);
  2538. }
  2539. }
  2540. /* to check registers... */
  2541. void ex_halbtc8812a1ant_media_status_notify(IN struct btc_coexist *btcoexist,
  2542. IN u8 type)
  2543. {
  2544. u8 data_len = 5;
  2545. u8 buf[6] = {0};
  2546. u8 h2c_parameter[3] = {0};
  2547. u32 wifi_bw;
  2548. u8 wifi_central_chnl;
  2549. boolean wifi_under_b_mode = false;
  2550. if (btcoexist->manual_control ||
  2551. btcoexist->stop_coex_dm ||
  2552. coex_sta->bt_disabled)
  2553. return;
  2554. if (BTC_MEDIA_CONNECT == type) {
  2555. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2556. "[BTCoex], MEDIA connect notify\n");
  2557. BTC_TRACE(trace_buf);
  2558. halbtc8812a1ant_ps_tdma(btcoexist, FORCE_EXEC, false,
  2559. 8); /* Force antenna setup for no scan result issue */
  2560. halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA,
  2561. FORCE_EXEC, false, false);
  2562. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
  2563. &wifi_under_b_mode);
  2564. #if 0
  2565. /* Set CCK Tx/Rx high Pri except 11b mode */
  2566. if (wifi_under_b_mode) {
  2567. btcoexist->btc_write_1byte(btcoexist, 0x6cd,
  2568. 0x00); /* CCK Tx */
  2569. btcoexist->btc_write_1byte(btcoexist, 0x6cf,
  2570. 0x00); /* CCK Rx */
  2571. } else {
  2572. btcoexist->btc_write_1byte(btcoexist, 0x6cd,
  2573. 0x10); /* CCK Tx */
  2574. btcoexist->btc_write_1byte(btcoexist, 0x6cf,
  2575. 0x10); /* CCK Rx */
  2576. }
  2577. #endif
  2578. coex_dm->backup_arfr_cnt1 = btcoexist->btc_read_4byte(btcoexist,
  2579. 0x430);
  2580. coex_dm->backup_arfr_cnt2 = btcoexist->btc_read_4byte(btcoexist,
  2581. 0x434);
  2582. coex_dm->backup_retry_limit = btcoexist->btc_read_2byte(
  2583. btcoexist, 0x42a);
  2584. coex_dm->backup_ampdu_max_time = btcoexist->btc_read_1byte(
  2585. btcoexist, 0x456);
  2586. } else {
  2587. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2588. "[BTCoex], MEDIA disconnect notify\n");
  2589. BTC_TRACE(trace_buf);
  2590. coex_dm->arp_cnt = 0;
  2591. btcoexist->btc_write_1byte(btcoexist, 0x6cd, 0x0); /* CCK Tx */
  2592. btcoexist->btc_write_1byte(btcoexist, 0x6cf, 0x0); /* CCK Rx */
  2593. }
  2594. /* only 2.4G we need to inform bt the chnl mask */
  2595. btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL,
  2596. &wifi_central_chnl);
  2597. if ((BTC_MEDIA_CONNECT == type) &&
  2598. (wifi_central_chnl <= 14)) {
  2599. /* h2c_parameter[0] = 0x1; */
  2600. h2c_parameter[0] = 0x0;
  2601. h2c_parameter[1] = wifi_central_chnl;
  2602. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  2603. if (BTC_WIFI_BW_HT40 == wifi_bw)
  2604. h2c_parameter[2] = 0x30;
  2605. else
  2606. h2c_parameter[2] = 0x20;
  2607. }
  2608. coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
  2609. coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
  2610. coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
  2611. buf[0] = data_len;
  2612. buf[1] = 0x5; /* OP_Code */
  2613. buf[2] = 0x3; /* OP_Code_Length */
  2614. buf[3] = h2c_parameter[0]; /* OP_Code_Content */
  2615. buf[4] = h2c_parameter[1];
  2616. buf[5] = h2c_parameter[2];
  2617. btcoexist->btc_set(btcoexist, BTC_SET_ACT_CTRL_BT_COEX,
  2618. (void *)&buf[0]);
  2619. }
  2620. void ex_halbtc8812a1ant_specific_packet_notify(IN struct btc_coexist *btcoexist,
  2621. IN u8 type)
  2622. {
  2623. boolean bt_hs_on = false;
  2624. u32 wifi_link_status = 0;
  2625. u32 num_of_wifi_link = 0;
  2626. boolean bt_ctrl_agg_buf_size = false;
  2627. u8 agg_buf_size = 5;
  2628. if (btcoexist->manual_control ||
  2629. btcoexist->stop_coex_dm ||
  2630. coex_sta->bt_disabled)
  2631. return;
  2632. if (BTC_PACKET_DHCP == type ||
  2633. BTC_PACKET_EAPOL == type ||
  2634. BTC_PACKET_ARP == type) {
  2635. if (BTC_PACKET_ARP == type) {
  2636. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2637. "[BTCoex], specific Packet ARP notify\n");
  2638. BTC_TRACE(trace_buf);
  2639. coex_dm->arp_cnt++;
  2640. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2641. "[BTCoex], ARP Packet Count = %d\n",
  2642. coex_dm->arp_cnt);
  2643. BTC_TRACE(trace_buf);
  2644. if (coex_dm->arp_cnt >=
  2645. 10) /* if APR PKT > 10 after connect, do not go to ActionWifiConnectedSpecificPacket(btcoexist) */
  2646. coex_sta->wifi_is_high_pri_task = false;
  2647. else
  2648. coex_sta->wifi_is_high_pri_task = true;
  2649. } else {
  2650. coex_sta->wifi_is_high_pri_task = true;
  2651. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2652. "[BTCoex], specific Packet DHCP or EAPOL notify\n");
  2653. BTC_TRACE(trace_buf);
  2654. }
  2655. } else {
  2656. coex_sta->wifi_is_high_pri_task = false;
  2657. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2658. "[BTCoex], specific Packet [Type = %d] notify\n", type);
  2659. BTC_TRACE(trace_buf);
  2660. }
  2661. coex_sta->specific_pkt_period_cnt = 0;
  2662. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
  2663. &wifi_link_status);
  2664. num_of_wifi_link = wifi_link_status >> 16;
  2665. if (num_of_wifi_link >= 2) {
  2666. halbtc8812a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
  2667. halbtc8812a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
  2668. bt_ctrl_agg_buf_size, agg_buf_size);
  2669. halbtc8812a1ant_action_wifi_multi_port(btcoexist);
  2670. return;
  2671. }
  2672. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  2673. if (coex_sta->c2h_bt_inquiry_page) {
  2674. halbtc8812a1ant_action_bt_inquiry(btcoexist);
  2675. return;
  2676. } else if (bt_hs_on) {
  2677. halbtc8812a1ant_action_hs(btcoexist);
  2678. return;
  2679. }
  2680. if (BTC_PACKET_DHCP == type ||
  2681. BTC_PACKET_EAPOL == type ||
  2682. ((BTC_PACKET_ARP == type) && (coex_sta->wifi_is_high_pri_task)))
  2683. halbtc8812a1ant_action_wifi_connected_specific_packet(btcoexist);
  2684. }
  2685. void ex_halbtc8812a1ant_bt_info_notify(IN struct btc_coexist *btcoexist,
  2686. IN u8 *tmp_buf, IN u8 length)
  2687. {
  2688. u8 bt_info = 0;
  2689. u8 i, rsp_source = 0;
  2690. boolean wifi_connected = false;
  2691. boolean bt_busy = false;
  2692. coex_sta->c2h_bt_info_req_sent = false;
  2693. rsp_source = tmp_buf[0] & 0xf;
  2694. if (rsp_source >= BT_INFO_SRC_8812A_1ANT_MAX)
  2695. rsp_source = BT_INFO_SRC_8812A_1ANT_WIFI_FW;
  2696. coex_sta->bt_info_c2h_cnt[rsp_source]++;
  2697. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2698. "[BTCoex], Bt info[%d], length=%d, hex data=[", rsp_source,
  2699. length);
  2700. BTC_TRACE(trace_buf);
  2701. for (i = 0; i < length; i++) {
  2702. coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i];
  2703. if (i == 1)
  2704. bt_info = tmp_buf[i];
  2705. if (i == length - 1) {
  2706. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n",
  2707. tmp_buf[i]);
  2708. BTC_TRACE(trace_buf);
  2709. } else {
  2710. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ",
  2711. tmp_buf[i]);
  2712. BTC_TRACE(trace_buf);
  2713. }
  2714. }
  2715. if (BT_INFO_SRC_8812A_1ANT_WIFI_FW != rsp_source) {
  2716. coex_sta->bt_retry_cnt = /* [3:0] */
  2717. coex_sta->bt_info_c2h[rsp_source][2] & 0xf;
  2718. if (coex_sta->bt_retry_cnt >= 1)
  2719. coex_sta->pop_event_cnt++;
  2720. if (coex_sta->bt_info_c2h[rsp_source][2] & 0x20)
  2721. coex_sta->c2h_bt_page = true;
  2722. else
  2723. coex_sta->c2h_bt_page = false;
  2724. coex_sta->bt_rssi =
  2725. coex_sta->bt_info_c2h[rsp_source][3] * 2 - 90;
  2726. /* coex_sta->bt_info_c2h[rsp_source][3]*2+10; */
  2727. coex_sta->bt_info_ext =
  2728. coex_sta->bt_info_c2h[rsp_source][4];
  2729. coex_sta->bt_tx_rx_mask = (coex_sta->bt_info_c2h[rsp_source][2]
  2730. & 0x40);
  2731. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TX_RX_MASK,
  2732. &coex_sta->bt_tx_rx_mask);
  2733. if (!coex_sta->bt_tx_rx_mask) {
  2734. /* BT into is responded by BT FW and BT RF REG 0x3C != 0x15 => Need to switch BT TRx Mask */
  2735. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2736. "[BTCoex], Switch BT TRx Mask since BT RF REG 0x3C != 0x15\n");
  2737. BTC_TRACE(trace_buf);
  2738. btcoexist->btc_set_bt_reg(btcoexist, BTC_BT_REG_RF,
  2739. 0x3c, 0x15);
  2740. }
  2741. /* Here we need to resend some wifi info to BT */
  2742. /* because bt is reset and loss of the info. */
  2743. if (coex_sta->bt_info_ext & BIT(1)) {
  2744. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2745. "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
  2746. BTC_TRACE(trace_buf);
  2747. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  2748. &wifi_connected);
  2749. if (wifi_connected)
  2750. ex_halbtc8812a1ant_media_status_notify(
  2751. btcoexist, BTC_MEDIA_CONNECT);
  2752. else
  2753. ex_halbtc8812a1ant_media_status_notify(
  2754. btcoexist, BTC_MEDIA_DISCONNECT);
  2755. }
  2756. if (coex_sta->bt_info_ext & BIT(3)) {
  2757. if (!btcoexist->manual_control &&
  2758. !btcoexist->stop_coex_dm) {
  2759. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2760. "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n");
  2761. BTC_TRACE(trace_buf);
  2762. halbtc8812a1ant_ignore_wlan_act(btcoexist,
  2763. FORCE_EXEC, false);
  2764. }
  2765. } else {
  2766. /* BT already NOT ignore Wlan active, do nothing here. */
  2767. }
  2768. #if (BT_AUTO_REPORT_ONLY_8812A_1ANT == 0)
  2769. if ((coex_sta->bt_info_ext & BIT(4))) {
  2770. /* BT auto report already enabled, do nothing */
  2771. } else
  2772. halbtc8812a1ant_bt_auto_report(btcoexist, FORCE_EXEC,
  2773. true);
  2774. #endif
  2775. }
  2776. /* check BIT2 first ==> check if bt is under inquiry or page scan */
  2777. if (bt_info & BT_INFO_8812A_1ANT_B_INQ_PAGE)
  2778. coex_sta->c2h_bt_inquiry_page = true;
  2779. else
  2780. coex_sta->c2h_bt_inquiry_page = false;
  2781. /* set link exist status */
  2782. if (!(bt_info & BT_INFO_8812A_1ANT_B_CONNECTION)) {
  2783. coex_sta->bt_link_exist = false;
  2784. coex_sta->pan_exist = false;
  2785. coex_sta->a2dp_exist = false;
  2786. coex_sta->hid_exist = false;
  2787. coex_sta->sco_exist = false;
  2788. } else { /* connection exists */
  2789. coex_sta->bt_link_exist = true;
  2790. if (bt_info & BT_INFO_8812A_1ANT_B_FTP)
  2791. coex_sta->pan_exist = true;
  2792. else
  2793. coex_sta->pan_exist = false;
  2794. if (bt_info & BT_INFO_8812A_1ANT_B_A2DP)
  2795. coex_sta->a2dp_exist = true;
  2796. else
  2797. coex_sta->a2dp_exist = false;
  2798. if (bt_info & BT_INFO_8812A_1ANT_B_HID)
  2799. coex_sta->hid_exist = true;
  2800. else
  2801. coex_sta->hid_exist = false;
  2802. if (bt_info & BT_INFO_8812A_1ANT_B_SCO_ESCO)
  2803. coex_sta->sco_exist = true;
  2804. else
  2805. coex_sta->sco_exist = false;
  2806. }
  2807. halbtc8812a1ant_update_bt_link_info(btcoexist);
  2808. bt_info = bt_info &
  2809. 0x1f; /* mask profile bit for connect-ilde identification ( for CSR case: A2DP idle --> 0x41) */
  2810. if (!(bt_info & BT_INFO_8812A_1ANT_B_CONNECTION)) {
  2811. coex_dm->bt_status = BT_8812A_1ANT_BT_STATUS_NON_CONNECTED_IDLE;
  2812. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2813. "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n");
  2814. BTC_TRACE(trace_buf);
  2815. } else if (bt_info ==
  2816. BT_INFO_8812A_1ANT_B_CONNECTION) { /* connection exists but no busy */
  2817. coex_dm->bt_status = BT_8812A_1ANT_BT_STATUS_CONNECTED_IDLE;
  2818. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2819. "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
  2820. BTC_TRACE(trace_buf);
  2821. } else if ((bt_info & BT_INFO_8812A_1ANT_B_SCO_ESCO) ||
  2822. (bt_info & BT_INFO_8812A_1ANT_B_SCO_BUSY)) {
  2823. coex_dm->bt_status = BT_8812A_1ANT_BT_STATUS_SCO_BUSY;
  2824. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2825. "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
  2826. BTC_TRACE(trace_buf);
  2827. } else if (bt_info & BT_INFO_8812A_1ANT_B_ACL_BUSY) {
  2828. if (BT_8812A_1ANT_BT_STATUS_ACL_BUSY != coex_dm->bt_status)
  2829. coex_dm->auto_tdma_adjust = false;
  2830. coex_dm->bt_status = BT_8812A_1ANT_BT_STATUS_ACL_BUSY;
  2831. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2832. "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
  2833. BTC_TRACE(trace_buf);
  2834. } else {
  2835. coex_dm->bt_status = BT_8812A_1ANT_BT_STATUS_MAX;
  2836. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2837. "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n");
  2838. BTC_TRACE(trace_buf);
  2839. }
  2840. if ((BT_8812A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
  2841. (BT_8812A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
  2842. (BT_8812A_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
  2843. bt_busy = true;
  2844. else
  2845. bt_busy = false;
  2846. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
  2847. halbtc8812a1ant_run_coexist_mechanism(btcoexist);
  2848. }
  2849. void ex_halbtc8812a1ant_rf_status_notify(IN struct btc_coexist *btcoexist,
  2850. IN u8 type)
  2851. {
  2852. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], RF Status notify\n");
  2853. BTC_TRACE(trace_buf);
  2854. if (BTC_RF_ON == type) {
  2855. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2856. "[BTCoex], RF is turned ON!!\n");
  2857. BTC_TRACE(trace_buf);
  2858. btcoexist->stop_coex_dm = false;
  2859. } else if (BTC_RF_OFF == type) {
  2860. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2861. "[BTCoex], RF is turned OFF!!\n");
  2862. BTC_TRACE(trace_buf);
  2863. halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  2864. 0x0, 0x0);
  2865. halbtc8812a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0);
  2866. halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT,
  2867. FORCE_EXEC, false, true);
  2868. halbtc8812a1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
  2869. btcoexist->stop_coex_dm = true;
  2870. }
  2871. }
  2872. void ex_halbtc8812a1ant_halt_notify(IN struct btc_coexist *btcoexist)
  2873. {
  2874. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n");
  2875. BTC_TRACE(trace_buf);
  2876. halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
  2877. 0x0);
  2878. halbtc8812a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0);
  2879. halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, FORCE_EXEC,
  2880. false, true);
  2881. halbtc8812a1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
  2882. ex_halbtc8812a1ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT);
  2883. btcoexist->stop_coex_dm = true;
  2884. }
  2885. void ex_halbtc8812a1ant_pnp_notify(IN struct btc_coexist *btcoexist,
  2886. IN u8 pnp_state)
  2887. {
  2888. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Pnp notify\n");
  2889. BTC_TRACE(trace_buf);
  2890. if (BTC_WIFI_PNP_SLEEP == pnp_state) {
  2891. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2892. "[BTCoex], Pnp notify to SLEEP\n");
  2893. BTC_TRACE(trace_buf);
  2894. halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  2895. 0x0, 0x0);
  2896. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  2897. halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT,
  2898. FORCE_EXEC, false, true);
  2899. halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  2900. /* Sinda 20150819, workaround for driver skip leave IPS/LPS to speed up sleep time. */
  2901. /* Driver do not leave IPS/LPS when driver is going to sleep, so BTCoexistence think wifi is still under IPS/LPS */
  2902. /* BT should clear UnderIPS/UnderLPS state to avoid mismatch state after wakeup. */
  2903. coex_sta->under_ips = false;
  2904. coex_sta->under_lps = false;
  2905. btcoexist->stop_coex_dm = true;
  2906. } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) {
  2907. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2908. "[BTCoex], Pnp notify to WAKE UP\n");
  2909. BTC_TRACE(trace_buf);
  2910. btcoexist->stop_coex_dm = false;
  2911. halbtc8812a1ant_init_hw_config(btcoexist, false, false);
  2912. halbtc8812a1ant_init_coex_dm(btcoexist);
  2913. halbtc8812a1ant_query_bt_info(btcoexist);
  2914. }
  2915. }
  2916. void ex_halbtc8812a1ant_coex_dm_reset(IN struct btc_coexist *btcoexist)
  2917. {
  2918. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2919. "[BTCoex], *****************Coex DM Reset*****************\n");
  2920. BTC_TRACE(trace_buf);
  2921. halbtc8812a1ant_init_hw_config(btcoexist, false, false);
  2922. halbtc8812a1ant_init_coex_dm(btcoexist);
  2923. }
  2924. void ex_halbtc8812a1ant_periodical(IN struct btc_coexist *btcoexist)
  2925. {
  2926. #if (BT_AUTO_REPORT_ONLY_8812A_1ANT == 0)
  2927. halbtc8812a1ant_query_bt_info(btcoexist);
  2928. halbtc8812a1ant_monitor_bt_enable_disable(btcoexist);
  2929. #else
  2930. halbtc8812a1ant_monitor_bt_ctr(btcoexist);
  2931. halbtc8812a1ant_monitor_wifi_ctr(btcoexist);
  2932. if (halbtc8812a1ant_is_wifi_status_changed(btcoexist) ||
  2933. coex_dm->auto_tdma_adjust)
  2934. halbtc8812a1ant_run_coexist_mechanism(btcoexist);
  2935. coex_sta->specific_pkt_period_cnt++;
  2936. #endif
  2937. }
  2938. void ex_halbtc8812a1ant_dbg_control(IN struct btc_coexist *btcoexist,
  2939. IN u8 op_code, IN u8 op_len, IN u8 *pdata)
  2940. {
  2941. switch (op_code) {
  2942. case BTC_DBG_SET_COEX_NORMAL:
  2943. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2944. "[BTCoex], Set CoexMode to Normal\n");
  2945. BTC_TRACE(trace_buf);
  2946. btcoexist->manual_control = false;
  2947. halbtc8812a1ant_init_coex_dm(btcoexist);
  2948. break;
  2949. case BTC_DBG_SET_COEX_WIFI_ONLY:
  2950. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2951. "[BTCoex], Set CoexMode to Wifi Only\n");
  2952. BTC_TRACE(trace_buf);
  2953. btcoexist->manual_control = true;
  2954. halbtc8812a1ant_power_save_state(btcoexist,
  2955. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  2956. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
  2957. 9);
  2958. break;
  2959. case BTC_DBG_SET_COEX_BT_ONLY:
  2960. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2961. "[BTCoex], Set CoexMode to BT only\n");
  2962. BTC_TRACE(trace_buf);
  2963. btcoexist->manual_control = true;
  2964. halbtc8812a1ant_power_save_state(btcoexist,
  2965. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  2966. halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
  2967. 0);
  2968. break;
  2969. case BTC_DBG_SET_COEX_DEC_BT_PWR:
  2970. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2971. "[BTCoex], Set Dec BT power\n");
  2972. BTC_TRACE(trace_buf);
  2973. {
  2974. u8 data_len = 4;
  2975. u8 buf[6] = {0};
  2976. u8 dec_bt_pwr = 0, pwr_level = 0;
  2977. if (op_len == 2) {
  2978. dec_bt_pwr = pdata[0];
  2979. pwr_level = pdata[1];
  2980. buf[0] = data_len;
  2981. buf[1] = 0x3; /* OP_Code */
  2982. buf[2] = 0x2; /* OP_Code_Length */
  2983. buf[3] = dec_bt_pwr; /* OP_Code_Content */
  2984. buf[4] = pwr_level;
  2985. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2986. "[BTCoex], Set Dec BT power=%d, pwr_level=%d\n",
  2987. dec_bt_pwr, pwr_level);
  2988. BTC_TRACE(trace_buf);
  2989. btcoexist->btc_set(btcoexist,
  2990. BTC_SET_ACT_CTRL_BT_COEX,
  2991. (void *)&buf[0]);
  2992. }
  2993. }
  2994. break;
  2995. case BTC_DBG_SET_COEX_BT_AFH_MAP:
  2996. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2997. "[BTCoex], Set BT AFH Map\n");
  2998. BTC_TRACE(trace_buf);
  2999. {
  3000. u8 data_len = 5;
  3001. u8 buf[6] = {0};
  3002. if (op_len == 3) {
  3003. buf[0] = data_len;
  3004. buf[1] = 0x5; /* OP_Code */
  3005. buf[2] = 0x3; /* OP_Code_Length */
  3006. buf[3] = pdata[0]; /* OP_Code_Content */
  3007. buf[4] = pdata[1];
  3008. buf[5] = pdata[2];
  3009. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3010. "[BTCoex], Set BT AFH Map = %02x %02x %02x\n",
  3011. pdata[0], pdata[1], pdata[2]);
  3012. BTC_TRACE(trace_buf);
  3013. btcoexist->btc_set(btcoexist,
  3014. BTC_SET_ACT_CTRL_BT_COEX,
  3015. (void *)&buf[0]);
  3016. }
  3017. }
  3018. break;
  3019. case BTC_DBG_SET_COEX_BT_IGNORE_WLAN_ACT:
  3020. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3021. "[BTCoex], Set BT Ignore Wlan Active\n");
  3022. BTC_TRACE(trace_buf);
  3023. {
  3024. u8 data_len = 3;
  3025. u8 buf[6] = {0};
  3026. if (op_len == 1) {
  3027. buf[0] = data_len;
  3028. buf[1] = 0x1; /* OP_Code */
  3029. buf[2] = 0x1; /* OP_Code_Length */
  3030. buf[3] = pdata[0]; /* OP_Code_Content */
  3031. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3032. "[BTCoex], Set BT Ignore Wlan Active = 0x%x\n",
  3033. pdata[0]);
  3034. BTC_TRACE(trace_buf);
  3035. btcoexist->btc_set(btcoexist,
  3036. BTC_SET_ACT_CTRL_BT_COEX,
  3037. (void *)&buf[0]);
  3038. }
  3039. }
  3040. break;
  3041. default:
  3042. break;
  3043. }
  3044. }
  3045. #endif
  3046. #endif /* #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) */