wcd934x.c 311 KB

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