halbtc8821c1ant.c 159 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2016 - 2017 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. *****************************************************************************/
  15. #include "mp_precomp.h"
  16. #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1)
  17. #if (RTL8821C_SUPPORT == 1)
  18. static u8 *trace_buf = &gl_btc_trace_buf[0];
  19. const char *const glbt_info_src_8821c_1ant[] = {
  20. "BT Info[wifi fw]",
  21. "BT Info[bt rsp]",
  22. "BT Info[bt auto report]",
  23. };
  24. u32 glcoex_ver_date_8821c_1ant = 20180712;
  25. u32 glcoex_ver_8821c_1ant = 0x32;
  26. u32 glcoex_ver_btdesired_8821c_1ant = 0x28;
  27. #if 0
  28. static
  29. u8 halbtc8821c1ant_bt_rssi_state(struct btc_coexist *btc, u8 level_num,
  30. u8 rssi_thresh, u8 rssi_thresh1)
  31. {
  32. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  33. s32 bt_rssi = 0;
  34. u8 bt_rssi_state = coex_sta->pre_bt_rssi_state;
  35. bt_rssi = coex_sta->bt_rssi;
  36. if (level_num == 2) {
  37. if (coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW ||
  38. coex_sta->pre_bt_rssi_state ==
  39. BTC_RSSI_STATE_STAY_LOW) {
  40. if (bt_rssi >= (rssi_thresh +
  41. BTC_RSSI_COEX_THRESH_TOL_8821C_1ANT))
  42. bt_rssi_state = BTC_RSSI_STATE_HIGH;
  43. else
  44. bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  45. } else {
  46. if (bt_rssi < rssi_thresh)
  47. bt_rssi_state = BTC_RSSI_STATE_LOW;
  48. else
  49. bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  50. }
  51. } else if (level_num == 3) {
  52. if (rssi_thresh > rssi_thresh1) {
  53. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  54. "[BTCoex], BT Rssi thresh error!!\n");
  55. BTC_TRACE(trace_buf);
  56. return coex_sta->pre_bt_rssi_state;
  57. }
  58. if (coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW ||
  59. coex_sta->pre_bt_rssi_state ==
  60. BTC_RSSI_STATE_STAY_LOW) {
  61. if (bt_rssi >= (rssi_thresh +
  62. BTC_RSSI_COEX_THRESH_TOL_8821C_1ANT))
  63. bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
  64. else
  65. bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  66. } else if (coex_sta->pre_bt_rssi_state ==
  67. BTC_RSSI_STATE_MEDIUM ||
  68. coex_sta->pre_bt_rssi_state ==
  69. BTC_RSSI_STATE_STAY_MEDIUM) {
  70. if (bt_rssi >= (rssi_thresh1 +
  71. BTC_RSSI_COEX_THRESH_TOL_8821C_1ANT))
  72. bt_rssi_state = BTC_RSSI_STATE_HIGH;
  73. else if (bt_rssi < rssi_thresh)
  74. bt_rssi_state = BTC_RSSI_STATE_LOW;
  75. else
  76. bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
  77. } else {
  78. if (bt_rssi < rssi_thresh1)
  79. bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
  80. else
  81. bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  82. }
  83. }
  84. coex_sta->pre_bt_rssi_state = bt_rssi_state;
  85. return bt_rssi_state;
  86. }
  87. #endif
  88. #if 0
  89. static
  90. u8 halbtc8821c1ant_wifi_rssi_state(struct btc_coexist *btc, u8 index,
  91. u8 level_num, u8 rssi_thresh,
  92. u8 rssi_thresh1)
  93. {
  94. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  95. s32 wifi_rssi = 0;
  96. u8 wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index];
  97. btc->btc_get(btc, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
  98. if (level_num == 2) {
  99. if (coex_sta->pre_wifi_rssi_state[index] ==
  100. BTC_RSSI_STATE_LOW ||
  101. coex_sta->pre_wifi_rssi_state[index] ==
  102. BTC_RSSI_STATE_STAY_LOW) {
  103. if (wifi_rssi >= rssi_thresh +
  104. BTC_RSSI_COEX_THRESH_TOL_8821C_1ANT)
  105. wifi_rssi_state = BTC_RSSI_STATE_HIGH;
  106. else
  107. wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  108. } else {
  109. if (wifi_rssi < rssi_thresh)
  110. wifi_rssi_state = BTC_RSSI_STATE_LOW;
  111. else
  112. wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  113. }
  114. } else if (level_num == 3) {
  115. if (rssi_thresh > rssi_thresh1) {
  116. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  117. "[BTCoex], wifi RSSI thresh error!!\n");
  118. BTC_TRACE(trace_buf);
  119. return coex_sta->pre_wifi_rssi_state[index];
  120. }
  121. if (coex_sta->pre_wifi_rssi_state[index] ==
  122. BTC_RSSI_STATE_LOW ||
  123. coex_sta->pre_wifi_rssi_state[index] ==
  124. BTC_RSSI_STATE_STAY_LOW) {
  125. if (wifi_rssi >= rssi_thresh +
  126. BTC_RSSI_COEX_THRESH_TOL_8821C_1ANT)
  127. wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
  128. else
  129. wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  130. } else if (coex_sta->pre_wifi_rssi_state[index] ==
  131. BTC_RSSI_STATE_MEDIUM ||
  132. coex_sta->pre_wifi_rssi_state[index] ==
  133. BTC_RSSI_STATE_STAY_MEDIUM) {
  134. if (wifi_rssi >= rssi_thresh1 +
  135. BTC_RSSI_COEX_THRESH_TOL_8821C_1ANT)
  136. wifi_rssi_state = BTC_RSSI_STATE_HIGH;
  137. else if (wifi_rssi < rssi_thresh)
  138. wifi_rssi_state = BTC_RSSI_STATE_LOW;
  139. else
  140. wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
  141. } else {
  142. if (wifi_rssi < rssi_thresh1)
  143. wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
  144. else
  145. wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  146. }
  147. }
  148. coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state;
  149. return wifi_rssi_state;
  150. }
  151. #endif
  152. static
  153. void halbtc8821c1ant_limited_rx(struct btc_coexist *btc, boolean force_exec,
  154. boolean rej_ap_agg_pkt,
  155. boolean bt_ctrl_agg_buf_size, u8 agg_buf_size)
  156. {
  157. boolean reject_rx_agg = rej_ap_agg_pkt;
  158. boolean bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size;
  159. u8 rx_agg_size = agg_buf_size;
  160. /* ============================================
  161. * Rx Aggregation related setting
  162. * ============================================
  163. */
  164. btc->btc_set(btc, BTC_SET_BL_TO_REJ_AP_AGG_PKT, &reject_rx_agg);
  165. /* decide BT control aggregation buf size or not */
  166. btc->btc_set(btc, BTC_SET_BL_BT_CTRL_AGG_SIZE, &bt_ctrl_rx_agg_size);
  167. /* aggregation buf size, only work
  168. * when BT control Rx aggregation size
  169. */
  170. btc->btc_set(btc, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size);
  171. /* real update aggregation setting */
  172. btc->btc_set(btc, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
  173. }
  174. static
  175. void halbtc8821c1ant_low_penalty_ra(struct btc_coexist *btc,
  176. boolean force_exec, boolean low_penalty_ra,
  177. u8 thres)
  178. {
  179. struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
  180. static u8 cur_thres;
  181. if (!force_exec) {
  182. if (low_penalty_ra == coex_dm->cur_low_penalty_ra &&
  183. thres == cur_thres)
  184. return;
  185. }
  186. if (low_penalty_ra)
  187. btc->btc_phydm_modify_RA_PCR_threshold(btc, 0, thres);
  188. else
  189. btc->btc_phydm_modify_RA_PCR_threshold(btc, 0, 0);
  190. coex_dm->cur_low_penalty_ra = low_penalty_ra;
  191. cur_thres = thres;
  192. }
  193. static
  194. void halbtc8821c1ant_write_scbd(struct btc_coexist *btc, u16 bitpos,
  195. boolean state)
  196. {
  197. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  198. static u16 originalval = 0x8002, preval;
  199. if (state)
  200. originalval = originalval | bitpos;
  201. else
  202. originalval = originalval & (~bitpos);
  203. coex_sta->score_board_WB = originalval;
  204. if (originalval != preval) {
  205. preval = originalval;
  206. btc->btc_write_2byte(btc, 0xaa, originalval);
  207. } else {
  208. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  209. "[BTCoex], %s: return for nochange\n", __func__);
  210. BTC_TRACE(trace_buf);
  211. }
  212. }
  213. static
  214. void halbtc8821c1ant_read_scbd(struct btc_coexist *btc,
  215. u16 *score_board_val)
  216. {
  217. *score_board_val = (btc->btc_read_2byte(btc, 0xaa)) & 0x7fff;
  218. }
  219. static
  220. void halbtc8821c1ant_query_bt_info(struct btc_coexist *btc)
  221. {
  222. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  223. u8 h2c_parameter[1] = {0};
  224. if (coex_sta->bt_disabled) {
  225. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  226. "[BTCoex], No query BT info because BT is disabled!\n");
  227. BTC_TRACE(trace_buf);
  228. return;
  229. }
  230. h2c_parameter[0] |= BIT(0); /* trigger */
  231. btc->btc_fill_h2c(btc, 0x61, 1, h2c_parameter);
  232. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  233. "[BTCoex], WL query BT info!!\n");
  234. BTC_TRACE(trace_buf);
  235. }
  236. static
  237. void halbtc8821c1ant_enable_gnt_to_gpio(struct btc_coexist *btc,
  238. boolean isenable)
  239. {
  240. static u8 bit_val[5] = {0, 0, 0, 0, 0};
  241. static boolean state;
  242. if (!btc->dbg_mode)
  243. return;
  244. if (state == isenable)
  245. return;
  246. state = isenable;
  247. if (isenable) {
  248. /* enable GNT_WL, GNT_BT to GPIO for debug */
  249. btc->btc_write_1byte_bitmask(btc, 0x73, 0x8, 0x1);
  250. /* store original value */
  251. /*0x66[4] */
  252. bit_val[0] = (btc->btc_read_1byte(btc, 0x66) & BIT(4)) >> 4;
  253. /*0x66[8] */
  254. bit_val[1] = (btc->btc_read_1byte(btc, 0x67) & BIT(0));
  255. /*0x40[19] */
  256. bit_val[2] = (btc->btc_read_1byte(btc, 0x42) & BIT(3)) >> 3;
  257. /*0x64[15] */
  258. bit_val[3] = (btc->btc_read_1byte(btc, 0x65) & BIT(7)) >> 7;
  259. /*0x70[18] */
  260. bit_val[4] = (btc->btc_read_1byte(btc, 0x72) & BIT(2)) >> 2;
  261. /* switch GPIO Mux */
  262. /*0x66[4] = 0 */
  263. btc->btc_write_1byte_bitmask(btc, 0x66, BIT(4), 0x0);
  264. /*0x66[8] = 0 */
  265. btc->btc_write_1byte_bitmask(btc, 0x67, BIT(0), 0x0);
  266. /*0x40[19] = 0 */
  267. btc->btc_write_1byte_bitmask(btc, 0x42, BIT(3), 0x0);
  268. /*0x64[15] = 0 */
  269. btc->btc_write_1byte_bitmask(btc, 0x65, BIT(7), 0x0);
  270. /*0x70[18] = 0 */
  271. btc->btc_write_1byte_bitmask(btc, 0x72, BIT(2), 0x0);
  272. } else {
  273. btc->btc_write_1byte_bitmask(btc, 0x73, 0x8, 0x0);
  274. /* Restore original value */
  275. /* switch GPIO Mux */
  276. /*0x66[4] = 0 */
  277. btc->btc_write_1byte_bitmask(btc, 0x66, BIT(4), bit_val[0]);
  278. /*0x66[8] = 0 */
  279. btc->btc_write_1byte_bitmask(btc, 0x67, BIT(0), bit_val[1]);
  280. /*0x40[19] = 0 */
  281. btc->btc_write_1byte_bitmask(btc, 0x42, BIT(3), bit_val[2]);
  282. /*0x64[15] = 0 */
  283. btc->btc_write_1byte_bitmask(btc, 0x65, BIT(7), bit_val[3]);
  284. /*0x70[18] = 0 */
  285. btc->btc_write_1byte_bitmask(btc, 0x72, BIT(2), bit_val[4]);
  286. }
  287. }
  288. static
  289. void halbtc8821c1ant_monitor_bt_ctr(struct btc_coexist *btc)
  290. {
  291. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  292. struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
  293. u32 reg_hp_txrx, reg_lp_txrx, u32tmp;
  294. u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0;
  295. static u8 num_of_bt_counter_chk, cnt_slave, cnt_overhead,
  296. cnt_autoslot_hang;
  297. struct btc_bt_link_info *bt_link_info = &btc->bt_link_info;
  298. /* to avoid 0x76e[3] = 1 (WLAN_Act control by PTA) during IPS */
  299. /* if (! (btc->btc_read_1byte(btc, 0x76e) & 0x8) ) */
  300. reg_hp_txrx = 0x770;
  301. reg_lp_txrx = 0x774;
  302. u32tmp = btc->btc_read_4byte(btc, reg_hp_txrx);
  303. reg_hp_tx = u32tmp & MASKLWORD;
  304. reg_hp_rx = (u32tmp & MASKHWORD) >> 16;
  305. u32tmp = btc->btc_read_4byte(btc, reg_lp_txrx);
  306. reg_lp_tx = u32tmp & MASKLWORD;
  307. reg_lp_rx = (u32tmp & MASKHWORD) >> 16;
  308. coex_sta->high_priority_tx = reg_hp_tx;
  309. coex_sta->high_priority_rx = reg_hp_rx;
  310. coex_sta->low_priority_tx = reg_lp_tx;
  311. coex_sta->low_priority_rx = reg_lp_rx;
  312. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  313. "[BTCoex], Hi-Pri Rx/Tx: %d/%d, Lo-Pri Rx/Tx: %d/%d\n",
  314. reg_hp_rx, reg_hp_tx, reg_lp_rx, reg_lp_tx);
  315. BTC_TRACE(trace_buf);
  316. if (coex_dm->bt_status == BT_8821C_1ANT_BSTATUS_NCON_IDLE) {
  317. if (coex_sta->high_priority_rx >= 15) {
  318. if (cnt_overhead < 3)
  319. cnt_overhead++;
  320. if (cnt_overhead == 3)
  321. coex_sta->is_hi_pri_rx_overhead = TRUE;
  322. } else {
  323. if (cnt_overhead > 0)
  324. cnt_overhead--;
  325. if (cnt_overhead == 0)
  326. coex_sta->is_hi_pri_rx_overhead = FALSE;
  327. }
  328. } else
  329. coex_sta->is_hi_pri_rx_overhead = FALSE;
  330. /* reset counter */
  331. btc->btc_write_1byte(btc, 0x76e, 0xc);
  332. if (coex_sta->low_priority_tx > 1150 && !coex_sta->c2h_bt_inquiry_page)
  333. coex_sta->pop_event_cnt++;
  334. if (coex_sta->low_priority_rx >= 1150 &&
  335. coex_sta->low_priority_rx >= coex_sta->low_priority_tx &&
  336. !coex_sta->under_ips && !coex_sta->c2h_bt_inquiry_page &&
  337. (bt_link_info->a2dp_exist || bt_link_info->pan_exist)) {
  338. if (cnt_slave >= 2) {
  339. bt_link_info->slave_role = TRUE;
  340. cnt_slave = 2;
  341. } else
  342. cnt_slave++;
  343. } else {
  344. if (cnt_slave == 0) {
  345. bt_link_info->slave_role = FALSE;
  346. cnt_slave = 0;
  347. } else
  348. cnt_slave--;
  349. }
  350. if (coex_sta->is_tdma_btautoslot) {
  351. if (coex_sta->low_priority_tx >= 1300 &&
  352. coex_sta->low_priority_rx <= 15) {
  353. if (cnt_autoslot_hang >= 2) {
  354. coex_sta->is_tdma_btautoslot_hang = TRUE;
  355. cnt_autoslot_hang = 2;
  356. } else
  357. cnt_autoslot_hang++;
  358. } else {
  359. if (cnt_autoslot_hang == 0) {
  360. coex_sta->is_tdma_btautoslot_hang = FALSE;
  361. cnt_autoslot_hang = 0;
  362. } else
  363. cnt_autoslot_hang--;
  364. }
  365. }
  366. if (bt_link_info->hid_only) {
  367. if (coex_sta->low_priority_tx > 100)
  368. coex_sta->is_hid_low_pri_tx_overhead = true;
  369. else
  370. coex_sta->is_hid_low_pri_tx_overhead = false;
  371. }
  372. if (!coex_sta->bt_disabled) {
  373. if ((coex_sta->high_priority_tx == 0) &&
  374. (coex_sta->high_priority_rx == 0) &&
  375. (coex_sta->low_priority_tx == 0) &&
  376. (coex_sta->low_priority_rx == 0)) {
  377. num_of_bt_counter_chk++;
  378. if (num_of_bt_counter_chk >= 3) {
  379. halbtc8821c1ant_query_bt_info(btc);
  380. num_of_bt_counter_chk = 0;
  381. }
  382. }
  383. }
  384. }
  385. static
  386. void halbtc8821c1ant_monitor_wifi_ctr(struct btc_coexist *btc)
  387. {
  388. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  389. struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
  390. boolean wifi_busy = FALSE, wifi_scan = FALSE;
  391. static u8 wl_noisy_count0, wl_noisy_count1 = 3, wl_noisy_count2;
  392. u32 cnt_cck;
  393. static u8 cnt_ccklocking;
  394. u8 h2c_parameter[1] = {0};
  395. struct btc_bt_link_info *bt_link_info = &btc->bt_link_info;
  396. /* Only enable for windows becaus 8821cu
  397. * H2C 0x69 unknown fail @ linux
  398. */
  399. if (btc->chip_interface != BTC_INTF_USB) {
  400. /*send h2c to query WL FW dbg info */
  401. if ((coex_dm->cur_ps_tdma_on && coex_sta->force_lps_ctrl) ||
  402. (coex_sta->acl_busy && bt_link_info->a2dp_exist)) {
  403. h2c_parameter[0] = 0x8;
  404. btc->btc_fill_h2c(btc, 0x69, 1, h2c_parameter);
  405. }
  406. }
  407. btc->btc_get(btc, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  408. btc->btc_get(btc, BTC_GET_BL_WIFI_SCAN, &wifi_scan);
  409. coex_sta->crc_ok_cck =
  410. btc->btc_phydm_query_PHY_counter(btc, PHYDM_INFO_CRC32_OK_CCK);
  411. coex_sta->crc_ok_11g =
  412. btc->btc_phydm_query_PHY_counter(btc, PHYDM_INFO_CRC32_OK_LEGACY);
  413. coex_sta->crc_ok_11n =
  414. btc->btc_phydm_query_PHY_counter(btc, PHYDM_INFO_CRC32_OK_HT);
  415. coex_sta->crc_ok_11n_vht =
  416. btc->btc_phydm_query_PHY_counter(btc, PHYDM_INFO_CRC32_OK_VHT);
  417. coex_sta->crc_err_cck =
  418. btc->btc_phydm_query_PHY_counter(btc, PHYDM_INFO_CRC32_ERROR_CCK);
  419. coex_sta->crc_err_11g =
  420. btc->btc_phydm_query_PHY_counter(btc, PHYDM_INFO_CRC32_ERROR_LEGACY);
  421. coex_sta->crc_err_11n =
  422. btc->btc_phydm_query_PHY_counter(btc, PHYDM_INFO_CRC32_ERROR_HT);
  423. coex_sta->crc_err_11n_vht =
  424. btc->btc_phydm_query_PHY_counter(btc, PHYDM_INFO_CRC32_ERROR_VHT);
  425. /* CCK lock identification */
  426. if (coex_sta->cck_lock)
  427. cnt_ccklocking++;
  428. else if (cnt_ccklocking != 0)
  429. cnt_ccklocking--;
  430. if (cnt_ccklocking >= 3) {
  431. cnt_ccklocking = 3;
  432. coex_sta->cck_lock_ever = TRUE;
  433. }
  434. /* WiFi environment noisy identification */
  435. cnt_cck = coex_sta->crc_ok_cck + coex_sta->crc_err_cck;
  436. if (!wifi_busy && !coex_sta->cck_lock) {
  437. if (cnt_cck > 250) {
  438. if (wl_noisy_count2 < 3)
  439. wl_noisy_count2++;
  440. if (wl_noisy_count2 == 3) {
  441. wl_noisy_count0 = 0;
  442. wl_noisy_count1 = 0;
  443. }
  444. } else if (cnt_cck < 100) {
  445. if (wl_noisy_count0 < 3)
  446. wl_noisy_count0++;
  447. if (wl_noisy_count0 == 3) {
  448. wl_noisy_count1 = 0;
  449. wl_noisy_count2 = 0;
  450. }
  451. } else {
  452. if (wl_noisy_count1 < 3)
  453. wl_noisy_count1++;
  454. if (wl_noisy_count1 == 3) {
  455. wl_noisy_count0 = 0;
  456. wl_noisy_count2 = 0;
  457. }
  458. }
  459. if (wl_noisy_count2 == 3)
  460. coex_sta->wl_noisy_level = 2;
  461. else if (wl_noisy_count1 == 3)
  462. coex_sta->wl_noisy_level = 1;
  463. else
  464. coex_sta->wl_noisy_level = 0;
  465. }
  466. }
  467. static
  468. void halbtc8821c1ant_monitor_bt_enable(struct btc_coexist *btc)
  469. {
  470. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  471. static u32 bt_disable_cnt;
  472. boolean bt_active = TRUE, bt_disabled = FALSE;
  473. u16 u16tmp;
  474. /* Read BT on/off status from scoreboard[1],
  475. * enable this only if BT patch support this feature
  476. */
  477. halbtc8821c1ant_read_scbd(btc, &u16tmp);
  478. bt_active = u16tmp & BIT(1);
  479. if (bt_active) {
  480. bt_disable_cnt = 0;
  481. bt_disabled = FALSE;
  482. btc->btc_set(btc, BTC_SET_BL_BT_DISABLE, &bt_disabled);
  483. } else {
  484. bt_disable_cnt++;
  485. if (bt_disable_cnt >= 2) {
  486. bt_disabled = TRUE;
  487. bt_disable_cnt = 2;
  488. }
  489. btc->btc_set(btc, BTC_SET_BL_BT_DISABLE, &bt_disabled);
  490. }
  491. if (coex_sta->bt_disabled != bt_disabled) {
  492. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  493. "[BTCoex], BT is from %s to %s!!\n",
  494. (coex_sta->bt_disabled ? "disabled" : "enabled"),
  495. (bt_disabled ? "disabled" : "enabled"));
  496. BTC_TRACE(trace_buf);
  497. coex_sta->bt_disabled = bt_disabled;
  498. /*for win10 BT disable->enable trigger wifi scan issue */
  499. if (!coex_sta->bt_disabled) {
  500. coex_sta->is_bt_reenable = TRUE;
  501. coex_sta->cnt_bt_reenable = 15;
  502. } else {
  503. coex_sta->is_bt_reenable = FALSE;
  504. coex_sta->cnt_bt_reenable = 0;
  505. }
  506. }
  507. }
  508. static
  509. boolean halbtc8821c1ant_moniter_wifibt_status(struct btc_coexist *btc)
  510. {
  511. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  512. struct rfe_type_8821c_1ant *rfe_type = &btc->rfe_type_8821c_1ant;
  513. struct wifi_link_info_8821c_1ant *wifi_link_info_ext =
  514. &btc->wifi_link_info_8821c_1ant;
  515. static boolean pre_wifi_busy, pre_under_4way,
  516. pre_bt_off,
  517. pre_bt_slave, pre_hid_low_pri_tx_overhead,
  518. pre_wifi_under_lps, pre_bt_setup_link,
  519. pre_cck_lock, pre_cck_lock_warn;
  520. static u8 pre_hid_busy_num, pre_wl_noisy_level;
  521. boolean wifi_busy = FALSE, under_4way = FALSE;
  522. boolean wifi_connected = FALSE;
  523. struct btc_bt_link_info *bt_link_info = &btc->bt_link_info;
  524. static u8 cnt_wifi_busytoidle;
  525. u32 num_of_wifi_link = 0, wifi_link_mode = 0;
  526. static u32 pre_num_of_wifi_link, pre_wifi_link_mode;
  527. boolean miracast_plus_bt = FALSE;
  528. u8 lna_lvl = 1;
  529. btc->btc_get(btc, BTC_GET_BL_WIFI_CONNECTED, &wifi_connected);
  530. btc->btc_get(btc, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  531. btc->btc_get(btc, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &under_4way);
  532. if (wifi_busy) {
  533. coex_sta->gl_wifi_busy = TRUE;
  534. cnt_wifi_busytoidle = 6;
  535. } else {
  536. if (coex_sta->gl_wifi_busy && cnt_wifi_busytoidle > 0)
  537. cnt_wifi_busytoidle--;
  538. else if (cnt_wifi_busytoidle == 0)
  539. coex_sta->gl_wifi_busy = FALSE;
  540. }
  541. if (coex_sta->bt_disabled != pre_bt_off) {
  542. pre_bt_off = coex_sta->bt_disabled;
  543. if (coex_sta->bt_disabled)
  544. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  545. "[BTCoex], BT is disabled !!\n");
  546. else
  547. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  548. "[BTCoex], BT is enabled !!\n");
  549. BTC_TRACE(trace_buf);
  550. coex_sta->bt_coex_supported_feature = 0;
  551. coex_sta->bt_coex_supported_version = 0;
  552. coex_sta->bt_ble_scan_type = 0;
  553. coex_sta->bt_ble_scan_para[0] = 0;
  554. coex_sta->bt_ble_scan_para[1] = 0;
  555. coex_sta->bt_ble_scan_para[2] = 0;
  556. coex_sta->bt_reg_vendor_ac = 0xffff;
  557. coex_sta->bt_reg_vendor_ae = 0xffff;
  558. coex_sta->legacy_forbidden_slot = 0;
  559. coex_sta->le_forbidden_slot = 0;
  560. coex_sta->bt_a2dp_vendor_id = 0;
  561. coex_sta->bt_a2dp_device_name = 0;
  562. return TRUE;
  563. }
  564. num_of_wifi_link = wifi_link_info_ext->num_of_active_port;
  565. if (num_of_wifi_link != pre_num_of_wifi_link) {
  566. pre_num_of_wifi_link = num_of_wifi_link;
  567. if (wifi_link_info_ext->is_p2p_connected) {
  568. if (bt_link_info->bt_link_exist)
  569. miracast_plus_bt = TRUE;
  570. else
  571. miracast_plus_bt = FALSE;
  572. btc->btc_set(btc, BTC_SET_BL_MIRACAST_PLUS_BT,
  573. &miracast_plus_bt);
  574. }
  575. return TRUE;
  576. }
  577. wifi_link_mode = btc->wifi_link_info.link_mode;
  578. if (wifi_link_mode != pre_wifi_link_mode) {
  579. pre_wifi_link_mode = wifi_link_mode;
  580. return TRUE;
  581. }
  582. if (wifi_connected) {
  583. if (wifi_busy != pre_wifi_busy) {
  584. pre_wifi_busy = wifi_busy;
  585. return TRUE;
  586. }
  587. if (under_4way != pre_under_4way) {
  588. pre_under_4way = under_4way;
  589. return TRUE;
  590. }
  591. if (coex_sta->wl_noisy_level != pre_wl_noisy_level) {
  592. pre_wl_noisy_level = coex_sta->wl_noisy_level;
  593. return TRUE;
  594. }
  595. if (coex_sta->under_lps != pre_wifi_under_lps) {
  596. pre_wifi_under_lps = coex_sta->under_lps;
  597. if (coex_sta->under_lps)
  598. return TRUE;
  599. }
  600. if (coex_sta->cck_lock != pre_cck_lock) {
  601. pre_cck_lock = coex_sta->cck_lock;
  602. return TRUE;
  603. }
  604. if (coex_sta->cck_lock_warn != pre_cck_lock_warn) {
  605. pre_cck_lock_warn = coex_sta->cck_lock_warn;
  606. return TRUE;
  607. }
  608. }
  609. if (!coex_sta->bt_disabled) {
  610. #if 0
  611. if (coex_sta->acl_busy != pre_bt_acl_busy) {
  612. pre_bt_acl_busy = coex_sta->acl_busy;
  613. btc->btc_set(btc, BTC_SET_BL_BT_LNA_CONSTRAIN_LEVEL,
  614. &lna_lvl);
  615. return TRUE;
  616. }
  617. #endif
  618. if (coex_sta->hid_busy_num != pre_hid_busy_num) {
  619. pre_hid_busy_num = coex_sta->hid_busy_num;
  620. return TRUE;
  621. }
  622. if (bt_link_info->slave_role != pre_bt_slave) {
  623. pre_bt_slave = bt_link_info->slave_role;
  624. return TRUE;
  625. }
  626. if (pre_hid_low_pri_tx_overhead !=
  627. coex_sta->is_hid_low_pri_tx_overhead) {
  628. pre_hid_low_pri_tx_overhead =
  629. coex_sta->is_hid_low_pri_tx_overhead;
  630. return TRUE;
  631. }
  632. if (pre_bt_setup_link != coex_sta->is_setup_link) {
  633. pre_bt_setup_link = coex_sta->is_setup_link;
  634. return TRUE;
  635. }
  636. }
  637. return FALSE;
  638. }
  639. static
  640. void halbtc8821c1ant_update_wifi_link_info(struct btc_coexist *btc, u8 reason)
  641. {
  642. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  643. struct wifi_link_info_8821c_1ant *wifi_link_info_ext =
  644. &btc->wifi_link_info_8821c_1ant;
  645. struct btc_wifi_link_info wifi_link_info;
  646. u8 wifi_central_chnl = 0, num_of_wifi_link = 0;
  647. boolean isunder5G = FALSE, ismcc25g = FALSE, isp2pconnected = FALSE;
  648. u32 wifi_link_status = 0;
  649. btc->btc_get(btc, BTC_GET_U4_WIFI_LINK_STATUS, &wifi_link_status);
  650. wifi_link_info_ext->port_connect_status = wifi_link_status & 0xffff;
  651. btc->btc_get(btc, BTC_GET_BL_WIFI_LINK_INFO, &wifi_link_info);
  652. btc->wifi_link_info = wifi_link_info;
  653. btc->btc_get(btc, BTC_GET_U1_WIFI_CENTRAL_CHNL, &wifi_central_chnl);
  654. coex_sta->wl_center_channel = wifi_central_chnl;
  655. /* Check scan/connect/special-pkt action first */
  656. switch (reason) {
  657. case BT_8821C_1ANT_RSN_5GSCANSTART:
  658. case BT_8821C_1ANT_RSN_5GSWITCHBAND:
  659. case BT_8821C_1ANT_RSN_5GCONSTART:
  660. isunder5G = TRUE;
  661. break;
  662. case BT_8821C_1ANT_RSN_2GSCANSTART:
  663. case BT_8821C_1ANT_RSN_2GSWITCHBAND:
  664. case BT_8821C_1ANT_RSN_2GCONSTART:
  665. isunder5G = FALSE;
  666. break;
  667. case BT_8821C_1ANT_RSN_2GCONFINISH:
  668. case BT_8821C_1ANT_RSN_5GCONFINISH:
  669. case BT_8821C_1ANT_RSN_2GMEDIA:
  670. case BT_8821C_1ANT_RSN_5GMEDIA:
  671. case BT_8821C_1ANT_RSN_BTINFO:
  672. case BT_8821C_1ANT_RSN_PERIODICAL:
  673. case BT_8821C_1ANT_RSN_5GSPECIALPKT:
  674. case BT_8821C_1ANT_RSN_2GSPECIALPKT:
  675. default:
  676. switch (wifi_link_info.link_mode) {
  677. case BTC_LINK_5G_MCC_GO_STA:
  678. case BTC_LINK_5G_MCC_GC_STA:
  679. case BTC_LINK_5G_SCC_GO_STA:
  680. case BTC_LINK_5G_SCC_GC_STA:
  681. isunder5G = TRUE;
  682. break;
  683. case BTC_LINK_2G_MCC_GO_STA:
  684. case BTC_LINK_2G_MCC_GC_STA:
  685. case BTC_LINK_2G_SCC_GO_STA:
  686. case BTC_LINK_2G_SCC_GC_STA:
  687. isunder5G = FALSE;
  688. break;
  689. case BTC_LINK_25G_MCC_GO_STA:
  690. case BTC_LINK_25G_MCC_GC_STA:
  691. isunder5G = FALSE;
  692. ismcc25g = TRUE;
  693. break;
  694. case BTC_LINK_ONLY_STA:
  695. if (wifi_link_info.sta_center_channel > 14)
  696. isunder5G = TRUE;
  697. else
  698. isunder5G = FALSE;
  699. break;
  700. case BTC_LINK_ONLY_GO:
  701. case BTC_LINK_ONLY_GC:
  702. case BTC_LINK_ONLY_AP:
  703. default:
  704. if (wifi_link_info.p2p_center_channel > 14)
  705. isunder5G = TRUE;
  706. else
  707. isunder5G = FALSE;
  708. break;
  709. }
  710. break;
  711. }
  712. wifi_link_info_ext->is_all_under_5g = isunder5G;
  713. wifi_link_info_ext->is_mcc_25g = ismcc25g;
  714. if (wifi_link_status & WIFI_STA_CONNECTED)
  715. num_of_wifi_link++;
  716. if (wifi_link_status & WIFI_AP_CONNECTED)
  717. num_of_wifi_link++;
  718. if (wifi_link_status & WIFI_P2P_GO_CONNECTED) {
  719. num_of_wifi_link++;
  720. isp2pconnected = TRUE;
  721. }
  722. if (wifi_link_status & WIFI_P2P_GC_CONNECTED) {
  723. num_of_wifi_link++;
  724. isp2pconnected = TRUE;
  725. }
  726. wifi_link_info_ext->num_of_active_port = num_of_wifi_link;
  727. wifi_link_info_ext->is_p2p_connected = isp2pconnected;
  728. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  729. "[BTCoex], wifi_link_info: link_mode=%d, STA_Ch=%d, P2P_Ch=%d, AnyClient_Join_Go=%d !\n",
  730. btc->wifi_link_info.link_mode,
  731. btc->wifi_link_info.sta_center_channel,
  732. btc->wifi_link_info.p2p_center_channel,
  733. btc->wifi_link_info.bany_client_join_go);
  734. BTC_TRACE(trace_buf);
  735. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  736. "[BTCoex], wifi_link_info: center_ch=%d, is_all_under_5g=%d, is_mcc_25g=%d!\n",
  737. coex_sta->wl_center_channel,
  738. wifi_link_info_ext->is_all_under_5g,
  739. wifi_link_info_ext->is_mcc_25g);
  740. BTC_TRACE(trace_buf);
  741. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  742. "[BTCoex], wifi_link_info: port_connect_status=0x%x, active_port_cnt=%d, P2P_Connect=%d!\n",
  743. wifi_link_info_ext->port_connect_status,
  744. wifi_link_info_ext->num_of_active_port,
  745. wifi_link_info_ext->is_p2p_connected);
  746. BTC_TRACE(trace_buf);
  747. switch (reason) {
  748. case BT_8821C_1ANT_RSN_2GSCANSTART:
  749. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  750. "[BTCoex], Update reason = %s\n", "2GSCANSTART");
  751. break;
  752. case BT_8821C_1ANT_RSN_5GSCANSTART:
  753. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  754. "[BTCoex], Update reason = %s\n", "5GSCANSTART");
  755. break;
  756. case BT_8821C_1ANT_RSN_SCANFINISH:
  757. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  758. "[BTCoex], Update reason = %s\n", "SCANFINISH");
  759. break;
  760. case BT_8821C_1ANT_RSN_2GSWITCHBAND:
  761. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  762. "[BTCoex], Update reason = %s\n", "2GSWITCHBAND");
  763. break;
  764. case BT_8821C_1ANT_RSN_5GSWITCHBAND:
  765. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  766. "[BTCoex], Update reason = %s\n", "5GSWITCHBAND");
  767. break;
  768. case BT_8821C_1ANT_RSN_2GCONSTART:
  769. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  770. "[BTCoex], Update reason = %s\n", "2GCONNECTSTART");
  771. break;
  772. case BT_8821C_1ANT_RSN_5GCONSTART:
  773. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  774. "[BTCoex], Update reason = %s\n", "5GCONNECTSTART");
  775. break;
  776. case BT_8821C_1ANT_RSN_2GCONFINISH:
  777. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  778. "[BTCoex], Update reason = %s\n",
  779. "2GCONNECTFINISH");
  780. break;
  781. case BT_8821C_1ANT_RSN_5GCONFINISH:
  782. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  783. "[BTCoex], Update reason = %s\n",
  784. "5GCONNECTFINISH");
  785. break;
  786. case BT_8821C_1ANT_RSN_2GMEDIA:
  787. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  788. "[BTCoex], Update reason = %s\n", "2GMEDIASTATUS");
  789. break;
  790. case BT_8821C_1ANT_RSN_5GMEDIA:
  791. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  792. "[BTCoex], Update reason = %s\n", "5GMEDIASTATUS");
  793. break;
  794. case BT_8821C_1ANT_RSN_MEDIADISCON:
  795. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  796. "[BTCoex], Update reason = %s\n",
  797. "MEDIADISCONNECT");
  798. break;
  799. case BT_8821C_1ANT_RSN_2GSPECIALPKT:
  800. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  801. "[BTCoex], Update reason = %s\n", "2GSPECIALPKT");
  802. break;
  803. case BT_8821C_1ANT_RSN_5GSPECIALPKT:
  804. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  805. "[BTCoex], Update reason = %s\n", "5GSPECIALPKT");
  806. break;
  807. case BT_8821C_1ANT_RSN_BTINFO:
  808. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  809. "[BTCoex], Update reason = %s\n", "BTINFO");
  810. break;
  811. case BT_8821C_1ANT_RSN_PERIODICAL:
  812. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  813. "[BTCoex], Update reason = %s\n", "PERIODICAL");
  814. break;
  815. case BT_8821C_1ANT_RSN_PNP:
  816. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  817. "[BTCoex], Update reason = %s\n", "PNPNotify");
  818. break;
  819. default:
  820. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  821. "[BTCoex], Update reason = %s\n", "UNKNOWN");
  822. break;
  823. }
  824. BTC_TRACE(trace_buf);
  825. if (wifi_link_info_ext->is_all_under_5g ||
  826. coex_sta->num_of_profile == 0)
  827. halbtc8821c1ant_low_penalty_ra(btc, NM_EXCU, FALSE, 0);
  828. else if (wifi_link_info_ext->is_p2p_connected)
  829. halbtc8821c1ant_low_penalty_ra(btc, NM_EXCU, TRUE, 30);
  830. else
  831. halbtc8821c1ant_low_penalty_ra(btc, NM_EXCU, TRUE, 15);
  832. }
  833. static
  834. void halbtc8821c1ant_update_bt_link_info(struct btc_coexist *btc)
  835. {
  836. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  837. struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
  838. struct btc_bt_link_info *bt_link_info = &btc->bt_link_info;
  839. boolean bt_busy = FALSE, increase_scan_dev_num = FALSE;
  840. u32 val = 0;
  841. static u8 pre_num_of_profile, cur_num_of_profile, cnt, ble_cnt;
  842. if (++ble_cnt >= 3)
  843. ble_cnt = 0;
  844. if (coex_sta->is_ble_scan_en && ble_cnt == 0) {
  845. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  846. "[BTCoex], BT ext info bit4 check, query BLE Scan type!!\n");
  847. BTC_TRACE(trace_buf);
  848. coex_sta->bt_ble_scan_type =
  849. btc->btc_get_ble_scan_type_from_bt(btc);
  850. if ((coex_sta->bt_ble_scan_type & 0x1) == 0x1)
  851. coex_sta->bt_ble_scan_para[0] =
  852. btc->btc_get_ble_scan_para_from_bt(btc, 0x1);
  853. if ((coex_sta->bt_ble_scan_type & 0x2) == 0x2)
  854. coex_sta->bt_ble_scan_para[1] =
  855. btc->btc_get_ble_scan_para_from_bt(btc, 0x2);
  856. if ((coex_sta->bt_ble_scan_type & 0x4) == 0x4)
  857. coex_sta->bt_ble_scan_para[2] =
  858. btc->btc_get_ble_scan_para_from_bt(btc, 0x4);
  859. }
  860. coex_sta->num_of_profile = 0;
  861. /* set link exist status */
  862. if (!(coex_sta->bt_info & BT_INFO_8821C_1ANT_B_CONNECTION)) {
  863. coex_sta->bt_link_exist = FALSE;
  864. coex_sta->pan_exist = FALSE;
  865. coex_sta->a2dp_exist = FALSE;
  866. coex_sta->hid_exist = FALSE;
  867. coex_sta->sco_exist = FALSE;
  868. coex_sta->msft_mr_exist = FALSE;
  869. } else { /* connection exists */
  870. coex_sta->bt_link_exist = TRUE;
  871. if (coex_sta->bt_info & BT_INFO_8821C_1ANT_B_FTP) {
  872. coex_sta->pan_exist = TRUE;
  873. coex_sta->num_of_profile++;
  874. } else
  875. coex_sta->pan_exist = FALSE;
  876. if (coex_sta->bt_info & BT_INFO_8821C_1ANT_B_A2DP) {
  877. coex_sta->a2dp_exist = TRUE;
  878. coex_sta->num_of_profile++;
  879. } else
  880. coex_sta->a2dp_exist = FALSE;
  881. if (coex_sta->bt_info & BT_INFO_8821C_1ANT_B_HID) {
  882. coex_sta->hid_exist = TRUE;
  883. coex_sta->num_of_profile++;
  884. } else
  885. coex_sta->hid_exist = FALSE;
  886. if (coex_sta->bt_info & BT_INFO_8821C_1ANT_B_SCO_ESCO) {
  887. coex_sta->sco_exist = TRUE;
  888. coex_sta->num_of_profile++;
  889. } else
  890. coex_sta->sco_exist = FALSE;
  891. if (coex_sta->hid_busy_num == 0 &&
  892. coex_sta->hid_pair_cnt > 0 &&
  893. coex_sta->low_priority_tx > 1000 &&
  894. coex_sta->low_priority_rx > 1000 &&
  895. !coex_sta->c2h_bt_inquiry_page)
  896. coex_sta->msft_mr_exist = true;
  897. else
  898. coex_sta->msft_mr_exist = false;
  899. }
  900. bt_link_info->bt_link_exist = coex_sta->bt_link_exist;
  901. bt_link_info->sco_exist = coex_sta->sco_exist;
  902. bt_link_info->a2dp_exist = coex_sta->a2dp_exist;
  903. bt_link_info->pan_exist = coex_sta->pan_exist;
  904. bt_link_info->hid_exist = coex_sta->hid_exist;
  905. bt_link_info->acl_busy = coex_sta->acl_busy;
  906. /* check if Sco only */
  907. if (bt_link_info->sco_exist &&
  908. !bt_link_info->a2dp_exist &&
  909. !bt_link_info->pan_exist &&
  910. !bt_link_info->hid_exist)
  911. bt_link_info->sco_only = TRUE;
  912. else
  913. bt_link_info->sco_only = FALSE;
  914. /* check if A2dp only */
  915. if (!bt_link_info->sco_exist &&
  916. bt_link_info->a2dp_exist &&
  917. !bt_link_info->pan_exist &&
  918. !bt_link_info->hid_exist)
  919. bt_link_info->a2dp_only = TRUE;
  920. else
  921. bt_link_info->a2dp_only = FALSE;
  922. /* check if Pan only */
  923. if (!bt_link_info->sco_exist &&
  924. !bt_link_info->a2dp_exist &&
  925. bt_link_info->pan_exist &&
  926. !bt_link_info->hid_exist)
  927. bt_link_info->pan_only = TRUE;
  928. else
  929. bt_link_info->pan_only = FALSE;
  930. /* check if Hid only */
  931. if (!bt_link_info->sco_exist &&
  932. !bt_link_info->a2dp_exist &&
  933. !bt_link_info->pan_exist &&
  934. bt_link_info->hid_exist)
  935. bt_link_info->hid_only = TRUE;
  936. else
  937. bt_link_info->hid_only = FALSE;
  938. if (coex_sta->bt_info & BT_INFO_8821C_1ANT_B_INQ_PAGE) {
  939. coex_dm->bt_status = BT_8821C_1ANT_BSTATUS_INQ_PAGE;
  940. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  941. "[BTCoex], BtInfoNotify(), BT Inq/page!!!\n");
  942. } else if (!(coex_sta->bt_info & BT_INFO_8821C_1ANT_B_CONNECTION)) {
  943. coex_dm->bt_status = BT_8821C_1ANT_BSTATUS_NCON_IDLE;
  944. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  945. "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n");
  946. } else if (coex_sta->bt_info == BT_INFO_8821C_1ANT_B_CONNECTION) {
  947. /* connection exists but no busy */
  948. if (coex_sta->msft_mr_exist) {
  949. coex_dm->bt_status = BT_8821C_1ANT_BSTATUS_ACL_BUSY;
  950. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  951. "[BTCoex], BtInfoNotify(), BT ACL busy!!\n");
  952. } else {
  953. coex_dm->bt_status = BT_8821C_1ANT_BSTATUS_CON_IDLE;
  954. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  955. "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
  956. }
  957. } else if (((coex_sta->bt_info & BT_INFO_8821C_1ANT_B_SCO_ESCO) ||
  958. (coex_sta->bt_info & BT_INFO_8821C_1ANT_B_SCO_BUSY)) &&
  959. (coex_sta->bt_info & BT_INFO_8821C_1ANT_B_ACL_BUSY)) {
  960. coex_dm->bt_status = BT_8821C_1ANT_BSTATUS_ACL_SCO_BUSY;
  961. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  962. "[BTCoex], BtInfoNotify(), BT ACL SCO busy!!!\n");
  963. } else if ((coex_sta->bt_info & BT_INFO_8821C_1ANT_B_SCO_ESCO) ||
  964. (coex_sta->bt_info & BT_INFO_8821C_1ANT_B_SCO_BUSY)) {
  965. coex_dm->bt_status = BT_8821C_1ANT_BSTATUS_SCO_BUSY;
  966. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  967. "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
  968. } else if (coex_sta->bt_info & BT_INFO_8821C_1ANT_B_ACL_BUSY) {
  969. coex_dm->bt_status = BT_8821C_1ANT_BSTATUS_ACL_BUSY;
  970. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  971. "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
  972. } else {
  973. coex_dm->bt_status = BT_8821C_1ANT_BSTATUS_MAX;
  974. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  975. "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n");
  976. }
  977. BTC_TRACE(trace_buf);
  978. if (coex_dm->bt_status == BT_8821C_1ANT_BSTATUS_ACL_BUSY ||
  979. coex_dm->bt_status == BT_8821C_1ANT_BSTATUS_SCO_BUSY ||
  980. coex_dm->bt_status == BT_8821C_1ANT_BSTATUS_ACL_SCO_BUSY) {
  981. bt_busy = TRUE;
  982. increase_scan_dev_num = TRUE;
  983. } else {
  984. bt_busy = FALSE;
  985. increase_scan_dev_num = FALSE;
  986. }
  987. btc->btc_set(btc, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
  988. btc->btc_set(btc, BTC_SET_BL_INC_SCAN_DEV_NUM, &increase_scan_dev_num);
  989. cur_num_of_profile = coex_sta->num_of_profile;
  990. if (cur_num_of_profile != pre_num_of_profile)
  991. cnt = 2;
  992. if (bt_link_info->a2dp_exist && (cnt > 0)) {
  993. cnt--;
  994. if (coex_sta->bt_a2dp_vendor_id == 0 &&
  995. coex_sta->bt_a2dp_device_name == 0) {
  996. btc->btc_get(btc, BTC_GET_U4_BT_DEVICE_INFO, &val);
  997. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  998. "[BTCoex], BtInfoNotify(), get BT DEVICE_INFO = %x\n",
  999. val);
  1000. BTC_TRACE(trace_buf);
  1001. coex_sta->bt_a2dp_vendor_id = (u8)(val & 0xff);
  1002. coex_sta->bt_a2dp_device_name = (val & 0xffffff00) >> 8;
  1003. }
  1004. if (coex_sta->legacy_forbidden_slot == 0 &&
  1005. coex_sta->le_forbidden_slot == 0) {
  1006. btc->btc_get(btc, BTC_GET_U4_BT_FORBIDDEN_SLOT_VAL,
  1007. &val);
  1008. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1009. "[BTCoex], BtInfoNotify(), get BT FORBIDDEN_SLOT_VAL = %x\n",
  1010. val);
  1011. BTC_TRACE(trace_buf);
  1012. coex_sta->legacy_forbidden_slot = (u16)(val & 0xffff);
  1013. coex_sta->le_forbidden_slot =
  1014. (u16)((val & 0xffff0000) >> 16);
  1015. }
  1016. }
  1017. pre_num_of_profile = coex_sta->num_of_profile;
  1018. }
  1019. static
  1020. void halbtc8821c1ant_update_wifi_ch_info(struct btc_coexist *btc, u8 type)
  1021. {
  1022. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  1023. struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
  1024. struct wifi_link_info_8821c_1ant *wifi_link_info_ext =
  1025. &btc->wifi_link_info_8821c_1ant;
  1026. u8 h2c_parameter[3] = {0}, i;
  1027. u32 wifi_bw;
  1028. u8 wifi_central_chnl = 0;
  1029. u8 wifi_5g_chnl[19] = {120, 124, 128, 132, 136, 140, 144, 149, 153, 157,
  1030. 118, 126, 134, 142, 151, 159, 122, 138, 155};
  1031. u8 bt_skip_cneter_chanl[19] = {2, 8, 17, 26, 34, 42, 51, 62, 71, 77, 2,
  1032. 12, 29, 46, 66, 76, 10, 37, 68};
  1033. u8 bt_skip_span[19] = {4, 8, 8, 10, 8, 10, 8, 8, 10, 4, 4, 16, 16, 16,
  1034. 16, 4, 20, 34, 20};
  1035. boolean is_any_connected = FALSE;
  1036. if (btc->manual_control)
  1037. return;
  1038. btc->btc_get(btc, BTC_GET_U4_WIFI_BW, &wifi_bw);
  1039. if (btc->stop_coex_dm || coex_sta->is_rf_state_off) {
  1040. is_any_connected = FALSE;
  1041. wifi_central_chnl = 0;
  1042. } else if (type != BTC_MEDIA_DISCONNECT ||
  1043. (type == BTC_MEDIA_DISCONNECT &&
  1044. wifi_link_info_ext->num_of_active_port > 0)) {
  1045. if (wifi_link_info_ext->num_of_active_port == 1) {
  1046. if (wifi_link_info_ext->is_p2p_connected)
  1047. wifi_central_chnl =
  1048. btc->wifi_link_info
  1049. .p2p_center_channel;
  1050. else
  1051. wifi_central_chnl =
  1052. btc->wifi_link_info
  1053. .sta_center_channel;
  1054. } else { /* port > 2 */
  1055. if ((btc->wifi_link_info
  1056. .p2p_center_channel > 14) &&
  1057. (btc->wifi_link_info
  1058. .sta_center_channel > 14))
  1059. wifi_central_chnl =
  1060. btc->wifi_link_info
  1061. .p2p_center_channel;
  1062. else if (btc->wifi_link_info
  1063. .p2p_center_channel <= 14)
  1064. wifi_central_chnl =
  1065. btc->wifi_link_info
  1066. .p2p_center_channel;
  1067. else if (btc->wifi_link_info
  1068. .sta_center_channel <= 14)
  1069. wifi_central_chnl =
  1070. btc->wifi_link_info
  1071. .sta_center_channel;
  1072. }
  1073. }
  1074. if (wifi_central_chnl > 0)
  1075. is_any_connected = TRUE;
  1076. if (is_any_connected) {
  1077. if (wifi_central_chnl <= 14) {
  1078. h2c_parameter[0] = 0x1;
  1079. h2c_parameter[1] = wifi_central_chnl;
  1080. if (wifi_bw == BTC_WIFI_BW_HT40)
  1081. h2c_parameter[2] = 0x36;
  1082. else
  1083. h2c_parameter[2] = 0x24;
  1084. } else { /* for 5G */
  1085. for (i = 0; i <= 18; i++) {
  1086. if (wifi_central_chnl == wifi_5g_chnl[i])
  1087. break;
  1088. }
  1089. if (i <= 18) {
  1090. h2c_parameter[0] = 0x3;
  1091. h2c_parameter[1] = bt_skip_cneter_chanl[i];
  1092. h2c_parameter[2] = bt_skip_span[i];
  1093. }
  1094. }
  1095. }
  1096. coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
  1097. coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
  1098. coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
  1099. btc->btc_fill_h2c(btc, 0x66, 3, h2c_parameter);
  1100. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1101. "[BTCoex], para[0:2] = 0x%x 0x%x 0x%x\n",
  1102. h2c_parameter[0], h2c_parameter[1], h2c_parameter[2]);
  1103. BTC_TRACE(trace_buf);
  1104. }
  1105. static
  1106. u32 halbtc8821c1ant_read_indirect_reg(struct btc_coexist *btc, u16 reg_addr)
  1107. {
  1108. u32 j = 0, delay_count = 0;
  1109. /* wait for ready bit before access 0x1700 */
  1110. while (1) {
  1111. if ((btc->btc_read_1byte(btc, 0x1703) & BIT(5)) == 0) {
  1112. delay_ms(10);
  1113. delay_count++;
  1114. if (delay_count >= 10) {
  1115. delay_count = 0;
  1116. break;
  1117. }
  1118. } else
  1119. break;
  1120. }
  1121. btc->btc_write_4byte(btc, 0x1700, 0x800F0000 | reg_addr);
  1122. return btc->btc_read_4byte(btc,
  1123. 0x1708); /* get read data */
  1124. }
  1125. static
  1126. void halbtc8821c1ant_write_indirect_reg(struct btc_coexist *btc, u16 reg_addr,
  1127. u32 bit_mask, u32 reg_value)
  1128. {
  1129. u32 val, i = 0, j = 0, bitpos = 0, delay_count = 0;
  1130. if (bit_mask == 0x0)
  1131. return;
  1132. if (bit_mask == 0xffffffff) {
  1133. /* wait for ready bit before access 0x1700/0x1704 */
  1134. while (1) {
  1135. if ((btc->btc_read_1byte(btc, 0x1703) & BIT(5)) == 0) {
  1136. delay_ms(10);
  1137. delay_count++;
  1138. if (delay_count >= 10) {
  1139. delay_count = 0;
  1140. break;
  1141. }
  1142. } else
  1143. break;
  1144. }
  1145. /* put write data */
  1146. btc->btc_write_4byte(btc, 0x1704, reg_value);
  1147. btc->btc_write_4byte(btc, 0x1700, 0xc00F0000 | reg_addr);
  1148. } else {
  1149. for (i = 0; i <= 31; i++) {
  1150. if (((bit_mask >> i) & 0x1) == 0x1) {
  1151. bitpos = i;
  1152. break;
  1153. }
  1154. }
  1155. /* read back register value before write */
  1156. val = halbtc8821c1ant_read_indirect_reg(btc, reg_addr);
  1157. val = (val & (~bit_mask)) | (reg_value << bitpos);
  1158. /* wait for ready bit before access 0x1700/0x1704 */
  1159. while (1) {
  1160. if ((btc->btc_read_1byte(btc, 0x1703) & BIT(5)) == 0) {
  1161. delay_ms(10);
  1162. delay_count++;
  1163. if (delay_count >= 10) {
  1164. delay_count = 0;
  1165. break;
  1166. }
  1167. } else
  1168. break;
  1169. }
  1170. /* put write data */
  1171. btc->btc_write_4byte(btc, 0x1704, val);
  1172. btc->btc_write_4byte(btc, 0x1700, 0xc00F0000 | reg_addr);
  1173. }
  1174. }
  1175. static
  1176. void halbtc8821c1ant_ltecoex_enable(struct btc_coexist *btc, boolean enable)
  1177. {
  1178. u8 val;
  1179. /* 0x38[7] */
  1180. val = (enable) ? 1 : 0;
  1181. halbtc8821c1ant_write_indirect_reg(btc, 0x38, 0x80, val);
  1182. }
  1183. static
  1184. void halbtc8821c1ant_ltecoex_table(struct btc_coexist *btc, u8 table_type,
  1185. u16 table_content)
  1186. {
  1187. u16 reg_addr = 0x0000;
  1188. switch (table_type) {
  1189. case BT_8821C_1ANT_CTT_WL_VS_LTE:
  1190. reg_addr = 0xa0;
  1191. break;
  1192. case BT_8821C_1ANT_CTT_BT_VS_LTE:
  1193. reg_addr = 0xa4;
  1194. break;
  1195. }
  1196. /* 0xa0[15:0] or 0xa4[15:0] */
  1197. if (reg_addr != 0x0000)
  1198. halbtc8821c1ant_write_indirect_reg(btc, reg_addr, 0xffff,
  1199. table_content);
  1200. }
  1201. static
  1202. void halbtc8821c1ant_coex_ctrl_owner(struct btc_coexist *btc,
  1203. boolean wifi_control)
  1204. {
  1205. u8 val;
  1206. /* 0x70[26] */
  1207. val = (wifi_control) ? 1 : 0;
  1208. btc->btc_write_1byte_bitmask(btc, 0x73, 0x4, val);
  1209. }
  1210. static
  1211. void halbtc8821c1ant_set_gnt_bt(struct btc_coexist *btc, u8 control_block,
  1212. boolean sw_control, u8 state)
  1213. {
  1214. u32 val = 0, val_orig = 0;
  1215. if (!sw_control)
  1216. val = 0x0;
  1217. else if (state & 0x1)
  1218. val = 0x3;
  1219. else
  1220. val = 0x1;
  1221. val_orig = halbtc8821c1ant_read_indirect_reg(btc, 0x38);
  1222. switch (control_block) {
  1223. case BT_8821C_1ANT_GNT_BLOCK_RFC_BB:
  1224. default:
  1225. val = ((val << 14) | (val << 10)) | (val_orig & 0xffff33ff);
  1226. break;
  1227. case BT_8821C_1ANT_GNT_BLOCK_RFC:
  1228. val = (val << 14) | (val_orig & 0xffff3fff);
  1229. break;
  1230. case BT_8821C_1ANT_GNT_BLOCK_BB:
  1231. val = (val << 10) | (val_orig & 0xfffff3ff);
  1232. break;
  1233. }
  1234. halbtc8821c1ant_write_indirect_reg(btc, 0x38, 0xffffffff, val);
  1235. }
  1236. static
  1237. void halbtc8821c1ant_set_gnt_wl(struct btc_coexist *btc, u8 control_block,
  1238. boolean sw_control, u8 state)
  1239. {
  1240. u32 val = 0, val_orig = 0;
  1241. if (!sw_control)
  1242. val = 0x0;
  1243. else if (state & 0x1)
  1244. val = 0x3;
  1245. else
  1246. val = 0x1;
  1247. val_orig = halbtc8821c1ant_read_indirect_reg(btc, 0x38);
  1248. switch (control_block) {
  1249. case BT_8821C_1ANT_GNT_BLOCK_RFC_BB:
  1250. default:
  1251. val = ((val << 12) | (val << 8)) | (val_orig & 0xffffccff);
  1252. break;
  1253. case BT_8821C_1ANT_GNT_BLOCK_RFC:
  1254. val = (val << 12) | (val_orig & 0xffffcfff);
  1255. break;
  1256. case BT_8821C_1ANT_GNT_BLOCK_BB:
  1257. val = (val << 8) | (val_orig & 0xfffffcff);
  1258. break;
  1259. }
  1260. halbtc8821c1ant_write_indirect_reg(btc, 0x38, 0xffffffff, val);
  1261. }
  1262. #if 0
  1263. static
  1264. void halbtc8821c1ant_ltecoex_set_break_table(struct btc_coexist *btc,
  1265. u8 table_type, u8 table_content)
  1266. {
  1267. u16 reg_addr = 0x0000;
  1268. switch (table_type) {
  1269. case BT_8821C_1ANT_LBTT_WL_BREAK_LTE:
  1270. reg_addr = 0xa8;
  1271. break;
  1272. case BT_8821C_1ANT_LBTT_BT_BREAK_LTE:
  1273. reg_addr = 0xac;
  1274. break;
  1275. case BT_8821C_1ANT_LBTT_LTE_BREAK_WL:
  1276. reg_addr = 0xb0;
  1277. break;
  1278. case BT_8821C_1ANT_LBTT_LTE_BREAK_BT:
  1279. reg_addr = 0xb4;
  1280. break;
  1281. }
  1282. /* 0xa8[15:0] or 0xb4[15:0] */
  1283. if (reg_addr != 0x0000)
  1284. halbtc8821c1ant_write_indirect_reg(btc, reg_addr, 0xff,
  1285. table_content);
  1286. }
  1287. #endif
  1288. #if 0
  1289. static
  1290. void halbtc8821c1ant_set_wltoggle_coex_table(struct btc_coexist *btc,
  1291. boolean force_exec, u8 interval,
  1292. u8 val0x6c4_b0, u8 val0x6c4_b1,
  1293. u8 val0x6c4_b2, u8 val0x6c4_b3)
  1294. {
  1295. static u8 pre_h2c_parameter[6] = {0};
  1296. u8 cur_h2c_parameter[6] = {0};
  1297. u8 i, match_cnt = 0;
  1298. cur_h2c_parameter[0] = 0x7; /* op_code, 0x7= wlan toggle slot*/
  1299. cur_h2c_parameter[1] = interval;
  1300. cur_h2c_parameter[2] = val0x6c4_b0;
  1301. cur_h2c_parameter[3] = val0x6c4_b1;
  1302. cur_h2c_parameter[4] = val0x6c4_b2;
  1303. cur_h2c_parameter[5] = val0x6c4_b3;
  1304. if (!force_exec) {
  1305. for (i = 1; i <= 5; i++) {
  1306. if (cur_h2c_parameter[i] != pre_h2c_parameter[i])
  1307. break;
  1308. match_cnt++;
  1309. }
  1310. if (match_cnt == 5)
  1311. return;
  1312. }
  1313. for (i = 1; i <= 5; i++)
  1314. pre_h2c_parameter[i] = cur_h2c_parameter[i];
  1315. btc->btc_fill_h2c(btc, 0x69, 6, cur_h2c_parameter);
  1316. }
  1317. #endif
  1318. static
  1319. void halbtc8821c1ant_set_table(struct btc_coexist *btc, boolean force_exec,
  1320. u32 val0x6c0, u32 val0x6c4, u32 val0x6c8,
  1321. u8 val0x6cc)
  1322. {
  1323. struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
  1324. if (!force_exec) {
  1325. if (val0x6c0 == coex_dm->cur_val0x6c0 &&
  1326. val0x6c4 == coex_dm->cur_val0x6c4 &&
  1327. val0x6c8 == coex_dm->cur_val0x6c8 &&
  1328. val0x6cc == coex_dm->cur_val0x6cc)
  1329. return;
  1330. }
  1331. btc->btc_write_4byte(btc, 0x6c0, val0x6c0);
  1332. btc->btc_write_4byte(btc, 0x6c4, val0x6c4);
  1333. btc->btc_write_4byte(btc, 0x6c8, val0x6c8);
  1334. btc->btc_write_1byte(btc, 0x6cc, val0x6cc);
  1335. coex_dm->cur_val0x6c0 = val0x6c0;
  1336. coex_dm->cur_val0x6c4 = val0x6c4;
  1337. coex_dm->cur_val0x6c8 = val0x6c8;
  1338. coex_dm->cur_val0x6cc = val0x6cc;
  1339. }
  1340. static
  1341. void halbtc8821c1ant_table(struct btc_coexist *btc, boolean force_exec, u8 type)
  1342. {
  1343. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  1344. u32 break_table;
  1345. u8 select_table;
  1346. coex_sta->coex_table_type = type;
  1347. if (coex_sta->concurrent_rx_mode_on == TRUE) {
  1348. /* set WL hi-pri can break BT */
  1349. break_table = 0xf0ffffff;
  1350. /* set Tx response = Hi-Pri (ex: Transmitting ACK,BA,CTS) */
  1351. select_table = 0x1b;
  1352. } else {
  1353. break_table = 0xffffff;
  1354. select_table = 0x13;
  1355. }
  1356. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1357. "[BTCoex], ********** Table-%d **********\n",
  1358. coex_sta->coex_table_type);
  1359. BTC_TRACE(trace_buf);
  1360. switch (type) {
  1361. case 0:
  1362. halbtc8821c1ant_set_table(btc, force_exec, 0x65555555,
  1363. 0x65555555, break_table,
  1364. select_table);
  1365. break;
  1366. case 1:
  1367. halbtc8821c1ant_set_table(btc, force_exec, 0x65555555,
  1368. 0x5a5a5a5a, break_table,
  1369. select_table);
  1370. break;
  1371. case 2:
  1372. halbtc8821c1ant_set_table(btc, force_exec, 0x65555555,
  1373. 0xaaaaaaaa, break_table,
  1374. select_table);
  1375. break;
  1376. case 3: /* not use */
  1377. halbtc8821c1ant_set_table(btc, force_exec, 0x65555555,
  1378. 0x5a5a5a5a, break_table,
  1379. select_table);
  1380. break;
  1381. case 4:
  1382. halbtc8821c1ant_set_table(btc, force_exec, 0x65555555,
  1383. 0x5a5a5a5a, break_table,
  1384. select_table);
  1385. break;
  1386. case 5:
  1387. halbtc8821c1ant_set_table(btc, force_exec, 0x6a5a5a5a,
  1388. 0x5a5a5a5a, break_table,
  1389. select_table);
  1390. break;
  1391. case 6: /* not use */
  1392. halbtc8821c1ant_set_table(btc, force_exec, 0x65555555,
  1393. 0x5a5a5a5a, break_table,
  1394. select_table);
  1395. break;
  1396. case 7:
  1397. halbtc8821c1ant_set_table(btc, force_exec, 0x65555555,
  1398. 0xaaaa5aaa, break_table,
  1399. select_table);
  1400. break;
  1401. case 8:
  1402. halbtc8821c1ant_set_table(btc, force_exec, 0x65555555,
  1403. 0x6aaa6aaa, break_table,
  1404. select_table);
  1405. break;
  1406. case 9:
  1407. halbtc8821c1ant_set_table(btc, force_exec, 0x65555555,
  1408. 0xaaaaaaaa, break_table,
  1409. select_table);
  1410. break;
  1411. case 10:
  1412. halbtc8821c1ant_set_table(btc, force_exec, 0xaa5555aa,
  1413. 0xaaaaaaaa, break_table,
  1414. select_table);
  1415. break;
  1416. case 11:
  1417. halbtc8821c1ant_set_table(btc, force_exec, 0x65a55555,
  1418. 0x5aaa5a5a, break_table,
  1419. select_table);
  1420. break;
  1421. case 12:
  1422. halbtc8821c1ant_set_table(btc, force_exec, 0x65555555,
  1423. 0x5aaa5a5a, break_table,
  1424. select_table);
  1425. break;
  1426. case 13:
  1427. halbtc8821c1ant_set_table(btc, force_exec, 0xaa5555aa,
  1428. 0x5a5a5a5a, break_table,
  1429. select_table);
  1430. break;
  1431. case 14:
  1432. halbtc8821c1ant_set_table(btc, force_exec, 0xaa5555aa,
  1433. 0x5a5a5a5a, break_table,
  1434. select_table);
  1435. break;
  1436. case 15:
  1437. halbtc8821c1ant_set_table(btc, force_exec, 0xffffffff,
  1438. 0x5a5a5a5a, break_table,
  1439. select_table);
  1440. break;
  1441. default:
  1442. break;
  1443. }
  1444. }
  1445. static
  1446. void halbtc8821c1ant_ignore_wlan_act(struct btc_coexist *btc,
  1447. boolean force_exec, boolean enable)
  1448. {
  1449. struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
  1450. u8 h2c_parameter[1] = {0};
  1451. if (btc->manual_control || btc->stop_coex_dm)
  1452. return;
  1453. if (!force_exec) {
  1454. if (enable == coex_dm->cur_ignore_wlan_act)
  1455. return;
  1456. }
  1457. if (enable)
  1458. h2c_parameter[0] |= BIT(0); /* function enable */
  1459. btc->btc_fill_h2c(btc, 0x63, 1, h2c_parameter);
  1460. coex_dm->cur_ignore_wlan_act = enable;
  1461. }
  1462. static
  1463. void halbtc8821c1ant_lps_rpwm(struct btc_coexist *btc, boolean force_exec,
  1464. u8 lps_val, u8 rpwm_val)
  1465. {
  1466. struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
  1467. if (!force_exec) {
  1468. if (lps_val == coex_dm->cur_lps &&
  1469. rpwm_val == coex_dm->cur_rpwm)
  1470. return;
  1471. }
  1472. btc->btc_set(btc, BTC_SET_U1_LPS_VAL, &lps_val);
  1473. btc->btc_set(btc, BTC_SET_U1_RPWM_VAL, &rpwm_val);
  1474. coex_dm->cur_lps = lps_val;
  1475. coex_dm->cur_rpwm = rpwm_val;
  1476. }
  1477. static
  1478. void halbtc8821c1ant_multiport_tdma(struct btc_coexist *btc, u8 multi_port_mode)
  1479. {
  1480. #if 0
  1481. struct btc_multi_port_tdma_info multiport_tdma_para;
  1482. static u8 pre_state = BTC_MULTI_PORT_TDMA_MODE_NONE;
  1483. if (multi_port_mode == pre_state)
  1484. return;
  1485. multiport_tdma_para.btc_multi_port_tdma_mode = multi_port_mode;
  1486. switch (multi_port_mode) {
  1487. case BTC_MULTI_PORT_TDMA_MODE_NONE:
  1488. multiport_tdma_para.start_time_from_bcn = 0;
  1489. multiport_tdma_para.bt_time = 0;
  1490. break;
  1491. case BTC_MULTI_PORT_TDMA_MODE_2G_SCC_GO:
  1492. multiport_tdma_para.start_time_from_bcn = 65;
  1493. multiport_tdma_para.bt_time = 35;
  1494. break;
  1495. case BTC_MULTI_PORT_TDMA_MODE_2G_P2P_GO:
  1496. multiport_tdma_para.start_time_from_bcn = 55;
  1497. multiport_tdma_para.bt_time = 45;
  1498. break;
  1499. }
  1500. btc->btc_set(btc, BTC_SET_WIFI_BT_COEX_MODE, &multiport_tdma_para);
  1501. pre_state = multi_port_mode;
  1502. #endif
  1503. }
  1504. static
  1505. void halbtc8821c1ant_tdma_check(struct btc_coexist *btc, boolean new_ps_state)
  1506. {
  1507. u8 lps_mode = 0x0;
  1508. u8 h2c_parameter[5] = {0x8, 0, 0, 0, 0};
  1509. btc->btc_get(btc, BTC_GET_U1_LPS_MODE, &lps_mode);
  1510. if (lps_mode) { /* already under LPS state */
  1511. if (new_ps_state) {
  1512. /* keep state under LPS, do nothing. */
  1513. } else {
  1514. /* will leave LPS state, turn off psTdma first */
  1515. btc->btc_fill_h2c(btc, 0x60, 5, h2c_parameter);
  1516. }
  1517. } else { /* NO PS state */
  1518. if (new_ps_state) {
  1519. /* will enter LPS state, turn off psTdma first */
  1520. btc->btc_fill_h2c(btc, 0x60, 5, h2c_parameter);
  1521. } else {
  1522. /* keep state under NO PS state, do nothing. */
  1523. }
  1524. }
  1525. }
  1526. static
  1527. boolean halbtc8821c1ant_power_save_state(struct btc_coexist *btc, u8 ps_type,
  1528. u8 lps_val, u8 rpwm_val)
  1529. {
  1530. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  1531. boolean low_pwr_disable = FALSE, result = TRUE;
  1532. switch (ps_type) {
  1533. case BTC_PS_WIFI_NATIVE:
  1534. /* recover to original 32k low power setting */
  1535. coex_sta->force_lps_ctrl = FALSE;
  1536. low_pwr_disable = FALSE;
  1537. /* btc->btc_set(btc, BTC_SET_ACT_DISABLE_LOW_POWER,
  1538. * &low_pwr_disable);
  1539. */
  1540. btc->btc_set(btc, BTC_SET_ACT_PRE_NORMAL_LPS, NULL);
  1541. break;
  1542. case BTC_PS_LPS_ON:
  1543. coex_sta->force_lps_ctrl = TRUE;
  1544. halbtc8821c1ant_tdma_check(btc, TRUE);
  1545. halbtc8821c1ant_lps_rpwm(btc, NM_EXCU, lps_val, rpwm_val);
  1546. /* when coex force to enter LPS, do not enter 32k low power. */
  1547. low_pwr_disable = TRUE;
  1548. btc->btc_set(btc, BTC_SET_ACT_DISABLE_LOW_POWER,
  1549. &low_pwr_disable);
  1550. /* power save must executed before psTdma.*/
  1551. btc->btc_set(btc, BTC_SET_ACT_ENTER_LPS, NULL);
  1552. break;
  1553. case BTC_PS_LPS_OFF:
  1554. coex_sta->force_lps_ctrl = TRUE;
  1555. halbtc8821c1ant_tdma_check(btc, FALSE);
  1556. result = btc->btc_set(btc, BTC_SET_ACT_LEAVE_LPS, NULL);
  1557. break;
  1558. default:
  1559. break;
  1560. }
  1561. return result;
  1562. }
  1563. static
  1564. void halbtc8821c1ant_set_tdma(struct btc_coexist *btc, u8 byte1, u8 byte2,
  1565. u8 byte3, u8 byte4, u8 byte5)
  1566. {
  1567. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  1568. struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
  1569. u8 h2c_parameter[5] = {0};
  1570. u8 real_byte1 = byte1, real_byte5 = byte5;
  1571. boolean ap_enable = FALSE, result = FALSE;
  1572. struct btc_bt_link_info *bt_link_info = &btc->bt_link_info;
  1573. u8 ps_type = BTC_PS_WIFI_NATIVE;
  1574. if (byte5 & BIT(2))
  1575. coex_sta->is_tdma_btautoslot = TRUE;
  1576. else
  1577. coex_sta->is_tdma_btautoslot = FALSE;
  1578. /* release bt-auto slot for auto-slot hang is detected!! */
  1579. if (coex_sta->is_tdma_btautoslot)
  1580. if (coex_sta->is_tdma_btautoslot_hang ||
  1581. bt_link_info->slave_role)
  1582. byte5 = byte5 & 0xfb;
  1583. #if 1
  1584. btc->btc_get(btc, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &ap_enable);
  1585. #else
  1586. if (btc->wifi_link_info.link_mode == BTC_LINK_ONLY_GO &&
  1587. btc->wifi_link_info.bhotspot &&
  1588. btc->wifi_link_info.bany_client_join_go)
  1589. ap_enable = TRUE;
  1590. #endif
  1591. if ((ap_enable) && (byte1 & BIT(4) && !(byte1 & BIT(5)))) {
  1592. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1593. "[BTCoex], %s == FW for 1Ant AP mode\n", __func__);
  1594. BTC_TRACE(trace_buf);
  1595. real_byte1 &= ~BIT(4);
  1596. real_byte1 |= BIT(5);
  1597. real_byte5 |= BIT(5);
  1598. real_byte5 &= ~BIT(6);
  1599. ps_type = BTC_PS_WIFI_NATIVE;
  1600. halbtc8821c1ant_power_save_state(btc, ps_type, 0x0, 0x0);
  1601. } else if (byte1 & BIT(4) && !(byte1 & BIT(5))) {
  1602. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1603. "[BTCoex], %s == Force LPS (byte1 = 0x%x)\n",
  1604. __func__, byte1);
  1605. BTC_TRACE(trace_buf);
  1606. ps_type = BTC_PS_LPS_OFF;
  1607. if (!halbtc8821c1ant_power_save_state(btc, ps_type, 0x50, 0x4))
  1608. result = TRUE;
  1609. } else {
  1610. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1611. "[BTCoex], %s == native power save (byte1 = 0x%x)\n",
  1612. __func__, byte1);
  1613. BTC_TRACE(trace_buf);
  1614. ps_type = BTC_PS_WIFI_NATIVE;
  1615. halbtc8821c1ant_power_save_state(btc, ps_type, 0x0, 0x0);
  1616. }
  1617. coex_sta->is_set_ps_state_fail = result;
  1618. if (!coex_sta->is_set_ps_state_fail) {
  1619. h2c_parameter[0] = real_byte1;
  1620. h2c_parameter[1] = byte2;
  1621. h2c_parameter[2] = byte3;
  1622. h2c_parameter[3] = byte4;
  1623. h2c_parameter[4] = real_byte5;
  1624. coex_dm->ps_tdma_para[0] = real_byte1;
  1625. coex_dm->ps_tdma_para[1] = byte2;
  1626. coex_dm->ps_tdma_para[2] = byte3;
  1627. coex_dm->ps_tdma_para[3] = byte4;
  1628. coex_dm->ps_tdma_para[4] = real_byte5;
  1629. btc->btc_fill_h2c(btc, 0x60, 5, h2c_parameter);
  1630. } else {
  1631. coex_sta->cnt_set_ps_state_fail++;
  1632. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1633. "[BTCoex], %s == Force Leave LPS Fail (cnt = %d)\n",
  1634. __func__, coex_sta->cnt_set_ps_state_fail);
  1635. BTC_TRACE(trace_buf);
  1636. }
  1637. if (ps_type == BTC_PS_WIFI_NATIVE)
  1638. btc->btc_set(btc, BTC_SET_ACT_POST_NORMAL_LPS, NULL);
  1639. }
  1640. static
  1641. void halbtc8821c1ant_tdma(struct btc_coexist *btc, boolean force_exec,
  1642. boolean turn_on, u8 type)
  1643. {
  1644. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  1645. struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
  1646. struct btc_bt_link_info *bt_link_info = &btc->bt_link_info;
  1647. struct btc_board_info *board_info = &btc->board_info;
  1648. boolean wifi_busy = FALSE;
  1649. static u8 tdma_byte4_modify, pre_tdma_byte4_modify;
  1650. static boolean pre_wifi_busy;
  1651. u8 multiport_pstdma = BTC_MULTI_PORT_TDMA_MODE_NONE;
  1652. btc->btc_set_atomic(btc, &coex_dm->setting_tdma, TRUE);
  1653. btc->btc_get(btc, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  1654. if (wifi_busy != pre_wifi_busy) {
  1655. force_exec = TRUE;
  1656. pre_wifi_busy = wifi_busy;
  1657. }
  1658. /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */
  1659. if ((bt_link_info->slave_role) && (bt_link_info->a2dp_exist))
  1660. tdma_byte4_modify = 0x1;
  1661. else
  1662. tdma_byte4_modify = 0x0;
  1663. if (pre_tdma_byte4_modify != tdma_byte4_modify) {
  1664. force_exec = TRUE;
  1665. pre_tdma_byte4_modify = tdma_byte4_modify;
  1666. }
  1667. if (!force_exec) {
  1668. if (turn_on == coex_dm->cur_ps_tdma_on &&
  1669. type == coex_dm->cur_ps_tdma) {
  1670. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1671. "[BTCoex], Skip TDMA because no change TDMA(%s, %d)\n",
  1672. (coex_dm->cur_ps_tdma_on ? "on" : "off"),
  1673. coex_dm->cur_ps_tdma);
  1674. BTC_TRACE(trace_buf);
  1675. btc->btc_set_atomic(btc, &coex_dm->setting_tdma, FALSE);
  1676. return;
  1677. }
  1678. }
  1679. if (turn_on) {
  1680. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1681. "[BTCoex], ********** TDMA(on, %d) **********\n",
  1682. type);
  1683. BTC_TRACE(trace_buf);
  1684. /* enable TBTT nterrupt */
  1685. btc->btc_write_1byte_bitmask(btc, 0x550, 0x8, 0x1);
  1686. switch (type) {
  1687. default:
  1688. halbtc8821c1ant_set_tdma(btc, 0x61, 0x35, 0x03, 0x11,
  1689. 0x11);
  1690. break;
  1691. case 3:
  1692. halbtc8821c1ant_set_tdma(btc, 0x51, 0x30, 0x03, 0x10,
  1693. 0x50);
  1694. break;
  1695. case 4:
  1696. halbtc8821c1ant_set_tdma(btc, 0x51, 0x21, 0x03, 0x10,
  1697. 0x50);
  1698. break;
  1699. case 5:
  1700. halbtc8821c1ant_set_tdma(btc, 0x61, 0x3a, 0x03, 0x11,
  1701. 0x11);
  1702. break;
  1703. case 6:
  1704. halbtc8821c1ant_set_tdma(btc, 0x61, 0x20, 0x03, 0x11,
  1705. 0x11);
  1706. break;
  1707. case 7:
  1708. halbtc8821c1ant_set_tdma(btc, 0x51, 0x08, 0x03, 0x10,
  1709. 0x54 | tdma_byte4_modify);
  1710. break;
  1711. case 8:
  1712. halbtc8821c1ant_set_tdma(btc, 0x51, 0x08, 0x03, 0x10,
  1713. 0x54 | tdma_byte4_modify);
  1714. break;
  1715. case 9: /* not use */
  1716. halbtc8821c1ant_set_tdma(btc, 0x51, 0x10, 0x03, 0x10,
  1717. 0x54 | tdma_byte4_modify);
  1718. break;
  1719. case 10:
  1720. halbtc8821c1ant_set_tdma(btc, 0x51, 0x08, 0x07, 0x10,
  1721. 0x55);
  1722. break;
  1723. case 11:
  1724. halbtc8821c1ant_set_tdma(btc, 0x61, 0x25, 0x03, 0x11,
  1725. 0x11);
  1726. break;
  1727. case 12:
  1728. halbtc8821c1ant_set_tdma(btc, 0x51, 0x35, 0x03, 0x10,
  1729. 0x50 | tdma_byte4_modify);
  1730. break;
  1731. case 13:
  1732. halbtc8821c1ant_set_tdma(btc, 0x51, 0x08, 0x07, 0x10,
  1733. 0x54 | tdma_byte4_modify);
  1734. break;
  1735. case 14:
  1736. halbtc8821c1ant_set_tdma(btc, 0x51, 0x15, 0x03, 0x10,
  1737. 0x50 | tdma_byte4_modify);
  1738. break;
  1739. case 15: /* not use */
  1740. halbtc8821c1ant_set_tdma(btc, 0x51, 0x20, 0x03, 0x10,
  1741. 0x50 | tdma_byte4_modify);
  1742. break;
  1743. case 16: /* not use */
  1744. halbtc8821c1ant_set_tdma(btc, 0x61, 0x10, 0x03, 0x11,
  1745. 0x11 | tdma_byte4_modify);
  1746. break;
  1747. case 17:
  1748. halbtc8821c1ant_set_tdma(btc, 0x61, 0x08, 0x03, 0x11,
  1749. 0x14 | tdma_byte4_modify);
  1750. break;
  1751. case 18:
  1752. halbtc8821c1ant_set_tdma(btc, 0x51, 0x30, 0x03, 0x10,
  1753. 0x50 | tdma_byte4_modify);
  1754. break;
  1755. case 19: /* not use */
  1756. halbtc8821c1ant_set_tdma(btc, 0x61, 0x15, 0x03, 0x11,
  1757. 0x10);
  1758. break;
  1759. case 20: /* not use */
  1760. halbtc8821c1ant_set_tdma(btc, 0x61, 0x30, 0x03, 0x11,
  1761. 0x10);
  1762. break;
  1763. case 21:
  1764. halbtc8821c1ant_set_tdma(btc, 0x61, 0x30, 0x03, 0x11,
  1765. 0x10);
  1766. break;
  1767. case 22:
  1768. halbtc8821c1ant_set_tdma(btc, 0x61, 0x25, 0x03, 0x11,
  1769. 0x10);
  1770. break;
  1771. case 23:
  1772. halbtc8821c1ant_set_tdma(btc, 0x61, 0x10, 0x03, 0x11,
  1773. 0x10);
  1774. break;
  1775. case 24:
  1776. halbtc8821c1ant_set_tdma(btc, 0x51, 0x08, 0x03, 0x10,
  1777. 0x54 | tdma_byte4_modify);
  1778. break;
  1779. case 25:
  1780. halbtc8821c1ant_set_tdma(btc, 0x51, 0x3a, 0x03, 0x11,
  1781. 0x50);
  1782. break;
  1783. case 26:
  1784. halbtc8821c1ant_set_tdma(btc, 0x51, 0x08, 0x03, 0x10,
  1785. 0x55);
  1786. break;
  1787. case 27:
  1788. halbtc8821c1ant_set_tdma(btc, 0x61, 0x08, 0x03, 0x11,
  1789. 0x15);
  1790. break;
  1791. case 28:
  1792. halbtc8821c1ant_set_tdma(btc, 0x51, 0x08, 0x0b, 0x10,
  1793. 0x54);
  1794. break;
  1795. case 32:
  1796. halbtc8821c1ant_set_tdma(btc, 0x61, 0x35, 0x03, 0x11,
  1797. 0x11);
  1798. break;
  1799. case 33:
  1800. halbtc8821c1ant_set_tdma(btc, 0x61, 0x35, 0x03, 0x11,
  1801. 0x10);
  1802. break;
  1803. case 36:
  1804. halbtc8821c1ant_set_tdma(btc, 0x61, 0x50, 0x03, 0x11,
  1805. 0x10);
  1806. break;
  1807. case 37:
  1808. halbtc8821c1ant_set_tdma(btc, 0x61, 0x3c, 0x03, 0x11,
  1809. 0x10);
  1810. break;
  1811. case 201:
  1812. multiport_pstdma = BTC_MULTI_PORT_TDMA_MODE_2G_SCC_GO;
  1813. halbtc8821c1ant_set_tdma(btc, 0x51, 0x3f, 0x3, 0x10,
  1814. 0x50);
  1815. break;
  1816. case 202:
  1817. multiport_pstdma = BTC_MULTI_PORT_TDMA_MODE_2G_P2P_GO;
  1818. halbtc8821c1ant_set_tdma(btc, 0x51, 0x35, 0x3, 0x10,
  1819. 0x50);
  1820. break;
  1821. }
  1822. } else {
  1823. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1824. "[BTCoex], ********** TDMA(off, %d) **********\n",
  1825. type);
  1826. BTC_TRACE(trace_buf);
  1827. /* disable PS tdma */
  1828. switch (type) {
  1829. case 8: /* PTA Control */
  1830. halbtc8821c1ant_set_tdma(btc, 0x8, 0x0, 0x0, 0x0, 0x0);
  1831. break;
  1832. case 0:
  1833. default: /* Software control, Antenna at BT side */
  1834. halbtc8821c1ant_set_tdma(btc, 0x0, 0x0, 0x0, 0x0, 0x0);
  1835. break;
  1836. case 1: /* 2-Ant, 0x778=3, antenna control
  1837. * by antenna diversity
  1838. */
  1839. halbtc8821c1ant_set_tdma(btc, 0x0, 0x0, 0x0, 0x48, 0x0);
  1840. break;
  1841. }
  1842. }
  1843. halbtc8821c1ant_multiport_tdma(btc, multiport_pstdma);
  1844. if (!coex_sta->is_set_ps_state_fail) {
  1845. /* update pre state */
  1846. coex_dm->cur_ps_tdma_on = turn_on;
  1847. coex_dm->cur_ps_tdma = type;
  1848. }
  1849. btc->btc_set_atomic(btc, &coex_dm->setting_tdma, FALSE);
  1850. }
  1851. static
  1852. void halbtc8821c1ant_set_ant_switch(struct btc_coexist *btc,
  1853. boolean force_exec, u8 ctrl_type,
  1854. u8 pos_type)
  1855. {
  1856. struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
  1857. struct rfe_type_8821c_1ant *rfe_type = &btc->rfe_type_8821c_1ant;
  1858. struct btc_board_info *board_info = &btc->board_info;
  1859. boolean polarity_inverse = FALSE;
  1860. u8 regval = 0;
  1861. u32 u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0;
  1862. if (!rfe_type->ext_ant_switch_exist)
  1863. return;
  1864. if (!force_exec) {
  1865. if (((ctrl_type << 8) + pos_type) ==
  1866. coex_dm->cur_ext_ant_switch_status)
  1867. return;
  1868. }
  1869. coex_dm->cur_ext_ant_switch_status = (ctrl_type << 8) + pos_type;
  1870. /* swap control polarity if use different switch control polarity
  1871. * Normal switch polarity for DPDT,
  1872. * 0xcb4[29:28] = 2b'01 => BTG to Main, WLG to Aux,
  1873. * 0xcb4[29:28] = 2b'10 => BTG to Aux, WLG to Main
  1874. * Normal switch polarity for SPDT,
  1875. * 0xcb4[29:28] = 2b'01 => Ant to BTG,
  1876. * 0xcb4[29:28] = 2b'10 => Ant to WLG
  1877. */
  1878. if (rfe_type->ext_ant_switch_ctrl_polarity)
  1879. polarity_inverse = !polarity_inverse;
  1880. /* swap control polarity if 1-Ant at Aux */
  1881. if (rfe_type->ant_at_main_port == FALSE)
  1882. polarity_inverse = !polarity_inverse;
  1883. switch (pos_type) {
  1884. default:
  1885. case BT_8821C_1ANT_TO_BT:
  1886. case BT_8821C_1ANT_TO_NOCARE:
  1887. case BT_8821C_1ANT_TO_WLA:
  1888. break;
  1889. case BT_8821C_1ANT_TO_WLG:
  1890. if (!rfe_type->wlg_locate_at_btg)
  1891. polarity_inverse = !polarity_inverse;
  1892. break;
  1893. }
  1894. if (board_info->ant_div_cfg)
  1895. ctrl_type = BT_8821C_1ANT_CTRL_BY_ANTDIV;
  1896. switch (ctrl_type) {
  1897. default:
  1898. case BT_8821C_1ANT_CTRL_BY_BBSW:
  1899. /* 0x4c[23] = 0 */
  1900. btc->btc_write_1byte_bitmask(btc, 0x4e, 0x80, 0x0);
  1901. /* 0x4c[24] = 1 */
  1902. btc->btc_write_1byte_bitmask(btc, 0x4f, 0x01, 0x1);
  1903. /* BB SW, DPDT use RFE_ctrl8 and RFE_ctrl9 as control pin */
  1904. btc->btc_write_1byte_bitmask(btc, 0xcb4, 0xff, 0x77);
  1905. /* 0xcb4[29:28] = 2b'01 for no switch_polarity_inverse,
  1906. * DPDT_SEL_N =1, DPDT_SEL_P =0
  1907. */
  1908. regval = (!polarity_inverse ? 0x1 : 0x2);
  1909. btc->btc_write_1byte_bitmask(btc, 0xcb7, 0x30, regval);
  1910. break;
  1911. case BT_8821C_1ANT_CTRL_BY_PTA:
  1912. /* 0x4c[23] = 0 */
  1913. btc->btc_write_1byte_bitmask(btc, 0x4e, 0x80, 0x0);
  1914. /* 0x4c[24] = 1 */
  1915. btc->btc_write_1byte_bitmask(btc, 0x4f, 0x01, 0x1);
  1916. /* PTA, DPDT use RFE_ctrl8 and RFE_ctrl9 as control pin */
  1917. btc->btc_write_1byte_bitmask(btc, 0xcb4, 0xff, 0x66);
  1918. /* 0xcb4[29:28] = 2b'10 for no switch_polatiry_inverse,
  1919. * DPDT_SEL_N =1, DPDT_SEL_P =0 @ GNT_BT=1
  1920. */
  1921. regval = (!polarity_inverse ? 0x2 : 0x1);
  1922. btc->btc_write_1byte_bitmask(btc, 0xcb7, 0x30, regval);
  1923. break;
  1924. case BT_8821C_1ANT_CTRL_BY_ANTDIV:
  1925. /* 0x4c[23] = 0 */
  1926. btc->btc_write_1byte_bitmask(btc, 0x4e, 0x80, 0x0);
  1927. /* 0x4c[24] = 1 */
  1928. btc->btc_write_1byte_bitmask(btc, 0x4f, 0x01, 0x1);
  1929. btc->btc_write_1byte_bitmask(btc, 0xcb4, 0xff, 0x88);
  1930. /* no regval_0xcb7 setup required, because antenna switch
  1931. * control value by antenna diversity
  1932. */
  1933. break;
  1934. case BT_8821C_1ANT_CTRL_BY_MAC:
  1935. /* 0x4c[23] = 1 */
  1936. btc->btc_write_1byte_bitmask(btc, 0x4e, 0x80, 0x1);
  1937. /* 0x64[0] = 1b'0 for no switch_polarity_inverse,
  1938. * DPDT_SEL_N =1, DPDT_SEL_P =0
  1939. */
  1940. regval = (!polarity_inverse ? 0x0 : 0x1);
  1941. btc->btc_write_1byte_bitmask(btc, 0x64, 0x1, regval);
  1942. break;
  1943. case BT_8821C_1ANT_CTRL_BY_FW:
  1944. /* 0x4c[23] = 0 */
  1945. btc->btc_write_1byte_bitmask(btc, 0x4e, 0x80, 0x0);
  1946. /* 0x4c[24] = 1 */
  1947. btc->btc_write_1byte_bitmask(btc, 0x4f, 0x01, 0x1);
  1948. break;
  1949. case BT_8821C_1ANT_CTRL_BY_BT:
  1950. /* 0x4c[23] = 0 */
  1951. btc->btc_write_1byte_bitmask(btc, 0x4e, 0x80, 0x0);
  1952. /* 0x4c[24] = 0 */
  1953. btc->btc_write_1byte_bitmask(btc, 0x4f, 0x01, 0x0);
  1954. /* no setup required, because antenna switch control value
  1955. * by BT vendor 0xac[1:0]
  1956. */
  1957. break;
  1958. }
  1959. /* PAPE, LNA_ON control by BT while WLAN off for current leakage issue */
  1960. if (ctrl_type == BT_8821C_1ANT_CTRL_BY_BT) {
  1961. /* PAPE 0x64[29] = 0 */
  1962. btc->btc_write_1byte_bitmask(btc, 0x67, 0x20, 0x0);
  1963. /* LNA_ON 0x64[28] = 0 */
  1964. btc->btc_write_1byte_bitmask(btc, 0x67, 0x10, 0x0);
  1965. } else {
  1966. /* PAPE 0x64[29] = 1 */
  1967. btc->btc_write_1byte_bitmask(btc, 0x67, 0x20, 0x1);
  1968. /* LNA_ON 0x64[28] = 1 */
  1969. btc->btc_write_1byte_bitmask(btc, 0x67, 0x10, 0x1);
  1970. }
  1971. }
  1972. static
  1973. void halbtc8821c1ant_set_rfe_type(struct btc_coexist *btc)
  1974. {
  1975. struct btc_board_info *board_info = &btc->board_info;
  1976. struct rfe_type_8821c_1ant *rfe_type = &btc->rfe_type_8821c_1ant;
  1977. /* the following setup should be got from Efuse in the future */
  1978. rfe_type->rfe_module_type = board_info->rfe_type & 0x1f;
  1979. rfe_type->ext_ant_switch_ctrl_polarity = 0;
  1980. switch (rfe_type->rfe_module_type) {
  1981. case 0:
  1982. case 8:
  1983. default: /*2-Ant, DPDT, WLG*/
  1984. rfe_type->ext_ant_switch_exist = TRUE;
  1985. rfe_type->ext_ant_switch_type = BT_8821C_1ANT_USE_DPDT;
  1986. rfe_type->wlg_locate_at_btg = FALSE;
  1987. rfe_type->ant_at_main_port = TRUE;
  1988. break;
  1989. case 1:
  1990. case 9: /*1-Ant, Main, WLG */
  1991. rfe_type->ext_ant_switch_exist = TRUE;
  1992. rfe_type->ext_ant_switch_type = BT_8821C_1ANT_USE_SPDT;
  1993. rfe_type->wlg_locate_at_btg = FALSE;
  1994. rfe_type->ant_at_main_port = TRUE;
  1995. break;
  1996. case 2:
  1997. case 10: /*1-Ant, Main, BTG */
  1998. rfe_type->ext_ant_switch_exist = TRUE;
  1999. rfe_type->ext_ant_switch_type = BT_8821C_1ANT_USE_SPDT;
  2000. rfe_type->wlg_locate_at_btg = TRUE;
  2001. rfe_type->ant_at_main_port = TRUE;
  2002. break;
  2003. case 3:
  2004. case 11: /*1-Ant, Aux, WLG */
  2005. rfe_type->ext_ant_switch_exist = TRUE;
  2006. rfe_type->ext_ant_switch_type = BT_8821C_1ANT_USE_DPDT;
  2007. rfe_type->wlg_locate_at_btg = FALSE;
  2008. rfe_type->ant_at_main_port = FALSE;
  2009. break;
  2010. case 4:
  2011. case 12: /*1-Ant, Aux, BTG */
  2012. rfe_type->ext_ant_switch_exist = TRUE;
  2013. rfe_type->ext_ant_switch_type = BT_8821C_1ANT_USE_DPDT;
  2014. rfe_type->wlg_locate_at_btg = TRUE;
  2015. rfe_type->ant_at_main_port = FALSE;
  2016. break;
  2017. case 5:
  2018. case 13: /*2-Ant, no switch, WLG*/
  2019. rfe_type->ext_ant_switch_exist = FALSE;
  2020. rfe_type->ext_ant_switch_type = BT_8821C_1ANT_SWITCH_NONE;
  2021. rfe_type->wlg_locate_at_btg = FALSE;
  2022. rfe_type->ant_at_main_port = TRUE;
  2023. break;
  2024. case 6:
  2025. case 14: /*2-Ant, no antenna switch, WLG*/
  2026. rfe_type->ext_ant_switch_exist = FALSE;
  2027. rfe_type->ext_ant_switch_type = BT_8821C_1ANT_SWITCH_NONE;
  2028. rfe_type->wlg_locate_at_btg = FALSE;
  2029. rfe_type->ant_at_main_port = TRUE;
  2030. break;
  2031. case 7:
  2032. case 15: /*2-Ant, DPDT, BTG*/
  2033. rfe_type->ext_ant_switch_exist = TRUE;
  2034. rfe_type->ext_ant_switch_type = BT_8821C_1ANT_USE_DPDT;
  2035. rfe_type->wlg_locate_at_btg = TRUE;
  2036. rfe_type->ant_at_main_port = TRUE;
  2037. break;
  2038. }
  2039. }
  2040. static
  2041. void halbtc8821c1ant_set_ant_path(struct btc_coexist *btc,
  2042. u8 ant_pos_type, boolean force_exec,
  2043. u8 phase)
  2044. {
  2045. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  2046. struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
  2047. struct rfe_type_8821c_1ant *rfe_type = &btc->rfe_type_8821c_1ant;
  2048. u32 cnt_bt_cal_chk = 0, u32tmp1 = 0, u32tmp2 = 0;
  2049. u8 u8tmp = 0, ctrl_type, pos_type;
  2050. if (!force_exec) {
  2051. if (coex_dm->cur_ant_pos_type == ((ant_pos_type << 8) + phase))
  2052. return;
  2053. }
  2054. coex_dm->cur_ant_pos_type = (ant_pos_type << 8) + phase;
  2055. if (btc->dbg_mode) {
  2056. u32tmp1 = btc->btc_read_4byte(btc, 0xcbc);
  2057. u32tmp2 = btc->btc_read_4byte(btc, 0xcb4);
  2058. u8tmp = btc->btc_read_1byte(btc, 0x73);
  2059. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2060. "[BTCoex], (Before Ant Setup) 0xcb4 = 0x%x, 0xcbc = 0x%x, 0x73 = 0x%x\n",
  2061. u32tmp1, u32tmp2, u8tmp);
  2062. BTC_TRACE(trace_buf);
  2063. }
  2064. switch (phase) {
  2065. case BT_8821C_1ANT_PHASE_POWERON:
  2066. /* set Path control owner to BT at power-on step */
  2067. halbtc8821c1ant_coex_ctrl_owner(btc, BT_8821C_1ANT_PCO_BTSIDE);
  2068. if (ant_pos_type == BTC_ANT_PATH_AUTO)
  2069. ant_pos_type = BTC_ANT_PATH_BT;
  2070. coex_sta->run_time_state = FALSE;
  2071. break;
  2072. case BT_8821C_1ANT_PHASE_INIT:
  2073. /* Disable LTE Coex Function in WiFi side (
  2074. * this should be on if LTE coex is required)
  2075. */
  2076. halbtc8821c1ant_ltecoex_enable(btc, 0x0);
  2077. /* GNT_WL_LTE always = 1
  2078. * (this should be config if LTE coex is required)
  2079. */
  2080. halbtc8821c1ant_ltecoex_table(btc, BT_8821C_1ANT_CTT_WL_VS_LTE,
  2081. 0xffff);
  2082. /* GNT_BT_LTE always = 1
  2083. * (this should be config if LTE coex is required)
  2084. */
  2085. halbtc8821c1ant_ltecoex_table(btc, BT_8821C_1ANT_CTT_BT_VS_LTE,
  2086. 0xffff);
  2087. /* Wait If BT IQK running, because Path control owner is at
  2088. * BT during BT IQK (setup by WiFi firmware)
  2089. */
  2090. while (cnt_bt_cal_chk <= 20) {
  2091. u8tmp = btc->btc_read_1byte(btc, 0x49c);
  2092. cnt_bt_cal_chk++;
  2093. if (u8tmp & BIT(1)) {
  2094. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2095. "[BTCoex], ########### BT is calibrating (wait cnt=%d) ###########\n",
  2096. cnt_bt_cal_chk);
  2097. BTC_TRACE(trace_buf);
  2098. delay_ms(10);
  2099. } else {
  2100. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2101. "[BTCoex], ********** BT is NOT calibrating (wait cnt=%d)**********\n",
  2102. cnt_bt_cal_chk);
  2103. BTC_TRACE(trace_buf);
  2104. break;
  2105. }
  2106. }
  2107. /* set Path control owner to WL at initial step */
  2108. halbtc8821c1ant_coex_ctrl_owner(btc, BT_8821C_1ANT_PCO_WLSIDE);
  2109. /* set GNT_BT to SW high */
  2110. halbtc8821c1ant_set_gnt_bt(btc,
  2111. BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
  2112. BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW,
  2113. BT_8821C_1ANT_GNT_SET_TO_HIGH);
  2114. /* Set GNT_WL to SW low */
  2115. halbtc8821c1ant_set_gnt_wl(btc,
  2116. BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
  2117. BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW,
  2118. BT_8821C_1ANT_GNT_SET_TO_LOW);
  2119. coex_sta->run_time_state = FALSE;
  2120. if (ant_pos_type == BTC_ANT_PATH_AUTO)
  2121. ant_pos_type = BTC_ANT_PATH_BT;
  2122. break;
  2123. case BT_8821C_1ANT_PHASE_WONLY:
  2124. /* Disable LTE Coex Function in WiFi side
  2125. *(this should be on if LTE coex is required)
  2126. */
  2127. halbtc8821c1ant_ltecoex_enable(btc, 0x0);
  2128. /* GNT_WL_LTE always = 1
  2129. *(this should be config if LTE coex is required)
  2130. */
  2131. halbtc8821c1ant_ltecoex_table(btc, BT_8821C_1ANT_CTT_WL_VS_LTE,
  2132. 0xffff);
  2133. /* GNT_BT_LTE always = 1
  2134. *(this should be config if LTE coex is required)
  2135. */
  2136. halbtc8821c1ant_ltecoex_table(btc, BT_8821C_1ANT_CTT_BT_VS_LTE,
  2137. 0xffff);
  2138. /* set Path control owner to WL at initial step */
  2139. halbtc8821c1ant_coex_ctrl_owner(btc, BT_8821C_1ANT_PCO_WLSIDE);
  2140. /* set GNT_BT to SW Low */
  2141. halbtc8821c1ant_set_gnt_bt(btc, BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
  2142. BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW,
  2143. BT_8821C_1ANT_GNT_SET_TO_LOW);
  2144. /* Set GNT_WL to SW high */
  2145. halbtc8821c1ant_set_gnt_wl(btc, BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
  2146. BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW,
  2147. BT_8821C_1ANT_GNT_SET_TO_HIGH);
  2148. coex_sta->run_time_state = FALSE;
  2149. if (ant_pos_type == BTC_ANT_PATH_AUTO)
  2150. ant_pos_type = BTC_ANT_PATH_WIFI;
  2151. break;
  2152. case BT_8821C_1ANT_PHASE_WOFF:
  2153. /* Disable LTE Coex Function in WiFi side */
  2154. halbtc8821c1ant_ltecoex_enable(btc, 0x0);
  2155. /* set Path control owner to BT */
  2156. halbtc8821c1ant_coex_ctrl_owner(btc,
  2157. BT_8821C_1ANT_PCO_BTSIDE);
  2158. coex_sta->run_time_state = FALSE;
  2159. break;
  2160. case BT_8821C_1ANT_PHASE_2G:
  2161. while (cnt_bt_cal_chk <= 20) {
  2162. /* 0x49c[0]=1 WL IQK, 0x49c[1]=1 BT IQK*/
  2163. u8tmp = btc->btc_read_1byte(btc, 0x49c);
  2164. cnt_bt_cal_chk++;
  2165. if (u8tmp & BIT(0)) {
  2166. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2167. "[BTCoex], ########### WL is IQK (wait cnt=%d)\n",
  2168. cnt_bt_cal_chk);
  2169. BTC_TRACE(trace_buf);
  2170. delay_ms(10);
  2171. } else if (u8tmp & BIT(1)) {
  2172. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2173. "[BTCoex], ########### BT is IQK (wait cnt=%d)\n",
  2174. cnt_bt_cal_chk);
  2175. BTC_TRACE(trace_buf);
  2176. delay_ms(10);
  2177. } else {
  2178. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2179. "[BTCoex], ********** WL and BT is NOT IQK (wait cnt=%d)\n",
  2180. cnt_bt_cal_chk);
  2181. BTC_TRACE(trace_buf);
  2182. break;
  2183. }
  2184. }
  2185. /* set Path control owner to WL at runtime step */
  2186. halbtc8821c1ant_coex_ctrl_owner(btc, BT_8821C_1ANT_PCO_WLSIDE);
  2187. /* set GNT_BT to PTA */
  2188. halbtc8821c1ant_set_gnt_bt(btc, BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
  2189. BT_8821C_1ANT_GNT_TYPE_CTRL_BY_PTA,
  2190. BT_8821C_1ANT_GNT_SET_BY_HW);
  2191. halbtc8821c1ant_set_gnt_wl(btc, BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
  2192. BT_8821C_1ANT_GNT_TYPE_CTRL_BY_PTA,
  2193. BT_8821C_1ANT_GNT_SET_BY_HW);
  2194. coex_sta->run_time_state = TRUE;
  2195. if (ant_pos_type == BTC_ANT_PATH_AUTO) {
  2196. if (rfe_type->wlg_locate_at_btg)
  2197. ant_pos_type = BTC_ANT_PATH_WIFI;
  2198. else
  2199. ant_pos_type = BTC_ANT_PATH_PTA;
  2200. }
  2201. break;
  2202. case BT_8821C_1ANT_PHASE_5G:
  2203. /* set Path control owner to WL at runtime step */
  2204. halbtc8821c1ant_coex_ctrl_owner(btc, BT_8821C_1ANT_PCO_WLSIDE);
  2205. /* set GNT_BT to SW Hi */
  2206. halbtc8821c1ant_set_gnt_bt(btc, BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
  2207. BT_8821C_1ANT_GNT_TYPE_CTRL_BY_PTA,
  2208. BT_8821C_1ANT_GNT_SET_BY_HW);
  2209. /* Set GNT_WL to SW Hi */
  2210. halbtc8821c1ant_set_gnt_wl(btc, BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
  2211. BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW,
  2212. BT_8821C_1ANT_GNT_SET_TO_HIGH);
  2213. coex_sta->run_time_state = TRUE;
  2214. if (ant_pos_type == BTC_ANT_PATH_AUTO)
  2215. ant_pos_type = BTC_ANT_PATH_WIFI5G;
  2216. break;
  2217. case BT_8821C_1ANT_PHASE_BTMP:
  2218. /* Disable LTE Coex Function in WiFi side */
  2219. halbtc8821c1ant_ltecoex_enable(btc, 0x0);
  2220. /* set Path control owner to WL */
  2221. halbtc8821c1ant_coex_ctrl_owner(btc, BT_8821C_1ANT_PCO_WLSIDE);
  2222. /* set GNT_BT to SW Hi */
  2223. halbtc8821c1ant_set_gnt_bt(btc, BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
  2224. BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW,
  2225. BT_8821C_1ANT_GNT_SET_TO_HIGH);
  2226. /* Set GNT_WL to SW Lo */
  2227. halbtc8821c1ant_set_gnt_wl(btc, BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
  2228. BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW,
  2229. BT_8821C_1ANT_GNT_SET_TO_LOW);
  2230. coex_sta->run_time_state = FALSE;
  2231. /* Set Ext Ant Switch to BT side at BT MP mode */
  2232. if (ant_pos_type == BTC_ANT_PATH_AUTO)
  2233. ant_pos_type = BTC_ANT_PATH_BT;
  2234. break;
  2235. case BT_8821C_1ANT_PHASE_ANTDET:
  2236. halbtc8821c1ant_coex_ctrl_owner(btc, BT_8821C_1ANT_PCO_WLSIDE);
  2237. /* set GNT_BT to high */
  2238. halbtc8821c1ant_set_gnt_bt(btc, BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
  2239. BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW,
  2240. BT_8821C_1ANT_GNT_SET_TO_HIGH);
  2241. /* Set GNT_WL to high */
  2242. halbtc8821c1ant_set_gnt_wl(btc, BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
  2243. BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW,
  2244. BT_8821C_1ANT_GNT_SET_TO_HIGH);
  2245. if (ant_pos_type == BTC_ANT_PATH_AUTO)
  2246. ant_pos_type = BTC_ANT_PATH_BT;
  2247. coex_sta->run_time_state = FALSE;
  2248. break;
  2249. case BT_8821C_1ANT_PHASE_MCC:
  2250. /* set Path control owner to WL at runtime step */
  2251. halbtc8821c1ant_coex_ctrl_owner(btc, BT_8821C_1ANT_PCO_WLSIDE);
  2252. /* set GNT_BT to PTA */
  2253. halbtc8821c1ant_set_gnt_bt(btc, BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
  2254. BT_8821C_1ANT_GNT_TYPE_CTRL_BY_PTA,
  2255. BT_8821C_1ANT_GNT_SET_BY_HW);
  2256. halbtc8821c1ant_set_gnt_wl(btc, BT_8821C_1ANT_GNT_BLOCK_RFC_BB,
  2257. BT_8821C_1ANT_GNT_TYPE_CTRL_BY_PTA,
  2258. BT_8821C_1ANT_GNT_SET_BY_HW);
  2259. coex_sta->run_time_state = TRUE;
  2260. if (ant_pos_type == BTC_ANT_PATH_AUTO)
  2261. ant_pos_type = BTC_ANT_PATH_BT;
  2262. break;
  2263. }
  2264. if (phase == BT_8821C_1ANT_PHASE_WOFF) {
  2265. /* Set Ext Ant Switch to BT control at wifi off step */
  2266. ctrl_type = BT_8821C_1ANT_CTRL_BY_BT;
  2267. pos_type = BT_8821C_1ANT_TO_NOCARE;
  2268. } else if (phase == BT_8821C_1ANT_PHASE_MCC) {
  2269. ctrl_type = BT_8821C_1ANT_CTRL_BY_FW;
  2270. pos_type = BT_8821C_1ANT_TO_NOCARE;
  2271. } else {
  2272. switch (ant_pos_type) {
  2273. case BTC_ANT_PATH_WIFI:
  2274. ctrl_type = BT_8821C_1ANT_CTRL_BY_BBSW;
  2275. pos_type = BT_8821C_1ANT_TO_WLG;
  2276. break;
  2277. case BTC_ANT_PATH_WIFI5G:
  2278. ctrl_type = BT_8821C_1ANT_CTRL_BY_BBSW;
  2279. pos_type = BT_8821C_1ANT_TO_WLA;
  2280. break;
  2281. case BTC_ANT_PATH_BT:
  2282. ctrl_type = BT_8821C_1ANT_CTRL_BY_BBSW;
  2283. pos_type = BT_8821C_1ANT_TO_BT;
  2284. break;
  2285. default:
  2286. case BTC_ANT_PATH_PTA:
  2287. ctrl_type = BT_8821C_1ANT_CTRL_BY_PTA;
  2288. pos_type = BT_8821C_1ANT_TO_NOCARE;
  2289. break;
  2290. }
  2291. }
  2292. halbtc8821c1ant_set_ant_switch(btc, force_exec, ctrl_type, pos_type);
  2293. if (btc->dbg_mode) {
  2294. u32tmp1 = btc->btc_read_4byte(btc, 0xcbc);
  2295. u32tmp2 = btc->btc_read_4byte(btc, 0xcb4);
  2296. u8tmp = btc->btc_read_1byte(btc, 0x73);
  2297. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2298. "[BTCoex], (After Ant Setup) 0xcb4 = 0x%x, 0xcbc = 0x%x, 0x73 = 0x%x\n",
  2299. u32tmp1, u32tmp2, u8tmp);
  2300. BTC_TRACE(trace_buf);
  2301. }
  2302. }
  2303. /* *********************************************
  2304. *
  2305. * Software Coex Mechanism start
  2306. *
  2307. * *********************************************
  2308. */
  2309. /* *********************************************
  2310. *
  2311. * Non-Software Coex Mechanism start
  2312. *
  2313. * *********************************************
  2314. */
  2315. static
  2316. u8 halbtc8821c1ant_action_algorithm(struct btc_coexist *btc)
  2317. {
  2318. struct btc_bt_link_info *bt_link_info = &btc->bt_link_info;
  2319. u8 algorithm = BT_8821C_1ANT_COEX_UNDEFINED;
  2320. u8 profile_map = 0;
  2321. if (bt_link_info->sco_exist)
  2322. profile_map = profile_map | BIT(0);
  2323. if (bt_link_info->hid_exist)
  2324. profile_map = profile_map | BIT(1);
  2325. if (bt_link_info->a2dp_exist)
  2326. profile_map = profile_map | BIT(2);
  2327. if (bt_link_info->pan_exist)
  2328. profile_map = profile_map | BIT(3);
  2329. switch (profile_map) {
  2330. default:
  2331. case 0:
  2332. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2333. "[BTCoex], No BT link exists!!!\n");
  2334. BTC_TRACE(trace_buf);
  2335. algorithm = BT_8821C_1ANT_COEX_UNDEFINED;
  2336. break;
  2337. case 1:
  2338. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2339. "[BTCoex], BT Profile = SCO only\n");
  2340. BTC_TRACE(trace_buf);
  2341. algorithm = BT_8821C_1ANT_COEX_SCO;
  2342. break;
  2343. case 2:
  2344. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2345. "[BTCoex], BT Profile = HID only\n");
  2346. BTC_TRACE(trace_buf);
  2347. algorithm = BT_8821C_1ANT_COEX_HID;
  2348. break;
  2349. case 3:
  2350. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2351. "[BTCoex], BT Profile = SCO + HID ==> HID\n");
  2352. BTC_TRACE(trace_buf);
  2353. algorithm = BT_8821C_1ANT_COEX_HID;
  2354. break;
  2355. case 4:
  2356. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2357. "[BTCoex], BT Profile = A2DP only\n");
  2358. BTC_TRACE(trace_buf);
  2359. algorithm = BT_8821C_1ANT_COEX_A2DP;
  2360. break;
  2361. case 5:
  2362. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2363. "[BTCoex], BT Profile = SCO + A2DP ==> HID + A2DP\n");
  2364. BTC_TRACE(trace_buf);
  2365. algorithm = BT_8821C_1ANT_COEX_HID_A2DP;
  2366. break;
  2367. case 6:
  2368. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2369. "[BTCoex], BT Profile = HID + A2DP\n");
  2370. BTC_TRACE(trace_buf);
  2371. algorithm = BT_8821C_1ANT_COEX_HID_A2DP;
  2372. break;
  2373. case 7:
  2374. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2375. "[BTCoex], BT Profile = SCO + HID + A2DP ==> HID + A2DP\n");
  2376. BTC_TRACE(trace_buf);
  2377. algorithm = BT_8821C_1ANT_COEX_HID_A2DP;
  2378. break;
  2379. case 8:
  2380. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2381. "[BTCoex], BT Profile = PAN(EDR) only\n");
  2382. BTC_TRACE(trace_buf);
  2383. algorithm = BT_8821C_1ANT_COEX_PAN;
  2384. break;
  2385. case 9:
  2386. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2387. "[BTCoex], BT Profile = SCO + PAN(EDR) ==> HID + PAN(EDR)\n");
  2388. BTC_TRACE(trace_buf);
  2389. algorithm = BT_8821C_1ANT_COEX_PAN_HID;
  2390. break;
  2391. case 10:
  2392. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2393. "[BTCoex], BT Profile = HID + PAN(EDR)\n");
  2394. BTC_TRACE(trace_buf);
  2395. algorithm = BT_8821C_1ANT_COEX_PAN_HID;
  2396. break;
  2397. case 11:
  2398. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2399. "[BTCoex], BT Profile = SCO + HID + PAN(EDR) ==> HID + PAN(EDR)\n");
  2400. BTC_TRACE(trace_buf);
  2401. algorithm = BT_8821C_1ANT_COEX_PAN_HID;
  2402. break;
  2403. case 12:
  2404. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2405. "[BTCoex], BT Profile = A2DP + PAN(EDR)\n");
  2406. BTC_TRACE(trace_buf);
  2407. algorithm = BT_8821C_1ANT_COEX_PAN_A2DP;
  2408. break;
  2409. case 13:
  2410. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2411. "[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> A2DP + PAN(EDR)\n");
  2412. BTC_TRACE(trace_buf);
  2413. algorithm = BT_8821C_1ANT_COEX_PAN_A2DP;
  2414. break;
  2415. case 14:
  2416. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2417. "[BTCoex], BT Profile = HID + A2DP + PAN(EDR) ==> A2DP + PAN(EDR)\n");
  2418. BTC_TRACE(trace_buf);
  2419. algorithm = BT_8821C_1ANT_COEX_PAN_A2DP;
  2420. break;
  2421. case 15:
  2422. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2423. "[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR) ==> A2DP + PAN(EDR)\n");
  2424. BTC_TRACE(trace_buf);
  2425. algorithm = BT_8821C_1ANT_COEX_PAN_A2DP;
  2426. break;
  2427. }
  2428. return algorithm;
  2429. }
  2430. static
  2431. void halbtc8821c1ant_action_coex_all_off(struct btc_coexist *btc)
  2432. {
  2433. halbtc8821c1ant_table(btc, NM_EXCU, 0);
  2434. halbtc8821c1ant_tdma(btc, NM_EXCU, FALSE, 0);
  2435. }
  2436. static
  2437. void halbtc8821c1ant_action_bt_whql_test(struct btc_coexist *btc)
  2438. {
  2439. halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, NM_EXCU,
  2440. BT_8821C_1ANT_PHASE_2G);
  2441. halbtc8821c1ant_table(btc, NM_EXCU, 0);
  2442. halbtc8821c1ant_tdma(btc, NM_EXCU, FALSE, 8);
  2443. }
  2444. static
  2445. void halbtc8821c1ant_action_bt_relink(struct btc_coexist *btc)
  2446. {
  2447. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  2448. struct btc_bt_link_info *bt_link_info = &btc->bt_link_info;
  2449. if ((!coex_sta->is_bt_multi_link && !bt_link_info->pan_exist) ||
  2450. (bt_link_info->a2dp_exist && bt_link_info->hid_exist)) {
  2451. halbtc8821c1ant_table(btc, NM_EXCU, 0);
  2452. halbtc8821c1ant_tdma(btc, NM_EXCU, FALSE, 8);
  2453. }
  2454. }
  2455. static
  2456. void halbtc8821c1ant_action_bt_idle(struct btc_coexist *btc)
  2457. {
  2458. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  2459. struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
  2460. boolean wifi_busy = FALSE;
  2461. u32 wifi_link_status = 0;
  2462. btc->btc_get(btc, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  2463. btc->btc_get(btc, BTC_GET_U4_WIFI_LINK_STATUS, &wifi_link_status);
  2464. if (!wifi_busy) {
  2465. halbtc8821c1ant_table(btc, NM_EXCU, 7);
  2466. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 32);
  2467. } else { /* if wl busy */
  2468. /*for initiator scan on*/
  2469. if ((coex_sta->bt_ble_scan_type & 0x2) &&
  2470. BT_8821C_1ANT_BSTATUS_NCON_IDLE ==
  2471. coex_dm->bt_status) {
  2472. halbtc8821c1ant_table(btc, NM_EXCU, 2);
  2473. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 36);
  2474. } else {
  2475. halbtc8821c1ant_table(btc, NM_EXCU, 2);
  2476. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 33);
  2477. }
  2478. }
  2479. }
  2480. static
  2481. void halbtc8821c1ant_action_bt_inquiry(struct btc_coexist *btc)
  2482. {
  2483. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  2484. struct btc_bt_link_info *bt_link_info = &btc->bt_link_info;
  2485. boolean wifi_connected = FALSE, wifi_busy = FALSE;
  2486. btc->btc_get(btc, BTC_GET_BL_WIFI_CONNECTED, &wifi_connected);
  2487. btc->btc_get(btc, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  2488. if (coex_sta->is_wifi_linkscan_process ||
  2489. coex_sta->wifi_high_pri_task1 ||
  2490. coex_sta->wifi_high_pri_task2) {
  2491. if (coex_sta->bt_create_connection) {
  2492. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2493. "[BTCoex], bt page + wifi hi-pri task\n");
  2494. BTC_TRACE(trace_buf);
  2495. halbtc8821c1ant_table(btc, NM_EXCU, 1);
  2496. if (bt_link_info->a2dp_exist &&
  2497. !bt_link_info->pan_exist)
  2498. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 17);
  2499. else if (coex_sta->wifi_high_pri_task1)
  2500. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 36);
  2501. else
  2502. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 33);
  2503. } else {
  2504. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2505. "[BTCoex], bt inquiry + wifi hi-pri task\n");
  2506. BTC_TRACE(trace_buf);
  2507. halbtc8821c1ant_table(btc, NM_EXCU, 1);
  2508. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 21);
  2509. }
  2510. } else if (wifi_busy) {
  2511. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2512. "[BTCoex], bt inq/page + wifi busy\n");
  2513. BTC_TRACE(trace_buf);
  2514. halbtc8821c1ant_table(btc, NM_EXCU, 1);
  2515. /* for android 6.0 remote name request */
  2516. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 23);
  2517. } else if (wifi_connected) {
  2518. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2519. "[BTCoex], bt inq/page + wifi connected\n");
  2520. BTC_TRACE(trace_buf);
  2521. halbtc8821c1ant_table(btc, NM_EXCU, 1);
  2522. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 23);
  2523. } else {
  2524. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2525. "[BTCoex], bt inq/page + wifi not-connected\n");
  2526. BTC_TRACE(trace_buf);
  2527. halbtc8821c1ant_table(btc, NM_EXCU, 0);
  2528. halbtc8821c1ant_tdma(btc, NM_EXCU, FALSE, 8);
  2529. }
  2530. }
  2531. static
  2532. void halbtc8821c1ant_action_bt_sco_hid_busy(struct btc_coexist *btc)
  2533. {
  2534. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  2535. struct btc_bt_link_info *bt_link_info = &btc->bt_link_info;
  2536. boolean wifi_connected = FALSE, wifi_busy = FALSE,
  2537. wifi_cckdeadlock_ap = FALSE;
  2538. u32 wifi_bw = 1;
  2539. u8 iot_peer = BTC_IOT_PEER_UNKNOWN;
  2540. btc->btc_get(btc, BTC_GET_BL_WIFI_CONNECTED, &wifi_connected);
  2541. btc->btc_get(btc, BTC_GET_U4_WIFI_BW, &wifi_bw);
  2542. btc->btc_get(btc, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  2543. btc->btc_get(btc, BTC_GET_U1_IOT_PEER, &iot_peer);
  2544. if (!wifi_busy)
  2545. wifi_busy = coex_sta->gl_wifi_busy;
  2546. if (iot_peer == BTC_IOT_PEER_ATHEROS && coex_sta->cck_lock_ever)
  2547. wifi_cckdeadlock_ap = TRUE;
  2548. if (bt_link_info->sco_exist) {
  2549. if (coex_sta->is_bt_multi_link) {
  2550. halbtc8821c1ant_table(btc, NM_EXCU, 1);
  2551. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 25);
  2552. } else {
  2553. halbtc8821c1ant_table(btc, NM_EXCU, 1);
  2554. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 5);
  2555. }
  2556. } else if (coex_sta->is_hid_rcu) {
  2557. if (coex_sta->voice_over_HOGP) { /* voice by RCU */
  2558. /* change coex table if slave latency support or not */
  2559. if (!wifi_busy)
  2560. halbtc8821c1ant_table(btc, NM_EXCU, 7);
  2561. else if (coex_sta->bt_coex_supported_feature & BIT(11))
  2562. halbtc8821c1ant_table(btc, NM_EXCU, 1);
  2563. else
  2564. halbtc8821c1ant_table(btc, NM_EXCU, 2);
  2565. if (wifi_busy)
  2566. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 37);
  2567. else
  2568. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 6);
  2569. } else { /* RCU */
  2570. if (!wifi_busy)
  2571. halbtc8821c1ant_table(btc, NM_EXCU, 7);
  2572. else if (coex_sta->bt_coex_supported_feature & BIT(11))
  2573. halbtc8821c1ant_table(btc, NM_EXCU, 1);
  2574. else
  2575. halbtc8821c1ant_table(btc, NM_EXCU, 2);
  2576. if (wifi_busy && coex_sta->wl_noisy_level == 0)
  2577. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 36);
  2578. else if (wifi_busy)
  2579. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 37);
  2580. else
  2581. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 6);
  2582. }
  2583. } else {
  2584. /* for HID exist */
  2585. if (wifi_cckdeadlock_ap &&
  2586. coex_sta->is_hid_low_pri_tx_overhead) {
  2587. halbtc8821c1ant_table(btc, NM_EXCU, 13);
  2588. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 18);
  2589. } else if (coex_sta->is_hid_low_pri_tx_overhead) {
  2590. halbtc8821c1ant_table(btc, NM_EXCU, 1);
  2591. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 18);
  2592. } else if (wifi_bw == 0) { /* if 11bg mode */
  2593. halbtc8821c1ant_table(btc, NM_EXCU, 11);
  2594. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 11);
  2595. } else {
  2596. halbtc8821c1ant_table(btc, NM_EXCU, 1);
  2597. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 11);
  2598. }
  2599. }
  2600. }
  2601. static
  2602. void halbtc8821c1ant_action_bt_acl_busy(struct btc_coexist *btc)
  2603. {
  2604. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  2605. struct btc_bt_link_info *bt_link_info = &btc->bt_link_info;
  2606. boolean wifi_busy = FALSE, wifi_turbo = FALSE,
  2607. wifi_cckdeadlock_ap = FALSE, bt_slave_latency = FALSE,
  2608. ap_enable = FALSE;
  2609. u32 wifi_bw = 1;
  2610. u8 iot_peer = BTC_IOT_PEER_UNKNOWN;
  2611. btc->btc_get(btc, BTC_GET_U4_WIFI_BW, &wifi_bw);
  2612. btc->btc_get(btc, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  2613. btc->btc_get(btc, BTC_GET_U1_AP_NUM, &coex_sta->scan_ap_num);
  2614. btc->btc_get(btc, BTC_GET_U1_IOT_PEER, &iot_peer);
  2615. btc->btc_get(btc, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &ap_enable);
  2616. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2617. "############# [BTCoex], scan_ap_num = %d, wl_noisy_level = %d\n",
  2618. coex_sta->scan_ap_num, coex_sta->wl_noisy_level);
  2619. BTC_TRACE(trace_buf);
  2620. if (!wifi_busy)
  2621. wifi_busy = coex_sta->gl_wifi_busy;
  2622. if (wifi_busy && coex_sta->wl_noisy_level == 0)
  2623. wifi_turbo = TRUE;
  2624. if (iot_peer == BTC_IOT_PEER_ATHEROS && coex_sta->cck_lock_ever)
  2625. wifi_cckdeadlock_ap = TRUE;
  2626. if (coex_sta->bt_coex_supported_feature & BIT(11))
  2627. bt_slave_latency = TRUE;
  2628. else
  2629. bt_slave_latency = FALSE;
  2630. if (bt_link_info->a2dp_exist && coex_sta->is_bt_a2dp_sink) {
  2631. if (ap_enable)
  2632. halbtc8821c1ant_table(btc, NM_EXCU, 0);
  2633. else if (coex_sta->wl_noisy_level == 0 && wifi_cckdeadlock_ap)
  2634. halbtc8821c1ant_table(btc, NM_EXCU, 13);
  2635. else
  2636. halbtc8821c1ant_table(btc, NM_EXCU, 1);
  2637. if (ap_enable)
  2638. halbtc8821c1ant_tdma(btc, NM_EXCU, FALSE, 8);
  2639. else
  2640. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 12);
  2641. } else if (bt_link_info->a2dp_only) { /* A2DP */
  2642. if (wifi_busy && (coex_sta->bt_ble_scan_type & 0x2)) {
  2643. if (coex_sta->wl_noisy_level == 0 &&
  2644. wifi_cckdeadlock_ap)
  2645. halbtc8821c1ant_table(btc, NM_EXCU, 10);
  2646. else if (coex_sta->wl_noisy_level == 0 &&
  2647. !wifi_cckdeadlock_ap)
  2648. halbtc8821c1ant_table(btc, NM_EXCU, 9);
  2649. else
  2650. halbtc8821c1ant_table(btc, NM_EXCU, 1);
  2651. } else if (wifi_busy && !(coex_sta->bt_ble_scan_type & 0x2)) {
  2652. if (coex_sta->wl_noisy_level == 0 &&
  2653. wifi_cckdeadlock_ap)
  2654. halbtc8821c1ant_table(btc, NM_EXCU, 13);
  2655. else
  2656. halbtc8821c1ant_table(btc, NM_EXCU, 1);
  2657. } else { /* wifi idle */
  2658. halbtc8821c1ant_table(btc, NM_EXCU, 7);
  2659. }
  2660. if (coex_sta->connect_ap_period_cnt > 0 || !wifi_busy)
  2661. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 26);
  2662. else
  2663. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 7);
  2664. } else if ((bt_link_info->a2dp_exist && bt_link_info->pan_exist) ||
  2665. (bt_link_info->hid_exist && bt_link_info->a2dp_exist &&
  2666. bt_link_info->pan_exist)) {
  2667. /* A2DP+PAN(OPP,FTP), HID+A2DP+PAN(OPP,FTP) */
  2668. if (coex_sta->wl_noisy_level == 0 && wifi_cckdeadlock_ap)
  2669. halbtc8821c1ant_table(btc, NM_EXCU, 13);
  2670. else if (bt_link_info->hid_exist)
  2671. halbtc8821c1ant_table(btc, NM_EXCU, 1);
  2672. else if (wifi_turbo)
  2673. halbtc8821c1ant_table(btc, NM_EXCU, 8);
  2674. else
  2675. halbtc8821c1ant_table(btc, NM_EXCU, 4);
  2676. if (wifi_busy)
  2677. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 13);
  2678. else
  2679. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 14);
  2680. } else if (bt_link_info->hid_exist && coex_sta->is_hid_rcu &&
  2681. coex_sta->voice_over_HOGP && bt_link_info->a2dp_exist) {
  2682. /* RCU voice + A2DP */
  2683. /* change coex table if slave latency support or not */
  2684. if (wifi_busy && !bt_slave_latency) {
  2685. if (coex_sta->wl_noisy_level == 0 &&
  2686. wifi_cckdeadlock_ap)
  2687. halbtc8821c1ant_table(btc, NM_EXCU, 10);
  2688. else if (coex_sta->wl_noisy_level == 0 &&
  2689. !wifi_cckdeadlock_ap)
  2690. halbtc8821c1ant_table(btc, NM_EXCU, 9);
  2691. else
  2692. halbtc8821c1ant_table(btc, NM_EXCU, 1);
  2693. } else if (wifi_busy && bt_slave_latency) {
  2694. if (coex_sta->wl_noisy_level == 0 &&
  2695. wifi_cckdeadlock_ap)
  2696. halbtc8821c1ant_table(btc, NM_EXCU, 13);
  2697. else
  2698. halbtc8821c1ant_table(btc, NM_EXCU, 1);
  2699. } else { /* wifi idle */
  2700. halbtc8821c1ant_table(btc, NM_EXCU, 7);
  2701. }
  2702. if (coex_sta->connect_ap_period_cnt > 0 || !wifi_busy)
  2703. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 10);
  2704. else
  2705. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 13);
  2706. } else if (bt_link_info->hid_exist && coex_sta->is_hid_rcu &&
  2707. bt_link_info->a2dp_exist) {
  2708. /* RCU + A2DP */
  2709. /* change coex table if slave latency support or not */
  2710. if (wifi_busy && !bt_slave_latency) {
  2711. if (coex_sta->wl_noisy_level == 0 &&
  2712. wifi_cckdeadlock_ap)
  2713. halbtc8821c1ant_table(btc, NM_EXCU, 10);
  2714. else if (coex_sta->wl_noisy_level == 0 &&
  2715. !wifi_cckdeadlock_ap)
  2716. halbtc8821c1ant_table(btc, NM_EXCU, 9);
  2717. else
  2718. halbtc8821c1ant_table(btc, NM_EXCU, 1);
  2719. } else if (wifi_busy && bt_slave_latency) {
  2720. if (coex_sta->wl_noisy_level == 0 &&
  2721. wifi_cckdeadlock_ap)
  2722. halbtc8821c1ant_table(btc, NM_EXCU, 13);
  2723. else
  2724. halbtc8821c1ant_table(btc, NM_EXCU, 1);
  2725. } else { /* wifi idle */
  2726. halbtc8821c1ant_table(btc, NM_EXCU, 7);
  2727. }
  2728. if (coex_sta->connect_ap_period_cnt > 0 || !wifi_busy)
  2729. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 26);
  2730. else
  2731. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 7);
  2732. } else if (bt_link_info->hid_exist && bt_link_info->a2dp_exist) {
  2733. /* HID+A2DP */
  2734. if (coex_sta->wl_noisy_level == 0 && wifi_cckdeadlock_ap)
  2735. halbtc8821c1ant_table(btc, NM_EXCU, 13);
  2736. else if (wifi_bw == 0)/* if 11bg mode */
  2737. halbtc8821c1ant_table(btc, NM_EXCU, 12);
  2738. else
  2739. halbtc8821c1ant_table(btc, NM_EXCU, 1);
  2740. if (coex_sta->connect_ap_period_cnt > 0 || !wifi_busy)
  2741. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 26);
  2742. else
  2743. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 7);
  2744. } else if (bt_link_info->pan_only ||
  2745. (bt_link_info->hid_exist && bt_link_info->pan_exist)) {
  2746. /* PAN(OPP,FTP), HID+PAN(OPP,FTP) */
  2747. if (coex_sta->wl_noisy_level == 0 && wifi_cckdeadlock_ap)
  2748. halbtc8821c1ant_table(btc, NM_EXCU, 13);
  2749. else if (bt_link_info->hid_exist)
  2750. halbtc8821c1ant_table(btc, NM_EXCU, 1);
  2751. else if (wifi_turbo || iot_peer == BTC_IOT_PEER_CISCO)
  2752. halbtc8821c1ant_table(btc, NM_EXCU, 8);
  2753. else
  2754. halbtc8821c1ant_table(btc, NM_EXCU, 4);
  2755. if (!wifi_busy)
  2756. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 4);
  2757. else
  2758. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 3);
  2759. } else {
  2760. /* BT no-profile busy (0x9) */
  2761. halbtc8821c1ant_table(btc, NM_EXCU, 4);
  2762. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 33);
  2763. }
  2764. }
  2765. static
  2766. void halbtc8821c1ant_action_bt_mr(struct btc_coexist *btc)
  2767. {
  2768. struct wifi_link_info_8821c_1ant *wifi_link_info_ext =
  2769. &btc->wifi_link_info_8821c_1ant;
  2770. if (!wifi_link_info_ext->is_all_under_5g) {
  2771. halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, NM_EXCU,
  2772. BT_8821C_1ANT_PHASE_2G);
  2773. halbtc8821c1ant_table(btc, NM_EXCU, 8);
  2774. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 32);
  2775. } else {
  2776. halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, NM_EXCU,
  2777. BT_8821C_1ANT_PHASE_5G);
  2778. halbtc8821c1ant_table(btc, NM_EXCU, 0);
  2779. halbtc8821c1ant_tdma(btc, NM_EXCU, FALSE, 8);
  2780. }
  2781. }
  2782. static
  2783. void halbtc8821c1ant_action_wifi_under5g(struct btc_coexist *btc)
  2784. {
  2785. halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, NM_EXCU,
  2786. BT_8821C_1ANT_PHASE_5G);
  2787. halbtc8821c1ant_table(btc, NM_EXCU, 0);
  2788. halbtc8821c1ant_tdma(btc, NM_EXCU, FALSE, 8);
  2789. }
  2790. static
  2791. void halbtc8821c1ant_action_wifi_only(struct btc_coexist *btc)
  2792. {
  2793. halbtc8821c1ant_table(btc, FC_EXCU, 10);
  2794. halbtc8821c1ant_tdma(btc, FC_EXCU, FALSE, 8);
  2795. }
  2796. static
  2797. void halbtc8821c1ant_action_wifi_native_lps(struct btc_coexist *btc)
  2798. {
  2799. halbtc8821c1ant_table(btc, NM_EXCU, 5);
  2800. halbtc8821c1ant_tdma(btc, NM_EXCU, FALSE, 8);
  2801. }
  2802. #if 0
  2803. static
  2804. void halbtc8821c1ant_action_wifi_cck_dead_lock(struct btc_coexist *btc)
  2805. {
  2806. struct btc_bt_link_info *bt_link_info = &btc->bt_link_info;
  2807. if (bt_link_info->hid_exis && bt_link_info->a2dp_exist &&
  2808. !bt_link_info->pan_exist) {
  2809. if (coex_sta->cck_lock || coex_sta->cck_lock_warn) {
  2810. halbtc8821c1ant_table(btc, NM_EXCU, 13);
  2811. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 28);
  2812. } else {
  2813. halbtc8821c1ant_table(btc, NM_EXCU, 13);
  2814. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 8);
  2815. }
  2816. }
  2817. }
  2818. #endif
  2819. static
  2820. void halbtc8821c1ant_action_wifi_linkscan(struct btc_coexist *btc)
  2821. {
  2822. struct btc_bt_link_info *bt_link_info = &btc->bt_link_info;
  2823. if (bt_link_info->pan_exist) {
  2824. halbtc8821c1ant_table(btc, NM_EXCU, 4);
  2825. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 22);
  2826. } else if (bt_link_info->a2dp_exist) {
  2827. halbtc8821c1ant_table(btc, NM_EXCU, 4);
  2828. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 27);
  2829. } else {
  2830. halbtc8821c1ant_table(btc, NM_EXCU, 4);
  2831. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 21);
  2832. }
  2833. }
  2834. static
  2835. void halbtc8821c1ant_action_wifi_not_connected(struct btc_coexist *btc)
  2836. {
  2837. /* tdma and coex table */
  2838. halbtc8821c1ant_table(btc, NM_EXCU, 0);
  2839. halbtc8821c1ant_tdma(btc, FC_EXCU, FALSE, 8);
  2840. }
  2841. static
  2842. void halbtc8821c1ant_action_wifi_connected(struct btc_coexist *btc)
  2843. {
  2844. struct btc_bt_link_info *bt_link_info = &btc->bt_link_info;
  2845. struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
  2846. u32 wifi_bw;
  2847. u8 iot_peer = BTC_IOT_PEER_UNKNOWN, algorithm;
  2848. btc->btc_get(btc, BTC_GET_U4_WIFI_BW, &wifi_bw);
  2849. if (bt_link_info->bt_link_exist) {
  2850. btc->btc_get(btc, BTC_GET_U1_IOT_PEER, &iot_peer);
  2851. if (iot_peer == BTC_IOT_PEER_CISCO) {
  2852. if (wifi_bw == BTC_WIFI_BW_HT40)
  2853. halbtc8821c1ant_limited_rx(btc, NM_EXCU, FALSE,
  2854. TRUE, 0x10);
  2855. else
  2856. halbtc8821c1ant_limited_rx(btc, NM_EXCU, FALSE,
  2857. TRUE, 0x8);
  2858. }
  2859. }
  2860. algorithm = halbtc8821c1ant_action_algorithm(btc);
  2861. coex_dm->cur_algorithm = algorithm;
  2862. if (coex_dm->bt_status == BT_8821C_1ANT_BSTATUS_ACL_BUSY ||
  2863. coex_dm->bt_status == BT_8821C_1ANT_BSTATUS_ACL_SCO_BUSY) {
  2864. if (bt_link_info->hid_only) /* HID only */
  2865. halbtc8821c1ant_action_bt_sco_hid_busy(btc);
  2866. else
  2867. halbtc8821c1ant_action_bt_acl_busy(btc);
  2868. } else if (coex_dm->bt_status == BT_8821C_1ANT_BSTATUS_SCO_BUSY) {
  2869. halbtc8821c1ant_action_bt_sco_hid_busy(btc);
  2870. } else {
  2871. halbtc8821c1ant_action_bt_idle(btc);
  2872. }
  2873. }
  2874. static
  2875. void halbtc8821c1ant_action_wifi_multiport25g(struct btc_coexist *btc)
  2876. {
  2877. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  2878. struct btc_bt_link_info *bt_link_info = &btc->bt_link_info;
  2879. halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, NM_EXCU,
  2880. BT_8821C_1ANT_PHASE_MCC);
  2881. halbtc8821c1ant_write_scbd(btc, BT_8821C_1ANT_SCBD_BTCQDDR, TRUE);
  2882. if (coex_sta->is_setup_link || coex_sta->bt_relink_downcount != 0) {
  2883. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2884. "[BTCoex], wifi_multiport25g(), BT Relink!!\n");
  2885. BTC_TRACE(trace_buf);
  2886. halbtc8821c1ant_table(btc, NM_EXCU, 15);
  2887. halbtc8821c1ant_tdma(btc, NM_EXCU, FALSE, 8);
  2888. } else if (coex_sta->c2h_bt_inquiry_page) {
  2889. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2890. "[BTCoex], wifi_multiport25g(), BT Inq-Page!!\n");
  2891. BTC_TRACE(trace_buf);
  2892. halbtc8821c1ant_table(btc, NM_EXCU, 15);
  2893. halbtc8821c1ant_tdma(btc, NM_EXCU, FALSE, 8);
  2894. } else {
  2895. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2896. "[BTCoex], wifi_multiport25g(), BT idle or busy!!\n");
  2897. BTC_TRACE(trace_buf);
  2898. halbtc8821c1ant_table(btc, NM_EXCU, 15);
  2899. halbtc8821c1ant_tdma(btc, NM_EXCU, FALSE, 8);
  2900. }
  2901. }
  2902. static
  2903. void halbtc8821c1ant_action_wifi_multiport2g(struct btc_coexist *btc)
  2904. {
  2905. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  2906. struct btc_bt_link_info *bt_link_info = &btc->bt_link_info;
  2907. struct btc_multi_port_tdma_info multiport_tdma_para;
  2908. u32 traffic_dir;
  2909. halbtc8821c1ant_write_scbd(btc, BT_8821C_1ANT_SCBD_BTCQDDR, TRUE);
  2910. btc->btc_get(btc, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &traffic_dir);
  2911. if (coex_sta->is_setup_link || coex_sta->bt_relink_downcount != 0) {
  2912. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2913. "[BTCoex], wifi_multiport2g, BT Relink!!\n");
  2914. BTC_TRACE(trace_buf);
  2915. halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, NM_EXCU,
  2916. BT_8821C_1ANT_PHASE_2G);
  2917. halbtc8821c1ant_table(btc, NM_EXCU, 0);
  2918. halbtc8821c1ant_tdma(btc, NM_EXCU, FALSE, 8);
  2919. } else if (coex_sta->c2h_bt_inquiry_page) {
  2920. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2921. "[BTCoex], wifi_multiport2g, BT Inq-Page!!\n");
  2922. BTC_TRACE(trace_buf);
  2923. halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, NM_EXCU,
  2924. BT_8821C_1ANT_PHASE_2G);
  2925. halbtc8821c1ant_table(btc, NM_EXCU, 1);
  2926. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 33);
  2927. } else if (coex_sta->num_of_profile == 0) {
  2928. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2929. "[BTCoex], wifi_multiport2g, BT idle!!\n");
  2930. BTC_TRACE(trace_buf);
  2931. halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, NM_EXCU,
  2932. BT_8821C_1ANT_PHASE_2G);
  2933. /* for P2P-GO only A2DP sink */
  2934. if (btc->wifi_link_info.link_mode == BTC_LINK_ONLY_GO &&
  2935. traffic_dir == BTC_WIFI_TRAFFIC_RX) {
  2936. halbtc8821c1ant_table(btc, NM_EXCU, 2);
  2937. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 33);
  2938. } else {
  2939. halbtc8821c1ant_table(btc, NM_EXCU, 0);
  2940. halbtc8821c1ant_tdma(btc, NM_EXCU, FALSE, 8);
  2941. }
  2942. } else if (coex_sta->is_wifi_linkscan_process) {
  2943. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2944. "[BTCoex], wifi_multiport2g, WL scan!!\n");
  2945. BTC_TRACE(trace_buf);
  2946. halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, NM_EXCU,
  2947. BT_8821C_1ANT_PHASE_2G);
  2948. halbtc8821c1ant_action_wifi_linkscan(btc);
  2949. } else {
  2950. halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, NM_EXCU,
  2951. BT_8821C_1ANT_PHASE_2G);
  2952. if (!coex_sta->is_bt_multi_link &&
  2953. (bt_link_info->sco_exist || bt_link_info->hid_exist ||
  2954. coex_sta->is_hid_rcu)) {
  2955. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2956. "[BTCoex], wifi_multiport2g, 2G multi-port + BT HID/HFP/RCU!!\n");
  2957. BTC_TRACE(trace_buf);
  2958. halbtc8821c1ant_table(btc, NM_EXCU, 0);
  2959. halbtc8821c1ant_tdma(btc, NM_EXCU, FALSE, 8);
  2960. } else {
  2961. switch (btc->wifi_link_info.link_mode) {
  2962. #if 0
  2963. case BTC_LINK_2G_SCC_GO_STA:
  2964. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2965. "[BTCoex], wifi_multiport2g, 2G_SCC_GO_STA + BT busy!!\n");
  2966. BTC_TRACE(trace_buf);
  2967. halbtc8821c1ant_table(btc, NM_EXCU, 4);
  2968. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 201);
  2969. break;
  2970. case BTC_LINK_ONLY_GO:
  2971. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2972. "[BTCoex], wifi_singleport2g, Only_P2PGO with client-join + BT busy!!\n");
  2973. BTC_TRACE(trace_buf);
  2974. halbtc8821c1ant_table(btc, NM_EXCU, 4);
  2975. halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 202);
  2976. break;
  2977. #endif
  2978. default:
  2979. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2980. "[BTCoex], wifi_multiport2g, Other multi-port + BT busy!!\n");
  2981. BTC_TRACE(trace_buf);
  2982. if (bt_link_info->a2dp_exist)
  2983. halbtc8821c1ant_table(btc, NM_EXCU, 0);
  2984. else
  2985. halbtc8821c1ant_table(btc, NM_EXCU, 5);
  2986. halbtc8821c1ant_tdma(btc, NM_EXCU, FALSE, 8);
  2987. break;
  2988. }
  2989. }
  2990. }
  2991. }
  2992. static
  2993. void halbtc8821c1ant_run_coex(struct btc_coexist *btc, u8 reason)
  2994. {
  2995. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  2996. struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
  2997. struct wifi_link_info_8821c_1ant *wifi_link_info_ext =
  2998. &btc->wifi_link_info_8821c_1ant;
  2999. boolean wifi_connected = FALSE, wifi_32k = FALSE;
  3000. boolean scan = FALSE, link = FALSE, roam = FALSE, under_4way = FALSE;
  3001. btc->btc_get(btc, BTC_GET_BL_WIFI_SCAN, &scan);
  3002. btc->btc_get(btc, BTC_GET_BL_WIFI_LINK, &link);
  3003. btc->btc_get(btc, BTC_GET_BL_WIFI_ROAM, &roam);
  3004. btc->btc_get(btc, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &under_4way);
  3005. btc->btc_get(btc, BTC_GET_BL_WIFI_CONNECTED, &wifi_connected);
  3006. btc->btc_get(btc, BTC_GET_BL_WIFI_LW_PWR_STATE, &wifi_32k);
  3007. if (scan || link || roam || under_4way ||
  3008. reason == BT_8821C_1ANT_RSN_2GSCANSTART ||
  3009. reason == BT_8821C_1ANT_RSN_2GSWITCHBAND ||
  3010. reason == BT_8821C_1ANT_RSN_2GCONSTART ||
  3011. reason == BT_8821C_1ANT_RSN_2GSPECIALPKT) {
  3012. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3013. "[BTCoex], scan = %d, link = %d, roam = %d 4way = %d!!!\n",
  3014. scan, link, roam, under_4way);
  3015. BTC_TRACE(trace_buf);
  3016. coex_sta->is_wifi_linkscan_process = TRUE;
  3017. } else {
  3018. coex_sta->is_wifi_linkscan_process = FALSE;
  3019. }
  3020. /* update wifi_link_info variable */
  3021. halbtc8821c1ant_update_wifi_link_info(btc, reason);
  3022. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3023. "[BTCoex], RunCoexistMechanism()===> reason = %d\n",
  3024. reason);
  3025. BTC_TRACE(trace_buf);
  3026. if (btc->manual_control) {
  3027. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3028. "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
  3029. BTC_TRACE(trace_buf);
  3030. return;
  3031. }
  3032. if (btc->stop_coex_dm) {
  3033. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3034. "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n");
  3035. BTC_TRACE(trace_buf);
  3036. return;
  3037. }
  3038. if (coex_sta->under_ips) {
  3039. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3040. "[BTCoex], RunCoexistMechanism(), return for wifi is under IPS !!!\n");
  3041. BTC_TRACE(trace_buf);
  3042. return;
  3043. }
  3044. if (coex_sta->under_lps && wifi_32k) {
  3045. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3046. "[BTCoex], RunCoexistMechanism(), return for wifi is under LPS-32K !!!\n");
  3047. BTC_TRACE(trace_buf);
  3048. return;
  3049. }
  3050. if (!coex_sta->run_time_state) {
  3051. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3052. "[BTCoex], return for run_time_state = FALSE !!!\n");
  3053. BTC_TRACE(trace_buf);
  3054. return;
  3055. }
  3056. if (coex_sta->freeze_coexrun_by_btinfo && !coex_sta->is_setup_link) {
  3057. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3058. "[BTCoex], return for freeze_coexrun_by_btinfo\n");
  3059. BTC_TRACE(trace_buf);
  3060. return;
  3061. }
  3062. coex_sta->coex_run_cnt++;
  3063. if (coex_sta->msft_mr_exist && wifi_connected) {
  3064. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3065. "[BTCoex], RunCoexistMechanism(), microsoft MR!!\n");
  3066. BTC_TRACE(trace_buf);
  3067. coex_sta->wl_coex_mode = BT_8821C_1ANT_WLINK_BTMR;
  3068. halbtc8821c1ant_action_bt_mr(btc);
  3069. return;
  3070. }
  3071. if (wifi_link_info_ext->is_all_under_5g) {
  3072. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3073. "[BTCoex], WiFi is under 5G!!!\n");
  3074. BTC_TRACE(trace_buf);
  3075. coex_sta->wl_coex_mode = BT_8821C_1ANT_WLINK_5G;
  3076. halbtc8821c1ant_action_wifi_under5g(btc);
  3077. return;
  3078. }
  3079. if (wifi_link_info_ext->is_mcc_25g) { /* not iclude scan action */
  3080. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3081. "[BTCoex], WiFi is under mcc dual-band!!!\n");
  3082. BTC_TRACE(trace_buf);
  3083. coex_sta->wl_coex_mode = BT_8821C_1ANT_WLINK_25GMPORT;
  3084. halbtc8821c1ant_action_wifi_multiport25g(btc);
  3085. return;
  3086. }
  3087. if (wifi_link_info_ext->num_of_active_port > 1 ||
  3088. (btc->wifi_link_info.link_mode == BTC_LINK_ONLY_GO &&
  3089. !btc->wifi_link_info.bhotspot &&
  3090. btc->wifi_link_info.bany_client_join_go)) {
  3091. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3092. "[BTCoex], WiFi is under scc-2g/mcc-2g/p2pGO-only!!!\n");
  3093. BTC_TRACE(trace_buf);
  3094. if (btc->wifi_link_info.link_mode ==
  3095. BTC_LINK_ONLY_GO)
  3096. coex_sta->wl_coex_mode = BT_8821C_1ANT_WLINK_2GGO;
  3097. else
  3098. coex_sta->wl_coex_mode = BT_8821C_1ANT_WLINK_2GMPORT;
  3099. halbtc8821c1ant_action_wifi_multiport2g(btc);
  3100. return;
  3101. }
  3102. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3103. "[BTCoex], WiFi is single-port 2G!!!\n");
  3104. BTC_TRACE(trace_buf);
  3105. coex_sta->wl_coex_mode = BT_8821C_1ANT_WLINK_2G1PORT;
  3106. halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, NM_EXCU,
  3107. BT_8821C_1ANT_PHASE_2G);
  3108. halbtc8821c1ant_write_scbd(btc, BT_8821C_1ANT_SCBD_BTCQDDR, TRUE);
  3109. if (coex_sta->bt_disabled) {
  3110. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3111. "[BTCoex], BT is disabled !!!\n");
  3112. BTC_TRACE(trace_buf);
  3113. halbtc8821c1ant_action_wifi_only(btc);
  3114. return;
  3115. }
  3116. if (coex_sta->under_lps && !coex_sta->force_lps_ctrl &&
  3117. !coex_sta->acl_busy) {
  3118. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3119. "[BTCoex], RunCoexistMechanism(), wifi is under LPS !!!\n");
  3120. BTC_TRACE(trace_buf);
  3121. halbtc8821c1ant_action_wifi_native_lps(btc);
  3122. return;
  3123. }
  3124. if (coex_sta->bt_whck_test) {
  3125. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3126. "[BTCoex], BT is under WHCK TEST!!!\n");
  3127. BTC_TRACE(trace_buf);
  3128. halbtc8821c1ant_action_bt_whql_test(btc);
  3129. return;
  3130. }
  3131. if (coex_sta->is_setup_link || coex_sta->bt_relink_downcount != 0) {
  3132. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3133. "[BTCoex], BT is re-link !!!\n");
  3134. BTC_TRACE(trace_buf);
  3135. halbtc8821c1ant_action_bt_relink(btc);
  3136. return;
  3137. }
  3138. if (coex_sta->c2h_bt_inquiry_page) {
  3139. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3140. "[BTCoex], BT is under inquiry/page scan !!\n");
  3141. BTC_TRACE(trace_buf);
  3142. halbtc8821c1ant_action_bt_inquiry(btc);
  3143. return;
  3144. }
  3145. if (coex_dm->bt_status == BT_8821C_1ANT_BSTATUS_NCON_IDLE ||
  3146. coex_dm->bt_status == BT_8821C_1ANT_BSTATUS_CON_IDLE) {
  3147. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3148. "############# [BTCoex], BT Is idle\n");
  3149. BTC_TRACE(trace_buf);
  3150. halbtc8821c1ant_action_bt_idle(btc);
  3151. return;
  3152. }
  3153. if (coex_sta->is_wifi_linkscan_process) {
  3154. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3155. "[BTCoex], wifi is under linkscan process!!\n");
  3156. BTC_TRACE(trace_buf);
  3157. halbtc8821c1ant_action_wifi_linkscan(btc);
  3158. return;
  3159. }
  3160. if (wifi_connected) {
  3161. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3162. "[BTCoex], wifi is under connected!!\n");
  3163. BTC_TRACE(trace_buf);
  3164. halbtc8821c1ant_action_wifi_connected(btc);
  3165. } else {
  3166. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3167. "[BTCoex], wifi is under not-connected!!\n");
  3168. BTC_TRACE(trace_buf);
  3169. halbtc8821c1ant_action_wifi_not_connected(btc);
  3170. }
  3171. }
  3172. static
  3173. void halbtc8821c1ant_init_coex_dm(struct btc_coexist *btc)
  3174. {
  3175. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  3176. struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
  3177. /* force to reset coex mechanism */
  3178. halbtc8821c1ant_low_penalty_ra(btc, FC_EXCU, FALSE, 0);
  3179. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3180. "[BTCoex], Coex Mechanism Init!!\n");
  3181. BTC_TRACE(trace_buf);
  3182. coex_sta->pop_event_cnt = 0;
  3183. coex_sta->cnt_remote_name_req = 0;
  3184. coex_sta->cnt_reinit = 0;
  3185. coex_sta->cnt_setup_link = 0;
  3186. coex_sta->cnt_ign_wlan_act = 0;
  3187. coex_sta->cnt_page = 0;
  3188. coex_sta->cnt_role_switch = 0;
  3189. coex_sta->switch_band_notify_to = BTC_NOT_SWITCH;
  3190. coex_dm->setting_tdma = FALSE;
  3191. halbtc8821c1ant_query_bt_info(btc);
  3192. }
  3193. static
  3194. void halbtc8821c1ant_init_hw_config(struct btc_coexist *btc, boolean back_up,
  3195. boolean wifi_only)
  3196. {
  3197. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  3198. u32 u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0;
  3199. u16 u16tmp1 = 0;
  3200. u8 i;
  3201. struct btc_board_info *board_info = &btc->board_info;
  3202. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3203. "[BTCoex], 1Ant Init HW Config!!\n");
  3204. BTC_TRACE(trace_buf);
  3205. u32tmp3 = btc->btc_read_4byte(btc, 0xcb4);
  3206. u32tmp1 = halbtc8821c1ant_read_indirect_reg(btc, 0x38);
  3207. u32tmp2 = halbtc8821c1ant_read_indirect_reg(btc, 0x54);
  3208. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3209. "[BTCoex],(Before Init HW config) 0xcb4 = 0x%x, 0x38= 0x%x, 0x54= 0x%x\n",
  3210. u32tmp3, u32tmp1, u32tmp2);
  3211. BTC_TRACE(trace_buf);
  3212. #if 0
  3213. coex_sta->bt_coex_supported_feature = 0;
  3214. coex_sta->bt_coex_supported_version = 0;
  3215. coex_sta->bt_ble_scan_type = 0;
  3216. coex_sta->bt_ble_scan_para[0] = 0;
  3217. coex_sta->bt_ble_scan_para[1] = 0;
  3218. coex_sta->bt_ble_scan_para[2] = 0;
  3219. #endif
  3220. coex_sta->bt_reg_vendor_ac = 0xffff;
  3221. coex_sta->bt_reg_vendor_ae = 0xffff;
  3222. coex_sta->isolation_btween_wb = BT_8821C_1ANT_DEFAULT_ISOLATION;
  3223. coex_sta->gnt_error_cnt = 0;
  3224. coex_sta->bt_relink_downcount = 0;
  3225. coex_sta->is_set_ps_state_fail = FALSE;
  3226. coex_sta->cnt_set_ps_state_fail = 0;
  3227. coex_sta->wl_rx_rate = BTC_UNKNOWN;
  3228. coex_sta->wl_rts_rx_rate = BTC_UNKNOWN;
  3229. coex_sta->wl_center_channel = 0;
  3230. coex_sta->coex_run_cnt = 0;
  3231. for (i = 0; i <= 9; i++)
  3232. coex_sta->bt_afh_map[i] = 0;
  3233. /* Setup RF front end type */
  3234. halbtc8821c1ant_set_rfe_type(btc);
  3235. /* 0xf0[15:12] --> Chip Cut information */
  3236. coex_sta->cut_version = (btc->btc_read_1byte(btc, 0xf1) & 0xf0) >> 4;
  3237. /* enable TBTT nterrupt */
  3238. btc->btc_write_1byte_bitmask(btc, 0x550, 0x8, 0x1);
  3239. /* BT report packet sample rate */
  3240. btc->btc_write_1byte(btc, 0x790, 0x5);
  3241. /* Init 0x778 = 0x1 for 1-Ant */
  3242. btc->btc_write_1byte(btc, 0x778, 0x1);
  3243. /* Enable PTA (3-wire function form BT side) */
  3244. btc->btc_write_1byte_bitmask(btc, 0x40, 0x20, 0x1);
  3245. btc->btc_write_1byte_bitmask(btc, 0x41, 0x02, 0x1);
  3246. /* Enable PTA (tx/rx signal form WiFi side) */
  3247. btc->btc_write_1byte_bitmask(btc, 0x4c6, 0x10, 0x1);
  3248. /* set GNT_BT=1 for coex table select both */
  3249. btc->btc_write_1byte_bitmask(btc, 0x763, 0x10, 0x1);
  3250. halbtc8821c1ant_enable_gnt_to_gpio(btc, TRUE);
  3251. #if 0
  3252. /* check if WL firmware download ok */
  3253. /*if (btc->btc_read_1byte(btc, 0x80) == 0xc6)*/
  3254. halbtc8821c1ant_write_scbd(btc, BT_8821C_1ANT_SCBD_ONOFF, TRUE);
  3255. #endif
  3256. /* PTA parameter */
  3257. halbtc8821c1ant_table(btc, FC_EXCU, 0);
  3258. halbtc8821c1ant_tdma(btc, FC_EXCU, FALSE, 8);
  3259. /* Antenna config */
  3260. if (coex_sta->is_rf_state_off) {
  3261. halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, FC_EXCU,
  3262. BT_8821C_1ANT_PHASE_WOFF);
  3263. btc->stop_coex_dm = TRUE;
  3264. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3265. "[BTCoex], ********** %s (RF Off)**********\n",
  3266. __func__);
  3267. BTC_TRACE(trace_buf);
  3268. } else if (wifi_only) {
  3269. coex_sta->concurrent_rx_mode_on = FALSE;
  3270. halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_WIFI, FC_EXCU,
  3271. BT_8821C_1ANT_PHASE_WONLY);
  3272. btc->stop_coex_dm = TRUE;
  3273. } else {
  3274. /*Set BT polluted packet on for Tx rate adaptive not including Tx retry break by PTA, 0x45c[19] =1 */
  3275. btc->btc_write_1byte_bitmask(btc, 0x45e, 0x8, 0x1);
  3276. coex_sta->concurrent_rx_mode_on = TRUE;
  3277. btc->btc_set_rf_reg(btc, BTC_RF_A, 0x1, 0x2, 0x0);
  3278. halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, FC_EXCU,
  3279. BT_8821C_1ANT_PHASE_INIT);
  3280. btc->stop_coex_dm = FALSE;
  3281. }
  3282. u32tmp3 = btc->btc_read_4byte(btc, 0xcb4);
  3283. u32tmp1 = halbtc8821c1ant_read_indirect_reg(btc, 0x38);
  3284. u32tmp2 = halbtc8821c1ant_read_indirect_reg(btc, 0x54);
  3285. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3286. "[BTCoex], (After Init HW config) 0xcb4 = 0x%x, 0x38= 0x%x, 0x54= 0x%x\n",
  3287. u32tmp3, u32tmp1, u32tmp2);
  3288. BTC_TRACE(trace_buf);
  3289. }
  3290. /* ************************************************************
  3291. * work around function start with wa_halbtc8821c1ant_
  3292. * ************************************************************
  3293. * ************************************************************
  3294. * extern function start with ex_halbtc8821c1ant_
  3295. * ************************************************************ */
  3296. void ex_halbtc8821c1ant_power_on_setting(struct btc_coexist *btc)
  3297. {
  3298. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  3299. struct btc_board_info *board_info = &btc->board_info;
  3300. u8 u8tmp = 0x0;
  3301. u16 u16tmp = 0x0;
  3302. u32 value = 0;
  3303. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3304. "[BTCoex], Execute %s !!\n", __func__);
  3305. BTC_TRACE(trace_buf);
  3306. btc->stop_coex_dm = TRUE;
  3307. coex_sta->is_rf_state_off = FALSE;
  3308. /* enable BB, REG_SYS_FUNC_EN such that we can write BB Register correctly. */
  3309. u16tmp = btc->btc_read_2byte(btc, 0x2);
  3310. btc->btc_write_2byte(btc, 0x2, u16tmp | BIT(0) | BIT(1));
  3311. /* Local setting bit define
  3312. * BIT0: "0" for no antenna inverse; "1" for antenna inverse
  3313. * BIT1: "0" for internal switch; "1" for external switch
  3314. * BIT2: "0" for one antenna; "1" for two antenna
  3315. * NOTE: here default all internal switch
  3316. * and 1-antenna ==> BIT1=0 and BIT2=0
  3317. */
  3318. /* Set Antenna Path to BT side */
  3319. /* Check efuse 0xc3[6] for Single Antenna Path */
  3320. if (board_info->single_ant_path == 0) {
  3321. board_info->btdm_ant_pos = BTC_ANTENNA_AT_AUX_PORT;
  3322. u8tmp = 1;
  3323. } else if (board_info->single_ant_path == 1) {
  3324. board_info->btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
  3325. u8tmp = 0;
  3326. }
  3327. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3328. "[BTCoex], (Power On) single_ant_path = %d, btdm_ant_pos = %d\n",
  3329. board_info->single_ant_path , board_info->btdm_ant_pos);
  3330. BTC_TRACE(trace_buf);
  3331. /* Setup RF front end type */
  3332. halbtc8821c1ant_set_rfe_type(btc);
  3333. /* Set Antenna Path to BT side */
  3334. halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, FC_EXCU,
  3335. BT_8821C_1ANT_PHASE_POWERON);
  3336. /* Save"single antenna position" info in Local register setting for
  3337. * FW reading, because FW may not ready at power on
  3338. */
  3339. if (btc->chip_interface == BTC_INTF_PCI)
  3340. btc->btc_write_local_reg_1byte(btc, 0x3e0, u8tmp);
  3341. else if (btc->chip_interface == BTC_INTF_USB)
  3342. btc->btc_write_local_reg_1byte(btc, 0xfe08, u8tmp);
  3343. else if (btc->chip_interface == BTC_INTF_SDIO)
  3344. btc->btc_write_local_reg_1byte(btc, 0x60, u8tmp);
  3345. /* enable GNT_WL/GNT_BT debug signal to GPIO14/15 */
  3346. halbtc8821c1ant_enable_gnt_to_gpio(btc, TRUE);
  3347. if (btc->dbg_mode) {
  3348. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3349. "[BTCoex], LTE coex Reg 0x38 (Power-On) = 0x%x\n",
  3350. halbtc8821c1ant_read_indirect_reg(btc, 0x38));
  3351. BTC_TRACE(trace_buf);
  3352. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3353. "[BTCoex], MACReg 0x70/ BBReg 0xcb4 (Power-On) = 0x%x/ 0x%x\n",
  3354. btc->btc_read_4byte(btc, 0x70),
  3355. btc->btc_read_4byte(btc, 0xcb4));
  3356. BTC_TRACE(trace_buf);
  3357. }
  3358. }
  3359. void ex_halbtc8821c1ant_pre_load_firmware(struct btc_coexist *btc)
  3360. {
  3361. }
  3362. void ex_halbtc8821c1ant_init_hw_config(struct btc_coexist *btc,
  3363. boolean wifi_only)
  3364. {
  3365. halbtc8821c1ant_init_hw_config(btc, TRUE, wifi_only);
  3366. }
  3367. void ex_halbtc8821c1ant_init_coex_dm(struct btc_coexist *btc)
  3368. {
  3369. btc->stop_coex_dm = FALSE;
  3370. btc->auto_report = TRUE;
  3371. btc->dbg_mode = FALSE;
  3372. halbtc8821c1ant_init_coex_dm(btc);
  3373. }
  3374. void ex_halbtc8821c1ant_display_simple_coex_info(struct btc_coexist *btc)
  3375. {
  3376. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  3377. struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
  3378. struct btc_board_info *board_info = &btc->board_info;
  3379. struct btc_bt_link_info *bt_link_info = &btc->bt_link_info;
  3380. u8 *cli_buf = btc->cli_buf;
  3381. u32 bt_patch_ver = 0, bt_coex_ver = 0;
  3382. static u8 cnt;
  3383. u8 * const p = &coex_sta->bt_afh_map[0];
  3384. if (!coex_sta->bt_disabled &&
  3385. (coex_sta->bt_coex_supported_version == 0 ||
  3386. coex_sta->bt_coex_supported_version == 0xffff) &&
  3387. cnt == 0) {
  3388. btc->btc_get(btc, BTC_GET_U4_SUPPORTED_FEATURE,
  3389. &coex_sta->bt_coex_supported_feature);
  3390. btc->btc_get(btc, BTC_GET_U4_SUPPORTED_VERSION,
  3391. &coex_sta->bt_coex_supported_version);
  3392. coex_sta->bt_reg_vendor_ac = (u16)(btc->btc_get_bt_reg(btc, 3,
  3393. 0xac) &
  3394. 0xffff);
  3395. coex_sta->bt_reg_vendor_ae = (u16)(btc->btc_get_bt_reg(btc, 3,
  3396. 0xae) &
  3397. 0xffff);
  3398. btc->btc_get(btc, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
  3399. btc->bt_info.bt_get_fw_ver = bt_patch_ver;
  3400. if (coex_sta->num_of_profile > 0)
  3401. btc->btc_get_bt_afh_map_from_bt(btc, 0, p);
  3402. }
  3403. if (++cnt >= 3)
  3404. cnt = 0;
  3405. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3406. "\r\n _____[BT Coexist info]____");
  3407. CL_PRINTF(cli_buf);
  3408. if (btc->manual_control) {
  3409. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3410. "\r\n __[Under Manual Control]_");
  3411. CL_PRINTF(cli_buf);
  3412. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3413. "\r\n _________________________");
  3414. CL_PRINTF(cli_buf);
  3415. }
  3416. if (btc->stop_coex_dm) {
  3417. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3418. "\r\n ____[Coex is STOPPED]____");
  3419. CL_PRINTF(cli_buf);
  3420. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3421. "\r\n _________________________");
  3422. CL_PRINTF(cli_buf);
  3423. }
  3424. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3425. "\r\n %-35s = %d/ %d/ %s / 0x%x",
  3426. "Ant PG Num/ Mech/ Pos/ RFE",
  3427. board_info->pg_ant_num, board_info->btdm_ant_num,
  3428. (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT
  3429. ? "Main" : "Aux"),
  3430. board_info->rfe_type);
  3431. CL_PRINTF(cli_buf);
  3432. bt_coex_ver = ((coex_sta->bt_coex_supported_version & 0xff00) >> 8);
  3433. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3434. "\r\n %-35s = %d_%02x/ 0x%02x/ 0x%02x (%s)",
  3435. "CoexVer WL/ BT_Desired/ BT_Report",
  3436. glcoex_ver_date_8821c_1ant, glcoex_ver_8821c_1ant,
  3437. glcoex_ver_btdesired_8821c_1ant,
  3438. bt_coex_ver,
  3439. (bt_coex_ver == 0xff ? "Unknown" :
  3440. (coex_sta->bt_disabled ? "BT-disable" :
  3441. (bt_coex_ver >= glcoex_ver_btdesired_8821c_1ant ?
  3442. "Match" : "Mis-Match"))));
  3443. CL_PRINTF(cli_buf);
  3444. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s ", "BT status",
  3445. ((coex_sta->bt_disabled) ? ("disabled") :
  3446. ((coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page")
  3447. : ((BT_8821C_1ANT_BSTATUS_NCON_IDLE ==
  3448. coex_dm->bt_status) ? "non-connected idle" :
  3449. ((BT_8821C_1ANT_BSTATUS_CON_IDLE ==
  3450. coex_dm->bt_status) ? "connected-idle" : "busy")))));
  3451. CL_PRINTF(cli_buf);
  3452. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
  3453. "0x770(Hi-pri rx/tx)",
  3454. coex_sta->high_priority_rx, coex_sta->high_priority_tx);
  3455. CL_PRINTF(cli_buf);
  3456. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d %s",
  3457. "0x774(Lo-pri rx/tx)",
  3458. coex_sta->low_priority_rx, coex_sta->low_priority_tx,
  3459. (bt_link_info->slave_role ? "(Slave!!)" :
  3460. (coex_sta->is_tdma_btautoslot_hang ?
  3461. "(auto-slot hang!!)" : "")));
  3462. CL_PRINTF(cli_buf);
  3463. }
  3464. void ex_halbtc8821c1ant_display_coex_info(struct btc_coexist *btc)
  3465. {
  3466. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  3467. struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
  3468. struct btc_board_info *board_info = &btc->board_info;
  3469. struct btc_bt_link_info *bt_link_info = &btc->bt_link_info;
  3470. u8 *cli_buf = btc->cli_buf;
  3471. u8 u8tmp[4], i, bt_info_ext, ps_tdma_case = 0;
  3472. u16 u16tmp[4];
  3473. u32 u32tmp[4];
  3474. u32 fa_ofdm, fa_cck, cca_ofdm, cca_cck;
  3475. u32 fw_ver = 0, bt_patch_ver = 0, bt_coex_ver = 0;
  3476. static u8 pop_report_in_10s;
  3477. u32 phyver = 0;
  3478. boolean lte_coex_on = FALSE;
  3479. static u8 cnt;
  3480. u8 * const p = &coex_sta->bt_afh_map[0];
  3481. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3482. "\r\n ============[BT Coexist info 8821C]============");
  3483. CL_PRINTF(cli_buf);
  3484. if (btc->manual_control) {
  3485. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3486. "\r\n ============[Under Manual Control]============");
  3487. CL_PRINTF(cli_buf);
  3488. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3489. "\r\n ==========================================");
  3490. CL_PRINTF(cli_buf);
  3491. } else if (btc->stop_coex_dm) {
  3492. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3493. "\r\n ============[Coex is STOPPED]============");
  3494. CL_PRINTF(cli_buf);
  3495. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3496. "\r\n ==========================================");
  3497. CL_PRINTF(cli_buf);
  3498. } else if (!coex_sta->run_time_state) {
  3499. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3500. "\r\n ============[Run Time State = False]============");
  3501. CL_PRINTF(cli_buf);
  3502. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3503. "\r\n ==========================================");
  3504. CL_PRINTF(cli_buf);
  3505. } else if (coex_sta->freeze_coexrun_by_btinfo) {
  3506. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3507. "\r\n ============[freeze_coexrun_by_btinfo]============");
  3508. CL_PRINTF(cli_buf);
  3509. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3510. "\r\n ==========================================");
  3511. CL_PRINTF(cli_buf);
  3512. }
  3513. if (!coex_sta->bt_disabled &&
  3514. (coex_sta->bt_coex_supported_version == 0 ||
  3515. coex_sta->bt_coex_supported_version == 0xffff) &&
  3516. cnt == 0) {
  3517. btc->btc_get(btc, BTC_GET_U4_SUPPORTED_FEATURE,
  3518. &coex_sta->bt_coex_supported_feature);
  3519. btc->btc_get(btc, BTC_GET_U4_SUPPORTED_VERSION,
  3520. &coex_sta->bt_coex_supported_version);
  3521. coex_sta->bt_reg_vendor_ac = (u16)(btc->btc_get_bt_reg(btc, 3,
  3522. 0xac) &
  3523. 0xffff);
  3524. coex_sta->bt_reg_vendor_ae = (u16)(btc->btc_get_bt_reg(btc, 3,
  3525. 0xae) &
  3526. 0xffff);
  3527. btc->btc_get(btc, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
  3528. btc->bt_info.bt_get_fw_ver = bt_patch_ver;
  3529. if (coex_sta->num_of_profile > 0)
  3530. btc->btc_get_bt_afh_map_from_bt(btc, 0, p);
  3531. }
  3532. if (++cnt >= 3)
  3533. cnt = 0;
  3534. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3535. "\r\n %-35s = %d/ %s/ %s / 0x%x",
  3536. "Ant PG Num/ Mech/ Pos/ RFE",
  3537. board_info->pg_ant_num,
  3538. (board_info->btdm_ant_num == 1 ? "Shared" : "Non-Shared"),
  3539. (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT
  3540. ? "Main" : "Aux"),
  3541. board_info->rfe_type);
  3542. CL_PRINTF(cli_buf);
  3543. bt_patch_ver = btc->bt_info.bt_get_fw_ver;
  3544. btc->btc_get(btc, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
  3545. phyver = btc->btc_get_bt_phydm_version(btc);
  3546. bt_coex_ver = ((coex_sta->bt_coex_supported_version & 0xff00) >> 8);
  3547. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3548. "\r\n %-35s = %d_%02x/ 0x%02x/ 0x%02x (%s)",
  3549. "CoexVer WL/ BT_Desired/ BT_Report",
  3550. glcoex_ver_date_8821c_1ant, glcoex_ver_8821c_1ant,
  3551. glcoex_ver_btdesired_8821c_1ant,
  3552. bt_coex_ver,
  3553. (bt_coex_ver == 0xff ? "Unknown" :
  3554. (coex_sta->bt_disabled ? "BT-disable" :
  3555. (bt_coex_ver >= glcoex_ver_btdesired_8821c_1ant ?
  3556. "Match" : "Mis-Match"))));
  3557. CL_PRINTF(cli_buf);
  3558. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3559. "\r\n %-35s = 0x%x/ 0x%x/ v%d/ %c",
  3560. "W_FW/ B_FW/ Phy/ Kt",
  3561. fw_ver, bt_patch_ver, phyver,
  3562. coex_sta->cut_version + 65);
  3563. CL_PRINTF(cli_buf);
  3564. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3565. "\r\n %-35s = %02x %02x %02x (RF-Ch = %d)",
  3566. "AFH Map to BT",
  3567. coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1],
  3568. coex_dm->wifi_chnl_info[2], coex_sta->wl_center_channel);
  3569. CL_PRINTF(cli_buf);
  3570. /* wifi status */
  3571. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  3572. "============[Wifi Status]============");
  3573. CL_PRINTF(cli_buf);
  3574. btc->btc_disp_dbg_msg(btc, BTC_DBG_DISP_WIFI_STATUS);
  3575. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  3576. "============[BT Status]============");
  3577. CL_PRINTF(cli_buf);
  3578. pop_report_in_10s++;
  3579. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3580. "\r\n %-35s = %s/ %ddBm/ %d/ %d",
  3581. "BT status/ rssi/ retryCnt/ popCnt",
  3582. ((coex_sta->bt_disabled) ? ("disabled") :
  3583. ((coex_sta->c2h_bt_inquiry_page) ? ("inquiry-page") :
  3584. ((coex_dm->bt_status == BT_8821C_1ANT_BSTATUS_NCON_IDLE)
  3585. ? "non-connected-idle" :
  3586. ((coex_dm->bt_status == BT_8821C_1ANT_BSTATUS_CON_IDLE)
  3587. ? "connected-idle" : "busy")))),
  3588. coex_sta->bt_rssi - 100, coex_sta->bt_retry_cnt,
  3589. coex_sta->pop_event_cnt);
  3590. CL_PRINTF(cli_buf);
  3591. if (pop_report_in_10s >= 5) {
  3592. coex_sta->pop_event_cnt = 0;
  3593. pop_report_in_10s = 0;
  3594. }
  3595. if (coex_sta->num_of_profile != 0)
  3596. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3597. "\r\n %-35s = %s%s%s%s%s%s (multilink = %d)",
  3598. "Profiles", ((bt_link_info->a2dp_exist) ?
  3599. ((coex_sta->is_bt_a2dp_sink) ?
  3600. "A2DP sink," :
  3601. "A2DP,") :
  3602. ""),
  3603. ((bt_link_info->sco_exist) ? "HFP," : ""),
  3604. ((bt_link_info->hid_exist) ?
  3605. ((coex_sta->is_hid_rcu) ?
  3606. "HID(RCU)" :
  3607. ((coex_sta->hid_busy_num >= 2) ?
  3608. "HID(4/18)," :
  3609. "HID(2/18),")) :
  3610. ""),
  3611. ((bt_link_info->pan_exist) ?
  3612. ((coex_sta->is_bt_opp_exist) ? "OPP," :
  3613. "PAN,") :
  3614. ""),
  3615. ((coex_sta->voice_over_HOGP) ? "Voice," : ""),
  3616. ((coex_sta->msft_mr_exist) ? "MR" : ""),
  3617. coex_sta->is_bt_multi_link);
  3618. else
  3619. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s",
  3620. "Profiles",
  3621. (coex_sta->msft_mr_exist) ? "MR" : "None");
  3622. CL_PRINTF(cli_buf);
  3623. if (bt_link_info->a2dp_exist) {
  3624. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %s",
  3625. "CQDDR/Bitpool/Auto_Slot",
  3626. ((coex_sta->is_A2DP_3M) ? "On" : "Off"),
  3627. coex_sta->a2dp_bit_pool,
  3628. ((coex_sta->is_autoslot) ? "On" : "Off")
  3629. );
  3630. CL_PRINTF(cli_buf);
  3631. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3632. "\r\n %-35s = 0x%x/ 0x%x/ %d/ %d",
  3633. "V_ID/D_name/FBSlot_Legacy/FBSlot_Le",
  3634. coex_sta->bt_a2dp_vendor_id,
  3635. coex_sta->bt_a2dp_device_name,
  3636. coex_sta->legacy_forbidden_slot,
  3637. coex_sta->le_forbidden_slot
  3638. );
  3639. CL_PRINTF(cli_buf);
  3640. }
  3641. if (bt_link_info->hid_exist) {
  3642. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d",
  3643. "HID PairNum",
  3644. coex_sta->hid_pair_cnt);
  3645. CL_PRINTF(cli_buf);
  3646. }
  3647. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %s/ 0x%x",
  3648. "Role/RoleSwCnt/IgnWlact/Feature",
  3649. (bt_link_info->slave_role ? "Slave" : "Master"),
  3650. coex_sta->cnt_role_switch,
  3651. (coex_dm->cur_ignore_wlan_act ? "Yes" : "No"),
  3652. coex_sta->bt_coex_supported_feature);
  3653. CL_PRINTF(cli_buf);
  3654. if (coex_sta->is_ble_scan_en) {
  3655. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3656. "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
  3657. "BLEScan Type/TV/Init/Ble",
  3658. coex_sta->bt_ble_scan_type,
  3659. (coex_sta->bt_ble_scan_type & 0x1 ?
  3660. coex_sta->bt_ble_scan_para[0] : 0x0),
  3661. (coex_sta->bt_ble_scan_type & 0x2 ?
  3662. coex_sta->bt_ble_scan_para[1] : 0x0),
  3663. (coex_sta->bt_ble_scan_type & 0x4 ?
  3664. coex_sta->bt_ble_scan_para[2] : 0x0));
  3665. CL_PRINTF(cli_buf);
  3666. }
  3667. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3668. "\r\n %-35s = %d/ %d/ %d/ %d/ %d %s",
  3669. "ReInit/ReLink/IgnWlact/Page/NameReq",
  3670. coex_sta->cnt_reinit,
  3671. coex_sta->cnt_setup_link,
  3672. coex_sta->cnt_ign_wlan_act,
  3673. coex_sta->cnt_page,
  3674. coex_sta->cnt_remote_name_req,
  3675. (coex_sta->is_setup_link ? "(Relink!!)" : ""));
  3676. CL_PRINTF(cli_buf);
  3677. halbtc8821c1ant_read_scbd(btc, &u16tmp[0]);
  3678. if (coex_sta->bt_reg_vendor_ae == 0xffff ||
  3679. coex_sta->bt_reg_vendor_ac == 0xffff)
  3680. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3681. "\r\n %-35s = x/ x/ 0x%04x",
  3682. "0xae[4]/0xac[1:0]/ScBd(B->W)", u16tmp[0]);
  3683. else
  3684. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3685. "\r\n %-35s = 0x%x/ 0x%x/ 0x%04x",
  3686. "0xae[4]/0xac[1:0]/ScBd(B->W)",
  3687. (int)((coex_sta->bt_reg_vendor_ae & BIT(4)) >> 4),
  3688. coex_sta->bt_reg_vendor_ac & 0x3, u16tmp[0]);
  3689. CL_PRINTF(cli_buf);
  3690. if (coex_sta->num_of_profile > 0) {
  3691. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3692. "\r\n %-35s = %02x%02x%02x%02x %02x%02x%02x%02x %02x%02x",
  3693. "AFH MAP",
  3694. coex_sta->bt_afh_map[0],
  3695. coex_sta->bt_afh_map[1],
  3696. coex_sta->bt_afh_map[2],
  3697. coex_sta->bt_afh_map[3],
  3698. coex_sta->bt_afh_map[4],
  3699. coex_sta->bt_afh_map[5],
  3700. coex_sta->bt_afh_map[6],
  3701. coex_sta->bt_afh_map[7],
  3702. coex_sta->bt_afh_map[8],
  3703. coex_sta->bt_afh_map[9]);
  3704. CL_PRINTF(cli_buf);
  3705. }
  3706. for (i = 0; i < BT_8821C_1ANT_INFO_SRC_MAX; i++) {
  3707. if (coex_sta->bt_info_c2h_cnt[i]) {
  3708. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3709. "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x (%d)",
  3710. glbt_info_src_8821c_1ant[i],
  3711. coex_sta->bt_info_c2h[i][0],
  3712. coex_sta->bt_info_c2h[i][1],
  3713. coex_sta->bt_info_c2h[i][2],
  3714. coex_sta->bt_info_c2h[i][3],
  3715. coex_sta->bt_info_c2h[i][4],
  3716. coex_sta->bt_info_c2h[i][5],
  3717. coex_sta->bt_info_c2h[i][6],
  3718. coex_sta->bt_info_c2h_cnt[i]);
  3719. CL_PRINTF(cli_buf);
  3720. }
  3721. }
  3722. if (btc->manual_control)
  3723. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  3724. "============[mechanisms] (before Manual)============");
  3725. else
  3726. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  3727. "============[Mechanisms]============");
  3728. CL_PRINTF(cli_buf);
  3729. ps_tdma_case = coex_dm->cur_ps_tdma;
  3730. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3731. "\r\n %-35s = %02x %02x %02x %02x %02x (case-%d, %s)",
  3732. "TDMA",
  3733. coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1],
  3734. coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3],
  3735. coex_dm->ps_tdma_para[4], ps_tdma_case,
  3736. (coex_dm->cur_ps_tdma_on ? "TDMA-On" : "TDMA-Off"));
  3737. CL_PRINTF(cli_buf);
  3738. switch (coex_sta->wl_coex_mode) {
  3739. case BT_8821C_1ANT_WLINK_2G1PORT:
  3740. default:
  3741. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3742. "\r\n %-35s = %s", "Coex_Mode", "2G-SP");
  3743. break;
  3744. case BT_8821C_1ANT_WLINK_2GMPORT:
  3745. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3746. "\r\n %-35s = %s", "Coex_Mode", "2G-MP");
  3747. break;
  3748. case BT_8821C_1ANT_WLINK_25GMPORT:
  3749. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3750. "\r\n %-35s = %s", "Coex_Mode", "25G-MP");
  3751. break;
  3752. case BT_8821C_1ANT_WLINK_5G:
  3753. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3754. "\r\n %-35s = %s", "Coex_Mode", "5G");
  3755. break;
  3756. case BT_8821C_1ANT_WLINK_2GGO:
  3757. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3758. "\r\n %-35s = %s", "Coex_Mode", "2G-P2P");
  3759. break;
  3760. case BT_8821C_1ANT_WLINK_BTMR:
  3761. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3762. "\r\n %-35s = %s", "Coex_Mode", "BT-MR");
  3763. break;
  3764. }
  3765. CL_PRINTF(cli_buf);
  3766. u32tmp[0] = btc->btc_read_4byte(btc, 0x6c0);
  3767. u32tmp[1] = btc->btc_read_4byte(btc, 0x6c4);
  3768. u32tmp[2] = btc->btc_read_4byte(btc, 0x6c8);
  3769. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3770. "\r\n %-35s = %d/ 0x%x/ 0x%x/ 0x%x",
  3771. "Table/0x6c0/0x6c4/0x6c8",
  3772. coex_sta->coex_table_type, u32tmp[0], u32tmp[1], u32tmp[2]);
  3773. CL_PRINTF(cli_buf);
  3774. u8tmp[0] = btc->btc_read_1byte(btc, 0x778);
  3775. u32tmp[0] = btc->btc_read_4byte(btc, 0x6cc);
  3776. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3777. "\r\n %-35s = 0x%x/ 0x%x/ 0x%04x/ %d",
  3778. "0x778/0x6cc/ScBd(W->B)/RunCnt", u8tmp[0], u32tmp[0],
  3779. coex_sta->score_board_WB, coex_sta->coex_run_cnt);
  3780. CL_PRINTF(cli_buf);
  3781. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s/ %d/ %d",
  3782. "AntDiv/BtCtrlLPS/LPRA/PsFail/g_busy",
  3783. (board_info->ant_div_cfg ? "On" : "Off"),
  3784. (coex_sta->force_lps_ctrl ? "On" : "Off"),
  3785. (coex_dm->cur_low_penalty_ra ? "On" : "Off"),
  3786. coex_sta->cnt_set_ps_state_fail,
  3787. coex_sta->gl_wifi_busy);
  3788. CL_PRINTF(cli_buf);
  3789. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d",
  3790. "Null All/Retry/Ack/BT_Empty/BT_Late",
  3791. coex_sta->wl_fw_dbg_info[1],
  3792. coex_sta->wl_fw_dbg_info[2],
  3793. coex_sta->wl_fw_dbg_info[3],
  3794. coex_sta->wl_fw_dbg_info[4],
  3795. coex_sta->wl_fw_dbg_info[5]);
  3796. CL_PRINTF(cli_buf);
  3797. u32tmp[0] = halbtc8821c1ant_read_indirect_reg(btc, 0x38);
  3798. lte_coex_on = ((u32tmp[0] & BIT(7)) >> 7) ? TRUE : FALSE;
  3799. if (lte_coex_on) {
  3800. u32tmp[0] = halbtc8821c1ant_read_indirect_reg(btc, 0xa0);
  3801. u32tmp[1] = halbtc8821c1ant_read_indirect_reg(btc, 0xa4);
  3802. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
  3803. "LTE Coex Table W_L/B_L", u32tmp[0] & 0xffff,
  3804. u32tmp[1] & 0xffff);
  3805. CL_PRINTF(cli_buf);
  3806. u32tmp[0] = halbtc8821c1ant_read_indirect_reg(btc, 0xa8);
  3807. u32tmp[1] = halbtc8821c1ant_read_indirect_reg(btc, 0xac);
  3808. u32tmp[2] = halbtc8821c1ant_read_indirect_reg(btc, 0xb0);
  3809. u32tmp[3] = halbtc8821c1ant_read_indirect_reg(btc, 0xb4);
  3810. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3811. "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
  3812. "LTE Break Table W_L/B_L/L_W/L_B",
  3813. u32tmp[0] & 0xffff, u32tmp[1] & 0xffff,
  3814. u32tmp[2] & 0xffff, u32tmp[3] & 0xffff);
  3815. CL_PRINTF(cli_buf);
  3816. }
  3817. /* Hw setting */
  3818. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  3819. "============[Hw setting]============");
  3820. CL_PRINTF(cli_buf);
  3821. u32tmp[0] = halbtc8821c1ant_read_indirect_reg(btc, 0x38);
  3822. u32tmp[1] = halbtc8821c1ant_read_indirect_reg(btc, 0x54);
  3823. u8tmp[0] = btc->btc_read_1byte(btc, 0x73);
  3824. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s",
  3825. "LTE Coex/Path Owner",
  3826. ((lte_coex_on) ? "On" : "Off") ,
  3827. ((u8tmp[0] & BIT(2)) ? "WL" : "BT"));
  3828. CL_PRINTF(cli_buf);
  3829. if (lte_coex_on) {
  3830. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3831. "\r\n %-35s = %d/ %d/ %d/ %d",
  3832. "LTE 3Wire/OPMode/UART/UARTMode",
  3833. (int)((u32tmp[0] & BIT(6)) >> 6),
  3834. (int)((u32tmp[0] & (BIT(5) | BIT(4))) >> 4),
  3835. (int)((u32tmp[0] & BIT(3)) >> 3),
  3836. (int)(u32tmp[0] & (BIT(2) | BIT(1) | BIT(0))));
  3837. CL_PRINTF(cli_buf);
  3838. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
  3839. "LTE_Busy/UART_Busy",
  3840. (int)((u32tmp[1] & BIT(1)) >> 1),
  3841. (int)(u32tmp[1] & BIT(0)));
  3842. CL_PRINTF(cli_buf);
  3843. }
  3844. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3845. "\r\n %-35s = %s (BB:%s)/ %s (BB:%s)/ %s (gnt_err = %d)",
  3846. "GNT_WL_Ctrl/GNT_BT_Ctrl/Dbg",
  3847. ((u32tmp[0] & BIT(12)) ? "SW" : "HW"),
  3848. ((u32tmp[0] & BIT(8)) ? "SW" : "HW"),
  3849. ((u32tmp[0] & BIT(14)) ? "SW" : "HW"),
  3850. ((u32tmp[0] & BIT(10)) ? "SW" : "HW"),
  3851. ((u8tmp[0] & BIT(3)) ? "On" : "Off"),
  3852. coex_sta->gnt_error_cnt);
  3853. CL_PRINTF(cli_buf);
  3854. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ 0x%x",
  3855. "GNT_WL/GNT_BT/ RF_0x1",
  3856. (int)((u32tmp[1] & BIT(2)) >> 2),
  3857. (int)((u32tmp[1] & BIT(3)) >> 3),
  3858. btc->btc_get_rf_reg(btc, BTC_RF_A, 0x1, 0xfffff));
  3859. CL_PRINTF(cli_buf);
  3860. u32tmp[0] = btc->btc_read_4byte(btc, 0xcb0);
  3861. u32tmp[1] = btc->btc_read_4byte(btc, 0xcb4);
  3862. u8tmp[0] = btc->btc_read_1byte(btc, 0xcba);
  3863. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3864. "\r\n %-35s = 0x%04x/ 0x%04x/ 0x%02x %s",
  3865. "0xcb0/0xcb4/0xcb8[23:16]",
  3866. u32tmp[0], u32tmp[1], u8tmp[0],
  3867. ((u8tmp[0] & 0x1) == 0x1 ? "(BTG)" : "(WL_A+G)"));
  3868. CL_PRINTF(cli_buf);
  3869. u32tmp[0] = btc->btc_read_4byte(btc, 0x4c);
  3870. u8tmp[2] = btc->btc_read_1byte(btc, 0x64);
  3871. u8tmp[0] = btc->btc_read_1byte(btc, 0x4c6);
  3872. u8tmp[1] = btc->btc_read_1byte(btc, 0x40);
  3873. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3874. "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
  3875. "4c[24:23]/64[0]/4c6[4]/40[5]",
  3876. (int)(u32tmp[0] & (BIT(24) | BIT(23))) >> 23,
  3877. u8tmp[2] & 0x1, (int)((u8tmp[0] & BIT(4)) >> 4),
  3878. (int)((u8tmp[1] & BIT(5)) >> 5));
  3879. CL_PRINTF(cli_buf);
  3880. u32tmp[0] = btc->btc_read_4byte(btc, 0x550);
  3881. u8tmp[0] = btc->btc_read_1byte(btc, 0x522);
  3882. u8tmp[1] = btc->btc_read_1byte(btc, 0x953);
  3883. u8tmp[2] = btc->btc_read_1byte(btc, 0xc50);
  3884. u8tmp[3] = btc->btc_read_1byte(btc, 0x60a);
  3885. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3886. "\r\n %-35s = 0x%x/ 0x%x/ %s/ 0x%x/ 0x%x",
  3887. "0x550/0x522/4-RxAGC/0xc50/0x60a",
  3888. u32tmp[0], u8tmp[0], (u8tmp[1] & 0x2) ? "On" : "Off",
  3889. u8tmp[2], u8tmp[3]);
  3890. CL_PRINTF(cli_buf);
  3891. fa_ofdm = btc->btc_phydm_query_PHY_counter(btc, PHYDM_INFO_FA_OFDM);
  3892. fa_cck = btc->btc_phydm_query_PHY_counter(btc, PHYDM_INFO_FA_CCK);
  3893. cca_ofdm = btc->btc_phydm_query_PHY_counter(btc, PHYDM_INFO_CCA_OFDM);
  3894. cca_cck = btc->btc_phydm_query_PHY_counter(btc, PHYDM_INFO_CCA_CCK);
  3895. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3896. "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
  3897. "CCK-CCA/CCK-FA/OFDM-CCA/OFDM-FA",
  3898. cca_cck, fa_cck, cca_ofdm, fa_ofdm);
  3899. CL_PRINTF(cli_buf);
  3900. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
  3901. "CRC_OK CCK/11g/11n/11ac",
  3902. coex_sta->crc_ok_cck, coex_sta->crc_ok_11g,
  3903. coex_sta->crc_ok_11n, coex_sta->crc_ok_11n_vht);
  3904. CL_PRINTF(cli_buf);
  3905. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
  3906. "CRC_Err CCK/11g/11n/11ac",
  3907. coex_sta->crc_err_cck, coex_sta->crc_err_11g,
  3908. coex_sta->crc_err_11n, coex_sta->crc_err_11n_vht);
  3909. CL_PRINTF(cli_buf);
  3910. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  3911. "\r\n %-35s = %d/ %d/ %s-%d/ %d (Tx macid: %d)",
  3912. "Rate RxD/RxRTS/TxD/TxRetry_ratio",
  3913. coex_sta->wl_rx_rate, coex_sta->wl_rts_rx_rate,
  3914. (coex_sta->wl_tx_rate & 0x80 ? "SGI" : "LGI"),
  3915. coex_sta->wl_tx_rate & 0x7f,
  3916. coex_sta->wl_tx_retry_ratio,
  3917. coex_sta->wl_tx_macid);
  3918. CL_PRINTF(cli_buf);
  3919. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s/ %s/ %d",
  3920. "HiPr/ Locking/ warn/ Locked/ Noisy",
  3921. (coex_sta->wifi_high_pri_task1 ? "Yes" : "No"),
  3922. (coex_sta->cck_lock ? "Yes" : "No"),
  3923. (coex_sta->cck_lock_warn ? "Yes" : "No"),
  3924. (coex_sta->cck_lock_ever ? "Yes" : "No"),
  3925. coex_sta->wl_noisy_level);
  3926. CL_PRINTF(cli_buf);
  3927. u8tmp[0] = btc->btc_read_1byte(btc, 0xf8e);
  3928. u8tmp[1] = btc->btc_read_1byte(btc, 0xf8f);
  3929. u8tmp[2] = btc->btc_read_1byte(btc, 0xd14);
  3930. u8tmp[3] = btc->btc_read_1byte(btc, 0xd54);
  3931. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
  3932. "EVM_A/ EVM_B/ SNR_A/ SNR_B",
  3933. (u8tmp[0] > 127 ? u8tmp[0] - 256 : u8tmp[0]),
  3934. (u8tmp[1] > 127 ? u8tmp[1] - 256 : u8tmp[1]),
  3935. (u8tmp[2] > 127 ? u8tmp[2] - 256 : u8tmp[2]),
  3936. (u8tmp[3] > 127 ? u8tmp[3] - 256 : u8tmp[3]));
  3937. CL_PRINTF(cli_buf);
  3938. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
  3939. "0x770(Hi-pri rx/tx)",
  3940. coex_sta->high_priority_rx, coex_sta->high_priority_tx);
  3941. CL_PRINTF(cli_buf);
  3942. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d %s",
  3943. "0x774(Lo-pri rx/tx)",
  3944. coex_sta->low_priority_rx, coex_sta->low_priority_tx,
  3945. (bt_link_info->slave_role ? "(Slave!!)" : (
  3946. coex_sta->is_tdma_btautoslot_hang ? "(auto-slot hang!!)" : "")));
  3947. CL_PRINTF(cli_buf);
  3948. btc->btc_disp_dbg_msg(btc, BTC_DBG_DISP_COEX_STATISTICS);
  3949. }
  3950. void ex_halbtc8821c1ant_ips_notify(struct btc_coexist *btc, u8 type)
  3951. {
  3952. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  3953. if (btc->manual_control || btc->stop_coex_dm)
  3954. return;
  3955. if (type == BTC_IPS_ENTER) {
  3956. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3957. "[BTCoex], IPS ENTER notify\n");
  3958. BTC_TRACE(trace_buf);
  3959. coex_sta->under_ips = TRUE;
  3960. /* Write WL "Active" in Score-board for LPS off */
  3961. halbtc8821c1ant_write_scbd(btc, BT_8821C_1ANT_SCBD_ACTIVE |
  3962. BT_8821C_1ANT_SCBD_ONOFF |
  3963. BT_8821C_1ANT_SCBD_SCAN |
  3964. BT_8821C_1ANT_SCBD_UNDERTEST,
  3965. FALSE);
  3966. halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, FC_EXCU,
  3967. BT_8821C_1ANT_PHASE_WOFF);
  3968. halbtc8821c1ant_action_coex_all_off(btc);
  3969. } else if (type == BTC_IPS_LEAVE) {
  3970. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3971. "[BTCoex], IPS LEAVE notify\n");
  3972. BTC_TRACE(trace_buf);
  3973. halbtc8821c1ant_init_hw_config(btc, FALSE, FALSE);
  3974. halbtc8821c1ant_init_coex_dm(btc);
  3975. coex_sta->under_ips = FALSE;
  3976. }
  3977. }
  3978. void ex_halbtc8821c1ant_lps_notify(struct btc_coexist *btc, u8 type)
  3979. {
  3980. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  3981. static boolean pre_force_lps_on = FALSE;
  3982. if (btc->manual_control || btc->stop_coex_dm)
  3983. return;
  3984. if (type == BTC_LPS_ENABLE) {
  3985. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  3986. "[BTCoex], LPS ENABLE notify\n");
  3987. BTC_TRACE(trace_buf);
  3988. coex_sta->under_lps = TRUE;
  3989. if (coex_sta->force_lps_ctrl == TRUE) { /* LPS No-32K */
  3990. /* Write WL "Active" in Score-board for PS-TDMA */
  3991. pre_force_lps_on = TRUE;
  3992. halbtc8821c1ant_write_scbd(btc,
  3993. BT_8821C_1ANT_SCBD_ACTIVE,
  3994. TRUE);
  3995. } else { /* LPS-32K, need check if this h2c 0x71 can work??
  3996. *(2015/08/28)
  3997. * Write WL "Non-Active" in Score-board for Native-PS
  3998. */
  3999. pre_force_lps_on = FALSE;
  4000. halbtc8821c1ant_write_scbd(btc,
  4001. BT_8821C_1ANT_SCBD_ACTIVE,
  4002. FALSE);
  4003. halbtc8821c1ant_action_wifi_native_lps(btc);
  4004. }
  4005. } else if (type == BTC_LPS_DISABLE) {
  4006. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4007. "[BTCoex], LPS DISABLE notify\n");
  4008. BTC_TRACE(trace_buf);
  4009. coex_sta->under_lps = FALSE;
  4010. /* Write WL "Active" in Score-board for LPS off */
  4011. halbtc8821c1ant_write_scbd(btc, BT_8821C_1ANT_SCBD_ACTIVE,
  4012. TRUE);
  4013. if (!pre_force_lps_on && !coex_sta->force_lps_ctrl)
  4014. halbtc8821c1ant_query_bt_info(btc);
  4015. }
  4016. }
  4017. void ex_halbtc8821c1ant_scan_notify(struct btc_coexist *btc,
  4018. u8 type)
  4019. {
  4020. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  4021. boolean wifi_connected = FALSE;
  4022. if (btc->manual_control ||
  4023. btc->stop_coex_dm)
  4024. return;
  4025. coex_sta->freeze_coexrun_by_btinfo = FALSE;
  4026. btc->btc_get(btc, BTC_GET_BL_WIFI_CONNECTED, &wifi_connected);
  4027. if (wifi_connected)
  4028. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4029. "[BTCoex], ********** WL connected before SCAN\n");
  4030. else
  4031. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4032. "[BTCoex], ********** WL is not connected before SCAN\n");
  4033. BTC_TRACE(trace_buf);
  4034. if (type != BTC_SCAN_FINISH) {
  4035. halbtc8821c1ant_write_scbd(btc, BT_8821C_1ANT_SCBD_ACTIVE |
  4036. BT_8821C_1ANT_SCBD_SCAN |
  4037. BT_8821C_1ANT_SCBD_ONOFF,
  4038. TRUE);
  4039. }
  4040. if (type == BTC_SCAN_START_5G) {
  4041. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4042. "[BTCoex], SCAN START notify (5G)\n");
  4043. BTC_TRACE(trace_buf);
  4044. halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, FC_EXCU,
  4045. BT_8821C_1ANT_PHASE_5G);
  4046. halbtc8821c1ant_run_coex(btc, BT_8821C_1ANT_RSN_5GSCANSTART);
  4047. } else if (type == BTC_SCAN_START_2G || type == BTC_SCAN_START) {
  4048. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4049. "[BTCoex], SCAN START notify (2G)\n");
  4050. BTC_TRACE(trace_buf);
  4051. if (!wifi_connected)
  4052. coex_sta->wifi_high_pri_task2 = TRUE;
  4053. /* Force antenna setup for no scan result issue */
  4054. halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, FC_EXCU,
  4055. BT_8821C_1ANT_PHASE_2G);
  4056. halbtc8821c1ant_run_coex(btc, BT_8821C_1ANT_RSN_2GSCANSTART);
  4057. } else {
  4058. btc->btc_get(btc, BTC_GET_U1_AP_NUM, &coex_sta->scan_ap_num);
  4059. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4060. "[BTCoex], SCAN FINISH notify (Scan-AP = %d)\n",
  4061. coex_sta->scan_ap_num);
  4062. BTC_TRACE(trace_buf);
  4063. coex_sta->wifi_high_pri_task2 = FALSE;
  4064. halbtc8821c1ant_run_coex(btc, BT_8821C_1ANT_RSN_SCANFINISH);
  4065. }
  4066. }
  4067. void ex_halbtc8821c1ant_switchband_notify(struct btc_coexist *btc, u8 type)
  4068. {
  4069. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  4070. if (btc->manual_control || btc->stop_coex_dm)
  4071. return;
  4072. coex_sta->switch_band_notify_to = type;
  4073. if (type == BTC_SWITCH_TO_5G) {
  4074. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4075. "[BTCoex], switchband_notify --- switch to 5G\n");
  4076. BTC_TRACE(trace_buf);
  4077. halbtc8821c1ant_run_coex(btc, BT_8821C_1ANT_RSN_5GSWITCHBAND);
  4078. } else if (type == BTC_SWITCH_TO_24G_NOFORSCAN) {
  4079. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4080. "[BTCoex], switchband_notify --- BTC_SWITCH_TO_2G (no for scan)\n");
  4081. BTC_TRACE(trace_buf);
  4082. halbtc8821c1ant_run_coex(btc, BT_8821C_1ANT_RSN_2GSWITCHBAND);
  4083. } else {
  4084. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4085. "[BTCoex], switchband_notify --- switch to 2G\n");
  4086. BTC_TRACE(trace_buf);
  4087. ex_halbtc8821c1ant_scan_notify(btc, BTC_SCAN_START_2G);
  4088. }
  4089. coex_sta->switch_band_notify_to = BTC_NOT_SWITCH;
  4090. }
  4091. void ex_halbtc8821c1ant_connect_notify(struct btc_coexist *btc, u8 type)
  4092. {
  4093. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  4094. struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
  4095. if (btc->manual_control || btc->stop_coex_dm)
  4096. return;
  4097. halbtc8821c1ant_write_scbd(btc, BT_8821C_1ANT_SCBD_ACTIVE |
  4098. BT_8821C_1ANT_SCBD_SCAN |
  4099. BT_8821C_1ANT_SCBD_ONOFF,
  4100. TRUE);
  4101. if (type == BTC_ASSOCIATE_5G_START ||
  4102. type == BTC_ASSOCIATE_5G_FINISH) {
  4103. halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, FC_EXCU,
  4104. BT_8821C_1ANT_PHASE_5G);
  4105. if (type == BTC_ASSOCIATE_5G_START) {
  4106. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4107. "[BTCoex], CONNECT START notify (5G)\n");
  4108. BTC_TRACE(trace_buf);
  4109. halbtc8821c1ant_run_coex(btc,
  4110. BT_8821C_1ANT_RSN_5GCONSTART);
  4111. } else {
  4112. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4113. "[BTCoex], CONNECT FINISH notify (5G)\n");
  4114. BTC_TRACE(trace_buf);
  4115. halbtc8821c1ant_run_coex(btc,
  4116. BT_8821C_1ANT_RSN_5GCONFINISH);
  4117. }
  4118. } else if (type == BTC_ASSOCIATE_START) {
  4119. coex_sta->wifi_high_pri_task1 = TRUE;
  4120. coex_dm->arp_cnt = 0;
  4121. coex_sta->connect_ap_period_cnt = 2;
  4122. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4123. "[BTCoex], CONNECT START notify (2G)\n");
  4124. BTC_TRACE(trace_buf);
  4125. /* Force antenna setup for no scan result issue */
  4126. halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, FC_EXCU,
  4127. BT_8821C_1ANT_PHASE_2G);
  4128. halbtc8821c1ant_run_coex(btc, BT_8821C_1ANT_RSN_2GCONSTART);
  4129. /* To keep TDMA case during connect process,
  4130. * to avoid changed by Btinfo and runcoexmechanism
  4131. */
  4132. coex_sta->freeze_coexrun_by_btinfo = TRUE;
  4133. } else {
  4134. coex_sta->wifi_high_pri_task1 = FALSE;
  4135. coex_sta->freeze_coexrun_by_btinfo = FALSE;
  4136. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4137. "[BTCoex], CONNECT FINISH notify (2G)\n");
  4138. BTC_TRACE(trace_buf);
  4139. halbtc8821c1ant_run_coex(btc, BT_8821C_1ANT_RSN_2GCONFINISH);
  4140. }
  4141. }
  4142. void ex_halbtc8821c1ant_media_status_notify(struct btc_coexist *btc, u8 type)
  4143. {
  4144. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  4145. boolean wifi_under_b_mode = FALSE;
  4146. u16 ap_beacon_interval = 100;
  4147. u8 h2c_parameter[3] = {0};
  4148. if (btc->manual_control || btc->stop_coex_dm)
  4149. return;
  4150. if (type == BTC_MEDIA_CONNECT || type == BTC_MEDIA_CONNECT_5G) {
  4151. halbtc8821c1ant_write_scbd(btc,
  4152. BT_8821C_1ANT_SCBD_ACTIVE |
  4153. BT_8821C_1ANT_SCBD_ONOFF,
  4154. TRUE);
  4155. if (type == BTC_MEDIA_CONNECT_5G) {
  4156. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4157. "[BTCoex], media_status_notify --- 5G\n");
  4158. BTC_TRACE(trace_buf);
  4159. halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO,
  4160. FC_EXCU,
  4161. BT_8821C_1ANT_PHASE_5G);
  4162. halbtc8821c1ant_run_coex(btc,
  4163. BT_8821C_1ANT_RSN_5GMEDIA);
  4164. } else {
  4165. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4166. "[BTCoex], media_status_notify --- 2G\n");
  4167. BTC_TRACE(trace_buf);
  4168. /* Force antenna setup for no scan result issue */
  4169. halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO,
  4170. FC_EXCU,
  4171. BT_8821C_1ANT_PHASE_2G);
  4172. btc->btc_get(btc, BTC_GET_BL_WIFI_UNDER_B_MODE,
  4173. &wifi_under_b_mode);
  4174. /* Set CCK Tx/Rx high Pri except 11b mode */
  4175. if (wifi_under_b_mode) {
  4176. /* CCK Tx */
  4177. btc->btc_write_1byte(btc, 0x6cd, 0x00);
  4178. /* CCK Rx */
  4179. btc->btc_write_1byte(btc, 0x6cf, 0x00);
  4180. } else {
  4181. /* CCK Tx */
  4182. btc->btc_write_1byte(btc, 0x6cd, 0x00);
  4183. /* CCK Rx */
  4184. btc->btc_write_1byte(btc, 0x6cf, 0x10);
  4185. }
  4186. btc->btc_get(btc, BTC_GET_U2_BEACON_PERIOD,
  4187. &ap_beacon_interval);
  4188. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4189. "[BTCoex], AP beacon interval = %d\n",
  4190. ap_beacon_interval);
  4191. BTC_TRACE(trace_buf);
  4192. /* set TDMA waiting BI if BI is not equal to 100 */
  4193. if (ap_beacon_interval < 80 && ap_beacon_interval > 0) {
  4194. h2c_parameter[0] = 0xb;
  4195. h2c_parameter[1] = (100 / ap_beacon_interval);
  4196. if (100 % ap_beacon_interval != 0)
  4197. h2c_parameter[1] = h2c_parameter[1] + 1;
  4198. } else if (ap_beacon_interval >= 180) {
  4199. h2c_parameter[0] = 0xb;
  4200. h2c_parameter[1] = (ap_beacon_interval / 100);
  4201. if (ap_beacon_interval % 100 <= 80)
  4202. h2c_parameter[1] = h2c_parameter[1] - 1;
  4203. h2c_parameter[1] = h2c_parameter[1] | 0x80;
  4204. } else {
  4205. h2c_parameter[0] = 0xb;
  4206. h2c_parameter[1] = 0x1;
  4207. }
  4208. btc->btc_fill_h2c(btc, 0x69, 2, h2c_parameter);
  4209. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4210. "[BTCoex], TDMA waiting BI = 0x%x\n",
  4211. h2c_parameter[1]);
  4212. BTC_TRACE(trace_buf);
  4213. halbtc8821c1ant_run_coex(btc,
  4214. BT_8821C_1ANT_RSN_2GMEDIA);
  4215. }
  4216. } else {
  4217. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4218. "[BTCoex], media disconnect notify\n");
  4219. BTC_TRACE(trace_buf);
  4220. halbtc8821c1ant_write_scbd(btc, BT_8821C_1ANT_SCBD_ACTIVE,
  4221. FALSE);
  4222. btc->btc_write_1byte(btc, 0x6cd, 0x0); /* CCK Tx */
  4223. btc->btc_write_1byte(btc, 0x6cf, 0x0); /* CCK Rx */
  4224. coex_sta->cck_lock_ever = FALSE;
  4225. coex_sta->cck_lock_warn = FALSE;
  4226. coex_sta->cck_lock = FALSE;
  4227. halbtc8821c1ant_run_coex(btc, BT_8821C_1ANT_RSN_MEDIADISCON);
  4228. }
  4229. halbtc8821c1ant_update_wifi_ch_info(btc, type);
  4230. }
  4231. void ex_halbtc8821c1ant_specific_packet_notify(struct btc_coexist *btc, u8 type)
  4232. {
  4233. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  4234. struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
  4235. boolean under_4way = FALSE;
  4236. if (btc->manual_control || btc->stop_coex_dm)
  4237. return;
  4238. if (type & BTC_5G_BAND) {
  4239. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4240. "[BTCoex], 5g special packet notify\n");
  4241. BTC_TRACE(trace_buf);
  4242. halbtc8821c1ant_run_coex(btc, BT_8821C_1ANT_RSN_5GSPECIALPKT);
  4243. return;
  4244. }
  4245. btc->btc_get(btc, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &under_4way);
  4246. if (under_4way) {
  4247. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4248. "[BTCoex], specific Packet ---- under_4way!!\n");
  4249. BTC_TRACE(trace_buf);
  4250. coex_sta->wifi_high_pri_task1 = TRUE;
  4251. coex_sta->specific_pkt_period_cnt = 2;
  4252. } else if (type == BTC_PACKET_ARP) {
  4253. coex_dm->arp_cnt++;
  4254. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4255. "[BTCoex], specific Packet ARP notify -cnt = %d\n",
  4256. coex_dm->arp_cnt);
  4257. BTC_TRACE(trace_buf);
  4258. } else {
  4259. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4260. "[BTCoex], specific Packet DHCP or EAPOL notify [Type = %d]\n",
  4261. type);
  4262. BTC_TRACE(trace_buf);
  4263. coex_sta->wifi_high_pri_task1 = TRUE;
  4264. coex_sta->specific_pkt_period_cnt = 2;
  4265. }
  4266. if (coex_sta->wifi_high_pri_task1) {
  4267. halbtc8821c1ant_write_scbd(btc, BT_8821C_1ANT_SCBD_SCAN, TRUE);
  4268. halbtc8821c1ant_run_coex(btc, BT_8821C_1ANT_RSN_2GSPECIALPKT);
  4269. }
  4270. }
  4271. void ex_halbtc8821c1ant_bt_info_notify(struct btc_coexist *btc, u8 *tmp_buf,
  4272. u8 length)
  4273. {
  4274. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  4275. u8 i, rsp_source = 0;
  4276. boolean wifi_connected = FALSE;
  4277. boolean wifi_busy = FALSE;
  4278. static boolean is_scoreboard_scan;
  4279. const u16 type_is_scan = BT_8821C_1ANT_SCBD_SCAN;
  4280. u8 type;
  4281. rsp_source = tmp_buf[0] & 0xf;
  4282. if (rsp_source >= BT_8821C_1ANT_INFO_SRC_MAX)
  4283. rsp_source = BT_8821C_1ANT_INFO_SRC_WIFI_FW;
  4284. coex_sta->bt_info_c2h_cnt[rsp_source]++;
  4285. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4286. "[BTCoex], Bt_info[%d], len=%d, data=[", rsp_source,
  4287. length);
  4288. BTC_TRACE(trace_buf);
  4289. if (rsp_source == BT_8821C_1ANT_INFO_SRC_BT_RSP ||
  4290. rsp_source == BT_8821C_1ANT_INFO_SRC_BT_ACT) {
  4291. if (coex_sta->bt_disabled) {
  4292. coex_sta->bt_disabled = FALSE;
  4293. coex_sta->is_bt_reenable = TRUE;
  4294. coex_sta->cnt_bt_reenable = 15;
  4295. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4296. "[BTCoex], BT enable detected by bt_info\n");
  4297. BTC_TRACE(trace_buf);
  4298. }
  4299. }
  4300. for (i = 0; i < length; i++) {
  4301. coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i];
  4302. if (i == length - 1) {
  4303. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n",
  4304. tmp_buf[i]);
  4305. BTC_TRACE(trace_buf);
  4306. } else {
  4307. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ",
  4308. tmp_buf[i]);
  4309. BTC_TRACE(trace_buf);
  4310. }
  4311. }
  4312. coex_sta->bt_info = coex_sta->bt_info_c2h[rsp_source][1];
  4313. coex_sta->bt_info_ext = coex_sta->bt_info_c2h[rsp_source][4];
  4314. coex_sta->bt_info_ext2 = coex_sta->bt_info_c2h[rsp_source][5];
  4315. if (rsp_source != BT_8821C_1ANT_INFO_SRC_WIFI_FW) {
  4316. /* if 0xff, it means BT is under WHCK test */
  4317. coex_sta->bt_whck_test =
  4318. ((coex_sta->bt_info == 0xff) ? TRUE : FALSE);
  4319. coex_sta->bt_create_connection =
  4320. ((coex_sta->bt_info_c2h[rsp_source][2] & 0x80) ? TRUE :
  4321. FALSE);
  4322. /* unit: %, value-100 to translate to unit: dBm */
  4323. coex_sta->bt_rssi =
  4324. coex_sta->bt_info_c2h[rsp_source][3] * 2 + 10;
  4325. coex_sta->c2h_bt_remote_name_req =
  4326. ((coex_sta->bt_info_c2h[rsp_source][2] & 0x20) ? TRUE :
  4327. FALSE);
  4328. coex_sta->is_A2DP_3M =
  4329. ((coex_sta->bt_info_c2h[rsp_source][2] & 0x10) ? TRUE :
  4330. FALSE);
  4331. coex_sta->acl_busy =
  4332. ((coex_sta->bt_info_c2h[rsp_source][1] & 0x8) ? TRUE :
  4333. FALSE);
  4334. coex_sta->voice_over_HOGP =
  4335. ((coex_sta->bt_info_ext & 0x10) ? TRUE : FALSE);
  4336. coex_sta->c2h_bt_inquiry_page =
  4337. ((coex_sta->bt_info & BT_INFO_8821C_1ANT_B_INQ_PAGE) ?
  4338. TRUE :
  4339. FALSE);
  4340. coex_sta->a2dp_bit_pool =
  4341. (((coex_sta->bt_info_c2h[rsp_source][1] & 0x49) ==
  4342. 0x49) ?
  4343. (coex_sta->bt_info_c2h[rsp_source][6] & 0x7f) :
  4344. 0);
  4345. coex_sta->is_bt_a2dp_sink =
  4346. (coex_sta->bt_info_c2h[rsp_source][6] & 0x80) ? TRUE :
  4347. FALSE;
  4348. coex_sta->bt_retry_cnt =
  4349. coex_sta->bt_info_c2h[rsp_source][2] & 0xf;
  4350. coex_sta->is_autoslot = coex_sta->bt_info_ext2 & 0x8;
  4351. coex_sta->forbidden_slot = coex_sta->bt_info_ext2 & 0x7;
  4352. coex_sta->hid_busy_num = (coex_sta->bt_info_ext2 & 0x30) >> 4;
  4353. coex_sta->hid_pair_cnt = (coex_sta->bt_info_ext2 & 0xc0) >> 6;
  4354. coex_sta->is_bt_opp_exist =
  4355. (coex_sta->bt_info_ext2 & 0x1) ? TRUE : FALSE;
  4356. if (coex_sta->bt_retry_cnt >= 1)
  4357. coex_sta->pop_event_cnt++;
  4358. if (coex_sta->c2h_bt_remote_name_req)
  4359. coex_sta->cnt_remote_name_req++;
  4360. if (coex_sta->bt_info_ext & BIT(1))
  4361. coex_sta->cnt_reinit++;
  4362. if ((coex_sta->bt_info_ext & BIT(2)) ||
  4363. (coex_sta->bt_create_connection &&
  4364. coex_sta->wl_pnp_wakeup_downcnt > 0)) {
  4365. coex_sta->cnt_setup_link++;
  4366. coex_sta->is_setup_link = TRUE;
  4367. if (coex_sta->is_bt_reenable)
  4368. coex_sta->bt_relink_downcount = 6;
  4369. else
  4370. coex_sta->bt_relink_downcount = 2;
  4371. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4372. "[BTCoex], Re-Link start in BT info!!\n");
  4373. BTC_TRACE(trace_buf);
  4374. } else {
  4375. coex_sta->is_setup_link = FALSE;
  4376. if (!coex_sta->is_bt_reenable)
  4377. coex_sta->bt_relink_downcount = 0;
  4378. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4379. "[BTCoex], Re-Link stop in BT info!!\n");
  4380. BTC_TRACE(trace_buf);
  4381. }
  4382. if (coex_sta->bt_info_ext & BIT(3))
  4383. coex_sta->cnt_ign_wlan_act++;
  4384. if (coex_sta->bt_info_ext & BIT(6))
  4385. coex_sta->cnt_role_switch++;
  4386. if (coex_sta->bt_info_ext & BIT(7))
  4387. coex_sta->is_bt_multi_link = TRUE;
  4388. else
  4389. coex_sta->is_bt_multi_link = FALSE;
  4390. if (coex_sta->bt_info_ext & BIT(0))
  4391. coex_sta->is_hid_rcu = TRUE;
  4392. else
  4393. coex_sta->is_hid_rcu = FALSE;
  4394. if (coex_sta->bt_info_ext & BIT(5))
  4395. coex_sta->is_ble_scan_en = TRUE;
  4396. else
  4397. coex_sta->is_ble_scan_en = FALSE;
  4398. if (coex_sta->bt_create_connection) {
  4399. coex_sta->cnt_page++;
  4400. btc->btc_get(btc, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  4401. if (coex_sta->is_wifi_linkscan_process ||
  4402. coex_sta->wifi_high_pri_task1 ||
  4403. coex_sta->wifi_high_pri_task2 ||
  4404. wifi_busy) {
  4405. is_scoreboard_scan = TRUE;
  4406. halbtc8821c1ant_write_scbd(btc, type_is_scan,
  4407. TRUE);
  4408. } else
  4409. halbtc8821c1ant_write_scbd(btc, type_is_scan,
  4410. FALSE);
  4411. } else {
  4412. if (is_scoreboard_scan) {
  4413. halbtc8821c1ant_write_scbd(btc, type_is_scan,
  4414. FALSE);
  4415. is_scoreboard_scan = FALSE;
  4416. }
  4417. }
  4418. /* Here we need to resend some wifi info to BT */
  4419. /* because bt is reset and loss of the info. */
  4420. btc->btc_get(btc, BTC_GET_BL_WIFI_CONNECTED, &wifi_connected);
  4421. /* Re-Init */
  4422. if ((coex_sta->bt_info_ext & BIT(1))) {
  4423. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4424. "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
  4425. BTC_TRACE(trace_buf);
  4426. if (wifi_connected)
  4427. type = BTC_MEDIA_CONNECT;
  4428. else
  4429. type = BTC_MEDIA_DISCONNECT;
  4430. halbtc8821c1ant_update_wifi_ch_info(btc, type);
  4431. }
  4432. /* If Ignore_WLanAct && not SetUp_Link */
  4433. if ((coex_sta->bt_info_ext & BIT(3)) &&
  4434. (!(coex_sta->bt_info_ext & BIT(2)))) {
  4435. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4436. "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n");
  4437. BTC_TRACE(trace_buf);
  4438. halbtc8821c1ant_ignore_wlan_act(btc, FC_EXCU, FALSE);
  4439. }
  4440. }
  4441. halbtc8821c1ant_update_bt_link_info(btc);
  4442. halbtc8821c1ant_run_coex(btc, BT_8821C_1ANT_RSN_BTINFO);
  4443. }
  4444. void ex_halbtc8821c1ant_wl_fwdbginfo_notify(struct btc_coexist *btc,
  4445. u8 *tmp_buf, u8 length)
  4446. {
  4447. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  4448. u8 i = 0;
  4449. static u8 tmp_buf_pre[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  4450. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4451. "[BTCoex], WiFi Fw Dbg info = %d %d %d %d %d %d (len = %d)\n",
  4452. tmp_buf[0], tmp_buf[1], tmp_buf[2], tmp_buf[3], tmp_buf[4],
  4453. tmp_buf[5], length);
  4454. BTC_TRACE(trace_buf);
  4455. if (tmp_buf[0] == 0x8) {
  4456. for (i = 1; i <= 5; i++) {
  4457. coex_sta->wl_fw_dbg_info[i] =
  4458. (tmp_buf[i] >= tmp_buf_pre[i]) ?
  4459. (tmp_buf[i] - tmp_buf_pre[i]) :
  4460. (255 - tmp_buf_pre[i] + tmp_buf[i]);
  4461. tmp_buf_pre[i] = tmp_buf[i];
  4462. }
  4463. }
  4464. }
  4465. void ex_halbtc8821c1ant_rx_rate_change_notify(struct btc_coexist *btc,
  4466. BOOLEAN is_data_frame,
  4467. u8 btc_rate_id)
  4468. {
  4469. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  4470. struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
  4471. BOOLEAN wifi_connected = FALSE;
  4472. btc->btc_get(btc, BTC_GET_BL_WIFI_CONNECTED, &wifi_connected);
  4473. if (is_data_frame) {
  4474. coex_sta->wl_rx_rate = btc_rate_id;
  4475. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4476. "[BTCoex], rx_rate_change_notify data rate id = %d, RTS_Rate = %d\n",
  4477. coex_sta->wl_rx_rate, coex_sta->wl_rts_rx_rate);
  4478. BTC_TRACE(trace_buf);
  4479. } else {
  4480. coex_sta->wl_rts_rx_rate = btc_rate_id;
  4481. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4482. "[BTCoex], rts_rate_change_notify RTS rate id = %d, RTS_Rate = %d\n",
  4483. coex_sta->wl_rts_rx_rate, coex_sta->wl_rts_rx_rate);
  4484. BTC_TRACE(trace_buf);
  4485. }
  4486. if (wifi_connected &&
  4487. (coex_dm->bt_status == BT_8821C_1ANT_BSTATUS_ACL_BUSY ||
  4488. coex_dm->bt_status == BT_8821C_1ANT_BSTATUS_ACL_SCO_BUSY ||
  4489. coex_dm->bt_status == BT_8821C_1ANT_BSTATUS_SCO_BUSY)) {
  4490. if (coex_sta->wl_rx_rate == BTC_CCK_5_5 ||
  4491. coex_sta->wl_rx_rate == BTC_OFDM_6 ||
  4492. coex_sta->wl_rx_rate == BTC_MCS_0) {
  4493. coex_sta->cck_lock_warn = TRUE;
  4494. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4495. "[BTCoex], cck lock warning...\n");
  4496. BTC_TRACE(trace_buf);
  4497. } else if (coex_sta->wl_rx_rate == BTC_CCK_1 ||
  4498. coex_sta->wl_rx_rate == BTC_CCK_2 ||
  4499. coex_sta->wl_rts_rx_rate == BTC_CCK_1 ||
  4500. coex_sta->wl_rts_rx_rate == BTC_CCK_2) {
  4501. coex_sta->cck_lock = TRUE;
  4502. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4503. "[BTCoex], cck locking...\n");
  4504. BTC_TRACE(trace_buf);
  4505. } else {
  4506. coex_sta->cck_lock_warn = FALSE;
  4507. coex_sta->cck_lock = FALSE;
  4508. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4509. "[BTCoex], cck unlock...\n");
  4510. BTC_TRACE(trace_buf);
  4511. }
  4512. } else {
  4513. if (coex_dm->bt_status == BT_8821C_1ANT_BSTATUS_CON_IDLE ||
  4514. coex_dm->bt_status == BT_8821C_1ANT_BSTATUS_NCON_IDLE) {
  4515. coex_sta->cck_lock_warn = FALSE;
  4516. coex_sta->cck_lock = FALSE;
  4517. }
  4518. }
  4519. }
  4520. void ex_halbtc8821c1ant_tx_rate_change_notify(struct btc_coexist *btc,
  4521. u8 tx_rate, u8 tx_retry_ratio,
  4522. u8 macid)
  4523. {
  4524. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  4525. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4526. "[BTCoex], tx_rate_change_notify Tx_Rate = %d, Tx_Retry_Ratio = %d, macid =%d\n",
  4527. tx_rate, tx_retry_ratio, macid);
  4528. BTC_TRACE(trace_buf);
  4529. coex_sta->wl_tx_rate = tx_rate;
  4530. coex_sta->wl_tx_retry_ratio = tx_retry_ratio;
  4531. coex_sta->wl_tx_macid = macid;
  4532. }
  4533. void ex_halbtc8821c1ant_rf_status_notify(struct btc_coexist *btc, u8 type)
  4534. {
  4535. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  4536. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], RF Status notify\n");
  4537. BTC_TRACE(trace_buf);
  4538. if (type == BTC_RF_ON) {
  4539. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4540. "[BTCoex], RF is turned ON!!\n");
  4541. BTC_TRACE(trace_buf);
  4542. btc->stop_coex_dm = FALSE;
  4543. coex_sta->is_rf_state_off = FALSE;
  4544. } else if (type == BTC_RF_OFF) {
  4545. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4546. "[BTCoex], RF is turned OFF!!\n");
  4547. BTC_TRACE(trace_buf);
  4548. halbtc8821c1ant_write_scbd(btc, BT_8821C_1ANT_SCBD_ACTIVE |
  4549. BT_8821C_1ANT_SCBD_ONOFF |
  4550. BT_8821C_1ANT_SCBD_SCAN |
  4551. BT_8821C_1ANT_SCBD_UNDERTEST,
  4552. FALSE);
  4553. halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, FC_EXCU,
  4554. BT_8821C_1ANT_PHASE_WOFF);
  4555. halbtc8821c1ant_action_coex_all_off(btc);
  4556. btc->stop_coex_dm = TRUE;
  4557. coex_sta->is_rf_state_off = TRUE;
  4558. /* must place in the last step */
  4559. halbtc8821c1ant_update_wifi_ch_info(btc, BTC_MEDIA_DISCONNECT);
  4560. }
  4561. }
  4562. void ex_halbtc8821c1ant_halt_notify(struct btc_coexist *btc)
  4563. {
  4564. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n");
  4565. BTC_TRACE(trace_buf);
  4566. halbtc8821c1ant_write_scbd(btc, BT_8821C_1ANT_SCBD_ACTIVE |
  4567. BT_8821C_1ANT_SCBD_ONOFF |
  4568. BT_8821C_1ANT_SCBD_SCAN |
  4569. BT_8821C_1ANT_SCBD_UNDERTEST,
  4570. FALSE);
  4571. halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, FC_EXCU,
  4572. BT_8821C_1ANT_PHASE_WOFF);
  4573. halbtc8821c1ant_action_coex_all_off(btc);
  4574. btc->stop_coex_dm = TRUE;
  4575. /* must place in the last step */
  4576. halbtc8821c1ant_update_wifi_ch_info(btc, BTC_MEDIA_DISCONNECT);
  4577. }
  4578. void ex_halbtc8821c1ant_pnp_notify(struct btc_coexist *btc, u8 pnp_state)
  4579. {
  4580. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  4581. struct wifi_link_info_8821c_1ant *wifi_link_info_ext =
  4582. &btc->wifi_link_info_8821c_1ant;
  4583. static u8 pre_pnp_state;
  4584. u8 phase;
  4585. if (pnp_state == BTC_WIFI_PNP_SLEEP ||
  4586. pnp_state == BTC_WIFI_PNP_SLEEP_KEEP_ANT) {
  4587. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4588. "[BTCoex], Pnp notify to SLEEP\n");
  4589. BTC_TRACE(trace_buf);
  4590. halbtc8821c1ant_write_scbd(btc, BT_8821C_1ANT_SCBD_ACTIVE |
  4591. BT_8821C_1ANT_SCBD_ONOFF |
  4592. BT_8821C_1ANT_SCBD_SCAN |
  4593. BT_8821C_1ANT_SCBD_UNDERTEST,
  4594. FALSE);
  4595. if (pnp_state == BTC_WIFI_PNP_SLEEP_KEEP_ANT) {
  4596. if (wifi_link_info_ext->is_all_under_5g)
  4597. phase = BT_8821C_1ANT_PHASE_5G;
  4598. else
  4599. phase = BT_8821C_1ANT_PHASE_2G;
  4600. } else {
  4601. phase = BT_8821C_1ANT_PHASE_WOFF;
  4602. }
  4603. halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, FC_EXCU,
  4604. phase);
  4605. btc->stop_coex_dm = TRUE;
  4606. } else {
  4607. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4608. "[BTCoex], Pnp notify to WAKE UP\n");
  4609. BTC_TRACE(trace_buf);
  4610. coex_sta->wl_pnp_wakeup_downcnt = 3;
  4611. /*WoWLAN*/
  4612. if (pre_pnp_state == BTC_WIFI_PNP_SLEEP_KEEP_ANT ||
  4613. pnp_state == BTC_WIFI_PNP_WOWLAN) {
  4614. coex_sta->run_time_state = TRUE;
  4615. btc->stop_coex_dm = FALSE;
  4616. halbtc8821c1ant_run_coex(btc, BT_8821C_1ANT_RSN_PNP);
  4617. }
  4618. }
  4619. pre_pnp_state = pnp_state;
  4620. }
  4621. void ex_halbtc8821c1ant_coex_dm_reset(struct btc_coexist *btc)
  4622. {
  4623. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4624. "[BTCoex], *****************Coex DM Reset*****************\n");
  4625. BTC_TRACE(trace_buf);
  4626. halbtc8821c1ant_init_hw_config(btc, FALSE, FALSE);
  4627. halbtc8821c1ant_init_coex_dm(btc);
  4628. }
  4629. void ex_halbtc8821c1ant_periodical(struct btc_coexist *btc)
  4630. {
  4631. struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
  4632. struct btc_board_info *board_info = &btc->board_info;
  4633. boolean wifi_busy = FALSE;
  4634. u16 bt_scoreboard_val = 0;
  4635. boolean bt_relink_finish = FALSE, is_defreeze = FALSE;
  4636. static u8 freeze_cnt;
  4637. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4638. "[BTCoex], ************* Periodical *************\n");
  4639. BTC_TRACE(trace_buf);
  4640. if (!btc->auto_report)
  4641. halbtc8821c1ant_query_bt_info(btc);
  4642. halbtc8821c1ant_monitor_bt_ctr(btc);
  4643. halbtc8821c1ant_monitor_wifi_ctr(btc);
  4644. halbtc8821c1ant_update_wifi_link_info(btc,
  4645. BT_8821C_1ANT_RSN_PERIODICAL);
  4646. halbtc8821c1ant_monitor_bt_enable(btc);
  4647. if (coex_sta->bt_relink_downcount != 0) {
  4648. coex_sta->bt_relink_downcount--;
  4649. if (coex_sta->bt_relink_downcount == 0) {
  4650. coex_sta->is_setup_link = FALSE;
  4651. bt_relink_finish = TRUE;
  4652. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4653. "[BTCoex], Re-Link stop by periodical count-down!!\n");
  4654. BTC_TRACE(trace_buf);
  4655. }
  4656. }
  4657. if (coex_sta->freeze_coexrun_by_btinfo) {
  4658. freeze_cnt++;
  4659. if (freeze_cnt >= 5) {
  4660. freeze_cnt = 0;
  4661. coex_sta->freeze_coexrun_by_btinfo = FALSE;
  4662. is_defreeze = TRUE;
  4663. }
  4664. } else {
  4665. freeze_cnt = 0;
  4666. }
  4667. /* for 4-way, DHCP, EAPOL packet */
  4668. if (coex_sta->specific_pkt_period_cnt > 0) {
  4669. coex_sta->specific_pkt_period_cnt--;
  4670. if (!coex_sta->freeze_coexrun_by_btinfo &&
  4671. coex_sta->specific_pkt_period_cnt == 0)
  4672. coex_sta->wifi_high_pri_task1 = FALSE;
  4673. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4674. "[BTCoex], Hi-Pri Task = %s\n",
  4675. (coex_sta->wifi_high_pri_task1 ? "Yes" : "No"));
  4676. BTC_TRACE(trace_buf);
  4677. }
  4678. /*for A2DP glitch during connecting AP*/
  4679. if (coex_sta->connect_ap_period_cnt > 0)
  4680. coex_sta->connect_ap_period_cnt--;
  4681. if (coex_sta->wl_pnp_wakeup_downcnt > 0) {
  4682. coex_sta->wl_pnp_wakeup_downcnt--;
  4683. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4684. "[BTCoex], wl_pnp_wakeup_downcnt = %d!!\n",
  4685. coex_sta->wl_pnp_wakeup_downcnt);
  4686. BTC_TRACE(trace_buf);
  4687. }
  4688. if (coex_sta->cnt_bt_reenable > 0) {
  4689. coex_sta->cnt_bt_reenable--;
  4690. if (coex_sta->cnt_bt_reenable == 0) {
  4691. coex_sta->is_bt_reenable = FALSE;
  4692. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4693. "[BTCoex], BT renable 30s finish!!\n");
  4694. BTC_TRACE(trace_buf);
  4695. }
  4696. }
  4697. if (halbtc8821c1ant_moniter_wifibt_status(btc) || bt_relink_finish ||
  4698. coex_sta->is_set_ps_state_fail || is_defreeze)
  4699. halbtc8821c1ant_run_coex(btc, BT_8821C_1ANT_RSN_PERIODICAL);
  4700. }
  4701. /*#pragma optimize( "", off )*/
  4702. #endif
  4703. #endif /* #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) */