wcd937x.c 69 KB

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