wcd938x.c 124 KB

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