sdm845.c 196 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125
  1. /*
  2. * Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 and
  6. * only version 2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include <linux/clk.h>
  14. #include <linux/delay.h>
  15. #include <linux/gpio.h>
  16. #include <linux/of_gpio.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/slab.h>
  19. #include <linux/io.h>
  20. #include <linux/module.h>
  21. #include <linux/input.h>
  22. #include <linux/of_device.h>
  23. #include <linux/pm_qos.h>
  24. #include <sound/core.h>
  25. #include <sound/soc.h>
  26. #include <sound/soc-dapm.h>
  27. #include <sound/pcm.h>
  28. #include <sound/jack.h>
  29. #include <sound/pcm_params.h>
  30. #include <sound/info.h>
  31. #include <device_event.h>
  32. #include <dsp/audio_notifier.h>
  33. #include <dsp/q6afe-v2.h>
  34. #include <dsp/q6core.h>
  35. #include "msm-pcm-routing-v2.h"
  36. #include "codecs/msm-cdc-pinctrl.h"
  37. #include "codecs/wcd934x/wcd934x.h"
  38. #include "codecs/wcd934x/wcd934x-mbhc.h"
  39. #include "codecs/wsa881x.h"
  40. #define DRV_NAME "sdm845-asoc-snd"
  41. #define __CHIPSET__ "SDM845 "
  42. #define MSM_DAILINK_NAME(name) (__CHIPSET__#name)
  43. #define SAMPLING_RATE_8KHZ 8000
  44. #define SAMPLING_RATE_11P025KHZ 11025
  45. #define SAMPLING_RATE_16KHZ 16000
  46. #define SAMPLING_RATE_22P05KHZ 22050
  47. #define SAMPLING_RATE_32KHZ 32000
  48. #define SAMPLING_RATE_44P1KHZ 44100
  49. #define SAMPLING_RATE_48KHZ 48000
  50. #define SAMPLING_RATE_88P2KHZ 88200
  51. #define SAMPLING_RATE_96KHZ 96000
  52. #define SAMPLING_RATE_176P4KHZ 176400
  53. #define SAMPLING_RATE_192KHZ 192000
  54. #define SAMPLING_RATE_352P8KHZ 352800
  55. #define SAMPLING_RATE_384KHZ 384000
  56. #define WCD9XXX_MBHC_DEF_BUTTONS 8
  57. #define WCD9XXX_MBHC_DEF_RLOADS 5
  58. #define CODEC_EXT_CLK_RATE 9600000
  59. #define ADSP_STATE_READY_TIMEOUT_MS 3000
  60. #define DEV_NAME_STR_LEN 32
  61. #define WSA8810_NAME_1 "wsa881x.20170211"
  62. #define WSA8810_NAME_2 "wsa881x.20170212"
  63. #define WCN_CDC_SLIM_RX_CH_MAX 2
  64. #define WCN_CDC_SLIM_TX_CH_MAX 3
  65. #define TDM_CHANNEL_MAX 8
  66. #define MSM_HIFI_ON 1
  67. #define MSM_LL_QOS_VALUE 300 /* time in us to ensure LPM doesn't go in C3/C4 */
  68. enum {
  69. SLIM_RX_0 = 0,
  70. SLIM_RX_1,
  71. SLIM_RX_2,
  72. SLIM_RX_3,
  73. SLIM_RX_4,
  74. SLIM_RX_5,
  75. SLIM_RX_6,
  76. SLIM_RX_7,
  77. SLIM_RX_MAX,
  78. };
  79. enum {
  80. SLIM_TX_0 = 0,
  81. SLIM_TX_1,
  82. SLIM_TX_2,
  83. SLIM_TX_3,
  84. SLIM_TX_4,
  85. SLIM_TX_5,
  86. SLIM_TX_6,
  87. SLIM_TX_7,
  88. SLIM_TX_8,
  89. SLIM_TX_MAX,
  90. };
  91. enum {
  92. PRIM_MI2S = 0,
  93. SEC_MI2S,
  94. TERT_MI2S,
  95. QUAT_MI2S,
  96. MI2S_MAX,
  97. };
  98. enum {
  99. PRIM_AUX_PCM = 0,
  100. SEC_AUX_PCM,
  101. TERT_AUX_PCM,
  102. QUAT_AUX_PCM,
  103. AUX_PCM_MAX,
  104. };
  105. enum {
  106. PCM_I2S_SEL_PRIM = 0,
  107. PCM_I2S_SEL_SEC,
  108. PCM_I2S_SEL_TERT,
  109. PCM_I2S_SEL_QUAT,
  110. PCM_I2S_SEL_MAX,
  111. };
  112. struct mi2s_aux_pcm_common_conf {
  113. struct mutex lock;
  114. void *pcm_i2s_sel_vt_addr;
  115. };
  116. struct mi2s_conf {
  117. struct mutex lock;
  118. u32 ref_cnt;
  119. u32 msm_is_mi2s_master;
  120. };
  121. static u32 mi2s_ebit_clk[MI2S_MAX] = {
  122. Q6AFE_LPASS_CLK_ID_PRI_MI2S_EBIT,
  123. Q6AFE_LPASS_CLK_ID_SEC_MI2S_EBIT,
  124. Q6AFE_LPASS_CLK_ID_TER_MI2S_EBIT,
  125. Q6AFE_LPASS_CLK_ID_QUAD_MI2S_EBIT
  126. };
  127. struct auxpcm_conf {
  128. struct mutex lock;
  129. u32 ref_cnt;
  130. };
  131. struct dev_config {
  132. u32 sample_rate;
  133. u32 bit_format;
  134. u32 channels;
  135. };
  136. enum {
  137. DP_RX_IDX = 0,
  138. EXT_DISP_RX_IDX_MAX,
  139. };
  140. struct msm_wsa881x_dev_info {
  141. struct device_node *of_node;
  142. u32 index;
  143. };
  144. enum pinctrl_pin_state {
  145. STATE_DISABLE = 0, /* All pins are in sleep state */
  146. STATE_MI2S_ACTIVE, /* IS2 = active, TDM = sleep */
  147. STATE_TDM_ACTIVE, /* IS2 = sleep, TDM = active */
  148. };
  149. struct msm_pinctrl_info {
  150. struct pinctrl *pinctrl;
  151. struct pinctrl_state *mi2s_disable;
  152. struct pinctrl_state *tdm_disable;
  153. struct pinctrl_state *mi2s_active;
  154. struct pinctrl_state *tdm_active;
  155. enum pinctrl_pin_state curr_state;
  156. };
  157. struct msm_asoc_mach_data {
  158. u32 mclk_freq;
  159. int us_euro_gpio; /* used by gpio driver API */
  160. int usbc_en2_gpio; /* used by gpio driver API */
  161. struct device_node *us_euro_gpio_p; /* used by pinctrl API */
  162. struct pinctrl *usbc_en2_gpio_p; /* used by pinctrl API */
  163. struct device_node *hph_en1_gpio_p; /* used by pinctrl API */
  164. struct device_node *hph_en0_gpio_p; /* used by pinctrl API */
  165. struct snd_info_entry *codec_root;
  166. struct msm_pinctrl_info pinctrl_info;
  167. };
  168. struct msm_asoc_wcd93xx_codec {
  169. void* (*get_afe_config_fn)(struct snd_soc_codec *codec,
  170. enum afe_config_type config_type);
  171. void (*mbhc_hs_detect_exit)(struct snd_soc_codec *codec);
  172. };
  173. static const char *const pin_states[] = {"sleep", "i2s-active",
  174. "tdm-active"};
  175. enum {
  176. TDM_0 = 0,
  177. TDM_1,
  178. TDM_2,
  179. TDM_3,
  180. TDM_4,
  181. TDM_5,
  182. TDM_6,
  183. TDM_7,
  184. TDM_PORT_MAX,
  185. };
  186. enum {
  187. TDM_PRI = 0,
  188. TDM_SEC,
  189. TDM_TERT,
  190. TDM_QUAT,
  191. TDM_INTERFACE_MAX,
  192. };
  193. struct tdm_port {
  194. u32 mode;
  195. u32 channel;
  196. };
  197. /* TDM default config */
  198. static struct dev_config tdm_rx_cfg[TDM_INTERFACE_MAX][TDM_PORT_MAX] = {
  199. { /* PRI TDM */
  200. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_0 */
  201. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_1 */
  202. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_2 */
  203. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_3 */
  204. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_4 */
  205. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_5 */
  206. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_6 */
  207. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_7 */
  208. },
  209. { /* SEC TDM */
  210. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_0 */
  211. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_1 */
  212. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_2 */
  213. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_3 */
  214. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_4 */
  215. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_5 */
  216. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_6 */
  217. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_7 */
  218. },
  219. { /* TERT TDM */
  220. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_0 */
  221. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_1 */
  222. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_2 */
  223. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_3 */
  224. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_4 */
  225. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_5 */
  226. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_6 */
  227. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_7 */
  228. },
  229. { /* QUAT TDM */
  230. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_0 */
  231. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_1 */
  232. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_2 */
  233. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_3 */
  234. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_4 */
  235. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_5 */
  236. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_6 */
  237. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* RX_7 */
  238. }
  239. };
  240. /* TDM default config */
  241. static struct dev_config tdm_tx_cfg[TDM_INTERFACE_MAX][TDM_PORT_MAX] = {
  242. { /* PRI TDM */
  243. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_0 */
  244. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_1 */
  245. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_2 */
  246. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_3 */
  247. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_4 */
  248. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_5 */
  249. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_6 */
  250. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_7 */
  251. },
  252. { /* SEC TDM */
  253. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_0 */
  254. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_1 */
  255. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_2 */
  256. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_3 */
  257. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_4 */
  258. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_5 */
  259. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_6 */
  260. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_7 */
  261. },
  262. { /* TERT TDM */
  263. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_0 */
  264. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_1 */
  265. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_2 */
  266. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_3 */
  267. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_4 */
  268. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_5 */
  269. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_6 */
  270. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_7 */
  271. },
  272. { /* QUAT TDM */
  273. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_0 */
  274. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_1 */
  275. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_2 */
  276. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_3 */
  277. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_4 */
  278. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_5 */
  279. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_6 */
  280. {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1}, /* TX_7 */
  281. }
  282. };
  283. /* Default configuration of slimbus channels */
  284. static struct dev_config slim_rx_cfg[] = {
  285. [SLIM_RX_0] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  286. [SLIM_RX_1] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  287. [SLIM_RX_2] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  288. [SLIM_RX_3] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  289. [SLIM_RX_4] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  290. [SLIM_RX_5] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  291. [SLIM_RX_6] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  292. [SLIM_RX_7] = {SAMPLING_RATE_8KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  293. };
  294. static struct dev_config slim_tx_cfg[] = {
  295. [SLIM_TX_0] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  296. [SLIM_TX_1] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  297. [SLIM_TX_2] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  298. [SLIM_TX_3] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  299. [SLIM_TX_4] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  300. [SLIM_TX_5] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  301. [SLIM_TX_6] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  302. [SLIM_TX_7] = {SAMPLING_RATE_8KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  303. [SLIM_TX_8] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 2},
  304. };
  305. /* Default configuration of external display BE */
  306. static struct dev_config ext_disp_rx_cfg[] = {
  307. [DP_RX_IDX] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 2},
  308. };
  309. static struct dev_config usb_rx_cfg = {
  310. .sample_rate = SAMPLING_RATE_48KHZ,
  311. .bit_format = SNDRV_PCM_FORMAT_S16_LE,
  312. .channels = 2,
  313. };
  314. static struct dev_config usb_tx_cfg = {
  315. .sample_rate = SAMPLING_RATE_48KHZ,
  316. .bit_format = SNDRV_PCM_FORMAT_S16_LE,
  317. .channels = 1,
  318. };
  319. static struct dev_config proxy_rx_cfg = {
  320. .sample_rate = SAMPLING_RATE_48KHZ,
  321. .bit_format = SNDRV_PCM_FORMAT_S16_LE,
  322. .channels = 2,
  323. };
  324. /* Default configuration of MI2S channels */
  325. static struct dev_config mi2s_rx_cfg[] = {
  326. [PRIM_MI2S] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 2},
  327. [SEC_MI2S] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 2},
  328. [TERT_MI2S] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 2},
  329. [QUAT_MI2S] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 2},
  330. };
  331. static struct dev_config mi2s_tx_cfg[] = {
  332. [PRIM_MI2S] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  333. [SEC_MI2S] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  334. [TERT_MI2S] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  335. [QUAT_MI2S] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  336. };
  337. static struct dev_config aux_pcm_rx_cfg[] = {
  338. [PRIM_AUX_PCM] = {SAMPLING_RATE_8KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  339. [SEC_AUX_PCM] = {SAMPLING_RATE_8KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  340. [TERT_AUX_PCM] = {SAMPLING_RATE_8KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  341. [QUAT_AUX_PCM] = {SAMPLING_RATE_8KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  342. };
  343. static struct dev_config aux_pcm_tx_cfg[] = {
  344. [PRIM_AUX_PCM] = {SAMPLING_RATE_8KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  345. [SEC_AUX_PCM] = {SAMPLING_RATE_8KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  346. [TERT_AUX_PCM] = {SAMPLING_RATE_8KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  347. [QUAT_AUX_PCM] = {SAMPLING_RATE_8KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  348. };
  349. static int msm_vi_feed_tx_ch = 2;
  350. static const char *const slim_rx_ch_text[] = {"One", "Two"};
  351. static const char *const slim_tx_ch_text[] = {"One", "Two", "Three", "Four",
  352. "Five", "Six", "Seven",
  353. "Eight"};
  354. static const char *const vi_feed_ch_text[] = {"One", "Two"};
  355. static char const *bit_format_text[] = {"S16_LE", "S24_LE", "S24_3LE",
  356. "S32_LE"};
  357. static char const *ext_disp_bit_format_text[] = {"S16_LE", "S24_LE",
  358. "S24_3LE"};
  359. static char const *slim_sample_rate_text[] = {"KHZ_8", "KHZ_16",
  360. "KHZ_32", "KHZ_44P1", "KHZ_48",
  361. "KHZ_88P2", "KHZ_96", "KHZ_176P4",
  362. "KHZ_192", "KHZ_352P8", "KHZ_384"};
  363. static char const *bt_sample_rate_text[] = {"KHZ_8", "KHZ_16",
  364. "KHZ_44P1", "KHZ_48",
  365. "KHZ_88P2", "KHZ_96"};
  366. static const char *const usb_ch_text[] = {"One", "Two", "Three", "Four",
  367. "Five", "Six", "Seven",
  368. "Eight"};
  369. static char const *ch_text[] = {"Two", "Three", "Four", "Five",
  370. "Six", "Seven", "Eight"};
  371. static char const *usb_sample_rate_text[] = {"KHZ_8", "KHZ_11P025",
  372. "KHZ_16", "KHZ_22P05",
  373. "KHZ_32", "KHZ_44P1", "KHZ_48",
  374. "KHZ_88P2", "KHZ_96", "KHZ_176P4",
  375. "KHZ_192", "KHZ_352P8", "KHZ_384"};
  376. static char const *ext_disp_sample_rate_text[] = {"KHZ_48", "KHZ_96",
  377. "KHZ_192", "KHZ_32", "KHZ_44P1",
  378. "KHZ_88P2", "KHZ_176P4" };
  379. static char const *tdm_ch_text[] = {"One", "Two", "Three", "Four",
  380. "Five", "Six", "Seven", "Eight"};
  381. static char const *tdm_bit_format_text[] = {"S16_LE", "S24_LE", "S32_LE"};
  382. static char const *tdm_sample_rate_text[] = {"KHZ_8", "KHZ_16", "KHZ_32",
  383. "KHZ_48", "KHZ_176P4",
  384. "KHZ_352P8"};
  385. static const char *const auxpcm_rate_text[] = {"KHZ_8", "KHZ_16"};
  386. static char const *mi2s_rate_text[] = {"KHZ_8", "KHZ_11P025", "KHZ_16",
  387. "KHZ_22P05", "KHZ_32", "KHZ_44P1",
  388. "KHZ_48", "KHZ_96", "KHZ_192"};
  389. static const char *const mi2s_ch_text[] = {"One", "Two", "Three", "Four",
  390. "Five", "Six", "Seven",
  391. "Eight"};
  392. static const char *const hifi_text[] = {"Off", "On"};
  393. static const char *const qos_text[] = {"Disable", "Enable"};
  394. static SOC_ENUM_SINGLE_EXT_DECL(slim_0_rx_chs, slim_rx_ch_text);
  395. static SOC_ENUM_SINGLE_EXT_DECL(slim_2_rx_chs, slim_rx_ch_text);
  396. static SOC_ENUM_SINGLE_EXT_DECL(slim_0_tx_chs, slim_tx_ch_text);
  397. static SOC_ENUM_SINGLE_EXT_DECL(slim_1_tx_chs, slim_tx_ch_text);
  398. static SOC_ENUM_SINGLE_EXT_DECL(slim_5_rx_chs, slim_rx_ch_text);
  399. static SOC_ENUM_SINGLE_EXT_DECL(slim_6_rx_chs, slim_rx_ch_text);
  400. static SOC_ENUM_SINGLE_EXT_DECL(usb_rx_chs, usb_ch_text);
  401. static SOC_ENUM_SINGLE_EXT_DECL(usb_tx_chs, usb_ch_text);
  402. static SOC_ENUM_SINGLE_EXT_DECL(vi_feed_tx_chs, vi_feed_ch_text);
  403. static SOC_ENUM_SINGLE_EXT_DECL(ext_disp_rx_chs, ch_text);
  404. static SOC_ENUM_SINGLE_EXT_DECL(proxy_rx_chs, ch_text);
  405. static SOC_ENUM_SINGLE_EXT_DECL(slim_0_rx_format, bit_format_text);
  406. static SOC_ENUM_SINGLE_EXT_DECL(slim_5_rx_format, bit_format_text);
  407. static SOC_ENUM_SINGLE_EXT_DECL(slim_6_rx_format, bit_format_text);
  408. static SOC_ENUM_SINGLE_EXT_DECL(slim_0_tx_format, bit_format_text);
  409. static SOC_ENUM_SINGLE_EXT_DECL(usb_rx_format, bit_format_text);
  410. static SOC_ENUM_SINGLE_EXT_DECL(usb_tx_format, bit_format_text);
  411. static SOC_ENUM_SINGLE_EXT_DECL(ext_disp_rx_format, ext_disp_bit_format_text);
  412. static SOC_ENUM_SINGLE_EXT_DECL(slim_0_rx_sample_rate, slim_sample_rate_text);
  413. static SOC_ENUM_SINGLE_EXT_DECL(slim_2_rx_sample_rate, slim_sample_rate_text);
  414. static SOC_ENUM_SINGLE_EXT_DECL(slim_0_tx_sample_rate, slim_sample_rate_text);
  415. static SOC_ENUM_SINGLE_EXT_DECL(slim_5_rx_sample_rate, slim_sample_rate_text);
  416. static SOC_ENUM_SINGLE_EXT_DECL(slim_6_rx_sample_rate, slim_sample_rate_text);
  417. static SOC_ENUM_SINGLE_EXT_DECL(bt_sample_rate, bt_sample_rate_text);
  418. static SOC_ENUM_SINGLE_EXT_DECL(usb_rx_sample_rate, usb_sample_rate_text);
  419. static SOC_ENUM_SINGLE_EXT_DECL(usb_tx_sample_rate, usb_sample_rate_text);
  420. static SOC_ENUM_SINGLE_EXT_DECL(ext_disp_rx_sample_rate,
  421. ext_disp_sample_rate_text);
  422. static SOC_ENUM_SINGLE_EXT_DECL(tdm_tx_chs, tdm_ch_text);
  423. static SOC_ENUM_SINGLE_EXT_DECL(tdm_tx_format, tdm_bit_format_text);
  424. static SOC_ENUM_SINGLE_EXT_DECL(tdm_tx_sample_rate, tdm_sample_rate_text);
  425. static SOC_ENUM_SINGLE_EXT_DECL(tdm_rx_chs, tdm_ch_text);
  426. static SOC_ENUM_SINGLE_EXT_DECL(tdm_rx_format, tdm_bit_format_text);
  427. static SOC_ENUM_SINGLE_EXT_DECL(tdm_rx_sample_rate, tdm_sample_rate_text);
  428. static SOC_ENUM_SINGLE_EXT_DECL(prim_aux_pcm_rx_sample_rate, auxpcm_rate_text);
  429. static SOC_ENUM_SINGLE_EXT_DECL(sec_aux_pcm_rx_sample_rate, auxpcm_rate_text);
  430. static SOC_ENUM_SINGLE_EXT_DECL(tert_aux_pcm_rx_sample_rate, auxpcm_rate_text);
  431. static SOC_ENUM_SINGLE_EXT_DECL(quat_aux_pcm_rx_sample_rate, auxpcm_rate_text);
  432. static SOC_ENUM_SINGLE_EXT_DECL(prim_aux_pcm_tx_sample_rate, auxpcm_rate_text);
  433. static SOC_ENUM_SINGLE_EXT_DECL(sec_aux_pcm_tx_sample_rate, auxpcm_rate_text);
  434. static SOC_ENUM_SINGLE_EXT_DECL(tert_aux_pcm_tx_sample_rate, auxpcm_rate_text);
  435. static SOC_ENUM_SINGLE_EXT_DECL(quat_aux_pcm_tx_sample_rate, auxpcm_rate_text);
  436. static SOC_ENUM_SINGLE_EXT_DECL(prim_mi2s_rx_sample_rate, mi2s_rate_text);
  437. static SOC_ENUM_SINGLE_EXT_DECL(sec_mi2s_rx_sample_rate, mi2s_rate_text);
  438. static SOC_ENUM_SINGLE_EXT_DECL(tert_mi2s_rx_sample_rate, mi2s_rate_text);
  439. static SOC_ENUM_SINGLE_EXT_DECL(quat_mi2s_rx_sample_rate, mi2s_rate_text);
  440. static SOC_ENUM_SINGLE_EXT_DECL(prim_mi2s_tx_sample_rate, mi2s_rate_text);
  441. static SOC_ENUM_SINGLE_EXT_DECL(sec_mi2s_tx_sample_rate, mi2s_rate_text);
  442. static SOC_ENUM_SINGLE_EXT_DECL(tert_mi2s_tx_sample_rate, mi2s_rate_text);
  443. static SOC_ENUM_SINGLE_EXT_DECL(quat_mi2s_tx_sample_rate, mi2s_rate_text);
  444. static SOC_ENUM_SINGLE_EXT_DECL(prim_mi2s_rx_chs, mi2s_ch_text);
  445. static SOC_ENUM_SINGLE_EXT_DECL(prim_mi2s_tx_chs, mi2s_ch_text);
  446. static SOC_ENUM_SINGLE_EXT_DECL(sec_mi2s_rx_chs, mi2s_ch_text);
  447. static SOC_ENUM_SINGLE_EXT_DECL(sec_mi2s_tx_chs, mi2s_ch_text);
  448. static SOC_ENUM_SINGLE_EXT_DECL(tert_mi2s_rx_chs, mi2s_ch_text);
  449. static SOC_ENUM_SINGLE_EXT_DECL(tert_mi2s_tx_chs, mi2s_ch_text);
  450. static SOC_ENUM_SINGLE_EXT_DECL(quat_mi2s_rx_chs, mi2s_ch_text);
  451. static SOC_ENUM_SINGLE_EXT_DECL(quat_mi2s_tx_chs, mi2s_ch_text);
  452. static SOC_ENUM_SINGLE_EXT_DECL(mi2s_rx_format, bit_format_text);
  453. static SOC_ENUM_SINGLE_EXT_DECL(mi2s_tx_format, bit_format_text);
  454. static SOC_ENUM_SINGLE_EXT_DECL(aux_pcm_rx_format, bit_format_text);
  455. static SOC_ENUM_SINGLE_EXT_DECL(aux_pcm_tx_format, bit_format_text);
  456. static SOC_ENUM_SINGLE_EXT_DECL(hifi_function, hifi_text);
  457. static SOC_ENUM_SINGLE_EXT_DECL(qos_vote, qos_text);
  458. static struct platform_device *spdev;
  459. static int msm_hifi_control;
  460. static int qos_vote_status;
  461. static bool is_initial_boot;
  462. static bool codec_reg_done;
  463. static struct snd_soc_aux_dev *msm_aux_dev;
  464. static struct snd_soc_codec_conf *msm_codec_conf;
  465. static struct msm_asoc_wcd93xx_codec msm_codec_fn;
  466. static void *def_tavil_mbhc_cal(void);
  467. static int msm_snd_enable_codec_ext_clk(struct snd_soc_codec *codec,
  468. int enable, bool dapm);
  469. static int msm_wsa881x_init(struct snd_soc_component *component);
  470. /*
  471. * Need to report LINEIN
  472. * if R/L channel impedance is larger than 5K ohm
  473. */
  474. static struct wcd_mbhc_config wcd_mbhc_cfg = {
  475. .read_fw_bin = false,
  476. .calibration = NULL,
  477. .detect_extn_cable = true,
  478. .mono_stero_detection = false,
  479. .swap_gnd_mic = NULL,
  480. .hs_ext_micbias = true,
  481. .key_code[0] = KEY_MEDIA,
  482. .key_code[1] = KEY_VOICECOMMAND,
  483. .key_code[2] = KEY_VOLUMEUP,
  484. .key_code[3] = KEY_VOLUMEDOWN,
  485. .key_code[4] = 0,
  486. .key_code[5] = 0,
  487. .key_code[6] = 0,
  488. .key_code[7] = 0,
  489. .linein_th = 5000,
  490. .moisture_en = true,
  491. .mbhc_micbias = MIC_BIAS_2,
  492. .anc_micbias = MIC_BIAS_2,
  493. .enable_anc_mic_detect = false,
  494. };
  495. static struct snd_soc_dapm_route wcd_audio_paths[] = {
  496. {"MIC BIAS1", NULL, "MCLK TX"},
  497. {"MIC BIAS2", NULL, "MCLK TX"},
  498. {"MIC BIAS3", NULL, "MCLK TX"},
  499. {"MIC BIAS4", NULL, "MCLK TX"},
  500. };
  501. static struct afe_clk_set mi2s_clk[MI2S_MAX] = {
  502. {
  503. AFE_API_VERSION_I2S_CONFIG,
  504. Q6AFE_LPASS_CLK_ID_PRI_MI2S_IBIT,
  505. Q6AFE_LPASS_IBIT_CLK_1_P536_MHZ,
  506. Q6AFE_LPASS_CLK_ATTRIBUTE_COUPLE_NO,
  507. Q6AFE_LPASS_CLK_ROOT_DEFAULT,
  508. 0,
  509. },
  510. {
  511. AFE_API_VERSION_I2S_CONFIG,
  512. Q6AFE_LPASS_CLK_ID_SEC_MI2S_IBIT,
  513. Q6AFE_LPASS_IBIT_CLK_1_P536_MHZ,
  514. Q6AFE_LPASS_CLK_ATTRIBUTE_COUPLE_NO,
  515. Q6AFE_LPASS_CLK_ROOT_DEFAULT,
  516. 0,
  517. },
  518. {
  519. AFE_API_VERSION_I2S_CONFIG,
  520. Q6AFE_LPASS_CLK_ID_TER_MI2S_IBIT,
  521. Q6AFE_LPASS_IBIT_CLK_1_P536_MHZ,
  522. Q6AFE_LPASS_CLK_ATTRIBUTE_COUPLE_NO,
  523. Q6AFE_LPASS_CLK_ROOT_DEFAULT,
  524. 0,
  525. },
  526. {
  527. AFE_API_VERSION_I2S_CONFIG,
  528. Q6AFE_LPASS_CLK_ID_QUAD_MI2S_IBIT,
  529. Q6AFE_LPASS_IBIT_CLK_1_P536_MHZ,
  530. Q6AFE_LPASS_CLK_ATTRIBUTE_COUPLE_NO,
  531. Q6AFE_LPASS_CLK_ROOT_DEFAULT,
  532. 0,
  533. }
  534. };
  535. static struct mi2s_aux_pcm_common_conf mi2s_auxpcm_conf[PCM_I2S_SEL_MAX];
  536. static struct mi2s_conf mi2s_intf_conf[MI2S_MAX];
  537. static struct auxpcm_conf auxpcm_intf_conf[AUX_PCM_MAX];
  538. static int slim_get_sample_rate_val(int sample_rate)
  539. {
  540. int sample_rate_val = 0;
  541. switch (sample_rate) {
  542. case SAMPLING_RATE_8KHZ:
  543. sample_rate_val = 0;
  544. break;
  545. case SAMPLING_RATE_16KHZ:
  546. sample_rate_val = 1;
  547. break;
  548. case SAMPLING_RATE_32KHZ:
  549. sample_rate_val = 2;
  550. break;
  551. case SAMPLING_RATE_44P1KHZ:
  552. sample_rate_val = 3;
  553. break;
  554. case SAMPLING_RATE_48KHZ:
  555. sample_rate_val = 4;
  556. break;
  557. case SAMPLING_RATE_88P2KHZ:
  558. sample_rate_val = 5;
  559. break;
  560. case SAMPLING_RATE_96KHZ:
  561. sample_rate_val = 6;
  562. break;
  563. case SAMPLING_RATE_176P4KHZ:
  564. sample_rate_val = 7;
  565. break;
  566. case SAMPLING_RATE_192KHZ:
  567. sample_rate_val = 8;
  568. break;
  569. case SAMPLING_RATE_352P8KHZ:
  570. sample_rate_val = 9;
  571. break;
  572. case SAMPLING_RATE_384KHZ:
  573. sample_rate_val = 10;
  574. break;
  575. default:
  576. sample_rate_val = 4;
  577. break;
  578. }
  579. return sample_rate_val;
  580. }
  581. static int slim_get_sample_rate(int value)
  582. {
  583. int sample_rate = 0;
  584. switch (value) {
  585. case 0:
  586. sample_rate = SAMPLING_RATE_8KHZ;
  587. break;
  588. case 1:
  589. sample_rate = SAMPLING_RATE_16KHZ;
  590. break;
  591. case 2:
  592. sample_rate = SAMPLING_RATE_32KHZ;
  593. break;
  594. case 3:
  595. sample_rate = SAMPLING_RATE_44P1KHZ;
  596. break;
  597. case 4:
  598. sample_rate = SAMPLING_RATE_48KHZ;
  599. break;
  600. case 5:
  601. sample_rate = SAMPLING_RATE_88P2KHZ;
  602. break;
  603. case 6:
  604. sample_rate = SAMPLING_RATE_96KHZ;
  605. break;
  606. case 7:
  607. sample_rate = SAMPLING_RATE_176P4KHZ;
  608. break;
  609. case 8:
  610. sample_rate = SAMPLING_RATE_192KHZ;
  611. break;
  612. case 9:
  613. sample_rate = SAMPLING_RATE_352P8KHZ;
  614. break;
  615. case 10:
  616. sample_rate = SAMPLING_RATE_384KHZ;
  617. break;
  618. default:
  619. sample_rate = SAMPLING_RATE_48KHZ;
  620. break;
  621. }
  622. return sample_rate;
  623. }
  624. static int slim_get_bit_format_val(int bit_format)
  625. {
  626. int val = 0;
  627. switch (bit_format) {
  628. case SNDRV_PCM_FORMAT_S32_LE:
  629. val = 3;
  630. break;
  631. case SNDRV_PCM_FORMAT_S24_3LE:
  632. val = 2;
  633. break;
  634. case SNDRV_PCM_FORMAT_S24_LE:
  635. val = 1;
  636. break;
  637. case SNDRV_PCM_FORMAT_S16_LE:
  638. default:
  639. val = 0;
  640. break;
  641. }
  642. return val;
  643. }
  644. static int slim_get_bit_format(int val)
  645. {
  646. int bit_fmt = SNDRV_PCM_FORMAT_S16_LE;
  647. switch (val) {
  648. case 0:
  649. bit_fmt = SNDRV_PCM_FORMAT_S16_LE;
  650. break;
  651. case 1:
  652. bit_fmt = SNDRV_PCM_FORMAT_S24_LE;
  653. break;
  654. case 2:
  655. bit_fmt = SNDRV_PCM_FORMAT_S24_3LE;
  656. break;
  657. case 3:
  658. bit_fmt = SNDRV_PCM_FORMAT_S32_LE;
  659. break;
  660. default:
  661. bit_fmt = SNDRV_PCM_FORMAT_S16_LE;
  662. break;
  663. }
  664. return bit_fmt;
  665. }
  666. static int slim_get_port_idx(struct snd_kcontrol *kcontrol)
  667. {
  668. int port_id = 0;
  669. if (strnstr(kcontrol->id.name, "SLIM_0_RX", sizeof("SLIM_0_RX")))
  670. port_id = SLIM_RX_0;
  671. else if (strnstr(kcontrol->id.name, "SLIM_2_RX", sizeof("SLIM_2_RX")))
  672. port_id = SLIM_RX_2;
  673. else if (strnstr(kcontrol->id.name, "SLIM_5_RX", sizeof("SLIM_5_RX")))
  674. port_id = SLIM_RX_5;
  675. else if (strnstr(kcontrol->id.name, "SLIM_6_RX", sizeof("SLIM_6_RX")))
  676. port_id = SLIM_RX_6;
  677. else if (strnstr(kcontrol->id.name, "SLIM_0_TX", sizeof("SLIM_0_TX")))
  678. port_id = SLIM_TX_0;
  679. else if (strnstr(kcontrol->id.name, "SLIM_1_TX", sizeof("SLIM_1_TX")))
  680. port_id = SLIM_TX_1;
  681. else {
  682. pr_err("%s: unsupported channel: %s",
  683. __func__, kcontrol->id.name);
  684. return -EINVAL;
  685. }
  686. return port_id;
  687. }
  688. static int slim_rx_sample_rate_get(struct snd_kcontrol *kcontrol,
  689. struct snd_ctl_elem_value *ucontrol)
  690. {
  691. int ch_num = slim_get_port_idx(kcontrol);
  692. if (ch_num < 0)
  693. return ch_num;
  694. ucontrol->value.enumerated.item[0] =
  695. slim_get_sample_rate_val(slim_rx_cfg[ch_num].sample_rate);
  696. pr_debug("%s: slim[%d]_rx_sample_rate = %d, item = %d\n", __func__,
  697. ch_num, slim_rx_cfg[ch_num].sample_rate,
  698. ucontrol->value.enumerated.item[0]);
  699. return 0;
  700. }
  701. static int slim_rx_sample_rate_put(struct snd_kcontrol *kcontrol,
  702. struct snd_ctl_elem_value *ucontrol)
  703. {
  704. int ch_num = slim_get_port_idx(kcontrol);
  705. if (ch_num < 0)
  706. return ch_num;
  707. slim_rx_cfg[ch_num].sample_rate =
  708. slim_get_sample_rate(ucontrol->value.enumerated.item[0]);
  709. pr_debug("%s: slim[%d]_rx_sample_rate = %d, item = %d\n", __func__,
  710. ch_num, slim_rx_cfg[ch_num].sample_rate,
  711. ucontrol->value.enumerated.item[0]);
  712. return 0;
  713. }
  714. static int slim_tx_sample_rate_get(struct snd_kcontrol *kcontrol,
  715. struct snd_ctl_elem_value *ucontrol)
  716. {
  717. int ch_num = slim_get_port_idx(kcontrol);
  718. if (ch_num < 0)
  719. return ch_num;
  720. ucontrol->value.enumerated.item[0] =
  721. slim_get_sample_rate_val(slim_tx_cfg[ch_num].sample_rate);
  722. pr_debug("%s: slim[%d]_tx_sample_rate = %d, item = %d\n", __func__,
  723. ch_num, slim_tx_cfg[ch_num].sample_rate,
  724. ucontrol->value.enumerated.item[0]);
  725. return 0;
  726. }
  727. static int slim_tx_sample_rate_put(struct snd_kcontrol *kcontrol,
  728. struct snd_ctl_elem_value *ucontrol)
  729. {
  730. int sample_rate = 0;
  731. int ch_num = slim_get_port_idx(kcontrol);
  732. if (ch_num < 0)
  733. return ch_num;
  734. sample_rate = slim_get_sample_rate(ucontrol->value.enumerated.item[0]);
  735. if (sample_rate == SAMPLING_RATE_44P1KHZ) {
  736. pr_err("%s: Unsupported sample rate %d: for Tx path\n",
  737. __func__, sample_rate);
  738. return -EINVAL;
  739. }
  740. slim_tx_cfg[ch_num].sample_rate = sample_rate;
  741. pr_debug("%s: slim[%d]_tx_sample_rate = %d, value = %d\n", __func__,
  742. ch_num, slim_tx_cfg[ch_num].sample_rate,
  743. ucontrol->value.enumerated.item[0]);
  744. return 0;
  745. }
  746. static int slim_rx_bit_format_get(struct snd_kcontrol *kcontrol,
  747. struct snd_ctl_elem_value *ucontrol)
  748. {
  749. int ch_num = slim_get_port_idx(kcontrol);
  750. if (ch_num < 0)
  751. return ch_num;
  752. ucontrol->value.enumerated.item[0] =
  753. slim_get_bit_format_val(slim_rx_cfg[ch_num].bit_format);
  754. pr_debug("%s: slim[%d]_rx_bit_format = %d, ucontrol value = %d\n",
  755. __func__, ch_num, slim_rx_cfg[ch_num].bit_format,
  756. ucontrol->value.enumerated.item[0]);
  757. return 0;
  758. }
  759. static int slim_rx_bit_format_put(struct snd_kcontrol *kcontrol,
  760. struct snd_ctl_elem_value *ucontrol)
  761. {
  762. int ch_num = slim_get_port_idx(kcontrol);
  763. if (ch_num < 0)
  764. return ch_num;
  765. slim_rx_cfg[ch_num].bit_format =
  766. slim_get_bit_format(ucontrol->value.enumerated.item[0]);
  767. pr_debug("%s: slim[%d]_rx_bit_format = %d, ucontrol value = %d\n",
  768. __func__, ch_num, slim_rx_cfg[ch_num].bit_format,
  769. ucontrol->value.enumerated.item[0]);
  770. return 0;
  771. }
  772. static int slim_tx_bit_format_get(struct snd_kcontrol *kcontrol,
  773. struct snd_ctl_elem_value *ucontrol)
  774. {
  775. int ch_num = slim_get_port_idx(kcontrol);
  776. if (ch_num < 0)
  777. return ch_num;
  778. ucontrol->value.enumerated.item[0] =
  779. slim_get_bit_format_val(slim_tx_cfg[ch_num].bit_format);
  780. pr_debug("%s: slim[%d]_tx_bit_format = %d, ucontrol value = %d\n",
  781. __func__, ch_num, slim_tx_cfg[ch_num].bit_format,
  782. ucontrol->value.enumerated.item[0]);
  783. return 0;
  784. }
  785. static int slim_tx_bit_format_put(struct snd_kcontrol *kcontrol,
  786. struct snd_ctl_elem_value *ucontrol)
  787. {
  788. int ch_num = slim_get_port_idx(kcontrol);
  789. if (ch_num < 0)
  790. return ch_num;
  791. slim_tx_cfg[ch_num].bit_format =
  792. slim_get_bit_format(ucontrol->value.enumerated.item[0]);
  793. pr_debug("%s: slim[%d]_tx_bit_format = %d, ucontrol value = %d\n",
  794. __func__, ch_num, slim_tx_cfg[ch_num].bit_format,
  795. ucontrol->value.enumerated.item[0]);
  796. return 0;
  797. }
  798. static int msm_slim_rx_ch_get(struct snd_kcontrol *kcontrol,
  799. struct snd_ctl_elem_value *ucontrol)
  800. {
  801. int ch_num = slim_get_port_idx(kcontrol);
  802. if (ch_num < 0)
  803. return ch_num;
  804. pr_debug("%s: msm_slim_[%d]_rx_ch = %d\n", __func__,
  805. ch_num, slim_rx_cfg[ch_num].channels);
  806. ucontrol->value.enumerated.item[0] = slim_rx_cfg[ch_num].channels - 1;
  807. return 0;
  808. }
  809. static int msm_slim_rx_ch_put(struct snd_kcontrol *kcontrol,
  810. struct snd_ctl_elem_value *ucontrol)
  811. {
  812. int ch_num = slim_get_port_idx(kcontrol);
  813. if (ch_num < 0)
  814. return ch_num;
  815. slim_rx_cfg[ch_num].channels = ucontrol->value.enumerated.item[0] + 1;
  816. pr_debug("%s: msm_slim_[%d]_rx_ch = %d\n", __func__,
  817. ch_num, slim_rx_cfg[ch_num].channels);
  818. return 1;
  819. }
  820. static int msm_slim_tx_ch_get(struct snd_kcontrol *kcontrol,
  821. struct snd_ctl_elem_value *ucontrol)
  822. {
  823. int ch_num = slim_get_port_idx(kcontrol);
  824. if (ch_num < 0)
  825. return ch_num;
  826. pr_debug("%s: msm_slim_[%d]_tx_ch = %d\n", __func__,
  827. ch_num, slim_tx_cfg[ch_num].channels);
  828. ucontrol->value.enumerated.item[0] = slim_tx_cfg[ch_num].channels - 1;
  829. return 0;
  830. }
  831. static int msm_slim_tx_ch_put(struct snd_kcontrol *kcontrol,
  832. struct snd_ctl_elem_value *ucontrol)
  833. {
  834. int ch_num = slim_get_port_idx(kcontrol);
  835. if (ch_num < 0)
  836. return ch_num;
  837. slim_tx_cfg[ch_num].channels = ucontrol->value.enumerated.item[0] + 1;
  838. pr_debug("%s: msm_slim_[%d]_tx_ch = %d\n", __func__,
  839. ch_num, slim_tx_cfg[ch_num].channels);
  840. return 1;
  841. }
  842. static int msm_vi_feed_tx_ch_get(struct snd_kcontrol *kcontrol,
  843. struct snd_ctl_elem_value *ucontrol)
  844. {
  845. ucontrol->value.integer.value[0] = msm_vi_feed_tx_ch - 1;
  846. pr_debug("%s: msm_vi_feed_tx_ch = %ld\n", __func__,
  847. ucontrol->value.integer.value[0]);
  848. return 0;
  849. }
  850. static int msm_vi_feed_tx_ch_put(struct snd_kcontrol *kcontrol,
  851. struct snd_ctl_elem_value *ucontrol)
  852. {
  853. msm_vi_feed_tx_ch = ucontrol->value.integer.value[0] + 1;
  854. pr_debug("%s: msm_vi_feed_tx_ch = %d\n", __func__, msm_vi_feed_tx_ch);
  855. return 1;
  856. }
  857. static int msm_bt_sample_rate_get(struct snd_kcontrol *kcontrol,
  858. struct snd_ctl_elem_value *ucontrol)
  859. {
  860. /*
  861. * Slimbus_7_Rx/Tx sample rate values should always be in sync (same)
  862. * when used for BT_SCO use case. Return either Rx or Tx sample rate
  863. * value.
  864. */
  865. switch (slim_rx_cfg[SLIM_RX_7].sample_rate) {
  866. case SAMPLING_RATE_96KHZ:
  867. ucontrol->value.integer.value[0] = 5;
  868. break;
  869. case SAMPLING_RATE_88P2KHZ:
  870. ucontrol->value.integer.value[0] = 4;
  871. break;
  872. case SAMPLING_RATE_48KHZ:
  873. ucontrol->value.integer.value[0] = 3;
  874. break;
  875. case SAMPLING_RATE_44P1KHZ:
  876. ucontrol->value.integer.value[0] = 2;
  877. break;
  878. case SAMPLING_RATE_16KHZ:
  879. ucontrol->value.integer.value[0] = 1;
  880. break;
  881. case SAMPLING_RATE_8KHZ:
  882. default:
  883. ucontrol->value.integer.value[0] = 0;
  884. break;
  885. }
  886. pr_debug("%s: sample rate = %d", __func__,
  887. slim_rx_cfg[SLIM_RX_7].sample_rate);
  888. return 0;
  889. }
  890. static int msm_bt_sample_rate_put(struct snd_kcontrol *kcontrol,
  891. struct snd_ctl_elem_value *ucontrol)
  892. {
  893. switch (ucontrol->value.integer.value[0]) {
  894. case 1:
  895. slim_rx_cfg[SLIM_RX_7].sample_rate = SAMPLING_RATE_16KHZ;
  896. slim_tx_cfg[SLIM_TX_7].sample_rate = SAMPLING_RATE_16KHZ;
  897. break;
  898. case 2:
  899. slim_rx_cfg[SLIM_RX_7].sample_rate = SAMPLING_RATE_44P1KHZ;
  900. slim_tx_cfg[SLIM_TX_7].sample_rate = SAMPLING_RATE_44P1KHZ;
  901. break;
  902. case 3:
  903. slim_rx_cfg[SLIM_RX_7].sample_rate = SAMPLING_RATE_48KHZ;
  904. slim_tx_cfg[SLIM_TX_7].sample_rate = SAMPLING_RATE_48KHZ;
  905. break;
  906. case 4:
  907. slim_rx_cfg[SLIM_RX_7].sample_rate = SAMPLING_RATE_88P2KHZ;
  908. slim_tx_cfg[SLIM_TX_7].sample_rate = SAMPLING_RATE_88P2KHZ;
  909. break;
  910. case 5:
  911. slim_rx_cfg[SLIM_RX_7].sample_rate = SAMPLING_RATE_96KHZ;
  912. slim_tx_cfg[SLIM_TX_7].sample_rate = SAMPLING_RATE_96KHZ;
  913. break;
  914. case 0:
  915. default:
  916. slim_rx_cfg[SLIM_RX_7].sample_rate = SAMPLING_RATE_8KHZ;
  917. slim_tx_cfg[SLIM_TX_7].sample_rate = SAMPLING_RATE_8KHZ;
  918. break;
  919. }
  920. pr_debug("%s: sample rates: slim7_rx = %d, slim7_tx = %d, value = %d\n",
  921. __func__,
  922. slim_rx_cfg[SLIM_RX_7].sample_rate,
  923. slim_tx_cfg[SLIM_TX_7].sample_rate,
  924. ucontrol->value.enumerated.item[0]);
  925. return 0;
  926. }
  927. static int usb_audio_rx_ch_get(struct snd_kcontrol *kcontrol,
  928. struct snd_ctl_elem_value *ucontrol)
  929. {
  930. pr_debug("%s: usb_audio_rx_ch = %d\n", __func__,
  931. usb_rx_cfg.channels);
  932. ucontrol->value.integer.value[0] = usb_rx_cfg.channels - 1;
  933. return 0;
  934. }
  935. static int usb_audio_rx_ch_put(struct snd_kcontrol *kcontrol,
  936. struct snd_ctl_elem_value *ucontrol)
  937. {
  938. usb_rx_cfg.channels = ucontrol->value.integer.value[0] + 1;
  939. pr_debug("%s: usb_audio_rx_ch = %d\n", __func__, usb_rx_cfg.channels);
  940. return 1;
  941. }
  942. static int usb_audio_rx_sample_rate_get(struct snd_kcontrol *kcontrol,
  943. struct snd_ctl_elem_value *ucontrol)
  944. {
  945. int sample_rate_val;
  946. switch (usb_rx_cfg.sample_rate) {
  947. case SAMPLING_RATE_384KHZ:
  948. sample_rate_val = 12;
  949. break;
  950. case SAMPLING_RATE_352P8KHZ:
  951. sample_rate_val = 11;
  952. break;
  953. case SAMPLING_RATE_192KHZ:
  954. sample_rate_val = 10;
  955. break;
  956. case SAMPLING_RATE_176P4KHZ:
  957. sample_rate_val = 9;
  958. break;
  959. case SAMPLING_RATE_96KHZ:
  960. sample_rate_val = 8;
  961. break;
  962. case SAMPLING_RATE_88P2KHZ:
  963. sample_rate_val = 7;
  964. break;
  965. case SAMPLING_RATE_48KHZ:
  966. sample_rate_val = 6;
  967. break;
  968. case SAMPLING_RATE_44P1KHZ:
  969. sample_rate_val = 5;
  970. break;
  971. case SAMPLING_RATE_32KHZ:
  972. sample_rate_val = 4;
  973. break;
  974. case SAMPLING_RATE_22P05KHZ:
  975. sample_rate_val = 3;
  976. break;
  977. case SAMPLING_RATE_16KHZ:
  978. sample_rate_val = 2;
  979. break;
  980. case SAMPLING_RATE_11P025KHZ:
  981. sample_rate_val = 1;
  982. break;
  983. case SAMPLING_RATE_8KHZ:
  984. default:
  985. sample_rate_val = 0;
  986. break;
  987. }
  988. ucontrol->value.integer.value[0] = sample_rate_val;
  989. pr_debug("%s: usb_audio_rx_sample_rate = %d\n", __func__,
  990. usb_rx_cfg.sample_rate);
  991. return 0;
  992. }
  993. static int usb_audio_rx_sample_rate_put(struct snd_kcontrol *kcontrol,
  994. struct snd_ctl_elem_value *ucontrol)
  995. {
  996. switch (ucontrol->value.integer.value[0]) {
  997. case 12:
  998. usb_rx_cfg.sample_rate = SAMPLING_RATE_384KHZ;
  999. break;
  1000. case 11:
  1001. usb_rx_cfg.sample_rate = SAMPLING_RATE_352P8KHZ;
  1002. break;
  1003. case 10:
  1004. usb_rx_cfg.sample_rate = SAMPLING_RATE_192KHZ;
  1005. break;
  1006. case 9:
  1007. usb_rx_cfg.sample_rate = SAMPLING_RATE_176P4KHZ;
  1008. break;
  1009. case 8:
  1010. usb_rx_cfg.sample_rate = SAMPLING_RATE_96KHZ;
  1011. break;
  1012. case 7:
  1013. usb_rx_cfg.sample_rate = SAMPLING_RATE_88P2KHZ;
  1014. break;
  1015. case 6:
  1016. usb_rx_cfg.sample_rate = SAMPLING_RATE_48KHZ;
  1017. break;
  1018. case 5:
  1019. usb_rx_cfg.sample_rate = SAMPLING_RATE_44P1KHZ;
  1020. break;
  1021. case 4:
  1022. usb_rx_cfg.sample_rate = SAMPLING_RATE_32KHZ;
  1023. break;
  1024. case 3:
  1025. usb_rx_cfg.sample_rate = SAMPLING_RATE_22P05KHZ;
  1026. break;
  1027. case 2:
  1028. usb_rx_cfg.sample_rate = SAMPLING_RATE_16KHZ;
  1029. break;
  1030. case 1:
  1031. usb_rx_cfg.sample_rate = SAMPLING_RATE_11P025KHZ;
  1032. break;
  1033. case 0:
  1034. usb_rx_cfg.sample_rate = SAMPLING_RATE_8KHZ;
  1035. break;
  1036. default:
  1037. usb_rx_cfg.sample_rate = SAMPLING_RATE_48KHZ;
  1038. break;
  1039. }
  1040. pr_debug("%s: control value = %ld, usb_audio_rx_sample_rate = %d\n",
  1041. __func__, ucontrol->value.integer.value[0],
  1042. usb_rx_cfg.sample_rate);
  1043. return 0;
  1044. }
  1045. static int usb_audio_rx_format_get(struct snd_kcontrol *kcontrol,
  1046. struct snd_ctl_elem_value *ucontrol)
  1047. {
  1048. switch (usb_rx_cfg.bit_format) {
  1049. case SNDRV_PCM_FORMAT_S32_LE:
  1050. ucontrol->value.integer.value[0] = 3;
  1051. break;
  1052. case SNDRV_PCM_FORMAT_S24_3LE:
  1053. ucontrol->value.integer.value[0] = 2;
  1054. break;
  1055. case SNDRV_PCM_FORMAT_S24_LE:
  1056. ucontrol->value.integer.value[0] = 1;
  1057. break;
  1058. case SNDRV_PCM_FORMAT_S16_LE:
  1059. default:
  1060. ucontrol->value.integer.value[0] = 0;
  1061. break;
  1062. }
  1063. pr_debug("%s: usb_audio_rx_format = %d, ucontrol value = %ld\n",
  1064. __func__, usb_rx_cfg.bit_format,
  1065. ucontrol->value.integer.value[0]);
  1066. return 0;
  1067. }
  1068. static int usb_audio_rx_format_put(struct snd_kcontrol *kcontrol,
  1069. struct snd_ctl_elem_value *ucontrol)
  1070. {
  1071. int rc = 0;
  1072. switch (ucontrol->value.integer.value[0]) {
  1073. case 3:
  1074. usb_rx_cfg.bit_format = SNDRV_PCM_FORMAT_S32_LE;
  1075. break;
  1076. case 2:
  1077. usb_rx_cfg.bit_format = SNDRV_PCM_FORMAT_S24_3LE;
  1078. break;
  1079. case 1:
  1080. usb_rx_cfg.bit_format = SNDRV_PCM_FORMAT_S24_LE;
  1081. break;
  1082. case 0:
  1083. default:
  1084. usb_rx_cfg.bit_format = SNDRV_PCM_FORMAT_S16_LE;
  1085. break;
  1086. }
  1087. pr_debug("%s: usb_audio_rx_format = %d, ucontrol value = %ld\n",
  1088. __func__, usb_rx_cfg.bit_format,
  1089. ucontrol->value.integer.value[0]);
  1090. return rc;
  1091. }
  1092. static int usb_audio_tx_ch_get(struct snd_kcontrol *kcontrol,
  1093. struct snd_ctl_elem_value *ucontrol)
  1094. {
  1095. pr_debug("%s: usb_audio_tx_ch = %d\n", __func__,
  1096. usb_tx_cfg.channels);
  1097. ucontrol->value.integer.value[0] = usb_tx_cfg.channels - 1;
  1098. return 0;
  1099. }
  1100. static int usb_audio_tx_ch_put(struct snd_kcontrol *kcontrol,
  1101. struct snd_ctl_elem_value *ucontrol)
  1102. {
  1103. usb_tx_cfg.channels = ucontrol->value.integer.value[0] + 1;
  1104. pr_debug("%s: usb_audio_tx_ch = %d\n", __func__, usb_tx_cfg.channels);
  1105. return 1;
  1106. }
  1107. static int usb_audio_tx_sample_rate_get(struct snd_kcontrol *kcontrol,
  1108. struct snd_ctl_elem_value *ucontrol)
  1109. {
  1110. int sample_rate_val;
  1111. switch (usb_tx_cfg.sample_rate) {
  1112. case SAMPLING_RATE_384KHZ:
  1113. sample_rate_val = 12;
  1114. break;
  1115. case SAMPLING_RATE_352P8KHZ:
  1116. sample_rate_val = 11;
  1117. break;
  1118. case SAMPLING_RATE_192KHZ:
  1119. sample_rate_val = 10;
  1120. break;
  1121. case SAMPLING_RATE_176P4KHZ:
  1122. sample_rate_val = 9;
  1123. break;
  1124. case SAMPLING_RATE_96KHZ:
  1125. sample_rate_val = 8;
  1126. break;
  1127. case SAMPLING_RATE_88P2KHZ:
  1128. sample_rate_val = 7;
  1129. break;
  1130. case SAMPLING_RATE_48KHZ:
  1131. sample_rate_val = 6;
  1132. break;
  1133. case SAMPLING_RATE_44P1KHZ:
  1134. sample_rate_val = 5;
  1135. break;
  1136. case SAMPLING_RATE_32KHZ:
  1137. sample_rate_val = 4;
  1138. break;
  1139. case SAMPLING_RATE_22P05KHZ:
  1140. sample_rate_val = 3;
  1141. break;
  1142. case SAMPLING_RATE_16KHZ:
  1143. sample_rate_val = 2;
  1144. break;
  1145. case SAMPLING_RATE_11P025KHZ:
  1146. sample_rate_val = 1;
  1147. break;
  1148. case SAMPLING_RATE_8KHZ:
  1149. sample_rate_val = 0;
  1150. break;
  1151. default:
  1152. sample_rate_val = 6;
  1153. break;
  1154. }
  1155. ucontrol->value.integer.value[0] = sample_rate_val;
  1156. pr_debug("%s: usb_audio_tx_sample_rate = %d\n", __func__,
  1157. usb_tx_cfg.sample_rate);
  1158. return 0;
  1159. }
  1160. static int usb_audio_tx_sample_rate_put(struct snd_kcontrol *kcontrol,
  1161. struct snd_ctl_elem_value *ucontrol)
  1162. {
  1163. switch (ucontrol->value.integer.value[0]) {
  1164. case 12:
  1165. usb_tx_cfg.sample_rate = SAMPLING_RATE_384KHZ;
  1166. break;
  1167. case 11:
  1168. usb_tx_cfg.sample_rate = SAMPLING_RATE_352P8KHZ;
  1169. break;
  1170. case 10:
  1171. usb_tx_cfg.sample_rate = SAMPLING_RATE_192KHZ;
  1172. break;
  1173. case 9:
  1174. usb_tx_cfg.sample_rate = SAMPLING_RATE_176P4KHZ;
  1175. break;
  1176. case 8:
  1177. usb_tx_cfg.sample_rate = SAMPLING_RATE_96KHZ;
  1178. break;
  1179. case 7:
  1180. usb_tx_cfg.sample_rate = SAMPLING_RATE_88P2KHZ;
  1181. break;
  1182. case 6:
  1183. usb_tx_cfg.sample_rate = SAMPLING_RATE_48KHZ;
  1184. break;
  1185. case 5:
  1186. usb_tx_cfg.sample_rate = SAMPLING_RATE_44P1KHZ;
  1187. break;
  1188. case 4:
  1189. usb_tx_cfg.sample_rate = SAMPLING_RATE_32KHZ;
  1190. break;
  1191. case 3:
  1192. usb_tx_cfg.sample_rate = SAMPLING_RATE_22P05KHZ;
  1193. break;
  1194. case 2:
  1195. usb_tx_cfg.sample_rate = SAMPLING_RATE_16KHZ;
  1196. break;
  1197. case 1:
  1198. usb_tx_cfg.sample_rate = SAMPLING_RATE_11P025KHZ;
  1199. break;
  1200. case 0:
  1201. usb_tx_cfg.sample_rate = SAMPLING_RATE_8KHZ;
  1202. break;
  1203. default:
  1204. usb_tx_cfg.sample_rate = SAMPLING_RATE_48KHZ;
  1205. break;
  1206. }
  1207. pr_debug("%s: control value = %ld, usb_audio_tx_sample_rate = %d\n",
  1208. __func__, ucontrol->value.integer.value[0],
  1209. usb_tx_cfg.sample_rate);
  1210. return 0;
  1211. }
  1212. static int usb_audio_tx_format_get(struct snd_kcontrol *kcontrol,
  1213. struct snd_ctl_elem_value *ucontrol)
  1214. {
  1215. switch (usb_tx_cfg.bit_format) {
  1216. case SNDRV_PCM_FORMAT_S32_LE:
  1217. ucontrol->value.integer.value[0] = 3;
  1218. break;
  1219. case SNDRV_PCM_FORMAT_S24_3LE:
  1220. ucontrol->value.integer.value[0] = 2;
  1221. break;
  1222. case SNDRV_PCM_FORMAT_S24_LE:
  1223. ucontrol->value.integer.value[0] = 1;
  1224. break;
  1225. case SNDRV_PCM_FORMAT_S16_LE:
  1226. default:
  1227. ucontrol->value.integer.value[0] = 0;
  1228. break;
  1229. }
  1230. pr_debug("%s: usb_audio_tx_format = %d, ucontrol value = %ld\n",
  1231. __func__, usb_tx_cfg.bit_format,
  1232. ucontrol->value.integer.value[0]);
  1233. return 0;
  1234. }
  1235. static int usb_audio_tx_format_put(struct snd_kcontrol *kcontrol,
  1236. struct snd_ctl_elem_value *ucontrol)
  1237. {
  1238. int rc = 0;
  1239. switch (ucontrol->value.integer.value[0]) {
  1240. case 3:
  1241. usb_tx_cfg.bit_format = SNDRV_PCM_FORMAT_S32_LE;
  1242. break;
  1243. case 2:
  1244. usb_tx_cfg.bit_format = SNDRV_PCM_FORMAT_S24_3LE;
  1245. break;
  1246. case 1:
  1247. usb_tx_cfg.bit_format = SNDRV_PCM_FORMAT_S24_LE;
  1248. break;
  1249. case 0:
  1250. default:
  1251. usb_tx_cfg.bit_format = SNDRV_PCM_FORMAT_S16_LE;
  1252. break;
  1253. }
  1254. pr_debug("%s: usb_audio_tx_format = %d, ucontrol value = %ld\n",
  1255. __func__, usb_tx_cfg.bit_format,
  1256. ucontrol->value.integer.value[0]);
  1257. return rc;
  1258. }
  1259. static int ext_disp_get_port_idx(struct snd_kcontrol *kcontrol)
  1260. {
  1261. int idx;
  1262. if (strnstr(kcontrol->id.name, "Display Port RX",
  1263. sizeof("Display Port RX"))) {
  1264. idx = DP_RX_IDX;
  1265. } else {
  1266. pr_err("%s: unsupported BE: %s",
  1267. __func__, kcontrol->id.name);
  1268. idx = -EINVAL;
  1269. }
  1270. return idx;
  1271. }
  1272. static int ext_disp_rx_format_get(struct snd_kcontrol *kcontrol,
  1273. struct snd_ctl_elem_value *ucontrol)
  1274. {
  1275. int idx = ext_disp_get_port_idx(kcontrol);
  1276. if (idx < 0)
  1277. return idx;
  1278. switch (ext_disp_rx_cfg[idx].bit_format) {
  1279. case SNDRV_PCM_FORMAT_S24_3LE:
  1280. ucontrol->value.integer.value[0] = 2;
  1281. break;
  1282. case SNDRV_PCM_FORMAT_S24_LE:
  1283. ucontrol->value.integer.value[0] = 1;
  1284. break;
  1285. case SNDRV_PCM_FORMAT_S16_LE:
  1286. default:
  1287. ucontrol->value.integer.value[0] = 0;
  1288. break;
  1289. }
  1290. pr_debug("%s: ext_disp_rx[%d].format = %d, ucontrol value = %ld\n",
  1291. __func__, idx, ext_disp_rx_cfg[idx].bit_format,
  1292. ucontrol->value.integer.value[0]);
  1293. return 0;
  1294. }
  1295. static int ext_disp_rx_format_put(struct snd_kcontrol *kcontrol,
  1296. struct snd_ctl_elem_value *ucontrol)
  1297. {
  1298. int idx = ext_disp_get_port_idx(kcontrol);
  1299. if (idx < 0)
  1300. return idx;
  1301. switch (ucontrol->value.integer.value[0]) {
  1302. case 2:
  1303. ext_disp_rx_cfg[idx].bit_format = SNDRV_PCM_FORMAT_S24_3LE;
  1304. break;
  1305. case 1:
  1306. ext_disp_rx_cfg[idx].bit_format = SNDRV_PCM_FORMAT_S24_LE;
  1307. break;
  1308. case 0:
  1309. default:
  1310. ext_disp_rx_cfg[idx].bit_format = SNDRV_PCM_FORMAT_S16_LE;
  1311. break;
  1312. }
  1313. pr_debug("%s: ext_disp_rx[%d].format = %d, ucontrol value = %ld\n",
  1314. __func__, idx, ext_disp_rx_cfg[idx].bit_format,
  1315. ucontrol->value.integer.value[0]);
  1316. return 0;
  1317. }
  1318. static int ext_disp_rx_ch_get(struct snd_kcontrol *kcontrol,
  1319. struct snd_ctl_elem_value *ucontrol)
  1320. {
  1321. int idx = ext_disp_get_port_idx(kcontrol);
  1322. if (idx < 0)
  1323. return idx;
  1324. ucontrol->value.integer.value[0] =
  1325. ext_disp_rx_cfg[idx].channels - 2;
  1326. pr_debug("%s: ext_disp_rx[%d].ch = %d\n", __func__,
  1327. idx, ext_disp_rx_cfg[idx].channels);
  1328. return 0;
  1329. }
  1330. static int ext_disp_rx_ch_put(struct snd_kcontrol *kcontrol,
  1331. struct snd_ctl_elem_value *ucontrol)
  1332. {
  1333. int idx = ext_disp_get_port_idx(kcontrol);
  1334. if (idx < 0)
  1335. return idx;
  1336. ext_disp_rx_cfg[idx].channels =
  1337. ucontrol->value.integer.value[0] + 2;
  1338. pr_debug("%s: ext_disp_rx[%d].ch = %d\n", __func__,
  1339. idx, ext_disp_rx_cfg[idx].channels);
  1340. return 1;
  1341. }
  1342. static int ext_disp_rx_sample_rate_get(struct snd_kcontrol *kcontrol,
  1343. struct snd_ctl_elem_value *ucontrol)
  1344. {
  1345. int sample_rate_val;
  1346. int idx = ext_disp_get_port_idx(kcontrol);
  1347. if (idx < 0)
  1348. return idx;
  1349. switch (ext_disp_rx_cfg[idx].sample_rate) {
  1350. case SAMPLING_RATE_176P4KHZ:
  1351. sample_rate_val = 6;
  1352. break;
  1353. case SAMPLING_RATE_88P2KHZ:
  1354. sample_rate_val = 5;
  1355. break;
  1356. case SAMPLING_RATE_44P1KHZ:
  1357. sample_rate_val = 4;
  1358. break;
  1359. case SAMPLING_RATE_32KHZ:
  1360. sample_rate_val = 3;
  1361. break;
  1362. case SAMPLING_RATE_192KHZ:
  1363. sample_rate_val = 2;
  1364. break;
  1365. case SAMPLING_RATE_96KHZ:
  1366. sample_rate_val = 1;
  1367. break;
  1368. case SAMPLING_RATE_48KHZ:
  1369. default:
  1370. sample_rate_val = 0;
  1371. break;
  1372. }
  1373. ucontrol->value.integer.value[0] = sample_rate_val;
  1374. pr_debug("%s: ext_disp_rx[%d].sample_rate = %d\n", __func__,
  1375. idx, ext_disp_rx_cfg[idx].sample_rate);
  1376. return 0;
  1377. }
  1378. static int ext_disp_rx_sample_rate_put(struct snd_kcontrol *kcontrol,
  1379. struct snd_ctl_elem_value *ucontrol)
  1380. {
  1381. int idx = ext_disp_get_port_idx(kcontrol);
  1382. if (idx < 0)
  1383. return idx;
  1384. switch (ucontrol->value.integer.value[0]) {
  1385. case 6:
  1386. ext_disp_rx_cfg[idx].sample_rate = SAMPLING_RATE_176P4KHZ;
  1387. break;
  1388. case 5:
  1389. ext_disp_rx_cfg[idx].sample_rate = SAMPLING_RATE_88P2KHZ;
  1390. break;
  1391. case 4:
  1392. ext_disp_rx_cfg[idx].sample_rate = SAMPLING_RATE_44P1KHZ;
  1393. break;
  1394. case 3:
  1395. ext_disp_rx_cfg[idx].sample_rate = SAMPLING_RATE_32KHZ;
  1396. break;
  1397. case 2:
  1398. ext_disp_rx_cfg[idx].sample_rate = SAMPLING_RATE_192KHZ;
  1399. break;
  1400. case 1:
  1401. ext_disp_rx_cfg[idx].sample_rate = SAMPLING_RATE_96KHZ;
  1402. break;
  1403. case 0:
  1404. default:
  1405. ext_disp_rx_cfg[idx].sample_rate = SAMPLING_RATE_48KHZ;
  1406. break;
  1407. }
  1408. pr_debug("%s: control value = %ld, ext_disp_rx[%d].sample_rate = %d\n",
  1409. __func__, ucontrol->value.integer.value[0], idx,
  1410. ext_disp_rx_cfg[idx].sample_rate);
  1411. return 0;
  1412. }
  1413. static int proxy_rx_ch_get(struct snd_kcontrol *kcontrol,
  1414. struct snd_ctl_elem_value *ucontrol)
  1415. {
  1416. pr_debug("%s: proxy_rx channels = %d\n",
  1417. __func__, proxy_rx_cfg.channels);
  1418. ucontrol->value.integer.value[0] = proxy_rx_cfg.channels - 2;
  1419. return 0;
  1420. }
  1421. static int proxy_rx_ch_put(struct snd_kcontrol *kcontrol,
  1422. struct snd_ctl_elem_value *ucontrol)
  1423. {
  1424. proxy_rx_cfg.channels = ucontrol->value.integer.value[0] + 2;
  1425. pr_debug("%s: proxy_rx channels = %d\n",
  1426. __func__, proxy_rx_cfg.channels);
  1427. return 1;
  1428. }
  1429. static int tdm_get_sample_rate(int value)
  1430. {
  1431. int sample_rate = 0;
  1432. switch (value) {
  1433. case 0:
  1434. sample_rate = SAMPLING_RATE_8KHZ;
  1435. break;
  1436. case 1:
  1437. sample_rate = SAMPLING_RATE_16KHZ;
  1438. break;
  1439. case 2:
  1440. sample_rate = SAMPLING_RATE_32KHZ;
  1441. break;
  1442. case 3:
  1443. sample_rate = SAMPLING_RATE_48KHZ;
  1444. break;
  1445. case 4:
  1446. sample_rate = SAMPLING_RATE_176P4KHZ;
  1447. break;
  1448. case 5:
  1449. sample_rate = SAMPLING_RATE_352P8KHZ;
  1450. break;
  1451. default:
  1452. sample_rate = SAMPLING_RATE_48KHZ;
  1453. break;
  1454. }
  1455. return sample_rate;
  1456. }
  1457. static int aux_pcm_get_sample_rate(int value)
  1458. {
  1459. int sample_rate;
  1460. switch (value) {
  1461. case 1:
  1462. sample_rate = SAMPLING_RATE_16KHZ;
  1463. break;
  1464. case 0:
  1465. default:
  1466. sample_rate = SAMPLING_RATE_8KHZ;
  1467. break;
  1468. }
  1469. return sample_rate;
  1470. }
  1471. static int tdm_get_sample_rate_val(int sample_rate)
  1472. {
  1473. int sample_rate_val = 0;
  1474. switch (sample_rate) {
  1475. case SAMPLING_RATE_8KHZ:
  1476. sample_rate_val = 0;
  1477. break;
  1478. case SAMPLING_RATE_16KHZ:
  1479. sample_rate_val = 1;
  1480. break;
  1481. case SAMPLING_RATE_32KHZ:
  1482. sample_rate_val = 2;
  1483. break;
  1484. case SAMPLING_RATE_48KHZ:
  1485. sample_rate_val = 3;
  1486. break;
  1487. case SAMPLING_RATE_176P4KHZ:
  1488. sample_rate_val = 4;
  1489. break;
  1490. case SAMPLING_RATE_352P8KHZ:
  1491. sample_rate_val = 5;
  1492. break;
  1493. default:
  1494. sample_rate_val = 3;
  1495. break;
  1496. }
  1497. return sample_rate_val;
  1498. }
  1499. static int aux_pcm_get_sample_rate_val(int sample_rate)
  1500. {
  1501. int sample_rate_val;
  1502. switch (sample_rate) {
  1503. case SAMPLING_RATE_16KHZ:
  1504. sample_rate_val = 1;
  1505. break;
  1506. case SAMPLING_RATE_8KHZ:
  1507. default:
  1508. sample_rate_val = 0;
  1509. break;
  1510. }
  1511. return sample_rate_val;
  1512. }
  1513. static int tdm_get_port_idx(struct snd_kcontrol *kcontrol,
  1514. struct tdm_port *port)
  1515. {
  1516. if (port) {
  1517. if (strnstr(kcontrol->id.name, "PRI",
  1518. sizeof(kcontrol->id.name))) {
  1519. port->mode = TDM_PRI;
  1520. } else if (strnstr(kcontrol->id.name, "SEC",
  1521. sizeof(kcontrol->id.name))) {
  1522. port->mode = TDM_SEC;
  1523. } else if (strnstr(kcontrol->id.name, "TERT",
  1524. sizeof(kcontrol->id.name))) {
  1525. port->mode = TDM_TERT;
  1526. } else if (strnstr(kcontrol->id.name, "QUAT",
  1527. sizeof(kcontrol->id.name))) {
  1528. port->mode = TDM_QUAT;
  1529. } else {
  1530. pr_err("%s: unsupported mode in: %s",
  1531. __func__, kcontrol->id.name);
  1532. return -EINVAL;
  1533. }
  1534. if (strnstr(kcontrol->id.name, "RX_0",
  1535. sizeof(kcontrol->id.name)) ||
  1536. strnstr(kcontrol->id.name, "TX_0",
  1537. sizeof(kcontrol->id.name))) {
  1538. port->channel = TDM_0;
  1539. } else if (strnstr(kcontrol->id.name, "RX_1",
  1540. sizeof(kcontrol->id.name)) ||
  1541. strnstr(kcontrol->id.name, "TX_1",
  1542. sizeof(kcontrol->id.name))) {
  1543. port->channel = TDM_1;
  1544. } else if (strnstr(kcontrol->id.name, "RX_2",
  1545. sizeof(kcontrol->id.name)) ||
  1546. strnstr(kcontrol->id.name, "TX_2",
  1547. sizeof(kcontrol->id.name))) {
  1548. port->channel = TDM_2;
  1549. } else if (strnstr(kcontrol->id.name, "RX_3",
  1550. sizeof(kcontrol->id.name)) ||
  1551. strnstr(kcontrol->id.name, "TX_3",
  1552. sizeof(kcontrol->id.name))) {
  1553. port->channel = TDM_3;
  1554. } else if (strnstr(kcontrol->id.name, "RX_4",
  1555. sizeof(kcontrol->id.name)) ||
  1556. strnstr(kcontrol->id.name, "TX_4",
  1557. sizeof(kcontrol->id.name))) {
  1558. port->channel = TDM_4;
  1559. } else if (strnstr(kcontrol->id.name, "RX_5",
  1560. sizeof(kcontrol->id.name)) ||
  1561. strnstr(kcontrol->id.name, "TX_5",
  1562. sizeof(kcontrol->id.name))) {
  1563. port->channel = TDM_5;
  1564. } else if (strnstr(kcontrol->id.name, "RX_6",
  1565. sizeof(kcontrol->id.name)) ||
  1566. strnstr(kcontrol->id.name, "TX_6",
  1567. sizeof(kcontrol->id.name))) {
  1568. port->channel = TDM_6;
  1569. } else if (strnstr(kcontrol->id.name, "RX_7",
  1570. sizeof(kcontrol->id.name)) ||
  1571. strnstr(kcontrol->id.name, "TX_7",
  1572. sizeof(kcontrol->id.name))) {
  1573. port->channel = TDM_7;
  1574. } else {
  1575. pr_err("%s: unsupported channel in: %s",
  1576. __func__, kcontrol->id.name);
  1577. return -EINVAL;
  1578. }
  1579. } else
  1580. return -EINVAL;
  1581. return 0;
  1582. }
  1583. static int tdm_rx_sample_rate_get(struct snd_kcontrol *kcontrol,
  1584. struct snd_ctl_elem_value *ucontrol)
  1585. {
  1586. struct tdm_port port;
  1587. int ret = tdm_get_port_idx(kcontrol, &port);
  1588. if (ret) {
  1589. pr_err("%s: unsupported control: %s",
  1590. __func__, kcontrol->id.name);
  1591. } else {
  1592. ucontrol->value.enumerated.item[0] = tdm_get_sample_rate_val(
  1593. tdm_rx_cfg[port.mode][port.channel].sample_rate);
  1594. pr_debug("%s: tdm_rx_sample_rate = %d, item = %d\n", __func__,
  1595. tdm_rx_cfg[port.mode][port.channel].sample_rate,
  1596. ucontrol->value.enumerated.item[0]);
  1597. }
  1598. return ret;
  1599. }
  1600. static int tdm_rx_sample_rate_put(struct snd_kcontrol *kcontrol,
  1601. struct snd_ctl_elem_value *ucontrol)
  1602. {
  1603. struct tdm_port port;
  1604. int ret = tdm_get_port_idx(kcontrol, &port);
  1605. if (ret) {
  1606. pr_err("%s: unsupported control: %s",
  1607. __func__, kcontrol->id.name);
  1608. } else {
  1609. tdm_rx_cfg[port.mode][port.channel].sample_rate =
  1610. tdm_get_sample_rate(ucontrol->value.enumerated.item[0]);
  1611. pr_debug("%s: tdm_rx_sample_rate = %d, item = %d\n", __func__,
  1612. tdm_rx_cfg[port.mode][port.channel].sample_rate,
  1613. ucontrol->value.enumerated.item[0]);
  1614. }
  1615. return ret;
  1616. }
  1617. static int tdm_tx_sample_rate_get(struct snd_kcontrol *kcontrol,
  1618. struct snd_ctl_elem_value *ucontrol)
  1619. {
  1620. struct tdm_port port;
  1621. int ret = tdm_get_port_idx(kcontrol, &port);
  1622. if (ret) {
  1623. pr_err("%s: unsupported control: %s",
  1624. __func__, kcontrol->id.name);
  1625. } else {
  1626. ucontrol->value.enumerated.item[0] = tdm_get_sample_rate_val(
  1627. tdm_tx_cfg[port.mode][port.channel].sample_rate);
  1628. pr_debug("%s: tdm_tx_sample_rate = %d, item = %d\n", __func__,
  1629. tdm_tx_cfg[port.mode][port.channel].sample_rate,
  1630. ucontrol->value.enumerated.item[0]);
  1631. }
  1632. return ret;
  1633. }
  1634. static int tdm_tx_sample_rate_put(struct snd_kcontrol *kcontrol,
  1635. struct snd_ctl_elem_value *ucontrol)
  1636. {
  1637. struct tdm_port port;
  1638. int ret = tdm_get_port_idx(kcontrol, &port);
  1639. if (ret) {
  1640. pr_err("%s: unsupported control: %s",
  1641. __func__, kcontrol->id.name);
  1642. } else {
  1643. tdm_tx_cfg[port.mode][port.channel].sample_rate =
  1644. tdm_get_sample_rate(ucontrol->value.enumerated.item[0]);
  1645. pr_debug("%s: tdm_tx_sample_rate = %d, item = %d\n", __func__,
  1646. tdm_tx_cfg[port.mode][port.channel].sample_rate,
  1647. ucontrol->value.enumerated.item[0]);
  1648. }
  1649. return ret;
  1650. }
  1651. static int tdm_get_format(int value)
  1652. {
  1653. int format = 0;
  1654. switch (value) {
  1655. case 0:
  1656. format = SNDRV_PCM_FORMAT_S16_LE;
  1657. break;
  1658. case 1:
  1659. format = SNDRV_PCM_FORMAT_S24_LE;
  1660. break;
  1661. case 2:
  1662. format = SNDRV_PCM_FORMAT_S32_LE;
  1663. break;
  1664. default:
  1665. format = SNDRV_PCM_FORMAT_S16_LE;
  1666. break;
  1667. }
  1668. return format;
  1669. }
  1670. static int tdm_get_format_val(int format)
  1671. {
  1672. int value = 0;
  1673. switch (format) {
  1674. case SNDRV_PCM_FORMAT_S16_LE:
  1675. value = 0;
  1676. break;
  1677. case SNDRV_PCM_FORMAT_S24_LE:
  1678. value = 1;
  1679. break;
  1680. case SNDRV_PCM_FORMAT_S32_LE:
  1681. value = 2;
  1682. break;
  1683. default:
  1684. value = 0;
  1685. break;
  1686. }
  1687. return value;
  1688. }
  1689. static int tdm_rx_format_get(struct snd_kcontrol *kcontrol,
  1690. struct snd_ctl_elem_value *ucontrol)
  1691. {
  1692. struct tdm_port port;
  1693. int ret = tdm_get_port_idx(kcontrol, &port);
  1694. if (ret) {
  1695. pr_err("%s: unsupported control: %s",
  1696. __func__, kcontrol->id.name);
  1697. } else {
  1698. ucontrol->value.enumerated.item[0] = tdm_get_format_val(
  1699. tdm_rx_cfg[port.mode][port.channel].bit_format);
  1700. pr_debug("%s: tdm_rx_bit_format = %d, item = %d\n", __func__,
  1701. tdm_rx_cfg[port.mode][port.channel].bit_format,
  1702. ucontrol->value.enumerated.item[0]);
  1703. }
  1704. return ret;
  1705. }
  1706. static int tdm_rx_format_put(struct snd_kcontrol *kcontrol,
  1707. struct snd_ctl_elem_value *ucontrol)
  1708. {
  1709. struct tdm_port port;
  1710. int ret = tdm_get_port_idx(kcontrol, &port);
  1711. if (ret) {
  1712. pr_err("%s: unsupported control: %s",
  1713. __func__, kcontrol->id.name);
  1714. } else {
  1715. tdm_rx_cfg[port.mode][port.channel].bit_format =
  1716. tdm_get_format(ucontrol->value.enumerated.item[0]);
  1717. pr_debug("%s: tdm_rx_bit_format = %d, item = %d\n", __func__,
  1718. tdm_rx_cfg[port.mode][port.channel].bit_format,
  1719. ucontrol->value.enumerated.item[0]);
  1720. }
  1721. return ret;
  1722. }
  1723. static int tdm_tx_format_get(struct snd_kcontrol *kcontrol,
  1724. struct snd_ctl_elem_value *ucontrol)
  1725. {
  1726. struct tdm_port port;
  1727. int ret = tdm_get_port_idx(kcontrol, &port);
  1728. if (ret) {
  1729. pr_err("%s: unsupported control: %s",
  1730. __func__, kcontrol->id.name);
  1731. } else {
  1732. ucontrol->value.enumerated.item[0] = tdm_get_format_val(
  1733. tdm_tx_cfg[port.mode][port.channel].bit_format);
  1734. pr_debug("%s: tdm_tx_bit_format = %d, item = %d\n", __func__,
  1735. tdm_tx_cfg[port.mode][port.channel].bit_format,
  1736. ucontrol->value.enumerated.item[0]);
  1737. }
  1738. return ret;
  1739. }
  1740. static int tdm_tx_format_put(struct snd_kcontrol *kcontrol,
  1741. struct snd_ctl_elem_value *ucontrol)
  1742. {
  1743. struct tdm_port port;
  1744. int ret = tdm_get_port_idx(kcontrol, &port);
  1745. if (ret) {
  1746. pr_err("%s: unsupported control: %s",
  1747. __func__, kcontrol->id.name);
  1748. } else {
  1749. tdm_tx_cfg[port.mode][port.channel].bit_format =
  1750. tdm_get_format(ucontrol->value.enumerated.item[0]);
  1751. pr_debug("%s: tdm_tx_bit_format = %d, item = %d\n", __func__,
  1752. tdm_tx_cfg[port.mode][port.channel].bit_format,
  1753. ucontrol->value.enumerated.item[0]);
  1754. }
  1755. return ret;
  1756. }
  1757. static int tdm_rx_ch_get(struct snd_kcontrol *kcontrol,
  1758. struct snd_ctl_elem_value *ucontrol)
  1759. {
  1760. struct tdm_port port;
  1761. int ret = tdm_get_port_idx(kcontrol, &port);
  1762. if (ret) {
  1763. pr_err("%s: unsupported control: %s",
  1764. __func__, kcontrol->id.name);
  1765. } else {
  1766. ucontrol->value.enumerated.item[0] =
  1767. tdm_rx_cfg[port.mode][port.channel].channels - 1;
  1768. pr_debug("%s: tdm_rx_ch = %d, item = %d\n", __func__,
  1769. tdm_rx_cfg[port.mode][port.channel].channels - 1,
  1770. ucontrol->value.enumerated.item[0]);
  1771. }
  1772. return ret;
  1773. }
  1774. static int tdm_rx_ch_put(struct snd_kcontrol *kcontrol,
  1775. struct snd_ctl_elem_value *ucontrol)
  1776. {
  1777. struct tdm_port port;
  1778. int ret = tdm_get_port_idx(kcontrol, &port);
  1779. if (ret) {
  1780. pr_err("%s: unsupported control: %s",
  1781. __func__, kcontrol->id.name);
  1782. } else {
  1783. tdm_rx_cfg[port.mode][port.channel].channels =
  1784. ucontrol->value.enumerated.item[0] + 1;
  1785. pr_debug("%s: tdm_rx_ch = %d, item = %d\n", __func__,
  1786. tdm_rx_cfg[port.mode][port.channel].channels,
  1787. ucontrol->value.enumerated.item[0] + 1);
  1788. }
  1789. return ret;
  1790. }
  1791. static int tdm_tx_ch_get(struct snd_kcontrol *kcontrol,
  1792. struct snd_ctl_elem_value *ucontrol)
  1793. {
  1794. struct tdm_port port;
  1795. int ret = tdm_get_port_idx(kcontrol, &port);
  1796. if (ret) {
  1797. pr_err("%s: unsupported control: %s",
  1798. __func__, kcontrol->id.name);
  1799. } else {
  1800. ucontrol->value.enumerated.item[0] =
  1801. tdm_tx_cfg[port.mode][port.channel].channels - 1;
  1802. pr_debug("%s: tdm_tx_ch = %d, item = %d\n", __func__,
  1803. tdm_tx_cfg[port.mode][port.channel].channels - 1,
  1804. ucontrol->value.enumerated.item[0]);
  1805. }
  1806. return ret;
  1807. }
  1808. static int tdm_tx_ch_put(struct snd_kcontrol *kcontrol,
  1809. struct snd_ctl_elem_value *ucontrol)
  1810. {
  1811. struct tdm_port port;
  1812. int ret = tdm_get_port_idx(kcontrol, &port);
  1813. if (ret) {
  1814. pr_err("%s: unsupported control: %s",
  1815. __func__, kcontrol->id.name);
  1816. } else {
  1817. tdm_tx_cfg[port.mode][port.channel].channels =
  1818. ucontrol->value.enumerated.item[0] + 1;
  1819. pr_debug("%s: tdm_tx_ch = %d, item = %d\n", __func__,
  1820. tdm_tx_cfg[port.mode][port.channel].channels,
  1821. ucontrol->value.enumerated.item[0] + 1);
  1822. }
  1823. return ret;
  1824. }
  1825. static int aux_pcm_get_port_idx(struct snd_kcontrol *kcontrol)
  1826. {
  1827. int idx;
  1828. if (strnstr(kcontrol->id.name, "PRIM_AUX_PCM",
  1829. sizeof("PRIM_AUX_PCM")))
  1830. idx = PRIM_AUX_PCM;
  1831. else if (strnstr(kcontrol->id.name, "SEC_AUX_PCM",
  1832. sizeof("SEC_AUX_PCM")))
  1833. idx = SEC_AUX_PCM;
  1834. else if (strnstr(kcontrol->id.name, "TERT_AUX_PCM",
  1835. sizeof("TERT_AUX_PCM")))
  1836. idx = TERT_AUX_PCM;
  1837. else if (strnstr(kcontrol->id.name, "QUAT_AUX_PCM",
  1838. sizeof("QUAT_AUX_PCM")))
  1839. idx = QUAT_AUX_PCM;
  1840. else {
  1841. pr_err("%s: unsupported port: %s",
  1842. __func__, kcontrol->id.name);
  1843. idx = -EINVAL;
  1844. }
  1845. return idx;
  1846. }
  1847. static int aux_pcm_rx_sample_rate_put(struct snd_kcontrol *kcontrol,
  1848. struct snd_ctl_elem_value *ucontrol)
  1849. {
  1850. int idx = aux_pcm_get_port_idx(kcontrol);
  1851. if (idx < 0)
  1852. return idx;
  1853. aux_pcm_rx_cfg[idx].sample_rate =
  1854. aux_pcm_get_sample_rate(ucontrol->value.enumerated.item[0]);
  1855. pr_debug("%s: idx[%d]_rx_sample_rate = %d, item = %d\n", __func__,
  1856. idx, aux_pcm_rx_cfg[idx].sample_rate,
  1857. ucontrol->value.enumerated.item[0]);
  1858. return 0;
  1859. }
  1860. static int aux_pcm_rx_sample_rate_get(struct snd_kcontrol *kcontrol,
  1861. struct snd_ctl_elem_value *ucontrol)
  1862. {
  1863. int idx = aux_pcm_get_port_idx(kcontrol);
  1864. if (idx < 0)
  1865. return idx;
  1866. ucontrol->value.enumerated.item[0] =
  1867. aux_pcm_get_sample_rate_val(aux_pcm_rx_cfg[idx].sample_rate);
  1868. pr_debug("%s: idx[%d]_rx_sample_rate = %d, item = %d\n", __func__,
  1869. idx, aux_pcm_rx_cfg[idx].sample_rate,
  1870. ucontrol->value.enumerated.item[0]);
  1871. return 0;
  1872. }
  1873. static int aux_pcm_tx_sample_rate_put(struct snd_kcontrol *kcontrol,
  1874. struct snd_ctl_elem_value *ucontrol)
  1875. {
  1876. int idx = aux_pcm_get_port_idx(kcontrol);
  1877. if (idx < 0)
  1878. return idx;
  1879. aux_pcm_tx_cfg[idx].sample_rate =
  1880. aux_pcm_get_sample_rate(ucontrol->value.enumerated.item[0]);
  1881. pr_debug("%s: idx[%d]_tx_sample_rate = %d, item = %d\n", __func__,
  1882. idx, aux_pcm_tx_cfg[idx].sample_rate,
  1883. ucontrol->value.enumerated.item[0]);
  1884. return 0;
  1885. }
  1886. static int aux_pcm_tx_sample_rate_get(struct snd_kcontrol *kcontrol,
  1887. struct snd_ctl_elem_value *ucontrol)
  1888. {
  1889. int idx = aux_pcm_get_port_idx(kcontrol);
  1890. if (idx < 0)
  1891. return idx;
  1892. ucontrol->value.enumerated.item[0] =
  1893. aux_pcm_get_sample_rate_val(aux_pcm_tx_cfg[idx].sample_rate);
  1894. pr_debug("%s: idx[%d]_tx_sample_rate = %d, item = %d\n", __func__,
  1895. idx, aux_pcm_tx_cfg[idx].sample_rate,
  1896. ucontrol->value.enumerated.item[0]);
  1897. return 0;
  1898. }
  1899. static int mi2s_get_port_idx(struct snd_kcontrol *kcontrol)
  1900. {
  1901. int idx;
  1902. if (strnstr(kcontrol->id.name, "PRIM_MI2S_RX",
  1903. sizeof("PRIM_MI2S_RX")))
  1904. idx = PRIM_MI2S;
  1905. else if (strnstr(kcontrol->id.name, "SEC_MI2S_RX",
  1906. sizeof("SEC_MI2S_RX")))
  1907. idx = SEC_MI2S;
  1908. else if (strnstr(kcontrol->id.name, "TERT_MI2S_RX",
  1909. sizeof("TERT_MI2S_RX")))
  1910. idx = TERT_MI2S;
  1911. else if (strnstr(kcontrol->id.name, "QUAT_MI2S_RX",
  1912. sizeof("QUAT_MI2S_RX")))
  1913. idx = QUAT_MI2S;
  1914. else if (strnstr(kcontrol->id.name, "PRIM_MI2S_TX",
  1915. sizeof("PRIM_MI2S_TX")))
  1916. idx = PRIM_MI2S;
  1917. else if (strnstr(kcontrol->id.name, "SEC_MI2S_TX",
  1918. sizeof("SEC_MI2S_TX")))
  1919. idx = SEC_MI2S;
  1920. else if (strnstr(kcontrol->id.name, "TERT_MI2S_TX",
  1921. sizeof("TERT_MI2S_TX")))
  1922. idx = TERT_MI2S;
  1923. else if (strnstr(kcontrol->id.name, "QUAT_MI2S_TX",
  1924. sizeof("QUAT_MI2S_TX")))
  1925. idx = QUAT_MI2S;
  1926. else {
  1927. pr_err("%s: unsupported channel: %s",
  1928. __func__, kcontrol->id.name);
  1929. idx = -EINVAL;
  1930. }
  1931. return idx;
  1932. }
  1933. static int mi2s_get_sample_rate_val(int sample_rate)
  1934. {
  1935. int sample_rate_val;
  1936. switch (sample_rate) {
  1937. case SAMPLING_RATE_8KHZ:
  1938. sample_rate_val = 0;
  1939. break;
  1940. case SAMPLING_RATE_11P025KHZ:
  1941. sample_rate_val = 1;
  1942. break;
  1943. case SAMPLING_RATE_16KHZ:
  1944. sample_rate_val = 2;
  1945. break;
  1946. case SAMPLING_RATE_22P05KHZ:
  1947. sample_rate_val = 3;
  1948. break;
  1949. case SAMPLING_RATE_32KHZ:
  1950. sample_rate_val = 4;
  1951. break;
  1952. case SAMPLING_RATE_44P1KHZ:
  1953. sample_rate_val = 5;
  1954. break;
  1955. case SAMPLING_RATE_48KHZ:
  1956. sample_rate_val = 6;
  1957. break;
  1958. case SAMPLING_RATE_96KHZ:
  1959. sample_rate_val = 7;
  1960. break;
  1961. case SAMPLING_RATE_192KHZ:
  1962. sample_rate_val = 8;
  1963. break;
  1964. default:
  1965. sample_rate_val = 6;
  1966. break;
  1967. }
  1968. return sample_rate_val;
  1969. }
  1970. static int mi2s_get_sample_rate(int value)
  1971. {
  1972. int sample_rate;
  1973. switch (value) {
  1974. case 0:
  1975. sample_rate = SAMPLING_RATE_8KHZ;
  1976. break;
  1977. case 1:
  1978. sample_rate = SAMPLING_RATE_11P025KHZ;
  1979. break;
  1980. case 2:
  1981. sample_rate = SAMPLING_RATE_16KHZ;
  1982. break;
  1983. case 3:
  1984. sample_rate = SAMPLING_RATE_22P05KHZ;
  1985. break;
  1986. case 4:
  1987. sample_rate = SAMPLING_RATE_32KHZ;
  1988. break;
  1989. case 5:
  1990. sample_rate = SAMPLING_RATE_44P1KHZ;
  1991. break;
  1992. case 6:
  1993. sample_rate = SAMPLING_RATE_48KHZ;
  1994. break;
  1995. case 7:
  1996. sample_rate = SAMPLING_RATE_96KHZ;
  1997. break;
  1998. case 8:
  1999. sample_rate = SAMPLING_RATE_192KHZ;
  2000. break;
  2001. default:
  2002. sample_rate = SAMPLING_RATE_48KHZ;
  2003. break;
  2004. }
  2005. return sample_rate;
  2006. }
  2007. static int mi2s_auxpcm_get_format(int value)
  2008. {
  2009. int format;
  2010. switch (value) {
  2011. case 0:
  2012. format = SNDRV_PCM_FORMAT_S16_LE;
  2013. break;
  2014. case 1:
  2015. format = SNDRV_PCM_FORMAT_S24_LE;
  2016. break;
  2017. case 2:
  2018. format = SNDRV_PCM_FORMAT_S24_3LE;
  2019. break;
  2020. case 3:
  2021. format = SNDRV_PCM_FORMAT_S32_LE;
  2022. break;
  2023. default:
  2024. format = SNDRV_PCM_FORMAT_S16_LE;
  2025. break;
  2026. }
  2027. return format;
  2028. }
  2029. static int mi2s_auxpcm_get_format_value(int format)
  2030. {
  2031. int value;
  2032. switch (format) {
  2033. case SNDRV_PCM_FORMAT_S16_LE:
  2034. value = 0;
  2035. break;
  2036. case SNDRV_PCM_FORMAT_S24_LE:
  2037. value = 1;
  2038. break;
  2039. case SNDRV_PCM_FORMAT_S24_3LE:
  2040. value = 2;
  2041. break;
  2042. case SNDRV_PCM_FORMAT_S32_LE:
  2043. value = 3;
  2044. break;
  2045. default:
  2046. value = 0;
  2047. break;
  2048. }
  2049. return value;
  2050. }
  2051. static int mi2s_rx_sample_rate_put(struct snd_kcontrol *kcontrol,
  2052. struct snd_ctl_elem_value *ucontrol)
  2053. {
  2054. int idx = mi2s_get_port_idx(kcontrol);
  2055. if (idx < 0)
  2056. return idx;
  2057. mi2s_rx_cfg[idx].sample_rate =
  2058. mi2s_get_sample_rate(ucontrol->value.enumerated.item[0]);
  2059. pr_debug("%s: idx[%d]_rx_sample_rate = %d, item = %d\n", __func__,
  2060. idx, mi2s_rx_cfg[idx].sample_rate,
  2061. ucontrol->value.enumerated.item[0]);
  2062. return 0;
  2063. }
  2064. static int mi2s_rx_sample_rate_get(struct snd_kcontrol *kcontrol,
  2065. struct snd_ctl_elem_value *ucontrol)
  2066. {
  2067. int idx = mi2s_get_port_idx(kcontrol);
  2068. if (idx < 0)
  2069. return idx;
  2070. ucontrol->value.enumerated.item[0] =
  2071. mi2s_get_sample_rate_val(mi2s_rx_cfg[idx].sample_rate);
  2072. pr_debug("%s: idx[%d]_rx_sample_rate = %d, item = %d\n", __func__,
  2073. idx, mi2s_rx_cfg[idx].sample_rate,
  2074. ucontrol->value.enumerated.item[0]);
  2075. return 0;
  2076. }
  2077. static int mi2s_tx_sample_rate_put(struct snd_kcontrol *kcontrol,
  2078. struct snd_ctl_elem_value *ucontrol)
  2079. {
  2080. int idx = mi2s_get_port_idx(kcontrol);
  2081. if (idx < 0)
  2082. return idx;
  2083. mi2s_tx_cfg[idx].sample_rate =
  2084. mi2s_get_sample_rate(ucontrol->value.enumerated.item[0]);
  2085. pr_debug("%s: idx[%d]_tx_sample_rate = %d, item = %d\n", __func__,
  2086. idx, mi2s_tx_cfg[idx].sample_rate,
  2087. ucontrol->value.enumerated.item[0]);
  2088. return 0;
  2089. }
  2090. static int mi2s_tx_sample_rate_get(struct snd_kcontrol *kcontrol,
  2091. struct snd_ctl_elem_value *ucontrol)
  2092. {
  2093. int idx = mi2s_get_port_idx(kcontrol);
  2094. if (idx < 0)
  2095. return idx;
  2096. ucontrol->value.enumerated.item[0] =
  2097. mi2s_get_sample_rate_val(mi2s_tx_cfg[idx].sample_rate);
  2098. pr_debug("%s: idx[%d]_tx_sample_rate = %d, item = %d\n", __func__,
  2099. idx, mi2s_tx_cfg[idx].sample_rate,
  2100. ucontrol->value.enumerated.item[0]);
  2101. return 0;
  2102. }
  2103. static int msm_mi2s_rx_ch_get(struct snd_kcontrol *kcontrol,
  2104. struct snd_ctl_elem_value *ucontrol)
  2105. {
  2106. int idx = mi2s_get_port_idx(kcontrol);
  2107. if (idx < 0)
  2108. return idx;
  2109. pr_debug("%s: msm_mi2s_[%d]_rx_ch = %d\n", __func__,
  2110. idx, mi2s_rx_cfg[idx].channels);
  2111. ucontrol->value.enumerated.item[0] = mi2s_rx_cfg[idx].channels - 1;
  2112. return 0;
  2113. }
  2114. static int msm_mi2s_rx_ch_put(struct snd_kcontrol *kcontrol,
  2115. struct snd_ctl_elem_value *ucontrol)
  2116. {
  2117. int idx = mi2s_get_port_idx(kcontrol);
  2118. if (idx < 0)
  2119. return idx;
  2120. mi2s_rx_cfg[idx].channels = ucontrol->value.enumerated.item[0] + 1;
  2121. pr_debug("%s: msm_mi2s_[%d]_rx_ch = %d\n", __func__,
  2122. idx, mi2s_rx_cfg[idx].channels);
  2123. return 1;
  2124. }
  2125. static int msm_mi2s_tx_ch_get(struct snd_kcontrol *kcontrol,
  2126. struct snd_ctl_elem_value *ucontrol)
  2127. {
  2128. int idx = mi2s_get_port_idx(kcontrol);
  2129. if (idx < 0)
  2130. return idx;
  2131. pr_debug("%s: msm_mi2s_[%d]_tx_ch = %d\n", __func__,
  2132. idx, mi2s_tx_cfg[idx].channels);
  2133. ucontrol->value.enumerated.item[0] = mi2s_tx_cfg[idx].channels - 1;
  2134. return 0;
  2135. }
  2136. static int msm_mi2s_tx_ch_put(struct snd_kcontrol *kcontrol,
  2137. struct snd_ctl_elem_value *ucontrol)
  2138. {
  2139. int idx = mi2s_get_port_idx(kcontrol);
  2140. if (idx < 0)
  2141. return idx;
  2142. mi2s_tx_cfg[idx].channels = ucontrol->value.enumerated.item[0] + 1;
  2143. pr_debug("%s: msm_mi2s_[%d]_tx_ch = %d\n", __func__,
  2144. idx, mi2s_tx_cfg[idx].channels);
  2145. return 1;
  2146. }
  2147. static int msm_mi2s_rx_format_get(struct snd_kcontrol *kcontrol,
  2148. struct snd_ctl_elem_value *ucontrol)
  2149. {
  2150. int idx = mi2s_get_port_idx(kcontrol);
  2151. if (idx < 0)
  2152. return idx;
  2153. ucontrol->value.enumerated.item[0] =
  2154. mi2s_auxpcm_get_format_value(mi2s_rx_cfg[idx].bit_format);
  2155. pr_debug("%s: idx[%d]_rx_format = %d, item = %d\n", __func__,
  2156. idx, mi2s_rx_cfg[idx].bit_format,
  2157. ucontrol->value.enumerated.item[0]);
  2158. return 0;
  2159. }
  2160. static int msm_mi2s_rx_format_put(struct snd_kcontrol *kcontrol,
  2161. struct snd_ctl_elem_value *ucontrol)
  2162. {
  2163. int idx = mi2s_get_port_idx(kcontrol);
  2164. if (idx < 0)
  2165. return idx;
  2166. mi2s_rx_cfg[idx].bit_format =
  2167. mi2s_auxpcm_get_format(ucontrol->value.enumerated.item[0]);
  2168. pr_debug("%s: idx[%d]_rx_format = %d, item = %d\n", __func__,
  2169. idx, mi2s_rx_cfg[idx].bit_format,
  2170. ucontrol->value.enumerated.item[0]);
  2171. return 0;
  2172. }
  2173. static int msm_mi2s_tx_format_get(struct snd_kcontrol *kcontrol,
  2174. struct snd_ctl_elem_value *ucontrol)
  2175. {
  2176. int idx = mi2s_get_port_idx(kcontrol);
  2177. if (idx < 0)
  2178. return idx;
  2179. ucontrol->value.enumerated.item[0] =
  2180. mi2s_auxpcm_get_format_value(mi2s_tx_cfg[idx].bit_format);
  2181. pr_debug("%s: idx[%d]_tx_format = %d, item = %d\n", __func__,
  2182. idx, mi2s_tx_cfg[idx].bit_format,
  2183. ucontrol->value.enumerated.item[0]);
  2184. return 0;
  2185. }
  2186. static int msm_mi2s_tx_format_put(struct snd_kcontrol *kcontrol,
  2187. struct snd_ctl_elem_value *ucontrol)
  2188. {
  2189. int idx = mi2s_get_port_idx(kcontrol);
  2190. if (idx < 0)
  2191. return idx;
  2192. mi2s_tx_cfg[idx].bit_format =
  2193. mi2s_auxpcm_get_format(ucontrol->value.enumerated.item[0]);
  2194. pr_debug("%s: idx[%d]_tx_format = %d, item = %d\n", __func__,
  2195. idx, mi2s_tx_cfg[idx].bit_format,
  2196. ucontrol->value.enumerated.item[0]);
  2197. return 0;
  2198. }
  2199. static int msm_aux_pcm_rx_format_get(struct snd_kcontrol *kcontrol,
  2200. struct snd_ctl_elem_value *ucontrol)
  2201. {
  2202. int idx = aux_pcm_get_port_idx(kcontrol);
  2203. if (idx < 0)
  2204. return idx;
  2205. ucontrol->value.enumerated.item[0] =
  2206. mi2s_auxpcm_get_format_value(aux_pcm_rx_cfg[idx].bit_format);
  2207. pr_debug("%s: idx[%d]_rx_format = %d, item = %d\n", __func__,
  2208. idx, aux_pcm_rx_cfg[idx].bit_format,
  2209. ucontrol->value.enumerated.item[0]);
  2210. return 0;
  2211. }
  2212. static int msm_aux_pcm_rx_format_put(struct snd_kcontrol *kcontrol,
  2213. struct snd_ctl_elem_value *ucontrol)
  2214. {
  2215. int idx = aux_pcm_get_port_idx(kcontrol);
  2216. if (idx < 0)
  2217. return idx;
  2218. aux_pcm_rx_cfg[idx].bit_format =
  2219. mi2s_auxpcm_get_format(ucontrol->value.enumerated.item[0]);
  2220. pr_debug("%s: idx[%d]_rx_format = %d, item = %d\n", __func__,
  2221. idx, aux_pcm_rx_cfg[idx].bit_format,
  2222. ucontrol->value.enumerated.item[0]);
  2223. return 0;
  2224. }
  2225. static int msm_aux_pcm_tx_format_get(struct snd_kcontrol *kcontrol,
  2226. struct snd_ctl_elem_value *ucontrol)
  2227. {
  2228. int idx = aux_pcm_get_port_idx(kcontrol);
  2229. if (idx < 0)
  2230. return idx;
  2231. ucontrol->value.enumerated.item[0] =
  2232. mi2s_auxpcm_get_format_value(aux_pcm_tx_cfg[idx].bit_format);
  2233. pr_debug("%s: idx[%d]_tx_format = %d, item = %d\n", __func__,
  2234. idx, aux_pcm_tx_cfg[idx].bit_format,
  2235. ucontrol->value.enumerated.item[0]);
  2236. return 0;
  2237. }
  2238. static int msm_aux_pcm_tx_format_put(struct snd_kcontrol *kcontrol,
  2239. struct snd_ctl_elem_value *ucontrol)
  2240. {
  2241. int idx = aux_pcm_get_port_idx(kcontrol);
  2242. if (idx < 0)
  2243. return idx;
  2244. aux_pcm_tx_cfg[idx].bit_format =
  2245. mi2s_auxpcm_get_format(ucontrol->value.enumerated.item[0]);
  2246. pr_debug("%s: idx[%d]_tx_format = %d, item = %d\n", __func__,
  2247. idx, aux_pcm_tx_cfg[idx].bit_format,
  2248. ucontrol->value.enumerated.item[0]);
  2249. return 0;
  2250. }
  2251. static int msm_hifi_ctrl(struct snd_soc_codec *codec)
  2252. {
  2253. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  2254. struct snd_soc_card *card = codec->component.card;
  2255. struct msm_asoc_mach_data *pdata =
  2256. snd_soc_card_get_drvdata(card);
  2257. pr_debug("%s: msm_hifi_control = %d", __func__,
  2258. msm_hifi_control);
  2259. if (!pdata || !pdata->hph_en1_gpio_p) {
  2260. pr_err("%s: hph_en1_gpio is invalid\n", __func__);
  2261. return -EINVAL;
  2262. }
  2263. if (msm_hifi_control == MSM_HIFI_ON) {
  2264. msm_cdc_pinctrl_select_active_state(pdata->hph_en1_gpio_p);
  2265. /* 5msec delay needed as per HW requirement */
  2266. usleep_range(5000, 5010);
  2267. } else {
  2268. msm_cdc_pinctrl_select_sleep_state(pdata->hph_en1_gpio_p);
  2269. }
  2270. snd_soc_dapm_sync(dapm);
  2271. return 0;
  2272. }
  2273. static int msm_hifi_get(struct snd_kcontrol *kcontrol,
  2274. struct snd_ctl_elem_value *ucontrol)
  2275. {
  2276. pr_debug("%s: msm_hifi_control = %d\n",
  2277. __func__, msm_hifi_control);
  2278. ucontrol->value.integer.value[0] = msm_hifi_control;
  2279. return 0;
  2280. }
  2281. static int msm_hifi_put(struct snd_kcontrol *kcontrol,
  2282. struct snd_ctl_elem_value *ucontrol)
  2283. {
  2284. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  2285. pr_debug("%s() ucontrol->value.integer.value[0] = %ld\n",
  2286. __func__, ucontrol->value.integer.value[0]);
  2287. msm_hifi_control = ucontrol->value.integer.value[0];
  2288. msm_hifi_ctrl(codec);
  2289. return 0;
  2290. }
  2291. static int msm_qos_ctl_get(struct snd_kcontrol *kcontrol,
  2292. struct snd_ctl_elem_value *ucontrol)
  2293. {
  2294. ucontrol->value.enumerated.item[0] = qos_vote_status;
  2295. return 0;
  2296. }
  2297. static int msm_qos_ctl_put(struct snd_kcontrol *kcontrol,
  2298. struct snd_ctl_elem_value *ucontrol)
  2299. {
  2300. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  2301. struct snd_soc_card *card = codec->component.card;
  2302. const char *be_name = MSM_DAILINK_NAME(LowLatency);
  2303. struct snd_soc_pcm_runtime *rtd;
  2304. struct snd_pcm_substream *substream;
  2305. s32 usecs;
  2306. rtd = snd_soc_get_pcm_runtime(card, be_name);
  2307. if (!rtd) {
  2308. pr_err("%s: fail to get pcm runtime for %s\n",
  2309. __func__, be_name);
  2310. return -EINVAL;
  2311. }
  2312. substream = rtd->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
  2313. if (!substream) {
  2314. pr_err("%s: substream is null\n", __func__);
  2315. return -EINVAL;
  2316. }
  2317. qos_vote_status = ucontrol->value.enumerated.item[0];
  2318. if (qos_vote_status) {
  2319. if (pm_qos_request_active(&substream->latency_pm_qos_req))
  2320. pm_qos_remove_request(&substream->latency_pm_qos_req);
  2321. if (!substream->runtime) {
  2322. pr_err("%s: runtime is null\n", __func__);
  2323. return -EINVAL;
  2324. }
  2325. usecs = MSM_LL_QOS_VALUE;
  2326. if (usecs >= 0)
  2327. pm_qos_add_request(&substream->latency_pm_qos_req,
  2328. PM_QOS_CPU_DMA_LATENCY, usecs);
  2329. } else {
  2330. if (pm_qos_request_active(&substream->latency_pm_qos_req))
  2331. pm_qos_remove_request(&substream->latency_pm_qos_req);
  2332. }
  2333. return 0;
  2334. }
  2335. static const struct snd_kcontrol_new msm_snd_controls[] = {
  2336. SOC_ENUM_EXT("SLIM_0_RX Channels", slim_0_rx_chs,
  2337. msm_slim_rx_ch_get, msm_slim_rx_ch_put),
  2338. SOC_ENUM_EXT("SLIM_2_RX Channels", slim_2_rx_chs,
  2339. msm_slim_rx_ch_get, msm_slim_rx_ch_put),
  2340. SOC_ENUM_EXT("SLIM_0_TX Channels", slim_0_tx_chs,
  2341. msm_slim_tx_ch_get, msm_slim_tx_ch_put),
  2342. SOC_ENUM_EXT("SLIM_1_TX Channels", slim_1_tx_chs,
  2343. msm_slim_tx_ch_get, msm_slim_tx_ch_put),
  2344. SOC_ENUM_EXT("SLIM_5_RX Channels", slim_5_rx_chs,
  2345. msm_slim_rx_ch_get, msm_slim_rx_ch_put),
  2346. SOC_ENUM_EXT("SLIM_6_RX Channels", slim_6_rx_chs,
  2347. msm_slim_rx_ch_get, msm_slim_rx_ch_put),
  2348. SOC_ENUM_EXT("VI_FEED_TX Channels", vi_feed_tx_chs,
  2349. msm_vi_feed_tx_ch_get, msm_vi_feed_tx_ch_put),
  2350. SOC_ENUM_EXT("USB_AUDIO_RX Channels", usb_rx_chs,
  2351. usb_audio_rx_ch_get, usb_audio_rx_ch_put),
  2352. SOC_ENUM_EXT("USB_AUDIO_TX Channels", usb_tx_chs,
  2353. usb_audio_tx_ch_get, usb_audio_tx_ch_put),
  2354. SOC_ENUM_EXT("Display Port RX Channels", ext_disp_rx_chs,
  2355. ext_disp_rx_ch_get, ext_disp_rx_ch_put),
  2356. SOC_ENUM_EXT("PROXY_RX Channels", proxy_rx_chs,
  2357. proxy_rx_ch_get, proxy_rx_ch_put),
  2358. SOC_ENUM_EXT("SLIM_0_RX Format", slim_0_rx_format,
  2359. slim_rx_bit_format_get, slim_rx_bit_format_put),
  2360. SOC_ENUM_EXT("SLIM_5_RX Format", slim_5_rx_format,
  2361. slim_rx_bit_format_get, slim_rx_bit_format_put),
  2362. SOC_ENUM_EXT("SLIM_6_RX Format", slim_6_rx_format,
  2363. slim_rx_bit_format_get, slim_rx_bit_format_put),
  2364. SOC_ENUM_EXT("SLIM_0_TX Format", slim_0_tx_format,
  2365. slim_tx_bit_format_get, slim_tx_bit_format_put),
  2366. SOC_ENUM_EXT("USB_AUDIO_RX Format", usb_rx_format,
  2367. usb_audio_rx_format_get, usb_audio_rx_format_put),
  2368. SOC_ENUM_EXT("USB_AUDIO_TX Format", usb_tx_format,
  2369. usb_audio_tx_format_get, usb_audio_tx_format_put),
  2370. SOC_ENUM_EXT("Display Port RX Bit Format", ext_disp_rx_format,
  2371. ext_disp_rx_format_get, ext_disp_rx_format_put),
  2372. SOC_ENUM_EXT("SLIM_0_RX SampleRate", slim_0_rx_sample_rate,
  2373. slim_rx_sample_rate_get, slim_rx_sample_rate_put),
  2374. SOC_ENUM_EXT("SLIM_2_RX SampleRate", slim_2_rx_sample_rate,
  2375. slim_rx_sample_rate_get, slim_rx_sample_rate_put),
  2376. SOC_ENUM_EXT("SLIM_0_TX SampleRate", slim_0_tx_sample_rate,
  2377. slim_tx_sample_rate_get, slim_tx_sample_rate_put),
  2378. SOC_ENUM_EXT("SLIM_5_RX SampleRate", slim_5_rx_sample_rate,
  2379. slim_rx_sample_rate_get, slim_rx_sample_rate_put),
  2380. SOC_ENUM_EXT("SLIM_6_RX SampleRate", slim_6_rx_sample_rate,
  2381. slim_rx_sample_rate_get, slim_rx_sample_rate_put),
  2382. SOC_ENUM_EXT("BT SampleRate", bt_sample_rate,
  2383. msm_bt_sample_rate_get,
  2384. msm_bt_sample_rate_put),
  2385. SOC_ENUM_EXT("USB_AUDIO_RX SampleRate", usb_rx_sample_rate,
  2386. usb_audio_rx_sample_rate_get,
  2387. usb_audio_rx_sample_rate_put),
  2388. SOC_ENUM_EXT("USB_AUDIO_TX SampleRate", usb_tx_sample_rate,
  2389. usb_audio_tx_sample_rate_get,
  2390. usb_audio_tx_sample_rate_put),
  2391. SOC_ENUM_EXT("Display Port RX SampleRate", ext_disp_rx_sample_rate,
  2392. ext_disp_rx_sample_rate_get,
  2393. ext_disp_rx_sample_rate_put),
  2394. SOC_ENUM_EXT("PRI_TDM_RX_0 SampleRate", tdm_rx_sample_rate,
  2395. tdm_rx_sample_rate_get,
  2396. tdm_rx_sample_rate_put),
  2397. SOC_ENUM_EXT("PRI_TDM_TX_0 SampleRate", tdm_tx_sample_rate,
  2398. tdm_tx_sample_rate_get,
  2399. tdm_tx_sample_rate_put),
  2400. SOC_ENUM_EXT("PRI_TDM_RX_0 Format", tdm_rx_format,
  2401. tdm_rx_format_get,
  2402. tdm_rx_format_put),
  2403. SOC_ENUM_EXT("PRI_TDM_TX_0 Format", tdm_tx_format,
  2404. tdm_tx_format_get,
  2405. tdm_tx_format_put),
  2406. SOC_ENUM_EXT("PRI_TDM_RX_0 Channels", tdm_rx_chs,
  2407. tdm_rx_ch_get,
  2408. tdm_rx_ch_put),
  2409. SOC_ENUM_EXT("PRI_TDM_TX_0 Channels", tdm_tx_chs,
  2410. tdm_tx_ch_get,
  2411. tdm_tx_ch_put),
  2412. SOC_ENUM_EXT("SEC_TDM_RX_0 SampleRate", tdm_rx_sample_rate,
  2413. tdm_rx_sample_rate_get,
  2414. tdm_rx_sample_rate_put),
  2415. SOC_ENUM_EXT("SEC_TDM_TX_0 SampleRate", tdm_tx_sample_rate,
  2416. tdm_tx_sample_rate_get,
  2417. tdm_tx_sample_rate_put),
  2418. SOC_ENUM_EXT("SEC_TDM_RX_0 Format", tdm_rx_format,
  2419. tdm_rx_format_get,
  2420. tdm_rx_format_put),
  2421. SOC_ENUM_EXT("SEC_TDM_TX_0 Format", tdm_tx_format,
  2422. tdm_tx_format_get,
  2423. tdm_tx_format_put),
  2424. SOC_ENUM_EXT("SEC_TDM_RX_0 Channels", tdm_rx_chs,
  2425. tdm_rx_ch_get,
  2426. tdm_rx_ch_put),
  2427. SOC_ENUM_EXT("SEC_TDM_TX_0 Channels", tdm_tx_chs,
  2428. tdm_tx_ch_get,
  2429. tdm_tx_ch_put),
  2430. SOC_ENUM_EXT("TERT_TDM_RX_0 SampleRate", tdm_rx_sample_rate,
  2431. tdm_rx_sample_rate_get,
  2432. tdm_rx_sample_rate_put),
  2433. SOC_ENUM_EXT("TERT_TDM_TX_0 SampleRate", tdm_tx_sample_rate,
  2434. tdm_tx_sample_rate_get,
  2435. tdm_tx_sample_rate_put),
  2436. SOC_ENUM_EXT("TERT_TDM_RX_0 Format", tdm_rx_format,
  2437. tdm_rx_format_get,
  2438. tdm_rx_format_put),
  2439. SOC_ENUM_EXT("TERT_TDM_TX_0 Format", tdm_tx_format,
  2440. tdm_tx_format_get,
  2441. tdm_tx_format_put),
  2442. SOC_ENUM_EXT("TERT_TDM_RX_0 Channels", tdm_rx_chs,
  2443. tdm_rx_ch_get,
  2444. tdm_rx_ch_put),
  2445. SOC_ENUM_EXT("TERT_TDM_TX_0 Channels", tdm_tx_chs,
  2446. tdm_tx_ch_get,
  2447. tdm_tx_ch_put),
  2448. SOC_ENUM_EXT("QUAT_TDM_RX_0 SampleRate", tdm_rx_sample_rate,
  2449. tdm_rx_sample_rate_get,
  2450. tdm_rx_sample_rate_put),
  2451. SOC_ENUM_EXT("QUAT_TDM_TX_0 SampleRate", tdm_tx_sample_rate,
  2452. tdm_tx_sample_rate_get,
  2453. tdm_tx_sample_rate_put),
  2454. SOC_ENUM_EXT("QUAT_TDM_RX_0 Format", tdm_rx_format,
  2455. tdm_rx_format_get,
  2456. tdm_rx_format_put),
  2457. SOC_ENUM_EXT("QUAT_TDM_TX_0 Format", tdm_tx_format,
  2458. tdm_tx_format_get,
  2459. tdm_tx_format_put),
  2460. SOC_ENUM_EXT("QUAT_TDM_RX_0 Channels", tdm_rx_chs,
  2461. tdm_rx_ch_get,
  2462. tdm_rx_ch_put),
  2463. SOC_ENUM_EXT("QUAT_TDM_TX_0 Channels", tdm_tx_chs,
  2464. tdm_tx_ch_get,
  2465. tdm_tx_ch_put),
  2466. SOC_ENUM_EXT("PRIM_AUX_PCM_RX SampleRate", prim_aux_pcm_rx_sample_rate,
  2467. aux_pcm_rx_sample_rate_get,
  2468. aux_pcm_rx_sample_rate_put),
  2469. SOC_ENUM_EXT("SEC_AUX_PCM_RX SampleRate", sec_aux_pcm_rx_sample_rate,
  2470. aux_pcm_rx_sample_rate_get,
  2471. aux_pcm_rx_sample_rate_put),
  2472. SOC_ENUM_EXT("TERT_AUX_PCM_RX SampleRate", tert_aux_pcm_rx_sample_rate,
  2473. aux_pcm_rx_sample_rate_get,
  2474. aux_pcm_rx_sample_rate_put),
  2475. SOC_ENUM_EXT("QUAT_AUX_PCM_RX SampleRate", quat_aux_pcm_rx_sample_rate,
  2476. aux_pcm_rx_sample_rate_get,
  2477. aux_pcm_rx_sample_rate_put),
  2478. SOC_ENUM_EXT("PRIM_AUX_PCM_TX SampleRate", prim_aux_pcm_tx_sample_rate,
  2479. aux_pcm_tx_sample_rate_get,
  2480. aux_pcm_tx_sample_rate_put),
  2481. SOC_ENUM_EXT("SEC_AUX_PCM_TX SampleRate", sec_aux_pcm_tx_sample_rate,
  2482. aux_pcm_tx_sample_rate_get,
  2483. aux_pcm_tx_sample_rate_put),
  2484. SOC_ENUM_EXT("TERT_AUX_PCM_TX SampleRate", tert_aux_pcm_tx_sample_rate,
  2485. aux_pcm_tx_sample_rate_get,
  2486. aux_pcm_tx_sample_rate_put),
  2487. SOC_ENUM_EXT("QUAT_AUX_PCM_TX SampleRate", quat_aux_pcm_tx_sample_rate,
  2488. aux_pcm_tx_sample_rate_get,
  2489. aux_pcm_tx_sample_rate_put),
  2490. SOC_ENUM_EXT("PRIM_MI2S_RX SampleRate", prim_mi2s_rx_sample_rate,
  2491. mi2s_rx_sample_rate_get,
  2492. mi2s_rx_sample_rate_put),
  2493. SOC_ENUM_EXT("SEC_MI2S_RX SampleRate", sec_mi2s_rx_sample_rate,
  2494. mi2s_rx_sample_rate_get,
  2495. mi2s_rx_sample_rate_put),
  2496. SOC_ENUM_EXT("TERT_MI2S_RX SampleRate", tert_mi2s_rx_sample_rate,
  2497. mi2s_rx_sample_rate_get,
  2498. mi2s_rx_sample_rate_put),
  2499. SOC_ENUM_EXT("QUAT_MI2S_RX SampleRate", quat_mi2s_rx_sample_rate,
  2500. mi2s_rx_sample_rate_get,
  2501. mi2s_rx_sample_rate_put),
  2502. SOC_ENUM_EXT("PRIM_MI2S_TX SampleRate", prim_mi2s_tx_sample_rate,
  2503. mi2s_tx_sample_rate_get,
  2504. mi2s_tx_sample_rate_put),
  2505. SOC_ENUM_EXT("SEC_MI2S_TX SampleRate", sec_mi2s_tx_sample_rate,
  2506. mi2s_tx_sample_rate_get,
  2507. mi2s_tx_sample_rate_put),
  2508. SOC_ENUM_EXT("TERT_MI2S_TX SampleRate", tert_mi2s_tx_sample_rate,
  2509. mi2s_tx_sample_rate_get,
  2510. mi2s_tx_sample_rate_put),
  2511. SOC_ENUM_EXT("QUAT_MI2S_TX SampleRate", quat_mi2s_tx_sample_rate,
  2512. mi2s_tx_sample_rate_get,
  2513. mi2s_tx_sample_rate_put),
  2514. SOC_ENUM_EXT("PRIM_MI2S_RX Channels", prim_mi2s_rx_chs,
  2515. msm_mi2s_rx_ch_get, msm_mi2s_rx_ch_put),
  2516. SOC_ENUM_EXT("PRIM_MI2S_TX Channels", prim_mi2s_tx_chs,
  2517. msm_mi2s_tx_ch_get, msm_mi2s_tx_ch_put),
  2518. SOC_ENUM_EXT("SEC_MI2S_RX Channels", sec_mi2s_rx_chs,
  2519. msm_mi2s_rx_ch_get, msm_mi2s_rx_ch_put),
  2520. SOC_ENUM_EXT("SEC_MI2S_TX Channels", sec_mi2s_tx_chs,
  2521. msm_mi2s_tx_ch_get, msm_mi2s_tx_ch_put),
  2522. SOC_ENUM_EXT("TERT_MI2S_RX Channels", tert_mi2s_rx_chs,
  2523. msm_mi2s_rx_ch_get, msm_mi2s_rx_ch_put),
  2524. SOC_ENUM_EXT("TERT_MI2S_TX Channels", tert_mi2s_tx_chs,
  2525. msm_mi2s_tx_ch_get, msm_mi2s_tx_ch_put),
  2526. SOC_ENUM_EXT("QUAT_MI2S_RX Channels", quat_mi2s_rx_chs,
  2527. msm_mi2s_rx_ch_get, msm_mi2s_rx_ch_put),
  2528. SOC_ENUM_EXT("QUAT_MI2S_TX Channels", quat_mi2s_tx_chs,
  2529. msm_mi2s_tx_ch_get, msm_mi2s_tx_ch_put),
  2530. SOC_ENUM_EXT("PRIM_MI2S_RX Format", mi2s_rx_format,
  2531. msm_mi2s_rx_format_get, msm_mi2s_rx_format_put),
  2532. SOC_ENUM_EXT("PRIM_MI2S_TX Format", mi2s_tx_format,
  2533. msm_mi2s_tx_format_get, msm_mi2s_tx_format_put),
  2534. SOC_ENUM_EXT("SEC_MI2S_RX Format", mi2s_rx_format,
  2535. msm_mi2s_rx_format_get, msm_mi2s_rx_format_put),
  2536. SOC_ENUM_EXT("SEC_MI2S_TX Format", mi2s_tx_format,
  2537. msm_mi2s_tx_format_get, msm_mi2s_tx_format_put),
  2538. SOC_ENUM_EXT("TERT_MI2S_RX Format", mi2s_rx_format,
  2539. msm_mi2s_rx_format_get, msm_mi2s_rx_format_put),
  2540. SOC_ENUM_EXT("TERT_MI2S_TX Format", mi2s_tx_format,
  2541. msm_mi2s_tx_format_get, msm_mi2s_tx_format_put),
  2542. SOC_ENUM_EXT("QUAT_MI2S_RX Format", mi2s_rx_format,
  2543. msm_mi2s_rx_format_get, msm_mi2s_rx_format_put),
  2544. SOC_ENUM_EXT("QUAT_MI2S_TX Format", mi2s_tx_format,
  2545. msm_mi2s_tx_format_get, msm_mi2s_tx_format_put),
  2546. SOC_ENUM_EXT("PRIM_AUX_PCM_RX Format", aux_pcm_rx_format,
  2547. msm_aux_pcm_rx_format_get, msm_aux_pcm_rx_format_put),
  2548. SOC_ENUM_EXT("PRIM_AUX_PCM_TX Format", aux_pcm_tx_format,
  2549. msm_aux_pcm_tx_format_get, msm_aux_pcm_tx_format_put),
  2550. SOC_ENUM_EXT("SEC_AUX_PCM_RX Format", aux_pcm_rx_format,
  2551. msm_aux_pcm_rx_format_get, msm_aux_pcm_rx_format_put),
  2552. SOC_ENUM_EXT("SEC_AUX_PCM_TX Format", aux_pcm_tx_format,
  2553. msm_aux_pcm_tx_format_get, msm_aux_pcm_tx_format_put),
  2554. SOC_ENUM_EXT("TERT_AUX_PCM_RX Format", aux_pcm_rx_format,
  2555. msm_aux_pcm_rx_format_get, msm_aux_pcm_rx_format_put),
  2556. SOC_ENUM_EXT("TERT_AUX_PCM_TX Format", aux_pcm_tx_format,
  2557. msm_aux_pcm_tx_format_get, msm_aux_pcm_tx_format_put),
  2558. SOC_ENUM_EXT("QUAT_AUX_PCM_RX Format", aux_pcm_rx_format,
  2559. msm_aux_pcm_rx_format_get, msm_aux_pcm_rx_format_put),
  2560. SOC_ENUM_EXT("QUAT_AUX_PCM_TX Format", aux_pcm_tx_format,
  2561. msm_aux_pcm_tx_format_get, msm_aux_pcm_tx_format_put),
  2562. SOC_ENUM_EXT("HiFi Function", hifi_function, msm_hifi_get,
  2563. msm_hifi_put),
  2564. SOC_ENUM_EXT("MultiMedia5_RX QOS Vote", qos_vote, msm_qos_ctl_get,
  2565. msm_qos_ctl_put),
  2566. };
  2567. static int msm_snd_enable_codec_ext_clk(struct snd_soc_codec *codec,
  2568. int enable, bool dapm)
  2569. {
  2570. int ret = 0;
  2571. if (!strcmp(dev_name(codec->dev), "tavil_codec")) {
  2572. ret = tavil_cdc_mclk_enable(codec, enable);
  2573. } else {
  2574. dev_err(codec->dev, "%s: unknown codec to enable ext clk\n",
  2575. __func__);
  2576. ret = -EINVAL;
  2577. }
  2578. return ret;
  2579. }
  2580. static int msm_snd_enable_codec_ext_tx_clk(struct snd_soc_codec *codec,
  2581. int enable, bool dapm)
  2582. {
  2583. int ret = 0;
  2584. if (!strcmp(dev_name(codec->dev), "tavil_codec")) {
  2585. ret = tavil_cdc_mclk_tx_enable(codec, enable);
  2586. } else {
  2587. dev_err(codec->dev, "%s: unknown codec to enable TX ext clk\n",
  2588. __func__);
  2589. ret = -EINVAL;
  2590. }
  2591. return ret;
  2592. }
  2593. static int msm_mclk_tx_event(struct snd_soc_dapm_widget *w,
  2594. struct snd_kcontrol *kcontrol, int event)
  2595. {
  2596. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2597. pr_debug("%s: event = %d\n", __func__, event);
  2598. switch (event) {
  2599. case SND_SOC_DAPM_PRE_PMU:
  2600. return msm_snd_enable_codec_ext_tx_clk(codec, 1, true);
  2601. case SND_SOC_DAPM_POST_PMD:
  2602. return msm_snd_enable_codec_ext_tx_clk(codec, 0, true);
  2603. }
  2604. return 0;
  2605. }
  2606. static int msm_mclk_event(struct snd_soc_dapm_widget *w,
  2607. struct snd_kcontrol *kcontrol, int event)
  2608. {
  2609. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2610. pr_debug("%s: event = %d\n", __func__, event);
  2611. switch (event) {
  2612. case SND_SOC_DAPM_PRE_PMU:
  2613. return msm_snd_enable_codec_ext_clk(codec, 1, true);
  2614. case SND_SOC_DAPM_POST_PMD:
  2615. return msm_snd_enable_codec_ext_clk(codec, 0, true);
  2616. }
  2617. return 0;
  2618. }
  2619. static int msm_hifi_ctrl_event(struct snd_soc_dapm_widget *w,
  2620. struct snd_kcontrol *k, int event)
  2621. {
  2622. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2623. struct snd_soc_card *card = codec->component.card;
  2624. struct msm_asoc_mach_data *pdata =
  2625. snd_soc_card_get_drvdata(card);
  2626. pr_debug("%s: msm_hifi_control = %d", __func__, msm_hifi_control);
  2627. if (!pdata || !pdata->hph_en0_gpio_p) {
  2628. pr_err("%s: hph_en0_gpio is invalid\n", __func__);
  2629. return -EINVAL;
  2630. }
  2631. if (msm_hifi_control != MSM_HIFI_ON) {
  2632. pr_debug("%s: HiFi mixer control is not set\n",
  2633. __func__);
  2634. return 0;
  2635. }
  2636. switch (event) {
  2637. case SND_SOC_DAPM_POST_PMU:
  2638. msm_cdc_pinctrl_select_active_state(pdata->hph_en0_gpio_p);
  2639. break;
  2640. case SND_SOC_DAPM_PRE_PMD:
  2641. msm_cdc_pinctrl_select_sleep_state(pdata->hph_en0_gpio_p);
  2642. break;
  2643. }
  2644. return 0;
  2645. }
  2646. static const struct snd_soc_dapm_widget msm_dapm_widgets[] = {
  2647. SND_SOC_DAPM_SUPPLY("MCLK", SND_SOC_NOPM, 0, 0,
  2648. msm_mclk_event,
  2649. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2650. SND_SOC_DAPM_SUPPLY("MCLK TX", SND_SOC_NOPM, 0, 0,
  2651. msm_mclk_tx_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2652. SND_SOC_DAPM_SPK("Lineout_1 amp", NULL),
  2653. SND_SOC_DAPM_SPK("Lineout_2 amp", NULL),
  2654. SND_SOC_DAPM_SPK("hifi amp", msm_hifi_ctrl_event),
  2655. SND_SOC_DAPM_MIC("Handset Mic", NULL),
  2656. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  2657. SND_SOC_DAPM_MIC("ANCRight Headset Mic", NULL),
  2658. SND_SOC_DAPM_MIC("ANCLeft Headset Mic", NULL),
  2659. SND_SOC_DAPM_MIC("Analog Mic5", NULL),
  2660. SND_SOC_DAPM_MIC("Digital Mic0", NULL),
  2661. SND_SOC_DAPM_MIC("Digital Mic1", NULL),
  2662. SND_SOC_DAPM_MIC("Digital Mic2", NULL),
  2663. SND_SOC_DAPM_MIC("Digital Mic3", NULL),
  2664. SND_SOC_DAPM_MIC("Digital Mic4", NULL),
  2665. SND_SOC_DAPM_MIC("Digital Mic5", NULL),
  2666. };
  2667. static inline int param_is_mask(int p)
  2668. {
  2669. return (p >= SNDRV_PCM_HW_PARAM_FIRST_MASK) &&
  2670. (p <= SNDRV_PCM_HW_PARAM_LAST_MASK);
  2671. }
  2672. static inline struct snd_mask *param_to_mask(struct snd_pcm_hw_params *p,
  2673. int n)
  2674. {
  2675. return &(p->masks[n - SNDRV_PCM_HW_PARAM_FIRST_MASK]);
  2676. }
  2677. static void param_set_mask(struct snd_pcm_hw_params *p, int n,
  2678. unsigned int bit)
  2679. {
  2680. if (bit >= SNDRV_MASK_MAX)
  2681. return;
  2682. if (param_is_mask(n)) {
  2683. struct snd_mask *m = param_to_mask(p, n);
  2684. m->bits[0] = 0;
  2685. m->bits[1] = 0;
  2686. m->bits[bit >> 5] |= (1 << (bit & 31));
  2687. }
  2688. }
  2689. static int msm_slim_get_ch_from_beid(int32_t be_id)
  2690. {
  2691. int ch_id = 0;
  2692. switch (be_id) {
  2693. case MSM_BACKEND_DAI_SLIMBUS_0_RX:
  2694. ch_id = SLIM_RX_0;
  2695. break;
  2696. case MSM_BACKEND_DAI_SLIMBUS_1_RX:
  2697. ch_id = SLIM_RX_1;
  2698. break;
  2699. case MSM_BACKEND_DAI_SLIMBUS_2_RX:
  2700. ch_id = SLIM_RX_2;
  2701. break;
  2702. case MSM_BACKEND_DAI_SLIMBUS_3_RX:
  2703. ch_id = SLIM_RX_3;
  2704. break;
  2705. case MSM_BACKEND_DAI_SLIMBUS_4_RX:
  2706. ch_id = SLIM_RX_4;
  2707. break;
  2708. case MSM_BACKEND_DAI_SLIMBUS_6_RX:
  2709. ch_id = SLIM_RX_6;
  2710. break;
  2711. case MSM_BACKEND_DAI_SLIMBUS_0_TX:
  2712. ch_id = SLIM_TX_0;
  2713. break;
  2714. case MSM_BACKEND_DAI_SLIMBUS_3_TX:
  2715. ch_id = SLIM_TX_3;
  2716. break;
  2717. default:
  2718. ch_id = SLIM_RX_0;
  2719. break;
  2720. }
  2721. return ch_id;
  2722. }
  2723. static int msm_ext_disp_get_idx_from_beid(int32_t be_id)
  2724. {
  2725. int idx;
  2726. switch (be_id) {
  2727. case MSM_BACKEND_DAI_DISPLAY_PORT_RX:
  2728. idx = DP_RX_IDX;
  2729. break;
  2730. default:
  2731. pr_err("%s: Incorrect ext_disp BE id %d\n", __func__, be_id);
  2732. idx = -EINVAL;
  2733. break;
  2734. }
  2735. return idx;
  2736. }
  2737. static int msm_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
  2738. struct snd_pcm_hw_params *params)
  2739. {
  2740. struct snd_soc_dai_link *dai_link = rtd->dai_link;
  2741. struct snd_interval *rate = hw_param_interval(params,
  2742. SNDRV_PCM_HW_PARAM_RATE);
  2743. struct snd_interval *channels = hw_param_interval(params,
  2744. SNDRV_PCM_HW_PARAM_CHANNELS);
  2745. int rc = 0;
  2746. int idx;
  2747. void *config = NULL;
  2748. struct snd_soc_codec *codec = NULL;
  2749. pr_debug("%s: format = %d, rate = %d\n",
  2750. __func__, params_format(params), params_rate(params));
  2751. switch (dai_link->id) {
  2752. case MSM_BACKEND_DAI_SLIMBUS_0_RX:
  2753. case MSM_BACKEND_DAI_SLIMBUS_1_RX:
  2754. case MSM_BACKEND_DAI_SLIMBUS_2_RX:
  2755. case MSM_BACKEND_DAI_SLIMBUS_3_RX:
  2756. case MSM_BACKEND_DAI_SLIMBUS_4_RX:
  2757. case MSM_BACKEND_DAI_SLIMBUS_6_RX:
  2758. idx = msm_slim_get_ch_from_beid(dai_link->id);
  2759. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2760. slim_rx_cfg[idx].bit_format);
  2761. rate->min = rate->max = slim_rx_cfg[idx].sample_rate;
  2762. channels->min = channels->max = slim_rx_cfg[idx].channels;
  2763. break;
  2764. case MSM_BACKEND_DAI_SLIMBUS_0_TX:
  2765. case MSM_BACKEND_DAI_SLIMBUS_3_TX:
  2766. idx = msm_slim_get_ch_from_beid(dai_link->id);
  2767. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2768. slim_tx_cfg[idx].bit_format);
  2769. rate->min = rate->max = slim_tx_cfg[idx].sample_rate;
  2770. channels->min = channels->max = slim_tx_cfg[idx].channels;
  2771. break;
  2772. case MSM_BACKEND_DAI_SLIMBUS_1_TX:
  2773. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2774. slim_tx_cfg[1].bit_format);
  2775. rate->min = rate->max = slim_tx_cfg[1].sample_rate;
  2776. channels->min = channels->max = slim_tx_cfg[1].channels;
  2777. break;
  2778. case MSM_BACKEND_DAI_SLIMBUS_4_TX:
  2779. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2780. SNDRV_PCM_FORMAT_S32_LE);
  2781. rate->min = rate->max = SAMPLING_RATE_8KHZ;
  2782. channels->min = channels->max = msm_vi_feed_tx_ch;
  2783. break;
  2784. case MSM_BACKEND_DAI_SLIMBUS_5_RX:
  2785. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2786. slim_rx_cfg[5].bit_format);
  2787. rate->min = rate->max = slim_rx_cfg[5].sample_rate;
  2788. channels->min = channels->max = slim_rx_cfg[5].channels;
  2789. break;
  2790. case MSM_BACKEND_DAI_SLIMBUS_5_TX:
  2791. codec = rtd->codec;
  2792. rate->min = rate->max = SAMPLING_RATE_16KHZ;
  2793. channels->min = channels->max = 1;
  2794. config = msm_codec_fn.get_afe_config_fn(codec,
  2795. AFE_SLIMBUS_SLAVE_PORT_CONFIG);
  2796. if (config) {
  2797. rc = afe_set_config(AFE_SLIMBUS_SLAVE_PORT_CONFIG,
  2798. config, SLIMBUS_5_TX);
  2799. if (rc)
  2800. pr_err("%s: Failed to set slimbus slave port config %d\n",
  2801. __func__, rc);
  2802. }
  2803. break;
  2804. case MSM_BACKEND_DAI_SLIMBUS_7_RX:
  2805. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2806. slim_rx_cfg[SLIM_RX_7].bit_format);
  2807. rate->min = rate->max = slim_rx_cfg[SLIM_RX_7].sample_rate;
  2808. channels->min = channels->max =
  2809. slim_rx_cfg[SLIM_RX_7].channels;
  2810. break;
  2811. case MSM_BACKEND_DAI_SLIMBUS_7_TX:
  2812. rate->min = rate->max = slim_tx_cfg[SLIM_TX_7].sample_rate;
  2813. channels->min = channels->max =
  2814. slim_tx_cfg[SLIM_TX_7].channels;
  2815. break;
  2816. case MSM_BACKEND_DAI_SLIMBUS_8_TX:
  2817. rate->min = rate->max = slim_tx_cfg[SLIM_TX_8].sample_rate;
  2818. channels->min = channels->max =
  2819. slim_tx_cfg[SLIM_TX_8].channels;
  2820. break;
  2821. case MSM_BACKEND_DAI_USB_RX:
  2822. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2823. usb_rx_cfg.bit_format);
  2824. rate->min = rate->max = usb_rx_cfg.sample_rate;
  2825. channels->min = channels->max = usb_rx_cfg.channels;
  2826. break;
  2827. case MSM_BACKEND_DAI_USB_TX:
  2828. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2829. usb_tx_cfg.bit_format);
  2830. rate->min = rate->max = usb_tx_cfg.sample_rate;
  2831. channels->min = channels->max = usb_tx_cfg.channels;
  2832. break;
  2833. case MSM_BACKEND_DAI_DISPLAY_PORT_RX:
  2834. idx = msm_ext_disp_get_idx_from_beid(dai_link->id);
  2835. if (idx < 0) {
  2836. pr_err("%s: Incorrect ext disp idx %d\n",
  2837. __func__, idx);
  2838. rc = idx;
  2839. goto done;
  2840. }
  2841. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2842. ext_disp_rx_cfg[idx].bit_format);
  2843. rate->min = rate->max = ext_disp_rx_cfg[idx].sample_rate;
  2844. channels->min = channels->max = ext_disp_rx_cfg[idx].channels;
  2845. break;
  2846. case MSM_BACKEND_DAI_AFE_PCM_RX:
  2847. channels->min = channels->max = proxy_rx_cfg.channels;
  2848. rate->min = rate->max = SAMPLING_RATE_48KHZ;
  2849. break;
  2850. case MSM_BACKEND_DAI_PRI_TDM_RX_0:
  2851. channels->min = channels->max =
  2852. tdm_rx_cfg[TDM_PRI][TDM_0].channels;
  2853. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2854. tdm_rx_cfg[TDM_PRI][TDM_0].bit_format);
  2855. rate->min = rate->max = tdm_rx_cfg[TDM_PRI][TDM_0].sample_rate;
  2856. break;
  2857. case MSM_BACKEND_DAI_PRI_TDM_TX_0:
  2858. channels->min = channels->max =
  2859. tdm_tx_cfg[TDM_PRI][TDM_0].channels;
  2860. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2861. tdm_tx_cfg[TDM_PRI][TDM_0].bit_format);
  2862. rate->min = rate->max = tdm_tx_cfg[TDM_PRI][TDM_0].sample_rate;
  2863. break;
  2864. case MSM_BACKEND_DAI_SEC_TDM_RX_0:
  2865. channels->min = channels->max =
  2866. tdm_rx_cfg[TDM_SEC][TDM_0].channels;
  2867. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2868. tdm_rx_cfg[TDM_SEC][TDM_0].bit_format);
  2869. rate->min = rate->max = tdm_rx_cfg[TDM_SEC][TDM_0].sample_rate;
  2870. break;
  2871. case MSM_BACKEND_DAI_SEC_TDM_TX_0:
  2872. channels->min = channels->max =
  2873. tdm_tx_cfg[TDM_SEC][TDM_0].channels;
  2874. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2875. tdm_tx_cfg[TDM_SEC][TDM_0].bit_format);
  2876. rate->min = rate->max = tdm_tx_cfg[TDM_SEC][TDM_0].sample_rate;
  2877. break;
  2878. case MSM_BACKEND_DAI_TERT_TDM_RX_0:
  2879. channels->min = channels->max =
  2880. tdm_rx_cfg[TDM_TERT][TDM_0].channels;
  2881. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2882. tdm_rx_cfg[TDM_TERT][TDM_0].bit_format);
  2883. rate->min = rate->max = tdm_rx_cfg[TDM_TERT][TDM_0].sample_rate;
  2884. break;
  2885. case MSM_BACKEND_DAI_TERT_TDM_TX_0:
  2886. channels->min = channels->max =
  2887. tdm_tx_cfg[TDM_TERT][TDM_0].channels;
  2888. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2889. tdm_tx_cfg[TDM_TERT][TDM_0].bit_format);
  2890. rate->min = rate->max = tdm_tx_cfg[TDM_TERT][TDM_0].sample_rate;
  2891. break;
  2892. case MSM_BACKEND_DAI_QUAT_TDM_RX_0:
  2893. channels->min = channels->max =
  2894. tdm_rx_cfg[TDM_QUAT][TDM_0].channels;
  2895. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2896. tdm_rx_cfg[TDM_QUAT][TDM_0].bit_format);
  2897. rate->min = rate->max = tdm_rx_cfg[TDM_QUAT][TDM_0].sample_rate;
  2898. break;
  2899. case MSM_BACKEND_DAI_QUAT_TDM_TX_0:
  2900. channels->min = channels->max =
  2901. tdm_tx_cfg[TDM_QUAT][TDM_0].channels;
  2902. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2903. tdm_tx_cfg[TDM_QUAT][TDM_0].bit_format);
  2904. rate->min = rate->max = tdm_tx_cfg[TDM_QUAT][TDM_0].sample_rate;
  2905. break;
  2906. case MSM_BACKEND_DAI_AUXPCM_RX:
  2907. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2908. aux_pcm_rx_cfg[PRIM_AUX_PCM].bit_format);
  2909. rate->min = rate->max =
  2910. aux_pcm_rx_cfg[PRIM_AUX_PCM].sample_rate;
  2911. channels->min = channels->max =
  2912. aux_pcm_rx_cfg[PRIM_AUX_PCM].channels;
  2913. break;
  2914. case MSM_BACKEND_DAI_AUXPCM_TX:
  2915. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2916. aux_pcm_tx_cfg[PRIM_AUX_PCM].bit_format);
  2917. rate->min = rate->max =
  2918. aux_pcm_tx_cfg[PRIM_AUX_PCM].sample_rate;
  2919. channels->min = channels->max =
  2920. aux_pcm_tx_cfg[PRIM_AUX_PCM].channels;
  2921. break;
  2922. case MSM_BACKEND_DAI_SEC_AUXPCM_RX:
  2923. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2924. aux_pcm_rx_cfg[SEC_AUX_PCM].bit_format);
  2925. rate->min = rate->max =
  2926. aux_pcm_rx_cfg[SEC_AUX_PCM].sample_rate;
  2927. channels->min = channels->max =
  2928. aux_pcm_rx_cfg[SEC_AUX_PCM].channels;
  2929. break;
  2930. case MSM_BACKEND_DAI_SEC_AUXPCM_TX:
  2931. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2932. aux_pcm_tx_cfg[SEC_AUX_PCM].bit_format);
  2933. rate->min = rate->max =
  2934. aux_pcm_tx_cfg[SEC_AUX_PCM].sample_rate;
  2935. channels->min = channels->max =
  2936. aux_pcm_tx_cfg[SEC_AUX_PCM].channels;
  2937. break;
  2938. case MSM_BACKEND_DAI_TERT_AUXPCM_RX:
  2939. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2940. aux_pcm_rx_cfg[TERT_AUX_PCM].bit_format);
  2941. rate->min = rate->max =
  2942. aux_pcm_rx_cfg[TERT_AUX_PCM].sample_rate;
  2943. channels->min = channels->max =
  2944. aux_pcm_rx_cfg[TERT_AUX_PCM].channels;
  2945. break;
  2946. case MSM_BACKEND_DAI_TERT_AUXPCM_TX:
  2947. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2948. aux_pcm_tx_cfg[TERT_AUX_PCM].bit_format);
  2949. rate->min = rate->max =
  2950. aux_pcm_tx_cfg[TERT_AUX_PCM].sample_rate;
  2951. channels->min = channels->max =
  2952. aux_pcm_tx_cfg[TERT_AUX_PCM].channels;
  2953. break;
  2954. case MSM_BACKEND_DAI_QUAT_AUXPCM_RX:
  2955. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2956. aux_pcm_rx_cfg[QUAT_AUX_PCM].bit_format);
  2957. rate->min = rate->max =
  2958. aux_pcm_rx_cfg[QUAT_AUX_PCM].sample_rate;
  2959. channels->min = channels->max =
  2960. aux_pcm_rx_cfg[QUAT_AUX_PCM].channels;
  2961. break;
  2962. case MSM_BACKEND_DAI_QUAT_AUXPCM_TX:
  2963. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2964. aux_pcm_tx_cfg[QUAT_AUX_PCM].bit_format);
  2965. rate->min = rate->max =
  2966. aux_pcm_tx_cfg[QUAT_AUX_PCM].sample_rate;
  2967. channels->min = channels->max =
  2968. aux_pcm_tx_cfg[QUAT_AUX_PCM].channels;
  2969. break;
  2970. case MSM_BACKEND_DAI_PRI_MI2S_RX:
  2971. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2972. mi2s_rx_cfg[PRIM_MI2S].bit_format);
  2973. rate->min = rate->max = mi2s_rx_cfg[PRIM_MI2S].sample_rate;
  2974. channels->min = channels->max =
  2975. mi2s_rx_cfg[PRIM_MI2S].channels;
  2976. break;
  2977. case MSM_BACKEND_DAI_PRI_MI2S_TX:
  2978. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2979. mi2s_tx_cfg[PRIM_MI2S].bit_format);
  2980. rate->min = rate->max = mi2s_tx_cfg[PRIM_MI2S].sample_rate;
  2981. channels->min = channels->max =
  2982. mi2s_tx_cfg[PRIM_MI2S].channels;
  2983. break;
  2984. case MSM_BACKEND_DAI_SECONDARY_MI2S_RX:
  2985. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2986. mi2s_rx_cfg[SEC_MI2S].bit_format);
  2987. rate->min = rate->max = mi2s_rx_cfg[SEC_MI2S].sample_rate;
  2988. channels->min = channels->max =
  2989. mi2s_rx_cfg[SEC_MI2S].channels;
  2990. break;
  2991. case MSM_BACKEND_DAI_SECONDARY_MI2S_TX:
  2992. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2993. mi2s_tx_cfg[SEC_MI2S].bit_format);
  2994. rate->min = rate->max = mi2s_tx_cfg[SEC_MI2S].sample_rate;
  2995. channels->min = channels->max =
  2996. mi2s_tx_cfg[SEC_MI2S].channels;
  2997. break;
  2998. case MSM_BACKEND_DAI_TERTIARY_MI2S_RX:
  2999. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  3000. mi2s_rx_cfg[TERT_MI2S].bit_format);
  3001. rate->min = rate->max = mi2s_rx_cfg[TERT_MI2S].sample_rate;
  3002. channels->min = channels->max =
  3003. mi2s_rx_cfg[TERT_MI2S].channels;
  3004. break;
  3005. case MSM_BACKEND_DAI_TERTIARY_MI2S_TX:
  3006. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  3007. mi2s_tx_cfg[TERT_MI2S].bit_format);
  3008. rate->min = rate->max = mi2s_tx_cfg[TERT_MI2S].sample_rate;
  3009. channels->min = channels->max =
  3010. mi2s_tx_cfg[TERT_MI2S].channels;
  3011. break;
  3012. case MSM_BACKEND_DAI_QUATERNARY_MI2S_RX:
  3013. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  3014. mi2s_rx_cfg[QUAT_MI2S].bit_format);
  3015. rate->min = rate->max = mi2s_rx_cfg[QUAT_MI2S].sample_rate;
  3016. channels->min = channels->max =
  3017. mi2s_rx_cfg[QUAT_MI2S].channels;
  3018. break;
  3019. case MSM_BACKEND_DAI_QUATERNARY_MI2S_TX:
  3020. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  3021. mi2s_tx_cfg[QUAT_MI2S].bit_format);
  3022. rate->min = rate->max = mi2s_tx_cfg[QUAT_MI2S].sample_rate;
  3023. channels->min = channels->max =
  3024. mi2s_tx_cfg[QUAT_MI2S].channels;
  3025. break;
  3026. default:
  3027. rate->min = rate->max = SAMPLING_RATE_48KHZ;
  3028. break;
  3029. }
  3030. done:
  3031. return rc;
  3032. }
  3033. static bool msm_usbc_swap_gnd_mic(struct snd_soc_codec *codec, bool active)
  3034. {
  3035. int value = 0;
  3036. bool ret = 0;
  3037. struct snd_soc_card *card = codec->component.card;
  3038. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  3039. struct pinctrl_state *en2_pinctrl_active;
  3040. struct pinctrl_state *en2_pinctrl_sleep;
  3041. if (!pdata->usbc_en2_gpio_p) {
  3042. if (active) {
  3043. /* if active and usbc_en2_gpio undefined, get pin */
  3044. pdata->usbc_en2_gpio_p = devm_pinctrl_get(card->dev);
  3045. if (IS_ERR_OR_NULL(pdata->usbc_en2_gpio_p)) {
  3046. dev_err(card->dev,
  3047. "%s: Can't get EN2 gpio pinctrl:%ld\n",
  3048. __func__,
  3049. PTR_ERR(pdata->usbc_en2_gpio_p));
  3050. pdata->usbc_en2_gpio_p = NULL;
  3051. return false;
  3052. }
  3053. } else
  3054. /* if not active and usbc_en2_gpio undefined, return */
  3055. return false;
  3056. }
  3057. pdata->usbc_en2_gpio = of_get_named_gpio(card->dev->of_node,
  3058. "qcom,usbc-analog-en2-gpio", 0);
  3059. if (!gpio_is_valid(pdata->usbc_en2_gpio)) {
  3060. dev_err(card->dev, "%s, property %s not in node %s",
  3061. __func__, "qcom,usbc-analog-en2-gpio",
  3062. card->dev->of_node->full_name);
  3063. return false;
  3064. }
  3065. en2_pinctrl_active = pinctrl_lookup_state(
  3066. pdata->usbc_en2_gpio_p, "aud_active");
  3067. if (IS_ERR_OR_NULL(en2_pinctrl_active)) {
  3068. dev_err(card->dev,
  3069. "%s: Cannot get aud_active pinctrl state:%ld\n",
  3070. __func__, PTR_ERR(en2_pinctrl_active));
  3071. ret = false;
  3072. goto err_lookup_state;
  3073. }
  3074. en2_pinctrl_sleep = pinctrl_lookup_state(
  3075. pdata->usbc_en2_gpio_p, "aud_sleep");
  3076. if (IS_ERR_OR_NULL(en2_pinctrl_sleep)) {
  3077. dev_err(card->dev,
  3078. "%s: Cannot get aud_sleep pinctrl state:%ld\n",
  3079. __func__, PTR_ERR(en2_pinctrl_sleep));
  3080. ret = false;
  3081. goto err_lookup_state;
  3082. }
  3083. /* if active and usbc_en2_gpio_p defined, swap using usbc_en2_gpio_p */
  3084. if (active) {
  3085. dev_dbg(codec->dev, "%s: enter\n", __func__);
  3086. if (pdata->usbc_en2_gpio_p) {
  3087. value = gpio_get_value_cansleep(pdata->usbc_en2_gpio);
  3088. if (value)
  3089. pinctrl_select_state(pdata->usbc_en2_gpio_p,
  3090. en2_pinctrl_sleep);
  3091. else
  3092. pinctrl_select_state(pdata->usbc_en2_gpio_p,
  3093. en2_pinctrl_active);
  3094. } else if (pdata->usbc_en2_gpio >= 0) {
  3095. value = gpio_get_value_cansleep(pdata->usbc_en2_gpio);
  3096. gpio_set_value_cansleep(pdata->usbc_en2_gpio, !value);
  3097. }
  3098. pr_debug("%s: swap select switch %d to %d\n", __func__,
  3099. value, !value);
  3100. ret = true;
  3101. } else {
  3102. /* if not active, release usbc_en2_gpio_p pin */
  3103. pinctrl_select_state(pdata->usbc_en2_gpio_p,
  3104. en2_pinctrl_sleep);
  3105. }
  3106. err_lookup_state:
  3107. devm_pinctrl_put(pdata->usbc_en2_gpio_p);
  3108. pdata->usbc_en2_gpio_p = NULL;
  3109. return ret;
  3110. }
  3111. static bool msm_swap_gnd_mic(struct snd_soc_codec *codec, bool active)
  3112. {
  3113. int value = 0;
  3114. int ret = 0;
  3115. struct snd_soc_card *card = codec->component.card;
  3116. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  3117. if (!pdata)
  3118. return false;
  3119. if (!wcd_mbhc_cfg.enable_usbc_analog) {
  3120. /* if usbc is not defined, swap using us_euro_gpio_p */
  3121. if (pdata->us_euro_gpio_p) {
  3122. value = msm_cdc_pinctrl_get_state(
  3123. pdata->us_euro_gpio_p);
  3124. if (value)
  3125. msm_cdc_pinctrl_select_sleep_state(
  3126. pdata->us_euro_gpio_p);
  3127. else
  3128. msm_cdc_pinctrl_select_active_state(
  3129. pdata->us_euro_gpio_p);
  3130. } else if (pdata->us_euro_gpio >= 0) {
  3131. value = gpio_get_value_cansleep(
  3132. pdata->us_euro_gpio);
  3133. gpio_set_value_cansleep(
  3134. pdata->us_euro_gpio, !value);
  3135. }
  3136. pr_debug("%s: swap select switch %d to %d\n", __func__,
  3137. value, !value);
  3138. ret = true;
  3139. } else {
  3140. /* if usbc is defined, swap using usbc_en2 */
  3141. ret = msm_usbc_swap_gnd_mic(codec, active);
  3142. }
  3143. return ret;
  3144. }
  3145. static int msm_afe_set_config(struct snd_soc_codec *codec)
  3146. {
  3147. int ret = 0;
  3148. void *config_data = NULL;
  3149. if (!msm_codec_fn.get_afe_config_fn) {
  3150. dev_err(codec->dev, "%s: codec get afe config not init'ed\n",
  3151. __func__);
  3152. return -EINVAL;
  3153. }
  3154. config_data = msm_codec_fn.get_afe_config_fn(codec,
  3155. AFE_CDC_REGISTERS_CONFIG);
  3156. if (config_data) {
  3157. ret = afe_set_config(AFE_CDC_REGISTERS_CONFIG, config_data, 0);
  3158. if (ret) {
  3159. dev_err(codec->dev,
  3160. "%s: Failed to set codec registers config %d\n",
  3161. __func__, ret);
  3162. return ret;
  3163. }
  3164. }
  3165. config_data = msm_codec_fn.get_afe_config_fn(codec,
  3166. AFE_CDC_REGISTER_PAGE_CONFIG);
  3167. if (config_data) {
  3168. ret = afe_set_config(AFE_CDC_REGISTER_PAGE_CONFIG, config_data,
  3169. 0);
  3170. if (ret)
  3171. dev_err(codec->dev,
  3172. "%s: Failed to set cdc register page config\n",
  3173. __func__);
  3174. }
  3175. config_data = msm_codec_fn.get_afe_config_fn(codec,
  3176. AFE_SLIMBUS_SLAVE_CONFIG);
  3177. if (config_data) {
  3178. ret = afe_set_config(AFE_SLIMBUS_SLAVE_CONFIG, config_data, 0);
  3179. if (ret) {
  3180. dev_err(codec->dev,
  3181. "%s: Failed to set slimbus slave config %d\n",
  3182. __func__, ret);
  3183. return ret;
  3184. }
  3185. }
  3186. return 0;
  3187. }
  3188. static void msm_afe_clear_config(void)
  3189. {
  3190. afe_clear_config(AFE_CDC_REGISTERS_CONFIG);
  3191. afe_clear_config(AFE_SLIMBUS_SLAVE_CONFIG);
  3192. }
  3193. static int msm_adsp_power_up_config(struct snd_soc_codec *codec,
  3194. struct snd_card *card)
  3195. {
  3196. int ret = 0;
  3197. unsigned long timeout;
  3198. int adsp_ready = 0;
  3199. bool snd_card_online = 0;
  3200. timeout = jiffies +
  3201. msecs_to_jiffies(ADSP_STATE_READY_TIMEOUT_MS);
  3202. do {
  3203. if (!snd_card_online) {
  3204. snd_card_online = snd_card_is_online_state(card);
  3205. pr_debug("%s: Sound card is %s\n", __func__,
  3206. snd_card_online ? "Online" : "Offline");
  3207. }
  3208. if (!adsp_ready) {
  3209. adsp_ready = q6core_is_adsp_ready();
  3210. pr_debug("%s: ADSP Audio is %s\n", __func__,
  3211. adsp_ready ? "ready" : "not ready");
  3212. }
  3213. if (snd_card_online && adsp_ready)
  3214. break;
  3215. /*
  3216. * Sound card/ADSP will be coming up after subsystem restart and
  3217. * it might not be fully up when the control reaches
  3218. * here. So, wait for 50msec before checking ADSP state
  3219. */
  3220. msleep(50);
  3221. } while (time_after(timeout, jiffies));
  3222. if (!snd_card_online || !adsp_ready) {
  3223. pr_err("%s: Timeout. Sound card is %s, ADSP Audio is %s\n",
  3224. __func__,
  3225. snd_card_online ? "Online" : "Offline",
  3226. adsp_ready ? "ready" : "not ready");
  3227. ret = -ETIMEDOUT;
  3228. goto err;
  3229. }
  3230. ret = msm_afe_set_config(codec);
  3231. if (ret)
  3232. pr_err("%s: Failed to set AFE config. err %d\n",
  3233. __func__, ret);
  3234. return 0;
  3235. err:
  3236. return ret;
  3237. }
  3238. static int sdm845_notifier_service_cb(struct notifier_block *this,
  3239. unsigned long opcode, void *ptr)
  3240. {
  3241. int ret;
  3242. struct snd_soc_card *card = NULL;
  3243. const char *be_dl_name = LPASS_BE_SLIMBUS_0_RX;
  3244. struct snd_soc_pcm_runtime *rtd;
  3245. struct snd_soc_codec *codec;
  3246. pr_debug("%s: Service opcode 0x%lx\n", __func__, opcode);
  3247. switch (opcode) {
  3248. case AUDIO_NOTIFIER_SERVICE_DOWN:
  3249. /*
  3250. * Use flag to ignore initial boot notifications
  3251. * On initial boot msm_adsp_power_up_config is
  3252. * called on init. There is no need to clear
  3253. * and set the config again on initial boot.
  3254. */
  3255. if (is_initial_boot)
  3256. break;
  3257. msm_afe_clear_config();
  3258. break;
  3259. case AUDIO_NOTIFIER_SERVICE_UP:
  3260. if (is_initial_boot) {
  3261. is_initial_boot = false;
  3262. break;
  3263. }
  3264. if (!spdev)
  3265. return -EINVAL;
  3266. card = platform_get_drvdata(spdev);
  3267. rtd = snd_soc_get_pcm_runtime(card, be_dl_name);
  3268. if (!rtd) {
  3269. dev_err(card->dev,
  3270. "%s: snd_soc_get_pcm_runtime for %s failed!\n",
  3271. __func__, be_dl_name);
  3272. ret = -EINVAL;
  3273. goto err;
  3274. }
  3275. codec = rtd->codec;
  3276. ret = msm_adsp_power_up_config(codec, card->snd_card);
  3277. if (ret < 0) {
  3278. dev_err(card->dev,
  3279. "%s: msm_adsp_power_up_config failed ret = %d!\n",
  3280. __func__, ret);
  3281. goto err;
  3282. }
  3283. break;
  3284. default:
  3285. break;
  3286. }
  3287. err:
  3288. return NOTIFY_OK;
  3289. }
  3290. static struct notifier_block service_nb = {
  3291. .notifier_call = sdm845_notifier_service_cb,
  3292. .priority = -INT_MAX,
  3293. };
  3294. static int msm_audrx_init(struct snd_soc_pcm_runtime *rtd)
  3295. {
  3296. int ret = 0;
  3297. void *config_data;
  3298. struct snd_soc_codec *codec = rtd->codec;
  3299. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  3300. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  3301. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  3302. struct snd_soc_component *aux_comp;
  3303. struct snd_card *card;
  3304. struct snd_info_entry *entry;
  3305. struct msm_asoc_mach_data *pdata =
  3306. snd_soc_card_get_drvdata(rtd->card);
  3307. /* Codec SLIMBUS configuration
  3308. * RX1, RX2, RX3, RX4, RX5, RX6, RX7, RX8
  3309. * TX1, TX2, TX3, TX4, TX5, TX6, TX7, TX8, TX9, TX10, TX11, TX12, TX13
  3310. * TX14, TX15, TX16
  3311. */
  3312. unsigned int rx_ch[WCD934X_RX_MAX] = {144, 145, 146, 147, 148, 149,
  3313. 150, 151};
  3314. unsigned int tx_ch[WCD934X_TX_MAX] = {128, 129, 130, 131, 132, 133,
  3315. 134, 135, 136, 137, 138, 139,
  3316. 140, 141, 142, 143};
  3317. pr_info("%s: dev_name%s\n", __func__, dev_name(cpu_dai->dev));
  3318. rtd->pmdown_time = 0;
  3319. ret = snd_soc_add_codec_controls(codec, msm_snd_controls,
  3320. ARRAY_SIZE(msm_snd_controls));
  3321. if (ret < 0) {
  3322. pr_err("%s: add_codec_controls failed, err %d\n",
  3323. __func__, ret);
  3324. return ret;
  3325. }
  3326. snd_soc_dapm_new_controls(dapm, msm_dapm_widgets,
  3327. ARRAY_SIZE(msm_dapm_widgets));
  3328. snd_soc_dapm_add_routes(dapm, wcd_audio_paths,
  3329. ARRAY_SIZE(wcd_audio_paths));
  3330. snd_soc_dapm_ignore_suspend(dapm, "Handset Mic");
  3331. snd_soc_dapm_ignore_suspend(dapm, "Headset Mic");
  3332. snd_soc_dapm_ignore_suspend(dapm, "ANCRight Headset Mic");
  3333. snd_soc_dapm_ignore_suspend(dapm, "ANCLeft Headset Mic");
  3334. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic0");
  3335. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic1");
  3336. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic2");
  3337. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic3");
  3338. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic4");
  3339. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic5");
  3340. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic5");
  3341. snd_soc_dapm_ignore_suspend(dapm, "MADINPUT");
  3342. snd_soc_dapm_ignore_suspend(dapm, "MAD_CPE_INPUT");
  3343. snd_soc_dapm_ignore_suspend(dapm, "MAD_CPE_OUT1");
  3344. snd_soc_dapm_ignore_suspend(dapm, "MAD_CPE_OUT2");
  3345. snd_soc_dapm_ignore_suspend(dapm, "EAR");
  3346. snd_soc_dapm_ignore_suspend(dapm, "LINEOUT1");
  3347. snd_soc_dapm_ignore_suspend(dapm, "LINEOUT2");
  3348. snd_soc_dapm_ignore_suspend(dapm, "ANC EAR");
  3349. snd_soc_dapm_ignore_suspend(dapm, "SPK1 OUT");
  3350. snd_soc_dapm_ignore_suspend(dapm, "SPK2 OUT");
  3351. snd_soc_dapm_ignore_suspend(dapm, "HPHL");
  3352. snd_soc_dapm_ignore_suspend(dapm, "HPHR");
  3353. snd_soc_dapm_ignore_suspend(dapm, "AIF4 VI");
  3354. snd_soc_dapm_ignore_suspend(dapm, "VIINPUT");
  3355. snd_soc_dapm_ignore_suspend(dapm, "ANC HPHL");
  3356. snd_soc_dapm_ignore_suspend(dapm, "ANC HPHR");
  3357. snd_soc_dapm_sync(dapm);
  3358. snd_soc_dai_set_channel_map(codec_dai, ARRAY_SIZE(tx_ch),
  3359. tx_ch, ARRAY_SIZE(rx_ch), rx_ch);
  3360. msm_codec_fn.get_afe_config_fn = tavil_get_afe_config;
  3361. ret = msm_adsp_power_up_config(codec, rtd->card->snd_card);
  3362. if (ret) {
  3363. pr_err("%s: Failed to set AFE config %d\n", __func__, ret);
  3364. goto err;
  3365. }
  3366. config_data = msm_codec_fn.get_afe_config_fn(codec,
  3367. AFE_AANC_VERSION);
  3368. if (config_data) {
  3369. ret = afe_set_config(AFE_AANC_VERSION, config_data, 0);
  3370. if (ret) {
  3371. pr_err("%s: Failed to set aanc version %d\n",
  3372. __func__, ret);
  3373. goto err;
  3374. }
  3375. }
  3376. /*
  3377. * Send speaker configuration only for WSA8810.
  3378. * Default configuration is for WSA8815.
  3379. */
  3380. pr_debug("%s: Number of aux devices: %d\n",
  3381. __func__, rtd->card->num_aux_devs);
  3382. if (rtd->card->num_aux_devs &&
  3383. !list_empty(&rtd->card->aux_comp_list)) {
  3384. aux_comp = list_first_entry(&rtd->card->aux_comp_list,
  3385. struct snd_soc_component, list_aux);
  3386. if (!strcmp(aux_comp->name, WSA8810_NAME_1) ||
  3387. !strcmp(aux_comp->name, WSA8810_NAME_2)) {
  3388. tavil_set_spkr_mode(rtd->codec, WCD934X_SPKR_MODE_1);
  3389. tavil_set_spkr_gain_offset(rtd->codec,
  3390. WCD934X_RX_GAIN_OFFSET_M1P5_DB);
  3391. }
  3392. }
  3393. card = rtd->card->snd_card;
  3394. entry = snd_info_create_subdir(card->module, "codecs",
  3395. card->proc_root);
  3396. if (!entry) {
  3397. pr_debug("%s: Cannot create codecs module entry\n",
  3398. __func__);
  3399. pdata->codec_root = NULL;
  3400. goto done;
  3401. }
  3402. pdata->codec_root = entry;
  3403. tavil_codec_info_create_codec_entry(pdata->codec_root, codec);
  3404. done:
  3405. codec_reg_done = true;
  3406. return 0;
  3407. err:
  3408. return ret;
  3409. }
  3410. static int msm_wcn_init(struct snd_soc_pcm_runtime *rtd)
  3411. {
  3412. unsigned int rx_ch[WCN_CDC_SLIM_RX_CH_MAX] = {157, 158};
  3413. unsigned int tx_ch[WCN_CDC_SLIM_TX_CH_MAX] = {159, 160, 161};
  3414. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  3415. return snd_soc_dai_set_channel_map(codec_dai, ARRAY_SIZE(tx_ch),
  3416. tx_ch, ARRAY_SIZE(rx_ch), rx_ch);
  3417. }
  3418. static void *def_tavil_mbhc_cal(void)
  3419. {
  3420. void *tavil_wcd_cal;
  3421. struct wcd_mbhc_btn_detect_cfg *btn_cfg;
  3422. u16 *btn_high;
  3423. tavil_wcd_cal = kzalloc(WCD_MBHC_CAL_SIZE(WCD_MBHC_DEF_BUTTONS,
  3424. WCD9XXX_MBHC_DEF_RLOADS), GFP_KERNEL);
  3425. if (!tavil_wcd_cal)
  3426. return NULL;
  3427. #define S(X, Y) ((WCD_MBHC_CAL_PLUG_TYPE_PTR(tavil_wcd_cal)->X) = (Y))
  3428. S(v_hs_max, 1600);
  3429. #undef S
  3430. #define S(X, Y) ((WCD_MBHC_CAL_BTN_DET_PTR(tavil_wcd_cal)->X) = (Y))
  3431. S(num_btn, WCD_MBHC_DEF_BUTTONS);
  3432. #undef S
  3433. btn_cfg = WCD_MBHC_CAL_BTN_DET_PTR(tavil_wcd_cal);
  3434. btn_high = ((void *)&btn_cfg->_v_btn_low) +
  3435. (sizeof(btn_cfg->_v_btn_low[0]) * btn_cfg->num_btn);
  3436. btn_high[0] = 75;
  3437. btn_high[1] = 150;
  3438. btn_high[2] = 237;
  3439. btn_high[3] = 500;
  3440. btn_high[4] = 500;
  3441. btn_high[5] = 500;
  3442. btn_high[6] = 500;
  3443. btn_high[7] = 500;
  3444. return tavil_wcd_cal;
  3445. }
  3446. static int msm_snd_hw_params(struct snd_pcm_substream *substream,
  3447. struct snd_pcm_hw_params *params)
  3448. {
  3449. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  3450. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  3451. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  3452. struct snd_soc_dai_link *dai_link = rtd->dai_link;
  3453. int ret = 0;
  3454. u32 rx_ch[SLIM_MAX_RX_PORTS], tx_ch[SLIM_MAX_TX_PORTS];
  3455. u32 rx_ch_cnt = 0, tx_ch_cnt = 0;
  3456. u32 user_set_tx_ch = 0;
  3457. u32 rx_ch_count;
  3458. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  3459. ret = snd_soc_dai_get_channel_map(codec_dai,
  3460. &tx_ch_cnt, tx_ch, &rx_ch_cnt, rx_ch);
  3461. if (ret < 0) {
  3462. pr_err("%s: failed to get codec chan map, err:%d\n",
  3463. __func__, ret);
  3464. goto err;
  3465. }
  3466. if (dai_link->id == MSM_BACKEND_DAI_SLIMBUS_5_RX) {
  3467. pr_debug("%s: rx_5_ch=%d\n", __func__,
  3468. slim_rx_cfg[5].channels);
  3469. rx_ch_count = slim_rx_cfg[5].channels;
  3470. } else if (dai_link->id == MSM_BACKEND_DAI_SLIMBUS_2_RX) {
  3471. pr_debug("%s: rx_2_ch=%d\n", __func__,
  3472. slim_rx_cfg[2].channels);
  3473. rx_ch_count = slim_rx_cfg[2].channels;
  3474. } else if (dai_link->id == MSM_BACKEND_DAI_SLIMBUS_6_RX) {
  3475. pr_debug("%s: rx_6_ch=%d\n", __func__,
  3476. slim_rx_cfg[6].channels);
  3477. rx_ch_count = slim_rx_cfg[6].channels;
  3478. } else {
  3479. pr_debug("%s: rx_0_ch=%d\n", __func__,
  3480. slim_rx_cfg[0].channels);
  3481. rx_ch_count = slim_rx_cfg[0].channels;
  3482. }
  3483. ret = snd_soc_dai_set_channel_map(cpu_dai, 0, 0,
  3484. rx_ch_count, rx_ch);
  3485. if (ret < 0) {
  3486. pr_err("%s: failed to set cpu chan map, err:%d\n",
  3487. __func__, ret);
  3488. goto err;
  3489. }
  3490. } else {
  3491. pr_debug("%s: %s_tx_dai_id_%d_ch=%d\n", __func__,
  3492. codec_dai->name, codec_dai->id, user_set_tx_ch);
  3493. ret = snd_soc_dai_get_channel_map(codec_dai,
  3494. &tx_ch_cnt, tx_ch, &rx_ch_cnt, rx_ch);
  3495. if (ret < 0) {
  3496. pr_err("%s: failed to get codec chan map\n, err:%d\n",
  3497. __func__, ret);
  3498. goto err;
  3499. }
  3500. /* For <codec>_tx1 case */
  3501. if (dai_link->id == MSM_BACKEND_DAI_SLIMBUS_0_TX)
  3502. user_set_tx_ch = slim_tx_cfg[0].channels;
  3503. /* For <codec>_tx3 case */
  3504. else if (dai_link->id == MSM_BACKEND_DAI_SLIMBUS_1_TX)
  3505. user_set_tx_ch = slim_tx_cfg[1].channels;
  3506. else if (dai_link->id == MSM_BACKEND_DAI_SLIMBUS_4_TX)
  3507. user_set_tx_ch = msm_vi_feed_tx_ch;
  3508. else
  3509. user_set_tx_ch = tx_ch_cnt;
  3510. pr_debug("%s: msm_slim_0_tx_ch(%d) user_set_tx_ch(%d) tx_ch_cnt(%d), BE id (%d)\n",
  3511. __func__, slim_tx_cfg[0].channels, user_set_tx_ch,
  3512. tx_ch_cnt, dai_link->id);
  3513. ret = snd_soc_dai_set_channel_map(cpu_dai,
  3514. user_set_tx_ch, tx_ch, 0, 0);
  3515. if (ret < 0)
  3516. pr_err("%s: failed to set cpu chan map, err:%d\n",
  3517. __func__, ret);
  3518. }
  3519. err:
  3520. return ret;
  3521. }
  3522. static int msm_slimbus_2_hw_params(struct snd_pcm_substream *substream,
  3523. struct snd_pcm_hw_params *params)
  3524. {
  3525. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  3526. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  3527. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  3528. unsigned int rx_ch[SLIM_MAX_RX_PORTS], tx_ch[SLIM_MAX_TX_PORTS];
  3529. unsigned int rx_ch_cnt = 0, tx_ch_cnt = 0;
  3530. unsigned int num_tx_ch = 0;
  3531. unsigned int num_rx_ch = 0;
  3532. int ret = 0;
  3533. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  3534. num_rx_ch = params_channels(params);
  3535. pr_debug("%s: %s rx_dai_id = %d num_ch = %d\n", __func__,
  3536. codec_dai->name, codec_dai->id, num_rx_ch);
  3537. ret = snd_soc_dai_get_channel_map(codec_dai,
  3538. &tx_ch_cnt, tx_ch, &rx_ch_cnt, rx_ch);
  3539. if (ret < 0) {
  3540. pr_err("%s: failed to get codec chan map, err:%d\n",
  3541. __func__, ret);
  3542. goto err;
  3543. }
  3544. ret = snd_soc_dai_set_channel_map(cpu_dai, 0, 0,
  3545. num_rx_ch, rx_ch);
  3546. if (ret < 0) {
  3547. pr_err("%s: failed to set cpu chan map, err:%d\n",
  3548. __func__, ret);
  3549. goto err;
  3550. }
  3551. } else {
  3552. num_tx_ch = params_channels(params);
  3553. pr_debug("%s: %s tx_dai_id = %d num_ch = %d\n", __func__,
  3554. codec_dai->name, codec_dai->id, num_tx_ch);
  3555. ret = snd_soc_dai_get_channel_map(codec_dai,
  3556. &tx_ch_cnt, tx_ch, &rx_ch_cnt, rx_ch);
  3557. if (ret < 0) {
  3558. pr_err("%s: failed to get codec chan map, err:%d\n",
  3559. __func__, ret);
  3560. goto err;
  3561. }
  3562. ret = snd_soc_dai_set_channel_map(cpu_dai,
  3563. num_tx_ch, tx_ch, 0, 0);
  3564. if (ret < 0) {
  3565. pr_err("%s: failed to set cpu chan map, err:%d\n",
  3566. __func__, ret);
  3567. goto err;
  3568. }
  3569. }
  3570. err:
  3571. return ret;
  3572. }
  3573. static int msm_wcn_hw_params(struct snd_pcm_substream *substream,
  3574. struct snd_pcm_hw_params *params)
  3575. {
  3576. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  3577. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  3578. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  3579. struct snd_soc_dai_link *dai_link = rtd->dai_link;
  3580. u32 rx_ch[WCN_CDC_SLIM_RX_CH_MAX], tx_ch[WCN_CDC_SLIM_TX_CH_MAX];
  3581. u32 rx_ch_cnt = 0, tx_ch_cnt = 0;
  3582. int ret;
  3583. dev_dbg(rtd->dev, "%s: %s_tx_dai_id_%d\n", __func__,
  3584. codec_dai->name, codec_dai->id);
  3585. ret = snd_soc_dai_get_channel_map(codec_dai,
  3586. &tx_ch_cnt, tx_ch, &rx_ch_cnt, rx_ch);
  3587. if (ret) {
  3588. dev_err(rtd->dev,
  3589. "%s: failed to get BTFM codec chan map\n, err:%d\n",
  3590. __func__, ret);
  3591. goto err;
  3592. }
  3593. dev_dbg(rtd->dev, "%s: tx_ch_cnt(%d) BE id %d\n",
  3594. __func__, tx_ch_cnt, dai_link->id);
  3595. ret = snd_soc_dai_set_channel_map(cpu_dai,
  3596. tx_ch_cnt, tx_ch, rx_ch_cnt, rx_ch);
  3597. if (ret)
  3598. dev_err(rtd->dev, "%s: failed to set cpu chan map, err:%d\n",
  3599. __func__, ret);
  3600. err:
  3601. return ret;
  3602. }
  3603. static int msm_aux_pcm_snd_startup(struct snd_pcm_substream *substream)
  3604. {
  3605. int ret = 0;
  3606. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  3607. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  3608. int index = cpu_dai->id - 1;
  3609. dev_dbg(rtd->card->dev,
  3610. "%s: substream = %s stream = %d, dai name %s, dai ID %d\n",
  3611. __func__, substream->name, substream->stream,
  3612. cpu_dai->name, cpu_dai->id);
  3613. if (index < PRIM_AUX_PCM || index > QUAT_AUX_PCM) {
  3614. ret = -EINVAL;
  3615. dev_err(rtd->card->dev,
  3616. "%s: CPU DAI id (%d) out of range\n",
  3617. __func__, cpu_dai->id);
  3618. goto err;
  3619. }
  3620. mutex_lock(&auxpcm_intf_conf[index].lock);
  3621. if (++auxpcm_intf_conf[index].ref_cnt == 1) {
  3622. if (mi2s_auxpcm_conf[index].pcm_i2s_sel_vt_addr != NULL) {
  3623. mutex_lock(&mi2s_auxpcm_conf[index].lock);
  3624. iowrite32(1,
  3625. mi2s_auxpcm_conf[index].pcm_i2s_sel_vt_addr);
  3626. mutex_unlock(&mi2s_auxpcm_conf[index].lock);
  3627. } else {
  3628. dev_err(rtd->card->dev,
  3629. "%s lpaif_tert_muxsel_virt_addr is NULL\n",
  3630. __func__);
  3631. ret = -EINVAL;
  3632. }
  3633. }
  3634. if (ret < 0)
  3635. auxpcm_intf_conf[index].ref_cnt--;
  3636. mutex_unlock(&auxpcm_intf_conf[index].lock);
  3637. err:
  3638. return ret;
  3639. }
  3640. static void msm_aux_pcm_snd_shutdown(struct snd_pcm_substream *substream)
  3641. {
  3642. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  3643. int index = rtd->cpu_dai->id - 1;
  3644. dev_dbg(rtd->card->dev,
  3645. "%s: substream = %s stream = %d, dai name %s, dai ID %d\n",
  3646. __func__,
  3647. substream->name, substream->stream,
  3648. rtd->cpu_dai->name, rtd->cpu_dai->id);
  3649. if (index < PRIM_AUX_PCM || index > QUAT_AUX_PCM) {
  3650. dev_err(rtd->card->dev,
  3651. "%s: CPU DAI id (%d) out of range\n",
  3652. __func__, rtd->cpu_dai->id);
  3653. return;
  3654. }
  3655. mutex_lock(&auxpcm_intf_conf[index].lock);
  3656. if (--auxpcm_intf_conf[index].ref_cnt == 0) {
  3657. if (mi2s_auxpcm_conf[index].pcm_i2s_sel_vt_addr != NULL) {
  3658. mutex_lock(&mi2s_auxpcm_conf[index].lock);
  3659. iowrite32(0,
  3660. mi2s_auxpcm_conf[index].pcm_i2s_sel_vt_addr);
  3661. mutex_unlock(&mi2s_auxpcm_conf[index].lock);
  3662. } else {
  3663. dev_err(rtd->card->dev,
  3664. "%s lpaif_tert_muxsel_virt_addr is NULL\n",
  3665. __func__);
  3666. }
  3667. }
  3668. mutex_unlock(&auxpcm_intf_conf[index].lock);
  3669. }
  3670. static int msm_get_port_id(int be_id)
  3671. {
  3672. int afe_port_id;
  3673. switch (be_id) {
  3674. case MSM_BACKEND_DAI_PRI_MI2S_RX:
  3675. afe_port_id = AFE_PORT_ID_PRIMARY_MI2S_RX;
  3676. break;
  3677. case MSM_BACKEND_DAI_PRI_MI2S_TX:
  3678. afe_port_id = AFE_PORT_ID_PRIMARY_MI2S_TX;
  3679. break;
  3680. case MSM_BACKEND_DAI_SECONDARY_MI2S_RX:
  3681. afe_port_id = AFE_PORT_ID_SECONDARY_MI2S_RX;
  3682. break;
  3683. case MSM_BACKEND_DAI_SECONDARY_MI2S_TX:
  3684. afe_port_id = AFE_PORT_ID_SECONDARY_MI2S_TX;
  3685. break;
  3686. case MSM_BACKEND_DAI_TERTIARY_MI2S_RX:
  3687. afe_port_id = AFE_PORT_ID_TERTIARY_MI2S_RX;
  3688. break;
  3689. case MSM_BACKEND_DAI_TERTIARY_MI2S_TX:
  3690. afe_port_id = AFE_PORT_ID_TERTIARY_MI2S_TX;
  3691. break;
  3692. case MSM_BACKEND_DAI_QUATERNARY_MI2S_RX:
  3693. afe_port_id = AFE_PORT_ID_QUATERNARY_MI2S_RX;
  3694. break;
  3695. case MSM_BACKEND_DAI_QUATERNARY_MI2S_TX:
  3696. afe_port_id = AFE_PORT_ID_QUATERNARY_MI2S_TX;
  3697. break;
  3698. default:
  3699. pr_err("%s: Invalid BE id: %d\n", __func__, be_id);
  3700. afe_port_id = -EINVAL;
  3701. }
  3702. return afe_port_id;
  3703. }
  3704. static u32 get_mi2s_bits_per_sample(u32 bit_format)
  3705. {
  3706. u32 bit_per_sample;
  3707. switch (bit_format) {
  3708. case SNDRV_PCM_FORMAT_S32_LE:
  3709. case SNDRV_PCM_FORMAT_S24_3LE:
  3710. case SNDRV_PCM_FORMAT_S24_LE:
  3711. bit_per_sample = 32;
  3712. break;
  3713. case SNDRV_PCM_FORMAT_S16_LE:
  3714. default:
  3715. bit_per_sample = 16;
  3716. break;
  3717. }
  3718. return bit_per_sample;
  3719. }
  3720. static void update_mi2s_clk_val(int dai_id, int stream)
  3721. {
  3722. u32 bit_per_sample;
  3723. if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
  3724. bit_per_sample =
  3725. get_mi2s_bits_per_sample(mi2s_rx_cfg[dai_id].bit_format);
  3726. mi2s_clk[dai_id].clk_freq_in_hz =
  3727. mi2s_rx_cfg[dai_id].sample_rate * 2 * bit_per_sample;
  3728. } else {
  3729. bit_per_sample =
  3730. get_mi2s_bits_per_sample(mi2s_tx_cfg[dai_id].bit_format);
  3731. mi2s_clk[dai_id].clk_freq_in_hz =
  3732. mi2s_tx_cfg[dai_id].sample_rate * 2 * bit_per_sample;
  3733. }
  3734. }
  3735. static int msm_mi2s_set_sclk(struct snd_pcm_substream *substream, bool enable)
  3736. {
  3737. int ret = 0;
  3738. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  3739. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  3740. int port_id = 0;
  3741. int index = cpu_dai->id;
  3742. port_id = msm_get_port_id(rtd->dai_link->id);
  3743. if (port_id < 0) {
  3744. dev_err(rtd->card->dev, "%s: Invalid port_id\n", __func__);
  3745. ret = port_id;
  3746. goto err;
  3747. }
  3748. if (enable) {
  3749. update_mi2s_clk_val(index, substream->stream);
  3750. dev_dbg(rtd->card->dev, "%s: clock rate %ul\n", __func__,
  3751. mi2s_clk[index].clk_freq_in_hz);
  3752. }
  3753. mi2s_clk[index].enable = enable;
  3754. ret = afe_set_lpass_clock_v2(port_id,
  3755. &mi2s_clk[index]);
  3756. if (ret < 0) {
  3757. dev_err(rtd->card->dev,
  3758. "%s: afe lpass clock failed for port 0x%x , err:%d\n",
  3759. __func__, port_id, ret);
  3760. goto err;
  3761. }
  3762. err:
  3763. return ret;
  3764. }
  3765. static int msm_set_pinctrl(struct msm_pinctrl_info *pinctrl_info,
  3766. enum pinctrl_pin_state new_state)
  3767. {
  3768. int ret = 0;
  3769. int curr_state = 0;
  3770. if (pinctrl_info == NULL) {
  3771. pr_err("%s: pinctrl_info is NULL\n", __func__);
  3772. ret = -EINVAL;
  3773. goto err;
  3774. }
  3775. if (pinctrl_info->pinctrl == NULL) {
  3776. pr_err("%s: pinctrl_info->pinctrl is NULL\n", __func__);
  3777. ret = -EINVAL;
  3778. goto err;
  3779. }
  3780. curr_state = pinctrl_info->curr_state;
  3781. pinctrl_info->curr_state = new_state;
  3782. pr_debug("%s: curr_state = %s new_state = %s\n", __func__,
  3783. pin_states[curr_state], pin_states[pinctrl_info->curr_state]);
  3784. if (curr_state == pinctrl_info->curr_state) {
  3785. pr_debug("%s: Already in same state\n", __func__);
  3786. goto err;
  3787. }
  3788. if (curr_state != STATE_DISABLE &&
  3789. pinctrl_info->curr_state != STATE_DISABLE) {
  3790. pr_debug("%s: state already active cannot switch\n", __func__);
  3791. ret = -EIO;
  3792. goto err;
  3793. }
  3794. switch (pinctrl_info->curr_state) {
  3795. case STATE_MI2S_ACTIVE:
  3796. ret = pinctrl_select_state(pinctrl_info->pinctrl,
  3797. pinctrl_info->mi2s_active);
  3798. if (ret) {
  3799. pr_err("%s: MI2S state select failed with %d\n",
  3800. __func__, ret);
  3801. ret = -EIO;
  3802. goto err;
  3803. }
  3804. break;
  3805. case STATE_TDM_ACTIVE:
  3806. ret = pinctrl_select_state(pinctrl_info->pinctrl,
  3807. pinctrl_info->tdm_active);
  3808. if (ret) {
  3809. pr_err("%s: TDM state select failed with %d\n",
  3810. __func__, ret);
  3811. ret = -EIO;
  3812. goto err;
  3813. }
  3814. break;
  3815. case STATE_DISABLE:
  3816. if (curr_state == STATE_MI2S_ACTIVE) {
  3817. ret = pinctrl_select_state(pinctrl_info->pinctrl,
  3818. pinctrl_info->mi2s_disable);
  3819. } else {
  3820. ret = pinctrl_select_state(pinctrl_info->pinctrl,
  3821. pinctrl_info->tdm_disable);
  3822. }
  3823. if (ret) {
  3824. pr_err("%s: state disable failed with %d\n",
  3825. __func__, ret);
  3826. ret = -EIO;
  3827. goto err;
  3828. }
  3829. break;
  3830. default:
  3831. pr_err("%s: TLMM pin state is invalid\n", __func__);
  3832. return -EINVAL;
  3833. }
  3834. err:
  3835. return ret;
  3836. }
  3837. static void msm_release_pinctrl(struct platform_device *pdev)
  3838. {
  3839. struct snd_soc_card *card = platform_get_drvdata(pdev);
  3840. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  3841. struct msm_pinctrl_info *pinctrl_info = &pdata->pinctrl_info;
  3842. if (pinctrl_info->pinctrl) {
  3843. devm_pinctrl_put(pinctrl_info->pinctrl);
  3844. pinctrl_info->pinctrl = NULL;
  3845. }
  3846. }
  3847. static int msm_get_pinctrl(struct platform_device *pdev)
  3848. {
  3849. struct snd_soc_card *card = platform_get_drvdata(pdev);
  3850. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  3851. struct msm_pinctrl_info *pinctrl_info = NULL;
  3852. struct pinctrl *pinctrl;
  3853. int ret;
  3854. pinctrl_info = &pdata->pinctrl_info;
  3855. if (pinctrl_info == NULL) {
  3856. pr_err("%s: pinctrl_info is NULL\n", __func__);
  3857. return -EINVAL;
  3858. }
  3859. pinctrl = devm_pinctrl_get(&pdev->dev);
  3860. if (IS_ERR_OR_NULL(pinctrl)) {
  3861. pr_err("%s: Unable to get pinctrl handle\n", __func__);
  3862. return -EINVAL;
  3863. }
  3864. pinctrl_info->pinctrl = pinctrl;
  3865. /* get all the states handles from Device Tree */
  3866. pinctrl_info->mi2s_disable = pinctrl_lookup_state(pinctrl,
  3867. "quat-mi2s-sleep");
  3868. if (IS_ERR(pinctrl_info->mi2s_disable)) {
  3869. pr_err("%s: could not get mi2s_disable pinstate\n", __func__);
  3870. goto err;
  3871. }
  3872. pinctrl_info->mi2s_active = pinctrl_lookup_state(pinctrl,
  3873. "quat-mi2s-active");
  3874. if (IS_ERR(pinctrl_info->mi2s_active)) {
  3875. pr_err("%s: could not get mi2s_active pinstate\n", __func__);
  3876. goto err;
  3877. }
  3878. pinctrl_info->tdm_disable = pinctrl_lookup_state(pinctrl,
  3879. "quat-tdm-sleep");
  3880. if (IS_ERR(pinctrl_info->tdm_disable)) {
  3881. pr_err("%s: could not get tdm_disable pinstate\n", __func__);
  3882. goto err;
  3883. }
  3884. pinctrl_info->tdm_active = pinctrl_lookup_state(pinctrl,
  3885. "quat-tdm-active");
  3886. if (IS_ERR(pinctrl_info->tdm_active)) {
  3887. pr_err("%s: could not get tdm_active pinstate\n",
  3888. __func__);
  3889. goto err;
  3890. }
  3891. /* Reset the TLMM pins to a default state */
  3892. ret = pinctrl_select_state(pinctrl_info->pinctrl,
  3893. pinctrl_info->mi2s_disable);
  3894. if (ret != 0) {
  3895. pr_err("%s: Disable TLMM pins failed with %d\n",
  3896. __func__, ret);
  3897. ret = -EIO;
  3898. goto err;
  3899. }
  3900. pinctrl_info->curr_state = STATE_DISABLE;
  3901. return 0;
  3902. err:
  3903. devm_pinctrl_put(pinctrl);
  3904. pinctrl_info->pinctrl = NULL;
  3905. return -EINVAL;
  3906. }
  3907. static int msm_tdm_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
  3908. struct snd_pcm_hw_params *params)
  3909. {
  3910. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  3911. struct snd_interval *rate = hw_param_interval(params,
  3912. SNDRV_PCM_HW_PARAM_RATE);
  3913. struct snd_interval *channels = hw_param_interval(params,
  3914. SNDRV_PCM_HW_PARAM_CHANNELS);
  3915. if (cpu_dai->id == AFE_PORT_ID_QUATERNARY_TDM_RX) {
  3916. channels->min = channels->max =
  3917. tdm_rx_cfg[TDM_QUAT][TDM_0].channels;
  3918. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  3919. tdm_rx_cfg[TDM_QUAT][TDM_0].bit_format);
  3920. rate->min = rate->max =
  3921. tdm_rx_cfg[TDM_QUAT][TDM_0].sample_rate;
  3922. } else if (cpu_dai->id == AFE_PORT_ID_SECONDARY_TDM_RX) {
  3923. channels->min = channels->max =
  3924. tdm_rx_cfg[TDM_SEC][TDM_0].channels;
  3925. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  3926. tdm_rx_cfg[TDM_SEC][TDM_0].bit_format);
  3927. rate->min = rate->max = tdm_rx_cfg[TDM_SEC][TDM_0].sample_rate;
  3928. } else {
  3929. pr_err("%s: dai id 0x%x not supported\n",
  3930. __func__, cpu_dai->id);
  3931. return -EINVAL;
  3932. }
  3933. pr_debug("%s: dai id = 0x%x channels = %d rate = %d format = 0x%x\n",
  3934. __func__, cpu_dai->id, channels->max, rate->max,
  3935. params_format(params));
  3936. return 0;
  3937. }
  3938. static int sdm845_tdm_snd_hw_params(struct snd_pcm_substream *substream,
  3939. struct snd_pcm_hw_params *params)
  3940. {
  3941. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  3942. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  3943. int ret = 0;
  3944. int slot_width = 32;
  3945. int channels, slots;
  3946. unsigned int slot_mask, rate, clk_freq;
  3947. unsigned int slot_offset[8] = {0, 4, 8, 12, 16, 20, 24, 28};
  3948. pr_debug("%s: dai id = 0x%x\n", __func__, cpu_dai->id);
  3949. /* currently only supporting TDM_RX_0 and TDM_TX_0 */
  3950. switch (cpu_dai->id) {
  3951. case AFE_PORT_ID_PRIMARY_TDM_RX:
  3952. slots = tdm_rx_cfg[TDM_PRI][TDM_0].channels;
  3953. break;
  3954. case AFE_PORT_ID_SECONDARY_TDM_RX:
  3955. slots = tdm_rx_cfg[TDM_SEC][TDM_0].channels;
  3956. break;
  3957. case AFE_PORT_ID_TERTIARY_TDM_RX:
  3958. slots = tdm_rx_cfg[TDM_TERT][TDM_0].channels;
  3959. break;
  3960. case AFE_PORT_ID_QUATERNARY_TDM_RX:
  3961. slots = tdm_rx_cfg[TDM_QUAT][TDM_0].channels;
  3962. break;
  3963. case AFE_PORT_ID_PRIMARY_TDM_TX:
  3964. slots = tdm_tx_cfg[TDM_PRI][TDM_0].channels;
  3965. break;
  3966. case AFE_PORT_ID_SECONDARY_TDM_TX:
  3967. slots = tdm_tx_cfg[TDM_SEC][TDM_0].channels;
  3968. break;
  3969. case AFE_PORT_ID_TERTIARY_TDM_TX:
  3970. slots = tdm_tx_cfg[TDM_TERT][TDM_0].channels;
  3971. break;
  3972. case AFE_PORT_ID_QUATERNARY_TDM_TX:
  3973. slots = tdm_tx_cfg[TDM_QUAT][TDM_0].channels;
  3974. break;
  3975. default:
  3976. pr_err("%s: dai id 0x%x not supported\n",
  3977. __func__, cpu_dai->id);
  3978. return -EINVAL;
  3979. }
  3980. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  3981. /*2 slot config - bits 0 and 1 set for the first two slots */
  3982. slot_mask = 0x0000FFFF >> (16-slots);
  3983. channels = slots;
  3984. pr_debug("%s: tdm rx slot_width %d slots %d\n",
  3985. __func__, slot_width, slots);
  3986. ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0, slot_mask,
  3987. slots, slot_width);
  3988. if (ret < 0) {
  3989. pr_err("%s: failed to set tdm rx slot, err:%d\n",
  3990. __func__, ret);
  3991. goto end;
  3992. }
  3993. ret = snd_soc_dai_set_channel_map(cpu_dai,
  3994. 0, NULL, channels, slot_offset);
  3995. if (ret < 0) {
  3996. pr_err("%s: failed to set tdm rx channel map, err:%d\n",
  3997. __func__, ret);
  3998. goto end;
  3999. }
  4000. } else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
  4001. /*2 slot config - bits 0 and 1 set for the first two slots */
  4002. slot_mask = 0x0000FFFF >> (16-slots);
  4003. channels = slots;
  4004. pr_debug("%s: tdm tx slot_width %d slots %d\n",
  4005. __func__, slot_width, slots);
  4006. ret = snd_soc_dai_set_tdm_slot(cpu_dai, slot_mask, 0,
  4007. slots, slot_width);
  4008. if (ret < 0) {
  4009. pr_err("%s: failed to set tdm tx slot, err:%d\n",
  4010. __func__, ret);
  4011. goto end;
  4012. }
  4013. ret = snd_soc_dai_set_channel_map(cpu_dai,
  4014. channels, slot_offset, 0, NULL);
  4015. if (ret < 0) {
  4016. pr_err("%s: failed to set tdm tx channel map, err:%d\n",
  4017. __func__, ret);
  4018. goto end;
  4019. }
  4020. } else {
  4021. ret = -EINVAL;
  4022. pr_err("%s: invalid use case, err:%d\n",
  4023. __func__, ret);
  4024. goto end;
  4025. }
  4026. rate = params_rate(params);
  4027. clk_freq = rate * slot_width * slots;
  4028. ret = snd_soc_dai_set_sysclk(cpu_dai, 0, clk_freq, SND_SOC_CLOCK_OUT);
  4029. if (ret < 0)
  4030. pr_err("%s: failed to set tdm clk, err:%d\n",
  4031. __func__, ret);
  4032. end:
  4033. return ret;
  4034. }
  4035. static int sdm845_tdm_snd_startup(struct snd_pcm_substream *substream)
  4036. {
  4037. int ret = 0;
  4038. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  4039. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  4040. struct snd_soc_card *card = rtd->card;
  4041. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  4042. struct msm_pinctrl_info *pinctrl_info = &pdata->pinctrl_info;
  4043. /* currently only supporting TDM_RX_0 and TDM_TX_0 */
  4044. if ((cpu_dai->id == AFE_PORT_ID_QUATERNARY_TDM_RX) ||
  4045. (cpu_dai->id == AFE_PORT_ID_QUATERNARY_TDM_TX)) {
  4046. ret = msm_set_pinctrl(pinctrl_info, STATE_TDM_ACTIVE);
  4047. if (ret)
  4048. pr_err("%s: TDM TLMM pinctrl set failed with %d\n",
  4049. __func__, ret);
  4050. }
  4051. return ret;
  4052. }
  4053. static void sdm845_tdm_snd_shutdown(struct snd_pcm_substream *substream)
  4054. {
  4055. int ret = 0;
  4056. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  4057. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  4058. struct snd_soc_card *card = rtd->card;
  4059. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  4060. struct msm_pinctrl_info *pinctrl_info = &pdata->pinctrl_info;
  4061. /* currently only supporting TDM_RX_0 and TDM_TX_0 */
  4062. if ((cpu_dai->id == AFE_PORT_ID_QUATERNARY_TDM_RX) ||
  4063. (cpu_dai->id == AFE_PORT_ID_QUATERNARY_TDM_TX)) {
  4064. ret = msm_set_pinctrl(pinctrl_info, STATE_DISABLE);
  4065. if (ret)
  4066. pr_err("%s: TDM TLMM pinctrl set failed with %d\n",
  4067. __func__, ret);
  4068. }
  4069. }
  4070. static struct snd_soc_ops sdm845_tdm_be_ops = {
  4071. .hw_params = sdm845_tdm_snd_hw_params,
  4072. .startup = sdm845_tdm_snd_startup,
  4073. .shutdown = sdm845_tdm_snd_shutdown
  4074. };
  4075. static int msm_fe_qos_prepare(struct snd_pcm_substream *substream)
  4076. {
  4077. cpumask_t mask;
  4078. if (pm_qos_request_active(&substream->latency_pm_qos_req))
  4079. pm_qos_remove_request(&substream->latency_pm_qos_req);
  4080. cpumask_clear(&mask);
  4081. cpumask_set_cpu(1, &mask); /* affine to core 1 */
  4082. cpumask_set_cpu(2, &mask); /* affine to core 2 */
  4083. cpumask_copy(&substream->latency_pm_qos_req.cpus_affine, &mask);
  4084. substream->latency_pm_qos_req.type = PM_QOS_REQ_AFFINE_CORES;
  4085. pm_qos_add_request(&substream->latency_pm_qos_req,
  4086. PM_QOS_CPU_DMA_LATENCY,
  4087. MSM_LL_QOS_VALUE);
  4088. return 0;
  4089. }
  4090. static struct snd_soc_ops msm_fe_qos_ops = {
  4091. .prepare = msm_fe_qos_prepare,
  4092. };
  4093. static int msm_mi2s_snd_startup(struct snd_pcm_substream *substream)
  4094. {
  4095. int ret = 0;
  4096. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  4097. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  4098. int index = cpu_dai->id;
  4099. unsigned int fmt = SND_SOC_DAIFMT_CBS_CFS;
  4100. struct snd_soc_card *card = rtd->card;
  4101. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  4102. struct msm_pinctrl_info *pinctrl_info = &pdata->pinctrl_info;
  4103. int ret_pinctrl = 0;
  4104. dev_dbg(rtd->card->dev,
  4105. "%s: substream = %s stream = %d, dai name %s, dai ID %d\n",
  4106. __func__, substream->name, substream->stream,
  4107. cpu_dai->name, cpu_dai->id);
  4108. if (index < PRIM_MI2S || index > QUAT_MI2S) {
  4109. ret = -EINVAL;
  4110. dev_err(rtd->card->dev,
  4111. "%s: CPU DAI id (%d) out of range\n",
  4112. __func__, cpu_dai->id);
  4113. goto err;
  4114. }
  4115. if (index == QUAT_MI2S) {
  4116. ret_pinctrl = msm_set_pinctrl(pinctrl_info, STATE_MI2S_ACTIVE);
  4117. if (ret_pinctrl)
  4118. pr_err("%s: MI2S TLMM pinctrl set failed with %d\n",
  4119. __func__, ret_pinctrl);
  4120. }
  4121. /*
  4122. * Muxtex protection in case the same MI2S
  4123. * interface using for both TX and RX so
  4124. * that the same clock won't be enable twice.
  4125. */
  4126. mutex_lock(&mi2s_intf_conf[index].lock);
  4127. if (++mi2s_intf_conf[index].ref_cnt == 1) {
  4128. /* Check if msm needs to provide the clock to the interface */
  4129. if (!mi2s_intf_conf[index].msm_is_mi2s_master) {
  4130. mi2s_clk[index].clk_id = mi2s_ebit_clk[index];
  4131. fmt = SND_SOC_DAIFMT_CBM_CFM;
  4132. }
  4133. ret = msm_mi2s_set_sclk(substream, true);
  4134. if (ret < 0) {
  4135. dev_err(rtd->card->dev,
  4136. "%s: afe lpass clock failed to enable MI2S clock, err:%d\n",
  4137. __func__, ret);
  4138. goto clean_up;
  4139. }
  4140. if (mi2s_auxpcm_conf[index].pcm_i2s_sel_vt_addr != NULL) {
  4141. mutex_lock(&mi2s_auxpcm_conf[index].lock);
  4142. iowrite32(0,
  4143. mi2s_auxpcm_conf[index].pcm_i2s_sel_vt_addr);
  4144. mutex_unlock(&mi2s_auxpcm_conf[index].lock);
  4145. } else {
  4146. dev_err(rtd->card->dev,
  4147. "%s lpaif_muxsel_virt_addr is NULL for dai %d\n",
  4148. __func__, index);
  4149. ret = -EINVAL;
  4150. goto clk_off;
  4151. }
  4152. ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
  4153. if (ret < 0) {
  4154. pr_err("%s: set fmt cpu dai failed for MI2S (%d), err:%d\n",
  4155. __func__, index, ret);
  4156. goto clk_off;
  4157. }
  4158. }
  4159. clk_off:
  4160. if (ret < 0)
  4161. msm_mi2s_set_sclk(substream, false);
  4162. clean_up:
  4163. if (ret < 0)
  4164. mi2s_intf_conf[index].ref_cnt--;
  4165. mutex_unlock(&mi2s_intf_conf[index].lock);
  4166. err:
  4167. return ret;
  4168. }
  4169. static void msm_mi2s_snd_shutdown(struct snd_pcm_substream *substream)
  4170. {
  4171. int ret;
  4172. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  4173. int index = rtd->cpu_dai->id;
  4174. struct snd_soc_card *card = rtd->card;
  4175. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  4176. struct msm_pinctrl_info *pinctrl_info = &pdata->pinctrl_info;
  4177. int ret_pinctrl = 0;
  4178. pr_debug("%s(): substream = %s stream = %d\n", __func__,
  4179. substream->name, substream->stream);
  4180. if (index < PRIM_MI2S || index > QUAT_MI2S) {
  4181. pr_err("%s:invalid MI2S DAI(%d)\n", __func__, index);
  4182. return;
  4183. }
  4184. mutex_lock(&mi2s_intf_conf[index].lock);
  4185. if (--mi2s_intf_conf[index].ref_cnt == 0) {
  4186. ret = msm_mi2s_set_sclk(substream, false);
  4187. if (ret < 0)
  4188. pr_err("%s:clock disable failed for MI2S (%d); ret=%d\n",
  4189. __func__, index, ret);
  4190. }
  4191. mutex_unlock(&mi2s_intf_conf[index].lock);
  4192. if (index == QUAT_MI2S) {
  4193. ret_pinctrl = msm_set_pinctrl(pinctrl_info, STATE_DISABLE);
  4194. if (ret_pinctrl)
  4195. pr_err("%s: MI2S TLMM pinctrl set failed with %d\n",
  4196. __func__, ret_pinctrl);
  4197. }
  4198. }
  4199. static struct snd_soc_ops msm_mi2s_be_ops = {
  4200. .startup = msm_mi2s_snd_startup,
  4201. .shutdown = msm_mi2s_snd_shutdown,
  4202. };
  4203. static struct snd_soc_ops msm_aux_pcm_be_ops = {
  4204. .startup = msm_aux_pcm_snd_startup,
  4205. .shutdown = msm_aux_pcm_snd_shutdown,
  4206. };
  4207. static struct snd_soc_ops msm_be_ops = {
  4208. .hw_params = msm_snd_hw_params,
  4209. };
  4210. static struct snd_soc_ops msm_slimbus_2_be_ops = {
  4211. .hw_params = msm_slimbus_2_hw_params,
  4212. };
  4213. static struct snd_soc_ops msm_wcn_ops = {
  4214. .hw_params = msm_wcn_hw_params,
  4215. };
  4216. /* Digital audio interface glue - connects codec <---> CPU */
  4217. static struct snd_soc_dai_link msm_common_dai_links[] = {
  4218. /* FrontEnd DAI Links */
  4219. {
  4220. .name = MSM_DAILINK_NAME(Media1),
  4221. .stream_name = "MultiMedia1",
  4222. .cpu_dai_name = "MultiMedia1",
  4223. .platform_name = "msm-pcm-dsp.0",
  4224. .dynamic = 1,
  4225. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  4226. .dpcm_playback = 1,
  4227. .dpcm_capture = 1,
  4228. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4229. SND_SOC_DPCM_TRIGGER_POST},
  4230. .codec_dai_name = "snd-soc-dummy-dai",
  4231. .codec_name = "snd-soc-dummy",
  4232. .ignore_suspend = 1,
  4233. /* this dainlink has playback support */
  4234. .ignore_pmdown_time = 1,
  4235. .id = MSM_FRONTEND_DAI_MULTIMEDIA1
  4236. },
  4237. {
  4238. .name = MSM_DAILINK_NAME(Media2),
  4239. .stream_name = "MultiMedia2",
  4240. .cpu_dai_name = "MultiMedia2",
  4241. .platform_name = "msm-pcm-dsp.0",
  4242. .dynamic = 1,
  4243. .dpcm_playback = 1,
  4244. .dpcm_capture = 1,
  4245. .codec_dai_name = "snd-soc-dummy-dai",
  4246. .codec_name = "snd-soc-dummy",
  4247. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4248. SND_SOC_DPCM_TRIGGER_POST},
  4249. .ignore_suspend = 1,
  4250. /* this dainlink has playback support */
  4251. .ignore_pmdown_time = 1,
  4252. .id = MSM_FRONTEND_DAI_MULTIMEDIA2,
  4253. },
  4254. {
  4255. .name = "VoiceMMode1",
  4256. .stream_name = "VoiceMMode1",
  4257. .cpu_dai_name = "VoiceMMode1",
  4258. .platform_name = "msm-pcm-voice",
  4259. .dynamic = 1,
  4260. .dpcm_playback = 1,
  4261. .dpcm_capture = 1,
  4262. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4263. SND_SOC_DPCM_TRIGGER_POST},
  4264. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4265. .ignore_suspend = 1,
  4266. .ignore_pmdown_time = 1,
  4267. .codec_dai_name = "snd-soc-dummy-dai",
  4268. .codec_name = "snd-soc-dummy",
  4269. .id = MSM_FRONTEND_DAI_VOICEMMODE1,
  4270. },
  4271. {
  4272. .name = "MSM VoIP",
  4273. .stream_name = "VoIP",
  4274. .cpu_dai_name = "VoIP",
  4275. .platform_name = "msm-voip-dsp",
  4276. .dynamic = 1,
  4277. .dpcm_playback = 1,
  4278. .dpcm_capture = 1,
  4279. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4280. SND_SOC_DPCM_TRIGGER_POST},
  4281. .codec_dai_name = "snd-soc-dummy-dai",
  4282. .codec_name = "snd-soc-dummy",
  4283. .ignore_suspend = 1,
  4284. /* this dainlink has playback support */
  4285. .ignore_pmdown_time = 1,
  4286. .id = MSM_FRONTEND_DAI_VOIP,
  4287. },
  4288. {
  4289. .name = MSM_DAILINK_NAME(ULL),
  4290. .stream_name = "MultiMedia3",
  4291. .cpu_dai_name = "MultiMedia3",
  4292. .platform_name = "msm-pcm-dsp.2",
  4293. .dynamic = 1,
  4294. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  4295. .dpcm_playback = 1,
  4296. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4297. SND_SOC_DPCM_TRIGGER_POST},
  4298. .codec_dai_name = "snd-soc-dummy-dai",
  4299. .codec_name = "snd-soc-dummy",
  4300. .ignore_suspend = 1,
  4301. /* this dainlink has playback support */
  4302. .ignore_pmdown_time = 1,
  4303. .id = MSM_FRONTEND_DAI_MULTIMEDIA3,
  4304. },
  4305. /* Hostless PCM purpose */
  4306. {
  4307. .name = "SLIMBUS_0 Hostless",
  4308. .stream_name = "SLIMBUS_0 Hostless",
  4309. .cpu_dai_name = "SLIMBUS0_HOSTLESS",
  4310. .platform_name = "msm-pcm-hostless",
  4311. .dynamic = 1,
  4312. .dpcm_playback = 1,
  4313. .dpcm_capture = 1,
  4314. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4315. SND_SOC_DPCM_TRIGGER_POST},
  4316. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4317. .ignore_suspend = 1,
  4318. /* this dailink has playback support */
  4319. .ignore_pmdown_time = 1,
  4320. .codec_dai_name = "snd-soc-dummy-dai",
  4321. .codec_name = "snd-soc-dummy",
  4322. },
  4323. {
  4324. .name = "MSM AFE-PCM RX",
  4325. .stream_name = "AFE-PROXY RX",
  4326. .cpu_dai_name = "msm-dai-q6-dev.241",
  4327. .codec_name = "msm-stub-codec.1",
  4328. .codec_dai_name = "msm-stub-rx",
  4329. .platform_name = "msm-pcm-afe",
  4330. .dpcm_playback = 1,
  4331. .ignore_suspend = 1,
  4332. /* this dainlink has playback support */
  4333. .ignore_pmdown_time = 1,
  4334. },
  4335. {
  4336. .name = "MSM AFE-PCM TX",
  4337. .stream_name = "AFE-PROXY TX",
  4338. .cpu_dai_name = "msm-dai-q6-dev.240",
  4339. .codec_name = "msm-stub-codec.1",
  4340. .codec_dai_name = "msm-stub-tx",
  4341. .platform_name = "msm-pcm-afe",
  4342. .dpcm_capture = 1,
  4343. .ignore_suspend = 1,
  4344. },
  4345. {
  4346. .name = MSM_DAILINK_NAME(Compress1),
  4347. .stream_name = "Compress1",
  4348. .cpu_dai_name = "MultiMedia4",
  4349. .platform_name = "msm-compress-dsp",
  4350. .dynamic = 1,
  4351. .async_ops = ASYNC_DPCM_SND_SOC_HW_PARAMS,
  4352. .dpcm_playback = 1,
  4353. .dpcm_capture = 1,
  4354. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4355. SND_SOC_DPCM_TRIGGER_POST},
  4356. .codec_dai_name = "snd-soc-dummy-dai",
  4357. .codec_name = "snd-soc-dummy",
  4358. .ignore_suspend = 1,
  4359. .ignore_pmdown_time = 1,
  4360. /* this dainlink has playback support */
  4361. .id = MSM_FRONTEND_DAI_MULTIMEDIA4,
  4362. },
  4363. {
  4364. .name = "AUXPCM Hostless",
  4365. .stream_name = "AUXPCM Hostless",
  4366. .cpu_dai_name = "AUXPCM_HOSTLESS",
  4367. .platform_name = "msm-pcm-hostless",
  4368. .dynamic = 1,
  4369. .dpcm_playback = 1,
  4370. .dpcm_capture = 1,
  4371. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4372. SND_SOC_DPCM_TRIGGER_POST},
  4373. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4374. .ignore_suspend = 1,
  4375. /* this dainlink has playback support */
  4376. .ignore_pmdown_time = 1,
  4377. .codec_dai_name = "snd-soc-dummy-dai",
  4378. .codec_name = "snd-soc-dummy",
  4379. },
  4380. {
  4381. .name = "SLIMBUS_1 Hostless",
  4382. .stream_name = "SLIMBUS_1 Hostless",
  4383. .cpu_dai_name = "SLIMBUS1_HOSTLESS",
  4384. .platform_name = "msm-pcm-hostless",
  4385. .dynamic = 1,
  4386. .dpcm_playback = 1,
  4387. .dpcm_capture = 1,
  4388. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4389. SND_SOC_DPCM_TRIGGER_POST},
  4390. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4391. .ignore_suspend = 1,
  4392. /* this dailink has playback support */
  4393. .ignore_pmdown_time = 1,
  4394. .codec_dai_name = "snd-soc-dummy-dai",
  4395. .codec_name = "snd-soc-dummy",
  4396. },
  4397. {
  4398. .name = "SLIMBUS_3 Hostless",
  4399. .stream_name = "SLIMBUS_3 Hostless",
  4400. .cpu_dai_name = "SLIMBUS3_HOSTLESS",
  4401. .platform_name = "msm-pcm-hostless",
  4402. .dynamic = 1,
  4403. .dpcm_playback = 1,
  4404. .dpcm_capture = 1,
  4405. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4406. SND_SOC_DPCM_TRIGGER_POST},
  4407. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4408. .ignore_suspend = 1,
  4409. /* this dailink has playback support */
  4410. .ignore_pmdown_time = 1,
  4411. .codec_dai_name = "snd-soc-dummy-dai",
  4412. .codec_name = "snd-soc-dummy",
  4413. },
  4414. {
  4415. .name = "SLIMBUS_4 Hostless",
  4416. .stream_name = "SLIMBUS_4 Hostless",
  4417. .cpu_dai_name = "SLIMBUS4_HOSTLESS",
  4418. .platform_name = "msm-pcm-hostless",
  4419. .dynamic = 1,
  4420. .dpcm_playback = 1,
  4421. .dpcm_capture = 1,
  4422. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4423. SND_SOC_DPCM_TRIGGER_POST},
  4424. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4425. .ignore_suspend = 1,
  4426. /* this dailink has playback support */
  4427. .ignore_pmdown_time = 1,
  4428. .codec_dai_name = "snd-soc-dummy-dai",
  4429. .codec_name = "snd-soc-dummy",
  4430. },
  4431. {
  4432. .name = MSM_DAILINK_NAME(LowLatency),
  4433. .stream_name = "MultiMedia5",
  4434. .cpu_dai_name = "MultiMedia5",
  4435. .platform_name = "msm-pcm-dsp.1",
  4436. .dynamic = 1,
  4437. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  4438. .dpcm_playback = 1,
  4439. .dpcm_capture = 1,
  4440. .codec_dai_name = "snd-soc-dummy-dai",
  4441. .codec_name = "snd-soc-dummy",
  4442. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4443. SND_SOC_DPCM_TRIGGER_POST},
  4444. .ignore_suspend = 1,
  4445. /* this dainlink has playback support */
  4446. .ignore_pmdown_time = 1,
  4447. .id = MSM_FRONTEND_DAI_MULTIMEDIA5,
  4448. .ops = &msm_fe_qos_ops,
  4449. },
  4450. {
  4451. .name = "Listen 1 Audio Service",
  4452. .stream_name = "Listen 1 Audio Service",
  4453. .cpu_dai_name = "LSM1",
  4454. .platform_name = "msm-lsm-client",
  4455. .dynamic = 1,
  4456. .dpcm_capture = 1,
  4457. .trigger = { SND_SOC_DPCM_TRIGGER_POST,
  4458. SND_SOC_DPCM_TRIGGER_POST },
  4459. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4460. .ignore_suspend = 1,
  4461. .ignore_pmdown_time = 1,
  4462. .codec_dai_name = "snd-soc-dummy-dai",
  4463. .codec_name = "snd-soc-dummy",
  4464. .id = MSM_FRONTEND_DAI_LSM1,
  4465. },
  4466. /* Multiple Tunnel instances */
  4467. {
  4468. .name = MSM_DAILINK_NAME(Compress2),
  4469. .stream_name = "Compress2",
  4470. .cpu_dai_name = "MultiMedia7",
  4471. .platform_name = "msm-compress-dsp",
  4472. .dynamic = 1,
  4473. .dpcm_playback = 1,
  4474. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4475. SND_SOC_DPCM_TRIGGER_POST},
  4476. .codec_dai_name = "snd-soc-dummy-dai",
  4477. .codec_name = "snd-soc-dummy",
  4478. .ignore_suspend = 1,
  4479. .ignore_pmdown_time = 1,
  4480. /* this dainlink has playback support */
  4481. .id = MSM_FRONTEND_DAI_MULTIMEDIA7,
  4482. },
  4483. {
  4484. .name = MSM_DAILINK_NAME(MultiMedia10),
  4485. .stream_name = "MultiMedia10",
  4486. .cpu_dai_name = "MultiMedia10",
  4487. .platform_name = "msm-pcm-dsp.1",
  4488. .dynamic = 1,
  4489. .dpcm_playback = 1,
  4490. .dpcm_capture = 1,
  4491. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4492. SND_SOC_DPCM_TRIGGER_POST},
  4493. .codec_dai_name = "snd-soc-dummy-dai",
  4494. .codec_name = "snd-soc-dummy",
  4495. .ignore_suspend = 1,
  4496. .ignore_pmdown_time = 1,
  4497. /* this dainlink has playback support */
  4498. .id = MSM_FRONTEND_DAI_MULTIMEDIA10,
  4499. },
  4500. {
  4501. .name = MSM_DAILINK_NAME(ULL_NOIRQ),
  4502. .stream_name = "MM_NOIRQ",
  4503. .cpu_dai_name = "MultiMedia8",
  4504. .platform_name = "msm-pcm-dsp-noirq",
  4505. .dynamic = 1,
  4506. .dpcm_playback = 1,
  4507. .dpcm_capture = 1,
  4508. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4509. SND_SOC_DPCM_TRIGGER_POST},
  4510. .codec_dai_name = "snd-soc-dummy-dai",
  4511. .codec_name = "snd-soc-dummy",
  4512. .ignore_suspend = 1,
  4513. .ignore_pmdown_time = 1,
  4514. /* this dainlink has playback support */
  4515. .id = MSM_FRONTEND_DAI_MULTIMEDIA8,
  4516. .ops = &msm_fe_qos_ops,
  4517. },
  4518. /* HDMI Hostless */
  4519. {
  4520. .name = "HDMI_RX_HOSTLESS",
  4521. .stream_name = "HDMI_RX_HOSTLESS",
  4522. .cpu_dai_name = "HDMI_HOSTLESS",
  4523. .platform_name = "msm-pcm-hostless",
  4524. .dynamic = 1,
  4525. .dpcm_playback = 1,
  4526. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4527. SND_SOC_DPCM_TRIGGER_POST},
  4528. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4529. .ignore_suspend = 1,
  4530. .ignore_pmdown_time = 1,
  4531. .codec_dai_name = "snd-soc-dummy-dai",
  4532. .codec_name = "snd-soc-dummy",
  4533. },
  4534. {
  4535. .name = "VoiceMMode2",
  4536. .stream_name = "VoiceMMode2",
  4537. .cpu_dai_name = "VoiceMMode2",
  4538. .platform_name = "msm-pcm-voice",
  4539. .dynamic = 1,
  4540. .dpcm_playback = 1,
  4541. .dpcm_capture = 1,
  4542. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4543. SND_SOC_DPCM_TRIGGER_POST},
  4544. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4545. .ignore_suspend = 1,
  4546. .ignore_pmdown_time = 1,
  4547. .codec_dai_name = "snd-soc-dummy-dai",
  4548. .codec_name = "snd-soc-dummy",
  4549. .id = MSM_FRONTEND_DAI_VOICEMMODE2,
  4550. },
  4551. /* LSM FE */
  4552. {
  4553. .name = "Listen 2 Audio Service",
  4554. .stream_name = "Listen 2 Audio Service",
  4555. .cpu_dai_name = "LSM2",
  4556. .platform_name = "msm-lsm-client",
  4557. .dynamic = 1,
  4558. .dpcm_capture = 1,
  4559. .trigger = { SND_SOC_DPCM_TRIGGER_POST,
  4560. SND_SOC_DPCM_TRIGGER_POST },
  4561. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4562. .ignore_suspend = 1,
  4563. .ignore_pmdown_time = 1,
  4564. .codec_dai_name = "snd-soc-dummy-dai",
  4565. .codec_name = "snd-soc-dummy",
  4566. .id = MSM_FRONTEND_DAI_LSM2,
  4567. },
  4568. {
  4569. .name = "Listen 3 Audio Service",
  4570. .stream_name = "Listen 3 Audio Service",
  4571. .cpu_dai_name = "LSM3",
  4572. .platform_name = "msm-lsm-client",
  4573. .dynamic = 1,
  4574. .dpcm_capture = 1,
  4575. .trigger = { SND_SOC_DPCM_TRIGGER_POST,
  4576. SND_SOC_DPCM_TRIGGER_POST },
  4577. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4578. .ignore_suspend = 1,
  4579. .ignore_pmdown_time = 1,
  4580. .codec_dai_name = "snd-soc-dummy-dai",
  4581. .codec_name = "snd-soc-dummy",
  4582. .id = MSM_FRONTEND_DAI_LSM3,
  4583. },
  4584. {
  4585. .name = "Listen 4 Audio Service",
  4586. .stream_name = "Listen 4 Audio Service",
  4587. .cpu_dai_name = "LSM4",
  4588. .platform_name = "msm-lsm-client",
  4589. .dynamic = 1,
  4590. .dpcm_capture = 1,
  4591. .trigger = { SND_SOC_DPCM_TRIGGER_POST,
  4592. SND_SOC_DPCM_TRIGGER_POST },
  4593. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4594. .ignore_suspend = 1,
  4595. .ignore_pmdown_time = 1,
  4596. .codec_dai_name = "snd-soc-dummy-dai",
  4597. .codec_name = "snd-soc-dummy",
  4598. .id = MSM_FRONTEND_DAI_LSM4,
  4599. },
  4600. {
  4601. .name = "Listen 5 Audio Service",
  4602. .stream_name = "Listen 5 Audio Service",
  4603. .cpu_dai_name = "LSM5",
  4604. .platform_name = "msm-lsm-client",
  4605. .dynamic = 1,
  4606. .dpcm_capture = 1,
  4607. .trigger = { SND_SOC_DPCM_TRIGGER_POST,
  4608. SND_SOC_DPCM_TRIGGER_POST },
  4609. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4610. .ignore_suspend = 1,
  4611. .ignore_pmdown_time = 1,
  4612. .codec_dai_name = "snd-soc-dummy-dai",
  4613. .codec_name = "snd-soc-dummy",
  4614. .id = MSM_FRONTEND_DAI_LSM5,
  4615. },
  4616. {
  4617. .name = "Listen 6 Audio Service",
  4618. .stream_name = "Listen 6 Audio Service",
  4619. .cpu_dai_name = "LSM6",
  4620. .platform_name = "msm-lsm-client",
  4621. .dynamic = 1,
  4622. .dpcm_capture = 1,
  4623. .trigger = { SND_SOC_DPCM_TRIGGER_POST,
  4624. SND_SOC_DPCM_TRIGGER_POST },
  4625. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4626. .ignore_suspend = 1,
  4627. .ignore_pmdown_time = 1,
  4628. .codec_dai_name = "snd-soc-dummy-dai",
  4629. .codec_name = "snd-soc-dummy",
  4630. .id = MSM_FRONTEND_DAI_LSM6,
  4631. },
  4632. {
  4633. .name = "Listen 7 Audio Service",
  4634. .stream_name = "Listen 7 Audio Service",
  4635. .cpu_dai_name = "LSM7",
  4636. .platform_name = "msm-lsm-client",
  4637. .dynamic = 1,
  4638. .dpcm_capture = 1,
  4639. .trigger = { SND_SOC_DPCM_TRIGGER_POST,
  4640. SND_SOC_DPCM_TRIGGER_POST },
  4641. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4642. .ignore_suspend = 1,
  4643. .ignore_pmdown_time = 1,
  4644. .codec_dai_name = "snd-soc-dummy-dai",
  4645. .codec_name = "snd-soc-dummy",
  4646. .id = MSM_FRONTEND_DAI_LSM7,
  4647. },
  4648. {
  4649. .name = "Listen 8 Audio Service",
  4650. .stream_name = "Listen 8 Audio Service",
  4651. .cpu_dai_name = "LSM8",
  4652. .platform_name = "msm-lsm-client",
  4653. .dynamic = 1,
  4654. .dpcm_capture = 1,
  4655. .trigger = { SND_SOC_DPCM_TRIGGER_POST,
  4656. SND_SOC_DPCM_TRIGGER_POST },
  4657. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4658. .ignore_suspend = 1,
  4659. .ignore_pmdown_time = 1,
  4660. .codec_dai_name = "snd-soc-dummy-dai",
  4661. .codec_name = "snd-soc-dummy",
  4662. .id = MSM_FRONTEND_DAI_LSM8,
  4663. },
  4664. {
  4665. .name = MSM_DAILINK_NAME(Media9),
  4666. .stream_name = "MultiMedia9",
  4667. .cpu_dai_name = "MultiMedia9",
  4668. .platform_name = "msm-pcm-dsp.0",
  4669. .dynamic = 1,
  4670. .dpcm_playback = 1,
  4671. .dpcm_capture = 1,
  4672. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4673. SND_SOC_DPCM_TRIGGER_POST},
  4674. .codec_dai_name = "snd-soc-dummy-dai",
  4675. .codec_name = "snd-soc-dummy",
  4676. .ignore_suspend = 1,
  4677. /* this dainlink has playback support */
  4678. .ignore_pmdown_time = 1,
  4679. .id = MSM_FRONTEND_DAI_MULTIMEDIA9,
  4680. },
  4681. {
  4682. .name = MSM_DAILINK_NAME(Compress4),
  4683. .stream_name = "Compress4",
  4684. .cpu_dai_name = "MultiMedia11",
  4685. .platform_name = "msm-compress-dsp",
  4686. .dynamic = 1,
  4687. .dpcm_playback = 1,
  4688. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4689. SND_SOC_DPCM_TRIGGER_POST},
  4690. .codec_dai_name = "snd-soc-dummy-dai",
  4691. .codec_name = "snd-soc-dummy",
  4692. .ignore_suspend = 1,
  4693. .ignore_pmdown_time = 1,
  4694. /* this dainlink has playback support */
  4695. .id = MSM_FRONTEND_DAI_MULTIMEDIA11,
  4696. },
  4697. {
  4698. .name = MSM_DAILINK_NAME(Compress5),
  4699. .stream_name = "Compress5",
  4700. .cpu_dai_name = "MultiMedia12",
  4701. .platform_name = "msm-compress-dsp",
  4702. .dynamic = 1,
  4703. .dpcm_playback = 1,
  4704. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4705. SND_SOC_DPCM_TRIGGER_POST},
  4706. .codec_dai_name = "snd-soc-dummy-dai",
  4707. .codec_name = "snd-soc-dummy",
  4708. .ignore_suspend = 1,
  4709. .ignore_pmdown_time = 1,
  4710. /* this dainlink has playback support */
  4711. .id = MSM_FRONTEND_DAI_MULTIMEDIA12,
  4712. },
  4713. {
  4714. .name = MSM_DAILINK_NAME(Compress6),
  4715. .stream_name = "Compress6",
  4716. .cpu_dai_name = "MultiMedia13",
  4717. .platform_name = "msm-compress-dsp",
  4718. .dynamic = 1,
  4719. .dpcm_playback = 1,
  4720. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4721. SND_SOC_DPCM_TRIGGER_POST},
  4722. .codec_dai_name = "snd-soc-dummy-dai",
  4723. .codec_name = "snd-soc-dummy",
  4724. .ignore_suspend = 1,
  4725. .ignore_pmdown_time = 1,
  4726. /* this dainlink has playback support */
  4727. .id = MSM_FRONTEND_DAI_MULTIMEDIA13,
  4728. },
  4729. {
  4730. .name = MSM_DAILINK_NAME(Compress7),
  4731. .stream_name = "Compress7",
  4732. .cpu_dai_name = "MultiMedia14",
  4733. .platform_name = "msm-compress-dsp",
  4734. .dynamic = 1,
  4735. .dpcm_playback = 1,
  4736. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4737. SND_SOC_DPCM_TRIGGER_POST},
  4738. .codec_dai_name = "snd-soc-dummy-dai",
  4739. .codec_name = "snd-soc-dummy",
  4740. .ignore_suspend = 1,
  4741. .ignore_pmdown_time = 1,
  4742. /* this dainlink has playback support */
  4743. .id = MSM_FRONTEND_DAI_MULTIMEDIA14,
  4744. },
  4745. {
  4746. .name = MSM_DAILINK_NAME(Compress8),
  4747. .stream_name = "Compress8",
  4748. .cpu_dai_name = "MultiMedia15",
  4749. .platform_name = "msm-compress-dsp",
  4750. .dynamic = 1,
  4751. .dpcm_playback = 1,
  4752. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4753. SND_SOC_DPCM_TRIGGER_POST},
  4754. .codec_dai_name = "snd-soc-dummy-dai",
  4755. .codec_name = "snd-soc-dummy",
  4756. .ignore_suspend = 1,
  4757. .ignore_pmdown_time = 1,
  4758. /* this dainlink has playback support */
  4759. .id = MSM_FRONTEND_DAI_MULTIMEDIA15,
  4760. },
  4761. {
  4762. .name = MSM_DAILINK_NAME(ULL_NOIRQ_2),
  4763. .stream_name = "MM_NOIRQ_2",
  4764. .cpu_dai_name = "MultiMedia16",
  4765. .platform_name = "msm-pcm-dsp-noirq",
  4766. .dynamic = 1,
  4767. .dpcm_playback = 1,
  4768. .dpcm_capture = 1,
  4769. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4770. SND_SOC_DPCM_TRIGGER_POST},
  4771. .codec_dai_name = "snd-soc-dummy-dai",
  4772. .codec_name = "snd-soc-dummy",
  4773. .ignore_suspend = 1,
  4774. .ignore_pmdown_time = 1,
  4775. /* this dainlink has playback support */
  4776. .id = MSM_FRONTEND_DAI_MULTIMEDIA16,
  4777. },
  4778. {
  4779. .name = "SLIMBUS_8 Hostless",
  4780. .stream_name = "SLIMBUS8_HOSTLESS Capture",
  4781. .cpu_dai_name = "SLIMBUS8_HOSTLESS",
  4782. .platform_name = "msm-pcm-hostless",
  4783. .dynamic = 1,
  4784. .dpcm_capture = 1,
  4785. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4786. SND_SOC_DPCM_TRIGGER_POST},
  4787. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4788. .ignore_suspend = 1,
  4789. .ignore_pmdown_time = 1,
  4790. .codec_dai_name = "snd-soc-dummy-dai",
  4791. .codec_name = "snd-soc-dummy",
  4792. },
  4793. };
  4794. static struct snd_soc_dai_link msm_tavil_fe_dai_links[] = {
  4795. {
  4796. .name = LPASS_BE_SLIMBUS_4_TX,
  4797. .stream_name = "Slimbus4 Capture",
  4798. .cpu_dai_name = "msm-dai-q6-dev.16393",
  4799. .platform_name = "msm-pcm-hostless",
  4800. .codec_name = "tavil_codec",
  4801. .codec_dai_name = "tavil_vifeedback",
  4802. .id = MSM_BACKEND_DAI_SLIMBUS_4_TX,
  4803. .be_hw_params_fixup = msm_be_hw_params_fixup,
  4804. .ops = &msm_be_ops,
  4805. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4806. .ignore_suspend = 1,
  4807. },
  4808. /* Ultrasound RX DAI Link */
  4809. {
  4810. .name = "SLIMBUS_2 Hostless Playback",
  4811. .stream_name = "SLIMBUS_2 Hostless Playback",
  4812. .cpu_dai_name = "msm-dai-q6-dev.16388",
  4813. .platform_name = "msm-pcm-hostless",
  4814. .codec_name = "tavil_codec",
  4815. .codec_dai_name = "tavil_rx2",
  4816. .ignore_suspend = 1,
  4817. .ignore_pmdown_time = 1,
  4818. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4819. .ops = &msm_slimbus_2_be_ops,
  4820. },
  4821. /* Ultrasound TX DAI Link */
  4822. {
  4823. .name = "SLIMBUS_2 Hostless Capture",
  4824. .stream_name = "SLIMBUS_2 Hostless Capture",
  4825. .cpu_dai_name = "msm-dai-q6-dev.16389",
  4826. .platform_name = "msm-pcm-hostless",
  4827. .codec_name = "tavil_codec",
  4828. .codec_dai_name = "tavil_tx2",
  4829. .ignore_suspend = 1,
  4830. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4831. .ops = &msm_slimbus_2_be_ops,
  4832. },
  4833. };
  4834. static struct snd_soc_dai_link msm_common_misc_fe_dai_links[] = {
  4835. {
  4836. .name = MSM_DAILINK_NAME(ASM Loopback),
  4837. .stream_name = "MultiMedia6",
  4838. .cpu_dai_name = "MultiMedia6",
  4839. .platform_name = "msm-pcm-loopback",
  4840. .dynamic = 1,
  4841. .dpcm_playback = 1,
  4842. .dpcm_capture = 1,
  4843. .codec_dai_name = "snd-soc-dummy-dai",
  4844. .codec_name = "snd-soc-dummy",
  4845. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4846. SND_SOC_DPCM_TRIGGER_POST},
  4847. .ignore_suspend = 1,
  4848. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4849. .ignore_pmdown_time = 1,
  4850. .id = MSM_FRONTEND_DAI_MULTIMEDIA6,
  4851. },
  4852. {
  4853. .name = "USB Audio Hostless",
  4854. .stream_name = "USB Audio Hostless",
  4855. .cpu_dai_name = "USBAUDIO_HOSTLESS",
  4856. .platform_name = "msm-pcm-hostless",
  4857. .dynamic = 1,
  4858. .dpcm_playback = 1,
  4859. .dpcm_capture = 1,
  4860. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4861. SND_SOC_DPCM_TRIGGER_POST},
  4862. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4863. .ignore_suspend = 1,
  4864. .ignore_pmdown_time = 1,
  4865. .codec_dai_name = "snd-soc-dummy-dai",
  4866. .codec_name = "snd-soc-dummy",
  4867. },
  4868. };
  4869. static struct snd_soc_dai_link msm_common_be_dai_links[] = {
  4870. /* Backend AFE DAI Links */
  4871. {
  4872. .name = LPASS_BE_AFE_PCM_RX,
  4873. .stream_name = "AFE Playback",
  4874. .cpu_dai_name = "msm-dai-q6-dev.224",
  4875. .platform_name = "msm-pcm-routing",
  4876. .codec_name = "msm-stub-codec.1",
  4877. .codec_dai_name = "msm-stub-rx",
  4878. .no_pcm = 1,
  4879. .dpcm_playback = 1,
  4880. .id = MSM_BACKEND_DAI_AFE_PCM_RX,
  4881. .be_hw_params_fixup = msm_be_hw_params_fixup,
  4882. /* this dainlink has playback support */
  4883. .ignore_pmdown_time = 1,
  4884. .ignore_suspend = 1,
  4885. },
  4886. {
  4887. .name = LPASS_BE_AFE_PCM_TX,
  4888. .stream_name = "AFE Capture",
  4889. .cpu_dai_name = "msm-dai-q6-dev.225",
  4890. .platform_name = "msm-pcm-routing",
  4891. .codec_name = "msm-stub-codec.1",
  4892. .codec_dai_name = "msm-stub-tx",
  4893. .no_pcm = 1,
  4894. .dpcm_capture = 1,
  4895. .id = MSM_BACKEND_DAI_AFE_PCM_TX,
  4896. .be_hw_params_fixup = msm_be_hw_params_fixup,
  4897. .ignore_suspend = 1,
  4898. },
  4899. /* Incall Record Uplink BACK END DAI Link */
  4900. {
  4901. .name = LPASS_BE_INCALL_RECORD_TX,
  4902. .stream_name = "Voice Uplink Capture",
  4903. .cpu_dai_name = "msm-dai-q6-dev.32772",
  4904. .platform_name = "msm-pcm-routing",
  4905. .codec_name = "msm-stub-codec.1",
  4906. .codec_dai_name = "msm-stub-tx",
  4907. .no_pcm = 1,
  4908. .dpcm_capture = 1,
  4909. .id = MSM_BACKEND_DAI_INCALL_RECORD_TX,
  4910. .be_hw_params_fixup = msm_be_hw_params_fixup,
  4911. .ignore_suspend = 1,
  4912. },
  4913. /* Incall Record Downlink BACK END DAI Link */
  4914. {
  4915. .name = LPASS_BE_INCALL_RECORD_RX,
  4916. .stream_name = "Voice Downlink Capture",
  4917. .cpu_dai_name = "msm-dai-q6-dev.32771",
  4918. .platform_name = "msm-pcm-routing",
  4919. .codec_name = "msm-stub-codec.1",
  4920. .codec_dai_name = "msm-stub-tx",
  4921. .no_pcm = 1,
  4922. .dpcm_capture = 1,
  4923. .id = MSM_BACKEND_DAI_INCALL_RECORD_RX,
  4924. .be_hw_params_fixup = msm_be_hw_params_fixup,
  4925. .ignore_suspend = 1,
  4926. },
  4927. /* Incall Music BACK END DAI Link */
  4928. {
  4929. .name = LPASS_BE_VOICE_PLAYBACK_TX,
  4930. .stream_name = "Voice Farend Playback",
  4931. .cpu_dai_name = "msm-dai-q6-dev.32773",
  4932. .platform_name = "msm-pcm-routing",
  4933. .codec_name = "msm-stub-codec.1",
  4934. .codec_dai_name = "msm-stub-rx",
  4935. .no_pcm = 1,
  4936. .dpcm_playback = 1,
  4937. .id = MSM_BACKEND_DAI_VOICE_PLAYBACK_TX,
  4938. .be_hw_params_fixup = msm_be_hw_params_fixup,
  4939. .ignore_suspend = 1,
  4940. },
  4941. /* Incall Music 2 BACK END DAI Link */
  4942. {
  4943. .name = LPASS_BE_VOICE2_PLAYBACK_TX,
  4944. .stream_name = "Voice2 Farend Playback",
  4945. .cpu_dai_name = "msm-dai-q6-dev.32770",
  4946. .platform_name = "msm-pcm-routing",
  4947. .codec_name = "msm-stub-codec.1",
  4948. .codec_dai_name = "msm-stub-rx",
  4949. .no_pcm = 1,
  4950. .dpcm_playback = 1,
  4951. .id = MSM_BACKEND_DAI_VOICE2_PLAYBACK_TX,
  4952. .be_hw_params_fixup = msm_be_hw_params_fixup,
  4953. .ignore_suspend = 1,
  4954. },
  4955. {
  4956. .name = LPASS_BE_USB_AUDIO_RX,
  4957. .stream_name = "USB Audio Playback",
  4958. .cpu_dai_name = "msm-dai-q6-dev.28672",
  4959. .platform_name = "msm-pcm-routing",
  4960. .codec_name = "msm-stub-codec.1",
  4961. .codec_dai_name = "msm-stub-rx",
  4962. .no_pcm = 1,
  4963. .dpcm_playback = 1,
  4964. .id = MSM_BACKEND_DAI_USB_RX,
  4965. .be_hw_params_fixup = msm_be_hw_params_fixup,
  4966. .ignore_pmdown_time = 1,
  4967. .ignore_suspend = 1,
  4968. },
  4969. {
  4970. .name = LPASS_BE_USB_AUDIO_TX,
  4971. .stream_name = "USB Audio Capture",
  4972. .cpu_dai_name = "msm-dai-q6-dev.28673",
  4973. .platform_name = "msm-pcm-routing",
  4974. .codec_name = "msm-stub-codec.1",
  4975. .codec_dai_name = "msm-stub-tx",
  4976. .no_pcm = 1,
  4977. .dpcm_capture = 1,
  4978. .id = MSM_BACKEND_DAI_USB_TX,
  4979. .be_hw_params_fixup = msm_be_hw_params_fixup,
  4980. .ignore_suspend = 1,
  4981. },
  4982. {
  4983. .name = LPASS_BE_PRI_TDM_RX_0,
  4984. .stream_name = "Primary TDM0 Playback",
  4985. .cpu_dai_name = "msm-dai-q6-tdm.36864",
  4986. .platform_name = "msm-pcm-routing",
  4987. .codec_name = "msm-stub-codec.1",
  4988. .codec_dai_name = "msm-stub-rx",
  4989. .no_pcm = 1,
  4990. .dpcm_playback = 1,
  4991. .id = MSM_BACKEND_DAI_PRI_TDM_RX_0,
  4992. .be_hw_params_fixup = msm_be_hw_params_fixup,
  4993. .ops = &sdm845_tdm_be_ops,
  4994. .ignore_suspend = 1,
  4995. },
  4996. {
  4997. .name = LPASS_BE_PRI_TDM_TX_0,
  4998. .stream_name = "Primary TDM0 Capture",
  4999. .cpu_dai_name = "msm-dai-q6-tdm.36865",
  5000. .platform_name = "msm-pcm-routing",
  5001. .codec_name = "msm-stub-codec.1",
  5002. .codec_dai_name = "msm-stub-tx",
  5003. .no_pcm = 1,
  5004. .dpcm_capture = 1,
  5005. .id = MSM_BACKEND_DAI_PRI_TDM_TX_0,
  5006. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5007. .ops = &sdm845_tdm_be_ops,
  5008. .ignore_suspend = 1,
  5009. },
  5010. {
  5011. .name = LPASS_BE_SEC_TDM_RX_0,
  5012. .stream_name = "Secondary TDM0 Playback",
  5013. .cpu_dai_name = "msm-dai-q6-tdm.36880",
  5014. .platform_name = "msm-pcm-routing",
  5015. .codec_name = "msm-stub-codec.1",
  5016. .codec_dai_name = "msm-stub-rx",
  5017. .no_pcm = 1,
  5018. .dpcm_playback = 1,
  5019. .id = MSM_BACKEND_DAI_SEC_TDM_RX_0,
  5020. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5021. .ops = &sdm845_tdm_be_ops,
  5022. .ignore_suspend = 1,
  5023. },
  5024. {
  5025. .name = LPASS_BE_SEC_TDM_TX_0,
  5026. .stream_name = "Secondary TDM0 Capture",
  5027. .cpu_dai_name = "msm-dai-q6-tdm.36881",
  5028. .platform_name = "msm-pcm-routing",
  5029. .codec_name = "msm-stub-codec.1",
  5030. .codec_dai_name = "msm-stub-tx",
  5031. .no_pcm = 1,
  5032. .dpcm_capture = 1,
  5033. .id = MSM_BACKEND_DAI_SEC_TDM_TX_0,
  5034. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5035. .ops = &sdm845_tdm_be_ops,
  5036. .ignore_suspend = 1,
  5037. },
  5038. {
  5039. .name = LPASS_BE_TERT_TDM_RX_0,
  5040. .stream_name = "Tertiary TDM0 Playback",
  5041. .cpu_dai_name = "msm-dai-q6-tdm.36896",
  5042. .platform_name = "msm-pcm-routing",
  5043. .codec_name = "msm-stub-codec.1",
  5044. .codec_dai_name = "msm-stub-rx",
  5045. .no_pcm = 1,
  5046. .dpcm_playback = 1,
  5047. .id = MSM_BACKEND_DAI_TERT_TDM_RX_0,
  5048. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5049. .ops = &sdm845_tdm_be_ops,
  5050. .ignore_suspend = 1,
  5051. },
  5052. {
  5053. .name = LPASS_BE_TERT_TDM_TX_0,
  5054. .stream_name = "Tertiary TDM0 Capture",
  5055. .cpu_dai_name = "msm-dai-q6-tdm.36897",
  5056. .platform_name = "msm-pcm-routing",
  5057. .codec_name = "msm-stub-codec.1",
  5058. .codec_dai_name = "msm-stub-tx",
  5059. .no_pcm = 1,
  5060. .dpcm_capture = 1,
  5061. .id = MSM_BACKEND_DAI_TERT_TDM_TX_0,
  5062. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5063. .ops = &sdm845_tdm_be_ops,
  5064. .ignore_suspend = 1,
  5065. },
  5066. {
  5067. .name = LPASS_BE_QUAT_TDM_RX_0,
  5068. .stream_name = "Quaternary TDM0 Playback",
  5069. .cpu_dai_name = "msm-dai-q6-tdm.36912",
  5070. .platform_name = "msm-pcm-routing",
  5071. .codec_name = "msm-stub-codec.1",
  5072. .codec_dai_name = "msm-stub-rx",
  5073. .no_pcm = 1,
  5074. .dpcm_playback = 1,
  5075. .id = MSM_BACKEND_DAI_QUAT_TDM_RX_0,
  5076. .be_hw_params_fixup = msm_tdm_be_hw_params_fixup,
  5077. .ops = &sdm845_tdm_be_ops,
  5078. .ignore_suspend = 1,
  5079. },
  5080. {
  5081. .name = LPASS_BE_QUAT_TDM_TX_0,
  5082. .stream_name = "Quaternary TDM0 Capture",
  5083. .cpu_dai_name = "msm-dai-q6-tdm.36913",
  5084. .platform_name = "msm-pcm-routing",
  5085. .codec_name = "msm-stub-codec.1",
  5086. .codec_dai_name = "msm-stub-tx",
  5087. .no_pcm = 1,
  5088. .dpcm_capture = 1,
  5089. .id = MSM_BACKEND_DAI_QUAT_TDM_TX_0,
  5090. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5091. .ops = &sdm845_tdm_be_ops,
  5092. .ignore_suspend = 1,
  5093. },
  5094. };
  5095. static struct snd_soc_dai_link msm_tavil_be_dai_links[] = {
  5096. {
  5097. .name = LPASS_BE_SLIMBUS_0_RX,
  5098. .stream_name = "Slimbus Playback",
  5099. .cpu_dai_name = "msm-dai-q6-dev.16384",
  5100. .platform_name = "msm-pcm-routing",
  5101. .codec_name = "tavil_codec",
  5102. .codec_dai_name = "tavil_rx1",
  5103. .no_pcm = 1,
  5104. .dpcm_playback = 1,
  5105. .id = MSM_BACKEND_DAI_SLIMBUS_0_RX,
  5106. .init = &msm_audrx_init,
  5107. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5108. /* this dainlink has playback support */
  5109. .ignore_pmdown_time = 1,
  5110. .ignore_suspend = 1,
  5111. .ops = &msm_be_ops,
  5112. },
  5113. {
  5114. .name = LPASS_BE_SLIMBUS_0_TX,
  5115. .stream_name = "Slimbus Capture",
  5116. .cpu_dai_name = "msm-dai-q6-dev.16385",
  5117. .platform_name = "msm-pcm-routing",
  5118. .codec_name = "tavil_codec",
  5119. .codec_dai_name = "tavil_tx1",
  5120. .no_pcm = 1,
  5121. .dpcm_capture = 1,
  5122. .id = MSM_BACKEND_DAI_SLIMBUS_0_TX,
  5123. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5124. .ignore_suspend = 1,
  5125. .ops = &msm_be_ops,
  5126. },
  5127. {
  5128. .name = LPASS_BE_SLIMBUS_1_RX,
  5129. .stream_name = "Slimbus1 Playback",
  5130. .cpu_dai_name = "msm-dai-q6-dev.16386",
  5131. .platform_name = "msm-pcm-routing",
  5132. .codec_name = "tavil_codec",
  5133. .codec_dai_name = "tavil_rx1",
  5134. .no_pcm = 1,
  5135. .dpcm_playback = 1,
  5136. .id = MSM_BACKEND_DAI_SLIMBUS_1_RX,
  5137. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5138. .ops = &msm_be_ops,
  5139. /* dai link has playback support */
  5140. .ignore_pmdown_time = 1,
  5141. .ignore_suspend = 1,
  5142. },
  5143. {
  5144. .name = LPASS_BE_SLIMBUS_1_TX,
  5145. .stream_name = "Slimbus1 Capture",
  5146. .cpu_dai_name = "msm-dai-q6-dev.16387",
  5147. .platform_name = "msm-pcm-routing",
  5148. .codec_name = "tavil_codec",
  5149. .codec_dai_name = "tavil_tx3",
  5150. .no_pcm = 1,
  5151. .dpcm_capture = 1,
  5152. .id = MSM_BACKEND_DAI_SLIMBUS_1_TX,
  5153. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5154. .ops = &msm_be_ops,
  5155. .ignore_suspend = 1,
  5156. },
  5157. {
  5158. .name = LPASS_BE_SLIMBUS_2_RX,
  5159. .stream_name = "Slimbus2 Playback",
  5160. .cpu_dai_name = "msm-dai-q6-dev.16388",
  5161. .platform_name = "msm-pcm-routing",
  5162. .codec_name = "tavil_codec",
  5163. .codec_dai_name = "tavil_rx2",
  5164. .no_pcm = 1,
  5165. .dpcm_playback = 1,
  5166. .id = MSM_BACKEND_DAI_SLIMBUS_2_RX,
  5167. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5168. .ops = &msm_be_ops,
  5169. .ignore_pmdown_time = 1,
  5170. .ignore_suspend = 1,
  5171. },
  5172. {
  5173. .name = LPASS_BE_SLIMBUS_3_RX,
  5174. .stream_name = "Slimbus3 Playback",
  5175. .cpu_dai_name = "msm-dai-q6-dev.16390",
  5176. .platform_name = "msm-pcm-routing",
  5177. .codec_name = "tavil_codec",
  5178. .codec_dai_name = "tavil_rx1",
  5179. .no_pcm = 1,
  5180. .dpcm_playback = 1,
  5181. .id = MSM_BACKEND_DAI_SLIMBUS_3_RX,
  5182. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5183. .ops = &msm_be_ops,
  5184. /* dai link has playback support */
  5185. .ignore_pmdown_time = 1,
  5186. .ignore_suspend = 1,
  5187. },
  5188. {
  5189. .name = LPASS_BE_SLIMBUS_3_TX,
  5190. .stream_name = "Slimbus3 Capture",
  5191. .cpu_dai_name = "msm-dai-q6-dev.16391",
  5192. .platform_name = "msm-pcm-routing",
  5193. .codec_name = "tavil_codec",
  5194. .codec_dai_name = "tavil_tx1",
  5195. .no_pcm = 1,
  5196. .dpcm_capture = 1,
  5197. .id = MSM_BACKEND_DAI_SLIMBUS_3_TX,
  5198. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5199. .ops = &msm_be_ops,
  5200. .ignore_suspend = 1,
  5201. },
  5202. {
  5203. .name = LPASS_BE_SLIMBUS_4_RX,
  5204. .stream_name = "Slimbus4 Playback",
  5205. .cpu_dai_name = "msm-dai-q6-dev.16392",
  5206. .platform_name = "msm-pcm-routing",
  5207. .codec_name = "tavil_codec",
  5208. .codec_dai_name = "tavil_rx1",
  5209. .no_pcm = 1,
  5210. .dpcm_playback = 1,
  5211. .id = MSM_BACKEND_DAI_SLIMBUS_4_RX,
  5212. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5213. .ops = &msm_be_ops,
  5214. /* dai link has playback support */
  5215. .ignore_pmdown_time = 1,
  5216. .ignore_suspend = 1,
  5217. },
  5218. {
  5219. .name = LPASS_BE_SLIMBUS_5_RX,
  5220. .stream_name = "Slimbus5 Playback",
  5221. .cpu_dai_name = "msm-dai-q6-dev.16394",
  5222. .platform_name = "msm-pcm-routing",
  5223. .codec_name = "tavil_codec",
  5224. .codec_dai_name = "tavil_rx3",
  5225. .no_pcm = 1,
  5226. .dpcm_playback = 1,
  5227. .id = MSM_BACKEND_DAI_SLIMBUS_5_RX,
  5228. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5229. .ops = &msm_be_ops,
  5230. /* dai link has playback support */
  5231. .ignore_pmdown_time = 1,
  5232. .ignore_suspend = 1,
  5233. },
  5234. /* MAD BE */
  5235. {
  5236. .name = LPASS_BE_SLIMBUS_5_TX,
  5237. .stream_name = "Slimbus5 Capture",
  5238. .cpu_dai_name = "msm-dai-q6-dev.16395",
  5239. .platform_name = "msm-pcm-routing",
  5240. .codec_name = "tavil_codec",
  5241. .codec_dai_name = "tavil_mad1",
  5242. .no_pcm = 1,
  5243. .dpcm_capture = 1,
  5244. .id = MSM_BACKEND_DAI_SLIMBUS_5_TX,
  5245. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5246. .ops = &msm_be_ops,
  5247. .ignore_suspend = 1,
  5248. },
  5249. {
  5250. .name = LPASS_BE_SLIMBUS_6_RX,
  5251. .stream_name = "Slimbus6 Playback",
  5252. .cpu_dai_name = "msm-dai-q6-dev.16396",
  5253. .platform_name = "msm-pcm-routing",
  5254. .codec_name = "tavil_codec",
  5255. .codec_dai_name = "tavil_rx4",
  5256. .no_pcm = 1,
  5257. .dpcm_playback = 1,
  5258. .id = MSM_BACKEND_DAI_SLIMBUS_6_RX,
  5259. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5260. .ops = &msm_be_ops,
  5261. /* dai link has playback support */
  5262. .ignore_pmdown_time = 1,
  5263. .ignore_suspend = 1,
  5264. },
  5265. /* Slimbus VI Recording */
  5266. {
  5267. .name = LPASS_BE_SLIMBUS_TX_VI,
  5268. .stream_name = "Slimbus4 Capture",
  5269. .cpu_dai_name = "msm-dai-q6-dev.16393",
  5270. .platform_name = "msm-pcm-routing",
  5271. .codec_name = "tavil_codec",
  5272. .codec_dai_name = "tavil_vifeedback",
  5273. .id = MSM_BACKEND_DAI_SLIMBUS_4_TX,
  5274. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5275. .ops = &msm_be_ops,
  5276. .ignore_suspend = 1,
  5277. .no_pcm = 1,
  5278. .dpcm_capture = 1,
  5279. .ignore_pmdown_time = 1,
  5280. },
  5281. };
  5282. static struct snd_soc_dai_link msm_wcn_be_dai_links[] = {
  5283. {
  5284. .name = LPASS_BE_SLIMBUS_7_RX,
  5285. .stream_name = "Slimbus7 Playback",
  5286. .cpu_dai_name = "msm-dai-q6-dev.16398",
  5287. .platform_name = "msm-pcm-routing",
  5288. .codec_name = "btfmslim_slave",
  5289. /* BT codec driver determines capabilities based on
  5290. * dai name, bt codecdai name should always contains
  5291. * supported usecase information
  5292. */
  5293. .codec_dai_name = "btfm_bt_sco_a2dp_slim_rx",
  5294. .no_pcm = 1,
  5295. .dpcm_playback = 1,
  5296. .id = MSM_BACKEND_DAI_SLIMBUS_7_RX,
  5297. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5298. .ops = &msm_wcn_ops,
  5299. /* dai link has playback support */
  5300. .ignore_pmdown_time = 1,
  5301. .ignore_suspend = 1,
  5302. },
  5303. {
  5304. .name = LPASS_BE_SLIMBUS_7_TX,
  5305. .stream_name = "Slimbus7 Capture",
  5306. .cpu_dai_name = "msm-dai-q6-dev.16399",
  5307. .platform_name = "msm-pcm-routing",
  5308. .codec_name = "btfmslim_slave",
  5309. .codec_dai_name = "btfm_bt_sco_slim_tx",
  5310. .no_pcm = 1,
  5311. .dpcm_capture = 1,
  5312. .id = MSM_BACKEND_DAI_SLIMBUS_7_TX,
  5313. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5314. .ops = &msm_wcn_ops,
  5315. .ignore_suspend = 1,
  5316. },
  5317. {
  5318. .name = LPASS_BE_SLIMBUS_8_TX,
  5319. .stream_name = "Slimbus8 Capture",
  5320. .cpu_dai_name = "msm-dai-q6-dev.16401",
  5321. .platform_name = "msm-pcm-routing",
  5322. .codec_name = "btfmslim_slave",
  5323. .codec_dai_name = "btfm_fm_slim_tx",
  5324. .no_pcm = 1,
  5325. .dpcm_capture = 1,
  5326. .id = MSM_BACKEND_DAI_SLIMBUS_8_TX,
  5327. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5328. .init = &msm_wcn_init,
  5329. .ops = &msm_wcn_ops,
  5330. .ignore_suspend = 1,
  5331. },
  5332. };
  5333. static struct snd_soc_dai_link ext_disp_be_dai_link[] = {
  5334. /* DISP PORT BACK END DAI Link */
  5335. {
  5336. .name = LPASS_BE_DISPLAY_PORT,
  5337. .stream_name = "Display Port Playback",
  5338. .cpu_dai_name = "msm-dai-q6-dp.24608",
  5339. .platform_name = "msm-pcm-routing",
  5340. .codec_name = "msm-ext-disp-audio-codec-rx",
  5341. .codec_dai_name = "msm_dp_audio_codec_rx_dai",
  5342. .no_pcm = 1,
  5343. .dpcm_playback = 1,
  5344. .id = MSM_BACKEND_DAI_DISPLAY_PORT_RX,
  5345. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5346. .ignore_pmdown_time = 1,
  5347. .ignore_suspend = 1,
  5348. },
  5349. };
  5350. static struct snd_soc_dai_link msm_mi2s_be_dai_links[] = {
  5351. {
  5352. .name = LPASS_BE_PRI_MI2S_RX,
  5353. .stream_name = "Primary MI2S Playback",
  5354. .cpu_dai_name = "msm-dai-q6-mi2s.0",
  5355. .platform_name = "msm-pcm-routing",
  5356. .codec_name = "msm-stub-codec.1",
  5357. .codec_dai_name = "msm-stub-rx",
  5358. .no_pcm = 1,
  5359. .dpcm_playback = 1,
  5360. .id = MSM_BACKEND_DAI_PRI_MI2S_RX,
  5361. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5362. .ops = &msm_mi2s_be_ops,
  5363. .ignore_suspend = 1,
  5364. .ignore_pmdown_time = 1,
  5365. },
  5366. {
  5367. .name = LPASS_BE_PRI_MI2S_TX,
  5368. .stream_name = "Primary MI2S Capture",
  5369. .cpu_dai_name = "msm-dai-q6-mi2s.0",
  5370. .platform_name = "msm-pcm-routing",
  5371. .codec_name = "msm-stub-codec.1",
  5372. .codec_dai_name = "msm-stub-tx",
  5373. .no_pcm = 1,
  5374. .dpcm_capture = 1,
  5375. .id = MSM_BACKEND_DAI_PRI_MI2S_TX,
  5376. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5377. .ops = &msm_mi2s_be_ops,
  5378. .ignore_suspend = 1,
  5379. },
  5380. {
  5381. .name = LPASS_BE_SEC_MI2S_RX,
  5382. .stream_name = "Secondary MI2S Playback",
  5383. .cpu_dai_name = "msm-dai-q6-mi2s.1",
  5384. .platform_name = "msm-pcm-routing",
  5385. .codec_name = "msm-stub-codec.1",
  5386. .codec_dai_name = "msm-stub-rx",
  5387. .no_pcm = 1,
  5388. .dpcm_playback = 1,
  5389. .id = MSM_BACKEND_DAI_SECONDARY_MI2S_RX,
  5390. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5391. .ops = &msm_mi2s_be_ops,
  5392. .ignore_suspend = 1,
  5393. .ignore_pmdown_time = 1,
  5394. },
  5395. {
  5396. .name = LPASS_BE_SEC_MI2S_TX,
  5397. .stream_name = "Secondary MI2S Capture",
  5398. .cpu_dai_name = "msm-dai-q6-mi2s.1",
  5399. .platform_name = "msm-pcm-routing",
  5400. .codec_name = "msm-stub-codec.1",
  5401. .codec_dai_name = "msm-stub-tx",
  5402. .no_pcm = 1,
  5403. .dpcm_capture = 1,
  5404. .id = MSM_BACKEND_DAI_SECONDARY_MI2S_TX,
  5405. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5406. .ops = &msm_mi2s_be_ops,
  5407. .ignore_suspend = 1,
  5408. },
  5409. {
  5410. .name = LPASS_BE_TERT_MI2S_RX,
  5411. .stream_name = "Tertiary MI2S Playback",
  5412. .cpu_dai_name = "msm-dai-q6-mi2s.2",
  5413. .platform_name = "msm-pcm-routing",
  5414. .codec_name = "msm-stub-codec.1",
  5415. .codec_dai_name = "msm-stub-rx",
  5416. .no_pcm = 1,
  5417. .dpcm_playback = 1,
  5418. .id = MSM_BACKEND_DAI_TERTIARY_MI2S_RX,
  5419. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5420. .ops = &msm_mi2s_be_ops,
  5421. .ignore_suspend = 1,
  5422. .ignore_pmdown_time = 1,
  5423. },
  5424. {
  5425. .name = LPASS_BE_TERT_MI2S_TX,
  5426. .stream_name = "Tertiary MI2S Capture",
  5427. .cpu_dai_name = "msm-dai-q6-mi2s.2",
  5428. .platform_name = "msm-pcm-routing",
  5429. .codec_name = "msm-stub-codec.1",
  5430. .codec_dai_name = "msm-stub-tx",
  5431. .no_pcm = 1,
  5432. .dpcm_capture = 1,
  5433. .id = MSM_BACKEND_DAI_TERTIARY_MI2S_TX,
  5434. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5435. .ops = &msm_mi2s_be_ops,
  5436. .ignore_suspend = 1,
  5437. },
  5438. {
  5439. .name = LPASS_BE_QUAT_MI2S_RX,
  5440. .stream_name = "Quaternary MI2S Playback",
  5441. .cpu_dai_name = "msm-dai-q6-mi2s.3",
  5442. .platform_name = "msm-pcm-routing",
  5443. .codec_name = "msm-stub-codec.1",
  5444. .codec_dai_name = "msm-stub-rx",
  5445. .no_pcm = 1,
  5446. .dpcm_playback = 1,
  5447. .id = MSM_BACKEND_DAI_QUATERNARY_MI2S_RX,
  5448. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5449. .ops = &msm_mi2s_be_ops,
  5450. .ignore_suspend = 1,
  5451. .ignore_pmdown_time = 1,
  5452. },
  5453. {
  5454. .name = LPASS_BE_QUAT_MI2S_TX,
  5455. .stream_name = "Quaternary MI2S Capture",
  5456. .cpu_dai_name = "msm-dai-q6-mi2s.3",
  5457. .platform_name = "msm-pcm-routing",
  5458. .codec_name = "msm-stub-codec.1",
  5459. .codec_dai_name = "msm-stub-tx",
  5460. .no_pcm = 1,
  5461. .dpcm_capture = 1,
  5462. .id = MSM_BACKEND_DAI_QUATERNARY_MI2S_TX,
  5463. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5464. .ops = &msm_mi2s_be_ops,
  5465. .ignore_suspend = 1,
  5466. },
  5467. };
  5468. static struct snd_soc_dai_link msm_auxpcm_be_dai_links[] = {
  5469. /* Primary AUX PCM Backend DAI Links */
  5470. {
  5471. .name = LPASS_BE_AUXPCM_RX,
  5472. .stream_name = "AUX PCM Playback",
  5473. .cpu_dai_name = "msm-dai-q6-auxpcm.1",
  5474. .platform_name = "msm-pcm-routing",
  5475. .codec_name = "msm-stub-codec.1",
  5476. .codec_dai_name = "msm-stub-rx",
  5477. .no_pcm = 1,
  5478. .dpcm_playback = 1,
  5479. .id = MSM_BACKEND_DAI_AUXPCM_RX,
  5480. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5481. .ignore_pmdown_time = 1,
  5482. .ignore_suspend = 1,
  5483. .ops = &msm_aux_pcm_be_ops,
  5484. },
  5485. {
  5486. .name = LPASS_BE_AUXPCM_TX,
  5487. .stream_name = "AUX PCM Capture",
  5488. .cpu_dai_name = "msm-dai-q6-auxpcm.1",
  5489. .platform_name = "msm-pcm-routing",
  5490. .codec_name = "msm-stub-codec.1",
  5491. .codec_dai_name = "msm-stub-tx",
  5492. .no_pcm = 1,
  5493. .dpcm_capture = 1,
  5494. .id = MSM_BACKEND_DAI_AUXPCM_TX,
  5495. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5496. .ignore_pmdown_time = 1,
  5497. .ignore_suspend = 1,
  5498. .ops = &msm_aux_pcm_be_ops,
  5499. },
  5500. /* Secondary AUX PCM Backend DAI Links */
  5501. {
  5502. .name = LPASS_BE_SEC_AUXPCM_RX,
  5503. .stream_name = "Sec AUX PCM Playback",
  5504. .cpu_dai_name = "msm-dai-q6-auxpcm.2",
  5505. .platform_name = "msm-pcm-routing",
  5506. .codec_name = "msm-stub-codec.1",
  5507. .codec_dai_name = "msm-stub-rx",
  5508. .no_pcm = 1,
  5509. .dpcm_playback = 1,
  5510. .id = MSM_BACKEND_DAI_SEC_AUXPCM_RX,
  5511. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5512. .ignore_pmdown_time = 1,
  5513. .ignore_suspend = 1,
  5514. .ops = &msm_aux_pcm_be_ops,
  5515. },
  5516. {
  5517. .name = LPASS_BE_SEC_AUXPCM_TX,
  5518. .stream_name = "Sec AUX PCM Capture",
  5519. .cpu_dai_name = "msm-dai-q6-auxpcm.2",
  5520. .platform_name = "msm-pcm-routing",
  5521. .codec_name = "msm-stub-codec.1",
  5522. .codec_dai_name = "msm-stub-tx",
  5523. .no_pcm = 1,
  5524. .dpcm_capture = 1,
  5525. .id = MSM_BACKEND_DAI_SEC_AUXPCM_TX,
  5526. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5527. .ignore_suspend = 1,
  5528. .ignore_pmdown_time = 1,
  5529. .ops = &msm_aux_pcm_be_ops,
  5530. },
  5531. /* Tertiary AUX PCM Backend DAI Links */
  5532. {
  5533. .name = LPASS_BE_TERT_AUXPCM_RX,
  5534. .stream_name = "Tert AUX PCM Playback",
  5535. .cpu_dai_name = "msm-dai-q6-auxpcm.3",
  5536. .platform_name = "msm-pcm-routing",
  5537. .codec_name = "msm-stub-codec.1",
  5538. .codec_dai_name = "msm-stub-rx",
  5539. .no_pcm = 1,
  5540. .dpcm_playback = 1,
  5541. .id = MSM_BACKEND_DAI_TERT_AUXPCM_RX,
  5542. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5543. .ignore_pmdown_time = 1,
  5544. .ignore_suspend = 1,
  5545. .ops = &msm_aux_pcm_be_ops,
  5546. },
  5547. {
  5548. .name = LPASS_BE_TERT_AUXPCM_TX,
  5549. .stream_name = "Tert AUX PCM Capture",
  5550. .cpu_dai_name = "msm-dai-q6-auxpcm.3",
  5551. .platform_name = "msm-pcm-routing",
  5552. .codec_name = "msm-stub-codec.1",
  5553. .codec_dai_name = "msm-stub-tx",
  5554. .no_pcm = 1,
  5555. .dpcm_capture = 1,
  5556. .id = MSM_BACKEND_DAI_TERT_AUXPCM_TX,
  5557. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5558. .ignore_suspend = 1,
  5559. .ignore_pmdown_time = 1,
  5560. .ops = &msm_aux_pcm_be_ops,
  5561. },
  5562. /* Quaternary AUX PCM Backend DAI Links */
  5563. {
  5564. .name = LPASS_BE_QUAT_AUXPCM_RX,
  5565. .stream_name = "Quat AUX PCM Playback",
  5566. .cpu_dai_name = "msm-dai-q6-auxpcm.4",
  5567. .platform_name = "msm-pcm-routing",
  5568. .codec_name = "msm-stub-codec.1",
  5569. .codec_dai_name = "msm-stub-rx",
  5570. .no_pcm = 1,
  5571. .dpcm_playback = 1,
  5572. .id = MSM_BACKEND_DAI_QUAT_AUXPCM_RX,
  5573. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5574. .ignore_pmdown_time = 1,
  5575. .ignore_suspend = 1,
  5576. .ops = &msm_aux_pcm_be_ops,
  5577. },
  5578. {
  5579. .name = LPASS_BE_QUAT_AUXPCM_TX,
  5580. .stream_name = "Quat AUX PCM Capture",
  5581. .cpu_dai_name = "msm-dai-q6-auxpcm.4",
  5582. .platform_name = "msm-pcm-routing",
  5583. .codec_name = "msm-stub-codec.1",
  5584. .codec_dai_name = "msm-stub-tx",
  5585. .no_pcm = 1,
  5586. .dpcm_capture = 1,
  5587. .id = MSM_BACKEND_DAI_QUAT_AUXPCM_TX,
  5588. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5589. .ignore_suspend = 1,
  5590. .ignore_pmdown_time = 1,
  5591. .ops = &msm_aux_pcm_be_ops,
  5592. },
  5593. };
  5594. static struct snd_soc_dai_link msm_tavil_snd_card_dai_links[
  5595. ARRAY_SIZE(msm_common_dai_links) +
  5596. ARRAY_SIZE(msm_tavil_fe_dai_links) +
  5597. ARRAY_SIZE(msm_common_misc_fe_dai_links) +
  5598. ARRAY_SIZE(msm_common_be_dai_links) +
  5599. ARRAY_SIZE(msm_tavil_be_dai_links) +
  5600. ARRAY_SIZE(msm_wcn_be_dai_links) +
  5601. ARRAY_SIZE(ext_disp_be_dai_link) +
  5602. ARRAY_SIZE(msm_mi2s_be_dai_links) +
  5603. ARRAY_SIZE(msm_auxpcm_be_dai_links)];
  5604. static int msm_snd_card_tavil_late_probe(struct snd_soc_card *card)
  5605. {
  5606. const char *be_dl_name = LPASS_BE_SLIMBUS_0_RX;
  5607. struct snd_soc_pcm_runtime *rtd;
  5608. int ret = 0;
  5609. void *mbhc_calibration;
  5610. rtd = snd_soc_get_pcm_runtime(card, be_dl_name);
  5611. if (!rtd) {
  5612. dev_err(card->dev,
  5613. "%s: snd_soc_get_pcm_runtime for %s failed!\n",
  5614. __func__, be_dl_name);
  5615. ret = -EINVAL;
  5616. goto err;
  5617. }
  5618. mbhc_calibration = def_tavil_mbhc_cal();
  5619. if (!mbhc_calibration) {
  5620. ret = -ENOMEM;
  5621. goto err;
  5622. }
  5623. wcd_mbhc_cfg.calibration = mbhc_calibration;
  5624. ret = tavil_mbhc_hs_detect(rtd->codec, &wcd_mbhc_cfg);
  5625. if (ret) {
  5626. dev_err(card->dev, "%s: mbhc hs detect failed, err:%d\n",
  5627. __func__, ret);
  5628. goto err_free_mbhc_cal;
  5629. }
  5630. return 0;
  5631. err_free_mbhc_cal:
  5632. kfree(mbhc_calibration);
  5633. err:
  5634. return ret;
  5635. }
  5636. struct snd_soc_card snd_soc_card_tavil_msm = {
  5637. .name = "sdm845-tavil-snd-card",
  5638. .late_probe = msm_snd_card_tavil_late_probe,
  5639. };
  5640. static int msm_populate_dai_link_component_of_node(
  5641. struct snd_soc_card *card)
  5642. {
  5643. int i, index, ret = 0;
  5644. struct device *cdev = card->dev;
  5645. struct snd_soc_dai_link *dai_link = card->dai_link;
  5646. struct device_node *np;
  5647. if (!cdev) {
  5648. pr_err("%s: Sound card device memory NULL\n", __func__);
  5649. return -ENODEV;
  5650. }
  5651. for (i = 0; i < card->num_links; i++) {
  5652. if (dai_link[i].platform_of_node && dai_link[i].cpu_of_node)
  5653. continue;
  5654. /* populate platform_of_node for snd card dai links */
  5655. if (dai_link[i].platform_name &&
  5656. !dai_link[i].platform_of_node) {
  5657. index = of_property_match_string(cdev->of_node,
  5658. "asoc-platform-names",
  5659. dai_link[i].platform_name);
  5660. if (index < 0) {
  5661. pr_err("%s: No match found for platform name: %s\n",
  5662. __func__, dai_link[i].platform_name);
  5663. ret = index;
  5664. goto err;
  5665. }
  5666. np = of_parse_phandle(cdev->of_node, "asoc-platform",
  5667. index);
  5668. if (!np) {
  5669. pr_err("%s: retrieving phandle for platform %s, index %d failed\n",
  5670. __func__, dai_link[i].platform_name,
  5671. index);
  5672. ret = -ENODEV;
  5673. goto err;
  5674. }
  5675. dai_link[i].platform_of_node = np;
  5676. dai_link[i].platform_name = NULL;
  5677. }
  5678. /* populate cpu_of_node for snd card dai links */
  5679. if (dai_link[i].cpu_dai_name && !dai_link[i].cpu_of_node) {
  5680. index = of_property_match_string(cdev->of_node,
  5681. "asoc-cpu-names",
  5682. dai_link[i].cpu_dai_name);
  5683. if (index >= 0) {
  5684. np = of_parse_phandle(cdev->of_node, "asoc-cpu",
  5685. index);
  5686. if (!np) {
  5687. pr_err("%s: retrieving phandle for cpu dai %s failed\n",
  5688. __func__,
  5689. dai_link[i].cpu_dai_name);
  5690. ret = -ENODEV;
  5691. goto err;
  5692. }
  5693. dai_link[i].cpu_of_node = np;
  5694. dai_link[i].cpu_dai_name = NULL;
  5695. }
  5696. }
  5697. /* populate codec_of_node for snd card dai links */
  5698. if (dai_link[i].codec_name && !dai_link[i].codec_of_node) {
  5699. index = of_property_match_string(cdev->of_node,
  5700. "asoc-codec-names",
  5701. dai_link[i].codec_name);
  5702. if (index < 0)
  5703. continue;
  5704. np = of_parse_phandle(cdev->of_node, "asoc-codec",
  5705. index);
  5706. if (!np) {
  5707. pr_err("%s: retrieving phandle for codec %s failed\n",
  5708. __func__, dai_link[i].codec_name);
  5709. ret = -ENODEV;
  5710. goto err;
  5711. }
  5712. dai_link[i].codec_of_node = np;
  5713. dai_link[i].codec_name = NULL;
  5714. }
  5715. }
  5716. err:
  5717. return ret;
  5718. }
  5719. static int msm_prepare_us_euro(struct snd_soc_card *card)
  5720. {
  5721. struct msm_asoc_mach_data *pdata =
  5722. snd_soc_card_get_drvdata(card);
  5723. int ret = 0;
  5724. if (pdata->us_euro_gpio >= 0) {
  5725. dev_dbg(card->dev, "%s: us_euro gpio request %d", __func__,
  5726. pdata->us_euro_gpio);
  5727. ret = gpio_request(pdata->us_euro_gpio, "TAVIL_CODEC_US_EURO");
  5728. if (ret) {
  5729. dev_err(card->dev,
  5730. "%s: Failed to request codec US/EURO gpio %d error %d\n",
  5731. __func__, pdata->us_euro_gpio, ret);
  5732. }
  5733. }
  5734. return ret;
  5735. }
  5736. static int msm_audrx_stub_init(struct snd_soc_pcm_runtime *rtd)
  5737. {
  5738. int ret = 0;
  5739. struct snd_soc_codec *codec = rtd->codec;
  5740. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  5741. ret = snd_soc_add_codec_controls(codec, msm_snd_controls,
  5742. ARRAY_SIZE(msm_snd_controls));
  5743. if (ret < 0) {
  5744. dev_err(codec->dev,
  5745. "%s: add_codec_controls failed, err = %d\n",
  5746. __func__, ret);
  5747. return ret;
  5748. }
  5749. snd_soc_dapm_new_controls(dapm, msm_dapm_widgets,
  5750. ARRAY_SIZE(msm_dapm_widgets));
  5751. return 0;
  5752. }
  5753. static int msm_snd_stub_hw_params(struct snd_pcm_substream *substream,
  5754. struct snd_pcm_hw_params *params)
  5755. {
  5756. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  5757. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  5758. int ret = 0;
  5759. unsigned int rx_ch[] = {144, 145, 146, 147, 148, 149, 150,
  5760. 151};
  5761. unsigned int tx_ch[] = {128, 129, 130, 131, 132, 133,
  5762. 134, 135, 136, 137, 138, 139,
  5763. 140, 141, 142, 143};
  5764. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  5765. ret = snd_soc_dai_set_channel_map(cpu_dai, 0, 0,
  5766. slim_rx_cfg[0].channels,
  5767. rx_ch);
  5768. if (ret < 0)
  5769. pr_err("%s: RX failed to set cpu chan map error %d\n",
  5770. __func__, ret);
  5771. } else {
  5772. ret = snd_soc_dai_set_channel_map(cpu_dai,
  5773. slim_tx_cfg[0].channels,
  5774. tx_ch, 0, 0);
  5775. if (ret < 0)
  5776. pr_err("%s: TX failed to set cpu chan map error %d\n",
  5777. __func__, ret);
  5778. }
  5779. return ret;
  5780. }
  5781. static struct snd_soc_ops msm_stub_be_ops = {
  5782. .hw_params = msm_snd_stub_hw_params,
  5783. };
  5784. static struct snd_soc_dai_link msm_stub_fe_dai_links[] = {
  5785. /* FrontEnd DAI Links */
  5786. {
  5787. .name = "MSMSTUB Media1",
  5788. .stream_name = "MultiMedia1",
  5789. .cpu_dai_name = "MultiMedia1",
  5790. .platform_name = "msm-pcm-dsp.0",
  5791. .dynamic = 1,
  5792. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  5793. .dpcm_playback = 1,
  5794. .dpcm_capture = 1,
  5795. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  5796. SND_SOC_DPCM_TRIGGER_POST},
  5797. .codec_dai_name = "snd-soc-dummy-dai",
  5798. .codec_name = "snd-soc-dummy",
  5799. .ignore_suspend = 1,
  5800. /* this dainlink has playback support */
  5801. .ignore_pmdown_time = 1,
  5802. .id = MSM_FRONTEND_DAI_MULTIMEDIA1
  5803. },
  5804. };
  5805. static struct snd_soc_dai_link msm_stub_be_dai_links[] = {
  5806. /* Backend DAI Links */
  5807. {
  5808. .name = LPASS_BE_SLIMBUS_0_RX,
  5809. .stream_name = "Slimbus Playback",
  5810. .cpu_dai_name = "msm-dai-q6-dev.16384",
  5811. .platform_name = "msm-pcm-routing",
  5812. .codec_name = "msm-stub-codec.1",
  5813. .codec_dai_name = "msm-stub-rx",
  5814. .no_pcm = 1,
  5815. .dpcm_playback = 1,
  5816. .id = MSM_BACKEND_DAI_SLIMBUS_0_RX,
  5817. .init = &msm_audrx_stub_init,
  5818. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5819. .ignore_pmdown_time = 1, /* dai link has playback support */
  5820. .ignore_suspend = 1,
  5821. .ops = &msm_stub_be_ops,
  5822. },
  5823. {
  5824. .name = LPASS_BE_SLIMBUS_0_TX,
  5825. .stream_name = "Slimbus Capture",
  5826. .cpu_dai_name = "msm-dai-q6-dev.16385",
  5827. .platform_name = "msm-pcm-routing",
  5828. .codec_name = "msm-stub-codec.1",
  5829. .codec_dai_name = "msm-stub-tx",
  5830. .no_pcm = 1,
  5831. .dpcm_capture = 1,
  5832. .id = MSM_BACKEND_DAI_SLIMBUS_0_TX,
  5833. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5834. .ignore_suspend = 1,
  5835. .ops = &msm_stub_be_ops,
  5836. },
  5837. };
  5838. static struct snd_soc_dai_link msm_stub_dai_links[
  5839. ARRAY_SIZE(msm_stub_fe_dai_links) +
  5840. ARRAY_SIZE(msm_stub_be_dai_links)];
  5841. struct snd_soc_card snd_soc_card_stub_msm = {
  5842. .name = "sdm845-stub-snd-card",
  5843. };
  5844. static const struct of_device_id sdm845_asoc_machine_of_match[] = {
  5845. { .compatible = "qcom,sdm845-asoc-snd-tavil",
  5846. .data = "tavil_codec"},
  5847. { .compatible = "qcom,sdm845-asoc-snd-stub",
  5848. .data = "stub_codec"},
  5849. {},
  5850. };
  5851. static struct snd_soc_card *populate_snd_card_dailinks(struct device *dev)
  5852. {
  5853. struct snd_soc_card *card = NULL;
  5854. struct snd_soc_dai_link *dailink;
  5855. int len_1, len_2, len_3, len_4;
  5856. int total_links;
  5857. const struct of_device_id *match;
  5858. match = of_match_node(sdm845_asoc_machine_of_match, dev->of_node);
  5859. if (!match) {
  5860. dev_err(dev, "%s: No DT match found for sound card\n",
  5861. __func__);
  5862. return NULL;
  5863. }
  5864. if (!strcmp(match->data, "tavil_codec")) {
  5865. card = &snd_soc_card_tavil_msm;
  5866. len_1 = ARRAY_SIZE(msm_common_dai_links);
  5867. len_2 = len_1 + ARRAY_SIZE(msm_tavil_fe_dai_links);
  5868. len_3 = len_2 + ARRAY_SIZE(msm_common_misc_fe_dai_links);
  5869. len_4 = len_3 + ARRAY_SIZE(msm_common_be_dai_links);
  5870. total_links = len_4 + ARRAY_SIZE(msm_tavil_be_dai_links);
  5871. memcpy(msm_tavil_snd_card_dai_links,
  5872. msm_common_dai_links,
  5873. sizeof(msm_common_dai_links));
  5874. memcpy(msm_tavil_snd_card_dai_links + len_1,
  5875. msm_tavil_fe_dai_links,
  5876. sizeof(msm_tavil_fe_dai_links));
  5877. memcpy(msm_tavil_snd_card_dai_links + len_2,
  5878. msm_common_misc_fe_dai_links,
  5879. sizeof(msm_common_misc_fe_dai_links));
  5880. memcpy(msm_tavil_snd_card_dai_links + len_3,
  5881. msm_common_be_dai_links,
  5882. sizeof(msm_common_be_dai_links));
  5883. memcpy(msm_tavil_snd_card_dai_links + len_4,
  5884. msm_tavil_be_dai_links,
  5885. sizeof(msm_tavil_be_dai_links));
  5886. if (of_property_read_bool(dev->of_node, "qcom,wcn-btfm")) {
  5887. dev_dbg(dev, "%s(): WCN BTFM support present\n",
  5888. __func__);
  5889. memcpy(msm_tavil_snd_card_dai_links + total_links,
  5890. msm_wcn_be_dai_links,
  5891. sizeof(msm_wcn_be_dai_links));
  5892. total_links += ARRAY_SIZE(msm_wcn_be_dai_links);
  5893. }
  5894. if (of_property_read_bool(dev->of_node,
  5895. "qcom,ext-disp-audio-rx")) {
  5896. dev_dbg(dev, "%s(): ext disp audio support present\n",
  5897. __func__);
  5898. memcpy(msm_tavil_snd_card_dai_links + total_links,
  5899. ext_disp_be_dai_link,
  5900. sizeof(ext_disp_be_dai_link));
  5901. total_links += ARRAY_SIZE(ext_disp_be_dai_link);
  5902. }
  5903. if (of_property_read_bool(dev->of_node,
  5904. "qcom,mi2s-audio-intf")) {
  5905. memcpy(msm_tavil_snd_card_dai_links + total_links,
  5906. msm_mi2s_be_dai_links,
  5907. sizeof(msm_mi2s_be_dai_links));
  5908. total_links += ARRAY_SIZE(msm_mi2s_be_dai_links);
  5909. }
  5910. if (of_property_read_bool(dev->of_node,
  5911. "qcom,auxpcm-audio-intf")) {
  5912. memcpy(msm_tavil_snd_card_dai_links + total_links,
  5913. msm_auxpcm_be_dai_links,
  5914. sizeof(msm_auxpcm_be_dai_links));
  5915. total_links += ARRAY_SIZE(msm_auxpcm_be_dai_links);
  5916. }
  5917. dailink = msm_tavil_snd_card_dai_links;
  5918. } else if (!strcmp(match->data, "stub_codec")) {
  5919. card = &snd_soc_card_stub_msm;
  5920. len_1 = ARRAY_SIZE(msm_stub_fe_dai_links);
  5921. len_2 = len_1 + ARRAY_SIZE(msm_stub_be_dai_links);
  5922. memcpy(msm_stub_dai_links,
  5923. msm_stub_fe_dai_links,
  5924. sizeof(msm_stub_fe_dai_links));
  5925. memcpy(msm_stub_dai_links + len_1,
  5926. msm_stub_be_dai_links,
  5927. sizeof(msm_stub_be_dai_links));
  5928. dailink = msm_stub_dai_links;
  5929. total_links = len_2;
  5930. }
  5931. if (card) {
  5932. card->dai_link = dailink;
  5933. card->num_links = total_links;
  5934. }
  5935. return card;
  5936. }
  5937. static int msm_wsa881x_init(struct snd_soc_component *component)
  5938. {
  5939. u8 spkleft_ports[WSA881X_MAX_SWR_PORTS] = {100, 101, 102, 106};
  5940. u8 spkright_ports[WSA881X_MAX_SWR_PORTS] = {103, 104, 105, 107};
  5941. unsigned int ch_rate[WSA881X_MAX_SWR_PORTS] = {2400, 600, 300, 1200};
  5942. unsigned int ch_mask[WSA881X_MAX_SWR_PORTS] = {0x1, 0xF, 0x3, 0x3};
  5943. struct snd_soc_codec *codec = snd_soc_component_to_codec(component);
  5944. struct msm_asoc_mach_data *pdata;
  5945. struct snd_soc_dapm_context *dapm;
  5946. int ret = 0;
  5947. if (!codec) {
  5948. pr_err("%s codec is NULL\n", __func__);
  5949. return -EINVAL;
  5950. }
  5951. dapm = snd_soc_codec_get_dapm(codec);
  5952. if (!strcmp(component->name_prefix, "SpkrLeft")) {
  5953. dev_dbg(codec->dev, "%s: setting left ch map to codec %s\n",
  5954. __func__, codec->component.name);
  5955. wsa881x_set_channel_map(codec, &spkleft_ports[0],
  5956. WSA881X_MAX_SWR_PORTS, &ch_mask[0],
  5957. &ch_rate[0], NULL);
  5958. if (dapm->component) {
  5959. snd_soc_dapm_ignore_suspend(dapm, "SpkrLeft IN");
  5960. snd_soc_dapm_ignore_suspend(dapm, "SpkrLeft SPKR");
  5961. }
  5962. } else if (!strcmp(component->name_prefix, "SpkrRight")) {
  5963. dev_dbg(codec->dev, "%s: setting right ch map to codec %s\n",
  5964. __func__, codec->component.name);
  5965. wsa881x_set_channel_map(codec, &spkright_ports[0],
  5966. WSA881X_MAX_SWR_PORTS, &ch_mask[0],
  5967. &ch_rate[0], NULL);
  5968. if (dapm->component) {
  5969. snd_soc_dapm_ignore_suspend(dapm, "SpkrRight IN");
  5970. snd_soc_dapm_ignore_suspend(dapm, "SpkrRight SPKR");
  5971. }
  5972. } else {
  5973. dev_err(codec->dev, "%s: wrong codec name %s\n", __func__,
  5974. codec->component.name);
  5975. ret = -EINVAL;
  5976. goto err;
  5977. }
  5978. pdata = snd_soc_card_get_drvdata(component->card);
  5979. if (pdata && pdata->codec_root)
  5980. wsa881x_codec_info_create_codec_entry(pdata->codec_root,
  5981. codec);
  5982. err:
  5983. return ret;
  5984. }
  5985. static int msm_init_wsa_dev(struct platform_device *pdev,
  5986. struct snd_soc_card *card)
  5987. {
  5988. struct device_node *wsa_of_node;
  5989. u32 wsa_max_devs;
  5990. u32 wsa_dev_cnt;
  5991. int i;
  5992. struct msm_wsa881x_dev_info *wsa881x_dev_info;
  5993. const char *wsa_auxdev_name_prefix[1];
  5994. char *dev_name_str = NULL;
  5995. int found = 0;
  5996. int ret = 0;
  5997. /* Get maximum WSA device count for this platform */
  5998. ret = of_property_read_u32(pdev->dev.of_node,
  5999. "qcom,wsa-max-devs", &wsa_max_devs);
  6000. if (ret) {
  6001. dev_info(&pdev->dev,
  6002. "%s: wsa-max-devs property missing in DT %s, ret = %d\n",
  6003. __func__, pdev->dev.of_node->full_name, ret);
  6004. card->num_aux_devs = 0;
  6005. return 0;
  6006. }
  6007. if (wsa_max_devs == 0) {
  6008. dev_warn(&pdev->dev,
  6009. "%s: Max WSA devices is 0 for this target?\n",
  6010. __func__);
  6011. card->num_aux_devs = 0;
  6012. return 0;
  6013. }
  6014. /* Get count of WSA device phandles for this platform */
  6015. wsa_dev_cnt = of_count_phandle_with_args(pdev->dev.of_node,
  6016. "qcom,wsa-devs", NULL);
  6017. if (wsa_dev_cnt == -ENOENT) {
  6018. dev_warn(&pdev->dev, "%s: No wsa device defined in DT.\n",
  6019. __func__);
  6020. goto err;
  6021. } else if (wsa_dev_cnt <= 0) {
  6022. dev_err(&pdev->dev,
  6023. "%s: Error reading wsa device from DT. wsa_dev_cnt = %d\n",
  6024. __func__, wsa_dev_cnt);
  6025. ret = -EINVAL;
  6026. goto err;
  6027. }
  6028. /*
  6029. * Expect total phandles count to be NOT less than maximum possible
  6030. * WSA count. However, if it is less, then assign same value to
  6031. * max count as well.
  6032. */
  6033. if (wsa_dev_cnt < wsa_max_devs) {
  6034. dev_dbg(&pdev->dev,
  6035. "%s: wsa_max_devs = %d cannot exceed wsa_dev_cnt = %d\n",
  6036. __func__, wsa_max_devs, wsa_dev_cnt);
  6037. wsa_max_devs = wsa_dev_cnt;
  6038. }
  6039. /* Make sure prefix string passed for each WSA device */
  6040. ret = of_property_count_strings(pdev->dev.of_node,
  6041. "qcom,wsa-aux-dev-prefix");
  6042. if (ret != wsa_dev_cnt) {
  6043. dev_err(&pdev->dev,
  6044. "%s: expecting %d wsa prefix. Defined only %d in DT\n",
  6045. __func__, wsa_dev_cnt, ret);
  6046. ret = -EINVAL;
  6047. goto err;
  6048. }
  6049. /*
  6050. * Alloc mem to store phandle and index info of WSA device, if already
  6051. * registered with ALSA core
  6052. */
  6053. wsa881x_dev_info = devm_kcalloc(&pdev->dev, wsa_max_devs,
  6054. sizeof(struct msm_wsa881x_dev_info),
  6055. GFP_KERNEL);
  6056. if (!wsa881x_dev_info) {
  6057. ret = -ENOMEM;
  6058. goto err;
  6059. }
  6060. /*
  6061. * search and check whether all WSA devices are already
  6062. * registered with ALSA core or not. If found a node, store
  6063. * the node and the index in a local array of struct for later
  6064. * use.
  6065. */
  6066. for (i = 0; i < wsa_dev_cnt; i++) {
  6067. wsa_of_node = of_parse_phandle(pdev->dev.of_node,
  6068. "qcom,wsa-devs", i);
  6069. if (unlikely(!wsa_of_node)) {
  6070. /* we should not be here */
  6071. dev_err(&pdev->dev,
  6072. "%s: wsa dev node is not present\n",
  6073. __func__);
  6074. ret = -EINVAL;
  6075. goto err_free_dev_info;
  6076. }
  6077. if (soc_find_component(wsa_of_node, NULL)) {
  6078. /* WSA device registered with ALSA core */
  6079. wsa881x_dev_info[found].of_node = wsa_of_node;
  6080. wsa881x_dev_info[found].index = i;
  6081. found++;
  6082. if (found == wsa_max_devs)
  6083. break;
  6084. }
  6085. }
  6086. if (found < wsa_max_devs) {
  6087. dev_dbg(&pdev->dev,
  6088. "%s: failed to find %d components. Found only %d\n",
  6089. __func__, wsa_max_devs, found);
  6090. return -EPROBE_DEFER;
  6091. }
  6092. dev_info(&pdev->dev,
  6093. "%s: found %d wsa881x devices registered with ALSA core\n",
  6094. __func__, found);
  6095. card->num_aux_devs = wsa_max_devs;
  6096. card->num_configs = wsa_max_devs;
  6097. /* Alloc array of AUX devs struct */
  6098. msm_aux_dev = devm_kcalloc(&pdev->dev, card->num_aux_devs,
  6099. sizeof(struct snd_soc_aux_dev),
  6100. GFP_KERNEL);
  6101. if (!msm_aux_dev) {
  6102. ret = -ENOMEM;
  6103. goto err_free_dev_info;
  6104. }
  6105. /* Alloc array of codec conf struct */
  6106. msm_codec_conf = devm_kcalloc(&pdev->dev, card->num_aux_devs,
  6107. sizeof(struct snd_soc_codec_conf),
  6108. GFP_KERNEL);
  6109. if (!msm_codec_conf) {
  6110. ret = -ENOMEM;
  6111. goto err_free_aux_dev;
  6112. }
  6113. for (i = 0; i < card->num_aux_devs; i++) {
  6114. dev_name_str = devm_kzalloc(&pdev->dev, DEV_NAME_STR_LEN,
  6115. GFP_KERNEL);
  6116. if (!dev_name_str) {
  6117. ret = -ENOMEM;
  6118. goto err_free_cdc_conf;
  6119. }
  6120. ret = of_property_read_string_index(pdev->dev.of_node,
  6121. "qcom,wsa-aux-dev-prefix",
  6122. wsa881x_dev_info[i].index,
  6123. wsa_auxdev_name_prefix);
  6124. if (ret) {
  6125. dev_err(&pdev->dev,
  6126. "%s: failed to read wsa aux dev prefix, ret = %d\n",
  6127. __func__, ret);
  6128. ret = -EINVAL;
  6129. goto err_free_dev_name_str;
  6130. }
  6131. snprintf(dev_name_str, strlen("wsa881x.%d"), "wsa881x.%d", i);
  6132. msm_aux_dev[i].name = dev_name_str;
  6133. msm_aux_dev[i].codec_name = NULL;
  6134. msm_aux_dev[i].codec_of_node =
  6135. wsa881x_dev_info[i].of_node;
  6136. msm_aux_dev[i].init = msm_wsa881x_init;
  6137. msm_codec_conf[i].dev_name = NULL;
  6138. msm_codec_conf[i].name_prefix = wsa_auxdev_name_prefix[0];
  6139. msm_codec_conf[i].of_node =
  6140. wsa881x_dev_info[i].of_node;
  6141. }
  6142. card->codec_conf = msm_codec_conf;
  6143. card->aux_dev = msm_aux_dev;
  6144. return 0;
  6145. err_free_dev_name_str:
  6146. devm_kfree(&pdev->dev, dev_name_str);
  6147. err_free_cdc_conf:
  6148. devm_kfree(&pdev->dev, msm_codec_conf);
  6149. err_free_aux_dev:
  6150. devm_kfree(&pdev->dev, msm_aux_dev);
  6151. err_free_dev_info:
  6152. devm_kfree(&pdev->dev, wsa881x_dev_info);
  6153. err:
  6154. return ret;
  6155. }
  6156. static void msm_i2s_auxpcm_init(struct platform_device *pdev)
  6157. {
  6158. struct resource *muxsel;
  6159. int count;
  6160. u32 mi2s_master_slave[MI2S_MAX];
  6161. int ret;
  6162. char *str[PCM_I2S_SEL_MAX] = {
  6163. "lpaif_pri_mode_muxsel",
  6164. "lpaif_sec_mode_muxsel",
  6165. "lpaif_tert_mode_muxsel",
  6166. "lpaif_quat_mode_muxsel"
  6167. };
  6168. for (count = 0; count < MI2S_MAX; count++) {
  6169. mutex_init(&mi2s_intf_conf[count].lock);
  6170. mi2s_intf_conf[count].ref_cnt = 0;
  6171. }
  6172. for (count = 0; count < AUX_PCM_MAX; count++) {
  6173. mutex_init(&auxpcm_intf_conf[count].lock);
  6174. auxpcm_intf_conf[count].ref_cnt = 0;
  6175. }
  6176. for (count = 0; count < PCM_I2S_SEL_MAX; count++) {
  6177. mutex_init(&mi2s_auxpcm_conf[count].lock);
  6178. mi2s_auxpcm_conf[count].pcm_i2s_sel_vt_addr = NULL;
  6179. }
  6180. for (count = 0; count < PCM_I2S_SEL_MAX; count++) {
  6181. muxsel = platform_get_resource_byname(pdev, IORESOURCE_MEM,
  6182. str[count]);
  6183. if (muxsel) {
  6184. mi2s_auxpcm_conf[count].pcm_i2s_sel_vt_addr
  6185. = ioremap(muxsel->start, resource_size(muxsel));
  6186. }
  6187. }
  6188. ret = of_property_read_u32_array(pdev->dev.of_node,
  6189. "qcom,msm-mi2s-master",
  6190. mi2s_master_slave, MI2S_MAX);
  6191. if (ret) {
  6192. dev_dbg(&pdev->dev, "%s: no qcom,msm-mi2s-master in DT node\n",
  6193. __func__);
  6194. } else {
  6195. for (count = 0; count < MI2S_MAX; count++) {
  6196. mi2s_intf_conf[count].msm_is_mi2s_master =
  6197. mi2s_master_slave[count];
  6198. }
  6199. }
  6200. }
  6201. static void msm_i2s_auxpcm_deinit(void)
  6202. {
  6203. int count;
  6204. for (count = 0; count < PCM_I2S_SEL_MAX; count++) {
  6205. if (mi2s_auxpcm_conf[count].pcm_i2s_sel_vt_addr !=
  6206. NULL) {
  6207. iounmap(
  6208. mi2s_auxpcm_conf[count].pcm_i2s_sel_vt_addr);
  6209. mi2s_auxpcm_conf[count].pcm_i2s_sel_vt_addr = NULL;
  6210. }
  6211. mutex_destroy(&mi2s_auxpcm_conf[count].lock);
  6212. }
  6213. for (count = 0; count < AUX_PCM_MAX; count++) {
  6214. mutex_destroy(&auxpcm_intf_conf[count].lock);
  6215. auxpcm_intf_conf[count].ref_cnt = 0;
  6216. }
  6217. for (count = 0; count < MI2S_MAX; count++) {
  6218. mutex_destroy(&mi2s_intf_conf[count].lock);
  6219. mi2s_intf_conf[count].ref_cnt = 0;
  6220. mi2s_intf_conf[count].msm_is_mi2s_master = 0;
  6221. }
  6222. }
  6223. static int msm_asoc_machine_probe(struct platform_device *pdev)
  6224. {
  6225. struct snd_soc_card *card;
  6226. struct msm_asoc_mach_data *pdata;
  6227. const char *mbhc_audio_jack_type = NULL;
  6228. char *mclk_freq_prop_name;
  6229. const struct of_device_id *match;
  6230. int ret;
  6231. const char *usb_c_dt = "qcom,msm-mbhc-usbc-audio-supported";
  6232. if (!pdev->dev.of_node) {
  6233. dev_err(&pdev->dev, "No platform supplied from device tree\n");
  6234. return -EINVAL;
  6235. }
  6236. pdata = devm_kzalloc(&pdev->dev,
  6237. sizeof(struct msm_asoc_mach_data), GFP_KERNEL);
  6238. if (!pdata)
  6239. return -ENOMEM;
  6240. card = populate_snd_card_dailinks(&pdev->dev);
  6241. if (!card) {
  6242. dev_err(&pdev->dev, "%s: Card uninitialized\n", __func__);
  6243. ret = -EINVAL;
  6244. goto err;
  6245. }
  6246. card->dev = &pdev->dev;
  6247. platform_set_drvdata(pdev, card);
  6248. snd_soc_card_set_drvdata(card, pdata);
  6249. ret = snd_soc_of_parse_card_name(card, "qcom,model");
  6250. if (ret) {
  6251. dev_err(&pdev->dev, "parse card name failed, err:%d\n",
  6252. ret);
  6253. goto err;
  6254. }
  6255. ret = snd_soc_of_parse_audio_routing(card, "qcom,audio-routing");
  6256. if (ret) {
  6257. dev_err(&pdev->dev, "parse audio routing failed, err:%d\n",
  6258. ret);
  6259. goto err;
  6260. }
  6261. match = of_match_node(sdm845_asoc_machine_of_match,
  6262. pdev->dev.of_node);
  6263. if (!match) {
  6264. dev_err(&pdev->dev, "%s: no matched codec is found.\n",
  6265. __func__);
  6266. goto err;
  6267. }
  6268. mclk_freq_prop_name = "qcom,tavil-mclk-clk-freq";
  6269. ret = of_property_read_u32(pdev->dev.of_node,
  6270. mclk_freq_prop_name, &pdata->mclk_freq);
  6271. if (ret) {
  6272. dev_err(&pdev->dev,
  6273. "Looking up %s property in node %s failed, err%d\n",
  6274. mclk_freq_prop_name,
  6275. pdev->dev.of_node->full_name, ret);
  6276. goto err;
  6277. }
  6278. if (pdata->mclk_freq != CODEC_EXT_CLK_RATE) {
  6279. dev_err(&pdev->dev, "unsupported mclk freq %u\n",
  6280. pdata->mclk_freq);
  6281. ret = -EINVAL;
  6282. goto err;
  6283. }
  6284. ret = msm_populate_dai_link_component_of_node(card);
  6285. if (ret) {
  6286. ret = -EPROBE_DEFER;
  6287. goto err;
  6288. }
  6289. ret = msm_init_wsa_dev(pdev, card);
  6290. if (ret)
  6291. goto err;
  6292. ret = devm_snd_soc_register_card(&pdev->dev, card);
  6293. if (ret == -EPROBE_DEFER) {
  6294. if (codec_reg_done)
  6295. ret = -EINVAL;
  6296. goto err;
  6297. } else if (ret) {
  6298. dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
  6299. ret);
  6300. goto err;
  6301. }
  6302. dev_info(&pdev->dev, "Sound card %s registered\n", card->name);
  6303. spdev = pdev;
  6304. ret = of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev);
  6305. if (ret) {
  6306. dev_dbg(&pdev->dev, "%s: failed to add child nodes, ret=%d\n",
  6307. __func__, ret);
  6308. } else {
  6309. pdata->hph_en1_gpio_p = of_parse_phandle(pdev->dev.of_node,
  6310. "qcom,hph-en1-gpio", 0);
  6311. if (!pdata->hph_en1_gpio_p) {
  6312. dev_dbg(&pdev->dev, "property %s not detected in node %s",
  6313. "qcom,hph-en1-gpio",
  6314. pdev->dev.of_node->full_name);
  6315. }
  6316. pdata->hph_en0_gpio_p = of_parse_phandle(pdev->dev.of_node,
  6317. "qcom,hph-en0-gpio", 0);
  6318. if (!pdata->hph_en0_gpio_p) {
  6319. dev_dbg(&pdev->dev, "property %s not detected in node %s",
  6320. "qcom,hph-en0-gpio",
  6321. pdev->dev.of_node->full_name);
  6322. }
  6323. }
  6324. ret = of_property_read_string(pdev->dev.of_node,
  6325. "qcom,mbhc-audio-jack-type", &mbhc_audio_jack_type);
  6326. if (ret) {
  6327. dev_dbg(&pdev->dev, "Looking up %s property in node %s failed",
  6328. "qcom,mbhc-audio-jack-type",
  6329. pdev->dev.of_node->full_name);
  6330. dev_dbg(&pdev->dev, "Jack type properties set to default");
  6331. } else {
  6332. if (!strcmp(mbhc_audio_jack_type, "4-pole-jack")) {
  6333. wcd_mbhc_cfg.enable_anc_mic_detect = false;
  6334. dev_dbg(&pdev->dev, "This hardware has 4 pole jack");
  6335. } else if (!strcmp(mbhc_audio_jack_type, "5-pole-jack")) {
  6336. wcd_mbhc_cfg.enable_anc_mic_detect = true;
  6337. dev_dbg(&pdev->dev, "This hardware has 5 pole jack");
  6338. } else if (!strcmp(mbhc_audio_jack_type, "6-pole-jack")) {
  6339. wcd_mbhc_cfg.enable_anc_mic_detect = true;
  6340. dev_dbg(&pdev->dev, "This hardware has 6 pole jack");
  6341. } else {
  6342. wcd_mbhc_cfg.enable_anc_mic_detect = false;
  6343. dev_dbg(&pdev->dev, "Unknown value, set to default");
  6344. }
  6345. }
  6346. /*
  6347. * Parse US-Euro gpio info from DT. Report no error if us-euro
  6348. * entry is not found in DT file as some targets do not support
  6349. * US-Euro detection
  6350. */
  6351. pdata->us_euro_gpio = of_get_named_gpio(pdev->dev.of_node,
  6352. "qcom,us-euro-gpios", 0);
  6353. if (!gpio_is_valid(pdata->us_euro_gpio))
  6354. pdata->us_euro_gpio_p = of_parse_phandle(pdev->dev.of_node,
  6355. "qcom,us-euro-gpios", 0);
  6356. if (!gpio_is_valid(pdata->us_euro_gpio) && (!pdata->us_euro_gpio_p)) {
  6357. dev_dbg(&pdev->dev, "property %s not detected in node %s",
  6358. "qcom,us-euro-gpios", pdev->dev.of_node->full_name);
  6359. } else {
  6360. dev_dbg(&pdev->dev, "%s detected",
  6361. "qcom,us-euro-gpios");
  6362. wcd_mbhc_cfg.swap_gnd_mic = msm_swap_gnd_mic;
  6363. }
  6364. if (of_find_property(pdev->dev.of_node, usb_c_dt, NULL))
  6365. wcd_mbhc_cfg.swap_gnd_mic = msm_swap_gnd_mic;
  6366. ret = msm_prepare_us_euro(card);
  6367. if (ret)
  6368. dev_dbg(&pdev->dev, "msm_prepare_us_euro failed (%d)\n",
  6369. ret);
  6370. /* Parse pinctrl info from devicetree */
  6371. ret = msm_get_pinctrl(pdev);
  6372. if (!ret) {
  6373. pr_debug("%s: pinctrl parsing successful\n", __func__);
  6374. } else {
  6375. dev_dbg(&pdev->dev,
  6376. "%s: Parsing pinctrl failed with %d. Cannot use Ports\n",
  6377. __func__, ret);
  6378. ret = 0;
  6379. }
  6380. msm_i2s_auxpcm_init(pdev);
  6381. is_initial_boot = true;
  6382. ret = audio_notifier_register("sdm845", AUDIO_NOTIFIER_ADSP_DOMAIN,
  6383. &service_nb);
  6384. if (ret < 0)
  6385. pr_err("%s: Audio notifier register failed ret = %d\n",
  6386. __func__, ret);
  6387. return 0;
  6388. err:
  6389. msm_release_pinctrl(pdev);
  6390. devm_kfree(&pdev->dev, pdata);
  6391. return ret;
  6392. }
  6393. static int msm_asoc_machine_remove(struct platform_device *pdev)
  6394. {
  6395. struct snd_soc_card *card = platform_get_drvdata(pdev);
  6396. struct msm_asoc_mach_data *pdata =
  6397. snd_soc_card_get_drvdata(card);
  6398. audio_notifier_deregister("sdm845");
  6399. if (pdata->us_euro_gpio > 0) {
  6400. gpio_free(pdata->us_euro_gpio);
  6401. pdata->us_euro_gpio = 0;
  6402. }
  6403. msm_i2s_auxpcm_deinit();
  6404. msm_release_pinctrl(pdev);
  6405. snd_soc_unregister_card(card);
  6406. return 0;
  6407. }
  6408. static struct platform_driver sdm845_asoc_machine_driver = {
  6409. .driver = {
  6410. .name = DRV_NAME,
  6411. .owner = THIS_MODULE,
  6412. .pm = &snd_soc_pm_ops,
  6413. .of_match_table = sdm845_asoc_machine_of_match,
  6414. },
  6415. .probe = msm_asoc_machine_probe,
  6416. .remove = msm_asoc_machine_remove,
  6417. };
  6418. module_platform_driver(sdm845_asoc_machine_driver);
  6419. MODULE_DESCRIPTION("ALSA SoC msm");
  6420. MODULE_LICENSE("GPL v2");
  6421. MODULE_ALIAS("platform:" DRV_NAME);
  6422. MODULE_DEVICE_TABLE(of, sdm845_asoc_machine_of_match);