wcd9360.c 234 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915
  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/wait.h>
  21. #include <linux/bitops.h>
  22. #include <linux/clk.h>
  23. #include <linux/delay.h>
  24. #include <linux/pm_runtime.h>
  25. #include <linux/kernel.h>
  26. #include <linux/gpio.h>
  27. #include <linux/regmap.h>
  28. #include <linux/spi/spi.h>
  29. #include <linux/regulator/consumer.h>
  30. #include <linux/mfd/wcd9xxx/wcd9xxx_registers.h>
  31. #include <soc/swr-wcd.h>
  32. #include <sound/pcm.h>
  33. #include <sound/pcm_params.h>
  34. #include <sound/soc.h>
  35. #include <sound/soc-dapm.h>
  36. #include <sound/tlv.h>
  37. #include <sound/info.h>
  38. #include <asoc/wcd9360-registers.h>
  39. #include "wcd9360.h"
  40. #include "wcd9360-routing.h"
  41. #include "wcd9360-dsp-cntl.h"
  42. #include "wcd9360-irq.h"
  43. #include "../core.h"
  44. #include "../pdata.h"
  45. #include "../wcd9xxx-irq.h"
  46. #include "../wcd9xxx-common-v2.h"
  47. #include "../wcd9xxx-resmgr-v2.h"
  48. #include "../wcdcal-hwdep.h"
  49. #include "../msm-cdc-supply.h"
  50. #define WCD9360_RATES_MASK (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
  51. SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\
  52. SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000 |\
  53. SNDRV_PCM_RATE_384000)
  54. /* Fractional Rates */
  55. #define WCD9360_FRAC_RATES_MASK (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_88200 |\
  56. SNDRV_PCM_RATE_176400)
  57. #define WCD9360_FORMATS_S16_S24_LE (SNDRV_PCM_FMTBIT_S16_LE | \
  58. SNDRV_PCM_FMTBIT_S24_LE)
  59. #define WCD9360_FORMATS_S16_S24_S32_LE (SNDRV_PCM_FMTBIT_S16_LE | \
  60. SNDRV_PCM_FMTBIT_S24_LE | \
  61. SNDRV_PCM_FMTBIT_S32_LE)
  62. #define WCD9360_FORMATS_S16_LE (SNDRV_PCM_FMTBIT_S16_LE)
  63. /* Macros for packing register writes into a U32 */
  64. #define WCD9360_PACKED_REG_SIZE sizeof(u32)
  65. #define WCD9360_CODEC_UNPACK_ENTRY(packed, reg, mask, val) \
  66. do { \
  67. ((reg) = ((packed >> 16) & (0xffff))); \
  68. ((mask) = ((packed >> 8) & (0xff))); \
  69. ((val) = ((packed) & (0xff))); \
  70. } while (0)
  71. #define STRING(name) #name
  72. #define WCD_DAPM_ENUM(name, reg, offset, text) \
  73. static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
  74. static const struct snd_kcontrol_new name##_mux = \
  75. SOC_DAPM_ENUM(STRING(name), name##_enum)
  76. #define WCD_DAPM_ENUM_EXT(name, reg, offset, text, getname, putname) \
  77. static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
  78. static const struct snd_kcontrol_new name##_mux = \
  79. SOC_DAPM_ENUM_EXT(STRING(name), name##_enum, getname, putname)
  80. #define WCD_DAPM_MUX(name, shift, kctl) \
  81. SND_SOC_DAPM_MUX(name, SND_SOC_NOPM, shift, 0, &kctl##_mux)
  82. /*
  83. * Timeout in milli seconds and it is the wait time for
  84. * slim channel removal interrupt to receive.
  85. */
  86. #define WCD9360_SLIM_CLOSE_TIMEOUT 1000
  87. #define WCD9360_SLIM_IRQ_OVERFLOW (1 << 0)
  88. #define WCD9360_SLIM_IRQ_UNDERFLOW (1 << 1)
  89. #define WCD9360_SLIM_IRQ_PORT_CLOSED (1 << 2)
  90. #define WCD9360_MCLK_CLK_9P6MHZ 9600000
  91. #define WCD9360_INTERP_MUX_NUM_INPUTS 3
  92. #define WCD9360_NUM_INTERPOLATORS 10
  93. #define WCD9360_NUM_DECIMATORS 9
  94. #define WCD9360_RX_PATH_CTL_OFFSET 20
  95. #define WCD9360_TLMM_DMIC_PINCFG_OFFSET 15
  96. #define BYTE_BIT_MASK(nr) (1 << ((nr) % BITS_PER_BYTE))
  97. #define WCD9360_REG_BITS 8
  98. #define WCD9360_MAX_VALID_ADC_MUX 11
  99. #define WCD9360_INVALID_ADC_MUX 9
  100. #define WCD9360_AMIC_PWR_LEVEL_LP 0
  101. #define WCD9360_AMIC_PWR_LEVEL_DEFAULT 1
  102. #define WCD9360_AMIC_PWR_LEVEL_HP 2
  103. #define WCD9360_AMIC_PWR_LVL_MASK 0x60
  104. #define WCD9360_AMIC_PWR_LVL_SHIFT 0x5
  105. #define WCD9360_DEC_PWR_LVL_MASK 0x06
  106. #define WCD9360_DEC_PWR_LVL_LP 0x02
  107. #define WCD9360_DEC_PWR_LVL_HP 0x04
  108. #define WCD9360_DEC_PWR_LVL_DF 0x00
  109. #define WCD9360_STRING_LEN 100
  110. #define WCD9360_CDC_SIDETONE_IIR_COEFF_MAX 5
  111. #define WCD9360_CDC_REPEAT_WRITES_MAX 16
  112. #define WCD9360_DIG_CORE_REG_MIN WCD9360_CDC_ANC0_CLK_RESET_CTL
  113. #define WCD9360_DIG_CORE_REG_MAX 0xFFF
  114. #define WCD9360_CHILD_DEVICES_MAX 6
  115. #define WCD9360_MAX_MICBIAS 4
  116. #define DAPM_MICBIAS1_STANDALONE "MIC BIAS1 Standalone"
  117. #define DAPM_MICBIAS2_STANDALONE "MIC BIAS2 Standalone"
  118. #define DAPM_MICBIAS3_STANDALONE "MIC BIAS3 Standalone"
  119. #define DAPM_MICBIAS4_STANDALONE "MIC BIAS4 Standalone"
  120. #define WCD9360_LDO_RXTX_SUPPLY_NAME "vdd_ldo_rxtx_supply"
  121. #define TX_HPF_CUT_OFF_FREQ_MASK 0x60
  122. #define CF_MIN_3DB_4HZ 0x0
  123. #define CF_MIN_3DB_75HZ 0x1
  124. #define CF_MIN_3DB_150HZ 0x2
  125. #define CPE_ERR_WDOG_BITE BIT(0)
  126. #define CPE_FATAL_IRQS CPE_ERR_WDOG_BITE
  127. #define WCD9360_MAD_AUDIO_FIRMWARE_PATH "wcd9360/wcd9360_mad_audio.bin"
  128. #define PAHU_VERSION_ENTRY_SIZE 17
  129. #define WCD9360_DIG_CORE_COLLAPSE_TIMER_MS (5 * 1000)
  130. enum {
  131. POWER_COLLAPSE,
  132. POWER_RESUME,
  133. };
  134. static int dig_core_collapse_enable = 1;
  135. module_param(dig_core_collapse_enable, int, 0664);
  136. MODULE_PARM_DESC(dig_core_collapse_enable, "enable/disable power gating");
  137. /* dig_core_collapse timer in seconds */
  138. static int dig_core_collapse_timer = (WCD9360_DIG_CORE_COLLAPSE_TIMER_MS/1000);
  139. module_param(dig_core_collapse_timer, int, 0664);
  140. MODULE_PARM_DESC(dig_core_collapse_timer, "timer for power gating");
  141. enum {
  142. VI_SENSE_1,
  143. VI_SENSE_2,
  144. CLK_INTERNAL,
  145. CLK_MODE,
  146. };
  147. enum {
  148. AIF1_PB = 0,
  149. AIF1_CAP,
  150. AIF2_PB,
  151. AIF2_CAP,
  152. AIF3_PB,
  153. AIF3_CAP,
  154. AIF4_PB,
  155. AIF4_VIFEED,
  156. AIF4_MAD_TX,
  157. NUM_CODEC_DAIS,
  158. };
  159. enum {
  160. INTn_1_INP_SEL_ZERO = 0,
  161. INTn_1_INP_SEL_DEC0,
  162. INTn_1_INP_SEL_DEC1,
  163. INTn_1_INP_SEL_IIR0,
  164. INTn_1_INP_SEL_NA,
  165. INTn_1_INP_SEL_RX0,
  166. INTn_1_INP_SEL_RX1,
  167. INTn_1_INP_SEL_RX2,
  168. INTn_1_INP_SEL_RX3,
  169. INTn_1_INP_SEL_RX4,
  170. INTn_1_INP_SEL_RX5,
  171. INTn_1_INP_SEL_RX6,
  172. INTn_1_INP_SEL_RX7,
  173. };
  174. enum {
  175. INTn_2_INP_SEL_ZERO = 0,
  176. INTn_2_INP_SEL_RX0,
  177. INTn_2_INP_SEL_RX1,
  178. INTn_2_INP_SEL_RX2,
  179. INTn_2_INP_SEL_RX3,
  180. INTn_2_INP_SEL_RX4,
  181. INTn_2_INP_SEL_RX5,
  182. INTn_2_INP_SEL_RX6,
  183. INTn_2_INP_SEL_RX7,
  184. INTn_2_INP_SEL_PROXIMITY,
  185. };
  186. enum {
  187. INTERP_MAIN_PATH,
  188. INTERP_MIX_PATH,
  189. };
  190. struct pahu_cpr_reg_defaults {
  191. int wr_data;
  192. int wr_addr;
  193. };
  194. struct interp_sample_rate {
  195. int sample_rate;
  196. int rate_val;
  197. };
  198. static struct interp_sample_rate sr_val_tbl[] = {
  199. {8000, 0x0}, {16000, 0x1}, {32000, 0x3}, {48000, 0x4}, {96000, 0x5},
  200. {192000, 0x6}, {384000, 0x7}, {44100, 0x9}, {88200, 0xA},
  201. {176400, 0xB}, {352800, 0xC},
  202. };
  203. static const struct wcd9xxx_ch pahu_rx_chs[WCD9360_RX_MAX] = {
  204. WCD9XXX_CH(WCD9360_RX_PORT_START_NUMBER, 0),
  205. WCD9XXX_CH(WCD9360_RX_PORT_START_NUMBER + 1, 1),
  206. WCD9XXX_CH(WCD9360_RX_PORT_START_NUMBER + 2, 2),
  207. WCD9XXX_CH(WCD9360_RX_PORT_START_NUMBER + 3, 3),
  208. WCD9XXX_CH(WCD9360_RX_PORT_START_NUMBER + 4, 4),
  209. WCD9XXX_CH(WCD9360_RX_PORT_START_NUMBER + 5, 5),
  210. WCD9XXX_CH(WCD9360_RX_PORT_START_NUMBER + 6, 6),
  211. WCD9XXX_CH(WCD9360_RX_PORT_START_NUMBER + 7, 7),
  212. };
  213. static const struct wcd9xxx_ch pahu_tx_chs[WCD9360_TX_MAX] = {
  214. WCD9XXX_CH(0, 0),
  215. WCD9XXX_CH(1, 1),
  216. WCD9XXX_CH(2, 2),
  217. WCD9XXX_CH(3, 3),
  218. WCD9XXX_CH(4, 4),
  219. WCD9XXX_CH(5, 5),
  220. WCD9XXX_CH(6, 6),
  221. WCD9XXX_CH(7, 7),
  222. WCD9XXX_CH(8, 8),
  223. WCD9XXX_CH(9, 9),
  224. WCD9XXX_CH(10, 10),
  225. WCD9XXX_CH(11, 11),
  226. WCD9XXX_CH(12, 12),
  227. WCD9XXX_CH(13, 13),
  228. WCD9XXX_CH(14, 14),
  229. WCD9XXX_CH(15, 15),
  230. };
  231. static const u32 vport_slim_check_table[NUM_CODEC_DAIS] = {
  232. 0, /* AIF1_PB */
  233. BIT(AIF2_CAP) | BIT(AIF3_CAP) | BIT(AIF4_MAD_TX), /* AIF1_CAP */
  234. 0, /* AIF2_PB */
  235. BIT(AIF1_CAP) | BIT(AIF3_CAP) | BIT(AIF4_MAD_TX), /* AIF2_CAP */
  236. 0, /* AIF3_PB */
  237. BIT(AIF1_CAP) | BIT(AIF2_CAP) | BIT(AIF4_MAD_TX), /* AIF3_CAP */
  238. 0, /* AIF4_PB */
  239. };
  240. /* Codec supports 2 IIR filters */
  241. enum {
  242. IIR0 = 0,
  243. IIR_MAX,
  244. };
  245. /* Each IIR has 5 Filter Stages */
  246. enum {
  247. BAND1 = 0,
  248. BAND2,
  249. BAND3,
  250. BAND4,
  251. BAND5,
  252. BAND_MAX,
  253. };
  254. enum {
  255. COMPANDER_0, /* EAR */
  256. COMPANDER_1, /* HPH_L */
  257. COMPANDER_2, /* HPH_R */
  258. COMPANDER_3, /* LO1_DIFF */
  259. COMPANDER_4, /* LO2_DIFF */
  260. COMPANDER_5, /* LO3_SE */
  261. COMPANDER_6, /* LO4_SE */
  262. COMPANDER_7, /* SWR SPK CH1 */
  263. COMPANDER_8, /* SWR SPK CH2 */
  264. COMPANDER_9, /* AUX */
  265. COMPANDER_MAX,
  266. };
  267. enum {
  268. ASRC_IN_SPKR1,
  269. ASRC_IN_SPKR2,
  270. ASRC_INVALID,
  271. };
  272. enum {
  273. ASRC2,
  274. ASRC3,
  275. ASRC_MAX,
  276. };
  277. enum {
  278. CONV_88P2K_TO_384K,
  279. CONV_96K_TO_352P8K,
  280. CONV_352P8K_TO_384K,
  281. CONV_384K_TO_352P8K,
  282. CONV_384K_TO_384K,
  283. CONV_96K_TO_384K,
  284. };
  285. static struct afe_param_slimbus_slave_port_cfg pahu_slimbus_slave_port_cfg = {
  286. .minor_version = 1,
  287. .slimbus_dev_id = AFE_SLIMBUS_DEVICE_1,
  288. .slave_dev_pgd_la = 0,
  289. .slave_dev_intfdev_la = 0,
  290. .bit_width = 16,
  291. .data_format = 0,
  292. .num_channels = 1
  293. };
  294. static struct afe_param_cdc_reg_page_cfg pahu_cdc_reg_page_cfg = {
  295. .minor_version = AFE_API_VERSION_CDC_REG_PAGE_CFG,
  296. .enable = 1,
  297. .proc_id = AFE_CDC_REG_PAGE_ASSIGN_PROC_ID_1,
  298. };
  299. static struct afe_param_cdc_reg_cfg audio_reg_cfg[] = {
  300. {
  301. 1,
  302. (WCD9360_REGISTER_START_OFFSET + WCD9360_SOC_MAD_MAIN_CTL_1),
  303. HW_MAD_AUDIO_ENABLE, 0x1, WCD9360_REG_BITS, 0
  304. },
  305. {
  306. 1,
  307. (WCD9360_REGISTER_START_OFFSET + WCD9360_SOC_MAD_AUDIO_CTL_3),
  308. HW_MAD_AUDIO_SLEEP_TIME, 0xF, WCD9360_REG_BITS, 0
  309. },
  310. {
  311. 1,
  312. (WCD9360_REGISTER_START_OFFSET + WCD9360_SOC_MAD_AUDIO_CTL_4),
  313. HW_MAD_TX_AUDIO_SWITCH_OFF, 0x1, WCD9360_REG_BITS, 0
  314. },
  315. {
  316. 1,
  317. (WCD9360_REGISTER_START_OFFSET + WCD9360_INTR_CFG),
  318. MAD_AUDIO_INT_DEST_SELECT_REG, 0x2, WCD9360_REG_BITS, 0
  319. },
  320. {
  321. 1,
  322. (WCD9360_REGISTER_START_OFFSET + WCD9360_INTR_PIN2_MASK3),
  323. MAD_AUDIO_INT_MASK_REG, 0x1, WCD9360_REG_BITS, 0
  324. },
  325. {
  326. 1,
  327. (WCD9360_REGISTER_START_OFFSET + WCD9360_INTR_PIN2_STATUS3),
  328. MAD_AUDIO_INT_STATUS_REG, 0x1, WCD9360_REG_BITS, 0
  329. },
  330. {
  331. 1,
  332. (WCD9360_REGISTER_START_OFFSET + WCD9360_INTR_PIN2_CLEAR3),
  333. MAD_AUDIO_INT_CLEAR_REG, 0x1, WCD9360_REG_BITS, 0
  334. },
  335. {
  336. 1,
  337. (WCD9360_REGISTER_START_OFFSET + WCD9360_SB_PGD_PORT_TX_BASE),
  338. SB_PGD_PORT_TX_WATERMARK_N, 0x1E, WCD9360_REG_BITS, 0x1
  339. },
  340. {
  341. 1,
  342. (WCD9360_REGISTER_START_OFFSET + WCD9360_SB_PGD_PORT_TX_BASE),
  343. SB_PGD_PORT_TX_ENABLE_N, 0x1, WCD9360_REG_BITS, 0x1
  344. },
  345. {
  346. 1,
  347. (WCD9360_REGISTER_START_OFFSET + WCD9360_SB_PGD_PORT_RX_BASE),
  348. SB_PGD_PORT_RX_WATERMARK_N, 0x1E, WCD9360_REG_BITS, 0x1
  349. },
  350. {
  351. 1,
  352. (WCD9360_REGISTER_START_OFFSET + WCD9360_SB_PGD_PORT_RX_BASE),
  353. SB_PGD_PORT_RX_ENABLE_N, 0x1, WCD9360_REG_BITS, 0x1
  354. },
  355. {
  356. 1,
  357. (WCD9360_REGISTER_START_OFFSET +
  358. WCD9360_CDC_ANC0_IIR_ADAPT_CTL),
  359. AANC_FF_GAIN_ADAPTIVE, 0x4, WCD9360_REG_BITS, 0
  360. },
  361. {
  362. 1,
  363. (WCD9360_REGISTER_START_OFFSET +
  364. WCD9360_CDC_ANC0_IIR_ADAPT_CTL),
  365. AANC_FFGAIN_ADAPTIVE_EN, 0x8, WCD9360_REG_BITS, 0
  366. },
  367. {
  368. 1,
  369. (WCD9360_REGISTER_START_OFFSET +
  370. WCD9360_CDC_ANC0_FF_A_GAIN_CTL),
  371. AANC_GAIN_CONTROL, 0xFF, WCD9360_REG_BITS, 0
  372. },
  373. {
  374. 1,
  375. (WCD9360_REGISTER_START_OFFSET +
  376. SB_PGD_TX_PORT_MULTI_CHANNEL_0(0)),
  377. SB_PGD_TX_PORTn_MULTI_CHNL_0, 0xFF, WCD9360_REG_BITS, 0x4
  378. },
  379. {
  380. 1,
  381. (WCD9360_REGISTER_START_OFFSET +
  382. SB_PGD_TX_PORT_MULTI_CHANNEL_1(0)),
  383. SB_PGD_TX_PORTn_MULTI_CHNL_1, 0xFF, WCD9360_REG_BITS, 0x4
  384. },
  385. {
  386. 1,
  387. (WCD9360_REGISTER_START_OFFSET +
  388. SB_PGD_RX_PORT_MULTI_CHANNEL_0(0x180, 0)),
  389. SB_PGD_RX_PORTn_MULTI_CHNL_0, 0xFF, WCD9360_REG_BITS, 0x4
  390. },
  391. {
  392. 1,
  393. (WCD9360_REGISTER_START_OFFSET +
  394. SB_PGD_RX_PORT_MULTI_CHANNEL_0(0x181, 0)),
  395. SB_PGD_RX_PORTn_MULTI_CHNL_1, 0xFF, WCD9360_REG_BITS, 0x4
  396. },
  397. };
  398. static struct afe_param_cdc_reg_cfg_data pahu_audio_reg_cfg = {
  399. .num_registers = ARRAY_SIZE(audio_reg_cfg),
  400. .reg_data = audio_reg_cfg,
  401. };
  402. static struct afe_param_id_cdc_aanc_version pahu_cdc_aanc_version = {
  403. .cdc_aanc_minor_version = AFE_API_VERSION_CDC_AANC_VERSION,
  404. .aanc_hw_version = AANC_HW_BLOCK_VERSION_2,
  405. };
  406. static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0);
  407. static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 25, 1);
  408. #define WCD9360_TX_UNMUTE_DELAY_MS 40
  409. static int tx_unmute_delay = WCD9360_TX_UNMUTE_DELAY_MS;
  410. module_param(tx_unmute_delay, int, 0664);
  411. MODULE_PARM_DESC(tx_unmute_delay, "delay to unmute the tx path");
  412. static void pahu_codec_set_tx_hold(struct snd_soc_codec *, u16, bool);
  413. /* Hold instance to soundwire platform device */
  414. struct pahu_swr_ctrl_data {
  415. struct platform_device *swr_pdev;
  416. };
  417. struct wcd_swr_ctrl_platform_data {
  418. void *handle; /* holds codec private data */
  419. int (*read)(void *handle, int reg);
  420. int (*write)(void *handle, int reg, int val);
  421. int (*bulk_write)(void *handle, u32 *reg, u32 *val, size_t len);
  422. int (*clk)(void *handle, bool enable);
  423. int (*handle_irq)(void *handle,
  424. irqreturn_t (*swrm_irq_handler)(int irq, void *data),
  425. void *swrm_handle, int action);
  426. };
  427. /* Holds all Soundwire and speaker related information */
  428. struct wcd9360_swr {
  429. struct pahu_swr_ctrl_data *ctrl_data;
  430. struct wcd_swr_ctrl_platform_data plat_data;
  431. struct mutex read_mutex;
  432. struct mutex write_mutex;
  433. struct mutex clk_mutex;
  434. int spkr_gain_offset;
  435. int spkr_mode;
  436. int clk_users;
  437. int rx_7_count;
  438. int rx_8_count;
  439. };
  440. struct tx_mute_work {
  441. struct pahu_priv *pahu;
  442. u8 decimator;
  443. struct delayed_work dwork;
  444. };
  445. #define WCD9360_SPK_ANC_EN_DELAY_MS 550
  446. static int spk_anc_en_delay = WCD9360_SPK_ANC_EN_DELAY_MS;
  447. module_param(spk_anc_en_delay, int, 0664);
  448. MODULE_PARM_DESC(spk_anc_en_delay, "delay to enable anc in speaker path");
  449. struct spk_anc_work {
  450. struct pahu_priv *pahu;
  451. struct delayed_work dwork;
  452. };
  453. struct hpf_work {
  454. struct pahu_priv *pahu;
  455. u8 decimator;
  456. u8 hpf_cut_off_freq;
  457. struct delayed_work dwork;
  458. };
  459. struct pahu_priv {
  460. struct device *dev;
  461. struct wcd9xxx *wcd9xxx;
  462. struct snd_soc_codec *codec;
  463. s32 ldo_rxtx_cnt;
  464. s32 dmic_0_1_clk_cnt;
  465. s32 dmic_2_3_clk_cnt;
  466. s32 dmic_4_5_clk_cnt;
  467. s32 dmic_6_7_clk_cnt;
  468. s32 micb_ref[PAHU_MAX_MICBIAS];
  469. s32 pullup_ref[PAHU_MAX_MICBIAS];
  470. /* ANC related */
  471. u32 anc_slot;
  472. bool anc_func;
  473. /* compander */
  474. int comp_enabled[COMPANDER_MAX];
  475. int ear_spkr_gain;
  476. /* Mad switch reference count */
  477. int mad_switch_cnt;
  478. /* track pahu interface type */
  479. u8 intf_type;
  480. /* to track the status */
  481. unsigned long status_mask;
  482. struct afe_param_cdc_slimbus_slave_cfg slimbus_slave_cfg;
  483. /* num of slim ports required */
  484. struct wcd9xxx_codec_dai_data dai[NUM_CODEC_DAIS];
  485. /* Port values for Rx and Tx codec_dai */
  486. unsigned int rx_port_value[WCD9360_RX_MAX];
  487. unsigned int tx_port_value;
  488. struct wcd9xxx_resmgr_v2 *resmgr;
  489. struct wcd9360_swr swr;
  490. struct mutex micb_lock;
  491. struct delayed_work power_gate_work;
  492. struct mutex power_lock;
  493. struct clk *wcd_ext_clk;
  494. struct mutex codec_mutex;
  495. struct work_struct pahu_add_child_devices_work;
  496. struct hpf_work tx_hpf_work[WCD9360_NUM_DECIMATORS];
  497. struct tx_mute_work tx_mute_dwork[WCD9360_NUM_DECIMATORS];
  498. struct spk_anc_work spk_anc_dwork;
  499. unsigned int vi_feed_value;
  500. /* DSP control */
  501. struct wcd_dsp_cntl *wdsp_cntl;
  502. /* cal info for codec */
  503. struct fw_info *fw_data;
  504. /* Entry for version info */
  505. struct snd_info_entry *entry;
  506. struct snd_info_entry *version_entry;
  507. /* SVS voting related */
  508. struct mutex svs_mutex;
  509. int svs_ref_cnt;
  510. int native_clk_users;
  511. /* ASRC users count */
  512. int asrc_users[ASRC_MAX];
  513. int asrc_output_mode[ASRC_MAX];
  514. /* Main path clock users count */
  515. int main_clk_users[WCD9360_NUM_INTERPOLATORS];
  516. int power_active_ref;
  517. u8 sidetone_coeff_array[IIR_MAX][BAND_MAX]
  518. [WCD9360_CDC_SIDETONE_IIR_COEFF_MAX * 4];
  519. struct spi_device *spi;
  520. struct platform_device *pdev_child_devices
  521. [WCD9360_CHILD_DEVICES_MAX];
  522. int child_count;
  523. };
  524. static const struct pahu_reg_mask_val pahu_spkr_default[] = {
  525. {WCD9360_CDC_COMPANDER7_CTL3, 0x80, 0x80},
  526. {WCD9360_CDC_COMPANDER8_CTL3, 0x80, 0x80},
  527. {WCD9360_CDC_COMPANDER7_CTL7, 0x01, 0x01},
  528. {WCD9360_CDC_COMPANDER8_CTL7, 0x01, 0x01},
  529. {WCD9360_CDC_BOOST0_BOOST_CTL, 0x7C, 0x50},
  530. {WCD9360_CDC_BOOST1_BOOST_CTL, 0x7C, 0x50},
  531. };
  532. static const struct pahu_reg_mask_val pahu_spkr_mode1[] = {
  533. {WCD9360_CDC_COMPANDER7_CTL3, 0x80, 0x00},
  534. {WCD9360_CDC_COMPANDER8_CTL3, 0x80, 0x00},
  535. {WCD9360_CDC_COMPANDER7_CTL7, 0x01, 0x00},
  536. {WCD9360_CDC_COMPANDER8_CTL7, 0x01, 0x00},
  537. {WCD9360_CDC_BOOST0_BOOST_CTL, 0x7C, 0x44},
  538. {WCD9360_CDC_BOOST1_BOOST_CTL, 0x7C, 0x44},
  539. };
  540. static int __pahu_enable_efuse_sensing(struct pahu_priv *pahu);
  541. /**
  542. * pahu_set_spkr_gain_offset - offset the speaker path
  543. * gain with the given offset value.
  544. *
  545. * @codec: codec instance
  546. * @offset: Indicates speaker path gain offset value.
  547. *
  548. * Returns 0 on success or -EINVAL on error.
  549. */
  550. int pahu_set_spkr_gain_offset(struct snd_soc_codec *codec, int offset)
  551. {
  552. struct pahu_priv *priv = snd_soc_codec_get_drvdata(codec);
  553. if (!priv)
  554. return -EINVAL;
  555. priv->swr.spkr_gain_offset = offset;
  556. return 0;
  557. }
  558. EXPORT_SYMBOL(pahu_set_spkr_gain_offset);
  559. /**
  560. * pahu_set_spkr_mode - Configures speaker compander and smartboost
  561. * settings based on speaker mode.
  562. *
  563. * @codec: codec instance
  564. * @mode: Indicates speaker configuration mode.
  565. *
  566. * Returns 0 on success or -EINVAL on error.
  567. */
  568. int pahu_set_spkr_mode(struct snd_soc_codec *codec, int mode)
  569. {
  570. struct pahu_priv *priv = snd_soc_codec_get_drvdata(codec);
  571. int i;
  572. const struct pahu_reg_mask_val *regs;
  573. int size;
  574. if (!priv)
  575. return -EINVAL;
  576. switch (mode) {
  577. case WCD9360_SPKR_MODE_1:
  578. regs = pahu_spkr_mode1;
  579. size = ARRAY_SIZE(pahu_spkr_mode1);
  580. break;
  581. default:
  582. regs = pahu_spkr_default;
  583. size = ARRAY_SIZE(pahu_spkr_default);
  584. break;
  585. }
  586. priv->swr.spkr_mode = mode;
  587. for (i = 0; i < size; i++)
  588. snd_soc_update_bits(codec, regs[i].reg,
  589. regs[i].mask, regs[i].val);
  590. return 0;
  591. }
  592. EXPORT_SYMBOL(pahu_set_spkr_mode);
  593. /**
  594. * pahu_get_afe_config - returns specific codec configuration to afe to write
  595. *
  596. * @codec: codec instance
  597. * @config_type: Indicates type of configuration to write.
  598. */
  599. void *pahu_get_afe_config(struct snd_soc_codec *codec,
  600. enum afe_config_type config_type)
  601. {
  602. struct pahu_priv *priv = snd_soc_codec_get_drvdata(codec);
  603. switch (config_type) {
  604. case AFE_SLIMBUS_SLAVE_CONFIG:
  605. return &priv->slimbus_slave_cfg;
  606. case AFE_CDC_REGISTERS_CONFIG:
  607. return &pahu_audio_reg_cfg;
  608. case AFE_SLIMBUS_SLAVE_PORT_CONFIG:
  609. return &pahu_slimbus_slave_port_cfg;
  610. case AFE_AANC_VERSION:
  611. return &pahu_cdc_aanc_version;
  612. case AFE_CDC_REGISTER_PAGE_CONFIG:
  613. return &pahu_cdc_reg_page_cfg;
  614. default:
  615. dev_info(codec->dev, "%s: Unknown config_type 0x%x\n",
  616. __func__, config_type);
  617. return NULL;
  618. }
  619. }
  620. EXPORT_SYMBOL(pahu_get_afe_config);
  621. static void pahu_vote_svs(struct pahu_priv *pahu, bool vote)
  622. {
  623. struct wcd9xxx *wcd9xxx;
  624. wcd9xxx = pahu->wcd9xxx;
  625. mutex_lock(&pahu->svs_mutex);
  626. if (vote) {
  627. pahu->svs_ref_cnt++;
  628. if (pahu->svs_ref_cnt == 1)
  629. regmap_update_bits(wcd9xxx->regmap,
  630. WCD9360_CPE_SS_PWR_SYS_PSTATE_CTL_0,
  631. 0x01, 0x01);
  632. } else {
  633. /* Do not decrement ref count if it is already 0 */
  634. if (pahu->svs_ref_cnt == 0)
  635. goto done;
  636. pahu->svs_ref_cnt--;
  637. if (pahu->svs_ref_cnt == 0)
  638. regmap_update_bits(wcd9xxx->regmap,
  639. WCD9360_CPE_SS_PWR_SYS_PSTATE_CTL_0,
  640. 0x01, 0x00);
  641. }
  642. done:
  643. dev_dbg(pahu->dev, "%s: vote = %s, updated ref cnt = %u\n", __func__,
  644. vote ? "vote" : "Unvote", pahu->svs_ref_cnt);
  645. mutex_unlock(&pahu->svs_mutex);
  646. }
  647. static int pahu_get_anc_slot(struct snd_kcontrol *kcontrol,
  648. struct snd_ctl_elem_value *ucontrol)
  649. {
  650. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  651. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(codec);
  652. ucontrol->value.integer.value[0] = pahu->anc_slot;
  653. return 0;
  654. }
  655. static int pahu_put_anc_slot(struct snd_kcontrol *kcontrol,
  656. struct snd_ctl_elem_value *ucontrol)
  657. {
  658. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  659. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(codec);
  660. pahu->anc_slot = ucontrol->value.integer.value[0];
  661. return 0;
  662. }
  663. static int pahu_get_anc_func(struct snd_kcontrol *kcontrol,
  664. struct snd_ctl_elem_value *ucontrol)
  665. {
  666. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  667. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(codec);
  668. ucontrol->value.integer.value[0] = (pahu->anc_func == true ? 1 : 0);
  669. return 0;
  670. }
  671. static int pahu_put_anc_func(struct snd_kcontrol *kcontrol,
  672. struct snd_ctl_elem_value *ucontrol)
  673. {
  674. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  675. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(codec);
  676. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  677. mutex_lock(&pahu->codec_mutex);
  678. pahu->anc_func = (!ucontrol->value.integer.value[0] ? false : true);
  679. dev_dbg(codec->dev, "%s: anc_func %x", __func__, pahu->anc_func);
  680. if (pahu->anc_func == true) {
  681. snd_soc_dapm_enable_pin(dapm, "ANC EAR PA");
  682. snd_soc_dapm_enable_pin(dapm, "ANC EAR");
  683. snd_soc_dapm_enable_pin(dapm, "ANC SPK1 PA");
  684. snd_soc_dapm_disable_pin(dapm, "EAR PA");
  685. snd_soc_dapm_disable_pin(dapm, "EAR");
  686. } else {
  687. snd_soc_dapm_disable_pin(dapm, "ANC EAR PA");
  688. snd_soc_dapm_disable_pin(dapm, "ANC EAR");
  689. snd_soc_dapm_disable_pin(dapm, "ANC SPK1 PA");
  690. snd_soc_dapm_enable_pin(dapm, "EAR PA");
  691. snd_soc_dapm_enable_pin(dapm, "EAR");
  692. }
  693. mutex_unlock(&pahu->codec_mutex);
  694. snd_soc_dapm_sync(dapm);
  695. return 0;
  696. }
  697. static int pahu_codec_enable_anc(struct snd_soc_dapm_widget *w,
  698. struct snd_kcontrol *kcontrol, int event)
  699. {
  700. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  701. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(codec);
  702. const char *filename;
  703. const struct firmware *fw;
  704. int i;
  705. int ret = 0;
  706. int num_anc_slots;
  707. struct wcd9xxx_anc_header *anc_head;
  708. struct firmware_cal *hwdep_cal = NULL;
  709. u32 anc_writes_size = 0;
  710. int anc_size_remaining;
  711. u32 *anc_ptr;
  712. u16 reg;
  713. u8 mask, val;
  714. size_t cal_size;
  715. const void *data;
  716. if (!pahu->anc_func)
  717. return 0;
  718. switch (event) {
  719. case SND_SOC_DAPM_PRE_PMU:
  720. hwdep_cal = wcdcal_get_fw_cal(pahu->fw_data, WCD9XXX_ANC_CAL);
  721. if (hwdep_cal) {
  722. data = hwdep_cal->data;
  723. cal_size = hwdep_cal->size;
  724. dev_dbg(codec->dev, "%s: using hwdep calibration, cal_size %zd",
  725. __func__, cal_size);
  726. } else {
  727. filename = "wcd9360/WCD9360_anc.bin";
  728. ret = request_firmware(&fw, filename, codec->dev);
  729. if (ret < 0) {
  730. dev_err(codec->dev, "%s: Failed to acquire ANC data: %d\n",
  731. __func__, ret);
  732. return ret;
  733. }
  734. if (!fw) {
  735. dev_err(codec->dev, "%s: Failed to get anc fw\n",
  736. __func__);
  737. return -ENODEV;
  738. }
  739. data = fw->data;
  740. cal_size = fw->size;
  741. dev_dbg(codec->dev, "%s: using request_firmware calibration\n",
  742. __func__);
  743. }
  744. if (cal_size < sizeof(struct wcd9xxx_anc_header)) {
  745. dev_err(codec->dev, "%s: Invalid cal_size %zd\n",
  746. __func__, cal_size);
  747. ret = -EINVAL;
  748. goto err;
  749. }
  750. /* First number is the number of register writes */
  751. anc_head = (struct wcd9xxx_anc_header *)(data);
  752. anc_ptr = (u32 *)(data + sizeof(struct wcd9xxx_anc_header));
  753. anc_size_remaining = cal_size -
  754. sizeof(struct wcd9xxx_anc_header);
  755. num_anc_slots = anc_head->num_anc_slots;
  756. if (pahu->anc_slot >= num_anc_slots) {
  757. dev_err(codec->dev, "%s: Invalid ANC slot selected\n",
  758. __func__);
  759. ret = -EINVAL;
  760. goto err;
  761. }
  762. for (i = 0; i < num_anc_slots; i++) {
  763. if (anc_size_remaining < WCD9360_PACKED_REG_SIZE) {
  764. dev_err(codec->dev, "%s: Invalid register format\n",
  765. __func__);
  766. ret = -EINVAL;
  767. goto err;
  768. }
  769. anc_writes_size = (u32)(*anc_ptr);
  770. anc_size_remaining -= sizeof(u32);
  771. anc_ptr += 1;
  772. if ((anc_writes_size * WCD9360_PACKED_REG_SIZE) >
  773. anc_size_remaining) {
  774. dev_err(codec->dev, "%s: Invalid register format\n",
  775. __func__);
  776. ret = -EINVAL;
  777. goto err;
  778. }
  779. if (pahu->anc_slot == i)
  780. break;
  781. anc_size_remaining -= (anc_writes_size *
  782. WCD9360_PACKED_REG_SIZE);
  783. anc_ptr += anc_writes_size;
  784. }
  785. if (i == num_anc_slots) {
  786. dev_err(codec->dev, "%s: Selected ANC slot not present\n",
  787. __func__);
  788. ret = -EINVAL;
  789. goto err;
  790. }
  791. for (i = 0; i < anc_writes_size; i++) {
  792. WCD9360_CODEC_UNPACK_ENTRY(anc_ptr[i], reg, mask, val);
  793. snd_soc_write(codec, reg, (val & mask));
  794. }
  795. if (!hwdep_cal)
  796. release_firmware(fw);
  797. break;
  798. case SND_SOC_DAPM_POST_PMU:
  799. break;
  800. case SND_SOC_DAPM_POST_PMD:
  801. if (!strcmp(w->name, "ANC EAR PA") ||
  802. !strcmp(w->name, "ANC SPK1 PA")) {
  803. snd_soc_update_bits(codec, WCD9360_CDC_ANC0_MODE_1_CTL,
  804. 0x30, 0x00);
  805. msleep(50);
  806. snd_soc_update_bits(codec, WCD9360_CDC_ANC0_MODE_1_CTL,
  807. 0x01, 0x00);
  808. snd_soc_update_bits(codec,
  809. WCD9360_CDC_ANC0_CLK_RESET_CTL,
  810. 0x38, 0x38);
  811. snd_soc_update_bits(codec,
  812. WCD9360_CDC_ANC0_CLK_RESET_CTL,
  813. 0x07, 0x00);
  814. snd_soc_update_bits(codec,
  815. WCD9360_CDC_ANC0_CLK_RESET_CTL,
  816. 0x38, 0x00);
  817. }
  818. break;
  819. }
  820. return 0;
  821. err:
  822. if (!hwdep_cal)
  823. release_firmware(fw);
  824. return ret;
  825. }
  826. static int pahu_get_clkmode(struct snd_kcontrol *kcontrol,
  827. struct snd_ctl_elem_value *ucontrol)
  828. {
  829. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  830. struct pahu_priv *pahu_p = snd_soc_codec_get_drvdata(codec);
  831. if (test_bit(CLK_MODE, &pahu_p->status_mask))
  832. ucontrol->value.enumerated.item[0] = 1;
  833. else
  834. ucontrol->value.enumerated.item[0] = 0;
  835. dev_dbg(codec->dev, "%s: is_low_power_clock: %s\n", __func__,
  836. test_bit(CLK_MODE, &pahu_p->status_mask) ? "true" : "false");
  837. return 0;
  838. }
  839. static int pahu_put_clkmode(struct snd_kcontrol *kcontrol,
  840. struct snd_ctl_elem_value *ucontrol)
  841. {
  842. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  843. struct pahu_priv *pahu_p = snd_soc_codec_get_drvdata(codec);
  844. if (ucontrol->value.enumerated.item[0])
  845. set_bit(CLK_MODE, &pahu_p->status_mask);
  846. else
  847. clear_bit(CLK_MODE, &pahu_p->status_mask);
  848. dev_dbg(codec->dev, "%s: is_low_power_clock: %s\n", __func__,
  849. test_bit(CLK_MODE, &pahu_p->status_mask) ? "true" : "false");
  850. return 0;
  851. }
  852. static int pahu_vi_feed_mixer_get(struct snd_kcontrol *kcontrol,
  853. struct snd_ctl_elem_value *ucontrol)
  854. {
  855. struct snd_soc_dapm_widget *widget =
  856. snd_soc_dapm_kcontrol_widget(kcontrol);
  857. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  858. struct pahu_priv *pahu_p = snd_soc_codec_get_drvdata(codec);
  859. ucontrol->value.integer.value[0] = pahu_p->vi_feed_value;
  860. return 0;
  861. }
  862. static int pahu_vi_feed_mixer_put(struct snd_kcontrol *kcontrol,
  863. struct snd_ctl_elem_value *ucontrol)
  864. {
  865. struct snd_soc_dapm_widget *widget =
  866. snd_soc_dapm_kcontrol_widget(kcontrol);
  867. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  868. struct pahu_priv *pahu_p = snd_soc_codec_get_drvdata(codec);
  869. struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent);
  870. struct soc_multi_mixer_control *mixer =
  871. ((struct soc_multi_mixer_control *)kcontrol->private_value);
  872. u32 dai_id = widget->shift;
  873. u32 port_id = mixer->shift;
  874. u32 enable = ucontrol->value.integer.value[0];
  875. dev_dbg(codec->dev, "%s: enable: %d, port_id:%d, dai_id: %d\n",
  876. __func__, enable, port_id, dai_id);
  877. pahu_p->vi_feed_value = ucontrol->value.integer.value[0];
  878. mutex_lock(&pahu_p->codec_mutex);
  879. if (enable) {
  880. if (port_id == WCD9360_TX14 && !test_bit(VI_SENSE_1,
  881. &pahu_p->status_mask)) {
  882. list_add_tail(&core->tx_chs[WCD9360_TX14].list,
  883. &pahu_p->dai[dai_id].wcd9xxx_ch_list);
  884. set_bit(VI_SENSE_1, &pahu_p->status_mask);
  885. }
  886. if (port_id == WCD9360_TX15 && !test_bit(VI_SENSE_2,
  887. &pahu_p->status_mask)) {
  888. list_add_tail(&core->tx_chs[WCD9360_TX15].list,
  889. &pahu_p->dai[dai_id].wcd9xxx_ch_list);
  890. set_bit(VI_SENSE_2, &pahu_p->status_mask);
  891. }
  892. } else {
  893. if (port_id == WCD9360_TX14 && test_bit(VI_SENSE_1,
  894. &pahu_p->status_mask)) {
  895. list_del_init(&core->tx_chs[WCD9360_TX14].list);
  896. clear_bit(VI_SENSE_1, &pahu_p->status_mask);
  897. }
  898. if (port_id == WCD9360_TX15 && test_bit(VI_SENSE_2,
  899. &pahu_p->status_mask)) {
  900. list_del_init(&core->tx_chs[WCD9360_TX15].list);
  901. clear_bit(VI_SENSE_2, &pahu_p->status_mask);
  902. }
  903. }
  904. mutex_unlock(&pahu_p->codec_mutex);
  905. snd_soc_dapm_mixer_update_power(widget->dapm, kcontrol, enable, NULL);
  906. return 0;
  907. }
  908. static int slim_tx_mixer_get(struct snd_kcontrol *kcontrol,
  909. struct snd_ctl_elem_value *ucontrol)
  910. {
  911. struct snd_soc_dapm_widget *widget =
  912. snd_soc_dapm_kcontrol_widget(kcontrol);
  913. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  914. struct pahu_priv *pahu_p = snd_soc_codec_get_drvdata(codec);
  915. ucontrol->value.integer.value[0] = pahu_p->tx_port_value;
  916. return 0;
  917. }
  918. static int slim_tx_mixer_put(struct snd_kcontrol *kcontrol,
  919. struct snd_ctl_elem_value *ucontrol)
  920. {
  921. struct snd_soc_dapm_widget *widget =
  922. snd_soc_dapm_kcontrol_widget(kcontrol);
  923. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  924. struct pahu_priv *pahu_p = snd_soc_codec_get_drvdata(codec);
  925. struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent);
  926. struct snd_soc_dapm_update *update = NULL;
  927. struct soc_multi_mixer_control *mixer =
  928. ((struct soc_multi_mixer_control *)kcontrol->private_value);
  929. u32 dai_id = widget->shift;
  930. u32 port_id = mixer->shift;
  931. u32 enable = ucontrol->value.integer.value[0];
  932. u32 vtable;
  933. dev_dbg(codec->dev, "%s: wname %s cname %s value %u shift %d item %ld\n",
  934. __func__,
  935. widget->name, ucontrol->id.name, pahu_p->tx_port_value,
  936. widget->shift, ucontrol->value.integer.value[0]);
  937. mutex_lock(&pahu_p->codec_mutex);
  938. if (dai_id >= ARRAY_SIZE(vport_slim_check_table)) {
  939. dev_err(codec->dev, "%s: dai_id: %d, out of bounds\n",
  940. __func__, dai_id);
  941. mutex_unlock(&pahu_p->codec_mutex);
  942. return -EINVAL;
  943. }
  944. vtable = vport_slim_check_table[dai_id];
  945. switch (dai_id) {
  946. case AIF1_CAP:
  947. case AIF2_CAP:
  948. case AIF3_CAP:
  949. /* only add to the list if value not set */
  950. if (enable && !(pahu_p->tx_port_value & 1 << port_id)) {
  951. if (wcd9xxx_tx_vport_validation(vtable, port_id,
  952. pahu_p->dai, NUM_CODEC_DAIS)) {
  953. dev_dbg(codec->dev, "%s: TX%u is used by other virtual port\n",
  954. __func__, port_id);
  955. mutex_unlock(&pahu_p->codec_mutex);
  956. return 0;
  957. }
  958. pahu_p->tx_port_value |= 1 << port_id;
  959. list_add_tail(&core->tx_chs[port_id].list,
  960. &pahu_p->dai[dai_id].wcd9xxx_ch_list);
  961. } else if (!enable && (pahu_p->tx_port_value &
  962. 1 << port_id)) {
  963. pahu_p->tx_port_value &= ~(1 << port_id);
  964. list_del_init(&core->tx_chs[port_id].list);
  965. } else {
  966. if (enable)
  967. dev_dbg(codec->dev, "%s: TX%u port is used by\n"
  968. "this virtual port\n",
  969. __func__, port_id);
  970. else
  971. dev_dbg(codec->dev, "%s: TX%u port is not used by\n"
  972. "this virtual port\n",
  973. __func__, port_id);
  974. /* avoid update power function */
  975. mutex_unlock(&pahu_p->codec_mutex);
  976. return 0;
  977. }
  978. break;
  979. case AIF4_MAD_TX:
  980. break;
  981. default:
  982. dev_err(codec->dev, "Unknown AIF %d\n", dai_id);
  983. mutex_unlock(&pahu_p->codec_mutex);
  984. return -EINVAL;
  985. }
  986. dev_dbg(codec->dev, "%s: name %s sname %s updated value %u shift %d\n",
  987. __func__, widget->name, widget->sname, pahu_p->tx_port_value,
  988. widget->shift);
  989. mutex_unlock(&pahu_p->codec_mutex);
  990. snd_soc_dapm_mixer_update_power(widget->dapm, kcontrol, enable, update);
  991. return 0;
  992. }
  993. static int slim_rx_mux_get(struct snd_kcontrol *kcontrol,
  994. struct snd_ctl_elem_value *ucontrol)
  995. {
  996. struct snd_soc_dapm_widget *widget =
  997. snd_soc_dapm_kcontrol_widget(kcontrol);
  998. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  999. struct pahu_priv *pahu_p = snd_soc_codec_get_drvdata(codec);
  1000. ucontrol->value.enumerated.item[0] =
  1001. pahu_p->rx_port_value[widget->shift];
  1002. return 0;
  1003. }
  1004. static int slim_rx_mux_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 pahu_priv *pahu_p = snd_soc_codec_get_drvdata(codec);
  1011. struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent);
  1012. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1013. struct snd_soc_dapm_update *update = NULL;
  1014. unsigned int rx_port_value;
  1015. u32 port_id = widget->shift;
  1016. pahu_p->rx_port_value[port_id] = ucontrol->value.enumerated.item[0];
  1017. rx_port_value = pahu_p->rx_port_value[port_id];
  1018. mutex_lock(&pahu_p->codec_mutex);
  1019. dev_dbg(codec->dev, "%s: wname %s cname %s value %u shift %d item %ld\n",
  1020. __func__, widget->name, ucontrol->id.name,
  1021. rx_port_value, widget->shift,
  1022. ucontrol->value.integer.value[0]);
  1023. /* value need to match the Virtual port and AIF number */
  1024. switch (rx_port_value) {
  1025. case 0:
  1026. list_del_init(&core->rx_chs[port_id].list);
  1027. break;
  1028. case 1:
  1029. if (wcd9xxx_rx_vport_validation(port_id +
  1030. WCD9360_RX_PORT_START_NUMBER,
  1031. &pahu_p->dai[AIF1_PB].wcd9xxx_ch_list)) {
  1032. dev_dbg(codec->dev, "%s: RX%u is used by current requesting AIF_PB itself\n",
  1033. __func__, port_id);
  1034. goto rtn;
  1035. }
  1036. list_add_tail(&core->rx_chs[port_id].list,
  1037. &pahu_p->dai[AIF1_PB].wcd9xxx_ch_list);
  1038. break;
  1039. case 2:
  1040. if (wcd9xxx_rx_vport_validation(port_id +
  1041. WCD9360_RX_PORT_START_NUMBER,
  1042. &pahu_p->dai[AIF2_PB].wcd9xxx_ch_list)) {
  1043. dev_dbg(codec->dev, "%s: RX%u is used by current requesting AIF_PB itself\n",
  1044. __func__, port_id);
  1045. goto rtn;
  1046. }
  1047. list_add_tail(&core->rx_chs[port_id].list,
  1048. &pahu_p->dai[AIF2_PB].wcd9xxx_ch_list);
  1049. break;
  1050. case 3:
  1051. if (wcd9xxx_rx_vport_validation(port_id +
  1052. WCD9360_RX_PORT_START_NUMBER,
  1053. &pahu_p->dai[AIF3_PB].wcd9xxx_ch_list)) {
  1054. dev_dbg(codec->dev, "%s: RX%u is used by current requesting AIF_PB itself\n",
  1055. __func__, port_id);
  1056. goto rtn;
  1057. }
  1058. list_add_tail(&core->rx_chs[port_id].list,
  1059. &pahu_p->dai[AIF3_PB].wcd9xxx_ch_list);
  1060. break;
  1061. case 4:
  1062. if (wcd9xxx_rx_vport_validation(port_id +
  1063. WCD9360_RX_PORT_START_NUMBER,
  1064. &pahu_p->dai[AIF4_PB].wcd9xxx_ch_list)) {
  1065. dev_dbg(codec->dev, "%s: RX%u is used by current requesting AIF_PB itself\n",
  1066. __func__, port_id);
  1067. goto rtn;
  1068. }
  1069. list_add_tail(&core->rx_chs[port_id].list,
  1070. &pahu_p->dai[AIF4_PB].wcd9xxx_ch_list);
  1071. break;
  1072. default:
  1073. dev_err(codec->dev, "Unknown AIF %d\n", rx_port_value);
  1074. goto err;
  1075. }
  1076. rtn:
  1077. mutex_unlock(&pahu_p->codec_mutex);
  1078. snd_soc_dapm_mux_update_power(widget->dapm, kcontrol,
  1079. rx_port_value, e, update);
  1080. return 0;
  1081. err:
  1082. mutex_unlock(&pahu_p->codec_mutex);
  1083. return -EINVAL;
  1084. }
  1085. static void pahu_codec_enable_slim_port_intr(
  1086. struct wcd9xxx_codec_dai_data *dai,
  1087. struct snd_soc_codec *codec)
  1088. {
  1089. struct wcd9xxx_ch *ch;
  1090. int port_num = 0;
  1091. unsigned short reg = 0;
  1092. u8 val = 0;
  1093. struct pahu_priv *pahu_p;
  1094. if (!dai || !codec) {
  1095. pr_err("%s: Invalid params\n", __func__);
  1096. return;
  1097. }
  1098. pahu_p = snd_soc_codec_get_drvdata(codec);
  1099. list_for_each_entry(ch, &dai->wcd9xxx_ch_list, list) {
  1100. if (ch->port >= WCD9360_RX_PORT_START_NUMBER) {
  1101. port_num = ch->port - WCD9360_RX_PORT_START_NUMBER;
  1102. reg = WCD9360_SLIM_PGD_PORT_INT_RX_EN0 + (port_num / 8);
  1103. val = wcd9xxx_interface_reg_read(pahu_p->wcd9xxx,
  1104. reg);
  1105. if (!(val & BYTE_BIT_MASK(port_num))) {
  1106. val |= BYTE_BIT_MASK(port_num);
  1107. wcd9xxx_interface_reg_write(
  1108. pahu_p->wcd9xxx, reg, val);
  1109. val = wcd9xxx_interface_reg_read(
  1110. pahu_p->wcd9xxx, reg);
  1111. }
  1112. } else {
  1113. port_num = ch->port;
  1114. reg = WCD9360_SLIM_PGD_PORT_INT_TX_EN0 + (port_num / 8);
  1115. val = wcd9xxx_interface_reg_read(pahu_p->wcd9xxx,
  1116. reg);
  1117. if (!(val & BYTE_BIT_MASK(port_num))) {
  1118. val |= BYTE_BIT_MASK(port_num);
  1119. wcd9xxx_interface_reg_write(pahu_p->wcd9xxx,
  1120. reg, val);
  1121. val = wcd9xxx_interface_reg_read(
  1122. pahu_p->wcd9xxx, reg);
  1123. }
  1124. }
  1125. }
  1126. }
  1127. static int pahu_codec_enable_slim_chmask(struct wcd9xxx_codec_dai_data *dai,
  1128. bool up)
  1129. {
  1130. int ret = 0;
  1131. struct wcd9xxx_ch *ch;
  1132. if (up) {
  1133. list_for_each_entry(ch, &dai->wcd9xxx_ch_list, list) {
  1134. ret = wcd9xxx_get_slave_port(ch->ch_num);
  1135. if (ret < 0) {
  1136. pr_err("%s: Invalid slave port ID: %d\n",
  1137. __func__, ret);
  1138. ret = -EINVAL;
  1139. } else {
  1140. set_bit(ret, &dai->ch_mask);
  1141. }
  1142. }
  1143. } else {
  1144. ret = wait_event_timeout(dai->dai_wait, (dai->ch_mask == 0),
  1145. msecs_to_jiffies(
  1146. WCD9360_SLIM_CLOSE_TIMEOUT));
  1147. if (!ret) {
  1148. pr_err("%s: Slim close tx/rx wait timeout, ch_mask:0x%lx\n",
  1149. __func__, dai->ch_mask);
  1150. ret = -ETIMEDOUT;
  1151. } else {
  1152. ret = 0;
  1153. }
  1154. }
  1155. return ret;
  1156. }
  1157. static int pahu_codec_enable_slimrx(struct snd_soc_dapm_widget *w,
  1158. struct snd_kcontrol *kcontrol,
  1159. int event)
  1160. {
  1161. struct wcd9xxx *core;
  1162. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1163. struct pahu_priv *pahu_p = snd_soc_codec_get_drvdata(codec);
  1164. int ret = 0;
  1165. struct wcd9xxx_codec_dai_data *dai;
  1166. core = dev_get_drvdata(codec->dev->parent);
  1167. dev_dbg(codec->dev, "%s: event called! codec name %s num_dai %d\n"
  1168. "stream name %s event %d\n",
  1169. __func__, codec->component.name,
  1170. codec->component.num_dai, w->sname, event);
  1171. dai = &pahu_p->dai[w->shift];
  1172. dev_dbg(codec->dev, "%s: w->name %s w->shift %d event %d\n",
  1173. __func__, w->name, w->shift, event);
  1174. switch (event) {
  1175. case SND_SOC_DAPM_POST_PMU:
  1176. dai->bus_down_in_recovery = false;
  1177. pahu_codec_enable_slim_port_intr(dai, codec);
  1178. (void) pahu_codec_enable_slim_chmask(dai, true);
  1179. ret = wcd9xxx_cfg_slim_sch_rx(core, &dai->wcd9xxx_ch_list,
  1180. dai->rate, dai->bit_width,
  1181. &dai->grph);
  1182. break;
  1183. case SND_SOC_DAPM_POST_PMD:
  1184. ret = wcd9xxx_disconnect_port(core, &dai->wcd9xxx_ch_list,
  1185. dai->grph);
  1186. dev_dbg(codec->dev, "%s: Disconnect RX port, ret = %d\n",
  1187. __func__, ret);
  1188. if (!dai->bus_down_in_recovery)
  1189. ret = pahu_codec_enable_slim_chmask(dai, false);
  1190. else
  1191. dev_dbg(codec->dev,
  1192. "%s: bus in recovery skip enable slim_chmask",
  1193. __func__);
  1194. ret = wcd9xxx_close_slim_sch_rx(core, &dai->wcd9xxx_ch_list,
  1195. dai->grph);
  1196. break;
  1197. }
  1198. return ret;
  1199. }
  1200. static int pahu_codec_enable_slimtx(struct snd_soc_dapm_widget *w,
  1201. struct snd_kcontrol *kcontrol,
  1202. int event)
  1203. {
  1204. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1205. struct pahu_priv *pahu_p = snd_soc_codec_get_drvdata(codec);
  1206. struct wcd9xxx_codec_dai_data *dai;
  1207. struct wcd9xxx *core;
  1208. int ret = 0;
  1209. dev_dbg(codec->dev,
  1210. "%s: w->name %s, w->shift = %d, num_dai %d stream name %s\n",
  1211. __func__, w->name, w->shift,
  1212. codec->component.num_dai, w->sname);
  1213. dai = &pahu_p->dai[w->shift];
  1214. core = dev_get_drvdata(codec->dev->parent);
  1215. switch (event) {
  1216. case SND_SOC_DAPM_POST_PMU:
  1217. dai->bus_down_in_recovery = false;
  1218. pahu_codec_enable_slim_port_intr(dai, codec);
  1219. (void) pahu_codec_enable_slim_chmask(dai, true);
  1220. ret = wcd9xxx_cfg_slim_sch_tx(core, &dai->wcd9xxx_ch_list,
  1221. dai->rate, dai->bit_width,
  1222. &dai->grph);
  1223. break;
  1224. case SND_SOC_DAPM_POST_PMD:
  1225. ret = wcd9xxx_close_slim_sch_tx(core, &dai->wcd9xxx_ch_list,
  1226. dai->grph);
  1227. if (!dai->bus_down_in_recovery)
  1228. ret = pahu_codec_enable_slim_chmask(dai, false);
  1229. if (ret < 0) {
  1230. ret = wcd9xxx_disconnect_port(core,
  1231. &dai->wcd9xxx_ch_list,
  1232. dai->grph);
  1233. dev_dbg(codec->dev, "%s: Disconnect RX port, ret = %d\n",
  1234. __func__, ret);
  1235. }
  1236. break;
  1237. }
  1238. return ret;
  1239. }
  1240. static int pahu_codec_enable_slimvi_feedback(struct snd_soc_dapm_widget *w,
  1241. struct snd_kcontrol *kcontrol,
  1242. int event)
  1243. {
  1244. struct wcd9xxx *core = NULL;
  1245. struct snd_soc_codec *codec = NULL;
  1246. struct pahu_priv *pahu_p = NULL;
  1247. int ret = 0;
  1248. struct wcd9xxx_codec_dai_data *dai = NULL;
  1249. codec = snd_soc_dapm_to_codec(w->dapm);
  1250. pahu_p = snd_soc_codec_get_drvdata(codec);
  1251. core = dev_get_drvdata(codec->dev->parent);
  1252. dev_dbg(codec->dev,
  1253. "%s: num_dai %d stream name %s w->name %s event %d shift %d\n",
  1254. __func__, codec->component.num_dai, w->sname,
  1255. w->name, event, w->shift);
  1256. if (w->shift != AIF4_VIFEED) {
  1257. pr_err("%s Error in enabling the tx path\n", __func__);
  1258. ret = -EINVAL;
  1259. goto done;
  1260. }
  1261. dai = &pahu_p->dai[w->shift];
  1262. switch (event) {
  1263. case SND_SOC_DAPM_POST_PMU:
  1264. if (test_bit(VI_SENSE_1, &pahu_p->status_mask)) {
  1265. dev_dbg(codec->dev, "%s: spkr1 enabled\n", __func__);
  1266. /* Enable V&I sensing */
  1267. snd_soc_update_bits(codec,
  1268. WCD9360_CDC_TX9_SPKR_PROT_PATH_CTL, 0x20, 0x20);
  1269. snd_soc_update_bits(codec,
  1270. WCD9360_CDC_TX10_SPKR_PROT_PATH_CTL, 0x20,
  1271. 0x20);
  1272. snd_soc_update_bits(codec,
  1273. WCD9360_CDC_TX9_SPKR_PROT_PATH_CTL, 0x0F, 0x00);
  1274. snd_soc_update_bits(codec,
  1275. WCD9360_CDC_TX10_SPKR_PROT_PATH_CTL, 0x0F,
  1276. 0x00);
  1277. snd_soc_update_bits(codec,
  1278. WCD9360_CDC_TX9_SPKR_PROT_PATH_CTL, 0x10, 0x10);
  1279. snd_soc_update_bits(codec,
  1280. WCD9360_CDC_TX10_SPKR_PROT_PATH_CTL, 0x10,
  1281. 0x10);
  1282. snd_soc_update_bits(codec,
  1283. WCD9360_CDC_TX9_SPKR_PROT_PATH_CTL, 0x20, 0x00);
  1284. snd_soc_update_bits(codec,
  1285. WCD9360_CDC_TX10_SPKR_PROT_PATH_CTL, 0x20,
  1286. 0x00);
  1287. }
  1288. if (test_bit(VI_SENSE_2, &pahu_p->status_mask)) {
  1289. pr_debug("%s: spkr2 enabled\n", __func__);
  1290. /* Enable V&I sensing */
  1291. snd_soc_update_bits(codec,
  1292. WCD9360_CDC_TX11_SPKR_PROT_PATH_CTL, 0x20,
  1293. 0x20);
  1294. snd_soc_update_bits(codec,
  1295. WCD9360_CDC_TX12_SPKR_PROT_PATH_CTL, 0x20,
  1296. 0x20);
  1297. snd_soc_update_bits(codec,
  1298. WCD9360_CDC_TX11_SPKR_PROT_PATH_CTL, 0x0F,
  1299. 0x00);
  1300. snd_soc_update_bits(codec,
  1301. WCD9360_CDC_TX12_SPKR_PROT_PATH_CTL, 0x0F,
  1302. 0x00);
  1303. snd_soc_update_bits(codec,
  1304. WCD9360_CDC_TX11_SPKR_PROT_PATH_CTL, 0x10,
  1305. 0x10);
  1306. snd_soc_update_bits(codec,
  1307. WCD9360_CDC_TX12_SPKR_PROT_PATH_CTL, 0x10,
  1308. 0x10);
  1309. snd_soc_update_bits(codec,
  1310. WCD9360_CDC_TX11_SPKR_PROT_PATH_CTL, 0x20,
  1311. 0x00);
  1312. snd_soc_update_bits(codec,
  1313. WCD9360_CDC_TX12_SPKR_PROT_PATH_CTL, 0x20,
  1314. 0x00);
  1315. }
  1316. dai->bus_down_in_recovery = false;
  1317. pahu_codec_enable_slim_port_intr(dai, codec);
  1318. (void) pahu_codec_enable_slim_chmask(dai, true);
  1319. ret = wcd9xxx_cfg_slim_sch_tx(core, &dai->wcd9xxx_ch_list,
  1320. dai->rate, dai->bit_width,
  1321. &dai->grph);
  1322. break;
  1323. case SND_SOC_DAPM_POST_PMD:
  1324. ret = wcd9xxx_close_slim_sch_tx(core, &dai->wcd9xxx_ch_list,
  1325. dai->grph);
  1326. if (ret)
  1327. dev_err(codec->dev, "%s error in close_slim_sch_tx %d\n",
  1328. __func__, ret);
  1329. if (!dai->bus_down_in_recovery)
  1330. ret = pahu_codec_enable_slim_chmask(dai, false);
  1331. if (ret < 0) {
  1332. ret = wcd9xxx_disconnect_port(core,
  1333. &dai->wcd9xxx_ch_list,
  1334. dai->grph);
  1335. dev_dbg(codec->dev, "%s: Disconnect TX port, ret = %d\n",
  1336. __func__, ret);
  1337. }
  1338. if (test_bit(VI_SENSE_1, &pahu_p->status_mask)) {
  1339. /* Disable V&I sensing */
  1340. dev_dbg(codec->dev, "%s: spkr1 disabled\n", __func__);
  1341. snd_soc_update_bits(codec,
  1342. WCD9360_CDC_TX9_SPKR_PROT_PATH_CTL, 0x20, 0x20);
  1343. snd_soc_update_bits(codec,
  1344. WCD9360_CDC_TX10_SPKR_PROT_PATH_CTL, 0x20,
  1345. 0x20);
  1346. snd_soc_update_bits(codec,
  1347. WCD9360_CDC_TX9_SPKR_PROT_PATH_CTL, 0x10, 0x00);
  1348. snd_soc_update_bits(codec,
  1349. WCD9360_CDC_TX10_SPKR_PROT_PATH_CTL, 0x10,
  1350. 0x00);
  1351. }
  1352. if (test_bit(VI_SENSE_2, &pahu_p->status_mask)) {
  1353. /* Disable V&I sensing */
  1354. dev_dbg(codec->dev, "%s: spkr2 disabled\n", __func__);
  1355. snd_soc_update_bits(codec,
  1356. WCD9360_CDC_TX11_SPKR_PROT_PATH_CTL, 0x20,
  1357. 0x20);
  1358. snd_soc_update_bits(codec,
  1359. WCD9360_CDC_TX12_SPKR_PROT_PATH_CTL, 0x20,
  1360. 0x20);
  1361. snd_soc_update_bits(codec,
  1362. WCD9360_CDC_TX11_SPKR_PROT_PATH_CTL, 0x10,
  1363. 0x00);
  1364. snd_soc_update_bits(codec,
  1365. WCD9360_CDC_TX12_SPKR_PROT_PATH_CTL, 0x10,
  1366. 0x00);
  1367. }
  1368. break;
  1369. }
  1370. done:
  1371. return ret;
  1372. }
  1373. static int pahu_codec_enable_ldo_rxtx(struct snd_soc_dapm_widget *w,
  1374. struct snd_kcontrol *kcontrol, int event)
  1375. {
  1376. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1377. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(codec);
  1378. struct wcd9xxx_pdata *pdata = dev_get_platdata(codec->dev->parent);
  1379. dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
  1380. switch (event) {
  1381. case SND_SOC_DAPM_PRE_PMU:
  1382. pahu->ldo_rxtx_cnt++;
  1383. if (pahu->ldo_rxtx_cnt == 1) {
  1384. /* Enable VDD_LDO_RxTx regulator */
  1385. msm_cdc_enable_ondemand_supply(pahu->wcd9xxx->dev,
  1386. pahu->wcd9xxx->supplies,
  1387. pdata->regulator,
  1388. pdata->num_supplies,
  1389. WCD9360_LDO_RXTX_SUPPLY_NAME);
  1390. snd_soc_update_bits(codec, WCD9360_LDORXTX_LDORXTX,
  1391. 0x80, 0x80);
  1392. }
  1393. break;
  1394. case SND_SOC_DAPM_POST_PMD:
  1395. pahu->ldo_rxtx_cnt--;
  1396. if (pahu->ldo_rxtx_cnt < 0)
  1397. pahu->ldo_rxtx_cnt = 0;
  1398. if (!pahu->ldo_rxtx_cnt) {
  1399. snd_soc_update_bits(codec, WCD9360_LDORXTX_LDORXTX,
  1400. 0x80, 0x00);
  1401. /* Disable VDD_LDO_RxTx regulator */
  1402. msm_cdc_disable_ondemand_supply(pahu->wcd9xxx->dev,
  1403. pahu->wcd9xxx->supplies,
  1404. pdata->regulator,
  1405. pdata->num_supplies,
  1406. WCD9360_LDO_RXTX_SUPPLY_NAME);
  1407. }
  1408. break;
  1409. };
  1410. dev_dbg(codec->dev, "%s: Current LDO RXTX user count: %d\n", __func__,
  1411. pahu->ldo_rxtx_cnt);
  1412. return 0;
  1413. }
  1414. static void pahu_spk_anc_update_callback(struct work_struct *work)
  1415. {
  1416. struct spk_anc_work *spk_anc_dwork;
  1417. struct pahu_priv *pahu;
  1418. struct delayed_work *delayed_work;
  1419. struct snd_soc_codec *codec;
  1420. delayed_work = to_delayed_work(work);
  1421. spk_anc_dwork = container_of(delayed_work, struct spk_anc_work, dwork);
  1422. pahu = spk_anc_dwork->pahu;
  1423. codec = pahu->codec;
  1424. snd_soc_update_bits(codec, WCD9360_CDC_RX7_RX_PATH_CFG0, 0x10, 0x10);
  1425. }
  1426. static int pahu_codec_enable_spkr_anc(struct snd_soc_dapm_widget *w,
  1427. struct snd_kcontrol *kcontrol,
  1428. int event)
  1429. {
  1430. int ret = 0;
  1431. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1432. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(codec);
  1433. if (!pahu->anc_func)
  1434. return 0;
  1435. dev_dbg(codec->dev, "%s: w: %s event: %d anc: %d\n", __func__,
  1436. w->name, event, pahu->anc_func);
  1437. switch (event) {
  1438. case SND_SOC_DAPM_PRE_PMU:
  1439. ret = pahu_codec_enable_anc(w, kcontrol, event);
  1440. schedule_delayed_work(&pahu->spk_anc_dwork.dwork,
  1441. msecs_to_jiffies(spk_anc_en_delay));
  1442. break;
  1443. case SND_SOC_DAPM_POST_PMD:
  1444. cancel_delayed_work_sync(&pahu->spk_anc_dwork.dwork);
  1445. snd_soc_update_bits(codec, WCD9360_CDC_RX7_RX_PATH_CFG0,
  1446. 0x10, 0x00);
  1447. ret = pahu_codec_enable_anc(w, kcontrol, event);
  1448. break;
  1449. }
  1450. return ret;
  1451. }
  1452. static int pahu_codec_enable_aux_pa(struct snd_soc_dapm_widget *w,
  1453. struct snd_kcontrol *kcontrol,
  1454. int event)
  1455. {
  1456. int ret = 0;
  1457. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1458. dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
  1459. switch (event) {
  1460. case SND_SOC_DAPM_POST_PMU:
  1461. /*
  1462. * 5ms sleep is required after PA is enabled as per
  1463. * HW requirement
  1464. */
  1465. usleep_range(5000, 5500);
  1466. snd_soc_update_bits(codec, WCD9360_CDC_RX9_RX_PATH_CTL,
  1467. 0x10, 0x00);
  1468. /* Remove mix path mute if it is enabled */
  1469. if ((snd_soc_read(codec, WCD9360_CDC_RX9_RX_PATH_MIX_CTL)) &
  1470. 0x10)
  1471. snd_soc_update_bits(codec,
  1472. WCD9360_CDC_RX9_RX_PATH_MIX_CTL,
  1473. 0x10, 0x00);
  1474. break;
  1475. default:
  1476. break;
  1477. };
  1478. return ret;
  1479. }
  1480. static int pahu_codec_enable_ear_pa(struct snd_soc_dapm_widget *w,
  1481. struct snd_kcontrol *kcontrol,
  1482. int event)
  1483. {
  1484. int ret = 0;
  1485. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1486. dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
  1487. switch (event) {
  1488. case SND_SOC_DAPM_POST_PMU:
  1489. /*
  1490. * 5ms sleep is required after PA is enabled as per
  1491. * HW requirement
  1492. */
  1493. usleep_range(5000, 5500);
  1494. snd_soc_update_bits(codec, WCD9360_CDC_RX0_RX_PATH_CTL,
  1495. 0x10, 0x00);
  1496. /* Remove mix path mute if it is enabled */
  1497. if ((snd_soc_read(codec, WCD9360_CDC_RX0_RX_PATH_MIX_CTL)) &
  1498. 0x10)
  1499. snd_soc_update_bits(codec,
  1500. WCD9360_CDC_RX0_RX_PATH_MIX_CTL,
  1501. 0x10, 0x00);
  1502. break;
  1503. case SND_SOC_DAPM_POST_PMD:
  1504. /*
  1505. * 5ms sleep is required after PA is disabled as per
  1506. * HW requirement
  1507. */
  1508. usleep_range(5000, 5500);
  1509. if (!(strcmp(w->name, "ANC EAR PA"))) {
  1510. ret = pahu_codec_enable_anc(w, kcontrol, event);
  1511. snd_soc_update_bits(codec, WCD9360_CDC_RX0_RX_PATH_CFG0,
  1512. 0x10, 0x00);
  1513. }
  1514. break;
  1515. };
  1516. return ret;
  1517. }
  1518. static int pahu_codec_ear_dac_event(struct snd_soc_dapm_widget *w,
  1519. struct snd_kcontrol *kcontrol,
  1520. int event)
  1521. {
  1522. int ret = 0;
  1523. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1524. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(codec);
  1525. dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
  1526. switch (event) {
  1527. case SND_SOC_DAPM_PRE_PMU:
  1528. if (pahu->anc_func) {
  1529. ret = pahu_codec_enable_anc(w, kcontrol, event);
  1530. snd_soc_update_bits(codec, WCD9360_CDC_RX0_RX_PATH_CFG0,
  1531. 0x10, 0x10);
  1532. }
  1533. break;
  1534. default:
  1535. break;
  1536. };
  1537. return ret;
  1538. }
  1539. static int pahu_codec_spk_boost_event(struct snd_soc_dapm_widget *w,
  1540. struct snd_kcontrol *kcontrol,
  1541. int event)
  1542. {
  1543. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1544. u16 boost_path_ctl, boost_path_cfg1;
  1545. u16 reg, reg_mix;
  1546. dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
  1547. if (!strcmp(w->name, "RX INT7 CHAIN")) {
  1548. boost_path_ctl = WCD9360_CDC_BOOST0_BOOST_PATH_CTL;
  1549. boost_path_cfg1 = WCD9360_CDC_RX7_RX_PATH_CFG1;
  1550. reg = WCD9360_CDC_RX7_RX_PATH_CTL;
  1551. reg_mix = WCD9360_CDC_RX7_RX_PATH_MIX_CTL;
  1552. } else if (!strcmp(w->name, "RX INT8 CHAIN")) {
  1553. boost_path_ctl = WCD9360_CDC_BOOST1_BOOST_PATH_CTL;
  1554. boost_path_cfg1 = WCD9360_CDC_RX8_RX_PATH_CFG1;
  1555. reg = WCD9360_CDC_RX8_RX_PATH_CTL;
  1556. reg_mix = WCD9360_CDC_RX8_RX_PATH_MIX_CTL;
  1557. } else {
  1558. dev_err(codec->dev, "%s: unknown widget: %s\n",
  1559. __func__, w->name);
  1560. return -EINVAL;
  1561. }
  1562. switch (event) {
  1563. case SND_SOC_DAPM_PRE_PMU:
  1564. snd_soc_update_bits(codec, boost_path_cfg1, 0x01, 0x01);
  1565. snd_soc_update_bits(codec, boost_path_ctl, 0x10, 0x10);
  1566. snd_soc_update_bits(codec, reg, 0x10, 0x00);
  1567. if ((snd_soc_read(codec, reg_mix)) & 0x10)
  1568. snd_soc_update_bits(codec, reg_mix, 0x10, 0x00);
  1569. break;
  1570. case SND_SOC_DAPM_POST_PMD:
  1571. snd_soc_update_bits(codec, boost_path_ctl, 0x10, 0x00);
  1572. snd_soc_update_bits(codec, boost_path_cfg1, 0x01, 0x00);
  1573. break;
  1574. };
  1575. return 0;
  1576. }
  1577. static int __pahu_codec_enable_swr(struct snd_soc_dapm_widget *w, int event)
  1578. {
  1579. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1580. struct pahu_priv *pahu;
  1581. int ch_cnt = 0;
  1582. pahu = snd_soc_codec_get_drvdata(codec);
  1583. switch (event) {
  1584. case SND_SOC_DAPM_PRE_PMU:
  1585. if (((strnstr(w->name, "INT7_", sizeof("RX INT7_"))) ||
  1586. (strnstr(w->name, "INT7 MIX2",
  1587. sizeof("RX INT7 MIX2")))))
  1588. pahu->swr.rx_7_count++;
  1589. if ((strnstr(w->name, "INT8_", sizeof("RX INT8_"))) &&
  1590. !pahu->swr.rx_8_count)
  1591. pahu->swr.rx_8_count++;
  1592. ch_cnt = !!(pahu->swr.rx_7_count) + pahu->swr.rx_8_count;
  1593. swrm_wcd_notify(pahu->swr.ctrl_data[0].swr_pdev,
  1594. SWR_DEVICE_UP, NULL);
  1595. swrm_wcd_notify(pahu->swr.ctrl_data[0].swr_pdev,
  1596. SWR_SET_NUM_RX_CH, &ch_cnt);
  1597. break;
  1598. case SND_SOC_DAPM_POST_PMD:
  1599. if ((strnstr(w->name, "INT7_", sizeof("RX INT7_"))) ||
  1600. (strnstr(w->name, "INT7 MIX2",
  1601. sizeof("RX INT7 MIX2"))))
  1602. pahu->swr.rx_7_count--;
  1603. if ((strnstr(w->name, "INT8_", sizeof("RX INT8_"))) &&
  1604. pahu->swr.rx_8_count)
  1605. pahu->swr.rx_8_count--;
  1606. ch_cnt = !!(pahu->swr.rx_7_count) + pahu->swr.rx_8_count;
  1607. swrm_wcd_notify(pahu->swr.ctrl_data[0].swr_pdev,
  1608. SWR_SET_NUM_RX_CH, &ch_cnt);
  1609. break;
  1610. }
  1611. dev_dbg(pahu->dev, "%s: %s: current swr ch cnt: %d\n",
  1612. __func__, w->name, ch_cnt);
  1613. return 0;
  1614. }
  1615. static int pahu_codec_enable_swr(struct snd_soc_dapm_widget *w,
  1616. struct snd_kcontrol *kcontrol, int event)
  1617. {
  1618. return __pahu_codec_enable_swr(w, event);
  1619. }
  1620. static int pahu_codec_config_mad(struct snd_soc_codec *codec)
  1621. {
  1622. int ret = 0;
  1623. int idx;
  1624. const struct firmware *fw;
  1625. struct firmware_cal *hwdep_cal = NULL;
  1626. struct wcd_mad_audio_cal *mad_cal = NULL;
  1627. const void *data;
  1628. const char *filename = WCD9360_MAD_AUDIO_FIRMWARE_PATH;
  1629. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(codec);
  1630. size_t cal_size;
  1631. hwdep_cal = wcdcal_get_fw_cal(pahu->fw_data, WCD9XXX_MAD_CAL);
  1632. if (hwdep_cal) {
  1633. data = hwdep_cal->data;
  1634. cal_size = hwdep_cal->size;
  1635. dev_dbg(codec->dev, "%s: using hwdep calibration\n",
  1636. __func__);
  1637. } else {
  1638. ret = request_firmware(&fw, filename, codec->dev);
  1639. if (ret || !fw) {
  1640. dev_err(codec->dev,
  1641. "%s: MAD firmware acquire failed, err = %d\n",
  1642. __func__, ret);
  1643. return -ENODEV;
  1644. }
  1645. data = fw->data;
  1646. cal_size = fw->size;
  1647. dev_dbg(codec->dev, "%s: using request_firmware calibration\n",
  1648. __func__);
  1649. }
  1650. if (cal_size < sizeof(*mad_cal)) {
  1651. dev_err(codec->dev,
  1652. "%s: Incorrect size %zd for MAD Cal, expected %zd\n",
  1653. __func__, cal_size, sizeof(*mad_cal));
  1654. ret = -ENOMEM;
  1655. goto done;
  1656. }
  1657. mad_cal = (struct wcd_mad_audio_cal *) (data);
  1658. if (!mad_cal) {
  1659. dev_err(codec->dev,
  1660. "%s: Invalid calibration data\n",
  1661. __func__);
  1662. ret = -EINVAL;
  1663. goto done;
  1664. }
  1665. snd_soc_write(codec, WCD9360_SOC_MAD_MAIN_CTL_2,
  1666. mad_cal->microphone_info.cycle_time);
  1667. snd_soc_update_bits(codec, WCD9360_SOC_MAD_MAIN_CTL_1, 0xFF << 3,
  1668. ((uint16_t)mad_cal->microphone_info.settle_time)
  1669. << 3);
  1670. /* Audio */
  1671. snd_soc_write(codec, WCD9360_SOC_MAD_AUDIO_CTL_8,
  1672. mad_cal->audio_info.rms_omit_samples);
  1673. snd_soc_update_bits(codec, WCD9360_SOC_MAD_AUDIO_CTL_1,
  1674. 0x07 << 4, mad_cal->audio_info.rms_comp_time << 4);
  1675. snd_soc_update_bits(codec, WCD9360_SOC_MAD_AUDIO_CTL_2, 0x03 << 2,
  1676. mad_cal->audio_info.detection_mechanism << 2);
  1677. snd_soc_write(codec, WCD9360_SOC_MAD_AUDIO_CTL_7,
  1678. mad_cal->audio_info.rms_diff_threshold & 0x3F);
  1679. snd_soc_write(codec, WCD9360_SOC_MAD_AUDIO_CTL_5,
  1680. mad_cal->audio_info.rms_threshold_lsb);
  1681. snd_soc_write(codec, WCD9360_SOC_MAD_AUDIO_CTL_6,
  1682. mad_cal->audio_info.rms_threshold_msb);
  1683. for (idx = 0; idx < ARRAY_SIZE(mad_cal->audio_info.iir_coefficients);
  1684. idx++) {
  1685. snd_soc_update_bits(codec, WCD9360_SOC_MAD_AUDIO_IIR_CTL_PTR,
  1686. 0x3F, idx);
  1687. snd_soc_write(codec, WCD9360_SOC_MAD_AUDIO_IIR_CTL_VAL,
  1688. mad_cal->audio_info.iir_coefficients[idx]);
  1689. dev_dbg(codec->dev, "%s:MAD Audio IIR Coef[%d] = 0X%x",
  1690. __func__, idx,
  1691. mad_cal->audio_info.iir_coefficients[idx]);
  1692. }
  1693. /* Beacon */
  1694. snd_soc_write(codec, WCD9360_SOC_MAD_BEACON_CTL_8,
  1695. mad_cal->beacon_info.rms_omit_samples);
  1696. snd_soc_update_bits(codec, WCD9360_SOC_MAD_BEACON_CTL_1,
  1697. 0x07 << 4, mad_cal->beacon_info.rms_comp_time << 4);
  1698. snd_soc_update_bits(codec, WCD9360_SOC_MAD_BEACON_CTL_2, 0x03 << 2,
  1699. mad_cal->beacon_info.detection_mechanism << 2);
  1700. snd_soc_write(codec, WCD9360_SOC_MAD_BEACON_CTL_7,
  1701. mad_cal->beacon_info.rms_diff_threshold & 0x1F);
  1702. snd_soc_write(codec, WCD9360_SOC_MAD_BEACON_CTL_5,
  1703. mad_cal->beacon_info.rms_threshold_lsb);
  1704. snd_soc_write(codec, WCD9360_SOC_MAD_BEACON_CTL_6,
  1705. mad_cal->beacon_info.rms_threshold_msb);
  1706. for (idx = 0; idx < ARRAY_SIZE(mad_cal->beacon_info.iir_coefficients);
  1707. idx++) {
  1708. snd_soc_update_bits(codec, WCD9360_SOC_MAD_BEACON_IIR_CTL_PTR,
  1709. 0x3F, idx);
  1710. snd_soc_write(codec, WCD9360_SOC_MAD_BEACON_IIR_CTL_VAL,
  1711. mad_cal->beacon_info.iir_coefficients[idx]);
  1712. dev_dbg(codec->dev, "%s:MAD Beacon IIR Coef[%d] = 0X%x",
  1713. __func__, idx,
  1714. mad_cal->beacon_info.iir_coefficients[idx]);
  1715. }
  1716. /* Ultrasound */
  1717. snd_soc_update_bits(codec, WCD9360_SOC_MAD_ULTR_CTL_1,
  1718. 0x07 << 4,
  1719. mad_cal->ultrasound_info.rms_comp_time << 4);
  1720. snd_soc_update_bits(codec, WCD9360_SOC_MAD_ULTR_CTL_2, 0x03 << 2,
  1721. mad_cal->ultrasound_info.detection_mechanism << 2);
  1722. snd_soc_write(codec, WCD9360_SOC_MAD_ULTR_CTL_7,
  1723. mad_cal->ultrasound_info.rms_diff_threshold & 0x1F);
  1724. snd_soc_write(codec, WCD9360_SOC_MAD_ULTR_CTL_5,
  1725. mad_cal->ultrasound_info.rms_threshold_lsb);
  1726. snd_soc_write(codec, WCD9360_SOC_MAD_ULTR_CTL_6,
  1727. mad_cal->ultrasound_info.rms_threshold_msb);
  1728. done:
  1729. if (!hwdep_cal)
  1730. release_firmware(fw);
  1731. return ret;
  1732. }
  1733. static int __pahu_codec_enable_mad(struct snd_soc_codec *codec, bool enable)
  1734. {
  1735. int rc = 0;
  1736. /* Return if CPE INPUT is DEC1 */
  1737. if (snd_soc_read(codec, WCD9360_CPE_SS_SVA_CFG) & 0x04) {
  1738. dev_dbg(codec->dev, "%s: MAD is bypassed, skip mad %s\n",
  1739. __func__, enable ? "enable" : "disable");
  1740. return rc;
  1741. }
  1742. dev_dbg(codec->dev, "%s: enable = %s\n", __func__,
  1743. enable ? "enable" : "disable");
  1744. if (enable) {
  1745. snd_soc_update_bits(codec, WCD9360_SOC_MAD_AUDIO_CTL_2,
  1746. 0x03, 0x03);
  1747. rc = pahu_codec_config_mad(codec);
  1748. if (rc < 0) {
  1749. snd_soc_update_bits(codec, WCD9360_SOC_MAD_AUDIO_CTL_2,
  1750. 0x03, 0x00);
  1751. goto done;
  1752. }
  1753. /* Turn on MAD clk */
  1754. snd_soc_update_bits(codec, WCD9360_CPE_SS_MAD_CTL,
  1755. 0x01, 0x01);
  1756. /* Undo reset for MAD */
  1757. snd_soc_update_bits(codec, WCD9360_CPE_SS_MAD_CTL,
  1758. 0x02, 0x00);
  1759. snd_soc_update_bits(codec, WCD9360_CODEC_RPM_CLK_MCLK_CFG,
  1760. 0x04, 0x04);
  1761. } else {
  1762. snd_soc_update_bits(codec, WCD9360_SOC_MAD_AUDIO_CTL_2,
  1763. 0x03, 0x00);
  1764. /* Reset the MAD block */
  1765. snd_soc_update_bits(codec, WCD9360_CPE_SS_MAD_CTL,
  1766. 0x02, 0x02);
  1767. /* Turn off MAD clk */
  1768. snd_soc_update_bits(codec, WCD9360_CPE_SS_MAD_CTL,
  1769. 0x01, 0x00);
  1770. snd_soc_update_bits(codec, WCD9360_CODEC_RPM_CLK_MCLK_CFG,
  1771. 0x04, 0x00);
  1772. }
  1773. done:
  1774. return rc;
  1775. }
  1776. static int pahu_codec_ape_enable_mad(struct snd_soc_dapm_widget *w,
  1777. struct snd_kcontrol *kcontrol,
  1778. int event)
  1779. {
  1780. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1781. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(codec);
  1782. int rc = 0;
  1783. switch (event) {
  1784. case SND_SOC_DAPM_PRE_PMU:
  1785. snd_soc_update_bits(codec, WCD9360_CPE_SS_SVA_CFG, 0x40, 0x40);
  1786. rc = __pahu_codec_enable_mad(codec, true);
  1787. break;
  1788. case SND_SOC_DAPM_PRE_PMD:
  1789. snd_soc_update_bits(codec, WCD9360_CPE_SS_SVA_CFG, 0x40, 0x00);
  1790. __pahu_codec_enable_mad(codec, false);
  1791. break;
  1792. }
  1793. dev_dbg(pahu->dev, "%s: event = %d\n", __func__, event);
  1794. return rc;
  1795. }
  1796. static int pahu_codec_cpe_mad_ctl(struct snd_soc_dapm_widget *w,
  1797. struct snd_kcontrol *kcontrol, int event)
  1798. {
  1799. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1800. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(codec);
  1801. int rc = 0;
  1802. switch (event) {
  1803. case SND_SOC_DAPM_PRE_PMU:
  1804. pahu->mad_switch_cnt++;
  1805. if (pahu->mad_switch_cnt != 1)
  1806. goto done;
  1807. snd_soc_update_bits(codec, WCD9360_CPE_SS_SVA_CFG, 0x20, 0x20);
  1808. rc = __pahu_codec_enable_mad(codec, true);
  1809. if (rc < 0) {
  1810. pahu->mad_switch_cnt--;
  1811. goto done;
  1812. }
  1813. break;
  1814. case SND_SOC_DAPM_PRE_PMD:
  1815. pahu->mad_switch_cnt--;
  1816. if (pahu->mad_switch_cnt != 0)
  1817. goto done;
  1818. snd_soc_update_bits(codec, WCD9360_CPE_SS_SVA_CFG, 0x20, 0x00);
  1819. __pahu_codec_enable_mad(codec, false);
  1820. break;
  1821. }
  1822. done:
  1823. dev_dbg(pahu->dev, "%s: event = %d, mad_switch_cnt = %d\n",
  1824. __func__, event, pahu->mad_switch_cnt);
  1825. return rc;
  1826. }
  1827. static int pahu_get_asrc_mode(struct pahu_priv *pahu, int asrc,
  1828. u8 main_sr, u8 mix_sr)
  1829. {
  1830. u8 asrc_output_mode;
  1831. int asrc_mode = CONV_88P2K_TO_384K;
  1832. if ((asrc < 0) || (asrc >= ASRC_MAX))
  1833. return 0;
  1834. asrc_output_mode = pahu->asrc_output_mode[asrc];
  1835. if (asrc_output_mode) {
  1836. /*
  1837. * If Mix sample rate is < 96KHz, use 96K to 352.8K
  1838. * conversion, or else use 384K to 352.8K conversion
  1839. */
  1840. if (mix_sr < 5)
  1841. asrc_mode = CONV_96K_TO_352P8K;
  1842. else
  1843. asrc_mode = CONV_384K_TO_352P8K;
  1844. } else {
  1845. /* Integer main and Fractional mix path */
  1846. if (main_sr < 8 && mix_sr > 9) {
  1847. asrc_mode = CONV_352P8K_TO_384K;
  1848. } else if (main_sr > 8 && mix_sr < 8) {
  1849. /* Fractional main and Integer mix path */
  1850. if (mix_sr < 5)
  1851. asrc_mode = CONV_96K_TO_352P8K;
  1852. else
  1853. asrc_mode = CONV_384K_TO_352P8K;
  1854. } else if (main_sr < 8 && mix_sr < 8) {
  1855. /* Integer main and Integer mix path */
  1856. asrc_mode = CONV_96K_TO_384K;
  1857. }
  1858. }
  1859. return asrc_mode;
  1860. }
  1861. static int pahu_codec_wdma3_ctl(struct snd_soc_dapm_widget *w,
  1862. struct snd_kcontrol *kcontrol, int event)
  1863. {
  1864. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1865. switch (event) {
  1866. case SND_SOC_DAPM_PRE_PMU:
  1867. /* Fix to 16KHz */
  1868. snd_soc_update_bits(codec, WCD9360_DMA_WDMA_CTL_3,
  1869. 0xF0, 0x10);
  1870. /* Select mclk_1 */
  1871. snd_soc_update_bits(codec, WCD9360_DMA_WDMA_CTL_3,
  1872. 0x02, 0x00);
  1873. /* Enable DMA */
  1874. snd_soc_update_bits(codec, WCD9360_DMA_WDMA_CTL_3,
  1875. 0x01, 0x01);
  1876. break;
  1877. case SND_SOC_DAPM_POST_PMD:
  1878. /* Disable DMA */
  1879. snd_soc_update_bits(codec, WCD9360_DMA_WDMA_CTL_3,
  1880. 0x01, 0x00);
  1881. break;
  1882. };
  1883. return 0;
  1884. }
  1885. static int pahu_codec_enable_asrc(struct snd_soc_codec *codec,
  1886. int asrc_in, int event)
  1887. {
  1888. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(codec);
  1889. u16 cfg_reg, ctl_reg, clk_reg, asrc_ctl, mix_ctl_reg, paired_reg;
  1890. int asrc, ret = 0;
  1891. u8 main_sr, mix_sr, asrc_mode = 0;
  1892. switch (asrc_in) {
  1893. case ASRC_IN_SPKR1:
  1894. cfg_reg = WCD9360_CDC_RX7_RX_PATH_CFG0;
  1895. ctl_reg = WCD9360_CDC_RX7_RX_PATH_CTL;
  1896. clk_reg = WCD9360_MIXING_ASRC2_CLK_RST_CTL;
  1897. paired_reg = WCD9360_MIXING_ASRC2_CLK_RST_CTL;
  1898. asrc_ctl = WCD9360_MIXING_ASRC2_CTL1;
  1899. asrc = ASRC2;
  1900. break;
  1901. case ASRC_IN_SPKR2:
  1902. cfg_reg = WCD9360_CDC_RX8_RX_PATH_CFG0;
  1903. ctl_reg = WCD9360_CDC_RX8_RX_PATH_CTL;
  1904. clk_reg = WCD9360_MIXING_ASRC3_CLK_RST_CTL;
  1905. paired_reg = WCD9360_MIXING_ASRC3_CLK_RST_CTL;
  1906. asrc_ctl = WCD9360_MIXING_ASRC3_CTL1;
  1907. asrc = ASRC3;
  1908. break;
  1909. default:
  1910. dev_err(codec->dev, "%s: Invalid asrc input :%d\n", __func__,
  1911. asrc_in);
  1912. ret = -EINVAL;
  1913. goto done;
  1914. };
  1915. switch (event) {
  1916. case SND_SOC_DAPM_PRE_PMU:
  1917. if (pahu->asrc_users[asrc] == 0) {
  1918. if ((snd_soc_read(codec, clk_reg) & 0x02) ||
  1919. (snd_soc_read(codec, paired_reg) & 0x02)) {
  1920. snd_soc_update_bits(codec, clk_reg,
  1921. 0x02, 0x00);
  1922. snd_soc_update_bits(codec, paired_reg,
  1923. 0x02, 0x00);
  1924. }
  1925. snd_soc_update_bits(codec, cfg_reg, 0x80, 0x80);
  1926. snd_soc_update_bits(codec, clk_reg, 0x01, 0x01);
  1927. main_sr = snd_soc_read(codec, ctl_reg) & 0x0F;
  1928. mix_ctl_reg = ctl_reg + 5;
  1929. mix_sr = snd_soc_read(codec, mix_ctl_reg) & 0x0F;
  1930. asrc_mode = pahu_get_asrc_mode(pahu, asrc,
  1931. main_sr, mix_sr);
  1932. dev_dbg(codec->dev, "%s: main_sr:%d mix_sr:%d asrc_mode %d\n",
  1933. __func__, main_sr, mix_sr, asrc_mode);
  1934. snd_soc_update_bits(codec, asrc_ctl, 0x07, asrc_mode);
  1935. }
  1936. pahu->asrc_users[asrc]++;
  1937. break;
  1938. case SND_SOC_DAPM_POST_PMD:
  1939. pahu->asrc_users[asrc]--;
  1940. if (pahu->asrc_users[asrc] <= 0) {
  1941. pahu->asrc_users[asrc] = 0;
  1942. snd_soc_update_bits(codec, asrc_ctl, 0x07, 0x00);
  1943. snd_soc_update_bits(codec, cfg_reg, 0x80, 0x00);
  1944. snd_soc_update_bits(codec, clk_reg, 0x03, 0x02);
  1945. }
  1946. break;
  1947. };
  1948. dev_dbg(codec->dev, "%s: ASRC%d, users: %d\n",
  1949. __func__, asrc, pahu->asrc_users[asrc]);
  1950. done:
  1951. return ret;
  1952. }
  1953. static int pahu_codec_enable_asrc_resampler(struct snd_soc_dapm_widget *w,
  1954. struct snd_kcontrol *kcontrol,
  1955. int event)
  1956. {
  1957. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1958. int ret = 0;
  1959. u8 cfg, asrc_in;
  1960. cfg = snd_soc_read(codec, WCD9360_CDC_RX_INP_MUX_SPLINE_ASRC_CFG0);
  1961. if (!(cfg & 0xFF)) {
  1962. dev_err(codec->dev, "%s: ASRC%u input not selected\n",
  1963. __func__, w->shift);
  1964. return -EINVAL;
  1965. }
  1966. switch (w->shift) {
  1967. case ASRC2:
  1968. asrc_in = ((cfg & 0x30) == 0x20) ? ASRC_IN_SPKR1 : ASRC_INVALID;
  1969. ret = pahu_codec_enable_asrc(codec, asrc_in, event);
  1970. break;
  1971. case ASRC3:
  1972. asrc_in = ((cfg & 0xC0) == 0x80) ? ASRC_IN_SPKR2 : ASRC_INVALID;
  1973. ret = pahu_codec_enable_asrc(codec, asrc_in, event);
  1974. break;
  1975. default:
  1976. dev_err(codec->dev, "%s: Invalid asrc:%u\n", __func__,
  1977. w->shift);
  1978. ret = -EINVAL;
  1979. break;
  1980. };
  1981. return ret;
  1982. }
  1983. static int pahu_enable_native_supply(struct snd_soc_dapm_widget *w,
  1984. struct snd_kcontrol *kcontrol, int event)
  1985. {
  1986. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1987. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(codec);
  1988. switch (event) {
  1989. case SND_SOC_DAPM_PRE_PMU:
  1990. if (++pahu->native_clk_users == 1) {
  1991. snd_soc_update_bits(codec, WCD9360_CLK_SYS_PLL_ENABLES,
  1992. 0x01, 0x01);
  1993. usleep_range(100, 120);
  1994. snd_soc_update_bits(codec, WCD9360_CLK_SYS_MCLK2_PRG1,
  1995. 0x06, 0x02);
  1996. snd_soc_update_bits(codec, WCD9360_CLK_SYS_MCLK2_PRG1,
  1997. 0x01, 0x01);
  1998. snd_soc_update_bits(codec, WCD9360_CODEC_RPM_CLK_GATE,
  1999. 0x04, 0x00);
  2000. /* Add sleep as per HW register sequence */
  2001. usleep_range(30, 50);
  2002. snd_soc_update_bits(codec,
  2003. WCD9360_CDC_CLK_RST_CTRL_MCLK_CONTROL,
  2004. 0x02, 0x02);
  2005. snd_soc_update_bits(codec,
  2006. WCD9360_CDC_CLK_RST_CTRL_FS_CNT_CONTROL,
  2007. 0x10, 0x10);
  2008. }
  2009. break;
  2010. case SND_SOC_DAPM_PRE_PMD:
  2011. if (pahu->native_clk_users &&
  2012. (--pahu->native_clk_users == 0)) {
  2013. snd_soc_update_bits(codec,
  2014. WCD9360_CDC_CLK_RST_CTRL_FS_CNT_CONTROL,
  2015. 0x10, 0x00);
  2016. snd_soc_update_bits(codec,
  2017. WCD9360_CDC_CLK_RST_CTRL_MCLK_CONTROL,
  2018. 0x02, 0x00);
  2019. snd_soc_update_bits(codec, WCD9360_CODEC_RPM_CLK_GATE,
  2020. 0x04, 0x04);
  2021. snd_soc_update_bits(codec, WCD9360_CLK_SYS_MCLK2_PRG1,
  2022. 0x01, 0x00);
  2023. snd_soc_update_bits(codec, WCD9360_CLK_SYS_MCLK2_PRG1,
  2024. 0x06, 0x00);
  2025. snd_soc_update_bits(codec, WCD9360_CLK_SYS_PLL_ENABLES,
  2026. 0x01, 0x00);
  2027. }
  2028. break;
  2029. }
  2030. dev_dbg(codec->dev, "%s: native_clk_users: %d, event: %d\n",
  2031. __func__, pahu->native_clk_users, event);
  2032. return 0;
  2033. }
  2034. static int pahu_codec_config_ear_spkr_gain(struct snd_soc_codec *codec,
  2035. int event, int gain_reg)
  2036. {
  2037. int comp_gain_offset, val;
  2038. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(codec);
  2039. switch (pahu->swr.spkr_mode) {
  2040. /* Compander gain in SPKR_MODE1 case is 12 dB */
  2041. case WCD9360_SPKR_MODE_1:
  2042. comp_gain_offset = -12;
  2043. break;
  2044. /* Default case compander gain is 15 dB */
  2045. default:
  2046. comp_gain_offset = -15;
  2047. break;
  2048. }
  2049. switch (event) {
  2050. case SND_SOC_DAPM_POST_PMU:
  2051. /* Apply ear spkr gain only if compander is enabled */
  2052. if (pahu->comp_enabled[COMPANDER_7] &&
  2053. (gain_reg == WCD9360_CDC_RX7_RX_VOL_CTL ||
  2054. gain_reg == WCD9360_CDC_RX7_RX_VOL_MIX_CTL) &&
  2055. (pahu->ear_spkr_gain != 0)) {
  2056. /* For example, val is -8(-12+5-1) for 4dB of gain */
  2057. val = comp_gain_offset + pahu->ear_spkr_gain - 1;
  2058. snd_soc_write(codec, gain_reg, val);
  2059. dev_dbg(codec->dev, "%s: RX7 Volume %d dB\n",
  2060. __func__, val);
  2061. }
  2062. break;
  2063. case SND_SOC_DAPM_POST_PMD:
  2064. /*
  2065. * Reset RX7 volume to 0 dB if compander is enabled and
  2066. * ear_spkr_gain is non-zero.
  2067. */
  2068. if (pahu->comp_enabled[COMPANDER_7] &&
  2069. (gain_reg == WCD9360_CDC_RX7_RX_VOL_CTL ||
  2070. gain_reg == WCD9360_CDC_RX7_RX_VOL_MIX_CTL) &&
  2071. (pahu->ear_spkr_gain != 0)) {
  2072. snd_soc_write(codec, gain_reg, 0x0);
  2073. dev_dbg(codec->dev, "%s: Reset RX7 Volume to 0 dB\n",
  2074. __func__);
  2075. }
  2076. break;
  2077. }
  2078. return 0;
  2079. }
  2080. static int pahu_config_compander(struct snd_soc_codec *codec, int interp_n,
  2081. int event)
  2082. {
  2083. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(codec);
  2084. int comp;
  2085. u16 comp_ctl0_reg, rx_path_cfg0_reg;
  2086. /* HPH, LO are not valid and AUX does not have compander */
  2087. if (((interp_n >= INTERP_HPHL_NA) && (interp_n <= INTERP_LO4_NA)) ||
  2088. (interp_n == INTERP_AUX))
  2089. return 0;
  2090. comp = interp_n;
  2091. dev_dbg(codec->dev, "%s: event %d compander %d, enabled %d\n",
  2092. __func__, event, comp, pahu->comp_enabled[comp]);
  2093. if (!pahu->comp_enabled[comp])
  2094. return 0;
  2095. comp_ctl0_reg = WCD9360_CDC_COMPANDER0_CTL0 + (comp * 8);
  2096. rx_path_cfg0_reg = WCD9360_CDC_RX0_RX_PATH_CFG0 + (comp * 20);
  2097. if (SND_SOC_DAPM_EVENT_ON(event)) {
  2098. /* Enable Compander Clock */
  2099. snd_soc_update_bits(codec, comp_ctl0_reg, 0x01, 0x01);
  2100. /* Soft reset */
  2101. snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x02);
  2102. snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x00);
  2103. /* Compander enable */
  2104. snd_soc_update_bits(codec, rx_path_cfg0_reg, 0x02, 0x02);
  2105. }
  2106. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  2107. snd_soc_update_bits(codec, rx_path_cfg0_reg, 0x02, 0x00);
  2108. snd_soc_update_bits(codec, comp_ctl0_reg, 0x04, 0x04);
  2109. snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x02);
  2110. snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x00);
  2111. snd_soc_update_bits(codec, comp_ctl0_reg, 0x01, 0x00);
  2112. snd_soc_update_bits(codec, comp_ctl0_reg, 0x04, 0x00);
  2113. }
  2114. return 0;
  2115. }
  2116. /**
  2117. * pahu_codec_enable_interp_clk - Enable main path Interpolator
  2118. * clock.
  2119. *
  2120. * @codec: Codec instance
  2121. * @event: Indicates speaker path gain offset value
  2122. * @intp_idx: Interpolator index
  2123. * Returns number of main clock users
  2124. */
  2125. int pahu_codec_enable_interp_clk(struct snd_soc_codec *codec,
  2126. int event, int interp_idx)
  2127. {
  2128. struct pahu_priv *pahu;
  2129. u16 main_reg;
  2130. if (!codec) {
  2131. pr_err("%s: codec is NULL\n", __func__);
  2132. return -EINVAL;
  2133. }
  2134. pahu = snd_soc_codec_get_drvdata(codec);
  2135. main_reg = WCD9360_CDC_RX0_RX_PATH_CTL +
  2136. (interp_idx * WCD9360_RX_PATH_CTL_OFFSET);
  2137. if (interp_idx == INTERP_AUX)
  2138. main_reg = WCD9360_CDC_RX9_RX_PATH_CTL;
  2139. if (SND_SOC_DAPM_EVENT_ON(event)) {
  2140. if (pahu->main_clk_users[interp_idx] == 0) {
  2141. /* Main path PGA mute enable */
  2142. snd_soc_update_bits(codec, main_reg, 0x10, 0x10);
  2143. /* Clk enable */
  2144. snd_soc_update_bits(codec, main_reg, 0x20, 0x20);
  2145. pahu_config_compander(codec, interp_idx, event);
  2146. }
  2147. pahu->main_clk_users[interp_idx]++;
  2148. }
  2149. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  2150. pahu->main_clk_users[interp_idx]--;
  2151. if (pahu->main_clk_users[interp_idx] <= 0) {
  2152. pahu->main_clk_users[interp_idx] = 0;
  2153. pahu_config_compander(codec, interp_idx, event);
  2154. /* Clk Disable */
  2155. snd_soc_update_bits(codec, main_reg, 0x20, 0x00);
  2156. /* Reset enable and disable */
  2157. snd_soc_update_bits(codec, main_reg, 0x40, 0x40);
  2158. snd_soc_update_bits(codec, main_reg, 0x40, 0x00);
  2159. /* Reset rate to 48K*/
  2160. snd_soc_update_bits(codec, main_reg, 0x0F, 0x04);
  2161. }
  2162. }
  2163. dev_dbg(codec->dev, "%s event %d main_clk_users %d\n",
  2164. __func__, event, pahu->main_clk_users[interp_idx]);
  2165. return pahu->main_clk_users[interp_idx];
  2166. }
  2167. EXPORT_SYMBOL(pahu_codec_enable_interp_clk);
  2168. static int pahu_codec_enable_mix_path(struct snd_soc_dapm_widget *w,
  2169. struct snd_kcontrol *kcontrol,
  2170. int event)
  2171. {
  2172. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2173. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(codec);
  2174. u16 gain_reg, mix_reg;
  2175. int offset_val = 0;
  2176. int val = 0;
  2177. if (w->shift >= WCD9360_NUM_INTERPOLATORS ||
  2178. ((w->shift >= INTERP_HPHL_NA) && (w->shift <= INTERP_LO4_NA))) {
  2179. dev_err(codec->dev, "%s: Invalid Interpolator value %d for name %s\n",
  2180. __func__, w->shift, w->name);
  2181. return -EINVAL;
  2182. };
  2183. gain_reg = WCD9360_CDC_RX0_RX_VOL_MIX_CTL +
  2184. (w->shift * WCD9360_RX_PATH_CTL_OFFSET);
  2185. mix_reg = WCD9360_CDC_RX0_RX_PATH_MIX_CTL +
  2186. (w->shift * WCD9360_RX_PATH_CTL_OFFSET);
  2187. if (w->shift == INTERP_AUX) {
  2188. gain_reg = WCD9360_CDC_RX9_RX_VOL_MIX_CTL;
  2189. mix_reg = WCD9360_CDC_RX9_RX_PATH_MIX_CTL;
  2190. }
  2191. if (w->shift == INTERP_SPKR1 || w->shift == INTERP_SPKR2)
  2192. __pahu_codec_enable_swr(w, event);
  2193. switch (event) {
  2194. case SND_SOC_DAPM_PRE_PMU:
  2195. pahu_codec_enable_interp_clk(codec, event, w->shift);
  2196. /* Clk enable */
  2197. snd_soc_update_bits(codec, mix_reg, 0x20, 0x20);
  2198. break;
  2199. case SND_SOC_DAPM_POST_PMU:
  2200. if ((pahu->swr.spkr_gain_offset ==
  2201. WCD9360_RX_GAIN_OFFSET_M1P5_DB) &&
  2202. (pahu->comp_enabled[COMPANDER_7] ||
  2203. pahu->comp_enabled[COMPANDER_8]) &&
  2204. (gain_reg == WCD9360_CDC_RX7_RX_VOL_MIX_CTL ||
  2205. gain_reg == WCD9360_CDC_RX8_RX_VOL_MIX_CTL)) {
  2206. snd_soc_update_bits(codec, WCD9360_CDC_RX7_RX_PATH_SEC1,
  2207. 0x01, 0x01);
  2208. snd_soc_update_bits(codec,
  2209. WCD9360_CDC_RX7_RX_PATH_MIX_SEC0,
  2210. 0x01, 0x01);
  2211. snd_soc_update_bits(codec, WCD9360_CDC_RX8_RX_PATH_SEC1,
  2212. 0x01, 0x01);
  2213. snd_soc_update_bits(codec,
  2214. WCD9360_CDC_RX8_RX_PATH_MIX_SEC0,
  2215. 0x01, 0x01);
  2216. offset_val = -2;
  2217. }
  2218. val = snd_soc_read(codec, gain_reg);
  2219. val += offset_val;
  2220. snd_soc_write(codec, gain_reg, val);
  2221. pahu_codec_config_ear_spkr_gain(codec, event, gain_reg);
  2222. break;
  2223. case SND_SOC_DAPM_POST_PMD:
  2224. /* Clk Disable */
  2225. snd_soc_update_bits(codec, mix_reg, 0x20, 0x00);
  2226. pahu_codec_enable_interp_clk(codec, event, w->shift);
  2227. /* Reset enable and disable */
  2228. snd_soc_update_bits(codec, mix_reg, 0x40, 0x40);
  2229. snd_soc_update_bits(codec, mix_reg, 0x40, 0x00);
  2230. if ((pahu->swr.spkr_gain_offset ==
  2231. WCD9360_RX_GAIN_OFFSET_M1P5_DB) &&
  2232. (pahu->comp_enabled[COMPANDER_7] ||
  2233. pahu->comp_enabled[COMPANDER_8]) &&
  2234. (gain_reg == WCD9360_CDC_RX7_RX_VOL_MIX_CTL ||
  2235. gain_reg == WCD9360_CDC_RX8_RX_VOL_MIX_CTL)) {
  2236. snd_soc_update_bits(codec, WCD9360_CDC_RX7_RX_PATH_SEC1,
  2237. 0x01, 0x00);
  2238. snd_soc_update_bits(codec,
  2239. WCD9360_CDC_RX7_RX_PATH_MIX_SEC0,
  2240. 0x01, 0x00);
  2241. snd_soc_update_bits(codec, WCD9360_CDC_RX8_RX_PATH_SEC1,
  2242. 0x01, 0x00);
  2243. snd_soc_update_bits(codec,
  2244. WCD9360_CDC_RX8_RX_PATH_MIX_SEC0,
  2245. 0x01, 0x00);
  2246. offset_val = 2;
  2247. val = snd_soc_read(codec, gain_reg);
  2248. val += offset_val;
  2249. snd_soc_write(codec, gain_reg, val);
  2250. }
  2251. pahu_codec_config_ear_spkr_gain(codec, event, gain_reg);
  2252. break;
  2253. };
  2254. dev_dbg(codec->dev, "%s event %d name %s\n", __func__, event, w->name);
  2255. return 0;
  2256. }
  2257. static int pahu_codec_enable_main_path(struct snd_soc_dapm_widget *w,
  2258. struct snd_kcontrol *kcontrol,
  2259. int event)
  2260. {
  2261. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2262. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(codec);
  2263. u16 gain_reg;
  2264. u16 reg;
  2265. int val;
  2266. int offset_val = 0;
  2267. dev_dbg(codec->dev, "%s %d %s\n", __func__, event, w->name);
  2268. if (w->shift >= WCD9360_NUM_INTERPOLATORS ||
  2269. ((w->shift >= INTERP_HPHL_NA) && (w->shift <= INTERP_LO4_NA))) {
  2270. dev_err(codec->dev, "%s: Invalid Interpolator value %d for name %s\n",
  2271. __func__, w->shift, w->name);
  2272. return -EINVAL;
  2273. };
  2274. reg = WCD9360_CDC_RX0_RX_PATH_CTL + (w->shift *
  2275. WCD9360_RX_PATH_CTL_OFFSET);
  2276. gain_reg = WCD9360_CDC_RX0_RX_VOL_CTL + (w->shift *
  2277. WCD9360_RX_PATH_CTL_OFFSET);
  2278. if (w->shift == INTERP_AUX) {
  2279. reg = WCD9360_CDC_RX9_RX_PATH_CTL;
  2280. gain_reg = WCD9360_CDC_RX9_RX_VOL_CTL;
  2281. }
  2282. switch (event) {
  2283. case SND_SOC_DAPM_PRE_PMU:
  2284. pahu_codec_enable_interp_clk(codec, event, w->shift);
  2285. break;
  2286. case SND_SOC_DAPM_POST_PMU:
  2287. /* apply gain after int clk is enabled */
  2288. if ((pahu->swr.spkr_gain_offset ==
  2289. WCD9360_RX_GAIN_OFFSET_M1P5_DB) &&
  2290. (pahu->comp_enabled[COMPANDER_7] ||
  2291. pahu->comp_enabled[COMPANDER_8]) &&
  2292. (gain_reg == WCD9360_CDC_RX7_RX_VOL_CTL ||
  2293. gain_reg == WCD9360_CDC_RX8_RX_VOL_CTL)) {
  2294. snd_soc_update_bits(codec, WCD9360_CDC_RX7_RX_PATH_SEC1,
  2295. 0x01, 0x01);
  2296. snd_soc_update_bits(codec,
  2297. WCD9360_CDC_RX7_RX_PATH_MIX_SEC0,
  2298. 0x01, 0x01);
  2299. snd_soc_update_bits(codec, WCD9360_CDC_RX8_RX_PATH_SEC1,
  2300. 0x01, 0x01);
  2301. snd_soc_update_bits(codec,
  2302. WCD9360_CDC_RX8_RX_PATH_MIX_SEC0,
  2303. 0x01, 0x01);
  2304. offset_val = -2;
  2305. }
  2306. val = snd_soc_read(codec, gain_reg);
  2307. val += offset_val;
  2308. snd_soc_write(codec, gain_reg, val);
  2309. pahu_codec_config_ear_spkr_gain(codec, event, gain_reg);
  2310. break;
  2311. case SND_SOC_DAPM_POST_PMD:
  2312. pahu_codec_enable_interp_clk(codec, event, w->shift);
  2313. if ((pahu->swr.spkr_gain_offset ==
  2314. WCD9360_RX_GAIN_OFFSET_M1P5_DB) &&
  2315. (pahu->comp_enabled[COMPANDER_7] ||
  2316. pahu->comp_enabled[COMPANDER_8]) &&
  2317. (gain_reg == WCD9360_CDC_RX7_RX_VOL_CTL ||
  2318. gain_reg == WCD9360_CDC_RX8_RX_VOL_CTL)) {
  2319. snd_soc_update_bits(codec, WCD9360_CDC_RX7_RX_PATH_SEC1,
  2320. 0x01, 0x00);
  2321. snd_soc_update_bits(codec,
  2322. WCD9360_CDC_RX7_RX_PATH_MIX_SEC0,
  2323. 0x01, 0x00);
  2324. snd_soc_update_bits(codec, WCD9360_CDC_RX8_RX_PATH_SEC1,
  2325. 0x01, 0x00);
  2326. snd_soc_update_bits(codec,
  2327. WCD9360_CDC_RX8_RX_PATH_MIX_SEC0,
  2328. 0x01, 0x00);
  2329. offset_val = 2;
  2330. val = snd_soc_read(codec, gain_reg);
  2331. val += offset_val;
  2332. snd_soc_write(codec, gain_reg, val);
  2333. }
  2334. pahu_codec_config_ear_spkr_gain(codec, event, gain_reg);
  2335. break;
  2336. };
  2337. return 0;
  2338. }
  2339. static int pahu_codec_set_iir_gain(struct snd_soc_dapm_widget *w,
  2340. struct snd_kcontrol *kcontrol, int event)
  2341. {
  2342. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2343. dev_dbg(codec->dev, "%s: event = %d\n", __func__, event);
  2344. switch (event) {
  2345. case SND_SOC_DAPM_POST_PMU: /* fall through */
  2346. case SND_SOC_DAPM_PRE_PMD:
  2347. if (strnstr(w->name, "IIR0", sizeof("IIR0"))) {
  2348. snd_soc_write(codec,
  2349. WCD9360_CDC_SIDETONE_IIR0_IIR_GAIN_B1_CTL,
  2350. snd_soc_read(codec,
  2351. WCD9360_CDC_SIDETONE_IIR0_IIR_GAIN_B1_CTL));
  2352. snd_soc_write(codec,
  2353. WCD9360_CDC_SIDETONE_IIR0_IIR_GAIN_B2_CTL,
  2354. snd_soc_read(codec,
  2355. WCD9360_CDC_SIDETONE_IIR0_IIR_GAIN_B2_CTL));
  2356. snd_soc_write(codec,
  2357. WCD9360_CDC_SIDETONE_IIR0_IIR_GAIN_B3_CTL,
  2358. snd_soc_read(codec,
  2359. WCD9360_CDC_SIDETONE_IIR0_IIR_GAIN_B3_CTL));
  2360. snd_soc_write(codec,
  2361. WCD9360_CDC_SIDETONE_IIR0_IIR_GAIN_B4_CTL,
  2362. snd_soc_read(codec,
  2363. WCD9360_CDC_SIDETONE_IIR0_IIR_GAIN_B4_CTL));
  2364. }
  2365. break;
  2366. }
  2367. return 0;
  2368. }
  2369. static int pahu_codec_find_amic_input(struct snd_soc_codec *codec,
  2370. int adc_mux_n)
  2371. {
  2372. u16 mask, shift, adc_mux_in_reg;
  2373. u16 amic_mux_sel_reg;
  2374. bool is_amic;
  2375. if (adc_mux_n < 0 || adc_mux_n > WCD9360_MAX_VALID_ADC_MUX ||
  2376. adc_mux_n == WCD9360_INVALID_ADC_MUX)
  2377. return 0;
  2378. if (adc_mux_n < 3) {
  2379. adc_mux_in_reg = WCD9360_CDC_TX_INP_MUX_ADC_MUX0_CFG1 +
  2380. 2 * adc_mux_n;
  2381. mask = 0x03;
  2382. shift = 0;
  2383. amic_mux_sel_reg = WCD9360_CDC_TX_INP_MUX_ADC_MUX0_CFG0 +
  2384. 2 * adc_mux_n;
  2385. } else if (adc_mux_n < 4) {
  2386. adc_mux_in_reg = WCD9360_CDC_TX_INP_MUX_ADC_MUX3_CFG1;
  2387. mask = 0x03;
  2388. shift = 0;
  2389. amic_mux_sel_reg = WCD9360_CDC_TX_INP_MUX_ADC_MUX0_CFG0 +
  2390. 2 * adc_mux_n;
  2391. } else if (adc_mux_n < 7) {
  2392. adc_mux_in_reg = WCD9360_CDC_TX_INP_MUX_ADC_MUX0_CFG1 +
  2393. 2 * (adc_mux_n - 4);
  2394. mask = 0x0C;
  2395. shift = 2;
  2396. amic_mux_sel_reg = WCD9360_CDC_TX_INP_MUX_ADC_MUX4_CFG0 +
  2397. adc_mux_n - 4;
  2398. } else if (adc_mux_n < 8) {
  2399. adc_mux_in_reg = WCD9360_CDC_TX_INP_MUX_ADC_MUX3_CFG1;
  2400. mask = 0x0C;
  2401. shift = 2;
  2402. amic_mux_sel_reg = WCD9360_CDC_TX_INP_MUX_ADC_MUX4_CFG0 +
  2403. adc_mux_n - 4;
  2404. } else if (adc_mux_n < 12) {
  2405. adc_mux_in_reg = WCD9360_CDC_TX_INP_MUX_ADC_MUX0_CFG1 +
  2406. 2 * (((adc_mux_n == 8) ? (adc_mux_n - 8) :
  2407. (adc_mux_n - 9)));
  2408. mask = 0x30;
  2409. shift = 4;
  2410. amic_mux_sel_reg = WCD9360_CDC_TX_INP_MUX_ADC_MUX8_CFG0 +
  2411. ((adc_mux_n == 8) ? (adc_mux_n - 8) :
  2412. (adc_mux_n - 9));
  2413. }
  2414. is_amic = (((snd_soc_read(codec, adc_mux_in_reg) & mask) >> shift)
  2415. == 1);
  2416. if (!is_amic)
  2417. return 0;
  2418. return snd_soc_read(codec, amic_mux_sel_reg) & 0x07;
  2419. }
  2420. static void pahu_codec_set_tx_hold(struct snd_soc_codec *codec,
  2421. u16 amic_reg, bool set)
  2422. {
  2423. u8 mask = 0x20;
  2424. u8 val;
  2425. if (amic_reg == WCD9360_ANA_AMIC1 ||
  2426. amic_reg == WCD9360_ANA_AMIC3)
  2427. mask = 0x40;
  2428. val = set ? mask : 0x00;
  2429. switch (amic_reg) {
  2430. case WCD9360_ANA_AMIC1:
  2431. case WCD9360_ANA_AMIC2:
  2432. snd_soc_update_bits(codec, WCD9360_ANA_AMIC2, mask, val);
  2433. break;
  2434. case WCD9360_ANA_AMIC3:
  2435. case WCD9360_ANA_AMIC4:
  2436. snd_soc_update_bits(codec, WCD9360_ANA_AMIC4, mask, val);
  2437. break;
  2438. default:
  2439. dev_dbg(codec->dev, "%s: invalid amic: %d\n",
  2440. __func__, amic_reg);
  2441. break;
  2442. }
  2443. }
  2444. static int pahu_codec_tx_adc_cfg(struct snd_soc_dapm_widget *w,
  2445. struct snd_kcontrol *kcontrol, int event)
  2446. {
  2447. int adc_mux_n = w->shift;
  2448. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2449. int amic_n;
  2450. dev_dbg(codec->dev, "%s: event: %d\n", __func__, event);
  2451. switch (event) {
  2452. case SND_SOC_DAPM_POST_PMU:
  2453. amic_n = pahu_codec_find_amic_input(codec, adc_mux_n);
  2454. break;
  2455. default:
  2456. break;
  2457. }
  2458. return 0;
  2459. }
  2460. static u16 pahu_codec_get_amic_pwlvl_reg(struct snd_soc_codec *codec, int amic)
  2461. {
  2462. u16 pwr_level_reg = 0;
  2463. switch (amic) {
  2464. case 1:
  2465. case 2:
  2466. pwr_level_reg = WCD9360_ANA_AMIC1;
  2467. break;
  2468. case 3:
  2469. case 4:
  2470. pwr_level_reg = WCD9360_ANA_AMIC3;
  2471. break;
  2472. default:
  2473. dev_dbg(codec->dev, "%s: invalid amic: %d\n",
  2474. __func__, amic);
  2475. break;
  2476. }
  2477. return pwr_level_reg;
  2478. }
  2479. #define TX_HPF_CUT_OFF_FREQ_MASK 0x60
  2480. #define CF_MIN_3DB_4HZ 0x0
  2481. #define CF_MIN_3DB_75HZ 0x1
  2482. #define CF_MIN_3DB_150HZ 0x2
  2483. static void pahu_tx_hpf_corner_freq_callback(struct work_struct *work)
  2484. {
  2485. struct delayed_work *hpf_delayed_work;
  2486. struct hpf_work *hpf_work;
  2487. struct pahu_priv *pahu;
  2488. struct snd_soc_codec *codec;
  2489. u16 dec_cfg_reg, amic_reg, go_bit_reg;
  2490. u8 hpf_cut_off_freq;
  2491. int amic_n;
  2492. hpf_delayed_work = to_delayed_work(work);
  2493. hpf_work = container_of(hpf_delayed_work, struct hpf_work, dwork);
  2494. pahu = hpf_work->pahu;
  2495. codec = pahu->codec;
  2496. hpf_cut_off_freq = hpf_work->hpf_cut_off_freq;
  2497. dec_cfg_reg = WCD9360_CDC_TX0_TX_PATH_CFG0 + 16 * hpf_work->decimator;
  2498. go_bit_reg = dec_cfg_reg + 7;
  2499. dev_dbg(codec->dev, "%s: decimator %u hpf_cut_of_freq 0x%x\n",
  2500. __func__, hpf_work->decimator, hpf_cut_off_freq);
  2501. amic_n = pahu_codec_find_amic_input(codec, hpf_work->decimator);
  2502. if (amic_n) {
  2503. amic_reg = WCD9360_ANA_AMIC1 + amic_n - 1;
  2504. pahu_codec_set_tx_hold(codec, amic_reg, false);
  2505. }
  2506. snd_soc_update_bits(codec, dec_cfg_reg, TX_HPF_CUT_OFF_FREQ_MASK,
  2507. hpf_cut_off_freq << 5);
  2508. snd_soc_update_bits(codec, go_bit_reg, 0x02, 0x02);
  2509. /* Minimum 1 clk cycle delay is required as per HW spec */
  2510. usleep_range(1000, 1010);
  2511. snd_soc_update_bits(codec, go_bit_reg, 0x02, 0x00);
  2512. }
  2513. static void pahu_tx_mute_update_callback(struct work_struct *work)
  2514. {
  2515. struct tx_mute_work *tx_mute_dwork;
  2516. struct pahu_priv *pahu;
  2517. struct delayed_work *delayed_work;
  2518. struct snd_soc_codec *codec;
  2519. u16 tx_vol_ctl_reg;
  2520. delayed_work = to_delayed_work(work);
  2521. tx_mute_dwork = container_of(delayed_work, struct tx_mute_work, dwork);
  2522. pahu = tx_mute_dwork->pahu;
  2523. codec = pahu->codec;
  2524. tx_vol_ctl_reg = WCD9360_CDC_TX0_TX_PATH_CTL +
  2525. 16 * tx_mute_dwork->decimator;
  2526. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x10, 0x00);
  2527. }
  2528. static int pahu_codec_enable_rx_path_clk(struct snd_soc_dapm_widget *w,
  2529. struct snd_kcontrol *kcontrol, int event)
  2530. {
  2531. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2532. u16 sidetone_reg;
  2533. dev_dbg(codec->dev, "%s %d %d\n", __func__, event, w->shift);
  2534. sidetone_reg = WCD9360_CDC_RX0_RX_PATH_CFG1 + 0x14*(w->shift);
  2535. if (w->shift == INTERP_AUX)
  2536. sidetone_reg = WCD9360_CDC_RX9_RX_PATH_CFG1;
  2537. switch (event) {
  2538. case SND_SOC_DAPM_PRE_PMU:
  2539. if (!strcmp(w->name, "RX INT7 MIX2 INP"))
  2540. __pahu_codec_enable_swr(w, event);
  2541. pahu_codec_enable_interp_clk(codec, event, w->shift);
  2542. snd_soc_update_bits(codec, sidetone_reg, 0x10, 0x10);
  2543. break;
  2544. case SND_SOC_DAPM_POST_PMD:
  2545. snd_soc_update_bits(codec, sidetone_reg, 0x10, 0x00);
  2546. pahu_codec_enable_interp_clk(codec, event, w->shift);
  2547. if (!strcmp(w->name, "RX INT7 MIX2 INP"))
  2548. __pahu_codec_enable_swr(w, event);
  2549. break;
  2550. default:
  2551. break;
  2552. };
  2553. return 0;
  2554. }
  2555. static int pahu_codec_enable_dec(struct snd_soc_dapm_widget *w,
  2556. struct snd_kcontrol *kcontrol, int event)
  2557. {
  2558. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2559. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(codec);
  2560. unsigned int decimator;
  2561. char *dec_adc_mux_name = NULL;
  2562. char *widget_name = NULL;
  2563. char *wname;
  2564. int ret = 0, amic_n;
  2565. u16 tx_vol_ctl_reg, pwr_level_reg = 0, dec_cfg_reg, hpf_gate_reg;
  2566. u16 tx_gain_ctl_reg;
  2567. char *dec;
  2568. u8 hpf_cut_off_freq;
  2569. dev_dbg(codec->dev, "%s %d\n", __func__, event);
  2570. widget_name = kstrndup(w->name, 15, GFP_KERNEL);
  2571. if (!widget_name)
  2572. return -ENOMEM;
  2573. wname = widget_name;
  2574. dec_adc_mux_name = strsep(&widget_name, " ");
  2575. if (!dec_adc_mux_name) {
  2576. dev_err(codec->dev, "%s: Invalid decimator = %s\n",
  2577. __func__, w->name);
  2578. ret = -EINVAL;
  2579. goto out;
  2580. }
  2581. dec_adc_mux_name = widget_name;
  2582. dec = strpbrk(dec_adc_mux_name, "012345678");
  2583. if (!dec) {
  2584. dev_err(codec->dev, "%s: decimator index not found\n",
  2585. __func__);
  2586. ret = -EINVAL;
  2587. goto out;
  2588. }
  2589. ret = kstrtouint(dec, 10, &decimator);
  2590. if (ret < 0) {
  2591. dev_err(codec->dev, "%s: Invalid decimator = %s\n",
  2592. __func__, wname);
  2593. ret = -EINVAL;
  2594. goto out;
  2595. }
  2596. dev_dbg(codec->dev, "%s(): widget = %s decimator = %u\n", __func__,
  2597. w->name, decimator);
  2598. tx_vol_ctl_reg = WCD9360_CDC_TX0_TX_PATH_CTL + 16 * decimator;
  2599. hpf_gate_reg = WCD9360_CDC_TX0_TX_PATH_SEC2 + 16 * decimator;
  2600. dec_cfg_reg = WCD9360_CDC_TX0_TX_PATH_CFG0 + 16 * decimator;
  2601. tx_gain_ctl_reg = WCD9360_CDC_TX0_TX_VOL_CTL + 16 * decimator;
  2602. switch (event) {
  2603. case SND_SOC_DAPM_PRE_PMU:
  2604. amic_n = pahu_codec_find_amic_input(codec, decimator);
  2605. if (amic_n)
  2606. pwr_level_reg = pahu_codec_get_amic_pwlvl_reg(codec,
  2607. amic_n);
  2608. if (pwr_level_reg) {
  2609. switch ((snd_soc_read(codec, pwr_level_reg) &
  2610. WCD9360_AMIC_PWR_LVL_MASK) >>
  2611. WCD9360_AMIC_PWR_LVL_SHIFT) {
  2612. case WCD9360_AMIC_PWR_LEVEL_LP:
  2613. snd_soc_update_bits(codec, dec_cfg_reg,
  2614. WCD9360_DEC_PWR_LVL_MASK,
  2615. WCD9360_DEC_PWR_LVL_LP);
  2616. break;
  2617. case WCD9360_AMIC_PWR_LEVEL_HP:
  2618. snd_soc_update_bits(codec, dec_cfg_reg,
  2619. WCD9360_DEC_PWR_LVL_MASK,
  2620. WCD9360_DEC_PWR_LVL_HP);
  2621. break;
  2622. case WCD9360_AMIC_PWR_LEVEL_DEFAULT:
  2623. default:
  2624. snd_soc_update_bits(codec, dec_cfg_reg,
  2625. WCD9360_DEC_PWR_LVL_MASK,
  2626. WCD9360_DEC_PWR_LVL_DF);
  2627. break;
  2628. }
  2629. }
  2630. /* Enable TX PGA Mute */
  2631. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x10, 0x10);
  2632. break;
  2633. case SND_SOC_DAPM_POST_PMU:
  2634. hpf_cut_off_freq = (snd_soc_read(codec, dec_cfg_reg) &
  2635. TX_HPF_CUT_OFF_FREQ_MASK) >> 5;
  2636. pahu->tx_hpf_work[decimator].hpf_cut_off_freq =
  2637. hpf_cut_off_freq;
  2638. if (hpf_cut_off_freq != CF_MIN_3DB_150HZ) {
  2639. snd_soc_update_bits(codec, dec_cfg_reg,
  2640. TX_HPF_CUT_OFF_FREQ_MASK,
  2641. CF_MIN_3DB_150HZ << 5);
  2642. snd_soc_update_bits(codec, hpf_gate_reg, 0x02, 0x02);
  2643. /*
  2644. * Minimum 1 clk cycle delay is required as per
  2645. * HW spec.
  2646. */
  2647. usleep_range(1000, 1010);
  2648. snd_soc_update_bits(codec, hpf_gate_reg, 0x02, 0x00);
  2649. }
  2650. /* schedule work queue to Remove Mute */
  2651. schedule_delayed_work(&pahu->tx_mute_dwork[decimator].dwork,
  2652. msecs_to_jiffies(tx_unmute_delay));
  2653. if (pahu->tx_hpf_work[decimator].hpf_cut_off_freq !=
  2654. CF_MIN_3DB_150HZ)
  2655. schedule_delayed_work(
  2656. &pahu->tx_hpf_work[decimator].dwork,
  2657. msecs_to_jiffies(300));
  2658. /* apply gain after decimator is enabled */
  2659. snd_soc_write(codec, tx_gain_ctl_reg,
  2660. snd_soc_read(codec, tx_gain_ctl_reg));
  2661. break;
  2662. case SND_SOC_DAPM_PRE_PMD:
  2663. hpf_cut_off_freq =
  2664. pahu->tx_hpf_work[decimator].hpf_cut_off_freq;
  2665. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x10, 0x10);
  2666. if (cancel_delayed_work_sync(
  2667. &pahu->tx_hpf_work[decimator].dwork)) {
  2668. if (hpf_cut_off_freq != CF_MIN_3DB_150HZ) {
  2669. snd_soc_update_bits(codec, dec_cfg_reg,
  2670. TX_HPF_CUT_OFF_FREQ_MASK,
  2671. hpf_cut_off_freq << 5);
  2672. snd_soc_update_bits(codec, hpf_gate_reg,
  2673. 0x02, 0x02);
  2674. /*
  2675. * Minimum 1 clk cycle delay is required as per
  2676. * HW spec.
  2677. */
  2678. usleep_range(1000, 1010);
  2679. snd_soc_update_bits(codec, hpf_gate_reg,
  2680. 0x02, 0x00);
  2681. }
  2682. }
  2683. cancel_delayed_work_sync(
  2684. &pahu->tx_mute_dwork[decimator].dwork);
  2685. break;
  2686. case SND_SOC_DAPM_POST_PMD:
  2687. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x10, 0x00);
  2688. snd_soc_update_bits(codec, dec_cfg_reg,
  2689. WCD9360_DEC_PWR_LVL_MASK,
  2690. WCD9360_DEC_PWR_LVL_DF);
  2691. break;
  2692. };
  2693. out:
  2694. kfree(wname);
  2695. return ret;
  2696. }
  2697. static u32 pahu_get_dmic_sample_rate(struct snd_soc_codec *codec,
  2698. unsigned int dmic,
  2699. struct wcd9xxx_pdata *pdata)
  2700. {
  2701. u8 tx_stream_fs;
  2702. u8 adc_mux_index = 0, adc_mux_sel = 0;
  2703. bool dec_found = false;
  2704. u16 adc_mux_ctl_reg, tx_fs_reg;
  2705. u32 dmic_fs;
  2706. while (dec_found == 0 && adc_mux_index < WCD9360_MAX_VALID_ADC_MUX) {
  2707. if (adc_mux_index < 4) {
  2708. adc_mux_ctl_reg = WCD9360_CDC_TX_INP_MUX_ADC_MUX0_CFG0 +
  2709. (adc_mux_index * 2);
  2710. } else if (adc_mux_index < WCD9360_INVALID_ADC_MUX) {
  2711. adc_mux_ctl_reg = WCD9360_CDC_TX_INP_MUX_ADC_MUX4_CFG0 +
  2712. adc_mux_index - 4;
  2713. } else if (adc_mux_index == WCD9360_INVALID_ADC_MUX) {
  2714. ++adc_mux_index;
  2715. continue;
  2716. }
  2717. adc_mux_sel = ((snd_soc_read(codec, adc_mux_ctl_reg) &
  2718. 0xF8) >> 3) - 1;
  2719. if (adc_mux_sel == dmic) {
  2720. dec_found = true;
  2721. break;
  2722. }
  2723. ++adc_mux_index;
  2724. }
  2725. if (dec_found && adc_mux_index <= 8) {
  2726. tx_fs_reg = WCD9360_CDC_TX0_TX_PATH_CTL + (16 * adc_mux_index);
  2727. tx_stream_fs = snd_soc_read(codec, tx_fs_reg) & 0x0F;
  2728. if (tx_stream_fs <= 4) {
  2729. if (pdata->dmic_sample_rate <=
  2730. WCD9XXX_DMIC_SAMPLE_RATE_2P4MHZ)
  2731. dmic_fs = pdata->dmic_sample_rate;
  2732. else
  2733. dmic_fs = WCD9XXX_DMIC_SAMPLE_RATE_2P4MHZ;
  2734. } else
  2735. dmic_fs = WCD9XXX_DMIC_SAMPLE_RATE_4P8MHZ;
  2736. } else {
  2737. dmic_fs = pdata->dmic_sample_rate;
  2738. }
  2739. return dmic_fs;
  2740. }
  2741. static u8 pahu_get_dmic_clk_val(struct snd_soc_codec *codec,
  2742. u32 dmic_clk_rate)
  2743. {
  2744. u32 div_factor;
  2745. u8 dmic_ctl_val = WCD9360_DMIC_CLK_DIV_2;
  2746. dev_dbg(codec->dev, "%s: dmic_sample_rate = %d\n",
  2747. __func__, dmic_clk_rate);
  2748. if (dmic_clk_rate == 0) {
  2749. dev_err(codec->dev, "%s: dmic_sample_rate cannot be 0\n",
  2750. __func__);
  2751. goto done;
  2752. }
  2753. div_factor = WCD9360_MCLK_CLK_9P6MHZ / dmic_clk_rate;
  2754. switch (div_factor) {
  2755. case 2:
  2756. dmic_ctl_val = WCD9360_DMIC_CLK_DIV_2;
  2757. break;
  2758. case 3:
  2759. dmic_ctl_val = WCD9360_DMIC_CLK_DIV_3;
  2760. break;
  2761. case 4:
  2762. dmic_ctl_val = WCD9360_DMIC_CLK_DIV_4;
  2763. break;
  2764. case 6:
  2765. dmic_ctl_val = WCD9360_DMIC_CLK_DIV_6;
  2766. break;
  2767. case 8:
  2768. dmic_ctl_val = WCD9360_DMIC_CLK_DIV_8;
  2769. break;
  2770. case 16:
  2771. dmic_ctl_val = WCD9360_DMIC_CLK_DIV_16;
  2772. break;
  2773. default:
  2774. dev_err(codec->dev,
  2775. "%s: Invalid div_factor %u, dmic_rate(%u)\n",
  2776. __func__, div_factor, dmic_clk_rate);
  2777. break;
  2778. }
  2779. done:
  2780. return dmic_ctl_val;
  2781. }
  2782. static int pahu_codec_enable_adc(struct snd_soc_dapm_widget *w,
  2783. struct snd_kcontrol *kcontrol, int event)
  2784. {
  2785. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2786. dev_dbg(codec->dev, "%s: event:%d\n", __func__, event);
  2787. switch (event) {
  2788. case SND_SOC_DAPM_PRE_PMU:
  2789. pahu_codec_set_tx_hold(codec, w->reg, true);
  2790. break;
  2791. default:
  2792. break;
  2793. }
  2794. return 0;
  2795. }
  2796. static int pahu_codec_enable_dmic(struct snd_soc_dapm_widget *w,
  2797. struct snd_kcontrol *kcontrol, int event)
  2798. {
  2799. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2800. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(codec);
  2801. struct wcd9xxx_pdata *pdata = dev_get_platdata(codec->dev->parent);
  2802. u8 dmic_clk_en = 0x01;
  2803. u16 dmic_clk_reg;
  2804. s32 *dmic_clk_cnt;
  2805. u8 dmic_rate_val, dmic_rate_shift = 1;
  2806. unsigned int dmic;
  2807. u32 dmic_sample_rate;
  2808. dmic = w->shift;
  2809. switch (dmic) {
  2810. case 0:
  2811. case 1:
  2812. dmic_clk_cnt = &(pahu->dmic_0_1_clk_cnt);
  2813. dmic_clk_reg = WCD9360_CPE_SS_DMIC0_CTL;
  2814. break;
  2815. case 2:
  2816. case 3:
  2817. dmic_clk_cnt = &(pahu->dmic_2_3_clk_cnt);
  2818. dmic_clk_reg = WCD9360_CPE_SS_DMIC1_CTL;
  2819. break;
  2820. case 4:
  2821. case 5:
  2822. dmic_clk_cnt = &(pahu->dmic_4_5_clk_cnt);
  2823. dmic_clk_reg = WCD9360_CPE_SS_DMIC2_CTL;
  2824. break;
  2825. case 6:
  2826. case 7:
  2827. dmic_clk_cnt = &(pahu->dmic_6_7_clk_cnt);
  2828. dmic_clk_reg = WCD9360_CPE_SS_DMIC3_CTL;
  2829. break;
  2830. default:
  2831. dev_err(codec->dev, "%s: Invalid DMIC Selection\n",
  2832. __func__);
  2833. return -EINVAL;
  2834. };
  2835. dev_dbg(codec->dev, "%s: event %d DMIC%d dmic_clk_cnt %d\n",
  2836. __func__, event, dmic, *dmic_clk_cnt);
  2837. switch (event) {
  2838. case SND_SOC_DAPM_PRE_PMU:
  2839. dmic_sample_rate = pahu_get_dmic_sample_rate(codec, dmic,
  2840. pdata);
  2841. dmic_rate_val =
  2842. pahu_get_dmic_clk_val(codec,
  2843. dmic_sample_rate);
  2844. (*dmic_clk_cnt)++;
  2845. if (*dmic_clk_cnt == 1) {
  2846. snd_soc_update_bits(codec, dmic_clk_reg,
  2847. 0x07 << dmic_rate_shift,
  2848. dmic_rate_val << dmic_rate_shift);
  2849. snd_soc_update_bits(codec, dmic_clk_reg,
  2850. dmic_clk_en, dmic_clk_en);
  2851. }
  2852. break;
  2853. case SND_SOC_DAPM_POST_PMD:
  2854. dmic_rate_val =
  2855. pahu_get_dmic_clk_val(codec,
  2856. pdata->mad_dmic_sample_rate);
  2857. (*dmic_clk_cnt)--;
  2858. if (*dmic_clk_cnt == 0) {
  2859. snd_soc_update_bits(codec, dmic_clk_reg,
  2860. dmic_clk_en, 0);
  2861. snd_soc_update_bits(codec, dmic_clk_reg,
  2862. 0x07 << dmic_rate_shift,
  2863. dmic_rate_val << dmic_rate_shift);
  2864. }
  2865. break;
  2866. };
  2867. return 0;
  2868. }
  2869. /*
  2870. * pahu_micbias_control: enable/disable micbias
  2871. * @codec: handle to snd_soc_codec *
  2872. * @micb_num: micbias to be enabled/disabled, e.g. micbias1 or micbias2
  2873. * @req: control requested, enable/disable or pullup enable/disable
  2874. * @is_dapm: triggered by dapm or not
  2875. *
  2876. * return 0 if control is success or error code in case of failure
  2877. */
  2878. int pahu_micbias_control(struct snd_soc_codec *codec,
  2879. int micb_num, int req, bool is_dapm)
  2880. {
  2881. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(codec);
  2882. int micb_index = micb_num - 1;
  2883. u16 micb_reg;
  2884. if ((micb_index < 0) || (micb_index > PAHU_MAX_MICBIAS - 1)) {
  2885. dev_err(codec->dev, "%s: Invalid micbias index, micb_ind:%d\n",
  2886. __func__, micb_index);
  2887. return -EINVAL;
  2888. }
  2889. switch (micb_num) {
  2890. case MIC_BIAS_1:
  2891. micb_reg = WCD9360_ANA_MICB1;
  2892. break;
  2893. case MIC_BIAS_2:
  2894. micb_reg = WCD9360_ANA_MICB2;
  2895. break;
  2896. case MIC_BIAS_3:
  2897. micb_reg = WCD9360_ANA_MICB3;
  2898. break;
  2899. case MIC_BIAS_4:
  2900. micb_reg = WCD9360_ANA_MICB4;
  2901. break;
  2902. default:
  2903. dev_err(codec->dev, "%s: Invalid micbias number: %d\n",
  2904. __func__, micb_num);
  2905. return -EINVAL;
  2906. }
  2907. mutex_lock(&pahu->micb_lock);
  2908. switch (req) {
  2909. case MICB_PULLUP_ENABLE:
  2910. pahu->pullup_ref[micb_index]++;
  2911. if ((pahu->pullup_ref[micb_index] == 1) &&
  2912. (pahu->micb_ref[micb_index] == 0))
  2913. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x80);
  2914. break;
  2915. case MICB_PULLUP_DISABLE:
  2916. if (pahu->pullup_ref[micb_index] > 0)
  2917. pahu->pullup_ref[micb_index]--;
  2918. if ((pahu->pullup_ref[micb_index] == 0) &&
  2919. (pahu->micb_ref[micb_index] == 0))
  2920. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x00);
  2921. break;
  2922. case MICB_ENABLE:
  2923. pahu->micb_ref[micb_index]++;
  2924. if (pahu->micb_ref[micb_index] == 1)
  2925. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x40);
  2926. break;
  2927. case MICB_DISABLE:
  2928. if (pahu->micb_ref[micb_index] > 0)
  2929. pahu->micb_ref[micb_index]--;
  2930. if ((pahu->micb_ref[micb_index] == 0) &&
  2931. (pahu->pullup_ref[micb_index] > 0))
  2932. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x80);
  2933. else if ((pahu->micb_ref[micb_index] == 0) &&
  2934. (pahu->pullup_ref[micb_index] == 0))
  2935. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x00);
  2936. break;
  2937. }
  2938. dev_dbg(codec->dev, "%s: micb_num:%d, micb_ref: %d\n",
  2939. __func__, micb_num, pahu->micb_ref[micb_index]);
  2940. mutex_unlock(&pahu->micb_lock);
  2941. return 0;
  2942. }
  2943. EXPORT_SYMBOL(pahu_micbias_control);
  2944. static int __pahu_codec_enable_micbias(struct snd_soc_dapm_widget *w,
  2945. int event)
  2946. {
  2947. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2948. int micb_num;
  2949. dev_dbg(codec->dev, "%s: wname: %s, event: %d\n",
  2950. __func__, w->name, event);
  2951. if (strnstr(w->name, "MIC BIAS1", sizeof("MIC BIAS1")))
  2952. micb_num = MIC_BIAS_1;
  2953. else if (strnstr(w->name, "MIC BIAS2", sizeof("MIC BIAS2")))
  2954. micb_num = MIC_BIAS_2;
  2955. else if (strnstr(w->name, "MIC BIAS3", sizeof("MIC BIAS3")))
  2956. micb_num = MIC_BIAS_3;
  2957. else if (strnstr(w->name, "MIC BIAS4", sizeof("MIC BIAS4")))
  2958. micb_num = MIC_BIAS_4;
  2959. else
  2960. return -EINVAL;
  2961. switch (event) {
  2962. case SND_SOC_DAPM_PRE_PMU:
  2963. /*
  2964. * Use ref count to handle micbias pullup
  2965. * and enable requests
  2966. */
  2967. pahu_micbias_control(codec, micb_num, MICB_ENABLE, true);
  2968. break;
  2969. case SND_SOC_DAPM_POST_PMU:
  2970. /* wait for cnp time */
  2971. usleep_range(1000, 1100);
  2972. break;
  2973. case SND_SOC_DAPM_POST_PMD:
  2974. pahu_micbias_control(codec, micb_num, MICB_DISABLE, true);
  2975. break;
  2976. };
  2977. return 0;
  2978. }
  2979. /*
  2980. * pahu_codec_enable_standalone_micbias - enable micbias standalone
  2981. * @codec: pointer to codec instance
  2982. * @micb_num: number of micbias to be enabled
  2983. * @enable: true to enable micbias or false to disable
  2984. *
  2985. * This function is used to enable micbias (1, 2, 3 or 4) during
  2986. * standalone independent of whether TX use-case is running or not
  2987. *
  2988. * Return: error code in case of failure or 0 for success
  2989. */
  2990. int pahu_codec_enable_standalone_micbias(struct snd_soc_codec *codec,
  2991. int micb_num,
  2992. bool enable)
  2993. {
  2994. const char * const micb_names[] = {
  2995. DAPM_MICBIAS1_STANDALONE, DAPM_MICBIAS2_STANDALONE,
  2996. DAPM_MICBIAS3_STANDALONE, DAPM_MICBIAS4_STANDALONE
  2997. };
  2998. int micb_index = micb_num - 1;
  2999. int rc;
  3000. if (!codec) {
  3001. pr_err("%s: Codec memory is NULL\n", __func__);
  3002. return -EINVAL;
  3003. }
  3004. if ((micb_index < 0) || (micb_index > PAHU_MAX_MICBIAS - 1)) {
  3005. dev_err(codec->dev, "%s: Invalid micbias index, micb_ind:%d\n",
  3006. __func__, micb_index);
  3007. return -EINVAL;
  3008. }
  3009. if (enable)
  3010. rc = snd_soc_dapm_force_enable_pin(
  3011. snd_soc_codec_get_dapm(codec),
  3012. micb_names[micb_index]);
  3013. else
  3014. rc = snd_soc_dapm_disable_pin(snd_soc_codec_get_dapm(codec),
  3015. micb_names[micb_index]);
  3016. if (!rc)
  3017. snd_soc_dapm_sync(snd_soc_codec_get_dapm(codec));
  3018. else
  3019. dev_err(codec->dev, "%s: micbias%d force %s pin failed\n",
  3020. __func__, micb_num, (enable ? "enable" : "disable"));
  3021. return rc;
  3022. }
  3023. EXPORT_SYMBOL(pahu_codec_enable_standalone_micbias);
  3024. static int pahu_codec_force_enable_micbias(struct snd_soc_dapm_widget *w,
  3025. struct snd_kcontrol *kcontrol,
  3026. int event)
  3027. {
  3028. int ret = 0;
  3029. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  3030. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(codec);
  3031. switch (event) {
  3032. case SND_SOC_DAPM_PRE_PMU:
  3033. wcd_resmgr_enable_master_bias(pahu->resmgr);
  3034. pahu_cdc_mclk_enable(codec, true);
  3035. ret = __pahu_codec_enable_micbias(w, SND_SOC_DAPM_PRE_PMU);
  3036. /* Wait for 1ms for better cnp */
  3037. usleep_range(1000, 1100);
  3038. pahu_cdc_mclk_enable(codec, false);
  3039. break;
  3040. case SND_SOC_DAPM_POST_PMD:
  3041. ret = __pahu_codec_enable_micbias(w, SND_SOC_DAPM_POST_PMD);
  3042. wcd_resmgr_disable_master_bias(pahu->resmgr);
  3043. break;
  3044. }
  3045. return ret;
  3046. }
  3047. static int pahu_codec_enable_micbias(struct snd_soc_dapm_widget *w,
  3048. struct snd_kcontrol *kcontrol, int event)
  3049. {
  3050. return __pahu_codec_enable_micbias(w, event);
  3051. }
  3052. static void pahu_restore_iir_coeff(struct pahu_priv *pahu, int iir_idx,
  3053. int band_idx)
  3054. {
  3055. u16 reg_add;
  3056. int no_of_reg = 0;
  3057. regmap_write(pahu->wcd9xxx->regmap,
  3058. (WCD9360_CDC_SIDETONE_IIR0_IIR_COEF_B1_CTL + 16 * iir_idx),
  3059. (band_idx * BAND_MAX * sizeof(uint32_t)) & 0x7F);
  3060. reg_add = WCD9360_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL + 16 * iir_idx;
  3061. if (pahu->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS)
  3062. return;
  3063. /*
  3064. * Since wcd9xxx_slim_write_repeat() supports only maximum of 16
  3065. * registers at a time, split total 20 writes(5 coefficients per
  3066. * band and 4 writes per coefficient) into 16 and 4.
  3067. */
  3068. no_of_reg = WCD9360_CDC_REPEAT_WRITES_MAX;
  3069. wcd9xxx_slim_write_repeat(pahu->wcd9xxx, reg_add, no_of_reg,
  3070. &pahu->sidetone_coeff_array[iir_idx][band_idx][0]);
  3071. no_of_reg = (WCD9360_CDC_SIDETONE_IIR_COEFF_MAX * 4) -
  3072. WCD9360_CDC_REPEAT_WRITES_MAX;
  3073. wcd9xxx_slim_write_repeat(pahu->wcd9xxx, reg_add, no_of_reg,
  3074. &pahu->sidetone_coeff_array[iir_idx][band_idx]
  3075. [WCD9360_CDC_REPEAT_WRITES_MAX]);
  3076. }
  3077. static int pahu_iir_enable_audio_mixer_get(struct snd_kcontrol *kcontrol,
  3078. struct snd_ctl_elem_value *ucontrol)
  3079. {
  3080. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  3081. int iir_idx = ((struct soc_multi_mixer_control *)
  3082. kcontrol->private_value)->reg;
  3083. int band_idx = ((struct soc_multi_mixer_control *)
  3084. kcontrol->private_value)->shift;
  3085. /* IIR filter band registers are at integer multiples of 16 */
  3086. u16 iir_reg = WCD9360_CDC_SIDETONE_IIR0_IIR_CTL + 16 * iir_idx;
  3087. ucontrol->value.integer.value[0] = (snd_soc_read(codec, iir_reg) &
  3088. (1 << band_idx)) != 0;
  3089. dev_dbg(codec->dev, "%s: IIR #%d band #%d enable %d\n", __func__,
  3090. iir_idx, band_idx,
  3091. (uint32_t)ucontrol->value.integer.value[0]);
  3092. return 0;
  3093. }
  3094. static int pahu_iir_enable_audio_mixer_put(struct snd_kcontrol *kcontrol,
  3095. struct snd_ctl_elem_value *ucontrol)
  3096. {
  3097. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  3098. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(codec);
  3099. int iir_idx = ((struct soc_multi_mixer_control *)
  3100. kcontrol->private_value)->reg;
  3101. int band_idx = ((struct soc_multi_mixer_control *)
  3102. kcontrol->private_value)->shift;
  3103. bool iir_band_en_status;
  3104. int value = ucontrol->value.integer.value[0];
  3105. u16 iir_reg = WCD9360_CDC_SIDETONE_IIR0_IIR_CTL + 16 * iir_idx;
  3106. pahu_restore_iir_coeff(pahu, iir_idx, band_idx);
  3107. /* Mask first 5 bits, 6-8 are reserved */
  3108. snd_soc_update_bits(codec, iir_reg, (1 << band_idx),
  3109. (value << band_idx));
  3110. iir_band_en_status = ((snd_soc_read(codec, iir_reg) &
  3111. (1 << band_idx)) != 0);
  3112. dev_dbg(codec->dev, "%s: IIR #%d band #%d enable %d\n", __func__,
  3113. iir_idx, band_idx, iir_band_en_status);
  3114. return 0;
  3115. }
  3116. static uint32_t get_iir_band_coeff(struct snd_soc_codec *codec,
  3117. int iir_idx, int band_idx,
  3118. int coeff_idx)
  3119. {
  3120. uint32_t value = 0;
  3121. /* Address does not automatically update if reading */
  3122. snd_soc_write(codec,
  3123. (WCD9360_CDC_SIDETONE_IIR0_IIR_COEF_B1_CTL + 16 * iir_idx),
  3124. ((band_idx * BAND_MAX + coeff_idx)
  3125. * sizeof(uint32_t)) & 0x7F);
  3126. value |= snd_soc_read(codec,
  3127. (WCD9360_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL + 16 * iir_idx));
  3128. snd_soc_write(codec,
  3129. (WCD9360_CDC_SIDETONE_IIR0_IIR_COEF_B1_CTL + 16 * iir_idx),
  3130. ((band_idx * BAND_MAX + coeff_idx)
  3131. * sizeof(uint32_t) + 1) & 0x7F);
  3132. value |= (snd_soc_read(codec,
  3133. (WCD9360_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL +
  3134. 16 * iir_idx)) << 8);
  3135. snd_soc_write(codec,
  3136. (WCD9360_CDC_SIDETONE_IIR0_IIR_COEF_B1_CTL + 16 * iir_idx),
  3137. ((band_idx * BAND_MAX + coeff_idx)
  3138. * sizeof(uint32_t) + 2) & 0x7F);
  3139. value |= (snd_soc_read(codec,
  3140. (WCD9360_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL +
  3141. 16 * iir_idx)) << 16);
  3142. snd_soc_write(codec,
  3143. (WCD9360_CDC_SIDETONE_IIR0_IIR_COEF_B1_CTL + 16 * iir_idx),
  3144. ((band_idx * BAND_MAX + coeff_idx)
  3145. * sizeof(uint32_t) + 3) & 0x7F);
  3146. /* Mask bits top 2 bits since they are reserved */
  3147. value |= ((snd_soc_read(codec,
  3148. (WCD9360_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL +
  3149. 16 * iir_idx)) & 0x3F) << 24);
  3150. return value;
  3151. }
  3152. static int pahu_iir_band_audio_mixer_get(struct snd_kcontrol *kcontrol,
  3153. struct snd_ctl_elem_value *ucontrol)
  3154. {
  3155. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  3156. int iir_idx = ((struct soc_multi_mixer_control *)
  3157. kcontrol->private_value)->reg;
  3158. int band_idx = ((struct soc_multi_mixer_control *)
  3159. kcontrol->private_value)->shift;
  3160. ucontrol->value.integer.value[0] =
  3161. get_iir_band_coeff(codec, iir_idx, band_idx, 0);
  3162. ucontrol->value.integer.value[1] =
  3163. get_iir_band_coeff(codec, iir_idx, band_idx, 1);
  3164. ucontrol->value.integer.value[2] =
  3165. get_iir_band_coeff(codec, iir_idx, band_idx, 2);
  3166. ucontrol->value.integer.value[3] =
  3167. get_iir_band_coeff(codec, iir_idx, band_idx, 3);
  3168. ucontrol->value.integer.value[4] =
  3169. get_iir_band_coeff(codec, iir_idx, band_idx, 4);
  3170. dev_dbg(codec->dev, "%s: IIR #%d band #%d b0 = 0x%x\n"
  3171. "%s: IIR #%d band #%d b1 = 0x%x\n"
  3172. "%s: IIR #%d band #%d b2 = 0x%x\n"
  3173. "%s: IIR #%d band #%d a1 = 0x%x\n"
  3174. "%s: IIR #%d band #%d a2 = 0x%x\n",
  3175. __func__, iir_idx, band_idx,
  3176. (uint32_t)ucontrol->value.integer.value[0],
  3177. __func__, iir_idx, band_idx,
  3178. (uint32_t)ucontrol->value.integer.value[1],
  3179. __func__, iir_idx, band_idx,
  3180. (uint32_t)ucontrol->value.integer.value[2],
  3181. __func__, iir_idx, band_idx,
  3182. (uint32_t)ucontrol->value.integer.value[3],
  3183. __func__, iir_idx, band_idx,
  3184. (uint32_t)ucontrol->value.integer.value[4]);
  3185. return 0;
  3186. }
  3187. static void set_iir_band_coeff(struct snd_soc_codec *codec,
  3188. int iir_idx, int band_idx,
  3189. uint32_t value)
  3190. {
  3191. snd_soc_write(codec,
  3192. (WCD9360_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL + 16 * iir_idx),
  3193. (value & 0xFF));
  3194. snd_soc_write(codec,
  3195. (WCD9360_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL + 16 * iir_idx),
  3196. (value >> 8) & 0xFF);
  3197. snd_soc_write(codec,
  3198. (WCD9360_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL + 16 * iir_idx),
  3199. (value >> 16) & 0xFF);
  3200. /* Mask top 2 bits, 7-8 are reserved */
  3201. snd_soc_write(codec,
  3202. (WCD9360_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL + 16 * iir_idx),
  3203. (value >> 24) & 0x3F);
  3204. }
  3205. static int pahu_iir_band_audio_mixer_put(struct snd_kcontrol *kcontrol,
  3206. struct snd_ctl_elem_value *ucontrol)
  3207. {
  3208. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  3209. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(codec);
  3210. int iir_idx = ((struct soc_multi_mixer_control *)
  3211. kcontrol->private_value)->reg;
  3212. int band_idx = ((struct soc_multi_mixer_control *)
  3213. kcontrol->private_value)->shift;
  3214. int coeff_idx, idx = 0;
  3215. /*
  3216. * Mask top bit it is reserved
  3217. * Updates addr automatically for each B2 write
  3218. */
  3219. snd_soc_write(codec,
  3220. (WCD9360_CDC_SIDETONE_IIR0_IIR_COEF_B1_CTL + 16 * iir_idx),
  3221. (band_idx * BAND_MAX * sizeof(uint32_t)) & 0x7F);
  3222. /* Store the coefficients in sidetone coeff array */
  3223. for (coeff_idx = 0; coeff_idx < WCD9360_CDC_SIDETONE_IIR_COEFF_MAX;
  3224. coeff_idx++) {
  3225. uint32_t value = ucontrol->value.integer.value[coeff_idx];
  3226. set_iir_band_coeff(codec, iir_idx, band_idx, value);
  3227. /* Four 8 bit values(one 32 bit) per coefficient */
  3228. pahu->sidetone_coeff_array[iir_idx][band_idx][idx++] =
  3229. (value & 0xFF);
  3230. pahu->sidetone_coeff_array[iir_idx][band_idx][idx++] =
  3231. ((value >> 8) & 0xFF);
  3232. pahu->sidetone_coeff_array[iir_idx][band_idx][idx++] =
  3233. ((value >> 16) & 0xFF);
  3234. pahu->sidetone_coeff_array[iir_idx][band_idx][idx++] =
  3235. ((value >> 24) & 0xFF);
  3236. }
  3237. pr_debug("%s: IIR #%d band #%d b0 = 0x%x\n"
  3238. "%s: IIR #%d band #%d b1 = 0x%x\n"
  3239. "%s: IIR #%d band #%d b2 = 0x%x\n"
  3240. "%s: IIR #%d band #%d a1 = 0x%x\n"
  3241. "%s: IIR #%d band #%d a2 = 0x%x\n",
  3242. __func__, iir_idx, band_idx,
  3243. get_iir_band_coeff(codec, iir_idx, band_idx, 0),
  3244. __func__, iir_idx, band_idx,
  3245. get_iir_band_coeff(codec, iir_idx, band_idx, 1),
  3246. __func__, iir_idx, band_idx,
  3247. get_iir_band_coeff(codec, iir_idx, band_idx, 2),
  3248. __func__, iir_idx, band_idx,
  3249. get_iir_band_coeff(codec, iir_idx, band_idx, 3),
  3250. __func__, iir_idx, band_idx,
  3251. get_iir_band_coeff(codec, iir_idx, band_idx, 4));
  3252. return 0;
  3253. }
  3254. static int pahu_compander_get(struct snd_kcontrol *kcontrol,
  3255. struct snd_ctl_elem_value *ucontrol)
  3256. {
  3257. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  3258. int comp = ((struct soc_multi_mixer_control *)
  3259. kcontrol->private_value)->shift;
  3260. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(codec);
  3261. ucontrol->value.integer.value[0] = pahu->comp_enabled[comp];
  3262. return 0;
  3263. }
  3264. static int pahu_compander_put(struct snd_kcontrol *kcontrol,
  3265. struct snd_ctl_elem_value *ucontrol)
  3266. {
  3267. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  3268. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(codec);
  3269. int comp = ((struct soc_multi_mixer_control *)
  3270. kcontrol->private_value)->shift;
  3271. int value = ucontrol->value.integer.value[0];
  3272. dev_dbg(codec->dev, "%s: Compander %d enable current %d, new %d\n",
  3273. __func__, comp + 1, pahu->comp_enabled[comp], value);
  3274. pahu->comp_enabled[comp] = value;
  3275. return 0;
  3276. }
  3277. static int pahu_dmic_pin_mode_get(struct snd_kcontrol *kcontrol,
  3278. struct snd_ctl_elem_value *ucontrol)
  3279. {
  3280. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  3281. u16 offset;
  3282. u8 reg_val, pinctl_position;
  3283. pinctl_position = ((struct soc_multi_mixer_control *)
  3284. kcontrol->private_value)->shift;
  3285. offset = pinctl_position - WCD9360_TLMM_DMIC_PINCFG_OFFSET;
  3286. reg_val = snd_soc_read(codec,
  3287. WCD9360_TLMM_DMIC1_CLK_PINCFG + offset);
  3288. ucontrol->value.integer.value[0] = !!reg_val;
  3289. return 0;
  3290. }
  3291. static int pahu_dmic_pin_mode_put(struct snd_kcontrol *kcontrol,
  3292. struct snd_ctl_elem_value *ucontrol)
  3293. {
  3294. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  3295. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(codec);
  3296. u16 ctl_reg, cfg_reg, offset;
  3297. u8 ctl_val, cfg_val, pinctl_position, pinctl_mode, mask;
  3298. /* 0- high or low; 1- high Z */
  3299. pinctl_mode = ucontrol->value.integer.value[0];
  3300. pinctl_position = ((struct soc_multi_mixer_control *)
  3301. kcontrol->private_value)->shift;
  3302. switch (pinctl_position >> 3) {
  3303. case 0:
  3304. ctl_reg = WCD9360_TEST_DEBUG_PIN_CTL_OE_0;
  3305. break;
  3306. case 1:
  3307. ctl_reg = WCD9360_TEST_DEBUG_PIN_CTL_OE_1;
  3308. break;
  3309. case 2:
  3310. ctl_reg = WCD9360_TEST_DEBUG_PIN_CTL_OE_2;
  3311. break;
  3312. case 3:
  3313. ctl_reg = WCD9360_TEST_DEBUG_PIN_CTL_OE_3;
  3314. break;
  3315. default:
  3316. dev_err(codec->dev, "%s: Invalid pinctl position = %d\n",
  3317. __func__, pinctl_position);
  3318. return -EINVAL;
  3319. }
  3320. ctl_val = ~(pinctl_mode << (pinctl_position & 0x07));
  3321. mask = 1 << (pinctl_position & 0x07);
  3322. snd_soc_update_bits(codec, ctl_reg, mask, ctl_val);
  3323. offset = pinctl_position - WCD9360_TLMM_DMIC_PINCFG_OFFSET;
  3324. cfg_reg = WCD9360_TLMM_DMIC1_CLK_PINCFG + offset;
  3325. if (pinctl_mode) {
  3326. if (pahu->intf_type == WCD9XXX_INTERFACE_TYPE_SLIMBUS)
  3327. cfg_val = 0x5;
  3328. else
  3329. cfg_val = 0xD;
  3330. } else
  3331. cfg_val = 0;
  3332. snd_soc_update_bits(codec, cfg_reg, 0x1F, cfg_val);
  3333. dev_dbg(codec->dev, "%s: reg=0x%x mask=0x%x val=%d reg=0x%x val=%d\n",
  3334. __func__, ctl_reg, mask, ctl_val, cfg_reg, cfg_val);
  3335. return 0;
  3336. }
  3337. static int pahu_amic_pwr_lvl_get(struct snd_kcontrol *kcontrol,
  3338. struct snd_ctl_elem_value *ucontrol)
  3339. {
  3340. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  3341. u16 amic_reg = 0;
  3342. if (!strcmp(kcontrol->id.name, "AMIC_1_2 PWR MODE"))
  3343. amic_reg = WCD9360_ANA_AMIC1;
  3344. if (!strcmp(kcontrol->id.name, "AMIC_3_4 PWR MODE"))
  3345. amic_reg = WCD9360_ANA_AMIC3;
  3346. if (amic_reg)
  3347. ucontrol->value.integer.value[0] =
  3348. (snd_soc_read(codec, amic_reg) &
  3349. WCD9360_AMIC_PWR_LVL_MASK) >>
  3350. WCD9360_AMIC_PWR_LVL_SHIFT;
  3351. return 0;
  3352. }
  3353. static int pahu_amic_pwr_lvl_put(struct snd_kcontrol *kcontrol,
  3354. struct snd_ctl_elem_value *ucontrol)
  3355. {
  3356. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  3357. u32 mode_val;
  3358. u16 amic_reg = 0;
  3359. mode_val = ucontrol->value.enumerated.item[0];
  3360. dev_dbg(codec->dev, "%s: mode: %d\n", __func__, mode_val);
  3361. if (!strcmp(kcontrol->id.name, "AMIC_1_2 PWR MODE"))
  3362. amic_reg = WCD9360_ANA_AMIC1;
  3363. if (!strcmp(kcontrol->id.name, "AMIC_3_4 PWR MODE"))
  3364. amic_reg = WCD9360_ANA_AMIC3;
  3365. if (amic_reg)
  3366. snd_soc_update_bits(codec, amic_reg, WCD9360_AMIC_PWR_LVL_MASK,
  3367. mode_val << WCD9360_AMIC_PWR_LVL_SHIFT);
  3368. return 0;
  3369. }
  3370. static const char *const pahu_conn_mad_text[] = {
  3371. "NOTUSED1", "ADC1", "ADC2", "ADC3", "ADC4", "NOTUSED5",
  3372. "NOTUSED6", "NOTUSED2", "DMIC0", "DMIC1", "DMIC2", "DMIC3",
  3373. "DMIC4", "DMIC5", "DMIC6", "DMIC7"
  3374. };
  3375. static const struct soc_enum pahu_conn_mad_enum =
  3376. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(pahu_conn_mad_text),
  3377. pahu_conn_mad_text);
  3378. static int pahu_mad_input_get(struct snd_kcontrol *kcontrol,
  3379. struct snd_ctl_elem_value *ucontrol)
  3380. {
  3381. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  3382. u8 pahu_mad_input;
  3383. pahu_mad_input = snd_soc_read(codec, WCD9360_SOC_MAD_INP_SEL) & 0x0F;
  3384. ucontrol->value.integer.value[0] = pahu_mad_input;
  3385. dev_dbg(codec->dev, "%s: pahu_mad_input = %s\n", __func__,
  3386. pahu_conn_mad_text[pahu_mad_input]);
  3387. return 0;
  3388. }
  3389. static int pahu_mad_input_put(struct snd_kcontrol *kcontrol,
  3390. struct snd_ctl_elem_value *ucontrol)
  3391. {
  3392. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  3393. struct snd_soc_card *card = codec->component.card;
  3394. u8 pahu_mad_input;
  3395. char mad_amic_input_widget[6];
  3396. const char *mad_input_widget;
  3397. const char *source_widget = NULL;
  3398. u32 adc, i, mic_bias_found = 0;
  3399. int ret = 0;
  3400. char *mad_input;
  3401. bool is_adc_input = false;
  3402. pahu_mad_input = ucontrol->value.integer.value[0];
  3403. if (pahu_mad_input >= sizeof(pahu_conn_mad_text)/
  3404. sizeof(pahu_conn_mad_text[0])) {
  3405. dev_err(codec->dev,
  3406. "%s: pahu_mad_input = %d out of bounds\n",
  3407. __func__, pahu_mad_input);
  3408. return -EINVAL;
  3409. }
  3410. if (strnstr(pahu_conn_mad_text[pahu_mad_input], "NOTUSED",
  3411. sizeof("NOTUSED"))) {
  3412. dev_dbg(codec->dev,
  3413. "%s: Unsupported pahu_mad_input = %s\n",
  3414. __func__, pahu_conn_mad_text[pahu_mad_input]);
  3415. /* Make sure the MAD register is updated */
  3416. snd_soc_update_bits(codec, WCD9360_ANA_MAD_SETUP,
  3417. 0x88, 0x00);
  3418. return -EINVAL;
  3419. }
  3420. if (strnstr(pahu_conn_mad_text[pahu_mad_input],
  3421. "ADC", sizeof("ADC"))) {
  3422. mad_input = strpbrk(pahu_conn_mad_text[pahu_mad_input],
  3423. "1234");
  3424. if (!mad_input) {
  3425. dev_err(codec->dev, "%s: Invalid MAD input %s\n",
  3426. __func__, pahu_conn_mad_text[pahu_mad_input]);
  3427. return -EINVAL;
  3428. }
  3429. ret = kstrtouint(mad_input, 10, &adc);
  3430. if ((ret < 0) || (adc > 4)) {
  3431. dev_err(codec->dev, "%s: Invalid ADC = %s\n", __func__,
  3432. pahu_conn_mad_text[pahu_mad_input]);
  3433. return -EINVAL;
  3434. }
  3435. snprintf(mad_amic_input_widget, 6, "%s%u", "AMIC", adc);
  3436. mad_input_widget = mad_amic_input_widget;
  3437. is_adc_input = true;
  3438. } else {
  3439. /* DMIC type input widget*/
  3440. mad_input_widget = pahu_conn_mad_text[pahu_mad_input];
  3441. }
  3442. dev_dbg(codec->dev,
  3443. "%s: pahu input widget = %s, adc_input = %s\n", __func__,
  3444. mad_input_widget, is_adc_input ? "true" : "false");
  3445. for (i = 0; i < card->num_of_dapm_routes; i++) {
  3446. if (!strcmp(card->of_dapm_routes[i].sink, mad_input_widget)) {
  3447. source_widget = card->of_dapm_routes[i].source;
  3448. if (!source_widget) {
  3449. dev_err(codec->dev,
  3450. "%s: invalid source widget\n",
  3451. __func__);
  3452. return -EINVAL;
  3453. }
  3454. if (strnstr(source_widget,
  3455. "MIC BIAS1", sizeof("MIC BIAS1"))) {
  3456. mic_bias_found = 1;
  3457. break;
  3458. } else if (strnstr(source_widget,
  3459. "MIC BIAS2", sizeof("MIC BIAS2"))) {
  3460. mic_bias_found = 2;
  3461. break;
  3462. } else if (strnstr(source_widget,
  3463. "MIC BIAS3", sizeof("MIC BIAS3"))) {
  3464. mic_bias_found = 3;
  3465. break;
  3466. } else if (strnstr(source_widget,
  3467. "MIC BIAS4", sizeof("MIC BIAS4"))) {
  3468. mic_bias_found = 4;
  3469. break;
  3470. }
  3471. }
  3472. }
  3473. if (!mic_bias_found) {
  3474. dev_err(codec->dev, "%s: mic bias not found for input %s\n",
  3475. __func__, mad_input_widget);
  3476. return -EINVAL;
  3477. }
  3478. dev_dbg(codec->dev, "%s: mic_bias found = %d\n", __func__,
  3479. mic_bias_found);
  3480. snd_soc_update_bits(codec, WCD9360_SOC_MAD_INP_SEL,
  3481. 0x0F, pahu_mad_input);
  3482. snd_soc_update_bits(codec, WCD9360_ANA_MAD_SETUP,
  3483. 0x07, mic_bias_found);
  3484. /* for all adc inputs, mad should be in micbias mode with BG enabled */
  3485. if (is_adc_input)
  3486. snd_soc_update_bits(codec, WCD9360_ANA_MAD_SETUP,
  3487. 0x88, 0x88);
  3488. else
  3489. snd_soc_update_bits(codec, WCD9360_ANA_MAD_SETUP,
  3490. 0x88, 0x00);
  3491. return 0;
  3492. }
  3493. static int pahu_ear_spkr_pa_gain_get(struct snd_kcontrol *kcontrol,
  3494. struct snd_ctl_elem_value *ucontrol)
  3495. {
  3496. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  3497. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(codec);
  3498. ucontrol->value.integer.value[0] = pahu->ear_spkr_gain;
  3499. dev_dbg(codec->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  3500. __func__, ucontrol->value.integer.value[0]);
  3501. return 0;
  3502. }
  3503. static int pahu_ear_spkr_pa_gain_put(struct snd_kcontrol *kcontrol,
  3504. struct snd_ctl_elem_value *ucontrol)
  3505. {
  3506. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  3507. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(codec);
  3508. pahu->ear_spkr_gain = ucontrol->value.integer.value[0];
  3509. dev_dbg(codec->dev, "%s: gain = %d\n", __func__, pahu->ear_spkr_gain);
  3510. return 0;
  3511. }
  3512. static int pahu_spkr_left_boost_stage_get(struct snd_kcontrol *kcontrol,
  3513. struct snd_ctl_elem_value *ucontrol)
  3514. {
  3515. u8 bst_state_max = 0;
  3516. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  3517. bst_state_max = snd_soc_read(codec, WCD9360_CDC_BOOST0_BOOST_CTL);
  3518. bst_state_max = (bst_state_max & 0x0c) >> 2;
  3519. ucontrol->value.integer.value[0] = bst_state_max;
  3520. dev_dbg(codec->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  3521. __func__, ucontrol->value.integer.value[0]);
  3522. return 0;
  3523. }
  3524. static int pahu_spkr_left_boost_stage_put(struct snd_kcontrol *kcontrol,
  3525. struct snd_ctl_elem_value *ucontrol)
  3526. {
  3527. u8 bst_state_max;
  3528. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  3529. dev_dbg(codec->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  3530. __func__, ucontrol->value.integer.value[0]);
  3531. bst_state_max = ucontrol->value.integer.value[0] << 2;
  3532. snd_soc_update_bits(codec, WCD9360_CDC_BOOST0_BOOST_CTL,
  3533. 0x0c, bst_state_max);
  3534. return 0;
  3535. }
  3536. static int pahu_spkr_right_boost_stage_get(struct snd_kcontrol *kcontrol,
  3537. struct snd_ctl_elem_value *ucontrol)
  3538. {
  3539. u8 bst_state_max = 0;
  3540. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  3541. bst_state_max = snd_soc_read(codec, WCD9360_CDC_BOOST1_BOOST_CTL);
  3542. bst_state_max = (bst_state_max & 0x0c) >> 2;
  3543. ucontrol->value.integer.value[0] = bst_state_max;
  3544. dev_dbg(codec->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  3545. __func__, ucontrol->value.integer.value[0]);
  3546. return 0;
  3547. }
  3548. static int pahu_spkr_right_boost_stage_put(struct snd_kcontrol *kcontrol,
  3549. struct snd_ctl_elem_value *ucontrol)
  3550. {
  3551. u8 bst_state_max;
  3552. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  3553. dev_dbg(codec->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  3554. __func__, ucontrol->value.integer.value[0]);
  3555. bst_state_max = ucontrol->value.integer.value[0] << 2;
  3556. snd_soc_update_bits(codec, WCD9360_CDC_BOOST1_BOOST_CTL,
  3557. 0x0c, bst_state_max);
  3558. return 0;
  3559. }
  3560. static const char *const pahu_anc_func_text[] = {"OFF", "ON"};
  3561. static const struct soc_enum pahu_anc_func_enum =
  3562. SOC_ENUM_SINGLE_EXT(2, pahu_anc_func_text);
  3563. static const char *const pahu_clkmode_text[] = {"EXTERNAL", "INTERNAL"};
  3564. static SOC_ENUM_SINGLE_EXT_DECL(pahu_clkmode_enum, pahu_clkmode_text);
  3565. /* Cutoff frequency for high pass filter */
  3566. static const char * const cf_text[] = {
  3567. "CF_NEG_3DB_4HZ", "CF_NEG_3DB_75HZ", "CF_NEG_3DB_150HZ"
  3568. };
  3569. static const char * const rx_cf_text[] = {
  3570. "CF_NEG_3DB_4HZ", "CF_NEG_3DB_75HZ", "CF_NEG_3DB_150HZ",
  3571. "CF_NEG_3DB_0P48HZ"
  3572. };
  3573. static const char * const amic_pwr_lvl_text[] = {
  3574. "LOW_PWR", "DEFAULT", "HIGH_PERF", "HYBRID"
  3575. };
  3576. static const char * const pahu_ear_pa_gain_text[] = {
  3577. "G_6_DB", "G_4P5_DB", "G_3_DB", "G_1P5_DB",
  3578. "G_0_DB", "G_M2P5_DB", "UNDEFINED", "G_M12_DB"
  3579. };
  3580. static const char * const pahu_ear_spkr_pa_gain_text[] = {
  3581. "G_DEFAULT", "G_0_DB", "G_1_DB", "G_2_DB", "G_3_DB",
  3582. "G_4_DB", "G_5_DB", "G_6_DB"
  3583. };
  3584. static const char * const pahu_speaker_boost_stage_text[] = {
  3585. "NO_MAX_STATE", "MAX_STATE_1", "MAX_STATE_2"
  3586. };
  3587. static SOC_ENUM_SINGLE_EXT_DECL(pahu_ear_pa_gain_enum, pahu_ear_pa_gain_text);
  3588. static SOC_ENUM_SINGLE_EXT_DECL(pahu_ear_spkr_pa_gain_enum,
  3589. pahu_ear_spkr_pa_gain_text);
  3590. static SOC_ENUM_SINGLE_EXT_DECL(pahu_spkr_boost_stage_enum,
  3591. pahu_speaker_boost_stage_text);
  3592. static SOC_ENUM_SINGLE_EXT_DECL(amic_pwr_lvl_enum, amic_pwr_lvl_text);
  3593. static SOC_ENUM_SINGLE_DECL(cf_dec0_enum, WCD9360_CDC_TX0_TX_PATH_CFG0, 5,
  3594. cf_text);
  3595. static SOC_ENUM_SINGLE_DECL(cf_dec1_enum, WCD9360_CDC_TX1_TX_PATH_CFG0, 5,
  3596. cf_text);
  3597. static SOC_ENUM_SINGLE_DECL(cf_dec2_enum, WCD9360_CDC_TX2_TX_PATH_CFG0, 5,
  3598. cf_text);
  3599. static SOC_ENUM_SINGLE_DECL(cf_dec3_enum, WCD9360_CDC_TX3_TX_PATH_CFG0, 5,
  3600. cf_text);
  3601. static SOC_ENUM_SINGLE_DECL(cf_dec4_enum, WCD9360_CDC_TX4_TX_PATH_CFG0, 5,
  3602. cf_text);
  3603. static SOC_ENUM_SINGLE_DECL(cf_dec5_enum, WCD9360_CDC_TX5_TX_PATH_CFG0, 5,
  3604. cf_text);
  3605. static SOC_ENUM_SINGLE_DECL(cf_dec6_enum, WCD9360_CDC_TX6_TX_PATH_CFG0, 5,
  3606. cf_text);
  3607. static SOC_ENUM_SINGLE_DECL(cf_dec7_enum, WCD9360_CDC_TX7_TX_PATH_CFG0, 5,
  3608. cf_text);
  3609. static SOC_ENUM_SINGLE_DECL(cf_dec8_enum, WCD9360_CDC_TX8_TX_PATH_CFG0, 5,
  3610. cf_text);
  3611. static SOC_ENUM_SINGLE_DECL(cf_int0_1_enum, WCD9360_CDC_RX0_RX_PATH_CFG2, 0,
  3612. rx_cf_text);
  3613. static SOC_ENUM_SINGLE_DECL(cf_int0_2_enum, WCD9360_CDC_RX0_RX_PATH_MIX_CFG, 2,
  3614. rx_cf_text);
  3615. static SOC_ENUM_SINGLE_DECL(cf_int7_1_enum, WCD9360_CDC_RX7_RX_PATH_CFG2, 0,
  3616. rx_cf_text);
  3617. static SOC_ENUM_SINGLE_DECL(cf_int7_2_enum, WCD9360_CDC_RX7_RX_PATH_MIX_CFG, 2,
  3618. rx_cf_text);
  3619. static SOC_ENUM_SINGLE_DECL(cf_int8_1_enum, WCD9360_CDC_RX8_RX_PATH_CFG2, 0,
  3620. rx_cf_text);
  3621. static SOC_ENUM_SINGLE_DECL(cf_int8_2_enum, WCD9360_CDC_RX8_RX_PATH_MIX_CFG, 2,
  3622. rx_cf_text);
  3623. static SOC_ENUM_SINGLE_DECL(cf_int9_1_enum, WCD9360_CDC_RX9_RX_PATH_CFG2, 0,
  3624. rx_cf_text);
  3625. static SOC_ENUM_SINGLE_DECL(cf_int9_2_enum, WCD9360_CDC_RX9_RX_PATH_MIX_CFG, 2,
  3626. rx_cf_text);
  3627. static const struct snd_kcontrol_new pahu_snd_controls[] = {
  3628. SOC_ENUM_EXT("EAR SPKR PA Gain", pahu_ear_spkr_pa_gain_enum,
  3629. pahu_ear_spkr_pa_gain_get, pahu_ear_spkr_pa_gain_put),
  3630. SOC_ENUM_EXT("SPKR Left Boost Max State", pahu_spkr_boost_stage_enum,
  3631. pahu_spkr_left_boost_stage_get,
  3632. pahu_spkr_left_boost_stage_put),
  3633. SOC_ENUM_EXT("SPKR Right Boost Max State", pahu_spkr_boost_stage_enum,
  3634. pahu_spkr_right_boost_stage_get,
  3635. pahu_spkr_right_boost_stage_put),
  3636. SOC_SINGLE_TLV("ADC1 Volume", WCD9360_ANA_AMIC1, 0, 20, 0, analog_gain),
  3637. SOC_SINGLE_TLV("ADC2 Volume", WCD9360_ANA_AMIC2, 0, 20, 0, analog_gain),
  3638. SOC_SINGLE_TLV("ADC3 Volume", WCD9360_ANA_AMIC3, 0, 20, 0, analog_gain),
  3639. SOC_SINGLE_TLV("ADC4 Volume", WCD9360_ANA_AMIC4, 0, 20, 0, analog_gain),
  3640. SOC_SINGLE_SX_TLV("RX0 Digital Volume", WCD9360_CDC_RX0_RX_VOL_CTL,
  3641. 0, -84, 40, digital_gain), /* -84dB min - 40dB max */
  3642. SOC_SINGLE_SX_TLV("RX7 Digital Volume", WCD9360_CDC_RX7_RX_VOL_CTL,
  3643. 0, -84, 40, digital_gain),
  3644. SOC_SINGLE_SX_TLV("RX8 Digital Volume", WCD9360_CDC_RX8_RX_VOL_CTL,
  3645. 0, -84, 40, digital_gain),
  3646. SOC_SINGLE_SX_TLV("RX9 Digital Volume", WCD9360_CDC_RX9_RX_VOL_CTL,
  3647. 0, -84, 40, digital_gain),
  3648. SOC_SINGLE_SX_TLV("RX0 Mix Digital Volume",
  3649. WCD9360_CDC_RX0_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain),
  3650. SOC_SINGLE_SX_TLV("RX7 Mix Digital Volume",
  3651. WCD9360_CDC_RX7_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain),
  3652. SOC_SINGLE_SX_TLV("RX8 Mix Digital Volume",
  3653. WCD9360_CDC_RX8_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain),
  3654. SOC_SINGLE_SX_TLV("RX9 Mix Digital Volume",
  3655. WCD9360_CDC_RX9_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain),
  3656. SOC_SINGLE_SX_TLV("DEC0 Volume", WCD9360_CDC_TX0_TX_VOL_CTL, 0,
  3657. -84, 40, digital_gain),
  3658. SOC_SINGLE_SX_TLV("DEC1 Volume", WCD9360_CDC_TX1_TX_VOL_CTL, 0,
  3659. -84, 40, digital_gain),
  3660. SOC_SINGLE_SX_TLV("DEC2 Volume", WCD9360_CDC_TX2_TX_VOL_CTL, 0,
  3661. -84, 40, digital_gain),
  3662. SOC_SINGLE_SX_TLV("DEC3 Volume", WCD9360_CDC_TX3_TX_VOL_CTL, 0,
  3663. -84, 40, digital_gain),
  3664. SOC_SINGLE_SX_TLV("DEC4 Volume", WCD9360_CDC_TX4_TX_VOL_CTL, 0,
  3665. -84, 40, digital_gain),
  3666. SOC_SINGLE_SX_TLV("DEC5 Volume", WCD9360_CDC_TX5_TX_VOL_CTL, 0,
  3667. -84, 40, digital_gain),
  3668. SOC_SINGLE_SX_TLV("DEC6 Volume", WCD9360_CDC_TX6_TX_VOL_CTL, 0,
  3669. -84, 40, digital_gain),
  3670. SOC_SINGLE_SX_TLV("DEC7 Volume", WCD9360_CDC_TX7_TX_VOL_CTL, 0,
  3671. -84, 40, digital_gain),
  3672. SOC_SINGLE_SX_TLV("DEC8 Volume", WCD9360_CDC_TX8_TX_VOL_CTL, 0,
  3673. -84, 40, digital_gain),
  3674. SOC_SINGLE_SX_TLV("IIR0 INP0 Volume",
  3675. WCD9360_CDC_SIDETONE_IIR0_IIR_GAIN_B1_CTL, 0, -84, 40,
  3676. digital_gain),
  3677. SOC_SINGLE_SX_TLV("IIR0 INP1 Volume",
  3678. WCD9360_CDC_SIDETONE_IIR0_IIR_GAIN_B2_CTL, 0, -84, 40,
  3679. digital_gain),
  3680. SOC_SINGLE_SX_TLV("IIR0 INP2 Volume",
  3681. WCD9360_CDC_SIDETONE_IIR0_IIR_GAIN_B3_CTL, 0, -84, 40,
  3682. digital_gain),
  3683. SOC_SINGLE_SX_TLV("IIR0 INP3 Volume",
  3684. WCD9360_CDC_SIDETONE_IIR0_IIR_GAIN_B4_CTL, 0, -84, 40,
  3685. digital_gain),
  3686. SOC_SINGLE_EXT("ANC Slot", SND_SOC_NOPM, 0, 100, 0, pahu_get_anc_slot,
  3687. pahu_put_anc_slot),
  3688. SOC_ENUM_EXT("ANC Function", pahu_anc_func_enum, pahu_get_anc_func,
  3689. pahu_put_anc_func),
  3690. SOC_ENUM_EXT("CLK MODE", pahu_clkmode_enum, pahu_get_clkmode,
  3691. pahu_put_clkmode),
  3692. SOC_ENUM("TX0 HPF cut off", cf_dec0_enum),
  3693. SOC_ENUM("TX1 HPF cut off", cf_dec1_enum),
  3694. SOC_ENUM("TX2 HPF cut off", cf_dec2_enum),
  3695. SOC_ENUM("TX3 HPF cut off", cf_dec3_enum),
  3696. SOC_ENUM("TX4 HPF cut off", cf_dec4_enum),
  3697. SOC_ENUM("TX5 HPF cut off", cf_dec5_enum),
  3698. SOC_ENUM("TX6 HPF cut off", cf_dec6_enum),
  3699. SOC_ENUM("TX7 HPF cut off", cf_dec7_enum),
  3700. SOC_ENUM("TX8 HPF cut off", cf_dec8_enum),
  3701. SOC_ENUM("RX INT0_1 HPF cut off", cf_int0_1_enum),
  3702. SOC_ENUM("RX INT0_2 HPF cut off", cf_int0_2_enum),
  3703. SOC_ENUM("RX INT7_1 HPF cut off", cf_int7_1_enum),
  3704. SOC_ENUM("RX INT7_2 HPF cut off", cf_int7_2_enum),
  3705. SOC_ENUM("RX INT8_1 HPF cut off", cf_int8_1_enum),
  3706. SOC_ENUM("RX INT8_2 HPF cut off", cf_int8_2_enum),
  3707. SOC_ENUM("RX INT9_1 HPF cut off", cf_int9_1_enum),
  3708. SOC_ENUM("RX INT9_2 HPF cut off", cf_int9_2_enum),
  3709. SOC_SINGLE_EXT("IIR0 Enable Band1", IIR0, BAND1, 1, 0,
  3710. pahu_iir_enable_audio_mixer_get,
  3711. pahu_iir_enable_audio_mixer_put),
  3712. SOC_SINGLE_EXT("IIR0 Enable Band2", IIR0, BAND2, 1, 0,
  3713. pahu_iir_enable_audio_mixer_get,
  3714. pahu_iir_enable_audio_mixer_put),
  3715. SOC_SINGLE_EXT("IIR0 Enable Band3", IIR0, BAND3, 1, 0,
  3716. pahu_iir_enable_audio_mixer_get,
  3717. pahu_iir_enable_audio_mixer_put),
  3718. SOC_SINGLE_EXT("IIR0 Enable Band4", IIR0, BAND4, 1, 0,
  3719. pahu_iir_enable_audio_mixer_get,
  3720. pahu_iir_enable_audio_mixer_put),
  3721. SOC_SINGLE_EXT("IIR0 Enable Band5", IIR0, BAND5, 1, 0,
  3722. pahu_iir_enable_audio_mixer_get,
  3723. pahu_iir_enable_audio_mixer_put),
  3724. SOC_SINGLE_MULTI_EXT("IIR0 Band1", IIR0, BAND1, 255, 0, 5,
  3725. pahu_iir_band_audio_mixer_get, pahu_iir_band_audio_mixer_put),
  3726. SOC_SINGLE_MULTI_EXT("IIR0 Band2", IIR0, BAND2, 255, 0, 5,
  3727. pahu_iir_band_audio_mixer_get, pahu_iir_band_audio_mixer_put),
  3728. SOC_SINGLE_MULTI_EXT("IIR0 Band3", IIR0, BAND3, 255, 0, 5,
  3729. pahu_iir_band_audio_mixer_get, pahu_iir_band_audio_mixer_put),
  3730. SOC_SINGLE_MULTI_EXT("IIR0 Band4", IIR0, BAND4, 255, 0, 5,
  3731. pahu_iir_band_audio_mixer_get, pahu_iir_band_audio_mixer_put),
  3732. SOC_SINGLE_MULTI_EXT("IIR0 Band5", IIR0, BAND5, 255, 0, 5,
  3733. pahu_iir_band_audio_mixer_get, pahu_iir_band_audio_mixer_put),
  3734. SOC_SINGLE_EXT("COMP0 Switch", SND_SOC_NOPM, COMPANDER_1, 1, 0,
  3735. pahu_compander_get, pahu_compander_put),
  3736. SOC_SINGLE_EXT("COMP7 Switch", SND_SOC_NOPM, COMPANDER_7, 1, 0,
  3737. pahu_compander_get, pahu_compander_put),
  3738. SOC_SINGLE_EXT("COMP8 Switch", SND_SOC_NOPM, COMPANDER_8, 1, 0,
  3739. pahu_compander_get, pahu_compander_put),
  3740. SOC_ENUM_EXT("MAD Input", pahu_conn_mad_enum,
  3741. pahu_mad_input_get, pahu_mad_input_put),
  3742. SOC_SINGLE_EXT("DMIC1_CLK_PIN_MODE", SND_SOC_NOPM, 15, 1, 0,
  3743. pahu_dmic_pin_mode_get, pahu_dmic_pin_mode_put),
  3744. SOC_SINGLE_EXT("DMIC1_DATA_PIN_MODE", SND_SOC_NOPM, 16, 1, 0,
  3745. pahu_dmic_pin_mode_get, pahu_dmic_pin_mode_put),
  3746. SOC_SINGLE_EXT("DMIC2_CLK_PIN_MODE", SND_SOC_NOPM, 17, 1, 0,
  3747. pahu_dmic_pin_mode_get, pahu_dmic_pin_mode_put),
  3748. SOC_SINGLE_EXT("DMIC2_DATA_PIN_MODE", SND_SOC_NOPM, 18, 1, 0,
  3749. pahu_dmic_pin_mode_get, pahu_dmic_pin_mode_put),
  3750. SOC_SINGLE_EXT("DMIC3_CLK_PIN_MODE", SND_SOC_NOPM, 28, 1, 0,
  3751. pahu_dmic_pin_mode_get, pahu_dmic_pin_mode_put),
  3752. SOC_SINGLE_EXT("DMIC3_DATA_PIN_MODE", SND_SOC_NOPM, 29, 1, 0,
  3753. pahu_dmic_pin_mode_get, pahu_dmic_pin_mode_put),
  3754. SOC_SINGLE_EXT("DMIC4_CLK_PIN_MODE", SND_SOC_NOPM, 30, 1, 0,
  3755. pahu_dmic_pin_mode_get, pahu_dmic_pin_mode_put),
  3756. SOC_SINGLE_EXT("DMIC4_DATA_PIN_MODE", SND_SOC_NOPM, 31, 1, 0,
  3757. pahu_dmic_pin_mode_get, pahu_dmic_pin_mode_put),
  3758. SOC_ENUM_EXT("AMIC_1_2 PWR MODE", amic_pwr_lvl_enum,
  3759. pahu_amic_pwr_lvl_get, pahu_amic_pwr_lvl_put),
  3760. SOC_ENUM_EXT("AMIC_3_4 PWR MODE", amic_pwr_lvl_enum,
  3761. pahu_amic_pwr_lvl_get, pahu_amic_pwr_lvl_put),
  3762. };
  3763. static int pahu_dec_enum_put(struct snd_kcontrol *kcontrol,
  3764. struct snd_ctl_elem_value *ucontrol)
  3765. {
  3766. struct snd_soc_dapm_widget *widget =
  3767. snd_soc_dapm_kcontrol_widget(kcontrol);
  3768. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  3769. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  3770. unsigned int val;
  3771. u16 mic_sel_reg = 0;
  3772. u8 mic_sel;
  3773. val = ucontrol->value.enumerated.item[0];
  3774. if (val > e->items - 1)
  3775. return -EINVAL;
  3776. dev_dbg(codec->dev, "%s: wname: %s, val: 0x%x\n", __func__,
  3777. widget->name, val);
  3778. switch (e->reg) {
  3779. case WCD9360_CDC_TX_INP_MUX_ADC_MUX0_CFG1:
  3780. if (e->shift_l == 0)
  3781. mic_sel_reg = WCD9360_CDC_TX0_TX_PATH_CFG0;
  3782. else if (e->shift_l == 2)
  3783. mic_sel_reg = WCD9360_CDC_TX4_TX_PATH_CFG0;
  3784. else if (e->shift_l == 4)
  3785. mic_sel_reg = WCD9360_CDC_TX8_TX_PATH_CFG0;
  3786. break;
  3787. case WCD9360_CDC_TX_INP_MUX_ADC_MUX1_CFG1:
  3788. if (e->shift_l == 0)
  3789. mic_sel_reg = WCD9360_CDC_TX1_TX_PATH_CFG0;
  3790. else if (e->shift_l == 2)
  3791. mic_sel_reg = WCD9360_CDC_TX5_TX_PATH_CFG0;
  3792. break;
  3793. case WCD9360_CDC_TX_INP_MUX_ADC_MUX2_CFG1:
  3794. if (e->shift_l == 0)
  3795. mic_sel_reg = WCD9360_CDC_TX2_TX_PATH_CFG0;
  3796. else if (e->shift_l == 2)
  3797. mic_sel_reg = WCD9360_CDC_TX6_TX_PATH_CFG0;
  3798. break;
  3799. case WCD9360_CDC_TX_INP_MUX_ADC_MUX3_CFG1:
  3800. if (e->shift_l == 0)
  3801. mic_sel_reg = WCD9360_CDC_TX3_TX_PATH_CFG0;
  3802. else if (e->shift_l == 2)
  3803. mic_sel_reg = WCD9360_CDC_TX7_TX_PATH_CFG0;
  3804. break;
  3805. default:
  3806. dev_err(codec->dev, "%s: e->reg: 0x%x not expected\n",
  3807. __func__, e->reg);
  3808. return -EINVAL;
  3809. }
  3810. /* ADC: 0, DMIC: 1 */
  3811. mic_sel = val ? 0x0 : 0x1;
  3812. if (mic_sel_reg)
  3813. snd_soc_update_bits(codec, mic_sel_reg, 1 << 7, mic_sel << 7);
  3814. return snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
  3815. }
  3816. static int pahu_int_dem_inp_mux_put(struct snd_kcontrol *kcontrol,
  3817. struct snd_ctl_elem_value *ucontrol)
  3818. {
  3819. struct snd_soc_dapm_widget *widget =
  3820. snd_soc_dapm_kcontrol_widget(kcontrol);
  3821. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  3822. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  3823. unsigned int val;
  3824. unsigned short look_ahead_dly_reg = WCD9360_CDC_RX0_RX_PATH_CFG0;
  3825. val = ucontrol->value.enumerated.item[0];
  3826. if (val >= e->items)
  3827. return -EINVAL;
  3828. dev_dbg(codec->dev, "%s: wname: %s, val: 0x%x\n", __func__,
  3829. widget->name, val);
  3830. if (e->reg == WCD9360_CDC_RX0_RX_PATH_SEC0)
  3831. look_ahead_dly_reg = WCD9360_CDC_RX0_RX_PATH_CFG0;
  3832. else if (e->reg == WCD9360_CDC_RX9_RX_PATH_SEC0)
  3833. look_ahead_dly_reg = WCD9360_CDC_RX9_RX_PATH_CFG0;
  3834. /* Set Look Ahead Delay */
  3835. snd_soc_update_bits(codec, look_ahead_dly_reg,
  3836. 0x08, (val ? 0x08 : 0x00));
  3837. /* Set DEM INP Select */
  3838. return snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
  3839. }
  3840. static const char * const rx_int0_7_mix_mux_text[] = {
  3841. "ZERO", "RX0", "RX1", "RX2", "RX3", "RX4", "RX5",
  3842. "RX6", "RX7", "PROXIMITY", "IIR0"
  3843. };
  3844. static const char * const rx_int_mix_mux_text[] = {
  3845. "ZERO", "RX0", "RX1", "RX2", "RX3", "RX4", "RX5",
  3846. "RX6", "RX7", "NA", "IIR0"
  3847. };
  3848. static const char * const rx_prim_mix_text[] = {
  3849. "ZERO", "DEC0", "DEC1", "IIR0", "INVALID", "RX0", "RX1", "RX2",
  3850. "RX3", "RX4", "RX5", "RX6", "RX7"
  3851. };
  3852. static const char * const rx_sidetone_mix_text[] = {
  3853. "ZERO", "SRC0"
  3854. };
  3855. static const char * const cdc_if_tx0_mux_text[] = {
  3856. "ZERO", "RX_MIX_TX0", "DEC0", "DEC0_192"
  3857. };
  3858. static const char * const cdc_if_tx1_mux_text[] = {
  3859. "ZERO", "RX_MIX_TX1", "DEC1", "DEC1_192"
  3860. };
  3861. static const char * const cdc_if_tx2_mux_text[] = {
  3862. "ZERO", "RX_MIX_TX2", "DEC2", "DEC2_192"
  3863. };
  3864. static const char * const cdc_if_tx3_mux_text[] = {
  3865. "ZERO", "RX_MIX_TX3", "DEC3", "DEC3_192"
  3866. };
  3867. static const char * const cdc_if_tx4_mux_text[] = {
  3868. "ZERO", "RX_MIX_TX4", "DEC4", "DEC4_192"
  3869. };
  3870. static const char * const cdc_if_tx5_mux_text[] = {
  3871. "ZERO", "RX_MIX_TX5", "DEC5", "DEC5_192"
  3872. };
  3873. static const char * const cdc_if_tx6_mux_text[] = {
  3874. "ZERO", "RX_MIX_TX6", "DEC6", "DEC6_192"
  3875. };
  3876. static const char * const cdc_if_tx7_mux_text[] = {
  3877. "ZERO", "RX_MIX_TX7", "DEC7", "DEC7_192"
  3878. };
  3879. static const char * const cdc_if_tx8_mux_text[] = {
  3880. "ZERO", "RX_MIX_TX8", "DEC8", "DEC8_192"
  3881. };
  3882. static const char * const cdc_if_tx9_mux_text[] = {
  3883. "ZERO", "DEC7", "DEC7_192"
  3884. };
  3885. static const char * const cdc_if_tx10_mux_text[] = {
  3886. "ZERO", "DEC6", "DEC6_192"
  3887. };
  3888. static const char * const cdc_if_tx11_mux_text[] = {
  3889. "DEC_0_5", "DEC_9_12", "MAD_AUDIO", "MAD_BRDCST"
  3890. };
  3891. static const char * const cdc_if_tx11_inp1_mux_text[] = {
  3892. "ZERO", "DEC0", "DEC1", "DEC2", "DEC3", "DEC4",
  3893. "DEC5", "RX_MIX_TX5", "DEC9_10", "DEC11_12"
  3894. };
  3895. static const char * const cdc_if_tx13_mux_text[] = {
  3896. "CDC_DEC_5", "MAD_BRDCST"
  3897. };
  3898. static const char * const cdc_if_tx13_inp1_mux_text[] = {
  3899. "ZERO", "DEC5", "DEC5_192"
  3900. };
  3901. static const char * const iir_inp_mux_text[] = {
  3902. "ZERO", "DEC0", "DEC1", "DEC2", "DEC3", "DEC4", "DEC5", "DEC6",
  3903. "DEC7", "DEC8", "RX0", "RX1", "RX2", "RX3", "RX4", "RX5", "RX6", "RX7"
  3904. };
  3905. static const char * const rx_int_dem_inp_mux_text[] = {
  3906. "NORMAL_DSM_OUT", "NOT_VALID", "ADC_LOOPBACK"
  3907. };
  3908. static const char * const rx_int0_1_interp_mux_text[] = {
  3909. "ZERO", "RX INT0_1 MIX1",
  3910. };
  3911. static const char * const rx_int7_1_interp_mux_text[] = {
  3912. "ZERO", "RX INT7_1 MIX1",
  3913. };
  3914. static const char * const rx_int8_1_interp_mux_text[] = {
  3915. "ZERO", "RX INT8_1 MIX1",
  3916. };
  3917. static const char * const rx_int9_1_interp_mux_text[] = {
  3918. "ZERO", "RX INT9_1 MIX1",
  3919. };
  3920. static const char * const rx_int0_2_interp_mux_text[] = {
  3921. "ZERO", "RX INT0_2 MUX",
  3922. };
  3923. static const char * const rx_int7_2_interp_mux_text[] = {
  3924. "ZERO", "RX INT7_2 MUX",
  3925. };
  3926. static const char * const rx_int8_2_interp_mux_text[] = {
  3927. "ZERO", "RX INT8_2 MUX",
  3928. };
  3929. static const char * const rx_int9_2_interp_mux_text[] = {
  3930. "ZERO", "RX INT9_2 MUX",
  3931. };
  3932. static const char * const mad_sel_txt[] = {
  3933. "SPE", "MSM"
  3934. };
  3935. static const char * const mad_inp_mux_txt[] = {
  3936. "MAD", "DEC1"
  3937. };
  3938. static const char * const adc_mux_text[] = {
  3939. "DMIC", "AMIC", "ANC_FB_TUNE1"
  3940. };
  3941. static const char * const dmic_mux_text[] = {
  3942. "ZERO", "DMIC0", "DMIC1", "DMIC2", "DMIC3", "DMIC4", "DMIC5",
  3943. "NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA", "DMIC6",
  3944. "DMIC7"
  3945. };
  3946. static const char * const amic_mux_text[] = {
  3947. "ZERO", "ADC1", "ADC2", "ADC3", "ADC4"
  3948. };
  3949. static const char * const adc2_in_text[] = {
  3950. "AMIC2", "AMIC1"
  3951. };
  3952. static const char * const adc4_in_text[] = {
  3953. "AMIC4", "AMIC3"
  3954. };
  3955. static const char * const anc0_fb_mux_text[] = {
  3956. "ZERO", "INVALID", "ANC_IN_EAR", "ANC_IN_EAR_SPKR",
  3957. };
  3958. static const char * const rx_echo_mux_text[] = {
  3959. "ZERO", "RX_MIX0", "NA", "NA", "NA", "NA", "NA", "NA",
  3960. "RX_MIX7", "RX_MIX8", "NA", "NA", "NA", "NA", "RX_MIX9"
  3961. };
  3962. static const char *const slim_rx_mux_text[] = {
  3963. "ZERO", "AIF1_PB", "AIF2_PB", "AIF3_PB", "AIF4_PB"
  3964. };
  3965. static const char *const cdc_if_rx0_mux_text[] = {
  3966. "SLIM RX0", "I2S RX0"
  3967. };
  3968. static const char *const cdc_if_rx1_mux_text[] = {
  3969. "SLIM RX1", "I2S RX1"
  3970. };
  3971. static const char *const cdc_if_rx2_mux_text[] = {
  3972. "SLIM RX2", "I2S RX2"
  3973. };
  3974. static const char *const cdc_if_rx3_mux_text[] = {
  3975. "SLIM RX3", "I2S RX3"
  3976. };
  3977. static const char *const cdc_if_rx4_mux_text[] = {
  3978. "SLIM RX4", "I2S RX4"
  3979. };
  3980. static const char *const cdc_if_rx5_mux_text[] = {
  3981. "SLIM RX5", "I2S RX5"
  3982. };
  3983. static const char *const cdc_if_rx6_mux_text[] = {
  3984. "SLIM RX6", "I2S RX6"
  3985. };
  3986. static const char *const cdc_if_rx7_mux_text[] = {
  3987. "SLIM RX7", "I2S RX7"
  3988. };
  3989. static const char * const asrc2_mux_text[] = {
  3990. "ZERO", "ASRC_IN_SPKR1",
  3991. };
  3992. static const char * const asrc3_mux_text[] = {
  3993. "ZERO", "ASRC_IN_SPKR2",
  3994. };
  3995. static const char * const native_mux_text[] = {
  3996. "OFF", "ON",
  3997. };
  3998. static const char *const wdma3_port0_text[] = {
  3999. "RX_MIX_TX0", "DEC0"
  4000. };
  4001. static const char *const wdma3_port1_text[] = {
  4002. "RX_MIX_TX1", "DEC1"
  4003. };
  4004. static const char *const wdma3_port2_text[] = {
  4005. "RX_MIX_TX2", "DEC2"
  4006. };
  4007. static const char *const wdma3_port3_text[] = {
  4008. "RX_MIX_TX3", "DEC3"
  4009. };
  4010. static const char *const wdma3_port4_text[] = {
  4011. "RX_MIX_TX4", "DEC4"
  4012. };
  4013. static const char *const wdma3_port5_text[] = {
  4014. "RX_MIX_TX5", "DEC5"
  4015. };
  4016. static const char *const wdma3_port6_text[] = {
  4017. "RX_MIX_TX6", "DEC6"
  4018. };
  4019. static const char *const wdma3_ch_text[] = {
  4020. "PORT_0", "PORT_1", "PORT_2", "PORT_3", "PORT_4",
  4021. "PORT_5", "PORT_6", "PORT_7", "PORT_8",
  4022. };
  4023. static const struct snd_kcontrol_new aif4_vi_mixer[] = {
  4024. SOC_SINGLE_EXT("SPKR_VI_1", SND_SOC_NOPM, WCD9360_TX14, 1, 0,
  4025. pahu_vi_feed_mixer_get, pahu_vi_feed_mixer_put),
  4026. SOC_SINGLE_EXT("SPKR_VI_2", SND_SOC_NOPM, WCD9360_TX15, 1, 0,
  4027. pahu_vi_feed_mixer_get, pahu_vi_feed_mixer_put),
  4028. };
  4029. static const struct snd_kcontrol_new aif1_cap_mixer[] = {
  4030. SOC_SINGLE_EXT("SLIM TX0", SND_SOC_NOPM, WCD9360_TX0, 1, 0,
  4031. slim_tx_mixer_get, slim_tx_mixer_put),
  4032. SOC_SINGLE_EXT("SLIM TX1", SND_SOC_NOPM, WCD9360_TX1, 1, 0,
  4033. slim_tx_mixer_get, slim_tx_mixer_put),
  4034. SOC_SINGLE_EXT("SLIM TX2", SND_SOC_NOPM, WCD9360_TX2, 1, 0,
  4035. slim_tx_mixer_get, slim_tx_mixer_put),
  4036. SOC_SINGLE_EXT("SLIM TX3", SND_SOC_NOPM, WCD9360_TX3, 1, 0,
  4037. slim_tx_mixer_get, slim_tx_mixer_put),
  4038. SOC_SINGLE_EXT("SLIM TX4", SND_SOC_NOPM, WCD9360_TX4, 1, 0,
  4039. slim_tx_mixer_get, slim_tx_mixer_put),
  4040. SOC_SINGLE_EXT("SLIM TX5", SND_SOC_NOPM, WCD9360_TX5, 1, 0,
  4041. slim_tx_mixer_get, slim_tx_mixer_put),
  4042. SOC_SINGLE_EXT("SLIM TX6", SND_SOC_NOPM, WCD9360_TX6, 1, 0,
  4043. slim_tx_mixer_get, slim_tx_mixer_put),
  4044. SOC_SINGLE_EXT("SLIM TX7", SND_SOC_NOPM, WCD9360_TX7, 1, 0,
  4045. slim_tx_mixer_get, slim_tx_mixer_put),
  4046. SOC_SINGLE_EXT("SLIM TX8", SND_SOC_NOPM, WCD9360_TX8, 1, 0,
  4047. slim_tx_mixer_get, slim_tx_mixer_put),
  4048. SOC_SINGLE_EXT("SLIM TX9", SND_SOC_NOPM, WCD9360_TX9, 1, 0,
  4049. slim_tx_mixer_get, slim_tx_mixer_put),
  4050. SOC_SINGLE_EXT("SLIM TX10", SND_SOC_NOPM, WCD9360_TX10, 1, 0,
  4051. slim_tx_mixer_get, slim_tx_mixer_put),
  4052. SOC_SINGLE_EXT("SLIM TX11", SND_SOC_NOPM, WCD9360_TX11, 1, 0,
  4053. slim_tx_mixer_get, slim_tx_mixer_put),
  4054. SOC_SINGLE_EXT("SLIM TX13", SND_SOC_NOPM, WCD9360_TX13, 1, 0,
  4055. slim_tx_mixer_get, slim_tx_mixer_put),
  4056. };
  4057. static const struct snd_kcontrol_new aif2_cap_mixer[] = {
  4058. SOC_SINGLE_EXT("SLIM TX0", SND_SOC_NOPM, WCD9360_TX0, 1, 0,
  4059. slim_tx_mixer_get, slim_tx_mixer_put),
  4060. SOC_SINGLE_EXT("SLIM TX1", SND_SOC_NOPM, WCD9360_TX1, 1, 0,
  4061. slim_tx_mixer_get, slim_tx_mixer_put),
  4062. SOC_SINGLE_EXT("SLIM TX2", SND_SOC_NOPM, WCD9360_TX2, 1, 0,
  4063. slim_tx_mixer_get, slim_tx_mixer_put),
  4064. SOC_SINGLE_EXT("SLIM TX3", SND_SOC_NOPM, WCD9360_TX3, 1, 0,
  4065. slim_tx_mixer_get, slim_tx_mixer_put),
  4066. SOC_SINGLE_EXT("SLIM TX4", SND_SOC_NOPM, WCD9360_TX4, 1, 0,
  4067. slim_tx_mixer_get, slim_tx_mixer_put),
  4068. SOC_SINGLE_EXT("SLIM TX5", SND_SOC_NOPM, WCD9360_TX5, 1, 0,
  4069. slim_tx_mixer_get, slim_tx_mixer_put),
  4070. SOC_SINGLE_EXT("SLIM TX6", SND_SOC_NOPM, WCD9360_TX6, 1, 0,
  4071. slim_tx_mixer_get, slim_tx_mixer_put),
  4072. SOC_SINGLE_EXT("SLIM TX7", SND_SOC_NOPM, WCD9360_TX7, 1, 0,
  4073. slim_tx_mixer_get, slim_tx_mixer_put),
  4074. SOC_SINGLE_EXT("SLIM TX8", SND_SOC_NOPM, WCD9360_TX8, 1, 0,
  4075. slim_tx_mixer_get, slim_tx_mixer_put),
  4076. SOC_SINGLE_EXT("SLIM TX9", SND_SOC_NOPM, WCD9360_TX9, 1, 0,
  4077. slim_tx_mixer_get, slim_tx_mixer_put),
  4078. SOC_SINGLE_EXT("SLIM TX10", SND_SOC_NOPM, WCD9360_TX10, 1, 0,
  4079. slim_tx_mixer_get, slim_tx_mixer_put),
  4080. SOC_SINGLE_EXT("SLIM TX11", SND_SOC_NOPM, WCD9360_TX11, 1, 0,
  4081. slim_tx_mixer_get, slim_tx_mixer_put),
  4082. SOC_SINGLE_EXT("SLIM TX13", SND_SOC_NOPM, WCD9360_TX13, 1, 0,
  4083. slim_tx_mixer_get, slim_tx_mixer_put),
  4084. };
  4085. static const struct snd_kcontrol_new aif3_cap_mixer[] = {
  4086. SOC_SINGLE_EXT("SLIM TX0", SND_SOC_NOPM, WCD9360_TX0, 1, 0,
  4087. slim_tx_mixer_get, slim_tx_mixer_put),
  4088. SOC_SINGLE_EXT("SLIM TX1", SND_SOC_NOPM, WCD9360_TX1, 1, 0,
  4089. slim_tx_mixer_get, slim_tx_mixer_put),
  4090. SOC_SINGLE_EXT("SLIM TX2", SND_SOC_NOPM, WCD9360_TX2, 1, 0,
  4091. slim_tx_mixer_get, slim_tx_mixer_put),
  4092. SOC_SINGLE_EXT("SLIM TX3", SND_SOC_NOPM, WCD9360_TX3, 1, 0,
  4093. slim_tx_mixer_get, slim_tx_mixer_put),
  4094. SOC_SINGLE_EXT("SLIM TX4", SND_SOC_NOPM, WCD9360_TX4, 1, 0,
  4095. slim_tx_mixer_get, slim_tx_mixer_put),
  4096. SOC_SINGLE_EXT("SLIM TX5", SND_SOC_NOPM, WCD9360_TX5, 1, 0,
  4097. slim_tx_mixer_get, slim_tx_mixer_put),
  4098. SOC_SINGLE_EXT("SLIM TX6", SND_SOC_NOPM, WCD9360_TX6, 1, 0,
  4099. slim_tx_mixer_get, slim_tx_mixer_put),
  4100. SOC_SINGLE_EXT("SLIM TX7", SND_SOC_NOPM, WCD9360_TX7, 1, 0,
  4101. slim_tx_mixer_get, slim_tx_mixer_put),
  4102. SOC_SINGLE_EXT("SLIM TX8", SND_SOC_NOPM, WCD9360_TX8, 1, 0,
  4103. slim_tx_mixer_get, slim_tx_mixer_put),
  4104. SOC_SINGLE_EXT("SLIM TX9", SND_SOC_NOPM, WCD9360_TX9, 1, 0,
  4105. slim_tx_mixer_get, slim_tx_mixer_put),
  4106. SOC_SINGLE_EXT("SLIM TX10", SND_SOC_NOPM, WCD9360_TX10, 1, 0,
  4107. slim_tx_mixer_get, slim_tx_mixer_put),
  4108. SOC_SINGLE_EXT("SLIM TX11", SND_SOC_NOPM, WCD9360_TX11, 1, 0,
  4109. slim_tx_mixer_get, slim_tx_mixer_put),
  4110. SOC_SINGLE_EXT("SLIM TX13", SND_SOC_NOPM, WCD9360_TX13, 1, 0,
  4111. slim_tx_mixer_get, slim_tx_mixer_put),
  4112. };
  4113. static const struct snd_kcontrol_new aif4_mad_mixer[] = {
  4114. SOC_SINGLE_EXT("SLIM TX13", SND_SOC_NOPM, WCD9360_TX13, 1, 0,
  4115. slim_tx_mixer_get, slim_tx_mixer_put),
  4116. };
  4117. WCD_DAPM_ENUM_EXT(slim_rx0, SND_SOC_NOPM, 0, slim_rx_mux_text,
  4118. slim_rx_mux_get, slim_rx_mux_put);
  4119. WCD_DAPM_ENUM_EXT(slim_rx1, SND_SOC_NOPM, 0, slim_rx_mux_text,
  4120. slim_rx_mux_get, slim_rx_mux_put);
  4121. WCD_DAPM_ENUM_EXT(slim_rx2, SND_SOC_NOPM, 0, slim_rx_mux_text,
  4122. slim_rx_mux_get, slim_rx_mux_put);
  4123. WCD_DAPM_ENUM_EXT(slim_rx3, SND_SOC_NOPM, 0, slim_rx_mux_text,
  4124. slim_rx_mux_get, slim_rx_mux_put);
  4125. WCD_DAPM_ENUM_EXT(slim_rx4, SND_SOC_NOPM, 0, slim_rx_mux_text,
  4126. slim_rx_mux_get, slim_rx_mux_put);
  4127. WCD_DAPM_ENUM_EXT(slim_rx5, SND_SOC_NOPM, 0, slim_rx_mux_text,
  4128. slim_rx_mux_get, slim_rx_mux_put);
  4129. WCD_DAPM_ENUM_EXT(slim_rx6, SND_SOC_NOPM, 0, slim_rx_mux_text,
  4130. slim_rx_mux_get, slim_rx_mux_put);
  4131. WCD_DAPM_ENUM_EXT(slim_rx7, SND_SOC_NOPM, 0, slim_rx_mux_text,
  4132. slim_rx_mux_get, slim_rx_mux_put);
  4133. WCD_DAPM_ENUM(cdc_if_rx0, SND_SOC_NOPM, 0, cdc_if_rx0_mux_text);
  4134. WCD_DAPM_ENUM(cdc_if_rx1, SND_SOC_NOPM, 0, cdc_if_rx1_mux_text);
  4135. WCD_DAPM_ENUM(cdc_if_rx2, SND_SOC_NOPM, 0, cdc_if_rx2_mux_text);
  4136. WCD_DAPM_ENUM(cdc_if_rx3, SND_SOC_NOPM, 0, cdc_if_rx3_mux_text);
  4137. WCD_DAPM_ENUM(cdc_if_rx4, SND_SOC_NOPM, 0, cdc_if_rx4_mux_text);
  4138. WCD_DAPM_ENUM(cdc_if_rx5, SND_SOC_NOPM, 0, cdc_if_rx5_mux_text);
  4139. WCD_DAPM_ENUM(cdc_if_rx6, SND_SOC_NOPM, 0, cdc_if_rx6_mux_text);
  4140. WCD_DAPM_ENUM(cdc_if_rx7, SND_SOC_NOPM, 0, cdc_if_rx7_mux_text);
  4141. WCD_DAPM_ENUM(rx_int0_2, WCD9360_CDC_RX_INP_MUX_RX_INT0_CFG1, 0,
  4142. rx_int0_7_mix_mux_text);
  4143. WCD_DAPM_ENUM(rx_int7_2, WCD9360_CDC_RX_INP_MUX_RX_INT7_CFG1, 0,
  4144. rx_int0_7_mix_mux_text);
  4145. WCD_DAPM_ENUM(rx_int8_2, WCD9360_CDC_RX_INP_MUX_RX_INT8_CFG1, 0,
  4146. rx_int_mix_mux_text);
  4147. WCD_DAPM_ENUM(rx_int9_2, WCD9360_CDC_RX_INP_MUX_RX_INT9_CFG1, 0,
  4148. rx_int0_7_mix_mux_text);
  4149. WCD_DAPM_ENUM(rx_int0_1_mix_inp0, WCD9360_CDC_RX_INP_MUX_RX_INT0_CFG0, 0,
  4150. rx_prim_mix_text);
  4151. WCD_DAPM_ENUM(rx_int0_1_mix_inp1, WCD9360_CDC_RX_INP_MUX_RX_INT0_CFG0, 4,
  4152. rx_prim_mix_text);
  4153. WCD_DAPM_ENUM(rx_int0_1_mix_inp2, WCD9360_CDC_RX_INP_MUX_RX_INT0_CFG1, 4,
  4154. rx_prim_mix_text);
  4155. WCD_DAPM_ENUM(rx_int7_1_mix_inp0, WCD9360_CDC_RX_INP_MUX_RX_INT7_CFG0, 0,
  4156. rx_prim_mix_text);
  4157. WCD_DAPM_ENUM(rx_int7_1_mix_inp1, WCD9360_CDC_RX_INP_MUX_RX_INT7_CFG0, 4,
  4158. rx_prim_mix_text);
  4159. WCD_DAPM_ENUM(rx_int7_1_mix_inp2, WCD9360_CDC_RX_INP_MUX_RX_INT7_CFG1, 4,
  4160. rx_prim_mix_text);
  4161. WCD_DAPM_ENUM(rx_int8_1_mix_inp0, WCD9360_CDC_RX_INP_MUX_RX_INT8_CFG0, 0,
  4162. rx_prim_mix_text);
  4163. WCD_DAPM_ENUM(rx_int8_1_mix_inp1, WCD9360_CDC_RX_INP_MUX_RX_INT8_CFG0, 4,
  4164. rx_prim_mix_text);
  4165. WCD_DAPM_ENUM(rx_int8_1_mix_inp2, WCD9360_CDC_RX_INP_MUX_RX_INT8_CFG1, 4,
  4166. rx_prim_mix_text);
  4167. WCD_DAPM_ENUM(rx_int9_1_mix_inp0, WCD9360_CDC_RX_INP_MUX_RX_INT9_CFG0, 0,
  4168. rx_prim_mix_text);
  4169. WCD_DAPM_ENUM(rx_int9_1_mix_inp1, WCD9360_CDC_RX_INP_MUX_RX_INT9_CFG0, 4,
  4170. rx_prim_mix_text);
  4171. WCD_DAPM_ENUM(rx_int9_1_mix_inp2, WCD9360_CDC_RX_INP_MUX_RX_INT9_CFG1, 4,
  4172. rx_prim_mix_text);
  4173. WCD_DAPM_ENUM(rx_int0_mix2_inp, WCD9360_CDC_RX_INP_MUX_SIDETONE_SRC_CFG0, 0,
  4174. rx_sidetone_mix_text);
  4175. WCD_DAPM_ENUM(rx_int7_mix2_inp, WCD9360_CDC_RX_INP_MUX_SIDETONE_SRC_CFG1, 2,
  4176. rx_sidetone_mix_text);
  4177. WCD_DAPM_ENUM(rx_int9_mix2_inp, WCD9360_CDC_RX_INP_MUX_SIDETONE_SRC_CFG1, 4,
  4178. rx_sidetone_mix_text);
  4179. WCD_DAPM_ENUM(tx_adc_mux10, WCD9360_CDC_TX_INP_MUX_ADC_MUX1_CFG1, 4,
  4180. adc_mux_text);
  4181. WCD_DAPM_ENUM(tx_adc_mux11, WCD9360_CDC_TX_INP_MUX_ADC_MUX2_CFG1, 4,
  4182. adc_mux_text);
  4183. WCD_DAPM_ENUM(tx_dmic_mux0, WCD9360_CDC_TX_INP_MUX_ADC_MUX0_CFG0, 3,
  4184. dmic_mux_text);
  4185. WCD_DAPM_ENUM(tx_dmic_mux1, WCD9360_CDC_TX_INP_MUX_ADC_MUX1_CFG0, 3,
  4186. dmic_mux_text);
  4187. WCD_DAPM_ENUM(tx_dmic_mux2, WCD9360_CDC_TX_INP_MUX_ADC_MUX2_CFG0, 3,
  4188. dmic_mux_text);
  4189. WCD_DAPM_ENUM(tx_dmic_mux3, WCD9360_CDC_TX_INP_MUX_ADC_MUX3_CFG0, 3,
  4190. dmic_mux_text);
  4191. WCD_DAPM_ENUM(tx_dmic_mux4, WCD9360_CDC_TX_INP_MUX_ADC_MUX4_CFG0, 3,
  4192. dmic_mux_text);
  4193. WCD_DAPM_ENUM(tx_dmic_mux5, WCD9360_CDC_TX_INP_MUX_ADC_MUX5_CFG0, 3,
  4194. dmic_mux_text);
  4195. WCD_DAPM_ENUM(tx_dmic_mux6, WCD9360_CDC_TX_INP_MUX_ADC_MUX6_CFG0, 3,
  4196. dmic_mux_text);
  4197. WCD_DAPM_ENUM(tx_dmic_mux7, WCD9360_CDC_TX_INP_MUX_ADC_MUX7_CFG0, 3,
  4198. dmic_mux_text);
  4199. WCD_DAPM_ENUM(tx_dmic_mux8, WCD9360_CDC_TX_INP_MUX_ADC_MUX8_CFG0, 3,
  4200. dmic_mux_text);
  4201. WCD_DAPM_ENUM(tx_dmic_mux10, WCD9360_CDC_TX_INP_MUX_ADC_MUX10_CFG0, 3,
  4202. dmic_mux_text);
  4203. WCD_DAPM_ENUM(tx_dmic_mux11, WCD9360_CDC_TX_INP_MUX_ADC_MUX11_CFG0, 3,
  4204. dmic_mux_text);
  4205. WCD_DAPM_ENUM(tx_amic_mux0, WCD9360_CDC_TX_INP_MUX_ADC_MUX0_CFG0, 0,
  4206. amic_mux_text);
  4207. WCD_DAPM_ENUM(tx_amic_mux1, WCD9360_CDC_TX_INP_MUX_ADC_MUX1_CFG0, 0,
  4208. amic_mux_text);
  4209. WCD_DAPM_ENUM(tx_amic_mux2, WCD9360_CDC_TX_INP_MUX_ADC_MUX2_CFG0, 0,
  4210. amic_mux_text);
  4211. WCD_DAPM_ENUM(tx_amic_mux3, WCD9360_CDC_TX_INP_MUX_ADC_MUX3_CFG0, 0,
  4212. amic_mux_text);
  4213. WCD_DAPM_ENUM(tx_amic_mux4, WCD9360_CDC_TX_INP_MUX_ADC_MUX4_CFG0, 0,
  4214. amic_mux_text);
  4215. WCD_DAPM_ENUM(tx_amic_mux5, WCD9360_CDC_TX_INP_MUX_ADC_MUX5_CFG0, 0,
  4216. amic_mux_text);
  4217. WCD_DAPM_ENUM(tx_amic_mux6, WCD9360_CDC_TX_INP_MUX_ADC_MUX6_CFG0, 0,
  4218. amic_mux_text);
  4219. WCD_DAPM_ENUM(tx_amic_mux7, WCD9360_CDC_TX_INP_MUX_ADC_MUX7_CFG0, 0,
  4220. amic_mux_text);
  4221. WCD_DAPM_ENUM(tx_amic_mux8, WCD9360_CDC_TX_INP_MUX_ADC_MUX8_CFG0, 0,
  4222. amic_mux_text);
  4223. WCD_DAPM_ENUM(tx_amic_mux10, WCD9360_CDC_TX_INP_MUX_ADC_MUX10_CFG0, 0,
  4224. amic_mux_text);
  4225. WCD_DAPM_ENUM(tx_amic_mux11, WCD9360_CDC_TX_INP_MUX_ADC_MUX11_CFG0, 0,
  4226. amic_mux_text);
  4227. WCD_DAPM_ENUM(tx_adc2_in, WCD9360_ANA_AMIC_INPUT_SWITCH_CTL, 7, adc2_in_text);
  4228. WCD_DAPM_ENUM(tx_adc4_in, WCD9360_ANA_AMIC_INPUT_SWITCH_CTL, 6, adc4_in_text);
  4229. WCD_DAPM_ENUM(cdc_if_tx0, WCD9360_CDC_IF_ROUTER_TX_MUX_CFG0, 0,
  4230. cdc_if_tx0_mux_text);
  4231. WCD_DAPM_ENUM(cdc_if_tx1, WCD9360_CDC_IF_ROUTER_TX_MUX_CFG0, 2,
  4232. cdc_if_tx1_mux_text);
  4233. WCD_DAPM_ENUM(cdc_if_tx2, WCD9360_CDC_IF_ROUTER_TX_MUX_CFG0, 4,
  4234. cdc_if_tx2_mux_text);
  4235. WCD_DAPM_ENUM(cdc_if_tx3, WCD9360_CDC_IF_ROUTER_TX_MUX_CFG0, 6,
  4236. cdc_if_tx3_mux_text);
  4237. WCD_DAPM_ENUM(cdc_if_tx4, WCD9360_CDC_IF_ROUTER_TX_MUX_CFG1, 0,
  4238. cdc_if_tx4_mux_text);
  4239. WCD_DAPM_ENUM(cdc_if_tx5, WCD9360_CDC_IF_ROUTER_TX_MUX_CFG1, 2,
  4240. cdc_if_tx5_mux_text);
  4241. WCD_DAPM_ENUM(cdc_if_tx6, WCD9360_CDC_IF_ROUTER_TX_MUX_CFG1, 4,
  4242. cdc_if_tx6_mux_text);
  4243. WCD_DAPM_ENUM(cdc_if_tx7, WCD9360_CDC_IF_ROUTER_TX_MUX_CFG1, 6,
  4244. cdc_if_tx7_mux_text);
  4245. WCD_DAPM_ENUM(cdc_if_tx8, WCD9360_CDC_IF_ROUTER_TX_MUX_CFG2, 0,
  4246. cdc_if_tx8_mux_text);
  4247. WCD_DAPM_ENUM(cdc_if_tx9, WCD9360_CDC_IF_ROUTER_TX_MUX_CFG2, 2,
  4248. cdc_if_tx9_mux_text);
  4249. WCD_DAPM_ENUM(cdc_if_tx10, WCD9360_CDC_IF_ROUTER_TX_MUX_CFG2, 4,
  4250. cdc_if_tx10_mux_text);
  4251. WCD_DAPM_ENUM(cdc_if_tx11_inp1, WCD9360_CDC_IF_ROUTER_TX_MUX_CFG3, 0,
  4252. cdc_if_tx11_inp1_mux_text);
  4253. WCD_DAPM_ENUM(cdc_if_tx11, WCD9360_DATA_HUB_SB_TX11_INP_CFG, 0,
  4254. cdc_if_tx11_mux_text);
  4255. WCD_DAPM_ENUM(cdc_if_tx13_inp1, WCD9360_CDC_IF_ROUTER_TX_MUX_CFG3, 4,
  4256. cdc_if_tx13_inp1_mux_text);
  4257. WCD_DAPM_ENUM(cdc_if_tx13, WCD9360_DATA_HUB_SB_TX13_INP_CFG, 0,
  4258. cdc_if_tx13_mux_text);
  4259. WCD_DAPM_ENUM(rx_mix_tx0, WCD9360_CDC_RX_INP_MUX_RX_MIX_CFG0, 0,
  4260. rx_echo_mux_text);
  4261. WCD_DAPM_ENUM(rx_mix_tx1, WCD9360_CDC_RX_INP_MUX_RX_MIX_CFG0, 4,
  4262. rx_echo_mux_text);
  4263. WCD_DAPM_ENUM(rx_mix_tx2, WCD9360_CDC_RX_INP_MUX_RX_MIX_CFG1, 0,
  4264. rx_echo_mux_text);
  4265. WCD_DAPM_ENUM(rx_mix_tx3, WCD9360_CDC_RX_INP_MUX_RX_MIX_CFG1, 4,
  4266. rx_echo_mux_text);
  4267. WCD_DAPM_ENUM(rx_mix_tx4, WCD9360_CDC_RX_INP_MUX_RX_MIX_CFG2, 0,
  4268. rx_echo_mux_text);
  4269. WCD_DAPM_ENUM(rx_mix_tx5, WCD9360_CDC_RX_INP_MUX_RX_MIX_CFG2, 4,
  4270. rx_echo_mux_text);
  4271. WCD_DAPM_ENUM(rx_mix_tx6, WCD9360_CDC_RX_INP_MUX_RX_MIX_CFG3, 0,
  4272. rx_echo_mux_text);
  4273. WCD_DAPM_ENUM(rx_mix_tx7, WCD9360_CDC_RX_INP_MUX_RX_MIX_CFG3, 4,
  4274. rx_echo_mux_text);
  4275. WCD_DAPM_ENUM(rx_mix_tx8, WCD9360_CDC_RX_INP_MUX_RX_MIX_CFG4, 0,
  4276. rx_echo_mux_text);
  4277. WCD_DAPM_ENUM(iir0_inp0, WCD9360_CDC_SIDETONE_IIR_INP_MUX_IIR0_MIX_CFG0, 0,
  4278. iir_inp_mux_text);
  4279. WCD_DAPM_ENUM(iir0_inp1, WCD9360_CDC_SIDETONE_IIR_INP_MUX_IIR0_MIX_CFG1, 0,
  4280. iir_inp_mux_text);
  4281. WCD_DAPM_ENUM(iir0_inp2, WCD9360_CDC_SIDETONE_IIR_INP_MUX_IIR0_MIX_CFG2, 0,
  4282. iir_inp_mux_text);
  4283. WCD_DAPM_ENUM(iir0_inp3, WCD9360_CDC_SIDETONE_IIR_INP_MUX_IIR0_MIX_CFG3, 0,
  4284. iir_inp_mux_text);
  4285. WCD_DAPM_ENUM(rx_int0_1_interp, SND_SOC_NOPM, 0, rx_int0_1_interp_mux_text);
  4286. WCD_DAPM_ENUM(rx_int7_1_interp, SND_SOC_NOPM, 0, rx_int7_1_interp_mux_text);
  4287. WCD_DAPM_ENUM(rx_int8_1_interp, SND_SOC_NOPM, 0, rx_int8_1_interp_mux_text);
  4288. WCD_DAPM_ENUM(rx_int9_1_interp, SND_SOC_NOPM, 0, rx_int9_1_interp_mux_text);
  4289. WCD_DAPM_ENUM(rx_int0_2_interp, SND_SOC_NOPM, 0, rx_int0_2_interp_mux_text);
  4290. WCD_DAPM_ENUM(rx_int7_2_interp, SND_SOC_NOPM, 0, rx_int7_2_interp_mux_text);
  4291. WCD_DAPM_ENUM(rx_int8_2_interp, SND_SOC_NOPM, 0, rx_int8_2_interp_mux_text);
  4292. WCD_DAPM_ENUM(rx_int9_2_interp, SND_SOC_NOPM, 0, rx_int9_2_interp_mux_text);
  4293. WCD_DAPM_ENUM(mad_sel, WCD9360_CPE_SS_SVA_CFG, 0,
  4294. mad_sel_txt);
  4295. WCD_DAPM_ENUM(mad_inp_mux, WCD9360_CPE_SS_SVA_CFG, 2,
  4296. mad_inp_mux_txt);
  4297. WCD_DAPM_ENUM_EXT(rx_int0_dem_inp, WCD9360_CDC_RX0_RX_PATH_SEC0, 0,
  4298. rx_int_dem_inp_mux_text, snd_soc_dapm_get_enum_double,
  4299. pahu_int_dem_inp_mux_put);
  4300. WCD_DAPM_ENUM_EXT(rx_int9_dem_inp, WCD9360_CDC_RX9_RX_PATH_SEC0, 0,
  4301. rx_int_dem_inp_mux_text, snd_soc_dapm_get_enum_double,
  4302. pahu_int_dem_inp_mux_put);
  4303. WCD_DAPM_ENUM_EXT(tx_adc_mux0, WCD9360_CDC_TX_INP_MUX_ADC_MUX0_CFG1, 0,
  4304. adc_mux_text, snd_soc_dapm_get_enum_double, pahu_dec_enum_put);
  4305. WCD_DAPM_ENUM_EXT(tx_adc_mux1, WCD9360_CDC_TX_INP_MUX_ADC_MUX1_CFG1, 0,
  4306. adc_mux_text, snd_soc_dapm_get_enum_double, pahu_dec_enum_put);
  4307. WCD_DAPM_ENUM_EXT(tx_adc_mux2, WCD9360_CDC_TX_INP_MUX_ADC_MUX2_CFG1, 0,
  4308. adc_mux_text, snd_soc_dapm_get_enum_double, pahu_dec_enum_put);
  4309. WCD_DAPM_ENUM_EXT(tx_adc_mux3, WCD9360_CDC_TX_INP_MUX_ADC_MUX3_CFG1, 0,
  4310. adc_mux_text, snd_soc_dapm_get_enum_double, pahu_dec_enum_put);
  4311. WCD_DAPM_ENUM_EXT(tx_adc_mux4, WCD9360_CDC_TX_INP_MUX_ADC_MUX0_CFG1, 2,
  4312. adc_mux_text, snd_soc_dapm_get_enum_double, pahu_dec_enum_put);
  4313. WCD_DAPM_ENUM_EXT(tx_adc_mux5, WCD9360_CDC_TX_INP_MUX_ADC_MUX1_CFG1, 2,
  4314. adc_mux_text, snd_soc_dapm_get_enum_double, pahu_dec_enum_put);
  4315. WCD_DAPM_ENUM_EXT(tx_adc_mux6, WCD9360_CDC_TX_INP_MUX_ADC_MUX2_CFG1, 2,
  4316. adc_mux_text, snd_soc_dapm_get_enum_double, pahu_dec_enum_put);
  4317. WCD_DAPM_ENUM_EXT(tx_adc_mux7, WCD9360_CDC_TX_INP_MUX_ADC_MUX3_CFG1, 2,
  4318. adc_mux_text, snd_soc_dapm_get_enum_double, pahu_dec_enum_put);
  4319. WCD_DAPM_ENUM_EXT(tx_adc_mux8, WCD9360_CDC_TX_INP_MUX_ADC_MUX0_CFG1, 4,
  4320. adc_mux_text, snd_soc_dapm_get_enum_double, pahu_dec_enum_put);
  4321. WCD_DAPM_ENUM(asrc2, WCD9360_CDC_RX_INP_MUX_SPLINE_ASRC_CFG0, 4,
  4322. asrc2_mux_text);
  4323. WCD_DAPM_ENUM(asrc3, WCD9360_CDC_RX_INP_MUX_SPLINE_ASRC_CFG0, 6,
  4324. asrc3_mux_text);
  4325. WCD_DAPM_ENUM(int7_2_native, SND_SOC_NOPM, 0, native_mux_text);
  4326. WCD_DAPM_ENUM(int8_2_native, SND_SOC_NOPM, 0, native_mux_text);
  4327. WCD_DAPM_ENUM(anc0_fb, WCD9360_CDC_RX_INP_MUX_ANC_CFG0, 0, anc0_fb_mux_text);
  4328. WCD_DAPM_ENUM(wdma3_port0, WCD9360_DMA_WDMA3_PRT_CFG, 0, wdma3_port0_text);
  4329. WCD_DAPM_ENUM(wdma3_port1, WCD9360_DMA_WDMA3_PRT_CFG, 1, wdma3_port1_text);
  4330. WCD_DAPM_ENUM(wdma3_port2, WCD9360_DMA_WDMA3_PRT_CFG, 2, wdma3_port2_text);
  4331. WCD_DAPM_ENUM(wdma3_port3, WCD9360_DMA_WDMA3_PRT_CFG, 3, wdma3_port3_text);
  4332. WCD_DAPM_ENUM(wdma3_port4, WCD9360_DMA_WDMA3_PRT_CFG, 4, wdma3_port4_text);
  4333. WCD_DAPM_ENUM(wdma3_port5, WCD9360_DMA_WDMA3_PRT_CFG, 5, wdma3_port5_text);
  4334. WCD_DAPM_ENUM(wdma3_port6, WCD9360_DMA_WDMA3_PRT_CFG, 6, wdma3_port6_text);
  4335. WCD_DAPM_ENUM(wdma3_ch0, WCD9360_DMA_CH_0_1_CFG_WDMA_3, 0, wdma3_ch_text);
  4336. WCD_DAPM_ENUM(wdma3_ch1, WCD9360_DMA_CH_0_1_CFG_WDMA_3, 4, wdma3_ch_text);
  4337. WCD_DAPM_ENUM(wdma3_ch2, WCD9360_DMA_CH_2_3_CFG_WDMA_3, 0, wdma3_ch_text);
  4338. WCD_DAPM_ENUM(wdma3_ch3, WCD9360_DMA_CH_2_3_CFG_WDMA_3, 4, wdma3_ch_text);
  4339. static const struct snd_kcontrol_new anc_ear_switch =
  4340. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0);
  4341. static const struct snd_kcontrol_new anc_ear_spkr_switch =
  4342. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0);
  4343. static const struct snd_kcontrol_new anc_spkr_pa_switch =
  4344. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0);
  4345. static const struct snd_kcontrol_new mad_cpe1_switch =
  4346. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0);
  4347. static const struct snd_kcontrol_new mad_cpe2_switch =
  4348. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0);
  4349. static const struct snd_kcontrol_new mad_brdcst_switch =
  4350. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0);
  4351. static const struct snd_kcontrol_new adc_us_mux0_switch =
  4352. SOC_DAPM_SINGLE("US_Switch", SND_SOC_NOPM, 0, 1, 0);
  4353. static const struct snd_kcontrol_new adc_us_mux1_switch =
  4354. SOC_DAPM_SINGLE("US_Switch", SND_SOC_NOPM, 0, 1, 0);
  4355. static const struct snd_kcontrol_new adc_us_mux2_switch =
  4356. SOC_DAPM_SINGLE("US_Switch", SND_SOC_NOPM, 0, 1, 0);
  4357. static const struct snd_kcontrol_new adc_us_mux3_switch =
  4358. SOC_DAPM_SINGLE("US_Switch", SND_SOC_NOPM, 0, 1, 0);
  4359. static const struct snd_kcontrol_new adc_us_mux4_switch =
  4360. SOC_DAPM_SINGLE("US_Switch", SND_SOC_NOPM, 0, 1, 0);
  4361. static const struct snd_kcontrol_new adc_us_mux5_switch =
  4362. SOC_DAPM_SINGLE("US_Switch", SND_SOC_NOPM, 0, 1, 0);
  4363. static const struct snd_kcontrol_new adc_us_mux6_switch =
  4364. SOC_DAPM_SINGLE("US_Switch", SND_SOC_NOPM, 0, 1, 0);
  4365. static const struct snd_kcontrol_new adc_us_mux7_switch =
  4366. SOC_DAPM_SINGLE("US_Switch", SND_SOC_NOPM, 0, 1, 0);
  4367. static const struct snd_kcontrol_new adc_us_mux8_switch =
  4368. SOC_DAPM_SINGLE("US_Switch", SND_SOC_NOPM, 0, 1, 0);
  4369. static const struct snd_kcontrol_new wdma3_onoff_switch =
  4370. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0);
  4371. static const struct snd_soc_dapm_widget pahu_dapm_widgets[] = {
  4372. SND_SOC_DAPM_AIF_IN_E("AIF1 PB", "AIF1 Playback", 0, SND_SOC_NOPM,
  4373. AIF1_PB, 0, pahu_codec_enable_slimrx,
  4374. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4375. SND_SOC_DAPM_AIF_IN_E("AIF2 PB", "AIF2 Playback", 0, SND_SOC_NOPM,
  4376. AIF2_PB, 0, pahu_codec_enable_slimrx,
  4377. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4378. SND_SOC_DAPM_AIF_IN_E("AIF3 PB", "AIF3 Playback", 0, SND_SOC_NOPM,
  4379. AIF3_PB, 0, pahu_codec_enable_slimrx,
  4380. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4381. SND_SOC_DAPM_AIF_IN_E("AIF4 PB", "AIF4 Playback", 0, SND_SOC_NOPM,
  4382. AIF4_PB, 0, pahu_codec_enable_slimrx,
  4383. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4384. WCD_DAPM_MUX("SLIM RX0 MUX", WCD9360_RX0, slim_rx0),
  4385. WCD_DAPM_MUX("SLIM RX1 MUX", WCD9360_RX1, slim_rx1),
  4386. WCD_DAPM_MUX("SLIM RX2 MUX", WCD9360_RX2, slim_rx2),
  4387. WCD_DAPM_MUX("SLIM RX3 MUX", WCD9360_RX3, slim_rx3),
  4388. WCD_DAPM_MUX("SLIM RX4 MUX", WCD9360_RX4, slim_rx4),
  4389. WCD_DAPM_MUX("SLIM RX5 MUX", WCD9360_RX5, slim_rx5),
  4390. WCD_DAPM_MUX("SLIM RX6 MUX", WCD9360_RX6, slim_rx6),
  4391. WCD_DAPM_MUX("SLIM RX7 MUX", WCD9360_RX7, slim_rx7),
  4392. SND_SOC_DAPM_MIXER("SLIM RX0", SND_SOC_NOPM, 0, 0, NULL, 0),
  4393. SND_SOC_DAPM_MIXER("SLIM RX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  4394. SND_SOC_DAPM_MIXER("SLIM RX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  4395. SND_SOC_DAPM_MIXER("SLIM RX3", SND_SOC_NOPM, 0, 0, NULL, 0),
  4396. SND_SOC_DAPM_MIXER("SLIM RX4", SND_SOC_NOPM, 0, 0, NULL, 0),
  4397. SND_SOC_DAPM_MIXER("SLIM RX5", SND_SOC_NOPM, 0, 0, NULL, 0),
  4398. SND_SOC_DAPM_MIXER("SLIM RX6", SND_SOC_NOPM, 0, 0, NULL, 0),
  4399. SND_SOC_DAPM_MIXER("SLIM RX7", SND_SOC_NOPM, 0, 0, NULL, 0),
  4400. WCD_DAPM_MUX("CDC_IF RX0 MUX", WCD9360_RX0, cdc_if_rx0),
  4401. WCD_DAPM_MUX("CDC_IF RX1 MUX", WCD9360_RX1, cdc_if_rx1),
  4402. WCD_DAPM_MUX("CDC_IF RX2 MUX", WCD9360_RX2, cdc_if_rx2),
  4403. WCD_DAPM_MUX("CDC_IF RX3 MUX", WCD9360_RX3, cdc_if_rx3),
  4404. WCD_DAPM_MUX("CDC_IF RX4 MUX", WCD9360_RX4, cdc_if_rx4),
  4405. WCD_DAPM_MUX("CDC_IF RX5 MUX", WCD9360_RX5, cdc_if_rx5),
  4406. WCD_DAPM_MUX("CDC_IF RX6 MUX", WCD9360_RX6, cdc_if_rx6),
  4407. WCD_DAPM_MUX("CDC_IF RX7 MUX", WCD9360_RX7, cdc_if_rx7),
  4408. SND_SOC_DAPM_MUX_E("RX INT0_2 MUX", SND_SOC_NOPM, INTERP_EAR, 0,
  4409. &rx_int0_2_mux, pahu_codec_enable_mix_path,
  4410. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  4411. SND_SOC_DAPM_POST_PMD),
  4412. SND_SOC_DAPM_MUX_E("RX INT7_2 MUX", SND_SOC_NOPM, INTERP_SPKR1, 0,
  4413. &rx_int7_2_mux, pahu_codec_enable_mix_path,
  4414. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  4415. SND_SOC_DAPM_POST_PMD),
  4416. SND_SOC_DAPM_MUX_E("RX INT8_2 MUX", SND_SOC_NOPM, INTERP_SPKR2, 0,
  4417. &rx_int8_2_mux, pahu_codec_enable_mix_path,
  4418. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  4419. SND_SOC_DAPM_POST_PMD),
  4420. SND_SOC_DAPM_MUX_E("RX INT9_2 MUX", SND_SOC_NOPM, INTERP_AUX, 0,
  4421. &rx_int9_2_mux, pahu_codec_enable_mix_path,
  4422. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  4423. SND_SOC_DAPM_POST_PMD),
  4424. WCD_DAPM_MUX("RX INT0_1 MIX1 INP0", 0, rx_int0_1_mix_inp0),
  4425. WCD_DAPM_MUX("RX INT0_1 MIX1 INP1", 0, rx_int0_1_mix_inp1),
  4426. WCD_DAPM_MUX("RX INT0_1 MIX1 INP2", 0, rx_int0_1_mix_inp2),
  4427. SND_SOC_DAPM_MUX_E("RX INT7_1 MIX1 INP0", SND_SOC_NOPM, 0, 0,
  4428. &rx_int7_1_mix_inp0_mux, pahu_codec_enable_swr,
  4429. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  4430. SND_SOC_DAPM_MUX_E("RX INT7_1 MIX1 INP1", SND_SOC_NOPM, 0, 0,
  4431. &rx_int7_1_mix_inp1_mux, pahu_codec_enable_swr,
  4432. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  4433. SND_SOC_DAPM_MUX_E("RX INT7_1 MIX1 INP2", SND_SOC_NOPM, 0, 0,
  4434. &rx_int7_1_mix_inp2_mux, pahu_codec_enable_swr,
  4435. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  4436. SND_SOC_DAPM_MUX_E("RX INT8_1 MIX1 INP0", SND_SOC_NOPM, 0, 0,
  4437. &rx_int8_1_mix_inp0_mux, pahu_codec_enable_swr,
  4438. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  4439. SND_SOC_DAPM_MUX_E("RX INT8_1 MIX1 INP1", SND_SOC_NOPM, 0, 0,
  4440. &rx_int8_1_mix_inp1_mux, pahu_codec_enable_swr,
  4441. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  4442. SND_SOC_DAPM_MUX_E("RX INT8_1 MIX1 INP2", SND_SOC_NOPM, 0, 0,
  4443. &rx_int8_1_mix_inp2_mux, pahu_codec_enable_swr,
  4444. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  4445. WCD_DAPM_MUX("RX INT9_1 MIX1 INP0", 0, rx_int9_1_mix_inp0),
  4446. WCD_DAPM_MUX("RX INT9_1 MIX1 INP1", 0, rx_int9_1_mix_inp1),
  4447. WCD_DAPM_MUX("RX INT9_1 MIX1 INP2", 0, rx_int9_1_mix_inp2),
  4448. SND_SOC_DAPM_MIXER("RX INT0_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  4449. SND_SOC_DAPM_MIXER("RX INT0 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
  4450. SND_SOC_DAPM_MIXER("RX INT7_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  4451. SND_SOC_DAPM_MIXER("RX INT7 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
  4452. SND_SOC_DAPM_MIXER("RX INT8_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  4453. SND_SOC_DAPM_MIXER("RX INT8 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
  4454. SND_SOC_DAPM_MIXER("RX INT9_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  4455. SND_SOC_DAPM_MIXER("RX INT9 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
  4456. SND_SOC_DAPM_MIXER("RX INT0 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  4457. SND_SOC_DAPM_MIXER("RX INT7 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  4458. SND_SOC_DAPM_MIXER("RX INT9 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  4459. SND_SOC_DAPM_MIXER_E("RX INT7 CHAIN", SND_SOC_NOPM, 0, 0,
  4460. NULL, 0, pahu_codec_spk_boost_event,
  4461. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  4462. SND_SOC_DAPM_MIXER_E("RX INT8 CHAIN", SND_SOC_NOPM, 0, 0,
  4463. NULL, 0, pahu_codec_spk_boost_event,
  4464. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  4465. SND_SOC_DAPM_MUX_E("RX INT0 MIX2 INP", SND_SOC_NOPM, INTERP_EAR,
  4466. 0, &rx_int0_mix2_inp_mux, pahu_codec_enable_rx_path_clk,
  4467. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  4468. SND_SOC_DAPM_MUX_E("RX INT7 MIX2 INP", SND_SOC_NOPM, INTERP_SPKR1,
  4469. 0, &rx_int7_mix2_inp_mux, pahu_codec_enable_rx_path_clk,
  4470. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  4471. SND_SOC_DAPM_MUX_E("RX INT9 MIX2 INP", SND_SOC_NOPM, INTERP_AUX,
  4472. 0, &rx_int9_mix2_inp_mux, pahu_codec_enable_rx_path_clk,
  4473. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  4474. WCD_DAPM_MUX("CDC_IF TX0 MUX", WCD9360_TX0, cdc_if_tx0),
  4475. WCD_DAPM_MUX("CDC_IF TX1 MUX", WCD9360_TX1, cdc_if_tx1),
  4476. WCD_DAPM_MUX("CDC_IF TX2 MUX", WCD9360_TX2, cdc_if_tx2),
  4477. WCD_DAPM_MUX("CDC_IF TX3 MUX", WCD9360_TX3, cdc_if_tx3),
  4478. WCD_DAPM_MUX("CDC_IF TX4 MUX", WCD9360_TX4, cdc_if_tx4),
  4479. WCD_DAPM_MUX("CDC_IF TX5 MUX", WCD9360_TX5, cdc_if_tx5),
  4480. WCD_DAPM_MUX("CDC_IF TX6 MUX", WCD9360_TX6, cdc_if_tx6),
  4481. WCD_DAPM_MUX("CDC_IF TX7 MUX", WCD9360_TX7, cdc_if_tx7),
  4482. WCD_DAPM_MUX("CDC_IF TX8 MUX", WCD9360_TX8, cdc_if_tx8),
  4483. WCD_DAPM_MUX("CDC_IF TX9 MUX", WCD9360_TX9, cdc_if_tx9),
  4484. WCD_DAPM_MUX("CDC_IF TX10 MUX", WCD9360_TX10, cdc_if_tx10),
  4485. WCD_DAPM_MUX("CDC_IF TX11 MUX", WCD9360_TX11, cdc_if_tx11),
  4486. WCD_DAPM_MUX("CDC_IF TX11 INP1 MUX", WCD9360_TX11, cdc_if_tx11_inp1),
  4487. WCD_DAPM_MUX("CDC_IF TX13 MUX", WCD9360_TX13, cdc_if_tx13),
  4488. WCD_DAPM_MUX("CDC_IF TX13 INP1 MUX", WCD9360_TX13, cdc_if_tx13_inp1),
  4489. SND_SOC_DAPM_MUX_E("ADC MUX0", WCD9360_CDC_TX0_TX_PATH_CTL, 5, 0,
  4490. &tx_adc_mux0_mux, pahu_codec_enable_dec,
  4491. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  4492. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  4493. SND_SOC_DAPM_MUX_E("ADC MUX1", WCD9360_CDC_TX1_TX_PATH_CTL, 5, 0,
  4494. &tx_adc_mux1_mux, pahu_codec_enable_dec,
  4495. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  4496. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  4497. SND_SOC_DAPM_MUX_E("ADC MUX2", WCD9360_CDC_TX2_TX_PATH_CTL, 5, 0,
  4498. &tx_adc_mux2_mux, pahu_codec_enable_dec,
  4499. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  4500. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  4501. SND_SOC_DAPM_MUX_E("ADC MUX3", WCD9360_CDC_TX3_TX_PATH_CTL, 5, 0,
  4502. &tx_adc_mux3_mux, pahu_codec_enable_dec,
  4503. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  4504. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  4505. SND_SOC_DAPM_MUX_E("ADC MUX4", WCD9360_CDC_TX4_TX_PATH_CTL, 5, 0,
  4506. &tx_adc_mux4_mux, pahu_codec_enable_dec,
  4507. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  4508. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  4509. SND_SOC_DAPM_MUX_E("ADC MUX5", WCD9360_CDC_TX5_TX_PATH_CTL, 5, 0,
  4510. &tx_adc_mux5_mux, pahu_codec_enable_dec,
  4511. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  4512. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  4513. SND_SOC_DAPM_MUX_E("ADC MUX6", WCD9360_CDC_TX6_TX_PATH_CTL, 5, 0,
  4514. &tx_adc_mux6_mux, pahu_codec_enable_dec,
  4515. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  4516. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  4517. SND_SOC_DAPM_MUX_E("ADC MUX7", WCD9360_CDC_TX7_TX_PATH_CTL, 5, 0,
  4518. &tx_adc_mux7_mux, pahu_codec_enable_dec,
  4519. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  4520. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  4521. SND_SOC_DAPM_MUX_E("ADC MUX8", WCD9360_CDC_TX8_TX_PATH_CTL, 5, 0,
  4522. &tx_adc_mux8_mux, pahu_codec_enable_dec,
  4523. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  4524. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  4525. SND_SOC_DAPM_MUX_E("ADC MUX10", SND_SOC_NOPM, 10, 0, &tx_adc_mux10_mux,
  4526. pahu_codec_tx_adc_cfg, SND_SOC_DAPM_POST_PMU),
  4527. SND_SOC_DAPM_MUX_E("ADC MUX11", SND_SOC_NOPM, 11, 0, &tx_adc_mux11_mux,
  4528. pahu_codec_tx_adc_cfg, SND_SOC_DAPM_POST_PMU),
  4529. WCD_DAPM_MUX("DMIC MUX0", 0, tx_dmic_mux0),
  4530. WCD_DAPM_MUX("DMIC MUX1", 0, tx_dmic_mux1),
  4531. WCD_DAPM_MUX("DMIC MUX2", 0, tx_dmic_mux2),
  4532. WCD_DAPM_MUX("DMIC MUX3", 0, tx_dmic_mux3),
  4533. WCD_DAPM_MUX("DMIC MUX4", 0, tx_dmic_mux4),
  4534. WCD_DAPM_MUX("DMIC MUX5", 0, tx_dmic_mux5),
  4535. WCD_DAPM_MUX("DMIC MUX6", 0, tx_dmic_mux6),
  4536. WCD_DAPM_MUX("DMIC MUX7", 0, tx_dmic_mux7),
  4537. WCD_DAPM_MUX("DMIC MUX8", 0, tx_dmic_mux8),
  4538. WCD_DAPM_MUX("DMIC MUX10", 0, tx_dmic_mux10),
  4539. WCD_DAPM_MUX("DMIC MUX11", 0, tx_dmic_mux11),
  4540. WCD_DAPM_MUX("AMIC MUX0", 0, tx_amic_mux0),
  4541. WCD_DAPM_MUX("AMIC MUX1", 0, tx_amic_mux1),
  4542. WCD_DAPM_MUX("AMIC MUX2", 0, tx_amic_mux2),
  4543. WCD_DAPM_MUX("AMIC MUX3", 0, tx_amic_mux3),
  4544. WCD_DAPM_MUX("AMIC MUX4", 0, tx_amic_mux4),
  4545. WCD_DAPM_MUX("AMIC MUX5", 0, tx_amic_mux5),
  4546. WCD_DAPM_MUX("AMIC MUX6", 0, tx_amic_mux6),
  4547. WCD_DAPM_MUX("AMIC MUX7", 0, tx_amic_mux7),
  4548. WCD_DAPM_MUX("AMIC MUX8", 0, tx_amic_mux8),
  4549. WCD_DAPM_MUX("AMIC MUX10", 0, tx_amic_mux10),
  4550. WCD_DAPM_MUX("AMIC MUX11", 0, tx_amic_mux11),
  4551. SND_SOC_DAPM_ADC_E("ADC1", NULL, WCD9360_ANA_AMIC1, 7, 0,
  4552. pahu_codec_enable_adc, SND_SOC_DAPM_PRE_PMU),
  4553. SND_SOC_DAPM_ADC_E("ADC2", NULL, WCD9360_ANA_AMIC2, 7, 0,
  4554. pahu_codec_enable_adc, SND_SOC_DAPM_PRE_PMU),
  4555. SND_SOC_DAPM_ADC_E("ADC3", NULL, WCD9360_ANA_AMIC3, 7, 0,
  4556. pahu_codec_enable_adc, SND_SOC_DAPM_PRE_PMU),
  4557. SND_SOC_DAPM_ADC_E("ADC4", NULL, WCD9360_ANA_AMIC4, 7, 0,
  4558. pahu_codec_enable_adc, SND_SOC_DAPM_PRE_PMU),
  4559. WCD_DAPM_MUX("ANC0 FB MUX", 0, anc0_fb),
  4560. WCD_DAPM_MUX("ADC2_IN", 0, tx_adc2_in),
  4561. WCD_DAPM_MUX("ADC4_IN", 0, tx_adc4_in),
  4562. SND_SOC_DAPM_INPUT("AMIC1"),
  4563. SND_SOC_DAPM_INPUT("AMIC2"),
  4564. SND_SOC_DAPM_INPUT("AMIC3"),
  4565. SND_SOC_DAPM_INPUT("AMIC4"),
  4566. SND_SOC_DAPM_MICBIAS_E("MIC BIAS1", SND_SOC_NOPM, 0, 0,
  4567. pahu_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
  4568. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4569. SND_SOC_DAPM_MICBIAS_E("MIC BIAS2", SND_SOC_NOPM, 0, 0,
  4570. pahu_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
  4571. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4572. SND_SOC_DAPM_MICBIAS_E("MIC BIAS3", SND_SOC_NOPM, 0, 0,
  4573. pahu_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
  4574. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4575. SND_SOC_DAPM_MICBIAS_E("MIC BIAS4", SND_SOC_NOPM, 0, 0,
  4576. pahu_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
  4577. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4578. SND_SOC_DAPM_MICBIAS_E(DAPM_MICBIAS1_STANDALONE, SND_SOC_NOPM, 0, 0,
  4579. pahu_codec_force_enable_micbias,
  4580. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  4581. SND_SOC_DAPM_MICBIAS_E(DAPM_MICBIAS2_STANDALONE, SND_SOC_NOPM, 0, 0,
  4582. pahu_codec_force_enable_micbias,
  4583. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  4584. SND_SOC_DAPM_MICBIAS_E(DAPM_MICBIAS3_STANDALONE, SND_SOC_NOPM, 0, 0,
  4585. pahu_codec_force_enable_micbias,
  4586. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  4587. SND_SOC_DAPM_MICBIAS_E(DAPM_MICBIAS4_STANDALONE, SND_SOC_NOPM, 0, 0,
  4588. pahu_codec_force_enable_micbias,
  4589. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  4590. SND_SOC_DAPM_AIF_OUT_E("AIF1 CAP", "AIF1 Capture", 0, SND_SOC_NOPM,
  4591. AIF1_CAP, 0, pahu_codec_enable_slimtx,
  4592. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4593. SND_SOC_DAPM_AIF_OUT_E("AIF2 CAP", "AIF2 Capture", 0, SND_SOC_NOPM,
  4594. AIF2_CAP, 0, pahu_codec_enable_slimtx,
  4595. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4596. SND_SOC_DAPM_AIF_OUT_E("AIF3 CAP", "AIF3 Capture", 0, SND_SOC_NOPM,
  4597. AIF3_CAP, 0, pahu_codec_enable_slimtx,
  4598. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4599. SND_SOC_DAPM_MIXER("AIF1_CAP Mixer", SND_SOC_NOPM, AIF1_CAP, 0,
  4600. aif1_cap_mixer, ARRAY_SIZE(aif1_cap_mixer)),
  4601. SND_SOC_DAPM_MIXER("AIF2_CAP Mixer", SND_SOC_NOPM, AIF2_CAP, 0,
  4602. aif2_cap_mixer, ARRAY_SIZE(aif2_cap_mixer)),
  4603. SND_SOC_DAPM_MIXER("AIF3_CAP Mixer", SND_SOC_NOPM, AIF3_CAP, 0,
  4604. aif3_cap_mixer, ARRAY_SIZE(aif3_cap_mixer)),
  4605. SND_SOC_DAPM_MIXER("AIF4_MAD Mixer", SND_SOC_NOPM, AIF4_MAD_TX, 0,
  4606. aif4_mad_mixer, ARRAY_SIZE(aif4_mad_mixer)),
  4607. SND_SOC_DAPM_AIF_OUT_E("AIF4 VI", "VIfeed", 0, SND_SOC_NOPM,
  4608. AIF4_VIFEED, 0, pahu_codec_enable_slimvi_feedback,
  4609. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4610. SND_SOC_DAPM_AIF_OUT("AIF4 MAD", "AIF4 MAD TX", 0,
  4611. SND_SOC_NOPM, 0, 0),
  4612. SND_SOC_DAPM_MIXER("AIF4_VI Mixer", SND_SOC_NOPM, AIF4_VIFEED, 0,
  4613. aif4_vi_mixer, ARRAY_SIZE(aif4_vi_mixer)),
  4614. SND_SOC_DAPM_INPUT("VIINPUT"),
  4615. SND_SOC_DAPM_MIXER("SLIM TX0", SND_SOC_NOPM, 0, 0, NULL, 0),
  4616. SND_SOC_DAPM_MIXER("SLIM TX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  4617. SND_SOC_DAPM_MIXER("SLIM TX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  4618. SND_SOC_DAPM_MIXER("SLIM TX3", SND_SOC_NOPM, 0, 0, NULL, 0),
  4619. SND_SOC_DAPM_MIXER("SLIM TX4", SND_SOC_NOPM, 0, 0, NULL, 0),
  4620. SND_SOC_DAPM_MIXER("SLIM TX5", SND_SOC_NOPM, 0, 0, NULL, 0),
  4621. SND_SOC_DAPM_MIXER("SLIM TX6", SND_SOC_NOPM, 0, 0, NULL, 0),
  4622. SND_SOC_DAPM_MIXER("SLIM TX7", SND_SOC_NOPM, 0, 0, NULL, 0),
  4623. SND_SOC_DAPM_MIXER("SLIM TX8", SND_SOC_NOPM, 0, 0, NULL, 0),
  4624. SND_SOC_DAPM_MIXER("SLIM TX9", SND_SOC_NOPM, 0, 0, NULL, 0),
  4625. SND_SOC_DAPM_MIXER("SLIM TX10", SND_SOC_NOPM, 0, 0, NULL, 0),
  4626. SND_SOC_DAPM_MIXER("SLIM TX11", SND_SOC_NOPM, 0, 0, NULL, 0),
  4627. SND_SOC_DAPM_MIXER("SLIM TX13", SND_SOC_NOPM, 0, 0, NULL, 0),
  4628. /* Digital Mic Inputs */
  4629. SND_SOC_DAPM_ADC_E("DMIC0", NULL, SND_SOC_NOPM, 0, 0,
  4630. pahu_codec_enable_dmic,
  4631. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  4632. SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 1, 0,
  4633. pahu_codec_enable_dmic,
  4634. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  4635. SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 2, 0,
  4636. pahu_codec_enable_dmic,
  4637. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  4638. SND_SOC_DAPM_ADC_E("DMIC3", NULL, SND_SOC_NOPM, 3, 0,
  4639. pahu_codec_enable_dmic,
  4640. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  4641. SND_SOC_DAPM_ADC_E("DMIC4", NULL, SND_SOC_NOPM, 4, 0,
  4642. pahu_codec_enable_dmic,
  4643. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  4644. SND_SOC_DAPM_ADC_E("DMIC5", NULL, SND_SOC_NOPM, 5, 0,
  4645. pahu_codec_enable_dmic,
  4646. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  4647. SND_SOC_DAPM_ADC_E("DMIC6", NULL, SND_SOC_NOPM, 6, 0,
  4648. pahu_codec_enable_dmic,
  4649. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  4650. SND_SOC_DAPM_ADC_E("DMIC7", NULL, SND_SOC_NOPM, 7, 0,
  4651. pahu_codec_enable_dmic,
  4652. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  4653. WCD_DAPM_MUX("IIR0 INP0 MUX", 0, iir0_inp0),
  4654. WCD_DAPM_MUX("IIR0 INP1 MUX", 0, iir0_inp1),
  4655. WCD_DAPM_MUX("IIR0 INP2 MUX", 0, iir0_inp2),
  4656. WCD_DAPM_MUX("IIR0 INP3 MUX", 0, iir0_inp3),
  4657. SND_SOC_DAPM_MIXER_E("IIR0", WCD9360_CDC_SIDETONE_IIR0_IIR_PATH_CTL,
  4658. 4, 0, NULL, 0, pahu_codec_set_iir_gain,
  4659. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  4660. SND_SOC_DAPM_MIXER("SRC0", WCD9360_CDC_SIDETONE_SRC0_ST_SRC_PATH_CTL,
  4661. 4, 0, NULL, 0),
  4662. WCD_DAPM_MUX("RX MIX TX0 MUX", 0, rx_mix_tx0),
  4663. WCD_DAPM_MUX("RX MIX TX1 MUX", 0, rx_mix_tx1),
  4664. WCD_DAPM_MUX("RX MIX TX2 MUX", 0, rx_mix_tx2),
  4665. WCD_DAPM_MUX("RX MIX TX3 MUX", 0, rx_mix_tx3),
  4666. WCD_DAPM_MUX("RX MIX TX4 MUX", 0, rx_mix_tx4),
  4667. WCD_DAPM_MUX("RX MIX TX5 MUX", 0, rx_mix_tx5),
  4668. WCD_DAPM_MUX("RX MIX TX6 MUX", 0, rx_mix_tx6),
  4669. WCD_DAPM_MUX("RX MIX TX7 MUX", 0, rx_mix_tx7),
  4670. WCD_DAPM_MUX("RX MIX TX8 MUX", 0, rx_mix_tx8),
  4671. WCD_DAPM_MUX("RX INT0 DEM MUX", 0, rx_int0_dem_inp),
  4672. WCD_DAPM_MUX("RX INT9 DEM MUX", 0, rx_int9_dem_inp),
  4673. SND_SOC_DAPM_MUX_E("RX INT0_1 INTERP", SND_SOC_NOPM, INTERP_EAR, 0,
  4674. &rx_int0_1_interp_mux, pahu_codec_enable_main_path,
  4675. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  4676. SND_SOC_DAPM_POST_PMD),
  4677. SND_SOC_DAPM_MUX_E("RX INT7_1 INTERP", SND_SOC_NOPM, INTERP_SPKR1, 0,
  4678. &rx_int7_1_interp_mux, pahu_codec_enable_main_path,
  4679. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  4680. SND_SOC_DAPM_POST_PMD),
  4681. SND_SOC_DAPM_MUX_E("RX INT8_1 INTERP", SND_SOC_NOPM, INTERP_SPKR2, 0,
  4682. &rx_int8_1_interp_mux, pahu_codec_enable_main_path,
  4683. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  4684. SND_SOC_DAPM_POST_PMD),
  4685. SND_SOC_DAPM_MUX_E("RX INT9_1 INTERP", SND_SOC_NOPM, INTERP_AUX, 0,
  4686. &rx_int9_1_interp_mux, pahu_codec_enable_main_path,
  4687. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  4688. SND_SOC_DAPM_POST_PMD),
  4689. WCD_DAPM_MUX("RX INT0_2 INTERP", 0, rx_int0_2_interp),
  4690. WCD_DAPM_MUX("RX INT7_2 INTERP", 0, rx_int7_2_interp),
  4691. WCD_DAPM_MUX("RX INT8_2 INTERP", 0, rx_int8_2_interp),
  4692. WCD_DAPM_MUX("RX INT9_2 INTERP", 0, rx_int9_2_interp),
  4693. SND_SOC_DAPM_SWITCH("ADC US MUX0", WCD9360_CDC_TX0_TX_PATH_192_CTL, 0,
  4694. 0, &adc_us_mux0_switch),
  4695. SND_SOC_DAPM_SWITCH("ADC US MUX1", WCD9360_CDC_TX1_TX_PATH_192_CTL, 0,
  4696. 0, &adc_us_mux1_switch),
  4697. SND_SOC_DAPM_SWITCH("ADC US MUX2", WCD9360_CDC_TX2_TX_PATH_192_CTL, 0,
  4698. 0, &adc_us_mux2_switch),
  4699. SND_SOC_DAPM_SWITCH("ADC US MUX3", WCD9360_CDC_TX3_TX_PATH_192_CTL, 0,
  4700. 0, &adc_us_mux3_switch),
  4701. SND_SOC_DAPM_SWITCH("ADC US MUX4", WCD9360_CDC_TX4_TX_PATH_192_CTL, 0,
  4702. 0, &adc_us_mux4_switch),
  4703. SND_SOC_DAPM_SWITCH("ADC US MUX5", WCD9360_CDC_TX5_TX_PATH_192_CTL, 0,
  4704. 0, &adc_us_mux5_switch),
  4705. SND_SOC_DAPM_SWITCH("ADC US MUX6", WCD9360_CDC_TX6_TX_PATH_192_CTL, 0,
  4706. 0, &adc_us_mux6_switch),
  4707. SND_SOC_DAPM_SWITCH("ADC US MUX7", WCD9360_CDC_TX7_TX_PATH_192_CTL, 0,
  4708. 0, &adc_us_mux7_switch),
  4709. SND_SOC_DAPM_SWITCH("ADC US MUX8", WCD9360_CDC_TX8_TX_PATH_192_CTL, 0,
  4710. 0, &adc_us_mux8_switch),
  4711. /* MAD related widgets */
  4712. SND_SOC_DAPM_INPUT("MAD_CPE_INPUT"),
  4713. SND_SOC_DAPM_INPUT("MADINPUT"),
  4714. WCD_DAPM_MUX("MAD_SEL MUX", 0, mad_sel),
  4715. WCD_DAPM_MUX("MAD_INP MUX", 0, mad_inp_mux),
  4716. SND_SOC_DAPM_SWITCH_E("MAD_BROADCAST", SND_SOC_NOPM, 0, 0,
  4717. &mad_brdcst_switch, pahu_codec_ape_enable_mad,
  4718. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  4719. SND_SOC_DAPM_SWITCH_E("MAD_CPE1", SND_SOC_NOPM, 0, 0,
  4720. &mad_cpe1_switch, pahu_codec_cpe_mad_ctl,
  4721. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  4722. SND_SOC_DAPM_SWITCH_E("MAD_CPE2", SND_SOC_NOPM, 0, 0,
  4723. &mad_cpe2_switch, pahu_codec_cpe_mad_ctl,
  4724. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  4725. SND_SOC_DAPM_OUTPUT("MAD_CPE_OUT1"),
  4726. SND_SOC_DAPM_OUTPUT("MAD_CPE_OUT2"),
  4727. SND_SOC_DAPM_DAC_E("RX INT0 DAC", NULL, SND_SOC_NOPM,
  4728. 0, 0, pahu_codec_ear_dac_event, SND_SOC_DAPM_PRE_PMU),
  4729. SND_SOC_DAPM_PGA_E("EAR PA", WCD9360_ANA_EAR, 7, 0, NULL, 0,
  4730. pahu_codec_enable_ear_pa,
  4731. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4732. SND_SOC_DAPM_PGA_E("ANC EAR PA", WCD9360_ANA_EAR, 7, 0, NULL, 0,
  4733. pahu_codec_enable_ear_pa, SND_SOC_DAPM_POST_PMU |
  4734. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  4735. SND_SOC_DAPM_PGA_E("ANC SPK1 PA", SND_SOC_NOPM, 0, 0, NULL, 0,
  4736. pahu_codec_enable_spkr_anc,
  4737. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  4738. SND_SOC_DAPM_OUTPUT("EAR"),
  4739. SND_SOC_DAPM_OUTPUT("SPK1 OUT"),
  4740. SND_SOC_DAPM_OUTPUT("SPK2 OUT"),
  4741. SND_SOC_DAPM_OUTPUT("ANC EAR"),
  4742. SND_SOC_DAPM_SWITCH("ANC OUT EAR Enable", SND_SOC_NOPM, 0, 0,
  4743. &anc_ear_switch),
  4744. SND_SOC_DAPM_SWITCH("ANC OUT EAR SPKR Enable", SND_SOC_NOPM, 0, 0,
  4745. &anc_ear_spkr_switch),
  4746. SND_SOC_DAPM_SWITCH("ANC SPKR PA Enable", SND_SOC_NOPM, 0, 0,
  4747. &anc_spkr_pa_switch),
  4748. SND_SOC_DAPM_DAC("RX INT9 DAC", NULL, SND_SOC_NOPM, 0, 0),
  4749. SND_SOC_DAPM_PGA_E("AUX PA", WCD9360_AUX_ANA_EAR, 7, 0, NULL, 0,
  4750. pahu_codec_enable_aux_pa, SND_SOC_DAPM_POST_PMU),
  4751. SND_SOC_DAPM_OUTPUT("AUX"),
  4752. SND_SOC_DAPM_SUPPLY("LDO_RXTX", SND_SOC_NOPM, 0, 0,
  4753. pahu_codec_enable_ldo_rxtx,
  4754. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  4755. SND_SOC_DAPM_SUPPLY("RX INT7 NATIVE SUPPLY", SND_SOC_NOPM,
  4756. INTERP_SPKR1, 0, pahu_enable_native_supply,
  4757. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  4758. SND_SOC_DAPM_SUPPLY("RX INT8 NATIVE SUPPLY", SND_SOC_NOPM,
  4759. INTERP_SPKR2, 0, pahu_enable_native_supply,
  4760. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  4761. WCD_DAPM_MUX("RX INT7_2 NATIVE MUX", 0, int7_2_native),
  4762. WCD_DAPM_MUX("RX INT8_2 NATIVE MUX", 0, int8_2_native),
  4763. SND_SOC_DAPM_MUX_E("ASRC2 MUX", SND_SOC_NOPM, ASRC2, 0,
  4764. &asrc2_mux, pahu_codec_enable_asrc_resampler,
  4765. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  4766. SND_SOC_DAPM_MUX_E("ASRC3 MUX", SND_SOC_NOPM, ASRC3, 0,
  4767. &asrc3_mux, pahu_codec_enable_asrc_resampler,
  4768. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  4769. /* WDMA3 widgets */
  4770. WCD_DAPM_MUX("WDMA3 PORT0 MUX", 0, wdma3_port0),
  4771. WCD_DAPM_MUX("WDMA3 PORT1 MUX", 1, wdma3_port1),
  4772. WCD_DAPM_MUX("WDMA3 PORT2 MUX", 2, wdma3_port2),
  4773. WCD_DAPM_MUX("WDMA3 PORT3 MUX", 3, wdma3_port3),
  4774. WCD_DAPM_MUX("WDMA3 PORT4 MUX", 4, wdma3_port4),
  4775. WCD_DAPM_MUX("WDMA3 PORT5 MUX", 5, wdma3_port5),
  4776. WCD_DAPM_MUX("WDMA3 PORT6 MUX", 6, wdma3_port6),
  4777. WCD_DAPM_MUX("WDMA3 CH0 MUX", 0, wdma3_ch0),
  4778. WCD_DAPM_MUX("WDMA3 CH1 MUX", 4, wdma3_ch1),
  4779. WCD_DAPM_MUX("WDMA3 CH2 MUX", 0, wdma3_ch2),
  4780. WCD_DAPM_MUX("WDMA3 CH3 MUX", 4, wdma3_ch3),
  4781. SND_SOC_DAPM_MIXER("WDMA3_CH_MIXER", SND_SOC_NOPM, 0, 0, NULL, 0),
  4782. SND_SOC_DAPM_SWITCH_E("WDMA3_ON_OFF", SND_SOC_NOPM, 0, 0,
  4783. &wdma3_onoff_switch, pahu_codec_wdma3_ctl,
  4784. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  4785. SND_SOC_DAPM_OUTPUT("WDMA3_OUT"),
  4786. };
  4787. static int pahu_get_channel_map(struct snd_soc_dai *dai,
  4788. unsigned int *tx_num, unsigned int *tx_slot,
  4789. unsigned int *rx_num, unsigned int *rx_slot)
  4790. {
  4791. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(dai->codec);
  4792. u32 i = 0;
  4793. struct wcd9xxx_ch *ch;
  4794. int ret = 0;
  4795. switch (dai->id) {
  4796. case AIF1_PB:
  4797. case AIF2_PB:
  4798. case AIF3_PB:
  4799. case AIF4_PB:
  4800. if (!rx_slot || !rx_num) {
  4801. dev_err(pahu->dev, "%s: Invalid rx_slot 0x%pK or rx_num 0x%pK\n",
  4802. __func__, rx_slot, rx_num);
  4803. ret = -EINVAL;
  4804. break;
  4805. }
  4806. list_for_each_entry(ch, &pahu->dai[dai->id].wcd9xxx_ch_list,
  4807. list) {
  4808. dev_dbg(pahu->dev, "%s: slot_num %u ch->ch_num %d\n",
  4809. __func__, i, ch->ch_num);
  4810. rx_slot[i++] = ch->ch_num;
  4811. }
  4812. *rx_num = i;
  4813. dev_dbg(pahu->dev, "%s: dai_name = %s dai_id = %x rx_num = %d\n",
  4814. __func__, dai->name, dai->id, i);
  4815. if (*rx_num == 0) {
  4816. dev_err(pahu->dev, "%s: Channel list empty for dai_name = %s dai_id = %x\n",
  4817. __func__, dai->name, dai->id);
  4818. ret = -EINVAL;
  4819. }
  4820. break;
  4821. case AIF1_CAP:
  4822. case AIF2_CAP:
  4823. case AIF3_CAP:
  4824. case AIF4_MAD_TX:
  4825. case AIF4_VIFEED:
  4826. if (!tx_slot || !tx_num) {
  4827. dev_err(pahu->dev, "%s: Invalid tx_slot 0x%pK or tx_num 0x%pK\n",
  4828. __func__, tx_slot, tx_num);
  4829. ret = -EINVAL;
  4830. break;
  4831. }
  4832. list_for_each_entry(ch, &pahu->dai[dai->id].wcd9xxx_ch_list,
  4833. list) {
  4834. dev_dbg(pahu->dev, "%s: slot_num %u ch->ch_num %d\n",
  4835. __func__, i, ch->ch_num);
  4836. tx_slot[i++] = ch->ch_num;
  4837. }
  4838. *tx_num = i;
  4839. dev_dbg(pahu->dev, "%s: dai_name = %s dai_id = %x tx_num = %d\n",
  4840. __func__, dai->name, dai->id, i);
  4841. if (*tx_num == 0) {
  4842. dev_err(pahu->dev, "%s: Channel list empty for dai_name = %s dai_id = %x\n",
  4843. __func__, dai->name, dai->id);
  4844. ret = -EINVAL;
  4845. }
  4846. break;
  4847. default:
  4848. dev_err(pahu->dev, "%s: Invalid DAI ID %x\n",
  4849. __func__, dai->id);
  4850. ret = -EINVAL;
  4851. break;
  4852. }
  4853. return ret;
  4854. }
  4855. static int pahu_set_channel_map(struct snd_soc_dai *dai,
  4856. unsigned int tx_num, unsigned int *tx_slot,
  4857. unsigned int rx_num, unsigned int *rx_slot)
  4858. {
  4859. struct pahu_priv *pahu;
  4860. struct wcd9xxx *core;
  4861. struct wcd9xxx_codec_dai_data *dai_data = NULL;
  4862. pahu = snd_soc_codec_get_drvdata(dai->codec);
  4863. core = dev_get_drvdata(dai->codec->dev->parent);
  4864. if (!tx_slot || !rx_slot) {
  4865. dev_err(pahu->dev, "%s: Invalid tx_slot 0x%pK, rx_slot 0x%pK\n",
  4866. __func__, tx_slot, rx_slot);
  4867. return -EINVAL;
  4868. }
  4869. dev_dbg(pahu->dev, "%s(): dai_name = %s DAI-ID %x tx_ch %d rx_ch %d\n",
  4870. __func__, dai->name, dai->id, tx_num, rx_num);
  4871. wcd9xxx_init_slimslave(core, core->slim->laddr,
  4872. tx_num, tx_slot, rx_num, rx_slot);
  4873. /* Reserve TX13 for MAD data channel */
  4874. dai_data = &pahu->dai[AIF4_MAD_TX];
  4875. if (dai_data)
  4876. list_add_tail(&core->tx_chs[WCD9360_TX13].list,
  4877. &dai_data->wcd9xxx_ch_list);
  4878. return 0;
  4879. }
  4880. static int pahu_startup(struct snd_pcm_substream *substream,
  4881. struct snd_soc_dai *dai)
  4882. {
  4883. pr_debug("%s(): substream = %s stream = %d\n", __func__,
  4884. substream->name, substream->stream);
  4885. return 0;
  4886. }
  4887. static void pahu_shutdown(struct snd_pcm_substream *substream,
  4888. struct snd_soc_dai *dai)
  4889. {
  4890. pr_debug("%s(): substream = %s stream = %d\n", __func__,
  4891. substream->name, substream->stream);
  4892. }
  4893. static int pahu_set_decimator_rate(struct snd_soc_dai *dai,
  4894. u32 sample_rate)
  4895. {
  4896. struct snd_soc_codec *codec = dai->codec;
  4897. struct wcd9xxx_ch *ch;
  4898. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(codec);
  4899. u32 tx_port = 0, tx_fs_rate = 0;
  4900. u8 shift = 0, shift_val = 0, tx_mux_sel = 0;
  4901. int decimator = -1;
  4902. u16 tx_port_reg = 0, tx_fs_reg = 0;
  4903. switch (sample_rate) {
  4904. case 8000:
  4905. tx_fs_rate = 0;
  4906. break;
  4907. case 16000:
  4908. tx_fs_rate = 1;
  4909. break;
  4910. case 32000:
  4911. tx_fs_rate = 3;
  4912. break;
  4913. case 48000:
  4914. tx_fs_rate = 4;
  4915. break;
  4916. case 96000:
  4917. tx_fs_rate = 5;
  4918. break;
  4919. case 192000:
  4920. tx_fs_rate = 6;
  4921. break;
  4922. default:
  4923. dev_err(pahu->dev, "%s: Invalid TX sample rate: %d\n",
  4924. __func__, sample_rate);
  4925. return -EINVAL;
  4926. };
  4927. list_for_each_entry(ch, &pahu->dai[dai->id].wcd9xxx_ch_list, list) {
  4928. tx_port = ch->port;
  4929. dev_dbg(codec->dev, "%s: dai->id = %d, tx_port = %d",
  4930. __func__, dai->id, tx_port);
  4931. if ((tx_port < 0) || (tx_port == 12) || (tx_port >= 14)) {
  4932. dev_err(codec->dev, "%s: Invalid SLIM TX%u port. DAI ID: %d\n",
  4933. __func__, tx_port, dai->id);
  4934. return -EINVAL;
  4935. }
  4936. /* Find the SB TX MUX input - which decimator is connected */
  4937. if (tx_port < 4) {
  4938. tx_port_reg = WCD9360_CDC_IF_ROUTER_TX_MUX_CFG0;
  4939. shift = (tx_port << 1);
  4940. shift_val = 0x03;
  4941. } else if ((tx_port >= 4) && (tx_port < 8)) {
  4942. tx_port_reg = WCD9360_CDC_IF_ROUTER_TX_MUX_CFG1;
  4943. shift = ((tx_port - 4) << 1);
  4944. shift_val = 0x03;
  4945. } else if ((tx_port >= 8) && (tx_port < 11)) {
  4946. tx_port_reg = WCD9360_CDC_IF_ROUTER_TX_MUX_CFG2;
  4947. shift = ((tx_port - 8) << 1);
  4948. shift_val = 0x03;
  4949. } else if (tx_port == 11) {
  4950. tx_port_reg = WCD9360_CDC_IF_ROUTER_TX_MUX_CFG3;
  4951. shift = 0;
  4952. shift_val = 0x0F;
  4953. } else if (tx_port == 13) {
  4954. tx_port_reg = WCD9360_CDC_IF_ROUTER_TX_MUX_CFG3;
  4955. shift = 4;
  4956. shift_val = 0x03;
  4957. }
  4958. tx_mux_sel = snd_soc_read(codec, tx_port_reg) &
  4959. (shift_val << shift);
  4960. tx_mux_sel = tx_mux_sel >> shift;
  4961. if (tx_port <= 8) {
  4962. if ((tx_mux_sel == 0x2) || (tx_mux_sel == 0x3))
  4963. decimator = tx_port;
  4964. } else if (tx_port <= 10) {
  4965. if ((tx_mux_sel == 0x1) || (tx_mux_sel == 0x2))
  4966. decimator = ((tx_port == 9) ? 7 : 6);
  4967. } else if (tx_port == 11) {
  4968. if ((tx_mux_sel >= 1) && (tx_mux_sel < 7))
  4969. decimator = tx_mux_sel - 1;
  4970. } else if (tx_port == 13) {
  4971. if ((tx_mux_sel == 0x1) || (tx_mux_sel == 0x2))
  4972. decimator = 5;
  4973. }
  4974. if (decimator >= 0) {
  4975. tx_fs_reg = WCD9360_CDC_TX0_TX_PATH_CTL +
  4976. 16 * decimator;
  4977. dev_dbg(codec->dev, "%s: set DEC%u (-> SLIM_TX%u) rate to %u\n",
  4978. __func__, decimator, tx_port, sample_rate);
  4979. snd_soc_update_bits(codec, tx_fs_reg, 0x0F, tx_fs_rate);
  4980. } else if ((tx_port <= 8) && (tx_mux_sel == 0x01)) {
  4981. /* Check if the TX Mux input is RX MIX TXn */
  4982. dev_dbg(codec->dev, "%s: RX_MIX_TX%u going to CDC_IF TX%u\n",
  4983. __func__, tx_port, tx_port);
  4984. } else {
  4985. dev_err(codec->dev, "%s: ERROR: Invalid decimator: %d\n",
  4986. __func__, decimator);
  4987. return -EINVAL;
  4988. }
  4989. }
  4990. return 0;
  4991. }
  4992. static int pahu_set_mix_interpolator_rate(struct snd_soc_dai *dai,
  4993. u8 rate_reg_val,
  4994. u32 sample_rate)
  4995. {
  4996. u8 int_2_inp;
  4997. u32 j;
  4998. u16 int_mux_cfg1, int_fs_reg;
  4999. u8 int_mux_cfg1_val;
  5000. struct snd_soc_codec *codec = dai->codec;
  5001. struct wcd9xxx_ch *ch;
  5002. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(codec);
  5003. list_for_each_entry(ch, &pahu->dai[dai->id].wcd9xxx_ch_list, list) {
  5004. int_2_inp = INTn_2_INP_SEL_RX0 + ch->port -
  5005. WCD9360_RX_PORT_START_NUMBER;
  5006. if ((int_2_inp < INTn_2_INP_SEL_RX0) ||
  5007. (int_2_inp > INTn_2_INP_SEL_RX7)) {
  5008. dev_err(codec->dev, "%s: Invalid RX%u port, Dai ID is %d\n",
  5009. __func__,
  5010. (ch->port - WCD9360_RX_PORT_START_NUMBER),
  5011. dai->id);
  5012. return -EINVAL;
  5013. }
  5014. for (j = 0; j < WCD9360_NUM_INTERPOLATORS; j++) {
  5015. if (j == INTERP_EAR) {
  5016. int_mux_cfg1 =
  5017. WCD9360_CDC_RX_INP_MUX_RX_INT0_CFG1;
  5018. int_fs_reg = WCD9360_CDC_RX0_RX_PATH_MIX_CTL;
  5019. } else if (j == INTERP_SPKR1) {
  5020. int_mux_cfg1 =
  5021. WCD9360_CDC_RX_INP_MUX_RX_INT7_CFG1;
  5022. int_fs_reg = WCD9360_CDC_RX7_RX_PATH_MIX_CTL;
  5023. } else if (j == INTERP_SPKR2) {
  5024. int_mux_cfg1 =
  5025. WCD9360_CDC_RX_INP_MUX_RX_INT8_CFG1;
  5026. int_fs_reg = WCD9360_CDC_RX8_RX_PATH_MIX_CTL;
  5027. } else if (j == INTERP_AUX) {
  5028. int_mux_cfg1 =
  5029. WCD9360_CDC_RX_INP_MUX_RX_INT9_CFG1;
  5030. int_fs_reg = WCD9360_CDC_RX9_RX_PATH_MIX_CTL;
  5031. } else {
  5032. continue;
  5033. }
  5034. int_mux_cfg1_val = snd_soc_read(codec, int_mux_cfg1) &
  5035. 0x0F;
  5036. if (int_mux_cfg1_val == int_2_inp) {
  5037. /*
  5038. * Ear mix path supports only 48, 96, 192,
  5039. * 384KHz only
  5040. */
  5041. if ((j == INTERP_EAR || j == INTERP_AUX) &&
  5042. (rate_reg_val < 0x4 || rate_reg_val > 0x7)) {
  5043. dev_err_ratelimited(codec->dev,
  5044. "%s: Invalid rate for AIF_PB DAI(%d)\n",
  5045. __func__, dai->id);
  5046. return -EINVAL;
  5047. }
  5048. dev_dbg(codec->dev, "%s: AIF_PB DAI(%d) connected to INT%u_2\n",
  5049. __func__, dai->id, j);
  5050. dev_dbg(codec->dev, "%s: set INT%u_2 sample rate to %u\n",
  5051. __func__, j, sample_rate);
  5052. snd_soc_update_bits(codec, int_fs_reg, 0x0F,
  5053. rate_reg_val);
  5054. }
  5055. }
  5056. }
  5057. return 0;
  5058. }
  5059. static int pahu_set_prim_interpolator_rate(struct snd_soc_dai *dai,
  5060. u8 rate_reg_val,
  5061. u32 sample_rate)
  5062. {
  5063. u8 int_1_mix1_inp;
  5064. u32 j;
  5065. u16 int_mux_cfg0, int_mux_cfg1;
  5066. u16 int_fs_reg;
  5067. u8 int_mux_cfg0_val, int_mux_cfg1_val;
  5068. u8 inp0_sel, inp1_sel, inp2_sel;
  5069. struct snd_soc_codec *codec = dai->codec;
  5070. struct wcd9xxx_ch *ch;
  5071. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(codec);
  5072. list_for_each_entry(ch, &pahu->dai[dai->id].wcd9xxx_ch_list, list) {
  5073. int_1_mix1_inp = INTn_1_INP_SEL_RX0 + ch->port -
  5074. WCD9360_RX_PORT_START_NUMBER;
  5075. if ((int_1_mix1_inp < INTn_1_INP_SEL_RX0) ||
  5076. (int_1_mix1_inp > INTn_1_INP_SEL_RX7)) {
  5077. dev_err(codec->dev, "%s: Invalid RX%u port, Dai ID is %d\n",
  5078. __func__,
  5079. (ch->port - WCD9360_RX_PORT_START_NUMBER),
  5080. dai->id);
  5081. return -EINVAL;
  5082. }
  5083. /*
  5084. * Loop through all interpolator MUX inputs and find out
  5085. * to which interpolator input, the slim rx port
  5086. * is connected
  5087. */
  5088. for (j = 0; j < WCD9360_NUM_INTERPOLATORS; j++) {
  5089. if (j == INTERP_EAR) {
  5090. int_mux_cfg0 =
  5091. WCD9360_CDC_RX_INP_MUX_RX_INT0_CFG0;
  5092. int_fs_reg = WCD9360_CDC_RX0_RX_PATH_CTL;
  5093. } else if (j == INTERP_SPKR1) {
  5094. int_mux_cfg0 =
  5095. WCD9360_CDC_RX_INP_MUX_RX_INT7_CFG0;
  5096. int_fs_reg = WCD9360_CDC_RX7_RX_PATH_CTL;
  5097. } else if (j == INTERP_SPKR2) {
  5098. int_mux_cfg0 =
  5099. WCD9360_CDC_RX_INP_MUX_RX_INT8_CFG0;
  5100. int_fs_reg = WCD9360_CDC_RX8_RX_PATH_CTL;
  5101. } else if (j == INTERP_AUX) {
  5102. int_mux_cfg0 =
  5103. WCD9360_CDC_RX_INP_MUX_RX_INT9_CFG0;
  5104. int_fs_reg = WCD9360_CDC_RX9_RX_PATH_CTL;
  5105. } else {
  5106. continue;
  5107. }
  5108. int_mux_cfg1 = int_mux_cfg0 + 1;
  5109. int_mux_cfg0_val = snd_soc_read(codec, int_mux_cfg0);
  5110. int_mux_cfg1_val = snd_soc_read(codec, int_mux_cfg1);
  5111. inp0_sel = int_mux_cfg0_val & 0x0F;
  5112. inp1_sel = (int_mux_cfg0_val >> 4) & 0x0F;
  5113. inp2_sel = (int_mux_cfg1_val >> 4) & 0x0F;
  5114. if ((inp0_sel == int_1_mix1_inp) ||
  5115. (inp1_sel == int_1_mix1_inp) ||
  5116. (inp2_sel == int_1_mix1_inp)) {
  5117. /*
  5118. * Primary path does not support
  5119. * native sample rates
  5120. */
  5121. if (rate_reg_val > 0x7) {
  5122. dev_err_ratelimited(codec->dev,
  5123. "%s: Invalid rate for AIF_PB DAI(%d)\n",
  5124. __func__, dai->id);
  5125. return -EINVAL;
  5126. }
  5127. dev_dbg(codec->dev,
  5128. "%s: AIF_PB DAI(%d) connected to INT%u_1\n",
  5129. __func__, dai->id, j);
  5130. dev_dbg(codec->dev,
  5131. "%s: set INT%u_1 sample rate to %u\n",
  5132. __func__, j, sample_rate);
  5133. snd_soc_update_bits(codec, int_fs_reg, 0x0F,
  5134. rate_reg_val);
  5135. }
  5136. int_mux_cfg0 += 2;
  5137. }
  5138. }
  5139. return 0;
  5140. }
  5141. static int pahu_set_interpolator_rate(struct snd_soc_dai *dai,
  5142. u32 sample_rate)
  5143. {
  5144. struct snd_soc_codec *codec = dai->codec;
  5145. int rate_val = 0;
  5146. int i, ret;
  5147. for (i = 0; i < ARRAY_SIZE(sr_val_tbl); i++) {
  5148. if (sample_rate == sr_val_tbl[i].sample_rate) {
  5149. rate_val = sr_val_tbl[i].rate_val;
  5150. break;
  5151. }
  5152. }
  5153. if ((i == ARRAY_SIZE(sr_val_tbl)) || (rate_val < 0)) {
  5154. dev_err(codec->dev, "%s: Unsupported sample rate: %d\n",
  5155. __func__, sample_rate);
  5156. return -EINVAL;
  5157. }
  5158. ret = pahu_set_prim_interpolator_rate(dai, (u8)rate_val, sample_rate);
  5159. if (ret)
  5160. return ret;
  5161. ret = pahu_set_mix_interpolator_rate(dai, (u8)rate_val, sample_rate);
  5162. if (ret)
  5163. return ret;
  5164. return ret;
  5165. }
  5166. static int pahu_prepare(struct snd_pcm_substream *substream,
  5167. struct snd_soc_dai *dai)
  5168. {
  5169. pr_debug("%s(): substream = %s stream = %d\n", __func__,
  5170. substream->name, substream->stream);
  5171. return 0;
  5172. }
  5173. static int pahu_vi_hw_params(struct snd_pcm_substream *substream,
  5174. struct snd_pcm_hw_params *params,
  5175. struct snd_soc_dai *dai)
  5176. {
  5177. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(dai->codec);
  5178. dev_dbg(pahu->dev, "%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n",
  5179. __func__, dai->name, dai->id, params_rate(params),
  5180. params_channels(params));
  5181. pahu->dai[dai->id].rate = params_rate(params);
  5182. pahu->dai[dai->id].bit_width = 32;
  5183. return 0;
  5184. }
  5185. static int pahu_hw_params(struct snd_pcm_substream *substream,
  5186. struct snd_pcm_hw_params *params,
  5187. struct snd_soc_dai *dai)
  5188. {
  5189. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(dai->codec);
  5190. int ret = 0;
  5191. dev_dbg(pahu->dev, "%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n",
  5192. __func__, dai->name, dai->id, params_rate(params),
  5193. params_channels(params));
  5194. switch (substream->stream) {
  5195. case SNDRV_PCM_STREAM_PLAYBACK:
  5196. ret = pahu_set_interpolator_rate(dai, params_rate(params));
  5197. if (ret) {
  5198. dev_err(pahu->dev, "%s: cannot set sample rate: %u\n",
  5199. __func__, params_rate(params));
  5200. return ret;
  5201. }
  5202. switch (params_width(params)) {
  5203. case 16:
  5204. pahu->dai[dai->id].bit_width = 16;
  5205. break;
  5206. case 24:
  5207. pahu->dai[dai->id].bit_width = 24;
  5208. break;
  5209. case 32:
  5210. pahu->dai[dai->id].bit_width = 32;
  5211. break;
  5212. default:
  5213. return -EINVAL;
  5214. }
  5215. pahu->dai[dai->id].rate = params_rate(params);
  5216. break;
  5217. case SNDRV_PCM_STREAM_CAPTURE:
  5218. if (dai->id != AIF4_MAD_TX)
  5219. ret = pahu_set_decimator_rate(dai,
  5220. params_rate(params));
  5221. if (ret) {
  5222. dev_err(pahu->dev, "%s: cannot set TX Decimator rate: %d\n",
  5223. __func__, ret);
  5224. return ret;
  5225. }
  5226. switch (params_width(params)) {
  5227. case 16:
  5228. pahu->dai[dai->id].bit_width = 16;
  5229. break;
  5230. case 24:
  5231. pahu->dai[dai->id].bit_width = 24;
  5232. break;
  5233. default:
  5234. dev_err(pahu->dev, "%s: Invalid format 0x%x\n",
  5235. __func__, params_width(params));
  5236. return -EINVAL;
  5237. };
  5238. pahu->dai[dai->id].rate = params_rate(params);
  5239. break;
  5240. default:
  5241. dev_err(pahu->dev, "%s: Invalid stream type %d\n", __func__,
  5242. substream->stream);
  5243. return -EINVAL;
  5244. };
  5245. return 0;
  5246. }
  5247. static struct snd_soc_dai_ops pahu_dai_ops = {
  5248. .startup = pahu_startup,
  5249. .shutdown = pahu_shutdown,
  5250. .hw_params = pahu_hw_params,
  5251. .prepare = pahu_prepare,
  5252. .set_channel_map = pahu_set_channel_map,
  5253. .get_channel_map = pahu_get_channel_map,
  5254. };
  5255. static struct snd_soc_dai_ops pahu_vi_dai_ops = {
  5256. .hw_params = pahu_vi_hw_params,
  5257. .set_channel_map = pahu_set_channel_map,
  5258. .get_channel_map = pahu_get_channel_map,
  5259. };
  5260. static struct snd_soc_dai_driver pahu_dai[] = {
  5261. {
  5262. .name = "pahu_rx1",
  5263. .id = AIF1_PB,
  5264. .playback = {
  5265. .stream_name = "AIF1 Playback",
  5266. .rates = WCD9360_RATES_MASK | WCD9360_FRAC_RATES_MASK,
  5267. .formats = WCD9360_FORMATS_S16_S24_S32_LE,
  5268. .rate_min = 8000,
  5269. .rate_max = 384000,
  5270. .channels_min = 1,
  5271. .channels_max = 2,
  5272. },
  5273. .ops = &pahu_dai_ops,
  5274. },
  5275. {
  5276. .name = "pahu_tx1",
  5277. .id = AIF1_CAP,
  5278. .capture = {
  5279. .stream_name = "AIF1 Capture",
  5280. .rates = WCD9360_RATES_MASK,
  5281. .formats = WCD9360_FORMATS_S16_S24_LE,
  5282. .rate_min = 8000,
  5283. .rate_max = 192000,
  5284. .channels_min = 1,
  5285. .channels_max = 8,
  5286. },
  5287. .ops = &pahu_dai_ops,
  5288. },
  5289. {
  5290. .name = "pahu_rx2",
  5291. .id = AIF2_PB,
  5292. .playback = {
  5293. .stream_name = "AIF2 Playback",
  5294. .rates = WCD9360_RATES_MASK | WCD9360_FRAC_RATES_MASK,
  5295. .formats = WCD9360_FORMATS_S16_S24_S32_LE,
  5296. .rate_min = 8000,
  5297. .rate_max = 384000,
  5298. .channels_min = 1,
  5299. .channels_max = 2,
  5300. },
  5301. .ops = &pahu_dai_ops,
  5302. },
  5303. {
  5304. .name = "pahu_tx2",
  5305. .id = AIF2_CAP,
  5306. .capture = {
  5307. .stream_name = "AIF2 Capture",
  5308. .rates = WCD9360_RATES_MASK,
  5309. .formats = WCD9360_FORMATS_S16_S24_LE,
  5310. .rate_min = 8000,
  5311. .rate_max = 192000,
  5312. .channels_min = 1,
  5313. .channels_max = 8,
  5314. },
  5315. .ops = &pahu_dai_ops,
  5316. },
  5317. {
  5318. .name = "pahu_rx3",
  5319. .id = AIF3_PB,
  5320. .playback = {
  5321. .stream_name = "AIF3 Playback",
  5322. .rates = WCD9360_RATES_MASK | WCD9360_FRAC_RATES_MASK,
  5323. .formats = WCD9360_FORMATS_S16_S24_S32_LE,
  5324. .rate_min = 8000,
  5325. .rate_max = 384000,
  5326. .channels_min = 1,
  5327. .channels_max = 2,
  5328. },
  5329. .ops = &pahu_dai_ops,
  5330. },
  5331. {
  5332. .name = "pahu_tx3",
  5333. .id = AIF3_CAP,
  5334. .capture = {
  5335. .stream_name = "AIF3 Capture",
  5336. .rates = WCD9360_RATES_MASK,
  5337. .formats = WCD9360_FORMATS_S16_S24_LE,
  5338. .rate_min = 8000,
  5339. .rate_max = 192000,
  5340. .channels_min = 1,
  5341. .channels_max = 8,
  5342. },
  5343. .ops = &pahu_dai_ops,
  5344. },
  5345. {
  5346. .name = "pahu_rx4",
  5347. .id = AIF4_PB,
  5348. .playback = {
  5349. .stream_name = "AIF4 Playback",
  5350. .rates = WCD9360_RATES_MASK | WCD9360_FRAC_RATES_MASK,
  5351. .formats = WCD9360_FORMATS_S16_S24_S32_LE,
  5352. .rate_min = 8000,
  5353. .rate_max = 384000,
  5354. .channels_min = 1,
  5355. .channels_max = 2,
  5356. },
  5357. .ops = &pahu_dai_ops,
  5358. },
  5359. {
  5360. .name = "pahu_vifeedback",
  5361. .id = AIF4_VIFEED,
  5362. .capture = {
  5363. .stream_name = "VIfeed",
  5364. .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_48000,
  5365. .formats = WCD9360_FORMATS_S16_S24_S32_LE,
  5366. .rate_min = 8000,
  5367. .rate_max = 48000,
  5368. .channels_min = 1,
  5369. .channels_max = 4,
  5370. },
  5371. .ops = &pahu_vi_dai_ops,
  5372. },
  5373. {
  5374. .name = "pahu_mad1",
  5375. .id = AIF4_MAD_TX,
  5376. .capture = {
  5377. .stream_name = "AIF4 MAD TX",
  5378. .rates = SNDRV_PCM_RATE_16000,
  5379. .formats = WCD9360_FORMATS_S16_LE,
  5380. .rate_min = 16000,
  5381. .rate_max = 16000,
  5382. .channels_min = 1,
  5383. .channels_max = 1,
  5384. },
  5385. .ops = &pahu_dai_ops,
  5386. },
  5387. };
  5388. static void pahu_codec_power_gate_digital_core(struct pahu_priv *pahu)
  5389. {
  5390. mutex_lock(&pahu->power_lock);
  5391. dev_dbg(pahu->dev, "%s: Entering power gating function, %d\n",
  5392. __func__, pahu->power_active_ref);
  5393. if (pahu->power_active_ref > 0)
  5394. goto exit;
  5395. wcd9xxx_set_power_state(pahu->wcd9xxx,
  5396. WCD_REGION_POWER_COLLAPSE_BEGIN,
  5397. WCD9XXX_DIG_CORE_REGION_1);
  5398. regmap_update_bits(pahu->wcd9xxx->regmap,
  5399. WCD9360_CODEC_RPM_PWR_CDC_DIG_HM_CTL, 0x04, 0x04);
  5400. regmap_update_bits(pahu->wcd9xxx->regmap,
  5401. WCD9360_CODEC_RPM_PWR_CDC_DIG_HM_CTL, 0x01, 0x00);
  5402. regmap_update_bits(pahu->wcd9xxx->regmap,
  5403. WCD9360_CODEC_RPM_PWR_CDC_DIG_HM_CTL, 0x02, 0x00);
  5404. wcd9xxx_set_power_state(pahu->wcd9xxx, WCD_REGION_POWER_DOWN,
  5405. WCD9XXX_DIG_CORE_REGION_1);
  5406. exit:
  5407. dev_dbg(pahu->dev, "%s: Exiting power gating function, %d\n",
  5408. __func__, pahu->power_active_ref);
  5409. mutex_unlock(&pahu->power_lock);
  5410. }
  5411. static void pahu_codec_power_gate_work(struct work_struct *work)
  5412. {
  5413. struct pahu_priv *pahu;
  5414. struct delayed_work *dwork;
  5415. dwork = to_delayed_work(work);
  5416. pahu = container_of(dwork, struct pahu_priv, power_gate_work);
  5417. pahu_codec_power_gate_digital_core(pahu);
  5418. }
  5419. /* called under power_lock acquisition */
  5420. static int pahu_dig_core_remove_power_collapse(struct pahu_priv *pahu)
  5421. {
  5422. regmap_write(pahu->wcd9xxx->regmap,
  5423. WCD9360_CODEC_RPM_PWR_CDC_DIG_HM_CTL, 0x05);
  5424. regmap_write(pahu->wcd9xxx->regmap,
  5425. WCD9360_CODEC_RPM_PWR_CDC_DIG_HM_CTL, 0x07);
  5426. regmap_update_bits(pahu->wcd9xxx->regmap,
  5427. WCD9360_CODEC_RPM_RST_CTL, 0x02, 0x00);
  5428. regmap_update_bits(pahu->wcd9xxx->regmap,
  5429. WCD9360_CODEC_RPM_RST_CTL, 0x02, 0x02);
  5430. regmap_write(pahu->wcd9xxx->regmap,
  5431. WCD9360_CODEC_RPM_PWR_CDC_DIG_HM_CTL, 0x03);
  5432. wcd9xxx_set_power_state(pahu->wcd9xxx,
  5433. WCD_REGION_POWER_COLLAPSE_REMOVE,
  5434. WCD9XXX_DIG_CORE_REGION_1);
  5435. regcache_mark_dirty(pahu->wcd9xxx->regmap);
  5436. regcache_sync_region(pahu->wcd9xxx->regmap,
  5437. WCD9360_DIG_CORE_REG_MIN,
  5438. WCD9360_DIG_CORE_REG_MAX);
  5439. return 0;
  5440. }
  5441. static int pahu_dig_core_power_collapse(struct pahu_priv *pahu,
  5442. int req_state)
  5443. {
  5444. int cur_state;
  5445. /* Exit if feature is disabled */
  5446. if (!dig_core_collapse_enable)
  5447. return 0;
  5448. mutex_lock(&pahu->power_lock);
  5449. if (req_state == POWER_COLLAPSE)
  5450. pahu->power_active_ref--;
  5451. else if (req_state == POWER_RESUME)
  5452. pahu->power_active_ref++;
  5453. else
  5454. goto unlock_mutex;
  5455. if (pahu->power_active_ref < 0) {
  5456. dev_dbg(pahu->dev, "%s: power_active_ref is negative\n",
  5457. __func__);
  5458. goto unlock_mutex;
  5459. }
  5460. if (req_state == POWER_COLLAPSE) {
  5461. if (pahu->power_active_ref == 0) {
  5462. schedule_delayed_work(&pahu->power_gate_work,
  5463. msecs_to_jiffies(dig_core_collapse_timer * 1000));
  5464. }
  5465. } else if (req_state == POWER_RESUME) {
  5466. if (pahu->power_active_ref == 1) {
  5467. /*
  5468. * At this point, there can be two cases:
  5469. * 1. Core already in power collapse state
  5470. * 2. Timer kicked in and still did not expire or
  5471. * waiting for the power_lock
  5472. */
  5473. cur_state = wcd9xxx_get_current_power_state(
  5474. pahu->wcd9xxx,
  5475. WCD9XXX_DIG_CORE_REGION_1);
  5476. if (cur_state == WCD_REGION_POWER_DOWN) {
  5477. pahu_dig_core_remove_power_collapse(pahu);
  5478. } else {
  5479. mutex_unlock(&pahu->power_lock);
  5480. cancel_delayed_work_sync(
  5481. &pahu->power_gate_work);
  5482. mutex_lock(&pahu->power_lock);
  5483. }
  5484. }
  5485. }
  5486. unlock_mutex:
  5487. mutex_unlock(&pahu->power_lock);
  5488. return 0;
  5489. }
  5490. static int pahu_cdc_req_mclk_enable(struct pahu_priv *pahu,
  5491. bool enable)
  5492. {
  5493. int ret = 0;
  5494. if (enable) {
  5495. ret = clk_prepare_enable(pahu->wcd_ext_clk);
  5496. if (ret) {
  5497. dev_err(pahu->dev, "%s: ext clk enable failed\n",
  5498. __func__);
  5499. goto done;
  5500. }
  5501. /* get BG */
  5502. wcd_resmgr_enable_master_bias(pahu->resmgr);
  5503. /* get MCLK */
  5504. wcd_resmgr_enable_clk_block(pahu->resmgr, WCD_CLK_MCLK);
  5505. } else {
  5506. /* put MCLK */
  5507. wcd_resmgr_disable_clk_block(pahu->resmgr, WCD_CLK_MCLK);
  5508. /* put BG */
  5509. wcd_resmgr_disable_master_bias(pahu->resmgr);
  5510. clk_disable_unprepare(pahu->wcd_ext_clk);
  5511. }
  5512. done:
  5513. return ret;
  5514. }
  5515. static int __pahu_cdc_mclk_enable_locked(struct pahu_priv *pahu,
  5516. bool enable)
  5517. {
  5518. int ret = 0;
  5519. if (!pahu->wcd_ext_clk) {
  5520. dev_err(pahu->dev, "%s: wcd ext clock is NULL\n", __func__);
  5521. return -EINVAL;
  5522. }
  5523. dev_dbg(pahu->dev, "%s: mclk_enable = %u\n", __func__, enable);
  5524. if (enable) {
  5525. pahu_dig_core_power_collapse(pahu, POWER_RESUME);
  5526. pahu_vote_svs(pahu, true);
  5527. ret = pahu_cdc_req_mclk_enable(pahu, true);
  5528. if (ret)
  5529. goto done;
  5530. } else {
  5531. pahu_cdc_req_mclk_enable(pahu, false);
  5532. pahu_vote_svs(pahu, false);
  5533. pahu_dig_core_power_collapse(pahu, POWER_COLLAPSE);
  5534. }
  5535. done:
  5536. return ret;
  5537. }
  5538. static int __pahu_cdc_mclk_enable(struct pahu_priv *pahu,
  5539. bool enable)
  5540. {
  5541. int ret;
  5542. WCD9XXX_V2_BG_CLK_LOCK(pahu->resmgr);
  5543. ret = __pahu_cdc_mclk_enable_locked(pahu, enable);
  5544. if (enable)
  5545. wcd_resmgr_set_sido_input_src(pahu->resmgr,
  5546. SIDO_SOURCE_RCO_BG);
  5547. WCD9XXX_V2_BG_CLK_UNLOCK(pahu->resmgr);
  5548. return ret;
  5549. }
  5550. static ssize_t pahu_codec_version_read(struct snd_info_entry *entry,
  5551. void *file_private_data,
  5552. struct file *file,
  5553. char __user *buf, size_t count,
  5554. loff_t pos)
  5555. {
  5556. struct pahu_priv *pahu;
  5557. struct wcd9xxx *wcd9xxx;
  5558. char buffer[PAHU_VERSION_ENTRY_SIZE];
  5559. int len = 0;
  5560. pahu = (struct pahu_priv *) entry->private_data;
  5561. if (!pahu) {
  5562. pr_err("%s: pahu priv is null\n", __func__);
  5563. return -EINVAL;
  5564. }
  5565. wcd9xxx = pahu->wcd9xxx;
  5566. switch (wcd9xxx->version) {
  5567. case PAHU_VERSION_1_0:
  5568. len = snprintf(buffer, sizeof(buffer), "WCD9360_1_0\n");
  5569. break;
  5570. default:
  5571. len = snprintf(buffer, sizeof(buffer), "VER_UNDEFINED\n");
  5572. }
  5573. return simple_read_from_buffer(buf, count, &pos, buffer, len);
  5574. }
  5575. static struct snd_info_entry_ops pahu_codec_info_ops = {
  5576. .read = pahu_codec_version_read,
  5577. };
  5578. /*
  5579. * pahu_codec_info_create_codec_entry - creates wcd9360 module
  5580. * @codec_root: The parent directory
  5581. * @codec: Codec instance
  5582. *
  5583. * Creates wcd9360 module and version entry under the given
  5584. * parent directory.
  5585. *
  5586. * Return: 0 on success or negative error code on failure.
  5587. */
  5588. int pahu_codec_info_create_codec_entry(struct snd_info_entry *codec_root,
  5589. struct snd_soc_codec *codec)
  5590. {
  5591. struct snd_info_entry *version_entry;
  5592. struct pahu_priv *pahu;
  5593. struct snd_soc_card *card;
  5594. if (!codec_root || !codec)
  5595. return -EINVAL;
  5596. pahu = snd_soc_codec_get_drvdata(codec);
  5597. card = codec->component.card;
  5598. pahu->entry = snd_info_create_subdir(codec_root->module,
  5599. "pahu", codec_root);
  5600. if (!pahu->entry) {
  5601. dev_dbg(codec->dev, "%s: failed to create wcd9360 entry\n",
  5602. __func__);
  5603. return -ENOMEM;
  5604. }
  5605. version_entry = snd_info_create_card_entry(card->snd_card,
  5606. "version",
  5607. pahu->entry);
  5608. if (!version_entry) {
  5609. dev_dbg(codec->dev, "%s: failed to create wcd9360 version entry\n",
  5610. __func__);
  5611. return -ENOMEM;
  5612. }
  5613. version_entry->private_data = pahu;
  5614. version_entry->size = PAHU_VERSION_ENTRY_SIZE;
  5615. version_entry->content = SNDRV_INFO_CONTENT_DATA;
  5616. version_entry->c.ops = &pahu_codec_info_ops;
  5617. if (snd_info_register(version_entry) < 0) {
  5618. snd_info_free_entry(version_entry);
  5619. return -ENOMEM;
  5620. }
  5621. pahu->version_entry = version_entry;
  5622. return 0;
  5623. }
  5624. EXPORT_SYMBOL(pahu_codec_info_create_codec_entry);
  5625. /**
  5626. * pahu_cdc_mclk_enable - Enable/disable codec mclk
  5627. *
  5628. * @codec: codec instance
  5629. * @enable: Indicates clk enable or disable
  5630. *
  5631. * Returns 0 on Success and error on failure
  5632. */
  5633. int pahu_cdc_mclk_enable(struct snd_soc_codec *codec, bool enable)
  5634. {
  5635. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(codec);
  5636. return __pahu_cdc_mclk_enable(pahu, enable);
  5637. }
  5638. EXPORT_SYMBOL(pahu_cdc_mclk_enable);
  5639. static int __pahu_codec_internal_rco_ctrl(struct snd_soc_codec *codec,
  5640. bool enable)
  5641. {
  5642. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(codec);
  5643. int ret = 0;
  5644. if (enable) {
  5645. if (wcd_resmgr_get_clk_type(pahu->resmgr) ==
  5646. WCD_CLK_RCO) {
  5647. ret = wcd_resmgr_enable_clk_block(pahu->resmgr,
  5648. WCD_CLK_RCO);
  5649. } else {
  5650. ret = pahu_cdc_req_mclk_enable(pahu, true);
  5651. if (ret) {
  5652. dev_err(codec->dev,
  5653. "%s: mclk_enable failed, err = %d\n",
  5654. __func__, ret);
  5655. goto done;
  5656. }
  5657. wcd_resmgr_set_sido_input_src(pahu->resmgr,
  5658. SIDO_SOURCE_RCO_BG);
  5659. ret = wcd_resmgr_enable_clk_block(pahu->resmgr,
  5660. WCD_CLK_RCO);
  5661. ret |= pahu_cdc_req_mclk_enable(pahu, false);
  5662. }
  5663. } else {
  5664. ret = wcd_resmgr_disable_clk_block(pahu->resmgr,
  5665. WCD_CLK_RCO);
  5666. }
  5667. if (ret) {
  5668. dev_err(codec->dev, "%s: Error in %s RCO\n",
  5669. __func__, (enable ? "enabling" : "disabling"));
  5670. ret = -EINVAL;
  5671. }
  5672. done:
  5673. return ret;
  5674. }
  5675. /*
  5676. * pahu_codec_internal_rco_ctrl: Enable/Disable codec's RCO clock
  5677. * @codec: Handle to the codec
  5678. * @enable: Indicates whether clock should be enabled or disabled
  5679. */
  5680. static int pahu_codec_internal_rco_ctrl(struct snd_soc_codec *codec,
  5681. bool enable)
  5682. {
  5683. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(codec);
  5684. int ret = 0;
  5685. WCD9XXX_V2_BG_CLK_LOCK(pahu->resmgr);
  5686. ret = __pahu_codec_internal_rco_ctrl(codec, enable);
  5687. WCD9XXX_V2_BG_CLK_UNLOCK(pahu->resmgr);
  5688. return ret;
  5689. }
  5690. /*
  5691. * pahu_cdc_mclk_tx_enable: Enable/Disable codec's clock for TX path
  5692. * @codec: Handle to codec
  5693. * @enable: Indicates whether clock should be enabled or disabled
  5694. */
  5695. int pahu_cdc_mclk_tx_enable(struct snd_soc_codec *codec, bool enable)
  5696. {
  5697. struct pahu_priv *pahu_p;
  5698. int ret = 0;
  5699. bool clk_mode;
  5700. bool clk_internal;
  5701. if (!codec)
  5702. return -EINVAL;
  5703. pahu_p = snd_soc_codec_get_drvdata(codec);
  5704. clk_mode = test_bit(CLK_MODE, &pahu_p->status_mask);
  5705. clk_internal = test_bit(CLK_INTERNAL, &pahu_p->status_mask);
  5706. dev_dbg(codec->dev, "%s: clkmode: %d, enable: %d, clk_internal: %d\n",
  5707. __func__, clk_mode, enable, clk_internal);
  5708. if (clk_mode || clk_internal) {
  5709. if (enable) {
  5710. wcd_resmgr_enable_master_bias(pahu_p->resmgr);
  5711. pahu_dig_core_power_collapse(pahu_p, POWER_RESUME);
  5712. pahu_vote_svs(pahu_p, true);
  5713. ret = pahu_codec_internal_rco_ctrl(codec, enable);
  5714. set_bit(CLK_INTERNAL, &pahu_p->status_mask);
  5715. } else {
  5716. clear_bit(CLK_INTERNAL, &pahu_p->status_mask);
  5717. pahu_codec_internal_rco_ctrl(codec, enable);
  5718. pahu_vote_svs(pahu_p, false);
  5719. pahu_dig_core_power_collapse(pahu_p, POWER_COLLAPSE);
  5720. wcd_resmgr_disable_master_bias(pahu_p->resmgr);
  5721. }
  5722. } else {
  5723. ret = __pahu_cdc_mclk_enable(pahu_p, enable);
  5724. }
  5725. return ret;
  5726. }
  5727. EXPORT_SYMBOL(pahu_cdc_mclk_tx_enable);
  5728. static const struct wcd_resmgr_cb pahu_resmgr_cb = {
  5729. .cdc_rco_ctrl = __pahu_codec_internal_rco_ctrl,
  5730. };
  5731. static const struct pahu_reg_mask_val pahu_codec_mclk2_1_0_defaults[] = {
  5732. /*
  5733. * PLL Settings:
  5734. * Clock Root: MCLK2,
  5735. * Clock Source: EXT_CLK,
  5736. * Clock Destination: MCLK2
  5737. * Clock Freq In: 19.2MHz,
  5738. * Clock Freq Out: 11.2896MHz
  5739. */
  5740. {WCD9360_CLK_SYS_MCLK2_PRG1, 0x60, 0x20},
  5741. {WCD9360_CLK_SYS_INT_POST_DIV_REG0, 0xFF, 0x5E},
  5742. {WCD9360_CLK_SYS_INT_POST_DIV_REG1, 0x1F, 0x1F},
  5743. {WCD9360_CLK_SYS_INT_REF_DIV_REG0, 0xFF, 0x54},
  5744. {WCD9360_CLK_SYS_INT_REF_DIV_REG1, 0xFF, 0x01},
  5745. {WCD9360_CLK_SYS_INT_FILTER_REG1, 0x07, 0x04},
  5746. {WCD9360_CLK_SYS_INT_PLL_L_VAL, 0xFF, 0x93},
  5747. {WCD9360_CLK_SYS_INT_PLL_N_VAL, 0xFF, 0xFA},
  5748. {WCD9360_CLK_SYS_INT_TEST_REG0, 0xFF, 0x90},
  5749. {WCD9360_CLK_SYS_INT_PFD_CP_DSM_PROG, 0xFF, 0x7E},
  5750. {WCD9360_CLK_SYS_INT_VCO_PROG, 0xFF, 0xF8},
  5751. {WCD9360_CLK_SYS_INT_TEST_REG1, 0xFF, 0x68},
  5752. {WCD9360_CLK_SYS_INT_LDO_LOCK_CFG, 0xFF, 0x40},
  5753. {WCD9360_CLK_SYS_INT_DIG_LOCK_DET_CFG, 0xFF, 0x32},
  5754. };
  5755. static const struct pahu_reg_mask_val pahu_codec_reg_defaults[] = {
  5756. {WCD9360_BIAS_VBG_FINE_ADJ, 0xFF, 0x75},
  5757. {WCD9360_CODEC_RPM_CLK_MCLK_CFG, 0x03, 0x01},
  5758. {WCD9360_CODEC_CPR_SVS_CX_VDD, 0xFF, 0x7C}, /* value in svs mode */
  5759. {WCD9360_CODEC_CPR_SVS2_CX_VDD, 0xFF, 0x58}, /* value in svs2 mode */
  5760. {WCD9360_CDC_RX0_RX_PATH_DSMDEM_CTL, 0x01, 0x01},
  5761. {WCD9360_CDC_RX7_RX_PATH_DSMDEM_CTL, 0x01, 0x01},
  5762. {WCD9360_CDC_RX8_RX_PATH_DSMDEM_CTL, 0x01, 0x01},
  5763. {WCD9360_CDC_RX9_RX_PATH_DSMDEM_CTL, 0x01, 0x01},
  5764. {WCD9360_CDC_COMPANDER8_CTL7, 0x1E, 0x18},
  5765. {WCD9360_CDC_COMPANDER7_CTL7, 0x1E, 0x18},
  5766. {WCD9360_CDC_RX0_RX_PATH_SEC0, 0x08, 0x00},
  5767. {WCD9360_CDC_RX9_RX_PATH_SEC0, 0x08, 0x00},
  5768. {WCD9360_MICB1_TEST_CTL_2, 0x07, 0x01},
  5769. {WCD9360_CDC_BOOST0_BOOST_CFG1, 0x3F, 0x12},
  5770. {WCD9360_CDC_BOOST0_BOOST_CFG2, 0x1C, 0x08},
  5771. {WCD9360_CDC_BOOST1_BOOST_CFG1, 0x3F, 0x12},
  5772. {WCD9360_CDC_BOOST1_BOOST_CFG2, 0x1C, 0x08},
  5773. {WCD9360_CPE_SS_CPARMAD_BUFRDY_INT_PERIOD, 0x1F, 0x09},
  5774. {WCD9360_CDC_TX0_TX_PATH_CFG1, 0x01, 0x00},
  5775. {WCD9360_CDC_TX1_TX_PATH_CFG1, 0x01, 0x00},
  5776. {WCD9360_CDC_TX2_TX_PATH_CFG1, 0x01, 0x00},
  5777. {WCD9360_CDC_TX3_TX_PATH_CFG1, 0x01, 0x00},
  5778. {WCD9360_CDC_TX4_TX_PATH_CFG1, 0x01, 0x00},
  5779. {WCD9360_CDC_TX5_TX_PATH_CFG1, 0x01, 0x00},
  5780. {WCD9360_CDC_TX6_TX_PATH_CFG1, 0x01, 0x00},
  5781. {WCD9360_CDC_TX7_TX_PATH_CFG1, 0x01, 0x00},
  5782. {WCD9360_CDC_TX8_TX_PATH_CFG1, 0x01, 0x00},
  5783. {WCD9360_CPE_FLL_CONFIG_CTL_2, 0xFF, 0x20},
  5784. {WCD9360_CPE_SS_DMIC_CFG, 0x80, 0x00},
  5785. {WCD9360_CDC_BOOST0_BOOST_CTL, 0x70, 0x50},
  5786. {WCD9360_CDC_BOOST1_BOOST_CTL, 0x70, 0x50},
  5787. {WCD9360_CDC_RX7_RX_PATH_CFG1, 0x08, 0x08},
  5788. {WCD9360_CDC_RX8_RX_PATH_CFG1, 0x08, 0x08},
  5789. {WCD9360_CDC_TOP_TOP_CFG1, 0x02, 0x02},
  5790. {WCD9360_CDC_TOP_TOP_CFG1, 0x01, 0x01},
  5791. {WCD9360_CDC_TOP_EAR_COMP_LUT, 0x80, 0x80},
  5792. {WCD9360_EAR_EAR_DAC_CON, 0x06, 0x02},
  5793. {WCD9360_AUX_INT_AUX_DAC_CON, 0x06, 0x02},
  5794. {WCD9360_CDC_TX9_SPKR_PROT_PATH_CFG0, 0x01, 0x01},
  5795. {WCD9360_CDC_TX10_SPKR_PROT_PATH_CFG0, 0x01, 0x01},
  5796. {WCD9360_CDC_TX11_SPKR_PROT_PATH_CFG0, 0x01, 0x01},
  5797. {WCD9360_CDC_TX12_SPKR_PROT_PATH_CFG0, 0x01, 0x01},
  5798. {WCD9360_DATA_HUB_SB_TX11_INP_CFG, 0x01, 0x01},
  5799. {WCD9360_CDC_CLK_RST_CTRL_FS_CNT_CONTROL, 0x01, 0x01},
  5800. {WCD9360_CDC_COMPANDER7_CTL3, 0x80, 0x80},
  5801. {WCD9360_CDC_COMPANDER8_CTL3, 0x80, 0x80},
  5802. {WCD9360_CDC_COMPANDER7_CTL7, 0x01, 0x01},
  5803. {WCD9360_CDC_COMPANDER8_CTL7, 0x01, 0x01},
  5804. {WCD9360_CODEC_RPM_CLK_GATE, 0x08, 0x00},
  5805. {WCD9360_TLMM_DMIC3_CLK_PINCFG, 0xFF, 0x0a},
  5806. {WCD9360_TLMM_DMIC3_DATA_PINCFG, 0xFF, 0x0a},
  5807. {WCD9360_CPE_SS_SVA_CFG, 0x60, 0x00},
  5808. {WCD9360_CPE_SS_CPAR_CFG, 0x10, 0x10},
  5809. };
  5810. static const struct pahu_cpr_reg_defaults cpr_defaults[] = {
  5811. { 0x00000820, 0x00000094 },
  5812. { 0x00000fC0, 0x00000048 },
  5813. { 0x0000f000, 0x00000044 },
  5814. { 0x0000bb80, 0xC0000178 },
  5815. { 0x00000000, 0x00000160 },
  5816. { 0x10854522, 0x00000060 },
  5817. { 0x10854509, 0x00000064 },
  5818. { 0x108544dd, 0x00000068 },
  5819. { 0x108544ad, 0x0000006C },
  5820. { 0x0000077E, 0x00000070 },
  5821. { 0x000007da, 0x00000074 },
  5822. { 0x00000000, 0x00000078 },
  5823. { 0x00000000, 0x0000007C },
  5824. { 0x00042029, 0x00000080 },
  5825. { 0x4002002A, 0x00000090 },
  5826. { 0x4002002B, 0x00000090 },
  5827. };
  5828. static void pahu_update_reg_defaults(struct pahu_priv *pahu)
  5829. {
  5830. u32 i;
  5831. struct wcd9xxx *wcd9xxx;
  5832. wcd9xxx = pahu->wcd9xxx;
  5833. for (i = 0; i < ARRAY_SIZE(pahu_codec_reg_defaults); i++)
  5834. regmap_update_bits(wcd9xxx->regmap,
  5835. pahu_codec_reg_defaults[i].reg,
  5836. pahu_codec_reg_defaults[i].mask,
  5837. pahu_codec_reg_defaults[i].val);
  5838. }
  5839. static void pahu_update_cpr_defaults(struct pahu_priv *pahu)
  5840. {
  5841. int i;
  5842. struct wcd9xxx *wcd9xxx;
  5843. wcd9xxx = pahu->wcd9xxx;
  5844. __pahu_cdc_mclk_enable(pahu, true);
  5845. regmap_update_bits(wcd9xxx->regmap, WCD9360_CODEC_RPM_CLK_GATE,
  5846. 0x10, 0x00);
  5847. for (i = 0; i < ARRAY_SIZE(cpr_defaults); i++) {
  5848. regmap_bulk_write(wcd9xxx->regmap,
  5849. WCD9360_CODEC_CPR_WR_DATA_0,
  5850. (u8 *)&cpr_defaults[i].wr_data, 4);
  5851. regmap_bulk_write(wcd9xxx->regmap,
  5852. WCD9360_CODEC_CPR_WR_ADDR_0,
  5853. (u8 *)&cpr_defaults[i].wr_addr, 4);
  5854. }
  5855. __pahu_cdc_mclk_enable(pahu, false);
  5856. }
  5857. static void pahu_slim_interface_init_reg(struct snd_soc_codec *codec)
  5858. {
  5859. int i;
  5860. struct pahu_priv *priv = snd_soc_codec_get_drvdata(codec);
  5861. for (i = 0; i < WCD9XXX_SLIM_NUM_PORT_REG; i++)
  5862. wcd9xxx_interface_reg_write(priv->wcd9xxx,
  5863. WCD9360_SLIM_PGD_PORT_INT_RX_EN0 + i,
  5864. 0xFF);
  5865. }
  5866. static irqreturn_t pahu_misc_irq(int irq, void *data)
  5867. {
  5868. struct pahu_priv *pahu = data;
  5869. int misc_val;
  5870. /* Find source of interrupt */
  5871. regmap_read(pahu->wcd9xxx->regmap, WCD9360_INTR_CODEC_MISC_STATUS,
  5872. &misc_val);
  5873. dev_dbg(pahu->dev, "%s: Codec misc irq: %d, val: 0x%x\n",
  5874. __func__, irq, misc_val);
  5875. /* Clear interrupt status */
  5876. regmap_update_bits(pahu->wcd9xxx->regmap,
  5877. WCD9360_INTR_CODEC_MISC_CLEAR, misc_val, 0x00);
  5878. return IRQ_HANDLED;
  5879. }
  5880. static irqreturn_t pahu_slimbus_irq(int irq, void *data)
  5881. {
  5882. struct pahu_priv *pahu = data;
  5883. unsigned long status = 0;
  5884. int i, j, port_id, k;
  5885. u32 bit;
  5886. u8 val, int_val = 0;
  5887. bool tx, cleared;
  5888. unsigned short reg = 0;
  5889. for (i = WCD9360_SLIM_PGD_PORT_INT_STATUS_RX_0, j = 0;
  5890. i <= WCD9360_SLIM_PGD_PORT_INT_STATUS_TX_1; i++, j++) {
  5891. val = wcd9xxx_interface_reg_read(pahu->wcd9xxx, i);
  5892. status |= ((u32)val << (8 * j));
  5893. }
  5894. for_each_set_bit(j, &status, 32) {
  5895. tx = (j >= 16 ? true : false);
  5896. port_id = (tx ? j - 16 : j);
  5897. val = wcd9xxx_interface_reg_read(pahu->wcd9xxx,
  5898. WCD9360_SLIM_PGD_PORT_INT_RX_SOURCE0 + j);
  5899. if (val) {
  5900. if (!tx)
  5901. reg = WCD9360_SLIM_PGD_PORT_INT_RX_EN0 +
  5902. (port_id / 8);
  5903. else
  5904. reg = WCD9360_SLIM_PGD_PORT_INT_TX_EN0 +
  5905. (port_id / 8);
  5906. int_val = wcd9xxx_interface_reg_read(
  5907. pahu->wcd9xxx, reg);
  5908. /*
  5909. * Ignore interrupts for ports for which the
  5910. * interrupts are not specifically enabled.
  5911. */
  5912. if (!(int_val & (1 << (port_id % 8))))
  5913. continue;
  5914. }
  5915. if (val & WCD9360_SLIM_IRQ_OVERFLOW)
  5916. dev_err_ratelimited(pahu->dev, "%s: overflow error on %s port %d, value %x\n",
  5917. __func__, (tx ? "TX" : "RX"), port_id, val);
  5918. if (val & WCD9360_SLIM_IRQ_UNDERFLOW)
  5919. dev_err_ratelimited(pahu->dev, "%s: underflow error on %s port %d, value %x\n",
  5920. __func__, (tx ? "TX" : "RX"), port_id, val);
  5921. if ((val & WCD9360_SLIM_IRQ_OVERFLOW) ||
  5922. (val & WCD9360_SLIM_IRQ_UNDERFLOW)) {
  5923. if (!tx)
  5924. reg = WCD9360_SLIM_PGD_PORT_INT_RX_EN0 +
  5925. (port_id / 8);
  5926. else
  5927. reg = WCD9360_SLIM_PGD_PORT_INT_TX_EN0 +
  5928. (port_id / 8);
  5929. int_val = wcd9xxx_interface_reg_read(
  5930. pahu->wcd9xxx, reg);
  5931. if (int_val & (1 << (port_id % 8))) {
  5932. int_val = int_val ^ (1 << (port_id % 8));
  5933. wcd9xxx_interface_reg_write(pahu->wcd9xxx,
  5934. reg, int_val);
  5935. }
  5936. }
  5937. if (val & WCD9360_SLIM_IRQ_PORT_CLOSED) {
  5938. /*
  5939. * INT SOURCE register starts from RX to TX
  5940. * but port number in the ch_mask is in opposite way
  5941. */
  5942. bit = (tx ? j - 16 : j + 16);
  5943. dev_dbg(pahu->dev, "%s: %s port %d closed value %x, bit %u\n",
  5944. __func__, (tx ? "TX" : "RX"), port_id, val,
  5945. bit);
  5946. for (k = 0, cleared = false; k < NUM_CODEC_DAIS; k++) {
  5947. dev_dbg(pahu->dev, "%s: pahu->dai[%d].ch_mask = 0x%lx\n",
  5948. __func__, k, pahu->dai[k].ch_mask);
  5949. if (test_and_clear_bit(bit,
  5950. &pahu->dai[k].ch_mask)) {
  5951. cleared = true;
  5952. if (!pahu->dai[k].ch_mask)
  5953. wake_up(
  5954. &pahu->dai[k].dai_wait);
  5955. /*
  5956. * There are cases when multiple DAIs
  5957. * might be using the same slimbus
  5958. * channel. Hence don't break here.
  5959. */
  5960. }
  5961. }
  5962. }
  5963. wcd9xxx_interface_reg_write(pahu->wcd9xxx,
  5964. WCD9360_SLIM_PGD_PORT_INT_CLR_RX_0 +
  5965. (j / 8),
  5966. 1 << (j % 8));
  5967. }
  5968. return IRQ_HANDLED;
  5969. }
  5970. static int pahu_setup_irqs(struct pahu_priv *pahu)
  5971. {
  5972. int ret = 0;
  5973. struct snd_soc_codec *codec = pahu->codec;
  5974. struct wcd9xxx *wcd9xxx = pahu->wcd9xxx;
  5975. struct wcd9xxx_core_resource *core_res =
  5976. &wcd9xxx->core_res;
  5977. ret = wcd9xxx_request_irq(core_res, WCD9XXX_IRQ_SLIMBUS,
  5978. pahu_slimbus_irq, "SLIMBUS Slave", pahu);
  5979. if (ret)
  5980. dev_err(codec->dev, "%s: Failed to request irq %d\n", __func__,
  5981. WCD9XXX_IRQ_SLIMBUS);
  5982. else
  5983. pahu_slim_interface_init_reg(codec);
  5984. /* Register for misc interrupts as well */
  5985. ret = wcd9xxx_request_irq(core_res, WCD9360_IRQ_MISC,
  5986. pahu_misc_irq, "CDC MISC Irq", pahu);
  5987. if (ret)
  5988. dev_err(codec->dev, "%s: Failed to request cdc misc irq\n",
  5989. __func__);
  5990. return ret;
  5991. }
  5992. static void pahu_init_slim_slave_cfg(struct snd_soc_codec *codec)
  5993. {
  5994. struct pahu_priv *priv = snd_soc_codec_get_drvdata(codec);
  5995. struct afe_param_cdc_slimbus_slave_cfg *cfg;
  5996. struct wcd9xxx *wcd9xxx = priv->wcd9xxx;
  5997. uint64_t eaddr = 0;
  5998. cfg = &priv->slimbus_slave_cfg;
  5999. cfg->minor_version = 1;
  6000. cfg->tx_slave_port_offset = 0;
  6001. cfg->rx_slave_port_offset = 16;
  6002. memcpy(&eaddr, &wcd9xxx->slim->e_addr, sizeof(wcd9xxx->slim->e_addr));
  6003. WARN_ON(sizeof(wcd9xxx->slim->e_addr) != 6);
  6004. cfg->device_enum_addr_lsw = eaddr & 0xFFFFFFFF;
  6005. cfg->device_enum_addr_msw = eaddr >> 32;
  6006. dev_dbg(codec->dev, "%s: slimbus logical address 0x%llx\n",
  6007. __func__, eaddr);
  6008. }
  6009. static void pahu_cleanup_irqs(struct pahu_priv *pahu)
  6010. {
  6011. struct wcd9xxx *wcd9xxx = pahu->wcd9xxx;
  6012. struct wcd9xxx_core_resource *core_res =
  6013. &wcd9xxx->core_res;
  6014. wcd9xxx_free_irq(core_res, WCD9XXX_IRQ_SLIMBUS, pahu);
  6015. wcd9xxx_free_irq(core_res, WCD9360_IRQ_MISC, pahu);
  6016. }
  6017. /*
  6018. * wcd9360_get_micb_vout_ctl_val: converts micbias from volts to register value
  6019. * @micb_mv: micbias in mv
  6020. *
  6021. * return register value converted
  6022. */
  6023. int wcd9360_get_micb_vout_ctl_val(u32 micb_mv)
  6024. {
  6025. /* min micbias voltage is 1V and maximum is 2.85V */
  6026. if (micb_mv < 1000 || micb_mv > 2850) {
  6027. pr_err("%s: unsupported micbias voltage\n", __func__);
  6028. return -EINVAL;
  6029. }
  6030. return (micb_mv - 1000) / 50;
  6031. }
  6032. EXPORT_SYMBOL(wcd9360_get_micb_vout_ctl_val);
  6033. static int pahu_handle_pdata(struct pahu_priv *pahu,
  6034. struct wcd9xxx_pdata *pdata)
  6035. {
  6036. struct snd_soc_codec *codec = pahu->codec;
  6037. u8 mad_dmic_ctl_val;
  6038. u8 anc_ctl_value;
  6039. u32 dmic_clk_drv;
  6040. int vout_ctl_1, vout_ctl_2, vout_ctl_3, vout_ctl_4;
  6041. int rc = 0;
  6042. if (!pdata) {
  6043. dev_err(codec->dev, "%s: NULL pdata\n", __func__);
  6044. return -ENODEV;
  6045. }
  6046. /* set micbias voltage */
  6047. vout_ctl_1 = wcd9360_get_micb_vout_ctl_val(pdata->micbias.micb1_mv);
  6048. vout_ctl_2 = wcd9360_get_micb_vout_ctl_val(pdata->micbias.micb2_mv);
  6049. vout_ctl_3 = wcd9360_get_micb_vout_ctl_val(pdata->micbias.micb3_mv);
  6050. vout_ctl_4 = wcd9360_get_micb_vout_ctl_val(pdata->micbias.micb4_mv);
  6051. if (vout_ctl_1 < 0 || vout_ctl_2 < 0 ||
  6052. vout_ctl_3 < 0 || vout_ctl_4 < 0) {
  6053. rc = -EINVAL;
  6054. goto done;
  6055. }
  6056. snd_soc_update_bits(codec, WCD9360_ANA_MICB1, 0x3F, vout_ctl_1);
  6057. snd_soc_update_bits(codec, WCD9360_ANA_MICB2, 0x3F, vout_ctl_2);
  6058. snd_soc_update_bits(codec, WCD9360_ANA_MICB3, 0x3F, vout_ctl_3);
  6059. snd_soc_update_bits(codec, WCD9360_ANA_MICB4, 0x3F, vout_ctl_4);
  6060. if (pdata->dmic_sample_rate ==
  6061. WCD9XXX_DMIC_SAMPLE_RATE_UNDEFINED) {
  6062. dev_info(codec->dev, "%s: dmic_rate invalid default = %d\n",
  6063. __func__, WCD9XXX_DMIC_SAMPLE_RATE_4P8MHZ);
  6064. pdata->dmic_sample_rate = WCD9XXX_DMIC_SAMPLE_RATE_4P8MHZ;
  6065. }
  6066. if (pdata->mad_dmic_sample_rate ==
  6067. WCD9XXX_DMIC_SAMPLE_RATE_UNDEFINED) {
  6068. dev_info(codec->dev, "%s: mad_dmic_rate invalid default = %d\n",
  6069. __func__, WCD9XXX_DMIC_SAMPLE_RATE_4P8MHZ);
  6070. /*
  6071. * use dmic_sample_rate as the default for MAD
  6072. * if mad dmic sample rate is undefined
  6073. */
  6074. pdata->mad_dmic_sample_rate = pdata->dmic_sample_rate;
  6075. }
  6076. if (pdata->dmic_clk_drv ==
  6077. WCD9XXX_DMIC_CLK_DRIVE_UNDEFINED) {
  6078. pdata->dmic_clk_drv = WCD9360_DMIC_CLK_DRIVE_DEFAULT;
  6079. dev_dbg(codec->dev,
  6080. "%s: dmic_clk_strength invalid, default = %d\n",
  6081. __func__, pdata->dmic_clk_drv);
  6082. }
  6083. switch (pdata->dmic_clk_drv) {
  6084. case 2:
  6085. dmic_clk_drv = 0;
  6086. break;
  6087. case 4:
  6088. dmic_clk_drv = 1;
  6089. break;
  6090. case 8:
  6091. dmic_clk_drv = 2;
  6092. break;
  6093. case 16:
  6094. dmic_clk_drv = 3;
  6095. break;
  6096. default:
  6097. dev_err(codec->dev,
  6098. "%s: invalid dmic_clk_drv %d, using default\n",
  6099. __func__, pdata->dmic_clk_drv);
  6100. dmic_clk_drv = 0;
  6101. break;
  6102. }
  6103. snd_soc_update_bits(codec, WCD9360_TEST_DEBUG_PAD_DRVCTL_0,
  6104. 0x0C, dmic_clk_drv << 2);
  6105. /*
  6106. * Default the DMIC clk rates to mad_dmic_sample_rate,
  6107. * whereas, the anc/txfe dmic rates to dmic_sample_rate
  6108. * since the anc/txfe are independent of mad block.
  6109. */
  6110. mad_dmic_ctl_val = pahu_get_dmic_clk_val(pahu->codec,
  6111. pdata->mad_dmic_sample_rate);
  6112. snd_soc_update_bits(codec, WCD9360_CPE_SS_DMIC0_CTL,
  6113. 0x0E, mad_dmic_ctl_val << 1);
  6114. snd_soc_update_bits(codec, WCD9360_CPE_SS_DMIC1_CTL,
  6115. 0x0E, mad_dmic_ctl_val << 1);
  6116. snd_soc_update_bits(codec, WCD9360_CPE_SS_DMIC2_CTL,
  6117. 0x0E, mad_dmic_ctl_val << 1);
  6118. if (dmic_clk_drv == WCD9360_DMIC_CLK_DIV_2)
  6119. anc_ctl_value = WCD9360_ANC_DMIC_X2_FULL_RATE;
  6120. else
  6121. anc_ctl_value = WCD9360_ANC_DMIC_X2_HALF_RATE;
  6122. snd_soc_update_bits(codec, WCD9360_CDC_ANC0_MODE_2_CTL,
  6123. 0x40, anc_ctl_value << 6);
  6124. snd_soc_update_bits(codec, WCD9360_CDC_ANC0_MODE_2_CTL,
  6125. 0x20, anc_ctl_value << 5);
  6126. done:
  6127. return rc;
  6128. }
  6129. static void pahu_cdc_vote_svs(struct snd_soc_codec *codec, bool vote)
  6130. {
  6131. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(codec);
  6132. return pahu_vote_svs(pahu, vote);
  6133. }
  6134. struct wcd_dsp_cdc_cb cdc_cb = {
  6135. .cdc_clk_en = pahu_codec_internal_rco_ctrl,
  6136. .cdc_vote_svs = pahu_cdc_vote_svs,
  6137. };
  6138. static int pahu_wdsp_initialize(struct snd_soc_codec *codec)
  6139. {
  6140. struct wcd9xxx *control;
  6141. struct pahu_priv *pahu;
  6142. struct wcd_dsp_params params;
  6143. int ret = 0;
  6144. control = dev_get_drvdata(codec->dev->parent);
  6145. pahu = snd_soc_codec_get_drvdata(codec);
  6146. params.cb = &cdc_cb;
  6147. params.irqs.cpe_ipc1_irq = WCD9360_IRQ_CPE1_INTR;
  6148. params.irqs.cpe_err_irq = WCD9360_IRQ_CPE_ERROR;
  6149. params.irqs.fatal_irqs = CPE_FATAL_IRQS;
  6150. params.clk_rate = control->mclk_rate;
  6151. params.dsp_instance = 0;
  6152. wcd9360_dsp_cntl_init(codec, &params, &pahu->wdsp_cntl);
  6153. if (!pahu->wdsp_cntl) {
  6154. dev_err(pahu->dev, "%s: wcd-dsp-control init failed\n",
  6155. __func__);
  6156. ret = -EINVAL;
  6157. }
  6158. return ret;
  6159. }
  6160. static void pahu_mclk2_reg_defaults(struct pahu_priv *pahu)
  6161. {
  6162. int i;
  6163. struct snd_soc_codec *codec = pahu->codec;
  6164. /* MCLK2 configuration */
  6165. for (i = 0; i < ARRAY_SIZE(pahu_codec_mclk2_1_0_defaults); i++)
  6166. snd_soc_update_bits(codec,
  6167. pahu_codec_mclk2_1_0_defaults[i].reg,
  6168. pahu_codec_mclk2_1_0_defaults[i].mask,
  6169. pahu_codec_mclk2_1_0_defaults[i].val);
  6170. }
  6171. static int pahu_device_down(struct wcd9xxx *wcd9xxx)
  6172. {
  6173. struct snd_soc_codec *codec;
  6174. struct pahu_priv *priv;
  6175. int count;
  6176. codec = (struct snd_soc_codec *)(wcd9xxx->ssr_priv);
  6177. priv = snd_soc_codec_get_drvdata(codec);
  6178. if (priv->swr.ctrl_data)
  6179. swrm_wcd_notify(priv->swr.ctrl_data[0].swr_pdev,
  6180. SWR_DEVICE_DOWN, NULL);
  6181. snd_soc_card_change_online_state(codec->component.card, 0);
  6182. for (count = 0; count < NUM_CODEC_DAIS; count++)
  6183. priv->dai[count].bus_down_in_recovery = true;
  6184. wcd9360_dsp_ssr_event(priv->wdsp_cntl, WCD_CDC_DOWN_EVENT);
  6185. wcd_resmgr_set_sido_input_src_locked(priv->resmgr,
  6186. SIDO_SOURCE_INTERNAL);
  6187. return 0;
  6188. }
  6189. static int pahu_post_reset_cb(struct wcd9xxx *wcd9xxx)
  6190. {
  6191. int i, ret = 0;
  6192. struct wcd9xxx *control;
  6193. struct snd_soc_codec *codec;
  6194. struct pahu_priv *pahu;
  6195. struct wcd9xxx_pdata *pdata;
  6196. codec = (struct snd_soc_codec *)(wcd9xxx->ssr_priv);
  6197. pahu = snd_soc_codec_get_drvdata(codec);
  6198. control = dev_get_drvdata(codec->dev->parent);
  6199. wcd9xxx_set_power_state(pahu->wcd9xxx,
  6200. WCD_REGION_POWER_COLLAPSE_REMOVE,
  6201. WCD9XXX_DIG_CORE_REGION_1);
  6202. mutex_lock(&pahu->codec_mutex);
  6203. pahu_vote_svs(pahu, true);
  6204. pahu_slimbus_slave_port_cfg.slave_dev_intfdev_la =
  6205. control->slim_slave->laddr;
  6206. pahu_slimbus_slave_port_cfg.slave_dev_pgd_la =
  6207. control->slim->laddr;
  6208. pahu_init_slim_slave_cfg(codec);
  6209. snd_soc_card_change_online_state(codec->component.card, 1);
  6210. for (i = 0; i < PAHU_MAX_MICBIAS; i++)
  6211. pahu->micb_ref[i] = 0;
  6212. dev_dbg(codec->dev, "%s: MCLK Rate = %x\n",
  6213. __func__, control->mclk_rate);
  6214. pahu_update_reg_defaults(pahu);
  6215. wcd_resmgr_post_ssr_v2(pahu->resmgr);
  6216. __pahu_enable_efuse_sensing(pahu);
  6217. pahu_mclk2_reg_defaults(pahu);
  6218. __pahu_cdc_mclk_enable(pahu, true);
  6219. regcache_mark_dirty(codec->component.regmap);
  6220. regcache_sync(codec->component.regmap);
  6221. __pahu_cdc_mclk_enable(pahu, false);
  6222. pahu_update_cpr_defaults(pahu);
  6223. pdata = dev_get_platdata(codec->dev->parent);
  6224. ret = pahu_handle_pdata(pahu, pdata);
  6225. if (ret < 0)
  6226. dev_err(codec->dev, "%s: invalid pdata\n", __func__);
  6227. pahu_cleanup_irqs(pahu);
  6228. ret = pahu_setup_irqs(pahu);
  6229. if (ret) {
  6230. dev_err(codec->dev, "%s: pahu irq setup failed %d\n",
  6231. __func__, ret);
  6232. goto done;
  6233. }
  6234. pahu_set_spkr_mode(codec, pahu->swr.spkr_mode);
  6235. /*
  6236. * Once the codec initialization is completed, the svs vote
  6237. * can be released allowing the codec to go to SVS2.
  6238. */
  6239. pahu_vote_svs(pahu, false);
  6240. wcd9360_dsp_ssr_event(pahu->wdsp_cntl, WCD_CDC_UP_EVENT);
  6241. done:
  6242. mutex_unlock(&pahu->codec_mutex);
  6243. return ret;
  6244. }
  6245. static int pahu_soc_codec_probe(struct snd_soc_codec *codec)
  6246. {
  6247. struct wcd9xxx *control;
  6248. struct pahu_priv *pahu;
  6249. struct wcd9xxx_pdata *pdata;
  6250. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  6251. int i, ret;
  6252. void *ptr = NULL;
  6253. control = dev_get_drvdata(codec->dev->parent);
  6254. dev_info(codec->dev, "%s()\n", __func__);
  6255. pahu = snd_soc_codec_get_drvdata(codec);
  6256. pahu->intf_type = wcd9xxx_get_intf_type();
  6257. control->dev_down = pahu_device_down;
  6258. control->post_reset = pahu_post_reset_cb;
  6259. control->ssr_priv = (void *)codec;
  6260. /* Resource Manager post Init */
  6261. ret = wcd_resmgr_post_init(pahu->resmgr, &pahu_resmgr_cb, codec);
  6262. if (ret) {
  6263. dev_err(codec->dev, "%s: wcd resmgr post init failed\n",
  6264. __func__);
  6265. goto err;
  6266. }
  6267. pahu->fw_data = devm_kzalloc(codec->dev, sizeof(*(pahu->fw_data)),
  6268. GFP_KERNEL);
  6269. if (!pahu->fw_data)
  6270. goto err;
  6271. set_bit(WCD9XXX_ANC_CAL, pahu->fw_data->cal_bit);
  6272. set_bit(WCD9XXX_MAD_CAL, pahu->fw_data->cal_bit);
  6273. ret = wcd_cal_create_hwdep(pahu->fw_data,
  6274. WCD9XXX_CODEC_HWDEP_NODE, codec);
  6275. if (ret < 0) {
  6276. dev_err(codec->dev, "%s hwdep failed %d\n", __func__, ret);
  6277. goto err_hwdep;
  6278. }
  6279. pahu->codec = codec;
  6280. for (i = 0; i < COMPANDER_MAX; i++)
  6281. pahu->comp_enabled[i] = 0;
  6282. pdata = dev_get_platdata(codec->dev->parent);
  6283. ret = pahu_handle_pdata(pahu, pdata);
  6284. if (ret < 0) {
  6285. dev_err(codec->dev, "%s: bad pdata\n", __func__);
  6286. goto err_hwdep;
  6287. }
  6288. ptr = devm_kzalloc(codec->dev, (sizeof(pahu_rx_chs) +
  6289. sizeof(pahu_tx_chs)), GFP_KERNEL);
  6290. if (!ptr) {
  6291. ret = -ENOMEM;
  6292. goto err_hwdep;
  6293. }
  6294. snd_soc_dapm_add_routes(dapm, pahu_slim_audio_map,
  6295. ARRAY_SIZE(pahu_slim_audio_map));
  6296. for (i = 0; i < NUM_CODEC_DAIS; i++) {
  6297. INIT_LIST_HEAD(&pahu->dai[i].wcd9xxx_ch_list);
  6298. init_waitqueue_head(&pahu->dai[i].dai_wait);
  6299. }
  6300. pahu_slimbus_slave_port_cfg.slave_dev_intfdev_la =
  6301. control->slim_slave->laddr;
  6302. pahu_slimbus_slave_port_cfg.slave_dev_pgd_la =
  6303. control->slim->laddr;
  6304. pahu_slimbus_slave_port_cfg.slave_port_mapping[0] =
  6305. WCD9360_TX13;
  6306. pahu_init_slim_slave_cfg(codec);
  6307. control->num_rx_port = WCD9360_RX_MAX;
  6308. control->rx_chs = ptr;
  6309. memcpy(control->rx_chs, pahu_rx_chs, sizeof(pahu_rx_chs));
  6310. control->num_tx_port = WCD9360_TX_MAX;
  6311. control->tx_chs = ptr + sizeof(pahu_rx_chs);
  6312. memcpy(control->tx_chs, pahu_tx_chs, sizeof(pahu_tx_chs));
  6313. ret = pahu_setup_irqs(pahu);
  6314. if (ret) {
  6315. dev_err(pahu->dev, "%s: pahu irq setup failed %d\n",
  6316. __func__, ret);
  6317. goto err_pdata;
  6318. }
  6319. for (i = 0; i < WCD9360_NUM_DECIMATORS; i++) {
  6320. pahu->tx_hpf_work[i].pahu = pahu;
  6321. pahu->tx_hpf_work[i].decimator = i;
  6322. INIT_DELAYED_WORK(&pahu->tx_hpf_work[i].dwork,
  6323. pahu_tx_hpf_corner_freq_callback);
  6324. pahu->tx_mute_dwork[i].pahu = pahu;
  6325. pahu->tx_mute_dwork[i].decimator = i;
  6326. INIT_DELAYED_WORK(&pahu->tx_mute_dwork[i].dwork,
  6327. pahu_tx_mute_update_callback);
  6328. }
  6329. pahu->spk_anc_dwork.pahu = pahu;
  6330. INIT_DELAYED_WORK(&pahu->spk_anc_dwork.dwork,
  6331. pahu_spk_anc_update_callback);
  6332. pahu_mclk2_reg_defaults(pahu);
  6333. mutex_lock(&pahu->codec_mutex);
  6334. snd_soc_dapm_disable_pin(dapm, "ANC EAR PA");
  6335. snd_soc_dapm_disable_pin(dapm, "ANC EAR");
  6336. snd_soc_dapm_enable_pin(dapm, "ANC SPK1 PA");
  6337. mutex_unlock(&pahu->codec_mutex);
  6338. snd_soc_dapm_ignore_suspend(dapm, "AIF1 Playback");
  6339. snd_soc_dapm_ignore_suspend(dapm, "AIF1 Capture");
  6340. snd_soc_dapm_ignore_suspend(dapm, "AIF2 Playback");
  6341. snd_soc_dapm_ignore_suspend(dapm, "AIF2 Capture");
  6342. snd_soc_dapm_ignore_suspend(dapm, "AIF3 Playback");
  6343. snd_soc_dapm_ignore_suspend(dapm, "AIF3 Capture");
  6344. snd_soc_dapm_ignore_suspend(dapm, "AIF4 Playback");
  6345. snd_soc_dapm_ignore_suspend(dapm, "AIF4 MAD TX");
  6346. snd_soc_dapm_ignore_suspend(dapm, "VIfeed");
  6347. snd_soc_dapm_sync(dapm);
  6348. pahu_wdsp_initialize(codec);
  6349. /*
  6350. * Once the codec initialization is completed, the svs vote
  6351. * can be released allowing the codec to go to SVS2.
  6352. */
  6353. pahu_vote_svs(pahu, false);
  6354. return ret;
  6355. err_pdata:
  6356. devm_kfree(codec->dev, ptr);
  6357. control->rx_chs = NULL;
  6358. control->tx_chs = NULL;
  6359. err_hwdep:
  6360. devm_kfree(codec->dev, pahu->fw_data);
  6361. pahu->fw_data = NULL;
  6362. err:
  6363. return ret;
  6364. }
  6365. static int pahu_soc_codec_remove(struct snd_soc_codec *codec)
  6366. {
  6367. struct wcd9xxx *control;
  6368. struct pahu_priv *pahu = snd_soc_codec_get_drvdata(codec);
  6369. control = dev_get_drvdata(codec->dev->parent);
  6370. devm_kfree(codec->dev, control->rx_chs);
  6371. /* slimslave deinit in wcd core looks for this value */
  6372. control->num_rx_port = 0;
  6373. control->num_tx_port = 0;
  6374. control->rx_chs = NULL;
  6375. control->tx_chs = NULL;
  6376. pahu_cleanup_irqs(pahu);
  6377. if (pahu->wdsp_cntl)
  6378. wcd9360_dsp_cntl_deinit(&pahu->wdsp_cntl);
  6379. return 0;
  6380. }
  6381. static struct regmap *pahu_get_regmap(struct device *dev)
  6382. {
  6383. struct wcd9xxx *control = dev_get_drvdata(dev->parent);
  6384. return control->regmap;
  6385. }
  6386. static struct snd_soc_codec_driver soc_codec_dev_pahu = {
  6387. .probe = pahu_soc_codec_probe,
  6388. .remove = pahu_soc_codec_remove,
  6389. .get_regmap = pahu_get_regmap,
  6390. .component_driver = {
  6391. .controls = pahu_snd_controls,
  6392. .num_controls = ARRAY_SIZE(pahu_snd_controls),
  6393. .dapm_widgets = pahu_dapm_widgets,
  6394. .num_dapm_widgets = ARRAY_SIZE(pahu_dapm_widgets),
  6395. .dapm_routes = pahu_audio_map,
  6396. .num_dapm_routes = ARRAY_SIZE(pahu_audio_map),
  6397. },
  6398. };
  6399. #ifdef CONFIG_PM
  6400. static int pahu_suspend(struct device *dev)
  6401. {
  6402. struct platform_device *pdev = to_platform_device(dev);
  6403. struct pahu_priv *pahu = platform_get_drvdata(pdev);
  6404. if (!pahu) {
  6405. dev_err(dev, "%s: pahu private data is NULL\n", __func__);
  6406. return -EINVAL;
  6407. }
  6408. dev_dbg(dev, "%s: system suspend\n", __func__);
  6409. if (delayed_work_pending(&pahu->power_gate_work) &&
  6410. cancel_delayed_work_sync(&pahu->power_gate_work))
  6411. pahu_codec_power_gate_digital_core(pahu);
  6412. return 0;
  6413. }
  6414. static int pahu_resume(struct device *dev)
  6415. {
  6416. struct platform_device *pdev = to_platform_device(dev);
  6417. struct pahu_priv *pahu = platform_get_drvdata(pdev);
  6418. if (!pahu) {
  6419. dev_err(dev, "%s: pahu private data is NULL\n", __func__);
  6420. return -EINVAL;
  6421. }
  6422. dev_dbg(dev, "%s: system resume\n", __func__);
  6423. return 0;
  6424. }
  6425. static const struct dev_pm_ops pahu_pm_ops = {
  6426. .suspend = pahu_suspend,
  6427. .resume = pahu_resume,
  6428. };
  6429. #endif
  6430. static int pahu_swrm_read(void *handle, int reg)
  6431. {
  6432. struct pahu_priv *pahu;
  6433. struct wcd9xxx *wcd9xxx;
  6434. unsigned short swr_rd_addr_base;
  6435. unsigned short swr_rd_data_base;
  6436. int val, ret;
  6437. if (!handle) {
  6438. pr_err("%s: NULL handle\n", __func__);
  6439. return -EINVAL;
  6440. }
  6441. pahu = (struct pahu_priv *)handle;
  6442. wcd9xxx = pahu->wcd9xxx;
  6443. dev_dbg(pahu->dev, "%s: Reading soundwire register, 0x%x\n",
  6444. __func__, reg);
  6445. swr_rd_addr_base = WCD9360_SWR_AHB_BRIDGE_RD_ADDR_0;
  6446. swr_rd_data_base = WCD9360_SWR_AHB_BRIDGE_RD_DATA_0;
  6447. mutex_lock(&pahu->swr.read_mutex);
  6448. ret = regmap_bulk_write(wcd9xxx->regmap, swr_rd_addr_base,
  6449. (u8 *)&reg, 4);
  6450. if (ret < 0) {
  6451. dev_err(pahu->dev, "%s: RD Addr Failure\n", __func__);
  6452. goto done;
  6453. }
  6454. ret = regmap_bulk_read(wcd9xxx->regmap, swr_rd_data_base,
  6455. (u8 *)&val, 4);
  6456. if (ret < 0) {
  6457. dev_err(pahu->dev, "%s: RD Data Failure\n", __func__);
  6458. goto done;
  6459. }
  6460. ret = val;
  6461. done:
  6462. mutex_unlock(&pahu->swr.read_mutex);
  6463. return ret;
  6464. }
  6465. static int pahu_swrm_bulk_write(void *handle, u32 *reg, u32 *val, size_t len)
  6466. {
  6467. struct pahu_priv *pahu;
  6468. struct wcd9xxx *wcd9xxx;
  6469. struct wcd9xxx_reg_val *bulk_reg;
  6470. unsigned short swr_wr_addr_base;
  6471. unsigned short swr_wr_data_base;
  6472. int i, j, ret;
  6473. if (!handle || !reg || !val) {
  6474. pr_err("%s: NULL parameter\n", __func__);
  6475. return -EINVAL;
  6476. }
  6477. if (len <= 0) {
  6478. pr_err("%s: Invalid size: %zu\n", __func__, len);
  6479. return -EINVAL;
  6480. }
  6481. pahu = (struct pahu_priv *)handle;
  6482. wcd9xxx = pahu->wcd9xxx;
  6483. swr_wr_addr_base = WCD9360_SWR_AHB_BRIDGE_WR_ADDR_0;
  6484. swr_wr_data_base = WCD9360_SWR_AHB_BRIDGE_WR_DATA_0;
  6485. bulk_reg = kzalloc((2 * len * sizeof(struct wcd9xxx_reg_val)),
  6486. GFP_KERNEL);
  6487. if (!bulk_reg)
  6488. return -ENOMEM;
  6489. for (i = 0, j = 0; i < (len * 2); i += 2, j++) {
  6490. bulk_reg[i].reg = swr_wr_data_base;
  6491. bulk_reg[i].buf = (u8 *)(&val[j]);
  6492. bulk_reg[i].bytes = 4;
  6493. bulk_reg[i+1].reg = swr_wr_addr_base;
  6494. bulk_reg[i+1].buf = (u8 *)(&reg[j]);
  6495. bulk_reg[i+1].bytes = 4;
  6496. }
  6497. mutex_lock(&pahu->swr.write_mutex);
  6498. ret = wcd9xxx_slim_bulk_write(wcd9xxx, bulk_reg,
  6499. (len * 2), false);
  6500. if (ret) {
  6501. dev_err(pahu->dev, "%s: swrm bulk write failed, ret: %d\n",
  6502. __func__, ret);
  6503. }
  6504. mutex_unlock(&pahu->swr.write_mutex);
  6505. kfree(bulk_reg);
  6506. return ret;
  6507. }
  6508. static int pahu_swrm_write(void *handle, int reg, int val)
  6509. {
  6510. struct pahu_priv *pahu;
  6511. struct wcd9xxx *wcd9xxx;
  6512. unsigned short swr_wr_addr_base;
  6513. unsigned short swr_wr_data_base;
  6514. struct wcd9xxx_reg_val bulk_reg[2];
  6515. int ret;
  6516. if (!handle) {
  6517. pr_err("%s: NULL handle\n", __func__);
  6518. return -EINVAL;
  6519. }
  6520. pahu = (struct pahu_priv *)handle;
  6521. wcd9xxx = pahu->wcd9xxx;
  6522. swr_wr_addr_base = WCD9360_SWR_AHB_BRIDGE_WR_ADDR_0;
  6523. swr_wr_data_base = WCD9360_SWR_AHB_BRIDGE_WR_DATA_0;
  6524. /* First Write the Data to register */
  6525. bulk_reg[0].reg = swr_wr_data_base;
  6526. bulk_reg[0].buf = (u8 *)(&val);
  6527. bulk_reg[0].bytes = 4;
  6528. bulk_reg[1].reg = swr_wr_addr_base;
  6529. bulk_reg[1].buf = (u8 *)(&reg);
  6530. bulk_reg[1].bytes = 4;
  6531. mutex_lock(&pahu->swr.write_mutex);
  6532. ret = wcd9xxx_slim_bulk_write(wcd9xxx, bulk_reg, 2, false);
  6533. if (ret < 0)
  6534. dev_err(pahu->dev, "%s: WR Data Failure\n", __func__);
  6535. mutex_unlock(&pahu->swr.write_mutex);
  6536. return ret;
  6537. }
  6538. static int pahu_swrm_clock(void *handle, bool enable)
  6539. {
  6540. struct pahu_priv *pahu;
  6541. if (!handle) {
  6542. pr_err("%s: NULL handle\n", __func__);
  6543. return -EINVAL;
  6544. }
  6545. pahu = (struct pahu_priv *)handle;
  6546. mutex_lock(&pahu->swr.clk_mutex);
  6547. dev_dbg(pahu->dev, "%s: swrm clock %s\n",
  6548. __func__, (enable?"enable" : "disable"));
  6549. if (enable) {
  6550. pahu->swr.clk_users++;
  6551. if (pahu->swr.clk_users == 1) {
  6552. regmap_update_bits(pahu->wcd9xxx->regmap,
  6553. WCD9360_TEST_DEBUG_NPL_DLY_TEST_1,
  6554. 0x10, 0x00);
  6555. __pahu_cdc_mclk_enable(pahu, true);
  6556. regmap_update_bits(pahu->wcd9xxx->regmap,
  6557. WCD9360_CDC_CLK_RST_CTRL_SWR_CONTROL,
  6558. 0x01, 0x01);
  6559. }
  6560. } else {
  6561. pahu->swr.clk_users--;
  6562. if (pahu->swr.clk_users == 0) {
  6563. regmap_update_bits(pahu->wcd9xxx->regmap,
  6564. WCD9360_CDC_CLK_RST_CTRL_SWR_CONTROL,
  6565. 0x01, 0x00);
  6566. __pahu_cdc_mclk_enable(pahu, false);
  6567. regmap_update_bits(pahu->wcd9xxx->regmap,
  6568. WCD9360_TEST_DEBUG_NPL_DLY_TEST_1,
  6569. 0x10, 0x10);
  6570. }
  6571. }
  6572. dev_dbg(pahu->dev, "%s: swrm clock users %d\n",
  6573. __func__, pahu->swr.clk_users);
  6574. mutex_unlock(&pahu->swr.clk_mutex);
  6575. return 0;
  6576. }
  6577. static int pahu_swrm_handle_irq(void *handle,
  6578. irqreturn_t (*swrm_irq_handler)(int irq,
  6579. void *data),
  6580. void *swrm_handle,
  6581. int action)
  6582. {
  6583. struct pahu_priv *pahu;
  6584. int ret = 0;
  6585. struct wcd9xxx *wcd9xxx;
  6586. if (!handle) {
  6587. pr_err("%s: NULL handle\n", __func__);
  6588. return -EINVAL;
  6589. }
  6590. pahu = (struct pahu_priv *) handle;
  6591. wcd9xxx = pahu->wcd9xxx;
  6592. if (action) {
  6593. ret = wcd9xxx_request_irq(&wcd9xxx->core_res,
  6594. WCD9360_IRQ_SOUNDWIRE,
  6595. swrm_irq_handler,
  6596. "Pahu SWR Master", swrm_handle);
  6597. if (ret)
  6598. dev_err(pahu->dev, "%s: Failed to request irq %d\n",
  6599. __func__, WCD9360_IRQ_SOUNDWIRE);
  6600. } else
  6601. wcd9xxx_free_irq(&wcd9xxx->core_res, WCD9360_IRQ_SOUNDWIRE,
  6602. swrm_handle);
  6603. return ret;
  6604. }
  6605. static void pahu_codec_add_spi_device(struct pahu_priv *pahu,
  6606. struct device_node *node)
  6607. {
  6608. struct spi_master *master;
  6609. struct spi_device *spi;
  6610. u32 prop_value;
  6611. int rc;
  6612. /* Read the master bus num from DT node */
  6613. rc = of_property_read_u32(node, "qcom,master-bus-num",
  6614. &prop_value);
  6615. if (rc < 0) {
  6616. dev_err(pahu->dev, "%s: prop %s not found in node %s",
  6617. __func__, "qcom,master-bus-num", node->full_name);
  6618. goto done;
  6619. }
  6620. /* Get the reference to SPI master */
  6621. master = spi_busnum_to_master(prop_value);
  6622. if (!master) {
  6623. dev_err(pahu->dev, "%s: Invalid spi_master for bus_num %u\n",
  6624. __func__, prop_value);
  6625. goto done;
  6626. }
  6627. /* Allocate the spi device */
  6628. spi = spi_alloc_device(master);
  6629. if (!spi) {
  6630. dev_err(pahu->dev, "%s: spi_alloc_device failed\n",
  6631. __func__);
  6632. goto err_spi_alloc_dev;
  6633. }
  6634. /* Initialize device properties */
  6635. if (of_modalias_node(node, spi->modalias,
  6636. sizeof(spi->modalias)) < 0) {
  6637. dev_err(pahu->dev, "%s: cannot find modalias for %s\n",
  6638. __func__, node->full_name);
  6639. goto err_dt_parse;
  6640. }
  6641. rc = of_property_read_u32(node, "qcom,chip-select",
  6642. &prop_value);
  6643. if (rc < 0) {
  6644. dev_err(pahu->dev, "%s: prop %s not found in node %s",
  6645. __func__, "qcom,chip-select", node->full_name);
  6646. goto err_dt_parse;
  6647. }
  6648. spi->chip_select = prop_value;
  6649. rc = of_property_read_u32(node, "qcom,max-frequency",
  6650. &prop_value);
  6651. if (rc < 0) {
  6652. dev_err(pahu->dev, "%s: prop %s not found in node %s",
  6653. __func__, "qcom,max-frequency", node->full_name);
  6654. goto err_dt_parse;
  6655. }
  6656. spi->max_speed_hz = prop_value;
  6657. spi->dev.of_node = node;
  6658. rc = spi_add_device(spi);
  6659. if (rc < 0) {
  6660. dev_err(pahu->dev, "%s: spi_add_device failed\n", __func__);
  6661. goto err_dt_parse;
  6662. }
  6663. pahu->spi = spi;
  6664. /* Put the reference to SPI master */
  6665. put_device(&master->dev);
  6666. return;
  6667. err_dt_parse:
  6668. spi_dev_put(spi);
  6669. err_spi_alloc_dev:
  6670. /* Put the reference to SPI master */
  6671. put_device(&master->dev);
  6672. done:
  6673. return;
  6674. }
  6675. static void pahu_add_child_devices(struct work_struct *work)
  6676. {
  6677. struct pahu_priv *pahu;
  6678. struct platform_device *pdev;
  6679. struct device_node *node;
  6680. struct wcd9xxx *wcd9xxx;
  6681. struct pahu_swr_ctrl_data *swr_ctrl_data = NULL, *temp;
  6682. int ret, ctrl_num = 0;
  6683. struct wcd_swr_ctrl_platform_data *platdata;
  6684. char plat_dev_name[WCD9360_STRING_LEN];
  6685. pahu = container_of(work, struct pahu_priv,
  6686. pahu_add_child_devices_work);
  6687. if (!pahu) {
  6688. pr_err("%s: Memory for wcd9360 does not exist\n",
  6689. __func__);
  6690. return;
  6691. }
  6692. wcd9xxx = pahu->wcd9xxx;
  6693. if (!wcd9xxx) {
  6694. pr_err("%s: Memory for WCD9XXX does not exist\n",
  6695. __func__);
  6696. return;
  6697. }
  6698. if (!wcd9xxx->dev->of_node) {
  6699. dev_err(wcd9xxx->dev, "%s: DT node for wcd9xxx does not exist\n",
  6700. __func__);
  6701. return;
  6702. }
  6703. platdata = &pahu->swr.plat_data;
  6704. pahu->child_count = 0;
  6705. for_each_child_of_node(wcd9xxx->dev->of_node, node) {
  6706. /* Parse and add the SPI device node */
  6707. if (!strcmp(node->name, "wcd_spi")) {
  6708. pahu_codec_add_spi_device(pahu, node);
  6709. continue;
  6710. }
  6711. /* Parse other child device nodes and add platform device */
  6712. if (!strcmp(node->name, "swr_master"))
  6713. strlcpy(plat_dev_name, "pahu_swr_ctrl",
  6714. (WCD9360_STRING_LEN - 1));
  6715. else if (strnstr(node->name, "msm_cdc_pinctrl",
  6716. strlen("msm_cdc_pinctrl")) != NULL)
  6717. strlcpy(plat_dev_name, node->name,
  6718. (WCD9360_STRING_LEN - 1));
  6719. else
  6720. continue;
  6721. pdev = platform_device_alloc(plat_dev_name, -1);
  6722. if (!pdev) {
  6723. dev_err(wcd9xxx->dev, "%s: pdev memory alloc failed\n",
  6724. __func__);
  6725. ret = -ENOMEM;
  6726. goto err_mem;
  6727. }
  6728. pdev->dev.parent = pahu->dev;
  6729. pdev->dev.of_node = node;
  6730. if (strcmp(node->name, "swr_master") == 0) {
  6731. ret = platform_device_add_data(pdev, platdata,
  6732. sizeof(*platdata));
  6733. if (ret) {
  6734. dev_err(&pdev->dev,
  6735. "%s: cannot add plat data ctrl:%d\n",
  6736. __func__, ctrl_num);
  6737. goto err_pdev_add;
  6738. }
  6739. }
  6740. ret = platform_device_add(pdev);
  6741. if (ret) {
  6742. dev_err(&pdev->dev,
  6743. "%s: Cannot add platform device\n",
  6744. __func__);
  6745. goto err_pdev_add;
  6746. }
  6747. if (strcmp(node->name, "swr_master") == 0) {
  6748. temp = krealloc(swr_ctrl_data,
  6749. (ctrl_num + 1) * sizeof(
  6750. struct pahu_swr_ctrl_data),
  6751. GFP_KERNEL);
  6752. if (!temp) {
  6753. dev_err(wcd9xxx->dev, "out of memory\n");
  6754. ret = -ENOMEM;
  6755. goto err_pdev_add;
  6756. }
  6757. swr_ctrl_data = temp;
  6758. swr_ctrl_data[ctrl_num].swr_pdev = pdev;
  6759. ctrl_num++;
  6760. dev_dbg(&pdev->dev,
  6761. "%s: Added soundwire ctrl device(s)\n",
  6762. __func__);
  6763. pahu->swr.ctrl_data = swr_ctrl_data;
  6764. }
  6765. if (pahu->child_count < WCD9360_CHILD_DEVICES_MAX)
  6766. pahu->pdev_child_devices[pahu->child_count++] = pdev;
  6767. else
  6768. goto err_mem;
  6769. }
  6770. return;
  6771. err_pdev_add:
  6772. platform_device_put(pdev);
  6773. err_mem:
  6774. return;
  6775. }
  6776. static int __pahu_enable_efuse_sensing(struct pahu_priv *pahu)
  6777. {
  6778. int val, rc;
  6779. WCD9XXX_V2_BG_CLK_LOCK(pahu->resmgr);
  6780. __pahu_cdc_mclk_enable_locked(pahu, true);
  6781. regmap_update_bits(pahu->wcd9xxx->regmap,
  6782. WCD9360_CHIP_TIER_CTRL_EFUSE_CTL, 0x1E, 0x10);
  6783. regmap_update_bits(pahu->wcd9xxx->regmap,
  6784. WCD9360_CHIP_TIER_CTRL_EFUSE_CTL, 0x01, 0x01);
  6785. /*
  6786. * 5ms sleep required after enabling efuse control
  6787. * before checking the status.
  6788. */
  6789. usleep_range(5000, 5500);
  6790. wcd_resmgr_set_sido_input_src(pahu->resmgr,
  6791. SIDO_SOURCE_RCO_BG);
  6792. WCD9XXX_V2_BG_CLK_UNLOCK(pahu->resmgr);
  6793. rc = regmap_read(pahu->wcd9xxx->regmap,
  6794. WCD9360_CHIP_TIER_CTRL_EFUSE_STATUS, &val);
  6795. if (rc || (!(val & 0x01)))
  6796. WARN(1, "%s: Efuse sense is not complete val=%x, ret=%d\n",
  6797. __func__, val, rc);
  6798. __pahu_cdc_mclk_enable(pahu, false);
  6799. return rc;
  6800. }
  6801. /*
  6802. * pahu_get_wcd_dsp_cntl: Get the reference to wcd_dsp_cntl
  6803. * @dev: Device pointer for codec device
  6804. *
  6805. * This API gets the reference to codec's struct wcd_dsp_cntl
  6806. */
  6807. struct wcd_dsp_cntl *pahu_get_wcd_dsp_cntl(struct device *dev)
  6808. {
  6809. struct platform_device *pdev;
  6810. struct pahu_priv *pahu;
  6811. if (!dev) {
  6812. pr_err("%s: Invalid device\n", __func__);
  6813. return NULL;
  6814. }
  6815. pdev = to_platform_device(dev);
  6816. pahu = platform_get_drvdata(pdev);
  6817. return pahu->wdsp_cntl;
  6818. }
  6819. EXPORT_SYMBOL(pahu_get_wcd_dsp_cntl);
  6820. static int pahu_probe(struct platform_device *pdev)
  6821. {
  6822. int ret = 0;
  6823. struct pahu_priv *pahu;
  6824. struct clk *wcd_ext_clk;
  6825. struct wcd9xxx_resmgr_v2 *resmgr;
  6826. struct wcd9xxx_power_region *cdc_pwr;
  6827. pahu = devm_kzalloc(&pdev->dev, sizeof(struct pahu_priv),
  6828. GFP_KERNEL);
  6829. if (!pahu)
  6830. return -ENOMEM;
  6831. platform_set_drvdata(pdev, pahu);
  6832. pahu->wcd9xxx = dev_get_drvdata(pdev->dev.parent);
  6833. pahu->dev = &pdev->dev;
  6834. INIT_DELAYED_WORK(&pahu->power_gate_work, pahu_codec_power_gate_work);
  6835. mutex_init(&pahu->power_lock);
  6836. INIT_WORK(&pahu->pahu_add_child_devices_work,
  6837. pahu_add_child_devices);
  6838. mutex_init(&pahu->micb_lock);
  6839. mutex_init(&pahu->swr.read_mutex);
  6840. mutex_init(&pahu->swr.write_mutex);
  6841. mutex_init(&pahu->swr.clk_mutex);
  6842. mutex_init(&pahu->codec_mutex);
  6843. mutex_init(&pahu->svs_mutex);
  6844. /*
  6845. * Codec hardware by default comes up in SVS mode.
  6846. * Initialize the svs_ref_cnt to 1 to reflect the hardware
  6847. * state in the driver.
  6848. */
  6849. pahu->svs_ref_cnt = 1;
  6850. cdc_pwr = devm_kzalloc(&pdev->dev, sizeof(struct wcd9xxx_power_region),
  6851. GFP_KERNEL);
  6852. if (!cdc_pwr) {
  6853. ret = -ENOMEM;
  6854. goto err_resmgr;
  6855. }
  6856. pahu->wcd9xxx->wcd9xxx_pwr[WCD9XXX_DIG_CORE_REGION_1] = cdc_pwr;
  6857. cdc_pwr->pwr_collapse_reg_min = WCD9360_DIG_CORE_REG_MIN;
  6858. cdc_pwr->pwr_collapse_reg_max = WCD9360_DIG_CORE_REG_MAX;
  6859. wcd9xxx_set_power_state(pahu->wcd9xxx,
  6860. WCD_REGION_POWER_COLLAPSE_REMOVE,
  6861. WCD9XXX_DIG_CORE_REGION_1);
  6862. /*
  6863. * Init resource manager so that if child nodes such as SoundWire
  6864. * requests for clock, resource manager can honor the request
  6865. */
  6866. resmgr = wcd_resmgr_init(&pahu->wcd9xxx->core_res, NULL);
  6867. if (IS_ERR(resmgr)) {
  6868. ret = PTR_ERR(resmgr);
  6869. dev_err(&pdev->dev, "%s: Failed to initialize wcd resmgr\n",
  6870. __func__);
  6871. goto err_resmgr;
  6872. }
  6873. pahu->resmgr = resmgr;
  6874. pahu->swr.plat_data.handle = (void *) pahu;
  6875. pahu->swr.plat_data.read = pahu_swrm_read;
  6876. pahu->swr.plat_data.write = pahu_swrm_write;
  6877. pahu->swr.plat_data.bulk_write = pahu_swrm_bulk_write;
  6878. pahu->swr.plat_data.clk = pahu_swrm_clock;
  6879. pahu->swr.plat_data.handle_irq = pahu_swrm_handle_irq;
  6880. pahu->swr.spkr_gain_offset = WCD9360_RX_GAIN_OFFSET_0_DB;
  6881. /* Register for Clock */
  6882. wcd_ext_clk = clk_get(pahu->wcd9xxx->dev, "wcd_clk");
  6883. if (IS_ERR(wcd_ext_clk)) {
  6884. dev_err(pahu->wcd9xxx->dev, "%s: clk get %s failed\n",
  6885. __func__, "wcd_ext_clk");
  6886. goto err_clk;
  6887. }
  6888. pahu->wcd_ext_clk = wcd_ext_clk;
  6889. dev_dbg(&pdev->dev, "%s: MCLK Rate = %x\n", __func__,
  6890. pahu->wcd9xxx->mclk_rate);
  6891. /* Update codec register default values */
  6892. pahu_update_reg_defaults(pahu);
  6893. __pahu_enable_efuse_sensing(pahu);
  6894. pahu_update_cpr_defaults(pahu);
  6895. /* Register with soc framework */
  6896. ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_pahu,
  6897. pahu_dai, ARRAY_SIZE(pahu_dai));
  6898. if (ret) {
  6899. dev_err(&pdev->dev, "%s: Codec registration failed\n",
  6900. __func__);
  6901. goto err_cdc_reg;
  6902. }
  6903. schedule_work(&pahu->pahu_add_child_devices_work);
  6904. return ret;
  6905. err_cdc_reg:
  6906. clk_put(pahu->wcd_ext_clk);
  6907. err_clk:
  6908. wcd_resmgr_remove(pahu->resmgr);
  6909. err_resmgr:
  6910. mutex_destroy(&pahu->micb_lock);
  6911. mutex_destroy(&pahu->svs_mutex);
  6912. mutex_destroy(&pahu->codec_mutex);
  6913. mutex_destroy(&pahu->swr.read_mutex);
  6914. mutex_destroy(&pahu->swr.write_mutex);
  6915. mutex_destroy(&pahu->swr.clk_mutex);
  6916. devm_kfree(&pdev->dev, pahu);
  6917. return ret;
  6918. }
  6919. static int pahu_remove(struct platform_device *pdev)
  6920. {
  6921. struct pahu_priv *pahu;
  6922. int count = 0;
  6923. pahu = platform_get_drvdata(pdev);
  6924. if (!pahu)
  6925. return -EINVAL;
  6926. if (pahu->spi)
  6927. spi_unregister_device(pahu->spi);
  6928. for (count = 0; count < pahu->child_count &&
  6929. count < WCD9360_CHILD_DEVICES_MAX; count++)
  6930. platform_device_unregister(pahu->pdev_child_devices[count]);
  6931. mutex_destroy(&pahu->micb_lock);
  6932. mutex_destroy(&pahu->svs_mutex);
  6933. mutex_destroy(&pahu->codec_mutex);
  6934. mutex_destroy(&pahu->swr.read_mutex);
  6935. mutex_destroy(&pahu->swr.write_mutex);
  6936. mutex_destroy(&pahu->swr.clk_mutex);
  6937. snd_soc_unregister_codec(&pdev->dev);
  6938. clk_put(pahu->wcd_ext_clk);
  6939. wcd_resmgr_remove(pahu->resmgr);
  6940. devm_kfree(&pdev->dev, pahu);
  6941. return 0;
  6942. }
  6943. static struct platform_driver pahu_codec_driver = {
  6944. .probe = pahu_probe,
  6945. .remove = pahu_remove,
  6946. .driver = {
  6947. .name = "pahu_codec",
  6948. .owner = THIS_MODULE,
  6949. #ifdef CONFIG_PM
  6950. .pm = &pahu_pm_ops,
  6951. #endif
  6952. },
  6953. };
  6954. module_platform_driver(pahu_codec_driver);
  6955. MODULE_DESCRIPTION("Pahu Codec driver");
  6956. MODULE_LICENSE("GPL v2");