wcd938x.c 126 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/module.h>
  6. #include <linux/slab.h>
  7. #include <linux/platform_device.h>
  8. #include <linux/device.h>
  9. #include <linux/delay.h>
  10. #include <linux/kernel.h>
  11. #include <linux/component.h>
  12. #include <sound/soc.h>
  13. #include <sound/tlv.h>
  14. #include <soc/soundwire.h>
  15. #include <linux/regmap.h>
  16. #include <sound/soc.h>
  17. #include <sound/soc-dapm.h>
  18. #include <asoc/wcdcal-hwdep.h>
  19. #include <asoc/msm-cdc-pinctrl.h>
  20. #include <asoc/msm-cdc-supply.h>
  21. #include <dt-bindings/sound/audio-codec-port-types.h>
  22. #include "wcd938x-registers.h"
  23. #include "wcd938x.h"
  24. #include "internal.h"
  25. #define NUM_SWRS_DT_PARAMS 5
  26. #define WCD938X_VARIANT_ENTRY_SIZE 32
  27. #define WCD938X_VERSION_1_0 1
  28. #define WCD938X_VERSION_ENTRY_SIZE 32
  29. #define EAR_RX_PATH_AUX 1
  30. #define ADC_MODE_VAL_HIFI 0x01
  31. #define ADC_MODE_VAL_LO_HIF 0x02
  32. #define ADC_MODE_VAL_NORMAL 0x03
  33. #define ADC_MODE_VAL_LP 0x05
  34. #define ADC_MODE_VAL_ULP1 0x09
  35. #define ADC_MODE_VAL_ULP2 0x0B
  36. #define NUM_ATTEMPTS 5
  37. #define DAPM_MICBIAS1_STANDALONE "MIC BIAS1 Standalone"
  38. #define DAPM_MICBIAS2_STANDALONE "MIC BIAS2 Standalone"
  39. #define DAPM_MICBIAS3_STANDALONE "MIC BIAS3 Standalone"
  40. #define DAPM_MICBIAS4_STANDALONE "MIC BIAS4 Standalone"
  41. #define WCD938X_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
  42. SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\
  43. SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000 |\
  44. SNDRV_PCM_RATE_384000)
  45. /* Fractional Rates */
  46. #define WCD938X_FRAC_RATES (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_88200 |\
  47. SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_352800)
  48. #define WCD938X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
  49. SNDRV_PCM_FMTBIT_S24_LE |\
  50. SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
  51. enum {
  52. CODEC_TX = 0,
  53. CODEC_RX,
  54. };
  55. enum {
  56. WCD_ADC1 = 0,
  57. WCD_ADC2,
  58. WCD_ADC3,
  59. WCD_ADC4,
  60. ALLOW_BUCK_DISABLE,
  61. HPH_COMP_DELAY,
  62. HPH_PA_DELAY,
  63. AMIC2_BCS_ENABLE,
  64. WCD_SUPPLIES_LPM_MODE,
  65. WCD_ADC1_MODE,
  66. WCD_ADC2_MODE,
  67. WCD_ADC3_MODE,
  68. WCD_ADC4_MODE,
  69. };
  70. enum {
  71. ADC_MODE_INVALID = 0,
  72. ADC_MODE_HIFI,
  73. ADC_MODE_LO_HIF,
  74. ADC_MODE_NORMAL,
  75. ADC_MODE_LP,
  76. ADC_MODE_ULP1,
  77. ADC_MODE_ULP2,
  78. };
  79. static u8 tx_mode_bit[] = {
  80. [ADC_MODE_INVALID] = 0x00,
  81. [ADC_MODE_HIFI] = 0x01,
  82. [ADC_MODE_LO_HIF] = 0x02,
  83. [ADC_MODE_NORMAL] = 0x04,
  84. [ADC_MODE_LP] = 0x08,
  85. [ADC_MODE_ULP1] = 0x10,
  86. [ADC_MODE_ULP2] = 0x20,
  87. };
  88. static const DECLARE_TLV_DB_SCALE(line_gain, 0, 7, 1);
  89. static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 25, 1);
  90. static int wcd938x_handle_post_irq(void *data);
  91. static int wcd938x_reset(struct device *dev);
  92. static int wcd938x_reset_low(struct device *dev);
  93. static const struct regmap_irq wcd938x_irqs[WCD938X_NUM_IRQS] = {
  94. REGMAP_IRQ_REG(WCD938X_IRQ_MBHC_BUTTON_PRESS_DET, 0, 0x01),
  95. REGMAP_IRQ_REG(WCD938X_IRQ_MBHC_BUTTON_RELEASE_DET, 0, 0x02),
  96. REGMAP_IRQ_REG(WCD938X_IRQ_MBHC_ELECT_INS_REM_DET, 0, 0x04),
  97. REGMAP_IRQ_REG(WCD938X_IRQ_MBHC_ELECT_INS_REM_LEG_DET, 0, 0x08),
  98. REGMAP_IRQ_REG(WCD938X_IRQ_MBHC_SW_DET, 0, 0x10),
  99. REGMAP_IRQ_REG(WCD938X_IRQ_HPHR_OCP_INT, 0, 0x20),
  100. REGMAP_IRQ_REG(WCD938X_IRQ_HPHR_CNP_INT, 0, 0x40),
  101. REGMAP_IRQ_REG(WCD938X_IRQ_HPHL_OCP_INT, 0, 0x80),
  102. REGMAP_IRQ_REG(WCD938X_IRQ_HPHL_CNP_INT, 1, 0x01),
  103. REGMAP_IRQ_REG(WCD938X_IRQ_EAR_CNP_INT, 1, 0x02),
  104. REGMAP_IRQ_REG(WCD938X_IRQ_EAR_SCD_INT, 1, 0x04),
  105. REGMAP_IRQ_REG(WCD938X_IRQ_AUX_CNP_INT, 1, 0x08),
  106. REGMAP_IRQ_REG(WCD938X_IRQ_AUX_SCD_INT, 1, 0x10),
  107. REGMAP_IRQ_REG(WCD938X_IRQ_HPHL_PDM_WD_INT, 1, 0x20),
  108. REGMAP_IRQ_REG(WCD938X_IRQ_HPHR_PDM_WD_INT, 1, 0x40),
  109. REGMAP_IRQ_REG(WCD938X_IRQ_AUX_PDM_WD_INT, 1, 0x80),
  110. REGMAP_IRQ_REG(WCD938X_IRQ_LDORT_SCD_INT, 2, 0x01),
  111. REGMAP_IRQ_REG(WCD938X_IRQ_MBHC_MOISTURE_INT, 2, 0x02),
  112. REGMAP_IRQ_REG(WCD938X_IRQ_HPHL_SURGE_DET_INT, 2, 0x04),
  113. REGMAP_IRQ_REG(WCD938X_IRQ_HPHR_SURGE_DET_INT, 2, 0x08),
  114. };
  115. static struct regmap_irq_chip wcd938x_regmap_irq_chip = {
  116. .name = "wcd938x",
  117. .irqs = wcd938x_irqs,
  118. .num_irqs = ARRAY_SIZE(wcd938x_irqs),
  119. .num_regs = 3,
  120. .status_base = WCD938X_DIGITAL_INTR_STATUS_0,
  121. .mask_base = WCD938X_DIGITAL_INTR_MASK_0,
  122. .type_base = WCD938X_DIGITAL_INTR_LEVEL_0,
  123. .ack_base = WCD938X_DIGITAL_INTR_CLEAR_0,
  124. .use_ack = 1,
  125. .runtime_pm = false,
  126. .handle_post_irq = wcd938x_handle_post_irq,
  127. .irq_drv_data = NULL,
  128. };
  129. static int wcd938x_handle_post_irq(void *data)
  130. {
  131. struct wcd938x_priv *wcd938x = data;
  132. u32 sts1 = 0, sts2 = 0, sts3 = 0;
  133. regmap_read(wcd938x->regmap, WCD938X_DIGITAL_INTR_STATUS_0, &sts1);
  134. regmap_read(wcd938x->regmap, WCD938X_DIGITAL_INTR_STATUS_1, &sts2);
  135. regmap_read(wcd938x->regmap, WCD938X_DIGITAL_INTR_STATUS_2, &sts3);
  136. wcd938x->tx_swr_dev->slave_irq_pending =
  137. ((sts1 || sts2 || sts3) ? true : false);
  138. return IRQ_HANDLED;
  139. }
  140. static int wcd938x_swr_slv_get_current_bank(struct swr_device *dev, u8 devnum)
  141. {
  142. int ret = 0;
  143. int bank = 0;
  144. ret = swr_read(dev, devnum, SWR_SCP_CONTROL, &bank, 1);
  145. if (ret)
  146. return -EINVAL;
  147. return ((bank & 0x40) ? 1: 0);
  148. }
  149. static int wcd938x_get_clk_rate(int mode)
  150. {
  151. int rate;
  152. switch (mode) {
  153. case ADC_MODE_ULP2:
  154. rate = SWR_CLK_RATE_0P6MHZ;
  155. break;
  156. case ADC_MODE_ULP1:
  157. rate = SWR_CLK_RATE_1P2MHZ;
  158. break;
  159. case ADC_MODE_LP:
  160. rate = SWR_CLK_RATE_4P8MHZ;
  161. break;
  162. case ADC_MODE_NORMAL:
  163. case ADC_MODE_LO_HIF:
  164. case ADC_MODE_HIFI:
  165. case ADC_MODE_INVALID:
  166. default:
  167. rate = SWR_CLK_RATE_9P6MHZ;
  168. break;
  169. }
  170. return rate;
  171. }
  172. static int wcd938x_set_swr_clk_rate(struct snd_soc_component *component,
  173. int rate, int bank)
  174. {
  175. u8 mask = (bank ? 0xF0 : 0x0F);
  176. u8 val = 0;
  177. switch (rate) {
  178. case SWR_CLK_RATE_0P6MHZ:
  179. val = (bank ? 0x60 : 0x06);
  180. break;
  181. case SWR_CLK_RATE_1P2MHZ:
  182. val = (bank ? 0x50 : 0x05);
  183. break;
  184. case SWR_CLK_RATE_2P4MHZ:
  185. val = (bank ? 0x30 : 0x03);
  186. break;
  187. case SWR_CLK_RATE_4P8MHZ:
  188. val = (bank ? 0x10 : 0x01);
  189. break;
  190. case SWR_CLK_RATE_9P6MHZ:
  191. default:
  192. val = 0x00;
  193. break;
  194. }
  195. snd_soc_component_update_bits(component,
  196. WCD938X_DIGITAL_SWR_TX_CLK_RATE,
  197. mask, val);
  198. return 0;
  199. }
  200. static int wcd938x_init_reg(struct snd_soc_component *component)
  201. {
  202. snd_soc_component_update_bits(component, WCD938X_SLEEP_CTL, 0x0E, 0x0E);
  203. snd_soc_component_update_bits(component, WCD938X_SLEEP_CTL, 0x80, 0x80);
  204. /* 1 msec delay as per HW requirement */
  205. usleep_range(1000, 1010);
  206. snd_soc_component_update_bits(component, WCD938X_SLEEP_CTL, 0x40, 0x40);
  207. /* 1 msec delay as per HW requirement */
  208. usleep_range(1000, 1010);
  209. snd_soc_component_update_bits(component, WCD938X_LDORXTX_CONFIG,
  210. 0x10, 0x00);
  211. snd_soc_component_update_bits(component, WCD938X_BIAS_VBG_FINE_ADJ,
  212. 0xF0, 0x80);
  213. snd_soc_component_update_bits(component, WCD938X_ANA_BIAS, 0x80, 0x80);
  214. snd_soc_component_update_bits(component, WCD938X_ANA_BIAS, 0x40, 0x40);
  215. /* 10 msec delay as per HW requirement */
  216. usleep_range(10000, 10010);
  217. snd_soc_component_update_bits(component, WCD938X_ANA_BIAS, 0x40, 0x00);
  218. snd_soc_component_update_bits(component,
  219. WCD938X_HPH_NEW_INT_RDAC_GAIN_CTL,
  220. 0xF0, 0x00);
  221. snd_soc_component_update_bits(component,
  222. WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_L_NEW,
  223. 0x1F, 0x15);
  224. snd_soc_component_update_bits(component,
  225. WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_R_NEW,
  226. 0x1F, 0x15);
  227. snd_soc_component_update_bits(component, WCD938X_HPH_REFBUFF_UHQA_CTL,
  228. 0xC0, 0x80);
  229. snd_soc_component_update_bits(component, WCD938X_DIGITAL_CDC_DMIC_CTL,
  230. 0x02, 0x02);
  231. snd_soc_component_update_bits(component,
  232. WCD938X_TX_COM_NEW_INT_TXFE_ICTRL_STG2CASC_ULP,
  233. 0xFF, 0x14);
  234. snd_soc_component_update_bits(component,
  235. WCD938X_TX_COM_NEW_INT_TXFE_ICTRL_STG2MAIN_ULP,
  236. 0x1F, 0x08);
  237. snd_soc_component_update_bits(component,
  238. WCD938X_DIGITAL_TX_REQ_FB_CTL_0, 0xFF, 0x55);
  239. snd_soc_component_update_bits(component,
  240. WCD938X_DIGITAL_TX_REQ_FB_CTL_1, 0xFF, 0x44);
  241. snd_soc_component_update_bits(component,
  242. WCD938X_DIGITAL_TX_REQ_FB_CTL_2, 0xFF, 0x11);
  243. snd_soc_component_update_bits(component,
  244. WCD938X_DIGITAL_TX_REQ_FB_CTL_3, 0xFF, 0x00);
  245. snd_soc_component_update_bits(component,
  246. WCD938X_DIGITAL_TX_REQ_FB_CTL_4, 0xFF, 0x00);
  247. snd_soc_component_update_bits(component,
  248. WCD938X_MICB1_TEST_CTL_1, 0xE0, 0xE0);
  249. snd_soc_component_update_bits(component,
  250. WCD938X_MICB2_TEST_CTL_1, 0xE0, 0xE0);
  251. snd_soc_component_update_bits(component,
  252. WCD938X_MICB3_TEST_CTL_1, 0xE0, 0xE0);
  253. snd_soc_component_update_bits(component,
  254. WCD938X_MICB4_TEST_CTL_1, 0xE0, 0xE0);
  255. snd_soc_component_update_bits(component,
  256. WCD938X_TX_3_4_TEST_BLK_EN2, 0x01, 0x00);
  257. snd_soc_component_update_bits(component, WCD938X_SLEEP_CTL, 0x0E,
  258. ((snd_soc_component_read32(component,
  259. WCD938X_DIGITAL_EFUSE_REG_30) & 0x07) << 1));
  260. snd_soc_component_update_bits(component,
  261. WCD938X_HPH_SURGE_HPHLR_SURGE_EN, 0xC0, 0xC0);
  262. return 0;
  263. }
  264. static int wcd938x_set_port_params(struct snd_soc_component *component,
  265. u8 slv_prt_type, u8 *port_id, u8 *num_ch,
  266. u8 *ch_mask, u32 *ch_rate,
  267. u8 *port_type, u8 path)
  268. {
  269. int i, j;
  270. u8 num_ports = 0;
  271. struct codec_port_info (*map)[MAX_PORT][MAX_CH_PER_PORT];
  272. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  273. switch (path) {
  274. case CODEC_RX:
  275. map = &wcd938x->rx_port_mapping;
  276. num_ports = wcd938x->num_rx_ports;
  277. break;
  278. case CODEC_TX:
  279. map = &wcd938x->tx_port_mapping;
  280. num_ports = wcd938x->num_tx_ports;
  281. break;
  282. default:
  283. dev_err(component->dev, "%s Invalid path selected %u\n",
  284. __func__, path);
  285. return -EINVAL;
  286. }
  287. for (i = 0; i <= num_ports; i++) {
  288. for (j = 0; j < MAX_CH_PER_PORT; j++) {
  289. if ((*map)[i][j].slave_port_type == slv_prt_type)
  290. goto found;
  291. }
  292. }
  293. found:
  294. if (i > num_ports || j == MAX_CH_PER_PORT) {
  295. dev_err(component->dev, "%s Failed to find slave port for type %u\n",
  296. __func__, slv_prt_type);
  297. return -EINVAL;
  298. }
  299. *port_id = i;
  300. *num_ch = (*map)[i][j].num_ch;
  301. *ch_mask = (*map)[i][j].ch_mask;
  302. *ch_rate = (*map)[i][j].ch_rate;
  303. *port_type = (*map)[i][j].master_port_type;
  304. return 0;
  305. }
  306. static int wcd938x_parse_port_mapping(struct device *dev,
  307. char *prop, u8 path)
  308. {
  309. u32 *dt_array, map_size, map_length;
  310. u32 port_num = 0, ch_mask, ch_rate, old_port_num = 0;
  311. u32 slave_port_type, master_port_type;
  312. u32 i, ch_iter = 0;
  313. int ret = 0;
  314. u8 *num_ports = NULL;
  315. struct codec_port_info (*map)[MAX_PORT][MAX_CH_PER_PORT];
  316. struct wcd938x_priv *wcd938x = dev_get_drvdata(dev);
  317. switch (path) {
  318. case CODEC_RX:
  319. map = &wcd938x->rx_port_mapping;
  320. num_ports = &wcd938x->num_rx_ports;
  321. break;
  322. case CODEC_TX:
  323. map = &wcd938x->tx_port_mapping;
  324. num_ports = &wcd938x->num_tx_ports;
  325. break;
  326. default:
  327. dev_err(dev, "%s Invalid path selected %u\n",
  328. __func__, path);
  329. return -EINVAL;
  330. }
  331. if (!of_find_property(dev->of_node, prop,
  332. &map_size)) {
  333. dev_err(dev, "missing port mapping prop %s\n", prop);
  334. ret = -EINVAL;
  335. goto err_port_map;
  336. }
  337. map_length = map_size / (NUM_SWRS_DT_PARAMS * sizeof(u32));
  338. dt_array = kzalloc(map_size, GFP_KERNEL);
  339. if (!dt_array) {
  340. ret = -ENOMEM;
  341. goto err_alloc;
  342. }
  343. ret = of_property_read_u32_array(dev->of_node, prop, dt_array,
  344. NUM_SWRS_DT_PARAMS * map_length);
  345. if (ret) {
  346. dev_err(dev, "%s: Failed to read port mapping from prop %s\n",
  347. __func__, prop);
  348. goto err_pdata_fail;
  349. }
  350. for (i = 0; i < map_length; i++) {
  351. port_num = dt_array[NUM_SWRS_DT_PARAMS * i];
  352. slave_port_type = dt_array[NUM_SWRS_DT_PARAMS * i + 1];
  353. ch_mask = dt_array[NUM_SWRS_DT_PARAMS * i + 2];
  354. ch_rate = dt_array[NUM_SWRS_DT_PARAMS * i + 3];
  355. master_port_type = dt_array[NUM_SWRS_DT_PARAMS * i + 4];
  356. if (port_num != old_port_num)
  357. ch_iter = 0;
  358. (*map)[port_num][ch_iter].slave_port_type = slave_port_type;
  359. (*map)[port_num][ch_iter].ch_mask = ch_mask;
  360. (*map)[port_num][ch_iter].master_port_type = master_port_type;
  361. (*map)[port_num][ch_iter].num_ch = __sw_hweight8(ch_mask);
  362. (*map)[port_num][ch_iter++].ch_rate = ch_rate;
  363. old_port_num = port_num;
  364. }
  365. *num_ports = port_num;
  366. kfree(dt_array);
  367. return 0;
  368. err_pdata_fail:
  369. kfree(dt_array);
  370. err_alloc:
  371. err_port_map:
  372. return ret;
  373. }
  374. static int wcd938x_tx_connect_port(struct snd_soc_component *component,
  375. u8 slv_port_type, int clk_rate,
  376. u8 enable)
  377. {
  378. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  379. u8 port_id, num_ch, ch_mask;
  380. u8 ch_type = 0;
  381. u32 ch_rate;
  382. int slave_ch_idx;
  383. u8 num_port = 1;
  384. int ret = 0;
  385. ret = wcd938x_set_port_params(component, slv_port_type, &port_id,
  386. &num_ch, &ch_mask, &ch_rate,
  387. &ch_type, CODEC_TX);
  388. if (ret)
  389. return ret;
  390. if (clk_rate)
  391. ch_rate = clk_rate;
  392. slave_ch_idx = wcd938x_slave_get_slave_ch_val(slv_port_type);
  393. if (slave_ch_idx != -EINVAL)
  394. ch_type = wcd938x->tx_master_ch_map[slave_ch_idx];
  395. dev_dbg(component->dev, "%s slv_ch_idx: %d, mstr_ch_type: %d\n",
  396. __func__, slave_ch_idx, ch_type);
  397. if (enable)
  398. ret = swr_connect_port(wcd938x->tx_swr_dev, &port_id,
  399. num_port, &ch_mask, &ch_rate,
  400. &num_ch, &ch_type);
  401. else
  402. ret = swr_disconnect_port(wcd938x->tx_swr_dev, &port_id,
  403. num_port, &ch_mask, &ch_type);
  404. return ret;
  405. }
  406. static int wcd938x_rx_connect_port(struct snd_soc_component *component,
  407. u8 slv_port_type, u8 enable)
  408. {
  409. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  410. u8 port_id, num_ch, ch_mask, port_type;
  411. u32 ch_rate;
  412. u8 num_port = 1;
  413. int ret = 0;
  414. ret = wcd938x_set_port_params(component, slv_port_type, &port_id,
  415. &num_ch, &ch_mask, &ch_rate,
  416. &port_type, CODEC_RX);
  417. if (ret)
  418. return ret;
  419. if (enable)
  420. ret = swr_connect_port(wcd938x->rx_swr_dev, &port_id,
  421. num_port, &ch_mask, &ch_rate,
  422. &num_ch, &port_type);
  423. else
  424. ret = swr_disconnect_port(wcd938x->rx_swr_dev, &port_id,
  425. num_port, &ch_mask, &port_type);
  426. return ret;
  427. }
  428. static int wcd938x_rx_clk_enable(struct snd_soc_component *component)
  429. {
  430. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  431. if (wcd938x->rx_clk_cnt == 0) {
  432. snd_soc_component_update_bits(component,
  433. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x01, 0x01);
  434. snd_soc_component_update_bits(component,
  435. WCD938X_ANA_RX_SUPPLIES, 0x01, 0x01);
  436. snd_soc_component_update_bits(component,
  437. WCD938X_DIGITAL_CDC_RX0_CTL, 0x40, 0x00);
  438. snd_soc_component_update_bits(component,
  439. WCD938X_DIGITAL_CDC_RX1_CTL, 0x40, 0x00);
  440. snd_soc_component_update_bits(component,
  441. WCD938X_DIGITAL_CDC_RX2_CTL, 0x40, 0x00);
  442. snd_soc_component_update_bits(component,
  443. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x02, 0x02);
  444. snd_soc_component_update_bits(component,
  445. WCD938X_AUX_AUXPA, 0x10, 0x10);
  446. }
  447. wcd938x->rx_clk_cnt++;
  448. return 0;
  449. }
  450. static int wcd938x_rx_clk_disable(struct snd_soc_component *component)
  451. {
  452. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  453. wcd938x->rx_clk_cnt--;
  454. if (wcd938x->rx_clk_cnt == 0) {
  455. snd_soc_component_update_bits(component,
  456. WCD938X_ANA_RX_SUPPLIES, 0x40, 0x00);
  457. snd_soc_component_update_bits(component,
  458. WCD938X_ANA_RX_SUPPLIES, 0x80, 0x00);
  459. snd_soc_component_update_bits(component,
  460. WCD938X_ANA_RX_SUPPLIES, 0x01, 0x00);
  461. snd_soc_component_update_bits(component,
  462. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x02, 0x00);
  463. snd_soc_component_update_bits(component,
  464. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x01, 0x00);
  465. }
  466. return 0;
  467. }
  468. /*
  469. * wcd938x_soc_get_mbhc: get wcd938x_mbhc handle of corresponding component
  470. * @component: handle to snd_soc_component *
  471. *
  472. * return wcd938x_mbhc handle or error code in case of failure
  473. */
  474. struct wcd938x_mbhc *wcd938x_soc_get_mbhc(struct snd_soc_component *component)
  475. {
  476. struct wcd938x_priv *wcd938x;
  477. if (!component) {
  478. pr_err("%s: Invalid params, NULL component\n", __func__);
  479. return NULL;
  480. }
  481. wcd938x = snd_soc_component_get_drvdata(component);
  482. if (!wcd938x) {
  483. pr_err("%s: wcd938x is NULL\n", __func__);
  484. return NULL;
  485. }
  486. return wcd938x->mbhc;
  487. }
  488. EXPORT_SYMBOL(wcd938x_soc_get_mbhc);
  489. static int wcd938x_codec_hphl_dac_event(struct snd_soc_dapm_widget *w,
  490. struct snd_kcontrol *kcontrol,
  491. int event)
  492. {
  493. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  494. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  495. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  496. w->name, event);
  497. switch (event) {
  498. case SND_SOC_DAPM_PRE_PMU:
  499. wcd938x_rx_clk_enable(component);
  500. snd_soc_component_update_bits(component,
  501. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x01, 0x01);
  502. snd_soc_component_update_bits(component,
  503. WCD938X_DIGITAL_CDC_HPH_GAIN_CTL, 0x04, 0x04);
  504. snd_soc_component_update_bits(component,
  505. WCD938X_HPH_RDAC_CLK_CTL1, 0x80, 0x00);
  506. break;
  507. case SND_SOC_DAPM_POST_PMU:
  508. snd_soc_component_update_bits(component,
  509. WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_L, 0x0F, 0x02);
  510. if (wcd938x->comp1_enable) {
  511. snd_soc_component_update_bits(component,
  512. WCD938X_DIGITAL_CDC_COMP_CTL_0, 0x02, 0x02);
  513. /* 5msec compander delay as per HW requirement */
  514. if (!wcd938x->comp2_enable ||
  515. (snd_soc_component_read32(component,
  516. WCD938X_DIGITAL_CDC_COMP_CTL_0) & 0x01))
  517. usleep_range(5000, 5010);
  518. snd_soc_component_update_bits(component,
  519. WCD938X_HPH_NEW_INT_HPH_TIMER1, 0x02, 0x00);
  520. } else {
  521. snd_soc_component_update_bits(component,
  522. WCD938X_DIGITAL_CDC_COMP_CTL_0,
  523. 0x02, 0x00);
  524. snd_soc_component_update_bits(component,
  525. WCD938X_HPH_L_EN, 0x20, 0x20);
  526. }
  527. break;
  528. case SND_SOC_DAPM_POST_PMD:
  529. snd_soc_component_update_bits(component,
  530. WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_R,
  531. 0x0F, 0x01);
  532. break;
  533. }
  534. return 0;
  535. }
  536. static int wcd938x_codec_hphr_dac_event(struct snd_soc_dapm_widget *w,
  537. struct snd_kcontrol *kcontrol,
  538. int event)
  539. {
  540. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  541. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  542. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  543. w->name, event);
  544. switch (event) {
  545. case SND_SOC_DAPM_PRE_PMU:
  546. wcd938x_rx_clk_enable(component);
  547. snd_soc_component_update_bits(component,
  548. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x02, 0x02);
  549. snd_soc_component_update_bits(component,
  550. WCD938X_DIGITAL_CDC_HPH_GAIN_CTL, 0x08, 0x08);
  551. snd_soc_component_update_bits(component,
  552. WCD938X_HPH_RDAC_CLK_CTL1, 0x80, 0x00);
  553. break;
  554. case SND_SOC_DAPM_POST_PMU:
  555. snd_soc_component_update_bits(component,
  556. WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_R, 0x0F, 0x02);
  557. if (wcd938x->comp2_enable) {
  558. snd_soc_component_update_bits(component,
  559. WCD938X_DIGITAL_CDC_COMP_CTL_0, 0x01, 0x01);
  560. /* 5msec compander delay as per HW requirement */
  561. if (!wcd938x->comp1_enable ||
  562. (snd_soc_component_read32(component,
  563. WCD938X_DIGITAL_CDC_COMP_CTL_0) & 0x02))
  564. usleep_range(5000, 5010);
  565. snd_soc_component_update_bits(component,
  566. WCD938X_HPH_NEW_INT_HPH_TIMER1, 0x02, 0x00);
  567. } else {
  568. snd_soc_component_update_bits(component,
  569. WCD938X_DIGITAL_CDC_COMP_CTL_0,
  570. 0x01, 0x00);
  571. snd_soc_component_update_bits(component,
  572. WCD938X_HPH_R_EN, 0x20, 0x20);
  573. }
  574. break;
  575. case SND_SOC_DAPM_POST_PMD:
  576. snd_soc_component_update_bits(component,
  577. WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_R,
  578. 0x0F, 0x01);
  579. break;
  580. }
  581. return 0;
  582. }
  583. static int wcd938x_codec_ear_dac_event(struct snd_soc_dapm_widget *w,
  584. struct snd_kcontrol *kcontrol,
  585. int event)
  586. {
  587. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  588. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  589. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  590. w->name, event);
  591. switch (event) {
  592. case SND_SOC_DAPM_PRE_PMU:
  593. wcd938x_rx_clk_enable(component);
  594. wcd938x->ear_rx_path =
  595. snd_soc_component_read32(
  596. component, WCD938X_DIGITAL_CDC_EAR_PATH_CTL);
  597. if (wcd938x->ear_rx_path & EAR_RX_PATH_AUX) {
  598. snd_soc_component_update_bits(component,
  599. WCD938X_EAR_EAR_DAC_CON, 0x80, 0x00);
  600. snd_soc_component_update_bits(component,
  601. WCD938X_DIGITAL_CDC_AUX_GAIN_CTL, 0x01, 0x01);
  602. snd_soc_component_update_bits(component,
  603. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x04, 0x04);
  604. snd_soc_component_update_bits(component,
  605. WCD938X_ANA_EAR_COMPANDER_CTL, 0x80, 0x80);
  606. } else {
  607. snd_soc_component_update_bits(component,
  608. WCD938X_DIGITAL_CDC_HPH_GAIN_CTL, 0x04, 0x04);
  609. snd_soc_component_update_bits(component,
  610. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x01, 0x01);
  611. if (wcd938x->comp1_enable)
  612. snd_soc_component_update_bits(component,
  613. WCD938X_DIGITAL_CDC_COMP_CTL_0,
  614. 0x02, 0x02);
  615. }
  616. /* 5 msec delay as per HW requirement */
  617. usleep_range(5000, 5010);
  618. if (wcd938x->flyback_cur_det_disable == 0)
  619. snd_soc_component_update_bits(component,
  620. WCD938X_FLYBACK_EN,
  621. 0x04, 0x00);
  622. wcd938x->flyback_cur_det_disable++;
  623. wcd_cls_h_fsm(component, &wcd938x->clsh_info,
  624. WCD_CLSH_EVENT_PRE_DAC,
  625. WCD_CLSH_STATE_EAR,
  626. wcd938x->hph_mode);
  627. break;
  628. case SND_SOC_DAPM_POST_PMD:
  629. if (wcd938x->ear_rx_path & EAR_RX_PATH_AUX) {
  630. snd_soc_component_update_bits(component,
  631. WCD938X_DIGITAL_CDC_AUX_GAIN_CTL, 0x01, 0x00);
  632. snd_soc_component_update_bits(component,
  633. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x04, 0x00);
  634. } else {
  635. snd_soc_component_update_bits(component,
  636. WCD938X_DIGITAL_CDC_HPH_GAIN_CTL, 0x04, 0x00);
  637. snd_soc_component_update_bits(component,
  638. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x01, 0x00);
  639. if (wcd938x->comp1_enable)
  640. snd_soc_component_update_bits(component,
  641. WCD938X_DIGITAL_CDC_COMP_CTL_0,
  642. 0x02, 0x00);
  643. }
  644. snd_soc_component_update_bits(component,
  645. WCD938X_ANA_EAR_COMPANDER_CTL, 0x80, 0x00);
  646. snd_soc_component_update_bits(component,
  647. WCD938X_EAR_EAR_DAC_CON, 0x80, 0x80);
  648. break;
  649. };
  650. return 0;
  651. }
  652. static int wcd938x_codec_aux_dac_event(struct snd_soc_dapm_widget *w,
  653. struct snd_kcontrol *kcontrol,
  654. int event)
  655. {
  656. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  657. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  658. int ret = 0;
  659. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  660. w->name, event);
  661. switch (event) {
  662. case SND_SOC_DAPM_PRE_PMU:
  663. wcd938x_rx_clk_enable(component);
  664. snd_soc_component_update_bits(component,
  665. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x04, 0x04);
  666. snd_soc_component_update_bits(component,
  667. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x04, 0x04);
  668. snd_soc_component_update_bits(component,
  669. WCD938X_DIGITAL_CDC_AUX_GAIN_CTL, 0x01, 0x01);
  670. if (wcd938x->flyback_cur_det_disable == 0)
  671. snd_soc_component_update_bits(component,
  672. WCD938X_FLYBACK_EN,
  673. 0x04, 0x00);
  674. wcd938x->flyback_cur_det_disable++;
  675. wcd_cls_h_fsm(component, &wcd938x->clsh_info,
  676. WCD_CLSH_EVENT_PRE_DAC,
  677. WCD_CLSH_STATE_AUX,
  678. wcd938x->hph_mode);
  679. break;
  680. case SND_SOC_DAPM_POST_PMD:
  681. snd_soc_component_update_bits(component,
  682. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x04, 0x00);
  683. break;
  684. };
  685. return ret;
  686. }
  687. static int wcd938x_codec_enable_hphr_pa(struct snd_soc_dapm_widget *w,
  688. struct snd_kcontrol *kcontrol,
  689. int event)
  690. {
  691. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  692. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  693. int ret = 0;
  694. int hph_mode = wcd938x->hph_mode;
  695. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  696. w->name, event);
  697. switch (event) {
  698. case SND_SOC_DAPM_PRE_PMU:
  699. if (wcd938x->ldoh)
  700. snd_soc_component_update_bits(component,
  701. WCD938X_LDOH_MODE,
  702. 0x80, 0x80);
  703. if (wcd938x->update_wcd_event)
  704. wcd938x->update_wcd_event(wcd938x->handle,
  705. WCD_BOLERO_EVT_RX_MUTE,
  706. (WCD_RX2 << 0x10 | 0x1));
  707. ret = swr_slvdev_datapath_control(wcd938x->rx_swr_dev,
  708. wcd938x->rx_swr_dev->dev_num,
  709. true);
  710. wcd_cls_h_fsm(component, &wcd938x->clsh_info,
  711. WCD_CLSH_EVENT_PRE_DAC,
  712. WCD_CLSH_STATE_HPHR,
  713. hph_mode);
  714. wcd_clsh_set_hph_mode(component, CLS_H_HIFI);
  715. if (hph_mode == CLS_H_LP || hph_mode == CLS_H_LOHIFI ||
  716. hph_mode == CLS_H_ULP) {
  717. snd_soc_component_update_bits(component,
  718. WCD938X_HPH_REFBUFF_LP_CTL, 0x01, 0x01);
  719. }
  720. snd_soc_component_update_bits(component, WCD938X_ANA_HPH,
  721. 0x10, 0x10);
  722. wcd_clsh_set_hph_mode(component, hph_mode);
  723. /* 100 usec delay as per HW requirement */
  724. usleep_range(100, 110);
  725. set_bit(HPH_PA_DELAY, &wcd938x->status_mask);
  726. snd_soc_component_update_bits(component,
  727. WCD938X_DIGITAL_PDM_WD_CTL1, 0x07, 0x03);
  728. break;
  729. case SND_SOC_DAPM_POST_PMU:
  730. /*
  731. * 7ms sleep is required if compander is enabled as per
  732. * HW requirement. If compander is disabled, then
  733. * 20ms delay is required.
  734. */
  735. if (test_bit(HPH_PA_DELAY, &wcd938x->status_mask)) {
  736. if (!wcd938x->comp2_enable)
  737. usleep_range(20000, 20100);
  738. else
  739. usleep_range(7000, 7100);
  740. if (hph_mode == CLS_H_LP ||
  741. hph_mode == CLS_H_LOHIFI ||
  742. hph_mode == CLS_H_ULP)
  743. snd_soc_component_update_bits(component,
  744. WCD938X_HPH_REFBUFF_LP_CTL, 0x01,
  745. 0x00);
  746. clear_bit(HPH_PA_DELAY, &wcd938x->status_mask);
  747. }
  748. snd_soc_component_update_bits(component,
  749. WCD938X_HPH_NEW_INT_HPH_TIMER1, 0x02, 0x02);
  750. if (hph_mode == CLS_AB || hph_mode == CLS_AB_HIFI ||
  751. hph_mode == CLS_AB_LP || hph_mode == CLS_AB_LOHIFI)
  752. snd_soc_component_update_bits(component,
  753. WCD938X_ANA_RX_SUPPLIES, 0x02, 0x02);
  754. if (wcd938x->update_wcd_event)
  755. wcd938x->update_wcd_event(wcd938x->handle,
  756. WCD_BOLERO_EVT_RX_MUTE,
  757. (WCD_RX2 << 0x10));
  758. wcd_enable_irq(&wcd938x->irq_info,
  759. WCD938X_IRQ_HPHR_PDM_WD_INT);
  760. break;
  761. case SND_SOC_DAPM_PRE_PMD:
  762. if (wcd938x->update_wcd_event)
  763. wcd938x->update_wcd_event(wcd938x->handle,
  764. WCD_BOLERO_EVT_RX_MUTE,
  765. (WCD_RX2 << 0x10 | 0x1));
  766. wcd_disable_irq(&wcd938x->irq_info,
  767. WCD938X_IRQ_HPHR_PDM_WD_INT);
  768. if (wcd938x->update_wcd_event && wcd938x->comp2_enable)
  769. wcd938x->update_wcd_event(wcd938x->handle,
  770. WCD_BOLERO_EVT_RX_COMPANDER_SOFT_RST,
  771. (WCD_RX2 << 0x10));
  772. /*
  773. * 7ms sleep is required if compander is enabled as per
  774. * HW requirement. If compander is disabled, then
  775. * 20ms delay is required.
  776. */
  777. if (!wcd938x->comp2_enable)
  778. usleep_range(20000, 20100);
  779. else
  780. usleep_range(7000, 7100);
  781. snd_soc_component_update_bits(component, WCD938X_ANA_HPH,
  782. 0x40, 0x00);
  783. blocking_notifier_call_chain(&wcd938x->mbhc->notifier,
  784. WCD_EVENT_PRE_HPHR_PA_OFF,
  785. &wcd938x->mbhc->wcd_mbhc);
  786. set_bit(HPH_PA_DELAY, &wcd938x->status_mask);
  787. break;
  788. case SND_SOC_DAPM_POST_PMD:
  789. /*
  790. * 7ms sleep is required if compander is enabled as per
  791. * HW requirement. If compander is disabled, then
  792. * 20ms delay is required.
  793. */
  794. if (test_bit(HPH_PA_DELAY, &wcd938x->status_mask)) {
  795. if (!wcd938x->comp2_enable)
  796. usleep_range(20000, 20100);
  797. else
  798. usleep_range(7000, 7100);
  799. clear_bit(HPH_PA_DELAY, &wcd938x->status_mask);
  800. }
  801. blocking_notifier_call_chain(&wcd938x->mbhc->notifier,
  802. WCD_EVENT_POST_HPHR_PA_OFF,
  803. &wcd938x->mbhc->wcd_mbhc);
  804. snd_soc_component_update_bits(component, WCD938X_ANA_HPH,
  805. 0x10, 0x00);
  806. snd_soc_component_update_bits(component,
  807. WCD938X_DIGITAL_PDM_WD_CTL1, 0x07, 0x00);
  808. wcd_cls_h_fsm(component, &wcd938x->clsh_info,
  809. WCD_CLSH_EVENT_POST_PA,
  810. WCD_CLSH_STATE_HPHR,
  811. hph_mode);
  812. if (wcd938x->ldoh)
  813. snd_soc_component_update_bits(component,
  814. WCD938X_LDOH_MODE,
  815. 0x80, 0x00);
  816. break;
  817. };
  818. return ret;
  819. }
  820. static int wcd938x_codec_enable_hphl_pa(struct snd_soc_dapm_widget *w,
  821. struct snd_kcontrol *kcontrol,
  822. int event)
  823. {
  824. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  825. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  826. int ret = 0;
  827. int hph_mode = wcd938x->hph_mode;
  828. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  829. w->name, event);
  830. switch (event) {
  831. case SND_SOC_DAPM_PRE_PMU:
  832. if (wcd938x->ldoh)
  833. snd_soc_component_update_bits(component,
  834. WCD938X_LDOH_MODE,
  835. 0x80, 0x80);
  836. if (wcd938x->update_wcd_event)
  837. wcd938x->update_wcd_event(wcd938x->handle,
  838. WCD_BOLERO_EVT_RX_MUTE,
  839. (WCD_RX1 << 0x10 | 0x01));
  840. ret = swr_slvdev_datapath_control(wcd938x->rx_swr_dev,
  841. wcd938x->rx_swr_dev->dev_num,
  842. true);
  843. wcd_cls_h_fsm(component, &wcd938x->clsh_info,
  844. WCD_CLSH_EVENT_PRE_DAC,
  845. WCD_CLSH_STATE_HPHL,
  846. hph_mode);
  847. wcd_clsh_set_hph_mode(component, CLS_H_HIFI);
  848. if (hph_mode == CLS_H_LP || hph_mode == CLS_H_LOHIFI ||
  849. hph_mode == CLS_H_ULP) {
  850. snd_soc_component_update_bits(component,
  851. WCD938X_HPH_REFBUFF_LP_CTL, 0x01, 0x01);
  852. }
  853. snd_soc_component_update_bits(component, WCD938X_ANA_HPH,
  854. 0x20, 0x20);
  855. wcd_clsh_set_hph_mode(component, hph_mode);
  856. /* 100 usec delay as per HW requirement */
  857. usleep_range(100, 110);
  858. set_bit(HPH_PA_DELAY, &wcd938x->status_mask);
  859. snd_soc_component_update_bits(component,
  860. WCD938X_DIGITAL_PDM_WD_CTL0, 0x07, 0x03);
  861. break;
  862. case SND_SOC_DAPM_POST_PMU:
  863. /*
  864. * 7ms sleep is required if compander is enabled as per
  865. * HW requirement. If compander is disabled, then
  866. * 20ms delay is required.
  867. */
  868. if (test_bit(HPH_PA_DELAY, &wcd938x->status_mask)) {
  869. if (!wcd938x->comp1_enable)
  870. usleep_range(20000, 20100);
  871. else
  872. usleep_range(7000, 7100);
  873. if (hph_mode == CLS_H_LP ||
  874. hph_mode == CLS_H_LOHIFI ||
  875. hph_mode == CLS_H_ULP)
  876. snd_soc_component_update_bits(component,
  877. WCD938X_HPH_REFBUFF_LP_CTL,
  878. 0x01, 0x00);
  879. clear_bit(HPH_PA_DELAY, &wcd938x->status_mask);
  880. }
  881. snd_soc_component_update_bits(component,
  882. WCD938X_HPH_NEW_INT_HPH_TIMER1, 0x02, 0x02);
  883. if (hph_mode == CLS_AB || hph_mode == CLS_AB_HIFI ||
  884. hph_mode == CLS_AB_LP || hph_mode == CLS_AB_LOHIFI)
  885. snd_soc_component_update_bits(component,
  886. WCD938X_ANA_RX_SUPPLIES, 0x02, 0x02);
  887. if (wcd938x->update_wcd_event)
  888. wcd938x->update_wcd_event(wcd938x->handle,
  889. WCD_BOLERO_EVT_RX_MUTE,
  890. (WCD_RX1 << 0x10));
  891. wcd_enable_irq(&wcd938x->irq_info,
  892. WCD938X_IRQ_HPHL_PDM_WD_INT);
  893. break;
  894. case SND_SOC_DAPM_PRE_PMD:
  895. if (wcd938x->update_wcd_event)
  896. wcd938x->update_wcd_event(wcd938x->handle,
  897. WCD_BOLERO_EVT_RX_MUTE,
  898. (WCD_RX1 << 0x10 | 0x1));
  899. wcd_disable_irq(&wcd938x->irq_info,
  900. WCD938X_IRQ_HPHL_PDM_WD_INT);
  901. if (wcd938x->update_wcd_event && wcd938x->comp1_enable)
  902. wcd938x->update_wcd_event(wcd938x->handle,
  903. WCD_BOLERO_EVT_RX_COMPANDER_SOFT_RST,
  904. (WCD_RX1 << 0x10));
  905. /*
  906. * 7ms sleep is required if compander is enabled as per
  907. * HW requirement. If compander is disabled, then
  908. * 20ms delay is required.
  909. */
  910. if (!wcd938x->comp1_enable)
  911. usleep_range(20000, 20100);
  912. else
  913. usleep_range(7000, 7100);
  914. snd_soc_component_update_bits(component, WCD938X_ANA_HPH,
  915. 0x80, 0x00);
  916. blocking_notifier_call_chain(&wcd938x->mbhc->notifier,
  917. WCD_EVENT_PRE_HPHL_PA_OFF,
  918. &wcd938x->mbhc->wcd_mbhc);
  919. set_bit(HPH_PA_DELAY, &wcd938x->status_mask);
  920. break;
  921. case SND_SOC_DAPM_POST_PMD:
  922. /*
  923. * 7ms sleep is required if compander is enabled as per
  924. * HW requirement. If compander is disabled, then
  925. * 20ms delay is required.
  926. */
  927. if (test_bit(HPH_PA_DELAY, &wcd938x->status_mask)) {
  928. if (!wcd938x->comp1_enable)
  929. usleep_range(21000, 21100);
  930. else
  931. usleep_range(7000, 7100);
  932. clear_bit(HPH_PA_DELAY, &wcd938x->status_mask);
  933. }
  934. blocking_notifier_call_chain(&wcd938x->mbhc->notifier,
  935. WCD_EVENT_POST_HPHL_PA_OFF,
  936. &wcd938x->mbhc->wcd_mbhc);
  937. snd_soc_component_update_bits(component, WCD938X_ANA_HPH,
  938. 0x20, 0x00);
  939. snd_soc_component_update_bits(component,
  940. WCD938X_DIGITAL_PDM_WD_CTL0, 0x07, 0x00);
  941. wcd_cls_h_fsm(component, &wcd938x->clsh_info,
  942. WCD_CLSH_EVENT_POST_PA,
  943. WCD_CLSH_STATE_HPHL,
  944. hph_mode);
  945. if (wcd938x->ldoh)
  946. snd_soc_component_update_bits(component,
  947. WCD938X_LDOH_MODE,
  948. 0x80, 0x00);
  949. break;
  950. };
  951. return ret;
  952. }
  953. static int wcd938x_codec_enable_aux_pa(struct snd_soc_dapm_widget *w,
  954. struct snd_kcontrol *kcontrol,
  955. int event)
  956. {
  957. struct snd_soc_component *component =
  958. snd_soc_dapm_to_component(w->dapm);
  959. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  960. int hph_mode = wcd938x->hph_mode;
  961. int ret = 0;
  962. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  963. w->name, event);
  964. switch (event) {
  965. case SND_SOC_DAPM_PRE_PMU:
  966. ret = swr_slvdev_datapath_control(wcd938x->rx_swr_dev,
  967. wcd938x->rx_swr_dev->dev_num,
  968. true);
  969. snd_soc_component_update_bits(component,
  970. WCD938X_DIGITAL_PDM_WD_CTL2, 0x01, 0x01);
  971. break;
  972. case SND_SOC_DAPM_POST_PMU:
  973. /* 1 msec delay as per HW requirement */
  974. usleep_range(1000, 1010);
  975. if (hph_mode == CLS_AB || hph_mode == CLS_AB_HIFI ||
  976. hph_mode == CLS_AB_LP || hph_mode == CLS_AB_LOHIFI)
  977. snd_soc_component_update_bits(component,
  978. WCD938X_ANA_RX_SUPPLIES,
  979. 0x02, 0x02);
  980. if (wcd938x->update_wcd_event)
  981. wcd938x->update_wcd_event(wcd938x->handle,
  982. WCD_BOLERO_EVT_RX_MUTE,
  983. (WCD_RX3 << 0x10));
  984. wcd_enable_irq(&wcd938x->irq_info, WCD938X_IRQ_AUX_PDM_WD_INT);
  985. break;
  986. case SND_SOC_DAPM_PRE_PMD:
  987. wcd_disable_irq(&wcd938x->irq_info,
  988. WCD938X_IRQ_AUX_PDM_WD_INT);
  989. if (wcd938x->update_wcd_event)
  990. wcd938x->update_wcd_event(wcd938x->handle,
  991. WCD_BOLERO_EVT_RX_MUTE,
  992. (WCD_RX3 << 0x10 | 0x1));
  993. break;
  994. case SND_SOC_DAPM_POST_PMD:
  995. /* 1 msec delay as per HW requirement */
  996. usleep_range(1000, 1010);
  997. snd_soc_component_update_bits(component,
  998. WCD938X_DIGITAL_PDM_WD_CTL2, 0x01, 0x00);
  999. wcd_cls_h_fsm(component, &wcd938x->clsh_info,
  1000. WCD_CLSH_EVENT_POST_PA,
  1001. WCD_CLSH_STATE_AUX,
  1002. hph_mode);
  1003. wcd938x->flyback_cur_det_disable--;
  1004. if (wcd938x->flyback_cur_det_disable == 0)
  1005. snd_soc_component_update_bits(component,
  1006. WCD938X_FLYBACK_EN,
  1007. 0x04, 0x04);
  1008. break;
  1009. };
  1010. return ret;
  1011. }
  1012. static int wcd938x_codec_enable_ear_pa(struct snd_soc_dapm_widget *w,
  1013. struct snd_kcontrol *kcontrol,
  1014. int event)
  1015. {
  1016. struct snd_soc_component *component =
  1017. snd_soc_dapm_to_component(w->dapm);
  1018. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1019. int hph_mode = wcd938x->hph_mode;
  1020. int ret = 0;
  1021. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1022. w->name, event);
  1023. switch (event) {
  1024. case SND_SOC_DAPM_PRE_PMU:
  1025. ret = swr_slvdev_datapath_control(wcd938x->rx_swr_dev,
  1026. wcd938x->rx_swr_dev->dev_num,
  1027. true);
  1028. /*
  1029. * Enable watchdog interrupt for HPHL or AUX
  1030. * depending on mux value
  1031. */
  1032. wcd938x->ear_rx_path =
  1033. snd_soc_component_read32(
  1034. component, WCD938X_DIGITAL_CDC_EAR_PATH_CTL);
  1035. if (wcd938x->ear_rx_path & EAR_RX_PATH_AUX)
  1036. snd_soc_component_update_bits(component,
  1037. WCD938X_DIGITAL_PDM_WD_CTL2,
  1038. 0x01, 0x01);
  1039. else
  1040. snd_soc_component_update_bits(component,
  1041. WCD938X_DIGITAL_PDM_WD_CTL0,
  1042. 0x07, 0x03);
  1043. if (!wcd938x->comp1_enable)
  1044. snd_soc_component_update_bits(component,
  1045. WCD938X_ANA_EAR_COMPANDER_CTL, 0x80, 0x80);
  1046. break;
  1047. case SND_SOC_DAPM_POST_PMU:
  1048. /* 6 msec delay as per HW requirement */
  1049. usleep_range(6000, 6010);
  1050. if (hph_mode == CLS_AB || hph_mode == CLS_AB_HIFI ||
  1051. hph_mode == CLS_AB_LP || hph_mode == CLS_AB_LOHIFI)
  1052. snd_soc_component_update_bits(component,
  1053. WCD938X_ANA_RX_SUPPLIES,
  1054. 0x02, 0x02);
  1055. if (wcd938x->ear_rx_path & EAR_RX_PATH_AUX) {
  1056. if (wcd938x->update_wcd_event)
  1057. wcd938x->update_wcd_event(wcd938x->handle,
  1058. WCD_BOLERO_EVT_RX_MUTE,
  1059. (WCD_RX3 << 0x10));
  1060. wcd_enable_irq(&wcd938x->irq_info,
  1061. WCD938X_IRQ_AUX_PDM_WD_INT);
  1062. } else {
  1063. if (wcd938x->update_wcd_event)
  1064. wcd938x->update_wcd_event(wcd938x->handle,
  1065. WCD_BOLERO_EVT_RX_MUTE,
  1066. (WCD_RX1 << 0x10));
  1067. wcd_enable_irq(&wcd938x->irq_info,
  1068. WCD938X_IRQ_HPHL_PDM_WD_INT);
  1069. }
  1070. break;
  1071. case SND_SOC_DAPM_PRE_PMD:
  1072. if (wcd938x->ear_rx_path & EAR_RX_PATH_AUX) {
  1073. wcd_disable_irq(&wcd938x->irq_info,
  1074. WCD938X_IRQ_AUX_PDM_WD_INT);
  1075. if (wcd938x->update_wcd_event)
  1076. wcd938x->update_wcd_event(wcd938x->handle,
  1077. WCD_BOLERO_EVT_RX_MUTE,
  1078. (WCD_RX3 << 0x10 | 0x1));
  1079. } else {
  1080. wcd_disable_irq(&wcd938x->irq_info,
  1081. WCD938X_IRQ_HPHL_PDM_WD_INT);
  1082. if (wcd938x->update_wcd_event)
  1083. wcd938x->update_wcd_event(wcd938x->handle,
  1084. WCD_BOLERO_EVT_RX_MUTE,
  1085. (WCD_RX1 << 0x10 | 0x1));
  1086. }
  1087. break;
  1088. case SND_SOC_DAPM_POST_PMD:
  1089. if (!wcd938x->comp1_enable)
  1090. snd_soc_component_update_bits(component,
  1091. WCD938X_ANA_EAR_COMPANDER_CTL, 0x80, 0x00);
  1092. /* 7 msec delay as per HW requirement */
  1093. usleep_range(7000, 7010);
  1094. if (wcd938x->ear_rx_path & EAR_RX_PATH_AUX)
  1095. snd_soc_component_update_bits(component,
  1096. WCD938X_DIGITAL_PDM_WD_CTL2,
  1097. 0x01, 0x00);
  1098. else
  1099. snd_soc_component_update_bits(component,
  1100. WCD938X_DIGITAL_PDM_WD_CTL0,
  1101. 0x07, 0x00);
  1102. wcd_cls_h_fsm(component, &wcd938x->clsh_info,
  1103. WCD_CLSH_EVENT_POST_PA,
  1104. WCD_CLSH_STATE_EAR,
  1105. hph_mode);
  1106. wcd938x->flyback_cur_det_disable--;
  1107. if (wcd938x->flyback_cur_det_disable == 0)
  1108. snd_soc_component_update_bits(component,
  1109. WCD938X_FLYBACK_EN,
  1110. 0x04, 0x04);
  1111. break;
  1112. };
  1113. return ret;
  1114. }
  1115. static int wcd938x_enable_clsh(struct snd_soc_dapm_widget *w,
  1116. struct snd_kcontrol *kcontrol,
  1117. int event)
  1118. {
  1119. struct snd_soc_component *component =
  1120. snd_soc_dapm_to_component(w->dapm);
  1121. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1122. int mode = wcd938x->hph_mode;
  1123. int ret = 0;
  1124. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1125. w->name, event);
  1126. if (mode == CLS_H_LOHIFI || mode == CLS_H_ULP ||
  1127. mode == CLS_H_HIFI || mode == CLS_H_LP) {
  1128. wcd938x_rx_connect_port(component, CLSH,
  1129. SND_SOC_DAPM_EVENT_ON(event));
  1130. }
  1131. if (SND_SOC_DAPM_EVENT_OFF(event))
  1132. ret = swr_slvdev_datapath_control(
  1133. wcd938x->rx_swr_dev,
  1134. wcd938x->rx_swr_dev->dev_num,
  1135. false);
  1136. return ret;
  1137. }
  1138. static int wcd938x_enable_rx1(struct snd_soc_dapm_widget *w,
  1139. struct snd_kcontrol *kcontrol,
  1140. int event)
  1141. {
  1142. struct snd_soc_component *component =
  1143. snd_soc_dapm_to_component(w->dapm);
  1144. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1145. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1146. w->name, event);
  1147. switch (event) {
  1148. case SND_SOC_DAPM_PRE_PMU:
  1149. wcd938x_rx_connect_port(component, HPH_L, true);
  1150. if (wcd938x->comp1_enable)
  1151. wcd938x_rx_connect_port(component, COMP_L, true);
  1152. break;
  1153. case SND_SOC_DAPM_POST_PMD:
  1154. wcd938x_rx_connect_port(component, HPH_L, false);
  1155. if (wcd938x->comp1_enable)
  1156. wcd938x_rx_connect_port(component, COMP_L, false);
  1157. wcd938x_rx_clk_disable(component);
  1158. snd_soc_component_update_bits(component,
  1159. WCD938X_DIGITAL_CDC_DIG_CLK_CTL,
  1160. 0x01, 0x00);
  1161. break;
  1162. };
  1163. return 0;
  1164. }
  1165. static int wcd938x_enable_rx2(struct snd_soc_dapm_widget *w,
  1166. struct snd_kcontrol *kcontrol, int event)
  1167. {
  1168. struct snd_soc_component *component =
  1169. snd_soc_dapm_to_component(w->dapm);
  1170. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1171. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1172. w->name, event);
  1173. switch (event) {
  1174. case SND_SOC_DAPM_PRE_PMU:
  1175. wcd938x_rx_connect_port(component, HPH_R, true);
  1176. if (wcd938x->comp2_enable)
  1177. wcd938x_rx_connect_port(component, COMP_R, true);
  1178. break;
  1179. case SND_SOC_DAPM_POST_PMD:
  1180. wcd938x_rx_connect_port(component, HPH_R, false);
  1181. if (wcd938x->comp2_enable)
  1182. wcd938x_rx_connect_port(component, COMP_R, false);
  1183. wcd938x_rx_clk_disable(component);
  1184. snd_soc_component_update_bits(component,
  1185. WCD938X_DIGITAL_CDC_DIG_CLK_CTL,
  1186. 0x02, 0x00);
  1187. break;
  1188. };
  1189. return 0;
  1190. }
  1191. static int wcd938x_enable_rx3(struct snd_soc_dapm_widget *w,
  1192. struct snd_kcontrol *kcontrol,
  1193. int event)
  1194. {
  1195. struct snd_soc_component *component =
  1196. snd_soc_dapm_to_component(w->dapm);
  1197. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1198. w->name, event);
  1199. switch (event) {
  1200. case SND_SOC_DAPM_PRE_PMU:
  1201. wcd938x_rx_connect_port(component, LO, true);
  1202. break;
  1203. case SND_SOC_DAPM_POST_PMD:
  1204. wcd938x_rx_connect_port(component, LO, false);
  1205. /* 6 msec delay as per HW requirement */
  1206. usleep_range(6000, 6010);
  1207. wcd938x_rx_clk_disable(component);
  1208. snd_soc_component_update_bits(component,
  1209. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x04, 0x00);
  1210. break;
  1211. }
  1212. return 0;
  1213. }
  1214. static int wcd938x_codec_enable_dmic(struct snd_soc_dapm_widget *w,
  1215. struct snd_kcontrol *kcontrol,
  1216. int event)
  1217. {
  1218. struct snd_soc_component *component =
  1219. snd_soc_dapm_to_component(w->dapm);
  1220. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1221. u16 dmic_clk_reg, dmic_clk_en_reg;
  1222. s32 *dmic_clk_cnt;
  1223. u8 dmic_ctl_shift = 0;
  1224. u8 dmic_clk_shift = 0;
  1225. u8 dmic_clk_mask = 0;
  1226. u16 dmic2_left_en = 0;
  1227. int ret = 0;
  1228. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1229. w->name, event);
  1230. switch (w->shift) {
  1231. case 0:
  1232. case 1:
  1233. dmic_clk_cnt = &(wcd938x->dmic_0_1_clk_cnt);
  1234. dmic_clk_reg = WCD938X_DIGITAL_CDC_DMIC_RATE_1_2;
  1235. dmic_clk_en_reg = WCD938X_DIGITAL_CDC_DMIC1_CTL;
  1236. dmic_clk_mask = 0x0F;
  1237. dmic_clk_shift = 0x00;
  1238. dmic_ctl_shift = 0x00;
  1239. break;
  1240. case 2:
  1241. dmic2_left_en = WCD938X_DIGITAL_CDC_DMIC2_CTL;
  1242. case 3:
  1243. dmic_clk_cnt = &(wcd938x->dmic_2_3_clk_cnt);
  1244. dmic_clk_reg = WCD938X_DIGITAL_CDC_DMIC_RATE_1_2;
  1245. dmic_clk_en_reg = WCD938X_DIGITAL_CDC_DMIC2_CTL;
  1246. dmic_clk_mask = 0xF0;
  1247. dmic_clk_shift = 0x04;
  1248. dmic_ctl_shift = 0x01;
  1249. break;
  1250. case 4:
  1251. case 5:
  1252. dmic_clk_cnt = &(wcd938x->dmic_4_5_clk_cnt);
  1253. dmic_clk_reg = WCD938X_DIGITAL_CDC_DMIC_RATE_3_4;
  1254. dmic_clk_en_reg = WCD938X_DIGITAL_CDC_DMIC3_CTL;
  1255. dmic_clk_mask = 0x0F;
  1256. dmic_clk_shift = 0x00;
  1257. dmic_ctl_shift = 0x02;
  1258. break;
  1259. case 6:
  1260. case 7:
  1261. dmic_clk_cnt = &(wcd938x->dmic_6_7_clk_cnt);
  1262. dmic_clk_reg = WCD938X_DIGITAL_CDC_DMIC_RATE_3_4;
  1263. dmic_clk_en_reg = WCD938X_DIGITAL_CDC_DMIC4_CTL;
  1264. dmic_clk_mask = 0xF0;
  1265. dmic_clk_shift = 0x04;
  1266. dmic_ctl_shift = 0x03;
  1267. break;
  1268. default:
  1269. dev_err(component->dev, "%s: Invalid DMIC Selection\n",
  1270. __func__);
  1271. return -EINVAL;
  1272. };
  1273. dev_dbg(component->dev, "%s: event %d DMIC%d dmic_clk_cnt %d\n",
  1274. __func__, event, (w->shift +1), *dmic_clk_cnt);
  1275. switch (event) {
  1276. case SND_SOC_DAPM_PRE_PMU:
  1277. snd_soc_component_update_bits(component,
  1278. WCD938X_DIGITAL_CDC_AMIC_CTL,
  1279. (0x01 << dmic_ctl_shift), 0x00);
  1280. /* 250us sleep as per HW requirement */
  1281. usleep_range(250, 260);
  1282. if (dmic2_left_en)
  1283. snd_soc_component_update_bits(component,
  1284. dmic2_left_en, 0x80, 0x80);
  1285. /* Setting DMIC clock rate to 2.4MHz */
  1286. snd_soc_component_update_bits(component,
  1287. dmic_clk_reg, dmic_clk_mask,
  1288. (0x03 << dmic_clk_shift));
  1289. snd_soc_component_update_bits(component,
  1290. dmic_clk_en_reg, 0x08, 0x08);
  1291. /* enable clock scaling */
  1292. snd_soc_component_update_bits(component,
  1293. WCD938X_DIGITAL_CDC_DMIC_CTL, 0x06, 0x06);
  1294. ret = swr_slvdev_datapath_control(wcd938x->tx_swr_dev,
  1295. wcd938x->tx_swr_dev->dev_num,
  1296. true);
  1297. break;
  1298. case SND_SOC_DAPM_POST_PMD:
  1299. ret = swr_slvdev_datapath_control(wcd938x->tx_swr_dev,
  1300. wcd938x->tx_swr_dev->dev_num,
  1301. false);
  1302. snd_soc_component_update_bits(component,
  1303. WCD938X_DIGITAL_CDC_AMIC_CTL,
  1304. (0x01 << dmic_ctl_shift),
  1305. (0x01 << dmic_ctl_shift));
  1306. if (dmic2_left_en)
  1307. snd_soc_component_update_bits(component,
  1308. dmic2_left_en, 0x80, 0x00);
  1309. snd_soc_component_update_bits(component,
  1310. dmic_clk_en_reg, 0x08, 0x00);
  1311. break;
  1312. };
  1313. return ret;
  1314. }
  1315. /*
  1316. * wcd938x_get_micb_vout_ctl_val: converts micbias from volts to register value
  1317. * @micb_mv: micbias in mv
  1318. *
  1319. * return register value converted
  1320. */
  1321. int wcd938x_get_micb_vout_ctl_val(u32 micb_mv)
  1322. {
  1323. /* min micbias voltage is 1V and maximum is 2.85V */
  1324. if (micb_mv < 1000 || micb_mv > 2850) {
  1325. pr_err("%s: unsupported micbias voltage\n", __func__);
  1326. return -EINVAL;
  1327. }
  1328. return (micb_mv - 1000) / 50;
  1329. }
  1330. EXPORT_SYMBOL(wcd938x_get_micb_vout_ctl_val);
  1331. /*
  1332. * wcd938x_mbhc_micb_adjust_voltage: adjust specific micbias voltage
  1333. * @component: handle to snd_soc_component *
  1334. * @req_volt: micbias voltage to be set
  1335. * @micb_num: micbias to be set, e.g. micbias1 or micbias2
  1336. *
  1337. * return 0 if adjustment is success or error code in case of failure
  1338. */
  1339. int wcd938x_mbhc_micb_adjust_voltage(struct snd_soc_component *component,
  1340. int req_volt, int micb_num)
  1341. {
  1342. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1343. int cur_vout_ctl, req_vout_ctl;
  1344. int micb_reg, micb_val, micb_en;
  1345. int ret = 0;
  1346. switch (micb_num) {
  1347. case MIC_BIAS_1:
  1348. micb_reg = WCD938X_ANA_MICB1;
  1349. break;
  1350. case MIC_BIAS_2:
  1351. micb_reg = WCD938X_ANA_MICB2;
  1352. break;
  1353. case MIC_BIAS_3:
  1354. micb_reg = WCD938X_ANA_MICB3;
  1355. break;
  1356. case MIC_BIAS_4:
  1357. micb_reg = WCD938X_ANA_MICB4;
  1358. break;
  1359. default:
  1360. return -EINVAL;
  1361. }
  1362. mutex_lock(&wcd938x->micb_lock);
  1363. /*
  1364. * If requested micbias voltage is same as current micbias
  1365. * voltage, then just return. Otherwise, adjust voltage as
  1366. * per requested value. If micbias is already enabled, then
  1367. * to avoid slow micbias ramp-up or down enable pull-up
  1368. * momentarily, change the micbias value and then re-enable
  1369. * micbias.
  1370. */
  1371. micb_val = snd_soc_component_read32(component, micb_reg);
  1372. micb_en = (micb_val & 0xC0) >> 6;
  1373. cur_vout_ctl = micb_val & 0x3F;
  1374. req_vout_ctl = wcd938x_get_micb_vout_ctl_val(req_volt);
  1375. if (req_vout_ctl < 0) {
  1376. ret = -EINVAL;
  1377. goto exit;
  1378. }
  1379. if (cur_vout_ctl == req_vout_ctl) {
  1380. ret = 0;
  1381. goto exit;
  1382. }
  1383. dev_dbg(component->dev, "%s: micb_num: %d, cur_mv: %d, req_mv: %d, micb_en: %d\n",
  1384. __func__, micb_num, WCD_VOUT_CTL_TO_MICB(cur_vout_ctl),
  1385. req_volt, micb_en);
  1386. if (micb_en == 0x1)
  1387. snd_soc_component_update_bits(component, micb_reg, 0xC0, 0x80);
  1388. snd_soc_component_update_bits(component, micb_reg, 0x3F, req_vout_ctl);
  1389. if (micb_en == 0x1) {
  1390. snd_soc_component_update_bits(component, micb_reg, 0xC0, 0x40);
  1391. /*
  1392. * Add 2ms delay as per HW requirement after enabling
  1393. * micbias
  1394. */
  1395. usleep_range(2000, 2100);
  1396. }
  1397. exit:
  1398. mutex_unlock(&wcd938x->micb_lock);
  1399. return ret;
  1400. }
  1401. EXPORT_SYMBOL(wcd938x_mbhc_micb_adjust_voltage);
  1402. static int wcd938x_tx_swr_ctrl(struct snd_soc_dapm_widget *w,
  1403. struct snd_kcontrol *kcontrol,
  1404. int event)
  1405. {
  1406. struct snd_soc_component *component =
  1407. snd_soc_dapm_to_component(w->dapm);
  1408. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1409. int ret = 0;
  1410. int bank = 0;
  1411. u8 mode = 0;
  1412. int i = 0;
  1413. int rate = 0;
  1414. bank = (wcd938x_swr_slv_get_current_bank(wcd938x->tx_swr_dev,
  1415. wcd938x->tx_swr_dev->dev_num) ? 0 : 1);
  1416. switch (event) {
  1417. case SND_SOC_DAPM_PRE_PMU:
  1418. if (strnstr(w->name, "ADC", sizeof("ADC"))) {
  1419. if (test_bit(WCD_ADC1, &wcd938x->status_mask) ||
  1420. test_bit(WCD_ADC1_MODE, &wcd938x->status_mask))
  1421. mode |= tx_mode_bit[wcd938x->tx_mode[WCD_ADC1]];
  1422. if (test_bit(WCD_ADC2, &wcd938x->status_mask) ||
  1423. test_bit(WCD_ADC2_MODE, &wcd938x->status_mask))
  1424. mode |= tx_mode_bit[wcd938x->tx_mode[WCD_ADC2]];
  1425. if (test_bit(WCD_ADC3, &wcd938x->status_mask) ||
  1426. test_bit(WCD_ADC3_MODE, &wcd938x->status_mask))
  1427. mode |= tx_mode_bit[wcd938x->tx_mode[WCD_ADC3]];
  1428. if (test_bit(WCD_ADC4, &wcd938x->status_mask) ||
  1429. test_bit(WCD_ADC4_MODE, &wcd938x->status_mask))
  1430. mode |= tx_mode_bit[wcd938x->tx_mode[WCD_ADC4]];
  1431. if (mode != 0) {
  1432. for (i = 0; i < ADC_MODE_ULP2; i++) {
  1433. if (mode & (1 << i)) {
  1434. i++;
  1435. break;
  1436. }
  1437. }
  1438. }
  1439. rate = wcd938x_get_clk_rate(i);
  1440. wcd938x_set_swr_clk_rate(component, rate, bank);
  1441. }
  1442. if (w->shift == ADC2 && !(snd_soc_component_read32(component,
  1443. WCD938X_TX_NEW_AMIC_MUX_CFG) & 0x80)) {
  1444. if (!wcd938x->bcs_dis)
  1445. wcd938x_tx_connect_port(component, MBHC,
  1446. SWR_CLK_RATE_4P8MHZ, true);
  1447. set_bit(AMIC2_BCS_ENABLE, &wcd938x->status_mask);
  1448. }
  1449. if (strnstr(w->name, "ADC", sizeof("ADC"))) {
  1450. wcd938x_tx_connect_port(component, w->shift, rate,
  1451. true);
  1452. /* Copy clk settings to active bank */
  1453. wcd938x_set_swr_clk_rate(component, rate, !bank);
  1454. } else {
  1455. wcd938x_tx_connect_port(component, w->shift,
  1456. SWR_CLK_RATE_2P4MHZ, true);
  1457. }
  1458. break;
  1459. case SND_SOC_DAPM_POST_PMD:
  1460. if (strnstr(w->name, "ADC", sizeof("ADC"))) {
  1461. rate = wcd938x_get_clk_rate(ADC_MODE_INVALID);
  1462. wcd938x_set_swr_clk_rate(component, rate, !bank);
  1463. }
  1464. wcd938x_tx_connect_port(component, w->shift, 0, false);
  1465. if (w->shift == ADC2 &&
  1466. test_bit(AMIC2_BCS_ENABLE, &wcd938x->status_mask)) {
  1467. if (!wcd938x->bcs_dis)
  1468. wcd938x_tx_connect_port(component, MBHC, 0,
  1469. false);
  1470. clear_bit(AMIC2_BCS_ENABLE, &wcd938x->status_mask);
  1471. }
  1472. if (strnstr(w->name, "ADC", sizeof("ADC")))
  1473. wcd938x_set_swr_clk_rate(component, rate, bank);
  1474. if (strnstr(w->name, "ADC1", sizeof("ADC1")))
  1475. clear_bit(WCD_ADC1_MODE, &wcd938x->status_mask);
  1476. else if (strnstr(w->name, "ADC2", sizeof("ADC2")))
  1477. clear_bit(WCD_ADC2_MODE, &wcd938x->status_mask);
  1478. else if (strnstr(w->name, "ADC3", sizeof("ADC3")))
  1479. clear_bit(WCD_ADC3_MODE, &wcd938x->status_mask);
  1480. else if (strnstr(w->name, "ADC4", sizeof("ADC4")))
  1481. clear_bit(WCD_ADC4_MODE, &wcd938x->status_mask);
  1482. break;
  1483. };
  1484. return ret;
  1485. }
  1486. static int wcd938x_get_adc_mode(int val)
  1487. {
  1488. int ret = 0;
  1489. switch (val) {
  1490. case ADC_MODE_INVALID:
  1491. ret = ADC_MODE_VAL_NORMAL;
  1492. break;
  1493. case ADC_MODE_HIFI:
  1494. ret = ADC_MODE_VAL_HIFI;
  1495. break;
  1496. case ADC_MODE_LO_HIF:
  1497. ret = ADC_MODE_VAL_LO_HIF;
  1498. break;
  1499. case ADC_MODE_NORMAL:
  1500. ret = ADC_MODE_VAL_NORMAL;
  1501. break;
  1502. case ADC_MODE_LP:
  1503. ret = ADC_MODE_VAL_LP;
  1504. break;
  1505. case ADC_MODE_ULP1:
  1506. ret = ADC_MODE_VAL_ULP1;
  1507. break;
  1508. case ADC_MODE_ULP2:
  1509. ret = ADC_MODE_VAL_ULP2;
  1510. break;
  1511. default:
  1512. ret = -EINVAL;
  1513. pr_err("%s: invalid ADC mode value %d\n", __func__, val);
  1514. break;
  1515. }
  1516. return ret;
  1517. }
  1518. int wcd938x_tx_channel_config(struct snd_soc_component *component,
  1519. int channel, int mode)
  1520. {
  1521. int reg = WCD938X_ANA_TX_CH2, mask = 0, val = 0;
  1522. int ret = 0;
  1523. switch (channel) {
  1524. case 0:
  1525. reg = WCD938X_ANA_TX_CH2;
  1526. mask = 0x40;
  1527. break;
  1528. case 1:
  1529. reg = WCD938X_ANA_TX_CH2;
  1530. mask = 0x20;
  1531. break;
  1532. case 2:
  1533. reg = WCD938X_ANA_TX_CH4;
  1534. mask = 0x40;
  1535. break;
  1536. case 3:
  1537. reg = WCD938X_ANA_TX_CH4;
  1538. mask = 0x20;
  1539. break;
  1540. default:
  1541. pr_err("%s: Invalid channel num %d\n", __func__, channel);
  1542. ret = -EINVAL;
  1543. break;
  1544. }
  1545. if (!mode)
  1546. val = 0x00;
  1547. else
  1548. val = mask;
  1549. if (!ret)
  1550. snd_soc_component_update_bits(component, reg, mask, val);
  1551. return ret;
  1552. }
  1553. static int wcd938x_codec_enable_adc(struct snd_soc_dapm_widget *w,
  1554. struct snd_kcontrol *kcontrol,
  1555. int event){
  1556. struct snd_soc_component *component =
  1557. snd_soc_dapm_to_component(w->dapm);
  1558. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1559. int clk_rate = 0, ret = 0;
  1560. int mode;
  1561. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1562. w->name, event);
  1563. switch (event) {
  1564. case SND_SOC_DAPM_PRE_PMU:
  1565. snd_soc_component_update_bits(component,
  1566. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x08, 0x08);
  1567. snd_soc_component_update_bits(component,
  1568. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x10, 0x10);
  1569. set_bit(w->shift, &wcd938x->status_mask);
  1570. clk_rate = wcd938x_get_clk_rate(wcd938x->tx_mode[w->shift]);
  1571. ret = swr_slvdev_datapath_control(wcd938x->tx_swr_dev,
  1572. wcd938x->tx_swr_dev->dev_num,
  1573. true);
  1574. ret = wcd938x_tx_channel_config(component, w->shift, 1);
  1575. mode = wcd938x_get_adc_mode(wcd938x->tx_mode[w->shift]);
  1576. if (mode < 0) {
  1577. dev_info(component->dev,
  1578. "%s: invalid mode, setting to normal mode\n",
  1579. __func__);
  1580. mode = ADC_MODE_VAL_NORMAL;
  1581. }
  1582. switch (w->shift) {
  1583. case 0:
  1584. snd_soc_component_update_bits(component,
  1585. WCD938X_DIGITAL_CDC_TX_ANA_MODE_0_1, 0x0F,
  1586. mode);
  1587. snd_soc_component_update_bits(component,
  1588. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x10, 0x10);
  1589. break;
  1590. case 1:
  1591. snd_soc_component_update_bits(component,
  1592. WCD938X_DIGITAL_CDC_TX_ANA_MODE_0_1, 0xF0,
  1593. mode << 4);
  1594. snd_soc_component_update_bits(component,
  1595. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x20, 0x20);
  1596. break;
  1597. case 2:
  1598. snd_soc_component_update_bits(component,
  1599. WCD938X_DIGITAL_CDC_TX_ANA_MODE_2_3, 0x0F,
  1600. mode);
  1601. snd_soc_component_update_bits(component,
  1602. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x40, 0x40);
  1603. break;
  1604. case 3:
  1605. snd_soc_component_update_bits(component,
  1606. WCD938X_DIGITAL_CDC_TX_ANA_MODE_2_3, 0xF0,
  1607. mode << 4);
  1608. snd_soc_component_update_bits(component,
  1609. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x80, 0x80);
  1610. break;
  1611. default:
  1612. break;
  1613. }
  1614. ret |= wcd938x_tx_channel_config(component, w->shift, 0);
  1615. break;
  1616. case SND_SOC_DAPM_POST_PMD:
  1617. switch (w->shift) {
  1618. case 0:
  1619. snd_soc_component_update_bits(component,
  1620. WCD938X_DIGITAL_CDC_TX_ANA_MODE_0_1, 0x0F,
  1621. 0x00);
  1622. snd_soc_component_update_bits(component,
  1623. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x10, 0x00);
  1624. break;
  1625. case 1:
  1626. snd_soc_component_update_bits(component,
  1627. WCD938X_DIGITAL_CDC_TX_ANA_MODE_0_1, 0xF0,
  1628. 0x00);
  1629. snd_soc_component_update_bits(component,
  1630. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x20, 0x00);
  1631. break;
  1632. case 2:
  1633. snd_soc_component_update_bits(component,
  1634. WCD938X_DIGITAL_CDC_TX_ANA_MODE_2_3, 0x0F,
  1635. 0x00);
  1636. snd_soc_component_update_bits(component,
  1637. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x40, 0x00);
  1638. break;
  1639. case 3:
  1640. snd_soc_component_update_bits(component,
  1641. WCD938X_DIGITAL_CDC_TX_ANA_MODE_2_3, 0xF0,
  1642. 0x00);
  1643. snd_soc_component_update_bits(component,
  1644. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x80, 0x00);
  1645. break;
  1646. default:
  1647. break;
  1648. }
  1649. ret = swr_slvdev_datapath_control(wcd938x->tx_swr_dev,
  1650. wcd938x->tx_swr_dev->dev_num,
  1651. false);
  1652. snd_soc_component_update_bits(component,
  1653. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x08, 0x00);
  1654. clear_bit(w->shift, &wcd938x->status_mask);
  1655. break;
  1656. };
  1657. return ret;
  1658. }
  1659. void wcd938x_disable_bcs_before_slow_insert(struct snd_soc_component *component,
  1660. bool bcs_disable)
  1661. {
  1662. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1663. if (wcd938x->update_wcd_event) {
  1664. if (bcs_disable)
  1665. wcd938x->update_wcd_event(wcd938x->handle,
  1666. WCD_BOLERO_EVT_BCS_CLK_OFF, 0);
  1667. else
  1668. wcd938x->update_wcd_event(wcd938x->handle,
  1669. WCD_BOLERO_EVT_BCS_CLK_OFF, 1);
  1670. }
  1671. }
  1672. static int wcd938x_enable_req(struct snd_soc_dapm_widget *w,
  1673. struct snd_kcontrol *kcontrol, int event)
  1674. {
  1675. struct snd_soc_component *component =
  1676. snd_soc_dapm_to_component(w->dapm);
  1677. int ret = 0;
  1678. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1679. w->name, event);
  1680. switch (event) {
  1681. case SND_SOC_DAPM_PRE_PMU:
  1682. snd_soc_component_update_bits(component,
  1683. WCD938X_DIGITAL_CDC_REQ_CTL, 0x02, 0x02);
  1684. snd_soc_component_update_bits(component,
  1685. WCD938X_DIGITAL_CDC_REQ_CTL, 0x01, 0x00);
  1686. break;
  1687. case SND_SOC_DAPM_POST_PMD:
  1688. snd_soc_component_update_bits(component,
  1689. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x10, 0x00);
  1690. break;
  1691. };
  1692. return ret;
  1693. }
  1694. int wcd938x_micbias_control(struct snd_soc_component *component,
  1695. int micb_num, int req, bool is_dapm)
  1696. {
  1697. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1698. int micb_index = micb_num - 1;
  1699. u16 micb_reg;
  1700. int pre_off_event = 0, post_off_event = 0;
  1701. int post_on_event = 0, post_dapm_off = 0;
  1702. int post_dapm_on = 0;
  1703. int ret = 0;
  1704. if ((micb_index < 0) || (micb_index > WCD938X_MAX_MICBIAS - 1)) {
  1705. dev_err(component->dev,
  1706. "%s: Invalid micbias index, micb_ind:%d\n",
  1707. __func__, micb_index);
  1708. return -EINVAL;
  1709. }
  1710. if (NULL == wcd938x) {
  1711. dev_err(component->dev,
  1712. "%s: wcd938x private data is NULL\n", __func__);
  1713. return -EINVAL;
  1714. }
  1715. switch (micb_num) {
  1716. case MIC_BIAS_1:
  1717. micb_reg = WCD938X_ANA_MICB1;
  1718. break;
  1719. case MIC_BIAS_2:
  1720. micb_reg = WCD938X_ANA_MICB2;
  1721. pre_off_event = WCD_EVENT_PRE_MICBIAS_2_OFF;
  1722. post_off_event = WCD_EVENT_POST_MICBIAS_2_OFF;
  1723. post_on_event = WCD_EVENT_POST_MICBIAS_2_ON;
  1724. post_dapm_on = WCD_EVENT_POST_DAPM_MICBIAS_2_ON;
  1725. post_dapm_off = WCD_EVENT_POST_DAPM_MICBIAS_2_OFF;
  1726. break;
  1727. case MIC_BIAS_3:
  1728. micb_reg = WCD938X_ANA_MICB3;
  1729. break;
  1730. case MIC_BIAS_4:
  1731. micb_reg = WCD938X_ANA_MICB4;
  1732. break;
  1733. default:
  1734. dev_err(component->dev, "%s: Invalid micbias number: %d\n",
  1735. __func__, micb_num);
  1736. return -EINVAL;
  1737. };
  1738. mutex_lock(&wcd938x->micb_lock);
  1739. switch (req) {
  1740. case MICB_PULLUP_ENABLE:
  1741. if (!wcd938x->dev_up) {
  1742. dev_dbg(component->dev, "%s: enable req %d wcd device down\n",
  1743. __func__, req);
  1744. ret = -ENODEV;
  1745. goto done;
  1746. }
  1747. wcd938x->pullup_ref[micb_index]++;
  1748. if ((wcd938x->pullup_ref[micb_index] == 1) &&
  1749. (wcd938x->micb_ref[micb_index] == 0))
  1750. snd_soc_component_update_bits(component, micb_reg,
  1751. 0xC0, 0x80);
  1752. break;
  1753. case MICB_PULLUP_DISABLE:
  1754. if (wcd938x->pullup_ref[micb_index] > 0)
  1755. wcd938x->pullup_ref[micb_index]--;
  1756. if (!wcd938x->dev_up) {
  1757. dev_dbg(component->dev, "%s: enable req %d wcd device down\n",
  1758. __func__, req);
  1759. ret = -ENODEV;
  1760. goto done;
  1761. }
  1762. if ((wcd938x->pullup_ref[micb_index] == 0) &&
  1763. (wcd938x->micb_ref[micb_index] == 0))
  1764. snd_soc_component_update_bits(component, micb_reg,
  1765. 0xC0, 0x00);
  1766. break;
  1767. case MICB_ENABLE:
  1768. if (!wcd938x->dev_up) {
  1769. dev_dbg(component->dev, "%s: enable req %d wcd device down\n",
  1770. __func__, req);
  1771. ret = -ENODEV;
  1772. goto done;
  1773. }
  1774. wcd938x->micb_ref[micb_index]++;
  1775. if (wcd938x->micb_ref[micb_index] == 1) {
  1776. snd_soc_component_update_bits(component,
  1777. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0xF0, 0xF0);
  1778. snd_soc_component_update_bits(component,
  1779. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x10, 0x10);
  1780. snd_soc_component_update_bits(component,
  1781. WCD938X_DIGITAL_CDC_ANA_TX_CLK_CTL, 0x01, 0x01);
  1782. snd_soc_component_update_bits(component,
  1783. WCD938X_MICB1_TEST_CTL_2, 0x01, 0x01);
  1784. snd_soc_component_update_bits(component,
  1785. WCD938X_MICB2_TEST_CTL_2, 0x01, 0x01);
  1786. snd_soc_component_update_bits(component,
  1787. WCD938X_MICB3_TEST_CTL_2, 0x01, 0x01);
  1788. snd_soc_component_update_bits(component,
  1789. WCD938X_MICB4_TEST_CTL_2, 0x01, 0x01);
  1790. snd_soc_component_update_bits(component,
  1791. micb_reg, 0xC0, 0x40);
  1792. if (post_on_event)
  1793. blocking_notifier_call_chain(
  1794. &wcd938x->mbhc->notifier,
  1795. post_on_event,
  1796. &wcd938x->mbhc->wcd_mbhc);
  1797. }
  1798. if (is_dapm && post_dapm_on && wcd938x->mbhc)
  1799. blocking_notifier_call_chain(&wcd938x->mbhc->notifier,
  1800. post_dapm_on,
  1801. &wcd938x->mbhc->wcd_mbhc);
  1802. break;
  1803. case MICB_DISABLE:
  1804. if (wcd938x->micb_ref[micb_index] > 0)
  1805. wcd938x->micb_ref[micb_index]--;
  1806. if (!wcd938x->dev_up) {
  1807. dev_dbg(component->dev, "%s: enable req %d wcd device down\n",
  1808. __func__, req);
  1809. ret = -ENODEV;
  1810. goto done;
  1811. }
  1812. if ((wcd938x->micb_ref[micb_index] == 0) &&
  1813. (wcd938x->pullup_ref[micb_index] > 0))
  1814. snd_soc_component_update_bits(component, micb_reg,
  1815. 0xC0, 0x80);
  1816. else if ((wcd938x->micb_ref[micb_index] == 0) &&
  1817. (wcd938x->pullup_ref[micb_index] == 0)) {
  1818. if (pre_off_event && wcd938x->mbhc)
  1819. blocking_notifier_call_chain(
  1820. &wcd938x->mbhc->notifier,
  1821. pre_off_event,
  1822. &wcd938x->mbhc->wcd_mbhc);
  1823. snd_soc_component_update_bits(component, micb_reg,
  1824. 0xC0, 0x00);
  1825. if (post_off_event && wcd938x->mbhc)
  1826. blocking_notifier_call_chain(
  1827. &wcd938x->mbhc->notifier,
  1828. post_off_event,
  1829. &wcd938x->mbhc->wcd_mbhc);
  1830. }
  1831. if (is_dapm && post_dapm_off && wcd938x->mbhc)
  1832. blocking_notifier_call_chain(&wcd938x->mbhc->notifier,
  1833. post_dapm_off,
  1834. &wcd938x->mbhc->wcd_mbhc);
  1835. break;
  1836. };
  1837. dev_dbg(component->dev,
  1838. "%s: micb_num:%d, micb_ref: %d, pullup_ref: %d\n",
  1839. __func__, micb_num, wcd938x->micb_ref[micb_index],
  1840. wcd938x->pullup_ref[micb_index]);
  1841. done:
  1842. mutex_unlock(&wcd938x->micb_lock);
  1843. return ret;
  1844. }
  1845. EXPORT_SYMBOL(wcd938x_micbias_control);
  1846. static int wcd938x_get_logical_addr(struct swr_device *swr_dev)
  1847. {
  1848. int ret = 0;
  1849. uint8_t devnum = 0;
  1850. int num_retry = NUM_ATTEMPTS;
  1851. do {
  1852. /* retry after 1ms */
  1853. usleep_range(1000, 1010);
  1854. ret = swr_get_logical_dev_num(swr_dev, swr_dev->addr, &devnum);
  1855. } while (ret && --num_retry);
  1856. if (ret)
  1857. dev_err(&swr_dev->dev,
  1858. "%s get devnum %d for dev addr %llx failed\n",
  1859. __func__, devnum, swr_dev->addr);
  1860. swr_dev->dev_num = devnum;
  1861. return 0;
  1862. }
  1863. static bool get_usbc_hs_status(struct snd_soc_component *component,
  1864. struct wcd_mbhc_config *mbhc_cfg)
  1865. {
  1866. if (mbhc_cfg->enable_usbc_analog) {
  1867. if (!(snd_soc_component_read32(component, WCD938X_ANA_MBHC_MECH)
  1868. & 0x20))
  1869. return true;
  1870. }
  1871. return false;
  1872. }
  1873. int wcd938x_swr_dmic_register_notifier(struct snd_soc_component *component,
  1874. struct notifier_block *nblock,
  1875. bool enable)
  1876. {
  1877. struct wcd938x_priv *wcd938x_priv;
  1878. if(NULL == component) {
  1879. pr_err("%s: wcd938x component is NULL\n", __func__);
  1880. return -EINVAL;
  1881. }
  1882. wcd938x_priv = snd_soc_component_get_drvdata(component);
  1883. wcd938x_priv->notify_swr_dmic = enable;
  1884. if (enable)
  1885. return blocking_notifier_chain_register(&wcd938x_priv->notifier,
  1886. nblock);
  1887. else
  1888. return blocking_notifier_chain_unregister(
  1889. &wcd938x_priv->notifier, nblock);
  1890. }
  1891. EXPORT_SYMBOL(wcd938x_swr_dmic_register_notifier);
  1892. static int wcd938x_event_notify(struct notifier_block *block,
  1893. unsigned long val,
  1894. void *data)
  1895. {
  1896. u16 event = (val & 0xffff);
  1897. int ret = 0;
  1898. struct wcd938x_priv *wcd938x = dev_get_drvdata((struct device *)data);
  1899. struct snd_soc_component *component = wcd938x->component;
  1900. struct wcd_mbhc *mbhc;
  1901. switch (event) {
  1902. case BOLERO_WCD_EVT_TX_CH_HOLD_CLEAR:
  1903. if (test_bit(WCD_ADC1, &wcd938x->status_mask)) {
  1904. snd_soc_component_update_bits(component,
  1905. WCD938X_ANA_TX_CH2, 0x40, 0x00);
  1906. set_bit(WCD_ADC1_MODE, &wcd938x->status_mask);
  1907. clear_bit(WCD_ADC1, &wcd938x->status_mask);
  1908. }
  1909. if (test_bit(WCD_ADC2, &wcd938x->status_mask)) {
  1910. snd_soc_component_update_bits(component,
  1911. WCD938X_ANA_TX_CH2, 0x20, 0x00);
  1912. set_bit(WCD_ADC2_MODE, &wcd938x->status_mask);
  1913. clear_bit(WCD_ADC2, &wcd938x->status_mask);
  1914. }
  1915. if (test_bit(WCD_ADC3, &wcd938x->status_mask)) {
  1916. snd_soc_component_update_bits(component,
  1917. WCD938X_ANA_TX_CH4, 0x40, 0x00);
  1918. set_bit(WCD_ADC3_MODE, &wcd938x->status_mask);
  1919. clear_bit(WCD_ADC3, &wcd938x->status_mask);
  1920. }
  1921. if (test_bit(WCD_ADC4, &wcd938x->status_mask)) {
  1922. snd_soc_component_update_bits(component,
  1923. WCD938X_ANA_TX_CH4, 0x20, 0x00);
  1924. set_bit(WCD_ADC4_MODE, &wcd938x->status_mask);
  1925. clear_bit(WCD_ADC4, &wcd938x->status_mask);
  1926. }
  1927. break;
  1928. case BOLERO_WCD_EVT_PA_OFF_PRE_SSR:
  1929. snd_soc_component_update_bits(component, WCD938X_ANA_HPH,
  1930. 0xC0, 0x00);
  1931. snd_soc_component_update_bits(component, WCD938X_ANA_EAR,
  1932. 0x80, 0x00);
  1933. snd_soc_component_update_bits(component, WCD938X_AUX_AUXPA,
  1934. 0x80, 0x00);
  1935. break;
  1936. case BOLERO_WCD_EVT_SSR_DOWN:
  1937. wcd938x->dev_up = false;
  1938. if(wcd938x->notify_swr_dmic)
  1939. blocking_notifier_call_chain(&wcd938x->notifier,
  1940. WCD938X_EVT_SSR_DOWN,
  1941. NULL);
  1942. wcd938x->mbhc->wcd_mbhc.deinit_in_progress = true;
  1943. wcd938x->mbhc->wcd_mbhc.plug_before_ssr =
  1944. wcd938x->mbhc->wcd_mbhc.current_plug;
  1945. mbhc = &wcd938x->mbhc->wcd_mbhc;
  1946. wcd938x->usbc_hs_status = get_usbc_hs_status(component,
  1947. mbhc->mbhc_cfg);
  1948. wcd938x_mbhc_ssr_down(wcd938x->mbhc, component);
  1949. wcd938x_reset_low(wcd938x->dev);
  1950. break;
  1951. case BOLERO_WCD_EVT_SSR_UP:
  1952. wcd938x_reset(wcd938x->dev);
  1953. /* allow reset to take effect */
  1954. usleep_range(10000, 10010);
  1955. wcd938x_get_logical_addr(wcd938x->tx_swr_dev);
  1956. wcd938x_get_logical_addr(wcd938x->rx_swr_dev);
  1957. wcd938x_init_reg(component);
  1958. regcache_mark_dirty(wcd938x->regmap);
  1959. regcache_sync(wcd938x->regmap);
  1960. /* Initialize MBHC module */
  1961. mbhc = &wcd938x->mbhc->wcd_mbhc;
  1962. ret = wcd938x_mbhc_post_ssr_init(wcd938x->mbhc, component);
  1963. if (ret) {
  1964. dev_err(component->dev, "%s: mbhc initialization failed\n",
  1965. __func__);
  1966. } else {
  1967. wcd938x_mbhc_hs_detect(component, mbhc->mbhc_cfg);
  1968. if (wcd938x->usbc_hs_status)
  1969. mdelay(500);
  1970. }
  1971. wcd938x->mbhc->wcd_mbhc.deinit_in_progress = false;
  1972. wcd938x->dev_up = true;
  1973. if(wcd938x->notify_swr_dmic)
  1974. blocking_notifier_call_chain(&wcd938x->notifier,
  1975. WCD938X_EVT_SSR_UP,
  1976. NULL);
  1977. break;
  1978. case BOLERO_WCD_EVT_CLK_NOTIFY:
  1979. snd_soc_component_update_bits(component,
  1980. WCD938X_DIGITAL_TOP_CLK_CFG, 0x06,
  1981. ((val >> 0x10) << 0x01));
  1982. break;
  1983. default:
  1984. dev_dbg(component->dev, "%s: invalid event %d\n", __func__, event);
  1985. break;
  1986. }
  1987. return 0;
  1988. }
  1989. static int __wcd938x_codec_enable_micbias(struct snd_soc_dapm_widget *w,
  1990. int event)
  1991. {
  1992. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  1993. int micb_num;
  1994. dev_dbg(component->dev, "%s: wname: %s, event: %d\n",
  1995. __func__, w->name, event);
  1996. if (strnstr(w->name, "MIC BIAS1", sizeof("MIC BIAS1")))
  1997. micb_num = MIC_BIAS_1;
  1998. else if (strnstr(w->name, "MIC BIAS2", sizeof("MIC BIAS2")))
  1999. micb_num = MIC_BIAS_2;
  2000. else if (strnstr(w->name, "MIC BIAS3", sizeof("MIC BIAS3")))
  2001. micb_num = MIC_BIAS_3;
  2002. else if (strnstr(w->name, "MIC BIAS4", sizeof("MIC BIAS4")))
  2003. micb_num = MIC_BIAS_4;
  2004. else
  2005. return -EINVAL;
  2006. switch (event) {
  2007. case SND_SOC_DAPM_PRE_PMU:
  2008. wcd938x_micbias_control(component, micb_num,
  2009. MICB_ENABLE, true);
  2010. break;
  2011. case SND_SOC_DAPM_POST_PMU:
  2012. /* 1 msec delay as per HW requirement */
  2013. usleep_range(1000, 1100);
  2014. break;
  2015. case SND_SOC_DAPM_POST_PMD:
  2016. wcd938x_micbias_control(component, micb_num,
  2017. MICB_DISABLE, true);
  2018. break;
  2019. };
  2020. return 0;
  2021. }
  2022. static int wcd938x_codec_enable_micbias(struct snd_soc_dapm_widget *w,
  2023. struct snd_kcontrol *kcontrol,
  2024. int event)
  2025. {
  2026. return __wcd938x_codec_enable_micbias(w, event);
  2027. }
  2028. static int __wcd938x_codec_enable_micbias_pullup(struct snd_soc_dapm_widget *w,
  2029. int event)
  2030. {
  2031. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  2032. int micb_num;
  2033. dev_dbg(component->dev, "%s: wname: %s, event: %d\n",
  2034. __func__, w->name, event);
  2035. if (strnstr(w->name, "VA MIC BIAS1", sizeof("VA MIC BIAS1")))
  2036. micb_num = MIC_BIAS_1;
  2037. else if (strnstr(w->name, "VA MIC BIAS2", sizeof("VA MIC BIAS2")))
  2038. micb_num = MIC_BIAS_2;
  2039. else if (strnstr(w->name, "VA MIC BIAS3", sizeof("VA MIC BIAS3")))
  2040. micb_num = MIC_BIAS_3;
  2041. else if (strnstr(w->name, "VA MIC BIAS4", sizeof("VA MIC BIAS4")))
  2042. micb_num = MIC_BIAS_4;
  2043. else
  2044. return -EINVAL;
  2045. switch (event) {
  2046. case SND_SOC_DAPM_PRE_PMU:
  2047. wcd938x_micbias_control(component, micb_num,
  2048. MICB_PULLUP_ENABLE, true);
  2049. break;
  2050. case SND_SOC_DAPM_POST_PMU:
  2051. /* 1 msec delay as per HW requirement */
  2052. usleep_range(1000, 1100);
  2053. break;
  2054. case SND_SOC_DAPM_POST_PMD:
  2055. wcd938x_micbias_control(component, micb_num,
  2056. MICB_PULLUP_DISABLE, true);
  2057. break;
  2058. };
  2059. return 0;
  2060. }
  2061. static int wcd938x_codec_enable_micbias_pullup(struct snd_soc_dapm_widget *w,
  2062. struct snd_kcontrol *kcontrol,
  2063. int event)
  2064. {
  2065. return __wcd938x_codec_enable_micbias_pullup(w, event);
  2066. }
  2067. static int wcd938x_wakeup(void *handle, bool enable)
  2068. {
  2069. struct wcd938x_priv *priv;
  2070. int ret = 0;
  2071. if (!handle) {
  2072. pr_err("%s: NULL handle\n", __func__);
  2073. return -EINVAL;
  2074. }
  2075. priv = (struct wcd938x_priv *)handle;
  2076. if (!priv->tx_swr_dev) {
  2077. pr_err("%s: tx swr dev is NULL\n", __func__);
  2078. return -EINVAL;
  2079. }
  2080. mutex_lock(&priv->wakeup_lock);
  2081. if (enable)
  2082. ret = swr_device_wakeup_vote(priv->tx_swr_dev);
  2083. else
  2084. ret = swr_device_wakeup_unvote(priv->tx_swr_dev);
  2085. mutex_unlock(&priv->wakeup_lock);
  2086. return ret;
  2087. }
  2088. static int wcd938x_codec_force_enable_micbias(struct snd_soc_dapm_widget *w,
  2089. struct snd_kcontrol *kcontrol,
  2090. int event)
  2091. {
  2092. int ret = 0;
  2093. struct snd_soc_component *component =
  2094. snd_soc_dapm_to_component(w->dapm);
  2095. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  2096. switch (event) {
  2097. case SND_SOC_DAPM_PRE_PMU:
  2098. wcd938x_wakeup(wcd938x, true);
  2099. ret = __wcd938x_codec_enable_micbias(w, SND_SOC_DAPM_PRE_PMU);
  2100. wcd938x_wakeup(wcd938x, false);
  2101. break;
  2102. case SND_SOC_DAPM_POST_PMD:
  2103. wcd938x_wakeup(wcd938x, true);
  2104. ret = __wcd938x_codec_enable_micbias(w, SND_SOC_DAPM_POST_PMD);
  2105. wcd938x_wakeup(wcd938x, false);
  2106. break;
  2107. }
  2108. return ret;
  2109. }
  2110. static int wcd938x_enable_micbias(struct wcd938x_priv *wcd938x,
  2111. int micb_num, int req)
  2112. {
  2113. int micb_index = micb_num - 1;
  2114. u16 micb_reg;
  2115. if (NULL == wcd938x) {
  2116. pr_err("%s: wcd938x private data is NULL\n", __func__);
  2117. return -EINVAL;
  2118. }
  2119. switch (micb_num) {
  2120. case MIC_BIAS_1:
  2121. micb_reg = WCD938X_ANA_MICB1;
  2122. break;
  2123. case MIC_BIAS_2:
  2124. micb_reg = WCD938X_ANA_MICB2;
  2125. break;
  2126. case MIC_BIAS_3:
  2127. micb_reg = WCD938X_ANA_MICB3;
  2128. break;
  2129. case MIC_BIAS_4:
  2130. micb_reg = WCD938X_ANA_MICB4;
  2131. break;
  2132. default:
  2133. pr_err("%s: Invalid micbias number: %d\n", __func__, micb_num);
  2134. return -EINVAL;
  2135. };
  2136. pr_debug("%s: req: %d micb_num: %d micb_ref: %d pullup_ref: %d\n",
  2137. __func__, req, micb_num, wcd938x->micb_ref[micb_index],
  2138. wcd938x->pullup_ref[micb_index]);
  2139. mutex_lock(&wcd938x->micb_lock);
  2140. switch (req) {
  2141. case MICB_ENABLE:
  2142. wcd938x->micb_ref[micb_index]++;
  2143. if (wcd938x->micb_ref[micb_index] == 1) {
  2144. regmap_update_bits(wcd938x->regmap,
  2145. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0xE0, 0xE0);
  2146. regmap_update_bits(wcd938x->regmap,
  2147. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x10, 0x10);
  2148. regmap_update_bits(wcd938x->regmap,
  2149. WCD938X_DIGITAL_CDC_ANA_TX_CLK_CTL, 0x01, 0x01);
  2150. regmap_update_bits(wcd938x->regmap,
  2151. WCD938X_MICB1_TEST_CTL_2, 0x01, 0x01);
  2152. regmap_update_bits(wcd938x->regmap,
  2153. WCD938X_MICB2_TEST_CTL_2, 0x01, 0x01);
  2154. regmap_update_bits(wcd938x->regmap,
  2155. WCD938X_MICB3_TEST_CTL_2, 0x01, 0x01);
  2156. regmap_update_bits(wcd938x->regmap,
  2157. WCD938X_MICB4_TEST_CTL_2, 0x01, 0x01);
  2158. regmap_update_bits(wcd938x->regmap,
  2159. micb_reg, 0xC0, 0x40);
  2160. regmap_update_bits(wcd938x->regmap, micb_reg, 0x3F, 0x10);
  2161. }
  2162. break;
  2163. case MICB_PULLUP_ENABLE:
  2164. wcd938x->pullup_ref[micb_index]++;
  2165. if ((wcd938x->pullup_ref[micb_index] == 1) &&
  2166. (wcd938x->micb_ref[micb_index] == 0))
  2167. regmap_update_bits(wcd938x->regmap, micb_reg,
  2168. 0xC0, 0x80);
  2169. break;
  2170. case MICB_PULLUP_DISABLE:
  2171. if (wcd938x->pullup_ref[micb_index] > 0)
  2172. wcd938x->pullup_ref[micb_index]--;
  2173. if ((wcd938x->pullup_ref[micb_index] == 0) &&
  2174. (wcd938x->micb_ref[micb_index] == 0))
  2175. regmap_update_bits(wcd938x->regmap, micb_reg,
  2176. 0xC0, 0x00);
  2177. break;
  2178. case MICB_DISABLE:
  2179. if (wcd938x->micb_ref[micb_index] > 0)
  2180. wcd938x->micb_ref[micb_index]--;
  2181. if ((wcd938x->micb_ref[micb_index] == 0) &&
  2182. (wcd938x->pullup_ref[micb_index] > 0))
  2183. regmap_update_bits(wcd938x->regmap, micb_reg,
  2184. 0xC0, 0x80);
  2185. else if ((wcd938x->micb_ref[micb_index] == 0) &&
  2186. (wcd938x->pullup_ref[micb_index] == 0))
  2187. regmap_update_bits(wcd938x->regmap, micb_reg,
  2188. 0xC0, 0x00);
  2189. break;
  2190. };
  2191. mutex_unlock(&wcd938x->micb_lock);
  2192. return 0;
  2193. }
  2194. int wcd938x_codec_force_enable_micbias_v2(struct snd_soc_component *component,
  2195. int event, int micb_num)
  2196. {
  2197. struct wcd938x_priv *wcd938x_priv = NULL;
  2198. int ret = 0;
  2199. int micb_index = micb_num - 1;
  2200. if(NULL == component) {
  2201. pr_err("%s: wcd938x component is NULL\n", __func__);
  2202. return -EINVAL;
  2203. }
  2204. if(event != SND_SOC_DAPM_PRE_PMU && event != SND_SOC_DAPM_POST_PMD) {
  2205. pr_err("%s: invalid event: %d\n", __func__, event);
  2206. return -EINVAL;
  2207. }
  2208. if(micb_num < MIC_BIAS_1 || micb_num > MIC_BIAS_4) {
  2209. pr_err("%s: invalid mic bias num: %d\n", __func__, micb_num);
  2210. return -EINVAL;
  2211. }
  2212. wcd938x_priv = snd_soc_component_get_drvdata(component);
  2213. if (!wcd938x_priv->dev_up) {
  2214. if ((wcd938x_priv->pullup_ref[micb_index] > 0) &&
  2215. (event == SND_SOC_DAPM_POST_PMD)) {
  2216. wcd938x_priv->pullup_ref[micb_index]--;
  2217. ret = -ENODEV;
  2218. goto done;
  2219. }
  2220. }
  2221. switch (event) {
  2222. case SND_SOC_DAPM_PRE_PMU:
  2223. wcd938x_wakeup(wcd938x_priv, true);
  2224. wcd938x_enable_micbias(wcd938x_priv, micb_num, MICB_PULLUP_ENABLE);
  2225. wcd938x_wakeup(wcd938x_priv, false);
  2226. break;
  2227. case SND_SOC_DAPM_POST_PMD:
  2228. wcd938x_wakeup(wcd938x_priv, true);
  2229. wcd938x_enable_micbias(wcd938x_priv, micb_num, MICB_PULLUP_DISABLE);
  2230. wcd938x_wakeup(wcd938x_priv, false);
  2231. break;
  2232. }
  2233. done:
  2234. return ret;
  2235. }
  2236. EXPORT_SYMBOL(wcd938x_codec_force_enable_micbias_v2);
  2237. static inline int wcd938x_tx_path_get(const char *wname,
  2238. unsigned int *path_num)
  2239. {
  2240. int ret = 0;
  2241. char *widget_name = NULL;
  2242. char *w_name = NULL;
  2243. char *path_num_char = NULL;
  2244. char *path_name = NULL;
  2245. widget_name = kstrndup(wname, 9, GFP_KERNEL);
  2246. if (!widget_name)
  2247. return -EINVAL;
  2248. w_name = widget_name;
  2249. path_name = strsep(&widget_name, " ");
  2250. if (!path_name) {
  2251. pr_err("%s: Invalid widget name = %s\n",
  2252. __func__, widget_name);
  2253. ret = -EINVAL;
  2254. goto err;
  2255. }
  2256. path_num_char = strpbrk(path_name, "0123");
  2257. if (!path_num_char) {
  2258. pr_err("%s: tx path index not found\n",
  2259. __func__);
  2260. ret = -EINVAL;
  2261. goto err;
  2262. }
  2263. ret = kstrtouint(path_num_char, 10, path_num);
  2264. if (ret < 0)
  2265. pr_err("%s: Invalid tx path = %s\n",
  2266. __func__, w_name);
  2267. err:
  2268. kfree(w_name);
  2269. return ret;
  2270. }
  2271. static int wcd938x_tx_mode_get(struct snd_kcontrol *kcontrol,
  2272. struct snd_ctl_elem_value *ucontrol)
  2273. {
  2274. struct snd_soc_component *component =
  2275. snd_soc_kcontrol_component(kcontrol);
  2276. struct wcd938x_priv *wcd938x = NULL;
  2277. int ret = 0;
  2278. unsigned int path = 0;
  2279. if (!component)
  2280. return -EINVAL;
  2281. wcd938x = snd_soc_component_get_drvdata(component);
  2282. if (!wcd938x)
  2283. return -EINVAL;
  2284. ret = wcd938x_tx_path_get(kcontrol->id.name, &path);
  2285. if (ret < 0)
  2286. return ret;
  2287. ucontrol->value.integer.value[0] = wcd938x->tx_mode[path];
  2288. return 0;
  2289. }
  2290. static int wcd938x_tx_mode_put(struct snd_kcontrol *kcontrol,
  2291. struct snd_ctl_elem_value *ucontrol)
  2292. {
  2293. struct snd_soc_component *component =
  2294. snd_soc_kcontrol_component(kcontrol);
  2295. struct wcd938x_priv *wcd938x = NULL;
  2296. u32 mode_val;
  2297. unsigned int path = 0;
  2298. int ret = 0;
  2299. if (!component)
  2300. return -EINVAL;
  2301. wcd938x = snd_soc_component_get_drvdata(component);
  2302. if (!wcd938x)
  2303. return -EINVAL;
  2304. ret = wcd938x_tx_path_get(kcontrol->id.name, &path);
  2305. if (ret)
  2306. return ret;
  2307. mode_val = ucontrol->value.enumerated.item[0];
  2308. dev_dbg(component->dev, "%s: mode: %d\n", __func__, mode_val);
  2309. wcd938x->tx_mode[path] = mode_val;
  2310. return 0;
  2311. }
  2312. static int wcd938x_rx_hph_mode_get(struct snd_kcontrol *kcontrol,
  2313. struct snd_ctl_elem_value *ucontrol)
  2314. {
  2315. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  2316. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  2317. ucontrol->value.integer.value[0] = wcd938x->hph_mode;
  2318. return 0;
  2319. }
  2320. static int wcd938x_rx_hph_mode_put(struct snd_kcontrol *kcontrol,
  2321. struct snd_ctl_elem_value *ucontrol)
  2322. {
  2323. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  2324. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  2325. u32 mode_val;
  2326. mode_val = ucontrol->value.enumerated.item[0];
  2327. dev_dbg(component->dev, "%s: mode: %d\n", __func__, mode_val);
  2328. if (wcd938x->variant == WCD9380) {
  2329. if (mode_val == CLS_H_HIFI || mode_val == CLS_AB_HIFI) {
  2330. dev_info(component->dev,
  2331. "%s:Invalid HPH Mode, default to CLS_H_ULP\n",
  2332. __func__);
  2333. mode_val = CLS_H_ULP;
  2334. }
  2335. }
  2336. if (mode_val == CLS_H_NORMAL) {
  2337. dev_info(component->dev,
  2338. "%s:Invalid HPH Mode, default to class_AB\n",
  2339. __func__);
  2340. mode_val = CLS_H_ULP;
  2341. }
  2342. wcd938x->hph_mode = mode_val;
  2343. return 0;
  2344. }
  2345. static int wcd938x_ear_pa_gain_get(struct snd_kcontrol *kcontrol,
  2346. struct snd_ctl_elem_value *ucontrol)
  2347. {
  2348. u8 ear_pa_gain = 0;
  2349. struct snd_soc_component *component =
  2350. snd_soc_kcontrol_component(kcontrol);
  2351. ear_pa_gain = snd_soc_component_read32(component,
  2352. WCD938X_ANA_EAR_COMPANDER_CTL);
  2353. ear_pa_gain = (ear_pa_gain & 0x7C) >> 2;
  2354. ucontrol->value.integer.value[0] = ear_pa_gain;
  2355. dev_dbg(component->dev, "%s: ear_pa_gain = 0x%x\n", __func__,
  2356. ear_pa_gain);
  2357. return 0;
  2358. }
  2359. static int wcd938x_ear_pa_gain_put(struct snd_kcontrol *kcontrol,
  2360. struct snd_ctl_elem_value *ucontrol)
  2361. {
  2362. u8 ear_pa_gain = 0;
  2363. struct snd_soc_component *component =
  2364. snd_soc_kcontrol_component(kcontrol);
  2365. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  2366. dev_dbg(component->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  2367. __func__, ucontrol->value.integer.value[0]);
  2368. ear_pa_gain = ucontrol->value.integer.value[0] << 2;
  2369. if (!wcd938x->comp1_enable) {
  2370. snd_soc_component_update_bits(component,
  2371. WCD938X_ANA_EAR_COMPANDER_CTL,
  2372. 0x7C, ear_pa_gain);
  2373. }
  2374. return 0;
  2375. }
  2376. static int wcd938x_get_compander(struct snd_kcontrol *kcontrol,
  2377. struct snd_ctl_elem_value *ucontrol)
  2378. {
  2379. struct snd_soc_component *component =
  2380. snd_soc_kcontrol_component(kcontrol);
  2381. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  2382. bool hphr;
  2383. struct soc_multi_mixer_control *mc;
  2384. mc = (struct soc_multi_mixer_control *)(kcontrol->private_value);
  2385. hphr = mc->shift;
  2386. ucontrol->value.integer.value[0] = hphr ? wcd938x->comp2_enable :
  2387. wcd938x->comp1_enable;
  2388. return 0;
  2389. }
  2390. static int wcd938x_set_compander(struct snd_kcontrol *kcontrol,
  2391. struct snd_ctl_elem_value *ucontrol)
  2392. {
  2393. struct snd_soc_component *component =
  2394. snd_soc_kcontrol_component(kcontrol);
  2395. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  2396. int value = ucontrol->value.integer.value[0];
  2397. bool hphr;
  2398. struct soc_multi_mixer_control *mc;
  2399. mc = (struct soc_multi_mixer_control *)(kcontrol->private_value);
  2400. hphr = mc->shift;
  2401. if (hphr)
  2402. wcd938x->comp2_enable = value;
  2403. else
  2404. wcd938x->comp1_enable = value;
  2405. return 0;
  2406. }
  2407. static int wcd938x_codec_enable_vdd_buck(struct snd_soc_dapm_widget *w,
  2408. struct snd_kcontrol *kcontrol,
  2409. int event)
  2410. {
  2411. struct snd_soc_component *component =
  2412. snd_soc_dapm_to_component(w->dapm);
  2413. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  2414. struct wcd938x_pdata *pdata = NULL;
  2415. int ret = 0;
  2416. pdata = dev_get_platdata(wcd938x->dev);
  2417. if (!pdata) {
  2418. dev_err(component->dev, "%s: pdata is NULL\n", __func__);
  2419. return -EINVAL;
  2420. }
  2421. if (!msm_cdc_is_ondemand_supply(wcd938x->dev,
  2422. wcd938x->supplies,
  2423. pdata->regulator,
  2424. pdata->num_supplies,
  2425. "cdc-vdd-buck"))
  2426. return 0;
  2427. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  2428. w->name, event);
  2429. switch (event) {
  2430. case SND_SOC_DAPM_PRE_PMU:
  2431. if (test_bit(ALLOW_BUCK_DISABLE, &wcd938x->status_mask)) {
  2432. dev_dbg(component->dev,
  2433. "%s: buck already in enabled state\n",
  2434. __func__);
  2435. clear_bit(ALLOW_BUCK_DISABLE, &wcd938x->status_mask);
  2436. return 0;
  2437. }
  2438. ret = msm_cdc_enable_ondemand_supply(wcd938x->dev,
  2439. wcd938x->supplies,
  2440. pdata->regulator,
  2441. pdata->num_supplies,
  2442. "cdc-vdd-buck");
  2443. if (ret == -EINVAL) {
  2444. dev_err(component->dev, "%s: vdd buck is not enabled\n",
  2445. __func__);
  2446. return ret;
  2447. }
  2448. clear_bit(ALLOW_BUCK_DISABLE, &wcd938x->status_mask);
  2449. /*
  2450. * 200us sleep is required after LDO is enabled as per
  2451. * HW requirement
  2452. */
  2453. usleep_range(200, 250);
  2454. break;
  2455. case SND_SOC_DAPM_POST_PMD:
  2456. set_bit(ALLOW_BUCK_DISABLE, &wcd938x->status_mask);
  2457. break;
  2458. }
  2459. return 0;
  2460. }
  2461. static int wcd938x_ldoh_get(struct snd_kcontrol *kcontrol,
  2462. struct snd_ctl_elem_value *ucontrol)
  2463. {
  2464. struct snd_soc_component *component =
  2465. snd_soc_kcontrol_component(kcontrol);
  2466. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  2467. ucontrol->value.integer.value[0] = wcd938x->ldoh;
  2468. return 0;
  2469. }
  2470. static int wcd938x_ldoh_put(struct snd_kcontrol *kcontrol,
  2471. struct snd_ctl_elem_value *ucontrol)
  2472. {
  2473. struct snd_soc_component *component =
  2474. snd_soc_kcontrol_component(kcontrol);
  2475. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  2476. wcd938x->ldoh = ucontrol->value.integer.value[0];
  2477. return 0;
  2478. }
  2479. const char * const tx_master_ch_text[] = {
  2480. "ZERO", "SWRM_TX1_CH1", "SWRM_TX1_CH2", "SWRM_TX1_CH3", "SWRM_TX1_CH4",
  2481. "SWRM_TX2_CH1", "SWRM_TX2_CH2", "SWRM_TX2_CH3", "SWRM_TX2_CH4",
  2482. "SWRM_TX3_CH1", "SWRM_TX3_CH2", "SWRM_TX3_CH3", "SWRM_TX3_CH4",
  2483. "SWRM_PCM_IN",
  2484. };
  2485. const struct soc_enum tx_master_ch_enum =
  2486. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(tx_master_ch_text),
  2487. tx_master_ch_text);
  2488. static void wcd938x_tx_get_slave_ch_type_idx(const char *wname, int *ch_idx)
  2489. {
  2490. u8 ch_type = 0;
  2491. if (strnstr(wname, "ADC1", sizeof("ADC1")))
  2492. ch_type = ADC1;
  2493. else if (strnstr(wname, "ADC2", sizeof("ADC2")))
  2494. ch_type = ADC2;
  2495. else if (strnstr(wname, "ADC3", sizeof("ADC3")))
  2496. ch_type = ADC3;
  2497. else if (strnstr(wname, "ADC4", sizeof("ADC4")))
  2498. ch_type = ADC4;
  2499. else if (strnstr(wname, "DMIC0", sizeof("DMIC0")))
  2500. ch_type = DMIC0;
  2501. else if (strnstr(wname, "DMIC1", sizeof("DMIC1")))
  2502. ch_type = DMIC1;
  2503. else if (strnstr(wname, "MBHC", sizeof("MBHC")))
  2504. ch_type = MBHC;
  2505. else if (strnstr(wname, "DMIC2", sizeof("DMIC2")))
  2506. ch_type = DMIC2;
  2507. else if (strnstr(wname, "DMIC3", sizeof("DMIC3")))
  2508. ch_type = DMIC3;
  2509. else if (strnstr(wname, "DMIC4", sizeof("DMIC4")))
  2510. ch_type = DMIC4;
  2511. else if (strnstr(wname, "DMIC5", sizeof("DMIC5")))
  2512. ch_type = DMIC5;
  2513. else if (strnstr(wname, "DMIC6", sizeof("DMIC6")))
  2514. ch_type = DMIC6;
  2515. else if (strnstr(wname, "DMIC7", sizeof("DMIC7")))
  2516. ch_type = DMIC7;
  2517. else
  2518. pr_err("%s: port name: %s is not listed\n", __func__, wname);
  2519. if (ch_type)
  2520. *ch_idx = wcd938x_slave_get_slave_ch_val(ch_type);
  2521. else
  2522. *ch_idx = -EINVAL;
  2523. }
  2524. static int wcd938x_tx_master_ch_get(struct snd_kcontrol *kcontrol,
  2525. struct snd_ctl_elem_value *ucontrol)
  2526. {
  2527. struct snd_soc_component *component =
  2528. snd_soc_kcontrol_component(kcontrol);
  2529. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  2530. int slave_ch_idx;
  2531. wcd938x_tx_get_slave_ch_type_idx(kcontrol->id.name, &slave_ch_idx);
  2532. if (slave_ch_idx != -EINVAL)
  2533. ucontrol->value.integer.value[0] =
  2534. wcd938x_slave_get_master_ch_val(
  2535. wcd938x->tx_master_ch_map[slave_ch_idx]);
  2536. return 0;
  2537. }
  2538. static int wcd938x_tx_master_ch_put(struct snd_kcontrol *kcontrol,
  2539. struct snd_ctl_elem_value *ucontrol)
  2540. {
  2541. struct snd_soc_component *component =
  2542. snd_soc_kcontrol_component(kcontrol);
  2543. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  2544. int slave_ch_idx;
  2545. wcd938x_tx_get_slave_ch_type_idx(kcontrol->id.name, &slave_ch_idx);
  2546. dev_dbg(component->dev, "%s: slave_ch_idx: %d", __func__, slave_ch_idx);
  2547. dev_dbg(component->dev, "%s: ucontrol->value.enumerated.item[0] = %ld\n",
  2548. __func__, ucontrol->value.enumerated.item[0]);
  2549. if (slave_ch_idx != -EINVAL)
  2550. wcd938x->tx_master_ch_map[slave_ch_idx] =
  2551. wcd938x_slave_get_master_ch(
  2552. ucontrol->value.enumerated.item[0]);
  2553. return 0;
  2554. }
  2555. static int wcd938x_bcs_get(struct snd_kcontrol *kcontrol,
  2556. struct snd_ctl_elem_value *ucontrol)
  2557. {
  2558. struct snd_soc_component *component =
  2559. snd_soc_kcontrol_component(kcontrol);
  2560. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  2561. ucontrol->value.integer.value[0] = wcd938x->bcs_dis;
  2562. return 0;
  2563. }
  2564. static int wcd938x_bcs_put(struct snd_kcontrol *kcontrol,
  2565. struct snd_ctl_elem_value *ucontrol)
  2566. {
  2567. struct snd_soc_component *component =
  2568. snd_soc_kcontrol_component(kcontrol);
  2569. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  2570. wcd938x->bcs_dis = ucontrol->value.integer.value[0];
  2571. return 0;
  2572. }
  2573. static const char * const tx_mode_mux_text_wcd9380[] = {
  2574. "ADC_INVALID", "ADC_HIFI", "ADC_LO_HIF", "ADC_NORMAL", "ADC_LP",
  2575. };
  2576. static const struct soc_enum tx_mode_mux_enum_wcd9380 =
  2577. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(tx_mode_mux_text_wcd9380),
  2578. tx_mode_mux_text_wcd9380);
  2579. static const char * const tx_mode_mux_text[] = {
  2580. "ADC_INVALID", "ADC_HIFI", "ADC_LO_HIF", "ADC_NORMAL", "ADC_LP",
  2581. "ADC_ULP1", "ADC_ULP2",
  2582. };
  2583. static const struct soc_enum tx_mode_mux_enum =
  2584. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(tx_mode_mux_text),
  2585. tx_mode_mux_text);
  2586. static const char * const rx_hph_mode_mux_text_wcd9380[] = {
  2587. "CLS_H_INVALID", "CLS_H_INVALID_1", "CLS_H_LP", "CLS_AB",
  2588. "CLS_H_LOHIFI", "CLS_H_ULP", "CLS_H_INVALID_2", "CLS_AB_LP",
  2589. "CLS_AB_LOHIFI",
  2590. };
  2591. static const char * const wcd938x_ear_pa_gain_text[] = {
  2592. "G_6_DB", "G_4P5_DB", "G_3_DB", "G_1P5_DB", "G_0_DB",
  2593. "G_M1P5_DB", "G_M3_DB", "G_M4P5_DB",
  2594. "G_M6_DB", "G_7P5_DB", "G_M9_DB",
  2595. "G_M10P5_DB", "G_M12_DB", "G_M13P5_DB",
  2596. "G_M15_DB", "G_M16P5_DB", "G_M18_DB",
  2597. };
  2598. static const struct soc_enum rx_hph_mode_mux_enum_wcd9380 =
  2599. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(rx_hph_mode_mux_text_wcd9380),
  2600. rx_hph_mode_mux_text_wcd9380);
  2601. static SOC_ENUM_SINGLE_EXT_DECL(wcd938x_ear_pa_gain_enum,
  2602. wcd938x_ear_pa_gain_text);
  2603. static const char * const rx_hph_mode_mux_text[] = {
  2604. "CLS_H_INVALID", "CLS_H_HIFI", "CLS_H_LP", "CLS_AB", "CLS_H_LOHIFI",
  2605. "CLS_H_ULP", "CLS_AB_HIFI", "CLS_AB_LP", "CLS_AB_LOHIFI",
  2606. };
  2607. static const struct soc_enum rx_hph_mode_mux_enum =
  2608. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(rx_hph_mode_mux_text),
  2609. rx_hph_mode_mux_text);
  2610. static const struct snd_kcontrol_new wcd9380_snd_controls[] = {
  2611. SOC_ENUM_EXT("EAR PA GAIN", wcd938x_ear_pa_gain_enum,
  2612. wcd938x_ear_pa_gain_get, wcd938x_ear_pa_gain_put),
  2613. SOC_ENUM_EXT("RX HPH Mode", rx_hph_mode_mux_enum_wcd9380,
  2614. wcd938x_rx_hph_mode_get, wcd938x_rx_hph_mode_put),
  2615. SOC_ENUM_EXT("TX0 MODE", tx_mode_mux_enum_wcd9380,
  2616. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  2617. SOC_ENUM_EXT("TX1 MODE", tx_mode_mux_enum_wcd9380,
  2618. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  2619. SOC_ENUM_EXT("TX2 MODE", tx_mode_mux_enum_wcd9380,
  2620. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  2621. SOC_ENUM_EXT("TX3 MODE", tx_mode_mux_enum_wcd9380,
  2622. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  2623. };
  2624. static const struct snd_kcontrol_new wcd9385_snd_controls[] = {
  2625. SOC_ENUM_EXT("RX HPH Mode", rx_hph_mode_mux_enum,
  2626. wcd938x_rx_hph_mode_get, wcd938x_rx_hph_mode_put),
  2627. SOC_ENUM_EXT("TX0 MODE", tx_mode_mux_enum,
  2628. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  2629. SOC_ENUM_EXT("TX1 MODE", tx_mode_mux_enum,
  2630. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  2631. SOC_ENUM_EXT("TX2 MODE", tx_mode_mux_enum,
  2632. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  2633. SOC_ENUM_EXT("TX3 MODE", tx_mode_mux_enum,
  2634. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  2635. };
  2636. static const struct snd_kcontrol_new wcd938x_snd_controls[] = {
  2637. SOC_SINGLE_EXT("HPHL_COMP Switch", SND_SOC_NOPM, 0, 1, 0,
  2638. wcd938x_get_compander, wcd938x_set_compander),
  2639. SOC_SINGLE_EXT("HPHR_COMP Switch", SND_SOC_NOPM, 1, 1, 0,
  2640. wcd938x_get_compander, wcd938x_set_compander),
  2641. SOC_SINGLE_EXT("LDOH Enable", SND_SOC_NOPM, 0, 1, 0,
  2642. wcd938x_ldoh_get, wcd938x_ldoh_put),
  2643. SOC_SINGLE_EXT("ADC2_BCS Disable", SND_SOC_NOPM, 0, 1, 0,
  2644. wcd938x_bcs_get, wcd938x_bcs_put),
  2645. SOC_SINGLE_TLV("HPHL Volume", WCD938X_HPH_L_EN, 0, 20, 1, line_gain),
  2646. SOC_SINGLE_TLV("HPHR Volume", WCD938X_HPH_R_EN, 0, 20, 1, line_gain),
  2647. SOC_SINGLE_TLV("ADC1 Volume", WCD938X_ANA_TX_CH1, 0, 20, 0,
  2648. analog_gain),
  2649. SOC_SINGLE_TLV("ADC2 Volume", WCD938X_ANA_TX_CH2, 0, 20, 0,
  2650. analog_gain),
  2651. SOC_SINGLE_TLV("ADC3 Volume", WCD938X_ANA_TX_CH3, 0, 20, 0,
  2652. analog_gain),
  2653. SOC_SINGLE_TLV("ADC4 Volume", WCD938X_ANA_TX_CH4, 0, 20, 0,
  2654. analog_gain),
  2655. SOC_ENUM_EXT("ADC1 ChMap", tx_master_ch_enum,
  2656. wcd938x_tx_master_ch_get, wcd938x_tx_master_ch_put),
  2657. SOC_ENUM_EXT("ADC2 ChMap", tx_master_ch_enum,
  2658. wcd938x_tx_master_ch_get, wcd938x_tx_master_ch_put),
  2659. SOC_ENUM_EXT("ADC3 ChMap", tx_master_ch_enum,
  2660. wcd938x_tx_master_ch_get, wcd938x_tx_master_ch_put),
  2661. SOC_ENUM_EXT("ADC4 ChMap", tx_master_ch_enum,
  2662. wcd938x_tx_master_ch_get, wcd938x_tx_master_ch_put),
  2663. SOC_ENUM_EXT("DMIC0 ChMap", tx_master_ch_enum,
  2664. wcd938x_tx_master_ch_get, wcd938x_tx_master_ch_put),
  2665. SOC_ENUM_EXT("DMIC1 ChMap", tx_master_ch_enum,
  2666. wcd938x_tx_master_ch_get, wcd938x_tx_master_ch_put),
  2667. SOC_ENUM_EXT("MBHC ChMap", tx_master_ch_enum,
  2668. wcd938x_tx_master_ch_get, wcd938x_tx_master_ch_put),
  2669. SOC_ENUM_EXT("DMIC2 ChMap", tx_master_ch_enum,
  2670. wcd938x_tx_master_ch_get, wcd938x_tx_master_ch_put),
  2671. SOC_ENUM_EXT("DMIC3 ChMap", tx_master_ch_enum,
  2672. wcd938x_tx_master_ch_get, wcd938x_tx_master_ch_put),
  2673. SOC_ENUM_EXT("DMIC4 ChMap", tx_master_ch_enum,
  2674. wcd938x_tx_master_ch_get, wcd938x_tx_master_ch_put),
  2675. SOC_ENUM_EXT("DMIC5 ChMap", tx_master_ch_enum,
  2676. wcd938x_tx_master_ch_get, wcd938x_tx_master_ch_put),
  2677. SOC_ENUM_EXT("DMIC6 ChMap", tx_master_ch_enum,
  2678. wcd938x_tx_master_ch_get, wcd938x_tx_master_ch_put),
  2679. SOC_ENUM_EXT("DMIC7 ChMap", tx_master_ch_enum,
  2680. wcd938x_tx_master_ch_get, wcd938x_tx_master_ch_put),
  2681. };
  2682. static const struct snd_kcontrol_new adc1_switch[] = {
  2683. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2684. };
  2685. static const struct snd_kcontrol_new adc2_switch[] = {
  2686. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2687. };
  2688. static const struct snd_kcontrol_new adc3_switch[] = {
  2689. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2690. };
  2691. static const struct snd_kcontrol_new adc4_switch[] = {
  2692. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2693. };
  2694. static const struct snd_kcontrol_new dmic1_switch[] = {
  2695. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2696. };
  2697. static const struct snd_kcontrol_new dmic2_switch[] = {
  2698. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2699. };
  2700. static const struct snd_kcontrol_new dmic3_switch[] = {
  2701. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2702. };
  2703. static const struct snd_kcontrol_new dmic4_switch[] = {
  2704. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2705. };
  2706. static const struct snd_kcontrol_new dmic5_switch[] = {
  2707. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2708. };
  2709. static const struct snd_kcontrol_new dmic6_switch[] = {
  2710. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2711. };
  2712. static const struct snd_kcontrol_new dmic7_switch[] = {
  2713. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2714. };
  2715. static const struct snd_kcontrol_new dmic8_switch[] = {
  2716. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2717. };
  2718. static const struct snd_kcontrol_new ear_rdac_switch[] = {
  2719. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2720. };
  2721. static const struct snd_kcontrol_new aux_rdac_switch[] = {
  2722. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2723. };
  2724. static const struct snd_kcontrol_new hphl_rdac_switch[] = {
  2725. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2726. };
  2727. static const struct snd_kcontrol_new hphr_rdac_switch[] = {
  2728. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  2729. };
  2730. static const char * const adc2_mux_text[] = {
  2731. "INP2", "INP3"
  2732. };
  2733. static const struct soc_enum adc2_enum =
  2734. SOC_ENUM_SINGLE(WCD938X_TX_NEW_AMIC_MUX_CFG, 7,
  2735. ARRAY_SIZE(adc2_mux_text), adc2_mux_text);
  2736. static const struct snd_kcontrol_new tx_adc2_mux =
  2737. SOC_DAPM_ENUM("ADC2 MUX Mux", adc2_enum);
  2738. static const char * const adc3_mux_text[] = {
  2739. "INP4", "INP6"
  2740. };
  2741. static const struct soc_enum adc3_enum =
  2742. SOC_ENUM_SINGLE(WCD938X_TX_NEW_AMIC_MUX_CFG, 6,
  2743. ARRAY_SIZE(adc3_mux_text), adc3_mux_text);
  2744. static const struct snd_kcontrol_new tx_adc3_mux =
  2745. SOC_DAPM_ENUM("ADC3 MUX Mux", adc3_enum);
  2746. static const char * const adc4_mux_text[] = {
  2747. "INP5", "INP7"
  2748. };
  2749. static const struct soc_enum adc4_enum =
  2750. SOC_ENUM_SINGLE(WCD938X_TX_NEW_AMIC_MUX_CFG, 5,
  2751. ARRAY_SIZE(adc4_mux_text), adc4_mux_text);
  2752. static const struct snd_kcontrol_new tx_adc4_mux =
  2753. SOC_DAPM_ENUM("ADC4 MUX Mux", adc4_enum);
  2754. static const char * const rdac3_mux_text[] = {
  2755. "RX1", "RX3"
  2756. };
  2757. static const char * const hdr12_mux_text[] = {
  2758. "NO_HDR12", "HDR12"
  2759. };
  2760. static const struct soc_enum hdr12_enum =
  2761. SOC_ENUM_SINGLE(WCD938X_TX_NEW_AMIC_MUX_CFG, 4,
  2762. ARRAY_SIZE(hdr12_mux_text), hdr12_mux_text);
  2763. static const struct snd_kcontrol_new tx_hdr12_mux =
  2764. SOC_DAPM_ENUM("HDR12 MUX Mux", hdr12_enum);
  2765. static const char * const hdr34_mux_text[] = {
  2766. "NO_HDR34", "HDR34"
  2767. };
  2768. static const struct soc_enum hdr34_enum =
  2769. SOC_ENUM_SINGLE(WCD938X_TX_NEW_AMIC_MUX_CFG, 3,
  2770. ARRAY_SIZE(hdr34_mux_text), hdr34_mux_text);
  2771. static const struct snd_kcontrol_new tx_hdr34_mux =
  2772. SOC_DAPM_ENUM("HDR34 MUX Mux", hdr34_enum);
  2773. static const struct soc_enum rdac3_enum =
  2774. SOC_ENUM_SINGLE(WCD938X_DIGITAL_CDC_EAR_PATH_CTL, 0,
  2775. ARRAY_SIZE(rdac3_mux_text), rdac3_mux_text);
  2776. static const struct snd_kcontrol_new rx_rdac3_mux =
  2777. SOC_DAPM_ENUM("RDAC3_MUX Mux", rdac3_enum);
  2778. static const struct snd_soc_dapm_widget wcd938x_dapm_widgets[] = {
  2779. /*input widgets*/
  2780. SND_SOC_DAPM_INPUT("AMIC1"),
  2781. SND_SOC_DAPM_INPUT("AMIC2"),
  2782. SND_SOC_DAPM_INPUT("AMIC3"),
  2783. SND_SOC_DAPM_INPUT("AMIC4"),
  2784. SND_SOC_DAPM_INPUT("AMIC5"),
  2785. SND_SOC_DAPM_INPUT("AMIC6"),
  2786. SND_SOC_DAPM_INPUT("AMIC7"),
  2787. SND_SOC_DAPM_INPUT("IN1_HPHL"),
  2788. SND_SOC_DAPM_INPUT("IN2_HPHR"),
  2789. SND_SOC_DAPM_INPUT("IN3_AUX"),
  2790. /*
  2791. * These dummy widgets are null connected to WCD938x dapm input and
  2792. * output widgets which are not actual path endpoints. This ensures
  2793. * dapm doesnt set these dapm input and output widgets as endpoints.
  2794. */
  2795. SND_SOC_DAPM_INPUT("WCD_TX_DUMMY"),
  2796. SND_SOC_DAPM_OUTPUT("WCD_RX_DUMMY"),
  2797. /*tx widgets*/
  2798. SND_SOC_DAPM_ADC_E("ADC1", NULL, SND_SOC_NOPM, 0, 0,
  2799. wcd938x_codec_enable_adc,
  2800. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2801. SND_SOC_DAPM_ADC_E("ADC2", NULL, SND_SOC_NOPM, 1, 0,
  2802. wcd938x_codec_enable_adc,
  2803. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2804. SND_SOC_DAPM_ADC_E("ADC3", NULL, SND_SOC_NOPM, 2, 0,
  2805. wcd938x_codec_enable_adc,
  2806. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2807. SND_SOC_DAPM_ADC_E("ADC4", NULL, SND_SOC_NOPM, 3, 0,
  2808. wcd938x_codec_enable_adc,
  2809. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2810. SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 0, 0,
  2811. wcd938x_codec_enable_dmic,
  2812. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2813. SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 1, 0,
  2814. wcd938x_codec_enable_dmic,
  2815. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2816. SND_SOC_DAPM_ADC_E("DMIC3", NULL, SND_SOC_NOPM, 2, 0,
  2817. wcd938x_codec_enable_dmic,
  2818. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2819. SND_SOC_DAPM_ADC_E("DMIC4", NULL, SND_SOC_NOPM, 3, 0,
  2820. wcd938x_codec_enable_dmic,
  2821. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2822. SND_SOC_DAPM_ADC_E("DMIC5", NULL, SND_SOC_NOPM, 4, 0,
  2823. wcd938x_codec_enable_dmic,
  2824. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2825. SND_SOC_DAPM_ADC_E("DMIC6", NULL, SND_SOC_NOPM, 5, 0,
  2826. wcd938x_codec_enable_dmic,
  2827. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2828. SND_SOC_DAPM_ADC_E("DMIC7", NULL, SND_SOC_NOPM, 6, 0,
  2829. wcd938x_codec_enable_dmic,
  2830. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2831. SND_SOC_DAPM_ADC_E("DMIC8", NULL, SND_SOC_NOPM, 7, 0,
  2832. wcd938x_codec_enable_dmic,
  2833. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2834. SND_SOC_DAPM_MIXER_E("ADC1 REQ", SND_SOC_NOPM, 0, 0,
  2835. NULL, 0, wcd938x_enable_req,
  2836. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2837. SND_SOC_DAPM_MIXER_E("ADC2 REQ", SND_SOC_NOPM, 1, 0,
  2838. NULL, 0, wcd938x_enable_req,
  2839. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2840. SND_SOC_DAPM_MIXER_E("ADC3 REQ", SND_SOC_NOPM, 2, 0,
  2841. NULL, 0, wcd938x_enable_req,
  2842. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2843. SND_SOC_DAPM_MIXER_E("ADC4 REQ", SND_SOC_NOPM, 3, 0,
  2844. NULL, 0, wcd938x_enable_req,
  2845. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2846. SND_SOC_DAPM_MUX("ADC2 MUX", SND_SOC_NOPM, 0, 0,
  2847. &tx_adc2_mux),
  2848. SND_SOC_DAPM_MUX("ADC3 MUX", SND_SOC_NOPM, 0, 0,
  2849. &tx_adc3_mux),
  2850. SND_SOC_DAPM_MUX("ADC4 MUX", SND_SOC_NOPM, 0, 0,
  2851. &tx_adc4_mux),
  2852. SND_SOC_DAPM_MUX("HDR12 MUX", SND_SOC_NOPM, 0, 0,
  2853. &tx_hdr12_mux),
  2854. SND_SOC_DAPM_MUX("HDR34 MUX", SND_SOC_NOPM, 0, 0,
  2855. &tx_hdr34_mux),
  2856. /*tx mixers*/
  2857. SND_SOC_DAPM_MIXER_E("ADC1_MIXER", SND_SOC_NOPM, ADC1, 0,
  2858. adc1_switch, ARRAY_SIZE(adc1_switch),
  2859. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  2860. SND_SOC_DAPM_POST_PMD),
  2861. SND_SOC_DAPM_MIXER_E("ADC2_MIXER", SND_SOC_NOPM, ADC2, 0,
  2862. adc2_switch, ARRAY_SIZE(adc2_switch),
  2863. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  2864. SND_SOC_DAPM_POST_PMD),
  2865. SND_SOC_DAPM_MIXER_E("ADC3_MIXER", SND_SOC_NOPM, ADC3, 0, adc3_switch,
  2866. ARRAY_SIZE(adc3_switch), wcd938x_tx_swr_ctrl,
  2867. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2868. SND_SOC_DAPM_MIXER_E("ADC4_MIXER", SND_SOC_NOPM, ADC4, 0, adc4_switch,
  2869. ARRAY_SIZE(adc4_switch), wcd938x_tx_swr_ctrl,
  2870. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2871. SND_SOC_DAPM_MIXER_E("DMIC1_MIXER", SND_SOC_NOPM, DMIC1,
  2872. 0, dmic1_switch, ARRAY_SIZE(dmic1_switch),
  2873. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  2874. SND_SOC_DAPM_POST_PMD),
  2875. SND_SOC_DAPM_MIXER_E("DMIC2_MIXER", SND_SOC_NOPM, DMIC2,
  2876. 0, dmic2_switch, ARRAY_SIZE(dmic2_switch),
  2877. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  2878. SND_SOC_DAPM_POST_PMD),
  2879. SND_SOC_DAPM_MIXER_E("DMIC3_MIXER", SND_SOC_NOPM, DMIC3,
  2880. 0, dmic3_switch, ARRAY_SIZE(dmic3_switch),
  2881. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  2882. SND_SOC_DAPM_POST_PMD),
  2883. SND_SOC_DAPM_MIXER_E("DMIC4_MIXER", SND_SOC_NOPM, DMIC4,
  2884. 0, dmic4_switch, ARRAY_SIZE(dmic4_switch),
  2885. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  2886. SND_SOC_DAPM_POST_PMD),
  2887. SND_SOC_DAPM_MIXER_E("DMIC5_MIXER", SND_SOC_NOPM, DMIC5,
  2888. 0, dmic5_switch, ARRAY_SIZE(dmic5_switch),
  2889. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  2890. SND_SOC_DAPM_POST_PMD),
  2891. SND_SOC_DAPM_MIXER_E("DMIC6_MIXER", SND_SOC_NOPM, DMIC6,
  2892. 0, dmic6_switch, ARRAY_SIZE(dmic6_switch),
  2893. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  2894. SND_SOC_DAPM_POST_PMD),
  2895. SND_SOC_DAPM_MIXER_E("DMIC7_MIXER", SND_SOC_NOPM, DMIC7,
  2896. 0, dmic7_switch, ARRAY_SIZE(dmic7_switch),
  2897. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  2898. SND_SOC_DAPM_POST_PMD),
  2899. SND_SOC_DAPM_MIXER_E("DMIC8_MIXER", SND_SOC_NOPM, DMIC8,
  2900. 0, dmic8_switch, ARRAY_SIZE(dmic8_switch),
  2901. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  2902. SND_SOC_DAPM_POST_PMD),
  2903. /* micbias widgets*/
  2904. SND_SOC_DAPM_SUPPLY("MIC BIAS1", SND_SOC_NOPM, 0, 0,
  2905. wcd938x_codec_enable_micbias,
  2906. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2907. SND_SOC_DAPM_POST_PMD),
  2908. SND_SOC_DAPM_SUPPLY("MIC BIAS2", SND_SOC_NOPM, 0, 0,
  2909. wcd938x_codec_enable_micbias,
  2910. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2911. SND_SOC_DAPM_POST_PMD),
  2912. SND_SOC_DAPM_SUPPLY("MIC BIAS3", SND_SOC_NOPM, 0, 0,
  2913. wcd938x_codec_enable_micbias,
  2914. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2915. SND_SOC_DAPM_POST_PMD),
  2916. SND_SOC_DAPM_SUPPLY("MIC BIAS4", SND_SOC_NOPM, 0, 0,
  2917. wcd938x_codec_enable_micbias,
  2918. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2919. SND_SOC_DAPM_POST_PMD),
  2920. SND_SOC_DAPM_SUPPLY(DAPM_MICBIAS1_STANDALONE, SND_SOC_NOPM, 0, 0,
  2921. wcd938x_codec_force_enable_micbias,
  2922. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2923. SND_SOC_DAPM_SUPPLY(DAPM_MICBIAS2_STANDALONE, SND_SOC_NOPM, 0, 0,
  2924. wcd938x_codec_force_enable_micbias,
  2925. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2926. SND_SOC_DAPM_SUPPLY(DAPM_MICBIAS3_STANDALONE, SND_SOC_NOPM, 0, 0,
  2927. wcd938x_codec_force_enable_micbias,
  2928. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2929. SND_SOC_DAPM_SUPPLY(DAPM_MICBIAS4_STANDALONE, SND_SOC_NOPM, 0, 0,
  2930. wcd938x_codec_force_enable_micbias,
  2931. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2932. SND_SOC_DAPM_SUPPLY("VDD_BUCK", SND_SOC_NOPM, 0, 0,
  2933. wcd938x_codec_enable_vdd_buck,
  2934. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2935. SND_SOC_DAPM_SUPPLY_S("CLS_H_PORT", 1, SND_SOC_NOPM, 0, 0,
  2936. wcd938x_enable_clsh,
  2937. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2938. /*rx widgets*/
  2939. SND_SOC_DAPM_PGA_E("EAR PGA", WCD938X_ANA_EAR, 7, 0, NULL, 0,
  2940. wcd938x_codec_enable_ear_pa,
  2941. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2942. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  2943. SND_SOC_DAPM_PGA_E("AUX PGA", WCD938X_AUX_AUXPA, 7, 0, NULL, 0,
  2944. wcd938x_codec_enable_aux_pa,
  2945. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2946. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  2947. SND_SOC_DAPM_PGA_E("HPHL PGA", WCD938X_ANA_HPH, 7, 0, NULL, 0,
  2948. wcd938x_codec_enable_hphl_pa,
  2949. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2950. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  2951. SND_SOC_DAPM_PGA_E("HPHR PGA", WCD938X_ANA_HPH, 6, 0, NULL, 0,
  2952. wcd938x_codec_enable_hphr_pa,
  2953. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2954. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  2955. SND_SOC_DAPM_DAC_E("RDAC1", NULL, SND_SOC_NOPM, 0, 0,
  2956. wcd938x_codec_hphl_dac_event,
  2957. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2958. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  2959. SND_SOC_DAPM_DAC_E("RDAC2", NULL, SND_SOC_NOPM, 0, 0,
  2960. wcd938x_codec_hphr_dac_event,
  2961. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2962. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  2963. SND_SOC_DAPM_DAC_E("RDAC3", NULL, SND_SOC_NOPM, 0, 0,
  2964. wcd938x_codec_ear_dac_event,
  2965. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2966. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  2967. SND_SOC_DAPM_DAC_E("RDAC4", NULL, SND_SOC_NOPM, 0, 0,
  2968. wcd938x_codec_aux_dac_event,
  2969. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2970. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  2971. SND_SOC_DAPM_MUX("RDAC3_MUX", SND_SOC_NOPM, 0, 0, &rx_rdac3_mux),
  2972. SND_SOC_DAPM_MIXER_E("RX1", SND_SOC_NOPM, 0, 0, NULL, 0,
  2973. wcd938x_enable_rx1, SND_SOC_DAPM_PRE_PMU |
  2974. SND_SOC_DAPM_POST_PMD),
  2975. SND_SOC_DAPM_MIXER_E("RX2", SND_SOC_NOPM, 0, 0, NULL, 0,
  2976. wcd938x_enable_rx2, SND_SOC_DAPM_PRE_PMU |
  2977. SND_SOC_DAPM_POST_PMD),
  2978. SND_SOC_DAPM_MIXER_E("RX3", SND_SOC_NOPM, 0, 0, NULL, 0,
  2979. wcd938x_enable_rx3, SND_SOC_DAPM_PRE_PMU |
  2980. SND_SOC_DAPM_POST_PMD),
  2981. /* rx mixer widgets*/
  2982. SND_SOC_DAPM_MIXER("EAR_RDAC", SND_SOC_NOPM, 0, 0,
  2983. ear_rdac_switch, ARRAY_SIZE(ear_rdac_switch)),
  2984. SND_SOC_DAPM_MIXER("AUX_RDAC", SND_SOC_NOPM, 0, 0,
  2985. aux_rdac_switch, ARRAY_SIZE(aux_rdac_switch)),
  2986. SND_SOC_DAPM_MIXER("HPHL_RDAC", SND_SOC_NOPM, 0, 0,
  2987. hphl_rdac_switch, ARRAY_SIZE(hphl_rdac_switch)),
  2988. SND_SOC_DAPM_MIXER("HPHR_RDAC", SND_SOC_NOPM, 0, 0,
  2989. hphr_rdac_switch, ARRAY_SIZE(hphr_rdac_switch)),
  2990. /*output widgets tx*/
  2991. SND_SOC_DAPM_OUTPUT("WCD_TX_OUTPUT"),
  2992. /*output widgets rx*/
  2993. SND_SOC_DAPM_OUTPUT("EAR"),
  2994. SND_SOC_DAPM_OUTPUT("AUX"),
  2995. SND_SOC_DAPM_OUTPUT("HPHL"),
  2996. SND_SOC_DAPM_OUTPUT("HPHR"),
  2997. /* micbias pull up widgets*/
  2998. SND_SOC_DAPM_SUPPLY("VA MIC BIAS1", SND_SOC_NOPM, 0, 0,
  2999. wcd938x_codec_enable_micbias_pullup,
  3000. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  3001. SND_SOC_DAPM_POST_PMD),
  3002. SND_SOC_DAPM_SUPPLY("VA MIC BIAS2", SND_SOC_NOPM, 0, 0,
  3003. wcd938x_codec_enable_micbias_pullup,
  3004. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  3005. SND_SOC_DAPM_POST_PMD),
  3006. SND_SOC_DAPM_SUPPLY("VA MIC BIAS3", SND_SOC_NOPM, 0, 0,
  3007. wcd938x_codec_enable_micbias_pullup,
  3008. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  3009. SND_SOC_DAPM_POST_PMD),
  3010. SND_SOC_DAPM_SUPPLY("VA MIC BIAS4", SND_SOC_NOPM, 0, 0,
  3011. wcd938x_codec_enable_micbias_pullup,
  3012. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  3013. SND_SOC_DAPM_POST_PMD),
  3014. };
  3015. static const struct snd_soc_dapm_route wcd938x_audio_map[] = {
  3016. {"WCD_TX_DUMMY", NULL, "WCD_TX_OUTPUT"},
  3017. {"WCD_TX_OUTPUT", NULL, "ADC1_MIXER"},
  3018. {"ADC1_MIXER", "Switch", "ADC1 REQ"},
  3019. {"ADC1 REQ", NULL, "ADC1"},
  3020. {"ADC1", NULL, "AMIC1"},
  3021. {"WCD_TX_OUTPUT", NULL, "ADC2_MIXER"},
  3022. {"ADC2_MIXER", "Switch", "ADC2 REQ"},
  3023. {"ADC2 REQ", NULL, "ADC2"},
  3024. {"ADC2", NULL, "HDR12 MUX"},
  3025. {"HDR12 MUX", "NO_HDR12", "ADC2 MUX"},
  3026. {"HDR12 MUX", "HDR12", "AMIC1"},
  3027. {"ADC2 MUX", "INP3", "AMIC3"},
  3028. {"ADC2 MUX", "INP2", "AMIC2"},
  3029. {"WCD_TX_OUTPUT", NULL, "ADC3_MIXER"},
  3030. {"ADC3_MIXER", "Switch", "ADC3 REQ"},
  3031. {"ADC3 REQ", NULL, "ADC3"},
  3032. {"ADC3", NULL, "HDR34 MUX"},
  3033. {"HDR34 MUX", "NO_HDR34", "ADC3 MUX"},
  3034. {"HDR34 MUX", "HDR34", "AMIC5"},
  3035. {"ADC3 MUX", "INP4", "AMIC4"},
  3036. {"ADC3 MUX", "INP6", "AMIC6"},
  3037. {"WCD_TX_OUTPUT", NULL, "ADC4_MIXER"},
  3038. {"ADC4_MIXER", "Switch", "ADC4 REQ"},
  3039. {"ADC4 REQ", NULL, "ADC4"},
  3040. {"ADC4", NULL, "ADC4 MUX"},
  3041. {"ADC4 MUX", "INP5", "AMIC5"},
  3042. {"ADC4 MUX", "INP7", "AMIC7"},
  3043. {"WCD_TX_OUTPUT", NULL, "DMIC1_MIXER"},
  3044. {"DMIC1_MIXER", "Switch", "DMIC1"},
  3045. {"WCD_TX_OUTPUT", NULL, "DMIC2_MIXER"},
  3046. {"DMIC2_MIXER", "Switch", "DMIC2"},
  3047. {"WCD_TX_OUTPUT", NULL, "DMIC3_MIXER"},
  3048. {"DMIC3_MIXER", "Switch", "DMIC3"},
  3049. {"WCD_TX_OUTPUT", NULL, "DMIC4_MIXER"},
  3050. {"DMIC4_MIXER", "Switch", "DMIC4"},
  3051. {"WCD_TX_OUTPUT", NULL, "DMIC5_MIXER"},
  3052. {"DMIC5_MIXER", "Switch", "DMIC5"},
  3053. {"WCD_TX_OUTPUT", NULL, "DMIC6_MIXER"},
  3054. {"DMIC6_MIXER", "Switch", "DMIC6"},
  3055. {"WCD_TX_OUTPUT", NULL, "DMIC7_MIXER"},
  3056. {"DMIC7_MIXER", "Switch", "DMIC7"},
  3057. {"WCD_TX_OUTPUT", NULL, "DMIC8_MIXER"},
  3058. {"DMIC8_MIXER", "Switch", "DMIC8"},
  3059. {"IN1_HPHL", NULL, "WCD_RX_DUMMY"},
  3060. {"IN1_HPHL", NULL, "VDD_BUCK"},
  3061. {"IN1_HPHL", NULL, "CLS_H_PORT"},
  3062. {"RX1", NULL, "IN1_HPHL"},
  3063. {"RDAC1", NULL, "RX1"},
  3064. {"HPHL_RDAC", "Switch", "RDAC1"},
  3065. {"HPHL PGA", NULL, "HPHL_RDAC"},
  3066. {"HPHL", NULL, "HPHL PGA"},
  3067. {"IN2_HPHR", NULL, "WCD_RX_DUMMY"},
  3068. {"IN2_HPHR", NULL, "VDD_BUCK"},
  3069. {"IN2_HPHR", NULL, "CLS_H_PORT"},
  3070. {"RX2", NULL, "IN2_HPHR"},
  3071. {"RDAC2", NULL, "RX2"},
  3072. {"HPHR_RDAC", "Switch", "RDAC2"},
  3073. {"HPHR PGA", NULL, "HPHR_RDAC"},
  3074. {"HPHR", NULL, "HPHR PGA"},
  3075. {"IN3_AUX", NULL, "WCD_RX_DUMMY"},
  3076. {"IN3_AUX", NULL, "VDD_BUCK"},
  3077. {"IN3_AUX", NULL, "CLS_H_PORT"},
  3078. {"RX3", NULL, "IN3_AUX"},
  3079. {"RDAC4", NULL, "RX3"},
  3080. {"AUX_RDAC", "Switch", "RDAC4"},
  3081. {"AUX PGA", NULL, "AUX_RDAC"},
  3082. {"AUX", NULL, "AUX PGA"},
  3083. {"RDAC3_MUX", "RX3", "RX3"},
  3084. {"RDAC3_MUX", "RX1", "RX1"},
  3085. {"RDAC3", NULL, "RDAC3_MUX"},
  3086. {"EAR_RDAC", "Switch", "RDAC3"},
  3087. {"EAR PGA", NULL, "EAR_RDAC"},
  3088. {"EAR", NULL, "EAR PGA"},
  3089. };
  3090. static ssize_t wcd938x_version_read(struct snd_info_entry *entry,
  3091. void *file_private_data,
  3092. struct file *file,
  3093. char __user *buf, size_t count,
  3094. loff_t pos)
  3095. {
  3096. struct wcd938x_priv *priv;
  3097. char buffer[WCD938X_VERSION_ENTRY_SIZE];
  3098. int len = 0;
  3099. priv = (struct wcd938x_priv *) entry->private_data;
  3100. if (!priv) {
  3101. pr_err("%s: wcd938x priv is null\n", __func__);
  3102. return -EINVAL;
  3103. }
  3104. switch (priv->version) {
  3105. case WCD938X_VERSION_1_0:
  3106. len = snprintf(buffer, sizeof(buffer), "WCD938X_1_0\n");
  3107. break;
  3108. default:
  3109. len = snprintf(buffer, sizeof(buffer), "VER_UNDEFINED\n");
  3110. }
  3111. return simple_read_from_buffer(buf, count, &pos, buffer, len);
  3112. }
  3113. static struct snd_info_entry_ops wcd938x_info_ops = {
  3114. .read = wcd938x_version_read,
  3115. };
  3116. static ssize_t wcd938x_variant_read(struct snd_info_entry *entry,
  3117. void *file_private_data,
  3118. struct file *file,
  3119. char __user *buf, size_t count,
  3120. loff_t pos)
  3121. {
  3122. struct wcd938x_priv *priv;
  3123. char buffer[WCD938X_VARIANT_ENTRY_SIZE];
  3124. int len = 0;
  3125. priv = (struct wcd938x_priv *) entry->private_data;
  3126. if (!priv) {
  3127. pr_err("%s: wcd938x priv is null\n", __func__);
  3128. return -EINVAL;
  3129. }
  3130. switch (priv->variant) {
  3131. case WCD9380:
  3132. len = snprintf(buffer, sizeof(buffer), "WCD9380\n");
  3133. break;
  3134. case WCD9385:
  3135. len = snprintf(buffer, sizeof(buffer), "WCD9385\n");
  3136. break;
  3137. default:
  3138. len = snprintf(buffer, sizeof(buffer), "VER_UNDEFINED\n");
  3139. }
  3140. return simple_read_from_buffer(buf, count, &pos, buffer, len);
  3141. }
  3142. static struct snd_info_entry_ops wcd938x_variant_ops = {
  3143. .read = wcd938x_variant_read,
  3144. };
  3145. /*
  3146. * wcd938x_get_codec_variant
  3147. * @component: component instance
  3148. *
  3149. * Return: codec variant or -EINVAL in error.
  3150. */
  3151. int wcd938x_get_codec_variant(struct snd_soc_component *component)
  3152. {
  3153. struct wcd938x_priv *priv = NULL;
  3154. if (!component)
  3155. return -EINVAL;
  3156. priv = snd_soc_component_get_drvdata(component);
  3157. if (!priv) {
  3158. dev_err(component->dev,
  3159. "%s:wcd938x not probed\n", __func__);
  3160. return 0;
  3161. }
  3162. return priv->variant;
  3163. }
  3164. EXPORT_SYMBOL(wcd938x_get_codec_variant);
  3165. /*
  3166. * wcd938x_info_create_codec_entry - creates wcd938x module
  3167. * @codec_root: The parent directory
  3168. * @component: component instance
  3169. *
  3170. * Creates wcd938x module, variant and version entry under the given
  3171. * parent directory.
  3172. *
  3173. * Return: 0 on success or negative error code on failure.
  3174. */
  3175. int wcd938x_info_create_codec_entry(struct snd_info_entry *codec_root,
  3176. struct snd_soc_component *component)
  3177. {
  3178. struct snd_info_entry *version_entry;
  3179. struct snd_info_entry *variant_entry;
  3180. struct wcd938x_priv *priv;
  3181. struct snd_soc_card *card;
  3182. if (!codec_root || !component)
  3183. return -EINVAL;
  3184. priv = snd_soc_component_get_drvdata(component);
  3185. if (priv->entry) {
  3186. dev_dbg(priv->dev,
  3187. "%s:wcd938x module already created\n", __func__);
  3188. return 0;
  3189. }
  3190. card = component->card;
  3191. priv->entry = snd_info_create_module_entry(codec_root->module,
  3192. "wcd938x", codec_root);
  3193. if (!priv->entry) {
  3194. dev_dbg(component->dev, "%s: failed to create wcd938x entry\n",
  3195. __func__);
  3196. return -ENOMEM;
  3197. }
  3198. priv->entry->mode = S_IFDIR | 0555;
  3199. if (snd_info_register(priv->entry) < 0) {
  3200. snd_info_free_entry(priv->entry);
  3201. return -ENOMEM;
  3202. }
  3203. version_entry = snd_info_create_card_entry(card->snd_card,
  3204. "version",
  3205. priv->entry);
  3206. if (!version_entry) {
  3207. dev_dbg(component->dev, "%s: failed to create wcd938x version entry\n",
  3208. __func__);
  3209. snd_info_free_entry(priv->entry);
  3210. return -ENOMEM;
  3211. }
  3212. version_entry->private_data = priv;
  3213. version_entry->size = WCD938X_VERSION_ENTRY_SIZE;
  3214. version_entry->content = SNDRV_INFO_CONTENT_DATA;
  3215. version_entry->c.ops = &wcd938x_info_ops;
  3216. if (snd_info_register(version_entry) < 0) {
  3217. snd_info_free_entry(version_entry);
  3218. snd_info_free_entry(priv->entry);
  3219. return -ENOMEM;
  3220. }
  3221. priv->version_entry = version_entry;
  3222. variant_entry = snd_info_create_card_entry(card->snd_card,
  3223. "variant",
  3224. priv->entry);
  3225. if (!variant_entry) {
  3226. dev_dbg(component->dev, "%s: failed to create wcd938x variant entry\n",
  3227. __func__);
  3228. snd_info_free_entry(version_entry);
  3229. snd_info_free_entry(priv->entry);
  3230. return -ENOMEM;
  3231. }
  3232. variant_entry->private_data = priv;
  3233. variant_entry->size = WCD938X_VARIANT_ENTRY_SIZE;
  3234. variant_entry->content = SNDRV_INFO_CONTENT_DATA;
  3235. variant_entry->c.ops = &wcd938x_variant_ops;
  3236. if (snd_info_register(variant_entry) < 0) {
  3237. snd_info_free_entry(variant_entry);
  3238. snd_info_free_entry(version_entry);
  3239. snd_info_free_entry(priv->entry);
  3240. return -ENOMEM;
  3241. }
  3242. priv->variant_entry = variant_entry;
  3243. return 0;
  3244. }
  3245. EXPORT_SYMBOL(wcd938x_info_create_codec_entry);
  3246. static int wcd938x_set_micbias_data(struct wcd938x_priv *wcd938x,
  3247. struct wcd938x_pdata *pdata)
  3248. {
  3249. int vout_ctl_1 = 0, vout_ctl_2 = 0, vout_ctl_3 = 0, vout_ctl_4 = 0;
  3250. int rc = 0;
  3251. if (!pdata) {
  3252. dev_err(wcd938x->dev, "%s: NULL pdata\n", __func__);
  3253. return -ENODEV;
  3254. }
  3255. /* set micbias voltage */
  3256. vout_ctl_1 = wcd938x_get_micb_vout_ctl_val(pdata->micbias.micb1_mv);
  3257. vout_ctl_2 = wcd938x_get_micb_vout_ctl_val(pdata->micbias.micb2_mv);
  3258. vout_ctl_3 = wcd938x_get_micb_vout_ctl_val(pdata->micbias.micb3_mv);
  3259. vout_ctl_4 = wcd938x_get_micb_vout_ctl_val(pdata->micbias.micb4_mv);
  3260. if (vout_ctl_1 < 0 || vout_ctl_2 < 0 || vout_ctl_3 < 0 ||
  3261. vout_ctl_4 < 0) {
  3262. rc = -EINVAL;
  3263. goto done;
  3264. }
  3265. regmap_update_bits(wcd938x->regmap, WCD938X_ANA_MICB1, 0x3F,
  3266. vout_ctl_1);
  3267. regmap_update_bits(wcd938x->regmap, WCD938X_ANA_MICB2, 0x3F,
  3268. vout_ctl_2);
  3269. regmap_update_bits(wcd938x->regmap, WCD938X_ANA_MICB3, 0x3F,
  3270. vout_ctl_3);
  3271. regmap_update_bits(wcd938x->regmap, WCD938X_ANA_MICB4, 0x3F,
  3272. vout_ctl_4);
  3273. done:
  3274. return rc;
  3275. }
  3276. static int wcd938x_soc_codec_probe(struct snd_soc_component *component)
  3277. {
  3278. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  3279. struct snd_soc_dapm_context *dapm =
  3280. snd_soc_component_get_dapm(component);
  3281. int variant;
  3282. int ret = -EINVAL;
  3283. dev_info(component->dev, "%s()\n", __func__);
  3284. wcd938x = snd_soc_component_get_drvdata(component);
  3285. if (!wcd938x)
  3286. return -EINVAL;
  3287. wcd938x->component = component;
  3288. snd_soc_component_init_regmap(component, wcd938x->regmap);
  3289. variant = (snd_soc_component_read32(component,
  3290. WCD938X_DIGITAL_EFUSE_REG_0) & 0x1E) >> 1;
  3291. wcd938x->variant = variant;
  3292. wcd938x->fw_data = devm_kzalloc(component->dev,
  3293. sizeof(*(wcd938x->fw_data)),
  3294. GFP_KERNEL);
  3295. if (!wcd938x->fw_data) {
  3296. dev_err(component->dev, "Failed to allocate fw_data\n");
  3297. ret = -ENOMEM;
  3298. goto err;
  3299. }
  3300. set_bit(WCD9XXX_MBHC_CAL, wcd938x->fw_data->cal_bit);
  3301. ret = wcd_cal_create_hwdep(wcd938x->fw_data,
  3302. WCD9XXX_CODEC_HWDEP_NODE, component);
  3303. if (ret < 0) {
  3304. dev_err(component->dev, "%s hwdep failed %d\n", __func__, ret);
  3305. goto err_hwdep;
  3306. }
  3307. ret = wcd938x_mbhc_init(&wcd938x->mbhc, component, wcd938x->fw_data);
  3308. if (ret) {
  3309. pr_err("%s: mbhc initialization failed\n", __func__);
  3310. goto err_hwdep;
  3311. }
  3312. snd_soc_dapm_ignore_suspend(dapm, "WCD938X_AIF Playback");
  3313. snd_soc_dapm_ignore_suspend(dapm, "WCD938X_AIF Capture");
  3314. snd_soc_dapm_ignore_suspend(dapm, "AMIC1");
  3315. snd_soc_dapm_ignore_suspend(dapm, "AMIC2");
  3316. snd_soc_dapm_ignore_suspend(dapm, "AMIC3");
  3317. snd_soc_dapm_ignore_suspend(dapm, "AMIC4");
  3318. snd_soc_dapm_ignore_suspend(dapm, "AMIC5");
  3319. snd_soc_dapm_ignore_suspend(dapm, "AMIC6");
  3320. snd_soc_dapm_ignore_suspend(dapm, "AMIC7");
  3321. snd_soc_dapm_ignore_suspend(dapm, "WCD_TX_OUTPUT");
  3322. snd_soc_dapm_ignore_suspend(dapm, "IN1_HPHL");
  3323. snd_soc_dapm_ignore_suspend(dapm, "IN2_HPHR");
  3324. snd_soc_dapm_ignore_suspend(dapm, "IN3_AUX");
  3325. snd_soc_dapm_ignore_suspend(dapm, "EAR");
  3326. snd_soc_dapm_ignore_suspend(dapm, "AUX");
  3327. snd_soc_dapm_ignore_suspend(dapm, "HPHL");
  3328. snd_soc_dapm_ignore_suspend(dapm, "HPHR");
  3329. snd_soc_dapm_ignore_suspend(dapm, "WCD_TX_DUMMY");
  3330. snd_soc_dapm_ignore_suspend(dapm, "WCD_RX_DUMMY");
  3331. snd_soc_dapm_sync(dapm);
  3332. wcd_cls_h_init(&wcd938x->clsh_info);
  3333. wcd938x_init_reg(component);
  3334. if (wcd938x->variant == WCD9380) {
  3335. ret = snd_soc_add_component_controls(component, wcd9380_snd_controls,
  3336. ARRAY_SIZE(wcd9380_snd_controls));
  3337. if (ret < 0) {
  3338. dev_err(component->dev,
  3339. "%s: Failed to add snd ctrls for variant: %d\n",
  3340. __func__, wcd938x->variant);
  3341. goto err_hwdep;
  3342. }
  3343. }
  3344. if (wcd938x->variant == WCD9385) {
  3345. ret = snd_soc_add_component_controls(component, wcd9385_snd_controls,
  3346. ARRAY_SIZE(wcd9385_snd_controls));
  3347. if (ret < 0) {
  3348. dev_err(component->dev,
  3349. "%s: Failed to add snd ctrls for variant: %d\n",
  3350. __func__, wcd938x->variant);
  3351. goto err_hwdep;
  3352. }
  3353. }
  3354. wcd938x->version = WCD938X_VERSION_1_0;
  3355. /* Register event notifier */
  3356. wcd938x->nblock.notifier_call = wcd938x_event_notify;
  3357. if (wcd938x->register_notifier) {
  3358. ret = wcd938x->register_notifier(wcd938x->handle,
  3359. &wcd938x->nblock,
  3360. true);
  3361. if (ret) {
  3362. dev_err(component->dev,
  3363. "%s: Failed to register notifier %d\n",
  3364. __func__, ret);
  3365. return ret;
  3366. }
  3367. }
  3368. return ret;
  3369. err_hwdep:
  3370. wcd938x->fw_data = NULL;
  3371. err:
  3372. return ret;
  3373. }
  3374. static void wcd938x_soc_codec_remove(struct snd_soc_component *component)
  3375. {
  3376. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  3377. if (!wcd938x) {
  3378. dev_err(component->dev, "%s: wcd938x is already NULL\n",
  3379. __func__);
  3380. return;
  3381. }
  3382. if (wcd938x->register_notifier)
  3383. wcd938x->register_notifier(wcd938x->handle,
  3384. &wcd938x->nblock,
  3385. false);
  3386. }
  3387. static int wcd938x_soc_codec_suspend(struct snd_soc_component *component)
  3388. {
  3389. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  3390. if (!wcd938x)
  3391. return 0;
  3392. wcd938x->dapm_bias_off = true;
  3393. return 0;
  3394. }
  3395. static int wcd938x_soc_codec_resume(struct snd_soc_component *component)
  3396. {
  3397. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  3398. if (!wcd938x)
  3399. return 0;
  3400. wcd938x->dapm_bias_off = false;
  3401. return 0;
  3402. }
  3403. static struct snd_soc_component_driver soc_codec_dev_wcd938x = {
  3404. .name = WCD938X_DRV_NAME,
  3405. .probe = wcd938x_soc_codec_probe,
  3406. .remove = wcd938x_soc_codec_remove,
  3407. .controls = wcd938x_snd_controls,
  3408. .num_controls = ARRAY_SIZE(wcd938x_snd_controls),
  3409. .dapm_widgets = wcd938x_dapm_widgets,
  3410. .num_dapm_widgets = ARRAY_SIZE(wcd938x_dapm_widgets),
  3411. .dapm_routes = wcd938x_audio_map,
  3412. .num_dapm_routes = ARRAY_SIZE(wcd938x_audio_map),
  3413. .suspend = wcd938x_soc_codec_suspend,
  3414. .resume = wcd938x_soc_codec_resume,
  3415. };
  3416. static int wcd938x_reset(struct device *dev)
  3417. {
  3418. struct wcd938x_priv *wcd938x = NULL;
  3419. int rc = 0;
  3420. int value = 0;
  3421. if (!dev)
  3422. return -ENODEV;
  3423. wcd938x = dev_get_drvdata(dev);
  3424. if (!wcd938x)
  3425. return -EINVAL;
  3426. if (!wcd938x->rst_np) {
  3427. dev_err(dev, "%s: reset gpio device node not specified\n",
  3428. __func__);
  3429. return -EINVAL;
  3430. }
  3431. value = msm_cdc_pinctrl_get_state(wcd938x->rst_np);
  3432. if (value > 0)
  3433. return 0;
  3434. rc = msm_cdc_pinctrl_select_sleep_state(wcd938x->rst_np);
  3435. if (rc) {
  3436. dev_err(dev, "%s: wcd sleep state request fail!\n",
  3437. __func__);
  3438. return rc;
  3439. }
  3440. /* 20us sleep required after pulling the reset gpio to LOW */
  3441. usleep_range(20, 30);
  3442. rc = msm_cdc_pinctrl_select_active_state(wcd938x->rst_np);
  3443. if (rc) {
  3444. dev_err(dev, "%s: wcd active state request fail!\n",
  3445. __func__);
  3446. return rc;
  3447. }
  3448. /* 20us sleep required after pulling the reset gpio to HIGH */
  3449. usleep_range(20, 30);
  3450. return rc;
  3451. }
  3452. static int wcd938x_read_of_property_u32(struct device *dev, const char *name,
  3453. u32 *val)
  3454. {
  3455. int rc = 0;
  3456. rc = of_property_read_u32(dev->of_node, name, val);
  3457. if (rc)
  3458. dev_err(dev, "%s: Looking up %s property in node %s failed\n",
  3459. __func__, name, dev->of_node->full_name);
  3460. return rc;
  3461. }
  3462. static void wcd938x_dt_parse_micbias_info(struct device *dev,
  3463. struct wcd938x_micbias_setting *mb)
  3464. {
  3465. u32 prop_val = 0;
  3466. int rc = 0;
  3467. /* MB1 */
  3468. if (of_find_property(dev->of_node, "qcom,cdc-micbias1-mv",
  3469. NULL)) {
  3470. rc = wcd938x_read_of_property_u32(dev,
  3471. "qcom,cdc-micbias1-mv",
  3472. &prop_val);
  3473. if (!rc)
  3474. mb->micb1_mv = prop_val;
  3475. } else {
  3476. dev_info(dev, "%s: Micbias1 DT property not found\n",
  3477. __func__);
  3478. }
  3479. /* MB2 */
  3480. if (of_find_property(dev->of_node, "qcom,cdc-micbias2-mv",
  3481. NULL)) {
  3482. rc = wcd938x_read_of_property_u32(dev,
  3483. "qcom,cdc-micbias2-mv",
  3484. &prop_val);
  3485. if (!rc)
  3486. mb->micb2_mv = prop_val;
  3487. } else {
  3488. dev_info(dev, "%s: Micbias2 DT property not found\n",
  3489. __func__);
  3490. }
  3491. /* MB3 */
  3492. if (of_find_property(dev->of_node, "qcom,cdc-micbias3-mv",
  3493. NULL)) {
  3494. rc = wcd938x_read_of_property_u32(dev,
  3495. "qcom,cdc-micbias3-mv",
  3496. &prop_val);
  3497. if (!rc)
  3498. mb->micb3_mv = prop_val;
  3499. } else {
  3500. dev_info(dev, "%s: Micbias3 DT property not found\n",
  3501. __func__);
  3502. }
  3503. /* MB4 */
  3504. if (of_find_property(dev->of_node, "qcom,cdc-micbias4-mv",
  3505. NULL)) {
  3506. rc = wcd938x_read_of_property_u32(dev,
  3507. "qcom,cdc-micbias4-mv",
  3508. &prop_val);
  3509. if (!rc)
  3510. mb->micb4_mv = prop_val;
  3511. } else {
  3512. dev_info(dev, "%s: Micbias4 DT property not found\n",
  3513. __func__);
  3514. }
  3515. }
  3516. static int wcd938x_reset_low(struct device *dev)
  3517. {
  3518. struct wcd938x_priv *wcd938x = NULL;
  3519. int rc = 0;
  3520. if (!dev)
  3521. return -ENODEV;
  3522. wcd938x = dev_get_drvdata(dev);
  3523. if (!wcd938x)
  3524. return -EINVAL;
  3525. if (!wcd938x->rst_np) {
  3526. dev_err(dev, "%s: reset gpio device node not specified\n",
  3527. __func__);
  3528. return -EINVAL;
  3529. }
  3530. rc = msm_cdc_pinctrl_select_sleep_state(wcd938x->rst_np);
  3531. if (rc) {
  3532. dev_err(dev, "%s: wcd sleep state request fail!\n",
  3533. __func__);
  3534. return rc;
  3535. }
  3536. /* 20us sleep required after pulling the reset gpio to LOW */
  3537. usleep_range(20, 30);
  3538. return rc;
  3539. }
  3540. struct wcd938x_pdata *wcd938x_populate_dt_data(struct device *dev)
  3541. {
  3542. struct wcd938x_pdata *pdata = NULL;
  3543. pdata = devm_kzalloc(dev, sizeof(struct wcd938x_pdata),
  3544. GFP_KERNEL);
  3545. if (!pdata)
  3546. return NULL;
  3547. pdata->rst_np = of_parse_phandle(dev->of_node,
  3548. "qcom,wcd-rst-gpio-node", 0);
  3549. if (!pdata->rst_np) {
  3550. dev_err(dev, "%s: Looking up %s property in node %s failed\n",
  3551. __func__, "qcom,wcd-rst-gpio-node",
  3552. dev->of_node->full_name);
  3553. return NULL;
  3554. }
  3555. /* Parse power supplies */
  3556. msm_cdc_get_power_supplies(dev, &pdata->regulator,
  3557. &pdata->num_supplies);
  3558. if (!pdata->regulator || (pdata->num_supplies <= 0)) {
  3559. dev_err(dev, "%s: no power supplies defined for codec\n",
  3560. __func__);
  3561. return NULL;
  3562. }
  3563. pdata->rx_slave = of_parse_phandle(dev->of_node, "qcom,rx-slave", 0);
  3564. pdata->tx_slave = of_parse_phandle(dev->of_node, "qcom,tx-slave", 0);
  3565. wcd938x_dt_parse_micbias_info(dev, &pdata->micbias);
  3566. return pdata;
  3567. }
  3568. static irqreturn_t wcd938x_wd_handle_irq(int irq, void *data)
  3569. {
  3570. pr_err_ratelimited("%s: Watchdog interrupt for irq =%d triggered\n",
  3571. __func__, irq);
  3572. return IRQ_HANDLED;
  3573. }
  3574. static struct snd_soc_dai_driver wcd938x_dai[] = {
  3575. {
  3576. .name = "wcd938x_cdc",
  3577. .playback = {
  3578. .stream_name = "WCD938X_AIF Playback",
  3579. .rates = WCD938X_RATES | WCD938X_FRAC_RATES,
  3580. .formats = WCD938X_FORMATS,
  3581. .rate_max = 192000,
  3582. .rate_min = 8000,
  3583. .channels_min = 1,
  3584. .channels_max = 4,
  3585. },
  3586. .capture = {
  3587. .stream_name = "WCD938X_AIF Capture",
  3588. .rates = WCD938X_RATES | WCD938X_FRAC_RATES,
  3589. .formats = WCD938X_FORMATS,
  3590. .rate_max = 192000,
  3591. .rate_min = 8000,
  3592. .channels_min = 1,
  3593. .channels_max = 4,
  3594. },
  3595. },
  3596. };
  3597. static int wcd938x_bind(struct device *dev)
  3598. {
  3599. int ret = 0, i = 0;
  3600. struct wcd938x_pdata *pdata = dev_get_platdata(dev);
  3601. struct wcd938x_priv *wcd938x = dev_get_drvdata(dev);
  3602. /*
  3603. * Add 5msec delay to provide sufficient time for
  3604. * soundwire auto enumeration of slave devices as
  3605. * as per HW requirement.
  3606. */
  3607. usleep_range(5000, 5010);
  3608. ret = component_bind_all(dev, wcd938x);
  3609. if (ret) {
  3610. dev_err(dev, "%s: Slave bind failed, ret = %d\n",
  3611. __func__, ret);
  3612. return ret;
  3613. }
  3614. wcd938x->rx_swr_dev = get_matching_swr_slave_device(pdata->rx_slave);
  3615. if (!wcd938x->rx_swr_dev) {
  3616. dev_err(dev, "%s: Could not find RX swr slave device\n",
  3617. __func__);
  3618. ret = -ENODEV;
  3619. goto err;
  3620. }
  3621. wcd938x->tx_swr_dev = get_matching_swr_slave_device(pdata->tx_slave);
  3622. if (!wcd938x->tx_swr_dev) {
  3623. dev_err(dev, "%s: Could not find TX swr slave device\n",
  3624. __func__);
  3625. ret = -ENODEV;
  3626. goto err;
  3627. }
  3628. wcd938x->regmap = devm_regmap_init_swr(wcd938x->tx_swr_dev,
  3629. &wcd938x_regmap_config);
  3630. if (!wcd938x->regmap) {
  3631. dev_err(dev, "%s: Regmap init failed\n",
  3632. __func__);
  3633. goto err;
  3634. }
  3635. /* Set all interupts as edge triggered */
  3636. for (i = 0; i < wcd938x_regmap_irq_chip.num_regs; i++)
  3637. regmap_write(wcd938x->regmap,
  3638. (WCD938X_DIGITAL_INTR_LEVEL_0 + i), 0);
  3639. wcd938x_regmap_irq_chip.irq_drv_data = wcd938x;
  3640. wcd938x->irq_info.wcd_regmap_irq_chip = &wcd938x_regmap_irq_chip;
  3641. wcd938x->irq_info.codec_name = "WCD938X";
  3642. wcd938x->irq_info.regmap = wcd938x->regmap;
  3643. wcd938x->irq_info.dev = dev;
  3644. ret = wcd_irq_init(&wcd938x->irq_info, &wcd938x->virq);
  3645. if (ret) {
  3646. dev_err(wcd938x->dev, "%s: IRQ init failed: %d\n",
  3647. __func__, ret);
  3648. goto err;
  3649. }
  3650. wcd938x->tx_swr_dev->slave_irq = wcd938x->virq;
  3651. ret = wcd938x_set_micbias_data(wcd938x, pdata);
  3652. if (ret < 0) {
  3653. dev_err(dev, "%s: bad micbias pdata\n", __func__);
  3654. goto err_irq;
  3655. }
  3656. /* Request for watchdog interrupt */
  3657. wcd_request_irq(&wcd938x->irq_info, WCD938X_IRQ_HPHR_PDM_WD_INT,
  3658. "HPHR PDM WD INT", wcd938x_wd_handle_irq, NULL);
  3659. wcd_request_irq(&wcd938x->irq_info, WCD938X_IRQ_HPHL_PDM_WD_INT,
  3660. "HPHL PDM WD INT", wcd938x_wd_handle_irq, NULL);
  3661. wcd_request_irq(&wcd938x->irq_info, WCD938X_IRQ_AUX_PDM_WD_INT,
  3662. "AUX PDM WD INT", wcd938x_wd_handle_irq, NULL);
  3663. /* Disable watchdog interrupt for HPH and AUX */
  3664. wcd_disable_irq(&wcd938x->irq_info, WCD938X_IRQ_HPHR_PDM_WD_INT);
  3665. wcd_disable_irq(&wcd938x->irq_info, WCD938X_IRQ_HPHL_PDM_WD_INT);
  3666. wcd_disable_irq(&wcd938x->irq_info, WCD938X_IRQ_AUX_PDM_WD_INT);
  3667. ret = snd_soc_register_component(dev, &soc_codec_dev_wcd938x,
  3668. wcd938x_dai, ARRAY_SIZE(wcd938x_dai));
  3669. if (ret) {
  3670. dev_err(dev, "%s: Codec registration failed\n",
  3671. __func__);
  3672. goto err_irq;
  3673. }
  3674. wcd938x->dev_up = true;
  3675. return ret;
  3676. err_irq:
  3677. wcd_irq_exit(&wcd938x->irq_info, wcd938x->virq);
  3678. err:
  3679. component_unbind_all(dev, wcd938x);
  3680. return ret;
  3681. }
  3682. static void wcd938x_unbind(struct device *dev)
  3683. {
  3684. struct wcd938x_priv *wcd938x = dev_get_drvdata(dev);
  3685. wcd_free_irq(&wcd938x->irq_info, WCD938X_IRQ_HPHR_PDM_WD_INT, NULL);
  3686. wcd_free_irq(&wcd938x->irq_info, WCD938X_IRQ_HPHL_PDM_WD_INT, NULL);
  3687. wcd_free_irq(&wcd938x->irq_info, WCD938X_IRQ_AUX_PDM_WD_INT, NULL);
  3688. wcd_irq_exit(&wcd938x->irq_info, wcd938x->virq);
  3689. snd_soc_unregister_component(dev);
  3690. component_unbind_all(dev, wcd938x);
  3691. }
  3692. static const struct of_device_id wcd938x_dt_match[] = {
  3693. { .compatible = "qcom,wcd938x-codec", .data = "wcd938x"},
  3694. {}
  3695. };
  3696. static const struct component_master_ops wcd938x_comp_ops = {
  3697. .bind = wcd938x_bind,
  3698. .unbind = wcd938x_unbind,
  3699. };
  3700. static int wcd938x_compare_of(struct device *dev, void *data)
  3701. {
  3702. return dev->of_node == data;
  3703. }
  3704. static void wcd938x_release_of(struct device *dev, void *data)
  3705. {
  3706. of_node_put(data);
  3707. }
  3708. static int wcd938x_add_slave_components(struct device *dev,
  3709. struct component_match **matchptr)
  3710. {
  3711. struct device_node *np, *rx_node, *tx_node;
  3712. np = dev->of_node;
  3713. rx_node = of_parse_phandle(np, "qcom,rx-slave", 0);
  3714. if (!rx_node) {
  3715. dev_err(dev, "%s: Rx-slave node not defined\n", __func__);
  3716. return -ENODEV;
  3717. }
  3718. of_node_get(rx_node);
  3719. component_match_add_release(dev, matchptr,
  3720. wcd938x_release_of,
  3721. wcd938x_compare_of,
  3722. rx_node);
  3723. tx_node = of_parse_phandle(np, "qcom,tx-slave", 0);
  3724. if (!tx_node) {
  3725. dev_err(dev, "%s: Tx-slave node not defined\n", __func__);
  3726. return -ENODEV;
  3727. }
  3728. of_node_get(tx_node);
  3729. component_match_add_release(dev, matchptr,
  3730. wcd938x_release_of,
  3731. wcd938x_compare_of,
  3732. tx_node);
  3733. return 0;
  3734. }
  3735. static int wcd938x_probe(struct platform_device *pdev)
  3736. {
  3737. struct component_match *match = NULL;
  3738. struct wcd938x_priv *wcd938x = NULL;
  3739. struct wcd938x_pdata *pdata = NULL;
  3740. struct wcd_ctrl_platform_data *plat_data = NULL;
  3741. struct device *dev = &pdev->dev;
  3742. int ret;
  3743. wcd938x = devm_kzalloc(dev, sizeof(struct wcd938x_priv),
  3744. GFP_KERNEL);
  3745. if (!wcd938x)
  3746. return -ENOMEM;
  3747. dev_set_drvdata(dev, wcd938x);
  3748. wcd938x->dev = dev;
  3749. pdata = wcd938x_populate_dt_data(dev);
  3750. if (!pdata) {
  3751. dev_err(dev, "%s: Fail to obtain platform data\n", __func__);
  3752. return -EINVAL;
  3753. }
  3754. dev->platform_data = pdata;
  3755. wcd938x->rst_np = pdata->rst_np;
  3756. ret = msm_cdc_init_supplies(dev, &wcd938x->supplies,
  3757. pdata->regulator, pdata->num_supplies);
  3758. if (!wcd938x->supplies) {
  3759. dev_err(dev, "%s: Cannot init wcd supplies\n",
  3760. __func__);
  3761. return ret;
  3762. }
  3763. plat_data = dev_get_platdata(dev->parent);
  3764. if (!plat_data) {
  3765. dev_err(dev, "%s: platform data from parent is NULL\n",
  3766. __func__);
  3767. return -EINVAL;
  3768. }
  3769. wcd938x->handle = (void *)plat_data->handle;
  3770. if (!wcd938x->handle) {
  3771. dev_err(dev, "%s: handle is NULL\n", __func__);
  3772. return -EINVAL;
  3773. }
  3774. wcd938x->update_wcd_event = plat_data->update_wcd_event;
  3775. if (!wcd938x->update_wcd_event) {
  3776. dev_err(dev, "%s: update_wcd_event api is null!\n",
  3777. __func__);
  3778. return -EINVAL;
  3779. }
  3780. wcd938x->register_notifier = plat_data->register_notifier;
  3781. if (!wcd938x->register_notifier) {
  3782. dev_err(dev, "%s: register_notifier api is null!\n",
  3783. __func__);
  3784. return -EINVAL;
  3785. }
  3786. ret = msm_cdc_enable_static_supplies(&pdev->dev, wcd938x->supplies,
  3787. pdata->regulator,
  3788. pdata->num_supplies);
  3789. if (ret) {
  3790. dev_err(dev, "%s: wcd static supply enable failed!\n",
  3791. __func__);
  3792. return ret;
  3793. }
  3794. ret = wcd938x_parse_port_mapping(dev, "qcom,rx_swr_ch_map",
  3795. CODEC_RX);
  3796. ret |= wcd938x_parse_port_mapping(dev, "qcom,tx_swr_ch_map",
  3797. CODEC_TX);
  3798. if (ret) {
  3799. dev_err(dev, "Failed to read port mapping\n");
  3800. goto err;
  3801. }
  3802. mutex_init(&wcd938x->wakeup_lock);
  3803. mutex_init(&wcd938x->micb_lock);
  3804. ret = wcd938x_add_slave_components(dev, &match);
  3805. if (ret)
  3806. goto err_lock_init;
  3807. wcd938x_reset(dev);
  3808. wcd938x->wakeup = wcd938x_wakeup;
  3809. return component_master_add_with_match(dev,
  3810. &wcd938x_comp_ops, match);
  3811. err_lock_init:
  3812. mutex_destroy(&wcd938x->micb_lock);
  3813. mutex_destroy(&wcd938x->wakeup_lock);
  3814. err:
  3815. return ret;
  3816. }
  3817. static int wcd938x_remove(struct platform_device *pdev)
  3818. {
  3819. struct wcd938x_priv *wcd938x = NULL;
  3820. wcd938x = platform_get_drvdata(pdev);
  3821. component_master_del(&pdev->dev, &wcd938x_comp_ops);
  3822. mutex_destroy(&wcd938x->micb_lock);
  3823. mutex_destroy(&wcd938x->wakeup_lock);
  3824. dev_set_drvdata(&pdev->dev, NULL);
  3825. return 0;
  3826. }
  3827. #ifdef CONFIG_PM_SLEEP
  3828. static int wcd938x_suspend(struct device *dev)
  3829. {
  3830. struct wcd938x_priv *wcd938x = NULL;
  3831. int ret = 0;
  3832. struct wcd938x_pdata *pdata = NULL;
  3833. if (!dev)
  3834. return -ENODEV;
  3835. wcd938x = dev_get_drvdata(dev);
  3836. if (!wcd938x)
  3837. return -EINVAL;
  3838. pdata = dev_get_platdata(wcd938x->dev);
  3839. if (!pdata) {
  3840. dev_err(dev, "%s: pdata is NULL\n", __func__);
  3841. return -EINVAL;
  3842. }
  3843. if (test_bit(ALLOW_BUCK_DISABLE, &wcd938x->status_mask)) {
  3844. ret = msm_cdc_disable_ondemand_supply(wcd938x->dev,
  3845. wcd938x->supplies,
  3846. pdata->regulator,
  3847. pdata->num_supplies,
  3848. "cdc-vdd-buck");
  3849. if (ret == -EINVAL) {
  3850. dev_err(dev, "%s: vdd buck is not disabled\n",
  3851. __func__);
  3852. return 0;
  3853. }
  3854. clear_bit(ALLOW_BUCK_DISABLE, &wcd938x->status_mask);
  3855. }
  3856. if (wcd938x->dapm_bias_off) {
  3857. msm_cdc_set_supplies_lpm_mode(wcd938x->dev,
  3858. wcd938x->supplies,
  3859. pdata->regulator,
  3860. pdata->num_supplies,
  3861. true);
  3862. set_bit(WCD_SUPPLIES_LPM_MODE, &wcd938x->status_mask);
  3863. }
  3864. return 0;
  3865. }
  3866. static int wcd938x_resume(struct device *dev)
  3867. {
  3868. struct wcd938x_priv *wcd938x = NULL;
  3869. struct wcd938x_pdata *pdata = NULL;
  3870. if (!dev)
  3871. return -ENODEV;
  3872. wcd938x = dev_get_drvdata(dev);
  3873. if (!wcd938x)
  3874. return -EINVAL;
  3875. pdata = dev_get_platdata(wcd938x->dev);
  3876. if (!pdata) {
  3877. dev_err(dev, "%s: pdata is NULL\n", __func__);
  3878. return -EINVAL;
  3879. }
  3880. if (test_bit(WCD_SUPPLIES_LPM_MODE, &wcd938x->status_mask)) {
  3881. msm_cdc_set_supplies_lpm_mode(wcd938x->dev,
  3882. wcd938x->supplies,
  3883. pdata->regulator,
  3884. pdata->num_supplies,
  3885. false);
  3886. clear_bit(WCD_SUPPLIES_LPM_MODE, &wcd938x->status_mask);
  3887. }
  3888. return 0;
  3889. }
  3890. static const struct dev_pm_ops wcd938x_dev_pm_ops = {
  3891. .suspend_late = wcd938x_suspend,
  3892. .resume_early = wcd938x_resume,
  3893. };
  3894. #endif
  3895. static struct platform_driver wcd938x_codec_driver = {
  3896. .probe = wcd938x_probe,
  3897. .remove = wcd938x_remove,
  3898. .driver = {
  3899. .name = "wcd938x_codec",
  3900. .owner = THIS_MODULE,
  3901. .of_match_table = of_match_ptr(wcd938x_dt_match),
  3902. #ifdef CONFIG_PM_SLEEP
  3903. .pm = &wcd938x_dev_pm_ops,
  3904. #endif
  3905. .suppress_bind_attrs = true,
  3906. },
  3907. };
  3908. module_platform_driver(wcd938x_codec_driver);
  3909. MODULE_DESCRIPTION("WCD938X Codec driver");
  3910. MODULE_LICENSE("GPL v2");