wcd9306.c 205 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018
  1. /* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/init.h>
  14. #include <linux/firmware.h>
  15. #include <linux/slab.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/device.h>
  18. #include <linux/printk.h>
  19. #include <linux/ratelimit.h>
  20. #include <linux/debugfs.h>
  21. #include <linux/wait.h>
  22. #include <linux/bitops.h>
  23. #include <linux/mfd/wcd9xxx/core.h>
  24. #include <linux/mfd/wcd9xxx/wcd9xxx_registers.h>
  25. #include <linux/mfd/wcd9xxx/wcd9306_registers.h>
  26. #include <linux/mfd/wcd9xxx/pdata.h>
  27. #include <linux/regulator/consumer.h>
  28. #include <sound/pcm.h>
  29. #include <sound/pcm_params.h>
  30. #include <sound/soc.h>
  31. #include <sound/soc-dapm.h>
  32. #include <sound/tlv.h>
  33. #include <linux/bitops.h>
  34. #include <linux/delay.h>
  35. #include <linux/pm_runtime.h>
  36. #include <linux/kernel.h>
  37. #include <linux/gpio.h>
  38. #include "wcd9306.h"
  39. #include "wcd9xxx-resmgr.h"
  40. #include "wcd9xxx-common.h"
  41. #define TAPAN_HPH_PA_SETTLE_COMP_ON 5000
  42. #define TAPAN_HPH_PA_SETTLE_COMP_OFF 13000
  43. #if defined(CONFIG_SND_SOC_ES705)
  44. #include "audience/es705-export.h"
  45. #elif defined(CONFIG_SND_SOC_ES325_ATLANTIC)
  46. #include "es325-export.h"
  47. #endif
  48. #if defined(CONFIG_SND_SOC_ES705)
  49. #define REMOTE_ROUTE_ENABLE_CB es705_remote_route_enable
  50. #define SLIM_GET_CHANNEL_MAP_CB es705_slim_get_channel_map
  51. #define SLIM_SET_CHANNEL_MAP_CB es705_slim_set_channel_map
  52. #define SLIM_HW_PARAMS_CB es705_slim_hw_params
  53. #define REMOTE_CFG_SLIM_RX_CB es705_remote_cfg_slim_rx
  54. #define REMOTE_CLOSE_SLIM_RX_CB es705_remote_close_slim_rx
  55. #define REMOTE_CFG_SLIM_TX_CB es705_remote_cfg_slim_tx
  56. #define REMOTE_CLOSE_SLIM_TX_CB es705_remote_close_slim_tx
  57. #define REMOTE_ADD_CODEC_CONTROLS_CB es705_remote_add_codec_controls
  58. #endif
  59. #ifndef CONFIG_ARCH_MSM8226
  60. #define DAPM_MICBIAS2_EXTERNAL_STANDALONE "MIC BIAS2 External Standalone"
  61. #endif
  62. #define TAPAN_VALIDATE_RX_SBPORT_RANGE(port) ((port >= 16) && (port <= 20))
  63. #define TAPAN_CONVERT_RX_SBPORT_ID(port) (port - 16) /* RX1 port ID = 0 */
  64. #define TAPAN_VDD_CX_OPTIMAL_UA 10000
  65. #define TAPAN_VDD_CX_SLEEP_UA 2000
  66. /* RX_HPH_CNP_WG_TIME increases by 0.24ms */
  67. #define TAPAN_WG_TIME_FACTOR_US 240
  68. #define TAPAN_SB_PGD_PORT_RX_BASE 0x40
  69. #define TAPAN_SB_PGD_PORT_TX_BASE 0x50
  70. #define TAPAN_REGISTER_START_OFFSET 0x800
  71. #define CODEC_REG_CFG_MINOR_VER 1
  72. static struct regulator *tapan_codec_find_regulator(
  73. struct snd_soc_codec *codec,
  74. const char *name);
  75. static atomic_t kp_tapan_priv;
  76. static int spkr_drv_wrnd_param_set(const char *val,
  77. const struct kernel_param *kp);
  78. static int spkr_drv_wrnd = 1;
  79. static struct kernel_param_ops spkr_drv_wrnd_param_ops = {
  80. .set = spkr_drv_wrnd_param_set,
  81. .get = param_get_int,
  82. };
  83. module_param_cb(spkr_drv_wrnd, &spkr_drv_wrnd_param_ops, &spkr_drv_wrnd, 0644);
  84. MODULE_PARM_DESC(spkr_drv_wrnd,
  85. "Run software workaround to avoid leakage on the speaker drive");
  86. #define WCD9306_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
  87. SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\
  88. SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000)
  89. #define WCD9302_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
  90. SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000)
  91. #define NUM_DECIMATORS 4
  92. #define NUM_INTERPOLATORS 4
  93. #define BITS_PER_REG 8
  94. /* This actual number of TX ports supported in slimbus slave */
  95. #define TAPAN_TX_PORT_NUMBER 16
  96. #define TAPAN_RX_PORT_START_NUMBER 16
  97. /* Nummer of TX ports actually connected from Slimbus slave to codec Digital */
  98. #define TAPAN_SLIM_CODEC_TX_PORTS 5
  99. #define TAPAN_I2S_MASTER_MODE_MASK 0x08
  100. #define TAPAN_MCLK_CLK_12P288MHZ 12288000
  101. #define TAPAN_MCLK_CLK_9P6MHZ 9600000
  102. #define TAPAN_SLIM_CLOSE_TIMEOUT 1000
  103. #define TAPAN_SLIM_IRQ_OVERFLOW (1 << 0)
  104. #define TAPAN_SLIM_IRQ_UNDERFLOW (1 << 1)
  105. #define TAPAN_SLIM_IRQ_PORT_CLOSED (1 << 2)
  106. enum tapan_codec_type {
  107. WCD9306,
  108. WCD9302,
  109. };
  110. static enum tapan_codec_type codec_ver;
  111. /*
  112. * Multiplication factor to compute impedance on Tapan
  113. * This is computed from (Vx / (m*Ical)) = (10mV/(180*30uA))
  114. */
  115. #define TAPAN_ZDET_MUL_FACTOR 1852
  116. static struct afe_param_cdc_reg_cfg audio_reg_cfg[] = {
  117. {
  118. CODEC_REG_CFG_MINOR_VER,
  119. (TAPAN_REGISTER_START_OFFSET + TAPAN_SB_PGD_PORT_TX_BASE),
  120. SB_PGD_PORT_TX_WATERMARK_N, 0x1E, 8, 0x1
  121. },
  122. {
  123. CODEC_REG_CFG_MINOR_VER,
  124. (TAPAN_REGISTER_START_OFFSET + TAPAN_SB_PGD_PORT_TX_BASE),
  125. SB_PGD_PORT_TX_ENABLE_N, 0x1, 8, 0x1
  126. },
  127. {
  128. CODEC_REG_CFG_MINOR_VER,
  129. (TAPAN_REGISTER_START_OFFSET + TAPAN_SB_PGD_PORT_RX_BASE),
  130. SB_PGD_PORT_RX_WATERMARK_N, 0x1E, 8, 0x1
  131. },
  132. {
  133. CODEC_REG_CFG_MINOR_VER,
  134. (TAPAN_REGISTER_START_OFFSET + TAPAN_SB_PGD_PORT_RX_BASE),
  135. SB_PGD_PORT_RX_ENABLE_N, 0x1, 8, 0x1
  136. },
  137. {
  138. CODEC_REG_CFG_MINOR_VER,
  139. (TAPAN_REGISTER_START_OFFSET + TAPAN_A_CDC_ANC1_IIR_B1_CTL),
  140. AANC_FF_GAIN_ADAPTIVE, 0x4, 8, 0
  141. },
  142. {
  143. CODEC_REG_CFG_MINOR_VER,
  144. (TAPAN_REGISTER_START_OFFSET + TAPAN_A_CDC_ANC1_IIR_B1_CTL),
  145. AANC_FFGAIN_ADAPTIVE_EN, 0x8, 8, 0
  146. },
  147. {
  148. CODEC_REG_CFG_MINOR_VER,
  149. (TAPAN_REGISTER_START_OFFSET + TAPAN_A_CDC_ANC1_GAIN_CTL),
  150. AANC_GAIN_CONTROL, 0xFF, 8, 0
  151. },
  152. };
  153. static struct afe_param_cdc_reg_cfg_data tapan_audio_reg_cfg = {
  154. .num_registers = ARRAY_SIZE(audio_reg_cfg),
  155. .reg_data = audio_reg_cfg,
  156. };
  157. static struct afe_param_id_cdc_aanc_version tapan_cdc_aanc_version = {
  158. .cdc_aanc_minor_version = AFE_API_VERSION_CDC_AANC_VERSION,
  159. .aanc_hw_version = AANC_HW_BLOCK_VERSION_2,
  160. };
  161. enum {
  162. AIF1_PB = 0,
  163. AIF1_CAP,
  164. AIF2_PB,
  165. AIF2_CAP,
  166. AIF3_PB,
  167. AIF3_CAP,
  168. NUM_CODEC_DAIS,
  169. };
  170. enum {
  171. RX_MIX1_INP_SEL_ZERO = 0,
  172. RX_MIX1_INP_SEL_SRC1,
  173. RX_MIX1_INP_SEL_SRC2,
  174. RX_MIX1_INP_SEL_IIR1,
  175. RX_MIX1_INP_SEL_IIR2,
  176. RX_MIX1_INP_SEL_RX1,
  177. RX_MIX1_INP_SEL_RX2,
  178. RX_MIX1_INP_SEL_RX3,
  179. RX_MIX1_INP_SEL_RX4,
  180. RX_MIX1_INP_SEL_RX5,
  181. RX_MIX1_INP_SEL_AUXRX,
  182. };
  183. #define TAPAN_COMP_DIGITAL_GAIN_OFFSET 3
  184. static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0);
  185. static const DECLARE_TLV_DB_SCALE(line_gain, 0, 7, 1);
  186. static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 25, 1);
  187. static struct snd_soc_dai_driver tapan_dai[];
  188. static const DECLARE_TLV_DB_SCALE(aux_pga_gain, 0, 2, 0);
  189. /* Codec supports 2 IIR filters */
  190. enum {
  191. IIR1 = 0,
  192. IIR2,
  193. IIR_MAX,
  194. };
  195. /* Codec supports 5 bands */
  196. enum {
  197. BAND1 = 0,
  198. BAND2,
  199. BAND3,
  200. BAND4,
  201. BAND5,
  202. BAND_MAX,
  203. };
  204. enum {
  205. COMPANDER_0,
  206. COMPANDER_1,
  207. COMPANDER_2,
  208. COMPANDER_MAX,
  209. };
  210. enum {
  211. COMPANDER_FS_8KHZ = 0,
  212. COMPANDER_FS_16KHZ,
  213. COMPANDER_FS_32KHZ,
  214. COMPANDER_FS_48KHZ,
  215. COMPANDER_FS_96KHZ,
  216. COMPANDER_FS_192KHZ,
  217. COMPANDER_FS_MAX,
  218. };
  219. struct comp_sample_dependent_params {
  220. u32 peak_det_timeout;
  221. u32 rms_meter_div_fact;
  222. u32 rms_meter_resamp_fact;
  223. };
  224. struct hpf_work {
  225. struct tapan_priv *tapan;
  226. u32 decimator;
  227. u8 tx_hpf_cut_of_freq;
  228. struct delayed_work dwork;
  229. };
  230. static struct hpf_work tx_hpf_work[NUM_DECIMATORS];
  231. static const struct wcd9xxx_ch tapan_rx_chs[TAPAN_RX_MAX] = {
  232. WCD9XXX_CH(TAPAN_RX_PORT_START_NUMBER, 0),
  233. WCD9XXX_CH(TAPAN_RX_PORT_START_NUMBER + 1, 1),
  234. WCD9XXX_CH(TAPAN_RX_PORT_START_NUMBER + 2, 2),
  235. WCD9XXX_CH(TAPAN_RX_PORT_START_NUMBER + 3, 3),
  236. WCD9XXX_CH(TAPAN_RX_PORT_START_NUMBER + 4, 4),
  237. };
  238. static const struct wcd9xxx_ch tapan_tx_chs[TAPAN_TX_MAX] = {
  239. WCD9XXX_CH(0, 0),
  240. WCD9XXX_CH(1, 1),
  241. WCD9XXX_CH(2, 2),
  242. WCD9XXX_CH(3, 3),
  243. WCD9XXX_CH(4, 4),
  244. };
  245. static const u32 vport_check_table[NUM_CODEC_DAIS] = {
  246. 0, /* AIF1_PB */
  247. (1 << AIF2_CAP) | (1 << AIF3_CAP), /* AIF1_CAP */
  248. 0, /* AIF2_PB */
  249. (1 << AIF1_CAP) | (1 << AIF3_CAP), /* AIF2_CAP */
  250. 0, /* AIF2_PB */
  251. (1 << AIF1_CAP) | (1 << AIF2_CAP), /* AIF2_CAP */
  252. };
  253. static const u32 vport_i2s_check_table[NUM_CODEC_DAIS] = {
  254. 0, /* AIF1_PB */
  255. 0, /* AIF1_CAP */
  256. };
  257. enum {
  258. CP_REG_BUCK = 0,
  259. CP_REG_BHELPER,
  260. CP_REG_MAX,
  261. };
  262. struct tapan_priv {
  263. struct snd_soc_codec *codec;
  264. u32 adc_count;
  265. u32 rx_bias_count;
  266. s32 dmic_1_2_clk_cnt;
  267. s32 dmic_3_4_clk_cnt;
  268. s32 dmic_5_6_clk_cnt;
  269. s32 ldo_h_users;
  270. s32 micb_2_users;
  271. u32 anc_slot;
  272. bool anc_func;
  273. /*track tapan interface type*/
  274. u8 intf_type;
  275. /* num of slim ports required */
  276. struct wcd9xxx_codec_dai_data dai[NUM_CODEC_DAIS];
  277. /*compander*/
  278. int comp_enabled[COMPANDER_MAX];
  279. u32 comp_fs[COMPANDER_MAX];
  280. /* Maintain the status of AUX PGA */
  281. int aux_pga_cnt;
  282. u8 aux_l_gain;
  283. u8 aux_r_gain;
  284. bool spkr_pa_widget_on;
  285. struct afe_param_cdc_slimbus_slave_cfg slimbus_slave_cfg;
  286. /* resmgr module */
  287. struct wcd9xxx_resmgr resmgr;
  288. /* mbhc module */
  289. struct wcd9xxx_mbhc mbhc;
  290. /* class h specific data */
  291. struct wcd9xxx_clsh_cdc_data clsh_d;
  292. int ldo_h_count;
  293. int (*mclk_cb_fn) (struct snd_soc_codec*, int, bool);
  294. int micb_2_ref_cnt;
  295. /* pointers to regulators required for chargepump */
  296. struct regulator *cp_regulators[CP_REG_MAX];
  297. /*
  298. * list used to save/restore registers at start and
  299. * end of impedance measurement
  300. */
  301. struct list_head reg_save_restore;
  302. int (*machine_codec_event_cb)(struct snd_soc_codec *codec,
  303. enum wcd9xxx_codec_event);
  304. };
  305. static const u32 comp_shift[] = {
  306. 0,
  307. 1,
  308. 2,
  309. };
  310. static const int comp_rx_path[] = {
  311. COMPANDER_1,
  312. COMPANDER_1,
  313. COMPANDER_2,
  314. COMPANDER_2,
  315. COMPANDER_MAX,
  316. };
  317. static const struct comp_sample_dependent_params comp_samp_params[] = {
  318. {
  319. /* 8 Khz */
  320. .peak_det_timeout = 0x06,
  321. .rms_meter_div_fact = 0x09,
  322. .rms_meter_resamp_fact = 0x06,
  323. },
  324. {
  325. /* 16 Khz */
  326. .peak_det_timeout = 0x07,
  327. .rms_meter_div_fact = 0x0A,
  328. .rms_meter_resamp_fact = 0x0C,
  329. },
  330. {
  331. /* 32 Khz */
  332. .peak_det_timeout = 0x08,
  333. .rms_meter_div_fact = 0x0B,
  334. .rms_meter_resamp_fact = 0x1E,
  335. },
  336. {
  337. /* 48 Khz */
  338. .peak_det_timeout = 0x09,
  339. .rms_meter_div_fact = 0x0B,
  340. .rms_meter_resamp_fact = 0x28,
  341. },
  342. {
  343. /* 96 Khz */
  344. .peak_det_timeout = 0x0A,
  345. .rms_meter_div_fact = 0x0C,
  346. .rms_meter_resamp_fact = 0x50,
  347. },
  348. {
  349. /* 192 Khz */
  350. .peak_det_timeout = 0x0B,
  351. .rms_meter_div_fact = 0xC,
  352. .rms_meter_resamp_fact = 0xA0,
  353. },
  354. };
  355. static unsigned short rx_digital_gain_reg[] = {
  356. TAPAN_A_CDC_RX1_VOL_CTL_B2_CTL,
  357. TAPAN_A_CDC_RX2_VOL_CTL_B2_CTL,
  358. TAPAN_A_CDC_RX3_VOL_CTL_B2_CTL,
  359. TAPAN_A_CDC_RX4_VOL_CTL_B2_CTL,
  360. };
  361. static unsigned short tx_digital_gain_reg[] = {
  362. TAPAN_A_CDC_TX1_VOL_CTL_GAIN,
  363. TAPAN_A_CDC_TX2_VOL_CTL_GAIN,
  364. TAPAN_A_CDC_TX3_VOL_CTL_GAIN,
  365. TAPAN_A_CDC_TX4_VOL_CTL_GAIN,
  366. };
  367. static int spkr_drv_wrnd_param_set(const char *val,
  368. const struct kernel_param *kp)
  369. {
  370. struct snd_soc_codec *codec;
  371. int ret, old;
  372. struct tapan_priv *priv;
  373. priv = (struct tapan_priv *)atomic_read(&kp_tapan_priv);
  374. if (!priv) {
  375. pr_debug("%s: codec isn't yet registered\n", __func__);
  376. return 0;
  377. }
  378. codec = priv->codec;
  379. mutex_lock(&codec->mutex);
  380. old = spkr_drv_wrnd;
  381. ret = param_set_int(val, kp);
  382. if (ret) {
  383. mutex_unlock(&codec->mutex);
  384. return ret;
  385. }
  386. dev_dbg(codec->dev, "%s: spkr_drv_wrnd %d -> %d\n",
  387. __func__, old, spkr_drv_wrnd);
  388. if ((old == -1 || old == 0) && spkr_drv_wrnd == 1) {
  389. WCD9XXX_BG_CLK_LOCK(&priv->resmgr);
  390. wcd9xxx_resmgr_get_bandgap(&priv->resmgr,
  391. WCD9XXX_BANDGAP_AUDIO_MODE);
  392. WCD9XXX_BG_CLK_UNLOCK(&priv->resmgr);
  393. snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_EN, 0x80, 0x80);
  394. } else if (old == 1 && spkr_drv_wrnd == 0) {
  395. WCD9XXX_BG_CLK_LOCK(&priv->resmgr);
  396. wcd9xxx_resmgr_put_bandgap(&priv->resmgr,
  397. WCD9XXX_BANDGAP_AUDIO_MODE);
  398. WCD9XXX_BG_CLK_UNLOCK(&priv->resmgr);
  399. if (!priv->spkr_pa_widget_on)
  400. snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_EN, 0x80,
  401. 0x00);
  402. }
  403. mutex_unlock(&codec->mutex);
  404. return 0;
  405. }
  406. static int tapan_get_anc_slot(struct snd_kcontrol *kcontrol,
  407. struct snd_ctl_elem_value *ucontrol)
  408. {
  409. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  410. struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
  411. ucontrol->value.integer.value[0] = tapan->anc_slot;
  412. return 0;
  413. }
  414. static int tapan_put_anc_slot(struct snd_kcontrol *kcontrol,
  415. struct snd_ctl_elem_value *ucontrol)
  416. {
  417. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  418. struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
  419. tapan->anc_slot = ucontrol->value.integer.value[0];
  420. return 0;
  421. }
  422. static int tapan_get_anc_func(struct snd_kcontrol *kcontrol,
  423. struct snd_ctl_elem_value *ucontrol)
  424. {
  425. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  426. struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
  427. ucontrol->value.integer.value[0] = (tapan->anc_func == true ? 1 : 0);
  428. return 0;
  429. }
  430. static int tapan_put_anc_func(struct snd_kcontrol *kcontrol,
  431. struct snd_ctl_elem_value *ucontrol)
  432. {
  433. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  434. struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
  435. struct snd_soc_dapm_context *dapm = &codec->dapm;
  436. mutex_lock(&dapm->codec->mutex);
  437. tapan->anc_func = (!ucontrol->value.integer.value[0] ? false : true);
  438. dev_err(codec->dev, "%s: anc_func %x", __func__, tapan->anc_func);
  439. if (tapan->anc_func == true) {
  440. pr_info("enable anc virtual widgets");
  441. snd_soc_dapm_enable_pin(dapm, "ANC HPHR");
  442. snd_soc_dapm_enable_pin(dapm, "ANC HPHL");
  443. snd_soc_dapm_enable_pin(dapm, "ANC HEADPHONE");
  444. snd_soc_dapm_enable_pin(dapm, "ANC EAR PA");
  445. snd_soc_dapm_enable_pin(dapm, "ANC EAR");
  446. snd_soc_dapm_disable_pin(dapm, "HPHR");
  447. snd_soc_dapm_disable_pin(dapm, "HPHL");
  448. snd_soc_dapm_disable_pin(dapm, "HEADPHONE");
  449. snd_soc_dapm_disable_pin(dapm, "EAR PA");
  450. snd_soc_dapm_disable_pin(dapm, "EAR");
  451. } else {
  452. pr_info("disable anc virtual widgets");
  453. snd_soc_dapm_disable_pin(dapm, "ANC HPHR");
  454. snd_soc_dapm_disable_pin(dapm, "ANC HPHL");
  455. snd_soc_dapm_disable_pin(dapm, "ANC HEADPHONE");
  456. snd_soc_dapm_disable_pin(dapm, "ANC EAR PA");
  457. snd_soc_dapm_disable_pin(dapm, "ANC EAR");
  458. snd_soc_dapm_enable_pin(dapm, "HPHR");
  459. snd_soc_dapm_enable_pin(dapm, "HPHL");
  460. snd_soc_dapm_enable_pin(dapm, "HEADPHONE");
  461. snd_soc_dapm_enable_pin(dapm, "EAR PA");
  462. snd_soc_dapm_enable_pin(dapm, "EAR");
  463. }
  464. snd_soc_dapm_sync(dapm);
  465. mutex_unlock(&dapm->codec->mutex);
  466. return 0;
  467. }
  468. static int tapan_pa_gain_get(struct snd_kcontrol *kcontrol,
  469. struct snd_ctl_elem_value *ucontrol)
  470. {
  471. u8 ear_pa_gain;
  472. int rc = 0;
  473. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  474. ear_pa_gain = snd_soc_read(codec, TAPAN_A_RX_EAR_GAIN);
  475. ear_pa_gain = ear_pa_gain >> 5;
  476. switch (ear_pa_gain) {
  477. case 0:
  478. case 1:
  479. case 2:
  480. case 3:
  481. case 4:
  482. case 5:
  483. ucontrol->value.integer.value[0] = ear_pa_gain;
  484. break;
  485. case 7:
  486. ucontrol->value.integer.value[0] = (ear_pa_gain - 1);
  487. break;
  488. default:
  489. rc = -EINVAL;
  490. pr_err("%s: ERROR: Unsupported Ear Gain = 0x%x\n",
  491. __func__, ear_pa_gain);
  492. break;
  493. }
  494. dev_dbg(codec->dev, "%s: ear_pa_gain = 0x%x\n", __func__, ear_pa_gain);
  495. return rc;
  496. }
  497. static int tapan_pa_gain_put(struct snd_kcontrol *kcontrol,
  498. struct snd_ctl_elem_value *ucontrol)
  499. {
  500. u8 ear_pa_gain;
  501. int rc = 0;
  502. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  503. dev_dbg(codec->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  504. __func__, ucontrol->value.integer.value[0]);
  505. switch (ucontrol->value.integer.value[0]) {
  506. case 0:
  507. case 1:
  508. case 2:
  509. case 3:
  510. case 4:
  511. case 5:
  512. ear_pa_gain = ucontrol->value.integer.value[0];
  513. break;
  514. case 6:
  515. ear_pa_gain = 0x07;
  516. break;
  517. default:
  518. rc = -EINVAL;
  519. break;
  520. }
  521. if (!rc)
  522. snd_soc_update_bits(codec, TAPAN_A_RX_EAR_GAIN,
  523. 0xE0, ear_pa_gain << 5);
  524. return rc;
  525. }
  526. static int tapan_get_iir_enable_audio_mixer(
  527. struct snd_kcontrol *kcontrol,
  528. struct snd_ctl_elem_value *ucontrol)
  529. {
  530. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  531. int iir_idx = ((struct soc_multi_mixer_control *)
  532. kcontrol->private_value)->reg;
  533. int band_idx = ((struct soc_multi_mixer_control *)
  534. kcontrol->private_value)->shift;
  535. ucontrol->value.integer.value[0] =
  536. (snd_soc_read(codec, (TAPAN_A_CDC_IIR1_CTL + 16 * iir_idx)) &
  537. (1 << band_idx)) != 0;
  538. dev_dbg(codec->dev, "%s: IIR #%d band #%d enable %d\n", __func__,
  539. iir_idx, band_idx,
  540. (uint32_t)ucontrol->value.integer.value[0]);
  541. return 0;
  542. }
  543. static int tapan_put_iir_enable_audio_mixer(
  544. struct snd_kcontrol *kcontrol,
  545. struct snd_ctl_elem_value *ucontrol)
  546. {
  547. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  548. int iir_idx = ((struct soc_multi_mixer_control *)
  549. kcontrol->private_value)->reg;
  550. int band_idx = ((struct soc_multi_mixer_control *)
  551. kcontrol->private_value)->shift;
  552. int value = ucontrol->value.integer.value[0];
  553. /* Mask first 5 bits, 6-8 are reserved */
  554. snd_soc_update_bits(codec, (TAPAN_A_CDC_IIR1_CTL + 16 * iir_idx),
  555. (1 << band_idx), (value << band_idx));
  556. pr_debug("%s: IIR #%d band #%d enable %d\n", __func__,
  557. iir_idx, band_idx,
  558. ((snd_soc_read(codec, (TAPAN_A_CDC_IIR1_CTL + 16 * iir_idx)) &
  559. (1 << band_idx)) != 0));
  560. return 0;
  561. }
  562. static uint32_t get_iir_band_coeff(struct snd_soc_codec *codec,
  563. int iir_idx, int band_idx,
  564. int coeff_idx)
  565. {
  566. uint32_t value = 0;
  567. /* Address does not automatically update if reading */
  568. snd_soc_write(codec,
  569. (TAPAN_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx),
  570. ((band_idx * BAND_MAX + coeff_idx)
  571. * sizeof(uint32_t)) & 0x7F);
  572. value |= snd_soc_read(codec,
  573. (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx));
  574. snd_soc_write(codec,
  575. (TAPAN_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx),
  576. ((band_idx * BAND_MAX + coeff_idx)
  577. * sizeof(uint32_t) + 1) & 0x7F);
  578. value |= (snd_soc_read(codec,
  579. (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx)) << 8);
  580. snd_soc_write(codec,
  581. (TAPAN_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx),
  582. ((band_idx * BAND_MAX + coeff_idx)
  583. * sizeof(uint32_t) + 2) & 0x7F);
  584. value |= (snd_soc_read(codec,
  585. (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx)) << 16);
  586. snd_soc_write(codec,
  587. (TAPAN_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx),
  588. ((band_idx * BAND_MAX + coeff_idx)
  589. * sizeof(uint32_t) + 3) & 0x7F);
  590. /* Mask bits top 2 bits since they are reserved */
  591. value |= ((snd_soc_read(codec,
  592. (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx)) & 0x3F) << 24);
  593. return value;
  594. }
  595. static int tapan_get_iir_band_audio_mixer(
  596. struct snd_kcontrol *kcontrol,
  597. struct snd_ctl_elem_value *ucontrol)
  598. {
  599. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  600. int iir_idx = ((struct soc_multi_mixer_control *)
  601. kcontrol->private_value)->reg;
  602. int band_idx = ((struct soc_multi_mixer_control *)
  603. kcontrol->private_value)->shift;
  604. ucontrol->value.integer.value[0] =
  605. get_iir_band_coeff(codec, iir_idx, band_idx, 0);
  606. ucontrol->value.integer.value[1] =
  607. get_iir_band_coeff(codec, iir_idx, band_idx, 1);
  608. ucontrol->value.integer.value[2] =
  609. get_iir_band_coeff(codec, iir_idx, band_idx, 2);
  610. ucontrol->value.integer.value[3] =
  611. get_iir_band_coeff(codec, iir_idx, band_idx, 3);
  612. ucontrol->value.integer.value[4] =
  613. get_iir_band_coeff(codec, iir_idx, band_idx, 4);
  614. dev_dbg(codec->dev, "%s: IIR #%d band #%d b0 = 0x%x\n"
  615. "%s: IIR #%d band #%d b1 = 0x%x\n"
  616. "%s: IIR #%d band #%d b2 = 0x%x\n"
  617. "%s: IIR #%d band #%d a1 = 0x%x\n"
  618. "%s: IIR #%d band #%d a2 = 0x%x\n",
  619. __func__, iir_idx, band_idx,
  620. (uint32_t)ucontrol->value.integer.value[0],
  621. __func__, iir_idx, band_idx,
  622. (uint32_t)ucontrol->value.integer.value[1],
  623. __func__, iir_idx, band_idx,
  624. (uint32_t)ucontrol->value.integer.value[2],
  625. __func__, iir_idx, band_idx,
  626. (uint32_t)ucontrol->value.integer.value[3],
  627. __func__, iir_idx, band_idx,
  628. (uint32_t)ucontrol->value.integer.value[4]);
  629. return 0;
  630. }
  631. static void set_iir_band_coeff(struct snd_soc_codec *codec,
  632. int iir_idx, int band_idx,
  633. uint32_t value)
  634. {
  635. snd_soc_write(codec,
  636. (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx),
  637. (value & 0xFF));
  638. snd_soc_write(codec,
  639. (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx),
  640. (value >> 8) & 0xFF);
  641. snd_soc_write(codec,
  642. (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx),
  643. (value >> 16) & 0xFF);
  644. /* Mask top 2 bits, 7-8 are reserved */
  645. snd_soc_write(codec,
  646. (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx),
  647. (value >> 24) & 0x3F);
  648. }
  649. static int tapan_put_iir_band_audio_mixer(
  650. struct snd_kcontrol *kcontrol,
  651. struct snd_ctl_elem_value *ucontrol)
  652. {
  653. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  654. int iir_idx = ((struct soc_multi_mixer_control *)
  655. kcontrol->private_value)->reg;
  656. int band_idx = ((struct soc_multi_mixer_control *)
  657. kcontrol->private_value)->shift;
  658. /* Mask top bit it is reserved */
  659. /* Updates addr automatically for each B2 write */
  660. snd_soc_write(codec,
  661. (TAPAN_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx),
  662. (band_idx * BAND_MAX * sizeof(uint32_t)) & 0x7F);
  663. set_iir_band_coeff(codec, iir_idx, band_idx,
  664. ucontrol->value.integer.value[0]);
  665. set_iir_band_coeff(codec, iir_idx, band_idx,
  666. ucontrol->value.integer.value[1]);
  667. set_iir_band_coeff(codec, iir_idx, band_idx,
  668. ucontrol->value.integer.value[2]);
  669. set_iir_band_coeff(codec, iir_idx, band_idx,
  670. ucontrol->value.integer.value[3]);
  671. set_iir_band_coeff(codec, iir_idx, band_idx,
  672. ucontrol->value.integer.value[4]);
  673. dev_dbg(codec->dev, "%s: IIR #%d band #%d b0 = 0x%x\n"
  674. "%s: IIR #%d band #%d b1 = 0x%x\n"
  675. "%s: IIR #%d band #%d b2 = 0x%x\n"
  676. "%s: IIR #%d band #%d a1 = 0x%x\n"
  677. "%s: IIR #%d band #%d a2 = 0x%x\n",
  678. __func__, iir_idx, band_idx,
  679. get_iir_band_coeff(codec, iir_idx, band_idx, 0),
  680. __func__, iir_idx, band_idx,
  681. get_iir_band_coeff(codec, iir_idx, band_idx, 1),
  682. __func__, iir_idx, band_idx,
  683. get_iir_band_coeff(codec, iir_idx, band_idx, 2),
  684. __func__, iir_idx, band_idx,
  685. get_iir_band_coeff(codec, iir_idx, band_idx, 3),
  686. __func__, iir_idx, band_idx,
  687. get_iir_band_coeff(codec, iir_idx, band_idx, 4));
  688. return 0;
  689. }
  690. static int tapan_get_compander(struct snd_kcontrol *kcontrol,
  691. struct snd_ctl_elem_value *ucontrol)
  692. {
  693. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  694. int comp = ((struct soc_multi_mixer_control *)
  695. kcontrol->private_value)->shift;
  696. struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
  697. ucontrol->value.integer.value[0] = tapan->comp_enabled[comp];
  698. return 0;
  699. }
  700. static int tapan_set_compander(struct snd_kcontrol *kcontrol,
  701. struct snd_ctl_elem_value *ucontrol)
  702. {
  703. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  704. struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
  705. int comp = ((struct soc_multi_mixer_control *)
  706. kcontrol->private_value)->shift;
  707. int value = ucontrol->value.integer.value[0];
  708. dev_dbg(codec->dev, "%s: Compander %d enable current %d, new %d\n",
  709. __func__, comp, tapan->comp_enabled[comp], value);
  710. tapan->comp_enabled[comp] = value;
  711. if (comp == COMPANDER_1 &&
  712. tapan->comp_enabled[comp] == 1) {
  713. /* Wavegen to 5 msec */
  714. snd_soc_write(codec, TAPAN_A_RX_HPH_CNP_WG_CTL, 0xDA);
  715. snd_soc_write(codec, TAPAN_A_RX_HPH_CNP_WG_TIME, 0x15);
  716. snd_soc_write(codec, TAPAN_A_RX_HPH_BIAS_WG_OCP, 0x2A);
  717. /* Enable Chopper */
  718. snd_soc_update_bits(codec,
  719. TAPAN_A_RX_HPH_CHOP_CTL, 0x80, 0x80);
  720. snd_soc_write(codec, TAPAN_A_NCP_DTEST, 0x20);
  721. pr_debug("%s: Enabled Chopper and set wavegen to 5 msec\n",
  722. __func__);
  723. } else if (comp == COMPANDER_1 &&
  724. tapan->comp_enabled[comp] == 0) {
  725. /* Wavegen to 20 msec */
  726. snd_soc_write(codec, TAPAN_A_RX_HPH_CNP_WG_CTL, 0xDB);
  727. snd_soc_write(codec, TAPAN_A_RX_HPH_CNP_WG_TIME, 0x58);
  728. snd_soc_write(codec, TAPAN_A_RX_HPH_BIAS_WG_OCP, 0x1A);
  729. /* Disable CHOPPER block */
  730. snd_soc_update_bits(codec,
  731. TAPAN_A_RX_HPH_CHOP_CTL, 0x80, 0x00);
  732. snd_soc_write(codec, TAPAN_A_NCP_DTEST, 0x10);
  733. pr_debug("%s: Disabled Chopper and set wavegen to 20 msec\n",
  734. __func__);
  735. }
  736. return 0;
  737. }
  738. static int tapan_config_gain_compander(struct snd_soc_codec *codec,
  739. int comp, bool enable)
  740. {
  741. int ret = 0;
  742. switch (comp) {
  743. case COMPANDER_0:
  744. snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_GAIN,
  745. 1 << 2, !enable << 2);
  746. break;
  747. case COMPANDER_1:
  748. snd_soc_update_bits(codec, TAPAN_A_RX_HPH_L_GAIN,
  749. 1 << 5, !enable << 5);
  750. snd_soc_update_bits(codec, TAPAN_A_RX_HPH_R_GAIN,
  751. 1 << 5, !enable << 5);
  752. break;
  753. case COMPANDER_2:
  754. snd_soc_update_bits(codec, TAPAN_A_RX_LINE_1_GAIN,
  755. 1 << 5, !enable << 5);
  756. snd_soc_update_bits(codec, TAPAN_A_RX_LINE_2_GAIN,
  757. 1 << 5, !enable << 5);
  758. break;
  759. default:
  760. WARN_ON(1);
  761. ret = -EINVAL;
  762. }
  763. return ret;
  764. }
  765. static void tapan_discharge_comp(struct snd_soc_codec *codec, int comp)
  766. {
  767. /* Level meter DIV Factor to 5*/
  768. snd_soc_update_bits(codec, TAPAN_A_CDC_COMP0_B2_CTL + (comp * 8), 0xF0,
  769. 0x05 << 4);
  770. /* RMS meter Sampling to 0x01 */
  771. snd_soc_write(codec, TAPAN_A_CDC_COMP0_B3_CTL + (comp * 8), 0x01);
  772. /* Worst case timeout for compander CnP sleep timeout */
  773. usleep_range(3000, 3000);
  774. }
  775. static enum wcd9xxx_buck_volt tapan_codec_get_buck_mv(
  776. struct snd_soc_codec *codec)
  777. {
  778. int buck_volt = WCD9XXX_CDC_BUCK_UNSUPPORTED;
  779. struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
  780. struct wcd9xxx_pdata *pdata = tapan->resmgr.pdata;
  781. int i;
  782. bool found_regulator = false;
  783. for (i = 0; i < ARRAY_SIZE(pdata->regulator); i++) {
  784. if (pdata->regulator[i].name == NULL)
  785. continue;
  786. if (!strncmp(pdata->regulator[i].name,
  787. WCD9XXX_SUPPLY_BUCK_NAME,
  788. sizeof(WCD9XXX_SUPPLY_BUCK_NAME))) {
  789. found_regulator = true;
  790. if ((pdata->regulator[i].min_uV ==
  791. WCD9XXX_CDC_BUCK_MV_1P8) ||
  792. (pdata->regulator[i].min_uV ==
  793. WCD9XXX_CDC_BUCK_MV_2P15))
  794. buck_volt = pdata->regulator[i].min_uV;
  795. break;
  796. }
  797. }
  798. if (!found_regulator)
  799. dev_err(codec->dev,
  800. "%s: Failed to find regulator for %s\n",
  801. __func__, WCD9XXX_SUPPLY_BUCK_NAME);
  802. else
  803. dev_dbg(codec->dev,
  804. "%s: S4 voltage requested is %d\n",
  805. __func__, buck_volt);
  806. return buck_volt;
  807. }
  808. static int tapan_config_compander(struct snd_soc_dapm_widget *w,
  809. struct snd_kcontrol *kcontrol, int event)
  810. {
  811. int mask, enable_mask;
  812. u8 rdac5_mux;
  813. struct snd_soc_codec *codec = w->codec;
  814. struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
  815. const int comp = w->shift;
  816. const u32 rate = tapan->comp_fs[comp];
  817. const struct comp_sample_dependent_params *comp_params =
  818. &comp_samp_params[rate];
  819. enum wcd9xxx_buck_volt buck_mv;
  820. dev_dbg(codec->dev, "%s: %s event %d compander %d, enabled %d",
  821. __func__, w->name, event, comp, tapan->comp_enabled[comp]);
  822. if (!tapan->comp_enabled[comp])
  823. return 0;
  824. /* Compander 0 has single channel */
  825. mask = (comp == COMPANDER_0 ? 0x01 : 0x03);
  826. buck_mv = tapan_codec_get_buck_mv(codec);
  827. rdac5_mux = snd_soc_read(codec, TAPAN_A_CDC_CONN_MISC);
  828. rdac5_mux = (rdac5_mux & 0x04) >> 2;
  829. if (comp == COMPANDER_0) { /* SPK compander */
  830. enable_mask = 0x02;
  831. } else if (comp == COMPANDER_1) { /* HPH compander */
  832. enable_mask = 0x03;
  833. } else if (comp == COMPANDER_2) { /* LO compander */
  834. if (rdac5_mux == 0) { /* DEM4 */
  835. /* for LO Stereo SE, enable Compander 2 left
  836. * channel on RX3 interpolator Path and Compander 2
  837. * rigt channel on RX4 interpolator Path.
  838. */
  839. enable_mask = 0x03;
  840. } else if (rdac5_mux == 1) { /* DEM3_INV */
  841. /* for LO mono differential only enable Compander 2
  842. * left channel on RX3 interpolator Path.
  843. */
  844. enable_mask = 0x02;
  845. } else {
  846. dev_err(codec->dev, "%s: invalid rdac5_mux val %d",
  847. __func__, rdac5_mux);
  848. return -EINVAL;
  849. }
  850. } else {
  851. dev_err(codec->dev, "%s: invalid compander %d", __func__, comp);
  852. return -EINVAL;
  853. }
  854. switch (event) {
  855. case SND_SOC_DAPM_PRE_PMU:
  856. /* Set compander Sample rate */
  857. snd_soc_update_bits(codec,
  858. TAPAN_A_CDC_COMP0_FS_CFG + (comp * 8),
  859. 0x07, rate);
  860. /* Set the static gain offset for HPH Path */
  861. if (comp == COMPANDER_1) {
  862. if (buck_mv == WCD9XXX_CDC_BUCK_MV_2P15)
  863. snd_soc_update_bits(codec,
  864. TAPAN_A_CDC_COMP0_B4_CTL + (comp * 8),
  865. 0x80, 0x00);
  866. else
  867. snd_soc_update_bits(codec,
  868. TAPAN_A_CDC_COMP0_B4_CTL + (comp * 8),
  869. 0x80, 0x80);
  870. }
  871. /* Enable RX interpolation path compander clocks */
  872. snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RX_B2_CTL,
  873. 0x01 << comp_shift[comp],
  874. 0x01 << comp_shift[comp]);
  875. /* Toggle compander reset bits */
  876. snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_OTHR_RESET_B2_CTL,
  877. 0x01 << comp_shift[comp],
  878. 0x01 << comp_shift[comp]);
  879. snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_OTHR_RESET_B2_CTL,
  880. 0x01 << comp_shift[comp], 0);
  881. /* Set gain source to compander */
  882. tapan_config_gain_compander(codec, comp, true);
  883. /* Compander enable */
  884. snd_soc_update_bits(codec, TAPAN_A_CDC_COMP0_B1_CTL +
  885. (comp * 8), enable_mask, enable_mask);
  886. tapan_discharge_comp(codec, comp);
  887. /* Set sample rate dependent paramater */
  888. snd_soc_write(codec, TAPAN_A_CDC_COMP0_B3_CTL + (comp * 8),
  889. comp_params->rms_meter_resamp_fact);
  890. snd_soc_update_bits(codec,
  891. TAPAN_A_CDC_COMP0_B2_CTL + (comp * 8),
  892. 0xF0, comp_params->rms_meter_div_fact << 4);
  893. snd_soc_update_bits(codec,
  894. TAPAN_A_CDC_COMP0_B2_CTL + (comp * 8),
  895. 0x0F, comp_params->peak_det_timeout);
  896. break;
  897. case SND_SOC_DAPM_PRE_PMD:
  898. /* Disable compander */
  899. snd_soc_update_bits(codec,
  900. TAPAN_A_CDC_COMP0_B1_CTL + (comp * 8),
  901. enable_mask, 0x00);
  902. /* Toggle compander reset bits */
  903. snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_OTHR_RESET_B2_CTL,
  904. mask << comp_shift[comp],
  905. mask << comp_shift[comp]);
  906. snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_OTHR_RESET_B2_CTL,
  907. mask << comp_shift[comp], 0);
  908. /* Turn off the clock for compander in pair */
  909. snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RX_B2_CTL,
  910. mask << comp_shift[comp], 0);
  911. /* Set gain source to register */
  912. tapan_config_gain_compander(codec, comp, false);
  913. break;
  914. }
  915. return 0;
  916. }
  917. static const char * const tapan_ear_pa_gain_text[] = {"POS_6_DB", "POS_4P5_DB",
  918. "POS_3_DB", "POS_1P5_DB",
  919. "POS_0_DB", "NEG_2P5_DB",
  920. "NEG_12_DB"};
  921. static const struct soc_enum tapan_ear_pa_gain_enum[] = {
  922. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(tapan_ear_pa_gain_text),
  923. tapan_ear_pa_gain_text),
  924. };
  925. static const char *const tapan_anc_func_text[] = {"OFF", "ON"};
  926. static const struct soc_enum tapan_anc_func_enum =
  927. SOC_ENUM_SINGLE_EXT(2, tapan_anc_func_text);
  928. /*cut of frequency for high pass filter*/
  929. static const char * const cf_text[] = {
  930. "MIN_3DB_4Hz", "MIN_3DB_75Hz", "MIN_3DB_150Hz"
  931. };
  932. static const struct soc_enum cf_dec1_enum =
  933. SOC_ENUM_SINGLE(TAPAN_A_CDC_TX1_MUX_CTL, 4, 3, cf_text);
  934. static const struct soc_enum cf_dec2_enum =
  935. SOC_ENUM_SINGLE(TAPAN_A_CDC_TX2_MUX_CTL, 4, 3, cf_text);
  936. static const struct soc_enum cf_dec3_enum =
  937. SOC_ENUM_SINGLE(TAPAN_A_CDC_TX3_MUX_CTL, 4, 3, cf_text);
  938. static const struct soc_enum cf_dec4_enum =
  939. SOC_ENUM_SINGLE(TAPAN_A_CDC_TX4_MUX_CTL, 4, 3, cf_text);
  940. static const struct soc_enum cf_rxmix1_enum =
  941. SOC_ENUM_SINGLE(TAPAN_A_CDC_RX1_B4_CTL, 0, 3, cf_text);
  942. static const struct soc_enum cf_rxmix2_enum =
  943. SOC_ENUM_SINGLE(TAPAN_A_CDC_RX2_B4_CTL, 0, 3, cf_text);
  944. static const struct soc_enum cf_rxmix3_enum =
  945. SOC_ENUM_SINGLE(TAPAN_A_CDC_RX3_B4_CTL, 0, 3, cf_text);
  946. static const struct soc_enum cf_rxmix4_enum =
  947. SOC_ENUM_SINGLE(TAPAN_A_CDC_RX4_B4_CTL, 0, 3, cf_text);
  948. static const char * const class_h_dsm_text[] = {
  949. "ZERO", "RX_HPHL", "RX_SPKR"
  950. };
  951. static const struct soc_enum class_h_dsm_enum =
  952. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_CLSH_CTL, 2, 3, class_h_dsm_text);
  953. static const struct snd_kcontrol_new class_h_dsm_mux =
  954. SOC_DAPM_ENUM("CLASS_H_DSM MUX Mux", class_h_dsm_enum);
  955. static const char * const rx1_interpolator_text[] = {
  956. "ZERO", "RX1 MIX2"
  957. };
  958. static const struct soc_enum rx1_interpolator_enum =
  959. SOC_ENUM_SINGLE(0, 0, 2, rx1_interpolator_text);
  960. static const struct snd_kcontrol_new rx1_interpolator =
  961. SOC_DAPM_ENUM_VIRT("RX1 INTERPOLATOR Mux", rx1_interpolator_enum);
  962. static const char * const rx2_interpolator_text[] = {
  963. "ZERO", "RX2 MIX2"
  964. };
  965. static const struct soc_enum rx2_interpolator_enum =
  966. SOC_ENUM_SINGLE(0, 1, 2, rx2_interpolator_text);
  967. static const struct snd_kcontrol_new rx2_interpolator =
  968. SOC_DAPM_ENUM_VIRT("RX2 INTERPOLATOR Mux", rx2_interpolator_enum);
  969. static int tapan_hph_impedance_get(struct snd_kcontrol *kcontrol,
  970. struct snd_ctl_elem_value *ucontrol)
  971. {
  972. uint32_t zl, zr;
  973. bool hphr;
  974. struct soc_multi_mixer_control *mc;
  975. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  976. struct tapan_priv *priv = snd_soc_codec_get_drvdata(codec);
  977. mc = (struct soc_multi_mixer_control *)(kcontrol->private_value);
  978. hphr = mc->shift;
  979. wcd9xxx_mbhc_get_impedance(&priv->mbhc, &zl, &zr);
  980. pr_debug("%s: zl %u, zr %u\n", __func__, zl, zr);
  981. ucontrol->value.integer.value[0] = hphr ? zr : zl;
  982. return 0;
  983. }
  984. static const struct snd_kcontrol_new tapan_common_snd_controls[] = {
  985. SOC_ENUM_EXT("EAR PA Gain", tapan_ear_pa_gain_enum[0],
  986. tapan_pa_gain_get, tapan_pa_gain_put),
  987. SOC_SINGLE_TLV("HPHL Volume", TAPAN_A_RX_HPH_L_GAIN, 0, 20, 1,
  988. line_gain),
  989. SOC_SINGLE_TLV("HPHR Volume", TAPAN_A_RX_HPH_R_GAIN, 0, 20, 1,
  990. line_gain),
  991. SOC_SINGLE_TLV("LINEOUT1 Volume", TAPAN_A_RX_LINE_1_GAIN, 0, 20, 1,
  992. line_gain),
  993. SOC_SINGLE_TLV("LINEOUT2 Volume", TAPAN_A_RX_LINE_2_GAIN, 0, 20, 1,
  994. line_gain),
  995. SOC_SINGLE_TLV("SPK DRV Volume", TAPAN_A_SPKR_DRV_GAIN, 3, 8, 1,
  996. line_gain),
  997. SOC_SINGLE_TLV("ADC1 Volume", TAPAN_A_TX_1_EN, 2, 19, 0, analog_gain),
  998. SOC_SINGLE_TLV("ADC2 Volume", TAPAN_A_TX_2_EN, 2, 19, 0, analog_gain),
  999. SOC_SINGLE_TLV("ADC3 Volume", TAPAN_A_TX_3_EN, 2, 19, 0, analog_gain),
  1000. SOC_SINGLE_TLV("ADC4 Volume", TAPAN_A_TX_4_EN, 2, 19, 0, analog_gain),
  1001. SOC_SINGLE_S8_TLV("RX1 Digital Volume", TAPAN_A_CDC_RX1_VOL_CTL_B2_CTL,
  1002. -84, 40, digital_gain),
  1003. SOC_SINGLE_S8_TLV("RX2 Digital Volume", TAPAN_A_CDC_RX2_VOL_CTL_B2_CTL,
  1004. -84, 40, digital_gain),
  1005. SOC_SINGLE_S8_TLV("RX3 Digital Volume", TAPAN_A_CDC_RX3_VOL_CTL_B2_CTL,
  1006. -84, 40, digital_gain),
  1007. SOC_SINGLE_S8_TLV("DEC1 Volume", TAPAN_A_CDC_TX1_VOL_CTL_GAIN, -84, 40,
  1008. digital_gain),
  1009. SOC_SINGLE_S8_TLV("DEC2 Volume", TAPAN_A_CDC_TX2_VOL_CTL_GAIN, -84, 40,
  1010. digital_gain),
  1011. SOC_SINGLE_S8_TLV("IIR1 INP1 Volume", TAPAN_A_CDC_IIR1_GAIN_B1_CTL, -84,
  1012. 40, digital_gain),
  1013. SOC_SINGLE_S8_TLV("IIR1 INP2 Volume", TAPAN_A_CDC_IIR1_GAIN_B2_CTL, -84,
  1014. 40, digital_gain),
  1015. SOC_SINGLE_S8_TLV("IIR1 INP3 Volume", TAPAN_A_CDC_IIR1_GAIN_B3_CTL, -84,
  1016. 40, digital_gain),
  1017. SOC_SINGLE_S8_TLV("IIR1 INP4 Volume", TAPAN_A_CDC_IIR1_GAIN_B4_CTL, -84,
  1018. 40, digital_gain),
  1019. SOC_SINGLE_S8_TLV("IIR2 INP1 Volume", TAPAN_A_CDC_IIR2_GAIN_B1_CTL, -84,
  1020. 40, digital_gain),
  1021. SOC_SINGLE_S8_TLV("IIR2 INP2 Volume", TAPAN_A_CDC_IIR2_GAIN_B2_CTL, -84,
  1022. 40, digital_gain),
  1023. SOC_SINGLE_S8_TLV("IIR2 INP3 Volume", TAPAN_A_CDC_IIR2_GAIN_B3_CTL, -84,
  1024. 40, digital_gain),
  1025. SOC_SINGLE_S8_TLV("IIR2 INP4 Volume", TAPAN_A_CDC_IIR2_GAIN_B4_CTL, -84,
  1026. 40, digital_gain),
  1027. SOC_ENUM("TX1 HPF cut off", cf_dec1_enum),
  1028. SOC_ENUM("TX2 HPF cut off", cf_dec2_enum),
  1029. SOC_ENUM("TX3 HPF cut off", cf_dec3_enum),
  1030. SOC_ENUM("TX4 HPF cut off", cf_dec4_enum),
  1031. SOC_SINGLE("TX1 HPF Switch", TAPAN_A_CDC_TX1_MUX_CTL, 3, 1, 0),
  1032. SOC_SINGLE("TX2 HPF Switch", TAPAN_A_CDC_TX2_MUX_CTL, 3, 1, 0),
  1033. SOC_SINGLE("TX3 HPF Switch", TAPAN_A_CDC_TX3_MUX_CTL, 3, 1, 0),
  1034. SOC_SINGLE("TX4 HPF Switch", TAPAN_A_CDC_TX4_MUX_CTL, 3, 1, 0),
  1035. SOC_SINGLE("RX1 HPF Switch", TAPAN_A_CDC_RX1_B5_CTL, 2, 1, 0),
  1036. SOC_SINGLE("RX2 HPF Switch", TAPAN_A_CDC_RX2_B5_CTL, 2, 1, 0),
  1037. SOC_SINGLE("RX3 HPF Switch", TAPAN_A_CDC_RX3_B5_CTL, 2, 1, 0),
  1038. SOC_ENUM("RX1 HPF cut off", cf_rxmix1_enum),
  1039. SOC_ENUM("RX2 HPF cut off", cf_rxmix2_enum),
  1040. SOC_ENUM("RX3 HPF cut off", cf_rxmix3_enum),
  1041. SOC_SINGLE_EXT("IIR1 Enable Band1", IIR1, BAND1, 1, 0,
  1042. tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer),
  1043. SOC_SINGLE_EXT("IIR1 Enable Band2", IIR1, BAND2, 1, 0,
  1044. tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer),
  1045. SOC_SINGLE_EXT("IIR1 Enable Band3", IIR1, BAND3, 1, 0,
  1046. tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer),
  1047. SOC_SINGLE_EXT("IIR1 Enable Band4", IIR1, BAND4, 1, 0,
  1048. tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer),
  1049. SOC_SINGLE_EXT("IIR1 Enable Band5", IIR1, BAND5, 1, 0,
  1050. tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer),
  1051. SOC_SINGLE_EXT("IIR2 Enable Band1", IIR2, BAND1, 1, 0,
  1052. tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer),
  1053. SOC_SINGLE_EXT("IIR2 Enable Band2", IIR2, BAND2, 1, 0,
  1054. tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer),
  1055. SOC_SINGLE_EXT("IIR2 Enable Band3", IIR2, BAND3, 1, 0,
  1056. tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer),
  1057. SOC_SINGLE_EXT("IIR2 Enable Band4", IIR2, BAND4, 1, 0,
  1058. tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer),
  1059. SOC_SINGLE_EXT("IIR2 Enable Band5", IIR2, BAND5, 1, 0,
  1060. tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer),
  1061. SOC_SINGLE_MULTI_EXT("IIR1 Band1", IIR1, BAND1, 255, 0, 5,
  1062. tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer),
  1063. SOC_SINGLE_MULTI_EXT("IIR1 Band2", IIR1, BAND2, 255, 0, 5,
  1064. tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer),
  1065. SOC_SINGLE_MULTI_EXT("IIR1 Band3", IIR1, BAND3, 255, 0, 5,
  1066. tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer),
  1067. SOC_SINGLE_MULTI_EXT("IIR1 Band4", IIR1, BAND4, 255, 0, 5,
  1068. tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer),
  1069. SOC_SINGLE_MULTI_EXT("IIR1 Band5", IIR1, BAND5, 255, 0, 5,
  1070. tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer),
  1071. SOC_SINGLE_MULTI_EXT("IIR2 Band1", IIR2, BAND1, 255, 0, 5,
  1072. tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer),
  1073. SOC_SINGLE_MULTI_EXT("IIR2 Band2", IIR2, BAND2, 255, 0, 5,
  1074. tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer),
  1075. SOC_SINGLE_MULTI_EXT("IIR2 Band3", IIR2, BAND3, 255, 0, 5,
  1076. tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer),
  1077. SOC_SINGLE_MULTI_EXT("IIR2 Band4", IIR2, BAND4, 255, 0, 5,
  1078. tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer),
  1079. SOC_SINGLE_MULTI_EXT("IIR2 Band5", IIR2, BAND5, 255, 0, 5,
  1080. tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer),
  1081. SOC_SINGLE_EXT("HPHL Impedance", 0, 0, UINT_MAX, 0,
  1082. tapan_hph_impedance_get, NULL),
  1083. SOC_SINGLE_EXT("HPHR Impedance", 0, 1, UINT_MAX, 0,
  1084. tapan_hph_impedance_get, NULL),
  1085. };
  1086. static const struct snd_kcontrol_new tapan_9306_snd_controls[] = {
  1087. SOC_SINGLE_TLV("ADC5 Volume", TAPAN_A_TX_5_EN, 2, 19, 0, analog_gain),
  1088. SOC_SINGLE_S8_TLV("RX4 Digital Volume", TAPAN_A_CDC_RX4_VOL_CTL_B2_CTL,
  1089. -84, 40, digital_gain),
  1090. SOC_SINGLE_S8_TLV("DEC3 Volume", TAPAN_A_CDC_TX3_VOL_CTL_GAIN, -84, 40,
  1091. digital_gain),
  1092. SOC_SINGLE_S8_TLV("DEC4 Volume", TAPAN_A_CDC_TX4_VOL_CTL_GAIN, -84, 40,
  1093. digital_gain),
  1094. SOC_SINGLE_EXT("ANC Slot", SND_SOC_NOPM, 0, 100, 0, tapan_get_anc_slot,
  1095. tapan_put_anc_slot),
  1096. SOC_ENUM_EXT("ANC Function", tapan_anc_func_enum, tapan_get_anc_func,
  1097. tapan_put_anc_func),
  1098. SOC_SINGLE("RX4 HPF Switch", TAPAN_A_CDC_RX4_B5_CTL, 2, 1, 0),
  1099. SOC_ENUM("RX4 HPF cut off", cf_rxmix4_enum),
  1100. SOC_SINGLE_EXT("COMP0 Switch", SND_SOC_NOPM, COMPANDER_0, 1, 0,
  1101. tapan_get_compander, tapan_set_compander),
  1102. SOC_SINGLE_EXT("COMP1 Switch", SND_SOC_NOPM, COMPANDER_1, 1, 0,
  1103. tapan_get_compander, tapan_set_compander),
  1104. SOC_SINGLE_EXT("COMP2 Switch", SND_SOC_NOPM, COMPANDER_2, 1, 0,
  1105. tapan_get_compander, tapan_set_compander),
  1106. };
  1107. static const char * const rx_1_2_mix1_text[] = {
  1108. "ZERO", "SRC1", "SRC2", "IIR1", "IIR2", "RX1", "RX2", "RX3", "RX4",
  1109. "RX5", "AUXRX", "AUXTX1"
  1110. };
  1111. static const char * const rx_3_4_mix1_text[] = {
  1112. "ZERO", "SRC1", "SRC2", "IIR1", "IIR2", "RX1", "RX2", "RX3", "RX4",
  1113. "RX5", "AUXRX", "AUXTX1", "AUXTX2"
  1114. };
  1115. static const char * const rx_mix2_text[] = {
  1116. "ZERO", "SRC1", "SRC2", "IIR1", "IIR2"
  1117. };
  1118. static const char * const rx_rdac3_text[] = {
  1119. "DEM1", "DEM2"
  1120. };
  1121. static const char * const rx_rdac4_text[] = {
  1122. "DEM3", "DEM2"
  1123. };
  1124. static const char * const rx_rdac5_text[] = {
  1125. "DEM4", "DEM3_INV"
  1126. };
  1127. static const char * const sb_tx_1_2_mux_text[] = {
  1128. "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4",
  1129. "RSVD", "RSVD", "RSVD",
  1130. "DEC1", "DEC2", "DEC3", "DEC4"
  1131. };
  1132. static const char * const sb_tx3_mux_text[] = {
  1133. "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4",
  1134. "RSVD", "RSVD", "RSVD", "RSVD", "RSVD",
  1135. "DEC3"
  1136. };
  1137. static const char * const sb_tx4_mux_text[] = {
  1138. "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4",
  1139. "RSVD", "RSVD", "RSVD", "RSVD", "RSVD", "RSVD",
  1140. "DEC4"
  1141. };
  1142. static const char * const sb_tx5_mux_text[] = {
  1143. "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4",
  1144. "RSVD", "RSVD", "RSVD",
  1145. "DEC1"
  1146. };
  1147. static const char * const dec_1_2_mux_text[] = {
  1148. "ZERO", "ADC1", "ADC2", "ADC3", "ADC4", "ADCMB",
  1149. "DMIC1", "DMIC2", "DMIC3", "DMIC4"
  1150. };
  1151. static const char * const dec3_mux_text[] = {
  1152. "ZERO", "ADC1", "ADC2", "ADC3", "ADC4", "ADC5", "ADCMB",
  1153. "DMIC1", "DMIC2", "DMIC3", "DMIC4",
  1154. "ANCFBTUNE1"
  1155. };
  1156. static const char * const dec4_mux_text[] = {
  1157. "ZERO", "ADC1", "ADC2", "ADC3", "ADC4", "ADC5", "ADCMB",
  1158. "DMIC1", "DMIC2", "DMIC3", "DMIC4",
  1159. "ANCFBTUNE2"
  1160. };
  1161. static const char * const anc_mux_text[] = {
  1162. "ZERO", "ADC1", "ADC2", "ADC3", "ADC4", "ADC5",
  1163. "RSVD", "RSVD", "RSVD",
  1164. "DMIC1", "DMIC2", "DMIC3", "DMIC4",
  1165. "RSVD", "RSVD"
  1166. };
  1167. static const char * const anc1_fb_mux_text[] = {
  1168. "ZERO", "EAR_HPH_L", "EAR_LINE_1",
  1169. };
  1170. static const char * const iir_inp_text[] = {
  1171. "ZERO", "DEC1", "DEC2", "DEC3", "DEC4",
  1172. "RX1", "RX2", "RX3", "RX4", "RX5"
  1173. };
  1174. static const struct soc_enum rx_mix1_inp1_chain_enum =
  1175. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX1_B1_CTL, 0, 12, rx_1_2_mix1_text);
  1176. static const struct soc_enum rx_mix1_inp2_chain_enum =
  1177. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX1_B1_CTL, 4, 12, rx_1_2_mix1_text);
  1178. static const struct soc_enum rx_mix1_inp3_chain_enum =
  1179. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX1_B2_CTL, 0, 12, rx_1_2_mix1_text);
  1180. static const struct soc_enum rx2_mix1_inp1_chain_enum =
  1181. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX2_B1_CTL, 0, 12, rx_1_2_mix1_text);
  1182. static const struct soc_enum rx2_mix1_inp2_chain_enum =
  1183. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX2_B1_CTL, 4, 12, rx_1_2_mix1_text);
  1184. static const struct soc_enum rx3_mix1_inp1_chain_enum =
  1185. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX3_B1_CTL, 0, 13, rx_3_4_mix1_text);
  1186. static const struct soc_enum rx3_mix1_inp2_chain_enum =
  1187. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX3_B1_CTL, 4, 13, rx_3_4_mix1_text);
  1188. static const struct soc_enum rx3_mix1_inp3_chain_enum =
  1189. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX3_B2_CTL, 0, 13, rx_3_4_mix1_text);
  1190. static const struct soc_enum rx4_mix1_inp1_chain_enum =
  1191. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX4_B1_CTL, 0, 13, rx_3_4_mix1_text);
  1192. static const struct soc_enum rx4_mix1_inp2_chain_enum =
  1193. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX4_B1_CTL, 4, 13, rx_3_4_mix1_text);
  1194. static const struct soc_enum rx4_mix1_inp3_chain_enum =
  1195. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX4_B2_CTL, 0, 13, rx_3_4_mix1_text);
  1196. static const struct soc_enum rx1_mix2_inp1_chain_enum =
  1197. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX1_B3_CTL, 0, 5, rx_mix2_text);
  1198. static const struct soc_enum rx1_mix2_inp2_chain_enum =
  1199. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX1_B3_CTL, 3, 5, rx_mix2_text);
  1200. static const struct soc_enum rx2_mix2_inp1_chain_enum =
  1201. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX2_B3_CTL, 0, 5, rx_mix2_text);
  1202. static const struct soc_enum rx2_mix2_inp2_chain_enum =
  1203. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX2_B3_CTL, 3, 5, rx_mix2_text);
  1204. static const struct soc_enum rx4_mix2_inp1_chain_enum =
  1205. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX4_B3_CTL, 0, 5, rx_mix2_text);
  1206. static const struct soc_enum rx4_mix2_inp2_chain_enum =
  1207. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX4_B3_CTL, 3, 5, rx_mix2_text);
  1208. static const struct soc_enum rx_rdac3_enum =
  1209. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX2_B2_CTL, 4, 2, rx_rdac3_text);
  1210. static const struct soc_enum rx_rdac4_enum =
  1211. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_MISC, 1, 2, rx_rdac4_text);
  1212. static const struct soc_enum rx_rdac5_enum =
  1213. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_MISC, 2, 2, rx_rdac5_text);
  1214. static const struct soc_enum sb_tx1_mux_enum =
  1215. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_SB_B1_CTL, 0, 12,
  1216. sb_tx_1_2_mux_text);
  1217. static const struct soc_enum sb_tx2_mux_enum =
  1218. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_SB_B2_CTL, 0, 12,
  1219. sb_tx_1_2_mux_text);
  1220. static const struct soc_enum sb_tx3_mux_enum =
  1221. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_SB_B3_CTL, 0, 11, sb_tx3_mux_text);
  1222. static const struct soc_enum sb_tx4_mux_enum =
  1223. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_SB_B4_CTL, 0, 12, sb_tx4_mux_text);
  1224. static const struct soc_enum sb_tx5_mux_enum =
  1225. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_SB_B5_CTL, 0, 9, sb_tx5_mux_text);
  1226. static const struct soc_enum dec1_mux_enum =
  1227. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_B1_CTL, 0, 10, dec_1_2_mux_text);
  1228. static const struct soc_enum dec2_mux_enum =
  1229. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_B1_CTL, 4, 10, dec_1_2_mux_text);
  1230. static const struct soc_enum dec3_mux_enum =
  1231. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_B2_CTL, 0, 12, dec3_mux_text);
  1232. static const struct soc_enum dec4_mux_enum =
  1233. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_B2_CTL, 4, 12, dec4_mux_text);
  1234. static const struct soc_enum anc1_mux_enum =
  1235. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_ANC_B1_CTL, 0, 15, anc_mux_text);
  1236. static const struct soc_enum anc2_mux_enum =
  1237. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_ANC_B1_CTL, 4, 15, anc_mux_text);
  1238. static const struct soc_enum anc1_fb_mux_enum =
  1239. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_ANC_B2_CTL, 0, 3, anc1_fb_mux_text);
  1240. static const struct soc_enum iir1_inp1_mux_enum =
  1241. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_EQ1_B1_CTL, 0, 10, iir_inp_text);
  1242. static const struct soc_enum iir1_inp2_mux_enum =
  1243. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_EQ1_B2_CTL, 0, 10, iir_inp_text);
  1244. static const struct soc_enum iir1_inp3_mux_enum =
  1245. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_EQ1_B3_CTL, 0, 10, iir_inp_text);
  1246. static const struct soc_enum iir1_inp4_mux_enum =
  1247. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_EQ1_B4_CTL, 0, 10, iir_inp_text);
  1248. static const struct soc_enum iir2_inp1_mux_enum =
  1249. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_EQ2_B1_CTL, 0, 10, iir_inp_text);
  1250. static const struct soc_enum iir2_inp2_mux_enum =
  1251. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_EQ2_B2_CTL, 0, 10, iir_inp_text);
  1252. static const struct soc_enum iir2_inp3_mux_enum =
  1253. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_EQ2_B3_CTL, 0, 10, iir_inp_text);
  1254. static const struct soc_enum iir2_inp4_mux_enum =
  1255. SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_EQ2_B4_CTL, 0, 10, iir_inp_text);
  1256. static const struct snd_kcontrol_new rx_mix1_inp1_mux =
  1257. SOC_DAPM_ENUM("RX1 MIX1 INP1 Mux", rx_mix1_inp1_chain_enum);
  1258. static const struct snd_kcontrol_new rx_mix1_inp2_mux =
  1259. SOC_DAPM_ENUM("RX1 MIX1 INP2 Mux", rx_mix1_inp2_chain_enum);
  1260. static const struct snd_kcontrol_new rx_mix1_inp3_mux =
  1261. SOC_DAPM_ENUM("RX1 MIX1 INP3 Mux", rx_mix1_inp3_chain_enum);
  1262. static const struct snd_kcontrol_new rx2_mix1_inp1_mux =
  1263. SOC_DAPM_ENUM("RX2 MIX1 INP1 Mux", rx2_mix1_inp1_chain_enum);
  1264. static const struct snd_kcontrol_new rx2_mix1_inp2_mux =
  1265. SOC_DAPM_ENUM("RX2 MIX1 INP2 Mux", rx2_mix1_inp2_chain_enum);
  1266. static const struct snd_kcontrol_new rx3_mix1_inp1_mux =
  1267. SOC_DAPM_ENUM("RX3 MIX1 INP1 Mux", rx3_mix1_inp1_chain_enum);
  1268. static const struct snd_kcontrol_new rx3_mix1_inp2_mux =
  1269. SOC_DAPM_ENUM("RX3 MIX1 INP2 Mux", rx3_mix1_inp2_chain_enum);
  1270. static const struct snd_kcontrol_new rx3_mix1_inp3_mux =
  1271. SOC_DAPM_ENUM("RX3 MIX1 INP3 Mux", rx3_mix1_inp3_chain_enum);
  1272. static const struct snd_kcontrol_new rx4_mix1_inp1_mux =
  1273. SOC_DAPM_ENUM("RX4 MIX1 INP1 Mux", rx4_mix1_inp1_chain_enum);
  1274. static const struct snd_kcontrol_new rx4_mix1_inp2_mux =
  1275. SOC_DAPM_ENUM("RX4 MIX1 INP2 Mux", rx4_mix1_inp2_chain_enum);
  1276. static const struct snd_kcontrol_new rx4_mix1_inp3_mux =
  1277. SOC_DAPM_ENUM("RX4 MIX1 INP3 Mux", rx4_mix1_inp3_chain_enum);
  1278. static const struct snd_kcontrol_new rx1_mix2_inp1_mux =
  1279. SOC_DAPM_ENUM("RX1 MIX2 INP1 Mux", rx1_mix2_inp1_chain_enum);
  1280. static const struct snd_kcontrol_new rx1_mix2_inp2_mux =
  1281. SOC_DAPM_ENUM("RX1 MIX2 INP2 Mux", rx1_mix2_inp2_chain_enum);
  1282. static const struct snd_kcontrol_new rx2_mix2_inp1_mux =
  1283. SOC_DAPM_ENUM("RX2 MIX2 INP1 Mux", rx2_mix2_inp1_chain_enum);
  1284. static const struct snd_kcontrol_new rx2_mix2_inp2_mux =
  1285. SOC_DAPM_ENUM("RX2 MIX2 INP2 Mux", rx2_mix2_inp2_chain_enum);
  1286. static const struct snd_kcontrol_new rx4_mix2_inp1_mux =
  1287. SOC_DAPM_ENUM("RX4 MIX2 INP1 Mux", rx4_mix2_inp1_chain_enum);
  1288. static const struct snd_kcontrol_new rx4_mix2_inp2_mux =
  1289. SOC_DAPM_ENUM("RX4 MIX2 INP2 Mux", rx4_mix2_inp2_chain_enum);
  1290. static const struct snd_kcontrol_new rx_dac3_mux =
  1291. SOC_DAPM_ENUM("RDAC3 MUX Mux", rx_rdac3_enum);
  1292. static const struct snd_kcontrol_new rx_dac4_mux =
  1293. SOC_DAPM_ENUM("RDAC4 MUX Mux", rx_rdac4_enum);
  1294. static const struct snd_kcontrol_new rx_dac5_mux =
  1295. SOC_DAPM_ENUM("RDAC5 MUX Mux", rx_rdac5_enum);
  1296. static const struct snd_kcontrol_new sb_tx1_mux =
  1297. SOC_DAPM_ENUM("SLIM TX1 MUX Mux", sb_tx1_mux_enum);
  1298. static const struct snd_kcontrol_new sb_tx2_mux =
  1299. SOC_DAPM_ENUM("SLIM TX2 MUX Mux", sb_tx2_mux_enum);
  1300. static const struct snd_kcontrol_new sb_tx3_mux =
  1301. SOC_DAPM_ENUM("SLIM TX3 MUX Mux", sb_tx3_mux_enum);
  1302. static const struct snd_kcontrol_new sb_tx4_mux =
  1303. SOC_DAPM_ENUM("SLIM TX4 MUX Mux", sb_tx4_mux_enum);
  1304. static const struct snd_kcontrol_new sb_tx5_mux =
  1305. SOC_DAPM_ENUM("SLIM TX5 MUX Mux", sb_tx5_mux_enum);
  1306. static int wcd9306_put_dec_enum(struct snd_kcontrol *kcontrol,
  1307. struct snd_ctl_elem_value *ucontrol)
  1308. {
  1309. struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
  1310. struct snd_soc_dapm_widget *w = wlist->widgets[0];
  1311. struct snd_soc_codec *codec = w->codec;
  1312. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1313. unsigned int dec_mux, decimator;
  1314. char *dec_name = NULL;
  1315. char *widget_name = NULL;
  1316. char *temp;
  1317. u16 tx_mux_ctl_reg;
  1318. u8 adc_dmic_sel = 0x0;
  1319. int ret = 0;
  1320. char *srch = NULL;
  1321. if (ucontrol->value.enumerated.item[0] > e->max - 1)
  1322. return -EINVAL;
  1323. dec_mux = ucontrol->value.enumerated.item[0];
  1324. widget_name = kstrndup(w->name, 15, GFP_KERNEL);
  1325. if (!widget_name)
  1326. return -ENOMEM;
  1327. temp = widget_name;
  1328. dec_name = strsep(&widget_name, " ");
  1329. widget_name = temp;
  1330. if (!dec_name) {
  1331. pr_err("%s: Invalid decimator = %s\n", __func__, w->name);
  1332. ret = -EINVAL;
  1333. goto out;
  1334. }
  1335. srch = strpbrk(dec_name, "1234");
  1336. if (srch == NULL) {
  1337. pr_err("%s: Invalid decimator name %s\n", __func__, dec_name);
  1338. return -EINVAL;
  1339. }
  1340. ret = kstrtouint(srch, 10, &decimator);
  1341. if (ret < 0) {
  1342. pr_err("%s: Invalid decimator = %s\n", __func__, dec_name);
  1343. ret = -EINVAL;
  1344. goto out;
  1345. }
  1346. dev_dbg(w->dapm->dev, "%s(): widget = %s decimator = %u dec_mux = %u\n"
  1347. , __func__, w->name, decimator, dec_mux);
  1348. switch (decimator) {
  1349. case 1:
  1350. case 2:
  1351. if ((dec_mux >= 1) && (dec_mux <= 5))
  1352. adc_dmic_sel = 0x0;
  1353. else if ((dec_mux >= 6) && (dec_mux <= 9))
  1354. adc_dmic_sel = 0x1;
  1355. break;
  1356. case 3:
  1357. case 4:
  1358. if ((dec_mux >= 1) && (dec_mux <= 6))
  1359. adc_dmic_sel = 0x0;
  1360. else if ((dec_mux >= 7) && (dec_mux <= 10))
  1361. adc_dmic_sel = 0x1;
  1362. break;
  1363. default:
  1364. pr_err("%s: Invalid Decimator = %u\n", __func__, decimator);
  1365. ret = -EINVAL;
  1366. goto out;
  1367. }
  1368. tx_mux_ctl_reg = TAPAN_A_CDC_TX1_MUX_CTL + 8 * (decimator - 1);
  1369. snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x1, adc_dmic_sel);
  1370. ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
  1371. out:
  1372. kfree(widget_name);
  1373. return ret;
  1374. }
  1375. #define WCD9306_DEC_ENUM(xname, xenum) \
  1376. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  1377. .info = snd_soc_info_enum_double, \
  1378. .get = snd_soc_dapm_get_enum_double, \
  1379. .put = wcd9306_put_dec_enum, \
  1380. .private_value = (unsigned long)&xenum }
  1381. static const struct snd_kcontrol_new dec1_mux =
  1382. WCD9306_DEC_ENUM("DEC1 MUX Mux", dec1_mux_enum);
  1383. static const struct snd_kcontrol_new dec2_mux =
  1384. WCD9306_DEC_ENUM("DEC2 MUX Mux", dec2_mux_enum);
  1385. static const struct snd_kcontrol_new dec3_mux =
  1386. WCD9306_DEC_ENUM("DEC3 MUX Mux", dec3_mux_enum);
  1387. static const struct snd_kcontrol_new dec4_mux =
  1388. WCD9306_DEC_ENUM("DEC4 MUX Mux", dec4_mux_enum);
  1389. static const struct snd_kcontrol_new iir1_inp1_mux =
  1390. SOC_DAPM_ENUM("IIR1 INP1 Mux", iir1_inp1_mux_enum);
  1391. static const struct snd_kcontrol_new iir1_inp2_mux =
  1392. SOC_DAPM_ENUM("IIR1 INP2 Mux", iir1_inp2_mux_enum);
  1393. static const struct snd_kcontrol_new iir1_inp3_mux =
  1394. SOC_DAPM_ENUM("IIR1 INP3 Mux", iir1_inp3_mux_enum);
  1395. static const struct snd_kcontrol_new iir1_inp4_mux =
  1396. SOC_DAPM_ENUM("IIR1 INP4 Mux", iir1_inp4_mux_enum);
  1397. static const struct snd_kcontrol_new iir2_inp1_mux =
  1398. SOC_DAPM_ENUM("IIR2 INP1 Mux", iir2_inp1_mux_enum);
  1399. static const struct snd_kcontrol_new iir2_inp2_mux =
  1400. SOC_DAPM_ENUM("IIR2 INP2 Mux", iir2_inp2_mux_enum);
  1401. static const struct snd_kcontrol_new iir2_inp3_mux =
  1402. SOC_DAPM_ENUM("IIR2 INP3 Mux", iir2_inp3_mux_enum);
  1403. static const struct snd_kcontrol_new iir2_inp4_mux =
  1404. SOC_DAPM_ENUM("IIR2 INP4 Mux", iir2_inp4_mux_enum);
  1405. static const struct snd_kcontrol_new anc1_mux =
  1406. SOC_DAPM_ENUM("ANC1 MUX Mux", anc1_mux_enum);
  1407. static const struct snd_kcontrol_new anc2_mux =
  1408. SOC_DAPM_ENUM("ANC2 MUX Mux", anc2_mux_enum);
  1409. static const struct snd_kcontrol_new anc1_fb_mux =
  1410. SOC_DAPM_ENUM("ANC1 FB MUX Mux", anc1_fb_mux_enum);
  1411. static const struct snd_kcontrol_new dac1_switch[] = {
  1412. SOC_DAPM_SINGLE("Switch", TAPAN_A_RX_EAR_EN, 5, 1, 0)
  1413. };
  1414. static const struct snd_kcontrol_new hphl_switch[] = {
  1415. SOC_DAPM_SINGLE("Switch", TAPAN_A_RX_HPH_L_DAC_CTL, 6, 1, 0)
  1416. };
  1417. static const struct snd_kcontrol_new spk_dac_switch[] = {
  1418. SOC_DAPM_SINGLE("Switch", TAPAN_A_SPKR_DRV_DAC_CTL, 2, 1, 0)
  1419. };
  1420. static const struct snd_kcontrol_new hphl_pa_mix[] = {
  1421. SOC_DAPM_SINGLE("AUX_PGA_L Switch", TAPAN_A_RX_PA_AUX_IN_CONN,
  1422. 7, 1, 0),
  1423. };
  1424. static const struct snd_kcontrol_new hphr_pa_mix[] = {
  1425. SOC_DAPM_SINGLE("AUX_PGA_R Switch", TAPAN_A_RX_PA_AUX_IN_CONN,
  1426. 6, 1, 0),
  1427. };
  1428. static const struct snd_kcontrol_new ear_pa_mix[] = {
  1429. SOC_DAPM_SINGLE("AUX_PGA_L Switch", TAPAN_A_RX_PA_AUX_IN_CONN,
  1430. 5, 1, 0),
  1431. };
  1432. static const struct snd_kcontrol_new lineout1_pa_mix[] = {
  1433. SOC_DAPM_SINGLE("AUX_PGA_L Switch", TAPAN_A_RX_PA_AUX_IN_CONN,
  1434. 4, 1, 0),
  1435. };
  1436. static const struct snd_kcontrol_new lineout2_pa_mix[] = {
  1437. SOC_DAPM_SINGLE("AUX_PGA_R Switch", TAPAN_A_RX_PA_AUX_IN_CONN,
  1438. 3, 1, 0),
  1439. };
  1440. /* virtual port entries */
  1441. static int slim_tx_mixer_get(struct snd_kcontrol *kcontrol,
  1442. struct snd_ctl_elem_value *ucontrol)
  1443. {
  1444. struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
  1445. struct snd_soc_dapm_widget *widget = wlist->widgets[0];
  1446. ucontrol->value.integer.value[0] = widget->value;
  1447. return 0;
  1448. }
  1449. static int slim_tx_mixer_put(struct snd_kcontrol *kcontrol,
  1450. struct snd_ctl_elem_value *ucontrol)
  1451. {
  1452. struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
  1453. struct snd_soc_dapm_widget *widget = wlist->widgets[0];
  1454. struct snd_soc_codec *codec = widget->codec;
  1455. struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec);
  1456. struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent);
  1457. struct soc_multi_mixer_control *mixer =
  1458. ((struct soc_multi_mixer_control *)kcontrol->private_value);
  1459. u32 dai_id = widget->shift;
  1460. u32 port_id = mixer->shift;
  1461. u32 enable = ucontrol->value.integer.value[0];
  1462. u32 vtable = vport_check_table[dai_id];
  1463. dev_dbg(codec->dev, "%s: wname %s cname %s\n",
  1464. __func__, widget->name, ucontrol->id.name);
  1465. dev_dbg(codec->dev, "%s: value %u shift %d item %ld\n",
  1466. __func__, widget->value, widget->shift,
  1467. ucontrol->value.integer.value[0]);
  1468. mutex_lock(&codec->mutex);
  1469. if (tapan_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) {
  1470. if (dai_id != AIF1_CAP) {
  1471. dev_err(codec->dev, "%s: invalid AIF for I2C mode\n",
  1472. __func__);
  1473. mutex_unlock(&codec->mutex);
  1474. return -EINVAL;
  1475. }
  1476. }
  1477. switch (dai_id) {
  1478. case AIF1_CAP:
  1479. case AIF2_CAP:
  1480. case AIF3_CAP:
  1481. /* only add to the list if value not set
  1482. */
  1483. if (enable && !(widget->value & 1 << port_id)) {
  1484. if (tapan_p->intf_type ==
  1485. WCD9XXX_INTERFACE_TYPE_SLIMBUS)
  1486. vtable = vport_check_table[dai_id];
  1487. if (tapan_p->intf_type ==
  1488. WCD9XXX_INTERFACE_TYPE_I2C)
  1489. vtable = vport_i2s_check_table[dai_id];
  1490. if (wcd9xxx_tx_vport_validation(
  1491. vtable,
  1492. port_id,
  1493. tapan_p->dai, NUM_CODEC_DAIS)) {
  1494. dev_dbg(codec->dev, "%s: TX%u is used by other virtual port\n",
  1495. __func__, port_id + 1);
  1496. mutex_unlock(&codec->mutex);
  1497. return 0;
  1498. }
  1499. widget->value |= 1 << port_id;
  1500. list_add_tail(&core->tx_chs[port_id].list,
  1501. &tapan_p->dai[dai_id].wcd9xxx_ch_list
  1502. );
  1503. } else if (!enable && (widget->value & 1 << port_id)) {
  1504. widget->value &= ~(1 << port_id);
  1505. list_del_init(&core->tx_chs[port_id].list);
  1506. } else {
  1507. if (enable)
  1508. dev_dbg(codec->dev, "%s: TX%u port is used by\n"
  1509. "this virtual port\n",
  1510. __func__, port_id + 1);
  1511. else
  1512. dev_dbg(codec->dev, "%s: TX%u port is not used by\n"
  1513. "this virtual port\n",
  1514. __func__, port_id + 1);
  1515. /* avoid update power function */
  1516. mutex_unlock(&codec->mutex);
  1517. return 0;
  1518. }
  1519. break;
  1520. default:
  1521. dev_err(codec->dev, "Unknown AIF %d\n", dai_id);
  1522. mutex_unlock(&codec->mutex);
  1523. return -EINVAL;
  1524. }
  1525. dev_dbg(codec->dev, "%s: name %s sname %s updated value %u shift %d\n",
  1526. __func__, widget->name, widget->sname,
  1527. widget->value, widget->shift);
  1528. snd_soc_dapm_mixer_update_power(widget, kcontrol, enable);
  1529. mutex_unlock(&codec->mutex);
  1530. return 0;
  1531. }
  1532. static int slim_rx_mux_get(struct snd_kcontrol *kcontrol,
  1533. struct snd_ctl_elem_value *ucontrol)
  1534. {
  1535. struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
  1536. struct snd_soc_dapm_widget *widget = wlist->widgets[0];
  1537. ucontrol->value.enumerated.item[0] = widget->value;
  1538. return 0;
  1539. }
  1540. static const char *const slim_rx_mux_text[] = {
  1541. "ZERO", "AIF1_PB", "AIF2_PB", "AIF3_PB"
  1542. };
  1543. static int slim_rx_mux_put(struct snd_kcontrol *kcontrol,
  1544. struct snd_ctl_elem_value *ucontrol)
  1545. {
  1546. struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
  1547. struct snd_soc_dapm_widget *widget = wlist->widgets[0];
  1548. struct snd_soc_codec *codec = widget->codec;
  1549. struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec);
  1550. struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent);
  1551. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1552. u32 port_id = widget->shift;
  1553. dev_dbg(codec->dev, "%s: wname %s cname %s value %u shift %d item %ld\n",
  1554. __func__, widget->name, ucontrol->id.name, widget->value,
  1555. widget->shift, ucontrol->value.integer.value[0]);
  1556. widget->value = ucontrol->value.enumerated.item[0];
  1557. mutex_lock(&codec->mutex);
  1558. if (tapan_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) {
  1559. if (widget->value > 1) {
  1560. dev_err(codec->dev, "%s: invalid AIF for I2C mode\n",
  1561. __func__);
  1562. goto err;
  1563. }
  1564. }
  1565. /* value need to match the Virtual port and AIF number
  1566. */
  1567. switch (widget->value) {
  1568. case 0:
  1569. list_del_init(&core->rx_chs[port_id].list);
  1570. break;
  1571. case 1:
  1572. if (wcd9xxx_rx_vport_validation(port_id +
  1573. TAPAN_RX_PORT_START_NUMBER,
  1574. &tapan_p->dai[AIF1_PB].wcd9xxx_ch_list)) {
  1575. dev_dbg(codec->dev, "%s: RX%u is used by current requesting AIF_PB itself\n",
  1576. __func__, port_id + 1);
  1577. goto rtn;
  1578. }
  1579. list_add_tail(&core->rx_chs[port_id].list,
  1580. &tapan_p->dai[AIF1_PB].wcd9xxx_ch_list);
  1581. break;
  1582. case 2:
  1583. if (wcd9xxx_rx_vport_validation(port_id +
  1584. TAPAN_RX_PORT_START_NUMBER,
  1585. &tapan_p->dai[AIF2_PB].wcd9xxx_ch_list)) {
  1586. dev_dbg(codec->dev, "%s: RX%u is used by current requesting AIF_PB itself\n",
  1587. __func__, port_id + 1);
  1588. goto rtn;
  1589. }
  1590. list_add_tail(&core->rx_chs[port_id].list,
  1591. &tapan_p->dai[AIF2_PB].wcd9xxx_ch_list);
  1592. break;
  1593. case 3:
  1594. if (wcd9xxx_rx_vport_validation(port_id +
  1595. TAPAN_RX_PORT_START_NUMBER,
  1596. &tapan_p->dai[AIF3_PB].wcd9xxx_ch_list)) {
  1597. dev_dbg(codec->dev, "%s: RX%u is used by current requesting AIF_PB itself\n",
  1598. __func__, port_id + 1);
  1599. goto rtn;
  1600. }
  1601. list_add_tail(&core->rx_chs[port_id].list,
  1602. &tapan_p->dai[AIF3_PB].wcd9xxx_ch_list);
  1603. break;
  1604. default:
  1605. pr_err("Unknown AIF %d\n", widget->value);
  1606. goto err;
  1607. }
  1608. rtn:
  1609. snd_soc_dapm_mux_update_power(widget, kcontrol, 1, widget->value, e);
  1610. mutex_unlock(&codec->mutex);
  1611. return 0;
  1612. err:
  1613. mutex_unlock(&codec->mutex);
  1614. return -EINVAL;
  1615. }
  1616. static const struct soc_enum slim_rx_mux_enum =
  1617. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(slim_rx_mux_text), slim_rx_mux_text);
  1618. static const struct snd_kcontrol_new slim_rx_mux[TAPAN_RX_MAX] = {
  1619. SOC_DAPM_ENUM_EXT("SLIM RX1 Mux", slim_rx_mux_enum,
  1620. slim_rx_mux_get, slim_rx_mux_put),
  1621. SOC_DAPM_ENUM_EXT("SLIM RX2 Mux", slim_rx_mux_enum,
  1622. slim_rx_mux_get, slim_rx_mux_put),
  1623. SOC_DAPM_ENUM_EXT("SLIM RX3 Mux", slim_rx_mux_enum,
  1624. slim_rx_mux_get, slim_rx_mux_put),
  1625. SOC_DAPM_ENUM_EXT("SLIM RX4 Mux", slim_rx_mux_enum,
  1626. slim_rx_mux_get, slim_rx_mux_put),
  1627. SOC_DAPM_ENUM_EXT("SLIM RX5 Mux", slim_rx_mux_enum,
  1628. slim_rx_mux_get, slim_rx_mux_put),
  1629. };
  1630. static const struct snd_kcontrol_new aif_cap_mixer[] = {
  1631. SOC_SINGLE_EXT("SLIM TX1", SND_SOC_NOPM, TAPAN_TX1, 1, 0,
  1632. slim_tx_mixer_get, slim_tx_mixer_put),
  1633. SOC_SINGLE_EXT("SLIM TX2", SND_SOC_NOPM, TAPAN_TX2, 1, 0,
  1634. slim_tx_mixer_get, slim_tx_mixer_put),
  1635. SOC_SINGLE_EXT("SLIM TX3", SND_SOC_NOPM, TAPAN_TX3, 1, 0,
  1636. slim_tx_mixer_get, slim_tx_mixer_put),
  1637. SOC_SINGLE_EXT("SLIM TX4", SND_SOC_NOPM, TAPAN_TX4, 1, 0,
  1638. slim_tx_mixer_get, slim_tx_mixer_put),
  1639. SOC_SINGLE_EXT("SLIM TX5", SND_SOC_NOPM, TAPAN_TX5, 1, 0,
  1640. slim_tx_mixer_get, slim_tx_mixer_put),
  1641. };
  1642. static int tapan_codec_enable_adc(struct snd_soc_dapm_widget *w,
  1643. struct snd_kcontrol *kcontrol, int event)
  1644. {
  1645. struct snd_soc_codec *codec = w->codec;
  1646. struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
  1647. u16 adc_reg;
  1648. u8 init_bit_shift;
  1649. dev_dbg(codec->dev, "%s(): %s %d\n", __func__, w->name, event);
  1650. if (w->reg == TAPAN_A_TX_1_EN) {
  1651. init_bit_shift = 7;
  1652. adc_reg = TAPAN_A_TX_1_2_TEST_CTL;
  1653. } else if (w->reg == TAPAN_A_TX_2_EN) {
  1654. init_bit_shift = 6;
  1655. adc_reg = TAPAN_A_TX_1_2_TEST_CTL;
  1656. } else if (w->reg == TAPAN_A_TX_3_EN) {
  1657. init_bit_shift = 6;
  1658. adc_reg = TAPAN_A_TX_1_2_TEST_CTL;
  1659. } else if (w->reg == TAPAN_A_TX_4_EN) {
  1660. init_bit_shift = 7;
  1661. adc_reg = TAPAN_A_TX_4_5_TEST_CTL;
  1662. } else if (w->reg == TAPAN_A_TX_5_EN) {
  1663. init_bit_shift = 6;
  1664. adc_reg = TAPAN_A_TX_4_5_TEST_CTL;
  1665. } else {
  1666. pr_err("%s: Error, invalid adc register\n", __func__);
  1667. return -EINVAL;
  1668. }
  1669. switch (event) {
  1670. case SND_SOC_DAPM_PRE_PMU:
  1671. if (w->reg == TAPAN_A_TX_3_EN ||
  1672. w->reg == TAPAN_A_TX_1_EN)
  1673. wcd9xxx_resmgr_notifier_call(&tapan->resmgr,
  1674. WCD9XXX_EVENT_PRE_TX_1_3_ON);
  1675. snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift,
  1676. 1 << init_bit_shift);
  1677. break;
  1678. case SND_SOC_DAPM_POST_PMU:
  1679. usleep_range(2000, 2010);
  1680. snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift, 0x00);
  1681. break;
  1682. case SND_SOC_DAPM_POST_PMD:
  1683. if (w->reg == TAPAN_A_TX_3_EN ||
  1684. w->reg == TAPAN_A_TX_1_EN)
  1685. wcd9xxx_resmgr_notifier_call(&tapan->resmgr,
  1686. WCD9XXX_EVENT_POST_TX_1_3_OFF);
  1687. break;
  1688. }
  1689. return 0;
  1690. }
  1691. static int tapan_codec_enable_aux_pga(struct snd_soc_dapm_widget *w,
  1692. struct snd_kcontrol *kcontrol, int event)
  1693. {
  1694. struct snd_soc_codec *codec = w->codec;
  1695. struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
  1696. dev_dbg(codec->dev, "%s: %d\n", __func__, event);
  1697. switch (event) {
  1698. case SND_SOC_DAPM_PRE_PMU:
  1699. WCD9XXX_BG_CLK_LOCK(&tapan->resmgr);
  1700. wcd9xxx_resmgr_get_bandgap(&tapan->resmgr,
  1701. WCD9XXX_BANDGAP_AUDIO_MODE);
  1702. /* AUX PGA requires RCO or MCLK */
  1703. wcd9xxx_resmgr_get_clk_block(&tapan->resmgr, WCD9XXX_CLK_RCO);
  1704. WCD9XXX_BG_CLK_UNLOCK(&tapan->resmgr);
  1705. wcd9xxx_resmgr_enable_rx_bias(&tapan->resmgr, 1);
  1706. break;
  1707. case SND_SOC_DAPM_POST_PMD:
  1708. wcd9xxx_resmgr_enable_rx_bias(&tapan->resmgr, 0);
  1709. WCD9XXX_BG_CLK_LOCK(&tapan->resmgr);
  1710. wcd9xxx_resmgr_put_bandgap(&tapan->resmgr,
  1711. WCD9XXX_BANDGAP_AUDIO_MODE);
  1712. wcd9xxx_resmgr_put_clk_block(&tapan->resmgr, WCD9XXX_CLK_RCO);
  1713. WCD9XXX_BG_CLK_UNLOCK(&tapan->resmgr);
  1714. break;
  1715. }
  1716. return 0;
  1717. }
  1718. static int tapan_codec_enable_lineout(struct snd_soc_dapm_widget *w,
  1719. struct snd_kcontrol *kcontrol, int event)
  1720. {
  1721. struct snd_soc_codec *codec = w->codec;
  1722. struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
  1723. u16 lineout_gain_reg;
  1724. dev_dbg(codec->dev, "%s %d %s\n", __func__, event, w->name);
  1725. switch (w->shift) {
  1726. case 0:
  1727. lineout_gain_reg = TAPAN_A_RX_LINE_1_GAIN;
  1728. break;
  1729. case 1:
  1730. lineout_gain_reg = TAPAN_A_RX_LINE_2_GAIN;
  1731. break;
  1732. default:
  1733. pr_err("%s: Error, incorrect lineout register value\n",
  1734. __func__);
  1735. return -EINVAL;
  1736. }
  1737. switch (event) {
  1738. case SND_SOC_DAPM_PRE_PMU:
  1739. break;
  1740. case SND_SOC_DAPM_POST_PMU:
  1741. wcd9xxx_clsh_fsm(codec, &tapan->clsh_d,
  1742. WCD9XXX_CLSH_STATE_LO,
  1743. WCD9XXX_CLSH_REQ_ENABLE,
  1744. WCD9XXX_CLSH_EVENT_POST_PA);
  1745. dev_dbg(codec->dev, "%s: sleeping 5 ms after %s PA turn on\n",
  1746. __func__, w->name);
  1747. /* Wait for CnP time after PA enable */
  1748. usleep_range(5000, 5100);
  1749. break;
  1750. case SND_SOC_DAPM_POST_PMD:
  1751. wcd9xxx_clsh_fsm(codec, &tapan->clsh_d,
  1752. WCD9XXX_CLSH_STATE_LO,
  1753. WCD9XXX_CLSH_REQ_DISABLE,
  1754. WCD9XXX_CLSH_EVENT_POST_PA);
  1755. dev_dbg(codec->dev, "%s: sleeping 5 ms after %s PA turn off\n",
  1756. __func__, w->name);
  1757. /* Wait for CnP time after PA enable */
  1758. usleep_range(5000, 5100);
  1759. break;
  1760. }
  1761. return 0;
  1762. }
  1763. static int tapan_codec_enable_spk_pa(struct snd_soc_dapm_widget *w,
  1764. struct snd_kcontrol *kcontrol, int event)
  1765. {
  1766. struct snd_soc_codec *codec = w->codec;
  1767. struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
  1768. dev_dbg(codec->dev, "%s: %s %d\n", __func__, w->name, event);
  1769. switch (event) {
  1770. case SND_SOC_DAPM_PRE_PMU:
  1771. tapan->spkr_pa_widget_on = true;
  1772. snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_EN, 0x80, 0x80);
  1773. break;
  1774. case SND_SOC_DAPM_POST_PMD:
  1775. tapan->spkr_pa_widget_on = false;
  1776. snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_EN, 0x80, 0x00);
  1777. break;
  1778. }
  1779. return 0;
  1780. }
  1781. static int tapan_codec_enable_dmic(struct snd_soc_dapm_widget *w,
  1782. struct snd_kcontrol *kcontrol, int event)
  1783. {
  1784. struct snd_soc_codec *codec = w->codec;
  1785. struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
  1786. u8 dmic_clk_en;
  1787. u16 dmic_clk_reg;
  1788. s32 *dmic_clk_cnt;
  1789. unsigned int dmic;
  1790. int ret;
  1791. char *srch = NULL;
  1792. srch = strpbrk(w->name, "1234");
  1793. if (srch == NULL) {
  1794. pr_err("%s: Invalid widget name %s\n", __func__, w->name);
  1795. return -EINVAL;
  1796. }
  1797. ret = kstrtouint(srch, 10, &dmic);
  1798. if (ret < 0) {
  1799. pr_err("%s: Invalid DMIC line on the codec\n", __func__);
  1800. return -EINVAL;
  1801. }
  1802. switch (dmic) {
  1803. case 1:
  1804. case 2:
  1805. dmic_clk_en = 0x01;
  1806. dmic_clk_cnt = &(tapan->dmic_1_2_clk_cnt);
  1807. dmic_clk_reg = TAPAN_A_CDC_CLK_DMIC_B1_CTL;
  1808. dev_dbg(codec->dev, "%s() event %d DMIC%d dmic_1_2_clk_cnt %d\n",
  1809. __func__, event, dmic, *dmic_clk_cnt);
  1810. break;
  1811. case 3:
  1812. case 4:
  1813. dmic_clk_en = 0x10;
  1814. dmic_clk_cnt = &(tapan->dmic_3_4_clk_cnt);
  1815. dmic_clk_reg = TAPAN_A_CDC_CLK_DMIC_B1_CTL;
  1816. dev_dbg(codec->dev, "%s() event %d DMIC%d dmic_3_4_clk_cnt %d\n",
  1817. __func__, event, dmic, *dmic_clk_cnt);
  1818. break;
  1819. default:
  1820. pr_err("%s: Invalid DMIC Selection\n", __func__);
  1821. return -EINVAL;
  1822. }
  1823. switch (event) {
  1824. case SND_SOC_DAPM_PRE_PMU:
  1825. (*dmic_clk_cnt)++;
  1826. if (*dmic_clk_cnt == 1)
  1827. snd_soc_update_bits(codec, dmic_clk_reg,
  1828. dmic_clk_en, dmic_clk_en);
  1829. break;
  1830. case SND_SOC_DAPM_POST_PMD:
  1831. (*dmic_clk_cnt)--;
  1832. if (*dmic_clk_cnt == 0)
  1833. snd_soc_update_bits(codec, dmic_clk_reg,
  1834. dmic_clk_en, 0);
  1835. break;
  1836. }
  1837. return 0;
  1838. }
  1839. static int tapan_codec_enable_anc(struct snd_soc_dapm_widget *w,
  1840. struct snd_kcontrol *kcontrol, int event)
  1841. {
  1842. struct snd_soc_codec *codec = w->codec;
  1843. const char *filename;
  1844. const struct firmware *fw;
  1845. int i;
  1846. int ret;
  1847. int num_anc_slots;
  1848. struct wcd9xxx_anc_header *anc_head;
  1849. struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
  1850. u32 anc_writes_size = 0;
  1851. int anc_size_remaining;
  1852. u32 *anc_ptr;
  1853. u16 reg;
  1854. u8 mask, val, old_val;
  1855. dev_dbg(codec->dev, "%s %d\n", __func__, event);
  1856. if (tapan->anc_func == 0)
  1857. return 0;
  1858. switch (event) {
  1859. case SND_SOC_DAPM_PRE_PMU:
  1860. filename = "wcd9306/wcd9306_anc.bin";
  1861. ret = request_firmware(&fw, filename, codec->dev);
  1862. if (ret != 0) {
  1863. dev_err(codec->dev, "Failed to acquire ANC data: %d\n",
  1864. ret);
  1865. return -ENODEV;
  1866. }
  1867. if (fw->size < sizeof(struct wcd9xxx_anc_header)) {
  1868. dev_err(codec->dev, "Not enough data\n");
  1869. release_firmware(fw);
  1870. return -ENOMEM;
  1871. }
  1872. /* First number is the number of register writes */
  1873. anc_head = (struct wcd9xxx_anc_header *)(fw->data);
  1874. anc_ptr = (u32 *)((u32)fw->data +
  1875. sizeof(struct wcd9xxx_anc_header));
  1876. anc_size_remaining = fw->size -
  1877. sizeof(struct wcd9xxx_anc_header);
  1878. num_anc_slots = anc_head->num_anc_slots;
  1879. if (tapan->anc_slot >= num_anc_slots) {
  1880. dev_err(codec->dev, "Invalid ANC slot selected\n");
  1881. release_firmware(fw);
  1882. return -EINVAL;
  1883. }
  1884. for (i = 0; i < num_anc_slots; i++) {
  1885. if (anc_size_remaining < TAPAN_PACKED_REG_SIZE) {
  1886. dev_err(codec->dev, "Invalid register format\n");
  1887. release_firmware(fw);
  1888. return -EINVAL;
  1889. }
  1890. anc_writes_size = (u32)(*anc_ptr);
  1891. anc_size_remaining -= sizeof(u32);
  1892. anc_ptr += 1;
  1893. if (anc_writes_size * TAPAN_PACKED_REG_SIZE
  1894. > anc_size_remaining) {
  1895. dev_err(codec->dev, "Invalid register format\n");
  1896. release_firmware(fw);
  1897. return -ENOMEM;
  1898. }
  1899. if (tapan->anc_slot == i)
  1900. break;
  1901. anc_size_remaining -= (anc_writes_size *
  1902. TAPAN_PACKED_REG_SIZE);
  1903. anc_ptr += anc_writes_size;
  1904. }
  1905. if (i == num_anc_slots) {
  1906. dev_err(codec->dev, "Selected ANC slot not present\n");
  1907. release_firmware(fw);
  1908. return -ENOMEM;
  1909. }
  1910. for (i = 0; i < anc_writes_size; i++) {
  1911. TAPAN_CODEC_UNPACK_ENTRY(anc_ptr[i], reg,
  1912. mask, val);
  1913. old_val = snd_soc_read(codec, reg);
  1914. snd_soc_write(codec, reg, (old_val & ~mask) |
  1915. (val & mask));
  1916. }
  1917. release_firmware(fw);
  1918. break;
  1919. case SND_SOC_DAPM_PRE_PMD:
  1920. msleep(40);
  1921. snd_soc_update_bits(codec, TAPAN_A_CDC_ANC1_B1_CTL, 0x01, 0x00);
  1922. snd_soc_update_bits(codec, TAPAN_A_CDC_ANC2_B1_CTL, 0x02, 0x00);
  1923. msleep(20);
  1924. snd_soc_write(codec, TAPAN_A_CDC_CLK_ANC_RESET_CTL, 0x0F);
  1925. snd_soc_write(codec, TAPAN_A_CDC_CLK_ANC_CLK_EN_CTL, 0);
  1926. snd_soc_write(codec, TAPAN_A_CDC_CLK_ANC_RESET_CTL, 0xFF);
  1927. break;
  1928. }
  1929. return 0;
  1930. }
  1931. static int tapan_codec_enable_micbias(struct snd_soc_dapm_widget *w,
  1932. struct snd_kcontrol *kcontrol, int event)
  1933. {
  1934. struct snd_soc_codec *codec = w->codec;
  1935. struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
  1936. u16 micb_int_reg = 0, micb_ctl_reg = 0;
  1937. u8 cfilt_sel_val = 0;
  1938. char *internal1_text = "Internal1";
  1939. char *internal2_text = "Internal2";
  1940. char *internal3_text = "Internal3";
  1941. enum wcd9xxx_notify_event e_post_off, e_pre_on, e_post_on;
  1942. pr_debug("%s: w->name %s event %d\n", __func__, w->name, event);
  1943. if (strnstr(w->name, "MIC BIAS1", sizeof("MIC BIAS1"))) {
  1944. micb_ctl_reg = TAPAN_A_MICB_1_CTL;
  1945. micb_int_reg = TAPAN_A_MICB_1_INT_RBIAS;
  1946. cfilt_sel_val = tapan->resmgr.pdata->micbias.bias1_cfilt_sel;
  1947. e_pre_on = WCD9XXX_EVENT_PRE_MICBIAS_1_ON;
  1948. e_post_on = WCD9XXX_EVENT_POST_MICBIAS_1_ON;
  1949. e_post_off = WCD9XXX_EVENT_POST_MICBIAS_1_OFF;
  1950. } else if (strnstr(w->name, "MIC BIAS2", sizeof("MIC BIAS2"))) {
  1951. micb_ctl_reg = TAPAN_A_MICB_2_CTL;
  1952. micb_int_reg = TAPAN_A_MICB_2_INT_RBIAS;
  1953. cfilt_sel_val = tapan->resmgr.pdata->micbias.bias2_cfilt_sel;
  1954. e_pre_on = WCD9XXX_EVENT_PRE_MICBIAS_2_ON;
  1955. e_post_on = WCD9XXX_EVENT_POST_MICBIAS_2_ON;
  1956. e_post_off = WCD9XXX_EVENT_POST_MICBIAS_2_OFF;
  1957. } else if (strnstr(w->name, "MIC BIAS3", sizeof("MIC BIAS3"))) {
  1958. micb_ctl_reg = TAPAN_A_MICB_3_CTL;
  1959. micb_int_reg = TAPAN_A_MICB_3_INT_RBIAS;
  1960. cfilt_sel_val = tapan->resmgr.pdata->micbias.bias3_cfilt_sel;
  1961. e_pre_on = WCD9XXX_EVENT_PRE_MICBIAS_3_ON;
  1962. e_post_on = WCD9XXX_EVENT_POST_MICBIAS_3_ON;
  1963. e_post_off = WCD9XXX_EVENT_POST_MICBIAS_3_OFF;
  1964. } else {
  1965. pr_err("%s: Error, invalid micbias %s\n", __func__, w->name);
  1966. return -EINVAL;
  1967. }
  1968. switch (event) {
  1969. case SND_SOC_DAPM_PRE_PMU:
  1970. /* Let MBHC module know so micbias switch to be off */
  1971. wcd9xxx_resmgr_notifier_call(&tapan->resmgr, e_pre_on);
  1972. /* Get cfilt */
  1973. wcd9xxx_resmgr_cfilt_get(&tapan->resmgr, cfilt_sel_val);
  1974. if (strnstr(w->name, internal1_text, 30))
  1975. snd_soc_update_bits(codec, micb_int_reg, 0xE0, 0xE0);
  1976. else if (strnstr(w->name, internal2_text, 30))
  1977. snd_soc_update_bits(codec, micb_int_reg, 0x1C, 0x1C);
  1978. else if (strnstr(w->name, internal3_text, 30))
  1979. snd_soc_update_bits(codec, micb_int_reg, 0x3, 0x3);
  1980. if (micb_ctl_reg == TAPAN_A_MICB_2_CTL) {
  1981. if (++tapan->micb_2_users == 1)
  1982. wcd9xxx_resmgr_add_cond_update_bits(
  1983. &tapan->resmgr,
  1984. WCD9XXX_COND_HPH_MIC,
  1985. micb_ctl_reg, w->shift,
  1986. false);
  1987. pr_debug("%s: micb_2_users %d\n", __func__,
  1988. tapan->micb_2_users);
  1989. } else
  1990. snd_soc_update_bits(codec, micb_ctl_reg, 1 << w->shift,
  1991. 1 << w->shift);
  1992. break;
  1993. case SND_SOC_DAPM_POST_PMU:
  1994. usleep_range(20000, 20000);
  1995. /* Let MBHC module know so micbias is on */
  1996. wcd9xxx_resmgr_notifier_call(&tapan->resmgr, e_post_on);
  1997. break;
  1998. case SND_SOC_DAPM_POST_PMD:
  1999. if (micb_ctl_reg == TAPAN_A_MICB_2_CTL) {
  2000. if (--tapan->micb_2_users == 0)
  2001. wcd9xxx_resmgr_rm_cond_update_bits(
  2002. &tapan->resmgr,
  2003. WCD9XXX_COND_HPH_MIC,
  2004. micb_ctl_reg, 7,
  2005. false);
  2006. pr_debug("%s: micb_2_users %d\n", __func__,
  2007. tapan->micb_2_users);
  2008. WARN(tapan->micb_2_users < 0,
  2009. "Unexpected micbias users %d\n",
  2010. tapan->micb_2_users);
  2011. } else
  2012. snd_soc_update_bits(codec, micb_ctl_reg, 1 << w->shift,
  2013. 0);
  2014. /* Let MBHC module know so micbias switch to be off */
  2015. wcd9xxx_resmgr_notifier_call(&tapan->resmgr, e_post_off);
  2016. if (strnstr(w->name, internal1_text, 30))
  2017. snd_soc_update_bits(codec, micb_int_reg, 0x80, 0x00);
  2018. else if (strnstr(w->name, internal2_text, 30))
  2019. snd_soc_update_bits(codec, micb_int_reg, 0x10, 0x00);
  2020. else if (strnstr(w->name, internal3_text, 30))
  2021. snd_soc_update_bits(codec, micb_int_reg, 0x2, 0x0);
  2022. /* Put cfilt */
  2023. wcd9xxx_resmgr_cfilt_put(&tapan->resmgr, cfilt_sel_val);
  2024. break;
  2025. }
  2026. return 0;
  2027. }
  2028. #ifndef CONFIG_ARCH_MSM8226
  2029. /* called under codec_resource_lock acquisition */
  2030. static int tapan_enable_mbhc_micbias(struct snd_soc_codec *codec, bool enable,
  2031. enum wcd9xxx_micbias_num micb_num)
  2032. {
  2033. int rc;
  2034. const char *micbias;
  2035. if (micb_num == MBHC_MICBIAS2)
  2036. micbias = DAPM_MICBIAS2_EXTERNAL_STANDALONE;
  2037. else
  2038. return -EINVAL;
  2039. if (enable)
  2040. rc = snd_soc_dapm_force_enable_pin(&codec->dapm,
  2041. micbias);
  2042. else
  2043. rc = snd_soc_dapm_disable_pin(&codec->dapm,
  2044. micbias);
  2045. if (!rc)
  2046. snd_soc_dapm_sync(&codec->dapm);
  2047. pr_debug("%s: leave ret %d\n", __func__, rc);
  2048. return rc;
  2049. }
  2050. #endif
  2051. static void tx_hpf_corner_freq_callback(struct work_struct *work)
  2052. {
  2053. struct delayed_work *hpf_delayed_work;
  2054. struct hpf_work *hpf_work;
  2055. struct tapan_priv *tapan;
  2056. struct snd_soc_codec *codec;
  2057. u16 tx_mux_ctl_reg;
  2058. u8 hpf_cut_of_freq;
  2059. hpf_delayed_work = to_delayed_work(work);
  2060. hpf_work = container_of(hpf_delayed_work, struct hpf_work, dwork);
  2061. tapan = hpf_work->tapan;
  2062. codec = hpf_work->tapan->codec;
  2063. hpf_cut_of_freq = hpf_work->tx_hpf_cut_of_freq;
  2064. tx_mux_ctl_reg = TAPAN_A_CDC_TX1_MUX_CTL +
  2065. (hpf_work->decimator - 1) * 8;
  2066. dev_dbg(codec->dev, "%s(): decimator %u hpf_cut_of_freq 0x%x\n",
  2067. __func__, hpf_work->decimator, (unsigned int)hpf_cut_of_freq);
  2068. snd_soc_update_bits(codec, TAPAN_A_TX_1_2_TXFE_CLKDIV, 0x55, 0x55);
  2069. snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30, hpf_cut_of_freq << 4);
  2070. }
  2071. #define TX_MUX_CTL_CUT_OFF_FREQ_MASK 0x30
  2072. #define CF_MIN_3DB_4HZ 0x0
  2073. #define CF_MIN_3DB_75HZ 0x1
  2074. #define CF_MIN_3DB_150HZ 0x2
  2075. static int tapan_codec_enable_dec(struct snd_soc_dapm_widget *w,
  2076. struct snd_kcontrol *kcontrol, int event)
  2077. {
  2078. struct snd_soc_codec *codec = w->codec;
  2079. unsigned int decimator;
  2080. char *dec_name = NULL;
  2081. char *widget_name = NULL;
  2082. char *temp;
  2083. int ret = 0;
  2084. u16 dec_reset_reg, tx_vol_ctl_reg, tx_mux_ctl_reg;
  2085. u8 dec_hpf_cut_of_freq;
  2086. int offset;
  2087. char *srch = NULL;
  2088. dev_dbg(codec->dev, "%s %d\n", __func__, event);
  2089. widget_name = kstrndup(w->name, 15, GFP_KERNEL);
  2090. if (!widget_name)
  2091. return -ENOMEM;
  2092. temp = widget_name;
  2093. dec_name = strsep(&widget_name, " ");
  2094. widget_name = temp;
  2095. if (!dec_name) {
  2096. pr_err("%s: Invalid decimator = %s\n", __func__, w->name);
  2097. ret = -EINVAL;
  2098. goto out;
  2099. }
  2100. srch = strpbrk(dec_name, "123456789");
  2101. if (srch == NULL) {
  2102. pr_err("%s: Invalid decimator name %s\n", __func__, dec_name);
  2103. return -EINVAL;
  2104. }
  2105. ret = kstrtouint(srch, 10, &decimator);
  2106. if (ret < 0) {
  2107. pr_err("%s: Invalid decimator = %s\n", __func__, dec_name);
  2108. ret = -EINVAL;
  2109. goto out;
  2110. }
  2111. dev_dbg(codec->dev, "%s(): widget = %s dec_name = %s decimator = %u\n",
  2112. __func__, w->name, dec_name, decimator);
  2113. if (w->reg == TAPAN_A_CDC_CLK_TX_CLK_EN_B1_CTL) {
  2114. dec_reset_reg = TAPAN_A_CDC_CLK_TX_RESET_B1_CTL;
  2115. offset = 0;
  2116. } else if (w->reg == TAPAN_A_CDC_CLK_TX_CLK_EN_B2_CTL) {
  2117. dec_reset_reg = TAPAN_A_CDC_CLK_TX_RESET_B2_CTL;
  2118. offset = 8;
  2119. } else {
  2120. pr_err("%s: Error, incorrect dec\n", __func__);
  2121. ret = -EINVAL;
  2122. goto out;
  2123. }
  2124. tx_vol_ctl_reg = TAPAN_A_CDC_TX1_VOL_CTL_CFG + 8 * (decimator - 1);
  2125. tx_mux_ctl_reg = TAPAN_A_CDC_TX1_MUX_CTL + 8 * (decimator - 1);
  2126. switch (event) {
  2127. case SND_SOC_DAPM_PRE_PMU:
  2128. /* Enableable TX digital mute */
  2129. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x01);
  2130. snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift,
  2131. 1 << w->shift);
  2132. snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift, 0x0);
  2133. dec_hpf_cut_of_freq = snd_soc_read(codec, tx_mux_ctl_reg);
  2134. dec_hpf_cut_of_freq = (dec_hpf_cut_of_freq & 0x30) >> 4;
  2135. tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq =
  2136. dec_hpf_cut_of_freq;
  2137. if ((dec_hpf_cut_of_freq != CF_MIN_3DB_150HZ)) {
  2138. /* set cut of freq to CF_MIN_3DB_150HZ (0x1); */
  2139. snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30,
  2140. CF_MIN_3DB_150HZ << 4);
  2141. }
  2142. /* enable HPF */
  2143. snd_soc_update_bits(codec, tx_mux_ctl_reg , 0x08, 0x00);
  2144. snd_soc_update_bits(codec, TAPAN_A_TX_1_2_TXFE_CLKDIV,
  2145. 0x55, 0x44);
  2146. break;
  2147. case SND_SOC_DAPM_POST_PMU:
  2148. /* Disable TX digital mute */
  2149. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x00);
  2150. if (tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq !=
  2151. CF_MIN_3DB_150HZ) {
  2152. schedule_delayed_work(&tx_hpf_work[decimator - 1].dwork,
  2153. msecs_to_jiffies(300));
  2154. }
  2155. /* apply the digital gain after the decimator is enabled*/
  2156. if ((w->shift + offset) < ARRAY_SIZE(tx_digital_gain_reg))
  2157. snd_soc_write(codec,
  2158. tx_digital_gain_reg[w->shift + offset],
  2159. snd_soc_read(codec,
  2160. tx_digital_gain_reg[w->shift + offset])
  2161. );
  2162. break;
  2163. case SND_SOC_DAPM_PRE_PMD:
  2164. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x01);
  2165. cancel_delayed_work_sync(&tx_hpf_work[decimator - 1].dwork);
  2166. break;
  2167. case SND_SOC_DAPM_POST_PMD:
  2168. snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x08, 0x08);
  2169. snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30,
  2170. (tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq) << 4);
  2171. break;
  2172. }
  2173. out:
  2174. kfree(widget_name);
  2175. return ret;
  2176. }
  2177. static int tapan_codec_enable_vdd_spkr(struct snd_soc_dapm_widget *w,
  2178. struct snd_kcontrol *kcontrol, int event)
  2179. {
  2180. struct snd_soc_codec *codec = w->codec;
  2181. struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent);
  2182. dev_dbg(codec->dev, "%s: %s %d\n", __func__, w->name, event);
  2183. switch (event) {
  2184. case SND_SOC_DAPM_PRE_PMU:
  2185. if (spkr_drv_wrnd > 0) {
  2186. WARN_ON(!(snd_soc_read(codec, TAPAN_A_SPKR_DRV_EN) &
  2187. 0x80));
  2188. snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_EN, 0x80,
  2189. 0x00);
  2190. }
  2191. if (TAPAN_IS_1_0(core->version))
  2192. snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_DBG_PWRSTG,
  2193. 0x24, 0x00);
  2194. break;
  2195. case SND_SOC_DAPM_POST_PMD:
  2196. if (TAPAN_IS_1_0(core->version))
  2197. snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_DBG_PWRSTG,
  2198. 0x24, 0x24);
  2199. if (spkr_drv_wrnd > 0) {
  2200. WARN_ON(!!(snd_soc_read(codec, TAPAN_A_SPKR_DRV_EN) &
  2201. 0x80));
  2202. snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_EN, 0x80,
  2203. 0x80);
  2204. }
  2205. break;
  2206. }
  2207. return 0;
  2208. }
  2209. static int tapan_codec_rx_dem_select(struct snd_soc_dapm_widget *w,
  2210. struct snd_kcontrol *kcontrol, int event)
  2211. {
  2212. struct snd_soc_codec *codec = w->codec;
  2213. pr_debug("%s %d %s\n", __func__, event, w->name);
  2214. switch (event) {
  2215. case SND_SOC_DAPM_PRE_PMU:
  2216. if (codec_ver == WCD9306)
  2217. snd_soc_update_bits(codec, TAPAN_A_CDC_RX2_B6_CTL,
  2218. 1 << 5, 1 << 5);
  2219. break;
  2220. case SND_SOC_DAPM_POST_PMD:
  2221. if (codec_ver == WCD9306)
  2222. snd_soc_update_bits(codec, TAPAN_A_CDC_RX2_B6_CTL,
  2223. 1 << 5, 0);
  2224. break;
  2225. }
  2226. return 0;
  2227. }
  2228. static int tapan_codec_enable_interpolator(struct snd_soc_dapm_widget *w,
  2229. struct snd_kcontrol *kcontrol, int event)
  2230. {
  2231. struct snd_soc_codec *codec = w->codec;
  2232. dev_dbg(codec->dev, "%s %d %s\n", __func__, event, w->name);
  2233. switch (event) {
  2234. case SND_SOC_DAPM_PRE_PMU:
  2235. snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RX_RESET_CTL,
  2236. 1 << w->shift, 1 << w->shift);
  2237. snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RX_RESET_CTL,
  2238. 1 << w->shift, 0x0);
  2239. break;
  2240. case SND_SOC_DAPM_POST_PMU:
  2241. /* apply the digital gain after the interpolator is enabled*/
  2242. if ((w->shift) < ARRAY_SIZE(rx_digital_gain_reg))
  2243. snd_soc_write(codec,
  2244. rx_digital_gain_reg[w->shift],
  2245. snd_soc_read(codec,
  2246. rx_digital_gain_reg[w->shift])
  2247. );
  2248. break;
  2249. }
  2250. return 0;
  2251. }
  2252. #ifndef CONFIG_ARCH_MSM8226
  2253. /* called under codec_resource_lock acquisition */
  2254. static int __tapan_codec_enable_ldo_h(struct snd_soc_dapm_widget *w,
  2255. struct snd_kcontrol *kcontrol, int event)
  2256. {
  2257. struct snd_soc_codec *codec = w->codec;
  2258. struct tapan_priv *priv = snd_soc_codec_get_drvdata(codec);
  2259. pr_debug("%s: enter\n", __func__);
  2260. switch (event) {
  2261. case SND_SOC_DAPM_PRE_PMU:
  2262. /*
  2263. * ldo_h_users is protected by codec->mutex, don't need
  2264. * additional mutex
  2265. */
  2266. if (++priv->ldo_h_users == 1) {
  2267. WCD9XXX_BG_CLK_LOCK(&priv->resmgr);
  2268. wcd9xxx_resmgr_get_bandgap(&priv->resmgr,
  2269. WCD9XXX_BANDGAP_AUDIO_MODE);
  2270. wcd9xxx_resmgr_get_clk_block(&priv->resmgr,
  2271. WCD9XXX_CLK_RCO);
  2272. snd_soc_update_bits(codec, TAPAN_A_LDO_H_MODE_1, 1 << 7,
  2273. 1 << 7);
  2274. wcd9xxx_resmgr_put_clk_block(&priv->resmgr,
  2275. WCD9XXX_CLK_RCO);
  2276. WCD9XXX_BG_CLK_UNLOCK(&priv->resmgr);
  2277. pr_debug("%s: ldo_h_users %d\n", __func__,
  2278. priv->ldo_h_users);
  2279. /* LDO enable requires 1ms to settle down */
  2280. usleep_range(1000, 1010);
  2281. }
  2282. break;
  2283. case SND_SOC_DAPM_POST_PMD:
  2284. if (--priv->ldo_h_users == 0) {
  2285. WCD9XXX_BG_CLK_LOCK(&priv->resmgr);
  2286. wcd9xxx_resmgr_get_clk_block(&priv->resmgr,
  2287. WCD9XXX_CLK_RCO);
  2288. snd_soc_update_bits(codec, TAPAN_A_LDO_H_MODE_1, 1 << 7,
  2289. 0);
  2290. wcd9xxx_resmgr_put_clk_block(&priv->resmgr,
  2291. WCD9XXX_CLK_RCO);
  2292. wcd9xxx_resmgr_put_bandgap(&priv->resmgr,
  2293. WCD9XXX_BANDGAP_AUDIO_MODE);
  2294. WCD9XXX_BG_CLK_UNLOCK(&priv->resmgr);
  2295. pr_debug("%s: ldo_h_users %d\n", __func__,
  2296. priv->ldo_h_users);
  2297. }
  2298. WARN(priv->ldo_h_users < 0, "Unexpected ldo_h users %d\n",
  2299. priv->ldo_h_users);
  2300. break;
  2301. }
  2302. pr_debug("%s: leave\n", __func__);
  2303. return 0;
  2304. }
  2305. #endif
  2306. void tapan_register_mclk_cb(struct snd_soc_codec *codec,
  2307. int (*mclk_cb_fn) (struct snd_soc_codec*, int, bool))
  2308. {
  2309. struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
  2310. tapan->mclk_cb_fn = mclk_cb_fn;
  2311. }
  2312. static void tapan_enable_ldo_h(struct snd_soc_codec *codec, u32 enable)
  2313. {
  2314. struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
  2315. if (enable) {
  2316. if (++tapan->ldo_h_count == 1)
  2317. snd_soc_update_bits(codec, TAPAN_A_LDO_H_MODE_1,
  2318. 0x80, 0x80);
  2319. } else {
  2320. if (--tapan->ldo_h_count <= 0) {
  2321. snd_soc_update_bits(codec, TAPAN_A_LDO_H_MODE_1,
  2322. 0x80, 0x00);
  2323. tapan->ldo_h_count = 0;
  2324. }
  2325. }
  2326. }
  2327. static int tapan_codec_enable_micbias_power(struct snd_soc_dapm_widget *w,
  2328. struct snd_kcontrol *kcontrol,
  2329. int event)
  2330. {
  2331. struct snd_soc_codec *codec = w->codec;
  2332. struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
  2333. pr_debug("%s %d\n", __func__, event);
  2334. if (!tapan->mclk_cb_fn) {
  2335. pr_err("%s: Callback to enable mclk is not registered\n",
  2336. __func__);
  2337. return -EINVAL;
  2338. }
  2339. switch (event) {
  2340. case SND_SOC_DAPM_PRE_PMU:
  2341. tapan->mclk_cb_fn(codec, 1, true);
  2342. WCD9XXX_BCL_LOCK(&tapan->resmgr);
  2343. WCD9XXX_BG_CLK_LOCK(&tapan->resmgr);
  2344. wcd9xxx_resmgr_get_bandgap(&tapan->resmgr,
  2345. WCD9XXX_BANDGAP_AUDIO_MODE);
  2346. WCD9XXX_BG_CLK_UNLOCK(&tapan->resmgr);
  2347. WCD9XXX_BCL_UNLOCK(&tapan->resmgr);
  2348. tapan_enable_ldo_h(codec, 1);
  2349. tapan_codec_enable_micbias(w, kcontrol, event);
  2350. break;
  2351. case SND_SOC_DAPM_POST_PMU:
  2352. tapan_codec_enable_micbias(w, kcontrol, event);
  2353. tapan->mclk_cb_fn(codec, 0, true);
  2354. break;
  2355. case SND_SOC_DAPM_POST_PMD:
  2356. tapan_codec_enable_micbias(w, kcontrol, event);
  2357. tapan_enable_ldo_h(codec, 0);
  2358. WCD9XXX_BCL_LOCK(&tapan->resmgr);
  2359. WCD9XXX_BG_CLK_LOCK(&tapan->resmgr);
  2360. wcd9xxx_resmgr_put_bandgap(&tapan->resmgr,
  2361. WCD9XXX_BANDGAP_AUDIO_MODE);
  2362. WCD9XXX_BG_CLK_UNLOCK(&tapan->resmgr);
  2363. WCD9XXX_BCL_UNLOCK(&tapan->resmgr);
  2364. break;
  2365. }
  2366. return 0;
  2367. }
  2368. static int tapan_codec_enable_ldo_h(struct snd_soc_dapm_widget *w,
  2369. struct snd_kcontrol *kcontrol, int event)
  2370. {
  2371. #ifndef CONFIG_ARCH_MSM8226
  2372. int rc;
  2373. rc = __tapan_codec_enable_ldo_h(w, kcontrol, event);
  2374. return rc;
  2375. #else
  2376. struct snd_soc_codec *codec = w->codec;
  2377. switch (event) {
  2378. case SND_SOC_DAPM_POST_PMU:
  2379. tapan_enable_ldo_h(codec, 1);
  2380. usleep_range(1000, 1000);
  2381. break;
  2382. case SND_SOC_DAPM_POST_PMD:
  2383. tapan_enable_ldo_h(codec, 0);
  2384. usleep_range(1000, 1000);
  2385. break;
  2386. }
  2387. return 0;
  2388. #endif
  2389. }
  2390. static int tapan_codec_enable_rx_bias(struct snd_soc_dapm_widget *w,
  2391. struct snd_kcontrol *kcontrol, int event)
  2392. {
  2393. struct snd_soc_codec *codec = w->codec;
  2394. struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
  2395. dev_dbg(codec->dev, "%s %d\n", __func__, event);
  2396. switch (event) {
  2397. case SND_SOC_DAPM_PRE_PMU:
  2398. wcd9xxx_resmgr_enable_rx_bias(&tapan->resmgr, 1);
  2399. break;
  2400. case SND_SOC_DAPM_POST_PMD:
  2401. wcd9xxx_resmgr_enable_rx_bias(&tapan->resmgr, 0);
  2402. break;
  2403. }
  2404. return 0;
  2405. }
  2406. static int tapan_hphl_dac_event(struct snd_soc_dapm_widget *w,
  2407. struct snd_kcontrol *kcontrol, int event)
  2408. {
  2409. struct snd_soc_codec *codec = w->codec;
  2410. struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec);
  2411. dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
  2412. switch (event) {
  2413. case SND_SOC_DAPM_PRE_PMU:
  2414. snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RDAC_CLK_EN_CTL,
  2415. 0x02, 0x02);
  2416. wcd9xxx_clsh_fsm(codec, &tapan_p->clsh_d,
  2417. WCD9XXX_CLSH_STATE_HPHL,
  2418. WCD9XXX_CLSH_REQ_ENABLE,
  2419. WCD9XXX_CLSH_EVENT_PRE_DAC);
  2420. break;
  2421. case SND_SOC_DAPM_POST_PMD:
  2422. snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RDAC_CLK_EN_CTL,
  2423. 0x02, 0x00);
  2424. }
  2425. return 0;
  2426. }
  2427. static int tapan_hphr_dac_event(struct snd_soc_dapm_widget *w,
  2428. struct snd_kcontrol *kcontrol, int event)
  2429. {
  2430. struct snd_soc_codec *codec = w->codec;
  2431. struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec);
  2432. dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
  2433. switch (event) {
  2434. case SND_SOC_DAPM_PRE_PMU:
  2435. snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RDAC_CLK_EN_CTL,
  2436. 0x04, 0x04);
  2437. snd_soc_update_bits(codec, w->reg, 0x40, 0x40);
  2438. wcd9xxx_clsh_fsm(codec, &tapan_p->clsh_d,
  2439. WCD9XXX_CLSH_STATE_HPHR,
  2440. WCD9XXX_CLSH_REQ_ENABLE,
  2441. WCD9XXX_CLSH_EVENT_PRE_DAC);
  2442. break;
  2443. case SND_SOC_DAPM_POST_PMD:
  2444. snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RDAC_CLK_EN_CTL,
  2445. 0x04, 0x00);
  2446. snd_soc_update_bits(codec, w->reg, 0x40, 0x00);
  2447. break;
  2448. }
  2449. return 0;
  2450. }
  2451. static int tapan_hph_pa_event(struct snd_soc_dapm_widget *w,
  2452. struct snd_kcontrol *kcontrol, int event)
  2453. {
  2454. struct snd_soc_codec *codec = w->codec;
  2455. struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
  2456. enum wcd9xxx_notify_event e_pre_on, e_post_off;
  2457. u8 req_clsh_state;
  2458. u32 pa_settle_time = TAPAN_HPH_PA_SETTLE_COMP_OFF;
  2459. dev_dbg(codec->dev, "%s: %s event = %d\n", __func__, w->name, event);
  2460. if (w->shift == 5) {
  2461. e_pre_on = WCD9XXX_EVENT_PRE_HPHL_PA_ON;
  2462. e_post_off = WCD9XXX_EVENT_POST_HPHL_PA_OFF;
  2463. req_clsh_state = WCD9XXX_CLSH_STATE_HPHR;
  2464. } else if (w->shift == 4) {
  2465. e_pre_on = WCD9XXX_EVENT_PRE_HPHR_PA_ON;
  2466. e_post_off = WCD9XXX_EVENT_POST_HPHR_PA_OFF;
  2467. req_clsh_state = WCD9XXX_CLSH_STATE_HPHL;
  2468. } else {
  2469. pr_err("%s: Invalid w->shift %d\n", __func__, w->shift);
  2470. return -EINVAL;
  2471. }
  2472. if (tapan->comp_enabled[COMPANDER_1])
  2473. pa_settle_time = TAPAN_HPH_PA_SETTLE_COMP_ON;
  2474. switch (event) {
  2475. case SND_SOC_DAPM_PRE_PMU:
  2476. /* Let MBHC module know PA is turning on */
  2477. wcd9xxx_resmgr_notifier_call(&tapan->resmgr, e_pre_on);
  2478. #if defined(CONFIG_MACH_ATLANTICLTE_ATT) || defined(CONFIG_MACH_ATLANTICLTE_USC)
  2479. snd_soc_write(codec,TAPAN_A_CDC_CLSH_V_PA_HD_HPH,0x19);
  2480. snd_soc_write(codec,TAPAN_A_CDC_CLSH_V_PA_MIN_HPH, 0x26);
  2481. #endif
  2482. break;
  2483. case SND_SOC_DAPM_POST_PMU:
  2484. dev_dbg(codec->dev, "%s: sleep %d ms after %s PA enable.\n",
  2485. __func__, pa_settle_time / 1000, w->name);
  2486. /* Time needed for PA to settle */
  2487. usleep_range(pa_settle_time, pa_settle_time + 1000);
  2488. wcd9xxx_clsh_fsm(codec, &tapan->clsh_d,
  2489. req_clsh_state,
  2490. WCD9XXX_CLSH_REQ_ENABLE,
  2491. WCD9XXX_CLSH_EVENT_POST_PA);
  2492. break;
  2493. case SND_SOC_DAPM_POST_PMD:
  2494. dev_dbg(codec->dev, "%s: sleep %d ms after %s PA disable.\n",
  2495. __func__, pa_settle_time / 1000, w->name);
  2496. /* Time needed for PA to settle */
  2497. usleep_range(pa_settle_time, pa_settle_time + 1000);
  2498. /* Let MBHC module know PA turned off */
  2499. wcd9xxx_resmgr_notifier_call(&tapan->resmgr, e_post_off);
  2500. wcd9xxx_clsh_fsm(codec, &tapan->clsh_d,
  2501. req_clsh_state,
  2502. WCD9XXX_CLSH_REQ_DISABLE,
  2503. WCD9XXX_CLSH_EVENT_POST_PA);
  2504. #if defined(CONFIG_MACH_ATLANTICLTE_ATT) || defined(CONFIG_MACH_ATLANTICLTE_USC)
  2505. snd_soc_write(codec,TAPAN_A_CDC_CLSH_V_PA_HD_HPH,0x00);
  2506. snd_soc_write(codec,TAPAN_A_CDC_CLSH_V_PA_MIN_HPH, 0x00);
  2507. #endif
  2508. break;
  2509. }
  2510. return 0;
  2511. }
  2512. static int tapan_codec_enable_anc_hph(struct snd_soc_dapm_widget *w,
  2513. struct snd_kcontrol *kcontrol, int event)
  2514. {
  2515. struct snd_soc_codec *codec = w->codec;
  2516. int ret = 0;
  2517. switch (event) {
  2518. case SND_SOC_DAPM_PRE_PMU:
  2519. ret = tapan_hph_pa_event(w, kcontrol, event);
  2520. if (w->shift == 4) {
  2521. ret |= tapan_codec_enable_anc(w, kcontrol, event);
  2522. msleep(50);
  2523. }
  2524. break;
  2525. case SND_SOC_DAPM_POST_PMU:
  2526. if (w->shift == 4) {
  2527. snd_soc_update_bits(codec,
  2528. TAPAN_A_RX_HPH_CNP_EN, 0x30, 0x30);
  2529. msleep(30);
  2530. }
  2531. ret = tapan_hph_pa_event(w, kcontrol, event);
  2532. break;
  2533. case SND_SOC_DAPM_PRE_PMD:
  2534. if (w->shift == 5) {
  2535. snd_soc_update_bits(codec,
  2536. TAPAN_A_RX_HPH_CNP_EN, 0x30, 0x00);
  2537. msleep(40);
  2538. snd_soc_update_bits(codec,
  2539. TAPAN_A_TX_7_MBHC_EN, 0x80, 00);
  2540. ret |= tapan_codec_enable_anc(w, kcontrol, event);
  2541. }
  2542. break;
  2543. case SND_SOC_DAPM_POST_PMD:
  2544. ret = tapan_hph_pa_event(w, kcontrol, event);
  2545. break;
  2546. }
  2547. return ret;
  2548. }
  2549. static const struct snd_soc_dapm_widget tapan_dapm_i2s_widgets[] = {
  2550. SND_SOC_DAPM_SUPPLY("I2S_CLK", TAPAN_A_CDC_CLK_I2S_CTL,
  2551. 4, 0, NULL, 0),
  2552. };
  2553. static int tapan_lineout_dac_event(struct snd_soc_dapm_widget *w,
  2554. struct snd_kcontrol *kcontrol, int event)
  2555. {
  2556. struct snd_soc_codec *codec = w->codec;
  2557. struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
  2558. dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
  2559. switch (event) {
  2560. case SND_SOC_DAPM_PRE_PMU:
  2561. wcd9xxx_clsh_fsm(codec, &tapan->clsh_d,
  2562. WCD9XXX_CLSH_STATE_LO,
  2563. WCD9XXX_CLSH_REQ_ENABLE,
  2564. WCD9XXX_CLSH_EVENT_PRE_DAC);
  2565. snd_soc_update_bits(codec, w->reg, 0x40, 0x40);
  2566. break;
  2567. case SND_SOC_DAPM_POST_PMD:
  2568. snd_soc_update_bits(codec, w->reg, 0x40, 0x00);
  2569. break;
  2570. }
  2571. return 0;
  2572. }
  2573. static int tapan_spk_dac_event(struct snd_soc_dapm_widget *w,
  2574. struct snd_kcontrol *kcontrol, int event)
  2575. {
  2576. struct snd_soc_codec *codec = w->codec;
  2577. dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
  2578. return 0;
  2579. }
  2580. static const struct snd_soc_dapm_route audio_i2s_map[] = {
  2581. {"I2S_CLK", NULL, "CDC_CONN"},
  2582. {"SLIM RX1", NULL, "I2S_CLK"},
  2583. {"SLIM RX2", NULL, "I2S_CLK"},
  2584. {"SLIM TX1 MUX", NULL, "I2S_CLK"},
  2585. {"SLIM TX2 MUX", NULL, "I2S_CLK"},
  2586. };
  2587. static const struct snd_soc_dapm_route wcd9306_map[] = {
  2588. {"SLIM TX1 MUX", "RMIX4", "RX4 MIX1"},
  2589. {"SLIM TX2 MUX", "RMIX4", "RX4 MIX1"},
  2590. {"SLIM TX3 MUX", "RMIX4", "RX4 MIX1"},
  2591. {"SLIM TX4 MUX", "RMIX4", "RX4 MIX1"},
  2592. {"SLIM TX5 MUX", "RMIX4", "RX4 MIX1"},
  2593. {"SLIM TX1 MUX", "DEC3", "DEC3 MUX"},
  2594. {"SLIM TX1 MUX", "DEC4", "DEC4 MUX"},
  2595. {"SLIM TX2 MUX", "DEC3", "DEC3 MUX"},
  2596. {"SLIM TX2 MUX", "DEC4", "DEC4 MUX"},
  2597. {"SLIM TX3 MUX", "DEC3", "DEC3 MUX"},
  2598. {"SLIM TX4 MUX", "DEC4", "DEC4 MUX"},
  2599. {"ANC EAR", NULL, "ANC EAR PA"},
  2600. {"ANC EAR PA", NULL, "EAR_PA_MIXER"},
  2601. {"ANC1 FB MUX", "EAR_HPH_L", "RX1 MIX2"},
  2602. {"ANC1 FB MUX", "EAR_LINE_1", "RX2 MIX2"},
  2603. {"ANC HEADPHONE", NULL, "ANC HPHL"},
  2604. {"ANC HEADPHONE", NULL, "ANC HPHR"},
  2605. {"ANC HPHL", NULL, "HPHL_PA_MIXER"},
  2606. {"ANC HPHR", NULL, "HPHR_PA_MIXER"},
  2607. {"ANC1 MUX", "ADC1", "ADC1"},
  2608. {"ANC1 MUX", "ADC2", "ADC2"},
  2609. {"ANC1 MUX", "ADC3", "ADC3"},
  2610. {"ANC1 MUX", "ADC4", "ADC4"},
  2611. {"ANC1 MUX", "ADC5", "ADC5"},
  2612. {"ANC1 MUX", "DMIC1", "DMIC1"},
  2613. {"ANC1 MUX", "DMIC2", "DMIC2"},
  2614. {"ANC1 MUX", "DMIC3", "DMIC3"},
  2615. {"ANC1 MUX", "DMIC4", "DMIC4"},
  2616. {"ANC2 MUX", "ADC1", "ADC1"},
  2617. {"ANC2 MUX", "ADC2", "ADC2"},
  2618. {"ANC2 MUX", "ADC3", "ADC3"},
  2619. {"ANC2 MUX", "ADC4", "ADC4"},
  2620. {"ANC2 MUX", "ADC5", "ADC5"},
  2621. {"ANC2 MUX", "DMIC1", "DMIC1"},
  2622. {"ANC2 MUX", "DMIC2", "DMIC2"},
  2623. {"ANC2 MUX", "DMIC3", "DMIC3"},
  2624. {"ANC2 MUX", "DMIC4", "DMIC4"},
  2625. {"ANC HPHR", NULL, "CDC_CONN"},
  2626. {"RDAC5 MUX", "DEM4", "RX4 MIX2"},
  2627. {"SPK DAC", "Switch", "RX4 MIX2"},
  2628. {"RX1 MIX2", NULL, "ANC1 MUX"},
  2629. {"RX2 MIX2", NULL, "ANC2 MUX"},
  2630. {"RX1 MIX1", NULL, "COMP1_CLK"},
  2631. {"RX2 MIX1", NULL, "COMP1_CLK"},
  2632. {"RX3 MIX1", NULL, "COMP2_CLK"},
  2633. {"RX4 MIX1", NULL, "COMP0_CLK"},
  2634. {"RX4 MIX1", NULL, "RX4 MIX1 INP1"},
  2635. {"RX4 MIX1", NULL, "RX4 MIX1 INP2"},
  2636. {"RX4 MIX2", NULL, "RX4 MIX1"},
  2637. {"RX4 MIX2", NULL, "RX4 MIX2 INP1"},
  2638. {"RX4 MIX2", NULL, "RX4 MIX2 INP2"},
  2639. {"RX4 MIX1 INP1", "RX1", "SLIM RX1"},
  2640. {"RX4 MIX1 INP1", "RX2", "SLIM RX2"},
  2641. {"RX4 MIX1 INP1", "RX3", "SLIM RX3"},
  2642. {"RX4 MIX1 INP1", "RX4", "SLIM RX4"},
  2643. {"RX4 MIX1 INP1", "RX5", "SLIM RX5"},
  2644. {"RX4 MIX1 INP1", "IIR1", "IIR1"},
  2645. {"RX4 MIX1 INP2", "RX1", "SLIM RX1"},
  2646. {"RX4 MIX1 INP2", "RX2", "SLIM RX2"},
  2647. {"RX4 MIX1 INP2", "RX3", "SLIM RX3"},
  2648. {"RX4 MIX1 INP2", "RX5", "SLIM RX5"},
  2649. {"RX4 MIX1 INP2", "RX4", "SLIM RX4"},
  2650. {"RX4 MIX1 INP2", "IIR1", "IIR1"},
  2651. {"RX4 MIX2 INP1", "IIR1", "IIR1"},
  2652. {"RX4 MIX2 INP2", "IIR1", "IIR1"},
  2653. {"DEC1 MUX", "DMIC3", "DMIC3"},
  2654. {"DEC1 MUX", "DMIC4", "DMIC4"},
  2655. {"DEC2 MUX", "DMIC3", "DMIC3"},
  2656. {"DEC2 MUX", "DMIC4", "DMIC4"},
  2657. {"DEC3 MUX", "ADC1", "ADC1"},
  2658. {"DEC3 MUX", "ADC2", "ADC2"},
  2659. {"DEC3 MUX", "ADC3", "ADC3"},
  2660. {"DEC3 MUX", "ADC4", "ADC4"},
  2661. {"DEC3 MUX", "ADC5", "ADC5"},
  2662. {"DEC3 MUX", "DMIC1", "DMIC1"},
  2663. {"DEC3 MUX", "DMIC2", "DMIC2"},
  2664. {"DEC3 MUX", "DMIC3", "DMIC3"},
  2665. {"DEC3 MUX", "DMIC4", "DMIC4"},
  2666. {"DEC3 MUX", NULL, "CDC_CONN"},
  2667. {"DEC4 MUX", "ADC1", "ADC1"},
  2668. {"DEC4 MUX", "ADC2", "ADC2"},
  2669. {"DEC4 MUX", "ADC3", "ADC3"},
  2670. {"DEC4 MUX", "ADC4", "ADC4"},
  2671. {"DEC4 MUX", "ADC5", "ADC5"},
  2672. {"DEC4 MUX", "DMIC1", "DMIC1"},
  2673. {"DEC4 MUX", "DMIC2", "DMIC2"},
  2674. {"DEC4 MUX", "DMIC3", "DMIC3"},
  2675. {"DEC4 MUX", "DMIC4", "DMIC4"},
  2676. {"DEC4 MUX", NULL, "CDC_CONN"},
  2677. {"ADC5", NULL, "AMIC5"},
  2678. {"AUX_PGA_Left", NULL, "AMIC5"},
  2679. {"IIR1 INP1 MUX", "DEC3", "DEC3 MUX"},
  2680. {"IIR1 INP1 MUX", "DEC4", "DEC4 MUX"},
  2681. {"MIC BIAS3 Internal1", NULL, "LDO_H"},
  2682. {"MIC BIAS3 Internal2", NULL, "LDO_H"},
  2683. {"MIC BIAS3 External", NULL, "LDO_H"},
  2684. };
  2685. static const struct snd_soc_dapm_route audio_map[] = {
  2686. /* SLIMBUS Connections */
  2687. {"AIF1 CAP", NULL, "AIF1_CAP Mixer"},
  2688. {"AIF2 CAP", NULL, "AIF2_CAP Mixer"},
  2689. {"AIF3 CAP", NULL, "AIF3_CAP Mixer"},
  2690. /* SLIM_MIXER("AIF1_CAP Mixer"),*/
  2691. {"AIF1_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"},
  2692. {"AIF1_CAP Mixer", "SLIM TX2", "SLIM TX2 MUX"},
  2693. {"AIF1_CAP Mixer", "SLIM TX3", "SLIM TX3 MUX"},
  2694. {"AIF1_CAP Mixer", "SLIM TX4", "SLIM TX4 MUX"},
  2695. {"AIF1_CAP Mixer", "SLIM TX5", "SLIM TX5 MUX"},
  2696. /* SLIM_MIXER("AIF2_CAP Mixer"),*/
  2697. {"AIF2_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"},
  2698. {"AIF2_CAP Mixer", "SLIM TX2", "SLIM TX2 MUX"},
  2699. {"AIF2_CAP Mixer", "SLIM TX3", "SLIM TX3 MUX"},
  2700. {"AIF2_CAP Mixer", "SLIM TX4", "SLIM TX4 MUX"},
  2701. {"AIF2_CAP Mixer", "SLIM TX5", "SLIM TX5 MUX"},
  2702. /* SLIM_MIXER("AIF3_CAP Mixer"),*/
  2703. {"AIF3_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"},
  2704. {"AIF3_CAP Mixer", "SLIM TX2", "SLIM TX2 MUX"},
  2705. {"AIF3_CAP Mixer", "SLIM TX3", "SLIM TX3 MUX"},
  2706. {"AIF3_CAP Mixer", "SLIM TX4", "SLIM TX4 MUX"},
  2707. {"AIF3_CAP Mixer", "SLIM TX5", "SLIM TX5 MUX"},
  2708. {"SLIM TX1 MUX", "DEC1", "DEC1 MUX"},
  2709. {"SLIM TX1 MUX", "DEC2", "DEC2 MUX"},
  2710. {"SLIM TX1 MUX", "RMIX1", "RX1 MIX1"},
  2711. {"SLIM TX1 MUX", "RMIX2", "RX2 MIX1"},
  2712. {"SLIM TX1 MUX", "RMIX3", "RX3 MIX1"},
  2713. {"SLIM TX2 MUX", "DEC1", "DEC1 MUX"},
  2714. {"SLIM TX2 MUX", "DEC2", "DEC2 MUX"},
  2715. {"SLIM TX2 MUX", "RMIX1", "RX1 MIX1"},
  2716. {"SLIM TX2 MUX", "RMIX2", "RX2 MIX1"},
  2717. {"SLIM TX2 MUX", "RMIX3", "RX3 MIX1"},
  2718. {"SLIM TX3 MUX", "RMIX1", "RX1 MIX1"},
  2719. {"SLIM TX3 MUX", "RMIX2", "RX2 MIX1"},
  2720. {"SLIM TX3 MUX", "RMIX3", "RX3 MIX1"},
  2721. {"SLIM TX4 MUX", "RMIX1", "RX1 MIX1"},
  2722. {"SLIM TX4 MUX", "RMIX2", "RX2 MIX1"},
  2723. {"SLIM TX4 MUX", "RMIX3", "RX3 MIX1"},
  2724. {"SLIM TX5 MUX", "DEC1", "DEC1 MUX"},
  2725. {"SLIM TX5 MUX", "RMIX1", "RX1 MIX1"},
  2726. {"SLIM TX5 MUX", "RMIX2", "RX2 MIX1"},
  2727. {"SLIM TX5 MUX", "RMIX3", "RX3 MIX1"},
  2728. /* Earpiece (RX MIX1) */
  2729. {"EAR", NULL, "EAR PA"},
  2730. {"EAR PA", NULL, "EAR_PA_MIXER"},
  2731. {"EAR_PA_MIXER", NULL, "DAC1"},
  2732. {"DAC1", NULL, "RX_BIAS"},
  2733. {"DAC1", NULL, "CDC_CP_VDD"},
  2734. /* Headset (RX MIX1 and RX MIX2) */
  2735. {"HEADPHONE", NULL, "HPHL"},
  2736. {"HEADPHONE", NULL, "HPHR"},
  2737. {"HPHL", NULL, "HPHL_PA_MIXER"},
  2738. {"HPHL_PA_MIXER", NULL, "HPHL DAC"},
  2739. {"HPHL DAC", NULL, "RX_BIAS"},
  2740. {"HPHL DAC", NULL, "CDC_CP_VDD"},
  2741. {"HPHR", NULL, "HPHR_PA_MIXER"},
  2742. {"HPHR_PA_MIXER", NULL, "HPHR DAC"},
  2743. {"HPHR DAC", NULL, "RX_BIAS"},
  2744. {"HPHR DAC", NULL, "CDC_CP_VDD"},
  2745. {"DAC1", "Switch", "CLASS_H_DSM MUX"},
  2746. {"HPHL DAC", "Switch", "CLASS_H_DSM MUX"},
  2747. {"HPHR DAC", NULL, "RDAC3 MUX"},
  2748. {"LINEOUT1", NULL, "LINEOUT1 PA"},
  2749. {"LINEOUT2", NULL, "LINEOUT2 PA"},
  2750. {"SPK_OUT", NULL, "SPK PA"},
  2751. {"LINEOUT1 PA", NULL, "LINEOUT1_PA_MIXER"},
  2752. {"LINEOUT1_PA_MIXER", NULL, "LINEOUT1 DAC"},
  2753. {"LINEOUT2 PA", NULL, "LINEOUT2_PA_MIXER"},
  2754. {"LINEOUT2_PA_MIXER", NULL, "LINEOUT2 DAC"},
  2755. {"RDAC5 MUX", "DEM3_INV", "RX3 MIX1"},
  2756. {"LINEOUT2 DAC", NULL, "RDAC5 MUX"},
  2757. {"RDAC4 MUX", "DEM3", "RX3 MIX1"},
  2758. {"RDAC4 MUX", "DEM2", "RX2 CHAIN"},
  2759. {"LINEOUT1 DAC", NULL, "RDAC4 MUX"},
  2760. {"SPK PA", NULL, "SPK DAC"},
  2761. {"SPK DAC", NULL, "VDD_SPKDRV"},
  2762. {"RX1 INTERPOLATOR", NULL, "RX1 MIX2"},
  2763. {"RX1 CHAIN", NULL, "RX1 INTERPOLATOR"},
  2764. {"RX2 INTERPOLATOR", NULL, "RX2 MIX2"},
  2765. {"RX2 CHAIN", NULL, "RX2 INTERPOLATOR"},
  2766. {"CLASS_H_DSM MUX", "RX_HPHL", "RX1 CHAIN"},
  2767. {"LINEOUT1 DAC", NULL, "RX_BIAS"},
  2768. {"LINEOUT2 DAC", NULL, "RX_BIAS"},
  2769. {"LINEOUT1 DAC", NULL, "CDC_CP_VDD"},
  2770. {"LINEOUT2 DAC", NULL, "CDC_CP_VDD"},
  2771. {"RDAC3 MUX", "DEM2", "RX2 CHAIN"},
  2772. {"RDAC3 MUX", "DEM1", "RX1 CHAIN"},
  2773. {"RX1 MIX1", NULL, "RX1 MIX1 INP1"},
  2774. {"RX1 MIX1", NULL, "RX1 MIX1 INP2"},
  2775. {"RX1 MIX1", NULL, "RX1 MIX1 INP3"},
  2776. {"RX2 MIX1", NULL, "RX2 MIX1 INP1"},
  2777. {"RX2 MIX1", NULL, "RX2 MIX1 INP2"},
  2778. {"RX3 MIX1", NULL, "RX3 MIX1 INP1"},
  2779. {"RX3 MIX1", NULL, "RX3 MIX1 INP2"},
  2780. {"RX1 MIX2", NULL, "RX1 MIX1"},
  2781. {"RX1 MIX2", NULL, "RX1 MIX2 INP1"},
  2782. {"RX1 MIX2", NULL, "RX1 MIX2 INP2"},
  2783. {"RX2 MIX2", NULL, "RX2 MIX1"},
  2784. {"RX2 MIX2", NULL, "RX2 MIX2 INP1"},
  2785. {"RX2 MIX2", NULL, "RX2 MIX2 INP2"},
  2786. /* SLIM_MUX("AIF1_PB", "AIF1 PB"),*/
  2787. {"SLIM RX1 MUX", "AIF1_PB", "AIF1 PB"},
  2788. {"SLIM RX2 MUX", "AIF1_PB", "AIF1 PB"},
  2789. {"SLIM RX3 MUX", "AIF1_PB", "AIF1 PB"},
  2790. {"SLIM RX4 MUX", "AIF1_PB", "AIF1 PB"},
  2791. {"SLIM RX5 MUX", "AIF1_PB", "AIF1 PB"},
  2792. /* SLIM_MUX("AIF2_PB", "AIF2 PB"),*/
  2793. {"SLIM RX1 MUX", "AIF2_PB", "AIF2 PB"},
  2794. {"SLIM RX2 MUX", "AIF2_PB", "AIF2 PB"},
  2795. {"SLIM RX3 MUX", "AIF2_PB", "AIF2 PB"},
  2796. {"SLIM RX4 MUX", "AIF2_PB", "AIF2 PB"},
  2797. {"SLIM RX5 MUX", "AIF2_PB", "AIF2 PB"},
  2798. /* SLIM_MUX("AIF3_PB", "AIF3 PB"),*/
  2799. {"SLIM RX1 MUX", "AIF3_PB", "AIF3 PB"},
  2800. {"SLIM RX2 MUX", "AIF3_PB", "AIF3 PB"},
  2801. {"SLIM RX3 MUX", "AIF3_PB", "AIF3 PB"},
  2802. {"SLIM RX4 MUX", "AIF3_PB", "AIF3 PB"},
  2803. {"SLIM RX5 MUX", "AIF3_PB", "AIF3 PB"},
  2804. {"SLIM RX1", NULL, "SLIM RX1 MUX"},
  2805. {"SLIM RX2", NULL, "SLIM RX2 MUX"},
  2806. {"SLIM RX3", NULL, "SLIM RX3 MUX"},
  2807. {"SLIM RX4", NULL, "SLIM RX4 MUX"},
  2808. {"SLIM RX5", NULL, "SLIM RX5 MUX"},
  2809. {"RX1 MIX1 INP1", "RX1", "SLIM RX1"},
  2810. {"RX1 MIX1 INP1", "RX2", "SLIM RX2"},
  2811. {"RX1 MIX1 INP1", "RX3", "SLIM RX3"},
  2812. {"RX1 MIX1 INP1", "RX4", "SLIM RX4"},
  2813. {"RX1 MIX1 INP1", "RX5", "SLIM RX5"},
  2814. {"RX1 MIX1 INP1", "IIR1", "IIR1"},
  2815. {"RX1 MIX1 INP1", "IIR2", "IIR2"},
  2816. {"RX1 MIX1 INP2", "RX1", "SLIM RX1"},
  2817. {"RX1 MIX1 INP2", "RX2", "SLIM RX2"},
  2818. {"RX1 MIX1 INP2", "RX3", "SLIM RX3"},
  2819. {"RX1 MIX1 INP2", "RX4", "SLIM RX4"},
  2820. {"RX1 MIX1 INP2", "RX5", "SLIM RX5"},
  2821. {"RX1 MIX1 INP2", "IIR1", "IIR1"},
  2822. {"RX1 MIX1 INP2", "IIR2", "IIR2"},
  2823. {"RX1 MIX1 INP3", "RX1", "SLIM RX1"},
  2824. {"RX1 MIX1 INP3", "RX2", "SLIM RX2"},
  2825. {"RX1 MIX1 INP3", "RX3", "SLIM RX3"},
  2826. {"RX1 MIX1 INP3", "RX4", "SLIM RX4"},
  2827. {"RX1 MIX1 INP3", "RX5", "SLIM RX5"},
  2828. {"RX2 MIX1 INP1", "RX1", "SLIM RX1"},
  2829. {"RX2 MIX1 INP1", "RX2", "SLIM RX2"},
  2830. {"RX2 MIX1 INP1", "RX3", "SLIM RX3"},
  2831. {"RX2 MIX1 INP1", "RX4", "SLIM RX4"},
  2832. {"RX2 MIX1 INP1", "RX5", "SLIM RX5"},
  2833. {"RX2 MIX1 INP1", "IIR1", "IIR1"},
  2834. {"RX2 MIX1 INP1", "IIR2", "IIR2"},
  2835. {"RX2 MIX1 INP2", "RX1", "SLIM RX1"},
  2836. {"RX2 MIX1 INP2", "RX2", "SLIM RX2"},
  2837. {"RX2 MIX1 INP2", "RX3", "SLIM RX3"},
  2838. {"RX2 MIX1 INP2", "RX4", "SLIM RX4"},
  2839. {"RX2 MIX1 INP2", "RX5", "SLIM RX5"},
  2840. {"RX2 MIX1 INP2", "IIR1", "IIR1"},
  2841. {"RX2 MIX1 INP2", "IIR2", "IIR2"},
  2842. {"RX3 MIX1 INP1", "RX1", "SLIM RX1"},
  2843. {"RX3 MIX1 INP1", "RX2", "SLIM RX2"},
  2844. {"RX3 MIX1 INP1", "RX3", "SLIM RX3"},
  2845. {"RX3 MIX1 INP1", "RX4", "SLIM RX4"},
  2846. {"RX3 MIX1 INP1", "RX5", "SLIM RX5"},
  2847. {"RX3 MIX1 INP1", "IIR1", "IIR1"},
  2848. {"RX3 MIX1 INP1", "IIR2", "IIR2"},
  2849. {"RX3 MIX1 INP2", "RX1", "SLIM RX1"},
  2850. {"RX3 MIX1 INP2", "RX2", "SLIM RX2"},
  2851. {"RX3 MIX1 INP2", "RX3", "SLIM RX3"},
  2852. {"RX3 MIX1 INP2", "RX4", "SLIM RX4"},
  2853. {"RX3 MIX1 INP2", "RX5", "SLIM RX5"},
  2854. {"RX3 MIX1 INP2", "IIR1", "IIR1"},
  2855. {"RX3 MIX1 INP2", "IIR2", "IIR2"},
  2856. {"RX1 MIX2 INP1", "IIR1", "IIR1"},
  2857. {"RX1 MIX2 INP2", "IIR1", "IIR1"},
  2858. {"RX2 MIX2 INP1", "IIR1", "IIR1"},
  2859. {"RX2 MIX2 INP2", "IIR1", "IIR1"},
  2860. {"RX1 MIX2 INP1", "IIR2", "IIR2"},
  2861. {"RX1 MIX2 INP2", "IIR2", "IIR2"},
  2862. {"RX2 MIX2 INP1", "IIR2", "IIR2"},
  2863. {"RX2 MIX2 INP2", "IIR2", "IIR2"},
  2864. /* Decimator Inputs */
  2865. {"DEC1 MUX", "ADC1", "ADC1"},
  2866. {"DEC1 MUX", "ADC2", "ADC2"},
  2867. {"DEC1 MUX", "ADC3", "ADC3"},
  2868. {"DEC1 MUX", "ADC4", "ADC4"},
  2869. {"DEC1 MUX", "DMIC1", "DMIC1"},
  2870. {"DEC1 MUX", "DMIC2", "DMIC2"},
  2871. {"DEC1 MUX", NULL, "CDC_CONN"},
  2872. {"DEC2 MUX", "ADC1", "ADC1"},
  2873. {"DEC2 MUX", "ADC2", "ADC2"},
  2874. {"DEC2 MUX", "ADC3", "ADC3"},
  2875. {"DEC2 MUX", "ADC4", "ADC4"},
  2876. {"DEC2 MUX", "DMIC1", "DMIC1"},
  2877. {"DEC2 MUX", "DMIC2", "DMIC2"},
  2878. {"DEC2 MUX", NULL, "CDC_CONN"},
  2879. /* ADC Connections */
  2880. {"ADC1", NULL, "AMIC1"},
  2881. {"ADC2", NULL, "AMIC2"},
  2882. {"ADC3", NULL, "AMIC3"},
  2883. {"ADC4", NULL, "AMIC4"},
  2884. /* AUX PGA Connections */
  2885. {"EAR_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
  2886. {"HPHL_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
  2887. {"HPHR_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
  2888. {"LINEOUT1_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
  2889. {"LINEOUT2_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
  2890. {"MIC BIAS1 Internal1", NULL, "LDO_H"},
  2891. {"MIC BIAS1 Internal2", NULL, "LDO_H"},
  2892. {"MIC BIAS1 External", NULL, "LDO_H"},
  2893. {"MIC BIAS2 Internal1", NULL, "LDO_H"},
  2894. {"MIC BIAS2 Internal2", NULL, "LDO_H"},
  2895. {"MIC BIAS2 Internal3", NULL, "LDO_H"},
  2896. {"MIC BIAS2 External", NULL, "LDO_H"},
  2897. #ifndef CONFIG_ARCH_MSM8226
  2898. {DAPM_MICBIAS2_EXTERNAL_STANDALONE, NULL, "LDO_H Standalone"},
  2899. #endif
  2900. /*sidetone path enable*/
  2901. {"IIR1", NULL, "IIR1 INP1 MUX"},
  2902. {"IIR1 INP1 MUX", "DEC1", "DEC1 MUX"},
  2903. {"IIR1 INP1 MUX", "DEC2", "DEC2 MUX"},
  2904. {"IIR1 INP1 MUX", "DEC3", "DEC3 MUX"},
  2905. {"IIR1 INP1 MUX", "DEC4", "DEC4 MUX"},
  2906. {"IIR1 INP1 MUX", "RX1", "SLIM RX1"},
  2907. {"IIR1 INP1 MUX", "RX2", "SLIM RX2"},
  2908. {"IIR1 INP1 MUX", "RX3", "SLIM RX3"},
  2909. {"IIR1 INP1 MUX", "RX4", "SLIM RX4"},
  2910. {"IIR1 INP1 MUX", "RX5", "SLIM RX5"},
  2911. {"IIR1", NULL, "IIR1 INP2 MUX"},
  2912. {"IIR1 INP2 MUX", "DEC1", "DEC1 MUX"},
  2913. {"IIR1 INP2 MUX", "DEC2", "DEC2 MUX"},
  2914. {"IIR1 INP2 MUX", "DEC3", "DEC3 MUX"},
  2915. {"IIR1 INP2 MUX", "DEC4", "DEC4 MUX"},
  2916. {"IIR1 INP2 MUX", "RX1", "SLIM RX1"},
  2917. {"IIR1 INP2 MUX", "RX2", "SLIM RX2"},
  2918. {"IIR1 INP2 MUX", "RX3", "SLIM RX3"},
  2919. {"IIR1 INP2 MUX", "RX4", "SLIM RX4"},
  2920. {"IIR1 INP2 MUX", "RX5", "SLIM RX5"},
  2921. {"IIR1", NULL, "IIR1 INP3 MUX"},
  2922. {"IIR1 INP3 MUX", "DEC1", "DEC1 MUX"},
  2923. {"IIR1 INP3 MUX", "DEC2", "DEC2 MUX"},
  2924. {"IIR1 INP3 MUX", "DEC3", "DEC3 MUX"},
  2925. {"IIR1 INP3 MUX", "DEC4", "DEC4 MUX"},
  2926. {"IIR1 INP3 MUX", "RX1", "SLIM RX1"},
  2927. {"IIR1 INP3 MUX", "RX2", "SLIM RX2"},
  2928. {"IIR1 INP3 MUX", "RX3", "SLIM RX3"},
  2929. {"IIR1 INP3 MUX", "RX4", "SLIM RX4"},
  2930. {"IIR1 INP3 MUX", "RX5", "SLIM RX5"},
  2931. {"IIR1", NULL, "IIR1 INP4 MUX"},
  2932. {"IIR1 INP4 MUX", "DEC1", "DEC1 MUX"},
  2933. {"IIR1 INP4 MUX", "DEC2", "DEC2 MUX"},
  2934. {"IIR1 INP4 MUX", "DEC3", "DEC3 MUX"},
  2935. {"IIR1 INP4 MUX", "DEC4", "DEC4 MUX"},
  2936. {"IIR1 INP4 MUX", "RX1", "SLIM RX1"},
  2937. {"IIR1 INP4 MUX", "RX2", "SLIM RX2"},
  2938. {"IIR1 INP4 MUX", "RX3", "SLIM RX3"},
  2939. {"IIR1 INP4 MUX", "RX4", "SLIM RX4"},
  2940. {"IIR1 INP4 MUX", "RX5", "SLIM RX5"},
  2941. {"IIR2", NULL, "IIR2 INP1 MUX"},
  2942. {"IIR2 INP1 MUX", "DEC1", "DEC1 MUX"},
  2943. {"IIR2 INP1 MUX", "DEC2", "DEC2 MUX"},
  2944. {"IIR2 INP1 MUX", "DEC3", "DEC3 MUX"},
  2945. {"IIR2 INP1 MUX", "DEC4", "DEC4 MUX"},
  2946. {"IIR2 INP1 MUX", "RX1", "SLIM RX1"},
  2947. {"IIR2 INP1 MUX", "RX2", "SLIM RX2"},
  2948. {"IIR2 INP1 MUX", "RX3", "SLIM RX3"},
  2949. {"IIR2 INP1 MUX", "RX4", "SLIM RX4"},
  2950. {"IIR2 INP1 MUX", "RX5", "SLIM RX5"},
  2951. {"IIR2", NULL, "IIR2 INP2 MUX"},
  2952. {"IIR2 INP2 MUX", "DEC1", "DEC1 MUX"},
  2953. {"IIR2 INP2 MUX", "DEC2", "DEC2 MUX"},
  2954. {"IIR2 INP2 MUX", "DEC3", "DEC3 MUX"},
  2955. {"IIR2 INP2 MUX", "DEC4", "DEC4 MUX"},
  2956. {"IIR2 INP2 MUX", "RX1", "SLIM RX1"},
  2957. {"IIR2 INP2 MUX", "RX2", "SLIM RX2"},
  2958. {"IIR2 INP2 MUX", "RX3", "SLIM RX3"},
  2959. {"IIR2 INP2 MUX", "RX4", "SLIM RX4"},
  2960. {"IIR2 INP2 MUX", "RX5", "SLIM RX5"},
  2961. {"IIR2", NULL, "IIR2 INP3 MUX"},
  2962. {"IIR2 INP3 MUX", "DEC1", "DEC1 MUX"},
  2963. {"IIR2 INP3 MUX", "DEC2", "DEC2 MUX"},
  2964. {"IIR2 INP3 MUX", "DEC3", "DEC3 MUX"},
  2965. {"IIR2 INP3 MUX", "DEC4", "DEC4 MUX"},
  2966. {"IIR2 INP3 MUX", "RX1", "SLIM RX1"},
  2967. {"IIR2 INP3 MUX", "RX2", "SLIM RX2"},
  2968. {"IIR2 INP3 MUX", "RX3", "SLIM RX3"},
  2969. {"IIR2 INP3 MUX", "RX4", "SLIM RX4"},
  2970. {"IIR2 INP3 MUX", "RX5", "SLIM RX5"},
  2971. {"IIR2", NULL, "IIR2 INP4 MUX"},
  2972. {"IIR2 INP4 MUX", "DEC1", "DEC1 MUX"},
  2973. {"IIR2 INP4 MUX", "DEC2", "DEC2 MUX"},
  2974. {"IIR2 INP4 MUX", "DEC3", "DEC3 MUX"},
  2975. {"IIR2 INP4 MUX", "DEC4", "DEC4 MUX"},
  2976. {"IIR2 INP4 MUX", "RX1", "SLIM RX1"},
  2977. {"IIR2 INP4 MUX", "RX2", "SLIM RX2"},
  2978. {"IIR2 INP4 MUX", "RX3", "SLIM RX3"},
  2979. {"IIR2 INP4 MUX", "RX4", "SLIM RX4"},
  2980. {"IIR2 INP4 MUX", "RX5", "SLIM RX5"},
  2981. };
  2982. static const struct snd_soc_dapm_route wcd9302_map[] = {
  2983. {"SPK DAC", "Switch", "RX3 MIX1"},
  2984. {"RDAC5 MUX", "DEM4", "RX3 MIX1"},
  2985. {"RDAC5 MUX", "DEM3_INV", "RDAC4 MUX"},
  2986. };
  2987. static int tapan_readable(struct snd_soc_codec *ssc, unsigned int reg)
  2988. {
  2989. return tapan_reg_readable[reg];
  2990. }
  2991. static bool tapan_is_digital_gain_register(unsigned int reg)
  2992. {
  2993. bool rtn = false;
  2994. switch (reg) {
  2995. case TAPAN_A_CDC_RX1_VOL_CTL_B2_CTL:
  2996. case TAPAN_A_CDC_RX2_VOL_CTL_B2_CTL:
  2997. case TAPAN_A_CDC_RX3_VOL_CTL_B2_CTL:
  2998. case TAPAN_A_CDC_RX4_VOL_CTL_B2_CTL:
  2999. case TAPAN_A_CDC_TX1_VOL_CTL_GAIN:
  3000. case TAPAN_A_CDC_TX2_VOL_CTL_GAIN:
  3001. case TAPAN_A_CDC_TX3_VOL_CTL_GAIN:
  3002. case TAPAN_A_CDC_TX4_VOL_CTL_GAIN:
  3003. rtn = true;
  3004. break;
  3005. default:
  3006. break;
  3007. }
  3008. return rtn;
  3009. }
  3010. static int tapan_volatile(struct snd_soc_codec *ssc, unsigned int reg)
  3011. {
  3012. int i = 0;
  3013. /* Registers lower than 0x100 are top level registers which can be
  3014. * written by the Tapan core driver.
  3015. */
  3016. if ((reg >= TAPAN_A_CDC_MBHC_EN_CTL) || (reg < 0x100))
  3017. return 1;
  3018. /* IIR Coeff registers are not cacheable */
  3019. if ((reg >= TAPAN_A_CDC_IIR1_COEF_B1_CTL) &&
  3020. (reg <= TAPAN_A_CDC_IIR2_COEF_B2_CTL))
  3021. return 1;
  3022. /* ANC filter registers are not cacheable */
  3023. if ((reg >= TAPAN_A_CDC_ANC1_IIR_B1_CTL) &&
  3024. (reg <= TAPAN_A_CDC_ANC1_LPF_B2_CTL))
  3025. return 1;
  3026. if ((reg >= TAPAN_A_CDC_ANC2_IIR_B1_CTL) &&
  3027. (reg <= TAPAN_A_CDC_ANC2_LPF_B2_CTL))
  3028. return 1;
  3029. /* Digital gain register is not cacheable so we have to write
  3030. * the setting even it is the same
  3031. */
  3032. if (tapan_is_digital_gain_register(reg))
  3033. return 1;
  3034. /* HPH status registers */
  3035. if (reg == TAPAN_A_RX_HPH_L_STATUS || reg == TAPAN_A_RX_HPH_R_STATUS)
  3036. return 1;
  3037. if (reg == TAPAN_A_MBHC_INSERT_DET_STATUS)
  3038. return 1;
  3039. for (i = 0; i < ARRAY_SIZE(audio_reg_cfg); i++)
  3040. if (audio_reg_cfg[i].reg_logical_addr -
  3041. TAPAN_REGISTER_START_OFFSET == reg)
  3042. return 1;
  3043. return 0;
  3044. }
  3045. #define TAPAN_FORMATS (SNDRV_PCM_FMTBIT_S16_LE)
  3046. #define TAPAN_FORMATS_S16_S24_LE (SNDRV_PCM_FMTBIT_S16_LE | \
  3047. SNDRV_PCM_FORMAT_S24_LE)
  3048. static int tapan_write(struct snd_soc_codec *codec, unsigned int reg,
  3049. unsigned int value)
  3050. {
  3051. int ret;
  3052. struct wcd9xxx *wcd9xxx = codec->control_data;
  3053. if (reg == SND_SOC_NOPM)
  3054. return 0;
  3055. BUG_ON(reg > TAPAN_MAX_REGISTER);
  3056. if (!tapan_volatile(codec, reg)) {
  3057. ret = snd_soc_cache_write(codec, reg, value);
  3058. if (ret != 0)
  3059. dev_err(codec->dev, "Cache write to %x failed: %d\n",
  3060. reg, ret);
  3061. }
  3062. return wcd9xxx_reg_write(&wcd9xxx->core_res, reg, value);
  3063. }
  3064. static unsigned int tapan_read(struct snd_soc_codec *codec,
  3065. unsigned int reg)
  3066. {
  3067. unsigned int val;
  3068. int ret;
  3069. struct wcd9xxx *wcd9xxx = codec->control_data;
  3070. if (reg == SND_SOC_NOPM)
  3071. return 0;
  3072. BUG_ON(reg > TAPAN_MAX_REGISTER);
  3073. if (!tapan_volatile(codec, reg) && tapan_readable(codec, reg) &&
  3074. reg < codec->driver->reg_cache_size) {
  3075. ret = snd_soc_cache_read(codec, reg, &val);
  3076. if (ret >= 0) {
  3077. return val;
  3078. } else
  3079. dev_err(codec->dev, "Cache read from %x failed: %d\n",
  3080. reg, ret);
  3081. }
  3082. val = wcd9xxx_reg_read(&wcd9xxx->core_res, reg);
  3083. return val;
  3084. }
  3085. #ifdef CONFIG_SND_SOC_ES325_ATLANTIC
  3086. static int tapan_startup(struct snd_pcm_substream *substream,
  3087. struct snd_soc_dai *dai)
  3088. {
  3089. struct wcd9xxx *tapan_core = dev_get_drvdata(dai->codec->dev->parent);
  3090. dev_dbg(dai->codec->dev, "%s(): substream = %s stream = %d\n",
  3091. __func__, substream->name, substream->stream);
  3092. if ((tapan_core != NULL) &&
  3093. (tapan_core->dev != NULL) &&
  3094. (tapan_core->dev->parent != NULL))
  3095. pm_runtime_get_sync(tapan_core->dev->parent);
  3096. es325_wrapper_wakeup(dai);
  3097. return 0;
  3098. }
  3099. #else
  3100. static int tapan_startup(struct snd_pcm_substream *substream,
  3101. struct snd_soc_dai *dai)
  3102. {
  3103. struct wcd9xxx *tapan_core = dev_get_drvdata(dai->codec->dev->parent);
  3104. dev_dbg(dai->codec->dev, "%s(): substream = %s stream = %d\n",
  3105. __func__, substream->name, substream->stream);
  3106. if ((tapan_core != NULL) &&
  3107. (tapan_core->dev != NULL) &&
  3108. (tapan_core->dev->parent != NULL))
  3109. pm_runtime_get_sync(tapan_core->dev->parent);
  3110. return 0;
  3111. }
  3112. #endif
  3113. static void tapan_shutdown(struct snd_pcm_substream *substream,
  3114. struct snd_soc_dai *dai)
  3115. {
  3116. struct wcd9xxx *tapan_core = dev_get_drvdata(dai->codec->dev->parent);
  3117. struct tapan_priv *tapan = snd_soc_codec_get_drvdata(dai->codec);
  3118. u32 active = 0;
  3119. dev_dbg(dai->codec->dev, "%s(): substream = %s stream = %d\n",
  3120. __func__, substream->name, substream->stream);
  3121. if (dai->id < NUM_CODEC_DAIS) {
  3122. if (tapan->dai[dai->id].ch_mask) {
  3123. active = 1;
  3124. dev_dbg(dai->codec->dev, "%s(): Codec DAI: chmask[%d] = 0x%lx\n",
  3125. __func__, dai->id,
  3126. tapan->dai[dai->id].ch_mask);
  3127. }
  3128. }
  3129. #ifdef CONFIG_SND_SOC_ES325_ATLANTIC
  3130. if ((tapan_core != NULL) &&
  3131. (tapan_core->dev != NULL) &&
  3132. (tapan_core->dev->parent != NULL)) {
  3133. es325_wrapper_sleep(dai->id);
  3134. }
  3135. #endif
  3136. if ((tapan_core != NULL) &&
  3137. (tapan_core->dev != NULL) &&
  3138. (tapan_core->dev->parent != NULL) &&
  3139. (active == 0)) {
  3140. pm_runtime_mark_last_busy(tapan_core->dev->parent);
  3141. pm_runtime_put(tapan_core->dev->parent);
  3142. dev_dbg(dai->codec->dev, "%s: unvote requested", __func__);
  3143. }
  3144. }
  3145. static void tapan_set_vdd_cx_current(struct snd_soc_codec *codec,
  3146. int current_uA)
  3147. {
  3148. struct regulator *cx_regulator;
  3149. int ret;
  3150. cx_regulator = tapan_codec_find_regulator(codec,
  3151. "cdc-vdd-cx");
  3152. if (!cx_regulator) {
  3153. dev_err(codec->dev, "%s: Regulator %s not defined\n",
  3154. __func__, "cdc-vdd-cx-supply");
  3155. return;
  3156. }
  3157. ret = regulator_set_optimum_mode(cx_regulator, current_uA);
  3158. if (ret < 0)
  3159. dev_err(codec->dev,
  3160. "%s: Failed to set vdd_cx current to %d\n",
  3161. __func__, current_uA);
  3162. }
  3163. int tapan_mclk_enable(struct snd_soc_codec *codec, int mclk_enable, bool dapm)
  3164. {
  3165. struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
  3166. dev_dbg(codec->dev, "%s: mclk_enable = %u, dapm = %d\n", __func__,
  3167. mclk_enable, dapm);
  3168. WCD9XXX_BG_CLK_LOCK(&tapan->resmgr);
  3169. if (mclk_enable) {
  3170. tapan_set_vdd_cx_current(codec, TAPAN_VDD_CX_OPTIMAL_UA);
  3171. wcd9xxx_resmgr_get_bandgap(&tapan->resmgr,
  3172. WCD9XXX_BANDGAP_AUDIO_MODE);
  3173. wcd9xxx_resmgr_get_clk_block(&tapan->resmgr, WCD9XXX_CLK_MCLK);
  3174. } else {
  3175. /* Put clock and BG */
  3176. wcd9xxx_resmgr_put_clk_block(&tapan->resmgr, WCD9XXX_CLK_MCLK);
  3177. wcd9xxx_resmgr_put_bandgap(&tapan->resmgr,
  3178. WCD9XXX_BANDGAP_AUDIO_MODE);
  3179. /* Set the vdd cx power rail sleep mode current */
  3180. tapan_set_vdd_cx_current(codec, TAPAN_VDD_CX_SLEEP_UA);
  3181. }
  3182. WCD9XXX_BG_CLK_UNLOCK(&tapan->resmgr);
  3183. return 0;
  3184. }
  3185. static int tapan_set_dai_sysclk(struct snd_soc_dai *dai,
  3186. int clk_id, unsigned int freq, int dir)
  3187. {
  3188. dev_dbg(dai->codec->dev, "%s\n", __func__);
  3189. return 0;
  3190. }
  3191. static int tapan_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
  3192. {
  3193. u8 val = 0;
  3194. struct snd_soc_codec *codec = dai->codec;
  3195. struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
  3196. dev_dbg(codec->dev, "%s\n", __func__);
  3197. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  3198. case SND_SOC_DAIFMT_CBS_CFS:
  3199. /* CPU is master */
  3200. if (tapan->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
  3201. if (dai->id == AIF1_CAP)
  3202. snd_soc_update_bits(codec,
  3203. TAPAN_A_CDC_CLK_I2S_CTL,
  3204. TAPAN_I2S_MASTER_MODE_MASK, 0);
  3205. else if (dai->id == AIF1_PB)
  3206. snd_soc_update_bits(codec,
  3207. TAPAN_A_CDC_CLK_I2S_CTL,
  3208. TAPAN_I2S_MASTER_MODE_MASK, 0);
  3209. }
  3210. break;
  3211. case SND_SOC_DAIFMT_CBM_CFM:
  3212. /* CPU is slave */
  3213. if (tapan->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
  3214. val = TAPAN_I2S_MASTER_MODE_MASK;
  3215. if (dai->id == AIF1_CAP)
  3216. snd_soc_update_bits(codec,
  3217. TAPAN_A_CDC_CLK_I2S_CTL, val, val);
  3218. else if (dai->id == AIF1_PB)
  3219. snd_soc_update_bits(codec,
  3220. TAPAN_A_CDC_CLK_I2S_CTL, val, val);
  3221. }
  3222. break;
  3223. default:
  3224. return -EINVAL;
  3225. }
  3226. return 0;
  3227. }
  3228. static int tapan_set_channel_map(struct snd_soc_dai *dai,
  3229. unsigned int tx_num, unsigned int *tx_slot,
  3230. unsigned int rx_num, unsigned int *rx_slot)
  3231. {
  3232. struct tapan_priv *tapan = snd_soc_codec_get_drvdata(dai->codec);
  3233. struct wcd9xxx *core = dev_get_drvdata(dai->codec->dev->parent);
  3234. if (!tx_slot || !rx_slot) {
  3235. pr_err("%s: Invalid\n", __func__);
  3236. return -EINVAL;
  3237. }
  3238. dev_dbg(dai->codec->dev, "%s(): dai_name = %s DAI-ID %x\n",
  3239. __func__, dai->name, dai->id);
  3240. dev_dbg(dai->codec->dev, "%s(): tx_ch %d rx_ch %d\n intf_type %d\n",
  3241. __func__, tx_num, rx_num, tapan->intf_type);
  3242. if (tapan->intf_type == WCD9XXX_INTERFACE_TYPE_SLIMBUS)
  3243. wcd9xxx_init_slimslave(core, core->slim->laddr,
  3244. tx_num, tx_slot, rx_num, rx_slot);
  3245. return 0;
  3246. }
  3247. static int tapan_get_channel_map(struct snd_soc_dai *dai,
  3248. unsigned int *tx_num, unsigned int *tx_slot,
  3249. unsigned int *rx_num, unsigned int *rx_slot)
  3250. {
  3251. struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(dai->codec);
  3252. u32 i = 0;
  3253. struct wcd9xxx_ch *ch;
  3254. switch (dai->id) {
  3255. case AIF1_PB:
  3256. case AIF2_PB:
  3257. case AIF3_PB:
  3258. if (!rx_slot || !rx_num) {
  3259. pr_err("%s: Invalid rx_slot %d or rx_num %d\n",
  3260. __func__, (u32) rx_slot, (u32) rx_num);
  3261. return -EINVAL;
  3262. }
  3263. list_for_each_entry(ch, &tapan_p->dai[dai->id].wcd9xxx_ch_list,
  3264. list) {
  3265. dev_dbg(dai->codec->dev, "%s: rx_slot[%d] %d, ch->ch_num %d\n",
  3266. __func__, i, rx_slot[i], ch->ch_num);
  3267. rx_slot[i++] = ch->ch_num;
  3268. }
  3269. dev_dbg(dai->codec->dev, "%s: rx_num %d\n", __func__, i);
  3270. *rx_num = i;
  3271. break;
  3272. case AIF1_CAP:
  3273. case AIF2_CAP:
  3274. case AIF3_CAP:
  3275. if (!tx_slot || !tx_num) {
  3276. pr_err("%s: Invalid tx_slot %d or tx_num %d\n",
  3277. __func__, (u32) tx_slot, (u32) tx_num);
  3278. return -EINVAL;
  3279. }
  3280. list_for_each_entry(ch, &tapan_p->dai[dai->id].wcd9xxx_ch_list,
  3281. list) {
  3282. dev_dbg(dai->codec->dev, "%s: tx_slot[%d] %d, ch->ch_num %d\n",
  3283. __func__, i, tx_slot[i], ch->ch_num);
  3284. tx_slot[i++] = ch->ch_num;
  3285. }
  3286. dev_dbg(dai->codec->dev, "%s: tx_num %d\n", __func__, i);
  3287. *tx_num = i;
  3288. break;
  3289. default:
  3290. pr_err("%s: Invalid DAI ID %x\n", __func__, dai->id);
  3291. break;
  3292. }
  3293. return 0;
  3294. }
  3295. static int tapan_set_interpolator_rate(struct snd_soc_dai *dai,
  3296. u8 rx_fs_rate_reg_val, u32 compander_fs, u32 sample_rate)
  3297. {
  3298. u32 j;
  3299. u8 rx_mix1_inp;
  3300. u16 rx_mix_1_reg_1, rx_mix_1_reg_2;
  3301. u16 rx_fs_reg;
  3302. u8 rx_mix_1_reg_1_val, rx_mix_1_reg_2_val;
  3303. u8 rdac5_mux;
  3304. struct snd_soc_codec *codec = dai->codec;
  3305. struct wcd9xxx_ch *ch;
  3306. struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
  3307. list_for_each_entry(ch, &tapan->dai[dai->id].wcd9xxx_ch_list, list) {
  3308. /* for RX port starting from 16 instead of 10 like tabla */
  3309. rx_mix1_inp = ch->port + RX_MIX1_INP_SEL_RX1 -
  3310. TAPAN_TX_PORT_NUMBER;
  3311. if ((rx_mix1_inp < RX_MIX1_INP_SEL_RX1) ||
  3312. (rx_mix1_inp > RX_MIX1_INP_SEL_RX5)) {
  3313. pr_err("%s: Invalid TAPAN_RX%u port. Dai ID is %d\n",
  3314. __func__, rx_mix1_inp - 5 , dai->id);
  3315. return -EINVAL;
  3316. }
  3317. rx_mix_1_reg_1 = TAPAN_A_CDC_CONN_RX1_B1_CTL;
  3318. rdac5_mux = snd_soc_read(codec, TAPAN_A_CDC_CONN_MISC);
  3319. rdac5_mux = (rdac5_mux & 0x04) >> 2;
  3320. for (j = 0; j < NUM_INTERPOLATORS; j++) {
  3321. rx_mix_1_reg_2 = rx_mix_1_reg_1 + 1;
  3322. rx_mix_1_reg_1_val = snd_soc_read(codec,
  3323. rx_mix_1_reg_1);
  3324. rx_mix_1_reg_2_val = snd_soc_read(codec,
  3325. rx_mix_1_reg_2);
  3326. if (((rx_mix_1_reg_1_val & 0x0F) == rx_mix1_inp) ||
  3327. (((rx_mix_1_reg_1_val >> 4) & 0x0F)
  3328. == rx_mix1_inp) ||
  3329. ((rx_mix_1_reg_2_val & 0x0F) == rx_mix1_inp)) {
  3330. rx_fs_reg = TAPAN_A_CDC_RX1_B5_CTL + 8 * j;
  3331. dev_dbg(codec->dev, "%s: AIF_PB DAI(%d) connected to RX%u\n",
  3332. __func__, dai->id, j + 1);
  3333. dev_dbg(codec->dev, "%s: set RX%u sample rate to %u\n",
  3334. __func__, j + 1, sample_rate);
  3335. snd_soc_update_bits(codec, rx_fs_reg,
  3336. 0xE0, rx_fs_rate_reg_val);
  3337. if (comp_rx_path[j] < COMPANDER_MAX) {
  3338. if ((j == 3) && (rdac5_mux == 1))
  3339. tapan->comp_fs[COMPANDER_0] =
  3340. compander_fs;
  3341. else
  3342. tapan->comp_fs[comp_rx_path[j]]
  3343. = compander_fs;
  3344. }
  3345. }
  3346. if (j <= 1)
  3347. rx_mix_1_reg_1 += 3;
  3348. else
  3349. rx_mix_1_reg_1 += 2;
  3350. }
  3351. }
  3352. return 0;
  3353. }
  3354. static int tapan_set_decimator_rate(struct snd_soc_dai *dai,
  3355. u8 tx_fs_rate_reg_val, u32 sample_rate)
  3356. {
  3357. struct snd_soc_codec *codec = dai->codec;
  3358. struct wcd9xxx_ch *ch;
  3359. struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
  3360. u32 tx_port;
  3361. u16 tx_port_reg, tx_fs_reg;
  3362. u8 tx_port_reg_val;
  3363. s8 decimator;
  3364. list_for_each_entry(ch, &tapan->dai[dai->id].wcd9xxx_ch_list, list) {
  3365. tx_port = ch->port + 1;
  3366. dev_dbg(codec->dev, "%s: dai->id = %d, tx_port = %d",
  3367. __func__, dai->id, tx_port);
  3368. if ((tx_port < 1) || (tx_port > TAPAN_SLIM_CODEC_TX_PORTS)) {
  3369. pr_err("%s: Invalid SLIM TX%u port. DAI ID is %d\n",
  3370. __func__, tx_port, dai->id);
  3371. return -EINVAL;
  3372. }
  3373. tx_port_reg = TAPAN_A_CDC_CONN_TX_SB_B1_CTL + (tx_port - 1);
  3374. tx_port_reg_val = snd_soc_read(codec, tx_port_reg);
  3375. decimator = 0;
  3376. tx_port_reg_val = tx_port_reg_val & 0x0F;
  3377. if ((tx_port_reg_val >= 0x8) &&
  3378. (tx_port_reg_val <= 0x11)) {
  3379. decimator = (tx_port_reg_val - 0x8) + 1;
  3380. }
  3381. if (decimator) { /* SLIM_TX port has a DEC as input */
  3382. tx_fs_reg = TAPAN_A_CDC_TX1_CLK_FS_CTL +
  3383. 8 * (decimator - 1);
  3384. dev_dbg(codec->dev, "%s: set DEC%u (-> SLIM_TX%u) rate to %u\n",
  3385. __func__, decimator, tx_port, sample_rate);
  3386. snd_soc_update_bits(codec, tx_fs_reg, 0x07,
  3387. tx_fs_rate_reg_val);
  3388. } else {
  3389. if ((tx_port_reg_val >= 0x1) &&
  3390. (tx_port_reg_val <= 0x4)) {
  3391. dev_dbg(codec->dev, "%s: RMIX%u going to SLIM TX%u\n",
  3392. __func__, tx_port_reg_val, tx_port);
  3393. } else if ((tx_port_reg_val >= 0x8) &&
  3394. (tx_port_reg_val <= 0x11)) {
  3395. pr_err("%s: ERROR: Should not be here\n",
  3396. __func__);
  3397. pr_err("%s: ERROR: DEC connected to SLIM TX%u\n",
  3398. __func__, tx_port);
  3399. return -EINVAL;
  3400. } else if (tx_port_reg_val == 0) {
  3401. dev_dbg(codec->dev, "%s: no signal to SLIM TX%u\n",
  3402. __func__, tx_port);
  3403. } else {
  3404. pr_err("%s: ERROR: wrong signal to SLIM TX%u\n",
  3405. __func__, tx_port);
  3406. pr_err("%s: ERROR: wrong signal = %u\n",
  3407. __func__, tx_port_reg_val);
  3408. return -EINVAL;
  3409. }
  3410. }
  3411. }
  3412. return 0;
  3413. }
  3414. static void tapan_set_rxsb_port_format(struct snd_pcm_hw_params *params,
  3415. struct snd_soc_dai *dai)
  3416. {
  3417. struct snd_soc_codec *codec = dai->codec;
  3418. struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec);
  3419. struct wcd9xxx_codec_dai_data *cdc_dai;
  3420. struct wcd9xxx_ch *ch;
  3421. int port;
  3422. u8 bit_sel;
  3423. u16 sb_ctl_reg, field_shift;
  3424. switch (params_format(params)) {
  3425. case SNDRV_PCM_FORMAT_S16_LE:
  3426. bit_sel = 0x2;
  3427. tapan_p->dai[dai->id].bit_width = 16;
  3428. break;
  3429. case SNDRV_PCM_FORMAT_S24_LE:
  3430. bit_sel = 0x0;
  3431. tapan_p->dai[dai->id].bit_width = 24;
  3432. break;
  3433. default:
  3434. dev_err(codec->dev, "Invalid format %x\n",
  3435. params_format(params));
  3436. return;
  3437. }
  3438. cdc_dai = &tapan_p->dai[dai->id];
  3439. list_for_each_entry(ch, &cdc_dai->wcd9xxx_ch_list, list) {
  3440. port = wcd9xxx_get_slave_port(ch->ch_num);
  3441. if (IS_ERR_VALUE(port) ||
  3442. !TAPAN_VALIDATE_RX_SBPORT_RANGE(port)) {
  3443. dev_warn(codec->dev,
  3444. "%s: invalid port ID %d returned for RX DAI\n",
  3445. __func__, port);
  3446. return;
  3447. }
  3448. port = TAPAN_CONVERT_RX_SBPORT_ID(port);
  3449. if (port <= 3) {
  3450. sb_ctl_reg = TAPAN_A_CDC_CONN_RX_SB_B1_CTL;
  3451. field_shift = port << 1;
  3452. } else if (port <= 4) {
  3453. sb_ctl_reg = TAPAN_A_CDC_CONN_RX_SB_B2_CTL;
  3454. field_shift = (port - 4) << 1;
  3455. } else { /* should not happen */
  3456. dev_warn(codec->dev,
  3457. "%s: bad port ID %d\n", __func__, port);
  3458. return;
  3459. }
  3460. dev_dbg(codec->dev, "%s: sb_ctl_reg %x field_shift %x\n"
  3461. "bit_sel %x\n", __func__, sb_ctl_reg, field_shift,
  3462. bit_sel);
  3463. snd_soc_update_bits(codec, sb_ctl_reg, 0x3 << field_shift,
  3464. bit_sel << field_shift);
  3465. }
  3466. }
  3467. static int tapan_hw_params(struct snd_pcm_substream *substream,
  3468. struct snd_pcm_hw_params *params,
  3469. struct snd_soc_dai *dai)
  3470. {
  3471. struct snd_soc_codec *codec = dai->codec;
  3472. struct tapan_priv *tapan = snd_soc_codec_get_drvdata(dai->codec);
  3473. u8 tx_fs_rate, rx_fs_rate;
  3474. u32 compander_fs;
  3475. int ret;
  3476. dev_dbg(dai->codec->dev, "%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n",
  3477. __func__, dai->name, dai->id,
  3478. params_rate(params), params_channels(params));
  3479. switch (params_rate(params)) {
  3480. case 8000:
  3481. tx_fs_rate = 0x00;
  3482. rx_fs_rate = 0x00;
  3483. compander_fs = COMPANDER_FS_8KHZ;
  3484. break;
  3485. case 16000:
  3486. tx_fs_rate = 0x01;
  3487. rx_fs_rate = 0x20;
  3488. compander_fs = COMPANDER_FS_16KHZ;
  3489. break;
  3490. case 32000:
  3491. tx_fs_rate = 0x02;
  3492. rx_fs_rate = 0x40;
  3493. compander_fs = COMPANDER_FS_32KHZ;
  3494. break;
  3495. case 48000:
  3496. tx_fs_rate = 0x03;
  3497. rx_fs_rate = 0x60;
  3498. compander_fs = COMPANDER_FS_48KHZ;
  3499. break;
  3500. case 96000:
  3501. tx_fs_rate = 0x04;
  3502. rx_fs_rate = 0x80;
  3503. compander_fs = COMPANDER_FS_96KHZ;
  3504. break;
  3505. case 192000:
  3506. tx_fs_rate = 0x05;
  3507. rx_fs_rate = 0xA0;
  3508. compander_fs = COMPANDER_FS_192KHZ;
  3509. break;
  3510. default:
  3511. pr_err("%s: Invalid sampling rate %d\n", __func__,
  3512. params_rate(params));
  3513. return -EINVAL;
  3514. }
  3515. switch (substream->stream) {
  3516. case SNDRV_PCM_STREAM_CAPTURE:
  3517. ret = tapan_set_decimator_rate(dai, tx_fs_rate,
  3518. params_rate(params));
  3519. if (ret < 0) {
  3520. pr_err("%s: set decimator rate failed %d\n", __func__,
  3521. ret);
  3522. return ret;
  3523. }
  3524. if (tapan->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
  3525. switch (params_format(params)) {
  3526. case SNDRV_PCM_FORMAT_S16_LE:
  3527. snd_soc_update_bits(codec,
  3528. TAPAN_A_CDC_CLK_I2S_CTL,
  3529. 0x20, 0x20);
  3530. break;
  3531. case SNDRV_PCM_FORMAT_S32_LE:
  3532. snd_soc_update_bits(codec,
  3533. TAPAN_A_CDC_CLK_I2S_CTL,
  3534. 0x20, 0x00);
  3535. break;
  3536. default:
  3537. pr_err("invalid format\n");
  3538. break;
  3539. }
  3540. snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_I2S_CTL,
  3541. 0x07, tx_fs_rate);
  3542. } else {
  3543. tapan->dai[dai->id].rate = params_rate(params);
  3544. }
  3545. break;
  3546. case SNDRV_PCM_STREAM_PLAYBACK:
  3547. ret = tapan_set_interpolator_rate(dai, rx_fs_rate,
  3548. compander_fs,
  3549. params_rate(params));
  3550. if (ret < 0) {
  3551. dev_err(codec->dev, "%s: set decimator rate failed %d\n",
  3552. __func__, ret);
  3553. return ret;
  3554. }
  3555. if (tapan->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
  3556. switch (params_format(params)) {
  3557. case SNDRV_PCM_FORMAT_S16_LE:
  3558. snd_soc_update_bits(codec,
  3559. TAPAN_A_CDC_CLK_I2S_CTL,
  3560. 0x20, 0x20);
  3561. break;
  3562. case SNDRV_PCM_FORMAT_S32_LE:
  3563. snd_soc_update_bits(codec,
  3564. TAPAN_A_CDC_CLK_I2S_CTL,
  3565. 0x20, 0x00);
  3566. break;
  3567. default:
  3568. dev_err(codec->dev, "invalid format\n");
  3569. break;
  3570. }
  3571. snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_I2S_CTL,
  3572. 0x03, (rx_fs_rate >> 0x05));
  3573. } else {
  3574. tapan_set_rxsb_port_format(params, dai);
  3575. tapan->dai[dai->id].rate = params_rate(params);
  3576. }
  3577. break;
  3578. default:
  3579. dev_err(codec->dev, "%s: Invalid stream type %d\n", __func__,
  3580. substream->stream);
  3581. return -EINVAL;
  3582. }
  3583. return 0;
  3584. }
  3585. #if defined(CONFIG_SND_SOC_ES705)
  3586. int (*remote_route_enable)(struct snd_soc_dai *dai) = REMOTE_ROUTE_ENABLE_CB;
  3587. int (*slim_get_channel_map)(struct snd_soc_dai *dai,
  3588. unsigned int *tx_num, unsigned int *tx_slot,
  3589. unsigned int *rx_num, unsigned int *rx_slot)
  3590. = SLIM_GET_CHANNEL_MAP_CB;
  3591. int (*slim_set_channel_map)(struct snd_soc_dai *dai,
  3592. unsigned int tx_num, unsigned int *tx_slot,
  3593. unsigned int rx_num, unsigned int *rx_slot)
  3594. = SLIM_SET_CHANNEL_MAP_CB;
  3595. int (*slim_hw_params)(struct snd_pcm_substream *substream,
  3596. struct snd_pcm_hw_params *params,
  3597. struct snd_soc_dai *dai)
  3598. = SLIM_HW_PARAMS_CB;
  3599. int (*remote_cfg_slim_rx)(int dai_id) = REMOTE_CFG_SLIM_RX_CB;
  3600. int (*remote_close_slim_rx)(int dai_id) = REMOTE_CLOSE_SLIM_RX_CB;
  3601. int (*remote_cfg_slim_tx)(int dai_id) = REMOTE_CFG_SLIM_TX_CB;
  3602. int (*remote_close_slim_tx)(int dai_id) = REMOTE_CLOSE_SLIM_TX_CB;
  3603. int (*remote_add_codec_controls)(struct snd_soc_codec *codec)
  3604. = REMOTE_ADD_CODEC_CONTROLS_CB;
  3605. static int tapan_esxxx_startup(struct snd_pcm_substream *substream,
  3606. struct snd_soc_dai *dai)
  3607. {
  3608. tapan_startup(substream, dai);
  3609. /*
  3610. if (es705_remote_route_enable(dai))
  3611. es705_slim_startup(substream, dai);
  3612. */
  3613. return 0;
  3614. }
  3615. static void tapan_esxxx_shutdown(struct snd_pcm_substream *substream,
  3616. struct snd_soc_dai *dai)
  3617. {
  3618. tapan_shutdown(substream, dai);
  3619. /*
  3620. if (es705_remote_route_enable(dai))
  3621. es705_slim_shutdown(substream, dai);
  3622. */
  3623. }
  3624. static int tapan_esxxx_hw_params(struct snd_pcm_substream *substream,
  3625. struct snd_pcm_hw_params *params,
  3626. struct snd_soc_dai *dai)
  3627. {
  3628. int rc = 0;
  3629. pr_info("%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n", __func__,
  3630. dai->name, dai->id, params_rate(params),
  3631. params_channels(params));
  3632. rc = tapan_hw_params(substream, params, dai);
  3633. if (remote_route_enable(dai))
  3634. rc = slim_hw_params(substream, params, dai);
  3635. return rc;
  3636. }
  3637. static int tapan_esxxx_set_channel_map(struct snd_soc_dai *dai,
  3638. unsigned int tx_num, unsigned int *tx_slot,
  3639. unsigned int rx_num, unsigned int *rx_slot)
  3640. {
  3641. unsigned int tapan_tx_num = 0;
  3642. unsigned int tapan_tx_slot[6];
  3643. unsigned int tapan_rx_num = 0;
  3644. unsigned int tapan_rx_slot[6];
  3645. int rc = 0;
  3646. pr_info("%s(): dai_name = %s DAI-ID %x tx_ch %d rx_ch %d\n",
  3647. __func__, dai->name, dai->id, tx_num, rx_num);
  3648. if (remote_route_enable(dai)) {
  3649. rc = tapan_get_channel_map(dai, &tapan_tx_num, tapan_tx_slot,
  3650. &tapan_rx_num, tapan_rx_slot);
  3651. rc = tapan_set_channel_map(dai, tx_num, tapan_tx_slot, rx_num, tapan_rx_slot);
  3652. rc = slim_set_channel_map(dai, tx_num, tx_slot, rx_num,
  3653. rx_slot);
  3654. } else
  3655. rc = tapan_set_channel_map(dai, tx_num, tx_slot, rx_num, rx_slot);
  3656. return rc;
  3657. }
  3658. static int tapan_esxxx_get_channel_map(struct snd_soc_dai *dai,
  3659. unsigned int *tx_num, unsigned int *tx_slot,
  3660. unsigned int *rx_num, unsigned int *rx_slot)
  3661. {
  3662. int rc = 0;
  3663. pr_info("%s(): dai_name = %s DAI-ID %d tx_ch %d rx_ch %d\n",
  3664. __func__, dai->name, dai->id, *tx_num, *rx_num);
  3665. if (remote_route_enable(dai))
  3666. rc = slim_get_channel_map(dai, tx_num, tx_slot, rx_num,
  3667. rx_slot);
  3668. else
  3669. rc = tapan_get_channel_map(dai, tx_num, tx_slot, rx_num, rx_slot);
  3670. return rc;
  3671. }
  3672. static struct snd_soc_dai_ops tapan_dai_ops = {
  3673. .startup = tapan_esxxx_startup, /* tapan_startup, */
  3674. .shutdown = tapan_esxxx_shutdown, /* tapan_shutdown, */
  3675. .hw_params = tapan_esxxx_hw_params, /* tapan_hw_params, */
  3676. .set_sysclk = tapan_set_dai_sysclk,
  3677. .set_fmt = tapan_set_dai_fmt,
  3678. .set_channel_map = tapan_esxxx_set_channel_map,
  3679. /* tapan_set_channel_map, */
  3680. .get_channel_map = tapan_esxxx_get_channel_map,
  3681. /* tapan_get_channel_map, */
  3682. };
  3683. #elif defined(CONFIG_SND_SOC_ES325_ATLANTIC)
  3684. static int tapan_es325_hw_params(struct snd_pcm_substream *substream,
  3685. struct snd_pcm_hw_params *params,
  3686. struct snd_soc_dai *dai)
  3687. {
  3688. int rc = 0;
  3689. dev_err(dai->dev,"%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n", __func__,
  3690. dai->name, dai->id, params_rate(params),
  3691. params_channels(params));
  3692. rc = tapan_hw_params(substream, params, dai);
  3693. if (es325_remote_route_enable(dai))
  3694. rc = es325_slim_hw_params(substream, params, dai);
  3695. return rc;
  3696. }
  3697. #define SLIM_BUGFIX
  3698. static int tapan_es325_set_channel_map(struct snd_soc_dai *dai,
  3699. unsigned int tx_num, unsigned int *tx_slot,
  3700. unsigned int rx_num, unsigned int *rx_slot)
  3701. {
  3702. #if !defined(SLIM_BUGFIX)
  3703. unsigned int tapan_tx_num = 0;
  3704. #endif
  3705. #if !defined(SLIM_BUGFIX)
  3706. unsigned int tapan_rx_num = 0;
  3707. #endif
  3708. #if defined(SLIM_BUGFIX)
  3709. unsigned int temp_tx_num = 0;
  3710. unsigned int temp_rx_num = 0;
  3711. #endif
  3712. int rc = 0;
  3713. if (es325_remote_route_enable(dai)) {
  3714. unsigned int tapan_tx_slot[6];
  3715. unsigned int tapan_rx_slot[6];
  3716. #if defined(SLIM_BUGFIX)
  3717. rc = tapan_get_channel_map(dai, &temp_tx_num, tapan_tx_slot,
  3718. &temp_rx_num, tapan_rx_slot);
  3719. if (rc < 0 )
  3720. pr_err ("error statement");
  3721. goto out;
  3722. #else
  3723. rc = tapan_get_channel_map(dai, &tapan_tx_num, tapan_tx_slot,
  3724. &tapan_rx_num, tapan_rx_slot);
  3725. if (rc < 0 )
  3726. pr_err ("error statement");
  3727. goto out;
  3728. #endif
  3729. rc = tapan_set_channel_map(dai, tx_num, tapan_tx_slot, rx_num, tapan_rx_slot);
  3730. if (rc < 0 )
  3731. pr_err ("error statement");
  3732. goto out;
  3733. rc = es325_slim_set_channel_map(dai, tx_num, tx_slot, rx_num, rx_slot);
  3734. if (rc < 0 )
  3735. pr_err ("error statement");
  3736. goto out;
  3737. } else
  3738. rc = tapan_set_channel_map(dai, tx_num, tx_slot, rx_num, rx_slot);
  3739. if (rc < 0 )
  3740. pr_err ("error statement");
  3741. goto out;
  3742. out:
  3743. return rc;
  3744. }
  3745. static int tapan_es325_get_channel_map(struct snd_soc_dai *dai,
  3746. unsigned int *tx_num, unsigned int *tx_slot,
  3747. unsigned int *rx_num, unsigned int *rx_slot)
  3748. {
  3749. int rc = 0;
  3750. if (es325_remote_route_enable(dai))
  3751. rc = es325_slim_get_channel_map(dai, tx_num, tx_slot, rx_num, rx_slot);
  3752. else
  3753. rc = tapan_get_channel_map(dai, tx_num, tx_slot, rx_num, rx_slot);
  3754. return rc;
  3755. }
  3756. static struct snd_soc_dai_ops tapan_dai_ops = {
  3757. .startup = tapan_startup,
  3758. .shutdown = tapan_shutdown,
  3759. .hw_params = tapan_es325_hw_params, /* tabla_hw_params, */
  3760. .set_sysclk = tapan_set_dai_sysclk,
  3761. .set_fmt = tapan_set_dai_fmt,
  3762. .set_channel_map = tapan_set_channel_map, /* tabla_set_channel_map, */
  3763. .get_channel_map = tapan_es325_get_channel_map, /* tabla_get_channel_map, */
  3764. };
  3765. static struct snd_soc_dai_ops tapan_es325_dai_ops = {
  3766. .startup = tapan_startup,
  3767. .hw_params = tapan_es325_hw_params,
  3768. .set_channel_map = tapan_es325_set_channel_map,
  3769. .get_channel_map = tapan_es325_get_channel_map,
  3770. };
  3771. #else
  3772. static struct snd_soc_dai_ops tapan_dai_ops = {
  3773. .startup = tapan_startup,
  3774. .shutdown = tapan_shutdown,
  3775. .hw_params = tapan_hw_params,
  3776. .set_sysclk = tapan_set_dai_sysclk,
  3777. .set_fmt = tapan_set_dai_fmt,
  3778. .set_channel_map = tapan_set_channel_map,
  3779. .get_channel_map = tapan_get_channel_map,
  3780. };
  3781. #endif
  3782. static struct snd_soc_dai_driver tapan9302_dai[] = {
  3783. {
  3784. .name = "tapan9302_rx1",
  3785. .id = AIF1_PB,
  3786. .playback = {
  3787. .stream_name = "AIF1 Playback",
  3788. .rates = WCD9302_RATES,
  3789. .formats = TAPAN_FORMATS,
  3790. .rate_max = 48000,
  3791. .rate_min = 8000,
  3792. .channels_min = 1,
  3793. .channels_max = 2,
  3794. },
  3795. .ops = &tapan_dai_ops,
  3796. },
  3797. {
  3798. .name = "tapan9302_tx1",
  3799. .id = AIF1_CAP,
  3800. .capture = {
  3801. .stream_name = "AIF1 Capture",
  3802. .rates = WCD9302_RATES,
  3803. .formats = TAPAN_FORMATS,
  3804. .rate_max = 48000,
  3805. .rate_min = 8000,
  3806. .channels_min = 1,
  3807. .channels_max = 4,
  3808. },
  3809. .ops = &tapan_dai_ops,
  3810. },
  3811. {
  3812. .name = "tapan9302_rx2",
  3813. .id = AIF2_PB,
  3814. .playback = {
  3815. .stream_name = "AIF2 Playback",
  3816. .rates = WCD9302_RATES,
  3817. .formats = TAPAN_FORMATS,
  3818. .rate_min = 8000,
  3819. .rate_max = 48000,
  3820. .channels_min = 1,
  3821. .channels_max = 2,
  3822. },
  3823. .ops = &tapan_dai_ops,
  3824. },
  3825. {
  3826. .name = "tapan9302_tx2",
  3827. .id = AIF2_CAP,
  3828. .capture = {
  3829. .stream_name = "AIF2 Capture",
  3830. .rates = WCD9302_RATES,
  3831. .formats = TAPAN_FORMATS,
  3832. .rate_max = 48000,
  3833. .rate_min = 8000,
  3834. .channels_min = 1,
  3835. .channels_max = 4,
  3836. },
  3837. .ops = &tapan_dai_ops,
  3838. },
  3839. {
  3840. .name = "tapan9302_tx3",
  3841. .id = AIF3_CAP,
  3842. .capture = {
  3843. .stream_name = "AIF3 Capture",
  3844. .rates = WCD9302_RATES,
  3845. .formats = TAPAN_FORMATS,
  3846. .rate_max = 48000,
  3847. .rate_min = 8000,
  3848. .channels_min = 1,
  3849. .channels_max = 2,
  3850. },
  3851. .ops = &tapan_dai_ops,
  3852. },
  3853. {
  3854. .name = "tapan9302_rx3",
  3855. .id = AIF3_PB,
  3856. .playback = {
  3857. .stream_name = "AIF3 Playback",
  3858. .rates = WCD9302_RATES,
  3859. .formats = TAPAN_FORMATS,
  3860. .rate_min = 8000,
  3861. .rate_max = 48000,
  3862. .channels_min = 1,
  3863. .channels_max = 2,
  3864. },
  3865. .ops = &tapan_dai_ops,
  3866. },
  3867. #ifdef CONFIG_SND_SOC_ES325_ATLANTIC
  3868. {
  3869. .name = "tapan_es325_rx1",
  3870. .id = AIF1_PB + ES325_DAI_ID_OFFSET,
  3871. .playback = {
  3872. .stream_name = "AIF1 Playback",
  3873. .rates = WCD9306_RATES,
  3874. .formats = TAPAN_FORMATS,
  3875. .rate_max = 192000,
  3876. .rate_min = 8000,
  3877. .channels_min = 1,
  3878. .channels_max = 2,
  3879. },
  3880. .ops = &tapan_es325_dai_ops,
  3881. },
  3882. {
  3883. .name = "tapan_es325_tx1",
  3884. .id = AIF1_CAP + ES325_DAI_ID_OFFSET,
  3885. .capture = {
  3886. .stream_name = "AIF1 Capture",
  3887. .rates = WCD9306_RATES,
  3888. .formats = TAPAN_FORMATS,
  3889. .rate_max = 192000,
  3890. .rate_min = 8000,
  3891. .channels_min = 1,
  3892. .channels_max = 2,
  3893. },
  3894. .ops = &tapan_es325_dai_ops,
  3895. },
  3896. {
  3897. .name = "tapan_es325_rx2",
  3898. .id = AIF2_PB + ES325_DAI_ID_OFFSET,
  3899. .playback = {
  3900. .stream_name = "AIF2 Playback",
  3901. .rates = WCD9306_RATES,
  3902. .formats = TAPAN_FORMATS,
  3903. .rate_max = 192000,
  3904. .rate_min = 8000,
  3905. .channels_min = 1,
  3906. .channels_max = 2,
  3907. },
  3908. .ops = &tapan_es325_dai_ops,
  3909. },
  3910. #endif
  3911. };
  3912. static struct snd_soc_dai_driver tapan_dai[] = {
  3913. {
  3914. .name = "tapan_rx1",
  3915. .id = AIF1_PB,
  3916. .playback = {
  3917. .stream_name = "AIF1 Playback",
  3918. .rates = WCD9306_RATES,
  3919. .formats = TAPAN_FORMATS_S16_S24_LE,
  3920. .rate_max = 192000,
  3921. .rate_min = 8000,
  3922. .channels_min = 1,
  3923. .channels_max = 2,
  3924. },
  3925. .ops = &tapan_dai_ops,
  3926. },
  3927. {
  3928. .name = "tapan_tx1",
  3929. .id = AIF1_CAP,
  3930. .capture = {
  3931. .stream_name = "AIF1 Capture",
  3932. .rates = WCD9306_RATES,
  3933. .formats = TAPAN_FORMATS,
  3934. .rate_max = 192000,
  3935. .rate_min = 8000,
  3936. .channels_min = 1,
  3937. .channels_max = 4,
  3938. },
  3939. .ops = &tapan_dai_ops,
  3940. },
  3941. {
  3942. .name = "tapan_rx2",
  3943. .id = AIF2_PB,
  3944. .playback = {
  3945. .stream_name = "AIF2 Playback",
  3946. .rates = WCD9306_RATES,
  3947. .formats = TAPAN_FORMATS_S16_S24_LE,
  3948. .rate_min = 8000,
  3949. .rate_max = 192000,
  3950. .channels_min = 1,
  3951. .channels_max = 2,
  3952. },
  3953. .ops = &tapan_dai_ops,
  3954. },
  3955. {
  3956. .name = "tapan_tx2",
  3957. .id = AIF2_CAP,
  3958. .capture = {
  3959. .stream_name = "AIF2 Capture",
  3960. .rates = WCD9306_RATES,
  3961. .formats = TAPAN_FORMATS,
  3962. .rate_max = 192000,
  3963. .rate_min = 8000,
  3964. .channels_min = 1,
  3965. .channels_max = 4,
  3966. },
  3967. .ops = &tapan_dai_ops,
  3968. },
  3969. {
  3970. .name = "tapan_tx3",
  3971. .id = AIF3_CAP,
  3972. .capture = {
  3973. .stream_name = "AIF3 Capture",
  3974. .rates = WCD9306_RATES,
  3975. .formats = TAPAN_FORMATS,
  3976. .rate_max = 48000,
  3977. .rate_min = 8000,
  3978. .channels_min = 1,
  3979. .channels_max = 2,
  3980. },
  3981. .ops = &tapan_dai_ops,
  3982. },
  3983. {
  3984. .name = "tapan_rx3",
  3985. .id = AIF3_PB,
  3986. .playback = {
  3987. .stream_name = "AIF3 Playback",
  3988. .rates = WCD9306_RATES,
  3989. .formats = TAPAN_FORMATS_S16_S24_LE,
  3990. .rate_min = 8000,
  3991. .rate_max = 192000,
  3992. .channels_min = 1,
  3993. .channels_max = 2,
  3994. },
  3995. .ops = &tapan_dai_ops,
  3996. },
  3997. };
  3998. static struct snd_soc_dai_driver tapan_i2s_dai[] = {
  3999. {
  4000. .name = "tapan_i2s_rx1",
  4001. .id = AIF1_PB,
  4002. .playback = {
  4003. .stream_name = "AIF1 Playback",
  4004. .rates = WCD9306_RATES,
  4005. .formats = TAPAN_FORMATS,
  4006. .rate_max = 192000,
  4007. .rate_min = 8000,
  4008. .channels_min = 1,
  4009. .channels_max = 4,
  4010. },
  4011. .ops = &tapan_dai_ops,
  4012. },
  4013. {
  4014. .name = "tapan_i2s_tx1",
  4015. .id = AIF1_CAP,
  4016. .capture = {
  4017. .stream_name = "AIF1 Capture",
  4018. .rates = WCD9306_RATES,
  4019. .formats = TAPAN_FORMATS,
  4020. .rate_max = 192000,
  4021. .rate_min = 8000,
  4022. .channels_min = 1,
  4023. .channels_max = 4,
  4024. },
  4025. .ops = &tapan_dai_ops,
  4026. },
  4027. };
  4028. static int tapan_codec_enable_slim_chmask(struct wcd9xxx_codec_dai_data *dai,
  4029. bool up)
  4030. {
  4031. int ret = 0;
  4032. struct wcd9xxx_ch *ch;
  4033. if (up) {
  4034. list_for_each_entry(ch, &dai->wcd9xxx_ch_list, list) {
  4035. ret = wcd9xxx_get_slave_port(ch->ch_num);
  4036. if (ret < 0) {
  4037. pr_debug("%s: Invalid slave port ID: %d\n",
  4038. __func__, ret);
  4039. ret = -EINVAL;
  4040. } else {
  4041. set_bit(ret, &dai->ch_mask);
  4042. }
  4043. }
  4044. } else {
  4045. ret = wait_event_timeout(dai->dai_wait, (dai->ch_mask == 0),
  4046. msecs_to_jiffies(
  4047. TAPAN_SLIM_CLOSE_TIMEOUT));
  4048. if (!ret) {
  4049. pr_debug("%s: Slim close tx/rx wait timeout\n",
  4050. __func__);
  4051. ret = -ETIMEDOUT;
  4052. } else {
  4053. ret = 0;
  4054. }
  4055. }
  4056. return ret;
  4057. }
  4058. static int tapan_codec_enable_slimrx(struct snd_soc_dapm_widget *w,
  4059. struct snd_kcontrol *kcontrol,
  4060. int event)
  4061. {
  4062. struct wcd9xxx *core;
  4063. struct snd_soc_codec *codec = w->codec;
  4064. struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec);
  4065. int ret = 0;
  4066. struct wcd9xxx_codec_dai_data *dai;
  4067. core = dev_get_drvdata(codec->dev->parent);
  4068. if(core == NULL) {
  4069. dev_err(codec->dev, "%s: core is null\n",
  4070. __func__);
  4071. return -EINVAL;
  4072. }
  4073. dev_dbg(codec->dev, "%s: event called! codec name %s\n",
  4074. __func__, w->codec->name);
  4075. dev_dbg(codec->dev, "%s: num_dai %d stream name %s event %d\n",
  4076. __func__, w->codec->num_dai, w->sname, event);
  4077. /* Execute the callback only if interface type is slimbus */
  4078. if (tapan_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS)
  4079. return 0;
  4080. dai = &tapan_p->dai[w->shift];
  4081. dev_dbg(codec->dev, "%s: w->name %s w->shift %d event %d\n",
  4082. __func__, w->name, w->shift, event);
  4083. switch (event) {
  4084. case SND_SOC_DAPM_POST_PMU:
  4085. dai->bus_down_in_recovery = false;
  4086. (void) tapan_codec_enable_slim_chmask(dai, true);
  4087. #if defined(CONFIG_SND_SOC_ES705)
  4088. ret = remote_cfg_slim_rx(w->shift);
  4089. #elif defined(CONFIG_SND_SOC_ES325_ATLANTIC)
  4090. ret = es325_remote_cfg_slim_rx(w->shift);
  4091. #endif
  4092. ret = wcd9xxx_cfg_slim_sch_rx(core, &dai->wcd9xxx_ch_list,
  4093. dai->rate, dai->bit_width,
  4094. &dai->grph);
  4095. break;
  4096. case SND_SOC_DAPM_POST_PMD:
  4097. #if defined(CONFIG_SND_SOC_ES705)
  4098. ret = remote_close_slim_rx(w->shift);
  4099. #elif defined(CONFIG_SND_SOC_ES325_ATLANTIC)
  4100. ret = es325_remote_close_slim_rx(w->shift);
  4101. #endif
  4102. ret = wcd9xxx_close_slim_sch_rx(core, &dai->wcd9xxx_ch_list,
  4103. dai->grph);
  4104. if (!dai->bus_down_in_recovery)
  4105. ret = tapan_codec_enable_slim_chmask(dai, false);
  4106. if (ret < 0) {
  4107. ret = wcd9xxx_disconnect_port(core,
  4108. &dai->wcd9xxx_ch_list,
  4109. dai->grph);
  4110. dev_dbg(codec->dev, "%s: Disconnect RX port, ret = %d\n",
  4111. __func__, ret);
  4112. }
  4113. if ((core != NULL) &&
  4114. (core->dev != NULL) &&
  4115. (core->dev->parent != NULL)) {
  4116. pm_runtime_mark_last_busy(core->dev->parent);
  4117. pm_runtime_put(core->dev->parent);
  4118. dev_dbg(codec->dev, "%s: unvote requested", __func__);
  4119. }
  4120. dai->bus_down_in_recovery = false;
  4121. break;
  4122. }
  4123. return ret;
  4124. }
  4125. static int tapan_codec_enable_slimtx(struct snd_soc_dapm_widget *w,
  4126. struct snd_kcontrol *kcontrol,
  4127. int event)
  4128. {
  4129. struct wcd9xxx *core;
  4130. struct snd_soc_codec *codec = w->codec;
  4131. struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec);
  4132. int ret = 0;
  4133. struct wcd9xxx_codec_dai_data *dai;
  4134. core = dev_get_drvdata(codec->dev->parent);
  4135. if (!core) {
  4136. dev_err(codec->dev,"core is NULL\n");
  4137. return -ENOMEM;
  4138. }
  4139. dev_dbg(codec->dev, "%s: event called! codec name %s\n",
  4140. __func__, w->codec->name);
  4141. dev_dbg(codec->dev, "%s: num_dai %d stream name %s\n",
  4142. __func__, w->codec->num_dai, w->sname);
  4143. /* Execute the callback only if interface type is slimbus */
  4144. if (tapan_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS)
  4145. return 0;
  4146. dev_dbg(codec->dev, "%s(): w->name %s event %d w->shift %d\n",
  4147. __func__, w->name, event, w->shift);
  4148. dai = &tapan_p->dai[w->shift];
  4149. switch (event) {
  4150. case SND_SOC_DAPM_POST_PMU:
  4151. dai->bus_down_in_recovery = false;
  4152. (void) tapan_codec_enable_slim_chmask(dai, true);
  4153. ret = wcd9xxx_cfg_slim_sch_tx(core, &dai->wcd9xxx_ch_list,
  4154. dai->rate, dai->bit_width,
  4155. &dai->grph);
  4156. #if defined(CONFIG_SND_SOC_ES705)
  4157. ret = remote_cfg_slim_tx(w->shift);
  4158. #elif defined(CONFIG_SND_SOC_ES325_ATLANTIC)
  4159. ret = es325_remote_cfg_slim_tx(w->shift);
  4160. #endif
  4161. break;
  4162. case SND_SOC_DAPM_POST_PMD:
  4163. #if defined(CONFIG_SND_SOC_ES705)
  4164. ret = remote_close_slim_tx(w->shift);
  4165. #elif defined(CONFIG_SND_SOC_ES325_ATLANTIC)
  4166. ret = es325_remote_close_slim_tx(w->shift);
  4167. #endif
  4168. ret = wcd9xxx_close_slim_sch_tx(core, &dai->wcd9xxx_ch_list,
  4169. dai->grph);
  4170. if (!dai->bus_down_in_recovery)
  4171. ret = tapan_codec_enable_slim_chmask(dai, false);
  4172. if (ret < 0) {
  4173. ret = wcd9xxx_disconnect_port(core,
  4174. &dai->wcd9xxx_ch_list,
  4175. dai->grph);
  4176. dev_dbg(codec->dev, "%s: Disconnect RX port, ret = %d\n",
  4177. __func__, ret);
  4178. }
  4179. if ((core != NULL) &&
  4180. (core->dev != NULL) &&
  4181. (core->dev->parent != NULL)) {
  4182. pm_runtime_mark_last_busy(core->dev->parent);
  4183. pm_runtime_put(core->dev->parent);
  4184. dev_dbg(codec->dev, "%s: unvote requested", __func__);
  4185. }
  4186. dai->bus_down_in_recovery = false;
  4187. break;
  4188. }
  4189. return ret;
  4190. }
  4191. static int tapan_codec_enable_ear_pa(struct snd_soc_dapm_widget *w,
  4192. struct snd_kcontrol *kcontrol, int event)
  4193. {
  4194. struct snd_soc_codec *codec = w->codec;
  4195. struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec);
  4196. dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
  4197. switch (event) {
  4198. case SND_SOC_DAPM_POST_PMU:
  4199. wcd9xxx_clsh_fsm(codec, &tapan_p->clsh_d,
  4200. WCD9XXX_CLSH_STATE_EAR,
  4201. WCD9XXX_CLSH_REQ_ENABLE,
  4202. WCD9XXX_CLSH_EVENT_POST_PA);
  4203. usleep_range(5000, 5010);
  4204. break;
  4205. case SND_SOC_DAPM_POST_PMD:
  4206. usleep_range(5000, 5010);
  4207. snd_soc_update_bits(codec, TAPAN_A_RX_EAR_EN, 0x40, 0x00);
  4208. wcd9xxx_clsh_fsm(codec, &tapan_p->clsh_d,
  4209. WCD9XXX_CLSH_STATE_EAR,
  4210. WCD9XXX_CLSH_REQ_DISABLE,
  4211. WCD9XXX_CLSH_EVENT_POST_PA);
  4212. }
  4213. return 0;
  4214. }
  4215. static int tapan_codec_ear_dac_event(struct snd_soc_dapm_widget *w,
  4216. struct snd_kcontrol *kcontrol, int event)
  4217. {
  4218. struct snd_soc_codec *codec = w->codec;
  4219. struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec);
  4220. dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
  4221. switch (event) {
  4222. case SND_SOC_DAPM_PRE_PMU:
  4223. wcd9xxx_clsh_fsm(codec, &tapan_p->clsh_d,
  4224. WCD9XXX_CLSH_STATE_EAR,
  4225. WCD9XXX_CLSH_REQ_ENABLE,
  4226. WCD9XXX_CLSH_EVENT_PRE_DAC);
  4227. break;
  4228. }
  4229. return 0;
  4230. }
  4231. static int tapan_codec_iir_mux_event(struct snd_soc_dapm_widget *w,
  4232. struct snd_kcontrol *kcontrol, int event)
  4233. {
  4234. struct snd_soc_codec *codec = w->codec;
  4235. pr_debug("%s: event = %d\n", __func__, event);
  4236. switch (event) {
  4237. case SND_SOC_DAPM_POST_PMU:
  4238. snd_soc_write(codec, w->reg, snd_soc_read(codec, w->reg));
  4239. break;
  4240. case SND_SOC_DAPM_POST_PMD:
  4241. snd_soc_write(codec, w->reg, snd_soc_read(codec, w->reg));
  4242. break;
  4243. }
  4244. return 0;
  4245. }
  4246. static int tapan_codec_dsm_mux_event(struct snd_soc_dapm_widget *w,
  4247. struct snd_kcontrol *kcontrol, int event)
  4248. {
  4249. struct snd_soc_codec *codec = w->codec;
  4250. u8 reg_val, zoh_mux_val = 0x00;
  4251. dev_dbg(codec->dev, "%s: event = %d\n", __func__, event);
  4252. switch (event) {
  4253. case SND_SOC_DAPM_POST_PMU:
  4254. reg_val = snd_soc_read(codec, TAPAN_A_CDC_CONN_CLSH_CTL);
  4255. if ((reg_val & 0x30) == 0x10)
  4256. zoh_mux_val = 0x04;
  4257. else if ((reg_val & 0x30) == 0x20)
  4258. zoh_mux_val = 0x08;
  4259. if (zoh_mux_val != 0x00)
  4260. snd_soc_update_bits(codec,
  4261. TAPAN_A_CDC_CONN_CLSH_CTL,
  4262. 0x0C, zoh_mux_val);
  4263. break;
  4264. case SND_SOC_DAPM_POST_PMD:
  4265. snd_soc_update_bits(codec, TAPAN_A_CDC_CONN_CLSH_CTL,
  4266. 0x0C, 0x00);
  4267. break;
  4268. }
  4269. return 0;
  4270. }
  4271. static int tapan_codec_enable_anc_ear(struct snd_soc_dapm_widget *w,
  4272. struct snd_kcontrol *kcontrol, int event)
  4273. {
  4274. struct snd_soc_codec *codec = w->codec;
  4275. int ret = 0;
  4276. switch (event) {
  4277. case SND_SOC_DAPM_PRE_PMU:
  4278. ret = tapan_codec_enable_anc(w, kcontrol, event);
  4279. msleep(50);
  4280. snd_soc_update_bits(codec, TAPAN_A_RX_EAR_EN, 0x10, 0x10);
  4281. break;
  4282. case SND_SOC_DAPM_POST_PMU:
  4283. ret = tapan_codec_enable_ear_pa(w, kcontrol, event);
  4284. break;
  4285. case SND_SOC_DAPM_PRE_PMD:
  4286. snd_soc_update_bits(codec, TAPAN_A_RX_EAR_EN, 0x10, 0x00);
  4287. msleep(40);
  4288. ret |= tapan_codec_enable_anc(w, kcontrol, event);
  4289. break;
  4290. case SND_SOC_DAPM_POST_PMD:
  4291. ret = tapan_codec_enable_ear_pa(w, kcontrol, event);
  4292. break;
  4293. }
  4294. return ret;
  4295. }
  4296. static int tapan_codec_chargepump_vdd_event(struct snd_soc_dapm_widget *w,
  4297. struct snd_kcontrol *kcontrol, int event)
  4298. {
  4299. struct snd_soc_codec *codec = w->codec;
  4300. struct tapan_priv *priv = snd_soc_codec_get_drvdata(codec);
  4301. int ret = 0, i;
  4302. pr_info("%s: event = %d\n", __func__, event);
  4303. if (!priv->cp_regulators[CP_REG_BUCK]
  4304. && !priv->cp_regulators[CP_REG_BHELPER]) {
  4305. pr_err("%s: No power supply defined for ChargePump\n",
  4306. __func__);
  4307. return -EINVAL;
  4308. }
  4309. switch (event) {
  4310. case SND_SOC_DAPM_PRE_PMU:
  4311. for (i = 0; i < CP_REG_MAX ; i++) {
  4312. if (!priv->cp_regulators[i])
  4313. continue;
  4314. ret = regulator_enable(priv->cp_regulators[i]);
  4315. if (ret) {
  4316. pr_err("%s: CP Regulator enable failed, index = %d\n",
  4317. __func__, i);
  4318. continue;
  4319. } else {
  4320. pr_debug("%s: Enabled CP regulator, index %d\n",
  4321. __func__, i);
  4322. }
  4323. }
  4324. break;
  4325. case SND_SOC_DAPM_POST_PMD:
  4326. for (i = 0; i < CP_REG_MAX; i++) {
  4327. if (!priv->cp_regulators[i])
  4328. continue;
  4329. ret = regulator_disable(priv->cp_regulators[i]);
  4330. if (ret) {
  4331. pr_err("%s: CP Regulator disable failed, index = %d\n",
  4332. __func__, i);
  4333. return ret;
  4334. } else {
  4335. pr_debug("%s: Disabled CP regulator %d\n",
  4336. __func__, i);
  4337. }
  4338. }
  4339. break;
  4340. }
  4341. return 0;
  4342. }
  4343. static int tapan_codec_set_iir_gain(struct snd_soc_dapm_widget *w,
  4344. struct snd_kcontrol *kcontrol, int event)
  4345. {
  4346. struct snd_soc_codec *codec = w->codec;
  4347. int value = 0;
  4348. switch (event) {
  4349. case SND_SOC_DAPM_POST_PMU:
  4350. value = snd_soc_read(codec, TAPAN_A_CDC_IIR1_GAIN_B1_CTL);
  4351. snd_soc_write(codec, TAPAN_A_CDC_IIR1_GAIN_B1_CTL, value);
  4352. break;
  4353. default:
  4354. pr_err("%s: event = %d not expected\n", __func__, event);
  4355. }
  4356. return 0;
  4357. }
  4358. static const struct snd_soc_dapm_widget tapan_9306_dapm_widgets[] = {
  4359. /* RX4 MIX1 mux inputs */
  4360. SND_SOC_DAPM_MUX("RX4 MIX1 INP1", SND_SOC_NOPM, 0, 0,
  4361. &rx4_mix1_inp1_mux),
  4362. SND_SOC_DAPM_MUX("RX4 MIX1 INP2", SND_SOC_NOPM, 0, 0,
  4363. &rx4_mix1_inp2_mux),
  4364. SND_SOC_DAPM_MUX("RX4 MIX1 INP3", SND_SOC_NOPM, 0, 0,
  4365. &rx4_mix1_inp3_mux),
  4366. /* RX4 MIX2 mux inputs */
  4367. SND_SOC_DAPM_MUX("RX4 MIX2 INP1", SND_SOC_NOPM, 0, 0,
  4368. &rx4_mix2_inp1_mux),
  4369. SND_SOC_DAPM_MUX("RX4 MIX2 INP2", SND_SOC_NOPM, 0, 0,
  4370. &rx4_mix2_inp2_mux),
  4371. SND_SOC_DAPM_MIXER("RX4 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  4372. SND_SOC_DAPM_MIXER_E("RX4 MIX2", TAPAN_A_CDC_CLK_RX_B1_CTL, 3, 0, NULL,
  4373. 0, tapan_codec_enable_interpolator, SND_SOC_DAPM_PRE_PMU |
  4374. SND_SOC_DAPM_POST_PMU),
  4375. SND_SOC_DAPM_MUX_E("DEC3 MUX", TAPAN_A_CDC_CLK_TX_CLK_EN_B1_CTL, 2, 0,
  4376. &dec3_mux, tapan_codec_enable_dec,
  4377. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  4378. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  4379. SND_SOC_DAPM_MUX_E("DEC4 MUX", TAPAN_A_CDC_CLK_TX_CLK_EN_B1_CTL, 3, 0,
  4380. &dec4_mux, tapan_codec_enable_dec,
  4381. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  4382. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  4383. SND_SOC_DAPM_SUPPLY("COMP0_CLK", SND_SOC_NOPM, 0, 0,
  4384. tapan_config_compander, SND_SOC_DAPM_PRE_PMU |
  4385. SND_SOC_DAPM_PRE_PMD),
  4386. SND_SOC_DAPM_SUPPLY("COMP1_CLK", SND_SOC_NOPM, 1, 0,
  4387. tapan_config_compander, SND_SOC_DAPM_PRE_PMU |
  4388. SND_SOC_DAPM_PRE_PMD),
  4389. SND_SOC_DAPM_SUPPLY("COMP2_CLK", SND_SOC_NOPM, 2, 0,
  4390. tapan_config_compander, SND_SOC_DAPM_PRE_PMU |
  4391. SND_SOC_DAPM_PRE_PMD),
  4392. SND_SOC_DAPM_INPUT("AMIC5"),
  4393. SND_SOC_DAPM_ADC_E("ADC5", NULL, TAPAN_A_TX_5_EN, 7, 0,
  4394. tapan_codec_enable_adc, SND_SOC_DAPM_POST_PMU),
  4395. SND_SOC_DAPM_MUX("ANC1 MUX", SND_SOC_NOPM, 0, 0, &anc1_mux),
  4396. SND_SOC_DAPM_MUX("ANC2 MUX", SND_SOC_NOPM, 0, 0, &anc2_mux),
  4397. SND_SOC_DAPM_OUTPUT("ANC HEADPHONE"),
  4398. SND_SOC_DAPM_PGA_E("ANC HPHL", SND_SOC_NOPM, 5, 0, NULL, 0,
  4399. tapan_codec_enable_anc_hph,
  4400. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD |
  4401. SND_SOC_DAPM_POST_PMD | SND_SOC_DAPM_POST_PMU),
  4402. SND_SOC_DAPM_PGA_E("ANC HPHR", SND_SOC_NOPM, 4, 0, NULL, 0,
  4403. tapan_codec_enable_anc_hph, SND_SOC_DAPM_PRE_PMU |
  4404. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD |
  4405. SND_SOC_DAPM_POST_PMU),
  4406. SND_SOC_DAPM_OUTPUT("ANC EAR"),
  4407. SND_SOC_DAPM_PGA_E("ANC EAR PA", SND_SOC_NOPM, 0, 0, NULL, 0,
  4408. tapan_codec_enable_anc_ear,
  4409. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD |
  4410. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4411. SND_SOC_DAPM_MUX("ANC1 FB MUX", SND_SOC_NOPM, 0, 0, &anc1_fb_mux),
  4412. SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 External", SND_SOC_NOPM, 3, 0,
  4413. tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
  4414. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4415. SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 Internal1", SND_SOC_NOPM, 3, 0,
  4416. tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
  4417. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4418. SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 Internal2", SND_SOC_NOPM, 3, 0,
  4419. tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
  4420. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4421. SND_SOC_DAPM_ADC_E("DMIC3", NULL, SND_SOC_NOPM, 0, 0,
  4422. tapan_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  4423. SND_SOC_DAPM_POST_PMD),
  4424. SND_SOC_DAPM_ADC_E("DMIC4", NULL, SND_SOC_NOPM, 0, 0,
  4425. tapan_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  4426. SND_SOC_DAPM_POST_PMD),
  4427. };
  4428. /* Todo: Have seperate dapm widgets for I2S and Slimbus.
  4429. * Might Need to have callbacks registered only for slimbus
  4430. */
  4431. static const struct snd_soc_dapm_widget tapan_common_dapm_widgets[] = {
  4432. SND_SOC_DAPM_AIF_IN_E("AIF1 PB", "AIF1 Playback", 0, SND_SOC_NOPM,
  4433. AIF1_PB, 0, tapan_codec_enable_slimrx,
  4434. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4435. SND_SOC_DAPM_AIF_IN_E("AIF2 PB", "AIF2 Playback", 0, SND_SOC_NOPM,
  4436. AIF2_PB, 0, tapan_codec_enable_slimrx,
  4437. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4438. SND_SOC_DAPM_AIF_IN_E("AIF3 PB", "AIF3 Playback", 0, SND_SOC_NOPM,
  4439. AIF3_PB, 0, tapan_codec_enable_slimrx,
  4440. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4441. SND_SOC_DAPM_MUX("SLIM RX1 MUX", SND_SOC_NOPM, TAPAN_RX1, 0,
  4442. &slim_rx_mux[TAPAN_RX1]),
  4443. SND_SOC_DAPM_MUX("SLIM RX2 MUX", SND_SOC_NOPM, TAPAN_RX2, 0,
  4444. &slim_rx_mux[TAPAN_RX2]),
  4445. SND_SOC_DAPM_MUX("SLIM RX3 MUX", SND_SOC_NOPM, TAPAN_RX3, 0,
  4446. &slim_rx_mux[TAPAN_RX3]),
  4447. SND_SOC_DAPM_MUX("SLIM RX4 MUX", SND_SOC_NOPM, TAPAN_RX4, 0,
  4448. &slim_rx_mux[TAPAN_RX4]),
  4449. SND_SOC_DAPM_MUX("SLIM RX5 MUX", SND_SOC_NOPM, TAPAN_RX5, 0,
  4450. &slim_rx_mux[TAPAN_RX5]),
  4451. SND_SOC_DAPM_MIXER("SLIM RX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  4452. SND_SOC_DAPM_MIXER("SLIM RX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  4453. SND_SOC_DAPM_MIXER("SLIM RX3", SND_SOC_NOPM, 0, 0, NULL, 0),
  4454. SND_SOC_DAPM_MIXER("SLIM RX4", SND_SOC_NOPM, 0, 0, NULL, 0),
  4455. SND_SOC_DAPM_MIXER("SLIM RX5", SND_SOC_NOPM, 0, 0, NULL, 0),
  4456. /* RX1 MIX1 mux inputs */
  4457. SND_SOC_DAPM_MUX("RX1 MIX1 INP1", SND_SOC_NOPM, 0, 0,
  4458. &rx_mix1_inp1_mux),
  4459. SND_SOC_DAPM_MUX("RX1 MIX1 INP2", SND_SOC_NOPM, 0, 0,
  4460. &rx_mix1_inp2_mux),
  4461. SND_SOC_DAPM_MUX("RX1 MIX1 INP3", SND_SOC_NOPM, 0, 0,
  4462. &rx_mix1_inp3_mux),
  4463. /* RX2 MIX1 mux inputs */
  4464. SND_SOC_DAPM_MUX("RX2 MIX1 INP1", SND_SOC_NOPM, 0, 0,
  4465. &rx2_mix1_inp1_mux),
  4466. SND_SOC_DAPM_MUX("RX2 MIX1 INP2", SND_SOC_NOPM, 0, 0,
  4467. &rx2_mix1_inp2_mux),
  4468. SND_SOC_DAPM_MUX("RX2 MIX1 INP3", SND_SOC_NOPM, 0, 0,
  4469. &rx2_mix1_inp2_mux),
  4470. /* RX3 MIX1 mux inputs */
  4471. SND_SOC_DAPM_MUX("RX3 MIX1 INP1", SND_SOC_NOPM, 0, 0,
  4472. &rx3_mix1_inp1_mux),
  4473. SND_SOC_DAPM_MUX("RX3 MIX1 INP2", SND_SOC_NOPM, 0, 0,
  4474. &rx3_mix1_inp2_mux),
  4475. SND_SOC_DAPM_MUX("RX3 MIX1 INP3", SND_SOC_NOPM, 0, 0,
  4476. &rx3_mix1_inp3_mux),
  4477. /* RX1 MIX2 mux inputs */
  4478. SND_SOC_DAPM_MUX("RX1 MIX2 INP1", SND_SOC_NOPM, 0, 0,
  4479. &rx1_mix2_inp1_mux),
  4480. SND_SOC_DAPM_MUX("RX1 MIX2 INP2", SND_SOC_NOPM, 0, 0,
  4481. &rx1_mix2_inp2_mux),
  4482. /* RX2 MIX2 mux inputs */
  4483. SND_SOC_DAPM_MUX("RX2 MIX2 INP1", SND_SOC_NOPM, 0, 0,
  4484. &rx2_mix2_inp1_mux),
  4485. SND_SOC_DAPM_MUX("RX2 MIX2 INP2", SND_SOC_NOPM, 0, 0,
  4486. &rx2_mix2_inp2_mux),
  4487. SND_SOC_DAPM_MIXER("RX1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  4488. SND_SOC_DAPM_MIXER("RX2 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  4489. SND_SOC_DAPM_MIXER("RX1 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  4490. SND_SOC_DAPM_MIXER("RX2 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  4491. SND_SOC_DAPM_MIXER_E("RX3 MIX1", TAPAN_A_CDC_CLK_RX_B1_CTL, 2, 0, NULL,
  4492. 0, tapan_codec_enable_interpolator, SND_SOC_DAPM_PRE_PMU |
  4493. SND_SOC_DAPM_POST_PMU),
  4494. SND_SOC_DAPM_VIRT_MUX_E("RX1 INTERPOLATOR",
  4495. TAPAN_A_CDC_CLK_RX_B1_CTL, 0, 0,
  4496. &rx1_interpolator, tapan_codec_enable_interpolator,
  4497. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU),
  4498. SND_SOC_DAPM_VIRT_MUX_E("RX2 INTERPOLATOR",
  4499. TAPAN_A_CDC_CLK_RX_B1_CTL, 1, 0,
  4500. &rx2_interpolator, tapan_codec_enable_interpolator,
  4501. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU),
  4502. SND_SOC_DAPM_MIXER("RX1 CHAIN", TAPAN_A_CDC_RX1_B6_CTL, 5, 0,
  4503. NULL, 0),
  4504. SND_SOC_DAPM_MIXER_E("RX2 CHAIN", SND_SOC_NOPM, 0, 0, NULL,
  4505. 0, tapan_codec_rx_dem_select, SND_SOC_DAPM_PRE_PMU |
  4506. SND_SOC_DAPM_POST_PMD),
  4507. SND_SOC_DAPM_MUX_E("CLASS_H_DSM MUX", SND_SOC_NOPM, 0, 0,
  4508. &class_h_dsm_mux, tapan_codec_dsm_mux_event,
  4509. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4510. /* RX Bias */
  4511. SND_SOC_DAPM_SUPPLY("RX_BIAS", SND_SOC_NOPM, 0, 0,
  4512. tapan_codec_enable_rx_bias, SND_SOC_DAPM_PRE_PMU |
  4513. SND_SOC_DAPM_POST_PMD),
  4514. /* CDC_CP_VDD */
  4515. SND_SOC_DAPM_SUPPLY("CDC_CP_VDD", SND_SOC_NOPM, 0, 0,
  4516. tapan_codec_chargepump_vdd_event, SND_SOC_DAPM_PRE_PMU |
  4517. SND_SOC_DAPM_POST_PMD),
  4518. /*EAR */
  4519. SND_SOC_DAPM_PGA_E("EAR PA", TAPAN_A_RX_EAR_EN, 4, 0, NULL, 0,
  4520. tapan_codec_enable_ear_pa, SND_SOC_DAPM_POST_PMU |
  4521. SND_SOC_DAPM_POST_PMD),
  4522. SND_SOC_DAPM_MIXER_E("DAC1", TAPAN_A_RX_EAR_EN, 6, 0, dac1_switch,
  4523. ARRAY_SIZE(dac1_switch), tapan_codec_ear_dac_event,
  4524. SND_SOC_DAPM_PRE_PMU),
  4525. /* Headphone Left */
  4526. SND_SOC_DAPM_PGA_E("HPHL", TAPAN_A_RX_HPH_CNP_EN, 5, 0, NULL, 0,
  4527. tapan_hph_pa_event, SND_SOC_DAPM_PRE_PMU |
  4528. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4529. SND_SOC_DAPM_MIXER_E("HPHL DAC", TAPAN_A_RX_HPH_L_DAC_CTL, 7, 0,
  4530. hphl_switch, ARRAY_SIZE(hphl_switch), tapan_hphl_dac_event,
  4531. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  4532. /* Headphone Right */
  4533. SND_SOC_DAPM_PGA_E("HPHR", TAPAN_A_RX_HPH_CNP_EN, 4, 0, NULL, 0,
  4534. tapan_hph_pa_event, SND_SOC_DAPM_PRE_PMU |
  4535. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4536. SND_SOC_DAPM_DAC_E("HPHR DAC", NULL, TAPAN_A_RX_HPH_R_DAC_CTL, 7, 0,
  4537. tapan_hphr_dac_event,
  4538. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  4539. /* LINEOUT1*/
  4540. SND_SOC_DAPM_DAC_E("LINEOUT1 DAC", NULL, TAPAN_A_RX_LINE_1_DAC_CTL, 7, 0
  4541. , tapan_lineout_dac_event,
  4542. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  4543. SND_SOC_DAPM_PGA_E("LINEOUT1 PA", TAPAN_A_RX_LINE_CNP_EN, 0, 0, NULL,
  4544. 0, tapan_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
  4545. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4546. /* LINEOUT2*/
  4547. SND_SOC_DAPM_MUX("RDAC5 MUX", SND_SOC_NOPM, 0, 0,
  4548. &rx_dac5_mux),
  4549. /* LINEOUT1*/
  4550. SND_SOC_DAPM_MUX("RDAC4 MUX", SND_SOC_NOPM, 0, 0,
  4551. &rx_dac4_mux),
  4552. SND_SOC_DAPM_MUX("RDAC3 MUX", SND_SOC_NOPM, 0, 0,
  4553. &rx_dac3_mux),
  4554. SND_SOC_DAPM_DAC_E("LINEOUT2 DAC", NULL, TAPAN_A_RX_LINE_2_DAC_CTL, 7, 0
  4555. , tapan_lineout_dac_event,
  4556. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  4557. SND_SOC_DAPM_PGA_E("LINEOUT2 PA", TAPAN_A_RX_LINE_CNP_EN, 1, 0, NULL,
  4558. 0, tapan_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
  4559. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4560. /* CLASS-D SPK */
  4561. SND_SOC_DAPM_MIXER_E("SPK DAC", SND_SOC_NOPM, 0, 0,
  4562. spk_dac_switch, ARRAY_SIZE(spk_dac_switch), tapan_spk_dac_event,
  4563. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  4564. SND_SOC_DAPM_PGA_E("SPK PA", SND_SOC_NOPM, 0, 0 , NULL,
  4565. 0, tapan_codec_enable_spk_pa,
  4566. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  4567. SND_SOC_DAPM_SUPPLY("VDD_SPKDRV", SND_SOC_NOPM, 0, 0,
  4568. tapan_codec_enable_vdd_spkr,
  4569. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  4570. SND_SOC_DAPM_OUTPUT("EAR"),
  4571. SND_SOC_DAPM_OUTPUT("HEADPHONE"),
  4572. SND_SOC_DAPM_OUTPUT("LINEOUT1"),
  4573. SND_SOC_DAPM_OUTPUT("LINEOUT2"),
  4574. SND_SOC_DAPM_OUTPUT("SPK_OUT"),
  4575. /* TX Path*/
  4576. SND_SOC_DAPM_MIXER("AIF1_CAP Mixer", SND_SOC_NOPM, AIF1_CAP, 0,
  4577. aif_cap_mixer, ARRAY_SIZE(aif_cap_mixer)),
  4578. SND_SOC_DAPM_MIXER("AIF2_CAP Mixer", SND_SOC_NOPM, AIF2_CAP, 0,
  4579. aif_cap_mixer, ARRAY_SIZE(aif_cap_mixer)),
  4580. SND_SOC_DAPM_MIXER("AIF3_CAP Mixer", SND_SOC_NOPM, AIF3_CAP, 0,
  4581. aif_cap_mixer, ARRAY_SIZE(aif_cap_mixer)),
  4582. SND_SOC_DAPM_MUX("SLIM TX1 MUX", SND_SOC_NOPM, TAPAN_TX1, 0,
  4583. &sb_tx1_mux),
  4584. SND_SOC_DAPM_MUX("SLIM TX2 MUX", SND_SOC_NOPM, TAPAN_TX2, 0,
  4585. &sb_tx2_mux),
  4586. SND_SOC_DAPM_MUX("SLIM TX3 MUX", SND_SOC_NOPM, TAPAN_TX3, 0,
  4587. &sb_tx3_mux),
  4588. SND_SOC_DAPM_MUX("SLIM TX4 MUX", SND_SOC_NOPM, TAPAN_TX4, 0,
  4589. &sb_tx4_mux),
  4590. SND_SOC_DAPM_MUX("SLIM TX5 MUX", SND_SOC_NOPM, TAPAN_TX5, 0,
  4591. &sb_tx5_mux),
  4592. SND_SOC_DAPM_SUPPLY("CDC_CONN", WCD9XXX_A_CDC_CLK_OTHR_CTL, 2, 0, NULL,
  4593. 0),
  4594. /* Decimator MUX */
  4595. SND_SOC_DAPM_MUX_E("DEC1 MUX", TAPAN_A_CDC_CLK_TX_CLK_EN_B1_CTL, 0, 0,
  4596. &dec1_mux, tapan_codec_enable_dec,
  4597. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  4598. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  4599. SND_SOC_DAPM_MUX_E("DEC2 MUX", TAPAN_A_CDC_CLK_TX_CLK_EN_B1_CTL, 1, 0,
  4600. &dec2_mux, tapan_codec_enable_dec,
  4601. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  4602. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  4603. SND_SOC_DAPM_SUPPLY("LDO_H", SND_SOC_NOPM, 0, 0,
  4604. tapan_codec_enable_ldo_h, SND_SOC_DAPM_POST_PMU |
  4605. SND_SOC_DAPM_POST_PMD),
  4606. #ifndef CONFIG_ARCH_MSM8226
  4607. /*
  4608. * DAPM 'LDO_H Standalone' is to be powered by mbhc driver after
  4609. * acquring codec_resource lock.
  4610. * So call __tapan_codec_enable_ldo_h instead and avoid deadlock.
  4611. */
  4612. SND_SOC_DAPM_SUPPLY("LDO_H Standalone", SND_SOC_NOPM, 7, 0,
  4613. __tapan_codec_enable_ldo_h,
  4614. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  4615. #endif
  4616. SND_SOC_DAPM_INPUT("AMIC1"),
  4617. SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 External", SND_SOC_NOPM, 1, 0,
  4618. tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
  4619. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4620. SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 Internal1", SND_SOC_NOPM, 1, 0,
  4621. tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
  4622. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4623. SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 Internal2", SND_SOC_NOPM, 1, 0,
  4624. tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
  4625. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4626. SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Power External",
  4627. SND_SOC_NOPM, 2, 0,
  4628. tapan_codec_enable_micbias_power,
  4629. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  4630. SND_SOC_DAPM_POST_PMD),
  4631. SND_SOC_DAPM_ADC_E("ADC1", NULL, TAPAN_A_TX_1_EN, 7, 0,
  4632. tapan_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
  4633. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4634. SND_SOC_DAPM_ADC_E("ADC2", NULL, TAPAN_A_TX_2_EN, 7, 0,
  4635. tapan_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
  4636. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4637. SND_SOC_DAPM_INPUT("AMIC3"),
  4638. SND_SOC_DAPM_ADC_E("ADC3", NULL, TAPAN_A_TX_3_EN, 7, 0,
  4639. tapan_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
  4640. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4641. SND_SOC_DAPM_INPUT("AMIC4"),
  4642. SND_SOC_DAPM_ADC_E("ADC4", NULL, TAPAN_A_TX_4_EN, 7, 0,
  4643. tapan_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
  4644. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4645. SND_SOC_DAPM_INPUT("AMIC2"),
  4646. SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 External", SND_SOC_NOPM, 2, 0,
  4647. tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
  4648. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4649. SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal1", SND_SOC_NOPM, 2, 0,
  4650. tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
  4651. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4652. SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal2", SND_SOC_NOPM, 2, 0,
  4653. tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
  4654. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4655. SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal3", SND_SOC_NOPM, 2, 0,
  4656. tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
  4657. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4658. #ifndef CONFIG_ARCH_MSM8226
  4659. SND_SOC_DAPM_MICBIAS_E(DAPM_MICBIAS2_EXTERNAL_STANDALONE, SND_SOC_NOPM,
  4660. 7, 0, tapan_codec_enable_micbias,
  4661. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  4662. SND_SOC_DAPM_POST_PMD),
  4663. #endif
  4664. SND_SOC_DAPM_AIF_OUT_E("AIF1 CAP", "AIF1 Capture", 0, SND_SOC_NOPM,
  4665. AIF1_CAP, 0, tapan_codec_enable_slimtx,
  4666. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4667. SND_SOC_DAPM_AIF_OUT_E("AIF2 CAP", "AIF2 Capture", 0, SND_SOC_NOPM,
  4668. AIF2_CAP, 0, tapan_codec_enable_slimtx,
  4669. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4670. SND_SOC_DAPM_AIF_OUT_E("AIF3 CAP", "AIF3 Capture", 0, SND_SOC_NOPM,
  4671. AIF3_CAP, 0, tapan_codec_enable_slimtx,
  4672. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4673. /* Digital Mic Inputs */
  4674. SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 0, 0,
  4675. tapan_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  4676. SND_SOC_DAPM_POST_PMD),
  4677. SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 0, 0,
  4678. tapan_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  4679. SND_SOC_DAPM_POST_PMD),
  4680. /* Sidetone */
  4681. //SND_SOC_DAPM_MUX("IIR1 INP1 MUX", SND_SOC_NOPM, 0, 0, &iir1_inp1_mux),
  4682. SND_SOC_DAPM_MUX_E("IIR1 INP1 MUX", TAPAN_A_CDC_IIR1_GAIN_B1_CTL, 0, 0,&iir1_inp1_mux, tapan_codec_iir_mux_event,SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4683. //SND_SOC_DAPM_PGA("IIR1", TAPAN_A_CDC_CLK_SD_CTL, 0, 0, NULL, 0),
  4684. SND_SOC_DAPM_PGA_E("IIR1", TAPAN_A_CDC_CLK_SD_CTL, 0, 0, NULL, 0,tapan_codec_set_iir_gain, SND_SOC_DAPM_POST_PMU),
  4685. SND_SOC_DAPM_MUX_E("IIR1 INP2 MUX", TAPAN_A_CDC_IIR1_GAIN_B2_CTL, 0, 0,
  4686. &iir1_inp2_mux, tapan_codec_iir_mux_event,
  4687. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4688. SND_SOC_DAPM_MUX_E("IIR1 INP3 MUX", TAPAN_A_CDC_IIR1_GAIN_B3_CTL, 0, 0,
  4689. &iir1_inp3_mux, tapan_codec_iir_mux_event,
  4690. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4691. SND_SOC_DAPM_MUX_E("IIR1 INP4 MUX", TAPAN_A_CDC_IIR1_GAIN_B4_CTL, 0, 0,
  4692. &iir1_inp4_mux, tapan_codec_iir_mux_event,
  4693. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4694. SND_SOC_DAPM_MUX_E("IIR2 INP1 MUX", TAPAN_A_CDC_IIR2_GAIN_B1_CTL, 0, 0,
  4695. &iir2_inp1_mux, tapan_codec_iir_mux_event,
  4696. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4697. SND_SOC_DAPM_MUX_E("IIR2 INP2 MUX", TAPAN_A_CDC_IIR2_GAIN_B2_CTL, 0, 0,
  4698. &iir2_inp2_mux, tapan_codec_iir_mux_event,
  4699. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4700. SND_SOC_DAPM_MUX_E("IIR2 INP3 MUX", TAPAN_A_CDC_IIR2_GAIN_B3_CTL, 0, 0,
  4701. &iir2_inp3_mux, tapan_codec_iir_mux_event,
  4702. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4703. SND_SOC_DAPM_MUX_E("IIR2 INP4 MUX", TAPAN_A_CDC_IIR2_GAIN_B4_CTL, 0, 0,
  4704. &iir2_inp4_mux, tapan_codec_iir_mux_event,
  4705. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  4706. SND_SOC_DAPM_PGA("IIR2", TAPAN_A_CDC_CLK_SD_CTL, 1, 0, NULL, 0),
  4707. /* AUX PGA */
  4708. SND_SOC_DAPM_ADC_E("AUX_PGA_Left", NULL, TAPAN_A_RX_AUX_SW_CTL, 7, 0,
  4709. tapan_codec_enable_aux_pga, SND_SOC_DAPM_PRE_PMU |
  4710. SND_SOC_DAPM_POST_PMD),
  4711. SND_SOC_DAPM_ADC_E("AUX_PGA_Right", NULL, TAPAN_A_RX_AUX_SW_CTL, 6, 0,
  4712. tapan_codec_enable_aux_pga, SND_SOC_DAPM_PRE_PMU |
  4713. SND_SOC_DAPM_POST_PMD),
  4714. /* Lineout, ear and HPH PA Mixers */
  4715. SND_SOC_DAPM_MIXER("EAR_PA_MIXER", SND_SOC_NOPM, 0, 0,
  4716. ear_pa_mix, ARRAY_SIZE(ear_pa_mix)),
  4717. SND_SOC_DAPM_MIXER("HPHL_PA_MIXER", SND_SOC_NOPM, 0, 0,
  4718. hphl_pa_mix, ARRAY_SIZE(hphl_pa_mix)),
  4719. SND_SOC_DAPM_MIXER("HPHR_PA_MIXER", SND_SOC_NOPM, 0, 0,
  4720. hphr_pa_mix, ARRAY_SIZE(hphr_pa_mix)),
  4721. SND_SOC_DAPM_MIXER("LINEOUT1_PA_MIXER", SND_SOC_NOPM, 0, 0,
  4722. lineout1_pa_mix, ARRAY_SIZE(lineout1_pa_mix)),
  4723. SND_SOC_DAPM_MIXER("LINEOUT2_PA_MIXER", SND_SOC_NOPM, 0, 0,
  4724. lineout2_pa_mix, ARRAY_SIZE(lineout2_pa_mix)),
  4725. };
  4726. static irqreturn_t tapan_slimbus_irq(int irq, void *data)
  4727. {
  4728. struct tapan_priv *priv = data;
  4729. struct snd_soc_codec *codec = priv->codec;
  4730. unsigned long status = 0;
  4731. int i, j, port_id, k;
  4732. u32 bit;
  4733. u8 val;
  4734. bool tx, cleared;
  4735. for (i = TAPAN_SLIM_PGD_PORT_INT_STATUS_RX_0, j = 0;
  4736. i <= TAPAN_SLIM_PGD_PORT_INT_STATUS_TX_1; i++, j++) {
  4737. val = wcd9xxx_interface_reg_read(codec->control_data, i);
  4738. status |= ((u32)val << (8 * j));
  4739. }
  4740. for_each_set_bit(j, &status, 32) {
  4741. tx = (j >= 16 ? true : false);
  4742. port_id = (tx ? j - 16 : j);
  4743. val = wcd9xxx_interface_reg_read(codec->control_data,
  4744. TAPAN_SLIM_PGD_PORT_INT_RX_SOURCE0 + j);
  4745. if (val & TAPAN_SLIM_IRQ_OVERFLOW)
  4746. pr_err_ratelimited(
  4747. "%s: overflow error on %s port %d, value %x\n",
  4748. __func__, (tx ? "TX" : "RX"), port_id, val);
  4749. if (val & TAPAN_SLIM_IRQ_UNDERFLOW)
  4750. pr_err_ratelimited(
  4751. "%s: underflow error on %s port %d, value %x\n",
  4752. __func__, (tx ? "TX" : "RX"), port_id, val);
  4753. if (val & TAPAN_SLIM_IRQ_PORT_CLOSED) {
  4754. /*
  4755. * INT SOURCE register starts from RX to TX
  4756. * but port number in the ch_mask is in opposite way
  4757. */
  4758. bit = (tx ? j - 16 : j + 16);
  4759. dev_dbg(codec->dev, "%s: %s port %d closed value %x, bit %u\n",
  4760. __func__, (tx ? "TX" : "RX"), port_id, val,
  4761. bit);
  4762. for (k = 0, cleared = false; k < NUM_CODEC_DAIS; k++) {
  4763. dev_dbg(codec->dev, "%s: priv->dai[%d].ch_mask = 0x%lx\n",
  4764. __func__, k, priv->dai[k].ch_mask);
  4765. if (test_and_clear_bit(bit,
  4766. &priv->dai[k].ch_mask)) {
  4767. cleared = true;
  4768. if (!priv->dai[k].ch_mask)
  4769. wake_up(&priv->dai[k].dai_wait);
  4770. /*
  4771. * There are cases when multiple DAIs
  4772. * might be using the same slimbus
  4773. * channel. Hence don't break here.
  4774. */
  4775. }
  4776. }
  4777. WARN(!cleared,
  4778. "Couldn't find slimbus %s port %d for closing\n",
  4779. (tx ? "TX" : "RX"), port_id);
  4780. }
  4781. wcd9xxx_interface_reg_write(codec->control_data,
  4782. TAPAN_SLIM_PGD_PORT_INT_CLR_RX_0 +
  4783. (j / 8),
  4784. 1 << (j % 8));
  4785. }
  4786. return IRQ_HANDLED;
  4787. }
  4788. static int tapan_handle_pdata(struct tapan_priv *tapan)
  4789. {
  4790. struct snd_soc_codec *codec = tapan->codec;
  4791. struct wcd9xxx_pdata *pdata = tapan->resmgr.pdata;
  4792. int k1, k2, k3, rc = 0;
  4793. u8 txfe_bypass;
  4794. u8 txfe_buff;
  4795. u8 flag;
  4796. u8 i = 0, j = 0;
  4797. u8 val_txfe = 0, value = 0;
  4798. u8 dmic_sample_rate_value = 0;
  4799. u8 dmic_b1_ctl_value = 0;
  4800. u8 anc_ctl_value = 0;
  4801. if (!pdata) {
  4802. dev_err(codec->dev, "%s: NULL pdata\n", __func__);
  4803. rc = -ENODEV;
  4804. goto done;
  4805. }
  4806. txfe_bypass = pdata->amic_settings.txfe_enable;
  4807. txfe_buff = pdata->amic_settings.txfe_buff;
  4808. flag = pdata->amic_settings.use_pdata;
  4809. /* Make sure settings are correct */
  4810. if ((pdata->micbias.ldoh_v > WCD9XXX_LDOH_3P0_V) ||
  4811. (pdata->micbias.bias1_cfilt_sel > WCD9XXX_CFILT3_SEL) ||
  4812. (pdata->micbias.bias2_cfilt_sel > WCD9XXX_CFILT3_SEL) ||
  4813. (pdata->micbias.bias3_cfilt_sel > WCD9XXX_CFILT3_SEL)) {
  4814. dev_err(codec->dev, "%s: Invalid ldoh voltage or bias cfilt\n",
  4815. __func__);
  4816. rc = -EINVAL;
  4817. goto done;
  4818. }
  4819. /* figure out k value */
  4820. k1 = wcd9xxx_resmgr_get_k_val(&tapan->resmgr, pdata->micbias.cfilt1_mv);
  4821. k2 = wcd9xxx_resmgr_get_k_val(&tapan->resmgr, pdata->micbias.cfilt2_mv);
  4822. k3 = wcd9xxx_resmgr_get_k_val(&tapan->resmgr, pdata->micbias.cfilt3_mv);
  4823. if (IS_ERR_VALUE(k1) || IS_ERR_VALUE(k2) || IS_ERR_VALUE(k3)) {
  4824. dev_err(codec->dev,
  4825. "%s: could not get K value. k1 = %d k2 = %d k3 = %d\n",
  4826. __func__, k1, k2, k3);
  4827. rc = -EINVAL;
  4828. goto done;
  4829. }
  4830. /* Set voltage level and always use LDO */
  4831. snd_soc_update_bits(codec, TAPAN_A_LDO_H_MODE_1, 0x0C,
  4832. (pdata->micbias.ldoh_v << 2));
  4833. snd_soc_update_bits(codec, TAPAN_A_MICB_CFILT_1_VAL, 0xFC, (k1 << 2));
  4834. snd_soc_update_bits(codec, TAPAN_A_MICB_CFILT_2_VAL, 0xFC, (k2 << 2));
  4835. snd_soc_update_bits(codec, TAPAN_A_MICB_CFILT_3_VAL, 0xFC, (k3 << 2));
  4836. i = 0;
  4837. while (i < 5) {
  4838. if (flag & (0x01 << i)) {
  4839. val_txfe = (txfe_bypass & (0x01 << i)) ? 0x20 : 0x00;
  4840. val_txfe = val_txfe |
  4841. ((txfe_buff & (0x01 << i)) ? 0x10 : 0x00);
  4842. snd_soc_update_bits(codec,
  4843. TAPAN_A_TX_1_2_TEST_EN + j * 10,
  4844. 0x30, val_txfe);
  4845. }
  4846. if (flag & (0x01 << (i + 1))) {
  4847. val_txfe = (txfe_bypass &
  4848. (0x01 << (i + 1))) ? 0x02 : 0x00;
  4849. val_txfe |= (txfe_buff &
  4850. (0x01 << (i + 1))) ? 0x01 : 0x00;
  4851. snd_soc_update_bits(codec,
  4852. TAPAN_A_TX_1_2_TEST_EN + j * 10,
  4853. 0x03, val_txfe);
  4854. }
  4855. /* Tapan only has TAPAN_A_TX_1_2_TEST_EN and
  4856. TAPAN_A_TX_4_5_TEST_EN reg */
  4857. if (i == 0) {
  4858. i = 3;
  4859. continue;
  4860. } else if (i == 3) {
  4861. break;
  4862. }
  4863. }
  4864. if (pdata->ocp.use_pdata) {
  4865. /* not defined in CODEC specification */
  4866. if (pdata->ocp.hph_ocp_limit == 1 ||
  4867. pdata->ocp.hph_ocp_limit == 5) {
  4868. rc = -EINVAL;
  4869. goto done;
  4870. }
  4871. snd_soc_update_bits(codec, TAPAN_A_RX_COM_OCP_CTL,
  4872. 0x0F, pdata->ocp.num_attempts);
  4873. snd_soc_write(codec, TAPAN_A_RX_COM_OCP_COUNT,
  4874. ((pdata->ocp.run_time << 4) | pdata->ocp.wait_time));
  4875. snd_soc_update_bits(codec, TAPAN_A_RX_HPH_OCP_CTL,
  4876. 0xE0, (pdata->ocp.hph_ocp_limit << 5));
  4877. }
  4878. /* Set micbias capless mode with tail current */
  4879. value = (pdata->micbias.bias1_cap_mode == MICBIAS_EXT_BYP_CAP ?
  4880. 0x00 : 0x10);
  4881. snd_soc_update_bits(codec, TAPAN_A_MICB_1_CTL, 0x10, value);
  4882. value = (pdata->micbias.bias2_cap_mode == MICBIAS_EXT_BYP_CAP ?
  4883. 0x00 : 0x10);
  4884. snd_soc_update_bits(codec, TAPAN_A_MICB_2_CTL, 0x10, value);
  4885. value = (pdata->micbias.bias3_cap_mode == MICBIAS_EXT_BYP_CAP ?
  4886. 0x00 : 0x10);
  4887. snd_soc_update_bits(codec, TAPAN_A_MICB_3_CTL, 0x10, value);
  4888. /* Set the DMIC sample rate */
  4889. if (pdata->mclk_rate == TAPAN_MCLK_CLK_9P6MHZ) {
  4890. switch (pdata->dmic_sample_rate) {
  4891. case WCD9XXX_DMIC_SAMPLE_RATE_2P4MHZ:
  4892. dmic_sample_rate_value = WCD9XXX_DMIC_SAMPLE_RATE_DIV_4;
  4893. dmic_b1_ctl_value = WCD9XXX_DMIC_B1_CTL_DIV_4;
  4894. anc_ctl_value = WCD9XXX_ANC_DMIC_X2_OFF;
  4895. break;
  4896. case WCD9XXX_DMIC_SAMPLE_RATE_4P8MHZ:
  4897. dmic_sample_rate_value = WCD9XXX_DMIC_SAMPLE_RATE_DIV_2;
  4898. dmic_b1_ctl_value = WCD9XXX_DMIC_B1_CTL_DIV_2;
  4899. anc_ctl_value = WCD9XXX_ANC_DMIC_X2_ON;
  4900. break;
  4901. case WCD9XXX_DMIC_SAMPLE_RATE_3P2MHZ:
  4902. case WCD9XXX_DMIC_SAMPLE_RATE_UNDEFINED:
  4903. dmic_sample_rate_value = WCD9XXX_DMIC_SAMPLE_RATE_DIV_3;
  4904. dmic_b1_ctl_value = WCD9XXX_DMIC_B1_CTL_DIV_3;
  4905. anc_ctl_value = WCD9XXX_ANC_DMIC_X2_OFF;
  4906. break;
  4907. default:
  4908. dev_err(codec->dev,
  4909. "%s Invalid sample rate %d for mclk %d\n",
  4910. __func__, pdata->dmic_sample_rate,
  4911. pdata->mclk_rate);
  4912. rc = -EINVAL;
  4913. goto done;
  4914. }
  4915. } else if (pdata->mclk_rate == TAPAN_MCLK_CLK_12P288MHZ) {
  4916. switch (pdata->dmic_sample_rate) {
  4917. case WCD9XXX_DMIC_SAMPLE_RATE_3P072MHZ:
  4918. dmic_sample_rate_value = WCD9XXX_DMIC_SAMPLE_RATE_DIV_4;
  4919. dmic_b1_ctl_value = WCD9XXX_DMIC_B1_CTL_DIV_4;
  4920. anc_ctl_value = WCD9XXX_ANC_DMIC_X2_OFF;
  4921. break;
  4922. case WCD9XXX_DMIC_SAMPLE_RATE_6P144MHZ:
  4923. dmic_sample_rate_value = WCD9XXX_DMIC_SAMPLE_RATE_DIV_2;
  4924. dmic_b1_ctl_value = WCD9XXX_DMIC_B1_CTL_DIV_2;
  4925. anc_ctl_value = WCD9XXX_ANC_DMIC_X2_ON;
  4926. break;
  4927. case WCD9XXX_DMIC_SAMPLE_RATE_4P096MHZ:
  4928. case WCD9XXX_DMIC_SAMPLE_RATE_UNDEFINED:
  4929. dmic_sample_rate_value = WCD9XXX_DMIC_SAMPLE_RATE_DIV_3;
  4930. dmic_b1_ctl_value = WCD9XXX_DMIC_B1_CTL_DIV_3;
  4931. anc_ctl_value = WCD9XXX_ANC_DMIC_X2_OFF;
  4932. break;
  4933. default:
  4934. dev_err(codec->dev,
  4935. "%s Invalid sample rate %d for mclk %d\n",
  4936. __func__, pdata->dmic_sample_rate,
  4937. pdata->mclk_rate);
  4938. rc = -EINVAL;
  4939. goto done;
  4940. }
  4941. } else {
  4942. dev_err(codec->dev, "%s MCLK is not set!\n", __func__);
  4943. rc = -EINVAL;
  4944. goto done;
  4945. }
  4946. snd_soc_update_bits(codec, TAPAN_A_CDC_TX1_DMIC_CTL,
  4947. 0x7, dmic_sample_rate_value);
  4948. snd_soc_update_bits(codec, TAPAN_A_CDC_TX2_DMIC_CTL,
  4949. 0x7, dmic_sample_rate_value);
  4950. snd_soc_update_bits(codec, TAPAN_A_CDC_TX3_DMIC_CTL,
  4951. 0x7, dmic_sample_rate_value);
  4952. snd_soc_update_bits(codec, TAPAN_A_CDC_TX4_DMIC_CTL,
  4953. 0x7, dmic_sample_rate_value);
  4954. snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_DMIC_B1_CTL,
  4955. 0xEE, dmic_b1_ctl_value);
  4956. snd_soc_update_bits(codec, TAPAN_A_CDC_ANC1_B2_CTL,
  4957. 0x1, anc_ctl_value);
  4958. done:
  4959. return rc;
  4960. }
  4961. static const struct tapan_reg_mask_val tapan_reg_defaults[] = {
  4962. /* enable QFUSE for wcd9306 */
  4963. TAPAN_REG_VAL(TAPAN_A_QFUSE_CTL, 0x03),
  4964. /* PROGRAM_THE_0P85V_VBG_REFERENCE = V_0P858V */
  4965. TAPAN_REG_VAL(TAPAN_A_BIAS_CURR_CTL_2, 0x04),
  4966. TAPAN_REG_VAL(TAPAN_A_CDC_CLK_POWER_CTL, 0x03),
  4967. /* EAR PA deafults */
  4968. TAPAN_REG_VAL(TAPAN_A_RX_EAR_CMBUFF, 0x05),
  4969. /* RX1 and RX2 defaults */
  4970. TAPAN_REG_VAL(TAPAN_A_CDC_RX1_B6_CTL, 0xA0),
  4971. TAPAN_REG_VAL(TAPAN_A_CDC_RX2_B6_CTL, 0x80),
  4972. /* Heaset set Right from RX2 */
  4973. TAPAN_REG_VAL(TAPAN_A_CDC_CONN_RX2_B2_CTL, 0x10),
  4974. /*
  4975. * The following only need to be written for Tapan 1.0 parts.
  4976. * Tapan 2.0 will have appropriate defaults for these registers.
  4977. */
  4978. /* Required defaults for class H operation */
  4979. /* borrowed from Taiko class-h */
  4980. TAPAN_REG_VAL(TAPAN_A_RX_HPH_CHOP_CTL, 0xF4),
  4981. TAPAN_REG_VAL(TAPAN_A_BIAS_CURR_CTL_2, 0x08),
  4982. TAPAN_REG_VAL(WCD9XXX_A_BUCK_CTRL_CCL_1, 0x5B),
  4983. TAPAN_REG_VAL(WCD9XXX_A_BUCK_CTRL_CCL_3, 0x6F),
  4984. /* TODO: Check below reg writes conflict with above */
  4985. /* PROGRAM_THE_0P85V_VBG_REFERENCE = V_0P858V */
  4986. TAPAN_REG_VAL(TAPAN_A_BIAS_CURR_CTL_2, 0x04),
  4987. TAPAN_REG_VAL(TAPAN_A_RX_HPH_CHOP_CTL, 0x74),
  4988. TAPAN_REG_VAL(TAPAN_A_RX_BUCK_BIAS1, 0x62),
  4989. /* Choose max non-overlap time for NCP */
  4990. TAPAN_REG_VAL(TAPAN_A_NCP_CLK, 0xFC),
  4991. /* Use 25mV/50mV for deltap/m to reduce ripple */
  4992. TAPAN_REG_VAL(WCD9XXX_A_BUCK_CTRL_VCL_1, 0x08),
  4993. /*
  4994. * Set DISABLE_MODE_SEL<1:0> to 0b10 (disable PWM in auto mode).
  4995. * Note that the other bits of this register will be changed during
  4996. * Rx PA bring up.
  4997. */
  4998. TAPAN_REG_VAL(WCD9XXX_A_BUCK_MODE_3, 0xCE),
  4999. /* Reduce HPH DAC bias to 70% */
  5000. TAPAN_REG_VAL(TAPAN_A_RX_HPH_BIAS_PA, 0x7A),
  5001. /*Reduce EAR DAC bias to 70% */
  5002. TAPAN_REG_VAL(TAPAN_A_RX_EAR_BIAS_PA, 0x76),
  5003. /* Reduce LINE DAC bias to 70% */
  5004. #if defined(CONFIG_SEC_MATISSE_PROJECT) || defined(CONFIG_SEC_T10_PROJECT)
  5005. TAPAN_REG_VAL(TAPAN_A_RX_LINE_BIAS_PA, 0x78),
  5006. #elif defined(CONFIG_MACH_MS01_EUR_3G)
  5007. TAPAN_REG_VAL(TAPAN_A_RX_LINE_BIAS_PA, 0x7A),
  5008. #else
  5009. TAPAN_REG_VAL(TAPAN_A_RX_LINE_BIAS_PA, 0x7B),
  5010. #endif
  5011. /*
  5012. * There is a diode to pull down the micbias while doing
  5013. * insertion detection. This diode can cause leakage.
  5014. * Set bit 0 to 1 to prevent leakage.
  5015. * Setting this bit of micbias 2 prevents leakage for all other micbias.
  5016. */
  5017. TAPAN_REG_VAL(TAPAN_A_MICB_2_MBHC, 0x41),
  5018. /*
  5019. * Default register settings to support dynamic change of
  5020. * vdd_buck between 1.8 volts and 2.15 volts.
  5021. */
  5022. TAPAN_REG_VAL(TAPAN_A_BUCK_MODE_2, 0xAA),
  5023. };
  5024. static const struct tapan_reg_mask_val tapan_2_x_reg_reset_values[] = {
  5025. TAPAN_REG_VAL(TAPAN_A_TX_7_MBHC_EN, 0x6C),
  5026. TAPAN_REG_VAL(TAPAN_A_BUCK_CTRL_CCL_4, 0x51),
  5027. TAPAN_REG_VAL(TAPAN_A_RX_HPH_CNP_WG_CTL, 0xDA),
  5028. TAPAN_REG_VAL(TAPAN_A_RX_EAR_CNP, 0xC0),
  5029. TAPAN_REG_VAL(TAPAN_A_RX_LINE_1_TEST, 0x02),
  5030. TAPAN_REG_VAL(TAPAN_A_RX_LINE_2_TEST, 0x02),
  5031. TAPAN_REG_VAL(TAPAN_A_SPKR_DRV_OCP_CTL, 0x97),
  5032. TAPAN_REG_VAL(TAPAN_A_SPKR_DRV_CLIP_DET, 0x01),
  5033. TAPAN_REG_VAL(TAPAN_A_SPKR_DRV_IEC, 0x00),
  5034. TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_B1_CTL, 0xE4),
  5035. TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_B2_CTL, 0x00),
  5036. TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_B3_CTL, 0x00),
  5037. TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_BUCK_NCP_VARS, 0x00),
  5038. TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_V_PA_HD_EAR, 0x00),
  5039. TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_V_PA_MIN_EAR, 0x00),
  5040. TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_V_PA_HD_HPH, 0x00),
  5041. TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_V_PA_MIN_HPH, 0x00),
  5042. };
  5043. static const struct tapan_reg_mask_val tapan_1_0_reg_defaults[] = {
  5044. /* Close leakage on the spkdrv */
  5045. TAPAN_REG_VAL(TAPAN_A_SPKR_DRV_DBG_PWRSTG, 0x24),
  5046. TAPAN_REG_VAL(TAPAN_A_SPKR_DRV_DBG_DAC, 0xE5),
  5047. };
  5048. static void tapan_update_reg_defaults(struct snd_soc_codec *codec)
  5049. {
  5050. u32 i;
  5051. struct wcd9xxx *tapan_core = dev_get_drvdata(codec->dev->parent);
  5052. if (!TAPAN_IS_1_0(tapan_core->version)) {
  5053. for (i = 0; i < ARRAY_SIZE(tapan_2_x_reg_reset_values); i++)
  5054. snd_soc_write(codec, tapan_2_x_reg_reset_values[i].reg,
  5055. tapan_2_x_reg_reset_values[i].val);
  5056. }
  5057. for (i = 0; i < ARRAY_SIZE(tapan_reg_defaults); i++)
  5058. snd_soc_write(codec, tapan_reg_defaults[i].reg,
  5059. tapan_reg_defaults[i].val);
  5060. if (TAPAN_IS_1_0(tapan_core->version)) {
  5061. for (i = 0; i < ARRAY_SIZE(tapan_1_0_reg_defaults); i++)
  5062. snd_soc_write(codec, tapan_1_0_reg_defaults[i].reg,
  5063. tapan_1_0_reg_defaults[i].val);
  5064. }
  5065. if (!TAPAN_IS_1_0(tapan_core->version))
  5066. spkr_drv_wrnd = -1;
  5067. else if (spkr_drv_wrnd == 1)
  5068. snd_soc_write(codec, TAPAN_A_SPKR_DRV_EN, 0xEF);
  5069. }
  5070. static void tapan_update_reg_mclk_rate(struct wcd9xxx *wcd9xxx)
  5071. {
  5072. struct snd_soc_codec *codec;
  5073. codec = (struct snd_soc_codec *)(wcd9xxx->ssr_priv);
  5074. dev_dbg(codec->dev, "%s: MCLK Rate = %x\n",
  5075. __func__, wcd9xxx->mclk_rate);
  5076. if (wcd9xxx->mclk_rate == TAPAN_MCLK_CLK_12P288MHZ) {
  5077. snd_soc_update_bits(codec, TAPAN_A_CHIP_CTL, 0x06, 0x0);
  5078. snd_soc_update_bits(codec, TAPAN_A_RX_COM_TIMER_DIV, 0x01,
  5079. 0x01);
  5080. } else if (wcd9xxx->mclk_rate == TAPAN_MCLK_CLK_9P6MHZ) {
  5081. snd_soc_update_bits(codec, TAPAN_A_CHIP_CTL, 0x06, 0x2);
  5082. }
  5083. }
  5084. static const struct tapan_reg_mask_val tapan_codec_reg_init_val[] = {
  5085. /* Initialize current threshold to 365MA
  5086. * number of wait and run cycles to 4096
  5087. */
  5088. #if defined (CONFIG_MACH_MILLETLTE_KOR)
  5089. {TAPAN_A_RX_HPH_OCP_CTL, 0xEB, 0x6B},
  5090. #else
  5091. {TAPAN_A_RX_HPH_OCP_CTL, 0xE9, 0x69},
  5092. #endif
  5093. {TAPAN_A_RX_COM_OCP_COUNT, 0xFF, 0xFF},
  5094. {TAPAN_A_RX_HPH_L_TEST, 0x01, 0x01},
  5095. {TAPAN_A_RX_HPH_R_TEST, 0x01, 0x01},
  5096. /* Initialize gain registers to use register gain */
  5097. {TAPAN_A_RX_HPH_L_GAIN, 0x20, 0x20},
  5098. {TAPAN_A_RX_HPH_R_GAIN, 0x20, 0x20},
  5099. {TAPAN_A_RX_LINE_1_GAIN, 0x20, 0x20},
  5100. {TAPAN_A_RX_LINE_2_GAIN, 0x20, 0x20},
  5101. {TAPAN_A_SPKR_DRV_GAIN, 0x04, 0x04},
  5102. /* Set RDAC5 MUX to take input from DEM3_INV.
  5103. * This sets LO2 DAC to get input from DEM3_INV
  5104. * for LO1 and LO2 to work as differential outputs.
  5105. */
  5106. {TAPAN_A_CDC_CONN_MISC, 0x04, 0x04},
  5107. /* CLASS H config */
  5108. {TAPAN_A_CDC_CONN_CLSH_CTL, 0x3C, 0x14},
  5109. /* Use 16 bit sample size for TX1 to TX5 */
  5110. {TAPAN_A_CDC_CONN_TX_SB_B1_CTL, 0x30, 0x20},
  5111. {TAPAN_A_CDC_CONN_TX_SB_B2_CTL, 0x30, 0x20},
  5112. {TAPAN_A_CDC_CONN_TX_SB_B3_CTL, 0x30, 0x20},
  5113. {TAPAN_A_CDC_CONN_TX_SB_B4_CTL, 0x30, 0x20},
  5114. {TAPAN_A_CDC_CONN_TX_SB_B5_CTL, 0x30, 0x20},
  5115. /* Disable SPK SWITCH */
  5116. {TAPAN_A_SPKR_DRV_DAC_CTL, 0x04, 0x00},
  5117. /* Use 16 bit sample size for RX */
  5118. {TAPAN_A_CDC_CONN_RX_SB_B1_CTL, 0xFF, 0xAA},
  5119. {TAPAN_A_CDC_CONN_RX_SB_B2_CTL, 0xFF, 0x2A},
  5120. /*enable HPF filter for TX paths */
  5121. {TAPAN_A_CDC_TX1_MUX_CTL, 0x8, 0x0},
  5122. {TAPAN_A_CDC_TX2_MUX_CTL, 0x8, 0x0},
  5123. {TAPAN_A_CDC_TX3_MUX_CTL, 0x8, 0x0},
  5124. {TAPAN_A_CDC_TX4_MUX_CTL, 0x8, 0x0},
  5125. /* Compander zone selection */
  5126. {TAPAN_A_CDC_COMP0_B4_CTL, 0x3F, 0x37},
  5127. {TAPAN_A_CDC_COMP1_B4_CTL, 0x3F, 0x37},
  5128. {TAPAN_A_CDC_COMP2_B4_CTL, 0x3F, 0x37},
  5129. {TAPAN_A_CDC_COMP0_B5_CTL, 0x7F, 0x7F},
  5130. {TAPAN_A_CDC_COMP1_B5_CTL, 0x7F, 0x7F},
  5131. {TAPAN_A_CDC_COMP2_B5_CTL, 0x7F, 0x7F},
  5132. /*
  5133. * Setup wavegen timer to 20msec and disable chopper
  5134. * as default. This corresponds to Compander OFF
  5135. */
  5136. {TAPAN_A_RX_HPH_CNP_WG_CTL, 0xFF, 0xDB},
  5137. {TAPAN_A_RX_HPH_CNP_WG_TIME, 0xFF, 0x58},
  5138. {TAPAN_A_RX_HPH_BIAS_WG_OCP, 0xFF, 0x1A},
  5139. {TAPAN_A_RX_HPH_CHOP_CTL, 0xFF, 0x24},
  5140. };
  5141. #if defined (CONFIG_MACH_RUBENSLTE_OPEN)
  5142. static const struct tapan_reg_mask_val tapan_codec_reg_mib3_int_rbias_init_val[] = {
  5143. {TAPAN_A_MICB_3_INT_RBIAS, 0x20, 0x00},
  5144. };
  5145. #endif
  5146. #if defined(CONFIG_MACH_MILLETLTE_VZW)
  5147. static const struct tapan_reg_mask_val tapan_codec_reg_mib2_ctl_init_val[] = {
  5148. {TAPAN_A_MICB_2_CTL, 0x01, 0x01},
  5149. };
  5150. #endif
  5151. #if defined(CONFIG_MACH_ATLANTICLTE_ATT) || defined(CONFIG_SEC_ATLANTIC3G_COMMON) || defined(CONFIG_MACH_ATLANTICLTE_USC) || defined(CONFIG_SEC_RUBENS_PROJECT)
  5152. static const struct tapan_reg_mask_val tapan_codec_reg_hph_ocp_ctl_init_val[] = {
  5153. {TAPAN_A_RX_HPH_OCP_CTL, 0xEB, 0x6B},
  5154. };
  5155. #endif
  5156. void *tapan_get_afe_config(struct snd_soc_codec *codec,
  5157. enum afe_config_type config_type)
  5158. {
  5159. struct tapan_priv *priv = snd_soc_codec_get_drvdata(codec);
  5160. switch (config_type) {
  5161. case AFE_SLIMBUS_SLAVE_CONFIG:
  5162. return &priv->slimbus_slave_cfg;
  5163. case AFE_CDC_REGISTERS_CONFIG:
  5164. return &tapan_audio_reg_cfg;
  5165. case AFE_AANC_VERSION:
  5166. return &tapan_cdc_aanc_version;
  5167. default:
  5168. pr_err("%s: Unknown config_type 0x%x\n", __func__, config_type);
  5169. return NULL;
  5170. }
  5171. }
  5172. static void tapan_init_slim_slave_cfg(struct snd_soc_codec *codec)
  5173. {
  5174. struct tapan_priv *priv = snd_soc_codec_get_drvdata(codec);
  5175. struct afe_param_cdc_slimbus_slave_cfg *cfg;
  5176. struct wcd9xxx *wcd9xxx = codec->control_data;
  5177. uint64_t eaddr = 0;
  5178. pr_debug("%s\n", __func__);
  5179. cfg = &priv->slimbus_slave_cfg;
  5180. cfg->minor_version = 1;
  5181. cfg->tx_slave_port_offset = 0;
  5182. cfg->rx_slave_port_offset = 16;
  5183. memcpy(&eaddr, &wcd9xxx->slim->e_addr, sizeof(wcd9xxx->slim->e_addr));
  5184. /* e-addr is 6-byte elemental address of the device */
  5185. WARN_ON(sizeof(wcd9xxx->slim->e_addr) != 6);
  5186. cfg->device_enum_addr_lsw = eaddr & 0xFFFFFFFF;
  5187. cfg->device_enum_addr_msw = eaddr >> 32;
  5188. pr_debug("%s: slimbus logical address 0x%llx\n", __func__, eaddr);
  5189. }
  5190. extern int system_rev;
  5191. static void tapan_codec_init_reg(struct snd_soc_codec *codec)
  5192. {
  5193. u32 i;
  5194. for (i = 0; i < ARRAY_SIZE(tapan_codec_reg_init_val); i++)
  5195. snd_soc_update_bits(codec, tapan_codec_reg_init_val[i].reg,
  5196. tapan_codec_reg_init_val[i].mask,
  5197. tapan_codec_reg_init_val[i].val);
  5198. #if defined (CONFIG_MACH_RUBENSLTE_OPEN)
  5199. snd_soc_update_bits(codec,tapan_codec_reg_mib3_int_rbias_init_val[0].reg,
  5200. tapan_codec_reg_mib3_int_rbias_init_val[0].mask,
  5201. tapan_codec_reg_mib3_int_rbias_init_val[0].val);
  5202. #endif
  5203. #if defined(CONFIG_MACH_MILLETLTE_VZW)
  5204. if (system_rev > 1)
  5205. {
  5206. snd_soc_update_bits(codec,tapan_codec_reg_mib2_ctl_init_val[0].reg,
  5207. tapan_codec_reg_mib2_ctl_init_val[0].mask,
  5208. tapan_codec_reg_mib2_ctl_init_val[0].val);
  5209. }
  5210. #endif
  5211. #if defined(CONFIG_MACH_ATLANTICLTE_ATT) || defined(CONFIG_SEC_ATLANTIC3G_COMMON) || defined(CONFIG_MACH_ATLANTICLTE_USC) || defined(CONFIG_SEC_RUBENS_PROJECT)
  5212. snd_soc_update_bits(codec,tapan_codec_reg_hph_ocp_ctl_init_val[0].reg,
  5213. tapan_codec_reg_hph_ocp_ctl_init_val[0].mask,
  5214. tapan_codec_reg_hph_ocp_ctl_init_val[0].val);
  5215. #endif
  5216. }
  5217. static void tapan_slim_interface_init_reg(struct snd_soc_codec *codec)
  5218. {
  5219. int i;
  5220. for (i = 0; i < WCD9XXX_SLIM_NUM_PORT_REG; i++)
  5221. wcd9xxx_interface_reg_write(codec->control_data,
  5222. TAPAN_SLIM_PGD_PORT_INT_EN0 + i,
  5223. 0xFF);
  5224. }
  5225. static int tapan_setup_irqs(struct tapan_priv *tapan)
  5226. {
  5227. int ret = 0;
  5228. struct snd_soc_codec *codec = tapan->codec;
  5229. struct wcd9xxx *wcd9xxx = codec->control_data;
  5230. struct wcd9xxx_core_resource *core_res = &wcd9xxx->core_res;
  5231. ret = wcd9xxx_request_irq(core_res, WCD9XXX_IRQ_SLIMBUS,
  5232. tapan_slimbus_irq, "SLIMBUS Slave", tapan);
  5233. if (ret)
  5234. pr_err("%s: Failed to request irq %d\n", __func__,
  5235. WCD9XXX_IRQ_SLIMBUS);
  5236. else
  5237. tapan_slim_interface_init_reg(codec);
  5238. return ret;
  5239. }
  5240. static void tapan_cleanup_irqs(struct tapan_priv *tapan)
  5241. {
  5242. struct snd_soc_codec *codec = tapan->codec;
  5243. struct wcd9xxx *wcd9xxx = codec->control_data;
  5244. struct wcd9xxx_core_resource *core_res = &wcd9xxx->core_res;
  5245. wcd9xxx_free_irq(core_res, WCD9XXX_IRQ_SLIMBUS, tapan);
  5246. }
  5247. static void tapan_enable_mux_bias_block(struct snd_soc_codec *codec)
  5248. {
  5249. snd_soc_update_bits(codec, WCD9XXX_A_MBHC_SCALING_MUX_1,
  5250. 0x80, 0x00);
  5251. }
  5252. static void tapan_put_cfilt_fast_mode(struct snd_soc_codec *codec,
  5253. struct wcd9xxx_mbhc *mbhc)
  5254. {
  5255. snd_soc_update_bits(codec, mbhc->mbhc_bias_regs.cfilt_ctl,
  5256. 0x30, 0x30);
  5257. }
  5258. static void tapan_codec_specific_cal_setup(struct snd_soc_codec *codec,
  5259. struct wcd9xxx_mbhc *mbhc)
  5260. {
  5261. snd_soc_update_bits(codec, WCD9XXX_A_CDC_MBHC_B1_CTL,
  5262. 0x04, 0x04);
  5263. snd_soc_update_bits(codec, WCD9XXX_A_TX_7_MBHC_EN, 0xE0, 0xE0);
  5264. }
  5265. static struct wcd9xxx_cfilt_mode tapan_codec_switch_cfilt_mode(
  5266. struct wcd9xxx_mbhc *mbhc,
  5267. bool fast)
  5268. {
  5269. struct snd_soc_codec *codec = mbhc->codec;
  5270. struct wcd9xxx_cfilt_mode cfilt_mode;
  5271. if (fast)
  5272. cfilt_mode.reg_mode_val = WCD9XXX_CFILT_EXT_PRCHG_EN;
  5273. else
  5274. cfilt_mode.reg_mode_val = WCD9XXX_CFILT_EXT_PRCHG_DSBL;
  5275. cfilt_mode.cur_mode_val =
  5276. snd_soc_read(codec, mbhc->mbhc_bias_regs.cfilt_ctl) & 0x30;
  5277. cfilt_mode.reg_mask = 0x30;
  5278. return cfilt_mode;
  5279. }
  5280. static void tapan_select_cfilt(struct snd_soc_codec *codec,
  5281. struct wcd9xxx_mbhc *mbhc)
  5282. {
  5283. snd_soc_update_bits(codec, mbhc->mbhc_bias_regs.ctl_reg, 0x60, 0x00);
  5284. }
  5285. enum wcd9xxx_cdc_type tapan_get_cdc_type(void)
  5286. {
  5287. return WCD9XXX_CDC_TYPE_TAPAN;
  5288. }
  5289. static void wcd9xxx_prepare_hph_pa(struct wcd9xxx_mbhc *mbhc,
  5290. struct list_head *lh)
  5291. {
  5292. int i;
  5293. struct snd_soc_codec *codec = mbhc->codec;
  5294. u32 delay;
  5295. int ret = 0;
  5296. const struct wcd9xxx_reg_mask_val reg_set_paon[] = {
  5297. {WCD9XXX_A_CDC_CLSH_B1_CTL, 0x0F, 0x00},
  5298. {WCD9XXX_A_RX_HPH_CHOP_CTL, 0xFF, 0xA4},
  5299. {WCD9XXX_A_RX_HPH_OCP_CTL, 0xFF, 0x67},
  5300. {WCD9XXX_A_RX_HPH_L_TEST, 0x1, 0x0},
  5301. {WCD9XXX_A_RX_HPH_R_TEST, 0x1, 0x0},
  5302. {WCD9XXX_A_RX_HPH_BIAS_WG_OCP, 0xFF, 0x1A},
  5303. {WCD9XXX_A_RX_HPH_CNP_WG_CTL, 0xFF, 0xDB},
  5304. {WCD9XXX_A_RX_HPH_CNP_WG_TIME, 0xFF, 0x2A},
  5305. {TAPAN_A_CDC_CONN_RX2_B2_CTL, 0xFF, 0x10},
  5306. {WCD9XXX_A_CDC_CLK_OTHR_CTL, 0xFF, 0x05},
  5307. {WCD9XXX_A_CDC_RX1_B6_CTL, 0xFF, 0x81},
  5308. {WCD9XXX_A_CDC_CLK_RX_B1_CTL, 0x03, 0x03},
  5309. {WCD9XXX_A_RX_HPH_L_GAIN, 0xFF, 0x2C},
  5310. {WCD9XXX_A_CDC_RX2_B6_CTL, 0xFF, 0x81},
  5311. {WCD9XXX_A_RX_HPH_R_GAIN, 0xFF, 0x2C},
  5312. {WCD9XXX_A_BUCK_CTRL_CCL_4, 0xFF, 0x50},
  5313. {WCD9XXX_A_BUCK_CTRL_VCL_1, 0xFF, 0x08},
  5314. {WCD9XXX_A_BUCK_CTRL_CCL_1, 0xFF, 0x5B},
  5315. {WCD9XXX_A_NCP_CLK, 0xFF, 0x9C},
  5316. {WCD9XXX_A_NCP_CLK, 0xFF, 0xFC},
  5317. {WCD9XXX_A_BUCK_MODE_3, 0xFF, 0xCE},
  5318. {WCD9XXX_A_BUCK_CTRL_CCL_3, 0xFF, 0x6B},
  5319. {WCD9XXX_A_BUCK_CTRL_CCL_3, 0xFF, 0x6F},
  5320. {TAPAN_A_RX_BUCK_BIAS1, 0xFF, 0x62},
  5321. {TAPAN_A_RX_HPH_BIAS_PA, 0xFF, 0x7A},
  5322. {TAPAN_A_CDC_CLK_RDAC_CLK_EN_CTL, 0xFF, 0x02},
  5323. {TAPAN_A_CDC_CLK_RDAC_CLK_EN_CTL, 0xFF, 0x06},
  5324. {WCD9XXX_A_RX_COM_BIAS, 0xFF, 0x80},
  5325. {WCD9XXX_A_BUCK_MODE_3, 0xFF, 0xC6},
  5326. {WCD9XXX_A_BUCK_MODE_4, 0xFF, 0xE6},
  5327. {WCD9XXX_A_BUCK_MODE_5, 0xFF, 0x02},
  5328. {WCD9XXX_A_BUCK_MODE_1, 0xFF, 0xA1},
  5329. /* Delay 1ms */
  5330. {WCD9XXX_A_NCP_EN, 0xFF, 0xFF},
  5331. /* Delay 1ms */
  5332. {WCD9XXX_A_BUCK_MODE_5, 0xFF, 0x03},
  5333. {WCD9XXX_A_BUCK_MODE_5, 0xFF, 0x7B},
  5334. {WCD9XXX_A_CDC_CLSH_B1_CTL, 0xFF, 0xE6},
  5335. {WCD9XXX_A_RX_HPH_L_DAC_CTL, 0xFF, 0x40},
  5336. {WCD9XXX_A_RX_HPH_L_DAC_CTL, 0xFF, 0xC0},
  5337. {WCD9XXX_A_RX_HPH_R_DAC_CTL, 0xFF, 0x40},
  5338. {WCD9XXX_A_RX_HPH_R_DAC_CTL, 0xFF, 0xC0},
  5339. {WCD9XXX_A_NCP_STATIC, 0xFF, 0x08},
  5340. {WCD9XXX_A_RX_HPH_L_DAC_CTL, 0x03, 0x01},
  5341. {WCD9XXX_A_RX_HPH_R_DAC_CTL, 0x03, 0x01},
  5342. };
  5343. /*
  5344. * Configure PA in class-AB, -18dB gain,
  5345. * companding off, OCP off, Chopping ON
  5346. */
  5347. for (i = 0; i < ARRAY_SIZE(reg_set_paon); i++) {
  5348. /*
  5349. * Some of the codec registers like BUCK_MODE_1
  5350. * and NCP_EN requires 1ms wait time for them
  5351. * to take effect. Other register writes for
  5352. * PA configuration do not require any wait time.
  5353. */
  5354. if (reg_set_paon[i].reg == WCD9XXX_A_BUCK_MODE_1 ||
  5355. reg_set_paon[i].reg == WCD9XXX_A_NCP_EN)
  5356. delay = 1000;
  5357. else
  5358. delay = 0;
  5359. ret = wcd9xxx_soc_update_bits_push(codec, lh,
  5360. reg_set_paon[i].reg,
  5361. reg_set_paon[i].mask,
  5362. reg_set_paon[i].val, delay);
  5363. if (ret < 0) {
  5364. pr_debug("%s: wcd9xxx_soc_update_bits_push failed\n", __func__);
  5365. return;
  5366. }
  5367. }
  5368. pr_debug("%s: PAs are prepared\n", __func__);
  5369. return;
  5370. }
  5371. static int wcd9xxx_enable_static_pa(struct wcd9xxx_mbhc *mbhc, bool enable)
  5372. {
  5373. struct snd_soc_codec *codec = mbhc->codec;
  5374. int wg_time = snd_soc_read(codec, WCD9XXX_A_RX_HPH_CNP_WG_TIME) *
  5375. TAPAN_WG_TIME_FACTOR_US;
  5376. /*
  5377. * Tapan requires additional time to enable PA.
  5378. * It is observed during experiments that we need
  5379. * an additional wait time about 0.35 times of
  5380. * the WG_TIME
  5381. */
  5382. wg_time += (int) (wg_time * 35) / 100;
  5383. snd_soc_update_bits(codec, WCD9XXX_A_RX_HPH_CNP_EN, 0x30,
  5384. enable ? 0x30 : 0x0);
  5385. /* Wait for wave gen time to avoid pop noise */
  5386. usleep_range(wg_time, wg_time + WCD9XXX_USLEEP_RANGE_MARGIN_US);
  5387. pr_debug("%s: PAs are %s as static mode (wg_time %d)\n", __func__,
  5388. enable ? "enabled" : "disabled", wg_time);
  5389. return 0;
  5390. }
  5391. static int tapan_setup_zdet(struct wcd9xxx_mbhc *mbhc,
  5392. enum mbhc_impedance_detect_stages stage)
  5393. {
  5394. int ret = 0;
  5395. struct snd_soc_codec *codec = mbhc->codec;
  5396. struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
  5397. const int mux_wait_us = 25;
  5398. switch (stage) {
  5399. case PRE_MEAS:
  5400. INIT_LIST_HEAD(&tapan->reg_save_restore);
  5401. /* Configure PA */
  5402. wcd9xxx_prepare_hph_pa(mbhc, &tapan->reg_save_restore);
  5403. #define __wr(reg, mask, value) \
  5404. do { \
  5405. ret = wcd9xxx_soc_update_bits_push(codec, \
  5406. &tapan->reg_save_restore, \
  5407. reg, mask, value, 0); \
  5408. if (ret < 0) \
  5409. return ret; \
  5410. } while (0)
  5411. /* Setup MBHC */
  5412. __wr(WCD9XXX_A_MBHC_SCALING_MUX_1, 0x7F, 0x40);
  5413. __wr(WCD9XXX_A_MBHC_SCALING_MUX_2, 0xFF, 0xF0);
  5414. __wr(WCD9XXX_A_TX_7_MBHC_TEST_CTL, 0xFF, 0x78);
  5415. __wr(WCD9XXX_A_TX_7_MBHC_EN, 0xFF, 0xEC);
  5416. __wr(WCD9XXX_A_CDC_MBHC_TIMER_B4_CTL, 0xFF, 0x45);
  5417. __wr(WCD9XXX_A_CDC_MBHC_TIMER_B5_CTL, 0xFF, 0x80);
  5418. __wr(WCD9XXX_A_CDC_MBHC_CLK_CTL, 0xFF, 0x0A);
  5419. snd_soc_write(codec, WCD9XXX_A_CDC_MBHC_EN_CTL, 0x2);
  5420. __wr(WCD9XXX_A_CDC_MBHC_CLK_CTL, 0xFF, 0x02);
  5421. /* Enable Impedance Detection */
  5422. __wr(WCD9XXX_A_MBHC_HPH, 0xFF, 0xC8);
  5423. /*
  5424. * CnP setup for 0mV
  5425. * Route static data as input to noise shaper
  5426. */
  5427. __wr(TAPAN_A_CDC_RX1_B3_CTL, 0xFF, 0x02);
  5428. __wr(TAPAN_A_CDC_RX2_B3_CTL, 0xFF, 0x02);
  5429. snd_soc_update_bits(codec, WCD9XXX_A_RX_HPH_L_TEST,
  5430. 0x02, 0x00);
  5431. snd_soc_update_bits(codec, WCD9XXX_A_RX_HPH_R_TEST,
  5432. 0x02, 0x00);
  5433. /* Reset the HPHL static data pointer */
  5434. __wr(TAPAN_A_CDC_RX1_B2_CTL, 0xFF, 0x00);
  5435. /* Four consecutive writes to set 0V as static data input */
  5436. snd_soc_write(codec, TAPAN_A_CDC_RX1_B1_CTL, 0x00);
  5437. snd_soc_write(codec, TAPAN_A_CDC_RX1_B1_CTL, 0x00);
  5438. snd_soc_write(codec, TAPAN_A_CDC_RX1_B1_CTL, 0x00);
  5439. snd_soc_write(codec, TAPAN_A_CDC_RX1_B1_CTL, 0x00);
  5440. /* Reset the HPHR static data pointer */
  5441. __wr(TAPAN_A_CDC_RX2_B2_CTL, 0xFF, 0x00);
  5442. /* Four consecutive writes to set 0V as static data input */
  5443. snd_soc_write(codec, TAPAN_A_CDC_RX2_B1_CTL, 0x00);
  5444. snd_soc_write(codec, TAPAN_A_CDC_RX2_B1_CTL, 0x00);
  5445. snd_soc_write(codec, TAPAN_A_CDC_RX2_B1_CTL, 0x00);
  5446. snd_soc_write(codec, TAPAN_A_CDC_RX2_B1_CTL, 0x00);
  5447. /* Enable the HPHL and HPHR PA */
  5448. wcd9xxx_enable_static_pa(mbhc, true);
  5449. break;
  5450. case POST_MEAS:
  5451. /* Turn off ICAL */
  5452. snd_soc_write(codec, WCD9XXX_A_MBHC_SCALING_MUX_2, 0xF0);
  5453. wcd9xxx_enable_static_pa(mbhc, false);
  5454. /*
  5455. * Setup CnP wavegen to ramp to the desired
  5456. * output using a 40ms ramp
  5457. */
  5458. /* CnP wavegen current to 0.5uA */
  5459. snd_soc_write(codec, WCD9XXX_A_RX_HPH_BIAS_WG_OCP, 0x1A);
  5460. /* Set the current division ratio to 2000 */
  5461. snd_soc_write(codec, WCD9XXX_A_RX_HPH_CNP_WG_CTL, 0xDF);
  5462. /* Set the wavegen timer to max (60msec) */
  5463. snd_soc_write(codec, WCD9XXX_A_RX_HPH_CNP_WG_TIME, 0xA0);
  5464. /* Set the CnP reference current to sc_bias */
  5465. snd_soc_write(codec, WCD9XXX_A_RX_HPH_OCP_CTL, 0x6D);
  5466. snd_soc_write(codec, TAPAN_A_CDC_RX1_B2_CTL, 0x00);
  5467. /* Four consecutive writes to set -10mV as static data input */
  5468. snd_soc_write(codec, TAPAN_A_CDC_RX1_B1_CTL, 0x00);
  5469. snd_soc_write(codec, TAPAN_A_CDC_RX1_B1_CTL, 0x1F);
  5470. snd_soc_write(codec, TAPAN_A_CDC_RX1_B1_CTL, 0x19);
  5471. snd_soc_write(codec, TAPAN_A_CDC_RX1_B1_CTL, 0xAA);
  5472. snd_soc_write(codec, TAPAN_A_CDC_RX2_B2_CTL, 0x00);
  5473. /* Four consecutive writes to set -10mV as static data input */
  5474. snd_soc_write(codec, TAPAN_A_CDC_RX2_B1_CTL, 0x00);
  5475. snd_soc_write(codec, TAPAN_A_CDC_RX2_B1_CTL, 0x1F);
  5476. snd_soc_write(codec, TAPAN_A_CDC_RX2_B1_CTL, 0x19);
  5477. snd_soc_write(codec, TAPAN_A_CDC_RX2_B1_CTL, 0xAA);
  5478. snd_soc_update_bits(codec, WCD9XXX_A_RX_HPH_L_TEST,
  5479. 0x02, 0x02);
  5480. snd_soc_update_bits(codec, WCD9XXX_A_RX_HPH_R_TEST,
  5481. 0x02, 0x02);
  5482. /* Enable the HPHL and HPHR PA and wait for 60mS */
  5483. wcd9xxx_enable_static_pa(mbhc, true);
  5484. snd_soc_update_bits(codec, WCD9XXX_A_MBHC_SCALING_MUX_1,
  5485. 0x7F, 0x40);
  5486. usleep_range(mux_wait_us,
  5487. mux_wait_us + WCD9XXX_USLEEP_RANGE_MARGIN_US);
  5488. break;
  5489. case PA_DISABLE:
  5490. if (!mbhc->hph_pa_dac_state &&
  5491. (!(test_bit(MBHC_EVENT_PA_HPHL, &mbhc->event_state) ||
  5492. test_bit(MBHC_EVENT_PA_HPHR, &mbhc->event_state))))
  5493. wcd9xxx_enable_static_pa(mbhc, false);
  5494. wcd9xxx_restore_registers(codec, &tapan->reg_save_restore);
  5495. break;
  5496. }
  5497. #undef __wr
  5498. return ret;
  5499. }
  5500. static void tapan_compute_impedance(s16 *l, s16 *r, uint32_t *zl, uint32_t *zr)
  5501. {
  5502. int zln, zld;
  5503. int zrn, zrd;
  5504. int rl = 0, rr = 0;
  5505. zln = (l[1] - l[0]) * TAPAN_ZDET_MUL_FACTOR;
  5506. zld = (l[2] - l[0]);
  5507. if (zld)
  5508. rl = zln / zld;
  5509. zrn = (r[1] - r[0]) * TAPAN_ZDET_MUL_FACTOR;
  5510. zrd = (r[2] - r[0]);
  5511. if (zrd)
  5512. rr = zrn / zrd;
  5513. *zl = rl;
  5514. *zr = rr;
  5515. }
  5516. static const struct wcd9xxx_mbhc_cb mbhc_cb = {
  5517. .enable_mux_bias_block = tapan_enable_mux_bias_block,
  5518. .cfilt_fast_mode = tapan_put_cfilt_fast_mode,
  5519. .codec_specific_cal = tapan_codec_specific_cal_setup,
  5520. .switch_cfilt_mode = tapan_codec_switch_cfilt_mode,
  5521. .select_cfilt = tapan_select_cfilt,
  5522. .get_cdc_type = tapan_get_cdc_type,
  5523. .setup_zdet = tapan_setup_zdet,
  5524. .compute_impedance = tapan_compute_impedance,
  5525. };
  5526. int tapan_hs_detect(struct snd_soc_codec *codec,
  5527. struct wcd9xxx_mbhc_config *mbhc_cfg)
  5528. {
  5529. struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
  5530. return wcd9xxx_mbhc_start(&tapan->mbhc, mbhc_cfg);
  5531. }
  5532. EXPORT_SYMBOL(tapan_hs_detect);
  5533. void tapan_hs_detect_exit(struct snd_soc_codec *codec)
  5534. {
  5535. struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
  5536. wcd9xxx_mbhc_stop(&tapan->mbhc);
  5537. }
  5538. EXPORT_SYMBOL(tapan_hs_detect_exit);
  5539. void tapan_event_register(
  5540. int (*machine_event_cb)(struct snd_soc_codec *codec,
  5541. enum wcd9xxx_codec_event),
  5542. struct snd_soc_codec *codec)
  5543. {
  5544. struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
  5545. tapan->machine_codec_event_cb = machine_event_cb;
  5546. }
  5547. EXPORT_SYMBOL(tapan_event_register);
  5548. static int tapan_device_down(struct wcd9xxx *wcd9xxx)
  5549. {
  5550. struct snd_soc_codec *codec;
  5551. codec = (struct snd_soc_codec *)(wcd9xxx->ssr_priv);
  5552. snd_soc_card_change_online_state(codec->card, 0);
  5553. return 0;
  5554. }
  5555. static const struct wcd9xxx_mbhc_intr cdc_intr_ids = {
  5556. .poll_plug_rem = WCD9XXX_IRQ_MBHC_REMOVAL,
  5557. .shortavg_complete = WCD9XXX_IRQ_MBHC_SHORT_TERM,
  5558. .potential_button_press = WCD9XXX_IRQ_MBHC_PRESS,
  5559. .button_release = WCD9XXX_IRQ_MBHC_RELEASE,
  5560. .dce_est_complete = WCD9XXX_IRQ_MBHC_POTENTIAL,
  5561. .insertion = WCD9XXX_IRQ_MBHC_INSERTION,
  5562. .hph_left_ocp = WCD9306_IRQ_HPH_PA_OCPL_FAULT,
  5563. .hph_right_ocp = WCD9306_IRQ_HPH_PA_OCPR_FAULT,
  5564. .hs_jack_switch = WCD9306_IRQ_MBHC_JACK_SWITCH,
  5565. };
  5566. static int tapan_post_reset_cb(struct wcd9xxx *wcd9xxx)
  5567. {
  5568. int ret = 0;
  5569. int rco_clk_rate;
  5570. struct snd_soc_codec *codec;
  5571. struct tapan_priv *tapan;
  5572. int count;
  5573. codec = (struct snd_soc_codec *)(wcd9xxx->ssr_priv);
  5574. tapan = snd_soc_codec_get_drvdata(codec);
  5575. snd_soc_card_change_online_state(codec->card, 1);
  5576. mutex_lock(&codec->mutex);
  5577. if (codec->reg_def_copy) {
  5578. pr_debug("%s: Update ASOC cache", __func__);
  5579. kfree(codec->reg_cache);
  5580. codec->reg_cache = kmemdup(codec->reg_def_copy,
  5581. codec->reg_size, GFP_KERNEL);
  5582. if (!codec->reg_cache) {
  5583. pr_err("%s: Cache update failed!\n", __func__);
  5584. mutex_unlock(&codec->mutex);
  5585. return -ENOMEM;
  5586. }
  5587. }
  5588. if (spkr_drv_wrnd == 1)
  5589. snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_EN, 0x80, 0x80);
  5590. tapan_update_reg_defaults(codec);
  5591. tapan_update_reg_mclk_rate(wcd9xxx);
  5592. tapan_codec_init_reg(codec);
  5593. ret = tapan_handle_pdata(tapan);
  5594. if (IS_ERR_VALUE(ret))
  5595. pr_err("%s: bad pdata\n", __func__);
  5596. tapan_slim_interface_init_reg(codec);
  5597. wcd9xxx_resmgr_post_ssr(&tapan->resmgr);
  5598. wcd9xxx_mbhc_deinit(&tapan->mbhc);
  5599. if (TAPAN_IS_1_0(wcd9xxx->version))
  5600. rco_clk_rate = TAPAN_MCLK_CLK_12P288MHZ;
  5601. else
  5602. rco_clk_rate = TAPAN_MCLK_CLK_9P6MHZ;
  5603. #ifndef CONFIG_ARCH_MSM8226
  5604. ret = wcd9xxx_mbhc_init(&tapan->mbhc, &tapan->resmgr, codec,
  5605. tapan_enable_mbhc_micbias,
  5606. &mbhc_cb, &cdc_intr_ids, rco_clk_rate,
  5607. TAPAN_CDC_ZDET_SUPPORTED);
  5608. #else
  5609. ret = wcd9xxx_mbhc_init(&tapan->mbhc, &tapan->resmgr, codec,NULL,
  5610. &mbhc_cb, &cdc_intr_ids, rco_clk_rate,
  5611. TAPAN_CDC_ZDET_SUPPORTED);
  5612. #endif
  5613. if (ret)
  5614. pr_err("%s: mbhc init failed %d\n", __func__, ret);
  5615. else
  5616. wcd9xxx_mbhc_start(&tapan->mbhc, tapan->mbhc.mbhc_cfg);
  5617. tapan_cleanup_irqs(tapan);
  5618. ret = tapan_setup_irqs(tapan);
  5619. if (ret)
  5620. pr_err("%s: Failed to setup irq: %d\n", __func__, ret);
  5621. tapan->machine_codec_event_cb(codec, WCD9XXX_CODEC_EVENT_CODEC_UP);
  5622. for (count = 0; count < NUM_CODEC_DAIS; count++)
  5623. tapan->dai[count].bus_down_in_recovery = true;
  5624. mutex_unlock(&codec->mutex);
  5625. return ret;
  5626. }
  5627. static struct wcd9xxx_reg_address tapan_reg_address = {
  5628. };
  5629. static int wcd9xxx_ssr_register(struct wcd9xxx *control,
  5630. int (*device_down_cb)(struct wcd9xxx *wcd9xxx),
  5631. int (*device_up_cb)(struct wcd9xxx *wcd9xxx),
  5632. void *priv)
  5633. {
  5634. control->dev_down = device_down_cb;
  5635. control->post_reset = device_up_cb;
  5636. control->ssr_priv = priv;
  5637. return 0;
  5638. }
  5639. static struct regulator *tapan_codec_find_regulator(
  5640. struct snd_soc_codec *codec,
  5641. const char *name)
  5642. {
  5643. int i;
  5644. struct wcd9xxx *core = NULL;
  5645. if (codec == NULL) {
  5646. dev_err(codec->dev, "%s: codec not initialized\n", __func__);
  5647. return NULL;
  5648. }
  5649. core = dev_get_drvdata(codec->dev->parent);
  5650. if (core == NULL) {
  5651. dev_err(codec->dev, "%s: core not initialized\n", __func__);
  5652. return NULL;
  5653. }
  5654. for (i = 0; i < core->num_of_supplies; i++) {
  5655. if (core->supplies[i].supply &&
  5656. !strcmp(core->supplies[i].supply, name))
  5657. return core->supplies[i].consumer;
  5658. }
  5659. return NULL;
  5660. }
  5661. static void tapan_enable_config_rco(struct wcd9xxx *core, bool enable)
  5662. {
  5663. struct wcd9xxx_core_resource *core_res = &core->core_res;
  5664. if (enable) {
  5665. wcd9xxx_reg_update(core, WCD9XXX_A_BIAS_CENTRAL_BG_CTL,
  5666. 0x80, 0x80);
  5667. wcd9xxx_reg_update(core, WCD9XXX_A_BIAS_CENTRAL_BG_CTL,
  5668. 0x04, 0x04);
  5669. wcd9xxx_reg_update(core, WCD9XXX_A_BIAS_CENTRAL_BG_CTL,
  5670. 0x01, 0x01);
  5671. usleep_range(1000, 1000);
  5672. wcd9xxx_reg_update(core, WCD9XXX_A_BIAS_CENTRAL_BG_CTL,
  5673. 0x80, 0x00);
  5674. /* Enable RC Oscillator */
  5675. wcd9xxx_reg_update(core, WCD9XXX_A_RC_OSC_FREQ, 0x10, 0x00);
  5676. wcd9xxx_reg_write(core_res, WCD9XXX_A_BIAS_OSC_BG_CTL, 0x17);
  5677. usleep_range(5, 5);
  5678. wcd9xxx_reg_update(core, WCD9XXX_A_RC_OSC_FREQ, 0x80, 0x80);
  5679. wcd9xxx_reg_update(core, WCD9XXX_A_RC_OSC_TEST, 0x80, 0x80);
  5680. usleep_range(10, 10);
  5681. wcd9xxx_reg_update(core, WCD9XXX_A_RC_OSC_TEST, 0x80, 0x00);
  5682. usleep_range(20, 20);
  5683. wcd9xxx_reg_update(core, WCD9XXX_A_CLK_BUFF_EN1, 0x08, 0x08);
  5684. /* Enable MCLK and wait 1ms till it gets enabled */
  5685. wcd9xxx_reg_write(core_res, WCD9XXX_A_CLK_BUFF_EN2, 0x02);
  5686. usleep_range(1000, 1000);
  5687. /* Enable CLK BUFF and wait for 1.2ms */
  5688. wcd9xxx_reg_update(core, WCD9XXX_A_CLK_BUFF_EN1, 0x01, 0x01);
  5689. usleep_range(1000, 1200);
  5690. wcd9xxx_reg_update(core, WCD9XXX_A_CLK_BUFF_EN2, 0x02, 0x00);
  5691. wcd9xxx_reg_update(core, WCD9XXX_A_CLK_BUFF_EN2, 0x04, 0x04);
  5692. wcd9xxx_reg_update(core, WCD9XXX_A_CDC_CLK_MCLK_CTL,
  5693. 0x01, 0x01);
  5694. usleep_range(50, 50);
  5695. } else {
  5696. wcd9xxx_reg_update(core, WCD9XXX_A_CLK_BUFF_EN2, 0x04, 0x00);
  5697. usleep_range(50, 50);
  5698. wcd9xxx_reg_update(core, WCD9XXX_A_CLK_BUFF_EN2, 0x02, 0x02);
  5699. wcd9xxx_reg_update(core, WCD9XXX_A_CLK_BUFF_EN1, 0x05, 0x00);
  5700. usleep_range(50, 50);
  5701. wcd9xxx_reg_update(core, WCD9XXX_A_RC_OSC_FREQ, 0x80, 0x00);
  5702. usleep_range(10, 10);
  5703. wcd9xxx_reg_write(core_res, WCD9XXX_A_BIAS_OSC_BG_CTL, 0x16);
  5704. wcd9xxx_reg_update(core, WCD9XXX_A_BIAS_CENTRAL_BG_CTL,
  5705. 0x03, 0x00);
  5706. usleep_range(100, 100);
  5707. }
  5708. }
  5709. static bool tapan_check_wcd9306(struct device *cdc_dev, bool sensed)
  5710. {
  5711. struct wcd9xxx *core = dev_get_drvdata(cdc_dev->parent);
  5712. u8 reg_val;
  5713. bool ret = true;
  5714. unsigned long timeout;
  5715. bool timedout;
  5716. struct wcd9xxx_core_resource *core_res = &core->core_res;
  5717. if (!core) {
  5718. dev_err(cdc_dev, "%s: core not initialized\n", __func__);
  5719. return -EINVAL;
  5720. }
  5721. tapan_enable_config_rco(core, 1);
  5722. if (sensed == false) {
  5723. reg_val = wcd9xxx_reg_read(core_res, TAPAN_A_QFUSE_CTL);
  5724. wcd9xxx_reg_write(core_res, TAPAN_A_QFUSE_CTL,
  5725. (reg_val | 0x03));
  5726. }
  5727. timeout = jiffies + HZ;
  5728. do {
  5729. if ((wcd9xxx_reg_read(core_res, TAPAN_A_QFUSE_STATUS)))
  5730. break;
  5731. } while (!(timedout = time_after(jiffies, timeout)));
  5732. if (wcd9xxx_reg_read(core_res, TAPAN_A_QFUSE_DATA_OUT1) ||
  5733. wcd9xxx_reg_read(core_res, TAPAN_A_QFUSE_DATA_OUT2)) {
  5734. dev_info(cdc_dev, "%s: wcd9302 detected\n", __func__);
  5735. ret = false;
  5736. } else
  5737. dev_info(cdc_dev, "%s: wcd9306 detected\n", __func__);
  5738. tapan_enable_config_rco(core, 0);
  5739. return ret;
  5740. };
  5741. #ifdef CONFIG_ARCH_MSM8226
  5742. bool codec_probe_done = false;
  5743. bool is_codec_probe_done(void)
  5744. {
  5745. return codec_probe_done;
  5746. }
  5747. EXPORT_SYMBOL(is_codec_probe_done);
  5748. #endif
  5749. static int tapan_codec_probe(struct snd_soc_codec *codec)
  5750. {
  5751. struct wcd9xxx *control;
  5752. struct tapan_priv *tapan;
  5753. struct wcd9xxx_pdata *pdata;
  5754. struct wcd9xxx *wcd9xxx;
  5755. struct snd_soc_dapm_context *dapm = &codec->dapm;
  5756. int ret = 0;
  5757. int i, rco_clk_rate;
  5758. void *ptr = NULL;
  5759. struct wcd9xxx_core_resource *core_res;
  5760. codec->control_data = dev_get_drvdata(codec->dev->parent);
  5761. control = codec->control_data;
  5762. wcd9xxx_ssr_register(control, tapan_device_down,
  5763. tapan_post_reset_cb, (void *)codec);
  5764. dev_info(codec->dev, "%s()\n", __func__);
  5765. tapan = kzalloc(sizeof(struct tapan_priv), GFP_KERNEL);
  5766. if (!tapan) {
  5767. dev_err(codec->dev, "Failed to allocate private data\n");
  5768. return -ENOMEM;
  5769. }
  5770. for (i = 0 ; i < NUM_DECIMATORS; i++) {
  5771. tx_hpf_work[i].tapan = tapan;
  5772. tx_hpf_work[i].decimator = i + 1;
  5773. INIT_DELAYED_WORK(&tx_hpf_work[i].dwork,
  5774. tx_hpf_corner_freq_callback);
  5775. }
  5776. snd_soc_codec_set_drvdata(codec, tapan);
  5777. tapan->ldo_h_count = 0;
  5778. /* codec resmgr module init */
  5779. wcd9xxx = codec->control_data;
  5780. core_res = &wcd9xxx->core_res;
  5781. pdata = dev_get_platdata(codec->dev->parent);
  5782. ret = wcd9xxx_resmgr_init(&tapan->resmgr, codec, core_res, pdata,
  5783. &pdata->micbias, &tapan_reg_address,
  5784. WCD9XXX_CDC_TYPE_TAPAN);
  5785. if (ret) {
  5786. pr_err("%s: wcd9xxx init failed %d\n", __func__, ret);
  5787. kfree(tapan);
  5788. return ret;
  5789. }
  5790. tapan->cp_regulators[CP_REG_BUCK] = tapan_codec_find_regulator(codec,
  5791. WCD9XXX_SUPPLY_BUCK_NAME);
  5792. tapan->cp_regulators[CP_REG_BHELPER] = tapan_codec_find_regulator(codec,
  5793. "cdc-vdd-buckhelper");
  5794. tapan->clsh_d.buck_mv = tapan_codec_get_buck_mv(codec);
  5795. /*
  5796. * If 1.8 volts is requested on the vdd_cp line, then
  5797. * assume that S4 is in a dynamically switchable state
  5798. * and can switch between 1.8 volts and 2.15 volts
  5799. */
  5800. if (tapan->clsh_d.buck_mv == WCD9XXX_CDC_BUCK_MV_1P8)
  5801. tapan->clsh_d.is_dynamic_vdd_cp = true;
  5802. wcd9xxx_clsh_init(&tapan->clsh_d, &tapan->resmgr);
  5803. if (TAPAN_IS_1_0(control->version))
  5804. rco_clk_rate = TAPAN_MCLK_CLK_12P288MHZ;
  5805. else
  5806. rco_clk_rate = TAPAN_MCLK_CLK_9P6MHZ;
  5807. tapan->micb_2_ref_cnt = 0;
  5808. #ifndef CONFIG_SAMSUNG_JACK //Comment Disable MBHC
  5809. ret = wcd9xxx_mbhc_init(&tapan->mbhc, &tapan->resmgr, codec, NULL,
  5810. &mbhc_cb, &cdc_intr_ids, rco_clk_rate,
  5811. TAPAN_CDC_ZDET_SUPPORTED);
  5812. if (ret) {
  5813. pr_err("%s: mbhc init failed %d\n", __func__, ret);
  5814. return ret;
  5815. }
  5816. #endif
  5817. tapan->codec = codec;
  5818. for (i = 0; i < COMPANDER_MAX; i++) {
  5819. tapan->comp_enabled[i] = 0;
  5820. tapan->comp_fs[i] = COMPANDER_FS_48KHZ;
  5821. }
  5822. tapan->intf_type = wcd9xxx_get_intf_type();
  5823. tapan->aux_pga_cnt = 0;
  5824. tapan->aux_l_gain = 0x1F;
  5825. tapan->aux_r_gain = 0x1F;
  5826. tapan->ldo_h_users = 0;
  5827. tapan->micb_2_users = 0;
  5828. tapan_update_reg_defaults(codec);
  5829. tapan_update_reg_mclk_rate(wcd9xxx);
  5830. tapan_codec_init_reg(codec);
  5831. ret = tapan_handle_pdata(tapan);
  5832. if (IS_ERR_VALUE(ret)) {
  5833. dev_err(codec->dev, "%s: bad pdata\n", __func__);
  5834. goto err_pdata;
  5835. }
  5836. if (spkr_drv_wrnd > 0) {
  5837. WCD9XXX_BG_CLK_LOCK(&tapan->resmgr);
  5838. wcd9xxx_resmgr_get_bandgap(&tapan->resmgr,
  5839. WCD9XXX_BANDGAP_AUDIO_MODE);
  5840. WCD9XXX_BG_CLK_UNLOCK(&tapan->resmgr);
  5841. }
  5842. #if defined(CONFIG_SND_SOC_ES705)
  5843. remote_add_codec_controls(codec);
  5844. #elif defined(CONFIG_SND_SOC_ES325_ATLANTIC)
  5845. es325_remote_add_codec_controls(codec);
  5846. #endif
  5847. ptr = kmalloc((sizeof(tapan_rx_chs) +
  5848. sizeof(tapan_tx_chs)), GFP_KERNEL);
  5849. if (!ptr) {
  5850. pr_err("%s: no mem for slim chan ctl data\n", __func__);
  5851. ret = -ENOMEM;
  5852. goto err_nomem_slimch;
  5853. }
  5854. if (tapan->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
  5855. snd_soc_dapm_new_controls(dapm, tapan_dapm_i2s_widgets,
  5856. ARRAY_SIZE(tapan_dapm_i2s_widgets));
  5857. snd_soc_dapm_add_routes(dapm, audio_i2s_map,
  5858. ARRAY_SIZE(audio_i2s_map));
  5859. for (i = 0; i < ARRAY_SIZE(tapan_i2s_dai); i++)
  5860. INIT_LIST_HEAD(&tapan->dai[i].wcd9xxx_ch_list);
  5861. } else if (tapan->intf_type == WCD9XXX_INTERFACE_TYPE_SLIMBUS) {
  5862. for (i = 0; i < NUM_CODEC_DAIS; i++) {
  5863. INIT_LIST_HEAD(&tapan->dai[i].wcd9xxx_ch_list);
  5864. init_waitqueue_head(&tapan->dai[i].dai_wait);
  5865. }
  5866. tapan_init_slim_slave_cfg(codec);
  5867. }
  5868. if (codec_ver == WCD9306) {
  5869. snd_soc_add_codec_controls(codec, tapan_9306_snd_controls,
  5870. ARRAY_SIZE(tapan_9306_snd_controls));
  5871. snd_soc_dapm_new_controls(dapm, tapan_9306_dapm_widgets,
  5872. ARRAY_SIZE(tapan_9306_dapm_widgets));
  5873. snd_soc_dapm_add_routes(dapm, wcd9306_map,
  5874. ARRAY_SIZE(wcd9306_map));
  5875. } else {
  5876. snd_soc_dapm_add_routes(dapm, wcd9302_map,
  5877. ARRAY_SIZE(wcd9302_map));
  5878. }
  5879. control->num_rx_port = TAPAN_RX_MAX;
  5880. control->rx_chs = ptr;
  5881. memcpy(control->rx_chs, tapan_rx_chs, sizeof(tapan_rx_chs));
  5882. control->num_tx_port = TAPAN_TX_MAX;
  5883. control->tx_chs = ptr + sizeof(tapan_rx_chs);
  5884. memcpy(control->tx_chs, tapan_tx_chs, sizeof(tapan_tx_chs));
  5885. snd_soc_dapm_sync(dapm);
  5886. (void) tapan_setup_irqs(tapan);
  5887. atomic_set(&kp_tapan_priv, (unsigned long)tapan);
  5888. mutex_lock(&dapm->codec->mutex);
  5889. if (codec_ver == WCD9306) {
  5890. snd_soc_dapm_disable_pin(dapm, "ANC HPHL");
  5891. snd_soc_dapm_disable_pin(dapm, "ANC HPHR");
  5892. snd_soc_dapm_disable_pin(dapm, "ANC HEADPHONE");
  5893. snd_soc_dapm_disable_pin(dapm, "ANC EAR PA");
  5894. snd_soc_dapm_disable_pin(dapm, "ANC EAR");
  5895. }
  5896. snd_soc_dapm_sync(dapm);
  5897. mutex_unlock(&dapm->codec->mutex);
  5898. codec->ignore_pmdown_time = 1;
  5899. if (ret)
  5900. tapan_cleanup_irqs(tapan);
  5901. #ifdef CONFIG_ARCH_MSM8226
  5902. codec_probe_done = true;
  5903. #endif
  5904. return ret;
  5905. err_pdata:
  5906. kfree(ptr);
  5907. err_nomem_slimch:
  5908. kfree(tapan);
  5909. return ret;
  5910. }
  5911. static int tapan_codec_remove(struct snd_soc_codec *codec)
  5912. {
  5913. struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
  5914. int index = 0;
  5915. WCD9XXX_BG_CLK_LOCK(&tapan->resmgr);
  5916. atomic_set(&kp_tapan_priv, 0);
  5917. if (spkr_drv_wrnd > 0)
  5918. wcd9xxx_resmgr_put_bandgap(&tapan->resmgr,
  5919. WCD9XXX_BANDGAP_AUDIO_MODE);
  5920. WCD9XXX_BG_CLK_UNLOCK(&tapan->resmgr);
  5921. tapan_cleanup_irqs(tapan);
  5922. #ifndef CONFIG_SAMSUNG_JACK //Comment Disable MBHC
  5923. /* cleanup MBHC */
  5924. wcd9xxx_mbhc_deinit(&tapan->mbhc);
  5925. #endif
  5926. /* cleanup resmgr */
  5927. wcd9xxx_resmgr_deinit(&tapan->resmgr);
  5928. for (index = 0; index < CP_REG_MAX; index++)
  5929. tapan->cp_regulators[index] = NULL;
  5930. kfree(tapan);
  5931. return 0;
  5932. }
  5933. static struct snd_soc_codec_driver soc_codec_dev_tapan = {
  5934. .probe = tapan_codec_probe,
  5935. .remove = tapan_codec_remove,
  5936. .read = tapan_read,
  5937. .write = tapan_write,
  5938. .readable_register = tapan_readable,
  5939. .volatile_register = tapan_volatile,
  5940. .reg_cache_size = TAPAN_CACHE_SIZE,
  5941. .reg_cache_default = tapan_reset_reg_defaults,
  5942. .reg_word_size = 1,
  5943. .controls = tapan_common_snd_controls,
  5944. .num_controls = ARRAY_SIZE(tapan_common_snd_controls),
  5945. .dapm_widgets = tapan_common_dapm_widgets,
  5946. .num_dapm_widgets = ARRAY_SIZE(tapan_common_dapm_widgets),
  5947. .dapm_routes = audio_map,
  5948. .num_dapm_routes = ARRAY_SIZE(audio_map),
  5949. };
  5950. #ifdef CONFIG_PM
  5951. static int tapan_suspend(struct device *dev)
  5952. {
  5953. dev_dbg(dev, "%s: system suspend\n", __func__);
  5954. return 0;
  5955. }
  5956. static int tapan_resume(struct device *dev)
  5957. {
  5958. struct platform_device *pdev = to_platform_device(dev);
  5959. struct tapan_priv *tapan = platform_get_drvdata(pdev);
  5960. dev_dbg(dev, "%s: system resume\n", __func__);
  5961. /* Notify */
  5962. wcd9xxx_resmgr_notifier_call(&tapan->resmgr, WCD9XXX_EVENT_POST_RESUME);
  5963. return 0;
  5964. }
  5965. static const struct dev_pm_ops tapan_pm_ops = {
  5966. .suspend = tapan_suspend,
  5967. .resume = tapan_resume,
  5968. };
  5969. #endif
  5970. static int __devinit tapan_probe(struct platform_device *pdev)
  5971. {
  5972. int ret = 0;
  5973. bool is_wcd9306;
  5974. is_wcd9306 = tapan_check_wcd9306(&pdev->dev, false);
  5975. if (is_wcd9306 < 0) {
  5976. dev_info(&pdev->dev, "%s: cannot find codec type, default to 9306\n",
  5977. __func__);
  5978. is_wcd9306 = true;
  5979. }
  5980. codec_ver = is_wcd9306 ? WCD9306 : WCD9302;
  5981. if (!is_wcd9306) {
  5982. if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_SLIMBUS)
  5983. ret = snd_soc_register_codec(&pdev->dev,
  5984. &soc_codec_dev_tapan,
  5985. tapan9302_dai, ARRAY_SIZE(tapan9302_dai));
  5986. else if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_I2C)
  5987. ret = snd_soc_register_codec(&pdev->dev,
  5988. &soc_codec_dev_tapan,
  5989. tapan_i2s_dai, ARRAY_SIZE(tapan_i2s_dai));
  5990. } else {
  5991. if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_SLIMBUS)
  5992. ret = snd_soc_register_codec(&pdev->dev,
  5993. &soc_codec_dev_tapan,
  5994. tapan_dai, ARRAY_SIZE(tapan_dai));
  5995. else if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_I2C)
  5996. ret = snd_soc_register_codec(&pdev->dev,
  5997. &soc_codec_dev_tapan,
  5998. tapan_i2s_dai, ARRAY_SIZE(tapan_i2s_dai));
  5999. }
  6000. return ret;
  6001. }
  6002. static int __devexit tapan_remove(struct platform_device *pdev)
  6003. {
  6004. snd_soc_unregister_codec(&pdev->dev);
  6005. return 0;
  6006. }
  6007. static struct platform_driver tapan_codec_driver = {
  6008. .probe = tapan_probe,
  6009. .remove = tapan_remove,
  6010. .driver = {
  6011. .name = "tapan_codec",
  6012. .owner = THIS_MODULE,
  6013. #ifdef CONFIG_PM
  6014. .pm = &tapan_pm_ops,
  6015. #endif
  6016. },
  6017. };
  6018. static int __init tapan_codec_init(void)
  6019. {
  6020. return platform_driver_register(&tapan_codec_driver);
  6021. }
  6022. static void __exit tapan_codec_exit(void)
  6023. {
  6024. platform_driver_unregister(&tapan_codec_driver);
  6025. }
  6026. module_init(tapan_codec_init);
  6027. module_exit(tapan_codec_exit);
  6028. MODULE_DESCRIPTION("Tapan codec driver");
  6029. MODULE_LICENSE("GPL v2");