wcd934x.c 338 KB

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