wcd934x.c 335 KB

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