wcd934x.c 335 KB

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