msm8998.c 206 KB

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