sdm845.c 195 KB

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