wcd934x.c 339 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194
  1. /* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/init.h>
  14. #include <linux/firmware.h>
  15. #include <linux/slab.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/device.h>
  18. #include <linux/printk.h>
  19. #include <linux/ratelimit.h>
  20. #include <linux/debugfs.h>
  21. #include <linux/wait.h>
  22. #include <linux/bitops.h>
  23. #include <linux/clk.h>
  24. #include <linux/delay.h>
  25. #include <linux/pm_runtime.h>
  26. #include <linux/kernel.h>
  27. #include <linux/gpio.h>
  28. #include <linux/regmap.h>
  29. #include <linux/spi/spi.h>
  30. #include <linux/regulator/consumer.h>
  31. #include <linux/mfd/wcd9xxx/wcd9xxx_registers.h>
  32. #include <soc/swr-wcd.h>
  33. #include <soc/snd_event.h>
  34. #include <sound/pcm.h>
  35. #include <sound/pcm_params.h>
  36. #include <sound/soc.h>
  37. #include <sound/soc-dapm.h>
  38. #include <sound/tlv.h>
  39. #include <sound/info.h>
  40. #include <asoc/wcd934x_registers.h>
  41. #include "wcd934x.h"
  42. #include "wcd934x-mbhc.h"
  43. #include "wcd934x-routing.h"
  44. #include "wcd934x-dsp-cntl.h"
  45. #include "wcd934x_irq.h"
  46. #include "../core.h"
  47. #include "../pdata.h"
  48. #include "../wcd9xxx-irq.h"
  49. #include "../wcd9xxx-common-v2.h"
  50. #include "../wcd9xxx-resmgr-v2.h"
  51. #include "../wcdcal-hwdep.h"
  52. #include "wcd934x-dsd.h"
  53. #define WCD934X_RATES_MASK (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
  54. SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\
  55. SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000 |\
  56. SNDRV_PCM_RATE_384000)
  57. /* Fractional Rates */
  58. #define WCD934X_FRAC_RATES_MASK (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_88200 |\
  59. SNDRV_PCM_RATE_176400)
  60. #define WCD934X_FORMATS_S16_S24_LE (SNDRV_PCM_FMTBIT_S16_LE | \
  61. SNDRV_PCM_FMTBIT_S24_LE)
  62. #define WCD934X_FORMATS_S16_S24_S32_LE (SNDRV_PCM_FMTBIT_S16_LE | \
  63. SNDRV_PCM_FMTBIT_S24_LE | \
  64. SNDRV_PCM_FMTBIT_S32_LE)
  65. #define WCD934X_FORMATS_S16_LE (SNDRV_PCM_FMTBIT_S16_LE)
  66. #define MICB_LOAD_PROP "qcom,vreg-micb"
  67. #define MICB_LOAD_DEFAULT 30400
  68. /* Macros for packing register writes into a U32 */
  69. #define WCD934X_PACKED_REG_SIZE sizeof(u32)
  70. #define WCD934X_CODEC_UNPACK_ENTRY(packed, reg, mask, val) \
  71. do { \
  72. ((reg) = ((packed >> 16) & (0xffff))); \
  73. ((mask) = ((packed >> 8) & (0xff))); \
  74. ((val) = ((packed) & (0xff))); \
  75. } while (0)
  76. #define STRING(name) #name
  77. #define WCD_DAPM_ENUM(name, reg, offset, text) \
  78. static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
  79. static const struct snd_kcontrol_new name##_mux = \
  80. SOC_DAPM_ENUM(STRING(name), name##_enum)
  81. #define WCD_DAPM_ENUM_EXT(name, reg, offset, text, getname, putname) \
  82. static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
  83. static const struct snd_kcontrol_new name##_mux = \
  84. SOC_DAPM_ENUM_EXT(STRING(name), name##_enum, getname, putname)
  85. #define WCD_DAPM_MUX(name, shift, kctl) \
  86. SND_SOC_DAPM_MUX(name, SND_SOC_NOPM, shift, 0, &kctl##_mux)
  87. /*
  88. * Timeout in milli seconds and it is the wait time for
  89. * slim channel removal interrupt to receive.
  90. */
  91. #define WCD934X_SLIM_CLOSE_TIMEOUT 1000
  92. #define WCD934X_SLIM_IRQ_OVERFLOW (1 << 0)
  93. #define WCD934X_SLIM_IRQ_UNDERFLOW (1 << 1)
  94. #define WCD934X_SLIM_IRQ_PORT_CLOSED (1 << 2)
  95. #define WCD934X_MCLK_CLK_12P288MHZ 12288000
  96. #define WCD934X_MCLK_CLK_9P6MHZ 9600000
  97. #define WCD934X_INTERP_MUX_NUM_INPUTS 3
  98. #define WCD934X_NUM_INTERPOLATORS 9
  99. #define WCD934X_NUM_DECIMATORS 9
  100. #define WCD934X_RX_PATH_CTL_OFFSET 20
  101. #define BYTE_BIT_MASK(nr) (1 << ((nr) % BITS_PER_BYTE))
  102. #define WCD934X_REG_BITS 8
  103. #define WCD934X_MAX_VALID_ADC_MUX 13
  104. #define WCD934X_INVALID_ADC_MUX 9
  105. #define WCD934X_AMIC_PWR_LEVEL_LP 0
  106. #define WCD934X_AMIC_PWR_LEVEL_DEFAULT 1
  107. #define WCD934X_AMIC_PWR_LEVEL_HP 2
  108. #define WCD934X_AMIC_PWR_LEVEL_HYBRID 3
  109. #define WCD934X_AMIC_PWR_LVL_MASK 0x60
  110. #define WCD934X_AMIC_PWR_LVL_SHIFT 0x5
  111. #define WCD934X_DEC_PWR_LVL_MASK 0x06
  112. #define WCD934X_DEC_PWR_LVL_LP 0x02
  113. #define WCD934X_DEC_PWR_LVL_HP 0x04
  114. #define WCD934X_DEC_PWR_LVL_DF 0x00
  115. #define WCD934X_DEC_PWR_LVL_HYBRID WCD934X_DEC_PWR_LVL_DF
  116. #define WCD934X_STRING_LEN 100
  117. #define WCD934X_CDC_SIDETONE_IIR_COEFF_MAX 5
  118. #define WCD934X_CDC_REPEAT_WRITES_MAX 16
  119. #define WCD934X_DIG_CORE_REG_MIN WCD934X_CDC_ANC0_CLK_RESET_CTL
  120. #define WCD934X_DIG_CORE_REG_MAX 0xFFF
  121. #define WCD934X_CHILD_DEVICES_MAX 6
  122. #define WCD934X_MAX_MICBIAS 4
  123. #define DAPM_MICBIAS1_STANDALONE "MIC BIAS1 Standalone"
  124. #define DAPM_MICBIAS2_STANDALONE "MIC BIAS2 Standalone"
  125. #define DAPM_MICBIAS3_STANDALONE "MIC BIAS3 Standalone"
  126. #define DAPM_MICBIAS4_STANDALONE "MIC BIAS4 Standalone"
  127. #define TX_HPF_CUT_OFF_FREQ_MASK 0x60
  128. #define CF_MIN_3DB_4HZ 0x0
  129. #define CF_MIN_3DB_75HZ 0x1
  130. #define CF_MIN_3DB_150HZ 0x2
  131. #define CPE_ERR_WDOG_BITE BIT(0)
  132. #define CPE_FATAL_IRQS CPE_ERR_WDOG_BITE
  133. #define WCD934X_MAD_AUDIO_FIRMWARE_PATH "wcd934x/wcd934x_mad_audio.bin"
  134. #define TAVIL_VERSION_ENTRY_SIZE 17
  135. #define WCD934X_DIG_CORE_COLLAPSE_TIMER_MS (5 * 1000)
  136. enum {
  137. POWER_COLLAPSE,
  138. POWER_RESUME,
  139. };
  140. static int dig_core_collapse_enable = 1;
  141. module_param(dig_core_collapse_enable, int, 0664);
  142. MODULE_PARM_DESC(dig_core_collapse_enable, "enable/disable power gating");
  143. /* dig_core_collapse timer in seconds */
  144. static int dig_core_collapse_timer = (WCD934X_DIG_CORE_COLLAPSE_TIMER_MS/1000);
  145. module_param(dig_core_collapse_timer, int, 0664);
  146. MODULE_PARM_DESC(dig_core_collapse_timer, "timer for power gating");
  147. #define TAVIL_HPH_REG_RANGE_1 (WCD934X_HPH_R_DAC_CTL - WCD934X_HPH_CNP_EN + 1)
  148. #define TAVIL_HPH_REG_RANGE_2 (WCD934X_HPH_NEW_ANA_HPH3 -\
  149. WCD934X_HPH_NEW_ANA_HPH2 + 1)
  150. #define TAVIL_HPH_REG_RANGE_3 (WCD934X_HPH_NEW_INT_PA_RDAC_MISC3 -\
  151. WCD934X_HPH_NEW_INT_RDAC_GAIN_CTL + 1)
  152. #define TAVIL_HPH_TOTAL_REG (TAVIL_HPH_REG_RANGE_1 + TAVIL_HPH_REG_RANGE_2 +\
  153. TAVIL_HPH_REG_RANGE_3)
  154. enum {
  155. VI_SENSE_1,
  156. VI_SENSE_2,
  157. AUDIO_NOMINAL,
  158. HPH_PA_DELAY,
  159. CLSH_Z_CONFIG,
  160. ANC_MIC_AMIC1,
  161. ANC_MIC_AMIC2,
  162. ANC_MIC_AMIC3,
  163. ANC_MIC_AMIC4,
  164. CLK_INTERNAL,
  165. CLK_MODE,
  166. };
  167. enum {
  168. AIF1_PB = 0,
  169. AIF1_CAP,
  170. AIF2_PB,
  171. AIF2_CAP,
  172. AIF3_PB,
  173. AIF3_CAP,
  174. AIF4_PB,
  175. AIF4_VIFEED,
  176. AIF4_MAD_TX,
  177. NUM_CODEC_DAIS,
  178. };
  179. enum {
  180. INTn_1_INP_SEL_ZERO = 0,
  181. INTn_1_INP_SEL_DEC0,
  182. INTn_1_INP_SEL_DEC1,
  183. INTn_1_INP_SEL_IIR0,
  184. INTn_1_INP_SEL_IIR1,
  185. INTn_1_INP_SEL_RX0,
  186. INTn_1_INP_SEL_RX1,
  187. INTn_1_INP_SEL_RX2,
  188. INTn_1_INP_SEL_RX3,
  189. INTn_1_INP_SEL_RX4,
  190. INTn_1_INP_SEL_RX5,
  191. INTn_1_INP_SEL_RX6,
  192. INTn_1_INP_SEL_RX7,
  193. };
  194. enum {
  195. INTn_2_INP_SEL_ZERO = 0,
  196. INTn_2_INP_SEL_RX0,
  197. INTn_2_INP_SEL_RX1,
  198. INTn_2_INP_SEL_RX2,
  199. INTn_2_INP_SEL_RX3,
  200. INTn_2_INP_SEL_RX4,
  201. INTn_2_INP_SEL_RX5,
  202. INTn_2_INP_SEL_RX6,
  203. INTn_2_INP_SEL_RX7,
  204. INTn_2_INP_SEL_PROXIMITY,
  205. };
  206. enum {
  207. INTERP_MAIN_PATH,
  208. INTERP_MIX_PATH,
  209. };
  210. struct tavil_idle_detect_config {
  211. u8 hph_idle_thr;
  212. u8 hph_idle_detect_en;
  213. };
  214. struct tavil_cpr_reg_defaults {
  215. int wr_data;
  216. int wr_addr;
  217. };
  218. struct interp_sample_rate {
  219. int sample_rate;
  220. int rate_val;
  221. };
  222. static struct interp_sample_rate sr_val_tbl[] = {
  223. {8000, 0x0}, {16000, 0x1}, {32000, 0x3}, {48000, 0x4}, {96000, 0x5},
  224. {192000, 0x6}, {384000, 0x7}, {44100, 0x9}, {88200, 0xA},
  225. {176400, 0xB}, {352800, 0xC},
  226. };
  227. static const struct wcd9xxx_ch tavil_rx_chs[WCD934X_RX_MAX] = {
  228. WCD9XXX_CH(WCD934X_RX_PORT_START_NUMBER, 0),
  229. WCD9XXX_CH(WCD934X_RX_PORT_START_NUMBER + 1, 1),
  230. WCD9XXX_CH(WCD934X_RX_PORT_START_NUMBER + 2, 2),
  231. WCD9XXX_CH(WCD934X_RX_PORT_START_NUMBER + 3, 3),
  232. WCD9XXX_CH(WCD934X_RX_PORT_START_NUMBER + 4, 4),
  233. WCD9XXX_CH(WCD934X_RX_PORT_START_NUMBER + 5, 5),
  234. WCD9XXX_CH(WCD934X_RX_PORT_START_NUMBER + 6, 6),
  235. WCD9XXX_CH(WCD934X_RX_PORT_START_NUMBER + 7, 7),
  236. };
  237. static const struct wcd9xxx_ch tavil_tx_chs[WCD934X_TX_MAX] = {
  238. WCD9XXX_CH(0, 0),
  239. WCD9XXX_CH(1, 1),
  240. WCD9XXX_CH(2, 2),
  241. WCD9XXX_CH(3, 3),
  242. WCD9XXX_CH(4, 4),
  243. WCD9XXX_CH(5, 5),
  244. WCD9XXX_CH(6, 6),
  245. WCD9XXX_CH(7, 7),
  246. WCD9XXX_CH(8, 8),
  247. WCD9XXX_CH(9, 9),
  248. WCD9XXX_CH(10, 10),
  249. WCD9XXX_CH(11, 11),
  250. WCD9XXX_CH(12, 12),
  251. WCD9XXX_CH(13, 13),
  252. WCD9XXX_CH(14, 14),
  253. WCD9XXX_CH(15, 15),
  254. };
  255. static const u32 vport_slim_check_table[NUM_CODEC_DAIS] = {
  256. 0, /* AIF1_PB */
  257. BIT(AIF2_CAP) | BIT(AIF3_CAP) | BIT(AIF4_MAD_TX), /* AIF1_CAP */
  258. 0, /* AIF2_PB */
  259. BIT(AIF1_CAP) | BIT(AIF3_CAP) | BIT(AIF4_MAD_TX), /* AIF2_CAP */
  260. 0, /* AIF3_PB */
  261. BIT(AIF1_CAP) | BIT(AIF2_CAP) | BIT(AIF4_MAD_TX), /* AIF3_CAP */
  262. 0, /* AIF4_PB */
  263. };
  264. /* Codec supports 2 IIR filters */
  265. enum {
  266. IIR0 = 0,
  267. IIR1,
  268. IIR_MAX,
  269. };
  270. /* Each IIR has 5 Filter Stages */
  271. enum {
  272. BAND1 = 0,
  273. BAND2,
  274. BAND3,
  275. BAND4,
  276. BAND5,
  277. BAND_MAX,
  278. };
  279. enum {
  280. COMPANDER_1, /* HPH_L */
  281. COMPANDER_2, /* HPH_R */
  282. COMPANDER_3, /* LO1_DIFF */
  283. COMPANDER_4, /* LO2_DIFF */
  284. COMPANDER_5, /* LO3_SE - not used in Tavil */
  285. COMPANDER_6, /* LO4_SE - not used in Tavil */
  286. COMPANDER_7, /* SWR SPK CH1 */
  287. COMPANDER_8, /* SWR SPK CH2 */
  288. COMPANDER_MAX,
  289. };
  290. enum {
  291. ASRC_IN_HPHL,
  292. ASRC_IN_LO1,
  293. ASRC_IN_HPHR,
  294. ASRC_IN_LO2,
  295. ASRC_IN_SPKR1,
  296. ASRC_IN_SPKR2,
  297. ASRC_INVALID,
  298. };
  299. enum {
  300. ASRC0,
  301. ASRC1,
  302. ASRC2,
  303. ASRC3,
  304. ASRC_MAX,
  305. };
  306. enum {
  307. CONV_88P2K_TO_384K,
  308. CONV_96K_TO_352P8K,
  309. CONV_352P8K_TO_384K,
  310. CONV_384K_TO_352P8K,
  311. CONV_384K_TO_384K,
  312. CONV_96K_TO_384K,
  313. };
  314. static struct afe_param_slimbus_slave_port_cfg tavil_slimbus_slave_port_cfg = {
  315. .minor_version = 1,
  316. .slimbus_dev_id = AFE_SLIMBUS_DEVICE_1,
  317. .slave_dev_pgd_la = 0,
  318. .slave_dev_intfdev_la = 0,
  319. .bit_width = 16,
  320. .data_format = 0,
  321. .num_channels = 1
  322. };
  323. static struct afe_param_cdc_reg_page_cfg tavil_cdc_reg_page_cfg = {
  324. .minor_version = AFE_API_VERSION_CDC_REG_PAGE_CFG,
  325. .enable = 1,
  326. .proc_id = AFE_CDC_REG_PAGE_ASSIGN_PROC_ID_1,
  327. };
  328. static struct afe_param_cdc_reg_cfg audio_reg_cfg[] = {
  329. {
  330. 1,
  331. (WCD934X_REGISTER_START_OFFSET + WCD934X_SOC_MAD_MAIN_CTL_1),
  332. HW_MAD_AUDIO_ENABLE, 0x1, WCD934X_REG_BITS, 0
  333. },
  334. {
  335. 1,
  336. (WCD934X_REGISTER_START_OFFSET + WCD934X_SOC_MAD_AUDIO_CTL_3),
  337. HW_MAD_AUDIO_SLEEP_TIME, 0xF, WCD934X_REG_BITS, 0
  338. },
  339. {
  340. 1,
  341. (WCD934X_REGISTER_START_OFFSET + WCD934X_SOC_MAD_AUDIO_CTL_4),
  342. HW_MAD_TX_AUDIO_SWITCH_OFF, 0x1, WCD934X_REG_BITS, 0
  343. },
  344. {
  345. 1,
  346. (WCD934X_REGISTER_START_OFFSET + WCD934X_INTR_CFG),
  347. MAD_AUDIO_INT_DEST_SELECT_REG, 0x2, WCD934X_REG_BITS, 0
  348. },
  349. {
  350. 1,
  351. (WCD934X_REGISTER_START_OFFSET + WCD934X_INTR_PIN2_MASK3),
  352. MAD_AUDIO_INT_MASK_REG, 0x1, WCD934X_REG_BITS, 0
  353. },
  354. {
  355. 1,
  356. (WCD934X_REGISTER_START_OFFSET + WCD934X_INTR_PIN2_STATUS3),
  357. MAD_AUDIO_INT_STATUS_REG, 0x1, WCD934X_REG_BITS, 0
  358. },
  359. {
  360. 1,
  361. (WCD934X_REGISTER_START_OFFSET + WCD934X_INTR_PIN2_CLEAR3),
  362. MAD_AUDIO_INT_CLEAR_REG, 0x1, WCD934X_REG_BITS, 0
  363. },
  364. {
  365. 1,
  366. (WCD934X_REGISTER_START_OFFSET + WCD934X_SB_PGD_PORT_TX_BASE),
  367. SB_PGD_PORT_TX_WATERMARK_N, 0x1E, WCD934X_REG_BITS, 0x1
  368. },
  369. {
  370. 1,
  371. (WCD934X_REGISTER_START_OFFSET + WCD934X_SB_PGD_PORT_TX_BASE),
  372. SB_PGD_PORT_TX_ENABLE_N, 0x1, WCD934X_REG_BITS, 0x1
  373. },
  374. {
  375. 1,
  376. (WCD934X_REGISTER_START_OFFSET + WCD934X_SB_PGD_PORT_RX_BASE),
  377. SB_PGD_PORT_RX_WATERMARK_N, 0x1E, WCD934X_REG_BITS, 0x1
  378. },
  379. {
  380. 1,
  381. (WCD934X_REGISTER_START_OFFSET + WCD934X_SB_PGD_PORT_RX_BASE),
  382. SB_PGD_PORT_RX_ENABLE_N, 0x1, WCD934X_REG_BITS, 0x1
  383. },
  384. {
  385. 1,
  386. (WCD934X_REGISTER_START_OFFSET +
  387. WCD934X_CDC_ANC0_IIR_ADAPT_CTL),
  388. AANC_FF_GAIN_ADAPTIVE, 0x4, WCD934X_REG_BITS, 0
  389. },
  390. {
  391. 1,
  392. (WCD934X_REGISTER_START_OFFSET +
  393. WCD934X_CDC_ANC0_IIR_ADAPT_CTL),
  394. AANC_FFGAIN_ADAPTIVE_EN, 0x8, WCD934X_REG_BITS, 0
  395. },
  396. {
  397. 1,
  398. (WCD934X_REGISTER_START_OFFSET +
  399. WCD934X_CDC_ANC0_FF_A_GAIN_CTL),
  400. AANC_GAIN_CONTROL, 0xFF, WCD934X_REG_BITS, 0
  401. },
  402. {
  403. 1,
  404. (WCD934X_REGISTER_START_OFFSET +
  405. SB_PGD_TX_PORT_MULTI_CHANNEL_0(0)),
  406. SB_PGD_TX_PORTn_MULTI_CHNL_0, 0xFF, WCD934X_REG_BITS, 0x4
  407. },
  408. {
  409. 1,
  410. (WCD934X_REGISTER_START_OFFSET +
  411. SB_PGD_TX_PORT_MULTI_CHANNEL_1(0)),
  412. SB_PGD_TX_PORTn_MULTI_CHNL_1, 0xFF, WCD934X_REG_BITS, 0x4
  413. },
  414. {
  415. 1,
  416. (WCD934X_REGISTER_START_OFFSET +
  417. SB_PGD_RX_PORT_MULTI_CHANNEL_0(0x180, 0)),
  418. SB_PGD_RX_PORTn_MULTI_CHNL_0, 0xFF, WCD934X_REG_BITS, 0x4
  419. },
  420. {
  421. 1,
  422. (WCD934X_REGISTER_START_OFFSET +
  423. SB_PGD_RX_PORT_MULTI_CHANNEL_0(0x181, 0)),
  424. SB_PGD_RX_PORTn_MULTI_CHNL_1, 0xFF, WCD934X_REG_BITS, 0x4
  425. },
  426. };
  427. static struct afe_param_cdc_reg_cfg_data tavil_audio_reg_cfg = {
  428. .num_registers = ARRAY_SIZE(audio_reg_cfg),
  429. .reg_data = audio_reg_cfg,
  430. };
  431. static struct afe_param_id_cdc_aanc_version tavil_cdc_aanc_version = {
  432. .cdc_aanc_minor_version = AFE_API_VERSION_CDC_AANC_VERSION,
  433. .aanc_hw_version = AANC_HW_BLOCK_VERSION_2,
  434. };
  435. static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0);
  436. static const DECLARE_TLV_DB_SCALE(line_gain, 0, 7, 1);
  437. static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 25, 1);
  438. #define WCD934X_TX_UNMUTE_DELAY_MS 40
  439. static int tx_unmute_delay = WCD934X_TX_UNMUTE_DELAY_MS;
  440. module_param(tx_unmute_delay, int, 0664);
  441. MODULE_PARM_DESC(tx_unmute_delay, "delay to unmute the tx path");
  442. static void tavil_codec_set_tx_hold(struct snd_soc_codec *, u16, bool);
  443. /* Hold instance to soundwire platform device */
  444. struct tavil_swr_ctrl_data {
  445. struct platform_device *swr_pdev;
  446. };
  447. struct wcd_swr_ctrl_platform_data {
  448. void *handle; /* holds codec private data */
  449. int (*read)(void *handle, int reg);
  450. int (*write)(void *handle, int reg, int val);
  451. int (*bulk_write)(void *handle, u32 *reg, u32 *val, size_t len);
  452. int (*clk)(void *handle, bool enable);
  453. int (*handle_irq)(void *handle,
  454. irqreturn_t (*swrm_irq_handler)(int irq, void *data),
  455. void *swrm_handle, int action);
  456. };
  457. /* Holds all Soundwire and speaker related information */
  458. struct wcd934x_swr {
  459. struct tavil_swr_ctrl_data *ctrl_data;
  460. struct wcd_swr_ctrl_platform_data plat_data;
  461. struct mutex read_mutex;
  462. struct mutex write_mutex;
  463. struct mutex clk_mutex;
  464. int spkr_gain_offset;
  465. int spkr_mode;
  466. int clk_users;
  467. int rx_7_count;
  468. int rx_8_count;
  469. };
  470. struct tx_mute_work {
  471. struct tavil_priv *tavil;
  472. u8 decimator;
  473. struct delayed_work dwork;
  474. };
  475. #define WCD934X_SPK_ANC_EN_DELAY_MS 550
  476. static int spk_anc_en_delay = WCD934X_SPK_ANC_EN_DELAY_MS;
  477. module_param(spk_anc_en_delay, int, 0664);
  478. MODULE_PARM_DESC(spk_anc_en_delay, "delay to enable anc in speaker path");
  479. struct spk_anc_work {
  480. struct tavil_priv *tavil;
  481. struct delayed_work dwork;
  482. };
  483. struct hpf_work {
  484. struct tavil_priv *tavil;
  485. u8 decimator;
  486. u8 hpf_cut_off_freq;
  487. struct delayed_work dwork;
  488. };
  489. struct tavil_priv {
  490. struct device *dev;
  491. struct wcd9xxx *wcd9xxx;
  492. struct snd_soc_codec *codec;
  493. u32 rx_bias_count;
  494. s32 dmic_0_1_clk_cnt;
  495. s32 dmic_2_3_clk_cnt;
  496. s32 dmic_4_5_clk_cnt;
  497. s32 micb_ref[TAVIL_MAX_MICBIAS];
  498. s32 pullup_ref[TAVIL_MAX_MICBIAS];
  499. /* ANC related */
  500. u32 anc_slot;
  501. bool anc_func;
  502. /* compander */
  503. int comp_enabled[COMPANDER_MAX];
  504. int ear_spkr_gain;
  505. /* class h specific data */
  506. struct wcd_clsh_cdc_data clsh_d;
  507. /* Tavil Interpolator Mode Select for EAR, HPH_L and HPH_R */
  508. u32 hph_mode;
  509. /* Mad switch reference count */
  510. int mad_switch_cnt;
  511. /* track tavil interface type */
  512. u8 intf_type;
  513. /* to track the status */
  514. unsigned long status_mask;
  515. struct afe_param_cdc_slimbus_slave_cfg slimbus_slave_cfg;
  516. /* num of slim ports required */
  517. struct wcd9xxx_codec_dai_data dai[NUM_CODEC_DAIS];
  518. /* Port values for Rx and Tx codec_dai */
  519. unsigned int rx_port_value[WCD934X_RX_MAX];
  520. unsigned int tx_port_value;
  521. struct wcd9xxx_resmgr_v2 *resmgr;
  522. struct wcd934x_swr swr;
  523. struct mutex micb_lock;
  524. struct delayed_work power_gate_work;
  525. struct mutex power_lock;
  526. struct clk *wcd_ext_clk;
  527. /* mbhc module */
  528. struct wcd934x_mbhc *mbhc;
  529. struct mutex codec_mutex;
  530. struct work_struct tavil_add_child_devices_work;
  531. struct hpf_work tx_hpf_work[WCD934X_NUM_DECIMATORS];
  532. struct tx_mute_work tx_mute_dwork[WCD934X_NUM_DECIMATORS];
  533. struct spk_anc_work spk_anc_dwork;
  534. unsigned int vi_feed_value;
  535. /* DSP control */
  536. struct wcd_dsp_cntl *wdsp_cntl;
  537. /* cal info for codec */
  538. struct fw_info *fw_data;
  539. /* Entry for version info */
  540. struct snd_info_entry *entry;
  541. struct snd_info_entry *version_entry;
  542. /* SVS voting related */
  543. struct mutex svs_mutex;
  544. int svs_ref_cnt;
  545. int native_clk_users;
  546. /* ASRC users count */
  547. int asrc_users[ASRC_MAX];
  548. int asrc_output_mode[ASRC_MAX];
  549. /* Main path clock users count */
  550. int main_clk_users[WCD934X_NUM_INTERPOLATORS];
  551. struct tavil_dsd_config *dsd_config;
  552. struct tavil_idle_detect_config idle_det_cfg;
  553. int power_active_ref;
  554. u8 sidetone_coeff_array[IIR_MAX][BAND_MAX]
  555. [WCD934X_CDC_SIDETONE_IIR_COEFF_MAX * 4];
  556. struct spi_device *spi;
  557. struct platform_device *pdev_child_devices
  558. [WCD934X_CHILD_DEVICES_MAX];
  559. int child_count;
  560. struct regulator *micb_load;
  561. int micb_load_low;
  562. int micb_load_high;
  563. };
  564. static const struct tavil_reg_mask_val tavil_spkr_default[] = {
  565. {WCD934X_CDC_COMPANDER7_CTL3, 0x80, 0x80},
  566. {WCD934X_CDC_COMPANDER8_CTL3, 0x80, 0x80},
  567. {WCD934X_CDC_COMPANDER7_CTL7, 0x01, 0x01},
  568. {WCD934X_CDC_COMPANDER8_CTL7, 0x01, 0x01},
  569. {WCD934X_CDC_BOOST0_BOOST_CTL, 0x7C, 0x58},
  570. {WCD934X_CDC_BOOST1_BOOST_CTL, 0x7C, 0x58},
  571. };
  572. static const struct tavil_reg_mask_val tavil_spkr_mode1[] = {
  573. {WCD934X_CDC_COMPANDER7_CTL3, 0x80, 0x00},
  574. {WCD934X_CDC_COMPANDER8_CTL3, 0x80, 0x00},
  575. {WCD934X_CDC_COMPANDER7_CTL7, 0x01, 0x00},
  576. {WCD934X_CDC_COMPANDER8_CTL7, 0x01, 0x00},
  577. {WCD934X_CDC_BOOST0_BOOST_CTL, 0x7C, 0x44},
  578. {WCD934X_CDC_BOOST1_BOOST_CTL, 0x7C, 0x44},
  579. };
  580. static int __tavil_enable_efuse_sensing(struct tavil_priv *tavil);
  581. /**
  582. * tavil_set_spkr_gain_offset - offset the speaker path
  583. * gain with the given offset value.
  584. *
  585. * @codec: codec instance
  586. * @offset: Indicates speaker path gain offset value.
  587. *
  588. * Returns 0 on success or -EINVAL on error.
  589. */
  590. int tavil_set_spkr_gain_offset(struct snd_soc_codec *codec, int offset)
  591. {
  592. struct tavil_priv *priv = snd_soc_codec_get_drvdata(codec);
  593. if (!priv)
  594. return -EINVAL;
  595. priv->swr.spkr_gain_offset = offset;
  596. return 0;
  597. }
  598. EXPORT_SYMBOL(tavil_set_spkr_gain_offset);
  599. /**
  600. * tavil_set_spkr_mode - Configures speaker compander and smartboost
  601. * settings based on speaker mode.
  602. *
  603. * @codec: codec instance
  604. * @mode: Indicates speaker configuration mode.
  605. *
  606. * Returns 0 on success or -EINVAL on error.
  607. */
  608. int tavil_set_spkr_mode(struct snd_soc_codec *codec, int mode)
  609. {
  610. struct tavil_priv *priv = snd_soc_codec_get_drvdata(codec);
  611. int i;
  612. const struct tavil_reg_mask_val *regs;
  613. int size;
  614. if (!priv)
  615. return -EINVAL;
  616. switch (mode) {
  617. case WCD934X_SPKR_MODE_1:
  618. regs = tavil_spkr_mode1;
  619. size = ARRAY_SIZE(tavil_spkr_mode1);
  620. break;
  621. default:
  622. regs = tavil_spkr_default;
  623. size = ARRAY_SIZE(tavil_spkr_default);
  624. break;
  625. }
  626. priv->swr.spkr_mode = mode;
  627. for (i = 0; i < size; i++)
  628. snd_soc_update_bits(codec, regs[i].reg,
  629. regs[i].mask, regs[i].val);
  630. return 0;
  631. }
  632. EXPORT_SYMBOL(tavil_set_spkr_mode);
  633. /**
  634. * tavil_get_afe_config - returns specific codec configuration to afe to write
  635. *
  636. * @codec: codec instance
  637. * @config_type: Indicates type of configuration to write.
  638. */
  639. void *tavil_get_afe_config(struct snd_soc_codec *codec,
  640. enum afe_config_type config_type)
  641. {
  642. struct tavil_priv *priv = snd_soc_codec_get_drvdata(codec);
  643. switch (config_type) {
  644. case AFE_SLIMBUS_SLAVE_CONFIG:
  645. return &priv->slimbus_slave_cfg;
  646. case AFE_CDC_REGISTERS_CONFIG:
  647. return &tavil_audio_reg_cfg;
  648. case AFE_SLIMBUS_SLAVE_PORT_CONFIG:
  649. return &tavil_slimbus_slave_port_cfg;
  650. case AFE_AANC_VERSION:
  651. return &tavil_cdc_aanc_version;
  652. case AFE_CDC_REGISTER_PAGE_CONFIG:
  653. return &tavil_cdc_reg_page_cfg;
  654. default:
  655. dev_info(codec->dev, "%s: Unknown config_type 0x%x\n",
  656. __func__, config_type);
  657. return NULL;
  658. }
  659. }
  660. EXPORT_SYMBOL(tavil_get_afe_config);
  661. static bool is_tavil_playback_dai(int dai_id)
  662. {
  663. if ((dai_id == AIF1_PB) || (dai_id == AIF2_PB) ||
  664. (dai_id == AIF3_PB) || (dai_id == AIF4_PB))
  665. return true;
  666. return false;
  667. }
  668. static int tavil_find_playback_dai_id_for_port(int port_id,
  669. struct tavil_priv *tavil)
  670. {
  671. struct wcd9xxx_codec_dai_data *dai;
  672. struct wcd9xxx_ch *ch;
  673. int i, slv_port_id;
  674. for (i = AIF1_PB; i < NUM_CODEC_DAIS; i++) {
  675. if (!is_tavil_playback_dai(i))
  676. continue;
  677. dai = &tavil->dai[i];
  678. list_for_each_entry(ch, &dai->wcd9xxx_ch_list, list) {
  679. slv_port_id = wcd9xxx_get_slave_port(ch->ch_num);
  680. if ((slv_port_id > 0) && (slv_port_id == port_id))
  681. return i;
  682. }
  683. }
  684. return -EINVAL;
  685. }
  686. static void tavil_vote_svs(struct tavil_priv *tavil, bool vote)
  687. {
  688. struct wcd9xxx *wcd9xxx;
  689. wcd9xxx = tavil->wcd9xxx;
  690. mutex_lock(&tavil->svs_mutex);
  691. if (vote) {
  692. tavil->svs_ref_cnt++;
  693. if (tavil->svs_ref_cnt == 1)
  694. regmap_update_bits(wcd9xxx->regmap,
  695. WCD934X_CPE_SS_PWR_SYS_PSTATE_CTL_0,
  696. 0x01, 0x01);
  697. } else {
  698. /* Do not decrement ref count if it is already 0 */
  699. if (tavil->svs_ref_cnt == 0)
  700. goto done;
  701. tavil->svs_ref_cnt--;
  702. if (tavil->svs_ref_cnt == 0)
  703. regmap_update_bits(wcd9xxx->regmap,
  704. WCD934X_CPE_SS_PWR_SYS_PSTATE_CTL_0,
  705. 0x01, 0x00);
  706. }
  707. done:
  708. dev_dbg(tavil->dev, "%s: vote = %s, updated ref cnt = %u\n", __func__,
  709. vote ? "vote" : "Unvote", tavil->svs_ref_cnt);
  710. mutex_unlock(&tavil->svs_mutex);
  711. }
  712. static int tavil_get_anc_slot(struct snd_kcontrol *kcontrol,
  713. struct snd_ctl_elem_value *ucontrol)
  714. {
  715. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  716. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  717. ucontrol->value.integer.value[0] = tavil->anc_slot;
  718. return 0;
  719. }
  720. static int tavil_put_anc_slot(struct snd_kcontrol *kcontrol,
  721. struct snd_ctl_elem_value *ucontrol)
  722. {
  723. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  724. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  725. tavil->anc_slot = ucontrol->value.integer.value[0];
  726. return 0;
  727. }
  728. static int tavil_get_anc_func(struct snd_kcontrol *kcontrol,
  729. struct snd_ctl_elem_value *ucontrol)
  730. {
  731. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  732. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  733. ucontrol->value.integer.value[0] = (tavil->anc_func == true ? 1 : 0);
  734. return 0;
  735. }
  736. static int tavil_put_anc_func(struct snd_kcontrol *kcontrol,
  737. struct snd_ctl_elem_value *ucontrol)
  738. {
  739. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  740. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  741. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  742. mutex_lock(&tavil->codec_mutex);
  743. tavil->anc_func = (!ucontrol->value.integer.value[0] ? false : true);
  744. dev_dbg(codec->dev, "%s: anc_func %x", __func__, tavil->anc_func);
  745. if (tavil->anc_func == true) {
  746. snd_soc_dapm_enable_pin(dapm, "ANC EAR PA");
  747. snd_soc_dapm_enable_pin(dapm, "ANC EAR");
  748. snd_soc_dapm_enable_pin(dapm, "ANC SPK1 PA");
  749. snd_soc_dapm_enable_pin(dapm, "ANC HPHL PA");
  750. snd_soc_dapm_enable_pin(dapm, "ANC HPHR PA");
  751. snd_soc_dapm_enable_pin(dapm, "ANC HPHL");
  752. snd_soc_dapm_enable_pin(dapm, "ANC HPHR");
  753. snd_soc_dapm_disable_pin(dapm, "EAR PA");
  754. snd_soc_dapm_disable_pin(dapm, "EAR");
  755. snd_soc_dapm_disable_pin(dapm, "HPHL PA");
  756. snd_soc_dapm_disable_pin(dapm, "HPHR PA");
  757. snd_soc_dapm_disable_pin(dapm, "HPHL");
  758. snd_soc_dapm_disable_pin(dapm, "HPHR");
  759. } else {
  760. snd_soc_dapm_disable_pin(dapm, "ANC EAR PA");
  761. snd_soc_dapm_disable_pin(dapm, "ANC EAR");
  762. snd_soc_dapm_disable_pin(dapm, "ANC SPK1 PA");
  763. snd_soc_dapm_disable_pin(dapm, "ANC HPHL PA");
  764. snd_soc_dapm_disable_pin(dapm, "ANC HPHR PA");
  765. snd_soc_dapm_disable_pin(dapm, "ANC HPHL");
  766. snd_soc_dapm_disable_pin(dapm, "ANC HPHR");
  767. snd_soc_dapm_enable_pin(dapm, "EAR PA");
  768. snd_soc_dapm_enable_pin(dapm, "EAR");
  769. snd_soc_dapm_enable_pin(dapm, "HPHL");
  770. snd_soc_dapm_enable_pin(dapm, "HPHR");
  771. snd_soc_dapm_enable_pin(dapm, "HPHL PA");
  772. snd_soc_dapm_enable_pin(dapm, "HPHR PA");
  773. }
  774. mutex_unlock(&tavil->codec_mutex);
  775. snd_soc_dapm_sync(dapm);
  776. return 0;
  777. }
  778. static int tavil_codec_enable_anc(struct snd_soc_dapm_widget *w,
  779. struct snd_kcontrol *kcontrol, int event)
  780. {
  781. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  782. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  783. const char *filename;
  784. const struct firmware *fw;
  785. int i;
  786. int ret = 0;
  787. int num_anc_slots;
  788. struct wcd9xxx_anc_header *anc_head;
  789. struct firmware_cal *hwdep_cal = NULL;
  790. u32 anc_writes_size = 0;
  791. int anc_size_remaining;
  792. u32 *anc_ptr;
  793. u16 reg;
  794. u8 mask, val;
  795. size_t cal_size;
  796. const void *data;
  797. if (!tavil->anc_func)
  798. return 0;
  799. switch (event) {
  800. case SND_SOC_DAPM_PRE_PMU:
  801. hwdep_cal = wcdcal_get_fw_cal(tavil->fw_data, WCD9XXX_ANC_CAL);
  802. if (hwdep_cal) {
  803. data = hwdep_cal->data;
  804. cal_size = hwdep_cal->size;
  805. dev_dbg(codec->dev, "%s: using hwdep calibration, cal_size %zd",
  806. __func__, cal_size);
  807. } else {
  808. filename = "WCD934X/WCD934X_anc.bin";
  809. ret = request_firmware(&fw, filename, codec->dev);
  810. if (ret < 0) {
  811. dev_err(codec->dev, "%s: Failed to acquire ANC data: %d\n",
  812. __func__, ret);
  813. return ret;
  814. }
  815. if (!fw) {
  816. dev_err(codec->dev, "%s: Failed to get anc fw\n",
  817. __func__);
  818. return -ENODEV;
  819. }
  820. data = fw->data;
  821. cal_size = fw->size;
  822. dev_dbg(codec->dev, "%s: using request_firmware calibration\n",
  823. __func__);
  824. }
  825. if (cal_size < sizeof(struct wcd9xxx_anc_header)) {
  826. dev_err(codec->dev, "%s: Invalid cal_size %zd\n",
  827. __func__, cal_size);
  828. ret = -EINVAL;
  829. goto err;
  830. }
  831. /* First number is the number of register writes */
  832. anc_head = (struct wcd9xxx_anc_header *)(data);
  833. anc_ptr = (u32 *)(data + sizeof(struct wcd9xxx_anc_header));
  834. anc_size_remaining = cal_size -
  835. sizeof(struct wcd9xxx_anc_header);
  836. num_anc_slots = anc_head->num_anc_slots;
  837. if (tavil->anc_slot >= num_anc_slots) {
  838. dev_err(codec->dev, "%s: Invalid ANC slot selected\n",
  839. __func__);
  840. ret = -EINVAL;
  841. goto err;
  842. }
  843. for (i = 0; i < num_anc_slots; i++) {
  844. if (anc_size_remaining < WCD934X_PACKED_REG_SIZE) {
  845. dev_err(codec->dev, "%s: Invalid register format\n",
  846. __func__);
  847. ret = -EINVAL;
  848. goto err;
  849. }
  850. anc_writes_size = (u32)(*anc_ptr);
  851. anc_size_remaining -= sizeof(u32);
  852. anc_ptr += 1;
  853. if ((anc_writes_size * WCD934X_PACKED_REG_SIZE) >
  854. anc_size_remaining) {
  855. dev_err(codec->dev, "%s: Invalid register format\n",
  856. __func__);
  857. ret = -EINVAL;
  858. goto err;
  859. }
  860. if (tavil->anc_slot == i)
  861. break;
  862. anc_size_remaining -= (anc_writes_size *
  863. WCD934X_PACKED_REG_SIZE);
  864. anc_ptr += anc_writes_size;
  865. }
  866. if (i == num_anc_slots) {
  867. dev_err(codec->dev, "%s: Selected ANC slot not present\n",
  868. __func__);
  869. ret = -EINVAL;
  870. goto err;
  871. }
  872. i = 0;
  873. if (!strcmp(w->name, "RX INT1 DAC") ||
  874. !strcmp(w->name, "RX INT3 DAC"))
  875. anc_writes_size = anc_writes_size / 2;
  876. else if (!strcmp(w->name, "RX INT2 DAC") ||
  877. !strcmp(w->name, "RX INT4 DAC"))
  878. i = anc_writes_size / 2;
  879. for (; i < anc_writes_size; i++) {
  880. WCD934X_CODEC_UNPACK_ENTRY(anc_ptr[i], reg, mask, val);
  881. snd_soc_write(codec, reg, (val & mask));
  882. }
  883. /* Rate converter clk enable and set bypass mode */
  884. if (!strcmp(w->name, "RX INT0 DAC") ||
  885. !strcmp(w->name, "RX INT1 DAC") ||
  886. !strcmp(w->name, "ANC SPK1 PA")) {
  887. snd_soc_update_bits(codec,
  888. WCD934X_CDC_ANC0_RC_COMMON_CTL,
  889. 0x05, 0x05);
  890. if (!strcmp(w->name, "RX INT1 DAC")) {
  891. snd_soc_update_bits(codec,
  892. WCD934X_CDC_ANC0_FIFO_COMMON_CTL,
  893. 0x66, 0x66);
  894. }
  895. } else if (!strcmp(w->name, "RX INT2 DAC")) {
  896. snd_soc_update_bits(codec,
  897. WCD934X_CDC_ANC1_RC_COMMON_CTL,
  898. 0x05, 0x05);
  899. snd_soc_update_bits(codec,
  900. WCD934X_CDC_ANC1_FIFO_COMMON_CTL,
  901. 0x66, 0x66);
  902. }
  903. if (!strcmp(w->name, "RX INT1 DAC"))
  904. snd_soc_update_bits(codec,
  905. WCD934X_CDC_ANC0_CLK_RESET_CTL, 0x08, 0x08);
  906. else if (!strcmp(w->name, "RX INT2 DAC"))
  907. snd_soc_update_bits(codec,
  908. WCD934X_CDC_ANC1_CLK_RESET_CTL, 0x08, 0x08);
  909. if (!hwdep_cal)
  910. release_firmware(fw);
  911. break;
  912. case SND_SOC_DAPM_POST_PMU:
  913. if (!strcmp(w->name, "ANC HPHL PA") ||
  914. !strcmp(w->name, "ANC HPHR PA")) {
  915. /* Remove ANC Rx from reset */
  916. snd_soc_update_bits(codec,
  917. WCD934X_CDC_ANC0_CLK_RESET_CTL,
  918. 0x08, 0x00);
  919. snd_soc_update_bits(codec,
  920. WCD934X_CDC_ANC1_CLK_RESET_CTL,
  921. 0x08, 0x00);
  922. }
  923. break;
  924. case SND_SOC_DAPM_POST_PMD:
  925. snd_soc_update_bits(codec, WCD934X_CDC_ANC0_RC_COMMON_CTL,
  926. 0x05, 0x00);
  927. if (!strcmp(w->name, "ANC EAR PA") ||
  928. !strcmp(w->name, "ANC SPK1 PA") ||
  929. !strcmp(w->name, "ANC HPHL PA")) {
  930. snd_soc_update_bits(codec, WCD934X_CDC_ANC0_MODE_1_CTL,
  931. 0x30, 0x00);
  932. msleep(50);
  933. snd_soc_update_bits(codec, WCD934X_CDC_ANC0_MODE_1_CTL,
  934. 0x01, 0x00);
  935. snd_soc_update_bits(codec,
  936. WCD934X_CDC_ANC0_CLK_RESET_CTL,
  937. 0x38, 0x38);
  938. snd_soc_update_bits(codec,
  939. WCD934X_CDC_ANC0_CLK_RESET_CTL,
  940. 0x07, 0x00);
  941. snd_soc_update_bits(codec,
  942. WCD934X_CDC_ANC0_CLK_RESET_CTL,
  943. 0x38, 0x00);
  944. } else if (!strcmp(w->name, "ANC HPHR PA")) {
  945. snd_soc_update_bits(codec, WCD934X_CDC_ANC1_MODE_1_CTL,
  946. 0x30, 0x00);
  947. msleep(50);
  948. snd_soc_update_bits(codec, WCD934X_CDC_ANC1_MODE_1_CTL,
  949. 0x01, 0x00);
  950. snd_soc_update_bits(codec,
  951. WCD934X_CDC_ANC1_CLK_RESET_CTL,
  952. 0x38, 0x38);
  953. snd_soc_update_bits(codec,
  954. WCD934X_CDC_ANC1_CLK_RESET_CTL,
  955. 0x07, 0x00);
  956. snd_soc_update_bits(codec,
  957. WCD934X_CDC_ANC1_CLK_RESET_CTL,
  958. 0x38, 0x00);
  959. }
  960. break;
  961. }
  962. return 0;
  963. err:
  964. if (!hwdep_cal)
  965. release_firmware(fw);
  966. return ret;
  967. }
  968. static int tavil_get_clkmode(struct snd_kcontrol *kcontrol,
  969. struct snd_ctl_elem_value *ucontrol)
  970. {
  971. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  972. struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec);
  973. if (test_bit(CLK_MODE, &tavil_p->status_mask))
  974. ucontrol->value.enumerated.item[0] = 1;
  975. else
  976. ucontrol->value.enumerated.item[0] = 0;
  977. dev_dbg(codec->dev, "%s: is_low_power_clock: %s\n", __func__,
  978. test_bit(CLK_MODE, &tavil_p->status_mask) ? "true" : "false");
  979. return 0;
  980. }
  981. static int tavil_put_clkmode(struct snd_kcontrol *kcontrol,
  982. struct snd_ctl_elem_value *ucontrol)
  983. {
  984. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  985. struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec);
  986. if (ucontrol->value.enumerated.item[0])
  987. set_bit(CLK_MODE, &tavil_p->status_mask);
  988. else
  989. clear_bit(CLK_MODE, &tavil_p->status_mask);
  990. dev_dbg(codec->dev, "%s: is_low_power_clock: %s\n", __func__,
  991. test_bit(CLK_MODE, &tavil_p->status_mask) ? "true" : "false");
  992. return 0;
  993. }
  994. static int tavil_vi_feed_mixer_get(struct snd_kcontrol *kcontrol,
  995. struct snd_ctl_elem_value *ucontrol)
  996. {
  997. struct snd_soc_dapm_widget *widget =
  998. snd_soc_dapm_kcontrol_widget(kcontrol);
  999. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  1000. struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec);
  1001. ucontrol->value.integer.value[0] = tavil_p->vi_feed_value;
  1002. return 0;
  1003. }
  1004. static int tavil_vi_feed_mixer_put(struct snd_kcontrol *kcontrol,
  1005. struct snd_ctl_elem_value *ucontrol)
  1006. {
  1007. struct snd_soc_dapm_widget *widget =
  1008. snd_soc_dapm_kcontrol_widget(kcontrol);
  1009. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  1010. struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec);
  1011. struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent);
  1012. struct soc_multi_mixer_control *mixer =
  1013. ((struct soc_multi_mixer_control *)kcontrol->private_value);
  1014. u32 dai_id = widget->shift;
  1015. u32 port_id = mixer->shift;
  1016. u32 enable = ucontrol->value.integer.value[0];
  1017. dev_dbg(codec->dev, "%s: enable: %d, port_id:%d, dai_id: %d\n",
  1018. __func__, enable, port_id, dai_id);
  1019. tavil_p->vi_feed_value = ucontrol->value.integer.value[0];
  1020. mutex_lock(&tavil_p->codec_mutex);
  1021. if (enable) {
  1022. if (port_id == WCD934X_TX14 && !test_bit(VI_SENSE_1,
  1023. &tavil_p->status_mask)) {
  1024. list_add_tail(&core->tx_chs[WCD934X_TX14].list,
  1025. &tavil_p->dai[dai_id].wcd9xxx_ch_list);
  1026. set_bit(VI_SENSE_1, &tavil_p->status_mask);
  1027. }
  1028. if (port_id == WCD934X_TX15 && !test_bit(VI_SENSE_2,
  1029. &tavil_p->status_mask)) {
  1030. list_add_tail(&core->tx_chs[WCD934X_TX15].list,
  1031. &tavil_p->dai[dai_id].wcd9xxx_ch_list);
  1032. set_bit(VI_SENSE_2, &tavil_p->status_mask);
  1033. }
  1034. } else {
  1035. if (port_id == WCD934X_TX14 && test_bit(VI_SENSE_1,
  1036. &tavil_p->status_mask)) {
  1037. list_del_init(&core->tx_chs[WCD934X_TX14].list);
  1038. clear_bit(VI_SENSE_1, &tavil_p->status_mask);
  1039. }
  1040. if (port_id == WCD934X_TX15 && test_bit(VI_SENSE_2,
  1041. &tavil_p->status_mask)) {
  1042. list_del_init(&core->tx_chs[WCD934X_TX15].list);
  1043. clear_bit(VI_SENSE_2, &tavil_p->status_mask);
  1044. }
  1045. }
  1046. mutex_unlock(&tavil_p->codec_mutex);
  1047. snd_soc_dapm_mixer_update_power(widget->dapm, kcontrol, enable, NULL);
  1048. return 0;
  1049. }
  1050. static int slim_tx_mixer_get(struct snd_kcontrol *kcontrol,
  1051. struct snd_ctl_elem_value *ucontrol)
  1052. {
  1053. struct snd_soc_dapm_widget *widget =
  1054. snd_soc_dapm_kcontrol_widget(kcontrol);
  1055. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  1056. struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec);
  1057. ucontrol->value.integer.value[0] = tavil_p->tx_port_value;
  1058. return 0;
  1059. }
  1060. static int slim_tx_mixer_put(struct snd_kcontrol *kcontrol,
  1061. struct snd_ctl_elem_value *ucontrol)
  1062. {
  1063. struct snd_soc_dapm_widget *widget =
  1064. snd_soc_dapm_kcontrol_widget(kcontrol);
  1065. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  1066. struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec);
  1067. struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent);
  1068. struct snd_soc_dapm_update *update = NULL;
  1069. struct soc_multi_mixer_control *mixer =
  1070. ((struct soc_multi_mixer_control *)kcontrol->private_value);
  1071. u32 dai_id = widget->shift;
  1072. u32 port_id = mixer->shift;
  1073. u32 enable = ucontrol->value.integer.value[0];
  1074. u32 vtable;
  1075. dev_dbg(codec->dev, "%s: wname %s cname %s value %u shift %d item %ld\n",
  1076. __func__,
  1077. widget->name, ucontrol->id.name, tavil_p->tx_port_value,
  1078. widget->shift, ucontrol->value.integer.value[0]);
  1079. mutex_lock(&tavil_p->codec_mutex);
  1080. if (dai_id >= ARRAY_SIZE(vport_slim_check_table)) {
  1081. dev_err(codec->dev, "%s: dai_id: %d, out of bounds\n",
  1082. __func__, dai_id);
  1083. mutex_unlock(&tavil_p->codec_mutex);
  1084. return -EINVAL;
  1085. }
  1086. vtable = vport_slim_check_table[dai_id];
  1087. switch (dai_id) {
  1088. case AIF1_CAP:
  1089. case AIF2_CAP:
  1090. case AIF3_CAP:
  1091. /* only add to the list if value not set */
  1092. if (enable && !(tavil_p->tx_port_value & 1 << port_id)) {
  1093. if (wcd9xxx_tx_vport_validation(vtable, port_id,
  1094. tavil_p->dai, NUM_CODEC_DAIS)) {
  1095. dev_dbg(codec->dev, "%s: TX%u is used by other virtual port\n",
  1096. __func__, port_id);
  1097. mutex_unlock(&tavil_p->codec_mutex);
  1098. return 0;
  1099. }
  1100. tavil_p->tx_port_value |= 1 << port_id;
  1101. list_add_tail(&core->tx_chs[port_id].list,
  1102. &tavil_p->dai[dai_id].wcd9xxx_ch_list);
  1103. } else if (!enable && (tavil_p->tx_port_value &
  1104. 1 << port_id)) {
  1105. tavil_p->tx_port_value &= ~(1 << port_id);
  1106. list_del_init(&core->tx_chs[port_id].list);
  1107. } else {
  1108. if (enable)
  1109. dev_dbg(codec->dev, "%s: TX%u port is used by\n"
  1110. "this virtual port\n",
  1111. __func__, port_id);
  1112. else
  1113. dev_dbg(codec->dev, "%s: TX%u port is not used by\n"
  1114. "this virtual port\n",
  1115. __func__, port_id);
  1116. /* avoid update power function */
  1117. mutex_unlock(&tavil_p->codec_mutex);
  1118. return 0;
  1119. }
  1120. break;
  1121. case AIF4_MAD_TX:
  1122. break;
  1123. default:
  1124. dev_err(codec->dev, "Unknown AIF %d\n", dai_id);
  1125. mutex_unlock(&tavil_p->codec_mutex);
  1126. return -EINVAL;
  1127. }
  1128. dev_dbg(codec->dev, "%s: name %s sname %s updated value %u shift %d\n",
  1129. __func__, widget->name, widget->sname, tavil_p->tx_port_value,
  1130. widget->shift);
  1131. mutex_unlock(&tavil_p->codec_mutex);
  1132. snd_soc_dapm_mixer_update_power(widget->dapm, kcontrol, enable, update);
  1133. return 0;
  1134. }
  1135. static int i2s_tx_mixer_get(struct snd_kcontrol *kcontrol,
  1136. struct snd_ctl_elem_value *ucontrol)
  1137. {
  1138. struct snd_soc_dapm_widget *widget =
  1139. snd_soc_dapm_kcontrol_widget(kcontrol);
  1140. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  1141. struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec);
  1142. ucontrol->value.integer.value[0] = tavil_p->tx_port_value;
  1143. return 0;
  1144. }
  1145. static int i2s_tx_mixer_put(struct snd_kcontrol *kcontrol,
  1146. struct snd_ctl_elem_value *ucontrol)
  1147. {
  1148. struct snd_soc_dapm_widget *widget =
  1149. snd_soc_dapm_kcontrol_widget(kcontrol);
  1150. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  1151. struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec);
  1152. struct snd_soc_dapm_update *update = NULL;
  1153. struct soc_multi_mixer_control *mixer =
  1154. (struct soc_multi_mixer_control *)kcontrol->private_value;
  1155. u32 dai_id = widget->shift;
  1156. u32 port_id = mixer->shift;
  1157. u32 enable = ucontrol->value.integer.value[0];
  1158. u32 vtable;
  1159. dev_dbg(codec->dev, "%s: wname %s cname %s value %u shift %d item %ld\n",
  1160. __func__,
  1161. widget->name, ucontrol->id.name, tavil_p->tx_port_value,
  1162. widget->shift, ucontrol->value.integer.value[0]);
  1163. mutex_lock(&tavil_p->codec_mutex);
  1164. if (dai_id >= ARRAY_SIZE(vport_slim_check_table)) {
  1165. dev_err(codec->dev, "%s: dai_id: %d, out of bounds\n",
  1166. __func__, dai_id);
  1167. mutex_unlock(&tavil_p->codec_mutex);
  1168. return -EINVAL;
  1169. }
  1170. vtable = vport_slim_check_table[dai_id];
  1171. switch (dai_id) {
  1172. case AIF1_CAP:
  1173. case AIF2_CAP:
  1174. case AIF3_CAP:
  1175. /* only add to the list if value not set */
  1176. if (enable && !(tavil_p->tx_port_value & 1 << port_id)) {
  1177. if (wcd9xxx_tx_vport_validation(vtable, port_id,
  1178. tavil_p->dai, NUM_CODEC_DAIS)) {
  1179. dev_dbg(codec->dev, "%s: TX%u is used by other virtual port\n",
  1180. __func__, port_id);
  1181. mutex_unlock(&tavil_p->codec_mutex);
  1182. return 0;
  1183. }
  1184. tavil_p->tx_port_value |= 1 << port_id;
  1185. } else if (!enable && (tavil_p->tx_port_value &
  1186. 1 << port_id)) {
  1187. tavil_p->tx_port_value &= ~(1 << port_id);
  1188. } else {
  1189. if (enable)
  1190. dev_dbg(codec->dev, "%s: TX%u port is used by\n"
  1191. "this virtual port\n",
  1192. __func__, port_id);
  1193. else
  1194. dev_dbg(codec->dev, "%s: TX%u port is not used by\n"
  1195. "this virtual port\n",
  1196. __func__, port_id);
  1197. /* avoid update power function */
  1198. mutex_unlock(&tavil_p->codec_mutex);
  1199. return 0;
  1200. }
  1201. break;
  1202. default:
  1203. dev_err(codec->dev, "Unknown AIF %d\n", dai_id);
  1204. mutex_unlock(&tavil_p->codec_mutex);
  1205. return -EINVAL;
  1206. }
  1207. dev_dbg(codec->dev, "%s: name %s sname %s updated value %u shift %d\n",
  1208. __func__, widget->name, widget->sname, tavil_p->tx_port_value,
  1209. widget->shift);
  1210. mutex_unlock(&tavil_p->codec_mutex);
  1211. snd_soc_dapm_mixer_update_power(widget->dapm, kcontrol, enable, update);
  1212. return 0;
  1213. }
  1214. static int slim_rx_mux_get(struct snd_kcontrol *kcontrol,
  1215. struct snd_ctl_elem_value *ucontrol)
  1216. {
  1217. struct snd_soc_dapm_widget *widget =
  1218. snd_soc_dapm_kcontrol_widget(kcontrol);
  1219. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  1220. struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec);
  1221. ucontrol->value.enumerated.item[0] =
  1222. tavil_p->rx_port_value[widget->shift];
  1223. return 0;
  1224. }
  1225. static int slim_rx_mux_put(struct snd_kcontrol *kcontrol,
  1226. struct snd_ctl_elem_value *ucontrol)
  1227. {
  1228. struct snd_soc_dapm_widget *widget =
  1229. snd_soc_dapm_kcontrol_widget(kcontrol);
  1230. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  1231. struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec);
  1232. struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent);
  1233. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1234. struct snd_soc_dapm_update *update = NULL;
  1235. unsigned int rx_port_value;
  1236. u32 port_id = widget->shift;
  1237. tavil_p->rx_port_value[port_id] = ucontrol->value.enumerated.item[0];
  1238. rx_port_value = tavil_p->rx_port_value[port_id];
  1239. mutex_lock(&tavil_p->codec_mutex);
  1240. dev_dbg(codec->dev, "%s: wname %s cname %s value %u shift %d item %ld\n",
  1241. __func__, widget->name, ucontrol->id.name,
  1242. rx_port_value, widget->shift,
  1243. ucontrol->value.integer.value[0]);
  1244. /* value need to match the Virtual port and AIF number */
  1245. switch (rx_port_value) {
  1246. case 0:
  1247. list_del_init(&core->rx_chs[port_id].list);
  1248. break;
  1249. case 1:
  1250. if (wcd9xxx_rx_vport_validation(port_id +
  1251. WCD934X_RX_PORT_START_NUMBER,
  1252. &tavil_p->dai[AIF1_PB].wcd9xxx_ch_list)) {
  1253. dev_dbg(codec->dev, "%s: RX%u is used by current requesting AIF_PB itself\n",
  1254. __func__, port_id);
  1255. goto rtn;
  1256. }
  1257. list_add_tail(&core->rx_chs[port_id].list,
  1258. &tavil_p->dai[AIF1_PB].wcd9xxx_ch_list);
  1259. break;
  1260. case 2:
  1261. if (wcd9xxx_rx_vport_validation(port_id +
  1262. WCD934X_RX_PORT_START_NUMBER,
  1263. &tavil_p->dai[AIF2_PB].wcd9xxx_ch_list)) {
  1264. dev_dbg(codec->dev, "%s: RX%u is used by current requesting AIF_PB itself\n",
  1265. __func__, port_id);
  1266. goto rtn;
  1267. }
  1268. list_add_tail(&core->rx_chs[port_id].list,
  1269. &tavil_p->dai[AIF2_PB].wcd9xxx_ch_list);
  1270. break;
  1271. case 3:
  1272. if (wcd9xxx_rx_vport_validation(port_id +
  1273. WCD934X_RX_PORT_START_NUMBER,
  1274. &tavil_p->dai[AIF3_PB].wcd9xxx_ch_list)) {
  1275. dev_dbg(codec->dev, "%s: RX%u is used by current requesting AIF_PB itself\n",
  1276. __func__, port_id);
  1277. goto rtn;
  1278. }
  1279. list_add_tail(&core->rx_chs[port_id].list,
  1280. &tavil_p->dai[AIF3_PB].wcd9xxx_ch_list);
  1281. break;
  1282. case 4:
  1283. if (wcd9xxx_rx_vport_validation(port_id +
  1284. WCD934X_RX_PORT_START_NUMBER,
  1285. &tavil_p->dai[AIF4_PB].wcd9xxx_ch_list)) {
  1286. dev_dbg(codec->dev, "%s: RX%u is used by current requesting AIF_PB itself\n",
  1287. __func__, port_id);
  1288. goto rtn;
  1289. }
  1290. list_add_tail(&core->rx_chs[port_id].list,
  1291. &tavil_p->dai[AIF4_PB].wcd9xxx_ch_list);
  1292. break;
  1293. default:
  1294. dev_err(codec->dev, "Unknown AIF %d\n", rx_port_value);
  1295. goto err;
  1296. }
  1297. rtn:
  1298. mutex_unlock(&tavil_p->codec_mutex);
  1299. snd_soc_dapm_mux_update_power(widget->dapm, kcontrol,
  1300. rx_port_value, e, update);
  1301. return 0;
  1302. err:
  1303. mutex_unlock(&tavil_p->codec_mutex);
  1304. return -EINVAL;
  1305. }
  1306. static void tavil_codec_enable_slim_port_intr(
  1307. struct wcd9xxx_codec_dai_data *dai,
  1308. struct snd_soc_codec *codec)
  1309. {
  1310. struct wcd9xxx_ch *ch;
  1311. int port_num = 0;
  1312. unsigned short reg = 0;
  1313. u8 val = 0;
  1314. struct tavil_priv *tavil_p;
  1315. if (!dai || !codec) {
  1316. pr_err("%s: Invalid params\n", __func__);
  1317. return;
  1318. }
  1319. tavil_p = snd_soc_codec_get_drvdata(codec);
  1320. list_for_each_entry(ch, &dai->wcd9xxx_ch_list, list) {
  1321. if (ch->port >= WCD934X_RX_PORT_START_NUMBER) {
  1322. port_num = ch->port - WCD934X_RX_PORT_START_NUMBER;
  1323. reg = WCD934X_SLIM_PGD_PORT_INT_RX_EN0 + (port_num / 8);
  1324. val = wcd9xxx_interface_reg_read(tavil_p->wcd9xxx,
  1325. reg);
  1326. if (!(val & BYTE_BIT_MASK(port_num))) {
  1327. val |= BYTE_BIT_MASK(port_num);
  1328. wcd9xxx_interface_reg_write(
  1329. tavil_p->wcd9xxx, reg, val);
  1330. val = wcd9xxx_interface_reg_read(
  1331. tavil_p->wcd9xxx, reg);
  1332. }
  1333. } else {
  1334. port_num = ch->port;
  1335. reg = WCD934X_SLIM_PGD_PORT_INT_TX_EN0 + (port_num / 8);
  1336. val = wcd9xxx_interface_reg_read(tavil_p->wcd9xxx,
  1337. reg);
  1338. if (!(val & BYTE_BIT_MASK(port_num))) {
  1339. val |= BYTE_BIT_MASK(port_num);
  1340. wcd9xxx_interface_reg_write(tavil_p->wcd9xxx,
  1341. reg, val);
  1342. val = wcd9xxx_interface_reg_read(
  1343. tavil_p->wcd9xxx, reg);
  1344. }
  1345. }
  1346. }
  1347. }
  1348. static int tavil_codec_enable_slim_chmask(struct wcd9xxx_codec_dai_data *dai,
  1349. bool up)
  1350. {
  1351. int ret = 0;
  1352. struct wcd9xxx_ch *ch;
  1353. if (up) {
  1354. list_for_each_entry(ch, &dai->wcd9xxx_ch_list, list) {
  1355. ret = wcd9xxx_get_slave_port(ch->ch_num);
  1356. if (ret < 0) {
  1357. pr_err("%s: Invalid slave port ID: %d\n",
  1358. __func__, ret);
  1359. ret = -EINVAL;
  1360. } else {
  1361. set_bit(ret, &dai->ch_mask);
  1362. }
  1363. }
  1364. } else {
  1365. ret = wait_event_timeout(dai->dai_wait, (dai->ch_mask == 0),
  1366. msecs_to_jiffies(
  1367. WCD934X_SLIM_CLOSE_TIMEOUT));
  1368. if (!ret) {
  1369. pr_err("%s: Slim close tx/rx wait timeout, ch_mask:0x%lx\n",
  1370. __func__, dai->ch_mask);
  1371. ret = -ETIMEDOUT;
  1372. } else {
  1373. ret = 0;
  1374. }
  1375. }
  1376. return ret;
  1377. }
  1378. static void tavil_codec_mute_dsd(struct snd_soc_codec *codec,
  1379. struct list_head *ch_list)
  1380. {
  1381. u8 dsd0_in;
  1382. u8 dsd1_in;
  1383. struct wcd9xxx_ch *ch;
  1384. /* Read DSD Input Ports */
  1385. dsd0_in = (snd_soc_read(codec, WCD934X_CDC_DSD0_CFG0) & 0x3C) >> 2;
  1386. dsd1_in = (snd_soc_read(codec, WCD934X_CDC_DSD1_CFG0) & 0x3C) >> 2;
  1387. if ((dsd0_in == 0) && (dsd1_in == 0))
  1388. return;
  1389. /*
  1390. * Check if the ports getting disabled are connected to DSD inputs.
  1391. * If connected, enable DSD mute to avoid DC entering into DSD Filter
  1392. */
  1393. list_for_each_entry(ch, ch_list, list) {
  1394. if (ch->port == (dsd0_in + WCD934X_RX_PORT_START_NUMBER - 1))
  1395. snd_soc_update_bits(codec, WCD934X_CDC_DSD0_CFG2,
  1396. 0x04, 0x04);
  1397. if (ch->port == (dsd1_in + WCD934X_RX_PORT_START_NUMBER - 1))
  1398. snd_soc_update_bits(codec, WCD934X_CDC_DSD1_CFG2,
  1399. 0x04, 0x04);
  1400. }
  1401. }
  1402. static int tavil_codec_set_i2s_rx_ch(struct snd_soc_dapm_widget *w,
  1403. u32 i2s_reg, bool up)
  1404. {
  1405. int rx_fs_rate = -EINVAL;
  1406. int i2s_bit_mode;
  1407. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1408. struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec);
  1409. struct wcd9xxx_codec_dai_data *dai;
  1410. dai = &tavil_p->dai[w->shift];
  1411. dev_dbg(tavil_p->dev, "%s: %d up/down, %d width, %d rate\n",
  1412. __func__, up, dai->bit_width, dai->rate);
  1413. if (up) {
  1414. if (dai->bit_width == 16)
  1415. i2s_bit_mode = 0x01;
  1416. else
  1417. i2s_bit_mode = 0x00;
  1418. switch (dai->rate) {
  1419. case 8000:
  1420. rx_fs_rate = 0;
  1421. break;
  1422. case 16000:
  1423. rx_fs_rate = 1;
  1424. break;
  1425. case 32000:
  1426. rx_fs_rate = 2;
  1427. break;
  1428. case 48000:
  1429. rx_fs_rate = 3;
  1430. break;
  1431. case 96000:
  1432. rx_fs_rate = 4;
  1433. break;
  1434. case 192000:
  1435. rx_fs_rate = 5;
  1436. break;
  1437. case 384000:
  1438. rx_fs_rate = 6;
  1439. break;
  1440. default:
  1441. dev_err(tavil_p->dev, "%s: Invalid RX sample rate: %d\n",
  1442. __func__, dai->rate);
  1443. return -EINVAL;
  1444. };
  1445. snd_soc_update_bits(codec, i2s_reg,
  1446. 0x40, i2s_bit_mode << 6);
  1447. snd_soc_update_bits(codec, i2s_reg,
  1448. 0x3c, (rx_fs_rate << 2));
  1449. } else {
  1450. snd_soc_update_bits(codec, i2s_reg,
  1451. 0x40, 0x00);
  1452. snd_soc_update_bits(codec, i2s_reg,
  1453. 0x3c, 0x00);
  1454. }
  1455. return 0;
  1456. }
  1457. static int tavil_codec_set_i2s_tx_ch(struct snd_soc_dapm_widget *w,
  1458. u32 i2s_reg, bool up)
  1459. {
  1460. int tx_fs_rate = -EINVAL;
  1461. int i2s_bit_mode;
  1462. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1463. struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec);
  1464. struct wcd9xxx_codec_dai_data *dai;
  1465. dai = &tavil_p->dai[w->shift];
  1466. if (up) {
  1467. if (dai->bit_width == 16)
  1468. i2s_bit_mode = 0x01;
  1469. else
  1470. i2s_bit_mode = 0x00;
  1471. snd_soc_update_bits(codec, i2s_reg, 0x40, i2s_bit_mode << 6);
  1472. switch (dai->rate) {
  1473. case 8000:
  1474. tx_fs_rate = 0;
  1475. break;
  1476. case 16000:
  1477. tx_fs_rate = 1;
  1478. break;
  1479. case 32000:
  1480. tx_fs_rate = 2;
  1481. break;
  1482. case 48000:
  1483. tx_fs_rate = 3;
  1484. break;
  1485. case 96000:
  1486. tx_fs_rate = 4;
  1487. break;
  1488. case 192000:
  1489. tx_fs_rate = 5;
  1490. break;
  1491. case 384000:
  1492. tx_fs_rate = 6;
  1493. break;
  1494. default:
  1495. dev_err(tavil_p->dev, "%s: Invalid sample rate: %d\n",
  1496. __func__, dai->rate);
  1497. return -EINVAL;
  1498. };
  1499. snd_soc_update_bits(codec, i2s_reg, 0x3c, tx_fs_rate << 2);
  1500. snd_soc_update_bits(codec,
  1501. WCD934X_DATA_HUB_I2S_TX0_CFG,
  1502. 0x03, 0x01);
  1503. snd_soc_update_bits(codec,
  1504. WCD934X_DATA_HUB_I2S_TX0_CFG,
  1505. 0x0C, 0x01);
  1506. snd_soc_update_bits(codec,
  1507. WCD934X_DATA_HUB_I2S_TX1_0_CFG,
  1508. 0x03, 0x01);
  1509. snd_soc_update_bits(codec,
  1510. WCD934X_DATA_HUB_I2S_TX1_1_CFG,
  1511. 0x05, 0x05);
  1512. } else {
  1513. snd_soc_update_bits(codec, i2s_reg, 0x40, 0x00);
  1514. snd_soc_update_bits(codec, i2s_reg, 0x3c, 0x00);
  1515. snd_soc_update_bits(codec,
  1516. WCD934X_DATA_HUB_I2S_TX0_CFG,
  1517. 0x03, 0x00);
  1518. snd_soc_update_bits(codec,
  1519. WCD934X_DATA_HUB_I2S_TX0_CFG,
  1520. 0x0C, 0x00);
  1521. snd_soc_update_bits(codec,
  1522. WCD934X_DATA_HUB_I2S_TX1_0_CFG,
  1523. 0x03, 0x00);
  1524. snd_soc_update_bits(codec,
  1525. WCD934X_DATA_HUB_I2S_TX1_1_CFG,
  1526. 0x05, 0x00);
  1527. }
  1528. return 0;
  1529. }
  1530. static int tavil_codec_enable_rx_i2c(struct snd_soc_dapm_widget *w,
  1531. struct snd_kcontrol *kcontrol,
  1532. int event)
  1533. {
  1534. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1535. struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec);
  1536. int ret = -EINVAL;
  1537. u32 i2s_reg;
  1538. switch (tavil_p->rx_port_value[w->shift]) {
  1539. case AIF1_PB:
  1540. case AIF1_CAP:
  1541. i2s_reg = WCD934X_DATA_HUB_I2S_0_CTL;
  1542. break;
  1543. case AIF2_PB:
  1544. case AIF2_CAP:
  1545. i2s_reg = WCD934X_DATA_HUB_I2S_1_CTL;
  1546. break;
  1547. case AIF3_PB:
  1548. case AIF3_CAP:
  1549. i2s_reg = WCD934X_DATA_HUB_I2S_2_CTL;
  1550. break;
  1551. default:
  1552. dev_err(codec->dev, "%s Invalid i2s Id received", __func__);
  1553. return -EINVAL;
  1554. }
  1555. switch (event) {
  1556. case SND_SOC_DAPM_POST_PMU:
  1557. ret = tavil_codec_set_i2s_rx_ch(w, i2s_reg, true);
  1558. break;
  1559. case SND_SOC_DAPM_POST_PMD:
  1560. ret = tavil_codec_set_i2s_rx_ch(w, i2s_reg, false);
  1561. break;
  1562. }
  1563. return ret;
  1564. }
  1565. static int tavil_codec_enable_rx(struct snd_soc_dapm_widget *w,
  1566. struct snd_kcontrol *kcontrol,
  1567. int event)
  1568. {
  1569. struct wcd9xxx *core;
  1570. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1571. struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec);
  1572. int ret = 0;
  1573. struct wcd9xxx_codec_dai_data *dai;
  1574. struct tavil_dsd_config *dsd_conf = tavil_p->dsd_config;
  1575. core = dev_get_drvdata(codec->dev->parent);
  1576. dev_dbg(codec->dev, "%s: event called! codec name %s num_dai %d\n"
  1577. "stream name %s event %d\n",
  1578. __func__, codec->component.name,
  1579. codec->component.num_dai, w->sname, event);
  1580. dai = &tavil_p->dai[w->shift];
  1581. dev_dbg(codec->dev, "%s: w->name %s w->shift %d event %d\n",
  1582. __func__, w->name, w->shift, event);
  1583. if (tavil_p->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
  1584. ret = tavil_codec_enable_rx_i2c(w, kcontrol, event);
  1585. return ret;
  1586. }
  1587. switch (event) {
  1588. case SND_SOC_DAPM_POST_PMU:
  1589. dai->bus_down_in_recovery = false;
  1590. tavil_codec_enable_slim_port_intr(dai, codec);
  1591. (void) tavil_codec_enable_slim_chmask(dai, true);
  1592. ret = wcd9xxx_cfg_slim_sch_rx(core, &dai->wcd9xxx_ch_list,
  1593. dai->rate, dai->bit_width,
  1594. &dai->grph);
  1595. break;
  1596. case SND_SOC_DAPM_POST_PMD:
  1597. if (dsd_conf)
  1598. tavil_codec_mute_dsd(codec, &dai->wcd9xxx_ch_list);
  1599. ret = wcd9xxx_disconnect_port(core, &dai->wcd9xxx_ch_list,
  1600. dai->grph);
  1601. dev_dbg(codec->dev, "%s: Disconnect RX port, ret = %d\n",
  1602. __func__, ret);
  1603. if (!dai->bus_down_in_recovery)
  1604. ret = tavil_codec_enable_slim_chmask(dai, false);
  1605. else
  1606. dev_dbg(codec->dev,
  1607. "%s: bus in recovery skip enable slim_chmask",
  1608. __func__);
  1609. ret = wcd9xxx_close_slim_sch_rx(core, &dai->wcd9xxx_ch_list,
  1610. dai->grph);
  1611. break;
  1612. }
  1613. return ret;
  1614. }
  1615. static int tavil_codec_enable_tx_i2c(struct snd_soc_dapm_widget *w,
  1616. struct snd_kcontrol *kcontrol,
  1617. int event)
  1618. {
  1619. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1620. struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec);
  1621. int ret = -EINVAL;
  1622. u32 i2s_reg;
  1623. switch (tavil_p->rx_port_value[w->shift]) {
  1624. case AIF1_PB:
  1625. case AIF1_CAP:
  1626. i2s_reg = WCD934X_DATA_HUB_I2S_0_CTL;
  1627. break;
  1628. case AIF2_PB:
  1629. case AIF2_CAP:
  1630. i2s_reg = WCD934X_DATA_HUB_I2S_1_CTL;
  1631. break;
  1632. case AIF3_PB:
  1633. case AIF3_CAP:
  1634. i2s_reg = WCD934X_DATA_HUB_I2S_2_CTL;
  1635. break;
  1636. default:
  1637. dev_err(codec->dev, "%s Invalid i2s Id received", __func__);
  1638. return -EINVAL;
  1639. }
  1640. switch (event) {
  1641. case SND_SOC_DAPM_POST_PMU:
  1642. ret = tavil_codec_set_i2s_tx_ch(w, i2s_reg, true);
  1643. break;
  1644. case SND_SOC_DAPM_POST_PMD:
  1645. ret = tavil_codec_set_i2s_tx_ch(w, i2s_reg, false);
  1646. break;
  1647. }
  1648. return ret;
  1649. }
  1650. static int tavil_codec_enable_tx(struct snd_soc_dapm_widget *w,
  1651. struct snd_kcontrol *kcontrol,
  1652. int event)
  1653. {
  1654. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1655. struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec);
  1656. struct wcd9xxx_codec_dai_data *dai;
  1657. struct wcd9xxx *core;
  1658. int ret = 0;
  1659. dev_dbg(codec->dev,
  1660. "%s: w->name %s, w->shift = %d, num_dai %d stream name %s\n",
  1661. __func__, w->name, w->shift,
  1662. codec->component.num_dai, w->sname);
  1663. dai = &tavil_p->dai[w->shift];
  1664. core = dev_get_drvdata(codec->dev->parent);
  1665. if (tavil_p->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
  1666. ret = tavil_codec_enable_tx_i2c(w, kcontrol, event);
  1667. return ret;
  1668. }
  1669. switch (event) {
  1670. case SND_SOC_DAPM_POST_PMU:
  1671. dai->bus_down_in_recovery = false;
  1672. tavil_codec_enable_slim_port_intr(dai, codec);
  1673. (void) tavil_codec_enable_slim_chmask(dai, true);
  1674. ret = wcd9xxx_cfg_slim_sch_tx(core, &dai->wcd9xxx_ch_list,
  1675. dai->rate, dai->bit_width,
  1676. &dai->grph);
  1677. break;
  1678. case SND_SOC_DAPM_POST_PMD:
  1679. ret = wcd9xxx_close_slim_sch_tx(core, &dai->wcd9xxx_ch_list,
  1680. dai->grph);
  1681. if (!dai->bus_down_in_recovery)
  1682. ret = tavil_codec_enable_slim_chmask(dai, false);
  1683. if (ret < 0) {
  1684. ret = wcd9xxx_disconnect_port(core,
  1685. &dai->wcd9xxx_ch_list,
  1686. dai->grph);
  1687. dev_dbg(codec->dev, "%s: Disconnect RX port, ret = %d\n",
  1688. __func__, ret);
  1689. }
  1690. break;
  1691. }
  1692. return ret;
  1693. }
  1694. static int tavil_codec_enable_slimvi_feedback(struct snd_soc_dapm_widget *w,
  1695. struct snd_kcontrol *kcontrol,
  1696. int event)
  1697. {
  1698. struct wcd9xxx *core = NULL;
  1699. struct snd_soc_codec *codec = NULL;
  1700. struct tavil_priv *tavil_p = NULL;
  1701. int ret = 0;
  1702. struct wcd9xxx_codec_dai_data *dai = NULL;
  1703. codec = snd_soc_dapm_to_codec(w->dapm);
  1704. tavil_p = snd_soc_codec_get_drvdata(codec);
  1705. core = dev_get_drvdata(codec->dev->parent);
  1706. dev_dbg(codec->dev,
  1707. "%s: num_dai %d stream name %s w->name %s event %d shift %d\n",
  1708. __func__, codec->component.num_dai, w->sname,
  1709. w->name, event, w->shift);
  1710. if (w->shift != AIF4_VIFEED) {
  1711. pr_err("%s Error in enabling the tx path\n", __func__);
  1712. ret = -EINVAL;
  1713. goto done;
  1714. }
  1715. dai = &tavil_p->dai[w->shift];
  1716. switch (event) {
  1717. case SND_SOC_DAPM_POST_PMU:
  1718. if (test_bit(VI_SENSE_1, &tavil_p->status_mask)) {
  1719. dev_dbg(codec->dev, "%s: spkr1 enabled\n", __func__);
  1720. /* Enable V&I sensing */
  1721. snd_soc_update_bits(codec,
  1722. WCD934X_CDC_TX9_SPKR_PROT_PATH_CTL, 0x20, 0x20);
  1723. snd_soc_update_bits(codec,
  1724. WCD934X_CDC_TX10_SPKR_PROT_PATH_CTL, 0x20,
  1725. 0x20);
  1726. snd_soc_update_bits(codec,
  1727. WCD934X_CDC_TX9_SPKR_PROT_PATH_CTL, 0x0F, 0x00);
  1728. snd_soc_update_bits(codec,
  1729. WCD934X_CDC_TX10_SPKR_PROT_PATH_CTL, 0x0F,
  1730. 0x00);
  1731. snd_soc_update_bits(codec,
  1732. WCD934X_CDC_TX9_SPKR_PROT_PATH_CTL, 0x10, 0x10);
  1733. snd_soc_update_bits(codec,
  1734. WCD934X_CDC_TX10_SPKR_PROT_PATH_CTL, 0x10,
  1735. 0x10);
  1736. snd_soc_update_bits(codec,
  1737. WCD934X_CDC_TX9_SPKR_PROT_PATH_CTL, 0x20, 0x00);
  1738. snd_soc_update_bits(codec,
  1739. WCD934X_CDC_TX10_SPKR_PROT_PATH_CTL, 0x20,
  1740. 0x00);
  1741. }
  1742. if (test_bit(VI_SENSE_2, &tavil_p->status_mask)) {
  1743. pr_debug("%s: spkr2 enabled\n", __func__);
  1744. /* Enable V&I sensing */
  1745. snd_soc_update_bits(codec,
  1746. WCD934X_CDC_TX11_SPKR_PROT_PATH_CTL, 0x20,
  1747. 0x20);
  1748. snd_soc_update_bits(codec,
  1749. WCD934X_CDC_TX12_SPKR_PROT_PATH_CTL, 0x20,
  1750. 0x20);
  1751. snd_soc_update_bits(codec,
  1752. WCD934X_CDC_TX11_SPKR_PROT_PATH_CTL, 0x0F,
  1753. 0x00);
  1754. snd_soc_update_bits(codec,
  1755. WCD934X_CDC_TX12_SPKR_PROT_PATH_CTL, 0x0F,
  1756. 0x00);
  1757. snd_soc_update_bits(codec,
  1758. WCD934X_CDC_TX11_SPKR_PROT_PATH_CTL, 0x10,
  1759. 0x10);
  1760. snd_soc_update_bits(codec,
  1761. WCD934X_CDC_TX12_SPKR_PROT_PATH_CTL, 0x10,
  1762. 0x10);
  1763. snd_soc_update_bits(codec,
  1764. WCD934X_CDC_TX11_SPKR_PROT_PATH_CTL, 0x20,
  1765. 0x00);
  1766. snd_soc_update_bits(codec,
  1767. WCD934X_CDC_TX12_SPKR_PROT_PATH_CTL, 0x20,
  1768. 0x00);
  1769. }
  1770. dai->bus_down_in_recovery = false;
  1771. tavil_codec_enable_slim_port_intr(dai, codec);
  1772. (void) tavil_codec_enable_slim_chmask(dai, true);
  1773. ret = wcd9xxx_cfg_slim_sch_tx(core, &dai->wcd9xxx_ch_list,
  1774. dai->rate, dai->bit_width,
  1775. &dai->grph);
  1776. break;
  1777. case SND_SOC_DAPM_POST_PMD:
  1778. ret = wcd9xxx_close_slim_sch_tx(core, &dai->wcd9xxx_ch_list,
  1779. dai->grph);
  1780. if (ret)
  1781. dev_err(codec->dev, "%s error in close_slim_sch_tx %d\n",
  1782. __func__, ret);
  1783. if (!dai->bus_down_in_recovery)
  1784. ret = tavil_codec_enable_slim_chmask(dai, false);
  1785. if (ret < 0) {
  1786. ret = wcd9xxx_disconnect_port(core,
  1787. &dai->wcd9xxx_ch_list,
  1788. dai->grph);
  1789. dev_dbg(codec->dev, "%s: Disconnect TX port, ret = %d\n",
  1790. __func__, ret);
  1791. }
  1792. if (test_bit(VI_SENSE_1, &tavil_p->status_mask)) {
  1793. /* Disable V&I sensing */
  1794. dev_dbg(codec->dev, "%s: spkr1 disabled\n", __func__);
  1795. snd_soc_update_bits(codec,
  1796. WCD934X_CDC_TX9_SPKR_PROT_PATH_CTL, 0x20, 0x20);
  1797. snd_soc_update_bits(codec,
  1798. WCD934X_CDC_TX10_SPKR_PROT_PATH_CTL, 0x20,
  1799. 0x20);
  1800. snd_soc_update_bits(codec,
  1801. WCD934X_CDC_TX9_SPKR_PROT_PATH_CTL, 0x10, 0x00);
  1802. snd_soc_update_bits(codec,
  1803. WCD934X_CDC_TX10_SPKR_PROT_PATH_CTL, 0x10,
  1804. 0x00);
  1805. }
  1806. if (test_bit(VI_SENSE_2, &tavil_p->status_mask)) {
  1807. /* Disable V&I sensing */
  1808. dev_dbg(codec->dev, "%s: spkr2 disabled\n", __func__);
  1809. snd_soc_update_bits(codec,
  1810. WCD934X_CDC_TX11_SPKR_PROT_PATH_CTL, 0x20,
  1811. 0x20);
  1812. snd_soc_update_bits(codec,
  1813. WCD934X_CDC_TX12_SPKR_PROT_PATH_CTL, 0x20,
  1814. 0x20);
  1815. snd_soc_update_bits(codec,
  1816. WCD934X_CDC_TX11_SPKR_PROT_PATH_CTL, 0x10,
  1817. 0x00);
  1818. snd_soc_update_bits(codec,
  1819. WCD934X_CDC_TX12_SPKR_PROT_PATH_CTL, 0x10,
  1820. 0x00);
  1821. }
  1822. break;
  1823. }
  1824. done:
  1825. return ret;
  1826. }
  1827. static int tavil_codec_enable_rx_bias(struct snd_soc_dapm_widget *w,
  1828. struct snd_kcontrol *kcontrol, int event)
  1829. {
  1830. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1831. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  1832. dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
  1833. switch (event) {
  1834. case SND_SOC_DAPM_PRE_PMU:
  1835. tavil->rx_bias_count++;
  1836. if (tavil->rx_bias_count == 1) {
  1837. snd_soc_update_bits(codec, WCD934X_ANA_RX_SUPPLIES,
  1838. 0x01, 0x01);
  1839. }
  1840. break;
  1841. case SND_SOC_DAPM_POST_PMD:
  1842. tavil->rx_bias_count--;
  1843. if (!tavil->rx_bias_count)
  1844. snd_soc_update_bits(codec, WCD934X_ANA_RX_SUPPLIES,
  1845. 0x01, 0x00);
  1846. break;
  1847. };
  1848. dev_dbg(codec->dev, "%s: Current RX BIAS user count: %d\n", __func__,
  1849. tavil->rx_bias_count);
  1850. return 0;
  1851. }
  1852. static void tavil_spk_anc_update_callback(struct work_struct *work)
  1853. {
  1854. struct spk_anc_work *spk_anc_dwork;
  1855. struct tavil_priv *tavil;
  1856. struct delayed_work *delayed_work;
  1857. struct snd_soc_codec *codec;
  1858. delayed_work = to_delayed_work(work);
  1859. spk_anc_dwork = container_of(delayed_work, struct spk_anc_work, dwork);
  1860. tavil = spk_anc_dwork->tavil;
  1861. codec = tavil->codec;
  1862. snd_soc_update_bits(codec, WCD934X_CDC_RX7_RX_PATH_CFG0, 0x10, 0x10);
  1863. }
  1864. static int tavil_codec_enable_spkr_anc(struct snd_soc_dapm_widget *w,
  1865. struct snd_kcontrol *kcontrol,
  1866. int event)
  1867. {
  1868. int ret = 0;
  1869. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1870. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  1871. if (!tavil->anc_func)
  1872. return 0;
  1873. dev_dbg(codec->dev, "%s: w: %s event: %d anc: %d\n", __func__,
  1874. w->name, event, tavil->anc_func);
  1875. switch (event) {
  1876. case SND_SOC_DAPM_PRE_PMU:
  1877. ret = tavil_codec_enable_anc(w, kcontrol, event);
  1878. schedule_delayed_work(&tavil->spk_anc_dwork.dwork,
  1879. msecs_to_jiffies(spk_anc_en_delay));
  1880. break;
  1881. case SND_SOC_DAPM_POST_PMD:
  1882. cancel_delayed_work_sync(&tavil->spk_anc_dwork.dwork);
  1883. snd_soc_update_bits(codec, WCD934X_CDC_RX7_RX_PATH_CFG0,
  1884. 0x10, 0x00);
  1885. ret = tavil_codec_enable_anc(w, kcontrol, event);
  1886. break;
  1887. }
  1888. return ret;
  1889. }
  1890. static int tavil_codec_enable_ear_pa(struct snd_soc_dapm_widget *w,
  1891. struct snd_kcontrol *kcontrol,
  1892. int event)
  1893. {
  1894. int ret = 0;
  1895. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1896. dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
  1897. switch (event) {
  1898. case SND_SOC_DAPM_POST_PMU:
  1899. /*
  1900. * 5ms sleep is required after PA is enabled as per
  1901. * HW requirement
  1902. */
  1903. usleep_range(5000, 5500);
  1904. snd_soc_update_bits(codec, WCD934X_CDC_RX0_RX_PATH_CTL,
  1905. 0x10, 0x00);
  1906. /* Remove mix path mute if it is enabled */
  1907. if ((snd_soc_read(codec, WCD934X_CDC_RX0_RX_PATH_MIX_CTL)) &
  1908. 0x10)
  1909. snd_soc_update_bits(codec,
  1910. WCD934X_CDC_RX0_RX_PATH_MIX_CTL,
  1911. 0x10, 0x00);
  1912. break;
  1913. case SND_SOC_DAPM_POST_PMD:
  1914. /*
  1915. * 5ms sleep is required after PA is disabled as per
  1916. * HW requirement
  1917. */
  1918. usleep_range(5000, 5500);
  1919. if (!(strcmp(w->name, "ANC EAR PA"))) {
  1920. ret = tavil_codec_enable_anc(w, kcontrol, event);
  1921. snd_soc_update_bits(codec, WCD934X_CDC_RX0_RX_PATH_CFG0,
  1922. 0x10, 0x00);
  1923. }
  1924. break;
  1925. };
  1926. return ret;
  1927. }
  1928. static void tavil_codec_override(struct snd_soc_codec *codec, int mode,
  1929. int event)
  1930. {
  1931. if (mode == CLS_AB || mode == CLS_AB_HIFI) {
  1932. switch (event) {
  1933. case SND_SOC_DAPM_PRE_PMU:
  1934. case SND_SOC_DAPM_POST_PMU:
  1935. snd_soc_update_bits(codec,
  1936. WCD9XXX_A_ANA_RX_SUPPLIES, 0x02, 0x02);
  1937. break;
  1938. case SND_SOC_DAPM_POST_PMD:
  1939. snd_soc_update_bits(codec,
  1940. WCD9XXX_A_ANA_RX_SUPPLIES, 0x02, 0x00);
  1941. break;
  1942. }
  1943. }
  1944. }
  1945. static void tavil_codec_clear_anc_tx_hold(struct tavil_priv *tavil)
  1946. {
  1947. if (test_and_clear_bit(ANC_MIC_AMIC1, &tavil->status_mask))
  1948. tavil_codec_set_tx_hold(tavil->codec, WCD934X_ANA_AMIC1, false);
  1949. if (test_and_clear_bit(ANC_MIC_AMIC2, &tavil->status_mask))
  1950. tavil_codec_set_tx_hold(tavil->codec, WCD934X_ANA_AMIC2, false);
  1951. if (test_and_clear_bit(ANC_MIC_AMIC3, &tavil->status_mask))
  1952. tavil_codec_set_tx_hold(tavil->codec, WCD934X_ANA_AMIC3, false);
  1953. if (test_and_clear_bit(ANC_MIC_AMIC4, &tavil->status_mask))
  1954. tavil_codec_set_tx_hold(tavil->codec, WCD934X_ANA_AMIC4, false);
  1955. }
  1956. static void tavil_ocp_control(struct snd_soc_codec *codec, bool enable)
  1957. {
  1958. if (enable) {
  1959. snd_soc_update_bits(codec, WCD934X_HPH_OCP_CTL, 0x10, 0x10);
  1960. snd_soc_update_bits(codec, WCD934X_RX_OCP_CTL, 0x0F, 0x02);
  1961. } else {
  1962. snd_soc_update_bits(codec, WCD934X_RX_OCP_CTL, 0x0F, 0x0F);
  1963. snd_soc_update_bits(codec, WCD934X_HPH_OCP_CTL, 0x10, 0x00);
  1964. }
  1965. }
  1966. static int tavil_codec_enable_hphr_pa(struct snd_soc_dapm_widget *w,
  1967. struct snd_kcontrol *kcontrol,
  1968. int event)
  1969. {
  1970. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1971. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  1972. struct tavil_dsd_config *dsd_conf = tavil->dsd_config;
  1973. int ret = 0;
  1974. dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
  1975. switch (event) {
  1976. case SND_SOC_DAPM_PRE_PMU:
  1977. tavil_ocp_control(codec, false);
  1978. if (TAVIL_IS_1_0(tavil->wcd9xxx))
  1979. snd_soc_update_bits(codec, WCD934X_HPH_REFBUFF_LP_CTL,
  1980. 0x06, (0x03 << 1));
  1981. if ((!(strcmp(w->name, "ANC HPHR PA"))) &&
  1982. (test_bit(HPH_PA_DELAY, &tavil->status_mask)))
  1983. snd_soc_update_bits(codec, WCD934X_ANA_HPH, 0xC0, 0xC0);
  1984. set_bit(HPH_PA_DELAY, &tavil->status_mask);
  1985. if (dsd_conf &&
  1986. (snd_soc_read(codec, WCD934X_CDC_DSD1_PATH_CTL) & 0x01)) {
  1987. /* Set regulator mode to AB if DSD is enabled */
  1988. snd_soc_update_bits(codec, WCD934X_ANA_RX_SUPPLIES,
  1989. 0x02, 0x02);
  1990. }
  1991. break;
  1992. case SND_SOC_DAPM_POST_PMU:
  1993. if ((!(strcmp(w->name, "ANC HPHR PA")))) {
  1994. if ((snd_soc_read(codec, WCD934X_ANA_HPH) & 0xC0)
  1995. != 0xC0)
  1996. /*
  1997. * If PA_EN is not set (potentially in ANC case)
  1998. * then do nothing for POST_PMU and let left
  1999. * channel handle everything.
  2000. */
  2001. break;
  2002. }
  2003. /*
  2004. * 7ms sleep is required after PA is enabled as per
  2005. * HW requirement. If compander is disabled, then
  2006. * 20ms delay is needed.
  2007. */
  2008. if (test_bit(HPH_PA_DELAY, &tavil->status_mask)) {
  2009. if (!tavil->comp_enabled[COMPANDER_2])
  2010. usleep_range(20000, 20100);
  2011. else
  2012. usleep_range(7000, 7100);
  2013. clear_bit(HPH_PA_DELAY, &tavil->status_mask);
  2014. }
  2015. if (tavil->anc_func) {
  2016. /* Clear Tx FE HOLD if both PAs are enabled */
  2017. if ((snd_soc_read(tavil->codec, WCD934X_ANA_HPH) &
  2018. 0xC0) == 0xC0)
  2019. tavil_codec_clear_anc_tx_hold(tavil);
  2020. }
  2021. snd_soc_update_bits(codec, WCD934X_HPH_R_TEST, 0x01, 0x01);
  2022. /* Remove mute */
  2023. snd_soc_update_bits(codec, WCD934X_CDC_RX2_RX_PATH_CTL,
  2024. 0x10, 0x00);
  2025. /* Enable GM3 boost */
  2026. snd_soc_update_bits(codec, WCD934X_HPH_CNP_WG_CTL,
  2027. 0x80, 0x80);
  2028. /* Enable AutoChop timer at the end of power up */
  2029. snd_soc_update_bits(codec, WCD934X_HPH_NEW_INT_HPH_TIMER1,
  2030. 0x02, 0x02);
  2031. /* Remove mix path mute if it is enabled */
  2032. if ((snd_soc_read(codec, WCD934X_CDC_RX2_RX_PATH_MIX_CTL)) &
  2033. 0x10)
  2034. snd_soc_update_bits(codec,
  2035. WCD934X_CDC_RX2_RX_PATH_MIX_CTL,
  2036. 0x10, 0x00);
  2037. if (dsd_conf &&
  2038. (snd_soc_read(codec, WCD934X_CDC_DSD1_PATH_CTL) & 0x01))
  2039. snd_soc_update_bits(codec, WCD934X_CDC_DSD1_CFG2,
  2040. 0x04, 0x00);
  2041. if (!(strcmp(w->name, "ANC HPHR PA"))) {
  2042. pr_debug("%s:Do everything needed for left channel\n",
  2043. __func__);
  2044. /* Do everything needed for left channel */
  2045. snd_soc_update_bits(codec, WCD934X_HPH_L_TEST,
  2046. 0x01, 0x01);
  2047. /* Remove mute */
  2048. snd_soc_update_bits(codec, WCD934X_CDC_RX1_RX_PATH_CTL,
  2049. 0x10, 0x00);
  2050. /* Remove mix path mute if it is enabled */
  2051. if ((snd_soc_read(codec,
  2052. WCD934X_CDC_RX1_RX_PATH_MIX_CTL)) &
  2053. 0x10)
  2054. snd_soc_update_bits(codec,
  2055. WCD934X_CDC_RX1_RX_PATH_MIX_CTL,
  2056. 0x10, 0x00);
  2057. if (dsd_conf && (snd_soc_read(codec,
  2058. WCD934X_CDC_DSD0_PATH_CTL) &
  2059. 0x01))
  2060. snd_soc_update_bits(codec,
  2061. WCD934X_CDC_DSD0_CFG2,
  2062. 0x04, 0x00);
  2063. /* Remove ANC Rx from reset */
  2064. ret = tavil_codec_enable_anc(w, kcontrol, event);
  2065. }
  2066. tavil_codec_override(codec, tavil->hph_mode, event);
  2067. tavil_ocp_control(codec, true);
  2068. break;
  2069. case SND_SOC_DAPM_PRE_PMD:
  2070. tavil_ocp_control(codec, false);
  2071. blocking_notifier_call_chain(&tavil->mbhc->notifier,
  2072. WCD_EVENT_PRE_HPHR_PA_OFF,
  2073. &tavil->mbhc->wcd_mbhc);
  2074. /* Enable DSD Mute before PA disable */
  2075. if (dsd_conf &&
  2076. (snd_soc_read(codec, WCD934X_CDC_DSD1_PATH_CTL) & 0x01))
  2077. snd_soc_update_bits(codec, WCD934X_CDC_DSD1_CFG2,
  2078. 0x04, 0x04);
  2079. snd_soc_update_bits(codec, WCD934X_HPH_R_TEST, 0x01, 0x00);
  2080. snd_soc_update_bits(codec, WCD934X_CDC_RX2_RX_PATH_CTL,
  2081. 0x10, 0x10);
  2082. snd_soc_update_bits(codec, WCD934X_CDC_RX2_RX_PATH_MIX_CTL,
  2083. 0x10, 0x10);
  2084. if (!(strcmp(w->name, "ANC HPHR PA")))
  2085. snd_soc_update_bits(codec, WCD934X_ANA_HPH, 0x40, 0x00);
  2086. break;
  2087. case SND_SOC_DAPM_POST_PMD:
  2088. /*
  2089. * 5ms sleep is required after PA disable. If compander is
  2090. * disabled, then 20ms delay is needed after PA disable.
  2091. */
  2092. if (!tavil->comp_enabled[COMPANDER_2])
  2093. usleep_range(20000, 20100);
  2094. else
  2095. usleep_range(5000, 5100);
  2096. tavil_codec_override(codec, tavil->hph_mode, event);
  2097. blocking_notifier_call_chain(&tavil->mbhc->notifier,
  2098. WCD_EVENT_POST_HPHR_PA_OFF,
  2099. &tavil->mbhc->wcd_mbhc);
  2100. if (TAVIL_IS_1_0(tavil->wcd9xxx))
  2101. snd_soc_update_bits(codec, WCD934X_HPH_REFBUFF_LP_CTL,
  2102. 0x06, 0x0);
  2103. if (!(strcmp(w->name, "ANC HPHR PA"))) {
  2104. ret = tavil_codec_enable_anc(w, kcontrol, event);
  2105. snd_soc_update_bits(codec,
  2106. WCD934X_CDC_RX2_RX_PATH_CFG0,
  2107. 0x10, 0x00);
  2108. }
  2109. tavil_ocp_control(codec, true);
  2110. break;
  2111. };
  2112. return ret;
  2113. }
  2114. static int tavil_codec_enable_hphl_pa(struct snd_soc_dapm_widget *w,
  2115. struct snd_kcontrol *kcontrol,
  2116. int event)
  2117. {
  2118. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2119. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  2120. struct tavil_dsd_config *dsd_conf = tavil->dsd_config;
  2121. int ret = 0;
  2122. dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
  2123. switch (event) {
  2124. case SND_SOC_DAPM_PRE_PMU:
  2125. tavil_ocp_control(codec, false);
  2126. if (TAVIL_IS_1_0(tavil->wcd9xxx))
  2127. snd_soc_update_bits(codec, WCD934X_HPH_REFBUFF_LP_CTL,
  2128. 0x06, (0x03 << 1));
  2129. if ((!(strcmp(w->name, "ANC HPHL PA"))) &&
  2130. (test_bit(HPH_PA_DELAY, &tavil->status_mask)))
  2131. snd_soc_update_bits(codec, WCD934X_ANA_HPH,
  2132. 0xC0, 0xC0);
  2133. set_bit(HPH_PA_DELAY, &tavil->status_mask);
  2134. if (dsd_conf &&
  2135. (snd_soc_read(codec, WCD934X_CDC_DSD0_PATH_CTL) & 0x01)) {
  2136. /* Set regulator mode to AB if DSD is enabled */
  2137. snd_soc_update_bits(codec, WCD934X_ANA_RX_SUPPLIES,
  2138. 0x02, 0x02);
  2139. }
  2140. break;
  2141. case SND_SOC_DAPM_POST_PMU:
  2142. if (!(strcmp(w->name, "ANC HPHL PA"))) {
  2143. if ((snd_soc_read(codec, WCD934X_ANA_HPH) & 0xC0)
  2144. != 0xC0)
  2145. /*
  2146. * If PA_EN is not set (potentially in ANC
  2147. * case) then do nothing for POST_PMU and
  2148. * let right channel handle everything.
  2149. */
  2150. break;
  2151. }
  2152. /*
  2153. * 7ms sleep is required after PA is enabled as per
  2154. * HW requirement. If compander is disabled, then
  2155. * 20ms delay is needed.
  2156. */
  2157. if (test_bit(HPH_PA_DELAY, &tavil->status_mask)) {
  2158. if (!tavil->comp_enabled[COMPANDER_1])
  2159. usleep_range(20000, 20100);
  2160. else
  2161. usleep_range(7000, 7100);
  2162. clear_bit(HPH_PA_DELAY, &tavil->status_mask);
  2163. }
  2164. if (tavil->anc_func) {
  2165. /* Clear Tx FE HOLD if both PAs are enabled */
  2166. if ((snd_soc_read(tavil->codec, WCD934X_ANA_HPH) &
  2167. 0xC0) == 0xC0)
  2168. tavil_codec_clear_anc_tx_hold(tavil);
  2169. }
  2170. snd_soc_update_bits(codec, WCD934X_HPH_L_TEST, 0x01, 0x01);
  2171. /* Remove Mute on primary path */
  2172. snd_soc_update_bits(codec, WCD934X_CDC_RX1_RX_PATH_CTL,
  2173. 0x10, 0x00);
  2174. /* Enable GM3 boost */
  2175. snd_soc_update_bits(codec, WCD934X_HPH_CNP_WG_CTL,
  2176. 0x80, 0x80);
  2177. /* Enable AutoChop timer at the end of power up */
  2178. snd_soc_update_bits(codec, WCD934X_HPH_NEW_INT_HPH_TIMER1,
  2179. 0x02, 0x02);
  2180. /* Remove mix path mute if it is enabled */
  2181. if ((snd_soc_read(codec, WCD934X_CDC_RX1_RX_PATH_MIX_CTL)) &
  2182. 0x10)
  2183. snd_soc_update_bits(codec,
  2184. WCD934X_CDC_RX1_RX_PATH_MIX_CTL,
  2185. 0x10, 0x00);
  2186. if (dsd_conf &&
  2187. (snd_soc_read(codec, WCD934X_CDC_DSD0_PATH_CTL) & 0x01))
  2188. snd_soc_update_bits(codec, WCD934X_CDC_DSD0_CFG2,
  2189. 0x04, 0x00);
  2190. if (!(strcmp(w->name, "ANC HPHL PA"))) {
  2191. pr_debug("%s:Do everything needed for right channel\n",
  2192. __func__);
  2193. /* Do everything needed for right channel */
  2194. snd_soc_update_bits(codec, WCD934X_HPH_R_TEST,
  2195. 0x01, 0x01);
  2196. /* Remove mute */
  2197. snd_soc_update_bits(codec, WCD934X_CDC_RX2_RX_PATH_CTL,
  2198. 0x10, 0x00);
  2199. /* Remove mix path mute if it is enabled */
  2200. if ((snd_soc_read(codec,
  2201. WCD934X_CDC_RX2_RX_PATH_MIX_CTL)) &
  2202. 0x10)
  2203. snd_soc_update_bits(codec,
  2204. WCD934X_CDC_RX2_RX_PATH_MIX_CTL,
  2205. 0x10, 0x00);
  2206. if (dsd_conf && (snd_soc_read(codec,
  2207. WCD934X_CDC_DSD1_PATH_CTL) & 0x01))
  2208. snd_soc_update_bits(codec,
  2209. WCD934X_CDC_DSD1_CFG2,
  2210. 0x04, 0x00);
  2211. /* Remove ANC Rx from reset */
  2212. ret = tavil_codec_enable_anc(w, kcontrol, event);
  2213. }
  2214. tavil_codec_override(codec, tavil->hph_mode, event);
  2215. tavil_ocp_control(codec, true);
  2216. break;
  2217. case SND_SOC_DAPM_PRE_PMD:
  2218. tavil_ocp_control(codec, false);
  2219. blocking_notifier_call_chain(&tavil->mbhc->notifier,
  2220. WCD_EVENT_PRE_HPHL_PA_OFF,
  2221. &tavil->mbhc->wcd_mbhc);
  2222. /* Enable DSD Mute before PA disable */
  2223. if (dsd_conf &&
  2224. (snd_soc_read(codec, WCD934X_CDC_DSD0_PATH_CTL) & 0x01))
  2225. snd_soc_update_bits(codec, WCD934X_CDC_DSD0_CFG2,
  2226. 0x04, 0x04);
  2227. snd_soc_update_bits(codec, WCD934X_HPH_L_TEST, 0x01, 0x00);
  2228. snd_soc_update_bits(codec, WCD934X_CDC_RX1_RX_PATH_CTL,
  2229. 0x10, 0x10);
  2230. snd_soc_update_bits(codec, WCD934X_CDC_RX1_RX_PATH_MIX_CTL,
  2231. 0x10, 0x10);
  2232. if (!(strcmp(w->name, "ANC HPHL PA")))
  2233. snd_soc_update_bits(codec, WCD934X_ANA_HPH,
  2234. 0x80, 0x00);
  2235. break;
  2236. case SND_SOC_DAPM_POST_PMD:
  2237. /*
  2238. * 5ms sleep is required after PA disable. If compander is
  2239. * disabled, then 20ms delay is needed after PA disable.
  2240. */
  2241. if (!tavil->comp_enabled[COMPANDER_1])
  2242. usleep_range(20000, 20100);
  2243. else
  2244. usleep_range(5000, 5100);
  2245. tavil_codec_override(codec, tavil->hph_mode, event);
  2246. blocking_notifier_call_chain(&tavil->mbhc->notifier,
  2247. WCD_EVENT_POST_HPHL_PA_OFF,
  2248. &tavil->mbhc->wcd_mbhc);
  2249. if (TAVIL_IS_1_0(tavil->wcd9xxx))
  2250. snd_soc_update_bits(codec, WCD934X_HPH_REFBUFF_LP_CTL,
  2251. 0x06, 0x0);
  2252. if (!(strcmp(w->name, "ANC HPHL PA"))) {
  2253. ret = tavil_codec_enable_anc(w, kcontrol, event);
  2254. snd_soc_update_bits(codec,
  2255. WCD934X_CDC_RX1_RX_PATH_CFG0, 0x10, 0x00);
  2256. }
  2257. tavil_ocp_control(codec, true);
  2258. break;
  2259. };
  2260. return ret;
  2261. }
  2262. static int tavil_codec_enable_lineout_pa(struct snd_soc_dapm_widget *w,
  2263. struct snd_kcontrol *kcontrol,
  2264. int event)
  2265. {
  2266. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2267. u16 lineout_vol_reg = 0, lineout_mix_vol_reg = 0;
  2268. u16 dsd_mute_reg = 0, dsd_clk_reg = 0;
  2269. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  2270. struct tavil_dsd_config *dsd_conf = tavil->dsd_config;
  2271. dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
  2272. if (w->reg == WCD934X_ANA_LO_1_2) {
  2273. if (w->shift == 7) {
  2274. lineout_vol_reg = WCD934X_CDC_RX3_RX_PATH_CTL;
  2275. lineout_mix_vol_reg = WCD934X_CDC_RX3_RX_PATH_MIX_CTL;
  2276. dsd_mute_reg = WCD934X_CDC_DSD0_CFG2;
  2277. dsd_clk_reg = WCD934X_CDC_DSD0_PATH_CTL;
  2278. } else if (w->shift == 6) {
  2279. lineout_vol_reg = WCD934X_CDC_RX4_RX_PATH_CTL;
  2280. lineout_mix_vol_reg = WCD934X_CDC_RX4_RX_PATH_MIX_CTL;
  2281. dsd_mute_reg = WCD934X_CDC_DSD1_CFG2;
  2282. dsd_clk_reg = WCD934X_CDC_DSD1_PATH_CTL;
  2283. }
  2284. } else {
  2285. dev_err(codec->dev, "%s: Error enabling lineout PA\n",
  2286. __func__);
  2287. return -EINVAL;
  2288. }
  2289. switch (event) {
  2290. case SND_SOC_DAPM_PRE_PMU:
  2291. tavil_codec_override(codec, CLS_AB, event);
  2292. break;
  2293. case SND_SOC_DAPM_POST_PMU:
  2294. /*
  2295. * 5ms sleep is required after PA is enabled as per
  2296. * HW requirement
  2297. */
  2298. usleep_range(5000, 5500);
  2299. snd_soc_update_bits(codec, lineout_vol_reg,
  2300. 0x10, 0x00);
  2301. /* Remove mix path mute if it is enabled */
  2302. if ((snd_soc_read(codec, lineout_mix_vol_reg)) & 0x10)
  2303. snd_soc_update_bits(codec,
  2304. lineout_mix_vol_reg,
  2305. 0x10, 0x00);
  2306. if (dsd_conf && (snd_soc_read(codec, dsd_clk_reg) & 0x01))
  2307. snd_soc_update_bits(codec, dsd_mute_reg, 0x04, 0x00);
  2308. break;
  2309. case SND_SOC_DAPM_PRE_PMD:
  2310. if (dsd_conf && (snd_soc_read(codec, dsd_clk_reg) & 0x01))
  2311. snd_soc_update_bits(codec, dsd_mute_reg, 0x04, 0x04);
  2312. break;
  2313. case SND_SOC_DAPM_POST_PMD:
  2314. /*
  2315. * 5ms sleep is required after PA is disabled as per
  2316. * HW requirement
  2317. */
  2318. usleep_range(5000, 5500);
  2319. tavil_codec_override(codec, CLS_AB, event);
  2320. default:
  2321. break;
  2322. };
  2323. return 0;
  2324. }
  2325. static int i2s_rx_mux_get(struct snd_kcontrol *kcontrol,
  2326. struct snd_ctl_elem_value *ucontrol)
  2327. {
  2328. struct snd_soc_dapm_widget *widget =
  2329. snd_soc_dapm_kcontrol_widget(kcontrol);
  2330. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  2331. struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec);
  2332. ucontrol->value.enumerated.item[0] =
  2333. tavil_p->rx_port_value[widget->shift];
  2334. return 0;
  2335. }
  2336. static int i2s_rx_mux_put(struct snd_kcontrol *kcontrol,
  2337. struct snd_ctl_elem_value *ucontrol)
  2338. {
  2339. struct snd_soc_dapm_widget *widget =
  2340. snd_soc_dapm_kcontrol_widget(kcontrol);
  2341. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  2342. struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec);
  2343. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  2344. struct snd_soc_dapm_update *update = NULL;
  2345. unsigned int rx_port_value;
  2346. u32 port_id = widget->shift;
  2347. tavil_p->rx_port_value[port_id] = ucontrol->value.enumerated.item[0];
  2348. rx_port_value = tavil_p->rx_port_value[port_id];
  2349. dev_dbg(codec->dev, "%s: wname %s cname %s value %u shift %d item %ld\n",
  2350. __func__, widget->name, ucontrol->id.name,
  2351. rx_port_value, widget->shift,
  2352. ucontrol->value.integer.value[0]);
  2353. snd_soc_dapm_mux_update_power(widget->dapm, kcontrol,
  2354. rx_port_value, e, update);
  2355. return 0;
  2356. }
  2357. static int tavil_codec_enable_i2s_path(struct snd_soc_dapm_widget *w,
  2358. struct snd_kcontrol *kcontrol,
  2359. int event)
  2360. {
  2361. int ret = 0;
  2362. u32 i2s_reg;
  2363. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2364. struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec);
  2365. switch (tavil_p->rx_port_value[w->shift]) {
  2366. case AIF1_PB:
  2367. case AIF1_CAP:
  2368. i2s_reg = WCD934X_DATA_HUB_I2S_0_CTL;
  2369. break;
  2370. case AIF2_PB:
  2371. case AIF2_CAP:
  2372. i2s_reg = WCD934X_DATA_HUB_I2S_1_CTL;
  2373. break;
  2374. case AIF3_PB:
  2375. case AIF3_CAP:
  2376. i2s_reg = WCD934X_DATA_HUB_I2S_2_CTL;
  2377. break;
  2378. default:
  2379. dev_err(codec->dev, "%s Invalid i2s Id received", __func__);
  2380. return -EINVAL;
  2381. }
  2382. switch (event) {
  2383. case SND_SOC_DAPM_PRE_PMU:
  2384. ret = snd_soc_update_bits(codec, i2s_reg, 0x01, 0x01);
  2385. break;
  2386. case SND_SOC_DAPM_POST_PMD:
  2387. ret = snd_soc_update_bits(codec, i2s_reg, 0x01, 0x00);
  2388. break;
  2389. }
  2390. return ret;
  2391. }
  2392. static int tavil_codec_ear_dac_event(struct snd_soc_dapm_widget *w,
  2393. struct snd_kcontrol *kcontrol,
  2394. int event)
  2395. {
  2396. int ret = 0;
  2397. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2398. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  2399. dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
  2400. switch (event) {
  2401. case SND_SOC_DAPM_PRE_PMU:
  2402. /* Disable AutoChop timer during power up */
  2403. snd_soc_update_bits(codec, WCD934X_HPH_NEW_INT_HPH_TIMER1,
  2404. 0x02, 0x00);
  2405. if (tavil->anc_func)
  2406. ret = tavil_codec_enable_anc(w, kcontrol, event);
  2407. wcd_clsh_fsm(codec, &tavil->clsh_d,
  2408. WCD_CLSH_EVENT_PRE_DAC,
  2409. WCD_CLSH_STATE_EAR,
  2410. CLS_H_NORMAL);
  2411. if (tavil->anc_func)
  2412. snd_soc_update_bits(codec, WCD934X_CDC_RX0_RX_PATH_CFG0,
  2413. 0x10, 0x10);
  2414. break;
  2415. case SND_SOC_DAPM_POST_PMD:
  2416. wcd_clsh_fsm(codec, &tavil->clsh_d,
  2417. WCD_CLSH_EVENT_POST_PA,
  2418. WCD_CLSH_STATE_EAR,
  2419. CLS_H_NORMAL);
  2420. break;
  2421. default:
  2422. break;
  2423. };
  2424. return ret;
  2425. }
  2426. static int tavil_codec_hphr_dac_event(struct snd_soc_dapm_widget *w,
  2427. struct snd_kcontrol *kcontrol,
  2428. int event)
  2429. {
  2430. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2431. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  2432. int hph_mode = tavil->hph_mode;
  2433. u8 dem_inp;
  2434. struct tavil_dsd_config *dsd_conf = tavil->dsd_config;
  2435. int ret = 0;
  2436. dev_dbg(codec->dev, "%s wname: %s event: %d hph_mode: %d\n", __func__,
  2437. w->name, event, hph_mode);
  2438. switch (event) {
  2439. case SND_SOC_DAPM_PRE_PMU:
  2440. if (tavil->anc_func) {
  2441. ret = tavil_codec_enable_anc(w, kcontrol, event);
  2442. /* 40 msec delay is needed to avoid click and pop */
  2443. msleep(40);
  2444. }
  2445. /* Read DEM INP Select */
  2446. dem_inp = snd_soc_read(codec, WCD934X_CDC_RX2_RX_PATH_SEC0) &
  2447. 0x03;
  2448. if (((hph_mode == CLS_H_HIFI) || (hph_mode == CLS_H_LOHIFI) ||
  2449. (hph_mode == CLS_H_LP)) && (dem_inp != 0x01)) {
  2450. dev_err(codec->dev, "%s: DEM Input not set correctly, hph_mode: %d\n",
  2451. __func__, hph_mode);
  2452. return -EINVAL;
  2453. }
  2454. if ((hph_mode != CLS_H_LP) && (hph_mode != CLS_H_ULP))
  2455. /* Ripple freq control enable */
  2456. snd_soc_update_bits(codec,
  2457. WCD934X_SIDO_NEW_VOUT_D_FREQ2,
  2458. 0x01, 0x01);
  2459. /* Disable AutoChop timer during power up */
  2460. snd_soc_update_bits(codec, WCD934X_HPH_NEW_INT_HPH_TIMER1,
  2461. 0x02, 0x00);
  2462. /* Set RDAC gain */
  2463. if (TAVIL_IS_1_0(tavil->wcd9xxx))
  2464. snd_soc_update_bits(codec,
  2465. WCD934X_HPH_NEW_INT_RDAC_GAIN_CTL,
  2466. 0xF0, 0x40);
  2467. if (dsd_conf &&
  2468. (snd_soc_read(codec, WCD934X_CDC_DSD1_PATH_CTL) & 0x01))
  2469. hph_mode = CLS_H_HIFI;
  2470. wcd_clsh_fsm(codec, &tavil->clsh_d,
  2471. WCD_CLSH_EVENT_PRE_DAC,
  2472. WCD_CLSH_STATE_HPHR,
  2473. hph_mode);
  2474. if (tavil->anc_func)
  2475. snd_soc_update_bits(codec,
  2476. WCD934X_CDC_RX2_RX_PATH_CFG0,
  2477. 0x10, 0x10);
  2478. break;
  2479. case SND_SOC_DAPM_POST_PMD:
  2480. /* 1000us required as per HW requirement */
  2481. usleep_range(1000, 1100);
  2482. wcd_clsh_fsm(codec, &tavil->clsh_d,
  2483. WCD_CLSH_EVENT_POST_PA,
  2484. WCD_CLSH_STATE_HPHR,
  2485. hph_mode);
  2486. if ((hph_mode != CLS_H_LP) && (hph_mode != CLS_H_ULP))
  2487. /* Ripple freq control disable */
  2488. snd_soc_update_bits(codec,
  2489. WCD934X_SIDO_NEW_VOUT_D_FREQ2,
  2490. 0x01, 0x0);
  2491. /* Re-set RDAC gain */
  2492. if (TAVIL_IS_1_0(tavil->wcd9xxx))
  2493. snd_soc_update_bits(codec,
  2494. WCD934X_HPH_NEW_INT_RDAC_GAIN_CTL,
  2495. 0xF0, 0x0);
  2496. break;
  2497. default:
  2498. break;
  2499. };
  2500. return 0;
  2501. }
  2502. static int tavil_codec_hphl_dac_event(struct snd_soc_dapm_widget *w,
  2503. struct snd_kcontrol *kcontrol,
  2504. int event)
  2505. {
  2506. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2507. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  2508. int hph_mode = tavil->hph_mode;
  2509. u8 dem_inp;
  2510. int ret = 0;
  2511. struct tavil_dsd_config *dsd_conf = tavil->dsd_config;
  2512. uint32_t impedl = 0, impedr = 0;
  2513. dev_dbg(codec->dev, "%s wname: %s event: %d hph_mode: %d\n", __func__,
  2514. w->name, event, hph_mode);
  2515. switch (event) {
  2516. case SND_SOC_DAPM_PRE_PMU:
  2517. if (tavil->anc_func) {
  2518. ret = tavil_codec_enable_anc(w, kcontrol, event);
  2519. /* 40 msec delay is needed to avoid click and pop */
  2520. msleep(40);
  2521. }
  2522. /* Read DEM INP Select */
  2523. dem_inp = snd_soc_read(codec, WCD934X_CDC_RX1_RX_PATH_SEC0) &
  2524. 0x03;
  2525. if (((hph_mode == CLS_H_HIFI) || (hph_mode == CLS_H_LOHIFI) ||
  2526. (hph_mode == CLS_H_LP)) && (dem_inp != 0x01)) {
  2527. dev_err(codec->dev, "%s: DEM Input not set correctly, hph_mode: %d\n",
  2528. __func__, hph_mode);
  2529. return -EINVAL;
  2530. }
  2531. if ((hph_mode != CLS_H_LP) && (hph_mode != CLS_H_ULP))
  2532. /* Ripple freq control enable */
  2533. snd_soc_update_bits(codec,
  2534. WCD934X_SIDO_NEW_VOUT_D_FREQ2,
  2535. 0x01, 0x01);
  2536. /* Disable AutoChop timer during power up */
  2537. snd_soc_update_bits(codec, WCD934X_HPH_NEW_INT_HPH_TIMER1,
  2538. 0x02, 0x00);
  2539. /* Set RDAC gain */
  2540. if (TAVIL_IS_1_0(tavil->wcd9xxx))
  2541. snd_soc_update_bits(codec,
  2542. WCD934X_HPH_NEW_INT_RDAC_GAIN_CTL,
  2543. 0xF0, 0x40);
  2544. if (dsd_conf &&
  2545. (snd_soc_read(codec, WCD934X_CDC_DSD0_PATH_CTL) & 0x01))
  2546. hph_mode = CLS_H_HIFI;
  2547. wcd_clsh_fsm(codec, &tavil->clsh_d,
  2548. WCD_CLSH_EVENT_PRE_DAC,
  2549. WCD_CLSH_STATE_HPHL,
  2550. hph_mode);
  2551. if (tavil->anc_func)
  2552. snd_soc_update_bits(codec,
  2553. WCD934X_CDC_RX1_RX_PATH_CFG0,
  2554. 0x10, 0x10);
  2555. ret = tavil_mbhc_get_impedance(tavil->mbhc,
  2556. &impedl, &impedr);
  2557. if (!ret) {
  2558. wcd_clsh_imped_config(codec, impedl, false);
  2559. set_bit(CLSH_Z_CONFIG, &tavil->status_mask);
  2560. } else {
  2561. dev_dbg(codec->dev, "%s: Failed to get mbhc impedance %d\n",
  2562. __func__, ret);
  2563. ret = 0;
  2564. }
  2565. break;
  2566. case SND_SOC_DAPM_POST_PMD:
  2567. /* 1000us required as per HW requirement */
  2568. usleep_range(1000, 1100);
  2569. wcd_clsh_fsm(codec, &tavil->clsh_d,
  2570. WCD_CLSH_EVENT_POST_PA,
  2571. WCD_CLSH_STATE_HPHL,
  2572. hph_mode);
  2573. if ((hph_mode != CLS_H_LP) && (hph_mode != CLS_H_ULP))
  2574. /* Ripple freq control disable */
  2575. snd_soc_update_bits(codec,
  2576. WCD934X_SIDO_NEW_VOUT_D_FREQ2,
  2577. 0x01, 0x0);
  2578. /* Re-set RDAC gain */
  2579. if (TAVIL_IS_1_0(tavil->wcd9xxx))
  2580. snd_soc_update_bits(codec,
  2581. WCD934X_HPH_NEW_INT_RDAC_GAIN_CTL,
  2582. 0xF0, 0x0);
  2583. if (test_bit(CLSH_Z_CONFIG, &tavil->status_mask)) {
  2584. wcd_clsh_imped_config(codec, impedl, true);
  2585. clear_bit(CLSH_Z_CONFIG, &tavil->status_mask);
  2586. }
  2587. break;
  2588. default:
  2589. break;
  2590. };
  2591. return ret;
  2592. }
  2593. static int tavil_codec_lineout_dac_event(struct snd_soc_dapm_widget *w,
  2594. struct snd_kcontrol *kcontrol,
  2595. int event)
  2596. {
  2597. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2598. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  2599. dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
  2600. switch (event) {
  2601. case SND_SOC_DAPM_PRE_PMU:
  2602. wcd_clsh_fsm(codec, &tavil->clsh_d,
  2603. WCD_CLSH_EVENT_PRE_DAC,
  2604. WCD_CLSH_STATE_LO,
  2605. CLS_AB);
  2606. break;
  2607. case SND_SOC_DAPM_POST_PMD:
  2608. wcd_clsh_fsm(codec, &tavil->clsh_d,
  2609. WCD_CLSH_EVENT_POST_PA,
  2610. WCD_CLSH_STATE_LO,
  2611. CLS_AB);
  2612. break;
  2613. }
  2614. return 0;
  2615. }
  2616. static int tavil_codec_spk_boost_event(struct snd_soc_dapm_widget *w,
  2617. struct snd_kcontrol *kcontrol,
  2618. int event)
  2619. {
  2620. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2621. u16 boost_path_ctl, boost_path_cfg1;
  2622. u16 reg, reg_mix;
  2623. dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
  2624. if (!strcmp(w->name, "RX INT7 CHAIN")) {
  2625. boost_path_ctl = WCD934X_CDC_BOOST0_BOOST_PATH_CTL;
  2626. boost_path_cfg1 = WCD934X_CDC_RX7_RX_PATH_CFG1;
  2627. reg = WCD934X_CDC_RX7_RX_PATH_CTL;
  2628. reg_mix = WCD934X_CDC_RX7_RX_PATH_MIX_CTL;
  2629. } else if (!strcmp(w->name, "RX INT8 CHAIN")) {
  2630. boost_path_ctl = WCD934X_CDC_BOOST1_BOOST_PATH_CTL;
  2631. boost_path_cfg1 = WCD934X_CDC_RX8_RX_PATH_CFG1;
  2632. reg = WCD934X_CDC_RX8_RX_PATH_CTL;
  2633. reg_mix = WCD934X_CDC_RX8_RX_PATH_MIX_CTL;
  2634. } else {
  2635. dev_err(codec->dev, "%s: unknown widget: %s\n",
  2636. __func__, w->name);
  2637. return -EINVAL;
  2638. }
  2639. switch (event) {
  2640. case SND_SOC_DAPM_PRE_PMU:
  2641. snd_soc_update_bits(codec, boost_path_cfg1, 0x01, 0x01);
  2642. snd_soc_update_bits(codec, boost_path_ctl, 0x10, 0x10);
  2643. snd_soc_update_bits(codec, reg, 0x10, 0x00);
  2644. if ((snd_soc_read(codec, reg_mix)) & 0x10)
  2645. snd_soc_update_bits(codec, reg_mix, 0x10, 0x00);
  2646. break;
  2647. case SND_SOC_DAPM_POST_PMD:
  2648. snd_soc_update_bits(codec, boost_path_ctl, 0x10, 0x00);
  2649. snd_soc_update_bits(codec, boost_path_cfg1, 0x01, 0x00);
  2650. break;
  2651. };
  2652. return 0;
  2653. }
  2654. static int __tavil_codec_enable_swr(struct snd_soc_dapm_widget *w, int event)
  2655. {
  2656. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2657. struct tavil_priv *tavil;
  2658. int ch_cnt = 0;
  2659. tavil = snd_soc_codec_get_drvdata(codec);
  2660. if (!tavil->swr.ctrl_data)
  2661. return -EINVAL;
  2662. if (!tavil->swr.ctrl_data[0].swr_pdev)
  2663. return -EINVAL;
  2664. switch (event) {
  2665. case SND_SOC_DAPM_PRE_PMU:
  2666. if (((strnstr(w->name, "INT7_", sizeof("RX INT7_"))) ||
  2667. (strnstr(w->name, "INT7 MIX2",
  2668. sizeof("RX INT7 MIX2")))))
  2669. tavil->swr.rx_7_count++;
  2670. if ((strnstr(w->name, "INT8_", sizeof("RX INT8_"))) &&
  2671. !tavil->swr.rx_8_count)
  2672. tavil->swr.rx_8_count++;
  2673. ch_cnt = !!(tavil->swr.rx_7_count) + tavil->swr.rx_8_count;
  2674. if (wcd9xxx_get_current_power_state(tavil->wcd9xxx,
  2675. WCD9XXX_DIG_CORE_REGION_1)
  2676. != WCD_REGION_POWER_COLLAPSE_REMOVE)
  2677. goto done;
  2678. swrm_wcd_notify(tavil->swr.ctrl_data[0].swr_pdev,
  2679. SWR_DEVICE_UP, NULL);
  2680. swrm_wcd_notify(tavil->swr.ctrl_data[0].swr_pdev,
  2681. SWR_SET_NUM_RX_CH, &ch_cnt);
  2682. break;
  2683. case SND_SOC_DAPM_POST_PMD:
  2684. if ((strnstr(w->name, "INT7_", sizeof("RX INT7_"))) ||
  2685. (strnstr(w->name, "INT7 MIX2",
  2686. sizeof("RX INT7 MIX2"))))
  2687. tavil->swr.rx_7_count--;
  2688. if ((strnstr(w->name, "INT8_", sizeof("RX INT8_"))) &&
  2689. tavil->swr.rx_8_count)
  2690. tavil->swr.rx_8_count--;
  2691. ch_cnt = !!(tavil->swr.rx_7_count) + tavil->swr.rx_8_count;
  2692. swrm_wcd_notify(tavil->swr.ctrl_data[0].swr_pdev,
  2693. SWR_SET_NUM_RX_CH, &ch_cnt);
  2694. break;
  2695. }
  2696. done:
  2697. dev_dbg(tavil->dev, "%s: %s: current swr ch cnt: %d\n",
  2698. __func__, w->name, ch_cnt);
  2699. return 0;
  2700. }
  2701. static int tavil_codec_enable_swr(struct snd_soc_dapm_widget *w,
  2702. struct snd_kcontrol *kcontrol, int event)
  2703. {
  2704. return __tavil_codec_enable_swr(w, event);
  2705. }
  2706. static int tavil_codec_config_mad(struct snd_soc_codec *codec)
  2707. {
  2708. int ret = 0;
  2709. int idx;
  2710. const struct firmware *fw;
  2711. struct firmware_cal *hwdep_cal = NULL;
  2712. struct wcd_mad_audio_cal *mad_cal = NULL;
  2713. const void *data;
  2714. const char *filename = WCD934X_MAD_AUDIO_FIRMWARE_PATH;
  2715. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  2716. size_t cal_size;
  2717. hwdep_cal = wcdcal_get_fw_cal(tavil->fw_data, WCD9XXX_MAD_CAL);
  2718. if (hwdep_cal) {
  2719. data = hwdep_cal->data;
  2720. cal_size = hwdep_cal->size;
  2721. dev_dbg(codec->dev, "%s: using hwdep calibration\n",
  2722. __func__);
  2723. } else {
  2724. ret = request_firmware(&fw, filename, codec->dev);
  2725. if (ret || !fw) {
  2726. dev_err(codec->dev,
  2727. "%s: MAD firmware acquire failed, err = %d\n",
  2728. __func__, ret);
  2729. return -ENODEV;
  2730. }
  2731. data = fw->data;
  2732. cal_size = fw->size;
  2733. dev_dbg(codec->dev, "%s: using request_firmware calibration\n",
  2734. __func__);
  2735. }
  2736. if (cal_size < sizeof(*mad_cal)) {
  2737. dev_err(codec->dev,
  2738. "%s: Incorrect size %zd for MAD Cal, expected %zd\n",
  2739. __func__, cal_size, sizeof(*mad_cal));
  2740. ret = -ENOMEM;
  2741. goto done;
  2742. }
  2743. mad_cal = (struct wcd_mad_audio_cal *) (data);
  2744. if (!mad_cal) {
  2745. dev_err(codec->dev,
  2746. "%s: Invalid calibration data\n",
  2747. __func__);
  2748. ret = -EINVAL;
  2749. goto done;
  2750. }
  2751. snd_soc_write(codec, WCD934X_SOC_MAD_MAIN_CTL_2,
  2752. mad_cal->microphone_info.cycle_time);
  2753. snd_soc_update_bits(codec, WCD934X_SOC_MAD_MAIN_CTL_1, 0xFF << 3,
  2754. ((uint16_t)mad_cal->microphone_info.settle_time)
  2755. << 3);
  2756. /* Audio */
  2757. snd_soc_write(codec, WCD934X_SOC_MAD_AUDIO_CTL_8,
  2758. mad_cal->audio_info.rms_omit_samples);
  2759. snd_soc_update_bits(codec, WCD934X_SOC_MAD_AUDIO_CTL_1,
  2760. 0x07 << 4, mad_cal->audio_info.rms_comp_time << 4);
  2761. snd_soc_update_bits(codec, WCD934X_SOC_MAD_AUDIO_CTL_2, 0x03 << 2,
  2762. mad_cal->audio_info.detection_mechanism << 2);
  2763. snd_soc_write(codec, WCD934X_SOC_MAD_AUDIO_CTL_7,
  2764. mad_cal->audio_info.rms_diff_threshold & 0x3F);
  2765. snd_soc_write(codec, WCD934X_SOC_MAD_AUDIO_CTL_5,
  2766. mad_cal->audio_info.rms_threshold_lsb);
  2767. snd_soc_write(codec, WCD934X_SOC_MAD_AUDIO_CTL_6,
  2768. mad_cal->audio_info.rms_threshold_msb);
  2769. for (idx = 0; idx < ARRAY_SIZE(mad_cal->audio_info.iir_coefficients);
  2770. idx++) {
  2771. snd_soc_update_bits(codec, WCD934X_SOC_MAD_AUDIO_IIR_CTL_PTR,
  2772. 0x3F, idx);
  2773. snd_soc_write(codec, WCD934X_SOC_MAD_AUDIO_IIR_CTL_VAL,
  2774. mad_cal->audio_info.iir_coefficients[idx]);
  2775. dev_dbg(codec->dev, "%s:MAD Audio IIR Coef[%d] = 0X%x",
  2776. __func__, idx,
  2777. mad_cal->audio_info.iir_coefficients[idx]);
  2778. }
  2779. /* Beacon */
  2780. snd_soc_write(codec, WCD934X_SOC_MAD_BEACON_CTL_8,
  2781. mad_cal->beacon_info.rms_omit_samples);
  2782. snd_soc_update_bits(codec, WCD934X_SOC_MAD_BEACON_CTL_1,
  2783. 0x07 << 4, mad_cal->beacon_info.rms_comp_time << 4);
  2784. snd_soc_update_bits(codec, WCD934X_SOC_MAD_BEACON_CTL_2, 0x03 << 2,
  2785. mad_cal->beacon_info.detection_mechanism << 2);
  2786. snd_soc_write(codec, WCD934X_SOC_MAD_BEACON_CTL_7,
  2787. mad_cal->beacon_info.rms_diff_threshold & 0x1F);
  2788. snd_soc_write(codec, WCD934X_SOC_MAD_BEACON_CTL_5,
  2789. mad_cal->beacon_info.rms_threshold_lsb);
  2790. snd_soc_write(codec, WCD934X_SOC_MAD_BEACON_CTL_6,
  2791. mad_cal->beacon_info.rms_threshold_msb);
  2792. for (idx = 0; idx < ARRAY_SIZE(mad_cal->beacon_info.iir_coefficients);
  2793. idx++) {
  2794. snd_soc_update_bits(codec, WCD934X_SOC_MAD_BEACON_IIR_CTL_PTR,
  2795. 0x3F, idx);
  2796. snd_soc_write(codec, WCD934X_SOC_MAD_BEACON_IIR_CTL_VAL,
  2797. mad_cal->beacon_info.iir_coefficients[idx]);
  2798. dev_dbg(codec->dev, "%s:MAD Beacon IIR Coef[%d] = 0X%x",
  2799. __func__, idx,
  2800. mad_cal->beacon_info.iir_coefficients[idx]);
  2801. }
  2802. /* Ultrasound */
  2803. snd_soc_update_bits(codec, WCD934X_SOC_MAD_ULTR_CTL_1,
  2804. 0x07 << 4,
  2805. mad_cal->ultrasound_info.rms_comp_time << 4);
  2806. snd_soc_update_bits(codec, WCD934X_SOC_MAD_ULTR_CTL_2, 0x03 << 2,
  2807. mad_cal->ultrasound_info.detection_mechanism << 2);
  2808. snd_soc_write(codec, WCD934X_SOC_MAD_ULTR_CTL_7,
  2809. mad_cal->ultrasound_info.rms_diff_threshold & 0x1F);
  2810. snd_soc_write(codec, WCD934X_SOC_MAD_ULTR_CTL_5,
  2811. mad_cal->ultrasound_info.rms_threshold_lsb);
  2812. snd_soc_write(codec, WCD934X_SOC_MAD_ULTR_CTL_6,
  2813. mad_cal->ultrasound_info.rms_threshold_msb);
  2814. done:
  2815. if (!hwdep_cal)
  2816. release_firmware(fw);
  2817. return ret;
  2818. }
  2819. static int __tavil_codec_enable_mad(struct snd_soc_codec *codec, bool enable)
  2820. {
  2821. int rc = 0;
  2822. /* Return if CPE INPUT is DEC1 */
  2823. if (snd_soc_read(codec, WCD934X_CPE_SS_SVA_CFG) & 0x04) {
  2824. dev_dbg(codec->dev, "%s: MAD is bypassed, skip mad %s\n",
  2825. __func__, enable ? "enable" : "disable");
  2826. return rc;
  2827. }
  2828. dev_dbg(codec->dev, "%s: enable = %s\n", __func__,
  2829. enable ? "enable" : "disable");
  2830. if (enable) {
  2831. snd_soc_update_bits(codec, WCD934X_SOC_MAD_AUDIO_CTL_2,
  2832. 0x03, 0x03);
  2833. rc = tavil_codec_config_mad(codec);
  2834. if (rc < 0) {
  2835. snd_soc_update_bits(codec, WCD934X_SOC_MAD_AUDIO_CTL_2,
  2836. 0x03, 0x00);
  2837. goto done;
  2838. }
  2839. /* Turn on MAD clk */
  2840. snd_soc_update_bits(codec, WCD934X_CPE_SS_MAD_CTL,
  2841. 0x01, 0x01);
  2842. /* Undo reset for MAD */
  2843. snd_soc_update_bits(codec, WCD934X_CPE_SS_MAD_CTL,
  2844. 0x02, 0x00);
  2845. } else {
  2846. snd_soc_update_bits(codec, WCD934X_SOC_MAD_AUDIO_CTL_2,
  2847. 0x03, 0x00);
  2848. /* Reset the MAD block */
  2849. snd_soc_update_bits(codec, WCD934X_CPE_SS_MAD_CTL,
  2850. 0x02, 0x02);
  2851. /* Turn off MAD clk */
  2852. snd_soc_update_bits(codec, WCD934X_CPE_SS_MAD_CTL,
  2853. 0x01, 0x00);
  2854. }
  2855. done:
  2856. return rc;
  2857. }
  2858. static int tavil_codec_ape_enable_mad(struct snd_soc_dapm_widget *w,
  2859. struct snd_kcontrol *kcontrol,
  2860. int event)
  2861. {
  2862. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2863. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  2864. int rc = 0;
  2865. switch (event) {
  2866. case SND_SOC_DAPM_PRE_PMU:
  2867. snd_soc_update_bits(codec, WCD934X_CPE_SS_SVA_CFG, 0x40, 0x40);
  2868. rc = __tavil_codec_enable_mad(codec, true);
  2869. break;
  2870. case SND_SOC_DAPM_PRE_PMD:
  2871. snd_soc_update_bits(codec, WCD934X_CPE_SS_SVA_CFG, 0x40, 0x00);
  2872. __tavil_codec_enable_mad(codec, false);
  2873. break;
  2874. }
  2875. dev_dbg(tavil->dev, "%s: event = %d\n", __func__, event);
  2876. return rc;
  2877. }
  2878. static int tavil_codec_cpe_mad_ctl(struct snd_soc_dapm_widget *w,
  2879. struct snd_kcontrol *kcontrol, int event)
  2880. {
  2881. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2882. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  2883. int rc = 0;
  2884. switch (event) {
  2885. case SND_SOC_DAPM_PRE_PMU:
  2886. tavil->mad_switch_cnt++;
  2887. if (tavil->mad_switch_cnt != 1)
  2888. goto done;
  2889. snd_soc_update_bits(codec, WCD934X_CPE_SS_SVA_CFG, 0x20, 0x20);
  2890. rc = __tavil_codec_enable_mad(codec, true);
  2891. if (rc < 0) {
  2892. tavil->mad_switch_cnt--;
  2893. goto done;
  2894. }
  2895. break;
  2896. case SND_SOC_DAPM_PRE_PMD:
  2897. tavil->mad_switch_cnt--;
  2898. if (tavil->mad_switch_cnt != 0)
  2899. goto done;
  2900. snd_soc_update_bits(codec, WCD934X_CPE_SS_SVA_CFG, 0x20, 0x00);
  2901. __tavil_codec_enable_mad(codec, false);
  2902. break;
  2903. }
  2904. done:
  2905. dev_dbg(tavil->dev, "%s: event = %d, mad_switch_cnt = %d\n",
  2906. __func__, event, tavil->mad_switch_cnt);
  2907. return rc;
  2908. }
  2909. static int tavil_get_asrc_mode(struct tavil_priv *tavil, int asrc,
  2910. u8 main_sr, u8 mix_sr)
  2911. {
  2912. u8 asrc_output_mode;
  2913. int asrc_mode = CONV_88P2K_TO_384K;
  2914. if ((asrc < 0) || (asrc >= ASRC_MAX))
  2915. return 0;
  2916. asrc_output_mode = tavil->asrc_output_mode[asrc];
  2917. if (asrc_output_mode) {
  2918. /*
  2919. * If Mix sample rate is < 96KHz, use 96K to 352.8K
  2920. * conversion, or else use 384K to 352.8K conversion
  2921. */
  2922. if (mix_sr < 5)
  2923. asrc_mode = CONV_96K_TO_352P8K;
  2924. else
  2925. asrc_mode = CONV_384K_TO_352P8K;
  2926. } else {
  2927. /* Integer main and Fractional mix path */
  2928. if (main_sr < 8 && mix_sr > 9) {
  2929. asrc_mode = CONV_352P8K_TO_384K;
  2930. } else if (main_sr > 8 && mix_sr < 8) {
  2931. /* Fractional main and Integer mix path */
  2932. if (mix_sr < 5)
  2933. asrc_mode = CONV_96K_TO_352P8K;
  2934. else
  2935. asrc_mode = CONV_384K_TO_352P8K;
  2936. } else if (main_sr < 8 && mix_sr < 8) {
  2937. /* Integer main and Integer mix path */
  2938. asrc_mode = CONV_96K_TO_384K;
  2939. }
  2940. }
  2941. return asrc_mode;
  2942. }
  2943. static int tavil_codec_wdma3_ctl(struct snd_soc_dapm_widget *w,
  2944. struct snd_kcontrol *kcontrol, int event)
  2945. {
  2946. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2947. switch (event) {
  2948. case SND_SOC_DAPM_PRE_PMU:
  2949. /* Fix to 16KHz */
  2950. snd_soc_update_bits(codec, WCD934X_DMA_WDMA_CTL_3,
  2951. 0xF0, 0x10);
  2952. /* Select mclk_1 */
  2953. snd_soc_update_bits(codec, WCD934X_DMA_WDMA_CTL_3,
  2954. 0x02, 0x00);
  2955. /* Enable DMA */
  2956. snd_soc_update_bits(codec, WCD934X_DMA_WDMA_CTL_3,
  2957. 0x01, 0x01);
  2958. break;
  2959. case SND_SOC_DAPM_POST_PMD:
  2960. /* Disable DMA */
  2961. snd_soc_update_bits(codec, WCD934X_DMA_WDMA_CTL_3,
  2962. 0x01, 0x00);
  2963. break;
  2964. };
  2965. return 0;
  2966. }
  2967. static int tavil_codec_enable_asrc(struct snd_soc_codec *codec,
  2968. int asrc_in, int event)
  2969. {
  2970. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  2971. u16 cfg_reg, ctl_reg, clk_reg, asrc_ctl, mix_ctl_reg, paired_reg;
  2972. int asrc, ret = 0;
  2973. u8 main_sr, mix_sr, asrc_mode = 0;
  2974. switch (asrc_in) {
  2975. case ASRC_IN_HPHL:
  2976. cfg_reg = WCD934X_CDC_RX1_RX_PATH_CFG0;
  2977. ctl_reg = WCD934X_CDC_RX1_RX_PATH_CTL;
  2978. clk_reg = WCD934X_MIXING_ASRC0_CLK_RST_CTL;
  2979. paired_reg = WCD934X_MIXING_ASRC1_CLK_RST_CTL;
  2980. asrc_ctl = WCD934X_MIXING_ASRC0_CTL1;
  2981. asrc = ASRC0;
  2982. break;
  2983. case ASRC_IN_LO1:
  2984. cfg_reg = WCD934X_CDC_RX3_RX_PATH_CFG0;
  2985. ctl_reg = WCD934X_CDC_RX3_RX_PATH_CTL;
  2986. clk_reg = WCD934X_MIXING_ASRC0_CLK_RST_CTL;
  2987. paired_reg = WCD934X_MIXING_ASRC1_CLK_RST_CTL;
  2988. asrc_ctl = WCD934X_MIXING_ASRC0_CTL1;
  2989. asrc = ASRC0;
  2990. break;
  2991. case ASRC_IN_HPHR:
  2992. cfg_reg = WCD934X_CDC_RX2_RX_PATH_CFG0;
  2993. ctl_reg = WCD934X_CDC_RX2_RX_PATH_CTL;
  2994. clk_reg = WCD934X_MIXING_ASRC1_CLK_RST_CTL;
  2995. paired_reg = WCD934X_MIXING_ASRC0_CLK_RST_CTL;
  2996. asrc_ctl = WCD934X_MIXING_ASRC1_CTL1;
  2997. asrc = ASRC1;
  2998. break;
  2999. case ASRC_IN_LO2:
  3000. cfg_reg = WCD934X_CDC_RX4_RX_PATH_CFG0;
  3001. ctl_reg = WCD934X_CDC_RX4_RX_PATH_CTL;
  3002. clk_reg = WCD934X_MIXING_ASRC1_CLK_RST_CTL;
  3003. paired_reg = WCD934X_MIXING_ASRC0_CLK_RST_CTL;
  3004. asrc_ctl = WCD934X_MIXING_ASRC1_CTL1;
  3005. asrc = ASRC1;
  3006. break;
  3007. case ASRC_IN_SPKR1:
  3008. cfg_reg = WCD934X_CDC_RX7_RX_PATH_CFG0;
  3009. ctl_reg = WCD934X_CDC_RX7_RX_PATH_CTL;
  3010. clk_reg = WCD934X_MIXING_ASRC2_CLK_RST_CTL;
  3011. paired_reg = WCD934X_MIXING_ASRC3_CLK_RST_CTL;
  3012. asrc_ctl = WCD934X_MIXING_ASRC2_CTL1;
  3013. asrc = ASRC2;
  3014. break;
  3015. case ASRC_IN_SPKR2:
  3016. cfg_reg = WCD934X_CDC_RX8_RX_PATH_CFG0;
  3017. ctl_reg = WCD934X_CDC_RX8_RX_PATH_CTL;
  3018. clk_reg = WCD934X_MIXING_ASRC3_CLK_RST_CTL;
  3019. paired_reg = WCD934X_MIXING_ASRC2_CLK_RST_CTL;
  3020. asrc_ctl = WCD934X_MIXING_ASRC3_CTL1;
  3021. asrc = ASRC3;
  3022. break;
  3023. default:
  3024. dev_err(codec->dev, "%s: Invalid asrc input :%d\n", __func__,
  3025. asrc_in);
  3026. ret = -EINVAL;
  3027. goto done;
  3028. };
  3029. switch (event) {
  3030. case SND_SOC_DAPM_PRE_PMU:
  3031. if (tavil->asrc_users[asrc] == 0) {
  3032. if ((snd_soc_read(codec, clk_reg) & 0x02) ||
  3033. (snd_soc_read(codec, paired_reg) & 0x02)) {
  3034. snd_soc_update_bits(codec, clk_reg,
  3035. 0x02, 0x00);
  3036. snd_soc_update_bits(codec, paired_reg,
  3037. 0x02, 0x00);
  3038. }
  3039. snd_soc_update_bits(codec, cfg_reg, 0x80, 0x80);
  3040. snd_soc_update_bits(codec, clk_reg, 0x01, 0x01);
  3041. main_sr = snd_soc_read(codec, ctl_reg) & 0x0F;
  3042. mix_ctl_reg = ctl_reg + 5;
  3043. mix_sr = snd_soc_read(codec, mix_ctl_reg) & 0x0F;
  3044. asrc_mode = tavil_get_asrc_mode(tavil, asrc,
  3045. main_sr, mix_sr);
  3046. dev_dbg(codec->dev, "%s: main_sr:%d mix_sr:%d asrc_mode %d\n",
  3047. __func__, main_sr, mix_sr, asrc_mode);
  3048. snd_soc_update_bits(codec, asrc_ctl, 0x07, asrc_mode);
  3049. }
  3050. tavil->asrc_users[asrc]++;
  3051. break;
  3052. case SND_SOC_DAPM_POST_PMD:
  3053. tavil->asrc_users[asrc]--;
  3054. if (tavil->asrc_users[asrc] <= 0) {
  3055. tavil->asrc_users[asrc] = 0;
  3056. snd_soc_update_bits(codec, asrc_ctl, 0x07, 0x00);
  3057. snd_soc_update_bits(codec, cfg_reg, 0x80, 0x00);
  3058. snd_soc_update_bits(codec, clk_reg, 0x03, 0x02);
  3059. }
  3060. break;
  3061. };
  3062. dev_dbg(codec->dev, "%s: ASRC%d, users: %d\n",
  3063. __func__, asrc, tavil->asrc_users[asrc]);
  3064. done:
  3065. return ret;
  3066. }
  3067. static int tavil_codec_enable_asrc_resampler(struct snd_soc_dapm_widget *w,
  3068. struct snd_kcontrol *kcontrol,
  3069. int event)
  3070. {
  3071. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  3072. int ret = 0;
  3073. u8 cfg, asrc_in;
  3074. cfg = snd_soc_read(codec, WCD934X_CDC_RX_INP_MUX_SPLINE_ASRC_CFG0);
  3075. if (!(cfg & 0xFF)) {
  3076. dev_err(codec->dev, "%s: ASRC%u input not selected\n",
  3077. __func__, w->shift);
  3078. return -EINVAL;
  3079. }
  3080. switch (w->shift) {
  3081. case ASRC0:
  3082. asrc_in = ((cfg & 0x03) == 1) ? ASRC_IN_HPHL : ASRC_IN_LO1;
  3083. ret = tavil_codec_enable_asrc(codec, asrc_in, event);
  3084. break;
  3085. case ASRC1:
  3086. asrc_in = ((cfg & 0x0C) == 4) ? ASRC_IN_HPHR : ASRC_IN_LO2;
  3087. ret = tavil_codec_enable_asrc(codec, asrc_in, event);
  3088. break;
  3089. case ASRC2:
  3090. asrc_in = ((cfg & 0x30) == 0x20) ? ASRC_IN_SPKR1 : ASRC_INVALID;
  3091. ret = tavil_codec_enable_asrc(codec, asrc_in, event);
  3092. break;
  3093. case ASRC3:
  3094. asrc_in = ((cfg & 0xC0) == 0x80) ? ASRC_IN_SPKR2 : ASRC_INVALID;
  3095. ret = tavil_codec_enable_asrc(codec, asrc_in, event);
  3096. break;
  3097. default:
  3098. dev_err(codec->dev, "%s: Invalid asrc:%u\n", __func__,
  3099. w->shift);
  3100. ret = -EINVAL;
  3101. break;
  3102. };
  3103. return ret;
  3104. }
  3105. static int tavil_enable_native_supply(struct snd_soc_dapm_widget *w,
  3106. struct snd_kcontrol *kcontrol, int event)
  3107. {
  3108. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  3109. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  3110. switch (event) {
  3111. case SND_SOC_DAPM_PRE_PMU:
  3112. if (++tavil->native_clk_users == 1) {
  3113. snd_soc_update_bits(codec, WCD934X_CLK_SYS_PLL_ENABLES,
  3114. 0x01, 0x01);
  3115. usleep_range(100, 120);
  3116. snd_soc_update_bits(codec, WCD934X_CLK_SYS_MCLK2_PRG1,
  3117. 0x06, 0x02);
  3118. snd_soc_update_bits(codec, WCD934X_CLK_SYS_MCLK2_PRG1,
  3119. 0x01, 0x01);
  3120. snd_soc_update_bits(codec, WCD934X_CODEC_RPM_CLK_GATE,
  3121. 0x04, 0x00);
  3122. usleep_range(30, 50);
  3123. snd_soc_update_bits(codec,
  3124. WCD934X_CDC_CLK_RST_CTRL_MCLK_CONTROL,
  3125. 0x02, 0x02);
  3126. snd_soc_update_bits(codec,
  3127. WCD934X_CDC_CLK_RST_CTRL_FS_CNT_CONTROL,
  3128. 0x10, 0x10);
  3129. }
  3130. break;
  3131. case SND_SOC_DAPM_PRE_PMD:
  3132. if (tavil->native_clk_users &&
  3133. (--tavil->native_clk_users == 0)) {
  3134. snd_soc_update_bits(codec,
  3135. WCD934X_CDC_CLK_RST_CTRL_FS_CNT_CONTROL,
  3136. 0x10, 0x00);
  3137. snd_soc_update_bits(codec,
  3138. WCD934X_CDC_CLK_RST_CTRL_MCLK_CONTROL,
  3139. 0x02, 0x00);
  3140. snd_soc_update_bits(codec, WCD934X_CODEC_RPM_CLK_GATE,
  3141. 0x04, 0x04);
  3142. snd_soc_update_bits(codec, WCD934X_CLK_SYS_MCLK2_PRG1,
  3143. 0x01, 0x00);
  3144. snd_soc_update_bits(codec, WCD934X_CLK_SYS_MCLK2_PRG1,
  3145. 0x06, 0x00);
  3146. snd_soc_update_bits(codec, WCD934X_CLK_SYS_PLL_ENABLES,
  3147. 0x01, 0x00);
  3148. }
  3149. break;
  3150. }
  3151. dev_dbg(codec->dev, "%s: native_clk_users: %d, event: %d\n",
  3152. __func__, tavil->native_clk_users, event);
  3153. return 0;
  3154. }
  3155. static void tavil_codec_hphdelay_lutbypass(struct snd_soc_codec *codec,
  3156. u16 interp_idx, int event)
  3157. {
  3158. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  3159. u8 hph_dly_mask;
  3160. u16 hph_lut_bypass_reg = 0;
  3161. u16 hph_comp_ctrl7 = 0;
  3162. switch (interp_idx) {
  3163. case INTERP_HPHL:
  3164. hph_dly_mask = 1;
  3165. hph_lut_bypass_reg = WCD934X_CDC_TOP_HPHL_COMP_LUT;
  3166. hph_comp_ctrl7 = WCD934X_CDC_COMPANDER1_CTL7;
  3167. break;
  3168. case INTERP_HPHR:
  3169. hph_dly_mask = 2;
  3170. hph_lut_bypass_reg = WCD934X_CDC_TOP_HPHR_COMP_LUT;
  3171. hph_comp_ctrl7 = WCD934X_CDC_COMPANDER2_CTL7;
  3172. break;
  3173. default:
  3174. break;
  3175. }
  3176. if (hph_lut_bypass_reg && SND_SOC_DAPM_EVENT_ON(event)) {
  3177. snd_soc_update_bits(codec, WCD934X_CDC_CLSH_TEST0,
  3178. hph_dly_mask, 0x0);
  3179. snd_soc_update_bits(codec, hph_lut_bypass_reg, 0x80, 0x80);
  3180. if (tavil->hph_mode == CLS_H_ULP)
  3181. snd_soc_update_bits(codec, hph_comp_ctrl7, 0x20, 0x20);
  3182. }
  3183. if (hph_lut_bypass_reg && SND_SOC_DAPM_EVENT_OFF(event)) {
  3184. snd_soc_update_bits(codec, WCD934X_CDC_CLSH_TEST0,
  3185. hph_dly_mask, hph_dly_mask);
  3186. snd_soc_update_bits(codec, hph_lut_bypass_reg, 0x80, 0x00);
  3187. snd_soc_update_bits(codec, hph_comp_ctrl7, 0x20, 0x0);
  3188. }
  3189. }
  3190. static void tavil_codec_hd2_control(struct tavil_priv *priv,
  3191. u16 interp_idx, int event)
  3192. {
  3193. u16 hd2_scale_reg;
  3194. u16 hd2_enable_reg = 0;
  3195. struct snd_soc_codec *codec = priv->codec;
  3196. if (TAVIL_IS_1_1(priv->wcd9xxx))
  3197. return;
  3198. switch (interp_idx) {
  3199. case INTERP_HPHL:
  3200. hd2_scale_reg = WCD934X_CDC_RX1_RX_PATH_SEC3;
  3201. hd2_enable_reg = WCD934X_CDC_RX1_RX_PATH_CFG0;
  3202. break;
  3203. case INTERP_HPHR:
  3204. hd2_scale_reg = WCD934X_CDC_RX2_RX_PATH_SEC3;
  3205. hd2_enable_reg = WCD934X_CDC_RX2_RX_PATH_CFG0;
  3206. break;
  3207. }
  3208. if (hd2_enable_reg && SND_SOC_DAPM_EVENT_ON(event)) {
  3209. snd_soc_update_bits(codec, hd2_scale_reg, 0x3C, 0x14);
  3210. snd_soc_update_bits(codec, hd2_enable_reg, 0x04, 0x04);
  3211. }
  3212. if (hd2_enable_reg && SND_SOC_DAPM_EVENT_OFF(event)) {
  3213. snd_soc_update_bits(codec, hd2_enable_reg, 0x04, 0x00);
  3214. snd_soc_update_bits(codec, hd2_scale_reg, 0x3C, 0x00);
  3215. }
  3216. }
  3217. static int tavil_codec_config_ear_spkr_gain(struct snd_soc_codec *codec,
  3218. int event, int gain_reg)
  3219. {
  3220. int comp_gain_offset, val;
  3221. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  3222. switch (tavil->swr.spkr_mode) {
  3223. /* Compander gain in SPKR_MODE1 case is 12 dB */
  3224. case WCD934X_SPKR_MODE_1:
  3225. comp_gain_offset = -12;
  3226. break;
  3227. /* Default case compander gain is 15 dB */
  3228. default:
  3229. comp_gain_offset = -15;
  3230. break;
  3231. }
  3232. switch (event) {
  3233. case SND_SOC_DAPM_POST_PMU:
  3234. /* Apply ear spkr gain only if compander is enabled */
  3235. if (tavil->comp_enabled[COMPANDER_7] &&
  3236. (gain_reg == WCD934X_CDC_RX7_RX_VOL_CTL ||
  3237. gain_reg == WCD934X_CDC_RX7_RX_VOL_MIX_CTL) &&
  3238. (tavil->ear_spkr_gain != 0)) {
  3239. /* For example, val is -8(-12+5-1) for 4dB of gain */
  3240. val = comp_gain_offset + tavil->ear_spkr_gain - 1;
  3241. snd_soc_write(codec, gain_reg, val);
  3242. dev_dbg(codec->dev, "%s: RX7 Volume %d dB\n",
  3243. __func__, val);
  3244. }
  3245. break;
  3246. case SND_SOC_DAPM_POST_PMD:
  3247. /*
  3248. * Reset RX7 volume to 0 dB if compander is enabled and
  3249. * ear_spkr_gain is non-zero.
  3250. */
  3251. if (tavil->comp_enabled[COMPANDER_7] &&
  3252. (gain_reg == WCD934X_CDC_RX7_RX_VOL_CTL ||
  3253. gain_reg == WCD934X_CDC_RX7_RX_VOL_MIX_CTL) &&
  3254. (tavil->ear_spkr_gain != 0)) {
  3255. snd_soc_write(codec, gain_reg, 0x0);
  3256. dev_dbg(codec->dev, "%s: Reset RX7 Volume to 0 dB\n",
  3257. __func__);
  3258. }
  3259. break;
  3260. }
  3261. return 0;
  3262. }
  3263. static int tavil_config_compander(struct snd_soc_codec *codec, int interp_n,
  3264. int event)
  3265. {
  3266. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  3267. int comp;
  3268. u16 comp_ctl0_reg, rx_path_cfg0_reg;
  3269. /* EAR does not have compander */
  3270. if (!interp_n)
  3271. return 0;
  3272. comp = interp_n - 1;
  3273. dev_dbg(codec->dev, "%s: event %d compander %d, enabled %d\n",
  3274. __func__, event, comp + 1, tavil->comp_enabled[comp]);
  3275. if (!tavil->comp_enabled[comp])
  3276. return 0;
  3277. comp_ctl0_reg = WCD934X_CDC_COMPANDER1_CTL0 + (comp * 8);
  3278. rx_path_cfg0_reg = WCD934X_CDC_RX1_RX_PATH_CFG0 + (comp * 20);
  3279. if (SND_SOC_DAPM_EVENT_ON(event)) {
  3280. /* Enable Compander Clock */
  3281. snd_soc_update_bits(codec, comp_ctl0_reg, 0x01, 0x01);
  3282. snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x02);
  3283. snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x00);
  3284. snd_soc_update_bits(codec, rx_path_cfg0_reg, 0x02, 0x02);
  3285. }
  3286. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  3287. snd_soc_update_bits(codec, rx_path_cfg0_reg, 0x02, 0x00);
  3288. snd_soc_update_bits(codec, comp_ctl0_reg, 0x04, 0x04);
  3289. snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x02);
  3290. snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x00);
  3291. snd_soc_update_bits(codec, comp_ctl0_reg, 0x01, 0x00);
  3292. snd_soc_update_bits(codec, comp_ctl0_reg, 0x04, 0x00);
  3293. }
  3294. return 0;
  3295. }
  3296. static void tavil_codec_idle_detect_control(struct snd_soc_codec *codec,
  3297. int interp, int event)
  3298. {
  3299. int reg = 0, mask, val;
  3300. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  3301. if (!tavil->idle_det_cfg.hph_idle_detect_en)
  3302. return;
  3303. if (interp == INTERP_HPHL) {
  3304. reg = WCD934X_CDC_RX_IDLE_DET_PATH_CTL;
  3305. mask = 0x01;
  3306. val = 0x01;
  3307. }
  3308. if (interp == INTERP_HPHR) {
  3309. reg = WCD934X_CDC_RX_IDLE_DET_PATH_CTL;
  3310. mask = 0x02;
  3311. val = 0x02;
  3312. }
  3313. if (reg && SND_SOC_DAPM_EVENT_ON(event))
  3314. snd_soc_update_bits(codec, reg, mask, val);
  3315. if (reg && SND_SOC_DAPM_EVENT_OFF(event)) {
  3316. snd_soc_update_bits(codec, reg, mask, 0x00);
  3317. tavil->idle_det_cfg.hph_idle_thr = 0;
  3318. snd_soc_write(codec, WCD934X_CDC_RX_IDLE_DET_CFG3, 0x0);
  3319. }
  3320. }
  3321. /**
  3322. * tavil_codec_enable_interp_clk - Enable main path Interpolator
  3323. * clock.
  3324. *
  3325. * @codec: Codec instance
  3326. * @event: Indicates speaker path gain offset value
  3327. * @intp_idx: Interpolator index
  3328. * Returns number of main clock users
  3329. */
  3330. int tavil_codec_enable_interp_clk(struct snd_soc_codec *codec,
  3331. int event, int interp_idx)
  3332. {
  3333. struct tavil_priv *tavil;
  3334. u16 main_reg;
  3335. if (!codec) {
  3336. pr_err("%s: codec is NULL\n", __func__);
  3337. return -EINVAL;
  3338. }
  3339. tavil = snd_soc_codec_get_drvdata(codec);
  3340. main_reg = WCD934X_CDC_RX0_RX_PATH_CTL + (interp_idx * 20);
  3341. if (SND_SOC_DAPM_EVENT_ON(event)) {
  3342. if (tavil->main_clk_users[interp_idx] == 0) {
  3343. /* Main path PGA mute enable */
  3344. snd_soc_update_bits(codec, main_reg, 0x10, 0x10);
  3345. /* Clk enable */
  3346. snd_soc_update_bits(codec, main_reg, 0x20, 0x20);
  3347. tavil_codec_idle_detect_control(codec, interp_idx,
  3348. event);
  3349. tavil_codec_hd2_control(tavil, interp_idx, event);
  3350. tavil_codec_hphdelay_lutbypass(codec, interp_idx,
  3351. event);
  3352. tavil_config_compander(codec, interp_idx, event);
  3353. }
  3354. tavil->main_clk_users[interp_idx]++;
  3355. }
  3356. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  3357. tavil->main_clk_users[interp_idx]--;
  3358. if (tavil->main_clk_users[interp_idx] <= 0) {
  3359. tavil->main_clk_users[interp_idx] = 0;
  3360. tavil_config_compander(codec, interp_idx, event);
  3361. tavil_codec_hphdelay_lutbypass(codec, interp_idx,
  3362. event);
  3363. tavil_codec_hd2_control(tavil, interp_idx, event);
  3364. tavil_codec_idle_detect_control(codec, interp_idx,
  3365. event);
  3366. /* Clk Disable */
  3367. snd_soc_update_bits(codec, main_reg, 0x20, 0x00);
  3368. /* Reset enable and disable */
  3369. snd_soc_update_bits(codec, main_reg, 0x40, 0x40);
  3370. snd_soc_update_bits(codec, main_reg, 0x40, 0x00);
  3371. /* Reset rate to 48K*/
  3372. snd_soc_update_bits(codec, main_reg, 0x0F, 0x04);
  3373. }
  3374. }
  3375. dev_dbg(codec->dev, "%s event %d main_clk_users %d\n",
  3376. __func__, event, tavil->main_clk_users[interp_idx]);
  3377. return tavil->main_clk_users[interp_idx];
  3378. }
  3379. EXPORT_SYMBOL(tavil_codec_enable_interp_clk);
  3380. static int tavil_anc_out_switch_cb(struct snd_soc_dapm_widget *w,
  3381. struct snd_kcontrol *kcontrol, int event)
  3382. {
  3383. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  3384. tavil_codec_enable_interp_clk(codec, event, w->shift);
  3385. return 0;
  3386. }
  3387. static int tavil_codec_set_idle_detect_thr(struct snd_soc_codec *codec,
  3388. int interp, int path_type)
  3389. {
  3390. int port_id[4] = { 0, 0, 0, 0 };
  3391. int *port_ptr, num_ports;
  3392. int bit_width = 0, i;
  3393. int mux_reg, mux_reg_val;
  3394. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  3395. int dai_id, idle_thr;
  3396. if ((interp != INTERP_HPHL) && (interp != INTERP_HPHR))
  3397. return 0;
  3398. if (!tavil->idle_det_cfg.hph_idle_detect_en)
  3399. return 0;
  3400. port_ptr = &port_id[0];
  3401. num_ports = 0;
  3402. /*
  3403. * Read interpolator MUX input registers and find
  3404. * which slimbus port is connected and store the port
  3405. * numbers in port_id array.
  3406. */
  3407. if (path_type == INTERP_MIX_PATH) {
  3408. mux_reg = WCD934X_CDC_RX_INP_MUX_RX_INT1_CFG1 +
  3409. 2 * (interp - 1);
  3410. mux_reg_val = snd_soc_read(codec, mux_reg) & 0x0f;
  3411. if ((mux_reg_val >= INTn_2_INP_SEL_RX0) &&
  3412. (mux_reg_val < INTn_2_INP_SEL_PROXIMITY)) {
  3413. *port_ptr++ = mux_reg_val +
  3414. WCD934X_RX_PORT_START_NUMBER - 1;
  3415. num_ports++;
  3416. }
  3417. }
  3418. if (path_type == INTERP_MAIN_PATH) {
  3419. mux_reg = WCD934X_CDC_RX_INP_MUX_RX_INT1_CFG0 +
  3420. 2 * (interp - 1);
  3421. mux_reg_val = snd_soc_read(codec, mux_reg) & 0x0f;
  3422. i = WCD934X_INTERP_MUX_NUM_INPUTS;
  3423. while (i) {
  3424. if ((mux_reg_val >= INTn_1_INP_SEL_RX0) &&
  3425. (mux_reg_val <= INTn_1_INP_SEL_RX7)) {
  3426. *port_ptr++ = mux_reg_val +
  3427. WCD934X_RX_PORT_START_NUMBER -
  3428. INTn_1_INP_SEL_RX0;
  3429. num_ports++;
  3430. }
  3431. mux_reg_val = (snd_soc_read(codec, mux_reg) &
  3432. 0xf0) >> 4;
  3433. mux_reg += 1;
  3434. i--;
  3435. }
  3436. }
  3437. dev_dbg(codec->dev, "%s: num_ports: %d, ports[%d %d %d %d]\n",
  3438. __func__, num_ports, port_id[0], port_id[1],
  3439. port_id[2], port_id[3]);
  3440. i = 0;
  3441. while (num_ports) {
  3442. dai_id = tavil_find_playback_dai_id_for_port(port_id[i++],
  3443. tavil);
  3444. if ((dai_id >= 0) && (dai_id < NUM_CODEC_DAIS)) {
  3445. dev_dbg(codec->dev, "%s: dai_id: %d bit_width: %d\n",
  3446. __func__, dai_id,
  3447. tavil->dai[dai_id].bit_width);
  3448. if (tavil->dai[dai_id].bit_width > bit_width)
  3449. bit_width = tavil->dai[dai_id].bit_width;
  3450. }
  3451. num_ports--;
  3452. }
  3453. switch (bit_width) {
  3454. case 16:
  3455. idle_thr = 0xff; /* F16 */
  3456. break;
  3457. case 24:
  3458. case 32:
  3459. idle_thr = 0x03; /* F22 */
  3460. break;
  3461. default:
  3462. idle_thr = 0x00;
  3463. break;
  3464. }
  3465. dev_dbg(codec->dev, "%s: (new) idle_thr: %d, (cur) idle_thr: %d\n",
  3466. __func__, idle_thr, tavil->idle_det_cfg.hph_idle_thr);
  3467. if ((tavil->idle_det_cfg.hph_idle_thr == 0) ||
  3468. (idle_thr < tavil->idle_det_cfg.hph_idle_thr)) {
  3469. snd_soc_write(codec, WCD934X_CDC_RX_IDLE_DET_CFG3, idle_thr);
  3470. tavil->idle_det_cfg.hph_idle_thr = idle_thr;
  3471. }
  3472. return 0;
  3473. }
  3474. static int tavil_codec_enable_mix_path(struct snd_soc_dapm_widget *w,
  3475. struct snd_kcontrol *kcontrol,
  3476. int event)
  3477. {
  3478. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  3479. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  3480. u16 gain_reg, mix_reg;
  3481. int offset_val = 0;
  3482. int val = 0;
  3483. if (w->shift >= WCD934X_NUM_INTERPOLATORS ||
  3484. w->shift == INTERP_LO3_NA || w->shift == INTERP_LO4_NA) {
  3485. dev_err(codec->dev, "%s: Invalid Interpolator value %d for name %s\n",
  3486. __func__, w->shift, w->name);
  3487. return -EINVAL;
  3488. };
  3489. gain_reg = WCD934X_CDC_RX0_RX_VOL_MIX_CTL +
  3490. (w->shift * WCD934X_RX_PATH_CTL_OFFSET);
  3491. mix_reg = WCD934X_CDC_RX0_RX_PATH_MIX_CTL +
  3492. (w->shift * WCD934X_RX_PATH_CTL_OFFSET);
  3493. if (w->shift == INTERP_SPKR1 || w->shift == INTERP_SPKR2)
  3494. __tavil_codec_enable_swr(w, event);
  3495. switch (event) {
  3496. case SND_SOC_DAPM_PRE_PMU:
  3497. tavil_codec_set_idle_detect_thr(codec, w->shift,
  3498. INTERP_MIX_PATH);
  3499. tavil_codec_enable_interp_clk(codec, event, w->shift);
  3500. /* Clk enable */
  3501. snd_soc_update_bits(codec, mix_reg, 0x20, 0x20);
  3502. break;
  3503. case SND_SOC_DAPM_POST_PMU:
  3504. if ((tavil->swr.spkr_gain_offset ==
  3505. WCD934X_RX_GAIN_OFFSET_M1P5_DB) &&
  3506. (tavil->comp_enabled[COMPANDER_7] ||
  3507. tavil->comp_enabled[COMPANDER_8]) &&
  3508. (gain_reg == WCD934X_CDC_RX7_RX_VOL_MIX_CTL ||
  3509. gain_reg == WCD934X_CDC_RX8_RX_VOL_MIX_CTL)) {
  3510. snd_soc_update_bits(codec, WCD934X_CDC_RX7_RX_PATH_SEC1,
  3511. 0x01, 0x01);
  3512. snd_soc_update_bits(codec,
  3513. WCD934X_CDC_RX7_RX_PATH_MIX_SEC0,
  3514. 0x01, 0x01);
  3515. snd_soc_update_bits(codec, WCD934X_CDC_RX8_RX_PATH_SEC1,
  3516. 0x01, 0x01);
  3517. snd_soc_update_bits(codec,
  3518. WCD934X_CDC_RX8_RX_PATH_MIX_SEC0,
  3519. 0x01, 0x01);
  3520. offset_val = -2;
  3521. }
  3522. val = snd_soc_read(codec, gain_reg);
  3523. val += offset_val;
  3524. snd_soc_write(codec, gain_reg, val);
  3525. tavil_codec_config_ear_spkr_gain(codec, event, gain_reg);
  3526. break;
  3527. case SND_SOC_DAPM_POST_PMD:
  3528. /* Clk Disable */
  3529. snd_soc_update_bits(codec, mix_reg, 0x20, 0x00);
  3530. tavil_codec_enable_interp_clk(codec, event, w->shift);
  3531. /* Reset enable and disable */
  3532. snd_soc_update_bits(codec, mix_reg, 0x40, 0x40);
  3533. snd_soc_update_bits(codec, mix_reg, 0x40, 0x00);
  3534. if ((tavil->swr.spkr_gain_offset ==
  3535. WCD934X_RX_GAIN_OFFSET_M1P5_DB) &&
  3536. (tavil->comp_enabled[COMPANDER_7] ||
  3537. tavil->comp_enabled[COMPANDER_8]) &&
  3538. (gain_reg == WCD934X_CDC_RX7_RX_VOL_MIX_CTL ||
  3539. gain_reg == WCD934X_CDC_RX8_RX_VOL_MIX_CTL)) {
  3540. snd_soc_update_bits(codec, WCD934X_CDC_RX7_RX_PATH_SEC1,
  3541. 0x01, 0x00);
  3542. snd_soc_update_bits(codec,
  3543. WCD934X_CDC_RX7_RX_PATH_MIX_SEC0,
  3544. 0x01, 0x00);
  3545. snd_soc_update_bits(codec, WCD934X_CDC_RX8_RX_PATH_SEC1,
  3546. 0x01, 0x00);
  3547. snd_soc_update_bits(codec,
  3548. WCD934X_CDC_RX8_RX_PATH_MIX_SEC0,
  3549. 0x01, 0x00);
  3550. offset_val = 2;
  3551. val = snd_soc_read(codec, gain_reg);
  3552. val += offset_val;
  3553. snd_soc_write(codec, gain_reg, val);
  3554. }
  3555. tavil_codec_config_ear_spkr_gain(codec, event, gain_reg);
  3556. break;
  3557. };
  3558. dev_dbg(codec->dev, "%s event %d name %s\n", __func__, event, w->name);
  3559. return 0;
  3560. }
  3561. /**
  3562. * tavil_get_dsd_config - Get pointer to dsd config structure
  3563. *
  3564. * @codec: pointer to snd_soc_codec structure
  3565. *
  3566. * Returns pointer to tavil_dsd_config structure
  3567. */
  3568. struct tavil_dsd_config *tavil_get_dsd_config(struct snd_soc_codec *codec)
  3569. {
  3570. struct tavil_priv *tavil;
  3571. if (!codec)
  3572. return NULL;
  3573. tavil = snd_soc_codec_get_drvdata(codec);
  3574. if (!tavil)
  3575. return NULL;
  3576. return tavil->dsd_config;
  3577. }
  3578. EXPORT_SYMBOL(tavil_get_dsd_config);
  3579. static int tavil_codec_enable_main_path(struct snd_soc_dapm_widget *w,
  3580. struct snd_kcontrol *kcontrol,
  3581. int event)
  3582. {
  3583. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  3584. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  3585. u16 gain_reg;
  3586. u16 reg;
  3587. int val;
  3588. int offset_val = 0;
  3589. dev_dbg(codec->dev, "%s %d %s\n", __func__, event, w->name);
  3590. if (w->shift >= WCD934X_NUM_INTERPOLATORS ||
  3591. w->shift == INTERP_LO3_NA || w->shift == INTERP_LO4_NA) {
  3592. dev_err(codec->dev, "%s: Invalid Interpolator value %d for name %s\n",
  3593. __func__, w->shift, w->name);
  3594. return -EINVAL;
  3595. };
  3596. reg = WCD934X_CDC_RX0_RX_PATH_CTL + (w->shift *
  3597. WCD934X_RX_PATH_CTL_OFFSET);
  3598. gain_reg = WCD934X_CDC_RX0_RX_VOL_CTL + (w->shift *
  3599. WCD934X_RX_PATH_CTL_OFFSET);
  3600. switch (event) {
  3601. case SND_SOC_DAPM_PRE_PMU:
  3602. tavil_codec_set_idle_detect_thr(codec, w->shift,
  3603. INTERP_MAIN_PATH);
  3604. tavil_codec_enable_interp_clk(codec, event, w->shift);
  3605. break;
  3606. case SND_SOC_DAPM_POST_PMU:
  3607. /* apply gain after int clk is enabled */
  3608. if ((tavil->swr.spkr_gain_offset ==
  3609. WCD934X_RX_GAIN_OFFSET_M1P5_DB) &&
  3610. (tavil->comp_enabled[COMPANDER_7] ||
  3611. tavil->comp_enabled[COMPANDER_8]) &&
  3612. (gain_reg == WCD934X_CDC_RX7_RX_VOL_CTL ||
  3613. gain_reg == WCD934X_CDC_RX8_RX_VOL_CTL)) {
  3614. snd_soc_update_bits(codec, WCD934X_CDC_RX7_RX_PATH_SEC1,
  3615. 0x01, 0x01);
  3616. snd_soc_update_bits(codec,
  3617. WCD934X_CDC_RX7_RX_PATH_MIX_SEC0,
  3618. 0x01, 0x01);
  3619. snd_soc_update_bits(codec, WCD934X_CDC_RX8_RX_PATH_SEC1,
  3620. 0x01, 0x01);
  3621. snd_soc_update_bits(codec,
  3622. WCD934X_CDC_RX8_RX_PATH_MIX_SEC0,
  3623. 0x01, 0x01);
  3624. offset_val = -2;
  3625. }
  3626. val = snd_soc_read(codec, gain_reg);
  3627. val += offset_val;
  3628. snd_soc_write(codec, gain_reg, val);
  3629. tavil_codec_config_ear_spkr_gain(codec, event, gain_reg);
  3630. break;
  3631. case SND_SOC_DAPM_POST_PMD:
  3632. tavil_codec_enable_interp_clk(codec, event, w->shift);
  3633. if ((tavil->swr.spkr_gain_offset ==
  3634. WCD934X_RX_GAIN_OFFSET_M1P5_DB) &&
  3635. (tavil->comp_enabled[COMPANDER_7] ||
  3636. tavil->comp_enabled[COMPANDER_8]) &&
  3637. (gain_reg == WCD934X_CDC_RX7_RX_VOL_CTL ||
  3638. gain_reg == WCD934X_CDC_RX8_RX_VOL_CTL)) {
  3639. snd_soc_update_bits(codec, WCD934X_CDC_RX7_RX_PATH_SEC1,
  3640. 0x01, 0x00);
  3641. snd_soc_update_bits(codec,
  3642. WCD934X_CDC_RX7_RX_PATH_MIX_SEC0,
  3643. 0x01, 0x00);
  3644. snd_soc_update_bits(codec, WCD934X_CDC_RX8_RX_PATH_SEC1,
  3645. 0x01, 0x00);
  3646. snd_soc_update_bits(codec,
  3647. WCD934X_CDC_RX8_RX_PATH_MIX_SEC0,
  3648. 0x01, 0x00);
  3649. offset_val = 2;
  3650. val = snd_soc_read(codec, gain_reg);
  3651. val += offset_val;
  3652. snd_soc_write(codec, gain_reg, val);
  3653. }
  3654. tavil_codec_config_ear_spkr_gain(codec, event, gain_reg);
  3655. break;
  3656. };
  3657. return 0;
  3658. }
  3659. static int tavil_codec_set_iir_gain(struct snd_soc_dapm_widget *w,
  3660. struct snd_kcontrol *kcontrol, int event)
  3661. {
  3662. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  3663. dev_dbg(codec->dev, "%s: event = %d\n", __func__, event);
  3664. switch (event) {
  3665. case SND_SOC_DAPM_POST_PMU: /* fall through */
  3666. case SND_SOC_DAPM_PRE_PMD:
  3667. if (strnstr(w->name, "IIR0", sizeof("IIR0"))) {
  3668. snd_soc_write(codec,
  3669. WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B1_CTL,
  3670. snd_soc_read(codec,
  3671. WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B1_CTL));
  3672. snd_soc_write(codec,
  3673. WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B2_CTL,
  3674. snd_soc_read(codec,
  3675. WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B2_CTL));
  3676. snd_soc_write(codec,
  3677. WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B3_CTL,
  3678. snd_soc_read(codec,
  3679. WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B3_CTL));
  3680. snd_soc_write(codec,
  3681. WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B4_CTL,
  3682. snd_soc_read(codec,
  3683. WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B4_CTL));
  3684. } else {
  3685. snd_soc_write(codec,
  3686. WCD934X_CDC_SIDETONE_IIR1_IIR_GAIN_B1_CTL,
  3687. snd_soc_read(codec,
  3688. WCD934X_CDC_SIDETONE_IIR1_IIR_GAIN_B1_CTL));
  3689. snd_soc_write(codec,
  3690. WCD934X_CDC_SIDETONE_IIR1_IIR_GAIN_B2_CTL,
  3691. snd_soc_read(codec,
  3692. WCD934X_CDC_SIDETONE_IIR1_IIR_GAIN_B2_CTL));
  3693. snd_soc_write(codec,
  3694. WCD934X_CDC_SIDETONE_IIR1_IIR_GAIN_B3_CTL,
  3695. snd_soc_read(codec,
  3696. WCD934X_CDC_SIDETONE_IIR1_IIR_GAIN_B3_CTL));
  3697. }
  3698. break;
  3699. }
  3700. return 0;
  3701. }
  3702. static int tavil_codec_find_amic_input(struct snd_soc_codec *codec,
  3703. int adc_mux_n)
  3704. {
  3705. u16 mask, shift, adc_mux_in_reg;
  3706. u16 amic_mux_sel_reg;
  3707. bool is_amic;
  3708. if (adc_mux_n < 0 || adc_mux_n > WCD934X_MAX_VALID_ADC_MUX ||
  3709. adc_mux_n == WCD934X_INVALID_ADC_MUX)
  3710. return 0;
  3711. if (adc_mux_n < 3) {
  3712. adc_mux_in_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG1 +
  3713. 2 * adc_mux_n;
  3714. mask = 0x03;
  3715. shift = 0;
  3716. amic_mux_sel_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG0 +
  3717. 2 * adc_mux_n;
  3718. } else if (adc_mux_n < 4) {
  3719. adc_mux_in_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX3_CFG1;
  3720. mask = 0x03;
  3721. shift = 0;
  3722. amic_mux_sel_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG0 +
  3723. 2 * adc_mux_n;
  3724. } else if (adc_mux_n < 7) {
  3725. adc_mux_in_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG1 +
  3726. 2 * (adc_mux_n - 4);
  3727. mask = 0x0C;
  3728. shift = 2;
  3729. amic_mux_sel_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX4_CFG0 +
  3730. adc_mux_n - 4;
  3731. } else if (adc_mux_n < 8) {
  3732. adc_mux_in_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX3_CFG1;
  3733. mask = 0x0C;
  3734. shift = 2;
  3735. amic_mux_sel_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX4_CFG0 +
  3736. adc_mux_n - 4;
  3737. } else if (adc_mux_n < 12) {
  3738. adc_mux_in_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG1 +
  3739. 2 * (((adc_mux_n == 8) ? (adc_mux_n - 8) :
  3740. (adc_mux_n - 9)));
  3741. mask = 0x30;
  3742. shift = 4;
  3743. amic_mux_sel_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX8_CFG0 +
  3744. ((adc_mux_n == 8) ? (adc_mux_n - 8) :
  3745. (adc_mux_n - 9));
  3746. } else if (adc_mux_n < 13) {
  3747. adc_mux_in_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX3_CFG1;
  3748. mask = 0x30;
  3749. shift = 4;
  3750. amic_mux_sel_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX4_CFG0 +
  3751. adc_mux_n - 5;
  3752. } else {
  3753. adc_mux_in_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG1;
  3754. mask = 0xC0;
  3755. shift = 6;
  3756. amic_mux_sel_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX4_CFG0 +
  3757. adc_mux_n - 5;
  3758. }
  3759. is_amic = (((snd_soc_read(codec, adc_mux_in_reg) & mask) >> shift)
  3760. == 1);
  3761. if (!is_amic)
  3762. return 0;
  3763. return snd_soc_read(codec, amic_mux_sel_reg) & 0x07;
  3764. }
  3765. static void tavil_codec_set_tx_hold(struct snd_soc_codec *codec,
  3766. u16 amic_reg, bool set)
  3767. {
  3768. u8 mask = 0x20;
  3769. u8 val;
  3770. if (amic_reg == WCD934X_ANA_AMIC1 ||
  3771. amic_reg == WCD934X_ANA_AMIC3)
  3772. mask = 0x40;
  3773. val = set ? mask : 0x00;
  3774. switch (amic_reg) {
  3775. case WCD934X_ANA_AMIC1:
  3776. case WCD934X_ANA_AMIC2:
  3777. snd_soc_update_bits(codec, WCD934X_ANA_AMIC2, mask, val);
  3778. break;
  3779. case WCD934X_ANA_AMIC3:
  3780. case WCD934X_ANA_AMIC4:
  3781. snd_soc_update_bits(codec, WCD934X_ANA_AMIC4, mask, val);
  3782. break;
  3783. default:
  3784. dev_dbg(codec->dev, "%s: invalid amic: %d\n",
  3785. __func__, amic_reg);
  3786. break;
  3787. }
  3788. }
  3789. static int tavil_codec_tx_adc_cfg(struct snd_soc_dapm_widget *w,
  3790. struct snd_kcontrol *kcontrol, int event)
  3791. {
  3792. int adc_mux_n = w->shift;
  3793. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  3794. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  3795. int amic_n;
  3796. dev_dbg(codec->dev, "%s: event: %d\n", __func__, event);
  3797. switch (event) {
  3798. case SND_SOC_DAPM_POST_PMU:
  3799. amic_n = tavil_codec_find_amic_input(codec, adc_mux_n);
  3800. if (amic_n) {
  3801. /*
  3802. * Prevent ANC Rx pop by leaving Tx FE in HOLD
  3803. * state until PA is up. Track AMIC being used
  3804. * so we can release the HOLD later.
  3805. */
  3806. set_bit(ANC_MIC_AMIC1 + amic_n - 1,
  3807. &tavil->status_mask);
  3808. }
  3809. break;
  3810. default:
  3811. break;
  3812. }
  3813. return 0;
  3814. }
  3815. static u16 tavil_codec_get_amic_pwlvl_reg(struct snd_soc_codec *codec, int amic)
  3816. {
  3817. u16 pwr_level_reg = 0;
  3818. switch (amic) {
  3819. case 1:
  3820. case 2:
  3821. pwr_level_reg = WCD934X_ANA_AMIC1;
  3822. break;
  3823. case 3:
  3824. case 4:
  3825. pwr_level_reg = WCD934X_ANA_AMIC3;
  3826. break;
  3827. default:
  3828. dev_dbg(codec->dev, "%s: invalid amic: %d\n",
  3829. __func__, amic);
  3830. break;
  3831. }
  3832. return pwr_level_reg;
  3833. }
  3834. #define TX_HPF_CUT_OFF_FREQ_MASK 0x60
  3835. #define CF_MIN_3DB_4HZ 0x0
  3836. #define CF_MIN_3DB_75HZ 0x1
  3837. #define CF_MIN_3DB_150HZ 0x2
  3838. static void tavil_tx_hpf_corner_freq_callback(struct work_struct *work)
  3839. {
  3840. struct delayed_work *hpf_delayed_work;
  3841. struct hpf_work *hpf_work;
  3842. struct tavil_priv *tavil;
  3843. struct snd_soc_codec *codec;
  3844. u16 dec_cfg_reg, amic_reg, go_bit_reg;
  3845. u8 hpf_cut_off_freq;
  3846. int amic_n;
  3847. hpf_delayed_work = to_delayed_work(work);
  3848. hpf_work = container_of(hpf_delayed_work, struct hpf_work, dwork);
  3849. tavil = hpf_work->tavil;
  3850. codec = tavil->codec;
  3851. hpf_cut_off_freq = hpf_work->hpf_cut_off_freq;
  3852. dec_cfg_reg = WCD934X_CDC_TX0_TX_PATH_CFG0 + 16 * hpf_work->decimator;
  3853. go_bit_reg = dec_cfg_reg + 7;
  3854. dev_dbg(codec->dev, "%s: decimator %u hpf_cut_of_freq 0x%x\n",
  3855. __func__, hpf_work->decimator, hpf_cut_off_freq);
  3856. amic_n = tavil_codec_find_amic_input(codec, hpf_work->decimator);
  3857. if (amic_n) {
  3858. amic_reg = WCD934X_ANA_AMIC1 + amic_n - 1;
  3859. tavil_codec_set_tx_hold(codec, amic_reg, false);
  3860. }
  3861. snd_soc_update_bits(codec, dec_cfg_reg, TX_HPF_CUT_OFF_FREQ_MASK,
  3862. hpf_cut_off_freq << 5);
  3863. snd_soc_update_bits(codec, go_bit_reg, 0x02, 0x02);
  3864. /* Minimum 1 clk cycle delay is required as per HW spec */
  3865. usleep_range(1000, 1010);
  3866. snd_soc_update_bits(codec, go_bit_reg, 0x02, 0x00);
  3867. }
  3868. static void tavil_tx_mute_update_callback(struct work_struct *work)
  3869. {
  3870. struct tx_mute_work *tx_mute_dwork;
  3871. struct tavil_priv *tavil;
  3872. struct delayed_work *delayed_work;
  3873. struct snd_soc_codec *codec;
  3874. u16 tx_vol_ctl_reg, hpf_gate_reg;
  3875. delayed_work = to_delayed_work(work);
  3876. tx_mute_dwork = container_of(delayed_work, struct tx_mute_work, dwork);
  3877. tavil = tx_mute_dwork->tavil;
  3878. codec = tavil->codec;
  3879. tx_vol_ctl_reg = WCD934X_CDC_TX0_TX_PATH_CTL +
  3880. 16 * tx_mute_dwork->decimator;
  3881. hpf_gate_reg = WCD934X_CDC_TX0_TX_PATH_SEC2 +
  3882. 16 * tx_mute_dwork->decimator;
  3883. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x10, 0x00);
  3884. }
  3885. static int tavil_codec_enable_rx_path_clk(struct snd_soc_dapm_widget *w,
  3886. struct snd_kcontrol *kcontrol, int event)
  3887. {
  3888. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  3889. u16 sidetone_reg;
  3890. dev_dbg(codec->dev, "%s %d %d\n", __func__, event, w->shift);
  3891. sidetone_reg = WCD934X_CDC_RX0_RX_PATH_CFG1 + 0x14*(w->shift);
  3892. switch (event) {
  3893. case SND_SOC_DAPM_PRE_PMU:
  3894. if (!strcmp(w->name, "RX INT7 MIX2 INP"))
  3895. __tavil_codec_enable_swr(w, event);
  3896. tavil_codec_enable_interp_clk(codec, event, w->shift);
  3897. snd_soc_update_bits(codec, sidetone_reg, 0x10, 0x10);
  3898. break;
  3899. case SND_SOC_DAPM_POST_PMD:
  3900. snd_soc_update_bits(codec, sidetone_reg, 0x10, 0x00);
  3901. tavil_codec_enable_interp_clk(codec, event, w->shift);
  3902. if (!strcmp(w->name, "RX INT7 MIX2 INP"))
  3903. __tavil_codec_enable_swr(w, event);
  3904. break;
  3905. default:
  3906. break;
  3907. };
  3908. return 0;
  3909. }
  3910. static int tavil_codec_enable_dec(struct snd_soc_dapm_widget *w,
  3911. struct snd_kcontrol *kcontrol, int event)
  3912. {
  3913. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  3914. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  3915. unsigned int decimator;
  3916. char *dec_adc_mux_name = NULL;
  3917. char *widget_name = NULL;
  3918. char *wname;
  3919. int ret = 0, amic_n;
  3920. u16 tx_vol_ctl_reg, pwr_level_reg = 0, dec_cfg_reg, hpf_gate_reg;
  3921. u16 tx_gain_ctl_reg;
  3922. char *dec;
  3923. u8 hpf_cut_off_freq;
  3924. dev_dbg(codec->dev, "%s %d\n", __func__, event);
  3925. widget_name = kstrndup(w->name, 15, GFP_KERNEL);
  3926. if (!widget_name)
  3927. return -ENOMEM;
  3928. wname = widget_name;
  3929. dec_adc_mux_name = strsep(&widget_name, " ");
  3930. if (!dec_adc_mux_name) {
  3931. dev_err(codec->dev, "%s: Invalid decimator = %s\n",
  3932. __func__, w->name);
  3933. ret = -EINVAL;
  3934. goto out;
  3935. }
  3936. dec_adc_mux_name = widget_name;
  3937. dec = strpbrk(dec_adc_mux_name, "012345678");
  3938. if (!dec) {
  3939. dev_err(codec->dev, "%s: decimator index not found\n",
  3940. __func__);
  3941. ret = -EINVAL;
  3942. goto out;
  3943. }
  3944. ret = kstrtouint(dec, 10, &decimator);
  3945. if (ret < 0) {
  3946. dev_err(codec->dev, "%s: Invalid decimator = %s\n",
  3947. __func__, wname);
  3948. ret = -EINVAL;
  3949. goto out;
  3950. }
  3951. dev_dbg(codec->dev, "%s(): widget = %s decimator = %u\n", __func__,
  3952. w->name, decimator);
  3953. tx_vol_ctl_reg = WCD934X_CDC_TX0_TX_PATH_CTL + 16 * decimator;
  3954. hpf_gate_reg = WCD934X_CDC_TX0_TX_PATH_SEC2 + 16 * decimator;
  3955. dec_cfg_reg = WCD934X_CDC_TX0_TX_PATH_CFG0 + 16 * decimator;
  3956. tx_gain_ctl_reg = WCD934X_CDC_TX0_TX_VOL_CTL + 16 * decimator;
  3957. switch (event) {
  3958. case SND_SOC_DAPM_PRE_PMU:
  3959. amic_n = tavil_codec_find_amic_input(codec, decimator);
  3960. if (amic_n)
  3961. pwr_level_reg = tavil_codec_get_amic_pwlvl_reg(codec,
  3962. amic_n);
  3963. if (pwr_level_reg) {
  3964. switch ((snd_soc_read(codec, pwr_level_reg) &
  3965. WCD934X_AMIC_PWR_LVL_MASK) >>
  3966. WCD934X_AMIC_PWR_LVL_SHIFT) {
  3967. case WCD934X_AMIC_PWR_LEVEL_LP:
  3968. snd_soc_update_bits(codec, dec_cfg_reg,
  3969. WCD934X_DEC_PWR_LVL_MASK,
  3970. WCD934X_DEC_PWR_LVL_LP);
  3971. break;
  3972. case WCD934X_AMIC_PWR_LEVEL_HP:
  3973. snd_soc_update_bits(codec, dec_cfg_reg,
  3974. WCD934X_DEC_PWR_LVL_MASK,
  3975. WCD934X_DEC_PWR_LVL_HP);
  3976. break;
  3977. case WCD934X_AMIC_PWR_LEVEL_DEFAULT:
  3978. case WCD934X_AMIC_PWR_LEVEL_HYBRID:
  3979. default:
  3980. snd_soc_update_bits(codec, dec_cfg_reg,
  3981. WCD934X_DEC_PWR_LVL_MASK,
  3982. WCD934X_DEC_PWR_LVL_DF);
  3983. break;
  3984. }
  3985. }
  3986. /* Enable TX PGA Mute */
  3987. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x10, 0x10);
  3988. break;
  3989. case SND_SOC_DAPM_POST_PMU:
  3990. hpf_cut_off_freq = (snd_soc_read(codec, dec_cfg_reg) &
  3991. TX_HPF_CUT_OFF_FREQ_MASK) >> 5;
  3992. tavil->tx_hpf_work[decimator].hpf_cut_off_freq =
  3993. hpf_cut_off_freq;
  3994. if (hpf_cut_off_freq != CF_MIN_3DB_150HZ) {
  3995. snd_soc_update_bits(codec, dec_cfg_reg,
  3996. TX_HPF_CUT_OFF_FREQ_MASK,
  3997. CF_MIN_3DB_150HZ << 5);
  3998. snd_soc_update_bits(codec, hpf_gate_reg, 0x02, 0x02);
  3999. /*
  4000. * Minimum 1 clk cycle delay is required as per
  4001. * HW spec.
  4002. */
  4003. usleep_range(1000, 1010);
  4004. snd_soc_update_bits(codec, hpf_gate_reg, 0x02, 0x00);
  4005. }
  4006. /* schedule work queue to Remove Mute */
  4007. schedule_delayed_work(&tavil->tx_mute_dwork[decimator].dwork,
  4008. msecs_to_jiffies(tx_unmute_delay));
  4009. if (tavil->tx_hpf_work[decimator].hpf_cut_off_freq !=
  4010. CF_MIN_3DB_150HZ)
  4011. schedule_delayed_work(
  4012. &tavil->tx_hpf_work[decimator].dwork,
  4013. msecs_to_jiffies(300));
  4014. /* apply gain after decimator is enabled */
  4015. snd_soc_write(codec, tx_gain_ctl_reg,
  4016. snd_soc_read(codec, tx_gain_ctl_reg));
  4017. break;
  4018. case SND_SOC_DAPM_PRE_PMD:
  4019. hpf_cut_off_freq =
  4020. tavil->tx_hpf_work[decimator].hpf_cut_off_freq;
  4021. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x10, 0x10);
  4022. if (cancel_delayed_work_sync(
  4023. &tavil->tx_hpf_work[decimator].dwork)) {
  4024. if (hpf_cut_off_freq != CF_MIN_3DB_150HZ) {
  4025. snd_soc_update_bits(codec, dec_cfg_reg,
  4026. TX_HPF_CUT_OFF_FREQ_MASK,
  4027. hpf_cut_off_freq << 5);
  4028. snd_soc_update_bits(codec, hpf_gate_reg,
  4029. 0x02, 0x02);
  4030. /*
  4031. * Minimum 1 clk cycle delay is required as per
  4032. * HW spec.
  4033. */
  4034. usleep_range(1000, 1010);
  4035. snd_soc_update_bits(codec, hpf_gate_reg,
  4036. 0x02, 0x00);
  4037. }
  4038. }
  4039. cancel_delayed_work_sync(
  4040. &tavil->tx_mute_dwork[decimator].dwork);
  4041. break;
  4042. case SND_SOC_DAPM_POST_PMD:
  4043. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x10, 0x00);
  4044. snd_soc_update_bits(codec, dec_cfg_reg,
  4045. WCD934X_DEC_PWR_LVL_MASK,
  4046. WCD934X_DEC_PWR_LVL_DF);
  4047. break;
  4048. };
  4049. out:
  4050. kfree(wname);
  4051. return ret;
  4052. }
  4053. static u32 tavil_get_dmic_sample_rate(struct snd_soc_codec *codec,
  4054. unsigned int dmic,
  4055. struct wcd9xxx_pdata *pdata)
  4056. {
  4057. u8 tx_stream_fs;
  4058. u8 adc_mux_index = 0, adc_mux_sel = 0;
  4059. bool dec_found = false;
  4060. u16 adc_mux_ctl_reg, tx_fs_reg;
  4061. u32 dmic_fs;
  4062. while (dec_found == 0 && adc_mux_index < WCD934X_MAX_VALID_ADC_MUX) {
  4063. if (adc_mux_index < 4) {
  4064. adc_mux_ctl_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG0 +
  4065. (adc_mux_index * 2);
  4066. } else if (adc_mux_index < WCD934X_INVALID_ADC_MUX) {
  4067. adc_mux_ctl_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX4_CFG0 +
  4068. adc_mux_index - 4;
  4069. } else if (adc_mux_index == WCD934X_INVALID_ADC_MUX) {
  4070. ++adc_mux_index;
  4071. continue;
  4072. }
  4073. adc_mux_sel = ((snd_soc_read(codec, adc_mux_ctl_reg) &
  4074. 0xF8) >> 3) - 1;
  4075. if (adc_mux_sel == dmic) {
  4076. dec_found = true;
  4077. break;
  4078. }
  4079. ++adc_mux_index;
  4080. }
  4081. if (dec_found && adc_mux_index <= 8) {
  4082. tx_fs_reg = WCD934X_CDC_TX0_TX_PATH_CTL + (16 * adc_mux_index);
  4083. tx_stream_fs = snd_soc_read(codec, tx_fs_reg) & 0x0F;
  4084. if (tx_stream_fs <= 4) {
  4085. if (pdata->dmic_sample_rate <=
  4086. WCD9XXX_DMIC_SAMPLE_RATE_2P4MHZ)
  4087. dmic_fs = pdata->dmic_sample_rate;
  4088. else
  4089. dmic_fs = WCD9XXX_DMIC_SAMPLE_RATE_2P4MHZ;
  4090. } else
  4091. dmic_fs = WCD9XXX_DMIC_SAMPLE_RATE_4P8MHZ;
  4092. } else {
  4093. dmic_fs = pdata->dmic_sample_rate;
  4094. }
  4095. return dmic_fs;
  4096. }
  4097. static u8 tavil_get_dmic_clk_val(struct snd_soc_codec *codec,
  4098. u32 mclk_rate, u32 dmic_clk_rate)
  4099. {
  4100. u32 div_factor;
  4101. u8 dmic_ctl_val;
  4102. dev_dbg(codec->dev,
  4103. "%s: mclk_rate = %d, dmic_sample_rate = %d\n",
  4104. __func__, mclk_rate, dmic_clk_rate);
  4105. /* Default value to return in case of error */
  4106. if (mclk_rate == WCD934X_MCLK_CLK_9P6MHZ)
  4107. dmic_ctl_val = WCD934X_DMIC_CLK_DIV_2;
  4108. else
  4109. dmic_ctl_val = WCD934X_DMIC_CLK_DIV_3;
  4110. if (dmic_clk_rate == 0) {
  4111. dev_err(codec->dev,
  4112. "%s: dmic_sample_rate cannot be 0\n",
  4113. __func__);
  4114. goto done;
  4115. }
  4116. div_factor = mclk_rate / dmic_clk_rate;
  4117. switch (div_factor) {
  4118. case 2:
  4119. dmic_ctl_val = WCD934X_DMIC_CLK_DIV_2;
  4120. break;
  4121. case 3:
  4122. dmic_ctl_val = WCD934X_DMIC_CLK_DIV_3;
  4123. break;
  4124. case 4:
  4125. dmic_ctl_val = WCD934X_DMIC_CLK_DIV_4;
  4126. break;
  4127. case 6:
  4128. dmic_ctl_val = WCD934X_DMIC_CLK_DIV_6;
  4129. break;
  4130. case 8:
  4131. dmic_ctl_val = WCD934X_DMIC_CLK_DIV_8;
  4132. break;
  4133. case 16:
  4134. dmic_ctl_val = WCD934X_DMIC_CLK_DIV_16;
  4135. break;
  4136. default:
  4137. dev_err(codec->dev,
  4138. "%s: Invalid div_factor %u, clk_rate(%u), dmic_rate(%u)\n",
  4139. __func__, div_factor, mclk_rate, dmic_clk_rate);
  4140. break;
  4141. }
  4142. done:
  4143. return dmic_ctl_val;
  4144. }
  4145. static int tavil_codec_enable_adc(struct snd_soc_dapm_widget *w,
  4146. struct snd_kcontrol *kcontrol, int event)
  4147. {
  4148. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  4149. dev_dbg(codec->dev, "%s: event:%d\n", __func__, event);
  4150. switch (event) {
  4151. case SND_SOC_DAPM_PRE_PMU:
  4152. tavil_codec_set_tx_hold(codec, w->reg, true);
  4153. break;
  4154. default:
  4155. break;
  4156. }
  4157. return 0;
  4158. }
  4159. static int tavil_codec_enable_dmic(struct snd_soc_dapm_widget *w,
  4160. struct snd_kcontrol *kcontrol, int event)
  4161. {
  4162. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  4163. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  4164. struct wcd9xxx_pdata *pdata = dev_get_platdata(codec->dev->parent);
  4165. u8 dmic_clk_en = 0x01;
  4166. u16 dmic_clk_reg;
  4167. s32 *dmic_clk_cnt;
  4168. u8 dmic_rate_val, dmic_rate_shift = 1;
  4169. unsigned int dmic;
  4170. u32 dmic_sample_rate;
  4171. int ret;
  4172. char *wname;
  4173. wname = strpbrk(w->name, "012345");
  4174. if (!wname) {
  4175. dev_err(codec->dev, "%s: widget not found\n", __func__);
  4176. return -EINVAL;
  4177. }
  4178. ret = kstrtouint(wname, 10, &dmic);
  4179. if (ret < 0) {
  4180. dev_err(codec->dev, "%s: Invalid DMIC line on the codec\n",
  4181. __func__);
  4182. return -EINVAL;
  4183. }
  4184. switch (dmic) {
  4185. case 0:
  4186. case 1:
  4187. dmic_clk_cnt = &(tavil->dmic_0_1_clk_cnt);
  4188. dmic_clk_reg = WCD934X_CPE_SS_DMIC0_CTL;
  4189. break;
  4190. case 2:
  4191. case 3:
  4192. dmic_clk_cnt = &(tavil->dmic_2_3_clk_cnt);
  4193. dmic_clk_reg = WCD934X_CPE_SS_DMIC1_CTL;
  4194. break;
  4195. case 4:
  4196. case 5:
  4197. dmic_clk_cnt = &(tavil->dmic_4_5_clk_cnt);
  4198. dmic_clk_reg = WCD934X_CPE_SS_DMIC2_CTL;
  4199. break;
  4200. default:
  4201. dev_err(codec->dev, "%s: Invalid DMIC Selection\n",
  4202. __func__);
  4203. return -EINVAL;
  4204. };
  4205. dev_dbg(codec->dev, "%s: event %d DMIC%d dmic_clk_cnt %d\n",
  4206. __func__, event, dmic, *dmic_clk_cnt);
  4207. switch (event) {
  4208. case SND_SOC_DAPM_PRE_PMU:
  4209. dmic_sample_rate = tavil_get_dmic_sample_rate(codec, dmic,
  4210. pdata);
  4211. dmic_rate_val =
  4212. tavil_get_dmic_clk_val(codec,
  4213. pdata->mclk_rate,
  4214. dmic_sample_rate);
  4215. (*dmic_clk_cnt)++;
  4216. if (*dmic_clk_cnt == 1) {
  4217. snd_soc_update_bits(codec, dmic_clk_reg,
  4218. 0x07 << dmic_rate_shift,
  4219. dmic_rate_val << dmic_rate_shift);
  4220. snd_soc_update_bits(codec, dmic_clk_reg,
  4221. dmic_clk_en, dmic_clk_en);
  4222. }
  4223. break;
  4224. case SND_SOC_DAPM_POST_PMD:
  4225. dmic_rate_val =
  4226. tavil_get_dmic_clk_val(codec,
  4227. pdata->mclk_rate,
  4228. pdata->mad_dmic_sample_rate);
  4229. (*dmic_clk_cnt)--;
  4230. if (*dmic_clk_cnt == 0) {
  4231. snd_soc_update_bits(codec, dmic_clk_reg,
  4232. dmic_clk_en, 0);
  4233. snd_soc_update_bits(codec, dmic_clk_reg,
  4234. 0x07 << dmic_rate_shift,
  4235. dmic_rate_val << dmic_rate_shift);
  4236. }
  4237. break;
  4238. };
  4239. return 0;
  4240. }
  4241. /*
  4242. * tavil_mbhc_micb_adjust_voltage: adjust specific micbias voltage
  4243. * @codec: handle to snd_soc_codec *
  4244. * @req_volt: micbias voltage to be set
  4245. * @micb_num: micbias to be set, e.g. micbias1 or micbias2
  4246. *
  4247. * return 0 if adjustment is success or error code in case of failure
  4248. */
  4249. int tavil_mbhc_micb_adjust_voltage(struct snd_soc_codec *codec,
  4250. int req_volt, int micb_num)
  4251. {
  4252. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  4253. int cur_vout_ctl, req_vout_ctl;
  4254. int micb_reg, micb_val, micb_en;
  4255. int ret = 0;
  4256. switch (micb_num) {
  4257. case MIC_BIAS_1:
  4258. micb_reg = WCD934X_ANA_MICB1;
  4259. break;
  4260. case MIC_BIAS_2:
  4261. micb_reg = WCD934X_ANA_MICB2;
  4262. break;
  4263. case MIC_BIAS_3:
  4264. micb_reg = WCD934X_ANA_MICB3;
  4265. break;
  4266. case MIC_BIAS_4:
  4267. micb_reg = WCD934X_ANA_MICB4;
  4268. break;
  4269. default:
  4270. return -EINVAL;
  4271. }
  4272. mutex_lock(&tavil->micb_lock);
  4273. /*
  4274. * If requested micbias voltage is same as current micbias
  4275. * voltage, then just return. Otherwise, adjust voltage as
  4276. * per requested value. If micbias is already enabled, then
  4277. * to avoid slow micbias ramp-up or down enable pull-up
  4278. * momentarily, change the micbias value and then re-enable
  4279. * micbias.
  4280. */
  4281. micb_val = snd_soc_read(codec, micb_reg);
  4282. micb_en = (micb_val & 0xC0) >> 6;
  4283. cur_vout_ctl = micb_val & 0x3F;
  4284. req_vout_ctl = wcd934x_get_micb_vout_ctl_val(req_volt);
  4285. if (req_vout_ctl < 0) {
  4286. ret = -EINVAL;
  4287. goto exit;
  4288. }
  4289. if (cur_vout_ctl == req_vout_ctl) {
  4290. ret = 0;
  4291. goto exit;
  4292. }
  4293. dev_dbg(codec->dev, "%s: micb_num: %d, cur_mv: %d, req_mv: %d, micb_en: %d\n",
  4294. __func__, micb_num, WCD_VOUT_CTL_TO_MICB(cur_vout_ctl),
  4295. req_volt, micb_en);
  4296. if (micb_en == 0x1)
  4297. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x80);
  4298. snd_soc_update_bits(codec, micb_reg, 0x3F, req_vout_ctl);
  4299. if (micb_en == 0x1) {
  4300. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x40);
  4301. /*
  4302. * Add 2ms delay as per HW requirement after enabling
  4303. * micbias
  4304. */
  4305. usleep_range(2000, 2100);
  4306. }
  4307. exit:
  4308. mutex_unlock(&tavil->micb_lock);
  4309. return ret;
  4310. }
  4311. EXPORT_SYMBOL(tavil_mbhc_micb_adjust_voltage);
  4312. /*
  4313. * tavil_micbias_control: enable/disable micbias
  4314. * @codec: handle to snd_soc_codec *
  4315. * @micb_num: micbias to be enabled/disabled, e.g. micbias1 or micbias2
  4316. * @req: control requested, enable/disable or pullup enable/disable
  4317. * @is_dapm: triggered by dapm or not
  4318. *
  4319. * return 0 if control is success or error code in case of failure
  4320. */
  4321. int tavil_micbias_control(struct snd_soc_codec *codec,
  4322. int micb_num, int req, bool is_dapm)
  4323. {
  4324. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  4325. int micb_index = micb_num - 1;
  4326. u16 micb_reg;
  4327. int pre_off_event = 0, post_off_event = 0;
  4328. int post_on_event = 0, post_dapm_off = 0;
  4329. int post_dapm_on = 0;
  4330. if ((micb_index < 0) || (micb_index > TAVIL_MAX_MICBIAS - 1)) {
  4331. dev_err(codec->dev, "%s: Invalid micbias index, micb_ind:%d\n",
  4332. __func__, micb_index);
  4333. return -EINVAL;
  4334. }
  4335. switch (micb_num) {
  4336. case MIC_BIAS_1:
  4337. micb_reg = WCD934X_ANA_MICB1;
  4338. break;
  4339. case MIC_BIAS_2:
  4340. micb_reg = WCD934X_ANA_MICB2;
  4341. pre_off_event = WCD_EVENT_PRE_MICBIAS_2_OFF;
  4342. post_off_event = WCD_EVENT_POST_MICBIAS_2_OFF;
  4343. post_on_event = WCD_EVENT_POST_MICBIAS_2_ON;
  4344. post_dapm_on = WCD_EVENT_POST_DAPM_MICBIAS_2_ON;
  4345. post_dapm_off = WCD_EVENT_POST_DAPM_MICBIAS_2_OFF;
  4346. break;
  4347. case MIC_BIAS_3:
  4348. micb_reg = WCD934X_ANA_MICB3;
  4349. break;
  4350. case MIC_BIAS_4:
  4351. micb_reg = WCD934X_ANA_MICB4;
  4352. break;
  4353. default:
  4354. dev_err(codec->dev, "%s: Invalid micbias number: %d\n",
  4355. __func__, micb_num);
  4356. return -EINVAL;
  4357. }
  4358. mutex_lock(&tavil->micb_lock);
  4359. switch (req) {
  4360. case MICB_PULLUP_ENABLE:
  4361. tavil->pullup_ref[micb_index]++;
  4362. if ((tavil->pullup_ref[micb_index] == 1) &&
  4363. (tavil->micb_ref[micb_index] == 0))
  4364. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x80);
  4365. break;
  4366. case MICB_PULLUP_DISABLE:
  4367. if (tavil->pullup_ref[micb_index] > 0)
  4368. tavil->pullup_ref[micb_index]--;
  4369. if ((tavil->pullup_ref[micb_index] == 0) &&
  4370. (tavil->micb_ref[micb_index] == 0))
  4371. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x00);
  4372. break;
  4373. case MICB_ENABLE:
  4374. tavil->micb_ref[micb_index]++;
  4375. if (tavil->micb_ref[micb_index] == 1) {
  4376. if (tavil->micb_load)
  4377. regulator_set_load(tavil->micb_load,
  4378. tavil->micb_load_high);
  4379. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x40);
  4380. if (post_on_event && tavil->mbhc)
  4381. blocking_notifier_call_chain(
  4382. &tavil->mbhc->notifier,
  4383. post_on_event,
  4384. &tavil->mbhc->wcd_mbhc);
  4385. }
  4386. if (is_dapm && post_dapm_on && tavil->mbhc)
  4387. blocking_notifier_call_chain(&tavil->mbhc->notifier,
  4388. post_dapm_on, &tavil->mbhc->wcd_mbhc);
  4389. break;
  4390. case MICB_DISABLE:
  4391. if (tavil->micb_ref[micb_index] > 0)
  4392. tavil->micb_ref[micb_index]--;
  4393. if ((tavil->micb_ref[micb_index] == 0) &&
  4394. (tavil->pullup_ref[micb_index] > 0))
  4395. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x80);
  4396. else if ((tavil->micb_ref[micb_index] == 0) &&
  4397. (tavil->pullup_ref[micb_index] == 0)) {
  4398. if (pre_off_event && tavil->mbhc)
  4399. blocking_notifier_call_chain(
  4400. &tavil->mbhc->notifier,
  4401. pre_off_event,
  4402. &tavil->mbhc->wcd_mbhc);
  4403. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x00);
  4404. if (post_off_event && tavil->mbhc)
  4405. blocking_notifier_call_chain(
  4406. &tavil->mbhc->notifier,
  4407. post_off_event,
  4408. &tavil->mbhc->wcd_mbhc);
  4409. if (tavil->micb_load)
  4410. regulator_set_load(tavil->micb_load,
  4411. tavil->micb_load_low);
  4412. }
  4413. if (is_dapm && post_dapm_off && tavil->mbhc)
  4414. blocking_notifier_call_chain(&tavil->mbhc->notifier,
  4415. post_dapm_off, &tavil->mbhc->wcd_mbhc);
  4416. break;
  4417. };
  4418. dev_dbg(codec->dev, "%s: micb_num:%d, micb_ref: %d, pullup_ref: %d\n",
  4419. __func__, micb_num, tavil->micb_ref[micb_index],
  4420. tavil->pullup_ref[micb_index]);
  4421. mutex_unlock(&tavil->micb_lock);
  4422. return 0;
  4423. }
  4424. EXPORT_SYMBOL(tavil_micbias_control);
  4425. static int __tavil_codec_enable_micbias(struct snd_soc_dapm_widget *w,
  4426. int event)
  4427. {
  4428. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  4429. int micb_num;
  4430. dev_dbg(codec->dev, "%s: wname: %s, event: %d\n",
  4431. __func__, w->name, event);
  4432. if (strnstr(w->name, "MIC BIAS1", sizeof("MIC BIAS1")))
  4433. micb_num = MIC_BIAS_1;
  4434. else if (strnstr(w->name, "MIC BIAS2", sizeof("MIC BIAS2")))
  4435. micb_num = MIC_BIAS_2;
  4436. else if (strnstr(w->name, "MIC BIAS3", sizeof("MIC BIAS3")))
  4437. micb_num = MIC_BIAS_3;
  4438. else if (strnstr(w->name, "MIC BIAS4", sizeof("MIC BIAS4")))
  4439. micb_num = MIC_BIAS_4;
  4440. else
  4441. return -EINVAL;
  4442. switch (event) {
  4443. case SND_SOC_DAPM_PRE_PMU:
  4444. /*
  4445. * MIC BIAS can also be requested by MBHC,
  4446. * so use ref count to handle micbias pullup
  4447. * and enable requests
  4448. */
  4449. tavil_micbias_control(codec, micb_num, MICB_ENABLE, true);
  4450. break;
  4451. case SND_SOC_DAPM_POST_PMU:
  4452. /* wait for cnp time */
  4453. usleep_range(1000, 1100);
  4454. break;
  4455. case SND_SOC_DAPM_POST_PMD:
  4456. tavil_micbias_control(codec, micb_num, MICB_DISABLE, true);
  4457. break;
  4458. };
  4459. return 0;
  4460. }
  4461. /*
  4462. * tavil_codec_enable_standalone_micbias - enable micbias standalone
  4463. * @codec: pointer to codec instance
  4464. * @micb_num: number of micbias to be enabled
  4465. * @enable: true to enable micbias or false to disable
  4466. *
  4467. * This function is used to enable micbias (1, 2, 3 or 4) during
  4468. * standalone independent of whether TX use-case is running or not
  4469. *
  4470. * Return: error code in case of failure or 0 for success
  4471. */
  4472. int tavil_codec_enable_standalone_micbias(struct snd_soc_codec *codec,
  4473. int micb_num,
  4474. bool enable)
  4475. {
  4476. const char * const micb_names[] = {
  4477. DAPM_MICBIAS1_STANDALONE, DAPM_MICBIAS2_STANDALONE,
  4478. DAPM_MICBIAS3_STANDALONE, DAPM_MICBIAS4_STANDALONE
  4479. };
  4480. int micb_index = micb_num - 1;
  4481. int rc;
  4482. if (!codec) {
  4483. pr_err("%s: Codec memory is NULL\n", __func__);
  4484. return -EINVAL;
  4485. }
  4486. if ((micb_index < 0) || (micb_index > TAVIL_MAX_MICBIAS - 1)) {
  4487. dev_err(codec->dev, "%s: Invalid micbias index, micb_ind:%d\n",
  4488. __func__, micb_index);
  4489. return -EINVAL;
  4490. }
  4491. if (enable)
  4492. rc = snd_soc_dapm_force_enable_pin(
  4493. snd_soc_codec_get_dapm(codec),
  4494. micb_names[micb_index]);
  4495. else
  4496. rc = snd_soc_dapm_disable_pin(snd_soc_codec_get_dapm(codec),
  4497. micb_names[micb_index]);
  4498. if (!rc)
  4499. snd_soc_dapm_sync(snd_soc_codec_get_dapm(codec));
  4500. else
  4501. dev_err(codec->dev, "%s: micbias%d force %s pin failed\n",
  4502. __func__, micb_num, (enable ? "enable" : "disable"));
  4503. return rc;
  4504. }
  4505. EXPORT_SYMBOL(tavil_codec_enable_standalone_micbias);
  4506. static int tavil_codec_force_enable_micbias(struct snd_soc_dapm_widget *w,
  4507. struct snd_kcontrol *kcontrol,
  4508. int event)
  4509. {
  4510. int ret = 0;
  4511. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  4512. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  4513. switch (event) {
  4514. case SND_SOC_DAPM_PRE_PMU:
  4515. wcd_resmgr_enable_master_bias(tavil->resmgr);
  4516. tavil_cdc_mclk_enable(codec, true);
  4517. ret = __tavil_codec_enable_micbias(w, SND_SOC_DAPM_PRE_PMU);
  4518. /* Wait for 1ms for better cnp */
  4519. usleep_range(1000, 1100);
  4520. tavil_cdc_mclk_enable(codec, false);
  4521. break;
  4522. case SND_SOC_DAPM_POST_PMD:
  4523. ret = __tavil_codec_enable_micbias(w, SND_SOC_DAPM_POST_PMD);
  4524. wcd_resmgr_disable_master_bias(tavil->resmgr);
  4525. break;
  4526. }
  4527. return ret;
  4528. }
  4529. static int tavil_codec_enable_micbias(struct snd_soc_dapm_widget *w,
  4530. struct snd_kcontrol *kcontrol, int event)
  4531. {
  4532. return __tavil_codec_enable_micbias(w, event);
  4533. }
  4534. static const struct reg_sequence tavil_hph_reset_tbl[] = {
  4535. { WCD934X_HPH_CNP_EN, 0x80 },
  4536. { WCD934X_HPH_CNP_WG_CTL, 0x9A },
  4537. { WCD934X_HPH_CNP_WG_TIME, 0x14 },
  4538. { WCD934X_HPH_OCP_CTL, 0x28 },
  4539. { WCD934X_HPH_AUTO_CHOP, 0x16 },
  4540. { WCD934X_HPH_CHOP_CTL, 0x83 },
  4541. { WCD934X_HPH_PA_CTL1, 0x46 },
  4542. { WCD934X_HPH_PA_CTL2, 0x50 },
  4543. { WCD934X_HPH_L_EN, 0x80 },
  4544. { WCD934X_HPH_L_TEST, 0xE0 },
  4545. { WCD934X_HPH_L_ATEST, 0x50 },
  4546. { WCD934X_HPH_R_EN, 0x80 },
  4547. { WCD934X_HPH_R_TEST, 0xE0 },
  4548. { WCD934X_HPH_R_ATEST, 0x54 },
  4549. { WCD934X_HPH_RDAC_CLK_CTL1, 0x99 },
  4550. { WCD934X_HPH_RDAC_CLK_CTL2, 0x9B },
  4551. { WCD934X_HPH_RDAC_LDO_CTL, 0x33 },
  4552. { WCD934X_HPH_RDAC_CHOP_CLK_LP_CTL, 0x00 },
  4553. { WCD934X_HPH_REFBUFF_UHQA_CTL, 0xA8 },
  4554. };
  4555. static const struct reg_sequence tavil_hph_reset_tbl_1_0[] = {
  4556. { WCD934X_HPH_REFBUFF_LP_CTL, 0x0A },
  4557. { WCD934X_HPH_L_DAC_CTL, 0x00 },
  4558. { WCD934X_HPH_R_DAC_CTL, 0x00 },
  4559. { WCD934X_HPH_NEW_ANA_HPH2, 0x00 },
  4560. { WCD934X_HPH_NEW_ANA_HPH3, 0x00 },
  4561. { WCD934X_HPH_NEW_INT_RDAC_GAIN_CTL, 0x00 },
  4562. { WCD934X_HPH_NEW_INT_RDAC_HD2_CTL, 0xA0 },
  4563. { WCD934X_HPH_NEW_INT_RDAC_VREF_CTL, 0x10 },
  4564. { WCD934X_HPH_NEW_INT_RDAC_OVERRIDE_CTL, 0x00 },
  4565. { WCD934X_HPH_NEW_INT_RDAC_MISC1, 0x00 },
  4566. { WCD934X_HPH_NEW_INT_PA_MISC1, 0x22 },
  4567. { WCD934X_HPH_NEW_INT_PA_MISC2, 0x00 },
  4568. { WCD934X_HPH_NEW_INT_PA_RDAC_MISC, 0x00 },
  4569. { WCD934X_HPH_NEW_INT_HPH_TIMER1, 0xFE },
  4570. { WCD934X_HPH_NEW_INT_HPH_TIMER2, 0x2 },
  4571. { WCD934X_HPH_NEW_INT_HPH_TIMER3, 0x4e},
  4572. { WCD934X_HPH_NEW_INT_HPH_TIMER4, 0x54 },
  4573. { WCD934X_HPH_NEW_INT_PA_RDAC_MISC2, 0x00 },
  4574. { WCD934X_HPH_NEW_INT_PA_RDAC_MISC3, 0x00 },
  4575. };
  4576. static const struct reg_sequence tavil_hph_reset_tbl_1_1[] = {
  4577. { WCD934X_HPH_REFBUFF_LP_CTL, 0x0E },
  4578. { WCD934X_HPH_L_DAC_CTL, 0x00 },
  4579. { WCD934X_HPH_R_DAC_CTL, 0x00 },
  4580. { WCD934X_HPH_NEW_ANA_HPH2, 0x00 },
  4581. { WCD934X_HPH_NEW_ANA_HPH3, 0x00 },
  4582. { WCD934X_HPH_NEW_INT_RDAC_GAIN_CTL, 0x40 },
  4583. { WCD934X_HPH_NEW_INT_RDAC_HD2_CTL, 0x81 },
  4584. { WCD934X_HPH_NEW_INT_RDAC_VREF_CTL, 0x10 },
  4585. { WCD934X_HPH_NEW_INT_RDAC_OVERRIDE_CTL, 0x00 },
  4586. { WCD934X_HPH_NEW_INT_RDAC_MISC1, 0x81 },
  4587. { WCD934X_HPH_NEW_INT_PA_MISC1, 0x22 },
  4588. { WCD934X_HPH_NEW_INT_PA_MISC2, 0x00 },
  4589. { WCD934X_HPH_NEW_INT_PA_RDAC_MISC, 0x00 },
  4590. { WCD934X_HPH_NEW_INT_HPH_TIMER1, 0xFE },
  4591. { WCD934X_HPH_NEW_INT_HPH_TIMER2, 0x2 },
  4592. { WCD934X_HPH_NEW_INT_HPH_TIMER3, 0x4e},
  4593. { WCD934X_HPH_NEW_INT_HPH_TIMER4, 0x54 },
  4594. { WCD934X_HPH_NEW_INT_PA_RDAC_MISC2, 0x00 },
  4595. { WCD934X_HPH_NEW_INT_PA_RDAC_MISC3, 0x00 },
  4596. };
  4597. static const struct tavil_reg_mask_val tavil_pa_disable[] = {
  4598. { WCD934X_CDC_RX1_RX_PATH_CTL, 0x30, 0x10 }, /* RX1 mute enable */
  4599. { WCD934X_CDC_RX2_RX_PATH_CTL, 0x30, 0x10 }, /* RX2 mute enable */
  4600. { WCD934X_HPH_CNP_WG_CTL, 0x80, 0x00 }, /* GM3 boost disable */
  4601. { WCD934X_ANA_HPH, 0x80, 0x00 }, /* HPHL PA disable */
  4602. { WCD934X_ANA_HPH, 0x40, 0x00 }, /* HPHR PA disable */
  4603. { WCD934X_ANA_HPH, 0x20, 0x00 }, /* HPHL REF dsable */
  4604. { WCD934X_ANA_HPH, 0x10, 0x00 }, /* HPHR REF disable */
  4605. };
  4606. static const struct tavil_reg_mask_val tavil_ocp_en_seq[] = {
  4607. { WCD934X_RX_OCP_CTL, 0x0F, 0x02 }, /* OCP number of attempts is 2 */
  4608. { WCD934X_HPH_OCP_CTL, 0xFA, 0x3A }, /* OCP current limit */
  4609. { WCD934X_HPH_L_TEST, 0x01, 0x01 }, /* Enable HPHL OCP */
  4610. { WCD934X_HPH_R_TEST, 0x01, 0x01 }, /* Enable HPHR OCP */
  4611. };
  4612. static const struct tavil_reg_mask_val tavil_ocp_en_seq_1[] = {
  4613. { WCD934X_RX_OCP_CTL, 0x0F, 0x02 }, /* OCP number of attempts is 2 */
  4614. { WCD934X_HPH_OCP_CTL, 0xFA, 0x3A }, /* OCP current limit */
  4615. };
  4616. /* LO-HIFI */
  4617. static const struct tavil_reg_mask_val tavil_pre_pa_en_lohifi[] = {
  4618. { WCD934X_HPH_NEW_INT_HPH_TIMER1, 0x02, 0x00 },
  4619. { WCD934X_FLYBACK_VNEG_CTRL_4, 0xf0, 0x80 },
  4620. { WCD934X_HPH_NEW_INT_PA_MISC2, 0x20, 0x20 },
  4621. { WCD934X_HPH_NEW_INT_RDAC_GAIN_CTL, 0xf0, 0x40 },
  4622. { WCD934X_HPH_CNP_WG_CTL, 0x80, 0x00 },
  4623. { WCD934X_RX_BIAS_HPH_LOWPOWER, 0xf0, 0xc0 },
  4624. { WCD934X_HPH_PA_CTL1, 0x0e, 0x02 },
  4625. { WCD934X_HPH_REFBUFF_LP_CTL, 0x06, 0x06 },
  4626. };
  4627. static const struct tavil_reg_mask_val tavil_pre_pa_en[] = {
  4628. { WCD934X_HPH_NEW_INT_HPH_TIMER1, 0x02, 0x00 },
  4629. { WCD934X_HPH_NEW_INT_PA_MISC2, 0x20, 0x0 },
  4630. { WCD934X_HPH_NEW_INT_RDAC_GAIN_CTL, 0xf0, 0x40 },
  4631. { WCD934X_HPH_CNP_WG_CTL, 0x80, 0x00 },
  4632. { WCD934X_RX_BIAS_HPH_LOWPOWER, 0xf0, 0x80 },
  4633. { WCD934X_HPH_PA_CTL1, 0x0e, 0x06 },
  4634. { WCD934X_HPH_REFBUFF_LP_CTL, 0x06, 0x06 },
  4635. };
  4636. static const struct tavil_reg_mask_val tavil_post_pa_en[] = {
  4637. { WCD934X_HPH_L_TEST, 0x01, 0x01 }, /* Enable HPHL OCP */
  4638. { WCD934X_HPH_R_TEST, 0x01, 0x01 }, /* Enable HPHR OCP */
  4639. { WCD934X_CDC_RX1_RX_PATH_CTL, 0x30, 0x20 }, /* RX1 mute disable */
  4640. { WCD934X_CDC_RX2_RX_PATH_CTL, 0x30, 0x20 }, /* RX2 mute disable */
  4641. { WCD934X_HPH_CNP_WG_CTL, 0x80, 0x80 }, /* GM3 boost enable */
  4642. { WCD934X_HPH_NEW_INT_HPH_TIMER1, 0x02, 0x02 },
  4643. };
  4644. static void tavil_codec_hph_reg_range_read(struct regmap *map, u8 *buf)
  4645. {
  4646. regmap_bulk_read(map, WCD934X_HPH_CNP_EN, buf, TAVIL_HPH_REG_RANGE_1);
  4647. regmap_bulk_read(map, WCD934X_HPH_NEW_ANA_HPH2,
  4648. buf + TAVIL_HPH_REG_RANGE_1, TAVIL_HPH_REG_RANGE_2);
  4649. regmap_bulk_read(map, WCD934X_HPH_NEW_INT_RDAC_GAIN_CTL,
  4650. buf + TAVIL_HPH_REG_RANGE_1 + TAVIL_HPH_REG_RANGE_2,
  4651. TAVIL_HPH_REG_RANGE_3);
  4652. }
  4653. static void tavil_codec_hph_reg_recover(struct tavil_priv *tavil,
  4654. struct regmap *map, int pa_status)
  4655. {
  4656. int i;
  4657. unsigned int reg;
  4658. blocking_notifier_call_chain(&tavil->mbhc->notifier,
  4659. WCD_EVENT_OCP_OFF,
  4660. &tavil->mbhc->wcd_mbhc);
  4661. if (pa_status & 0xC0)
  4662. goto pa_en_restore;
  4663. dev_dbg(tavil->dev, "%s: HPH PA in disable state (0x%x)\n",
  4664. __func__, pa_status);
  4665. regmap_write_bits(map, WCD934X_CDC_RX1_RX_PATH_CTL, 0x10, 0x10);
  4666. regmap_write_bits(map, WCD934X_CDC_RX2_RX_PATH_CTL, 0x10, 0x10);
  4667. regmap_write_bits(map, WCD934X_ANA_HPH, 0xC0, 0x00);
  4668. regmap_write_bits(map, WCD934X_ANA_HPH, 0x30, 0x00);
  4669. regmap_write_bits(map, WCD934X_CDC_RX1_RX_PATH_CTL, 0x10, 0x00);
  4670. regmap_write_bits(map, WCD934X_CDC_RX2_RX_PATH_CTL, 0x10, 0x00);
  4671. /* Restore to HW defaults */
  4672. regmap_multi_reg_write(map, tavil_hph_reset_tbl,
  4673. ARRAY_SIZE(tavil_hph_reset_tbl));
  4674. if (TAVIL_IS_1_1(tavil->wcd9xxx))
  4675. regmap_multi_reg_write(map, tavil_hph_reset_tbl_1_1,
  4676. ARRAY_SIZE(tavil_hph_reset_tbl_1_1));
  4677. if (TAVIL_IS_1_0(tavil->wcd9xxx))
  4678. regmap_multi_reg_write(map, tavil_hph_reset_tbl_1_0,
  4679. ARRAY_SIZE(tavil_hph_reset_tbl_1_0));
  4680. for (i = 0; i < ARRAY_SIZE(tavil_ocp_en_seq); i++)
  4681. regmap_write_bits(map, tavil_ocp_en_seq[i].reg,
  4682. tavil_ocp_en_seq[i].mask,
  4683. tavil_ocp_en_seq[i].val);
  4684. goto end;
  4685. pa_en_restore:
  4686. dev_dbg(tavil->dev, "%s: HPH PA in enable state (0x%x)\n",
  4687. __func__, pa_status);
  4688. /* Disable PA and other registers before restoring */
  4689. for (i = 0; i < ARRAY_SIZE(tavil_pa_disable); i++) {
  4690. if (TAVIL_IS_1_1(tavil->wcd9xxx) &&
  4691. (tavil_pa_disable[i].reg == WCD934X_HPH_CNP_WG_CTL))
  4692. continue;
  4693. regmap_write_bits(map, tavil_pa_disable[i].reg,
  4694. tavil_pa_disable[i].mask,
  4695. tavil_pa_disable[i].val);
  4696. }
  4697. regmap_multi_reg_write(map, tavil_hph_reset_tbl,
  4698. ARRAY_SIZE(tavil_hph_reset_tbl));
  4699. if (TAVIL_IS_1_1(tavil->wcd9xxx))
  4700. regmap_multi_reg_write(map, tavil_hph_reset_tbl_1_1,
  4701. ARRAY_SIZE(tavil_hph_reset_tbl_1_1));
  4702. if (TAVIL_IS_1_0(tavil->wcd9xxx))
  4703. regmap_multi_reg_write(map, tavil_hph_reset_tbl_1_0,
  4704. ARRAY_SIZE(tavil_hph_reset_tbl_1_0));
  4705. for (i = 0; i < ARRAY_SIZE(tavil_ocp_en_seq_1); i++)
  4706. regmap_write_bits(map, tavil_ocp_en_seq_1[i].reg,
  4707. tavil_ocp_en_seq_1[i].mask,
  4708. tavil_ocp_en_seq_1[i].val);
  4709. if (tavil->hph_mode == CLS_H_LOHIFI) {
  4710. for (i = 0; i < ARRAY_SIZE(tavil_pre_pa_en_lohifi); i++) {
  4711. reg = tavil_pre_pa_en_lohifi[i].reg;
  4712. if ((TAVIL_IS_1_1(tavil->wcd9xxx)) &&
  4713. ((reg == WCD934X_HPH_NEW_INT_RDAC_GAIN_CTL) ||
  4714. (reg == WCD934X_HPH_CNP_WG_CTL) ||
  4715. (reg == WCD934X_HPH_REFBUFF_LP_CTL)))
  4716. continue;
  4717. regmap_write_bits(map,
  4718. tavil_pre_pa_en_lohifi[i].reg,
  4719. tavil_pre_pa_en_lohifi[i].mask,
  4720. tavil_pre_pa_en_lohifi[i].val);
  4721. }
  4722. } else {
  4723. for (i = 0; i < ARRAY_SIZE(tavil_pre_pa_en); i++) {
  4724. reg = tavil_pre_pa_en[i].reg;
  4725. if ((TAVIL_IS_1_1(tavil->wcd9xxx)) &&
  4726. ((reg == WCD934X_HPH_NEW_INT_RDAC_GAIN_CTL) ||
  4727. (reg == WCD934X_HPH_CNP_WG_CTL) ||
  4728. (reg == WCD934X_HPH_REFBUFF_LP_CTL)))
  4729. continue;
  4730. regmap_write_bits(map, tavil_pre_pa_en[i].reg,
  4731. tavil_pre_pa_en[i].mask,
  4732. tavil_pre_pa_en[i].val);
  4733. }
  4734. }
  4735. if (TAVIL_IS_1_1(tavil->wcd9xxx)) {
  4736. regmap_write(map, WCD934X_HPH_NEW_INT_RDAC_HD2_CTL_L, 0x84);
  4737. regmap_write(map, WCD934X_HPH_NEW_INT_RDAC_HD2_CTL_R, 0x84);
  4738. }
  4739. regmap_write_bits(map, WCD934X_ANA_HPH, 0x0C, pa_status & 0x0C);
  4740. regmap_write_bits(map, WCD934X_ANA_HPH, 0x30, 0x30);
  4741. /* wait for 100usec after HPH DAC is enabled */
  4742. usleep_range(100, 110);
  4743. regmap_write(map, WCD934X_ANA_HPH, pa_status);
  4744. /* Sleep for 7msec after PA is enabled */
  4745. usleep_range(7000, 7100);
  4746. for (i = 0; i < ARRAY_SIZE(tavil_post_pa_en); i++) {
  4747. if ((TAVIL_IS_1_1(tavil->wcd9xxx)) &&
  4748. (tavil_post_pa_en[i].reg == WCD934X_HPH_CNP_WG_CTL))
  4749. continue;
  4750. regmap_write_bits(map, tavil_post_pa_en[i].reg,
  4751. tavil_post_pa_en[i].mask,
  4752. tavil_post_pa_en[i].val);
  4753. }
  4754. end:
  4755. tavil->mbhc->is_hph_recover = true;
  4756. blocking_notifier_call_chain(
  4757. &tavil->mbhc->notifier,
  4758. WCD_EVENT_OCP_ON,
  4759. &tavil->mbhc->wcd_mbhc);
  4760. }
  4761. static int tavil_codec_reset_hph_registers(struct snd_soc_dapm_widget *w,
  4762. struct snd_kcontrol *kcontrol,
  4763. int event)
  4764. {
  4765. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  4766. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  4767. struct wcd9xxx *wcd9xxx = dev_get_drvdata(codec->dev->parent);
  4768. u8 cache_val[TAVIL_HPH_TOTAL_REG];
  4769. u8 hw_val[TAVIL_HPH_TOTAL_REG];
  4770. int pa_status;
  4771. int ret;
  4772. dev_dbg(wcd9xxx->dev, "%s: event: %d\n", __func__, event);
  4773. switch (event) {
  4774. case SND_SOC_DAPM_PRE_PMU:
  4775. memset(cache_val, 0, TAVIL_HPH_TOTAL_REG);
  4776. memset(hw_val, 0, TAVIL_HPH_TOTAL_REG);
  4777. regmap_read(wcd9xxx->regmap, WCD934X_ANA_HPH, &pa_status);
  4778. tavil_codec_hph_reg_range_read(wcd9xxx->regmap, cache_val);
  4779. /* Read register values from HW directly */
  4780. regcache_cache_bypass(wcd9xxx->regmap, true);
  4781. tavil_codec_hph_reg_range_read(wcd9xxx->regmap, hw_val);
  4782. regcache_cache_bypass(wcd9xxx->regmap, false);
  4783. /* compare both the registers to know if there is corruption */
  4784. ret = memcmp(cache_val, hw_val, TAVIL_HPH_TOTAL_REG);
  4785. /* If both the values are same, it means no corruption */
  4786. if (ret) {
  4787. dev_dbg(codec->dev, "%s: cache and hw reg are not same\n",
  4788. __func__);
  4789. tavil_codec_hph_reg_recover(tavil, wcd9xxx->regmap,
  4790. pa_status);
  4791. } else {
  4792. dev_dbg(codec->dev, "%s: cache and hw reg are same\n",
  4793. __func__);
  4794. tavil->mbhc->is_hph_recover = false;
  4795. }
  4796. break;
  4797. default:
  4798. break;
  4799. };
  4800. return 0;
  4801. }
  4802. static void tavil_restore_iir_coeff(struct tavil_priv *tavil, int iir_idx,
  4803. int band_idx)
  4804. {
  4805. u16 reg_add;
  4806. int no_of_reg = 0;
  4807. regmap_write(tavil->wcd9xxx->regmap,
  4808. (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B1_CTL + 16 * iir_idx),
  4809. (band_idx * BAND_MAX * sizeof(uint32_t)) & 0x7F);
  4810. reg_add = WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL + 16 * iir_idx;
  4811. if (tavil->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS)
  4812. return;
  4813. /*
  4814. * Since wcd9xxx_slim_write_repeat() supports only maximum of 16
  4815. * registers at a time, split total 20 writes(5 coefficients per
  4816. * band and 4 writes per coefficient) into 16 and 4.
  4817. */
  4818. no_of_reg = WCD934X_CDC_REPEAT_WRITES_MAX;
  4819. wcd9xxx_slim_write_repeat(tavil->wcd9xxx, reg_add, no_of_reg,
  4820. &tavil->sidetone_coeff_array[iir_idx][band_idx][0]);
  4821. no_of_reg = (WCD934X_CDC_SIDETONE_IIR_COEFF_MAX * 4) -
  4822. WCD934X_CDC_REPEAT_WRITES_MAX;
  4823. wcd9xxx_slim_write_repeat(tavil->wcd9xxx, reg_add, no_of_reg,
  4824. &tavil->sidetone_coeff_array[iir_idx][band_idx]
  4825. [WCD934X_CDC_REPEAT_WRITES_MAX]);
  4826. }
  4827. static int tavil_iir_enable_audio_mixer_get(struct snd_kcontrol *kcontrol,
  4828. struct snd_ctl_elem_value *ucontrol)
  4829. {
  4830. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  4831. int iir_idx = ((struct soc_multi_mixer_control *)
  4832. kcontrol->private_value)->reg;
  4833. int band_idx = ((struct soc_multi_mixer_control *)
  4834. kcontrol->private_value)->shift;
  4835. /* IIR filter band registers are at integer multiples of 16 */
  4836. u16 iir_reg = WCD934X_CDC_SIDETONE_IIR0_IIR_CTL + 16 * iir_idx;
  4837. ucontrol->value.integer.value[0] = (snd_soc_read(codec, iir_reg) &
  4838. (1 << band_idx)) != 0;
  4839. dev_dbg(codec->dev, "%s: IIR #%d band #%d enable %d\n", __func__,
  4840. iir_idx, band_idx,
  4841. (uint32_t)ucontrol->value.integer.value[0]);
  4842. return 0;
  4843. }
  4844. static int tavil_iir_enable_audio_mixer_put(struct snd_kcontrol *kcontrol,
  4845. struct snd_ctl_elem_value *ucontrol)
  4846. {
  4847. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  4848. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  4849. int iir_idx = ((struct soc_multi_mixer_control *)
  4850. kcontrol->private_value)->reg;
  4851. int band_idx = ((struct soc_multi_mixer_control *)
  4852. kcontrol->private_value)->shift;
  4853. bool iir_band_en_status;
  4854. int value = ucontrol->value.integer.value[0];
  4855. u16 iir_reg = WCD934X_CDC_SIDETONE_IIR0_IIR_CTL + 16 * iir_idx;
  4856. tavil_restore_iir_coeff(tavil, iir_idx, band_idx);
  4857. /* Mask first 5 bits, 6-8 are reserved */
  4858. snd_soc_update_bits(codec, iir_reg, (1 << band_idx),
  4859. (value << band_idx));
  4860. iir_band_en_status = ((snd_soc_read(codec, iir_reg) &
  4861. (1 << band_idx)) != 0);
  4862. dev_dbg(codec->dev, "%s: IIR #%d band #%d enable %d\n", __func__,
  4863. iir_idx, band_idx, iir_band_en_status);
  4864. return 0;
  4865. }
  4866. static uint32_t get_iir_band_coeff(struct snd_soc_codec *codec,
  4867. int iir_idx, int band_idx,
  4868. int coeff_idx)
  4869. {
  4870. uint32_t value = 0;
  4871. /* Address does not automatically update if reading */
  4872. snd_soc_write(codec,
  4873. (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B1_CTL + 16 * iir_idx),
  4874. ((band_idx * BAND_MAX + coeff_idx)
  4875. * sizeof(uint32_t)) & 0x7F);
  4876. value |= snd_soc_read(codec,
  4877. (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL + 16 * iir_idx));
  4878. snd_soc_write(codec,
  4879. (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B1_CTL + 16 * iir_idx),
  4880. ((band_idx * BAND_MAX + coeff_idx)
  4881. * sizeof(uint32_t) + 1) & 0x7F);
  4882. value |= (snd_soc_read(codec,
  4883. (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL +
  4884. 16 * iir_idx)) << 8);
  4885. snd_soc_write(codec,
  4886. (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B1_CTL + 16 * iir_idx),
  4887. ((band_idx * BAND_MAX + coeff_idx)
  4888. * sizeof(uint32_t) + 2) & 0x7F);
  4889. value |= (snd_soc_read(codec,
  4890. (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL +
  4891. 16 * iir_idx)) << 16);
  4892. snd_soc_write(codec,
  4893. (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B1_CTL + 16 * iir_idx),
  4894. ((band_idx * BAND_MAX + coeff_idx)
  4895. * sizeof(uint32_t) + 3) & 0x7F);
  4896. /* Mask bits top 2 bits since they are reserved */
  4897. value |= ((snd_soc_read(codec,
  4898. (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL +
  4899. 16 * iir_idx)) & 0x3F) << 24);
  4900. return value;
  4901. }
  4902. static int tavil_iir_band_audio_mixer_get(struct snd_kcontrol *kcontrol,
  4903. struct snd_ctl_elem_value *ucontrol)
  4904. {
  4905. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  4906. int iir_idx = ((struct soc_multi_mixer_control *)
  4907. kcontrol->private_value)->reg;
  4908. int band_idx = ((struct soc_multi_mixer_control *)
  4909. kcontrol->private_value)->shift;
  4910. ucontrol->value.integer.value[0] =
  4911. get_iir_band_coeff(codec, iir_idx, band_idx, 0);
  4912. ucontrol->value.integer.value[1] =
  4913. get_iir_band_coeff(codec, iir_idx, band_idx, 1);
  4914. ucontrol->value.integer.value[2] =
  4915. get_iir_band_coeff(codec, iir_idx, band_idx, 2);
  4916. ucontrol->value.integer.value[3] =
  4917. get_iir_band_coeff(codec, iir_idx, band_idx, 3);
  4918. ucontrol->value.integer.value[4] =
  4919. get_iir_band_coeff(codec, iir_idx, band_idx, 4);
  4920. dev_dbg(codec->dev, "%s: IIR #%d band #%d b0 = 0x%x\n"
  4921. "%s: IIR #%d band #%d b1 = 0x%x\n"
  4922. "%s: IIR #%d band #%d b2 = 0x%x\n"
  4923. "%s: IIR #%d band #%d a1 = 0x%x\n"
  4924. "%s: IIR #%d band #%d a2 = 0x%x\n",
  4925. __func__, iir_idx, band_idx,
  4926. (uint32_t)ucontrol->value.integer.value[0],
  4927. __func__, iir_idx, band_idx,
  4928. (uint32_t)ucontrol->value.integer.value[1],
  4929. __func__, iir_idx, band_idx,
  4930. (uint32_t)ucontrol->value.integer.value[2],
  4931. __func__, iir_idx, band_idx,
  4932. (uint32_t)ucontrol->value.integer.value[3],
  4933. __func__, iir_idx, band_idx,
  4934. (uint32_t)ucontrol->value.integer.value[4]);
  4935. return 0;
  4936. }
  4937. static void set_iir_band_coeff(struct snd_soc_codec *codec,
  4938. int iir_idx, int band_idx,
  4939. uint32_t value)
  4940. {
  4941. snd_soc_write(codec,
  4942. (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL + 16 * iir_idx),
  4943. (value & 0xFF));
  4944. snd_soc_write(codec,
  4945. (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL + 16 * iir_idx),
  4946. (value >> 8) & 0xFF);
  4947. snd_soc_write(codec,
  4948. (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL + 16 * iir_idx),
  4949. (value >> 16) & 0xFF);
  4950. /* Mask top 2 bits, 7-8 are reserved */
  4951. snd_soc_write(codec,
  4952. (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL + 16 * iir_idx),
  4953. (value >> 24) & 0x3F);
  4954. }
  4955. static int tavil_iir_band_audio_mixer_put(struct snd_kcontrol *kcontrol,
  4956. struct snd_ctl_elem_value *ucontrol)
  4957. {
  4958. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  4959. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  4960. int iir_idx = ((struct soc_multi_mixer_control *)
  4961. kcontrol->private_value)->reg;
  4962. int band_idx = ((struct soc_multi_mixer_control *)
  4963. kcontrol->private_value)->shift;
  4964. int coeff_idx, idx = 0;
  4965. /*
  4966. * Mask top bit it is reserved
  4967. * Updates addr automatically for each B2 write
  4968. */
  4969. snd_soc_write(codec,
  4970. (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B1_CTL + 16 * iir_idx),
  4971. (band_idx * BAND_MAX * sizeof(uint32_t)) & 0x7F);
  4972. /* Store the coefficients in sidetone coeff array */
  4973. for (coeff_idx = 0; coeff_idx < WCD934X_CDC_SIDETONE_IIR_COEFF_MAX;
  4974. coeff_idx++) {
  4975. uint32_t value = ucontrol->value.integer.value[coeff_idx];
  4976. set_iir_band_coeff(codec, iir_idx, band_idx, value);
  4977. /* Four 8 bit values(one 32 bit) per coefficient */
  4978. tavil->sidetone_coeff_array[iir_idx][band_idx][idx++] =
  4979. (value & 0xFF);
  4980. tavil->sidetone_coeff_array[iir_idx][band_idx][idx++] =
  4981. (value >> 8) & 0xFF;
  4982. tavil->sidetone_coeff_array[iir_idx][band_idx][idx++] =
  4983. (value >> 16) & 0xFF;
  4984. tavil->sidetone_coeff_array[iir_idx][band_idx][idx++] =
  4985. (value >> 24) & 0xFF;
  4986. }
  4987. pr_debug("%s: IIR #%d band #%d b0 = 0x%x\n"
  4988. "%s: IIR #%d band #%d b1 = 0x%x\n"
  4989. "%s: IIR #%d band #%d b2 = 0x%x\n"
  4990. "%s: IIR #%d band #%d a1 = 0x%x\n"
  4991. "%s: IIR #%d band #%d a2 = 0x%x\n",
  4992. __func__, iir_idx, band_idx,
  4993. get_iir_band_coeff(codec, iir_idx, band_idx, 0),
  4994. __func__, iir_idx, band_idx,
  4995. get_iir_band_coeff(codec, iir_idx, band_idx, 1),
  4996. __func__, iir_idx, band_idx,
  4997. get_iir_band_coeff(codec, iir_idx, band_idx, 2),
  4998. __func__, iir_idx, band_idx,
  4999. get_iir_band_coeff(codec, iir_idx, band_idx, 3),
  5000. __func__, iir_idx, band_idx,
  5001. get_iir_band_coeff(codec, iir_idx, band_idx, 4));
  5002. return 0;
  5003. }
  5004. static int tavil_compander_get(struct snd_kcontrol *kcontrol,
  5005. struct snd_ctl_elem_value *ucontrol)
  5006. {
  5007. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  5008. int comp = ((struct soc_multi_mixer_control *)
  5009. kcontrol->private_value)->shift;
  5010. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  5011. ucontrol->value.integer.value[0] = tavil->comp_enabled[comp];
  5012. return 0;
  5013. }
  5014. static int tavil_compander_put(struct snd_kcontrol *kcontrol,
  5015. struct snd_ctl_elem_value *ucontrol)
  5016. {
  5017. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  5018. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  5019. int comp = ((struct soc_multi_mixer_control *)
  5020. kcontrol->private_value)->shift;
  5021. int value = ucontrol->value.integer.value[0];
  5022. dev_dbg(codec->dev, "%s: Compander %d enable current %d, new %d\n",
  5023. __func__, comp + 1, tavil->comp_enabled[comp], value);
  5024. tavil->comp_enabled[comp] = value;
  5025. /* Any specific register configuration for compander */
  5026. switch (comp) {
  5027. case COMPANDER_1:
  5028. /* Set Gain Source Select based on compander enable/disable */
  5029. snd_soc_update_bits(codec, WCD934X_HPH_L_EN, 0x20,
  5030. (value ? 0x00:0x20));
  5031. break;
  5032. case COMPANDER_2:
  5033. snd_soc_update_bits(codec, WCD934X_HPH_R_EN, 0x20,
  5034. (value ? 0x00:0x20));
  5035. break;
  5036. case COMPANDER_3:
  5037. case COMPANDER_4:
  5038. case COMPANDER_7:
  5039. case COMPANDER_8:
  5040. break;
  5041. default:
  5042. /*
  5043. * if compander is not enabled for any interpolator,
  5044. * it does not cause any audio failure, so do not
  5045. * return error in this case, but just print a log
  5046. */
  5047. dev_warn(codec->dev, "%s: unknown compander: %d\n",
  5048. __func__, comp);
  5049. };
  5050. return 0;
  5051. }
  5052. static int tavil_hph_asrc_mode_put(struct snd_kcontrol *kcontrol,
  5053. struct snd_ctl_elem_value *ucontrol)
  5054. {
  5055. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  5056. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  5057. int index = -EINVAL;
  5058. if (!strcmp(kcontrol->id.name, "ASRC0 Output Mode"))
  5059. index = ASRC0;
  5060. if (!strcmp(kcontrol->id.name, "ASRC1 Output Mode"))
  5061. index = ASRC1;
  5062. if (tavil && (index >= 0) && (index < ASRC_MAX))
  5063. tavil->asrc_output_mode[index] =
  5064. ucontrol->value.integer.value[0];
  5065. return 0;
  5066. }
  5067. static int tavil_hph_asrc_mode_get(struct snd_kcontrol *kcontrol,
  5068. struct snd_ctl_elem_value *ucontrol)
  5069. {
  5070. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  5071. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  5072. int val = 0;
  5073. int index = -EINVAL;
  5074. if (!strcmp(kcontrol->id.name, "ASRC0 Output Mode"))
  5075. index = ASRC0;
  5076. if (!strcmp(kcontrol->id.name, "ASRC1 Output Mode"))
  5077. index = ASRC1;
  5078. if (tavil && (index >= 0) && (index < ASRC_MAX))
  5079. val = tavil->asrc_output_mode[index];
  5080. ucontrol->value.integer.value[0] = val;
  5081. return 0;
  5082. }
  5083. static int tavil_hph_idle_detect_get(struct snd_kcontrol *kcontrol,
  5084. struct snd_ctl_elem_value *ucontrol)
  5085. {
  5086. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  5087. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  5088. int val = 0;
  5089. if (tavil)
  5090. val = tavil->idle_det_cfg.hph_idle_detect_en;
  5091. ucontrol->value.integer.value[0] = val;
  5092. return 0;
  5093. }
  5094. static int tavil_hph_idle_detect_put(struct snd_kcontrol *kcontrol,
  5095. struct snd_ctl_elem_value *ucontrol)
  5096. {
  5097. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  5098. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  5099. if (tavil)
  5100. tavil->idle_det_cfg.hph_idle_detect_en =
  5101. ucontrol->value.integer.value[0];
  5102. return 0;
  5103. }
  5104. static int tavil_dmic_pin_mode_get(struct snd_kcontrol *kcontrol,
  5105. struct snd_ctl_elem_value *ucontrol)
  5106. {
  5107. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  5108. u16 dmic_pin;
  5109. u8 reg_val, pinctl_position;
  5110. pinctl_position = ((struct soc_multi_mixer_control *)
  5111. kcontrol->private_value)->shift;
  5112. dmic_pin = pinctl_position & 0x07;
  5113. reg_val = snd_soc_read(codec,
  5114. WCD934X_TLMM_DMIC1_CLK_PINCFG + dmic_pin - 1);
  5115. ucontrol->value.integer.value[0] = !!reg_val;
  5116. return 0;
  5117. }
  5118. static int tavil_dmic_pin_mode_put(struct snd_kcontrol *kcontrol,
  5119. struct snd_ctl_elem_value *ucontrol)
  5120. {
  5121. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  5122. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  5123. u16 ctl_reg, cfg_reg, dmic_pin;
  5124. u8 ctl_val, cfg_val, pinctl_position, pinctl_mode, mask;
  5125. /* 0- high or low; 1- high Z */
  5126. pinctl_mode = ucontrol->value.integer.value[0];
  5127. pinctl_position = ((struct soc_multi_mixer_control *)
  5128. kcontrol->private_value)->shift;
  5129. switch (pinctl_position >> 3) {
  5130. case 0:
  5131. ctl_reg = WCD934X_TEST_DEBUG_PIN_CTL_OE_0;
  5132. break;
  5133. case 1:
  5134. ctl_reg = WCD934X_TEST_DEBUG_PIN_CTL_OE_1;
  5135. break;
  5136. case 2:
  5137. ctl_reg = WCD934X_TEST_DEBUG_PIN_CTL_OE_2;
  5138. break;
  5139. case 3:
  5140. ctl_reg = WCD934X_TEST_DEBUG_PIN_CTL_OE_3;
  5141. break;
  5142. default:
  5143. dev_err(codec->dev, "%s: Invalid pinctl position = %d\n",
  5144. __func__, pinctl_position);
  5145. return -EINVAL;
  5146. }
  5147. ctl_val = ~(pinctl_mode << (pinctl_position & 0x07));
  5148. mask = 1 << (pinctl_position & 0x07);
  5149. snd_soc_update_bits(codec, ctl_reg, mask, ctl_val);
  5150. dmic_pin = pinctl_position & 0x07;
  5151. cfg_reg = WCD934X_TLMM_DMIC1_CLK_PINCFG + dmic_pin - 1;
  5152. if (pinctl_mode) {
  5153. if (tavil->intf_type == WCD9XXX_INTERFACE_TYPE_SLIMBUS)
  5154. cfg_val = 0x6;
  5155. else
  5156. cfg_val = 0xD;
  5157. } else
  5158. cfg_val = 0;
  5159. snd_soc_update_bits(codec, cfg_reg, 0x1F, cfg_val);
  5160. dev_dbg(codec->dev, "%s: reg=0x%x mask=0x%x val=%d reg=0x%x val=%d\n",
  5161. __func__, ctl_reg, mask, ctl_val, cfg_reg, cfg_val);
  5162. return 0;
  5163. }
  5164. static int tavil_amic_pwr_lvl_get(struct snd_kcontrol *kcontrol,
  5165. struct snd_ctl_elem_value *ucontrol)
  5166. {
  5167. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  5168. u16 amic_reg = 0;
  5169. if (!strcmp(kcontrol->id.name, "AMIC_1_2 PWR MODE"))
  5170. amic_reg = WCD934X_ANA_AMIC1;
  5171. if (!strcmp(kcontrol->id.name, "AMIC_3_4 PWR MODE"))
  5172. amic_reg = WCD934X_ANA_AMIC3;
  5173. if (amic_reg)
  5174. ucontrol->value.integer.value[0] =
  5175. (snd_soc_read(codec, amic_reg) &
  5176. WCD934X_AMIC_PWR_LVL_MASK) >>
  5177. WCD934X_AMIC_PWR_LVL_SHIFT;
  5178. return 0;
  5179. }
  5180. static int tavil_amic_pwr_lvl_put(struct snd_kcontrol *kcontrol,
  5181. struct snd_ctl_elem_value *ucontrol)
  5182. {
  5183. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  5184. u32 mode_val;
  5185. u16 amic_reg = 0;
  5186. mode_val = ucontrol->value.enumerated.item[0];
  5187. dev_dbg(codec->dev, "%s: mode: %d\n", __func__, mode_val);
  5188. if (!strcmp(kcontrol->id.name, "AMIC_1_2 PWR MODE"))
  5189. amic_reg = WCD934X_ANA_AMIC1;
  5190. if (!strcmp(kcontrol->id.name, "AMIC_3_4 PWR MODE"))
  5191. amic_reg = WCD934X_ANA_AMIC3;
  5192. if (amic_reg)
  5193. snd_soc_update_bits(codec, amic_reg, WCD934X_AMIC_PWR_LVL_MASK,
  5194. mode_val << WCD934X_AMIC_PWR_LVL_SHIFT);
  5195. return 0;
  5196. }
  5197. static const char *const tavil_conn_mad_text[] = {
  5198. "NOTUSED1", "ADC1", "ADC2", "ADC3", "ADC4", "NOTUSED5",
  5199. "NOTUSED6", "NOTUSED2", "DMIC0", "DMIC1", "DMIC2", "DMIC3",
  5200. "DMIC4", "DMIC5", "NOTUSED3", "NOTUSED4"
  5201. };
  5202. static const struct soc_enum tavil_conn_mad_enum =
  5203. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(tavil_conn_mad_text),
  5204. tavil_conn_mad_text);
  5205. static int tavil_mad_input_get(struct snd_kcontrol *kcontrol,
  5206. struct snd_ctl_elem_value *ucontrol)
  5207. {
  5208. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  5209. u8 tavil_mad_input;
  5210. tavil_mad_input = snd_soc_read(codec, WCD934X_SOC_MAD_INP_SEL) & 0x0F;
  5211. ucontrol->value.integer.value[0] = tavil_mad_input;
  5212. dev_dbg(codec->dev, "%s: tavil_mad_input = %s\n", __func__,
  5213. tavil_conn_mad_text[tavil_mad_input]);
  5214. return 0;
  5215. }
  5216. static int tavil_mad_input_put(struct snd_kcontrol *kcontrol,
  5217. struct snd_ctl_elem_value *ucontrol)
  5218. {
  5219. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  5220. struct snd_soc_card *card = codec->component.card;
  5221. u8 tavil_mad_input;
  5222. char mad_amic_input_widget[6];
  5223. const char *mad_input_widget;
  5224. const char *source_widget = NULL;
  5225. u32 adc, i, mic_bias_found = 0;
  5226. int ret = 0;
  5227. char *mad_input;
  5228. bool is_adc_input = false;
  5229. tavil_mad_input = ucontrol->value.integer.value[0];
  5230. if (tavil_mad_input >= sizeof(tavil_conn_mad_text)/
  5231. sizeof(tavil_conn_mad_text[0])) {
  5232. dev_err(codec->dev,
  5233. "%s: tavil_mad_input = %d out of bounds\n",
  5234. __func__, tavil_mad_input);
  5235. return -EINVAL;
  5236. }
  5237. if (strnstr(tavil_conn_mad_text[tavil_mad_input], "NOTUSED",
  5238. sizeof("NOTUSED"))) {
  5239. dev_dbg(codec->dev,
  5240. "%s: Unsupported tavil_mad_input = %s\n",
  5241. __func__, tavil_conn_mad_text[tavil_mad_input]);
  5242. /* Make sure the MAD register is updated */
  5243. snd_soc_update_bits(codec, WCD934X_ANA_MAD_SETUP,
  5244. 0x88, 0x00);
  5245. return -EINVAL;
  5246. }
  5247. if (strnstr(tavil_conn_mad_text[tavil_mad_input],
  5248. "ADC", sizeof("ADC"))) {
  5249. mad_input = strpbrk(tavil_conn_mad_text[tavil_mad_input],
  5250. "1234");
  5251. if (!mad_input) {
  5252. dev_err(codec->dev, "%s: Invalid MAD input %s\n",
  5253. __func__, tavil_conn_mad_text[tavil_mad_input]);
  5254. return -EINVAL;
  5255. }
  5256. ret = kstrtouint(mad_input, 10, &adc);
  5257. if ((ret < 0) || (adc > 4)) {
  5258. dev_err(codec->dev, "%s: Invalid ADC = %s\n", __func__,
  5259. tavil_conn_mad_text[tavil_mad_input]);
  5260. return -EINVAL;
  5261. }
  5262. /*AMIC4 and AMIC5 share ADC4*/
  5263. if ((adc == 4) &&
  5264. (snd_soc_read(codec, WCD934X_TX_NEW_AMIC_4_5_SEL) & 0x10))
  5265. adc = 5;
  5266. snprintf(mad_amic_input_widget, 6, "%s%u", "AMIC", adc);
  5267. mad_input_widget = mad_amic_input_widget;
  5268. is_adc_input = true;
  5269. } else {
  5270. /* DMIC type input widget*/
  5271. mad_input_widget = tavil_conn_mad_text[tavil_mad_input];
  5272. }
  5273. dev_dbg(codec->dev,
  5274. "%s: tavil input widget = %s, adc_input = %s\n", __func__,
  5275. mad_input_widget, is_adc_input ? "true" : "false");
  5276. for (i = 0; i < card->num_of_dapm_routes; i++) {
  5277. if (!strcmp(card->of_dapm_routes[i].sink, mad_input_widget)) {
  5278. source_widget = card->of_dapm_routes[i].source;
  5279. if (!source_widget) {
  5280. dev_err(codec->dev,
  5281. "%s: invalid source widget\n",
  5282. __func__);
  5283. return -EINVAL;
  5284. }
  5285. if (strnstr(source_widget,
  5286. "MIC BIAS1", sizeof("MIC BIAS1"))) {
  5287. mic_bias_found = 1;
  5288. break;
  5289. } else if (strnstr(source_widget,
  5290. "MIC BIAS2", sizeof("MIC BIAS2"))) {
  5291. mic_bias_found = 2;
  5292. break;
  5293. } else if (strnstr(source_widget,
  5294. "MIC BIAS3", sizeof("MIC BIAS3"))) {
  5295. mic_bias_found = 3;
  5296. break;
  5297. } else if (strnstr(source_widget,
  5298. "MIC BIAS4", sizeof("MIC BIAS4"))) {
  5299. mic_bias_found = 4;
  5300. break;
  5301. }
  5302. }
  5303. }
  5304. if (!mic_bias_found) {
  5305. dev_err(codec->dev, "%s: mic bias not found for input %s\n",
  5306. __func__, mad_input_widget);
  5307. return -EINVAL;
  5308. }
  5309. dev_dbg(codec->dev, "%s: mic_bias found = %d\n", __func__,
  5310. mic_bias_found);
  5311. snd_soc_update_bits(codec, WCD934X_SOC_MAD_INP_SEL,
  5312. 0x0F, tavil_mad_input);
  5313. snd_soc_update_bits(codec, WCD934X_ANA_MAD_SETUP,
  5314. 0x07, mic_bias_found);
  5315. /* for all adc inputs, mad should be in micbias mode with BG enabled */
  5316. if (is_adc_input)
  5317. snd_soc_update_bits(codec, WCD934X_ANA_MAD_SETUP,
  5318. 0x88, 0x88);
  5319. else
  5320. snd_soc_update_bits(codec, WCD934X_ANA_MAD_SETUP,
  5321. 0x88, 0x00);
  5322. return 0;
  5323. }
  5324. static int tavil_ear_pa_gain_get(struct snd_kcontrol *kcontrol,
  5325. struct snd_ctl_elem_value *ucontrol)
  5326. {
  5327. u8 ear_pa_gain;
  5328. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  5329. ear_pa_gain = snd_soc_read(codec, WCD934X_ANA_EAR);
  5330. ear_pa_gain = (ear_pa_gain & 0x70) >> 4;
  5331. ucontrol->value.integer.value[0] = ear_pa_gain;
  5332. dev_dbg(codec->dev, "%s: ear_pa_gain = 0x%x\n", __func__,
  5333. ear_pa_gain);
  5334. return 0;
  5335. }
  5336. static int tavil_ear_pa_gain_put(struct snd_kcontrol *kcontrol,
  5337. struct snd_ctl_elem_value *ucontrol)
  5338. {
  5339. u8 ear_pa_gain;
  5340. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  5341. dev_dbg(codec->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  5342. __func__, ucontrol->value.integer.value[0]);
  5343. ear_pa_gain = ucontrol->value.integer.value[0] << 4;
  5344. snd_soc_update_bits(codec, WCD934X_ANA_EAR, 0x70, ear_pa_gain);
  5345. return 0;
  5346. }
  5347. static int tavil_ear_spkr_pa_gain_get(struct snd_kcontrol *kcontrol,
  5348. struct snd_ctl_elem_value *ucontrol)
  5349. {
  5350. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  5351. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  5352. ucontrol->value.integer.value[0] = tavil->ear_spkr_gain;
  5353. dev_dbg(codec->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  5354. __func__, ucontrol->value.integer.value[0]);
  5355. return 0;
  5356. }
  5357. static int tavil_ear_spkr_pa_gain_put(struct snd_kcontrol *kcontrol,
  5358. struct snd_ctl_elem_value *ucontrol)
  5359. {
  5360. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  5361. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  5362. tavil->ear_spkr_gain = ucontrol->value.integer.value[0];
  5363. dev_dbg(codec->dev, "%s: gain = %d\n", __func__, tavil->ear_spkr_gain);
  5364. return 0;
  5365. }
  5366. static int tavil_spkr_left_boost_stage_get(struct snd_kcontrol *kcontrol,
  5367. struct snd_ctl_elem_value *ucontrol)
  5368. {
  5369. u8 bst_state_max = 0;
  5370. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  5371. bst_state_max = snd_soc_read(codec, WCD934X_CDC_BOOST0_BOOST_CTL);
  5372. bst_state_max = (bst_state_max & 0x0c) >> 2;
  5373. ucontrol->value.integer.value[0] = bst_state_max;
  5374. dev_dbg(codec->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  5375. __func__, ucontrol->value.integer.value[0]);
  5376. return 0;
  5377. }
  5378. static int tavil_spkr_left_boost_stage_put(struct snd_kcontrol *kcontrol,
  5379. struct snd_ctl_elem_value *ucontrol)
  5380. {
  5381. u8 bst_state_max;
  5382. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  5383. dev_dbg(codec->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  5384. __func__, ucontrol->value.integer.value[0]);
  5385. bst_state_max = ucontrol->value.integer.value[0] << 2;
  5386. snd_soc_update_bits(codec, WCD934X_CDC_BOOST0_BOOST_CTL,
  5387. 0x0c, bst_state_max);
  5388. return 0;
  5389. }
  5390. static int tavil_spkr_right_boost_stage_get(struct snd_kcontrol *kcontrol,
  5391. struct snd_ctl_elem_value *ucontrol)
  5392. {
  5393. u8 bst_state_max = 0;
  5394. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  5395. bst_state_max = snd_soc_read(codec, WCD934X_CDC_BOOST1_BOOST_CTL);
  5396. bst_state_max = (bst_state_max & 0x0c) >> 2;
  5397. ucontrol->value.integer.value[0] = bst_state_max;
  5398. dev_dbg(codec->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  5399. __func__, ucontrol->value.integer.value[0]);
  5400. return 0;
  5401. }
  5402. static int tavil_spkr_right_boost_stage_put(struct snd_kcontrol *kcontrol,
  5403. struct snd_ctl_elem_value *ucontrol)
  5404. {
  5405. u8 bst_state_max;
  5406. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  5407. dev_dbg(codec->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  5408. __func__, ucontrol->value.integer.value[0]);
  5409. bst_state_max = ucontrol->value.integer.value[0] << 2;
  5410. snd_soc_update_bits(codec, WCD934X_CDC_BOOST1_BOOST_CTL,
  5411. 0x0c, bst_state_max);
  5412. return 0;
  5413. }
  5414. static int tavil_rx_hph_mode_get(struct snd_kcontrol *kcontrol,
  5415. struct snd_ctl_elem_value *ucontrol)
  5416. {
  5417. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  5418. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  5419. ucontrol->value.integer.value[0] = tavil->hph_mode;
  5420. return 0;
  5421. }
  5422. static int tavil_rx_hph_mode_put(struct snd_kcontrol *kcontrol,
  5423. struct snd_ctl_elem_value *ucontrol)
  5424. {
  5425. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  5426. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  5427. u32 mode_val;
  5428. mode_val = ucontrol->value.enumerated.item[0];
  5429. dev_dbg(codec->dev, "%s: mode: %d\n", __func__, mode_val);
  5430. if (mode_val == 0) {
  5431. dev_warn(codec->dev, "%s:Invalid HPH Mode, default to Cls-H LOHiFi\n",
  5432. __func__);
  5433. mode_val = CLS_H_LOHIFI;
  5434. }
  5435. tavil->hph_mode = mode_val;
  5436. return 0;
  5437. }
  5438. static const char * const rx_hph_mode_mux_text[] = {
  5439. "CLS_H_INVALID", "CLS_H_HIFI", "CLS_H_LP", "CLS_AB", "CLS_H_LOHIFI",
  5440. "CLS_H_ULP", "CLS_AB_HIFI",
  5441. };
  5442. static const struct soc_enum rx_hph_mode_mux_enum =
  5443. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(rx_hph_mode_mux_text),
  5444. rx_hph_mode_mux_text);
  5445. static const char *const tavil_anc_func_text[] = {"OFF", "ON"};
  5446. static const struct soc_enum tavil_anc_func_enum =
  5447. SOC_ENUM_SINGLE_EXT(2, tavil_anc_func_text);
  5448. static const char *const tavil_clkmode_text[] = {"EXTERNAL", "INTERNAL"};
  5449. static SOC_ENUM_SINGLE_EXT_DECL(tavil_clkmode_enum, tavil_clkmode_text);
  5450. /* Cutoff frequency for high pass filter */
  5451. static const char * const cf_text[] = {
  5452. "CF_NEG_3DB_4HZ", "CF_NEG_3DB_75HZ", "CF_NEG_3DB_150HZ"
  5453. };
  5454. static const char * const rx_cf_text[] = {
  5455. "CF_NEG_3DB_4HZ", "CF_NEG_3DB_75HZ", "CF_NEG_3DB_150HZ",
  5456. "CF_NEG_3DB_0P48HZ"
  5457. };
  5458. static const char * const amic_pwr_lvl_text[] = {
  5459. "LOW_PWR", "DEFAULT", "HIGH_PERF", "HYBRID"
  5460. };
  5461. static const char * const hph_idle_detect_text[] = {
  5462. "OFF", "ON"
  5463. };
  5464. static const char * const asrc_mode_text[] = {
  5465. "INT", "FRAC"
  5466. };
  5467. static const char * const tavil_ear_pa_gain_text[] = {
  5468. "G_6_DB", "G_4P5_DB", "G_3_DB", "G_1P5_DB",
  5469. "G_0_DB", "G_M2P5_DB", "UNDEFINED", "G_M12_DB"
  5470. };
  5471. static const char * const tavil_ear_spkr_pa_gain_text[] = {
  5472. "G_DEFAULT", "G_0_DB", "G_1_DB", "G_2_DB", "G_3_DB",
  5473. "G_4_DB", "G_5_DB", "G_6_DB"
  5474. };
  5475. static const char * const tavil_speaker_boost_stage_text[] = {
  5476. "NO_MAX_STATE", "MAX_STATE_1", "MAX_STATE_2"
  5477. };
  5478. static SOC_ENUM_SINGLE_EXT_DECL(tavil_ear_pa_gain_enum, tavil_ear_pa_gain_text);
  5479. static SOC_ENUM_SINGLE_EXT_DECL(tavil_ear_spkr_pa_gain_enum,
  5480. tavil_ear_spkr_pa_gain_text);
  5481. static SOC_ENUM_SINGLE_EXT_DECL(tavil_spkr_boost_stage_enum,
  5482. tavil_speaker_boost_stage_text);
  5483. static SOC_ENUM_SINGLE_EXT_DECL(amic_pwr_lvl_enum, amic_pwr_lvl_text);
  5484. static SOC_ENUM_SINGLE_EXT_DECL(hph_idle_detect_enum, hph_idle_detect_text);
  5485. static SOC_ENUM_SINGLE_EXT_DECL(asrc_mode_enum, asrc_mode_text);
  5486. static SOC_ENUM_SINGLE_DECL(cf_dec0_enum, WCD934X_CDC_TX0_TX_PATH_CFG0, 5,
  5487. cf_text);
  5488. static SOC_ENUM_SINGLE_DECL(cf_dec1_enum, WCD934X_CDC_TX1_TX_PATH_CFG0, 5,
  5489. cf_text);
  5490. static SOC_ENUM_SINGLE_DECL(cf_dec2_enum, WCD934X_CDC_TX2_TX_PATH_CFG0, 5,
  5491. cf_text);
  5492. static SOC_ENUM_SINGLE_DECL(cf_dec3_enum, WCD934X_CDC_TX3_TX_PATH_CFG0, 5,
  5493. cf_text);
  5494. static SOC_ENUM_SINGLE_DECL(cf_dec4_enum, WCD934X_CDC_TX4_TX_PATH_CFG0, 5,
  5495. cf_text);
  5496. static SOC_ENUM_SINGLE_DECL(cf_dec5_enum, WCD934X_CDC_TX5_TX_PATH_CFG0, 5,
  5497. cf_text);
  5498. static SOC_ENUM_SINGLE_DECL(cf_dec6_enum, WCD934X_CDC_TX6_TX_PATH_CFG0, 5,
  5499. cf_text);
  5500. static SOC_ENUM_SINGLE_DECL(cf_dec7_enum, WCD934X_CDC_TX7_TX_PATH_CFG0, 5,
  5501. cf_text);
  5502. static SOC_ENUM_SINGLE_DECL(cf_dec8_enum, WCD934X_CDC_TX8_TX_PATH_CFG0, 5,
  5503. cf_text);
  5504. static SOC_ENUM_SINGLE_DECL(cf_int0_1_enum, WCD934X_CDC_RX0_RX_PATH_CFG2, 0,
  5505. rx_cf_text);
  5506. static SOC_ENUM_SINGLE_DECL(cf_int0_2_enum, WCD934X_CDC_RX0_RX_PATH_MIX_CFG, 2,
  5507. rx_cf_text);
  5508. static SOC_ENUM_SINGLE_DECL(cf_int1_1_enum, WCD934X_CDC_RX1_RX_PATH_CFG2, 0,
  5509. rx_cf_text);
  5510. static SOC_ENUM_SINGLE_DECL(cf_int1_2_enum, WCD934X_CDC_RX1_RX_PATH_MIX_CFG, 2,
  5511. rx_cf_text);
  5512. static SOC_ENUM_SINGLE_DECL(cf_int2_1_enum, WCD934X_CDC_RX2_RX_PATH_CFG2, 0,
  5513. rx_cf_text);
  5514. static SOC_ENUM_SINGLE_DECL(cf_int2_2_enum, WCD934X_CDC_RX2_RX_PATH_MIX_CFG, 2,
  5515. rx_cf_text);
  5516. static SOC_ENUM_SINGLE_DECL(cf_int3_1_enum, WCD934X_CDC_RX3_RX_PATH_CFG2, 0,
  5517. rx_cf_text);
  5518. static SOC_ENUM_SINGLE_DECL(cf_int3_2_enum, WCD934X_CDC_RX3_RX_PATH_MIX_CFG, 2,
  5519. rx_cf_text);
  5520. static SOC_ENUM_SINGLE_DECL(cf_int4_1_enum, WCD934X_CDC_RX4_RX_PATH_CFG2, 0,
  5521. rx_cf_text);
  5522. static SOC_ENUM_SINGLE_DECL(cf_int4_2_enum, WCD934X_CDC_RX4_RX_PATH_MIX_CFG, 2,
  5523. rx_cf_text);
  5524. static SOC_ENUM_SINGLE_DECL(cf_int7_1_enum, WCD934X_CDC_RX7_RX_PATH_CFG2, 0,
  5525. rx_cf_text);
  5526. static SOC_ENUM_SINGLE_DECL(cf_int7_2_enum, WCD934X_CDC_RX7_RX_PATH_MIX_CFG, 2,
  5527. rx_cf_text);
  5528. static SOC_ENUM_SINGLE_DECL(cf_int8_1_enum, WCD934X_CDC_RX8_RX_PATH_CFG2, 0,
  5529. rx_cf_text);
  5530. static SOC_ENUM_SINGLE_DECL(cf_int8_2_enum, WCD934X_CDC_RX8_RX_PATH_MIX_CFG, 2,
  5531. rx_cf_text);
  5532. static const struct snd_kcontrol_new tavil_snd_controls[] = {
  5533. SOC_ENUM_EXT("EAR PA Gain", tavil_ear_pa_gain_enum,
  5534. tavil_ear_pa_gain_get, tavil_ear_pa_gain_put),
  5535. SOC_ENUM_EXT("EAR SPKR PA Gain", tavil_ear_spkr_pa_gain_enum,
  5536. tavil_ear_spkr_pa_gain_get, tavil_ear_spkr_pa_gain_put),
  5537. SOC_ENUM_EXT("SPKR Left Boost Max State", tavil_spkr_boost_stage_enum,
  5538. tavil_spkr_left_boost_stage_get,
  5539. tavil_spkr_left_boost_stage_put),
  5540. SOC_ENUM_EXT("SPKR Right Boost Max State", tavil_spkr_boost_stage_enum,
  5541. tavil_spkr_right_boost_stage_get,
  5542. tavil_spkr_right_boost_stage_put),
  5543. SOC_SINGLE_TLV("HPHL Volume", WCD934X_HPH_L_EN, 0, 20, 1, line_gain),
  5544. SOC_SINGLE_TLV("HPHR Volume", WCD934X_HPH_R_EN, 0, 20, 1, line_gain),
  5545. SOC_SINGLE_TLV("LINEOUT1 Volume", WCD934X_DIFF_LO_LO1_COMPANDER,
  5546. 3, 16, 1, line_gain),
  5547. SOC_SINGLE_TLV("LINEOUT2 Volume", WCD934X_DIFF_LO_LO2_COMPANDER,
  5548. 3, 16, 1, line_gain),
  5549. SOC_SINGLE_TLV("ADC1 Volume", WCD934X_ANA_AMIC1, 0, 20, 0, analog_gain),
  5550. SOC_SINGLE_TLV("ADC2 Volume", WCD934X_ANA_AMIC2, 0, 20, 0, analog_gain),
  5551. SOC_SINGLE_TLV("ADC3 Volume", WCD934X_ANA_AMIC3, 0, 20, 0, analog_gain),
  5552. SOC_SINGLE_TLV("ADC4 Volume", WCD934X_ANA_AMIC4, 0, 20, 0, analog_gain),
  5553. SOC_SINGLE_SX_TLV("RX0 Digital Volume", WCD934X_CDC_RX0_RX_VOL_CTL,
  5554. 0, -84, 40, digital_gain), /* -84dB min - 40dB max */
  5555. SOC_SINGLE_SX_TLV("RX1 Digital Volume", WCD934X_CDC_RX1_RX_VOL_CTL,
  5556. 0, -84, 40, digital_gain),
  5557. SOC_SINGLE_SX_TLV("RX2 Digital Volume", WCD934X_CDC_RX2_RX_VOL_CTL,
  5558. 0, -84, 40, digital_gain),
  5559. SOC_SINGLE_SX_TLV("RX3 Digital Volume", WCD934X_CDC_RX3_RX_VOL_CTL,
  5560. 0, -84, 40, digital_gain),
  5561. SOC_SINGLE_SX_TLV("RX4 Digital Volume", WCD934X_CDC_RX4_RX_VOL_CTL,
  5562. 0, -84, 40, digital_gain),
  5563. SOC_SINGLE_SX_TLV("RX7 Digital Volume", WCD934X_CDC_RX7_RX_VOL_CTL,
  5564. 0, -84, 40, digital_gain),
  5565. SOC_SINGLE_SX_TLV("RX8 Digital Volume", WCD934X_CDC_RX8_RX_VOL_CTL,
  5566. 0, -84, 40, digital_gain),
  5567. SOC_SINGLE_SX_TLV("RX0 Mix Digital Volume",
  5568. WCD934X_CDC_RX0_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain),
  5569. SOC_SINGLE_SX_TLV("RX1 Mix Digital Volume",
  5570. WCD934X_CDC_RX1_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain),
  5571. SOC_SINGLE_SX_TLV("RX2 Mix Digital Volume",
  5572. WCD934X_CDC_RX2_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain),
  5573. SOC_SINGLE_SX_TLV("RX3 Mix Digital Volume",
  5574. WCD934X_CDC_RX3_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain),
  5575. SOC_SINGLE_SX_TLV("RX4 Mix Digital Volume",
  5576. WCD934X_CDC_RX4_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain),
  5577. SOC_SINGLE_SX_TLV("RX7 Mix Digital Volume",
  5578. WCD934X_CDC_RX7_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain),
  5579. SOC_SINGLE_SX_TLV("RX8 Mix Digital Volume",
  5580. WCD934X_CDC_RX8_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain),
  5581. SOC_SINGLE_SX_TLV("DEC0 Volume", WCD934X_CDC_TX0_TX_VOL_CTL, 0,
  5582. -84, 40, digital_gain),
  5583. SOC_SINGLE_SX_TLV("DEC1 Volume", WCD934X_CDC_TX1_TX_VOL_CTL, 0,
  5584. -84, 40, digital_gain),
  5585. SOC_SINGLE_SX_TLV("DEC2 Volume", WCD934X_CDC_TX2_TX_VOL_CTL, 0,
  5586. -84, 40, digital_gain),
  5587. SOC_SINGLE_SX_TLV("DEC3 Volume", WCD934X_CDC_TX3_TX_VOL_CTL, 0,
  5588. -84, 40, digital_gain),
  5589. SOC_SINGLE_SX_TLV("DEC4 Volume", WCD934X_CDC_TX4_TX_VOL_CTL, 0,
  5590. -84, 40, digital_gain),
  5591. SOC_SINGLE_SX_TLV("DEC5 Volume", WCD934X_CDC_TX5_TX_VOL_CTL, 0,
  5592. -84, 40, digital_gain),
  5593. SOC_SINGLE_SX_TLV("DEC6 Volume", WCD934X_CDC_TX6_TX_VOL_CTL, 0,
  5594. -84, 40, digital_gain),
  5595. SOC_SINGLE_SX_TLV("DEC7 Volume", WCD934X_CDC_TX7_TX_VOL_CTL, 0,
  5596. -84, 40, digital_gain),
  5597. SOC_SINGLE_SX_TLV("DEC8 Volume", WCD934X_CDC_TX8_TX_VOL_CTL, 0,
  5598. -84, 40, digital_gain),
  5599. SOC_SINGLE_SX_TLV("IIR0 INP0 Volume",
  5600. WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B1_CTL, 0, -84, 40,
  5601. digital_gain),
  5602. SOC_SINGLE_SX_TLV("IIR0 INP1 Volume",
  5603. WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B2_CTL, 0, -84, 40,
  5604. digital_gain),
  5605. SOC_SINGLE_SX_TLV("IIR0 INP2 Volume",
  5606. WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B3_CTL, 0, -84, 40,
  5607. digital_gain),
  5608. SOC_SINGLE_SX_TLV("IIR0 INP3 Volume",
  5609. WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B4_CTL, 0, -84, 40,
  5610. digital_gain),
  5611. SOC_SINGLE_SX_TLV("IIR1 INP0 Volume",
  5612. WCD934X_CDC_SIDETONE_IIR1_IIR_GAIN_B1_CTL, 0, -84, 40,
  5613. digital_gain),
  5614. SOC_SINGLE_SX_TLV("IIR1 INP1 Volume",
  5615. WCD934X_CDC_SIDETONE_IIR1_IIR_GAIN_B2_CTL, 0, -84, 40,
  5616. digital_gain),
  5617. SOC_SINGLE_SX_TLV("IIR1 INP2 Volume",
  5618. WCD934X_CDC_SIDETONE_IIR1_IIR_GAIN_B3_CTL, 0, -84, 40,
  5619. digital_gain),
  5620. SOC_SINGLE_SX_TLV("IIR1 INP3 Volume",
  5621. WCD934X_CDC_SIDETONE_IIR1_IIR_GAIN_B4_CTL, 0, -84, 40,
  5622. digital_gain),
  5623. SOC_SINGLE_EXT("ANC Slot", SND_SOC_NOPM, 0, 100, 0, tavil_get_anc_slot,
  5624. tavil_put_anc_slot),
  5625. SOC_ENUM_EXT("ANC Function", tavil_anc_func_enum, tavil_get_anc_func,
  5626. tavil_put_anc_func),
  5627. SOC_ENUM_EXT("CLK MODE", tavil_clkmode_enum, tavil_get_clkmode,
  5628. tavil_put_clkmode),
  5629. SOC_ENUM("TX0 HPF cut off", cf_dec0_enum),
  5630. SOC_ENUM("TX1 HPF cut off", cf_dec1_enum),
  5631. SOC_ENUM("TX2 HPF cut off", cf_dec2_enum),
  5632. SOC_ENUM("TX3 HPF cut off", cf_dec3_enum),
  5633. SOC_ENUM("TX4 HPF cut off", cf_dec4_enum),
  5634. SOC_ENUM("TX5 HPF cut off", cf_dec5_enum),
  5635. SOC_ENUM("TX6 HPF cut off", cf_dec6_enum),
  5636. SOC_ENUM("TX7 HPF cut off", cf_dec7_enum),
  5637. SOC_ENUM("TX8 HPF cut off", cf_dec8_enum),
  5638. SOC_ENUM("RX INT0_1 HPF cut off", cf_int0_1_enum),
  5639. SOC_ENUM("RX INT0_2 HPF cut off", cf_int0_2_enum),
  5640. SOC_ENUM("RX INT1_1 HPF cut off", cf_int1_1_enum),
  5641. SOC_ENUM("RX INT1_2 HPF cut off", cf_int1_2_enum),
  5642. SOC_ENUM("RX INT2_1 HPF cut off", cf_int2_1_enum),
  5643. SOC_ENUM("RX INT2_2 HPF cut off", cf_int2_2_enum),
  5644. SOC_ENUM("RX INT3_1 HPF cut off", cf_int3_1_enum),
  5645. SOC_ENUM("RX INT3_2 HPF cut off", cf_int3_2_enum),
  5646. SOC_ENUM("RX INT4_1 HPF cut off", cf_int4_1_enum),
  5647. SOC_ENUM("RX INT4_2 HPF cut off", cf_int4_2_enum),
  5648. SOC_ENUM("RX INT7_1 HPF cut off", cf_int7_1_enum),
  5649. SOC_ENUM("RX INT7_2 HPF cut off", cf_int7_2_enum),
  5650. SOC_ENUM("RX INT8_1 HPF cut off", cf_int8_1_enum),
  5651. SOC_ENUM("RX INT8_2 HPF cut off", cf_int8_2_enum),
  5652. SOC_ENUM_EXT("RX HPH Mode", rx_hph_mode_mux_enum,
  5653. tavil_rx_hph_mode_get, tavil_rx_hph_mode_put),
  5654. SOC_SINGLE_EXT("IIR0 Enable Band1", IIR0, BAND1, 1, 0,
  5655. tavil_iir_enable_audio_mixer_get,
  5656. tavil_iir_enable_audio_mixer_put),
  5657. SOC_SINGLE_EXT("IIR0 Enable Band2", IIR0, BAND2, 1, 0,
  5658. tavil_iir_enable_audio_mixer_get,
  5659. tavil_iir_enable_audio_mixer_put),
  5660. SOC_SINGLE_EXT("IIR0 Enable Band3", IIR0, BAND3, 1, 0,
  5661. tavil_iir_enable_audio_mixer_get,
  5662. tavil_iir_enable_audio_mixer_put),
  5663. SOC_SINGLE_EXT("IIR0 Enable Band4", IIR0, BAND4, 1, 0,
  5664. tavil_iir_enable_audio_mixer_get,
  5665. tavil_iir_enable_audio_mixer_put),
  5666. SOC_SINGLE_EXT("IIR0 Enable Band5", IIR0, BAND5, 1, 0,
  5667. tavil_iir_enable_audio_mixer_get,
  5668. tavil_iir_enable_audio_mixer_put),
  5669. SOC_SINGLE_EXT("IIR1 Enable Band1", IIR1, BAND1, 1, 0,
  5670. tavil_iir_enable_audio_mixer_get,
  5671. tavil_iir_enable_audio_mixer_put),
  5672. SOC_SINGLE_EXT("IIR1 Enable Band2", IIR1, BAND2, 1, 0,
  5673. tavil_iir_enable_audio_mixer_get,
  5674. tavil_iir_enable_audio_mixer_put),
  5675. SOC_SINGLE_EXT("IIR1 Enable Band3", IIR1, BAND3, 1, 0,
  5676. tavil_iir_enable_audio_mixer_get,
  5677. tavil_iir_enable_audio_mixer_put),
  5678. SOC_SINGLE_EXT("IIR1 Enable Band4", IIR1, BAND4, 1, 0,
  5679. tavil_iir_enable_audio_mixer_get,
  5680. tavil_iir_enable_audio_mixer_put),
  5681. SOC_SINGLE_EXT("IIR1 Enable Band5", IIR1, BAND5, 1, 0,
  5682. tavil_iir_enable_audio_mixer_get,
  5683. tavil_iir_enable_audio_mixer_put),
  5684. SOC_SINGLE_MULTI_EXT("IIR0 Band1", IIR0, BAND1, 255, 0, 5,
  5685. tavil_iir_band_audio_mixer_get, tavil_iir_band_audio_mixer_put),
  5686. SOC_SINGLE_MULTI_EXT("IIR0 Band2", IIR0, BAND2, 255, 0, 5,
  5687. tavil_iir_band_audio_mixer_get, tavil_iir_band_audio_mixer_put),
  5688. SOC_SINGLE_MULTI_EXT("IIR0 Band3", IIR0, BAND3, 255, 0, 5,
  5689. tavil_iir_band_audio_mixer_get, tavil_iir_band_audio_mixer_put),
  5690. SOC_SINGLE_MULTI_EXT("IIR0 Band4", IIR0, BAND4, 255, 0, 5,
  5691. tavil_iir_band_audio_mixer_get, tavil_iir_band_audio_mixer_put),
  5692. SOC_SINGLE_MULTI_EXT("IIR0 Band5", IIR0, BAND5, 255, 0, 5,
  5693. tavil_iir_band_audio_mixer_get, tavil_iir_band_audio_mixer_put),
  5694. SOC_SINGLE_MULTI_EXT("IIR1 Band1", IIR1, BAND1, 255, 0, 5,
  5695. tavil_iir_band_audio_mixer_get, tavil_iir_band_audio_mixer_put),
  5696. SOC_SINGLE_MULTI_EXT("IIR1 Band2", IIR1, BAND2, 255, 0, 5,
  5697. tavil_iir_band_audio_mixer_get, tavil_iir_band_audio_mixer_put),
  5698. SOC_SINGLE_MULTI_EXT("IIR1 Band3", IIR1, BAND3, 255, 0, 5,
  5699. tavil_iir_band_audio_mixer_get, tavil_iir_band_audio_mixer_put),
  5700. SOC_SINGLE_MULTI_EXT("IIR1 Band4", IIR1, BAND4, 255, 0, 5,
  5701. tavil_iir_band_audio_mixer_get, tavil_iir_band_audio_mixer_put),
  5702. SOC_SINGLE_MULTI_EXT("IIR1 Band5", IIR1, BAND5, 255, 0, 5,
  5703. tavil_iir_band_audio_mixer_get, tavil_iir_band_audio_mixer_put),
  5704. SOC_SINGLE_EXT("COMP1 Switch", SND_SOC_NOPM, COMPANDER_1, 1, 0,
  5705. tavil_compander_get, tavil_compander_put),
  5706. SOC_SINGLE_EXT("COMP2 Switch", SND_SOC_NOPM, COMPANDER_2, 1, 0,
  5707. tavil_compander_get, tavil_compander_put),
  5708. SOC_SINGLE_EXT("COMP3 Switch", SND_SOC_NOPM, COMPANDER_3, 1, 0,
  5709. tavil_compander_get, tavil_compander_put),
  5710. SOC_SINGLE_EXT("COMP4 Switch", SND_SOC_NOPM, COMPANDER_4, 1, 0,
  5711. tavil_compander_get, tavil_compander_put),
  5712. SOC_SINGLE_EXT("COMP7 Switch", SND_SOC_NOPM, COMPANDER_7, 1, 0,
  5713. tavil_compander_get, tavil_compander_put),
  5714. SOC_SINGLE_EXT("COMP8 Switch", SND_SOC_NOPM, COMPANDER_8, 1, 0,
  5715. tavil_compander_get, tavil_compander_put),
  5716. SOC_ENUM_EXT("ASRC0 Output Mode", asrc_mode_enum,
  5717. tavil_hph_asrc_mode_get, tavil_hph_asrc_mode_put),
  5718. SOC_ENUM_EXT("ASRC1 Output Mode", asrc_mode_enum,
  5719. tavil_hph_asrc_mode_get, tavil_hph_asrc_mode_put),
  5720. SOC_ENUM_EXT("HPH Idle Detect", hph_idle_detect_enum,
  5721. tavil_hph_idle_detect_get, tavil_hph_idle_detect_put),
  5722. SOC_ENUM_EXT("MAD Input", tavil_conn_mad_enum,
  5723. tavil_mad_input_get, tavil_mad_input_put),
  5724. SOC_SINGLE_EXT("DMIC1_CLK_PIN_MODE", SND_SOC_NOPM, 17, 1, 0,
  5725. tavil_dmic_pin_mode_get, tavil_dmic_pin_mode_put),
  5726. SOC_SINGLE_EXT("DMIC1_DATA_PIN_MODE", SND_SOC_NOPM, 18, 1, 0,
  5727. tavil_dmic_pin_mode_get, tavil_dmic_pin_mode_put),
  5728. SOC_SINGLE_EXT("DMIC2_CLK_PIN_MODE", SND_SOC_NOPM, 19, 1, 0,
  5729. tavil_dmic_pin_mode_get, tavil_dmic_pin_mode_put),
  5730. SOC_SINGLE_EXT("DMIC2_DATA_PIN_MODE", SND_SOC_NOPM, 20, 1, 0,
  5731. tavil_dmic_pin_mode_get, tavil_dmic_pin_mode_put),
  5732. SOC_SINGLE_EXT("DMIC3_CLK_PIN_MODE", SND_SOC_NOPM, 21, 1, 0,
  5733. tavil_dmic_pin_mode_get, tavil_dmic_pin_mode_put),
  5734. SOC_SINGLE_EXT("DMIC3_DATA_PIN_MODE", SND_SOC_NOPM, 22, 1, 0,
  5735. tavil_dmic_pin_mode_get, tavil_dmic_pin_mode_put),
  5736. SOC_ENUM_EXT("AMIC_1_2 PWR MODE", amic_pwr_lvl_enum,
  5737. tavil_amic_pwr_lvl_get, tavil_amic_pwr_lvl_put),
  5738. SOC_ENUM_EXT("AMIC_3_4 PWR MODE", amic_pwr_lvl_enum,
  5739. tavil_amic_pwr_lvl_get, tavil_amic_pwr_lvl_put),
  5740. SOC_ENUM_EXT("AMIC_5_6 PWR MODE", amic_pwr_lvl_enum,
  5741. tavil_amic_pwr_lvl_get, tavil_amic_pwr_lvl_put),
  5742. };
  5743. static int tavil_dec_enum_put(struct snd_kcontrol *kcontrol,
  5744. struct snd_ctl_elem_value *ucontrol)
  5745. {
  5746. struct snd_soc_dapm_widget *widget =
  5747. snd_soc_dapm_kcontrol_widget(kcontrol);
  5748. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  5749. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  5750. unsigned int val;
  5751. u16 mic_sel_reg = 0;
  5752. u8 mic_sel;
  5753. val = ucontrol->value.enumerated.item[0];
  5754. if (val > e->items - 1)
  5755. return -EINVAL;
  5756. dev_dbg(codec->dev, "%s: wname: %s, val: 0x%x\n", __func__,
  5757. widget->name, val);
  5758. switch (e->reg) {
  5759. case WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG1:
  5760. if (e->shift_l == 0)
  5761. mic_sel_reg = WCD934X_CDC_TX0_TX_PATH_CFG0;
  5762. else if (e->shift_l == 2)
  5763. mic_sel_reg = WCD934X_CDC_TX4_TX_PATH_CFG0;
  5764. else if (e->shift_l == 4)
  5765. mic_sel_reg = WCD934X_CDC_TX8_TX_PATH_CFG0;
  5766. break;
  5767. case WCD934X_CDC_TX_INP_MUX_ADC_MUX1_CFG1:
  5768. if (e->shift_l == 0)
  5769. mic_sel_reg = WCD934X_CDC_TX1_TX_PATH_CFG0;
  5770. else if (e->shift_l == 2)
  5771. mic_sel_reg = WCD934X_CDC_TX5_TX_PATH_CFG0;
  5772. break;
  5773. case WCD934X_CDC_TX_INP_MUX_ADC_MUX2_CFG1:
  5774. if (e->shift_l == 0)
  5775. mic_sel_reg = WCD934X_CDC_TX2_TX_PATH_CFG0;
  5776. else if (e->shift_l == 2)
  5777. mic_sel_reg = WCD934X_CDC_TX6_TX_PATH_CFG0;
  5778. break;
  5779. case WCD934X_CDC_TX_INP_MUX_ADC_MUX3_CFG1:
  5780. if (e->shift_l == 0)
  5781. mic_sel_reg = WCD934X_CDC_TX3_TX_PATH_CFG0;
  5782. else if (e->shift_l == 2)
  5783. mic_sel_reg = WCD934X_CDC_TX7_TX_PATH_CFG0;
  5784. break;
  5785. default:
  5786. dev_err(codec->dev, "%s: e->reg: 0x%x not expected\n",
  5787. __func__, e->reg);
  5788. return -EINVAL;
  5789. }
  5790. /* ADC: 0, DMIC: 1 */
  5791. mic_sel = val ? 0x0 : 0x1;
  5792. if (mic_sel_reg)
  5793. snd_soc_update_bits(codec, mic_sel_reg, 1 << 7, mic_sel << 7);
  5794. return snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
  5795. }
  5796. static int tavil_int_dem_inp_mux_put(struct snd_kcontrol *kcontrol,
  5797. struct snd_ctl_elem_value *ucontrol)
  5798. {
  5799. struct snd_soc_dapm_widget *widget =
  5800. snd_soc_dapm_kcontrol_widget(kcontrol);
  5801. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  5802. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  5803. unsigned int val;
  5804. unsigned short look_ahead_dly_reg = WCD934X_CDC_RX0_RX_PATH_CFG0;
  5805. val = ucontrol->value.enumerated.item[0];
  5806. if (val >= e->items)
  5807. return -EINVAL;
  5808. dev_dbg(codec->dev, "%s: wname: %s, val: 0x%x\n", __func__,
  5809. widget->name, val);
  5810. if (e->reg == WCD934X_CDC_RX0_RX_PATH_SEC0)
  5811. look_ahead_dly_reg = WCD934X_CDC_RX0_RX_PATH_CFG0;
  5812. else if (e->reg == WCD934X_CDC_RX1_RX_PATH_SEC0)
  5813. look_ahead_dly_reg = WCD934X_CDC_RX1_RX_PATH_CFG0;
  5814. else if (e->reg == WCD934X_CDC_RX2_RX_PATH_SEC0)
  5815. look_ahead_dly_reg = WCD934X_CDC_RX2_RX_PATH_CFG0;
  5816. /* Set Look Ahead Delay */
  5817. snd_soc_update_bits(codec, look_ahead_dly_reg,
  5818. 0x08, (val ? 0x08 : 0x00));
  5819. /* Set DEM INP Select */
  5820. return snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
  5821. }
  5822. static const char * const rx_int0_7_mix_mux_text[] = {
  5823. "ZERO", "RX0", "RX1", "RX2", "RX3", "RX4", "RX5",
  5824. "RX6", "RX7", "PROXIMITY"
  5825. };
  5826. static const char * const rx_int_mix_mux_text[] = {
  5827. "ZERO", "RX0", "RX1", "RX2", "RX3", "RX4", "RX5",
  5828. "RX6", "RX7"
  5829. };
  5830. static const char * const rx_prim_mix_text[] = {
  5831. "ZERO", "DEC0", "DEC1", "IIR0", "IIR1", "RX0", "RX1", "RX2",
  5832. "RX3", "RX4", "RX5", "RX6", "RX7"
  5833. };
  5834. static const char * const rx_sidetone_mix_text[] = {
  5835. "ZERO", "SRC0", "SRC1", "SRC_SUM"
  5836. };
  5837. static const char * const cdc_if_tx0_mux_text[] = {
  5838. "ZERO", "RX_MIX_TX0", "DEC0", "DEC0_192"
  5839. };
  5840. static const char * const cdc_if_tx1_mux_text[] = {
  5841. "ZERO", "RX_MIX_TX1", "DEC1", "DEC1_192"
  5842. };
  5843. static const char * const cdc_if_tx2_mux_text[] = {
  5844. "ZERO", "RX_MIX_TX2", "DEC2", "DEC2_192"
  5845. };
  5846. static const char * const cdc_if_tx3_mux_text[] = {
  5847. "ZERO", "RX_MIX_TX3", "DEC3", "DEC3_192"
  5848. };
  5849. static const char * const cdc_if_tx4_mux_text[] = {
  5850. "ZERO", "RX_MIX_TX4", "DEC4", "DEC4_192"
  5851. };
  5852. static const char * const cdc_if_tx5_mux_text[] = {
  5853. "ZERO", "RX_MIX_TX5", "DEC5", "DEC5_192"
  5854. };
  5855. static const char * const cdc_if_tx6_mux_text[] = {
  5856. "ZERO", "RX_MIX_TX6", "DEC6", "DEC6_192"
  5857. };
  5858. static const char * const cdc_if_tx7_mux_text[] = {
  5859. "ZERO", "RX_MIX_TX7", "DEC7", "DEC7_192"
  5860. };
  5861. static const char * const cdc_if_tx8_mux_text[] = {
  5862. "ZERO", "RX_MIX_TX8", "DEC8", "DEC8_192"
  5863. };
  5864. static const char * const cdc_if_tx9_mux_text[] = {
  5865. "ZERO", "DEC7", "DEC7_192"
  5866. };
  5867. static const char * const cdc_if_tx10_mux_text[] = {
  5868. "ZERO", "DEC6", "DEC6_192"
  5869. };
  5870. static const char * const cdc_if_tx11_mux_text[] = {
  5871. "DEC_0_5", "DEC_9_12", "MAD_AUDIO", "MAD_BRDCST"
  5872. };
  5873. static const char * const cdc_if_tx11_inp1_mux_text[] = {
  5874. "ZERO", "DEC0", "DEC1", "DEC2", "DEC3", "DEC4",
  5875. "DEC5", "RX_MIX_TX5", "DEC9_10", "DEC11_12"
  5876. };
  5877. static const char * const cdc_if_tx13_mux_text[] = {
  5878. "CDC_DEC_5", "MAD_BRDCST"
  5879. };
  5880. static const char * const cdc_if_tx13_inp1_mux_text[] = {
  5881. "ZERO", "DEC5", "DEC5_192"
  5882. };
  5883. static const char * const iir_inp_mux_text[] = {
  5884. "ZERO", "DEC0", "DEC1", "DEC2", "DEC3", "DEC4", "DEC5", "DEC6",
  5885. "DEC7", "DEC8", "RX0", "RX1", "RX2", "RX3", "RX4", "RX5", "RX6", "RX7"
  5886. };
  5887. static const char * const rx_int_dem_inp_mux_text[] = {
  5888. "NORMAL_DSM_OUT", "CLSH_DSM_OUT",
  5889. };
  5890. static const char * const rx_int0_1_interp_mux_text[] = {
  5891. "ZERO", "RX INT0_1 MIX1",
  5892. };
  5893. static const char * const rx_int1_1_interp_mux_text[] = {
  5894. "ZERO", "RX INT1_1 MIX1",
  5895. };
  5896. static const char * const rx_int2_1_interp_mux_text[] = {
  5897. "ZERO", "RX INT2_1 MIX1",
  5898. };
  5899. static const char * const rx_int3_1_interp_mux_text[] = {
  5900. "ZERO", "RX INT3_1 MIX1",
  5901. };
  5902. static const char * const rx_int4_1_interp_mux_text[] = {
  5903. "ZERO", "RX INT4_1 MIX1",
  5904. };
  5905. static const char * const rx_int7_1_interp_mux_text[] = {
  5906. "ZERO", "RX INT7_1 MIX1",
  5907. };
  5908. static const char * const rx_int8_1_interp_mux_text[] = {
  5909. "ZERO", "RX INT8_1 MIX1",
  5910. };
  5911. static const char * const rx_int0_2_interp_mux_text[] = {
  5912. "ZERO", "RX INT0_2 MUX",
  5913. };
  5914. static const char * const rx_int1_2_interp_mux_text[] = {
  5915. "ZERO", "RX INT1_2 MUX",
  5916. };
  5917. static const char * const rx_int2_2_interp_mux_text[] = {
  5918. "ZERO", "RX INT2_2 MUX",
  5919. };
  5920. static const char * const rx_int3_2_interp_mux_text[] = {
  5921. "ZERO", "RX INT3_2 MUX",
  5922. };
  5923. static const char * const rx_int4_2_interp_mux_text[] = {
  5924. "ZERO", "RX INT4_2 MUX",
  5925. };
  5926. static const char * const rx_int7_2_interp_mux_text[] = {
  5927. "ZERO", "RX INT7_2 MUX",
  5928. };
  5929. static const char * const rx_int8_2_interp_mux_text[] = {
  5930. "ZERO", "RX INT8_2 MUX",
  5931. };
  5932. static const char * const mad_sel_txt[] = {
  5933. "SPE", "MSM"
  5934. };
  5935. static const char * const mad_inp_mux_txt[] = {
  5936. "MAD", "DEC1"
  5937. };
  5938. static const char * const adc_mux_text[] = {
  5939. "DMIC", "AMIC", "ANC_FB_TUNE1", "ANC_FB_TUNE2"
  5940. };
  5941. static const char * const dmic_mux_text[] = {
  5942. "ZERO", "DMIC0", "DMIC1", "DMIC2", "DMIC3", "DMIC4", "DMIC5"
  5943. };
  5944. static const char * const amic_mux_text[] = {
  5945. "ZERO", "ADC1", "ADC2", "ADC3", "ADC4"
  5946. };
  5947. static const char * const amic4_5_sel_text[] = {
  5948. "AMIC4", "AMIC5"
  5949. };
  5950. static const char * const anc0_fb_mux_text[] = {
  5951. "ZERO", "ANC_IN_HPHL", "ANC_IN_EAR", "ANC_IN_EAR_SPKR",
  5952. "ANC_IN_LO1"
  5953. };
  5954. static const char * const anc1_fb_mux_text[] = {
  5955. "ZERO", "ANC_IN_HPHR", "ANC_IN_LO2"
  5956. };
  5957. static const char * const rx_echo_mux_text[] = {
  5958. "ZERO", "RX_MIX0", "RX_MIX1", "RX_MIX2", "RX_MIX3", "RX_MIX4",
  5959. "RX_MIX5", "RX_MIX6", "RX_MIX7", "RX_MIX8"
  5960. };
  5961. static const char *const slim_rx_mux_text[] = {
  5962. "ZERO", "AIF1_PB", "AIF2_PB", "AIF3_PB", "AIF4_PB"
  5963. };
  5964. static const char *const i2s_rx01_mux_text[] = {
  5965. "ZERO", "AIF1_PB", "AIF2_PB", "AIF3_PB"
  5966. };
  5967. static const char *const i2s_rx23_mux_text[] = {
  5968. "ZERO", "AIF1_PB", "AIF2_PB", "AIF3_PB"
  5969. };
  5970. static const char *const i2s_rx45_mux_text[] = {
  5971. "ZERO", "AIF1_PB", "AIF2_PB", "AIF3_PB"
  5972. };
  5973. static const char *const i2s_rx67_mux_text[] = {
  5974. "ZERO", "AIF1_PB", "AIF2_PB", "AIF3_PB"
  5975. };
  5976. static const char *const cdc_if_rx0_mux_text[] = {
  5977. "SLIM RX0", "I2S RX0"
  5978. };
  5979. static const char *const cdc_if_rx1_mux_text[] = {
  5980. "SLIM RX1", "I2S RX1"
  5981. };
  5982. static const char *const cdc_if_rx2_mux_text[] = {
  5983. "SLIM RX2", "I2S RX2"
  5984. };
  5985. static const char *const cdc_if_rx3_mux_text[] = {
  5986. "SLIM RX3", "I2S RX3"
  5987. };
  5988. static const char *const cdc_if_rx4_mux_text[] = {
  5989. "SLIM RX4", "I2S RX4"
  5990. };
  5991. static const char *const cdc_if_rx5_mux_text[] = {
  5992. "SLIM RX5", "I2S RX5"
  5993. };
  5994. static const char *const cdc_if_rx6_mux_text[] = {
  5995. "SLIM RX6", "I2S RX6"
  5996. };
  5997. static const char *const cdc_if_rx7_mux_text[] = {
  5998. "SLIM RX7", "I2S RX7"
  5999. };
  6000. static const char * const asrc0_mux_text[] = {
  6001. "ZERO", "ASRC_IN_HPHL", "ASRC_IN_LO1",
  6002. };
  6003. static const char * const asrc1_mux_text[] = {
  6004. "ZERO", "ASRC_IN_HPHR", "ASRC_IN_LO2",
  6005. };
  6006. static const char * const asrc2_mux_text[] = {
  6007. "ZERO", "ASRC_IN_SPKR1",
  6008. };
  6009. static const char * const asrc3_mux_text[] = {
  6010. "ZERO", "ASRC_IN_SPKR2",
  6011. };
  6012. static const char * const native_mux_text[] = {
  6013. "OFF", "ON",
  6014. };
  6015. static const char *const wdma3_port0_text[] = {
  6016. "RX_MIX_TX0", "DEC0"
  6017. };
  6018. static const char *const wdma3_port1_text[] = {
  6019. "RX_MIX_TX1", "DEC1"
  6020. };
  6021. static const char *const wdma3_port2_text[] = {
  6022. "RX_MIX_TX2", "DEC2"
  6023. };
  6024. static const char *const wdma3_port3_text[] = {
  6025. "RX_MIX_TX3", "DEC3"
  6026. };
  6027. static const char *const wdma3_port4_text[] = {
  6028. "RX_MIX_TX4", "DEC4"
  6029. };
  6030. static const char *const wdma3_port5_text[] = {
  6031. "RX_MIX_TX5", "DEC5"
  6032. };
  6033. static const char *const wdma3_port6_text[] = {
  6034. "RX_MIX_TX6", "DEC6"
  6035. };
  6036. static const char *const wdma3_ch_text[] = {
  6037. "PORT_0", "PORT_1", "PORT_2", "PORT_3", "PORT_4",
  6038. "PORT_5", "PORT_6", "PORT_7", "PORT_8",
  6039. };
  6040. static const struct snd_kcontrol_new aif4_vi_mixer[] = {
  6041. SOC_SINGLE_EXT("SPKR_VI_1", SND_SOC_NOPM, WCD934X_TX14, 1, 0,
  6042. tavil_vi_feed_mixer_get, tavil_vi_feed_mixer_put),
  6043. SOC_SINGLE_EXT("SPKR_VI_2", SND_SOC_NOPM, WCD934X_TX15, 1, 0,
  6044. tavil_vi_feed_mixer_get, tavil_vi_feed_mixer_put),
  6045. };
  6046. static const struct snd_kcontrol_new aif1_slim_cap_mixer[] = {
  6047. SOC_SINGLE_EXT("SLIM TX0", SND_SOC_NOPM, WCD934X_TX0, 1, 0,
  6048. slim_tx_mixer_get, slim_tx_mixer_put),
  6049. SOC_SINGLE_EXT("SLIM TX1", SND_SOC_NOPM, WCD934X_TX1, 1, 0,
  6050. slim_tx_mixer_get, slim_tx_mixer_put),
  6051. SOC_SINGLE_EXT("SLIM TX2", SND_SOC_NOPM, WCD934X_TX2, 1, 0,
  6052. slim_tx_mixer_get, slim_tx_mixer_put),
  6053. SOC_SINGLE_EXT("SLIM TX3", SND_SOC_NOPM, WCD934X_TX3, 1, 0,
  6054. slim_tx_mixer_get, slim_tx_mixer_put),
  6055. SOC_SINGLE_EXT("SLIM TX4", SND_SOC_NOPM, WCD934X_TX4, 1, 0,
  6056. slim_tx_mixer_get, slim_tx_mixer_put),
  6057. SOC_SINGLE_EXT("SLIM TX5", SND_SOC_NOPM, WCD934X_TX5, 1, 0,
  6058. slim_tx_mixer_get, slim_tx_mixer_put),
  6059. SOC_SINGLE_EXT("SLIM TX6", SND_SOC_NOPM, WCD934X_TX6, 1, 0,
  6060. slim_tx_mixer_get, slim_tx_mixer_put),
  6061. SOC_SINGLE_EXT("SLIM TX7", SND_SOC_NOPM, WCD934X_TX7, 1, 0,
  6062. slim_tx_mixer_get, slim_tx_mixer_put),
  6063. SOC_SINGLE_EXT("SLIM TX8", SND_SOC_NOPM, WCD934X_TX8, 1, 0,
  6064. slim_tx_mixer_get, slim_tx_mixer_put),
  6065. SOC_SINGLE_EXT("SLIM TX9", SND_SOC_NOPM, WCD934X_TX9, 1, 0,
  6066. slim_tx_mixer_get, slim_tx_mixer_put),
  6067. SOC_SINGLE_EXT("SLIM TX10", SND_SOC_NOPM, WCD934X_TX10, 1, 0,
  6068. slim_tx_mixer_get, slim_tx_mixer_put),
  6069. SOC_SINGLE_EXT("SLIM TX11", SND_SOC_NOPM, WCD934X_TX11, 1, 0,
  6070. slim_tx_mixer_get, slim_tx_mixer_put),
  6071. SOC_SINGLE_EXT("SLIM TX13", SND_SOC_NOPM, WCD934X_TX13, 1, 0,
  6072. slim_tx_mixer_get, slim_tx_mixer_put),
  6073. };
  6074. static const struct snd_kcontrol_new aif1_i2s_cap_mixer[] = {
  6075. SOC_SINGLE_EXT("I2S TX1", SND_SOC_NOPM, WCD934X_TX1, 1, 0,
  6076. i2s_tx_mixer_get, i2s_tx_mixer_put),
  6077. SOC_SINGLE_EXT("I2S TX2", SND_SOC_NOPM, WCD934X_TX2, 1, 0,
  6078. i2s_tx_mixer_get, i2s_tx_mixer_put),
  6079. SOC_SINGLE_EXT("I2S TX3", SND_SOC_NOPM, WCD934X_TX3, 1, 0,
  6080. i2s_tx_mixer_get, i2s_tx_mixer_put),
  6081. SOC_SINGLE_EXT("I2S TX4", SND_SOC_NOPM, WCD934X_TX4, 1, 0,
  6082. i2s_tx_mixer_get, i2s_tx_mixer_put),
  6083. SOC_SINGLE_EXT("I2S TX5", SND_SOC_NOPM, WCD934X_TX5, 1, 0,
  6084. i2s_tx_mixer_get, i2s_tx_mixer_put),
  6085. SOC_SINGLE_EXT("I2S TX6", SND_SOC_NOPM, WCD934X_TX6, 1, 0,
  6086. i2s_tx_mixer_get, i2s_tx_mixer_put),
  6087. SOC_SINGLE_EXT("I2S TX7", SND_SOC_NOPM, WCD934X_TX7, 1, 0,
  6088. i2s_tx_mixer_get, i2s_tx_mixer_put),
  6089. };
  6090. static const struct snd_kcontrol_new aif2_slim_cap_mixer[] = {
  6091. SOC_SINGLE_EXT("SLIM TX0", SND_SOC_NOPM, WCD934X_TX0, 1, 0,
  6092. slim_tx_mixer_get, slim_tx_mixer_put),
  6093. SOC_SINGLE_EXT("SLIM TX1", SND_SOC_NOPM, WCD934X_TX1, 1, 0,
  6094. slim_tx_mixer_get, slim_tx_mixer_put),
  6095. SOC_SINGLE_EXT("SLIM TX2", SND_SOC_NOPM, WCD934X_TX2, 1, 0,
  6096. slim_tx_mixer_get, slim_tx_mixer_put),
  6097. SOC_SINGLE_EXT("SLIM TX3", SND_SOC_NOPM, WCD934X_TX3, 1, 0,
  6098. slim_tx_mixer_get, slim_tx_mixer_put),
  6099. SOC_SINGLE_EXT("SLIM TX4", SND_SOC_NOPM, WCD934X_TX4, 1, 0,
  6100. slim_tx_mixer_get, slim_tx_mixer_put),
  6101. SOC_SINGLE_EXT("SLIM TX5", SND_SOC_NOPM, WCD934X_TX5, 1, 0,
  6102. slim_tx_mixer_get, slim_tx_mixer_put),
  6103. SOC_SINGLE_EXT("SLIM TX6", SND_SOC_NOPM, WCD934X_TX6, 1, 0,
  6104. slim_tx_mixer_get, slim_tx_mixer_put),
  6105. SOC_SINGLE_EXT("SLIM TX7", SND_SOC_NOPM, WCD934X_TX7, 1, 0,
  6106. slim_tx_mixer_get, slim_tx_mixer_put),
  6107. SOC_SINGLE_EXT("SLIM TX8", SND_SOC_NOPM, WCD934X_TX8, 1, 0,
  6108. slim_tx_mixer_get, slim_tx_mixer_put),
  6109. SOC_SINGLE_EXT("SLIM TX9", SND_SOC_NOPM, WCD934X_TX9, 1, 0,
  6110. slim_tx_mixer_get, slim_tx_mixer_put),
  6111. SOC_SINGLE_EXT("SLIM TX10", SND_SOC_NOPM, WCD934X_TX10, 1, 0,
  6112. slim_tx_mixer_get, slim_tx_mixer_put),
  6113. SOC_SINGLE_EXT("SLIM TX11", SND_SOC_NOPM, WCD934X_TX11, 1, 0,
  6114. slim_tx_mixer_get, slim_tx_mixer_put),
  6115. SOC_SINGLE_EXT("SLIM TX13", SND_SOC_NOPM, WCD934X_TX13, 1, 0,
  6116. slim_tx_mixer_get, slim_tx_mixer_put),
  6117. };
  6118. static const struct snd_kcontrol_new aif2_i2s_cap_mixer[] = {
  6119. SOC_SINGLE_EXT("I2S TX8", SND_SOC_NOPM, WCD934X_TX8, 1, 0,
  6120. i2s_tx_mixer_get, i2s_tx_mixer_put),
  6121. SOC_SINGLE_EXT("I2S TX11", SND_SOC_NOPM, WCD934X_TX11, 1, 0,
  6122. i2s_tx_mixer_get, i2s_tx_mixer_put),
  6123. };
  6124. static const struct snd_kcontrol_new aif3_slim_cap_mixer[] = {
  6125. SOC_SINGLE_EXT("SLIM TX0", SND_SOC_NOPM, WCD934X_TX0, 1, 0,
  6126. slim_tx_mixer_get, slim_tx_mixer_put),
  6127. SOC_SINGLE_EXT("SLIM TX1", SND_SOC_NOPM, WCD934X_TX1, 1, 0,
  6128. slim_tx_mixer_get, slim_tx_mixer_put),
  6129. SOC_SINGLE_EXT("SLIM TX2", SND_SOC_NOPM, WCD934X_TX2, 1, 0,
  6130. slim_tx_mixer_get, slim_tx_mixer_put),
  6131. SOC_SINGLE_EXT("SLIM TX3", SND_SOC_NOPM, WCD934X_TX3, 1, 0,
  6132. slim_tx_mixer_get, slim_tx_mixer_put),
  6133. SOC_SINGLE_EXT("SLIM TX4", SND_SOC_NOPM, WCD934X_TX4, 1, 0,
  6134. slim_tx_mixer_get, slim_tx_mixer_put),
  6135. SOC_SINGLE_EXT("SLIM TX5", SND_SOC_NOPM, WCD934X_TX5, 1, 0,
  6136. slim_tx_mixer_get, slim_tx_mixer_put),
  6137. SOC_SINGLE_EXT("SLIM TX6", SND_SOC_NOPM, WCD934X_TX6, 1, 0,
  6138. slim_tx_mixer_get, slim_tx_mixer_put),
  6139. SOC_SINGLE_EXT("SLIM TX7", SND_SOC_NOPM, WCD934X_TX7, 1, 0,
  6140. slim_tx_mixer_get, slim_tx_mixer_put),
  6141. SOC_SINGLE_EXT("SLIM TX8", SND_SOC_NOPM, WCD934X_TX8, 1, 0,
  6142. slim_tx_mixer_get, slim_tx_mixer_put),
  6143. SOC_SINGLE_EXT("SLIM TX9", SND_SOC_NOPM, WCD934X_TX9, 1, 0,
  6144. slim_tx_mixer_get, slim_tx_mixer_put),
  6145. SOC_SINGLE_EXT("SLIM TX10", SND_SOC_NOPM, WCD934X_TX10, 1, 0,
  6146. slim_tx_mixer_get, slim_tx_mixer_put),
  6147. SOC_SINGLE_EXT("SLIM TX11", SND_SOC_NOPM, WCD934X_TX11, 1, 0,
  6148. slim_tx_mixer_get, slim_tx_mixer_put),
  6149. SOC_SINGLE_EXT("SLIM TX13", SND_SOC_NOPM, WCD934X_TX13, 1, 0,
  6150. slim_tx_mixer_get, slim_tx_mixer_put),
  6151. };
  6152. static const struct snd_kcontrol_new aif3_i2s_cap_mixer[] = {
  6153. SOC_SINGLE_EXT("I2S TX0", SND_SOC_NOPM, WCD934X_TX0, 1, 0,
  6154. i2s_tx_mixer_get, i2s_tx_mixer_put),
  6155. SOC_SINGLE_EXT("I2S TX1", SND_SOC_NOPM, WCD934X_TX1, 1, 0,
  6156. i2s_tx_mixer_get, i2s_tx_mixer_put),
  6157. };
  6158. static const struct snd_kcontrol_new aif4_slim_mad_mixer[] = {
  6159. SOC_SINGLE_EXT("SLIM TX13", SND_SOC_NOPM, WCD934X_TX13, 1, 0,
  6160. slim_tx_mixer_get, slim_tx_mixer_put),
  6161. };
  6162. WCD_DAPM_ENUM_EXT(slim_rx0, SND_SOC_NOPM, 0, slim_rx_mux_text,
  6163. slim_rx_mux_get, slim_rx_mux_put);
  6164. WCD_DAPM_ENUM_EXT(slim_rx1, SND_SOC_NOPM, 0, slim_rx_mux_text,
  6165. slim_rx_mux_get, slim_rx_mux_put);
  6166. WCD_DAPM_ENUM_EXT(slim_rx2, SND_SOC_NOPM, 0, slim_rx_mux_text,
  6167. slim_rx_mux_get, slim_rx_mux_put);
  6168. WCD_DAPM_ENUM_EXT(slim_rx3, SND_SOC_NOPM, 0, slim_rx_mux_text,
  6169. slim_rx_mux_get, slim_rx_mux_put);
  6170. WCD_DAPM_ENUM_EXT(slim_rx4, SND_SOC_NOPM, 0, slim_rx_mux_text,
  6171. slim_rx_mux_get, slim_rx_mux_put);
  6172. WCD_DAPM_ENUM_EXT(slim_rx5, SND_SOC_NOPM, 0, slim_rx_mux_text,
  6173. slim_rx_mux_get, slim_rx_mux_put);
  6174. WCD_DAPM_ENUM_EXT(slim_rx6, SND_SOC_NOPM, 0, slim_rx_mux_text,
  6175. slim_rx_mux_get, slim_rx_mux_put);
  6176. WCD_DAPM_ENUM_EXT(slim_rx7, SND_SOC_NOPM, 0, slim_rx_mux_text,
  6177. slim_rx_mux_get, slim_rx_mux_put);
  6178. WCD_DAPM_ENUM(cdc_if_rx0, SND_SOC_NOPM, 0, cdc_if_rx0_mux_text);
  6179. WCD_DAPM_ENUM(cdc_if_rx1, SND_SOC_NOPM, 0, cdc_if_rx1_mux_text);
  6180. WCD_DAPM_ENUM(cdc_if_rx2, SND_SOC_NOPM, 0, cdc_if_rx2_mux_text);
  6181. WCD_DAPM_ENUM(cdc_if_rx3, SND_SOC_NOPM, 0, cdc_if_rx3_mux_text);
  6182. WCD_DAPM_ENUM(cdc_if_rx4, SND_SOC_NOPM, 0, cdc_if_rx4_mux_text);
  6183. WCD_DAPM_ENUM(cdc_if_rx5, SND_SOC_NOPM, 0, cdc_if_rx5_mux_text);
  6184. WCD_DAPM_ENUM(cdc_if_rx6, SND_SOC_NOPM, 0, cdc_if_rx6_mux_text);
  6185. WCD_DAPM_ENUM(cdc_if_rx7, SND_SOC_NOPM, 0, cdc_if_rx7_mux_text);
  6186. WCD_DAPM_ENUM(rx_int0_2, WCD934X_CDC_RX_INP_MUX_RX_INT0_CFG1, 0,
  6187. rx_int0_7_mix_mux_text);
  6188. WCD_DAPM_ENUM(rx_int1_2, WCD934X_CDC_RX_INP_MUX_RX_INT1_CFG1, 0,
  6189. rx_int_mix_mux_text);
  6190. WCD_DAPM_ENUM(rx_int2_2, WCD934X_CDC_RX_INP_MUX_RX_INT2_CFG1, 0,
  6191. rx_int_mix_mux_text);
  6192. WCD_DAPM_ENUM(rx_int3_2, WCD934X_CDC_RX_INP_MUX_RX_INT3_CFG1, 0,
  6193. rx_int_mix_mux_text);
  6194. WCD_DAPM_ENUM(rx_int4_2, WCD934X_CDC_RX_INP_MUX_RX_INT4_CFG1, 0,
  6195. rx_int_mix_mux_text);
  6196. WCD_DAPM_ENUM(rx_int7_2, WCD934X_CDC_RX_INP_MUX_RX_INT7_CFG1, 0,
  6197. rx_int0_7_mix_mux_text);
  6198. WCD_DAPM_ENUM(rx_int8_2, WCD934X_CDC_RX_INP_MUX_RX_INT8_CFG1, 0,
  6199. rx_int_mix_mux_text);
  6200. WCD_DAPM_ENUM(rx_int0_1_mix_inp0, WCD934X_CDC_RX_INP_MUX_RX_INT0_CFG0, 0,
  6201. rx_prim_mix_text);
  6202. WCD_DAPM_ENUM(rx_int0_1_mix_inp1, WCD934X_CDC_RX_INP_MUX_RX_INT0_CFG0, 4,
  6203. rx_prim_mix_text);
  6204. WCD_DAPM_ENUM(rx_int0_1_mix_inp2, WCD934X_CDC_RX_INP_MUX_RX_INT0_CFG1, 4,
  6205. rx_prim_mix_text);
  6206. WCD_DAPM_ENUM(rx_int1_1_mix_inp0, WCD934X_CDC_RX_INP_MUX_RX_INT1_CFG0, 0,
  6207. rx_prim_mix_text);
  6208. WCD_DAPM_ENUM(rx_int1_1_mix_inp1, WCD934X_CDC_RX_INP_MUX_RX_INT1_CFG0, 4,
  6209. rx_prim_mix_text);
  6210. WCD_DAPM_ENUM(rx_int1_1_mix_inp2, WCD934X_CDC_RX_INP_MUX_RX_INT1_CFG1, 4,
  6211. rx_prim_mix_text);
  6212. WCD_DAPM_ENUM(rx_int2_1_mix_inp0, WCD934X_CDC_RX_INP_MUX_RX_INT2_CFG0, 0,
  6213. rx_prim_mix_text);
  6214. WCD_DAPM_ENUM(rx_int2_1_mix_inp1, WCD934X_CDC_RX_INP_MUX_RX_INT2_CFG0, 4,
  6215. rx_prim_mix_text);
  6216. WCD_DAPM_ENUM(rx_int2_1_mix_inp2, WCD934X_CDC_RX_INP_MUX_RX_INT2_CFG1, 4,
  6217. rx_prim_mix_text);
  6218. WCD_DAPM_ENUM(rx_int3_1_mix_inp0, WCD934X_CDC_RX_INP_MUX_RX_INT3_CFG0, 0,
  6219. rx_prim_mix_text);
  6220. WCD_DAPM_ENUM(rx_int3_1_mix_inp1, WCD934X_CDC_RX_INP_MUX_RX_INT3_CFG0, 4,
  6221. rx_prim_mix_text);
  6222. WCD_DAPM_ENUM(rx_int3_1_mix_inp2, WCD934X_CDC_RX_INP_MUX_RX_INT3_CFG1, 4,
  6223. rx_prim_mix_text);
  6224. WCD_DAPM_ENUM(rx_int4_1_mix_inp0, WCD934X_CDC_RX_INP_MUX_RX_INT4_CFG0, 0,
  6225. rx_prim_mix_text);
  6226. WCD_DAPM_ENUM(rx_int4_1_mix_inp1, WCD934X_CDC_RX_INP_MUX_RX_INT4_CFG0, 4,
  6227. rx_prim_mix_text);
  6228. WCD_DAPM_ENUM(rx_int4_1_mix_inp2, WCD934X_CDC_RX_INP_MUX_RX_INT4_CFG1, 4,
  6229. rx_prim_mix_text);
  6230. WCD_DAPM_ENUM(rx_int7_1_mix_inp0, WCD934X_CDC_RX_INP_MUX_RX_INT7_CFG0, 0,
  6231. rx_prim_mix_text);
  6232. WCD_DAPM_ENUM(rx_int7_1_mix_inp1, WCD934X_CDC_RX_INP_MUX_RX_INT7_CFG0, 4,
  6233. rx_prim_mix_text);
  6234. WCD_DAPM_ENUM(rx_int7_1_mix_inp2, WCD934X_CDC_RX_INP_MUX_RX_INT7_CFG1, 4,
  6235. rx_prim_mix_text);
  6236. WCD_DAPM_ENUM(rx_int8_1_mix_inp0, WCD934X_CDC_RX_INP_MUX_RX_INT8_CFG0, 0,
  6237. rx_prim_mix_text);
  6238. WCD_DAPM_ENUM(rx_int8_1_mix_inp1, WCD934X_CDC_RX_INP_MUX_RX_INT8_CFG0, 4,
  6239. rx_prim_mix_text);
  6240. WCD_DAPM_ENUM(rx_int8_1_mix_inp2, WCD934X_CDC_RX_INP_MUX_RX_INT8_CFG1, 4,
  6241. rx_prim_mix_text);
  6242. WCD_DAPM_ENUM(rx_int0_mix2_inp, WCD934X_CDC_RX_INP_MUX_SIDETONE_SRC_CFG0, 0,
  6243. rx_sidetone_mix_text);
  6244. WCD_DAPM_ENUM(rx_int1_mix2_inp, WCD934X_CDC_RX_INP_MUX_SIDETONE_SRC_CFG0, 2,
  6245. rx_sidetone_mix_text);
  6246. WCD_DAPM_ENUM(rx_int2_mix2_inp, WCD934X_CDC_RX_INP_MUX_SIDETONE_SRC_CFG0, 4,
  6247. rx_sidetone_mix_text);
  6248. WCD_DAPM_ENUM(rx_int3_mix2_inp, WCD934X_CDC_RX_INP_MUX_SIDETONE_SRC_CFG0, 6,
  6249. rx_sidetone_mix_text);
  6250. WCD_DAPM_ENUM(rx_int4_mix2_inp, WCD934X_CDC_RX_INP_MUX_SIDETONE_SRC_CFG1, 0,
  6251. rx_sidetone_mix_text);
  6252. WCD_DAPM_ENUM(rx_int7_mix2_inp, WCD934X_CDC_RX_INP_MUX_SIDETONE_SRC_CFG1, 2,
  6253. rx_sidetone_mix_text);
  6254. WCD_DAPM_ENUM(tx_adc_mux10, WCD934X_CDC_TX_INP_MUX_ADC_MUX1_CFG1, 4,
  6255. adc_mux_text);
  6256. WCD_DAPM_ENUM(tx_adc_mux11, WCD934X_CDC_TX_INP_MUX_ADC_MUX2_CFG1, 4,
  6257. adc_mux_text);
  6258. WCD_DAPM_ENUM(tx_adc_mux12, WCD934X_CDC_TX_INP_MUX_ADC_MUX3_CFG1, 4,
  6259. adc_mux_text);
  6260. WCD_DAPM_ENUM(tx_adc_mux13, WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG1, 6,
  6261. adc_mux_text);
  6262. WCD_DAPM_ENUM(tx_dmic_mux0, WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG0, 3,
  6263. dmic_mux_text);
  6264. WCD_DAPM_ENUM(tx_dmic_mux1, WCD934X_CDC_TX_INP_MUX_ADC_MUX1_CFG0, 3,
  6265. dmic_mux_text);
  6266. WCD_DAPM_ENUM(tx_dmic_mux2, WCD934X_CDC_TX_INP_MUX_ADC_MUX2_CFG0, 3,
  6267. dmic_mux_text);
  6268. WCD_DAPM_ENUM(tx_dmic_mux3, WCD934X_CDC_TX_INP_MUX_ADC_MUX3_CFG0, 3,
  6269. dmic_mux_text);
  6270. WCD_DAPM_ENUM(tx_dmic_mux4, WCD934X_CDC_TX_INP_MUX_ADC_MUX4_CFG0, 3,
  6271. dmic_mux_text);
  6272. WCD_DAPM_ENUM(tx_dmic_mux5, WCD934X_CDC_TX_INP_MUX_ADC_MUX5_CFG0, 3,
  6273. dmic_mux_text);
  6274. WCD_DAPM_ENUM(tx_dmic_mux6, WCD934X_CDC_TX_INP_MUX_ADC_MUX6_CFG0, 3,
  6275. dmic_mux_text);
  6276. WCD_DAPM_ENUM(tx_dmic_mux7, WCD934X_CDC_TX_INP_MUX_ADC_MUX7_CFG0, 3,
  6277. dmic_mux_text);
  6278. WCD_DAPM_ENUM(tx_dmic_mux8, WCD934X_CDC_TX_INP_MUX_ADC_MUX8_CFG0, 3,
  6279. dmic_mux_text);
  6280. WCD_DAPM_ENUM(tx_dmic_mux10, WCD934X_CDC_TX_INP_MUX_ADC_MUX10_CFG0, 3,
  6281. dmic_mux_text);
  6282. WCD_DAPM_ENUM(tx_dmic_mux11, WCD934X_CDC_TX_INP_MUX_ADC_MUX11_CFG0, 3,
  6283. dmic_mux_text);
  6284. WCD_DAPM_ENUM(tx_dmic_mux12, WCD934X_CDC_TX_INP_MUX_ADC_MUX12_CFG0, 3,
  6285. dmic_mux_text);
  6286. WCD_DAPM_ENUM(tx_dmic_mux13, WCD934X_CDC_TX_INP_MUX_ADC_MUX13_CFG0, 3,
  6287. dmic_mux_text);
  6288. WCD_DAPM_ENUM(tx_amic_mux0, WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG0, 0,
  6289. amic_mux_text);
  6290. WCD_DAPM_ENUM(tx_amic_mux1, WCD934X_CDC_TX_INP_MUX_ADC_MUX1_CFG0, 0,
  6291. amic_mux_text);
  6292. WCD_DAPM_ENUM(tx_amic_mux2, WCD934X_CDC_TX_INP_MUX_ADC_MUX2_CFG0, 0,
  6293. amic_mux_text);
  6294. WCD_DAPM_ENUM(tx_amic_mux3, WCD934X_CDC_TX_INP_MUX_ADC_MUX3_CFG0, 0,
  6295. amic_mux_text);
  6296. WCD_DAPM_ENUM(tx_amic_mux4, WCD934X_CDC_TX_INP_MUX_ADC_MUX4_CFG0, 0,
  6297. amic_mux_text);
  6298. WCD_DAPM_ENUM(tx_amic_mux5, WCD934X_CDC_TX_INP_MUX_ADC_MUX5_CFG0, 0,
  6299. amic_mux_text);
  6300. WCD_DAPM_ENUM(tx_amic_mux6, WCD934X_CDC_TX_INP_MUX_ADC_MUX6_CFG0, 0,
  6301. amic_mux_text);
  6302. WCD_DAPM_ENUM(tx_amic_mux7, WCD934X_CDC_TX_INP_MUX_ADC_MUX7_CFG0, 0,
  6303. amic_mux_text);
  6304. WCD_DAPM_ENUM(tx_amic_mux8, WCD934X_CDC_TX_INP_MUX_ADC_MUX8_CFG0, 0,
  6305. amic_mux_text);
  6306. WCD_DAPM_ENUM(tx_amic_mux10, WCD934X_CDC_TX_INP_MUX_ADC_MUX10_CFG0, 0,
  6307. amic_mux_text);
  6308. WCD_DAPM_ENUM(tx_amic_mux11, WCD934X_CDC_TX_INP_MUX_ADC_MUX11_CFG0, 0,
  6309. amic_mux_text);
  6310. WCD_DAPM_ENUM(tx_amic_mux12, WCD934X_CDC_TX_INP_MUX_ADC_MUX12_CFG0, 0,
  6311. amic_mux_text);
  6312. WCD_DAPM_ENUM(tx_amic_mux13, WCD934X_CDC_TX_INP_MUX_ADC_MUX13_CFG0, 0,
  6313. amic_mux_text);
  6314. WCD_DAPM_ENUM(tx_amic4_5, WCD934X_TX_NEW_AMIC_4_5_SEL, 7, amic4_5_sel_text);
  6315. WCD_DAPM_ENUM(cdc_if_tx0, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG0, 0,
  6316. cdc_if_tx0_mux_text);
  6317. WCD_DAPM_ENUM(cdc_if_tx1, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG0, 2,
  6318. cdc_if_tx1_mux_text);
  6319. WCD_DAPM_ENUM(cdc_if_tx2, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG0, 4,
  6320. cdc_if_tx2_mux_text);
  6321. WCD_DAPM_ENUM(cdc_if_tx3, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG0, 6,
  6322. cdc_if_tx3_mux_text);
  6323. WCD_DAPM_ENUM(cdc_if_tx4, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG1, 0,
  6324. cdc_if_tx4_mux_text);
  6325. WCD_DAPM_ENUM(cdc_if_tx5, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG1, 2,
  6326. cdc_if_tx5_mux_text);
  6327. WCD_DAPM_ENUM(cdc_if_tx6, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG1, 4,
  6328. cdc_if_tx6_mux_text);
  6329. WCD_DAPM_ENUM(cdc_if_tx7, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG1, 6,
  6330. cdc_if_tx7_mux_text);
  6331. WCD_DAPM_ENUM(cdc_if_tx8, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG2, 0,
  6332. cdc_if_tx8_mux_text);
  6333. WCD_DAPM_ENUM(cdc_if_tx9, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG2, 2,
  6334. cdc_if_tx9_mux_text);
  6335. WCD_DAPM_ENUM(cdc_if_tx10, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG2, 4,
  6336. cdc_if_tx10_mux_text);
  6337. WCD_DAPM_ENUM(cdc_if_tx11_inp1, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG3, 0,
  6338. cdc_if_tx11_inp1_mux_text);
  6339. WCD_DAPM_ENUM(cdc_if_tx11, WCD934X_DATA_HUB_SB_TX11_INP_CFG, 0,
  6340. cdc_if_tx11_mux_text);
  6341. WCD_DAPM_ENUM(cdc_if_tx13_inp1, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG3, 4,
  6342. cdc_if_tx13_inp1_mux_text);
  6343. WCD_DAPM_ENUM(cdc_if_tx13, WCD934X_DATA_HUB_SB_TX13_INP_CFG, 0,
  6344. cdc_if_tx13_mux_text);
  6345. WCD_DAPM_ENUM(rx_mix_tx0, WCD934X_CDC_RX_INP_MUX_RX_MIX_CFG0, 0,
  6346. rx_echo_mux_text);
  6347. WCD_DAPM_ENUM(rx_mix_tx1, WCD934X_CDC_RX_INP_MUX_RX_MIX_CFG0, 4,
  6348. rx_echo_mux_text);
  6349. WCD_DAPM_ENUM(rx_mix_tx2, WCD934X_CDC_RX_INP_MUX_RX_MIX_CFG1, 0,
  6350. rx_echo_mux_text);
  6351. WCD_DAPM_ENUM(rx_mix_tx3, WCD934X_CDC_RX_INP_MUX_RX_MIX_CFG1, 4,
  6352. rx_echo_mux_text);
  6353. WCD_DAPM_ENUM(rx_mix_tx4, WCD934X_CDC_RX_INP_MUX_RX_MIX_CFG2, 0,
  6354. rx_echo_mux_text);
  6355. WCD_DAPM_ENUM(rx_mix_tx5, WCD934X_CDC_RX_INP_MUX_RX_MIX_CFG2, 4,
  6356. rx_echo_mux_text);
  6357. WCD_DAPM_ENUM(rx_mix_tx6, WCD934X_CDC_RX_INP_MUX_RX_MIX_CFG3, 0,
  6358. rx_echo_mux_text);
  6359. WCD_DAPM_ENUM(rx_mix_tx7, WCD934X_CDC_RX_INP_MUX_RX_MIX_CFG3, 4,
  6360. rx_echo_mux_text);
  6361. WCD_DAPM_ENUM(rx_mix_tx8, WCD934X_CDC_RX_INP_MUX_RX_MIX_CFG4, 0,
  6362. rx_echo_mux_text);
  6363. WCD_DAPM_ENUM(iir0_inp0, WCD934X_CDC_SIDETONE_IIR_INP_MUX_IIR0_MIX_CFG0, 0,
  6364. iir_inp_mux_text);
  6365. WCD_DAPM_ENUM(iir0_inp1, WCD934X_CDC_SIDETONE_IIR_INP_MUX_IIR0_MIX_CFG1, 0,
  6366. iir_inp_mux_text);
  6367. WCD_DAPM_ENUM(iir0_inp2, WCD934X_CDC_SIDETONE_IIR_INP_MUX_IIR0_MIX_CFG2, 0,
  6368. iir_inp_mux_text);
  6369. WCD_DAPM_ENUM(iir0_inp3, WCD934X_CDC_SIDETONE_IIR_INP_MUX_IIR0_MIX_CFG3, 0,
  6370. iir_inp_mux_text);
  6371. WCD_DAPM_ENUM(iir1_inp0, WCD934X_CDC_SIDETONE_IIR_INP_MUX_IIR1_MIX_CFG0, 0,
  6372. iir_inp_mux_text);
  6373. WCD_DAPM_ENUM(iir1_inp1, WCD934X_CDC_SIDETONE_IIR_INP_MUX_IIR1_MIX_CFG1, 0,
  6374. iir_inp_mux_text);
  6375. WCD_DAPM_ENUM(iir1_inp2, WCD934X_CDC_SIDETONE_IIR_INP_MUX_IIR1_MIX_CFG2, 0,
  6376. iir_inp_mux_text);
  6377. WCD_DAPM_ENUM(iir1_inp3, WCD934X_CDC_SIDETONE_IIR_INP_MUX_IIR1_MIX_CFG3, 0,
  6378. iir_inp_mux_text);
  6379. WCD_DAPM_ENUM(rx_int0_1_interp, SND_SOC_NOPM, 0, rx_int0_1_interp_mux_text);
  6380. WCD_DAPM_ENUM(rx_int1_1_interp, SND_SOC_NOPM, 0, rx_int1_1_interp_mux_text);
  6381. WCD_DAPM_ENUM(rx_int2_1_interp, SND_SOC_NOPM, 0, rx_int2_1_interp_mux_text);
  6382. WCD_DAPM_ENUM(rx_int3_1_interp, SND_SOC_NOPM, 0, rx_int3_1_interp_mux_text);
  6383. WCD_DAPM_ENUM(rx_int4_1_interp, SND_SOC_NOPM, 0, rx_int4_1_interp_mux_text);
  6384. WCD_DAPM_ENUM(rx_int7_1_interp, SND_SOC_NOPM, 0, rx_int7_1_interp_mux_text);
  6385. WCD_DAPM_ENUM(rx_int8_1_interp, SND_SOC_NOPM, 0, rx_int8_1_interp_mux_text);
  6386. WCD_DAPM_ENUM(rx_int0_2_interp, SND_SOC_NOPM, 0, rx_int0_2_interp_mux_text);
  6387. WCD_DAPM_ENUM(rx_int1_2_interp, SND_SOC_NOPM, 0, rx_int1_2_interp_mux_text);
  6388. WCD_DAPM_ENUM(rx_int2_2_interp, SND_SOC_NOPM, 0, rx_int2_2_interp_mux_text);
  6389. WCD_DAPM_ENUM(rx_int3_2_interp, SND_SOC_NOPM, 0, rx_int3_2_interp_mux_text);
  6390. WCD_DAPM_ENUM(rx_int4_2_interp, SND_SOC_NOPM, 0, rx_int4_2_interp_mux_text);
  6391. WCD_DAPM_ENUM(rx_int7_2_interp, SND_SOC_NOPM, 0, rx_int7_2_interp_mux_text);
  6392. WCD_DAPM_ENUM(rx_int8_2_interp, SND_SOC_NOPM, 0, rx_int8_2_interp_mux_text);
  6393. WCD_DAPM_ENUM(mad_sel, WCD934X_CPE_SS_SVA_CFG, 0,
  6394. mad_sel_txt);
  6395. WCD_DAPM_ENUM(mad_inp_mux, WCD934X_CPE_SS_SVA_CFG, 2,
  6396. mad_inp_mux_txt);
  6397. WCD_DAPM_ENUM_EXT(rx_int0_dem_inp, WCD934X_CDC_RX0_RX_PATH_SEC0, 0,
  6398. rx_int_dem_inp_mux_text, snd_soc_dapm_get_enum_double,
  6399. tavil_int_dem_inp_mux_put);
  6400. WCD_DAPM_ENUM_EXT(rx_int1_dem_inp, WCD934X_CDC_RX1_RX_PATH_SEC0, 0,
  6401. rx_int_dem_inp_mux_text, snd_soc_dapm_get_enum_double,
  6402. tavil_int_dem_inp_mux_put);
  6403. WCD_DAPM_ENUM_EXT(rx_int2_dem_inp, WCD934X_CDC_RX2_RX_PATH_SEC0, 0,
  6404. rx_int_dem_inp_mux_text, snd_soc_dapm_get_enum_double,
  6405. tavil_int_dem_inp_mux_put);
  6406. WCD_DAPM_ENUM_EXT(tx_adc_mux0, WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG1, 0,
  6407. adc_mux_text, snd_soc_dapm_get_enum_double, tavil_dec_enum_put);
  6408. WCD_DAPM_ENUM_EXT(tx_adc_mux1, WCD934X_CDC_TX_INP_MUX_ADC_MUX1_CFG1, 0,
  6409. adc_mux_text, snd_soc_dapm_get_enum_double, tavil_dec_enum_put);
  6410. WCD_DAPM_ENUM_EXT(tx_adc_mux2, WCD934X_CDC_TX_INP_MUX_ADC_MUX2_CFG1, 0,
  6411. adc_mux_text, snd_soc_dapm_get_enum_double, tavil_dec_enum_put);
  6412. WCD_DAPM_ENUM_EXT(tx_adc_mux3, WCD934X_CDC_TX_INP_MUX_ADC_MUX3_CFG1, 0,
  6413. adc_mux_text, snd_soc_dapm_get_enum_double, tavil_dec_enum_put);
  6414. WCD_DAPM_ENUM_EXT(tx_adc_mux4, WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG1, 2,
  6415. adc_mux_text, snd_soc_dapm_get_enum_double, tavil_dec_enum_put);
  6416. WCD_DAPM_ENUM_EXT(tx_adc_mux5, WCD934X_CDC_TX_INP_MUX_ADC_MUX1_CFG1, 2,
  6417. adc_mux_text, snd_soc_dapm_get_enum_double, tavil_dec_enum_put);
  6418. WCD_DAPM_ENUM_EXT(tx_adc_mux6, WCD934X_CDC_TX_INP_MUX_ADC_MUX2_CFG1, 2,
  6419. adc_mux_text, snd_soc_dapm_get_enum_double, tavil_dec_enum_put);
  6420. WCD_DAPM_ENUM_EXT(tx_adc_mux7, WCD934X_CDC_TX_INP_MUX_ADC_MUX3_CFG1, 2,
  6421. adc_mux_text, snd_soc_dapm_get_enum_double, tavil_dec_enum_put);
  6422. WCD_DAPM_ENUM_EXT(tx_adc_mux8, WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG1, 4,
  6423. adc_mux_text, snd_soc_dapm_get_enum_double, tavil_dec_enum_put);
  6424. WCD_DAPM_ENUM(asrc0, WCD934X_CDC_RX_INP_MUX_SPLINE_ASRC_CFG0, 0,
  6425. asrc0_mux_text);
  6426. WCD_DAPM_ENUM(asrc1, WCD934X_CDC_RX_INP_MUX_SPLINE_ASRC_CFG0, 2,
  6427. asrc1_mux_text);
  6428. WCD_DAPM_ENUM(asrc2, WCD934X_CDC_RX_INP_MUX_SPLINE_ASRC_CFG0, 4,
  6429. asrc2_mux_text);
  6430. WCD_DAPM_ENUM(asrc3, WCD934X_CDC_RX_INP_MUX_SPLINE_ASRC_CFG0, 6,
  6431. asrc3_mux_text);
  6432. WCD_DAPM_ENUM(int1_1_native, SND_SOC_NOPM, 0, native_mux_text);
  6433. WCD_DAPM_ENUM(int2_1_native, SND_SOC_NOPM, 0, native_mux_text);
  6434. WCD_DAPM_ENUM(int3_1_native, SND_SOC_NOPM, 0, native_mux_text);
  6435. WCD_DAPM_ENUM(int4_1_native, SND_SOC_NOPM, 0, native_mux_text);
  6436. WCD_DAPM_ENUM(int1_2_native, SND_SOC_NOPM, 0, native_mux_text);
  6437. WCD_DAPM_ENUM(int2_2_native, SND_SOC_NOPM, 0, native_mux_text);
  6438. WCD_DAPM_ENUM(int3_2_native, SND_SOC_NOPM, 0, native_mux_text);
  6439. WCD_DAPM_ENUM(int4_2_native, SND_SOC_NOPM, 0, native_mux_text);
  6440. WCD_DAPM_ENUM(int7_2_native, SND_SOC_NOPM, 0, native_mux_text);
  6441. WCD_DAPM_ENUM(int8_2_native, SND_SOC_NOPM, 0, native_mux_text);
  6442. WCD_DAPM_ENUM(anc0_fb, WCD934X_CDC_RX_INP_MUX_ANC_CFG0, 0, anc0_fb_mux_text);
  6443. WCD_DAPM_ENUM(anc1_fb, WCD934X_CDC_RX_INP_MUX_ANC_CFG0, 3, anc1_fb_mux_text);
  6444. WCD_DAPM_ENUM_EXT(i2s_rx0, SND_SOC_NOPM, 0, i2s_rx01_mux_text,
  6445. i2s_rx_mux_get, i2s_rx_mux_put);
  6446. WCD_DAPM_ENUM_EXT(i2s_rx1, SND_SOC_NOPM, 0, i2s_rx01_mux_text,
  6447. i2s_rx_mux_get, i2s_rx_mux_put);
  6448. WCD_DAPM_ENUM_EXT(i2s_rx2, SND_SOC_NOPM, 0, i2s_rx23_mux_text,
  6449. i2s_rx_mux_get, i2s_rx_mux_put);
  6450. WCD_DAPM_ENUM_EXT(i2s_rx3, SND_SOC_NOPM, 0, i2s_rx23_mux_text,
  6451. i2s_rx_mux_get, i2s_rx_mux_put);
  6452. WCD_DAPM_ENUM_EXT(i2s_rx4, SND_SOC_NOPM, 0, i2s_rx45_mux_text,
  6453. i2s_rx_mux_get, i2s_rx_mux_put);
  6454. WCD_DAPM_ENUM_EXT(i2s_rx5, SND_SOC_NOPM, 0, i2s_rx45_mux_text,
  6455. i2s_rx_mux_get, i2s_rx_mux_put);
  6456. WCD_DAPM_ENUM_EXT(i2s_rx6, SND_SOC_NOPM, 0, i2s_rx67_mux_text,
  6457. i2s_rx_mux_get, i2s_rx_mux_put);
  6458. WCD_DAPM_ENUM_EXT(i2s_rx7, SND_SOC_NOPM, 0, i2s_rx67_mux_text,
  6459. i2s_rx_mux_get, i2s_rx_mux_put);
  6460. WCD_DAPM_ENUM(wdma3_port0, WCD934X_DMA_WDMA3_PRT_CFG, 0, wdma3_port0_text);
  6461. WCD_DAPM_ENUM(wdma3_port1, WCD934X_DMA_WDMA3_PRT_CFG, 1, wdma3_port1_text);
  6462. WCD_DAPM_ENUM(wdma3_port2, WCD934X_DMA_WDMA3_PRT_CFG, 2, wdma3_port2_text);
  6463. WCD_DAPM_ENUM(wdma3_port3, WCD934X_DMA_WDMA3_PRT_CFG, 3, wdma3_port3_text);
  6464. WCD_DAPM_ENUM(wdma3_port4, WCD934X_DMA_WDMA3_PRT_CFG, 4, wdma3_port4_text);
  6465. WCD_DAPM_ENUM(wdma3_port5, WCD934X_DMA_WDMA3_PRT_CFG, 5, wdma3_port5_text);
  6466. WCD_DAPM_ENUM(wdma3_port6, WCD934X_DMA_WDMA3_PRT_CFG, 6, wdma3_port6_text);
  6467. WCD_DAPM_ENUM(wdma3_ch0, WCD934X_DMA_CH_0_1_CFG_WDMA_3, 0, wdma3_ch_text);
  6468. WCD_DAPM_ENUM(wdma3_ch1, WCD934X_DMA_CH_0_1_CFG_WDMA_3, 4, wdma3_ch_text);
  6469. WCD_DAPM_ENUM(wdma3_ch2, WCD934X_DMA_CH_2_3_CFG_WDMA_3, 0, wdma3_ch_text);
  6470. WCD_DAPM_ENUM(wdma3_ch3, WCD934X_DMA_CH_2_3_CFG_WDMA_3, 4, wdma3_ch_text);
  6471. static const struct snd_kcontrol_new anc_ear_switch =
  6472. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0);
  6473. static const struct snd_kcontrol_new anc_ear_spkr_switch =
  6474. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0);
  6475. static const struct snd_kcontrol_new anc_spkr_pa_switch =
  6476. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0);
  6477. static const struct snd_kcontrol_new anc_hphl_pa_switch =
  6478. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0);
  6479. static const struct snd_kcontrol_new anc_hphr_pa_switch =
  6480. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0);
  6481. static const struct snd_kcontrol_new mad_cpe1_switch =
  6482. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0);
  6483. static const struct snd_kcontrol_new mad_cpe2_switch =
  6484. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0);
  6485. static const struct snd_kcontrol_new mad_brdcst_switch =
  6486. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0);
  6487. static const struct snd_kcontrol_new adc_us_mux0_switch =
  6488. SOC_DAPM_SINGLE("US_Switch", SND_SOC_NOPM, 0, 1, 0);
  6489. static const struct snd_kcontrol_new adc_us_mux1_switch =
  6490. SOC_DAPM_SINGLE("US_Switch", SND_SOC_NOPM, 0, 1, 0);
  6491. static const struct snd_kcontrol_new adc_us_mux2_switch =
  6492. SOC_DAPM_SINGLE("US_Switch", SND_SOC_NOPM, 0, 1, 0);
  6493. static const struct snd_kcontrol_new adc_us_mux3_switch =
  6494. SOC_DAPM_SINGLE("US_Switch", SND_SOC_NOPM, 0, 1, 0);
  6495. static const struct snd_kcontrol_new adc_us_mux4_switch =
  6496. SOC_DAPM_SINGLE("US_Switch", SND_SOC_NOPM, 0, 1, 0);
  6497. static const struct snd_kcontrol_new adc_us_mux5_switch =
  6498. SOC_DAPM_SINGLE("US_Switch", SND_SOC_NOPM, 0, 1, 0);
  6499. static const struct snd_kcontrol_new adc_us_mux6_switch =
  6500. SOC_DAPM_SINGLE("US_Switch", SND_SOC_NOPM, 0, 1, 0);
  6501. static const struct snd_kcontrol_new adc_us_mux7_switch =
  6502. SOC_DAPM_SINGLE("US_Switch", SND_SOC_NOPM, 0, 1, 0);
  6503. static const struct snd_kcontrol_new adc_us_mux8_switch =
  6504. SOC_DAPM_SINGLE("US_Switch", SND_SOC_NOPM, 0, 1, 0);
  6505. static const struct snd_kcontrol_new rx_int1_asrc_switch[] = {
  6506. SOC_DAPM_SINGLE("HPHL Switch", SND_SOC_NOPM, 0, 1, 0),
  6507. };
  6508. static const struct snd_kcontrol_new rx_int2_asrc_switch[] = {
  6509. SOC_DAPM_SINGLE("HPHR Switch", SND_SOC_NOPM, 0, 1, 0),
  6510. };
  6511. static const struct snd_kcontrol_new rx_int3_asrc_switch[] = {
  6512. SOC_DAPM_SINGLE("LO1 Switch", SND_SOC_NOPM, 0, 1, 0),
  6513. };
  6514. static const struct snd_kcontrol_new rx_int4_asrc_switch[] = {
  6515. SOC_DAPM_SINGLE("LO2 Switch", SND_SOC_NOPM, 0, 1, 0),
  6516. };
  6517. static const struct snd_kcontrol_new wdma3_onoff_switch =
  6518. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0);
  6519. static const struct snd_soc_dapm_widget tavil_dapm_i2s_widgets[] = {
  6520. SND_SOC_DAPM_MUX_E("I2S RX0 MUX", SND_SOC_NOPM, WCD934X_RX0, 0,
  6521. &i2s_rx0_mux, tavil_codec_enable_i2s_path,
  6522. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6523. SND_SOC_DAPM_POST_PMD),
  6524. SND_SOC_DAPM_MUX_E("I2S RX1 MUX", SND_SOC_NOPM, WCD934X_RX1, 0,
  6525. &i2s_rx1_mux, tavil_codec_enable_i2s_path,
  6526. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6527. SND_SOC_DAPM_POST_PMD),
  6528. SND_SOC_DAPM_MUX_E("I2S RX2 MUX", SND_SOC_NOPM, WCD934X_RX2, 0,
  6529. &i2s_rx2_mux, tavil_codec_enable_i2s_path,
  6530. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6531. SND_SOC_DAPM_POST_PMD),
  6532. SND_SOC_DAPM_MUX_E("I2S RX3 MUX", SND_SOC_NOPM, WCD934X_RX3, 0,
  6533. &i2s_rx3_mux, tavil_codec_enable_i2s_path,
  6534. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6535. SND_SOC_DAPM_POST_PMD),
  6536. SND_SOC_DAPM_MUX_E("I2S RX4 MUX", SND_SOC_NOPM, WCD934X_RX4, 0,
  6537. &i2s_rx4_mux, tavil_codec_enable_i2s_path,
  6538. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6539. SND_SOC_DAPM_POST_PMD),
  6540. SND_SOC_DAPM_MUX_E("I2S RX5 MUX", SND_SOC_NOPM, WCD934X_RX5, 0,
  6541. &i2s_rx5_mux, tavil_codec_enable_i2s_path,
  6542. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6543. SND_SOC_DAPM_POST_PMD),
  6544. SND_SOC_DAPM_MUX_E("I2S RX6 MUX", SND_SOC_NOPM, WCD934X_RX6, 0,
  6545. &i2s_rx6_mux, tavil_codec_enable_i2s_path,
  6546. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6547. SND_SOC_DAPM_POST_PMD),
  6548. SND_SOC_DAPM_MUX_E("I2S RX7 MUX", SND_SOC_NOPM, WCD934X_RX7, 0,
  6549. &i2s_rx7_mux, tavil_codec_enable_i2s_path,
  6550. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6551. SND_SOC_DAPM_POST_PMD),
  6552. SND_SOC_DAPM_MIXER("I2S RX0", SND_SOC_NOPM, 0, 0, NULL, 0),
  6553. SND_SOC_DAPM_MIXER("I2S RX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  6554. SND_SOC_DAPM_MIXER("I2S RX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  6555. SND_SOC_DAPM_MIXER("I2S RX3", SND_SOC_NOPM, 0, 0, NULL, 0),
  6556. SND_SOC_DAPM_MIXER("I2S RX4", SND_SOC_NOPM, 0, 0, NULL, 0),
  6557. SND_SOC_DAPM_MIXER("I2S RX5", SND_SOC_NOPM, 0, 0, NULL, 0),
  6558. SND_SOC_DAPM_MIXER("I2S RX6", SND_SOC_NOPM, 0, 0, NULL, 0),
  6559. SND_SOC_DAPM_MIXER("I2S RX7", SND_SOC_NOPM, 0, 0, NULL, 0),
  6560. SND_SOC_DAPM_MIXER_E("I2S TX0", SND_SOC_NOPM, WCD934X_TX0, 0, NULL, 0,
  6561. tavil_codec_enable_i2s_path, SND_SOC_DAPM_PRE_PMU |
  6562. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  6563. SND_SOC_DAPM_MIXER_E("I2S TX1", SND_SOC_NOPM, WCD934X_TX1, 0, NULL, 0,
  6564. tavil_codec_enable_i2s_path, SND_SOC_DAPM_PRE_PMU |
  6565. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  6566. SND_SOC_DAPM_MIXER_E("I2S TX2", SND_SOC_NOPM, WCD934X_TX2, 0, NULL, 0,
  6567. tavil_codec_enable_i2s_path, SND_SOC_DAPM_PRE_PMU |
  6568. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  6569. SND_SOC_DAPM_MIXER_E("I2S TX3", SND_SOC_NOPM, WCD934X_TX3, 0, NULL, 0,
  6570. tavil_codec_enable_i2s_path, SND_SOC_DAPM_PRE_PMU |
  6571. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  6572. SND_SOC_DAPM_MIXER_E("I2S TX4", SND_SOC_NOPM, WCD934X_TX4, 0, NULL, 0,
  6573. tavil_codec_enable_i2s_path, SND_SOC_DAPM_PRE_PMU |
  6574. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  6575. SND_SOC_DAPM_MIXER_E("I2S TX5", SND_SOC_NOPM, WCD934X_TX5, 0, NULL, 0,
  6576. tavil_codec_enable_i2s_path, SND_SOC_DAPM_PRE_PMU |
  6577. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  6578. SND_SOC_DAPM_MIXER_E("I2S TX6", SND_SOC_NOPM, WCD934X_TX6, 0, NULL, 0,
  6579. tavil_codec_enable_i2s_path, SND_SOC_DAPM_PRE_PMU |
  6580. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  6581. SND_SOC_DAPM_MIXER_E("I2S TX7", SND_SOC_NOPM, WCD934X_TX7, 0, NULL, 0,
  6582. tavil_codec_enable_i2s_path, SND_SOC_DAPM_PRE_PMU |
  6583. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  6584. SND_SOC_DAPM_MIXER_E("I2S TX8", SND_SOC_NOPM, WCD934X_TX8, 0, NULL, 0,
  6585. tavil_codec_enable_i2s_path, SND_SOC_DAPM_PRE_PMU |
  6586. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  6587. SND_SOC_DAPM_MIXER_E("I2S TX11", SND_SOC_NOPM, WCD934X_TX11, 0, NULL, 0,
  6588. tavil_codec_enable_i2s_path, SND_SOC_DAPM_PRE_PMU |
  6589. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  6590. SND_SOC_DAPM_MIXER("AIF1_CAP Mixer", SND_SOC_NOPM, AIF1_CAP, 0,
  6591. aif1_i2s_cap_mixer, ARRAY_SIZE(aif1_i2s_cap_mixer)),
  6592. SND_SOC_DAPM_MIXER("AIF2_CAP Mixer", SND_SOC_NOPM, AIF2_CAP, 0,
  6593. aif2_i2s_cap_mixer, ARRAY_SIZE(aif2_i2s_cap_mixer)),
  6594. SND_SOC_DAPM_MIXER("AIF3_CAP Mixer", SND_SOC_NOPM, AIF3_CAP, 0,
  6595. aif3_i2s_cap_mixer, ARRAY_SIZE(aif3_i2s_cap_mixer)),
  6596. };
  6597. static int tavil_dsd_mixer_get(struct snd_kcontrol *kcontrol,
  6598. struct snd_ctl_elem_value *ucontrol)
  6599. {
  6600. struct snd_soc_dapm_context *dapm =
  6601. snd_soc_dapm_kcontrol_dapm(kcontrol);
  6602. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(dapm);
  6603. struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec);
  6604. struct soc_mixer_control *mc =
  6605. (struct soc_mixer_control *)kcontrol->private_value;
  6606. struct tavil_dsd_config *dsd_conf = tavil_p->dsd_config;
  6607. int val;
  6608. val = tavil_dsd_get_current_mixer_value(dsd_conf, mc->shift);
  6609. ucontrol->value.integer.value[0] = ((val < 0) ? 0 : val);
  6610. return 0;
  6611. }
  6612. static int tavil_dsd_mixer_put(struct snd_kcontrol *kcontrol,
  6613. struct snd_ctl_elem_value *ucontrol)
  6614. {
  6615. struct soc_mixer_control *mc =
  6616. (struct soc_mixer_control *)kcontrol->private_value;
  6617. struct snd_soc_dapm_context *dapm =
  6618. snd_soc_dapm_kcontrol_dapm(kcontrol);
  6619. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(dapm);
  6620. struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec);
  6621. unsigned int wval = ucontrol->value.integer.value[0];
  6622. struct tavil_dsd_config *dsd_conf = tavil_p->dsd_config;
  6623. if (!dsd_conf)
  6624. return 0;
  6625. mutex_lock(&tavil_p->codec_mutex);
  6626. tavil_dsd_set_out_select(dsd_conf, mc->shift);
  6627. tavil_dsd_set_mixer_value(dsd_conf, mc->shift, wval);
  6628. mutex_unlock(&tavil_p->codec_mutex);
  6629. snd_soc_dapm_mixer_update_power(dapm, kcontrol, wval, NULL);
  6630. return 0;
  6631. }
  6632. static const struct snd_kcontrol_new hphl_mixer[] = {
  6633. SOC_SINGLE_EXT("DSD HPHL Switch", SND_SOC_NOPM, INTERP_HPHL, 1, 0,
  6634. tavil_dsd_mixer_get, tavil_dsd_mixer_put),
  6635. };
  6636. static const struct snd_kcontrol_new hphr_mixer[] = {
  6637. SOC_SINGLE_EXT("DSD HPHR Switch", SND_SOC_NOPM, INTERP_HPHR, 1, 0,
  6638. tavil_dsd_mixer_get, tavil_dsd_mixer_put),
  6639. };
  6640. static const struct snd_kcontrol_new lo1_mixer[] = {
  6641. SOC_SINGLE_EXT("DSD LO1 Switch", SND_SOC_NOPM, INTERP_LO1, 1, 0,
  6642. tavil_dsd_mixer_get, tavil_dsd_mixer_put),
  6643. };
  6644. static const struct snd_kcontrol_new lo2_mixer[] = {
  6645. SOC_SINGLE_EXT("DSD LO2 Switch", SND_SOC_NOPM, INTERP_LO2, 1, 0,
  6646. tavil_dsd_mixer_get, tavil_dsd_mixer_put),
  6647. };
  6648. static const struct snd_soc_dapm_widget tavil_dapm_slim_widgets[] = {
  6649. SND_SOC_DAPM_AIF_IN_E("AIF4 PB", "AIF4 Playback", 0, SND_SOC_NOPM,
  6650. AIF4_PB, 0, tavil_codec_enable_rx,
  6651. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  6652. SND_SOC_DAPM_AIF_OUT_E("AIF4 VI", "VIfeed", 0, SND_SOC_NOPM,
  6653. AIF4_VIFEED, 0,
  6654. tavil_codec_enable_slimvi_feedback,
  6655. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  6656. SND_SOC_DAPM_AIF_OUT("AIF4 MAD", "AIF4 MAD TX", 0,
  6657. SND_SOC_NOPM, 0, 0),
  6658. SND_SOC_DAPM_MIXER("AIF4_VI Mixer", SND_SOC_NOPM, AIF4_VIFEED, 0,
  6659. aif4_vi_mixer, ARRAY_SIZE(aif4_vi_mixer)),
  6660. SND_SOC_DAPM_INPUT("VIINPUT"),
  6661. WCD_DAPM_MUX("SLIM RX0 MUX", WCD934X_RX0, slim_rx0),
  6662. WCD_DAPM_MUX("SLIM RX1 MUX", WCD934X_RX1, slim_rx1),
  6663. WCD_DAPM_MUX("SLIM RX2 MUX", WCD934X_RX2, slim_rx2),
  6664. WCD_DAPM_MUX("SLIM RX3 MUX", WCD934X_RX3, slim_rx3),
  6665. WCD_DAPM_MUX("SLIM RX4 MUX", WCD934X_RX4, slim_rx4),
  6666. WCD_DAPM_MUX("SLIM RX5 MUX", WCD934X_RX5, slim_rx5),
  6667. WCD_DAPM_MUX("SLIM RX6 MUX", WCD934X_RX6, slim_rx6),
  6668. WCD_DAPM_MUX("SLIM RX7 MUX", WCD934X_RX7, slim_rx7),
  6669. SND_SOC_DAPM_MIXER("SLIM RX0", SND_SOC_NOPM, 0, 0, NULL, 0),
  6670. SND_SOC_DAPM_MIXER("SLIM RX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  6671. SND_SOC_DAPM_MIXER("SLIM RX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  6672. SND_SOC_DAPM_MIXER("SLIM RX3", SND_SOC_NOPM, 0, 0, NULL, 0),
  6673. SND_SOC_DAPM_MIXER("SLIM RX4", SND_SOC_NOPM, 0, 0, NULL, 0),
  6674. SND_SOC_DAPM_MIXER("SLIM RX5", SND_SOC_NOPM, 0, 0, NULL, 0),
  6675. SND_SOC_DAPM_MIXER("SLIM RX6", SND_SOC_NOPM, 0, 0, NULL, 0),
  6676. SND_SOC_DAPM_MIXER("SLIM RX7", SND_SOC_NOPM, 0, 0, NULL, 0),
  6677. SND_SOC_DAPM_MIXER("AIF1_CAP Mixer", SND_SOC_NOPM, AIF1_CAP, 0,
  6678. aif1_slim_cap_mixer,
  6679. ARRAY_SIZE(aif1_slim_cap_mixer)),
  6680. SND_SOC_DAPM_MIXER("AIF2_CAP Mixer", SND_SOC_NOPM, AIF2_CAP, 0,
  6681. aif2_slim_cap_mixer,
  6682. ARRAY_SIZE(aif2_slim_cap_mixer)),
  6683. SND_SOC_DAPM_MIXER("AIF3_CAP Mixer", SND_SOC_NOPM, AIF3_CAP, 0,
  6684. aif3_slim_cap_mixer,
  6685. ARRAY_SIZE(aif3_slim_cap_mixer)),
  6686. SND_SOC_DAPM_MIXER("AIF4_MAD Mixer", SND_SOC_NOPM, AIF4_MAD_TX, 0,
  6687. aif4_slim_mad_mixer,
  6688. ARRAY_SIZE(aif4_slim_mad_mixer)),
  6689. };
  6690. static const struct snd_soc_dapm_widget tavil_dapm_widgets[] = {
  6691. SND_SOC_DAPM_AIF_IN_E("AIF1 PB", "AIF1 Playback", 0, SND_SOC_NOPM,
  6692. AIF1_PB, 0, tavil_codec_enable_rx,
  6693. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  6694. SND_SOC_DAPM_AIF_IN_E("AIF2 PB", "AIF2 Playback", 0, SND_SOC_NOPM,
  6695. AIF2_PB, 0, tavil_codec_enable_rx,
  6696. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  6697. SND_SOC_DAPM_AIF_IN_E("AIF3 PB", "AIF3 Playback", 0, SND_SOC_NOPM,
  6698. AIF3_PB, 0, tavil_codec_enable_rx,
  6699. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  6700. WCD_DAPM_MUX("CDC_IF RX0 MUX", WCD934X_RX0, cdc_if_rx0),
  6701. WCD_DAPM_MUX("CDC_IF RX1 MUX", WCD934X_RX1, cdc_if_rx1),
  6702. WCD_DAPM_MUX("CDC_IF RX2 MUX", WCD934X_RX2, cdc_if_rx2),
  6703. WCD_DAPM_MUX("CDC_IF RX3 MUX", WCD934X_RX3, cdc_if_rx3),
  6704. WCD_DAPM_MUX("CDC_IF RX4 MUX", WCD934X_RX4, cdc_if_rx4),
  6705. WCD_DAPM_MUX("CDC_IF RX5 MUX", WCD934X_RX5, cdc_if_rx5),
  6706. WCD_DAPM_MUX("CDC_IF RX6 MUX", WCD934X_RX6, cdc_if_rx6),
  6707. WCD_DAPM_MUX("CDC_IF RX7 MUX", WCD934X_RX7, cdc_if_rx7),
  6708. SND_SOC_DAPM_MUX_E("RX INT0_2 MUX", SND_SOC_NOPM, INTERP_EAR, 0,
  6709. &rx_int0_2_mux, tavil_codec_enable_mix_path,
  6710. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6711. SND_SOC_DAPM_POST_PMD),
  6712. SND_SOC_DAPM_MUX_E("RX INT1_2 MUX", SND_SOC_NOPM, INTERP_HPHL, 0,
  6713. &rx_int1_2_mux, tavil_codec_enable_mix_path,
  6714. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6715. SND_SOC_DAPM_POST_PMD),
  6716. SND_SOC_DAPM_MUX_E("RX INT2_2 MUX", SND_SOC_NOPM, INTERP_HPHR, 0,
  6717. &rx_int2_2_mux, tavil_codec_enable_mix_path,
  6718. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6719. SND_SOC_DAPM_POST_PMD),
  6720. SND_SOC_DAPM_MUX_E("RX INT3_2 MUX", SND_SOC_NOPM, INTERP_LO1, 0,
  6721. &rx_int3_2_mux, tavil_codec_enable_mix_path,
  6722. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6723. SND_SOC_DAPM_POST_PMD),
  6724. SND_SOC_DAPM_MUX_E("RX INT4_2 MUX", SND_SOC_NOPM, INTERP_LO2, 0,
  6725. &rx_int4_2_mux, tavil_codec_enable_mix_path,
  6726. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6727. SND_SOC_DAPM_POST_PMD),
  6728. SND_SOC_DAPM_MUX_E("RX INT7_2 MUX", SND_SOC_NOPM, INTERP_SPKR1, 0,
  6729. &rx_int7_2_mux, tavil_codec_enable_mix_path,
  6730. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6731. SND_SOC_DAPM_POST_PMD),
  6732. SND_SOC_DAPM_MUX_E("RX INT8_2 MUX", SND_SOC_NOPM, INTERP_SPKR2, 0,
  6733. &rx_int8_2_mux, tavil_codec_enable_mix_path,
  6734. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6735. SND_SOC_DAPM_POST_PMD),
  6736. WCD_DAPM_MUX("RX INT0_1 MIX1 INP0", 0, rx_int0_1_mix_inp0),
  6737. WCD_DAPM_MUX("RX INT0_1 MIX1 INP1", 0, rx_int0_1_mix_inp1),
  6738. WCD_DAPM_MUX("RX INT0_1 MIX1 INP2", 0, rx_int0_1_mix_inp2),
  6739. WCD_DAPM_MUX("RX INT1_1 MIX1 INP0", 0, rx_int1_1_mix_inp0),
  6740. WCD_DAPM_MUX("RX INT1_1 MIX1 INP1", 0, rx_int1_1_mix_inp1),
  6741. WCD_DAPM_MUX("RX INT1_1 MIX1 INP2", 0, rx_int1_1_mix_inp2),
  6742. WCD_DAPM_MUX("RX INT2_1 MIX1 INP0", 0, rx_int2_1_mix_inp0),
  6743. WCD_DAPM_MUX("RX INT2_1 MIX1 INP1", 0, rx_int2_1_mix_inp1),
  6744. WCD_DAPM_MUX("RX INT2_1 MIX1 INP2", 0, rx_int2_1_mix_inp2),
  6745. WCD_DAPM_MUX("RX INT3_1 MIX1 INP0", 0, rx_int3_1_mix_inp0),
  6746. WCD_DAPM_MUX("RX INT3_1 MIX1 INP1", 0, rx_int3_1_mix_inp1),
  6747. WCD_DAPM_MUX("RX INT3_1 MIX1 INP2", 0, rx_int3_1_mix_inp2),
  6748. WCD_DAPM_MUX("RX INT4_1 MIX1 INP0", 0, rx_int4_1_mix_inp0),
  6749. WCD_DAPM_MUX("RX INT4_1 MIX1 INP1", 0, rx_int4_1_mix_inp1),
  6750. WCD_DAPM_MUX("RX INT4_1 MIX1 INP2", 0, rx_int4_1_mix_inp2),
  6751. SND_SOC_DAPM_MUX_E("RX INT7_1 MIX1 INP0", SND_SOC_NOPM, 0, 0,
  6752. &rx_int7_1_mix_inp0_mux, tavil_codec_enable_swr,
  6753. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6754. SND_SOC_DAPM_MUX_E("RX INT7_1 MIX1 INP1", SND_SOC_NOPM, 0, 0,
  6755. &rx_int7_1_mix_inp1_mux, tavil_codec_enable_swr,
  6756. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6757. SND_SOC_DAPM_MUX_E("RX INT7_1 MIX1 INP2", SND_SOC_NOPM, 0, 0,
  6758. &rx_int7_1_mix_inp2_mux, tavil_codec_enable_swr,
  6759. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6760. SND_SOC_DAPM_MUX_E("RX INT8_1 MIX1 INP0", SND_SOC_NOPM, 0, 0,
  6761. &rx_int8_1_mix_inp0_mux, tavil_codec_enable_swr,
  6762. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6763. SND_SOC_DAPM_MUX_E("RX INT8_1 MIX1 INP1", SND_SOC_NOPM, 0, 0,
  6764. &rx_int8_1_mix_inp1_mux, tavil_codec_enable_swr,
  6765. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6766. SND_SOC_DAPM_MUX_E("RX INT8_1 MIX1 INP2", SND_SOC_NOPM, 0, 0,
  6767. &rx_int8_1_mix_inp2_mux, tavil_codec_enable_swr,
  6768. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6769. SND_SOC_DAPM_MIXER("RX INT0_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  6770. SND_SOC_DAPM_MIXER("RX INT0 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
  6771. SND_SOC_DAPM_MIXER("RX INT1_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  6772. SND_SOC_DAPM_MIXER("RX INT1 SEC MIX", SND_SOC_NOPM, 0, 0,
  6773. rx_int1_asrc_switch, ARRAY_SIZE(rx_int1_asrc_switch)),
  6774. SND_SOC_DAPM_MIXER("RX INT2_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  6775. SND_SOC_DAPM_MIXER("RX INT2 SEC MIX", SND_SOC_NOPM, 0, 0,
  6776. rx_int2_asrc_switch, ARRAY_SIZE(rx_int2_asrc_switch)),
  6777. SND_SOC_DAPM_MIXER("RX INT3_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  6778. SND_SOC_DAPM_MIXER("RX INT3 SEC MIX", SND_SOC_NOPM, 0, 0,
  6779. rx_int3_asrc_switch, ARRAY_SIZE(rx_int3_asrc_switch)),
  6780. SND_SOC_DAPM_MIXER("RX INT4_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  6781. SND_SOC_DAPM_MIXER("RX INT4 SEC MIX", SND_SOC_NOPM, 0, 0,
  6782. rx_int4_asrc_switch, ARRAY_SIZE(rx_int4_asrc_switch)),
  6783. SND_SOC_DAPM_MIXER("RX INT7_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  6784. SND_SOC_DAPM_MIXER("RX INT7 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
  6785. SND_SOC_DAPM_MIXER("RX INT8_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  6786. SND_SOC_DAPM_MIXER("RX INT8 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
  6787. SND_SOC_DAPM_MIXER("RX INT0 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  6788. SND_SOC_DAPM_MIXER("RX INT1 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  6789. SND_SOC_DAPM_MIXER("RX INT1 MIX3", SND_SOC_NOPM, 0, 0, hphl_mixer,
  6790. ARRAY_SIZE(hphl_mixer)),
  6791. SND_SOC_DAPM_MIXER("RX INT2 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  6792. SND_SOC_DAPM_MIXER("RX INT2 MIX3", SND_SOC_NOPM, 0, 0, hphr_mixer,
  6793. ARRAY_SIZE(hphr_mixer)),
  6794. SND_SOC_DAPM_MIXER("RX INT3 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  6795. SND_SOC_DAPM_MIXER("RX INT3 MIX3", SND_SOC_NOPM, 0, 0, lo1_mixer,
  6796. ARRAY_SIZE(lo1_mixer)),
  6797. SND_SOC_DAPM_MIXER("RX INT4 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  6798. SND_SOC_DAPM_MIXER("RX INT4 MIX3", SND_SOC_NOPM, 0, 0, lo2_mixer,
  6799. ARRAY_SIZE(lo2_mixer)),
  6800. SND_SOC_DAPM_MIXER("RX INT7 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  6801. SND_SOC_DAPM_MIXER_E("RX INT7 CHAIN", SND_SOC_NOPM, 0, 0,
  6802. NULL, 0, tavil_codec_spk_boost_event,
  6803. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6804. SND_SOC_DAPM_MIXER_E("RX INT8 CHAIN", SND_SOC_NOPM, 0, 0,
  6805. NULL, 0, tavil_codec_spk_boost_event,
  6806. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6807. SND_SOC_DAPM_MUX_E("RX INT0 MIX2 INP", SND_SOC_NOPM, INTERP_EAR,
  6808. 0, &rx_int0_mix2_inp_mux, tavil_codec_enable_rx_path_clk,
  6809. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6810. SND_SOC_DAPM_MUX_E("RX INT1 MIX2 INP", SND_SOC_NOPM, INTERP_HPHL,
  6811. 0, &rx_int1_mix2_inp_mux, tavil_codec_enable_rx_path_clk,
  6812. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6813. SND_SOC_DAPM_MUX_E("RX INT2 MIX2 INP", SND_SOC_NOPM, INTERP_HPHR,
  6814. 0, &rx_int2_mix2_inp_mux, tavil_codec_enable_rx_path_clk,
  6815. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6816. SND_SOC_DAPM_MUX_E("RX INT3 MIX2 INP", SND_SOC_NOPM, INTERP_LO1,
  6817. 0, &rx_int3_mix2_inp_mux, tavil_codec_enable_rx_path_clk,
  6818. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6819. SND_SOC_DAPM_MUX_E("RX INT4 MIX2 INP", SND_SOC_NOPM, INTERP_LO2,
  6820. 0, &rx_int4_mix2_inp_mux, tavil_codec_enable_rx_path_clk,
  6821. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6822. SND_SOC_DAPM_MUX_E("RX INT7 MIX2 INP", SND_SOC_NOPM, INTERP_SPKR1,
  6823. 0, &rx_int7_mix2_inp_mux, tavil_codec_enable_rx_path_clk,
  6824. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6825. WCD_DAPM_MUX("CDC_IF TX0 MUX", WCD934X_TX0, cdc_if_tx0),
  6826. WCD_DAPM_MUX("CDC_IF TX1 MUX", WCD934X_TX1, cdc_if_tx1),
  6827. WCD_DAPM_MUX("CDC_IF TX2 MUX", WCD934X_TX2, cdc_if_tx2),
  6828. WCD_DAPM_MUX("CDC_IF TX3 MUX", WCD934X_TX3, cdc_if_tx3),
  6829. WCD_DAPM_MUX("CDC_IF TX4 MUX", WCD934X_TX4, cdc_if_tx4),
  6830. WCD_DAPM_MUX("CDC_IF TX5 MUX", WCD934X_TX5, cdc_if_tx5),
  6831. WCD_DAPM_MUX("CDC_IF TX6 MUX", WCD934X_TX6, cdc_if_tx6),
  6832. WCD_DAPM_MUX("CDC_IF TX7 MUX", WCD934X_TX7, cdc_if_tx7),
  6833. WCD_DAPM_MUX("CDC_IF TX8 MUX", WCD934X_TX8, cdc_if_tx8),
  6834. WCD_DAPM_MUX("CDC_IF TX9 MUX", WCD934X_TX9, cdc_if_tx9),
  6835. WCD_DAPM_MUX("CDC_IF TX10 MUX", WCD934X_TX10, cdc_if_tx10),
  6836. WCD_DAPM_MUX("CDC_IF TX11 MUX", WCD934X_TX11, cdc_if_tx11),
  6837. WCD_DAPM_MUX("CDC_IF TX11 INP1 MUX", WCD934X_TX11, cdc_if_tx11_inp1),
  6838. WCD_DAPM_MUX("CDC_IF TX13 MUX", WCD934X_TX13, cdc_if_tx13),
  6839. WCD_DAPM_MUX("CDC_IF TX13 INP1 MUX", WCD934X_TX13, cdc_if_tx13_inp1),
  6840. SND_SOC_DAPM_MUX_E("ADC MUX0", WCD934X_CDC_TX0_TX_PATH_CTL, 5, 0,
  6841. &tx_adc_mux0_mux, tavil_codec_enable_dec,
  6842. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6843. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  6844. SND_SOC_DAPM_MUX_E("ADC MUX1", WCD934X_CDC_TX1_TX_PATH_CTL, 5, 0,
  6845. &tx_adc_mux1_mux, tavil_codec_enable_dec,
  6846. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6847. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  6848. SND_SOC_DAPM_MUX_E("ADC MUX2", WCD934X_CDC_TX2_TX_PATH_CTL, 5, 0,
  6849. &tx_adc_mux2_mux, tavil_codec_enable_dec,
  6850. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6851. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  6852. SND_SOC_DAPM_MUX_E("ADC MUX3", WCD934X_CDC_TX3_TX_PATH_CTL, 5, 0,
  6853. &tx_adc_mux3_mux, tavil_codec_enable_dec,
  6854. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6855. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  6856. SND_SOC_DAPM_MUX_E("ADC MUX4", WCD934X_CDC_TX4_TX_PATH_CTL, 5, 0,
  6857. &tx_adc_mux4_mux, tavil_codec_enable_dec,
  6858. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6859. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  6860. SND_SOC_DAPM_MUX_E("ADC MUX5", WCD934X_CDC_TX5_TX_PATH_CTL, 5, 0,
  6861. &tx_adc_mux5_mux, tavil_codec_enable_dec,
  6862. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6863. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  6864. SND_SOC_DAPM_MUX_E("ADC MUX6", WCD934X_CDC_TX6_TX_PATH_CTL, 5, 0,
  6865. &tx_adc_mux6_mux, tavil_codec_enable_dec,
  6866. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6867. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  6868. SND_SOC_DAPM_MUX_E("ADC MUX7", WCD934X_CDC_TX7_TX_PATH_CTL, 5, 0,
  6869. &tx_adc_mux7_mux, tavil_codec_enable_dec,
  6870. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6871. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  6872. SND_SOC_DAPM_MUX_E("ADC MUX8", WCD934X_CDC_TX8_TX_PATH_CTL, 5, 0,
  6873. &tx_adc_mux8_mux, tavil_codec_enable_dec,
  6874. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  6875. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  6876. SND_SOC_DAPM_MUX_E("ADC MUX10", SND_SOC_NOPM, 10, 0, &tx_adc_mux10_mux,
  6877. tavil_codec_tx_adc_cfg, SND_SOC_DAPM_POST_PMU),
  6878. SND_SOC_DAPM_MUX_E("ADC MUX11", SND_SOC_NOPM, 11, 0, &tx_adc_mux11_mux,
  6879. tavil_codec_tx_adc_cfg, SND_SOC_DAPM_POST_PMU),
  6880. SND_SOC_DAPM_MUX_E("ADC MUX12", SND_SOC_NOPM, 12, 0, &tx_adc_mux12_mux,
  6881. tavil_codec_tx_adc_cfg, SND_SOC_DAPM_POST_PMU),
  6882. SND_SOC_DAPM_MUX_E("ADC MUX13", SND_SOC_NOPM, 13, 0, &tx_adc_mux13_mux,
  6883. tavil_codec_tx_adc_cfg, SND_SOC_DAPM_POST_PMU),
  6884. WCD_DAPM_MUX("DMIC MUX0", 0, tx_dmic_mux0),
  6885. WCD_DAPM_MUX("DMIC MUX1", 0, tx_dmic_mux1),
  6886. WCD_DAPM_MUX("DMIC MUX2", 0, tx_dmic_mux2),
  6887. WCD_DAPM_MUX("DMIC MUX3", 0, tx_dmic_mux3),
  6888. WCD_DAPM_MUX("DMIC MUX4", 0, tx_dmic_mux4),
  6889. WCD_DAPM_MUX("DMIC MUX5", 0, tx_dmic_mux5),
  6890. WCD_DAPM_MUX("DMIC MUX6", 0, tx_dmic_mux6),
  6891. WCD_DAPM_MUX("DMIC MUX7", 0, tx_dmic_mux7),
  6892. WCD_DAPM_MUX("DMIC MUX8", 0, tx_dmic_mux8),
  6893. WCD_DAPM_MUX("DMIC MUX10", 0, tx_dmic_mux10),
  6894. WCD_DAPM_MUX("DMIC MUX11", 0, tx_dmic_mux11),
  6895. WCD_DAPM_MUX("DMIC MUX12", 0, tx_dmic_mux12),
  6896. WCD_DAPM_MUX("DMIC MUX13", 0, tx_dmic_mux13),
  6897. WCD_DAPM_MUX("AMIC MUX0", 0, tx_amic_mux0),
  6898. WCD_DAPM_MUX("AMIC MUX1", 0, tx_amic_mux1),
  6899. WCD_DAPM_MUX("AMIC MUX2", 0, tx_amic_mux2),
  6900. WCD_DAPM_MUX("AMIC MUX3", 0, tx_amic_mux3),
  6901. WCD_DAPM_MUX("AMIC MUX4", 0, tx_amic_mux4),
  6902. WCD_DAPM_MUX("AMIC MUX5", 0, tx_amic_mux5),
  6903. WCD_DAPM_MUX("AMIC MUX6", 0, tx_amic_mux6),
  6904. WCD_DAPM_MUX("AMIC MUX7", 0, tx_amic_mux7),
  6905. WCD_DAPM_MUX("AMIC MUX8", 0, tx_amic_mux8),
  6906. WCD_DAPM_MUX("AMIC MUX10", 0, tx_amic_mux10),
  6907. WCD_DAPM_MUX("AMIC MUX11", 0, tx_amic_mux11),
  6908. WCD_DAPM_MUX("AMIC MUX12", 0, tx_amic_mux12),
  6909. WCD_DAPM_MUX("AMIC MUX13", 0, tx_amic_mux13),
  6910. SND_SOC_DAPM_ADC_E("ADC1", NULL, WCD934X_ANA_AMIC1, 7, 0,
  6911. tavil_codec_enable_adc, SND_SOC_DAPM_PRE_PMU),
  6912. SND_SOC_DAPM_ADC_E("ADC2", NULL, WCD934X_ANA_AMIC2, 7, 0,
  6913. tavil_codec_enable_adc, SND_SOC_DAPM_PRE_PMU),
  6914. SND_SOC_DAPM_ADC_E("ADC3", NULL, WCD934X_ANA_AMIC3, 7, 0,
  6915. tavil_codec_enable_adc, SND_SOC_DAPM_PRE_PMU),
  6916. SND_SOC_DAPM_ADC_E("ADC4", NULL, WCD934X_ANA_AMIC4, 7, 0,
  6917. tavil_codec_enable_adc, SND_SOC_DAPM_PRE_PMU),
  6918. WCD_DAPM_MUX("AMIC4_5 SEL", 0, tx_amic4_5),
  6919. WCD_DAPM_MUX("ANC0 FB MUX", 0, anc0_fb),
  6920. WCD_DAPM_MUX("ANC1 FB MUX", 0, anc1_fb),
  6921. SND_SOC_DAPM_INPUT("AMIC1"),
  6922. SND_SOC_DAPM_INPUT("AMIC2"),
  6923. SND_SOC_DAPM_INPUT("AMIC3"),
  6924. SND_SOC_DAPM_INPUT("AMIC4"),
  6925. SND_SOC_DAPM_INPUT("AMIC5"),
  6926. SND_SOC_DAPM_MICBIAS_E("MIC BIAS1", SND_SOC_NOPM, 0, 0,
  6927. tavil_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
  6928. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  6929. SND_SOC_DAPM_MICBIAS_E("MIC BIAS2", SND_SOC_NOPM, 0, 0,
  6930. tavil_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
  6931. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  6932. SND_SOC_DAPM_MICBIAS_E("MIC BIAS3", SND_SOC_NOPM, 0, 0,
  6933. tavil_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
  6934. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  6935. SND_SOC_DAPM_MICBIAS_E("MIC BIAS4", SND_SOC_NOPM, 0, 0,
  6936. tavil_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
  6937. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  6938. /*
  6939. * Not supply widget, this is used to recover HPH registers.
  6940. * It is not connected to any other widgets
  6941. */
  6942. SND_SOC_DAPM_SUPPLY("RESET_HPH_REGISTERS", SND_SOC_NOPM,
  6943. 0, 0, tavil_codec_reset_hph_registers,
  6944. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6945. SND_SOC_DAPM_MICBIAS_E(DAPM_MICBIAS1_STANDALONE, SND_SOC_NOPM, 0, 0,
  6946. tavil_codec_force_enable_micbias,
  6947. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6948. SND_SOC_DAPM_MICBIAS_E(DAPM_MICBIAS2_STANDALONE, SND_SOC_NOPM, 0, 0,
  6949. tavil_codec_force_enable_micbias,
  6950. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6951. SND_SOC_DAPM_MICBIAS_E(DAPM_MICBIAS3_STANDALONE, SND_SOC_NOPM, 0, 0,
  6952. tavil_codec_force_enable_micbias,
  6953. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6954. SND_SOC_DAPM_MICBIAS_E(DAPM_MICBIAS4_STANDALONE, SND_SOC_NOPM, 0, 0,
  6955. tavil_codec_force_enable_micbias,
  6956. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6957. SND_SOC_DAPM_AIF_OUT_E("AIF1 CAP", "AIF1 Capture", 0, SND_SOC_NOPM,
  6958. AIF1_CAP, 0, tavil_codec_enable_tx,
  6959. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  6960. SND_SOC_DAPM_AIF_OUT_E("AIF2 CAP", "AIF2 Capture", 0, SND_SOC_NOPM,
  6961. AIF2_CAP, 0, tavil_codec_enable_tx,
  6962. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  6963. SND_SOC_DAPM_AIF_OUT_E("AIF3 CAP", "AIF3 Capture", 0, SND_SOC_NOPM,
  6964. AIF3_CAP, 0, tavil_codec_enable_tx,
  6965. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  6966. SND_SOC_DAPM_MIXER("SLIM TX0", SND_SOC_NOPM, 0, 0, NULL, 0),
  6967. SND_SOC_DAPM_MIXER("SLIM TX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  6968. SND_SOC_DAPM_MIXER("SLIM TX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  6969. SND_SOC_DAPM_MIXER("SLIM TX3", SND_SOC_NOPM, 0, 0, NULL, 0),
  6970. SND_SOC_DAPM_MIXER("SLIM TX4", SND_SOC_NOPM, 0, 0, NULL, 0),
  6971. SND_SOC_DAPM_MIXER("SLIM TX5", SND_SOC_NOPM, 0, 0, NULL, 0),
  6972. SND_SOC_DAPM_MIXER("SLIM TX6", SND_SOC_NOPM, 0, 0, NULL, 0),
  6973. SND_SOC_DAPM_MIXER("SLIM TX7", SND_SOC_NOPM, 0, 0, NULL, 0),
  6974. SND_SOC_DAPM_MIXER("SLIM TX8", SND_SOC_NOPM, 0, 0, NULL, 0),
  6975. SND_SOC_DAPM_MIXER("SLIM TX9", SND_SOC_NOPM, 0, 0, NULL, 0),
  6976. SND_SOC_DAPM_MIXER("SLIM TX10", SND_SOC_NOPM, 0, 0, NULL, 0),
  6977. SND_SOC_DAPM_MIXER("SLIM TX11", SND_SOC_NOPM, 0, 0, NULL, 0),
  6978. SND_SOC_DAPM_MIXER("SLIM TX13", SND_SOC_NOPM, 0, 0, NULL, 0),
  6979. /* Digital Mic Inputs */
  6980. SND_SOC_DAPM_ADC_E("DMIC0", NULL, SND_SOC_NOPM, 0, 0,
  6981. tavil_codec_enable_dmic,
  6982. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6983. SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 0, 0,
  6984. tavil_codec_enable_dmic,
  6985. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6986. SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 0, 0,
  6987. tavil_codec_enable_dmic,
  6988. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6989. SND_SOC_DAPM_ADC_E("DMIC3", NULL, SND_SOC_NOPM, 0, 0,
  6990. tavil_codec_enable_dmic,
  6991. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6992. SND_SOC_DAPM_ADC_E("DMIC4", NULL, SND_SOC_NOPM, 0, 0,
  6993. tavil_codec_enable_dmic,
  6994. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6995. SND_SOC_DAPM_ADC_E("DMIC5", NULL, SND_SOC_NOPM, 0, 0,
  6996. tavil_codec_enable_dmic,
  6997. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  6998. WCD_DAPM_MUX("IIR0 INP0 MUX", 0, iir0_inp0),
  6999. WCD_DAPM_MUX("IIR0 INP1 MUX", 0, iir0_inp1),
  7000. WCD_DAPM_MUX("IIR0 INP2 MUX", 0, iir0_inp2),
  7001. WCD_DAPM_MUX("IIR0 INP3 MUX", 0, iir0_inp3),
  7002. WCD_DAPM_MUX("IIR1 INP0 MUX", 0, iir1_inp0),
  7003. WCD_DAPM_MUX("IIR1 INP1 MUX", 0, iir1_inp1),
  7004. WCD_DAPM_MUX("IIR1 INP2 MUX", 0, iir1_inp2),
  7005. WCD_DAPM_MUX("IIR1 INP3 MUX", 0, iir1_inp3),
  7006. SND_SOC_DAPM_MIXER_E("IIR0", WCD934X_CDC_SIDETONE_IIR0_IIR_PATH_CTL,
  7007. 4, 0, NULL, 0, tavil_codec_set_iir_gain,
  7008. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  7009. SND_SOC_DAPM_MIXER_E("IIR1", WCD934X_CDC_SIDETONE_IIR1_IIR_PATH_CTL,
  7010. 4, 0, NULL, 0, tavil_codec_set_iir_gain,
  7011. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  7012. SND_SOC_DAPM_MIXER("SRC0", WCD934X_CDC_SIDETONE_SRC0_ST_SRC_PATH_CTL,
  7013. 4, 0, NULL, 0),
  7014. SND_SOC_DAPM_MIXER("SRC1", WCD934X_CDC_SIDETONE_SRC1_ST_SRC_PATH_CTL,
  7015. 4, 0, NULL, 0),
  7016. WCD_DAPM_MUX("RX MIX TX0 MUX", 0, rx_mix_tx0),
  7017. WCD_DAPM_MUX("RX MIX TX1 MUX", 0, rx_mix_tx1),
  7018. WCD_DAPM_MUX("RX MIX TX2 MUX", 0, rx_mix_tx2),
  7019. WCD_DAPM_MUX("RX MIX TX3 MUX", 0, rx_mix_tx3),
  7020. WCD_DAPM_MUX("RX MIX TX4 MUX", 0, rx_mix_tx4),
  7021. WCD_DAPM_MUX("RX MIX TX5 MUX", 0, rx_mix_tx5),
  7022. WCD_DAPM_MUX("RX MIX TX6 MUX", 0, rx_mix_tx6),
  7023. WCD_DAPM_MUX("RX MIX TX7 MUX", 0, rx_mix_tx7),
  7024. WCD_DAPM_MUX("RX MIX TX8 MUX", 0, rx_mix_tx8),
  7025. WCD_DAPM_MUX("RX INT0 DEM MUX", 0, rx_int0_dem_inp),
  7026. WCD_DAPM_MUX("RX INT1 DEM MUX", 0, rx_int1_dem_inp),
  7027. WCD_DAPM_MUX("RX INT2 DEM MUX", 0, rx_int2_dem_inp),
  7028. SND_SOC_DAPM_MUX_E("RX INT0_1 INTERP", SND_SOC_NOPM, INTERP_EAR, 0,
  7029. &rx_int0_1_interp_mux, tavil_codec_enable_main_path,
  7030. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  7031. SND_SOC_DAPM_POST_PMD),
  7032. SND_SOC_DAPM_MUX_E("RX INT1_1 INTERP", SND_SOC_NOPM, INTERP_HPHL, 0,
  7033. &rx_int1_1_interp_mux, tavil_codec_enable_main_path,
  7034. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  7035. SND_SOC_DAPM_POST_PMD),
  7036. SND_SOC_DAPM_MUX_E("RX INT2_1 INTERP", SND_SOC_NOPM, INTERP_HPHR, 0,
  7037. &rx_int2_1_interp_mux, tavil_codec_enable_main_path,
  7038. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  7039. SND_SOC_DAPM_POST_PMD),
  7040. SND_SOC_DAPM_MUX_E("RX INT3_1 INTERP", SND_SOC_NOPM, INTERP_LO1, 0,
  7041. &rx_int3_1_interp_mux, tavil_codec_enable_main_path,
  7042. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  7043. SND_SOC_DAPM_POST_PMD),
  7044. SND_SOC_DAPM_MUX_E("RX INT4_1 INTERP", SND_SOC_NOPM, INTERP_LO2, 0,
  7045. &rx_int4_1_interp_mux, tavil_codec_enable_main_path,
  7046. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  7047. SND_SOC_DAPM_POST_PMD),
  7048. SND_SOC_DAPM_MUX_E("RX INT7_1 INTERP", SND_SOC_NOPM, INTERP_SPKR1, 0,
  7049. &rx_int7_1_interp_mux, tavil_codec_enable_main_path,
  7050. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  7051. SND_SOC_DAPM_POST_PMD),
  7052. SND_SOC_DAPM_MUX_E("RX INT8_1 INTERP", SND_SOC_NOPM, INTERP_SPKR2, 0,
  7053. &rx_int8_1_interp_mux, tavil_codec_enable_main_path,
  7054. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  7055. SND_SOC_DAPM_POST_PMD),
  7056. WCD_DAPM_MUX("RX INT0_2 INTERP", 0, rx_int0_2_interp),
  7057. WCD_DAPM_MUX("RX INT1_2 INTERP", 0, rx_int1_2_interp),
  7058. WCD_DAPM_MUX("RX INT2_2 INTERP", 0, rx_int2_2_interp),
  7059. WCD_DAPM_MUX("RX INT3_2 INTERP", 0, rx_int3_2_interp),
  7060. WCD_DAPM_MUX("RX INT4_2 INTERP", 0, rx_int4_2_interp),
  7061. WCD_DAPM_MUX("RX INT7_2 INTERP", 0, rx_int7_2_interp),
  7062. WCD_DAPM_MUX("RX INT8_2 INTERP", 0, rx_int8_2_interp),
  7063. SND_SOC_DAPM_SWITCH("ADC US MUX0", WCD934X_CDC_TX0_TX_PATH_192_CTL, 0,
  7064. 0, &adc_us_mux0_switch),
  7065. SND_SOC_DAPM_SWITCH("ADC US MUX1", WCD934X_CDC_TX1_TX_PATH_192_CTL, 0,
  7066. 0, &adc_us_mux1_switch),
  7067. SND_SOC_DAPM_SWITCH("ADC US MUX2", WCD934X_CDC_TX2_TX_PATH_192_CTL, 0,
  7068. 0, &adc_us_mux2_switch),
  7069. SND_SOC_DAPM_SWITCH("ADC US MUX3", WCD934X_CDC_TX3_TX_PATH_192_CTL, 0,
  7070. 0, &adc_us_mux3_switch),
  7071. SND_SOC_DAPM_SWITCH("ADC US MUX4", WCD934X_CDC_TX4_TX_PATH_192_CTL, 0,
  7072. 0, &adc_us_mux4_switch),
  7073. SND_SOC_DAPM_SWITCH("ADC US MUX5", WCD934X_CDC_TX5_TX_PATH_192_CTL, 0,
  7074. 0, &adc_us_mux5_switch),
  7075. SND_SOC_DAPM_SWITCH("ADC US MUX6", WCD934X_CDC_TX6_TX_PATH_192_CTL, 0,
  7076. 0, &adc_us_mux6_switch),
  7077. SND_SOC_DAPM_SWITCH("ADC US MUX7", WCD934X_CDC_TX7_TX_PATH_192_CTL, 0,
  7078. 0, &adc_us_mux7_switch),
  7079. SND_SOC_DAPM_SWITCH("ADC US MUX8", WCD934X_CDC_TX8_TX_PATH_192_CTL, 0,
  7080. 0, &adc_us_mux8_switch),
  7081. /* MAD related widgets */
  7082. SND_SOC_DAPM_INPUT("MAD_CPE_INPUT"),
  7083. SND_SOC_DAPM_INPUT("MADINPUT"),
  7084. WCD_DAPM_MUX("MAD_SEL MUX", 0, mad_sel),
  7085. WCD_DAPM_MUX("MAD_INP MUX", 0, mad_inp_mux),
  7086. SND_SOC_DAPM_SWITCH_E("MAD_BROADCAST", SND_SOC_NOPM, 0, 0,
  7087. &mad_brdcst_switch, tavil_codec_ape_enable_mad,
  7088. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  7089. SND_SOC_DAPM_SWITCH_E("MAD_CPE1", SND_SOC_NOPM, 0, 0,
  7090. &mad_cpe1_switch, tavil_codec_cpe_mad_ctl,
  7091. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  7092. SND_SOC_DAPM_SWITCH_E("MAD_CPE2", SND_SOC_NOPM, 0, 0,
  7093. &mad_cpe2_switch, tavil_codec_cpe_mad_ctl,
  7094. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  7095. SND_SOC_DAPM_OUTPUT("MAD_CPE_OUT1"),
  7096. SND_SOC_DAPM_OUTPUT("MAD_CPE_OUT2"),
  7097. SND_SOC_DAPM_DAC_E("RX INT0 DAC", NULL, SND_SOC_NOPM,
  7098. 0, 0, tavil_codec_ear_dac_event,
  7099. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  7100. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  7101. SND_SOC_DAPM_DAC_E("RX INT1 DAC", NULL, WCD934X_ANA_HPH,
  7102. 5, 0, tavil_codec_hphl_dac_event,
  7103. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  7104. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  7105. SND_SOC_DAPM_DAC_E("RX INT2 DAC", NULL, WCD934X_ANA_HPH,
  7106. 4, 0, tavil_codec_hphr_dac_event,
  7107. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  7108. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  7109. SND_SOC_DAPM_DAC_E("RX INT3 DAC", NULL, SND_SOC_NOPM,
  7110. 0, 0, tavil_codec_lineout_dac_event,
  7111. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  7112. SND_SOC_DAPM_DAC_E("RX INT4 DAC", NULL, SND_SOC_NOPM,
  7113. 0, 0, tavil_codec_lineout_dac_event,
  7114. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  7115. SND_SOC_DAPM_PGA_E("EAR PA", WCD934X_ANA_EAR, 7, 0, NULL, 0,
  7116. tavil_codec_enable_ear_pa,
  7117. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  7118. SND_SOC_DAPM_PGA_E("HPHL PA", WCD934X_ANA_HPH, 7, 0, NULL, 0,
  7119. tavil_codec_enable_hphl_pa,
  7120. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  7121. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  7122. SND_SOC_DAPM_PGA_E("HPHR PA", WCD934X_ANA_HPH, 6, 0, NULL, 0,
  7123. tavil_codec_enable_hphr_pa,
  7124. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  7125. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  7126. SND_SOC_DAPM_PGA_E("LINEOUT1 PA", WCD934X_ANA_LO_1_2, 7, 0, NULL, 0,
  7127. tavil_codec_enable_lineout_pa,
  7128. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  7129. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  7130. SND_SOC_DAPM_PGA_E("LINEOUT2 PA", WCD934X_ANA_LO_1_2, 6, 0, NULL, 0,
  7131. tavil_codec_enable_lineout_pa,
  7132. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  7133. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  7134. SND_SOC_DAPM_PGA_E("ANC EAR PA", WCD934X_ANA_EAR, 7, 0, NULL, 0,
  7135. tavil_codec_enable_ear_pa, SND_SOC_DAPM_POST_PMU |
  7136. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  7137. SND_SOC_DAPM_PGA_E("ANC SPK1 PA", SND_SOC_NOPM, 0, 0, NULL, 0,
  7138. tavil_codec_enable_spkr_anc,
  7139. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  7140. SND_SOC_DAPM_PGA_E("ANC HPHL PA", SND_SOC_NOPM, 0, 0, NULL, 0,
  7141. tavil_codec_enable_hphl_pa,
  7142. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  7143. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  7144. SND_SOC_DAPM_PGA_E("ANC HPHR PA", SND_SOC_NOPM, 0, 0, NULL, 0,
  7145. tavil_codec_enable_hphr_pa,
  7146. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  7147. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  7148. SND_SOC_DAPM_OUTPUT("EAR"),
  7149. SND_SOC_DAPM_OUTPUT("HPHL"),
  7150. SND_SOC_DAPM_OUTPUT("HPHR"),
  7151. SND_SOC_DAPM_OUTPUT("LINEOUT1"),
  7152. SND_SOC_DAPM_OUTPUT("LINEOUT2"),
  7153. SND_SOC_DAPM_OUTPUT("SPK1 OUT"),
  7154. SND_SOC_DAPM_OUTPUT("SPK2 OUT"),
  7155. SND_SOC_DAPM_OUTPUT("ANC EAR"),
  7156. SND_SOC_DAPM_OUTPUT("ANC HPHL"),
  7157. SND_SOC_DAPM_OUTPUT("ANC HPHR"),
  7158. SND_SOC_DAPM_SWITCH("ANC OUT EAR Enable", SND_SOC_NOPM, 0, 0,
  7159. &anc_ear_switch),
  7160. SND_SOC_DAPM_SWITCH("ANC OUT EAR SPKR Enable", SND_SOC_NOPM, 0, 0,
  7161. &anc_ear_spkr_switch),
  7162. SND_SOC_DAPM_SWITCH("ANC SPKR PA Enable", SND_SOC_NOPM, 0, 0,
  7163. &anc_spkr_pa_switch),
  7164. SND_SOC_DAPM_SWITCH_E("ANC OUT HPHL Enable", SND_SOC_NOPM, INTERP_HPHL,
  7165. 0, &anc_hphl_pa_switch, tavil_anc_out_switch_cb,
  7166. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  7167. SND_SOC_DAPM_SWITCH_E("ANC OUT HPHR Enable", SND_SOC_NOPM, INTERP_HPHR,
  7168. 0, &anc_hphr_pa_switch, tavil_anc_out_switch_cb,
  7169. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  7170. SND_SOC_DAPM_SUPPLY("RX_BIAS", SND_SOC_NOPM, 0, 0,
  7171. tavil_codec_enable_rx_bias,
  7172. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  7173. SND_SOC_DAPM_SUPPLY("RX INT1 NATIVE SUPPLY", SND_SOC_NOPM,
  7174. INTERP_HPHL, 0, tavil_enable_native_supply,
  7175. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  7176. SND_SOC_DAPM_SUPPLY("RX INT2 NATIVE SUPPLY", SND_SOC_NOPM,
  7177. INTERP_HPHR, 0, tavil_enable_native_supply,
  7178. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  7179. SND_SOC_DAPM_SUPPLY("RX INT3 NATIVE SUPPLY", SND_SOC_NOPM,
  7180. INTERP_LO1, 0, tavil_enable_native_supply,
  7181. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  7182. SND_SOC_DAPM_SUPPLY("RX INT4 NATIVE SUPPLY", SND_SOC_NOPM,
  7183. INTERP_LO2, 0, tavil_enable_native_supply,
  7184. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  7185. SND_SOC_DAPM_SUPPLY("RX INT7 NATIVE SUPPLY", SND_SOC_NOPM,
  7186. INTERP_SPKR1, 0, tavil_enable_native_supply,
  7187. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  7188. SND_SOC_DAPM_SUPPLY("RX INT8 NATIVE SUPPLY", SND_SOC_NOPM,
  7189. INTERP_SPKR2, 0, tavil_enable_native_supply,
  7190. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  7191. WCD_DAPM_MUX("RX INT1_1 NATIVE MUX", 0, int1_1_native),
  7192. WCD_DAPM_MUX("RX INT2_1 NATIVE MUX", 0, int2_1_native),
  7193. WCD_DAPM_MUX("RX INT3_1 NATIVE MUX", 0, int3_1_native),
  7194. WCD_DAPM_MUX("RX INT4_1 NATIVE MUX", 0, int4_1_native),
  7195. WCD_DAPM_MUX("RX INT1_2 NATIVE MUX", 0, int1_2_native),
  7196. WCD_DAPM_MUX("RX INT2_2 NATIVE MUX", 0, int2_2_native),
  7197. WCD_DAPM_MUX("RX INT3_2 NATIVE MUX", 0, int3_2_native),
  7198. WCD_DAPM_MUX("RX INT4_2 NATIVE MUX", 0, int4_2_native),
  7199. WCD_DAPM_MUX("RX INT7_2 NATIVE MUX", 0, int7_2_native),
  7200. WCD_DAPM_MUX("RX INT8_2 NATIVE MUX", 0, int8_2_native),
  7201. SND_SOC_DAPM_MUX_E("ASRC0 MUX", SND_SOC_NOPM, ASRC0, 0,
  7202. &asrc0_mux, tavil_codec_enable_asrc_resampler,
  7203. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  7204. SND_SOC_DAPM_MUX_E("ASRC1 MUX", SND_SOC_NOPM, ASRC1, 0,
  7205. &asrc1_mux, tavil_codec_enable_asrc_resampler,
  7206. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  7207. SND_SOC_DAPM_MUX_E("ASRC2 MUX", SND_SOC_NOPM, ASRC2, 0,
  7208. &asrc2_mux, tavil_codec_enable_asrc_resampler,
  7209. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  7210. SND_SOC_DAPM_MUX_E("ASRC3 MUX", SND_SOC_NOPM, ASRC3, 0,
  7211. &asrc3_mux, tavil_codec_enable_asrc_resampler,
  7212. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  7213. /* WDMA3 widgets */
  7214. WCD_DAPM_MUX("WDMA3 PORT0 MUX", 0, wdma3_port0),
  7215. WCD_DAPM_MUX("WDMA3 PORT1 MUX", 1, wdma3_port1),
  7216. WCD_DAPM_MUX("WDMA3 PORT2 MUX", 2, wdma3_port2),
  7217. WCD_DAPM_MUX("WDMA3 PORT3 MUX", 3, wdma3_port3),
  7218. WCD_DAPM_MUX("WDMA3 PORT4 MUX", 4, wdma3_port4),
  7219. WCD_DAPM_MUX("WDMA3 PORT5 MUX", 5, wdma3_port5),
  7220. WCD_DAPM_MUX("WDMA3 PORT6 MUX", 6, wdma3_port6),
  7221. WCD_DAPM_MUX("WDMA3 CH0 MUX", 0, wdma3_ch0),
  7222. WCD_DAPM_MUX("WDMA3 CH1 MUX", 4, wdma3_ch1),
  7223. WCD_DAPM_MUX("WDMA3 CH2 MUX", 0, wdma3_ch2),
  7224. WCD_DAPM_MUX("WDMA3 CH3 MUX", 4, wdma3_ch3),
  7225. SND_SOC_DAPM_MIXER("WDMA3_CH_MIXER", SND_SOC_NOPM, 0, 0, NULL, 0),
  7226. SND_SOC_DAPM_SWITCH_E("WDMA3_ON_OFF", SND_SOC_NOPM, 0, 0,
  7227. &wdma3_onoff_switch, tavil_codec_wdma3_ctl,
  7228. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  7229. SND_SOC_DAPM_OUTPUT("WDMA3_OUT"),
  7230. };
  7231. static int tavil_get_channel_map(struct snd_soc_dai *dai,
  7232. unsigned int *tx_num, unsigned int *tx_slot,
  7233. unsigned int *rx_num, unsigned int *rx_slot)
  7234. {
  7235. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(dai->codec);
  7236. u32 i = 0;
  7237. struct wcd9xxx_ch *ch;
  7238. int ret = 0;
  7239. switch (dai->id) {
  7240. case AIF1_PB:
  7241. case AIF2_PB:
  7242. case AIF3_PB:
  7243. case AIF4_PB:
  7244. if (!rx_slot || !rx_num) {
  7245. dev_err(tavil->dev, "%s: Invalid rx_slot 0x%pK or rx_num 0x%pK\n",
  7246. __func__, rx_slot, rx_num);
  7247. ret = -EINVAL;
  7248. break;
  7249. }
  7250. list_for_each_entry(ch, &tavil->dai[dai->id].wcd9xxx_ch_list,
  7251. list) {
  7252. dev_dbg(tavil->dev, "%s: slot_num %u ch->ch_num %d\n",
  7253. __func__, i, ch->ch_num);
  7254. rx_slot[i++] = ch->ch_num;
  7255. }
  7256. *rx_num = i;
  7257. dev_dbg(tavil->dev, "%s: dai_name = %s dai_id = %x rx_num = %d\n",
  7258. __func__, dai->name, dai->id, i);
  7259. if (*rx_num == 0) {
  7260. dev_err(tavil->dev, "%s: Channel list empty for dai_name = %s dai_id = %x\n",
  7261. __func__, dai->name, dai->id);
  7262. ret = -EINVAL;
  7263. }
  7264. break;
  7265. case AIF1_CAP:
  7266. case AIF2_CAP:
  7267. case AIF3_CAP:
  7268. case AIF4_MAD_TX:
  7269. case AIF4_VIFEED:
  7270. if (!tx_slot || !tx_num) {
  7271. dev_err(tavil->dev, "%s: Invalid tx_slot 0x%pK or tx_num 0x%pK\n",
  7272. __func__, tx_slot, tx_num);
  7273. ret = -EINVAL;
  7274. break;
  7275. }
  7276. list_for_each_entry(ch, &tavil->dai[dai->id].wcd9xxx_ch_list,
  7277. list) {
  7278. dev_dbg(tavil->dev, "%s: slot_num %u ch->ch_num %d\n",
  7279. __func__, i, ch->ch_num);
  7280. tx_slot[i++] = ch->ch_num;
  7281. }
  7282. *tx_num = i;
  7283. dev_dbg(tavil->dev, "%s: dai_name = %s dai_id = %x tx_num = %d\n",
  7284. __func__, dai->name, dai->id, i);
  7285. if (*tx_num == 0) {
  7286. dev_err(tavil->dev, "%s: Channel list empty for dai_name = %s dai_id = %x\n",
  7287. __func__, dai->name, dai->id);
  7288. ret = -EINVAL;
  7289. }
  7290. break;
  7291. default:
  7292. dev_err(tavil->dev, "%s: Invalid DAI ID %x\n",
  7293. __func__, dai->id);
  7294. ret = -EINVAL;
  7295. break;
  7296. }
  7297. return ret;
  7298. }
  7299. static int tavil_set_channel_map(struct snd_soc_dai *dai,
  7300. unsigned int tx_num, unsigned int *tx_slot,
  7301. unsigned int rx_num, unsigned int *rx_slot)
  7302. {
  7303. struct tavil_priv *tavil;
  7304. struct wcd9xxx *core;
  7305. struct wcd9xxx_codec_dai_data *dai_data = NULL;
  7306. tavil = snd_soc_codec_get_drvdata(dai->codec);
  7307. core = dev_get_drvdata(dai->codec->dev->parent);
  7308. if (!tx_slot || !rx_slot) {
  7309. dev_err(tavil->dev, "%s: Invalid tx_slot 0x%pK, rx_slot 0x%pK\n",
  7310. __func__, tx_slot, rx_slot);
  7311. return -EINVAL;
  7312. }
  7313. dev_dbg(tavil->dev, "%s(): dai_name = %s DAI-ID %x tx_ch %d rx_ch %d\n",
  7314. __func__, dai->name, dai->id, tx_num, rx_num);
  7315. wcd9xxx_init_slimslave(core, core->slim->laddr,
  7316. tx_num, tx_slot, rx_num, rx_slot);
  7317. /* Reserve TX13 for MAD data channel */
  7318. dai_data = &tavil->dai[AIF4_MAD_TX];
  7319. if (dai_data)
  7320. list_add_tail(&core->tx_chs[WCD934X_TX13].list,
  7321. &dai_data->wcd9xxx_ch_list);
  7322. return 0;
  7323. }
  7324. static int tavil_startup(struct snd_pcm_substream *substream,
  7325. struct snd_soc_dai *dai)
  7326. {
  7327. pr_debug("%s(): substream = %s stream = %d\n", __func__,
  7328. substream->name, substream->stream);
  7329. return 0;
  7330. }
  7331. static void tavil_shutdown(struct snd_pcm_substream *substream,
  7332. struct snd_soc_dai *dai)
  7333. {
  7334. pr_debug("%s(): substream = %s stream = %d\n", __func__,
  7335. substream->name, substream->stream);
  7336. }
  7337. static int tavil_set_decimator_rate(struct snd_soc_dai *dai,
  7338. u32 sample_rate)
  7339. {
  7340. struct snd_soc_codec *codec = dai->codec;
  7341. struct wcd9xxx_ch *ch;
  7342. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  7343. u32 tx_port = 0, tx_fs_rate = 0;
  7344. u8 shift = 0, shift_val = 0, tx_mux_sel = 0;
  7345. int decimator = -1;
  7346. u16 tx_port_reg = 0, tx_fs_reg = 0;
  7347. switch (sample_rate) {
  7348. case 8000:
  7349. tx_fs_rate = 0;
  7350. break;
  7351. case 16000:
  7352. tx_fs_rate = 1;
  7353. break;
  7354. case 32000:
  7355. tx_fs_rate = 3;
  7356. break;
  7357. case 48000:
  7358. tx_fs_rate = 4;
  7359. break;
  7360. case 96000:
  7361. tx_fs_rate = 5;
  7362. break;
  7363. case 192000:
  7364. tx_fs_rate = 6;
  7365. break;
  7366. default:
  7367. dev_err(tavil->dev, "%s: Invalid TX sample rate: %d\n",
  7368. __func__, sample_rate);
  7369. return -EINVAL;
  7370. };
  7371. list_for_each_entry(ch, &tavil->dai[dai->id].wcd9xxx_ch_list, list) {
  7372. tx_port = ch->port;
  7373. dev_dbg(codec->dev, "%s: dai->id = %d, tx_port = %d",
  7374. __func__, dai->id, tx_port);
  7375. if ((tx_port < 0) || (tx_port == 12) || (tx_port >= 14)) {
  7376. dev_err(codec->dev, "%s: Invalid SLIM TX%u port. DAI ID: %d\n",
  7377. __func__, tx_port, dai->id);
  7378. return -EINVAL;
  7379. }
  7380. /* Find the SB TX MUX input - which decimator is connected */
  7381. if (tx_port < 4) {
  7382. tx_port_reg = WCD934X_CDC_IF_ROUTER_TX_MUX_CFG0;
  7383. shift = (tx_port << 1);
  7384. shift_val = 0x03;
  7385. } else if ((tx_port >= 4) && (tx_port < 8)) {
  7386. tx_port_reg = WCD934X_CDC_IF_ROUTER_TX_MUX_CFG1;
  7387. shift = ((tx_port - 4) << 1);
  7388. shift_val = 0x03;
  7389. } else if ((tx_port >= 8) && (tx_port < 11)) {
  7390. tx_port_reg = WCD934X_CDC_IF_ROUTER_TX_MUX_CFG2;
  7391. shift = ((tx_port - 8) << 1);
  7392. shift_val = 0x03;
  7393. } else if (tx_port == 11) {
  7394. tx_port_reg = WCD934X_CDC_IF_ROUTER_TX_MUX_CFG3;
  7395. shift = 0;
  7396. shift_val = 0x0F;
  7397. } else if (tx_port == 13) {
  7398. tx_port_reg = WCD934X_CDC_IF_ROUTER_TX_MUX_CFG3;
  7399. shift = 4;
  7400. shift_val = 0x03;
  7401. }
  7402. tx_mux_sel = snd_soc_read(codec, tx_port_reg) &
  7403. (shift_val << shift);
  7404. tx_mux_sel = tx_mux_sel >> shift;
  7405. if (tx_port <= 8) {
  7406. if ((tx_mux_sel == 0x2) || (tx_mux_sel == 0x3))
  7407. decimator = tx_port;
  7408. } else if (tx_port <= 10) {
  7409. if ((tx_mux_sel == 0x1) || (tx_mux_sel == 0x2))
  7410. decimator = ((tx_port == 9) ? 7 : 6);
  7411. } else if (tx_port == 11) {
  7412. if ((tx_mux_sel >= 1) && (tx_mux_sel < 7))
  7413. decimator = tx_mux_sel - 1;
  7414. } else if (tx_port == 13) {
  7415. if ((tx_mux_sel == 0x1) || (tx_mux_sel == 0x2))
  7416. decimator = 5;
  7417. }
  7418. if (decimator >= 0) {
  7419. tx_fs_reg = WCD934X_CDC_TX0_TX_PATH_CTL +
  7420. 16 * decimator;
  7421. dev_dbg(codec->dev, "%s: set DEC%u (-> SLIM_TX%u) rate to %u\n",
  7422. __func__, decimator, tx_port, sample_rate);
  7423. snd_soc_update_bits(codec, tx_fs_reg, 0x0F, tx_fs_rate);
  7424. } else if ((tx_port <= 8) && (tx_mux_sel == 0x01)) {
  7425. /* Check if the TX Mux input is RX MIX TXn */
  7426. dev_dbg(codec->dev, "%s: RX_MIX_TX%u going to CDC_IF TX%u\n",
  7427. __func__, tx_port, tx_port);
  7428. } else {
  7429. dev_err(codec->dev, "%s: ERROR: Invalid decimator: %d\n",
  7430. __func__, decimator);
  7431. return -EINVAL;
  7432. }
  7433. }
  7434. return 0;
  7435. }
  7436. static int tavil_set_mix_interpolator_rate(struct snd_soc_dai *dai,
  7437. u8 rate_reg_val,
  7438. u32 sample_rate)
  7439. {
  7440. u8 int_2_inp;
  7441. u32 j;
  7442. u16 int_mux_cfg1, int_fs_reg;
  7443. u8 int_mux_cfg1_val;
  7444. struct snd_soc_codec *codec = dai->codec;
  7445. struct wcd9xxx_ch *ch;
  7446. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  7447. list_for_each_entry(ch, &tavil->dai[dai->id].wcd9xxx_ch_list, list) {
  7448. int_2_inp = INTn_2_INP_SEL_RX0 + ch->port -
  7449. WCD934X_RX_PORT_START_NUMBER;
  7450. if ((int_2_inp < INTn_2_INP_SEL_RX0) ||
  7451. (int_2_inp > INTn_2_INP_SEL_RX7)) {
  7452. dev_err(codec->dev, "%s: Invalid RX%u port, Dai ID is %d\n",
  7453. __func__,
  7454. (ch->port - WCD934X_RX_PORT_START_NUMBER),
  7455. dai->id);
  7456. return -EINVAL;
  7457. }
  7458. int_mux_cfg1 = WCD934X_CDC_RX_INP_MUX_RX_INT0_CFG1;
  7459. for (j = 0; j < WCD934X_NUM_INTERPOLATORS; j++) {
  7460. /* Interpolators 5 and 6 are not aviliable in Tavil */
  7461. if (j == INTERP_LO3_NA || j == INTERP_LO4_NA) {
  7462. int_mux_cfg1 += 2;
  7463. continue;
  7464. }
  7465. int_mux_cfg1_val = snd_soc_read(codec, int_mux_cfg1) &
  7466. 0x0F;
  7467. if (int_mux_cfg1_val == int_2_inp) {
  7468. /*
  7469. * Ear mix path supports only 48, 96, 192,
  7470. * 384KHz only
  7471. */
  7472. if ((j == INTERP_EAR) &&
  7473. (rate_reg_val < 0x4 ||
  7474. rate_reg_val > 0x7)) {
  7475. dev_err_ratelimited(codec->dev,
  7476. "%s: Invalid rate for AIF_PB DAI(%d)\n",
  7477. __func__, dai->id);
  7478. return -EINVAL;
  7479. }
  7480. int_fs_reg = WCD934X_CDC_RX0_RX_PATH_MIX_CTL +
  7481. 20 * j;
  7482. dev_dbg(codec->dev, "%s: AIF_PB DAI(%d) connected to INT%u_2\n",
  7483. __func__, dai->id, j);
  7484. dev_dbg(codec->dev, "%s: set INT%u_2 sample rate to %u\n",
  7485. __func__, j, sample_rate);
  7486. snd_soc_update_bits(codec, int_fs_reg, 0x0F,
  7487. rate_reg_val);
  7488. }
  7489. int_mux_cfg1 += 2;
  7490. }
  7491. }
  7492. return 0;
  7493. }
  7494. static int tavil_set_prim_interpolator_rate(struct snd_soc_dai *dai,
  7495. u8 rate_reg_val,
  7496. u32 sample_rate)
  7497. {
  7498. u8 int_1_mix1_inp;
  7499. u32 j;
  7500. u16 int_mux_cfg0, int_mux_cfg1;
  7501. u16 int_fs_reg;
  7502. u8 int_mux_cfg0_val, int_mux_cfg1_val;
  7503. u8 inp0_sel, inp1_sel, inp2_sel;
  7504. struct snd_soc_codec *codec = dai->codec;
  7505. struct wcd9xxx_ch *ch;
  7506. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  7507. struct tavil_dsd_config *dsd_conf = tavil->dsd_config;
  7508. list_for_each_entry(ch, &tavil->dai[dai->id].wcd9xxx_ch_list, list) {
  7509. int_1_mix1_inp = INTn_1_INP_SEL_RX0 + ch->port -
  7510. WCD934X_RX_PORT_START_NUMBER;
  7511. if ((int_1_mix1_inp < INTn_1_INP_SEL_RX0) ||
  7512. (int_1_mix1_inp > INTn_1_INP_SEL_RX7)) {
  7513. dev_err(codec->dev, "%s: Invalid RX%u port, Dai ID is %d\n",
  7514. __func__,
  7515. (ch->port - WCD934X_RX_PORT_START_NUMBER),
  7516. dai->id);
  7517. return -EINVAL;
  7518. }
  7519. int_mux_cfg0 = WCD934X_CDC_RX_INP_MUX_RX_INT0_CFG0;
  7520. /*
  7521. * Loop through all interpolator MUX inputs and find out
  7522. * to which interpolator input, the slim rx port
  7523. * is connected
  7524. */
  7525. for (j = 0; j < WCD934X_NUM_INTERPOLATORS; j++) {
  7526. /* Interpolators 5 and 6 are not aviliable in Tavil */
  7527. if (j == INTERP_LO3_NA || j == INTERP_LO4_NA) {
  7528. int_mux_cfg0 += 2;
  7529. continue;
  7530. }
  7531. int_mux_cfg1 = int_mux_cfg0 + 1;
  7532. int_mux_cfg0_val = snd_soc_read(codec, int_mux_cfg0);
  7533. int_mux_cfg1_val = snd_soc_read(codec, int_mux_cfg1);
  7534. inp0_sel = int_mux_cfg0_val & 0x0F;
  7535. inp1_sel = (int_mux_cfg0_val >> 4) & 0x0F;
  7536. inp2_sel = (int_mux_cfg1_val >> 4) & 0x0F;
  7537. if ((inp0_sel == int_1_mix1_inp) ||
  7538. (inp1_sel == int_1_mix1_inp) ||
  7539. (inp2_sel == int_1_mix1_inp)) {
  7540. /*
  7541. * Ear and speaker primary path does not support
  7542. * native sample rates
  7543. */
  7544. if ((j == INTERP_EAR || j == INTERP_SPKR1 ||
  7545. j == INTERP_SPKR2) &&
  7546. (rate_reg_val > 0x7)) {
  7547. dev_err_ratelimited(codec->dev,
  7548. "%s: Invalid rate for AIF_PB DAI(%d)\n",
  7549. __func__, dai->id);
  7550. return -EINVAL;
  7551. }
  7552. int_fs_reg = WCD934X_CDC_RX0_RX_PATH_CTL +
  7553. 20 * j;
  7554. dev_dbg(codec->dev,
  7555. "%s: AIF_PB DAI(%d) connected to INT%u_1\n",
  7556. __func__, dai->id, j);
  7557. dev_dbg(codec->dev,
  7558. "%s: set INT%u_1 sample rate to %u\n",
  7559. __func__, j, sample_rate);
  7560. snd_soc_update_bits(codec, int_fs_reg, 0x0F,
  7561. rate_reg_val);
  7562. }
  7563. int_mux_cfg0 += 2;
  7564. }
  7565. if (dsd_conf)
  7566. tavil_dsd_set_interp_rate(dsd_conf, ch->port,
  7567. sample_rate, rate_reg_val);
  7568. }
  7569. return 0;
  7570. }
  7571. static int tavil_set_interpolator_rate(struct snd_soc_dai *dai,
  7572. u32 sample_rate)
  7573. {
  7574. struct snd_soc_codec *codec = dai->codec;
  7575. int rate_val = 0;
  7576. int i, ret;
  7577. for (i = 0; i < ARRAY_SIZE(sr_val_tbl); i++) {
  7578. if (sample_rate == sr_val_tbl[i].sample_rate) {
  7579. rate_val = sr_val_tbl[i].rate_val;
  7580. break;
  7581. }
  7582. }
  7583. if ((i == ARRAY_SIZE(sr_val_tbl)) || (rate_val < 0)) {
  7584. dev_err(codec->dev, "%s: Unsupported sample rate: %d\n",
  7585. __func__, sample_rate);
  7586. return -EINVAL;
  7587. }
  7588. ret = tavil_set_prim_interpolator_rate(dai, (u8)rate_val, sample_rate);
  7589. if (ret)
  7590. return ret;
  7591. ret = tavil_set_mix_interpolator_rate(dai, (u8)rate_val, sample_rate);
  7592. if (ret)
  7593. return ret;
  7594. return ret;
  7595. }
  7596. static int tavil_prepare(struct snd_pcm_substream *substream,
  7597. struct snd_soc_dai *dai)
  7598. {
  7599. pr_debug("%s(): substream = %s stream = %d\n", __func__,
  7600. substream->name, substream->stream);
  7601. return 0;
  7602. }
  7603. static int tavil_vi_hw_params(struct snd_pcm_substream *substream,
  7604. struct snd_pcm_hw_params *params,
  7605. struct snd_soc_dai *dai)
  7606. {
  7607. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(dai->codec);
  7608. dev_dbg(tavil->dev, "%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n",
  7609. __func__, dai->name, dai->id, params_rate(params),
  7610. params_channels(params));
  7611. tavil->dai[dai->id].rate = params_rate(params);
  7612. tavil->dai[dai->id].bit_width = 32;
  7613. return 0;
  7614. }
  7615. static int tavil_hw_params(struct snd_pcm_substream *substream,
  7616. struct snd_pcm_hw_params *params,
  7617. struct snd_soc_dai *dai)
  7618. {
  7619. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(dai->codec);
  7620. int ret = 0;
  7621. dev_dbg(tavil->dev, "%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n",
  7622. __func__, dai->name, dai->id, params_rate(params),
  7623. params_channels(params));
  7624. switch (substream->stream) {
  7625. case SNDRV_PCM_STREAM_PLAYBACK:
  7626. ret = tavil_set_interpolator_rate(dai, params_rate(params));
  7627. if (ret) {
  7628. dev_err(tavil->dev, "%s: cannot set sample rate: %u\n",
  7629. __func__, params_rate(params));
  7630. return ret;
  7631. }
  7632. switch (params_width(params)) {
  7633. case 16:
  7634. tavil->dai[dai->id].bit_width = 16;
  7635. break;
  7636. case 24:
  7637. tavil->dai[dai->id].bit_width = 24;
  7638. break;
  7639. case 32:
  7640. tavil->dai[dai->id].bit_width = 32;
  7641. break;
  7642. default:
  7643. return -EINVAL;
  7644. }
  7645. tavil->dai[dai->id].rate = params_rate(params);
  7646. break;
  7647. case SNDRV_PCM_STREAM_CAPTURE:
  7648. if (dai->id != AIF4_MAD_TX)
  7649. ret = tavil_set_decimator_rate(dai,
  7650. params_rate(params));
  7651. if (ret) {
  7652. dev_err(tavil->dev, "%s: cannot set TX Decimator rate: %d\n",
  7653. __func__, ret);
  7654. return ret;
  7655. }
  7656. switch (params_width(params)) {
  7657. case 16:
  7658. tavil->dai[dai->id].bit_width = 16;
  7659. break;
  7660. case 24:
  7661. tavil->dai[dai->id].bit_width = 24;
  7662. break;
  7663. default:
  7664. dev_err(tavil->dev, "%s: Invalid format 0x%x\n",
  7665. __func__, params_width(params));
  7666. return -EINVAL;
  7667. };
  7668. tavil->dai[dai->id].rate = params_rate(params);
  7669. break;
  7670. default:
  7671. dev_err(tavil->dev, "%s: Invalid stream type %d\n", __func__,
  7672. substream->stream);
  7673. return -EINVAL;
  7674. };
  7675. return 0;
  7676. }
  7677. static int tavil_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
  7678. {
  7679. u32 i2s_reg;
  7680. switch (dai->id) {
  7681. case AIF1_PB:
  7682. case AIF1_CAP:
  7683. i2s_reg = WCD934X_DATA_HUB_I2S_0_CTL;
  7684. break;
  7685. case AIF2_PB:
  7686. case AIF2_CAP:
  7687. i2s_reg = WCD934X_DATA_HUB_I2S_1_CTL;
  7688. break;
  7689. case AIF3_PB:
  7690. case AIF3_CAP:
  7691. i2s_reg = WCD934X_DATA_HUB_I2S_2_CTL;
  7692. break;
  7693. default:
  7694. dev_err(dai->codec->dev, "%s Invalid i2s Id", __func__);
  7695. return -EINVAL;
  7696. }
  7697. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  7698. case SND_SOC_DAIFMT_CBS_CFS:
  7699. /* CPU is master */
  7700. snd_soc_update_bits(dai->codec, i2s_reg, 0x2, 0x0);
  7701. break;
  7702. case SND_SOC_DAIFMT_CBM_CFM:
  7703. /* CPU is slave */
  7704. snd_soc_update_bits(dai->codec, i2s_reg, 0x2, 0x2);
  7705. break;
  7706. default:
  7707. return -EINVAL;
  7708. }
  7709. return 0;
  7710. }
  7711. static struct snd_soc_dai_ops tavil_dai_ops = {
  7712. .startup = tavil_startup,
  7713. .shutdown = tavil_shutdown,
  7714. .hw_params = tavil_hw_params,
  7715. .prepare = tavil_prepare,
  7716. .set_channel_map = tavil_set_channel_map,
  7717. .get_channel_map = tavil_get_channel_map,
  7718. };
  7719. static struct snd_soc_dai_ops tavil_i2s_dai_ops = {
  7720. .startup = tavil_startup,
  7721. .shutdown = tavil_shutdown,
  7722. .hw_params = tavil_hw_params,
  7723. .prepare = tavil_prepare,
  7724. .set_fmt = tavil_set_dai_fmt,
  7725. };
  7726. static struct snd_soc_dai_ops tavil_vi_dai_ops = {
  7727. .hw_params = tavil_vi_hw_params,
  7728. .set_channel_map = tavil_set_channel_map,
  7729. .get_channel_map = tavil_get_channel_map,
  7730. };
  7731. static struct snd_soc_dai_driver tavil_slim_dai[] = {
  7732. {
  7733. .name = "tavil_rx1",
  7734. .id = AIF1_PB,
  7735. .playback = {
  7736. .stream_name = "AIF1 Playback",
  7737. .rates = WCD934X_RATES_MASK | WCD934X_FRAC_RATES_MASK,
  7738. .formats = WCD934X_FORMATS_S16_S24_S32_LE,
  7739. .rate_min = 8000,
  7740. .rate_max = 384000,
  7741. .channels_min = 1,
  7742. .channels_max = 2,
  7743. },
  7744. .ops = &tavil_dai_ops,
  7745. },
  7746. {
  7747. .name = "tavil_tx1",
  7748. .id = AIF1_CAP,
  7749. .capture = {
  7750. .stream_name = "AIF1 Capture",
  7751. .rates = WCD934X_RATES_MASK,
  7752. .formats = WCD934X_FORMATS_S16_S24_LE,
  7753. .rate_min = 8000,
  7754. .rate_max = 192000,
  7755. .channels_min = 1,
  7756. .channels_max = 4,
  7757. },
  7758. .ops = &tavil_dai_ops,
  7759. },
  7760. {
  7761. .name = "tavil_rx2",
  7762. .id = AIF2_PB,
  7763. .playback = {
  7764. .stream_name = "AIF2 Playback",
  7765. .rates = WCD934X_RATES_MASK | WCD934X_FRAC_RATES_MASK,
  7766. .formats = WCD934X_FORMATS_S16_S24_S32_LE,
  7767. .rate_min = 8000,
  7768. .rate_max = 384000,
  7769. .channels_min = 1,
  7770. .channels_max = 2,
  7771. },
  7772. .ops = &tavil_dai_ops,
  7773. },
  7774. {
  7775. .name = "tavil_tx2",
  7776. .id = AIF2_CAP,
  7777. .capture = {
  7778. .stream_name = "AIF2 Capture",
  7779. .rates = WCD934X_RATES_MASK,
  7780. .formats = WCD934X_FORMATS_S16_S24_LE,
  7781. .rate_min = 8000,
  7782. .rate_max = 192000,
  7783. .channels_min = 1,
  7784. .channels_max = 4,
  7785. },
  7786. .ops = &tavil_dai_ops,
  7787. },
  7788. {
  7789. .name = "tavil_rx3",
  7790. .id = AIF3_PB,
  7791. .playback = {
  7792. .stream_name = "AIF3 Playback",
  7793. .rates = WCD934X_RATES_MASK | WCD934X_FRAC_RATES_MASK,
  7794. .formats = WCD934X_FORMATS_S16_S24_S32_LE,
  7795. .rate_min = 8000,
  7796. .rate_max = 384000,
  7797. .channels_min = 1,
  7798. .channels_max = 2,
  7799. },
  7800. .ops = &tavil_dai_ops,
  7801. },
  7802. {
  7803. .name = "tavil_tx3",
  7804. .id = AIF3_CAP,
  7805. .capture = {
  7806. .stream_name = "AIF3 Capture",
  7807. .rates = WCD934X_RATES_MASK,
  7808. .formats = WCD934X_FORMATS_S16_S24_LE,
  7809. .rate_min = 8000,
  7810. .rate_max = 192000,
  7811. .channels_min = 1,
  7812. .channels_max = 4,
  7813. },
  7814. .ops = &tavil_dai_ops,
  7815. },
  7816. {
  7817. .name = "tavil_rx4",
  7818. .id = AIF4_PB,
  7819. .playback = {
  7820. .stream_name = "AIF4 Playback",
  7821. .rates = WCD934X_RATES_MASK | WCD934X_FRAC_RATES_MASK,
  7822. .formats = WCD934X_FORMATS_S16_S24_S32_LE,
  7823. .rate_min = 8000,
  7824. .rate_max = 384000,
  7825. .channels_min = 1,
  7826. .channels_max = 2,
  7827. },
  7828. .ops = &tavil_dai_ops,
  7829. },
  7830. {
  7831. .name = "tavil_vifeedback",
  7832. .id = AIF4_VIFEED,
  7833. .capture = {
  7834. .stream_name = "VIfeed",
  7835. .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_48000,
  7836. .formats = WCD934X_FORMATS_S16_S24_S32_LE,
  7837. .rate_min = 8000,
  7838. .rate_max = 48000,
  7839. .channels_min = 1,
  7840. .channels_max = 4,
  7841. },
  7842. .ops = &tavil_vi_dai_ops,
  7843. },
  7844. {
  7845. .name = "tavil_mad1",
  7846. .id = AIF4_MAD_TX,
  7847. .capture = {
  7848. .stream_name = "AIF4 MAD TX",
  7849. .rates = SNDRV_PCM_RATE_16000,
  7850. .formats = WCD934X_FORMATS_S16_LE,
  7851. .rate_min = 16000,
  7852. .rate_max = 16000,
  7853. .channels_min = 1,
  7854. .channels_max = 1,
  7855. },
  7856. .ops = &tavil_dai_ops,
  7857. },
  7858. };
  7859. static struct snd_soc_dai_driver tavil_i2s_dai[] = {
  7860. {
  7861. .name = "tavil_i2s_rx1",
  7862. .id = AIF1_PB,
  7863. .playback = {
  7864. .stream_name = "AIF1 Playback",
  7865. .rates = WCD934X_RATES_MASK,
  7866. .formats = WCD934X_FORMATS_S16_S24_S32_LE,
  7867. .rate_min = 8000,
  7868. .rate_max = 384000,
  7869. .channels_min = 1,
  7870. .channels_max = 2,
  7871. },
  7872. .ops = &tavil_i2s_dai_ops,
  7873. },
  7874. {
  7875. .name = "tavil_i2s_tx1",
  7876. .id = AIF1_CAP,
  7877. .capture = {
  7878. .stream_name = "AIF1 Capture",
  7879. .rates = WCD934X_RATES_MASK,
  7880. .formats = WCD934X_FORMATS_S16_S24_LE,
  7881. .rate_min = 8000,
  7882. .rate_max = 384000,
  7883. .channels_min = 1,
  7884. .channels_max = 2,
  7885. },
  7886. .ops = &tavil_i2s_dai_ops,
  7887. },
  7888. {
  7889. .name = "tavil_i2s_rx2",
  7890. .id = AIF2_PB,
  7891. .playback = {
  7892. .stream_name = "AIF2 Playback",
  7893. .rates = WCD934X_RATES_MASK,
  7894. .formats = WCD934X_FORMATS_S16_S24_S32_LE,
  7895. .rate_min = 8000,
  7896. .rate_max = 384000,
  7897. .channels_min = 1,
  7898. .channels_max = 2,
  7899. },
  7900. .ops = &tavil_i2s_dai_ops,
  7901. },
  7902. {
  7903. .name = "tavil_i2s_tx2",
  7904. .id = AIF2_CAP,
  7905. .capture = {
  7906. .stream_name = "AIF2 Capture",
  7907. .rates = WCD934X_RATES_MASK,
  7908. .formats = WCD934X_FORMATS_S16_S24_LE,
  7909. .rate_min = 8000,
  7910. .rate_max = 384000,
  7911. .channels_min = 1,
  7912. .channels_max = 2,
  7913. },
  7914. .ops = &tavil_i2s_dai_ops,
  7915. },
  7916. {
  7917. .name = "tavil_i2s_rx3",
  7918. .id = AIF3_PB,
  7919. .playback = {
  7920. .stream_name = "AIF3 Playback",
  7921. .rates = WCD934X_RATES_MASK,
  7922. .formats = WCD934X_FORMATS_S16_S24_S32_LE,
  7923. .rate_min = 8000,
  7924. .rate_max = 384000,
  7925. .channels_min = 1,
  7926. .channels_max = 2,
  7927. },
  7928. .ops = &tavil_i2s_dai_ops,
  7929. },
  7930. {
  7931. .name = "tavil_i2s_tx3",
  7932. .id = AIF3_CAP,
  7933. .capture = {
  7934. .stream_name = "AIF3 Capture",
  7935. .rates = WCD934X_RATES_MASK,
  7936. .formats = WCD934X_FORMATS_S16_S24_LE,
  7937. .rate_min = 8000,
  7938. .rate_max = 384000,
  7939. .channels_min = 1,
  7940. .channels_max = 2,
  7941. },
  7942. .ops = &tavil_i2s_dai_ops,
  7943. },
  7944. };
  7945. static void tavil_codec_power_gate_digital_core(struct tavil_priv *tavil)
  7946. {
  7947. if (!tavil)
  7948. return;
  7949. mutex_lock(&tavil->power_lock);
  7950. dev_dbg(tavil->dev, "%s: Entering power gating function, %d\n",
  7951. __func__, tavil->power_active_ref);
  7952. if (tavil->power_active_ref > 0)
  7953. goto exit;
  7954. wcd9xxx_set_power_state(tavil->wcd9xxx,
  7955. WCD_REGION_POWER_COLLAPSE_BEGIN,
  7956. WCD9XXX_DIG_CORE_REGION_1);
  7957. regmap_update_bits(tavil->wcd9xxx->regmap,
  7958. WCD934X_CODEC_RPM_PWR_CDC_DIG_HM_CTL, 0x04, 0x04);
  7959. regmap_update_bits(tavil->wcd9xxx->regmap,
  7960. WCD934X_CODEC_RPM_PWR_CDC_DIG_HM_CTL, 0x01, 0x00);
  7961. regmap_update_bits(tavil->wcd9xxx->regmap,
  7962. WCD934X_CODEC_RPM_PWR_CDC_DIG_HM_CTL, 0x02, 0x00);
  7963. wcd9xxx_set_power_state(tavil->wcd9xxx, WCD_REGION_POWER_DOWN,
  7964. WCD9XXX_DIG_CORE_REGION_1);
  7965. exit:
  7966. dev_dbg(tavil->dev, "%s: Exiting power gating function, %d\n",
  7967. __func__, tavil->power_active_ref);
  7968. mutex_unlock(&tavil->power_lock);
  7969. }
  7970. static void tavil_codec_power_gate_work(struct work_struct *work)
  7971. {
  7972. struct tavil_priv *tavil;
  7973. struct delayed_work *dwork;
  7974. dwork = to_delayed_work(work);
  7975. tavil = container_of(dwork, struct tavil_priv, power_gate_work);
  7976. tavil_codec_power_gate_digital_core(tavil);
  7977. }
  7978. /* called under power_lock acquisition */
  7979. static int tavil_dig_core_remove_power_collapse(struct tavil_priv *tavil)
  7980. {
  7981. regmap_write(tavil->wcd9xxx->regmap,
  7982. WCD934X_CODEC_RPM_PWR_CDC_DIG_HM_CTL, 0x05);
  7983. regmap_write(tavil->wcd9xxx->regmap,
  7984. WCD934X_CODEC_RPM_PWR_CDC_DIG_HM_CTL, 0x07);
  7985. regmap_update_bits(tavil->wcd9xxx->regmap,
  7986. WCD934X_CODEC_RPM_RST_CTL, 0x02, 0x00);
  7987. regmap_update_bits(tavil->wcd9xxx->regmap,
  7988. WCD934X_CODEC_RPM_RST_CTL, 0x02, 0x02);
  7989. regmap_write(tavil->wcd9xxx->regmap,
  7990. WCD934X_CODEC_RPM_PWR_CDC_DIG_HM_CTL, 0x03);
  7991. wcd9xxx_set_power_state(tavil->wcd9xxx,
  7992. WCD_REGION_POWER_COLLAPSE_REMOVE,
  7993. WCD9XXX_DIG_CORE_REGION_1);
  7994. regcache_mark_dirty(tavil->wcd9xxx->regmap);
  7995. regcache_sync_region(tavil->wcd9xxx->regmap,
  7996. WCD934X_DIG_CORE_REG_MIN,
  7997. WCD934X_DIG_CORE_REG_MAX);
  7998. return 0;
  7999. }
  8000. static int tavil_dig_core_power_collapse(struct tavil_priv *tavil,
  8001. int req_state)
  8002. {
  8003. int cur_state;
  8004. /* Exit if feature is disabled */
  8005. if (!dig_core_collapse_enable)
  8006. return 0;
  8007. mutex_lock(&tavil->power_lock);
  8008. if (req_state == POWER_COLLAPSE)
  8009. tavil->power_active_ref--;
  8010. else if (req_state == POWER_RESUME)
  8011. tavil->power_active_ref++;
  8012. else
  8013. goto unlock_mutex;
  8014. if (tavil->power_active_ref < 0) {
  8015. dev_dbg(tavil->dev,
  8016. "%s: power_active_ref is negative, reset it\n",
  8017. __func__);
  8018. tavil->power_active_ref = 0;
  8019. goto unlock_mutex;
  8020. }
  8021. if (req_state == POWER_COLLAPSE) {
  8022. if (tavil->power_active_ref == 0) {
  8023. schedule_delayed_work(&tavil->power_gate_work,
  8024. msecs_to_jiffies(dig_core_collapse_timer * 1000));
  8025. }
  8026. } else if (req_state == POWER_RESUME) {
  8027. if (tavil->power_active_ref == 1) {
  8028. /*
  8029. * At this point, there can be two cases:
  8030. * 1. Core already in power collapse state
  8031. * 2. Timer kicked in and still did not expire or
  8032. * waiting for the power_lock
  8033. */
  8034. cur_state = wcd9xxx_get_current_power_state(
  8035. tavil->wcd9xxx,
  8036. WCD9XXX_DIG_CORE_REGION_1);
  8037. if (cur_state == WCD_REGION_POWER_DOWN) {
  8038. tavil_dig_core_remove_power_collapse(tavil);
  8039. } else {
  8040. mutex_unlock(&tavil->power_lock);
  8041. cancel_delayed_work_sync(
  8042. &tavil->power_gate_work);
  8043. mutex_lock(&tavil->power_lock);
  8044. }
  8045. }
  8046. }
  8047. unlock_mutex:
  8048. mutex_unlock(&tavil->power_lock);
  8049. return 0;
  8050. }
  8051. static int tavil_cdc_req_mclk_enable(struct tavil_priv *tavil,
  8052. bool enable)
  8053. {
  8054. int ret = 0;
  8055. if (enable) {
  8056. ret = clk_prepare_enable(tavil->wcd_ext_clk);
  8057. if (ret) {
  8058. dev_err(tavil->dev, "%s: ext clk enable failed\n",
  8059. __func__);
  8060. goto done;
  8061. }
  8062. /* get BG */
  8063. wcd_resmgr_enable_master_bias(tavil->resmgr);
  8064. /* get MCLK */
  8065. wcd_resmgr_enable_clk_block(tavil->resmgr, WCD_CLK_MCLK);
  8066. } else {
  8067. /* put MCLK */
  8068. wcd_resmgr_disable_clk_block(tavil->resmgr, WCD_CLK_MCLK);
  8069. /* put BG */
  8070. wcd_resmgr_disable_master_bias(tavil->resmgr);
  8071. clk_disable_unprepare(tavil->wcd_ext_clk);
  8072. }
  8073. done:
  8074. return ret;
  8075. }
  8076. static int __tavil_cdc_mclk_enable_locked(struct tavil_priv *tavil,
  8077. bool enable)
  8078. {
  8079. int ret = 0;
  8080. if (!tavil->wcd_ext_clk) {
  8081. dev_err(tavil->dev, "%s: wcd ext clock is NULL\n", __func__);
  8082. return -EINVAL;
  8083. }
  8084. dev_dbg(tavil->dev, "%s: mclk_enable = %u\n", __func__, enable);
  8085. if (enable) {
  8086. tavil_dig_core_power_collapse(tavil, POWER_RESUME);
  8087. tavil_vote_svs(tavil, true);
  8088. ret = tavil_cdc_req_mclk_enable(tavil, true);
  8089. if (ret)
  8090. goto done;
  8091. } else {
  8092. tavil_cdc_req_mclk_enable(tavil, false);
  8093. tavil_vote_svs(tavil, false);
  8094. tavil_dig_core_power_collapse(tavil, POWER_COLLAPSE);
  8095. }
  8096. done:
  8097. return ret;
  8098. }
  8099. static int __tavil_cdc_mclk_enable(struct tavil_priv *tavil,
  8100. bool enable)
  8101. {
  8102. int ret;
  8103. WCD9XXX_V2_BG_CLK_LOCK(tavil->resmgr);
  8104. ret = __tavil_cdc_mclk_enable_locked(tavil, enable);
  8105. if (enable)
  8106. wcd_resmgr_set_sido_input_src(tavil->resmgr,
  8107. SIDO_SOURCE_RCO_BG);
  8108. WCD9XXX_V2_BG_CLK_UNLOCK(tavil->resmgr);
  8109. return ret;
  8110. }
  8111. static ssize_t tavil_codec_version_read(struct snd_info_entry *entry,
  8112. void *file_private_data,
  8113. struct file *file,
  8114. char __user *buf, size_t count,
  8115. loff_t pos)
  8116. {
  8117. struct tavil_priv *tavil;
  8118. struct wcd9xxx *wcd9xxx;
  8119. char buffer[TAVIL_VERSION_ENTRY_SIZE];
  8120. int len = 0;
  8121. tavil = (struct tavil_priv *) entry->private_data;
  8122. if (!tavil) {
  8123. pr_err("%s: tavil priv is null\n", __func__);
  8124. return -EINVAL;
  8125. }
  8126. wcd9xxx = tavil->wcd9xxx;
  8127. switch (wcd9xxx->version) {
  8128. case TAVIL_VERSION_WCD9340_1_0:
  8129. len = snprintf(buffer, sizeof(buffer), "WCD9340_1_0\n");
  8130. break;
  8131. case TAVIL_VERSION_WCD9341_1_0:
  8132. len = snprintf(buffer, sizeof(buffer), "WCD9341_1_0\n");
  8133. break;
  8134. case TAVIL_VERSION_WCD9340_1_1:
  8135. len = snprintf(buffer, sizeof(buffer), "WCD9340_1_1\n");
  8136. break;
  8137. case TAVIL_VERSION_WCD9341_1_1:
  8138. len = snprintf(buffer, sizeof(buffer), "WCD9341_1_1\n");
  8139. break;
  8140. default:
  8141. len = snprintf(buffer, sizeof(buffer), "VER_UNDEFINED\n");
  8142. }
  8143. return simple_read_from_buffer(buf, count, &pos, buffer, len);
  8144. }
  8145. static struct snd_info_entry_ops tavil_codec_info_ops = {
  8146. .read = tavil_codec_version_read,
  8147. };
  8148. /*
  8149. * tavil_codec_info_create_codec_entry - creates wcd934x module
  8150. * @codec_root: The parent directory
  8151. * @codec: Codec instance
  8152. *
  8153. * Creates wcd934x module and version entry under the given
  8154. * parent directory.
  8155. *
  8156. * Return: 0 on success or negative error code on failure.
  8157. */
  8158. int tavil_codec_info_create_codec_entry(struct snd_info_entry *codec_root,
  8159. struct snd_soc_codec *codec)
  8160. {
  8161. struct snd_info_entry *version_entry;
  8162. struct tavil_priv *tavil;
  8163. struct snd_soc_card *card;
  8164. if (!codec_root || !codec)
  8165. return -EINVAL;
  8166. tavil = snd_soc_codec_get_drvdata(codec);
  8167. card = codec->component.card;
  8168. tavil->entry = snd_info_create_subdir(codec_root->module,
  8169. "tavil", codec_root);
  8170. if (!tavil->entry) {
  8171. dev_dbg(codec->dev, "%s: failed to create wcd934x entry\n",
  8172. __func__);
  8173. return -ENOMEM;
  8174. }
  8175. version_entry = snd_info_create_card_entry(card->snd_card,
  8176. "version",
  8177. tavil->entry);
  8178. if (!version_entry) {
  8179. dev_dbg(codec->dev, "%s: failed to create wcd934x version entry\n",
  8180. __func__);
  8181. return -ENOMEM;
  8182. }
  8183. version_entry->private_data = tavil;
  8184. version_entry->size = TAVIL_VERSION_ENTRY_SIZE;
  8185. version_entry->content = SNDRV_INFO_CONTENT_DATA;
  8186. version_entry->c.ops = &tavil_codec_info_ops;
  8187. if (snd_info_register(version_entry) < 0) {
  8188. snd_info_free_entry(version_entry);
  8189. return -ENOMEM;
  8190. }
  8191. tavil->version_entry = version_entry;
  8192. return 0;
  8193. }
  8194. EXPORT_SYMBOL(tavil_codec_info_create_codec_entry);
  8195. /**
  8196. * tavil_cdc_mclk_enable - Enable/disable codec mclk
  8197. *
  8198. * @codec: codec instance
  8199. * @enable: Indicates clk enable or disable
  8200. *
  8201. * Returns 0 on Success and error on failure
  8202. */
  8203. int tavil_cdc_mclk_enable(struct snd_soc_codec *codec, bool enable)
  8204. {
  8205. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  8206. return __tavil_cdc_mclk_enable(tavil, enable);
  8207. }
  8208. EXPORT_SYMBOL(tavil_cdc_mclk_enable);
  8209. static int __tavil_codec_internal_rco_ctrl(struct snd_soc_codec *codec,
  8210. bool enable)
  8211. {
  8212. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  8213. int ret = 0;
  8214. if (enable) {
  8215. if (wcd_resmgr_get_clk_type(tavil->resmgr) ==
  8216. WCD_CLK_RCO) {
  8217. ret = wcd_resmgr_enable_clk_block(tavil->resmgr,
  8218. WCD_CLK_RCO);
  8219. } else {
  8220. ret = tavil_cdc_req_mclk_enable(tavil, true);
  8221. if (ret) {
  8222. dev_err(codec->dev,
  8223. "%s: mclk_enable failed, err = %d\n",
  8224. __func__, ret);
  8225. goto done;
  8226. }
  8227. wcd_resmgr_set_sido_input_src(tavil->resmgr,
  8228. SIDO_SOURCE_RCO_BG);
  8229. ret = wcd_resmgr_enable_clk_block(tavil->resmgr,
  8230. WCD_CLK_RCO);
  8231. ret |= tavil_cdc_req_mclk_enable(tavil, false);
  8232. }
  8233. } else {
  8234. ret = wcd_resmgr_disable_clk_block(tavil->resmgr,
  8235. WCD_CLK_RCO);
  8236. }
  8237. if (ret) {
  8238. dev_err(codec->dev, "%s: Error in %s RCO\n",
  8239. __func__, (enable ? "enabling" : "disabling"));
  8240. ret = -EINVAL;
  8241. }
  8242. done:
  8243. return ret;
  8244. }
  8245. /*
  8246. * tavil_codec_internal_rco_ctrl: Enable/Disable codec's RCO clock
  8247. * @codec: Handle to the codec
  8248. * @enable: Indicates whether clock should be enabled or disabled
  8249. */
  8250. static int tavil_codec_internal_rco_ctrl(struct snd_soc_codec *codec,
  8251. bool enable)
  8252. {
  8253. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  8254. int ret = 0;
  8255. WCD9XXX_V2_BG_CLK_LOCK(tavil->resmgr);
  8256. ret = __tavil_codec_internal_rco_ctrl(codec, enable);
  8257. WCD9XXX_V2_BG_CLK_UNLOCK(tavil->resmgr);
  8258. return ret;
  8259. }
  8260. /*
  8261. * tavil_cdc_mclk_tx_enable: Enable/Disable codec's clock for TX path
  8262. * @codec: Handle to codec
  8263. * @enable: Indicates whether clock should be enabled or disabled
  8264. */
  8265. int tavil_cdc_mclk_tx_enable(struct snd_soc_codec *codec, bool enable)
  8266. {
  8267. struct tavil_priv *tavil_p;
  8268. int ret = 0;
  8269. bool clk_mode;
  8270. bool clk_internal;
  8271. if (!codec)
  8272. return -EINVAL;
  8273. tavil_p = snd_soc_codec_get_drvdata(codec);
  8274. clk_mode = test_bit(CLK_MODE, &tavil_p->status_mask);
  8275. clk_internal = test_bit(CLK_INTERNAL, &tavil_p->status_mask);
  8276. dev_dbg(codec->dev, "%s: clkmode: %d, enable: %d, clk_internal: %d\n",
  8277. __func__, clk_mode, enable, clk_internal);
  8278. if (clk_mode || clk_internal) {
  8279. if (enable) {
  8280. wcd_resmgr_enable_master_bias(tavil_p->resmgr);
  8281. tavil_dig_core_power_collapse(tavil_p, POWER_RESUME);
  8282. tavil_vote_svs(tavil_p, true);
  8283. ret = tavil_codec_internal_rco_ctrl(codec, enable);
  8284. set_bit(CLK_INTERNAL, &tavil_p->status_mask);
  8285. } else {
  8286. clear_bit(CLK_INTERNAL, &tavil_p->status_mask);
  8287. tavil_codec_internal_rco_ctrl(codec, enable);
  8288. tavil_vote_svs(tavil_p, false);
  8289. tavil_dig_core_power_collapse(tavil_p, POWER_COLLAPSE);
  8290. wcd_resmgr_disable_master_bias(tavil_p->resmgr);
  8291. }
  8292. } else {
  8293. ret = __tavil_cdc_mclk_enable(tavil_p, enable);
  8294. }
  8295. return ret;
  8296. }
  8297. EXPORT_SYMBOL(tavil_cdc_mclk_tx_enable);
  8298. static const struct wcd_resmgr_cb tavil_resmgr_cb = {
  8299. .cdc_rco_ctrl = __tavil_codec_internal_rco_ctrl,
  8300. };
  8301. static const struct tavil_reg_mask_val tavil_codec_mclk2_1_1_defaults[] = {
  8302. {WCD934X_CLK_SYS_MCLK2_PRG1, 0x60, 0x20},
  8303. };
  8304. static const struct tavil_reg_mask_val tavil_codec_mclk2_1_0_defaults[] = {
  8305. /*
  8306. * PLL Settings:
  8307. * Clock Root: MCLK2,
  8308. * Clock Source: EXT_CLK,
  8309. * Clock Destination: MCLK2
  8310. * Clock Freq In: 19.2MHz,
  8311. * Clock Freq Out: 11.2896MHz
  8312. */
  8313. {WCD934X_CLK_SYS_MCLK2_PRG1, 0x60, 0x20},
  8314. {WCD934X_CLK_SYS_INT_POST_DIV_REG0, 0xFF, 0x5E},
  8315. {WCD934X_CLK_SYS_INT_POST_DIV_REG1, 0x1F, 0x1F},
  8316. {WCD934X_CLK_SYS_INT_REF_DIV_REG0, 0xFF, 0x54},
  8317. {WCD934X_CLK_SYS_INT_REF_DIV_REG1, 0xFF, 0x01},
  8318. {WCD934X_CLK_SYS_INT_FILTER_REG1, 0x07, 0x04},
  8319. {WCD934X_CLK_SYS_INT_PLL_L_VAL, 0xFF, 0x93},
  8320. {WCD934X_CLK_SYS_INT_PLL_N_VAL, 0xFF, 0xFA},
  8321. {WCD934X_CLK_SYS_INT_TEST_REG0, 0xFF, 0x90},
  8322. {WCD934X_CLK_SYS_INT_PFD_CP_DSM_PROG, 0xFF, 0x7E},
  8323. {WCD934X_CLK_SYS_INT_VCO_PROG, 0xFF, 0xF8},
  8324. {WCD934X_CLK_SYS_INT_TEST_REG1, 0xFF, 0x68},
  8325. {WCD934X_CLK_SYS_INT_LDO_LOCK_CFG, 0xFF, 0x40},
  8326. {WCD934X_CLK_SYS_INT_DIG_LOCK_DET_CFG, 0xFF, 0x32},
  8327. };
  8328. static const struct tavil_reg_mask_val tavil_codec_reg_defaults[] = {
  8329. {WCD934X_BIAS_VBG_FINE_ADJ, 0xFF, 0x75},
  8330. {WCD934X_CODEC_CPR_SVS_CX_VDD, 0xFF, 0x7C}, /* value in svs mode */
  8331. {WCD934X_CODEC_CPR_SVS2_CX_VDD, 0xFF, 0x58}, /* value in svs2 mode */
  8332. {WCD934X_CDC_RX0_RX_PATH_DSMDEM_CTL, 0x01, 0x01},
  8333. {WCD934X_CDC_RX1_RX_PATH_DSMDEM_CTL, 0x01, 0x01},
  8334. {WCD934X_CDC_RX2_RX_PATH_DSMDEM_CTL, 0x01, 0x01},
  8335. {WCD934X_CDC_RX3_RX_PATH_DSMDEM_CTL, 0x01, 0x01},
  8336. {WCD934X_CDC_RX4_RX_PATH_DSMDEM_CTL, 0x01, 0x01},
  8337. {WCD934X_CDC_RX7_RX_PATH_DSMDEM_CTL, 0x01, 0x01},
  8338. {WCD934X_CDC_RX8_RX_PATH_DSMDEM_CTL, 0x01, 0x01},
  8339. {WCD934X_CDC_COMPANDER8_CTL7, 0x1E, 0x18},
  8340. {WCD934X_CDC_COMPANDER7_CTL7, 0x1E, 0x18},
  8341. {WCD934X_CDC_RX0_RX_PATH_SEC0, 0x08, 0x0},
  8342. {WCD934X_CDC_CLSH_DECAY_CTRL, 0x03, 0x0},
  8343. {WCD934X_MICB1_TEST_CTL_2, 0x07, 0x01},
  8344. {WCD934X_CDC_BOOST0_BOOST_CFG1, 0x3F, 0x12},
  8345. {WCD934X_CDC_BOOST0_BOOST_CFG2, 0x1C, 0x08},
  8346. {WCD934X_CDC_BOOST1_BOOST_CFG1, 0x3F, 0x12},
  8347. {WCD934X_CDC_BOOST1_BOOST_CFG2, 0x1C, 0x08},
  8348. {WCD934X_CPE_SS_CPARMAD_BUFRDY_INT_PERIOD, 0x1F, 0x09},
  8349. {WCD934X_CDC_TX0_TX_PATH_CFG1, 0x01, 0x00},
  8350. {WCD934X_CDC_TX1_TX_PATH_CFG1, 0x01, 0x00},
  8351. {WCD934X_CDC_TX2_TX_PATH_CFG1, 0x01, 0x00},
  8352. {WCD934X_CDC_TX3_TX_PATH_CFG1, 0x01, 0x00},
  8353. {WCD934X_CDC_TX4_TX_PATH_CFG1, 0x01, 0x00},
  8354. {WCD934X_CDC_TX5_TX_PATH_CFG1, 0x01, 0x00},
  8355. {WCD934X_CDC_TX6_TX_PATH_CFG1, 0x01, 0x00},
  8356. {WCD934X_CDC_TX7_TX_PATH_CFG1, 0x01, 0x00},
  8357. {WCD934X_CDC_TX8_TX_PATH_CFG1, 0x01, 0x00},
  8358. {WCD934X_RX_OCP_CTL, 0x0F, 0x02}, /* OCP number of attempts is 2 */
  8359. {WCD934X_HPH_OCP_CTL, 0xFF, 0x3A}, /* OCP current limit */
  8360. {WCD934X_HPH_L_TEST, 0x01, 0x01},
  8361. {WCD934X_HPH_R_TEST, 0x01, 0x01},
  8362. {WCD934X_CPE_FLL_CONFIG_CTL_2, 0xFF, 0x20},
  8363. {WCD934X_MBHC_NEW_CTL_2, 0x0C, 0x00},
  8364. {WCD934X_CODEC_RPM_CLK_MCLK_CFG, 0x04, 0x04},
  8365. };
  8366. static const struct tavil_reg_mask_val tavil_codec_reg_init_1_1_val[] = {
  8367. {WCD934X_CDC_COMPANDER1_CTL7, 0x1E, 0x06},
  8368. {WCD934X_CDC_COMPANDER2_CTL7, 0x1E, 0x06},
  8369. {WCD934X_HPH_NEW_INT_RDAC_HD2_CTL_L, 0xFF, 0x84},
  8370. {WCD934X_HPH_NEW_INT_RDAC_HD2_CTL_R, 0xFF, 0x84},
  8371. {WCD934X_CDC_RX3_RX_PATH_SEC0, 0xFC, 0xF4},
  8372. {WCD934X_CDC_RX4_RX_PATH_SEC0, 0xFC, 0xF4},
  8373. };
  8374. static const struct tavil_cpr_reg_defaults cpr_defaults[] = {
  8375. { 0x00000820, 0x00000094 },
  8376. { 0x00000fC0, 0x00000048 },
  8377. { 0x0000f000, 0x00000044 },
  8378. { 0x0000bb80, 0xC0000178 },
  8379. { 0x00000000, 0x00000160 },
  8380. { 0x10854522, 0x00000060 },
  8381. { 0x10854509, 0x00000064 },
  8382. { 0x108544dd, 0x00000068 },
  8383. { 0x108544ad, 0x0000006C },
  8384. { 0x0000077E, 0x00000070 },
  8385. { 0x000007da, 0x00000074 },
  8386. { 0x00000000, 0x00000078 },
  8387. { 0x00000000, 0x0000007C },
  8388. { 0x00042029, 0x00000080 },
  8389. { 0x4002002A, 0x00000090 },
  8390. { 0x4002002B, 0x00000090 },
  8391. };
  8392. static const struct tavil_reg_mask_val tavil_codec_reg_init_common_val[] = {
  8393. {WCD934X_CDC_CLSH_K2_MSB, 0x0F, 0x00},
  8394. {WCD934X_CDC_CLSH_K2_LSB, 0xFF, 0x60},
  8395. {WCD934X_CPE_SS_DMIC_CFG, 0x80, 0x00},
  8396. {WCD934X_CDC_BOOST0_BOOST_CTL, 0x7C, 0x58},
  8397. {WCD934X_CDC_BOOST1_BOOST_CTL, 0x7C, 0x58},
  8398. {WCD934X_CDC_RX7_RX_PATH_CFG1, 0x08, 0x08},
  8399. {WCD934X_CDC_RX8_RX_PATH_CFG1, 0x08, 0x08},
  8400. {WCD934X_CDC_TOP_TOP_CFG1, 0x02, 0x02},
  8401. {WCD934X_CDC_TOP_TOP_CFG1, 0x01, 0x01},
  8402. {WCD934X_CDC_TX9_SPKR_PROT_PATH_CFG0, 0x01, 0x01},
  8403. {WCD934X_CDC_TX10_SPKR_PROT_PATH_CFG0, 0x01, 0x01},
  8404. {WCD934X_CDC_TX11_SPKR_PROT_PATH_CFG0, 0x01, 0x01},
  8405. {WCD934X_CDC_TX12_SPKR_PROT_PATH_CFG0, 0x01, 0x01},
  8406. {WCD934X_DATA_HUB_SB_TX11_INP_CFG, 0x01, 0x01},
  8407. {WCD934X_CDC_CLK_RST_CTRL_FS_CNT_CONTROL, 0x01, 0x01},
  8408. {WCD934X_CDC_COMPANDER7_CTL3, 0x80, 0x80},
  8409. {WCD934X_CDC_COMPANDER8_CTL3, 0x80, 0x80},
  8410. {WCD934X_CDC_COMPANDER7_CTL7, 0x01, 0x01},
  8411. {WCD934X_CDC_COMPANDER8_CTL7, 0x01, 0x01},
  8412. {WCD934X_CODEC_RPM_CLK_GATE, 0x08, 0x00},
  8413. {WCD934X_TLMM_DMIC3_CLK_PINCFG, 0xFF, 0x0a},
  8414. {WCD934X_TLMM_DMIC3_DATA_PINCFG, 0xFF, 0x0a},
  8415. {WCD934X_CPE_SS_SVA_CFG, 0x60, 0x00},
  8416. {WCD934X_CPE_SS_CPAR_CFG, 0x10, 0x10},
  8417. {WCD934X_MICB1_TEST_CTL_1, 0xff, 0xfa},
  8418. {WCD934X_MICB2_TEST_CTL_1, 0xff, 0xfa},
  8419. {WCD934X_MICB3_TEST_CTL_1, 0xff, 0xfa},
  8420. {WCD934X_MICB4_TEST_CTL_1, 0xff, 0xfa},
  8421. };
  8422. static void tavil_codec_init_reg(struct tavil_priv *priv)
  8423. {
  8424. struct snd_soc_codec *codec = priv->codec;
  8425. u32 i;
  8426. for (i = 0; i < ARRAY_SIZE(tavil_codec_reg_init_common_val); i++)
  8427. snd_soc_update_bits(codec,
  8428. tavil_codec_reg_init_common_val[i].reg,
  8429. tavil_codec_reg_init_common_val[i].mask,
  8430. tavil_codec_reg_init_common_val[i].val);
  8431. if (TAVIL_IS_1_1(priv->wcd9xxx)) {
  8432. for (i = 0; i < ARRAY_SIZE(tavil_codec_reg_init_1_1_val); i++)
  8433. snd_soc_update_bits(codec,
  8434. tavil_codec_reg_init_1_1_val[i].reg,
  8435. tavil_codec_reg_init_1_1_val[i].mask,
  8436. tavil_codec_reg_init_1_1_val[i].val);
  8437. }
  8438. }
  8439. static const struct tavil_reg_mask_val tavil_codec_reg_i2c_defaults[] = {
  8440. {WCD934X_CLK_SYS_MCLK_PRG, 0x40, 0x00},
  8441. {WCD934X_CODEC_RPM_CLK_GATE, 0x03, 0x01},
  8442. {WCD934X_CODEC_RPM_CLK_MCLK_CFG, 0x03, 0x00},
  8443. {WCD934X_CODEC_RPM_CLK_MCLK_CFG, 0x05, 0x05},
  8444. {WCD934X_DATA_HUB_RX0_CFG, 0x71, 0x31},
  8445. {WCD934X_DATA_HUB_RX1_CFG, 0x71, 0x31},
  8446. {WCD934X_DATA_HUB_RX2_CFG, 0x03, 0x01},
  8447. {WCD934X_DATA_HUB_RX3_CFG, 0x03, 0x01},
  8448. {WCD934X_DATA_HUB_I2S_TX0_CFG, 0x01, 0x01},
  8449. {WCD934X_DATA_HUB_I2S_TX0_CFG, 0x04, 0x01},
  8450. {WCD934X_DATA_HUB_I2S_TX1_0_CFG, 0x01, 0x01},
  8451. {WCD934X_DATA_HUB_I2S_TX1_1_CFG, 0x05, 0x05},
  8452. {WCD934X_CHIP_TIER_CTRL_ALT_FUNC_EN, 0x1, 0x1},
  8453. };
  8454. static void tavil_update_reg_defaults(struct tavil_priv *tavil)
  8455. {
  8456. u32 i;
  8457. struct wcd9xxx *wcd9xxx;
  8458. wcd9xxx = tavil->wcd9xxx;
  8459. for (i = 0; i < ARRAY_SIZE(tavil_codec_reg_defaults); i++)
  8460. regmap_update_bits(wcd9xxx->regmap,
  8461. tavil_codec_reg_defaults[i].reg,
  8462. tavil_codec_reg_defaults[i].mask,
  8463. tavil_codec_reg_defaults[i].val);
  8464. if (tavil->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
  8465. for (i = 0; i < ARRAY_SIZE(tavil_codec_reg_i2c_defaults); i++) {
  8466. regmap_update_bits(wcd9xxx->regmap,
  8467. tavil_codec_reg_i2c_defaults[i].reg,
  8468. tavil_codec_reg_i2c_defaults[i].mask,
  8469. tavil_codec_reg_i2c_defaults[i].val);
  8470. }
  8471. }
  8472. }
  8473. static void tavil_update_cpr_defaults(struct tavil_priv *tavil)
  8474. {
  8475. int i;
  8476. struct wcd9xxx *wcd9xxx;
  8477. wcd9xxx = tavil->wcd9xxx;
  8478. if (!TAVIL_IS_1_1(wcd9xxx))
  8479. return;
  8480. __tavil_cdc_mclk_enable(tavil, true);
  8481. regmap_write(wcd9xxx->regmap, WCD934X_CODEC_CPR_SVS2_MIN_CX_VDD, 0x2C);
  8482. regmap_update_bits(wcd9xxx->regmap, WCD934X_CODEC_RPM_CLK_GATE,
  8483. 0x10, 0x00);
  8484. for (i = 0; i < ARRAY_SIZE(cpr_defaults); i++) {
  8485. regmap_bulk_write(wcd9xxx->regmap,
  8486. WCD934X_CODEC_CPR_WR_DATA_0,
  8487. (u8 *)&cpr_defaults[i].wr_data, 4);
  8488. regmap_bulk_write(wcd9xxx->regmap,
  8489. WCD934X_CODEC_CPR_WR_ADDR_0,
  8490. (u8 *)&cpr_defaults[i].wr_addr, 4);
  8491. }
  8492. __tavil_cdc_mclk_enable(tavil, false);
  8493. }
  8494. static void tavil_slim_interface_init_reg(struct snd_soc_codec *codec)
  8495. {
  8496. int i;
  8497. struct tavil_priv *priv = snd_soc_codec_get_drvdata(codec);
  8498. for (i = 0; i < WCD9XXX_SLIM_NUM_PORT_REG; i++)
  8499. wcd9xxx_interface_reg_write(priv->wcd9xxx,
  8500. WCD934X_SLIM_PGD_PORT_INT_RX_EN0 + i,
  8501. 0xFF);
  8502. }
  8503. static irqreturn_t tavil_misc_irq(int irq, void *data)
  8504. {
  8505. struct tavil_priv *tavil = data;
  8506. int misc_val;
  8507. /* Find source of interrupt */
  8508. regmap_read(tavil->wcd9xxx->regmap, WCD934X_INTR_CODEC_MISC_STATUS,
  8509. &misc_val);
  8510. if (misc_val & 0x08) {
  8511. dev_info(tavil->dev, "%s: irq: %d, DSD DC detected!\n",
  8512. __func__, irq);
  8513. /* DSD DC interrupt, reset DSD path */
  8514. tavil_dsd_reset(tavil->dsd_config);
  8515. } else {
  8516. dev_err(tavil->dev, "%s: Codec misc irq: %d, val: 0x%x\n",
  8517. __func__, irq, misc_val);
  8518. }
  8519. /* Clear interrupt status */
  8520. regmap_update_bits(tavil->wcd9xxx->regmap,
  8521. WCD934X_INTR_CODEC_MISC_CLEAR, misc_val, 0x00);
  8522. return IRQ_HANDLED;
  8523. }
  8524. static irqreturn_t tavil_slimbus_irq(int irq, void *data)
  8525. {
  8526. struct tavil_priv *tavil = data;
  8527. unsigned long status = 0;
  8528. int i, j, port_id, k;
  8529. u32 bit;
  8530. u8 val, int_val = 0;
  8531. bool tx, cleared;
  8532. unsigned short reg = 0;
  8533. for (i = WCD934X_SLIM_PGD_PORT_INT_STATUS_RX_0, j = 0;
  8534. i <= WCD934X_SLIM_PGD_PORT_INT_STATUS_TX_1; i++, j++) {
  8535. val = wcd9xxx_interface_reg_read(tavil->wcd9xxx, i);
  8536. status |= ((u32)val << (8 * j));
  8537. }
  8538. for_each_set_bit(j, &status, 32) {
  8539. tx = (j >= 16 ? true : false);
  8540. port_id = (tx ? j - 16 : j);
  8541. val = wcd9xxx_interface_reg_read(tavil->wcd9xxx,
  8542. WCD934X_SLIM_PGD_PORT_INT_RX_SOURCE0 + j);
  8543. if (val) {
  8544. if (!tx)
  8545. reg = WCD934X_SLIM_PGD_PORT_INT_RX_EN0 +
  8546. (port_id / 8);
  8547. else
  8548. reg = WCD934X_SLIM_PGD_PORT_INT_TX_EN0 +
  8549. (port_id / 8);
  8550. int_val = wcd9xxx_interface_reg_read(
  8551. tavil->wcd9xxx, reg);
  8552. /*
  8553. * Ignore interrupts for ports for which the
  8554. * interrupts are not specifically enabled.
  8555. */
  8556. if (!(int_val & (1 << (port_id % 8))))
  8557. continue;
  8558. }
  8559. if (val & WCD934X_SLIM_IRQ_OVERFLOW)
  8560. dev_err_ratelimited(tavil->dev, "%s: overflow error on %s port %d, value %x\n",
  8561. __func__, (tx ? "TX" : "RX"), port_id, val);
  8562. if (val & WCD934X_SLIM_IRQ_UNDERFLOW)
  8563. dev_err_ratelimited(tavil->dev, "%s: underflow error on %s port %d, value %x\n",
  8564. __func__, (tx ? "TX" : "RX"), port_id, val);
  8565. if ((val & WCD934X_SLIM_IRQ_OVERFLOW) ||
  8566. (val & WCD934X_SLIM_IRQ_UNDERFLOW)) {
  8567. if (!tx)
  8568. reg = WCD934X_SLIM_PGD_PORT_INT_RX_EN0 +
  8569. (port_id / 8);
  8570. else
  8571. reg = WCD934X_SLIM_PGD_PORT_INT_TX_EN0 +
  8572. (port_id / 8);
  8573. int_val = wcd9xxx_interface_reg_read(
  8574. tavil->wcd9xxx, reg);
  8575. if (int_val & (1 << (port_id % 8))) {
  8576. int_val = int_val ^ (1 << (port_id % 8));
  8577. wcd9xxx_interface_reg_write(tavil->wcd9xxx,
  8578. reg, int_val);
  8579. }
  8580. }
  8581. if (val & WCD934X_SLIM_IRQ_PORT_CLOSED) {
  8582. /*
  8583. * INT SOURCE register starts from RX to TX
  8584. * but port number in the ch_mask is in opposite way
  8585. */
  8586. bit = (tx ? j - 16 : j + 16);
  8587. dev_dbg(tavil->dev, "%s: %s port %d closed value %x, bit %u\n",
  8588. __func__, (tx ? "TX" : "RX"), port_id, val,
  8589. bit);
  8590. for (k = 0, cleared = false; k < NUM_CODEC_DAIS; k++) {
  8591. dev_dbg(tavil->dev, "%s: tavil->dai[%d].ch_mask = 0x%lx\n",
  8592. __func__, k, tavil->dai[k].ch_mask);
  8593. if (test_and_clear_bit(bit,
  8594. &tavil->dai[k].ch_mask)) {
  8595. cleared = true;
  8596. if (!tavil->dai[k].ch_mask)
  8597. wake_up(
  8598. &tavil->dai[k].dai_wait);
  8599. /*
  8600. * There are cases when multiple DAIs
  8601. * might be using the same slimbus
  8602. * channel. Hence don't break here.
  8603. */
  8604. }
  8605. }
  8606. WARN(!cleared,
  8607. "Couldn't find slimbus %s port %d for closing\n",
  8608. (tx ? "TX" : "RX"), port_id);
  8609. }
  8610. wcd9xxx_interface_reg_write(tavil->wcd9xxx,
  8611. WCD934X_SLIM_PGD_PORT_INT_CLR_RX_0 +
  8612. (j / 8),
  8613. 1 << (j % 8));
  8614. }
  8615. return IRQ_HANDLED;
  8616. }
  8617. static int tavil_setup_irqs(struct tavil_priv *tavil)
  8618. {
  8619. int ret = 0;
  8620. struct snd_soc_codec *codec = tavil->codec;
  8621. struct wcd9xxx *wcd9xxx = tavil->wcd9xxx;
  8622. struct wcd9xxx_core_resource *core_res =
  8623. &wcd9xxx->core_res;
  8624. ret = wcd9xxx_request_irq(core_res, WCD9XXX_IRQ_SLIMBUS,
  8625. tavil_slimbus_irq, "SLIMBUS Slave", tavil);
  8626. if (ret)
  8627. dev_err(codec->dev, "%s: Failed to request irq %d\n", __func__,
  8628. WCD9XXX_IRQ_SLIMBUS);
  8629. else
  8630. tavil_slim_interface_init_reg(codec);
  8631. /* Register for misc interrupts as well */
  8632. ret = wcd9xxx_request_irq(core_res, WCD934X_IRQ_MISC,
  8633. tavil_misc_irq, "CDC MISC Irq", tavil);
  8634. if (ret)
  8635. dev_err(codec->dev, "%s: Failed to request cdc misc irq\n",
  8636. __func__);
  8637. return ret;
  8638. }
  8639. static void tavil_init_slim_slave_cfg(struct snd_soc_codec *codec)
  8640. {
  8641. struct tavil_priv *priv = snd_soc_codec_get_drvdata(codec);
  8642. struct afe_param_cdc_slimbus_slave_cfg *cfg;
  8643. struct wcd9xxx *wcd9xxx = priv->wcd9xxx;
  8644. uint64_t eaddr = 0;
  8645. cfg = &priv->slimbus_slave_cfg;
  8646. cfg->minor_version = 1;
  8647. cfg->tx_slave_port_offset = 0;
  8648. cfg->rx_slave_port_offset = 16;
  8649. memcpy(&eaddr, &wcd9xxx->slim->e_addr, sizeof(wcd9xxx->slim->e_addr));
  8650. WARN_ON(sizeof(wcd9xxx->slim->e_addr) != 6);
  8651. cfg->device_enum_addr_lsw = eaddr & 0xFFFFFFFF;
  8652. cfg->device_enum_addr_msw = eaddr >> 32;
  8653. dev_dbg(codec->dev, "%s: slimbus logical address 0x%llx\n",
  8654. __func__, eaddr);
  8655. }
  8656. static void tavil_cleanup_irqs(struct tavil_priv *tavil)
  8657. {
  8658. struct wcd9xxx *wcd9xxx = tavil->wcd9xxx;
  8659. struct wcd9xxx_core_resource *core_res =
  8660. &wcd9xxx->core_res;
  8661. wcd9xxx_free_irq(core_res, WCD9XXX_IRQ_SLIMBUS, tavil);
  8662. wcd9xxx_free_irq(core_res, WCD934X_IRQ_MISC, tavil);
  8663. }
  8664. /*
  8665. * wcd934x_get_micb_vout_ctl_val: converts micbias from volts to register value
  8666. * @micb_mv: micbias in mv
  8667. *
  8668. * return register value converted
  8669. */
  8670. int wcd934x_get_micb_vout_ctl_val(u32 micb_mv)
  8671. {
  8672. /* min micbias voltage is 1V and maximum is 2.85V */
  8673. if (micb_mv < 1000 || micb_mv > 2850) {
  8674. pr_err("%s: unsupported micbias voltage\n", __func__);
  8675. return -EINVAL;
  8676. }
  8677. return (micb_mv - 1000) / 50;
  8678. }
  8679. EXPORT_SYMBOL(wcd934x_get_micb_vout_ctl_val);
  8680. static int tavil_handle_pdata(struct tavil_priv *tavil,
  8681. struct wcd9xxx_pdata *pdata)
  8682. {
  8683. struct snd_soc_codec *codec = tavil->codec;
  8684. u8 mad_dmic_ctl_val;
  8685. u8 anc_ctl_value;
  8686. u32 def_dmic_rate, dmic_clk_drv;
  8687. int vout_ctl_1, vout_ctl_2, vout_ctl_3, vout_ctl_4;
  8688. int rc = 0;
  8689. if (!pdata) {
  8690. dev_err(codec->dev, "%s: NULL pdata\n", __func__);
  8691. return -ENODEV;
  8692. }
  8693. /* set micbias voltage */
  8694. vout_ctl_1 = wcd934x_get_micb_vout_ctl_val(pdata->micbias.micb1_mv);
  8695. vout_ctl_2 = wcd934x_get_micb_vout_ctl_val(pdata->micbias.micb2_mv);
  8696. vout_ctl_3 = wcd934x_get_micb_vout_ctl_val(pdata->micbias.micb3_mv);
  8697. vout_ctl_4 = wcd934x_get_micb_vout_ctl_val(pdata->micbias.micb4_mv);
  8698. if (vout_ctl_1 < 0 || vout_ctl_2 < 0 ||
  8699. vout_ctl_3 < 0 || vout_ctl_4 < 0) {
  8700. rc = -EINVAL;
  8701. goto done;
  8702. }
  8703. snd_soc_update_bits(codec, WCD934X_ANA_MICB1, 0x3F, vout_ctl_1);
  8704. snd_soc_update_bits(codec, WCD934X_ANA_MICB2, 0x3F, vout_ctl_2);
  8705. snd_soc_update_bits(codec, WCD934X_ANA_MICB3, 0x3F, vout_ctl_3);
  8706. snd_soc_update_bits(codec, WCD934X_ANA_MICB4, 0x3F, vout_ctl_4);
  8707. /* Set the DMIC sample rate */
  8708. switch (pdata->mclk_rate) {
  8709. case WCD934X_MCLK_CLK_9P6MHZ:
  8710. def_dmic_rate = WCD9XXX_DMIC_SAMPLE_RATE_4P8MHZ;
  8711. break;
  8712. case WCD934X_MCLK_CLK_12P288MHZ:
  8713. def_dmic_rate = WCD9XXX_DMIC_SAMPLE_RATE_4P096MHZ;
  8714. break;
  8715. default:
  8716. /* should never happen */
  8717. dev_err(codec->dev, "%s: Invalid mclk_rate %d\n",
  8718. __func__, pdata->mclk_rate);
  8719. rc = -EINVAL;
  8720. goto done;
  8721. };
  8722. if (pdata->dmic_sample_rate ==
  8723. WCD9XXX_DMIC_SAMPLE_RATE_UNDEFINED) {
  8724. dev_info(codec->dev, "%s: dmic_rate invalid default = %d\n",
  8725. __func__, def_dmic_rate);
  8726. pdata->dmic_sample_rate = def_dmic_rate;
  8727. }
  8728. if (pdata->mad_dmic_sample_rate ==
  8729. WCD9XXX_DMIC_SAMPLE_RATE_UNDEFINED) {
  8730. dev_info(codec->dev, "%s: mad_dmic_rate invalid default = %d\n",
  8731. __func__, def_dmic_rate);
  8732. /*
  8733. * use dmic_sample_rate as the default for MAD
  8734. * if mad dmic sample rate is undefined
  8735. */
  8736. pdata->mad_dmic_sample_rate = pdata->dmic_sample_rate;
  8737. }
  8738. if (pdata->dmic_clk_drv ==
  8739. WCD9XXX_DMIC_CLK_DRIVE_UNDEFINED) {
  8740. pdata->dmic_clk_drv = WCD934X_DMIC_CLK_DRIVE_DEFAULT;
  8741. dev_dbg(codec->dev,
  8742. "%s: dmic_clk_strength invalid, default = %d\n",
  8743. __func__, pdata->dmic_clk_drv);
  8744. }
  8745. switch (pdata->dmic_clk_drv) {
  8746. case 2:
  8747. dmic_clk_drv = 0;
  8748. break;
  8749. case 4:
  8750. dmic_clk_drv = 1;
  8751. break;
  8752. case 8:
  8753. dmic_clk_drv = 2;
  8754. break;
  8755. case 16:
  8756. dmic_clk_drv = 3;
  8757. break;
  8758. default:
  8759. dev_err(codec->dev,
  8760. "%s: invalid dmic_clk_drv %d, using default\n",
  8761. __func__, pdata->dmic_clk_drv);
  8762. dmic_clk_drv = 0;
  8763. break;
  8764. }
  8765. snd_soc_update_bits(codec, WCD934X_TEST_DEBUG_PAD_DRVCTL_0,
  8766. 0x0C, dmic_clk_drv << 2);
  8767. /*
  8768. * Default the DMIC clk rates to mad_dmic_sample_rate,
  8769. * whereas, the anc/txfe dmic rates to dmic_sample_rate
  8770. * since the anc/txfe are independent of mad block.
  8771. */
  8772. mad_dmic_ctl_val = tavil_get_dmic_clk_val(tavil->codec,
  8773. pdata->mclk_rate,
  8774. pdata->mad_dmic_sample_rate);
  8775. snd_soc_update_bits(codec, WCD934X_CPE_SS_DMIC0_CTL,
  8776. 0x0E, mad_dmic_ctl_val << 1);
  8777. snd_soc_update_bits(codec, WCD934X_CPE_SS_DMIC1_CTL,
  8778. 0x0E, mad_dmic_ctl_val << 1);
  8779. snd_soc_update_bits(codec, WCD934X_CPE_SS_DMIC2_CTL,
  8780. 0x0E, mad_dmic_ctl_val << 1);
  8781. if (dmic_clk_drv == WCD934X_DMIC_CLK_DIV_2)
  8782. anc_ctl_value = WCD934X_ANC_DMIC_X2_FULL_RATE;
  8783. else
  8784. anc_ctl_value = WCD934X_ANC_DMIC_X2_HALF_RATE;
  8785. snd_soc_update_bits(codec, WCD934X_CDC_ANC0_MODE_2_CTL,
  8786. 0x40, anc_ctl_value << 6);
  8787. snd_soc_update_bits(codec, WCD934X_CDC_ANC0_MODE_2_CTL,
  8788. 0x20, anc_ctl_value << 5);
  8789. snd_soc_update_bits(codec, WCD934X_CDC_ANC1_MODE_2_CTL,
  8790. 0x40, anc_ctl_value << 6);
  8791. snd_soc_update_bits(codec, WCD934X_CDC_ANC1_MODE_2_CTL,
  8792. 0x20, anc_ctl_value << 5);
  8793. done:
  8794. return rc;
  8795. }
  8796. static void tavil_cdc_vote_svs(struct snd_soc_codec *codec, bool vote)
  8797. {
  8798. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  8799. return tavil_vote_svs(tavil, vote);
  8800. }
  8801. static struct wcd_dsp_cdc_cb cdc_cb = {
  8802. .cdc_clk_en = tavil_codec_internal_rco_ctrl,
  8803. .cdc_vote_svs = tavil_cdc_vote_svs,
  8804. };
  8805. static int tavil_wdsp_initialize(struct snd_soc_codec *codec)
  8806. {
  8807. struct wcd9xxx *control;
  8808. struct tavil_priv *tavil;
  8809. struct wcd_dsp_params params;
  8810. int ret = 0;
  8811. control = dev_get_drvdata(codec->dev->parent);
  8812. tavil = snd_soc_codec_get_drvdata(codec);
  8813. params.cb = &cdc_cb;
  8814. params.irqs.cpe_ipc1_irq = WCD934X_IRQ_CPE1_INTR;
  8815. params.irqs.cpe_err_irq = WCD934X_IRQ_CPE_ERROR;
  8816. params.irqs.fatal_irqs = CPE_FATAL_IRQS;
  8817. params.clk_rate = control->mclk_rate;
  8818. params.dsp_instance = 0;
  8819. wcd_dsp_cntl_init(codec, &params, &tavil->wdsp_cntl);
  8820. if (!tavil->wdsp_cntl) {
  8821. dev_err(tavil->dev, "%s: wcd-dsp-control init failed\n",
  8822. __func__);
  8823. ret = -EINVAL;
  8824. }
  8825. return ret;
  8826. }
  8827. /*
  8828. * tavil_soc_get_mbhc: get wcd934x_mbhc handle of corresponding codec
  8829. * @codec: handle to snd_soc_codec *
  8830. *
  8831. * return wcd934x_mbhc handle or error code in case of failure
  8832. */
  8833. struct wcd934x_mbhc *tavil_soc_get_mbhc(struct snd_soc_codec *codec)
  8834. {
  8835. struct tavil_priv *tavil;
  8836. if (!codec) {
  8837. pr_err("%s: Invalid params, NULL codec\n", __func__);
  8838. return NULL;
  8839. }
  8840. tavil = snd_soc_codec_get_drvdata(codec);
  8841. if (!tavil) {
  8842. pr_err("%s: Invalid params, NULL tavil\n", __func__);
  8843. return NULL;
  8844. }
  8845. return tavil->mbhc;
  8846. }
  8847. EXPORT_SYMBOL(tavil_soc_get_mbhc);
  8848. static void tavil_mclk2_reg_defaults(struct tavil_priv *tavil)
  8849. {
  8850. int i;
  8851. struct snd_soc_codec *codec = tavil->codec;
  8852. if (TAVIL_IS_1_0(tavil->wcd9xxx)) {
  8853. /* MCLK2 configuration */
  8854. for (i = 0; i < ARRAY_SIZE(tavil_codec_mclk2_1_0_defaults); i++)
  8855. snd_soc_update_bits(codec,
  8856. tavil_codec_mclk2_1_0_defaults[i].reg,
  8857. tavil_codec_mclk2_1_0_defaults[i].mask,
  8858. tavil_codec_mclk2_1_0_defaults[i].val);
  8859. }
  8860. if (TAVIL_IS_1_1(tavil->wcd9xxx)) {
  8861. /* MCLK2 configuration */
  8862. for (i = 0; i < ARRAY_SIZE(tavil_codec_mclk2_1_1_defaults); i++)
  8863. snd_soc_update_bits(codec,
  8864. tavil_codec_mclk2_1_1_defaults[i].reg,
  8865. tavil_codec_mclk2_1_1_defaults[i].mask,
  8866. tavil_codec_mclk2_1_1_defaults[i].val);
  8867. }
  8868. }
  8869. static int tavil_device_down(struct wcd9xxx *wcd9xxx)
  8870. {
  8871. struct snd_soc_codec *codec;
  8872. struct tavil_priv *priv;
  8873. int count;
  8874. int decimator;
  8875. int ret;
  8876. codec = (struct snd_soc_codec *)(wcd9xxx->ssr_priv);
  8877. if (!codec->component.card) {
  8878. dev_err(codec->dev, "%s: sound card is not enumerated.\n",
  8879. __func__);
  8880. return -EINVAL;
  8881. }
  8882. priv = snd_soc_codec_get_drvdata(codec);
  8883. for (count = 0; count < NUM_CODEC_DAIS; count++)
  8884. priv->dai[count].bus_down_in_recovery = true;
  8885. snd_event_notify(priv->dev->parent, SND_EVENT_DOWN);
  8886. priv->mbhc->wcd_mbhc.deinit_in_progress = true;
  8887. if (delayed_work_pending(&priv->spk_anc_dwork.dwork))
  8888. cancel_delayed_work(&priv->spk_anc_dwork.dwork);
  8889. for (decimator = 0; decimator < WCD934X_NUM_DECIMATORS; decimator++) {
  8890. if (delayed_work_pending
  8891. (&priv->tx_mute_dwork[decimator].dwork))
  8892. cancel_delayed_work
  8893. (&priv->tx_mute_dwork[decimator].dwork);
  8894. if (delayed_work_pending
  8895. (&priv->tx_hpf_work[decimator].dwork))
  8896. cancel_delayed_work
  8897. (&priv->tx_hpf_work[decimator].dwork);
  8898. }
  8899. if (delayed_work_pending(&priv->power_gate_work))
  8900. cancel_delayed_work_sync(&priv->power_gate_work);
  8901. if (delayed_work_pending(&priv->mbhc->wcd_mbhc.mbhc_btn_dwork)) {
  8902. ret = cancel_delayed_work(&priv->mbhc->wcd_mbhc.mbhc_btn_dwork);
  8903. if (ret)
  8904. priv->mbhc->wcd_mbhc.mbhc_cb->lock_sleep
  8905. (&priv->mbhc->wcd_mbhc, false);
  8906. }
  8907. if (priv->swr.ctrl_data) {
  8908. if (is_snd_event_fwk_enabled())
  8909. swrm_wcd_notify(priv->swr.ctrl_data[0].swr_pdev,
  8910. SWR_DEVICE_SSR_DOWN, NULL);
  8911. swrm_wcd_notify(priv->swr.ctrl_data[0].swr_pdev,
  8912. SWR_DEVICE_DOWN, NULL);
  8913. }
  8914. tavil_dsd_reset(priv->dsd_config);
  8915. if (!is_snd_event_fwk_enabled())
  8916. snd_soc_card_change_online_state(codec->component.card, 0);
  8917. wcd_dsp_ssr_event(priv->wdsp_cntl, WCD_CDC_DOWN_EVENT);
  8918. wcd_resmgr_set_sido_input_src_locked(priv->resmgr,
  8919. SIDO_SOURCE_INTERNAL);
  8920. return 0;
  8921. }
  8922. static int tavil_post_reset_cb(struct wcd9xxx *wcd9xxx)
  8923. {
  8924. int i, ret = 0;
  8925. struct wcd9xxx *control;
  8926. struct snd_soc_codec *codec;
  8927. struct tavil_priv *tavil;
  8928. struct wcd9xxx_pdata *pdata;
  8929. struct wcd_mbhc *mbhc;
  8930. codec = (struct snd_soc_codec *)(wcd9xxx->ssr_priv);
  8931. if (!codec->component.card) {
  8932. dev_err(codec->dev, "%s: sound card is not enumerated.\n",
  8933. __func__);
  8934. return -EINVAL;
  8935. }
  8936. tavil = snd_soc_codec_get_drvdata(codec);
  8937. control = dev_get_drvdata(codec->dev->parent);
  8938. wcd9xxx_set_power_state(tavil->wcd9xxx,
  8939. WCD_REGION_POWER_COLLAPSE_REMOVE,
  8940. WCD9XXX_DIG_CORE_REGION_1);
  8941. mutex_lock(&tavil->codec_mutex);
  8942. tavil_vote_svs(tavil, true);
  8943. tavil_slimbus_slave_port_cfg.slave_dev_intfdev_la =
  8944. control->slim_slave->laddr;
  8945. tavil_slimbus_slave_port_cfg.slave_dev_pgd_la =
  8946. control->slim->laddr;
  8947. tavil_init_slim_slave_cfg(codec);
  8948. if (!is_snd_event_fwk_enabled())
  8949. snd_soc_card_change_online_state(codec->component.card, 1);
  8950. for (i = 0; i < TAVIL_MAX_MICBIAS; i++)
  8951. tavil->micb_ref[i] = 0;
  8952. dev_dbg(codec->dev, "%s: MCLK Rate = %x\n",
  8953. __func__, control->mclk_rate);
  8954. if (control->mclk_rate == WCD934X_MCLK_CLK_12P288MHZ)
  8955. snd_soc_update_bits(codec, WCD934X_CODEC_RPM_CLK_MCLK_CFG,
  8956. 0x03, 0x00);
  8957. else if (control->mclk_rate == WCD934X_MCLK_CLK_9P6MHZ)
  8958. snd_soc_update_bits(codec, WCD934X_CODEC_RPM_CLK_MCLK_CFG,
  8959. 0x03, 0x01);
  8960. tavil_update_reg_defaults(tavil);
  8961. wcd_resmgr_post_ssr_v2(tavil->resmgr);
  8962. tavil_codec_init_reg(tavil);
  8963. __tavil_enable_efuse_sensing(tavil);
  8964. tavil_mclk2_reg_defaults(tavil);
  8965. __tavil_cdc_mclk_enable(tavil, true);
  8966. regcache_mark_dirty(codec->component.regmap);
  8967. regcache_sync(codec->component.regmap);
  8968. __tavil_cdc_mclk_enable(tavil, false);
  8969. tavil_update_cpr_defaults(tavil);
  8970. pdata = dev_get_platdata(codec->dev->parent);
  8971. ret = tavil_handle_pdata(tavil, pdata);
  8972. if (ret < 0)
  8973. dev_err(codec->dev, "%s: invalid pdata\n", __func__);
  8974. /* Initialize MBHC module */
  8975. mbhc = &tavil->mbhc->wcd_mbhc;
  8976. ret = tavil_mbhc_post_ssr_init(tavil->mbhc, codec);
  8977. if (ret) {
  8978. dev_err(codec->dev, "%s: mbhc initialization failed\n",
  8979. __func__);
  8980. goto done;
  8981. } else {
  8982. tavil_mbhc_hs_detect(codec, mbhc->mbhc_cfg);
  8983. }
  8984. /* DSD initialization */
  8985. ret = tavil_dsd_post_ssr_init(tavil->dsd_config);
  8986. if (ret)
  8987. dev_dbg(tavil->dev, "%s: DSD init failed\n", __func__);
  8988. tavil_cleanup_irqs(tavil);
  8989. ret = tavil_setup_irqs(tavil);
  8990. if (ret) {
  8991. dev_err(codec->dev, "%s: tavil irq setup failed %d\n",
  8992. __func__, ret);
  8993. goto done;
  8994. }
  8995. if (tavil->swr.ctrl_data && is_snd_event_fwk_enabled())
  8996. swrm_wcd_notify(tavil->swr.ctrl_data[0].swr_pdev,
  8997. SWR_DEVICE_SSR_UP, NULL);
  8998. tavil_set_spkr_mode(codec, tavil->swr.spkr_mode);
  8999. /*
  9000. * Once the codec initialization is completed, the svs vote
  9001. * can be released allowing the codec to go to SVS2.
  9002. */
  9003. tavil_vote_svs(tavil, false);
  9004. wcd_dsp_ssr_event(tavil->wdsp_cntl, WCD_CDC_UP_EVENT);
  9005. snd_event_notify(tavil->dev->parent, SND_EVENT_UP);
  9006. done:
  9007. mutex_unlock(&tavil->codec_mutex);
  9008. return ret;
  9009. }
  9010. static int tavil_soc_codec_probe(struct snd_soc_codec *codec)
  9011. {
  9012. struct wcd9xxx *control;
  9013. struct tavil_priv *tavil;
  9014. struct wcd9xxx_pdata *pdata;
  9015. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  9016. int i, ret;
  9017. void *ptr = NULL;
  9018. control = dev_get_drvdata(codec->dev->parent);
  9019. dev_info(codec->dev, "%s()\n", __func__);
  9020. tavil = snd_soc_codec_get_drvdata(codec);
  9021. tavil->intf_type = wcd9xxx_get_intf_type();
  9022. control->dev_down = tavil_device_down;
  9023. control->post_reset = tavil_post_reset_cb;
  9024. control->ssr_priv = (void *)codec;
  9025. /* Resource Manager post Init */
  9026. ret = wcd_resmgr_post_init(tavil->resmgr, &tavil_resmgr_cb, codec);
  9027. if (ret) {
  9028. dev_err(codec->dev, "%s: wcd resmgr post init failed\n",
  9029. __func__);
  9030. goto err;
  9031. }
  9032. /* Class-H Init */
  9033. wcd_clsh_init(&tavil->clsh_d);
  9034. /* Default HPH Mode to Class-H Low HiFi */
  9035. tavil->hph_mode = CLS_H_LOHIFI;
  9036. tavil->fw_data = devm_kzalloc(codec->dev, sizeof(*(tavil->fw_data)),
  9037. GFP_KERNEL);
  9038. if (!tavil->fw_data)
  9039. goto err;
  9040. set_bit(WCD9XXX_ANC_CAL, tavil->fw_data->cal_bit);
  9041. set_bit(WCD9XXX_MBHC_CAL, tavil->fw_data->cal_bit);
  9042. set_bit(WCD9XXX_MAD_CAL, tavil->fw_data->cal_bit);
  9043. set_bit(WCD9XXX_VBAT_CAL, tavil->fw_data->cal_bit);
  9044. ret = wcd_cal_create_hwdep(tavil->fw_data,
  9045. WCD9XXX_CODEC_HWDEP_NODE, codec);
  9046. if (ret < 0) {
  9047. dev_err(codec->dev, "%s hwdep failed %d\n", __func__, ret);
  9048. goto err_hwdep;
  9049. }
  9050. /* Initialize MBHC module */
  9051. ret = tavil_mbhc_init(&tavil->mbhc, codec, tavil->fw_data);
  9052. if (ret) {
  9053. pr_err("%s: mbhc initialization failed\n", __func__);
  9054. goto err_hwdep;
  9055. }
  9056. tavil->codec = codec;
  9057. for (i = 0; i < COMPANDER_MAX; i++)
  9058. tavil->comp_enabled[i] = 0;
  9059. tavil_codec_init_reg(tavil);
  9060. pdata = dev_get_platdata(codec->dev->parent);
  9061. ret = tavil_handle_pdata(tavil, pdata);
  9062. if (ret < 0) {
  9063. dev_err(codec->dev, "%s: bad pdata\n", __func__);
  9064. goto err_hwdep;
  9065. }
  9066. ptr = devm_kzalloc(codec->dev, (sizeof(tavil_rx_chs) +
  9067. sizeof(tavil_tx_chs)), GFP_KERNEL);
  9068. if (!ptr) {
  9069. ret = -ENOMEM;
  9070. goto err_hwdep;
  9071. }
  9072. for (i = 0; i < NUM_CODEC_DAIS; i++) {
  9073. INIT_LIST_HEAD(&tavil->dai[i].wcd9xxx_ch_list);
  9074. init_waitqueue_head(&tavil->dai[i].dai_wait);
  9075. }
  9076. if (tavil->intf_type == WCD9XXX_INTERFACE_TYPE_SLIMBUS) {
  9077. snd_soc_dapm_new_controls(dapm, tavil_dapm_slim_widgets,
  9078. ARRAY_SIZE(tavil_dapm_slim_widgets));
  9079. snd_soc_dapm_add_routes(dapm, tavil_slim_audio_map,
  9080. ARRAY_SIZE(tavil_slim_audio_map));
  9081. tavil_slimbus_slave_port_cfg.slave_dev_intfdev_la =
  9082. control->slim_slave->laddr;
  9083. tavil_slimbus_slave_port_cfg.slave_dev_pgd_la =
  9084. control->slim->laddr;
  9085. tavil_slimbus_slave_port_cfg.slave_port_mapping[0] =
  9086. WCD934X_TX13;
  9087. tavil_init_slim_slave_cfg(codec);
  9088. } else {
  9089. snd_soc_dapm_new_controls(dapm, tavil_dapm_i2s_widgets,
  9090. ARRAY_SIZE(tavil_dapm_i2s_widgets));
  9091. snd_soc_dapm_add_routes(dapm, tavil_i2s_audio_map,
  9092. ARRAY_SIZE(tavil_i2s_audio_map));
  9093. }
  9094. control->num_rx_port = WCD934X_RX_MAX;
  9095. control->rx_chs = ptr;
  9096. memcpy(control->rx_chs, tavil_rx_chs, sizeof(tavil_rx_chs));
  9097. control->num_tx_port = WCD934X_TX_MAX;
  9098. control->tx_chs = ptr + sizeof(tavil_rx_chs);
  9099. memcpy(control->tx_chs, tavil_tx_chs, sizeof(tavil_tx_chs));
  9100. ret = tavil_setup_irqs(tavil);
  9101. if (ret) {
  9102. dev_err(tavil->dev, "%s: tavil irq setup failed %d\n",
  9103. __func__, ret);
  9104. goto err_pdata;
  9105. }
  9106. for (i = 0; i < WCD934X_NUM_DECIMATORS; i++) {
  9107. tavil->tx_hpf_work[i].tavil = tavil;
  9108. tavil->tx_hpf_work[i].decimator = i;
  9109. INIT_DELAYED_WORK(&tavil->tx_hpf_work[i].dwork,
  9110. tavil_tx_hpf_corner_freq_callback);
  9111. tavil->tx_mute_dwork[i].tavil = tavil;
  9112. tavil->tx_mute_dwork[i].decimator = i;
  9113. INIT_DELAYED_WORK(&tavil->tx_mute_dwork[i].dwork,
  9114. tavil_tx_mute_update_callback);
  9115. }
  9116. tavil->spk_anc_dwork.tavil = tavil;
  9117. INIT_DELAYED_WORK(&tavil->spk_anc_dwork.dwork,
  9118. tavil_spk_anc_update_callback);
  9119. tavil_mclk2_reg_defaults(tavil);
  9120. /* DSD initialization */
  9121. tavil->dsd_config = tavil_dsd_init(codec);
  9122. if (IS_ERR_OR_NULL(tavil->dsd_config))
  9123. dev_dbg(tavil->dev, "%s: DSD init failed\n", __func__);
  9124. mutex_lock(&tavil->codec_mutex);
  9125. snd_soc_dapm_disable_pin(dapm, "ANC EAR PA");
  9126. snd_soc_dapm_disable_pin(dapm, "ANC EAR");
  9127. snd_soc_dapm_disable_pin(dapm, "ANC HPHL PA");
  9128. snd_soc_dapm_disable_pin(dapm, "ANC HPHR PA");
  9129. snd_soc_dapm_disable_pin(dapm, "ANC HPHL");
  9130. snd_soc_dapm_disable_pin(dapm, "ANC HPHR");
  9131. snd_soc_dapm_enable_pin(dapm, "ANC SPK1 PA");
  9132. mutex_unlock(&tavil->codec_mutex);
  9133. snd_soc_dapm_ignore_suspend(dapm, "AIF1 Playback");
  9134. snd_soc_dapm_ignore_suspend(dapm, "AIF1 Capture");
  9135. snd_soc_dapm_ignore_suspend(dapm, "AIF2 Playback");
  9136. snd_soc_dapm_ignore_suspend(dapm, "AIF2 Capture");
  9137. snd_soc_dapm_ignore_suspend(dapm, "AIF3 Playback");
  9138. snd_soc_dapm_ignore_suspend(dapm, "AIF3 Capture");
  9139. snd_soc_dapm_ignore_suspend(dapm, "WDMA3_OUT");
  9140. if (tavil->intf_type == WCD9XXX_INTERFACE_TYPE_SLIMBUS) {
  9141. snd_soc_dapm_ignore_suspend(dapm, "AIF4 Playback");
  9142. snd_soc_dapm_ignore_suspend(dapm, "AIF4 MAD TX");
  9143. snd_soc_dapm_ignore_suspend(dapm, "VIfeed");
  9144. }
  9145. snd_soc_dapm_sync(dapm);
  9146. tavil_wdsp_initialize(codec);
  9147. /*
  9148. * Once the codec initialization is completed, the svs vote
  9149. * can be released allowing the codec to go to SVS2.
  9150. */
  9151. tavil_vote_svs(tavil, false);
  9152. return ret;
  9153. err_pdata:
  9154. devm_kfree(codec->dev, ptr);
  9155. control->rx_chs = NULL;
  9156. control->tx_chs = NULL;
  9157. err_hwdep:
  9158. devm_kfree(codec->dev, tavil->fw_data);
  9159. tavil->fw_data = NULL;
  9160. err:
  9161. return ret;
  9162. }
  9163. static int tavil_soc_codec_remove(struct snd_soc_codec *codec)
  9164. {
  9165. struct wcd9xxx *control;
  9166. struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec);
  9167. control = dev_get_drvdata(codec->dev->parent);
  9168. devm_kfree(codec->dev, control->rx_chs);
  9169. /* slimslave deinit in wcd core looks for this value */
  9170. control->num_rx_port = 0;
  9171. control->num_tx_port = 0;
  9172. control->rx_chs = NULL;
  9173. control->tx_chs = NULL;
  9174. tavil_cleanup_irqs(tavil);
  9175. if (tavil->wdsp_cntl)
  9176. wcd_dsp_cntl_deinit(&tavil->wdsp_cntl);
  9177. /* Deinitialize MBHC module */
  9178. tavil_mbhc_deinit(codec);
  9179. tavil->mbhc = NULL;
  9180. return 0;
  9181. }
  9182. static struct regmap *tavil_get_regmap(struct device *dev)
  9183. {
  9184. struct wcd9xxx *control = dev_get_drvdata(dev->parent);
  9185. return control->regmap;
  9186. }
  9187. static struct snd_soc_codec_driver soc_codec_dev_tavil = {
  9188. .probe = tavil_soc_codec_probe,
  9189. .remove = tavil_soc_codec_remove,
  9190. .get_regmap = tavil_get_regmap,
  9191. .component_driver = {
  9192. .controls = tavil_snd_controls,
  9193. .num_controls = ARRAY_SIZE(tavil_snd_controls),
  9194. .dapm_widgets = tavil_dapm_widgets,
  9195. .num_dapm_widgets = ARRAY_SIZE(tavil_dapm_widgets),
  9196. .dapm_routes = tavil_audio_map,
  9197. .num_dapm_routes = ARRAY_SIZE(tavil_audio_map),
  9198. },
  9199. };
  9200. #ifdef CONFIG_PM
  9201. static int tavil_suspend(struct device *dev)
  9202. {
  9203. struct platform_device *pdev = to_platform_device(dev);
  9204. struct tavil_priv *tavil = platform_get_drvdata(pdev);
  9205. if (!tavil) {
  9206. dev_err(dev, "%s: tavil private data is NULL\n", __func__);
  9207. return -EINVAL;
  9208. }
  9209. dev_dbg(dev, "%s: system suspend\n", __func__);
  9210. if (delayed_work_pending(&tavil->power_gate_work) &&
  9211. cancel_delayed_work_sync(&tavil->power_gate_work))
  9212. tavil_codec_power_gate_digital_core(tavil);
  9213. return 0;
  9214. }
  9215. static int tavil_resume(struct device *dev)
  9216. {
  9217. struct platform_device *pdev = to_platform_device(dev);
  9218. struct tavil_priv *tavil = platform_get_drvdata(pdev);
  9219. if (!tavil) {
  9220. dev_err(dev, "%s: tavil private data is NULL\n", __func__);
  9221. return -EINVAL;
  9222. }
  9223. dev_dbg(dev, "%s: system resume\n", __func__);
  9224. return 0;
  9225. }
  9226. static const struct dev_pm_ops tavil_pm_ops = {
  9227. .suspend = tavil_suspend,
  9228. .resume = tavil_resume,
  9229. };
  9230. #endif
  9231. static int wcd9xxx_swrm_i2c_bulk_write(struct wcd9xxx *wcd9xxx,
  9232. struct wcd9xxx_reg_val *bulk_reg,
  9233. size_t len)
  9234. {
  9235. int i, ret = 0;
  9236. unsigned short swr_wr_addr_base;
  9237. unsigned short swr_wr_data_base;
  9238. swr_wr_addr_base = WCD934X_SWR_AHB_BRIDGE_WR_ADDR_0;
  9239. swr_wr_data_base = WCD934X_SWR_AHB_BRIDGE_WR_DATA_0;
  9240. for (i = 0; i < (len * 2); i += 2) {
  9241. /* First Write the Data to register */
  9242. ret = regmap_bulk_write(wcd9xxx->regmap,
  9243. swr_wr_data_base, bulk_reg[i].buf, 4);
  9244. if (ret < 0) {
  9245. dev_err(wcd9xxx->dev, "%s: WR Data Failure\n",
  9246. __func__);
  9247. break;
  9248. }
  9249. /* Next Write Address */
  9250. ret = regmap_bulk_write(wcd9xxx->regmap,
  9251. swr_wr_addr_base,
  9252. bulk_reg[i+1].buf, 4);
  9253. if (ret < 0) {
  9254. dev_err(wcd9xxx->dev, "%s: WR Addr Failure\n",
  9255. __func__);
  9256. break;
  9257. }
  9258. }
  9259. return ret;
  9260. }
  9261. static int tavil_swrm_read(void *handle, int reg)
  9262. {
  9263. struct tavil_priv *tavil;
  9264. struct wcd9xxx *wcd9xxx;
  9265. unsigned short swr_rd_addr_base;
  9266. unsigned short swr_rd_data_base;
  9267. int val, ret;
  9268. if (!handle) {
  9269. pr_err("%s: NULL handle\n", __func__);
  9270. return -EINVAL;
  9271. }
  9272. tavil = (struct tavil_priv *)handle;
  9273. wcd9xxx = tavil->wcd9xxx;
  9274. dev_dbg(tavil->dev, "%s: Reading soundwire register, 0x%x\n",
  9275. __func__, reg);
  9276. swr_rd_addr_base = WCD934X_SWR_AHB_BRIDGE_RD_ADDR_0;
  9277. swr_rd_data_base = WCD934X_SWR_AHB_BRIDGE_RD_DATA_0;
  9278. mutex_lock(&tavil->swr.read_mutex);
  9279. ret = regmap_bulk_write(wcd9xxx->regmap, swr_rd_addr_base,
  9280. (u8 *)&reg, 4);
  9281. if (ret < 0) {
  9282. dev_err(tavil->dev, "%s: RD Addr Failure\n", __func__);
  9283. goto done;
  9284. }
  9285. ret = regmap_bulk_read(wcd9xxx->regmap, swr_rd_data_base,
  9286. (u8 *)&val, 4);
  9287. if (ret < 0) {
  9288. dev_err(tavil->dev, "%s: RD Data Failure\n", __func__);
  9289. goto done;
  9290. }
  9291. ret = val;
  9292. done:
  9293. mutex_unlock(&tavil->swr.read_mutex);
  9294. return ret;
  9295. }
  9296. static int tavil_swrm_bulk_write(void *handle, u32 *reg, u32 *val, size_t len)
  9297. {
  9298. struct tavil_priv *tavil;
  9299. struct wcd9xxx *wcd9xxx;
  9300. struct wcd9xxx_reg_val *bulk_reg;
  9301. unsigned short swr_wr_addr_base;
  9302. unsigned short swr_wr_data_base;
  9303. int i, j, ret;
  9304. if (!handle || !reg || !val) {
  9305. pr_err("%s: NULL parameter\n", __func__);
  9306. return -EINVAL;
  9307. }
  9308. if (len <= 0) {
  9309. pr_err("%s: Invalid size: %zu\n", __func__, len);
  9310. return -EINVAL;
  9311. }
  9312. tavil = (struct tavil_priv *)handle;
  9313. wcd9xxx = tavil->wcd9xxx;
  9314. swr_wr_addr_base = WCD934X_SWR_AHB_BRIDGE_WR_ADDR_0;
  9315. swr_wr_data_base = WCD934X_SWR_AHB_BRIDGE_WR_DATA_0;
  9316. bulk_reg = kzalloc((2 * len * sizeof(struct wcd9xxx_reg_val)),
  9317. GFP_KERNEL);
  9318. if (!bulk_reg)
  9319. return -ENOMEM;
  9320. for (i = 0, j = 0; i < (len * 2); i += 2, j++) {
  9321. bulk_reg[i].reg = swr_wr_data_base;
  9322. bulk_reg[i].buf = (u8 *)(&val[j]);
  9323. bulk_reg[i].bytes = 4;
  9324. bulk_reg[i+1].reg = swr_wr_addr_base;
  9325. bulk_reg[i+1].buf = (u8 *)(&reg[j]);
  9326. bulk_reg[i+1].bytes = 4;
  9327. }
  9328. mutex_lock(&tavil->swr.write_mutex);
  9329. if (tavil->intf_type == WCD9XXX_INTERFACE_TYPE_SLIMBUS)
  9330. ret = wcd9xxx_slim_bulk_write(wcd9xxx, bulk_reg,
  9331. (len * 2), false);
  9332. else
  9333. ret = wcd9xxx_swrm_i2c_bulk_write(wcd9xxx, bulk_reg, len);
  9334. if (ret) {
  9335. dev_err(tavil->dev, "%s: swrm bulk write failed, ret: %d\n",
  9336. __func__, ret);
  9337. }
  9338. mutex_unlock(&tavil->swr.write_mutex);
  9339. kfree(bulk_reg);
  9340. return ret;
  9341. }
  9342. static int tavil_swrm_write(void *handle, int reg, int val)
  9343. {
  9344. struct tavil_priv *tavil;
  9345. struct wcd9xxx *wcd9xxx;
  9346. unsigned short swr_wr_addr_base;
  9347. unsigned short swr_wr_data_base;
  9348. struct wcd9xxx_reg_val bulk_reg[2];
  9349. int ret;
  9350. if (!handle) {
  9351. pr_err("%s: NULL handle\n", __func__);
  9352. return -EINVAL;
  9353. }
  9354. tavil = (struct tavil_priv *)handle;
  9355. wcd9xxx = tavil->wcd9xxx;
  9356. swr_wr_addr_base = WCD934X_SWR_AHB_BRIDGE_WR_ADDR_0;
  9357. swr_wr_data_base = WCD934X_SWR_AHB_BRIDGE_WR_DATA_0;
  9358. /* First Write the Data to register */
  9359. bulk_reg[0].reg = swr_wr_data_base;
  9360. bulk_reg[0].buf = (u8 *)(&val);
  9361. bulk_reg[0].bytes = 4;
  9362. bulk_reg[1].reg = swr_wr_addr_base;
  9363. bulk_reg[1].buf = (u8 *)(&reg);
  9364. bulk_reg[1].bytes = 4;
  9365. mutex_lock(&tavil->swr.write_mutex);
  9366. if (tavil->intf_type == WCD9XXX_INTERFACE_TYPE_SLIMBUS)
  9367. ret = wcd9xxx_slim_bulk_write(wcd9xxx, bulk_reg, 2, false);
  9368. else
  9369. ret = wcd9xxx_swrm_i2c_bulk_write(wcd9xxx, bulk_reg, 1);
  9370. if (ret < 0)
  9371. dev_err(tavil->dev, "%s: WR Data Failure\n", __func__);
  9372. mutex_unlock(&tavil->swr.write_mutex);
  9373. return ret;
  9374. }
  9375. static int tavil_swrm_clock(void *handle, bool enable)
  9376. {
  9377. struct tavil_priv *tavil;
  9378. if (!handle) {
  9379. pr_err("%s: NULL handle\n", __func__);
  9380. return -EINVAL;
  9381. }
  9382. tavil = (struct tavil_priv *)handle;
  9383. mutex_lock(&tavil->swr.clk_mutex);
  9384. dev_dbg(tavil->dev, "%s: swrm clock %s\n",
  9385. __func__, (enable?"enable" : "disable"));
  9386. if (enable) {
  9387. tavil->swr.clk_users++;
  9388. if (tavil->swr.clk_users == 1) {
  9389. regmap_update_bits(tavil->wcd9xxx->regmap,
  9390. WCD934X_TEST_DEBUG_NPL_DLY_TEST_1,
  9391. 0x10, 0x00);
  9392. __tavil_cdc_mclk_enable(tavil, true);
  9393. regmap_update_bits(tavil->wcd9xxx->regmap,
  9394. WCD934X_CDC_CLK_RST_CTRL_SWR_CONTROL,
  9395. 0x01, 0x01);
  9396. }
  9397. } else {
  9398. tavil->swr.clk_users--;
  9399. if (tavil->swr.clk_users == 0) {
  9400. regmap_update_bits(tavil->wcd9xxx->regmap,
  9401. WCD934X_CDC_CLK_RST_CTRL_SWR_CONTROL,
  9402. 0x01, 0x00);
  9403. __tavil_cdc_mclk_enable(tavil, false);
  9404. regmap_update_bits(tavil->wcd9xxx->regmap,
  9405. WCD934X_TEST_DEBUG_NPL_DLY_TEST_1,
  9406. 0x10, 0x10);
  9407. }
  9408. }
  9409. dev_dbg(tavil->dev, "%s: swrm clock users %d\n",
  9410. __func__, tavil->swr.clk_users);
  9411. mutex_unlock(&tavil->swr.clk_mutex);
  9412. return 0;
  9413. }
  9414. static int tavil_swrm_handle_irq(void *handle,
  9415. irqreturn_t (*swrm_irq_handler)(int irq,
  9416. void *data),
  9417. void *swrm_handle,
  9418. int action)
  9419. {
  9420. struct tavil_priv *tavil;
  9421. int ret = 0;
  9422. struct wcd9xxx *wcd9xxx;
  9423. if (!handle) {
  9424. pr_err("%s: NULL handle\n", __func__);
  9425. return -EINVAL;
  9426. }
  9427. tavil = (struct tavil_priv *) handle;
  9428. wcd9xxx = tavil->wcd9xxx;
  9429. if (action) {
  9430. ret = wcd9xxx_request_irq(&wcd9xxx->core_res,
  9431. WCD934X_IRQ_SOUNDWIRE,
  9432. swrm_irq_handler,
  9433. "Tavil SWR Master", swrm_handle);
  9434. if (ret)
  9435. dev_err(tavil->dev, "%s: Failed to request irq %d\n",
  9436. __func__, WCD934X_IRQ_SOUNDWIRE);
  9437. } else
  9438. wcd9xxx_free_irq(&wcd9xxx->core_res, WCD934X_IRQ_SOUNDWIRE,
  9439. swrm_handle);
  9440. return ret;
  9441. }
  9442. static void tavil_codec_add_spi_device(struct tavil_priv *tavil,
  9443. struct device_node *node)
  9444. {
  9445. struct spi_master *master;
  9446. struct spi_device *spi;
  9447. u32 prop_value;
  9448. int rc;
  9449. /* Read the master bus num from DT node */
  9450. rc = of_property_read_u32(node, "qcom,master-bus-num",
  9451. &prop_value);
  9452. if (rc < 0) {
  9453. dev_err(tavil->dev, "%s: prop %s not found in node %s",
  9454. __func__, "qcom,master-bus-num", node->full_name);
  9455. goto done;
  9456. }
  9457. /* Get the reference to SPI master */
  9458. master = spi_busnum_to_master(prop_value);
  9459. if (!master) {
  9460. dev_err(tavil->dev, "%s: Invalid spi_master for bus_num %u\n",
  9461. __func__, prop_value);
  9462. goto done;
  9463. }
  9464. /* Allocate the spi device */
  9465. spi = spi_alloc_device(master);
  9466. if (!spi) {
  9467. dev_err(tavil->dev, "%s: spi_alloc_device failed\n",
  9468. __func__);
  9469. goto err_spi_alloc_dev;
  9470. }
  9471. /* Initialize device properties */
  9472. if (of_modalias_node(node, spi->modalias,
  9473. sizeof(spi->modalias)) < 0) {
  9474. dev_err(tavil->dev, "%s: cannot find modalias for %s\n",
  9475. __func__, node->full_name);
  9476. goto err_dt_parse;
  9477. }
  9478. rc = of_property_read_u32(node, "qcom,chip-select",
  9479. &prop_value);
  9480. if (rc < 0) {
  9481. dev_err(tavil->dev, "%s: prop %s not found in node %s",
  9482. __func__, "qcom,chip-select", node->full_name);
  9483. goto err_dt_parse;
  9484. }
  9485. spi->chip_select = prop_value;
  9486. rc = of_property_read_u32(node, "qcom,max-frequency",
  9487. &prop_value);
  9488. if (rc < 0) {
  9489. dev_err(tavil->dev, "%s: prop %s not found in node %s",
  9490. __func__, "qcom,max-frequency", node->full_name);
  9491. goto err_dt_parse;
  9492. }
  9493. spi->max_speed_hz = prop_value;
  9494. spi->dev.of_node = node;
  9495. rc = spi_add_device(spi);
  9496. if (rc < 0) {
  9497. dev_err(tavil->dev, "%s: spi_add_device failed\n", __func__);
  9498. goto err_dt_parse;
  9499. }
  9500. tavil->spi = spi;
  9501. /* Put the reference to SPI master */
  9502. put_device(&master->dev);
  9503. return;
  9504. err_dt_parse:
  9505. spi_dev_put(spi);
  9506. err_spi_alloc_dev:
  9507. /* Put the reference to SPI master */
  9508. put_device(&master->dev);
  9509. done:
  9510. return;
  9511. }
  9512. static void tavil_add_child_devices(struct work_struct *work)
  9513. {
  9514. struct tavil_priv *tavil;
  9515. struct platform_device *pdev;
  9516. struct device_node *node;
  9517. struct wcd9xxx *wcd9xxx;
  9518. struct tavil_swr_ctrl_data *swr_ctrl_data = NULL, *temp;
  9519. int ret, ctrl_num = 0;
  9520. struct wcd_swr_ctrl_platform_data *platdata;
  9521. char plat_dev_name[WCD934X_STRING_LEN];
  9522. tavil = container_of(work, struct tavil_priv,
  9523. tavil_add_child_devices_work);
  9524. if (!tavil) {
  9525. pr_err("%s: Memory for WCD934X does not exist\n",
  9526. __func__);
  9527. return;
  9528. }
  9529. wcd9xxx = tavil->wcd9xxx;
  9530. if (!wcd9xxx) {
  9531. pr_err("%s: Memory for WCD9XXX does not exist\n",
  9532. __func__);
  9533. return;
  9534. }
  9535. if (!wcd9xxx->dev->of_node) {
  9536. dev_err(wcd9xxx->dev, "%s: DT node for wcd9xxx does not exist\n",
  9537. __func__);
  9538. return;
  9539. }
  9540. platdata = &tavil->swr.plat_data;
  9541. tavil->child_count = 0;
  9542. for_each_child_of_node(wcd9xxx->dev->of_node, node) {
  9543. /* Parse and add the SPI device node */
  9544. if (!strcmp(node->name, "wcd_spi")) {
  9545. tavil_codec_add_spi_device(tavil, node);
  9546. continue;
  9547. }
  9548. /* Parse other child device nodes and add platform device */
  9549. if (!strcmp(node->name, "swr_master"))
  9550. strlcpy(plat_dev_name, "tavil_swr_ctrl",
  9551. (WCD934X_STRING_LEN - 1));
  9552. else if (strnstr(node->name, "msm_cdc_pinctrl",
  9553. strlen("msm_cdc_pinctrl")) != NULL)
  9554. strlcpy(plat_dev_name, node->name,
  9555. (WCD934X_STRING_LEN - 1));
  9556. else
  9557. continue;
  9558. pdev = platform_device_alloc(plat_dev_name, -1);
  9559. if (!pdev) {
  9560. dev_err(wcd9xxx->dev, "%s: pdev memory alloc failed\n",
  9561. __func__);
  9562. ret = -ENOMEM;
  9563. goto err_mem;
  9564. }
  9565. pdev->dev.parent = tavil->dev;
  9566. pdev->dev.of_node = node;
  9567. if (strcmp(node->name, "swr_master") == 0) {
  9568. ret = platform_device_add_data(pdev, platdata,
  9569. sizeof(*platdata));
  9570. if (ret) {
  9571. dev_err(&pdev->dev,
  9572. "%s: cannot add plat data ctrl:%d\n",
  9573. __func__, ctrl_num);
  9574. goto err_pdev_add;
  9575. }
  9576. }
  9577. ret = platform_device_add(pdev);
  9578. if (ret) {
  9579. dev_err(&pdev->dev,
  9580. "%s: Cannot add platform device\n",
  9581. __func__);
  9582. goto err_pdev_add;
  9583. }
  9584. if (strcmp(node->name, "swr_master") == 0) {
  9585. temp = krealloc(swr_ctrl_data,
  9586. (ctrl_num + 1) * sizeof(
  9587. struct tavil_swr_ctrl_data),
  9588. GFP_KERNEL);
  9589. if (!temp) {
  9590. dev_err(wcd9xxx->dev, "out of memory\n");
  9591. ret = -ENOMEM;
  9592. goto err_pdev_add;
  9593. }
  9594. swr_ctrl_data = temp;
  9595. swr_ctrl_data[ctrl_num].swr_pdev = pdev;
  9596. ctrl_num++;
  9597. dev_dbg(&pdev->dev,
  9598. "%s: Added soundwire ctrl device(s)\n",
  9599. __func__);
  9600. tavil->swr.ctrl_data = swr_ctrl_data;
  9601. }
  9602. if (tavil->child_count < WCD934X_CHILD_DEVICES_MAX)
  9603. tavil->pdev_child_devices[tavil->child_count++] = pdev;
  9604. else
  9605. goto err_mem;
  9606. }
  9607. return;
  9608. err_pdev_add:
  9609. platform_device_put(pdev);
  9610. err_mem:
  9611. return;
  9612. }
  9613. static int __tavil_enable_efuse_sensing(struct tavil_priv *tavil)
  9614. {
  9615. int val, rc;
  9616. WCD9XXX_V2_BG_CLK_LOCK(tavil->resmgr);
  9617. __tavil_cdc_mclk_enable_locked(tavil, true);
  9618. regmap_update_bits(tavil->wcd9xxx->regmap,
  9619. WCD934X_CHIP_TIER_CTRL_EFUSE_CTL, 0x1E, 0x10);
  9620. regmap_update_bits(tavil->wcd9xxx->regmap,
  9621. WCD934X_CHIP_TIER_CTRL_EFUSE_CTL, 0x01, 0x01);
  9622. /*
  9623. * 5ms sleep required after enabling efuse control
  9624. * before checking the status.
  9625. */
  9626. usleep_range(5000, 5500);
  9627. wcd_resmgr_set_sido_input_src(tavil->resmgr,
  9628. SIDO_SOURCE_RCO_BG);
  9629. WCD9XXX_V2_BG_CLK_UNLOCK(tavil->resmgr);
  9630. rc = regmap_read(tavil->wcd9xxx->regmap,
  9631. WCD934X_CHIP_TIER_CTRL_EFUSE_STATUS, &val);
  9632. if (rc || (!(val & 0x01)))
  9633. WARN(1, "%s: Efuse sense is not complete val=%x, ret=%d\n",
  9634. __func__, val, rc);
  9635. __tavil_cdc_mclk_enable(tavil, false);
  9636. return rc;
  9637. }
  9638. static void ___tavil_get_codec_fine_version(struct tavil_priv *tavil)
  9639. {
  9640. int val1, val2, version;
  9641. struct regmap *regmap;
  9642. u16 id_minor;
  9643. u32 version_mask = 0;
  9644. regmap = tavil->wcd9xxx->regmap;
  9645. version = tavil->wcd9xxx->version;
  9646. id_minor = tavil->wcd9xxx->codec_type->id_minor;
  9647. regmap_read(regmap, WCD934X_CHIP_TIER_CTRL_EFUSE_VAL_OUT14, &val1);
  9648. regmap_read(regmap, WCD934X_CHIP_TIER_CTRL_EFUSE_VAL_OUT15, &val2);
  9649. dev_dbg(tavil->dev, "%s: chip version :0x%x 0x:%x\n",
  9650. __func__, val1, val2);
  9651. version_mask |= (!!((u8)val1 & 0x80)) << DSD_DISABLED_MASK;
  9652. version_mask |= (!!((u8)val2 & 0x01)) << SLNQ_DISABLED_MASK;
  9653. switch (version_mask) {
  9654. case DSD_DISABLED | SLNQ_DISABLED:
  9655. if (id_minor == cpu_to_le16(0))
  9656. version = TAVIL_VERSION_WCD9340_1_0;
  9657. else if (id_minor == cpu_to_le16(0x01))
  9658. version = TAVIL_VERSION_WCD9340_1_1;
  9659. break;
  9660. case SLNQ_DISABLED:
  9661. if (id_minor == cpu_to_le16(0))
  9662. version = TAVIL_VERSION_WCD9341_1_0;
  9663. else if (id_minor == cpu_to_le16(0x01))
  9664. version = TAVIL_VERSION_WCD9341_1_1;
  9665. break;
  9666. }
  9667. tavil->wcd9xxx->version = version;
  9668. tavil->wcd9xxx->codec_type->version = version;
  9669. }
  9670. /*
  9671. * tavil_get_wcd_dsp_cntl: Get the reference to wcd_dsp_cntl
  9672. * @dev: Device pointer for codec device
  9673. *
  9674. * This API gets the reference to codec's struct wcd_dsp_cntl
  9675. */
  9676. struct wcd_dsp_cntl *tavil_get_wcd_dsp_cntl(struct device *dev)
  9677. {
  9678. struct platform_device *pdev;
  9679. struct tavil_priv *tavil;
  9680. if (!dev) {
  9681. pr_err("%s: Invalid device\n", __func__);
  9682. return NULL;
  9683. }
  9684. pdev = to_platform_device(dev);
  9685. tavil = platform_get_drvdata(pdev);
  9686. return tavil->wdsp_cntl;
  9687. }
  9688. EXPORT_SYMBOL(tavil_get_wcd_dsp_cntl);
  9689. static void wcd934x_ssr_disable(struct device *dev, void *data)
  9690. {
  9691. struct wcd9xxx *wcd9xxx = dev_get_drvdata(dev);
  9692. struct tavil_priv *tavil;
  9693. struct snd_soc_codec *codec;
  9694. int count = 0;
  9695. if (!wcd9xxx) {
  9696. dev_dbg(dev, "%s: wcd9xxx pointer NULL.\n", __func__);
  9697. return;
  9698. }
  9699. codec = (struct snd_soc_codec *)(wcd9xxx->ssr_priv);
  9700. tavil = snd_soc_codec_get_drvdata(codec);
  9701. for (count = 0; count < NUM_CODEC_DAIS; count++)
  9702. tavil->dai[count].bus_down_in_recovery = true;
  9703. }
  9704. static const struct snd_event_ops wcd934x_ssr_ops = {
  9705. .disable = wcd934x_ssr_disable,
  9706. };
  9707. static int tavil_probe(struct platform_device *pdev)
  9708. {
  9709. int ret = 0, len = 0;
  9710. struct tavil_priv *tavil;
  9711. struct clk *wcd_ext_clk;
  9712. struct wcd9xxx_resmgr_v2 *resmgr;
  9713. struct wcd9xxx_power_region *cdc_pwr;
  9714. const __be32 *micb_prop;
  9715. tavil = devm_kzalloc(&pdev->dev, sizeof(struct tavil_priv),
  9716. GFP_KERNEL);
  9717. if (!tavil)
  9718. return -ENOMEM;
  9719. tavil->intf_type = wcd9xxx_get_intf_type();
  9720. if (tavil->intf_type != WCD9XXX_INTERFACE_TYPE_I2C &&
  9721. tavil->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) {
  9722. devm_kfree(&pdev->dev, tavil);
  9723. return -EPROBE_DEFER;
  9724. }
  9725. if (tavil->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
  9726. if (apr_get_subsys_state() == APR_SUBSYS_DOWN) {
  9727. dev_dbg(&pdev->dev, "%s: dsp down\n", __func__);
  9728. devm_kfree(&pdev->dev, tavil);
  9729. return -EPROBE_DEFER;
  9730. }
  9731. }
  9732. platform_set_drvdata(pdev, tavil);
  9733. tavil->wcd9xxx = dev_get_drvdata(pdev->dev.parent);
  9734. tavil->dev = &pdev->dev;
  9735. INIT_DELAYED_WORK(&tavil->power_gate_work, tavil_codec_power_gate_work);
  9736. mutex_init(&tavil->power_lock);
  9737. INIT_WORK(&tavil->tavil_add_child_devices_work,
  9738. tavil_add_child_devices);
  9739. mutex_init(&tavil->micb_lock);
  9740. mutex_init(&tavil->swr.read_mutex);
  9741. mutex_init(&tavil->swr.write_mutex);
  9742. mutex_init(&tavil->swr.clk_mutex);
  9743. mutex_init(&tavil->codec_mutex);
  9744. mutex_init(&tavil->svs_mutex);
  9745. /*
  9746. * Codec hardware by default comes up in SVS mode.
  9747. * Initialize the svs_ref_cnt to 1 to reflect the hardware
  9748. * state in the driver.
  9749. */
  9750. tavil->svs_ref_cnt = 1;
  9751. cdc_pwr = devm_kzalloc(&pdev->dev, sizeof(struct wcd9xxx_power_region),
  9752. GFP_KERNEL);
  9753. if (!cdc_pwr) {
  9754. ret = -ENOMEM;
  9755. goto err_resmgr;
  9756. }
  9757. tavil->wcd9xxx->wcd9xxx_pwr[WCD9XXX_DIG_CORE_REGION_1] = cdc_pwr;
  9758. cdc_pwr->pwr_collapse_reg_min = WCD934X_DIG_CORE_REG_MIN;
  9759. cdc_pwr->pwr_collapse_reg_max = WCD934X_DIG_CORE_REG_MAX;
  9760. wcd9xxx_set_power_state(tavil->wcd9xxx,
  9761. WCD_REGION_POWER_COLLAPSE_REMOVE,
  9762. WCD9XXX_DIG_CORE_REGION_1);
  9763. /*
  9764. * Init resource manager so that if child nodes such as SoundWire
  9765. * requests for clock, resource manager can honor the request
  9766. */
  9767. resmgr = wcd_resmgr_init(&tavil->wcd9xxx->core_res, NULL);
  9768. if (IS_ERR(resmgr)) {
  9769. ret = PTR_ERR(resmgr);
  9770. dev_err(&pdev->dev, "%s: Failed to initialize wcd resmgr\n",
  9771. __func__);
  9772. goto err_resmgr;
  9773. }
  9774. tavil->resmgr = resmgr;
  9775. tavil->swr.plat_data.handle = (void *) tavil;
  9776. tavil->swr.plat_data.read = tavil_swrm_read;
  9777. tavil->swr.plat_data.write = tavil_swrm_write;
  9778. tavil->swr.plat_data.bulk_write = tavil_swrm_bulk_write;
  9779. tavil->swr.plat_data.clk = tavil_swrm_clock;
  9780. tavil->swr.plat_data.handle_irq = tavil_swrm_handle_irq;
  9781. tavil->swr.spkr_gain_offset = WCD934X_RX_GAIN_OFFSET_0_DB;
  9782. /* Register for Clock */
  9783. wcd_ext_clk = clk_get(tavil->wcd9xxx->dev, "wcd_clk");
  9784. if (IS_ERR(wcd_ext_clk)) {
  9785. dev_err(tavil->wcd9xxx->dev, "%s: clk get %s failed\n",
  9786. __func__, "wcd_ext_clk");
  9787. goto err_clk;
  9788. }
  9789. tavil->wcd_ext_clk = wcd_ext_clk;
  9790. set_bit(AUDIO_NOMINAL, &tavil->status_mask);
  9791. /* Update codec register default values */
  9792. dev_dbg(&pdev->dev, "%s: MCLK Rate = %x\n", __func__,
  9793. tavil->wcd9xxx->mclk_rate);
  9794. if (tavil->wcd9xxx->mclk_rate == WCD934X_MCLK_CLK_12P288MHZ)
  9795. regmap_update_bits(tavil->wcd9xxx->regmap,
  9796. WCD934X_CODEC_RPM_CLK_MCLK_CFG,
  9797. 0x03, 0x00);
  9798. else if (tavil->wcd9xxx->mclk_rate == WCD934X_MCLK_CLK_9P6MHZ)
  9799. regmap_update_bits(tavil->wcd9xxx->regmap,
  9800. WCD934X_CODEC_RPM_CLK_MCLK_CFG,
  9801. 0x03, 0x01);
  9802. tavil_update_reg_defaults(tavil);
  9803. __tavil_enable_efuse_sensing(tavil);
  9804. ___tavil_get_codec_fine_version(tavil);
  9805. tavil_update_cpr_defaults(tavil);
  9806. /* Register with soc framework */
  9807. if (tavil->intf_type == WCD9XXX_INTERFACE_TYPE_I2C)
  9808. ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_tavil,
  9809. tavil_i2s_dai,
  9810. ARRAY_SIZE(tavil_i2s_dai));
  9811. else
  9812. ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_tavil,
  9813. tavil_slim_dai,
  9814. ARRAY_SIZE(tavil_slim_dai));
  9815. if (ret) {
  9816. dev_err(&pdev->dev, "%s: Codec registration failed\n",
  9817. __func__);
  9818. goto err_cdc_reg;
  9819. }
  9820. schedule_work(&tavil->tavil_add_child_devices_work);
  9821. ret = snd_event_client_register(pdev->dev.parent, &wcd934x_ssr_ops, NULL);
  9822. if (!ret) {
  9823. snd_event_notify(pdev->dev.parent, SND_EVENT_UP);
  9824. } else {
  9825. pr_err("%s: Registration with SND event fwk failed ret = %d\n",
  9826. __func__, ret);
  9827. ret = 0;
  9828. }
  9829. tavil->micb_load = NULL;
  9830. if (of_get_property(tavil->wcd9xxx->dev->of_node,
  9831. "qcom,vreg-micb-supply", NULL)) {
  9832. micb_prop = of_get_property(tavil->wcd9xxx->dev->of_node,
  9833. "qcom,cdc-vdd-mic-bias-current",
  9834. &len);
  9835. if (!micb_prop || (len != (2 * sizeof(__be32)))) {
  9836. tavil->micb_load_low = MICB_LOAD_DEFAULT;
  9837. tavil->micb_load_high = MICB_LOAD_DEFAULT;
  9838. } else {
  9839. tavil->micb_load_low = be32_to_cpup(&micb_prop[0]);
  9840. tavil->micb_load_high = be32_to_cpup(&micb_prop[1]);
  9841. }
  9842. tavil->micb_load = regulator_get(&pdev->dev, MICB_LOAD_PROP);
  9843. if (IS_ERR(tavil->micb_load))
  9844. dev_dbg(tavil->dev, "%s micb load get failed\n",
  9845. __func__);
  9846. }
  9847. return ret;
  9848. err_cdc_reg:
  9849. clk_put(tavil->wcd_ext_clk);
  9850. err_clk:
  9851. wcd_resmgr_remove(tavil->resmgr);
  9852. err_resmgr:
  9853. mutex_destroy(&tavil->micb_lock);
  9854. mutex_destroy(&tavil->svs_mutex);
  9855. mutex_destroy(&tavil->codec_mutex);
  9856. mutex_destroy(&tavil->swr.read_mutex);
  9857. mutex_destroy(&tavil->swr.write_mutex);
  9858. mutex_destroy(&tavil->swr.clk_mutex);
  9859. devm_kfree(&pdev->dev, tavil);
  9860. return ret;
  9861. }
  9862. static int tavil_remove(struct platform_device *pdev)
  9863. {
  9864. struct tavil_priv *tavil;
  9865. int count = 0;
  9866. tavil = platform_get_drvdata(pdev);
  9867. if (!tavil)
  9868. return -EINVAL;
  9869. /* do dsd deinit before codec->component->regmap becomes freed */
  9870. if (tavil->dsd_config) {
  9871. tavil_dsd_deinit(tavil->dsd_config);
  9872. tavil->dsd_config = NULL;
  9873. }
  9874. snd_event_client_deregister(pdev->dev.parent);
  9875. if (tavil->spi)
  9876. spi_unregister_device(tavil->spi);
  9877. for (count = 0; count < tavil->child_count &&
  9878. count < WCD934X_CHILD_DEVICES_MAX; count++)
  9879. platform_device_unregister(tavil->pdev_child_devices[count]);
  9880. if (tavil->micb_load)
  9881. regulator_put(tavil->micb_load);
  9882. mutex_destroy(&tavil->micb_lock);
  9883. mutex_destroy(&tavil->svs_mutex);
  9884. mutex_destroy(&tavil->codec_mutex);
  9885. mutex_destroy(&tavil->swr.read_mutex);
  9886. mutex_destroy(&tavil->swr.write_mutex);
  9887. mutex_destroy(&tavil->swr.clk_mutex);
  9888. snd_soc_unregister_codec(&pdev->dev);
  9889. clk_put(tavil->wcd_ext_clk);
  9890. wcd_resmgr_remove(tavil->resmgr);
  9891. devm_kfree(&pdev->dev, tavil);
  9892. return 0;
  9893. }
  9894. static struct platform_driver tavil_codec_driver = {
  9895. .probe = tavil_probe,
  9896. .remove = tavil_remove,
  9897. .driver = {
  9898. .name = "tavil_codec",
  9899. .owner = THIS_MODULE,
  9900. #ifdef CONFIG_PM
  9901. .pm = &tavil_pm_ops,
  9902. #endif
  9903. },
  9904. };
  9905. module_platform_driver(tavil_codec_driver);
  9906. MODULE_DESCRIPTION("Tavil Codec driver");
  9907. MODULE_LICENSE("GPL v2");