wcd934x.c 337 KB

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