sdm845.c 197 KB

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