sdm845.c 197 KB

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