msm8998.c 205 KB

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