halbtc8723b2ant.c 130 KB

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