sdm845.c 195 KB

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