halbtc8812a2ant.c 171 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624
  1. /* ************************************************************
  2. * Description:
  3. *
  4. * This file is for RTL8812A Co-exist mechanism
  5. *
  6. * History
  7. * 2012/08/22 Cosa first check in.
  8. * 2012/11/14 Cosa Revise for 8812A 2Ant out sourcing.
  9. *
  10. * ************************************************************ */
  11. /* ************************************************************
  12. * include files
  13. * ************************************************************ */
  14. #include "mp_precomp.h"
  15. #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1)
  16. #if (RTL8812A_SUPPORT == 1)
  17. /* ************************************************************
  18. * Global variables, these are static variables
  19. * ************************************************************ */
  20. static u8 *trace_buf = &gl_btc_trace_buf[0];
  21. static struct coex_dm_8812a_2ant glcoex_dm_8812a_2ant;
  22. static struct coex_dm_8812a_2ant *coex_dm = &glcoex_dm_8812a_2ant;
  23. static struct coex_sta_8812a_2ant glcoex_sta_8812a_2ant;
  24. static struct coex_sta_8812a_2ant *coex_sta = &glcoex_sta_8812a_2ant;
  25. const char *const glbt_info_src_8812a_2ant[] = {
  26. "BT Info[wifi fw]",
  27. "BT Info[bt rsp]",
  28. "BT Info[bt auto report]",
  29. };
  30. /* ************************************************************
  31. * BtCoex Version Format:
  32. * 1. date : glcoex_ver_date_XXXXX_1ant
  33. * 2. WifiCoexVersion : glcoex_ver_XXXX_1ant
  34. * 3. BtCoexVersion : glcoex_ver_btdesired_XXXXX_1ant
  35. * 4. others : glcoex_ver_XXXXXX_XXXXX_1ant
  36. *
  37. * Variable should be indicated IC and Antenna numbers !!!
  38. * Please strictly follow this order and naming style !!!
  39. *
  40. * ************************************************************ */
  41. u32 glcoex_ver_date_8812a_2ant = 20160818;
  42. u32 glcoex_ver_8812a_2ant = 0x3c;
  43. u32 glcoex_ver_btdesired_8812a_2ant = 0x3c;
  44. /*1. add coex. log for wifi/BT coex. version*/
  45. /* ************************************************************
  46. * local function proto type if needed
  47. * ************************************************************
  48. * ************************************************************
  49. * local function start with halbtc8812a2ant_
  50. * ************************************************************ */
  51. u8 halbtc8812a2ant_bt_rssi_state(u8 level_num, u8 rssi_thresh, u8 rssi_thresh1)
  52. {
  53. s32 bt_rssi = 0;
  54. u8 bt_rssi_state = coex_sta->pre_bt_rssi_state;
  55. bt_rssi = coex_sta->bt_rssi;
  56. if (level_num == 2) {
  57. if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
  58. (coex_sta->pre_bt_rssi_state ==
  59. BTC_RSSI_STATE_STAY_LOW)) {
  60. if (bt_rssi >= (rssi_thresh +
  61. BTC_RSSI_COEX_THRESH_TOL_8812A_2ANT))
  62. bt_rssi_state = BTC_RSSI_STATE_HIGH;
  63. else
  64. bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  65. } else {
  66. if (bt_rssi < rssi_thresh)
  67. bt_rssi_state = BTC_RSSI_STATE_LOW;
  68. else
  69. bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  70. }
  71. } else if (level_num == 3) {
  72. if (rssi_thresh > rssi_thresh1) {
  73. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  74. "[BTCoex], BT Rssi thresh error!!\n");
  75. BTC_TRACE(trace_buf);
  76. return coex_sta->pre_bt_rssi_state;
  77. }
  78. if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
  79. (coex_sta->pre_bt_rssi_state ==
  80. BTC_RSSI_STATE_STAY_LOW)) {
  81. if (bt_rssi >= (rssi_thresh +
  82. BTC_RSSI_COEX_THRESH_TOL_8812A_2ANT))
  83. bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
  84. else
  85. bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  86. } else if ((coex_sta->pre_bt_rssi_state ==
  87. BTC_RSSI_STATE_MEDIUM) ||
  88. (coex_sta->pre_bt_rssi_state ==
  89. BTC_RSSI_STATE_STAY_MEDIUM)) {
  90. if (bt_rssi >= (rssi_thresh1 +
  91. BTC_RSSI_COEX_THRESH_TOL_8812A_2ANT))
  92. bt_rssi_state = BTC_RSSI_STATE_HIGH;
  93. else if (bt_rssi < rssi_thresh)
  94. bt_rssi_state = BTC_RSSI_STATE_LOW;
  95. else
  96. bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
  97. } else {
  98. if (bt_rssi < rssi_thresh1)
  99. bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
  100. else
  101. bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  102. }
  103. }
  104. coex_sta->pre_bt_rssi_state = bt_rssi_state;
  105. return bt_rssi_state;
  106. }
  107. u8 halbtc8812a2ant_wifi_rssi_state(IN struct btc_coexist *btcoexist,
  108. IN u8 index, IN u8 level_num, IN u8 rssi_thresh, IN u8 rssi_thresh1)
  109. {
  110. s32 wifi_rssi = 0;
  111. u8 wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index];
  112. btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
  113. if (level_num == 2) {
  114. if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW)
  115. ||
  116. (coex_sta->pre_wifi_rssi_state[index] ==
  117. BTC_RSSI_STATE_STAY_LOW)) {
  118. if (wifi_rssi >= (rssi_thresh +
  119. BTC_RSSI_COEX_THRESH_TOL_8812A_2ANT))
  120. wifi_rssi_state = BTC_RSSI_STATE_HIGH;
  121. else
  122. wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  123. } else {
  124. if (wifi_rssi < rssi_thresh)
  125. wifi_rssi_state = BTC_RSSI_STATE_LOW;
  126. else
  127. wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  128. }
  129. } else if (level_num == 3) {
  130. if (rssi_thresh > rssi_thresh1) {
  131. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  132. "[BTCoex], wifi RSSI thresh error!!\n");
  133. BTC_TRACE(trace_buf);
  134. return coex_sta->pre_wifi_rssi_state[index];
  135. }
  136. if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW)
  137. ||
  138. (coex_sta->pre_wifi_rssi_state[index] ==
  139. BTC_RSSI_STATE_STAY_LOW)) {
  140. if (wifi_rssi >= (rssi_thresh +
  141. BTC_RSSI_COEX_THRESH_TOL_8812A_2ANT))
  142. wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
  143. else
  144. wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  145. } else if ((coex_sta->pre_wifi_rssi_state[index] ==
  146. BTC_RSSI_STATE_MEDIUM) ||
  147. (coex_sta->pre_wifi_rssi_state[index] ==
  148. BTC_RSSI_STATE_STAY_MEDIUM)) {
  149. if (wifi_rssi >= (rssi_thresh1 +
  150. BTC_RSSI_COEX_THRESH_TOL_8812A_2ANT))
  151. wifi_rssi_state = BTC_RSSI_STATE_HIGH;
  152. else if (wifi_rssi < rssi_thresh)
  153. wifi_rssi_state = BTC_RSSI_STATE_LOW;
  154. else
  155. wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
  156. } else {
  157. if (wifi_rssi < rssi_thresh1)
  158. wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
  159. else
  160. wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  161. }
  162. }
  163. coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state;
  164. return wifi_rssi_state;
  165. }
  166. void halbtc8812a2ant_set_enable_pta(IN struct btc_coexist *btcoexist,
  167. IN boolean enablePTA)
  168. {
  169. if (enablePTA) {
  170. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  171. "[BTCoex], PTA is enable!\n");
  172. BTC_TRACE(trace_buf);
  173. btcoexist->btc_write_1byte(btcoexist, 0x40, 0x20);
  174. } else {
  175. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  176. "[BTCoex], PTA is disable!\n");
  177. BTC_TRACE(trace_buf);
  178. btcoexist->btc_write_1byte(btcoexist, 0x40, 0x00);
  179. }
  180. }
  181. void halbtc8812a2ant_enable_pta(IN struct btc_coexist *btcoexist,
  182. IN boolean force_exec, IN boolean enable)
  183. {
  184. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  185. "[BTCoex], %s turn Enable PTA %s\n",
  186. (force_exec ? "force to" : ""), (enable ? "ON" : "OFF"));
  187. BTC_TRACE(trace_buf);
  188. coex_dm->cur_enable_pta = enable;
  189. if (!force_exec) {
  190. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  191. "[BTCoex], pre_enable_pta = %d, cur_enable_pta = %d!!\n",
  192. coex_dm->pre_enable_pta, coex_dm->cur_enable_pta);
  193. BTC_TRACE(trace_buf);
  194. if (coex_dm->pre_enable_pta == coex_dm->cur_enable_pta)
  195. return;
  196. }
  197. halbtc8812a2ant_set_enable_pta(btcoexist, enable);
  198. coex_dm->pre_enable_pta = coex_dm->cur_enable_pta;
  199. }
  200. u32 halbtc8812a2ant_decide_ra_mask(IN struct btc_coexist *btcoexist,
  201. IN u32 ra_mask_type)
  202. {
  203. u32 dis_ra_mask = 0x0;
  204. switch (ra_mask_type) {
  205. case 0: /* normal mode */
  206. dis_ra_mask = 0x0;
  207. break;
  208. case 1: /* disable cck 1/2 */
  209. dis_ra_mask = 0x00000003;
  210. break;
  211. case 2: /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */
  212. dis_ra_mask = 0x0001f1f7;
  213. break;
  214. default:
  215. break;
  216. }
  217. return dis_ra_mask;
  218. }
  219. void halbtc8812a2ant_update_ra_mask(IN struct btc_coexist *btcoexist,
  220. IN boolean force_exec, IN u32 dis_rate_mask)
  221. {
  222. coex_dm->cur_ra_mask = dis_rate_mask;
  223. if (force_exec || (coex_dm->pre_ra_mask != coex_dm->cur_ra_mask))
  224. btcoexist->btc_set(btcoexist, BTC_SET_ACT_UPDATE_RAMASK,
  225. &coex_dm->cur_ra_mask);
  226. coex_dm->pre_ra_mask = coex_dm->cur_ra_mask;
  227. }
  228. void halbtc8812a2ant_auto_rate_fallback_retry(IN struct btc_coexist *btcoexist,
  229. IN boolean force_exec, IN u8 type)
  230. {
  231. boolean wifi_under_b_mode = false;
  232. coex_dm->cur_arfr_type = type;
  233. if (force_exec || (coex_dm->pre_arfr_type != coex_dm->cur_arfr_type)) {
  234. switch (coex_dm->cur_arfr_type) {
  235. case 0: /* normal mode */
  236. btcoexist->btc_write_4byte(btcoexist, 0x430,
  237. coex_dm->backup_arfr_cnt1);
  238. btcoexist->btc_write_4byte(btcoexist, 0x434,
  239. coex_dm->backup_arfr_cnt2);
  240. break;
  241. case 1:
  242. btcoexist->btc_get(btcoexist,
  243. BTC_GET_BL_WIFI_UNDER_B_MODE,
  244. &wifi_under_b_mode);
  245. if (wifi_under_b_mode) {
  246. btcoexist->btc_write_4byte(btcoexist,
  247. 0x430, 0x0);
  248. btcoexist->btc_write_4byte(btcoexist,
  249. 0x434, 0x01010101);
  250. } else {
  251. btcoexist->btc_write_4byte(btcoexist,
  252. 0x430, 0x0);
  253. btcoexist->btc_write_4byte(btcoexist,
  254. 0x434, 0x04030201);
  255. }
  256. break;
  257. default:
  258. break;
  259. }
  260. }
  261. coex_dm->pre_arfr_type = coex_dm->cur_arfr_type;
  262. }
  263. void halbtc8812a2ant_retry_limit(IN struct btc_coexist *btcoexist,
  264. IN boolean force_exec, IN u8 type)
  265. {
  266. coex_dm->cur_retry_limit_type = type;
  267. if (force_exec ||
  268. (coex_dm->pre_retry_limit_type !=
  269. coex_dm->cur_retry_limit_type)) {
  270. switch (coex_dm->cur_retry_limit_type) {
  271. case 0: /* normal mode */
  272. btcoexist->btc_write_2byte(btcoexist, 0x42a,
  273. coex_dm->backup_retry_limit);
  274. break;
  275. case 1: /* retry limit=8 */
  276. btcoexist->btc_write_2byte(btcoexist, 0x42a,
  277. 0x0808);
  278. break;
  279. default:
  280. break;
  281. }
  282. }
  283. coex_dm->pre_retry_limit_type = coex_dm->cur_retry_limit_type;
  284. }
  285. void halbtc8812a2ant_ampdu_max_time(IN struct btc_coexist *btcoexist,
  286. IN boolean force_exec, IN u8 type)
  287. {
  288. coex_dm->cur_ampdu_time_type = type;
  289. if (force_exec ||
  290. (coex_dm->pre_ampdu_time_type != coex_dm->cur_ampdu_time_type)) {
  291. switch (coex_dm->cur_ampdu_time_type) {
  292. case 0: /* normal mode */
  293. btcoexist->btc_write_1byte(btcoexist, 0x456,
  294. coex_dm->backup_ampdu_max_time);
  295. break;
  296. case 1: /* AMPDU timw = 0x38 * 32us */
  297. btcoexist->btc_write_1byte(btcoexist, 0x456,
  298. 0x38);
  299. break;
  300. default:
  301. break;
  302. }
  303. }
  304. coex_dm->pre_ampdu_time_type = coex_dm->cur_ampdu_time_type;
  305. }
  306. void halbtc8812a2ant_limited_tx(IN struct btc_coexist *btcoexist,
  307. IN boolean force_exec, IN u8 ra_mask_type, IN u8 arfr_type,
  308. IN u8 retry_limit_type, IN u8 ampdu_time_type)
  309. {
  310. u32 dis_ra_mask = 0x0;
  311. coex_dm->cur_ra_mask_type = ra_mask_type;
  312. dis_ra_mask = halbtc8812a2ant_decide_ra_mask(btcoexist, ra_mask_type);
  313. halbtc8812a2ant_update_ra_mask(btcoexist, force_exec, dis_ra_mask);
  314. halbtc8812a2ant_auto_rate_fallback_retry(btcoexist, force_exec,
  315. arfr_type);
  316. halbtc8812a2ant_retry_limit(btcoexist, force_exec, retry_limit_type);
  317. halbtc8812a2ant_ampdu_max_time(btcoexist, force_exec, ampdu_time_type);
  318. }
  319. void halbtc8812a2ant_limited_rx(IN struct btc_coexist *btcoexist,
  320. IN boolean force_exec, IN boolean rej_ap_agg_pkt,
  321. IN boolean bt_ctrl_agg_buf_size, IN u8 agg_buf_size)
  322. {
  323. boolean reject_rx_agg = rej_ap_agg_pkt;
  324. boolean bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size;
  325. u8 rx_agg_size = agg_buf_size;
  326. /* ============================================ */
  327. /* Rx Aggregation related setting */
  328. /* ============================================ */
  329. btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT,
  330. &reject_rx_agg);
  331. /* decide BT control aggregation buf size or not */
  332. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE,
  333. &bt_ctrl_rx_agg_size);
  334. /* aggregation buf size, only work when BT control Rx aggregation size. */
  335. btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size);
  336. /* real update aggregation setting */
  337. btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
  338. }
  339. void halbtc8812a2ant_monitor_bt_ctr(IN struct btc_coexist *btcoexist)
  340. {
  341. u32 reg_hp_txrx, reg_lp_txrx, u32tmp;
  342. u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0;
  343. reg_hp_txrx = 0x770;
  344. reg_lp_txrx = 0x774;
  345. u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx);
  346. reg_hp_tx = u32tmp & MASKLWORD;
  347. reg_hp_rx = (u32tmp & MASKHWORD) >> 16;
  348. u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx);
  349. reg_lp_tx = u32tmp & MASKLWORD;
  350. reg_lp_rx = (u32tmp & MASKHWORD) >> 16;
  351. coex_sta->high_priority_tx = reg_hp_tx;
  352. coex_sta->high_priority_rx = reg_hp_rx;
  353. coex_sta->low_priority_tx = reg_lp_tx;
  354. coex_sta->low_priority_rx = reg_lp_rx;
  355. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  356. "[BTCoex], High Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n",
  357. reg_hp_txrx, reg_hp_tx, reg_hp_tx, reg_hp_rx, reg_hp_rx);
  358. BTC_TRACE(trace_buf);
  359. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  360. "[BTCoex], Low Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n",
  361. reg_lp_txrx, reg_lp_tx, reg_lp_tx, reg_lp_rx, reg_lp_rx);
  362. BTC_TRACE(trace_buf);
  363. /* reset counter */
  364. btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
  365. }
  366. void halbtc8812a2ant_monitor_wifi_ctr(IN struct btc_coexist *btcoexist)
  367. {
  368. #if 1
  369. coex_sta->crc_ok_cck =
  370. btcoexist->btc_phydm_query_PHY_counter(
  371. btcoexist,
  372. PHYDM_INFO_CRC32_OK_CCK);
  373. coex_sta->crc_ok_11g =
  374. btcoexist->btc_phydm_query_PHY_counter(
  375. btcoexist,
  376. PHYDM_INFO_CRC32_OK_LEGACY);
  377. coex_sta->crc_ok_11n =
  378. btcoexist->btc_phydm_query_PHY_counter(
  379. btcoexist,
  380. PHYDM_INFO_CRC32_OK_HT);
  381. coex_sta->crc_ok_11n_vht =
  382. btcoexist->btc_phydm_query_PHY_counter(
  383. btcoexist,
  384. PHYDM_INFO_CRC32_OK_VHT);
  385. coex_sta->crc_err_cck =
  386. btcoexist->btc_phydm_query_PHY_counter(
  387. btcoexist,
  388. PHYDM_INFO_CRC32_ERROR_CCK);
  389. coex_sta->crc_err_11g =
  390. btcoexist->btc_phydm_query_PHY_counter(
  391. btcoexist,
  392. PHYDM_INFO_CRC32_ERROR_LEGACY);
  393. coex_sta->crc_err_11n =
  394. btcoexist->btc_phydm_query_PHY_counter(
  395. btcoexist,
  396. PHYDM_INFO_CRC32_ERROR_HT);
  397. coex_sta->crc_err_11n_vht =
  398. btcoexist->btc_phydm_query_PHY_counter(
  399. btcoexist,
  400. PHYDM_INFO_CRC32_ERROR_VHT);
  401. #endif
  402. }
  403. void halbtc8812a2ant_query_bt_info(IN struct btc_coexist *btcoexist)
  404. {
  405. u8 data_len = 3;
  406. u8 buf[5] = {0};
  407. /* 8812a watch btifo to check BT enable/disable
  408. * if(!btcoexist->bt_info.bt_disabled) */
  409. {
  410. if (!coex_sta->bt_info_query_cnt ||
  411. (coex_sta->bt_info_c2h_cnt[BT_INFO_SRC_8812A_2ANT_BT_RSP]
  412. - coex_sta->bt_info_query_cnt) > 2) {
  413. buf[0] = data_len;
  414. buf[1] = 0x1; /* polling enable, 1=enable, 0=disable */
  415. buf[2] = 0x2; /* polling time in seconds */
  416. buf[3] = 0x1; /* auto report enable, 1=enable, 0=disable */
  417. btcoexist->btc_set(btcoexist, BTC_SET_ACT_CTRL_BT_INFO,
  418. (void *)&buf[0]);
  419. }
  420. }
  421. coex_sta->bt_info_query_cnt++;
  422. }
  423. boolean halbtc8812a2ant_is_wifi_status_changed(IN struct btc_coexist *btcoexist)
  424. {
  425. static boolean pre_wifi_busy = false, pre_under_4way = false,
  426. pre_bt_hs_on = false;
  427. boolean wifi_busy = false, under_4way = false, bt_hs_on = false;
  428. boolean wifi_connected = false;
  429. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  430. &wifi_connected);
  431. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  432. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  433. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
  434. &under_4way);
  435. if (wifi_connected) {
  436. if (wifi_busy != pre_wifi_busy) {
  437. pre_wifi_busy = wifi_busy;
  438. return true;
  439. }
  440. if (under_4way != pre_under_4way) {
  441. pre_under_4way = under_4way;
  442. return true;
  443. }
  444. if (bt_hs_on != pre_bt_hs_on) {
  445. pre_bt_hs_on = bt_hs_on;
  446. return true;
  447. }
  448. }
  449. return false;
  450. }
  451. void halbtc8812a2ant_update_bt_link_info(IN struct btc_coexist *btcoexist)
  452. {
  453. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  454. boolean bt_hs_on = false;
  455. #if 1/* (BT_AUTO_REPORT_ONLY_8812A_2ANT == 1) / profile from bt patch */
  456. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  457. bt_link_info->bt_link_exist = coex_sta->bt_link_exist;
  458. bt_link_info->sco_exist = coex_sta->sco_exist;
  459. bt_link_info->a2dp_exist = coex_sta->a2dp_exist;
  460. bt_link_info->pan_exist = coex_sta->pan_exist;
  461. bt_link_info->hid_exist = coex_sta->hid_exist;
  462. bt_link_info->acl_busy = coex_sta->acl_busy;
  463. /* work around for HS mode. */
  464. if (bt_hs_on) {
  465. bt_link_info->pan_exist = true;
  466. bt_link_info->bt_link_exist = true;
  467. }
  468. #else /* profile from bt stack */
  469. bt_link_info->bt_link_exist = stack_info->bt_link_exist;
  470. bt_link_info->sco_exist = stack_info->sco_exist;
  471. bt_link_info->a2dp_exist = stack_info->a2dp_exist;
  472. bt_link_info->pan_exist = stack_info->pan_exist;
  473. bt_link_info->hid_exist = stack_info->hid_exist;
  474. /* for win-8 stack HID report error */
  475. if (!stack_info->hid_exist)
  476. stack_info->hid_exist =
  477. coex_sta->hid_exist; /* sync BTInfo with BT firmware and stack */
  478. /* when stack HID report error, here we use the info from bt fw. */
  479. if (!stack_info->bt_link_exist)
  480. stack_info->bt_link_exist = coex_sta->bt_link_exist;
  481. #endif
  482. /* check if Sco only */
  483. if (bt_link_info->sco_exist &&
  484. !bt_link_info->a2dp_exist &&
  485. !bt_link_info->pan_exist &&
  486. !bt_link_info->hid_exist)
  487. bt_link_info->sco_only = true;
  488. else
  489. bt_link_info->sco_only = false;
  490. /* check if A2dp only */
  491. if (!bt_link_info->sco_exist &&
  492. bt_link_info->a2dp_exist &&
  493. !bt_link_info->pan_exist &&
  494. !bt_link_info->hid_exist)
  495. bt_link_info->a2dp_only = true;
  496. else
  497. bt_link_info->a2dp_only = false;
  498. /* check if Pan only */
  499. if (!bt_link_info->sco_exist &&
  500. !bt_link_info->a2dp_exist &&
  501. bt_link_info->pan_exist &&
  502. !bt_link_info->hid_exist)
  503. bt_link_info->pan_only = true;
  504. else
  505. bt_link_info->pan_only = false;
  506. /* check if Hid only */
  507. if (!bt_link_info->sco_exist &&
  508. !bt_link_info->a2dp_exist &&
  509. !bt_link_info->pan_exist &&
  510. bt_link_info->hid_exist)
  511. bt_link_info->hid_only = true;
  512. else
  513. bt_link_info->hid_only = false;
  514. }
  515. u8 halbtc8812a2ant_action_algorithm(IN struct btc_coexist *btcoexist)
  516. {
  517. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  518. struct btc_stack_info *stack_info = &btcoexist->stack_info;
  519. boolean bt_hs_on = false;
  520. u8 algorithm = BT_8812A_2ANT_COEX_ALGO_UNDEFINED;
  521. u8 num_of_diff_profile = 0;
  522. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  523. if (!bt_link_info->bt_link_exist) {
  524. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  525. "[BTCoex], No BT link exists!!!\n");
  526. BTC_TRACE(trace_buf);
  527. return algorithm;
  528. }
  529. if (bt_link_info->sco_exist)
  530. num_of_diff_profile++;
  531. if (bt_link_info->hid_exist)
  532. num_of_diff_profile++;
  533. if (bt_link_info->pan_exist)
  534. num_of_diff_profile++;
  535. if (bt_link_info->a2dp_exist)
  536. num_of_diff_profile++;
  537. if (num_of_diff_profile == 0) {
  538. if (bt_link_info->acl_busy) {
  539. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  540. "[BTCoex], ACL Busy only\n");
  541. BTC_TRACE(trace_buf);
  542. algorithm = BT_8812A_2ANT_COEX_ALGO_PANEDR;
  543. }
  544. } else if (num_of_diff_profile == 1) {
  545. if (bt_link_info->sco_exist) {
  546. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  547. "[BTCoex], SCO only\n");
  548. BTC_TRACE(trace_buf);
  549. algorithm = BT_8812A_2ANT_COEX_ALGO_SCO;
  550. } else {
  551. if (bt_link_info->hid_exist) {
  552. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  553. "[BTCoex], HID only\n");
  554. BTC_TRACE(trace_buf);
  555. algorithm = BT_8812A_2ANT_COEX_ALGO_HID;
  556. } else if (bt_link_info->a2dp_exist) {
  557. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  558. "[BTCoex], A2DP only\n");
  559. BTC_TRACE(trace_buf);
  560. algorithm = BT_8812A_2ANT_COEX_ALGO_A2DP;
  561. } else if (bt_link_info->pan_exist) {
  562. if (bt_hs_on) {
  563. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  564. "[BTCoex], PAN(HS) only\n");
  565. BTC_TRACE(trace_buf);
  566. algorithm =
  567. BT_8812A_2ANT_COEX_ALGO_PANHS;
  568. } else {
  569. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  570. "[BTCoex], PAN(EDR) only\n");
  571. BTC_TRACE(trace_buf);
  572. algorithm =
  573. BT_8812A_2ANT_COEX_ALGO_PANEDR;
  574. }
  575. }
  576. }
  577. } else if (num_of_diff_profile == 2) {
  578. if (bt_link_info->sco_exist) {
  579. if (bt_link_info->hid_exist) {
  580. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  581. "[BTCoex], SCO + HID\n");
  582. BTC_TRACE(trace_buf);
  583. algorithm = BT_8812A_2ANT_COEX_ALGO_SCO_HID;
  584. } else if (bt_link_info->a2dp_exist) {
  585. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  586. "[BTCoex], SCO + A2DP ==> SCO\n");
  587. BTC_TRACE(trace_buf);
  588. algorithm = BT_8812A_2ANT_COEX_ALGO_PANEDR_HID;
  589. } else if (bt_link_info->pan_exist) {
  590. if (bt_hs_on) {
  591. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  592. "[BTCoex], SCO + PAN(HS)\n");
  593. BTC_TRACE(trace_buf);
  594. algorithm = BT_8812A_2ANT_COEX_ALGO_SCO;
  595. } else {
  596. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  597. "[BTCoex], SCO + PAN(EDR)\n");
  598. BTC_TRACE(trace_buf);
  599. algorithm = BT_8812A_2ANT_COEX_ALGO_SCO;
  600. }
  601. }
  602. } else {
  603. if (bt_link_info->hid_exist &&
  604. bt_link_info->a2dp_exist) {
  605. if (stack_info->num_of_hid >= 2) {
  606. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  607. "[BTCoex], HID*2 + A2DP\n");
  608. BTC_TRACE(trace_buf);
  609. algorithm =
  610. BT_8812A_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
  611. } else {
  612. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  613. "[BTCoex], HID + A2DP\n");
  614. BTC_TRACE(trace_buf);
  615. algorithm =
  616. BT_8812A_2ANT_COEX_ALGO_HID_A2DP;
  617. }
  618. } else if (bt_link_info->hid_exist &&
  619. bt_link_info->pan_exist) {
  620. if (bt_hs_on) {
  621. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  622. "[BTCoex], HID + PAN(HS)\n");
  623. BTC_TRACE(trace_buf);
  624. algorithm =
  625. BT_8812A_2ANT_COEX_ALGO_HID;
  626. } else {
  627. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  628. "[BTCoex], HID + PAN(EDR)\n");
  629. BTC_TRACE(trace_buf);
  630. algorithm =
  631. BT_8812A_2ANT_COEX_ALGO_PANEDR_HID;
  632. }
  633. } else if (bt_link_info->pan_exist &&
  634. bt_link_info->a2dp_exist) {
  635. if (bt_hs_on) {
  636. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  637. "[BTCoex], A2DP + PAN(HS)\n");
  638. BTC_TRACE(trace_buf);
  639. algorithm =
  640. BT_8812A_2ANT_COEX_ALGO_A2DP_PANHS;
  641. } else {
  642. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  643. "[BTCoex], A2DP + PAN(EDR)\n");
  644. BTC_TRACE(trace_buf);
  645. algorithm =
  646. BT_8812A_2ANT_COEX_ALGO_PANEDR_A2DP;
  647. }
  648. }
  649. }
  650. } else if (num_of_diff_profile == 3) {
  651. if (bt_link_info->sco_exist) {
  652. if (bt_link_info->hid_exist &&
  653. bt_link_info->a2dp_exist) {
  654. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  655. "[BTCoex], SCO + HID + A2DP ==> HID\n");
  656. BTC_TRACE(trace_buf);
  657. algorithm = BT_8812A_2ANT_COEX_ALGO_PANEDR_HID;
  658. } else if (bt_link_info->hid_exist &&
  659. bt_link_info->pan_exist) {
  660. if (bt_hs_on) {
  661. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  662. "[BTCoex], SCO + HID + PAN(HS)\n");
  663. BTC_TRACE(trace_buf);
  664. algorithm =
  665. BT_8812A_2ANT_COEX_ALGO_SCO_HID;
  666. } else {
  667. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  668. "[BTCoex], SCO + HID + PAN(EDR)\n");
  669. BTC_TRACE(trace_buf);
  670. algorithm =
  671. BT_8812A_2ANT_COEX_ALGO_SCO_HID;
  672. }
  673. } else if (bt_link_info->pan_exist &&
  674. bt_link_info->a2dp_exist) {
  675. if (bt_hs_on) {
  676. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  677. "[BTCoex], SCO + A2DP + PAN(HS)\n");
  678. BTC_TRACE(trace_buf);
  679. algorithm = BT_8812A_2ANT_COEX_ALGO_SCO;
  680. } else {
  681. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  682. "[BTCoex], SCO + A2DP + PAN(EDR) ==> HID\n");
  683. BTC_TRACE(trace_buf);
  684. algorithm =
  685. BT_8812A_2ANT_COEX_ALGO_PANEDR_HID;
  686. }
  687. }
  688. } else {
  689. if (bt_link_info->hid_exist &&
  690. bt_link_info->pan_exist &&
  691. bt_link_info->a2dp_exist) {
  692. if (bt_hs_on) {
  693. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  694. "[BTCoex], HID + A2DP + PAN(HS)\n");
  695. BTC_TRACE(trace_buf);
  696. algorithm =
  697. BT_8812A_2ANT_COEX_ALGO_HID_A2DP_PANHS;
  698. } else {
  699. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  700. "[BTCoex], HID + A2DP + PAN(EDR)\n");
  701. BTC_TRACE(trace_buf);
  702. algorithm =
  703. BT_8812A_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
  704. }
  705. }
  706. }
  707. } else if (num_of_diff_profile >= 3) {
  708. if (bt_link_info->sco_exist) {
  709. if (bt_link_info->hid_exist &&
  710. bt_link_info->pan_exist &&
  711. bt_link_info->a2dp_exist) {
  712. if (bt_hs_on) {
  713. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  714. "[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n");
  715. BTC_TRACE(trace_buf);
  716. } else {
  717. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  718. "[BTCoex], SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n");
  719. BTC_TRACE(trace_buf);
  720. algorithm =
  721. BT_8812A_2ANT_COEX_ALGO_PANEDR_HID;
  722. }
  723. }
  724. }
  725. }
  726. return algorithm;
  727. }
  728. void halbtc8812a2ant_set_fw_dac_swing_level(IN struct btc_coexist *btcoexist,
  729. IN u8 dac_swing_lvl)
  730. {
  731. u8 h2c_parameter[1] = {0};
  732. /* There are several type of dacswing */
  733. /* 0x18/ 0x10/ 0xc/ 0x8/ 0x4/ 0x6 */
  734. h2c_parameter[0] = dac_swing_lvl;
  735. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  736. "[BTCoex], Set Dac Swing Level=0x%x\n",
  737. dac_swing_lvl);
  738. BTC_TRACE(trace_buf);
  739. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  740. "[BTCoex], FW write 0x64=0x%x\n",
  741. h2c_parameter[0]);
  742. BTC_TRACE(trace_buf);
  743. btcoexist->btc_fill_h2c(btcoexist, 0x64, 1, h2c_parameter);
  744. }
  745. void halbtc8812a2ant_set_fw_dec_bt_pwr(IN struct btc_coexist *btcoexist,
  746. IN u8 dec_bt_pwr_lvl)
  747. {
  748. u8 data_len = 4;
  749. u8 buf[6] = {0};
  750. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  751. "[BTCoex], decrease Bt Power level = %d\n",
  752. dec_bt_pwr_lvl);
  753. BTC_TRACE(trace_buf);
  754. buf[0] = data_len;
  755. buf[1] = 0x3; /* OP_Code */
  756. buf[2] = 0x2; /* OP_Code_Length */
  757. if (dec_bt_pwr_lvl)
  758. buf[3] = 0x1; /* OP_Code_Content */
  759. else
  760. buf[3] = 0x0;
  761. buf[4] = dec_bt_pwr_lvl;/* pwr_level */
  762. btcoexist->btc_set(btcoexist, BTC_SET_ACT_CTRL_BT_COEX,
  763. (void *)&buf[0]);
  764. }
  765. void halbtc8812a2ant_dec_bt_pwr(IN struct btc_coexist *btcoexist,
  766. IN boolean force_exec, IN u8 dec_bt_pwr_lvl)
  767. {
  768. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  769. "[BTCoex], %s Dec BT power level = %d\n",
  770. (force_exec ? "force to" : ""), dec_bt_pwr_lvl);
  771. BTC_TRACE(trace_buf);
  772. coex_dm->cur_bt_dec_pwr_lvl = dec_bt_pwr_lvl;
  773. if (!force_exec) {
  774. if (coex_dm->pre_bt_dec_pwr_lvl == coex_dm->cur_bt_dec_pwr_lvl)
  775. return;
  776. }
  777. halbtc8812a2ant_set_fw_dec_bt_pwr(btcoexist,
  778. coex_dm->cur_bt_dec_pwr_lvl);
  779. coex_dm->pre_bt_dec_pwr_lvl = coex_dm->cur_bt_dec_pwr_lvl;
  780. }
  781. void halbtc8812a2ant_fw_dac_swing_lvl(IN struct btc_coexist *btcoexist,
  782. IN boolean force_exec, IN u8 fw_dac_swing_lvl)
  783. {
  784. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  785. "[BTCoex], %s set FW Dac Swing level = %d\n",
  786. (force_exec ? "force to" : ""), fw_dac_swing_lvl);
  787. BTC_TRACE(trace_buf);
  788. coex_dm->cur_fw_dac_swing_lvl = fw_dac_swing_lvl;
  789. if (!force_exec) {
  790. if (coex_dm->pre_fw_dac_swing_lvl ==
  791. coex_dm->cur_fw_dac_swing_lvl)
  792. return;
  793. }
  794. halbtc8812a2ant_set_fw_dac_swing_level(btcoexist,
  795. coex_dm->cur_fw_dac_swing_lvl);
  796. coex_dm->pre_fw_dac_swing_lvl = coex_dm->cur_fw_dac_swing_lvl;
  797. }
  798. void halbtc8812a2ant_set_sw_rf_rx_lpf_corner(IN struct btc_coexist *btcoexist,
  799. IN boolean rx_rf_shrink_on)
  800. {
  801. if (rx_rf_shrink_on) {
  802. /* Shrink RF Rx LPF corner */
  803. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  804. "[BTCoex], Shrink RF Rx LPF corner!!\n");
  805. BTC_TRACE(trace_buf);
  806. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1e, 0xfffff,
  807. 0xffffc);
  808. } else {
  809. /* Resume RF Rx LPF corner */
  810. /* After initialized, we can use coex_dm->bt_rf_0x1e_backup */
  811. if (btcoexist->initilized) {
  812. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  813. "[BTCoex], Resume RF Rx LPF corner!!\n");
  814. BTC_TRACE(trace_buf);
  815. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1e,
  816. 0xfffff, coex_dm->bt_rf_0x1e_backup);
  817. }
  818. }
  819. }
  820. void halbtc8812a2ant_rf_shrink(IN struct btc_coexist *btcoexist,
  821. IN boolean force_exec, IN boolean rx_rf_shrink_on)
  822. {
  823. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  824. "[BTCoex], %s turn Rx RF Shrink = %s\n",
  825. (force_exec ? "force to" : ""),
  826. ((rx_rf_shrink_on) ? "ON" : "OFF"));
  827. BTC_TRACE(trace_buf);
  828. coex_dm->cur_rf_rx_lpf_shrink = rx_rf_shrink_on;
  829. if (!force_exec) {
  830. if (coex_dm->pre_rf_rx_lpf_shrink ==
  831. coex_dm->cur_rf_rx_lpf_shrink)
  832. return;
  833. }
  834. halbtc8812a2ant_set_sw_rf_rx_lpf_corner(btcoexist,
  835. coex_dm->cur_rf_rx_lpf_shrink);
  836. coex_dm->pre_rf_rx_lpf_shrink = coex_dm->cur_rf_rx_lpf_shrink;
  837. }
  838. void halbtc8812a2ant_set_sw_penalty_tx_rate_adaptive(IN struct btc_coexist
  839. *btcoexist, IN boolean low_penalty_ra)
  840. {
  841. u8 tmp_u1;
  842. tmp_u1 = btcoexist->btc_read_1byte(btcoexist, 0x4fd);
  843. tmp_u1 |= BIT(0);
  844. if (low_penalty_ra) {
  845. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  846. "[BTCoex], Tx rate adaptive, set low penalty!!\n");
  847. BTC_TRACE(trace_buf);
  848. tmp_u1 &= ~BIT(2);
  849. } else {
  850. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  851. "[BTCoex], Tx rate adaptive, set normal!!\n");
  852. BTC_TRACE(trace_buf);
  853. tmp_u1 |= BIT(2);
  854. }
  855. btcoexist->btc_write_1byte(btcoexist, 0x4fd, tmp_u1);
  856. }
  857. void halbtc8812a2ant_low_penalty_ra(IN struct btc_coexist *btcoexist,
  858. IN boolean force_exec, IN boolean low_penalty_ra)
  859. {
  860. return;
  861. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  862. "[BTCoex], %s turn LowPenaltyRA = %s\n",
  863. (force_exec ? "force to" : ""),
  864. ((low_penalty_ra) ? "ON" : "OFF"));
  865. BTC_TRACE(trace_buf);
  866. coex_dm->cur_low_penalty_ra = low_penalty_ra;
  867. if (!force_exec) {
  868. if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra)
  869. return;
  870. }
  871. halbtc8812a2ant_set_sw_penalty_tx_rate_adaptive(btcoexist,
  872. coex_dm->cur_low_penalty_ra);
  873. coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra;
  874. }
  875. void halbtc8812a2ant_set_dac_swing_reg(IN struct btc_coexist *btcoexist,
  876. IN u32 level)
  877. {
  878. u8 val = (u8)level;
  879. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  880. "[BTCoex], Write SwDacSwing = 0x%x\n",
  881. level);
  882. BTC_TRACE(trace_buf);
  883. btcoexist->btc_write_1byte_bitmask(btcoexist, 0xc5b, 0x3e, val);
  884. }
  885. void halbtc8812a2ant_set_sw_full_time_dac_swing(IN struct btc_coexist
  886. *btcoexist, IN boolean sw_dac_swing_on, IN u32 sw_dac_swing_lvl)
  887. {
  888. if (sw_dac_swing_on)
  889. halbtc8812a2ant_set_dac_swing_reg(btcoexist, sw_dac_swing_lvl);
  890. else
  891. halbtc8812a2ant_set_dac_swing_reg(btcoexist, 0x18);
  892. }
  893. void halbtc8812a2ant_dac_swing(IN struct btc_coexist *btcoexist,
  894. IN boolean force_exec, IN boolean dac_swing_on, IN u32 dac_swing_lvl)
  895. {
  896. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  897. "[BTCoex], %s turn DacSwing=%s, dac_swing_lvl=0x%x\n",
  898. (force_exec ? "force to" : ""), ((dac_swing_on) ? "ON" : "OFF"),
  899. dac_swing_lvl);
  900. BTC_TRACE(trace_buf);
  901. coex_dm->cur_dac_swing_on = dac_swing_on;
  902. coex_dm->cur_dac_swing_lvl = dac_swing_lvl;
  903. if (!force_exec) {
  904. if ((coex_dm->pre_dac_swing_on == coex_dm->cur_dac_swing_on) &&
  905. (coex_dm->pre_dac_swing_lvl ==
  906. coex_dm->cur_dac_swing_lvl))
  907. return;
  908. }
  909. delay_ms(30);
  910. halbtc8812a2ant_set_sw_full_time_dac_swing(btcoexist, dac_swing_on,
  911. dac_swing_lvl);
  912. coex_dm->pre_dac_swing_on = coex_dm->cur_dac_swing_on;
  913. coex_dm->pre_dac_swing_lvl = coex_dm->cur_dac_swing_lvl;
  914. }
  915. void halbtc8812a2ant_set_adc_back_off(IN struct btc_coexist *btcoexist,
  916. IN boolean adc_back_off)
  917. {
  918. if (adc_back_off) {
  919. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  920. "[BTCoex], BB BackOff Level On!\n");
  921. BTC_TRACE(trace_buf);
  922. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x8db, 0x60, 0x3);
  923. } else {
  924. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  925. "[BTCoex], BB BackOff Level Off!\n");
  926. BTC_TRACE(trace_buf);
  927. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x8db, 0x60, 0x1);
  928. }
  929. }
  930. void halbtc8812a2ant_adc_back_off(IN struct btc_coexist *btcoexist,
  931. IN boolean force_exec, IN boolean adc_back_off)
  932. {
  933. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  934. "[BTCoex], %s turn AdcBackOff = %s\n",
  935. (force_exec ? "force to" : ""),
  936. ((adc_back_off) ? "ON" : "OFF"));
  937. BTC_TRACE(trace_buf);
  938. coex_dm->cur_adc_back_off = adc_back_off;
  939. if (!force_exec) {
  940. if (coex_dm->pre_adc_back_off == coex_dm->cur_adc_back_off)
  941. return;
  942. }
  943. halbtc8812a2ant_set_adc_back_off(btcoexist, coex_dm->cur_adc_back_off);
  944. coex_dm->pre_adc_back_off = coex_dm->cur_adc_back_off;
  945. }
  946. void halbtc8812a2ant_set_agc_table(IN struct btc_coexist *btcoexist,
  947. IN boolean agc_table_en)
  948. {
  949. u8 rssi_adjust_val = 0;
  950. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xef, 0xfffff, 0x02000);
  951. if (agc_table_en) {
  952. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  953. "[BTCoex], Agc Table On!\n");
  954. BTC_TRACE(trace_buf);
  955. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x3b, 0xfffff,
  956. 0x28F4B);
  957. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x3b, 0xfffff,
  958. 0x10AB2);
  959. rssi_adjust_val = 8;
  960. } else {
  961. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  962. "[BTCoex], Agc Table Off!\n");
  963. BTC_TRACE(trace_buf);
  964. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x3b, 0xfffff,
  965. 0x2884B);
  966. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x3b, 0xfffff,
  967. 0x104B2);
  968. }
  969. btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xef, 0xfffff, 0x0);
  970. /* set rssi_adjust_val for wifi module. */
  971. btcoexist->btc_set(btcoexist, BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON,
  972. &rssi_adjust_val);
  973. }
  974. void halbtc8812a2ant_agc_table(IN struct btc_coexist *btcoexist,
  975. IN boolean force_exec, IN boolean agc_table_en)
  976. {
  977. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], %s %s Agc Table\n",
  978. (force_exec ? "force to" : ""),
  979. ((agc_table_en) ? "Enable" : "Disable"));
  980. BTC_TRACE(trace_buf);
  981. coex_dm->cur_agc_table_en = agc_table_en;
  982. if (!force_exec) {
  983. if (coex_dm->pre_agc_table_en == coex_dm->cur_agc_table_en)
  984. return;
  985. }
  986. halbtc8812a2ant_set_agc_table(btcoexist, agc_table_en);
  987. coex_dm->pre_agc_table_en = coex_dm->cur_agc_table_en;
  988. }
  989. void halbtc8812a2ant_set_coex_table(IN struct btc_coexist *btcoexist,
  990. IN u32 val0x6c0, IN u32 val0x6c4, IN u32 val0x6c8, IN u8 val0x6cc)
  991. {
  992. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  993. "[BTCoex], set coex table, set 0x6c0=0x%x\n", val0x6c0);
  994. BTC_TRACE(trace_buf);
  995. btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0);
  996. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  997. "[BTCoex], set coex table, set 0x6c4=0x%x\n", val0x6c4);
  998. BTC_TRACE(trace_buf);
  999. btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4);
  1000. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1001. "[BTCoex], set coex table, set 0x6c8=0x%x\n", val0x6c8);
  1002. BTC_TRACE(trace_buf);
  1003. btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8);
  1004. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1005. "[BTCoex], set coex table, set 0x6cc=0x%x\n", val0x6cc);
  1006. BTC_TRACE(trace_buf);
  1007. btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc);
  1008. }
  1009. void halbtc8812a2ant_coex_table(IN struct btc_coexist *btcoexist,
  1010. IN boolean force_exec, IN u32 val0x6c0, IN u32 val0x6c4,
  1011. IN u32 val0x6c8, IN u8 val0x6cc)
  1012. {
  1013. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1014. "[BTCoex], %s write Coex Table 0x6c0=0x%x, 0x6c4=0x%x, 0x6c8=0x%x, 0x6cc=0x%x\n",
  1015. (force_exec ? "force to" : ""), val0x6c0, val0x6c4, val0x6c8,
  1016. val0x6cc);
  1017. BTC_TRACE(trace_buf);
  1018. coex_dm->cur_val0x6c0 = val0x6c0;
  1019. coex_dm->cur_val0x6c4 = val0x6c4;
  1020. coex_dm->cur_val0x6c8 = val0x6c8;
  1021. coex_dm->cur_val0x6cc = val0x6cc;
  1022. if (!force_exec) {
  1023. if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) &&
  1024. (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) &&
  1025. (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) &&
  1026. (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc))
  1027. return;
  1028. }
  1029. halbtc8812a2ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8,
  1030. val0x6cc);
  1031. coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0;
  1032. coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4;
  1033. coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8;
  1034. coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc;
  1035. }
  1036. void halbtc8812a2ant_coex_table_with_type(IN struct btc_coexist *btcoexist,
  1037. IN boolean force_exec, IN u8 type)
  1038. {
  1039. switch (type) {
  1040. case 0:
  1041. halbtc8812a2ant_coex_table(btcoexist, force_exec,
  1042. 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3);
  1043. break;
  1044. case 1:
  1045. halbtc8812a2ant_coex_table(btcoexist, force_exec,
  1046. 0x5a5a5a5a, 0x5a5a5a5a, 0xffffff, 0x3);
  1047. break;
  1048. case 2:
  1049. halbtc8812a2ant_coex_table(btcoexist, force_exec,
  1050. 0x55555555, 0x5ffb5ffb, 0xffffff, 0x3);
  1051. break;
  1052. case 3:
  1053. halbtc8812a2ant_coex_table(btcoexist, force_exec,
  1054. 0x5fdf5fdf, 0x5fdb5fdb, 0xffffff, 0x3);
  1055. break;
  1056. case 4:
  1057. halbtc8812a2ant_coex_table(btcoexist, force_exec,
  1058. 0xdfffdfff, 0x5fdb5fdb, 0xffffff, 0x3);
  1059. break;
  1060. case 5:
  1061. halbtc8812a2ant_coex_table(btcoexist, force_exec,
  1062. 0x5ddd5ddd, 0x5fdb5fdb, 0xffffff, 0x3);
  1063. break;
  1064. case 6:
  1065. halbtc8812a2ant_coex_table(btcoexist, force_exec,
  1066. 0x5fff5fff, 0x5a5a5a5a, 0xffffff, 0x3);
  1067. break;
  1068. case 7:
  1069. if (coex_sta->scan_ap_num <= 5)
  1070. halbtc8812a2ant_coex_table(btcoexist,
  1071. force_exec, 0xffffffff, 0xfafafafa,
  1072. 0xffffff, 0x3);
  1073. else
  1074. halbtc8812a2ant_coex_table(btcoexist,
  1075. force_exec, 0xffffffff, 0x5a5a5a5a,
  1076. 0xffffff, 0x3);
  1077. break;
  1078. case 8:
  1079. halbtc8812a2ant_coex_table(btcoexist, force_exec,
  1080. 0x5f5f5f5f, 0x5a5a5a5a, 0xffffff, 0x3);
  1081. break;
  1082. default:
  1083. break;
  1084. }
  1085. }
  1086. void halbtc8812a2ant_set_fw_ignore_wlan_act(IN struct btc_coexist *btcoexist,
  1087. IN boolean enable)
  1088. {
  1089. u8 data_len = 3;
  1090. u8 buf[5] = {0};
  1091. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1092. "[BTCoex], %s BT Ignore Wlan_Act\n",
  1093. (enable ? "Enable" : "Disable"));
  1094. BTC_TRACE(trace_buf);
  1095. buf[0] = data_len;
  1096. buf[1] = 0x1; /* OP_Code */
  1097. buf[2] = 0x1; /* OP_Code_Length */
  1098. if (enable)
  1099. buf[3] = 0x1; /* OP_Code_Content */
  1100. else
  1101. buf[3] = 0x0;
  1102. btcoexist->btc_set(btcoexist, BTC_SET_ACT_CTRL_BT_COEX,
  1103. (void *)&buf[0]);
  1104. }
  1105. void halbtc8812a2ant_ignore_wlan_act(IN struct btc_coexist *btcoexist,
  1106. IN boolean force_exec, IN boolean enable)
  1107. {
  1108. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1109. "[BTCoex], %s turn Ignore WlanAct %s\n",
  1110. (force_exec ? "force to" : ""), (enable ? "ON" : "OFF"));
  1111. BTC_TRACE(trace_buf);
  1112. coex_dm->cur_ignore_wlan_act = enable;
  1113. if (!force_exec) {
  1114. if (coex_dm->pre_ignore_wlan_act ==
  1115. coex_dm->cur_ignore_wlan_act)
  1116. return;
  1117. }
  1118. halbtc8812a2ant_set_fw_ignore_wlan_act(btcoexist, enable);
  1119. coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act;
  1120. }
  1121. void halbtc8812a2ant_set_fw_pstdma(IN struct btc_coexist *btcoexist,
  1122. IN u8 byte1, IN u8 byte2, IN u8 byte3, IN u8 byte4, IN u8 byte5)
  1123. {
  1124. u8 h2c_parameter[5] = {0};
  1125. u8 real_byte1 = byte1, real_byte5 = byte5;
  1126. boolean ap_enable = false;
  1127. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
  1128. &ap_enable);
  1129. if (ap_enable) {
  1130. if (byte1 & BIT(4) && !(byte1 & BIT(5))) {
  1131. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1132. "[BTCoex], FW for 1Ant AP mode\n");
  1133. BTC_TRACE(trace_buf);
  1134. real_byte1 &= ~BIT(4);
  1135. real_byte1 |= BIT(5);
  1136. real_byte5 |= BIT(5);
  1137. real_byte5 &= ~BIT(6);
  1138. }
  1139. }
  1140. h2c_parameter[0] = real_byte1;
  1141. h2c_parameter[1] = byte2;
  1142. h2c_parameter[2] = byte3;
  1143. h2c_parameter[3] = byte4;
  1144. h2c_parameter[4] = real_byte5;
  1145. coex_dm->ps_tdma_para[0] = real_byte1;
  1146. coex_dm->ps_tdma_para[1] = byte2;
  1147. coex_dm->ps_tdma_para[2] = byte3;
  1148. coex_dm->ps_tdma_para[3] = byte4;
  1149. coex_dm->ps_tdma_para[4] = real_byte5;
  1150. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1151. "[BTCoex], PS-TDMA H2C cmd =0x%x%08x\n",
  1152. h2c_parameter[0],
  1153. h2c_parameter[1] << 24 | h2c_parameter[2] << 16 |
  1154. h2c_parameter[3] << 8 | h2c_parameter[4]);
  1155. BTC_TRACE(trace_buf);
  1156. btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter);
  1157. }
  1158. void halbtc8812a2ant_set_lps_rpwm(IN struct btc_coexist *btcoexist,
  1159. IN u8 lps_val, IN u8 rpwm_val)
  1160. {
  1161. u8 lps = lps_val;
  1162. u8 rpwm = rpwm_val;
  1163. btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps);
  1164. btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
  1165. }
  1166. void halbtc8812a2ant_lps_rpwm(IN struct btc_coexist *btcoexist,
  1167. IN boolean force_exec, IN u8 lps_val, IN u8 rpwm_val)
  1168. {
  1169. coex_dm->cur_lps = lps_val;
  1170. coex_dm->cur_rpwm = rpwm_val;
  1171. if (!force_exec) {
  1172. if ((coex_dm->pre_lps == coex_dm->cur_lps) &&
  1173. (coex_dm->pre_rpwm == coex_dm->cur_rpwm))
  1174. return;
  1175. }
  1176. halbtc8812a2ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val);
  1177. coex_dm->pre_lps = coex_dm->cur_lps;
  1178. coex_dm->pre_rpwm = coex_dm->cur_rpwm;
  1179. }
  1180. void halbtc8812a2ant_sw_mechanism1(IN struct btc_coexist *btcoexist,
  1181. IN boolean shrink_rx_lpf, IN boolean low_penalty_ra,
  1182. IN boolean limited_dig, IN boolean bt_lna_constrain)
  1183. {
  1184. /*
  1185. u32 wifi_bw;
  1186. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  1187. if(BTC_WIFI_BW_HT40 != wifi_bw)
  1188. {
  1189. if (shrink_rx_lpf)
  1190. shrink_rx_lpf = false;
  1191. }
  1192. */
  1193. halbtc8812a2ant_rf_shrink(btcoexist, NORMAL_EXEC, shrink_rx_lpf);
  1194. /* halbtc8812a2ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra); */
  1195. }
  1196. void halbtc8812a2ant_sw_mechanism2(IN struct btc_coexist *btcoexist,
  1197. IN boolean agc_table_shift, IN boolean adc_back_off,
  1198. IN boolean sw_dac_swing, IN u32 dac_swing_lvl)
  1199. {
  1200. /* halbtc8812a2ant_agc_table(btcoexist, NORMAL_EXEC, agc_table_shift); */
  1201. halbtc8812a2ant_adc_back_off(btcoexist, NORMAL_EXEC, adc_back_off);
  1202. halbtc8812a2ant_dac_swing(btcoexist, NORMAL_EXEC, sw_dac_swing,
  1203. dac_swing_lvl);
  1204. }
  1205. void halbtc8812a2ant_set_ant_path(IN struct btc_coexist *btcoexist,
  1206. IN u8 ant_pos_type, IN boolean init_hwcfg, IN boolean wifi_off)
  1207. {
  1208. u8 u8tmp = 0;
  1209. if (init_hwcfg) {
  1210. btcoexist->btc_write_4byte(btcoexist, 0x900, 0x00000400);
  1211. btcoexist->btc_write_1byte(btcoexist, 0x76d, 0x1);
  1212. } else if (wifi_off) {
  1213. }
  1214. /* ext switch setting */
  1215. switch (ant_pos_type) {
  1216. case BTC_ANT_WIFI_AT_CPL_MAIN:
  1217. u8tmp = btcoexist->btc_read_1byte(btcoexist, 0xcb7);
  1218. u8tmp &= ~BIT(2);
  1219. u8tmp |= BIT(3);
  1220. btcoexist->btc_write_1byte(btcoexist, 0xcb7, u8tmp);
  1221. break;
  1222. case BTC_ANT_WIFI_AT_CPL_AUX:
  1223. u8tmp = btcoexist->btc_read_1byte(btcoexist, 0xcb7);
  1224. u8tmp &= ~BIT(3);
  1225. u8tmp |= BIT(2);
  1226. btcoexist->btc_write_1byte(btcoexist, 0xcb7, u8tmp);
  1227. break;
  1228. default:
  1229. break;
  1230. }
  1231. }
  1232. void halbtc8812a2ant_ps_tdma(IN struct btc_coexist *btcoexist,
  1233. IN boolean force_exec, IN boolean turn_on, IN u8 type)
  1234. {
  1235. s8 wifi_duration_adjust = 0x0;
  1236. coex_dm->cur_ps_tdma_on = turn_on;
  1237. coex_dm->cur_ps_tdma = type;
  1238. if (!force_exec) {
  1239. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1240. "[BTCoex], pre_ps_tdma_on = %d, cur_ps_tdma_on = %d!!\n",
  1241. coex_dm->pre_ps_tdma_on, coex_dm->cur_ps_tdma_on);
  1242. BTC_TRACE(trace_buf);
  1243. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1244. "[BTCoex], pre_ps_tdma = %d, cur_ps_tdma = %d!!\n",
  1245. coex_dm->pre_ps_tdma, coex_dm->cur_ps_tdma);
  1246. BTC_TRACE(trace_buf);
  1247. if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) &&
  1248. (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma))
  1249. return;
  1250. }
  1251. if (coex_sta->scan_ap_num >= 40)
  1252. wifi_duration_adjust = -15;
  1253. else if (coex_sta->scan_ap_num >= 20)
  1254. wifi_duration_adjust = -10;
  1255. /*
  1256. if (!coex_sta->force_lps_on)
  1257. {
  1258. ps_tdma_byte0_val = 0x61;
  1259. ps_tdma_byte3_val = 0x11;
  1260. ps_tdma_byte4_val = 0x10;
  1261. }
  1262. if ( (type == 3) || (type == 13) || (type == 14) )
  1263. {
  1264. ps_tdma_byte4_val = ps_tdma_byte4_val & 0xbf;
  1265. if (!wifi_busy)
  1266. ps_tdma_byte4_val = ps_tdma_byte4_val | 0x1;
  1267. }
  1268. if (bt_link_info->slave_role == true)
  1269. ps_tdma_byte4_val = ps_tdma_byte4_val | 0x1;
  1270. */
  1271. if (turn_on) {
  1272. switch (type) {
  1273. case 1:
  1274. default: /* d1,wb */
  1275. halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1276. 0x3c, 0x03, 0x11, 0x10);
  1277. break;
  1278. case 2:
  1279. halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1280. 0x32, 0x03, 0x11, 0x10);
  1281. break;
  1282. case 3:
  1283. halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1284. 0x28, 0x03, 0x11, 0x10);
  1285. break;
  1286. case 4:
  1287. halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1288. 0x1e, 0x03, 0x11, 0x10);
  1289. break;
  1290. case 5: /* d1,pb,TXpause */
  1291. halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x63,
  1292. 0x3c, 0x03, 0x90, 0x10);
  1293. break;
  1294. case 6:
  1295. halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x63,
  1296. 0x32, 0x03, 0x90, 0x10);
  1297. break;
  1298. case 7:
  1299. halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x63,
  1300. 0x28, 0x03, 0x90, 0x10);
  1301. break;
  1302. case 8:
  1303. halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x63,
  1304. 0x1e, 0x03, 0x90, 0x10);
  1305. break;
  1306. case 9: /* d1,bb */
  1307. halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1308. 0x3c, 0x03, 0x31, 0x10);
  1309. break;
  1310. case 10:
  1311. halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1312. 0x32, 0x03, 0x31, 0x10);
  1313. break;
  1314. case 11:
  1315. halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1316. 0x28, 0x03, 0x31, 0x10);
  1317. break;
  1318. case 12:
  1319. halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1320. 0x1e, 0x03, 0x31, 0x10);
  1321. break;
  1322. case 13: /* d1,bb,TXpause */
  1323. halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1324. 0x3c, 0x03, 0x30, 0x10);
  1325. break;
  1326. case 14:
  1327. halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1328. 0x32, 0x03, 0x30, 0x10);
  1329. break;
  1330. case 15:
  1331. halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1332. 0x28, 0x03, 0x30, 0x10);
  1333. break;
  1334. case 16:
  1335. halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1336. 0x1e, 0x03, 0x30, 0x10);
  1337. break;
  1338. case 17:
  1339. halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x61,
  1340. 0x35, 0x3, 0x11, 0x11);
  1341. break;
  1342. case 18:
  1343. halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1344. 0x5, 0x5, 0xe1, 0x90);
  1345. break;
  1346. case 19:
  1347. halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1348. 0x25, 0x25, 0xe1, 0x90);
  1349. break;
  1350. case 20:
  1351. halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1352. 0x25, 0x25, 0x60, 0x90);
  1353. break;
  1354. case 21:
  1355. halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1356. 0x15, 0x3, 0x70, 0x90);
  1357. break;
  1358. case 22:
  1359. halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x61,
  1360. 0x1a, 0x1a, 0x21, 0x10);
  1361. break;
  1362. case 23:
  1363. halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1364. 0x1c, 0x03, 0x31, 0x10);
  1365. break;
  1366. case 71:
  1367. halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3,
  1368. 0x1a, 0x1a, 0xe1, 0x90);
  1369. break;
  1370. /* following cases is for wifi rssi low, started from 81 */
  1371. case 80:
  1372. halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x53,
  1373. 0x3c, 0x3, 0x90, 0x50);
  1374. break;
  1375. case 81:
  1376. halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x53,
  1377. 0x3a + wifi_duration_adjust, 0x3, 0x90,
  1378. 0x50);
  1379. break;
  1380. case 82:
  1381. halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x53,
  1382. 0x30 + wifi_duration_adjust, 0x03, 0x90,
  1383. 0x50);
  1384. break;
  1385. case 83:
  1386. halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x53,
  1387. 0x21, 0x03, 0x90, 0x50);
  1388. break;
  1389. case 84:
  1390. halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x53,
  1391. 0x15, 0x3, 0x90, 0x50);
  1392. break;
  1393. case 85:
  1394. halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x53,
  1395. 0x1d, 0x1d, 0x80, 0x50);
  1396. break;
  1397. case 86:
  1398. halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x53,
  1399. 0x15, 0x15, 0x80, 0x50);
  1400. break;
  1401. }
  1402. } else {
  1403. /* disable PS tdma */
  1404. switch (type) {
  1405. case 0: /* ANT2PTA, 0x778=0x1 */
  1406. halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x8,
  1407. 0x0, 0x0, 0x0, 0x0);
  1408. break;
  1409. case 1: /* ANT2BT, 0x778=3 */
  1410. halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x0,
  1411. 0x0, 0x0, 0x8, 0x0);
  1412. delay_ms(5);
  1413. halbtc8812a2ant_set_ant_path(btcoexist,
  1414. BTC_ANT_WIFI_AT_CPL_AUX, false, false);
  1415. break;
  1416. case 2: /* ANT2BT, 0x778=3 */
  1417. halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x0,
  1418. 0x0, 0x0, 0x8, 0x0);
  1419. delay_ms(5);
  1420. halbtc8812a2ant_set_ant_path(btcoexist,
  1421. BTC_ANT_WIFI_AT_CPL_MAIN, false, false);
  1422. break;
  1423. default:
  1424. halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x0,
  1425. 0x0, 0x0, 0x0, 0x0);
  1426. break;
  1427. }
  1428. }
  1429. /* update pre state */
  1430. coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on;
  1431. coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma;
  1432. }
  1433. void halbtc8812a2ant_ps_tdma_check_for_power_save_state(
  1434. IN struct btc_coexist *btcoexist, IN boolean new_ps_state)
  1435. {
  1436. u8 lps_mode = 0x0;
  1437. btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode);
  1438. if (lps_mode) { /* already under LPS state */
  1439. if (new_ps_state) {
  1440. /* keep state under LPS, do nothing. */
  1441. } else {
  1442. /* will leave LPS state, turn off psTdma first */
  1443. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
  1444. 0);
  1445. }
  1446. } else { /* NO PS state */
  1447. if (new_ps_state) {
  1448. /* will enter LPS state, turn off psTdma first */
  1449. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
  1450. 0);
  1451. } else {
  1452. /* keep state under NO PS state, do nothing. */
  1453. }
  1454. }
  1455. }
  1456. void halbtc8812a2ant_power_save_state(IN struct btc_coexist *btcoexist,
  1457. IN u8 ps_type, IN u8 lps_val, IN u8 rpwm_val)
  1458. {
  1459. boolean low_pwr_disable = false;
  1460. boolean ap_enable = false;
  1461. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
  1462. &ap_enable);
  1463. if (ap_enable) {
  1464. ps_type = BTC_PS_WIFI_NATIVE;
  1465. lps_val = 0x0;
  1466. rpwm_val = 0x0;
  1467. }
  1468. switch (ps_type) {
  1469. case BTC_PS_WIFI_NATIVE:
  1470. /* recover to original 32k low power setting */
  1471. low_pwr_disable = true;
  1472. btcoexist->btc_set(btcoexist,
  1473. BTC_SET_ACT_DISABLE_LOW_POWER,
  1474. &low_pwr_disable);
  1475. btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS,
  1476. NULL);
  1477. coex_sta->force_lps_on = false;
  1478. break;
  1479. case BTC_PS_LPS_ON:
  1480. halbtc8812a2ant_ps_tdma_check_for_power_save_state(
  1481. btcoexist, true);
  1482. halbtc8812a2ant_lps_rpwm(btcoexist, NORMAL_EXEC,
  1483. lps_val, rpwm_val);
  1484. /* when coex force to enter LPS, do not enter 32k low power. */
  1485. low_pwr_disable = true;
  1486. btcoexist->btc_set(btcoexist,
  1487. BTC_SET_ACT_DISABLE_LOW_POWER,
  1488. &low_pwr_disable);
  1489. /* power save must executed before psTdma. */
  1490. btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS,
  1491. NULL);
  1492. coex_sta->force_lps_on = true;
  1493. break;
  1494. case BTC_PS_LPS_OFF:
  1495. halbtc8812a2ant_ps_tdma_check_for_power_save_state(
  1496. btcoexist, false);
  1497. btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS,
  1498. NULL);
  1499. coex_sta->force_lps_on = false;
  1500. break;
  1501. default:
  1502. break;
  1503. }
  1504. }
  1505. void halbtc8812a2ant_coex_all_off(IN struct btc_coexist *btcoexist)
  1506. {
  1507. /* fw all off */
  1508. halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
  1509. 0x0);
  1510. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
  1511. halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  1512. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  1513. /* sw all off */
  1514. halbtc8812a2ant_sw_mechanism1(btcoexist, false, false, false, false);
  1515. halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18);
  1516. /* hw all off */
  1517. halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  1518. }
  1519. void halbtc8812a2ant_init_coex_dm(IN struct btc_coexist *btcoexist)
  1520. {
  1521. /* force to reset coex mechanism */
  1522. halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
  1523. 0x0);
  1524. halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false, 1);
  1525. halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 6);
  1526. halbtc8812a2ant_dec_bt_pwr(btcoexist, FORCE_EXEC, 0);
  1527. halbtc8812a2ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
  1528. halbtc8812a2ant_sw_mechanism1(btcoexist, false, false, false, false);
  1529. halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18);
  1530. }
  1531. void halbtc8812a2ant_monitor_bt_enable_disable(IN struct btc_coexist *btcoexist)
  1532. {
  1533. struct btc_stack_info *stack_info = &btcoexist->stack_info;
  1534. static u32 bt_disable_cnt = 0;
  1535. boolean bt_active = true, bt_disabled = false;
  1536. /* This function check if bt is disabled */
  1537. /* only 8812a need to consider if core stack is installed. */
  1538. /*if (!stack_info->hci_version)*/
  1539. /*bt_active = false;*/
  1540. bt_disabled = btcoexist->bt_info.bt_disabled;
  1541. if (coex_sta->pre_bt_disabled != bt_disabled) {
  1542. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1543. "[BTCoex], BT is from %s to %s!!\n",
  1544. (coex_sta->pre_bt_disabled ? "disabled" : "enabled"),
  1545. (bt_disabled ? "disabled" : "enabled"));
  1546. BTC_TRACE(trace_buf);
  1547. coex_sta->pre_bt_disabled = bt_disabled;
  1548. if (bt_disabled) {
  1549. halbtc8812a2ant_power_save_state(btcoexist,
  1550. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  1551. halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false,
  1552. 2);
  1553. halbtc8812a2ant_coex_table_with_type(btcoexist,
  1554. NORMAL_EXEC, 0);
  1555. }
  1556. }
  1557. }
  1558. void halbtc8812a2ant_action_bt_inquiry(IN struct btc_coexist *btcoexist)
  1559. {
  1560. halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
  1561. 0x0);
  1562. halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  1563. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3);
  1564. halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  1565. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  1566. halbtc8812a2ant_sw_mechanism1(btcoexist, false, false, false, false);
  1567. halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18);
  1568. }
  1569. boolean halbtc8812a2ant_is_common_action(IN struct btc_coexist *btcoexist)
  1570. {
  1571. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1572. boolean common = false, wifi_connected = false, wifi_busy = false;
  1573. boolean bt_hs_on = false;
  1574. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  1575. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  1576. &wifi_connected);
  1577. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  1578. if (coex_sta->c2h_bt_inquiry_page) {
  1579. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1580. "[BTCoex], BT is under inquiry/page scan !!\n");
  1581. BTC_TRACE(trace_buf);
  1582. halbtc8812a2ant_action_bt_inquiry(btcoexist);
  1583. return true;
  1584. }
  1585. if (bt_link_info->sco_exist || bt_link_info->hid_exist)
  1586. halbtc8812a2ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 0, 0, 0);
  1587. else
  1588. halbtc8812a2ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
  1589. if (!wifi_connected) {
  1590. halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  1591. 0x0, 0x0);
  1592. halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
  1593. 0x8);
  1594. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1595. "[BTCoex], Wifi non-connected idle!!\n");
  1596. BTC_TRACE(trace_buf);
  1597. if ((BT_8812A_2ANT_BT_STATUS_NON_CONNECTED_IDLE ==
  1598. coex_dm->bt_status) ||
  1599. (BT_8812A_2ANT_BT_STATUS_CONNECTED_IDLE ==
  1600. coex_dm->bt_status)) {
  1601. halbtc8812a2ant_coex_table_with_type(btcoexist,
  1602. NORMAL_EXEC, 1);
  1603. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
  1604. 0);
  1605. } else {
  1606. halbtc8812a2ant_coex_table_with_type(btcoexist,
  1607. NORMAL_EXEC, 0);
  1608. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
  1609. 1);
  1610. }
  1611. halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  1612. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  1613. halbtc8812a2ant_sw_mechanism1(btcoexist, false, false, false,
  1614. false);
  1615. halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, false,
  1616. 0x18);
  1617. common = true;
  1618. } else {
  1619. if (BT_8812A_2ANT_BT_STATUS_NON_CONNECTED_IDLE ==
  1620. coex_dm->bt_status) {
  1621. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1622. "[BTCoex], Wifi connected + BT non connected-idle!!\n");
  1623. BTC_TRACE(trace_buf);
  1624. halbtc8812a2ant_power_save_state(btcoexist,
  1625. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  1626. halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC,
  1627. false, false, 0x8);
  1628. halbtc8812a2ant_coex_table_with_type(btcoexist,
  1629. NORMAL_EXEC, 0);
  1630. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
  1631. 0);
  1632. halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC,
  1633. 6);
  1634. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  1635. halbtc8812a2ant_sw_mechanism1(btcoexist, false, false,
  1636. false, false);
  1637. halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
  1638. false, 0x18);
  1639. common = true;
  1640. } else if (BT_8812A_2ANT_BT_STATUS_CONNECTED_IDLE ==
  1641. coex_dm->bt_status) {
  1642. if (bt_hs_on)
  1643. return false;
  1644. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1645. "[BTCoex], Wifi connected + BT connected-idle!!\n");
  1646. BTC_TRACE(trace_buf);
  1647. halbtc8812a2ant_power_save_state(btcoexist,
  1648. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  1649. halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC,
  1650. false, false, 0x8);
  1651. halbtc8812a2ant_coex_table_with_type(btcoexist,
  1652. NORMAL_EXEC, 0);
  1653. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
  1654. 0);
  1655. halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC,
  1656. 6);
  1657. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  1658. halbtc8812a2ant_sw_mechanism1(btcoexist, true, false,
  1659. false, false);
  1660. halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
  1661. false, 0x18);
  1662. common = true;
  1663. } else {
  1664. if (wifi_busy) {
  1665. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1666. "[BTCoex], Wifi Connected-Busy + BT Busy!!\n");
  1667. BTC_TRACE(trace_buf);
  1668. common = false;
  1669. } else {
  1670. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1671. "[BTCoex], Wifi Connected-Idle + BT Busy!!\n");
  1672. BTC_TRACE(trace_buf);
  1673. halbtc8812a2ant_power_save_state(btcoexist,
  1674. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  1675. halbtc8812a2ant_limited_rx(btcoexist,
  1676. NORMAL_EXEC, false, false, 0x8);
  1677. halbtc8812a2ant_coex_table_with_type(btcoexist,
  1678. NORMAL_EXEC, 0);
  1679. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  1680. true, 17);
  1681. halbtc8812a2ant_fw_dac_swing_lvl(btcoexist,
  1682. NORMAL_EXEC, 6);
  1683. halbtc8812a2ant_dec_bt_pwr(btcoexist,
  1684. NORMAL_EXEC, 0);
  1685. halbtc8812a2ant_sw_mechanism1(btcoexist, false,
  1686. false, false, false);
  1687. halbtc8812a2ant_sw_mechanism2(btcoexist, false,
  1688. false, false, 0x18);
  1689. common = true;
  1690. }
  1691. }
  1692. }
  1693. return common;
  1694. }
  1695. void halbtc8812a2ant_tdma_duration_adjust(IN struct btc_coexist *btcoexist,
  1696. IN boolean sco_hid, IN boolean tx_pause, IN u8 max_interval)
  1697. {
  1698. static s32 up, dn, m, n, wait_count;
  1699. s32 result; /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */
  1700. u8 retry_count = 0;
  1701. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1702. "[BTCoex], TdmaDurationAdjust()\n");
  1703. BTC_TRACE(trace_buf);
  1704. coex_dm->auto_tdma_adjust_low_rssi = false;
  1705. if (!coex_dm->auto_tdma_adjust) {
  1706. coex_dm->auto_tdma_adjust = true;
  1707. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1708. "[BTCoex], first run TdmaDurationAdjust()!!\n");
  1709. BTC_TRACE(trace_buf);
  1710. {
  1711. if (sco_hid) {
  1712. if (tx_pause) {
  1713. if (max_interval == 1) {
  1714. halbtc8812a2ant_ps_tdma(
  1715. btcoexist, NORMAL_EXEC,
  1716. true, 13);
  1717. coex_dm->ps_tdma_du_adj_type =
  1718. 13;
  1719. } else if (max_interval == 2) {
  1720. halbtc8812a2ant_ps_tdma(
  1721. btcoexist, NORMAL_EXEC,
  1722. true, 14);
  1723. coex_dm->ps_tdma_du_adj_type =
  1724. 14;
  1725. } else if (max_interval == 3) {
  1726. halbtc8812a2ant_ps_tdma(
  1727. btcoexist, NORMAL_EXEC,
  1728. true, 15);
  1729. coex_dm->ps_tdma_du_adj_type =
  1730. 15;
  1731. } else {
  1732. halbtc8812a2ant_ps_tdma(
  1733. btcoexist, NORMAL_EXEC,
  1734. true, 15);
  1735. coex_dm->ps_tdma_du_adj_type =
  1736. 15;
  1737. }
  1738. } else {
  1739. if (max_interval == 1) {
  1740. halbtc8812a2ant_ps_tdma(
  1741. btcoexist, NORMAL_EXEC,
  1742. true, 9);
  1743. coex_dm->ps_tdma_du_adj_type =
  1744. 9;
  1745. } else if (max_interval == 2) {
  1746. halbtc8812a2ant_ps_tdma(
  1747. btcoexist, NORMAL_EXEC,
  1748. true, 10);
  1749. coex_dm->ps_tdma_du_adj_type =
  1750. 10;
  1751. } else if (max_interval == 3) {
  1752. halbtc8812a2ant_ps_tdma(
  1753. btcoexist, NORMAL_EXEC,
  1754. true, 11);
  1755. coex_dm->ps_tdma_du_adj_type =
  1756. 11;
  1757. } else {
  1758. halbtc8812a2ant_ps_tdma(
  1759. btcoexist, NORMAL_EXEC,
  1760. true, 11);
  1761. coex_dm->ps_tdma_du_adj_type =
  1762. 11;
  1763. }
  1764. }
  1765. } else {
  1766. if (tx_pause) {
  1767. if (max_interval == 1) {
  1768. halbtc8812a2ant_ps_tdma(
  1769. btcoexist, NORMAL_EXEC,
  1770. true, 5);
  1771. coex_dm->ps_tdma_du_adj_type =
  1772. 5;
  1773. } else if (max_interval == 2) {
  1774. halbtc8812a2ant_ps_tdma(
  1775. btcoexist, NORMAL_EXEC,
  1776. true, 6);
  1777. coex_dm->ps_tdma_du_adj_type =
  1778. 6;
  1779. } else if (max_interval == 3) {
  1780. halbtc8812a2ant_ps_tdma(
  1781. btcoexist, NORMAL_EXEC,
  1782. true, 7);
  1783. coex_dm->ps_tdma_du_adj_type =
  1784. 7;
  1785. } else {
  1786. halbtc8812a2ant_ps_tdma(
  1787. btcoexist, NORMAL_EXEC,
  1788. true, 7);
  1789. coex_dm->ps_tdma_du_adj_type =
  1790. 7;
  1791. }
  1792. } else {
  1793. if (max_interval == 1) {
  1794. halbtc8812a2ant_ps_tdma(
  1795. btcoexist, NORMAL_EXEC,
  1796. true, 1);
  1797. coex_dm->ps_tdma_du_adj_type =
  1798. 1;
  1799. } else if (max_interval == 2) {
  1800. halbtc8812a2ant_ps_tdma(
  1801. btcoexist, NORMAL_EXEC,
  1802. true, 2);
  1803. coex_dm->ps_tdma_du_adj_type =
  1804. 2;
  1805. } else if (max_interval == 3) {
  1806. halbtc8812a2ant_ps_tdma(
  1807. btcoexist, NORMAL_EXEC,
  1808. true, 3);
  1809. coex_dm->ps_tdma_du_adj_type =
  1810. 3;
  1811. } else {
  1812. halbtc8812a2ant_ps_tdma(
  1813. btcoexist, NORMAL_EXEC,
  1814. true, 3);
  1815. coex_dm->ps_tdma_du_adj_type =
  1816. 3;
  1817. }
  1818. }
  1819. }
  1820. }
  1821. /* ============ */
  1822. up = 0;
  1823. dn = 0;
  1824. m = 1;
  1825. n = 3;
  1826. result = 0;
  1827. wait_count = 0;
  1828. } else {
  1829. /* acquire the BT TRx retry count from BT_Info byte2 */
  1830. retry_count = coex_sta->bt_retry_cnt;
  1831. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1832. "[BTCoex], retry_count = %d\n",
  1833. retry_count);
  1834. BTC_TRACE(trace_buf);
  1835. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1836. "[BTCoex], up=%d, dn=%d, m=%d, n=%d, wait_count=%d\n",
  1837. up, dn, m, n, wait_count);
  1838. BTC_TRACE(trace_buf);
  1839. result = 0;
  1840. wait_count++;
  1841. if (retry_count ==
  1842. 0) { /* no retry in the last 2-second duration */
  1843. up++;
  1844. dn--;
  1845. if (dn <= 0)
  1846. dn = 0;
  1847. if (up >= n) { /* if 連續 n 個2秒 retry count為0, 則調寬WiFi duration */
  1848. wait_count = 0;
  1849. n = 3;
  1850. up = 0;
  1851. dn = 0;
  1852. result = 1;
  1853. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1854. "[BTCoex], Increase wifi duration!!\n");
  1855. BTC_TRACE(trace_buf);
  1856. }
  1857. } else if (retry_count <=
  1858. 3) { /* <=3 retry in the last 2-second duration */
  1859. up--;
  1860. dn++;
  1861. if (up <= 0)
  1862. up = 0;
  1863. if (dn == 2) { /* if 連續 2 個2秒 retry count< 3, 則調窄WiFi duration */
  1864. if (wait_count <= 2)
  1865. m++; /* 避免一直在兩個level中來回 */
  1866. else
  1867. m = 1;
  1868. if (m >= 20) /* m 最大值 = 20 ' 最大120秒 recheck是否調整 WiFi duration. */
  1869. m = 20;
  1870. n = 3 * m;
  1871. up = 0;
  1872. dn = 0;
  1873. wait_count = 0;
  1874. result = -1;
  1875. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1876. "[BTCoex], Decrease wifi duration for retry_counter<3!!\n");
  1877. BTC_TRACE(trace_buf);
  1878. }
  1879. } else { /* retry count > 3, 只要1次 retry count > 3, 則調窄WiFi duration */
  1880. if (wait_count == 1)
  1881. m++; /* 避免一直在兩個level中來回 */
  1882. else
  1883. m = 1;
  1884. if (m >= 20) /* m 最大值 = 20 ' 最大120秒 recheck是否調整 WiFi duration. */
  1885. m = 20;
  1886. n = 3 * m;
  1887. up = 0;
  1888. dn = 0;
  1889. wait_count = 0;
  1890. result = -1;
  1891. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1892. "[BTCoex], Decrease wifi duration for retry_counter>3!!\n");
  1893. BTC_TRACE(trace_buf);
  1894. }
  1895. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1896. "[BTCoex], max Interval = %d\n",
  1897. max_interval);
  1898. BTC_TRACE(trace_buf);
  1899. if (max_interval == 1) {
  1900. if (tx_pause) {
  1901. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1902. "[BTCoex], TxPause = 1\n");
  1903. BTC_TRACE(trace_buf);
  1904. if (coex_dm->cur_ps_tdma == 1) {
  1905. halbtc8812a2ant_ps_tdma(btcoexist,
  1906. NORMAL_EXEC, true, 5);
  1907. coex_dm->ps_tdma_du_adj_type = 5;
  1908. } else if (coex_dm->cur_ps_tdma == 2) {
  1909. halbtc8812a2ant_ps_tdma(btcoexist,
  1910. NORMAL_EXEC, true, 6);
  1911. coex_dm->ps_tdma_du_adj_type = 6;
  1912. } else if (coex_dm->cur_ps_tdma == 3) {
  1913. halbtc8812a2ant_ps_tdma(btcoexist,
  1914. NORMAL_EXEC, true, 7);
  1915. coex_dm->ps_tdma_du_adj_type = 7;
  1916. } else if (coex_dm->cur_ps_tdma == 4) {
  1917. halbtc8812a2ant_ps_tdma(btcoexist,
  1918. NORMAL_EXEC, true, 8);
  1919. coex_dm->ps_tdma_du_adj_type = 8;
  1920. }
  1921. if (coex_dm->cur_ps_tdma == 9) {
  1922. halbtc8812a2ant_ps_tdma(btcoexist,
  1923. NORMAL_EXEC, true, 13);
  1924. coex_dm->ps_tdma_du_adj_type = 13;
  1925. } else if (coex_dm->cur_ps_tdma == 10) {
  1926. halbtc8812a2ant_ps_tdma(btcoexist,
  1927. NORMAL_EXEC, true, 14);
  1928. coex_dm->ps_tdma_du_adj_type = 14;
  1929. } else if (coex_dm->cur_ps_tdma == 11) {
  1930. halbtc8812a2ant_ps_tdma(btcoexist,
  1931. NORMAL_EXEC, true, 15);
  1932. coex_dm->ps_tdma_du_adj_type = 15;
  1933. } else if (coex_dm->cur_ps_tdma == 12) {
  1934. halbtc8812a2ant_ps_tdma(btcoexist,
  1935. NORMAL_EXEC, true, 16);
  1936. coex_dm->ps_tdma_du_adj_type = 16;
  1937. }
  1938. if (result == -1) {
  1939. if (coex_dm->cur_ps_tdma == 5) {
  1940. halbtc8812a2ant_ps_tdma(
  1941. btcoexist, NORMAL_EXEC,
  1942. true, 6);
  1943. coex_dm->ps_tdma_du_adj_type =
  1944. 6;
  1945. } else if (coex_dm->cur_ps_tdma == 6) {
  1946. halbtc8812a2ant_ps_tdma(
  1947. btcoexist, NORMAL_EXEC,
  1948. true, 7);
  1949. coex_dm->ps_tdma_du_adj_type =
  1950. 7;
  1951. } else if (coex_dm->cur_ps_tdma == 7) {
  1952. halbtc8812a2ant_ps_tdma(
  1953. btcoexist, NORMAL_EXEC,
  1954. true, 8);
  1955. coex_dm->ps_tdma_du_adj_type =
  1956. 8;
  1957. } else if (coex_dm->cur_ps_tdma == 13) {
  1958. halbtc8812a2ant_ps_tdma(
  1959. btcoexist, NORMAL_EXEC,
  1960. true, 14);
  1961. coex_dm->ps_tdma_du_adj_type =
  1962. 14;
  1963. } else if (coex_dm->cur_ps_tdma == 14) {
  1964. halbtc8812a2ant_ps_tdma(
  1965. btcoexist, NORMAL_EXEC,
  1966. true, 15);
  1967. coex_dm->ps_tdma_du_adj_type =
  1968. 15;
  1969. } else if (coex_dm->cur_ps_tdma == 15) {
  1970. halbtc8812a2ant_ps_tdma(
  1971. btcoexist, NORMAL_EXEC,
  1972. true, 16);
  1973. coex_dm->ps_tdma_du_adj_type =
  1974. 16;
  1975. }
  1976. } else if (result == 1) {
  1977. if (coex_dm->cur_ps_tdma == 8) {
  1978. halbtc8812a2ant_ps_tdma(
  1979. btcoexist, NORMAL_EXEC,
  1980. true, 7);
  1981. coex_dm->ps_tdma_du_adj_type =
  1982. 7;
  1983. } else if (coex_dm->cur_ps_tdma == 7) {
  1984. halbtc8812a2ant_ps_tdma(
  1985. btcoexist, NORMAL_EXEC,
  1986. true, 6);
  1987. coex_dm->ps_tdma_du_adj_type =
  1988. 6;
  1989. } else if (coex_dm->cur_ps_tdma == 6) {
  1990. halbtc8812a2ant_ps_tdma(
  1991. btcoexist, NORMAL_EXEC,
  1992. true, 5);
  1993. coex_dm->ps_tdma_du_adj_type =
  1994. 5;
  1995. } else if (coex_dm->cur_ps_tdma == 16) {
  1996. halbtc8812a2ant_ps_tdma(
  1997. btcoexist, NORMAL_EXEC,
  1998. true, 15);
  1999. coex_dm->ps_tdma_du_adj_type =
  2000. 15;
  2001. } else if (coex_dm->cur_ps_tdma == 15) {
  2002. halbtc8812a2ant_ps_tdma(
  2003. btcoexist, NORMAL_EXEC,
  2004. true, 14);
  2005. coex_dm->ps_tdma_du_adj_type =
  2006. 14;
  2007. } else if (coex_dm->cur_ps_tdma == 14) {
  2008. halbtc8812a2ant_ps_tdma(
  2009. btcoexist, NORMAL_EXEC,
  2010. true, 13);
  2011. coex_dm->ps_tdma_du_adj_type =
  2012. 13;
  2013. }
  2014. }
  2015. } else {
  2016. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2017. "[BTCoex], TxPause = 0\n");
  2018. BTC_TRACE(trace_buf);
  2019. if (coex_dm->cur_ps_tdma == 5) {
  2020. halbtc8812a2ant_ps_tdma(btcoexist,
  2021. NORMAL_EXEC, true, 1);
  2022. coex_dm->ps_tdma_du_adj_type = 1;
  2023. } else if (coex_dm->cur_ps_tdma == 6) {
  2024. halbtc8812a2ant_ps_tdma(btcoexist,
  2025. NORMAL_EXEC, true, 2);
  2026. coex_dm->ps_tdma_du_adj_type = 2;
  2027. } else if (coex_dm->cur_ps_tdma == 7) {
  2028. halbtc8812a2ant_ps_tdma(btcoexist,
  2029. NORMAL_EXEC, true, 3);
  2030. coex_dm->ps_tdma_du_adj_type = 3;
  2031. } else if (coex_dm->cur_ps_tdma == 8) {
  2032. halbtc8812a2ant_ps_tdma(btcoexist,
  2033. NORMAL_EXEC, true, 4);
  2034. coex_dm->ps_tdma_du_adj_type = 4;
  2035. }
  2036. if (coex_dm->cur_ps_tdma == 13) {
  2037. halbtc8812a2ant_ps_tdma(btcoexist,
  2038. NORMAL_EXEC, true, 9);
  2039. coex_dm->ps_tdma_du_adj_type = 9;
  2040. } else if (coex_dm->cur_ps_tdma == 14) {
  2041. halbtc8812a2ant_ps_tdma(btcoexist,
  2042. NORMAL_EXEC, true, 10);
  2043. coex_dm->ps_tdma_du_adj_type = 10;
  2044. } else if (coex_dm->cur_ps_tdma == 15) {
  2045. halbtc8812a2ant_ps_tdma(btcoexist,
  2046. NORMAL_EXEC, true, 11);
  2047. coex_dm->ps_tdma_du_adj_type = 11;
  2048. } else if (coex_dm->cur_ps_tdma == 16) {
  2049. halbtc8812a2ant_ps_tdma(btcoexist,
  2050. NORMAL_EXEC, true, 12);
  2051. coex_dm->ps_tdma_du_adj_type = 12;
  2052. }
  2053. if (result == -1) {
  2054. if (coex_dm->cur_ps_tdma == 1) {
  2055. halbtc8812a2ant_ps_tdma(
  2056. btcoexist, NORMAL_EXEC,
  2057. true, 2);
  2058. coex_dm->ps_tdma_du_adj_type =
  2059. 2;
  2060. } else if (coex_dm->cur_ps_tdma == 2) {
  2061. halbtc8812a2ant_ps_tdma(
  2062. btcoexist, NORMAL_EXEC,
  2063. true, 3);
  2064. coex_dm->ps_tdma_du_adj_type =
  2065. 3;
  2066. } else if (coex_dm->cur_ps_tdma == 3) {
  2067. halbtc8812a2ant_ps_tdma(
  2068. btcoexist, NORMAL_EXEC,
  2069. true, 4);
  2070. coex_dm->ps_tdma_du_adj_type =
  2071. 4;
  2072. } else if (coex_dm->cur_ps_tdma == 9) {
  2073. halbtc8812a2ant_ps_tdma(
  2074. btcoexist, NORMAL_EXEC,
  2075. true, 10);
  2076. coex_dm->ps_tdma_du_adj_type =
  2077. 10;
  2078. } else if (coex_dm->cur_ps_tdma == 10) {
  2079. halbtc8812a2ant_ps_tdma(
  2080. btcoexist, NORMAL_EXEC,
  2081. true, 11);
  2082. coex_dm->ps_tdma_du_adj_type =
  2083. 11;
  2084. } else if (coex_dm->cur_ps_tdma == 11) {
  2085. halbtc8812a2ant_ps_tdma(
  2086. btcoexist, NORMAL_EXEC,
  2087. true, 12);
  2088. coex_dm->ps_tdma_du_adj_type =
  2089. 12;
  2090. }
  2091. } else if (result == 1) {
  2092. if (coex_dm->cur_ps_tdma == 4) {
  2093. halbtc8812a2ant_ps_tdma(
  2094. btcoexist, NORMAL_EXEC,
  2095. true, 3);
  2096. coex_dm->ps_tdma_du_adj_type =
  2097. 3;
  2098. } else if (coex_dm->cur_ps_tdma == 3) {
  2099. halbtc8812a2ant_ps_tdma(
  2100. btcoexist, NORMAL_EXEC,
  2101. true, 2);
  2102. coex_dm->ps_tdma_du_adj_type =
  2103. 2;
  2104. } else if (coex_dm->cur_ps_tdma == 2) {
  2105. halbtc8812a2ant_ps_tdma(
  2106. btcoexist, NORMAL_EXEC,
  2107. true, 1);
  2108. coex_dm->ps_tdma_du_adj_type =
  2109. 1;
  2110. } else if (coex_dm->cur_ps_tdma == 12) {
  2111. halbtc8812a2ant_ps_tdma(
  2112. btcoexist, NORMAL_EXEC,
  2113. true, 11);
  2114. coex_dm->ps_tdma_du_adj_type =
  2115. 11;
  2116. } else if (coex_dm->cur_ps_tdma == 11) {
  2117. halbtc8812a2ant_ps_tdma(
  2118. btcoexist, NORMAL_EXEC,
  2119. true, 10);
  2120. coex_dm->ps_tdma_du_adj_type =
  2121. 10;
  2122. } else if (coex_dm->cur_ps_tdma == 10) {
  2123. halbtc8812a2ant_ps_tdma(
  2124. btcoexist, NORMAL_EXEC,
  2125. true, 9);
  2126. coex_dm->ps_tdma_du_adj_type =
  2127. 9;
  2128. }
  2129. }
  2130. }
  2131. } else if (max_interval == 2) {
  2132. if (tx_pause) {
  2133. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2134. "[BTCoex], TxPause = 1\n");
  2135. BTC_TRACE(trace_buf);
  2136. if (coex_dm->cur_ps_tdma == 1) {
  2137. halbtc8812a2ant_ps_tdma(btcoexist,
  2138. NORMAL_EXEC, true, 6);
  2139. coex_dm->ps_tdma_du_adj_type = 6;
  2140. } else if (coex_dm->cur_ps_tdma == 2) {
  2141. halbtc8812a2ant_ps_tdma(btcoexist,
  2142. NORMAL_EXEC, true, 6);
  2143. coex_dm->ps_tdma_du_adj_type = 6;
  2144. } else if (coex_dm->cur_ps_tdma == 3) {
  2145. halbtc8812a2ant_ps_tdma(btcoexist,
  2146. NORMAL_EXEC, true, 7);
  2147. coex_dm->ps_tdma_du_adj_type = 7;
  2148. } else if (coex_dm->cur_ps_tdma == 4) {
  2149. halbtc8812a2ant_ps_tdma(btcoexist,
  2150. NORMAL_EXEC, true, 8);
  2151. coex_dm->ps_tdma_du_adj_type = 8;
  2152. }
  2153. if (coex_dm->cur_ps_tdma == 9) {
  2154. halbtc8812a2ant_ps_tdma(btcoexist,
  2155. NORMAL_EXEC, true, 14);
  2156. coex_dm->ps_tdma_du_adj_type = 14;
  2157. } else if (coex_dm->cur_ps_tdma == 10) {
  2158. halbtc8812a2ant_ps_tdma(btcoexist,
  2159. NORMAL_EXEC, true, 14);
  2160. coex_dm->ps_tdma_du_adj_type = 14;
  2161. } else if (coex_dm->cur_ps_tdma == 11) {
  2162. halbtc8812a2ant_ps_tdma(btcoexist,
  2163. NORMAL_EXEC, true, 15);
  2164. coex_dm->ps_tdma_du_adj_type = 15;
  2165. } else if (coex_dm->cur_ps_tdma == 12) {
  2166. halbtc8812a2ant_ps_tdma(btcoexist,
  2167. NORMAL_EXEC, true, 16);
  2168. coex_dm->ps_tdma_du_adj_type = 16;
  2169. }
  2170. if (result == -1) {
  2171. if (coex_dm->cur_ps_tdma == 5) {
  2172. halbtc8812a2ant_ps_tdma(
  2173. btcoexist, NORMAL_EXEC,
  2174. true, 6);
  2175. coex_dm->ps_tdma_du_adj_type =
  2176. 6;
  2177. } else if (coex_dm->cur_ps_tdma == 6) {
  2178. halbtc8812a2ant_ps_tdma(
  2179. btcoexist, NORMAL_EXEC,
  2180. true, 7);
  2181. coex_dm->ps_tdma_du_adj_type =
  2182. 7;
  2183. } else if (coex_dm->cur_ps_tdma == 7) {
  2184. halbtc8812a2ant_ps_tdma(
  2185. btcoexist, NORMAL_EXEC,
  2186. true, 8);
  2187. coex_dm->ps_tdma_du_adj_type =
  2188. 8;
  2189. } else if (coex_dm->cur_ps_tdma == 13) {
  2190. halbtc8812a2ant_ps_tdma(
  2191. btcoexist, NORMAL_EXEC,
  2192. true, 14);
  2193. coex_dm->ps_tdma_du_adj_type =
  2194. 14;
  2195. } else if (coex_dm->cur_ps_tdma == 14) {
  2196. halbtc8812a2ant_ps_tdma(
  2197. btcoexist, NORMAL_EXEC,
  2198. true, 15);
  2199. coex_dm->ps_tdma_du_adj_type =
  2200. 15;
  2201. } else if (coex_dm->cur_ps_tdma == 15) {
  2202. halbtc8812a2ant_ps_tdma(
  2203. btcoexist, NORMAL_EXEC,
  2204. true, 16);
  2205. coex_dm->ps_tdma_du_adj_type =
  2206. 16;
  2207. }
  2208. } else if (result == 1) {
  2209. if (coex_dm->cur_ps_tdma == 8) {
  2210. halbtc8812a2ant_ps_tdma(
  2211. btcoexist, NORMAL_EXEC,
  2212. true, 7);
  2213. coex_dm->ps_tdma_du_adj_type =
  2214. 7;
  2215. } else if (coex_dm->cur_ps_tdma == 7) {
  2216. halbtc8812a2ant_ps_tdma(
  2217. btcoexist, NORMAL_EXEC,
  2218. true, 6);
  2219. coex_dm->ps_tdma_du_adj_type =
  2220. 6;
  2221. } else if (coex_dm->cur_ps_tdma == 6) {
  2222. halbtc8812a2ant_ps_tdma(
  2223. btcoexist, NORMAL_EXEC,
  2224. true, 6);
  2225. coex_dm->ps_tdma_du_adj_type =
  2226. 6;
  2227. } else if (coex_dm->cur_ps_tdma == 16) {
  2228. halbtc8812a2ant_ps_tdma(
  2229. btcoexist, NORMAL_EXEC,
  2230. true, 15);
  2231. coex_dm->ps_tdma_du_adj_type =
  2232. 15;
  2233. } else if (coex_dm->cur_ps_tdma == 15) {
  2234. halbtc8812a2ant_ps_tdma(
  2235. btcoexist, NORMAL_EXEC,
  2236. true, 14);
  2237. coex_dm->ps_tdma_du_adj_type =
  2238. 14;
  2239. } else if (coex_dm->cur_ps_tdma == 14) {
  2240. halbtc8812a2ant_ps_tdma(
  2241. btcoexist, NORMAL_EXEC,
  2242. true, 14);
  2243. coex_dm->ps_tdma_du_adj_type =
  2244. 14;
  2245. }
  2246. }
  2247. } else {
  2248. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2249. "[BTCoex], TxPause = 0\n");
  2250. BTC_TRACE(trace_buf);
  2251. if (coex_dm->cur_ps_tdma == 5) {
  2252. halbtc8812a2ant_ps_tdma(btcoexist,
  2253. NORMAL_EXEC, true, 2);
  2254. coex_dm->ps_tdma_du_adj_type = 2;
  2255. } else if (coex_dm->cur_ps_tdma == 6) {
  2256. halbtc8812a2ant_ps_tdma(btcoexist,
  2257. NORMAL_EXEC, true, 2);
  2258. coex_dm->ps_tdma_du_adj_type = 2;
  2259. } else if (coex_dm->cur_ps_tdma == 7) {
  2260. halbtc8812a2ant_ps_tdma(btcoexist,
  2261. NORMAL_EXEC, true, 3);
  2262. coex_dm->ps_tdma_du_adj_type = 3;
  2263. } else if (coex_dm->cur_ps_tdma == 8) {
  2264. halbtc8812a2ant_ps_tdma(btcoexist,
  2265. NORMAL_EXEC, true, 4);
  2266. coex_dm->ps_tdma_du_adj_type = 4;
  2267. }
  2268. if (coex_dm->cur_ps_tdma == 13) {
  2269. halbtc8812a2ant_ps_tdma(btcoexist,
  2270. NORMAL_EXEC, true, 10);
  2271. coex_dm->ps_tdma_du_adj_type = 10;
  2272. } else if (coex_dm->cur_ps_tdma == 14) {
  2273. halbtc8812a2ant_ps_tdma(btcoexist,
  2274. NORMAL_EXEC, true, 10);
  2275. coex_dm->ps_tdma_du_adj_type = 10;
  2276. } else if (coex_dm->cur_ps_tdma == 15) {
  2277. halbtc8812a2ant_ps_tdma(btcoexist,
  2278. NORMAL_EXEC, true, 11);
  2279. coex_dm->ps_tdma_du_adj_type = 11;
  2280. } else if (coex_dm->cur_ps_tdma == 16) {
  2281. halbtc8812a2ant_ps_tdma(btcoexist,
  2282. NORMAL_EXEC, true, 12);
  2283. coex_dm->ps_tdma_du_adj_type = 12;
  2284. }
  2285. if (result == -1) {
  2286. if (coex_dm->cur_ps_tdma == 1) {
  2287. halbtc8812a2ant_ps_tdma(
  2288. btcoexist, NORMAL_EXEC,
  2289. true, 2);
  2290. coex_dm->ps_tdma_du_adj_type =
  2291. 2;
  2292. } else if (coex_dm->cur_ps_tdma == 2) {
  2293. halbtc8812a2ant_ps_tdma(
  2294. btcoexist, NORMAL_EXEC,
  2295. true, 3);
  2296. coex_dm->ps_tdma_du_adj_type =
  2297. 3;
  2298. } else if (coex_dm->cur_ps_tdma == 3) {
  2299. halbtc8812a2ant_ps_tdma(
  2300. btcoexist, NORMAL_EXEC,
  2301. true, 4);
  2302. coex_dm->ps_tdma_du_adj_type =
  2303. 4;
  2304. } else if (coex_dm->cur_ps_tdma == 9) {
  2305. halbtc8812a2ant_ps_tdma(
  2306. btcoexist, NORMAL_EXEC,
  2307. true, 10);
  2308. coex_dm->ps_tdma_du_adj_type =
  2309. 10;
  2310. } else if (coex_dm->cur_ps_tdma == 10) {
  2311. halbtc8812a2ant_ps_tdma(
  2312. btcoexist, NORMAL_EXEC,
  2313. true, 11);
  2314. coex_dm->ps_tdma_du_adj_type =
  2315. 11;
  2316. } else if (coex_dm->cur_ps_tdma == 11) {
  2317. halbtc8812a2ant_ps_tdma(
  2318. btcoexist, NORMAL_EXEC,
  2319. true, 12);
  2320. coex_dm->ps_tdma_du_adj_type =
  2321. 12;
  2322. }
  2323. } else if (result == 1) {
  2324. if (coex_dm->cur_ps_tdma == 4) {
  2325. halbtc8812a2ant_ps_tdma(
  2326. btcoexist, NORMAL_EXEC,
  2327. true, 3);
  2328. coex_dm->ps_tdma_du_adj_type =
  2329. 3;
  2330. } else if (coex_dm->cur_ps_tdma == 3) {
  2331. halbtc8812a2ant_ps_tdma(
  2332. btcoexist, NORMAL_EXEC,
  2333. true, 2);
  2334. coex_dm->ps_tdma_du_adj_type =
  2335. 2;
  2336. } else if (coex_dm->cur_ps_tdma == 2) {
  2337. halbtc8812a2ant_ps_tdma(
  2338. btcoexist, NORMAL_EXEC,
  2339. true, 2);
  2340. coex_dm->ps_tdma_du_adj_type =
  2341. 2;
  2342. } else if (coex_dm->cur_ps_tdma == 12) {
  2343. halbtc8812a2ant_ps_tdma(
  2344. btcoexist, NORMAL_EXEC,
  2345. true, 11);
  2346. coex_dm->ps_tdma_du_adj_type =
  2347. 11;
  2348. } else if (coex_dm->cur_ps_tdma == 11) {
  2349. halbtc8812a2ant_ps_tdma(
  2350. btcoexist, NORMAL_EXEC,
  2351. true, 10);
  2352. coex_dm->ps_tdma_du_adj_type =
  2353. 10;
  2354. } else if (coex_dm->cur_ps_tdma == 10) {
  2355. halbtc8812a2ant_ps_tdma(
  2356. btcoexist, NORMAL_EXEC,
  2357. true, 10);
  2358. coex_dm->ps_tdma_du_adj_type =
  2359. 10;
  2360. }
  2361. }
  2362. }
  2363. } else if (max_interval == 3) {
  2364. if (tx_pause) {
  2365. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2366. "[BTCoex], TxPause = 1\n");
  2367. BTC_TRACE(trace_buf);
  2368. if (coex_dm->cur_ps_tdma == 1) {
  2369. halbtc8812a2ant_ps_tdma(btcoexist,
  2370. NORMAL_EXEC, true, 7);
  2371. coex_dm->ps_tdma_du_adj_type = 7;
  2372. } else if (coex_dm->cur_ps_tdma == 2) {
  2373. halbtc8812a2ant_ps_tdma(btcoexist,
  2374. NORMAL_EXEC, true, 7);
  2375. coex_dm->ps_tdma_du_adj_type = 7;
  2376. } else if (coex_dm->cur_ps_tdma == 3) {
  2377. halbtc8812a2ant_ps_tdma(btcoexist,
  2378. NORMAL_EXEC, true, 7);
  2379. coex_dm->ps_tdma_du_adj_type = 7;
  2380. } else if (coex_dm->cur_ps_tdma == 4) {
  2381. halbtc8812a2ant_ps_tdma(btcoexist,
  2382. NORMAL_EXEC, true, 8);
  2383. coex_dm->ps_tdma_du_adj_type = 8;
  2384. }
  2385. if (coex_dm->cur_ps_tdma == 9) {
  2386. halbtc8812a2ant_ps_tdma(btcoexist,
  2387. NORMAL_EXEC, true, 15);
  2388. coex_dm->ps_tdma_du_adj_type = 15;
  2389. } else if (coex_dm->cur_ps_tdma == 10) {
  2390. halbtc8812a2ant_ps_tdma(btcoexist,
  2391. NORMAL_EXEC, true, 15);
  2392. coex_dm->ps_tdma_du_adj_type = 15;
  2393. } else if (coex_dm->cur_ps_tdma == 11) {
  2394. halbtc8812a2ant_ps_tdma(btcoexist,
  2395. NORMAL_EXEC, true, 15);
  2396. coex_dm->ps_tdma_du_adj_type = 15;
  2397. } else if (coex_dm->cur_ps_tdma == 12) {
  2398. halbtc8812a2ant_ps_tdma(btcoexist,
  2399. NORMAL_EXEC, true, 16);
  2400. coex_dm->ps_tdma_du_adj_type = 16;
  2401. }
  2402. if (result == -1) {
  2403. if (coex_dm->cur_ps_tdma == 5) {
  2404. halbtc8812a2ant_ps_tdma(
  2405. btcoexist, NORMAL_EXEC,
  2406. true, 7);
  2407. coex_dm->ps_tdma_du_adj_type =
  2408. 7;
  2409. } else if (coex_dm->cur_ps_tdma == 6) {
  2410. halbtc8812a2ant_ps_tdma(
  2411. btcoexist, NORMAL_EXEC,
  2412. true, 7);
  2413. coex_dm->ps_tdma_du_adj_type =
  2414. 7;
  2415. } else if (coex_dm->cur_ps_tdma == 7) {
  2416. halbtc8812a2ant_ps_tdma(
  2417. btcoexist, NORMAL_EXEC,
  2418. true, 8);
  2419. coex_dm->ps_tdma_du_adj_type =
  2420. 8;
  2421. } else if (coex_dm->cur_ps_tdma == 13) {
  2422. halbtc8812a2ant_ps_tdma(
  2423. btcoexist, NORMAL_EXEC,
  2424. true, 15);
  2425. coex_dm->ps_tdma_du_adj_type =
  2426. 15;
  2427. } else if (coex_dm->cur_ps_tdma == 14) {
  2428. halbtc8812a2ant_ps_tdma(
  2429. btcoexist, NORMAL_EXEC,
  2430. true, 15);
  2431. coex_dm->ps_tdma_du_adj_type =
  2432. 15;
  2433. } else if (coex_dm->cur_ps_tdma == 15) {
  2434. halbtc8812a2ant_ps_tdma(
  2435. btcoexist, NORMAL_EXEC,
  2436. true, 16);
  2437. coex_dm->ps_tdma_du_adj_type =
  2438. 16;
  2439. }
  2440. } else if (result == 1) {
  2441. if (coex_dm->cur_ps_tdma == 8) {
  2442. halbtc8812a2ant_ps_tdma(
  2443. btcoexist, NORMAL_EXEC,
  2444. true, 7);
  2445. coex_dm->ps_tdma_du_adj_type =
  2446. 7;
  2447. } else if (coex_dm->cur_ps_tdma == 7) {
  2448. halbtc8812a2ant_ps_tdma(
  2449. btcoexist, NORMAL_EXEC,
  2450. true, 7);
  2451. coex_dm->ps_tdma_du_adj_type =
  2452. 7;
  2453. } else if (coex_dm->cur_ps_tdma == 6) {
  2454. halbtc8812a2ant_ps_tdma(
  2455. btcoexist, NORMAL_EXEC,
  2456. true, 7);
  2457. coex_dm->ps_tdma_du_adj_type =
  2458. 7;
  2459. } else if (coex_dm->cur_ps_tdma == 16) {
  2460. halbtc8812a2ant_ps_tdma(
  2461. btcoexist, NORMAL_EXEC,
  2462. true, 15);
  2463. coex_dm->ps_tdma_du_adj_type =
  2464. 15;
  2465. } else if (coex_dm->cur_ps_tdma == 15) {
  2466. halbtc8812a2ant_ps_tdma(
  2467. btcoexist, NORMAL_EXEC,
  2468. true, 15);
  2469. coex_dm->ps_tdma_du_adj_type =
  2470. 15;
  2471. } else if (coex_dm->cur_ps_tdma == 14) {
  2472. halbtc8812a2ant_ps_tdma(
  2473. btcoexist, NORMAL_EXEC,
  2474. true, 15);
  2475. coex_dm->ps_tdma_du_adj_type =
  2476. 15;
  2477. }
  2478. }
  2479. } else {
  2480. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2481. "[BTCoex], TxPause = 0\n");
  2482. BTC_TRACE(trace_buf);
  2483. if (coex_dm->cur_ps_tdma == 5) {
  2484. halbtc8812a2ant_ps_tdma(btcoexist,
  2485. NORMAL_EXEC, true, 3);
  2486. coex_dm->ps_tdma_du_adj_type = 3;
  2487. } else if (coex_dm->cur_ps_tdma == 6) {
  2488. halbtc8812a2ant_ps_tdma(btcoexist,
  2489. NORMAL_EXEC, true, 3);
  2490. coex_dm->ps_tdma_du_adj_type = 3;
  2491. } else if (coex_dm->cur_ps_tdma == 7) {
  2492. halbtc8812a2ant_ps_tdma(btcoexist,
  2493. NORMAL_EXEC, true, 3);
  2494. coex_dm->ps_tdma_du_adj_type = 3;
  2495. } else if (coex_dm->cur_ps_tdma == 8) {
  2496. halbtc8812a2ant_ps_tdma(btcoexist,
  2497. NORMAL_EXEC, true, 4);
  2498. coex_dm->ps_tdma_du_adj_type = 4;
  2499. }
  2500. if (coex_dm->cur_ps_tdma == 13) {
  2501. halbtc8812a2ant_ps_tdma(btcoexist,
  2502. NORMAL_EXEC, true, 11);
  2503. coex_dm->ps_tdma_du_adj_type = 11;
  2504. } else if (coex_dm->cur_ps_tdma == 14) {
  2505. halbtc8812a2ant_ps_tdma(btcoexist,
  2506. NORMAL_EXEC, true, 11);
  2507. coex_dm->ps_tdma_du_adj_type = 11;
  2508. } else if (coex_dm->cur_ps_tdma == 15) {
  2509. halbtc8812a2ant_ps_tdma(btcoexist,
  2510. NORMAL_EXEC, true, 11);
  2511. coex_dm->ps_tdma_du_adj_type = 11;
  2512. } else if (coex_dm->cur_ps_tdma == 16) {
  2513. halbtc8812a2ant_ps_tdma(btcoexist,
  2514. NORMAL_EXEC, true, 12);
  2515. coex_dm->ps_tdma_du_adj_type = 12;
  2516. }
  2517. if (result == -1) {
  2518. if (coex_dm->cur_ps_tdma == 1) {
  2519. halbtc8812a2ant_ps_tdma(
  2520. btcoexist, NORMAL_EXEC,
  2521. true, 3);
  2522. coex_dm->ps_tdma_du_adj_type =
  2523. 3;
  2524. } else if (coex_dm->cur_ps_tdma == 2) {
  2525. halbtc8812a2ant_ps_tdma(
  2526. btcoexist, NORMAL_EXEC,
  2527. true, 3);
  2528. coex_dm->ps_tdma_du_adj_type =
  2529. 3;
  2530. } else if (coex_dm->cur_ps_tdma == 3) {
  2531. halbtc8812a2ant_ps_tdma(
  2532. btcoexist, NORMAL_EXEC,
  2533. true, 4);
  2534. coex_dm->ps_tdma_du_adj_type =
  2535. 4;
  2536. } else if (coex_dm->cur_ps_tdma == 9) {
  2537. halbtc8812a2ant_ps_tdma(
  2538. btcoexist, NORMAL_EXEC,
  2539. true, 11);
  2540. coex_dm->ps_tdma_du_adj_type =
  2541. 11;
  2542. } else if (coex_dm->cur_ps_tdma == 10) {
  2543. halbtc8812a2ant_ps_tdma(
  2544. btcoexist, NORMAL_EXEC,
  2545. true, 11);
  2546. coex_dm->ps_tdma_du_adj_type =
  2547. 11;
  2548. } else if (coex_dm->cur_ps_tdma == 11) {
  2549. halbtc8812a2ant_ps_tdma(
  2550. btcoexist, NORMAL_EXEC,
  2551. true, 12);
  2552. coex_dm->ps_tdma_du_adj_type =
  2553. 12;
  2554. }
  2555. } else if (result == 1) {
  2556. if (coex_dm->cur_ps_tdma == 4) {
  2557. halbtc8812a2ant_ps_tdma(
  2558. btcoexist, NORMAL_EXEC,
  2559. true, 3);
  2560. coex_dm->ps_tdma_du_adj_type =
  2561. 3;
  2562. } else if (coex_dm->cur_ps_tdma == 3) {
  2563. halbtc8812a2ant_ps_tdma(
  2564. btcoexist, NORMAL_EXEC,
  2565. true, 3);
  2566. coex_dm->ps_tdma_du_adj_type =
  2567. 3;
  2568. } else if (coex_dm->cur_ps_tdma == 2) {
  2569. halbtc8812a2ant_ps_tdma(
  2570. btcoexist, NORMAL_EXEC,
  2571. true, 3);
  2572. coex_dm->ps_tdma_du_adj_type =
  2573. 3;
  2574. } else if (coex_dm->cur_ps_tdma == 12) {
  2575. halbtc8812a2ant_ps_tdma(
  2576. btcoexist, NORMAL_EXEC,
  2577. true, 11);
  2578. coex_dm->ps_tdma_du_adj_type =
  2579. 11;
  2580. } else if (coex_dm->cur_ps_tdma == 11) {
  2581. halbtc8812a2ant_ps_tdma(
  2582. btcoexist, NORMAL_EXEC,
  2583. true, 11);
  2584. coex_dm->ps_tdma_du_adj_type =
  2585. 11;
  2586. } else if (coex_dm->cur_ps_tdma == 10) {
  2587. halbtc8812a2ant_ps_tdma(
  2588. btcoexist, NORMAL_EXEC,
  2589. true, 11);
  2590. coex_dm->ps_tdma_du_adj_type =
  2591. 11;
  2592. }
  2593. }
  2594. }
  2595. }
  2596. }
  2597. /* if current PsTdma not match with the recorded one (when scan, dhcp...), */
  2598. /* then we have to adjust it back to the previous record one. */
  2599. if (coex_dm->cur_ps_tdma != coex_dm->ps_tdma_du_adj_type) {
  2600. boolean scan = false, link = false, roam = false;
  2601. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2602. "[BTCoex], PsTdma type dismatch!!!, cur_ps_tdma=%d, recordPsTdma=%d\n",
  2603. coex_dm->cur_ps_tdma, coex_dm->ps_tdma_du_adj_type);
  2604. BTC_TRACE(trace_buf);
  2605. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
  2606. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
  2607. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
  2608. if (!scan && !link && !roam)
  2609. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2610. coex_dm->ps_tdma_du_adj_type);
  2611. else {
  2612. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2613. "[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n");
  2614. BTC_TRACE(trace_buf);
  2615. }
  2616. }
  2617. }
  2618. /* ******************
  2619. * pstdma for wifi rssi low
  2620. * ****************** */
  2621. void halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low(
  2622. IN struct btc_coexist *btcoexist/* , */ /* IN u8 wifi_status */)
  2623. {
  2624. static s32 up, dn, m, n, wait_count;
  2625. s32 result; /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */
  2626. u8 retry_count = 0, bt_info_ext;
  2627. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2628. "[BTCoex], halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low()\n");
  2629. BTC_TRACE(trace_buf);
  2630. #if 0
  2631. if ((BT_8812A_2ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN ==
  2632. wifi_status) ||
  2633. (BT_8812A_2ANT_WIFI_STATUS_CONNECTED_SCAN == wifi_status) ||
  2634. (BT_8812A_2ANT_WIFI_STATUS_CONNECTED_SPECIAL_PKT ==
  2635. wifi_status)) {
  2636. if (coex_dm->cur_ps_tdma != 81 &&
  2637. coex_dm->cur_ps_tdma != 82 &&
  2638. coex_dm->cur_ps_tdma != 83 &&
  2639. coex_dm->cur_ps_tdma != 84) {
  2640. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2641. 82);
  2642. coex_dm->ps_tdma_du_adj_type = 82;
  2643. up = 0;
  2644. dn = 0;
  2645. m = 1;
  2646. n = 3;
  2647. result = 0;
  2648. wait_count = 0;
  2649. }
  2650. return;
  2651. }
  2652. #endif
  2653. coex_dm->auto_tdma_adjust = false;
  2654. retry_count = coex_sta->bt_retry_cnt;
  2655. bt_info_ext = coex_sta->bt_info_ext;
  2656. if (!coex_dm->auto_tdma_adjust_low_rssi) {
  2657. coex_dm->auto_tdma_adjust_low_rssi = true;
  2658. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2659. "[BTCoex], first run TdmaDurationAdjustForWifiRssiLow()!!\n");
  2660. BTC_TRACE(trace_buf);
  2661. if (BT_INFO_8812A_2ANT_A2DP_BASIC_RATE(bt_info_ext)) {
  2662. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2663. 83);
  2664. coex_dm->ps_tdma_du_adj_type = 83;
  2665. } else {
  2666. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2667. 82);
  2668. coex_dm->ps_tdma_du_adj_type = 82;
  2669. }
  2670. /* ============ */
  2671. up = 0;
  2672. dn = 0;
  2673. m = 1;
  2674. n = 3;
  2675. result = 0;
  2676. wait_count = 0;
  2677. } else {
  2678. /* acquire the BT TRx retry count from BT_Info byte2
  2679. * retry_count = coex_sta->bt_retry_cnt;
  2680. * bt_info_ext = coex_sta->bt_info_ext; */
  2681. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2682. "[BTCoex], retry_count = %d\n",
  2683. retry_count);
  2684. BTC_TRACE(trace_buf);
  2685. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2686. "[BTCoex], up=%d, dn=%d, m=%d, n=%d, wait_count=%d\n",
  2687. up, dn, m, n, wait_count);
  2688. BTC_TRACE(trace_buf);
  2689. result = 0;
  2690. wait_count++;
  2691. if ((coex_sta->low_priority_tx) > 1050 ||
  2692. (coex_sta->low_priority_rx) > 1250)
  2693. retry_count++;
  2694. if (retry_count ==
  2695. 0) { /* no retry in the last 2-second duration */
  2696. up++;
  2697. dn--;
  2698. if (dn <= 0)
  2699. dn = 0;
  2700. if (up >= n) { /* if 連續 n 個2秒 retry count為0, 則調寬WiFi duration */
  2701. wait_count = 0;
  2702. n = 3;
  2703. up = 0;
  2704. dn = 0;
  2705. result = 1;
  2706. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2707. "[BTCoex], Increase wifi duration!!\n");
  2708. BTC_TRACE(trace_buf);
  2709. }
  2710. } else if (retry_count <=
  2711. 3) { /* <=3 retry in the last 2-second duration */
  2712. up--;
  2713. dn++;
  2714. if (up <= 0)
  2715. up = 0;
  2716. if (dn == 2) { /* if 連續 2 個2秒 retry count< 3, 則調窄WiFi duration */
  2717. if (wait_count <= 2)
  2718. m++; /* 避免一直在兩個level中來回 */
  2719. else
  2720. m = 1;
  2721. if (m >= 20) /* m 最大值 = 20 ' 最大120秒 recheck是否調整 WiFi duration. */
  2722. m = 20;
  2723. n = 3 * m;
  2724. up = 0;
  2725. dn = 0;
  2726. wait_count = 0;
  2727. result = -1;
  2728. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2729. "[BTCoex], Decrease wifi duration for retry_counter<3!!\n");
  2730. BTC_TRACE(trace_buf);
  2731. }
  2732. } else { /* retry count > 3, 只要1次 retry count > 3, 則調窄WiFi duration */
  2733. if (wait_count == 1)
  2734. m++; /* 避免一直在兩個level中來回 */
  2735. else
  2736. m = 1;
  2737. if (m >= 20) /* m 最大值 = 20 ' 最大120秒 recheck是否調整 WiFi duration. */
  2738. m = 20;
  2739. n = 3 * m;
  2740. up = 0;
  2741. dn = 0;
  2742. wait_count = 0;
  2743. result = -1;
  2744. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2745. "[BTCoex], Decrease wifi duration for retry_counter>3!!\n");
  2746. BTC_TRACE(trace_buf);
  2747. }
  2748. if (result == -1) {
  2749. /*
  2750. if( (BT_INFO_8812A_2ANT_A2DP_BASIC_RATE(bt_info_ext)) &&
  2751. ((coex_dm->cur_ps_tdma == 81) ||(coex_dm->cur_ps_tdma == 82)) )
  2752. {
  2753. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 84);
  2754. coex_dm->ps_tdma_du_adj_type = 84;
  2755. }
  2756. */
  2757. if (coex_dm->cur_ps_tdma == 80) {
  2758. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2759. true, 82);
  2760. coex_dm->ps_tdma_du_adj_type = 82;
  2761. } else if (coex_dm->cur_ps_tdma == 81) {
  2762. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2763. true, 82);
  2764. coex_dm->ps_tdma_du_adj_type = 82;
  2765. } else if (coex_dm->cur_ps_tdma == 82) {
  2766. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2767. true, 83);
  2768. coex_dm->ps_tdma_du_adj_type = 83;
  2769. } else if (coex_dm->cur_ps_tdma == 83) {
  2770. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2771. true, 84);
  2772. coex_dm->ps_tdma_du_adj_type = 84;
  2773. }
  2774. } else if (result == 1) {
  2775. /*
  2776. if( (BT_INFO_8812A_2ANT_A2DP_BASIC_RATE(bt_info_ext)) &&
  2777. ((coex_dm->cur_ps_tdma == 81) ||(coex_dm->cur_ps_tdma == 82)) )
  2778. {
  2779. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 83);
  2780. coex_dm->ps_tdma_du_adj_type = 83;
  2781. }
  2782. */
  2783. if (coex_dm->cur_ps_tdma == 84) {
  2784. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2785. true, 83);
  2786. coex_dm->ps_tdma_du_adj_type = 83;
  2787. } else if (coex_dm->cur_ps_tdma == 83) {
  2788. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2789. true, 82);
  2790. coex_dm->ps_tdma_du_adj_type = 82;
  2791. } else if (coex_dm->cur_ps_tdma == 82) {
  2792. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2793. true, 81);
  2794. coex_dm->ps_tdma_du_adj_type = 81;
  2795. } else if ((coex_dm->cur_ps_tdma == 81) &&
  2796. ((coex_sta->scan_ap_num <= 5))) {
  2797. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC,
  2798. true, 81);
  2799. coex_dm->ps_tdma_du_adj_type = 81;
  2800. }
  2801. }
  2802. if (coex_dm->cur_ps_tdma != 80 &&
  2803. coex_dm->cur_ps_tdma != 81 &&
  2804. coex_dm->cur_ps_tdma != 82 &&
  2805. coex_dm->cur_ps_tdma != 83 &&
  2806. coex_dm->cur_ps_tdma != 84) {
  2807. /* recover to previous adjust type */
  2808. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  2809. coex_dm->ps_tdma_du_adj_type);
  2810. }
  2811. }
  2812. }
  2813. void halbtc8812a2ant_get_bt_rssi_threshold(IN struct btc_coexist *btcoexist,
  2814. IN u8 *pThres0, IN u8 *pThres1)
  2815. {
  2816. u8 ant_type;
  2817. btcoexist->btc_get(btcoexist, BTC_GET_U1_ANT_TYPE, &ant_type);
  2818. switch (ant_type) {
  2819. case BTC_ANT_TYPE_0:
  2820. *pThres0 = 100;
  2821. *pThres1 = 100;
  2822. break;
  2823. case BTC_ANT_TYPE_1:
  2824. *pThres0 = 34;
  2825. *pThres1 = 42;
  2826. break;
  2827. case BTC_ANT_TYPE_2:
  2828. *pThres0 = 34;
  2829. *pThres1 = 42;
  2830. break;
  2831. case BTC_ANT_TYPE_3:
  2832. *pThres0 = 34;
  2833. *pThres1 = 42;
  2834. break;
  2835. case BTC_ANT_TYPE_4:
  2836. *pThres0 = 34;
  2837. *pThres1 = 42;
  2838. break;
  2839. default:
  2840. break;
  2841. }
  2842. }
  2843. void halbtc8812a2ant_action_sco(IN struct btc_coexist *btcoexist)
  2844. {
  2845. u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH,
  2846. bt_rssi_state = BTC_RSSI_STATE_HIGH;
  2847. u32 wifi_bw;
  2848. u8 bt_thresh0 = 0, bt_thresh1 = 0;
  2849. /* halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0, &bt_thresh1); */
  2850. bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0,
  2851. bt_thresh1);
  2852. wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34,
  2853. 0);
  2854. bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42);
  2855. /* power save state */
  2856. halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
  2857. 0x0);
  2858. /* coex table */
  2859. if (BTC_RSSI_LOW(bt_rssi_state))
  2860. halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
  2861. else
  2862. halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  2863. /* pstdma */
  2864. if (BTC_RSSI_LOW(bt_rssi_state))
  2865. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 13);
  2866. else
  2867. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 9);
  2868. /* decrease BT power */
  2869. if (BTC_RSSI_LOW(bt_rssi_state))
  2870. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2871. else if (BTC_RSSI_MEDIUM(bt_rssi_state))
  2872. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
  2873. else
  2874. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4);
  2875. /* limited Rx */
  2876. halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
  2877. /* fw dac swing level */
  2878. halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  2879. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  2880. /* sw mechanism */
  2881. if (BTC_WIFI_BW_HT40 == wifi_bw) {
  2882. if (BTC_RSSI_HIGH(wifi_rssi_state)) {
  2883. halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
  2884. false, false);
  2885. halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
  2886. true, 0x6);
  2887. } else {
  2888. halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
  2889. false, false);
  2890. halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
  2891. true, 0x6);
  2892. }
  2893. } else {
  2894. if (BTC_RSSI_HIGH(wifi_rssi_state)) {
  2895. halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
  2896. false, false);
  2897. halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
  2898. true, 0x6);
  2899. } else {
  2900. halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
  2901. false, false);
  2902. halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
  2903. true, 0x6);
  2904. }
  2905. }
  2906. }
  2907. void halbtc8812a2ant_action_sco_hid(IN struct btc_coexist *btcoexist)
  2908. {
  2909. u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH,
  2910. bt_rssi_state = BTC_RSSI_STATE_HIGH;
  2911. u32 wifi_bw;
  2912. u8 bt_thresh0 = 0, bt_thresh1 = 0;
  2913. /* halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0, &bt_thresh1); */
  2914. bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0,
  2915. bt_thresh1);
  2916. wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34,
  2917. 0);
  2918. bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42);
  2919. /* power save state */
  2920. halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
  2921. 0x0);
  2922. /* coex table */
  2923. halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  2924. /* pstdma */
  2925. if (BTC_RSSI_LOW(bt_rssi_state))
  2926. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 13);
  2927. else
  2928. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 9);
  2929. /* decrease BT power */
  2930. if (BTC_RSSI_LOW(bt_rssi_state))
  2931. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  2932. else if (BTC_RSSI_MEDIUM(bt_rssi_state))
  2933. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
  2934. else
  2935. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4);
  2936. /* limited Rx */
  2937. halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, true, 0x8);
  2938. /* fw dac swing level */
  2939. halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  2940. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  2941. /* sw mechanism */
  2942. if (BTC_WIFI_BW_HT40 == wifi_bw) {
  2943. if (BTC_RSSI_HIGH(wifi_rssi_state)) {
  2944. halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
  2945. false, false);
  2946. halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
  2947. false, 0x6);
  2948. } else {
  2949. halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
  2950. false, false);
  2951. halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
  2952. false, 0x6);
  2953. }
  2954. } else {
  2955. if (BTC_RSSI_HIGH(wifi_rssi_state)) {
  2956. halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
  2957. false, false);
  2958. halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
  2959. false, 0x6);
  2960. } else {
  2961. halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
  2962. false, false);
  2963. halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
  2964. false, 0x6);
  2965. }
  2966. }
  2967. }
  2968. void halbtc8812a2ant_action_hid(IN struct btc_coexist *btcoexist)
  2969. {
  2970. u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH,
  2971. bt_rssi_state = BTC_RSSI_STATE_HIGH;
  2972. u32 wifi_bw;
  2973. u8 anttype = 0;
  2974. btcoexist->btc_get(btcoexist, BTC_GET_U1_ANT_TYPE, &anttype);
  2975. /* halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0, &bt_thresh1);
  2976. * bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0, bt_thresh1); */
  2977. wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34,
  2978. 0);
  2979. bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42);
  2980. if (anttype == 0) { /* ANTTYPE = 0 92E 2ant with SPDT */
  2981. /* power save state & pstdma & coex table */
  2982. coex_dm->auto_tdma_adjust = false;
  2983. coex_dm->auto_tdma_adjust_low_rssi = false;
  2984. halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  2985. 0x0, 0x0);
  2986. halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0);
  2987. halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  2988. } else if (anttype ==
  2989. 1) { /* 92E 2ant with coupler and bad ant. isolation, 92E 3ant with bad ant. isolation */
  2990. /* power save state & pstdma & coex table */
  2991. coex_dm->auto_tdma_adjust = false;
  2992. coex_dm->auto_tdma_adjust_low_rssi = false;
  2993. halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  2994. 0x0, 0x0);
  2995. halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0);
  2996. halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  2997. } else if (anttype ==
  2998. 2) { /* ANTTYPE = 2, 92E 2ant with coupler and normal/good ant. isolation, 92E 3ant with normal ant. isolation */
  2999. /* power save state & pstdma & coex table */
  3000. if (BTC_RSSI_HIGH(wifi_rssi_state) &&
  3001. (!BTC_RSSI_LOW(bt_rssi_state)) &&
  3002. (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8812A)) {
  3003. /* WIFI RSSI = high & BT RSSI = high & shielding room */
  3004. halbtc8812a2ant_power_save_state(btcoexist,
  3005. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  3006. halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, true, 9);
  3007. halbtc8812a2ant_coex_table_with_type(btcoexist,
  3008. NORMAL_EXEC, 3);
  3009. } else if (BTC_RSSI_HIGH(wifi_rssi_state) &&
  3010. (!BTC_RSSI_LOW(bt_rssi_state)) &&
  3011. (coex_sta->scan_ap_num > NOISY_AP_NUM_THRESH_8812A)) {
  3012. /* WIFI RSSI = high & BT RSSI = high & noisy environment */
  3013. halbtc8812a2ant_power_save_state(btcoexist,
  3014. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  3015. halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, true, 9);
  3016. halbtc8812a2ant_coex_table_with_type(btcoexist,
  3017. NORMAL_EXEC, 3);
  3018. } else { /* WIFI RSSI || BT RSSI == low */
  3019. halbtc8812a2ant_power_save_state(btcoexist,
  3020. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  3021. halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, true, 9);
  3022. halbtc8812a2ant_coex_table_with_type(btcoexist,
  3023. NORMAL_EXEC, 3);
  3024. }
  3025. } else if (anttype ==
  3026. 3) { /* ANTTYPE = 3, 92E 3ant with good ant. isolation */
  3027. /* power save state & pstdma & coex table */
  3028. if (BTC_RSSI_HIGH(wifi_rssi_state) &&
  3029. (!BTC_RSSI_LOW(bt_rssi_state)) &&
  3030. (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8812A)) {
  3031. /* WIFI RSSI = high & BT RSSI = high & shielding room */
  3032. coex_dm->auto_tdma_adjust = false;
  3033. coex_dm->auto_tdma_adjust_low_rssi = false;
  3034. halbtc8812a2ant_power_save_state(btcoexist,
  3035. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  3036. halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false,
  3037. 1);
  3038. halbtc8812a2ant_coex_table_with_type(btcoexist,
  3039. NORMAL_EXEC, 0);
  3040. } else if (BTC_RSSI_HIGH(wifi_rssi_state) &&
  3041. (!BTC_RSSI_LOW(bt_rssi_state)) &&
  3042. (coex_sta->scan_ap_num > NOISY_AP_NUM_THRESH_8812A)) {
  3043. /* WIFI RSSI = high & BT RSSI = high & noisy environment */
  3044. coex_dm->auto_tdma_adjust = false;
  3045. coex_dm->auto_tdma_adjust_low_rssi = false;
  3046. halbtc8812a2ant_power_save_state(btcoexist,
  3047. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  3048. halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false,
  3049. 1);
  3050. halbtc8812a2ant_coex_table_with_type(btcoexist,
  3051. NORMAL_EXEC, 0);
  3052. } else { /* WIFI RSSI || BT RSSI == low */
  3053. coex_dm->auto_tdma_adjust = false;
  3054. coex_dm->auto_tdma_adjust_low_rssi = false;
  3055. halbtc8812a2ant_power_save_state(btcoexist,
  3056. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  3057. halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false,
  3058. 1);
  3059. halbtc8812a2ant_coex_table_with_type(btcoexist,
  3060. NORMAL_EXEC, 0);
  3061. }
  3062. } else { /* ANTTYPE = 4 for test */
  3063. /* power save state & pstdma & coex table */
  3064. if (BTC_RSSI_HIGH(wifi_rssi_state) &&
  3065. (!BTC_RSSI_LOW(bt_rssi_state)) &&
  3066. (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8812A)) {
  3067. /* WIFI RSSI = high & BT RSSI = high & shielding room */
  3068. halbtc8812a2ant_power_save_state(btcoexist,
  3069. BTC_PS_LPS_ON, 0x50, 0x4);
  3070. halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low(
  3071. btcoexist);
  3072. halbtc8812a2ant_coex_table_with_type(btcoexist,
  3073. NORMAL_EXEC, 7);
  3074. } else if (BTC_RSSI_HIGH(wifi_rssi_state) &&
  3075. (!BTC_RSSI_LOW(bt_rssi_state)) &&
  3076. (coex_sta->scan_ap_num > NOISY_AP_NUM_THRESH_8812A)) {
  3077. /* WIFI RSSI = high & BT RSSI = high & noisy environment */
  3078. halbtc8812a2ant_power_save_state(btcoexist,
  3079. BTC_PS_LPS_ON, 0x50, 0x4);
  3080. halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low(
  3081. btcoexist);
  3082. halbtc8812a2ant_coex_table_with_type(btcoexist,
  3083. NORMAL_EXEC, 7);
  3084. } else { /* WIFI RSSI || BT RSSI == low */
  3085. halbtc8812a2ant_power_save_state(btcoexist,
  3086. BTC_PS_LPS_ON, 0x50, 0x4);
  3087. halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low(
  3088. btcoexist);
  3089. halbtc8812a2ant_coex_table_with_type(btcoexist,
  3090. NORMAL_EXEC, 7);
  3091. }
  3092. }
  3093. /* power save state */
  3094. halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
  3095. 0x0);
  3096. /* coex table */
  3097. halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  3098. /* pstdma */
  3099. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  3100. /* decrease BT power */
  3101. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  3102. /* limited Rx */
  3103. halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
  3104. /* fw dac swing level */
  3105. halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  3106. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  3107. /* sw mechanism */
  3108. if (BTC_WIFI_BW_HT40 == wifi_bw) {
  3109. if (BTC_RSSI_HIGH(wifi_rssi_state)) {
  3110. halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
  3111. false, false);
  3112. halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
  3113. false, 0x18);
  3114. } else {
  3115. halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
  3116. false, false);
  3117. halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
  3118. false, 0x18);
  3119. }
  3120. } else {
  3121. if (BTC_RSSI_HIGH(wifi_rssi_state)) {
  3122. halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
  3123. false, false);
  3124. halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
  3125. false, 0x18);
  3126. } else {
  3127. halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
  3128. false, false);
  3129. halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
  3130. false, 0x18);
  3131. }
  3132. }
  3133. }
  3134. /* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */
  3135. void halbtc8812a2ant_action_a2dp(IN struct btc_coexist *btcoexist)
  3136. {
  3137. u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH,
  3138. bt_rssi_state = BTC_RSSI_STATE_HIGH;
  3139. u32 wifi_bw;
  3140. u8 anttype = 0;
  3141. boolean ap_enable = false;
  3142. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
  3143. &ap_enable);
  3144. btcoexist->btc_get(btcoexist, BTC_GET_U1_ANT_TYPE, &anttype);
  3145. /* halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0, &bt_thresh1);
  3146. * bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0, bt_thresh1); */
  3147. wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34,
  3148. 0);
  3149. bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42);
  3150. /* anttype = 4; */
  3151. if (anttype == 0) { /* ANTTYPE = 0 92E 2ant with SPDT */
  3152. if (coex_sta->scan_ap_num > NOISY_AP_NUM_THRESH_8812A) {
  3153. coex_dm->auto_tdma_adjust = false;
  3154. coex_dm->auto_tdma_adjust_low_rssi = false;
  3155. halbtc8812a2ant_power_save_state(btcoexist,
  3156. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  3157. halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false,
  3158. 0);
  3159. halbtc8812a2ant_coex_table_with_type(btcoexist,
  3160. NORMAL_EXEC, 0);
  3161. } else {
  3162. if (BTC_RSSI_HIGH(wifi_rssi_state) &&
  3163. (!BTC_RSSI_LOW(bt_rssi_state))) {
  3164. /* WIFI RSSI = high & BT RSSI = high & shielding room */
  3165. halbtc8812a2ant_power_save_state(btcoexist,
  3166. BTC_PS_LPS_ON, 0x50, 0x4);
  3167. halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low(
  3168. btcoexist);
  3169. halbtc8812a2ant_coex_table_with_type(btcoexist,
  3170. NORMAL_EXEC, 7);
  3171. } else { /* WIFI RSSI || BT RSSI == low */
  3172. halbtc8812a2ant_power_save_state(btcoexist,
  3173. BTC_PS_LPS_ON, 0x50, 0x4);
  3174. halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low(
  3175. btcoexist);
  3176. halbtc8812a2ant_coex_table_with_type(btcoexist,
  3177. NORMAL_EXEC, 7);
  3178. }
  3179. }
  3180. /* power save state & pstdma & coex table
  3181. *
  3182. if(BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)) && (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8812A))
  3183. {
  3184. halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50, 0x4);
  3185. halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low(btcoexist);
  3186. halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
  3187. }
  3188. else if (BTC_RSSI_HIGH(wifi_rssi_state)&&(!BTC_RSSI_LOW(bt_rssi_state)) && (coex_sta->scan_ap_num > NOISY_AP_NUM_THRESH_8812A))
  3189. {
  3190. coex_dm->auto_tdma_adjust = false;
  3191. coex_dm->auto_tdma_adjust_low_rssi = false;
  3192. halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  3193. halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0);
  3194. halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  3195. }
  3196. else
  3197. {
  3198. halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50, 0x4);
  3199. halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low(btcoexist);
  3200. halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
  3201. }
  3202. */
  3203. } else if (anttype ==
  3204. 1) { /* 92E 2ant with coupler and bad ant. isolation, 92E 3ant with bad ant. isolation */
  3205. /* power save state & pstdma & coex table */
  3206. if (BTC_RSSI_HIGH(wifi_rssi_state) &&
  3207. (!BTC_RSSI_LOW(bt_rssi_state)) &&
  3208. (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8812A)) {
  3209. /* WIFI RSSI = high & BT RSSI = high & shielding room */
  3210. halbtc8812a2ant_power_save_state(btcoexist,
  3211. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  3212. halbtc8812a2ant_tdma_duration_adjust(btcoexist, false,
  3213. false, 1); /* shielding room */
  3214. halbtc8812a2ant_coex_table_with_type(btcoexist,
  3215. NORMAL_EXEC, 0);
  3216. } else if (BTC_RSSI_HIGH(wifi_rssi_state) &&
  3217. (!BTC_RSSI_LOW(bt_rssi_state)) &&
  3218. (coex_sta->scan_ap_num > NOISY_AP_NUM_THRESH_8812A)) {
  3219. /* WIFI RSSI = high & BT RSSI = high & noisy environment */
  3220. coex_dm->auto_tdma_adjust = false;
  3221. coex_dm->auto_tdma_adjust_low_rssi = false;
  3222. halbtc8812a2ant_power_save_state(btcoexist,
  3223. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  3224. halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false,
  3225. 1);
  3226. halbtc8812a2ant_coex_table_with_type(btcoexist,
  3227. NORMAL_EXEC, 0);
  3228. } else { /* WIFI RSSI || BT RSSI == low */
  3229. halbtc8812a2ant_power_save_state(btcoexist,
  3230. BTC_PS_LPS_ON, 0x50, 0x4);
  3231. halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low(
  3232. btcoexist);
  3233. halbtc8812a2ant_coex_table_with_type(btcoexist,
  3234. NORMAL_EXEC, 7);
  3235. }
  3236. } else if (anttype ==
  3237. 2) { /* ANTTYPE = 2, 92E 2ant with coupler and normal/good ant. isolation, 92E 3ant with normal ant. isolation */
  3238. /* power save state & pstdma & coex table */
  3239. if (BTC_RSSI_HIGH(wifi_rssi_state) &&
  3240. (!BTC_RSSI_LOW(bt_rssi_state)) &&
  3241. (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8812A)) {
  3242. /* WIFI RSSI = high & BT RSSI = high & shielding room */
  3243. halbtc8812a2ant_power_save_state(btcoexist,
  3244. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  3245. halbtc8812a2ant_tdma_duration_adjust(btcoexist, false,
  3246. false, 1);
  3247. halbtc8812a2ant_coex_table_with_type(btcoexist,
  3248. NORMAL_EXEC, 5);
  3249. } else if (BTC_RSSI_HIGH(wifi_rssi_state) &&
  3250. (!BTC_RSSI_LOW(bt_rssi_state)) &&
  3251. (coex_sta->scan_ap_num > NOISY_AP_NUM_THRESH_8812A)) {
  3252. /* WIFI RSSI = high & BT RSSI = high & noisy environment */
  3253. coex_dm->auto_tdma_adjust = false;
  3254. coex_dm->auto_tdma_adjust_low_rssi = false;
  3255. halbtc8812a2ant_power_save_state(btcoexist,
  3256. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  3257. halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false,
  3258. 1);
  3259. halbtc8812a2ant_coex_table_with_type(btcoexist,
  3260. NORMAL_EXEC, 0);
  3261. } else { /* WIFI RSSI || BT RSSI == low */
  3262. halbtc8812a2ant_power_save_state(btcoexist,
  3263. BTC_PS_LPS_ON, 0x50, 0x4);
  3264. halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low(
  3265. btcoexist);
  3266. halbtc8812a2ant_coex_table_with_type(btcoexist,
  3267. NORMAL_EXEC, 7);
  3268. }
  3269. } else if (anttype ==
  3270. 3) { /* ANTTYPE = 3, 92E 3ant with good ant. isolation */
  3271. /* power save state & pstdma & coex table */
  3272. if (BTC_RSSI_HIGH(wifi_rssi_state) &&
  3273. (!BTC_RSSI_LOW(bt_rssi_state)) &&
  3274. (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8812A)) {
  3275. /* WIFI RSSI = high & BT RSSI = high & shielding room */
  3276. coex_dm->auto_tdma_adjust = false;
  3277. coex_dm->auto_tdma_adjust_low_rssi = false;
  3278. halbtc8812a2ant_power_save_state(btcoexist,
  3279. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  3280. halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false,
  3281. 1);
  3282. halbtc8812a2ant_coex_table_with_type(btcoexist,
  3283. NORMAL_EXEC, 0);
  3284. } else if (BTC_RSSI_HIGH(wifi_rssi_state) &&
  3285. (!BTC_RSSI_LOW(bt_rssi_state)) &&
  3286. (coex_sta->scan_ap_num > NOISY_AP_NUM_THRESH_8812A)) {
  3287. /* WIFI RSSI = high & BT RSSI = high & noisy environment */
  3288. coex_dm->auto_tdma_adjust = false;
  3289. coex_dm->auto_tdma_adjust_low_rssi = false;
  3290. halbtc8812a2ant_power_save_state(btcoexist,
  3291. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  3292. halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false,
  3293. 1);
  3294. halbtc8812a2ant_coex_table_with_type(btcoexist,
  3295. NORMAL_EXEC, 0);
  3296. } else { /* WIFI RSSI || BT RSSI == low */
  3297. coex_dm->auto_tdma_adjust = false;
  3298. coex_dm->auto_tdma_adjust_low_rssi = false;
  3299. halbtc8812a2ant_power_save_state(btcoexist,
  3300. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  3301. halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false,
  3302. 1);
  3303. halbtc8812a2ant_coex_table_with_type(btcoexist,
  3304. NORMAL_EXEC, 0);
  3305. }
  3306. } else { /* ANTTYPE = 4 for test */
  3307. /* power save state & pstdma & coex table */
  3308. if (BTC_RSSI_HIGH(wifi_rssi_state) &&
  3309. (!BTC_RSSI_LOW(bt_rssi_state)) &&
  3310. (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8812A)) {
  3311. /* WIFI RSSI = high & BT RSSI = high & shielding room */
  3312. halbtc8812a2ant_power_save_state(btcoexist,
  3313. BTC_PS_LPS_ON, 0x50, 0x4);
  3314. halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low(
  3315. btcoexist);
  3316. halbtc8812a2ant_coex_table_with_type(btcoexist,
  3317. NORMAL_EXEC, 7);
  3318. } else if (BTC_RSSI_HIGH(wifi_rssi_state) &&
  3319. (!BTC_RSSI_LOW(bt_rssi_state)) &&
  3320. (coex_sta->scan_ap_num > NOISY_AP_NUM_THRESH_8812A)) {
  3321. /* WIFI RSSI = high & BT RSSI = high & noisy environment */
  3322. halbtc8812a2ant_power_save_state(btcoexist,
  3323. BTC_PS_LPS_ON, 0x50, 0x4);
  3324. halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low(
  3325. btcoexist);
  3326. halbtc8812a2ant_coex_table_with_type(btcoexist,
  3327. NORMAL_EXEC, 7);
  3328. } else { /* WIFI RSSI || BT RSSI == low */
  3329. halbtc8812a2ant_power_save_state(btcoexist,
  3330. BTC_PS_LPS_ON, 0x50, 0x4);
  3331. halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low(
  3332. btcoexist);
  3333. halbtc8812a2ant_coex_table_with_type(btcoexist,
  3334. NORMAL_EXEC, 7);
  3335. }
  3336. }
  3337. /* decrease BT power */
  3338. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  3339. /* decrease BT power
  3340. *
  3341. if(BTC_RSSI_LOW(bt_rssi_state))
  3342. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  3343. else if(BTC_RSSI_MEDIUM(bt_rssi_state))
  3344. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
  3345. else if (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8812A)
  3346. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4);
  3347. */
  3348. /* limited Rx */
  3349. halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
  3350. /* fw dac swing level */
  3351. halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  3352. /* sw mechanism */
  3353. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  3354. if (BTC_WIFI_BW_HT40 == wifi_bw) {
  3355. if (BTC_RSSI_HIGH(wifi_rssi_state)) {
  3356. halbtc8812a2ant_sw_mechanism1(btcoexist, true, false,
  3357. false, false);
  3358. halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
  3359. false, 0x18);
  3360. } else {
  3361. halbtc8812a2ant_sw_mechanism1(btcoexist, true, false,
  3362. false, false);
  3363. halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
  3364. false, 0x18);
  3365. }
  3366. } else {
  3367. if (BTC_RSSI_HIGH(wifi_rssi_state)) {
  3368. halbtc8812a2ant_sw_mechanism1(btcoexist, false, false,
  3369. false, false);
  3370. halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
  3371. false, 0x18);
  3372. } else {
  3373. halbtc8812a2ant_sw_mechanism1(btcoexist, false, false,
  3374. false, false);
  3375. halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
  3376. false, 0x18);
  3377. }
  3378. }
  3379. }
  3380. void halbtc8812a2ant_action_a2dp_pan_hs(IN struct btc_coexist *btcoexist)
  3381. {
  3382. u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH,
  3383. bt_rssi_state = BTC_RSSI_STATE_HIGH;
  3384. u32 wifi_bw;
  3385. u8 bt_thresh0 = 0, bt_thresh1 = 0;
  3386. /* halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0, &bt_thresh1); */
  3387. bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0,
  3388. bt_thresh1);
  3389. wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34,
  3390. 0);
  3391. bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42);
  3392. /* power save state */
  3393. halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
  3394. 0x0);
  3395. /* coex table */
  3396. if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
  3397. halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  3398. else
  3399. halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
  3400. /* pstdma */
  3401. if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
  3402. halbtc8812a2ant_tdma_duration_adjust(btcoexist, false, false,
  3403. 2);
  3404. else
  3405. halbtc8812a2ant_tdma_duration_adjust(btcoexist, false, true, 2);
  3406. /* decrease BT power */
  3407. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  3408. /*
  3409. if(BTC_RSSI_LOW(bt_rssi_state))
  3410. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  3411. else if(BTC_RSSI_MEDIUM(bt_rssi_state))
  3412. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
  3413. else
  3414. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4);
  3415. */
  3416. /* limited Rx */
  3417. halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
  3418. /* fw dac swing level */
  3419. halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  3420. /* sw mechanism */
  3421. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  3422. if (BTC_WIFI_BW_HT40 == wifi_bw) {
  3423. if (BTC_RSSI_HIGH(wifi_rssi_state)) {
  3424. halbtc8812a2ant_sw_mechanism1(btcoexist, true, false,
  3425. false, false);
  3426. halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
  3427. true, 0x6);
  3428. } else {
  3429. halbtc8812a2ant_sw_mechanism1(btcoexist, true, false,
  3430. false, false);
  3431. halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
  3432. true, 0x6);
  3433. }
  3434. } else {
  3435. if (BTC_RSSI_HIGH(wifi_rssi_state)) {
  3436. halbtc8812a2ant_sw_mechanism1(btcoexist, false, false,
  3437. false, false);
  3438. halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
  3439. true, 0x6);
  3440. } else {
  3441. halbtc8812a2ant_sw_mechanism1(btcoexist, false, false,
  3442. false, false);
  3443. halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
  3444. true, 0x6);
  3445. }
  3446. }
  3447. }
  3448. void halbtc8812a2ant_action_pan_edr(IN struct btc_coexist *btcoexist)
  3449. {
  3450. u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH,
  3451. bt_rssi_state = BTC_RSSI_STATE_HIGH;
  3452. u32 wifi_bw;
  3453. u8 bt_thresh0 = 0, bt_thresh1 = 0;
  3454. halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0,
  3455. &bt_thresh1);
  3456. bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0,
  3457. bt_thresh1);
  3458. wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34,
  3459. 0);
  3460. /* bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); */
  3461. /* power save state */
  3462. if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
  3463. halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  3464. 0x0, 0x0);
  3465. else
  3466. halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50,
  3467. 0x4);
  3468. /* coex table */
  3469. if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
  3470. halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  3471. else
  3472. halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  3473. /* pstdma */
  3474. if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
  3475. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 1);
  3476. else
  3477. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 85);
  3478. /* decrease BT power */
  3479. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  3480. /* limited Rx */
  3481. halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
  3482. /* fw dac swing level */
  3483. halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  3484. /* sw mechanism */
  3485. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  3486. if (BTC_WIFI_BW_HT40 == wifi_bw) {
  3487. if (BTC_RSSI_HIGH(wifi_rssi_state)) {
  3488. halbtc8812a2ant_sw_mechanism1(btcoexist, true, false,
  3489. false, false);
  3490. halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
  3491. false, 0x18);
  3492. } else {
  3493. halbtc8812a2ant_sw_mechanism1(btcoexist, true, false,
  3494. false, false);
  3495. halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
  3496. false, 0x18);
  3497. }
  3498. } else {
  3499. if (BTC_RSSI_HIGH(wifi_rssi_state)) {
  3500. halbtc8812a2ant_sw_mechanism1(btcoexist, false, false,
  3501. false, false);
  3502. halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
  3503. false, 0x18);
  3504. } else {
  3505. halbtc8812a2ant_sw_mechanism1(btcoexist, false, false,
  3506. false, false);
  3507. halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
  3508. false, 0x18);
  3509. }
  3510. }
  3511. }
  3512. /* PAN(HS) only */
  3513. void halbtc8812a2ant_action_pan_hs(IN struct btc_coexist *btcoexist)
  3514. {
  3515. u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH,
  3516. bt_rssi_state = BTC_RSSI_STATE_HIGH;
  3517. u32 wifi_bw;
  3518. wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34,
  3519. 0);
  3520. bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42);
  3521. /* power save state */
  3522. halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
  3523. 0x0);
  3524. /* coex table */
  3525. halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  3526. /* pstdma */
  3527. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1);
  3528. /* decrease BT power */
  3529. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  3530. /*
  3531. if(BTC_RSSI_LOW(bt_rssi_state))
  3532. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  3533. else if(BTC_RSSI_MEDIUM(bt_rssi_state))
  3534. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
  3535. else
  3536. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4);
  3537. */
  3538. /* limited Rx */
  3539. halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
  3540. /* fw dac swing level */
  3541. halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  3542. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  3543. if (BTC_WIFI_BW_HT40 == wifi_bw) {
  3544. if (BTC_RSSI_HIGH(wifi_rssi_state)) {
  3545. halbtc8812a2ant_sw_mechanism1(btcoexist, true, false,
  3546. false, false);
  3547. halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
  3548. false, 0x18);
  3549. } else {
  3550. halbtc8812a2ant_sw_mechanism1(btcoexist, true, false,
  3551. false, false);
  3552. halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
  3553. false, 0x18);
  3554. }
  3555. } else {
  3556. if (BTC_RSSI_HIGH(wifi_rssi_state)) {
  3557. halbtc8812a2ant_sw_mechanism1(btcoexist, false, false,
  3558. false, false);
  3559. halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
  3560. false, 0x18);
  3561. } else {
  3562. halbtc8812a2ant_sw_mechanism1(btcoexist, false, false,
  3563. false, false);
  3564. halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
  3565. false, 0x18);
  3566. }
  3567. }
  3568. }
  3569. /* PAN(EDR)+A2DP */
  3570. void halbtc8812a2ant_action_pan_edr_a2dp(IN struct btc_coexist *btcoexist)
  3571. {
  3572. u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH,
  3573. bt_rssi_state = BTC_RSSI_STATE_HIGH;
  3574. u32 wifi_bw;
  3575. u8 bt_thresh0 = 0, bt_thresh1 = 0;
  3576. halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0,
  3577. &bt_thresh1);
  3578. bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0,
  3579. bt_thresh1);
  3580. wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34,
  3581. 0);
  3582. /* bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); */
  3583. /* power save state */
  3584. if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
  3585. halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  3586. 0x0, 0x0);
  3587. else
  3588. halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50,
  3589. 0x4);
  3590. /* coex table */
  3591. if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
  3592. halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  3593. else
  3594. halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  3595. /* pstdma */
  3596. if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
  3597. halbtc8812a2ant_tdma_duration_adjust(btcoexist, false, false,
  3598. 3);
  3599. else {
  3600. coex_dm->auto_tdma_adjust = false;
  3601. coex_dm->auto_tdma_adjust_low_rssi = false;
  3602. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 86);
  3603. }
  3604. /* decrease BT power */
  3605. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  3606. /* limited Rx */
  3607. halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
  3608. /* fw dac swing level */
  3609. halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  3610. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  3611. /* sw mechanism */
  3612. if (BTC_WIFI_BW_HT40 == wifi_bw) {
  3613. if (BTC_RSSI_HIGH(wifi_rssi_state)) {
  3614. halbtc8812a2ant_sw_mechanism1(btcoexist, true, false,
  3615. false, false);
  3616. halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
  3617. false, 0x18);
  3618. } else {
  3619. halbtc8812a2ant_sw_mechanism1(btcoexist, true, false,
  3620. false, false);
  3621. halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
  3622. false, 0x18);
  3623. }
  3624. } else {
  3625. if (BTC_RSSI_HIGH(wifi_rssi_state)) {
  3626. halbtc8812a2ant_sw_mechanism1(btcoexist, false, false,
  3627. false, false);
  3628. halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
  3629. false, 0x18);
  3630. } else {
  3631. halbtc8812a2ant_sw_mechanism1(btcoexist, false, false,
  3632. false, false);
  3633. halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
  3634. false, 0x18);
  3635. }
  3636. }
  3637. }
  3638. void halbtc8812a2ant_action_pan_edr_hid(IN struct btc_coexist *btcoexist)
  3639. {
  3640. u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH,
  3641. bt_rssi_state = BTC_RSSI_STATE_HIGH;
  3642. u32 wifi_bw;
  3643. u8 bt_thresh0 = 0, bt_thresh1 = 0;
  3644. halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0,
  3645. &bt_thresh1);
  3646. bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0,
  3647. bt_thresh1);
  3648. wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34,
  3649. 0);
  3650. /* bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); */
  3651. /* power save state */
  3652. if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
  3653. halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  3654. 0x0, 0x0);
  3655. else if (BTC_RSSI_LOW(wifi_rssi_state) &&
  3656. (!BTC_RSSI_LOW(bt_rssi_state)))
  3657. halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  3658. 0x0, 0x0);
  3659. else
  3660. halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50,
  3661. 0x4);
  3662. /* coex table */
  3663. if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
  3664. halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3);
  3665. else if (BTC_RSSI_LOW(wifi_rssi_state) &&
  3666. (!BTC_RSSI_LOW(bt_rssi_state)))
  3667. halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
  3668. else
  3669. halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  3670. /* pstdma */
  3671. if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
  3672. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 10);
  3673. else if (BTC_RSSI_LOW(wifi_rssi_state) &&
  3674. (!BTC_RSSI_LOW(bt_rssi_state)))
  3675. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14);
  3676. else
  3677. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 85);
  3678. /* decrease BT power */
  3679. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  3680. /*
  3681. if(BTC_RSSI_LOW(bt_rssi_state))
  3682. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  3683. else if(BTC_RSSI_MEDIUM(bt_rssi_state))
  3684. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
  3685. else
  3686. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4);
  3687. */
  3688. /* limited Rx */
  3689. if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
  3690. halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
  3691. 0x8);
  3692. else if (BTC_RSSI_LOW(wifi_rssi_state) &&
  3693. (!BTC_RSSI_LOW(bt_rssi_state)))
  3694. halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
  3695. 0x8);
  3696. else
  3697. halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, true,
  3698. 0x8);
  3699. /* fw dac swing level */
  3700. halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  3701. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  3702. /* sw mechanism */
  3703. if (BTC_WIFI_BW_HT40 == wifi_bw) {
  3704. if (BTC_RSSI_HIGH(wifi_rssi_state)) {
  3705. halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
  3706. false, false);
  3707. halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
  3708. false, 0x18);
  3709. } else {
  3710. halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
  3711. false, false);
  3712. halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
  3713. false, 0x18);
  3714. }
  3715. } else {
  3716. if (BTC_RSSI_HIGH(wifi_rssi_state)) {
  3717. halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
  3718. false, false);
  3719. halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
  3720. false, 0x18);
  3721. } else {
  3722. halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
  3723. false, false);
  3724. halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
  3725. false, 0x18);
  3726. }
  3727. }
  3728. }
  3729. /* HID+A2DP+PAN(EDR) */
  3730. void halbtc8812a2ant_action_hid_a2dp_pan_edr(IN struct btc_coexist *btcoexist)
  3731. {
  3732. u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH,
  3733. bt_rssi_state = BTC_RSSI_STATE_HIGH;
  3734. u32 wifi_bw;
  3735. u8 bt_thresh0 = 0, bt_thresh1 = 0;
  3736. halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0,
  3737. &bt_thresh1);
  3738. bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0,
  3739. bt_thresh1);
  3740. wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34,
  3741. 0);
  3742. /* bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); */
  3743. /* power save state */
  3744. if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
  3745. halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  3746. 0x0, 0x0);
  3747. else if (BTC_RSSI_LOW(wifi_rssi_state) &&
  3748. (!BTC_RSSI_LOW(bt_rssi_state)))
  3749. halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
  3750. 0x0, 0x0);
  3751. else
  3752. halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50,
  3753. 0x4);
  3754. /* coex table */
  3755. if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
  3756. halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3);
  3757. else if (BTC_RSSI_LOW(wifi_rssi_state) &&
  3758. (!BTC_RSSI_LOW(bt_rssi_state)))
  3759. halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
  3760. else
  3761. halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  3762. /* pstdma */
  3763. if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
  3764. halbtc8812a2ant_tdma_duration_adjust(btcoexist, true, false, 3);
  3765. else if (BTC_RSSI_LOW(wifi_rssi_state) &&
  3766. (!BTC_RSSI_LOW(bt_rssi_state)))
  3767. halbtc8812a2ant_tdma_duration_adjust(btcoexist, true, true, 3);
  3768. else {
  3769. coex_dm->auto_tdma_adjust = false;
  3770. halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 86);
  3771. }
  3772. /* decrease BT power */
  3773. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  3774. /*
  3775. if(BTC_RSSI_LOW(bt_rssi_state))
  3776. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  3777. else if(BTC_RSSI_MEDIUM(bt_rssi_state))
  3778. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
  3779. else
  3780. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4);
  3781. */
  3782. /* limited Rx */
  3783. if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
  3784. halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
  3785. 0x8);
  3786. else if (BTC_RSSI_LOW(wifi_rssi_state) &&
  3787. (!BTC_RSSI_LOW(bt_rssi_state)))
  3788. halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
  3789. 0x8);
  3790. else
  3791. halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, true,
  3792. 0x8);
  3793. /* fw dac swing level */
  3794. halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  3795. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  3796. /* sw mechanism */
  3797. if (BTC_WIFI_BW_HT40 == wifi_bw) {
  3798. if (BTC_RSSI_HIGH(wifi_rssi_state)) {
  3799. halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
  3800. false, false);
  3801. halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
  3802. false, 0x18);
  3803. } else {
  3804. halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
  3805. false, false);
  3806. halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
  3807. false, 0x18);
  3808. }
  3809. } else {
  3810. if (BTC_RSSI_HIGH(wifi_rssi_state)) {
  3811. halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
  3812. false, false);
  3813. halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
  3814. false, 0x18);
  3815. } else {
  3816. halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
  3817. false, false);
  3818. halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
  3819. false, 0x18);
  3820. }
  3821. }
  3822. }
  3823. void halbtc8812a2ant_action_hid_a2dp_pan_hs(IN struct btc_coexist *btcoexist)
  3824. {
  3825. u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH,
  3826. bt_rssi_state = BTC_RSSI_STATE_HIGH;
  3827. u32 wifi_bw;
  3828. u8 bt_thresh0 = 0, bt_thresh1 = 0;
  3829. halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0,
  3830. &bt_thresh1);
  3831. bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0,
  3832. bt_thresh1);
  3833. wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34,
  3834. 0);
  3835. /* bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); */
  3836. /* power save state */
  3837. halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
  3838. 0x0);
  3839. /* coex table */
  3840. if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
  3841. halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3);
  3842. else if (BTC_RSSI_LOW(wifi_rssi_state) &&
  3843. (!BTC_RSSI_LOW(bt_rssi_state)))
  3844. halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
  3845. else
  3846. halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  3847. /* pstdma */
  3848. if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
  3849. halbtc8812a2ant_tdma_duration_adjust(btcoexist, true, false, 2);
  3850. else if (BTC_RSSI_LOW(wifi_rssi_state) &&
  3851. (!BTC_RSSI_LOW(bt_rssi_state)))
  3852. halbtc8812a2ant_tdma_duration_adjust(btcoexist, true, true, 2);
  3853. else
  3854. halbtc8812a2ant_tdma_duration_adjust(btcoexist, true, true, 2);
  3855. /* decrease BT power */
  3856. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  3857. /*
  3858. if(BTC_RSSI_LOW(bt_rssi_state))
  3859. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  3860. else if(BTC_RSSI_MEDIUM(bt_rssi_state))
  3861. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
  3862. else
  3863. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4);
  3864. */
  3865. /* limited Rx */
  3866. if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))
  3867. halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
  3868. 0x8);
  3869. else if (BTC_RSSI_LOW(wifi_rssi_state) &&
  3870. (!BTC_RSSI_LOW(bt_rssi_state)))
  3871. halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false,
  3872. 0x8);
  3873. else
  3874. halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, true,
  3875. 0x8);
  3876. /* fw dac swing level */
  3877. halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  3878. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  3879. /* sw mechanism */
  3880. if (BTC_WIFI_BW_HT40 == wifi_bw) {
  3881. if (BTC_RSSI_HIGH(wifi_rssi_state)) {
  3882. halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
  3883. false, false);
  3884. halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
  3885. false, 0x18);
  3886. } else {
  3887. halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
  3888. false, false);
  3889. halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
  3890. false, 0x18);
  3891. }
  3892. } else {
  3893. if (BTC_RSSI_HIGH(wifi_rssi_state)) {
  3894. halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
  3895. false, false);
  3896. halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
  3897. false, 0x18);
  3898. } else {
  3899. halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
  3900. false, false);
  3901. halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
  3902. false, 0x18);
  3903. }
  3904. }
  3905. }
  3906. void halbtc8812a2ant_action_hid_a2dp(IN struct btc_coexist *btcoexist)
  3907. {
  3908. u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH,
  3909. bt_rssi_state = BTC_RSSI_STATE_HIGH;
  3910. u32 wifi_bw;
  3911. u8 anttype = 0;
  3912. btcoexist->btc_get(btcoexist, BTC_GET_U1_ANT_TYPE, &anttype);
  3913. /* halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0, &bt_thresh1);
  3914. * bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0, bt_thresh1); */
  3915. wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34,
  3916. 0);
  3917. bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42);
  3918. if (anttype == 0) { /* ANTTYPE = 0 92E 2ant with SPDT */
  3919. /* power save state & pstdma & coex table */
  3920. if (BTC_RSSI_HIGH(wifi_rssi_state) &&
  3921. (!BTC_RSSI_LOW(bt_rssi_state)) &&
  3922. (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8812A)) {
  3923. halbtc8812a2ant_power_save_state(btcoexist,
  3924. BTC_PS_LPS_ON, 0x50, 0x4);
  3925. halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, true,
  3926. 83);
  3927. halbtc8812a2ant_coex_table_with_type(btcoexist,
  3928. NORMAL_EXEC, 8);
  3929. } else if (BTC_RSSI_HIGH(wifi_rssi_state) &&
  3930. (!BTC_RSSI_LOW(bt_rssi_state)) &&
  3931. (coex_sta->scan_ap_num > NOISY_AP_NUM_THRESH_8812A)) {
  3932. coex_dm->auto_tdma_adjust = false;
  3933. coex_dm->auto_tdma_adjust_low_rssi = false;
  3934. halbtc8812a2ant_power_save_state(btcoexist,
  3935. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  3936. halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false,
  3937. 0);
  3938. halbtc8812a2ant_coex_table_with_type(btcoexist,
  3939. NORMAL_EXEC, 0);
  3940. } else {
  3941. halbtc8812a2ant_power_save_state(btcoexist,
  3942. BTC_PS_LPS_ON, 0x50, 0x4);
  3943. halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, true,
  3944. 83);
  3945. halbtc8812a2ant_coex_table_with_type(btcoexist,
  3946. NORMAL_EXEC, 8);
  3947. }
  3948. } else if (anttype ==
  3949. 1) { /* 92E 2ant with coupler and bad ant. isolation, 92E 3ant with bad ant. isolation */
  3950. /* power save state & pstdma & coex table */
  3951. if (BTC_RSSI_HIGH(wifi_rssi_state) &&
  3952. (!BTC_RSSI_LOW(bt_rssi_state)) &&
  3953. (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8812A)) {
  3954. halbtc8812a2ant_power_save_state(btcoexist,
  3955. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  3956. halbtc8812a2ant_tdma_duration_adjust(btcoexist, true,
  3957. true, 2);
  3958. halbtc8812a2ant_coex_table_with_type(btcoexist,
  3959. NORMAL_EXEC, 8);
  3960. } else if (BTC_RSSI_HIGH(wifi_rssi_state) &&
  3961. (!BTC_RSSI_LOW(bt_rssi_state)) &&
  3962. (coex_sta->scan_ap_num > NOISY_AP_NUM_THRESH_8812A)) {
  3963. coex_dm->auto_tdma_adjust = false;
  3964. coex_dm->auto_tdma_adjust_low_rssi = false;
  3965. halbtc8812a2ant_power_save_state(btcoexist,
  3966. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  3967. halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false,
  3968. 0);
  3969. halbtc8812a2ant_coex_table_with_type(btcoexist,
  3970. NORMAL_EXEC, 0);
  3971. } else {
  3972. halbtc8812a2ant_power_save_state(btcoexist,
  3973. BTC_PS_LPS_ON, 0x50, 0x4);
  3974. halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, true,
  3975. 83);
  3976. halbtc8812a2ant_coex_table_with_type(btcoexist,
  3977. NORMAL_EXEC, 8);
  3978. }
  3979. } else if (anttype ==
  3980. 2) { /* ANTTYPE = 2, 92E 2ant with coupler and normal/good ant. isolation, 92E 3ant with normal ant. isolation */
  3981. /* power save state & pstdma & coex table */
  3982. if (BTC_RSSI_HIGH(wifi_rssi_state) &&
  3983. (!BTC_RSSI_LOW(bt_rssi_state)) &&
  3984. (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8812A)) {
  3985. /* WIFI RSSI = high & BT RSSI = high & shielding room */
  3986. halbtc8812a2ant_power_save_state(btcoexist,
  3987. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  3988. halbtc8812a2ant_tdma_duration_adjust(btcoexist, true,
  3989. true, 2);
  3990. halbtc8812a2ant_coex_table_with_type(btcoexist,
  3991. NORMAL_EXEC, 8);
  3992. } else if (BTC_RSSI_HIGH(wifi_rssi_state) &&
  3993. (!BTC_RSSI_LOW(bt_rssi_state)) &&
  3994. (coex_sta->scan_ap_num > NOISY_AP_NUM_THRESH_8812A)) {
  3995. /* WIFI RSSI = high & BT RSSI = high & noisy environment */
  3996. coex_dm->auto_tdma_adjust = false;
  3997. coex_dm->auto_tdma_adjust_low_rssi = false;
  3998. halbtc8812a2ant_power_save_state(btcoexist,
  3999. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  4000. halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false,
  4001. 0);
  4002. halbtc8812a2ant_coex_table_with_type(btcoexist,
  4003. NORMAL_EXEC, 8);
  4004. } else { /* WIFI RSSI || BT RSSI == low */
  4005. halbtc8812a2ant_power_save_state(btcoexist,
  4006. BTC_PS_LPS_ON, 0x50, 0x4);
  4007. halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, true,
  4008. 83);
  4009. halbtc8812a2ant_coex_table_with_type(btcoexist,
  4010. NORMAL_EXEC, 8);
  4011. }
  4012. } else if (anttype ==
  4013. 3) { /* ANTTYPE = 3, 92E 3ant with good ant. isolation */
  4014. /* power save state & pstdma & coex table */
  4015. if (BTC_RSSI_HIGH(wifi_rssi_state) &&
  4016. (!BTC_RSSI_LOW(bt_rssi_state)) &&
  4017. (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8812A)) {
  4018. /* WIFI RSSI = high & BT RSSI = high & shielding room */
  4019. coex_dm->auto_tdma_adjust = false;
  4020. coex_dm->auto_tdma_adjust_low_rssi = false;
  4021. halbtc8812a2ant_power_save_state(btcoexist,
  4022. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  4023. halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false,
  4024. 1);
  4025. halbtc8812a2ant_coex_table_with_type(btcoexist,
  4026. NORMAL_EXEC, 0);
  4027. } else if (BTC_RSSI_HIGH(wifi_rssi_state) &&
  4028. (!BTC_RSSI_LOW(bt_rssi_state)) &&
  4029. (coex_sta->scan_ap_num > NOISY_AP_NUM_THRESH_8812A)) {
  4030. /* WIFI RSSI = high & BT RSSI = high & noisy environment */
  4031. coex_dm->auto_tdma_adjust = false;
  4032. coex_dm->auto_tdma_adjust_low_rssi = false;
  4033. halbtc8812a2ant_power_save_state(btcoexist,
  4034. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  4035. halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false,
  4036. 1);
  4037. halbtc8812a2ant_coex_table_with_type(btcoexist,
  4038. NORMAL_EXEC, 0);
  4039. } else { /* WIFI RSSI || BT RSSI == low */
  4040. coex_dm->auto_tdma_adjust = false;
  4041. coex_dm->auto_tdma_adjust_low_rssi = false;
  4042. halbtc8812a2ant_power_save_state(btcoexist,
  4043. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  4044. halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false,
  4045. 1);
  4046. halbtc8812a2ant_coex_table_with_type(btcoexist,
  4047. NORMAL_EXEC, 0);
  4048. }
  4049. } else { /* ANTTYPE = 4 for test */
  4050. /* power save state & pstdma & coex table */
  4051. if (BTC_RSSI_HIGH(wifi_rssi_state) &&
  4052. (!BTC_RSSI_LOW(bt_rssi_state)) &&
  4053. (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8812A)) {
  4054. /* WIFI RSSI = high & BT RSSI = high & shielding room */
  4055. halbtc8812a2ant_power_save_state(btcoexist,
  4056. BTC_PS_LPS_ON, 0x50, 0x4);
  4057. halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low(
  4058. btcoexist);
  4059. halbtc8812a2ant_coex_table_with_type(btcoexist,
  4060. NORMAL_EXEC, 7);
  4061. } else if (BTC_RSSI_HIGH(wifi_rssi_state) &&
  4062. (!BTC_RSSI_LOW(bt_rssi_state)) &&
  4063. (coex_sta->scan_ap_num > NOISY_AP_NUM_THRESH_8812A)) {
  4064. /* WIFI RSSI = high & BT RSSI = high & noisy environment */
  4065. halbtc8812a2ant_power_save_state(btcoexist,
  4066. BTC_PS_LPS_ON, 0x50, 0x4);
  4067. halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low(
  4068. btcoexist);
  4069. halbtc8812a2ant_coex_table_with_type(btcoexist,
  4070. NORMAL_EXEC, 7);
  4071. } else { /* WIFI RSSI || BT RSSI == low */
  4072. halbtc8812a2ant_power_save_state(btcoexist,
  4073. BTC_PS_LPS_ON, 0x50, 0x4);
  4074. halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low(
  4075. btcoexist);
  4076. halbtc8812a2ant_coex_table_with_type(btcoexist,
  4077. NORMAL_EXEC, 7);
  4078. }
  4079. }
  4080. /* decrease BT power */
  4081. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  4082. /*
  4083. if(BTC_RSSI_LOW(bt_rssi_state))
  4084. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0);
  4085. else if(BTC_RSSI_MEDIUM(bt_rssi_state))
  4086. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2);
  4087. else if (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8812A)
  4088. halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4);
  4089. */
  4090. /* limited Rx */
  4091. halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8);
  4092. /* fw dac swing level */
  4093. halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6);
  4094. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  4095. /* sw mechanism */
  4096. if (BTC_WIFI_BW_HT40 == wifi_bw) {
  4097. if (BTC_RSSI_HIGH(wifi_rssi_state)) {
  4098. halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
  4099. false, false);
  4100. halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
  4101. false, 0x18);
  4102. } else {
  4103. halbtc8812a2ant_sw_mechanism1(btcoexist, true, true,
  4104. false, false);
  4105. halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
  4106. false, 0x18);
  4107. }
  4108. } else {
  4109. if (BTC_RSSI_HIGH(wifi_rssi_state)) {
  4110. halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
  4111. false, false);
  4112. halbtc8812a2ant_sw_mechanism2(btcoexist, true, false,
  4113. false, 0x18);
  4114. } else {
  4115. halbtc8812a2ant_sw_mechanism1(btcoexist, false, true,
  4116. false, false);
  4117. halbtc8812a2ant_sw_mechanism2(btcoexist, false, false,
  4118. false, 0x18);
  4119. }
  4120. }
  4121. }
  4122. void halbtc8812a2ant_coex_under_5g(IN struct btc_coexist *btcoexist)
  4123. {
  4124. halbtc8812a2ant_coex_all_off(btcoexist);
  4125. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4126. "[BTCoex], Under 5G, force set BT to ignore Wlan active!!\n");
  4127. BTC_TRACE(trace_buf);
  4128. halbtc8812a2ant_ignore_wlan_act(btcoexist, NORMAL_EXEC, true);
  4129. }
  4130. /* **************************************************** */
  4131. void halbtc8812a2ant_run_coexist_mechanism(IN struct btc_coexist *btcoexist)
  4132. {
  4133. boolean wifi_under_5g = false;
  4134. u8 algorithm = 0;
  4135. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4136. "[BTCoex], RunCoexistMechanism()===>\n");
  4137. BTC_TRACE(trace_buf);
  4138. if (btcoexist->manual_control) {
  4139. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4140. "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
  4141. BTC_TRACE(trace_buf);
  4142. return;
  4143. }
  4144. if (coex_sta->under_ips) {
  4145. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4146. "[BTCoex], wifi is under IPS !!!\n");
  4147. BTC_TRACE(trace_buf);
  4148. return;
  4149. }
  4150. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  4151. if (wifi_under_5g) {
  4152. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4153. "[BTCoex], RunCoexistMechanism(), run 5G coex setting!!<===\n");
  4154. BTC_TRACE(trace_buf);
  4155. halbtc8812a2ant_coex_under_5g(btcoexist);
  4156. return;
  4157. }
  4158. algorithm = halbtc8812a2ant_action_algorithm(btcoexist);
  4159. if (coex_sta->c2h_bt_inquiry_page &&
  4160. (BT_8812A_2ANT_COEX_ALGO_PANHS != algorithm)) {
  4161. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4162. "[BTCoex], BT is under inquiry/page scan !!\n");
  4163. BTC_TRACE(trace_buf);
  4164. halbtc8812a2ant_action_bt_inquiry(btcoexist);
  4165. return;
  4166. }
  4167. coex_dm->cur_algorithm = algorithm;
  4168. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Algorithm = %d\n",
  4169. coex_dm->cur_algorithm);
  4170. BTC_TRACE(trace_buf);
  4171. if (halbtc8812a2ant_is_common_action(btcoexist)) {
  4172. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4173. "[BTCoex], Action 2-Ant common.\n");
  4174. BTC_TRACE(trace_buf);
  4175. coex_dm->auto_tdma_adjust = false;
  4176. coex_dm->auto_tdma_adjust_low_rssi = false;
  4177. } else {
  4178. if (coex_dm->cur_algorithm != coex_dm->pre_algorithm) {
  4179. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4180. "[BTCoex], pre_algorithm=%d, cur_algorithm=%d\n",
  4181. coex_dm->pre_algorithm, coex_dm->cur_algorithm);
  4182. BTC_TRACE(trace_buf);
  4183. coex_dm->auto_tdma_adjust = false;
  4184. coex_dm->auto_tdma_adjust_low_rssi = false;
  4185. }
  4186. switch (coex_dm->cur_algorithm) {
  4187. case BT_8812A_2ANT_COEX_ALGO_SCO:
  4188. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4189. "[BTCoex], Action 2-Ant, algorithm = SCO.\n");
  4190. BTC_TRACE(trace_buf);
  4191. halbtc8812a2ant_action_sco(btcoexist);
  4192. break;
  4193. case BT_8812A_2ANT_COEX_ALGO_SCO_HID:
  4194. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4195. "[BTCoex], Action 2-Ant, algorithm = SCO+HID.\n");
  4196. BTC_TRACE(trace_buf);
  4197. halbtc8812a2ant_action_sco_hid(btcoexist);
  4198. break;
  4199. case BT_8812A_2ANT_COEX_ALGO_HID:
  4200. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4201. "[BTCoex], Action 2-Ant, algorithm = HID.\n");
  4202. BTC_TRACE(trace_buf);
  4203. halbtc8812a2ant_action_hid(btcoexist);
  4204. break;
  4205. case BT_8812A_2ANT_COEX_ALGO_A2DP:
  4206. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4207. "[BTCoex], Action 2-Ant, algorithm = A2DP.\n");
  4208. BTC_TRACE(trace_buf);
  4209. halbtc8812a2ant_action_a2dp(btcoexist);
  4210. break;
  4211. case BT_8812A_2ANT_COEX_ALGO_A2DP_PANHS:
  4212. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4213. "[BTCoex], Action 2-Ant, algorithm = A2DP+PAN(HS).\n");
  4214. BTC_TRACE(trace_buf);
  4215. halbtc8812a2ant_action_a2dp_pan_hs(btcoexist);
  4216. break;
  4217. case BT_8812A_2ANT_COEX_ALGO_PANEDR:
  4218. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4219. "[BTCoex], Action 2-Ant, algorithm = PAN(EDR).\n");
  4220. BTC_TRACE(trace_buf);
  4221. halbtc8812a2ant_action_pan_edr(btcoexist);
  4222. break;
  4223. case BT_8812A_2ANT_COEX_ALGO_PANHS:
  4224. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4225. "[BTCoex], Action 2-Ant, algorithm = HS mode.\n");
  4226. BTC_TRACE(trace_buf);
  4227. halbtc8812a2ant_action_pan_hs(btcoexist);
  4228. break;
  4229. case BT_8812A_2ANT_COEX_ALGO_PANEDR_A2DP:
  4230. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4231. "[BTCoex], Action 2-Ant, algorithm = PAN+A2DP.\n");
  4232. BTC_TRACE(trace_buf);
  4233. halbtc8812a2ant_action_pan_edr_a2dp(btcoexist);
  4234. break;
  4235. case BT_8812A_2ANT_COEX_ALGO_PANEDR_HID:
  4236. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4237. "[BTCoex], Action 2-Ant, algorithm = PAN(EDR)+HID.\n");
  4238. BTC_TRACE(trace_buf);
  4239. halbtc8812a2ant_action_pan_edr_hid(btcoexist);
  4240. break;
  4241. case BT_8812A_2ANT_COEX_ALGO_HID_A2DP_PANEDR:
  4242. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4243. "[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN.\n");
  4244. BTC_TRACE(trace_buf);
  4245. halbtc8812a2ant_action_hid_a2dp_pan_edr(
  4246. btcoexist);
  4247. break;
  4248. case BT_8812A_2ANT_COEX_ALGO_HID_A2DP_PANHS:
  4249. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4250. "[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN(HS).\n");
  4251. BTC_TRACE(trace_buf);
  4252. halbtc8812a2ant_action_hid_a2dp_pan_hs(
  4253. btcoexist);
  4254. break;
  4255. case BT_8812A_2ANT_COEX_ALGO_HID_A2DP:
  4256. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4257. "[BTCoex], Action 2-Ant, algorithm = HID+A2DP.\n");
  4258. BTC_TRACE(trace_buf);
  4259. halbtc8812a2ant_action_hid_a2dp(btcoexist);
  4260. break;
  4261. default:
  4262. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4263. "[BTCoex], Action 2-Ant, algorithm = coexist All Off!!\n");
  4264. BTC_TRACE(trace_buf);
  4265. halbtc8812a2ant_coex_all_off(btcoexist);
  4266. break;
  4267. }
  4268. coex_dm->pre_algorithm = coex_dm->cur_algorithm;
  4269. }
  4270. }
  4271. void halbtc8812a2ant_init_hw_config(IN struct btc_coexist *btcoexist,
  4272. IN boolean back_up)
  4273. {
  4274. u8 u8tmp = 0;
  4275. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4276. "[BTCoex], 2Ant Init HW Config!!\n");
  4277. BTC_TRACE(trace_buf);
  4278. if (back_up) {
  4279. /* backup rf 0x1e value */
  4280. coex_dm->bt_rf_0x1e_backup =
  4281. btcoexist->btc_get_rf_reg(btcoexist, BTC_RF_A, 0x1e,
  4282. 0xfffff);
  4283. coex_dm->backup_arfr_cnt1 = btcoexist->btc_read_4byte(btcoexist,
  4284. 0x430);
  4285. coex_dm->backup_arfr_cnt2 = btcoexist->btc_read_4byte(btcoexist,
  4286. 0x434);
  4287. coex_dm->backup_retry_limit = btcoexist->btc_read_2byte(
  4288. btcoexist, 0x42a);
  4289. coex_dm->backup_ampdu_max_time = btcoexist->btc_read_1byte(
  4290. btcoexist, 0x456);
  4291. }
  4292. /* ant sw control to BT */
  4293. halbtc8812a2ant_set_ant_path(btcoexist, BTC_ANT_WIFI_AT_CPL_AUX, true,
  4294. false);
  4295. /* 0x790[5:0]=0x5 */
  4296. u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x790);
  4297. u8tmp &= 0xc0;
  4298. u8tmp |= 0x5;
  4299. btcoexist->btc_write_1byte(btcoexist, 0x790, u8tmp);
  4300. /* PTA parameter */
  4301. btcoexist->btc_write_1byte(btcoexist, 0x6cc, 0x0);
  4302. btcoexist->btc_write_4byte(btcoexist, 0x6c8, 0xffff);
  4303. btcoexist->btc_write_4byte(btcoexist, 0x6c4, 0x55555555);
  4304. btcoexist->btc_write_4byte(btcoexist, 0x6c0, 0x55555555);
  4305. /* coex parameters */
  4306. btcoexist->btc_write_1byte(btcoexist, 0x778, 0x1);
  4307. /* enable counter statistics */
  4308. btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4);
  4309. /* disable PTA to avoid BT insn't on */
  4310. btcoexist->btc_write_1byte(btcoexist, 0x40, 0x00);
  4311. /* bt clock related */
  4312. u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x4);
  4313. u8tmp |= BIT(7);
  4314. btcoexist->btc_write_1byte(btcoexist, 0x4, u8tmp);
  4315. /* bt clock related */
  4316. u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x7);
  4317. u8tmp |= BIT(1);
  4318. btcoexist->btc_write_1byte(btcoexist, 0x7, u8tmp);
  4319. /* Give bt_coex_supported_version the default value */
  4320. coex_sta->bt_coex_supported_version = 0;
  4321. }
  4322. /* ************************************************************
  4323. * work around function start with wa_halbtc8812a2ant_
  4324. * ************************************************************
  4325. * ************************************************************
  4326. * extern function start with ex_halbtc8812a2ant_
  4327. * ************************************************************ */
  4328. void ex_halbtc8812a2ant_power_on_setting(IN struct btc_coexist *btcoexist)
  4329. {
  4330. }
  4331. void ex_halbtc8812a2ant_init_hw_config(IN struct btc_coexist *btcoexist,
  4332. IN boolean wifi_only)
  4333. {
  4334. halbtc8812a2ant_init_hw_config(btcoexist, true);
  4335. }
  4336. void ex_halbtc8812a2ant_init_coex_dm(IN struct btc_coexist *btcoexist)
  4337. {
  4338. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4339. "[BTCoex], Coex Mechanism Init!!\n");
  4340. BTC_TRACE(trace_buf);
  4341. halbtc8812a2ant_init_coex_dm(btcoexist);
  4342. }
  4343. void ex_halbtc8812a2ant_pta_off_on_notify(IN struct btc_coexist *btcoexist,
  4344. IN u8 bt_status)
  4345. {
  4346. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], BToff/on notify\n");
  4347. BTC_TRACE(trace_buf);
  4348. if (BTC_BT_OFF == bt_status) {
  4349. /* PTA off */
  4350. btcoexist->bt_info.bt_disabled = true;
  4351. halbtc8812a2ant_enable_pta(btcoexist, FORCE_EXEC, false);
  4352. } else {
  4353. /* PTA on */
  4354. btcoexist->bt_info.bt_disabled = false;
  4355. halbtc8812a2ant_enable_pta(btcoexist, FORCE_EXEC, true);
  4356. }
  4357. }
  4358. void ex_halbtc8812a2ant_display_coex_info(IN struct btc_coexist *btcoexist)
  4359. {
  4360. struct btc_board_info *board_info = &btcoexist->board_info;
  4361. struct btc_stack_info *stack_info = &btcoexist->stack_info;
  4362. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  4363. u8 *cli_buf = btcoexist->cli_buf;
  4364. u8 u8tmp[4], i, bt_info_ext, ps_tdma_case = 0;
  4365. u16 u16tmp[4];
  4366. u32 u32tmp[4];
  4367. u32 fa_ofdm, fa_cck, cca_ofdm, cca_cck;
  4368. u32 fw_ver = 0, bt_patch_ver = 0, bt_coex_ver = 0;
  4369. u32 phyver = 0;
  4370. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4371. "\r\n ============[BT Coexist info]============");
  4372. CL_PRINTF(cli_buf);
  4373. if (btcoexist->manual_control) {
  4374. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4375. "\r\n ============[Under Manual Control]============");
  4376. CL_PRINTF(cli_buf);
  4377. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4378. "\r\n ==========================================");
  4379. CL_PRINTF(cli_buf);
  4380. }
  4381. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ",
  4382. "Ant PG number/ Ant mechanism:",
  4383. board_info->pg_ant_num, board_info->btdm_ant_num);
  4384. CL_PRINTF(cli_buf);
  4385. #if 0
  4386. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "Antenna type:",
  4387. board_info->ant_type);
  4388. CL_PRINTF(cli_buf);
  4389. #endif
  4390. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d",
  4391. "BT stack/ hci ext ver",
  4392. ((stack_info->profile_notified) ? "Yes" : "No"),
  4393. stack_info->hci_version);
  4394. CL_PRINTF(cli_buf);
  4395. bt_patch_ver = btcoexist->bt_info.bt_get_fw_ver;
  4396. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
  4397. phyver = btcoexist->btc_get_bt_phydm_version(btcoexist);
  4398. bt_coex_ver = coex_sta->bt_coex_supported_version & 0xff;
  4399. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4400. "\r\n %-35s = %d_%02x/ 0x%02x/ 0x%02x (%s)",
  4401. "CoexVer WL/ BT_Desired/ BT_Report",
  4402. glcoex_ver_date_8812a_2ant, glcoex_ver_8812a_2ant,
  4403. glcoex_ver_btdesired_8812a_2ant, bt_coex_ver,
  4404. (bt_coex_ver == 0xff ? "Unknown" : (bt_coex_ver >=
  4405. glcoex_ver_btdesired_8812a_2ant ? "Match" :
  4406. "Mis-Match")));
  4407. CL_PRINTF(cli_buf);
  4408. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4409. "\r\n %-35s = 0x%x/ 0x%x/ v%d",
  4410. "W_FW/ B_FW/ Phy",
  4411. fw_ver, bt_patch_ver, phyver);
  4412. CL_PRINTF(cli_buf);
  4413. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ",
  4414. "Wifi channel informed to BT",
  4415. coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1],
  4416. coex_dm->wifi_chnl_info[2]);
  4417. CL_PRINTF(cli_buf);
  4418. /* wifi status */
  4419. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  4420. "============[Wifi Status]============");
  4421. CL_PRINTF(cli_buf);
  4422. btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS);
  4423. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  4424. "============[BT Status]============");
  4425. CL_PRINTF(cli_buf);
  4426. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d] ",
  4427. "BT [status/ rssi/ retryCnt]",
  4428. ((btcoexist->bt_info.bt_disabled) ? ("disabled") : ((
  4429. coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan")
  4430. : ((BT_8812A_2ANT_BT_STATUS_NON_CONNECTED_IDLE ==
  4431. coex_dm->bt_status) ? "non-connected idle" :
  4432. ((BT_8812A_2ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)
  4433. ? "connected-idle" : "busy")))),
  4434. coex_sta->bt_rssi, coex_sta->bt_retry_cnt);
  4435. CL_PRINTF(cli_buf);
  4436. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d",
  4437. "SCO/HID/PAN/A2DP",
  4438. bt_link_info->sco_exist, bt_link_info->hid_exist,
  4439. bt_link_info->pan_exist, bt_link_info->a2dp_exist);
  4440. CL_PRINTF(cli_buf);
  4441. btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_BT_LINK_INFO);
  4442. bt_info_ext = coex_sta->bt_info_ext;
  4443. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s",
  4444. "BT Info A2DP rate",
  4445. (bt_info_ext & BIT(0)) ? "Basic rate" : "EDR rate");
  4446. CL_PRINTF(cli_buf);
  4447. for (i = 0; i < BT_INFO_SRC_8812A_2ANT_MAX; i++) {
  4448. if (coex_sta->bt_info_c2h_cnt[i]) {
  4449. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4450. "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)",
  4451. glbt_info_src_8812a_2ant[i],
  4452. coex_sta->bt_info_c2h[i][0],
  4453. coex_sta->bt_info_c2h[i][1],
  4454. coex_sta->bt_info_c2h[i][2],
  4455. coex_sta->bt_info_c2h[i][3],
  4456. coex_sta->bt_info_c2h[i][4],
  4457. coex_sta->bt_info_c2h[i][5],
  4458. coex_sta->bt_info_c2h[i][6],
  4459. coex_sta->bt_info_c2h_cnt[i]);
  4460. CL_PRINTF(cli_buf);
  4461. }
  4462. }
  4463. /* Sw mechanism */
  4464. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  4465. "============[Sw mechanism]============");
  4466. CL_PRINTF(cli_buf);
  4467. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d ",
  4468. "SM1[ShRf/ LpRA/ LimDig]",
  4469. coex_dm->cur_rf_rx_lpf_shrink, coex_dm->cur_low_penalty_ra,
  4470. coex_dm->limited_dig);
  4471. CL_PRINTF(cli_buf);
  4472. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d(0x%x) ",
  4473. "SM2[AgcT/ AdcB/ SwDacSwing(lvl)]",
  4474. coex_dm->cur_agc_table_en, coex_dm->cur_adc_back_off,
  4475. coex_dm->cur_dac_swing_on, coex_dm->cur_dac_swing_lvl);
  4476. CL_PRINTF(cli_buf);
  4477. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ", "Rate Mask",
  4478. btcoexist->bt_info.ra_mask);
  4479. CL_PRINTF(cli_buf);
  4480. /* Fw mechanism */
  4481. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  4482. "============[Fw mechanism]============");
  4483. CL_PRINTF(cli_buf);
  4484. ps_tdma_case = coex_dm->cur_ps_tdma;
  4485. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4486. "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (auto:%d/%d)",
  4487. "PS TDMA",
  4488. coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1],
  4489. coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3],
  4490. coex_dm->ps_tdma_para[4], ps_tdma_case,
  4491. coex_dm->auto_tdma_adjust,
  4492. coex_dm->auto_tdma_adjust_low_rssi);
  4493. CL_PRINTF(cli_buf);
  4494. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ",
  4495. "DecBtPwr/ IgnWlanAct",
  4496. coex_dm->cur_bt_dec_pwr_lvl, coex_dm->cur_ignore_wlan_act);
  4497. CL_PRINTF(cli_buf);
  4498. /* Hw setting */
  4499. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  4500. "============[Hw setting]============");
  4501. CL_PRINTF(cli_buf);
  4502. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x",
  4503. "RF-A, 0x1e initVal",
  4504. coex_dm->bt_rf_0x1e_backup);
  4505. CL_PRINTF(cli_buf);
  4506. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
  4507. "backup ARFR1/ARFR2/RL/AMaxTime",
  4508. coex_dm->backup_arfr_cnt1, coex_dm->backup_arfr_cnt2,
  4509. coex_dm->backup_retry_limit,
  4510. coex_dm->backup_ampdu_max_time);
  4511. CL_PRINTF(cli_buf);
  4512. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x430);
  4513. u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x434);
  4514. u16tmp[0] = btcoexist->btc_read_2byte(btcoexist, 0x42a);
  4515. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x456);
  4516. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
  4517. "0x430/0x434/0x42a/0x456",
  4518. u32tmp[0], u32tmp[1], u16tmp[0], u8tmp[0]);
  4519. CL_PRINTF(cli_buf);
  4520. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
  4521. u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x6cc);
  4522. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x ",
  4523. "0x778 (W_Act)/ 0x6cc (CoTab Sel)",
  4524. u8tmp[0], u8tmp[1]);
  4525. CL_PRINTF(cli_buf);
  4526. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x8db);
  4527. u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xc5b);
  4528. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
  4529. "0x8db(ADC)/0xc5b[29:25](DAC)",
  4530. ((u8tmp[0] & 0x60) >> 5), ((u8tmp[1] & 0x3e) >> 1));
  4531. CL_PRINTF(cli_buf);
  4532. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xcb3);
  4533. u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xcb7);
  4534. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
  4535. "0xcb3/ 0xcb7",
  4536. u8tmp[0], u8tmp[1]);
  4537. CL_PRINTF(cli_buf);
  4538. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x40);
  4539. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c);
  4540. u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x974);
  4541. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
  4542. "0x40/ 0x4c[24:23]/ 0x974",
  4543. u8tmp[0], ((u32tmp[0] & 0x01800000) >> 23), u32tmp[1]);
  4544. CL_PRINTF(cli_buf);
  4545. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
  4546. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
  4547. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
  4548. "0x550(bcn ctrl)/0x522",
  4549. u32tmp[0], u8tmp[0]);
  4550. CL_PRINTF(cli_buf);
  4551. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50);
  4552. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xa0a);
  4553. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
  4554. "0xc50(DIG)/0xa0a(CCK-TH)",
  4555. u32tmp[0], u8tmp[0]);
  4556. CL_PRINTF(cli_buf);
  4557. fa_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
  4558. PHYDM_INFO_FA_OFDM);
  4559. fa_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
  4560. PHYDM_INFO_FA_CCK);
  4561. cca_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
  4562. PHYDM_INFO_CCA_OFDM);
  4563. cca_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
  4564. PHYDM_INFO_CCA_CCK);
  4565. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4566. "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
  4567. "CCK-CCA/CCK-FA/OFDM-CCA/OFDM-FA",
  4568. cca_cck, fa_cck, cca_ofdm, fa_ofdm);
  4569. CL_PRINTF(cli_buf);
  4570. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
  4571. "CRC_OK CCK/11g/11n/11n-agg",
  4572. coex_sta->crc_ok_cck, coex_sta->crc_ok_11g,
  4573. coex_sta->crc_ok_11n, coex_sta->crc_ok_11n_vht);
  4574. CL_PRINTF(cli_buf);
  4575. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
  4576. "CRC_Err CCK/11g/11n/11n-agg",
  4577. coex_sta->crc_err_cck, coex_sta->crc_err_11g,
  4578. coex_sta->crc_err_11n, coex_sta->crc_err_11n_vht);
  4579. CL_PRINTF(cli_buf);
  4580. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
  4581. u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
  4582. u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
  4583. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x6cc);
  4584. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  4585. "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
  4586. "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)",
  4587. u32tmp[0], u32tmp[1], u32tmp[2], u8tmp[0]);
  4588. CL_PRINTF(cli_buf);
  4589. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
  4590. "0x770(high-pri rx/tx)",
  4591. coex_sta->high_priority_rx, coex_sta->high_priority_tx);
  4592. CL_PRINTF(cli_buf);
  4593. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
  4594. "0x774(low-pri rx/tx)",
  4595. coex_sta->low_priority_rx, coex_sta->low_priority_tx);
  4596. CL_PRINTF(cli_buf);
  4597. #if (BT_AUTO_REPORT_ONLY_8812A_2ANT == 1)
  4598. halbtc8812a2ant_monitor_bt_ctr(btcoexist);
  4599. #endif
  4600. btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS);
  4601. }
  4602. void ex_halbtc8812a2ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type)
  4603. {
  4604. boolean wifi_under_5g = false;
  4605. if (BTC_IPS_ENTER == type) {
  4606. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4607. "[BTCoex], IPS ENTER notify\n");
  4608. BTC_TRACE(trace_buf);
  4609. coex_sta->under_ips = true;
  4610. halbtc8812a2ant_coex_all_off(btcoexist);
  4611. halbtc8812a2ant_set_ant_path(btcoexist, BTC_ANT_WIFI_AT_CPL_AUX,
  4612. false, true);
  4613. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4614. "[BTCoex], IPS notify, force set BT to ignore Wlan active!!\n");
  4615. BTC_TRACE(trace_buf);
  4616. halbtc8812a2ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
  4617. ex_halbtc8812a2ant_media_status_notify(btcoexist,
  4618. BTC_MEDIA_DISCONNECT);
  4619. } else if (BTC_IPS_LEAVE == type) {
  4620. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4621. "[BTCoex], IPS LEAVE notify\n");
  4622. BTC_TRACE(trace_buf);
  4623. coex_sta->under_ips = false;
  4624. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G,
  4625. &wifi_under_5g);
  4626. if (!wifi_under_5g) {
  4627. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4628. "[BTCoex], IPS notify, force set BT NOT to ignore Wlan active!!\n");
  4629. BTC_TRACE(trace_buf);
  4630. halbtc8812a2ant_ignore_wlan_act(btcoexist, FORCE_EXEC,
  4631. false);
  4632. }
  4633. }
  4634. }
  4635. void ex_halbtc8812a2ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type)
  4636. {
  4637. if (BTC_LPS_ENABLE == type) {
  4638. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4639. "[BTCoex], LPS ENABLE notify\n");
  4640. BTC_TRACE(trace_buf);
  4641. coex_sta->under_lps = true;
  4642. } else if (BTC_LPS_DISABLE == type) {
  4643. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4644. "[BTCoex], LPS DISABLE notify\n");
  4645. BTC_TRACE(trace_buf);
  4646. coex_sta->under_lps = false;
  4647. }
  4648. }
  4649. void ex_halbtc8812a2ant_scan_notify(IN struct btc_coexist *btcoexist,
  4650. IN u8 type)
  4651. {
  4652. if (BTC_SCAN_START == type) {
  4653. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4654. "[BTCoex], SCAN START notify\n");
  4655. BTC_TRACE(trace_buf);
  4656. } else if (BTC_SCAN_FINISH == type) {
  4657. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4658. "[BTCoex], SCAN FINISH notify\n");
  4659. BTC_TRACE(trace_buf);
  4660. btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
  4661. &coex_sta->scan_ap_num);
  4662. }
  4663. }
  4664. void ex_halbtc8812a2ant_connect_notify(IN struct btc_coexist *btcoexist,
  4665. IN u8 type)
  4666. {
  4667. if (BTC_ASSOCIATE_START == type) {
  4668. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4669. "[BTCoex], CONNECT START notify\n");
  4670. BTC_TRACE(trace_buf);
  4671. } else if (BTC_ASSOCIATE_FINISH == type) {
  4672. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4673. "[BTCoex], CONNECT FINISH notify\n");
  4674. BTC_TRACE(trace_buf);
  4675. }
  4676. }
  4677. void ex_halbtc8812a2ant_media_status_notify(IN struct btc_coexist *btcoexist,
  4678. IN u8 type)
  4679. {
  4680. u8 data_len = 5;
  4681. u8 buf[6] = {0};
  4682. u8 h2c_parameter[3] = {0};
  4683. u32 wifi_bw;
  4684. u8 wifi_central_chnl;
  4685. if (btcoexist->manual_control ||
  4686. btcoexist->stop_coex_dm ||
  4687. btcoexist->bt_info.bt_disabled)
  4688. return;
  4689. if (BTC_MEDIA_CONNECT == type) {
  4690. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4691. "[BTCoex], MEDIA connect notify\n");
  4692. BTC_TRACE(trace_buf);
  4693. } else {
  4694. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4695. "[BTCoex], MEDIA disconnect notify\n");
  4696. BTC_TRACE(trace_buf);
  4697. }
  4698. /* only 2.4G we need to inform bt the chnl mask */
  4699. btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL,
  4700. &wifi_central_chnl);
  4701. if ((BTC_MEDIA_CONNECT == type) &&
  4702. (wifi_central_chnl <= 14)) {
  4703. h2c_parameter[0] = 0x1;
  4704. h2c_parameter[1] = wifi_central_chnl;
  4705. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  4706. if (BTC_WIFI_BW_HT40 == wifi_bw)
  4707. h2c_parameter[2] = 0x30;
  4708. else
  4709. h2c_parameter[2] = 0x20;
  4710. }
  4711. coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
  4712. coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
  4713. coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
  4714. buf[0] = data_len;
  4715. buf[1] = 0x5; /* OP_Code */
  4716. buf[2] = 0x3; /* OP_Code_Length */
  4717. buf[3] = h2c_parameter[0]; /* OP_Code_Content */
  4718. buf[4] = h2c_parameter[1];
  4719. buf[5] = h2c_parameter[2];
  4720. btcoexist->btc_set(btcoexist, BTC_SET_ACT_CTRL_BT_COEX,
  4721. (void *)&buf[0]);
  4722. }
  4723. void ex_halbtc8812a2ant_specific_packet_notify(IN struct btc_coexist *btcoexist,
  4724. IN u8 type)
  4725. {
  4726. if (type == BTC_PACKET_DHCP) {
  4727. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4728. "[BTCoex], DHCP Packet notify\n");
  4729. BTC_TRACE(trace_buf);
  4730. }
  4731. }
  4732. void ex_halbtc8812a2ant_bt_info_notify(IN struct btc_coexist *btcoexist,
  4733. IN u8 *tmp_buf, IN u8 length)
  4734. {
  4735. u8 bt_info = 0;
  4736. u8 i, rsp_source = 0;
  4737. boolean bt_busy = false, limited_dig = false;
  4738. boolean wifi_connected = false, wifi_under_5g = false;
  4739. coex_sta->c2h_bt_info_req_sent = false;
  4740. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  4741. rsp_source = tmp_buf[0] & 0xf;
  4742. if (rsp_source >= BT_INFO_SRC_8812A_2ANT_MAX)
  4743. rsp_source = BT_INFO_SRC_8812A_2ANT_WIFI_FW;
  4744. coex_sta->bt_info_c2h_cnt[rsp_source]++;
  4745. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4746. "[BTCoex], Bt info[%d], length=%d, hex data=[", rsp_source,
  4747. length);
  4748. BTC_TRACE(trace_buf);
  4749. for (i = 0; i < length; i++) {
  4750. coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i];
  4751. if (i == 1)
  4752. bt_info = tmp_buf[i];
  4753. if (i == length - 1) {
  4754. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n",
  4755. tmp_buf[i]);
  4756. BTC_TRACE(trace_buf);
  4757. } else {
  4758. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ",
  4759. tmp_buf[i]);
  4760. BTC_TRACE(trace_buf);
  4761. }
  4762. }
  4763. if (BT_INFO_SRC_8812A_2ANT_WIFI_FW != rsp_source) {
  4764. coex_sta->bt_retry_cnt = /* [3:0] */
  4765. coex_sta->bt_info_c2h[rsp_source][2] & 0xf;
  4766. coex_sta->bt_rssi =
  4767. coex_sta->bt_info_c2h[rsp_source][3] * 2 + 10;
  4768. coex_sta->bt_info_ext =
  4769. coex_sta->bt_info_c2h[rsp_source][4];
  4770. /* Here we need to resend some wifi info to BT */
  4771. /* because bt is reset and loss of the info. */
  4772. if ((coex_sta->bt_info_ext & BIT(1))) {
  4773. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4774. "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
  4775. BTC_TRACE(trace_buf);
  4776. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  4777. &wifi_connected);
  4778. if (wifi_connected)
  4779. ex_halbtc8812a2ant_media_status_notify(
  4780. btcoexist, BTC_MEDIA_CONNECT);
  4781. else
  4782. ex_halbtc8812a2ant_media_status_notify(
  4783. btcoexist, BTC_MEDIA_DISCONNECT);
  4784. }
  4785. if ((coex_sta->bt_info_ext & BIT(3)) && !wifi_under_5g) {
  4786. /* BT already ignored WlanAct */
  4787. if (!btcoexist->manual_control &&
  4788. !btcoexist->stop_coex_dm) {
  4789. if (!coex_sta->under_ips) {
  4790. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4791. "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n");
  4792. BTC_TRACE(trace_buf);
  4793. halbtc8812a2ant_ignore_wlan_act(
  4794. btcoexist, FORCE_EXEC, false);
  4795. }
  4796. }
  4797. } else {
  4798. /* BT already NOT ignore Wlan active, do nothing here. */
  4799. if (coex_sta->under_ips) {
  4800. /* work around for 8812a combo hw bug => when IPS, wlanAct is always high. */
  4801. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4802. "[BTCoex], wifi is under IPS, set BT to ignore Wlan active!!\n");
  4803. BTC_TRACE(trace_buf);
  4804. halbtc8812a2ant_ignore_wlan_act(btcoexist,
  4805. FORCE_EXEC, true);
  4806. }
  4807. }
  4808. }
  4809. /* check BIT2 first ==> check if bt is under inquiry or page scan */
  4810. if (bt_info & BT_INFO_8812A_2ANT_B_INQ_PAGE)
  4811. coex_sta->c2h_bt_inquiry_page = true;
  4812. else
  4813. coex_sta->c2h_bt_inquiry_page = false;
  4814. /* set link exist status */
  4815. if (!(bt_info & BT_INFO_8812A_2ANT_B_CONNECTION)) {
  4816. coex_sta->bt_link_exist = false;
  4817. coex_sta->pan_exist = false;
  4818. coex_sta->a2dp_exist = false;
  4819. coex_sta->hid_exist = false;
  4820. coex_sta->sco_exist = false;
  4821. coex_sta->acl_busy = false;
  4822. } else { /* connection exists */
  4823. coex_sta->bt_link_exist = true;
  4824. if (bt_info & BT_INFO_8812A_2ANT_B_FTP)
  4825. coex_sta->pan_exist = true;
  4826. else
  4827. coex_sta->pan_exist = false;
  4828. if (bt_info & BT_INFO_8812A_2ANT_B_A2DP)
  4829. coex_sta->a2dp_exist = true;
  4830. else
  4831. coex_sta->a2dp_exist = false;
  4832. if (bt_info & BT_INFO_8812A_2ANT_B_HID)
  4833. coex_sta->hid_exist = true;
  4834. else
  4835. coex_sta->hid_exist = false;
  4836. if (bt_info & BT_INFO_8812A_2ANT_B_SCO_ESCO)
  4837. coex_sta->sco_exist = true;
  4838. else
  4839. coex_sta->sco_exist = false;
  4840. if (bt_info & BT_INFO_8812A_2ANT_B_ACL_BUSY)
  4841. coex_sta->acl_busy = true;
  4842. else
  4843. coex_sta->acl_busy = false;
  4844. }
  4845. halbtc8812a2ant_update_bt_link_info(btcoexist);
  4846. if (!(bt_info & BT_INFO_8812A_2ANT_B_CONNECTION)) {
  4847. coex_dm->bt_status = BT_8812A_2ANT_BT_STATUS_NON_CONNECTED_IDLE;
  4848. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4849. "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n");
  4850. BTC_TRACE(trace_buf);
  4851. } else if (bt_info ==
  4852. BT_INFO_8812A_2ANT_B_CONNECTION) { /* connection exists but no busy */
  4853. coex_dm->bt_status = BT_8812A_2ANT_BT_STATUS_CONNECTED_IDLE;
  4854. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4855. "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
  4856. BTC_TRACE(trace_buf);
  4857. } else if ((bt_info & BT_INFO_8812A_2ANT_B_SCO_ESCO) ||
  4858. (bt_info & BT_INFO_8812A_2ANT_B_SCO_BUSY)) {
  4859. coex_dm->bt_status = BT_8812A_2ANT_BT_STATUS_SCO_BUSY;
  4860. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4861. "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
  4862. BTC_TRACE(trace_buf);
  4863. } else if (bt_info & BT_INFO_8812A_2ANT_B_ACL_BUSY) {
  4864. coex_dm->bt_status = BT_8812A_2ANT_BT_STATUS_ACL_BUSY;
  4865. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4866. "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
  4867. BTC_TRACE(trace_buf);
  4868. } else {
  4869. coex_dm->bt_status = BT_8812A_2ANT_BT_STATUS_MAX;
  4870. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4871. "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n");
  4872. BTC_TRACE(trace_buf);
  4873. }
  4874. if ((BT_8812A_2ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
  4875. (BT_8812A_2ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
  4876. (BT_8812A_2ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) {
  4877. bt_busy = true;
  4878. if (!wifi_under_5g)
  4879. limited_dig = true;
  4880. } else {
  4881. bt_busy = false;
  4882. limited_dig = false;
  4883. }
  4884. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
  4885. coex_dm->limited_dig = limited_dig;
  4886. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_LIMITED_DIG, &limited_dig);
  4887. halbtc8812a2ant_run_coexist_mechanism(btcoexist);
  4888. }
  4889. void ex_halbtc8812a2ant_halt_notify(IN struct btc_coexist *btcoexist)
  4890. {
  4891. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n");
  4892. BTC_TRACE(trace_buf);
  4893. halbtc8812a2ant_set_ant_path(btcoexist, BTC_ANT_WIFI_AT_CPL_AUX, false,
  4894. true);
  4895. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4896. "[BTCoex], Halt notify, force set BT to ignore Wlan active!!\n");
  4897. BTC_TRACE(trace_buf);
  4898. halbtc8812a2ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
  4899. ex_halbtc8812a2ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT);
  4900. /* 0x522=0xff, pause tx */
  4901. btcoexist->btc_write_1byte(btcoexist, 0x522, 0xff);
  4902. /* 0x40[7:6]=2'b01, modify BT mode. */
  4903. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0xc0, 0x2);
  4904. /* PTA off. */
  4905. #ifndef CONFIG_PCI_HCI
  4906. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x0);
  4907. #endif
  4908. }
  4909. void ex_halbtc8812a2ant_periodical(IN struct btc_coexist *btcoexist)
  4910. {
  4911. static u8 dis_ver_info_cnt = 0;
  4912. u32 fw_ver = 0, bt_patch_ver = 0;
  4913. struct btc_board_info *board_info = &btcoexist->board_info;
  4914. struct btc_stack_info *stack_info = &btcoexist->stack_info;
  4915. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4916. "[BTCoex], ==========================Periodical===========================\n");
  4917. BTC_TRACE(trace_buf);
  4918. if (dis_ver_info_cnt <= 5) {
  4919. dis_ver_info_cnt += 1;
  4920. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4921. "[BTCoex], ****************************************************************\n");
  4922. BTC_TRACE(trace_buf);
  4923. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4924. "[BTCoex], Ant PG Num/ Ant Mech/ Ant Pos = %d/ %d/ %d\n",
  4925. board_info->pg_ant_num, board_info->btdm_ant_num,
  4926. board_info->btdm_ant_pos);
  4927. BTC_TRACE(trace_buf);
  4928. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4929. "[BTCoex], BT stack/ hci ext ver = %s / %d\n",
  4930. ((stack_info->profile_notified) ? "Yes" : "No"),
  4931. stack_info->hci_version);
  4932. BTC_TRACE(trace_buf);
  4933. btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER,
  4934. &bt_patch_ver);
  4935. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
  4936. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4937. "[BTCoex], CoexVer/ FwVer/ PatchVer = %d_%x/ 0x%x/ 0x%x(%d)\n",
  4938. glcoex_ver_date_8812a_2ant, glcoex_ver_8812a_2ant,
  4939. fw_ver, bt_patch_ver, bt_patch_ver);
  4940. BTC_TRACE(trace_buf);
  4941. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4942. "[BTCoex], ****************************************************************\n");
  4943. BTC_TRACE(trace_buf);
  4944. }
  4945. if ((coex_sta->bt_coex_supported_version == 0) ||
  4946. (coex_sta->bt_coex_supported_version == 0xffff))
  4947. coex_sta->bt_coex_supported_version =
  4948. btcoexist->btc_get_bt_coex_supported_version(btcoexist);
  4949. #if (BT_AUTO_REPORT_ONLY_8812A_2ANT == 0)
  4950. halbtc8812a2ant_query_bt_info(btcoexist);
  4951. halbtc8812a2ant_monitor_bt_ctr(btcoexist);
  4952. halbtc8812a2ant_monitor_wifi_ctr(btcoexist);
  4953. halbtc8812a2ant_monitor_bt_enable_disable(btcoexist);
  4954. #else
  4955. halbtc8812a2ant_monitor_wifi_ctr(btcoexist);
  4956. if (halbtc8812a2ant_is_wifi_status_changed(btcoexist) ||
  4957. coex_dm->auto_tdma_adjust ||
  4958. coex_dm->auto_tdma_adjust_low_rssi)
  4959. halbtc8812a2ant_run_coexist_mechanism(btcoexist);
  4960. #endif
  4961. }
  4962. void ex_halbtc8812a2ant_dbg_control(IN struct btc_coexist *btcoexist,
  4963. IN u8 op_code, IN u8 op_len, IN u8 *pdata)
  4964. {
  4965. switch (op_code) {
  4966. case BTC_DBG_SET_COEX_DEC_BT_PWR:
  4967. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4968. "[BTCoex], Set Dec BT power\n");
  4969. BTC_TRACE(trace_buf);
  4970. {
  4971. u8 data_len = 4;
  4972. u8 buf[6] = {0};
  4973. u8 dec_bt_pwr = 0, pwr_level = 0;
  4974. if (op_len == 2) {
  4975. dec_bt_pwr = pdata[0];
  4976. pwr_level = pdata[1];
  4977. buf[0] = data_len;
  4978. buf[1] = 0x3; /* OP_Code */
  4979. buf[2] = 0x2; /* OP_Code_Length */
  4980. buf[3] = dec_bt_pwr; /* OP_Code_Content */
  4981. buf[4] = pwr_level;
  4982. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4983. "[BTCoex], Set Dec BT power=%d, pwr_level=%d\n",
  4984. dec_bt_pwr, pwr_level);
  4985. BTC_TRACE(trace_buf);
  4986. btcoexist->btc_set(btcoexist,
  4987. BTC_SET_ACT_CTRL_BT_COEX,
  4988. (void *)&buf[0]);
  4989. }
  4990. }
  4991. break;
  4992. case BTC_DBG_SET_COEX_BT_AFH_MAP:
  4993. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  4994. "[BTCoex], Set BT AFH Map\n");
  4995. BTC_TRACE(trace_buf);
  4996. {
  4997. u8 data_len = 5;
  4998. u8 buf[6] = {0};
  4999. if (op_len == 3) {
  5000. buf[0] = data_len;
  5001. buf[1] = 0x5; /* OP_Code */
  5002. buf[2] = 0x3; /* OP_Code_Length */
  5003. buf[3] = pdata[0]; /* OP_Code_Content */
  5004. buf[4] = pdata[1];
  5005. buf[5] = pdata[2];
  5006. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5007. "[BTCoex], Set BT AFH Map = %02x %02x %02x\n",
  5008. pdata[0], pdata[1], pdata[2]);
  5009. BTC_TRACE(trace_buf);
  5010. btcoexist->btc_set(btcoexist,
  5011. BTC_SET_ACT_CTRL_BT_COEX,
  5012. (void *)&buf[0]);
  5013. }
  5014. }
  5015. break;
  5016. case BTC_DBG_SET_COEX_BT_IGNORE_WLAN_ACT:
  5017. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5018. "[BTCoex], Set BT Ignore Wlan Active\n");
  5019. BTC_TRACE(trace_buf);
  5020. {
  5021. u8 data_len = 3;
  5022. u8 buf[6] = {0};
  5023. if (op_len == 1) {
  5024. buf[0] = data_len;
  5025. buf[1] = 0x1; /* OP_Code */
  5026. buf[2] = 0x1; /* OP_Code_Length */
  5027. buf[3] = pdata[0]; /* OP_Code_Content */
  5028. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  5029. "[BTCoex], Set BT Ignore Wlan Active = 0x%x\n",
  5030. pdata[0]);
  5031. BTC_TRACE(trace_buf);
  5032. btcoexist->btc_set(btcoexist,
  5033. BTC_SET_ACT_CTRL_BT_COEX,
  5034. (void *)&buf[0]);
  5035. }
  5036. }
  5037. break;
  5038. default:
  5039. break;
  5040. }
  5041. }
  5042. #endif
  5043. #endif /* #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) */