wcd934x.c 334 KB

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