wcd934x.c 307 KB

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