wcd934x.c 335 KB

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