wcd937x.c 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970
  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 "../wcdcal-hwdep.h"
  28. #include "wcd937x-registers.h"
  29. #include "../msm-cdc-pinctrl.h"
  30. #include <dt-bindings/sound/audio-codec-port-types.h>
  31. #include "../msm-cdc-supply.h"
  32. #define WCD9370_VARIANT 0
  33. #define WCD9375_VARIANT 5
  34. #define NUM_SWRS_DT_PARAMS 5
  35. enum {
  36. CODEC_TX = 0,
  37. CODEC_RX,
  38. };
  39. static const DECLARE_TLV_DB_SCALE(line_gain, 0, 7, 1);
  40. static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 25, 1);
  41. static int wcd937x_handle_pre_irq(void *data);
  42. static int wcd937x_handle_post_irq(void *data);
  43. static const struct regmap_irq wcd937x_irqs[WCD937X_NUM_IRQS] = {
  44. REGMAP_IRQ_REG(WCD937X_IRQ_MBHC_BUTTON_PRESS_DET, 0, 0x01),
  45. REGMAP_IRQ_REG(WCD937X_IRQ_MBHC_BUTTON_RELEASE_DET, 0, 0x02),
  46. REGMAP_IRQ_REG(WCD937X_IRQ_MBHC_ELECT_INS_REM_DET, 0, 0x04),
  47. REGMAP_IRQ_REG(WCD937X_IRQ_MBHC_ELECT_INS_REM_LEG_DET, 0, 0x08),
  48. REGMAP_IRQ_REG(WCD937X_IRQ_MBHC_SW_DET, 0, 0x10),
  49. REGMAP_IRQ_REG(WCD937X_IRQ_HPHR_OCP_INT, 0, 0x20),
  50. REGMAP_IRQ_REG(WCD937X_IRQ_HPHR_CNP_INT, 0, 0x40),
  51. REGMAP_IRQ_REG(WCD937X_IRQ_HPHL_OCP_INT, 0, 0x80),
  52. REGMAP_IRQ_REG(WCD937X_IRQ_HPHL_CNP_INT, 1, 0x01),
  53. REGMAP_IRQ_REG(WCD937X_IRQ_EAR_CNP_INT, 1, 0x02),
  54. REGMAP_IRQ_REG(WCD937X_IRQ_EAR_SCD_INT, 1, 0x04),
  55. REGMAP_IRQ_REG(WCD937X_IRQ_AUX_CNP_INT, 1, 0x08),
  56. REGMAP_IRQ_REG(WCD937X_IRQ_AUX_SCD_INT, 1, 0x10),
  57. REGMAP_IRQ_REG(WCD937X_IRQ_HPHL_PDM_WD_INT, 1, 0x20),
  58. REGMAP_IRQ_REG(WCD937X_IRQ_HPHR_PDM_WD_INT, 1, 0x40),
  59. REGMAP_IRQ_REG(WCD937X_IRQ_AUX_PDM_WD_INT, 1, 0x80),
  60. REGMAP_IRQ_REG(WCD937X_IRQ_LDORT_SCD_INT, 2, 0x01),
  61. REGMAP_IRQ_REG(WCD937X_IRQ_MBHC_MOISTURE_INT, 2, 0x02),
  62. REGMAP_IRQ_REG(WCD937X_IRQ_HPHL_SURGE_DET_INT, 2, 0x04),
  63. REGMAP_IRQ_REG(WCD937X_IRQ_HPHR_SURGE_DET_INT, 2, 0x08),
  64. };
  65. static struct regmap_irq_chip wcd937x_regmap_irq_chip = {
  66. .name = "wcd937x",
  67. .irqs = wcd937x_irqs,
  68. .num_irqs = ARRAY_SIZE(wcd937x_irqs),
  69. .num_regs = 3,
  70. .status_base = WCD937X_DIGITAL_INTR_STATUS_0,
  71. .mask_base = WCD937X_DIGITAL_INTR_MASK_0,
  72. .type_base = WCD937X_DIGITAL_INTR_LEVEL_0,
  73. .runtime_pm = true,
  74. .handle_post_irq = wcd937x_handle_post_irq,
  75. .handle_pre_irq = wcd937x_handle_pre_irq,
  76. };
  77. static int wcd937x_handle_pre_irq(void *data)
  78. {
  79. struct wcd937x_priv *wcd937x = data;
  80. int num_irq_regs = wcd937x->num_irq_regs;
  81. int ret = 0;
  82. u8 sts[num_irq_regs];
  83. struct wcd937x_pdata *pdata;
  84. pdata = dev_get_platdata(wcd937x->dev);
  85. memset(sts, 0, sizeof(sts));
  86. ret = regmap_bulk_read(wcd937x->regmap, WCD937X_DIGITAL_INTR_STATUS_0,
  87. sts, num_irq_regs);
  88. if (ret < 0) {
  89. dev_err(wcd937x->dev, "%s: Failed to read intr status: %d\n",
  90. __func__, ret);
  91. } else if (ret == 0) {
  92. dev_dbg(wcd937x->dev,
  93. "%s: clear interrupts except OCP and SCD\n", __func__);
  94. /* Do not affect OCP and SCD interrupts */
  95. sts[0] = sts[0] & 0x5F;
  96. sts[1] = sts[1] & 0xEB;
  97. regmap_write(wcd937x->regmap, WCD937X_DIGITAL_INTR_CLEAR_0,
  98. sts[0]);
  99. regmap_write(wcd937x->regmap, WCD937X_DIGITAL_INTR_CLEAR_1,
  100. sts[1]);
  101. regmap_write(wcd937x->regmap, WCD937X_DIGITAL_INTR_CLEAR_2,
  102. sts[2]);
  103. }
  104. return IRQ_HANDLED;
  105. }
  106. static int wcd937x_handle_post_irq(void *data)
  107. {
  108. struct wcd937x_priv *wcd937x = data;
  109. int val = 0;
  110. struct wcd937x_pdata *pdata = NULL;
  111. pdata = dev_get_platdata(wcd937x->dev);
  112. regmap_read(wcd937x->regmap, WCD937X_DIGITAL_INTR_STATUS_0, &val);
  113. if ((val & 0xA0) != 0) {
  114. dev_dbg(wcd937x->dev, "%s Clear OCP interupts\n", __func__);
  115. regmap_update_bits(wcd937x->regmap,
  116. WCD937X_DIGITAL_INTR_CLEAR_0, 0xA0, 0x00);
  117. }
  118. regmap_read(wcd937x->regmap, WCD937X_DIGITAL_INTR_STATUS_1, &val);
  119. if ((val & 0x14) != 0) {
  120. dev_dbg(wcd937x->dev, "%s Clear SCD interupts\n", __func__);
  121. regmap_update_bits(wcd937x->regmap,
  122. WCD937X_DIGITAL_INTR_CLEAR_1, 0x14, 0x00);
  123. }
  124. return IRQ_HANDLED;
  125. }
  126. static int wcd937x_init_reg(struct snd_soc_codec *codec)
  127. {
  128. snd_soc_update_bits(codec, WCD937X_SLEEP_CTL, 0x0E, 0x0E);
  129. snd_soc_update_bits(codec, WCD937X_SLEEP_CTL, 0x80, 0x80);
  130. usleep_range(1000, 1010);
  131. snd_soc_update_bits(codec, WCD937X_SLEEP_CTL, 0x40, 0x40);
  132. usleep_range(1000, 1010);
  133. snd_soc_update_bits(codec, WCD937X_LDORXTX_CONFIG, 0x10, 0x00);
  134. snd_soc_update_bits(codec, WCD937X_BIAS_VBG_FINE_ADJ, 0xF0, 0x80);
  135. snd_soc_update_bits(codec, WCD937X_ANA_BIAS, 0x80, 0x80);
  136. snd_soc_update_bits(codec, WCD937X_ANA_BIAS, 0x40, 0x40);
  137. usleep_range(10000, 10010);
  138. snd_soc_update_bits(codec, WCD937X_ANA_BIAS, 0x40, 0x00);
  139. return 0;
  140. }
  141. static int wcd937x_set_port_params(struct snd_soc_codec *codec, u8 slv_prt_type,
  142. u8 *port_id, u8 *num_ch, u8 *ch_mask, u32 *ch_rate,
  143. u8 *port_type, u8 path)
  144. {
  145. int i, j;
  146. u8 num_ports;
  147. struct codec_port_info (*map)[MAX_PORT][MAX_CH_PER_PORT];
  148. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  149. switch (path) {
  150. case CODEC_RX:
  151. map = &wcd937x->rx_port_mapping;
  152. num_ports = wcd937x->num_rx_ports;
  153. break;
  154. case CODEC_TX:
  155. map = &wcd937x->tx_port_mapping;
  156. num_ports = wcd937x->num_tx_ports;
  157. break;
  158. }
  159. for (i = 0; i <= num_ports; i++) {
  160. for (j = 0; j < MAX_CH_PER_PORT; j++) {
  161. if ((*map)[i][j].slave_port_type == slv_prt_type)
  162. goto found;
  163. }
  164. }
  165. found:
  166. if (i > num_ports || j == MAX_CH_PER_PORT) {
  167. dev_err(codec->dev, "%s Failed to find slave port for type %u\n",
  168. __func__, slv_prt_type);
  169. return -EINVAL;
  170. }
  171. *port_id = i;
  172. *num_ch = (*map)[i][j].num_ch;
  173. *ch_mask = (*map)[i][j].ch_mask;
  174. *ch_rate = (*map)[i][j].ch_rate;
  175. *port_type = (*map)[i][j].master_port_type;
  176. return 0;
  177. }
  178. static int wcd937x_parse_port_mapping(struct device *dev,
  179. char *prop, u8 path)
  180. {
  181. u32 *dt_array, map_size, map_length;
  182. u32 port_num, ch_mask, ch_rate, old_port_num = 0;
  183. u32 slave_port_type, master_port_type;
  184. u32 i, ch_iter = 0;
  185. int ret = 0;
  186. u8 *num_ports;
  187. struct codec_port_info (*map)[MAX_PORT][MAX_CH_PER_PORT];
  188. struct wcd937x_priv *wcd937x = dev_get_drvdata(dev);
  189. switch (path) {
  190. case CODEC_RX:
  191. map = &wcd937x->rx_port_mapping;
  192. num_ports = &wcd937x->num_rx_ports;
  193. break;
  194. case CODEC_TX:
  195. map = &wcd937x->tx_port_mapping;
  196. num_ports = &wcd937x->num_tx_ports;
  197. break;
  198. }
  199. if (!of_find_property(dev->of_node, prop,
  200. &map_size)) {
  201. dev_err(dev, "missing port mapping prop %s\n", prop);
  202. goto err_pdata_fail;
  203. }
  204. map_length = map_size / (NUM_SWRS_DT_PARAMS * sizeof(u32));
  205. dt_array = kzalloc(map_size, GFP_KERNEL);
  206. if (!dt_array) {
  207. ret = -ENOMEM;
  208. goto err_pdata_fail;
  209. }
  210. ret = of_property_read_u32_array(dev->of_node, prop, dt_array,
  211. NUM_SWRS_DT_PARAMS * map_length);
  212. if (ret) {
  213. dev_err(dev, "%s: Failed to read port mapping from prop %s\n",
  214. __func__, prop);
  215. goto err_pdata_fail;
  216. }
  217. for (i = 0; i < map_length; i++) {
  218. port_num = dt_array[NUM_SWRS_DT_PARAMS * i];
  219. slave_port_type = dt_array[NUM_SWRS_DT_PARAMS * i + 1];
  220. ch_mask = dt_array[NUM_SWRS_DT_PARAMS * i + 2];
  221. ch_rate = dt_array[NUM_SWRS_DT_PARAMS * i + 3];
  222. master_port_type = dt_array[NUM_SWRS_DT_PARAMS * i + 4];
  223. if (port_num != old_port_num)
  224. ch_iter = 0;
  225. (*map)[port_num][ch_iter].slave_port_type = slave_port_type;
  226. (*map)[port_num][ch_iter].ch_mask = ch_mask;
  227. (*map)[port_num][ch_iter].master_port_type = master_port_type;
  228. (*map)[port_num][ch_iter].num_ch = __sw_hweight8(ch_mask);
  229. (*map)[port_num][ch_iter++].ch_rate = ch_rate;
  230. old_port_num = port_num;
  231. }
  232. *num_ports = port_num;
  233. kfree(dt_array);
  234. return 0;
  235. err_pdata_fail:
  236. kfree(dt_array);
  237. return -EINVAL;
  238. }
  239. static int wcd937x_tx_connect_port(struct snd_soc_codec *codec,
  240. u8 slv_port_type, u8 enable)
  241. {
  242. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  243. u8 port_id;
  244. u8 num_ch;
  245. u8 ch_mask;
  246. u32 ch_rate;
  247. u8 port_type;
  248. u8 num_port = 1;
  249. int ret = 0;
  250. ret = wcd937x_set_port_params(codec, slv_port_type, &port_id,
  251. &num_ch, &ch_mask, &ch_rate,
  252. &port_type, CODEC_TX);
  253. if (ret)
  254. return ret;
  255. if (enable)
  256. ret = swr_connect_port(wcd937x->tx_swr_dev, &port_id,
  257. num_port, &ch_mask, &ch_rate,
  258. &num_ch, &port_type);
  259. else
  260. ret = swr_disconnect_port(wcd937x->tx_swr_dev, &port_id,
  261. num_port, &ch_mask, &port_type);
  262. return ret;
  263. }
  264. static int wcd937x_rx_connect_port(struct snd_soc_codec *codec,
  265. u8 slv_port_type, u8 enable)
  266. {
  267. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  268. u8 port_id;
  269. u8 num_ch;
  270. u8 ch_mask;
  271. u32 ch_rate;
  272. u8 port_type;
  273. u8 num_port = 1;
  274. int ret = 0;
  275. ret = wcd937x_set_port_params(codec, slv_port_type, &port_id,
  276. &num_ch, &ch_mask, &ch_rate,
  277. &port_type, CODEC_RX);
  278. if (ret)
  279. return ret;
  280. if (enable)
  281. ret = swr_connect_port(wcd937x->rx_swr_dev, &port_id,
  282. num_port, &ch_mask, &ch_rate,
  283. &num_ch, &port_type);
  284. else
  285. ret = swr_disconnect_port(wcd937x->rx_swr_dev, &port_id,
  286. num_port, &ch_mask, &port_type);
  287. return ret;
  288. }
  289. static int wcd937x_rx_clk_enable(struct snd_soc_codec *codec)
  290. {
  291. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  292. if (wcd937x->rx_clk_cnt == 0) {
  293. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_DIG_CLK_CTL,
  294. 0x08, 0x08);
  295. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_ANA_CLK_CTL,
  296. 0x01, 0x01);
  297. snd_soc_update_bits(codec, WCD937X_ANA_RX_SUPPLIES, 0x01, 0x01);
  298. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_RX0_CTL,
  299. 0x40, 0x00);
  300. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_ANA_CLK_CTL,
  301. 0x02, 0x02);
  302. }
  303. wcd937x->rx_clk_cnt++;
  304. return 0;
  305. }
  306. static int wcd937x_rx_clk_disable(struct snd_soc_codec *codec)
  307. {
  308. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  309. wcd937x->rx_clk_cnt--;
  310. if (wcd937x->rx_clk_cnt == 0) {
  311. snd_soc_update_bits(codec, WCD937X_ANA_RX_SUPPLIES, 0x40, 0x00);
  312. snd_soc_update_bits(codec, WCD937X_ANA_RX_SUPPLIES, 0x80, 0x00);
  313. snd_soc_update_bits(codec, WCD937X_ANA_RX_SUPPLIES, 0x01, 0x00);
  314. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_ANA_CLK_CTL,
  315. 0x02, 0x00);
  316. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_ANA_CLK_CTL,
  317. 0x01, 0x00);
  318. }
  319. return 0;
  320. }
  321. /*
  322. * wcd937x_soc_get_mbhc: get wcd937x_mbhc handle of corresponding codec
  323. * @codec: handle to snd_soc_codec *
  324. *
  325. * return wcd937x_mbhc handle or error code in case of failure
  326. */
  327. struct wcd937x_mbhc *wcd937x_soc_get_mbhc(struct snd_soc_codec *codec)
  328. {
  329. struct wcd937x_priv *wcd937x;
  330. if (!codec) {
  331. pr_err("%s: Invalid params, NULL codec\n", __func__);
  332. return NULL;
  333. }
  334. wcd937x = snd_soc_codec_get_drvdata(codec);
  335. if (!wcd937x) {
  336. pr_err("%s: Invalid params, NULL tavil\n", __func__);
  337. return NULL;
  338. }
  339. return wcd937x->mbhc;
  340. }
  341. EXPORT_SYMBOL(wcd937x_soc_get_mbhc);
  342. static int wcd937x_codec_hphl_dac_event(struct snd_soc_dapm_widget *w,
  343. struct snd_kcontrol *kcontrol,
  344. int event)
  345. {
  346. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  347. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  348. int ret = 0;
  349. dev_dbg(codec->dev, "%s wname: %s event: %d\n", __func__,
  350. w->name, event);
  351. switch (event) {
  352. case SND_SOC_DAPM_PRE_PMU:
  353. wcd937x_rx_clk_enable(codec);
  354. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_DIG_CLK_CTL,
  355. 0x01, 0x01);
  356. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_HPH_GAIN_CTL,
  357. 0x04, 0x04);
  358. snd_soc_update_bits(codec, WCD937X_HPH_RDAC_CLK_CTL1,
  359. 0x80, 0x00);
  360. break;
  361. case SND_SOC_DAPM_POST_PMU:
  362. snd_soc_update_bits(codec, WCD937X_HPH_NEW_INT_RDAC_HD2_CTL_L,
  363. 0x0F, 0x02);
  364. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_COMP_CTL_0,
  365. 0x02, 0x02);
  366. usleep_range(5000, 5010);
  367. snd_soc_update_bits(codec, WCD937X_HPH_NEW_INT_HPH_TIMER1,
  368. 0x02, 0x00);
  369. break;
  370. case SND_SOC_DAPM_POST_PMD:
  371. ret = swr_slvdev_datapath_control(wcd937x->rx_swr_dev,
  372. wcd937x->rx_swr_dev->dev_num,
  373. false);
  374. break;
  375. }
  376. return ret;
  377. }
  378. static int wcd937x_codec_hphr_dac_event(struct snd_soc_dapm_widget *w,
  379. struct snd_kcontrol *kcontrol,
  380. int event)
  381. {
  382. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  383. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  384. int ret = 0;
  385. dev_dbg(codec->dev, "%s wname: %s event: %d\n", __func__,
  386. w->name, event);
  387. switch (event) {
  388. case SND_SOC_DAPM_PRE_PMU:
  389. wcd937x_rx_clk_enable(codec);
  390. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_DIG_CLK_CTL,
  391. 0x02, 0x02);
  392. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_HPH_GAIN_CTL,
  393. 0x08, 0x08);
  394. snd_soc_update_bits(codec, WCD937X_HPH_RDAC_CLK_CTL1,
  395. 0x80, 0x00);
  396. break;
  397. case SND_SOC_DAPM_POST_PMU:
  398. snd_soc_update_bits(codec, WCD937X_HPH_NEW_INT_RDAC_HD2_CTL_R,
  399. 0x0F, 0x02);
  400. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_COMP_CTL_0,
  401. 0x01, 0x01);
  402. usleep_range(5000, 5010);
  403. snd_soc_update_bits(codec, WCD937X_HPH_NEW_INT_HPH_TIMER1,
  404. 0x02, 0x00);
  405. break;
  406. case SND_SOC_DAPM_POST_PMD:
  407. ret = swr_slvdev_datapath_control(wcd937x->rx_swr_dev,
  408. wcd937x->rx_swr_dev->dev_num,
  409. false);
  410. break;
  411. }
  412. return ret;
  413. }
  414. static int wcd937x_codec_ear_dac_event(struct snd_soc_dapm_widget *w,
  415. struct snd_kcontrol *kcontrol,
  416. int event)
  417. {
  418. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  419. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  420. int ret = 0;
  421. dev_dbg(codec->dev, "%s wname: %s event: %d\n", __func__,
  422. w->name, event);
  423. switch (event) {
  424. case SND_SOC_DAPM_PRE_PMU:
  425. wcd937x_rx_clk_enable(codec);
  426. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_HPH_GAIN_CTL,
  427. 0x04, 0x04);
  428. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_DIG_CLK_CTL,
  429. 0x01, 0x01);
  430. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_COMP_CTL_0,
  431. 0x02, 0x02);
  432. usleep_range(5000, 5010);
  433. break;
  434. case SND_SOC_DAPM_POST_PMD:
  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_aux_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 ret = 0;
  449. dev_dbg(codec->dev, "%s wname: %s event: %d\n", __func__,
  450. w->name, event);
  451. switch (event) {
  452. case SND_SOC_DAPM_PRE_PMU:
  453. wcd937x_rx_clk_enable(codec);
  454. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_ANA_CLK_CTL,
  455. 0x04, 0x04);
  456. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_DIG_CLK_CTL,
  457. 0x04, 0x04);
  458. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_AUX_GAIN_CTL,
  459. 0x01, 0x01);
  460. break;
  461. case SND_SOC_DAPM_POST_PMD:
  462. ret = swr_slvdev_datapath_control(wcd937x->rx_swr_dev,
  463. wcd937x->rx_swr_dev->dev_num,
  464. false);
  465. wcd937x_rx_clk_disable(codec);
  466. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_ANA_CLK_CTL,
  467. 0x04, 0x00);
  468. break;
  469. };
  470. return ret;
  471. }
  472. static int wcd937x_codec_enable_hphr_pa(struct snd_soc_dapm_widget *w,
  473. struct snd_kcontrol *kcontrol,
  474. int event)
  475. {
  476. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  477. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  478. int ret = 0;
  479. dev_dbg(codec->dev, "%s wname: %s event: %d\n", __func__,
  480. w->name, event);
  481. switch (event) {
  482. case SND_SOC_DAPM_PRE_PMU:
  483. snd_soc_update_bits(codec, WCD937X_ANA_HPH, 0x10, 0x10);
  484. usleep_range(100, 110);
  485. break;
  486. case SND_SOC_DAPM_POST_PMU:
  487. usleep_range(7000, 7010);
  488. snd_soc_update_bits(codec, WCD937X_HPH_NEW_INT_HPH_TIMER1,
  489. 0x02, 0x02);
  490. snd_soc_update_bits(codec, WCD937X_ANA_RX_SUPPLIES,
  491. 0x02, 0x02);
  492. ret = swr_slvdev_datapath_control(wcd937x->rx_swr_dev,
  493. wcd937x->rx_swr_dev->dev_num,
  494. true);
  495. break;
  496. case SND_SOC_DAPM_POST_PMD:
  497. usleep_range(7000, 7010);
  498. snd_soc_update_bits(codec, WCD937X_ANA_HPH, 0x10, 0x00);
  499. break;
  500. };
  501. return ret;
  502. }
  503. static int wcd937x_codec_enable_hphl_pa(struct snd_soc_dapm_widget *w,
  504. struct snd_kcontrol *kcontrol,
  505. int event)
  506. {
  507. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  508. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  509. int ret = 0;
  510. switch (event) {
  511. case SND_SOC_DAPM_PRE_PMU:
  512. snd_soc_update_bits(codec, WCD937X_ANA_HPH, 0x0C, 0x08);
  513. snd_soc_update_bits(codec, WCD937X_ANA_HPH, 0x20, 0x20);
  514. usleep_range(100, 110);
  515. break;
  516. case SND_SOC_DAPM_POST_PMU:
  517. usleep_range(7000, 7010);
  518. snd_soc_update_bits(codec, WCD937X_HPH_NEW_INT_HPH_TIMER1,
  519. 0x02, 0x02);
  520. snd_soc_update_bits(codec, WCD937X_ANA_RX_SUPPLIES,
  521. 0x02, 0x02);
  522. ret = swr_slvdev_datapath_control(wcd937x->rx_swr_dev,
  523. wcd937x->rx_swr_dev->dev_num,
  524. true);
  525. break;
  526. case SND_SOC_DAPM_POST_PMD:
  527. usleep_range(7000, 7010);
  528. snd_soc_update_bits(codec, WCD937X_ANA_HPH, 0x20, 0x00);
  529. break;
  530. };
  531. return ret;
  532. }
  533. static int wcd937x_codec_enable_aux_pa(struct snd_soc_dapm_widget *w,
  534. struct snd_kcontrol *kcontrol,
  535. int event)
  536. {
  537. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  538. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  539. int ret = 0;
  540. dev_dbg(codec->dev, "%s wname: %s event: %d\n", __func__,
  541. w->name, event);
  542. switch (event) {
  543. case SND_SOC_DAPM_PRE_PMU:
  544. snd_soc_update_bits(codec, WCD937X_ANA_RX_SUPPLIES,
  545. 0x80, 0x80);
  546. usleep_range(500, 510);
  547. snd_soc_update_bits(codec, WCD937X_CLASSH_MODE_2, 0xFF, 0x3A);
  548. usleep_range(500, 510);
  549. break;
  550. case SND_SOC_DAPM_POST_PMU:
  551. usleep_range(1000, 1010);
  552. snd_soc_update_bits(codec, WCD937X_ANA_RX_SUPPLIES,
  553. 0x20, 0x20);
  554. ret = swr_slvdev_datapath_control(wcd937x->rx_swr_dev,
  555. wcd937x->rx_swr_dev->dev_num,
  556. true);
  557. break;
  558. case SND_SOC_DAPM_POST_PMD:
  559. usleep_range(1000, 1010);
  560. usleep_range(1000, 1010);
  561. break;
  562. };
  563. return ret;
  564. }
  565. static int wcd937x_codec_enable_ear_pa(struct snd_soc_dapm_widget *w,
  566. struct snd_kcontrol *kcontrol,
  567. int event)
  568. {
  569. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  570. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  571. int ret = 0;
  572. dev_dbg(codec->dev, "%s wname: %s event: %d\n", __func__,
  573. w->name, event);
  574. switch (event) {
  575. case SND_SOC_DAPM_PRE_PMU:
  576. snd_soc_update_bits(codec, WCD937X_ANA_RX_SUPPLIES,
  577. 0x08, 0x08);
  578. usleep_range(500, 510);
  579. snd_soc_update_bits(codec, WCD937X_CLASSH_MODE_2, 0xFF, 0x3A);
  580. usleep_range(500, 510);
  581. break;
  582. case SND_SOC_DAPM_POST_PMU:
  583. usleep_range(6000, 6010);
  584. snd_soc_update_bits(codec, WCD937X_ANA_RX_SUPPLIES,
  585. 0x02, 0x02);
  586. ret = swr_slvdev_datapath_control(wcd937x->rx_swr_dev,
  587. wcd937x->rx_swr_dev->dev_num,
  588. true);
  589. break;
  590. case SND_SOC_DAPM_POST_PMD:
  591. usleep_range(7000, 7010);
  592. break;
  593. };
  594. return ret;
  595. }
  596. static int wcd937x_enable_rx1(struct snd_soc_dapm_widget *w,
  597. struct snd_kcontrol *kcontrol,
  598. int event)
  599. {
  600. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  601. dev_dbg(codec->dev, "%s wname: %s event: %d\n", __func__,
  602. w->name, event);
  603. switch (event) {
  604. case SND_SOC_DAPM_PRE_PMU:
  605. snd_soc_update_bits(codec, WCD937X_FLYBACK_VNEG_CTRL_4,
  606. 0xF0, 0x80);
  607. snd_soc_update_bits(codec, WCD937X_FLYBACK_VNEGDAC_CTRL_2,
  608. 0xE0, 0xA0);
  609. snd_soc_update_bits(codec, WCD937X_CLASSH_MODE_3,
  610. 0x02, 0x02);
  611. snd_soc_update_bits(codec, WCD937X_CLASSH_MODE_2,
  612. 0xFF, 0x1C);
  613. snd_soc_update_bits(codec, WCD937X_ANA_RX_SUPPLIES,
  614. 0x40, 0x40);
  615. usleep_range(100, 110);
  616. snd_soc_update_bits(codec, WCD937X_FLYBACK_VNEGDAC_CTRL_2,
  617. 0xE0, 0xE0);
  618. usleep_range(100, 110);
  619. snd_soc_update_bits(codec, WCD937X_ANA_RX_SUPPLIES,
  620. 0x80, 0x80);
  621. usleep_range(500, 510);
  622. snd_soc_update_bits(codec, WCD937X_CLASSH_MODE_2, 0xFF, 0x3A);
  623. usleep_range(500, 510);
  624. wcd937x_rx_connect_port(codec, HPH_L, true);
  625. wcd937x_rx_connect_port(codec, COMP_L, true);
  626. break;
  627. case SND_SOC_DAPM_POST_PMD:
  628. wcd937x_rx_connect_port(codec, HPH_L, false);
  629. wcd937x_rx_connect_port(codec, COMP_L, false);
  630. wcd937x_rx_clk_disable(codec);
  631. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_DIG_CLK_CTL,
  632. 0x01, 0x00);
  633. break;
  634. };
  635. return 0;
  636. }
  637. static int wcd937x_enable_rx2(struct snd_soc_dapm_widget *w,
  638. struct snd_kcontrol *kcontrol, int event)
  639. {
  640. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  641. dev_dbg(codec->dev, "%s wname: %s event: %d\n", __func__,
  642. w->name, event);
  643. switch (event) {
  644. case SND_SOC_DAPM_PRE_PMU:
  645. snd_soc_update_bits(codec, WCD937X_FLYBACK_VNEG_CTRL_4,
  646. 0xF0, 0x80);
  647. snd_soc_update_bits(codec, WCD937X_FLYBACK_VNEGDAC_CTRL_2,
  648. 0xE0, 0xA0);
  649. snd_soc_update_bits(codec, WCD937X_CLASSH_MODE_3, 0x02, 0x02);
  650. snd_soc_update_bits(codec, WCD937X_CLASSH_MODE_2, 0xFF, 0x1C);
  651. snd_soc_update_bits(codec, WCD937X_ANA_RX_SUPPLIES,
  652. 0x40, 0x40);
  653. usleep_range(100, 110);
  654. snd_soc_update_bits(codec, WCD937X_FLYBACK_VNEGDAC_CTRL_2,
  655. 0xE0, 0xE0);
  656. usleep_range(100, 110);
  657. snd_soc_update_bits(codec, WCD937X_ANA_RX_SUPPLIES,
  658. 0x80, 0x80);
  659. usleep_range(500, 510);
  660. snd_soc_update_bits(codec, WCD937X_CLASSH_MODE_2, 0xFF, 0x3A);
  661. usleep_range(500, 510);
  662. wcd937x_rx_connect_port(codec, HPH_R, true);
  663. wcd937x_rx_connect_port(codec, COMP_R, true);
  664. break;
  665. case SND_SOC_DAPM_POST_PMD:
  666. wcd937x_rx_connect_port(codec, HPH_R, false);
  667. wcd937x_rx_connect_port(codec, COMP_R, false);
  668. wcd937x_rx_clk_disable(codec);
  669. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_DIG_CLK_CTL,
  670. 0x02, 0x00);
  671. break;
  672. };
  673. return 0;
  674. }
  675. static int wcd937x_enable_rx3(struct snd_soc_dapm_widget *w,
  676. struct snd_kcontrol *kcontrol,
  677. int event)
  678. {
  679. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  680. dev_dbg(codec->dev, "%s wname: %s event: %d\n", __func__,
  681. w->name, event);
  682. switch (event) {
  683. case SND_SOC_DAPM_PRE_PMU:
  684. snd_soc_update_bits(codec, WCD937X_FLYBACK_VNEG_CTRL_2,
  685. 0xE0, 0xA0);
  686. snd_soc_update_bits(codec, WCD937X_CLASSH_MODE_3, 0x02, 0x02);
  687. snd_soc_update_bits(codec, WCD937X_CLASSH_MODE_2, 0xFF, 0x1C);
  688. snd_soc_update_bits(codec, WCD937X_ANA_RX_SUPPLIES,
  689. 0x40, 0x40);
  690. usleep_range(100, 110);
  691. snd_soc_update_bits(codec, WCD937X_FLYBACK_VNEG_CTRL_2,
  692. 0xE0, 0xE0);
  693. usleep_range(100, 110);
  694. wcd937x_rx_connect_port(codec, LO, true);
  695. break;
  696. case SND_SOC_DAPM_POST_PMD:
  697. wcd937x_rx_connect_port(codec, LO, false);
  698. usleep_range(6000, 6010);
  699. wcd937x_rx_clk_disable(codec);
  700. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_DIG_CLK_CTL,
  701. 0x04, 0x00);
  702. break;
  703. }
  704. return 0;
  705. }
  706. static int wcd937x_codec_enable_dmic(struct snd_soc_dapm_widget *w,
  707. struct snd_kcontrol *kcontrol,
  708. int event)
  709. {
  710. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  711. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  712. u16 dmic_clk_reg;
  713. s32 *dmic_clk_cnt;
  714. unsigned int dmic;
  715. char *wname;
  716. int ret = 0;
  717. wname = strpbrk(w->name, "012345");
  718. if (!wname) {
  719. dev_err(codec->dev, "%s: widget not found\n", __func__);
  720. return -EINVAL;
  721. }
  722. ret = kstrtouint(wname, 10, &dmic);
  723. if (ret < 0) {
  724. dev_err(codec->dev, "%s: Invalid DMIC line on the codec\n",
  725. __func__);
  726. return -EINVAL;
  727. }
  728. dev_dbg(codec->dev, "%s wname: %s event: %d\n", __func__,
  729. w->name, event);
  730. switch (dmic) {
  731. case 0:
  732. case 1:
  733. dmic_clk_cnt = &(wcd937x->dmic_0_1_clk_cnt);
  734. dmic_clk_reg = WCD937X_DIGITAL_CDC_DMIC0_CTL;
  735. break;
  736. case 2:
  737. case 3:
  738. dmic_clk_cnt = &(wcd937x->dmic_2_3_clk_cnt);
  739. dmic_clk_reg = WCD937X_DIGITAL_CDC_DMIC1_CTL;
  740. break;
  741. case 4:
  742. case 5:
  743. dmic_clk_cnt = &(wcd937x->dmic_4_5_clk_cnt);
  744. dmic_clk_reg = WCD937X_DIGITAL_CDC_DMIC2_CTL;
  745. break;
  746. default:
  747. dev_err(codec->dev, "%s: Invalid DMIC Selection\n",
  748. __func__);
  749. return -EINVAL;
  750. };
  751. dev_dbg(codec->dev, "%s: event %d DMIC%d dmic_clk_cnt %d\n",
  752. __func__, event, dmic, *dmic_clk_cnt);
  753. switch (event) {
  754. case SND_SOC_DAPM_PRE_PMU:
  755. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_DIG_CLK_CTL,
  756. 0x80, 0x80);
  757. snd_soc_update_bits(codec, dmic_clk_reg, 0x07, 0x02);
  758. snd_soc_update_bits(codec, dmic_clk_reg, 0x08, 0x08);
  759. snd_soc_update_bits(codec, dmic_clk_reg, 0x70, 0x20);
  760. wcd937x_tx_connect_port(codec, DMIC0 + (w->shift), true);
  761. break;
  762. case SND_SOC_DAPM_POST_PMD:
  763. wcd937x_tx_connect_port(codec, DMIC0 + (w->shift), false);
  764. break;
  765. };
  766. return 0;
  767. }
  768. /*
  769. * wcd937x_get_micb_vout_ctl_val: converts micbias from volts to register value
  770. * @micb_mv: micbias in mv
  771. *
  772. * return register value converted
  773. */
  774. int wcd937x_get_micb_vout_ctl_val(u32 micb_mv)
  775. {
  776. /* min micbias voltage is 1V and maximum is 2.85V */
  777. if (micb_mv < 1000 || micb_mv > 2850) {
  778. pr_err("%s: unsupported micbias voltage\n", __func__);
  779. return -EINVAL;
  780. }
  781. return (micb_mv - 1000) / 50;
  782. }
  783. EXPORT_SYMBOL(wcd937x_get_micb_vout_ctl_val);
  784. /*
  785. * wcd937x_mbhc_micb_adjust_voltage: adjust specific micbias voltage
  786. * @codec: handle to snd_soc_codec *
  787. * @req_volt: micbias voltage to be set
  788. * @micb_num: micbias to be set, e.g. micbias1 or micbias2
  789. *
  790. * return 0 if adjustment is success or error code in case of failure
  791. */
  792. int wcd937x_mbhc_micb_adjust_voltage(struct snd_soc_codec *codec,
  793. int req_volt, int micb_num)
  794. {
  795. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  796. int cur_vout_ctl, req_vout_ctl;
  797. int micb_reg, micb_val, micb_en;
  798. int ret = 0;
  799. switch (micb_num) {
  800. case MIC_BIAS_1:
  801. micb_reg = WCD937X_ANA_MICB1;
  802. break;
  803. case MIC_BIAS_2:
  804. micb_reg = WCD937X_ANA_MICB2;
  805. break;
  806. case MIC_BIAS_3:
  807. micb_reg = WCD937X_ANA_MICB3;
  808. break;
  809. default:
  810. return -EINVAL;
  811. }
  812. mutex_lock(&wcd937x->micb_lock);
  813. /*
  814. * If requested micbias voltage is same as current micbias
  815. * voltage, then just return. Otherwise, adjust voltage as
  816. * per requested value. If micbias is already enabled, then
  817. * to avoid slow micbias ramp-up or down enable pull-up
  818. * momentarily, change the micbias value and then re-enable
  819. * micbias.
  820. */
  821. micb_val = snd_soc_read(codec, micb_reg);
  822. micb_en = (micb_val & 0xC0) >> 6;
  823. cur_vout_ctl = micb_val & 0x3F;
  824. req_vout_ctl = wcd937x_get_micb_vout_ctl_val(req_volt);
  825. if (req_vout_ctl < 0) {
  826. ret = -EINVAL;
  827. goto exit;
  828. }
  829. if (cur_vout_ctl == req_vout_ctl) {
  830. ret = 0;
  831. goto exit;
  832. }
  833. dev_dbg(codec->dev, "%s: micb_num: %d, cur_mv: %d, req_mv: %d, micb_en: %d\n",
  834. __func__, micb_num, WCD_VOUT_CTL_TO_MICB(cur_vout_ctl),
  835. req_volt, micb_en);
  836. if (micb_en == 0x1)
  837. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x80);
  838. snd_soc_update_bits(codec, micb_reg, 0x3F, req_vout_ctl);
  839. if (micb_en == 0x1) {
  840. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x40);
  841. /*
  842. * Add 2ms delay as per HW requirement after enabling
  843. * micbias
  844. */
  845. usleep_range(2000, 2100);
  846. }
  847. exit:
  848. mutex_unlock(&wcd937x->micb_lock);
  849. return ret;
  850. }
  851. EXPORT_SYMBOL(wcd937x_mbhc_micb_adjust_voltage);
  852. static int wcd937x_tx_swr_ctrl(struct snd_soc_dapm_widget *w,
  853. struct snd_kcontrol *kcontrol,
  854. int event)
  855. {
  856. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  857. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  858. int ret = 0;
  859. switch (event) {
  860. case SND_SOC_DAPM_PRE_PMU:
  861. ret = swr_slvdev_datapath_control(wcd937x->tx_swr_dev,
  862. wcd937x->tx_swr_dev->dev_num,
  863. true);
  864. break;
  865. case SND_SOC_DAPM_POST_PMD:
  866. ret = swr_slvdev_datapath_control(wcd937x->tx_swr_dev,
  867. wcd937x->tx_swr_dev->dev_num,
  868. false);
  869. break;
  870. };
  871. return ret;
  872. }
  873. static int wcd937x_codec_enable_adc(struct snd_soc_dapm_widget *w,
  874. struct snd_kcontrol *kcontrol,
  875. int event){
  876. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  877. dev_dbg(codec->dev, "%s wname: %s event: %d\n", __func__,
  878. w->name, event);
  879. switch (event) {
  880. case SND_SOC_DAPM_PRE_PMU:
  881. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_DIG_CLK_CTL,
  882. 0x80, 0x80);
  883. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_ANA_CLK_CTL,
  884. 0x08, 0x08);
  885. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_ANA_CLK_CTL,
  886. 0x10, 0x10);
  887. wcd937x_tx_connect_port(codec, ADC1 + (w->shift), true);
  888. break;
  889. case SND_SOC_DAPM_POST_PMD:
  890. wcd937x_tx_connect_port(codec, ADC1 + (w->shift), false);
  891. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_ANA_CLK_CTL,
  892. 0x08, 0x00);
  893. break;
  894. };
  895. return 0;
  896. }
  897. static int wcd937x_enable_req(struct snd_soc_dapm_widget *w,
  898. struct snd_kcontrol *kcontrol, int event)
  899. {
  900. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  901. dev_dbg(codec->dev, "%s wname: %s event: %d\n", __func__,
  902. w->name, event);
  903. switch (event) {
  904. case SND_SOC_DAPM_PRE_PMU:
  905. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_REQ_CTL,
  906. 0x02, 0x02);
  907. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_REQ_CTL, 0x01,
  908. 0x00);
  909. snd_soc_update_bits(codec, WCD937X_ANA_TX_CH2, 0x40, 0x40);
  910. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_DIG_CLK_CTL,
  911. 0x10, 0x10);
  912. snd_soc_update_bits(codec, WCD937X_ANA_TX_CH1, 0x80, 0x80);
  913. snd_soc_update_bits(codec, WCD937X_ANA_TX_CH2, 0x40, 0x00);
  914. break;
  915. case SND_SOC_DAPM_POST_PMD:
  916. snd_soc_update_bits(codec, WCD937X_ANA_TX_CH1, 0x80, 0x00);
  917. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_DIG_CLK_CTL,
  918. 0x10, 0x00);
  919. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_ANA_CLK_CTL,
  920. 0x10, 0x00);
  921. snd_soc_update_bits(codec, WCD937X_DIGITAL_CDC_DIG_CLK_CTL,
  922. 0x80, 0x00);
  923. break;
  924. };
  925. return 0;
  926. }
  927. int wcd937x_micbias_control(struct snd_soc_codec *codec,
  928. int micb_num, int req, bool is_dapm)
  929. {
  930. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  931. int micb_index = micb_num - 1;
  932. u16 micb_reg;
  933. int pre_off_event = 0, post_off_event = 0;
  934. int post_on_event = 0, post_dapm_off = 0;
  935. int post_dapm_on = 0;
  936. if ((micb_index < 0) || (micb_index > WCD937X_MAX_MICBIAS - 1)) {
  937. dev_err(codec->dev, "%s: Invalid micbias index, micb_ind:%d\n",
  938. __func__, micb_index);
  939. return -EINVAL;
  940. }
  941. switch (micb_num) {
  942. case MIC_BIAS_1:
  943. micb_reg = WCD937X_ANA_MICB1;
  944. break;
  945. case MIC_BIAS_2:
  946. micb_reg = WCD937X_ANA_MICB2;
  947. pre_off_event = WCD_EVENT_PRE_MICBIAS_2_OFF;
  948. post_off_event = WCD_EVENT_POST_MICBIAS_2_OFF;
  949. post_on_event = WCD_EVENT_POST_MICBIAS_2_ON;
  950. post_dapm_on = WCD_EVENT_POST_DAPM_MICBIAS_2_ON;
  951. post_dapm_off = WCD_EVENT_POST_DAPM_MICBIAS_2_OFF;
  952. break;
  953. case MIC_BIAS_3:
  954. micb_reg = WCD937X_ANA_MICB3;
  955. break;
  956. default:
  957. dev_err(codec->dev, "%s: Invalid micbias number: %d\n",
  958. __func__, micb_num);
  959. return -EINVAL;
  960. };
  961. mutex_lock(&wcd937x->micb_lock);
  962. switch (req) {
  963. case MICB_PULLUP_ENABLE:
  964. wcd937x->pullup_ref[micb_index]++;
  965. if ((wcd937x->pullup_ref[micb_index] == 1) &&
  966. (wcd937x->micb_ref[micb_index] == 0))
  967. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x80);
  968. break;
  969. case MICB_PULLUP_DISABLE:
  970. if (wcd937x->pullup_ref[micb_index] > 0)
  971. wcd937x->pullup_ref[micb_index]--;
  972. if ((wcd937x->pullup_ref[micb_index] == 0) &&
  973. (wcd937x->micb_ref[micb_index] == 0))
  974. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x00);
  975. break;
  976. case MICB_ENABLE:
  977. wcd937x->micb_ref[micb_index]++;
  978. if (wcd937x->micb_ref[micb_index] == 1) {
  979. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x40);
  980. if (post_on_event)
  981. blocking_notifier_call_chain(&wcd937x->notifier,
  982. post_on_event,
  983. &wcd937x->mbhc);
  984. }
  985. if (is_dapm && post_dapm_on)
  986. blocking_notifier_call_chain(&wcd937x->notifier,
  987. post_dapm_on,
  988. &wcd937x->mbhc);
  989. break;
  990. case MICB_DISABLE:
  991. if (wcd937x->micb_ref[micb_index] > 0)
  992. wcd937x->micb_ref[micb_index]--;
  993. if ((wcd937x->micb_ref[micb_index] == 0) &&
  994. (wcd937x->pullup_ref[micb_index] > 0))
  995. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x80);
  996. else if ((wcd937x->micb_ref[micb_index] == 0) &&
  997. (wcd937x->pullup_ref[micb_index] == 0)) {
  998. if (pre_off_event)
  999. blocking_notifier_call_chain(&wcd937x->notifier,
  1000. pre_off_event,
  1001. &wcd937x->mbhc);
  1002. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x00);
  1003. if (post_off_event)
  1004. blocking_notifier_call_chain(&wcd937x->notifier,
  1005. post_off_event,
  1006. &wcd937x->mbhc);
  1007. }
  1008. if (is_dapm && post_dapm_off)
  1009. blocking_notifier_call_chain(&wcd937x->notifier,
  1010. post_dapm_off,
  1011. &wcd937x->mbhc);
  1012. break;
  1013. };
  1014. dev_dbg(codec->dev, "%s: micb_num:%d, micb_ref: %d, pullup_ref: %d\n",
  1015. __func__, micb_num, wcd937x->micb_ref[micb_index],
  1016. wcd937x->pullup_ref[micb_index]);
  1017. mutex_unlock(&wcd937x->micb_lock);
  1018. return 0;
  1019. }
  1020. EXPORT_SYMBOL(wcd937x_micbias_control);
  1021. static int __wcd937x_codec_enable_micbias(struct snd_soc_dapm_widget *w,
  1022. int event)
  1023. {
  1024. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1025. int micb_num;
  1026. dev_dbg(codec->dev, "%s: wname: %s, event: %d\n",
  1027. __func__, w->name, event);
  1028. if (strnstr(w->name, "MIC BIAS1", sizeof("MIC BIAS1")))
  1029. micb_num = MIC_BIAS_1;
  1030. else if (strnstr(w->name, "MIC BIAS2", sizeof("MIC BIAS2")))
  1031. micb_num = MIC_BIAS_2;
  1032. else if (strnstr(w->name, "MIC BIAS3", sizeof("MIC BIAS3")))
  1033. micb_num = MIC_BIAS_3;
  1034. else
  1035. return -EINVAL;
  1036. switch (event) {
  1037. case SND_SOC_DAPM_PRE_PMU:
  1038. wcd937x_micbias_control(codec, micb_num, MICB_ENABLE, true);
  1039. break;
  1040. case SND_SOC_DAPM_POST_PMU:
  1041. usleep_range(1000, 1100);
  1042. break;
  1043. case SND_SOC_DAPM_POST_PMD:
  1044. wcd937x_micbias_control(codec, micb_num, MICB_DISABLE, true);
  1045. break;
  1046. };
  1047. return 0;
  1048. }
  1049. static int wcd937x_codec_enable_micbias(struct snd_soc_dapm_widget *w,
  1050. struct snd_kcontrol *kcontrol,
  1051. int event)
  1052. {
  1053. return __wcd937x_codec_enable_micbias(w, event);
  1054. }
  1055. static int wcd937x_rx_hph_mode_get(struct snd_kcontrol *kcontrol,
  1056. struct snd_ctl_elem_value *ucontrol)
  1057. {
  1058. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1059. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  1060. ucontrol->value.integer.value[0] = wcd937x->hph_mode;
  1061. return 0;
  1062. }
  1063. static int wcd937x_rx_hph_mode_put(struct snd_kcontrol *kcontrol,
  1064. struct snd_ctl_elem_value *ucontrol)
  1065. {
  1066. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1067. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  1068. u32 mode_val;
  1069. mode_val = ucontrol->value.enumerated.item[0];
  1070. dev_dbg(codec->dev, "%s: mode: %d\n", __func__, mode_val);
  1071. if (mode_val == 0) {
  1072. dev_warn(codec->dev, "%s:Invalid HPH Mode, default to class_AB\n",
  1073. __func__);
  1074. mode_val = 3; /* enum will be updated later */
  1075. }
  1076. wcd937x->hph_mode = mode_val;
  1077. return 0;
  1078. }
  1079. static const char * const rx_hph_mode_mux_text[] = {
  1080. "CLS_H_INVALID", "CLS_H_HIFI", "CLS_H_LP", "CLS_AB", "CLS_H_LOHIFI",
  1081. "CLS_H_ULP", "CLS_AB_HIFI",
  1082. };
  1083. static const struct soc_enum rx_hph_mode_mux_enum =
  1084. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(rx_hph_mode_mux_text),
  1085. rx_hph_mode_mux_text);
  1086. static const struct snd_kcontrol_new wcd937x_snd_controls[] = {
  1087. SOC_ENUM_EXT("RX HPH Mode", rx_hph_mode_mux_enum,
  1088. wcd937x_rx_hph_mode_get, wcd937x_rx_hph_mode_put),
  1089. SOC_SINGLE_TLV("HPHL Volume", WCD937X_HPH_L_EN, 0, 20, 1, line_gain),
  1090. SOC_SINGLE_TLV("HPHR Volume", WCD937X_HPH_R_EN, 0, 20, 1, line_gain),
  1091. SOC_SINGLE_TLV("ADC1 Volume", WCD937X_ANA_TX_CH1, 0, 20, 0, analog_gain),
  1092. SOC_SINGLE_TLV("ADC2 Volume", WCD937X_ANA_TX_CH2, 0, 20, 0, analog_gain),
  1093. SOC_SINGLE_TLV("ADC3 Volume", WCD937X_ANA_TX_CH3, 0, 20, 0, analog_gain),
  1094. };
  1095. static const struct snd_kcontrol_new adc1_switch[] = {
  1096. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1097. };
  1098. static const struct snd_kcontrol_new adc2_switch[] = {
  1099. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1100. };
  1101. static const struct snd_kcontrol_new adc3_switch[] = {
  1102. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1103. };
  1104. static const struct snd_kcontrol_new dmic1_switch[] = {
  1105. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1106. };
  1107. static const struct snd_kcontrol_new dmic2_switch[] = {
  1108. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1109. };
  1110. static const struct snd_kcontrol_new dmic3_switch[] = {
  1111. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1112. };
  1113. static const struct snd_kcontrol_new dmic4_switch[] = {
  1114. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1115. };
  1116. static const struct snd_kcontrol_new dmic5_switch[] = {
  1117. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1118. };
  1119. static const struct snd_kcontrol_new dmic6_switch[] = {
  1120. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1121. };
  1122. static const struct snd_kcontrol_new ear_rdac_switch[] = {
  1123. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1124. };
  1125. static const struct snd_kcontrol_new aux_rdac_switch[] = {
  1126. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1127. };
  1128. static const struct snd_kcontrol_new hphl_rdac_switch[] = {
  1129. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1130. };
  1131. static const struct snd_kcontrol_new hphr_rdac_switch[] = {
  1132. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1133. };
  1134. static const char * const adc2_mux_text[] = {
  1135. "INP2", "INP3"
  1136. };
  1137. static const char * const rdac3_mux_text[] = {
  1138. "RX1", "RX3"
  1139. };
  1140. static const struct soc_enum adc2_enum =
  1141. SOC_ENUM_SINGLE(WCD937X_TX_NEW_TX_CH2_SEL, 7,
  1142. ARRAY_SIZE(adc2_mux_text), adc2_mux_text);
  1143. static const struct soc_enum rdac3_enum =
  1144. SOC_ENUM_SINGLE(WCD937X_DIGITAL_CDC_EAR_PATH_CTL, 0,
  1145. ARRAY_SIZE(rdac3_mux_text), rdac3_mux_text);
  1146. static const struct snd_kcontrol_new tx_adc2_mux =
  1147. SOC_DAPM_ENUM("ADC2 MUX Mux", adc2_enum);
  1148. static const struct snd_kcontrol_new rx_rdac3_mux =
  1149. SOC_DAPM_ENUM("RDAC3_MUX Mux", rdac3_enum);
  1150. static const struct snd_soc_dapm_widget wcd937x_dapm_widgets[] = {
  1151. /*input widgets*/
  1152. SND_SOC_DAPM_INPUT("AMIC1"),
  1153. SND_SOC_DAPM_INPUT("AMIC2"),
  1154. SND_SOC_DAPM_INPUT("AMIC3"),
  1155. SND_SOC_DAPM_INPUT("IN1_HPHL"),
  1156. SND_SOC_DAPM_INPUT("IN2_HPHR"),
  1157. SND_SOC_DAPM_INPUT("IN3_AUX"),
  1158. /*tx widgets*/
  1159. SND_SOC_DAPM_ADC_E("ADC1", NULL, SND_SOC_NOPM, 0, 0,
  1160. wcd937x_codec_enable_adc,
  1161. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1162. SND_SOC_DAPM_ADC_E("ADC2", NULL, SND_SOC_NOPM, 0, 1,
  1163. wcd937x_codec_enable_adc,
  1164. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1165. SND_SOC_DAPM_MIXER_E("ADC1 REQ", SND_SOC_NOPM, 0, 0,
  1166. NULL, 0, wcd937x_enable_req,
  1167. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1168. SND_SOC_DAPM_MIXER_E("ADC2 REQ", SND_SOC_NOPM, 0, 0,
  1169. NULL, 0, wcd937x_enable_req,
  1170. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1171. SND_SOC_DAPM_MUX("ADC2 MUX", SND_SOC_NOPM, 0, 0,
  1172. &tx_adc2_mux),
  1173. /*tx mixers*/
  1174. SND_SOC_DAPM_MIXER_E("ADC1_MIXER", SND_SOC_NOPM, 0, 0,
  1175. adc1_switch, ARRAY_SIZE(adc1_switch),
  1176. wcd937x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  1177. SND_SOC_DAPM_POST_PMD),
  1178. SND_SOC_DAPM_MIXER_E("ADC2_MIXER", SND_SOC_NOPM, 0, 0,
  1179. adc2_switch, ARRAY_SIZE(adc2_switch),
  1180. wcd937x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  1181. SND_SOC_DAPM_POST_PMD),
  1182. /* micbias widgets*/
  1183. SND_SOC_DAPM_MICBIAS_E("MIC BIAS1", SND_SOC_NOPM, 0, 0,
  1184. wcd937x_codec_enable_micbias,
  1185. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1186. SND_SOC_DAPM_POST_PMD),
  1187. SND_SOC_DAPM_MICBIAS_E("MIC BIAS2", SND_SOC_NOPM, 0, 0,
  1188. wcd937x_codec_enable_micbias,
  1189. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1190. SND_SOC_DAPM_POST_PMD),
  1191. SND_SOC_DAPM_MICBIAS_E("MIC BIAS3", SND_SOC_NOPM, 0, 0,
  1192. wcd937x_codec_enable_micbias,
  1193. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1194. SND_SOC_DAPM_POST_PMD),
  1195. /*rx widgets*/
  1196. SND_SOC_DAPM_PGA_E("EAR PGA", WCD937X_ANA_EAR, 7, 0, NULL, 0,
  1197. wcd937x_codec_enable_ear_pa,
  1198. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1199. SND_SOC_DAPM_POST_PMD),
  1200. SND_SOC_DAPM_PGA_E("AUX PGA", WCD937X_AUX_AUXPA, 7, 0, NULL, 0,
  1201. wcd937x_codec_enable_aux_pa,
  1202. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1203. SND_SOC_DAPM_POST_PMD),
  1204. SND_SOC_DAPM_PGA_E("HPHL PGA", WCD937X_ANA_HPH, 7, 0, NULL, 0,
  1205. wcd937x_codec_enable_hphl_pa,
  1206. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1207. SND_SOC_DAPM_POST_PMD),
  1208. SND_SOC_DAPM_PGA_E("HPHR PGA", WCD937X_ANA_HPH, 6, 0, NULL, 0,
  1209. wcd937x_codec_enable_hphr_pa,
  1210. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1211. SND_SOC_DAPM_POST_PMD),
  1212. SND_SOC_DAPM_DAC_E("RDAC1", NULL, SND_SOC_NOPM, 0, 0,
  1213. wcd937x_codec_hphl_dac_event,
  1214. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1215. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1216. SND_SOC_DAPM_DAC_E("RDAC2", NULL, SND_SOC_NOPM, 0, 0,
  1217. wcd937x_codec_hphr_dac_event,
  1218. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1219. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1220. SND_SOC_DAPM_DAC_E("RDAC3", NULL, SND_SOC_NOPM, 0, 0,
  1221. wcd937x_codec_ear_dac_event,
  1222. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1223. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1224. SND_SOC_DAPM_DAC_E("RDAC4", NULL, SND_SOC_NOPM, 0, 0,
  1225. wcd937x_codec_aux_dac_event,
  1226. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1227. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1228. SND_SOC_DAPM_MUX("RDAC3_MUX", SND_SOC_NOPM, 0, 0, &rx_rdac3_mux),
  1229. SND_SOC_DAPM_MIXER_E("RX1", SND_SOC_NOPM, 0, 0, NULL, 0,
  1230. wcd937x_enable_rx1, SND_SOC_DAPM_PRE_PMU |
  1231. SND_SOC_DAPM_POST_PMD),
  1232. SND_SOC_DAPM_MIXER_E("RX2", SND_SOC_NOPM, 0, 0, NULL, 0,
  1233. wcd937x_enable_rx2, SND_SOC_DAPM_PRE_PMU |
  1234. SND_SOC_DAPM_POST_PMD),
  1235. SND_SOC_DAPM_MIXER_E("RX3", SND_SOC_NOPM, 0, 0, NULL, 0,
  1236. wcd937x_enable_rx3, SND_SOC_DAPM_PRE_PMU |
  1237. SND_SOC_DAPM_POST_PMD),
  1238. /* rx mixer widgets*/
  1239. SND_SOC_DAPM_MIXER("EAR_RDAC", SND_SOC_NOPM, 0, 0,
  1240. ear_rdac_switch, ARRAY_SIZE(ear_rdac_switch)),
  1241. SND_SOC_DAPM_MIXER("AUX_RDAC", SND_SOC_NOPM, 0, 0,
  1242. aux_rdac_switch, ARRAY_SIZE(aux_rdac_switch)),
  1243. SND_SOC_DAPM_MIXER("HPHL_RDAC", SND_SOC_NOPM, 0, 0,
  1244. hphl_rdac_switch, ARRAY_SIZE(hphl_rdac_switch)),
  1245. SND_SOC_DAPM_MIXER("HPHR_RDAC", SND_SOC_NOPM, 0, 0,
  1246. hphr_rdac_switch, ARRAY_SIZE(hphr_rdac_switch)),
  1247. /*output widgets tx*/
  1248. SND_SOC_DAPM_OUTPUT("ADC1_OUTPUT"),
  1249. SND_SOC_DAPM_OUTPUT("ADC2_OUTPUT"),
  1250. /*output widgets rx*/
  1251. SND_SOC_DAPM_OUTPUT("EAR"),
  1252. SND_SOC_DAPM_OUTPUT("AUX"),
  1253. SND_SOC_DAPM_OUTPUT("HPHL"),
  1254. SND_SOC_DAPM_OUTPUT("HPHR"),
  1255. };
  1256. static const struct snd_soc_dapm_widget wcd9375_dapm_widgets[] = {
  1257. /*input widgets*/
  1258. SND_SOC_DAPM_INPUT("AMIC4"),
  1259. /*tx widgets*/
  1260. SND_SOC_DAPM_ADC_E("ADC3", NULL, SND_SOC_NOPM, 0, 2,
  1261. wcd937x_codec_enable_adc,
  1262. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1263. SND_SOC_DAPM_MIXER_E("ADC3 REQ", SND_SOC_NOPM, 0, 0,
  1264. NULL, 0, wcd937x_enable_req,
  1265. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1266. SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 0, 0,
  1267. wcd937x_codec_enable_dmic,
  1268. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1269. SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 0, 1,
  1270. wcd937x_codec_enable_dmic,
  1271. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1272. SND_SOC_DAPM_ADC_E("DMIC3", NULL, SND_SOC_NOPM, 0, 2,
  1273. wcd937x_codec_enable_dmic,
  1274. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1275. SND_SOC_DAPM_ADC_E("DMIC4", NULL, SND_SOC_NOPM, 0, 3,
  1276. wcd937x_codec_enable_dmic,
  1277. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1278. SND_SOC_DAPM_ADC_E("DMIC5", NULL, SND_SOC_NOPM, 0, 4,
  1279. wcd937x_codec_enable_dmic,
  1280. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1281. SND_SOC_DAPM_ADC_E("DMIC6", NULL, SND_SOC_NOPM, 0, 5,
  1282. wcd937x_codec_enable_dmic,
  1283. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1284. /*tx mixer widgets*/
  1285. SND_SOC_DAPM_MIXER_E("DMIC1_MIXER", SND_SOC_NOPM, 0,
  1286. 0, dmic1_switch, ARRAY_SIZE(dmic1_switch),
  1287. wcd937x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  1288. SND_SOC_DAPM_POST_PMD),
  1289. SND_SOC_DAPM_MIXER_E("DMIC2_MIXER", SND_SOC_NOPM, 0,
  1290. 0, dmic2_switch, ARRAY_SIZE(dmic2_switch),
  1291. wcd937x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  1292. SND_SOC_DAPM_POST_PMD),
  1293. SND_SOC_DAPM_MIXER_E("DMIC3_MIXER", SND_SOC_NOPM, 0,
  1294. 0, dmic3_switch, ARRAY_SIZE(dmic3_switch),
  1295. wcd937x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  1296. SND_SOC_DAPM_POST_PMD),
  1297. SND_SOC_DAPM_MIXER_E("DMIC4_MIXER", SND_SOC_NOPM, 0,
  1298. 0, dmic4_switch, ARRAY_SIZE(dmic4_switch),
  1299. wcd937x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  1300. SND_SOC_DAPM_POST_PMD),
  1301. SND_SOC_DAPM_MIXER_E("DMIC5_MIXER", SND_SOC_NOPM, 0,
  1302. 0, dmic5_switch, ARRAY_SIZE(dmic5_switch),
  1303. wcd937x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  1304. SND_SOC_DAPM_POST_PMD),
  1305. SND_SOC_DAPM_MIXER_E("DMIC6_MIXER", SND_SOC_NOPM, 0,
  1306. 0, dmic6_switch, ARRAY_SIZE(dmic6_switch),
  1307. wcd937x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  1308. SND_SOC_DAPM_POST_PMD),
  1309. SND_SOC_DAPM_MIXER_E("ADC3_MIXER", SND_SOC_NOPM, 0, 0, adc3_switch,
  1310. ARRAY_SIZE(adc3_switch), wcd937x_tx_swr_ctrl,
  1311. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1312. /*output widgets*/
  1313. SND_SOC_DAPM_OUTPUT("DMIC1_OUTPUT"),
  1314. SND_SOC_DAPM_OUTPUT("DMIC2_OUTPUT"),
  1315. SND_SOC_DAPM_OUTPUT("DMIC3_OUTPUT"),
  1316. SND_SOC_DAPM_OUTPUT("DMIC4_OUTPUT"),
  1317. SND_SOC_DAPM_OUTPUT("DMIC5_OUTPUT"),
  1318. SND_SOC_DAPM_OUTPUT("DMIC6_OUTPUT"),
  1319. SND_SOC_DAPM_OUTPUT("ADC3_OUTPUT"),
  1320. };
  1321. static const struct snd_soc_dapm_route wcd937x_audio_map[] = {
  1322. {"ADC2_OUTPUT", NULL, "ADC2_MIXER"},
  1323. {"ADC2_MIXER", "Switch", "ADC2 REQ"},
  1324. {"ADC2 REQ", "NULL", "ADC2"},
  1325. {"ADC2", "NULL", "ADC2 MUX"},
  1326. {"ADC2 MUX", "INP3", "AMIC3"},
  1327. {"ADC2 MUX", "INP2", "AMIC2"},
  1328. {"ADC1_OUTPUT", NULL, "ADC1_MIXER"},
  1329. {"ADC1_MIXER", "Switch", "ADC1 REQ"},
  1330. {"ADC1 REQ", NULL, "ADC1"},
  1331. {"ADC1", NULL, "AMIC1"},
  1332. {"RX1", NULL, "IN1_HPHL"},
  1333. {"RDAC1", NULL, "RX1"},
  1334. {"HPHL_RDAC", "Switch", "RDAC1"},
  1335. {"HPHL PGA", NULL, "HPHL_RDAC"},
  1336. {"HPHL", NULL, "HPHL PGA"},
  1337. {"RX2", NULL, "IN2_HPHR"},
  1338. {"RDAC2", NULL, "RX2"},
  1339. {"HPHR_RDAC", "Switch", "RDAC2"},
  1340. {"HPHR PGA", NULL, "HPHR_RDAC"},
  1341. {"HPHR", NULL, "HPHR PGA"},
  1342. {"RX3", NULL, "IN3_AUX"},
  1343. {"RDAC4", NULL, "RX3"},
  1344. {"AUX_RDAC", "Switch", "RDAC4"},
  1345. {"AUX PGA", NULL, "AUX_RDAC"},
  1346. {"AUX", NULL, "AUX PGA"},
  1347. {"RDAC3_MUX", "RX3", "RX3"},
  1348. {"RDAC3_MUX", "RX1", "RX1"},
  1349. {"RDAC3", NULL, "RDAC3_MUX"},
  1350. {"EAR_RDAC", "Switch", "RDAC3"},
  1351. {"EAR PGA", NULL, "EAR_RDAC"},
  1352. {"EAR", NULL, "EAR PGA"},
  1353. };
  1354. static const struct snd_soc_dapm_route wcd9375_audio_map[] = {
  1355. {"ADC3_OUTPUT", NULL, "ADC3_MIXER"},
  1356. {"ADC3_MIXER", "Switch", "ADC3 REQ"},
  1357. {"ADC3 REQ", NULL, "ADC3"},
  1358. {"ADC3", NULL, "AMIC4"},
  1359. {"DMIC1_OUTPUT", NULL, "DMIC1_MIXER"},
  1360. {"DMIC1_MIXER", "Switch", "DMIC1"},
  1361. {"DMIC2_OUTPUT", NULL, "DMIC2_MIXER"},
  1362. {"DMIC2_MIXER", "Switch", "DMIC2"},
  1363. {"DMIC3_OUTPUT", NULL, "DMIC3_MIXER"},
  1364. {"DMIC3_MIXER", "Switch", "DMIC3"},
  1365. {"DMIC4_OUTPUT", NULL, "DMIC4_MIXER"},
  1366. {"DMIC4_MIXER", "Switch", "DMIC4"},
  1367. {"DMIC5_OUTPUT", NULL, "DMIC5_MIXER"},
  1368. {"DMIC5_MIXER", "Switch", "DMIC5"},
  1369. {"DMIC6_OUTPUT", NULL, "DMIC6_MIXER"},
  1370. {"DMIC6_MIXER", "Switch", "DMIC6"},
  1371. };
  1372. static int wcd937x_soc_codec_probe(struct snd_soc_codec *codec)
  1373. {
  1374. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  1375. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  1376. int variant;
  1377. int ret = -EINVAL;
  1378. dev_info(codec->dev, "%s()\n", __func__);
  1379. wcd937x = snd_soc_codec_get_drvdata(codec);
  1380. if (!wcd937x)
  1381. return -EINVAL;
  1382. wcd937x->codec = codec;
  1383. variant = (snd_soc_read(codec, WCD937X_DIGITAL_EFUSE_REG_0) & 0x0E) >> 1;
  1384. wcd937x->variant = variant;
  1385. wcd937x->fw_data = devm_kzalloc(codec->dev,
  1386. sizeof(*(wcd937x->fw_data)),
  1387. GFP_KERNEL);
  1388. if (!wcd937x->fw_data) {
  1389. dev_err(codec->dev, "Failed to allocate fw_data\n");
  1390. ret = -ENOMEM;
  1391. goto err;
  1392. }
  1393. set_bit(WCD9XXX_MBHC_CAL, wcd937x->fw_data->cal_bit);
  1394. ret = wcd_cal_create_hwdep(wcd937x->fw_data,
  1395. WCD9XXX_CODEC_HWDEP_NODE, codec);
  1396. if (ret < 0) {
  1397. dev_err(codec->dev, "%s hwdep failed %d\n", __func__, ret);
  1398. goto err_hwdep;
  1399. }
  1400. ret = wcd937x_mbhc_init(&wcd937x->mbhc, codec, wcd937x->fw_data);
  1401. if (ret) {
  1402. pr_err("%s: mbhc initialization failed\n", __func__);
  1403. goto err_hwdep;
  1404. }
  1405. wcd937x_init_reg(codec);
  1406. if (wcd937x->variant == WCD9375_VARIANT) {
  1407. ret = snd_soc_dapm_new_controls(dapm, wcd9375_dapm_widgets,
  1408. ARRAY_SIZE(wcd9375_dapm_widgets));
  1409. if (ret < 0) {
  1410. dev_err(codec->dev, "%s: Failed to add snd_ctls\n",
  1411. __func__);
  1412. goto err_hwdep;
  1413. }
  1414. ret = snd_soc_dapm_add_routes(dapm, wcd9375_audio_map,
  1415. ARRAY_SIZE(wcd9375_audio_map));
  1416. if (ret < 0) {
  1417. dev_err(codec->dev, "%s: Failed to add routes\n",
  1418. __func__);
  1419. goto err_hwdep;
  1420. }
  1421. ret = snd_soc_dapm_new_widgets(dapm->card);
  1422. if (ret < 0) {
  1423. dev_err(codec->dev, "%s: Failed to add widgets\n",
  1424. __func__);
  1425. goto err_hwdep;
  1426. }
  1427. }
  1428. return ret;
  1429. err_hwdep:
  1430. wcd937x->fw_data = NULL;
  1431. err:
  1432. return ret;
  1433. }
  1434. static int wcd937x_soc_codec_remove(struct snd_soc_codec *codec)
  1435. {
  1436. struct wcd937x_priv *wcd937x = snd_soc_codec_get_drvdata(codec);
  1437. if (!wcd937x)
  1438. return -EINVAL;
  1439. return 0;
  1440. }
  1441. static struct regmap *wcd937x_get_regmap(struct device *dev)
  1442. {
  1443. struct wcd937x_priv *wcd937x = dev_get_drvdata(dev);
  1444. return wcd937x->regmap;
  1445. }
  1446. static struct snd_soc_codec_driver soc_codec_dev_wcd937x = {
  1447. .probe = wcd937x_soc_codec_probe,
  1448. .remove = wcd937x_soc_codec_remove,
  1449. .get_regmap = wcd937x_get_regmap,
  1450. .component_driver = {
  1451. .controls = wcd937x_snd_controls,
  1452. .num_controls = ARRAY_SIZE(wcd937x_snd_controls),
  1453. .dapm_widgets = wcd937x_dapm_widgets,
  1454. .num_dapm_widgets = ARRAY_SIZE(wcd937x_dapm_widgets),
  1455. .dapm_routes = wcd937x_audio_map,
  1456. .num_dapm_routes = ARRAY_SIZE(wcd937x_audio_map),
  1457. },
  1458. };
  1459. int wcd937x_reset(struct device *dev)
  1460. {
  1461. struct wcd937x_priv *wcd937x = NULL;
  1462. int rc = 0;
  1463. int value = 0;
  1464. if (!dev)
  1465. return -ENODEV;
  1466. wcd937x = dev_get_drvdata(dev);
  1467. if (!wcd937x)
  1468. return -EINVAL;
  1469. if (!wcd937x->rst_np) {
  1470. dev_err(dev, "%s: reset gpio device node not specified\n",
  1471. __func__);
  1472. return -EINVAL;
  1473. }
  1474. value = msm_cdc_pinctrl_get_state(wcd937x->rst_np);
  1475. if (value > 0)
  1476. return 0;
  1477. rc = msm_cdc_pinctrl_select_sleep_state(wcd937x->rst_np);
  1478. if (rc) {
  1479. dev_err(dev, "%s: wcd sleep state request fail!\n",
  1480. __func__);
  1481. return rc;
  1482. }
  1483. /* 20ms sleep required after pulling the reset gpio to LOW */
  1484. usleep_range(20, 30);
  1485. rc = msm_cdc_pinctrl_select_active_state(wcd937x->rst_np);
  1486. if (rc) {
  1487. dev_err(dev, "%s: wcd active state request fail!\n",
  1488. __func__);
  1489. return rc;
  1490. }
  1491. /* 20ms sleep required after pulling the reset gpio to HIGH */
  1492. usleep_range(20, 30);
  1493. return rc;
  1494. }
  1495. struct wcd937x_pdata *wcd937x_populate_dt_data(struct device *dev)
  1496. {
  1497. struct wcd937x_pdata *pdata = NULL;
  1498. pdata = devm_kzalloc(dev, sizeof(struct wcd937x_pdata),
  1499. GFP_KERNEL);
  1500. if (!pdata)
  1501. return NULL;
  1502. pdata->rst_np = of_parse_phandle(dev->of_node,
  1503. "qcom,wcd-rst-gpio-node", 0);
  1504. if (!pdata->rst_np) {
  1505. dev_err(dev, "%s: Looking up %s property in node %s failed\n",
  1506. __func__, "qcom,wcd-rst-gpio-node",
  1507. dev->of_node->full_name);
  1508. return NULL;
  1509. }
  1510. /* Parse power supplies */
  1511. msm_cdc_get_power_supplies(dev, &pdata->regulator,
  1512. &pdata->num_supplies);
  1513. if (!pdata->regulator || (pdata->num_supplies <= 0)) {
  1514. dev_err(dev, "%s: no power supplies defined for codec\n",
  1515. __func__);
  1516. return NULL;
  1517. }
  1518. pdata->rx_slave = of_parse_phandle(dev->of_node, "qcom,rx-slave", 0);
  1519. pdata->tx_slave = of_parse_phandle(dev->of_node, "qcom,tx-slave", 0);
  1520. return pdata;
  1521. }
  1522. static int wcd937x_bind(struct device *dev)
  1523. {
  1524. int ret = 0, i = 0;
  1525. struct wcd937x_priv *wcd937x = NULL;
  1526. struct wcd937x_pdata *pdata = NULL;
  1527. wcd937x = devm_kzalloc(dev, sizeof(struct wcd937x_priv), GFP_KERNEL);
  1528. if (!wcd937x)
  1529. return -ENOMEM;
  1530. dev_set_drvdata(dev, wcd937x);
  1531. pdata = wcd937x_populate_dt_data(dev);
  1532. if (!pdata) {
  1533. dev_err(dev, "%s: Fail to obtain platform data\n", __func__);
  1534. return -EINVAL;
  1535. }
  1536. wcd937x->rst_np = pdata->rst_np;
  1537. ret = msm_cdc_init_supplies(dev, &wcd937x->supplies,
  1538. pdata->regulator, pdata->num_supplies);
  1539. if (!wcd937x->supplies) {
  1540. dev_err(dev, "%s: Cannot init wcd supplies\n",
  1541. __func__);
  1542. return ret;
  1543. }
  1544. ret = msm_cdc_enable_static_supplies(dev, wcd937x->supplies,
  1545. pdata->regulator,
  1546. pdata->num_supplies);
  1547. if (ret) {
  1548. dev_err(dev, "%s: wcd static supply enable failed!\n",
  1549. __func__);
  1550. return ret;
  1551. }
  1552. wcd937x_reset(dev);
  1553. /*
  1554. * Add 5msec delay to provide sufficient time for
  1555. * soundwire auto enumeration of slave devices as
  1556. * as per HW requirement.
  1557. */
  1558. usleep_range(5000, 5010);
  1559. ret = component_bind_all(dev, wcd937x);
  1560. if (ret) {
  1561. dev_err(dev, "%s: Slave bind failed, ret = %d\n",
  1562. __func__, ret);
  1563. return ret;
  1564. }
  1565. ret = wcd937x_parse_port_mapping(dev, "qcom,rx_swr_ch_map", CODEC_RX);
  1566. ret |= wcd937x_parse_port_mapping(dev, "qcom,tx_swr_ch_map", CODEC_TX);
  1567. if (ret) {
  1568. dev_err(dev, "Failed to read port mapping\n");
  1569. goto err;
  1570. }
  1571. wcd937x->rx_swr_dev = get_matching_swr_slave_device(pdata->rx_slave);
  1572. if (!wcd937x->rx_swr_dev) {
  1573. dev_err(dev, "%s: Could not find RX swr slave device\n",
  1574. __func__);
  1575. ret = -ENODEV;
  1576. goto err;
  1577. }
  1578. wcd937x->tx_swr_dev = get_matching_swr_slave_device(pdata->tx_slave);
  1579. if (!wcd937x->tx_swr_dev) {
  1580. dev_err(dev, "%s: Could not find TX swr slave device\n",
  1581. __func__);
  1582. ret = -ENODEV;
  1583. goto err;
  1584. }
  1585. wcd937x->regmap = devm_regmap_init_swr(wcd937x->tx_swr_dev,
  1586. &wcd937x_regmap_config);
  1587. if (!wcd937x->regmap) {
  1588. dev_err(dev, "%s: Regmap init failed\n",
  1589. __func__);
  1590. goto err;
  1591. }
  1592. /* Set all interupts as edge triggered */
  1593. for (i = 0; i < wcd937x_regmap_irq_chip.num_regs; i++)
  1594. regmap_write(wcd937x->regmap,
  1595. (WCD937X_DIGITAL_INTR_LEVEL_0 + i), 0);
  1596. wcd937x->irq_info->wcd_regmap_irq_chip = &wcd937x_regmap_irq_chip;
  1597. wcd937x->irq_info->codec_name = "WCD937X";
  1598. wcd937x->irq_info->regmap = wcd937x->regmap;
  1599. wcd937x->irq_info->dev = dev;
  1600. ret = wcd_irq_init(wcd937x->irq_info, &wcd937x->virq);
  1601. if (ret) {
  1602. dev_err(wcd937x->dev, "%s: IRQ init failed: %d\n",
  1603. __func__, ret);
  1604. goto err;
  1605. }
  1606. wcd937x->tx_swr_dev->slave_irq = wcd937x->virq;
  1607. ret = snd_soc_register_codec(dev, &soc_codec_dev_wcd937x,
  1608. NULL, 0);
  1609. if (ret) {
  1610. dev_err(dev, "%s: Codec registration failed\n",
  1611. __func__);
  1612. goto err_irq;
  1613. }
  1614. return ret;
  1615. err_irq:
  1616. wcd_irq_exit(wcd937x->irq_info, wcd937x->virq);
  1617. err:
  1618. component_unbind_all(dev, wcd937x);
  1619. return ret;
  1620. }
  1621. static void wcd937x_unbind(struct device *dev)
  1622. {
  1623. struct wcd937x_priv *wcd937x = dev_get_drvdata(dev);
  1624. wcd_irq_exit(wcd937x->irq_info, wcd937x->virq);
  1625. snd_soc_unregister_codec(dev);
  1626. component_unbind_all(dev, wcd937x);
  1627. }
  1628. static const struct of_device_id wcd937x_dt_match[] = {
  1629. { .compatible = "qcom,wcd937x-codec" },
  1630. {}
  1631. };
  1632. static const struct component_master_ops wcd937x_comp_ops = {
  1633. .bind = wcd937x_bind,
  1634. .unbind = wcd937x_unbind,
  1635. };
  1636. static int wcd937x_compare_of(struct device *dev, void *data)
  1637. {
  1638. return dev->of_node == data;
  1639. }
  1640. static void wcd937x_release_of(struct device *dev, void *data)
  1641. {
  1642. of_node_put(data);
  1643. }
  1644. static int wcd937x_add_slave_components(struct device *dev,
  1645. struct component_match **matchptr)
  1646. {
  1647. struct device_node *np, *rx_node, *tx_node;
  1648. np = dev->of_node;
  1649. rx_node = of_parse_phandle(np, "qcom,rx-slave", 0);
  1650. if (!rx_node) {
  1651. dev_err(dev, "%s: Rx-slave node not defined\n", __func__);
  1652. return -ENODEV;
  1653. }
  1654. of_node_get(rx_node);
  1655. component_match_add_release(dev, matchptr,
  1656. wcd937x_release_of,
  1657. wcd937x_compare_of,
  1658. rx_node);
  1659. tx_node = of_parse_phandle(np, "qcom,tx-slave", 0);
  1660. if (!tx_node) {
  1661. dev_err(dev, "%s: Tx-slave node not defined\n", __func__);
  1662. return -ENODEV;
  1663. }
  1664. of_node_get(tx_node);
  1665. component_match_add_release(dev, matchptr,
  1666. wcd937x_release_of,
  1667. wcd937x_compare_of,
  1668. tx_node);
  1669. return 0;
  1670. }
  1671. static int wcd937x_probe(struct platform_device *pdev)
  1672. {
  1673. struct component_match *match = NULL;
  1674. int ret;
  1675. ret = wcd937x_add_slave_components(&pdev->dev, &match);
  1676. if (ret)
  1677. return ret;
  1678. return component_master_add_with_match(&pdev->dev,
  1679. &wcd937x_comp_ops, match);
  1680. }
  1681. static int wcd937x_remove(struct platform_device *pdev)
  1682. {
  1683. component_master_del(&pdev->dev, &wcd937x_comp_ops);
  1684. return 0;
  1685. }
  1686. static struct platform_driver wcd937x_codec_driver = {
  1687. .probe = wcd937x_probe,
  1688. .remove = wcd937x_remove,
  1689. .driver = {
  1690. .name = "wcd937x_codec",
  1691. .owner = THIS_MODULE,
  1692. .of_match_table = of_match_ptr(wcd937x_dt_match),
  1693. },
  1694. };
  1695. module_platform_driver(wcd937x_codec_driver);
  1696. MODULE_DESCRIPTION("WCD937X Codec driver");
  1697. MODULE_LICENSE("GPL v2");