sdm845.c 196 KB

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