sdm845.c 195 KB

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