sdm845.c 192 KB

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