wcd934x.c 348 KB

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