sdm845.c 194 KB

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