sdm845.c 194 KB

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