wcd934x.c 335 KB

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