sdm845.c 196 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112
  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_16",
  387. "KHZ_32", "KHZ_44P1", "KHZ_48",
  388. "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_16KHZ:
  1941. sample_rate_val = 1;
  1942. break;
  1943. case SAMPLING_RATE_32KHZ:
  1944. sample_rate_val = 2;
  1945. break;
  1946. case SAMPLING_RATE_44P1KHZ:
  1947. sample_rate_val = 3;
  1948. break;
  1949. case SAMPLING_RATE_48KHZ:
  1950. sample_rate_val = 4;
  1951. break;
  1952. case SAMPLING_RATE_96KHZ:
  1953. sample_rate_val = 5;
  1954. break;
  1955. case SAMPLING_RATE_192KHZ:
  1956. sample_rate_val = 6;
  1957. break;
  1958. default:
  1959. sample_rate_val = 4;
  1960. break;
  1961. }
  1962. return sample_rate_val;
  1963. }
  1964. static int mi2s_get_sample_rate(int value)
  1965. {
  1966. int sample_rate;
  1967. switch (value) {
  1968. case 0:
  1969. sample_rate = SAMPLING_RATE_8KHZ;
  1970. break;
  1971. case 1:
  1972. sample_rate = SAMPLING_RATE_16KHZ;
  1973. break;
  1974. case 2:
  1975. sample_rate = SAMPLING_RATE_32KHZ;
  1976. break;
  1977. case 3:
  1978. sample_rate = SAMPLING_RATE_44P1KHZ;
  1979. break;
  1980. case 4:
  1981. sample_rate = SAMPLING_RATE_48KHZ;
  1982. break;
  1983. case 5:
  1984. sample_rate = SAMPLING_RATE_96KHZ;
  1985. break;
  1986. case 6:
  1987. sample_rate = SAMPLING_RATE_192KHZ;
  1988. break;
  1989. default:
  1990. sample_rate = SAMPLING_RATE_48KHZ;
  1991. break;
  1992. }
  1993. return sample_rate;
  1994. }
  1995. static int mi2s_auxpcm_get_format(int value)
  1996. {
  1997. int format;
  1998. switch (value) {
  1999. case 0:
  2000. format = SNDRV_PCM_FORMAT_S16_LE;
  2001. break;
  2002. case 1:
  2003. format = SNDRV_PCM_FORMAT_S24_LE;
  2004. break;
  2005. case 2:
  2006. format = SNDRV_PCM_FORMAT_S24_3LE;
  2007. break;
  2008. case 3:
  2009. format = SNDRV_PCM_FORMAT_S32_LE;
  2010. break;
  2011. default:
  2012. format = SNDRV_PCM_FORMAT_S16_LE;
  2013. break;
  2014. }
  2015. return format;
  2016. }
  2017. static int mi2s_auxpcm_get_format_value(int format)
  2018. {
  2019. int value;
  2020. switch (format) {
  2021. case SNDRV_PCM_FORMAT_S16_LE:
  2022. value = 0;
  2023. break;
  2024. case SNDRV_PCM_FORMAT_S24_LE:
  2025. value = 1;
  2026. break;
  2027. case SNDRV_PCM_FORMAT_S24_3LE:
  2028. value = 2;
  2029. break;
  2030. case SNDRV_PCM_FORMAT_S32_LE:
  2031. value = 3;
  2032. break;
  2033. default:
  2034. value = 0;
  2035. break;
  2036. }
  2037. return value;
  2038. }
  2039. static int mi2s_rx_sample_rate_put(struct snd_kcontrol *kcontrol,
  2040. struct snd_ctl_elem_value *ucontrol)
  2041. {
  2042. int idx = mi2s_get_port_idx(kcontrol);
  2043. if (idx < 0)
  2044. return idx;
  2045. mi2s_rx_cfg[idx].sample_rate =
  2046. mi2s_get_sample_rate(ucontrol->value.enumerated.item[0]);
  2047. pr_debug("%s: idx[%d]_rx_sample_rate = %d, item = %d\n", __func__,
  2048. idx, mi2s_rx_cfg[idx].sample_rate,
  2049. ucontrol->value.enumerated.item[0]);
  2050. return 0;
  2051. }
  2052. static int mi2s_rx_sample_rate_get(struct snd_kcontrol *kcontrol,
  2053. struct snd_ctl_elem_value *ucontrol)
  2054. {
  2055. int idx = mi2s_get_port_idx(kcontrol);
  2056. if (idx < 0)
  2057. return idx;
  2058. ucontrol->value.enumerated.item[0] =
  2059. mi2s_get_sample_rate_val(mi2s_rx_cfg[idx].sample_rate);
  2060. pr_debug("%s: idx[%d]_rx_sample_rate = %d, item = %d\n", __func__,
  2061. idx, mi2s_rx_cfg[idx].sample_rate,
  2062. ucontrol->value.enumerated.item[0]);
  2063. return 0;
  2064. }
  2065. static int mi2s_tx_sample_rate_put(struct snd_kcontrol *kcontrol,
  2066. struct snd_ctl_elem_value *ucontrol)
  2067. {
  2068. int idx = mi2s_get_port_idx(kcontrol);
  2069. if (idx < 0)
  2070. return idx;
  2071. mi2s_tx_cfg[idx].sample_rate =
  2072. mi2s_get_sample_rate(ucontrol->value.enumerated.item[0]);
  2073. pr_debug("%s: idx[%d]_tx_sample_rate = %d, item = %d\n", __func__,
  2074. idx, mi2s_tx_cfg[idx].sample_rate,
  2075. ucontrol->value.enumerated.item[0]);
  2076. return 0;
  2077. }
  2078. static int mi2s_tx_sample_rate_get(struct snd_kcontrol *kcontrol,
  2079. struct snd_ctl_elem_value *ucontrol)
  2080. {
  2081. int idx = mi2s_get_port_idx(kcontrol);
  2082. if (idx < 0)
  2083. return idx;
  2084. ucontrol->value.enumerated.item[0] =
  2085. mi2s_get_sample_rate_val(mi2s_tx_cfg[idx].sample_rate);
  2086. pr_debug("%s: idx[%d]_tx_sample_rate = %d, item = %d\n", __func__,
  2087. idx, mi2s_tx_cfg[idx].sample_rate,
  2088. ucontrol->value.enumerated.item[0]);
  2089. return 0;
  2090. }
  2091. static int msm_mi2s_rx_ch_get(struct snd_kcontrol *kcontrol,
  2092. struct snd_ctl_elem_value *ucontrol)
  2093. {
  2094. int idx = mi2s_get_port_idx(kcontrol);
  2095. if (idx < 0)
  2096. return idx;
  2097. pr_debug("%s: msm_mi2s_[%d]_rx_ch = %d\n", __func__,
  2098. idx, mi2s_rx_cfg[idx].channels);
  2099. ucontrol->value.enumerated.item[0] = mi2s_rx_cfg[idx].channels - 1;
  2100. return 0;
  2101. }
  2102. static int msm_mi2s_rx_ch_put(struct snd_kcontrol *kcontrol,
  2103. struct snd_ctl_elem_value *ucontrol)
  2104. {
  2105. int idx = mi2s_get_port_idx(kcontrol);
  2106. if (idx < 0)
  2107. return idx;
  2108. mi2s_rx_cfg[idx].channels = ucontrol->value.enumerated.item[0] + 1;
  2109. pr_debug("%s: msm_mi2s_[%d]_rx_ch = %d\n", __func__,
  2110. idx, mi2s_rx_cfg[idx].channels);
  2111. return 1;
  2112. }
  2113. static int msm_mi2s_tx_ch_get(struct snd_kcontrol *kcontrol,
  2114. struct snd_ctl_elem_value *ucontrol)
  2115. {
  2116. int idx = mi2s_get_port_idx(kcontrol);
  2117. if (idx < 0)
  2118. return idx;
  2119. pr_debug("%s: msm_mi2s_[%d]_tx_ch = %d\n", __func__,
  2120. idx, mi2s_tx_cfg[idx].channels);
  2121. ucontrol->value.enumerated.item[0] = mi2s_tx_cfg[idx].channels - 1;
  2122. return 0;
  2123. }
  2124. static int msm_mi2s_tx_ch_put(struct snd_kcontrol *kcontrol,
  2125. struct snd_ctl_elem_value *ucontrol)
  2126. {
  2127. int idx = mi2s_get_port_idx(kcontrol);
  2128. if (idx < 0)
  2129. return idx;
  2130. mi2s_tx_cfg[idx].channels = ucontrol->value.enumerated.item[0] + 1;
  2131. pr_debug("%s: msm_mi2s_[%d]_tx_ch = %d\n", __func__,
  2132. idx, mi2s_tx_cfg[idx].channels);
  2133. return 1;
  2134. }
  2135. static int msm_mi2s_rx_format_get(struct snd_kcontrol *kcontrol,
  2136. struct snd_ctl_elem_value *ucontrol)
  2137. {
  2138. int idx = mi2s_get_port_idx(kcontrol);
  2139. if (idx < 0)
  2140. return idx;
  2141. ucontrol->value.enumerated.item[0] =
  2142. mi2s_auxpcm_get_format_value(mi2s_rx_cfg[idx].bit_format);
  2143. pr_debug("%s: idx[%d]_rx_format = %d, item = %d\n", __func__,
  2144. idx, mi2s_rx_cfg[idx].bit_format,
  2145. ucontrol->value.enumerated.item[0]);
  2146. return 0;
  2147. }
  2148. static int msm_mi2s_rx_format_put(struct snd_kcontrol *kcontrol,
  2149. struct snd_ctl_elem_value *ucontrol)
  2150. {
  2151. int idx = mi2s_get_port_idx(kcontrol);
  2152. if (idx < 0)
  2153. return idx;
  2154. mi2s_rx_cfg[idx].bit_format =
  2155. mi2s_auxpcm_get_format(ucontrol->value.enumerated.item[0]);
  2156. pr_debug("%s: idx[%d]_rx_format = %d, item = %d\n", __func__,
  2157. idx, mi2s_rx_cfg[idx].bit_format,
  2158. ucontrol->value.enumerated.item[0]);
  2159. return 0;
  2160. }
  2161. static int msm_mi2s_tx_format_get(struct snd_kcontrol *kcontrol,
  2162. struct snd_ctl_elem_value *ucontrol)
  2163. {
  2164. int idx = mi2s_get_port_idx(kcontrol);
  2165. if (idx < 0)
  2166. return idx;
  2167. ucontrol->value.enumerated.item[0] =
  2168. mi2s_auxpcm_get_format_value(mi2s_tx_cfg[idx].bit_format);
  2169. pr_debug("%s: idx[%d]_tx_format = %d, item = %d\n", __func__,
  2170. idx, mi2s_tx_cfg[idx].bit_format,
  2171. ucontrol->value.enumerated.item[0]);
  2172. return 0;
  2173. }
  2174. static int msm_mi2s_tx_format_put(struct snd_kcontrol *kcontrol,
  2175. struct snd_ctl_elem_value *ucontrol)
  2176. {
  2177. int idx = mi2s_get_port_idx(kcontrol);
  2178. if (idx < 0)
  2179. return idx;
  2180. mi2s_tx_cfg[idx].bit_format =
  2181. mi2s_auxpcm_get_format(ucontrol->value.enumerated.item[0]);
  2182. pr_debug("%s: idx[%d]_tx_format = %d, item = %d\n", __func__,
  2183. idx, mi2s_tx_cfg[idx].bit_format,
  2184. ucontrol->value.enumerated.item[0]);
  2185. return 0;
  2186. }
  2187. static int msm_aux_pcm_rx_format_get(struct snd_kcontrol *kcontrol,
  2188. struct snd_ctl_elem_value *ucontrol)
  2189. {
  2190. int idx = aux_pcm_get_port_idx(kcontrol);
  2191. if (idx < 0)
  2192. return idx;
  2193. ucontrol->value.enumerated.item[0] =
  2194. mi2s_auxpcm_get_format_value(aux_pcm_rx_cfg[idx].bit_format);
  2195. pr_debug("%s: idx[%d]_rx_format = %d, item = %d\n", __func__,
  2196. idx, aux_pcm_rx_cfg[idx].bit_format,
  2197. ucontrol->value.enumerated.item[0]);
  2198. return 0;
  2199. }
  2200. static int msm_aux_pcm_rx_format_put(struct snd_kcontrol *kcontrol,
  2201. struct snd_ctl_elem_value *ucontrol)
  2202. {
  2203. int idx = aux_pcm_get_port_idx(kcontrol);
  2204. if (idx < 0)
  2205. return idx;
  2206. aux_pcm_rx_cfg[idx].bit_format =
  2207. mi2s_auxpcm_get_format(ucontrol->value.enumerated.item[0]);
  2208. pr_debug("%s: idx[%d]_rx_format = %d, item = %d\n", __func__,
  2209. idx, aux_pcm_rx_cfg[idx].bit_format,
  2210. ucontrol->value.enumerated.item[0]);
  2211. return 0;
  2212. }
  2213. static int msm_aux_pcm_tx_format_get(struct snd_kcontrol *kcontrol,
  2214. struct snd_ctl_elem_value *ucontrol)
  2215. {
  2216. int idx = aux_pcm_get_port_idx(kcontrol);
  2217. if (idx < 0)
  2218. return idx;
  2219. ucontrol->value.enumerated.item[0] =
  2220. mi2s_auxpcm_get_format_value(aux_pcm_tx_cfg[idx].bit_format);
  2221. pr_debug("%s: idx[%d]_tx_format = %d, item = %d\n", __func__,
  2222. idx, aux_pcm_tx_cfg[idx].bit_format,
  2223. ucontrol->value.enumerated.item[0]);
  2224. return 0;
  2225. }
  2226. static int msm_aux_pcm_tx_format_put(struct snd_kcontrol *kcontrol,
  2227. struct snd_ctl_elem_value *ucontrol)
  2228. {
  2229. int idx = aux_pcm_get_port_idx(kcontrol);
  2230. if (idx < 0)
  2231. return idx;
  2232. aux_pcm_tx_cfg[idx].bit_format =
  2233. mi2s_auxpcm_get_format(ucontrol->value.enumerated.item[0]);
  2234. pr_debug("%s: idx[%d]_tx_format = %d, item = %d\n", __func__,
  2235. idx, aux_pcm_tx_cfg[idx].bit_format,
  2236. ucontrol->value.enumerated.item[0]);
  2237. return 0;
  2238. }
  2239. static int msm_hifi_ctrl(struct snd_soc_codec *codec)
  2240. {
  2241. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  2242. struct snd_soc_card *card = codec->component.card;
  2243. struct msm_asoc_mach_data *pdata =
  2244. snd_soc_card_get_drvdata(card);
  2245. pr_debug("%s: msm_hifi_control = %d", __func__,
  2246. msm_hifi_control);
  2247. if (!pdata || !pdata->hph_en1_gpio_p) {
  2248. pr_err("%s: hph_en1_gpio is invalid\n", __func__);
  2249. return -EINVAL;
  2250. }
  2251. if (msm_hifi_control == MSM_HIFI_ON) {
  2252. msm_cdc_pinctrl_select_active_state(pdata->hph_en1_gpio_p);
  2253. /* 5msec delay needed as per HW requirement */
  2254. usleep_range(5000, 5010);
  2255. } else {
  2256. msm_cdc_pinctrl_select_sleep_state(pdata->hph_en1_gpio_p);
  2257. }
  2258. snd_soc_dapm_sync(dapm);
  2259. return 0;
  2260. }
  2261. static int msm_hifi_get(struct snd_kcontrol *kcontrol,
  2262. struct snd_ctl_elem_value *ucontrol)
  2263. {
  2264. pr_debug("%s: msm_hifi_control = %d\n",
  2265. __func__, msm_hifi_control);
  2266. ucontrol->value.integer.value[0] = msm_hifi_control;
  2267. return 0;
  2268. }
  2269. static int msm_hifi_put(struct snd_kcontrol *kcontrol,
  2270. struct snd_ctl_elem_value *ucontrol)
  2271. {
  2272. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  2273. pr_debug("%s() ucontrol->value.integer.value[0] = %ld\n",
  2274. __func__, ucontrol->value.integer.value[0]);
  2275. msm_hifi_control = ucontrol->value.integer.value[0];
  2276. msm_hifi_ctrl(codec);
  2277. return 0;
  2278. }
  2279. static int msm_qos_ctl_get(struct snd_kcontrol *kcontrol,
  2280. struct snd_ctl_elem_value *ucontrol)
  2281. {
  2282. ucontrol->value.enumerated.item[0] = qos_vote_status;
  2283. return 0;
  2284. }
  2285. static int msm_qos_ctl_put(struct snd_kcontrol *kcontrol,
  2286. struct snd_ctl_elem_value *ucontrol)
  2287. {
  2288. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  2289. struct snd_soc_card *card = codec->component.card;
  2290. const char *be_name = MSM_DAILINK_NAME(LowLatency);
  2291. struct snd_soc_pcm_runtime *rtd;
  2292. struct snd_pcm_substream *substream;
  2293. s32 usecs;
  2294. rtd = snd_soc_get_pcm_runtime(card, be_name);
  2295. if (!rtd) {
  2296. pr_err("%s: fail to get pcm runtime for %s\n",
  2297. __func__, be_name);
  2298. return -EINVAL;
  2299. }
  2300. substream = rtd->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
  2301. if (!substream) {
  2302. pr_err("%s: substream is null\n", __func__);
  2303. return -EINVAL;
  2304. }
  2305. qos_vote_status = ucontrol->value.enumerated.item[0];
  2306. if (qos_vote_status) {
  2307. if (pm_qos_request_active(&substream->latency_pm_qos_req))
  2308. pm_qos_remove_request(&substream->latency_pm_qos_req);
  2309. if (!substream->runtime) {
  2310. pr_err("%s: runtime is null\n", __func__);
  2311. return -EINVAL;
  2312. }
  2313. usecs = MSM_LL_QOS_VALUE;
  2314. if (usecs >= 0)
  2315. pm_qos_add_request(&substream->latency_pm_qos_req,
  2316. PM_QOS_CPU_DMA_LATENCY, usecs);
  2317. } else {
  2318. if (pm_qos_request_active(&substream->latency_pm_qos_req))
  2319. pm_qos_remove_request(&substream->latency_pm_qos_req);
  2320. }
  2321. return 0;
  2322. }
  2323. static const struct snd_kcontrol_new msm_snd_controls[] = {
  2324. SOC_ENUM_EXT("SLIM_0_RX Channels", slim_0_rx_chs,
  2325. msm_slim_rx_ch_get, msm_slim_rx_ch_put),
  2326. SOC_ENUM_EXT("SLIM_2_RX Channels", slim_2_rx_chs,
  2327. msm_slim_rx_ch_get, msm_slim_rx_ch_put),
  2328. SOC_ENUM_EXT("SLIM_0_TX Channels", slim_0_tx_chs,
  2329. msm_slim_tx_ch_get, msm_slim_tx_ch_put),
  2330. SOC_ENUM_EXT("SLIM_1_TX Channels", slim_1_tx_chs,
  2331. msm_slim_tx_ch_get, msm_slim_tx_ch_put),
  2332. SOC_ENUM_EXT("SLIM_5_RX Channels", slim_5_rx_chs,
  2333. msm_slim_rx_ch_get, msm_slim_rx_ch_put),
  2334. SOC_ENUM_EXT("SLIM_6_RX Channels", slim_6_rx_chs,
  2335. msm_slim_rx_ch_get, msm_slim_rx_ch_put),
  2336. SOC_ENUM_EXT("VI_FEED_TX Channels", vi_feed_tx_chs,
  2337. msm_vi_feed_tx_ch_get, msm_vi_feed_tx_ch_put),
  2338. SOC_ENUM_EXT("USB_AUDIO_RX Channels", usb_rx_chs,
  2339. usb_audio_rx_ch_get, usb_audio_rx_ch_put),
  2340. SOC_ENUM_EXT("USB_AUDIO_TX Channels", usb_tx_chs,
  2341. usb_audio_tx_ch_get, usb_audio_tx_ch_put),
  2342. SOC_ENUM_EXT("Display Port RX Channels", ext_disp_rx_chs,
  2343. ext_disp_rx_ch_get, ext_disp_rx_ch_put),
  2344. SOC_ENUM_EXT("PROXY_RX Channels", proxy_rx_chs,
  2345. proxy_rx_ch_get, proxy_rx_ch_put),
  2346. SOC_ENUM_EXT("SLIM_0_RX Format", slim_0_rx_format,
  2347. slim_rx_bit_format_get, slim_rx_bit_format_put),
  2348. SOC_ENUM_EXT("SLIM_5_RX Format", slim_5_rx_format,
  2349. slim_rx_bit_format_get, slim_rx_bit_format_put),
  2350. SOC_ENUM_EXT("SLIM_6_RX Format", slim_6_rx_format,
  2351. slim_rx_bit_format_get, slim_rx_bit_format_put),
  2352. SOC_ENUM_EXT("SLIM_0_TX Format", slim_0_tx_format,
  2353. slim_tx_bit_format_get, slim_tx_bit_format_put),
  2354. SOC_ENUM_EXT("USB_AUDIO_RX Format", usb_rx_format,
  2355. usb_audio_rx_format_get, usb_audio_rx_format_put),
  2356. SOC_ENUM_EXT("USB_AUDIO_TX Format", usb_tx_format,
  2357. usb_audio_tx_format_get, usb_audio_tx_format_put),
  2358. SOC_ENUM_EXT("Display Port RX Bit Format", ext_disp_rx_format,
  2359. ext_disp_rx_format_get, ext_disp_rx_format_put),
  2360. SOC_ENUM_EXT("SLIM_0_RX SampleRate", slim_0_rx_sample_rate,
  2361. slim_rx_sample_rate_get, slim_rx_sample_rate_put),
  2362. SOC_ENUM_EXT("SLIM_2_RX SampleRate", slim_2_rx_sample_rate,
  2363. slim_rx_sample_rate_get, slim_rx_sample_rate_put),
  2364. SOC_ENUM_EXT("SLIM_0_TX SampleRate", slim_0_tx_sample_rate,
  2365. slim_tx_sample_rate_get, slim_tx_sample_rate_put),
  2366. SOC_ENUM_EXT("SLIM_5_RX SampleRate", slim_5_rx_sample_rate,
  2367. slim_rx_sample_rate_get, slim_rx_sample_rate_put),
  2368. SOC_ENUM_EXT("SLIM_6_RX SampleRate", slim_6_rx_sample_rate,
  2369. slim_rx_sample_rate_get, slim_rx_sample_rate_put),
  2370. SOC_ENUM_EXT("BT SampleRate", bt_sample_rate,
  2371. msm_bt_sample_rate_get,
  2372. msm_bt_sample_rate_put),
  2373. SOC_ENUM_EXT("USB_AUDIO_RX SampleRate", usb_rx_sample_rate,
  2374. usb_audio_rx_sample_rate_get,
  2375. usb_audio_rx_sample_rate_put),
  2376. SOC_ENUM_EXT("USB_AUDIO_TX SampleRate", usb_tx_sample_rate,
  2377. usb_audio_tx_sample_rate_get,
  2378. usb_audio_tx_sample_rate_put),
  2379. SOC_ENUM_EXT("Display Port RX SampleRate", ext_disp_rx_sample_rate,
  2380. ext_disp_rx_sample_rate_get,
  2381. ext_disp_rx_sample_rate_put),
  2382. SOC_ENUM_EXT("PRI_TDM_RX_0 SampleRate", tdm_rx_sample_rate,
  2383. tdm_rx_sample_rate_get,
  2384. tdm_rx_sample_rate_put),
  2385. SOC_ENUM_EXT("PRI_TDM_TX_0 SampleRate", tdm_tx_sample_rate,
  2386. tdm_tx_sample_rate_get,
  2387. tdm_tx_sample_rate_put),
  2388. SOC_ENUM_EXT("PRI_TDM_RX_0 Format", tdm_rx_format,
  2389. tdm_rx_format_get,
  2390. tdm_rx_format_put),
  2391. SOC_ENUM_EXT("PRI_TDM_TX_0 Format", tdm_tx_format,
  2392. tdm_tx_format_get,
  2393. tdm_tx_format_put),
  2394. SOC_ENUM_EXT("PRI_TDM_RX_0 Channels", tdm_rx_chs,
  2395. tdm_rx_ch_get,
  2396. tdm_rx_ch_put),
  2397. SOC_ENUM_EXT("PRI_TDM_TX_0 Channels", tdm_tx_chs,
  2398. tdm_tx_ch_get,
  2399. tdm_tx_ch_put),
  2400. SOC_ENUM_EXT("SEC_TDM_RX_0 SampleRate", tdm_rx_sample_rate,
  2401. tdm_rx_sample_rate_get,
  2402. tdm_rx_sample_rate_put),
  2403. SOC_ENUM_EXT("SEC_TDM_TX_0 SampleRate", tdm_tx_sample_rate,
  2404. tdm_tx_sample_rate_get,
  2405. tdm_tx_sample_rate_put),
  2406. SOC_ENUM_EXT("SEC_TDM_RX_0 Format", tdm_rx_format,
  2407. tdm_rx_format_get,
  2408. tdm_rx_format_put),
  2409. SOC_ENUM_EXT("SEC_TDM_TX_0 Format", tdm_tx_format,
  2410. tdm_tx_format_get,
  2411. tdm_tx_format_put),
  2412. SOC_ENUM_EXT("SEC_TDM_RX_0 Channels", tdm_rx_chs,
  2413. tdm_rx_ch_get,
  2414. tdm_rx_ch_put),
  2415. SOC_ENUM_EXT("SEC_TDM_TX_0 Channels", tdm_tx_chs,
  2416. tdm_tx_ch_get,
  2417. tdm_tx_ch_put),
  2418. SOC_ENUM_EXT("TERT_TDM_RX_0 SampleRate", tdm_rx_sample_rate,
  2419. tdm_rx_sample_rate_get,
  2420. tdm_rx_sample_rate_put),
  2421. SOC_ENUM_EXT("TERT_TDM_TX_0 SampleRate", tdm_tx_sample_rate,
  2422. tdm_tx_sample_rate_get,
  2423. tdm_tx_sample_rate_put),
  2424. SOC_ENUM_EXT("TERT_TDM_RX_0 Format", tdm_rx_format,
  2425. tdm_rx_format_get,
  2426. tdm_rx_format_put),
  2427. SOC_ENUM_EXT("TERT_TDM_TX_0 Format", tdm_tx_format,
  2428. tdm_tx_format_get,
  2429. tdm_tx_format_put),
  2430. SOC_ENUM_EXT("TERT_TDM_RX_0 Channels", tdm_rx_chs,
  2431. tdm_rx_ch_get,
  2432. tdm_rx_ch_put),
  2433. SOC_ENUM_EXT("TERT_TDM_TX_0 Channels", tdm_tx_chs,
  2434. tdm_tx_ch_get,
  2435. tdm_tx_ch_put),
  2436. SOC_ENUM_EXT("QUAT_TDM_RX_0 SampleRate", tdm_rx_sample_rate,
  2437. tdm_rx_sample_rate_get,
  2438. tdm_rx_sample_rate_put),
  2439. SOC_ENUM_EXT("QUAT_TDM_TX_0 SampleRate", tdm_tx_sample_rate,
  2440. tdm_tx_sample_rate_get,
  2441. tdm_tx_sample_rate_put),
  2442. SOC_ENUM_EXT("QUAT_TDM_RX_0 Format", tdm_rx_format,
  2443. tdm_rx_format_get,
  2444. tdm_rx_format_put),
  2445. SOC_ENUM_EXT("QUAT_TDM_TX_0 Format", tdm_tx_format,
  2446. tdm_tx_format_get,
  2447. tdm_tx_format_put),
  2448. SOC_ENUM_EXT("QUAT_TDM_RX_0 Channels", tdm_rx_chs,
  2449. tdm_rx_ch_get,
  2450. tdm_rx_ch_put),
  2451. SOC_ENUM_EXT("QUAT_TDM_TX_0 Channels", tdm_tx_chs,
  2452. tdm_tx_ch_get,
  2453. tdm_tx_ch_put),
  2454. SOC_ENUM_EXT("PRIM_AUX_PCM_RX SampleRate", prim_aux_pcm_rx_sample_rate,
  2455. aux_pcm_rx_sample_rate_get,
  2456. aux_pcm_rx_sample_rate_put),
  2457. SOC_ENUM_EXT("SEC_AUX_PCM_RX SampleRate", sec_aux_pcm_rx_sample_rate,
  2458. aux_pcm_rx_sample_rate_get,
  2459. aux_pcm_rx_sample_rate_put),
  2460. SOC_ENUM_EXT("TERT_AUX_PCM_RX SampleRate", tert_aux_pcm_rx_sample_rate,
  2461. aux_pcm_rx_sample_rate_get,
  2462. aux_pcm_rx_sample_rate_put),
  2463. SOC_ENUM_EXT("QUAT_AUX_PCM_RX SampleRate", quat_aux_pcm_rx_sample_rate,
  2464. aux_pcm_rx_sample_rate_get,
  2465. aux_pcm_rx_sample_rate_put),
  2466. SOC_ENUM_EXT("PRIM_AUX_PCM_TX SampleRate", prim_aux_pcm_tx_sample_rate,
  2467. aux_pcm_tx_sample_rate_get,
  2468. aux_pcm_tx_sample_rate_put),
  2469. SOC_ENUM_EXT("SEC_AUX_PCM_TX SampleRate", sec_aux_pcm_tx_sample_rate,
  2470. aux_pcm_tx_sample_rate_get,
  2471. aux_pcm_tx_sample_rate_put),
  2472. SOC_ENUM_EXT("TERT_AUX_PCM_TX SampleRate", tert_aux_pcm_tx_sample_rate,
  2473. aux_pcm_tx_sample_rate_get,
  2474. aux_pcm_tx_sample_rate_put),
  2475. SOC_ENUM_EXT("QUAT_AUX_PCM_TX SampleRate", quat_aux_pcm_tx_sample_rate,
  2476. aux_pcm_tx_sample_rate_get,
  2477. aux_pcm_tx_sample_rate_put),
  2478. SOC_ENUM_EXT("PRIM_MI2S_RX SampleRate", prim_mi2s_rx_sample_rate,
  2479. mi2s_rx_sample_rate_get,
  2480. mi2s_rx_sample_rate_put),
  2481. SOC_ENUM_EXT("SEC_MI2S_RX SampleRate", sec_mi2s_rx_sample_rate,
  2482. mi2s_rx_sample_rate_get,
  2483. mi2s_rx_sample_rate_put),
  2484. SOC_ENUM_EXT("TERT_MI2S_RX SampleRate", tert_mi2s_rx_sample_rate,
  2485. mi2s_rx_sample_rate_get,
  2486. mi2s_rx_sample_rate_put),
  2487. SOC_ENUM_EXT("QUAT_MI2S_RX SampleRate", quat_mi2s_rx_sample_rate,
  2488. mi2s_rx_sample_rate_get,
  2489. mi2s_rx_sample_rate_put),
  2490. SOC_ENUM_EXT("PRIM_MI2S_TX SampleRate", prim_mi2s_tx_sample_rate,
  2491. mi2s_tx_sample_rate_get,
  2492. mi2s_tx_sample_rate_put),
  2493. SOC_ENUM_EXT("SEC_MI2S_TX SampleRate", sec_mi2s_tx_sample_rate,
  2494. mi2s_tx_sample_rate_get,
  2495. mi2s_tx_sample_rate_put),
  2496. SOC_ENUM_EXT("TERT_MI2S_TX SampleRate", tert_mi2s_tx_sample_rate,
  2497. mi2s_tx_sample_rate_get,
  2498. mi2s_tx_sample_rate_put),
  2499. SOC_ENUM_EXT("QUAT_MI2S_TX SampleRate", quat_mi2s_tx_sample_rate,
  2500. mi2s_tx_sample_rate_get,
  2501. mi2s_tx_sample_rate_put),
  2502. SOC_ENUM_EXT("PRIM_MI2S_RX Channels", prim_mi2s_rx_chs,
  2503. msm_mi2s_rx_ch_get, msm_mi2s_rx_ch_put),
  2504. SOC_ENUM_EXT("PRIM_MI2S_TX Channels", prim_mi2s_tx_chs,
  2505. msm_mi2s_tx_ch_get, msm_mi2s_tx_ch_put),
  2506. SOC_ENUM_EXT("SEC_MI2S_RX Channels", sec_mi2s_rx_chs,
  2507. msm_mi2s_rx_ch_get, msm_mi2s_rx_ch_put),
  2508. SOC_ENUM_EXT("SEC_MI2S_TX Channels", sec_mi2s_tx_chs,
  2509. msm_mi2s_tx_ch_get, msm_mi2s_tx_ch_put),
  2510. SOC_ENUM_EXT("TERT_MI2S_RX Channels", tert_mi2s_rx_chs,
  2511. msm_mi2s_rx_ch_get, msm_mi2s_rx_ch_put),
  2512. SOC_ENUM_EXT("TERT_MI2S_TX Channels", tert_mi2s_tx_chs,
  2513. msm_mi2s_tx_ch_get, msm_mi2s_tx_ch_put),
  2514. SOC_ENUM_EXT("QUAT_MI2S_RX Channels", quat_mi2s_rx_chs,
  2515. msm_mi2s_rx_ch_get, msm_mi2s_rx_ch_put),
  2516. SOC_ENUM_EXT("QUAT_MI2S_TX Channels", quat_mi2s_tx_chs,
  2517. msm_mi2s_tx_ch_get, msm_mi2s_tx_ch_put),
  2518. SOC_ENUM_EXT("PRIM_MI2S_RX Format", mi2s_rx_format,
  2519. msm_mi2s_rx_format_get, msm_mi2s_rx_format_put),
  2520. SOC_ENUM_EXT("PRIM_MI2S_TX Format", mi2s_tx_format,
  2521. msm_mi2s_tx_format_get, msm_mi2s_tx_format_put),
  2522. SOC_ENUM_EXT("SEC_MI2S_RX Format", mi2s_rx_format,
  2523. msm_mi2s_rx_format_get, msm_mi2s_rx_format_put),
  2524. SOC_ENUM_EXT("SEC_MI2S_TX Format", mi2s_tx_format,
  2525. msm_mi2s_tx_format_get, msm_mi2s_tx_format_put),
  2526. SOC_ENUM_EXT("TERT_MI2S_RX Format", mi2s_rx_format,
  2527. msm_mi2s_rx_format_get, msm_mi2s_rx_format_put),
  2528. SOC_ENUM_EXT("TERT_MI2S_TX Format", mi2s_tx_format,
  2529. msm_mi2s_tx_format_get, msm_mi2s_tx_format_put),
  2530. SOC_ENUM_EXT("QUAT_MI2S_RX Format", mi2s_rx_format,
  2531. msm_mi2s_rx_format_get, msm_mi2s_rx_format_put),
  2532. SOC_ENUM_EXT("QUAT_MI2S_TX Format", mi2s_tx_format,
  2533. msm_mi2s_tx_format_get, msm_mi2s_tx_format_put),
  2534. SOC_ENUM_EXT("PRIM_AUX_PCM_RX Format", aux_pcm_rx_format,
  2535. msm_aux_pcm_rx_format_get, msm_aux_pcm_rx_format_put),
  2536. SOC_ENUM_EXT("PRIM_AUX_PCM_TX Format", aux_pcm_tx_format,
  2537. msm_aux_pcm_tx_format_get, msm_aux_pcm_tx_format_put),
  2538. SOC_ENUM_EXT("SEC_AUX_PCM_RX Format", aux_pcm_rx_format,
  2539. msm_aux_pcm_rx_format_get, msm_aux_pcm_rx_format_put),
  2540. SOC_ENUM_EXT("SEC_AUX_PCM_TX Format", aux_pcm_tx_format,
  2541. msm_aux_pcm_tx_format_get, msm_aux_pcm_tx_format_put),
  2542. SOC_ENUM_EXT("TERT_AUX_PCM_RX Format", aux_pcm_rx_format,
  2543. msm_aux_pcm_rx_format_get, msm_aux_pcm_rx_format_put),
  2544. SOC_ENUM_EXT("TERT_AUX_PCM_TX Format", aux_pcm_tx_format,
  2545. msm_aux_pcm_tx_format_get, msm_aux_pcm_tx_format_put),
  2546. SOC_ENUM_EXT("QUAT_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("QUAT_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("HiFi Function", hifi_function, msm_hifi_get,
  2551. msm_hifi_put),
  2552. SOC_ENUM_EXT("MultiMedia5_RX QOS Vote", qos_vote, msm_qos_ctl_get,
  2553. msm_qos_ctl_put),
  2554. };
  2555. static int msm_snd_enable_codec_ext_clk(struct snd_soc_codec *codec,
  2556. int enable, bool dapm)
  2557. {
  2558. int ret = 0;
  2559. if (!strcmp(dev_name(codec->dev), "tavil_codec")) {
  2560. ret = tavil_cdc_mclk_enable(codec, enable);
  2561. } else {
  2562. dev_err(codec->dev, "%s: unknown codec to enable ext clk\n",
  2563. __func__);
  2564. ret = -EINVAL;
  2565. }
  2566. return ret;
  2567. }
  2568. static int msm_snd_enable_codec_ext_tx_clk(struct snd_soc_codec *codec,
  2569. int enable, bool dapm)
  2570. {
  2571. int ret = 0;
  2572. if (!strcmp(dev_name(codec->dev), "tavil_codec")) {
  2573. ret = tavil_cdc_mclk_tx_enable(codec, enable);
  2574. } else {
  2575. dev_err(codec->dev, "%s: unknown codec to enable TX ext clk\n",
  2576. __func__);
  2577. ret = -EINVAL;
  2578. }
  2579. return ret;
  2580. }
  2581. static int msm_mclk_tx_event(struct snd_soc_dapm_widget *w,
  2582. struct snd_kcontrol *kcontrol, int event)
  2583. {
  2584. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2585. pr_debug("%s: event = %d\n", __func__, event);
  2586. switch (event) {
  2587. case SND_SOC_DAPM_PRE_PMU:
  2588. return msm_snd_enable_codec_ext_tx_clk(codec, 1, true);
  2589. case SND_SOC_DAPM_POST_PMD:
  2590. return msm_snd_enable_codec_ext_tx_clk(codec, 0, true);
  2591. }
  2592. return 0;
  2593. }
  2594. static int msm_mclk_event(struct snd_soc_dapm_widget *w,
  2595. struct snd_kcontrol *kcontrol, int event)
  2596. {
  2597. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2598. pr_debug("%s: event = %d\n", __func__, event);
  2599. switch (event) {
  2600. case SND_SOC_DAPM_PRE_PMU:
  2601. return msm_snd_enable_codec_ext_clk(codec, 1, true);
  2602. case SND_SOC_DAPM_POST_PMD:
  2603. return msm_snd_enable_codec_ext_clk(codec, 0, true);
  2604. }
  2605. return 0;
  2606. }
  2607. static int msm_hifi_ctrl_event(struct snd_soc_dapm_widget *w,
  2608. struct snd_kcontrol *k, int event)
  2609. {
  2610. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2611. struct snd_soc_card *card = codec->component.card;
  2612. struct msm_asoc_mach_data *pdata =
  2613. snd_soc_card_get_drvdata(card);
  2614. pr_debug("%s: msm_hifi_control = %d", __func__, msm_hifi_control);
  2615. if (!pdata || !pdata->hph_en0_gpio_p) {
  2616. pr_err("%s: hph_en0_gpio is invalid\n", __func__);
  2617. return -EINVAL;
  2618. }
  2619. if (msm_hifi_control != MSM_HIFI_ON) {
  2620. pr_debug("%s: HiFi mixer control is not set\n",
  2621. __func__);
  2622. return 0;
  2623. }
  2624. switch (event) {
  2625. case SND_SOC_DAPM_POST_PMU:
  2626. msm_cdc_pinctrl_select_active_state(pdata->hph_en0_gpio_p);
  2627. break;
  2628. case SND_SOC_DAPM_PRE_PMD:
  2629. msm_cdc_pinctrl_select_sleep_state(pdata->hph_en0_gpio_p);
  2630. break;
  2631. }
  2632. return 0;
  2633. }
  2634. static const struct snd_soc_dapm_widget msm_dapm_widgets[] = {
  2635. SND_SOC_DAPM_SUPPLY("MCLK", SND_SOC_NOPM, 0, 0,
  2636. msm_mclk_event,
  2637. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2638. SND_SOC_DAPM_SUPPLY("MCLK TX", SND_SOC_NOPM, 0, 0,
  2639. msm_mclk_tx_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2640. SND_SOC_DAPM_SPK("Lineout_1 amp", NULL),
  2641. SND_SOC_DAPM_SPK("Lineout_2 amp", NULL),
  2642. SND_SOC_DAPM_SPK("hifi amp", msm_hifi_ctrl_event),
  2643. SND_SOC_DAPM_MIC("Handset Mic", NULL),
  2644. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  2645. SND_SOC_DAPM_MIC("ANCRight Headset Mic", NULL),
  2646. SND_SOC_DAPM_MIC("ANCLeft Headset Mic", NULL),
  2647. SND_SOC_DAPM_MIC("Analog Mic5", NULL),
  2648. SND_SOC_DAPM_MIC("Digital Mic0", NULL),
  2649. SND_SOC_DAPM_MIC("Digital Mic1", NULL),
  2650. SND_SOC_DAPM_MIC("Digital Mic2", NULL),
  2651. SND_SOC_DAPM_MIC("Digital Mic3", NULL),
  2652. SND_SOC_DAPM_MIC("Digital Mic4", NULL),
  2653. SND_SOC_DAPM_MIC("Digital Mic5", NULL),
  2654. };
  2655. static inline int param_is_mask(int p)
  2656. {
  2657. return (p >= SNDRV_PCM_HW_PARAM_FIRST_MASK) &&
  2658. (p <= SNDRV_PCM_HW_PARAM_LAST_MASK);
  2659. }
  2660. static inline struct snd_mask *param_to_mask(struct snd_pcm_hw_params *p,
  2661. int n)
  2662. {
  2663. return &(p->masks[n - SNDRV_PCM_HW_PARAM_FIRST_MASK]);
  2664. }
  2665. static void param_set_mask(struct snd_pcm_hw_params *p, int n,
  2666. unsigned int bit)
  2667. {
  2668. if (bit >= SNDRV_MASK_MAX)
  2669. return;
  2670. if (param_is_mask(n)) {
  2671. struct snd_mask *m = param_to_mask(p, n);
  2672. m->bits[0] = 0;
  2673. m->bits[1] = 0;
  2674. m->bits[bit >> 5] |= (1 << (bit & 31));
  2675. }
  2676. }
  2677. static int msm_slim_get_ch_from_beid(int32_t be_id)
  2678. {
  2679. int ch_id = 0;
  2680. switch (be_id) {
  2681. case MSM_BACKEND_DAI_SLIMBUS_0_RX:
  2682. ch_id = SLIM_RX_0;
  2683. break;
  2684. case MSM_BACKEND_DAI_SLIMBUS_1_RX:
  2685. ch_id = SLIM_RX_1;
  2686. break;
  2687. case MSM_BACKEND_DAI_SLIMBUS_2_RX:
  2688. ch_id = SLIM_RX_2;
  2689. break;
  2690. case MSM_BACKEND_DAI_SLIMBUS_3_RX:
  2691. ch_id = SLIM_RX_3;
  2692. break;
  2693. case MSM_BACKEND_DAI_SLIMBUS_4_RX:
  2694. ch_id = SLIM_RX_4;
  2695. break;
  2696. case MSM_BACKEND_DAI_SLIMBUS_6_RX:
  2697. ch_id = SLIM_RX_6;
  2698. break;
  2699. case MSM_BACKEND_DAI_SLIMBUS_0_TX:
  2700. ch_id = SLIM_TX_0;
  2701. break;
  2702. case MSM_BACKEND_DAI_SLIMBUS_3_TX:
  2703. ch_id = SLIM_TX_3;
  2704. break;
  2705. default:
  2706. ch_id = SLIM_RX_0;
  2707. break;
  2708. }
  2709. return ch_id;
  2710. }
  2711. static int msm_ext_disp_get_idx_from_beid(int32_t be_id)
  2712. {
  2713. int idx;
  2714. switch (be_id) {
  2715. case MSM_BACKEND_DAI_DISPLAY_PORT_RX:
  2716. idx = DP_RX_IDX;
  2717. break;
  2718. default:
  2719. pr_err("%s: Incorrect ext_disp BE id %d\n", __func__, be_id);
  2720. idx = -EINVAL;
  2721. break;
  2722. }
  2723. return idx;
  2724. }
  2725. static int msm_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
  2726. struct snd_pcm_hw_params *params)
  2727. {
  2728. struct snd_soc_dai_link *dai_link = rtd->dai_link;
  2729. struct snd_interval *rate = hw_param_interval(params,
  2730. SNDRV_PCM_HW_PARAM_RATE);
  2731. struct snd_interval *channels = hw_param_interval(params,
  2732. SNDRV_PCM_HW_PARAM_CHANNELS);
  2733. int rc = 0;
  2734. int idx;
  2735. void *config = NULL;
  2736. struct snd_soc_codec *codec = NULL;
  2737. pr_debug("%s: format = %d, rate = %d\n",
  2738. __func__, params_format(params), params_rate(params));
  2739. switch (dai_link->id) {
  2740. case MSM_BACKEND_DAI_SLIMBUS_0_RX:
  2741. case MSM_BACKEND_DAI_SLIMBUS_1_RX:
  2742. case MSM_BACKEND_DAI_SLIMBUS_2_RX:
  2743. case MSM_BACKEND_DAI_SLIMBUS_3_RX:
  2744. case MSM_BACKEND_DAI_SLIMBUS_4_RX:
  2745. case MSM_BACKEND_DAI_SLIMBUS_6_RX:
  2746. idx = msm_slim_get_ch_from_beid(dai_link->id);
  2747. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2748. slim_rx_cfg[idx].bit_format);
  2749. rate->min = rate->max = slim_rx_cfg[idx].sample_rate;
  2750. channels->min = channels->max = slim_rx_cfg[idx].channels;
  2751. break;
  2752. case MSM_BACKEND_DAI_SLIMBUS_0_TX:
  2753. case MSM_BACKEND_DAI_SLIMBUS_3_TX:
  2754. idx = msm_slim_get_ch_from_beid(dai_link->id);
  2755. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2756. slim_tx_cfg[idx].bit_format);
  2757. rate->min = rate->max = slim_tx_cfg[idx].sample_rate;
  2758. channels->min = channels->max = slim_tx_cfg[idx].channels;
  2759. break;
  2760. case MSM_BACKEND_DAI_SLIMBUS_1_TX:
  2761. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2762. slim_tx_cfg[1].bit_format);
  2763. rate->min = rate->max = slim_tx_cfg[1].sample_rate;
  2764. channels->min = channels->max = slim_tx_cfg[1].channels;
  2765. break;
  2766. case MSM_BACKEND_DAI_SLIMBUS_4_TX:
  2767. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2768. SNDRV_PCM_FORMAT_S32_LE);
  2769. rate->min = rate->max = SAMPLING_RATE_8KHZ;
  2770. channels->min = channels->max = msm_vi_feed_tx_ch;
  2771. break;
  2772. case MSM_BACKEND_DAI_SLIMBUS_5_RX:
  2773. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2774. slim_rx_cfg[5].bit_format);
  2775. rate->min = rate->max = slim_rx_cfg[5].sample_rate;
  2776. channels->min = channels->max = slim_rx_cfg[5].channels;
  2777. break;
  2778. case MSM_BACKEND_DAI_SLIMBUS_5_TX:
  2779. codec = rtd->codec;
  2780. rate->min = rate->max = SAMPLING_RATE_16KHZ;
  2781. channels->min = channels->max = 1;
  2782. config = msm_codec_fn.get_afe_config_fn(codec,
  2783. AFE_SLIMBUS_SLAVE_PORT_CONFIG);
  2784. if (config) {
  2785. rc = afe_set_config(AFE_SLIMBUS_SLAVE_PORT_CONFIG,
  2786. config, SLIMBUS_5_TX);
  2787. if (rc)
  2788. pr_err("%s: Failed to set slimbus slave port config %d\n",
  2789. __func__, rc);
  2790. }
  2791. break;
  2792. case MSM_BACKEND_DAI_SLIMBUS_7_RX:
  2793. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2794. slim_rx_cfg[SLIM_RX_7].bit_format);
  2795. rate->min = rate->max = slim_rx_cfg[SLIM_RX_7].sample_rate;
  2796. channels->min = channels->max =
  2797. slim_rx_cfg[SLIM_RX_7].channels;
  2798. break;
  2799. case MSM_BACKEND_DAI_SLIMBUS_7_TX:
  2800. rate->min = rate->max = slim_tx_cfg[SLIM_TX_7].sample_rate;
  2801. channels->min = channels->max =
  2802. slim_tx_cfg[SLIM_TX_7].channels;
  2803. break;
  2804. case MSM_BACKEND_DAI_SLIMBUS_8_TX:
  2805. rate->min = rate->max = slim_tx_cfg[SLIM_TX_8].sample_rate;
  2806. channels->min = channels->max =
  2807. slim_tx_cfg[SLIM_TX_8].channels;
  2808. break;
  2809. case MSM_BACKEND_DAI_USB_RX:
  2810. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2811. usb_rx_cfg.bit_format);
  2812. rate->min = rate->max = usb_rx_cfg.sample_rate;
  2813. channels->min = channels->max = usb_rx_cfg.channels;
  2814. break;
  2815. case MSM_BACKEND_DAI_USB_TX:
  2816. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2817. usb_tx_cfg.bit_format);
  2818. rate->min = rate->max = usb_tx_cfg.sample_rate;
  2819. channels->min = channels->max = usb_tx_cfg.channels;
  2820. break;
  2821. case MSM_BACKEND_DAI_DISPLAY_PORT_RX:
  2822. idx = msm_ext_disp_get_idx_from_beid(dai_link->id);
  2823. if (idx < 0) {
  2824. pr_err("%s: Incorrect ext disp idx %d\n",
  2825. __func__, idx);
  2826. rc = idx;
  2827. goto done;
  2828. }
  2829. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2830. ext_disp_rx_cfg[idx].bit_format);
  2831. rate->min = rate->max = ext_disp_rx_cfg[idx].sample_rate;
  2832. channels->min = channels->max = ext_disp_rx_cfg[idx].channels;
  2833. break;
  2834. case MSM_BACKEND_DAI_AFE_PCM_RX:
  2835. channels->min = channels->max = proxy_rx_cfg.channels;
  2836. rate->min = rate->max = SAMPLING_RATE_48KHZ;
  2837. break;
  2838. case MSM_BACKEND_DAI_PRI_TDM_RX_0:
  2839. channels->min = channels->max =
  2840. tdm_rx_cfg[TDM_PRI][TDM_0].channels;
  2841. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2842. tdm_rx_cfg[TDM_PRI][TDM_0].bit_format);
  2843. rate->min = rate->max = tdm_rx_cfg[TDM_PRI][TDM_0].sample_rate;
  2844. break;
  2845. case MSM_BACKEND_DAI_PRI_TDM_TX_0:
  2846. channels->min = channels->max =
  2847. tdm_tx_cfg[TDM_PRI][TDM_0].channels;
  2848. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2849. tdm_tx_cfg[TDM_PRI][TDM_0].bit_format);
  2850. rate->min = rate->max = tdm_tx_cfg[TDM_PRI][TDM_0].sample_rate;
  2851. break;
  2852. case MSM_BACKEND_DAI_SEC_TDM_RX_0:
  2853. channels->min = channels->max =
  2854. tdm_rx_cfg[TDM_SEC][TDM_0].channels;
  2855. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2856. tdm_rx_cfg[TDM_SEC][TDM_0].bit_format);
  2857. rate->min = rate->max = tdm_rx_cfg[TDM_SEC][TDM_0].sample_rate;
  2858. break;
  2859. case MSM_BACKEND_DAI_SEC_TDM_TX_0:
  2860. channels->min = channels->max =
  2861. tdm_tx_cfg[TDM_SEC][TDM_0].channels;
  2862. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2863. tdm_tx_cfg[TDM_SEC][TDM_0].bit_format);
  2864. rate->min = rate->max = tdm_tx_cfg[TDM_SEC][TDM_0].sample_rate;
  2865. break;
  2866. case MSM_BACKEND_DAI_TERT_TDM_RX_0:
  2867. channels->min = channels->max =
  2868. tdm_rx_cfg[TDM_TERT][TDM_0].channels;
  2869. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2870. tdm_rx_cfg[TDM_TERT][TDM_0].bit_format);
  2871. rate->min = rate->max = tdm_rx_cfg[TDM_TERT][TDM_0].sample_rate;
  2872. break;
  2873. case MSM_BACKEND_DAI_TERT_TDM_TX_0:
  2874. channels->min = channels->max =
  2875. tdm_tx_cfg[TDM_TERT][TDM_0].channels;
  2876. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2877. tdm_tx_cfg[TDM_TERT][TDM_0].bit_format);
  2878. rate->min = rate->max = tdm_tx_cfg[TDM_TERT][TDM_0].sample_rate;
  2879. break;
  2880. case MSM_BACKEND_DAI_QUAT_TDM_RX_0:
  2881. channels->min = channels->max =
  2882. tdm_rx_cfg[TDM_QUAT][TDM_0].channels;
  2883. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2884. tdm_rx_cfg[TDM_QUAT][TDM_0].bit_format);
  2885. rate->min = rate->max = tdm_rx_cfg[TDM_QUAT][TDM_0].sample_rate;
  2886. break;
  2887. case MSM_BACKEND_DAI_QUAT_TDM_TX_0:
  2888. channels->min = channels->max =
  2889. tdm_tx_cfg[TDM_QUAT][TDM_0].channels;
  2890. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2891. tdm_tx_cfg[TDM_QUAT][TDM_0].bit_format);
  2892. rate->min = rate->max = tdm_tx_cfg[TDM_QUAT][TDM_0].sample_rate;
  2893. break;
  2894. case MSM_BACKEND_DAI_AUXPCM_RX:
  2895. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2896. aux_pcm_rx_cfg[PRIM_AUX_PCM].bit_format);
  2897. rate->min = rate->max =
  2898. aux_pcm_rx_cfg[PRIM_AUX_PCM].sample_rate;
  2899. channels->min = channels->max =
  2900. aux_pcm_rx_cfg[PRIM_AUX_PCM].channels;
  2901. break;
  2902. case MSM_BACKEND_DAI_AUXPCM_TX:
  2903. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2904. aux_pcm_tx_cfg[PRIM_AUX_PCM].bit_format);
  2905. rate->min = rate->max =
  2906. aux_pcm_tx_cfg[PRIM_AUX_PCM].sample_rate;
  2907. channels->min = channels->max =
  2908. aux_pcm_tx_cfg[PRIM_AUX_PCM].channels;
  2909. break;
  2910. case MSM_BACKEND_DAI_SEC_AUXPCM_RX:
  2911. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2912. aux_pcm_rx_cfg[SEC_AUX_PCM].bit_format);
  2913. rate->min = rate->max =
  2914. aux_pcm_rx_cfg[SEC_AUX_PCM].sample_rate;
  2915. channels->min = channels->max =
  2916. aux_pcm_rx_cfg[SEC_AUX_PCM].channels;
  2917. break;
  2918. case MSM_BACKEND_DAI_SEC_AUXPCM_TX:
  2919. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2920. aux_pcm_tx_cfg[SEC_AUX_PCM].bit_format);
  2921. rate->min = rate->max =
  2922. aux_pcm_tx_cfg[SEC_AUX_PCM].sample_rate;
  2923. channels->min = channels->max =
  2924. aux_pcm_tx_cfg[SEC_AUX_PCM].channels;
  2925. break;
  2926. case MSM_BACKEND_DAI_TERT_AUXPCM_RX:
  2927. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2928. aux_pcm_rx_cfg[TERT_AUX_PCM].bit_format);
  2929. rate->min = rate->max =
  2930. aux_pcm_rx_cfg[TERT_AUX_PCM].sample_rate;
  2931. channels->min = channels->max =
  2932. aux_pcm_rx_cfg[TERT_AUX_PCM].channels;
  2933. break;
  2934. case MSM_BACKEND_DAI_TERT_AUXPCM_TX:
  2935. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2936. aux_pcm_tx_cfg[TERT_AUX_PCM].bit_format);
  2937. rate->min = rate->max =
  2938. aux_pcm_tx_cfg[TERT_AUX_PCM].sample_rate;
  2939. channels->min = channels->max =
  2940. aux_pcm_tx_cfg[TERT_AUX_PCM].channels;
  2941. break;
  2942. case MSM_BACKEND_DAI_QUAT_AUXPCM_RX:
  2943. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2944. aux_pcm_rx_cfg[QUAT_AUX_PCM].bit_format);
  2945. rate->min = rate->max =
  2946. aux_pcm_rx_cfg[QUAT_AUX_PCM].sample_rate;
  2947. channels->min = channels->max =
  2948. aux_pcm_rx_cfg[QUAT_AUX_PCM].channels;
  2949. break;
  2950. case MSM_BACKEND_DAI_QUAT_AUXPCM_TX:
  2951. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2952. aux_pcm_tx_cfg[QUAT_AUX_PCM].bit_format);
  2953. rate->min = rate->max =
  2954. aux_pcm_tx_cfg[QUAT_AUX_PCM].sample_rate;
  2955. channels->min = channels->max =
  2956. aux_pcm_tx_cfg[QUAT_AUX_PCM].channels;
  2957. break;
  2958. case MSM_BACKEND_DAI_PRI_MI2S_RX:
  2959. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2960. mi2s_rx_cfg[PRIM_MI2S].bit_format);
  2961. rate->min = rate->max = mi2s_rx_cfg[PRIM_MI2S].sample_rate;
  2962. channels->min = channels->max =
  2963. mi2s_rx_cfg[PRIM_MI2S].channels;
  2964. break;
  2965. case MSM_BACKEND_DAI_PRI_MI2S_TX:
  2966. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2967. mi2s_tx_cfg[PRIM_MI2S].bit_format);
  2968. rate->min = rate->max = mi2s_tx_cfg[PRIM_MI2S].sample_rate;
  2969. channels->min = channels->max =
  2970. mi2s_tx_cfg[PRIM_MI2S].channels;
  2971. break;
  2972. case MSM_BACKEND_DAI_SECONDARY_MI2S_RX:
  2973. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2974. mi2s_rx_cfg[SEC_MI2S].bit_format);
  2975. rate->min = rate->max = mi2s_rx_cfg[SEC_MI2S].sample_rate;
  2976. channels->min = channels->max =
  2977. mi2s_rx_cfg[SEC_MI2S].channels;
  2978. break;
  2979. case MSM_BACKEND_DAI_SECONDARY_MI2S_TX:
  2980. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2981. mi2s_tx_cfg[SEC_MI2S].bit_format);
  2982. rate->min = rate->max = mi2s_tx_cfg[SEC_MI2S].sample_rate;
  2983. channels->min = channels->max =
  2984. mi2s_tx_cfg[SEC_MI2S].channels;
  2985. break;
  2986. case MSM_BACKEND_DAI_TERTIARY_MI2S_RX:
  2987. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2988. mi2s_rx_cfg[TERT_MI2S].bit_format);
  2989. rate->min = rate->max = mi2s_rx_cfg[TERT_MI2S].sample_rate;
  2990. channels->min = channels->max =
  2991. mi2s_rx_cfg[TERT_MI2S].channels;
  2992. break;
  2993. case MSM_BACKEND_DAI_TERTIARY_MI2S_TX:
  2994. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  2995. mi2s_tx_cfg[TERT_MI2S].bit_format);
  2996. rate->min = rate->max = mi2s_tx_cfg[TERT_MI2S].sample_rate;
  2997. channels->min = channels->max =
  2998. mi2s_tx_cfg[TERT_MI2S].channels;
  2999. break;
  3000. case MSM_BACKEND_DAI_QUATERNARY_MI2S_RX:
  3001. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  3002. mi2s_rx_cfg[QUAT_MI2S].bit_format);
  3003. rate->min = rate->max = mi2s_rx_cfg[QUAT_MI2S].sample_rate;
  3004. channels->min = channels->max =
  3005. mi2s_rx_cfg[QUAT_MI2S].channels;
  3006. break;
  3007. case MSM_BACKEND_DAI_QUATERNARY_MI2S_TX:
  3008. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  3009. mi2s_tx_cfg[QUAT_MI2S].bit_format);
  3010. rate->min = rate->max = mi2s_tx_cfg[QUAT_MI2S].sample_rate;
  3011. channels->min = channels->max =
  3012. mi2s_tx_cfg[QUAT_MI2S].channels;
  3013. break;
  3014. default:
  3015. rate->min = rate->max = SAMPLING_RATE_48KHZ;
  3016. break;
  3017. }
  3018. done:
  3019. return rc;
  3020. }
  3021. static bool msm_usbc_swap_gnd_mic(struct snd_soc_codec *codec, bool active)
  3022. {
  3023. int value = 0;
  3024. bool ret = 0;
  3025. struct snd_soc_card *card = codec->component.card;
  3026. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  3027. struct pinctrl_state *en2_pinctrl_active;
  3028. struct pinctrl_state *en2_pinctrl_sleep;
  3029. if (!pdata->usbc_en2_gpio_p) {
  3030. if (active) {
  3031. /* if active and usbc_en2_gpio undefined, get pin */
  3032. pdata->usbc_en2_gpio_p = devm_pinctrl_get(card->dev);
  3033. if (IS_ERR_OR_NULL(pdata->usbc_en2_gpio_p)) {
  3034. dev_err(card->dev,
  3035. "%s: Can't get EN2 gpio pinctrl:%ld\n",
  3036. __func__,
  3037. PTR_ERR(pdata->usbc_en2_gpio_p));
  3038. pdata->usbc_en2_gpio_p = NULL;
  3039. return false;
  3040. }
  3041. } else
  3042. /* if not active and usbc_en2_gpio undefined, return */
  3043. return false;
  3044. }
  3045. pdata->usbc_en2_gpio = of_get_named_gpio(card->dev->of_node,
  3046. "qcom,usbc-analog-en2-gpio", 0);
  3047. if (!gpio_is_valid(pdata->usbc_en2_gpio)) {
  3048. dev_err(card->dev, "%s, property %s not in node %s",
  3049. __func__, "qcom,usbc-analog-en2-gpio",
  3050. card->dev->of_node->full_name);
  3051. return false;
  3052. }
  3053. en2_pinctrl_active = pinctrl_lookup_state(
  3054. pdata->usbc_en2_gpio_p, "aud_active");
  3055. if (IS_ERR_OR_NULL(en2_pinctrl_active)) {
  3056. dev_err(card->dev,
  3057. "%s: Cannot get aud_active pinctrl state:%ld\n",
  3058. __func__, PTR_ERR(en2_pinctrl_active));
  3059. ret = false;
  3060. goto err_lookup_state;
  3061. }
  3062. en2_pinctrl_sleep = pinctrl_lookup_state(
  3063. pdata->usbc_en2_gpio_p, "aud_sleep");
  3064. if (IS_ERR_OR_NULL(en2_pinctrl_sleep)) {
  3065. dev_err(card->dev,
  3066. "%s: Cannot get aud_sleep pinctrl state:%ld\n",
  3067. __func__, PTR_ERR(en2_pinctrl_sleep));
  3068. ret = false;
  3069. goto err_lookup_state;
  3070. }
  3071. /* if active and usbc_en2_gpio_p defined, swap using usbc_en2_gpio_p */
  3072. if (active) {
  3073. dev_dbg(codec->dev, "%s: enter\n", __func__);
  3074. if (pdata->usbc_en2_gpio_p) {
  3075. value = gpio_get_value_cansleep(pdata->usbc_en2_gpio);
  3076. if (value)
  3077. pinctrl_select_state(pdata->usbc_en2_gpio_p,
  3078. en2_pinctrl_sleep);
  3079. else
  3080. pinctrl_select_state(pdata->usbc_en2_gpio_p,
  3081. en2_pinctrl_active);
  3082. } else if (pdata->usbc_en2_gpio >= 0) {
  3083. value = gpio_get_value_cansleep(pdata->usbc_en2_gpio);
  3084. gpio_set_value_cansleep(pdata->usbc_en2_gpio, !value);
  3085. }
  3086. pr_debug("%s: swap select switch %d to %d\n", __func__,
  3087. value, !value);
  3088. ret = true;
  3089. } else {
  3090. /* if not active, release usbc_en2_gpio_p pin */
  3091. pinctrl_select_state(pdata->usbc_en2_gpio_p,
  3092. en2_pinctrl_sleep);
  3093. }
  3094. err_lookup_state:
  3095. devm_pinctrl_put(pdata->usbc_en2_gpio_p);
  3096. pdata->usbc_en2_gpio_p = NULL;
  3097. return ret;
  3098. }
  3099. static bool msm_swap_gnd_mic(struct snd_soc_codec *codec, bool active)
  3100. {
  3101. int value = 0;
  3102. int ret = 0;
  3103. struct snd_soc_card *card = codec->component.card;
  3104. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  3105. if (!pdata)
  3106. return false;
  3107. if (!wcd_mbhc_cfg.enable_usbc_analog) {
  3108. /* if usbc is not defined, swap using us_euro_gpio_p */
  3109. if (pdata->us_euro_gpio_p) {
  3110. value = msm_cdc_pinctrl_get_state(
  3111. pdata->us_euro_gpio_p);
  3112. if (value)
  3113. msm_cdc_pinctrl_select_sleep_state(
  3114. pdata->us_euro_gpio_p);
  3115. else
  3116. msm_cdc_pinctrl_select_active_state(
  3117. pdata->us_euro_gpio_p);
  3118. } else if (pdata->us_euro_gpio >= 0) {
  3119. value = gpio_get_value_cansleep(
  3120. pdata->us_euro_gpio);
  3121. gpio_set_value_cansleep(
  3122. pdata->us_euro_gpio, !value);
  3123. }
  3124. pr_debug("%s: swap select switch %d to %d\n", __func__,
  3125. value, !value);
  3126. ret = true;
  3127. } else {
  3128. /* if usbc is defined, swap using usbc_en2 */
  3129. ret = msm_usbc_swap_gnd_mic(codec, active);
  3130. }
  3131. return ret;
  3132. }
  3133. static int msm_afe_set_config(struct snd_soc_codec *codec)
  3134. {
  3135. int ret = 0;
  3136. void *config_data = NULL;
  3137. if (!msm_codec_fn.get_afe_config_fn) {
  3138. dev_err(codec->dev, "%s: codec get afe config not init'ed\n",
  3139. __func__);
  3140. return -EINVAL;
  3141. }
  3142. config_data = msm_codec_fn.get_afe_config_fn(codec,
  3143. AFE_CDC_REGISTERS_CONFIG);
  3144. if (config_data) {
  3145. ret = afe_set_config(AFE_CDC_REGISTERS_CONFIG, config_data, 0);
  3146. if (ret) {
  3147. dev_err(codec->dev,
  3148. "%s: Failed to set codec registers config %d\n",
  3149. __func__, ret);
  3150. return ret;
  3151. }
  3152. }
  3153. config_data = msm_codec_fn.get_afe_config_fn(codec,
  3154. AFE_CDC_REGISTER_PAGE_CONFIG);
  3155. if (config_data) {
  3156. ret = afe_set_config(AFE_CDC_REGISTER_PAGE_CONFIG, config_data,
  3157. 0);
  3158. if (ret)
  3159. dev_err(codec->dev,
  3160. "%s: Failed to set cdc register page config\n",
  3161. __func__);
  3162. }
  3163. config_data = msm_codec_fn.get_afe_config_fn(codec,
  3164. AFE_SLIMBUS_SLAVE_CONFIG);
  3165. if (config_data) {
  3166. ret = afe_set_config(AFE_SLIMBUS_SLAVE_CONFIG, config_data, 0);
  3167. if (ret) {
  3168. dev_err(codec->dev,
  3169. "%s: Failed to set slimbus slave config %d\n",
  3170. __func__, ret);
  3171. return ret;
  3172. }
  3173. }
  3174. return 0;
  3175. }
  3176. static void msm_afe_clear_config(void)
  3177. {
  3178. afe_clear_config(AFE_CDC_REGISTERS_CONFIG);
  3179. afe_clear_config(AFE_SLIMBUS_SLAVE_CONFIG);
  3180. }
  3181. static int msm_adsp_power_up_config(struct snd_soc_codec *codec,
  3182. struct snd_card *card)
  3183. {
  3184. int ret = 0;
  3185. unsigned long timeout;
  3186. int adsp_ready = 0;
  3187. bool snd_card_online = 0;
  3188. timeout = jiffies +
  3189. msecs_to_jiffies(ADSP_STATE_READY_TIMEOUT_MS);
  3190. do {
  3191. if (!snd_card_online) {
  3192. snd_card_online = snd_card_is_online_state(card);
  3193. pr_debug("%s: Sound card is %s\n", __func__,
  3194. snd_card_online ? "Online" : "Offline");
  3195. }
  3196. if (!adsp_ready) {
  3197. adsp_ready = q6core_is_adsp_ready();
  3198. pr_debug("%s: ADSP Audio is %s\n", __func__,
  3199. adsp_ready ? "ready" : "not ready");
  3200. }
  3201. if (snd_card_online && adsp_ready)
  3202. break;
  3203. /*
  3204. * Sound card/ADSP will be coming up after subsystem restart and
  3205. * it might not be fully up when the control reaches
  3206. * here. So, wait for 50msec before checking ADSP state
  3207. */
  3208. msleep(50);
  3209. } while (time_after(timeout, jiffies));
  3210. if (!snd_card_online || !adsp_ready) {
  3211. pr_err("%s: Timeout. Sound card is %s, ADSP Audio is %s\n",
  3212. __func__,
  3213. snd_card_online ? "Online" : "Offline",
  3214. adsp_ready ? "ready" : "not ready");
  3215. ret = -ETIMEDOUT;
  3216. goto err;
  3217. }
  3218. ret = msm_afe_set_config(codec);
  3219. if (ret)
  3220. pr_err("%s: Failed to set AFE config. err %d\n",
  3221. __func__, ret);
  3222. return 0;
  3223. err:
  3224. return ret;
  3225. }
  3226. static int sdm845_notifier_service_cb(struct notifier_block *this,
  3227. unsigned long opcode, void *ptr)
  3228. {
  3229. int ret;
  3230. struct snd_soc_card *card = NULL;
  3231. const char *be_dl_name = LPASS_BE_SLIMBUS_0_RX;
  3232. struct snd_soc_pcm_runtime *rtd;
  3233. struct snd_soc_codec *codec;
  3234. pr_debug("%s: Service opcode 0x%lx\n", __func__, opcode);
  3235. switch (opcode) {
  3236. case AUDIO_NOTIFIER_SERVICE_DOWN:
  3237. /*
  3238. * Use flag to ignore initial boot notifications
  3239. * On initial boot msm_adsp_power_up_config is
  3240. * called on init. There is no need to clear
  3241. * and set the config again on initial boot.
  3242. */
  3243. if (is_initial_boot)
  3244. break;
  3245. msm_afe_clear_config();
  3246. break;
  3247. case AUDIO_NOTIFIER_SERVICE_UP:
  3248. if (is_initial_boot) {
  3249. is_initial_boot = false;
  3250. break;
  3251. }
  3252. if (!spdev)
  3253. return -EINVAL;
  3254. card = platform_get_drvdata(spdev);
  3255. rtd = snd_soc_get_pcm_runtime(card, be_dl_name);
  3256. if (!rtd) {
  3257. dev_err(card->dev,
  3258. "%s: snd_soc_get_pcm_runtime for %s failed!\n",
  3259. __func__, be_dl_name);
  3260. ret = -EINVAL;
  3261. goto err;
  3262. }
  3263. codec = rtd->codec;
  3264. ret = msm_adsp_power_up_config(codec, card->snd_card);
  3265. if (ret < 0) {
  3266. dev_err(card->dev,
  3267. "%s: msm_adsp_power_up_config failed ret = %d!\n",
  3268. __func__, ret);
  3269. goto err;
  3270. }
  3271. break;
  3272. default:
  3273. break;
  3274. }
  3275. err:
  3276. return NOTIFY_OK;
  3277. }
  3278. static struct notifier_block service_nb = {
  3279. .notifier_call = sdm845_notifier_service_cb,
  3280. .priority = -INT_MAX,
  3281. };
  3282. static int msm_audrx_init(struct snd_soc_pcm_runtime *rtd)
  3283. {
  3284. int ret = 0;
  3285. void *config_data;
  3286. struct snd_soc_codec *codec = rtd->codec;
  3287. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  3288. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  3289. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  3290. struct snd_soc_component *aux_comp;
  3291. struct snd_card *card;
  3292. struct snd_info_entry *entry;
  3293. struct msm_asoc_mach_data *pdata =
  3294. snd_soc_card_get_drvdata(rtd->card);
  3295. /* Codec SLIMBUS configuration
  3296. * RX1, RX2, RX3, RX4, RX5, RX6, RX7, RX8
  3297. * TX1, TX2, TX3, TX4, TX5, TX6, TX7, TX8, TX9, TX10, TX11, TX12, TX13
  3298. * TX14, TX15, TX16
  3299. */
  3300. unsigned int rx_ch[WCD934X_RX_MAX] = {144, 145, 146, 147, 148, 149,
  3301. 150, 151};
  3302. unsigned int tx_ch[WCD934X_TX_MAX] = {128, 129, 130, 131, 132, 133,
  3303. 134, 135, 136, 137, 138, 139,
  3304. 140, 141, 142, 143};
  3305. pr_info("%s: dev_name%s\n", __func__, dev_name(cpu_dai->dev));
  3306. rtd->pmdown_time = 0;
  3307. ret = snd_soc_add_codec_controls(codec, msm_snd_controls,
  3308. ARRAY_SIZE(msm_snd_controls));
  3309. if (ret < 0) {
  3310. pr_err("%s: add_codec_controls failed, err %d\n",
  3311. __func__, ret);
  3312. return ret;
  3313. }
  3314. snd_soc_dapm_new_controls(dapm, msm_dapm_widgets,
  3315. ARRAY_SIZE(msm_dapm_widgets));
  3316. snd_soc_dapm_add_routes(dapm, wcd_audio_paths,
  3317. ARRAY_SIZE(wcd_audio_paths));
  3318. snd_soc_dapm_ignore_suspend(dapm, "Handset Mic");
  3319. snd_soc_dapm_ignore_suspend(dapm, "Headset Mic");
  3320. snd_soc_dapm_ignore_suspend(dapm, "ANCRight Headset Mic");
  3321. snd_soc_dapm_ignore_suspend(dapm, "ANCLeft Headset Mic");
  3322. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic0");
  3323. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic1");
  3324. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic2");
  3325. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic3");
  3326. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic4");
  3327. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic5");
  3328. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic5");
  3329. snd_soc_dapm_ignore_suspend(dapm, "MADINPUT");
  3330. snd_soc_dapm_ignore_suspend(dapm, "MAD_CPE_INPUT");
  3331. snd_soc_dapm_ignore_suspend(dapm, "MAD_CPE_OUT1");
  3332. snd_soc_dapm_ignore_suspend(dapm, "MAD_CPE_OUT2");
  3333. snd_soc_dapm_ignore_suspend(dapm, "EAR");
  3334. snd_soc_dapm_ignore_suspend(dapm, "LINEOUT1");
  3335. snd_soc_dapm_ignore_suspend(dapm, "LINEOUT2");
  3336. snd_soc_dapm_ignore_suspend(dapm, "ANC EAR");
  3337. snd_soc_dapm_ignore_suspend(dapm, "SPK1 OUT");
  3338. snd_soc_dapm_ignore_suspend(dapm, "SPK2 OUT");
  3339. snd_soc_dapm_ignore_suspend(dapm, "HPHL");
  3340. snd_soc_dapm_ignore_suspend(dapm, "HPHR");
  3341. snd_soc_dapm_ignore_suspend(dapm, "AIF4 VI");
  3342. snd_soc_dapm_ignore_suspend(dapm, "VIINPUT");
  3343. snd_soc_dapm_ignore_suspend(dapm, "ANC HPHL");
  3344. snd_soc_dapm_ignore_suspend(dapm, "ANC HPHR");
  3345. snd_soc_dapm_sync(dapm);
  3346. snd_soc_dai_set_channel_map(codec_dai, ARRAY_SIZE(tx_ch),
  3347. tx_ch, ARRAY_SIZE(rx_ch), rx_ch);
  3348. msm_codec_fn.get_afe_config_fn = tavil_get_afe_config;
  3349. ret = msm_adsp_power_up_config(codec, rtd->card->snd_card);
  3350. if (ret) {
  3351. pr_err("%s: Failed to set AFE config %d\n", __func__, ret);
  3352. goto err;
  3353. }
  3354. config_data = msm_codec_fn.get_afe_config_fn(codec,
  3355. AFE_AANC_VERSION);
  3356. if (config_data) {
  3357. ret = afe_set_config(AFE_AANC_VERSION, config_data, 0);
  3358. if (ret) {
  3359. pr_err("%s: Failed to set aanc version %d\n",
  3360. __func__, ret);
  3361. goto err;
  3362. }
  3363. }
  3364. /*
  3365. * Send speaker configuration only for WSA8810.
  3366. * Default configuration is for WSA8815.
  3367. */
  3368. pr_debug("%s: Number of aux devices: %d\n",
  3369. __func__, rtd->card->num_aux_devs);
  3370. if (rtd->card->num_aux_devs &&
  3371. !list_empty(&rtd->card->aux_comp_list)) {
  3372. aux_comp = list_first_entry(&rtd->card->aux_comp_list,
  3373. struct snd_soc_component, list_aux);
  3374. if (!strcmp(aux_comp->name, WSA8810_NAME_1) ||
  3375. !strcmp(aux_comp->name, WSA8810_NAME_2)) {
  3376. tavil_set_spkr_mode(rtd->codec, WCD934X_SPKR_MODE_1);
  3377. tavil_set_spkr_gain_offset(rtd->codec,
  3378. WCD934X_RX_GAIN_OFFSET_M1P5_DB);
  3379. }
  3380. }
  3381. card = rtd->card->snd_card;
  3382. entry = snd_info_create_subdir(card->module, "codecs",
  3383. card->proc_root);
  3384. if (!entry) {
  3385. pr_debug("%s: Cannot create codecs module entry\n",
  3386. __func__);
  3387. pdata->codec_root = NULL;
  3388. goto done;
  3389. }
  3390. pdata->codec_root = entry;
  3391. tavil_codec_info_create_codec_entry(pdata->codec_root, codec);
  3392. done:
  3393. codec_reg_done = true;
  3394. return 0;
  3395. err:
  3396. return ret;
  3397. }
  3398. static int msm_wcn_init(struct snd_soc_pcm_runtime *rtd)
  3399. {
  3400. unsigned int rx_ch[WCN_CDC_SLIM_RX_CH_MAX] = {157, 158};
  3401. unsigned int tx_ch[WCN_CDC_SLIM_TX_CH_MAX] = {159, 160, 161};
  3402. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  3403. return snd_soc_dai_set_channel_map(codec_dai, ARRAY_SIZE(tx_ch),
  3404. tx_ch, ARRAY_SIZE(rx_ch), rx_ch);
  3405. }
  3406. static void *def_tavil_mbhc_cal(void)
  3407. {
  3408. void *tavil_wcd_cal;
  3409. struct wcd_mbhc_btn_detect_cfg *btn_cfg;
  3410. u16 *btn_high;
  3411. tavil_wcd_cal = kzalloc(WCD_MBHC_CAL_SIZE(WCD_MBHC_DEF_BUTTONS,
  3412. WCD9XXX_MBHC_DEF_RLOADS), GFP_KERNEL);
  3413. if (!tavil_wcd_cal)
  3414. return NULL;
  3415. #define S(X, Y) ((WCD_MBHC_CAL_PLUG_TYPE_PTR(tavil_wcd_cal)->X) = (Y))
  3416. S(v_hs_max, 1600);
  3417. #undef S
  3418. #define S(X, Y) ((WCD_MBHC_CAL_BTN_DET_PTR(tavil_wcd_cal)->X) = (Y))
  3419. S(num_btn, WCD_MBHC_DEF_BUTTONS);
  3420. #undef S
  3421. btn_cfg = WCD_MBHC_CAL_BTN_DET_PTR(tavil_wcd_cal);
  3422. btn_high = ((void *)&btn_cfg->_v_btn_low) +
  3423. (sizeof(btn_cfg->_v_btn_low[0]) * btn_cfg->num_btn);
  3424. btn_high[0] = 75;
  3425. btn_high[1] = 150;
  3426. btn_high[2] = 237;
  3427. btn_high[3] = 500;
  3428. btn_high[4] = 500;
  3429. btn_high[5] = 500;
  3430. btn_high[6] = 500;
  3431. btn_high[7] = 500;
  3432. return tavil_wcd_cal;
  3433. }
  3434. static int msm_snd_hw_params(struct snd_pcm_substream *substream,
  3435. struct snd_pcm_hw_params *params)
  3436. {
  3437. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  3438. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  3439. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  3440. struct snd_soc_dai_link *dai_link = rtd->dai_link;
  3441. int ret = 0;
  3442. u32 rx_ch[SLIM_MAX_RX_PORTS], tx_ch[SLIM_MAX_TX_PORTS];
  3443. u32 rx_ch_cnt = 0, tx_ch_cnt = 0;
  3444. u32 user_set_tx_ch = 0;
  3445. u32 rx_ch_count;
  3446. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  3447. ret = snd_soc_dai_get_channel_map(codec_dai,
  3448. &tx_ch_cnt, tx_ch, &rx_ch_cnt, rx_ch);
  3449. if (ret < 0) {
  3450. pr_err("%s: failed to get codec chan map, err:%d\n",
  3451. __func__, ret);
  3452. goto err;
  3453. }
  3454. if (dai_link->id == MSM_BACKEND_DAI_SLIMBUS_5_RX) {
  3455. pr_debug("%s: rx_5_ch=%d\n", __func__,
  3456. slim_rx_cfg[5].channels);
  3457. rx_ch_count = slim_rx_cfg[5].channels;
  3458. } else if (dai_link->id == MSM_BACKEND_DAI_SLIMBUS_2_RX) {
  3459. pr_debug("%s: rx_2_ch=%d\n", __func__,
  3460. slim_rx_cfg[2].channels);
  3461. rx_ch_count = slim_rx_cfg[2].channels;
  3462. } else if (dai_link->id == MSM_BACKEND_DAI_SLIMBUS_6_RX) {
  3463. pr_debug("%s: rx_6_ch=%d\n", __func__,
  3464. slim_rx_cfg[6].channels);
  3465. rx_ch_count = slim_rx_cfg[6].channels;
  3466. } else {
  3467. pr_debug("%s: rx_0_ch=%d\n", __func__,
  3468. slim_rx_cfg[0].channels);
  3469. rx_ch_count = slim_rx_cfg[0].channels;
  3470. }
  3471. ret = snd_soc_dai_set_channel_map(cpu_dai, 0, 0,
  3472. rx_ch_count, rx_ch);
  3473. if (ret < 0) {
  3474. pr_err("%s: failed to set cpu chan map, err:%d\n",
  3475. __func__, ret);
  3476. goto err;
  3477. }
  3478. } else {
  3479. pr_debug("%s: %s_tx_dai_id_%d_ch=%d\n", __func__,
  3480. codec_dai->name, codec_dai->id, user_set_tx_ch);
  3481. ret = snd_soc_dai_get_channel_map(codec_dai,
  3482. &tx_ch_cnt, tx_ch, &rx_ch_cnt, rx_ch);
  3483. if (ret < 0) {
  3484. pr_err("%s: failed to get codec chan map\n, err:%d\n",
  3485. __func__, ret);
  3486. goto err;
  3487. }
  3488. /* For <codec>_tx1 case */
  3489. if (dai_link->id == MSM_BACKEND_DAI_SLIMBUS_0_TX)
  3490. user_set_tx_ch = slim_tx_cfg[0].channels;
  3491. /* For <codec>_tx3 case */
  3492. else if (dai_link->id == MSM_BACKEND_DAI_SLIMBUS_1_TX)
  3493. user_set_tx_ch = slim_tx_cfg[1].channels;
  3494. else if (dai_link->id == MSM_BACKEND_DAI_SLIMBUS_4_TX)
  3495. user_set_tx_ch = msm_vi_feed_tx_ch;
  3496. else
  3497. user_set_tx_ch = tx_ch_cnt;
  3498. pr_debug("%s: msm_slim_0_tx_ch(%d) user_set_tx_ch(%d) tx_ch_cnt(%d), BE id (%d)\n",
  3499. __func__, slim_tx_cfg[0].channels, user_set_tx_ch,
  3500. tx_ch_cnt, dai_link->id);
  3501. ret = snd_soc_dai_set_channel_map(cpu_dai,
  3502. user_set_tx_ch, tx_ch, 0, 0);
  3503. if (ret < 0)
  3504. pr_err("%s: failed to set cpu chan map, err:%d\n",
  3505. __func__, ret);
  3506. }
  3507. err:
  3508. return ret;
  3509. }
  3510. static int msm_slimbus_2_hw_params(struct snd_pcm_substream *substream,
  3511. struct snd_pcm_hw_params *params)
  3512. {
  3513. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  3514. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  3515. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  3516. unsigned int rx_ch[SLIM_MAX_RX_PORTS], tx_ch[SLIM_MAX_TX_PORTS];
  3517. unsigned int rx_ch_cnt = 0, tx_ch_cnt = 0;
  3518. unsigned int num_tx_ch = 0;
  3519. unsigned int num_rx_ch = 0;
  3520. int ret = 0;
  3521. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  3522. num_rx_ch = params_channels(params);
  3523. pr_debug("%s: %s rx_dai_id = %d num_ch = %d\n", __func__,
  3524. codec_dai->name, codec_dai->id, num_rx_ch);
  3525. ret = snd_soc_dai_get_channel_map(codec_dai,
  3526. &tx_ch_cnt, tx_ch, &rx_ch_cnt, rx_ch);
  3527. if (ret < 0) {
  3528. pr_err("%s: failed to get codec chan map, err:%d\n",
  3529. __func__, ret);
  3530. goto err;
  3531. }
  3532. ret = snd_soc_dai_set_channel_map(cpu_dai, 0, 0,
  3533. num_rx_ch, rx_ch);
  3534. if (ret < 0) {
  3535. pr_err("%s: failed to set cpu chan map, err:%d\n",
  3536. __func__, ret);
  3537. goto err;
  3538. }
  3539. } else {
  3540. num_tx_ch = params_channels(params);
  3541. pr_debug("%s: %s tx_dai_id = %d num_ch = %d\n", __func__,
  3542. codec_dai->name, codec_dai->id, num_tx_ch);
  3543. ret = snd_soc_dai_get_channel_map(codec_dai,
  3544. &tx_ch_cnt, tx_ch, &rx_ch_cnt, rx_ch);
  3545. if (ret < 0) {
  3546. pr_err("%s: failed to get codec chan map, err:%d\n",
  3547. __func__, ret);
  3548. goto err;
  3549. }
  3550. ret = snd_soc_dai_set_channel_map(cpu_dai,
  3551. num_tx_ch, tx_ch, 0, 0);
  3552. if (ret < 0) {
  3553. pr_err("%s: failed to set cpu chan map, err:%d\n",
  3554. __func__, ret);
  3555. goto err;
  3556. }
  3557. }
  3558. err:
  3559. return ret;
  3560. }
  3561. static int msm_wcn_hw_params(struct snd_pcm_substream *substream,
  3562. struct snd_pcm_hw_params *params)
  3563. {
  3564. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  3565. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  3566. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  3567. struct snd_soc_dai_link *dai_link = rtd->dai_link;
  3568. u32 rx_ch[WCN_CDC_SLIM_RX_CH_MAX], tx_ch[WCN_CDC_SLIM_TX_CH_MAX];
  3569. u32 rx_ch_cnt = 0, tx_ch_cnt = 0;
  3570. int ret;
  3571. dev_dbg(rtd->dev, "%s: %s_tx_dai_id_%d\n", __func__,
  3572. codec_dai->name, codec_dai->id);
  3573. ret = snd_soc_dai_get_channel_map(codec_dai,
  3574. &tx_ch_cnt, tx_ch, &rx_ch_cnt, rx_ch);
  3575. if (ret) {
  3576. dev_err(rtd->dev,
  3577. "%s: failed to get BTFM codec chan map\n, err:%d\n",
  3578. __func__, ret);
  3579. goto err;
  3580. }
  3581. dev_dbg(rtd->dev, "%s: tx_ch_cnt(%d) BE id %d\n",
  3582. __func__, tx_ch_cnt, dai_link->id);
  3583. ret = snd_soc_dai_set_channel_map(cpu_dai,
  3584. tx_ch_cnt, tx_ch, rx_ch_cnt, rx_ch);
  3585. if (ret)
  3586. dev_err(rtd->dev, "%s: failed to set cpu chan map, err:%d\n",
  3587. __func__, ret);
  3588. err:
  3589. return ret;
  3590. }
  3591. static int msm_aux_pcm_snd_startup(struct snd_pcm_substream *substream)
  3592. {
  3593. int ret = 0;
  3594. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  3595. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  3596. int index = cpu_dai->id - 1;
  3597. dev_dbg(rtd->card->dev,
  3598. "%s: substream = %s stream = %d, dai name %s, dai ID %d\n",
  3599. __func__, substream->name, substream->stream,
  3600. cpu_dai->name, cpu_dai->id);
  3601. if (index < PRIM_AUX_PCM || index > QUAT_AUX_PCM) {
  3602. ret = -EINVAL;
  3603. dev_err(rtd->card->dev,
  3604. "%s: CPU DAI id (%d) out of range\n",
  3605. __func__, cpu_dai->id);
  3606. goto err;
  3607. }
  3608. mutex_lock(&auxpcm_intf_conf[index].lock);
  3609. if (++auxpcm_intf_conf[index].ref_cnt == 1) {
  3610. if (mi2s_auxpcm_conf[index].pcm_i2s_sel_vt_addr != NULL) {
  3611. mutex_lock(&mi2s_auxpcm_conf[index].lock);
  3612. iowrite32(1,
  3613. mi2s_auxpcm_conf[index].pcm_i2s_sel_vt_addr);
  3614. mutex_unlock(&mi2s_auxpcm_conf[index].lock);
  3615. } else {
  3616. dev_err(rtd->card->dev,
  3617. "%s lpaif_tert_muxsel_virt_addr is NULL\n",
  3618. __func__);
  3619. ret = -EINVAL;
  3620. }
  3621. }
  3622. if (ret < 0)
  3623. auxpcm_intf_conf[index].ref_cnt--;
  3624. mutex_unlock(&auxpcm_intf_conf[index].lock);
  3625. err:
  3626. return ret;
  3627. }
  3628. static void msm_aux_pcm_snd_shutdown(struct snd_pcm_substream *substream)
  3629. {
  3630. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  3631. int index = rtd->cpu_dai->id - 1;
  3632. dev_dbg(rtd->card->dev,
  3633. "%s: substream = %s stream = %d, dai name %s, dai ID %d\n",
  3634. __func__,
  3635. substream->name, substream->stream,
  3636. rtd->cpu_dai->name, rtd->cpu_dai->id);
  3637. if (index < PRIM_AUX_PCM || index > QUAT_AUX_PCM) {
  3638. dev_err(rtd->card->dev,
  3639. "%s: CPU DAI id (%d) out of range\n",
  3640. __func__, rtd->cpu_dai->id);
  3641. return;
  3642. }
  3643. mutex_lock(&auxpcm_intf_conf[index].lock);
  3644. if (--auxpcm_intf_conf[index].ref_cnt == 0) {
  3645. if (mi2s_auxpcm_conf[index].pcm_i2s_sel_vt_addr != NULL) {
  3646. mutex_lock(&mi2s_auxpcm_conf[index].lock);
  3647. iowrite32(0,
  3648. mi2s_auxpcm_conf[index].pcm_i2s_sel_vt_addr);
  3649. mutex_unlock(&mi2s_auxpcm_conf[index].lock);
  3650. } else {
  3651. dev_err(rtd->card->dev,
  3652. "%s lpaif_tert_muxsel_virt_addr is NULL\n",
  3653. __func__);
  3654. }
  3655. }
  3656. mutex_unlock(&auxpcm_intf_conf[index].lock);
  3657. }
  3658. static int msm_get_port_id(int be_id)
  3659. {
  3660. int afe_port_id;
  3661. switch (be_id) {
  3662. case MSM_BACKEND_DAI_PRI_MI2S_RX:
  3663. afe_port_id = AFE_PORT_ID_PRIMARY_MI2S_RX;
  3664. break;
  3665. case MSM_BACKEND_DAI_PRI_MI2S_TX:
  3666. afe_port_id = AFE_PORT_ID_PRIMARY_MI2S_TX;
  3667. break;
  3668. case MSM_BACKEND_DAI_SECONDARY_MI2S_RX:
  3669. afe_port_id = AFE_PORT_ID_SECONDARY_MI2S_RX;
  3670. break;
  3671. case MSM_BACKEND_DAI_SECONDARY_MI2S_TX:
  3672. afe_port_id = AFE_PORT_ID_SECONDARY_MI2S_TX;
  3673. break;
  3674. case MSM_BACKEND_DAI_TERTIARY_MI2S_RX:
  3675. afe_port_id = AFE_PORT_ID_TERTIARY_MI2S_RX;
  3676. break;
  3677. case MSM_BACKEND_DAI_TERTIARY_MI2S_TX:
  3678. afe_port_id = AFE_PORT_ID_TERTIARY_MI2S_TX;
  3679. break;
  3680. case MSM_BACKEND_DAI_QUATERNARY_MI2S_RX:
  3681. afe_port_id = AFE_PORT_ID_QUATERNARY_MI2S_RX;
  3682. break;
  3683. case MSM_BACKEND_DAI_QUATERNARY_MI2S_TX:
  3684. afe_port_id = AFE_PORT_ID_QUATERNARY_MI2S_TX;
  3685. break;
  3686. default:
  3687. pr_err("%s: Invalid BE id: %d\n", __func__, be_id);
  3688. afe_port_id = -EINVAL;
  3689. }
  3690. return afe_port_id;
  3691. }
  3692. static u32 get_mi2s_bits_per_sample(u32 bit_format)
  3693. {
  3694. u32 bit_per_sample;
  3695. switch (bit_format) {
  3696. case SNDRV_PCM_FORMAT_S32_LE:
  3697. case SNDRV_PCM_FORMAT_S24_3LE:
  3698. case SNDRV_PCM_FORMAT_S24_LE:
  3699. bit_per_sample = 32;
  3700. break;
  3701. case SNDRV_PCM_FORMAT_S16_LE:
  3702. default:
  3703. bit_per_sample = 16;
  3704. break;
  3705. }
  3706. return bit_per_sample;
  3707. }
  3708. static void update_mi2s_clk_val(int dai_id, int stream)
  3709. {
  3710. u32 bit_per_sample;
  3711. if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
  3712. bit_per_sample =
  3713. get_mi2s_bits_per_sample(mi2s_rx_cfg[dai_id].bit_format);
  3714. mi2s_clk[dai_id].clk_freq_in_hz =
  3715. mi2s_rx_cfg[dai_id].sample_rate * 2 * bit_per_sample;
  3716. } else {
  3717. bit_per_sample =
  3718. get_mi2s_bits_per_sample(mi2s_tx_cfg[dai_id].bit_format);
  3719. mi2s_clk[dai_id].clk_freq_in_hz =
  3720. mi2s_tx_cfg[dai_id].sample_rate * 2 * bit_per_sample;
  3721. }
  3722. }
  3723. static int msm_mi2s_set_sclk(struct snd_pcm_substream *substream, bool enable)
  3724. {
  3725. int ret = 0;
  3726. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  3727. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  3728. int port_id = 0;
  3729. int index = cpu_dai->id;
  3730. port_id = msm_get_port_id(rtd->dai_link->id);
  3731. if (port_id < 0) {
  3732. dev_err(rtd->card->dev, "%s: Invalid port_id\n", __func__);
  3733. ret = port_id;
  3734. goto err;
  3735. }
  3736. if (enable) {
  3737. update_mi2s_clk_val(index, substream->stream);
  3738. dev_dbg(rtd->card->dev, "%s: clock rate %ul\n", __func__,
  3739. mi2s_clk[index].clk_freq_in_hz);
  3740. }
  3741. mi2s_clk[index].enable = enable;
  3742. ret = afe_set_lpass_clock_v2(port_id,
  3743. &mi2s_clk[index]);
  3744. if (ret < 0) {
  3745. dev_err(rtd->card->dev,
  3746. "%s: afe lpass clock failed for port 0x%x , err:%d\n",
  3747. __func__, port_id, ret);
  3748. goto err;
  3749. }
  3750. err:
  3751. return ret;
  3752. }
  3753. static int msm_set_pinctrl(struct msm_pinctrl_info *pinctrl_info,
  3754. enum pinctrl_pin_state new_state)
  3755. {
  3756. int ret = 0;
  3757. int curr_state = 0;
  3758. if (pinctrl_info == NULL) {
  3759. pr_err("%s: pinctrl_info is NULL\n", __func__);
  3760. ret = -EINVAL;
  3761. goto err;
  3762. }
  3763. if (pinctrl_info->pinctrl == NULL) {
  3764. pr_err("%s: pinctrl_info->pinctrl is NULL\n", __func__);
  3765. ret = -EINVAL;
  3766. goto err;
  3767. }
  3768. curr_state = pinctrl_info->curr_state;
  3769. pinctrl_info->curr_state = new_state;
  3770. pr_debug("%s: curr_state = %s new_state = %s\n", __func__,
  3771. pin_states[curr_state], pin_states[pinctrl_info->curr_state]);
  3772. if (curr_state == pinctrl_info->curr_state) {
  3773. pr_debug("%s: Already in same state\n", __func__);
  3774. goto err;
  3775. }
  3776. if (curr_state != STATE_DISABLE &&
  3777. pinctrl_info->curr_state != STATE_DISABLE) {
  3778. pr_debug("%s: state already active cannot switch\n", __func__);
  3779. ret = -EIO;
  3780. goto err;
  3781. }
  3782. switch (pinctrl_info->curr_state) {
  3783. case STATE_MI2S_ACTIVE:
  3784. ret = pinctrl_select_state(pinctrl_info->pinctrl,
  3785. pinctrl_info->mi2s_active);
  3786. if (ret) {
  3787. pr_err("%s: MI2S state select failed with %d\n",
  3788. __func__, ret);
  3789. ret = -EIO;
  3790. goto err;
  3791. }
  3792. break;
  3793. case STATE_TDM_ACTIVE:
  3794. ret = pinctrl_select_state(pinctrl_info->pinctrl,
  3795. pinctrl_info->tdm_active);
  3796. if (ret) {
  3797. pr_err("%s: TDM state select failed with %d\n",
  3798. __func__, ret);
  3799. ret = -EIO;
  3800. goto err;
  3801. }
  3802. break;
  3803. case STATE_DISABLE:
  3804. if (curr_state == STATE_MI2S_ACTIVE) {
  3805. ret = pinctrl_select_state(pinctrl_info->pinctrl,
  3806. pinctrl_info->mi2s_disable);
  3807. } else {
  3808. ret = pinctrl_select_state(pinctrl_info->pinctrl,
  3809. pinctrl_info->tdm_disable);
  3810. }
  3811. if (ret) {
  3812. pr_err("%s: state disable failed with %d\n",
  3813. __func__, ret);
  3814. ret = -EIO;
  3815. goto err;
  3816. }
  3817. break;
  3818. default:
  3819. pr_err("%s: TLMM pin state is invalid\n", __func__);
  3820. return -EINVAL;
  3821. }
  3822. err:
  3823. return ret;
  3824. }
  3825. static void msm_release_pinctrl(struct platform_device *pdev)
  3826. {
  3827. struct snd_soc_card *card = platform_get_drvdata(pdev);
  3828. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  3829. struct msm_pinctrl_info *pinctrl_info = &pdata->pinctrl_info;
  3830. if (pinctrl_info->pinctrl) {
  3831. devm_pinctrl_put(pinctrl_info->pinctrl);
  3832. pinctrl_info->pinctrl = NULL;
  3833. }
  3834. }
  3835. static int msm_get_pinctrl(struct platform_device *pdev)
  3836. {
  3837. struct snd_soc_card *card = platform_get_drvdata(pdev);
  3838. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  3839. struct msm_pinctrl_info *pinctrl_info = NULL;
  3840. struct pinctrl *pinctrl;
  3841. int ret;
  3842. pinctrl_info = &pdata->pinctrl_info;
  3843. if (pinctrl_info == NULL) {
  3844. pr_err("%s: pinctrl_info is NULL\n", __func__);
  3845. return -EINVAL;
  3846. }
  3847. pinctrl = devm_pinctrl_get(&pdev->dev);
  3848. if (IS_ERR_OR_NULL(pinctrl)) {
  3849. pr_err("%s: Unable to get pinctrl handle\n", __func__);
  3850. return -EINVAL;
  3851. }
  3852. pinctrl_info->pinctrl = pinctrl;
  3853. /* get all the states handles from Device Tree */
  3854. pinctrl_info->mi2s_disable = pinctrl_lookup_state(pinctrl,
  3855. "quat-mi2s-sleep");
  3856. if (IS_ERR(pinctrl_info->mi2s_disable)) {
  3857. pr_err("%s: could not get mi2s_disable pinstate\n", __func__);
  3858. goto err;
  3859. }
  3860. pinctrl_info->mi2s_active = pinctrl_lookup_state(pinctrl,
  3861. "quat-mi2s-active");
  3862. if (IS_ERR(pinctrl_info->mi2s_active)) {
  3863. pr_err("%s: could not get mi2s_active pinstate\n", __func__);
  3864. goto err;
  3865. }
  3866. pinctrl_info->tdm_disable = pinctrl_lookup_state(pinctrl,
  3867. "quat-tdm-sleep");
  3868. if (IS_ERR(pinctrl_info->tdm_disable)) {
  3869. pr_err("%s: could not get tdm_disable pinstate\n", __func__);
  3870. goto err;
  3871. }
  3872. pinctrl_info->tdm_active = pinctrl_lookup_state(pinctrl,
  3873. "quat-tdm-active");
  3874. if (IS_ERR(pinctrl_info->tdm_active)) {
  3875. pr_err("%s: could not get tdm_active pinstate\n",
  3876. __func__);
  3877. goto err;
  3878. }
  3879. /* Reset the TLMM pins to a default state */
  3880. ret = pinctrl_select_state(pinctrl_info->pinctrl,
  3881. pinctrl_info->mi2s_disable);
  3882. if (ret != 0) {
  3883. pr_err("%s: Disable TLMM pins failed with %d\n",
  3884. __func__, ret);
  3885. ret = -EIO;
  3886. goto err;
  3887. }
  3888. pinctrl_info->curr_state = STATE_DISABLE;
  3889. return 0;
  3890. err:
  3891. devm_pinctrl_put(pinctrl);
  3892. pinctrl_info->pinctrl = NULL;
  3893. return -EINVAL;
  3894. }
  3895. static int msm_tdm_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
  3896. struct snd_pcm_hw_params *params)
  3897. {
  3898. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  3899. struct snd_interval *rate = hw_param_interval(params,
  3900. SNDRV_PCM_HW_PARAM_RATE);
  3901. struct snd_interval *channels = hw_param_interval(params,
  3902. SNDRV_PCM_HW_PARAM_CHANNELS);
  3903. if (cpu_dai->id == AFE_PORT_ID_QUATERNARY_TDM_RX) {
  3904. channels->min = channels->max =
  3905. tdm_rx_cfg[TDM_QUAT][TDM_0].channels;
  3906. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  3907. tdm_rx_cfg[TDM_QUAT][TDM_0].bit_format);
  3908. rate->min = rate->max =
  3909. tdm_rx_cfg[TDM_QUAT][TDM_0].sample_rate;
  3910. } else if (cpu_dai->id == AFE_PORT_ID_SECONDARY_TDM_RX) {
  3911. channels->min = channels->max =
  3912. tdm_rx_cfg[TDM_SEC][TDM_0].channels;
  3913. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  3914. tdm_rx_cfg[TDM_SEC][TDM_0].bit_format);
  3915. rate->min = rate->max = tdm_rx_cfg[TDM_SEC][TDM_0].sample_rate;
  3916. } else {
  3917. pr_err("%s: dai id 0x%x not supported\n",
  3918. __func__, cpu_dai->id);
  3919. return -EINVAL;
  3920. }
  3921. pr_debug("%s: dai id = 0x%x channels = %d rate = %d format = 0x%x\n",
  3922. __func__, cpu_dai->id, channels->max, rate->max,
  3923. params_format(params));
  3924. return 0;
  3925. }
  3926. static int sdm845_tdm_snd_hw_params(struct snd_pcm_substream *substream,
  3927. struct snd_pcm_hw_params *params)
  3928. {
  3929. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  3930. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  3931. int ret = 0;
  3932. int slot_width = 32;
  3933. int channels, slots;
  3934. unsigned int slot_mask, rate, clk_freq;
  3935. unsigned int slot_offset[8] = {0, 4, 8, 12, 16, 20, 24, 28};
  3936. pr_debug("%s: dai id = 0x%x\n", __func__, cpu_dai->id);
  3937. /* currently only supporting TDM_RX_0 and TDM_TX_0 */
  3938. switch (cpu_dai->id) {
  3939. case AFE_PORT_ID_PRIMARY_TDM_RX:
  3940. slots = tdm_rx_cfg[TDM_PRI][TDM_0].channels;
  3941. break;
  3942. case AFE_PORT_ID_SECONDARY_TDM_RX:
  3943. slots = tdm_rx_cfg[TDM_SEC][TDM_0].channels;
  3944. break;
  3945. case AFE_PORT_ID_TERTIARY_TDM_RX:
  3946. slots = tdm_rx_cfg[TDM_TERT][TDM_0].channels;
  3947. break;
  3948. case AFE_PORT_ID_QUATERNARY_TDM_RX:
  3949. slots = tdm_rx_cfg[TDM_QUAT][TDM_0].channels;
  3950. break;
  3951. case AFE_PORT_ID_PRIMARY_TDM_TX:
  3952. slots = tdm_tx_cfg[TDM_PRI][TDM_0].channels;
  3953. break;
  3954. case AFE_PORT_ID_SECONDARY_TDM_TX:
  3955. slots = tdm_tx_cfg[TDM_SEC][TDM_0].channels;
  3956. break;
  3957. case AFE_PORT_ID_TERTIARY_TDM_TX:
  3958. slots = tdm_tx_cfg[TDM_TERT][TDM_0].channels;
  3959. break;
  3960. case AFE_PORT_ID_QUATERNARY_TDM_TX:
  3961. slots = tdm_tx_cfg[TDM_QUAT][TDM_0].channels;
  3962. break;
  3963. default:
  3964. pr_err("%s: dai id 0x%x not supported\n",
  3965. __func__, cpu_dai->id);
  3966. return -EINVAL;
  3967. }
  3968. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  3969. /*2 slot config - bits 0 and 1 set for the first two slots */
  3970. slot_mask = 0x0000FFFF >> (16-slots);
  3971. channels = slots;
  3972. pr_debug("%s: tdm rx slot_width %d slots %d\n",
  3973. __func__, slot_width, slots);
  3974. ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0, slot_mask,
  3975. slots, slot_width);
  3976. if (ret < 0) {
  3977. pr_err("%s: failed to set tdm rx slot, err:%d\n",
  3978. __func__, ret);
  3979. goto end;
  3980. }
  3981. ret = snd_soc_dai_set_channel_map(cpu_dai,
  3982. 0, NULL, channels, slot_offset);
  3983. if (ret < 0) {
  3984. pr_err("%s: failed to set tdm rx channel map, err:%d\n",
  3985. __func__, ret);
  3986. goto end;
  3987. }
  3988. } else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
  3989. /*2 slot config - bits 0 and 1 set for the first two slots */
  3990. slot_mask = 0x0000FFFF >> (16-slots);
  3991. channels = slots;
  3992. pr_debug("%s: tdm tx slot_width %d slots %d\n",
  3993. __func__, slot_width, slots);
  3994. ret = snd_soc_dai_set_tdm_slot(cpu_dai, slot_mask, 0,
  3995. slots, slot_width);
  3996. if (ret < 0) {
  3997. pr_err("%s: failed to set tdm tx slot, err:%d\n",
  3998. __func__, ret);
  3999. goto end;
  4000. }
  4001. ret = snd_soc_dai_set_channel_map(cpu_dai,
  4002. channels, slot_offset, 0, NULL);
  4003. if (ret < 0) {
  4004. pr_err("%s: failed to set tdm tx channel map, err:%d\n",
  4005. __func__, ret);
  4006. goto end;
  4007. }
  4008. } else {
  4009. ret = -EINVAL;
  4010. pr_err("%s: invalid use case, err:%d\n",
  4011. __func__, ret);
  4012. goto end;
  4013. }
  4014. rate = params_rate(params);
  4015. clk_freq = rate * slot_width * slots;
  4016. ret = snd_soc_dai_set_sysclk(cpu_dai, 0, clk_freq, SND_SOC_CLOCK_OUT);
  4017. if (ret < 0)
  4018. pr_err("%s: failed to set tdm clk, err:%d\n",
  4019. __func__, ret);
  4020. end:
  4021. return ret;
  4022. }
  4023. static int sdm845_tdm_snd_startup(struct snd_pcm_substream *substream)
  4024. {
  4025. int ret = 0;
  4026. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  4027. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  4028. struct snd_soc_card *card = rtd->card;
  4029. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  4030. struct msm_pinctrl_info *pinctrl_info = &pdata->pinctrl_info;
  4031. /* currently only supporting TDM_RX_0 and TDM_TX_0 */
  4032. if ((cpu_dai->id == AFE_PORT_ID_QUATERNARY_TDM_RX) ||
  4033. (cpu_dai->id == AFE_PORT_ID_QUATERNARY_TDM_TX)) {
  4034. ret = msm_set_pinctrl(pinctrl_info, STATE_TDM_ACTIVE);
  4035. if (ret)
  4036. pr_err("%s: TDM TLMM pinctrl set failed with %d\n",
  4037. __func__, ret);
  4038. }
  4039. return ret;
  4040. }
  4041. static void sdm845_tdm_snd_shutdown(struct snd_pcm_substream *substream)
  4042. {
  4043. int ret = 0;
  4044. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  4045. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  4046. struct snd_soc_card *card = rtd->card;
  4047. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  4048. struct msm_pinctrl_info *pinctrl_info = &pdata->pinctrl_info;
  4049. /* currently only supporting TDM_RX_0 and TDM_TX_0 */
  4050. if ((cpu_dai->id == AFE_PORT_ID_QUATERNARY_TDM_RX) ||
  4051. (cpu_dai->id == AFE_PORT_ID_QUATERNARY_TDM_TX)) {
  4052. ret = msm_set_pinctrl(pinctrl_info, STATE_DISABLE);
  4053. if (ret)
  4054. pr_err("%s: TDM TLMM pinctrl set failed with %d\n",
  4055. __func__, ret);
  4056. }
  4057. }
  4058. static struct snd_soc_ops sdm845_tdm_be_ops = {
  4059. .hw_params = sdm845_tdm_snd_hw_params,
  4060. .startup = sdm845_tdm_snd_startup,
  4061. .shutdown = sdm845_tdm_snd_shutdown
  4062. };
  4063. static int msm_fe_qos_prepare(struct snd_pcm_substream *substream)
  4064. {
  4065. cpumask_t mask;
  4066. if (pm_qos_request_active(&substream->latency_pm_qos_req))
  4067. pm_qos_remove_request(&substream->latency_pm_qos_req);
  4068. cpumask_clear(&mask);
  4069. cpumask_set_cpu(1, &mask); /* affine to core 1 */
  4070. cpumask_set_cpu(2, &mask); /* affine to core 2 */
  4071. cpumask_copy(&substream->latency_pm_qos_req.cpus_affine, &mask);
  4072. substream->latency_pm_qos_req.type = PM_QOS_REQ_AFFINE_CORES;
  4073. pm_qos_add_request(&substream->latency_pm_qos_req,
  4074. PM_QOS_CPU_DMA_LATENCY,
  4075. MSM_LL_QOS_VALUE);
  4076. return 0;
  4077. }
  4078. static struct snd_soc_ops msm_fe_qos_ops = {
  4079. .prepare = msm_fe_qos_prepare,
  4080. };
  4081. static int msm_mi2s_snd_startup(struct snd_pcm_substream *substream)
  4082. {
  4083. int ret = 0;
  4084. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  4085. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  4086. int index = cpu_dai->id;
  4087. unsigned int fmt = SND_SOC_DAIFMT_CBS_CFS;
  4088. struct snd_soc_card *card = rtd->card;
  4089. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  4090. struct msm_pinctrl_info *pinctrl_info = &pdata->pinctrl_info;
  4091. int ret_pinctrl = 0;
  4092. dev_dbg(rtd->card->dev,
  4093. "%s: substream = %s stream = %d, dai name %s, dai ID %d\n",
  4094. __func__, substream->name, substream->stream,
  4095. cpu_dai->name, cpu_dai->id);
  4096. if (index < PRIM_MI2S || index > QUAT_MI2S) {
  4097. ret = -EINVAL;
  4098. dev_err(rtd->card->dev,
  4099. "%s: CPU DAI id (%d) out of range\n",
  4100. __func__, cpu_dai->id);
  4101. goto err;
  4102. }
  4103. if (index == QUAT_MI2S) {
  4104. ret_pinctrl = msm_set_pinctrl(pinctrl_info, STATE_MI2S_ACTIVE);
  4105. if (ret_pinctrl)
  4106. pr_err("%s: MI2S TLMM pinctrl set failed with %d\n",
  4107. __func__, ret_pinctrl);
  4108. }
  4109. /*
  4110. * Muxtex protection in case the same MI2S
  4111. * interface using for both TX and RX so
  4112. * that the same clock won't be enable twice.
  4113. */
  4114. mutex_lock(&mi2s_intf_conf[index].lock);
  4115. if (++mi2s_intf_conf[index].ref_cnt == 1) {
  4116. /* Check if msm needs to provide the clock to the interface */
  4117. if (!mi2s_intf_conf[index].msm_is_mi2s_master) {
  4118. mi2s_clk[index].clk_id = mi2s_ebit_clk[index];
  4119. fmt = SND_SOC_DAIFMT_CBM_CFM;
  4120. }
  4121. ret = msm_mi2s_set_sclk(substream, true);
  4122. if (ret < 0) {
  4123. dev_err(rtd->card->dev,
  4124. "%s: afe lpass clock failed to enable MI2S clock, err:%d\n",
  4125. __func__, ret);
  4126. goto clean_up;
  4127. }
  4128. if (mi2s_auxpcm_conf[index].pcm_i2s_sel_vt_addr != NULL) {
  4129. mutex_lock(&mi2s_auxpcm_conf[index].lock);
  4130. iowrite32(0,
  4131. mi2s_auxpcm_conf[index].pcm_i2s_sel_vt_addr);
  4132. mutex_unlock(&mi2s_auxpcm_conf[index].lock);
  4133. } else {
  4134. dev_err(rtd->card->dev,
  4135. "%s lpaif_muxsel_virt_addr is NULL for dai %d\n",
  4136. __func__, index);
  4137. ret = -EINVAL;
  4138. goto clk_off;
  4139. }
  4140. ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
  4141. if (ret < 0) {
  4142. pr_err("%s: set fmt cpu dai failed for MI2S (%d), err:%d\n",
  4143. __func__, index, ret);
  4144. goto clk_off;
  4145. }
  4146. }
  4147. clk_off:
  4148. if (ret < 0)
  4149. msm_mi2s_set_sclk(substream, false);
  4150. clean_up:
  4151. if (ret < 0)
  4152. mi2s_intf_conf[index].ref_cnt--;
  4153. mutex_unlock(&mi2s_intf_conf[index].lock);
  4154. err:
  4155. return ret;
  4156. }
  4157. static void msm_mi2s_snd_shutdown(struct snd_pcm_substream *substream)
  4158. {
  4159. int ret;
  4160. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  4161. int index = rtd->cpu_dai->id;
  4162. struct snd_soc_card *card = rtd->card;
  4163. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  4164. struct msm_pinctrl_info *pinctrl_info = &pdata->pinctrl_info;
  4165. int ret_pinctrl = 0;
  4166. pr_debug("%s(): substream = %s stream = %d\n", __func__,
  4167. substream->name, substream->stream);
  4168. if (index < PRIM_MI2S || index > QUAT_MI2S) {
  4169. pr_err("%s:invalid MI2S DAI(%d)\n", __func__, index);
  4170. return;
  4171. }
  4172. mutex_lock(&mi2s_intf_conf[index].lock);
  4173. if (--mi2s_intf_conf[index].ref_cnt == 0) {
  4174. ret = msm_mi2s_set_sclk(substream, false);
  4175. if (ret < 0)
  4176. pr_err("%s:clock disable failed for MI2S (%d); ret=%d\n",
  4177. __func__, index, ret);
  4178. }
  4179. mutex_unlock(&mi2s_intf_conf[index].lock);
  4180. if (index == QUAT_MI2S) {
  4181. ret_pinctrl = msm_set_pinctrl(pinctrl_info, STATE_DISABLE);
  4182. if (ret_pinctrl)
  4183. pr_err("%s: MI2S TLMM pinctrl set failed with %d\n",
  4184. __func__, ret_pinctrl);
  4185. }
  4186. }
  4187. static struct snd_soc_ops msm_mi2s_be_ops = {
  4188. .startup = msm_mi2s_snd_startup,
  4189. .shutdown = msm_mi2s_snd_shutdown,
  4190. };
  4191. static struct snd_soc_ops msm_aux_pcm_be_ops = {
  4192. .startup = msm_aux_pcm_snd_startup,
  4193. .shutdown = msm_aux_pcm_snd_shutdown,
  4194. };
  4195. static struct snd_soc_ops msm_be_ops = {
  4196. .hw_params = msm_snd_hw_params,
  4197. };
  4198. static struct snd_soc_ops msm_slimbus_2_be_ops = {
  4199. .hw_params = msm_slimbus_2_hw_params,
  4200. };
  4201. static struct snd_soc_ops msm_wcn_ops = {
  4202. .hw_params = msm_wcn_hw_params,
  4203. };
  4204. /* Digital audio interface glue - connects codec <---> CPU */
  4205. static struct snd_soc_dai_link msm_common_dai_links[] = {
  4206. /* FrontEnd DAI Links */
  4207. {
  4208. .name = MSM_DAILINK_NAME(Media1),
  4209. .stream_name = "MultiMedia1",
  4210. .cpu_dai_name = "MultiMedia1",
  4211. .platform_name = "msm-pcm-dsp.0",
  4212. .dynamic = 1,
  4213. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  4214. .dpcm_playback = 1,
  4215. .dpcm_capture = 1,
  4216. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4217. SND_SOC_DPCM_TRIGGER_POST},
  4218. .codec_dai_name = "snd-soc-dummy-dai",
  4219. .codec_name = "snd-soc-dummy",
  4220. .ignore_suspend = 1,
  4221. /* this dainlink has playback support */
  4222. .ignore_pmdown_time = 1,
  4223. .id = MSM_FRONTEND_DAI_MULTIMEDIA1
  4224. },
  4225. {
  4226. .name = MSM_DAILINK_NAME(Media2),
  4227. .stream_name = "MultiMedia2",
  4228. .cpu_dai_name = "MultiMedia2",
  4229. .platform_name = "msm-pcm-dsp.0",
  4230. .dynamic = 1,
  4231. .dpcm_playback = 1,
  4232. .dpcm_capture = 1,
  4233. .codec_dai_name = "snd-soc-dummy-dai",
  4234. .codec_name = "snd-soc-dummy",
  4235. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4236. SND_SOC_DPCM_TRIGGER_POST},
  4237. .ignore_suspend = 1,
  4238. /* this dainlink has playback support */
  4239. .ignore_pmdown_time = 1,
  4240. .id = MSM_FRONTEND_DAI_MULTIMEDIA2,
  4241. },
  4242. {
  4243. .name = "VoiceMMode1",
  4244. .stream_name = "VoiceMMode1",
  4245. .cpu_dai_name = "VoiceMMode1",
  4246. .platform_name = "msm-pcm-voice",
  4247. .dynamic = 1,
  4248. .dpcm_playback = 1,
  4249. .dpcm_capture = 1,
  4250. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4251. SND_SOC_DPCM_TRIGGER_POST},
  4252. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4253. .ignore_suspend = 1,
  4254. .ignore_pmdown_time = 1,
  4255. .codec_dai_name = "snd-soc-dummy-dai",
  4256. .codec_name = "snd-soc-dummy",
  4257. .id = MSM_FRONTEND_DAI_VOICEMMODE1,
  4258. },
  4259. {
  4260. .name = "MSM VoIP",
  4261. .stream_name = "VoIP",
  4262. .cpu_dai_name = "VoIP",
  4263. .platform_name = "msm-voip-dsp",
  4264. .dynamic = 1,
  4265. .dpcm_playback = 1,
  4266. .dpcm_capture = 1,
  4267. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4268. SND_SOC_DPCM_TRIGGER_POST},
  4269. .codec_dai_name = "snd-soc-dummy-dai",
  4270. .codec_name = "snd-soc-dummy",
  4271. .ignore_suspend = 1,
  4272. /* this dainlink has playback support */
  4273. .ignore_pmdown_time = 1,
  4274. .id = MSM_FRONTEND_DAI_VOIP,
  4275. },
  4276. {
  4277. .name = MSM_DAILINK_NAME(ULL),
  4278. .stream_name = "MultiMedia3",
  4279. .cpu_dai_name = "MultiMedia3",
  4280. .platform_name = "msm-pcm-dsp.2",
  4281. .dynamic = 1,
  4282. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  4283. .dpcm_playback = 1,
  4284. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4285. SND_SOC_DPCM_TRIGGER_POST},
  4286. .codec_dai_name = "snd-soc-dummy-dai",
  4287. .codec_name = "snd-soc-dummy",
  4288. .ignore_suspend = 1,
  4289. /* this dainlink has playback support */
  4290. .ignore_pmdown_time = 1,
  4291. .id = MSM_FRONTEND_DAI_MULTIMEDIA3,
  4292. },
  4293. /* Hostless PCM purpose */
  4294. {
  4295. .name = "SLIMBUS_0 Hostless",
  4296. .stream_name = "SLIMBUS_0 Hostless",
  4297. .cpu_dai_name = "SLIMBUS0_HOSTLESS",
  4298. .platform_name = "msm-pcm-hostless",
  4299. .dynamic = 1,
  4300. .dpcm_playback = 1,
  4301. .dpcm_capture = 1,
  4302. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4303. SND_SOC_DPCM_TRIGGER_POST},
  4304. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4305. .ignore_suspend = 1,
  4306. /* this dailink has playback support */
  4307. .ignore_pmdown_time = 1,
  4308. .codec_dai_name = "snd-soc-dummy-dai",
  4309. .codec_name = "snd-soc-dummy",
  4310. },
  4311. {
  4312. .name = "MSM AFE-PCM RX",
  4313. .stream_name = "AFE-PROXY RX",
  4314. .cpu_dai_name = "msm-dai-q6-dev.241",
  4315. .codec_name = "msm-stub-codec.1",
  4316. .codec_dai_name = "msm-stub-rx",
  4317. .platform_name = "msm-pcm-afe",
  4318. .dpcm_playback = 1,
  4319. .ignore_suspend = 1,
  4320. /* this dainlink has playback support */
  4321. .ignore_pmdown_time = 1,
  4322. },
  4323. {
  4324. .name = "MSM AFE-PCM TX",
  4325. .stream_name = "AFE-PROXY TX",
  4326. .cpu_dai_name = "msm-dai-q6-dev.240",
  4327. .codec_name = "msm-stub-codec.1",
  4328. .codec_dai_name = "msm-stub-tx",
  4329. .platform_name = "msm-pcm-afe",
  4330. .dpcm_capture = 1,
  4331. .ignore_suspend = 1,
  4332. },
  4333. {
  4334. .name = MSM_DAILINK_NAME(Compress1),
  4335. .stream_name = "Compress1",
  4336. .cpu_dai_name = "MultiMedia4",
  4337. .platform_name = "msm-compress-dsp",
  4338. .dynamic = 1,
  4339. .async_ops = ASYNC_DPCM_SND_SOC_HW_PARAMS,
  4340. .dpcm_playback = 1,
  4341. .dpcm_capture = 1,
  4342. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4343. SND_SOC_DPCM_TRIGGER_POST},
  4344. .codec_dai_name = "snd-soc-dummy-dai",
  4345. .codec_name = "snd-soc-dummy",
  4346. .ignore_suspend = 1,
  4347. .ignore_pmdown_time = 1,
  4348. /* this dainlink has playback support */
  4349. .id = MSM_FRONTEND_DAI_MULTIMEDIA4,
  4350. },
  4351. {
  4352. .name = "AUXPCM Hostless",
  4353. .stream_name = "AUXPCM Hostless",
  4354. .cpu_dai_name = "AUXPCM_HOSTLESS",
  4355. .platform_name = "msm-pcm-hostless",
  4356. .dynamic = 1,
  4357. .dpcm_playback = 1,
  4358. .dpcm_capture = 1,
  4359. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4360. SND_SOC_DPCM_TRIGGER_POST},
  4361. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4362. .ignore_suspend = 1,
  4363. /* this dainlink has playback support */
  4364. .ignore_pmdown_time = 1,
  4365. .codec_dai_name = "snd-soc-dummy-dai",
  4366. .codec_name = "snd-soc-dummy",
  4367. },
  4368. {
  4369. .name = "SLIMBUS_1 Hostless",
  4370. .stream_name = "SLIMBUS_1 Hostless",
  4371. .cpu_dai_name = "SLIMBUS1_HOSTLESS",
  4372. .platform_name = "msm-pcm-hostless",
  4373. .dynamic = 1,
  4374. .dpcm_playback = 1,
  4375. .dpcm_capture = 1,
  4376. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4377. SND_SOC_DPCM_TRIGGER_POST},
  4378. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4379. .ignore_suspend = 1,
  4380. /* this dailink has playback support */
  4381. .ignore_pmdown_time = 1,
  4382. .codec_dai_name = "snd-soc-dummy-dai",
  4383. .codec_name = "snd-soc-dummy",
  4384. },
  4385. {
  4386. .name = "SLIMBUS_3 Hostless",
  4387. .stream_name = "SLIMBUS_3 Hostless",
  4388. .cpu_dai_name = "SLIMBUS3_HOSTLESS",
  4389. .platform_name = "msm-pcm-hostless",
  4390. .dynamic = 1,
  4391. .dpcm_playback = 1,
  4392. .dpcm_capture = 1,
  4393. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4394. SND_SOC_DPCM_TRIGGER_POST},
  4395. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4396. .ignore_suspend = 1,
  4397. /* this dailink has playback support */
  4398. .ignore_pmdown_time = 1,
  4399. .codec_dai_name = "snd-soc-dummy-dai",
  4400. .codec_name = "snd-soc-dummy",
  4401. },
  4402. {
  4403. .name = "SLIMBUS_4 Hostless",
  4404. .stream_name = "SLIMBUS_4 Hostless",
  4405. .cpu_dai_name = "SLIMBUS4_HOSTLESS",
  4406. .platform_name = "msm-pcm-hostless",
  4407. .dynamic = 1,
  4408. .dpcm_playback = 1,
  4409. .dpcm_capture = 1,
  4410. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4411. SND_SOC_DPCM_TRIGGER_POST},
  4412. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4413. .ignore_suspend = 1,
  4414. /* this dailink has playback support */
  4415. .ignore_pmdown_time = 1,
  4416. .codec_dai_name = "snd-soc-dummy-dai",
  4417. .codec_name = "snd-soc-dummy",
  4418. },
  4419. {
  4420. .name = MSM_DAILINK_NAME(LowLatency),
  4421. .stream_name = "MultiMedia5",
  4422. .cpu_dai_name = "MultiMedia5",
  4423. .platform_name = "msm-pcm-dsp.1",
  4424. .dynamic = 1,
  4425. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  4426. .dpcm_playback = 1,
  4427. .dpcm_capture = 1,
  4428. .codec_dai_name = "snd-soc-dummy-dai",
  4429. .codec_name = "snd-soc-dummy",
  4430. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4431. SND_SOC_DPCM_TRIGGER_POST},
  4432. .ignore_suspend = 1,
  4433. /* this dainlink has playback support */
  4434. .ignore_pmdown_time = 1,
  4435. .id = MSM_FRONTEND_DAI_MULTIMEDIA5,
  4436. .ops = &msm_fe_qos_ops,
  4437. },
  4438. {
  4439. .name = "Listen 1 Audio Service",
  4440. .stream_name = "Listen 1 Audio Service",
  4441. .cpu_dai_name = "LSM1",
  4442. .platform_name = "msm-lsm-client",
  4443. .dynamic = 1,
  4444. .dpcm_capture = 1,
  4445. .trigger = { SND_SOC_DPCM_TRIGGER_POST,
  4446. SND_SOC_DPCM_TRIGGER_POST },
  4447. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4448. .ignore_suspend = 1,
  4449. .ignore_pmdown_time = 1,
  4450. .codec_dai_name = "snd-soc-dummy-dai",
  4451. .codec_name = "snd-soc-dummy",
  4452. .id = MSM_FRONTEND_DAI_LSM1,
  4453. },
  4454. /* Multiple Tunnel instances */
  4455. {
  4456. .name = MSM_DAILINK_NAME(Compress2),
  4457. .stream_name = "Compress2",
  4458. .cpu_dai_name = "MultiMedia7",
  4459. .platform_name = "msm-compress-dsp",
  4460. .dynamic = 1,
  4461. .dpcm_playback = 1,
  4462. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4463. SND_SOC_DPCM_TRIGGER_POST},
  4464. .codec_dai_name = "snd-soc-dummy-dai",
  4465. .codec_name = "snd-soc-dummy",
  4466. .ignore_suspend = 1,
  4467. .ignore_pmdown_time = 1,
  4468. /* this dainlink has playback support */
  4469. .id = MSM_FRONTEND_DAI_MULTIMEDIA7,
  4470. },
  4471. {
  4472. .name = MSM_DAILINK_NAME(MultiMedia10),
  4473. .stream_name = "MultiMedia10",
  4474. .cpu_dai_name = "MultiMedia10",
  4475. .platform_name = "msm-pcm-dsp.1",
  4476. .dynamic = 1,
  4477. .dpcm_playback = 1,
  4478. .dpcm_capture = 1,
  4479. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4480. SND_SOC_DPCM_TRIGGER_POST},
  4481. .codec_dai_name = "snd-soc-dummy-dai",
  4482. .codec_name = "snd-soc-dummy",
  4483. .ignore_suspend = 1,
  4484. .ignore_pmdown_time = 1,
  4485. /* this dainlink has playback support */
  4486. .id = MSM_FRONTEND_DAI_MULTIMEDIA10,
  4487. },
  4488. {
  4489. .name = MSM_DAILINK_NAME(ULL_NOIRQ),
  4490. .stream_name = "MM_NOIRQ",
  4491. .cpu_dai_name = "MultiMedia8",
  4492. .platform_name = "msm-pcm-dsp-noirq",
  4493. .dynamic = 1,
  4494. .dpcm_playback = 1,
  4495. .dpcm_capture = 1,
  4496. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4497. SND_SOC_DPCM_TRIGGER_POST},
  4498. .codec_dai_name = "snd-soc-dummy-dai",
  4499. .codec_name = "snd-soc-dummy",
  4500. .ignore_suspend = 1,
  4501. .ignore_pmdown_time = 1,
  4502. /* this dainlink has playback support */
  4503. .id = MSM_FRONTEND_DAI_MULTIMEDIA8,
  4504. .ops = &msm_fe_qos_ops,
  4505. },
  4506. /* HDMI Hostless */
  4507. {
  4508. .name = "HDMI_RX_HOSTLESS",
  4509. .stream_name = "HDMI_RX_HOSTLESS",
  4510. .cpu_dai_name = "HDMI_HOSTLESS",
  4511. .platform_name = "msm-pcm-hostless",
  4512. .dynamic = 1,
  4513. .dpcm_playback = 1,
  4514. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4515. SND_SOC_DPCM_TRIGGER_POST},
  4516. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4517. .ignore_suspend = 1,
  4518. .ignore_pmdown_time = 1,
  4519. .codec_dai_name = "snd-soc-dummy-dai",
  4520. .codec_name = "snd-soc-dummy",
  4521. },
  4522. {
  4523. .name = "VoiceMMode2",
  4524. .stream_name = "VoiceMMode2",
  4525. .cpu_dai_name = "VoiceMMode2",
  4526. .platform_name = "msm-pcm-voice",
  4527. .dynamic = 1,
  4528. .dpcm_playback = 1,
  4529. .dpcm_capture = 1,
  4530. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4531. SND_SOC_DPCM_TRIGGER_POST},
  4532. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4533. .ignore_suspend = 1,
  4534. .ignore_pmdown_time = 1,
  4535. .codec_dai_name = "snd-soc-dummy-dai",
  4536. .codec_name = "snd-soc-dummy",
  4537. .id = MSM_FRONTEND_DAI_VOICEMMODE2,
  4538. },
  4539. /* LSM FE */
  4540. {
  4541. .name = "Listen 2 Audio Service",
  4542. .stream_name = "Listen 2 Audio Service",
  4543. .cpu_dai_name = "LSM2",
  4544. .platform_name = "msm-lsm-client",
  4545. .dynamic = 1,
  4546. .dpcm_capture = 1,
  4547. .trigger = { SND_SOC_DPCM_TRIGGER_POST,
  4548. SND_SOC_DPCM_TRIGGER_POST },
  4549. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4550. .ignore_suspend = 1,
  4551. .ignore_pmdown_time = 1,
  4552. .codec_dai_name = "snd-soc-dummy-dai",
  4553. .codec_name = "snd-soc-dummy",
  4554. .id = MSM_FRONTEND_DAI_LSM2,
  4555. },
  4556. {
  4557. .name = "Listen 3 Audio Service",
  4558. .stream_name = "Listen 3 Audio Service",
  4559. .cpu_dai_name = "LSM3",
  4560. .platform_name = "msm-lsm-client",
  4561. .dynamic = 1,
  4562. .dpcm_capture = 1,
  4563. .trigger = { SND_SOC_DPCM_TRIGGER_POST,
  4564. SND_SOC_DPCM_TRIGGER_POST },
  4565. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4566. .ignore_suspend = 1,
  4567. .ignore_pmdown_time = 1,
  4568. .codec_dai_name = "snd-soc-dummy-dai",
  4569. .codec_name = "snd-soc-dummy",
  4570. .id = MSM_FRONTEND_DAI_LSM3,
  4571. },
  4572. {
  4573. .name = "Listen 4 Audio Service",
  4574. .stream_name = "Listen 4 Audio Service",
  4575. .cpu_dai_name = "LSM4",
  4576. .platform_name = "msm-lsm-client",
  4577. .dynamic = 1,
  4578. .dpcm_capture = 1,
  4579. .trigger = { SND_SOC_DPCM_TRIGGER_POST,
  4580. SND_SOC_DPCM_TRIGGER_POST },
  4581. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4582. .ignore_suspend = 1,
  4583. .ignore_pmdown_time = 1,
  4584. .codec_dai_name = "snd-soc-dummy-dai",
  4585. .codec_name = "snd-soc-dummy",
  4586. .id = MSM_FRONTEND_DAI_LSM4,
  4587. },
  4588. {
  4589. .name = "Listen 5 Audio Service",
  4590. .stream_name = "Listen 5 Audio Service",
  4591. .cpu_dai_name = "LSM5",
  4592. .platform_name = "msm-lsm-client",
  4593. .dynamic = 1,
  4594. .dpcm_capture = 1,
  4595. .trigger = { SND_SOC_DPCM_TRIGGER_POST,
  4596. SND_SOC_DPCM_TRIGGER_POST },
  4597. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4598. .ignore_suspend = 1,
  4599. .ignore_pmdown_time = 1,
  4600. .codec_dai_name = "snd-soc-dummy-dai",
  4601. .codec_name = "snd-soc-dummy",
  4602. .id = MSM_FRONTEND_DAI_LSM5,
  4603. },
  4604. {
  4605. .name = "Listen 6 Audio Service",
  4606. .stream_name = "Listen 6 Audio Service",
  4607. .cpu_dai_name = "LSM6",
  4608. .platform_name = "msm-lsm-client",
  4609. .dynamic = 1,
  4610. .dpcm_capture = 1,
  4611. .trigger = { SND_SOC_DPCM_TRIGGER_POST,
  4612. SND_SOC_DPCM_TRIGGER_POST },
  4613. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4614. .ignore_suspend = 1,
  4615. .ignore_pmdown_time = 1,
  4616. .codec_dai_name = "snd-soc-dummy-dai",
  4617. .codec_name = "snd-soc-dummy",
  4618. .id = MSM_FRONTEND_DAI_LSM6,
  4619. },
  4620. {
  4621. .name = "Listen 7 Audio Service",
  4622. .stream_name = "Listen 7 Audio Service",
  4623. .cpu_dai_name = "LSM7",
  4624. .platform_name = "msm-lsm-client",
  4625. .dynamic = 1,
  4626. .dpcm_capture = 1,
  4627. .trigger = { SND_SOC_DPCM_TRIGGER_POST,
  4628. SND_SOC_DPCM_TRIGGER_POST },
  4629. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4630. .ignore_suspend = 1,
  4631. .ignore_pmdown_time = 1,
  4632. .codec_dai_name = "snd-soc-dummy-dai",
  4633. .codec_name = "snd-soc-dummy",
  4634. .id = MSM_FRONTEND_DAI_LSM7,
  4635. },
  4636. {
  4637. .name = "Listen 8 Audio Service",
  4638. .stream_name = "Listen 8 Audio Service",
  4639. .cpu_dai_name = "LSM8",
  4640. .platform_name = "msm-lsm-client",
  4641. .dynamic = 1,
  4642. .dpcm_capture = 1,
  4643. .trigger = { SND_SOC_DPCM_TRIGGER_POST,
  4644. SND_SOC_DPCM_TRIGGER_POST },
  4645. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4646. .ignore_suspend = 1,
  4647. .ignore_pmdown_time = 1,
  4648. .codec_dai_name = "snd-soc-dummy-dai",
  4649. .codec_name = "snd-soc-dummy",
  4650. .id = MSM_FRONTEND_DAI_LSM8,
  4651. },
  4652. {
  4653. .name = MSM_DAILINK_NAME(Media9),
  4654. .stream_name = "MultiMedia9",
  4655. .cpu_dai_name = "MultiMedia9",
  4656. .platform_name = "msm-pcm-dsp.0",
  4657. .dynamic = 1,
  4658. .dpcm_playback = 1,
  4659. .dpcm_capture = 1,
  4660. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4661. SND_SOC_DPCM_TRIGGER_POST},
  4662. .codec_dai_name = "snd-soc-dummy-dai",
  4663. .codec_name = "snd-soc-dummy",
  4664. .ignore_suspend = 1,
  4665. /* this dainlink has playback support */
  4666. .ignore_pmdown_time = 1,
  4667. .id = MSM_FRONTEND_DAI_MULTIMEDIA9,
  4668. },
  4669. {
  4670. .name = MSM_DAILINK_NAME(Compress4),
  4671. .stream_name = "Compress4",
  4672. .cpu_dai_name = "MultiMedia11",
  4673. .platform_name = "msm-compress-dsp",
  4674. .dynamic = 1,
  4675. .dpcm_playback = 1,
  4676. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4677. SND_SOC_DPCM_TRIGGER_POST},
  4678. .codec_dai_name = "snd-soc-dummy-dai",
  4679. .codec_name = "snd-soc-dummy",
  4680. .ignore_suspend = 1,
  4681. .ignore_pmdown_time = 1,
  4682. /* this dainlink has playback support */
  4683. .id = MSM_FRONTEND_DAI_MULTIMEDIA11,
  4684. },
  4685. {
  4686. .name = MSM_DAILINK_NAME(Compress5),
  4687. .stream_name = "Compress5",
  4688. .cpu_dai_name = "MultiMedia12",
  4689. .platform_name = "msm-compress-dsp",
  4690. .dynamic = 1,
  4691. .dpcm_playback = 1,
  4692. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4693. SND_SOC_DPCM_TRIGGER_POST},
  4694. .codec_dai_name = "snd-soc-dummy-dai",
  4695. .codec_name = "snd-soc-dummy",
  4696. .ignore_suspend = 1,
  4697. .ignore_pmdown_time = 1,
  4698. /* this dainlink has playback support */
  4699. .id = MSM_FRONTEND_DAI_MULTIMEDIA12,
  4700. },
  4701. {
  4702. .name = MSM_DAILINK_NAME(Compress6),
  4703. .stream_name = "Compress6",
  4704. .cpu_dai_name = "MultiMedia13",
  4705. .platform_name = "msm-compress-dsp",
  4706. .dynamic = 1,
  4707. .dpcm_playback = 1,
  4708. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4709. SND_SOC_DPCM_TRIGGER_POST},
  4710. .codec_dai_name = "snd-soc-dummy-dai",
  4711. .codec_name = "snd-soc-dummy",
  4712. .ignore_suspend = 1,
  4713. .ignore_pmdown_time = 1,
  4714. /* this dainlink has playback support */
  4715. .id = MSM_FRONTEND_DAI_MULTIMEDIA13,
  4716. },
  4717. {
  4718. .name = MSM_DAILINK_NAME(Compress7),
  4719. .stream_name = "Compress7",
  4720. .cpu_dai_name = "MultiMedia14",
  4721. .platform_name = "msm-compress-dsp",
  4722. .dynamic = 1,
  4723. .dpcm_playback = 1,
  4724. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4725. SND_SOC_DPCM_TRIGGER_POST},
  4726. .codec_dai_name = "snd-soc-dummy-dai",
  4727. .codec_name = "snd-soc-dummy",
  4728. .ignore_suspend = 1,
  4729. .ignore_pmdown_time = 1,
  4730. /* this dainlink has playback support */
  4731. .id = MSM_FRONTEND_DAI_MULTIMEDIA14,
  4732. },
  4733. {
  4734. .name = MSM_DAILINK_NAME(Compress8),
  4735. .stream_name = "Compress8",
  4736. .cpu_dai_name = "MultiMedia15",
  4737. .platform_name = "msm-compress-dsp",
  4738. .dynamic = 1,
  4739. .dpcm_playback = 1,
  4740. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4741. SND_SOC_DPCM_TRIGGER_POST},
  4742. .codec_dai_name = "snd-soc-dummy-dai",
  4743. .codec_name = "snd-soc-dummy",
  4744. .ignore_suspend = 1,
  4745. .ignore_pmdown_time = 1,
  4746. /* this dainlink has playback support */
  4747. .id = MSM_FRONTEND_DAI_MULTIMEDIA15,
  4748. },
  4749. {
  4750. .name = MSM_DAILINK_NAME(ULL_NOIRQ_2),
  4751. .stream_name = "MM_NOIRQ_2",
  4752. .cpu_dai_name = "MultiMedia16",
  4753. .platform_name = "msm-pcm-dsp-noirq",
  4754. .dynamic = 1,
  4755. .dpcm_playback = 1,
  4756. .dpcm_capture = 1,
  4757. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4758. SND_SOC_DPCM_TRIGGER_POST},
  4759. .codec_dai_name = "snd-soc-dummy-dai",
  4760. .codec_name = "snd-soc-dummy",
  4761. .ignore_suspend = 1,
  4762. .ignore_pmdown_time = 1,
  4763. /* this dainlink has playback support */
  4764. .id = MSM_FRONTEND_DAI_MULTIMEDIA16,
  4765. },
  4766. {
  4767. .name = "SLIMBUS_8 Hostless",
  4768. .stream_name = "SLIMBUS8_HOSTLESS Capture",
  4769. .cpu_dai_name = "SLIMBUS8_HOSTLESS",
  4770. .platform_name = "msm-pcm-hostless",
  4771. .dynamic = 1,
  4772. .dpcm_capture = 1,
  4773. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4774. SND_SOC_DPCM_TRIGGER_POST},
  4775. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4776. .ignore_suspend = 1,
  4777. .ignore_pmdown_time = 1,
  4778. .codec_dai_name = "snd-soc-dummy-dai",
  4779. .codec_name = "snd-soc-dummy",
  4780. },
  4781. };
  4782. static struct snd_soc_dai_link msm_tavil_fe_dai_links[] = {
  4783. {
  4784. .name = LPASS_BE_SLIMBUS_4_TX,
  4785. .stream_name = "Slimbus4 Capture",
  4786. .cpu_dai_name = "msm-dai-q6-dev.16393",
  4787. .platform_name = "msm-pcm-hostless",
  4788. .codec_name = "tavil_codec",
  4789. .codec_dai_name = "tavil_vifeedback",
  4790. .id = MSM_BACKEND_DAI_SLIMBUS_4_TX,
  4791. .be_hw_params_fixup = msm_be_hw_params_fixup,
  4792. .ops = &msm_be_ops,
  4793. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4794. .ignore_suspend = 1,
  4795. },
  4796. /* Ultrasound RX DAI Link */
  4797. {
  4798. .name = "SLIMBUS_2 Hostless Playback",
  4799. .stream_name = "SLIMBUS_2 Hostless Playback",
  4800. .cpu_dai_name = "msm-dai-q6-dev.16388",
  4801. .platform_name = "msm-pcm-hostless",
  4802. .codec_name = "tavil_codec",
  4803. .codec_dai_name = "tavil_rx2",
  4804. .ignore_suspend = 1,
  4805. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4806. .ops = &msm_slimbus_2_be_ops,
  4807. },
  4808. /* Ultrasound TX DAI Link */
  4809. {
  4810. .name = "SLIMBUS_2 Hostless Capture",
  4811. .stream_name = "SLIMBUS_2 Hostless Capture",
  4812. .cpu_dai_name = "msm-dai-q6-dev.16389",
  4813. .platform_name = "msm-pcm-hostless",
  4814. .codec_name = "tavil_codec",
  4815. .codec_dai_name = "tavil_tx2",
  4816. .ignore_suspend = 1,
  4817. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4818. .ops = &msm_slimbus_2_be_ops,
  4819. },
  4820. };
  4821. static struct snd_soc_dai_link msm_common_misc_fe_dai_links[] = {
  4822. {
  4823. .name = MSM_DAILINK_NAME(ASM Loopback),
  4824. .stream_name = "MultiMedia6",
  4825. .cpu_dai_name = "MultiMedia6",
  4826. .platform_name = "msm-pcm-loopback",
  4827. .dynamic = 1,
  4828. .dpcm_playback = 1,
  4829. .dpcm_capture = 1,
  4830. .codec_dai_name = "snd-soc-dummy-dai",
  4831. .codec_name = "snd-soc-dummy",
  4832. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4833. SND_SOC_DPCM_TRIGGER_POST},
  4834. .ignore_suspend = 1,
  4835. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4836. .ignore_pmdown_time = 1,
  4837. .id = MSM_FRONTEND_DAI_MULTIMEDIA6,
  4838. },
  4839. {
  4840. .name = "USB Audio Hostless",
  4841. .stream_name = "USB Audio Hostless",
  4842. .cpu_dai_name = "USBAUDIO_HOSTLESS",
  4843. .platform_name = "msm-pcm-hostless",
  4844. .dynamic = 1,
  4845. .dpcm_playback = 1,
  4846. .dpcm_capture = 1,
  4847. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  4848. SND_SOC_DPCM_TRIGGER_POST},
  4849. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  4850. .ignore_suspend = 1,
  4851. .ignore_pmdown_time = 1,
  4852. .codec_dai_name = "snd-soc-dummy-dai",
  4853. .codec_name = "snd-soc-dummy",
  4854. },
  4855. };
  4856. static struct snd_soc_dai_link msm_common_be_dai_links[] = {
  4857. /* Backend AFE DAI Links */
  4858. {
  4859. .name = LPASS_BE_AFE_PCM_RX,
  4860. .stream_name = "AFE Playback",
  4861. .cpu_dai_name = "msm-dai-q6-dev.224",
  4862. .platform_name = "msm-pcm-routing",
  4863. .codec_name = "msm-stub-codec.1",
  4864. .codec_dai_name = "msm-stub-rx",
  4865. .no_pcm = 1,
  4866. .dpcm_playback = 1,
  4867. .id = MSM_BACKEND_DAI_AFE_PCM_RX,
  4868. .be_hw_params_fixup = msm_be_hw_params_fixup,
  4869. /* this dainlink has playback support */
  4870. .ignore_pmdown_time = 1,
  4871. .ignore_suspend = 1,
  4872. },
  4873. {
  4874. .name = LPASS_BE_AFE_PCM_TX,
  4875. .stream_name = "AFE Capture",
  4876. .cpu_dai_name = "msm-dai-q6-dev.225",
  4877. .platform_name = "msm-pcm-routing",
  4878. .codec_name = "msm-stub-codec.1",
  4879. .codec_dai_name = "msm-stub-tx",
  4880. .no_pcm = 1,
  4881. .dpcm_capture = 1,
  4882. .id = MSM_BACKEND_DAI_AFE_PCM_TX,
  4883. .be_hw_params_fixup = msm_be_hw_params_fixup,
  4884. .ignore_suspend = 1,
  4885. },
  4886. /* Incall Record Uplink BACK END DAI Link */
  4887. {
  4888. .name = LPASS_BE_INCALL_RECORD_TX,
  4889. .stream_name = "Voice Uplink Capture",
  4890. .cpu_dai_name = "msm-dai-q6-dev.32772",
  4891. .platform_name = "msm-pcm-routing",
  4892. .codec_name = "msm-stub-codec.1",
  4893. .codec_dai_name = "msm-stub-tx",
  4894. .no_pcm = 1,
  4895. .dpcm_capture = 1,
  4896. .id = MSM_BACKEND_DAI_INCALL_RECORD_TX,
  4897. .be_hw_params_fixup = msm_be_hw_params_fixup,
  4898. .ignore_suspend = 1,
  4899. },
  4900. /* Incall Record Downlink BACK END DAI Link */
  4901. {
  4902. .name = LPASS_BE_INCALL_RECORD_RX,
  4903. .stream_name = "Voice Downlink Capture",
  4904. .cpu_dai_name = "msm-dai-q6-dev.32771",
  4905. .platform_name = "msm-pcm-routing",
  4906. .codec_name = "msm-stub-codec.1",
  4907. .codec_dai_name = "msm-stub-tx",
  4908. .no_pcm = 1,
  4909. .dpcm_capture = 1,
  4910. .id = MSM_BACKEND_DAI_INCALL_RECORD_RX,
  4911. .be_hw_params_fixup = msm_be_hw_params_fixup,
  4912. .ignore_suspend = 1,
  4913. },
  4914. /* Incall Music BACK END DAI Link */
  4915. {
  4916. .name = LPASS_BE_VOICE_PLAYBACK_TX,
  4917. .stream_name = "Voice Farend Playback",
  4918. .cpu_dai_name = "msm-dai-q6-dev.32773",
  4919. .platform_name = "msm-pcm-routing",
  4920. .codec_name = "msm-stub-codec.1",
  4921. .codec_dai_name = "msm-stub-rx",
  4922. .no_pcm = 1,
  4923. .dpcm_playback = 1,
  4924. .id = MSM_BACKEND_DAI_VOICE_PLAYBACK_TX,
  4925. .be_hw_params_fixup = msm_be_hw_params_fixup,
  4926. .ignore_suspend = 1,
  4927. },
  4928. /* Incall Music 2 BACK END DAI Link */
  4929. {
  4930. .name = LPASS_BE_VOICE2_PLAYBACK_TX,
  4931. .stream_name = "Voice2 Farend Playback",
  4932. .cpu_dai_name = "msm-dai-q6-dev.32770",
  4933. .platform_name = "msm-pcm-routing",
  4934. .codec_name = "msm-stub-codec.1",
  4935. .codec_dai_name = "msm-stub-rx",
  4936. .no_pcm = 1,
  4937. .dpcm_playback = 1,
  4938. .id = MSM_BACKEND_DAI_VOICE2_PLAYBACK_TX,
  4939. .be_hw_params_fixup = msm_be_hw_params_fixup,
  4940. .ignore_suspend = 1,
  4941. },
  4942. {
  4943. .name = LPASS_BE_USB_AUDIO_RX,
  4944. .stream_name = "USB Audio Playback",
  4945. .cpu_dai_name = "msm-dai-q6-dev.28672",
  4946. .platform_name = "msm-pcm-routing",
  4947. .codec_name = "msm-stub-codec.1",
  4948. .codec_dai_name = "msm-stub-rx",
  4949. .no_pcm = 1,
  4950. .dpcm_playback = 1,
  4951. .id = MSM_BACKEND_DAI_USB_RX,
  4952. .be_hw_params_fixup = msm_be_hw_params_fixup,
  4953. .ignore_pmdown_time = 1,
  4954. .ignore_suspend = 1,
  4955. },
  4956. {
  4957. .name = LPASS_BE_USB_AUDIO_TX,
  4958. .stream_name = "USB Audio Capture",
  4959. .cpu_dai_name = "msm-dai-q6-dev.28673",
  4960. .platform_name = "msm-pcm-routing",
  4961. .codec_name = "msm-stub-codec.1",
  4962. .codec_dai_name = "msm-stub-tx",
  4963. .no_pcm = 1,
  4964. .dpcm_capture = 1,
  4965. .id = MSM_BACKEND_DAI_USB_TX,
  4966. .be_hw_params_fixup = msm_be_hw_params_fixup,
  4967. .ignore_suspend = 1,
  4968. },
  4969. {
  4970. .name = LPASS_BE_PRI_TDM_RX_0,
  4971. .stream_name = "Primary TDM0 Playback",
  4972. .cpu_dai_name = "msm-dai-q6-tdm.36864",
  4973. .platform_name = "msm-pcm-routing",
  4974. .codec_name = "msm-stub-codec.1",
  4975. .codec_dai_name = "msm-stub-rx",
  4976. .no_pcm = 1,
  4977. .dpcm_playback = 1,
  4978. .id = MSM_BACKEND_DAI_PRI_TDM_RX_0,
  4979. .be_hw_params_fixup = msm_be_hw_params_fixup,
  4980. .ops = &sdm845_tdm_be_ops,
  4981. .ignore_suspend = 1,
  4982. },
  4983. {
  4984. .name = LPASS_BE_PRI_TDM_TX_0,
  4985. .stream_name = "Primary TDM0 Capture",
  4986. .cpu_dai_name = "msm-dai-q6-tdm.36865",
  4987. .platform_name = "msm-pcm-routing",
  4988. .codec_name = "msm-stub-codec.1",
  4989. .codec_dai_name = "msm-stub-tx",
  4990. .no_pcm = 1,
  4991. .dpcm_capture = 1,
  4992. .id = MSM_BACKEND_DAI_PRI_TDM_TX_0,
  4993. .be_hw_params_fixup = msm_be_hw_params_fixup,
  4994. .ops = &sdm845_tdm_be_ops,
  4995. .ignore_suspend = 1,
  4996. },
  4997. {
  4998. .name = LPASS_BE_SEC_TDM_RX_0,
  4999. .stream_name = "Secondary TDM0 Playback",
  5000. .cpu_dai_name = "msm-dai-q6-tdm.36880",
  5001. .platform_name = "msm-pcm-routing",
  5002. .codec_name = "msm-stub-codec.1",
  5003. .codec_dai_name = "msm-stub-rx",
  5004. .no_pcm = 1,
  5005. .dpcm_playback = 1,
  5006. .id = MSM_BACKEND_DAI_SEC_TDM_RX_0,
  5007. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5008. .ops = &sdm845_tdm_be_ops,
  5009. .ignore_suspend = 1,
  5010. },
  5011. {
  5012. .name = LPASS_BE_SEC_TDM_TX_0,
  5013. .stream_name = "Secondary TDM0 Capture",
  5014. .cpu_dai_name = "msm-dai-q6-tdm.36881",
  5015. .platform_name = "msm-pcm-routing",
  5016. .codec_name = "msm-stub-codec.1",
  5017. .codec_dai_name = "msm-stub-tx",
  5018. .no_pcm = 1,
  5019. .dpcm_capture = 1,
  5020. .id = MSM_BACKEND_DAI_SEC_TDM_TX_0,
  5021. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5022. .ops = &sdm845_tdm_be_ops,
  5023. .ignore_suspend = 1,
  5024. },
  5025. {
  5026. .name = LPASS_BE_TERT_TDM_RX_0,
  5027. .stream_name = "Tertiary TDM0 Playback",
  5028. .cpu_dai_name = "msm-dai-q6-tdm.36896",
  5029. .platform_name = "msm-pcm-routing",
  5030. .codec_name = "msm-stub-codec.1",
  5031. .codec_dai_name = "msm-stub-rx",
  5032. .no_pcm = 1,
  5033. .dpcm_playback = 1,
  5034. .id = MSM_BACKEND_DAI_TERT_TDM_RX_0,
  5035. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5036. .ops = &sdm845_tdm_be_ops,
  5037. .ignore_suspend = 1,
  5038. },
  5039. {
  5040. .name = LPASS_BE_TERT_TDM_TX_0,
  5041. .stream_name = "Tertiary TDM0 Capture",
  5042. .cpu_dai_name = "msm-dai-q6-tdm.36897",
  5043. .platform_name = "msm-pcm-routing",
  5044. .codec_name = "msm-stub-codec.1",
  5045. .codec_dai_name = "msm-stub-tx",
  5046. .no_pcm = 1,
  5047. .dpcm_capture = 1,
  5048. .id = MSM_BACKEND_DAI_TERT_TDM_TX_0,
  5049. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5050. .ops = &sdm845_tdm_be_ops,
  5051. .ignore_suspend = 1,
  5052. },
  5053. {
  5054. .name = LPASS_BE_QUAT_TDM_RX_0,
  5055. .stream_name = "Quaternary TDM0 Playback",
  5056. .cpu_dai_name = "msm-dai-q6-tdm.36912",
  5057. .platform_name = "msm-pcm-routing",
  5058. .codec_name = "msm-stub-codec.1",
  5059. .codec_dai_name = "msm-stub-rx",
  5060. .no_pcm = 1,
  5061. .dpcm_playback = 1,
  5062. .id = MSM_BACKEND_DAI_QUAT_TDM_RX_0,
  5063. .be_hw_params_fixup = msm_tdm_be_hw_params_fixup,
  5064. .ops = &sdm845_tdm_be_ops,
  5065. .ignore_suspend = 1,
  5066. },
  5067. {
  5068. .name = LPASS_BE_QUAT_TDM_TX_0,
  5069. .stream_name = "Quaternary TDM0 Capture",
  5070. .cpu_dai_name = "msm-dai-q6-tdm.36913",
  5071. .platform_name = "msm-pcm-routing",
  5072. .codec_name = "msm-stub-codec.1",
  5073. .codec_dai_name = "msm-stub-tx",
  5074. .no_pcm = 1,
  5075. .dpcm_capture = 1,
  5076. .id = MSM_BACKEND_DAI_QUAT_TDM_TX_0,
  5077. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5078. .ops = &sdm845_tdm_be_ops,
  5079. .ignore_suspend = 1,
  5080. },
  5081. };
  5082. static struct snd_soc_dai_link msm_tavil_be_dai_links[] = {
  5083. {
  5084. .name = LPASS_BE_SLIMBUS_0_RX,
  5085. .stream_name = "Slimbus Playback",
  5086. .cpu_dai_name = "msm-dai-q6-dev.16384",
  5087. .platform_name = "msm-pcm-routing",
  5088. .codec_name = "tavil_codec",
  5089. .codec_dai_name = "tavil_rx1",
  5090. .no_pcm = 1,
  5091. .dpcm_playback = 1,
  5092. .id = MSM_BACKEND_DAI_SLIMBUS_0_RX,
  5093. .init = &msm_audrx_init,
  5094. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5095. /* this dainlink has playback support */
  5096. .ignore_pmdown_time = 1,
  5097. .ignore_suspend = 1,
  5098. .ops = &msm_be_ops,
  5099. },
  5100. {
  5101. .name = LPASS_BE_SLIMBUS_0_TX,
  5102. .stream_name = "Slimbus Capture",
  5103. .cpu_dai_name = "msm-dai-q6-dev.16385",
  5104. .platform_name = "msm-pcm-routing",
  5105. .codec_name = "tavil_codec",
  5106. .codec_dai_name = "tavil_tx1",
  5107. .no_pcm = 1,
  5108. .dpcm_capture = 1,
  5109. .id = MSM_BACKEND_DAI_SLIMBUS_0_TX,
  5110. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5111. .ignore_suspend = 1,
  5112. .ops = &msm_be_ops,
  5113. },
  5114. {
  5115. .name = LPASS_BE_SLIMBUS_1_RX,
  5116. .stream_name = "Slimbus1 Playback",
  5117. .cpu_dai_name = "msm-dai-q6-dev.16386",
  5118. .platform_name = "msm-pcm-routing",
  5119. .codec_name = "tavil_codec",
  5120. .codec_dai_name = "tavil_rx1",
  5121. .no_pcm = 1,
  5122. .dpcm_playback = 1,
  5123. .id = MSM_BACKEND_DAI_SLIMBUS_1_RX,
  5124. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5125. .ops = &msm_be_ops,
  5126. /* dai link has playback support */
  5127. .ignore_pmdown_time = 1,
  5128. .ignore_suspend = 1,
  5129. },
  5130. {
  5131. .name = LPASS_BE_SLIMBUS_1_TX,
  5132. .stream_name = "Slimbus1 Capture",
  5133. .cpu_dai_name = "msm-dai-q6-dev.16387",
  5134. .platform_name = "msm-pcm-routing",
  5135. .codec_name = "tavil_codec",
  5136. .codec_dai_name = "tavil_tx3",
  5137. .no_pcm = 1,
  5138. .dpcm_capture = 1,
  5139. .id = MSM_BACKEND_DAI_SLIMBUS_1_TX,
  5140. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5141. .ops = &msm_be_ops,
  5142. .ignore_suspend = 1,
  5143. },
  5144. {
  5145. .name = LPASS_BE_SLIMBUS_2_RX,
  5146. .stream_name = "Slimbus2 Playback",
  5147. .cpu_dai_name = "msm-dai-q6-dev.16388",
  5148. .platform_name = "msm-pcm-routing",
  5149. .codec_name = "tavil_codec",
  5150. .codec_dai_name = "tavil_rx2",
  5151. .no_pcm = 1,
  5152. .dpcm_playback = 1,
  5153. .id = MSM_BACKEND_DAI_SLIMBUS_2_RX,
  5154. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5155. .ops = &msm_be_ops,
  5156. .ignore_pmdown_time = 1,
  5157. .ignore_suspend = 1,
  5158. },
  5159. {
  5160. .name = LPASS_BE_SLIMBUS_3_RX,
  5161. .stream_name = "Slimbus3 Playback",
  5162. .cpu_dai_name = "msm-dai-q6-dev.16390",
  5163. .platform_name = "msm-pcm-routing",
  5164. .codec_name = "tavil_codec",
  5165. .codec_dai_name = "tavil_rx1",
  5166. .no_pcm = 1,
  5167. .dpcm_playback = 1,
  5168. .id = MSM_BACKEND_DAI_SLIMBUS_3_RX,
  5169. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5170. .ops = &msm_be_ops,
  5171. /* dai link has playback support */
  5172. .ignore_pmdown_time = 1,
  5173. .ignore_suspend = 1,
  5174. },
  5175. {
  5176. .name = LPASS_BE_SLIMBUS_3_TX,
  5177. .stream_name = "Slimbus3 Capture",
  5178. .cpu_dai_name = "msm-dai-q6-dev.16391",
  5179. .platform_name = "msm-pcm-routing",
  5180. .codec_name = "tavil_codec",
  5181. .codec_dai_name = "tavil_tx1",
  5182. .no_pcm = 1,
  5183. .dpcm_capture = 1,
  5184. .id = MSM_BACKEND_DAI_SLIMBUS_3_TX,
  5185. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5186. .ops = &msm_be_ops,
  5187. .ignore_suspend = 1,
  5188. },
  5189. {
  5190. .name = LPASS_BE_SLIMBUS_4_RX,
  5191. .stream_name = "Slimbus4 Playback",
  5192. .cpu_dai_name = "msm-dai-q6-dev.16392",
  5193. .platform_name = "msm-pcm-routing",
  5194. .codec_name = "tavil_codec",
  5195. .codec_dai_name = "tavil_rx1",
  5196. .no_pcm = 1,
  5197. .dpcm_playback = 1,
  5198. .id = MSM_BACKEND_DAI_SLIMBUS_4_RX,
  5199. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5200. .ops = &msm_be_ops,
  5201. /* dai link has playback support */
  5202. .ignore_pmdown_time = 1,
  5203. .ignore_suspend = 1,
  5204. },
  5205. {
  5206. .name = LPASS_BE_SLIMBUS_5_RX,
  5207. .stream_name = "Slimbus5 Playback",
  5208. .cpu_dai_name = "msm-dai-q6-dev.16394",
  5209. .platform_name = "msm-pcm-routing",
  5210. .codec_name = "tavil_codec",
  5211. .codec_dai_name = "tavil_rx3",
  5212. .no_pcm = 1,
  5213. .dpcm_playback = 1,
  5214. .id = MSM_BACKEND_DAI_SLIMBUS_5_RX,
  5215. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5216. .ops = &msm_be_ops,
  5217. /* dai link has playback support */
  5218. .ignore_pmdown_time = 1,
  5219. .ignore_suspend = 1,
  5220. },
  5221. /* MAD BE */
  5222. {
  5223. .name = LPASS_BE_SLIMBUS_5_TX,
  5224. .stream_name = "Slimbus5 Capture",
  5225. .cpu_dai_name = "msm-dai-q6-dev.16395",
  5226. .platform_name = "msm-pcm-routing",
  5227. .codec_name = "tavil_codec",
  5228. .codec_dai_name = "tavil_mad1",
  5229. .no_pcm = 1,
  5230. .dpcm_capture = 1,
  5231. .id = MSM_BACKEND_DAI_SLIMBUS_5_TX,
  5232. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5233. .ops = &msm_be_ops,
  5234. .ignore_suspend = 1,
  5235. },
  5236. {
  5237. .name = LPASS_BE_SLIMBUS_6_RX,
  5238. .stream_name = "Slimbus6 Playback",
  5239. .cpu_dai_name = "msm-dai-q6-dev.16396",
  5240. .platform_name = "msm-pcm-routing",
  5241. .codec_name = "tavil_codec",
  5242. .codec_dai_name = "tavil_rx4",
  5243. .no_pcm = 1,
  5244. .dpcm_playback = 1,
  5245. .id = MSM_BACKEND_DAI_SLIMBUS_6_RX,
  5246. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5247. .ops = &msm_be_ops,
  5248. /* dai link has playback support */
  5249. .ignore_pmdown_time = 1,
  5250. .ignore_suspend = 1,
  5251. },
  5252. /* Slimbus VI Recording */
  5253. {
  5254. .name = LPASS_BE_SLIMBUS_TX_VI,
  5255. .stream_name = "Slimbus4 Capture",
  5256. .cpu_dai_name = "msm-dai-q6-dev.16393",
  5257. .platform_name = "msm-pcm-routing",
  5258. .codec_name = "tavil_codec",
  5259. .codec_dai_name = "tavil_vifeedback",
  5260. .id = MSM_BACKEND_DAI_SLIMBUS_4_TX,
  5261. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5262. .ops = &msm_be_ops,
  5263. .ignore_suspend = 1,
  5264. .no_pcm = 1,
  5265. .dpcm_capture = 1,
  5266. .ignore_pmdown_time = 1,
  5267. },
  5268. };
  5269. static struct snd_soc_dai_link msm_wcn_be_dai_links[] = {
  5270. {
  5271. .name = LPASS_BE_SLIMBUS_7_RX,
  5272. .stream_name = "Slimbus7 Playback",
  5273. .cpu_dai_name = "msm-dai-q6-dev.16398",
  5274. .platform_name = "msm-pcm-routing",
  5275. .codec_name = "btfmslim_slave",
  5276. /* BT codec driver determines capabilities based on
  5277. * dai name, bt codecdai name should always contains
  5278. * supported usecase information
  5279. */
  5280. .codec_dai_name = "btfm_bt_sco_a2dp_slim_rx",
  5281. .no_pcm = 1,
  5282. .dpcm_playback = 1,
  5283. .id = MSM_BACKEND_DAI_SLIMBUS_7_RX,
  5284. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5285. .ops = &msm_wcn_ops,
  5286. /* dai link has playback support */
  5287. .ignore_pmdown_time = 1,
  5288. .ignore_suspend = 1,
  5289. },
  5290. {
  5291. .name = LPASS_BE_SLIMBUS_7_TX,
  5292. .stream_name = "Slimbus7 Capture",
  5293. .cpu_dai_name = "msm-dai-q6-dev.16399",
  5294. .platform_name = "msm-pcm-routing",
  5295. .codec_name = "btfmslim_slave",
  5296. .codec_dai_name = "btfm_bt_sco_slim_tx",
  5297. .no_pcm = 1,
  5298. .dpcm_capture = 1,
  5299. .id = MSM_BACKEND_DAI_SLIMBUS_7_TX,
  5300. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5301. .ops = &msm_wcn_ops,
  5302. .ignore_suspend = 1,
  5303. },
  5304. {
  5305. .name = LPASS_BE_SLIMBUS_8_TX,
  5306. .stream_name = "Slimbus8 Capture",
  5307. .cpu_dai_name = "msm-dai-q6-dev.16401",
  5308. .platform_name = "msm-pcm-routing",
  5309. .codec_name = "btfmslim_slave",
  5310. .codec_dai_name = "btfm_fm_slim_tx",
  5311. .no_pcm = 1,
  5312. .dpcm_capture = 1,
  5313. .id = MSM_BACKEND_DAI_SLIMBUS_8_TX,
  5314. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5315. .init = &msm_wcn_init,
  5316. .ops = &msm_wcn_ops,
  5317. .ignore_suspend = 1,
  5318. },
  5319. };
  5320. static struct snd_soc_dai_link ext_disp_be_dai_link[] = {
  5321. /* DISP PORT BACK END DAI Link */
  5322. {
  5323. .name = LPASS_BE_DISPLAY_PORT,
  5324. .stream_name = "Display Port Playback",
  5325. .cpu_dai_name = "msm-dai-q6-dp.24608",
  5326. .platform_name = "msm-pcm-routing",
  5327. .codec_name = "msm-ext-disp-audio-codec-rx",
  5328. .codec_dai_name = "msm_dp_audio_codec_rx_dai",
  5329. .no_pcm = 1,
  5330. .dpcm_playback = 1,
  5331. .id = MSM_BACKEND_DAI_DISPLAY_PORT_RX,
  5332. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5333. .ignore_pmdown_time = 1,
  5334. .ignore_suspend = 1,
  5335. },
  5336. };
  5337. static struct snd_soc_dai_link msm_mi2s_be_dai_links[] = {
  5338. {
  5339. .name = LPASS_BE_PRI_MI2S_RX,
  5340. .stream_name = "Primary MI2S Playback",
  5341. .cpu_dai_name = "msm-dai-q6-mi2s.0",
  5342. .platform_name = "msm-pcm-routing",
  5343. .codec_name = "msm-stub-codec.1",
  5344. .codec_dai_name = "msm-stub-rx",
  5345. .no_pcm = 1,
  5346. .dpcm_playback = 1,
  5347. .id = MSM_BACKEND_DAI_PRI_MI2S_RX,
  5348. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5349. .ops = &msm_mi2s_be_ops,
  5350. .ignore_suspend = 1,
  5351. .ignore_pmdown_time = 1,
  5352. },
  5353. {
  5354. .name = LPASS_BE_PRI_MI2S_TX,
  5355. .stream_name = "Primary MI2S Capture",
  5356. .cpu_dai_name = "msm-dai-q6-mi2s.0",
  5357. .platform_name = "msm-pcm-routing",
  5358. .codec_name = "msm-stub-codec.1",
  5359. .codec_dai_name = "msm-stub-tx",
  5360. .no_pcm = 1,
  5361. .dpcm_capture = 1,
  5362. .id = MSM_BACKEND_DAI_PRI_MI2S_TX,
  5363. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5364. .ops = &msm_mi2s_be_ops,
  5365. .ignore_suspend = 1,
  5366. },
  5367. {
  5368. .name = LPASS_BE_SEC_MI2S_RX,
  5369. .stream_name = "Secondary MI2S Playback",
  5370. .cpu_dai_name = "msm-dai-q6-mi2s.1",
  5371. .platform_name = "msm-pcm-routing",
  5372. .codec_name = "msm-stub-codec.1",
  5373. .codec_dai_name = "msm-stub-rx",
  5374. .no_pcm = 1,
  5375. .dpcm_playback = 1,
  5376. .id = MSM_BACKEND_DAI_SECONDARY_MI2S_RX,
  5377. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5378. .ops = &msm_mi2s_be_ops,
  5379. .ignore_suspend = 1,
  5380. .ignore_pmdown_time = 1,
  5381. },
  5382. {
  5383. .name = LPASS_BE_SEC_MI2S_TX,
  5384. .stream_name = "Secondary MI2S Capture",
  5385. .cpu_dai_name = "msm-dai-q6-mi2s.1",
  5386. .platform_name = "msm-pcm-routing",
  5387. .codec_name = "msm-stub-codec.1",
  5388. .codec_dai_name = "msm-stub-tx",
  5389. .no_pcm = 1,
  5390. .dpcm_capture = 1,
  5391. .id = MSM_BACKEND_DAI_SECONDARY_MI2S_TX,
  5392. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5393. .ops = &msm_mi2s_be_ops,
  5394. .ignore_suspend = 1,
  5395. },
  5396. {
  5397. .name = LPASS_BE_TERT_MI2S_RX,
  5398. .stream_name = "Tertiary MI2S Playback",
  5399. .cpu_dai_name = "msm-dai-q6-mi2s.2",
  5400. .platform_name = "msm-pcm-routing",
  5401. .codec_name = "msm-stub-codec.1",
  5402. .codec_dai_name = "msm-stub-rx",
  5403. .no_pcm = 1,
  5404. .dpcm_playback = 1,
  5405. .id = MSM_BACKEND_DAI_TERTIARY_MI2S_RX,
  5406. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5407. .ops = &msm_mi2s_be_ops,
  5408. .ignore_suspend = 1,
  5409. .ignore_pmdown_time = 1,
  5410. },
  5411. {
  5412. .name = LPASS_BE_TERT_MI2S_TX,
  5413. .stream_name = "Tertiary MI2S Capture",
  5414. .cpu_dai_name = "msm-dai-q6-mi2s.2",
  5415. .platform_name = "msm-pcm-routing",
  5416. .codec_name = "msm-stub-codec.1",
  5417. .codec_dai_name = "msm-stub-tx",
  5418. .no_pcm = 1,
  5419. .dpcm_capture = 1,
  5420. .id = MSM_BACKEND_DAI_TERTIARY_MI2S_TX,
  5421. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5422. .ops = &msm_mi2s_be_ops,
  5423. .ignore_suspend = 1,
  5424. },
  5425. {
  5426. .name = LPASS_BE_QUAT_MI2S_RX,
  5427. .stream_name = "Quaternary MI2S Playback",
  5428. .cpu_dai_name = "msm-dai-q6-mi2s.3",
  5429. .platform_name = "msm-pcm-routing",
  5430. .codec_name = "msm-stub-codec.1",
  5431. .codec_dai_name = "msm-stub-rx",
  5432. .no_pcm = 1,
  5433. .dpcm_playback = 1,
  5434. .id = MSM_BACKEND_DAI_QUATERNARY_MI2S_RX,
  5435. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5436. .ops = &msm_mi2s_be_ops,
  5437. .ignore_suspend = 1,
  5438. .ignore_pmdown_time = 1,
  5439. },
  5440. {
  5441. .name = LPASS_BE_QUAT_MI2S_TX,
  5442. .stream_name = "Quaternary MI2S Capture",
  5443. .cpu_dai_name = "msm-dai-q6-mi2s.3",
  5444. .platform_name = "msm-pcm-routing",
  5445. .codec_name = "msm-stub-codec.1",
  5446. .codec_dai_name = "msm-stub-tx",
  5447. .no_pcm = 1,
  5448. .dpcm_capture = 1,
  5449. .id = MSM_BACKEND_DAI_QUATERNARY_MI2S_TX,
  5450. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5451. .ops = &msm_mi2s_be_ops,
  5452. .ignore_suspend = 1,
  5453. },
  5454. };
  5455. static struct snd_soc_dai_link msm_auxpcm_be_dai_links[] = {
  5456. /* Primary AUX PCM Backend DAI Links */
  5457. {
  5458. .name = LPASS_BE_AUXPCM_RX,
  5459. .stream_name = "AUX PCM Playback",
  5460. .cpu_dai_name = "msm-dai-q6-auxpcm.1",
  5461. .platform_name = "msm-pcm-routing",
  5462. .codec_name = "msm-stub-codec.1",
  5463. .codec_dai_name = "msm-stub-rx",
  5464. .no_pcm = 1,
  5465. .dpcm_playback = 1,
  5466. .id = MSM_BACKEND_DAI_AUXPCM_RX,
  5467. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5468. .ignore_pmdown_time = 1,
  5469. .ignore_suspend = 1,
  5470. .ops = &msm_aux_pcm_be_ops,
  5471. },
  5472. {
  5473. .name = LPASS_BE_AUXPCM_TX,
  5474. .stream_name = "AUX PCM Capture",
  5475. .cpu_dai_name = "msm-dai-q6-auxpcm.1",
  5476. .platform_name = "msm-pcm-routing",
  5477. .codec_name = "msm-stub-codec.1",
  5478. .codec_dai_name = "msm-stub-tx",
  5479. .no_pcm = 1,
  5480. .dpcm_capture = 1,
  5481. .id = MSM_BACKEND_DAI_AUXPCM_TX,
  5482. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5483. .ignore_pmdown_time = 1,
  5484. .ignore_suspend = 1,
  5485. .ops = &msm_aux_pcm_be_ops,
  5486. },
  5487. /* Secondary AUX PCM Backend DAI Links */
  5488. {
  5489. .name = LPASS_BE_SEC_AUXPCM_RX,
  5490. .stream_name = "Sec AUX PCM Playback",
  5491. .cpu_dai_name = "msm-dai-q6-auxpcm.2",
  5492. .platform_name = "msm-pcm-routing",
  5493. .codec_name = "msm-stub-codec.1",
  5494. .codec_dai_name = "msm-stub-rx",
  5495. .no_pcm = 1,
  5496. .dpcm_playback = 1,
  5497. .id = MSM_BACKEND_DAI_SEC_AUXPCM_RX,
  5498. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5499. .ignore_pmdown_time = 1,
  5500. .ignore_suspend = 1,
  5501. .ops = &msm_aux_pcm_be_ops,
  5502. },
  5503. {
  5504. .name = LPASS_BE_SEC_AUXPCM_TX,
  5505. .stream_name = "Sec AUX PCM Capture",
  5506. .cpu_dai_name = "msm-dai-q6-auxpcm.2",
  5507. .platform_name = "msm-pcm-routing",
  5508. .codec_name = "msm-stub-codec.1",
  5509. .codec_dai_name = "msm-stub-tx",
  5510. .no_pcm = 1,
  5511. .dpcm_capture = 1,
  5512. .id = MSM_BACKEND_DAI_SEC_AUXPCM_TX,
  5513. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5514. .ignore_suspend = 1,
  5515. .ignore_pmdown_time = 1,
  5516. .ops = &msm_aux_pcm_be_ops,
  5517. },
  5518. /* Tertiary AUX PCM Backend DAI Links */
  5519. {
  5520. .name = LPASS_BE_TERT_AUXPCM_RX,
  5521. .stream_name = "Tert AUX PCM Playback",
  5522. .cpu_dai_name = "msm-dai-q6-auxpcm.3",
  5523. .platform_name = "msm-pcm-routing",
  5524. .codec_name = "msm-stub-codec.1",
  5525. .codec_dai_name = "msm-stub-rx",
  5526. .no_pcm = 1,
  5527. .dpcm_playback = 1,
  5528. .id = MSM_BACKEND_DAI_TERT_AUXPCM_RX,
  5529. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5530. .ignore_pmdown_time = 1,
  5531. .ignore_suspend = 1,
  5532. .ops = &msm_aux_pcm_be_ops,
  5533. },
  5534. {
  5535. .name = LPASS_BE_TERT_AUXPCM_TX,
  5536. .stream_name = "Tert AUX PCM Capture",
  5537. .cpu_dai_name = "msm-dai-q6-auxpcm.3",
  5538. .platform_name = "msm-pcm-routing",
  5539. .codec_name = "msm-stub-codec.1",
  5540. .codec_dai_name = "msm-stub-tx",
  5541. .no_pcm = 1,
  5542. .dpcm_capture = 1,
  5543. .id = MSM_BACKEND_DAI_TERT_AUXPCM_TX,
  5544. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5545. .ignore_suspend = 1,
  5546. .ignore_pmdown_time = 1,
  5547. .ops = &msm_aux_pcm_be_ops,
  5548. },
  5549. /* Quaternary AUX PCM Backend DAI Links */
  5550. {
  5551. .name = LPASS_BE_QUAT_AUXPCM_RX,
  5552. .stream_name = "Quat AUX PCM Playback",
  5553. .cpu_dai_name = "msm-dai-q6-auxpcm.4",
  5554. .platform_name = "msm-pcm-routing",
  5555. .codec_name = "msm-stub-codec.1",
  5556. .codec_dai_name = "msm-stub-rx",
  5557. .no_pcm = 1,
  5558. .dpcm_playback = 1,
  5559. .id = MSM_BACKEND_DAI_QUAT_AUXPCM_RX,
  5560. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5561. .ignore_pmdown_time = 1,
  5562. .ignore_suspend = 1,
  5563. .ops = &msm_aux_pcm_be_ops,
  5564. },
  5565. {
  5566. .name = LPASS_BE_QUAT_AUXPCM_TX,
  5567. .stream_name = "Quat AUX PCM Capture",
  5568. .cpu_dai_name = "msm-dai-q6-auxpcm.4",
  5569. .platform_name = "msm-pcm-routing",
  5570. .codec_name = "msm-stub-codec.1",
  5571. .codec_dai_name = "msm-stub-tx",
  5572. .no_pcm = 1,
  5573. .dpcm_capture = 1,
  5574. .id = MSM_BACKEND_DAI_QUAT_AUXPCM_TX,
  5575. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5576. .ignore_suspend = 1,
  5577. .ignore_pmdown_time = 1,
  5578. .ops = &msm_aux_pcm_be_ops,
  5579. },
  5580. };
  5581. static struct snd_soc_dai_link msm_tavil_snd_card_dai_links[
  5582. ARRAY_SIZE(msm_common_dai_links) +
  5583. ARRAY_SIZE(msm_tavil_fe_dai_links) +
  5584. ARRAY_SIZE(msm_common_misc_fe_dai_links) +
  5585. ARRAY_SIZE(msm_common_be_dai_links) +
  5586. ARRAY_SIZE(msm_tavil_be_dai_links) +
  5587. ARRAY_SIZE(msm_wcn_be_dai_links) +
  5588. ARRAY_SIZE(ext_disp_be_dai_link) +
  5589. ARRAY_SIZE(msm_mi2s_be_dai_links) +
  5590. ARRAY_SIZE(msm_auxpcm_be_dai_links)];
  5591. static int msm_snd_card_tavil_late_probe(struct snd_soc_card *card)
  5592. {
  5593. const char *be_dl_name = LPASS_BE_SLIMBUS_0_RX;
  5594. struct snd_soc_pcm_runtime *rtd;
  5595. int ret = 0;
  5596. void *mbhc_calibration;
  5597. rtd = snd_soc_get_pcm_runtime(card, be_dl_name);
  5598. if (!rtd) {
  5599. dev_err(card->dev,
  5600. "%s: snd_soc_get_pcm_runtime for %s failed!\n",
  5601. __func__, be_dl_name);
  5602. ret = -EINVAL;
  5603. goto err;
  5604. }
  5605. mbhc_calibration = def_tavil_mbhc_cal();
  5606. if (!mbhc_calibration) {
  5607. ret = -ENOMEM;
  5608. goto err;
  5609. }
  5610. wcd_mbhc_cfg.calibration = mbhc_calibration;
  5611. ret = tavil_mbhc_hs_detect(rtd->codec, &wcd_mbhc_cfg);
  5612. if (ret) {
  5613. dev_err(card->dev, "%s: mbhc hs detect failed, err:%d\n",
  5614. __func__, ret);
  5615. goto err_free_mbhc_cal;
  5616. }
  5617. return 0;
  5618. err_free_mbhc_cal:
  5619. kfree(mbhc_calibration);
  5620. err:
  5621. return ret;
  5622. }
  5623. struct snd_soc_card snd_soc_card_tavil_msm = {
  5624. .name = "sdm845-tavil-snd-card",
  5625. .late_probe = msm_snd_card_tavil_late_probe,
  5626. };
  5627. static int msm_populate_dai_link_component_of_node(
  5628. struct snd_soc_card *card)
  5629. {
  5630. int i, index, ret = 0;
  5631. struct device *cdev = card->dev;
  5632. struct snd_soc_dai_link *dai_link = card->dai_link;
  5633. struct device_node *np;
  5634. if (!cdev) {
  5635. pr_err("%s: Sound card device memory NULL\n", __func__);
  5636. return -ENODEV;
  5637. }
  5638. for (i = 0; i < card->num_links; i++) {
  5639. if (dai_link[i].platform_of_node && dai_link[i].cpu_of_node)
  5640. continue;
  5641. /* populate platform_of_node for snd card dai links */
  5642. if (dai_link[i].platform_name &&
  5643. !dai_link[i].platform_of_node) {
  5644. index = of_property_match_string(cdev->of_node,
  5645. "asoc-platform-names",
  5646. dai_link[i].platform_name);
  5647. if (index < 0) {
  5648. pr_err("%s: No match found for platform name: %s\n",
  5649. __func__, dai_link[i].platform_name);
  5650. ret = index;
  5651. goto err;
  5652. }
  5653. np = of_parse_phandle(cdev->of_node, "asoc-platform",
  5654. index);
  5655. if (!np) {
  5656. pr_err("%s: retrieving phandle for platform %s, index %d failed\n",
  5657. __func__, dai_link[i].platform_name,
  5658. index);
  5659. ret = -ENODEV;
  5660. goto err;
  5661. }
  5662. dai_link[i].platform_of_node = np;
  5663. dai_link[i].platform_name = NULL;
  5664. }
  5665. /* populate cpu_of_node for snd card dai links */
  5666. if (dai_link[i].cpu_dai_name && !dai_link[i].cpu_of_node) {
  5667. index = of_property_match_string(cdev->of_node,
  5668. "asoc-cpu-names",
  5669. dai_link[i].cpu_dai_name);
  5670. if (index >= 0) {
  5671. np = of_parse_phandle(cdev->of_node, "asoc-cpu",
  5672. index);
  5673. if (!np) {
  5674. pr_err("%s: retrieving phandle for cpu dai %s failed\n",
  5675. __func__,
  5676. dai_link[i].cpu_dai_name);
  5677. ret = -ENODEV;
  5678. goto err;
  5679. }
  5680. dai_link[i].cpu_of_node = np;
  5681. dai_link[i].cpu_dai_name = NULL;
  5682. }
  5683. }
  5684. /* populate codec_of_node for snd card dai links */
  5685. if (dai_link[i].codec_name && !dai_link[i].codec_of_node) {
  5686. index = of_property_match_string(cdev->of_node,
  5687. "asoc-codec-names",
  5688. dai_link[i].codec_name);
  5689. if (index < 0)
  5690. continue;
  5691. np = of_parse_phandle(cdev->of_node, "asoc-codec",
  5692. index);
  5693. if (!np) {
  5694. pr_err("%s: retrieving phandle for codec %s failed\n",
  5695. __func__, dai_link[i].codec_name);
  5696. ret = -ENODEV;
  5697. goto err;
  5698. }
  5699. dai_link[i].codec_of_node = np;
  5700. dai_link[i].codec_name = NULL;
  5701. }
  5702. }
  5703. err:
  5704. return ret;
  5705. }
  5706. static int msm_prepare_us_euro(struct snd_soc_card *card)
  5707. {
  5708. struct msm_asoc_mach_data *pdata =
  5709. snd_soc_card_get_drvdata(card);
  5710. int ret = 0;
  5711. if (pdata->us_euro_gpio >= 0) {
  5712. dev_dbg(card->dev, "%s: us_euro gpio request %d", __func__,
  5713. pdata->us_euro_gpio);
  5714. ret = gpio_request(pdata->us_euro_gpio, "TAVIL_CODEC_US_EURO");
  5715. if (ret) {
  5716. dev_err(card->dev,
  5717. "%s: Failed to request codec US/EURO gpio %d error %d\n",
  5718. __func__, pdata->us_euro_gpio, ret);
  5719. }
  5720. }
  5721. return ret;
  5722. }
  5723. static int msm_audrx_stub_init(struct snd_soc_pcm_runtime *rtd)
  5724. {
  5725. int ret = 0;
  5726. struct snd_soc_codec *codec = rtd->codec;
  5727. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  5728. ret = snd_soc_add_codec_controls(codec, msm_snd_controls,
  5729. ARRAY_SIZE(msm_snd_controls));
  5730. if (ret < 0) {
  5731. dev_err(codec->dev,
  5732. "%s: add_codec_controls failed, err = %d\n",
  5733. __func__, ret);
  5734. return ret;
  5735. }
  5736. snd_soc_dapm_new_controls(dapm, msm_dapm_widgets,
  5737. ARRAY_SIZE(msm_dapm_widgets));
  5738. return 0;
  5739. }
  5740. static int msm_snd_stub_hw_params(struct snd_pcm_substream *substream,
  5741. struct snd_pcm_hw_params *params)
  5742. {
  5743. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  5744. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  5745. int ret = 0;
  5746. unsigned int rx_ch[] = {144, 145, 146, 147, 148, 149, 150,
  5747. 151};
  5748. unsigned int tx_ch[] = {128, 129, 130, 131, 132, 133,
  5749. 134, 135, 136, 137, 138, 139,
  5750. 140, 141, 142, 143};
  5751. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  5752. ret = snd_soc_dai_set_channel_map(cpu_dai, 0, 0,
  5753. slim_rx_cfg[0].channels,
  5754. rx_ch);
  5755. if (ret < 0)
  5756. pr_err("%s: RX failed to set cpu chan map error %d\n",
  5757. __func__, ret);
  5758. } else {
  5759. ret = snd_soc_dai_set_channel_map(cpu_dai,
  5760. slim_tx_cfg[0].channels,
  5761. tx_ch, 0, 0);
  5762. if (ret < 0)
  5763. pr_err("%s: TX failed to set cpu chan map error %d\n",
  5764. __func__, ret);
  5765. }
  5766. return ret;
  5767. }
  5768. static struct snd_soc_ops msm_stub_be_ops = {
  5769. .hw_params = msm_snd_stub_hw_params,
  5770. };
  5771. static struct snd_soc_dai_link msm_stub_fe_dai_links[] = {
  5772. /* FrontEnd DAI Links */
  5773. {
  5774. .name = "MSMSTUB Media1",
  5775. .stream_name = "MultiMedia1",
  5776. .cpu_dai_name = "MultiMedia1",
  5777. .platform_name = "msm-pcm-dsp.0",
  5778. .dynamic = 1,
  5779. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  5780. .dpcm_playback = 1,
  5781. .dpcm_capture = 1,
  5782. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  5783. SND_SOC_DPCM_TRIGGER_POST},
  5784. .codec_dai_name = "snd-soc-dummy-dai",
  5785. .codec_name = "snd-soc-dummy",
  5786. .ignore_suspend = 1,
  5787. /* this dainlink has playback support */
  5788. .ignore_pmdown_time = 1,
  5789. .id = MSM_FRONTEND_DAI_MULTIMEDIA1
  5790. },
  5791. };
  5792. static struct snd_soc_dai_link msm_stub_be_dai_links[] = {
  5793. /* Backend DAI Links */
  5794. {
  5795. .name = LPASS_BE_SLIMBUS_0_RX,
  5796. .stream_name = "Slimbus Playback",
  5797. .cpu_dai_name = "msm-dai-q6-dev.16384",
  5798. .platform_name = "msm-pcm-routing",
  5799. .codec_name = "msm-stub-codec.1",
  5800. .codec_dai_name = "msm-stub-rx",
  5801. .no_pcm = 1,
  5802. .dpcm_playback = 1,
  5803. .id = MSM_BACKEND_DAI_SLIMBUS_0_RX,
  5804. .init = &msm_audrx_stub_init,
  5805. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5806. .ignore_pmdown_time = 1, /* dai link has playback support */
  5807. .ignore_suspend = 1,
  5808. .ops = &msm_stub_be_ops,
  5809. },
  5810. {
  5811. .name = LPASS_BE_SLIMBUS_0_TX,
  5812. .stream_name = "Slimbus Capture",
  5813. .cpu_dai_name = "msm-dai-q6-dev.16385",
  5814. .platform_name = "msm-pcm-routing",
  5815. .codec_name = "msm-stub-codec.1",
  5816. .codec_dai_name = "msm-stub-tx",
  5817. .no_pcm = 1,
  5818. .dpcm_capture = 1,
  5819. .id = MSM_BACKEND_DAI_SLIMBUS_0_TX,
  5820. .be_hw_params_fixup = msm_be_hw_params_fixup,
  5821. .ignore_suspend = 1,
  5822. .ops = &msm_stub_be_ops,
  5823. },
  5824. };
  5825. static struct snd_soc_dai_link msm_stub_dai_links[
  5826. ARRAY_SIZE(msm_stub_fe_dai_links) +
  5827. ARRAY_SIZE(msm_stub_be_dai_links)];
  5828. struct snd_soc_card snd_soc_card_stub_msm = {
  5829. .name = "sdm845-stub-snd-card",
  5830. };
  5831. static const struct of_device_id sdm845_asoc_machine_of_match[] = {
  5832. { .compatible = "qcom,sdm845-asoc-snd-tavil",
  5833. .data = "tavil_codec"},
  5834. { .compatible = "qcom,sdm845-asoc-snd-stub",
  5835. .data = "stub_codec"},
  5836. {},
  5837. };
  5838. static struct snd_soc_card *populate_snd_card_dailinks(struct device *dev)
  5839. {
  5840. struct snd_soc_card *card = NULL;
  5841. struct snd_soc_dai_link *dailink;
  5842. int len_1, len_2, len_3, len_4;
  5843. int total_links;
  5844. const struct of_device_id *match;
  5845. match = of_match_node(sdm845_asoc_machine_of_match, dev->of_node);
  5846. if (!match) {
  5847. dev_err(dev, "%s: No DT match found for sound card\n",
  5848. __func__);
  5849. return NULL;
  5850. }
  5851. if (!strcmp(match->data, "tavil_codec")) {
  5852. card = &snd_soc_card_tavil_msm;
  5853. len_1 = ARRAY_SIZE(msm_common_dai_links);
  5854. len_2 = len_1 + ARRAY_SIZE(msm_tavil_fe_dai_links);
  5855. len_3 = len_2 + ARRAY_SIZE(msm_common_misc_fe_dai_links);
  5856. len_4 = len_3 + ARRAY_SIZE(msm_common_be_dai_links);
  5857. total_links = len_4 + ARRAY_SIZE(msm_tavil_be_dai_links);
  5858. memcpy(msm_tavil_snd_card_dai_links,
  5859. msm_common_dai_links,
  5860. sizeof(msm_common_dai_links));
  5861. memcpy(msm_tavil_snd_card_dai_links + len_1,
  5862. msm_tavil_fe_dai_links,
  5863. sizeof(msm_tavil_fe_dai_links));
  5864. memcpy(msm_tavil_snd_card_dai_links + len_2,
  5865. msm_common_misc_fe_dai_links,
  5866. sizeof(msm_common_misc_fe_dai_links));
  5867. memcpy(msm_tavil_snd_card_dai_links + len_3,
  5868. msm_common_be_dai_links,
  5869. sizeof(msm_common_be_dai_links));
  5870. memcpy(msm_tavil_snd_card_dai_links + len_4,
  5871. msm_tavil_be_dai_links,
  5872. sizeof(msm_tavil_be_dai_links));
  5873. if (of_property_read_bool(dev->of_node, "qcom,wcn-btfm")) {
  5874. dev_dbg(dev, "%s(): WCN BTFM support present\n",
  5875. __func__);
  5876. memcpy(msm_tavil_snd_card_dai_links + total_links,
  5877. msm_wcn_be_dai_links,
  5878. sizeof(msm_wcn_be_dai_links));
  5879. total_links += ARRAY_SIZE(msm_wcn_be_dai_links);
  5880. }
  5881. if (of_property_read_bool(dev->of_node,
  5882. "qcom,ext-disp-audio-rx")) {
  5883. dev_dbg(dev, "%s(): ext disp audio support present\n",
  5884. __func__);
  5885. memcpy(msm_tavil_snd_card_dai_links + total_links,
  5886. ext_disp_be_dai_link,
  5887. sizeof(ext_disp_be_dai_link));
  5888. total_links += ARRAY_SIZE(ext_disp_be_dai_link);
  5889. }
  5890. if (of_property_read_bool(dev->of_node,
  5891. "qcom,mi2s-audio-intf")) {
  5892. memcpy(msm_tavil_snd_card_dai_links + total_links,
  5893. msm_mi2s_be_dai_links,
  5894. sizeof(msm_mi2s_be_dai_links));
  5895. total_links += ARRAY_SIZE(msm_mi2s_be_dai_links);
  5896. }
  5897. if (of_property_read_bool(dev->of_node,
  5898. "qcom,auxpcm-audio-intf")) {
  5899. memcpy(msm_tavil_snd_card_dai_links + total_links,
  5900. msm_auxpcm_be_dai_links,
  5901. sizeof(msm_auxpcm_be_dai_links));
  5902. total_links += ARRAY_SIZE(msm_auxpcm_be_dai_links);
  5903. }
  5904. dailink = msm_tavil_snd_card_dai_links;
  5905. } else if (!strcmp(match->data, "stub_codec")) {
  5906. card = &snd_soc_card_stub_msm;
  5907. len_1 = ARRAY_SIZE(msm_stub_fe_dai_links);
  5908. len_2 = len_1 + ARRAY_SIZE(msm_stub_be_dai_links);
  5909. memcpy(msm_stub_dai_links,
  5910. msm_stub_fe_dai_links,
  5911. sizeof(msm_stub_fe_dai_links));
  5912. memcpy(msm_stub_dai_links + len_1,
  5913. msm_stub_be_dai_links,
  5914. sizeof(msm_stub_be_dai_links));
  5915. dailink = msm_stub_dai_links;
  5916. total_links = len_2;
  5917. }
  5918. if (card) {
  5919. card->dai_link = dailink;
  5920. card->num_links = total_links;
  5921. }
  5922. return card;
  5923. }
  5924. static int msm_wsa881x_init(struct snd_soc_component *component)
  5925. {
  5926. u8 spkleft_ports[WSA881X_MAX_SWR_PORTS] = {100, 101, 102, 106};
  5927. u8 spkright_ports[WSA881X_MAX_SWR_PORTS] = {103, 104, 105, 107};
  5928. unsigned int ch_rate[WSA881X_MAX_SWR_PORTS] = {2400, 600, 300, 1200};
  5929. unsigned int ch_mask[WSA881X_MAX_SWR_PORTS] = {0x1, 0xF, 0x3, 0x3};
  5930. struct snd_soc_codec *codec = snd_soc_component_to_codec(component);
  5931. struct msm_asoc_mach_data *pdata;
  5932. struct snd_soc_dapm_context *dapm;
  5933. int ret = 0;
  5934. if (!codec) {
  5935. pr_err("%s codec is NULL\n", __func__);
  5936. return -EINVAL;
  5937. }
  5938. dapm = snd_soc_codec_get_dapm(codec);
  5939. if (!strcmp(component->name_prefix, "SpkrLeft")) {
  5940. dev_dbg(codec->dev, "%s: setting left ch map to codec %s\n",
  5941. __func__, codec->component.name);
  5942. wsa881x_set_channel_map(codec, &spkleft_ports[0],
  5943. WSA881X_MAX_SWR_PORTS, &ch_mask[0],
  5944. &ch_rate[0]);
  5945. if (dapm->component) {
  5946. snd_soc_dapm_ignore_suspend(dapm, "SpkrLeft IN");
  5947. snd_soc_dapm_ignore_suspend(dapm, "SpkrLeft SPKR");
  5948. }
  5949. } else if (!strcmp(component->name_prefix, "SpkrRight")) {
  5950. dev_dbg(codec->dev, "%s: setting right ch map to codec %s\n",
  5951. __func__, codec->component.name);
  5952. wsa881x_set_channel_map(codec, &spkright_ports[0],
  5953. WSA881X_MAX_SWR_PORTS, &ch_mask[0],
  5954. &ch_rate[0]);
  5955. if (dapm->component) {
  5956. snd_soc_dapm_ignore_suspend(dapm, "SpkrRight IN");
  5957. snd_soc_dapm_ignore_suspend(dapm, "SpkrRight SPKR");
  5958. }
  5959. } else {
  5960. dev_err(codec->dev, "%s: wrong codec name %s\n", __func__,
  5961. codec->component.name);
  5962. ret = -EINVAL;
  5963. goto err;
  5964. }
  5965. pdata = snd_soc_card_get_drvdata(component->card);
  5966. if (pdata && pdata->codec_root)
  5967. wsa881x_codec_info_create_codec_entry(pdata->codec_root,
  5968. codec);
  5969. err:
  5970. return ret;
  5971. }
  5972. static int msm_init_wsa_dev(struct platform_device *pdev,
  5973. struct snd_soc_card *card)
  5974. {
  5975. struct device_node *wsa_of_node;
  5976. u32 wsa_max_devs;
  5977. u32 wsa_dev_cnt;
  5978. int i;
  5979. struct msm_wsa881x_dev_info *wsa881x_dev_info;
  5980. const char *wsa_auxdev_name_prefix[1];
  5981. char *dev_name_str = NULL;
  5982. int found = 0;
  5983. int ret = 0;
  5984. /* Get maximum WSA device count for this platform */
  5985. ret = of_property_read_u32(pdev->dev.of_node,
  5986. "qcom,wsa-max-devs", &wsa_max_devs);
  5987. if (ret) {
  5988. dev_info(&pdev->dev,
  5989. "%s: wsa-max-devs property missing in DT %s, ret = %d\n",
  5990. __func__, pdev->dev.of_node->full_name, ret);
  5991. card->num_aux_devs = 0;
  5992. return 0;
  5993. }
  5994. if (wsa_max_devs == 0) {
  5995. dev_warn(&pdev->dev,
  5996. "%s: Max WSA devices is 0 for this target?\n",
  5997. __func__);
  5998. card->num_aux_devs = 0;
  5999. return 0;
  6000. }
  6001. /* Get count of WSA device phandles for this platform */
  6002. wsa_dev_cnt = of_count_phandle_with_args(pdev->dev.of_node,
  6003. "qcom,wsa-devs", NULL);
  6004. if (wsa_dev_cnt == -ENOENT) {
  6005. dev_warn(&pdev->dev, "%s: No wsa device defined in DT.\n",
  6006. __func__);
  6007. goto err;
  6008. } else if (wsa_dev_cnt <= 0) {
  6009. dev_err(&pdev->dev,
  6010. "%s: Error reading wsa device from DT. wsa_dev_cnt = %d\n",
  6011. __func__, wsa_dev_cnt);
  6012. ret = -EINVAL;
  6013. goto err;
  6014. }
  6015. /*
  6016. * Expect total phandles count to be NOT less than maximum possible
  6017. * WSA count. However, if it is less, then assign same value to
  6018. * max count as well.
  6019. */
  6020. if (wsa_dev_cnt < wsa_max_devs) {
  6021. dev_dbg(&pdev->dev,
  6022. "%s: wsa_max_devs = %d cannot exceed wsa_dev_cnt = %d\n",
  6023. __func__, wsa_max_devs, wsa_dev_cnt);
  6024. wsa_max_devs = wsa_dev_cnt;
  6025. }
  6026. /* Make sure prefix string passed for each WSA device */
  6027. ret = of_property_count_strings(pdev->dev.of_node,
  6028. "qcom,wsa-aux-dev-prefix");
  6029. if (ret != wsa_dev_cnt) {
  6030. dev_err(&pdev->dev,
  6031. "%s: expecting %d wsa prefix. Defined only %d in DT\n",
  6032. __func__, wsa_dev_cnt, ret);
  6033. ret = -EINVAL;
  6034. goto err;
  6035. }
  6036. /*
  6037. * Alloc mem to store phandle and index info of WSA device, if already
  6038. * registered with ALSA core
  6039. */
  6040. wsa881x_dev_info = devm_kcalloc(&pdev->dev, wsa_max_devs,
  6041. sizeof(struct msm_wsa881x_dev_info),
  6042. GFP_KERNEL);
  6043. if (!wsa881x_dev_info) {
  6044. ret = -ENOMEM;
  6045. goto err;
  6046. }
  6047. /*
  6048. * search and check whether all WSA devices are already
  6049. * registered with ALSA core or not. If found a node, store
  6050. * the node and the index in a local array of struct for later
  6051. * use.
  6052. */
  6053. for (i = 0; i < wsa_dev_cnt; i++) {
  6054. wsa_of_node = of_parse_phandle(pdev->dev.of_node,
  6055. "qcom,wsa-devs", i);
  6056. if (unlikely(!wsa_of_node)) {
  6057. /* we should not be here */
  6058. dev_err(&pdev->dev,
  6059. "%s: wsa dev node is not present\n",
  6060. __func__);
  6061. ret = -EINVAL;
  6062. goto err_free_dev_info;
  6063. }
  6064. if (soc_find_component(wsa_of_node, NULL)) {
  6065. /* WSA device registered with ALSA core */
  6066. wsa881x_dev_info[found].of_node = wsa_of_node;
  6067. wsa881x_dev_info[found].index = i;
  6068. found++;
  6069. if (found == wsa_max_devs)
  6070. break;
  6071. }
  6072. }
  6073. if (found < wsa_max_devs) {
  6074. dev_dbg(&pdev->dev,
  6075. "%s: failed to find %d components. Found only %d\n",
  6076. __func__, wsa_max_devs, found);
  6077. return -EPROBE_DEFER;
  6078. }
  6079. dev_info(&pdev->dev,
  6080. "%s: found %d wsa881x devices registered with ALSA core\n",
  6081. __func__, found);
  6082. card->num_aux_devs = wsa_max_devs;
  6083. card->num_configs = wsa_max_devs;
  6084. /* Alloc array of AUX devs struct */
  6085. msm_aux_dev = devm_kcalloc(&pdev->dev, card->num_aux_devs,
  6086. sizeof(struct snd_soc_aux_dev),
  6087. GFP_KERNEL);
  6088. if (!msm_aux_dev) {
  6089. ret = -ENOMEM;
  6090. goto err_free_dev_info;
  6091. }
  6092. /* Alloc array of codec conf struct */
  6093. msm_codec_conf = devm_kcalloc(&pdev->dev, card->num_aux_devs,
  6094. sizeof(struct snd_soc_codec_conf),
  6095. GFP_KERNEL);
  6096. if (!msm_codec_conf) {
  6097. ret = -ENOMEM;
  6098. goto err_free_aux_dev;
  6099. }
  6100. for (i = 0; i < card->num_aux_devs; i++) {
  6101. dev_name_str = devm_kzalloc(&pdev->dev, DEV_NAME_STR_LEN,
  6102. GFP_KERNEL);
  6103. if (!dev_name_str) {
  6104. ret = -ENOMEM;
  6105. goto err_free_cdc_conf;
  6106. }
  6107. ret = of_property_read_string_index(pdev->dev.of_node,
  6108. "qcom,wsa-aux-dev-prefix",
  6109. wsa881x_dev_info[i].index,
  6110. wsa_auxdev_name_prefix);
  6111. if (ret) {
  6112. dev_err(&pdev->dev,
  6113. "%s: failed to read wsa aux dev prefix, ret = %d\n",
  6114. __func__, ret);
  6115. ret = -EINVAL;
  6116. goto err_free_dev_name_str;
  6117. }
  6118. snprintf(dev_name_str, strlen("wsa881x.%d"), "wsa881x.%d", i);
  6119. msm_aux_dev[i].name = dev_name_str;
  6120. msm_aux_dev[i].codec_name = NULL;
  6121. msm_aux_dev[i].codec_of_node =
  6122. wsa881x_dev_info[i].of_node;
  6123. msm_aux_dev[i].init = msm_wsa881x_init;
  6124. msm_codec_conf[i].dev_name = NULL;
  6125. msm_codec_conf[i].name_prefix = wsa_auxdev_name_prefix[0];
  6126. msm_codec_conf[i].of_node =
  6127. wsa881x_dev_info[i].of_node;
  6128. }
  6129. card->codec_conf = msm_codec_conf;
  6130. card->aux_dev = msm_aux_dev;
  6131. return 0;
  6132. err_free_dev_name_str:
  6133. devm_kfree(&pdev->dev, dev_name_str);
  6134. err_free_cdc_conf:
  6135. devm_kfree(&pdev->dev, msm_codec_conf);
  6136. err_free_aux_dev:
  6137. devm_kfree(&pdev->dev, msm_aux_dev);
  6138. err_free_dev_info:
  6139. devm_kfree(&pdev->dev, wsa881x_dev_info);
  6140. err:
  6141. return ret;
  6142. }
  6143. static void msm_i2s_auxpcm_init(struct platform_device *pdev)
  6144. {
  6145. struct resource *muxsel;
  6146. int count;
  6147. u32 mi2s_master_slave[MI2S_MAX];
  6148. int ret;
  6149. char *str[PCM_I2S_SEL_MAX] = {
  6150. "lpaif_pri_mode_muxsel",
  6151. "lpaif_sec_mode_muxsel",
  6152. "lpaif_tert_mode_muxsel",
  6153. "lpaif_quat_mode_muxsel"
  6154. };
  6155. for (count = 0; count < MI2S_MAX; count++) {
  6156. mutex_init(&mi2s_intf_conf[count].lock);
  6157. mi2s_intf_conf[count].ref_cnt = 0;
  6158. }
  6159. for (count = 0; count < AUX_PCM_MAX; count++) {
  6160. mutex_init(&auxpcm_intf_conf[count].lock);
  6161. auxpcm_intf_conf[count].ref_cnt = 0;
  6162. }
  6163. for (count = 0; count < PCM_I2S_SEL_MAX; count++) {
  6164. mutex_init(&mi2s_auxpcm_conf[count].lock);
  6165. mi2s_auxpcm_conf[count].pcm_i2s_sel_vt_addr = NULL;
  6166. }
  6167. for (count = 0; count < PCM_I2S_SEL_MAX; count++) {
  6168. muxsel = platform_get_resource_byname(pdev, IORESOURCE_MEM,
  6169. str[count]);
  6170. if (muxsel) {
  6171. mi2s_auxpcm_conf[count].pcm_i2s_sel_vt_addr
  6172. = ioremap(muxsel->start, resource_size(muxsel));
  6173. }
  6174. }
  6175. ret = of_property_read_u32_array(pdev->dev.of_node,
  6176. "qcom,msm-mi2s-master",
  6177. mi2s_master_slave, MI2S_MAX);
  6178. if (ret) {
  6179. dev_dbg(&pdev->dev, "%s: no qcom,msm-mi2s-master in DT node\n",
  6180. __func__);
  6181. } else {
  6182. for (count = 0; count < MI2S_MAX; count++) {
  6183. mi2s_intf_conf[count].msm_is_mi2s_master =
  6184. mi2s_master_slave[count];
  6185. }
  6186. }
  6187. }
  6188. static void msm_i2s_auxpcm_deinit(void)
  6189. {
  6190. int count;
  6191. for (count = 0; count < PCM_I2S_SEL_MAX; count++) {
  6192. if (mi2s_auxpcm_conf[count].pcm_i2s_sel_vt_addr !=
  6193. NULL) {
  6194. iounmap(
  6195. mi2s_auxpcm_conf[count].pcm_i2s_sel_vt_addr);
  6196. mi2s_auxpcm_conf[count].pcm_i2s_sel_vt_addr = NULL;
  6197. }
  6198. mutex_destroy(&mi2s_auxpcm_conf[count].lock);
  6199. }
  6200. for (count = 0; count < AUX_PCM_MAX; count++) {
  6201. mutex_destroy(&auxpcm_intf_conf[count].lock);
  6202. auxpcm_intf_conf[count].ref_cnt = 0;
  6203. }
  6204. for (count = 0; count < MI2S_MAX; count++) {
  6205. mutex_destroy(&mi2s_intf_conf[count].lock);
  6206. mi2s_intf_conf[count].ref_cnt = 0;
  6207. mi2s_intf_conf[count].msm_is_mi2s_master = 0;
  6208. }
  6209. }
  6210. static int msm_asoc_machine_probe(struct platform_device *pdev)
  6211. {
  6212. struct snd_soc_card *card;
  6213. struct msm_asoc_mach_data *pdata;
  6214. const char *mbhc_audio_jack_type = NULL;
  6215. char *mclk_freq_prop_name;
  6216. const struct of_device_id *match;
  6217. int ret;
  6218. const char *usb_c_dt = "qcom,msm-mbhc-usbc-audio-supported";
  6219. if (!pdev->dev.of_node) {
  6220. dev_err(&pdev->dev, "No platform supplied from device tree\n");
  6221. return -EINVAL;
  6222. }
  6223. pdata = devm_kzalloc(&pdev->dev,
  6224. sizeof(struct msm_asoc_mach_data), GFP_KERNEL);
  6225. if (!pdata)
  6226. return -ENOMEM;
  6227. card = populate_snd_card_dailinks(&pdev->dev);
  6228. if (!card) {
  6229. dev_err(&pdev->dev, "%s: Card uninitialized\n", __func__);
  6230. ret = -EINVAL;
  6231. goto err;
  6232. }
  6233. card->dev = &pdev->dev;
  6234. platform_set_drvdata(pdev, card);
  6235. snd_soc_card_set_drvdata(card, pdata);
  6236. ret = snd_soc_of_parse_card_name(card, "qcom,model");
  6237. if (ret) {
  6238. dev_err(&pdev->dev, "parse card name failed, err:%d\n",
  6239. ret);
  6240. goto err;
  6241. }
  6242. ret = snd_soc_of_parse_audio_routing(card, "qcom,audio-routing");
  6243. if (ret) {
  6244. dev_err(&pdev->dev, "parse audio routing failed, err:%d\n",
  6245. ret);
  6246. goto err;
  6247. }
  6248. match = of_match_node(sdm845_asoc_machine_of_match,
  6249. pdev->dev.of_node);
  6250. if (!match) {
  6251. dev_err(&pdev->dev, "%s: no matched codec is found.\n",
  6252. __func__);
  6253. goto err;
  6254. }
  6255. mclk_freq_prop_name = "qcom,tavil-mclk-clk-freq";
  6256. ret = of_property_read_u32(pdev->dev.of_node,
  6257. mclk_freq_prop_name, &pdata->mclk_freq);
  6258. if (ret) {
  6259. dev_err(&pdev->dev,
  6260. "Looking up %s property in node %s failed, err%d\n",
  6261. mclk_freq_prop_name,
  6262. pdev->dev.of_node->full_name, ret);
  6263. goto err;
  6264. }
  6265. if (pdata->mclk_freq != CODEC_EXT_CLK_RATE) {
  6266. dev_err(&pdev->dev, "unsupported mclk freq %u\n",
  6267. pdata->mclk_freq);
  6268. ret = -EINVAL;
  6269. goto err;
  6270. }
  6271. ret = msm_populate_dai_link_component_of_node(card);
  6272. if (ret) {
  6273. ret = -EPROBE_DEFER;
  6274. goto err;
  6275. }
  6276. ret = msm_init_wsa_dev(pdev, card);
  6277. if (ret)
  6278. goto err;
  6279. ret = devm_snd_soc_register_card(&pdev->dev, card);
  6280. if (ret == -EPROBE_DEFER) {
  6281. if (codec_reg_done)
  6282. ret = -EINVAL;
  6283. goto err;
  6284. } else if (ret) {
  6285. dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
  6286. ret);
  6287. goto err;
  6288. }
  6289. dev_info(&pdev->dev, "Sound card %s registered\n", card->name);
  6290. spdev = pdev;
  6291. ret = of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev);
  6292. if (ret) {
  6293. dev_dbg(&pdev->dev, "%s: failed to add child nodes, ret=%d\n",
  6294. __func__, ret);
  6295. } else {
  6296. pdata->hph_en1_gpio_p = of_parse_phandle(pdev->dev.of_node,
  6297. "qcom,hph-en1-gpio", 0);
  6298. if (!pdata->hph_en1_gpio_p) {
  6299. dev_dbg(&pdev->dev, "property %s not detected in node %s",
  6300. "qcom,hph-en1-gpio",
  6301. pdev->dev.of_node->full_name);
  6302. }
  6303. pdata->hph_en0_gpio_p = of_parse_phandle(pdev->dev.of_node,
  6304. "qcom,hph-en0-gpio", 0);
  6305. if (!pdata->hph_en0_gpio_p) {
  6306. dev_dbg(&pdev->dev, "property %s not detected in node %s",
  6307. "qcom,hph-en0-gpio",
  6308. pdev->dev.of_node->full_name);
  6309. }
  6310. }
  6311. ret = of_property_read_string(pdev->dev.of_node,
  6312. "qcom,mbhc-audio-jack-type", &mbhc_audio_jack_type);
  6313. if (ret) {
  6314. dev_dbg(&pdev->dev, "Looking up %s property in node %s failed",
  6315. "qcom,mbhc-audio-jack-type",
  6316. pdev->dev.of_node->full_name);
  6317. dev_dbg(&pdev->dev, "Jack type properties set to default");
  6318. } else {
  6319. if (!strcmp(mbhc_audio_jack_type, "4-pole-jack")) {
  6320. wcd_mbhc_cfg.enable_anc_mic_detect = false;
  6321. dev_dbg(&pdev->dev, "This hardware has 4 pole jack");
  6322. } else if (!strcmp(mbhc_audio_jack_type, "5-pole-jack")) {
  6323. wcd_mbhc_cfg.enable_anc_mic_detect = true;
  6324. dev_dbg(&pdev->dev, "This hardware has 5 pole jack");
  6325. } else if (!strcmp(mbhc_audio_jack_type, "6-pole-jack")) {
  6326. wcd_mbhc_cfg.enable_anc_mic_detect = true;
  6327. dev_dbg(&pdev->dev, "This hardware has 6 pole jack");
  6328. } else {
  6329. wcd_mbhc_cfg.enable_anc_mic_detect = false;
  6330. dev_dbg(&pdev->dev, "Unknown value, set to default");
  6331. }
  6332. }
  6333. /*
  6334. * Parse US-Euro gpio info from DT. Report no error if us-euro
  6335. * entry is not found in DT file as some targets do not support
  6336. * US-Euro detection
  6337. */
  6338. pdata->us_euro_gpio = of_get_named_gpio(pdev->dev.of_node,
  6339. "qcom,us-euro-gpios", 0);
  6340. if (!gpio_is_valid(pdata->us_euro_gpio))
  6341. pdata->us_euro_gpio_p = of_parse_phandle(pdev->dev.of_node,
  6342. "qcom,us-euro-gpios", 0);
  6343. if (!gpio_is_valid(pdata->us_euro_gpio) && (!pdata->us_euro_gpio_p)) {
  6344. dev_dbg(&pdev->dev, "property %s not detected in node %s",
  6345. "qcom,us-euro-gpios", pdev->dev.of_node->full_name);
  6346. } else {
  6347. dev_dbg(&pdev->dev, "%s detected",
  6348. "qcom,us-euro-gpios");
  6349. wcd_mbhc_cfg.swap_gnd_mic = msm_swap_gnd_mic;
  6350. }
  6351. if (of_find_property(pdev->dev.of_node, usb_c_dt, NULL))
  6352. wcd_mbhc_cfg.swap_gnd_mic = msm_swap_gnd_mic;
  6353. ret = msm_prepare_us_euro(card);
  6354. if (ret)
  6355. dev_dbg(&pdev->dev, "msm_prepare_us_euro failed (%d)\n",
  6356. ret);
  6357. /* Parse pinctrl info from devicetree */
  6358. ret = msm_get_pinctrl(pdev);
  6359. if (!ret) {
  6360. pr_debug("%s: pinctrl parsing successful\n", __func__);
  6361. } else {
  6362. dev_dbg(&pdev->dev,
  6363. "%s: Parsing pinctrl failed with %d. Cannot use Ports\n",
  6364. __func__, ret);
  6365. ret = 0;
  6366. }
  6367. msm_i2s_auxpcm_init(pdev);
  6368. is_initial_boot = true;
  6369. ret = audio_notifier_register("sdm845", AUDIO_NOTIFIER_ADSP_DOMAIN,
  6370. &service_nb);
  6371. if (ret < 0)
  6372. pr_err("%s: Audio notifier register failed ret = %d\n",
  6373. __func__, ret);
  6374. return 0;
  6375. err:
  6376. msm_release_pinctrl(pdev);
  6377. devm_kfree(&pdev->dev, pdata);
  6378. return ret;
  6379. }
  6380. static int msm_asoc_machine_remove(struct platform_device *pdev)
  6381. {
  6382. struct snd_soc_card *card = platform_get_drvdata(pdev);
  6383. struct msm_asoc_mach_data *pdata =
  6384. snd_soc_card_get_drvdata(card);
  6385. audio_notifier_deregister("sdm845");
  6386. if (pdata->us_euro_gpio > 0) {
  6387. gpio_free(pdata->us_euro_gpio);
  6388. pdata->us_euro_gpio = 0;
  6389. }
  6390. msm_i2s_auxpcm_deinit();
  6391. msm_release_pinctrl(pdev);
  6392. snd_soc_unregister_card(card);
  6393. return 0;
  6394. }
  6395. static struct platform_driver sdm845_asoc_machine_driver = {
  6396. .driver = {
  6397. .name = DRV_NAME,
  6398. .owner = THIS_MODULE,
  6399. .pm = &snd_soc_pm_ops,
  6400. .of_match_table = sdm845_asoc_machine_of_match,
  6401. },
  6402. .probe = msm_asoc_machine_probe,
  6403. .remove = msm_asoc_machine_remove,
  6404. };
  6405. module_platform_driver(sdm845_asoc_machine_driver);
  6406. MODULE_DESCRIPTION("ALSA SoC msm");
  6407. MODULE_LICENSE("GPL v2");
  6408. MODULE_ALIAS("platform:" DRV_NAME);
  6409. MODULE_DEVICE_TABLE(of, sdm845_asoc_machine_of_match);