wcd934x.c 339 KB

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