wcd934x.c 333 KB

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