wcd934x.c 311 KB

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