wcd934x.c 339 KB

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