sdm845.c 197 KB

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