wcd938x.c 97 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2018-2019, 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 "internal.h"
  23. #include "wcd938x-registers.h"
  24. #define WCD938X_DRV_NAME "wcd938x_codec"
  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. enum {
  37. WCD9380 = 0,
  38. WCD9385 = 5,
  39. };
  40. enum {
  41. CODEC_TX = 0,
  42. CODEC_RX,
  43. };
  44. enum {
  45. WCD_ADC1 = 0,
  46. WCD_ADC2,
  47. WCD_ADC3,
  48. WCD_ADC4,
  49. ALLOW_BUCK_DISABLE,
  50. HPH_COMP_DELAY,
  51. HPH_PA_DELAY,
  52. AMIC2_BCS_ENABLE,
  53. };
  54. enum {
  55. ADC_MODE_INVALID = 0,
  56. ADC_MODE_HIFI,
  57. ADC_MODE_LO_HIF,
  58. ADC_MODE_NORMAL,
  59. ADC_MODE_LP,
  60. ADC_MODE_ULP1,
  61. ADC_MODE_ULP2,
  62. };
  63. static const DECLARE_TLV_DB_SCALE(line_gain, 0, 7, 1);
  64. static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 25, 1);
  65. static int wcd938x_handle_post_irq(void *data);
  66. static int wcd938x_reset(struct device *dev);
  67. static int wcd938x_reset_low(struct device *dev);
  68. static const struct regmap_irq wcd938x_irqs[WCD938X_NUM_IRQS] = {
  69. REGMAP_IRQ_REG(WCD938X_IRQ_MBHC_BUTTON_PRESS_DET, 0, 0x01),
  70. REGMAP_IRQ_REG(WCD938X_IRQ_MBHC_BUTTON_RELEASE_DET, 0, 0x02),
  71. REGMAP_IRQ_REG(WCD938X_IRQ_MBHC_ELECT_INS_REM_DET, 0, 0x04),
  72. REGMAP_IRQ_REG(WCD938X_IRQ_MBHC_ELECT_INS_REM_LEG_DET, 0, 0x08),
  73. REGMAP_IRQ_REG(WCD938X_IRQ_MBHC_SW_DET, 0, 0x10),
  74. REGMAP_IRQ_REG(WCD938X_IRQ_HPHR_OCP_INT, 0, 0x20),
  75. REGMAP_IRQ_REG(WCD938X_IRQ_HPHR_CNP_INT, 0, 0x40),
  76. REGMAP_IRQ_REG(WCD938X_IRQ_HPHL_OCP_INT, 0, 0x80),
  77. REGMAP_IRQ_REG(WCD938X_IRQ_HPHL_CNP_INT, 1, 0x01),
  78. REGMAP_IRQ_REG(WCD938X_IRQ_EAR_CNP_INT, 1, 0x02),
  79. REGMAP_IRQ_REG(WCD938X_IRQ_EAR_SCD_INT, 1, 0x04),
  80. REGMAP_IRQ_REG(WCD938X_IRQ_AUX_CNP_INT, 1, 0x08),
  81. REGMAP_IRQ_REG(WCD938X_IRQ_AUX_SCD_INT, 1, 0x10),
  82. REGMAP_IRQ_REG(WCD938X_IRQ_HPHL_PDM_WD_INT, 1, 0x20),
  83. REGMAP_IRQ_REG(WCD938X_IRQ_HPHR_PDM_WD_INT, 1, 0x40),
  84. REGMAP_IRQ_REG(WCD938X_IRQ_AUX_PDM_WD_INT, 1, 0x80),
  85. REGMAP_IRQ_REG(WCD938X_IRQ_LDORT_SCD_INT, 2, 0x01),
  86. REGMAP_IRQ_REG(WCD938X_IRQ_MBHC_MOISTURE_INT, 2, 0x02),
  87. REGMAP_IRQ_REG(WCD938X_IRQ_HPHL_SURGE_DET_INT, 2, 0x04),
  88. REGMAP_IRQ_REG(WCD938X_IRQ_HPHR_SURGE_DET_INT, 2, 0x08),
  89. };
  90. static struct regmap_irq_chip wcd938x_regmap_irq_chip = {
  91. .name = "wcd938x",
  92. .irqs = wcd938x_irqs,
  93. .num_irqs = ARRAY_SIZE(wcd938x_irqs),
  94. .num_regs = 3,
  95. .status_base = WCD938X_DIGITAL_INTR_STATUS_0,
  96. .mask_base = WCD938X_DIGITAL_INTR_MASK_0,
  97. .type_base = WCD938X_DIGITAL_INTR_LEVEL_0,
  98. .ack_base = WCD938X_DIGITAL_INTR_CLEAR_0,
  99. .use_ack = 1,
  100. .runtime_pm = false,
  101. .handle_post_irq = wcd938x_handle_post_irq,
  102. .irq_drv_data = NULL,
  103. };
  104. static int wcd938x_handle_post_irq(void *data)
  105. {
  106. struct wcd938x_priv *wcd938x = data;
  107. u32 sts1 = 0, sts2 = 0, sts3 = 0;
  108. regmap_read(wcd938x->regmap, WCD938X_DIGITAL_INTR_STATUS_0, &sts1);
  109. regmap_read(wcd938x->regmap, WCD938X_DIGITAL_INTR_STATUS_1, &sts2);
  110. regmap_read(wcd938x->regmap, WCD938X_DIGITAL_INTR_STATUS_2, &sts3);
  111. wcd938x->tx_swr_dev->slave_irq_pending =
  112. ((sts1 || sts2 || sts3) ? true : false);
  113. return IRQ_HANDLED;
  114. }
  115. static int wcd938x_init_reg(struct snd_soc_component *component)
  116. {
  117. snd_soc_component_update_bits(component, WCD938X_SLEEP_CTL, 0x0E, 0x0E);
  118. snd_soc_component_update_bits(component, WCD938X_SLEEP_CTL, 0x80, 0x80);
  119. /* 1 msec delay as per HW requirement */
  120. usleep_range(1000, 1010);
  121. snd_soc_component_update_bits(component, WCD938X_SLEEP_CTL, 0x40, 0x40);
  122. /* 1 msec delay as per HW requirement */
  123. usleep_range(1000, 1010);
  124. snd_soc_component_update_bits(component, WCD938X_LDORXTX_CONFIG,
  125. 0x10, 0x00);
  126. snd_soc_component_update_bits(component, WCD938X_BIAS_VBG_FINE_ADJ,
  127. 0xF0, 0x80);
  128. snd_soc_component_update_bits(component, WCD938X_ANA_BIAS, 0x80, 0x80);
  129. snd_soc_component_update_bits(component, WCD938X_ANA_BIAS, 0x40, 0x40);
  130. /* 10 msec delay as per HW requirement */
  131. usleep_range(10000, 10010);
  132. snd_soc_component_update_bits(component, WCD938X_ANA_BIAS, 0x40, 0x00);
  133. snd_soc_component_update_bits(component,
  134. WCD938X_HPH_NEW_INT_RDAC_GAIN_CTL,
  135. 0xF0, 0x00);
  136. snd_soc_component_update_bits(component,
  137. WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_L_NEW,
  138. 0x1F, 0x15);
  139. snd_soc_component_update_bits(component,
  140. WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_R_NEW,
  141. 0x1F, 0x15);
  142. snd_soc_component_update_bits(component, WCD938X_HPH_REFBUFF_UHQA_CTL,
  143. 0xC0, 0x80);
  144. snd_soc_component_update_bits(component, WCD938X_DIGITAL_CDC_DMIC_CTL,
  145. 0x02, 0x02);
  146. snd_soc_component_update_bits(component,
  147. WCD938X_TX_COM_NEW_INT_TXFE_ICTRL_STG2CASC_ULP,
  148. 0xFF, 0x14);
  149. snd_soc_component_update_bits(component,
  150. WCD938X_TX_COM_NEW_INT_TXFE_ICTRL_STG2MAIN_ULP,
  151. 0x1F, 0x08);
  152. snd_soc_component_update_bits(component,
  153. WCD938X_DIGITAL_TX_REQ_FB_CTL_0, 0xFF, 0x55);
  154. snd_soc_component_update_bits(component,
  155. WCD938X_DIGITAL_TX_REQ_FB_CTL_1, 0xFF, 0x44);
  156. snd_soc_component_update_bits(component,
  157. WCD938X_DIGITAL_TX_REQ_FB_CTL_2, 0xFF, 0x11);
  158. snd_soc_component_update_bits(component,
  159. WCD938X_DIGITAL_TX_REQ_FB_CTL_3, 0xFF, 0x00);
  160. snd_soc_component_update_bits(component,
  161. WCD938X_DIGITAL_TX_REQ_FB_CTL_4, 0xFF, 0x00);
  162. snd_soc_component_update_bits(component,
  163. WCD938X_MICB1_TEST_CTL_1, 0xE0, 0xE0);
  164. snd_soc_component_update_bits(component,
  165. WCD938X_MICB2_TEST_CTL_1, 0xE0, 0xE0);
  166. snd_soc_component_update_bits(component,
  167. WCD938X_MICB3_TEST_CTL_1, 0xE0, 0xE0);
  168. snd_soc_component_update_bits(component,
  169. WCD938X_MICB4_TEST_CTL_1, 0xE0, 0xE0);
  170. return 0;
  171. }
  172. static int wcd938x_set_port_params(struct snd_soc_component *component,
  173. u8 slv_prt_type, u8 *port_id, u8 *num_ch,
  174. u8 *ch_mask, u32 *ch_rate,
  175. u8 *port_type, u8 path)
  176. {
  177. int i, j;
  178. u8 num_ports = 0;
  179. struct codec_port_info (*map)[MAX_PORT][MAX_CH_PER_PORT];
  180. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  181. switch (path) {
  182. case CODEC_RX:
  183. map = &wcd938x->rx_port_mapping;
  184. num_ports = wcd938x->num_rx_ports;
  185. break;
  186. case CODEC_TX:
  187. map = &wcd938x->tx_port_mapping;
  188. num_ports = wcd938x->num_tx_ports;
  189. break;
  190. default:
  191. dev_err(component->dev, "%s Invalid path selected %u\n",
  192. __func__, path);
  193. return -EINVAL;
  194. }
  195. for (i = 0; i <= num_ports; i++) {
  196. for (j = 0; j < MAX_CH_PER_PORT; j++) {
  197. if ((*map)[i][j].slave_port_type == slv_prt_type)
  198. goto found;
  199. }
  200. }
  201. found:
  202. if (i > num_ports || j == MAX_CH_PER_PORT) {
  203. dev_err(component->dev, "%s Failed to find slave port for type %u\n",
  204. __func__, slv_prt_type);
  205. return -EINVAL;
  206. }
  207. *port_id = i;
  208. *num_ch = (*map)[i][j].num_ch;
  209. *ch_mask = (*map)[i][j].ch_mask;
  210. *ch_rate = (*map)[i][j].ch_rate;
  211. *port_type = (*map)[i][j].master_port_type;
  212. return 0;
  213. }
  214. static int wcd938x_parse_port_mapping(struct device *dev,
  215. char *prop, u8 path)
  216. {
  217. u32 *dt_array, map_size, map_length;
  218. u32 port_num = 0, ch_mask, ch_rate, old_port_num = 0;
  219. u32 slave_port_type, master_port_type;
  220. u32 i, ch_iter = 0;
  221. int ret = 0;
  222. u8 *num_ports = NULL;
  223. struct codec_port_info (*map)[MAX_PORT][MAX_CH_PER_PORT];
  224. struct wcd938x_priv *wcd938x = dev_get_drvdata(dev);
  225. switch (path) {
  226. case CODEC_RX:
  227. map = &wcd938x->rx_port_mapping;
  228. num_ports = &wcd938x->num_rx_ports;
  229. break;
  230. case CODEC_TX:
  231. map = &wcd938x->tx_port_mapping;
  232. num_ports = &wcd938x->num_tx_ports;
  233. break;
  234. default:
  235. dev_err(dev, "%s Invalid path selected %u\n",
  236. __func__, path);
  237. return -EINVAL;
  238. }
  239. if (!of_find_property(dev->of_node, prop,
  240. &map_size)) {
  241. dev_err(dev, "missing port mapping prop %s\n", prop);
  242. ret = -EINVAL;
  243. goto err_port_map;
  244. }
  245. map_length = map_size / (NUM_SWRS_DT_PARAMS * sizeof(u32));
  246. dt_array = kzalloc(map_size, GFP_KERNEL);
  247. if (!dt_array) {
  248. ret = -ENOMEM;
  249. goto err_alloc;
  250. }
  251. ret = of_property_read_u32_array(dev->of_node, prop, dt_array,
  252. NUM_SWRS_DT_PARAMS * map_length);
  253. if (ret) {
  254. dev_err(dev, "%s: Failed to read port mapping from prop %s\n",
  255. __func__, prop);
  256. goto err_pdata_fail;
  257. }
  258. for (i = 0; i < map_length; i++) {
  259. port_num = dt_array[NUM_SWRS_DT_PARAMS * i];
  260. slave_port_type = dt_array[NUM_SWRS_DT_PARAMS * i + 1];
  261. ch_mask = dt_array[NUM_SWRS_DT_PARAMS * i + 2];
  262. ch_rate = dt_array[NUM_SWRS_DT_PARAMS * i + 3];
  263. master_port_type = dt_array[NUM_SWRS_DT_PARAMS * i + 4];
  264. if (port_num != old_port_num)
  265. ch_iter = 0;
  266. (*map)[port_num][ch_iter].slave_port_type = slave_port_type;
  267. (*map)[port_num][ch_iter].ch_mask = ch_mask;
  268. (*map)[port_num][ch_iter].master_port_type = master_port_type;
  269. (*map)[port_num][ch_iter].num_ch = __sw_hweight8(ch_mask);
  270. (*map)[port_num][ch_iter++].ch_rate = ch_rate;
  271. old_port_num = port_num;
  272. }
  273. *num_ports = port_num;
  274. kfree(dt_array);
  275. return 0;
  276. err_pdata_fail:
  277. kfree(dt_array);
  278. err_alloc:
  279. err_port_map:
  280. return ret;
  281. }
  282. static int wcd938x_tx_connect_port(struct snd_soc_component *component,
  283. u8 slv_port_type, u8 enable)
  284. {
  285. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  286. u8 port_id, num_ch, ch_mask, port_type;
  287. u32 ch_rate;
  288. u8 num_port = 1;
  289. int ret = 0;
  290. ret = wcd938x_set_port_params(component, slv_port_type, &port_id,
  291. &num_ch, &ch_mask, &ch_rate,
  292. &port_type, CODEC_TX);
  293. if (ret)
  294. return ret;
  295. if (enable)
  296. ret = swr_connect_port(wcd938x->tx_swr_dev, &port_id,
  297. num_port, &ch_mask, &ch_rate,
  298. &num_ch, &port_type);
  299. else
  300. ret = swr_disconnect_port(wcd938x->tx_swr_dev, &port_id,
  301. num_port, &ch_mask, &port_type);
  302. return ret;
  303. }
  304. static int wcd938x_rx_connect_port(struct snd_soc_component *component,
  305. u8 slv_port_type, u8 enable)
  306. {
  307. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  308. u8 port_id, num_ch, ch_mask, port_type;
  309. u32 ch_rate;
  310. u8 num_port = 1;
  311. int ret = 0;
  312. ret = wcd938x_set_port_params(component, slv_port_type, &port_id,
  313. &num_ch, &ch_mask, &ch_rate,
  314. &port_type, CODEC_RX);
  315. if (ret)
  316. return ret;
  317. if (enable)
  318. ret = swr_connect_port(wcd938x->rx_swr_dev, &port_id,
  319. num_port, &ch_mask, &ch_rate,
  320. &num_ch, &port_type);
  321. else
  322. ret = swr_disconnect_port(wcd938x->rx_swr_dev, &port_id,
  323. num_port, &ch_mask, &port_type);
  324. return ret;
  325. }
  326. static int wcd938x_rx_clk_enable(struct snd_soc_component *component)
  327. {
  328. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  329. if (wcd938x->rx_clk_cnt == 0) {
  330. snd_soc_component_update_bits(component,
  331. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x01, 0x01);
  332. snd_soc_component_update_bits(component,
  333. WCD938X_ANA_RX_SUPPLIES, 0x01, 0x01);
  334. snd_soc_component_update_bits(component,
  335. WCD938X_DIGITAL_CDC_RX0_CTL, 0x40, 0x00);
  336. snd_soc_component_update_bits(component,
  337. WCD938X_DIGITAL_CDC_RX1_CTL, 0x40, 0x00);
  338. snd_soc_component_update_bits(component,
  339. WCD938X_DIGITAL_CDC_RX2_CTL, 0x40, 0x00);
  340. snd_soc_component_update_bits(component,
  341. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x02, 0x02);
  342. snd_soc_component_update_bits(component,
  343. WCD938X_AUX_AUXPA, 0x10, 0x10);
  344. }
  345. wcd938x->rx_clk_cnt++;
  346. return 0;
  347. }
  348. static int wcd938x_rx_clk_disable(struct snd_soc_component *component)
  349. {
  350. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  351. wcd938x->rx_clk_cnt--;
  352. if (wcd938x->rx_clk_cnt == 0) {
  353. snd_soc_component_update_bits(component,
  354. WCD938X_ANA_RX_SUPPLIES, 0x40, 0x00);
  355. snd_soc_component_update_bits(component,
  356. WCD938X_ANA_RX_SUPPLIES, 0x80, 0x00);
  357. snd_soc_component_update_bits(component,
  358. WCD938X_ANA_RX_SUPPLIES, 0x01, 0x00);
  359. snd_soc_component_update_bits(component,
  360. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x02, 0x00);
  361. snd_soc_component_update_bits(component,
  362. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x01, 0x00);
  363. }
  364. return 0;
  365. }
  366. /*
  367. * wcd938x_soc_get_mbhc: get wcd938x_mbhc handle of corresponding component
  368. * @component: handle to snd_soc_component *
  369. *
  370. * return wcd938x_mbhc handle or error code in case of failure
  371. */
  372. struct wcd938x_mbhc *wcd938x_soc_get_mbhc(struct snd_soc_component *component)
  373. {
  374. struct wcd938x_priv *wcd938x;
  375. if (!component) {
  376. pr_err("%s: Invalid params, NULL component\n", __func__);
  377. return NULL;
  378. }
  379. wcd938x = snd_soc_component_get_drvdata(component);
  380. if (!wcd938x) {
  381. pr_err("%s: wcd938x is NULL\n", __func__);
  382. return NULL;
  383. }
  384. return wcd938x->mbhc;
  385. }
  386. EXPORT_SYMBOL(wcd938x_soc_get_mbhc);
  387. static int wcd938x_codec_hphl_dac_event(struct snd_soc_dapm_widget *w,
  388. struct snd_kcontrol *kcontrol,
  389. int event)
  390. {
  391. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  392. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  393. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  394. w->name, event);
  395. switch (event) {
  396. case SND_SOC_DAPM_PRE_PMU:
  397. wcd938x_rx_clk_enable(component);
  398. snd_soc_component_update_bits(component,
  399. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x01, 0x01);
  400. snd_soc_component_update_bits(component,
  401. WCD938X_DIGITAL_CDC_HPH_GAIN_CTL, 0x04, 0x04);
  402. snd_soc_component_update_bits(component,
  403. WCD938X_HPH_RDAC_CLK_CTL1, 0x80, 0x00);
  404. break;
  405. case SND_SOC_DAPM_POST_PMU:
  406. snd_soc_component_update_bits(component,
  407. WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_L, 0x0F, 0x02);
  408. if (wcd938x->comp1_enable) {
  409. snd_soc_component_update_bits(component,
  410. WCD938X_DIGITAL_CDC_COMP_CTL_0, 0x02, 0x02);
  411. /* 5msec compander delay as per HW requirement */
  412. if (!wcd938x->comp2_enable ||
  413. (snd_soc_component_read32(component,
  414. WCD938X_DIGITAL_CDC_COMP_CTL_0) & 0x01))
  415. usleep_range(5000, 5010);
  416. snd_soc_component_update_bits(component,
  417. WCD938X_HPH_NEW_INT_HPH_TIMER1, 0x02, 0x00);
  418. } else {
  419. snd_soc_component_update_bits(component,
  420. WCD938X_DIGITAL_CDC_COMP_CTL_0,
  421. 0x02, 0x00);
  422. snd_soc_component_update_bits(component,
  423. WCD938X_HPH_L_EN, 0x20, 0x20);
  424. }
  425. break;
  426. case SND_SOC_DAPM_POST_PMD:
  427. snd_soc_component_update_bits(component,
  428. WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_R,
  429. 0x0F, 0x01);
  430. break;
  431. }
  432. return 0;
  433. }
  434. static int wcd938x_codec_hphr_dac_event(struct snd_soc_dapm_widget *w,
  435. struct snd_kcontrol *kcontrol,
  436. int event)
  437. {
  438. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  439. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  440. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  441. w->name, event);
  442. switch (event) {
  443. case SND_SOC_DAPM_PRE_PMU:
  444. wcd938x_rx_clk_enable(component);
  445. snd_soc_component_update_bits(component,
  446. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x02, 0x02);
  447. snd_soc_component_update_bits(component,
  448. WCD938X_DIGITAL_CDC_HPH_GAIN_CTL, 0x08, 0x08);
  449. snd_soc_component_update_bits(component,
  450. WCD938X_HPH_RDAC_CLK_CTL1, 0x80, 0x00);
  451. break;
  452. case SND_SOC_DAPM_POST_PMU:
  453. snd_soc_component_update_bits(component,
  454. WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_R, 0x0F, 0x02);
  455. if (wcd938x->comp2_enable) {
  456. snd_soc_component_update_bits(component,
  457. WCD938X_DIGITAL_CDC_COMP_CTL_0, 0x01, 0x01);
  458. /* 5msec compander delay as per HW requirement */
  459. if (!wcd938x->comp1_enable ||
  460. (snd_soc_component_read32(component,
  461. WCD938X_DIGITAL_CDC_COMP_CTL_0) & 0x02))
  462. usleep_range(5000, 5010);
  463. snd_soc_component_update_bits(component,
  464. WCD938X_HPH_NEW_INT_HPH_TIMER1, 0x02, 0x00);
  465. } else {
  466. snd_soc_component_update_bits(component,
  467. WCD938X_DIGITAL_CDC_COMP_CTL_0,
  468. 0x01, 0x00);
  469. snd_soc_component_update_bits(component,
  470. WCD938X_HPH_R_EN, 0x20, 0x20);
  471. }
  472. break;
  473. case SND_SOC_DAPM_POST_PMD:
  474. snd_soc_component_update_bits(component,
  475. WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_R,
  476. 0x0F, 0x01);
  477. break;
  478. }
  479. return 0;
  480. }
  481. static int wcd938x_codec_ear_dac_event(struct snd_soc_dapm_widget *w,
  482. struct snd_kcontrol *kcontrol,
  483. int event)
  484. {
  485. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  486. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  487. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  488. w->name, event);
  489. switch (event) {
  490. case SND_SOC_DAPM_PRE_PMU:
  491. wcd938x_rx_clk_enable(component);
  492. snd_soc_component_update_bits(component,
  493. WCD938X_DIGITAL_CDC_HPH_GAIN_CTL, 0x04, 0x04);
  494. snd_soc_component_update_bits(component,
  495. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x01, 0x01);
  496. snd_soc_component_update_bits(component,
  497. WCD938X_DIGITAL_CDC_COMP_CTL_0, 0x02, 0x02);
  498. /* 5 msec delay as per HW requirement */
  499. usleep_range(5000, 5010);
  500. if (wcd938x->flyback_cur_det_disable == 0)
  501. snd_soc_component_update_bits(component,
  502. WCD938X_FLYBACK_EN,
  503. 0x04, 0x00);
  504. wcd938x->flyback_cur_det_disable++;
  505. wcd_cls_h_fsm(component, &wcd938x->clsh_info,
  506. WCD_CLSH_EVENT_PRE_DAC,
  507. WCD_CLSH_STATE_EAR,
  508. wcd938x->hph_mode);
  509. break;
  510. case SND_SOC_DAPM_POST_PMD:
  511. break;
  512. };
  513. return 0;
  514. }
  515. static int wcd938x_codec_aux_dac_event(struct snd_soc_dapm_widget *w,
  516. struct snd_kcontrol *kcontrol,
  517. int event)
  518. {
  519. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  520. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  521. int ret = 0;
  522. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  523. w->name, event);
  524. switch (event) {
  525. case SND_SOC_DAPM_PRE_PMU:
  526. wcd938x_rx_clk_enable(component);
  527. snd_soc_component_update_bits(component,
  528. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x04, 0x04);
  529. snd_soc_component_update_bits(component,
  530. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x04, 0x04);
  531. snd_soc_component_update_bits(component,
  532. WCD938X_DIGITAL_CDC_AUX_GAIN_CTL, 0x01, 0x01);
  533. if (wcd938x->flyback_cur_det_disable == 0)
  534. snd_soc_component_update_bits(component,
  535. WCD938X_FLYBACK_EN,
  536. 0x04, 0x00);
  537. wcd938x->flyback_cur_det_disable++;
  538. wcd_cls_h_fsm(component, &wcd938x->clsh_info,
  539. WCD_CLSH_EVENT_PRE_DAC,
  540. WCD_CLSH_STATE_AUX,
  541. wcd938x->hph_mode);
  542. break;
  543. case SND_SOC_DAPM_POST_PMD:
  544. snd_soc_component_update_bits(component,
  545. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x04, 0x00);
  546. break;
  547. };
  548. return ret;
  549. }
  550. static int wcd938x_codec_enable_hphr_pa(struct snd_soc_dapm_widget *w,
  551. struct snd_kcontrol *kcontrol,
  552. int event)
  553. {
  554. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  555. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  556. int ret = 0;
  557. int hph_mode = wcd938x->hph_mode;
  558. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  559. w->name, event);
  560. switch (event) {
  561. case SND_SOC_DAPM_PRE_PMU:
  562. if (wcd938x->ldoh)
  563. snd_soc_component_update_bits(component,
  564. WCD938X_LDOH_MODE,
  565. 0x80, 0x80);
  566. if (wcd938x->update_wcd_event)
  567. wcd938x->update_wcd_event(wcd938x->handle,
  568. WCD_BOLERO_EVT_RX_MUTE,
  569. (WCD_RX2 << 0x10 | 0x1));
  570. ret = swr_slvdev_datapath_control(wcd938x->rx_swr_dev,
  571. wcd938x->rx_swr_dev->dev_num,
  572. true);
  573. wcd_cls_h_fsm(component, &wcd938x->clsh_info,
  574. WCD_CLSH_EVENT_PRE_DAC,
  575. WCD_CLSH_STATE_HPHR,
  576. hph_mode);
  577. wcd_clsh_set_hph_mode(component, CLS_H_HIFI);
  578. snd_soc_component_update_bits(component, WCD938X_ANA_HPH,
  579. 0x10, 0x10);
  580. wcd_clsh_set_hph_mode(component, hph_mode);
  581. /* 100 usec delay as per HW requirement */
  582. usleep_range(100, 110);
  583. set_bit(HPH_PA_DELAY, &wcd938x->status_mask);
  584. snd_soc_component_update_bits(component,
  585. WCD938X_DIGITAL_PDM_WD_CTL1, 0x17, 0x13);
  586. break;
  587. case SND_SOC_DAPM_POST_PMU:
  588. /*
  589. * 7ms sleep is required if compander is enabled as per
  590. * HW requirement. If compander is disabled, then
  591. * 20ms delay is required.
  592. */
  593. if (test_bit(HPH_PA_DELAY, &wcd938x->status_mask)) {
  594. if (!wcd938x->comp2_enable)
  595. usleep_range(20000, 20100);
  596. else
  597. usleep_range(7000, 7100);
  598. clear_bit(HPH_PA_DELAY, &wcd938x->status_mask);
  599. }
  600. snd_soc_component_update_bits(component,
  601. WCD938X_HPH_NEW_INT_HPH_TIMER1, 0x02, 0x02);
  602. if (hph_mode == CLS_AB || hph_mode == CLS_AB_HIFI ||
  603. hph_mode == CLS_AB_LP || hph_mode == CLS_AB_LOHIFI)
  604. snd_soc_component_update_bits(component,
  605. WCD938X_ANA_RX_SUPPLIES, 0x02, 0x02);
  606. if (wcd938x->update_wcd_event)
  607. wcd938x->update_wcd_event(wcd938x->handle,
  608. WCD_BOLERO_EVT_RX_MUTE,
  609. (WCD_RX2 << 0x10));
  610. wcd_enable_irq(&wcd938x->irq_info,
  611. WCD938X_IRQ_HPHR_PDM_WD_INT);
  612. break;
  613. case SND_SOC_DAPM_PRE_PMD:
  614. if (wcd938x->update_wcd_event)
  615. wcd938x->update_wcd_event(wcd938x->handle,
  616. WCD_BOLERO_EVT_RX_MUTE,
  617. (WCD_RX2 << 0x10 | 0x1));
  618. wcd_disable_irq(&wcd938x->irq_info,
  619. WCD938X_IRQ_HPHR_PDM_WD_INT);
  620. if (wcd938x->update_wcd_event && wcd938x->comp2_enable)
  621. wcd938x->update_wcd_event(wcd938x->handle,
  622. WCD_BOLERO_EVT_RX_COMPANDER_SOFT_RST,
  623. (WCD_RX2 << 0x10));
  624. /*
  625. * 7ms sleep is required if compander is enabled as per
  626. * HW requirement. If compander is disabled, then
  627. * 20ms delay is required.
  628. */
  629. if (!wcd938x->comp2_enable)
  630. usleep_range(20000, 20100);
  631. else
  632. usleep_range(7000, 7100);
  633. snd_soc_component_update_bits(component, WCD938X_ANA_HPH,
  634. 0x40, 0x00);
  635. blocking_notifier_call_chain(&wcd938x->mbhc->notifier,
  636. WCD_EVENT_PRE_HPHR_PA_OFF,
  637. &wcd938x->mbhc->wcd_mbhc);
  638. set_bit(HPH_PA_DELAY, &wcd938x->status_mask);
  639. break;
  640. case SND_SOC_DAPM_POST_PMD:
  641. /*
  642. * 7ms sleep is required if compander is enabled as per
  643. * HW requirement. If compander is disabled, then
  644. * 20ms delay is required.
  645. */
  646. if (test_bit(HPH_PA_DELAY, &wcd938x->status_mask)) {
  647. if (!wcd938x->comp2_enable)
  648. usleep_range(20000, 20100);
  649. else
  650. usleep_range(7000, 7100);
  651. clear_bit(HPH_PA_DELAY, &wcd938x->status_mask);
  652. }
  653. blocking_notifier_call_chain(&wcd938x->mbhc->notifier,
  654. WCD_EVENT_POST_HPHR_PA_OFF,
  655. &wcd938x->mbhc->wcd_mbhc);
  656. snd_soc_component_update_bits(component, WCD938X_ANA_HPH,
  657. 0x10, 0x00);
  658. snd_soc_component_update_bits(component,
  659. WCD938X_DIGITAL_PDM_WD_CTL1, 0x17, 0x00);
  660. wcd_cls_h_fsm(component, &wcd938x->clsh_info,
  661. WCD_CLSH_EVENT_POST_PA,
  662. WCD_CLSH_STATE_HPHR,
  663. hph_mode);
  664. if (wcd938x->ldoh)
  665. snd_soc_component_update_bits(component,
  666. WCD938X_LDOH_MODE,
  667. 0x80, 0x00);
  668. break;
  669. };
  670. return ret;
  671. }
  672. static int wcd938x_codec_enable_hphl_pa(struct snd_soc_dapm_widget *w,
  673. struct snd_kcontrol *kcontrol,
  674. int event)
  675. {
  676. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  677. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  678. int ret = 0;
  679. int hph_mode = wcd938x->hph_mode;
  680. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  681. w->name, event);
  682. switch (event) {
  683. case SND_SOC_DAPM_PRE_PMU:
  684. if (wcd938x->ldoh)
  685. snd_soc_component_update_bits(component,
  686. WCD938X_LDOH_MODE,
  687. 0x80, 0x80);
  688. if (wcd938x->update_wcd_event)
  689. wcd938x->update_wcd_event(wcd938x->handle,
  690. WCD_BOLERO_EVT_RX_MUTE,
  691. (WCD_RX1 << 0x10 | 0x01));
  692. ret = swr_slvdev_datapath_control(wcd938x->rx_swr_dev,
  693. wcd938x->rx_swr_dev->dev_num,
  694. true);
  695. wcd_cls_h_fsm(component, &wcd938x->clsh_info,
  696. WCD_CLSH_EVENT_PRE_DAC,
  697. WCD_CLSH_STATE_HPHL,
  698. hph_mode);
  699. wcd_clsh_set_hph_mode(component, CLS_H_HIFI);
  700. snd_soc_component_update_bits(component, WCD938X_ANA_HPH,
  701. 0x20, 0x20);
  702. wcd_clsh_set_hph_mode(component, hph_mode);
  703. /* 100 usec delay as per HW requirement */
  704. usleep_range(100, 110);
  705. set_bit(HPH_PA_DELAY, &wcd938x->status_mask);
  706. snd_soc_component_update_bits(component,
  707. WCD938X_DIGITAL_PDM_WD_CTL0, 0x17, 0x13);
  708. break;
  709. case SND_SOC_DAPM_POST_PMU:
  710. /*
  711. * 7ms sleep is required if compander is enabled as per
  712. * HW requirement. If compander is disabled, then
  713. * 20ms delay is required.
  714. */
  715. if (test_bit(HPH_PA_DELAY, &wcd938x->status_mask)) {
  716. if (!wcd938x->comp1_enable)
  717. usleep_range(20000, 20100);
  718. else
  719. usleep_range(7000, 7100);
  720. clear_bit(HPH_PA_DELAY, &wcd938x->status_mask);
  721. }
  722. snd_soc_component_update_bits(component,
  723. WCD938X_HPH_NEW_INT_HPH_TIMER1, 0x02, 0x02);
  724. if (hph_mode == CLS_AB || hph_mode == CLS_AB_HIFI ||
  725. hph_mode == CLS_AB_LP || hph_mode == CLS_AB_LOHIFI)
  726. snd_soc_component_update_bits(component,
  727. WCD938X_ANA_RX_SUPPLIES, 0x02, 0x02);
  728. if (wcd938x->update_wcd_event)
  729. wcd938x->update_wcd_event(wcd938x->handle,
  730. WCD_BOLERO_EVT_RX_MUTE,
  731. (WCD_RX1 << 0x10));
  732. wcd_enable_irq(&wcd938x->irq_info,
  733. WCD938X_IRQ_HPHL_PDM_WD_INT);
  734. break;
  735. case SND_SOC_DAPM_PRE_PMD:
  736. if (wcd938x->update_wcd_event)
  737. wcd938x->update_wcd_event(wcd938x->handle,
  738. WCD_BOLERO_EVT_RX_MUTE,
  739. (WCD_RX1 << 0x10 | 0x1));
  740. wcd_disable_irq(&wcd938x->irq_info,
  741. WCD938X_IRQ_HPHL_PDM_WD_INT);
  742. if (wcd938x->update_wcd_event && wcd938x->comp1_enable)
  743. wcd938x->update_wcd_event(wcd938x->handle,
  744. WCD_BOLERO_EVT_RX_COMPANDER_SOFT_RST,
  745. (WCD_RX1 << 0x10));
  746. /*
  747. * 7ms sleep is required if compander is enabled as per
  748. * HW requirement. If compander is disabled, then
  749. * 20ms delay is required.
  750. */
  751. if (!wcd938x->comp1_enable)
  752. usleep_range(20000, 20100);
  753. else
  754. usleep_range(7000, 7100);
  755. snd_soc_component_update_bits(component, WCD938X_ANA_HPH,
  756. 0x80, 0x00);
  757. blocking_notifier_call_chain(&wcd938x->mbhc->notifier,
  758. WCD_EVENT_PRE_HPHL_PA_OFF,
  759. &wcd938x->mbhc->wcd_mbhc);
  760. set_bit(HPH_PA_DELAY, &wcd938x->status_mask);
  761. break;
  762. case SND_SOC_DAPM_POST_PMD:
  763. /*
  764. * 7ms sleep is required if compander is enabled as per
  765. * HW requirement. If compander is disabled, then
  766. * 20ms delay is required.
  767. */
  768. if (test_bit(HPH_PA_DELAY, &wcd938x->status_mask)) {
  769. if (!wcd938x->comp1_enable)
  770. usleep_range(21000, 21100);
  771. else
  772. usleep_range(7000, 7100);
  773. clear_bit(HPH_PA_DELAY, &wcd938x->status_mask);
  774. }
  775. blocking_notifier_call_chain(&wcd938x->mbhc->notifier,
  776. WCD_EVENT_POST_HPHL_PA_OFF,
  777. &wcd938x->mbhc->wcd_mbhc);
  778. snd_soc_component_update_bits(component, WCD938X_ANA_HPH,
  779. 0x20, 0x00);
  780. snd_soc_component_update_bits(component,
  781. WCD938X_DIGITAL_PDM_WD_CTL0, 0x17, 0x00);
  782. wcd_cls_h_fsm(component, &wcd938x->clsh_info,
  783. WCD_CLSH_EVENT_POST_PA,
  784. WCD_CLSH_STATE_HPHL,
  785. hph_mode);
  786. if (wcd938x->ldoh)
  787. snd_soc_component_update_bits(component,
  788. WCD938X_LDOH_MODE,
  789. 0x80, 0x00);
  790. break;
  791. };
  792. return ret;
  793. }
  794. static int wcd938x_codec_enable_aux_pa(struct snd_soc_dapm_widget *w,
  795. struct snd_kcontrol *kcontrol,
  796. int event)
  797. {
  798. struct snd_soc_component *component =
  799. snd_soc_dapm_to_component(w->dapm);
  800. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  801. int hph_mode = wcd938x->hph_mode;
  802. int ret = 0;
  803. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  804. w->name, event);
  805. switch (event) {
  806. case SND_SOC_DAPM_PRE_PMU:
  807. ret = swr_slvdev_datapath_control(wcd938x->rx_swr_dev,
  808. wcd938x->rx_swr_dev->dev_num,
  809. true);
  810. snd_soc_component_update_bits(component,
  811. WCD938X_DIGITAL_PDM_WD_CTL2, 0x05, 0x05);
  812. break;
  813. case SND_SOC_DAPM_POST_PMU:
  814. /* 1 msec delay as per HW requirement */
  815. usleep_range(1000, 1010);
  816. if (hph_mode == CLS_AB || hph_mode == CLS_AB_HIFI ||
  817. hph_mode == CLS_AB_LP || hph_mode == CLS_AB_LOHIFI)
  818. snd_soc_component_update_bits(component,
  819. WCD938X_ANA_RX_SUPPLIES,
  820. 0x02, 0x02);
  821. if (wcd938x->update_wcd_event)
  822. wcd938x->update_wcd_event(wcd938x->handle,
  823. WCD_BOLERO_EVT_RX_MUTE,
  824. (WCD_RX3 << 0x10));
  825. wcd_enable_irq(&wcd938x->irq_info, WCD938X_IRQ_AUX_PDM_WD_INT);
  826. break;
  827. case SND_SOC_DAPM_PRE_PMD:
  828. wcd_disable_irq(&wcd938x->irq_info,
  829. WCD938X_IRQ_AUX_PDM_WD_INT);
  830. if (wcd938x->update_wcd_event)
  831. wcd938x->update_wcd_event(wcd938x->handle,
  832. WCD_BOLERO_EVT_RX_MUTE,
  833. (WCD_RX3 << 0x10 | 0x1));
  834. break;
  835. case SND_SOC_DAPM_POST_PMD:
  836. /* 1 msec delay as per HW requirement */
  837. usleep_range(1000, 1010);
  838. snd_soc_component_update_bits(component,
  839. WCD938X_DIGITAL_PDM_WD_CTL2, 0x05, 0x00);
  840. wcd_cls_h_fsm(component, &wcd938x->clsh_info,
  841. WCD_CLSH_EVENT_POST_PA,
  842. WCD_CLSH_STATE_AUX,
  843. hph_mode);
  844. wcd938x->flyback_cur_det_disable--;
  845. if (wcd938x->flyback_cur_det_disable == 0)
  846. snd_soc_component_update_bits(component,
  847. WCD938X_FLYBACK_EN,
  848. 0x04, 0x04);
  849. break;
  850. };
  851. return ret;
  852. }
  853. static int wcd938x_codec_enable_ear_pa(struct snd_soc_dapm_widget *w,
  854. struct snd_kcontrol *kcontrol,
  855. int event)
  856. {
  857. struct snd_soc_component *component =
  858. snd_soc_dapm_to_component(w->dapm);
  859. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  860. int hph_mode = wcd938x->hph_mode;
  861. int ret = 0;
  862. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  863. w->name, event);
  864. switch (event) {
  865. case SND_SOC_DAPM_PRE_PMU:
  866. ret = swr_slvdev_datapath_control(wcd938x->rx_swr_dev,
  867. wcd938x->rx_swr_dev->dev_num,
  868. true);
  869. /*
  870. * Enable watchdog interrupt for HPHL or AUX
  871. * depending on mux value
  872. */
  873. wcd938x->ear_rx_path =
  874. snd_soc_component_read32(
  875. component, WCD938X_DIGITAL_CDC_EAR_PATH_CTL);
  876. if (wcd938x->ear_rx_path & EAR_RX_PATH_AUX)
  877. snd_soc_component_update_bits(component,
  878. WCD938X_DIGITAL_PDM_WD_CTL2,
  879. 0x05, 0x05);
  880. else
  881. snd_soc_component_update_bits(component,
  882. WCD938X_DIGITAL_PDM_WD_CTL0,
  883. 0x17, 0x13);
  884. break;
  885. case SND_SOC_DAPM_POST_PMU:
  886. /* 6 msec delay as per HW requirement */
  887. usleep_range(6000, 6010);
  888. if (hph_mode == CLS_AB || hph_mode == CLS_AB_HIFI ||
  889. hph_mode == CLS_AB_LP || hph_mode == CLS_AB_LOHIFI)
  890. snd_soc_component_update_bits(component,
  891. WCD938X_ANA_RX_SUPPLIES,
  892. 0x02, 0x02);
  893. if (wcd938x->update_wcd_event)
  894. wcd938x->update_wcd_event(wcd938x->handle,
  895. WCD_BOLERO_EVT_RX_MUTE,
  896. (WCD_RX1 << 0x10));
  897. if (wcd938x->ear_rx_path & EAR_RX_PATH_AUX)
  898. wcd_enable_irq(&wcd938x->irq_info,
  899. WCD938X_IRQ_AUX_PDM_WD_INT);
  900. else
  901. wcd_enable_irq(&wcd938x->irq_info,
  902. WCD938X_IRQ_HPHL_PDM_WD_INT);
  903. break;
  904. case SND_SOC_DAPM_PRE_PMD:
  905. if (wcd938x->ear_rx_path & EAR_RX_PATH_AUX)
  906. wcd_disable_irq(&wcd938x->irq_info,
  907. WCD938X_IRQ_AUX_PDM_WD_INT);
  908. else
  909. wcd_disable_irq(&wcd938x->irq_info,
  910. WCD938X_IRQ_HPHL_PDM_WD_INT);
  911. if (wcd938x->update_wcd_event)
  912. wcd938x->update_wcd_event(wcd938x->handle,
  913. WCD_BOLERO_EVT_RX_MUTE,
  914. (WCD_RX1 << 0x10 | 0x1));
  915. break;
  916. case SND_SOC_DAPM_POST_PMD:
  917. /* 7 msec delay as per HW requirement */
  918. usleep_range(7000, 7010);
  919. if (wcd938x->ear_rx_path & EAR_RX_PATH_AUX)
  920. snd_soc_component_update_bits(component,
  921. WCD938X_DIGITAL_PDM_WD_CTL2,
  922. 0x05, 0x00);
  923. else
  924. snd_soc_component_update_bits(component,
  925. WCD938X_DIGITAL_PDM_WD_CTL0,
  926. 0x17, 0x00);
  927. wcd_cls_h_fsm(component, &wcd938x->clsh_info,
  928. WCD_CLSH_EVENT_POST_PA,
  929. WCD_CLSH_STATE_EAR,
  930. hph_mode);
  931. wcd938x->flyback_cur_det_disable--;
  932. if (wcd938x->flyback_cur_det_disable == 0)
  933. snd_soc_component_update_bits(component,
  934. WCD938X_FLYBACK_EN,
  935. 0x04, 0x04);
  936. break;
  937. };
  938. return ret;
  939. }
  940. static int wcd938x_enable_clsh(struct snd_soc_dapm_widget *w,
  941. struct snd_kcontrol *kcontrol,
  942. int event)
  943. {
  944. struct snd_soc_component *component =
  945. snd_soc_dapm_to_component(w->dapm);
  946. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  947. int mode = wcd938x->hph_mode;
  948. int ret = 0;
  949. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  950. w->name, event);
  951. if (mode == CLS_H_LOHIFI || mode == CLS_H_ULP ||
  952. mode == CLS_H_HIFI || mode == CLS_H_LP) {
  953. wcd938x_rx_connect_port(component, CLSH,
  954. SND_SOC_DAPM_EVENT_ON(event));
  955. }
  956. if (SND_SOC_DAPM_EVENT_OFF(event))
  957. ret = swr_slvdev_datapath_control(
  958. wcd938x->rx_swr_dev,
  959. wcd938x->rx_swr_dev->dev_num,
  960. false);
  961. return ret;
  962. }
  963. static int wcd938x_enable_rx1(struct snd_soc_dapm_widget *w,
  964. struct snd_kcontrol *kcontrol,
  965. int event)
  966. {
  967. struct snd_soc_component *component =
  968. snd_soc_dapm_to_component(w->dapm);
  969. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  970. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  971. w->name, event);
  972. switch (event) {
  973. case SND_SOC_DAPM_PRE_PMU:
  974. wcd938x_rx_connect_port(component, HPH_L, true);
  975. if (wcd938x->comp1_enable)
  976. wcd938x_rx_connect_port(component, COMP_L, true);
  977. break;
  978. case SND_SOC_DAPM_POST_PMD:
  979. wcd938x_rx_connect_port(component, HPH_L, false);
  980. if (wcd938x->comp1_enable)
  981. wcd938x_rx_connect_port(component, COMP_L, false);
  982. wcd938x_rx_clk_disable(component);
  983. snd_soc_component_update_bits(component,
  984. WCD938X_DIGITAL_CDC_DIG_CLK_CTL,
  985. 0x01, 0x00);
  986. break;
  987. };
  988. return 0;
  989. }
  990. static int wcd938x_enable_rx2(struct snd_soc_dapm_widget *w,
  991. struct snd_kcontrol *kcontrol, int event)
  992. {
  993. struct snd_soc_component *component =
  994. snd_soc_dapm_to_component(w->dapm);
  995. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  996. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  997. w->name, event);
  998. switch (event) {
  999. case SND_SOC_DAPM_PRE_PMU:
  1000. wcd938x_rx_connect_port(component, HPH_R, true);
  1001. if (wcd938x->comp2_enable)
  1002. wcd938x_rx_connect_port(component, COMP_R, true);
  1003. break;
  1004. case SND_SOC_DAPM_POST_PMD:
  1005. wcd938x_rx_connect_port(component, HPH_R, false);
  1006. if (wcd938x->comp2_enable)
  1007. wcd938x_rx_connect_port(component, COMP_R, false);
  1008. wcd938x_rx_clk_disable(component);
  1009. snd_soc_component_update_bits(component,
  1010. WCD938X_DIGITAL_CDC_DIG_CLK_CTL,
  1011. 0x02, 0x00);
  1012. break;
  1013. };
  1014. return 0;
  1015. }
  1016. static int wcd938x_enable_rx3(struct snd_soc_dapm_widget *w,
  1017. struct snd_kcontrol *kcontrol,
  1018. int event)
  1019. {
  1020. struct snd_soc_component *component =
  1021. snd_soc_dapm_to_component(w->dapm);
  1022. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1023. w->name, event);
  1024. switch (event) {
  1025. case SND_SOC_DAPM_PRE_PMU:
  1026. wcd938x_rx_connect_port(component, LO, true);
  1027. break;
  1028. case SND_SOC_DAPM_POST_PMD:
  1029. wcd938x_rx_connect_port(component, LO, false);
  1030. /* 6 msec delay as per HW requirement */
  1031. usleep_range(6000, 6010);
  1032. wcd938x_rx_clk_disable(component);
  1033. snd_soc_component_update_bits(component,
  1034. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x04, 0x00);
  1035. break;
  1036. }
  1037. return 0;
  1038. }
  1039. static int wcd938x_codec_enable_dmic(struct snd_soc_dapm_widget *w,
  1040. struct snd_kcontrol *kcontrol,
  1041. int event)
  1042. {
  1043. struct snd_soc_component *component =
  1044. snd_soc_dapm_to_component(w->dapm);
  1045. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1046. u16 dmic_clk_reg, dmic_clk_en_reg;
  1047. s32 *dmic_clk_cnt;
  1048. u8 dmic_ctl_shift = 0;
  1049. u8 dmic_clk_shift = 0;
  1050. u8 dmic_clk_mask = 0;
  1051. u16 dmic2_left_en = 0;
  1052. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1053. w->name, event);
  1054. switch (w->shift) {
  1055. case 0:
  1056. case 1:
  1057. dmic_clk_cnt = &(wcd938x->dmic_0_1_clk_cnt);
  1058. dmic_clk_reg = WCD938X_DIGITAL_CDC_DMIC_RATE_1_2;
  1059. dmic_clk_en_reg = WCD938X_DIGITAL_CDC_DMIC1_CTL;
  1060. dmic_clk_mask = 0x0F;
  1061. dmic_clk_shift = 0x00;
  1062. dmic_ctl_shift = 0x00;
  1063. break;
  1064. case 2:
  1065. dmic2_left_en = WCD938X_DIGITAL_CDC_DMIC2_CTL;
  1066. case 3:
  1067. dmic_clk_cnt = &(wcd938x->dmic_2_3_clk_cnt);
  1068. dmic_clk_reg = WCD938X_DIGITAL_CDC_DMIC_RATE_1_2;
  1069. dmic_clk_en_reg = WCD938X_DIGITAL_CDC_DMIC2_CTL;
  1070. dmic_clk_mask = 0xF0;
  1071. dmic_clk_shift = 0x04;
  1072. dmic_ctl_shift = 0x01;
  1073. break;
  1074. case 4:
  1075. case 5:
  1076. dmic_clk_cnt = &(wcd938x->dmic_4_5_clk_cnt);
  1077. dmic_clk_reg = WCD938X_DIGITAL_CDC_DMIC_RATE_3_4;
  1078. dmic_clk_en_reg = WCD938X_DIGITAL_CDC_DMIC3_CTL;
  1079. dmic_clk_mask = 0x0F;
  1080. dmic_clk_shift = 0x00;
  1081. dmic_ctl_shift = 0x02;
  1082. break;
  1083. case 6:
  1084. case 7:
  1085. dmic_clk_cnt = &(wcd938x->dmic_6_7_clk_cnt);
  1086. dmic_clk_reg = WCD938X_DIGITAL_CDC_DMIC_RATE_3_4;
  1087. dmic_clk_en_reg = WCD938X_DIGITAL_CDC_DMIC4_CTL;
  1088. dmic_clk_mask = 0xF0;
  1089. dmic_clk_shift = 0x04;
  1090. dmic_ctl_shift = 0x03;
  1091. break;
  1092. default:
  1093. dev_err(component->dev, "%s: Invalid DMIC Selection\n",
  1094. __func__);
  1095. return -EINVAL;
  1096. };
  1097. dev_dbg(component->dev, "%s: event %d DMIC%d dmic_clk_cnt %d\n",
  1098. __func__, event, (w->shift +1), *dmic_clk_cnt);
  1099. switch (event) {
  1100. case SND_SOC_DAPM_PRE_PMU:
  1101. snd_soc_component_update_bits(component,
  1102. WCD938X_DIGITAL_CDC_AMIC_CTL,
  1103. (0x01 << dmic_ctl_shift), 0x00);
  1104. /* 250us sleep as per HW requirement */
  1105. usleep_range(250, 260);
  1106. if (dmic2_left_en)
  1107. snd_soc_component_update_bits(component,
  1108. dmic2_left_en, 0x80, 0x80);
  1109. /* Setting DMIC clock rate to 2.4MHz */
  1110. snd_soc_component_update_bits(component,
  1111. dmic_clk_reg, dmic_clk_mask,
  1112. (0x03 << dmic_clk_shift));
  1113. snd_soc_component_update_bits(component,
  1114. dmic_clk_en_reg, 0x08, 0x08);
  1115. /* enable clock scaling */
  1116. snd_soc_component_update_bits(component,
  1117. WCD938X_DIGITAL_CDC_DMIC_CTL, 0x06, 0x06);
  1118. wcd938x_tx_connect_port(component, DMIC0 + (w->shift), true);
  1119. break;
  1120. case SND_SOC_DAPM_POST_PMD:
  1121. wcd938x_tx_connect_port(component, DMIC0 + (w->shift), false);
  1122. snd_soc_component_update_bits(component,
  1123. WCD938X_DIGITAL_CDC_AMIC_CTL,
  1124. (0x01 << dmic_ctl_shift),
  1125. (0x01 << dmic_ctl_shift));
  1126. if (dmic2_left_en)
  1127. snd_soc_component_update_bits(component,
  1128. dmic2_left_en, 0x80, 0x00);
  1129. snd_soc_component_update_bits(component,
  1130. dmic_clk_en_reg, 0x08, 0x00);
  1131. break;
  1132. };
  1133. return 0;
  1134. }
  1135. /*
  1136. * wcd938x_get_micb_vout_ctl_val: converts micbias from volts to register value
  1137. * @micb_mv: micbias in mv
  1138. *
  1139. * return register value converted
  1140. */
  1141. int wcd938x_get_micb_vout_ctl_val(u32 micb_mv)
  1142. {
  1143. /* min micbias voltage is 1V and maximum is 2.85V */
  1144. if (micb_mv < 1000 || micb_mv > 2850) {
  1145. pr_err("%s: unsupported micbias voltage\n", __func__);
  1146. return -EINVAL;
  1147. }
  1148. return (micb_mv - 1000) / 50;
  1149. }
  1150. EXPORT_SYMBOL(wcd938x_get_micb_vout_ctl_val);
  1151. /*
  1152. * wcd938x_mbhc_micb_adjust_voltage: adjust specific micbias voltage
  1153. * @component: handle to snd_soc_component *
  1154. * @req_volt: micbias voltage to be set
  1155. * @micb_num: micbias to be set, e.g. micbias1 or micbias2
  1156. *
  1157. * return 0 if adjustment is success or error code in case of failure
  1158. */
  1159. int wcd938x_mbhc_micb_adjust_voltage(struct snd_soc_component *component,
  1160. int req_volt, int micb_num)
  1161. {
  1162. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1163. int cur_vout_ctl, req_vout_ctl;
  1164. int micb_reg, micb_val, micb_en;
  1165. int ret = 0;
  1166. switch (micb_num) {
  1167. case MIC_BIAS_1:
  1168. micb_reg = WCD938X_ANA_MICB1;
  1169. break;
  1170. case MIC_BIAS_2:
  1171. micb_reg = WCD938X_ANA_MICB2;
  1172. break;
  1173. case MIC_BIAS_3:
  1174. micb_reg = WCD938X_ANA_MICB3;
  1175. break;
  1176. case MIC_BIAS_4:
  1177. micb_reg = WCD938X_ANA_MICB4;
  1178. break;
  1179. default:
  1180. return -EINVAL;
  1181. }
  1182. mutex_lock(&wcd938x->micb_lock);
  1183. /*
  1184. * If requested micbias voltage is same as current micbias
  1185. * voltage, then just return. Otherwise, adjust voltage as
  1186. * per requested value. If micbias is already enabled, then
  1187. * to avoid slow micbias ramp-up or down enable pull-up
  1188. * momentarily, change the micbias value and then re-enable
  1189. * micbias.
  1190. */
  1191. micb_val = snd_soc_component_read32(component, micb_reg);
  1192. micb_en = (micb_val & 0xC0) >> 6;
  1193. cur_vout_ctl = micb_val & 0x3F;
  1194. req_vout_ctl = wcd938x_get_micb_vout_ctl_val(req_volt);
  1195. if (req_vout_ctl < 0) {
  1196. ret = -EINVAL;
  1197. goto exit;
  1198. }
  1199. if (cur_vout_ctl == req_vout_ctl) {
  1200. ret = 0;
  1201. goto exit;
  1202. }
  1203. dev_dbg(component->dev, "%s: micb_num: %d, cur_mv: %d, req_mv: %d, micb_en: %d\n",
  1204. __func__, micb_num, WCD_VOUT_CTL_TO_MICB(cur_vout_ctl),
  1205. req_volt, micb_en);
  1206. if (micb_en == 0x1)
  1207. snd_soc_component_update_bits(component, micb_reg, 0xC0, 0x80);
  1208. snd_soc_component_update_bits(component, micb_reg, 0x3F, req_vout_ctl);
  1209. if (micb_en == 0x1) {
  1210. snd_soc_component_update_bits(component, micb_reg, 0xC0, 0x40);
  1211. /*
  1212. * Add 2ms delay as per HW requirement after enabling
  1213. * micbias
  1214. */
  1215. usleep_range(2000, 2100);
  1216. }
  1217. exit:
  1218. mutex_unlock(&wcd938x->micb_lock);
  1219. return ret;
  1220. }
  1221. EXPORT_SYMBOL(wcd938x_mbhc_micb_adjust_voltage);
  1222. static int wcd938x_tx_swr_ctrl(struct snd_soc_dapm_widget *w,
  1223. struct snd_kcontrol *kcontrol,
  1224. int event)
  1225. {
  1226. struct snd_soc_component *component =
  1227. snd_soc_dapm_to_component(w->dapm);
  1228. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1229. int ret = 0;
  1230. switch (event) {
  1231. case SND_SOC_DAPM_PRE_PMU:
  1232. ret = swr_slvdev_datapath_control(wcd938x->tx_swr_dev,
  1233. wcd938x->tx_swr_dev->dev_num,
  1234. true);
  1235. break;
  1236. case SND_SOC_DAPM_POST_PMD:
  1237. ret = swr_slvdev_datapath_control(wcd938x->tx_swr_dev,
  1238. wcd938x->tx_swr_dev->dev_num,
  1239. false);
  1240. break;
  1241. };
  1242. return ret;
  1243. }
  1244. static int wcd938x_get_adc_mode(int val)
  1245. {
  1246. int ret = 0;
  1247. switch (val) {
  1248. case ADC_MODE_INVALID:
  1249. ret = ADC_MODE_VAL_NORMAL;
  1250. break;
  1251. case ADC_MODE_HIFI:
  1252. ret = ADC_MODE_VAL_HIFI;
  1253. break;
  1254. case ADC_MODE_LO_HIF:
  1255. ret = ADC_MODE_VAL_LO_HIF;
  1256. break;
  1257. case ADC_MODE_NORMAL:
  1258. ret = ADC_MODE_VAL_NORMAL;
  1259. break;
  1260. case ADC_MODE_LP:
  1261. ret = ADC_MODE_VAL_LP;
  1262. break;
  1263. case ADC_MODE_ULP1:
  1264. ret = ADC_MODE_VAL_ULP1;
  1265. break;
  1266. case ADC_MODE_ULP2:
  1267. ret = ADC_MODE_VAL_ULP2;
  1268. break;
  1269. default:
  1270. ret = -EINVAL;
  1271. pr_err("%s: invalid ADC mode value %d\n", __func__, val);
  1272. break;
  1273. }
  1274. return ret;
  1275. }
  1276. static int wcd938x_codec_enable_adc(struct snd_soc_dapm_widget *w,
  1277. struct snd_kcontrol *kcontrol,
  1278. int event){
  1279. struct snd_soc_component *component =
  1280. snd_soc_dapm_to_component(w->dapm);
  1281. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1282. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1283. w->name, event);
  1284. switch (event) {
  1285. case SND_SOC_DAPM_PRE_PMU:
  1286. snd_soc_component_update_bits(component,
  1287. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x08, 0x08);
  1288. snd_soc_component_update_bits(component,
  1289. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x10, 0x10);
  1290. set_bit(w->shift, &wcd938x->status_mask);
  1291. /* Enable BCS for Headset mic */
  1292. if (w->shift == 1 && !(snd_soc_component_read32(component,
  1293. WCD938X_TX_NEW_AMIC_MUX_CFG) & 0x80)) {
  1294. wcd938x_tx_connect_port(component, MBHC, true);
  1295. set_bit(AMIC2_BCS_ENABLE, &wcd938x->status_mask);
  1296. }
  1297. wcd938x_tx_connect_port(component, ADC1 + (w->shift), true);
  1298. break;
  1299. case SND_SOC_DAPM_POST_PMD:
  1300. wcd938x_tx_connect_port(component, ADC1 + (w->shift), false);
  1301. if (w->shift == 1 &&
  1302. test_bit(AMIC2_BCS_ENABLE, &wcd938x->status_mask)) {
  1303. wcd938x_tx_connect_port(component, MBHC, false);
  1304. clear_bit(AMIC2_BCS_ENABLE, &wcd938x->status_mask);
  1305. }
  1306. snd_soc_component_update_bits(component,
  1307. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x08, 0x00);
  1308. clear_bit(w->shift, &wcd938x->status_mask);
  1309. break;
  1310. };
  1311. return 0;
  1312. }
  1313. int wcd938x_tx_channel_config(struct snd_soc_component *component,
  1314. int channel, int mode)
  1315. {
  1316. int reg = WCD938X_ANA_TX_CH2, mask = 0, val = 0;
  1317. int ret = 0;
  1318. switch (channel) {
  1319. case 0:
  1320. reg = WCD938X_ANA_TX_CH2;
  1321. mask = 0x40;
  1322. break;
  1323. case 1:
  1324. reg = WCD938X_ANA_TX_CH2;
  1325. mask = 0x20;
  1326. break;
  1327. case 2:
  1328. reg = WCD938X_ANA_TX_CH4;
  1329. mask = 0x40;
  1330. break;
  1331. case 3:
  1332. reg = WCD938X_ANA_TX_CH4;
  1333. mask = 0x20;
  1334. break;
  1335. default:
  1336. pr_err("%s: Invalid channel num %d\n", __func__, channel);
  1337. ret = -EINVAL;
  1338. break;
  1339. }
  1340. if (!mode)
  1341. val = 0x00;
  1342. else
  1343. val = mask;
  1344. if (!ret)
  1345. snd_soc_component_update_bits(component, reg, mask, val);
  1346. return ret;
  1347. }
  1348. static int wcd938x_enable_req(struct snd_soc_dapm_widget *w,
  1349. struct snd_kcontrol *kcontrol, int event)
  1350. {
  1351. struct snd_soc_component *component =
  1352. snd_soc_dapm_to_component(w->dapm);
  1353. int mode;
  1354. int ret = 0;
  1355. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1356. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1357. w->name, event);
  1358. switch (event) {
  1359. case SND_SOC_DAPM_PRE_PMU:
  1360. snd_soc_component_update_bits(component,
  1361. WCD938X_DIGITAL_CDC_REQ_CTL, 0x02, 0x02);
  1362. snd_soc_component_update_bits(component,
  1363. WCD938X_DIGITAL_CDC_REQ_CTL, 0x01, 0x00);
  1364. ret = wcd938x_tx_channel_config(component, w->shift, 1);
  1365. mode = wcd938x_get_adc_mode(wcd938x->tx_mode[w->shift]);
  1366. if (mode < 0) {
  1367. dev_info(component->dev,
  1368. "%s: invalid mode, setting to normal mode\n",
  1369. __func__);
  1370. mode = ADC_MODE_VAL_NORMAL;
  1371. }
  1372. switch (w->shift) {
  1373. case 0:
  1374. snd_soc_component_update_bits(component,
  1375. WCD938X_DIGITAL_CDC_TX_ANA_MODE_0_1, 0x0F,
  1376. mode);
  1377. snd_soc_component_update_bits(component,
  1378. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x10, 0x10);
  1379. break;
  1380. case 1:
  1381. snd_soc_component_update_bits(component,
  1382. WCD938X_DIGITAL_CDC_TX_ANA_MODE_0_1, 0xF0,
  1383. mode << 4);
  1384. snd_soc_component_update_bits(component,
  1385. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x20, 0x20);
  1386. break;
  1387. case 2:
  1388. snd_soc_component_update_bits(component,
  1389. WCD938X_DIGITAL_CDC_TX_ANA_MODE_2_3, 0x0F,
  1390. mode);
  1391. snd_soc_component_update_bits(component,
  1392. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x40, 0x40);
  1393. break;
  1394. case 3:
  1395. snd_soc_component_update_bits(component,
  1396. WCD938X_DIGITAL_CDC_TX_ANA_MODE_2_3, 0xF0,
  1397. mode << 4);
  1398. snd_soc_component_update_bits(component,
  1399. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x80, 0x80);
  1400. break;
  1401. default:
  1402. break;
  1403. }
  1404. ret |= wcd938x_tx_channel_config(component, w->shift, 0);
  1405. break;
  1406. case SND_SOC_DAPM_POST_PMD:
  1407. switch (w->shift) {
  1408. case 0:
  1409. snd_soc_component_update_bits(component,
  1410. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x10, 0x00);
  1411. break;
  1412. case 1:
  1413. snd_soc_component_update_bits(component,
  1414. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x20, 0x00);
  1415. break;
  1416. case 2:
  1417. snd_soc_component_update_bits(component,
  1418. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x40, 0x00);
  1419. break;
  1420. case 3:
  1421. snd_soc_component_update_bits(component,
  1422. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x80, 0x00);
  1423. break;
  1424. default:
  1425. break;
  1426. }
  1427. snd_soc_component_update_bits(component,
  1428. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x10, 0x00);
  1429. break;
  1430. };
  1431. return ret;
  1432. }
  1433. int wcd938x_micbias_control(struct snd_soc_component *component,
  1434. int micb_num, int req, bool is_dapm)
  1435. {
  1436. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1437. int micb_index = micb_num - 1;
  1438. u16 micb_reg;
  1439. int pre_off_event = 0, post_off_event = 0;
  1440. int post_on_event = 0, post_dapm_off = 0;
  1441. int post_dapm_on = 0;
  1442. if ((micb_index < 0) || (micb_index > WCD938X_MAX_MICBIAS - 1)) {
  1443. dev_err(component->dev,
  1444. "%s: Invalid micbias index, micb_ind:%d\n",
  1445. __func__, micb_index);
  1446. return -EINVAL;
  1447. }
  1448. if (NULL == wcd938x) {
  1449. dev_err(component->dev,
  1450. "%s: wcd938x private data is NULL\n", __func__);
  1451. return -EINVAL;
  1452. }
  1453. switch (micb_num) {
  1454. case MIC_BIAS_1:
  1455. micb_reg = WCD938X_ANA_MICB1;
  1456. break;
  1457. case MIC_BIAS_2:
  1458. micb_reg = WCD938X_ANA_MICB2;
  1459. pre_off_event = WCD_EVENT_PRE_MICBIAS_2_OFF;
  1460. post_off_event = WCD_EVENT_POST_MICBIAS_2_OFF;
  1461. post_on_event = WCD_EVENT_POST_MICBIAS_2_ON;
  1462. post_dapm_on = WCD_EVENT_POST_DAPM_MICBIAS_2_ON;
  1463. post_dapm_off = WCD_EVENT_POST_DAPM_MICBIAS_2_OFF;
  1464. break;
  1465. case MIC_BIAS_3:
  1466. micb_reg = WCD938X_ANA_MICB3;
  1467. break;
  1468. case MIC_BIAS_4:
  1469. micb_reg = WCD938X_ANA_MICB4;
  1470. break;
  1471. default:
  1472. dev_err(component->dev, "%s: Invalid micbias number: %d\n",
  1473. __func__, micb_num);
  1474. return -EINVAL;
  1475. };
  1476. mutex_lock(&wcd938x->micb_lock);
  1477. switch (req) {
  1478. case MICB_PULLUP_ENABLE:
  1479. wcd938x->pullup_ref[micb_index]++;
  1480. if ((wcd938x->pullup_ref[micb_index] == 1) &&
  1481. (wcd938x->micb_ref[micb_index] == 0))
  1482. snd_soc_component_update_bits(component, micb_reg,
  1483. 0xC0, 0x80);
  1484. break;
  1485. case MICB_PULLUP_DISABLE:
  1486. if (wcd938x->pullup_ref[micb_index] > 0)
  1487. wcd938x->pullup_ref[micb_index]--;
  1488. if ((wcd938x->pullup_ref[micb_index] == 0) &&
  1489. (wcd938x->micb_ref[micb_index] == 0))
  1490. snd_soc_component_update_bits(component, micb_reg,
  1491. 0xC0, 0x00);
  1492. break;
  1493. case MICB_ENABLE:
  1494. wcd938x->micb_ref[micb_index]++;
  1495. if (wcd938x->micb_ref[micb_index] == 1) {
  1496. snd_soc_component_update_bits(component,
  1497. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0xE0, 0xE0);
  1498. snd_soc_component_update_bits(component,
  1499. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x10, 0x10);
  1500. snd_soc_component_update_bits(component,
  1501. WCD938X_DIGITAL_CDC_ANA_TX_CLK_CTL, 0x01, 0x01);
  1502. snd_soc_component_update_bits(component,
  1503. WCD938X_MICB1_TEST_CTL_2, 0x01, 0x01);
  1504. snd_soc_component_update_bits(component,
  1505. WCD938X_MICB2_TEST_CTL_2, 0x01, 0x01);
  1506. snd_soc_component_update_bits(component,
  1507. WCD938X_MICB3_TEST_CTL_2, 0x01, 0x01);
  1508. snd_soc_component_update_bits(component,
  1509. WCD938X_MICB4_TEST_CTL_2, 0x01, 0x01);
  1510. snd_soc_component_update_bits(component,
  1511. micb_reg, 0xC0, 0x40);
  1512. if (post_on_event)
  1513. blocking_notifier_call_chain(
  1514. &wcd938x->mbhc->notifier,
  1515. post_on_event,
  1516. &wcd938x->mbhc->wcd_mbhc);
  1517. }
  1518. if (is_dapm && post_dapm_on && wcd938x->mbhc)
  1519. blocking_notifier_call_chain(&wcd938x->mbhc->notifier,
  1520. post_dapm_on,
  1521. &wcd938x->mbhc->wcd_mbhc);
  1522. break;
  1523. case MICB_DISABLE:
  1524. if (wcd938x->micb_ref[micb_index] > 0)
  1525. wcd938x->micb_ref[micb_index]--;
  1526. if ((wcd938x->micb_ref[micb_index] == 0) &&
  1527. (wcd938x->pullup_ref[micb_index] > 0))
  1528. snd_soc_component_update_bits(component, micb_reg,
  1529. 0xC0, 0x80);
  1530. else if ((wcd938x->micb_ref[micb_index] == 0) &&
  1531. (wcd938x->pullup_ref[micb_index] == 0)) {
  1532. if (pre_off_event && wcd938x->mbhc)
  1533. blocking_notifier_call_chain(
  1534. &wcd938x->mbhc->notifier,
  1535. pre_off_event,
  1536. &wcd938x->mbhc->wcd_mbhc);
  1537. snd_soc_component_update_bits(component, micb_reg,
  1538. 0xC0, 0x00);
  1539. if (post_off_event && wcd938x->mbhc)
  1540. blocking_notifier_call_chain(
  1541. &wcd938x->mbhc->notifier,
  1542. post_off_event,
  1543. &wcd938x->mbhc->wcd_mbhc);
  1544. }
  1545. if (is_dapm && post_dapm_off && wcd938x->mbhc)
  1546. blocking_notifier_call_chain(&wcd938x->mbhc->notifier,
  1547. post_dapm_off,
  1548. &wcd938x->mbhc->wcd_mbhc);
  1549. break;
  1550. };
  1551. dev_dbg(component->dev,
  1552. "%s: micb_num:%d, micb_ref: %d, pullup_ref: %d\n",
  1553. __func__, micb_num, wcd938x->micb_ref[micb_index],
  1554. wcd938x->pullup_ref[micb_index]);
  1555. mutex_unlock(&wcd938x->micb_lock);
  1556. return 0;
  1557. }
  1558. EXPORT_SYMBOL(wcd938x_micbias_control);
  1559. static int wcd938x_get_logical_addr(struct swr_device *swr_dev)
  1560. {
  1561. int ret = 0;
  1562. uint8_t devnum = 0;
  1563. ret = swr_get_logical_dev_num(swr_dev, swr_dev->addr, &devnum);
  1564. if (ret) {
  1565. dev_err(&swr_dev->dev,
  1566. "%s get devnum %d for dev addr %lx failed\n",
  1567. __func__, devnum, swr_dev->addr);
  1568. swr_remove_device(swr_dev);
  1569. return ret;
  1570. }
  1571. swr_dev->dev_num = devnum;
  1572. return 0;
  1573. }
  1574. static int wcd938x_event_notify(struct notifier_block *block,
  1575. unsigned long val,
  1576. void *data)
  1577. {
  1578. u16 event = (val & 0xffff);
  1579. int ret = 0;
  1580. struct wcd938x_priv *wcd938x = dev_get_drvdata((struct device *)data);
  1581. struct snd_soc_component *component = wcd938x->component;
  1582. struct wcd_mbhc *mbhc;
  1583. switch (event) {
  1584. case BOLERO_WCD_EVT_TX_CH_HOLD_CLEAR:
  1585. if (test_bit(WCD_ADC1, &wcd938x->status_mask)) {
  1586. snd_soc_component_update_bits(component,
  1587. WCD938X_ANA_TX_CH2, 0x40, 0x00);
  1588. clear_bit(WCD_ADC1, &wcd938x->status_mask);
  1589. }
  1590. if (test_bit(WCD_ADC2, &wcd938x->status_mask)) {
  1591. snd_soc_component_update_bits(component,
  1592. WCD938X_ANA_TX_CH2, 0x20, 0x00);
  1593. clear_bit(WCD_ADC2, &wcd938x->status_mask);
  1594. }
  1595. if (test_bit(WCD_ADC3, &wcd938x->status_mask)) {
  1596. snd_soc_component_update_bits(component,
  1597. WCD938X_ANA_TX_CH4, 0x40, 0x00);
  1598. clear_bit(WCD_ADC3, &wcd938x->status_mask);
  1599. }
  1600. if (test_bit(WCD_ADC4, &wcd938x->status_mask)) {
  1601. snd_soc_component_update_bits(component,
  1602. WCD938X_ANA_TX_CH4, 0x20, 0x00);
  1603. clear_bit(WCD_ADC4, &wcd938x->status_mask);
  1604. }
  1605. break;
  1606. case BOLERO_WCD_EVT_PA_OFF_PRE_SSR:
  1607. snd_soc_component_update_bits(component, WCD938X_ANA_HPH,
  1608. 0xC0, 0x00);
  1609. snd_soc_component_update_bits(component, WCD938X_ANA_EAR,
  1610. 0x80, 0x00);
  1611. snd_soc_component_update_bits(component, WCD938X_AUX_AUXPA,
  1612. 0x80, 0x00);
  1613. break;
  1614. case BOLERO_WCD_EVT_SSR_DOWN:
  1615. mbhc = &wcd938x->mbhc->wcd_mbhc;
  1616. wcd938x_mbhc_ssr_down(wcd938x->mbhc, component);
  1617. wcd938x_reset_low(wcd938x->dev);
  1618. break;
  1619. case BOLERO_WCD_EVT_SSR_UP:
  1620. wcd938x_reset(wcd938x->dev);
  1621. wcd938x_get_logical_addr(wcd938x->tx_swr_dev);
  1622. wcd938x_get_logical_addr(wcd938x->rx_swr_dev);
  1623. wcd938x_init_reg(component);
  1624. regcache_mark_dirty(wcd938x->regmap);
  1625. regcache_sync(wcd938x->regmap);
  1626. /* Initialize MBHC module */
  1627. mbhc = &wcd938x->mbhc->wcd_mbhc;
  1628. ret = wcd938x_mbhc_post_ssr_init(wcd938x->mbhc, component);
  1629. if (ret) {
  1630. dev_err(component->dev, "%s: mbhc initialization failed\n",
  1631. __func__);
  1632. } else {
  1633. wcd938x_mbhc_hs_detect(component, mbhc->mbhc_cfg);
  1634. }
  1635. break;
  1636. case BOLERO_WCD_EVT_CLK_NOTIFY:
  1637. snd_soc_component_update_bits(component,
  1638. WCD938X_DIGITAL_TOP_CLK_CFG, 0x06,
  1639. ((val >> 0x10) << 0x01));
  1640. break;
  1641. default:
  1642. dev_dbg(component->dev, "%s: invalid event %d\n", __func__, event);
  1643. break;
  1644. }
  1645. return 0;
  1646. }
  1647. static int __wcd938x_codec_enable_micbias(struct snd_soc_dapm_widget *w,
  1648. int event)
  1649. {
  1650. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  1651. int micb_num;
  1652. dev_dbg(component->dev, "%s: wname: %s, event: %d\n",
  1653. __func__, w->name, event);
  1654. if (strnstr(w->name, "MIC BIAS1", sizeof("MIC BIAS1")))
  1655. micb_num = MIC_BIAS_1;
  1656. else if (strnstr(w->name, "MIC BIAS2", sizeof("MIC BIAS2")))
  1657. micb_num = MIC_BIAS_2;
  1658. else if (strnstr(w->name, "MIC BIAS3", sizeof("MIC BIAS3")))
  1659. micb_num = MIC_BIAS_3;
  1660. else if (strnstr(w->name, "MIC BIAS4", sizeof("MIC BIAS4")))
  1661. micb_num = MIC_BIAS_4;
  1662. else
  1663. return -EINVAL;
  1664. switch (event) {
  1665. case SND_SOC_DAPM_PRE_PMU:
  1666. wcd938x_micbias_control(component, micb_num,
  1667. MICB_ENABLE, true);
  1668. break;
  1669. case SND_SOC_DAPM_POST_PMU:
  1670. /* 1 msec delay as per HW requirement */
  1671. usleep_range(1000, 1100);
  1672. break;
  1673. case SND_SOC_DAPM_POST_PMD:
  1674. wcd938x_micbias_control(component, micb_num,
  1675. MICB_DISABLE, true);
  1676. break;
  1677. };
  1678. return 0;
  1679. }
  1680. static int wcd938x_codec_enable_micbias(struct snd_soc_dapm_widget *w,
  1681. struct snd_kcontrol *kcontrol,
  1682. int event)
  1683. {
  1684. return __wcd938x_codec_enable_micbias(w, event);
  1685. }
  1686. static int __wcd938x_codec_enable_micbias_pullup(struct snd_soc_dapm_widget *w,
  1687. int event)
  1688. {
  1689. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  1690. int micb_num;
  1691. dev_dbg(component->dev, "%s: wname: %s, event: %d\n",
  1692. __func__, w->name, event);
  1693. if (strnstr(w->name, "VA MIC BIAS1", sizeof("VA MIC BIAS1")))
  1694. micb_num = MIC_BIAS_1;
  1695. else if (strnstr(w->name, "VA MIC BIAS2", sizeof("VA MIC BIAS2")))
  1696. micb_num = MIC_BIAS_2;
  1697. else if (strnstr(w->name, "VA MIC BIAS3", sizeof("VA MIC BIAS3")))
  1698. micb_num = MIC_BIAS_3;
  1699. else if (strnstr(w->name, "VA MIC BIAS4", sizeof("VA MIC BIAS4")))
  1700. micb_num = MIC_BIAS_4;
  1701. else
  1702. return -EINVAL;
  1703. switch (event) {
  1704. case SND_SOC_DAPM_PRE_PMU:
  1705. wcd938x_micbias_control(component, micb_num,
  1706. MICB_PULLUP_ENABLE, true);
  1707. break;
  1708. case SND_SOC_DAPM_POST_PMU:
  1709. /* 1 msec delay as per HW requirement */
  1710. usleep_range(1000, 1100);
  1711. break;
  1712. case SND_SOC_DAPM_POST_PMD:
  1713. wcd938x_micbias_control(component, micb_num,
  1714. MICB_PULLUP_DISABLE, true);
  1715. break;
  1716. };
  1717. return 0;
  1718. }
  1719. static int wcd938x_codec_enable_micbias_pullup(struct snd_soc_dapm_widget *w,
  1720. struct snd_kcontrol *kcontrol,
  1721. int event)
  1722. {
  1723. return __wcd938x_codec_enable_micbias_pullup(w, event);
  1724. }
  1725. static inline int wcd938x_tx_path_get(const char *wname,
  1726. unsigned int *path_num)
  1727. {
  1728. int ret = 0;
  1729. char *widget_name = NULL;
  1730. char *w_name = NULL;
  1731. char *path_num_char = NULL;
  1732. char *path_name = NULL;
  1733. widget_name = kstrndup(wname, 9, GFP_KERNEL);
  1734. if (!widget_name)
  1735. return -EINVAL;
  1736. w_name = widget_name;
  1737. path_name = strsep(&widget_name, " ");
  1738. if (!path_name) {
  1739. pr_err("%s: Invalid widget name = %s\n",
  1740. __func__, widget_name);
  1741. ret = -EINVAL;
  1742. goto err;
  1743. }
  1744. path_num_char = strpbrk(path_name, "0123");
  1745. if (!path_num_char) {
  1746. pr_err("%s: tx path index not found\n",
  1747. __func__);
  1748. ret = -EINVAL;
  1749. goto err;
  1750. }
  1751. ret = kstrtouint(path_num_char, 10, path_num);
  1752. if (ret < 0)
  1753. pr_err("%s: Invalid tx path = %s\n",
  1754. __func__, w_name);
  1755. err:
  1756. kfree(w_name);
  1757. return ret;
  1758. }
  1759. static int wcd938x_tx_mode_get(struct snd_kcontrol *kcontrol,
  1760. struct snd_ctl_elem_value *ucontrol)
  1761. {
  1762. struct snd_soc_component *component =
  1763. snd_soc_kcontrol_component(kcontrol);
  1764. struct wcd938x_priv *wcd938x = NULL;
  1765. int ret = 0;
  1766. unsigned int path = 0;
  1767. if (!component)
  1768. return -EINVAL;
  1769. wcd938x = snd_soc_component_get_drvdata(component);
  1770. if (!wcd938x)
  1771. return -EINVAL;
  1772. ret = wcd938x_tx_path_get(kcontrol->id.name, &path);
  1773. if (ret < 0)
  1774. return ret;
  1775. ucontrol->value.integer.value[0] = wcd938x->tx_mode[path];
  1776. return 0;
  1777. }
  1778. static int wcd938x_tx_mode_put(struct snd_kcontrol *kcontrol,
  1779. struct snd_ctl_elem_value *ucontrol)
  1780. {
  1781. struct snd_soc_component *component =
  1782. snd_soc_kcontrol_component(kcontrol);
  1783. struct wcd938x_priv *wcd938x = NULL;
  1784. u32 mode_val;
  1785. unsigned int path = 0;
  1786. int ret = 0;
  1787. if (!component)
  1788. return -EINVAL;
  1789. wcd938x = snd_soc_component_get_drvdata(component);
  1790. if (!wcd938x)
  1791. return -EINVAL;
  1792. ret = wcd938x_tx_path_get(kcontrol->id.name, &path);
  1793. if (ret)
  1794. return ret;
  1795. mode_val = ucontrol->value.enumerated.item[0];
  1796. dev_dbg(component->dev, "%s: mode: %d\n", __func__, mode_val);
  1797. wcd938x->tx_mode[path] = mode_val;
  1798. return 0;
  1799. }
  1800. static int wcd938x_rx_hph_mode_get(struct snd_kcontrol *kcontrol,
  1801. struct snd_ctl_elem_value *ucontrol)
  1802. {
  1803. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1804. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1805. ucontrol->value.integer.value[0] = wcd938x->hph_mode;
  1806. return 0;
  1807. }
  1808. static int wcd938x_rx_hph_mode_put(struct snd_kcontrol *kcontrol,
  1809. struct snd_ctl_elem_value *ucontrol)
  1810. {
  1811. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1812. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1813. u32 mode_val;
  1814. mode_val = ucontrol->value.enumerated.item[0];
  1815. dev_dbg(component->dev, "%s: mode: %d\n", __func__, mode_val);
  1816. if (wcd938x->variant == WCD9380) {
  1817. if (mode_val == CLS_H_HIFI || mode_val == CLS_AB_HIFI) {
  1818. dev_info(component->dev,
  1819. "%s:Invalid HPH Mode, default to CLS_H_ULP\n",
  1820. __func__);
  1821. mode_val = CLS_H_ULP;
  1822. }
  1823. }
  1824. if (mode_val == CLS_H_NORMAL) {
  1825. dev_info(component->dev,
  1826. "%s:Invalid HPH Mode, default to class_AB\n",
  1827. __func__);
  1828. mode_val = CLS_H_ULP;
  1829. }
  1830. wcd938x->hph_mode = mode_val;
  1831. return 0;
  1832. }
  1833. static int wcd938x_get_compander(struct snd_kcontrol *kcontrol,
  1834. struct snd_ctl_elem_value *ucontrol)
  1835. {
  1836. struct snd_soc_component *component =
  1837. snd_soc_kcontrol_component(kcontrol);
  1838. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1839. bool hphr;
  1840. struct soc_multi_mixer_control *mc;
  1841. mc = (struct soc_multi_mixer_control *)(kcontrol->private_value);
  1842. hphr = mc->shift;
  1843. ucontrol->value.integer.value[0] = hphr ? wcd938x->comp2_enable :
  1844. wcd938x->comp1_enable;
  1845. return 0;
  1846. }
  1847. static int wcd938x_set_compander(struct snd_kcontrol *kcontrol,
  1848. struct snd_ctl_elem_value *ucontrol)
  1849. {
  1850. struct snd_soc_component *component =
  1851. snd_soc_kcontrol_component(kcontrol);
  1852. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1853. int value = ucontrol->value.integer.value[0];
  1854. bool hphr;
  1855. struct soc_multi_mixer_control *mc;
  1856. mc = (struct soc_multi_mixer_control *)(kcontrol->private_value);
  1857. hphr = mc->shift;
  1858. if (hphr)
  1859. wcd938x->comp2_enable = value;
  1860. else
  1861. wcd938x->comp1_enable = value;
  1862. return 0;
  1863. }
  1864. static int wcd938x_ldoh_get(struct snd_kcontrol *kcontrol,
  1865. struct snd_ctl_elem_value *ucontrol)
  1866. {
  1867. struct snd_soc_component *component =
  1868. snd_soc_kcontrol_component(kcontrol);
  1869. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1870. ucontrol->value.integer.value[0] = wcd938x->ldoh;
  1871. return 0;
  1872. }
  1873. static int wcd938x_ldoh_put(struct snd_kcontrol *kcontrol,
  1874. struct snd_ctl_elem_value *ucontrol)
  1875. {
  1876. struct snd_soc_component *component =
  1877. snd_soc_kcontrol_component(kcontrol);
  1878. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1879. wcd938x->ldoh = ucontrol->value.integer.value[0];
  1880. return 0;
  1881. }
  1882. static const char * const tx_mode_mux_text_wcd9380[] = {
  1883. "ADC_INVALID", "ADC_HIFI", "ADC_LO_HIF", "ADC_NORMAL", "ADC_LP",
  1884. };
  1885. static const struct soc_enum tx_mode_mux_enum_wcd9380 =
  1886. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(tx_mode_mux_text_wcd9380),
  1887. tx_mode_mux_text_wcd9380);
  1888. static const char * const tx_mode_mux_text[] = {
  1889. "ADC_INVALID", "ADC_HIFI", "ADC_LO_HIF", "ADC_NORMAL", "ADC_LP",
  1890. "ADC_ULP1", "ADC_ULP2",
  1891. };
  1892. static const struct soc_enum tx_mode_mux_enum =
  1893. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(tx_mode_mux_text),
  1894. tx_mode_mux_text);
  1895. static const char * const rx_hph_mode_mux_text_wcd9380[] = {
  1896. "CLS_H_INVALID", "CLS_H_INVALID_1", "CLS_H_LP", "CLS_AB",
  1897. "CLS_H_LOHIFI", "CLS_H_ULP", "CLS_H_INVALID_2", "CLS_AB_LP",
  1898. "CLS_AB_LOHIFI",
  1899. };
  1900. static const struct soc_enum rx_hph_mode_mux_enum_wcd9380 =
  1901. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(rx_hph_mode_mux_text_wcd9380),
  1902. rx_hph_mode_mux_text_wcd9380);
  1903. static const char * const rx_hph_mode_mux_text[] = {
  1904. "CLS_H_INVALID", "CLS_H_HIFI", "CLS_H_LP", "CLS_AB", "CLS_H_LOHIFI",
  1905. "CLS_H_ULP", "CLS_AB_HIFI", "CLS_AB_LP", "CLS_AB_LOHIFI",
  1906. };
  1907. static const struct soc_enum rx_hph_mode_mux_enum =
  1908. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(rx_hph_mode_mux_text),
  1909. rx_hph_mode_mux_text);
  1910. static const struct snd_kcontrol_new wcd9380_snd_controls[] = {
  1911. SOC_ENUM_EXT("RX HPH Mode", rx_hph_mode_mux_enum_wcd9380,
  1912. wcd938x_rx_hph_mode_get, wcd938x_rx_hph_mode_put),
  1913. SOC_ENUM_EXT("TX0 MODE", tx_mode_mux_enum_wcd9380,
  1914. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  1915. SOC_ENUM_EXT("TX1 MODE", tx_mode_mux_enum_wcd9380,
  1916. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  1917. SOC_ENUM_EXT("TX2 MODE", tx_mode_mux_enum_wcd9380,
  1918. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  1919. SOC_ENUM_EXT("TX3 MODE", tx_mode_mux_enum_wcd9380,
  1920. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  1921. };
  1922. static const struct snd_kcontrol_new wcd9385_snd_controls[] = {
  1923. SOC_ENUM_EXT("RX HPH Mode", rx_hph_mode_mux_enum,
  1924. wcd938x_rx_hph_mode_get, wcd938x_rx_hph_mode_put),
  1925. SOC_ENUM_EXT("TX0 MODE", tx_mode_mux_enum,
  1926. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  1927. SOC_ENUM_EXT("TX1 MODE", tx_mode_mux_enum,
  1928. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  1929. SOC_ENUM_EXT("TX2 MODE", tx_mode_mux_enum,
  1930. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  1931. SOC_ENUM_EXT("TX3 MODE", tx_mode_mux_enum,
  1932. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  1933. };
  1934. static const struct snd_kcontrol_new wcd938x_snd_controls[] = {
  1935. SOC_SINGLE_EXT("HPHL_COMP Switch", SND_SOC_NOPM, 0, 1, 0,
  1936. wcd938x_get_compander, wcd938x_set_compander),
  1937. SOC_SINGLE_EXT("HPHR_COMP Switch", SND_SOC_NOPM, 1, 1, 0,
  1938. wcd938x_get_compander, wcd938x_set_compander),
  1939. SOC_SINGLE_EXT("LDOH Enable", SND_SOC_NOPM, 0, 1, 0,
  1940. wcd938x_ldoh_get, wcd938x_ldoh_put),
  1941. SOC_SINGLE_TLV("HPHL Volume", WCD938X_HPH_L_EN, 0, 20, 1, line_gain),
  1942. SOC_SINGLE_TLV("HPHR Volume", WCD938X_HPH_R_EN, 0, 20, 1, line_gain),
  1943. SOC_SINGLE_TLV("ADC1 Volume", WCD938X_ANA_TX_CH1, 0, 20, 0,
  1944. analog_gain),
  1945. SOC_SINGLE_TLV("ADC2 Volume", WCD938X_ANA_TX_CH2, 0, 20, 0,
  1946. analog_gain),
  1947. SOC_SINGLE_TLV("ADC3 Volume", WCD938X_ANA_TX_CH3, 0, 20, 0,
  1948. analog_gain),
  1949. SOC_SINGLE_TLV("ADC4 Volume", WCD938X_ANA_TX_CH4, 0, 20, 0,
  1950. analog_gain),
  1951. };
  1952. static const struct snd_kcontrol_new adc1_switch[] = {
  1953. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1954. };
  1955. static const struct snd_kcontrol_new adc2_switch[] = {
  1956. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1957. };
  1958. static const struct snd_kcontrol_new adc3_switch[] = {
  1959. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1960. };
  1961. static const struct snd_kcontrol_new adc4_switch[] = {
  1962. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1963. };
  1964. static const struct snd_kcontrol_new dmic1_switch[] = {
  1965. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1966. };
  1967. static const struct snd_kcontrol_new dmic2_switch[] = {
  1968. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1969. };
  1970. static const struct snd_kcontrol_new dmic3_switch[] = {
  1971. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1972. };
  1973. static const struct snd_kcontrol_new dmic4_switch[] = {
  1974. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1975. };
  1976. static const struct snd_kcontrol_new dmic5_switch[] = {
  1977. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1978. };
  1979. static const struct snd_kcontrol_new dmic6_switch[] = {
  1980. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1981. };
  1982. static const struct snd_kcontrol_new dmic7_switch[] = {
  1983. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1984. };
  1985. static const struct snd_kcontrol_new dmic8_switch[] = {
  1986. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1987. };
  1988. static const struct snd_kcontrol_new ear_rdac_switch[] = {
  1989. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1990. };
  1991. static const struct snd_kcontrol_new aux_rdac_switch[] = {
  1992. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1993. };
  1994. static const struct snd_kcontrol_new hphl_rdac_switch[] = {
  1995. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1996. };
  1997. static const struct snd_kcontrol_new hphr_rdac_switch[] = {
  1998. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1999. };
  2000. static const char * const adc2_mux_text[] = {
  2001. "INP2", "INP3"
  2002. };
  2003. static const struct soc_enum adc2_enum =
  2004. SOC_ENUM_SINGLE(WCD938X_TX_NEW_AMIC_MUX_CFG, 7,
  2005. ARRAY_SIZE(adc2_mux_text), adc2_mux_text);
  2006. static const struct snd_kcontrol_new tx_adc2_mux =
  2007. SOC_DAPM_ENUM("ADC2 MUX Mux", adc2_enum);
  2008. static const char * const adc3_mux_text[] = {
  2009. "INP4", "INP6"
  2010. };
  2011. static const struct soc_enum adc3_enum =
  2012. SOC_ENUM_SINGLE(WCD938X_TX_NEW_AMIC_MUX_CFG, 6,
  2013. ARRAY_SIZE(adc3_mux_text), adc3_mux_text);
  2014. static const struct snd_kcontrol_new tx_adc3_mux =
  2015. SOC_DAPM_ENUM("ADC3 MUX Mux", adc3_enum);
  2016. static const char * const adc4_mux_text[] = {
  2017. "INP5", "INP7"
  2018. };
  2019. static const struct soc_enum adc4_enum =
  2020. SOC_ENUM_SINGLE(WCD938X_TX_NEW_AMIC_MUX_CFG, 5,
  2021. ARRAY_SIZE(adc4_mux_text), adc4_mux_text);
  2022. static const struct snd_kcontrol_new tx_adc4_mux =
  2023. SOC_DAPM_ENUM("ADC4 MUX Mux", adc4_enum);
  2024. static const char * const rdac3_mux_text[] = {
  2025. "RX1", "RX3"
  2026. };
  2027. static const char * const hdr12_mux_text[] = {
  2028. "NO_HDR12", "HDR12"
  2029. };
  2030. static const struct soc_enum hdr12_enum =
  2031. SOC_ENUM_SINGLE(WCD938X_TX_NEW_AMIC_MUX_CFG, 4,
  2032. ARRAY_SIZE(hdr12_mux_text), hdr12_mux_text);
  2033. static const struct snd_kcontrol_new tx_hdr12_mux =
  2034. SOC_DAPM_ENUM("HDR12 MUX Mux", hdr12_enum);
  2035. static const char * const hdr34_mux_text[] = {
  2036. "NO_HDR34", "HDR34"
  2037. };
  2038. static const struct soc_enum hdr34_enum =
  2039. SOC_ENUM_SINGLE(WCD938X_TX_NEW_AMIC_MUX_CFG, 3,
  2040. ARRAY_SIZE(hdr34_mux_text), hdr34_mux_text);
  2041. static const struct snd_kcontrol_new tx_hdr34_mux =
  2042. SOC_DAPM_ENUM("HDR34 MUX Mux", hdr34_enum);
  2043. static const struct soc_enum rdac3_enum =
  2044. SOC_ENUM_SINGLE(WCD938X_DIGITAL_CDC_EAR_PATH_CTL, 0,
  2045. ARRAY_SIZE(rdac3_mux_text), rdac3_mux_text);
  2046. static const struct snd_kcontrol_new rx_rdac3_mux =
  2047. SOC_DAPM_ENUM("RDAC3_MUX Mux", rdac3_enum);
  2048. static const struct snd_soc_dapm_widget wcd938x_dapm_widgets[] = {
  2049. /*input widgets*/
  2050. SND_SOC_DAPM_INPUT("AMIC1"),
  2051. SND_SOC_DAPM_INPUT("AMIC2"),
  2052. SND_SOC_DAPM_INPUT("AMIC3"),
  2053. SND_SOC_DAPM_INPUT("AMIC4"),
  2054. SND_SOC_DAPM_INPUT("AMIC5"),
  2055. SND_SOC_DAPM_INPUT("AMIC6"),
  2056. SND_SOC_DAPM_INPUT("AMIC7"),
  2057. SND_SOC_DAPM_INPUT("IN1_HPHL"),
  2058. SND_SOC_DAPM_INPUT("IN2_HPHR"),
  2059. SND_SOC_DAPM_INPUT("IN3_AUX"),
  2060. /*tx widgets*/
  2061. SND_SOC_DAPM_ADC_E("ADC1", NULL, SND_SOC_NOPM, 0, 0,
  2062. wcd938x_codec_enable_adc,
  2063. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2064. SND_SOC_DAPM_ADC_E("ADC2", NULL, SND_SOC_NOPM, 1, 0,
  2065. wcd938x_codec_enable_adc,
  2066. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2067. SND_SOC_DAPM_ADC_E("ADC3", NULL, SND_SOC_NOPM, 2, 0,
  2068. wcd938x_codec_enable_adc,
  2069. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2070. SND_SOC_DAPM_ADC_E("ADC4", NULL, SND_SOC_NOPM, 3, 0,
  2071. wcd938x_codec_enable_adc,
  2072. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2073. SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 0, 0,
  2074. wcd938x_codec_enable_dmic,
  2075. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2076. SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 1, 0,
  2077. wcd938x_codec_enable_dmic,
  2078. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2079. SND_SOC_DAPM_ADC_E("DMIC3", NULL, SND_SOC_NOPM, 2, 0,
  2080. wcd938x_codec_enable_dmic,
  2081. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2082. SND_SOC_DAPM_ADC_E("DMIC4", NULL, SND_SOC_NOPM, 3, 0,
  2083. wcd938x_codec_enable_dmic,
  2084. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2085. SND_SOC_DAPM_ADC_E("DMIC5", NULL, SND_SOC_NOPM, 4, 0,
  2086. wcd938x_codec_enable_dmic,
  2087. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2088. SND_SOC_DAPM_ADC_E("DMIC6", NULL, SND_SOC_NOPM, 5, 0,
  2089. wcd938x_codec_enable_dmic,
  2090. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2091. SND_SOC_DAPM_ADC_E("DMIC7", NULL, SND_SOC_NOPM, 6, 0,
  2092. wcd938x_codec_enable_dmic,
  2093. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2094. SND_SOC_DAPM_ADC_E("DMIC8", NULL, SND_SOC_NOPM, 7, 0,
  2095. wcd938x_codec_enable_dmic,
  2096. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2097. SND_SOC_DAPM_MIXER_E("ADC1 REQ", SND_SOC_NOPM, 0, 0,
  2098. NULL, 0, wcd938x_enable_req,
  2099. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2100. SND_SOC_DAPM_MIXER_E("ADC2 REQ", SND_SOC_NOPM, 1, 0,
  2101. NULL, 0, wcd938x_enable_req,
  2102. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2103. SND_SOC_DAPM_MIXER_E("ADC3 REQ", SND_SOC_NOPM, 2, 0,
  2104. NULL, 0, wcd938x_enable_req,
  2105. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2106. SND_SOC_DAPM_MIXER_E("ADC4 REQ", SND_SOC_NOPM, 3, 0,
  2107. NULL, 0, wcd938x_enable_req,
  2108. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2109. SND_SOC_DAPM_MUX("ADC2 MUX", SND_SOC_NOPM, 0, 0,
  2110. &tx_adc2_mux),
  2111. SND_SOC_DAPM_MUX("ADC3 MUX", SND_SOC_NOPM, 0, 0,
  2112. &tx_adc3_mux),
  2113. SND_SOC_DAPM_MUX("ADC4 MUX", SND_SOC_NOPM, 0, 0,
  2114. &tx_adc4_mux),
  2115. SND_SOC_DAPM_MUX("HDR12 MUX", SND_SOC_NOPM, 0, 0,
  2116. &tx_hdr12_mux),
  2117. SND_SOC_DAPM_MUX("HDR34 MUX", SND_SOC_NOPM, 0, 0,
  2118. &tx_hdr34_mux),
  2119. /*tx mixers*/
  2120. SND_SOC_DAPM_MIXER_E("ADC1_MIXER", SND_SOC_NOPM, 0, 0,
  2121. adc1_switch, ARRAY_SIZE(adc1_switch),
  2122. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  2123. SND_SOC_DAPM_POST_PMD),
  2124. SND_SOC_DAPM_MIXER_E("ADC2_MIXER", SND_SOC_NOPM, 0, 0,
  2125. adc2_switch, ARRAY_SIZE(adc2_switch),
  2126. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  2127. SND_SOC_DAPM_POST_PMD),
  2128. SND_SOC_DAPM_MIXER_E("ADC3_MIXER", SND_SOC_NOPM, 0, 0, adc3_switch,
  2129. ARRAY_SIZE(adc3_switch), wcd938x_tx_swr_ctrl,
  2130. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2131. SND_SOC_DAPM_MIXER_E("ADC4_MIXER", SND_SOC_NOPM, 0, 0, adc4_switch,
  2132. ARRAY_SIZE(adc4_switch), wcd938x_tx_swr_ctrl,
  2133. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2134. SND_SOC_DAPM_MIXER_E("DMIC1_MIXER", SND_SOC_NOPM, 0,
  2135. 0, dmic1_switch, ARRAY_SIZE(dmic1_switch),
  2136. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  2137. SND_SOC_DAPM_POST_PMD),
  2138. SND_SOC_DAPM_MIXER_E("DMIC2_MIXER", SND_SOC_NOPM, 0,
  2139. 0, dmic2_switch, ARRAY_SIZE(dmic2_switch),
  2140. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  2141. SND_SOC_DAPM_POST_PMD),
  2142. SND_SOC_DAPM_MIXER_E("DMIC3_MIXER", SND_SOC_NOPM, 0,
  2143. 0, dmic3_switch, ARRAY_SIZE(dmic3_switch),
  2144. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  2145. SND_SOC_DAPM_POST_PMD),
  2146. SND_SOC_DAPM_MIXER_E("DMIC4_MIXER", SND_SOC_NOPM, 0,
  2147. 0, dmic4_switch, ARRAY_SIZE(dmic4_switch),
  2148. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  2149. SND_SOC_DAPM_POST_PMD),
  2150. SND_SOC_DAPM_MIXER_E("DMIC5_MIXER", SND_SOC_NOPM, 0,
  2151. 0, dmic5_switch, ARRAY_SIZE(dmic5_switch),
  2152. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  2153. SND_SOC_DAPM_POST_PMD),
  2154. SND_SOC_DAPM_MIXER_E("DMIC6_MIXER", SND_SOC_NOPM, 0,
  2155. 0, dmic6_switch, ARRAY_SIZE(dmic6_switch),
  2156. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  2157. SND_SOC_DAPM_POST_PMD),
  2158. SND_SOC_DAPM_MIXER_E("DMIC7_MIXER", SND_SOC_NOPM, 0,
  2159. 0, dmic7_switch, ARRAY_SIZE(dmic7_switch),
  2160. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  2161. SND_SOC_DAPM_POST_PMD),
  2162. SND_SOC_DAPM_MIXER_E("DMIC8_MIXER", SND_SOC_NOPM, 0,
  2163. 0, dmic8_switch, ARRAY_SIZE(dmic8_switch),
  2164. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  2165. SND_SOC_DAPM_POST_PMD),
  2166. /* micbias widgets*/
  2167. SND_SOC_DAPM_MICBIAS_E("MIC BIAS1", SND_SOC_NOPM, 0, 0,
  2168. wcd938x_codec_enable_micbias,
  2169. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2170. SND_SOC_DAPM_POST_PMD),
  2171. SND_SOC_DAPM_MICBIAS_E("MIC BIAS2", SND_SOC_NOPM, 0, 0,
  2172. wcd938x_codec_enable_micbias,
  2173. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2174. SND_SOC_DAPM_POST_PMD),
  2175. SND_SOC_DAPM_MICBIAS_E("MIC BIAS3", SND_SOC_NOPM, 0, 0,
  2176. wcd938x_codec_enable_micbias,
  2177. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2178. SND_SOC_DAPM_POST_PMD),
  2179. SND_SOC_DAPM_MICBIAS_E("MIC BIAS4", SND_SOC_NOPM, 0, 0,
  2180. wcd938x_codec_enable_micbias,
  2181. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2182. SND_SOC_DAPM_POST_PMD),
  2183. SND_SOC_DAPM_SUPPLY_S("CLS_H_PORT", 1, SND_SOC_NOPM, 0, 0,
  2184. wcd938x_enable_clsh,
  2185. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2186. /*rx widgets*/
  2187. SND_SOC_DAPM_PGA_E("EAR PGA", WCD938X_ANA_EAR, 7, 0, NULL, 0,
  2188. wcd938x_codec_enable_ear_pa,
  2189. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2190. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  2191. SND_SOC_DAPM_PGA_E("AUX PGA", WCD938X_AUX_AUXPA, 7, 0, NULL, 0,
  2192. wcd938x_codec_enable_aux_pa,
  2193. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2194. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  2195. SND_SOC_DAPM_PGA_E("HPHL PGA", WCD938X_ANA_HPH, 7, 0, NULL, 0,
  2196. wcd938x_codec_enable_hphl_pa,
  2197. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2198. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  2199. SND_SOC_DAPM_PGA_E("HPHR PGA", WCD938X_ANA_HPH, 6, 0, NULL, 0,
  2200. wcd938x_codec_enable_hphr_pa,
  2201. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2202. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  2203. SND_SOC_DAPM_DAC_E("RDAC1", NULL, SND_SOC_NOPM, 0, 0,
  2204. wcd938x_codec_hphl_dac_event,
  2205. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2206. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  2207. SND_SOC_DAPM_DAC_E("RDAC2", NULL, SND_SOC_NOPM, 0, 0,
  2208. wcd938x_codec_hphr_dac_event,
  2209. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2210. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  2211. SND_SOC_DAPM_DAC_E("RDAC3", NULL, SND_SOC_NOPM, 0, 0,
  2212. wcd938x_codec_ear_dac_event,
  2213. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2214. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  2215. SND_SOC_DAPM_DAC_E("RDAC4", NULL, SND_SOC_NOPM, 0, 0,
  2216. wcd938x_codec_aux_dac_event,
  2217. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2218. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  2219. SND_SOC_DAPM_MUX("RDAC3_MUX", SND_SOC_NOPM, 0, 0, &rx_rdac3_mux),
  2220. SND_SOC_DAPM_MIXER_E("RX1", SND_SOC_NOPM, 0, 0, NULL, 0,
  2221. wcd938x_enable_rx1, SND_SOC_DAPM_PRE_PMU |
  2222. SND_SOC_DAPM_POST_PMD),
  2223. SND_SOC_DAPM_MIXER_E("RX2", SND_SOC_NOPM, 0, 0, NULL, 0,
  2224. wcd938x_enable_rx2, SND_SOC_DAPM_PRE_PMU |
  2225. SND_SOC_DAPM_POST_PMD),
  2226. SND_SOC_DAPM_MIXER_E("RX3", SND_SOC_NOPM, 0, 0, NULL, 0,
  2227. wcd938x_enable_rx3, SND_SOC_DAPM_PRE_PMU |
  2228. SND_SOC_DAPM_POST_PMD),
  2229. /* rx mixer widgets*/
  2230. SND_SOC_DAPM_MIXER("EAR_RDAC", SND_SOC_NOPM, 0, 0,
  2231. ear_rdac_switch, ARRAY_SIZE(ear_rdac_switch)),
  2232. SND_SOC_DAPM_MIXER("AUX_RDAC", SND_SOC_NOPM, 0, 0,
  2233. aux_rdac_switch, ARRAY_SIZE(aux_rdac_switch)),
  2234. SND_SOC_DAPM_MIXER("HPHL_RDAC", SND_SOC_NOPM, 0, 0,
  2235. hphl_rdac_switch, ARRAY_SIZE(hphl_rdac_switch)),
  2236. SND_SOC_DAPM_MIXER("HPHR_RDAC", SND_SOC_NOPM, 0, 0,
  2237. hphr_rdac_switch, ARRAY_SIZE(hphr_rdac_switch)),
  2238. /*output widgets tx*/
  2239. SND_SOC_DAPM_OUTPUT("ADC1_OUTPUT"),
  2240. SND_SOC_DAPM_OUTPUT("ADC2_OUTPUT"),
  2241. SND_SOC_DAPM_OUTPUT("ADC3_OUTPUT"),
  2242. SND_SOC_DAPM_OUTPUT("ADC4_OUTPUT"),
  2243. SND_SOC_DAPM_OUTPUT("DMIC1_OUTPUT"),
  2244. SND_SOC_DAPM_OUTPUT("DMIC2_OUTPUT"),
  2245. SND_SOC_DAPM_OUTPUT("DMIC3_OUTPUT"),
  2246. SND_SOC_DAPM_OUTPUT("DMIC4_OUTPUT"),
  2247. SND_SOC_DAPM_OUTPUT("DMIC5_OUTPUT"),
  2248. SND_SOC_DAPM_OUTPUT("DMIC6_OUTPUT"),
  2249. SND_SOC_DAPM_OUTPUT("DMIC7_OUTPUT"),
  2250. SND_SOC_DAPM_OUTPUT("DMIC8_OUTPUT"),
  2251. /*output widgets rx*/
  2252. SND_SOC_DAPM_OUTPUT("EAR"),
  2253. SND_SOC_DAPM_OUTPUT("AUX"),
  2254. SND_SOC_DAPM_OUTPUT("HPHL"),
  2255. SND_SOC_DAPM_OUTPUT("HPHR"),
  2256. /* micbias pull up widgets*/
  2257. SND_SOC_DAPM_MICBIAS_E("VA MIC BIAS1", SND_SOC_NOPM, 0, 0,
  2258. wcd938x_codec_enable_micbias_pullup,
  2259. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2260. SND_SOC_DAPM_POST_PMD),
  2261. SND_SOC_DAPM_MICBIAS_E("VA MIC BIAS2", SND_SOC_NOPM, 0, 0,
  2262. wcd938x_codec_enable_micbias_pullup,
  2263. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2264. SND_SOC_DAPM_POST_PMD),
  2265. SND_SOC_DAPM_MICBIAS_E("VA MIC BIAS3", SND_SOC_NOPM, 0, 0,
  2266. wcd938x_codec_enable_micbias_pullup,
  2267. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2268. SND_SOC_DAPM_POST_PMD),
  2269. SND_SOC_DAPM_MICBIAS_E("VA MIC BIAS4", SND_SOC_NOPM, 0, 0,
  2270. wcd938x_codec_enable_micbias_pullup,
  2271. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2272. SND_SOC_DAPM_POST_PMD),
  2273. };
  2274. static const struct snd_soc_dapm_route wcd938x_audio_map[] = {
  2275. {"ADC1_OUTPUT", NULL, "ADC1_MIXER"},
  2276. {"ADC1_MIXER", "Switch", "ADC1 REQ"},
  2277. {"ADC1 REQ", NULL, "ADC1"},
  2278. {"ADC1", NULL, "AMIC1"},
  2279. {"ADC2_OUTPUT", NULL, "ADC2_MIXER"},
  2280. {"ADC2_MIXER", "Switch", "ADC2 REQ"},
  2281. {"ADC2 REQ", NULL, "ADC2"},
  2282. {"ADC2", NULL, "HDR12 MUX"},
  2283. {"HDR12 MUX", "NO_HDR12", "ADC2 MUX"},
  2284. {"HDR12 MUX", "HDR12", "AMIC1"},
  2285. {"ADC2 MUX", "INP3", "AMIC3"},
  2286. {"ADC2 MUX", "INP2", "AMIC2"},
  2287. {"ADC3_OUTPUT", NULL, "ADC3_MIXER"},
  2288. {"ADC3_MIXER", "Switch", "ADC3 REQ"},
  2289. {"ADC3 REQ", NULL, "ADC3"},
  2290. {"ADC3", NULL, "HDR34 MUX"},
  2291. {"HDR34 MUX", "NO_HDR34", "ADC3 MUX"},
  2292. {"HDR34 MUX", "HDR34", "AMIC5"},
  2293. {"ADC3 MUX", "INP4", "AMIC4"},
  2294. {"ADC3 MUX", "INP6", "AMIC6"},
  2295. {"ADC4_OUTPUT", NULL, "ADC4_MIXER"},
  2296. {"ADC4_MIXER", "Switch", "ADC4 REQ"},
  2297. {"ADC4 REQ", NULL, "ADC4"},
  2298. {"ADC4", NULL, "ADC4 MUX"},
  2299. {"ADC4 MUX", "INP5", "AMIC5"},
  2300. {"ADC4 MUX", "INP7", "AMIC7"},
  2301. {"DMIC1_OUTPUT", NULL, "DMIC1_MIXER"},
  2302. {"DMIC1_MIXER", "Switch", "DMIC1"},
  2303. {"DMIC2_OUTPUT", NULL, "DMIC2_MIXER"},
  2304. {"DMIC2_MIXER", "Switch", "DMIC2"},
  2305. {"DMIC3_OUTPUT", NULL, "DMIC3_MIXER"},
  2306. {"DMIC3_MIXER", "Switch", "DMIC3"},
  2307. {"DMIC4_OUTPUT", NULL, "DMIC4_MIXER"},
  2308. {"DMIC4_MIXER", "Switch", "DMIC4"},
  2309. {"DMIC5_OUTPUT", NULL, "DMIC5_MIXER"},
  2310. {"DMIC5_MIXER", "Switch", "DMIC5"},
  2311. {"DMIC6_OUTPUT", NULL, "DMIC6_MIXER"},
  2312. {"DMIC6_MIXER", "Switch", "DMIC6"},
  2313. {"DMIC7_OUTPUT", NULL, "DMIC7_MIXER"},
  2314. {"DMIC7_MIXER", "Switch", "DMIC7"},
  2315. {"DMIC8_OUTPUT", NULL, "DMIC8_MIXER"},
  2316. {"DMIC8_MIXER", "Switch", "DMIC8"},
  2317. {"IN1_HPHL", NULL, "CLS_H_PORT"},
  2318. {"RX1", NULL, "IN1_HPHL"},
  2319. {"RDAC1", NULL, "RX1"},
  2320. {"HPHL_RDAC", "Switch", "RDAC1"},
  2321. {"HPHL PGA", NULL, "HPHL_RDAC"},
  2322. {"HPHL", NULL, "HPHL PGA"},
  2323. {"IN2_HPHR", NULL, "CLS_H_PORT"},
  2324. {"RX2", NULL, "IN2_HPHR"},
  2325. {"RDAC2", NULL, "RX2"},
  2326. {"HPHR_RDAC", "Switch", "RDAC2"},
  2327. {"HPHR PGA", NULL, "HPHR_RDAC"},
  2328. {"HPHR", NULL, "HPHR PGA"},
  2329. {"IN3_AUX", NULL, "CLS_H_PORT"},
  2330. {"RX3", NULL, "IN3_AUX"},
  2331. {"RDAC4", NULL, "RX3"},
  2332. {"AUX_RDAC", "Switch", "RDAC4"},
  2333. {"AUX PGA", NULL, "AUX_RDAC"},
  2334. {"AUX", NULL, "AUX PGA"},
  2335. {"RDAC3_MUX", "RX3", "RX3"},
  2336. {"RDAC3_MUX", "RX1", "RX1"},
  2337. {"RDAC3", NULL, "RDAC3_MUX"},
  2338. {"EAR_RDAC", "Switch", "RDAC3"},
  2339. {"EAR PGA", NULL, "EAR_RDAC"},
  2340. {"EAR", NULL, "EAR PGA"},
  2341. };
  2342. static ssize_t wcd938x_version_read(struct snd_info_entry *entry,
  2343. void *file_private_data,
  2344. struct file *file,
  2345. char __user *buf, size_t count,
  2346. loff_t pos)
  2347. {
  2348. struct wcd938x_priv *priv;
  2349. char buffer[WCD938X_VERSION_ENTRY_SIZE];
  2350. int len = 0;
  2351. priv = (struct wcd938x_priv *) entry->private_data;
  2352. if (!priv) {
  2353. pr_err("%s: wcd938x priv is null\n", __func__);
  2354. return -EINVAL;
  2355. }
  2356. switch (priv->version) {
  2357. case WCD938X_VERSION_1_0:
  2358. len = snprintf(buffer, sizeof(buffer), "WCD938X_1_0\n");
  2359. break;
  2360. default:
  2361. len = snprintf(buffer, sizeof(buffer), "VER_UNDEFINED\n");
  2362. }
  2363. return simple_read_from_buffer(buf, count, &pos, buffer, len);
  2364. }
  2365. static struct snd_info_entry_ops wcd938x_info_ops = {
  2366. .read = wcd938x_version_read,
  2367. };
  2368. static ssize_t wcd938x_variant_read(struct snd_info_entry *entry,
  2369. void *file_private_data,
  2370. struct file *file,
  2371. char __user *buf, size_t count,
  2372. loff_t pos)
  2373. {
  2374. struct wcd938x_priv *priv;
  2375. char buffer[WCD938X_VARIANT_ENTRY_SIZE];
  2376. int len = 0;
  2377. priv = (struct wcd938x_priv *) entry->private_data;
  2378. if (!priv) {
  2379. pr_err("%s: wcd938x priv is null\n", __func__);
  2380. return -EINVAL;
  2381. }
  2382. switch (priv->variant) {
  2383. case WCD9380:
  2384. len = snprintf(buffer, sizeof(buffer), "WCD9380\n");
  2385. break;
  2386. case WCD9385:
  2387. len = snprintf(buffer, sizeof(buffer), "WCD9385\n");
  2388. break;
  2389. default:
  2390. len = snprintf(buffer, sizeof(buffer), "VER_UNDEFINED\n");
  2391. }
  2392. return simple_read_from_buffer(buf, count, &pos, buffer, len);
  2393. }
  2394. static struct snd_info_entry_ops wcd938x_variant_ops = {
  2395. .read = wcd938x_variant_read,
  2396. };
  2397. /*
  2398. * wcd938x_info_create_codec_entry - creates wcd938x module
  2399. * @codec_root: The parent directory
  2400. * @component: component instance
  2401. *
  2402. * Creates wcd938x module, variant and version entry under the given
  2403. * parent directory.
  2404. *
  2405. * Return: 0 on success or negative error code on failure.
  2406. */
  2407. int wcd938x_info_create_codec_entry(struct snd_info_entry *codec_root,
  2408. struct snd_soc_component *component)
  2409. {
  2410. struct snd_info_entry *version_entry;
  2411. struct snd_info_entry *variant_entry;
  2412. struct wcd938x_priv *priv;
  2413. struct snd_soc_card *card;
  2414. if (!codec_root || !component)
  2415. return -EINVAL;
  2416. priv = snd_soc_component_get_drvdata(component);
  2417. if (priv->entry) {
  2418. dev_dbg(priv->dev,
  2419. "%s:wcd938x module already created\n", __func__);
  2420. return 0;
  2421. }
  2422. card = component->card;
  2423. priv->entry = snd_info_create_subdir(codec_root->module,
  2424. "wcd938x", codec_root);
  2425. if (!priv->entry) {
  2426. dev_dbg(component->dev, "%s: failed to create wcd938x entry\n",
  2427. __func__);
  2428. return -ENOMEM;
  2429. }
  2430. version_entry = snd_info_create_card_entry(card->snd_card,
  2431. "version",
  2432. priv->entry);
  2433. if (!version_entry) {
  2434. dev_dbg(component->dev, "%s: failed to create wcd938x version entry\n",
  2435. __func__);
  2436. return -ENOMEM;
  2437. }
  2438. version_entry->private_data = priv;
  2439. version_entry->size = WCD938X_VERSION_ENTRY_SIZE;
  2440. version_entry->content = SNDRV_INFO_CONTENT_DATA;
  2441. version_entry->c.ops = &wcd938x_info_ops;
  2442. if (snd_info_register(version_entry) < 0) {
  2443. snd_info_free_entry(version_entry);
  2444. return -ENOMEM;
  2445. }
  2446. priv->version_entry = version_entry;
  2447. variant_entry = snd_info_create_card_entry(card->snd_card,
  2448. "variant",
  2449. priv->entry);
  2450. if (!variant_entry) {
  2451. dev_dbg(component->dev, "%s: failed to create wcd938x variant entry\n",
  2452. __func__);
  2453. return -ENOMEM;
  2454. }
  2455. variant_entry->private_data = priv;
  2456. variant_entry->size = WCD938X_VARIANT_ENTRY_SIZE;
  2457. variant_entry->content = SNDRV_INFO_CONTENT_DATA;
  2458. variant_entry->c.ops = &wcd938x_variant_ops;
  2459. if (snd_info_register(variant_entry) < 0) {
  2460. snd_info_free_entry(variant_entry);
  2461. return -ENOMEM;
  2462. }
  2463. priv->variant_entry = variant_entry;
  2464. return 0;
  2465. }
  2466. EXPORT_SYMBOL(wcd938x_info_create_codec_entry);
  2467. static int wcd938x_soc_codec_probe(struct snd_soc_component *component)
  2468. {
  2469. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  2470. struct snd_soc_dapm_context *dapm =
  2471. snd_soc_component_get_dapm(component);
  2472. int variant;
  2473. int ret = -EINVAL;
  2474. dev_info(component->dev, "%s()\n", __func__);
  2475. wcd938x = snd_soc_component_get_drvdata(component);
  2476. if (!wcd938x)
  2477. return -EINVAL;
  2478. wcd938x->component = component;
  2479. snd_soc_component_init_regmap(component, wcd938x->regmap);
  2480. variant = (snd_soc_component_read32(component,
  2481. WCD938X_DIGITAL_EFUSE_REG_0) & 0x1E) >> 1;
  2482. wcd938x->variant = variant;
  2483. wcd938x->fw_data = devm_kzalloc(component->dev,
  2484. sizeof(*(wcd938x->fw_data)),
  2485. GFP_KERNEL);
  2486. if (!wcd938x->fw_data) {
  2487. dev_err(component->dev, "Failed to allocate fw_data\n");
  2488. ret = -ENOMEM;
  2489. goto err;
  2490. }
  2491. set_bit(WCD9XXX_MBHC_CAL, wcd938x->fw_data->cal_bit);
  2492. ret = wcd_cal_create_hwdep(wcd938x->fw_data,
  2493. WCD9XXX_CODEC_HWDEP_NODE, component);
  2494. if (ret < 0) {
  2495. dev_err(component->dev, "%s hwdep failed %d\n", __func__, ret);
  2496. goto err_hwdep;
  2497. }
  2498. ret = wcd938x_mbhc_init(&wcd938x->mbhc, component, wcd938x->fw_data);
  2499. if (ret) {
  2500. pr_err("%s: mbhc initialization failed\n", __func__);
  2501. goto err_hwdep;
  2502. }
  2503. snd_soc_dapm_ignore_suspend(dapm, "AMIC1");
  2504. snd_soc_dapm_ignore_suspend(dapm, "AMIC2");
  2505. snd_soc_dapm_ignore_suspend(dapm, "AMIC3");
  2506. snd_soc_dapm_ignore_suspend(dapm, "AMIC4");
  2507. snd_soc_dapm_ignore_suspend(dapm, "AMIC5");
  2508. snd_soc_dapm_ignore_suspend(dapm, "AMIC6");
  2509. snd_soc_dapm_ignore_suspend(dapm, "AMIC7");
  2510. snd_soc_dapm_ignore_suspend(dapm, "DMIC1_OUTPUT");
  2511. snd_soc_dapm_ignore_suspend(dapm, "DMIC2_OUTPUT");
  2512. snd_soc_dapm_ignore_suspend(dapm, "DMIC3_OUTPUT");
  2513. snd_soc_dapm_ignore_suspend(dapm, "DMIC4_OUTPUT");
  2514. snd_soc_dapm_ignore_suspend(dapm, "DMIC5_OUTPUT");
  2515. snd_soc_dapm_ignore_suspend(dapm, "DMIC6_OUTPUT");
  2516. snd_soc_dapm_ignore_suspend(dapm, "DMIC7_OUTPUT");
  2517. snd_soc_dapm_ignore_suspend(dapm, "DMIC8_OUTPUT");
  2518. snd_soc_dapm_ignore_suspend(dapm, "ADC1_OUTPUT");
  2519. snd_soc_dapm_ignore_suspend(dapm, "ADC2_OUTPUT");
  2520. snd_soc_dapm_ignore_suspend(dapm, "ADC3_OUTPUT");
  2521. snd_soc_dapm_ignore_suspend(dapm, "ADC4_OUTPUT");
  2522. snd_soc_dapm_ignore_suspend(dapm, "IN1_HPHL");
  2523. snd_soc_dapm_ignore_suspend(dapm, "IN2_HPHR");
  2524. snd_soc_dapm_ignore_suspend(dapm, "IN3_AUX");
  2525. snd_soc_dapm_ignore_suspend(dapm, "EAR");
  2526. snd_soc_dapm_ignore_suspend(dapm, "AUX");
  2527. snd_soc_dapm_ignore_suspend(dapm, "HPHL");
  2528. snd_soc_dapm_ignore_suspend(dapm, "HPHR");
  2529. snd_soc_dapm_sync(dapm);
  2530. wcd_cls_h_init(&wcd938x->clsh_info);
  2531. wcd938x_init_reg(component);
  2532. if (wcd938x->variant == WCD9380) {
  2533. ret = snd_soc_add_component_controls(component, wcd9380_snd_controls,
  2534. ARRAY_SIZE(wcd9380_snd_controls));
  2535. if (ret < 0) {
  2536. dev_err(component->dev,
  2537. "%s: Failed to add snd ctrls for variant: %d\n",
  2538. __func__, wcd938x->variant);
  2539. goto err_hwdep;
  2540. }
  2541. }
  2542. if (wcd938x->variant == WCD9385) {
  2543. ret = snd_soc_add_component_controls(component, wcd9385_snd_controls,
  2544. ARRAY_SIZE(wcd9385_snd_controls));
  2545. if (ret < 0) {
  2546. dev_err(component->dev,
  2547. "%s: Failed to add snd ctrls for variant: %d\n",
  2548. __func__, wcd938x->variant);
  2549. goto err_hwdep;
  2550. }
  2551. }
  2552. wcd938x->version = WCD938X_VERSION_1_0;
  2553. /* Register event notifier */
  2554. wcd938x->nblock.notifier_call = wcd938x_event_notify;
  2555. if (wcd938x->register_notifier) {
  2556. ret = wcd938x->register_notifier(wcd938x->handle,
  2557. &wcd938x->nblock,
  2558. true);
  2559. if (ret) {
  2560. dev_err(component->dev,
  2561. "%s: Failed to register notifier %d\n",
  2562. __func__, ret);
  2563. return ret;
  2564. }
  2565. }
  2566. return ret;
  2567. err_hwdep:
  2568. wcd938x->fw_data = NULL;
  2569. err:
  2570. return ret;
  2571. }
  2572. static void wcd938x_soc_codec_remove(struct snd_soc_component *component)
  2573. {
  2574. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  2575. if (!wcd938x) {
  2576. dev_err(component->dev, "%s: wcd938x is already NULL\n",
  2577. __func__);
  2578. return;
  2579. }
  2580. if (wcd938x->register_notifier)
  2581. wcd938x->register_notifier(wcd938x->handle,
  2582. &wcd938x->nblock,
  2583. false);
  2584. }
  2585. static struct snd_soc_component_driver soc_codec_dev_wcd938x = {
  2586. .name = WCD938X_DRV_NAME,
  2587. .probe = wcd938x_soc_codec_probe,
  2588. .remove = wcd938x_soc_codec_remove,
  2589. .controls = wcd938x_snd_controls,
  2590. .num_controls = ARRAY_SIZE(wcd938x_snd_controls),
  2591. .dapm_widgets = wcd938x_dapm_widgets,
  2592. .num_dapm_widgets = ARRAY_SIZE(wcd938x_dapm_widgets),
  2593. .dapm_routes = wcd938x_audio_map,
  2594. .num_dapm_routes = ARRAY_SIZE(wcd938x_audio_map),
  2595. };
  2596. static int wcd938x_reset(struct device *dev)
  2597. {
  2598. struct wcd938x_priv *wcd938x = NULL;
  2599. int rc = 0;
  2600. int value = 0;
  2601. if (!dev)
  2602. return -ENODEV;
  2603. wcd938x = dev_get_drvdata(dev);
  2604. if (!wcd938x)
  2605. return -EINVAL;
  2606. if (!wcd938x->rst_np) {
  2607. dev_err(dev, "%s: reset gpio device node not specified\n",
  2608. __func__);
  2609. return -EINVAL;
  2610. }
  2611. value = msm_cdc_pinctrl_get_state(wcd938x->rst_np);
  2612. if (value > 0)
  2613. return 0;
  2614. rc = msm_cdc_pinctrl_select_sleep_state(wcd938x->rst_np);
  2615. if (rc) {
  2616. dev_err(dev, "%s: wcd sleep state request fail!\n",
  2617. __func__);
  2618. return rc;
  2619. }
  2620. /* 20us sleep required after pulling the reset gpio to LOW */
  2621. usleep_range(20, 30);
  2622. rc = msm_cdc_pinctrl_select_active_state(wcd938x->rst_np);
  2623. if (rc) {
  2624. dev_err(dev, "%s: wcd active state request fail!\n",
  2625. __func__);
  2626. return rc;
  2627. }
  2628. /* 20us sleep required after pulling the reset gpio to HIGH */
  2629. usleep_range(20, 30);
  2630. return rc;
  2631. }
  2632. static int wcd938x_read_of_property_u32(struct device *dev, const char *name,
  2633. u32 *val)
  2634. {
  2635. int rc = 0;
  2636. rc = of_property_read_u32(dev->of_node, name, val);
  2637. if (rc)
  2638. dev_err(dev, "%s: Looking up %s property in node %s failed\n",
  2639. __func__, name, dev->of_node->full_name);
  2640. return rc;
  2641. }
  2642. static void wcd938x_dt_parse_micbias_info(struct device *dev,
  2643. struct wcd938x_micbias_setting *mb)
  2644. {
  2645. u32 prop_val = 0;
  2646. int rc = 0;
  2647. /* MB1 */
  2648. if (of_find_property(dev->of_node, "qcom,cdc-micbias1-mv",
  2649. NULL)) {
  2650. rc = wcd938x_read_of_property_u32(dev,
  2651. "qcom,cdc-micbias1-mv",
  2652. &prop_val);
  2653. if (!rc)
  2654. mb->micb1_mv = prop_val;
  2655. } else {
  2656. dev_info(dev, "%s: Micbias1 DT property not found\n",
  2657. __func__);
  2658. }
  2659. /* MB2 */
  2660. if (of_find_property(dev->of_node, "qcom,cdc-micbias2-mv",
  2661. NULL)) {
  2662. rc = wcd938x_read_of_property_u32(dev,
  2663. "qcom,cdc-micbias2-mv",
  2664. &prop_val);
  2665. if (!rc)
  2666. mb->micb2_mv = prop_val;
  2667. } else {
  2668. dev_info(dev, "%s: Micbias2 DT property not found\n",
  2669. __func__);
  2670. }
  2671. /* MB3 */
  2672. if (of_find_property(dev->of_node, "qcom,cdc-micbias3-mv",
  2673. NULL)) {
  2674. rc = wcd938x_read_of_property_u32(dev,
  2675. "qcom,cdc-micbias3-mv",
  2676. &prop_val);
  2677. if (!rc)
  2678. mb->micb3_mv = prop_val;
  2679. } else {
  2680. dev_info(dev, "%s: Micbias3 DT property not found\n",
  2681. __func__);
  2682. }
  2683. }
  2684. static int wcd938x_reset_low(struct device *dev)
  2685. {
  2686. struct wcd938x_priv *wcd938x = NULL;
  2687. int rc = 0;
  2688. if (!dev)
  2689. return -ENODEV;
  2690. wcd938x = dev_get_drvdata(dev);
  2691. if (!wcd938x)
  2692. return -EINVAL;
  2693. if (!wcd938x->rst_np) {
  2694. dev_err(dev, "%s: reset gpio device node not specified\n",
  2695. __func__);
  2696. return -EINVAL;
  2697. }
  2698. rc = msm_cdc_pinctrl_select_sleep_state(wcd938x->rst_np);
  2699. if (rc) {
  2700. dev_err(dev, "%s: wcd sleep state request fail!\n",
  2701. __func__);
  2702. return rc;
  2703. }
  2704. /* 20us sleep required after pulling the reset gpio to LOW */
  2705. usleep_range(20, 30);
  2706. return rc;
  2707. }
  2708. struct wcd938x_pdata *wcd938x_populate_dt_data(struct device *dev)
  2709. {
  2710. struct wcd938x_pdata *pdata = NULL;
  2711. pdata = devm_kzalloc(dev, sizeof(struct wcd938x_pdata),
  2712. GFP_KERNEL);
  2713. if (!pdata)
  2714. return NULL;
  2715. pdata->rst_np = of_parse_phandle(dev->of_node,
  2716. "qcom,wcd-rst-gpio-node", 0);
  2717. if (!pdata->rst_np) {
  2718. dev_err(dev, "%s: Looking up %s property in node %s failed\n",
  2719. __func__, "qcom,wcd-rst-gpio-node",
  2720. dev->of_node->full_name);
  2721. return NULL;
  2722. }
  2723. /* Parse power supplies */
  2724. msm_cdc_get_power_supplies(dev, &pdata->regulator,
  2725. &pdata->num_supplies);
  2726. if (!pdata->regulator || (pdata->num_supplies <= 0)) {
  2727. dev_err(dev, "%s: no power supplies defined for codec\n",
  2728. __func__);
  2729. return NULL;
  2730. }
  2731. pdata->rx_slave = of_parse_phandle(dev->of_node, "qcom,rx-slave", 0);
  2732. pdata->tx_slave = of_parse_phandle(dev->of_node, "qcom,tx-slave", 0);
  2733. wcd938x_dt_parse_micbias_info(dev, &pdata->micbias);
  2734. return pdata;
  2735. }
  2736. static irqreturn_t wcd938x_wd_handle_irq(int irq, void *data)
  2737. {
  2738. pr_err_ratelimited("%s: Watchdog interrupt for irq =%d triggered\n",
  2739. __func__, irq);
  2740. return IRQ_HANDLED;
  2741. }
  2742. static int wcd938x_bind(struct device *dev)
  2743. {
  2744. int ret = 0, i = 0;
  2745. struct wcd938x_pdata *pdata = dev_get_platdata(dev);
  2746. struct wcd938x_priv *wcd938x = dev_get_drvdata(dev);
  2747. /*
  2748. * Add 5msec delay to provide sufficient time for
  2749. * soundwire auto enumeration of slave devices as
  2750. * as per HW requirement.
  2751. */
  2752. usleep_range(5000, 5010);
  2753. ret = component_bind_all(dev, wcd938x);
  2754. if (ret) {
  2755. dev_err(dev, "%s: Slave bind failed, ret = %d\n",
  2756. __func__, ret);
  2757. return ret;
  2758. }
  2759. wcd938x->rx_swr_dev = get_matching_swr_slave_device(pdata->rx_slave);
  2760. if (!wcd938x->rx_swr_dev) {
  2761. dev_err(dev, "%s: Could not find RX swr slave device\n",
  2762. __func__);
  2763. ret = -ENODEV;
  2764. goto err;
  2765. }
  2766. wcd938x->tx_swr_dev = get_matching_swr_slave_device(pdata->tx_slave);
  2767. if (!wcd938x->tx_swr_dev) {
  2768. dev_err(dev, "%s: Could not find TX swr slave device\n",
  2769. __func__);
  2770. ret = -ENODEV;
  2771. goto err;
  2772. }
  2773. wcd938x->regmap = devm_regmap_init_swr(wcd938x->tx_swr_dev,
  2774. &wcd938x_regmap_config);
  2775. if (!wcd938x->regmap) {
  2776. dev_err(dev, "%s: Regmap init failed\n",
  2777. __func__);
  2778. goto err;
  2779. }
  2780. /* Set all interupts as edge triggered */
  2781. for (i = 0; i < wcd938x_regmap_irq_chip.num_regs; i++)
  2782. regmap_write(wcd938x->regmap,
  2783. (WCD938X_DIGITAL_INTR_LEVEL_0 + i), 0);
  2784. wcd938x_regmap_irq_chip.irq_drv_data = wcd938x;
  2785. wcd938x->irq_info.wcd_regmap_irq_chip = &wcd938x_regmap_irq_chip;
  2786. wcd938x->irq_info.codec_name = "WCD938X";
  2787. wcd938x->irq_info.regmap = wcd938x->regmap;
  2788. wcd938x->irq_info.dev = dev;
  2789. ret = wcd_irq_init(&wcd938x->irq_info, &wcd938x->virq);
  2790. if (ret) {
  2791. dev_err(wcd938x->dev, "%s: IRQ init failed: %d\n",
  2792. __func__, ret);
  2793. goto err;
  2794. }
  2795. wcd938x->tx_swr_dev->slave_irq = wcd938x->virq;
  2796. /* Request for watchdog interrupt */
  2797. wcd_request_irq(&wcd938x->irq_info, WCD938X_IRQ_HPHR_PDM_WD_INT,
  2798. "HPHR PDM WD INT", wcd938x_wd_handle_irq, NULL);
  2799. wcd_request_irq(&wcd938x->irq_info, WCD938X_IRQ_HPHL_PDM_WD_INT,
  2800. "HPHL PDM WD INT", wcd938x_wd_handle_irq, NULL);
  2801. wcd_request_irq(&wcd938x->irq_info, WCD938X_IRQ_AUX_PDM_WD_INT,
  2802. "AUX PDM WD INT", wcd938x_wd_handle_irq, NULL);
  2803. /* Disable watchdog interrupt for HPH and AUX */
  2804. wcd_disable_irq(&wcd938x->irq_info, WCD938X_IRQ_HPHR_PDM_WD_INT);
  2805. wcd_disable_irq(&wcd938x->irq_info, WCD938X_IRQ_HPHL_PDM_WD_INT);
  2806. wcd_disable_irq(&wcd938x->irq_info, WCD938X_IRQ_AUX_PDM_WD_INT);
  2807. ret = snd_soc_register_component(dev, &soc_codec_dev_wcd938x,
  2808. NULL, 0);
  2809. if (ret) {
  2810. dev_err(dev, "%s: Codec registration failed\n",
  2811. __func__);
  2812. goto err_irq;
  2813. }
  2814. return ret;
  2815. err_irq:
  2816. wcd_irq_exit(&wcd938x->irq_info, wcd938x->virq);
  2817. err:
  2818. component_unbind_all(dev, wcd938x);
  2819. return ret;
  2820. }
  2821. static void wcd938x_unbind(struct device *dev)
  2822. {
  2823. struct wcd938x_priv *wcd938x = dev_get_drvdata(dev);
  2824. wcd_free_irq(&wcd938x->irq_info, WCD938X_IRQ_HPHR_PDM_WD_INT, NULL);
  2825. wcd_free_irq(&wcd938x->irq_info, WCD938X_IRQ_HPHL_PDM_WD_INT, NULL);
  2826. wcd_free_irq(&wcd938x->irq_info, WCD938X_IRQ_AUX_PDM_WD_INT, NULL);
  2827. wcd_irq_exit(&wcd938x->irq_info, wcd938x->virq);
  2828. snd_soc_unregister_component(dev);
  2829. component_unbind_all(dev, wcd938x);
  2830. }
  2831. static const struct of_device_id wcd938x_dt_match[] = {
  2832. { .compatible = "qcom,wcd938x-codec" },
  2833. {}
  2834. };
  2835. static const struct component_master_ops wcd938x_comp_ops = {
  2836. .bind = wcd938x_bind,
  2837. .unbind = wcd938x_unbind,
  2838. };
  2839. static int wcd938x_compare_of(struct device *dev, void *data)
  2840. {
  2841. return dev->of_node == data;
  2842. }
  2843. static void wcd938x_release_of(struct device *dev, void *data)
  2844. {
  2845. of_node_put(data);
  2846. }
  2847. static int wcd938x_add_slave_components(struct device *dev,
  2848. struct component_match **matchptr)
  2849. {
  2850. struct device_node *np, *rx_node, *tx_node;
  2851. np = dev->of_node;
  2852. rx_node = of_parse_phandle(np, "qcom,rx-slave", 0);
  2853. if (!rx_node) {
  2854. dev_err(dev, "%s: Rx-slave node not defined\n", __func__);
  2855. return -ENODEV;
  2856. }
  2857. of_node_get(rx_node);
  2858. component_match_add_release(dev, matchptr,
  2859. wcd938x_release_of,
  2860. wcd938x_compare_of,
  2861. rx_node);
  2862. tx_node = of_parse_phandle(np, "qcom,tx-slave", 0);
  2863. if (!tx_node) {
  2864. dev_err(dev, "%s: Tx-slave node not defined\n", __func__);
  2865. return -ENODEV;
  2866. }
  2867. of_node_get(tx_node);
  2868. component_match_add_release(dev, matchptr,
  2869. wcd938x_release_of,
  2870. wcd938x_compare_of,
  2871. tx_node);
  2872. return 0;
  2873. }
  2874. static int wcd938x_wakeup(void *handle, bool enable)
  2875. {
  2876. struct wcd938x_priv *priv;
  2877. if (!handle) {
  2878. pr_err("%s: NULL handle\n", __func__);
  2879. return -EINVAL;
  2880. }
  2881. priv = (struct wcd938x_priv *)handle;
  2882. if (!priv->tx_swr_dev) {
  2883. pr_err("%s: tx swr dev is NULL\n", __func__);
  2884. return -EINVAL;
  2885. }
  2886. if (enable)
  2887. return swr_device_wakeup_vote(priv->tx_swr_dev);
  2888. else
  2889. return swr_device_wakeup_unvote(priv->tx_swr_dev);
  2890. }
  2891. static int wcd938x_probe(struct platform_device *pdev)
  2892. {
  2893. struct component_match *match = NULL;
  2894. struct wcd938x_priv *wcd938x = NULL;
  2895. struct wcd938x_pdata *pdata = NULL;
  2896. struct wcd_ctrl_platform_data *plat_data = NULL;
  2897. struct device *dev = &pdev->dev;
  2898. int ret;
  2899. wcd938x = devm_kzalloc(dev, sizeof(struct wcd938x_priv),
  2900. GFP_KERNEL);
  2901. if (!wcd938x)
  2902. return -ENOMEM;
  2903. dev_set_drvdata(dev, wcd938x);
  2904. wcd938x->dev = dev;
  2905. pdata = wcd938x_populate_dt_data(dev);
  2906. if (!pdata) {
  2907. dev_err(dev, "%s: Fail to obtain platform data\n", __func__);
  2908. return -EINVAL;
  2909. }
  2910. dev->platform_data = pdata;
  2911. wcd938x->rst_np = pdata->rst_np;
  2912. ret = msm_cdc_init_supplies(dev, &wcd938x->supplies,
  2913. pdata->regulator, pdata->num_supplies);
  2914. if (!wcd938x->supplies) {
  2915. dev_err(dev, "%s: Cannot init wcd supplies\n",
  2916. __func__);
  2917. return ret;
  2918. }
  2919. plat_data = dev_get_platdata(dev->parent);
  2920. if (!plat_data) {
  2921. dev_err(dev, "%s: platform data from parent is NULL\n",
  2922. __func__);
  2923. return -EINVAL;
  2924. }
  2925. wcd938x->handle = (void *)plat_data->handle;
  2926. if (!wcd938x->handle) {
  2927. dev_err(dev, "%s: handle is NULL\n", __func__);
  2928. return -EINVAL;
  2929. }
  2930. wcd938x->update_wcd_event = plat_data->update_wcd_event;
  2931. if (!wcd938x->update_wcd_event) {
  2932. dev_err(dev, "%s: update_wcd_event api is null!\n",
  2933. __func__);
  2934. return -EINVAL;
  2935. }
  2936. wcd938x->register_notifier = plat_data->register_notifier;
  2937. if (!wcd938x->register_notifier) {
  2938. dev_err(dev, "%s: register_notifier api is null!\n",
  2939. __func__);
  2940. return -EINVAL;
  2941. }
  2942. ret = msm_cdc_enable_static_supplies(&pdev->dev, wcd938x->supplies,
  2943. pdata->regulator,
  2944. pdata->num_supplies);
  2945. if (ret) {
  2946. dev_err(dev, "%s: wcd static supply enable failed!\n",
  2947. __func__);
  2948. return ret;
  2949. }
  2950. ret = wcd938x_parse_port_mapping(dev, "qcom,rx_swr_ch_map",
  2951. CODEC_RX);
  2952. ret |= wcd938x_parse_port_mapping(dev, "qcom,tx_swr_ch_map",
  2953. CODEC_TX);
  2954. if (ret) {
  2955. dev_err(dev, "Failed to read port mapping\n");
  2956. goto err;
  2957. }
  2958. mutex_init(&wcd938x->micb_lock);
  2959. ret = wcd938x_add_slave_components(dev, &match);
  2960. if (ret)
  2961. goto err_lock_init;
  2962. wcd938x_reset(dev);
  2963. wcd938x->wakeup = wcd938x_wakeup;
  2964. return component_master_add_with_match(dev,
  2965. &wcd938x_comp_ops, match);
  2966. err_lock_init:
  2967. mutex_destroy(&wcd938x->micb_lock);
  2968. err:
  2969. return ret;
  2970. }
  2971. static int wcd938x_remove(struct platform_device *pdev)
  2972. {
  2973. struct wcd938x_priv *wcd938x = NULL;
  2974. wcd938x = platform_get_drvdata(pdev);
  2975. component_master_del(&pdev->dev, &wcd938x_comp_ops);
  2976. mutex_destroy(&wcd938x->micb_lock);
  2977. dev_set_drvdata(&pdev->dev, NULL);
  2978. return 0;
  2979. }
  2980. #ifdef CONFIG_PM_SLEEP
  2981. static int wcd938x_suspend(struct device *dev)
  2982. {
  2983. return 0;
  2984. }
  2985. static int wcd938x_resume(struct device *dev)
  2986. {
  2987. return 0;
  2988. }
  2989. static const struct dev_pm_ops wcd938x_dev_pm_ops = {
  2990. SET_SYSTEM_SLEEP_PM_OPS(
  2991. wcd938x_suspend,
  2992. wcd938x_resume
  2993. )
  2994. };
  2995. #endif
  2996. static struct platform_driver wcd938x_codec_driver = {
  2997. .probe = wcd938x_probe,
  2998. .remove = wcd938x_remove,
  2999. .driver = {
  3000. .name = "wcd938x_codec",
  3001. .owner = THIS_MODULE,
  3002. .of_match_table = of_match_ptr(wcd938x_dt_match),
  3003. #ifdef CONFIG_PM_SLEEP
  3004. .pm = &wcd938x_dev_pm_ops,
  3005. #endif
  3006. .suppress_bind_attrs = true,
  3007. },
  3008. };
  3009. module_platform_driver(wcd938x_codec_driver);
  3010. MODULE_DESCRIPTION("WCD938X Codec driver");
  3011. MODULE_LICENSE("GPL v2");