wcd934x.c 311 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254
  1. /* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/init.h>
  14. #include <linux/firmware.h>
  15. #include <linux/slab.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/device.h>
  18. #include <linux/printk.h>
  19. #include <linux/ratelimit.h>
  20. #include <linux/debugfs.h>
  21. #include <linux/wait.h>
  22. #include <linux/bitops.h>
  23. #include <linux/clk.h>
  24. #include <linux/delay.h>
  25. #include <linux/pm_runtime.h>
  26. #include <linux/kernel.h>
  27. #include <linux/gpio.h>
  28. #include <linux/regmap.h>
  29. #include <linux/spi/spi.h>
  30. #include <linux/regulator/consumer.h>
  31. #include <linux/mfd/wcd9xxx/wcd9xxx_registers.h>
  32. #include <soc/swr-wcd.h>
  33. #include <sound/pcm.h>
  34. #include <sound/pcm_params.h>
  35. #include <sound/soc.h>
  36. #include <sound/soc-dapm.h>
  37. #include <sound/tlv.h>
  38. #include <sound/info.h>
  39. #include <asoc/wcd934x_registers.h>
  40. #include "wcd934x.h"
  41. #include "wcd934x-mbhc.h"
  42. #include "wcd934x-routing.h"
  43. #include "wcd934x-dsp-cntl.h"
  44. #include "wcd934x_irq.h"
  45. #include "../core.h"
  46. #include "../pdata.h"
  47. #include "../wcd9xxx-irq.h"
  48. #include "../wcd9xxx-common-v2.h"
  49. #include "../wcd9xxx-resmgr-v2.h"
  50. #include "../wcdcal-hwdep.h"
  51. #include "wcd934x-dsd.h"
  52. #define WCD934X_RATES_MASK (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
  53. SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\
  54. SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000 |\
  55. SNDRV_PCM_RATE_384000)
  56. /* Fractional Rates */
  57. #define WCD934X_FRAC_RATES_MASK (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_88200 |\
  58. SNDRV_PCM_RATE_176400)
  59. #define WCD934X_FORMATS_S16_S24_LE (SNDRV_PCM_FMTBIT_S16_LE | \
  60. SNDRV_PCM_FMTBIT_S24_LE)
  61. #define WCD934X_FORMATS_S16_S24_S32_LE (SNDRV_PCM_FMTBIT_S16_LE | \
  62. SNDRV_PCM_FMTBIT_S24_LE | \
  63. SNDRV_PCM_FMTBIT_S32_LE)
  64. #define WCD934X_FORMATS_S16_LE (SNDRV_PCM_FMTBIT_S16_LE)
  65. /* Macros for packing register writes into a U32 */
  66. #define WCD934X_PACKED_REG_SIZE sizeof(u32)
  67. #define WCD934X_CODEC_UNPACK_ENTRY(packed, reg, mask, val) \
  68. do { \
  69. ((reg) = ((packed >> 16) & (0xffff))); \
  70. ((mask) = ((packed >> 8) & (0xff))); \
  71. ((val) = ((packed) & (0xff))); \
  72. } while (0)
  73. #define STRING(name) #name
  74. #define WCD_DAPM_ENUM(name, reg, offset, text) \
  75. static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
  76. static const struct snd_kcontrol_new name##_mux = \
  77. SOC_DAPM_ENUM(STRING(name), name##_enum)
  78. #define WCD_DAPM_ENUM_EXT(name, reg, offset, text, getname, putname) \
  79. static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
  80. static const struct snd_kcontrol_new name##_mux = \
  81. SOC_DAPM_ENUM_EXT(STRING(name), name##_enum, getname, putname)
  82. #define WCD_DAPM_MUX(name, shift, kctl) \
  83. SND_SOC_DAPM_MUX(name, SND_SOC_NOPM, shift, 0, &kctl##_mux)
  84. /*
  85. * Timeout in milli seconds and it is the wait time for
  86. * slim channel removal interrupt to receive.
  87. */
  88. #define WCD934X_SLIM_CLOSE_TIMEOUT 1000
  89. #define WCD934X_SLIM_IRQ_OVERFLOW (1 << 0)
  90. #define WCD934X_SLIM_IRQ_UNDERFLOW (1 << 1)
  91. #define WCD934X_SLIM_IRQ_PORT_CLOSED (1 << 2)
  92. #define WCD934X_MCLK_CLK_12P288MHZ 12288000
  93. #define WCD934X_MCLK_CLK_9P6MHZ 9600000
  94. #define WCD934X_INTERP_MUX_NUM_INPUTS 3
  95. #define WCD934X_NUM_INTERPOLATORS 9
  96. #define WCD934X_NUM_DECIMATORS 9
  97. #define WCD934X_RX_PATH_CTL_OFFSET 20
  98. #define BYTE_BIT_MASK(nr) (1 << ((nr) % BITS_PER_BYTE))
  99. #define WCD934X_REG_BITS 8
  100. #define WCD934X_MAX_VALID_ADC_MUX 13
  101. #define WCD934X_INVALID_ADC_MUX 9
  102. #define WCD934X_AMIC_PWR_LEVEL_LP 0
  103. #define WCD934X_AMIC_PWR_LEVEL_DEFAULT 1
  104. #define WCD934X_AMIC_PWR_LEVEL_HP 2
  105. #define WCD934X_AMIC_PWR_LEVEL_HYBRID 3
  106. #define WCD934X_AMIC_PWR_LVL_MASK 0x60
  107. #define WCD934X_AMIC_PWR_LVL_SHIFT 0x5
  108. #define WCD934X_DEC_PWR_LVL_MASK 0x06
  109. #define WCD934X_DEC_PWR_LVL_LP 0x02
  110. #define WCD934X_DEC_PWR_LVL_HP 0x04
  111. #define WCD934X_DEC_PWR_LVL_DF 0x00
  112. #define WCD934X_DEC_PWR_LVL_HYBRID WCD934X_DEC_PWR_LVL_DF
  113. #define WCD934X_STRING_LEN 100
  114. #define WCD934X_CDC_SIDETONE_IIR_COEFF_MAX 5
  115. #define WCD934X_CDC_REPEAT_WRITES_MAX 16
  116. #define WCD934X_DIG_CORE_REG_MIN WCD934X_CDC_ANC0_CLK_RESET_CTL
  117. #define WCD934X_DIG_CORE_REG_MAX 0xFFF
  118. #define WCD934X_CHILD_DEVICES_MAX 6
  119. #define WCD934X_MAX_MICBIAS 4
  120. #define DAPM_MICBIAS1_STANDALONE "MIC BIAS1 Standalone"
  121. #define DAPM_MICBIAS2_STANDALONE "MIC BIAS2 Standalone"
  122. #define DAPM_MICBIAS3_STANDALONE "MIC BIAS3 Standalone"
  123. #define DAPM_MICBIAS4_STANDALONE "MIC BIAS4 Standalone"
  124. #define TX_HPF_CUT_OFF_FREQ_MASK 0x60
  125. #define CF_MIN_3DB_4HZ 0x0
  126. #define CF_MIN_3DB_75HZ 0x1
  127. #define CF_MIN_3DB_150HZ 0x2
  128. #define CPE_ERR_WDOG_BITE BIT(0)
  129. #define CPE_FATAL_IRQS CPE_ERR_WDOG_BITE
  130. #define WCD934X_MAD_AUDIO_FIRMWARE_PATH "wcd934x/wcd934x_mad_audio.bin"
  131. #define TAVIL_VERSION_ENTRY_SIZE 17
  132. #define WCD934X_DIG_CORE_COLLAPSE_TIMER_MS (5 * 1000)
  133. enum {
  134. POWER_COLLAPSE,
  135. POWER_RESUME,
  136. };
  137. static int dig_core_collapse_enable = 1;
  138. module_param(dig_core_collapse_enable, int, 0664);
  139. MODULE_PARM_DESC(dig_core_collapse_enable, "enable/disable power gating");
  140. /* dig_core_collapse timer in seconds */
  141. static int dig_core_collapse_timer = (WCD934X_DIG_CORE_COLLAPSE_TIMER_MS/1000);
  142. module_param(dig_core_collapse_timer, int, 0664);
  143. MODULE_PARM_DESC(dig_core_collapse_timer, "timer for power gating");
  144. #define TAVIL_HPH_REG_RANGE_1 (WCD934X_HPH_R_DAC_CTL - WCD934X_HPH_CNP_EN + 1)
  145. #define TAVIL_HPH_REG_RANGE_2 (WCD934X_HPH_NEW_ANA_HPH3 -\
  146. WCD934X_HPH_NEW_ANA_HPH2 + 1)
  147. #define TAVIL_HPH_REG_RANGE_3 (WCD934X_HPH_NEW_INT_PA_RDAC_MISC3 -\
  148. WCD934X_HPH_NEW_INT_RDAC_GAIN_CTL + 1)
  149. #define TAVIL_HPH_TOTAL_REG (TAVIL_HPH_REG_RANGE_1 + TAVIL_HPH_REG_RANGE_2 +\
  150. TAVIL_HPH_REG_RANGE_3)
  151. enum {
  152. VI_SENSE_1,
  153. VI_SENSE_2,
  154. AUDIO_NOMINAL,
  155. HPH_PA_DELAY,
  156. CLSH_Z_CONFIG,
  157. ANC_MIC_AMIC1,
  158. ANC_MIC_AMIC2,
  159. ANC_MIC_AMIC3,
  160. ANC_MIC_AMIC4,
  161. CLK_INTERNAL,
  162. CLK_MODE,
  163. };
  164. enum {
  165. AIF1_PB = 0,
  166. AIF1_CAP,
  167. AIF2_PB,
  168. AIF2_CAP,
  169. AIF3_PB,
  170. AIF3_CAP,
  171. AIF4_PB,
  172. AIF4_VIFEED,
  173. AIF4_MAD_TX,
  174. NUM_CODEC_DAIS,
  175. };
  176. enum {
  177. INTn_1_INP_SEL_ZERO = 0,
  178. INTn_1_INP_SEL_DEC0,
  179. INTn_1_INP_SEL_DEC1,
  180. INTn_1_INP_SEL_IIR0,
  181. INTn_1_INP_SEL_IIR1,
  182. INTn_1_INP_SEL_RX0,
  183. INTn_1_INP_SEL_RX1,
  184. INTn_1_INP_SEL_RX2,
  185. INTn_1_INP_SEL_RX3,
  186. INTn_1_INP_SEL_RX4,
  187. INTn_1_INP_SEL_RX5,
  188. INTn_1_INP_SEL_RX6,
  189. INTn_1_INP_SEL_RX7,
  190. };
  191. enum {
  192. INTn_2_INP_SEL_ZERO = 0,
  193. INTn_2_INP_SEL_RX0,
  194. INTn_2_INP_SEL_RX1,
  195. INTn_2_INP_SEL_RX2,
  196. INTn_2_INP_SEL_RX3,
  197. INTn_2_INP_SEL_RX4,
  198. INTn_2_INP_SEL_RX5,
  199. INTn_2_INP_SEL_RX6,
  200. INTn_2_INP_SEL_RX7,
  201. INTn_2_INP_SEL_PROXIMITY,
  202. };
  203. enum {
  204. INTERP_MAIN_PATH,
  205. INTERP_MIX_PATH,
  206. };
  207. struct tavil_idle_detect_config {
  208. u8 hph_idle_thr;
  209. u8 hph_idle_detect_en;
  210. };
  211. struct tavil_cpr_reg_defaults {
  212. int wr_data;
  213. int wr_addr;
  214. };
  215. struct interp_sample_rate {
  216. int sample_rate;
  217. int rate_val;
  218. };
  219. static struct interp_sample_rate sr_val_tbl[] = {
  220. {8000, 0x0}, {16000, 0x1}, {32000, 0x3}, {48000, 0x4}, {96000, 0x5},
  221. {192000, 0x6}, {384000, 0x7}, {44100, 0x9}, {88200, 0xA},
  222. {176400, 0xB}, {352800, 0xC},
  223. };
  224. static const struct wcd9xxx_ch tavil_rx_chs[WCD934X_RX_MAX] = {
  225. WCD9XXX_CH(WCD934X_RX_PORT_START_NUMBER, 0),
  226. WCD9XXX_CH(WCD934X_RX_PORT_START_NUMBER + 1, 1),
  227. WCD9XXX_CH(WCD934X_RX_PORT_START_NUMBER + 2, 2),
  228. WCD9XXX_CH(WCD934X_RX_PORT_START_NUMBER + 3, 3),
  229. WCD9XXX_CH(WCD934X_RX_PORT_START_NUMBER + 4, 4),
  230. WCD9XXX_CH(WCD934X_RX_PORT_START_NUMBER + 5, 5),
  231. WCD9XXX_CH(WCD934X_RX_PORT_START_NUMBER + 6, 6),
  232. WCD9XXX_CH(WCD934X_RX_PORT_START_NUMBER + 7, 7),
  233. };
  234. static const struct wcd9xxx_ch tavil_tx_chs[WCD934X_TX_MAX] = {
  235. WCD9XXX_CH(0, 0),
  236. WCD9XXX_CH(1, 1),
  237. WCD9XXX_CH(2, 2),
  238. WCD9XXX_CH(3, 3),
  239. WCD9XXX_CH(4, 4),
  240. WCD9XXX_CH(5, 5),
  241. WCD9XXX_CH(6, 6),
  242. WCD9XXX_CH(7, 7),
  243. WCD9XXX_CH(8, 8),
  244. WCD9XXX_CH(9, 9),
  245. WCD9XXX_CH(10, 10),
  246. WCD9XXX_CH(11, 11),
  247. WCD9XXX_CH(12, 12),
  248. WCD9XXX_CH(13, 13),
  249. WCD9XXX_CH(14, 14),
  250. WCD9XXX_CH(15, 15),
  251. };
  252. static const u32 vport_slim_check_table[NUM_CODEC_DAIS] = {
  253. 0, /* AIF1_PB */
  254. BIT(AIF2_CAP) | BIT(AIF3_CAP) | BIT(AIF4_MAD_TX), /* AIF1_CAP */
  255. 0, /* AIF2_PB */
  256. BIT(AIF1_CAP) | BIT(AIF3_CAP) | BIT(AIF4_MAD_TX), /* AIF2_CAP */
  257. 0, /* AIF3_PB */
  258. BIT(AIF1_CAP) | BIT(AIF2_CAP) | BIT(AIF4_MAD_TX), /* AIF3_CAP */
  259. 0, /* AIF4_PB */
  260. };
  261. /* Codec supports 2 IIR filters */
  262. enum {
  263. IIR0 = 0,
  264. IIR1,
  265. IIR_MAX,
  266. };
  267. /* Each IIR has 5 Filter Stages */
  268. enum {
  269. BAND1 = 0,
  270. BAND2,
  271. BAND3,
  272. BAND4,
  273. BAND5,
  274. BAND_MAX,
  275. };
  276. enum {
  277. COMPANDER_1, /* HPH_L */
  278. COMPANDER_2, /* HPH_R */
  279. COMPANDER_3, /* LO1_DIFF */
  280. COMPANDER_4, /* LO2_DIFF */
  281. COMPANDER_5, /* LO3_SE - not used in Tavil */
  282. COMPANDER_6, /* LO4_SE - not used in Tavil */
  283. COMPANDER_7, /* SWR SPK CH1 */
  284. COMPANDER_8, /* SWR SPK CH2 */
  285. COMPANDER_MAX,
  286. };
  287. enum {
  288. ASRC_IN_HPHL,
  289. ASRC_IN_LO1,
  290. ASRC_IN_HPHR,
  291. ASRC_IN_LO2,
  292. ASRC_IN_SPKR1,
  293. ASRC_IN_SPKR2,
  294. ASRC_INVALID,
  295. };
  296. enum {
  297. ASRC0,
  298. ASRC1,
  299. ASRC2,
  300. ASRC3,
  301. ASRC_MAX,
  302. };
  303. enum {
  304. CONV_88P2K_TO_384K,
  305. CONV_96K_TO_352P8K,
  306. CONV_352P8K_TO_384K,
  307. CONV_384K_TO_352P8K,
  308. CONV_384K_TO_384K,
  309. CONV_96K_TO_384K,
  310. };
  311. static struct afe_param_slimbus_slave_port_cfg tavil_slimbus_slave_port_cfg = {
  312. .minor_version = 1,
  313. .slimbus_dev_id = AFE_SLIMBUS_DEVICE_1,
  314. .slave_dev_pgd_la = 0,
  315. .slave_dev_intfdev_la = 0,
  316. .bit_width = 16,
  317. .data_format = 0,
  318. .num_channels = 1
  319. };
  320. static struct afe_param_cdc_reg_page_cfg tavil_cdc_reg_page_cfg = {
  321. .minor_version = AFE_API_VERSION_CDC_REG_PAGE_CFG,
  322. .enable = 1,
  323. .proc_id = AFE_CDC_REG_PAGE_ASSIGN_PROC_ID_1,
  324. };
  325. static struct afe_param_cdc_reg_cfg audio_reg_cfg[] = {
  326. {
  327. 1,
  328. (WCD934X_REGISTER_START_OFFSET + WCD934X_SOC_MAD_MAIN_CTL_1),
  329. HW_MAD_AUDIO_ENABLE, 0x1, WCD934X_REG_BITS, 0
  330. },
  331. {
  332. 1,
  333. (WCD934X_REGISTER_START_OFFSET + WCD934X_SOC_MAD_AUDIO_CTL_3),
  334. HW_MAD_AUDIO_SLEEP_TIME, 0xF, WCD934X_REG_BITS, 0
  335. },
  336. {
  337. 1,
  338. (WCD934X_REGISTER_START_OFFSET + WCD934X_SOC_MAD_AUDIO_CTL_4),
  339. HW_MAD_TX_AUDIO_SWITCH_OFF, 0x1, WCD934X_REG_BITS, 0
  340. },
  341. {
  342. 1,
  343. (WCD934X_REGISTER_START_OFFSET + WCD934X_INTR_CFG),
  344. MAD_AUDIO_INT_DEST_SELECT_REG, 0x2, WCD934X_REG_BITS, 0
  345. },
  346. {
  347. 1,
  348. (WCD934X_REGISTER_START_OFFSET + WCD934X_INTR_PIN2_MASK3),
  349. MAD_AUDIO_INT_MASK_REG, 0x1, WCD934X_REG_BITS, 0
  350. },
  351. {
  352. 1,
  353. (WCD934X_REGISTER_START_OFFSET + WCD934X_INTR_PIN2_STATUS3),
  354. MAD_AUDIO_INT_STATUS_REG, 0x1, WCD934X_REG_BITS, 0
  355. },
  356. {
  357. 1,
  358. (WCD934X_REGISTER_START_OFFSET + WCD934X_INTR_PIN2_CLEAR3),
  359. MAD_AUDIO_INT_CLEAR_REG, 0x1, WCD934X_REG_BITS, 0
  360. },
  361. {
  362. 1,
  363. (WCD934X_REGISTER_START_OFFSET + WCD934X_SB_PGD_PORT_TX_BASE),
  364. SB_PGD_PORT_TX_WATERMARK_N, 0x1E, WCD934X_REG_BITS, 0x1
  365. },
  366. {
  367. 1,
  368. (WCD934X_REGISTER_START_OFFSET + WCD934X_SB_PGD_PORT_TX_BASE),
  369. SB_PGD_PORT_TX_ENABLE_N, 0x1, WCD934X_REG_BITS, 0x1
  370. },
  371. {
  372. 1,
  373. (WCD934X_REGISTER_START_OFFSET + WCD934X_SB_PGD_PORT_RX_BASE),
  374. SB_PGD_PORT_RX_WATERMARK_N, 0x1E, WCD934X_REG_BITS, 0x1
  375. },
  376. {
  377. 1,
  378. (WCD934X_REGISTER_START_OFFSET + WCD934X_SB_PGD_PORT_RX_BASE),
  379. SB_PGD_PORT_RX_ENABLE_N, 0x1, WCD934X_REG_BITS, 0x1
  380. },
  381. {
  382. 1,
  383. (WCD934X_REGISTER_START_OFFSET +
  384. WCD934X_CDC_ANC0_IIR_ADAPT_CTL),
  385. AANC_FF_GAIN_ADAPTIVE, 0x4, WCD934X_REG_BITS, 0
  386. },
  387. {
  388. 1,
  389. (WCD934X_REGISTER_START_OFFSET +
  390. WCD934X_CDC_ANC0_IIR_ADAPT_CTL),
  391. AANC_FFGAIN_ADAPTIVE_EN, 0x8, WCD934X_REG_BITS, 0
  392. },
  393. {
  394. 1,
  395. (WCD934X_REGISTER_START_OFFSET +
  396. WCD934X_CDC_ANC0_FF_A_GAIN_CTL),
  397. AANC_GAIN_CONTROL, 0xFF, WCD934X_REG_BITS, 0
  398. },
  399. {
  400. 1,
  401. (WCD934X_REGISTER_START_OFFSET +
  402. SB_PGD_TX_PORT_MULTI_CHANNEL_0(0)),
  403. SB_PGD_TX_PORTn_MULTI_CHNL_0, 0xFF, WCD934X_REG_BITS, 0x4
  404. },
  405. {
  406. 1,
  407. (WCD934X_REGISTER_START_OFFSET +
  408. SB_PGD_TX_PORT_MULTI_CHANNEL_1(0)),
  409. SB_PGD_TX_PORTn_MULTI_CHNL_1, 0xFF, WCD934X_REG_BITS, 0x4
  410. },
  411. {
  412. 1,
  413. (WCD934X_REGISTER_START_OFFSET +
  414. SB_PGD_RX_PORT_MULTI_CHANNEL_0(0x180, 0)),
  415. SB_PGD_RX_PORTn_MULTI_CHNL_0, 0xFF, WCD934X_REG_BITS, 0x4
  416. },
  417. {
  418. 1,
  419. (WCD934X_REGISTER_START_OFFSET +
  420. SB_PGD_RX_PORT_MULTI_CHANNEL_0(0x181, 0)),
  421. SB_PGD_RX_PORTn_MULTI_CHNL_1, 0xFF, WCD934X_REG_BITS, 0x4
  422. },
  423. };
  424. static struct afe_param_cdc_reg_cfg_data tavil_audio_reg_cfg = {
  425. .num_registers = ARRAY_SIZE(audio_reg_cfg),
  426. .reg_data = audio_reg_cfg,
  427. };
  428. static struct afe_param_id_cdc_aanc_version tavil_cdc_aanc_version = {
  429. .cdc_aanc_minor_version = AFE_API_VERSION_CDC_AANC_VERSION,
  430. .aanc_hw_version = AANC_HW_BLOCK_VERSION_2,
  431. };
  432. static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0);
  433. static const DECLARE_TLV_DB_SCALE(line_gain, 0, 7, 1);
  434. static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 25, 1);
  435. #define WCD934X_TX_UNMUTE_DELAY_MS 40
  436. static int tx_unmute_delay = WCD934X_TX_UNMUTE_DELAY_MS;
  437. module_param(tx_unmute_delay, int, 0664);
  438. MODULE_PARM_DESC(tx_unmute_delay, "delay to unmute the tx path");
  439. static void tavil_codec_set_tx_hold(struct snd_soc_codec *, u16, bool);
  440. /* Hold instance to soundwire platform device */
  441. struct tavil_swr_ctrl_data {
  442. struct platform_device *swr_pdev;
  443. };
  444. struct wcd_swr_ctrl_platform_data {
  445. void *handle; /* holds codec private data */
  446. int (*read)(void *handle, int reg);
  447. int (*write)(void *handle, int reg, int val);
  448. int (*bulk_write)(void *handle, u32 *reg, u32 *val, size_t len);
  449. int (*clk)(void *handle, bool enable);
  450. int (*handle_irq)(void *handle,
  451. irqreturn_t (*swrm_irq_handler)(int irq, void *data),
  452. void *swrm_handle, int action);
  453. };
  454. /* Holds all Soundwire and speaker related information */
  455. struct wcd934x_swr {
  456. struct tavil_swr_ctrl_data *ctrl_data;
  457. struct wcd_swr_ctrl_platform_data plat_data;
  458. struct mutex read_mutex;
  459. struct mutex write_mutex;
  460. struct mutex clk_mutex;
  461. int spkr_gain_offset;
  462. int spkr_mode;
  463. int clk_users;
  464. int rx_7_count;
  465. int rx_8_count;
  466. };
  467. struct tx_mute_work {
  468. struct tavil_priv *tavil;
  469. u8 decimator;
  470. struct delayed_work dwork;
  471. };
  472. #define WCD934X_SPK_ANC_EN_DELAY_MS 550
  473. static int spk_anc_en_delay = WCD934X_SPK_ANC_EN_DELAY_MS;
  474. module_param(spk_anc_en_delay, int, 0664);
  475. MODULE_PARM_DESC(spk_anc_en_delay, "delay to enable anc in speaker path");
  476. struct spk_anc_work {
  477. struct tavil_priv *tavil;
  478. struct delayed_work dwork;
  479. };
  480. struct hpf_work {
  481. struct tavil_priv *tavil;
  482. u8 decimator;
  483. u8 hpf_cut_off_freq;
  484. struct delayed_work dwork;
  485. };
  486. struct tavil_priv {
  487. struct device *dev;
  488. struct wcd9xxx *wcd9xxx;
  489. struct snd_soc_codec *codec;
  490. u32 rx_bias_count;
  491. s32 dmic_0_1_clk_cnt;
  492. s32 dmic_2_3_clk_cnt;
  493. s32 dmic_4_5_clk_cnt;
  494. s32 micb_ref[TAVIL_MAX_MICBIAS];
  495. s32 pullup_ref[TAVIL_MAX_MICBIAS];
  496. /* ANC related */
  497. u32 anc_slot;
  498. bool anc_func;
  499. /* compander */
  500. int comp_enabled[COMPANDER_MAX];
  501. int ear_spkr_gain;
  502. /* class h specific data */
  503. struct wcd_clsh_cdc_data clsh_d;
  504. /* Tavil Interpolator Mode Select for EAR, HPH_L and HPH_R */
  505. u32 hph_mode;
  506. /* Mad switch reference count */
  507. int mad_switch_cnt;
  508. /* track tavil interface type */
  509. u8 intf_type;
  510. /* to track the status */
  511. unsigned long status_mask;
  512. struct afe_param_cdc_slimbus_slave_cfg slimbus_slave_cfg;
  513. /* num of slim ports required */
  514. struct wcd9xxx_codec_dai_data dai[NUM_CODEC_DAIS];
  515. /* Port values for Rx and Tx codec_dai */
  516. unsigned int rx_port_value[WCD934X_RX_MAX];
  517. unsigned int tx_port_value;
  518. struct wcd9xxx_resmgr_v2 *resmgr;
  519. struct wcd934x_swr swr;
  520. struct mutex micb_lock;
  521. struct delayed_work power_gate_work;
  522. struct mutex power_lock;
  523. struct clk *wcd_ext_clk;
  524. /* mbhc module */
  525. struct wcd934x_mbhc *mbhc;
  526. struct mutex codec_mutex;
  527. struct work_struct tavil_add_child_devices_work;
  528. struct hpf_work tx_hpf_work[WCD934X_NUM_DECIMATORS];
  529. struct tx_mute_work tx_mute_dwork[WCD934X_NUM_DECIMATORS];
  530. struct spk_anc_work spk_anc_dwork;
  531. unsigned int vi_feed_value;
  532. /* DSP control */
  533. struct wcd_dsp_cntl *wdsp_cntl;
  534. /* cal info for codec */
  535. struct fw_info *fw_data;
  536. /* Entry for version info */
  537. struct snd_info_entry *entry;
  538. struct snd_info_entry *version_entry;
  539. /* SVS voting related */
  540. struct mutex svs_mutex;
  541. int svs_ref_cnt;
  542. int native_clk_users;
  543. /* ASRC users count */
  544. int asrc_users[ASRC_MAX];
  545. int asrc_output_mode[ASRC_MAX];
  546. /* Main path clock users count */
  547. int main_clk_users[WCD934X_NUM_INTERPOLATORS];
  548. struct tavil_dsd_config *dsd_config;
  549. struct tavil_idle_detect_config idle_det_cfg;
  550. int power_active_ref;
  551. u8 sidetone_coeff_array[IIR_MAX][BAND_MAX]
  552. [WCD934X_CDC_SIDETONE_IIR_COEFF_MAX * 4];
  553. struct spi_device *spi;
  554. struct platform_device *pdev_child_devices
  555. [WCD934X_CHILD_DEVICES_MAX];
  556. int child_count;
  557. };
  558. static const struct tavil_reg_mask_val tavil_spkr_default[] = {
  559. {WCD934X_CDC_COMPANDER7_CTL3, 0x80, 0x80},
  560. {WCD934X_CDC_COMPANDER8_CTL3, 0x80, 0x80},
  561. {WCD934X_CDC_COMPANDER7_CTL7, 0x01, 0x01},
  562. {WCD934X_CDC_COMPANDER8_CTL7, 0x01, 0x01},
  563. {WCD934X_CDC_BOOST0_BOOST_CTL, 0x7C, 0x50},
  564. {WCD934X_CDC_BOOST1_BOOST_CTL, 0x7C, 0x50},
  565. };
  566. static const struct tavil_reg_mask_val tavil_spkr_mode1[] = {
  567. {WCD934X_CDC_COMPANDER7_CTL3, 0x80, 0x00},
  568. {WCD934X_CDC_COMPANDER8_CTL3, 0x80, 0x00},
  569. {WCD934X_CDC_COMPANDER7_CTL7, 0x01, 0x00},
  570. {WCD934X_CDC_COMPANDER8_CTL7, 0x01, 0x00},
  571. {WCD934X_CDC_BOOST0_BOOST_CTL, 0x7C, 0x44},
  572. {WCD934X_CDC_BOOST1_BOOST_CTL, 0x7C, 0x44},
  573. };
  574. static int __tavil_enable_efuse_sensing(struct tavil_priv *tavil);
  575. /**
  576. * tavil_set_spkr_gain_offset - offset the speaker path
  577. * gain with the given offset value.
  578. *
  579. * @codec: codec instance
  580. * @offset: Indicates speaker path gain offset value.
  581. *
  582. * Returns 0 on success or -EINVAL on error.
  583. */
  584. int tavil_set_spkr_gain_offset(struct snd_soc_codec *codec, int offset)
  585. {
  586. struct tavil_priv *priv = snd_soc_codec_get_drvdata(codec);
  587. if (!priv)
  588. return -EINVAL;
  589. priv->swr.spkr_gain_offset = offset;
  590. return 0;
  591. }
  592. EXPORT_SYMBOL(tavil_set_spkr_gain_offset);
  593. /**
  594. * tavil_set_spkr_mode - Configures speaker compander and smartboost
  595. * settings based on speaker mode.
  596. *
  597. * @codec: codec instance
  598. * @mode: Indicates speaker configuration mode.
  599. *
  600. * Returns 0 on success or -EINVAL on error.
  601. */
  602. int tavil_set_spkr_mode(struct snd_soc_codec *codec, int mode)
  603. {
  604. struct tavil_priv *priv = snd_soc_codec_get_drvdata(codec);
  605. int i;
  606. const struct tavil_reg_mask_val *regs;
  607. int size;
  608. if (!priv)
  609. return -EINVAL;
  610. switch (mode) {
  611. case WCD934X_SPKR_MODE_1:
  612. regs = tavil_spkr_mode1;
  613. size = ARRAY_SIZE(tavil_spkr_mode1);
  614. break;
  615. default:
  616. regs = tavil_spkr_default;
  617. size = ARRAY_SIZE(tavil_spkr_default);
  618. break;
  619. }
  620. priv->swr.spkr_mode = mode;
  621. for (i = 0; i < size; i++)
  622. snd_soc_update_bits(codec, regs[i].reg,
  623. regs[i].mask, regs[i].val);
  624. return 0;
  625. }
  626. EXPORT_SYMBOL(tavil_set_spkr_mode);
  627. /**
  628. * tavil_get_afe_config - returns specific codec configuration to afe to write
  629. *
  630. * @codec: codec instance
  631. * @config_type: Indicates type of configuration to write.
  632. */
  633. void *tavil_get_afe_config(struct snd_soc_codec *codec,
  634. enum afe_config_type config_type)
  635. {
  636. struct tavil_priv *priv = snd_soc_codec_get_drvdata(codec);
  637. switch (config_type) {
  638. case AFE_SLIMBUS_SLAVE_CONFIG:
  639. return &priv->slimbus_slave_cfg;
  640. case AFE_CDC_REGISTERS_CONFIG:
  641. return &tavil_audio_reg_cfg;
  642. case AFE_SLIMBUS_SLAVE_PORT_CONFIG:
  643. return &tavil_slimbus_slave_port_cfg;
  644. case AFE_AANC_VERSION:
  645. return &tavil_cdc_aanc_version;
  646. case AFE_CDC_REGISTER_PAGE_CONFIG:
  647. return &tavil_cdc_reg_page_cfg;
  648. default:
  649. dev_info(codec->dev, "%s: Unknown config_type 0x%x\n",
  650. __func__, config_type);
  651. return NULL;
  652. }
  653. }
  654. EXPORT_SYMBOL(tavil_get_afe_config);
  655. static bool is_tavil_playback_dai(int dai_id)
  656. {
  657. if ((dai_id == AIF1_PB) || (dai_id == AIF2_PB) ||
  658. (dai_id == AIF3_PB) || (dai_id == AIF4_PB))
  659. return true;
  660. return false;
  661. }
  662. static int tavil_find_playback_dai_id_for_port(int port_id,
  663. struct tavil_priv *tavil)
  664. {
  665. struct wcd9xxx_codec_dai_data *dai;
  666. struct wcd9xxx_ch *ch;
  667. int i, slv_port_id;
  668. for (i = AIF1_PB; i < NUM_CODEC_DAIS; i++) {
  669. if (!is_tavil_playback_dai(i))
  670. continue;
  671. dai = &tavil->dai[i];
  672. list_for_each_entry(ch, &dai->wcd9xxx_ch_list, list) {
  673. slv_port_id = wcd9xxx_get_slave_port(ch->ch_num);
  674. if ((slv_port_id > 0) && (slv_port_id == port_id))
  675. return i;
  676. }
  677. }
  678. return -EINVAL;
  679. }
  680. static void tavil_vote_svs(struct tavil_priv *tavil, bool vote)
  681. {
  682. struct wcd9xxx *wcd9xxx;
  683. wcd9xxx = tavil->wcd9xxx;
  684. mutex_lock(&tavil->svs_mutex);
  685. if (vote) {
  686. tavil->svs_ref_cnt++;
  687. if (tavil->svs_ref_cnt == 1)
  688. regmap_update_bits(wcd9xxx->regmap,
  689. WCD934X_CPE_SS_PWR_SYS_PSTATE_CTL_0,
  690. 0x01, 0x01);
  691. } else {
  692. /* Do not decrement ref count if it is already 0 */
  693. if (tavil->svs_ref_cnt == 0)
  694. goto done;
  695. tavil->svs_ref_cnt--;
  696. if (tavil->svs_ref_cnt == 0)
  697. regmap_update_bits(wcd9xxx->regmap,
  698. WCD934X_CPE_SS_PWR_SYS_PSTATE_CTL_0,
  699. 0x01, 0x00);
  700. }
  701. done:
  702. dev_dbg(tavil->dev, "%s: vote = %s, updated ref cnt = %u\n", __func__,
  703. vote ? "vote" : "Unvote", tavil->svs_ref_cnt);
  704. mutex_unlock(&tavil->svs_mutex);
  705. }
  706. static int tavil_get_anc_slot(struct snd_kcontrol *kcontrol,
  707. struct snd_ctl_elem_value *ucontrol)
  708. {
  709. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  710. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  711. ucontrol->value.integer.value[0] = tavil->anc_slot;
  712. return 0;
  713. }
  714. static int tavil_put_anc_slot(struct snd_kcontrol *kcontrol,
  715. struct snd_ctl_elem_value *ucontrol)
  716. {
  717. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  718. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  719. tavil->anc_slot = ucontrol->value.integer.value[0];
  720. return 0;
  721. }
  722. static int tavil_get_anc_func(struct snd_kcontrol *kcontrol,
  723. struct snd_ctl_elem_value *ucontrol)
  724. {
  725. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  726. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  727. ucontrol->value.integer.value[0] = (tavil->anc_func == true ? 1 : 0);
  728. return 0;
  729. }
  730. static int tavil_put_anc_func(struct snd_kcontrol *kcontrol,
  731. struct snd_ctl_elem_value *ucontrol)
  732. {
  733. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  734. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  735. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  736. mutex_lock(&tavil->codec_mutex);
  737. tavil->anc_func = (!ucontrol->value.integer.value[0] ? false : true);
  738. dev_dbg(codec->dev, "%s: anc_func %x", __func__, tavil->anc_func);
  739. if (tavil->anc_func == true) {
  740. snd_soc_dapm_enable_pin(dapm, "ANC EAR PA");
  741. snd_soc_dapm_enable_pin(dapm, "ANC EAR");
  742. snd_soc_dapm_enable_pin(dapm, "ANC SPK1 PA");
  743. snd_soc_dapm_enable_pin(dapm, "ANC HPHL PA");
  744. snd_soc_dapm_enable_pin(dapm, "ANC HPHR PA");
  745. snd_soc_dapm_enable_pin(dapm, "ANC HPHL");
  746. snd_soc_dapm_enable_pin(dapm, "ANC HPHR");
  747. snd_soc_dapm_disable_pin(dapm, "EAR PA");
  748. snd_soc_dapm_disable_pin(dapm, "EAR");
  749. snd_soc_dapm_disable_pin(dapm, "HPHL PA");
  750. snd_soc_dapm_disable_pin(dapm, "HPHR PA");
  751. snd_soc_dapm_disable_pin(dapm, "HPHL");
  752. snd_soc_dapm_disable_pin(dapm, "HPHR");
  753. } else {
  754. snd_soc_dapm_disable_pin(dapm, "ANC EAR PA");
  755. snd_soc_dapm_disable_pin(dapm, "ANC EAR");
  756. snd_soc_dapm_disable_pin(dapm, "ANC SPK1 PA");
  757. snd_soc_dapm_disable_pin(dapm, "ANC HPHL PA");
  758. snd_soc_dapm_disable_pin(dapm, "ANC HPHR PA");
  759. snd_soc_dapm_disable_pin(dapm, "ANC HPHL");
  760. snd_soc_dapm_disable_pin(dapm, "ANC HPHR");
  761. snd_soc_dapm_enable_pin(dapm, "EAR PA");
  762. snd_soc_dapm_enable_pin(dapm, "EAR");
  763. snd_soc_dapm_enable_pin(dapm, "HPHL");
  764. snd_soc_dapm_enable_pin(dapm, "HPHR");
  765. snd_soc_dapm_enable_pin(dapm, "HPHL PA");
  766. snd_soc_dapm_enable_pin(dapm, "HPHR PA");
  767. }
  768. mutex_unlock(&tavil->codec_mutex);
  769. snd_soc_dapm_sync(dapm);
  770. return 0;
  771. }
  772. static int tavil_codec_enable_anc(struct snd_soc_dapm_widget *w,
  773. struct snd_kcontrol *kcontrol, int event)
  774. {
  775. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  776. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  777. const char *filename;
  778. const struct firmware *fw;
  779. int i;
  780. int ret = 0;
  781. int num_anc_slots;
  782. struct wcd9xxx_anc_header *anc_head;
  783. struct firmware_cal *hwdep_cal = NULL;
  784. u32 anc_writes_size = 0;
  785. u32 anc_cal_size = 0;
  786. int anc_size_remaining;
  787. u32 *anc_ptr;
  788. u16 reg;
  789. u8 mask, val;
  790. size_t cal_size;
  791. const void *data;
  792. if (!tavil->anc_func)
  793. return 0;
  794. switch (event) {
  795. case SND_SOC_DAPM_PRE_PMU:
  796. hwdep_cal = wcdcal_get_fw_cal(tavil->fw_data, WCD9XXX_ANC_CAL);
  797. if (hwdep_cal) {
  798. data = hwdep_cal->data;
  799. cal_size = hwdep_cal->size;
  800. dev_dbg(codec->dev, "%s: using hwdep calibration, cal_size %zd",
  801. __func__, cal_size);
  802. } else {
  803. filename = "WCD934X/WCD934X_anc.bin";
  804. ret = request_firmware(&fw, filename, codec->dev);
  805. if (ret < 0) {
  806. dev_err(codec->dev, "%s: Failed to acquire ANC data: %d\n",
  807. __func__, ret);
  808. return ret;
  809. }
  810. if (!fw) {
  811. dev_err(codec->dev, "%s: Failed to get anc fw\n",
  812. __func__);
  813. return -ENODEV;
  814. }
  815. data = fw->data;
  816. cal_size = fw->size;
  817. dev_dbg(codec->dev, "%s: using request_firmware calibration\n",
  818. __func__);
  819. }
  820. if (cal_size < sizeof(struct wcd9xxx_anc_header)) {
  821. dev_err(codec->dev, "%s: Invalid cal_size %zd\n",
  822. __func__, cal_size);
  823. ret = -EINVAL;
  824. goto err;
  825. }
  826. /* First number is the number of register writes */
  827. anc_head = (struct wcd9xxx_anc_header *)(data);
  828. anc_ptr = (u32 *)(data + sizeof(struct wcd9xxx_anc_header));
  829. anc_size_remaining = cal_size -
  830. sizeof(struct wcd9xxx_anc_header);
  831. num_anc_slots = anc_head->num_anc_slots;
  832. if (tavil->anc_slot >= num_anc_slots) {
  833. dev_err(codec->dev, "%s: Invalid ANC slot selected\n",
  834. __func__);
  835. ret = -EINVAL;
  836. goto err;
  837. }
  838. for (i = 0; i < num_anc_slots; i++) {
  839. if (anc_size_remaining < WCD934X_PACKED_REG_SIZE) {
  840. dev_err(codec->dev, "%s: Invalid register format\n",
  841. __func__);
  842. ret = -EINVAL;
  843. goto err;
  844. }
  845. anc_writes_size = (u32)(*anc_ptr);
  846. anc_size_remaining -= sizeof(u32);
  847. anc_ptr += 1;
  848. if ((anc_writes_size * WCD934X_PACKED_REG_SIZE) >
  849. anc_size_remaining) {
  850. dev_err(codec->dev, "%s: Invalid register format\n",
  851. __func__);
  852. ret = -EINVAL;
  853. goto err;
  854. }
  855. if (tavil->anc_slot == i)
  856. break;
  857. anc_size_remaining -= (anc_writes_size *
  858. WCD934X_PACKED_REG_SIZE);
  859. anc_ptr += anc_writes_size;
  860. }
  861. if (i == num_anc_slots) {
  862. dev_err(codec->dev, "%s: Selected ANC slot not present\n",
  863. __func__);
  864. ret = -EINVAL;
  865. goto err;
  866. }
  867. anc_cal_size = anc_writes_size;
  868. for (i = 0; i < anc_writes_size; i++) {
  869. WCD934X_CODEC_UNPACK_ENTRY(anc_ptr[i], reg, mask, val);
  870. snd_soc_write(codec, reg, (val & mask));
  871. }
  872. /* Rate converter clk enable and set bypass mode */
  873. if (!strcmp(w->name, "RX INT0 DAC") ||
  874. !strcmp(w->name, "RX INT1 DAC") ||
  875. !strcmp(w->name, "ANC SPK1 PA")) {
  876. snd_soc_update_bits(codec,
  877. WCD934X_CDC_ANC0_RC_COMMON_CTL,
  878. 0x05, 0x05);
  879. if (!strcmp(w->name, "RX INT1 DAC")) {
  880. snd_soc_update_bits(codec,
  881. WCD934X_CDC_ANC0_FIFO_COMMON_CTL,
  882. 0x66, 0x66);
  883. }
  884. } else if (!strcmp(w->name, "RX INT2 DAC")) {
  885. snd_soc_update_bits(codec,
  886. WCD934X_CDC_ANC1_RC_COMMON_CTL,
  887. 0x05, 0x05);
  888. snd_soc_update_bits(codec,
  889. WCD934X_CDC_ANC1_FIFO_COMMON_CTL,
  890. 0x66, 0x66);
  891. }
  892. if (!strcmp(w->name, "RX INT1 DAC"))
  893. snd_soc_update_bits(codec,
  894. WCD934X_CDC_ANC0_CLK_RESET_CTL, 0x08, 0x08);
  895. else if (!strcmp(w->name, "RX INT2 DAC"))
  896. snd_soc_update_bits(codec,
  897. WCD934X_CDC_ANC1_CLK_RESET_CTL, 0x08, 0x08);
  898. if (!hwdep_cal)
  899. release_firmware(fw);
  900. break;
  901. case SND_SOC_DAPM_POST_PMU:
  902. if (!strcmp(w->name, "ANC HPHL PA") ||
  903. !strcmp(w->name, "ANC HPHR PA")) {
  904. /* Remove ANC Rx from reset */
  905. snd_soc_update_bits(codec,
  906. WCD934X_CDC_ANC0_CLK_RESET_CTL,
  907. 0x08, 0x00);
  908. snd_soc_update_bits(codec,
  909. WCD934X_CDC_ANC1_CLK_RESET_CTL,
  910. 0x08, 0x00);
  911. }
  912. break;
  913. case SND_SOC_DAPM_POST_PMD:
  914. snd_soc_update_bits(codec, WCD934X_CDC_ANC0_RC_COMMON_CTL,
  915. 0x05, 0x00);
  916. if (!strcmp(w->name, "ANC EAR PA") ||
  917. !strcmp(w->name, "ANC SPK1 PA") ||
  918. !strcmp(w->name, "ANC HPHL PA")) {
  919. snd_soc_update_bits(codec, WCD934X_CDC_ANC0_MODE_1_CTL,
  920. 0x30, 0x00);
  921. msleep(50);
  922. snd_soc_update_bits(codec, WCD934X_CDC_ANC0_MODE_1_CTL,
  923. 0x01, 0x00);
  924. snd_soc_update_bits(codec,
  925. WCD934X_CDC_ANC0_CLK_RESET_CTL,
  926. 0x38, 0x38);
  927. snd_soc_update_bits(codec,
  928. WCD934X_CDC_ANC0_CLK_RESET_CTL,
  929. 0x07, 0x00);
  930. snd_soc_update_bits(codec,
  931. WCD934X_CDC_ANC0_CLK_RESET_CTL,
  932. 0x38, 0x00);
  933. } else if (!strcmp(w->name, "ANC HPHR PA")) {
  934. snd_soc_update_bits(codec, WCD934X_CDC_ANC1_MODE_1_CTL,
  935. 0x30, 0x00);
  936. msleep(50);
  937. snd_soc_update_bits(codec, WCD934X_CDC_ANC1_MODE_1_CTL,
  938. 0x01, 0x00);
  939. snd_soc_update_bits(codec,
  940. WCD934X_CDC_ANC1_CLK_RESET_CTL,
  941. 0x38, 0x38);
  942. snd_soc_update_bits(codec,
  943. WCD934X_CDC_ANC1_CLK_RESET_CTL,
  944. 0x07, 0x00);
  945. snd_soc_update_bits(codec,
  946. WCD934X_CDC_ANC1_CLK_RESET_CTL,
  947. 0x38, 0x00);
  948. }
  949. break;
  950. }
  951. return 0;
  952. err:
  953. if (!hwdep_cal)
  954. release_firmware(fw);
  955. return ret;
  956. }
  957. static int tavil_get_clkmode(struct snd_kcontrol *kcontrol,
  958. struct snd_ctl_elem_value *ucontrol)
  959. {
  960. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  961. struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec);
  962. if (test_bit(CLK_MODE, &tavil_p->status_mask))
  963. ucontrol->value.enumerated.item[0] = 1;
  964. else
  965. ucontrol->value.enumerated.item[0] = 0;
  966. dev_dbg(codec->dev, "%s: is_low_power_clock: %s\n", __func__,
  967. test_bit(CLK_MODE, &tavil_p->status_mask) ? "true" : "false");
  968. return 0;
  969. }
  970. static int tavil_put_clkmode(struct snd_kcontrol *kcontrol,
  971. struct snd_ctl_elem_value *ucontrol)
  972. {
  973. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  974. struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec);
  975. if (ucontrol->value.enumerated.item[0])
  976. set_bit(CLK_MODE, &tavil_p->status_mask);
  977. else
  978. clear_bit(CLK_MODE, &tavil_p->status_mask);
  979. dev_dbg(codec->dev, "%s: is_low_power_clock: %s\n", __func__,
  980. test_bit(CLK_MODE, &tavil_p->status_mask) ? "true" : "false");
  981. return 0;
  982. }
  983. static int tavil_vi_feed_mixer_get(struct snd_kcontrol *kcontrol,
  984. struct snd_ctl_elem_value *ucontrol)
  985. {
  986. struct snd_soc_dapm_widget *widget =
  987. snd_soc_dapm_kcontrol_widget(kcontrol);
  988. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  989. struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec);
  990. ucontrol->value.integer.value[0] = tavil_p->vi_feed_value;
  991. return 0;
  992. }
  993. static int tavil_vi_feed_mixer_put(struct snd_kcontrol *kcontrol,
  994. struct snd_ctl_elem_value *ucontrol)
  995. {
  996. struct snd_soc_dapm_widget *widget =
  997. snd_soc_dapm_kcontrol_widget(kcontrol);
  998. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  999. struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec);
  1000. struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent);
  1001. struct soc_multi_mixer_control *mixer =
  1002. ((struct soc_multi_mixer_control *)kcontrol->private_value);
  1003. u32 dai_id = widget->shift;
  1004. u32 port_id = mixer->shift;
  1005. u32 enable = ucontrol->value.integer.value[0];
  1006. dev_dbg(codec->dev, "%s: enable: %d, port_id:%d, dai_id: %d\n",
  1007. __func__, enable, port_id, dai_id);
  1008. tavil_p->vi_feed_value = ucontrol->value.integer.value[0];
  1009. mutex_lock(&tavil_p->codec_mutex);
  1010. if (enable) {
  1011. if (port_id == WCD934X_TX14 && !test_bit(VI_SENSE_1,
  1012. &tavil_p->status_mask)) {
  1013. list_add_tail(&core->tx_chs[WCD934X_TX14].list,
  1014. &tavil_p->dai[dai_id].wcd9xxx_ch_list);
  1015. set_bit(VI_SENSE_1, &tavil_p->status_mask);
  1016. }
  1017. if (port_id == WCD934X_TX15 && !test_bit(VI_SENSE_2,
  1018. &tavil_p->status_mask)) {
  1019. list_add_tail(&core->tx_chs[WCD934X_TX15].list,
  1020. &tavil_p->dai[dai_id].wcd9xxx_ch_list);
  1021. set_bit(VI_SENSE_2, &tavil_p->status_mask);
  1022. }
  1023. } else {
  1024. if (port_id == WCD934X_TX14 && test_bit(VI_SENSE_1,
  1025. &tavil_p->status_mask)) {
  1026. list_del_init(&core->tx_chs[WCD934X_TX14].list);
  1027. clear_bit(VI_SENSE_1, &tavil_p->status_mask);
  1028. }
  1029. if (port_id == WCD934X_TX15 && test_bit(VI_SENSE_2,
  1030. &tavil_p->status_mask)) {
  1031. list_del_init(&core->tx_chs[WCD934X_TX15].list);
  1032. clear_bit(VI_SENSE_2, &tavil_p->status_mask);
  1033. }
  1034. }
  1035. mutex_unlock(&tavil_p->codec_mutex);
  1036. snd_soc_dapm_mixer_update_power(widget->dapm, kcontrol, enable, NULL);
  1037. return 0;
  1038. }
  1039. static int slim_tx_mixer_get(struct snd_kcontrol *kcontrol,
  1040. struct snd_ctl_elem_value *ucontrol)
  1041. {
  1042. struct snd_soc_dapm_widget *widget =
  1043. snd_soc_dapm_kcontrol_widget(kcontrol);
  1044. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  1045. struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec);
  1046. ucontrol->value.integer.value[0] = tavil_p->tx_port_value;
  1047. return 0;
  1048. }
  1049. static int slim_tx_mixer_put(struct snd_kcontrol *kcontrol,
  1050. struct snd_ctl_elem_value *ucontrol)
  1051. {
  1052. struct snd_soc_dapm_widget *widget =
  1053. snd_soc_dapm_kcontrol_widget(kcontrol);
  1054. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  1055. struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec);
  1056. struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent);
  1057. struct snd_soc_dapm_update *update = NULL;
  1058. struct soc_multi_mixer_control *mixer =
  1059. ((struct soc_multi_mixer_control *)kcontrol->private_value);
  1060. u32 dai_id = widget->shift;
  1061. u32 port_id = mixer->shift;
  1062. u32 enable = ucontrol->value.integer.value[0];
  1063. u32 vtable;
  1064. dev_dbg(codec->dev, "%s: wname %s cname %s value %u shift %d item %ld\n",
  1065. __func__,
  1066. widget->name, ucontrol->id.name, tavil_p->tx_port_value,
  1067. widget->shift, ucontrol->value.integer.value[0]);
  1068. mutex_lock(&tavil_p->codec_mutex);
  1069. if (dai_id >= ARRAY_SIZE(vport_slim_check_table)) {
  1070. dev_err(codec->dev, "%s: dai_id: %d, out of bounds\n",
  1071. __func__, dai_id);
  1072. mutex_unlock(&tavil_p->codec_mutex);
  1073. return -EINVAL;
  1074. }
  1075. vtable = vport_slim_check_table[dai_id];
  1076. switch (dai_id) {
  1077. case AIF1_CAP:
  1078. case AIF2_CAP:
  1079. case AIF3_CAP:
  1080. /* only add to the list if value not set */
  1081. if (enable && !(tavil_p->tx_port_value & 1 << port_id)) {
  1082. if (wcd9xxx_tx_vport_validation(vtable, port_id,
  1083. tavil_p->dai, NUM_CODEC_DAIS)) {
  1084. dev_dbg(codec->dev, "%s: TX%u is used by other virtual port\n",
  1085. __func__, port_id);
  1086. mutex_unlock(&tavil_p->codec_mutex);
  1087. return 0;
  1088. }
  1089. tavil_p->tx_port_value |= 1 << port_id;
  1090. list_add_tail(&core->tx_chs[port_id].list,
  1091. &tavil_p->dai[dai_id].wcd9xxx_ch_list);
  1092. } else if (!enable && (tavil_p->tx_port_value &
  1093. 1 << port_id)) {
  1094. tavil_p->tx_port_value &= ~(1 << port_id);
  1095. list_del_init(&core->tx_chs[port_id].list);
  1096. } else {
  1097. if (enable)
  1098. dev_dbg(codec->dev, "%s: TX%u port is used by\n"
  1099. "this virtual port\n",
  1100. __func__, port_id);
  1101. else
  1102. dev_dbg(codec->dev, "%s: TX%u port is not used by\n"
  1103. "this virtual port\n",
  1104. __func__, port_id);
  1105. /* avoid update power function */
  1106. mutex_unlock(&tavil_p->codec_mutex);
  1107. return 0;
  1108. }
  1109. break;
  1110. case AIF4_MAD_TX:
  1111. break;
  1112. default:
  1113. dev_err(codec->dev, "Unknown AIF %d\n", dai_id);
  1114. mutex_unlock(&tavil_p->codec_mutex);
  1115. return -EINVAL;
  1116. }
  1117. dev_dbg(codec->dev, "%s: name %s sname %s updated value %u shift %d\n",
  1118. __func__, widget->name, widget->sname, tavil_p->tx_port_value,
  1119. widget->shift);
  1120. mutex_unlock(&tavil_p->codec_mutex);
  1121. snd_soc_dapm_mixer_update_power(widget->dapm, kcontrol, enable, update);
  1122. return 0;
  1123. }
  1124. static int slim_rx_mux_get(struct snd_kcontrol *kcontrol,
  1125. struct snd_ctl_elem_value *ucontrol)
  1126. {
  1127. struct snd_soc_dapm_widget *widget =
  1128. snd_soc_dapm_kcontrol_widget(kcontrol);
  1129. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  1130. struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec);
  1131. ucontrol->value.enumerated.item[0] =
  1132. tavil_p->rx_port_value[widget->shift];
  1133. return 0;
  1134. }
  1135. static int slim_rx_mux_put(struct snd_kcontrol *kcontrol,
  1136. struct snd_ctl_elem_value *ucontrol)
  1137. {
  1138. struct snd_soc_dapm_widget *widget =
  1139. snd_soc_dapm_kcontrol_widget(kcontrol);
  1140. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  1141. struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec);
  1142. struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent);
  1143. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1144. struct snd_soc_dapm_update *update = NULL;
  1145. unsigned int rx_port_value;
  1146. u32 port_id = widget->shift;
  1147. tavil_p->rx_port_value[port_id] = ucontrol->value.enumerated.item[0];
  1148. rx_port_value = tavil_p->rx_port_value[port_id];
  1149. mutex_lock(&tavil_p->codec_mutex);
  1150. dev_dbg(codec->dev, "%s: wname %s cname %s value %u shift %d item %ld\n",
  1151. __func__, widget->name, ucontrol->id.name,
  1152. rx_port_value, widget->shift,
  1153. ucontrol->value.integer.value[0]);
  1154. /* value need to match the Virtual port and AIF number */
  1155. switch (rx_port_value) {
  1156. case 0:
  1157. list_del_init(&core->rx_chs[port_id].list);
  1158. break;
  1159. case 1:
  1160. if (wcd9xxx_rx_vport_validation(port_id +
  1161. WCD934X_RX_PORT_START_NUMBER,
  1162. &tavil_p->dai[AIF1_PB].wcd9xxx_ch_list)) {
  1163. dev_dbg(codec->dev, "%s: RX%u is used by current requesting AIF_PB itself\n",
  1164. __func__, port_id);
  1165. goto rtn;
  1166. }
  1167. list_add_tail(&core->rx_chs[port_id].list,
  1168. &tavil_p->dai[AIF1_PB].wcd9xxx_ch_list);
  1169. break;
  1170. case 2:
  1171. if (wcd9xxx_rx_vport_validation(port_id +
  1172. WCD934X_RX_PORT_START_NUMBER,
  1173. &tavil_p->dai[AIF2_PB].wcd9xxx_ch_list)) {
  1174. dev_dbg(codec->dev, "%s: RX%u is used by current requesting AIF_PB itself\n",
  1175. __func__, port_id);
  1176. goto rtn;
  1177. }
  1178. list_add_tail(&core->rx_chs[port_id].list,
  1179. &tavil_p->dai[AIF2_PB].wcd9xxx_ch_list);
  1180. break;
  1181. case 3:
  1182. if (wcd9xxx_rx_vport_validation(port_id +
  1183. WCD934X_RX_PORT_START_NUMBER,
  1184. &tavil_p->dai[AIF3_PB].wcd9xxx_ch_list)) {
  1185. dev_dbg(codec->dev, "%s: RX%u is used by current requesting AIF_PB itself\n",
  1186. __func__, port_id);
  1187. goto rtn;
  1188. }
  1189. list_add_tail(&core->rx_chs[port_id].list,
  1190. &tavil_p->dai[AIF3_PB].wcd9xxx_ch_list);
  1191. break;
  1192. case 4:
  1193. if (wcd9xxx_rx_vport_validation(port_id +
  1194. WCD934X_RX_PORT_START_NUMBER,
  1195. &tavil_p->dai[AIF4_PB].wcd9xxx_ch_list)) {
  1196. dev_dbg(codec->dev, "%s: RX%u is used by current requesting AIF_PB itself\n",
  1197. __func__, port_id);
  1198. goto rtn;
  1199. }
  1200. list_add_tail(&core->rx_chs[port_id].list,
  1201. &tavil_p->dai[AIF4_PB].wcd9xxx_ch_list);
  1202. break;
  1203. default:
  1204. dev_err(codec->dev, "Unknown AIF %d\n", rx_port_value);
  1205. goto err;
  1206. }
  1207. rtn:
  1208. mutex_unlock(&tavil_p->codec_mutex);
  1209. snd_soc_dapm_mux_update_power(widget->dapm, kcontrol,
  1210. rx_port_value, e, update);
  1211. return 0;
  1212. err:
  1213. mutex_unlock(&tavil_p->codec_mutex);
  1214. return -EINVAL;
  1215. }
  1216. static void tavil_codec_enable_slim_port_intr(
  1217. struct wcd9xxx_codec_dai_data *dai,
  1218. struct snd_soc_codec *codec)
  1219. {
  1220. struct wcd9xxx_ch *ch;
  1221. int port_num = 0;
  1222. unsigned short reg = 0;
  1223. u8 val = 0;
  1224. struct tavil_priv *tavil_p;
  1225. if (!dai || !codec) {
  1226. pr_err("%s: Invalid params\n", __func__);
  1227. return;
  1228. }
  1229. tavil_p = snd_soc_codec_get_drvdata(codec);
  1230. list_for_each_entry(ch, &dai->wcd9xxx_ch_list, list) {
  1231. if (ch->port >= WCD934X_RX_PORT_START_NUMBER) {
  1232. port_num = ch->port - WCD934X_RX_PORT_START_NUMBER;
  1233. reg = WCD934X_SLIM_PGD_PORT_INT_RX_EN0 + (port_num / 8);
  1234. val = wcd9xxx_interface_reg_read(tavil_p->wcd9xxx,
  1235. reg);
  1236. if (!(val & BYTE_BIT_MASK(port_num))) {
  1237. val |= BYTE_BIT_MASK(port_num);
  1238. wcd9xxx_interface_reg_write(
  1239. tavil_p->wcd9xxx, reg, val);
  1240. val = wcd9xxx_interface_reg_read(
  1241. tavil_p->wcd9xxx, reg);
  1242. }
  1243. } else {
  1244. port_num = ch->port;
  1245. reg = WCD934X_SLIM_PGD_PORT_INT_TX_EN0 + (port_num / 8);
  1246. val = wcd9xxx_interface_reg_read(tavil_p->wcd9xxx,
  1247. reg);
  1248. if (!(val & BYTE_BIT_MASK(port_num))) {
  1249. val |= BYTE_BIT_MASK(port_num);
  1250. wcd9xxx_interface_reg_write(tavil_p->wcd9xxx,
  1251. reg, val);
  1252. val = wcd9xxx_interface_reg_read(
  1253. tavil_p->wcd9xxx, reg);
  1254. }
  1255. }
  1256. }
  1257. }
  1258. static int tavil_codec_enable_slim_chmask(struct wcd9xxx_codec_dai_data *dai,
  1259. bool up)
  1260. {
  1261. int ret = 0;
  1262. struct wcd9xxx_ch *ch;
  1263. if (up) {
  1264. list_for_each_entry(ch, &dai->wcd9xxx_ch_list, list) {
  1265. ret = wcd9xxx_get_slave_port(ch->ch_num);
  1266. if (ret < 0) {
  1267. pr_err("%s: Invalid slave port ID: %d\n",
  1268. __func__, ret);
  1269. ret = -EINVAL;
  1270. } else {
  1271. set_bit(ret, &dai->ch_mask);
  1272. }
  1273. }
  1274. } else {
  1275. ret = wait_event_timeout(dai->dai_wait, (dai->ch_mask == 0),
  1276. msecs_to_jiffies(
  1277. WCD934X_SLIM_CLOSE_TIMEOUT));
  1278. if (!ret) {
  1279. pr_err("%s: Slim close tx/rx wait timeout, ch_mask:0x%lx\n",
  1280. __func__, dai->ch_mask);
  1281. ret = -ETIMEDOUT;
  1282. } else {
  1283. ret = 0;
  1284. }
  1285. }
  1286. return ret;
  1287. }
  1288. static void tavil_codec_mute_dsd(struct snd_soc_codec *codec,
  1289. struct list_head *ch_list)
  1290. {
  1291. u8 dsd0_in;
  1292. u8 dsd1_in;
  1293. struct wcd9xxx_ch *ch;
  1294. /* Read DSD Input Ports */
  1295. dsd0_in = (snd_soc_read(codec, WCD934X_CDC_DSD0_CFG0) & 0x3C) >> 2;
  1296. dsd1_in = (snd_soc_read(codec, WCD934X_CDC_DSD1_CFG0) & 0x3C) >> 2;
  1297. if ((dsd0_in == 0) && (dsd1_in == 0))
  1298. return;
  1299. /*
  1300. * Check if the ports getting disabled are connected to DSD inputs.
  1301. * If connected, enable DSD mute to avoid DC entering into DSD Filter
  1302. */
  1303. list_for_each_entry(ch, ch_list, list) {
  1304. if (ch->port == (dsd0_in + WCD934X_RX_PORT_START_NUMBER - 1))
  1305. snd_soc_update_bits(codec, WCD934X_CDC_DSD0_CFG2,
  1306. 0x04, 0x04);
  1307. if (ch->port == (dsd1_in + WCD934X_RX_PORT_START_NUMBER - 1))
  1308. snd_soc_update_bits(codec, WCD934X_CDC_DSD1_CFG2,
  1309. 0x04, 0x04);
  1310. }
  1311. }
  1312. static int tavil_codec_enable_slimrx(struct snd_soc_dapm_widget *w,
  1313. struct snd_kcontrol *kcontrol,
  1314. int event)
  1315. {
  1316. struct wcd9xxx *core;
  1317. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1318. struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec);
  1319. int ret = 0;
  1320. struct wcd9xxx_codec_dai_data *dai;
  1321. struct tavil_dsd_config *dsd_conf = tavil_p->dsd_config;
  1322. core = dev_get_drvdata(codec->dev->parent);
  1323. dev_dbg(codec->dev, "%s: event called! codec name %s num_dai %d\n"
  1324. "stream name %s event %d\n",
  1325. __func__, codec->component.name,
  1326. codec->component.num_dai, w->sname, event);
  1327. dai = &tavil_p->dai[w->shift];
  1328. dev_dbg(codec->dev, "%s: w->name %s w->shift %d event %d\n",
  1329. __func__, w->name, w->shift, event);
  1330. switch (event) {
  1331. case SND_SOC_DAPM_POST_PMU:
  1332. dai->bus_down_in_recovery = false;
  1333. tavil_codec_enable_slim_port_intr(dai, codec);
  1334. (void) tavil_codec_enable_slim_chmask(dai, true);
  1335. ret = wcd9xxx_cfg_slim_sch_rx(core, &dai->wcd9xxx_ch_list,
  1336. dai->rate, dai->bit_width,
  1337. &dai->grph);
  1338. break;
  1339. case SND_SOC_DAPM_POST_PMD:
  1340. if (dsd_conf)
  1341. tavil_codec_mute_dsd(codec, &dai->wcd9xxx_ch_list);
  1342. ret = wcd9xxx_disconnect_port(core, &dai->wcd9xxx_ch_list,
  1343. dai->grph);
  1344. dev_dbg(codec->dev, "%s: Disconnect RX port, ret = %d\n",
  1345. __func__, ret);
  1346. if (!dai->bus_down_in_recovery)
  1347. ret = tavil_codec_enable_slim_chmask(dai, false);
  1348. else
  1349. dev_dbg(codec->dev,
  1350. "%s: bus in recovery skip enable slim_chmask",
  1351. __func__);
  1352. ret = wcd9xxx_close_slim_sch_rx(core, &dai->wcd9xxx_ch_list,
  1353. dai->grph);
  1354. break;
  1355. }
  1356. return ret;
  1357. }
  1358. static int tavil_codec_enable_slimtx(struct snd_soc_dapm_widget *w,
  1359. struct snd_kcontrol *kcontrol,
  1360. int event)
  1361. {
  1362. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1363. struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec);
  1364. struct wcd9xxx_codec_dai_data *dai;
  1365. struct wcd9xxx *core;
  1366. int ret = 0;
  1367. dev_dbg(codec->dev,
  1368. "%s: w->name %s, w->shift = %d, num_dai %d stream name %s\n",
  1369. __func__, w->name, w->shift,
  1370. codec->component.num_dai, w->sname);
  1371. dai = &tavil_p->dai[w->shift];
  1372. core = dev_get_drvdata(codec->dev->parent);
  1373. switch (event) {
  1374. case SND_SOC_DAPM_POST_PMU:
  1375. dai->bus_down_in_recovery = false;
  1376. tavil_codec_enable_slim_port_intr(dai, codec);
  1377. (void) tavil_codec_enable_slim_chmask(dai, true);
  1378. ret = wcd9xxx_cfg_slim_sch_tx(core, &dai->wcd9xxx_ch_list,
  1379. dai->rate, dai->bit_width,
  1380. &dai->grph);
  1381. break;
  1382. case SND_SOC_DAPM_POST_PMD:
  1383. ret = wcd9xxx_close_slim_sch_tx(core, &dai->wcd9xxx_ch_list,
  1384. dai->grph);
  1385. if (!dai->bus_down_in_recovery)
  1386. ret = tavil_codec_enable_slim_chmask(dai, false);
  1387. if (ret < 0) {
  1388. ret = wcd9xxx_disconnect_port(core,
  1389. &dai->wcd9xxx_ch_list,
  1390. dai->grph);
  1391. dev_dbg(codec->dev, "%s: Disconnect RX port, ret = %d\n",
  1392. __func__, ret);
  1393. }
  1394. break;
  1395. }
  1396. return ret;
  1397. }
  1398. static int tavil_codec_enable_slimvi_feedback(struct snd_soc_dapm_widget *w,
  1399. struct snd_kcontrol *kcontrol,
  1400. int event)
  1401. {
  1402. struct wcd9xxx *core = NULL;
  1403. struct snd_soc_codec *codec = NULL;
  1404. struct tavil_priv *tavil_p = NULL;
  1405. int ret = 0;
  1406. struct wcd9xxx_codec_dai_data *dai = NULL;
  1407. codec = snd_soc_dapm_to_codec(w->dapm);
  1408. tavil_p = snd_soc_codec_get_drvdata(codec);
  1409. core = dev_get_drvdata(codec->dev->parent);
  1410. dev_dbg(codec->dev,
  1411. "%s: num_dai %d stream name %s w->name %s event %d shift %d\n",
  1412. __func__, codec->component.num_dai, w->sname,
  1413. w->name, event, w->shift);
  1414. if (w->shift != AIF4_VIFEED) {
  1415. pr_err("%s Error in enabling the tx path\n", __func__);
  1416. ret = -EINVAL;
  1417. goto done;
  1418. }
  1419. dai = &tavil_p->dai[w->shift];
  1420. switch (event) {
  1421. case SND_SOC_DAPM_POST_PMU:
  1422. if (test_bit(VI_SENSE_1, &tavil_p->status_mask)) {
  1423. dev_dbg(codec->dev, "%s: spkr1 enabled\n", __func__);
  1424. /* Enable V&I sensing */
  1425. snd_soc_update_bits(codec,
  1426. WCD934X_CDC_TX9_SPKR_PROT_PATH_CTL, 0x20, 0x20);
  1427. snd_soc_update_bits(codec,
  1428. WCD934X_CDC_TX10_SPKR_PROT_PATH_CTL, 0x20,
  1429. 0x20);
  1430. snd_soc_update_bits(codec,
  1431. WCD934X_CDC_TX9_SPKR_PROT_PATH_CTL, 0x0F, 0x00);
  1432. snd_soc_update_bits(codec,
  1433. WCD934X_CDC_TX10_SPKR_PROT_PATH_CTL, 0x0F,
  1434. 0x00);
  1435. snd_soc_update_bits(codec,
  1436. WCD934X_CDC_TX9_SPKR_PROT_PATH_CTL, 0x10, 0x10);
  1437. snd_soc_update_bits(codec,
  1438. WCD934X_CDC_TX10_SPKR_PROT_PATH_CTL, 0x10,
  1439. 0x10);
  1440. snd_soc_update_bits(codec,
  1441. WCD934X_CDC_TX9_SPKR_PROT_PATH_CTL, 0x20, 0x00);
  1442. snd_soc_update_bits(codec,
  1443. WCD934X_CDC_TX10_SPKR_PROT_PATH_CTL, 0x20,
  1444. 0x00);
  1445. }
  1446. if (test_bit(VI_SENSE_2, &tavil_p->status_mask)) {
  1447. pr_debug("%s: spkr2 enabled\n", __func__);
  1448. /* Enable V&I sensing */
  1449. snd_soc_update_bits(codec,
  1450. WCD934X_CDC_TX11_SPKR_PROT_PATH_CTL, 0x20,
  1451. 0x20);
  1452. snd_soc_update_bits(codec,
  1453. WCD934X_CDC_TX12_SPKR_PROT_PATH_CTL, 0x20,
  1454. 0x20);
  1455. snd_soc_update_bits(codec,
  1456. WCD934X_CDC_TX11_SPKR_PROT_PATH_CTL, 0x0F,
  1457. 0x00);
  1458. snd_soc_update_bits(codec,
  1459. WCD934X_CDC_TX12_SPKR_PROT_PATH_CTL, 0x0F,
  1460. 0x00);
  1461. snd_soc_update_bits(codec,
  1462. WCD934X_CDC_TX11_SPKR_PROT_PATH_CTL, 0x10,
  1463. 0x10);
  1464. snd_soc_update_bits(codec,
  1465. WCD934X_CDC_TX12_SPKR_PROT_PATH_CTL, 0x10,
  1466. 0x10);
  1467. snd_soc_update_bits(codec,
  1468. WCD934X_CDC_TX11_SPKR_PROT_PATH_CTL, 0x20,
  1469. 0x00);
  1470. snd_soc_update_bits(codec,
  1471. WCD934X_CDC_TX12_SPKR_PROT_PATH_CTL, 0x20,
  1472. 0x00);
  1473. }
  1474. dai->bus_down_in_recovery = false;
  1475. tavil_codec_enable_slim_port_intr(dai, codec);
  1476. (void) tavil_codec_enable_slim_chmask(dai, true);
  1477. ret = wcd9xxx_cfg_slim_sch_tx(core, &dai->wcd9xxx_ch_list,
  1478. dai->rate, dai->bit_width,
  1479. &dai->grph);
  1480. break;
  1481. case SND_SOC_DAPM_POST_PMD:
  1482. ret = wcd9xxx_close_slim_sch_tx(core, &dai->wcd9xxx_ch_list,
  1483. dai->grph);
  1484. if (ret)
  1485. dev_err(codec->dev, "%s error in close_slim_sch_tx %d\n",
  1486. __func__, ret);
  1487. if (!dai->bus_down_in_recovery)
  1488. ret = tavil_codec_enable_slim_chmask(dai, false);
  1489. if (ret < 0) {
  1490. ret = wcd9xxx_disconnect_port(core,
  1491. &dai->wcd9xxx_ch_list,
  1492. dai->grph);
  1493. dev_dbg(codec->dev, "%s: Disconnect TX port, ret = %d\n",
  1494. __func__, ret);
  1495. }
  1496. if (test_bit(VI_SENSE_1, &tavil_p->status_mask)) {
  1497. /* Disable V&I sensing */
  1498. dev_dbg(codec->dev, "%s: spkr1 disabled\n", __func__);
  1499. snd_soc_update_bits(codec,
  1500. WCD934X_CDC_TX9_SPKR_PROT_PATH_CTL, 0x20, 0x20);
  1501. snd_soc_update_bits(codec,
  1502. WCD934X_CDC_TX10_SPKR_PROT_PATH_CTL, 0x20,
  1503. 0x20);
  1504. snd_soc_update_bits(codec,
  1505. WCD934X_CDC_TX9_SPKR_PROT_PATH_CTL, 0x10, 0x00);
  1506. snd_soc_update_bits(codec,
  1507. WCD934X_CDC_TX10_SPKR_PROT_PATH_CTL, 0x10,
  1508. 0x00);
  1509. }
  1510. if (test_bit(VI_SENSE_2, &tavil_p->status_mask)) {
  1511. /* Disable V&I sensing */
  1512. dev_dbg(codec->dev, "%s: spkr2 disabled\n", __func__);
  1513. snd_soc_update_bits(codec,
  1514. WCD934X_CDC_TX11_SPKR_PROT_PATH_CTL, 0x20,
  1515. 0x20);
  1516. snd_soc_update_bits(codec,
  1517. WCD934X_CDC_TX12_SPKR_PROT_PATH_CTL, 0x20,
  1518. 0x20);
  1519. snd_soc_update_bits(codec,
  1520. WCD934X_CDC_TX11_SPKR_PROT_PATH_CTL, 0x10,
  1521. 0x00);
  1522. snd_soc_update_bits(codec,
  1523. WCD934X_CDC_TX12_SPKR_PROT_PATH_CTL, 0x10,
  1524. 0x00);
  1525. }
  1526. break;
  1527. }
  1528. done:
  1529. return ret;
  1530. }
  1531. static int tavil_codec_enable_rx_bias(struct snd_soc_dapm_widget *w,
  1532. struct snd_kcontrol *kcontrol, int event)
  1533. {
  1534. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1535. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  1536. dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
  1537. switch (event) {
  1538. case SND_SOC_DAPM_PRE_PMU:
  1539. tavil->rx_bias_count++;
  1540. if (tavil->rx_bias_count == 1) {
  1541. snd_soc_update_bits(codec, WCD934X_ANA_RX_SUPPLIES,
  1542. 0x01, 0x01);
  1543. }
  1544. break;
  1545. case SND_SOC_DAPM_POST_PMD:
  1546. tavil->rx_bias_count--;
  1547. if (!tavil->rx_bias_count)
  1548. snd_soc_update_bits(codec, WCD934X_ANA_RX_SUPPLIES,
  1549. 0x01, 0x00);
  1550. break;
  1551. };
  1552. dev_dbg(codec->dev, "%s: Current RX BIAS user count: %d\n", __func__,
  1553. tavil->rx_bias_count);
  1554. return 0;
  1555. }
  1556. static void tavil_spk_anc_update_callback(struct work_struct *work)
  1557. {
  1558. struct spk_anc_work *spk_anc_dwork;
  1559. struct tavil_priv *tavil;
  1560. struct delayed_work *delayed_work;
  1561. struct snd_soc_codec *codec;
  1562. delayed_work = to_delayed_work(work);
  1563. spk_anc_dwork = container_of(delayed_work, struct spk_anc_work, dwork);
  1564. tavil = spk_anc_dwork->tavil;
  1565. codec = tavil->codec;
  1566. snd_soc_update_bits(codec, WCD934X_CDC_RX7_RX_PATH_CFG0, 0x10, 0x10);
  1567. }
  1568. static int tavil_codec_enable_spkr_anc(struct snd_soc_dapm_widget *w,
  1569. struct snd_kcontrol *kcontrol,
  1570. int event)
  1571. {
  1572. int ret = 0;
  1573. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1574. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  1575. if (!tavil->anc_func)
  1576. return 0;
  1577. dev_dbg(codec->dev, "%s: w: %s event: %d anc: %d\n", __func__,
  1578. w->name, event, tavil->anc_func);
  1579. switch (event) {
  1580. case SND_SOC_DAPM_PRE_PMU:
  1581. ret = tavil_codec_enable_anc(w, kcontrol, event);
  1582. schedule_delayed_work(&tavil->spk_anc_dwork.dwork,
  1583. msecs_to_jiffies(spk_anc_en_delay));
  1584. break;
  1585. case SND_SOC_DAPM_POST_PMD:
  1586. cancel_delayed_work_sync(&tavil->spk_anc_dwork.dwork);
  1587. snd_soc_update_bits(codec, WCD934X_CDC_RX7_RX_PATH_CFG0,
  1588. 0x10, 0x00);
  1589. ret = tavil_codec_enable_anc(w, kcontrol, event);
  1590. break;
  1591. }
  1592. return ret;
  1593. }
  1594. static int tavil_codec_enable_ear_pa(struct snd_soc_dapm_widget *w,
  1595. struct snd_kcontrol *kcontrol,
  1596. int event)
  1597. {
  1598. int ret = 0;
  1599. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1600. dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
  1601. switch (event) {
  1602. case SND_SOC_DAPM_POST_PMU:
  1603. /*
  1604. * 5ms sleep is required after PA is enabled as per
  1605. * HW requirement
  1606. */
  1607. usleep_range(5000, 5500);
  1608. snd_soc_update_bits(codec, WCD934X_CDC_RX0_RX_PATH_CTL,
  1609. 0x10, 0x00);
  1610. /* Remove mix path mute if it is enabled */
  1611. if ((snd_soc_read(codec, WCD934X_CDC_RX0_RX_PATH_MIX_CTL)) &
  1612. 0x10)
  1613. snd_soc_update_bits(codec,
  1614. WCD934X_CDC_RX0_RX_PATH_MIX_CTL,
  1615. 0x10, 0x00);
  1616. break;
  1617. case SND_SOC_DAPM_POST_PMD:
  1618. /*
  1619. * 5ms sleep is required after PA is disabled as per
  1620. * HW requirement
  1621. */
  1622. usleep_range(5000, 5500);
  1623. if (!(strcmp(w->name, "ANC EAR PA"))) {
  1624. ret = tavil_codec_enable_anc(w, kcontrol, event);
  1625. snd_soc_update_bits(codec, WCD934X_CDC_RX0_RX_PATH_CFG0,
  1626. 0x10, 0x00);
  1627. }
  1628. break;
  1629. };
  1630. return ret;
  1631. }
  1632. static void tavil_codec_override(struct snd_soc_codec *codec, int mode,
  1633. int event)
  1634. {
  1635. if (mode == CLS_AB || mode == CLS_AB_HIFI) {
  1636. switch (event) {
  1637. case SND_SOC_DAPM_PRE_PMU:
  1638. case SND_SOC_DAPM_POST_PMU:
  1639. snd_soc_update_bits(codec,
  1640. WCD9XXX_A_ANA_RX_SUPPLIES, 0x02, 0x02);
  1641. break;
  1642. case SND_SOC_DAPM_POST_PMD:
  1643. snd_soc_update_bits(codec,
  1644. WCD9XXX_A_ANA_RX_SUPPLIES, 0x02, 0x00);
  1645. break;
  1646. }
  1647. }
  1648. }
  1649. static void tavil_codec_clear_anc_tx_hold(struct tavil_priv *tavil)
  1650. {
  1651. if (test_and_clear_bit(ANC_MIC_AMIC1, &tavil->status_mask))
  1652. tavil_codec_set_tx_hold(tavil->codec, WCD934X_ANA_AMIC1, false);
  1653. if (test_and_clear_bit(ANC_MIC_AMIC2, &tavil->status_mask))
  1654. tavil_codec_set_tx_hold(tavil->codec, WCD934X_ANA_AMIC2, false);
  1655. if (test_and_clear_bit(ANC_MIC_AMIC3, &tavil->status_mask))
  1656. tavil_codec_set_tx_hold(tavil->codec, WCD934X_ANA_AMIC3, false);
  1657. if (test_and_clear_bit(ANC_MIC_AMIC4, &tavil->status_mask))
  1658. tavil_codec_set_tx_hold(tavil->codec, WCD934X_ANA_AMIC4, false);
  1659. }
  1660. static int tavil_codec_enable_hphr_pa(struct snd_soc_dapm_widget *w,
  1661. struct snd_kcontrol *kcontrol,
  1662. int event)
  1663. {
  1664. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1665. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  1666. struct tavil_dsd_config *dsd_conf = tavil->dsd_config;
  1667. int ret = 0;
  1668. dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
  1669. switch (event) {
  1670. case SND_SOC_DAPM_PRE_PMU:
  1671. if (TAVIL_IS_1_0(tavil->wcd9xxx))
  1672. snd_soc_update_bits(codec, WCD934X_HPH_REFBUFF_LP_CTL,
  1673. 0x06, (0x03 << 1));
  1674. if ((!(strcmp(w->name, "ANC HPHR PA"))) &&
  1675. (test_bit(HPH_PA_DELAY, &tavil->status_mask)))
  1676. snd_soc_update_bits(codec, WCD934X_ANA_HPH, 0xC0, 0xC0);
  1677. set_bit(HPH_PA_DELAY, &tavil->status_mask);
  1678. if (dsd_conf &&
  1679. (snd_soc_read(codec, WCD934X_CDC_DSD1_PATH_CTL) & 0x01)) {
  1680. /* Set regulator mode to AB if DSD is enabled */
  1681. snd_soc_update_bits(codec, WCD934X_ANA_RX_SUPPLIES,
  1682. 0x02, 0x02);
  1683. }
  1684. break;
  1685. case SND_SOC_DAPM_POST_PMU:
  1686. if ((!(strcmp(w->name, "ANC HPHR PA")))) {
  1687. if ((snd_soc_read(codec, WCD934X_ANA_HPH) & 0xC0)
  1688. != 0xC0)
  1689. /*
  1690. * If PA_EN is not set (potentially in ANC case)
  1691. * then do nothing for POST_PMU and let left
  1692. * channel handle everything.
  1693. */
  1694. break;
  1695. }
  1696. /*
  1697. * 7ms sleep is required after PA is enabled as per
  1698. * HW requirement. If compander is disabled, then
  1699. * 20ms delay is needed.
  1700. */
  1701. if (test_bit(HPH_PA_DELAY, &tavil->status_mask)) {
  1702. if (!tavil->comp_enabled[COMPANDER_2])
  1703. usleep_range(20000, 20100);
  1704. else
  1705. usleep_range(7000, 7100);
  1706. clear_bit(HPH_PA_DELAY, &tavil->status_mask);
  1707. }
  1708. if (tavil->anc_func) {
  1709. /* Clear Tx FE HOLD if both PAs are enabled */
  1710. if ((snd_soc_read(tavil->codec, WCD934X_ANA_HPH) &
  1711. 0xC0) == 0xC0)
  1712. tavil_codec_clear_anc_tx_hold(tavil);
  1713. }
  1714. snd_soc_update_bits(codec, WCD934X_HPH_R_TEST, 0x01, 0x01);
  1715. /* Remove mute */
  1716. snd_soc_update_bits(codec, WCD934X_CDC_RX2_RX_PATH_CTL,
  1717. 0x10, 0x00);
  1718. /* Enable GM3 boost */
  1719. snd_soc_update_bits(codec, WCD934X_HPH_CNP_WG_CTL,
  1720. 0x80, 0x80);
  1721. /* Enable AutoChop timer at the end of power up */
  1722. snd_soc_update_bits(codec, WCD934X_HPH_NEW_INT_HPH_TIMER1,
  1723. 0x02, 0x02);
  1724. /* Remove mix path mute if it is enabled */
  1725. if ((snd_soc_read(codec, WCD934X_CDC_RX2_RX_PATH_MIX_CTL)) &
  1726. 0x10)
  1727. snd_soc_update_bits(codec,
  1728. WCD934X_CDC_RX2_RX_PATH_MIX_CTL,
  1729. 0x10, 0x00);
  1730. if (dsd_conf &&
  1731. (snd_soc_read(codec, WCD934X_CDC_DSD1_PATH_CTL) & 0x01))
  1732. snd_soc_update_bits(codec, WCD934X_CDC_DSD1_CFG2,
  1733. 0x04, 0x00);
  1734. if (!(strcmp(w->name, "ANC HPHR PA"))) {
  1735. pr_debug("%s:Do everything needed for left channel\n",
  1736. __func__);
  1737. /* Do everything needed for left channel */
  1738. snd_soc_update_bits(codec, WCD934X_HPH_L_TEST,
  1739. 0x01, 0x01);
  1740. /* Remove mute */
  1741. snd_soc_update_bits(codec, WCD934X_CDC_RX1_RX_PATH_CTL,
  1742. 0x10, 0x00);
  1743. /* Remove mix path mute if it is enabled */
  1744. if ((snd_soc_read(codec,
  1745. WCD934X_CDC_RX1_RX_PATH_MIX_CTL)) &
  1746. 0x10)
  1747. snd_soc_update_bits(codec,
  1748. WCD934X_CDC_RX1_RX_PATH_MIX_CTL,
  1749. 0x10, 0x00);
  1750. if (dsd_conf && (snd_soc_read(codec,
  1751. WCD934X_CDC_DSD0_PATH_CTL) &
  1752. 0x01))
  1753. snd_soc_update_bits(codec,
  1754. WCD934X_CDC_DSD0_CFG2,
  1755. 0x04, 0x00);
  1756. /* Remove ANC Rx from reset */
  1757. ret = tavil_codec_enable_anc(w, kcontrol, event);
  1758. }
  1759. tavil_codec_override(codec, tavil->hph_mode, event);
  1760. break;
  1761. case SND_SOC_DAPM_PRE_PMD:
  1762. blocking_notifier_call_chain(&tavil->mbhc->notifier,
  1763. WCD_EVENT_PRE_HPHR_PA_OFF,
  1764. &tavil->mbhc->wcd_mbhc);
  1765. /* Enable DSD Mute before PA disable */
  1766. if (dsd_conf &&
  1767. (snd_soc_read(codec, WCD934X_CDC_DSD1_PATH_CTL) & 0x01))
  1768. snd_soc_update_bits(codec, WCD934X_CDC_DSD1_CFG2,
  1769. 0x04, 0x04);
  1770. snd_soc_update_bits(codec, WCD934X_HPH_R_TEST, 0x01, 0x00);
  1771. snd_soc_update_bits(codec, WCD934X_CDC_RX2_RX_PATH_CTL,
  1772. 0x10, 0x10);
  1773. snd_soc_update_bits(codec, WCD934X_CDC_RX2_RX_PATH_MIX_CTL,
  1774. 0x10, 0x10);
  1775. if (!(strcmp(w->name, "ANC HPHR PA")))
  1776. snd_soc_update_bits(codec, WCD934X_ANA_HPH, 0x40, 0x00);
  1777. break;
  1778. case SND_SOC_DAPM_POST_PMD:
  1779. /*
  1780. * 5ms sleep is required after PA disable. If compander is
  1781. * disabled, then 20ms delay is needed after PA disable.
  1782. */
  1783. if (!tavil->comp_enabled[COMPANDER_2])
  1784. usleep_range(20000, 20100);
  1785. else
  1786. usleep_range(5000, 5100);
  1787. tavil_codec_override(codec, tavil->hph_mode, event);
  1788. blocking_notifier_call_chain(&tavil->mbhc->notifier,
  1789. WCD_EVENT_POST_HPHR_PA_OFF,
  1790. &tavil->mbhc->wcd_mbhc);
  1791. if (TAVIL_IS_1_0(tavil->wcd9xxx))
  1792. snd_soc_update_bits(codec, WCD934X_HPH_REFBUFF_LP_CTL,
  1793. 0x06, 0x0);
  1794. if (!(strcmp(w->name, "ANC HPHR PA"))) {
  1795. ret = tavil_codec_enable_anc(w, kcontrol, event);
  1796. snd_soc_update_bits(codec,
  1797. WCD934X_CDC_RX2_RX_PATH_CFG0,
  1798. 0x10, 0x00);
  1799. }
  1800. break;
  1801. };
  1802. return ret;
  1803. }
  1804. static int tavil_codec_enable_hphl_pa(struct snd_soc_dapm_widget *w,
  1805. struct snd_kcontrol *kcontrol,
  1806. int event)
  1807. {
  1808. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1809. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  1810. struct tavil_dsd_config *dsd_conf = tavil->dsd_config;
  1811. int ret = 0;
  1812. dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
  1813. switch (event) {
  1814. case SND_SOC_DAPM_PRE_PMU:
  1815. if (TAVIL_IS_1_0(tavil->wcd9xxx))
  1816. snd_soc_update_bits(codec, WCD934X_HPH_REFBUFF_LP_CTL,
  1817. 0x06, (0x03 << 1));
  1818. if ((!(strcmp(w->name, "ANC HPHL PA"))) &&
  1819. (test_bit(HPH_PA_DELAY, &tavil->status_mask)))
  1820. snd_soc_update_bits(codec, WCD934X_ANA_HPH,
  1821. 0xC0, 0xC0);
  1822. set_bit(HPH_PA_DELAY, &tavil->status_mask);
  1823. if (dsd_conf &&
  1824. (snd_soc_read(codec, WCD934X_CDC_DSD0_PATH_CTL) & 0x01)) {
  1825. /* Set regulator mode to AB if DSD is enabled */
  1826. snd_soc_update_bits(codec, WCD934X_ANA_RX_SUPPLIES,
  1827. 0x02, 0x02);
  1828. }
  1829. break;
  1830. case SND_SOC_DAPM_POST_PMU:
  1831. if (!(strcmp(w->name, "ANC HPHL PA"))) {
  1832. if ((snd_soc_read(codec, WCD934X_ANA_HPH) & 0xC0)
  1833. != 0xC0)
  1834. /*
  1835. * If PA_EN is not set (potentially in ANC
  1836. * case) then do nothing for POST_PMU and
  1837. * let right channel handle everything.
  1838. */
  1839. break;
  1840. }
  1841. /*
  1842. * 7ms sleep is required after PA is enabled as per
  1843. * HW requirement. If compander is disabled, then
  1844. * 20ms delay is needed.
  1845. */
  1846. if (test_bit(HPH_PA_DELAY, &tavil->status_mask)) {
  1847. if (!tavil->comp_enabled[COMPANDER_1])
  1848. usleep_range(20000, 20100);
  1849. else
  1850. usleep_range(7000, 7100);
  1851. clear_bit(HPH_PA_DELAY, &tavil->status_mask);
  1852. }
  1853. if (tavil->anc_func) {
  1854. /* Clear Tx FE HOLD if both PAs are enabled */
  1855. if ((snd_soc_read(tavil->codec, WCD934X_ANA_HPH) &
  1856. 0xC0) == 0xC0)
  1857. tavil_codec_clear_anc_tx_hold(tavil);
  1858. }
  1859. snd_soc_update_bits(codec, WCD934X_HPH_L_TEST, 0x01, 0x01);
  1860. /* Remove Mute on primary path */
  1861. snd_soc_update_bits(codec, WCD934X_CDC_RX1_RX_PATH_CTL,
  1862. 0x10, 0x00);
  1863. /* Enable GM3 boost */
  1864. snd_soc_update_bits(codec, WCD934X_HPH_CNP_WG_CTL,
  1865. 0x80, 0x80);
  1866. /* Enable AutoChop timer at the end of power up */
  1867. snd_soc_update_bits(codec, WCD934X_HPH_NEW_INT_HPH_TIMER1,
  1868. 0x02, 0x02);
  1869. /* Remove mix path mute if it is enabled */
  1870. if ((snd_soc_read(codec, WCD934X_CDC_RX1_RX_PATH_MIX_CTL)) &
  1871. 0x10)
  1872. snd_soc_update_bits(codec,
  1873. WCD934X_CDC_RX1_RX_PATH_MIX_CTL,
  1874. 0x10, 0x00);
  1875. if (dsd_conf &&
  1876. (snd_soc_read(codec, WCD934X_CDC_DSD0_PATH_CTL) & 0x01))
  1877. snd_soc_update_bits(codec, WCD934X_CDC_DSD0_CFG2,
  1878. 0x04, 0x00);
  1879. if (!(strcmp(w->name, "ANC HPHL PA"))) {
  1880. pr_debug("%s:Do everything needed for right channel\n",
  1881. __func__);
  1882. /* Do everything needed for right channel */
  1883. snd_soc_update_bits(codec, WCD934X_HPH_R_TEST,
  1884. 0x01, 0x01);
  1885. /* Remove mute */
  1886. snd_soc_update_bits(codec, WCD934X_CDC_RX2_RX_PATH_CTL,
  1887. 0x10, 0x00);
  1888. /* Remove mix path mute if it is enabled */
  1889. if ((snd_soc_read(codec,
  1890. WCD934X_CDC_RX2_RX_PATH_MIX_CTL)) &
  1891. 0x10)
  1892. snd_soc_update_bits(codec,
  1893. WCD934X_CDC_RX2_RX_PATH_MIX_CTL,
  1894. 0x10, 0x00);
  1895. if (dsd_conf && (snd_soc_read(codec,
  1896. WCD934X_CDC_DSD1_PATH_CTL) & 0x01))
  1897. snd_soc_update_bits(codec,
  1898. WCD934X_CDC_DSD1_CFG2,
  1899. 0x04, 0x00);
  1900. /* Remove ANC Rx from reset */
  1901. ret = tavil_codec_enable_anc(w, kcontrol, event);
  1902. }
  1903. tavil_codec_override(codec, tavil->hph_mode, event);
  1904. break;
  1905. case SND_SOC_DAPM_PRE_PMD:
  1906. blocking_notifier_call_chain(&tavil->mbhc->notifier,
  1907. WCD_EVENT_PRE_HPHL_PA_OFF,
  1908. &tavil->mbhc->wcd_mbhc);
  1909. /* Enable DSD Mute before PA disable */
  1910. if (dsd_conf &&
  1911. (snd_soc_read(codec, WCD934X_CDC_DSD0_PATH_CTL) & 0x01))
  1912. snd_soc_update_bits(codec, WCD934X_CDC_DSD0_CFG2,
  1913. 0x04, 0x04);
  1914. snd_soc_update_bits(codec, WCD934X_HPH_L_TEST, 0x01, 0x00);
  1915. snd_soc_update_bits(codec, WCD934X_CDC_RX1_RX_PATH_CTL,
  1916. 0x10, 0x10);
  1917. snd_soc_update_bits(codec, WCD934X_CDC_RX1_RX_PATH_MIX_CTL,
  1918. 0x10, 0x10);
  1919. if (!(strcmp(w->name, "ANC HPHL PA")))
  1920. snd_soc_update_bits(codec, WCD934X_ANA_HPH,
  1921. 0x80, 0x00);
  1922. break;
  1923. case SND_SOC_DAPM_POST_PMD:
  1924. /*
  1925. * 5ms sleep is required after PA disable. If compander is
  1926. * disabled, then 20ms delay is needed after PA disable.
  1927. */
  1928. if (!tavil->comp_enabled[COMPANDER_1])
  1929. usleep_range(20000, 20100);
  1930. else
  1931. usleep_range(5000, 5100);
  1932. tavil_codec_override(codec, tavil->hph_mode, event);
  1933. blocking_notifier_call_chain(&tavil->mbhc->notifier,
  1934. WCD_EVENT_POST_HPHL_PA_OFF,
  1935. &tavil->mbhc->wcd_mbhc);
  1936. if (TAVIL_IS_1_0(tavil->wcd9xxx))
  1937. snd_soc_update_bits(codec, WCD934X_HPH_REFBUFF_LP_CTL,
  1938. 0x06, 0x0);
  1939. if (!(strcmp(w->name, "ANC HPHL PA"))) {
  1940. ret = tavil_codec_enable_anc(w, kcontrol, event);
  1941. snd_soc_update_bits(codec,
  1942. WCD934X_CDC_RX1_RX_PATH_CFG0, 0x10, 0x00);
  1943. }
  1944. break;
  1945. };
  1946. return ret;
  1947. }
  1948. static int tavil_codec_enable_lineout_pa(struct snd_soc_dapm_widget *w,
  1949. struct snd_kcontrol *kcontrol,
  1950. int event)
  1951. {
  1952. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1953. u16 lineout_vol_reg = 0, lineout_mix_vol_reg = 0;
  1954. u16 dsd_mute_reg = 0, dsd_clk_reg = 0;
  1955. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  1956. struct tavil_dsd_config *dsd_conf = tavil->dsd_config;
  1957. dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
  1958. if (w->reg == WCD934X_ANA_LO_1_2) {
  1959. if (w->shift == 7) {
  1960. lineout_vol_reg = WCD934X_CDC_RX3_RX_PATH_CTL;
  1961. lineout_mix_vol_reg = WCD934X_CDC_RX3_RX_PATH_MIX_CTL;
  1962. dsd_mute_reg = WCD934X_CDC_DSD0_CFG2;
  1963. dsd_clk_reg = WCD934X_CDC_DSD0_PATH_CTL;
  1964. } else if (w->shift == 6) {
  1965. lineout_vol_reg = WCD934X_CDC_RX4_RX_PATH_CTL;
  1966. lineout_mix_vol_reg = WCD934X_CDC_RX4_RX_PATH_MIX_CTL;
  1967. dsd_mute_reg = WCD934X_CDC_DSD1_CFG2;
  1968. dsd_clk_reg = WCD934X_CDC_DSD1_PATH_CTL;
  1969. }
  1970. } else {
  1971. dev_err(codec->dev, "%s: Error enabling lineout PA\n",
  1972. __func__);
  1973. return -EINVAL;
  1974. }
  1975. switch (event) {
  1976. case SND_SOC_DAPM_PRE_PMU:
  1977. tavil_codec_override(codec, CLS_AB, event);
  1978. break;
  1979. case SND_SOC_DAPM_POST_PMU:
  1980. /*
  1981. * 5ms sleep is required after PA is enabled as per
  1982. * HW requirement
  1983. */
  1984. usleep_range(5000, 5500);
  1985. snd_soc_update_bits(codec, lineout_vol_reg,
  1986. 0x10, 0x00);
  1987. /* Remove mix path mute if it is enabled */
  1988. if ((snd_soc_read(codec, lineout_mix_vol_reg)) & 0x10)
  1989. snd_soc_update_bits(codec,
  1990. lineout_mix_vol_reg,
  1991. 0x10, 0x00);
  1992. if (dsd_conf && (snd_soc_read(codec, dsd_clk_reg) & 0x01))
  1993. snd_soc_update_bits(codec, dsd_mute_reg, 0x04, 0x00);
  1994. break;
  1995. case SND_SOC_DAPM_PRE_PMD:
  1996. if (dsd_conf && (snd_soc_read(codec, dsd_clk_reg) & 0x01))
  1997. snd_soc_update_bits(codec, dsd_mute_reg, 0x04, 0x04);
  1998. break;
  1999. case SND_SOC_DAPM_POST_PMD:
  2000. /*
  2001. * 5ms sleep is required after PA is disabled as per
  2002. * HW requirement
  2003. */
  2004. usleep_range(5000, 5500);
  2005. tavil_codec_override(codec, CLS_AB, event);
  2006. default:
  2007. break;
  2008. };
  2009. return 0;
  2010. }
  2011. static int tavil_codec_ear_dac_event(struct snd_soc_dapm_widget *w,
  2012. struct snd_kcontrol *kcontrol,
  2013. int event)
  2014. {
  2015. int ret = 0;
  2016. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2017. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  2018. dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
  2019. switch (event) {
  2020. case SND_SOC_DAPM_PRE_PMU:
  2021. /* Disable AutoChop timer during power up */
  2022. snd_soc_update_bits(codec, WCD934X_HPH_NEW_INT_HPH_TIMER1,
  2023. 0x02, 0x00);
  2024. if (tavil->anc_func)
  2025. ret = tavil_codec_enable_anc(w, kcontrol, event);
  2026. wcd_clsh_fsm(codec, &tavil->clsh_d,
  2027. WCD_CLSH_EVENT_PRE_DAC,
  2028. WCD_CLSH_STATE_EAR,
  2029. CLS_H_NORMAL);
  2030. if (tavil->anc_func)
  2031. snd_soc_update_bits(codec, WCD934X_CDC_RX0_RX_PATH_CFG0,
  2032. 0x10, 0x10);
  2033. break;
  2034. case SND_SOC_DAPM_POST_PMD:
  2035. wcd_clsh_fsm(codec, &tavil->clsh_d,
  2036. WCD_CLSH_EVENT_POST_PA,
  2037. WCD_CLSH_STATE_EAR,
  2038. CLS_H_NORMAL);
  2039. break;
  2040. default:
  2041. break;
  2042. };
  2043. return ret;
  2044. }
  2045. static int tavil_codec_hphr_dac_event(struct snd_soc_dapm_widget *w,
  2046. struct snd_kcontrol *kcontrol,
  2047. int event)
  2048. {
  2049. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2050. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  2051. int hph_mode = tavil->hph_mode;
  2052. u8 dem_inp;
  2053. struct tavil_dsd_config *dsd_conf = tavil->dsd_config;
  2054. int ret = 0;
  2055. dev_dbg(codec->dev, "%s wname: %s event: %d hph_mode: %d\n", __func__,
  2056. w->name, event, hph_mode);
  2057. switch (event) {
  2058. case SND_SOC_DAPM_PRE_PMU:
  2059. if (tavil->anc_func) {
  2060. ret = tavil_codec_enable_anc(w, kcontrol, event);
  2061. /* 40 msec delay is needed to avoid click and pop */
  2062. msleep(40);
  2063. }
  2064. /* Read DEM INP Select */
  2065. dem_inp = snd_soc_read(codec, WCD934X_CDC_RX2_RX_PATH_SEC0) &
  2066. 0x03;
  2067. if (((hph_mode == CLS_H_HIFI) || (hph_mode == CLS_H_LOHIFI) ||
  2068. (hph_mode == CLS_H_LP)) && (dem_inp != 0x01)) {
  2069. dev_err(codec->dev, "%s: DEM Input not set correctly, hph_mode: %d\n",
  2070. __func__, hph_mode);
  2071. return -EINVAL;
  2072. }
  2073. if ((hph_mode != CLS_H_LP) && (hph_mode != CLS_H_ULP))
  2074. /* Ripple freq control enable */
  2075. snd_soc_update_bits(codec,
  2076. WCD934X_SIDO_NEW_VOUT_D_FREQ2,
  2077. 0x01, 0x01);
  2078. /* Disable AutoChop timer during power up */
  2079. snd_soc_update_bits(codec, WCD934X_HPH_NEW_INT_HPH_TIMER1,
  2080. 0x02, 0x00);
  2081. /* Set RDAC gain */
  2082. if (TAVIL_IS_1_0(tavil->wcd9xxx))
  2083. snd_soc_update_bits(codec,
  2084. WCD934X_HPH_NEW_INT_RDAC_GAIN_CTL,
  2085. 0xF0, 0x40);
  2086. if (dsd_conf &&
  2087. (snd_soc_read(codec, WCD934X_CDC_DSD1_PATH_CTL) & 0x01))
  2088. hph_mode = CLS_H_HIFI;
  2089. wcd_clsh_fsm(codec, &tavil->clsh_d,
  2090. WCD_CLSH_EVENT_PRE_DAC,
  2091. WCD_CLSH_STATE_HPHR,
  2092. hph_mode);
  2093. if (tavil->anc_func)
  2094. snd_soc_update_bits(codec,
  2095. WCD934X_CDC_RX2_RX_PATH_CFG0,
  2096. 0x10, 0x10);
  2097. break;
  2098. case SND_SOC_DAPM_POST_PMD:
  2099. /* 1000us required as per HW requirement */
  2100. usleep_range(1000, 1100);
  2101. wcd_clsh_fsm(codec, &tavil->clsh_d,
  2102. WCD_CLSH_EVENT_POST_PA,
  2103. WCD_CLSH_STATE_HPHR,
  2104. hph_mode);
  2105. if ((hph_mode != CLS_H_LP) && (hph_mode != CLS_H_ULP))
  2106. /* Ripple freq control disable */
  2107. snd_soc_update_bits(codec,
  2108. WCD934X_SIDO_NEW_VOUT_D_FREQ2,
  2109. 0x01, 0x0);
  2110. /* Re-set RDAC gain */
  2111. if (TAVIL_IS_1_0(tavil->wcd9xxx))
  2112. snd_soc_update_bits(codec,
  2113. WCD934X_HPH_NEW_INT_RDAC_GAIN_CTL,
  2114. 0xF0, 0x0);
  2115. break;
  2116. default:
  2117. break;
  2118. };
  2119. return 0;
  2120. }
  2121. static int tavil_codec_hphl_dac_event(struct snd_soc_dapm_widget *w,
  2122. struct snd_kcontrol *kcontrol,
  2123. int event)
  2124. {
  2125. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2126. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  2127. int hph_mode = tavil->hph_mode;
  2128. u8 dem_inp;
  2129. int ret = 0;
  2130. struct tavil_dsd_config *dsd_conf = tavil->dsd_config;
  2131. uint32_t impedl = 0, impedr = 0;
  2132. dev_dbg(codec->dev, "%s wname: %s event: %d hph_mode: %d\n", __func__,
  2133. w->name, event, hph_mode);
  2134. switch (event) {
  2135. case SND_SOC_DAPM_PRE_PMU:
  2136. if (tavil->anc_func) {
  2137. ret = tavil_codec_enable_anc(w, kcontrol, event);
  2138. /* 40 msec delay is needed to avoid click and pop */
  2139. msleep(40);
  2140. }
  2141. /* Read DEM INP Select */
  2142. dem_inp = snd_soc_read(codec, WCD934X_CDC_RX1_RX_PATH_SEC0) &
  2143. 0x03;
  2144. if (((hph_mode == CLS_H_HIFI) || (hph_mode == CLS_H_LOHIFI) ||
  2145. (hph_mode == CLS_H_LP)) && (dem_inp != 0x01)) {
  2146. dev_err(codec->dev, "%s: DEM Input not set correctly, hph_mode: %d\n",
  2147. __func__, hph_mode);
  2148. return -EINVAL;
  2149. }
  2150. if ((hph_mode != CLS_H_LP) && (hph_mode != CLS_H_ULP))
  2151. /* Ripple freq control enable */
  2152. snd_soc_update_bits(codec,
  2153. WCD934X_SIDO_NEW_VOUT_D_FREQ2,
  2154. 0x01, 0x01);
  2155. /* Disable AutoChop timer during power up */
  2156. snd_soc_update_bits(codec, WCD934X_HPH_NEW_INT_HPH_TIMER1,
  2157. 0x02, 0x00);
  2158. /* Set RDAC gain */
  2159. if (TAVIL_IS_1_0(tavil->wcd9xxx))
  2160. snd_soc_update_bits(codec,
  2161. WCD934X_HPH_NEW_INT_RDAC_GAIN_CTL,
  2162. 0xF0, 0x40);
  2163. if (dsd_conf &&
  2164. (snd_soc_read(codec, WCD934X_CDC_DSD0_PATH_CTL) & 0x01))
  2165. hph_mode = CLS_H_HIFI;
  2166. wcd_clsh_fsm(codec, &tavil->clsh_d,
  2167. WCD_CLSH_EVENT_PRE_DAC,
  2168. WCD_CLSH_STATE_HPHL,
  2169. hph_mode);
  2170. if (tavil->anc_func)
  2171. snd_soc_update_bits(codec,
  2172. WCD934X_CDC_RX1_RX_PATH_CFG0,
  2173. 0x10, 0x10);
  2174. ret = tavil_mbhc_get_impedance(tavil->mbhc,
  2175. &impedl, &impedr);
  2176. if (!ret) {
  2177. wcd_clsh_imped_config(codec, impedl, false);
  2178. set_bit(CLSH_Z_CONFIG, &tavil->status_mask);
  2179. } else {
  2180. dev_dbg(codec->dev, "%s: Failed to get mbhc impedance %d\n",
  2181. __func__, ret);
  2182. ret = 0;
  2183. }
  2184. break;
  2185. case SND_SOC_DAPM_POST_PMD:
  2186. /* 1000us required as per HW requirement */
  2187. usleep_range(1000, 1100);
  2188. wcd_clsh_fsm(codec, &tavil->clsh_d,
  2189. WCD_CLSH_EVENT_POST_PA,
  2190. WCD_CLSH_STATE_HPHL,
  2191. hph_mode);
  2192. if ((hph_mode != CLS_H_LP) && (hph_mode != CLS_H_ULP))
  2193. /* Ripple freq control disable */
  2194. snd_soc_update_bits(codec,
  2195. WCD934X_SIDO_NEW_VOUT_D_FREQ2,
  2196. 0x01, 0x0);
  2197. /* Re-set RDAC gain */
  2198. if (TAVIL_IS_1_0(tavil->wcd9xxx))
  2199. snd_soc_update_bits(codec,
  2200. WCD934X_HPH_NEW_INT_RDAC_GAIN_CTL,
  2201. 0xF0, 0x0);
  2202. if (test_bit(CLSH_Z_CONFIG, &tavil->status_mask)) {
  2203. wcd_clsh_imped_config(codec, impedl, true);
  2204. clear_bit(CLSH_Z_CONFIG, &tavil->status_mask);
  2205. }
  2206. break;
  2207. default:
  2208. break;
  2209. };
  2210. return ret;
  2211. }
  2212. static int tavil_codec_lineout_dac_event(struct snd_soc_dapm_widget *w,
  2213. struct snd_kcontrol *kcontrol,
  2214. int event)
  2215. {
  2216. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2217. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  2218. dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
  2219. switch (event) {
  2220. case SND_SOC_DAPM_PRE_PMU:
  2221. wcd_clsh_fsm(codec, &tavil->clsh_d,
  2222. WCD_CLSH_EVENT_PRE_DAC,
  2223. WCD_CLSH_STATE_LO,
  2224. CLS_AB);
  2225. break;
  2226. case SND_SOC_DAPM_POST_PMD:
  2227. wcd_clsh_fsm(codec, &tavil->clsh_d,
  2228. WCD_CLSH_EVENT_POST_PA,
  2229. WCD_CLSH_STATE_LO,
  2230. CLS_AB);
  2231. break;
  2232. }
  2233. return 0;
  2234. }
  2235. static int tavil_codec_spk_boost_event(struct snd_soc_dapm_widget *w,
  2236. struct snd_kcontrol *kcontrol,
  2237. int event)
  2238. {
  2239. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2240. u16 boost_path_ctl, boost_path_cfg1;
  2241. u16 reg, reg_mix;
  2242. dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
  2243. if (!strcmp(w->name, "RX INT7 CHAIN")) {
  2244. boost_path_ctl = WCD934X_CDC_BOOST0_BOOST_PATH_CTL;
  2245. boost_path_cfg1 = WCD934X_CDC_RX7_RX_PATH_CFG1;
  2246. reg = WCD934X_CDC_RX7_RX_PATH_CTL;
  2247. reg_mix = WCD934X_CDC_RX7_RX_PATH_MIX_CTL;
  2248. } else if (!strcmp(w->name, "RX INT8 CHAIN")) {
  2249. boost_path_ctl = WCD934X_CDC_BOOST1_BOOST_PATH_CTL;
  2250. boost_path_cfg1 = WCD934X_CDC_RX8_RX_PATH_CFG1;
  2251. reg = WCD934X_CDC_RX8_RX_PATH_CTL;
  2252. reg_mix = WCD934X_CDC_RX8_RX_PATH_MIX_CTL;
  2253. } else {
  2254. dev_err(codec->dev, "%s: unknown widget: %s\n",
  2255. __func__, w->name);
  2256. return -EINVAL;
  2257. }
  2258. switch (event) {
  2259. case SND_SOC_DAPM_PRE_PMU:
  2260. snd_soc_update_bits(codec, boost_path_cfg1, 0x01, 0x01);
  2261. snd_soc_update_bits(codec, boost_path_ctl, 0x10, 0x10);
  2262. snd_soc_update_bits(codec, reg, 0x10, 0x00);
  2263. if ((snd_soc_read(codec, reg_mix)) & 0x10)
  2264. snd_soc_update_bits(codec, reg_mix, 0x10, 0x00);
  2265. break;
  2266. case SND_SOC_DAPM_POST_PMD:
  2267. snd_soc_update_bits(codec, boost_path_ctl, 0x10, 0x00);
  2268. snd_soc_update_bits(codec, boost_path_cfg1, 0x01, 0x00);
  2269. break;
  2270. };
  2271. return 0;
  2272. }
  2273. static int __tavil_codec_enable_swr(struct snd_soc_dapm_widget *w, int event)
  2274. {
  2275. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2276. struct tavil_priv *tavil;
  2277. int ch_cnt = 0;
  2278. tavil = snd_soc_codec_get_drvdata(codec);
  2279. switch (event) {
  2280. case SND_SOC_DAPM_PRE_PMU:
  2281. if (((strnstr(w->name, "INT7_", sizeof("RX INT7_"))) ||
  2282. (strnstr(w->name, "INT7 MIX2",
  2283. sizeof("RX INT7 MIX2")))))
  2284. tavil->swr.rx_7_count++;
  2285. if ((strnstr(w->name, "INT8_", sizeof("RX INT8_"))) &&
  2286. !tavil->swr.rx_8_count)
  2287. tavil->swr.rx_8_count++;
  2288. ch_cnt = !!(tavil->swr.rx_7_count) + tavil->swr.rx_8_count;
  2289. swrm_wcd_notify(tavil->swr.ctrl_data[0].swr_pdev,
  2290. SWR_DEVICE_UP, NULL);
  2291. swrm_wcd_notify(tavil->swr.ctrl_data[0].swr_pdev,
  2292. SWR_SET_NUM_RX_CH, &ch_cnt);
  2293. break;
  2294. case SND_SOC_DAPM_POST_PMD:
  2295. if ((strnstr(w->name, "INT7_", sizeof("RX INT7_"))) ||
  2296. (strnstr(w->name, "INT7 MIX2",
  2297. sizeof("RX INT7 MIX2"))))
  2298. tavil->swr.rx_7_count--;
  2299. if ((strnstr(w->name, "INT8_", sizeof("RX INT8_"))) &&
  2300. tavil->swr.rx_8_count)
  2301. tavil->swr.rx_8_count--;
  2302. ch_cnt = !!(tavil->swr.rx_7_count) + tavil->swr.rx_8_count;
  2303. swrm_wcd_notify(tavil->swr.ctrl_data[0].swr_pdev,
  2304. SWR_SET_NUM_RX_CH, &ch_cnt);
  2305. break;
  2306. }
  2307. dev_dbg(tavil->dev, "%s: %s: current swr ch cnt: %d\n",
  2308. __func__, w->name, ch_cnt);
  2309. return 0;
  2310. }
  2311. static int tavil_codec_enable_swr(struct snd_soc_dapm_widget *w,
  2312. struct snd_kcontrol *kcontrol, int event)
  2313. {
  2314. return __tavil_codec_enable_swr(w, event);
  2315. }
  2316. static int tavil_codec_config_mad(struct snd_soc_codec *codec)
  2317. {
  2318. int ret = 0;
  2319. int idx;
  2320. const struct firmware *fw;
  2321. struct firmware_cal *hwdep_cal = NULL;
  2322. struct wcd_mad_audio_cal *mad_cal = NULL;
  2323. const void *data;
  2324. const char *filename = WCD934X_MAD_AUDIO_FIRMWARE_PATH;
  2325. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  2326. size_t cal_size;
  2327. hwdep_cal = wcdcal_get_fw_cal(tavil->fw_data, WCD9XXX_MAD_CAL);
  2328. if (hwdep_cal) {
  2329. data = hwdep_cal->data;
  2330. cal_size = hwdep_cal->size;
  2331. dev_dbg(codec->dev, "%s: using hwdep calibration\n",
  2332. __func__);
  2333. } else {
  2334. ret = request_firmware(&fw, filename, codec->dev);
  2335. if (ret || !fw) {
  2336. dev_err(codec->dev,
  2337. "%s: MAD firmware acquire failed, err = %d\n",
  2338. __func__, ret);
  2339. return -ENODEV;
  2340. }
  2341. data = fw->data;
  2342. cal_size = fw->size;
  2343. dev_dbg(codec->dev, "%s: using request_firmware calibration\n",
  2344. __func__);
  2345. }
  2346. if (cal_size < sizeof(*mad_cal)) {
  2347. dev_err(codec->dev,
  2348. "%s: Incorrect size %zd for MAD Cal, expected %zd\n",
  2349. __func__, cal_size, sizeof(*mad_cal));
  2350. ret = -ENOMEM;
  2351. goto done;
  2352. }
  2353. mad_cal = (struct wcd_mad_audio_cal *) (data);
  2354. if (!mad_cal) {
  2355. dev_err(codec->dev,
  2356. "%s: Invalid calibration data\n",
  2357. __func__);
  2358. ret = -EINVAL;
  2359. goto done;
  2360. }
  2361. snd_soc_write(codec, WCD934X_SOC_MAD_MAIN_CTL_2,
  2362. mad_cal->microphone_info.cycle_time);
  2363. snd_soc_update_bits(codec, WCD934X_SOC_MAD_MAIN_CTL_1, 0xFF << 3,
  2364. ((uint16_t)mad_cal->microphone_info.settle_time)
  2365. << 3);
  2366. /* Audio */
  2367. snd_soc_write(codec, WCD934X_SOC_MAD_AUDIO_CTL_8,
  2368. mad_cal->audio_info.rms_omit_samples);
  2369. snd_soc_update_bits(codec, WCD934X_SOC_MAD_AUDIO_CTL_1,
  2370. 0x07 << 4, mad_cal->audio_info.rms_comp_time << 4);
  2371. snd_soc_update_bits(codec, WCD934X_SOC_MAD_AUDIO_CTL_2, 0x03 << 2,
  2372. mad_cal->audio_info.detection_mechanism << 2);
  2373. snd_soc_write(codec, WCD934X_SOC_MAD_AUDIO_CTL_7,
  2374. mad_cal->audio_info.rms_diff_threshold & 0x3F);
  2375. snd_soc_write(codec, WCD934X_SOC_MAD_AUDIO_CTL_5,
  2376. mad_cal->audio_info.rms_threshold_lsb);
  2377. snd_soc_write(codec, WCD934X_SOC_MAD_AUDIO_CTL_6,
  2378. mad_cal->audio_info.rms_threshold_msb);
  2379. for (idx = 0; idx < ARRAY_SIZE(mad_cal->audio_info.iir_coefficients);
  2380. idx++) {
  2381. snd_soc_update_bits(codec, WCD934X_SOC_MAD_AUDIO_IIR_CTL_PTR,
  2382. 0x3F, idx);
  2383. snd_soc_write(codec, WCD934X_SOC_MAD_AUDIO_IIR_CTL_VAL,
  2384. mad_cal->audio_info.iir_coefficients[idx]);
  2385. dev_dbg(codec->dev, "%s:MAD Audio IIR Coef[%d] = 0X%x",
  2386. __func__, idx,
  2387. mad_cal->audio_info.iir_coefficients[idx]);
  2388. }
  2389. /* Beacon */
  2390. snd_soc_write(codec, WCD934X_SOC_MAD_BEACON_CTL_8,
  2391. mad_cal->beacon_info.rms_omit_samples);
  2392. snd_soc_update_bits(codec, WCD934X_SOC_MAD_BEACON_CTL_1,
  2393. 0x07 << 4, mad_cal->beacon_info.rms_comp_time << 4);
  2394. snd_soc_update_bits(codec, WCD934X_SOC_MAD_BEACON_CTL_2, 0x03 << 2,
  2395. mad_cal->beacon_info.detection_mechanism << 2);
  2396. snd_soc_write(codec, WCD934X_SOC_MAD_BEACON_CTL_7,
  2397. mad_cal->beacon_info.rms_diff_threshold & 0x1F);
  2398. snd_soc_write(codec, WCD934X_SOC_MAD_BEACON_CTL_5,
  2399. mad_cal->beacon_info.rms_threshold_lsb);
  2400. snd_soc_write(codec, WCD934X_SOC_MAD_BEACON_CTL_6,
  2401. mad_cal->beacon_info.rms_threshold_msb);
  2402. for (idx = 0; idx < ARRAY_SIZE(mad_cal->beacon_info.iir_coefficients);
  2403. idx++) {
  2404. snd_soc_update_bits(codec, WCD934X_SOC_MAD_BEACON_IIR_CTL_PTR,
  2405. 0x3F, idx);
  2406. snd_soc_write(codec, WCD934X_SOC_MAD_BEACON_IIR_CTL_VAL,
  2407. mad_cal->beacon_info.iir_coefficients[idx]);
  2408. dev_dbg(codec->dev, "%s:MAD Beacon IIR Coef[%d] = 0X%x",
  2409. __func__, idx,
  2410. mad_cal->beacon_info.iir_coefficients[idx]);
  2411. }
  2412. /* Ultrasound */
  2413. snd_soc_update_bits(codec, WCD934X_SOC_MAD_ULTR_CTL_1,
  2414. 0x07 << 4,
  2415. mad_cal->ultrasound_info.rms_comp_time << 4);
  2416. snd_soc_update_bits(codec, WCD934X_SOC_MAD_ULTR_CTL_2, 0x03 << 2,
  2417. mad_cal->ultrasound_info.detection_mechanism << 2);
  2418. snd_soc_write(codec, WCD934X_SOC_MAD_ULTR_CTL_7,
  2419. mad_cal->ultrasound_info.rms_diff_threshold & 0x1F);
  2420. snd_soc_write(codec, WCD934X_SOC_MAD_ULTR_CTL_5,
  2421. mad_cal->ultrasound_info.rms_threshold_lsb);
  2422. snd_soc_write(codec, WCD934X_SOC_MAD_ULTR_CTL_6,
  2423. mad_cal->ultrasound_info.rms_threshold_msb);
  2424. done:
  2425. if (!hwdep_cal)
  2426. release_firmware(fw);
  2427. return ret;
  2428. }
  2429. static int __tavil_codec_enable_mad(struct snd_soc_codec *codec, bool enable)
  2430. {
  2431. int rc = 0;
  2432. /* Return if CPE INPUT is DEC1 */
  2433. if (snd_soc_read(codec, WCD934X_CPE_SS_SVA_CFG) & 0x04) {
  2434. dev_dbg(codec->dev, "%s: MAD is bypassed, skip mad %s\n",
  2435. __func__, enable ? "enable" : "disable");
  2436. return rc;
  2437. }
  2438. dev_dbg(codec->dev, "%s: enable = %s\n", __func__,
  2439. enable ? "enable" : "disable");
  2440. if (enable) {
  2441. snd_soc_update_bits(codec, WCD934X_SOC_MAD_AUDIO_CTL_2,
  2442. 0x03, 0x03);
  2443. rc = tavil_codec_config_mad(codec);
  2444. if (rc < 0) {
  2445. snd_soc_update_bits(codec, WCD934X_SOC_MAD_AUDIO_CTL_2,
  2446. 0x03, 0x00);
  2447. goto done;
  2448. }
  2449. /* Turn on MAD clk */
  2450. snd_soc_update_bits(codec, WCD934X_CPE_SS_MAD_CTL,
  2451. 0x01, 0x01);
  2452. /* Undo reset for MAD */
  2453. snd_soc_update_bits(codec, WCD934X_CPE_SS_MAD_CTL,
  2454. 0x02, 0x00);
  2455. snd_soc_update_bits(codec, WCD934X_CODEC_RPM_CLK_MCLK_CFG,
  2456. 0x04, 0x04);
  2457. } else {
  2458. snd_soc_update_bits(codec, WCD934X_SOC_MAD_AUDIO_CTL_2,
  2459. 0x03, 0x00);
  2460. /* Reset the MAD block */
  2461. snd_soc_update_bits(codec, WCD934X_CPE_SS_MAD_CTL,
  2462. 0x02, 0x02);
  2463. /* Turn off MAD clk */
  2464. snd_soc_update_bits(codec, WCD934X_CPE_SS_MAD_CTL,
  2465. 0x01, 0x00);
  2466. snd_soc_update_bits(codec, WCD934X_CODEC_RPM_CLK_MCLK_CFG,
  2467. 0x04, 0x00);
  2468. }
  2469. done:
  2470. return rc;
  2471. }
  2472. static int tavil_codec_ape_enable_mad(struct snd_soc_dapm_widget *w,
  2473. struct snd_kcontrol *kcontrol,
  2474. int event)
  2475. {
  2476. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2477. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  2478. int rc = 0;
  2479. switch (event) {
  2480. case SND_SOC_DAPM_PRE_PMU:
  2481. snd_soc_update_bits(codec, WCD934X_CPE_SS_SVA_CFG, 0x40, 0x40);
  2482. rc = __tavil_codec_enable_mad(codec, true);
  2483. break;
  2484. case SND_SOC_DAPM_PRE_PMD:
  2485. snd_soc_update_bits(codec, WCD934X_CPE_SS_SVA_CFG, 0x40, 0x00);
  2486. __tavil_codec_enable_mad(codec, false);
  2487. break;
  2488. }
  2489. dev_dbg(tavil->dev, "%s: event = %d\n", __func__, event);
  2490. return rc;
  2491. }
  2492. static int tavil_codec_cpe_mad_ctl(struct snd_soc_dapm_widget *w,
  2493. struct snd_kcontrol *kcontrol, int event)
  2494. {
  2495. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2496. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  2497. int rc = 0;
  2498. switch (event) {
  2499. case SND_SOC_DAPM_PRE_PMU:
  2500. tavil->mad_switch_cnt++;
  2501. if (tavil->mad_switch_cnt != 1)
  2502. goto done;
  2503. snd_soc_update_bits(codec, WCD934X_CPE_SS_SVA_CFG, 0x20, 0x20);
  2504. rc = __tavil_codec_enable_mad(codec, true);
  2505. if (rc < 0) {
  2506. tavil->mad_switch_cnt--;
  2507. goto done;
  2508. }
  2509. break;
  2510. case SND_SOC_DAPM_PRE_PMD:
  2511. tavil->mad_switch_cnt--;
  2512. if (tavil->mad_switch_cnt != 0)
  2513. goto done;
  2514. snd_soc_update_bits(codec, WCD934X_CPE_SS_SVA_CFG, 0x20, 0x00);
  2515. __tavil_codec_enable_mad(codec, false);
  2516. break;
  2517. }
  2518. done:
  2519. dev_dbg(tavil->dev, "%s: event = %d, mad_switch_cnt = %d\n",
  2520. __func__, event, tavil->mad_switch_cnt);
  2521. return rc;
  2522. }
  2523. static int tavil_get_asrc_mode(struct tavil_priv *tavil, int asrc,
  2524. u8 main_sr, u8 mix_sr)
  2525. {
  2526. u8 asrc_output_mode;
  2527. int asrc_mode = CONV_88P2K_TO_384K;
  2528. if ((asrc < 0) || (asrc >= ASRC_MAX))
  2529. return 0;
  2530. asrc_output_mode = tavil->asrc_output_mode[asrc];
  2531. if (asrc_output_mode) {
  2532. /*
  2533. * If Mix sample rate is < 96KHz, use 96K to 352.8K
  2534. * conversion, or else use 384K to 352.8K conversion
  2535. */
  2536. if (mix_sr < 5)
  2537. asrc_mode = CONV_96K_TO_352P8K;
  2538. else
  2539. asrc_mode = CONV_384K_TO_352P8K;
  2540. } else {
  2541. /* Integer main and Fractional mix path */
  2542. if (main_sr < 8 && mix_sr > 9) {
  2543. asrc_mode = CONV_352P8K_TO_384K;
  2544. } else if (main_sr > 8 && mix_sr < 8) {
  2545. /* Fractional main and Integer mix path */
  2546. if (mix_sr < 5)
  2547. asrc_mode = CONV_96K_TO_352P8K;
  2548. else
  2549. asrc_mode = CONV_384K_TO_352P8K;
  2550. } else if (main_sr < 8 && mix_sr < 8) {
  2551. /* Integer main and Integer mix path */
  2552. asrc_mode = CONV_96K_TO_384K;
  2553. }
  2554. }
  2555. return asrc_mode;
  2556. }
  2557. static int tavil_codec_wdma3_ctl(struct snd_soc_dapm_widget *w,
  2558. struct snd_kcontrol *kcontrol, int event)
  2559. {
  2560. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2561. switch (event) {
  2562. case SND_SOC_DAPM_PRE_PMU:
  2563. /* Fix to 16KHz */
  2564. snd_soc_update_bits(codec, WCD934X_DMA_WDMA_CTL_3,
  2565. 0xF0, 0x10);
  2566. /* Select mclk_1 */
  2567. snd_soc_update_bits(codec, WCD934X_DMA_WDMA_CTL_3,
  2568. 0x02, 0x00);
  2569. /* Enable DMA */
  2570. snd_soc_update_bits(codec, WCD934X_DMA_WDMA_CTL_3,
  2571. 0x01, 0x01);
  2572. break;
  2573. case SND_SOC_DAPM_POST_PMD:
  2574. /* Disable DMA */
  2575. snd_soc_update_bits(codec, WCD934X_DMA_WDMA_CTL_3,
  2576. 0x01, 0x00);
  2577. break;
  2578. };
  2579. return 0;
  2580. }
  2581. static int tavil_codec_enable_asrc(struct snd_soc_codec *codec,
  2582. int asrc_in, int event)
  2583. {
  2584. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  2585. u16 cfg_reg, ctl_reg, clk_reg, asrc_ctl, mix_ctl_reg, paired_reg;
  2586. int asrc, ret = 0;
  2587. u8 main_sr, mix_sr, asrc_mode = 0;
  2588. switch (asrc_in) {
  2589. case ASRC_IN_HPHL:
  2590. cfg_reg = WCD934X_CDC_RX1_RX_PATH_CFG0;
  2591. ctl_reg = WCD934X_CDC_RX1_RX_PATH_CTL;
  2592. clk_reg = WCD934X_MIXING_ASRC0_CLK_RST_CTL;
  2593. paired_reg = WCD934X_MIXING_ASRC1_CLK_RST_CTL;
  2594. asrc_ctl = WCD934X_MIXING_ASRC0_CTL1;
  2595. asrc = ASRC0;
  2596. break;
  2597. case ASRC_IN_LO1:
  2598. cfg_reg = WCD934X_CDC_RX3_RX_PATH_CFG0;
  2599. ctl_reg = WCD934X_CDC_RX3_RX_PATH_CTL;
  2600. clk_reg = WCD934X_MIXING_ASRC0_CLK_RST_CTL;
  2601. paired_reg = WCD934X_MIXING_ASRC1_CLK_RST_CTL;
  2602. asrc_ctl = WCD934X_MIXING_ASRC0_CTL1;
  2603. asrc = ASRC0;
  2604. break;
  2605. case ASRC_IN_HPHR:
  2606. cfg_reg = WCD934X_CDC_RX2_RX_PATH_CFG0;
  2607. ctl_reg = WCD934X_CDC_RX2_RX_PATH_CTL;
  2608. clk_reg = WCD934X_MIXING_ASRC1_CLK_RST_CTL;
  2609. paired_reg = WCD934X_MIXING_ASRC0_CLK_RST_CTL;
  2610. asrc_ctl = WCD934X_MIXING_ASRC1_CTL1;
  2611. asrc = ASRC1;
  2612. break;
  2613. case ASRC_IN_LO2:
  2614. cfg_reg = WCD934X_CDC_RX4_RX_PATH_CFG0;
  2615. ctl_reg = WCD934X_CDC_RX4_RX_PATH_CTL;
  2616. clk_reg = WCD934X_MIXING_ASRC1_CLK_RST_CTL;
  2617. paired_reg = WCD934X_MIXING_ASRC0_CLK_RST_CTL;
  2618. asrc_ctl = WCD934X_MIXING_ASRC1_CTL1;
  2619. asrc = ASRC1;
  2620. break;
  2621. case ASRC_IN_SPKR1:
  2622. cfg_reg = WCD934X_CDC_RX7_RX_PATH_CFG0;
  2623. ctl_reg = WCD934X_CDC_RX7_RX_PATH_CTL;
  2624. clk_reg = WCD934X_MIXING_ASRC2_CLK_RST_CTL;
  2625. paired_reg = WCD934X_MIXING_ASRC3_CLK_RST_CTL;
  2626. asrc_ctl = WCD934X_MIXING_ASRC2_CTL1;
  2627. asrc = ASRC2;
  2628. break;
  2629. case ASRC_IN_SPKR2:
  2630. cfg_reg = WCD934X_CDC_RX8_RX_PATH_CFG0;
  2631. ctl_reg = WCD934X_CDC_RX8_RX_PATH_CTL;
  2632. clk_reg = WCD934X_MIXING_ASRC3_CLK_RST_CTL;
  2633. paired_reg = WCD934X_MIXING_ASRC2_CLK_RST_CTL;
  2634. asrc_ctl = WCD934X_MIXING_ASRC3_CTL1;
  2635. asrc = ASRC3;
  2636. break;
  2637. default:
  2638. dev_err(codec->dev, "%s: Invalid asrc input :%d\n", __func__,
  2639. asrc_in);
  2640. ret = -EINVAL;
  2641. goto done;
  2642. };
  2643. switch (event) {
  2644. case SND_SOC_DAPM_PRE_PMU:
  2645. if (tavil->asrc_users[asrc] == 0) {
  2646. if ((snd_soc_read(codec, clk_reg) & 0x02) ||
  2647. (snd_soc_read(codec, paired_reg) & 0x02)) {
  2648. snd_soc_update_bits(codec, clk_reg,
  2649. 0x02, 0x00);
  2650. snd_soc_update_bits(codec, paired_reg,
  2651. 0x02, 0x00);
  2652. }
  2653. snd_soc_update_bits(codec, cfg_reg, 0x80, 0x80);
  2654. snd_soc_update_bits(codec, clk_reg, 0x01, 0x01);
  2655. main_sr = snd_soc_read(codec, ctl_reg) & 0x0F;
  2656. mix_ctl_reg = ctl_reg + 5;
  2657. mix_sr = snd_soc_read(codec, mix_ctl_reg) & 0x0F;
  2658. asrc_mode = tavil_get_asrc_mode(tavil, asrc,
  2659. main_sr, mix_sr);
  2660. dev_dbg(codec->dev, "%s: main_sr:%d mix_sr:%d asrc_mode %d\n",
  2661. __func__, main_sr, mix_sr, asrc_mode);
  2662. snd_soc_update_bits(codec, asrc_ctl, 0x07, asrc_mode);
  2663. }
  2664. tavil->asrc_users[asrc]++;
  2665. break;
  2666. case SND_SOC_DAPM_POST_PMD:
  2667. tavil->asrc_users[asrc]--;
  2668. if (tavil->asrc_users[asrc] <= 0) {
  2669. tavil->asrc_users[asrc] = 0;
  2670. snd_soc_update_bits(codec, asrc_ctl, 0x07, 0x00);
  2671. snd_soc_update_bits(codec, cfg_reg, 0x80, 0x00);
  2672. snd_soc_update_bits(codec, clk_reg, 0x03, 0x02);
  2673. }
  2674. break;
  2675. };
  2676. dev_dbg(codec->dev, "%s: ASRC%d, users: %d\n",
  2677. __func__, asrc, tavil->asrc_users[asrc]);
  2678. done:
  2679. return ret;
  2680. }
  2681. static int tavil_codec_enable_asrc_resampler(struct snd_soc_dapm_widget *w,
  2682. struct snd_kcontrol *kcontrol,
  2683. int event)
  2684. {
  2685. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2686. int ret = 0;
  2687. u8 cfg, asrc_in;
  2688. cfg = snd_soc_read(codec, WCD934X_CDC_RX_INP_MUX_SPLINE_ASRC_CFG0);
  2689. if (!(cfg & 0xFF)) {
  2690. dev_err(codec->dev, "%s: ASRC%u input not selected\n",
  2691. __func__, w->shift);
  2692. return -EINVAL;
  2693. }
  2694. switch (w->shift) {
  2695. case ASRC0:
  2696. asrc_in = ((cfg & 0x03) == 1) ? ASRC_IN_HPHL : ASRC_IN_LO1;
  2697. ret = tavil_codec_enable_asrc(codec, asrc_in, event);
  2698. break;
  2699. case ASRC1:
  2700. asrc_in = ((cfg & 0x0C) == 4) ? ASRC_IN_HPHR : ASRC_IN_LO2;
  2701. ret = tavil_codec_enable_asrc(codec, asrc_in, event);
  2702. break;
  2703. case ASRC2:
  2704. asrc_in = ((cfg & 0x30) == 0x20) ? ASRC_IN_SPKR1 : ASRC_INVALID;
  2705. ret = tavil_codec_enable_asrc(codec, asrc_in, event);
  2706. break;
  2707. case ASRC3:
  2708. asrc_in = ((cfg & 0xC0) == 0x80) ? ASRC_IN_SPKR2 : ASRC_INVALID;
  2709. ret = tavil_codec_enable_asrc(codec, asrc_in, event);
  2710. break;
  2711. default:
  2712. dev_err(codec->dev, "%s: Invalid asrc:%u\n", __func__,
  2713. w->shift);
  2714. ret = -EINVAL;
  2715. break;
  2716. };
  2717. return ret;
  2718. }
  2719. static int tavil_enable_native_supply(struct snd_soc_dapm_widget *w,
  2720. struct snd_kcontrol *kcontrol, int event)
  2721. {
  2722. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2723. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  2724. switch (event) {
  2725. case SND_SOC_DAPM_PRE_PMU:
  2726. if (++tavil->native_clk_users == 1) {
  2727. snd_soc_update_bits(codec, WCD934X_CLK_SYS_PLL_ENABLES,
  2728. 0x01, 0x01);
  2729. usleep_range(100, 120);
  2730. snd_soc_update_bits(codec, WCD934X_CLK_SYS_MCLK2_PRG1,
  2731. 0x06, 0x02);
  2732. snd_soc_update_bits(codec, WCD934X_CLK_SYS_MCLK2_PRG1,
  2733. 0x01, 0x01);
  2734. snd_soc_update_bits(codec, WCD934X_CODEC_RPM_CLK_GATE,
  2735. 0x04, 0x00);
  2736. usleep_range(30, 50);
  2737. snd_soc_update_bits(codec,
  2738. WCD934X_CDC_CLK_RST_CTRL_MCLK_CONTROL,
  2739. 0x02, 0x02);
  2740. snd_soc_update_bits(codec,
  2741. WCD934X_CDC_CLK_RST_CTRL_FS_CNT_CONTROL,
  2742. 0x10, 0x10);
  2743. }
  2744. break;
  2745. case SND_SOC_DAPM_PRE_PMD:
  2746. if (tavil->native_clk_users &&
  2747. (--tavil->native_clk_users == 0)) {
  2748. snd_soc_update_bits(codec,
  2749. WCD934X_CDC_CLK_RST_CTRL_FS_CNT_CONTROL,
  2750. 0x10, 0x00);
  2751. snd_soc_update_bits(codec,
  2752. WCD934X_CDC_CLK_RST_CTRL_MCLK_CONTROL,
  2753. 0x02, 0x00);
  2754. snd_soc_update_bits(codec, WCD934X_CODEC_RPM_CLK_GATE,
  2755. 0x04, 0x04);
  2756. snd_soc_update_bits(codec, WCD934X_CLK_SYS_MCLK2_PRG1,
  2757. 0x01, 0x00);
  2758. snd_soc_update_bits(codec, WCD934X_CLK_SYS_MCLK2_PRG1,
  2759. 0x06, 0x00);
  2760. snd_soc_update_bits(codec, WCD934X_CLK_SYS_PLL_ENABLES,
  2761. 0x01, 0x00);
  2762. }
  2763. break;
  2764. }
  2765. dev_dbg(codec->dev, "%s: native_clk_users: %d, event: %d\n",
  2766. __func__, tavil->native_clk_users, event);
  2767. return 0;
  2768. }
  2769. static void tavil_codec_hphdelay_lutbypass(struct snd_soc_codec *codec,
  2770. u16 interp_idx, int event)
  2771. {
  2772. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  2773. u8 hph_dly_mask;
  2774. u16 hph_lut_bypass_reg = 0;
  2775. u16 hph_comp_ctrl7 = 0;
  2776. switch (interp_idx) {
  2777. case INTERP_HPHL:
  2778. hph_dly_mask = 1;
  2779. hph_lut_bypass_reg = WCD934X_CDC_TOP_HPHL_COMP_LUT;
  2780. hph_comp_ctrl7 = WCD934X_CDC_COMPANDER1_CTL7;
  2781. break;
  2782. case INTERP_HPHR:
  2783. hph_dly_mask = 2;
  2784. hph_lut_bypass_reg = WCD934X_CDC_TOP_HPHR_COMP_LUT;
  2785. hph_comp_ctrl7 = WCD934X_CDC_COMPANDER2_CTL7;
  2786. break;
  2787. default:
  2788. break;
  2789. }
  2790. if (hph_lut_bypass_reg && SND_SOC_DAPM_EVENT_ON(event)) {
  2791. snd_soc_update_bits(codec, WCD934X_CDC_CLSH_TEST0,
  2792. hph_dly_mask, 0x0);
  2793. snd_soc_update_bits(codec, hph_lut_bypass_reg, 0x80, 0x80);
  2794. if (tavil->hph_mode == CLS_H_ULP)
  2795. snd_soc_update_bits(codec, hph_comp_ctrl7, 0x20, 0x20);
  2796. }
  2797. if (hph_lut_bypass_reg && SND_SOC_DAPM_EVENT_OFF(event)) {
  2798. snd_soc_update_bits(codec, WCD934X_CDC_CLSH_TEST0,
  2799. hph_dly_mask, hph_dly_mask);
  2800. snd_soc_update_bits(codec, hph_lut_bypass_reg, 0x80, 0x00);
  2801. snd_soc_update_bits(codec, hph_comp_ctrl7, 0x20, 0x0);
  2802. }
  2803. }
  2804. static void tavil_codec_hd2_control(struct tavil_priv *priv,
  2805. u16 interp_idx, int event)
  2806. {
  2807. u16 hd2_scale_reg;
  2808. u16 hd2_enable_reg = 0;
  2809. struct snd_soc_codec *codec = priv->codec;
  2810. if (TAVIL_IS_1_1(priv->wcd9xxx))
  2811. return;
  2812. switch (interp_idx) {
  2813. case INTERP_HPHL:
  2814. hd2_scale_reg = WCD934X_CDC_RX1_RX_PATH_SEC3;
  2815. hd2_enable_reg = WCD934X_CDC_RX1_RX_PATH_CFG0;
  2816. break;
  2817. case INTERP_HPHR:
  2818. hd2_scale_reg = WCD934X_CDC_RX2_RX_PATH_SEC3;
  2819. hd2_enable_reg = WCD934X_CDC_RX2_RX_PATH_CFG0;
  2820. break;
  2821. }
  2822. if (hd2_enable_reg && SND_SOC_DAPM_EVENT_ON(event)) {
  2823. snd_soc_update_bits(codec, hd2_scale_reg, 0x3C, 0x14);
  2824. snd_soc_update_bits(codec, hd2_enable_reg, 0x04, 0x04);
  2825. }
  2826. if (hd2_enable_reg && SND_SOC_DAPM_EVENT_OFF(event)) {
  2827. snd_soc_update_bits(codec, hd2_enable_reg, 0x04, 0x00);
  2828. snd_soc_update_bits(codec, hd2_scale_reg, 0x3C, 0x00);
  2829. }
  2830. }
  2831. static int tavil_codec_config_ear_spkr_gain(struct snd_soc_codec *codec,
  2832. int event, int gain_reg)
  2833. {
  2834. int comp_gain_offset, val;
  2835. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  2836. switch (tavil->swr.spkr_mode) {
  2837. /* Compander gain in SPKR_MODE1 case is 12 dB */
  2838. case WCD934X_SPKR_MODE_1:
  2839. comp_gain_offset = -12;
  2840. break;
  2841. /* Default case compander gain is 15 dB */
  2842. default:
  2843. comp_gain_offset = -15;
  2844. break;
  2845. }
  2846. switch (event) {
  2847. case SND_SOC_DAPM_POST_PMU:
  2848. /* Apply ear spkr gain only if compander is enabled */
  2849. if (tavil->comp_enabled[COMPANDER_7] &&
  2850. (gain_reg == WCD934X_CDC_RX7_RX_VOL_CTL ||
  2851. gain_reg == WCD934X_CDC_RX7_RX_VOL_MIX_CTL) &&
  2852. (tavil->ear_spkr_gain != 0)) {
  2853. /* For example, val is -8(-12+5-1) for 4dB of gain */
  2854. val = comp_gain_offset + tavil->ear_spkr_gain - 1;
  2855. snd_soc_write(codec, gain_reg, val);
  2856. dev_dbg(codec->dev, "%s: RX7 Volume %d dB\n",
  2857. __func__, val);
  2858. }
  2859. break;
  2860. case SND_SOC_DAPM_POST_PMD:
  2861. /*
  2862. * Reset RX7 volume to 0 dB if compander is enabled and
  2863. * ear_spkr_gain is non-zero.
  2864. */
  2865. if (tavil->comp_enabled[COMPANDER_7] &&
  2866. (gain_reg == WCD934X_CDC_RX7_RX_VOL_CTL ||
  2867. gain_reg == WCD934X_CDC_RX7_RX_VOL_MIX_CTL) &&
  2868. (tavil->ear_spkr_gain != 0)) {
  2869. snd_soc_write(codec, gain_reg, 0x0);
  2870. dev_dbg(codec->dev, "%s: Reset RX7 Volume to 0 dB\n",
  2871. __func__);
  2872. }
  2873. break;
  2874. }
  2875. return 0;
  2876. }
  2877. static int tavil_config_compander(struct snd_soc_codec *codec, int interp_n,
  2878. int event)
  2879. {
  2880. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  2881. int comp;
  2882. u16 comp_ctl0_reg, rx_path_cfg0_reg;
  2883. /* EAR does not have compander */
  2884. if (!interp_n)
  2885. return 0;
  2886. comp = interp_n - 1;
  2887. dev_dbg(codec->dev, "%s: event %d compander %d, enabled %d\n",
  2888. __func__, event, comp + 1, tavil->comp_enabled[comp]);
  2889. if (!tavil->comp_enabled[comp])
  2890. return 0;
  2891. comp_ctl0_reg = WCD934X_CDC_COMPANDER1_CTL0 + (comp * 8);
  2892. rx_path_cfg0_reg = WCD934X_CDC_RX1_RX_PATH_CFG0 + (comp * 20);
  2893. if (SND_SOC_DAPM_EVENT_ON(event)) {
  2894. /* Enable Compander Clock */
  2895. snd_soc_update_bits(codec, comp_ctl0_reg, 0x01, 0x01);
  2896. snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x02);
  2897. snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x00);
  2898. snd_soc_update_bits(codec, rx_path_cfg0_reg, 0x02, 0x02);
  2899. }
  2900. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  2901. snd_soc_update_bits(codec, rx_path_cfg0_reg, 0x02, 0x00);
  2902. snd_soc_update_bits(codec, comp_ctl0_reg, 0x04, 0x04);
  2903. snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x02);
  2904. snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x00);
  2905. snd_soc_update_bits(codec, comp_ctl0_reg, 0x01, 0x00);
  2906. snd_soc_update_bits(codec, comp_ctl0_reg, 0x04, 0x00);
  2907. }
  2908. return 0;
  2909. }
  2910. static void tavil_codec_idle_detect_control(struct snd_soc_codec *codec,
  2911. int interp, int event)
  2912. {
  2913. int reg = 0, mask, val;
  2914. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  2915. if (!tavil->idle_det_cfg.hph_idle_detect_en)
  2916. return;
  2917. if (interp == INTERP_HPHL) {
  2918. reg = WCD934X_CDC_RX_IDLE_DET_PATH_CTL;
  2919. mask = 0x01;
  2920. val = 0x01;
  2921. }
  2922. if (interp == INTERP_HPHR) {
  2923. reg = WCD934X_CDC_RX_IDLE_DET_PATH_CTL;
  2924. mask = 0x02;
  2925. val = 0x02;
  2926. }
  2927. if (reg && SND_SOC_DAPM_EVENT_ON(event))
  2928. snd_soc_update_bits(codec, reg, mask, val);
  2929. if (reg && SND_SOC_DAPM_EVENT_OFF(event)) {
  2930. snd_soc_update_bits(codec, reg, mask, 0x00);
  2931. tavil->idle_det_cfg.hph_idle_thr = 0;
  2932. snd_soc_write(codec, WCD934X_CDC_RX_IDLE_DET_CFG3, 0x0);
  2933. }
  2934. }
  2935. /**
  2936. * tavil_codec_enable_interp_clk - Enable main path Interpolator
  2937. * clock.
  2938. *
  2939. * @codec: Codec instance
  2940. * @event: Indicates speaker path gain offset value
  2941. * @intp_idx: Interpolator index
  2942. * Returns number of main clock users
  2943. */
  2944. int tavil_codec_enable_interp_clk(struct snd_soc_codec *codec,
  2945. int event, int interp_idx)
  2946. {
  2947. struct tavil_priv *tavil;
  2948. u16 main_reg;
  2949. if (!codec) {
  2950. pr_err("%s: codec is NULL\n", __func__);
  2951. return -EINVAL;
  2952. }
  2953. tavil = snd_soc_codec_get_drvdata(codec);
  2954. main_reg = WCD934X_CDC_RX0_RX_PATH_CTL + (interp_idx * 20);
  2955. if (SND_SOC_DAPM_EVENT_ON(event)) {
  2956. if (tavil->main_clk_users[interp_idx] == 0) {
  2957. /* Main path PGA mute enable */
  2958. snd_soc_update_bits(codec, main_reg, 0x10, 0x10);
  2959. /* Clk enable */
  2960. snd_soc_update_bits(codec, main_reg, 0x20, 0x20);
  2961. tavil_codec_idle_detect_control(codec, interp_idx,
  2962. event);
  2963. tavil_codec_hd2_control(tavil, interp_idx, event);
  2964. tavil_codec_hphdelay_lutbypass(codec, interp_idx,
  2965. event);
  2966. tavil_config_compander(codec, interp_idx, event);
  2967. }
  2968. tavil->main_clk_users[interp_idx]++;
  2969. }
  2970. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  2971. tavil->main_clk_users[interp_idx]--;
  2972. if (tavil->main_clk_users[interp_idx] <= 0) {
  2973. tavil->main_clk_users[interp_idx] = 0;
  2974. tavil_config_compander(codec, interp_idx, event);
  2975. tavil_codec_hphdelay_lutbypass(codec, interp_idx,
  2976. event);
  2977. tavil_codec_hd2_control(tavil, interp_idx, event);
  2978. tavil_codec_idle_detect_control(codec, interp_idx,
  2979. event);
  2980. /* Clk Disable */
  2981. snd_soc_update_bits(codec, main_reg, 0x20, 0x00);
  2982. /* Reset enable and disable */
  2983. snd_soc_update_bits(codec, main_reg, 0x40, 0x40);
  2984. snd_soc_update_bits(codec, main_reg, 0x40, 0x00);
  2985. /* Reset rate to 48K*/
  2986. snd_soc_update_bits(codec, main_reg, 0x0F, 0x04);
  2987. }
  2988. }
  2989. dev_dbg(codec->dev, "%s event %d main_clk_users %d\n",
  2990. __func__, event, tavil->main_clk_users[interp_idx]);
  2991. return tavil->main_clk_users[interp_idx];
  2992. }
  2993. EXPORT_SYMBOL(tavil_codec_enable_interp_clk);
  2994. static int tavil_anc_out_switch_cb(struct snd_soc_dapm_widget *w,
  2995. struct snd_kcontrol *kcontrol, int event)
  2996. {
  2997. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2998. tavil_codec_enable_interp_clk(codec, event, w->shift);
  2999. return 0;
  3000. }
  3001. static int tavil_codec_set_idle_detect_thr(struct snd_soc_codec *codec,
  3002. int interp, int path_type)
  3003. {
  3004. int port_id[4] = { 0, 0, 0, 0 };
  3005. int *port_ptr, num_ports;
  3006. int bit_width = 0, i;
  3007. int mux_reg, mux_reg_val;
  3008. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  3009. int dai_id, idle_thr;
  3010. if ((interp != INTERP_HPHL) && (interp != INTERP_HPHR))
  3011. return 0;
  3012. if (!tavil->idle_det_cfg.hph_idle_detect_en)
  3013. return 0;
  3014. port_ptr = &port_id[0];
  3015. num_ports = 0;
  3016. /*
  3017. * Read interpolator MUX input registers and find
  3018. * which slimbus port is connected and store the port
  3019. * numbers in port_id array.
  3020. */
  3021. if (path_type == INTERP_MIX_PATH) {
  3022. mux_reg = WCD934X_CDC_RX_INP_MUX_RX_INT1_CFG1 +
  3023. 2 * (interp - 1);
  3024. mux_reg_val = snd_soc_read(codec, mux_reg) & 0x0f;
  3025. if ((mux_reg_val >= INTn_2_INP_SEL_RX0) &&
  3026. (mux_reg_val < INTn_2_INP_SEL_PROXIMITY)) {
  3027. *port_ptr++ = mux_reg_val +
  3028. WCD934X_RX_PORT_START_NUMBER - 1;
  3029. num_ports++;
  3030. }
  3031. }
  3032. if (path_type == INTERP_MAIN_PATH) {
  3033. mux_reg = WCD934X_CDC_RX_INP_MUX_RX_INT1_CFG0 +
  3034. 2 * (interp - 1);
  3035. mux_reg_val = snd_soc_read(codec, mux_reg) & 0x0f;
  3036. i = WCD934X_INTERP_MUX_NUM_INPUTS;
  3037. while (i) {
  3038. if ((mux_reg_val >= INTn_1_INP_SEL_RX0) &&
  3039. (mux_reg_val <= INTn_1_INP_SEL_RX7)) {
  3040. *port_ptr++ = mux_reg_val +
  3041. WCD934X_RX_PORT_START_NUMBER -
  3042. INTn_1_INP_SEL_RX0;
  3043. num_ports++;
  3044. }
  3045. mux_reg_val = (snd_soc_read(codec, mux_reg) &
  3046. 0xf0) >> 4;
  3047. mux_reg += 1;
  3048. i--;
  3049. }
  3050. }
  3051. dev_dbg(codec->dev, "%s: num_ports: %d, ports[%d %d %d %d]\n",
  3052. __func__, num_ports, port_id[0], port_id[1],
  3053. port_id[2], port_id[3]);
  3054. i = 0;
  3055. while (num_ports) {
  3056. dai_id = tavil_find_playback_dai_id_for_port(port_id[i++],
  3057. tavil);
  3058. if ((dai_id >= 0) && (dai_id < NUM_CODEC_DAIS)) {
  3059. dev_dbg(codec->dev, "%s: dai_id: %d bit_width: %d\n",
  3060. __func__, dai_id,
  3061. tavil->dai[dai_id].bit_width);
  3062. if (tavil->dai[dai_id].bit_width > bit_width)
  3063. bit_width = tavil->dai[dai_id].bit_width;
  3064. }
  3065. num_ports--;
  3066. }
  3067. switch (bit_width) {
  3068. case 16:
  3069. idle_thr = 0xff; /* F16 */
  3070. break;
  3071. case 24:
  3072. case 32:
  3073. idle_thr = 0x03; /* F22 */
  3074. break;
  3075. default:
  3076. idle_thr = 0x00;
  3077. break;
  3078. }
  3079. dev_dbg(codec->dev, "%s: (new) idle_thr: %d, (cur) idle_thr: %d\n",
  3080. __func__, idle_thr, tavil->idle_det_cfg.hph_idle_thr);
  3081. if ((tavil->idle_det_cfg.hph_idle_thr == 0) ||
  3082. (idle_thr < tavil->idle_det_cfg.hph_idle_thr)) {
  3083. snd_soc_write(codec, WCD934X_CDC_RX_IDLE_DET_CFG3, idle_thr);
  3084. tavil->idle_det_cfg.hph_idle_thr = idle_thr;
  3085. }
  3086. return 0;
  3087. }
  3088. static int tavil_codec_enable_mix_path(struct snd_soc_dapm_widget *w,
  3089. struct snd_kcontrol *kcontrol,
  3090. int event)
  3091. {
  3092. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  3093. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  3094. u16 gain_reg, mix_reg;
  3095. int offset_val = 0;
  3096. int val = 0;
  3097. if (w->shift >= WCD934X_NUM_INTERPOLATORS ||
  3098. w->shift == INTERP_LO3_NA || w->shift == INTERP_LO4_NA) {
  3099. dev_err(codec->dev, "%s: Invalid Interpolator value %d for name %s\n",
  3100. __func__, w->shift, w->name);
  3101. return -EINVAL;
  3102. };
  3103. gain_reg = WCD934X_CDC_RX0_RX_VOL_MIX_CTL +
  3104. (w->shift * WCD934X_RX_PATH_CTL_OFFSET);
  3105. mix_reg = WCD934X_CDC_RX0_RX_PATH_MIX_CTL +
  3106. (w->shift * WCD934X_RX_PATH_CTL_OFFSET);
  3107. if (w->shift == INTERP_SPKR1 || w->shift == INTERP_SPKR2)
  3108. __tavil_codec_enable_swr(w, event);
  3109. switch (event) {
  3110. case SND_SOC_DAPM_PRE_PMU:
  3111. tavil_codec_set_idle_detect_thr(codec, w->shift,
  3112. INTERP_MIX_PATH);
  3113. tavil_codec_enable_interp_clk(codec, event, w->shift);
  3114. /* Clk enable */
  3115. snd_soc_update_bits(codec, mix_reg, 0x20, 0x20);
  3116. break;
  3117. case SND_SOC_DAPM_POST_PMU:
  3118. if ((tavil->swr.spkr_gain_offset ==
  3119. WCD934X_RX_GAIN_OFFSET_M1P5_DB) &&
  3120. (tavil->comp_enabled[COMPANDER_7] ||
  3121. tavil->comp_enabled[COMPANDER_8]) &&
  3122. (gain_reg == WCD934X_CDC_RX7_RX_VOL_MIX_CTL ||
  3123. gain_reg == WCD934X_CDC_RX8_RX_VOL_MIX_CTL)) {
  3124. snd_soc_update_bits(codec, WCD934X_CDC_RX7_RX_PATH_SEC1,
  3125. 0x01, 0x01);
  3126. snd_soc_update_bits(codec,
  3127. WCD934X_CDC_RX7_RX_PATH_MIX_SEC0,
  3128. 0x01, 0x01);
  3129. snd_soc_update_bits(codec, WCD934X_CDC_RX8_RX_PATH_SEC1,
  3130. 0x01, 0x01);
  3131. snd_soc_update_bits(codec,
  3132. WCD934X_CDC_RX8_RX_PATH_MIX_SEC0,
  3133. 0x01, 0x01);
  3134. offset_val = -2;
  3135. }
  3136. val = snd_soc_read(codec, gain_reg);
  3137. val += offset_val;
  3138. snd_soc_write(codec, gain_reg, val);
  3139. tavil_codec_config_ear_spkr_gain(codec, event, gain_reg);
  3140. break;
  3141. case SND_SOC_DAPM_POST_PMD:
  3142. /* Clk Disable */
  3143. snd_soc_update_bits(codec, mix_reg, 0x20, 0x00);
  3144. tavil_codec_enable_interp_clk(codec, event, w->shift);
  3145. /* Reset enable and disable */
  3146. snd_soc_update_bits(codec, mix_reg, 0x40, 0x40);
  3147. snd_soc_update_bits(codec, mix_reg, 0x40, 0x00);
  3148. if ((tavil->swr.spkr_gain_offset ==
  3149. WCD934X_RX_GAIN_OFFSET_M1P5_DB) &&
  3150. (tavil->comp_enabled[COMPANDER_7] ||
  3151. tavil->comp_enabled[COMPANDER_8]) &&
  3152. (gain_reg == WCD934X_CDC_RX7_RX_VOL_MIX_CTL ||
  3153. gain_reg == WCD934X_CDC_RX8_RX_VOL_MIX_CTL)) {
  3154. snd_soc_update_bits(codec, WCD934X_CDC_RX7_RX_PATH_SEC1,
  3155. 0x01, 0x00);
  3156. snd_soc_update_bits(codec,
  3157. WCD934X_CDC_RX7_RX_PATH_MIX_SEC0,
  3158. 0x01, 0x00);
  3159. snd_soc_update_bits(codec, WCD934X_CDC_RX8_RX_PATH_SEC1,
  3160. 0x01, 0x00);
  3161. snd_soc_update_bits(codec,
  3162. WCD934X_CDC_RX8_RX_PATH_MIX_SEC0,
  3163. 0x01, 0x00);
  3164. offset_val = 2;
  3165. val = snd_soc_read(codec, gain_reg);
  3166. val += offset_val;
  3167. snd_soc_write(codec, gain_reg, val);
  3168. }
  3169. tavil_codec_config_ear_spkr_gain(codec, event, gain_reg);
  3170. break;
  3171. };
  3172. dev_dbg(codec->dev, "%s event %d name %s\n", __func__, event, w->name);
  3173. return 0;
  3174. }
  3175. /**
  3176. * tavil_get_dsd_config - Get pointer to dsd config structure
  3177. *
  3178. * @codec: pointer to snd_soc_codec structure
  3179. *
  3180. * Returns pointer to tavil_dsd_config structure
  3181. */
  3182. struct tavil_dsd_config *tavil_get_dsd_config(struct snd_soc_codec *codec)
  3183. {
  3184. struct tavil_priv *tavil;
  3185. if (!codec)
  3186. return NULL;
  3187. tavil = snd_soc_codec_get_drvdata(codec);
  3188. if (!tavil)
  3189. return NULL;
  3190. return tavil->dsd_config;
  3191. }
  3192. EXPORT_SYMBOL(tavil_get_dsd_config);
  3193. static int tavil_codec_enable_main_path(struct snd_soc_dapm_widget *w,
  3194. struct snd_kcontrol *kcontrol,
  3195. int event)
  3196. {
  3197. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  3198. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  3199. u16 gain_reg;
  3200. u16 reg;
  3201. int val;
  3202. int offset_val = 0;
  3203. dev_dbg(codec->dev, "%s %d %s\n", __func__, event, w->name);
  3204. if (w->shift >= WCD934X_NUM_INTERPOLATORS ||
  3205. w->shift == INTERP_LO3_NA || w->shift == INTERP_LO4_NA) {
  3206. dev_err(codec->dev, "%s: Invalid Interpolator value %d for name %s\n",
  3207. __func__, w->shift, w->name);
  3208. return -EINVAL;
  3209. };
  3210. reg = WCD934X_CDC_RX0_RX_PATH_CTL + (w->shift *
  3211. WCD934X_RX_PATH_CTL_OFFSET);
  3212. gain_reg = WCD934X_CDC_RX0_RX_VOL_CTL + (w->shift *
  3213. WCD934X_RX_PATH_CTL_OFFSET);
  3214. switch (event) {
  3215. case SND_SOC_DAPM_PRE_PMU:
  3216. tavil_codec_set_idle_detect_thr(codec, w->shift,
  3217. INTERP_MAIN_PATH);
  3218. tavil_codec_enable_interp_clk(codec, event, w->shift);
  3219. break;
  3220. case SND_SOC_DAPM_POST_PMU:
  3221. /* apply gain after int clk is enabled */
  3222. if ((tavil->swr.spkr_gain_offset ==
  3223. WCD934X_RX_GAIN_OFFSET_M1P5_DB) &&
  3224. (tavil->comp_enabled[COMPANDER_7] ||
  3225. tavil->comp_enabled[COMPANDER_8]) &&
  3226. (gain_reg == WCD934X_CDC_RX7_RX_VOL_CTL ||
  3227. gain_reg == WCD934X_CDC_RX8_RX_VOL_CTL)) {
  3228. snd_soc_update_bits(codec, WCD934X_CDC_RX7_RX_PATH_SEC1,
  3229. 0x01, 0x01);
  3230. snd_soc_update_bits(codec,
  3231. WCD934X_CDC_RX7_RX_PATH_MIX_SEC0,
  3232. 0x01, 0x01);
  3233. snd_soc_update_bits(codec, WCD934X_CDC_RX8_RX_PATH_SEC1,
  3234. 0x01, 0x01);
  3235. snd_soc_update_bits(codec,
  3236. WCD934X_CDC_RX8_RX_PATH_MIX_SEC0,
  3237. 0x01, 0x01);
  3238. offset_val = -2;
  3239. }
  3240. val = snd_soc_read(codec, gain_reg);
  3241. val += offset_val;
  3242. snd_soc_write(codec, gain_reg, val);
  3243. tavil_codec_config_ear_spkr_gain(codec, event, gain_reg);
  3244. break;
  3245. case SND_SOC_DAPM_POST_PMD:
  3246. tavil_codec_enable_interp_clk(codec, event, w->shift);
  3247. if ((tavil->swr.spkr_gain_offset ==
  3248. WCD934X_RX_GAIN_OFFSET_M1P5_DB) &&
  3249. (tavil->comp_enabled[COMPANDER_7] ||
  3250. tavil->comp_enabled[COMPANDER_8]) &&
  3251. (gain_reg == WCD934X_CDC_RX7_RX_VOL_CTL ||
  3252. gain_reg == WCD934X_CDC_RX8_RX_VOL_CTL)) {
  3253. snd_soc_update_bits(codec, WCD934X_CDC_RX7_RX_PATH_SEC1,
  3254. 0x01, 0x00);
  3255. snd_soc_update_bits(codec,
  3256. WCD934X_CDC_RX7_RX_PATH_MIX_SEC0,
  3257. 0x01, 0x00);
  3258. snd_soc_update_bits(codec, WCD934X_CDC_RX8_RX_PATH_SEC1,
  3259. 0x01, 0x00);
  3260. snd_soc_update_bits(codec,
  3261. WCD934X_CDC_RX8_RX_PATH_MIX_SEC0,
  3262. 0x01, 0x00);
  3263. offset_val = 2;
  3264. val = snd_soc_read(codec, gain_reg);
  3265. val += offset_val;
  3266. snd_soc_write(codec, gain_reg, val);
  3267. }
  3268. tavil_codec_config_ear_spkr_gain(codec, event, gain_reg);
  3269. break;
  3270. };
  3271. return 0;
  3272. }
  3273. static int tavil_codec_set_iir_gain(struct snd_soc_dapm_widget *w,
  3274. struct snd_kcontrol *kcontrol, int event)
  3275. {
  3276. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  3277. dev_dbg(codec->dev, "%s: event = %d\n", __func__, event);
  3278. switch (event) {
  3279. case SND_SOC_DAPM_POST_PMU: /* fall through */
  3280. case SND_SOC_DAPM_PRE_PMD:
  3281. if (strnstr(w->name, "IIR0", sizeof("IIR0"))) {
  3282. snd_soc_write(codec,
  3283. WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B1_CTL,
  3284. snd_soc_read(codec,
  3285. WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B1_CTL));
  3286. snd_soc_write(codec,
  3287. WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B2_CTL,
  3288. snd_soc_read(codec,
  3289. WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B2_CTL));
  3290. snd_soc_write(codec,
  3291. WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B3_CTL,
  3292. snd_soc_read(codec,
  3293. WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B3_CTL));
  3294. snd_soc_write(codec,
  3295. WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B4_CTL,
  3296. snd_soc_read(codec,
  3297. WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B4_CTL));
  3298. } else {
  3299. snd_soc_write(codec,
  3300. WCD934X_CDC_SIDETONE_IIR1_IIR_GAIN_B1_CTL,
  3301. snd_soc_read(codec,
  3302. WCD934X_CDC_SIDETONE_IIR1_IIR_GAIN_B1_CTL));
  3303. snd_soc_write(codec,
  3304. WCD934X_CDC_SIDETONE_IIR1_IIR_GAIN_B2_CTL,
  3305. snd_soc_read(codec,
  3306. WCD934X_CDC_SIDETONE_IIR1_IIR_GAIN_B2_CTL));
  3307. snd_soc_write(codec,
  3308. WCD934X_CDC_SIDETONE_IIR1_IIR_GAIN_B3_CTL,
  3309. snd_soc_read(codec,
  3310. WCD934X_CDC_SIDETONE_IIR1_IIR_GAIN_B3_CTL));
  3311. }
  3312. break;
  3313. }
  3314. return 0;
  3315. }
  3316. static int tavil_codec_find_amic_input(struct snd_soc_codec *codec,
  3317. int adc_mux_n)
  3318. {
  3319. u16 mask, shift, adc_mux_in_reg;
  3320. u16 amic_mux_sel_reg;
  3321. bool is_amic;
  3322. if (adc_mux_n < 0 || adc_mux_n > WCD934X_MAX_VALID_ADC_MUX ||
  3323. adc_mux_n == WCD934X_INVALID_ADC_MUX)
  3324. return 0;
  3325. if (adc_mux_n < 3) {
  3326. adc_mux_in_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG1 +
  3327. adc_mux_n;
  3328. mask = 0x03;
  3329. shift = 0;
  3330. amic_mux_sel_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG0 +
  3331. 2 * adc_mux_n;
  3332. } else if (adc_mux_n < 4) {
  3333. adc_mux_in_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX3_CFG1;
  3334. mask = 0x03;
  3335. shift = 0;
  3336. amic_mux_sel_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG0 +
  3337. 2 * adc_mux_n;
  3338. } else if (adc_mux_n < 7) {
  3339. adc_mux_in_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG1 +
  3340. (adc_mux_n - 4);
  3341. mask = 0x0C;
  3342. shift = 2;
  3343. amic_mux_sel_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX4_CFG0 +
  3344. adc_mux_n - 4;
  3345. } else if (adc_mux_n < 8) {
  3346. adc_mux_in_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX3_CFG1;
  3347. mask = 0x0C;
  3348. shift = 2;
  3349. amic_mux_sel_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX4_CFG0 +
  3350. adc_mux_n - 4;
  3351. } else if (adc_mux_n < 12) {
  3352. adc_mux_in_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG1 +
  3353. ((adc_mux_n == 8) ? (adc_mux_n - 8) :
  3354. (adc_mux_n - 9));
  3355. mask = 0x30;
  3356. shift = 4;
  3357. amic_mux_sel_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX4_CFG0 +
  3358. adc_mux_n - 4;
  3359. } else if (adc_mux_n < 13) {
  3360. adc_mux_in_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX3_CFG1;
  3361. mask = 0x30;
  3362. shift = 4;
  3363. amic_mux_sel_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX4_CFG0 +
  3364. adc_mux_n - 4;
  3365. } else {
  3366. adc_mux_in_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG1;
  3367. mask = 0xC0;
  3368. shift = 6;
  3369. amic_mux_sel_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX4_CFG0 +
  3370. adc_mux_n - 4;
  3371. }
  3372. is_amic = (((snd_soc_read(codec, adc_mux_in_reg) & mask) >> shift)
  3373. == 1);
  3374. if (!is_amic)
  3375. return 0;
  3376. return snd_soc_read(codec, amic_mux_sel_reg) & 0x07;
  3377. }
  3378. static void tavil_codec_set_tx_hold(struct snd_soc_codec *codec,
  3379. u16 amic_reg, bool set)
  3380. {
  3381. u8 mask = 0x20;
  3382. u8 val;
  3383. if (amic_reg == WCD934X_ANA_AMIC1 ||
  3384. amic_reg == WCD934X_ANA_AMIC3)
  3385. mask = 0x40;
  3386. val = set ? mask : 0x00;
  3387. switch (amic_reg) {
  3388. case WCD934X_ANA_AMIC1:
  3389. case WCD934X_ANA_AMIC2:
  3390. snd_soc_update_bits(codec, WCD934X_ANA_AMIC2, mask, val);
  3391. break;
  3392. case WCD934X_ANA_AMIC3:
  3393. case WCD934X_ANA_AMIC4:
  3394. snd_soc_update_bits(codec, WCD934X_ANA_AMIC4, mask, val);
  3395. break;
  3396. default:
  3397. dev_dbg(codec->dev, "%s: invalid amic: %d\n",
  3398. __func__, amic_reg);
  3399. break;
  3400. }
  3401. }
  3402. static int tavil_codec_tx_adc_cfg(struct snd_soc_dapm_widget *w,
  3403. struct snd_kcontrol *kcontrol, int event)
  3404. {
  3405. int adc_mux_n = w->shift;
  3406. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  3407. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  3408. int amic_n;
  3409. dev_dbg(codec->dev, "%s: event: %d\n", __func__, event);
  3410. switch (event) {
  3411. case SND_SOC_DAPM_POST_PMU:
  3412. amic_n = tavil_codec_find_amic_input(codec, adc_mux_n);
  3413. if (amic_n) {
  3414. /*
  3415. * Prevent ANC Rx pop by leaving Tx FE in HOLD
  3416. * state until PA is up. Track AMIC being used
  3417. * so we can release the HOLD later.
  3418. */
  3419. set_bit(ANC_MIC_AMIC1 + amic_n - 1,
  3420. &tavil->status_mask);
  3421. }
  3422. break;
  3423. default:
  3424. break;
  3425. }
  3426. return 0;
  3427. }
  3428. static u16 tavil_codec_get_amic_pwlvl_reg(struct snd_soc_codec *codec, int amic)
  3429. {
  3430. u16 pwr_level_reg = 0;
  3431. switch (amic) {
  3432. case 1:
  3433. case 2:
  3434. pwr_level_reg = WCD934X_ANA_AMIC1;
  3435. break;
  3436. case 3:
  3437. case 4:
  3438. pwr_level_reg = WCD934X_ANA_AMIC3;
  3439. break;
  3440. default:
  3441. dev_dbg(codec->dev, "%s: invalid amic: %d\n",
  3442. __func__, amic);
  3443. break;
  3444. }
  3445. return pwr_level_reg;
  3446. }
  3447. #define TX_HPF_CUT_OFF_FREQ_MASK 0x60
  3448. #define CF_MIN_3DB_4HZ 0x0
  3449. #define CF_MIN_3DB_75HZ 0x1
  3450. #define CF_MIN_3DB_150HZ 0x2
  3451. static void tavil_tx_hpf_corner_freq_callback(struct work_struct *work)
  3452. {
  3453. struct delayed_work *hpf_delayed_work;
  3454. struct hpf_work *hpf_work;
  3455. struct tavil_priv *tavil;
  3456. struct snd_soc_codec *codec;
  3457. u16 dec_cfg_reg, amic_reg, go_bit_reg;
  3458. u8 hpf_cut_off_freq;
  3459. int amic_n;
  3460. hpf_delayed_work = to_delayed_work(work);
  3461. hpf_work = container_of(hpf_delayed_work, struct hpf_work, dwork);
  3462. tavil = hpf_work->tavil;
  3463. codec = tavil->codec;
  3464. hpf_cut_off_freq = hpf_work->hpf_cut_off_freq;
  3465. dec_cfg_reg = WCD934X_CDC_TX0_TX_PATH_CFG0 + 16 * hpf_work->decimator;
  3466. go_bit_reg = dec_cfg_reg + 7;
  3467. dev_dbg(codec->dev, "%s: decimator %u hpf_cut_of_freq 0x%x\n",
  3468. __func__, hpf_work->decimator, hpf_cut_off_freq);
  3469. amic_n = tavil_codec_find_amic_input(codec, hpf_work->decimator);
  3470. if (amic_n) {
  3471. amic_reg = WCD934X_ANA_AMIC1 + amic_n - 1;
  3472. tavil_codec_set_tx_hold(codec, amic_reg, false);
  3473. }
  3474. snd_soc_update_bits(codec, dec_cfg_reg, TX_HPF_CUT_OFF_FREQ_MASK,
  3475. hpf_cut_off_freq << 5);
  3476. snd_soc_update_bits(codec, go_bit_reg, 0x02, 0x02);
  3477. /* Minimum 1 clk cycle delay is required as per HW spec */
  3478. usleep_range(1000, 1010);
  3479. snd_soc_update_bits(codec, go_bit_reg, 0x02, 0x00);
  3480. }
  3481. static void tavil_tx_mute_update_callback(struct work_struct *work)
  3482. {
  3483. struct tx_mute_work *tx_mute_dwork;
  3484. struct tavil_priv *tavil;
  3485. struct delayed_work *delayed_work;
  3486. struct snd_soc_codec *codec;
  3487. u16 tx_vol_ctl_reg, hpf_gate_reg;
  3488. delayed_work = to_delayed_work(work);
  3489. tx_mute_dwork = container_of(delayed_work, struct tx_mute_work, dwork);
  3490. tavil = tx_mute_dwork->tavil;
  3491. codec = tavil->codec;
  3492. tx_vol_ctl_reg = WCD934X_CDC_TX0_TX_PATH_CTL +
  3493. 16 * tx_mute_dwork->decimator;
  3494. hpf_gate_reg = WCD934X_CDC_TX0_TX_PATH_SEC2 +
  3495. 16 * tx_mute_dwork->decimator;
  3496. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x10, 0x00);
  3497. }
  3498. static int tavil_codec_enable_rx_path_clk(struct snd_soc_dapm_widget *w,
  3499. struct snd_kcontrol *kcontrol, int event)
  3500. {
  3501. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  3502. u16 sidetone_reg;
  3503. dev_dbg(codec->dev, "%s %d %d\n", __func__, event, w->shift);
  3504. sidetone_reg = WCD934X_CDC_RX0_RX_PATH_CFG1 + 0x14*(w->shift);
  3505. switch (event) {
  3506. case SND_SOC_DAPM_PRE_PMU:
  3507. if (!strcmp(w->name, "RX INT7 MIX2 INP"))
  3508. __tavil_codec_enable_swr(w, event);
  3509. tavil_codec_enable_interp_clk(codec, event, w->shift);
  3510. snd_soc_update_bits(codec, sidetone_reg, 0x10, 0x10);
  3511. break;
  3512. case SND_SOC_DAPM_POST_PMD:
  3513. snd_soc_update_bits(codec, sidetone_reg, 0x10, 0x00);
  3514. tavil_codec_enable_interp_clk(codec, event, w->shift);
  3515. if (!strcmp(w->name, "RX INT7 MIX2 INP"))
  3516. __tavil_codec_enable_swr(w, event);
  3517. break;
  3518. default:
  3519. break;
  3520. };
  3521. return 0;
  3522. }
  3523. static int tavil_codec_enable_dec(struct snd_soc_dapm_widget *w,
  3524. struct snd_kcontrol *kcontrol, int event)
  3525. {
  3526. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  3527. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  3528. unsigned int decimator;
  3529. char *dec_adc_mux_name = NULL;
  3530. char *widget_name = NULL;
  3531. char *wname;
  3532. int ret = 0, amic_n;
  3533. u16 tx_vol_ctl_reg, pwr_level_reg = 0, dec_cfg_reg, hpf_gate_reg;
  3534. u16 tx_gain_ctl_reg;
  3535. char *dec;
  3536. u8 hpf_cut_off_freq;
  3537. dev_dbg(codec->dev, "%s %d\n", __func__, event);
  3538. widget_name = kstrndup(w->name, 15, GFP_KERNEL);
  3539. if (!widget_name)
  3540. return -ENOMEM;
  3541. wname = widget_name;
  3542. dec_adc_mux_name = strsep(&widget_name, " ");
  3543. if (!dec_adc_mux_name) {
  3544. dev_err(codec->dev, "%s: Invalid decimator = %s\n",
  3545. __func__, w->name);
  3546. ret = -EINVAL;
  3547. goto out;
  3548. }
  3549. dec_adc_mux_name = widget_name;
  3550. dec = strpbrk(dec_adc_mux_name, "012345678");
  3551. if (!dec) {
  3552. dev_err(codec->dev, "%s: decimator index not found\n",
  3553. __func__);
  3554. ret = -EINVAL;
  3555. goto out;
  3556. }
  3557. ret = kstrtouint(dec, 10, &decimator);
  3558. if (ret < 0) {
  3559. dev_err(codec->dev, "%s: Invalid decimator = %s\n",
  3560. __func__, wname);
  3561. ret = -EINVAL;
  3562. goto out;
  3563. }
  3564. dev_dbg(codec->dev, "%s(): widget = %s decimator = %u\n", __func__,
  3565. w->name, decimator);
  3566. tx_vol_ctl_reg = WCD934X_CDC_TX0_TX_PATH_CTL + 16 * decimator;
  3567. hpf_gate_reg = WCD934X_CDC_TX0_TX_PATH_SEC2 + 16 * decimator;
  3568. dec_cfg_reg = WCD934X_CDC_TX0_TX_PATH_CFG0 + 16 * decimator;
  3569. tx_gain_ctl_reg = WCD934X_CDC_TX0_TX_VOL_CTL + 16 * decimator;
  3570. switch (event) {
  3571. case SND_SOC_DAPM_PRE_PMU:
  3572. amic_n = tavil_codec_find_amic_input(codec, decimator);
  3573. if (amic_n)
  3574. pwr_level_reg = tavil_codec_get_amic_pwlvl_reg(codec,
  3575. amic_n);
  3576. if (pwr_level_reg) {
  3577. switch ((snd_soc_read(codec, pwr_level_reg) &
  3578. WCD934X_AMIC_PWR_LVL_MASK) >>
  3579. WCD934X_AMIC_PWR_LVL_SHIFT) {
  3580. case WCD934X_AMIC_PWR_LEVEL_LP:
  3581. snd_soc_update_bits(codec, dec_cfg_reg,
  3582. WCD934X_DEC_PWR_LVL_MASK,
  3583. WCD934X_DEC_PWR_LVL_LP);
  3584. break;
  3585. case WCD934X_AMIC_PWR_LEVEL_HP:
  3586. snd_soc_update_bits(codec, dec_cfg_reg,
  3587. WCD934X_DEC_PWR_LVL_MASK,
  3588. WCD934X_DEC_PWR_LVL_HP);
  3589. break;
  3590. case WCD934X_AMIC_PWR_LEVEL_DEFAULT:
  3591. case WCD934X_AMIC_PWR_LEVEL_HYBRID:
  3592. default:
  3593. snd_soc_update_bits(codec, dec_cfg_reg,
  3594. WCD934X_DEC_PWR_LVL_MASK,
  3595. WCD934X_DEC_PWR_LVL_DF);
  3596. break;
  3597. }
  3598. }
  3599. /* Enable TX PGA Mute */
  3600. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x10, 0x10);
  3601. break;
  3602. case SND_SOC_DAPM_POST_PMU:
  3603. hpf_cut_off_freq = (snd_soc_read(codec, dec_cfg_reg) &
  3604. TX_HPF_CUT_OFF_FREQ_MASK) >> 5;
  3605. tavil->tx_hpf_work[decimator].hpf_cut_off_freq =
  3606. hpf_cut_off_freq;
  3607. if (hpf_cut_off_freq != CF_MIN_3DB_150HZ) {
  3608. snd_soc_update_bits(codec, dec_cfg_reg,
  3609. TX_HPF_CUT_OFF_FREQ_MASK,
  3610. CF_MIN_3DB_150HZ << 5);
  3611. snd_soc_update_bits(codec, hpf_gate_reg, 0x02, 0x02);
  3612. /*
  3613. * Minimum 1 clk cycle delay is required as per
  3614. * HW spec.
  3615. */
  3616. usleep_range(1000, 1010);
  3617. snd_soc_update_bits(codec, hpf_gate_reg, 0x02, 0x00);
  3618. }
  3619. /* schedule work queue to Remove Mute */
  3620. schedule_delayed_work(&tavil->tx_mute_dwork[decimator].dwork,
  3621. msecs_to_jiffies(tx_unmute_delay));
  3622. if (tavil->tx_hpf_work[decimator].hpf_cut_off_freq !=
  3623. CF_MIN_3DB_150HZ)
  3624. schedule_delayed_work(
  3625. &tavil->tx_hpf_work[decimator].dwork,
  3626. msecs_to_jiffies(300));
  3627. /* apply gain after decimator is enabled */
  3628. snd_soc_write(codec, tx_gain_ctl_reg,
  3629. snd_soc_read(codec, tx_gain_ctl_reg));
  3630. break;
  3631. case SND_SOC_DAPM_PRE_PMD:
  3632. hpf_cut_off_freq =
  3633. tavil->tx_hpf_work[decimator].hpf_cut_off_freq;
  3634. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x10, 0x10);
  3635. if (cancel_delayed_work_sync(
  3636. &tavil->tx_hpf_work[decimator].dwork)) {
  3637. if (hpf_cut_off_freq != CF_MIN_3DB_150HZ) {
  3638. snd_soc_update_bits(codec, dec_cfg_reg,
  3639. TX_HPF_CUT_OFF_FREQ_MASK,
  3640. hpf_cut_off_freq << 5);
  3641. snd_soc_update_bits(codec, hpf_gate_reg,
  3642. 0x02, 0x02);
  3643. /*
  3644. * Minimum 1 clk cycle delay is required as per
  3645. * HW spec.
  3646. */
  3647. usleep_range(1000, 1010);
  3648. snd_soc_update_bits(codec, hpf_gate_reg,
  3649. 0x02, 0x00);
  3650. }
  3651. }
  3652. cancel_delayed_work_sync(
  3653. &tavil->tx_mute_dwork[decimator].dwork);
  3654. break;
  3655. case SND_SOC_DAPM_POST_PMD:
  3656. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x10, 0x00);
  3657. snd_soc_update_bits(codec, dec_cfg_reg,
  3658. WCD934X_DEC_PWR_LVL_MASK,
  3659. WCD934X_DEC_PWR_LVL_DF);
  3660. break;
  3661. };
  3662. out:
  3663. kfree(wname);
  3664. return ret;
  3665. }
  3666. static u32 tavil_get_dmic_sample_rate(struct snd_soc_codec *codec,
  3667. unsigned int dmic,
  3668. struct wcd9xxx_pdata *pdata)
  3669. {
  3670. u8 tx_stream_fs;
  3671. u8 adc_mux_index = 0, adc_mux_sel = 0;
  3672. bool dec_found = false;
  3673. u16 adc_mux_ctl_reg, tx_fs_reg;
  3674. u32 dmic_fs;
  3675. while (dec_found == 0 && adc_mux_index < WCD934X_MAX_VALID_ADC_MUX) {
  3676. if (adc_mux_index < 4) {
  3677. adc_mux_ctl_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG0 +
  3678. (adc_mux_index * 2);
  3679. } else if (adc_mux_index < WCD934X_INVALID_ADC_MUX) {
  3680. adc_mux_ctl_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX4_CFG0 +
  3681. adc_mux_index - 4;
  3682. } else if (adc_mux_index == WCD934X_INVALID_ADC_MUX) {
  3683. ++adc_mux_index;
  3684. continue;
  3685. }
  3686. adc_mux_sel = ((snd_soc_read(codec, adc_mux_ctl_reg) &
  3687. 0xF8) >> 3) - 1;
  3688. if (adc_mux_sel == dmic) {
  3689. dec_found = true;
  3690. break;
  3691. }
  3692. ++adc_mux_index;
  3693. }
  3694. if (dec_found && adc_mux_index <= 8) {
  3695. tx_fs_reg = WCD934X_CDC_TX0_TX_PATH_CTL + (16 * adc_mux_index);
  3696. tx_stream_fs = snd_soc_read(codec, tx_fs_reg) & 0x0F;
  3697. if (tx_stream_fs <= 4) {
  3698. if (pdata->dmic_sample_rate <=
  3699. WCD9XXX_DMIC_SAMPLE_RATE_2P4MHZ)
  3700. dmic_fs = pdata->dmic_sample_rate;
  3701. else
  3702. dmic_fs = WCD9XXX_DMIC_SAMPLE_RATE_2P4MHZ;
  3703. } else
  3704. dmic_fs = WCD9XXX_DMIC_SAMPLE_RATE_4P8MHZ;
  3705. } else {
  3706. dmic_fs = pdata->dmic_sample_rate;
  3707. }
  3708. return dmic_fs;
  3709. }
  3710. static u8 tavil_get_dmic_clk_val(struct snd_soc_codec *codec,
  3711. u32 mclk_rate, u32 dmic_clk_rate)
  3712. {
  3713. u32 div_factor;
  3714. u8 dmic_ctl_val;
  3715. dev_dbg(codec->dev,
  3716. "%s: mclk_rate = %d, dmic_sample_rate = %d\n",
  3717. __func__, mclk_rate, dmic_clk_rate);
  3718. /* Default value to return in case of error */
  3719. if (mclk_rate == WCD934X_MCLK_CLK_9P6MHZ)
  3720. dmic_ctl_val = WCD934X_DMIC_CLK_DIV_2;
  3721. else
  3722. dmic_ctl_val = WCD934X_DMIC_CLK_DIV_3;
  3723. if (dmic_clk_rate == 0) {
  3724. dev_err(codec->dev,
  3725. "%s: dmic_sample_rate cannot be 0\n",
  3726. __func__);
  3727. goto done;
  3728. }
  3729. div_factor = mclk_rate / dmic_clk_rate;
  3730. switch (div_factor) {
  3731. case 2:
  3732. dmic_ctl_val = WCD934X_DMIC_CLK_DIV_2;
  3733. break;
  3734. case 3:
  3735. dmic_ctl_val = WCD934X_DMIC_CLK_DIV_3;
  3736. break;
  3737. case 4:
  3738. dmic_ctl_val = WCD934X_DMIC_CLK_DIV_4;
  3739. break;
  3740. case 6:
  3741. dmic_ctl_val = WCD934X_DMIC_CLK_DIV_6;
  3742. break;
  3743. case 8:
  3744. dmic_ctl_val = WCD934X_DMIC_CLK_DIV_8;
  3745. break;
  3746. case 16:
  3747. dmic_ctl_val = WCD934X_DMIC_CLK_DIV_16;
  3748. break;
  3749. default:
  3750. dev_err(codec->dev,
  3751. "%s: Invalid div_factor %u, clk_rate(%u), dmic_rate(%u)\n",
  3752. __func__, div_factor, mclk_rate, dmic_clk_rate);
  3753. break;
  3754. }
  3755. done:
  3756. return dmic_ctl_val;
  3757. }
  3758. static int tavil_codec_enable_adc(struct snd_soc_dapm_widget *w,
  3759. struct snd_kcontrol *kcontrol, int event)
  3760. {
  3761. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  3762. dev_dbg(codec->dev, "%s: event:%d\n", __func__, event);
  3763. switch (event) {
  3764. case SND_SOC_DAPM_PRE_PMU:
  3765. tavil_codec_set_tx_hold(codec, w->reg, true);
  3766. break;
  3767. default:
  3768. break;
  3769. }
  3770. return 0;
  3771. }
  3772. static int tavil_codec_enable_dmic(struct snd_soc_dapm_widget *w,
  3773. struct snd_kcontrol *kcontrol, int event)
  3774. {
  3775. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  3776. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  3777. struct wcd9xxx_pdata *pdata = dev_get_platdata(codec->dev->parent);
  3778. u8 dmic_clk_en = 0x01;
  3779. u16 dmic_clk_reg;
  3780. s32 *dmic_clk_cnt;
  3781. u8 dmic_rate_val, dmic_rate_shift = 1;
  3782. unsigned int dmic;
  3783. u32 dmic_sample_rate;
  3784. int ret;
  3785. char *wname;
  3786. wname = strpbrk(w->name, "012345");
  3787. if (!wname) {
  3788. dev_err(codec->dev, "%s: widget not found\n", __func__);
  3789. return -EINVAL;
  3790. }
  3791. ret = kstrtouint(wname, 10, &dmic);
  3792. if (ret < 0) {
  3793. dev_err(codec->dev, "%s: Invalid DMIC line on the codec\n",
  3794. __func__);
  3795. return -EINVAL;
  3796. }
  3797. switch (dmic) {
  3798. case 0:
  3799. case 1:
  3800. dmic_clk_cnt = &(tavil->dmic_0_1_clk_cnt);
  3801. dmic_clk_reg = WCD934X_CPE_SS_DMIC0_CTL;
  3802. break;
  3803. case 2:
  3804. case 3:
  3805. dmic_clk_cnt = &(tavil->dmic_2_3_clk_cnt);
  3806. dmic_clk_reg = WCD934X_CPE_SS_DMIC1_CTL;
  3807. break;
  3808. case 4:
  3809. case 5:
  3810. dmic_clk_cnt = &(tavil->dmic_4_5_clk_cnt);
  3811. dmic_clk_reg = WCD934X_CPE_SS_DMIC2_CTL;
  3812. break;
  3813. default:
  3814. dev_err(codec->dev, "%s: Invalid DMIC Selection\n",
  3815. __func__);
  3816. return -EINVAL;
  3817. };
  3818. dev_dbg(codec->dev, "%s: event %d DMIC%d dmic_clk_cnt %d\n",
  3819. __func__, event, dmic, *dmic_clk_cnt);
  3820. switch (event) {
  3821. case SND_SOC_DAPM_PRE_PMU:
  3822. dmic_sample_rate = tavil_get_dmic_sample_rate(codec, dmic,
  3823. pdata);
  3824. dmic_rate_val =
  3825. tavil_get_dmic_clk_val(codec,
  3826. pdata->mclk_rate,
  3827. dmic_sample_rate);
  3828. (*dmic_clk_cnt)++;
  3829. if (*dmic_clk_cnt == 1) {
  3830. snd_soc_update_bits(codec, dmic_clk_reg,
  3831. 0x07 << dmic_rate_shift,
  3832. dmic_rate_val << dmic_rate_shift);
  3833. snd_soc_update_bits(codec, dmic_clk_reg,
  3834. dmic_clk_en, dmic_clk_en);
  3835. }
  3836. break;
  3837. case SND_SOC_DAPM_POST_PMD:
  3838. dmic_rate_val =
  3839. tavil_get_dmic_clk_val(codec,
  3840. pdata->mclk_rate,
  3841. pdata->mad_dmic_sample_rate);
  3842. (*dmic_clk_cnt)--;
  3843. if (*dmic_clk_cnt == 0) {
  3844. snd_soc_update_bits(codec, dmic_clk_reg,
  3845. dmic_clk_en, 0);
  3846. snd_soc_update_bits(codec, dmic_clk_reg,
  3847. 0x07 << dmic_rate_shift,
  3848. dmic_rate_val << dmic_rate_shift);
  3849. }
  3850. break;
  3851. };
  3852. return 0;
  3853. }
  3854. /*
  3855. * tavil_mbhc_micb_adjust_voltage: adjust specific micbias voltage
  3856. * @codec: handle to snd_soc_codec *
  3857. * @req_volt: micbias voltage to be set
  3858. * @micb_num: micbias to be set, e.g. micbias1 or micbias2
  3859. *
  3860. * return 0 if adjustment is success or error code in case of failure
  3861. */
  3862. int tavil_mbhc_micb_adjust_voltage(struct snd_soc_codec *codec,
  3863. int req_volt, int micb_num)
  3864. {
  3865. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  3866. int cur_vout_ctl, req_vout_ctl;
  3867. int micb_reg, micb_val, micb_en;
  3868. int ret = 0;
  3869. switch (micb_num) {
  3870. case MIC_BIAS_1:
  3871. micb_reg = WCD934X_ANA_MICB1;
  3872. break;
  3873. case MIC_BIAS_2:
  3874. micb_reg = WCD934X_ANA_MICB2;
  3875. break;
  3876. case MIC_BIAS_3:
  3877. micb_reg = WCD934X_ANA_MICB3;
  3878. break;
  3879. case MIC_BIAS_4:
  3880. micb_reg = WCD934X_ANA_MICB4;
  3881. break;
  3882. default:
  3883. return -EINVAL;
  3884. }
  3885. mutex_lock(&tavil->micb_lock);
  3886. /*
  3887. * If requested micbias voltage is same as current micbias
  3888. * voltage, then just return. Otherwise, adjust voltage as
  3889. * per requested value. If micbias is already enabled, then
  3890. * to avoid slow micbias ramp-up or down enable pull-up
  3891. * momentarily, change the micbias value and then re-enable
  3892. * micbias.
  3893. */
  3894. micb_val = snd_soc_read(codec, micb_reg);
  3895. micb_en = (micb_val & 0xC0) >> 6;
  3896. cur_vout_ctl = micb_val & 0x3F;
  3897. req_vout_ctl = wcd934x_get_micb_vout_ctl_val(req_volt);
  3898. if (req_vout_ctl < 0) {
  3899. ret = -EINVAL;
  3900. goto exit;
  3901. }
  3902. if (cur_vout_ctl == req_vout_ctl) {
  3903. ret = 0;
  3904. goto exit;
  3905. }
  3906. dev_dbg(codec->dev, "%s: micb_num: %d, cur_mv: %d, req_mv: %d, micb_en: %d\n",
  3907. __func__, micb_num, WCD_VOUT_CTL_TO_MICB(cur_vout_ctl),
  3908. req_volt, micb_en);
  3909. if (micb_en == 0x1)
  3910. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x80);
  3911. snd_soc_update_bits(codec, micb_reg, 0x3F, req_vout_ctl);
  3912. if (micb_en == 0x1) {
  3913. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x40);
  3914. /*
  3915. * Add 2ms delay as per HW requirement after enabling
  3916. * micbias
  3917. */
  3918. usleep_range(2000, 2100);
  3919. }
  3920. exit:
  3921. mutex_unlock(&tavil->micb_lock);
  3922. return ret;
  3923. }
  3924. EXPORT_SYMBOL(tavil_mbhc_micb_adjust_voltage);
  3925. /*
  3926. * tavil_micbias_control: enable/disable micbias
  3927. * @codec: handle to snd_soc_codec *
  3928. * @micb_num: micbias to be enabled/disabled, e.g. micbias1 or micbias2
  3929. * @req: control requested, enable/disable or pullup enable/disable
  3930. * @is_dapm: triggered by dapm or not
  3931. *
  3932. * return 0 if control is success or error code in case of failure
  3933. */
  3934. int tavil_micbias_control(struct snd_soc_codec *codec,
  3935. int micb_num, int req, bool is_dapm)
  3936. {
  3937. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  3938. int micb_index = micb_num - 1;
  3939. u16 micb_reg;
  3940. int pre_off_event = 0, post_off_event = 0;
  3941. int post_on_event = 0, post_dapm_off = 0;
  3942. int post_dapm_on = 0;
  3943. if ((micb_index < 0) || (micb_index > TAVIL_MAX_MICBIAS - 1)) {
  3944. dev_err(codec->dev, "%s: Invalid micbias index, micb_ind:%d\n",
  3945. __func__, micb_index);
  3946. return -EINVAL;
  3947. }
  3948. switch (micb_num) {
  3949. case MIC_BIAS_1:
  3950. micb_reg = WCD934X_ANA_MICB1;
  3951. break;
  3952. case MIC_BIAS_2:
  3953. micb_reg = WCD934X_ANA_MICB2;
  3954. pre_off_event = WCD_EVENT_PRE_MICBIAS_2_OFF;
  3955. post_off_event = WCD_EVENT_POST_MICBIAS_2_OFF;
  3956. post_on_event = WCD_EVENT_POST_MICBIAS_2_ON;
  3957. post_dapm_on = WCD_EVENT_POST_DAPM_MICBIAS_2_ON;
  3958. post_dapm_off = WCD_EVENT_POST_DAPM_MICBIAS_2_OFF;
  3959. break;
  3960. case MIC_BIAS_3:
  3961. micb_reg = WCD934X_ANA_MICB3;
  3962. break;
  3963. case MIC_BIAS_4:
  3964. micb_reg = WCD934X_ANA_MICB4;
  3965. break;
  3966. default:
  3967. dev_err(codec->dev, "%s: Invalid micbias number: %d\n",
  3968. __func__, micb_num);
  3969. return -EINVAL;
  3970. }
  3971. mutex_lock(&tavil->micb_lock);
  3972. switch (req) {
  3973. case MICB_PULLUP_ENABLE:
  3974. tavil->pullup_ref[micb_index]++;
  3975. if ((tavil->pullup_ref[micb_index] == 1) &&
  3976. (tavil->micb_ref[micb_index] == 0))
  3977. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x80);
  3978. break;
  3979. case MICB_PULLUP_DISABLE:
  3980. if (tavil->pullup_ref[micb_index] > 0)
  3981. tavil->pullup_ref[micb_index]--;
  3982. if ((tavil->pullup_ref[micb_index] == 0) &&
  3983. (tavil->micb_ref[micb_index] == 0))
  3984. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x00);
  3985. break;
  3986. case MICB_ENABLE:
  3987. tavil->micb_ref[micb_index]++;
  3988. if (tavil->micb_ref[micb_index] == 1) {
  3989. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x40);
  3990. if (post_on_event && tavil->mbhc)
  3991. blocking_notifier_call_chain(
  3992. &tavil->mbhc->notifier,
  3993. post_on_event,
  3994. &tavil->mbhc->wcd_mbhc);
  3995. }
  3996. if (is_dapm && post_dapm_on && tavil->mbhc)
  3997. blocking_notifier_call_chain(&tavil->mbhc->notifier,
  3998. post_dapm_on, &tavil->mbhc->wcd_mbhc);
  3999. break;
  4000. case MICB_DISABLE:
  4001. if (tavil->micb_ref[micb_index] > 0)
  4002. tavil->micb_ref[micb_index]--;
  4003. if ((tavil->micb_ref[micb_index] == 0) &&
  4004. (tavil->pullup_ref[micb_index] > 0))
  4005. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x80);
  4006. else if ((tavil->micb_ref[micb_index] == 0) &&
  4007. (tavil->pullup_ref[micb_index] == 0)) {
  4008. if (pre_off_event && tavil->mbhc)
  4009. blocking_notifier_call_chain(
  4010. &tavil->mbhc->notifier,
  4011. pre_off_event,
  4012. &tavil->mbhc->wcd_mbhc);
  4013. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x00);
  4014. if (post_off_event && tavil->mbhc)
  4015. blocking_notifier_call_chain(
  4016. &tavil->mbhc->notifier,
  4017. post_off_event,
  4018. &tavil->mbhc->wcd_mbhc);
  4019. }
  4020. if (is_dapm && post_dapm_off && tavil->mbhc)
  4021. blocking_notifier_call_chain(&tavil->mbhc->notifier,
  4022. post_dapm_off, &tavil->mbhc->wcd_mbhc);
  4023. break;
  4024. };
  4025. dev_dbg(codec->dev, "%s: micb_num:%d, micb_ref: %d, pullup_ref: %d\n",
  4026. __func__, micb_num, tavil->micb_ref[micb_index],
  4027. tavil->pullup_ref[micb_index]);
  4028. mutex_unlock(&tavil->micb_lock);
  4029. return 0;
  4030. }
  4031. EXPORT_SYMBOL(tavil_micbias_control);
  4032. static int __tavil_codec_enable_micbias(struct snd_soc_dapm_widget *w,
  4033. int event)
  4034. {
  4035. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  4036. int micb_num;
  4037. dev_dbg(codec->dev, "%s: wname: %s, event: %d\n",
  4038. __func__, w->name, event);
  4039. if (strnstr(w->name, "MIC BIAS1", sizeof("MIC BIAS1")))
  4040. micb_num = MIC_BIAS_1;
  4041. else if (strnstr(w->name, "MIC BIAS2", sizeof("MIC BIAS2")))
  4042. micb_num = MIC_BIAS_2;
  4043. else if (strnstr(w->name, "MIC BIAS3", sizeof("MIC BIAS3")))
  4044. micb_num = MIC_BIAS_3;
  4045. else if (strnstr(w->name, "MIC BIAS4", sizeof("MIC BIAS4")))
  4046. micb_num = MIC_BIAS_4;
  4047. else
  4048. return -EINVAL;
  4049. switch (event) {
  4050. case SND_SOC_DAPM_PRE_PMU:
  4051. /*
  4052. * MIC BIAS can also be requested by MBHC,
  4053. * so use ref count to handle micbias pullup
  4054. * and enable requests
  4055. */
  4056. tavil_micbias_control(codec, micb_num, MICB_ENABLE, true);
  4057. break;
  4058. case SND_SOC_DAPM_POST_PMU:
  4059. /* wait for cnp time */
  4060. usleep_range(1000, 1100);
  4061. break;
  4062. case SND_SOC_DAPM_POST_PMD:
  4063. tavil_micbias_control(codec, micb_num, MICB_DISABLE, true);
  4064. break;
  4065. };
  4066. return 0;
  4067. }
  4068. /*
  4069. * tavil_codec_enable_standalone_micbias - enable micbias standalone
  4070. * @codec: pointer to codec instance
  4071. * @micb_num: number of micbias to be enabled
  4072. * @enable: true to enable micbias or false to disable
  4073. *
  4074. * This function is used to enable micbias (1, 2, 3 or 4) during
  4075. * standalone independent of whether TX use-case is running or not
  4076. *
  4077. * Return: error code in case of failure or 0 for success
  4078. */
  4079. int tavil_codec_enable_standalone_micbias(struct snd_soc_codec *codec,
  4080. int micb_num,
  4081. bool enable)
  4082. {
  4083. const char * const micb_names[] = {
  4084. DAPM_MICBIAS1_STANDALONE, DAPM_MICBIAS2_STANDALONE,
  4085. DAPM_MICBIAS3_STANDALONE, DAPM_MICBIAS4_STANDALONE
  4086. };
  4087. int micb_index = micb_num - 1;
  4088. int rc;
  4089. if (!codec) {
  4090. pr_err("%s: Codec memory is NULL\n", __func__);
  4091. return -EINVAL;
  4092. }
  4093. if ((micb_index < 0) || (micb_index > TAVIL_MAX_MICBIAS - 1)) {
  4094. dev_err(codec->dev, "%s: Invalid micbias index, micb_ind:%d\n",
  4095. __func__, micb_index);
  4096. return -EINVAL;
  4097. }
  4098. if (enable)
  4099. rc = snd_soc_dapm_force_enable_pin(
  4100. snd_soc_codec_get_dapm(codec),
  4101. micb_names[micb_index]);
  4102. else
  4103. rc = snd_soc_dapm_disable_pin(snd_soc_codec_get_dapm(codec),
  4104. micb_names[micb_index]);
  4105. if (!rc)
  4106. snd_soc_dapm_sync(snd_soc_codec_get_dapm(codec));
  4107. else
  4108. dev_err(codec->dev, "%s: micbias%d force %s pin failed\n",
  4109. __func__, micb_num, (enable ? "enable" : "disable"));
  4110. return rc;
  4111. }
  4112. EXPORT_SYMBOL(tavil_codec_enable_standalone_micbias);
  4113. static int tavil_codec_force_enable_micbias(struct snd_soc_dapm_widget *w,
  4114. struct snd_kcontrol *kcontrol,
  4115. int event)
  4116. {
  4117. int ret = 0;
  4118. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  4119. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  4120. switch (event) {
  4121. case SND_SOC_DAPM_PRE_PMU:
  4122. wcd_resmgr_enable_master_bias(tavil->resmgr);
  4123. tavil_cdc_mclk_enable(codec, true);
  4124. ret = __tavil_codec_enable_micbias(w, SND_SOC_DAPM_PRE_PMU);
  4125. /* Wait for 1ms for better cnp */
  4126. usleep_range(1000, 1100);
  4127. tavil_cdc_mclk_enable(codec, false);
  4128. break;
  4129. case SND_SOC_DAPM_POST_PMD:
  4130. ret = __tavil_codec_enable_micbias(w, SND_SOC_DAPM_POST_PMD);
  4131. wcd_resmgr_disable_master_bias(tavil->resmgr);
  4132. break;
  4133. }
  4134. return ret;
  4135. }
  4136. static int tavil_codec_enable_micbias(struct snd_soc_dapm_widget *w,
  4137. struct snd_kcontrol *kcontrol, int event)
  4138. {
  4139. return __tavil_codec_enable_micbias(w, event);
  4140. }
  4141. static const struct reg_sequence tavil_hph_reset_tbl[] = {
  4142. { WCD934X_HPH_CNP_EN, 0x80 },
  4143. { WCD934X_HPH_CNP_WG_CTL, 0x9A },
  4144. { WCD934X_HPH_CNP_WG_TIME, 0x14 },
  4145. { WCD934X_HPH_OCP_CTL, 0x28 },
  4146. { WCD934X_HPH_AUTO_CHOP, 0x16 },
  4147. { WCD934X_HPH_CHOP_CTL, 0x83 },
  4148. { WCD934X_HPH_PA_CTL1, 0x46 },
  4149. { WCD934X_HPH_PA_CTL2, 0x50 },
  4150. { WCD934X_HPH_L_EN, 0x80 },
  4151. { WCD934X_HPH_L_TEST, 0xE0 },
  4152. { WCD934X_HPH_L_ATEST, 0x50 },
  4153. { WCD934X_HPH_R_EN, 0x80 },
  4154. { WCD934X_HPH_R_TEST, 0xE0 },
  4155. { WCD934X_HPH_R_ATEST, 0x54 },
  4156. { WCD934X_HPH_RDAC_CLK_CTL1, 0x99 },
  4157. { WCD934X_HPH_RDAC_CLK_CTL2, 0x9B },
  4158. { WCD934X_HPH_RDAC_LDO_CTL, 0x33 },
  4159. { WCD934X_HPH_RDAC_CHOP_CLK_LP_CTL, 0x00 },
  4160. { WCD934X_HPH_REFBUFF_UHQA_CTL, 0xA8 },
  4161. };
  4162. static const struct reg_sequence tavil_hph_reset_tbl_1_0[] = {
  4163. { WCD934X_HPH_REFBUFF_LP_CTL, 0x0A },
  4164. { WCD934X_HPH_L_DAC_CTL, 0x00 },
  4165. { WCD934X_HPH_R_DAC_CTL, 0x00 },
  4166. { WCD934X_HPH_NEW_ANA_HPH2, 0x00 },
  4167. { WCD934X_HPH_NEW_ANA_HPH3, 0x00 },
  4168. { WCD934X_HPH_NEW_INT_RDAC_GAIN_CTL, 0x00 },
  4169. { WCD934X_HPH_NEW_INT_RDAC_HD2_CTL, 0xA0 },
  4170. { WCD934X_HPH_NEW_INT_RDAC_VREF_CTL, 0x10 },
  4171. { WCD934X_HPH_NEW_INT_RDAC_OVERRIDE_CTL, 0x00 },
  4172. { WCD934X_HPH_NEW_INT_RDAC_MISC1, 0x00 },
  4173. { WCD934X_HPH_NEW_INT_PA_MISC1, 0x22 },
  4174. { WCD934X_HPH_NEW_INT_PA_MISC2, 0x00 },
  4175. { WCD934X_HPH_NEW_INT_PA_RDAC_MISC, 0x00 },
  4176. { WCD934X_HPH_NEW_INT_HPH_TIMER1, 0xFE },
  4177. { WCD934X_HPH_NEW_INT_HPH_TIMER2, 0x2 },
  4178. { WCD934X_HPH_NEW_INT_HPH_TIMER3, 0x4e},
  4179. { WCD934X_HPH_NEW_INT_HPH_TIMER4, 0x54 },
  4180. { WCD934X_HPH_NEW_INT_PA_RDAC_MISC2, 0x00 },
  4181. { WCD934X_HPH_NEW_INT_PA_RDAC_MISC3, 0x00 },
  4182. };
  4183. static const struct reg_sequence tavil_hph_reset_tbl_1_1[] = {
  4184. { WCD934X_HPH_REFBUFF_LP_CTL, 0x0E },
  4185. { WCD934X_HPH_L_DAC_CTL, 0x00 },
  4186. { WCD934X_HPH_R_DAC_CTL, 0x00 },
  4187. { WCD934X_HPH_NEW_ANA_HPH2, 0x00 },
  4188. { WCD934X_HPH_NEW_ANA_HPH3, 0x00 },
  4189. { WCD934X_HPH_NEW_INT_RDAC_GAIN_CTL, 0x40 },
  4190. { WCD934X_HPH_NEW_INT_RDAC_HD2_CTL, 0x81 },
  4191. { WCD934X_HPH_NEW_INT_RDAC_VREF_CTL, 0x10 },
  4192. { WCD934X_HPH_NEW_INT_RDAC_OVERRIDE_CTL, 0x00 },
  4193. { WCD934X_HPH_NEW_INT_RDAC_MISC1, 0x81 },
  4194. { WCD934X_HPH_NEW_INT_PA_MISC1, 0x22 },
  4195. { WCD934X_HPH_NEW_INT_PA_MISC2, 0x00 },
  4196. { WCD934X_HPH_NEW_INT_PA_RDAC_MISC, 0x00 },
  4197. { WCD934X_HPH_NEW_INT_HPH_TIMER1, 0xFE },
  4198. { WCD934X_HPH_NEW_INT_HPH_TIMER2, 0x2 },
  4199. { WCD934X_HPH_NEW_INT_HPH_TIMER3, 0x4e},
  4200. { WCD934X_HPH_NEW_INT_HPH_TIMER4, 0x54 },
  4201. { WCD934X_HPH_NEW_INT_PA_RDAC_MISC2, 0x00 },
  4202. { WCD934X_HPH_NEW_INT_PA_RDAC_MISC3, 0x00 },
  4203. };
  4204. static const struct tavil_reg_mask_val tavil_pa_disable[] = {
  4205. { WCD934X_CDC_RX1_RX_PATH_CTL, 0x30, 0x10 }, /* RX1 mute enable */
  4206. { WCD934X_CDC_RX2_RX_PATH_CTL, 0x30, 0x10 }, /* RX2 mute enable */
  4207. { WCD934X_HPH_CNP_WG_CTL, 0x80, 0x00 }, /* GM3 boost disable */
  4208. { WCD934X_ANA_HPH, 0x80, 0x00 }, /* HPHL PA disable */
  4209. { WCD934X_ANA_HPH, 0x40, 0x00 }, /* HPHR PA disable */
  4210. { WCD934X_ANA_HPH, 0x20, 0x00 }, /* HPHL REF dsable */
  4211. { WCD934X_ANA_HPH, 0x10, 0x00 }, /* HPHR REF disable */
  4212. };
  4213. static const struct tavil_reg_mask_val tavil_ocp_en_seq[] = {
  4214. { WCD934X_RX_OCP_CTL, 0x0F, 0x02 }, /* OCP number of attempts is 2 */
  4215. { WCD934X_HPH_OCP_CTL, 0xFA, 0x3A }, /* OCP current limit */
  4216. { WCD934X_HPH_L_TEST, 0x01, 0x01 }, /* Enable HPHL OCP */
  4217. { WCD934X_HPH_R_TEST, 0x01, 0x01 }, /* Enable HPHR OCP */
  4218. };
  4219. static const struct tavil_reg_mask_val tavil_ocp_en_seq_1[] = {
  4220. { WCD934X_RX_OCP_CTL, 0x0F, 0x02 }, /* OCP number of attempts is 2 */
  4221. { WCD934X_HPH_OCP_CTL, 0xFA, 0x3A }, /* OCP current limit */
  4222. };
  4223. /* LO-HIFI */
  4224. static const struct tavil_reg_mask_val tavil_pre_pa_en_lohifi[] = {
  4225. { WCD934X_HPH_NEW_INT_HPH_TIMER1, 0x02, 0x00 },
  4226. { WCD934X_FLYBACK_VNEG_CTRL_4, 0xf0, 0x80 },
  4227. { WCD934X_HPH_NEW_INT_PA_MISC2, 0x20, 0x20 },
  4228. { WCD934X_HPH_NEW_INT_RDAC_GAIN_CTL, 0xf0, 0x40 },
  4229. { WCD934X_HPH_CNP_WG_CTL, 0x80, 0x00 },
  4230. { WCD934X_RX_BIAS_HPH_LOWPOWER, 0xf0, 0xc0 },
  4231. { WCD934X_HPH_PA_CTL1, 0x0e, 0x02 },
  4232. { WCD934X_HPH_REFBUFF_LP_CTL, 0x06, 0x06 },
  4233. };
  4234. static const struct tavil_reg_mask_val tavil_pre_pa_en[] = {
  4235. { WCD934X_HPH_NEW_INT_HPH_TIMER1, 0x02, 0x00 },
  4236. { WCD934X_HPH_NEW_INT_PA_MISC2, 0x20, 0x0 },
  4237. { WCD934X_HPH_NEW_INT_RDAC_GAIN_CTL, 0xf0, 0x40 },
  4238. { WCD934X_HPH_CNP_WG_CTL, 0x80, 0x00 },
  4239. { WCD934X_RX_BIAS_HPH_LOWPOWER, 0xf0, 0x80 },
  4240. { WCD934X_HPH_PA_CTL1, 0x0e, 0x06 },
  4241. { WCD934X_HPH_REFBUFF_LP_CTL, 0x06, 0x06 },
  4242. };
  4243. static const struct tavil_reg_mask_val tavil_post_pa_en[] = {
  4244. { WCD934X_HPH_L_TEST, 0x01, 0x01 }, /* Enable HPHL OCP */
  4245. { WCD934X_HPH_R_TEST, 0x01, 0x01 }, /* Enable HPHR OCP */
  4246. { WCD934X_CDC_RX1_RX_PATH_CTL, 0x30, 0x20 }, /* RX1 mute disable */
  4247. { WCD934X_CDC_RX2_RX_PATH_CTL, 0x30, 0x20 }, /* RX2 mute disable */
  4248. { WCD934X_HPH_CNP_WG_CTL, 0x80, 0x80 }, /* GM3 boost enable */
  4249. { WCD934X_HPH_NEW_INT_HPH_TIMER1, 0x02, 0x02 },
  4250. };
  4251. static void tavil_codec_hph_reg_range_read(struct regmap *map, u8 *buf)
  4252. {
  4253. regmap_bulk_read(map, WCD934X_HPH_CNP_EN, buf, TAVIL_HPH_REG_RANGE_1);
  4254. regmap_bulk_read(map, WCD934X_HPH_NEW_ANA_HPH2,
  4255. buf + TAVIL_HPH_REG_RANGE_1, TAVIL_HPH_REG_RANGE_2);
  4256. regmap_bulk_read(map, WCD934X_HPH_NEW_INT_RDAC_GAIN_CTL,
  4257. buf + TAVIL_HPH_REG_RANGE_1 + TAVIL_HPH_REG_RANGE_2,
  4258. TAVIL_HPH_REG_RANGE_3);
  4259. }
  4260. static void tavil_codec_hph_reg_recover(struct tavil_priv *tavil,
  4261. struct regmap *map, int pa_status)
  4262. {
  4263. int i;
  4264. unsigned int reg;
  4265. blocking_notifier_call_chain(&tavil->mbhc->notifier,
  4266. WCD_EVENT_OCP_OFF,
  4267. &tavil->mbhc->wcd_mbhc);
  4268. if (pa_status & 0xC0)
  4269. goto pa_en_restore;
  4270. dev_dbg(tavil->dev, "%s: HPH PA in disable state (0x%x)\n",
  4271. __func__, pa_status);
  4272. regmap_write_bits(map, WCD934X_CDC_RX1_RX_PATH_CTL, 0x10, 0x10);
  4273. regmap_write_bits(map, WCD934X_CDC_RX2_RX_PATH_CTL, 0x10, 0x10);
  4274. regmap_write_bits(map, WCD934X_ANA_HPH, 0xC0, 0x00);
  4275. regmap_write_bits(map, WCD934X_ANA_HPH, 0x30, 0x00);
  4276. regmap_write_bits(map, WCD934X_CDC_RX1_RX_PATH_CTL, 0x10, 0x00);
  4277. regmap_write_bits(map, WCD934X_CDC_RX2_RX_PATH_CTL, 0x10, 0x00);
  4278. /* Restore to HW defaults */
  4279. regmap_multi_reg_write(map, tavil_hph_reset_tbl,
  4280. ARRAY_SIZE(tavil_hph_reset_tbl));
  4281. if (TAVIL_IS_1_1(tavil->wcd9xxx))
  4282. regmap_multi_reg_write(map, tavil_hph_reset_tbl_1_1,
  4283. ARRAY_SIZE(tavil_hph_reset_tbl_1_1));
  4284. if (TAVIL_IS_1_0(tavil->wcd9xxx))
  4285. regmap_multi_reg_write(map, tavil_hph_reset_tbl_1_0,
  4286. ARRAY_SIZE(tavil_hph_reset_tbl_1_0));
  4287. for (i = 0; i < ARRAY_SIZE(tavil_ocp_en_seq); i++)
  4288. regmap_write_bits(map, tavil_ocp_en_seq[i].reg,
  4289. tavil_ocp_en_seq[i].mask,
  4290. tavil_ocp_en_seq[i].val);
  4291. goto end;
  4292. pa_en_restore:
  4293. dev_dbg(tavil->dev, "%s: HPH PA in enable state (0x%x)\n",
  4294. __func__, pa_status);
  4295. /* Disable PA and other registers before restoring */
  4296. for (i = 0; i < ARRAY_SIZE(tavil_pa_disable); i++) {
  4297. if (TAVIL_IS_1_1(tavil->wcd9xxx) &&
  4298. (tavil_pa_disable[i].reg == WCD934X_HPH_CNP_WG_CTL))
  4299. continue;
  4300. regmap_write_bits(map, tavil_pa_disable[i].reg,
  4301. tavil_pa_disable[i].mask,
  4302. tavil_pa_disable[i].val);
  4303. }
  4304. regmap_multi_reg_write(map, tavil_hph_reset_tbl,
  4305. ARRAY_SIZE(tavil_hph_reset_tbl));
  4306. if (TAVIL_IS_1_1(tavil->wcd9xxx))
  4307. regmap_multi_reg_write(map, tavil_hph_reset_tbl_1_1,
  4308. ARRAY_SIZE(tavil_hph_reset_tbl_1_1));
  4309. if (TAVIL_IS_1_0(tavil->wcd9xxx))
  4310. regmap_multi_reg_write(map, tavil_hph_reset_tbl_1_0,
  4311. ARRAY_SIZE(tavil_hph_reset_tbl_1_0));
  4312. for (i = 0; i < ARRAY_SIZE(tavil_ocp_en_seq_1); i++)
  4313. regmap_write_bits(map, tavil_ocp_en_seq_1[i].reg,
  4314. tavil_ocp_en_seq_1[i].mask,
  4315. tavil_ocp_en_seq_1[i].val);
  4316. if (tavil->hph_mode == CLS_H_LOHIFI) {
  4317. for (i = 0; i < ARRAY_SIZE(tavil_pre_pa_en_lohifi); i++) {
  4318. reg = tavil_pre_pa_en_lohifi[i].reg;
  4319. if ((TAVIL_IS_1_1(tavil->wcd9xxx)) &&
  4320. ((reg == WCD934X_HPH_NEW_INT_RDAC_GAIN_CTL) ||
  4321. (reg == WCD934X_HPH_CNP_WG_CTL) ||
  4322. (reg == WCD934X_HPH_REFBUFF_LP_CTL)))
  4323. continue;
  4324. regmap_write_bits(map,
  4325. tavil_pre_pa_en_lohifi[i].reg,
  4326. tavil_pre_pa_en_lohifi[i].mask,
  4327. tavil_pre_pa_en_lohifi[i].val);
  4328. }
  4329. } else {
  4330. for (i = 0; i < ARRAY_SIZE(tavil_pre_pa_en); i++) {
  4331. reg = tavil_pre_pa_en[i].reg;
  4332. if ((TAVIL_IS_1_1(tavil->wcd9xxx)) &&
  4333. ((reg == WCD934X_HPH_NEW_INT_RDAC_GAIN_CTL) ||
  4334. (reg == WCD934X_HPH_CNP_WG_CTL) ||
  4335. (reg == WCD934X_HPH_REFBUFF_LP_CTL)))
  4336. continue;
  4337. regmap_write_bits(map, tavil_pre_pa_en[i].reg,
  4338. tavil_pre_pa_en[i].mask,
  4339. tavil_pre_pa_en[i].val);
  4340. }
  4341. }
  4342. if (TAVIL_IS_1_1(tavil->wcd9xxx)) {
  4343. regmap_write(map, WCD934X_HPH_NEW_INT_RDAC_HD2_CTL_L, 0x84);
  4344. regmap_write(map, WCD934X_HPH_NEW_INT_RDAC_HD2_CTL_R, 0x84);
  4345. }
  4346. regmap_write_bits(map, WCD934X_ANA_HPH, 0x0C, pa_status & 0x0C);
  4347. regmap_write_bits(map, WCD934X_ANA_HPH, 0x30, 0x30);
  4348. /* wait for 100usec after HPH DAC is enabled */
  4349. usleep_range(100, 110);
  4350. regmap_write(map, WCD934X_ANA_HPH, pa_status);
  4351. /* Sleep for 7msec after PA is enabled */
  4352. usleep_range(7000, 7100);
  4353. for (i = 0; i < ARRAY_SIZE(tavil_post_pa_en); i++) {
  4354. if ((TAVIL_IS_1_1(tavil->wcd9xxx)) &&
  4355. (tavil_post_pa_en[i].reg == WCD934X_HPH_CNP_WG_CTL))
  4356. continue;
  4357. regmap_write_bits(map, tavil_post_pa_en[i].reg,
  4358. tavil_post_pa_en[i].mask,
  4359. tavil_post_pa_en[i].val);
  4360. }
  4361. end:
  4362. tavil->mbhc->is_hph_recover = true;
  4363. blocking_notifier_call_chain(
  4364. &tavil->mbhc->notifier,
  4365. WCD_EVENT_OCP_ON,
  4366. &tavil->mbhc->wcd_mbhc);
  4367. }
  4368. static int tavil_codec_reset_hph_registers(struct snd_soc_dapm_widget *w,
  4369. struct snd_kcontrol *kcontrol,
  4370. int event)
  4371. {
  4372. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  4373. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  4374. struct wcd9xxx *wcd9xxx = dev_get_drvdata(codec->dev->parent);
  4375. u8 cache_val[TAVIL_HPH_TOTAL_REG];
  4376. u8 hw_val[TAVIL_HPH_TOTAL_REG];
  4377. int pa_status;
  4378. int ret;
  4379. dev_dbg(wcd9xxx->dev, "%s: event: %d\n", __func__, event);
  4380. switch (event) {
  4381. case SND_SOC_DAPM_PRE_PMU:
  4382. memset(cache_val, 0, TAVIL_HPH_TOTAL_REG);
  4383. memset(hw_val, 0, TAVIL_HPH_TOTAL_REG);
  4384. regmap_read(wcd9xxx->regmap, WCD934X_ANA_HPH, &pa_status);
  4385. tavil_codec_hph_reg_range_read(wcd9xxx->regmap, cache_val);
  4386. /* Read register values from HW directly */
  4387. regcache_cache_bypass(wcd9xxx->regmap, true);
  4388. tavil_codec_hph_reg_range_read(wcd9xxx->regmap, hw_val);
  4389. regcache_cache_bypass(wcd9xxx->regmap, false);
  4390. /* compare both the registers to know if there is corruption */
  4391. ret = memcmp(cache_val, hw_val, TAVIL_HPH_TOTAL_REG);
  4392. /* If both the values are same, it means no corruption */
  4393. if (ret) {
  4394. dev_dbg(codec->dev, "%s: cache and hw reg are not same\n",
  4395. __func__);
  4396. tavil_codec_hph_reg_recover(tavil, wcd9xxx->regmap,
  4397. pa_status);
  4398. } else {
  4399. dev_dbg(codec->dev, "%s: cache and hw reg are same\n",
  4400. __func__);
  4401. tavil->mbhc->is_hph_recover = false;
  4402. }
  4403. break;
  4404. default:
  4405. break;
  4406. };
  4407. return 0;
  4408. }
  4409. static void tavil_restore_iir_coeff(struct tavil_priv *tavil, int iir_idx,
  4410. int band_idx)
  4411. {
  4412. u16 reg_add;
  4413. int no_of_reg = 0;
  4414. regmap_write(tavil->wcd9xxx->regmap,
  4415. (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B1_CTL + 16 * iir_idx),
  4416. (band_idx * BAND_MAX * sizeof(uint32_t)) & 0x7F);
  4417. reg_add = WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL + 16 * iir_idx;
  4418. if (tavil->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS)
  4419. return;
  4420. /*
  4421. * Since wcd9xxx_slim_write_repeat() supports only maximum of 16
  4422. * registers at a time, split total 20 writes(5 coefficients per
  4423. * band and 4 writes per coefficient) into 16 and 4.
  4424. */
  4425. no_of_reg = WCD934X_CDC_REPEAT_WRITES_MAX;
  4426. wcd9xxx_slim_write_repeat(tavil->wcd9xxx, reg_add, no_of_reg,
  4427. &tavil->sidetone_coeff_array[iir_idx][band_idx][0]);
  4428. no_of_reg = (WCD934X_CDC_SIDETONE_IIR_COEFF_MAX * 4) -
  4429. WCD934X_CDC_REPEAT_WRITES_MAX;
  4430. wcd9xxx_slim_write_repeat(tavil->wcd9xxx, reg_add, no_of_reg,
  4431. &tavil->sidetone_coeff_array[iir_idx][band_idx]
  4432. [WCD934X_CDC_REPEAT_WRITES_MAX]);
  4433. }
  4434. static int tavil_iir_enable_audio_mixer_get(struct snd_kcontrol *kcontrol,
  4435. struct snd_ctl_elem_value *ucontrol)
  4436. {
  4437. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  4438. int iir_idx = ((struct soc_multi_mixer_control *)
  4439. kcontrol->private_value)->reg;
  4440. int band_idx = ((struct soc_multi_mixer_control *)
  4441. kcontrol->private_value)->shift;
  4442. /* IIR filter band registers are at integer multiples of 16 */
  4443. u16 iir_reg = WCD934X_CDC_SIDETONE_IIR0_IIR_CTL + 16 * iir_idx;
  4444. ucontrol->value.integer.value[0] = (snd_soc_read(codec, iir_reg) &
  4445. (1 << band_idx)) != 0;
  4446. dev_dbg(codec->dev, "%s: IIR #%d band #%d enable %d\n", __func__,
  4447. iir_idx, band_idx,
  4448. (uint32_t)ucontrol->value.integer.value[0]);
  4449. return 0;
  4450. }
  4451. static int tavil_iir_enable_audio_mixer_put(struct snd_kcontrol *kcontrol,
  4452. struct snd_ctl_elem_value *ucontrol)
  4453. {
  4454. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  4455. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  4456. int iir_idx = ((struct soc_multi_mixer_control *)
  4457. kcontrol->private_value)->reg;
  4458. int band_idx = ((struct soc_multi_mixer_control *)
  4459. kcontrol->private_value)->shift;
  4460. bool iir_band_en_status;
  4461. int value = ucontrol->value.integer.value[0];
  4462. u16 iir_reg = WCD934X_CDC_SIDETONE_IIR0_IIR_CTL + 16 * iir_idx;
  4463. tavil_restore_iir_coeff(tavil, iir_idx, band_idx);
  4464. /* Mask first 5 bits, 6-8 are reserved */
  4465. snd_soc_update_bits(codec, iir_reg, (1 << band_idx),
  4466. (value << band_idx));
  4467. iir_band_en_status = ((snd_soc_read(codec, iir_reg) &
  4468. (1 << band_idx)) != 0);
  4469. dev_dbg(codec->dev, "%s: IIR #%d band #%d enable %d\n", __func__,
  4470. iir_idx, band_idx, iir_band_en_status);
  4471. return 0;
  4472. }
  4473. static uint32_t get_iir_band_coeff(struct snd_soc_codec *codec,
  4474. int iir_idx, int band_idx,
  4475. int coeff_idx)
  4476. {
  4477. uint32_t value = 0;
  4478. /* Address does not automatically update if reading */
  4479. snd_soc_write(codec,
  4480. (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B1_CTL + 16 * iir_idx),
  4481. ((band_idx * BAND_MAX + coeff_idx)
  4482. * sizeof(uint32_t)) & 0x7F);
  4483. value |= snd_soc_read(codec,
  4484. (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL + 16 * iir_idx));
  4485. snd_soc_write(codec,
  4486. (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B1_CTL + 16 * iir_idx),
  4487. ((band_idx * BAND_MAX + coeff_idx)
  4488. * sizeof(uint32_t) + 1) & 0x7F);
  4489. value |= (snd_soc_read(codec,
  4490. (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL +
  4491. 16 * iir_idx)) << 8);
  4492. snd_soc_write(codec,
  4493. (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B1_CTL + 16 * iir_idx),
  4494. ((band_idx * BAND_MAX + coeff_idx)
  4495. * sizeof(uint32_t) + 2) & 0x7F);
  4496. value |= (snd_soc_read(codec,
  4497. (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL +
  4498. 16 * iir_idx)) << 16);
  4499. snd_soc_write(codec,
  4500. (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B1_CTL + 16 * iir_idx),
  4501. ((band_idx * BAND_MAX + coeff_idx)
  4502. * sizeof(uint32_t) + 3) & 0x7F);
  4503. /* Mask bits top 2 bits since they are reserved */
  4504. value |= ((snd_soc_read(codec,
  4505. (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL +
  4506. 16 * iir_idx)) & 0x3F) << 24);
  4507. return value;
  4508. }
  4509. static int tavil_iir_band_audio_mixer_get(struct snd_kcontrol *kcontrol,
  4510. struct snd_ctl_elem_value *ucontrol)
  4511. {
  4512. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  4513. int iir_idx = ((struct soc_multi_mixer_control *)
  4514. kcontrol->private_value)->reg;
  4515. int band_idx = ((struct soc_multi_mixer_control *)
  4516. kcontrol->private_value)->shift;
  4517. ucontrol->value.integer.value[0] =
  4518. get_iir_band_coeff(codec, iir_idx, band_idx, 0);
  4519. ucontrol->value.integer.value[1] =
  4520. get_iir_band_coeff(codec, iir_idx, band_idx, 1);
  4521. ucontrol->value.integer.value[2] =
  4522. get_iir_band_coeff(codec, iir_idx, band_idx, 2);
  4523. ucontrol->value.integer.value[3] =
  4524. get_iir_band_coeff(codec, iir_idx, band_idx, 3);
  4525. ucontrol->value.integer.value[4] =
  4526. get_iir_band_coeff(codec, iir_idx, band_idx, 4);
  4527. dev_dbg(codec->dev, "%s: IIR #%d band #%d b0 = 0x%x\n"
  4528. "%s: IIR #%d band #%d b1 = 0x%x\n"
  4529. "%s: IIR #%d band #%d b2 = 0x%x\n"
  4530. "%s: IIR #%d band #%d a1 = 0x%x\n"
  4531. "%s: IIR #%d band #%d a2 = 0x%x\n",
  4532. __func__, iir_idx, band_idx,
  4533. (uint32_t)ucontrol->value.integer.value[0],
  4534. __func__, iir_idx, band_idx,
  4535. (uint32_t)ucontrol->value.integer.value[1],
  4536. __func__, iir_idx, band_idx,
  4537. (uint32_t)ucontrol->value.integer.value[2],
  4538. __func__, iir_idx, band_idx,
  4539. (uint32_t)ucontrol->value.integer.value[3],
  4540. __func__, iir_idx, band_idx,
  4541. (uint32_t)ucontrol->value.integer.value[4]);
  4542. return 0;
  4543. }
  4544. static void set_iir_band_coeff(struct snd_soc_codec *codec,
  4545. int iir_idx, int band_idx,
  4546. uint32_t value)
  4547. {
  4548. snd_soc_write(codec,
  4549. (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL + 16 * iir_idx),
  4550. (value & 0xFF));
  4551. snd_soc_write(codec,
  4552. (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL + 16 * iir_idx),
  4553. (value >> 8) & 0xFF);
  4554. snd_soc_write(codec,
  4555. (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL + 16 * iir_idx),
  4556. (value >> 16) & 0xFF);
  4557. /* Mask top 2 bits, 7-8 are reserved */
  4558. snd_soc_write(codec,
  4559. (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL + 16 * iir_idx),
  4560. (value >> 24) & 0x3F);
  4561. }
  4562. static int tavil_iir_band_audio_mixer_put(struct snd_kcontrol *kcontrol,
  4563. struct snd_ctl_elem_value *ucontrol)
  4564. {
  4565. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  4566. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  4567. int iir_idx = ((struct soc_multi_mixer_control *)
  4568. kcontrol->private_value)->reg;
  4569. int band_idx = ((struct soc_multi_mixer_control *)
  4570. kcontrol->private_value)->shift;
  4571. int coeff_idx, idx = 0;
  4572. /*
  4573. * Mask top bit it is reserved
  4574. * Updates addr automatically for each B2 write
  4575. */
  4576. snd_soc_write(codec,
  4577. (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B1_CTL + 16 * iir_idx),
  4578. (band_idx * BAND_MAX * sizeof(uint32_t)) & 0x7F);
  4579. /* Store the coefficients in sidetone coeff array */
  4580. for (coeff_idx = 0; coeff_idx < WCD934X_CDC_SIDETONE_IIR_COEFF_MAX;
  4581. coeff_idx++) {
  4582. uint32_t value = ucontrol->value.integer.value[coeff_idx];
  4583. set_iir_band_coeff(codec, iir_idx, band_idx, value);
  4584. /* Four 8 bit values(one 32 bit) per coefficient */
  4585. tavil->sidetone_coeff_array[iir_idx][band_idx][idx++] =
  4586. (value & 0xFF);
  4587. tavil->sidetone_coeff_array[iir_idx][band_idx][idx++] =
  4588. (value >> 8) & 0xFF;
  4589. tavil->sidetone_coeff_array[iir_idx][band_idx][idx++] =
  4590. (value >> 16) & 0xFF;
  4591. tavil->sidetone_coeff_array[iir_idx][band_idx][idx++] =
  4592. (value >> 24) & 0xFF;
  4593. }
  4594. pr_debug("%s: IIR #%d band #%d b0 = 0x%x\n"
  4595. "%s: IIR #%d band #%d b1 = 0x%x\n"
  4596. "%s: IIR #%d band #%d b2 = 0x%x\n"
  4597. "%s: IIR #%d band #%d a1 = 0x%x\n"
  4598. "%s: IIR #%d band #%d a2 = 0x%x\n",
  4599. __func__, iir_idx, band_idx,
  4600. get_iir_band_coeff(codec, iir_idx, band_idx, 0),
  4601. __func__, iir_idx, band_idx,
  4602. get_iir_band_coeff(codec, iir_idx, band_idx, 1),
  4603. __func__, iir_idx, band_idx,
  4604. get_iir_band_coeff(codec, iir_idx, band_idx, 2),
  4605. __func__, iir_idx, band_idx,
  4606. get_iir_band_coeff(codec, iir_idx, band_idx, 3),
  4607. __func__, iir_idx, band_idx,
  4608. get_iir_band_coeff(codec, iir_idx, band_idx, 4));
  4609. return 0;
  4610. }
  4611. static int tavil_compander_get(struct snd_kcontrol *kcontrol,
  4612. struct snd_ctl_elem_value *ucontrol)
  4613. {
  4614. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  4615. int comp = ((struct soc_multi_mixer_control *)
  4616. kcontrol->private_value)->shift;
  4617. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  4618. ucontrol->value.integer.value[0] = tavil->comp_enabled[comp];
  4619. return 0;
  4620. }
  4621. static int tavil_compander_put(struct snd_kcontrol *kcontrol,
  4622. struct snd_ctl_elem_value *ucontrol)
  4623. {
  4624. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  4625. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  4626. int comp = ((struct soc_multi_mixer_control *)
  4627. kcontrol->private_value)->shift;
  4628. int value = ucontrol->value.integer.value[0];
  4629. dev_dbg(codec->dev, "%s: Compander %d enable current %d, new %d\n",
  4630. __func__, comp + 1, tavil->comp_enabled[comp], value);
  4631. tavil->comp_enabled[comp] = value;
  4632. /* Any specific register configuration for compander */
  4633. switch (comp) {
  4634. case COMPANDER_1:
  4635. /* Set Gain Source Select based on compander enable/disable */
  4636. snd_soc_update_bits(codec, WCD934X_HPH_L_EN, 0x20,
  4637. (value ? 0x00:0x20));
  4638. break;
  4639. case COMPANDER_2:
  4640. snd_soc_update_bits(codec, WCD934X_HPH_R_EN, 0x20,
  4641. (value ? 0x00:0x20));
  4642. break;
  4643. case COMPANDER_3:
  4644. case COMPANDER_4:
  4645. case COMPANDER_7:
  4646. case COMPANDER_8:
  4647. break;
  4648. default:
  4649. /*
  4650. * if compander is not enabled for any interpolator,
  4651. * it does not cause any audio failure, so do not
  4652. * return error in this case, but just print a log
  4653. */
  4654. dev_warn(codec->dev, "%s: unknown compander: %d\n",
  4655. __func__, comp);
  4656. };
  4657. return 0;
  4658. }
  4659. static int tavil_hph_asrc_mode_put(struct snd_kcontrol *kcontrol,
  4660. struct snd_ctl_elem_value *ucontrol)
  4661. {
  4662. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  4663. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  4664. int index = -EINVAL;
  4665. if (!strcmp(kcontrol->id.name, "ASRC0 Output Mode"))
  4666. index = ASRC0;
  4667. if (!strcmp(kcontrol->id.name, "ASRC1 Output Mode"))
  4668. index = ASRC1;
  4669. if (tavil && (index >= 0) && (index < ASRC_MAX))
  4670. tavil->asrc_output_mode[index] =
  4671. ucontrol->value.integer.value[0];
  4672. return 0;
  4673. }
  4674. static int tavil_hph_asrc_mode_get(struct snd_kcontrol *kcontrol,
  4675. struct snd_ctl_elem_value *ucontrol)
  4676. {
  4677. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  4678. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  4679. int val = 0;
  4680. int index = -EINVAL;
  4681. if (!strcmp(kcontrol->id.name, "ASRC0 Output Mode"))
  4682. index = ASRC0;
  4683. if (!strcmp(kcontrol->id.name, "ASRC1 Output Mode"))
  4684. index = ASRC1;
  4685. if (tavil && (index >= 0) && (index < ASRC_MAX))
  4686. val = tavil->asrc_output_mode[index];
  4687. ucontrol->value.integer.value[0] = val;
  4688. return 0;
  4689. }
  4690. static int tavil_hph_idle_detect_get(struct snd_kcontrol *kcontrol,
  4691. struct snd_ctl_elem_value *ucontrol)
  4692. {
  4693. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  4694. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  4695. int val = 0;
  4696. if (tavil)
  4697. val = tavil->idle_det_cfg.hph_idle_detect_en;
  4698. ucontrol->value.integer.value[0] = val;
  4699. return 0;
  4700. }
  4701. static int tavil_hph_idle_detect_put(struct snd_kcontrol *kcontrol,
  4702. struct snd_ctl_elem_value *ucontrol)
  4703. {
  4704. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  4705. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  4706. if (tavil)
  4707. tavil->idle_det_cfg.hph_idle_detect_en =
  4708. ucontrol->value.integer.value[0];
  4709. return 0;
  4710. }
  4711. static int tavil_dmic_pin_mode_get(struct snd_kcontrol *kcontrol,
  4712. struct snd_ctl_elem_value *ucontrol)
  4713. {
  4714. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  4715. u16 dmic_pin;
  4716. u8 reg_val, pinctl_position;
  4717. pinctl_position = ((struct soc_multi_mixer_control *)
  4718. kcontrol->private_value)->shift;
  4719. dmic_pin = pinctl_position & 0x07;
  4720. reg_val = snd_soc_read(codec,
  4721. WCD934X_TLMM_DMIC1_CLK_PINCFG + dmic_pin - 1);
  4722. ucontrol->value.integer.value[0] = !!reg_val;
  4723. return 0;
  4724. }
  4725. static int tavil_dmic_pin_mode_put(struct snd_kcontrol *kcontrol,
  4726. struct snd_ctl_elem_value *ucontrol)
  4727. {
  4728. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  4729. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  4730. u16 ctl_reg, cfg_reg, dmic_pin;
  4731. u8 ctl_val, cfg_val, pinctl_position, pinctl_mode, mask;
  4732. /* 0- high or low; 1- high Z */
  4733. pinctl_mode = ucontrol->value.integer.value[0];
  4734. pinctl_position = ((struct soc_multi_mixer_control *)
  4735. kcontrol->private_value)->shift;
  4736. switch (pinctl_position >> 3) {
  4737. case 0:
  4738. ctl_reg = WCD934X_TEST_DEBUG_PIN_CTL_OE_0;
  4739. break;
  4740. case 1:
  4741. ctl_reg = WCD934X_TEST_DEBUG_PIN_CTL_OE_1;
  4742. break;
  4743. case 2:
  4744. ctl_reg = WCD934X_TEST_DEBUG_PIN_CTL_OE_2;
  4745. break;
  4746. case 3:
  4747. ctl_reg = WCD934X_TEST_DEBUG_PIN_CTL_OE_3;
  4748. break;
  4749. default:
  4750. dev_err(codec->dev, "%s: Invalid pinctl position = %d\n",
  4751. __func__, pinctl_position);
  4752. return -EINVAL;
  4753. }
  4754. ctl_val = ~(pinctl_mode << (pinctl_position & 0x07));
  4755. mask = 1 << (pinctl_position & 0x07);
  4756. snd_soc_update_bits(codec, ctl_reg, mask, ctl_val);
  4757. dmic_pin = pinctl_position & 0x07;
  4758. cfg_reg = WCD934X_TLMM_DMIC1_CLK_PINCFG + dmic_pin - 1;
  4759. if (pinctl_mode) {
  4760. if (tavil->intf_type == WCD9XXX_INTERFACE_TYPE_SLIMBUS)
  4761. cfg_val = 0x6;
  4762. else
  4763. cfg_val = 0xD;
  4764. } else
  4765. cfg_val = 0;
  4766. snd_soc_update_bits(codec, cfg_reg, 0x1F, cfg_val);
  4767. dev_dbg(codec->dev, "%s: reg=0x%x mask=0x%x val=%d reg=0x%x val=%d\n",
  4768. __func__, ctl_reg, mask, ctl_val, cfg_reg, cfg_val);
  4769. return 0;
  4770. }
  4771. static int tavil_amic_pwr_lvl_get(struct snd_kcontrol *kcontrol,
  4772. struct snd_ctl_elem_value *ucontrol)
  4773. {
  4774. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  4775. u16 amic_reg = 0;
  4776. if (!strcmp(kcontrol->id.name, "AMIC_1_2 PWR MODE"))
  4777. amic_reg = WCD934X_ANA_AMIC1;
  4778. if (!strcmp(kcontrol->id.name, "AMIC_3_4 PWR MODE"))
  4779. amic_reg = WCD934X_ANA_AMIC3;
  4780. if (amic_reg)
  4781. ucontrol->value.integer.value[0] =
  4782. (snd_soc_read(codec, amic_reg) &
  4783. WCD934X_AMIC_PWR_LVL_MASK) >>
  4784. WCD934X_AMIC_PWR_LVL_SHIFT;
  4785. return 0;
  4786. }
  4787. static int tavil_amic_pwr_lvl_put(struct snd_kcontrol *kcontrol,
  4788. struct snd_ctl_elem_value *ucontrol)
  4789. {
  4790. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  4791. u32 mode_val;
  4792. u16 amic_reg = 0;
  4793. mode_val = ucontrol->value.enumerated.item[0];
  4794. dev_dbg(codec->dev, "%s: mode: %d\n", __func__, mode_val);
  4795. if (!strcmp(kcontrol->id.name, "AMIC_1_2 PWR MODE"))
  4796. amic_reg = WCD934X_ANA_AMIC1;
  4797. if (!strcmp(kcontrol->id.name, "AMIC_3_4 PWR MODE"))
  4798. amic_reg = WCD934X_ANA_AMIC3;
  4799. if (amic_reg)
  4800. snd_soc_update_bits(codec, amic_reg, WCD934X_AMIC_PWR_LVL_MASK,
  4801. mode_val << WCD934X_AMIC_PWR_LVL_SHIFT);
  4802. return 0;
  4803. }
  4804. static const char *const tavil_conn_mad_text[] = {
  4805. "NOTUSED1", "ADC1", "ADC2", "ADC3", "ADC4", "NOTUSED5",
  4806. "NOTUSED6", "NOTUSED2", "DMIC0", "DMIC1", "DMIC2", "DMIC3",
  4807. "DMIC4", "DMIC5", "NOTUSED3", "NOTUSED4"
  4808. };
  4809. static const struct soc_enum tavil_conn_mad_enum =
  4810. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(tavil_conn_mad_text),
  4811. tavil_conn_mad_text);
  4812. static int tavil_mad_input_get(struct snd_kcontrol *kcontrol,
  4813. struct snd_ctl_elem_value *ucontrol)
  4814. {
  4815. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  4816. u8 tavil_mad_input;
  4817. tavil_mad_input = snd_soc_read(codec, WCD934X_SOC_MAD_INP_SEL) & 0x0F;
  4818. ucontrol->value.integer.value[0] = tavil_mad_input;
  4819. dev_dbg(codec->dev, "%s: tavil_mad_input = %s\n", __func__,
  4820. tavil_conn_mad_text[tavil_mad_input]);
  4821. return 0;
  4822. }
  4823. static int tavil_mad_input_put(struct snd_kcontrol *kcontrol,
  4824. struct snd_ctl_elem_value *ucontrol)
  4825. {
  4826. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  4827. struct snd_soc_card *card = codec->component.card;
  4828. u8 tavil_mad_input;
  4829. char mad_amic_input_widget[6];
  4830. const char *mad_input_widget;
  4831. const char *source_widget = NULL;
  4832. u32 adc, i, mic_bias_found = 0;
  4833. int ret = 0;
  4834. char *mad_input;
  4835. bool is_adc_input = false;
  4836. tavil_mad_input = ucontrol->value.integer.value[0];
  4837. if (tavil_mad_input >= sizeof(tavil_conn_mad_text)/
  4838. sizeof(tavil_conn_mad_text[0])) {
  4839. dev_err(codec->dev,
  4840. "%s: tavil_mad_input = %d out of bounds\n",
  4841. __func__, tavil_mad_input);
  4842. return -EINVAL;
  4843. }
  4844. if (strnstr(tavil_conn_mad_text[tavil_mad_input], "NOTUSED",
  4845. sizeof("NOTUSED"))) {
  4846. dev_dbg(codec->dev,
  4847. "%s: Unsupported tavil_mad_input = %s\n",
  4848. __func__, tavil_conn_mad_text[tavil_mad_input]);
  4849. /* Make sure the MAD register is updated */
  4850. snd_soc_update_bits(codec, WCD934X_ANA_MAD_SETUP,
  4851. 0x88, 0x00);
  4852. return -EINVAL;
  4853. }
  4854. if (strnstr(tavil_conn_mad_text[tavil_mad_input],
  4855. "ADC", sizeof("ADC"))) {
  4856. mad_input = strpbrk(tavil_conn_mad_text[tavil_mad_input],
  4857. "1234");
  4858. if (!mad_input) {
  4859. dev_err(codec->dev, "%s: Invalid MAD input %s\n",
  4860. __func__, tavil_conn_mad_text[tavil_mad_input]);
  4861. return -EINVAL;
  4862. }
  4863. ret = kstrtouint(mad_input, 10, &adc);
  4864. if ((ret < 0) || (adc > 4)) {
  4865. dev_err(codec->dev, "%s: Invalid ADC = %s\n", __func__,
  4866. tavil_conn_mad_text[tavil_mad_input]);
  4867. return -EINVAL;
  4868. }
  4869. /*AMIC4 and AMIC5 share ADC4*/
  4870. if ((adc == 4) &&
  4871. (snd_soc_read(codec, WCD934X_TX_NEW_AMIC_4_5_SEL) & 0x10))
  4872. adc = 5;
  4873. snprintf(mad_amic_input_widget, 6, "%s%u", "AMIC", adc);
  4874. mad_input_widget = mad_amic_input_widget;
  4875. is_adc_input = true;
  4876. } else {
  4877. /* DMIC type input widget*/
  4878. mad_input_widget = tavil_conn_mad_text[tavil_mad_input];
  4879. }
  4880. dev_dbg(codec->dev,
  4881. "%s: tavil input widget = %s, adc_input = %s\n", __func__,
  4882. mad_input_widget, is_adc_input ? "true" : "false");
  4883. for (i = 0; i < card->num_of_dapm_routes; i++) {
  4884. if (!strcmp(card->of_dapm_routes[i].sink, mad_input_widget)) {
  4885. source_widget = card->of_dapm_routes[i].source;
  4886. if (!source_widget) {
  4887. dev_err(codec->dev,
  4888. "%s: invalid source widget\n",
  4889. __func__);
  4890. return -EINVAL;
  4891. }
  4892. if (strnstr(source_widget,
  4893. "MIC BIAS1", sizeof("MIC BIAS1"))) {
  4894. mic_bias_found = 1;
  4895. break;
  4896. } else if (strnstr(source_widget,
  4897. "MIC BIAS2", sizeof("MIC BIAS2"))) {
  4898. mic_bias_found = 2;
  4899. break;
  4900. } else if (strnstr(source_widget,
  4901. "MIC BIAS3", sizeof("MIC BIAS3"))) {
  4902. mic_bias_found = 3;
  4903. break;
  4904. } else if (strnstr(source_widget,
  4905. "MIC BIAS4", sizeof("MIC BIAS4"))) {
  4906. mic_bias_found = 4;
  4907. break;
  4908. }
  4909. }
  4910. }
  4911. if (!mic_bias_found) {
  4912. dev_err(codec->dev, "%s: mic bias not found for input %s\n",
  4913. __func__, mad_input_widget);
  4914. return -EINVAL;
  4915. }
  4916. dev_dbg(codec->dev, "%s: mic_bias found = %d\n", __func__,
  4917. mic_bias_found);
  4918. snd_soc_update_bits(codec, WCD934X_SOC_MAD_INP_SEL,
  4919. 0x0F, tavil_mad_input);
  4920. snd_soc_update_bits(codec, WCD934X_ANA_MAD_SETUP,
  4921. 0x07, mic_bias_found);
  4922. /* for all adc inputs, mad should be in micbias mode with BG enabled */
  4923. if (is_adc_input)
  4924. snd_soc_update_bits(codec, WCD934X_ANA_MAD_SETUP,
  4925. 0x88, 0x88);
  4926. else
  4927. snd_soc_update_bits(codec, WCD934X_ANA_MAD_SETUP,
  4928. 0x88, 0x00);
  4929. return 0;
  4930. }
  4931. static int tavil_ear_pa_gain_get(struct snd_kcontrol *kcontrol,
  4932. struct snd_ctl_elem_value *ucontrol)
  4933. {
  4934. u8 ear_pa_gain;
  4935. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  4936. ear_pa_gain = snd_soc_read(codec, WCD934X_ANA_EAR);
  4937. ear_pa_gain = (ear_pa_gain & 0x70) >> 4;
  4938. ucontrol->value.integer.value[0] = ear_pa_gain;
  4939. dev_dbg(codec->dev, "%s: ear_pa_gain = 0x%x\n", __func__,
  4940. ear_pa_gain);
  4941. return 0;
  4942. }
  4943. static int tavil_ear_pa_gain_put(struct snd_kcontrol *kcontrol,
  4944. struct snd_ctl_elem_value *ucontrol)
  4945. {
  4946. u8 ear_pa_gain;
  4947. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  4948. dev_dbg(codec->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  4949. __func__, ucontrol->value.integer.value[0]);
  4950. ear_pa_gain = ucontrol->value.integer.value[0] << 4;
  4951. snd_soc_update_bits(codec, WCD934X_ANA_EAR, 0x70, ear_pa_gain);
  4952. return 0;
  4953. }
  4954. static int tavil_ear_spkr_pa_gain_get(struct snd_kcontrol *kcontrol,
  4955. struct snd_ctl_elem_value *ucontrol)
  4956. {
  4957. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  4958. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  4959. ucontrol->value.integer.value[0] = tavil->ear_spkr_gain;
  4960. dev_dbg(codec->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  4961. __func__, ucontrol->value.integer.value[0]);
  4962. return 0;
  4963. }
  4964. static int tavil_ear_spkr_pa_gain_put(struct snd_kcontrol *kcontrol,
  4965. struct snd_ctl_elem_value *ucontrol)
  4966. {
  4967. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  4968. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  4969. tavil->ear_spkr_gain = ucontrol->value.integer.value[0];
  4970. dev_dbg(codec->dev, "%s: gain = %d\n", __func__, tavil->ear_spkr_gain);
  4971. return 0;
  4972. }
  4973. static int tavil_spkr_left_boost_stage_get(struct snd_kcontrol *kcontrol,
  4974. struct snd_ctl_elem_value *ucontrol)
  4975. {
  4976. u8 bst_state_max = 0;
  4977. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  4978. bst_state_max = snd_soc_read(codec, WCD934X_CDC_BOOST0_BOOST_CTL);
  4979. bst_state_max = (bst_state_max & 0x0c) >> 2;
  4980. ucontrol->value.integer.value[0] = bst_state_max;
  4981. dev_dbg(codec->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  4982. __func__, ucontrol->value.integer.value[0]);
  4983. return 0;
  4984. }
  4985. static int tavil_spkr_left_boost_stage_put(struct snd_kcontrol *kcontrol,
  4986. struct snd_ctl_elem_value *ucontrol)
  4987. {
  4988. u8 bst_state_max;
  4989. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  4990. dev_dbg(codec->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  4991. __func__, ucontrol->value.integer.value[0]);
  4992. bst_state_max = ucontrol->value.integer.value[0] << 2;
  4993. snd_soc_update_bits(codec, WCD934X_CDC_BOOST0_BOOST_CTL,
  4994. 0x0c, bst_state_max);
  4995. return 0;
  4996. }
  4997. static int tavil_spkr_right_boost_stage_get(struct snd_kcontrol *kcontrol,
  4998. struct snd_ctl_elem_value *ucontrol)
  4999. {
  5000. u8 bst_state_max = 0;
  5001. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  5002. bst_state_max = snd_soc_read(codec, WCD934X_CDC_BOOST1_BOOST_CTL);
  5003. bst_state_max = (bst_state_max & 0x0c) >> 2;
  5004. ucontrol->value.integer.value[0] = bst_state_max;
  5005. dev_dbg(codec->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  5006. __func__, ucontrol->value.integer.value[0]);
  5007. return 0;
  5008. }
  5009. static int tavil_spkr_right_boost_stage_put(struct snd_kcontrol *kcontrol,
  5010. struct snd_ctl_elem_value *ucontrol)
  5011. {
  5012. u8 bst_state_max;
  5013. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  5014. dev_dbg(codec->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  5015. __func__, ucontrol->value.integer.value[0]);
  5016. bst_state_max = ucontrol->value.integer.value[0] << 2;
  5017. snd_soc_update_bits(codec, WCD934X_CDC_BOOST1_BOOST_CTL,
  5018. 0x0c, bst_state_max);
  5019. return 0;
  5020. }
  5021. static int tavil_rx_hph_mode_get(struct snd_kcontrol *kcontrol,
  5022. struct snd_ctl_elem_value *ucontrol)
  5023. {
  5024. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  5025. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  5026. ucontrol->value.integer.value[0] = tavil->hph_mode;
  5027. return 0;
  5028. }
  5029. static int tavil_rx_hph_mode_put(struct snd_kcontrol *kcontrol,
  5030. struct snd_ctl_elem_value *ucontrol)
  5031. {
  5032. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  5033. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  5034. u32 mode_val;
  5035. mode_val = ucontrol->value.enumerated.item[0];
  5036. dev_dbg(codec->dev, "%s: mode: %d\n", __func__, mode_val);
  5037. if (mode_val == 0) {
  5038. dev_warn(codec->dev, "%s:Invalid HPH Mode, default to Cls-H LOHiFi\n",
  5039. __func__);
  5040. mode_val = CLS_H_LOHIFI;
  5041. }
  5042. tavil->hph_mode = mode_val;
  5043. return 0;
  5044. }
  5045. static const char * const rx_hph_mode_mux_text[] = {
  5046. "CLS_H_INVALID", "CLS_H_HIFI", "CLS_H_LP", "CLS_AB", "CLS_H_LOHIFI",
  5047. "CLS_H_ULP", "CLS_AB_HIFI",
  5048. };
  5049. static const struct soc_enum rx_hph_mode_mux_enum =
  5050. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(rx_hph_mode_mux_text),
  5051. rx_hph_mode_mux_text);
  5052. static const char *const tavil_anc_func_text[] = {"OFF", "ON"};
  5053. static const struct soc_enum tavil_anc_func_enum =
  5054. SOC_ENUM_SINGLE_EXT(2, tavil_anc_func_text);
  5055. static const char *const tavil_clkmode_text[] = {"EXTERNAL", "INTERNAL"};
  5056. static SOC_ENUM_SINGLE_EXT_DECL(tavil_clkmode_enum, tavil_clkmode_text);
  5057. /* Cutoff frequency for high pass filter */
  5058. static const char * const cf_text[] = {
  5059. "CF_NEG_3DB_4HZ", "CF_NEG_3DB_75HZ", "CF_NEG_3DB_150HZ"
  5060. };
  5061. static const char * const rx_cf_text[] = {
  5062. "CF_NEG_3DB_4HZ", "CF_NEG_3DB_75HZ", "CF_NEG_3DB_150HZ",
  5063. "CF_NEG_3DB_0P48HZ"
  5064. };
  5065. static const char * const amic_pwr_lvl_text[] = {
  5066. "LOW_PWR", "DEFAULT", "HIGH_PERF", "HYBRID"
  5067. };
  5068. static const char * const hph_idle_detect_text[] = {
  5069. "OFF", "ON"
  5070. };
  5071. static const char * const asrc_mode_text[] = {
  5072. "INT", "FRAC"
  5073. };
  5074. static const char * const tavil_ear_pa_gain_text[] = {
  5075. "G_6_DB", "G_4P5_DB", "G_3_DB", "G_1P5_DB",
  5076. "G_0_DB", "G_M2P5_DB", "UNDEFINED", "G_M12_DB"
  5077. };
  5078. static const char * const tavil_ear_spkr_pa_gain_text[] = {
  5079. "G_DEFAULT", "G_0_DB", "G_1_DB", "G_2_DB", "G_3_DB",
  5080. "G_4_DB", "G_5_DB", "G_6_DB"
  5081. };
  5082. static const char * const tavil_speaker_boost_stage_text[] = {
  5083. "NO_MAX_STATE", "MAX_STATE_1", "MAX_STATE_2"
  5084. };
  5085. static SOC_ENUM_SINGLE_EXT_DECL(tavil_ear_pa_gain_enum, tavil_ear_pa_gain_text);
  5086. static SOC_ENUM_SINGLE_EXT_DECL(tavil_ear_spkr_pa_gain_enum,
  5087. tavil_ear_spkr_pa_gain_text);
  5088. static SOC_ENUM_SINGLE_EXT_DECL(tavil_spkr_boost_stage_enum,
  5089. tavil_speaker_boost_stage_text);
  5090. static SOC_ENUM_SINGLE_EXT_DECL(amic_pwr_lvl_enum, amic_pwr_lvl_text);
  5091. static SOC_ENUM_SINGLE_EXT_DECL(hph_idle_detect_enum, hph_idle_detect_text);
  5092. static SOC_ENUM_SINGLE_EXT_DECL(asrc_mode_enum, asrc_mode_text);
  5093. static SOC_ENUM_SINGLE_DECL(cf_dec0_enum, WCD934X_CDC_TX0_TX_PATH_CFG0, 5,
  5094. cf_text);
  5095. static SOC_ENUM_SINGLE_DECL(cf_dec1_enum, WCD934X_CDC_TX1_TX_PATH_CFG0, 5,
  5096. cf_text);
  5097. static SOC_ENUM_SINGLE_DECL(cf_dec2_enum, WCD934X_CDC_TX2_TX_PATH_CFG0, 5,
  5098. cf_text);
  5099. static SOC_ENUM_SINGLE_DECL(cf_dec3_enum, WCD934X_CDC_TX3_TX_PATH_CFG0, 5,
  5100. cf_text);
  5101. static SOC_ENUM_SINGLE_DECL(cf_dec4_enum, WCD934X_CDC_TX4_TX_PATH_CFG0, 5,
  5102. cf_text);
  5103. static SOC_ENUM_SINGLE_DECL(cf_dec5_enum, WCD934X_CDC_TX5_TX_PATH_CFG0, 5,
  5104. cf_text);
  5105. static SOC_ENUM_SINGLE_DECL(cf_dec6_enum, WCD934X_CDC_TX6_TX_PATH_CFG0, 5,
  5106. cf_text);
  5107. static SOC_ENUM_SINGLE_DECL(cf_dec7_enum, WCD934X_CDC_TX7_TX_PATH_CFG0, 5,
  5108. cf_text);
  5109. static SOC_ENUM_SINGLE_DECL(cf_dec8_enum, WCD934X_CDC_TX8_TX_PATH_CFG0, 5,
  5110. cf_text);
  5111. static SOC_ENUM_SINGLE_DECL(cf_int0_1_enum, WCD934X_CDC_RX0_RX_PATH_CFG2, 0,
  5112. rx_cf_text);
  5113. static SOC_ENUM_SINGLE_DECL(cf_int0_2_enum, WCD934X_CDC_RX0_RX_PATH_MIX_CFG, 2,
  5114. rx_cf_text);
  5115. static SOC_ENUM_SINGLE_DECL(cf_int1_1_enum, WCD934X_CDC_RX1_RX_PATH_CFG2, 0,
  5116. rx_cf_text);
  5117. static SOC_ENUM_SINGLE_DECL(cf_int1_2_enum, WCD934X_CDC_RX1_RX_PATH_MIX_CFG, 2,
  5118. rx_cf_text);
  5119. static SOC_ENUM_SINGLE_DECL(cf_int2_1_enum, WCD934X_CDC_RX2_RX_PATH_CFG2, 0,
  5120. rx_cf_text);
  5121. static SOC_ENUM_SINGLE_DECL(cf_int2_2_enum, WCD934X_CDC_RX2_RX_PATH_MIX_CFG, 2,
  5122. rx_cf_text);
  5123. static SOC_ENUM_SINGLE_DECL(cf_int3_1_enum, WCD934X_CDC_RX3_RX_PATH_CFG2, 0,
  5124. rx_cf_text);
  5125. static SOC_ENUM_SINGLE_DECL(cf_int3_2_enum, WCD934X_CDC_RX3_RX_PATH_MIX_CFG, 2,
  5126. rx_cf_text);
  5127. static SOC_ENUM_SINGLE_DECL(cf_int4_1_enum, WCD934X_CDC_RX4_RX_PATH_CFG2, 0,
  5128. rx_cf_text);
  5129. static SOC_ENUM_SINGLE_DECL(cf_int4_2_enum, WCD934X_CDC_RX4_RX_PATH_MIX_CFG, 2,
  5130. rx_cf_text);
  5131. static SOC_ENUM_SINGLE_DECL(cf_int7_1_enum, WCD934X_CDC_RX7_RX_PATH_CFG2, 0,
  5132. rx_cf_text);
  5133. static SOC_ENUM_SINGLE_DECL(cf_int7_2_enum, WCD934X_CDC_RX7_RX_PATH_MIX_CFG, 2,
  5134. rx_cf_text);
  5135. static SOC_ENUM_SINGLE_DECL(cf_int8_1_enum, WCD934X_CDC_RX8_RX_PATH_CFG2, 0,
  5136. rx_cf_text);
  5137. static SOC_ENUM_SINGLE_DECL(cf_int8_2_enum, WCD934X_CDC_RX8_RX_PATH_MIX_CFG, 2,
  5138. rx_cf_text);
  5139. static const struct snd_kcontrol_new tavil_snd_controls[] = {
  5140. SOC_ENUM_EXT("EAR PA Gain", tavil_ear_pa_gain_enum,
  5141. tavil_ear_pa_gain_get, tavil_ear_pa_gain_put),
  5142. SOC_ENUM_EXT("EAR SPKR PA Gain", tavil_ear_spkr_pa_gain_enum,
  5143. tavil_ear_spkr_pa_gain_get, tavil_ear_spkr_pa_gain_put),
  5144. SOC_ENUM_EXT("SPKR Left Boost Max State", tavil_spkr_boost_stage_enum,
  5145. tavil_spkr_left_boost_stage_get,
  5146. tavil_spkr_left_boost_stage_put),
  5147. SOC_ENUM_EXT("SPKR Right Boost Max State", tavil_spkr_boost_stage_enum,
  5148. tavil_spkr_right_boost_stage_get,
  5149. tavil_spkr_right_boost_stage_put),
  5150. SOC_SINGLE_TLV("HPHL Volume", WCD934X_HPH_L_EN, 0, 20, 1, line_gain),
  5151. SOC_SINGLE_TLV("HPHR Volume", WCD934X_HPH_R_EN, 0, 20, 1, line_gain),
  5152. SOC_SINGLE_TLV("LINEOUT1 Volume", WCD934X_DIFF_LO_LO1_COMPANDER,
  5153. 3, 16, 1, line_gain),
  5154. SOC_SINGLE_TLV("LINEOUT2 Volume", WCD934X_DIFF_LO_LO2_COMPANDER,
  5155. 3, 16, 1, line_gain),
  5156. SOC_SINGLE_TLV("ADC1 Volume", WCD934X_ANA_AMIC1, 0, 20, 0, analog_gain),
  5157. SOC_SINGLE_TLV("ADC2 Volume", WCD934X_ANA_AMIC2, 0, 20, 0, analog_gain),
  5158. SOC_SINGLE_TLV("ADC3 Volume", WCD934X_ANA_AMIC3, 0, 20, 0, analog_gain),
  5159. SOC_SINGLE_TLV("ADC4 Volume", WCD934X_ANA_AMIC4, 0, 20, 0, analog_gain),
  5160. SOC_SINGLE_SX_TLV("RX0 Digital Volume", WCD934X_CDC_RX0_RX_VOL_CTL,
  5161. 0, -84, 40, digital_gain), /* -84dB min - 40dB max */
  5162. SOC_SINGLE_SX_TLV("RX1 Digital Volume", WCD934X_CDC_RX1_RX_VOL_CTL,
  5163. 0, -84, 40, digital_gain),
  5164. SOC_SINGLE_SX_TLV("RX2 Digital Volume", WCD934X_CDC_RX2_RX_VOL_CTL,
  5165. 0, -84, 40, digital_gain),
  5166. SOC_SINGLE_SX_TLV("RX3 Digital Volume", WCD934X_CDC_RX3_RX_VOL_CTL,
  5167. 0, -84, 40, digital_gain),
  5168. SOC_SINGLE_SX_TLV("RX4 Digital Volume", WCD934X_CDC_RX4_RX_VOL_CTL,
  5169. 0, -84, 40, digital_gain),
  5170. SOC_SINGLE_SX_TLV("RX7 Digital Volume", WCD934X_CDC_RX7_RX_VOL_CTL,
  5171. 0, -84, 40, digital_gain),
  5172. SOC_SINGLE_SX_TLV("RX8 Digital Volume", WCD934X_CDC_RX8_RX_VOL_CTL,
  5173. 0, -84, 40, digital_gain),
  5174. SOC_SINGLE_SX_TLV("RX0 Mix Digital Volume",
  5175. WCD934X_CDC_RX0_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain),
  5176. SOC_SINGLE_SX_TLV("RX1 Mix Digital Volume",
  5177. WCD934X_CDC_RX1_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain),
  5178. SOC_SINGLE_SX_TLV("RX2 Mix Digital Volume",
  5179. WCD934X_CDC_RX2_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain),
  5180. SOC_SINGLE_SX_TLV("RX3 Mix Digital Volume",
  5181. WCD934X_CDC_RX3_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain),
  5182. SOC_SINGLE_SX_TLV("RX4 Mix Digital Volume",
  5183. WCD934X_CDC_RX4_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain),
  5184. SOC_SINGLE_SX_TLV("RX7 Mix Digital Volume",
  5185. WCD934X_CDC_RX7_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain),
  5186. SOC_SINGLE_SX_TLV("RX8 Mix Digital Volume",
  5187. WCD934X_CDC_RX8_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain),
  5188. SOC_SINGLE_SX_TLV("DEC0 Volume", WCD934X_CDC_TX0_TX_VOL_CTL, 0,
  5189. -84, 40, digital_gain),
  5190. SOC_SINGLE_SX_TLV("DEC1 Volume", WCD934X_CDC_TX1_TX_VOL_CTL, 0,
  5191. -84, 40, digital_gain),
  5192. SOC_SINGLE_SX_TLV("DEC2 Volume", WCD934X_CDC_TX2_TX_VOL_CTL, 0,
  5193. -84, 40, digital_gain),
  5194. SOC_SINGLE_SX_TLV("DEC3 Volume", WCD934X_CDC_TX3_TX_VOL_CTL, 0,
  5195. -84, 40, digital_gain),
  5196. SOC_SINGLE_SX_TLV("DEC4 Volume", WCD934X_CDC_TX4_TX_VOL_CTL, 0,
  5197. -84, 40, digital_gain),
  5198. SOC_SINGLE_SX_TLV("DEC5 Volume", WCD934X_CDC_TX5_TX_VOL_CTL, 0,
  5199. -84, 40, digital_gain),
  5200. SOC_SINGLE_SX_TLV("DEC6 Volume", WCD934X_CDC_TX6_TX_VOL_CTL, 0,
  5201. -84, 40, digital_gain),
  5202. SOC_SINGLE_SX_TLV("DEC7 Volume", WCD934X_CDC_TX7_TX_VOL_CTL, 0,
  5203. -84, 40, digital_gain),
  5204. SOC_SINGLE_SX_TLV("DEC8 Volume", WCD934X_CDC_TX8_TX_VOL_CTL, 0,
  5205. -84, 40, digital_gain),
  5206. SOC_SINGLE_SX_TLV("IIR0 INP0 Volume",
  5207. WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B1_CTL, 0, -84, 40,
  5208. digital_gain),
  5209. SOC_SINGLE_SX_TLV("IIR0 INP1 Volume",
  5210. WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B2_CTL, 0, -84, 40,
  5211. digital_gain),
  5212. SOC_SINGLE_SX_TLV("IIR0 INP2 Volume",
  5213. WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B3_CTL, 0, -84, 40,
  5214. digital_gain),
  5215. SOC_SINGLE_SX_TLV("IIR0 INP3 Volume",
  5216. WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B4_CTL, 0, -84, 40,
  5217. digital_gain),
  5218. SOC_SINGLE_SX_TLV("IIR1 INP0 Volume",
  5219. WCD934X_CDC_SIDETONE_IIR1_IIR_GAIN_B1_CTL, 0, -84, 40,
  5220. digital_gain),
  5221. SOC_SINGLE_SX_TLV("IIR1 INP1 Volume",
  5222. WCD934X_CDC_SIDETONE_IIR1_IIR_GAIN_B2_CTL, 0, -84, 40,
  5223. digital_gain),
  5224. SOC_SINGLE_SX_TLV("IIR1 INP2 Volume",
  5225. WCD934X_CDC_SIDETONE_IIR1_IIR_GAIN_B3_CTL, 0, -84, 40,
  5226. digital_gain),
  5227. SOC_SINGLE_SX_TLV("IIR1 INP3 Volume",
  5228. WCD934X_CDC_SIDETONE_IIR1_IIR_GAIN_B4_CTL, 0, -84, 40,
  5229. digital_gain),
  5230. SOC_SINGLE_EXT("ANC Slot", SND_SOC_NOPM, 0, 100, 0, tavil_get_anc_slot,
  5231. tavil_put_anc_slot),
  5232. SOC_ENUM_EXT("ANC Function", tavil_anc_func_enum, tavil_get_anc_func,
  5233. tavil_put_anc_func),
  5234. SOC_ENUM_EXT("CLK MODE", tavil_clkmode_enum, tavil_get_clkmode,
  5235. tavil_put_clkmode),
  5236. SOC_ENUM("TX0 HPF cut off", cf_dec0_enum),
  5237. SOC_ENUM("TX1 HPF cut off", cf_dec1_enum),
  5238. SOC_ENUM("TX2 HPF cut off", cf_dec2_enum),
  5239. SOC_ENUM("TX3 HPF cut off", cf_dec3_enum),
  5240. SOC_ENUM("TX4 HPF cut off", cf_dec4_enum),
  5241. SOC_ENUM("TX5 HPF cut off", cf_dec5_enum),
  5242. SOC_ENUM("TX6 HPF cut off", cf_dec6_enum),
  5243. SOC_ENUM("TX7 HPF cut off", cf_dec7_enum),
  5244. SOC_ENUM("TX8 HPF cut off", cf_dec8_enum),
  5245. SOC_ENUM("RX INT0_1 HPF cut off", cf_int0_1_enum),
  5246. SOC_ENUM("RX INT0_2 HPF cut off", cf_int0_2_enum),
  5247. SOC_ENUM("RX INT1_1 HPF cut off", cf_int1_1_enum),
  5248. SOC_ENUM("RX INT1_2 HPF cut off", cf_int1_2_enum),
  5249. SOC_ENUM("RX INT2_1 HPF cut off", cf_int2_1_enum),
  5250. SOC_ENUM("RX INT2_2 HPF cut off", cf_int2_2_enum),
  5251. SOC_ENUM("RX INT3_1 HPF cut off", cf_int3_1_enum),
  5252. SOC_ENUM("RX INT3_2 HPF cut off", cf_int3_2_enum),
  5253. SOC_ENUM("RX INT4_1 HPF cut off", cf_int4_1_enum),
  5254. SOC_ENUM("RX INT4_2 HPF cut off", cf_int4_2_enum),
  5255. SOC_ENUM("RX INT7_1 HPF cut off", cf_int7_1_enum),
  5256. SOC_ENUM("RX INT7_2 HPF cut off", cf_int7_2_enum),
  5257. SOC_ENUM("RX INT8_1 HPF cut off", cf_int8_1_enum),
  5258. SOC_ENUM("RX INT8_2 HPF cut off", cf_int8_2_enum),
  5259. SOC_ENUM_EXT("RX HPH Mode", rx_hph_mode_mux_enum,
  5260. tavil_rx_hph_mode_get, tavil_rx_hph_mode_put),
  5261. SOC_SINGLE_EXT("IIR0 Enable Band1", IIR0, BAND1, 1, 0,
  5262. tavil_iir_enable_audio_mixer_get,
  5263. tavil_iir_enable_audio_mixer_put),
  5264. SOC_SINGLE_EXT("IIR0 Enable Band2", IIR0, BAND2, 1, 0,
  5265. tavil_iir_enable_audio_mixer_get,
  5266. tavil_iir_enable_audio_mixer_put),
  5267. SOC_SINGLE_EXT("IIR0 Enable Band3", IIR0, BAND3, 1, 0,
  5268. tavil_iir_enable_audio_mixer_get,
  5269. tavil_iir_enable_audio_mixer_put),
  5270. SOC_SINGLE_EXT("IIR0 Enable Band4", IIR0, BAND4, 1, 0,
  5271. tavil_iir_enable_audio_mixer_get,
  5272. tavil_iir_enable_audio_mixer_put),
  5273. SOC_SINGLE_EXT("IIR0 Enable Band5", IIR0, BAND5, 1, 0,
  5274. tavil_iir_enable_audio_mixer_get,
  5275. tavil_iir_enable_audio_mixer_put),
  5276. SOC_SINGLE_EXT("IIR1 Enable Band1", IIR1, BAND1, 1, 0,
  5277. tavil_iir_enable_audio_mixer_get,
  5278. tavil_iir_enable_audio_mixer_put),
  5279. SOC_SINGLE_EXT("IIR1 Enable Band2", IIR1, BAND2, 1, 0,
  5280. tavil_iir_enable_audio_mixer_get,
  5281. tavil_iir_enable_audio_mixer_put),
  5282. SOC_SINGLE_EXT("IIR1 Enable Band3", IIR1, BAND3, 1, 0,
  5283. tavil_iir_enable_audio_mixer_get,
  5284. tavil_iir_enable_audio_mixer_put),
  5285. SOC_SINGLE_EXT("IIR1 Enable Band4", IIR1, BAND4, 1, 0,
  5286. tavil_iir_enable_audio_mixer_get,
  5287. tavil_iir_enable_audio_mixer_put),
  5288. SOC_SINGLE_EXT("IIR1 Enable Band5", IIR1, BAND5, 1, 0,
  5289. tavil_iir_enable_audio_mixer_get,
  5290. tavil_iir_enable_audio_mixer_put),
  5291. SOC_SINGLE_MULTI_EXT("IIR0 Band1", IIR0, BAND1, 255, 0, 5,
  5292. tavil_iir_band_audio_mixer_get, tavil_iir_band_audio_mixer_put),
  5293. SOC_SINGLE_MULTI_EXT("IIR0 Band2", IIR0, BAND2, 255, 0, 5,
  5294. tavil_iir_band_audio_mixer_get, tavil_iir_band_audio_mixer_put),
  5295. SOC_SINGLE_MULTI_EXT("IIR0 Band3", IIR0, BAND3, 255, 0, 5,
  5296. tavil_iir_band_audio_mixer_get, tavil_iir_band_audio_mixer_put),
  5297. SOC_SINGLE_MULTI_EXT("IIR0 Band4", IIR0, BAND4, 255, 0, 5,
  5298. tavil_iir_band_audio_mixer_get, tavil_iir_band_audio_mixer_put),
  5299. SOC_SINGLE_MULTI_EXT("IIR0 Band5", IIR0, BAND5, 255, 0, 5,
  5300. tavil_iir_band_audio_mixer_get, tavil_iir_band_audio_mixer_put),
  5301. SOC_SINGLE_MULTI_EXT("IIR1 Band1", IIR1, BAND1, 255, 0, 5,
  5302. tavil_iir_band_audio_mixer_get, tavil_iir_band_audio_mixer_put),
  5303. SOC_SINGLE_MULTI_EXT("IIR1 Band2", IIR1, BAND2, 255, 0, 5,
  5304. tavil_iir_band_audio_mixer_get, tavil_iir_band_audio_mixer_put),
  5305. SOC_SINGLE_MULTI_EXT("IIR1 Band3", IIR1, BAND3, 255, 0, 5,
  5306. tavil_iir_band_audio_mixer_get, tavil_iir_band_audio_mixer_put),
  5307. SOC_SINGLE_MULTI_EXT("IIR1 Band4", IIR1, BAND4, 255, 0, 5,
  5308. tavil_iir_band_audio_mixer_get, tavil_iir_band_audio_mixer_put),
  5309. SOC_SINGLE_MULTI_EXT("IIR1 Band5", IIR1, BAND5, 255, 0, 5,
  5310. tavil_iir_band_audio_mixer_get, tavil_iir_band_audio_mixer_put),
  5311. SOC_SINGLE_EXT("COMP1 Switch", SND_SOC_NOPM, COMPANDER_1, 1, 0,
  5312. tavil_compander_get, tavil_compander_put),
  5313. SOC_SINGLE_EXT("COMP2 Switch", SND_SOC_NOPM, COMPANDER_2, 1, 0,
  5314. tavil_compander_get, tavil_compander_put),
  5315. SOC_SINGLE_EXT("COMP3 Switch", SND_SOC_NOPM, COMPANDER_3, 1, 0,
  5316. tavil_compander_get, tavil_compander_put),
  5317. SOC_SINGLE_EXT("COMP4 Switch", SND_SOC_NOPM, COMPANDER_4, 1, 0,
  5318. tavil_compander_get, tavil_compander_put),
  5319. SOC_SINGLE_EXT("COMP7 Switch", SND_SOC_NOPM, COMPANDER_7, 1, 0,
  5320. tavil_compander_get, tavil_compander_put),
  5321. SOC_SINGLE_EXT("COMP8 Switch", SND_SOC_NOPM, COMPANDER_8, 1, 0,
  5322. tavil_compander_get, tavil_compander_put),
  5323. SOC_ENUM_EXT("ASRC0 Output Mode", asrc_mode_enum,
  5324. tavil_hph_asrc_mode_get, tavil_hph_asrc_mode_put),
  5325. SOC_ENUM_EXT("ASRC1 Output Mode", asrc_mode_enum,
  5326. tavil_hph_asrc_mode_get, tavil_hph_asrc_mode_put),
  5327. SOC_ENUM_EXT("HPH Idle Detect", hph_idle_detect_enum,
  5328. tavil_hph_idle_detect_get, tavil_hph_idle_detect_put),
  5329. SOC_ENUM_EXT("MAD Input", tavil_conn_mad_enum,
  5330. tavil_mad_input_get, tavil_mad_input_put),
  5331. SOC_SINGLE_EXT("DMIC1_CLK_PIN_MODE", SND_SOC_NOPM, 17, 1, 0,
  5332. tavil_dmic_pin_mode_get, tavil_dmic_pin_mode_put),
  5333. SOC_SINGLE_EXT("DMIC1_DATA_PIN_MODE", SND_SOC_NOPM, 18, 1, 0,
  5334. tavil_dmic_pin_mode_get, tavil_dmic_pin_mode_put),
  5335. SOC_SINGLE_EXT("DMIC2_CLK_PIN_MODE", SND_SOC_NOPM, 19, 1, 0,
  5336. tavil_dmic_pin_mode_get, tavil_dmic_pin_mode_put),
  5337. SOC_SINGLE_EXT("DMIC2_DATA_PIN_MODE", SND_SOC_NOPM, 20, 1, 0,
  5338. tavil_dmic_pin_mode_get, tavil_dmic_pin_mode_put),
  5339. SOC_SINGLE_EXT("DMIC3_CLK_PIN_MODE", SND_SOC_NOPM, 21, 1, 0,
  5340. tavil_dmic_pin_mode_get, tavil_dmic_pin_mode_put),
  5341. SOC_SINGLE_EXT("DMIC3_DATA_PIN_MODE", SND_SOC_NOPM, 22, 1, 0,
  5342. tavil_dmic_pin_mode_get, tavil_dmic_pin_mode_put),
  5343. SOC_ENUM_EXT("AMIC_1_2 PWR MODE", amic_pwr_lvl_enum,
  5344. tavil_amic_pwr_lvl_get, tavil_amic_pwr_lvl_put),
  5345. SOC_ENUM_EXT("AMIC_3_4 PWR MODE", amic_pwr_lvl_enum,
  5346. tavil_amic_pwr_lvl_get, tavil_amic_pwr_lvl_put),
  5347. SOC_ENUM_EXT("AMIC_5_6 PWR MODE", amic_pwr_lvl_enum,
  5348. tavil_amic_pwr_lvl_get, tavil_amic_pwr_lvl_put),
  5349. };
  5350. static int tavil_dec_enum_put(struct snd_kcontrol *kcontrol,
  5351. struct snd_ctl_elem_value *ucontrol)
  5352. {
  5353. struct snd_soc_dapm_widget *widget =
  5354. snd_soc_dapm_kcontrol_widget(kcontrol);
  5355. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  5356. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  5357. unsigned int val;
  5358. u16 mic_sel_reg = 0;
  5359. u8 mic_sel;
  5360. val = ucontrol->value.enumerated.item[0];
  5361. if (val > e->items - 1)
  5362. return -EINVAL;
  5363. dev_dbg(codec->dev, "%s: wname: %s, val: 0x%x\n", __func__,
  5364. widget->name, val);
  5365. switch (e->reg) {
  5366. case WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG1:
  5367. if (e->shift_l == 0)
  5368. mic_sel_reg = WCD934X_CDC_TX0_TX_PATH_CFG0;
  5369. else if (e->shift_l == 2)
  5370. mic_sel_reg = WCD934X_CDC_TX4_TX_PATH_CFG0;
  5371. else if (e->shift_l == 4)
  5372. mic_sel_reg = WCD934X_CDC_TX8_TX_PATH_CFG0;
  5373. break;
  5374. case WCD934X_CDC_TX_INP_MUX_ADC_MUX1_CFG1:
  5375. if (e->shift_l == 0)
  5376. mic_sel_reg = WCD934X_CDC_TX1_TX_PATH_CFG0;
  5377. else if (e->shift_l == 2)
  5378. mic_sel_reg = WCD934X_CDC_TX5_TX_PATH_CFG0;
  5379. break;
  5380. case WCD934X_CDC_TX_INP_MUX_ADC_MUX2_CFG1:
  5381. if (e->shift_l == 0)
  5382. mic_sel_reg = WCD934X_CDC_TX2_TX_PATH_CFG0;
  5383. else if (e->shift_l == 2)
  5384. mic_sel_reg = WCD934X_CDC_TX6_TX_PATH_CFG0;
  5385. break;
  5386. case WCD934X_CDC_TX_INP_MUX_ADC_MUX3_CFG1:
  5387. if (e->shift_l == 0)
  5388. mic_sel_reg = WCD934X_CDC_TX3_TX_PATH_CFG0;
  5389. else if (e->shift_l == 2)
  5390. mic_sel_reg = WCD934X_CDC_TX7_TX_PATH_CFG0;
  5391. break;
  5392. default:
  5393. dev_err(codec->dev, "%s: e->reg: 0x%x not expected\n",
  5394. __func__, e->reg);
  5395. return -EINVAL;
  5396. }
  5397. /* ADC: 0, DMIC: 1 */
  5398. mic_sel = val ? 0x0 : 0x1;
  5399. if (mic_sel_reg)
  5400. snd_soc_update_bits(codec, mic_sel_reg, 1 << 7, mic_sel << 7);
  5401. return snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
  5402. }
  5403. static int tavil_int_dem_inp_mux_put(struct snd_kcontrol *kcontrol,
  5404. struct snd_ctl_elem_value *ucontrol)
  5405. {
  5406. struct snd_soc_dapm_widget *widget =
  5407. snd_soc_dapm_kcontrol_widget(kcontrol);
  5408. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  5409. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  5410. unsigned int val;
  5411. unsigned short look_ahead_dly_reg = WCD934X_CDC_RX0_RX_PATH_CFG0;
  5412. val = ucontrol->value.enumerated.item[0];
  5413. if (val >= e->items)
  5414. return -EINVAL;
  5415. dev_dbg(codec->dev, "%s: wname: %s, val: 0x%x\n", __func__,
  5416. widget->name, val);
  5417. if (e->reg == WCD934X_CDC_RX0_RX_PATH_SEC0)
  5418. look_ahead_dly_reg = WCD934X_CDC_RX0_RX_PATH_CFG0;
  5419. else if (e->reg == WCD934X_CDC_RX1_RX_PATH_SEC0)
  5420. look_ahead_dly_reg = WCD934X_CDC_RX1_RX_PATH_CFG0;
  5421. else if (e->reg == WCD934X_CDC_RX2_RX_PATH_SEC0)
  5422. look_ahead_dly_reg = WCD934X_CDC_RX2_RX_PATH_CFG0;
  5423. /* Set Look Ahead Delay */
  5424. snd_soc_update_bits(codec, look_ahead_dly_reg,
  5425. 0x08, (val ? 0x08 : 0x00));
  5426. /* Set DEM INP Select */
  5427. return snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
  5428. }
  5429. static const char * const rx_int0_7_mix_mux_text[] = {
  5430. "ZERO", "RX0", "RX1", "RX2", "RX3", "RX4", "RX5",
  5431. "RX6", "RX7", "PROXIMITY"
  5432. };
  5433. static const char * const rx_int_mix_mux_text[] = {
  5434. "ZERO", "RX0", "RX1", "RX2", "RX3", "RX4", "RX5",
  5435. "RX6", "RX7"
  5436. };
  5437. static const char * const rx_prim_mix_text[] = {
  5438. "ZERO", "DEC0", "DEC1", "IIR0", "IIR1", "RX0", "RX1", "RX2",
  5439. "RX3", "RX4", "RX5", "RX6", "RX7"
  5440. };
  5441. static const char * const rx_sidetone_mix_text[] = {
  5442. "ZERO", "SRC0", "SRC1", "SRC_SUM"
  5443. };
  5444. static const char * const cdc_if_tx0_mux_text[] = {
  5445. "ZERO", "RX_MIX_TX0", "DEC0", "DEC0_192"
  5446. };
  5447. static const char * const cdc_if_tx1_mux_text[] = {
  5448. "ZERO", "RX_MIX_TX1", "DEC1", "DEC1_192"
  5449. };
  5450. static const char * const cdc_if_tx2_mux_text[] = {
  5451. "ZERO", "RX_MIX_TX2", "DEC2", "DEC2_192"
  5452. };
  5453. static const char * const cdc_if_tx3_mux_text[] = {
  5454. "ZERO", "RX_MIX_TX3", "DEC3", "DEC3_192"
  5455. };
  5456. static const char * const cdc_if_tx4_mux_text[] = {
  5457. "ZERO", "RX_MIX_TX4", "DEC4", "DEC4_192"
  5458. };
  5459. static const char * const cdc_if_tx5_mux_text[] = {
  5460. "ZERO", "RX_MIX_TX5", "DEC5", "DEC5_192"
  5461. };
  5462. static const char * const cdc_if_tx6_mux_text[] = {
  5463. "ZERO", "RX_MIX_TX6", "DEC6", "DEC6_192"
  5464. };
  5465. static const char * const cdc_if_tx7_mux_text[] = {
  5466. "ZERO", "RX_MIX_TX7", "DEC7", "DEC7_192"
  5467. };
  5468. static const char * const cdc_if_tx8_mux_text[] = {
  5469. "ZERO", "RX_MIX_TX8", "DEC8", "DEC8_192"
  5470. };
  5471. static const char * const cdc_if_tx9_mux_text[] = {
  5472. "ZERO", "DEC7", "DEC7_192"
  5473. };
  5474. static const char * const cdc_if_tx10_mux_text[] = {
  5475. "ZERO", "DEC6", "DEC6_192"
  5476. };
  5477. static const char * const cdc_if_tx11_mux_text[] = {
  5478. "DEC_0_5", "DEC_9_12", "MAD_AUDIO", "MAD_BRDCST"
  5479. };
  5480. static const char * const cdc_if_tx11_inp1_mux_text[] = {
  5481. "ZERO", "DEC0", "DEC1", "DEC2", "DEC3", "DEC4",
  5482. "DEC5", "RX_MIX_TX5", "DEC9_10", "DEC11_12"
  5483. };
  5484. static const char * const cdc_if_tx13_mux_text[] = {
  5485. "CDC_DEC_5", "MAD_BRDCST"
  5486. };
  5487. static const char * const cdc_if_tx13_inp1_mux_text[] = {
  5488. "ZERO", "DEC5", "DEC5_192"
  5489. };
  5490. static const char * const iir_inp_mux_text[] = {
  5491. "ZERO", "DEC0", "DEC1", "DEC2", "DEC3", "DEC4", "DEC5", "DEC6",
  5492. "DEC7", "DEC8", "RX0", "RX1", "RX2", "RX3", "RX4", "RX5", "RX6", "RX7"
  5493. };
  5494. static const char * const rx_int_dem_inp_mux_text[] = {
  5495. "NORMAL_DSM_OUT", "CLSH_DSM_OUT",
  5496. };
  5497. static const char * const rx_int0_1_interp_mux_text[] = {
  5498. "ZERO", "RX INT0_1 MIX1",
  5499. };
  5500. static const char * const rx_int1_1_interp_mux_text[] = {
  5501. "ZERO", "RX INT1_1 MIX1",
  5502. };
  5503. static const char * const rx_int2_1_interp_mux_text[] = {
  5504. "ZERO", "RX INT2_1 MIX1",
  5505. };
  5506. static const char * const rx_int3_1_interp_mux_text[] = {
  5507. "ZERO", "RX INT3_1 MIX1",
  5508. };
  5509. static const char * const rx_int4_1_interp_mux_text[] = {
  5510. "ZERO", "RX INT4_1 MIX1",
  5511. };
  5512. static const char * const rx_int7_1_interp_mux_text[] = {
  5513. "ZERO", "RX INT7_1 MIX1",
  5514. };
  5515. static const char * const rx_int8_1_interp_mux_text[] = {
  5516. "ZERO", "RX INT8_1 MIX1",
  5517. };
  5518. static const char * const rx_int0_2_interp_mux_text[] = {
  5519. "ZERO", "RX INT0_2 MUX",
  5520. };
  5521. static const char * const rx_int1_2_interp_mux_text[] = {
  5522. "ZERO", "RX INT1_2 MUX",
  5523. };
  5524. static const char * const rx_int2_2_interp_mux_text[] = {
  5525. "ZERO", "RX INT2_2 MUX",
  5526. };
  5527. static const char * const rx_int3_2_interp_mux_text[] = {
  5528. "ZERO", "RX INT3_2 MUX",
  5529. };
  5530. static const char * const rx_int4_2_interp_mux_text[] = {
  5531. "ZERO", "RX INT4_2 MUX",
  5532. };
  5533. static const char * const rx_int7_2_interp_mux_text[] = {
  5534. "ZERO", "RX INT7_2 MUX",
  5535. };
  5536. static const char * const rx_int8_2_interp_mux_text[] = {
  5537. "ZERO", "RX INT8_2 MUX",
  5538. };
  5539. static const char * const mad_sel_txt[] = {
  5540. "SPE", "MSM"
  5541. };
  5542. static const char * const mad_inp_mux_txt[] = {
  5543. "MAD", "DEC1"
  5544. };
  5545. static const char * const adc_mux_text[] = {
  5546. "DMIC", "AMIC", "ANC_FB_TUNE1", "ANC_FB_TUNE2"
  5547. };
  5548. static const char * const dmic_mux_text[] = {
  5549. "ZERO", "DMIC0", "DMIC1", "DMIC2", "DMIC3", "DMIC4", "DMIC5"
  5550. };
  5551. static const char * const amic_mux_text[] = {
  5552. "ZERO", "ADC1", "ADC2", "ADC3", "ADC4"
  5553. };
  5554. static const char * const amic4_5_sel_text[] = {
  5555. "AMIC4", "AMIC5"
  5556. };
  5557. static const char * const anc0_fb_mux_text[] = {
  5558. "ZERO", "ANC_IN_HPHL", "ANC_IN_EAR", "ANC_IN_EAR_SPKR",
  5559. "ANC_IN_LO1"
  5560. };
  5561. static const char * const anc1_fb_mux_text[] = {
  5562. "ZERO", "ANC_IN_HPHR", "ANC_IN_LO2"
  5563. };
  5564. static const char * const rx_echo_mux_text[] = {
  5565. "ZERO", "RX_MIX0", "RX_MIX1", "RX_MIX2", "RX_MIX3", "RX_MIX4",
  5566. "RX_MIX5", "RX_MIX6", "RX_MIX7", "RX_MIX8"
  5567. };
  5568. static const char *const slim_rx_mux_text[] = {
  5569. "ZERO", "AIF1_PB", "AIF2_PB", "AIF3_PB", "AIF4_PB"
  5570. };
  5571. static const char *const cdc_if_rx0_mux_text[] = {
  5572. "SLIM RX0", "I2S_0 RX0"
  5573. };
  5574. static const char *const cdc_if_rx1_mux_text[] = {
  5575. "SLIM RX1", "I2S_0 RX1"
  5576. };
  5577. static const char *const cdc_if_rx2_mux_text[] = {
  5578. "SLIM RX2", "I2S_0 RX2"
  5579. };
  5580. static const char *const cdc_if_rx3_mux_text[] = {
  5581. "SLIM RX3", "I2S_0 RX3"
  5582. };
  5583. static const char *const cdc_if_rx4_mux_text[] = {
  5584. "SLIM RX4", "I2S_0 RX4"
  5585. };
  5586. static const char *const cdc_if_rx5_mux_text[] = {
  5587. "SLIM RX5", "I2S_0 RX5"
  5588. };
  5589. static const char *const cdc_if_rx6_mux_text[] = {
  5590. "SLIM RX6", "I2S_0 RX6"
  5591. };
  5592. static const char *const cdc_if_rx7_mux_text[] = {
  5593. "SLIM RX7", "I2S_0 RX7"
  5594. };
  5595. static const char * const asrc0_mux_text[] = {
  5596. "ZERO", "ASRC_IN_HPHL", "ASRC_IN_LO1",
  5597. };
  5598. static const char * const asrc1_mux_text[] = {
  5599. "ZERO", "ASRC_IN_HPHR", "ASRC_IN_LO2",
  5600. };
  5601. static const char * const asrc2_mux_text[] = {
  5602. "ZERO", "ASRC_IN_SPKR1",
  5603. };
  5604. static const char * const asrc3_mux_text[] = {
  5605. "ZERO", "ASRC_IN_SPKR2",
  5606. };
  5607. static const char * const native_mux_text[] = {
  5608. "OFF", "ON",
  5609. };
  5610. static const char *const wdma3_port0_text[] = {
  5611. "RX_MIX_TX0", "DEC0"
  5612. };
  5613. static const char *const wdma3_port1_text[] = {
  5614. "RX_MIX_TX1", "DEC1"
  5615. };
  5616. static const char *const wdma3_port2_text[] = {
  5617. "RX_MIX_TX2", "DEC2"
  5618. };
  5619. static const char *const wdma3_port3_text[] = {
  5620. "RX_MIX_TX3", "DEC3"
  5621. };
  5622. static const char *const wdma3_port4_text[] = {
  5623. "RX_MIX_TX4", "DEC4"
  5624. };
  5625. static const char *const wdma3_port5_text[] = {
  5626. "RX_MIX_TX5", "DEC5"
  5627. };
  5628. static const char *const wdma3_port6_text[] = {
  5629. "RX_MIX_TX6", "DEC6"
  5630. };
  5631. static const char *const wdma3_ch_text[] = {
  5632. "PORT_0", "PORT_1", "PORT_2", "PORT_3", "PORT_4",
  5633. "PORT_5", "PORT_6", "PORT_7", "PORT_8",
  5634. };
  5635. static const struct snd_kcontrol_new aif4_vi_mixer[] = {
  5636. SOC_SINGLE_EXT("SPKR_VI_1", SND_SOC_NOPM, WCD934X_TX14, 1, 0,
  5637. tavil_vi_feed_mixer_get, tavil_vi_feed_mixer_put),
  5638. SOC_SINGLE_EXT("SPKR_VI_2", SND_SOC_NOPM, WCD934X_TX15, 1, 0,
  5639. tavil_vi_feed_mixer_get, tavil_vi_feed_mixer_put),
  5640. };
  5641. static const struct snd_kcontrol_new aif1_cap_mixer[] = {
  5642. SOC_SINGLE_EXT("SLIM TX0", SND_SOC_NOPM, WCD934X_TX0, 1, 0,
  5643. slim_tx_mixer_get, slim_tx_mixer_put),
  5644. SOC_SINGLE_EXT("SLIM TX1", SND_SOC_NOPM, WCD934X_TX1, 1, 0,
  5645. slim_tx_mixer_get, slim_tx_mixer_put),
  5646. SOC_SINGLE_EXT("SLIM TX2", SND_SOC_NOPM, WCD934X_TX2, 1, 0,
  5647. slim_tx_mixer_get, slim_tx_mixer_put),
  5648. SOC_SINGLE_EXT("SLIM TX3", SND_SOC_NOPM, WCD934X_TX3, 1, 0,
  5649. slim_tx_mixer_get, slim_tx_mixer_put),
  5650. SOC_SINGLE_EXT("SLIM TX4", SND_SOC_NOPM, WCD934X_TX4, 1, 0,
  5651. slim_tx_mixer_get, slim_tx_mixer_put),
  5652. SOC_SINGLE_EXT("SLIM TX5", SND_SOC_NOPM, WCD934X_TX5, 1, 0,
  5653. slim_tx_mixer_get, slim_tx_mixer_put),
  5654. SOC_SINGLE_EXT("SLIM TX6", SND_SOC_NOPM, WCD934X_TX6, 1, 0,
  5655. slim_tx_mixer_get, slim_tx_mixer_put),
  5656. SOC_SINGLE_EXT("SLIM TX7", SND_SOC_NOPM, WCD934X_TX7, 1, 0,
  5657. slim_tx_mixer_get, slim_tx_mixer_put),
  5658. SOC_SINGLE_EXT("SLIM TX8", SND_SOC_NOPM, WCD934X_TX8, 1, 0,
  5659. slim_tx_mixer_get, slim_tx_mixer_put),
  5660. SOC_SINGLE_EXT("SLIM TX9", SND_SOC_NOPM, WCD934X_TX9, 1, 0,
  5661. slim_tx_mixer_get, slim_tx_mixer_put),
  5662. SOC_SINGLE_EXT("SLIM TX10", SND_SOC_NOPM, WCD934X_TX10, 1, 0,
  5663. slim_tx_mixer_get, slim_tx_mixer_put),
  5664. SOC_SINGLE_EXT("SLIM TX11", SND_SOC_NOPM, WCD934X_TX11, 1, 0,
  5665. slim_tx_mixer_get, slim_tx_mixer_put),
  5666. SOC_SINGLE_EXT("SLIM TX13", SND_SOC_NOPM, WCD934X_TX13, 1, 0,
  5667. slim_tx_mixer_get, slim_tx_mixer_put),
  5668. };
  5669. static const struct snd_kcontrol_new aif2_cap_mixer[] = {
  5670. SOC_SINGLE_EXT("SLIM TX0", SND_SOC_NOPM, WCD934X_TX0, 1, 0,
  5671. slim_tx_mixer_get, slim_tx_mixer_put),
  5672. SOC_SINGLE_EXT("SLIM TX1", SND_SOC_NOPM, WCD934X_TX1, 1, 0,
  5673. slim_tx_mixer_get, slim_tx_mixer_put),
  5674. SOC_SINGLE_EXT("SLIM TX2", SND_SOC_NOPM, WCD934X_TX2, 1, 0,
  5675. slim_tx_mixer_get, slim_tx_mixer_put),
  5676. SOC_SINGLE_EXT("SLIM TX3", SND_SOC_NOPM, WCD934X_TX3, 1, 0,
  5677. slim_tx_mixer_get, slim_tx_mixer_put),
  5678. SOC_SINGLE_EXT("SLIM TX4", SND_SOC_NOPM, WCD934X_TX4, 1, 0,
  5679. slim_tx_mixer_get, slim_tx_mixer_put),
  5680. SOC_SINGLE_EXT("SLIM TX5", SND_SOC_NOPM, WCD934X_TX5, 1, 0,
  5681. slim_tx_mixer_get, slim_tx_mixer_put),
  5682. SOC_SINGLE_EXT("SLIM TX6", SND_SOC_NOPM, WCD934X_TX6, 1, 0,
  5683. slim_tx_mixer_get, slim_tx_mixer_put),
  5684. SOC_SINGLE_EXT("SLIM TX7", SND_SOC_NOPM, WCD934X_TX7, 1, 0,
  5685. slim_tx_mixer_get, slim_tx_mixer_put),
  5686. SOC_SINGLE_EXT("SLIM TX8", SND_SOC_NOPM, WCD934X_TX8, 1, 0,
  5687. slim_tx_mixer_get, slim_tx_mixer_put),
  5688. SOC_SINGLE_EXT("SLIM TX9", SND_SOC_NOPM, WCD934X_TX9, 1, 0,
  5689. slim_tx_mixer_get, slim_tx_mixer_put),
  5690. SOC_SINGLE_EXT("SLIM TX10", SND_SOC_NOPM, WCD934X_TX10, 1, 0,
  5691. slim_tx_mixer_get, slim_tx_mixer_put),
  5692. SOC_SINGLE_EXT("SLIM TX11", SND_SOC_NOPM, WCD934X_TX11, 1, 0,
  5693. slim_tx_mixer_get, slim_tx_mixer_put),
  5694. SOC_SINGLE_EXT("SLIM TX13", SND_SOC_NOPM, WCD934X_TX13, 1, 0,
  5695. slim_tx_mixer_get, slim_tx_mixer_put),
  5696. };
  5697. static const struct snd_kcontrol_new aif3_cap_mixer[] = {
  5698. SOC_SINGLE_EXT("SLIM TX0", SND_SOC_NOPM, WCD934X_TX0, 1, 0,
  5699. slim_tx_mixer_get, slim_tx_mixer_put),
  5700. SOC_SINGLE_EXT("SLIM TX1", SND_SOC_NOPM, WCD934X_TX1, 1, 0,
  5701. slim_tx_mixer_get, slim_tx_mixer_put),
  5702. SOC_SINGLE_EXT("SLIM TX2", SND_SOC_NOPM, WCD934X_TX2, 1, 0,
  5703. slim_tx_mixer_get, slim_tx_mixer_put),
  5704. SOC_SINGLE_EXT("SLIM TX3", SND_SOC_NOPM, WCD934X_TX3, 1, 0,
  5705. slim_tx_mixer_get, slim_tx_mixer_put),
  5706. SOC_SINGLE_EXT("SLIM TX4", SND_SOC_NOPM, WCD934X_TX4, 1, 0,
  5707. slim_tx_mixer_get, slim_tx_mixer_put),
  5708. SOC_SINGLE_EXT("SLIM TX5", SND_SOC_NOPM, WCD934X_TX5, 1, 0,
  5709. slim_tx_mixer_get, slim_tx_mixer_put),
  5710. SOC_SINGLE_EXT("SLIM TX6", SND_SOC_NOPM, WCD934X_TX6, 1, 0,
  5711. slim_tx_mixer_get, slim_tx_mixer_put),
  5712. SOC_SINGLE_EXT("SLIM TX7", SND_SOC_NOPM, WCD934X_TX7, 1, 0,
  5713. slim_tx_mixer_get, slim_tx_mixer_put),
  5714. SOC_SINGLE_EXT("SLIM TX8", SND_SOC_NOPM, WCD934X_TX8, 1, 0,
  5715. slim_tx_mixer_get, slim_tx_mixer_put),
  5716. SOC_SINGLE_EXT("SLIM TX9", SND_SOC_NOPM, WCD934X_TX9, 1, 0,
  5717. slim_tx_mixer_get, slim_tx_mixer_put),
  5718. SOC_SINGLE_EXT("SLIM TX10", SND_SOC_NOPM, WCD934X_TX10, 1, 0,
  5719. slim_tx_mixer_get, slim_tx_mixer_put),
  5720. SOC_SINGLE_EXT("SLIM TX11", SND_SOC_NOPM, WCD934X_TX11, 1, 0,
  5721. slim_tx_mixer_get, slim_tx_mixer_put),
  5722. SOC_SINGLE_EXT("SLIM TX13", SND_SOC_NOPM, WCD934X_TX13, 1, 0,
  5723. slim_tx_mixer_get, slim_tx_mixer_put),
  5724. };
  5725. static const struct snd_kcontrol_new aif4_mad_mixer[] = {
  5726. SOC_SINGLE_EXT("SLIM TX13", SND_SOC_NOPM, WCD934X_TX13, 1, 0,
  5727. slim_tx_mixer_get, slim_tx_mixer_put),
  5728. };
  5729. WCD_DAPM_ENUM_EXT(slim_rx0, SND_SOC_NOPM, 0, slim_rx_mux_text,
  5730. slim_rx_mux_get, slim_rx_mux_put);
  5731. WCD_DAPM_ENUM_EXT(slim_rx1, SND_SOC_NOPM, 0, slim_rx_mux_text,
  5732. slim_rx_mux_get, slim_rx_mux_put);
  5733. WCD_DAPM_ENUM_EXT(slim_rx2, SND_SOC_NOPM, 0, slim_rx_mux_text,
  5734. slim_rx_mux_get, slim_rx_mux_put);
  5735. WCD_DAPM_ENUM_EXT(slim_rx3, SND_SOC_NOPM, 0, slim_rx_mux_text,
  5736. slim_rx_mux_get, slim_rx_mux_put);
  5737. WCD_DAPM_ENUM_EXT(slim_rx4, SND_SOC_NOPM, 0, slim_rx_mux_text,
  5738. slim_rx_mux_get, slim_rx_mux_put);
  5739. WCD_DAPM_ENUM_EXT(slim_rx5, SND_SOC_NOPM, 0, slim_rx_mux_text,
  5740. slim_rx_mux_get, slim_rx_mux_put);
  5741. WCD_DAPM_ENUM_EXT(slim_rx6, SND_SOC_NOPM, 0, slim_rx_mux_text,
  5742. slim_rx_mux_get, slim_rx_mux_put);
  5743. WCD_DAPM_ENUM_EXT(slim_rx7, SND_SOC_NOPM, 0, slim_rx_mux_text,
  5744. slim_rx_mux_get, slim_rx_mux_put);
  5745. WCD_DAPM_ENUM(cdc_if_rx0, SND_SOC_NOPM, 0, cdc_if_rx0_mux_text);
  5746. WCD_DAPM_ENUM(cdc_if_rx1, SND_SOC_NOPM, 0, cdc_if_rx1_mux_text);
  5747. WCD_DAPM_ENUM(cdc_if_rx2, SND_SOC_NOPM, 0, cdc_if_rx2_mux_text);
  5748. WCD_DAPM_ENUM(cdc_if_rx3, SND_SOC_NOPM, 0, cdc_if_rx3_mux_text);
  5749. WCD_DAPM_ENUM(cdc_if_rx4, SND_SOC_NOPM, 0, cdc_if_rx4_mux_text);
  5750. WCD_DAPM_ENUM(cdc_if_rx5, SND_SOC_NOPM, 0, cdc_if_rx5_mux_text);
  5751. WCD_DAPM_ENUM(cdc_if_rx6, SND_SOC_NOPM, 0, cdc_if_rx6_mux_text);
  5752. WCD_DAPM_ENUM(cdc_if_rx7, SND_SOC_NOPM, 0, cdc_if_rx7_mux_text);
  5753. WCD_DAPM_ENUM(rx_int0_2, WCD934X_CDC_RX_INP_MUX_RX_INT0_CFG1, 0,
  5754. rx_int0_7_mix_mux_text);
  5755. WCD_DAPM_ENUM(rx_int1_2, WCD934X_CDC_RX_INP_MUX_RX_INT1_CFG1, 0,
  5756. rx_int_mix_mux_text);
  5757. WCD_DAPM_ENUM(rx_int2_2, WCD934X_CDC_RX_INP_MUX_RX_INT2_CFG1, 0,
  5758. rx_int_mix_mux_text);
  5759. WCD_DAPM_ENUM(rx_int3_2, WCD934X_CDC_RX_INP_MUX_RX_INT3_CFG1, 0,
  5760. rx_int_mix_mux_text);
  5761. WCD_DAPM_ENUM(rx_int4_2, WCD934X_CDC_RX_INP_MUX_RX_INT4_CFG1, 0,
  5762. rx_int_mix_mux_text);
  5763. WCD_DAPM_ENUM(rx_int7_2, WCD934X_CDC_RX_INP_MUX_RX_INT7_CFG1, 0,
  5764. rx_int0_7_mix_mux_text);
  5765. WCD_DAPM_ENUM(rx_int8_2, WCD934X_CDC_RX_INP_MUX_RX_INT8_CFG1, 0,
  5766. rx_int_mix_mux_text);
  5767. WCD_DAPM_ENUM(rx_int0_1_mix_inp0, WCD934X_CDC_RX_INP_MUX_RX_INT0_CFG0, 0,
  5768. rx_prim_mix_text);
  5769. WCD_DAPM_ENUM(rx_int0_1_mix_inp1, WCD934X_CDC_RX_INP_MUX_RX_INT0_CFG0, 4,
  5770. rx_prim_mix_text);
  5771. WCD_DAPM_ENUM(rx_int0_1_mix_inp2, WCD934X_CDC_RX_INP_MUX_RX_INT0_CFG1, 4,
  5772. rx_prim_mix_text);
  5773. WCD_DAPM_ENUM(rx_int1_1_mix_inp0, WCD934X_CDC_RX_INP_MUX_RX_INT1_CFG0, 0,
  5774. rx_prim_mix_text);
  5775. WCD_DAPM_ENUM(rx_int1_1_mix_inp1, WCD934X_CDC_RX_INP_MUX_RX_INT1_CFG0, 4,
  5776. rx_prim_mix_text);
  5777. WCD_DAPM_ENUM(rx_int1_1_mix_inp2, WCD934X_CDC_RX_INP_MUX_RX_INT1_CFG1, 4,
  5778. rx_prim_mix_text);
  5779. WCD_DAPM_ENUM(rx_int2_1_mix_inp0, WCD934X_CDC_RX_INP_MUX_RX_INT2_CFG0, 0,
  5780. rx_prim_mix_text);
  5781. WCD_DAPM_ENUM(rx_int2_1_mix_inp1, WCD934X_CDC_RX_INP_MUX_RX_INT2_CFG0, 4,
  5782. rx_prim_mix_text);
  5783. WCD_DAPM_ENUM(rx_int2_1_mix_inp2, WCD934X_CDC_RX_INP_MUX_RX_INT2_CFG1, 4,
  5784. rx_prim_mix_text);
  5785. WCD_DAPM_ENUM(rx_int3_1_mix_inp0, WCD934X_CDC_RX_INP_MUX_RX_INT3_CFG0, 0,
  5786. rx_prim_mix_text);
  5787. WCD_DAPM_ENUM(rx_int3_1_mix_inp1, WCD934X_CDC_RX_INP_MUX_RX_INT3_CFG0, 4,
  5788. rx_prim_mix_text);
  5789. WCD_DAPM_ENUM(rx_int3_1_mix_inp2, WCD934X_CDC_RX_INP_MUX_RX_INT3_CFG1, 4,
  5790. rx_prim_mix_text);
  5791. WCD_DAPM_ENUM(rx_int4_1_mix_inp0, WCD934X_CDC_RX_INP_MUX_RX_INT4_CFG0, 0,
  5792. rx_prim_mix_text);
  5793. WCD_DAPM_ENUM(rx_int4_1_mix_inp1, WCD934X_CDC_RX_INP_MUX_RX_INT4_CFG0, 4,
  5794. rx_prim_mix_text);
  5795. WCD_DAPM_ENUM(rx_int4_1_mix_inp2, WCD934X_CDC_RX_INP_MUX_RX_INT4_CFG1, 4,
  5796. rx_prim_mix_text);
  5797. WCD_DAPM_ENUM(rx_int7_1_mix_inp0, WCD934X_CDC_RX_INP_MUX_RX_INT7_CFG0, 0,
  5798. rx_prim_mix_text);
  5799. WCD_DAPM_ENUM(rx_int7_1_mix_inp1, WCD934X_CDC_RX_INP_MUX_RX_INT7_CFG0, 4,
  5800. rx_prim_mix_text);
  5801. WCD_DAPM_ENUM(rx_int7_1_mix_inp2, WCD934X_CDC_RX_INP_MUX_RX_INT7_CFG1, 4,
  5802. rx_prim_mix_text);
  5803. WCD_DAPM_ENUM(rx_int8_1_mix_inp0, WCD934X_CDC_RX_INP_MUX_RX_INT8_CFG0, 0,
  5804. rx_prim_mix_text);
  5805. WCD_DAPM_ENUM(rx_int8_1_mix_inp1, WCD934X_CDC_RX_INP_MUX_RX_INT8_CFG0, 4,
  5806. rx_prim_mix_text);
  5807. WCD_DAPM_ENUM(rx_int8_1_mix_inp2, WCD934X_CDC_RX_INP_MUX_RX_INT8_CFG1, 4,
  5808. rx_prim_mix_text);
  5809. WCD_DAPM_ENUM(rx_int0_mix2_inp, WCD934X_CDC_RX_INP_MUX_SIDETONE_SRC_CFG0, 0,
  5810. rx_sidetone_mix_text);
  5811. WCD_DAPM_ENUM(rx_int1_mix2_inp, WCD934X_CDC_RX_INP_MUX_SIDETONE_SRC_CFG0, 2,
  5812. rx_sidetone_mix_text);
  5813. WCD_DAPM_ENUM(rx_int2_mix2_inp, WCD934X_CDC_RX_INP_MUX_SIDETONE_SRC_CFG0, 4,
  5814. rx_sidetone_mix_text);
  5815. WCD_DAPM_ENUM(rx_int3_mix2_inp, WCD934X_CDC_RX_INP_MUX_SIDETONE_SRC_CFG0, 6,
  5816. rx_sidetone_mix_text);
  5817. WCD_DAPM_ENUM(rx_int4_mix2_inp, WCD934X_CDC_RX_INP_MUX_SIDETONE_SRC_CFG1, 0,
  5818. rx_sidetone_mix_text);
  5819. WCD_DAPM_ENUM(rx_int7_mix2_inp, WCD934X_CDC_RX_INP_MUX_SIDETONE_SRC_CFG1, 2,
  5820. rx_sidetone_mix_text);
  5821. WCD_DAPM_ENUM(tx_adc_mux10, WCD934X_CDC_TX_INP_MUX_ADC_MUX1_CFG1, 4,
  5822. adc_mux_text);
  5823. WCD_DAPM_ENUM(tx_adc_mux11, WCD934X_CDC_TX_INP_MUX_ADC_MUX2_CFG1, 4,
  5824. adc_mux_text);
  5825. WCD_DAPM_ENUM(tx_adc_mux12, WCD934X_CDC_TX_INP_MUX_ADC_MUX3_CFG1, 4,
  5826. adc_mux_text);
  5827. WCD_DAPM_ENUM(tx_adc_mux13, WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG1, 6,
  5828. adc_mux_text);
  5829. WCD_DAPM_ENUM(tx_dmic_mux0, WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG0, 3,
  5830. dmic_mux_text);
  5831. WCD_DAPM_ENUM(tx_dmic_mux1, WCD934X_CDC_TX_INP_MUX_ADC_MUX1_CFG0, 3,
  5832. dmic_mux_text);
  5833. WCD_DAPM_ENUM(tx_dmic_mux2, WCD934X_CDC_TX_INP_MUX_ADC_MUX2_CFG0, 3,
  5834. dmic_mux_text);
  5835. WCD_DAPM_ENUM(tx_dmic_mux3, WCD934X_CDC_TX_INP_MUX_ADC_MUX3_CFG0, 3,
  5836. dmic_mux_text);
  5837. WCD_DAPM_ENUM(tx_dmic_mux4, WCD934X_CDC_TX_INP_MUX_ADC_MUX4_CFG0, 3,
  5838. dmic_mux_text);
  5839. WCD_DAPM_ENUM(tx_dmic_mux5, WCD934X_CDC_TX_INP_MUX_ADC_MUX5_CFG0, 3,
  5840. dmic_mux_text);
  5841. WCD_DAPM_ENUM(tx_dmic_mux6, WCD934X_CDC_TX_INP_MUX_ADC_MUX6_CFG0, 3,
  5842. dmic_mux_text);
  5843. WCD_DAPM_ENUM(tx_dmic_mux7, WCD934X_CDC_TX_INP_MUX_ADC_MUX7_CFG0, 3,
  5844. dmic_mux_text);
  5845. WCD_DAPM_ENUM(tx_dmic_mux8, WCD934X_CDC_TX_INP_MUX_ADC_MUX8_CFG0, 3,
  5846. dmic_mux_text);
  5847. WCD_DAPM_ENUM(tx_dmic_mux10, WCD934X_CDC_TX_INP_MUX_ADC_MUX10_CFG0, 3,
  5848. dmic_mux_text);
  5849. WCD_DAPM_ENUM(tx_dmic_mux11, WCD934X_CDC_TX_INP_MUX_ADC_MUX11_CFG0, 3,
  5850. dmic_mux_text);
  5851. WCD_DAPM_ENUM(tx_dmic_mux12, WCD934X_CDC_TX_INP_MUX_ADC_MUX12_CFG0, 3,
  5852. dmic_mux_text);
  5853. WCD_DAPM_ENUM(tx_dmic_mux13, WCD934X_CDC_TX_INP_MUX_ADC_MUX13_CFG0, 3,
  5854. dmic_mux_text);
  5855. WCD_DAPM_ENUM(tx_amic_mux0, WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG0, 0,
  5856. amic_mux_text);
  5857. WCD_DAPM_ENUM(tx_amic_mux1, WCD934X_CDC_TX_INP_MUX_ADC_MUX1_CFG0, 0,
  5858. amic_mux_text);
  5859. WCD_DAPM_ENUM(tx_amic_mux2, WCD934X_CDC_TX_INP_MUX_ADC_MUX2_CFG0, 0,
  5860. amic_mux_text);
  5861. WCD_DAPM_ENUM(tx_amic_mux3, WCD934X_CDC_TX_INP_MUX_ADC_MUX3_CFG0, 0,
  5862. amic_mux_text);
  5863. WCD_DAPM_ENUM(tx_amic_mux4, WCD934X_CDC_TX_INP_MUX_ADC_MUX4_CFG0, 0,
  5864. amic_mux_text);
  5865. WCD_DAPM_ENUM(tx_amic_mux5, WCD934X_CDC_TX_INP_MUX_ADC_MUX5_CFG0, 0,
  5866. amic_mux_text);
  5867. WCD_DAPM_ENUM(tx_amic_mux6, WCD934X_CDC_TX_INP_MUX_ADC_MUX6_CFG0, 0,
  5868. amic_mux_text);
  5869. WCD_DAPM_ENUM(tx_amic_mux7, WCD934X_CDC_TX_INP_MUX_ADC_MUX7_CFG0, 0,
  5870. amic_mux_text);
  5871. WCD_DAPM_ENUM(tx_amic_mux8, WCD934X_CDC_TX_INP_MUX_ADC_MUX8_CFG0, 0,
  5872. amic_mux_text);
  5873. WCD_DAPM_ENUM(tx_amic_mux10, WCD934X_CDC_TX_INP_MUX_ADC_MUX10_CFG0, 0,
  5874. amic_mux_text);
  5875. WCD_DAPM_ENUM(tx_amic_mux11, WCD934X_CDC_TX_INP_MUX_ADC_MUX11_CFG0, 0,
  5876. amic_mux_text);
  5877. WCD_DAPM_ENUM(tx_amic_mux12, WCD934X_CDC_TX_INP_MUX_ADC_MUX12_CFG0, 0,
  5878. amic_mux_text);
  5879. WCD_DAPM_ENUM(tx_amic_mux13, WCD934X_CDC_TX_INP_MUX_ADC_MUX13_CFG0, 0,
  5880. amic_mux_text);
  5881. WCD_DAPM_ENUM(tx_amic4_5, WCD934X_TX_NEW_AMIC_4_5_SEL, 7, amic4_5_sel_text);
  5882. WCD_DAPM_ENUM(cdc_if_tx0, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG0, 0,
  5883. cdc_if_tx0_mux_text);
  5884. WCD_DAPM_ENUM(cdc_if_tx1, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG0, 2,
  5885. cdc_if_tx1_mux_text);
  5886. WCD_DAPM_ENUM(cdc_if_tx2, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG0, 4,
  5887. cdc_if_tx2_mux_text);
  5888. WCD_DAPM_ENUM(cdc_if_tx3, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG0, 6,
  5889. cdc_if_tx3_mux_text);
  5890. WCD_DAPM_ENUM(cdc_if_tx4, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG1, 0,
  5891. cdc_if_tx4_mux_text);
  5892. WCD_DAPM_ENUM(cdc_if_tx5, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG1, 2,
  5893. cdc_if_tx5_mux_text);
  5894. WCD_DAPM_ENUM(cdc_if_tx6, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG1, 4,
  5895. cdc_if_tx6_mux_text);
  5896. WCD_DAPM_ENUM(cdc_if_tx7, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG1, 6,
  5897. cdc_if_tx7_mux_text);
  5898. WCD_DAPM_ENUM(cdc_if_tx8, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG2, 0,
  5899. cdc_if_tx8_mux_text);
  5900. WCD_DAPM_ENUM(cdc_if_tx9, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG2, 2,
  5901. cdc_if_tx9_mux_text);
  5902. WCD_DAPM_ENUM(cdc_if_tx10, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG2, 4,
  5903. cdc_if_tx10_mux_text);
  5904. WCD_DAPM_ENUM(cdc_if_tx11_inp1, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG3, 0,
  5905. cdc_if_tx11_inp1_mux_text);
  5906. WCD_DAPM_ENUM(cdc_if_tx11, WCD934X_DATA_HUB_SB_TX11_INP_CFG, 0,
  5907. cdc_if_tx11_mux_text);
  5908. WCD_DAPM_ENUM(cdc_if_tx13_inp1, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG3, 4,
  5909. cdc_if_tx13_inp1_mux_text);
  5910. WCD_DAPM_ENUM(cdc_if_tx13, WCD934X_DATA_HUB_SB_TX13_INP_CFG, 0,
  5911. cdc_if_tx13_mux_text);
  5912. WCD_DAPM_ENUM(rx_mix_tx0, WCD934X_CDC_RX_INP_MUX_RX_MIX_CFG0, 0,
  5913. rx_echo_mux_text);
  5914. WCD_DAPM_ENUM(rx_mix_tx1, WCD934X_CDC_RX_INP_MUX_RX_MIX_CFG0, 4,
  5915. rx_echo_mux_text);
  5916. WCD_DAPM_ENUM(rx_mix_tx2, WCD934X_CDC_RX_INP_MUX_RX_MIX_CFG1, 0,
  5917. rx_echo_mux_text);
  5918. WCD_DAPM_ENUM(rx_mix_tx3, WCD934X_CDC_RX_INP_MUX_RX_MIX_CFG1, 4,
  5919. rx_echo_mux_text);
  5920. WCD_DAPM_ENUM(rx_mix_tx4, WCD934X_CDC_RX_INP_MUX_RX_MIX_CFG2, 0,
  5921. rx_echo_mux_text);
  5922. WCD_DAPM_ENUM(rx_mix_tx5, WCD934X_CDC_RX_INP_MUX_RX_MIX_CFG2, 4,
  5923. rx_echo_mux_text);
  5924. WCD_DAPM_ENUM(rx_mix_tx6, WCD934X_CDC_RX_INP_MUX_RX_MIX_CFG3, 0,
  5925. rx_echo_mux_text);
  5926. WCD_DAPM_ENUM(rx_mix_tx7, WCD934X_CDC_RX_INP_MUX_RX_MIX_CFG3, 4,
  5927. rx_echo_mux_text);
  5928. WCD_DAPM_ENUM(rx_mix_tx8, WCD934X_CDC_RX_INP_MUX_RX_MIX_CFG4, 0,
  5929. rx_echo_mux_text);
  5930. WCD_DAPM_ENUM(iir0_inp0, WCD934X_CDC_SIDETONE_IIR_INP_MUX_IIR0_MIX_CFG0, 0,
  5931. iir_inp_mux_text);
  5932. WCD_DAPM_ENUM(iir0_inp1, WCD934X_CDC_SIDETONE_IIR_INP_MUX_IIR0_MIX_CFG1, 0,
  5933. iir_inp_mux_text);
  5934. WCD_DAPM_ENUM(iir0_inp2, WCD934X_CDC_SIDETONE_IIR_INP_MUX_IIR0_MIX_CFG2, 0,
  5935. iir_inp_mux_text);
  5936. WCD_DAPM_ENUM(iir0_inp3, WCD934X_CDC_SIDETONE_IIR_INP_MUX_IIR0_MIX_CFG3, 0,
  5937. iir_inp_mux_text);
  5938. WCD_DAPM_ENUM(iir1_inp0, WCD934X_CDC_SIDETONE_IIR_INP_MUX_IIR1_MIX_CFG0, 0,
  5939. iir_inp_mux_text);
  5940. WCD_DAPM_ENUM(iir1_inp1, WCD934X_CDC_SIDETONE_IIR_INP_MUX_IIR1_MIX_CFG1, 0,
  5941. iir_inp_mux_text);
  5942. WCD_DAPM_ENUM(iir1_inp2, WCD934X_CDC_SIDETONE_IIR_INP_MUX_IIR1_MIX_CFG2, 0,
  5943. iir_inp_mux_text);
  5944. WCD_DAPM_ENUM(iir1_inp3, WCD934X_CDC_SIDETONE_IIR_INP_MUX_IIR1_MIX_CFG3, 0,
  5945. iir_inp_mux_text);
  5946. WCD_DAPM_ENUM(rx_int0_1_interp, SND_SOC_NOPM, 0, rx_int0_1_interp_mux_text);
  5947. WCD_DAPM_ENUM(rx_int1_1_interp, SND_SOC_NOPM, 0, rx_int1_1_interp_mux_text);
  5948. WCD_DAPM_ENUM(rx_int2_1_interp, SND_SOC_NOPM, 0, rx_int2_1_interp_mux_text);
  5949. WCD_DAPM_ENUM(rx_int3_1_interp, SND_SOC_NOPM, 0, rx_int3_1_interp_mux_text);
  5950. WCD_DAPM_ENUM(rx_int4_1_interp, SND_SOC_NOPM, 0, rx_int4_1_interp_mux_text);
  5951. WCD_DAPM_ENUM(rx_int7_1_interp, SND_SOC_NOPM, 0, rx_int7_1_interp_mux_text);
  5952. WCD_DAPM_ENUM(rx_int8_1_interp, SND_SOC_NOPM, 0, rx_int8_1_interp_mux_text);
  5953. WCD_DAPM_ENUM(rx_int0_2_interp, SND_SOC_NOPM, 0, rx_int0_2_interp_mux_text);
  5954. WCD_DAPM_ENUM(rx_int1_2_interp, SND_SOC_NOPM, 0, rx_int1_2_interp_mux_text);
  5955. WCD_DAPM_ENUM(rx_int2_2_interp, SND_SOC_NOPM, 0, rx_int2_2_interp_mux_text);
  5956. WCD_DAPM_ENUM(rx_int3_2_interp, SND_SOC_NOPM, 0, rx_int3_2_interp_mux_text);
  5957. WCD_DAPM_ENUM(rx_int4_2_interp, SND_SOC_NOPM, 0, rx_int4_2_interp_mux_text);
  5958. WCD_DAPM_ENUM(rx_int7_2_interp, SND_SOC_NOPM, 0, rx_int7_2_interp_mux_text);
  5959. WCD_DAPM_ENUM(rx_int8_2_interp, SND_SOC_NOPM, 0, rx_int8_2_interp_mux_text);
  5960. WCD_DAPM_ENUM(mad_sel, WCD934X_CPE_SS_SVA_CFG, 0,
  5961. mad_sel_txt);
  5962. WCD_DAPM_ENUM(mad_inp_mux, WCD934X_CPE_SS_SVA_CFG, 2,
  5963. mad_inp_mux_txt);
  5964. WCD_DAPM_ENUM_EXT(rx_int0_dem_inp, WCD934X_CDC_RX0_RX_PATH_SEC0, 0,
  5965. rx_int_dem_inp_mux_text, snd_soc_dapm_get_enum_double,
  5966. tavil_int_dem_inp_mux_put);
  5967. WCD_DAPM_ENUM_EXT(rx_int1_dem_inp, WCD934X_CDC_RX1_RX_PATH_SEC0, 0,
  5968. rx_int_dem_inp_mux_text, snd_soc_dapm_get_enum_double,
  5969. tavil_int_dem_inp_mux_put);
  5970. WCD_DAPM_ENUM_EXT(rx_int2_dem_inp, WCD934X_CDC_RX2_RX_PATH_SEC0, 0,
  5971. rx_int_dem_inp_mux_text, snd_soc_dapm_get_enum_double,
  5972. tavil_int_dem_inp_mux_put);
  5973. WCD_DAPM_ENUM_EXT(tx_adc_mux0, WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG1, 0,
  5974. adc_mux_text, snd_soc_dapm_get_enum_double, tavil_dec_enum_put);
  5975. WCD_DAPM_ENUM_EXT(tx_adc_mux1, WCD934X_CDC_TX_INP_MUX_ADC_MUX1_CFG1, 0,
  5976. adc_mux_text, snd_soc_dapm_get_enum_double, tavil_dec_enum_put);
  5977. WCD_DAPM_ENUM_EXT(tx_adc_mux2, WCD934X_CDC_TX_INP_MUX_ADC_MUX2_CFG1, 0,
  5978. adc_mux_text, snd_soc_dapm_get_enum_double, tavil_dec_enum_put);
  5979. WCD_DAPM_ENUM_EXT(tx_adc_mux3, WCD934X_CDC_TX_INP_MUX_ADC_MUX3_CFG1, 0,
  5980. adc_mux_text, snd_soc_dapm_get_enum_double, tavil_dec_enum_put);
  5981. WCD_DAPM_ENUM_EXT(tx_adc_mux4, WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG1, 2,
  5982. adc_mux_text, snd_soc_dapm_get_enum_double, tavil_dec_enum_put);
  5983. WCD_DAPM_ENUM_EXT(tx_adc_mux5, WCD934X_CDC_TX_INP_MUX_ADC_MUX1_CFG1, 2,
  5984. adc_mux_text, snd_soc_dapm_get_enum_double, tavil_dec_enum_put);
  5985. WCD_DAPM_ENUM_EXT(tx_adc_mux6, WCD934X_CDC_TX_INP_MUX_ADC_MUX2_CFG1, 2,
  5986. adc_mux_text, snd_soc_dapm_get_enum_double, tavil_dec_enum_put);
  5987. WCD_DAPM_ENUM_EXT(tx_adc_mux7, WCD934X_CDC_TX_INP_MUX_ADC_MUX3_CFG1, 2,
  5988. adc_mux_text, snd_soc_dapm_get_enum_double, tavil_dec_enum_put);
  5989. WCD_DAPM_ENUM_EXT(tx_adc_mux8, WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG1, 4,
  5990. adc_mux_text, snd_soc_dapm_get_enum_double, tavil_dec_enum_put);
  5991. WCD_DAPM_ENUM(asrc0, WCD934X_CDC_RX_INP_MUX_SPLINE_ASRC_CFG0, 0,
  5992. asrc0_mux_text);
  5993. WCD_DAPM_ENUM(asrc1, WCD934X_CDC_RX_INP_MUX_SPLINE_ASRC_CFG0, 2,
  5994. asrc1_mux_text);
  5995. WCD_DAPM_ENUM(asrc2, WCD934X_CDC_RX_INP_MUX_SPLINE_ASRC_CFG0, 4,
  5996. asrc2_mux_text);
  5997. WCD_DAPM_ENUM(asrc3, WCD934X_CDC_RX_INP_MUX_SPLINE_ASRC_CFG0, 6,
  5998. asrc3_mux_text);
  5999. WCD_DAPM_ENUM(int1_1_native, SND_SOC_NOPM, 0, native_mux_text);
  6000. WCD_DAPM_ENUM(int2_1_native, SND_SOC_NOPM, 0, native_mux_text);
  6001. WCD_DAPM_ENUM(int3_1_native, SND_SOC_NOPM, 0, native_mux_text);
  6002. WCD_DAPM_ENUM(int4_1_native, SND_SOC_NOPM, 0, native_mux_text);
  6003. WCD_DAPM_ENUM(int1_2_native, SND_SOC_NOPM, 0, native_mux_text);
  6004. WCD_DAPM_ENUM(int2_2_native, SND_SOC_NOPM, 0, native_mux_text);
  6005. WCD_DAPM_ENUM(int3_2_native, SND_SOC_NOPM, 0, native_mux_text);
  6006. WCD_DAPM_ENUM(int4_2_native, SND_SOC_NOPM, 0, native_mux_text);
  6007. WCD_DAPM_ENUM(int7_2_native, SND_SOC_NOPM, 0, native_mux_text);
  6008. WCD_DAPM_ENUM(int8_2_native, SND_SOC_NOPM, 0, native_mux_text);
  6009. WCD_DAPM_ENUM(anc0_fb, WCD934X_CDC_RX_INP_MUX_ANC_CFG0, 0, anc0_fb_mux_text);
  6010. WCD_DAPM_ENUM(anc1_fb, WCD934X_CDC_RX_INP_MUX_ANC_CFG0, 3, anc1_fb_mux_text);
  6011. WCD_DAPM_ENUM(wdma3_port0, WCD934X_DMA_WDMA3_PRT_CFG, 0, wdma3_port0_text);
  6012. WCD_DAPM_ENUM(wdma3_port1, WCD934X_DMA_WDMA3_PRT_CFG, 1, wdma3_port1_text);
  6013. WCD_DAPM_ENUM(wdma3_port2, WCD934X_DMA_WDMA3_PRT_CFG, 2, wdma3_port2_text);
  6014. WCD_DAPM_ENUM(wdma3_port3, WCD934X_DMA_WDMA3_PRT_CFG, 3, wdma3_port3_text);
  6015. WCD_DAPM_ENUM(wdma3_port4, WCD934X_DMA_WDMA3_PRT_CFG, 4, wdma3_port4_text);
  6016. WCD_DAPM_ENUM(wdma3_port5, WCD934X_DMA_WDMA3_PRT_CFG, 5, wdma3_port5_text);
  6017. WCD_DAPM_ENUM(wdma3_port6, WCD934X_DMA_WDMA3_PRT_CFG, 6, wdma3_port6_text);
  6018. WCD_DAPM_ENUM(wdma3_ch0, WCD934X_DMA_CH_0_1_CFG_WDMA_3, 0, wdma3_ch_text);
  6019. WCD_DAPM_ENUM(wdma3_ch1, WCD934X_DMA_CH_0_1_CFG_WDMA_3, 4, wdma3_ch_text);
  6020. WCD_DAPM_ENUM(wdma3_ch2, WCD934X_DMA_CH_2_3_CFG_WDMA_3, 0, wdma3_ch_text);
  6021. WCD_DAPM_ENUM(wdma3_ch3, WCD934X_DMA_CH_2_3_CFG_WDMA_3, 4, wdma3_ch_text);
  6022. static const struct snd_kcontrol_new anc_ear_switch =
  6023. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0);
  6024. static const struct snd_kcontrol_new anc_ear_spkr_switch =
  6025. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0);
  6026. static const struct snd_kcontrol_new anc_spkr_pa_switch =
  6027. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0);
  6028. static const struct snd_kcontrol_new anc_hphl_pa_switch =
  6029. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0);
  6030. static const struct snd_kcontrol_new anc_hphr_pa_switch =
  6031. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0);
  6032. static const struct snd_kcontrol_new mad_cpe1_switch =
  6033. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0);
  6034. static const struct snd_kcontrol_new mad_cpe2_switch =
  6035. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0);
  6036. static const struct snd_kcontrol_new mad_brdcst_switch =
  6037. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0);
  6038. static const struct snd_kcontrol_new adc_us_mux0_switch =
  6039. SOC_DAPM_SINGLE("US_Switch", SND_SOC_NOPM, 0, 1, 0);
  6040. static const struct snd_kcontrol_new adc_us_mux1_switch =
  6041. SOC_DAPM_SINGLE("US_Switch", SND_SOC_NOPM, 0, 1, 0);
  6042. static const struct snd_kcontrol_new adc_us_mux2_switch =
  6043. SOC_DAPM_SINGLE("US_Switch", SND_SOC_NOPM, 0, 1, 0);
  6044. static const struct snd_kcontrol_new adc_us_mux3_switch =
  6045. SOC_DAPM_SINGLE("US_Switch", SND_SOC_NOPM, 0, 1, 0);
  6046. static const struct snd_kcontrol_new adc_us_mux4_switch =
  6047. SOC_DAPM_SINGLE("US_Switch", SND_SOC_NOPM, 0, 1, 0);
  6048. static const struct snd_kcontrol_new adc_us_mux5_switch =
  6049. SOC_DAPM_SINGLE("US_Switch", SND_SOC_NOPM, 0, 1, 0);
  6050. static const struct snd_kcontrol_new adc_us_mux6_switch =
  6051. SOC_DAPM_SINGLE("US_Switch", SND_SOC_NOPM, 0, 1, 0);
  6052. static const struct snd_kcontrol_new adc_us_mux7_switch =
  6053. SOC_DAPM_SINGLE("US_Switch", SND_SOC_NOPM, 0, 1, 0);
  6054. static const struct snd_kcontrol_new adc_us_mux8_switch =
  6055. SOC_DAPM_SINGLE("US_Switch", SND_SOC_NOPM, 0, 1, 0);
  6056. static const struct snd_kcontrol_new rx_int1_asrc_switch[] = {
  6057. SOC_DAPM_SINGLE("HPHL Switch", SND_SOC_NOPM, 0, 1, 0),
  6058. };
  6059. static const struct snd_kcontrol_new rx_int2_asrc_switch[] = {
  6060. SOC_DAPM_SINGLE("HPHR Switch", SND_SOC_NOPM, 0, 1, 0),
  6061. };
  6062. static const struct snd_kcontrol_new rx_int3_asrc_switch[] = {
  6063. SOC_DAPM_SINGLE("LO1 Switch", SND_SOC_NOPM, 0, 1, 0),
  6064. };
  6065. static const struct snd_kcontrol_new rx_int4_asrc_switch[] = {
  6066. SOC_DAPM_SINGLE("LO2 Switch", SND_SOC_NOPM, 0, 1, 0),
  6067. };
  6068. static const struct snd_kcontrol_new wdma3_onoff_switch =
  6069. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0);
  6070. static int tavil_dsd_mixer_get(struct snd_kcontrol *kcontrol,
  6071. struct snd_ctl_elem_value *ucontrol)
  6072. {
  6073. struct snd_soc_dapm_context *dapm =
  6074. snd_soc_dapm_kcontrol_dapm(kcontrol);
  6075. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(dapm);
  6076. struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec);
  6077. struct soc_mixer_control *mc =
  6078. (struct soc_mixer_control *)kcontrol->private_value;
  6079. struct tavil_dsd_config *dsd_conf = tavil_p->dsd_config;
  6080. int val;
  6081. val = tavil_dsd_get_current_mixer_value(dsd_conf, mc->shift);
  6082. ucontrol->value.integer.value[0] = ((val < 0) ? 0 : val);
  6083. return 0;
  6084. }
  6085. static int tavil_dsd_mixer_put(struct snd_kcontrol *kcontrol,
  6086. struct snd_ctl_elem_value *ucontrol)
  6087. {
  6088. struct soc_mixer_control *mc =
  6089. (struct soc_mixer_control *)kcontrol->private_value;
  6090. struct snd_soc_dapm_context *dapm =
  6091. snd_soc_dapm_kcontrol_dapm(kcontrol);
  6092. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(dapm);
  6093. struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec);
  6094. unsigned int wval = ucontrol->value.integer.value[0];
  6095. struct tavil_dsd_config *dsd_conf = tavil_p->dsd_config;
  6096. if (!dsd_conf)
  6097. return 0;
  6098. mutex_lock(&tavil_p->codec_mutex);
  6099. tavil_dsd_set_out_select(dsd_conf, mc->shift);
  6100. tavil_dsd_set_mixer_value(dsd_conf, mc->shift, wval);
  6101. mutex_unlock(&tavil_p->codec_mutex);
  6102. snd_soc_dapm_mixer_update_power(dapm, kcontrol, wval, NULL);
  6103. return 0;
  6104. }
  6105. static const struct snd_kcontrol_new hphl_mixer[] = {
  6106. SOC_SINGLE_EXT("DSD HPHL Switch", SND_SOC_NOPM, INTERP_HPHL, 1, 0,
  6107. tavil_dsd_mixer_get, tavil_dsd_mixer_put),
  6108. };
  6109. static const struct snd_kcontrol_new hphr_mixer[] = {
  6110. SOC_SINGLE_EXT("DSD HPHR Switch", SND_SOC_NOPM, INTERP_HPHR, 1, 0,
  6111. tavil_dsd_mixer_get, tavil_dsd_mixer_put),
  6112. };
  6113. static const struct snd_kcontrol_new lo1_mixer[] = {
  6114. SOC_SINGLE_EXT("DSD LO1 Switch", SND_SOC_NOPM, INTERP_LO1, 1, 0,
  6115. tavil_dsd_mixer_get, tavil_dsd_mixer_put),
  6116. };
  6117. static const struct snd_kcontrol_new lo2_mixer[] = {
  6118. SOC_SINGLE_EXT("DSD LO2 Switch", SND_SOC_NOPM, INTERP_LO2, 1, 0,
  6119. tavil_dsd_mixer_get, tavil_dsd_mixer_put),
  6120. };
  6121. static const struct snd_soc_dapm_widget tavil_dapm_widgets[] = {
  6122. SND_SOC_DAPM_AIF_IN_E("AIF1 PB", "AIF1 Playback", 0, SND_SOC_NOPM,
  6123. AIF1_PB, 0, tavil_codec_enable_slimrx,
  6124. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  6125. SND_SOC_DAPM_AIF_IN_E("AIF2 PB", "AIF2 Playback", 0, SND_SOC_NOPM,
  6126. AIF2_PB, 0, tavil_codec_enable_slimrx,
  6127. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  6128. SND_SOC_DAPM_AIF_IN_E("AIF3 PB", "AIF3 Playback", 0, SND_SOC_NOPM,
  6129. AIF3_PB, 0, tavil_codec_enable_slimrx,
  6130. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  6131. SND_SOC_DAPM_AIF_IN_E("AIF4 PB", "AIF4 Playback", 0, SND_SOC_NOPM,
  6132. AIF4_PB, 0, tavil_codec_enable_slimrx,
  6133. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  6134. WCD_DAPM_MUX("SLIM RX0 MUX", WCD934X_RX0, slim_rx0),
  6135. WCD_DAPM_MUX("SLIM RX1 MUX", WCD934X_RX1, slim_rx1),
  6136. WCD_DAPM_MUX("SLIM RX2 MUX", WCD934X_RX2, slim_rx2),
  6137. WCD_DAPM_MUX("SLIM RX3 MUX", WCD934X_RX3, slim_rx3),
  6138. WCD_DAPM_MUX("SLIM RX4 MUX", WCD934X_RX4, slim_rx4),
  6139. WCD_DAPM_MUX("SLIM RX5 MUX", WCD934X_RX5, slim_rx5),
  6140. WCD_DAPM_MUX("SLIM RX6 MUX", WCD934X_RX6, slim_rx6),
  6141. WCD_DAPM_MUX("SLIM RX7 MUX", WCD934X_RX7, slim_rx7),
  6142. SND_SOC_DAPM_MIXER("SLIM RX0", SND_SOC_NOPM, 0, 0, NULL, 0),
  6143. SND_SOC_DAPM_MIXER("SLIM RX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  6144. SND_SOC_DAPM_MIXER("SLIM RX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  6145. SND_SOC_DAPM_MIXER("SLIM RX3", SND_SOC_NOPM, 0, 0, NULL, 0),
  6146. SND_SOC_DAPM_MIXER("SLIM RX4", SND_SOC_NOPM, 0, 0, NULL, 0),
  6147. SND_SOC_DAPM_MIXER("SLIM RX5", SND_SOC_NOPM, 0, 0, NULL, 0),
  6148. SND_SOC_DAPM_MIXER("SLIM RX6", SND_SOC_NOPM, 0, 0, NULL, 0),
  6149. SND_SOC_DAPM_MIXER("SLIM RX7", SND_SOC_NOPM, 0, 0, NULL, 0),
  6150. WCD_DAPM_MUX("CDC_IF RX0 MUX", WCD934X_RX0, cdc_if_rx0),
  6151. WCD_DAPM_MUX("CDC_IF RX1 MUX", WCD934X_RX1, cdc_if_rx1),
  6152. WCD_DAPM_MUX("CDC_IF RX2 MUX", WCD934X_RX2, cdc_if_rx2),
  6153. WCD_DAPM_MUX("CDC_IF RX3 MUX", WCD934X_RX3, cdc_if_rx3),
  6154. WCD_DAPM_MUX("CDC_IF RX4 MUX", WCD934X_RX4, cdc_if_rx4),
  6155. WCD_DAPM_MUX("CDC_IF RX5 MUX", WCD934X_RX5, cdc_if_rx5),
  6156. WCD_DAPM_MUX("CDC_IF RX6 MUX", WCD934X_RX6, cdc_if_rx6),
  6157. WCD_DAPM_MUX("CDC_IF RX7 MUX", WCD934X_RX7, cdc_if_rx7),
  6158. SND_SOC_DAPM_MUX_E("RX INT0_2 MUX", SND_SOC_NOPM, INTERP_EAR, 0,
  6159. &rx_int0_2_mux, tavil_codec_enable_mix_path,
  6160. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6161. SND_SOC_DAPM_POST_PMD),
  6162. SND_SOC_DAPM_MUX_E("RX INT1_2 MUX", SND_SOC_NOPM, INTERP_HPHL, 0,
  6163. &rx_int1_2_mux, tavil_codec_enable_mix_path,
  6164. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6165. SND_SOC_DAPM_POST_PMD),
  6166. SND_SOC_DAPM_MUX_E("RX INT2_2 MUX", SND_SOC_NOPM, INTERP_HPHR, 0,
  6167. &rx_int2_2_mux, tavil_codec_enable_mix_path,
  6168. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6169. SND_SOC_DAPM_POST_PMD),
  6170. SND_SOC_DAPM_MUX_E("RX INT3_2 MUX", SND_SOC_NOPM, INTERP_LO1, 0,
  6171. &rx_int3_2_mux, tavil_codec_enable_mix_path,
  6172. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6173. SND_SOC_DAPM_POST_PMD),
  6174. SND_SOC_DAPM_MUX_E("RX INT4_2 MUX", SND_SOC_NOPM, INTERP_LO2, 0,
  6175. &rx_int4_2_mux, tavil_codec_enable_mix_path,
  6176. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6177. SND_SOC_DAPM_POST_PMD),
  6178. SND_SOC_DAPM_MUX_E("RX INT7_2 MUX", SND_SOC_NOPM, INTERP_SPKR1, 0,
  6179. &rx_int7_2_mux, tavil_codec_enable_mix_path,
  6180. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6181. SND_SOC_DAPM_POST_PMD),
  6182. SND_SOC_DAPM_MUX_E("RX INT8_2 MUX", SND_SOC_NOPM, INTERP_SPKR2, 0,
  6183. &rx_int8_2_mux, tavil_codec_enable_mix_path,
  6184. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6185. SND_SOC_DAPM_POST_PMD),
  6186. WCD_DAPM_MUX("RX INT0_1 MIX1 INP0", 0, rx_int0_1_mix_inp0),
  6187. WCD_DAPM_MUX("RX INT0_1 MIX1 INP1", 0, rx_int0_1_mix_inp1),
  6188. WCD_DAPM_MUX("RX INT0_1 MIX1 INP2", 0, rx_int0_1_mix_inp2),
  6189. WCD_DAPM_MUX("RX INT1_1 MIX1 INP0", 0, rx_int1_1_mix_inp0),
  6190. WCD_DAPM_MUX("RX INT1_1 MIX1 INP1", 0, rx_int1_1_mix_inp1),
  6191. WCD_DAPM_MUX("RX INT1_1 MIX1 INP2", 0, rx_int1_1_mix_inp2),
  6192. WCD_DAPM_MUX("RX INT2_1 MIX1 INP0", 0, rx_int2_1_mix_inp0),
  6193. WCD_DAPM_MUX("RX INT2_1 MIX1 INP1", 0, rx_int2_1_mix_inp1),
  6194. WCD_DAPM_MUX("RX INT2_1 MIX1 INP2", 0, rx_int2_1_mix_inp2),
  6195. WCD_DAPM_MUX("RX INT3_1 MIX1 INP0", 0, rx_int3_1_mix_inp0),
  6196. WCD_DAPM_MUX("RX INT3_1 MIX1 INP1", 0, rx_int3_1_mix_inp1),
  6197. WCD_DAPM_MUX("RX INT3_1 MIX1 INP2", 0, rx_int3_1_mix_inp2),
  6198. WCD_DAPM_MUX("RX INT4_1 MIX1 INP0", 0, rx_int4_1_mix_inp0),
  6199. WCD_DAPM_MUX("RX INT4_1 MIX1 INP1", 0, rx_int4_1_mix_inp1),
  6200. WCD_DAPM_MUX("RX INT4_1 MIX1 INP2", 0, rx_int4_1_mix_inp2),
  6201. SND_SOC_DAPM_MUX_E("RX INT7_1 MIX1 INP0", SND_SOC_NOPM, 0, 0,
  6202. &rx_int7_1_mix_inp0_mux, tavil_codec_enable_swr,
  6203. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6204. SND_SOC_DAPM_MUX_E("RX INT7_1 MIX1 INP1", SND_SOC_NOPM, 0, 0,
  6205. &rx_int7_1_mix_inp1_mux, tavil_codec_enable_swr,
  6206. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6207. SND_SOC_DAPM_MUX_E("RX INT7_1 MIX1 INP2", SND_SOC_NOPM, 0, 0,
  6208. &rx_int7_1_mix_inp2_mux, tavil_codec_enable_swr,
  6209. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6210. SND_SOC_DAPM_MUX_E("RX INT8_1 MIX1 INP0", SND_SOC_NOPM, 0, 0,
  6211. &rx_int8_1_mix_inp0_mux, tavil_codec_enable_swr,
  6212. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6213. SND_SOC_DAPM_MUX_E("RX INT8_1 MIX1 INP1", SND_SOC_NOPM, 0, 0,
  6214. &rx_int8_1_mix_inp1_mux, tavil_codec_enable_swr,
  6215. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6216. SND_SOC_DAPM_MUX_E("RX INT8_1 MIX1 INP2", SND_SOC_NOPM, 0, 0,
  6217. &rx_int8_1_mix_inp2_mux, tavil_codec_enable_swr,
  6218. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6219. SND_SOC_DAPM_MIXER("RX INT0_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  6220. SND_SOC_DAPM_MIXER("RX INT0 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
  6221. SND_SOC_DAPM_MIXER("RX INT1_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  6222. SND_SOC_DAPM_MIXER("RX INT1 SEC MIX", SND_SOC_NOPM, 0, 0,
  6223. rx_int1_asrc_switch, ARRAY_SIZE(rx_int1_asrc_switch)),
  6224. SND_SOC_DAPM_MIXER("RX INT2_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  6225. SND_SOC_DAPM_MIXER("RX INT2 SEC MIX", SND_SOC_NOPM, 0, 0,
  6226. rx_int2_asrc_switch, ARRAY_SIZE(rx_int2_asrc_switch)),
  6227. SND_SOC_DAPM_MIXER("RX INT3_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  6228. SND_SOC_DAPM_MIXER("RX INT3 SEC MIX", SND_SOC_NOPM, 0, 0,
  6229. rx_int3_asrc_switch, ARRAY_SIZE(rx_int3_asrc_switch)),
  6230. SND_SOC_DAPM_MIXER("RX INT4_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  6231. SND_SOC_DAPM_MIXER("RX INT4 SEC MIX", SND_SOC_NOPM, 0, 0,
  6232. rx_int4_asrc_switch, ARRAY_SIZE(rx_int4_asrc_switch)),
  6233. SND_SOC_DAPM_MIXER("RX INT7_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  6234. SND_SOC_DAPM_MIXER("RX INT7 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
  6235. SND_SOC_DAPM_MIXER("RX INT8_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  6236. SND_SOC_DAPM_MIXER("RX INT8 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
  6237. SND_SOC_DAPM_MIXER("RX INT0 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  6238. SND_SOC_DAPM_MIXER("RX INT1 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  6239. SND_SOC_DAPM_MIXER("RX INT1 MIX3", SND_SOC_NOPM, 0, 0, hphl_mixer,
  6240. ARRAY_SIZE(hphl_mixer)),
  6241. SND_SOC_DAPM_MIXER("RX INT2 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  6242. SND_SOC_DAPM_MIXER("RX INT2 MIX3", SND_SOC_NOPM, 0, 0, hphr_mixer,
  6243. ARRAY_SIZE(hphr_mixer)),
  6244. SND_SOC_DAPM_MIXER("RX INT3 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  6245. SND_SOC_DAPM_MIXER("RX INT3 MIX3", SND_SOC_NOPM, 0, 0, lo1_mixer,
  6246. ARRAY_SIZE(lo1_mixer)),
  6247. SND_SOC_DAPM_MIXER("RX INT4 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  6248. SND_SOC_DAPM_MIXER("RX INT4 MIX3", SND_SOC_NOPM, 0, 0, lo2_mixer,
  6249. ARRAY_SIZE(lo2_mixer)),
  6250. SND_SOC_DAPM_MIXER("RX INT7 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  6251. SND_SOC_DAPM_MIXER_E("RX INT7 CHAIN", SND_SOC_NOPM, 0, 0,
  6252. NULL, 0, tavil_codec_spk_boost_event,
  6253. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6254. SND_SOC_DAPM_MIXER_E("RX INT8 CHAIN", SND_SOC_NOPM, 0, 0,
  6255. NULL, 0, tavil_codec_spk_boost_event,
  6256. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6257. SND_SOC_DAPM_MUX_E("RX INT0 MIX2 INP", SND_SOC_NOPM, INTERP_EAR,
  6258. 0, &rx_int0_mix2_inp_mux, tavil_codec_enable_rx_path_clk,
  6259. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6260. SND_SOC_DAPM_MUX_E("RX INT1 MIX2 INP", SND_SOC_NOPM, INTERP_HPHL,
  6261. 0, &rx_int1_mix2_inp_mux, tavil_codec_enable_rx_path_clk,
  6262. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6263. SND_SOC_DAPM_MUX_E("RX INT2 MIX2 INP", SND_SOC_NOPM, INTERP_HPHR,
  6264. 0, &rx_int2_mix2_inp_mux, tavil_codec_enable_rx_path_clk,
  6265. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6266. SND_SOC_DAPM_MUX_E("RX INT3 MIX2 INP", SND_SOC_NOPM, INTERP_LO1,
  6267. 0, &rx_int3_mix2_inp_mux, tavil_codec_enable_rx_path_clk,
  6268. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6269. SND_SOC_DAPM_MUX_E("RX INT4 MIX2 INP", SND_SOC_NOPM, INTERP_LO2,
  6270. 0, &rx_int4_mix2_inp_mux, tavil_codec_enable_rx_path_clk,
  6271. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6272. SND_SOC_DAPM_MUX_E("RX INT7 MIX2 INP", SND_SOC_NOPM, INTERP_SPKR1,
  6273. 0, &rx_int7_mix2_inp_mux, tavil_codec_enable_rx_path_clk,
  6274. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6275. WCD_DAPM_MUX("CDC_IF TX0 MUX", WCD934X_TX0, cdc_if_tx0),
  6276. WCD_DAPM_MUX("CDC_IF TX1 MUX", WCD934X_TX1, cdc_if_tx1),
  6277. WCD_DAPM_MUX("CDC_IF TX2 MUX", WCD934X_TX2, cdc_if_tx2),
  6278. WCD_DAPM_MUX("CDC_IF TX3 MUX", WCD934X_TX3, cdc_if_tx3),
  6279. WCD_DAPM_MUX("CDC_IF TX4 MUX", WCD934X_TX4, cdc_if_tx4),
  6280. WCD_DAPM_MUX("CDC_IF TX5 MUX", WCD934X_TX5, cdc_if_tx5),
  6281. WCD_DAPM_MUX("CDC_IF TX6 MUX", WCD934X_TX6, cdc_if_tx6),
  6282. WCD_DAPM_MUX("CDC_IF TX7 MUX", WCD934X_TX7, cdc_if_tx7),
  6283. WCD_DAPM_MUX("CDC_IF TX8 MUX", WCD934X_TX8, cdc_if_tx8),
  6284. WCD_DAPM_MUX("CDC_IF TX9 MUX", WCD934X_TX9, cdc_if_tx9),
  6285. WCD_DAPM_MUX("CDC_IF TX10 MUX", WCD934X_TX10, cdc_if_tx10),
  6286. WCD_DAPM_MUX("CDC_IF TX11 MUX", WCD934X_TX11, cdc_if_tx11),
  6287. WCD_DAPM_MUX("CDC_IF TX11 INP1 MUX", WCD934X_TX11, cdc_if_tx11_inp1),
  6288. WCD_DAPM_MUX("CDC_IF TX13 MUX", WCD934X_TX13, cdc_if_tx13),
  6289. WCD_DAPM_MUX("CDC_IF TX13 INP1 MUX", WCD934X_TX13, cdc_if_tx13_inp1),
  6290. SND_SOC_DAPM_MUX_E("ADC MUX0", WCD934X_CDC_TX0_TX_PATH_CTL, 5, 0,
  6291. &tx_adc_mux0_mux, tavil_codec_enable_dec,
  6292. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6293. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  6294. SND_SOC_DAPM_MUX_E("ADC MUX1", WCD934X_CDC_TX1_TX_PATH_CTL, 5, 0,
  6295. &tx_adc_mux1_mux, tavil_codec_enable_dec,
  6296. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6297. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  6298. SND_SOC_DAPM_MUX_E("ADC MUX2", WCD934X_CDC_TX2_TX_PATH_CTL, 5, 0,
  6299. &tx_adc_mux2_mux, tavil_codec_enable_dec,
  6300. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6301. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  6302. SND_SOC_DAPM_MUX_E("ADC MUX3", WCD934X_CDC_TX3_TX_PATH_CTL, 5, 0,
  6303. &tx_adc_mux3_mux, tavil_codec_enable_dec,
  6304. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6305. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  6306. SND_SOC_DAPM_MUX_E("ADC MUX4", WCD934X_CDC_TX4_TX_PATH_CTL, 5, 0,
  6307. &tx_adc_mux4_mux, tavil_codec_enable_dec,
  6308. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6309. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  6310. SND_SOC_DAPM_MUX_E("ADC MUX5", WCD934X_CDC_TX5_TX_PATH_CTL, 5, 0,
  6311. &tx_adc_mux5_mux, tavil_codec_enable_dec,
  6312. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6313. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  6314. SND_SOC_DAPM_MUX_E("ADC MUX6", WCD934X_CDC_TX6_TX_PATH_CTL, 5, 0,
  6315. &tx_adc_mux6_mux, tavil_codec_enable_dec,
  6316. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6317. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  6318. SND_SOC_DAPM_MUX_E("ADC MUX7", WCD934X_CDC_TX7_TX_PATH_CTL, 5, 0,
  6319. &tx_adc_mux7_mux, tavil_codec_enable_dec,
  6320. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6321. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  6322. SND_SOC_DAPM_MUX_E("ADC MUX8", WCD934X_CDC_TX8_TX_PATH_CTL, 5, 0,
  6323. &tx_adc_mux8_mux, tavil_codec_enable_dec,
  6324. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6325. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  6326. SND_SOC_DAPM_MUX_E("ADC MUX10", SND_SOC_NOPM, 10, 0, &tx_adc_mux10_mux,
  6327. tavil_codec_tx_adc_cfg, SND_SOC_DAPM_POST_PMU),
  6328. SND_SOC_DAPM_MUX_E("ADC MUX11", SND_SOC_NOPM, 11, 0, &tx_adc_mux11_mux,
  6329. tavil_codec_tx_adc_cfg, SND_SOC_DAPM_POST_PMU),
  6330. SND_SOC_DAPM_MUX_E("ADC MUX12", SND_SOC_NOPM, 12, 0, &tx_adc_mux12_mux,
  6331. tavil_codec_tx_adc_cfg, SND_SOC_DAPM_POST_PMU),
  6332. SND_SOC_DAPM_MUX_E("ADC MUX13", SND_SOC_NOPM, 13, 0, &tx_adc_mux13_mux,
  6333. tavil_codec_tx_adc_cfg, SND_SOC_DAPM_POST_PMU),
  6334. WCD_DAPM_MUX("DMIC MUX0", 0, tx_dmic_mux0),
  6335. WCD_DAPM_MUX("DMIC MUX1", 0, tx_dmic_mux1),
  6336. WCD_DAPM_MUX("DMIC MUX2", 0, tx_dmic_mux2),
  6337. WCD_DAPM_MUX("DMIC MUX3", 0, tx_dmic_mux3),
  6338. WCD_DAPM_MUX("DMIC MUX4", 0, tx_dmic_mux4),
  6339. WCD_DAPM_MUX("DMIC MUX5", 0, tx_dmic_mux5),
  6340. WCD_DAPM_MUX("DMIC MUX6", 0, tx_dmic_mux6),
  6341. WCD_DAPM_MUX("DMIC MUX7", 0, tx_dmic_mux7),
  6342. WCD_DAPM_MUX("DMIC MUX8", 0, tx_dmic_mux8),
  6343. WCD_DAPM_MUX("DMIC MUX10", 0, tx_dmic_mux10),
  6344. WCD_DAPM_MUX("DMIC MUX11", 0, tx_dmic_mux11),
  6345. WCD_DAPM_MUX("DMIC MUX12", 0, tx_dmic_mux12),
  6346. WCD_DAPM_MUX("DMIC MUX13", 0, tx_dmic_mux13),
  6347. WCD_DAPM_MUX("AMIC MUX0", 0, tx_amic_mux0),
  6348. WCD_DAPM_MUX("AMIC MUX1", 0, tx_amic_mux1),
  6349. WCD_DAPM_MUX("AMIC MUX2", 0, tx_amic_mux2),
  6350. WCD_DAPM_MUX("AMIC MUX3", 0, tx_amic_mux3),
  6351. WCD_DAPM_MUX("AMIC MUX4", 0, tx_amic_mux4),
  6352. WCD_DAPM_MUX("AMIC MUX5", 0, tx_amic_mux5),
  6353. WCD_DAPM_MUX("AMIC MUX6", 0, tx_amic_mux6),
  6354. WCD_DAPM_MUX("AMIC MUX7", 0, tx_amic_mux7),
  6355. WCD_DAPM_MUX("AMIC MUX8", 0, tx_amic_mux8),
  6356. WCD_DAPM_MUX("AMIC MUX10", 0, tx_amic_mux10),
  6357. WCD_DAPM_MUX("AMIC MUX11", 0, tx_amic_mux11),
  6358. WCD_DAPM_MUX("AMIC MUX12", 0, tx_amic_mux12),
  6359. WCD_DAPM_MUX("AMIC MUX13", 0, tx_amic_mux13),
  6360. SND_SOC_DAPM_ADC_E("ADC1", NULL, WCD934X_ANA_AMIC1, 7, 0,
  6361. tavil_codec_enable_adc, SND_SOC_DAPM_PRE_PMU),
  6362. SND_SOC_DAPM_ADC_E("ADC2", NULL, WCD934X_ANA_AMIC2, 7, 0,
  6363. tavil_codec_enable_adc, SND_SOC_DAPM_PRE_PMU),
  6364. SND_SOC_DAPM_ADC_E("ADC3", NULL, WCD934X_ANA_AMIC3, 7, 0,
  6365. tavil_codec_enable_adc, SND_SOC_DAPM_PRE_PMU),
  6366. SND_SOC_DAPM_ADC_E("ADC4", NULL, WCD934X_ANA_AMIC4, 7, 0,
  6367. tavil_codec_enable_adc, SND_SOC_DAPM_PRE_PMU),
  6368. WCD_DAPM_MUX("AMIC4_5 SEL", 0, tx_amic4_5),
  6369. WCD_DAPM_MUX("ANC0 FB MUX", 0, anc0_fb),
  6370. WCD_DAPM_MUX("ANC1 FB MUX", 0, anc1_fb),
  6371. SND_SOC_DAPM_INPUT("AMIC1"),
  6372. SND_SOC_DAPM_INPUT("AMIC2"),
  6373. SND_SOC_DAPM_INPUT("AMIC3"),
  6374. SND_SOC_DAPM_INPUT("AMIC4"),
  6375. SND_SOC_DAPM_INPUT("AMIC5"),
  6376. SND_SOC_DAPM_MICBIAS_E("MIC BIAS1", SND_SOC_NOPM, 0, 0,
  6377. tavil_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
  6378. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  6379. SND_SOC_DAPM_MICBIAS_E("MIC BIAS2", SND_SOC_NOPM, 0, 0,
  6380. tavil_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
  6381. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  6382. SND_SOC_DAPM_MICBIAS_E("MIC BIAS3", SND_SOC_NOPM, 0, 0,
  6383. tavil_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
  6384. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  6385. SND_SOC_DAPM_MICBIAS_E("MIC BIAS4", SND_SOC_NOPM, 0, 0,
  6386. tavil_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
  6387. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  6388. /*
  6389. * Not supply widget, this is used to recover HPH registers.
  6390. * It is not connected to any other widgets
  6391. */
  6392. SND_SOC_DAPM_SUPPLY("RESET_HPH_REGISTERS", SND_SOC_NOPM,
  6393. 0, 0, tavil_codec_reset_hph_registers,
  6394. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6395. SND_SOC_DAPM_MICBIAS_E(DAPM_MICBIAS1_STANDALONE, SND_SOC_NOPM, 0, 0,
  6396. tavil_codec_force_enable_micbias,
  6397. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6398. SND_SOC_DAPM_MICBIAS_E(DAPM_MICBIAS2_STANDALONE, SND_SOC_NOPM, 0, 0,
  6399. tavil_codec_force_enable_micbias,
  6400. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6401. SND_SOC_DAPM_MICBIAS_E(DAPM_MICBIAS3_STANDALONE, SND_SOC_NOPM, 0, 0,
  6402. tavil_codec_force_enable_micbias,
  6403. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6404. SND_SOC_DAPM_MICBIAS_E(DAPM_MICBIAS4_STANDALONE, SND_SOC_NOPM, 0, 0,
  6405. tavil_codec_force_enable_micbias,
  6406. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6407. SND_SOC_DAPM_AIF_OUT_E("AIF1 CAP", "AIF1 Capture", 0, SND_SOC_NOPM,
  6408. AIF1_CAP, 0, tavil_codec_enable_slimtx,
  6409. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  6410. SND_SOC_DAPM_AIF_OUT_E("AIF2 CAP", "AIF2 Capture", 0, SND_SOC_NOPM,
  6411. AIF2_CAP, 0, tavil_codec_enable_slimtx,
  6412. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  6413. SND_SOC_DAPM_AIF_OUT_E("AIF3 CAP", "AIF3 Capture", 0, SND_SOC_NOPM,
  6414. AIF3_CAP, 0, tavil_codec_enable_slimtx,
  6415. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  6416. SND_SOC_DAPM_MIXER("AIF1_CAP Mixer", SND_SOC_NOPM, AIF1_CAP, 0,
  6417. aif1_cap_mixer, ARRAY_SIZE(aif1_cap_mixer)),
  6418. SND_SOC_DAPM_MIXER("AIF2_CAP Mixer", SND_SOC_NOPM, AIF2_CAP, 0,
  6419. aif2_cap_mixer, ARRAY_SIZE(aif2_cap_mixer)),
  6420. SND_SOC_DAPM_MIXER("AIF3_CAP Mixer", SND_SOC_NOPM, AIF3_CAP, 0,
  6421. aif3_cap_mixer, ARRAY_SIZE(aif3_cap_mixer)),
  6422. SND_SOC_DAPM_MIXER("AIF4_MAD Mixer", SND_SOC_NOPM, AIF4_MAD_TX, 0,
  6423. aif4_mad_mixer, ARRAY_SIZE(aif4_mad_mixer)),
  6424. SND_SOC_DAPM_AIF_OUT_E("AIF4 VI", "VIfeed", 0, SND_SOC_NOPM,
  6425. AIF4_VIFEED, 0, tavil_codec_enable_slimvi_feedback,
  6426. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  6427. SND_SOC_DAPM_AIF_OUT("AIF4 MAD", "AIF4 MAD TX", 0,
  6428. SND_SOC_NOPM, 0, 0),
  6429. SND_SOC_DAPM_MIXER("AIF4_VI Mixer", SND_SOC_NOPM, AIF4_VIFEED, 0,
  6430. aif4_vi_mixer, ARRAY_SIZE(aif4_vi_mixer)),
  6431. SND_SOC_DAPM_INPUT("VIINPUT"),
  6432. SND_SOC_DAPM_MIXER("SLIM TX0", SND_SOC_NOPM, 0, 0, NULL, 0),
  6433. SND_SOC_DAPM_MIXER("SLIM TX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  6434. SND_SOC_DAPM_MIXER("SLIM TX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  6435. SND_SOC_DAPM_MIXER("SLIM TX3", SND_SOC_NOPM, 0, 0, NULL, 0),
  6436. SND_SOC_DAPM_MIXER("SLIM TX4", SND_SOC_NOPM, 0, 0, NULL, 0),
  6437. SND_SOC_DAPM_MIXER("SLIM TX5", SND_SOC_NOPM, 0, 0, NULL, 0),
  6438. SND_SOC_DAPM_MIXER("SLIM TX6", SND_SOC_NOPM, 0, 0, NULL, 0),
  6439. SND_SOC_DAPM_MIXER("SLIM TX7", SND_SOC_NOPM, 0, 0, NULL, 0),
  6440. SND_SOC_DAPM_MIXER("SLIM TX8", SND_SOC_NOPM, 0, 0, NULL, 0),
  6441. SND_SOC_DAPM_MIXER("SLIM TX9", SND_SOC_NOPM, 0, 0, NULL, 0),
  6442. SND_SOC_DAPM_MIXER("SLIM TX10", SND_SOC_NOPM, 0, 0, NULL, 0),
  6443. SND_SOC_DAPM_MIXER("SLIM TX11", SND_SOC_NOPM, 0, 0, NULL, 0),
  6444. SND_SOC_DAPM_MIXER("SLIM TX13", SND_SOC_NOPM, 0, 0, NULL, 0),
  6445. /* Digital Mic Inputs */
  6446. SND_SOC_DAPM_ADC_E("DMIC0", NULL, SND_SOC_NOPM, 0, 0,
  6447. tavil_codec_enable_dmic,
  6448. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6449. SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 0, 0,
  6450. tavil_codec_enable_dmic,
  6451. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6452. SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 0, 0,
  6453. tavil_codec_enable_dmic,
  6454. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6455. SND_SOC_DAPM_ADC_E("DMIC3", NULL, SND_SOC_NOPM, 0, 0,
  6456. tavil_codec_enable_dmic,
  6457. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6458. SND_SOC_DAPM_ADC_E("DMIC4", NULL, SND_SOC_NOPM, 0, 0,
  6459. tavil_codec_enable_dmic,
  6460. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6461. SND_SOC_DAPM_ADC_E("DMIC5", NULL, SND_SOC_NOPM, 0, 0,
  6462. tavil_codec_enable_dmic,
  6463. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6464. WCD_DAPM_MUX("IIR0 INP0 MUX", 0, iir0_inp0),
  6465. WCD_DAPM_MUX("IIR0 INP1 MUX", 0, iir0_inp1),
  6466. WCD_DAPM_MUX("IIR0 INP2 MUX", 0, iir0_inp2),
  6467. WCD_DAPM_MUX("IIR0 INP3 MUX", 0, iir0_inp3),
  6468. WCD_DAPM_MUX("IIR1 INP0 MUX", 0, iir1_inp0),
  6469. WCD_DAPM_MUX("IIR1 INP1 MUX", 0, iir1_inp1),
  6470. WCD_DAPM_MUX("IIR1 INP2 MUX", 0, iir1_inp2),
  6471. WCD_DAPM_MUX("IIR1 INP3 MUX", 0, iir1_inp3),
  6472. SND_SOC_DAPM_MIXER_E("IIR0", WCD934X_CDC_SIDETONE_IIR0_IIR_PATH_CTL,
  6473. 4, 0, NULL, 0, tavil_codec_set_iir_gain,
  6474. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  6475. SND_SOC_DAPM_MIXER_E("IIR1", WCD934X_CDC_SIDETONE_IIR1_IIR_PATH_CTL,
  6476. 4, 0, NULL, 0, tavil_codec_set_iir_gain,
  6477. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  6478. SND_SOC_DAPM_MIXER("SRC0", WCD934X_CDC_SIDETONE_SRC0_ST_SRC_PATH_CTL,
  6479. 4, 0, NULL, 0),
  6480. SND_SOC_DAPM_MIXER("SRC1", WCD934X_CDC_SIDETONE_SRC1_ST_SRC_PATH_CTL,
  6481. 4, 0, NULL, 0),
  6482. WCD_DAPM_MUX("RX MIX TX0 MUX", 0, rx_mix_tx0),
  6483. WCD_DAPM_MUX("RX MIX TX1 MUX", 0, rx_mix_tx1),
  6484. WCD_DAPM_MUX("RX MIX TX2 MUX", 0, rx_mix_tx2),
  6485. WCD_DAPM_MUX("RX MIX TX3 MUX", 0, rx_mix_tx3),
  6486. WCD_DAPM_MUX("RX MIX TX4 MUX", 0, rx_mix_tx4),
  6487. WCD_DAPM_MUX("RX MIX TX5 MUX", 0, rx_mix_tx5),
  6488. WCD_DAPM_MUX("RX MIX TX6 MUX", 0, rx_mix_tx6),
  6489. WCD_DAPM_MUX("RX MIX TX7 MUX", 0, rx_mix_tx7),
  6490. WCD_DAPM_MUX("RX MIX TX8 MUX", 0, rx_mix_tx8),
  6491. WCD_DAPM_MUX("RX INT0 DEM MUX", 0, rx_int0_dem_inp),
  6492. WCD_DAPM_MUX("RX INT1 DEM MUX", 0, rx_int1_dem_inp),
  6493. WCD_DAPM_MUX("RX INT2 DEM MUX", 0, rx_int2_dem_inp),
  6494. SND_SOC_DAPM_MUX_E("RX INT0_1 INTERP", SND_SOC_NOPM, INTERP_EAR, 0,
  6495. &rx_int0_1_interp_mux, tavil_codec_enable_main_path,
  6496. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6497. SND_SOC_DAPM_POST_PMD),
  6498. SND_SOC_DAPM_MUX_E("RX INT1_1 INTERP", SND_SOC_NOPM, INTERP_HPHL, 0,
  6499. &rx_int1_1_interp_mux, tavil_codec_enable_main_path,
  6500. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6501. SND_SOC_DAPM_POST_PMD),
  6502. SND_SOC_DAPM_MUX_E("RX INT2_1 INTERP", SND_SOC_NOPM, INTERP_HPHR, 0,
  6503. &rx_int2_1_interp_mux, tavil_codec_enable_main_path,
  6504. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6505. SND_SOC_DAPM_POST_PMD),
  6506. SND_SOC_DAPM_MUX_E("RX INT3_1 INTERP", SND_SOC_NOPM, INTERP_LO1, 0,
  6507. &rx_int3_1_interp_mux, tavil_codec_enable_main_path,
  6508. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6509. SND_SOC_DAPM_POST_PMD),
  6510. SND_SOC_DAPM_MUX_E("RX INT4_1 INTERP", SND_SOC_NOPM, INTERP_LO2, 0,
  6511. &rx_int4_1_interp_mux, tavil_codec_enable_main_path,
  6512. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6513. SND_SOC_DAPM_POST_PMD),
  6514. SND_SOC_DAPM_MUX_E("RX INT7_1 INTERP", SND_SOC_NOPM, INTERP_SPKR1, 0,
  6515. &rx_int7_1_interp_mux, tavil_codec_enable_main_path,
  6516. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6517. SND_SOC_DAPM_POST_PMD),
  6518. SND_SOC_DAPM_MUX_E("RX INT8_1 INTERP", SND_SOC_NOPM, INTERP_SPKR2, 0,
  6519. &rx_int8_1_interp_mux, tavil_codec_enable_main_path,
  6520. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6521. SND_SOC_DAPM_POST_PMD),
  6522. WCD_DAPM_MUX("RX INT0_2 INTERP", 0, rx_int0_2_interp),
  6523. WCD_DAPM_MUX("RX INT1_2 INTERP", 0, rx_int1_2_interp),
  6524. WCD_DAPM_MUX("RX INT2_2 INTERP", 0, rx_int2_2_interp),
  6525. WCD_DAPM_MUX("RX INT3_2 INTERP", 0, rx_int3_2_interp),
  6526. WCD_DAPM_MUX("RX INT4_2 INTERP", 0, rx_int4_2_interp),
  6527. WCD_DAPM_MUX("RX INT7_2 INTERP", 0, rx_int7_2_interp),
  6528. WCD_DAPM_MUX("RX INT8_2 INTERP", 0, rx_int8_2_interp),
  6529. SND_SOC_DAPM_SWITCH("ADC US MUX0", WCD934X_CDC_TX0_TX_PATH_192_CTL, 0,
  6530. 0, &adc_us_mux0_switch),
  6531. SND_SOC_DAPM_SWITCH("ADC US MUX1", WCD934X_CDC_TX1_TX_PATH_192_CTL, 0,
  6532. 0, &adc_us_mux1_switch),
  6533. SND_SOC_DAPM_SWITCH("ADC US MUX2", WCD934X_CDC_TX2_TX_PATH_192_CTL, 0,
  6534. 0, &adc_us_mux2_switch),
  6535. SND_SOC_DAPM_SWITCH("ADC US MUX3", WCD934X_CDC_TX3_TX_PATH_192_CTL, 0,
  6536. 0, &adc_us_mux3_switch),
  6537. SND_SOC_DAPM_SWITCH("ADC US MUX4", WCD934X_CDC_TX4_TX_PATH_192_CTL, 0,
  6538. 0, &adc_us_mux4_switch),
  6539. SND_SOC_DAPM_SWITCH("ADC US MUX5", WCD934X_CDC_TX5_TX_PATH_192_CTL, 0,
  6540. 0, &adc_us_mux5_switch),
  6541. SND_SOC_DAPM_SWITCH("ADC US MUX6", WCD934X_CDC_TX6_TX_PATH_192_CTL, 0,
  6542. 0, &adc_us_mux6_switch),
  6543. SND_SOC_DAPM_SWITCH("ADC US MUX7", WCD934X_CDC_TX7_TX_PATH_192_CTL, 0,
  6544. 0, &adc_us_mux7_switch),
  6545. SND_SOC_DAPM_SWITCH("ADC US MUX8", WCD934X_CDC_TX8_TX_PATH_192_CTL, 0,
  6546. 0, &adc_us_mux8_switch),
  6547. /* MAD related widgets */
  6548. SND_SOC_DAPM_INPUT("MAD_CPE_INPUT"),
  6549. SND_SOC_DAPM_INPUT("MADINPUT"),
  6550. WCD_DAPM_MUX("MAD_SEL MUX", 0, mad_sel),
  6551. WCD_DAPM_MUX("MAD_INP MUX", 0, mad_inp_mux),
  6552. SND_SOC_DAPM_SWITCH_E("MAD_BROADCAST", SND_SOC_NOPM, 0, 0,
  6553. &mad_brdcst_switch, tavil_codec_ape_enable_mad,
  6554. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  6555. SND_SOC_DAPM_SWITCH_E("MAD_CPE1", SND_SOC_NOPM, 0, 0,
  6556. &mad_cpe1_switch, tavil_codec_cpe_mad_ctl,
  6557. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  6558. SND_SOC_DAPM_SWITCH_E("MAD_CPE2", SND_SOC_NOPM, 0, 0,
  6559. &mad_cpe2_switch, tavil_codec_cpe_mad_ctl,
  6560. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  6561. SND_SOC_DAPM_OUTPUT("MAD_CPE_OUT1"),
  6562. SND_SOC_DAPM_OUTPUT("MAD_CPE_OUT2"),
  6563. SND_SOC_DAPM_DAC_E("RX INT0 DAC", NULL, SND_SOC_NOPM,
  6564. 0, 0, tavil_codec_ear_dac_event,
  6565. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6566. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  6567. SND_SOC_DAPM_DAC_E("RX INT1 DAC", NULL, WCD934X_ANA_HPH,
  6568. 5, 0, tavil_codec_hphl_dac_event,
  6569. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6570. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  6571. SND_SOC_DAPM_DAC_E("RX INT2 DAC", NULL, WCD934X_ANA_HPH,
  6572. 4, 0, tavil_codec_hphr_dac_event,
  6573. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6574. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  6575. SND_SOC_DAPM_DAC_E("RX INT3 DAC", NULL, SND_SOC_NOPM,
  6576. 0, 0, tavil_codec_lineout_dac_event,
  6577. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6578. SND_SOC_DAPM_DAC_E("RX INT4 DAC", NULL, SND_SOC_NOPM,
  6579. 0, 0, tavil_codec_lineout_dac_event,
  6580. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6581. SND_SOC_DAPM_PGA_E("EAR PA", WCD934X_ANA_EAR, 7, 0, NULL, 0,
  6582. tavil_codec_enable_ear_pa,
  6583. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  6584. SND_SOC_DAPM_PGA_E("HPHL PA", WCD934X_ANA_HPH, 7, 0, NULL, 0,
  6585. tavil_codec_enable_hphl_pa,
  6586. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6587. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  6588. SND_SOC_DAPM_PGA_E("HPHR PA", WCD934X_ANA_HPH, 6, 0, NULL, 0,
  6589. tavil_codec_enable_hphr_pa,
  6590. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6591. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  6592. SND_SOC_DAPM_PGA_E("LINEOUT1 PA", WCD934X_ANA_LO_1_2, 7, 0, NULL, 0,
  6593. tavil_codec_enable_lineout_pa,
  6594. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6595. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  6596. SND_SOC_DAPM_PGA_E("LINEOUT2 PA", WCD934X_ANA_LO_1_2, 6, 0, NULL, 0,
  6597. tavil_codec_enable_lineout_pa,
  6598. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6599. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  6600. SND_SOC_DAPM_PGA_E("ANC EAR PA", WCD934X_ANA_EAR, 7, 0, NULL, 0,
  6601. tavil_codec_enable_ear_pa, SND_SOC_DAPM_POST_PMU |
  6602. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  6603. SND_SOC_DAPM_PGA_E("ANC SPK1 PA", SND_SOC_NOPM, 0, 0, NULL, 0,
  6604. tavil_codec_enable_spkr_anc,
  6605. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6606. SND_SOC_DAPM_PGA_E("ANC HPHL PA", SND_SOC_NOPM, 0, 0, NULL, 0,
  6607. tavil_codec_enable_hphl_pa,
  6608. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6609. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  6610. SND_SOC_DAPM_PGA_E("ANC HPHR PA", SND_SOC_NOPM, 0, 0, NULL, 0,
  6611. tavil_codec_enable_hphr_pa,
  6612. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6613. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  6614. SND_SOC_DAPM_OUTPUT("EAR"),
  6615. SND_SOC_DAPM_OUTPUT("HPHL"),
  6616. SND_SOC_DAPM_OUTPUT("HPHR"),
  6617. SND_SOC_DAPM_OUTPUT("LINEOUT1"),
  6618. SND_SOC_DAPM_OUTPUT("LINEOUT2"),
  6619. SND_SOC_DAPM_OUTPUT("SPK1 OUT"),
  6620. SND_SOC_DAPM_OUTPUT("SPK2 OUT"),
  6621. SND_SOC_DAPM_OUTPUT("ANC EAR"),
  6622. SND_SOC_DAPM_OUTPUT("ANC HPHL"),
  6623. SND_SOC_DAPM_OUTPUT("ANC HPHR"),
  6624. SND_SOC_DAPM_SWITCH("ANC OUT EAR Enable", SND_SOC_NOPM, 0, 0,
  6625. &anc_ear_switch),
  6626. SND_SOC_DAPM_SWITCH("ANC OUT EAR SPKR Enable", SND_SOC_NOPM, 0, 0,
  6627. &anc_ear_spkr_switch),
  6628. SND_SOC_DAPM_SWITCH("ANC SPKR PA Enable", SND_SOC_NOPM, 0, 0,
  6629. &anc_spkr_pa_switch),
  6630. SND_SOC_DAPM_SWITCH_E("ANC OUT HPHL Enable", SND_SOC_NOPM, INTERP_HPHL,
  6631. 0, &anc_hphl_pa_switch, tavil_anc_out_switch_cb,
  6632. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  6633. SND_SOC_DAPM_SWITCH_E("ANC OUT HPHR Enable", SND_SOC_NOPM, INTERP_HPHR,
  6634. 0, &anc_hphr_pa_switch, tavil_anc_out_switch_cb,
  6635. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  6636. SND_SOC_DAPM_SUPPLY("RX_BIAS", SND_SOC_NOPM, 0, 0,
  6637. tavil_codec_enable_rx_bias,
  6638. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6639. SND_SOC_DAPM_SUPPLY("RX INT1 NATIVE SUPPLY", SND_SOC_NOPM,
  6640. INTERP_HPHL, 0, tavil_enable_native_supply,
  6641. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  6642. SND_SOC_DAPM_SUPPLY("RX INT2 NATIVE SUPPLY", SND_SOC_NOPM,
  6643. INTERP_HPHR, 0, tavil_enable_native_supply,
  6644. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  6645. SND_SOC_DAPM_SUPPLY("RX INT3 NATIVE SUPPLY", SND_SOC_NOPM,
  6646. INTERP_LO1, 0, tavil_enable_native_supply,
  6647. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  6648. SND_SOC_DAPM_SUPPLY("RX INT4 NATIVE SUPPLY", SND_SOC_NOPM,
  6649. INTERP_LO2, 0, tavil_enable_native_supply,
  6650. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  6651. SND_SOC_DAPM_SUPPLY("RX INT7 NATIVE SUPPLY", SND_SOC_NOPM,
  6652. INTERP_SPKR1, 0, tavil_enable_native_supply,
  6653. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  6654. SND_SOC_DAPM_SUPPLY("RX INT8 NATIVE SUPPLY", SND_SOC_NOPM,
  6655. INTERP_SPKR2, 0, tavil_enable_native_supply,
  6656. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  6657. WCD_DAPM_MUX("RX INT1_1 NATIVE MUX", 0, int1_1_native),
  6658. WCD_DAPM_MUX("RX INT2_1 NATIVE MUX", 0, int2_1_native),
  6659. WCD_DAPM_MUX("RX INT3_1 NATIVE MUX", 0, int3_1_native),
  6660. WCD_DAPM_MUX("RX INT4_1 NATIVE MUX", 0, int4_1_native),
  6661. WCD_DAPM_MUX("RX INT1_2 NATIVE MUX", 0, int1_2_native),
  6662. WCD_DAPM_MUX("RX INT2_2 NATIVE MUX", 0, int2_2_native),
  6663. WCD_DAPM_MUX("RX INT3_2 NATIVE MUX", 0, int3_2_native),
  6664. WCD_DAPM_MUX("RX INT4_2 NATIVE MUX", 0, int4_2_native),
  6665. WCD_DAPM_MUX("RX INT7_2 NATIVE MUX", 0, int7_2_native),
  6666. WCD_DAPM_MUX("RX INT8_2 NATIVE MUX", 0, int8_2_native),
  6667. SND_SOC_DAPM_MUX_E("ASRC0 MUX", SND_SOC_NOPM, ASRC0, 0,
  6668. &asrc0_mux, tavil_codec_enable_asrc_resampler,
  6669. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6670. SND_SOC_DAPM_MUX_E("ASRC1 MUX", SND_SOC_NOPM, ASRC1, 0,
  6671. &asrc1_mux, tavil_codec_enable_asrc_resampler,
  6672. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6673. SND_SOC_DAPM_MUX_E("ASRC2 MUX", SND_SOC_NOPM, ASRC2, 0,
  6674. &asrc2_mux, tavil_codec_enable_asrc_resampler,
  6675. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6676. SND_SOC_DAPM_MUX_E("ASRC3 MUX", SND_SOC_NOPM, ASRC3, 0,
  6677. &asrc3_mux, tavil_codec_enable_asrc_resampler,
  6678. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6679. /* WDMA3 widgets */
  6680. WCD_DAPM_MUX("WDMA3 PORT0 MUX", 0, wdma3_port0),
  6681. WCD_DAPM_MUX("WDMA3 PORT1 MUX", 1, wdma3_port1),
  6682. WCD_DAPM_MUX("WDMA3 PORT2 MUX", 2, wdma3_port2),
  6683. WCD_DAPM_MUX("WDMA3 PORT3 MUX", 3, wdma3_port3),
  6684. WCD_DAPM_MUX("WDMA3 PORT4 MUX", 4, wdma3_port4),
  6685. WCD_DAPM_MUX("WDMA3 PORT5 MUX", 5, wdma3_port5),
  6686. WCD_DAPM_MUX("WDMA3 PORT6 MUX", 6, wdma3_port6),
  6687. WCD_DAPM_MUX("WDMA3 CH0 MUX", 0, wdma3_ch0),
  6688. WCD_DAPM_MUX("WDMA3 CH1 MUX", 4, wdma3_ch1),
  6689. WCD_DAPM_MUX("WDMA3 CH2 MUX", 0, wdma3_ch2),
  6690. WCD_DAPM_MUX("WDMA3 CH3 MUX", 4, wdma3_ch3),
  6691. SND_SOC_DAPM_MIXER("WDMA3_CH_MIXER", SND_SOC_NOPM, 0, 0, NULL, 0),
  6692. SND_SOC_DAPM_SWITCH_E("WDMA3_ON_OFF", SND_SOC_NOPM, 0, 0,
  6693. &wdma3_onoff_switch, tavil_codec_wdma3_ctl,
  6694. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6695. SND_SOC_DAPM_OUTPUT("WDMA3_OUT"),
  6696. };
  6697. static int tavil_get_channel_map(struct snd_soc_dai *dai,
  6698. unsigned int *tx_num, unsigned int *tx_slot,
  6699. unsigned int *rx_num, unsigned int *rx_slot)
  6700. {
  6701. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(dai->codec);
  6702. u32 i = 0;
  6703. struct wcd9xxx_ch *ch;
  6704. int ret = 0;
  6705. switch (dai->id) {
  6706. case AIF1_PB:
  6707. case AIF2_PB:
  6708. case AIF3_PB:
  6709. case AIF4_PB:
  6710. if (!rx_slot || !rx_num) {
  6711. dev_err(tavil->dev, "%s: Invalid rx_slot 0x%pK or rx_num 0x%pK\n",
  6712. __func__, rx_slot, rx_num);
  6713. ret = -EINVAL;
  6714. break;
  6715. }
  6716. list_for_each_entry(ch, &tavil->dai[dai->id].wcd9xxx_ch_list,
  6717. list) {
  6718. dev_dbg(tavil->dev, "%s: slot_num %u ch->ch_num %d\n",
  6719. __func__, i, ch->ch_num);
  6720. rx_slot[i++] = ch->ch_num;
  6721. }
  6722. *rx_num = i;
  6723. dev_dbg(tavil->dev, "%s: dai_name = %s dai_id = %x rx_num = %d\n",
  6724. __func__, dai->name, dai->id, i);
  6725. if (*rx_num == 0) {
  6726. dev_err(tavil->dev, "%s: Channel list empty for dai_name = %s dai_id = %x\n",
  6727. __func__, dai->name, dai->id);
  6728. ret = -EINVAL;
  6729. }
  6730. break;
  6731. case AIF1_CAP:
  6732. case AIF2_CAP:
  6733. case AIF3_CAP:
  6734. case AIF4_MAD_TX:
  6735. case AIF4_VIFEED:
  6736. if (!tx_slot || !tx_num) {
  6737. dev_err(tavil->dev, "%s: Invalid tx_slot 0x%pK or tx_num 0x%pK\n",
  6738. __func__, tx_slot, tx_num);
  6739. ret = -EINVAL;
  6740. break;
  6741. }
  6742. list_for_each_entry(ch, &tavil->dai[dai->id].wcd9xxx_ch_list,
  6743. list) {
  6744. dev_dbg(tavil->dev, "%s: slot_num %u ch->ch_num %d\n",
  6745. __func__, i, ch->ch_num);
  6746. tx_slot[i++] = ch->ch_num;
  6747. }
  6748. *tx_num = i;
  6749. dev_dbg(tavil->dev, "%s: dai_name = %s dai_id = %x tx_num = %d\n",
  6750. __func__, dai->name, dai->id, i);
  6751. if (*tx_num == 0) {
  6752. dev_err(tavil->dev, "%s: Channel list empty for dai_name = %s dai_id = %x\n",
  6753. __func__, dai->name, dai->id);
  6754. ret = -EINVAL;
  6755. }
  6756. break;
  6757. default:
  6758. dev_err(tavil->dev, "%s: Invalid DAI ID %x\n",
  6759. __func__, dai->id);
  6760. ret = -EINVAL;
  6761. break;
  6762. }
  6763. return ret;
  6764. }
  6765. static int tavil_set_channel_map(struct snd_soc_dai *dai,
  6766. unsigned int tx_num, unsigned int *tx_slot,
  6767. unsigned int rx_num, unsigned int *rx_slot)
  6768. {
  6769. struct tavil_priv *tavil;
  6770. struct wcd9xxx *core;
  6771. struct wcd9xxx_codec_dai_data *dai_data = NULL;
  6772. tavil = snd_soc_codec_get_drvdata(dai->codec);
  6773. core = dev_get_drvdata(dai->codec->dev->parent);
  6774. if (!tx_slot || !rx_slot) {
  6775. dev_err(tavil->dev, "%s: Invalid tx_slot 0x%pK, rx_slot 0x%pK\n",
  6776. __func__, tx_slot, rx_slot);
  6777. return -EINVAL;
  6778. }
  6779. dev_dbg(tavil->dev, "%s(): dai_name = %s DAI-ID %x tx_ch %d rx_ch %d\n",
  6780. __func__, dai->name, dai->id, tx_num, rx_num);
  6781. wcd9xxx_init_slimslave(core, core->slim->laddr,
  6782. tx_num, tx_slot, rx_num, rx_slot);
  6783. /* Reserve TX13 for MAD data channel */
  6784. dai_data = &tavil->dai[AIF4_MAD_TX];
  6785. if (dai_data)
  6786. list_add_tail(&core->tx_chs[WCD934X_TX13].list,
  6787. &dai_data->wcd9xxx_ch_list);
  6788. return 0;
  6789. }
  6790. static int tavil_startup(struct snd_pcm_substream *substream,
  6791. struct snd_soc_dai *dai)
  6792. {
  6793. pr_debug("%s(): substream = %s stream = %d\n", __func__,
  6794. substream->name, substream->stream);
  6795. return 0;
  6796. }
  6797. static void tavil_shutdown(struct snd_pcm_substream *substream,
  6798. struct snd_soc_dai *dai)
  6799. {
  6800. pr_debug("%s(): substream = %s stream = %d\n", __func__,
  6801. substream->name, substream->stream);
  6802. }
  6803. static int tavil_set_decimator_rate(struct snd_soc_dai *dai,
  6804. u32 sample_rate)
  6805. {
  6806. struct snd_soc_codec *codec = dai->codec;
  6807. struct wcd9xxx_ch *ch;
  6808. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  6809. u32 tx_port = 0, tx_fs_rate = 0;
  6810. u8 shift = 0, shift_val = 0, tx_mux_sel = 0;
  6811. int decimator = -1;
  6812. u16 tx_port_reg = 0, tx_fs_reg = 0;
  6813. switch (sample_rate) {
  6814. case 8000:
  6815. tx_fs_rate = 0;
  6816. break;
  6817. case 16000:
  6818. tx_fs_rate = 1;
  6819. break;
  6820. case 32000:
  6821. tx_fs_rate = 3;
  6822. break;
  6823. case 48000:
  6824. tx_fs_rate = 4;
  6825. break;
  6826. case 96000:
  6827. tx_fs_rate = 5;
  6828. break;
  6829. case 192000:
  6830. tx_fs_rate = 6;
  6831. break;
  6832. default:
  6833. dev_err(tavil->dev, "%s: Invalid TX sample rate: %d\n",
  6834. __func__, sample_rate);
  6835. return -EINVAL;
  6836. };
  6837. list_for_each_entry(ch, &tavil->dai[dai->id].wcd9xxx_ch_list, list) {
  6838. tx_port = ch->port;
  6839. dev_dbg(codec->dev, "%s: dai->id = %d, tx_port = %d",
  6840. __func__, dai->id, tx_port);
  6841. if ((tx_port < 0) || (tx_port == 12) || (tx_port >= 14)) {
  6842. dev_err(codec->dev, "%s: Invalid SLIM TX%u port. DAI ID: %d\n",
  6843. __func__, tx_port, dai->id);
  6844. return -EINVAL;
  6845. }
  6846. /* Find the SB TX MUX input - which decimator is connected */
  6847. if (tx_port < 4) {
  6848. tx_port_reg = WCD934X_CDC_IF_ROUTER_TX_MUX_CFG0;
  6849. shift = (tx_port << 1);
  6850. shift_val = 0x03;
  6851. } else if ((tx_port >= 4) && (tx_port < 8)) {
  6852. tx_port_reg = WCD934X_CDC_IF_ROUTER_TX_MUX_CFG1;
  6853. shift = ((tx_port - 4) << 1);
  6854. shift_val = 0x03;
  6855. } else if ((tx_port >= 8) && (tx_port < 11)) {
  6856. tx_port_reg = WCD934X_CDC_IF_ROUTER_TX_MUX_CFG2;
  6857. shift = ((tx_port - 8) << 1);
  6858. shift_val = 0x03;
  6859. } else if (tx_port == 11) {
  6860. tx_port_reg = WCD934X_CDC_IF_ROUTER_TX_MUX_CFG3;
  6861. shift = 0;
  6862. shift_val = 0x0F;
  6863. } else if (tx_port == 13) {
  6864. tx_port_reg = WCD934X_CDC_IF_ROUTER_TX_MUX_CFG3;
  6865. shift = 4;
  6866. shift_val = 0x03;
  6867. }
  6868. tx_mux_sel = snd_soc_read(codec, tx_port_reg) &
  6869. (shift_val << shift);
  6870. tx_mux_sel = tx_mux_sel >> shift;
  6871. if (tx_port <= 8) {
  6872. if ((tx_mux_sel == 0x2) || (tx_mux_sel == 0x3))
  6873. decimator = tx_port;
  6874. } else if (tx_port <= 10) {
  6875. if ((tx_mux_sel == 0x1) || (tx_mux_sel == 0x2))
  6876. decimator = ((tx_port == 9) ? 7 : 6);
  6877. } else if (tx_port == 11) {
  6878. if ((tx_mux_sel >= 1) && (tx_mux_sel < 7))
  6879. decimator = tx_mux_sel - 1;
  6880. } else if (tx_port == 13) {
  6881. if ((tx_mux_sel == 0x1) || (tx_mux_sel == 0x2))
  6882. decimator = 5;
  6883. }
  6884. if (decimator >= 0) {
  6885. tx_fs_reg = WCD934X_CDC_TX0_TX_PATH_CTL +
  6886. 16 * decimator;
  6887. dev_dbg(codec->dev, "%s: set DEC%u (-> SLIM_TX%u) rate to %u\n",
  6888. __func__, decimator, tx_port, sample_rate);
  6889. snd_soc_update_bits(codec, tx_fs_reg, 0x0F, tx_fs_rate);
  6890. } else if ((tx_port <= 8) && (tx_mux_sel == 0x01)) {
  6891. /* Check if the TX Mux input is RX MIX TXn */
  6892. dev_dbg(codec->dev, "%s: RX_MIX_TX%u going to CDC_IF TX%u\n",
  6893. __func__, tx_port, tx_port);
  6894. } else {
  6895. dev_err(codec->dev, "%s: ERROR: Invalid decimator: %d\n",
  6896. __func__, decimator);
  6897. return -EINVAL;
  6898. }
  6899. }
  6900. return 0;
  6901. }
  6902. static int tavil_set_mix_interpolator_rate(struct snd_soc_dai *dai,
  6903. u8 rate_reg_val,
  6904. u32 sample_rate)
  6905. {
  6906. u8 int_2_inp;
  6907. u32 j;
  6908. u16 int_mux_cfg1, int_fs_reg;
  6909. u8 int_mux_cfg1_val;
  6910. struct snd_soc_codec *codec = dai->codec;
  6911. struct wcd9xxx_ch *ch;
  6912. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  6913. list_for_each_entry(ch, &tavil->dai[dai->id].wcd9xxx_ch_list, list) {
  6914. int_2_inp = INTn_2_INP_SEL_RX0 + ch->port -
  6915. WCD934X_RX_PORT_START_NUMBER;
  6916. if ((int_2_inp < INTn_2_INP_SEL_RX0) ||
  6917. (int_2_inp > INTn_2_INP_SEL_RX7)) {
  6918. dev_err(codec->dev, "%s: Invalid RX%u port, Dai ID is %d\n",
  6919. __func__,
  6920. (ch->port - WCD934X_RX_PORT_START_NUMBER),
  6921. dai->id);
  6922. return -EINVAL;
  6923. }
  6924. int_mux_cfg1 = WCD934X_CDC_RX_INP_MUX_RX_INT0_CFG1;
  6925. for (j = 0; j < WCD934X_NUM_INTERPOLATORS; j++) {
  6926. /* Interpolators 5 and 6 are not aviliable in Tavil */
  6927. if (j == INTERP_LO3_NA || j == INTERP_LO4_NA) {
  6928. int_mux_cfg1 += 2;
  6929. continue;
  6930. }
  6931. int_mux_cfg1_val = snd_soc_read(codec, int_mux_cfg1) &
  6932. 0x0F;
  6933. if (int_mux_cfg1_val == int_2_inp) {
  6934. /*
  6935. * Ear mix path supports only 48, 96, 192,
  6936. * 384KHz only
  6937. */
  6938. if ((j == INTERP_EAR) &&
  6939. (rate_reg_val < 0x4 ||
  6940. rate_reg_val > 0x7)) {
  6941. dev_err_ratelimited(codec->dev,
  6942. "%s: Invalid rate for AIF_PB DAI(%d)\n",
  6943. __func__, dai->id);
  6944. return -EINVAL;
  6945. }
  6946. int_fs_reg = WCD934X_CDC_RX0_RX_PATH_MIX_CTL +
  6947. 20 * j;
  6948. dev_dbg(codec->dev, "%s: AIF_PB DAI(%d) connected to INT%u_2\n",
  6949. __func__, dai->id, j);
  6950. dev_dbg(codec->dev, "%s: set INT%u_2 sample rate to %u\n",
  6951. __func__, j, sample_rate);
  6952. snd_soc_update_bits(codec, int_fs_reg, 0x0F,
  6953. rate_reg_val);
  6954. }
  6955. int_mux_cfg1 += 2;
  6956. }
  6957. }
  6958. return 0;
  6959. }
  6960. static int tavil_set_prim_interpolator_rate(struct snd_soc_dai *dai,
  6961. u8 rate_reg_val,
  6962. u32 sample_rate)
  6963. {
  6964. u8 int_1_mix1_inp;
  6965. u32 j;
  6966. u16 int_mux_cfg0, int_mux_cfg1;
  6967. u16 int_fs_reg;
  6968. u8 int_mux_cfg0_val, int_mux_cfg1_val;
  6969. u8 inp0_sel, inp1_sel, inp2_sel;
  6970. struct snd_soc_codec *codec = dai->codec;
  6971. struct wcd9xxx_ch *ch;
  6972. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  6973. struct tavil_dsd_config *dsd_conf = tavil->dsd_config;
  6974. list_for_each_entry(ch, &tavil->dai[dai->id].wcd9xxx_ch_list, list) {
  6975. int_1_mix1_inp = INTn_1_INP_SEL_RX0 + ch->port -
  6976. WCD934X_RX_PORT_START_NUMBER;
  6977. if ((int_1_mix1_inp < INTn_1_INP_SEL_RX0) ||
  6978. (int_1_mix1_inp > INTn_1_INP_SEL_RX7)) {
  6979. dev_err(codec->dev, "%s: Invalid RX%u port, Dai ID is %d\n",
  6980. __func__,
  6981. (ch->port - WCD934X_RX_PORT_START_NUMBER),
  6982. dai->id);
  6983. return -EINVAL;
  6984. }
  6985. int_mux_cfg0 = WCD934X_CDC_RX_INP_MUX_RX_INT0_CFG0;
  6986. /*
  6987. * Loop through all interpolator MUX inputs and find out
  6988. * to which interpolator input, the slim rx port
  6989. * is connected
  6990. */
  6991. for (j = 0; j < WCD934X_NUM_INTERPOLATORS; j++) {
  6992. /* Interpolators 5 and 6 are not aviliable in Tavil */
  6993. if (j == INTERP_LO3_NA || j == INTERP_LO4_NA) {
  6994. int_mux_cfg0 += 2;
  6995. continue;
  6996. }
  6997. int_mux_cfg1 = int_mux_cfg0 + 1;
  6998. int_mux_cfg0_val = snd_soc_read(codec, int_mux_cfg0);
  6999. int_mux_cfg1_val = snd_soc_read(codec, int_mux_cfg1);
  7000. inp0_sel = int_mux_cfg0_val & 0x0F;
  7001. inp1_sel = (int_mux_cfg0_val >> 4) & 0x0F;
  7002. inp2_sel = (int_mux_cfg1_val >> 4) & 0x0F;
  7003. if ((inp0_sel == int_1_mix1_inp) ||
  7004. (inp1_sel == int_1_mix1_inp) ||
  7005. (inp2_sel == int_1_mix1_inp)) {
  7006. /*
  7007. * Ear and speaker primary path does not support
  7008. * native sample rates
  7009. */
  7010. if ((j == INTERP_EAR || j == INTERP_SPKR1 ||
  7011. j == INTERP_SPKR2) &&
  7012. (rate_reg_val > 0x7)) {
  7013. dev_err_ratelimited(codec->dev,
  7014. "%s: Invalid rate for AIF_PB DAI(%d)\n",
  7015. __func__, dai->id);
  7016. return -EINVAL;
  7017. }
  7018. int_fs_reg = WCD934X_CDC_RX0_RX_PATH_CTL +
  7019. 20 * j;
  7020. dev_dbg(codec->dev,
  7021. "%s: AIF_PB DAI(%d) connected to INT%u_1\n",
  7022. __func__, dai->id, j);
  7023. dev_dbg(codec->dev,
  7024. "%s: set INT%u_1 sample rate to %u\n",
  7025. __func__, j, sample_rate);
  7026. snd_soc_update_bits(codec, int_fs_reg, 0x0F,
  7027. rate_reg_val);
  7028. }
  7029. int_mux_cfg0 += 2;
  7030. }
  7031. if (dsd_conf)
  7032. tavil_dsd_set_interp_rate(dsd_conf, ch->port,
  7033. sample_rate, rate_reg_val);
  7034. }
  7035. return 0;
  7036. }
  7037. static int tavil_set_interpolator_rate(struct snd_soc_dai *dai,
  7038. u32 sample_rate)
  7039. {
  7040. struct snd_soc_codec *codec = dai->codec;
  7041. int rate_val = 0;
  7042. int i, ret;
  7043. for (i = 0; i < ARRAY_SIZE(sr_val_tbl); i++) {
  7044. if (sample_rate == sr_val_tbl[i].sample_rate) {
  7045. rate_val = sr_val_tbl[i].rate_val;
  7046. break;
  7047. }
  7048. }
  7049. if ((i == ARRAY_SIZE(sr_val_tbl)) || (rate_val < 0)) {
  7050. dev_err(codec->dev, "%s: Unsupported sample rate: %d\n",
  7051. __func__, sample_rate);
  7052. return -EINVAL;
  7053. }
  7054. ret = tavil_set_prim_interpolator_rate(dai, (u8)rate_val, sample_rate);
  7055. if (ret)
  7056. return ret;
  7057. ret = tavil_set_mix_interpolator_rate(dai, (u8)rate_val, sample_rate);
  7058. if (ret)
  7059. return ret;
  7060. return ret;
  7061. }
  7062. static int tavil_prepare(struct snd_pcm_substream *substream,
  7063. struct snd_soc_dai *dai)
  7064. {
  7065. pr_debug("%s(): substream = %s stream = %d\n", __func__,
  7066. substream->name, substream->stream);
  7067. return 0;
  7068. }
  7069. static int tavil_vi_hw_params(struct snd_pcm_substream *substream,
  7070. struct snd_pcm_hw_params *params,
  7071. struct snd_soc_dai *dai)
  7072. {
  7073. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(dai->codec);
  7074. dev_dbg(tavil->dev, "%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n",
  7075. __func__, dai->name, dai->id, params_rate(params),
  7076. params_channels(params));
  7077. tavil->dai[dai->id].rate = params_rate(params);
  7078. tavil->dai[dai->id].bit_width = 32;
  7079. return 0;
  7080. }
  7081. static int tavil_hw_params(struct snd_pcm_substream *substream,
  7082. struct snd_pcm_hw_params *params,
  7083. struct snd_soc_dai *dai)
  7084. {
  7085. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(dai->codec);
  7086. int ret = 0;
  7087. dev_dbg(tavil->dev, "%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n",
  7088. __func__, dai->name, dai->id, params_rate(params),
  7089. params_channels(params));
  7090. switch (substream->stream) {
  7091. case SNDRV_PCM_STREAM_PLAYBACK:
  7092. ret = tavil_set_interpolator_rate(dai, params_rate(params));
  7093. if (ret) {
  7094. dev_err(tavil->dev, "%s: cannot set sample rate: %u\n",
  7095. __func__, params_rate(params));
  7096. return ret;
  7097. }
  7098. switch (params_width(params)) {
  7099. case 16:
  7100. tavil->dai[dai->id].bit_width = 16;
  7101. break;
  7102. case 24:
  7103. tavil->dai[dai->id].bit_width = 24;
  7104. break;
  7105. case 32:
  7106. tavil->dai[dai->id].bit_width = 32;
  7107. break;
  7108. default:
  7109. return -EINVAL;
  7110. }
  7111. tavil->dai[dai->id].rate = params_rate(params);
  7112. break;
  7113. case SNDRV_PCM_STREAM_CAPTURE:
  7114. if (dai->id != AIF4_MAD_TX)
  7115. ret = tavil_set_decimator_rate(dai,
  7116. params_rate(params));
  7117. if (ret) {
  7118. dev_err(tavil->dev, "%s: cannot set TX Decimator rate: %d\n",
  7119. __func__, ret);
  7120. return ret;
  7121. }
  7122. switch (params_width(params)) {
  7123. case 16:
  7124. tavil->dai[dai->id].bit_width = 16;
  7125. break;
  7126. case 24:
  7127. tavil->dai[dai->id].bit_width = 24;
  7128. break;
  7129. default:
  7130. dev_err(tavil->dev, "%s: Invalid format 0x%x\n",
  7131. __func__, params_width(params));
  7132. return -EINVAL;
  7133. };
  7134. tavil->dai[dai->id].rate = params_rate(params);
  7135. break;
  7136. default:
  7137. dev_err(tavil->dev, "%s: Invalid stream type %d\n", __func__,
  7138. substream->stream);
  7139. return -EINVAL;
  7140. };
  7141. return 0;
  7142. }
  7143. static struct snd_soc_dai_ops tavil_dai_ops = {
  7144. .startup = tavil_startup,
  7145. .shutdown = tavil_shutdown,
  7146. .hw_params = tavil_hw_params,
  7147. .prepare = tavil_prepare,
  7148. .set_channel_map = tavil_set_channel_map,
  7149. .get_channel_map = tavil_get_channel_map,
  7150. };
  7151. static struct snd_soc_dai_ops tavil_vi_dai_ops = {
  7152. .hw_params = tavil_vi_hw_params,
  7153. .set_channel_map = tavil_set_channel_map,
  7154. .get_channel_map = tavil_get_channel_map,
  7155. };
  7156. static struct snd_soc_dai_driver tavil_dai[] = {
  7157. {
  7158. .name = "tavil_rx1",
  7159. .id = AIF1_PB,
  7160. .playback = {
  7161. .stream_name = "AIF1 Playback",
  7162. .rates = WCD934X_RATES_MASK | WCD934X_FRAC_RATES_MASK,
  7163. .formats = WCD934X_FORMATS_S16_S24_S32_LE,
  7164. .rate_min = 8000,
  7165. .rate_max = 384000,
  7166. .channels_min = 1,
  7167. .channels_max = 2,
  7168. },
  7169. .ops = &tavil_dai_ops,
  7170. },
  7171. {
  7172. .name = "tavil_tx1",
  7173. .id = AIF1_CAP,
  7174. .capture = {
  7175. .stream_name = "AIF1 Capture",
  7176. .rates = WCD934X_RATES_MASK,
  7177. .formats = WCD934X_FORMATS_S16_S24_LE,
  7178. .rate_min = 8000,
  7179. .rate_max = 192000,
  7180. .channels_min = 1,
  7181. .channels_max = 4,
  7182. },
  7183. .ops = &tavil_dai_ops,
  7184. },
  7185. {
  7186. .name = "tavil_rx2",
  7187. .id = AIF2_PB,
  7188. .playback = {
  7189. .stream_name = "AIF2 Playback",
  7190. .rates = WCD934X_RATES_MASK | WCD934X_FRAC_RATES_MASK,
  7191. .formats = WCD934X_FORMATS_S16_S24_S32_LE,
  7192. .rate_min = 8000,
  7193. .rate_max = 384000,
  7194. .channels_min = 1,
  7195. .channels_max = 2,
  7196. },
  7197. .ops = &tavil_dai_ops,
  7198. },
  7199. {
  7200. .name = "tavil_tx2",
  7201. .id = AIF2_CAP,
  7202. .capture = {
  7203. .stream_name = "AIF2 Capture",
  7204. .rates = WCD934X_RATES_MASK,
  7205. .formats = WCD934X_FORMATS_S16_S24_LE,
  7206. .rate_min = 8000,
  7207. .rate_max = 192000,
  7208. .channels_min = 1,
  7209. .channels_max = 4,
  7210. },
  7211. .ops = &tavil_dai_ops,
  7212. },
  7213. {
  7214. .name = "tavil_rx3",
  7215. .id = AIF3_PB,
  7216. .playback = {
  7217. .stream_name = "AIF3 Playback",
  7218. .rates = WCD934X_RATES_MASK | WCD934X_FRAC_RATES_MASK,
  7219. .formats = WCD934X_FORMATS_S16_S24_S32_LE,
  7220. .rate_min = 8000,
  7221. .rate_max = 384000,
  7222. .channels_min = 1,
  7223. .channels_max = 2,
  7224. },
  7225. .ops = &tavil_dai_ops,
  7226. },
  7227. {
  7228. .name = "tavil_tx3",
  7229. .id = AIF3_CAP,
  7230. .capture = {
  7231. .stream_name = "AIF3 Capture",
  7232. .rates = WCD934X_RATES_MASK,
  7233. .formats = WCD934X_FORMATS_S16_S24_LE,
  7234. .rate_min = 8000,
  7235. .rate_max = 192000,
  7236. .channels_min = 1,
  7237. .channels_max = 4,
  7238. },
  7239. .ops = &tavil_dai_ops,
  7240. },
  7241. {
  7242. .name = "tavil_rx4",
  7243. .id = AIF4_PB,
  7244. .playback = {
  7245. .stream_name = "AIF4 Playback",
  7246. .rates = WCD934X_RATES_MASK | WCD934X_FRAC_RATES_MASK,
  7247. .formats = WCD934X_FORMATS_S16_S24_S32_LE,
  7248. .rate_min = 8000,
  7249. .rate_max = 384000,
  7250. .channels_min = 1,
  7251. .channels_max = 2,
  7252. },
  7253. .ops = &tavil_dai_ops,
  7254. },
  7255. {
  7256. .name = "tavil_vifeedback",
  7257. .id = AIF4_VIFEED,
  7258. .capture = {
  7259. .stream_name = "VIfeed",
  7260. .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_48000,
  7261. .formats = WCD934X_FORMATS_S16_S24_S32_LE,
  7262. .rate_min = 8000,
  7263. .rate_max = 48000,
  7264. .channels_min = 1,
  7265. .channels_max = 4,
  7266. },
  7267. .ops = &tavil_vi_dai_ops,
  7268. },
  7269. {
  7270. .name = "tavil_mad1",
  7271. .id = AIF4_MAD_TX,
  7272. .capture = {
  7273. .stream_name = "AIF4 MAD TX",
  7274. .rates = SNDRV_PCM_RATE_16000,
  7275. .formats = WCD934X_FORMATS_S16_LE,
  7276. .rate_min = 16000,
  7277. .rate_max = 16000,
  7278. .channels_min = 1,
  7279. .channels_max = 1,
  7280. },
  7281. .ops = &tavil_dai_ops,
  7282. },
  7283. };
  7284. static void tavil_codec_power_gate_digital_core(struct tavil_priv *tavil)
  7285. {
  7286. mutex_lock(&tavil->power_lock);
  7287. dev_dbg(tavil->dev, "%s: Entering power gating function, %d\n",
  7288. __func__, tavil->power_active_ref);
  7289. if (tavil->power_active_ref > 0)
  7290. goto exit;
  7291. wcd9xxx_set_power_state(tavil->wcd9xxx,
  7292. WCD_REGION_POWER_COLLAPSE_BEGIN,
  7293. WCD9XXX_DIG_CORE_REGION_1);
  7294. regmap_update_bits(tavil->wcd9xxx->regmap,
  7295. WCD934X_CODEC_RPM_PWR_CDC_DIG_HM_CTL, 0x04, 0x04);
  7296. regmap_update_bits(tavil->wcd9xxx->regmap,
  7297. WCD934X_CODEC_RPM_PWR_CDC_DIG_HM_CTL, 0x01, 0x00);
  7298. regmap_update_bits(tavil->wcd9xxx->regmap,
  7299. WCD934X_CODEC_RPM_PWR_CDC_DIG_HM_CTL, 0x02, 0x00);
  7300. wcd9xxx_set_power_state(tavil->wcd9xxx, WCD_REGION_POWER_DOWN,
  7301. WCD9XXX_DIG_CORE_REGION_1);
  7302. exit:
  7303. dev_dbg(tavil->dev, "%s: Exiting power gating function, %d\n",
  7304. __func__, tavil->power_active_ref);
  7305. mutex_unlock(&tavil->power_lock);
  7306. }
  7307. static void tavil_codec_power_gate_work(struct work_struct *work)
  7308. {
  7309. struct tavil_priv *tavil;
  7310. struct delayed_work *dwork;
  7311. dwork = to_delayed_work(work);
  7312. tavil = container_of(dwork, struct tavil_priv, power_gate_work);
  7313. tavil_codec_power_gate_digital_core(tavil);
  7314. }
  7315. /* called under power_lock acquisition */
  7316. static int tavil_dig_core_remove_power_collapse(struct tavil_priv *tavil)
  7317. {
  7318. regmap_write(tavil->wcd9xxx->regmap,
  7319. WCD934X_CODEC_RPM_PWR_CDC_DIG_HM_CTL, 0x05);
  7320. regmap_write(tavil->wcd9xxx->regmap,
  7321. WCD934X_CODEC_RPM_PWR_CDC_DIG_HM_CTL, 0x07);
  7322. regmap_update_bits(tavil->wcd9xxx->regmap,
  7323. WCD934X_CODEC_RPM_RST_CTL, 0x02, 0x00);
  7324. regmap_update_bits(tavil->wcd9xxx->regmap,
  7325. WCD934X_CODEC_RPM_RST_CTL, 0x02, 0x02);
  7326. regmap_write(tavil->wcd9xxx->regmap,
  7327. WCD934X_CODEC_RPM_PWR_CDC_DIG_HM_CTL, 0x03);
  7328. wcd9xxx_set_power_state(tavil->wcd9xxx,
  7329. WCD_REGION_POWER_COLLAPSE_REMOVE,
  7330. WCD9XXX_DIG_CORE_REGION_1);
  7331. regcache_mark_dirty(tavil->wcd9xxx->regmap);
  7332. regcache_sync_region(tavil->wcd9xxx->regmap,
  7333. WCD934X_DIG_CORE_REG_MIN,
  7334. WCD934X_DIG_CORE_REG_MAX);
  7335. return 0;
  7336. }
  7337. static int tavil_dig_core_power_collapse(struct tavil_priv *tavil,
  7338. int req_state)
  7339. {
  7340. int cur_state;
  7341. /* Exit if feature is disabled */
  7342. if (!dig_core_collapse_enable)
  7343. return 0;
  7344. mutex_lock(&tavil->power_lock);
  7345. if (req_state == POWER_COLLAPSE)
  7346. tavil->power_active_ref--;
  7347. else if (req_state == POWER_RESUME)
  7348. tavil->power_active_ref++;
  7349. else
  7350. goto unlock_mutex;
  7351. if (tavil->power_active_ref < 0) {
  7352. dev_dbg(tavil->dev, "%s: power_active_ref is negative\n",
  7353. __func__);
  7354. goto unlock_mutex;
  7355. }
  7356. if (req_state == POWER_COLLAPSE) {
  7357. if (tavil->power_active_ref == 0) {
  7358. schedule_delayed_work(&tavil->power_gate_work,
  7359. msecs_to_jiffies(dig_core_collapse_timer * 1000));
  7360. }
  7361. } else if (req_state == POWER_RESUME) {
  7362. if (tavil->power_active_ref == 1) {
  7363. /*
  7364. * At this point, there can be two cases:
  7365. * 1. Core already in power collapse state
  7366. * 2. Timer kicked in and still did not expire or
  7367. * waiting for the power_lock
  7368. */
  7369. cur_state = wcd9xxx_get_current_power_state(
  7370. tavil->wcd9xxx,
  7371. WCD9XXX_DIG_CORE_REGION_1);
  7372. if (cur_state == WCD_REGION_POWER_DOWN) {
  7373. tavil_dig_core_remove_power_collapse(tavil);
  7374. } else {
  7375. mutex_unlock(&tavil->power_lock);
  7376. cancel_delayed_work_sync(
  7377. &tavil->power_gate_work);
  7378. mutex_lock(&tavil->power_lock);
  7379. }
  7380. }
  7381. }
  7382. unlock_mutex:
  7383. mutex_unlock(&tavil->power_lock);
  7384. return 0;
  7385. }
  7386. static int tavil_cdc_req_mclk_enable(struct tavil_priv *tavil,
  7387. bool enable)
  7388. {
  7389. int ret = 0;
  7390. if (enable) {
  7391. ret = clk_prepare_enable(tavil->wcd_ext_clk);
  7392. if (ret) {
  7393. dev_err(tavil->dev, "%s: ext clk enable failed\n",
  7394. __func__);
  7395. goto done;
  7396. }
  7397. /* get BG */
  7398. wcd_resmgr_enable_master_bias(tavil->resmgr);
  7399. /* get MCLK */
  7400. wcd_resmgr_enable_clk_block(tavil->resmgr, WCD_CLK_MCLK);
  7401. } else {
  7402. /* put MCLK */
  7403. wcd_resmgr_disable_clk_block(tavil->resmgr, WCD_CLK_MCLK);
  7404. /* put BG */
  7405. wcd_resmgr_disable_master_bias(tavil->resmgr);
  7406. clk_disable_unprepare(tavil->wcd_ext_clk);
  7407. }
  7408. done:
  7409. return ret;
  7410. }
  7411. static int __tavil_cdc_mclk_enable_locked(struct tavil_priv *tavil,
  7412. bool enable)
  7413. {
  7414. int ret = 0;
  7415. if (!tavil->wcd_ext_clk) {
  7416. dev_err(tavil->dev, "%s: wcd ext clock is NULL\n", __func__);
  7417. return -EINVAL;
  7418. }
  7419. dev_dbg(tavil->dev, "%s: mclk_enable = %u\n", __func__, enable);
  7420. if (enable) {
  7421. tavil_dig_core_power_collapse(tavil, POWER_RESUME);
  7422. tavil_vote_svs(tavil, true);
  7423. ret = tavil_cdc_req_mclk_enable(tavil, true);
  7424. if (ret)
  7425. goto done;
  7426. } else {
  7427. tavil_cdc_req_mclk_enable(tavil, false);
  7428. tavil_vote_svs(tavil, false);
  7429. tavil_dig_core_power_collapse(tavil, POWER_COLLAPSE);
  7430. }
  7431. done:
  7432. return ret;
  7433. }
  7434. static int __tavil_cdc_mclk_enable(struct tavil_priv *tavil,
  7435. bool enable)
  7436. {
  7437. int ret;
  7438. WCD9XXX_V2_BG_CLK_LOCK(tavil->resmgr);
  7439. ret = __tavil_cdc_mclk_enable_locked(tavil, enable);
  7440. if (enable)
  7441. wcd_resmgr_set_sido_input_src(tavil->resmgr,
  7442. SIDO_SOURCE_RCO_BG);
  7443. WCD9XXX_V2_BG_CLK_UNLOCK(tavil->resmgr);
  7444. return ret;
  7445. }
  7446. static ssize_t tavil_codec_version_read(struct snd_info_entry *entry,
  7447. void *file_private_data,
  7448. struct file *file,
  7449. char __user *buf, size_t count,
  7450. loff_t pos)
  7451. {
  7452. struct tavil_priv *tavil;
  7453. struct wcd9xxx *wcd9xxx;
  7454. char buffer[TAVIL_VERSION_ENTRY_SIZE];
  7455. int len = 0;
  7456. tavil = (struct tavil_priv *) entry->private_data;
  7457. if (!tavil) {
  7458. pr_err("%s: tavil priv is null\n", __func__);
  7459. return -EINVAL;
  7460. }
  7461. wcd9xxx = tavil->wcd9xxx;
  7462. switch (wcd9xxx->version) {
  7463. case TAVIL_VERSION_WCD9340_1_0:
  7464. len = snprintf(buffer, sizeof(buffer), "WCD9340_1_0\n");
  7465. break;
  7466. case TAVIL_VERSION_WCD9341_1_0:
  7467. len = snprintf(buffer, sizeof(buffer), "WCD9341_1_0\n");
  7468. break;
  7469. case TAVIL_VERSION_WCD9340_1_1:
  7470. len = snprintf(buffer, sizeof(buffer), "WCD9340_1_1\n");
  7471. break;
  7472. case TAVIL_VERSION_WCD9341_1_1:
  7473. len = snprintf(buffer, sizeof(buffer), "WCD9341_1_1\n");
  7474. break;
  7475. default:
  7476. len = snprintf(buffer, sizeof(buffer), "VER_UNDEFINED\n");
  7477. }
  7478. return simple_read_from_buffer(buf, count, &pos, buffer, len);
  7479. }
  7480. static struct snd_info_entry_ops tavil_codec_info_ops = {
  7481. .read = tavil_codec_version_read,
  7482. };
  7483. /*
  7484. * tavil_codec_info_create_codec_entry - creates wcd934x module
  7485. * @codec_root: The parent directory
  7486. * @codec: Codec instance
  7487. *
  7488. * Creates wcd934x module and version entry under the given
  7489. * parent directory.
  7490. *
  7491. * Return: 0 on success or negative error code on failure.
  7492. */
  7493. int tavil_codec_info_create_codec_entry(struct snd_info_entry *codec_root,
  7494. struct snd_soc_codec *codec)
  7495. {
  7496. struct snd_info_entry *version_entry;
  7497. struct tavil_priv *tavil;
  7498. struct snd_soc_card *card;
  7499. if (!codec_root || !codec)
  7500. return -EINVAL;
  7501. tavil = snd_soc_codec_get_drvdata(codec);
  7502. card = codec->component.card;
  7503. tavil->entry = snd_info_create_subdir(codec_root->module,
  7504. "tavil", codec_root);
  7505. if (!tavil->entry) {
  7506. dev_dbg(codec->dev, "%s: failed to create wcd934x entry\n",
  7507. __func__);
  7508. return -ENOMEM;
  7509. }
  7510. version_entry = snd_info_create_card_entry(card->snd_card,
  7511. "version",
  7512. tavil->entry);
  7513. if (!version_entry) {
  7514. dev_dbg(codec->dev, "%s: failed to create wcd934x version entry\n",
  7515. __func__);
  7516. return -ENOMEM;
  7517. }
  7518. version_entry->private_data = tavil;
  7519. version_entry->size = TAVIL_VERSION_ENTRY_SIZE;
  7520. version_entry->content = SNDRV_INFO_CONTENT_DATA;
  7521. version_entry->c.ops = &tavil_codec_info_ops;
  7522. if (snd_info_register(version_entry) < 0) {
  7523. snd_info_free_entry(version_entry);
  7524. return -ENOMEM;
  7525. }
  7526. tavil->version_entry = version_entry;
  7527. return 0;
  7528. }
  7529. EXPORT_SYMBOL(tavil_codec_info_create_codec_entry);
  7530. /**
  7531. * tavil_cdc_mclk_enable - Enable/disable codec mclk
  7532. *
  7533. * @codec: codec instance
  7534. * @enable: Indicates clk enable or disable
  7535. *
  7536. * Returns 0 on Success and error on failure
  7537. */
  7538. int tavil_cdc_mclk_enable(struct snd_soc_codec *codec, bool enable)
  7539. {
  7540. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  7541. return __tavil_cdc_mclk_enable(tavil, enable);
  7542. }
  7543. EXPORT_SYMBOL(tavil_cdc_mclk_enable);
  7544. static int __tavil_codec_internal_rco_ctrl(struct snd_soc_codec *codec,
  7545. bool enable)
  7546. {
  7547. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  7548. int ret = 0;
  7549. if (enable) {
  7550. if (wcd_resmgr_get_clk_type(tavil->resmgr) ==
  7551. WCD_CLK_RCO) {
  7552. ret = wcd_resmgr_enable_clk_block(tavil->resmgr,
  7553. WCD_CLK_RCO);
  7554. } else {
  7555. ret = tavil_cdc_req_mclk_enable(tavil, true);
  7556. if (ret) {
  7557. dev_err(codec->dev,
  7558. "%s: mclk_enable failed, err = %d\n",
  7559. __func__, ret);
  7560. goto done;
  7561. }
  7562. wcd_resmgr_set_sido_input_src(tavil->resmgr,
  7563. SIDO_SOURCE_RCO_BG);
  7564. ret = wcd_resmgr_enable_clk_block(tavil->resmgr,
  7565. WCD_CLK_RCO);
  7566. ret |= tavil_cdc_req_mclk_enable(tavil, false);
  7567. }
  7568. } else {
  7569. ret = wcd_resmgr_disable_clk_block(tavil->resmgr,
  7570. WCD_CLK_RCO);
  7571. }
  7572. if (ret) {
  7573. dev_err(codec->dev, "%s: Error in %s RCO\n",
  7574. __func__, (enable ? "enabling" : "disabling"));
  7575. ret = -EINVAL;
  7576. }
  7577. done:
  7578. return ret;
  7579. }
  7580. /*
  7581. * tavil_codec_internal_rco_ctrl: Enable/Disable codec's RCO clock
  7582. * @codec: Handle to the codec
  7583. * @enable: Indicates whether clock should be enabled or disabled
  7584. */
  7585. static int tavil_codec_internal_rco_ctrl(struct snd_soc_codec *codec,
  7586. bool enable)
  7587. {
  7588. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  7589. int ret = 0;
  7590. WCD9XXX_V2_BG_CLK_LOCK(tavil->resmgr);
  7591. ret = __tavil_codec_internal_rco_ctrl(codec, enable);
  7592. WCD9XXX_V2_BG_CLK_UNLOCK(tavil->resmgr);
  7593. return ret;
  7594. }
  7595. /*
  7596. * tavil_cdc_mclk_tx_enable: Enable/Disable codec's clock for TX path
  7597. * @codec: Handle to codec
  7598. * @enable: Indicates whether clock should be enabled or disabled
  7599. */
  7600. int tavil_cdc_mclk_tx_enable(struct snd_soc_codec *codec, bool enable)
  7601. {
  7602. struct tavil_priv *tavil_p;
  7603. int ret = 0;
  7604. bool clk_mode;
  7605. bool clk_internal;
  7606. if (!codec)
  7607. return -EINVAL;
  7608. tavil_p = snd_soc_codec_get_drvdata(codec);
  7609. clk_mode = test_bit(CLK_MODE, &tavil_p->status_mask);
  7610. clk_internal = test_bit(CLK_INTERNAL, &tavil_p->status_mask);
  7611. dev_dbg(codec->dev, "%s: clkmode: %d, enable: %d, clk_internal: %d\n",
  7612. __func__, clk_mode, enable, clk_internal);
  7613. if (clk_mode || clk_internal) {
  7614. if (enable) {
  7615. wcd_resmgr_enable_master_bias(tavil_p->resmgr);
  7616. tavil_dig_core_power_collapse(tavil_p, POWER_RESUME);
  7617. tavil_vote_svs(tavil_p, true);
  7618. ret = tavil_codec_internal_rco_ctrl(codec, enable);
  7619. set_bit(CLK_INTERNAL, &tavil_p->status_mask);
  7620. } else {
  7621. clear_bit(CLK_INTERNAL, &tavil_p->status_mask);
  7622. tavil_codec_internal_rco_ctrl(codec, enable);
  7623. tavil_vote_svs(tavil_p, false);
  7624. tavil_dig_core_power_collapse(tavil_p, POWER_COLLAPSE);
  7625. wcd_resmgr_disable_master_bias(tavil_p->resmgr);
  7626. }
  7627. } else {
  7628. ret = __tavil_cdc_mclk_enable(tavil_p, enable);
  7629. }
  7630. return ret;
  7631. }
  7632. EXPORT_SYMBOL(tavil_cdc_mclk_tx_enable);
  7633. static const struct wcd_resmgr_cb tavil_resmgr_cb = {
  7634. .cdc_rco_ctrl = __tavil_codec_internal_rco_ctrl,
  7635. };
  7636. static const struct tavil_reg_mask_val tavil_codec_mclk2_1_1_defaults[] = {
  7637. {WCD934X_CLK_SYS_MCLK2_PRG1, 0x60, 0x20},
  7638. };
  7639. static const struct tavil_reg_mask_val tavil_codec_mclk2_1_0_defaults[] = {
  7640. /*
  7641. * PLL Settings:
  7642. * Clock Root: MCLK2,
  7643. * Clock Source: EXT_CLK,
  7644. * Clock Destination: MCLK2
  7645. * Clock Freq In: 19.2MHz,
  7646. * Clock Freq Out: 11.2896MHz
  7647. */
  7648. {WCD934X_CLK_SYS_MCLK2_PRG1, 0x60, 0x20},
  7649. {WCD934X_CLK_SYS_INT_POST_DIV_REG0, 0xFF, 0x5E},
  7650. {WCD934X_CLK_SYS_INT_POST_DIV_REG1, 0x1F, 0x1F},
  7651. {WCD934X_CLK_SYS_INT_REF_DIV_REG0, 0xFF, 0x54},
  7652. {WCD934X_CLK_SYS_INT_REF_DIV_REG1, 0xFF, 0x01},
  7653. {WCD934X_CLK_SYS_INT_FILTER_REG1, 0x07, 0x04},
  7654. {WCD934X_CLK_SYS_INT_PLL_L_VAL, 0xFF, 0x93},
  7655. {WCD934X_CLK_SYS_INT_PLL_N_VAL, 0xFF, 0xFA},
  7656. {WCD934X_CLK_SYS_INT_TEST_REG0, 0xFF, 0x90},
  7657. {WCD934X_CLK_SYS_INT_PFD_CP_DSM_PROG, 0xFF, 0x7E},
  7658. {WCD934X_CLK_SYS_INT_VCO_PROG, 0xFF, 0xF8},
  7659. {WCD934X_CLK_SYS_INT_TEST_REG1, 0xFF, 0x68},
  7660. {WCD934X_CLK_SYS_INT_LDO_LOCK_CFG, 0xFF, 0x40},
  7661. {WCD934X_CLK_SYS_INT_DIG_LOCK_DET_CFG, 0xFF, 0x32},
  7662. };
  7663. static const struct tavil_reg_mask_val tavil_codec_reg_defaults[] = {
  7664. {WCD934X_BIAS_VBG_FINE_ADJ, 0xFF, 0x75},
  7665. {WCD934X_CODEC_CPR_SVS_CX_VDD, 0xFF, 0x7C}, /* value in svs mode */
  7666. {WCD934X_CODEC_CPR_SVS2_CX_VDD, 0xFF, 0x58}, /* value in svs2 mode */
  7667. {WCD934X_CDC_RX0_RX_PATH_DSMDEM_CTL, 0x01, 0x01},
  7668. {WCD934X_CDC_RX1_RX_PATH_DSMDEM_CTL, 0x01, 0x01},
  7669. {WCD934X_CDC_RX2_RX_PATH_DSMDEM_CTL, 0x01, 0x01},
  7670. {WCD934X_CDC_RX3_RX_PATH_DSMDEM_CTL, 0x01, 0x01},
  7671. {WCD934X_CDC_RX4_RX_PATH_DSMDEM_CTL, 0x01, 0x01},
  7672. {WCD934X_CDC_RX7_RX_PATH_DSMDEM_CTL, 0x01, 0x01},
  7673. {WCD934X_CDC_RX8_RX_PATH_DSMDEM_CTL, 0x01, 0x01},
  7674. {WCD934X_CDC_COMPANDER8_CTL7, 0x1E, 0x18},
  7675. {WCD934X_CDC_COMPANDER7_CTL7, 0x1E, 0x18},
  7676. {WCD934X_CDC_RX0_RX_PATH_SEC0, 0x08, 0x0},
  7677. {WCD934X_CDC_CLSH_DECAY_CTRL, 0x03, 0x0},
  7678. {WCD934X_MICB1_TEST_CTL_2, 0x07, 0x01},
  7679. {WCD934X_CDC_BOOST0_BOOST_CFG1, 0x3F, 0x12},
  7680. {WCD934X_CDC_BOOST0_BOOST_CFG2, 0x1C, 0x08},
  7681. {WCD934X_CDC_BOOST1_BOOST_CFG1, 0x3F, 0x12},
  7682. {WCD934X_CDC_BOOST1_BOOST_CFG2, 0x1C, 0x08},
  7683. {WCD934X_CPE_SS_CPARMAD_BUFRDY_INT_PERIOD, 0x1F, 0x09},
  7684. {WCD934X_CDC_TX0_TX_PATH_CFG1, 0x01, 0x00},
  7685. {WCD934X_CDC_TX1_TX_PATH_CFG1, 0x01, 0x00},
  7686. {WCD934X_CDC_TX2_TX_PATH_CFG1, 0x01, 0x00},
  7687. {WCD934X_CDC_TX3_TX_PATH_CFG1, 0x01, 0x00},
  7688. {WCD934X_CDC_TX4_TX_PATH_CFG1, 0x01, 0x00},
  7689. {WCD934X_CDC_TX5_TX_PATH_CFG1, 0x01, 0x00},
  7690. {WCD934X_CDC_TX6_TX_PATH_CFG1, 0x01, 0x00},
  7691. {WCD934X_CDC_TX7_TX_PATH_CFG1, 0x01, 0x00},
  7692. {WCD934X_CDC_TX8_TX_PATH_CFG1, 0x01, 0x00},
  7693. {WCD934X_RX_OCP_CTL, 0x0F, 0x02}, /* OCP number of attempts is 2 */
  7694. {WCD934X_HPH_OCP_CTL, 0xFF, 0x3A}, /* OCP current limit */
  7695. {WCD934X_HPH_L_TEST, 0x01, 0x01},
  7696. {WCD934X_HPH_R_TEST, 0x01, 0x01},
  7697. {WCD934X_CPE_FLL_CONFIG_CTL_2, 0xFF, 0x20},
  7698. {WCD934X_MBHC_NEW_CTL_2, 0x0C, 0x00},
  7699. };
  7700. static const struct tavil_reg_mask_val tavil_codec_reg_init_1_1_val[] = {
  7701. {WCD934X_CDC_COMPANDER1_CTL7, 0x1E, 0x06},
  7702. {WCD934X_CDC_COMPANDER2_CTL7, 0x1E, 0x06},
  7703. {WCD934X_HPH_NEW_INT_RDAC_HD2_CTL_L, 0xFF, 0x84},
  7704. {WCD934X_HPH_NEW_INT_RDAC_HD2_CTL_R, 0xFF, 0x84},
  7705. {WCD934X_CDC_RX3_RX_PATH_SEC0, 0xFC, 0xF4},
  7706. {WCD934X_CDC_RX4_RX_PATH_SEC0, 0xFC, 0xF4},
  7707. };
  7708. static const struct tavil_cpr_reg_defaults cpr_defaults[] = {
  7709. { 0x00000820, 0x00000094 },
  7710. { 0x00000fC0, 0x00000048 },
  7711. { 0x0000f000, 0x00000044 },
  7712. { 0x0000bb80, 0xC0000178 },
  7713. { 0x00000000, 0x00000160 },
  7714. { 0x10854522, 0x00000060 },
  7715. { 0x10854509, 0x00000064 },
  7716. { 0x108544dd, 0x00000068 },
  7717. { 0x108544ad, 0x0000006C },
  7718. { 0x0000077E, 0x00000070 },
  7719. { 0x000007da, 0x00000074 },
  7720. { 0x00000000, 0x00000078 },
  7721. { 0x00000000, 0x0000007C },
  7722. { 0x00042029, 0x00000080 },
  7723. { 0x4002002A, 0x00000090 },
  7724. { 0x4002002B, 0x00000090 },
  7725. };
  7726. static const struct tavil_reg_mask_val tavil_codec_reg_init_common_val[] = {
  7727. {WCD934X_CDC_CLSH_K2_MSB, 0x0F, 0x00},
  7728. {WCD934X_CDC_CLSH_K2_LSB, 0xFF, 0x60},
  7729. {WCD934X_CPE_SS_DMIC_CFG, 0x80, 0x00},
  7730. {WCD934X_CDC_BOOST0_BOOST_CTL, 0x70, 0x50},
  7731. {WCD934X_CDC_BOOST1_BOOST_CTL, 0x70, 0x50},
  7732. {WCD934X_CDC_RX7_RX_PATH_CFG1, 0x08, 0x08},
  7733. {WCD934X_CDC_RX8_RX_PATH_CFG1, 0x08, 0x08},
  7734. {WCD934X_CDC_TOP_TOP_CFG1, 0x02, 0x02},
  7735. {WCD934X_CDC_TOP_TOP_CFG1, 0x01, 0x01},
  7736. {WCD934X_CDC_TX9_SPKR_PROT_PATH_CFG0, 0x01, 0x01},
  7737. {WCD934X_CDC_TX10_SPKR_PROT_PATH_CFG0, 0x01, 0x01},
  7738. {WCD934X_CDC_TX11_SPKR_PROT_PATH_CFG0, 0x01, 0x01},
  7739. {WCD934X_CDC_TX12_SPKR_PROT_PATH_CFG0, 0x01, 0x01},
  7740. {WCD934X_DATA_HUB_SB_TX11_INP_CFG, 0x01, 0x01},
  7741. {WCD934X_CDC_CLK_RST_CTRL_FS_CNT_CONTROL, 0x01, 0x01},
  7742. {WCD934X_CDC_COMPANDER7_CTL3, 0x80, 0x80},
  7743. {WCD934X_CDC_COMPANDER8_CTL3, 0x80, 0x80},
  7744. {WCD934X_CDC_COMPANDER7_CTL7, 0x01, 0x01},
  7745. {WCD934X_CDC_COMPANDER8_CTL7, 0x01, 0x01},
  7746. {WCD934X_CODEC_RPM_CLK_GATE, 0x08, 0x00},
  7747. {WCD934X_TLMM_DMIC3_CLK_PINCFG, 0xFF, 0x0a},
  7748. {WCD934X_TLMM_DMIC3_DATA_PINCFG, 0xFF, 0x0a},
  7749. {WCD934X_CPE_SS_SVA_CFG, 0x60, 0x00},
  7750. {WCD934X_CPE_SS_CPAR_CFG, 0x10, 0x10},
  7751. {WCD934X_MICB1_TEST_CTL_1, 0xff, 0xfa},
  7752. {WCD934X_MICB2_TEST_CTL_1, 0xff, 0xfa},
  7753. {WCD934X_MICB3_TEST_CTL_1, 0xff, 0xfa},
  7754. {WCD934X_MICB4_TEST_CTL_1, 0xff, 0xfa},
  7755. };
  7756. static void tavil_codec_init_reg(struct tavil_priv *priv)
  7757. {
  7758. struct snd_soc_codec *codec = priv->codec;
  7759. u32 i;
  7760. for (i = 0; i < ARRAY_SIZE(tavil_codec_reg_init_common_val); i++)
  7761. snd_soc_update_bits(codec,
  7762. tavil_codec_reg_init_common_val[i].reg,
  7763. tavil_codec_reg_init_common_val[i].mask,
  7764. tavil_codec_reg_init_common_val[i].val);
  7765. if (TAVIL_IS_1_1(priv->wcd9xxx)) {
  7766. for (i = 0; i < ARRAY_SIZE(tavil_codec_reg_init_1_1_val); i++)
  7767. snd_soc_update_bits(codec,
  7768. tavil_codec_reg_init_1_1_val[i].reg,
  7769. tavil_codec_reg_init_1_1_val[i].mask,
  7770. tavil_codec_reg_init_1_1_val[i].val);
  7771. }
  7772. }
  7773. static void tavil_update_reg_defaults(struct tavil_priv *tavil)
  7774. {
  7775. u32 i;
  7776. struct wcd9xxx *wcd9xxx;
  7777. wcd9xxx = tavil->wcd9xxx;
  7778. for (i = 0; i < ARRAY_SIZE(tavil_codec_reg_defaults); i++)
  7779. regmap_update_bits(wcd9xxx->regmap,
  7780. tavil_codec_reg_defaults[i].reg,
  7781. tavil_codec_reg_defaults[i].mask,
  7782. tavil_codec_reg_defaults[i].val);
  7783. }
  7784. static void tavil_update_cpr_defaults(struct tavil_priv *tavil)
  7785. {
  7786. int i;
  7787. struct wcd9xxx *wcd9xxx;
  7788. wcd9xxx = tavil->wcd9xxx;
  7789. if (!TAVIL_IS_1_1(wcd9xxx))
  7790. return;
  7791. __tavil_cdc_mclk_enable(tavil, true);
  7792. regmap_write(wcd9xxx->regmap, WCD934X_CODEC_CPR_SVS2_MIN_CX_VDD, 0x2C);
  7793. regmap_update_bits(wcd9xxx->regmap, WCD934X_CODEC_RPM_CLK_GATE,
  7794. 0x10, 0x00);
  7795. for (i = 0; i < ARRAY_SIZE(cpr_defaults); i++) {
  7796. regmap_bulk_write(wcd9xxx->regmap,
  7797. WCD934X_CODEC_CPR_WR_DATA_0,
  7798. (u8 *)&cpr_defaults[i].wr_data, 4);
  7799. regmap_bulk_write(wcd9xxx->regmap,
  7800. WCD934X_CODEC_CPR_WR_ADDR_0,
  7801. (u8 *)&cpr_defaults[i].wr_addr, 4);
  7802. }
  7803. __tavil_cdc_mclk_enable(tavil, false);
  7804. }
  7805. static void tavil_slim_interface_init_reg(struct snd_soc_codec *codec)
  7806. {
  7807. int i;
  7808. struct tavil_priv *priv = snd_soc_codec_get_drvdata(codec);
  7809. for (i = 0; i < WCD9XXX_SLIM_NUM_PORT_REG; i++)
  7810. wcd9xxx_interface_reg_write(priv->wcd9xxx,
  7811. WCD934X_SLIM_PGD_PORT_INT_RX_EN0 + i,
  7812. 0xFF);
  7813. }
  7814. static irqreturn_t tavil_misc_irq(int irq, void *data)
  7815. {
  7816. struct tavil_priv *tavil = data;
  7817. int misc_val;
  7818. /* Find source of interrupt */
  7819. regmap_read(tavil->wcd9xxx->regmap, WCD934X_INTR_CODEC_MISC_STATUS,
  7820. &misc_val);
  7821. if (misc_val & 0x08) {
  7822. dev_info(tavil->dev, "%s: irq: %d, DSD DC detected!\n",
  7823. __func__, irq);
  7824. /* DSD DC interrupt, reset DSD path */
  7825. tavil_dsd_reset(tavil->dsd_config);
  7826. } else {
  7827. dev_err(tavil->dev, "%s: Codec misc irq: %d, val: 0x%x\n",
  7828. __func__, irq, misc_val);
  7829. }
  7830. /* Clear interrupt status */
  7831. regmap_update_bits(tavil->wcd9xxx->regmap,
  7832. WCD934X_INTR_CODEC_MISC_CLEAR, misc_val, 0x00);
  7833. return IRQ_HANDLED;
  7834. }
  7835. static irqreturn_t tavil_slimbus_irq(int irq, void *data)
  7836. {
  7837. struct tavil_priv *tavil = data;
  7838. unsigned long status = 0;
  7839. int i, j, port_id, k;
  7840. u32 bit;
  7841. u8 val, int_val = 0;
  7842. bool tx, cleared;
  7843. unsigned short reg = 0;
  7844. for (i = WCD934X_SLIM_PGD_PORT_INT_STATUS_RX_0, j = 0;
  7845. i <= WCD934X_SLIM_PGD_PORT_INT_STATUS_TX_1; i++, j++) {
  7846. val = wcd9xxx_interface_reg_read(tavil->wcd9xxx, i);
  7847. status |= ((u32)val << (8 * j));
  7848. }
  7849. for_each_set_bit(j, &status, 32) {
  7850. tx = (j >= 16 ? true : false);
  7851. port_id = (tx ? j - 16 : j);
  7852. val = wcd9xxx_interface_reg_read(tavil->wcd9xxx,
  7853. WCD934X_SLIM_PGD_PORT_INT_RX_SOURCE0 + j);
  7854. if (val) {
  7855. if (!tx)
  7856. reg = WCD934X_SLIM_PGD_PORT_INT_RX_EN0 +
  7857. (port_id / 8);
  7858. else
  7859. reg = WCD934X_SLIM_PGD_PORT_INT_TX_EN0 +
  7860. (port_id / 8);
  7861. int_val = wcd9xxx_interface_reg_read(
  7862. tavil->wcd9xxx, reg);
  7863. /*
  7864. * Ignore interrupts for ports for which the
  7865. * interrupts are not specifically enabled.
  7866. */
  7867. if (!(int_val & (1 << (port_id % 8))))
  7868. continue;
  7869. }
  7870. if (val & WCD934X_SLIM_IRQ_OVERFLOW)
  7871. dev_err_ratelimited(tavil->dev, "%s: overflow error on %s port %d, value %x\n",
  7872. __func__, (tx ? "TX" : "RX"), port_id, val);
  7873. if (val & WCD934X_SLIM_IRQ_UNDERFLOW)
  7874. dev_err_ratelimited(tavil->dev, "%s: underflow error on %s port %d, value %x\n",
  7875. __func__, (tx ? "TX" : "RX"), port_id, val);
  7876. if ((val & WCD934X_SLIM_IRQ_OVERFLOW) ||
  7877. (val & WCD934X_SLIM_IRQ_UNDERFLOW)) {
  7878. if (!tx)
  7879. reg = WCD934X_SLIM_PGD_PORT_INT_RX_EN0 +
  7880. (port_id / 8);
  7881. else
  7882. reg = WCD934X_SLIM_PGD_PORT_INT_TX_EN0 +
  7883. (port_id / 8);
  7884. int_val = wcd9xxx_interface_reg_read(
  7885. tavil->wcd9xxx, reg);
  7886. if (int_val & (1 << (port_id % 8))) {
  7887. int_val = int_val ^ (1 << (port_id % 8));
  7888. wcd9xxx_interface_reg_write(tavil->wcd9xxx,
  7889. reg, int_val);
  7890. }
  7891. }
  7892. if (val & WCD934X_SLIM_IRQ_PORT_CLOSED) {
  7893. /*
  7894. * INT SOURCE register starts from RX to TX
  7895. * but port number in the ch_mask is in opposite way
  7896. */
  7897. bit = (tx ? j - 16 : j + 16);
  7898. dev_dbg(tavil->dev, "%s: %s port %d closed value %x, bit %u\n",
  7899. __func__, (tx ? "TX" : "RX"), port_id, val,
  7900. bit);
  7901. for (k = 0, cleared = false; k < NUM_CODEC_DAIS; k++) {
  7902. dev_dbg(tavil->dev, "%s: tavil->dai[%d].ch_mask = 0x%lx\n",
  7903. __func__, k, tavil->dai[k].ch_mask);
  7904. if (test_and_clear_bit(bit,
  7905. &tavil->dai[k].ch_mask)) {
  7906. cleared = true;
  7907. if (!tavil->dai[k].ch_mask)
  7908. wake_up(
  7909. &tavil->dai[k].dai_wait);
  7910. /*
  7911. * There are cases when multiple DAIs
  7912. * might be using the same slimbus
  7913. * channel. Hence don't break here.
  7914. */
  7915. }
  7916. }
  7917. WARN(!cleared,
  7918. "Couldn't find slimbus %s port %d for closing\n",
  7919. (tx ? "TX" : "RX"), port_id);
  7920. }
  7921. wcd9xxx_interface_reg_write(tavil->wcd9xxx,
  7922. WCD934X_SLIM_PGD_PORT_INT_CLR_RX_0 +
  7923. (j / 8),
  7924. 1 << (j % 8));
  7925. }
  7926. return IRQ_HANDLED;
  7927. }
  7928. static int tavil_setup_irqs(struct tavil_priv *tavil)
  7929. {
  7930. int ret = 0;
  7931. struct snd_soc_codec *codec = tavil->codec;
  7932. struct wcd9xxx *wcd9xxx = tavil->wcd9xxx;
  7933. struct wcd9xxx_core_resource *core_res =
  7934. &wcd9xxx->core_res;
  7935. ret = wcd9xxx_request_irq(core_res, WCD9XXX_IRQ_SLIMBUS,
  7936. tavil_slimbus_irq, "SLIMBUS Slave", tavil);
  7937. if (ret)
  7938. dev_err(codec->dev, "%s: Failed to request irq %d\n", __func__,
  7939. WCD9XXX_IRQ_SLIMBUS);
  7940. else
  7941. tavil_slim_interface_init_reg(codec);
  7942. /* Register for misc interrupts as well */
  7943. ret = wcd9xxx_request_irq(core_res, WCD934X_IRQ_MISC,
  7944. tavil_misc_irq, "CDC MISC Irq", tavil);
  7945. if (ret)
  7946. dev_err(codec->dev, "%s: Failed to request cdc misc irq\n",
  7947. __func__);
  7948. return ret;
  7949. }
  7950. static void tavil_init_slim_slave_cfg(struct snd_soc_codec *codec)
  7951. {
  7952. struct tavil_priv *priv = snd_soc_codec_get_drvdata(codec);
  7953. struct afe_param_cdc_slimbus_slave_cfg *cfg;
  7954. struct wcd9xxx *wcd9xxx = priv->wcd9xxx;
  7955. uint64_t eaddr = 0;
  7956. cfg = &priv->slimbus_slave_cfg;
  7957. cfg->minor_version = 1;
  7958. cfg->tx_slave_port_offset = 0;
  7959. cfg->rx_slave_port_offset = 16;
  7960. memcpy(&eaddr, &wcd9xxx->slim->e_addr, sizeof(wcd9xxx->slim->e_addr));
  7961. WARN_ON(sizeof(wcd9xxx->slim->e_addr) != 6);
  7962. cfg->device_enum_addr_lsw = eaddr & 0xFFFFFFFF;
  7963. cfg->device_enum_addr_msw = eaddr >> 32;
  7964. dev_dbg(codec->dev, "%s: slimbus logical address 0x%llx\n",
  7965. __func__, eaddr);
  7966. }
  7967. static void tavil_cleanup_irqs(struct tavil_priv *tavil)
  7968. {
  7969. struct wcd9xxx *wcd9xxx = tavil->wcd9xxx;
  7970. struct wcd9xxx_core_resource *core_res =
  7971. &wcd9xxx->core_res;
  7972. wcd9xxx_free_irq(core_res, WCD9XXX_IRQ_SLIMBUS, tavil);
  7973. wcd9xxx_free_irq(core_res, WCD934X_IRQ_MISC, tavil);
  7974. }
  7975. /*
  7976. * wcd934x_get_micb_vout_ctl_val: converts micbias from volts to register value
  7977. * @micb_mv: micbias in mv
  7978. *
  7979. * return register value converted
  7980. */
  7981. int wcd934x_get_micb_vout_ctl_val(u32 micb_mv)
  7982. {
  7983. /* min micbias voltage is 1V and maximum is 2.85V */
  7984. if (micb_mv < 1000 || micb_mv > 2850) {
  7985. pr_err("%s: unsupported micbias voltage\n", __func__);
  7986. return -EINVAL;
  7987. }
  7988. return (micb_mv - 1000) / 50;
  7989. }
  7990. EXPORT_SYMBOL(wcd934x_get_micb_vout_ctl_val);
  7991. static int tavil_handle_pdata(struct tavil_priv *tavil,
  7992. struct wcd9xxx_pdata *pdata)
  7993. {
  7994. struct snd_soc_codec *codec = tavil->codec;
  7995. u8 mad_dmic_ctl_val;
  7996. u8 anc_ctl_value;
  7997. u32 def_dmic_rate, dmic_clk_drv;
  7998. int vout_ctl_1, vout_ctl_2, vout_ctl_3, vout_ctl_4;
  7999. int rc = 0;
  8000. if (!pdata) {
  8001. dev_err(codec->dev, "%s: NULL pdata\n", __func__);
  8002. return -ENODEV;
  8003. }
  8004. /* set micbias voltage */
  8005. vout_ctl_1 = wcd934x_get_micb_vout_ctl_val(pdata->micbias.micb1_mv);
  8006. vout_ctl_2 = wcd934x_get_micb_vout_ctl_val(pdata->micbias.micb2_mv);
  8007. vout_ctl_3 = wcd934x_get_micb_vout_ctl_val(pdata->micbias.micb3_mv);
  8008. vout_ctl_4 = wcd934x_get_micb_vout_ctl_val(pdata->micbias.micb4_mv);
  8009. if (vout_ctl_1 < 0 || vout_ctl_2 < 0 ||
  8010. vout_ctl_3 < 0 || vout_ctl_4 < 0) {
  8011. rc = -EINVAL;
  8012. goto done;
  8013. }
  8014. snd_soc_update_bits(codec, WCD934X_ANA_MICB1, 0x3F, vout_ctl_1);
  8015. snd_soc_update_bits(codec, WCD934X_ANA_MICB2, 0x3F, vout_ctl_2);
  8016. snd_soc_update_bits(codec, WCD934X_ANA_MICB3, 0x3F, vout_ctl_3);
  8017. snd_soc_update_bits(codec, WCD934X_ANA_MICB4, 0x3F, vout_ctl_4);
  8018. /* Set the DMIC sample rate */
  8019. switch (pdata->mclk_rate) {
  8020. case WCD934X_MCLK_CLK_9P6MHZ:
  8021. def_dmic_rate = WCD9XXX_DMIC_SAMPLE_RATE_4P8MHZ;
  8022. break;
  8023. case WCD934X_MCLK_CLK_12P288MHZ:
  8024. def_dmic_rate = WCD9XXX_DMIC_SAMPLE_RATE_4P096MHZ;
  8025. break;
  8026. default:
  8027. /* should never happen */
  8028. dev_err(codec->dev, "%s: Invalid mclk_rate %d\n",
  8029. __func__, pdata->mclk_rate);
  8030. rc = -EINVAL;
  8031. goto done;
  8032. };
  8033. if (pdata->dmic_sample_rate ==
  8034. WCD9XXX_DMIC_SAMPLE_RATE_UNDEFINED) {
  8035. dev_info(codec->dev, "%s: dmic_rate invalid default = %d\n",
  8036. __func__, def_dmic_rate);
  8037. pdata->dmic_sample_rate = def_dmic_rate;
  8038. }
  8039. if (pdata->mad_dmic_sample_rate ==
  8040. WCD9XXX_DMIC_SAMPLE_RATE_UNDEFINED) {
  8041. dev_info(codec->dev, "%s: mad_dmic_rate invalid default = %d\n",
  8042. __func__, def_dmic_rate);
  8043. /*
  8044. * use dmic_sample_rate as the default for MAD
  8045. * if mad dmic sample rate is undefined
  8046. */
  8047. pdata->mad_dmic_sample_rate = pdata->dmic_sample_rate;
  8048. }
  8049. if (pdata->dmic_clk_drv ==
  8050. WCD9XXX_DMIC_CLK_DRIVE_UNDEFINED) {
  8051. pdata->dmic_clk_drv = WCD934X_DMIC_CLK_DRIVE_DEFAULT;
  8052. dev_dbg(codec->dev,
  8053. "%s: dmic_clk_strength invalid, default = %d\n",
  8054. __func__, pdata->dmic_clk_drv);
  8055. }
  8056. switch (pdata->dmic_clk_drv) {
  8057. case 2:
  8058. dmic_clk_drv = 0;
  8059. break;
  8060. case 4:
  8061. dmic_clk_drv = 1;
  8062. break;
  8063. case 8:
  8064. dmic_clk_drv = 2;
  8065. break;
  8066. case 16:
  8067. dmic_clk_drv = 3;
  8068. break;
  8069. default:
  8070. dev_err(codec->dev,
  8071. "%s: invalid dmic_clk_drv %d, using default\n",
  8072. __func__, pdata->dmic_clk_drv);
  8073. dmic_clk_drv = 0;
  8074. break;
  8075. }
  8076. snd_soc_update_bits(codec, WCD934X_TEST_DEBUG_PAD_DRVCTL_0,
  8077. 0x0C, dmic_clk_drv << 2);
  8078. /*
  8079. * Default the DMIC clk rates to mad_dmic_sample_rate,
  8080. * whereas, the anc/txfe dmic rates to dmic_sample_rate
  8081. * since the anc/txfe are independent of mad block.
  8082. */
  8083. mad_dmic_ctl_val = tavil_get_dmic_clk_val(tavil->codec,
  8084. pdata->mclk_rate,
  8085. pdata->mad_dmic_sample_rate);
  8086. snd_soc_update_bits(codec, WCD934X_CPE_SS_DMIC0_CTL,
  8087. 0x0E, mad_dmic_ctl_val << 1);
  8088. snd_soc_update_bits(codec, WCD934X_CPE_SS_DMIC1_CTL,
  8089. 0x0E, mad_dmic_ctl_val << 1);
  8090. snd_soc_update_bits(codec, WCD934X_CPE_SS_DMIC2_CTL,
  8091. 0x0E, mad_dmic_ctl_val << 1);
  8092. if (dmic_clk_drv == WCD934X_DMIC_CLK_DIV_2)
  8093. anc_ctl_value = WCD934X_ANC_DMIC_X2_FULL_RATE;
  8094. else
  8095. anc_ctl_value = WCD934X_ANC_DMIC_X2_HALF_RATE;
  8096. snd_soc_update_bits(codec, WCD934X_CDC_ANC0_MODE_2_CTL,
  8097. 0x40, anc_ctl_value << 6);
  8098. snd_soc_update_bits(codec, WCD934X_CDC_ANC0_MODE_2_CTL,
  8099. 0x20, anc_ctl_value << 5);
  8100. snd_soc_update_bits(codec, WCD934X_CDC_ANC1_MODE_2_CTL,
  8101. 0x40, anc_ctl_value << 6);
  8102. snd_soc_update_bits(codec, WCD934X_CDC_ANC1_MODE_2_CTL,
  8103. 0x20, anc_ctl_value << 5);
  8104. done:
  8105. return rc;
  8106. }
  8107. static void tavil_cdc_vote_svs(struct snd_soc_codec *codec, bool vote)
  8108. {
  8109. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  8110. return tavil_vote_svs(tavil, vote);
  8111. }
  8112. struct wcd_dsp_cdc_cb cdc_cb = {
  8113. .cdc_clk_en = tavil_codec_internal_rco_ctrl,
  8114. .cdc_vote_svs = tavil_cdc_vote_svs,
  8115. };
  8116. static int tavil_wdsp_initialize(struct snd_soc_codec *codec)
  8117. {
  8118. struct wcd9xxx *control;
  8119. struct tavil_priv *tavil;
  8120. struct wcd_dsp_params params;
  8121. int ret = 0;
  8122. control = dev_get_drvdata(codec->dev->parent);
  8123. tavil = snd_soc_codec_get_drvdata(codec);
  8124. params.cb = &cdc_cb;
  8125. params.irqs.cpe_ipc1_irq = WCD934X_IRQ_CPE1_INTR;
  8126. params.irqs.cpe_err_irq = WCD934X_IRQ_CPE_ERROR;
  8127. params.irqs.fatal_irqs = CPE_FATAL_IRQS;
  8128. params.clk_rate = control->mclk_rate;
  8129. params.dsp_instance = 0;
  8130. wcd_dsp_cntl_init(codec, &params, &tavil->wdsp_cntl);
  8131. if (!tavil->wdsp_cntl) {
  8132. dev_err(tavil->dev, "%s: wcd-dsp-control init failed\n",
  8133. __func__);
  8134. ret = -EINVAL;
  8135. }
  8136. return ret;
  8137. }
  8138. /*
  8139. * tavil_soc_get_mbhc: get wcd934x_mbhc handle of corresponding codec
  8140. * @codec: handle to snd_soc_codec *
  8141. *
  8142. * return wcd934x_mbhc handle or error code in case of failure
  8143. */
  8144. struct wcd934x_mbhc *tavil_soc_get_mbhc(struct snd_soc_codec *codec)
  8145. {
  8146. struct tavil_priv *tavil;
  8147. if (!codec) {
  8148. pr_err("%s: Invalid params, NULL codec\n", __func__);
  8149. return NULL;
  8150. }
  8151. tavil = snd_soc_codec_get_drvdata(codec);
  8152. if (!tavil) {
  8153. pr_err("%s: Invalid params, NULL tavil\n", __func__);
  8154. return NULL;
  8155. }
  8156. return tavil->mbhc;
  8157. }
  8158. EXPORT_SYMBOL(tavil_soc_get_mbhc);
  8159. static void tavil_mclk2_reg_defaults(struct tavil_priv *tavil)
  8160. {
  8161. int i;
  8162. struct snd_soc_codec *codec = tavil->codec;
  8163. if (TAVIL_IS_1_0(tavil->wcd9xxx)) {
  8164. /* MCLK2 configuration */
  8165. for (i = 0; i < ARRAY_SIZE(tavil_codec_mclk2_1_0_defaults); i++)
  8166. snd_soc_update_bits(codec,
  8167. tavil_codec_mclk2_1_0_defaults[i].reg,
  8168. tavil_codec_mclk2_1_0_defaults[i].mask,
  8169. tavil_codec_mclk2_1_0_defaults[i].val);
  8170. }
  8171. if (TAVIL_IS_1_1(tavil->wcd9xxx)) {
  8172. /* MCLK2 configuration */
  8173. for (i = 0; i < ARRAY_SIZE(tavil_codec_mclk2_1_1_defaults); i++)
  8174. snd_soc_update_bits(codec,
  8175. tavil_codec_mclk2_1_1_defaults[i].reg,
  8176. tavil_codec_mclk2_1_1_defaults[i].mask,
  8177. tavil_codec_mclk2_1_1_defaults[i].val);
  8178. }
  8179. }
  8180. static int tavil_device_down(struct wcd9xxx *wcd9xxx)
  8181. {
  8182. struct snd_soc_codec *codec;
  8183. struct tavil_priv *priv;
  8184. int count;
  8185. codec = (struct snd_soc_codec *)(wcd9xxx->ssr_priv);
  8186. priv = snd_soc_codec_get_drvdata(codec);
  8187. for (count = 0; count < NUM_CODEC_DAIS; count++)
  8188. priv->dai[count].bus_down_in_recovery = true;
  8189. if (priv->swr.ctrl_data)
  8190. swrm_wcd_notify(priv->swr.ctrl_data[0].swr_pdev,
  8191. SWR_DEVICE_DOWN, NULL);
  8192. tavil_dsd_reset(priv->dsd_config);
  8193. snd_soc_card_change_online_state(codec->component.card, 0);
  8194. wcd_dsp_ssr_event(priv->wdsp_cntl, WCD_CDC_DOWN_EVENT);
  8195. wcd_resmgr_set_sido_input_src_locked(priv->resmgr,
  8196. SIDO_SOURCE_INTERNAL);
  8197. return 0;
  8198. }
  8199. static int tavil_post_reset_cb(struct wcd9xxx *wcd9xxx)
  8200. {
  8201. int i, ret = 0;
  8202. struct wcd9xxx *control;
  8203. struct snd_soc_codec *codec;
  8204. struct tavil_priv *tavil;
  8205. struct wcd9xxx_pdata *pdata;
  8206. struct wcd_mbhc *mbhc;
  8207. codec = (struct snd_soc_codec *)(wcd9xxx->ssr_priv);
  8208. tavil = snd_soc_codec_get_drvdata(codec);
  8209. control = dev_get_drvdata(codec->dev->parent);
  8210. wcd9xxx_set_power_state(tavil->wcd9xxx,
  8211. WCD_REGION_POWER_COLLAPSE_REMOVE,
  8212. WCD9XXX_DIG_CORE_REGION_1);
  8213. mutex_lock(&tavil->codec_mutex);
  8214. tavil_vote_svs(tavil, true);
  8215. tavil_slimbus_slave_port_cfg.slave_dev_intfdev_la =
  8216. control->slim_slave->laddr;
  8217. tavil_slimbus_slave_port_cfg.slave_dev_pgd_la =
  8218. control->slim->laddr;
  8219. tavil_init_slim_slave_cfg(codec);
  8220. snd_soc_card_change_online_state(codec->component.card, 1);
  8221. for (i = 0; i < TAVIL_MAX_MICBIAS; i++)
  8222. tavil->micb_ref[i] = 0;
  8223. dev_dbg(codec->dev, "%s: MCLK Rate = %x\n",
  8224. __func__, control->mclk_rate);
  8225. if (control->mclk_rate == WCD934X_MCLK_CLK_12P288MHZ)
  8226. snd_soc_update_bits(codec, WCD934X_CODEC_RPM_CLK_MCLK_CFG,
  8227. 0x03, 0x00);
  8228. else if (control->mclk_rate == WCD934X_MCLK_CLK_9P6MHZ)
  8229. snd_soc_update_bits(codec, WCD934X_CODEC_RPM_CLK_MCLK_CFG,
  8230. 0x03, 0x01);
  8231. wcd_resmgr_post_ssr_v2(tavil->resmgr);
  8232. tavil_update_reg_defaults(tavil);
  8233. tavil_codec_init_reg(tavil);
  8234. __tavil_enable_efuse_sensing(tavil);
  8235. tavil_mclk2_reg_defaults(tavil);
  8236. __tavil_cdc_mclk_enable(tavil, true);
  8237. regcache_mark_dirty(codec->component.regmap);
  8238. regcache_sync(codec->component.regmap);
  8239. __tavil_cdc_mclk_enable(tavil, false);
  8240. tavil_update_cpr_defaults(tavil);
  8241. pdata = dev_get_platdata(codec->dev->parent);
  8242. ret = tavil_handle_pdata(tavil, pdata);
  8243. if (ret < 0)
  8244. dev_err(codec->dev, "%s: invalid pdata\n", __func__);
  8245. /* Initialize MBHC module */
  8246. mbhc = &tavil->mbhc->wcd_mbhc;
  8247. ret = tavil_mbhc_post_ssr_init(tavil->mbhc, codec);
  8248. if (ret) {
  8249. dev_err(codec->dev, "%s: mbhc initialization failed\n",
  8250. __func__);
  8251. goto done;
  8252. } else {
  8253. tavil_mbhc_hs_detect(codec, mbhc->mbhc_cfg);
  8254. }
  8255. /* DSD initialization */
  8256. ret = tavil_dsd_post_ssr_init(tavil->dsd_config);
  8257. if (ret)
  8258. dev_dbg(tavil->dev, "%s: DSD init failed\n", __func__);
  8259. tavil_cleanup_irqs(tavil);
  8260. ret = tavil_setup_irqs(tavil);
  8261. if (ret) {
  8262. dev_err(codec->dev, "%s: tavil irq setup failed %d\n",
  8263. __func__, ret);
  8264. goto done;
  8265. }
  8266. tavil_set_spkr_mode(codec, tavil->swr.spkr_mode);
  8267. /*
  8268. * Once the codec initialization is completed, the svs vote
  8269. * can be released allowing the codec to go to SVS2.
  8270. */
  8271. tavil_vote_svs(tavil, false);
  8272. wcd_dsp_ssr_event(tavil->wdsp_cntl, WCD_CDC_UP_EVENT);
  8273. done:
  8274. mutex_unlock(&tavil->codec_mutex);
  8275. return ret;
  8276. }
  8277. static int tavil_soc_codec_probe(struct snd_soc_codec *codec)
  8278. {
  8279. struct wcd9xxx *control;
  8280. struct tavil_priv *tavil;
  8281. struct wcd9xxx_pdata *pdata;
  8282. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  8283. int i, ret;
  8284. void *ptr = NULL;
  8285. control = dev_get_drvdata(codec->dev->parent);
  8286. dev_info(codec->dev, "%s()\n", __func__);
  8287. tavil = snd_soc_codec_get_drvdata(codec);
  8288. tavil->intf_type = wcd9xxx_get_intf_type();
  8289. control->dev_down = tavil_device_down;
  8290. control->post_reset = tavil_post_reset_cb;
  8291. control->ssr_priv = (void *)codec;
  8292. /* Resource Manager post Init */
  8293. ret = wcd_resmgr_post_init(tavil->resmgr, &tavil_resmgr_cb, codec);
  8294. if (ret) {
  8295. dev_err(codec->dev, "%s: wcd resmgr post init failed\n",
  8296. __func__);
  8297. goto err;
  8298. }
  8299. /* Class-H Init */
  8300. wcd_clsh_init(&tavil->clsh_d);
  8301. /* Default HPH Mode to Class-H Low HiFi */
  8302. tavil->hph_mode = CLS_H_LOHIFI;
  8303. tavil->fw_data = devm_kzalloc(codec->dev, sizeof(*(tavil->fw_data)),
  8304. GFP_KERNEL);
  8305. if (!tavil->fw_data)
  8306. goto err;
  8307. set_bit(WCD9XXX_ANC_CAL, tavil->fw_data->cal_bit);
  8308. set_bit(WCD9XXX_MBHC_CAL, tavil->fw_data->cal_bit);
  8309. set_bit(WCD9XXX_MAD_CAL, tavil->fw_data->cal_bit);
  8310. set_bit(WCD9XXX_VBAT_CAL, tavil->fw_data->cal_bit);
  8311. ret = wcd_cal_create_hwdep(tavil->fw_data,
  8312. WCD9XXX_CODEC_HWDEP_NODE, codec);
  8313. if (ret < 0) {
  8314. dev_err(codec->dev, "%s hwdep failed %d\n", __func__, ret);
  8315. goto err_hwdep;
  8316. }
  8317. /* Initialize MBHC module */
  8318. ret = tavil_mbhc_init(&tavil->mbhc, codec, tavil->fw_data);
  8319. if (ret) {
  8320. pr_err("%s: mbhc initialization failed\n", __func__);
  8321. goto err_hwdep;
  8322. }
  8323. tavil->codec = codec;
  8324. for (i = 0; i < COMPANDER_MAX; i++)
  8325. tavil->comp_enabled[i] = 0;
  8326. tavil_codec_init_reg(tavil);
  8327. pdata = dev_get_platdata(codec->dev->parent);
  8328. ret = tavil_handle_pdata(tavil, pdata);
  8329. if (ret < 0) {
  8330. dev_err(codec->dev, "%s: bad pdata\n", __func__);
  8331. goto err_hwdep;
  8332. }
  8333. ptr = devm_kzalloc(codec->dev, (sizeof(tavil_rx_chs) +
  8334. sizeof(tavil_tx_chs)), GFP_KERNEL);
  8335. if (!ptr) {
  8336. ret = -ENOMEM;
  8337. goto err_hwdep;
  8338. }
  8339. snd_soc_dapm_add_routes(dapm, tavil_slim_audio_map,
  8340. ARRAY_SIZE(tavil_slim_audio_map));
  8341. for (i = 0; i < NUM_CODEC_DAIS; i++) {
  8342. INIT_LIST_HEAD(&tavil->dai[i].wcd9xxx_ch_list);
  8343. init_waitqueue_head(&tavil->dai[i].dai_wait);
  8344. }
  8345. tavil_slimbus_slave_port_cfg.slave_dev_intfdev_la =
  8346. control->slim_slave->laddr;
  8347. tavil_slimbus_slave_port_cfg.slave_dev_pgd_la =
  8348. control->slim->laddr;
  8349. tavil_slimbus_slave_port_cfg.slave_port_mapping[0] =
  8350. WCD934X_TX13;
  8351. tavil_init_slim_slave_cfg(codec);
  8352. control->num_rx_port = WCD934X_RX_MAX;
  8353. control->rx_chs = ptr;
  8354. memcpy(control->rx_chs, tavil_rx_chs, sizeof(tavil_rx_chs));
  8355. control->num_tx_port = WCD934X_TX_MAX;
  8356. control->tx_chs = ptr + sizeof(tavil_rx_chs);
  8357. memcpy(control->tx_chs, tavil_tx_chs, sizeof(tavil_tx_chs));
  8358. ret = tavil_setup_irqs(tavil);
  8359. if (ret) {
  8360. dev_err(tavil->dev, "%s: tavil irq setup failed %d\n",
  8361. __func__, ret);
  8362. goto err_pdata;
  8363. }
  8364. for (i = 0; i < WCD934X_NUM_DECIMATORS; i++) {
  8365. tavil->tx_hpf_work[i].tavil = tavil;
  8366. tavil->tx_hpf_work[i].decimator = i;
  8367. INIT_DELAYED_WORK(&tavil->tx_hpf_work[i].dwork,
  8368. tavil_tx_hpf_corner_freq_callback);
  8369. tavil->tx_mute_dwork[i].tavil = tavil;
  8370. tavil->tx_mute_dwork[i].decimator = i;
  8371. INIT_DELAYED_WORK(&tavil->tx_mute_dwork[i].dwork,
  8372. tavil_tx_mute_update_callback);
  8373. }
  8374. tavil->spk_anc_dwork.tavil = tavil;
  8375. INIT_DELAYED_WORK(&tavil->spk_anc_dwork.dwork,
  8376. tavil_spk_anc_update_callback);
  8377. tavil_mclk2_reg_defaults(tavil);
  8378. /* DSD initialization */
  8379. tavil->dsd_config = tavil_dsd_init(codec);
  8380. if (IS_ERR_OR_NULL(tavil->dsd_config))
  8381. dev_dbg(tavil->dev, "%s: DSD init failed\n", __func__);
  8382. mutex_lock(&tavil->codec_mutex);
  8383. snd_soc_dapm_disable_pin(dapm, "ANC EAR PA");
  8384. snd_soc_dapm_disable_pin(dapm, "ANC EAR");
  8385. snd_soc_dapm_disable_pin(dapm, "ANC HPHL PA");
  8386. snd_soc_dapm_disable_pin(dapm, "ANC HPHR PA");
  8387. snd_soc_dapm_disable_pin(dapm, "ANC HPHL");
  8388. snd_soc_dapm_disable_pin(dapm, "ANC HPHR");
  8389. snd_soc_dapm_enable_pin(dapm, "ANC SPK1 PA");
  8390. mutex_unlock(&tavil->codec_mutex);
  8391. snd_soc_dapm_ignore_suspend(dapm, "AIF1 Playback");
  8392. snd_soc_dapm_ignore_suspend(dapm, "AIF1 Capture");
  8393. snd_soc_dapm_ignore_suspend(dapm, "AIF2 Playback");
  8394. snd_soc_dapm_ignore_suspend(dapm, "AIF2 Capture");
  8395. snd_soc_dapm_ignore_suspend(dapm, "AIF3 Playback");
  8396. snd_soc_dapm_ignore_suspend(dapm, "AIF3 Capture");
  8397. snd_soc_dapm_ignore_suspend(dapm, "AIF4 Playback");
  8398. snd_soc_dapm_ignore_suspend(dapm, "AIF4 MAD TX");
  8399. snd_soc_dapm_ignore_suspend(dapm, "VIfeed");
  8400. snd_soc_dapm_sync(dapm);
  8401. tavil_wdsp_initialize(codec);
  8402. /*
  8403. * Once the codec initialization is completed, the svs vote
  8404. * can be released allowing the codec to go to SVS2.
  8405. */
  8406. tavil_vote_svs(tavil, false);
  8407. return ret;
  8408. err_pdata:
  8409. devm_kfree(codec->dev, ptr);
  8410. control->rx_chs = NULL;
  8411. control->tx_chs = NULL;
  8412. err_hwdep:
  8413. devm_kfree(codec->dev, tavil->fw_data);
  8414. tavil->fw_data = NULL;
  8415. err:
  8416. return ret;
  8417. }
  8418. static int tavil_soc_codec_remove(struct snd_soc_codec *codec)
  8419. {
  8420. struct wcd9xxx *control;
  8421. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  8422. control = dev_get_drvdata(codec->dev->parent);
  8423. devm_kfree(codec->dev, control->rx_chs);
  8424. /* slimslave deinit in wcd core looks for this value */
  8425. control->num_rx_port = 0;
  8426. control->num_tx_port = 0;
  8427. control->rx_chs = NULL;
  8428. control->tx_chs = NULL;
  8429. tavil_cleanup_irqs(tavil);
  8430. if (tavil->wdsp_cntl)
  8431. wcd_dsp_cntl_deinit(&tavil->wdsp_cntl);
  8432. /* Deinitialize MBHC module */
  8433. tavil_mbhc_deinit(codec);
  8434. tavil->mbhc = NULL;
  8435. return 0;
  8436. }
  8437. static struct regmap *tavil_get_regmap(struct device *dev)
  8438. {
  8439. struct wcd9xxx *control = dev_get_drvdata(dev->parent);
  8440. return control->regmap;
  8441. }
  8442. static struct snd_soc_codec_driver soc_codec_dev_tavil = {
  8443. .probe = tavil_soc_codec_probe,
  8444. .remove = tavil_soc_codec_remove,
  8445. .get_regmap = tavil_get_regmap,
  8446. .component_driver = {
  8447. .controls = tavil_snd_controls,
  8448. .num_controls = ARRAY_SIZE(tavil_snd_controls),
  8449. .dapm_widgets = tavil_dapm_widgets,
  8450. .num_dapm_widgets = ARRAY_SIZE(tavil_dapm_widgets),
  8451. .dapm_routes = tavil_audio_map,
  8452. .num_dapm_routes = ARRAY_SIZE(tavil_audio_map),
  8453. },
  8454. };
  8455. #ifdef CONFIG_PM
  8456. static int tavil_suspend(struct device *dev)
  8457. {
  8458. struct platform_device *pdev = to_platform_device(dev);
  8459. struct tavil_priv *tavil = platform_get_drvdata(pdev);
  8460. if (!tavil) {
  8461. dev_err(dev, "%s: tavil private data is NULL\n", __func__);
  8462. return -EINVAL;
  8463. }
  8464. dev_dbg(dev, "%s: system suspend\n", __func__);
  8465. if (delayed_work_pending(&tavil->power_gate_work) &&
  8466. cancel_delayed_work_sync(&tavil->power_gate_work))
  8467. tavil_codec_power_gate_digital_core(tavil);
  8468. return 0;
  8469. }
  8470. static int tavil_resume(struct device *dev)
  8471. {
  8472. struct platform_device *pdev = to_platform_device(dev);
  8473. struct tavil_priv *tavil = platform_get_drvdata(pdev);
  8474. if (!tavil) {
  8475. dev_err(dev, "%s: tavil private data is NULL\n", __func__);
  8476. return -EINVAL;
  8477. }
  8478. dev_dbg(dev, "%s: system resume\n", __func__);
  8479. return 0;
  8480. }
  8481. static const struct dev_pm_ops tavil_pm_ops = {
  8482. .suspend = tavil_suspend,
  8483. .resume = tavil_resume,
  8484. };
  8485. #endif
  8486. static int tavil_swrm_read(void *handle, int reg)
  8487. {
  8488. struct tavil_priv *tavil;
  8489. struct wcd9xxx *wcd9xxx;
  8490. unsigned short swr_rd_addr_base;
  8491. unsigned short swr_rd_data_base;
  8492. int val, ret;
  8493. if (!handle) {
  8494. pr_err("%s: NULL handle\n", __func__);
  8495. return -EINVAL;
  8496. }
  8497. tavil = (struct tavil_priv *)handle;
  8498. wcd9xxx = tavil->wcd9xxx;
  8499. dev_dbg(tavil->dev, "%s: Reading soundwire register, 0x%x\n",
  8500. __func__, reg);
  8501. swr_rd_addr_base = WCD934X_SWR_AHB_BRIDGE_RD_ADDR_0;
  8502. swr_rd_data_base = WCD934X_SWR_AHB_BRIDGE_RD_DATA_0;
  8503. mutex_lock(&tavil->swr.read_mutex);
  8504. ret = regmap_bulk_write(wcd9xxx->regmap, swr_rd_addr_base,
  8505. (u8 *)&reg, 4);
  8506. if (ret < 0) {
  8507. dev_err(tavil->dev, "%s: RD Addr Failure\n", __func__);
  8508. goto done;
  8509. }
  8510. ret = regmap_bulk_read(wcd9xxx->regmap, swr_rd_data_base,
  8511. (u8 *)&val, 4);
  8512. if (ret < 0) {
  8513. dev_err(tavil->dev, "%s: RD Data Failure\n", __func__);
  8514. goto done;
  8515. }
  8516. ret = val;
  8517. done:
  8518. mutex_unlock(&tavil->swr.read_mutex);
  8519. return ret;
  8520. }
  8521. static int tavil_swrm_bulk_write(void *handle, u32 *reg, u32 *val, size_t len)
  8522. {
  8523. struct tavil_priv *tavil;
  8524. struct wcd9xxx *wcd9xxx;
  8525. struct wcd9xxx_reg_val *bulk_reg;
  8526. unsigned short swr_wr_addr_base;
  8527. unsigned short swr_wr_data_base;
  8528. int i, j, ret;
  8529. if (!handle || !reg || !val) {
  8530. pr_err("%s: NULL parameter\n", __func__);
  8531. return -EINVAL;
  8532. }
  8533. if (len <= 0) {
  8534. pr_err("%s: Invalid size: %zu\n", __func__, len);
  8535. return -EINVAL;
  8536. }
  8537. tavil = (struct tavil_priv *)handle;
  8538. wcd9xxx = tavil->wcd9xxx;
  8539. swr_wr_addr_base = WCD934X_SWR_AHB_BRIDGE_WR_ADDR_0;
  8540. swr_wr_data_base = WCD934X_SWR_AHB_BRIDGE_WR_DATA_0;
  8541. bulk_reg = kzalloc((2 * len * sizeof(struct wcd9xxx_reg_val)),
  8542. GFP_KERNEL);
  8543. if (!bulk_reg)
  8544. return -ENOMEM;
  8545. for (i = 0, j = 0; i < (len * 2); i += 2, j++) {
  8546. bulk_reg[i].reg = swr_wr_data_base;
  8547. bulk_reg[i].buf = (u8 *)(&val[j]);
  8548. bulk_reg[i].bytes = 4;
  8549. bulk_reg[i+1].reg = swr_wr_addr_base;
  8550. bulk_reg[i+1].buf = (u8 *)(&reg[j]);
  8551. bulk_reg[i+1].bytes = 4;
  8552. }
  8553. mutex_lock(&tavil->swr.write_mutex);
  8554. ret = wcd9xxx_slim_bulk_write(wcd9xxx, bulk_reg,
  8555. (len * 2), false);
  8556. if (ret) {
  8557. dev_err(tavil->dev, "%s: swrm bulk write failed, ret: %d\n",
  8558. __func__, ret);
  8559. }
  8560. mutex_unlock(&tavil->swr.write_mutex);
  8561. kfree(bulk_reg);
  8562. return ret;
  8563. }
  8564. static int tavil_swrm_write(void *handle, int reg, int val)
  8565. {
  8566. struct tavil_priv *tavil;
  8567. struct wcd9xxx *wcd9xxx;
  8568. unsigned short swr_wr_addr_base;
  8569. unsigned short swr_wr_data_base;
  8570. struct wcd9xxx_reg_val bulk_reg[2];
  8571. int ret;
  8572. if (!handle) {
  8573. pr_err("%s: NULL handle\n", __func__);
  8574. return -EINVAL;
  8575. }
  8576. tavil = (struct tavil_priv *)handle;
  8577. wcd9xxx = tavil->wcd9xxx;
  8578. swr_wr_addr_base = WCD934X_SWR_AHB_BRIDGE_WR_ADDR_0;
  8579. swr_wr_data_base = WCD934X_SWR_AHB_BRIDGE_WR_DATA_0;
  8580. /* First Write the Data to register */
  8581. bulk_reg[0].reg = swr_wr_data_base;
  8582. bulk_reg[0].buf = (u8 *)(&val);
  8583. bulk_reg[0].bytes = 4;
  8584. bulk_reg[1].reg = swr_wr_addr_base;
  8585. bulk_reg[1].buf = (u8 *)(&reg);
  8586. bulk_reg[1].bytes = 4;
  8587. mutex_lock(&tavil->swr.write_mutex);
  8588. ret = wcd9xxx_slim_bulk_write(wcd9xxx, bulk_reg, 2, false);
  8589. if (ret < 0)
  8590. dev_err(tavil->dev, "%s: WR Data Failure\n", __func__);
  8591. mutex_unlock(&tavil->swr.write_mutex);
  8592. return ret;
  8593. }
  8594. static int tavil_swrm_clock(void *handle, bool enable)
  8595. {
  8596. struct tavil_priv *tavil;
  8597. if (!handle) {
  8598. pr_err("%s: NULL handle\n", __func__);
  8599. return -EINVAL;
  8600. }
  8601. tavil = (struct tavil_priv *)handle;
  8602. mutex_lock(&tavil->swr.clk_mutex);
  8603. dev_dbg(tavil->dev, "%s: swrm clock %s\n",
  8604. __func__, (enable?"enable" : "disable"));
  8605. if (enable) {
  8606. tavil->swr.clk_users++;
  8607. if (tavil->swr.clk_users == 1) {
  8608. regmap_update_bits(tavil->wcd9xxx->regmap,
  8609. WCD934X_TEST_DEBUG_NPL_DLY_TEST_1,
  8610. 0x10, 0x00);
  8611. __tavil_cdc_mclk_enable(tavil, true);
  8612. regmap_update_bits(tavil->wcd9xxx->regmap,
  8613. WCD934X_CDC_CLK_RST_CTRL_SWR_CONTROL,
  8614. 0x01, 0x01);
  8615. }
  8616. } else {
  8617. tavil->swr.clk_users--;
  8618. if (tavil->swr.clk_users == 0) {
  8619. regmap_update_bits(tavil->wcd9xxx->regmap,
  8620. WCD934X_CDC_CLK_RST_CTRL_SWR_CONTROL,
  8621. 0x01, 0x00);
  8622. __tavil_cdc_mclk_enable(tavil, false);
  8623. regmap_update_bits(tavil->wcd9xxx->regmap,
  8624. WCD934X_TEST_DEBUG_NPL_DLY_TEST_1,
  8625. 0x10, 0x10);
  8626. }
  8627. }
  8628. dev_dbg(tavil->dev, "%s: swrm clock users %d\n",
  8629. __func__, tavil->swr.clk_users);
  8630. mutex_unlock(&tavil->swr.clk_mutex);
  8631. return 0;
  8632. }
  8633. static int tavil_swrm_handle_irq(void *handle,
  8634. irqreturn_t (*swrm_irq_handler)(int irq,
  8635. void *data),
  8636. void *swrm_handle,
  8637. int action)
  8638. {
  8639. struct tavil_priv *tavil;
  8640. int ret = 0;
  8641. struct wcd9xxx *wcd9xxx;
  8642. if (!handle) {
  8643. pr_err("%s: NULL handle\n", __func__);
  8644. return -EINVAL;
  8645. }
  8646. tavil = (struct tavil_priv *) handle;
  8647. wcd9xxx = tavil->wcd9xxx;
  8648. if (action) {
  8649. ret = wcd9xxx_request_irq(&wcd9xxx->core_res,
  8650. WCD934X_IRQ_SOUNDWIRE,
  8651. swrm_irq_handler,
  8652. "Tavil SWR Master", swrm_handle);
  8653. if (ret)
  8654. dev_err(tavil->dev, "%s: Failed to request irq %d\n",
  8655. __func__, WCD934X_IRQ_SOUNDWIRE);
  8656. } else
  8657. wcd9xxx_free_irq(&wcd9xxx->core_res, WCD934X_IRQ_SOUNDWIRE,
  8658. swrm_handle);
  8659. return ret;
  8660. }
  8661. static void tavil_codec_add_spi_device(struct tavil_priv *tavil,
  8662. struct device_node *node)
  8663. {
  8664. struct spi_master *master;
  8665. struct spi_device *spi;
  8666. u32 prop_value;
  8667. int rc;
  8668. /* Read the master bus num from DT node */
  8669. rc = of_property_read_u32(node, "qcom,master-bus-num",
  8670. &prop_value);
  8671. if (rc < 0) {
  8672. dev_err(tavil->dev, "%s: prop %s not found in node %s",
  8673. __func__, "qcom,master-bus-num", node->full_name);
  8674. goto done;
  8675. }
  8676. /* Get the reference to SPI master */
  8677. master = spi_busnum_to_master(prop_value);
  8678. if (!master) {
  8679. dev_err(tavil->dev, "%s: Invalid spi_master for bus_num %u\n",
  8680. __func__, prop_value);
  8681. goto done;
  8682. }
  8683. /* Allocate the spi device */
  8684. spi = spi_alloc_device(master);
  8685. if (!spi) {
  8686. dev_err(tavil->dev, "%s: spi_alloc_device failed\n",
  8687. __func__);
  8688. goto err_spi_alloc_dev;
  8689. }
  8690. /* Initialize device properties */
  8691. if (of_modalias_node(node, spi->modalias,
  8692. sizeof(spi->modalias)) < 0) {
  8693. dev_err(tavil->dev, "%s: cannot find modalias for %s\n",
  8694. __func__, node->full_name);
  8695. goto err_dt_parse;
  8696. }
  8697. rc = of_property_read_u32(node, "qcom,chip-select",
  8698. &prop_value);
  8699. if (rc < 0) {
  8700. dev_err(tavil->dev, "%s: prop %s not found in node %s",
  8701. __func__, "qcom,chip-select", node->full_name);
  8702. goto err_dt_parse;
  8703. }
  8704. spi->chip_select = prop_value;
  8705. rc = of_property_read_u32(node, "qcom,max-frequency",
  8706. &prop_value);
  8707. if (rc < 0) {
  8708. dev_err(tavil->dev, "%s: prop %s not found in node %s",
  8709. __func__, "qcom,max-frequency", node->full_name);
  8710. goto err_dt_parse;
  8711. }
  8712. spi->max_speed_hz = prop_value;
  8713. spi->dev.of_node = node;
  8714. rc = spi_add_device(spi);
  8715. if (rc < 0) {
  8716. dev_err(tavil->dev, "%s: spi_add_device failed\n", __func__);
  8717. goto err_dt_parse;
  8718. }
  8719. tavil->spi = spi;
  8720. /* Put the reference to SPI master */
  8721. put_device(&master->dev);
  8722. return;
  8723. err_dt_parse:
  8724. spi_dev_put(spi);
  8725. err_spi_alloc_dev:
  8726. /* Put the reference to SPI master */
  8727. put_device(&master->dev);
  8728. done:
  8729. return;
  8730. }
  8731. static void tavil_add_child_devices(struct work_struct *work)
  8732. {
  8733. struct tavil_priv *tavil;
  8734. struct platform_device *pdev;
  8735. struct device_node *node;
  8736. struct wcd9xxx *wcd9xxx;
  8737. struct tavil_swr_ctrl_data *swr_ctrl_data = NULL, *temp;
  8738. int ret, ctrl_num = 0;
  8739. struct wcd_swr_ctrl_platform_data *platdata;
  8740. char plat_dev_name[WCD934X_STRING_LEN];
  8741. tavil = container_of(work, struct tavil_priv,
  8742. tavil_add_child_devices_work);
  8743. if (!tavil) {
  8744. pr_err("%s: Memory for WCD934X does not exist\n",
  8745. __func__);
  8746. return;
  8747. }
  8748. wcd9xxx = tavil->wcd9xxx;
  8749. if (!wcd9xxx) {
  8750. pr_err("%s: Memory for WCD9XXX does not exist\n",
  8751. __func__);
  8752. return;
  8753. }
  8754. if (!wcd9xxx->dev->of_node) {
  8755. dev_err(wcd9xxx->dev, "%s: DT node for wcd9xxx does not exist\n",
  8756. __func__);
  8757. return;
  8758. }
  8759. platdata = &tavil->swr.plat_data;
  8760. tavil->child_count = 0;
  8761. for_each_child_of_node(wcd9xxx->dev->of_node, node) {
  8762. /* Parse and add the SPI device node */
  8763. if (!strcmp(node->name, "wcd_spi")) {
  8764. tavil_codec_add_spi_device(tavil, node);
  8765. continue;
  8766. }
  8767. /* Parse other child device nodes and add platform device */
  8768. if (!strcmp(node->name, "swr_master"))
  8769. strlcpy(plat_dev_name, "tavil_swr_ctrl",
  8770. (WCD934X_STRING_LEN - 1));
  8771. else if (strnstr(node->name, "msm_cdc_pinctrl",
  8772. strlen("msm_cdc_pinctrl")) != NULL)
  8773. strlcpy(plat_dev_name, node->name,
  8774. (WCD934X_STRING_LEN - 1));
  8775. else
  8776. continue;
  8777. pdev = platform_device_alloc(plat_dev_name, -1);
  8778. if (!pdev) {
  8779. dev_err(wcd9xxx->dev, "%s: pdev memory alloc failed\n",
  8780. __func__);
  8781. ret = -ENOMEM;
  8782. goto err_mem;
  8783. }
  8784. pdev->dev.parent = tavil->dev;
  8785. pdev->dev.of_node = node;
  8786. if (strcmp(node->name, "swr_master") == 0) {
  8787. ret = platform_device_add_data(pdev, platdata,
  8788. sizeof(*platdata));
  8789. if (ret) {
  8790. dev_err(&pdev->dev,
  8791. "%s: cannot add plat data ctrl:%d\n",
  8792. __func__, ctrl_num);
  8793. goto err_pdev_add;
  8794. }
  8795. }
  8796. ret = platform_device_add(pdev);
  8797. if (ret) {
  8798. dev_err(&pdev->dev,
  8799. "%s: Cannot add platform device\n",
  8800. __func__);
  8801. goto err_pdev_add;
  8802. }
  8803. if (strcmp(node->name, "swr_master") == 0) {
  8804. temp = krealloc(swr_ctrl_data,
  8805. (ctrl_num + 1) * sizeof(
  8806. struct tavil_swr_ctrl_data),
  8807. GFP_KERNEL);
  8808. if (!temp) {
  8809. dev_err(wcd9xxx->dev, "out of memory\n");
  8810. ret = -ENOMEM;
  8811. goto err_pdev_add;
  8812. }
  8813. swr_ctrl_data = temp;
  8814. swr_ctrl_data[ctrl_num].swr_pdev = pdev;
  8815. ctrl_num++;
  8816. dev_dbg(&pdev->dev,
  8817. "%s: Added soundwire ctrl device(s)\n",
  8818. __func__);
  8819. tavil->swr.ctrl_data = swr_ctrl_data;
  8820. }
  8821. if (tavil->child_count < WCD934X_CHILD_DEVICES_MAX)
  8822. tavil->pdev_child_devices[tavil->child_count++] = pdev;
  8823. else
  8824. goto err_mem;
  8825. }
  8826. return;
  8827. err_pdev_add:
  8828. platform_device_put(pdev);
  8829. err_mem:
  8830. return;
  8831. }
  8832. static int __tavil_enable_efuse_sensing(struct tavil_priv *tavil)
  8833. {
  8834. int val, rc;
  8835. WCD9XXX_V2_BG_CLK_LOCK(tavil->resmgr);
  8836. __tavil_cdc_mclk_enable_locked(tavil, true);
  8837. regmap_update_bits(tavil->wcd9xxx->regmap,
  8838. WCD934X_CHIP_TIER_CTRL_EFUSE_CTL, 0x1E, 0x10);
  8839. regmap_update_bits(tavil->wcd9xxx->regmap,
  8840. WCD934X_CHIP_TIER_CTRL_EFUSE_CTL, 0x01, 0x01);
  8841. /*
  8842. * 5ms sleep required after enabling efuse control
  8843. * before checking the status.
  8844. */
  8845. usleep_range(5000, 5500);
  8846. wcd_resmgr_set_sido_input_src(tavil->resmgr,
  8847. SIDO_SOURCE_RCO_BG);
  8848. WCD9XXX_V2_BG_CLK_UNLOCK(tavil->resmgr);
  8849. rc = regmap_read(tavil->wcd9xxx->regmap,
  8850. WCD934X_CHIP_TIER_CTRL_EFUSE_STATUS, &val);
  8851. if (rc || (!(val & 0x01)))
  8852. WARN(1, "%s: Efuse sense is not complete val=%x, ret=%d\n",
  8853. __func__, val, rc);
  8854. __tavil_cdc_mclk_enable(tavil, false);
  8855. return rc;
  8856. }
  8857. static void ___tavil_get_codec_fine_version(struct tavil_priv *tavil)
  8858. {
  8859. int val1, val2, version;
  8860. struct regmap *regmap;
  8861. u16 id_minor;
  8862. u32 version_mask = 0;
  8863. regmap = tavil->wcd9xxx->regmap;
  8864. version = tavil->wcd9xxx->version;
  8865. id_minor = tavil->wcd9xxx->codec_type->id_minor;
  8866. regmap_read(regmap, WCD934X_CHIP_TIER_CTRL_EFUSE_VAL_OUT14, &val1);
  8867. regmap_read(regmap, WCD934X_CHIP_TIER_CTRL_EFUSE_VAL_OUT15, &val2);
  8868. dev_dbg(tavil->dev, "%s: chip version :0x%x 0x:%x\n",
  8869. __func__, val1, val2);
  8870. version_mask |= (!!((u8)val1 & 0x80)) << DSD_DISABLED_MASK;
  8871. version_mask |= (!!((u8)val2 & 0x01)) << SLNQ_DISABLED_MASK;
  8872. switch (version_mask) {
  8873. case DSD_DISABLED | SLNQ_DISABLED:
  8874. if (id_minor == cpu_to_le16(0))
  8875. version = TAVIL_VERSION_WCD9340_1_0;
  8876. else if (id_minor == cpu_to_le16(0x01))
  8877. version = TAVIL_VERSION_WCD9340_1_1;
  8878. break;
  8879. case SLNQ_DISABLED:
  8880. if (id_minor == cpu_to_le16(0))
  8881. version = TAVIL_VERSION_WCD9341_1_0;
  8882. else if (id_minor == cpu_to_le16(0x01))
  8883. version = TAVIL_VERSION_WCD9341_1_1;
  8884. break;
  8885. }
  8886. tavil->wcd9xxx->version = version;
  8887. tavil->wcd9xxx->codec_type->version = version;
  8888. }
  8889. /*
  8890. * tavil_get_wcd_dsp_cntl: Get the reference to wcd_dsp_cntl
  8891. * @dev: Device pointer for codec device
  8892. *
  8893. * This API gets the reference to codec's struct wcd_dsp_cntl
  8894. */
  8895. struct wcd_dsp_cntl *tavil_get_wcd_dsp_cntl(struct device *dev)
  8896. {
  8897. struct platform_device *pdev;
  8898. struct tavil_priv *tavil;
  8899. if (!dev) {
  8900. pr_err("%s: Invalid device\n", __func__);
  8901. return NULL;
  8902. }
  8903. pdev = to_platform_device(dev);
  8904. tavil = platform_get_drvdata(pdev);
  8905. return tavil->wdsp_cntl;
  8906. }
  8907. EXPORT_SYMBOL(tavil_get_wcd_dsp_cntl);
  8908. static int tavil_probe(struct platform_device *pdev)
  8909. {
  8910. int ret = 0;
  8911. struct tavil_priv *tavil;
  8912. struct clk *wcd_ext_clk;
  8913. struct wcd9xxx_resmgr_v2 *resmgr;
  8914. struct wcd9xxx_power_region *cdc_pwr;
  8915. tavil = devm_kzalloc(&pdev->dev, sizeof(struct tavil_priv),
  8916. GFP_KERNEL);
  8917. if (!tavil)
  8918. return -ENOMEM;
  8919. platform_set_drvdata(pdev, tavil);
  8920. tavil->wcd9xxx = dev_get_drvdata(pdev->dev.parent);
  8921. tavil->dev = &pdev->dev;
  8922. INIT_DELAYED_WORK(&tavil->power_gate_work, tavil_codec_power_gate_work);
  8923. mutex_init(&tavil->power_lock);
  8924. INIT_WORK(&tavil->tavil_add_child_devices_work,
  8925. tavil_add_child_devices);
  8926. mutex_init(&tavil->micb_lock);
  8927. mutex_init(&tavil->swr.read_mutex);
  8928. mutex_init(&tavil->swr.write_mutex);
  8929. mutex_init(&tavil->swr.clk_mutex);
  8930. mutex_init(&tavil->codec_mutex);
  8931. mutex_init(&tavil->svs_mutex);
  8932. /*
  8933. * Codec hardware by default comes up in SVS mode.
  8934. * Initialize the svs_ref_cnt to 1 to reflect the hardware
  8935. * state in the driver.
  8936. */
  8937. tavil->svs_ref_cnt = 1;
  8938. cdc_pwr = devm_kzalloc(&pdev->dev, sizeof(struct wcd9xxx_power_region),
  8939. GFP_KERNEL);
  8940. if (!cdc_pwr) {
  8941. ret = -ENOMEM;
  8942. goto err_resmgr;
  8943. }
  8944. tavil->wcd9xxx->wcd9xxx_pwr[WCD9XXX_DIG_CORE_REGION_1] = cdc_pwr;
  8945. cdc_pwr->pwr_collapse_reg_min = WCD934X_DIG_CORE_REG_MIN;
  8946. cdc_pwr->pwr_collapse_reg_max = WCD934X_DIG_CORE_REG_MAX;
  8947. wcd9xxx_set_power_state(tavil->wcd9xxx,
  8948. WCD_REGION_POWER_COLLAPSE_REMOVE,
  8949. WCD9XXX_DIG_CORE_REGION_1);
  8950. /*
  8951. * Init resource manager so that if child nodes such as SoundWire
  8952. * requests for clock, resource manager can honor the request
  8953. */
  8954. resmgr = wcd_resmgr_init(&tavil->wcd9xxx->core_res, NULL);
  8955. if (IS_ERR(resmgr)) {
  8956. ret = PTR_ERR(resmgr);
  8957. dev_err(&pdev->dev, "%s: Failed to initialize wcd resmgr\n",
  8958. __func__);
  8959. goto err_resmgr;
  8960. }
  8961. tavil->resmgr = resmgr;
  8962. tavil->swr.plat_data.handle = (void *) tavil;
  8963. tavil->swr.plat_data.read = tavil_swrm_read;
  8964. tavil->swr.plat_data.write = tavil_swrm_write;
  8965. tavil->swr.plat_data.bulk_write = tavil_swrm_bulk_write;
  8966. tavil->swr.plat_data.clk = tavil_swrm_clock;
  8967. tavil->swr.plat_data.handle_irq = tavil_swrm_handle_irq;
  8968. tavil->swr.spkr_gain_offset = WCD934X_RX_GAIN_OFFSET_0_DB;
  8969. /* Register for Clock */
  8970. wcd_ext_clk = clk_get(tavil->wcd9xxx->dev, "wcd_clk");
  8971. if (IS_ERR(wcd_ext_clk)) {
  8972. dev_err(tavil->wcd9xxx->dev, "%s: clk get %s failed\n",
  8973. __func__, "wcd_ext_clk");
  8974. goto err_clk;
  8975. }
  8976. tavil->wcd_ext_clk = wcd_ext_clk;
  8977. set_bit(AUDIO_NOMINAL, &tavil->status_mask);
  8978. /* Update codec register default values */
  8979. dev_dbg(&pdev->dev, "%s: MCLK Rate = %x\n", __func__,
  8980. tavil->wcd9xxx->mclk_rate);
  8981. if (tavil->wcd9xxx->mclk_rate == WCD934X_MCLK_CLK_12P288MHZ)
  8982. regmap_update_bits(tavil->wcd9xxx->regmap,
  8983. WCD934X_CODEC_RPM_CLK_MCLK_CFG,
  8984. 0x03, 0x00);
  8985. else if (tavil->wcd9xxx->mclk_rate == WCD934X_MCLK_CLK_9P6MHZ)
  8986. regmap_update_bits(tavil->wcd9xxx->regmap,
  8987. WCD934X_CODEC_RPM_CLK_MCLK_CFG,
  8988. 0x03, 0x01);
  8989. tavil_update_reg_defaults(tavil);
  8990. __tavil_enable_efuse_sensing(tavil);
  8991. ___tavil_get_codec_fine_version(tavil);
  8992. tavil_update_cpr_defaults(tavil);
  8993. /* Register with soc framework */
  8994. ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_tavil,
  8995. tavil_dai, ARRAY_SIZE(tavil_dai));
  8996. if (ret) {
  8997. dev_err(&pdev->dev, "%s: Codec registration failed\n",
  8998. __func__);
  8999. goto err_cdc_reg;
  9000. }
  9001. schedule_work(&tavil->tavil_add_child_devices_work);
  9002. return ret;
  9003. err_cdc_reg:
  9004. clk_put(tavil->wcd_ext_clk);
  9005. err_clk:
  9006. wcd_resmgr_remove(tavil->resmgr);
  9007. err_resmgr:
  9008. mutex_destroy(&tavil->micb_lock);
  9009. mutex_destroy(&tavil->svs_mutex);
  9010. mutex_destroy(&tavil->codec_mutex);
  9011. mutex_destroy(&tavil->swr.read_mutex);
  9012. mutex_destroy(&tavil->swr.write_mutex);
  9013. mutex_destroy(&tavil->swr.clk_mutex);
  9014. devm_kfree(&pdev->dev, tavil);
  9015. return ret;
  9016. }
  9017. static int tavil_remove(struct platform_device *pdev)
  9018. {
  9019. struct tavil_priv *tavil;
  9020. int count = 0;
  9021. tavil = platform_get_drvdata(pdev);
  9022. if (!tavil)
  9023. return -EINVAL;
  9024. /* do dsd deinit before codec->component->regmap becomes freed */
  9025. if (tavil->dsd_config) {
  9026. tavil_dsd_deinit(tavil->dsd_config);
  9027. tavil->dsd_config = NULL;
  9028. }
  9029. if (tavil->spi)
  9030. spi_unregister_device(tavil->spi);
  9031. for (count = 0; count < tavil->child_count &&
  9032. count < WCD934X_CHILD_DEVICES_MAX; count++)
  9033. platform_device_unregister(tavil->pdev_child_devices[count]);
  9034. mutex_destroy(&tavil->micb_lock);
  9035. mutex_destroy(&tavil->svs_mutex);
  9036. mutex_destroy(&tavil->codec_mutex);
  9037. mutex_destroy(&tavil->swr.read_mutex);
  9038. mutex_destroy(&tavil->swr.write_mutex);
  9039. mutex_destroy(&tavil->swr.clk_mutex);
  9040. snd_soc_unregister_codec(&pdev->dev);
  9041. clk_put(tavil->wcd_ext_clk);
  9042. wcd_resmgr_remove(tavil->resmgr);
  9043. devm_kfree(&pdev->dev, tavil);
  9044. return 0;
  9045. }
  9046. static struct platform_driver tavil_codec_driver = {
  9047. .probe = tavil_probe,
  9048. .remove = tavil_remove,
  9049. .driver = {
  9050. .name = "tavil_codec",
  9051. .owner = THIS_MODULE,
  9052. #ifdef CONFIG_PM
  9053. .pm = &tavil_pm_ops,
  9054. #endif
  9055. },
  9056. };
  9057. module_platform_driver(tavil_codec_driver);
  9058. MODULE_DESCRIPTION("Tavil Codec driver");
  9059. MODULE_LICENSE("GPL v2");