halbtc8821c1ant.c 155 KB

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