halbtc8821a2ant.c 130 KB

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