halbtc8723b2ant.c 134 KB

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