wcd937x.c 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496
  1. /*
  2. * Copyright (c) 2018, The Linux Foundation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 and
  6. * only version 2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include <linux/module.h>
  14. #include <linux/slab.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/device.h>
  17. #include <linux/delay.h>
  18. #include <linux/kernel.h>
  19. #include <linux/component.h>
  20. #include <sound/soc.h>
  21. #include <sound/tlv.h>
  22. #include <soc/soundwire.h>
  23. #include <linux/regmap.h>
  24. #include <sound/soc.h>
  25. #include <sound/soc-dapm.h>
  26. #include "internal.h"
  27. #include "wcd937x.h"
  28. #include "../wcdcal-hwdep.h"
  29. #include "wcd937x-registers.h"
  30. #include "../msm-cdc-pinctrl.h"
  31. #include <dt-bindings/sound/audio-codec-port-types.h>
  32. #include "../msm-cdc-supply.h"
  33. #define WCD9370_VARIANT 0
  34. #define WCD9375_VARIANT 5
  35. #define NUM_SWRS_DT_PARAMS 5
  36. #define WCD937X_VERSION_1_0 1
  37. #define WCD937X_VERSION_ENTRY_SIZE 32
  38. enum {
  39. CODEC_TX = 0,
  40. CODEC_RX,
  41. };
  42. static const DECLARE_TLV_DB_SCALE(line_gain, 0, 7, 1);
  43. static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 25, 1);
  44. static int wcd937x_handle_post_irq(void *data);
  45. static int wcd937x_reset(struct device *dev);
  46. static int wcd937x_reset_low(struct device *dev);
  47. static const struct regmap_irq wcd937x_irqs[WCD937X_NUM_IRQS] = {
  48. REGMAP_IRQ_REG(WCD937X_IRQ_MBHC_BUTTON_PRESS_DET, 0, 0x01),
  49. REGMAP_IRQ_REG(WCD937X_IRQ_MBHC_BUTTON_RELEASE_DET, 0, 0x02),
  50. REGMAP_IRQ_REG(WCD937X_IRQ_MBHC_ELECT_INS_REM_DET, 0, 0x04),
  51. REGMAP_IRQ_REG(WCD937X_IRQ_MBHC_ELECT_INS_REM_LEG_DET, 0, 0x08),
  52. REGMAP_IRQ_REG(WCD937X_IRQ_MBHC_SW_DET, 0, 0x10),
  53. REGMAP_IRQ_REG(WCD937X_IRQ_HPHR_OCP_INT, 0, 0x20),
  54. REGMAP_IRQ_REG(WCD937X_IRQ_HPHR_CNP_INT, 0, 0x40),
  55. REGMAP_IRQ_REG(WCD937X_IRQ_HPHL_OCP_INT, 0, 0x80),
  56. REGMAP_IRQ_REG(WCD937X_IRQ_HPHL_CNP_INT, 1, 0x01),
  57. REGMAP_IRQ_REG(WCD937X_IRQ_EAR_CNP_INT, 1, 0x02),
  58. REGMAP_IRQ_REG(WCD937X_IRQ_EAR_SCD_INT, 1, 0x04),
  59. REGMAP_IRQ_REG(WCD937X_IRQ_AUX_CNP_INT, 1, 0x08),
  60. REGMAP_IRQ_REG(WCD937X_IRQ_AUX_SCD_INT, 1, 0x10),
  61. REGMAP_IRQ_REG(WCD937X_IRQ_HPHL_PDM_WD_INT, 1, 0x20),
  62. REGMAP_IRQ_REG(WCD937X_IRQ_HPHR_PDM_WD_INT, 1, 0x40),
  63. REGMAP_IRQ_REG(WCD937X_IRQ_AUX_PDM_WD_INT, 1, 0x80),
  64. REGMAP_IRQ_REG(WCD937X_IRQ_LDORT_SCD_INT, 2, 0x01),
  65. REGMAP_IRQ_REG(WCD937X_IRQ_MBHC_MOISTURE_INT, 2, 0x02),
  66. REGMAP_IRQ_REG(WCD937X_IRQ_HPHL_SURGE_DET_INT, 2, 0x04),
  67. REGMAP_IRQ_REG(WCD937X_IRQ_HPHR_SURGE_DET_INT, 2, 0x08),
  68. };
  69. static struct regmap_irq_chip wcd937x_regmap_irq_chip = {
  70. .name = "wcd937x",
  71. .irqs = wcd937x_irqs,
  72. .num_irqs = ARRAY_SIZE(wcd937x_irqs),
  73. .num_regs = 3,
  74. .status_base = WCD937X_DIGITAL_INTR_STATUS_0,
  75. .mask_base = WCD937X_DIGITAL_INTR_MASK_0,
  76. .ack_base = WCD937X_DIGITAL_INTR_CLEAR_0,
  77. .use_ack = 1,
  78. .clear_ack = 1,
  79. .type_base = WCD937X_DIGITAL_INTR_LEVEL_0,
  80. .runtime_pm = false,
  81. .handle_post_irq = wcd937x_handle_post_irq,
  82. .irq_drv_data = NULL,
  83. };
  84. static int wcd937x_handle_post_irq(void *data)
  85. {
  86. struct wcd937x_priv *wcd937x = data;
  87. u32 status1 = 0, status2 = 0, status3 = 0;
  88. regmap_read(wcd937x->regmap, WCD937X_DIGITAL_INTR_STATUS_0, &status1);
  89. regmap_read(wcd937x->regmap, WCD937X_DIGITAL_INTR_STATUS_1, &status2);
  90. regmap_read(wcd937x->regmap, WCD937X_DIGITAL_INTR_STATUS_2, &status3);
  91. wcd937x->tx_swr_dev->slave_irq_pending =
  92. ((status1 || status2 || status3) ? true : false);
  93. return IRQ_HANDLED;
  94. }
  95. static int wcd937x_init_reg(struct snd_soc_codec *codec)
  96. {
  97. snd_soc_update_bits(codec, WCD937X_SLEEP_CTL, 0x0E, 0x0E);
  98. snd_soc_update_bits(codec, WCD937X_SLEEP_CTL, 0x80, 0x80);
  99. usleep_range(1000, 1010);
  100. snd_soc_update_bits(codec, WCD937X_SLEEP_CTL, 0x40, 0x40);
  101. usleep_range(1000, 1010);
  102. snd_soc_update_bits(codec, WCD937X_LDORXTX_CONFIG, 0x10, 0x00);
  103. snd_soc_update_bits(codec, WCD937X_BIAS_VBG_FINE_ADJ, 0xF0, 0x80);
  104. snd_soc_update_bits(codec, WCD937X_ANA_BIAS, 0x80, 0x80);
  105. snd_soc_update_bits(codec, WCD937X_ANA_BIAS, 0x40, 0x40);
  106. usleep_range(10000, 10010);
  107. snd_soc_update_bits(codec, WCD937X_ANA_BIAS, 0x40, 0x00);
  108. return 0;
  109. }
  110. static int wcd937x_set_port_params(struct snd_soc_codec *codec, u8 slv_prt_type,
  111. u8 *port_id, u8 *num_ch, u8 *ch_mask, u32 *ch_rate,
  112. u8 *port_type, u8 path)
  113. {
  114. int i, j;
  115. u8 num_ports = 0;
  116. struct codec_port_info (*map)[MAX_PORT][MAX_CH_PER_PORT] = NULL;
  117. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  118. switch (path) {
  119. case CODEC_RX:
  120. map = &wcd937x->rx_port_mapping;
  121. num_ports = wcd937x->num_rx_ports;
  122. break;
  123. case CODEC_TX:
  124. map = &wcd937x->tx_port_mapping;
  125. num_ports = wcd937x->num_tx_ports;
  126. break;
  127. }
  128. for (i = 0; i <= num_ports; i++) {
  129. for (j = 0; j < MAX_CH_PER_PORT; j++) {
  130. if ((*map)[i][j].slave_port_type == slv_prt_type)
  131. goto found;
  132. }
  133. }
  134. found:
  135. if (i > num_ports || j == MAX_CH_PER_PORT) {
  136. dev_err(codec->dev, "%s Failed to find slave port for type %u\n",
  137. __func__, slv_prt_type);
  138. return -EINVAL;
  139. }
  140. *port_id = i;
  141. *num_ch = (*map)[i][j].num_ch;
  142. *ch_mask = (*map)[i][j].ch_mask;
  143. *ch_rate = (*map)[i][j].ch_rate;
  144. *port_type = (*map)[i][j].master_port_type;
  145. return 0;
  146. }
  147. static int wcd937x_parse_port_mapping(struct device *dev,
  148. char *prop, u8 path)
  149. {
  150. u32 *dt_array, map_size, map_length;
  151. u32 port_num = 0, ch_mask, ch_rate, old_port_num = 0;
  152. u32 slave_port_type, master_port_type;
  153. u32 i, ch_iter = 0;
  154. int ret = 0;
  155. u8 *num_ports = NULL;
  156. struct codec_port_info (*map)[MAX_PORT][MAX_CH_PER_PORT] = NULL;
  157. struct wcd937x_priv *wcd937x = dev_get_drvdata(dev);
  158. switch (path) {
  159. case CODEC_RX:
  160. map = &wcd937x->rx_port_mapping;
  161. num_ports = &wcd937x->num_rx_ports;
  162. break;
  163. case CODEC_TX:
  164. map = &wcd937x->tx_port_mapping;
  165. num_ports = &wcd937x->num_tx_ports;
  166. break;
  167. }
  168. if (!of_find_property(dev->of_node, prop,
  169. &map_size)) {
  170. dev_err(dev, "missing port mapping prop %s\n", prop);
  171. ret = -EINVAL;
  172. goto err;
  173. }
  174. map_length = map_size / (NUM_SWRS_DT_PARAMS * sizeof(u32));
  175. dt_array = kzalloc(map_size, GFP_KERNEL);
  176. if (!dt_array) {
  177. ret = -ENOMEM;
  178. goto err;
  179. }
  180. ret = of_property_read_u32_array(dev->of_node, prop, dt_array,
  181. NUM_SWRS_DT_PARAMS * map_length);
  182. if (ret) {
  183. dev_err(dev, "%s: Failed to read port mapping from prop %s\n",
  184. __func__, prop);
  185. ret = -EINVAL;
  186. goto err_pdata_fail;
  187. }
  188. for (i = 0; i < map_length; i++) {
  189. port_num = dt_array[NUM_SWRS_DT_PARAMS * i];
  190. slave_port_type = dt_array[NUM_SWRS_DT_PARAMS * i + 1];
  191. ch_mask = dt_array[NUM_SWRS_DT_PARAMS * i + 2];
  192. ch_rate = dt_array[NUM_SWRS_DT_PARAMS * i + 3];
  193. master_port_type = dt_array[NUM_SWRS_DT_PARAMS * i + 4];
  194. if (port_num != old_port_num)
  195. ch_iter = 0;
  196. (*map)[port_num][ch_iter].slave_port_type = slave_port_type;
  197. (*map)[port_num][ch_iter].ch_mask = ch_mask;
  198. (*map)[port_num][ch_iter].master_port_type = master_port_type;
  199. (*map)[port_num][ch_iter].num_ch = __sw_hweight8(ch_mask);
  200. (*map)[port_num][ch_iter++].ch_rate = ch_rate;
  201. old_port_num = port_num;
  202. }
  203. *num_ports = port_num;
  204. kfree(dt_array);
  205. return 0;
  206. err_pdata_fail:
  207. kfree(dt_array);
  208. err:
  209. return ret;
  210. }
  211. static int wcd937x_tx_connect_port(struct snd_soc_codec *codec,
  212. u8 slv_port_type, u8 enable)
  213. {
  214. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  215. u8 port_id;
  216. u8 num_ch;
  217. u8 ch_mask;
  218. u32 ch_rate;
  219. u8 port_type;
  220. u8 num_port = 1;
  221. int ret = 0;
  222. ret = wcd937x_set_port_params(codec, slv_port_type, &port_id,
  223. &num_ch, &ch_mask, &ch_rate,
  224. &port_type, CODEC_TX);
  225. if (ret)
  226. return ret;
  227. if (enable)
  228. ret = swr_connect_port(wcd937x->tx_swr_dev, &port_id,
  229. num_port, &ch_mask, &ch_rate,
  230. &num_ch, &port_type);
  231. else
  232. ret = swr_disconnect_port(wcd937x->tx_swr_dev, &port_id,
  233. num_port, &ch_mask, &port_type);
  234. return ret;
  235. }
  236. static int wcd937x_rx_connect_port(struct snd_soc_codec *codec,
  237. u8 slv_port_type, u8 enable)
  238. {
  239. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  240. u8 port_id;
  241. u8 num_ch;
  242. u8 ch_mask;
  243. u32 ch_rate;
  244. u8 port_type;
  245. u8 num_port = 1;
  246. int ret = 0;
  247. ret = wcd937x_set_port_params(codec, slv_port_type, &port_id,
  248. &num_ch, &ch_mask, &ch_rate,
  249. &port_type, CODEC_RX);
  250. if (ret)
  251. return ret;
  252. if (enable)
  253. ret = swr_connect_port(wcd937x->rx_swr_dev, &port_id,
  254. num_port, &ch_mask, &ch_rate,
  255. &num_ch, &port_type);
  256. else
  257. ret = swr_disconnect_port(wcd937x->rx_swr_dev, &port_id,
  258. num_port, &ch_mask, &port_type);
  259. return ret;
  260. }
  261. static int wcd937x_rx_clk_enable(struct snd_soc_codec *codec)
  262. {
  263. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  264. if (wcd937x->rx_clk_cnt == 0) {
  265. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_DIG_CLK_CTL,
  266. 0x08, 0x08);
  267. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_ANA_CLK_CTL,
  268. 0x01, 0x01);
  269. snd_soc_update_bits(codec, WCD937X_ANA_RX_SUPPLIES, 0x01, 0x01);
  270. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_RX0_CTL,
  271. 0x40, 0x00);
  272. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_RX1_CTL,
  273. 0x40, 0x00);
  274. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_RX2_CTL,
  275. 0x40, 0x00);
  276. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_ANA_CLK_CTL,
  277. 0x02, 0x02);
  278. }
  279. wcd937x->rx_clk_cnt++;
  280. return 0;
  281. }
  282. static int wcd937x_rx_clk_disable(struct snd_soc_codec *codec)
  283. {
  284. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  285. if (wcd937x->rx_clk_cnt == 0) {
  286. dev_dbg(wcd937x->dev, "%s:clk already disabled\n", __func__);
  287. return 0;
  288. }
  289. wcd937x->rx_clk_cnt--;
  290. if (wcd937x->rx_clk_cnt == 0) {
  291. snd_soc_update_bits(codec, WCD937X_ANA_RX_SUPPLIES, 0x01, 0x00);
  292. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_ANA_CLK_CTL,
  293. 0x02, 0x00);
  294. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_ANA_CLK_CTL,
  295. 0x01, 0x00);
  296. }
  297. return 0;
  298. }
  299. /*
  300. * wcd937x_soc_get_mbhc: get wcd937x_mbhc handle of corresponding codec
  301. * @codec: handle to snd_soc_codec *
  302. *
  303. * return wcd937x_mbhc handle or error code in case of failure
  304. */
  305. struct wcd937x_mbhc *wcd937x_soc_get_mbhc(struct snd_soc_codec *codec)
  306. {
  307. struct wcd937x_priv *wcd937x;
  308. if (!codec) {
  309. pr_err("%s: Invalid params, NULL codec\n", __func__);
  310. return NULL;
  311. }
  312. wcd937x = snd_soc_codec_get_drvdata(codec);
  313. if (!wcd937x) {
  314. pr_err("%s: Invalid params, NULL tavil\n", __func__);
  315. return NULL;
  316. }
  317. return wcd937x->mbhc;
  318. }
  319. EXPORT_SYMBOL(wcd937x_soc_get_mbhc);
  320. static int wcd937x_codec_hphl_dac_event(struct snd_soc_dapm_widget *w,
  321. struct snd_kcontrol *kcontrol,
  322. int event)
  323. {
  324. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  325. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  326. int hph_mode = wcd937x->hph_mode;
  327. int ret = 0;
  328. dev_dbg(codec->dev, "%s wname: %s event: %d\n", __func__,
  329. w->name, event);
  330. switch (event) {
  331. case SND_SOC_DAPM_PRE_PMU:
  332. wcd937x_rx_clk_enable(codec);
  333. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_DIG_CLK_CTL,
  334. 0x01, 0x01);
  335. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_HPH_GAIN_CTL,
  336. 0x04, 0x04);
  337. snd_soc_update_bits(codec, WCD937X_HPH_RDAC_CLK_CTL1,
  338. 0x80, 0x00);
  339. break;
  340. case SND_SOC_DAPM_POST_PMU:
  341. if (hph_mode == CLS_AB_HIFI || hph_mode == CLS_H_HIFI)
  342. snd_soc_update_bits(codec,
  343. WCD937X_HPH_NEW_INT_RDAC_HD2_CTL_L,
  344. 0x0F, 0x02);
  345. else if (hph_mode == CLS_H_LOHIFI)
  346. snd_soc_update_bits(codec,
  347. WCD937X_HPH_NEW_INT_RDAC_HD2_CTL_L,
  348. 0x0F, 0x06);
  349. if (wcd937x->comp1_enable) {
  350. snd_soc_update_bits(codec,
  351. WCD937X_DIGITAL_CDC_COMP_CTL_0,
  352. 0x02, 0x02);
  353. snd_soc_update_bits(codec,
  354. WCD937X_HPH_L_EN, 0x20, 0x00);
  355. } else {
  356. snd_soc_update_bits(codec,
  357. WCD937X_DIGITAL_CDC_COMP_CTL_0,
  358. 0x02, 0x00);
  359. snd_soc_update_bits(codec,
  360. WCD937X_HPH_L_EN, 0x20, 0x20);
  361. }
  362. usleep_range(5000, 5010);
  363. snd_soc_update_bits(codec, WCD937X_HPH_NEW_INT_HPH_TIMER1,
  364. 0x02, 0x00);
  365. wcd_cls_h_fsm(codec, &wcd937x->clsh_info,
  366. WCD_CLSH_EVENT_PRE_DAC,
  367. WCD_CLSH_STATE_HPHL,
  368. hph_mode);
  369. break;
  370. case SND_SOC_DAPM_POST_PMD:
  371. snd_soc_update_bits(codec,
  372. WCD937X_HPH_NEW_INT_RDAC_HD2_CTL_L,
  373. 0x0F, 0x01);
  374. ret = swr_slvdev_datapath_control(wcd937x->rx_swr_dev,
  375. wcd937x->rx_swr_dev->dev_num,
  376. false);
  377. break;
  378. }
  379. return ret;
  380. }
  381. static int wcd937x_codec_hphr_dac_event(struct snd_soc_dapm_widget *w,
  382. struct snd_kcontrol *kcontrol,
  383. int event)
  384. {
  385. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  386. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  387. int hph_mode = wcd937x->hph_mode;
  388. int ret = 0;
  389. dev_dbg(codec->dev, "%s wname: %s event: %d\n", __func__,
  390. w->name, event);
  391. switch (event) {
  392. case SND_SOC_DAPM_PRE_PMU:
  393. wcd937x_rx_clk_enable(codec);
  394. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_DIG_CLK_CTL,
  395. 0x02, 0x02);
  396. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_HPH_GAIN_CTL,
  397. 0x08, 0x08);
  398. snd_soc_update_bits(codec, WCD937X_HPH_RDAC_CLK_CTL1,
  399. 0x80, 0x00);
  400. break;
  401. case SND_SOC_DAPM_POST_PMU:
  402. if (hph_mode == CLS_AB_HIFI || hph_mode == CLS_H_HIFI)
  403. snd_soc_update_bits(codec,
  404. WCD937X_HPH_NEW_INT_RDAC_HD2_CTL_R,
  405. 0x0F, 0x02);
  406. else if (hph_mode == CLS_H_LOHIFI)
  407. snd_soc_update_bits(codec,
  408. WCD937X_HPH_NEW_INT_RDAC_HD2_CTL_R,
  409. 0x0F, 0x06);
  410. if (wcd937x->comp2_enable) {
  411. snd_soc_update_bits(codec,
  412. WCD937X_DIGITAL_CDC_COMP_CTL_0,
  413. 0x01, 0x01);
  414. snd_soc_update_bits(codec,
  415. WCD937X_HPH_R_EN, 0x20, 0x00);
  416. } else {
  417. snd_soc_update_bits(codec,
  418. WCD937X_DIGITAL_CDC_COMP_CTL_0,
  419. 0x01, 0x00);
  420. snd_soc_update_bits(codec,
  421. WCD937X_HPH_R_EN, 0x20, 0x20);
  422. }
  423. usleep_range(5000, 5010);
  424. snd_soc_update_bits(codec, WCD937X_HPH_NEW_INT_HPH_TIMER1,
  425. 0x02, 0x00);
  426. wcd_cls_h_fsm(codec, &wcd937x->clsh_info,
  427. WCD_CLSH_EVENT_PRE_DAC,
  428. WCD_CLSH_STATE_HPHR,
  429. hph_mode);
  430. break;
  431. case SND_SOC_DAPM_POST_PMD:
  432. snd_soc_update_bits(codec,
  433. WCD937X_HPH_NEW_INT_RDAC_HD2_CTL_R,
  434. 0x0F, 0x01);
  435. ret = swr_slvdev_datapath_control(wcd937x->rx_swr_dev,
  436. wcd937x->rx_swr_dev->dev_num,
  437. false);
  438. break;
  439. }
  440. return ret;
  441. }
  442. static int wcd937x_codec_ear_dac_event(struct snd_soc_dapm_widget *w,
  443. struct snd_kcontrol *kcontrol,
  444. int event)
  445. {
  446. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  447. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  448. int hph_mode = wcd937x->hph_mode;
  449. int ret = 0;
  450. dev_dbg(codec->dev, "%s wname: %s event: %d\n", __func__,
  451. w->name, event);
  452. switch (event) {
  453. case SND_SOC_DAPM_PRE_PMU:
  454. wcd937x_rx_clk_enable(codec);
  455. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_HPH_GAIN_CTL,
  456. 0x04, 0x04);
  457. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_DIG_CLK_CTL,
  458. 0x01, 0x01);
  459. if (hph_mode == CLS_AB_HIFI || hph_mode == CLS_H_HIFI)
  460. snd_soc_update_bits(codec,
  461. WCD937X_HPH_NEW_INT_RDAC_HD2_CTL_L,
  462. 0x0F, 0x02);
  463. else if (hph_mode == CLS_H_LOHIFI)
  464. snd_soc_update_bits(codec,
  465. WCD937X_HPH_NEW_INT_RDAC_HD2_CTL_L,
  466. 0x0F, 0x06);
  467. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_COMP_CTL_0,
  468. 0x02, 0x02);
  469. usleep_range(5000, 5010);
  470. wcd_cls_h_fsm(codec, &wcd937x->clsh_info,
  471. WCD_CLSH_EVENT_PRE_DAC,
  472. WCD_CLSH_STATE_EAR,
  473. hph_mode);
  474. break;
  475. case SND_SOC_DAPM_POST_PMD:
  476. if (hph_mode == CLS_AB_HIFI || hph_mode == CLS_H_LOHIFI ||
  477. hph_mode == CLS_H_HIFI)
  478. snd_soc_update_bits(codec,
  479. WCD937X_HPH_NEW_INT_RDAC_HD2_CTL_L,
  480. 0x0F, 0x01);
  481. ret = swr_slvdev_datapath_control(wcd937x->rx_swr_dev,
  482. wcd937x->rx_swr_dev->dev_num,
  483. false);
  484. break;
  485. };
  486. return ret;
  487. }
  488. static int wcd937x_codec_aux_dac_event(struct snd_soc_dapm_widget *w,
  489. struct snd_kcontrol *kcontrol,
  490. int event)
  491. {
  492. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  493. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  494. int hph_mode = wcd937x->hph_mode;
  495. int ret = 0;
  496. dev_dbg(codec->dev, "%s wname: %s event: %d\n", __func__,
  497. w->name, event);
  498. switch (event) {
  499. case SND_SOC_DAPM_PRE_PMU:
  500. wcd937x_rx_clk_enable(codec);
  501. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_ANA_CLK_CTL,
  502. 0x04, 0x04);
  503. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_DIG_CLK_CTL,
  504. 0x04, 0x04);
  505. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_AUX_GAIN_CTL,
  506. 0x01, 0x01);
  507. wcd_cls_h_fsm(codec, &wcd937x->clsh_info,
  508. WCD_CLSH_EVENT_PRE_DAC,
  509. WCD_CLSH_STATE_AUX,
  510. hph_mode);
  511. break;
  512. case SND_SOC_DAPM_POST_PMD:
  513. ret = swr_slvdev_datapath_control(wcd937x->rx_swr_dev,
  514. wcd937x->rx_swr_dev->dev_num,
  515. false);
  516. wcd937x_rx_clk_disable(codec);
  517. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_ANA_CLK_CTL,
  518. 0x04, 0x00);
  519. break;
  520. };
  521. return ret;
  522. }
  523. static int wcd937x_codec_enable_hphr_pa(struct snd_soc_dapm_widget *w,
  524. struct snd_kcontrol *kcontrol,
  525. int event)
  526. {
  527. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  528. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  529. int ret = 0;
  530. int hph_mode = wcd937x->hph_mode;
  531. dev_dbg(codec->dev, "%s wname: %s event: %d\n", __func__,
  532. w->name, event);
  533. switch (event) {
  534. case SND_SOC_DAPM_PRE_PMU:
  535. snd_soc_update_bits(codec, WCD937X_ANA_HPH, 0x10, 0x10);
  536. usleep_range(100, 110);
  537. ret = swr_slvdev_datapath_control(wcd937x->rx_swr_dev,
  538. wcd937x->rx_swr_dev->dev_num,
  539. true);
  540. break;
  541. case SND_SOC_DAPM_POST_PMU:
  542. usleep_range(7000, 7010);
  543. snd_soc_update_bits(codec, WCD937X_HPH_NEW_INT_HPH_TIMER1,
  544. 0x02, 0x02);
  545. if (hph_mode == CLS_AB || hph_mode == CLS_AB_HIFI)
  546. snd_soc_update_bits(codec, WCD937X_ANA_RX_SUPPLIES,
  547. 0x02, 0x02);
  548. if (wcd937x->update_wcd_event)
  549. wcd937x->update_wcd_event(wcd937x->handle,
  550. WCD_BOLERO_EVT_RX_MUTE,
  551. (WCD_RX2 << 0x10));
  552. break;
  553. case SND_SOC_DAPM_PRE_PMD:
  554. if (wcd937x->update_wcd_event)
  555. wcd937x->update_wcd_event(wcd937x->handle,
  556. WCD_BOLERO_EVT_RX_MUTE,
  557. (WCD_RX2 << 0x10 | 0x1));
  558. blocking_notifier_call_chain(&wcd937x->mbhc->notifier,
  559. WCD_EVENT_PRE_HPHR_PA_OFF,
  560. &wcd937x->mbhc->wcd_mbhc);
  561. break;
  562. case SND_SOC_DAPM_POST_PMD:
  563. usleep_range(7000, 7010);
  564. blocking_notifier_call_chain(&wcd937x->mbhc->notifier,
  565. WCD_EVENT_POST_HPHR_PA_OFF,
  566. &wcd937x->mbhc->wcd_mbhc);
  567. snd_soc_update_bits(codec, WCD937X_ANA_HPH, 0x10, 0x00);
  568. wcd_cls_h_fsm(codec, &wcd937x->clsh_info,
  569. WCD_CLSH_EVENT_POST_PA,
  570. WCD_CLSH_STATE_HPHR,
  571. hph_mode);
  572. break;
  573. };
  574. return ret;
  575. }
  576. static int wcd937x_codec_enable_hphl_pa(struct snd_soc_dapm_widget *w,
  577. struct snd_kcontrol *kcontrol,
  578. int event)
  579. {
  580. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  581. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  582. int ret = 0;
  583. int hph_mode = wcd937x->hph_mode;
  584. switch (event) {
  585. case SND_SOC_DAPM_PRE_PMU:
  586. snd_soc_update_bits(codec, WCD937X_ANA_HPH, 0x20, 0x20);
  587. usleep_range(100, 110);
  588. ret = swr_slvdev_datapath_control(wcd937x->rx_swr_dev,
  589. wcd937x->rx_swr_dev->dev_num,
  590. true);
  591. break;
  592. case SND_SOC_DAPM_POST_PMU:
  593. usleep_range(7000, 7010);
  594. snd_soc_update_bits(codec, WCD937X_HPH_NEW_INT_HPH_TIMER1,
  595. 0x02, 0x02);
  596. if (hph_mode == CLS_AB || hph_mode == CLS_AB_HIFI)
  597. snd_soc_update_bits(codec, WCD937X_ANA_RX_SUPPLIES,
  598. 0x02, 0x02);
  599. if (wcd937x->update_wcd_event)
  600. wcd937x->update_wcd_event(wcd937x->handle,
  601. WCD_BOLERO_EVT_RX_MUTE,
  602. (WCD_RX1 << 0x10));
  603. break;
  604. case SND_SOC_DAPM_PRE_PMD:
  605. if (wcd937x->update_wcd_event)
  606. wcd937x->update_wcd_event(wcd937x->handle,
  607. WCD_BOLERO_EVT_RX_MUTE,
  608. (WCD_RX1 << 0x10 | 0x1));
  609. blocking_notifier_call_chain(&wcd937x->mbhc->notifier,
  610. WCD_EVENT_PRE_HPHL_PA_OFF,
  611. &wcd937x->mbhc->wcd_mbhc);
  612. break;
  613. case SND_SOC_DAPM_POST_PMD:
  614. usleep_range(7000, 7010);
  615. blocking_notifier_call_chain(&wcd937x->mbhc->notifier,
  616. WCD_EVENT_POST_HPHL_PA_OFF,
  617. &wcd937x->mbhc->wcd_mbhc);
  618. snd_soc_update_bits(codec, WCD937X_ANA_HPH, 0x20, 0x00);
  619. wcd_cls_h_fsm(codec, &wcd937x->clsh_info,
  620. WCD_CLSH_EVENT_POST_PA,
  621. WCD_CLSH_STATE_HPHL,
  622. hph_mode);
  623. break;
  624. };
  625. return ret;
  626. }
  627. static int wcd937x_codec_enable_aux_pa(struct snd_soc_dapm_widget *w,
  628. struct snd_kcontrol *kcontrol,
  629. int event)
  630. {
  631. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  632. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  633. int hph_mode = wcd937x->hph_mode;
  634. int ret = 0;
  635. dev_dbg(codec->dev, "%s wname: %s event: %d\n", __func__,
  636. w->name, event);
  637. switch (event) {
  638. case SND_SOC_DAPM_PRE_PMU:
  639. ret = swr_slvdev_datapath_control(wcd937x->rx_swr_dev,
  640. wcd937x->rx_swr_dev->dev_num,
  641. true);
  642. break;
  643. case SND_SOC_DAPM_POST_PMU:
  644. usleep_range(1000, 1010);
  645. if (hph_mode == CLS_AB || hph_mode == CLS_AB_HIFI)
  646. snd_soc_update_bits(codec, WCD937X_ANA_RX_SUPPLIES,
  647. 0x02, 0x02);
  648. if (wcd937x->update_wcd_event)
  649. wcd937x->update_wcd_event(wcd937x->handle,
  650. WCD_BOLERO_EVT_RX_MUTE,
  651. (WCD_RX3 << 0x10));
  652. break;
  653. case SND_SOC_DAPM_PRE_PMD:
  654. if (wcd937x->update_wcd_event)
  655. wcd937x->update_wcd_event(wcd937x->handle,
  656. WCD_BOLERO_EVT_RX_MUTE,
  657. (WCD_RX3 << 0x10 | 0x1));
  658. break;
  659. case SND_SOC_DAPM_POST_PMD:
  660. usleep_range(1000, 1010);
  661. usleep_range(1000, 1010);
  662. wcd_cls_h_fsm(codec, &wcd937x->clsh_info,
  663. WCD_CLSH_EVENT_POST_PA,
  664. WCD_CLSH_STATE_AUX,
  665. hph_mode);
  666. break;
  667. };
  668. return ret;
  669. }
  670. static int wcd937x_codec_enable_ear_pa(struct snd_soc_dapm_widget *w,
  671. struct snd_kcontrol *kcontrol,
  672. int event)
  673. {
  674. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  675. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  676. int hph_mode = wcd937x->hph_mode;
  677. int ret = 0;
  678. dev_dbg(codec->dev, "%s wname: %s event: %d\n", __func__,
  679. w->name, event);
  680. switch (event) {
  681. case SND_SOC_DAPM_PRE_PMU:
  682. ret = swr_slvdev_datapath_control(wcd937x->rx_swr_dev,
  683. wcd937x->rx_swr_dev->dev_num,
  684. true);
  685. break;
  686. case SND_SOC_DAPM_POST_PMU:
  687. usleep_range(6000, 6010);
  688. if (hph_mode == CLS_AB || hph_mode == CLS_AB_HIFI)
  689. snd_soc_update_bits(codec, WCD937X_ANA_RX_SUPPLIES,
  690. 0x02, 0x02);
  691. if (wcd937x->update_wcd_event)
  692. wcd937x->update_wcd_event(wcd937x->handle,
  693. WCD_BOLERO_EVT_RX_MUTE,
  694. (WCD_RX1 << 0x10));
  695. break;
  696. case SND_SOC_DAPM_PRE_PMD:
  697. if (wcd937x->update_wcd_event)
  698. wcd937x->update_wcd_event(wcd937x->handle,
  699. WCD_BOLERO_EVT_RX_MUTE,
  700. (WCD_RX1 << 0x10 | 0x1));
  701. break;
  702. case SND_SOC_DAPM_POST_PMD:
  703. usleep_range(7000, 7010);
  704. wcd_cls_h_fsm(codec, &wcd937x->clsh_info,
  705. WCD_CLSH_EVENT_POST_PA,
  706. WCD_CLSH_STATE_EAR,
  707. hph_mode);
  708. break;
  709. };
  710. return ret;
  711. }
  712. static int wcd937x_enable_clsh(struct snd_soc_dapm_widget *w,
  713. struct snd_kcontrol *kcontrol,
  714. int event)
  715. {
  716. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  717. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  718. int mode = wcd937x->hph_mode;
  719. int ret = 0;
  720. dev_dbg(codec->dev, "%s wname: %s event: %d\n", __func__,
  721. w->name, event);
  722. if (mode == CLS_H_LOHIFI || mode == CLS_H_ULP ||
  723. mode == CLS_H_HIFI || mode == CLS_H_LP) {
  724. wcd937x_rx_connect_port(codec, CLSH,
  725. SND_SOC_DAPM_EVENT_ON(event));
  726. if (SND_SOC_DAPM_EVENT_OFF(event))
  727. ret = swr_slvdev_datapath_control(
  728. wcd937x->rx_swr_dev,
  729. wcd937x->rx_swr_dev->dev_num,
  730. false);
  731. }
  732. return ret;
  733. }
  734. static int wcd937x_enable_rx1(struct snd_soc_dapm_widget *w,
  735. struct snd_kcontrol *kcontrol,
  736. int event)
  737. {
  738. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  739. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  740. dev_dbg(codec->dev, "%s wname: %s event: %d\n", __func__,
  741. w->name, event);
  742. switch (event) {
  743. case SND_SOC_DAPM_PRE_PMU:
  744. wcd937x_rx_connect_port(codec, HPH_L, true);
  745. if (wcd937x->comp1_enable)
  746. wcd937x_rx_connect_port(codec, COMP_L, true);
  747. break;
  748. case SND_SOC_DAPM_POST_PMD:
  749. wcd937x_rx_connect_port(codec, HPH_L, false);
  750. if (wcd937x->comp1_enable)
  751. wcd937x_rx_connect_port(codec, COMP_L, false);
  752. wcd937x_rx_clk_disable(codec);
  753. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_DIG_CLK_CTL,
  754. 0x01, 0x00);
  755. break;
  756. };
  757. return 0;
  758. }
  759. static int wcd937x_enable_rx2(struct snd_soc_dapm_widget *w,
  760. struct snd_kcontrol *kcontrol, int event)
  761. {
  762. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  763. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  764. dev_dbg(codec->dev, "%s wname: %s event: %d\n", __func__,
  765. w->name, event);
  766. switch (event) {
  767. case SND_SOC_DAPM_PRE_PMU:
  768. wcd937x_rx_connect_port(codec, HPH_R, true);
  769. if (wcd937x->comp2_enable)
  770. wcd937x_rx_connect_port(codec, COMP_R, true);
  771. break;
  772. case SND_SOC_DAPM_POST_PMD:
  773. wcd937x_rx_connect_port(codec, HPH_R, false);
  774. if (wcd937x->comp2_enable)
  775. wcd937x_rx_connect_port(codec, COMP_R, false);
  776. wcd937x_rx_clk_disable(codec);
  777. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_DIG_CLK_CTL,
  778. 0x02, 0x00);
  779. break;
  780. };
  781. return 0;
  782. }
  783. static int wcd937x_enable_rx3(struct snd_soc_dapm_widget *w,
  784. struct snd_kcontrol *kcontrol,
  785. int event)
  786. {
  787. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  788. dev_dbg(codec->dev, "%s wname: %s event: %d\n", __func__,
  789. w->name, event);
  790. switch (event) {
  791. case SND_SOC_DAPM_PRE_PMU:
  792. wcd937x_rx_connect_port(codec, LO, true);
  793. break;
  794. case SND_SOC_DAPM_POST_PMD:
  795. wcd937x_rx_connect_port(codec, LO, false);
  796. usleep_range(6000, 6010);
  797. wcd937x_rx_clk_disable(codec);
  798. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_DIG_CLK_CTL,
  799. 0x04, 0x00);
  800. break;
  801. }
  802. return 0;
  803. }
  804. static int wcd937x_codec_enable_dmic(struct snd_soc_dapm_widget *w,
  805. struct snd_kcontrol *kcontrol,
  806. int event)
  807. {
  808. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  809. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  810. u16 dmic_clk_reg;
  811. s32 *dmic_clk_cnt;
  812. unsigned int dmic;
  813. char *wname;
  814. int ret = 0;
  815. wname = strpbrk(w->name, "012345");
  816. if (!wname) {
  817. dev_err(codec->dev, "%s: widget not found\n", __func__);
  818. return -EINVAL;
  819. }
  820. ret = kstrtouint(wname, 10, &dmic);
  821. if (ret < 0) {
  822. dev_err(codec->dev, "%s: Invalid DMIC line on the codec\n",
  823. __func__);
  824. return -EINVAL;
  825. }
  826. dev_dbg(codec->dev, "%s wname: %s event: %d\n", __func__,
  827. w->name, event);
  828. switch (dmic) {
  829. case 0:
  830. case 1:
  831. dmic_clk_cnt = &(wcd937x->dmic_0_1_clk_cnt);
  832. dmic_clk_reg = WCD937X_DIGITAL_CDC_DMIC0_CTL;
  833. break;
  834. case 2:
  835. case 3:
  836. dmic_clk_cnt = &(wcd937x->dmic_2_3_clk_cnt);
  837. dmic_clk_reg = WCD937X_DIGITAL_CDC_DMIC1_CTL;
  838. break;
  839. case 4:
  840. case 5:
  841. dmic_clk_cnt = &(wcd937x->dmic_4_5_clk_cnt);
  842. dmic_clk_reg = WCD937X_DIGITAL_CDC_DMIC2_CTL;
  843. break;
  844. default:
  845. dev_err(codec->dev, "%s: Invalid DMIC Selection\n",
  846. __func__);
  847. return -EINVAL;
  848. };
  849. dev_dbg(codec->dev, "%s: event %d DMIC%d dmic_clk_cnt %d\n",
  850. __func__, event, dmic, *dmic_clk_cnt);
  851. switch (event) {
  852. case SND_SOC_DAPM_PRE_PMU:
  853. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_DIG_CLK_CTL,
  854. 0x80, 0x80);
  855. snd_soc_update_bits(codec, dmic_clk_reg, 0x07, 0x02);
  856. snd_soc_update_bits(codec, dmic_clk_reg, 0x08, 0x08);
  857. snd_soc_update_bits(codec, dmic_clk_reg, 0x70, 0x20);
  858. wcd937x_tx_connect_port(codec, DMIC0 + (w->shift), true);
  859. break;
  860. case SND_SOC_DAPM_POST_PMD:
  861. wcd937x_tx_connect_port(codec, DMIC0 + (w->shift), false);
  862. break;
  863. };
  864. return 0;
  865. }
  866. /*
  867. * wcd937x_get_micb_vout_ctl_val: converts micbias from volts to register value
  868. * @micb_mv: micbias in mv
  869. *
  870. * return register value converted
  871. */
  872. int wcd937x_get_micb_vout_ctl_val(u32 micb_mv)
  873. {
  874. /* min micbias voltage is 1V and maximum is 2.85V */
  875. if (micb_mv < 1000 || micb_mv > 2850) {
  876. pr_err("%s: unsupported micbias voltage\n", __func__);
  877. return -EINVAL;
  878. }
  879. return (micb_mv - 1000) / 50;
  880. }
  881. EXPORT_SYMBOL(wcd937x_get_micb_vout_ctl_val);
  882. /*
  883. * wcd937x_mbhc_micb_adjust_voltage: adjust specific micbias voltage
  884. * @codec: handle to snd_soc_codec *
  885. * @req_volt: micbias voltage to be set
  886. * @micb_num: micbias to be set, e.g. micbias1 or micbias2
  887. *
  888. * return 0 if adjustment is success or error code in case of failure
  889. */
  890. int wcd937x_mbhc_micb_adjust_voltage(struct snd_soc_codec *codec,
  891. int req_volt, int micb_num)
  892. {
  893. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  894. int cur_vout_ctl, req_vout_ctl;
  895. int micb_reg, micb_val, micb_en;
  896. int ret = 0;
  897. switch (micb_num) {
  898. case MIC_BIAS_1:
  899. micb_reg = WCD937X_ANA_MICB1;
  900. break;
  901. case MIC_BIAS_2:
  902. micb_reg = WCD937X_ANA_MICB2;
  903. break;
  904. case MIC_BIAS_3:
  905. micb_reg = WCD937X_ANA_MICB3;
  906. break;
  907. default:
  908. return -EINVAL;
  909. }
  910. mutex_lock(&wcd937x->micb_lock);
  911. /*
  912. * If requested micbias voltage is same as current micbias
  913. * voltage, then just return. Otherwise, adjust voltage as
  914. * per requested value. If micbias is already enabled, then
  915. * to avoid slow micbias ramp-up or down enable pull-up
  916. * momentarily, change the micbias value and then re-enable
  917. * micbias.
  918. */
  919. micb_val = snd_soc_read(codec, micb_reg);
  920. micb_en = (micb_val & 0xC0) >> 6;
  921. cur_vout_ctl = micb_val & 0x3F;
  922. req_vout_ctl = wcd937x_get_micb_vout_ctl_val(req_volt);
  923. if (req_vout_ctl < 0) {
  924. ret = -EINVAL;
  925. goto exit;
  926. }
  927. if (cur_vout_ctl == req_vout_ctl) {
  928. ret = 0;
  929. goto exit;
  930. }
  931. dev_dbg(codec->dev, "%s: micb_num: %d, cur_mv: %d, req_mv: %d, micb_en: %d\n",
  932. __func__, micb_num, WCD_VOUT_CTL_TO_MICB(cur_vout_ctl),
  933. req_volt, micb_en);
  934. if (micb_en == 0x1)
  935. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x80);
  936. snd_soc_update_bits(codec, micb_reg, 0x3F, req_vout_ctl);
  937. if (micb_en == 0x1) {
  938. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x40);
  939. /*
  940. * Add 2ms delay as per HW requirement after enabling
  941. * micbias
  942. */
  943. usleep_range(2000, 2100);
  944. }
  945. exit:
  946. mutex_unlock(&wcd937x->micb_lock);
  947. return ret;
  948. }
  949. EXPORT_SYMBOL(wcd937x_mbhc_micb_adjust_voltage);
  950. static int wcd937x_tx_swr_ctrl(struct snd_soc_dapm_widget *w,
  951. struct snd_kcontrol *kcontrol,
  952. int event)
  953. {
  954. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  955. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  956. int ret = 0;
  957. switch (event) {
  958. case SND_SOC_DAPM_PRE_PMU:
  959. ret = swr_slvdev_datapath_control(wcd937x->tx_swr_dev,
  960. wcd937x->tx_swr_dev->dev_num,
  961. true);
  962. break;
  963. case SND_SOC_DAPM_POST_PMD:
  964. ret = swr_slvdev_datapath_control(wcd937x->tx_swr_dev,
  965. wcd937x->tx_swr_dev->dev_num,
  966. false);
  967. break;
  968. };
  969. return ret;
  970. }
  971. static int wcd937x_codec_enable_adc(struct snd_soc_dapm_widget *w,
  972. struct snd_kcontrol *kcontrol,
  973. int event){
  974. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  975. dev_dbg(codec->dev, "%s wname: %s event: %d\n", __func__,
  976. w->name, event);
  977. switch (event) {
  978. case SND_SOC_DAPM_PRE_PMU:
  979. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_DIG_CLK_CTL,
  980. 0x80, 0x80);
  981. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_ANA_CLK_CTL,
  982. 0x08, 0x08);
  983. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_ANA_CLK_CTL,
  984. 0x10, 0x10);
  985. wcd937x_tx_connect_port(codec, ADC1 + (w->shift), true);
  986. break;
  987. case SND_SOC_DAPM_POST_PMD:
  988. wcd937x_tx_connect_port(codec, ADC1 + (w->shift), false);
  989. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_ANA_CLK_CTL,
  990. 0x08, 0x00);
  991. break;
  992. };
  993. return 0;
  994. }
  995. static int wcd937x_enable_req(struct snd_soc_dapm_widget *w,
  996. struct snd_kcontrol *kcontrol, int event)
  997. {
  998. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  999. dev_dbg(codec->dev, "%s wname: %s event: %d\n", __func__,
  1000. w->name, event);
  1001. switch (event) {
  1002. case SND_SOC_DAPM_PRE_PMU:
  1003. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_REQ_CTL,
  1004. 0x02, 0x02);
  1005. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_REQ_CTL, 0x01,
  1006. 0x00);
  1007. snd_soc_update_bits(codec, WCD937X_ANA_TX_CH2, 0x40, 0x40);
  1008. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_DIG_CLK_CTL,
  1009. 0x30, 0x30);
  1010. snd_soc_update_bits(codec, WCD937X_ANA_TX_CH1, 0x80, 0x80);
  1011. snd_soc_update_bits(codec, WCD937X_ANA_TX_CH2, 0x40, 0x00);
  1012. snd_soc_update_bits(codec, WCD937X_ANA_TX_CH2, 0x80, 0x80);
  1013. break;
  1014. case SND_SOC_DAPM_POST_PMD:
  1015. snd_soc_update_bits(codec, WCD937X_ANA_TX_CH1, 0x80, 0x00);
  1016. snd_soc_update_bits(codec, WCD937X_ANA_TX_CH2, 0x80, 0x00);
  1017. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_DIG_CLK_CTL,
  1018. 0x10, 0x00);
  1019. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_ANA_CLK_CTL,
  1020. 0x10, 0x00);
  1021. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_DIG_CLK_CTL,
  1022. 0x80, 0x00);
  1023. break;
  1024. };
  1025. return 0;
  1026. }
  1027. int wcd937x_micbias_control(struct snd_soc_codec *codec,
  1028. int micb_num, int req, bool is_dapm)
  1029. {
  1030. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  1031. int micb_index = micb_num - 1;
  1032. u16 micb_reg;
  1033. int pre_off_event = 0, post_off_event = 0;
  1034. int post_on_event = 0, post_dapm_off = 0;
  1035. int post_dapm_on = 0;
  1036. if ((micb_index < 0) || (micb_index > WCD937X_MAX_MICBIAS - 1)) {
  1037. dev_err(codec->dev, "%s: Invalid micbias index, micb_ind:%d\n",
  1038. __func__, micb_index);
  1039. return -EINVAL;
  1040. }
  1041. switch (micb_num) {
  1042. case MIC_BIAS_1:
  1043. micb_reg = WCD937X_ANA_MICB1;
  1044. break;
  1045. case MIC_BIAS_2:
  1046. micb_reg = WCD937X_ANA_MICB2;
  1047. pre_off_event = WCD_EVENT_PRE_MICBIAS_2_OFF;
  1048. post_off_event = WCD_EVENT_POST_MICBIAS_2_OFF;
  1049. post_on_event = WCD_EVENT_POST_MICBIAS_2_ON;
  1050. post_dapm_on = WCD_EVENT_POST_DAPM_MICBIAS_2_ON;
  1051. post_dapm_off = WCD_EVENT_POST_DAPM_MICBIAS_2_OFF;
  1052. break;
  1053. case MIC_BIAS_3:
  1054. micb_reg = WCD937X_ANA_MICB3;
  1055. break;
  1056. default:
  1057. dev_err(codec->dev, "%s: Invalid micbias number: %d\n",
  1058. __func__, micb_num);
  1059. return -EINVAL;
  1060. };
  1061. mutex_lock(&wcd937x->micb_lock);
  1062. switch (req) {
  1063. case MICB_PULLUP_ENABLE:
  1064. wcd937x->pullup_ref[micb_index]++;
  1065. if ((wcd937x->pullup_ref[micb_index] == 1) &&
  1066. (wcd937x->micb_ref[micb_index] == 0))
  1067. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x80);
  1068. break;
  1069. case MICB_PULLUP_DISABLE:
  1070. if (wcd937x->pullup_ref[micb_index] > 0)
  1071. wcd937x->pullup_ref[micb_index]--;
  1072. if ((wcd937x->pullup_ref[micb_index] == 0) &&
  1073. (wcd937x->micb_ref[micb_index] == 0))
  1074. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x00);
  1075. break;
  1076. case MICB_ENABLE:
  1077. wcd937x->micb_ref[micb_index]++;
  1078. if (wcd937x->micb_ref[micb_index] == 1) {
  1079. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_DIG_CLK_CTL, 0xE0, 0xE0);
  1080. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_ANA_CLK_CTL, 0x10, 0x10);
  1081. snd_soc_update_bits(codec, WCD937X_MICB1_TEST_CTL_2, 0x01, 0x01);
  1082. snd_soc_update_bits(codec, WCD937X_MICB2_TEST_CTL_2, 0x01, 0x01);
  1083. snd_soc_update_bits(codec, WCD937X_MICB3_TEST_CTL_2, 0x01, 0x01);
  1084. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x40);
  1085. if (post_on_event && wcd937x->mbhc)
  1086. blocking_notifier_call_chain(
  1087. &wcd937x->mbhc->notifier, post_on_event,
  1088. &wcd937x->mbhc->wcd_mbhc);
  1089. }
  1090. if (is_dapm && post_dapm_on && wcd937x->mbhc)
  1091. blocking_notifier_call_chain(
  1092. &wcd937x->mbhc->notifier, post_dapm_on,
  1093. &wcd937x->mbhc->wcd_mbhc);
  1094. break;
  1095. case MICB_DISABLE:
  1096. if (wcd937x->micb_ref[micb_index] > 0)
  1097. wcd937x->micb_ref[micb_index]--;
  1098. if ((wcd937x->micb_ref[micb_index] == 0) &&
  1099. (wcd937x->pullup_ref[micb_index] > 0))
  1100. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x80);
  1101. else if ((wcd937x->micb_ref[micb_index] == 0) &&
  1102. (wcd937x->pullup_ref[micb_index] == 0)) {
  1103. if (pre_off_event && wcd937x->mbhc)
  1104. blocking_notifier_call_chain(
  1105. &wcd937x->mbhc->notifier, pre_off_event,
  1106. &wcd937x->mbhc->wcd_mbhc);
  1107. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x00);
  1108. if (post_off_event && wcd937x->mbhc)
  1109. blocking_notifier_call_chain(
  1110. &wcd937x->mbhc->notifier,
  1111. post_off_event,
  1112. &wcd937x->mbhc->wcd_mbhc);
  1113. }
  1114. if (is_dapm && post_dapm_off && wcd937x->mbhc)
  1115. blocking_notifier_call_chain(
  1116. &wcd937x->mbhc->notifier, post_dapm_off,
  1117. &wcd937x->mbhc->wcd_mbhc);
  1118. break;
  1119. };
  1120. dev_dbg(codec->dev, "%s: micb_num:%d, micb_ref: %d, pullup_ref: %d\n",
  1121. __func__, micb_num, wcd937x->micb_ref[micb_index],
  1122. wcd937x->pullup_ref[micb_index]);
  1123. mutex_unlock(&wcd937x->micb_lock);
  1124. return 0;
  1125. }
  1126. EXPORT_SYMBOL(wcd937x_micbias_control);
  1127. static int wcd937x_get_logical_addr(struct swr_device *swr_dev)
  1128. {
  1129. int ret = 0;
  1130. uint8_t devnum = 0;
  1131. ret = swr_get_logical_dev_num(swr_dev, swr_dev->addr, &devnum);
  1132. if (ret) {
  1133. dev_err(&swr_dev->dev,
  1134. "%s get devnum %d for dev addr %lx failed\n",
  1135. __func__, devnum, swr_dev->addr);
  1136. swr_remove_device(swr_dev);
  1137. return ret;
  1138. }
  1139. swr_dev->dev_num = devnum;
  1140. return 0;
  1141. }
  1142. static int wcd937x_event_notify(struct notifier_block *block,
  1143. unsigned long val,
  1144. void *data)
  1145. {
  1146. u16 event = (val & 0xffff);
  1147. u16 amic = (val >> 0x10);
  1148. u16 mask = 0x40, reg = 0x0;
  1149. int ret = 0;
  1150. struct wcd937x_priv *wcd937x = dev_get_drvdata((struct device *)data);
  1151. struct snd_soc_codec *codec = wcd937x->codec;
  1152. struct wcd_mbhc *mbhc;
  1153. switch (event) {
  1154. case BOLERO_WCD_EVT_TX_CH_HOLD_CLEAR:
  1155. if (amic == 0x1 || amic == 0x2)
  1156. reg = WCD937X_ANA_TX_CH2;
  1157. else if (amic == 0x3)
  1158. reg = WCD937X_ANA_TX_CH3_HPF;
  1159. else
  1160. return 0;
  1161. if (amic == 0x2)
  1162. mask = 0x20;
  1163. snd_soc_update_bits(codec, reg, mask, 0x00);
  1164. break;
  1165. case BOLERO_WCD_EVT_SSR_DOWN:
  1166. wcd937x_reset_low(wcd937x->dev);
  1167. break;
  1168. case BOLERO_WCD_EVT_SSR_UP:
  1169. wcd937x_reset(wcd937x->dev);
  1170. wcd937x_get_logical_addr(wcd937x->tx_swr_dev);
  1171. wcd937x_get_logical_addr(wcd937x->rx_swr_dev);
  1172. regcache_mark_dirty(wcd937x->regmap);
  1173. regcache_sync(wcd937x->regmap);
  1174. /* Initialize MBHC module */
  1175. mbhc = &wcd937x->mbhc->wcd_mbhc;
  1176. ret = wcd937x_mbhc_post_ssr_init(wcd937x->mbhc, codec);
  1177. if (ret) {
  1178. dev_err(codec->dev, "%s: mbhc initialization failed\n",
  1179. __func__);
  1180. } else {
  1181. wcd937x_mbhc_hs_detect(codec, mbhc->mbhc_cfg);
  1182. }
  1183. break;
  1184. default:
  1185. dev_err(codec->dev, "%s: invalid event %d\n", __func__, event);
  1186. break;
  1187. }
  1188. return 0;
  1189. }
  1190. static int __wcd937x_codec_enable_micbias(struct snd_soc_dapm_widget *w,
  1191. int event)
  1192. {
  1193. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1194. int micb_num;
  1195. dev_dbg(codec->dev, "%s: wname: %s, event: %d\n",
  1196. __func__, w->name, event);
  1197. if (strnstr(w->name, "MIC BIAS1", sizeof("MIC BIAS1")))
  1198. micb_num = MIC_BIAS_1;
  1199. else if (strnstr(w->name, "MIC BIAS2", sizeof("MIC BIAS2")))
  1200. micb_num = MIC_BIAS_2;
  1201. else if (strnstr(w->name, "MIC BIAS3", sizeof("MIC BIAS3")))
  1202. micb_num = MIC_BIAS_3;
  1203. else
  1204. return -EINVAL;
  1205. switch (event) {
  1206. case SND_SOC_DAPM_PRE_PMU:
  1207. wcd937x_micbias_control(codec, micb_num, MICB_ENABLE, true);
  1208. break;
  1209. case SND_SOC_DAPM_POST_PMU:
  1210. usleep_range(1000, 1100);
  1211. break;
  1212. case SND_SOC_DAPM_POST_PMD:
  1213. wcd937x_micbias_control(codec, micb_num, MICB_DISABLE, true);
  1214. break;
  1215. };
  1216. return 0;
  1217. }
  1218. static int wcd937x_codec_enable_micbias(struct snd_soc_dapm_widget *w,
  1219. struct snd_kcontrol *kcontrol,
  1220. int event)
  1221. {
  1222. return __wcd937x_codec_enable_micbias(w, event);
  1223. }
  1224. static int wcd937x_rx_hph_mode_get(struct snd_kcontrol *kcontrol,
  1225. struct snd_ctl_elem_value *ucontrol)
  1226. {
  1227. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1228. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  1229. ucontrol->value.integer.value[0] = wcd937x->hph_mode;
  1230. return 0;
  1231. }
  1232. static int wcd937x_rx_hph_mode_put(struct snd_kcontrol *kcontrol,
  1233. struct snd_ctl_elem_value *ucontrol)
  1234. {
  1235. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1236. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  1237. u32 mode_val;
  1238. mode_val = ucontrol->value.enumerated.item[0];
  1239. dev_dbg(codec->dev, "%s: mode: %d\n", __func__, mode_val);
  1240. if (mode_val == 0) {
  1241. dev_warn(codec->dev, "%s:Invalid HPH Mode, default to class_AB\n",
  1242. __func__);
  1243. mode_val = 3; /* enum will be updated later */
  1244. }
  1245. wcd937x->hph_mode = mode_val;
  1246. return 0;
  1247. }
  1248. static int wcd937x_get_compander(struct snd_kcontrol *kcontrol,
  1249. struct snd_ctl_elem_value *ucontrol)
  1250. {
  1251. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1252. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  1253. bool hphr;
  1254. struct soc_multi_mixer_control *mc;
  1255. mc = (struct soc_multi_mixer_control *)(kcontrol->private_value);
  1256. hphr = mc->shift;
  1257. ucontrol->value.integer.value[0] = hphr ? wcd937x->comp2_enable :
  1258. wcd937x->comp1_enable;
  1259. return 0;
  1260. }
  1261. static int wcd937x_set_compander(struct snd_kcontrol *kcontrol,
  1262. struct snd_ctl_elem_value *ucontrol)
  1263. {
  1264. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1265. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  1266. int value = ucontrol->value.integer.value[0];
  1267. bool hphr;
  1268. struct soc_multi_mixer_control *mc;
  1269. mc = (struct soc_multi_mixer_control *)(kcontrol->private_value);
  1270. hphr = mc->shift;
  1271. if (hphr)
  1272. wcd937x->comp2_enable = value;
  1273. else
  1274. wcd937x->comp1_enable = value;
  1275. return 0;
  1276. }
  1277. static int wcd937x_codec_enable_vdd_buck(struct snd_soc_dapm_widget *w,
  1278. struct snd_kcontrol *kcontrol,
  1279. int event)
  1280. {
  1281. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1282. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  1283. struct wcd937x_pdata *pdata = NULL;
  1284. int ret = 0;
  1285. pdata = dev_get_platdata(wcd937x->dev);
  1286. if (!pdata) {
  1287. dev_err(codec->dev, "%s: pdata is NULL\n", __func__);
  1288. return -EINVAL;
  1289. }
  1290. dev_dbg(codec->dev, "%s wname: %s event: %d\n", __func__,
  1291. w->name, event);
  1292. switch (event) {
  1293. case SND_SOC_DAPM_PRE_PMU:
  1294. ret = msm_cdc_enable_ondemand_supply(wcd937x->dev,
  1295. wcd937x->supplies,
  1296. pdata->regulator,
  1297. pdata->num_supplies,
  1298. "cdc-vdd-buck");
  1299. if (ret == -EINVAL) {
  1300. dev_err(codec->dev, "%s: vdd buck is not enabled\n",
  1301. __func__);
  1302. return ret;
  1303. }
  1304. /*
  1305. * 200us sleep is required after LDO15 is enabled as per
  1306. * HW requirement
  1307. */
  1308. usleep_range(200, 250);
  1309. break;
  1310. case SND_SOC_DAPM_POST_PMD:
  1311. ret = msm_cdc_disable_ondemand_supply(wcd937x->dev,
  1312. wcd937x->supplies,
  1313. pdata->regulator,
  1314. pdata->num_supplies,
  1315. "cdc-vdd-buck");
  1316. if (ret == -EINVAL) {
  1317. dev_err(codec->dev, "%s: vdd buck is not enabled\n",
  1318. __func__);
  1319. return ret;
  1320. }
  1321. break;
  1322. }
  1323. return 0;
  1324. }
  1325. static const char * const rx_hph_mode_mux_text[] = {
  1326. "CLS_H_INVALID", "CLS_H_HIFI", "CLS_H_LP", "CLS_AB", "CLS_H_LOHIFI",
  1327. "CLS_H_ULP", "CLS_AB_HIFI",
  1328. };
  1329. static const struct soc_enum rx_hph_mode_mux_enum =
  1330. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(rx_hph_mode_mux_text),
  1331. rx_hph_mode_mux_text);
  1332. static const struct snd_kcontrol_new wcd937x_snd_controls[] = {
  1333. SOC_ENUM_EXT("RX HPH Mode", rx_hph_mode_mux_enum,
  1334. wcd937x_rx_hph_mode_get, wcd937x_rx_hph_mode_put),
  1335. SOC_SINGLE_EXT("HPHL_COMP Switch", SND_SOC_NOPM, 0, 1, 0,
  1336. wcd937x_get_compander, wcd937x_set_compander),
  1337. SOC_SINGLE_EXT("HPHR_COMP Switch", SND_SOC_NOPM, 1, 1, 0,
  1338. wcd937x_get_compander, wcd937x_set_compander),
  1339. SOC_SINGLE_TLV("HPHL Volume", WCD937X_HPH_L_EN, 0, 20, 1, line_gain),
  1340. SOC_SINGLE_TLV("HPHR Volume", WCD937X_HPH_R_EN, 0, 20, 1, line_gain),
  1341. SOC_SINGLE_TLV("ADC1 Volume", WCD937X_ANA_TX_CH1, 0, 20, 0, analog_gain),
  1342. SOC_SINGLE_TLV("ADC2 Volume", WCD937X_ANA_TX_CH2, 0, 20, 0, analog_gain),
  1343. SOC_SINGLE_TLV("ADC3 Volume", WCD937X_ANA_TX_CH3, 0, 20, 0, analog_gain),
  1344. };
  1345. static const struct snd_kcontrol_new adc1_switch[] = {
  1346. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1347. };
  1348. static const struct snd_kcontrol_new adc2_switch[] = {
  1349. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1350. };
  1351. static const struct snd_kcontrol_new adc3_switch[] = {
  1352. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1353. };
  1354. static const struct snd_kcontrol_new dmic1_switch[] = {
  1355. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1356. };
  1357. static const struct snd_kcontrol_new dmic2_switch[] = {
  1358. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1359. };
  1360. static const struct snd_kcontrol_new dmic3_switch[] = {
  1361. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1362. };
  1363. static const struct snd_kcontrol_new dmic4_switch[] = {
  1364. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1365. };
  1366. static const struct snd_kcontrol_new dmic5_switch[] = {
  1367. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1368. };
  1369. static const struct snd_kcontrol_new dmic6_switch[] = {
  1370. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1371. };
  1372. static const struct snd_kcontrol_new ear_rdac_switch[] = {
  1373. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1374. };
  1375. static const struct snd_kcontrol_new aux_rdac_switch[] = {
  1376. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1377. };
  1378. static const struct snd_kcontrol_new hphl_rdac_switch[] = {
  1379. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1380. };
  1381. static const struct snd_kcontrol_new hphr_rdac_switch[] = {
  1382. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1383. };
  1384. static const char * const adc2_mux_text[] = {
  1385. "INP2", "INP3"
  1386. };
  1387. static const char * const rdac3_mux_text[] = {
  1388. "RX1", "RX3"
  1389. };
  1390. static const struct soc_enum adc2_enum =
  1391. SOC_ENUM_SINGLE(WCD937X_TX_NEW_TX_CH2_SEL, 7,
  1392. ARRAY_SIZE(adc2_mux_text), adc2_mux_text);
  1393. static const struct soc_enum rdac3_enum =
  1394. SOC_ENUM_SINGLE(WCD937X_DIGITAL_CDC_EAR_PATH_CTL, 0,
  1395. ARRAY_SIZE(rdac3_mux_text), rdac3_mux_text);
  1396. static const struct snd_kcontrol_new tx_adc2_mux =
  1397. SOC_DAPM_ENUM("ADC2 MUX Mux", adc2_enum);
  1398. static const struct snd_kcontrol_new rx_rdac3_mux =
  1399. SOC_DAPM_ENUM("RDAC3_MUX Mux", rdac3_enum);
  1400. static const struct snd_soc_dapm_widget wcd937x_dapm_widgets[] = {
  1401. /*input widgets*/
  1402. SND_SOC_DAPM_INPUT("AMIC1"),
  1403. SND_SOC_DAPM_INPUT("AMIC2"),
  1404. SND_SOC_DAPM_INPUT("AMIC3"),
  1405. SND_SOC_DAPM_INPUT("IN1_HPHL"),
  1406. SND_SOC_DAPM_INPUT("IN2_HPHR"),
  1407. SND_SOC_DAPM_INPUT("IN3_AUX"),
  1408. /*tx widgets*/
  1409. SND_SOC_DAPM_ADC_E("ADC1", NULL, SND_SOC_NOPM, 0, 0,
  1410. wcd937x_codec_enable_adc,
  1411. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1412. SND_SOC_DAPM_ADC_E("ADC2", NULL, SND_SOC_NOPM, 1, 0,
  1413. wcd937x_codec_enable_adc,
  1414. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1415. SND_SOC_DAPM_MIXER_E("ADC1 REQ", SND_SOC_NOPM, 0, 0,
  1416. NULL, 0, wcd937x_enable_req,
  1417. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1418. SND_SOC_DAPM_MIXER_E("ADC2 REQ", SND_SOC_NOPM, 0, 0,
  1419. NULL, 0, wcd937x_enable_req,
  1420. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1421. SND_SOC_DAPM_MUX("ADC2 MUX", SND_SOC_NOPM, 0, 0,
  1422. &tx_adc2_mux),
  1423. /*tx mixers*/
  1424. SND_SOC_DAPM_MIXER_E("ADC1_MIXER", SND_SOC_NOPM, 0, 0,
  1425. adc1_switch, ARRAY_SIZE(adc1_switch),
  1426. wcd937x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  1427. SND_SOC_DAPM_POST_PMD),
  1428. SND_SOC_DAPM_MIXER_E("ADC2_MIXER", SND_SOC_NOPM, 0, 0,
  1429. adc2_switch, ARRAY_SIZE(adc2_switch),
  1430. wcd937x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  1431. SND_SOC_DAPM_POST_PMD),
  1432. /* micbias widgets*/
  1433. SND_SOC_DAPM_MICBIAS_E("MIC BIAS1", SND_SOC_NOPM, 0, 0,
  1434. wcd937x_codec_enable_micbias,
  1435. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1436. SND_SOC_DAPM_POST_PMD),
  1437. SND_SOC_DAPM_MICBIAS_E("MIC BIAS2", SND_SOC_NOPM, 0, 0,
  1438. wcd937x_codec_enable_micbias,
  1439. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1440. SND_SOC_DAPM_POST_PMD),
  1441. SND_SOC_DAPM_MICBIAS_E("MIC BIAS3", SND_SOC_NOPM, 0, 0,
  1442. wcd937x_codec_enable_micbias,
  1443. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1444. SND_SOC_DAPM_POST_PMD),
  1445. SND_SOC_DAPM_SUPPLY("VDD_BUCK", SND_SOC_NOPM, 0, 0,
  1446. wcd937x_codec_enable_vdd_buck,
  1447. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1448. SND_SOC_DAPM_SUPPLY("CLS_H_PORT", SND_SOC_NOPM, 0, 0,
  1449. wcd937x_enable_clsh,
  1450. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1451. /*rx widgets*/
  1452. SND_SOC_DAPM_PGA_E("EAR PGA", WCD937X_ANA_EAR, 7, 0, NULL, 0,
  1453. wcd937x_codec_enable_ear_pa,
  1454. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1455. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1456. SND_SOC_DAPM_PGA_E("AUX PGA", WCD937X_AUX_AUXPA, 7, 0, NULL, 0,
  1457. wcd937x_codec_enable_aux_pa,
  1458. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1459. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1460. SND_SOC_DAPM_PGA_E("HPHL PGA", WCD937X_ANA_HPH, 7, 0, NULL, 0,
  1461. wcd937x_codec_enable_hphl_pa,
  1462. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1463. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1464. SND_SOC_DAPM_PGA_E("HPHR PGA", WCD937X_ANA_HPH, 6, 0, NULL, 0,
  1465. wcd937x_codec_enable_hphr_pa,
  1466. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1467. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1468. SND_SOC_DAPM_DAC_E("RDAC1", NULL, SND_SOC_NOPM, 0, 0,
  1469. wcd937x_codec_hphl_dac_event,
  1470. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1471. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1472. SND_SOC_DAPM_DAC_E("RDAC2", NULL, SND_SOC_NOPM, 0, 0,
  1473. wcd937x_codec_hphr_dac_event,
  1474. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1475. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1476. SND_SOC_DAPM_DAC_E("RDAC3", NULL, SND_SOC_NOPM, 0, 0,
  1477. wcd937x_codec_ear_dac_event,
  1478. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1479. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1480. SND_SOC_DAPM_DAC_E("RDAC4", NULL, SND_SOC_NOPM, 0, 0,
  1481. wcd937x_codec_aux_dac_event,
  1482. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1483. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1484. SND_SOC_DAPM_MUX("RDAC3_MUX", SND_SOC_NOPM, 0, 0, &rx_rdac3_mux),
  1485. SND_SOC_DAPM_MIXER_E("RX1", SND_SOC_NOPM, 0, 0, NULL, 0,
  1486. wcd937x_enable_rx1, SND_SOC_DAPM_PRE_PMU |
  1487. SND_SOC_DAPM_POST_PMD),
  1488. SND_SOC_DAPM_MIXER_E("RX2", SND_SOC_NOPM, 0, 0, NULL, 0,
  1489. wcd937x_enable_rx2, SND_SOC_DAPM_PRE_PMU |
  1490. SND_SOC_DAPM_POST_PMD),
  1491. SND_SOC_DAPM_MIXER_E("RX3", SND_SOC_NOPM, 0, 0, NULL, 0,
  1492. wcd937x_enable_rx3, SND_SOC_DAPM_PRE_PMU |
  1493. SND_SOC_DAPM_POST_PMD),
  1494. /* rx mixer widgets*/
  1495. SND_SOC_DAPM_MIXER("EAR_RDAC", SND_SOC_NOPM, 0, 0,
  1496. ear_rdac_switch, ARRAY_SIZE(ear_rdac_switch)),
  1497. SND_SOC_DAPM_MIXER("AUX_RDAC", SND_SOC_NOPM, 0, 0,
  1498. aux_rdac_switch, ARRAY_SIZE(aux_rdac_switch)),
  1499. SND_SOC_DAPM_MIXER("HPHL_RDAC", SND_SOC_NOPM, 0, 0,
  1500. hphl_rdac_switch, ARRAY_SIZE(hphl_rdac_switch)),
  1501. SND_SOC_DAPM_MIXER("HPHR_RDAC", SND_SOC_NOPM, 0, 0,
  1502. hphr_rdac_switch, ARRAY_SIZE(hphr_rdac_switch)),
  1503. /*output widgets tx*/
  1504. SND_SOC_DAPM_OUTPUT("ADC1_OUTPUT"),
  1505. SND_SOC_DAPM_OUTPUT("ADC2_OUTPUT"),
  1506. /*output widgets rx*/
  1507. SND_SOC_DAPM_OUTPUT("EAR"),
  1508. SND_SOC_DAPM_OUTPUT("AUX"),
  1509. SND_SOC_DAPM_OUTPUT("HPHL"),
  1510. SND_SOC_DAPM_OUTPUT("HPHR"),
  1511. };
  1512. static const struct snd_soc_dapm_widget wcd9375_dapm_widgets[] = {
  1513. /*input widgets*/
  1514. SND_SOC_DAPM_INPUT("AMIC4"),
  1515. /*tx widgets*/
  1516. SND_SOC_DAPM_ADC_E("ADC3", NULL, SND_SOC_NOPM, 2, 0,
  1517. wcd937x_codec_enable_adc,
  1518. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1519. SND_SOC_DAPM_MIXER_E("ADC3 REQ", SND_SOC_NOPM, 0, 0,
  1520. NULL, 0, wcd937x_enable_req,
  1521. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1522. SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 0, 0,
  1523. wcd937x_codec_enable_dmic,
  1524. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1525. SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 1, 0,
  1526. wcd937x_codec_enable_dmic,
  1527. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1528. SND_SOC_DAPM_ADC_E("DMIC3", NULL, SND_SOC_NOPM, 2, 0,
  1529. wcd937x_codec_enable_dmic,
  1530. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1531. SND_SOC_DAPM_ADC_E("DMIC4", NULL, SND_SOC_NOPM, 3, 0,
  1532. wcd937x_codec_enable_dmic,
  1533. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1534. SND_SOC_DAPM_ADC_E("DMIC5", NULL, SND_SOC_NOPM, 4, 0,
  1535. wcd937x_codec_enable_dmic,
  1536. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1537. SND_SOC_DAPM_ADC_E("DMIC6", NULL, SND_SOC_NOPM, 5, 0,
  1538. wcd937x_codec_enable_dmic,
  1539. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1540. /*tx mixer widgets*/
  1541. SND_SOC_DAPM_MIXER_E("DMIC1_MIXER", SND_SOC_NOPM, 0,
  1542. 0, dmic1_switch, ARRAY_SIZE(dmic1_switch),
  1543. wcd937x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  1544. SND_SOC_DAPM_POST_PMD),
  1545. SND_SOC_DAPM_MIXER_E("DMIC2_MIXER", SND_SOC_NOPM, 0,
  1546. 0, dmic2_switch, ARRAY_SIZE(dmic2_switch),
  1547. wcd937x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  1548. SND_SOC_DAPM_POST_PMD),
  1549. SND_SOC_DAPM_MIXER_E("DMIC3_MIXER", SND_SOC_NOPM, 0,
  1550. 0, dmic3_switch, ARRAY_SIZE(dmic3_switch),
  1551. wcd937x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  1552. SND_SOC_DAPM_POST_PMD),
  1553. SND_SOC_DAPM_MIXER_E("DMIC4_MIXER", SND_SOC_NOPM, 0,
  1554. 0, dmic4_switch, ARRAY_SIZE(dmic4_switch),
  1555. wcd937x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  1556. SND_SOC_DAPM_POST_PMD),
  1557. SND_SOC_DAPM_MIXER_E("DMIC5_MIXER", SND_SOC_NOPM, 0,
  1558. 0, dmic5_switch, ARRAY_SIZE(dmic5_switch),
  1559. wcd937x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  1560. SND_SOC_DAPM_POST_PMD),
  1561. SND_SOC_DAPM_MIXER_E("DMIC6_MIXER", SND_SOC_NOPM, 0,
  1562. 0, dmic6_switch, ARRAY_SIZE(dmic6_switch),
  1563. wcd937x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  1564. SND_SOC_DAPM_POST_PMD),
  1565. SND_SOC_DAPM_MIXER_E("ADC3_MIXER", SND_SOC_NOPM, 0, 0, adc3_switch,
  1566. ARRAY_SIZE(adc3_switch), wcd937x_tx_swr_ctrl,
  1567. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1568. /*output widgets*/
  1569. SND_SOC_DAPM_OUTPUT("DMIC1_OUTPUT"),
  1570. SND_SOC_DAPM_OUTPUT("DMIC2_OUTPUT"),
  1571. SND_SOC_DAPM_OUTPUT("DMIC3_OUTPUT"),
  1572. SND_SOC_DAPM_OUTPUT("DMIC4_OUTPUT"),
  1573. SND_SOC_DAPM_OUTPUT("DMIC5_OUTPUT"),
  1574. SND_SOC_DAPM_OUTPUT("DMIC6_OUTPUT"),
  1575. SND_SOC_DAPM_OUTPUT("ADC3_OUTPUT"),
  1576. };
  1577. static const struct snd_soc_dapm_route wcd937x_audio_map[] = {
  1578. {"ADC1_OUTPUT", NULL, "ADC1_MIXER"},
  1579. {"ADC1_MIXER", "Switch", "ADC1 REQ"},
  1580. {"ADC1 REQ", NULL, "ADC1"},
  1581. {"ADC1", NULL, "AMIC1"},
  1582. {"ADC2_OUTPUT", NULL, "ADC2_MIXER"},
  1583. {"ADC2_MIXER", "Switch", "ADC2 REQ"},
  1584. {"ADC2 REQ", NULL, "ADC2"},
  1585. {"ADC2", NULL, "ADC2 MUX"},
  1586. {"ADC2 MUX", "INP3", "AMIC3"},
  1587. {"ADC2 MUX", "INP2", "AMIC2"},
  1588. {"RX1", NULL, "IN1_HPHL"},
  1589. {"RDAC1", NULL, "RX1"},
  1590. {"HPHL_RDAC", "Switch", "RDAC1"},
  1591. {"HPHL PGA", NULL, "HPHL_RDAC"},
  1592. {"HPHL", NULL, "HPHL PGA"},
  1593. {"RX2", NULL, "IN2_HPHR"},
  1594. {"RDAC2", NULL, "RX2"},
  1595. {"HPHR_RDAC", "Switch", "RDAC2"},
  1596. {"HPHR PGA", NULL, "HPHR_RDAC"},
  1597. {"HPHR", NULL, "HPHR PGA"},
  1598. {"RX3", NULL, "IN3_AUX"},
  1599. {"RDAC4", NULL, "RX3"},
  1600. {"AUX_RDAC", "Switch", "RDAC4"},
  1601. {"AUX PGA", NULL, "AUX_RDAC"},
  1602. {"AUX", NULL, "AUX PGA"},
  1603. {"RDAC3_MUX", "RX3", "RX3"},
  1604. {"RDAC3_MUX", "RX1", "RX1"},
  1605. {"RDAC3", NULL, "RDAC3_MUX"},
  1606. {"EAR_RDAC", "Switch", "RDAC3"},
  1607. {"EAR PGA", NULL, "EAR_RDAC"},
  1608. {"EAR", NULL, "EAR PGA"},
  1609. {"EAR", NULL, "VDD_BUCK"},
  1610. {"HPHR", NULL, "VDD_BUCK"},
  1611. {"HPHL", NULL, "VDD_BUCK"},
  1612. {"AUX", NULL, "VDD_BUCK"},
  1613. {"EAR", NULL, "CLS_H_PORT"},
  1614. {"HPHR", NULL, "CLS_H_PORT"},
  1615. {"HPHL", NULL, "CLS_H_PORT"},
  1616. {"AUX", NULL, "CLS_H_PORT"},
  1617. };
  1618. static const struct snd_soc_dapm_route wcd9375_audio_map[] = {
  1619. {"ADC3_OUTPUT", NULL, "ADC3_MIXER"},
  1620. {"ADC3_MIXER", "Switch", "ADC3 REQ"},
  1621. {"ADC3 REQ", NULL, "ADC3"},
  1622. {"ADC3", NULL, "AMIC4"},
  1623. {"DMIC1_OUTPUT", NULL, "DMIC1_MIXER"},
  1624. {"DMIC1_MIXER", "Switch", "DMIC1"},
  1625. {"DMIC2_OUTPUT", NULL, "DMIC2_MIXER"},
  1626. {"DMIC2_MIXER", "Switch", "DMIC2"},
  1627. {"DMIC3_OUTPUT", NULL, "DMIC3_MIXER"},
  1628. {"DMIC3_MIXER", "Switch", "DMIC3"},
  1629. {"DMIC4_OUTPUT", NULL, "DMIC4_MIXER"},
  1630. {"DMIC4_MIXER", "Switch", "DMIC4"},
  1631. {"DMIC5_OUTPUT", NULL, "DMIC5_MIXER"},
  1632. {"DMIC5_MIXER", "Switch", "DMIC5"},
  1633. {"DMIC6_OUTPUT", NULL, "DMIC6_MIXER"},
  1634. {"DMIC6_MIXER", "Switch", "DMIC6"},
  1635. };
  1636. static ssize_t wcd937x_version_read(struct snd_info_entry *entry,
  1637. void *file_private_data,
  1638. struct file *file,
  1639. char __user *buf, size_t count,
  1640. loff_t pos)
  1641. {
  1642. struct wcd937x_priv *priv;
  1643. char buffer[WCD937X_VERSION_ENTRY_SIZE];
  1644. int len = 0;
  1645. priv = (struct wcd937x_priv *) entry->private_data;
  1646. if (!priv) {
  1647. pr_err("%s: wcd937x priv is null\n", __func__);
  1648. return -EINVAL;
  1649. }
  1650. switch (priv->version) {
  1651. case WCD937X_VERSION_1_0:
  1652. len = snprintf(buffer, sizeof(buffer), "WCD937X_1_0\n");
  1653. break;
  1654. default:
  1655. len = snprintf(buffer, sizeof(buffer), "VER_UNDEFINED\n");
  1656. }
  1657. return simple_read_from_buffer(buf, count, &pos, buffer, len);
  1658. }
  1659. static struct snd_info_entry_ops wcd937x_info_ops = {
  1660. .read = wcd937x_version_read,
  1661. };
  1662. /*
  1663. * wcd937x_info_create_codec_entry - creates wcd937x module
  1664. * @codec_root: The parent directory
  1665. * @codec: Codec instance
  1666. *
  1667. * Creates wcd937x module and version entry under the given
  1668. * parent directory.
  1669. *
  1670. * Return: 0 on success or negative error code on failure.
  1671. */
  1672. int wcd937x_info_create_codec_entry(struct snd_info_entry *codec_root,
  1673. struct snd_soc_codec *codec)
  1674. {
  1675. struct snd_info_entry *version_entry;
  1676. struct wcd937x_priv *priv;
  1677. struct snd_soc_card *card;
  1678. if (!codec_root || !codec)
  1679. return -EINVAL;
  1680. priv = snd_soc_codec_get_drvdata(codec);
  1681. if (priv->entry) {
  1682. dev_dbg(priv->dev,
  1683. "%s:wcd937x module already created\n", __func__);
  1684. return 0;
  1685. }
  1686. card = codec->component.card;
  1687. priv->entry = snd_info_create_subdir(codec_root->module,
  1688. "wcd937x", codec_root);
  1689. if (!priv->entry) {
  1690. dev_dbg(codec->dev, "%s: failed to create wcd937x entry\n",
  1691. __func__);
  1692. return -ENOMEM;
  1693. }
  1694. version_entry = snd_info_create_card_entry(card->snd_card,
  1695. "version",
  1696. priv->entry);
  1697. if (!version_entry) {
  1698. dev_dbg(codec->dev, "%s: failed to create wcd937x version entry\n",
  1699. __func__);
  1700. return -ENOMEM;
  1701. }
  1702. version_entry->private_data = priv;
  1703. version_entry->size = WCD937X_VERSION_ENTRY_SIZE;
  1704. version_entry->content = SNDRV_INFO_CONTENT_DATA;
  1705. version_entry->c.ops = &wcd937x_info_ops;
  1706. if (snd_info_register(version_entry) < 0) {
  1707. snd_info_free_entry(version_entry);
  1708. return -ENOMEM;
  1709. }
  1710. priv->version_entry = version_entry;
  1711. return 0;
  1712. }
  1713. EXPORT_SYMBOL(wcd937x_info_create_codec_entry);
  1714. static int wcd937x_soc_codec_probe(struct snd_soc_codec *codec)
  1715. {
  1716. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  1717. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  1718. int variant;
  1719. int ret = -EINVAL;
  1720. dev_info(codec->dev, "%s()\n", __func__);
  1721. wcd937x = snd_soc_codec_get_drvdata(codec);
  1722. if (!wcd937x)
  1723. return -EINVAL;
  1724. wcd937x->codec = codec;
  1725. variant = (snd_soc_read(codec, WCD937X_DIGITAL_EFUSE_REG_0) & 0x0E) >> 1;
  1726. wcd937x->variant = variant;
  1727. wcd937x->fw_data = devm_kzalloc(codec->dev,
  1728. sizeof(*(wcd937x->fw_data)),
  1729. GFP_KERNEL);
  1730. if (!wcd937x->fw_data) {
  1731. dev_err(codec->dev, "Failed to allocate fw_data\n");
  1732. ret = -ENOMEM;
  1733. goto err;
  1734. }
  1735. set_bit(WCD9XXX_MBHC_CAL, wcd937x->fw_data->cal_bit);
  1736. ret = wcd_cal_create_hwdep(wcd937x->fw_data,
  1737. WCD9XXX_CODEC_HWDEP_NODE, codec);
  1738. if (ret < 0) {
  1739. dev_err(codec->dev, "%s hwdep failed %d\n", __func__, ret);
  1740. goto err_hwdep;
  1741. }
  1742. ret = wcd937x_mbhc_init(&wcd937x->mbhc, codec, wcd937x->fw_data);
  1743. if (ret) {
  1744. pr_err("%s: mbhc initialization failed\n", __func__);
  1745. goto err_hwdep;
  1746. }
  1747. snd_soc_dapm_ignore_suspend(dapm, "AMIC1");
  1748. snd_soc_dapm_ignore_suspend(dapm, "AMIC2");
  1749. snd_soc_dapm_ignore_suspend(dapm, "AMIC3");
  1750. snd_soc_dapm_ignore_suspend(dapm, "IN1_HPHL");
  1751. snd_soc_dapm_ignore_suspend(dapm, "IN2_HPHR");
  1752. snd_soc_dapm_ignore_suspend(dapm, "IN3_AUX");
  1753. snd_soc_dapm_ignore_suspend(dapm, "ADC1_OUTPUT");
  1754. snd_soc_dapm_ignore_suspend(dapm, "ADC2_OUTPUT");
  1755. snd_soc_dapm_ignore_suspend(dapm, "EAR");
  1756. snd_soc_dapm_ignore_suspend(dapm, "AUX");
  1757. snd_soc_dapm_ignore_suspend(dapm, "HPHL");
  1758. snd_soc_dapm_ignore_suspend(dapm, "HPHR");
  1759. snd_soc_dapm_sync(dapm);
  1760. wcd_cls_h_init(&wcd937x->clsh_info);
  1761. wcd937x_init_reg(codec);
  1762. if (wcd937x->variant == WCD9375_VARIANT) {
  1763. ret = snd_soc_dapm_new_controls(dapm, wcd9375_dapm_widgets,
  1764. ARRAY_SIZE(wcd9375_dapm_widgets));
  1765. if (ret < 0) {
  1766. dev_err(codec->dev, "%s: Failed to add snd_ctls\n",
  1767. __func__);
  1768. goto err_hwdep;
  1769. }
  1770. ret = snd_soc_dapm_add_routes(dapm, wcd9375_audio_map,
  1771. ARRAY_SIZE(wcd9375_audio_map));
  1772. if (ret < 0) {
  1773. dev_err(codec->dev, "%s: Failed to add routes\n",
  1774. __func__);
  1775. goto err_hwdep;
  1776. }
  1777. snd_soc_dapm_ignore_suspend(dapm, "AMIC4");
  1778. snd_soc_dapm_ignore_suspend(dapm, "DMIC1_OUTPUT");
  1779. snd_soc_dapm_ignore_suspend(dapm, "DMIC2_OUTPUT");
  1780. snd_soc_dapm_ignore_suspend(dapm, "DMIC3_OUTPUT");
  1781. snd_soc_dapm_ignore_suspend(dapm, "DMIC4_OUTPUT");
  1782. snd_soc_dapm_ignore_suspend(dapm, "DMIC5_OUTPUT");
  1783. snd_soc_dapm_ignore_suspend(dapm, "DMIC6_OUTPUT");
  1784. snd_soc_dapm_ignore_suspend(dapm, "ADC3_OUTPUT");
  1785. snd_soc_dapm_sync(dapm);
  1786. }
  1787. wcd937x->version = WCD937X_VERSION_1_0;
  1788. /* Register event notifier */
  1789. wcd937x->nblock.notifier_call = wcd937x_event_notify;
  1790. if (wcd937x->register_notifier) {
  1791. ret = wcd937x->register_notifier(wcd937x->handle,
  1792. &wcd937x->nblock,
  1793. true);
  1794. if (ret) {
  1795. dev_err(codec->dev,
  1796. "%s: Failed to register notifier %d\n",
  1797. __func__, ret);
  1798. return ret;
  1799. }
  1800. }
  1801. return ret;
  1802. err_hwdep:
  1803. wcd937x->fw_data = NULL;
  1804. err:
  1805. return ret;
  1806. }
  1807. static int wcd937x_soc_codec_remove(struct snd_soc_codec *codec)
  1808. {
  1809. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  1810. if (!wcd937x)
  1811. return -EINVAL;
  1812. if (wcd937x->register_notifier)
  1813. return wcd937x->register_notifier(wcd937x->handle,
  1814. &wcd937x->nblock,
  1815. false);
  1816. return 0;
  1817. }
  1818. static struct regmap *wcd937x_get_regmap(struct device *dev)
  1819. {
  1820. struct wcd937x_priv *wcd937x = dev_get_drvdata(dev);
  1821. return wcd937x->regmap;
  1822. }
  1823. static struct snd_soc_codec_driver soc_codec_dev_wcd937x = {
  1824. .probe = wcd937x_soc_codec_probe,
  1825. .remove = wcd937x_soc_codec_remove,
  1826. .get_regmap = wcd937x_get_regmap,
  1827. .component_driver = {
  1828. .controls = wcd937x_snd_controls,
  1829. .num_controls = ARRAY_SIZE(wcd937x_snd_controls),
  1830. .dapm_widgets = wcd937x_dapm_widgets,
  1831. .num_dapm_widgets = ARRAY_SIZE(wcd937x_dapm_widgets),
  1832. .dapm_routes = wcd937x_audio_map,
  1833. .num_dapm_routes = ARRAY_SIZE(wcd937x_audio_map),
  1834. },
  1835. };
  1836. static int wcd937x_reset(struct device *dev)
  1837. {
  1838. struct wcd937x_priv *wcd937x = NULL;
  1839. int rc = 0;
  1840. int value = 0;
  1841. if (!dev)
  1842. return -ENODEV;
  1843. wcd937x = dev_get_drvdata(dev);
  1844. if (!wcd937x)
  1845. return -EINVAL;
  1846. if (!wcd937x->rst_np) {
  1847. dev_err(dev, "%s: reset gpio device node not specified\n",
  1848. __func__);
  1849. return -EINVAL;
  1850. }
  1851. value = msm_cdc_pinctrl_get_state(wcd937x->rst_np);
  1852. if (value > 0)
  1853. return 0;
  1854. rc = msm_cdc_pinctrl_select_sleep_state(wcd937x->rst_np);
  1855. if (rc) {
  1856. dev_err(dev, "%s: wcd sleep state request fail!\n",
  1857. __func__);
  1858. return rc;
  1859. }
  1860. /* 20ms sleep required after pulling the reset gpio to LOW */
  1861. usleep_range(20, 30);
  1862. rc = msm_cdc_pinctrl_select_active_state(wcd937x->rst_np);
  1863. if (rc) {
  1864. dev_err(dev, "%s: wcd active state request fail!\n",
  1865. __func__);
  1866. return rc;
  1867. }
  1868. /* 20ms sleep required after pulling the reset gpio to HIGH */
  1869. usleep_range(20, 30);
  1870. return rc;
  1871. }
  1872. static int wcd937x_read_of_property_u32(struct device *dev, const char *name,
  1873. u32 *val)
  1874. {
  1875. int rc = 0;
  1876. rc = of_property_read_u32(dev->of_node, name, val);
  1877. if (rc)
  1878. dev_err(dev, "%s: Looking up %s property in node %s failed\n",
  1879. __func__, name, dev->of_node->full_name);
  1880. return rc;
  1881. }
  1882. static void wcd937x_dt_parse_micbias_info(struct device *dev,
  1883. struct wcd937x_micbias_setting *mb)
  1884. {
  1885. u32 prop_val = 0;
  1886. int rc = 0;
  1887. /* MB1 */
  1888. if (of_find_property(dev->of_node, "qcom,cdc-micbias1-mv",
  1889. NULL)) {
  1890. rc = wcd937x_read_of_property_u32(dev,
  1891. "qcom,cdc-micbias1-mv",
  1892. &prop_val);
  1893. if (!rc)
  1894. mb->micb1_mv = prop_val;
  1895. } else {
  1896. dev_info(dev, "%s: Micbias1 DT property not found\n",
  1897. __func__);
  1898. }
  1899. /* MB2 */
  1900. if (of_find_property(dev->of_node, "qcom,cdc-micbias2-mv",
  1901. NULL)) {
  1902. rc = wcd937x_read_of_property_u32(dev,
  1903. "qcom,cdc-micbias2-mv",
  1904. &prop_val);
  1905. if (!rc)
  1906. mb->micb2_mv = prop_val;
  1907. } else {
  1908. dev_info(dev, "%s: Micbias2 DT property not found\n",
  1909. __func__);
  1910. }
  1911. /* MB3 */
  1912. if (of_find_property(dev->of_node, "qcom,cdc-micbias3-mv",
  1913. NULL)) {
  1914. rc = wcd937x_read_of_property_u32(dev,
  1915. "qcom,cdc-micbias3-mv",
  1916. &prop_val);
  1917. if (!rc)
  1918. mb->micb3_mv = prop_val;
  1919. } else {
  1920. dev_info(dev, "%s: Micbias3 DT property not found\n",
  1921. __func__);
  1922. }
  1923. }
  1924. static int wcd937x_reset_low(struct device *dev)
  1925. {
  1926. struct wcd937x_priv *wcd937x = NULL;
  1927. int rc = 0;
  1928. if (!dev)
  1929. return -ENODEV;
  1930. wcd937x = dev_get_drvdata(dev);
  1931. if (!wcd937x)
  1932. return -EINVAL;
  1933. if (!wcd937x->rst_np) {
  1934. dev_err(dev, "%s: reset gpio device node not specified\n",
  1935. __func__);
  1936. return -EINVAL;
  1937. }
  1938. rc = msm_cdc_pinctrl_select_sleep_state(wcd937x->rst_np);
  1939. if (rc) {
  1940. dev_err(dev, "%s: wcd sleep state request fail!\n",
  1941. __func__);
  1942. return rc;
  1943. }
  1944. /* 20ms sleep required after pulling the reset gpio to LOW */
  1945. usleep_range(20, 30);
  1946. return rc;
  1947. }
  1948. struct wcd937x_pdata *wcd937x_populate_dt_data(struct device *dev)
  1949. {
  1950. struct wcd937x_pdata *pdata = NULL;
  1951. pdata = devm_kzalloc(dev, sizeof(struct wcd937x_pdata),
  1952. GFP_KERNEL);
  1953. if (!pdata)
  1954. return NULL;
  1955. pdata->rst_np = of_parse_phandle(dev->of_node,
  1956. "qcom,wcd-rst-gpio-node", 0);
  1957. if (!pdata->rst_np) {
  1958. dev_err(dev, "%s: Looking up %s property in node %s failed\n",
  1959. __func__, "qcom,wcd-rst-gpio-node",
  1960. dev->of_node->full_name);
  1961. return NULL;
  1962. }
  1963. /* Parse power supplies */
  1964. msm_cdc_get_power_supplies(dev, &pdata->regulator,
  1965. &pdata->num_supplies);
  1966. if (!pdata->regulator || (pdata->num_supplies <= 0)) {
  1967. dev_err(dev, "%s: no power supplies defined for codec\n",
  1968. __func__);
  1969. return NULL;
  1970. }
  1971. pdata->rx_slave = of_parse_phandle(dev->of_node, "qcom,rx-slave", 0);
  1972. pdata->tx_slave = of_parse_phandle(dev->of_node, "qcom,tx-slave", 0);
  1973. wcd937x_dt_parse_micbias_info(dev, &pdata->micbias);
  1974. return pdata;
  1975. }
  1976. static int wcd937x_bind(struct device *dev)
  1977. {
  1978. int ret = 0, i = 0;
  1979. struct wcd937x_priv *wcd937x = NULL;
  1980. struct wcd937x_pdata *pdata = NULL;
  1981. struct wcd_ctrl_platform_data *plat_data = NULL;
  1982. wcd937x = devm_kzalloc(dev, sizeof(struct wcd937x_priv), GFP_KERNEL);
  1983. if (!wcd937x)
  1984. return -ENOMEM;
  1985. dev_set_drvdata(dev, wcd937x);
  1986. pdata = wcd937x_populate_dt_data(dev);
  1987. if (!pdata) {
  1988. dev_err(dev, "%s: Fail to obtain platform data\n", __func__);
  1989. return -EINVAL;
  1990. }
  1991. wcd937x->dev = dev;
  1992. wcd937x->dev->platform_data = pdata;
  1993. wcd937x->rst_np = pdata->rst_np;
  1994. ret = msm_cdc_init_supplies(dev, &wcd937x->supplies,
  1995. pdata->regulator, pdata->num_supplies);
  1996. if (!wcd937x->supplies) {
  1997. dev_err(dev, "%s: Cannot init wcd supplies\n",
  1998. __func__);
  1999. return ret;
  2000. }
  2001. plat_data = dev_get_platdata(dev->parent);
  2002. if (!plat_data) {
  2003. dev_err(dev, "%s: platform data from parent is NULL\n",
  2004. __func__);
  2005. return -EINVAL;
  2006. }
  2007. wcd937x->handle = (void *)plat_data->handle;
  2008. if (!wcd937x->handle) {
  2009. dev_err(dev, "%s: handle is NULL\n", __func__);
  2010. return -EINVAL;
  2011. }
  2012. wcd937x->update_wcd_event = plat_data->update_wcd_event;
  2013. if (!wcd937x->update_wcd_event) {
  2014. dev_err(dev, "%s: update_wcd_event api is null!\n",
  2015. __func__);
  2016. return -EINVAL;
  2017. }
  2018. wcd937x->register_notifier = plat_data->register_notifier;
  2019. if (!wcd937x->register_notifier) {
  2020. dev_err(dev, "%s: register_notifier api is null!\n",
  2021. __func__);
  2022. return -EINVAL;
  2023. }
  2024. ret = msm_cdc_enable_static_supplies(dev, wcd937x->supplies,
  2025. pdata->regulator,
  2026. pdata->num_supplies);
  2027. if (ret) {
  2028. dev_err(dev, "%s: wcd static supply enable failed!\n",
  2029. __func__);
  2030. return ret;
  2031. }
  2032. wcd937x_reset(dev);
  2033. /*
  2034. * Add 5msec delay to provide sufficient time for
  2035. * soundwire auto enumeration of slave devices as
  2036. * as per HW requirement.
  2037. */
  2038. usleep_range(5000, 5010);
  2039. ret = component_bind_all(dev, wcd937x);
  2040. if (ret) {
  2041. dev_err(dev, "%s: Slave bind failed, ret = %d\n",
  2042. __func__, ret);
  2043. return ret;
  2044. }
  2045. ret = wcd937x_parse_port_mapping(dev, "qcom,rx_swr_ch_map", CODEC_RX);
  2046. ret |= wcd937x_parse_port_mapping(dev, "qcom,tx_swr_ch_map", CODEC_TX);
  2047. if (ret) {
  2048. dev_err(dev, "Failed to read port mapping\n");
  2049. goto err;
  2050. }
  2051. wcd937x->rx_swr_dev = get_matching_swr_slave_device(pdata->rx_slave);
  2052. if (!wcd937x->rx_swr_dev) {
  2053. dev_err(dev, "%s: Could not find RX swr slave device\n",
  2054. __func__);
  2055. ret = -ENODEV;
  2056. goto err;
  2057. }
  2058. wcd937x->tx_swr_dev = get_matching_swr_slave_device(pdata->tx_slave);
  2059. if (!wcd937x->tx_swr_dev) {
  2060. dev_err(dev, "%s: Could not find TX swr slave device\n",
  2061. __func__);
  2062. ret = -ENODEV;
  2063. goto err;
  2064. }
  2065. wcd937x->regmap = devm_regmap_init_swr(wcd937x->tx_swr_dev,
  2066. &wcd937x_regmap_config);
  2067. if (!wcd937x->regmap) {
  2068. dev_err(dev, "%s: Regmap init failed\n",
  2069. __func__);
  2070. goto err;
  2071. }
  2072. /* Set all interupts as edge triggered */
  2073. for (i = 0; i < wcd937x_regmap_irq_chip.num_regs; i++)
  2074. regmap_write(wcd937x->regmap,
  2075. (WCD937X_DIGITAL_INTR_LEVEL_0 + i), 0);
  2076. wcd937x_regmap_irq_chip.irq_drv_data = wcd937x;
  2077. wcd937x->irq_info.wcd_regmap_irq_chip = &wcd937x_regmap_irq_chip;
  2078. wcd937x->irq_info.codec_name = "WCD937X";
  2079. wcd937x->irq_info.regmap = wcd937x->regmap;
  2080. wcd937x->irq_info.dev = dev;
  2081. ret = wcd_irq_init(&wcd937x->irq_info, &wcd937x->virq);
  2082. if (ret) {
  2083. dev_err(dev, "%s: IRQ init failed: %d\n",
  2084. __func__, ret);
  2085. goto err;
  2086. }
  2087. wcd937x->tx_swr_dev->slave_irq = wcd937x->virq;
  2088. mutex_init(&wcd937x->micb_lock);
  2089. ret = snd_soc_register_codec(dev, &soc_codec_dev_wcd937x,
  2090. NULL, 0);
  2091. if (ret) {
  2092. dev_err(dev, "%s: Codec registration failed\n",
  2093. __func__);
  2094. goto err_irq;
  2095. }
  2096. return ret;
  2097. err_irq:
  2098. wcd_irq_exit(&wcd937x->irq_info, wcd937x->virq);
  2099. err:
  2100. component_unbind_all(dev, wcd937x);
  2101. return ret;
  2102. }
  2103. static void wcd937x_unbind(struct device *dev)
  2104. {
  2105. struct wcd937x_priv *wcd937x = dev_get_drvdata(dev);
  2106. wcd_irq_exit(&wcd937x->irq_info, wcd937x->virq);
  2107. snd_soc_unregister_codec(dev);
  2108. component_unbind_all(dev, wcd937x);
  2109. mutex_destroy(&wcd937x->micb_lock);
  2110. }
  2111. static const struct of_device_id wcd937x_dt_match[] = {
  2112. { .compatible = "qcom,wcd937x-codec" },
  2113. {}
  2114. };
  2115. static const struct component_master_ops wcd937x_comp_ops = {
  2116. .bind = wcd937x_bind,
  2117. .unbind = wcd937x_unbind,
  2118. };
  2119. static int wcd937x_compare_of(struct device *dev, void *data)
  2120. {
  2121. return dev->of_node == data;
  2122. }
  2123. static void wcd937x_release_of(struct device *dev, void *data)
  2124. {
  2125. of_node_put(data);
  2126. }
  2127. static int wcd937x_add_slave_components(struct device *dev,
  2128. struct component_match **matchptr)
  2129. {
  2130. struct device_node *np, *rx_node, *tx_node;
  2131. np = dev->of_node;
  2132. rx_node = of_parse_phandle(np, "qcom,rx-slave", 0);
  2133. if (!rx_node) {
  2134. dev_err(dev, "%s: Rx-slave node not defined\n", __func__);
  2135. return -ENODEV;
  2136. }
  2137. of_node_get(rx_node);
  2138. component_match_add_release(dev, matchptr,
  2139. wcd937x_release_of,
  2140. wcd937x_compare_of,
  2141. rx_node);
  2142. tx_node = of_parse_phandle(np, "qcom,tx-slave", 0);
  2143. if (!tx_node) {
  2144. dev_err(dev, "%s: Tx-slave node not defined\n", __func__);
  2145. return -ENODEV;
  2146. }
  2147. of_node_get(tx_node);
  2148. component_match_add_release(dev, matchptr,
  2149. wcd937x_release_of,
  2150. wcd937x_compare_of,
  2151. tx_node);
  2152. return 0;
  2153. }
  2154. static int wcd937x_probe(struct platform_device *pdev)
  2155. {
  2156. struct component_match *match = NULL;
  2157. int ret;
  2158. ret = wcd937x_add_slave_components(&pdev->dev, &match);
  2159. if (ret)
  2160. return ret;
  2161. return component_master_add_with_match(&pdev->dev,
  2162. &wcd937x_comp_ops, match);
  2163. }
  2164. static int wcd937x_remove(struct platform_device *pdev)
  2165. {
  2166. component_master_del(&pdev->dev, &wcd937x_comp_ops);
  2167. return 0;
  2168. }
  2169. static struct platform_driver wcd937x_codec_driver = {
  2170. .probe = wcd937x_probe,
  2171. .remove = wcd937x_remove,
  2172. .driver = {
  2173. .name = "wcd937x_codec",
  2174. .owner = THIS_MODULE,
  2175. .of_match_table = of_match_ptr(wcd937x_dt_match),
  2176. },
  2177. };
  2178. module_platform_driver(wcd937x_codec_driver);
  2179. MODULE_DESCRIPTION("WCD937X Codec driver");
  2180. MODULE_LICENSE("GPL v2");