sdm845.c 198 KB

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