wcd934x.c 335 KB

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