msm8998.c 205 KB

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