sdm845.c 194 KB

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