wcd934x.c 307 KB

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