sdm845.c 195 KB

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