sdm845.c 194 KB

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