wcd934x.c 310 KB

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