bengal.c 183 KB

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