sdx-target.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2016-2020, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/clk.h>
  6. #include <linux/delay.h>
  7. #include <linux/gpio.h>
  8. #include <linux/of_gpio.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/slab.h>
  11. #include <linux/io.h>
  12. #include <linux/module.h>
  13. #include <linux/input.h>
  14. #include <linux/of_device.h>
  15. #include <linux/soc/qcom/fsa4480-i2c.h>
  16. #include <sound/control.h>
  17. #include <sound/core.h>
  18. #include <sound/soc.h>
  19. #include <sound/soc-dapm.h>
  20. #include <sound/pcm.h>
  21. #include <sound/pcm_params.h>
  22. #include <sound/info.h>
  23. #include <soc/snd_event.h>
  24. #include <dsp/audio_prm.h>
  25. #include <soc/swr-common.h>
  26. #include <soc/soundwire.h>
  27. #include "device_event.h"
  28. #include "asoc/msm-cdc-pinctrl.h"
  29. #include "asoc/wcd-mbhc-v2.h"
  30. #include "codecs/wcd934x/wcd934x-mbhc.h"
  31. #include "codecs/wsa881x.h"
  32. #include "codecs/wcd934x/wcd934x.h"
  33. #include <dt-bindings/sound/audio-codec-port-types.h>
  34. #include "sdx-port-config.h"
  35. #include "msm-audio-defs.h"
  36. #include "msm_common.h"
  37. #include "msm_dailink.h"
  38. #define DRV_NAME "sdx-asoc-snd"
  39. #define __CHIPSET__ "LAHAINA "
  40. #define MSM_DAILINK_NAME(name) (__CHIPSET__#name)
  41. #define WCD9XXX_MBHC_DEF_RLOADS 5
  42. #define WCD9XXX_MBHC_DEF_BUTTONS 8
  43. #define CODEC_EXT_CLK_RATE 9600000
  44. #define DEV_NAME_STR_LEN 32
  45. #define WCD_MBHC_HS_V_MAX 1600
  46. #define MSM_LL_QOS_VALUE 300 /* time in us to ensure LPM doesn't go in C3/C4 */
  47. #define WCN_CDC_SLIM_RX_CH_MAX 2
  48. #define WCN_CDC_SLIM_TX_CH_MAX 2
  49. #define WCN_CDC_SLIM_TX_CH_MAX_LITO 3
  50. struct msm_asoc_mach_data {
  51. struct snd_info_entry *codec_root;
  52. struct msm_common_pdata *common_pdata;
  53. int usbc_en2_gpio; /* used by gpio driver API */
  54. struct device_node *dmic01_gpio_p; /* used by pinctrl API */
  55. struct device_node *dmic23_gpio_p; /* used by pinctrl API */
  56. struct device_node *dmic45_gpio_p; /* used by pinctrl API */
  57. struct device_node *us_euro_gpio_p; /* used by pinctrl API */
  58. struct pinctrl *usbc_en2_gpio_p; /* used by pinctrl API */
  59. struct device_node *hph_en1_gpio_p; /* used by pinctrl API */
  60. struct device_node *hph_en0_gpio_p; /* used by pinctrl API */
  61. bool is_afe_config_done;
  62. struct device_node *fsa_handle;
  63. struct clk *lpass_audio_hw_vote;
  64. int core_audio_vote_count;
  65. u32 wsa_max_devs;
  66. };
  67. static bool is_initial_boot;
  68. static bool codec_reg_done;
  69. static struct snd_soc_card snd_soc_card_sdx_msm;
  70. static int dmic_0_1_gpio_cnt;
  71. static int dmic_2_3_gpio_cnt;
  72. static int dmic_4_5_gpio_cnt;
  73. static void *def_wcd_mbhc_cal(void);
  74. static int msm_aux_codec_init(struct snd_soc_pcm_runtime*);
  75. static int msm_int_audrx_init(struct snd_soc_pcm_runtime*);
  76. /*
  77. * Need to report LINEIN
  78. * if R/L channel impedance is larger than 5K ohm
  79. */
  80. static struct wcd_mbhc_config wcd_mbhc_cfg = {
  81. .read_fw_bin = false,
  82. .calibration = NULL,
  83. .detect_extn_cable = true,
  84. .mono_stero_detection = false,
  85. .swap_gnd_mic = NULL,
  86. .hs_ext_micbias = true,
  87. .key_code[0] = KEY_MEDIA,
  88. .key_code[1] = KEY_VOICECOMMAND,
  89. .key_code[2] = KEY_VOLUMEUP,
  90. .key_code[3] = KEY_VOLUMEDOWN,
  91. .key_code[4] = 0,
  92. .key_code[5] = 0,
  93. .key_code[6] = 0,
  94. .key_code[7] = 0,
  95. .linein_th = 5000,
  96. .moisture_en = false,
  97. .mbhc_micbias = MIC_BIAS_2,
  98. .anc_micbias = MIC_BIAS_2,
  99. .enable_anc_mic_detect = false,
  100. .moisture_duty_cycle_en = true,
  101. };
  102. /* set audio task affinity to core 1 & 2 */
  103. static const unsigned int audio_core_list[] = {1, 2};
  104. static cpumask_t audio_cpu_map = CPU_MASK_NONE;
  105. static struct dev_pm_qos_request *msm_audio_req = NULL;
  106. static void msm_audio_add_qos_request()
  107. {
  108. int i;
  109. int cpu = 0;
  110. msm_audio_req = kzalloc(sizeof(struct dev_pm_qos_request) * NR_CPUS,
  111. GFP_KERNEL);
  112. if (!msm_audio_req) {
  113. pr_err("%s failed to alloc mem for qos req.\n", __func__);
  114. return;
  115. }
  116. for (i = 0; i < ARRAY_SIZE(audio_core_list); i++) {
  117. if (audio_core_list[i] >= NR_CPUS)
  118. pr_err("%s incorrect cpu id: %d specified.\n", __func__, audio_core_list[i]);
  119. else
  120. cpumask_set_cpu(audio_core_list[i], &audio_cpu_map);
  121. }
  122. for_each_cpu(cpu, &audio_cpu_map) {
  123. dev_pm_qos_add_request(get_cpu_device(cpu),
  124. &msm_audio_req[cpu],
  125. DEV_PM_QOS_RESUME_LATENCY,
  126. PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE);
  127. pr_debug("%s set cpu affinity to core %d.\n", __func__, cpu);
  128. }
  129. }
  130. static void msm_audio_remove_qos_request()
  131. {
  132. int cpu = 0;
  133. if (msm_audio_req) {
  134. for_each_cpu(cpu, &audio_cpu_map) {
  135. dev_pm_qos_remove_request(
  136. &msm_audio_req[cpu]);
  137. pr_debug("%s remove cpu affinity of core %d.\n", __func__, cpu);
  138. }
  139. kfree(msm_audio_req);
  140. }
  141. }
  142. static bool msm_usbc_swap_gnd_mic(struct snd_soc_component *component, bool active)
  143. {
  144. struct snd_soc_card *card = component->card;
  145. struct msm_asoc_mach_data *pdata =
  146. snd_soc_card_get_drvdata(card);
  147. if (!pdata->fsa_handle)
  148. return false;
  149. return fsa4480_switch_event(pdata->fsa_handle, FSA_MIC_GND_SWAP);
  150. }
  151. static bool msm_swap_gnd_mic(struct snd_soc_component *component, bool active)
  152. {
  153. int value = 0;
  154. bool ret = false;
  155. struct snd_soc_card *card;
  156. struct msm_asoc_mach_data *pdata;
  157. if (!component) {
  158. pr_err("%s component is NULL\n", __func__);
  159. return false;
  160. }
  161. card = component->card;
  162. pdata = snd_soc_card_get_drvdata(card);
  163. if (!pdata)
  164. return false;
  165. if (wcd_mbhc_cfg.enable_usbc_analog)
  166. return msm_usbc_swap_gnd_mic(component, active);
  167. /* if usbc is not defined, swap using us_euro_gpio_p */
  168. if (pdata->us_euro_gpio_p) {
  169. value = msm_cdc_pinctrl_get_state(
  170. pdata->us_euro_gpio_p);
  171. if (value)
  172. msm_cdc_pinctrl_select_sleep_state(
  173. pdata->us_euro_gpio_p);
  174. else
  175. msm_cdc_pinctrl_select_active_state(
  176. pdata->us_euro_gpio_p);
  177. dev_dbg(component->dev, "%s: swap select switch %d to %d\n",
  178. __func__, value, !value);
  179. ret = true;
  180. }
  181. return ret;
  182. }
  183. static struct snd_soc_ops msm_common_be_ops = {
  184. .hw_params = msm_common_snd_hw_params,
  185. .startup = msm_common_snd_startup,
  186. .shutdown = msm_common_snd_shutdown,
  187. };
  188. static int msm_dmic_event(struct snd_soc_dapm_widget *w,
  189. struct snd_kcontrol *kcontrol, int event)
  190. {
  191. struct msm_asoc_mach_data *pdata = NULL;
  192. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  193. int ret = 0;
  194. u32 dmic_idx;
  195. int *dmic_gpio_cnt;
  196. struct device_node *dmic_gpio;
  197. char *wname;
  198. wname = strpbrk(w->name, "012345");
  199. if (!wname) {
  200. dev_err(component->dev, "%s: widget not found\n", __func__);
  201. return -EINVAL;
  202. }
  203. ret = kstrtouint(wname, 10, &dmic_idx);
  204. if (ret < 0) {
  205. dev_err(component->dev, "%s: Invalid DMIC line on the codec\n",
  206. __func__);
  207. return -EINVAL;
  208. }
  209. pdata = snd_soc_card_get_drvdata(component->card);
  210. switch (dmic_idx) {
  211. case 0:
  212. case 1:
  213. dmic_gpio_cnt = &dmic_0_1_gpio_cnt;
  214. dmic_gpio = pdata->dmic01_gpio_p;
  215. break;
  216. case 2:
  217. case 3:
  218. dmic_gpio_cnt = &dmic_2_3_gpio_cnt;
  219. dmic_gpio = pdata->dmic23_gpio_p;
  220. break;
  221. case 4:
  222. case 5:
  223. dmic_gpio_cnt = &dmic_4_5_gpio_cnt;
  224. dmic_gpio = pdata->dmic45_gpio_p;
  225. break;
  226. default:
  227. dev_err(component->dev, "%s: Invalid DMIC Selection\n",
  228. __func__);
  229. return -EINVAL;
  230. }
  231. dev_dbg(component->dev, "%s: event %d DMIC%d dmic_gpio_cnt %d\n",
  232. __func__, event, dmic_idx, *dmic_gpio_cnt);
  233. switch (event) {
  234. case SND_SOC_DAPM_PRE_PMU:
  235. (*dmic_gpio_cnt)++;
  236. if (*dmic_gpio_cnt == 1) {
  237. ret = msm_cdc_pinctrl_select_active_state(
  238. dmic_gpio);
  239. if (ret < 0) {
  240. pr_err("%s: gpio set cannot be activated %sd",
  241. __func__, "dmic_gpio");
  242. return ret;
  243. }
  244. }
  245. break;
  246. case SND_SOC_DAPM_POST_PMD:
  247. (*dmic_gpio_cnt)--;
  248. if (*dmic_gpio_cnt == 0) {
  249. ret = msm_cdc_pinctrl_select_sleep_state(
  250. dmic_gpio);
  251. if (ret < 0) {
  252. pr_err("%s: gpio set cannot be de-activated %sd",
  253. __func__, "dmic_gpio");
  254. return ret;
  255. }
  256. }
  257. break;
  258. default:
  259. pr_err("%s: invalid DAPM event %d\n", __func__, event);
  260. return -EINVAL;
  261. }
  262. return 0;
  263. }
  264. static const struct snd_soc_dapm_widget msm_int_dapm_widgets[] = {
  265. SND_SOC_DAPM_MIC("Analog Mic1", NULL),
  266. SND_SOC_DAPM_MIC("Analog Mic2", NULL),
  267. SND_SOC_DAPM_MIC("Analog Mic3", NULL),
  268. SND_SOC_DAPM_MIC("Analog Mic4", NULL),
  269. SND_SOC_DAPM_MIC("Analog Mic5", NULL),
  270. SND_SOC_DAPM_MIC("Digital Mic0", msm_dmic_event),
  271. SND_SOC_DAPM_MIC("Digital Mic1", msm_dmic_event),
  272. SND_SOC_DAPM_MIC("Digital Mic2", msm_dmic_event),
  273. SND_SOC_DAPM_MIC("Digital Mic3", msm_dmic_event),
  274. SND_SOC_DAPM_MIC("Digital Mic4", msm_dmic_event),
  275. SND_SOC_DAPM_MIC("Digital Mic5", msm_dmic_event),
  276. SND_SOC_DAPM_MIC("Digital Mic6", NULL),
  277. SND_SOC_DAPM_MIC("Digital Mic7", NULL),
  278. };
  279. static struct snd_info_entry *msm_snd_info_create_subdir(struct module *mod,
  280. const char *name,
  281. struct snd_info_entry *parent)
  282. {
  283. struct snd_info_entry *entry;
  284. entry = snd_info_create_module_entry(mod, name, parent);
  285. if (!entry)
  286. return NULL;
  287. entry->mode = S_IFDIR | 0555;
  288. if (snd_info_register(entry) < 0) {
  289. snd_info_free_entry(entry);
  290. return NULL;
  291. }
  292. return entry;
  293. }
  294. static void *def_wcd_mbhc_cal(void)
  295. {
  296. void *wcd_mbhc_cal;
  297. struct wcd_mbhc_btn_detect_cfg *btn_cfg;
  298. u16 *btn_high;
  299. wcd_mbhc_cal = kzalloc(WCD_MBHC_CAL_SIZE(WCD_MBHC_DEF_BUTTONS,
  300. WCD9XXX_MBHC_DEF_RLOADS), GFP_KERNEL);
  301. if (!wcd_mbhc_cal)
  302. return NULL;
  303. WCD_MBHC_CAL_PLUG_TYPE_PTR(wcd_mbhc_cal)->v_hs_max = WCD_MBHC_HS_V_MAX;
  304. WCD_MBHC_CAL_BTN_DET_PTR(wcd_mbhc_cal)->num_btn = WCD_MBHC_DEF_BUTTONS;
  305. btn_cfg = WCD_MBHC_CAL_BTN_DET_PTR(wcd_mbhc_cal);
  306. btn_high = ((void *)&btn_cfg->_v_btn_low) +
  307. (sizeof(btn_cfg->_v_btn_low[0]) * btn_cfg->num_btn);
  308. btn_high[0] = 75;
  309. btn_high[1] = 150;
  310. btn_high[2] = 237;
  311. btn_high[3] = 500;
  312. btn_high[4] = 500;
  313. btn_high[5] = 500;
  314. btn_high[6] = 500;
  315. btn_high[7] = 500;
  316. return wcd_mbhc_cal;
  317. }
  318. /* Digital audio interface glue - connects codec <---> CPU */
  319. static struct snd_soc_dai_link msm_common_be_dai_links[] = {
  320. /* Proxy Tx BACK END DAI Link */
  321. {
  322. .name = LPASS_BE_RT_PROXY_PCM_TX,
  323. .stream_name = LPASS_BE_RT_PROXY_PCM_TX,
  324. .capture_only = 1,
  325. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  326. SND_SOC_DPCM_TRIGGER_POST},
  327. .ignore_suspend = 1,
  328. .ops = &msm_common_be_ops,
  329. SND_SOC_DAILINK_REG(proxy_tx),
  330. },
  331. /* Proxy Rx BACK END DAI Link */
  332. {
  333. .name = LPASS_BE_RT_PROXY_PCM_RX,
  334. .stream_name = LPASS_BE_RT_PROXY_PCM_RX,
  335. .playback_only = 1,
  336. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  337. SND_SOC_DPCM_TRIGGER_POST},
  338. .ignore_pmdown_time = 1,
  339. .ignore_suspend = 1,
  340. .ops = &msm_common_be_ops,
  341. SND_SOC_DAILINK_REG(proxy_rx),
  342. },
  343. {
  344. .name = LPASS_BE_USB_AUDIO_RX,
  345. .stream_name = LPASS_BE_USB_AUDIO_RX,
  346. .playback_only = 1,
  347. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  348. SND_SOC_DPCM_TRIGGER_POST},
  349. .ignore_pmdown_time = 1,
  350. .ignore_suspend = 1,
  351. .ops = &msm_common_be_ops,
  352. SND_SOC_DAILINK_REG(usb_audio_rx),
  353. },
  354. {
  355. .name = LPASS_BE_USB_AUDIO_TX,
  356. .stream_name = LPASS_BE_USB_AUDIO_TX,
  357. .capture_only = 1,
  358. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  359. SND_SOC_DPCM_TRIGGER_POST},
  360. .ignore_suspend = 1,
  361. .ops = &msm_common_be_ops,
  362. SND_SOC_DAILINK_REG(usb_audio_tx),
  363. },
  364. };
  365. static struct snd_soc_dai_link msm_rx_tx_cdc_dma_be_dai_links[] = {
  366. /* WSA CDC DMA Backend DAI Links */
  367. {
  368. .name = LPASS_BE_PRI_MI2S_RX,
  369. .stream_name = LPASS_BE_PRI_MI2S_RX,
  370. .playback_only = 1,
  371. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  372. SND_SOC_DPCM_TRIGGER_POST},
  373. .ignore_pmdown_time = 1,
  374. .ignore_suspend = 1,
  375. .ops = &msm_common_be_ops,
  376. SND_SOC_DAILINK_REG(tavil_i2s_rx1),
  377. .init = &msm_aux_codec_init,
  378. },
  379. {
  380. .name = LPASS_BE_PRI_MI2S_TX,
  381. .stream_name = LPASS_BE_PRI_MI2S_TX,
  382. .playback_only = 1,
  383. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  384. SND_SOC_DPCM_TRIGGER_POST},
  385. .ignore_pmdown_time = 1,
  386. .ignore_suspend = 1,
  387. .ops = &msm_common_be_ops,
  388. SND_SOC_DAILINK_REG(tavil_i2s_tx1),
  389. },
  390. };
  391. static struct snd_soc_dai_link msm_tdm_dai_links[] = {
  392. {
  393. .name = LPASS_BE_PRI_TDM_RX_0,
  394. .stream_name = LPASS_BE_PRI_TDM_RX_0,
  395. .playback_only = 1,
  396. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  397. SND_SOC_DPCM_TRIGGER_POST},
  398. .ops = &msm_common_be_ops,
  399. .ignore_suspend = 1,
  400. .ignore_pmdown_time = 1,
  401. SND_SOC_DAILINK_REG(pri_tdm_rx_0),
  402. },
  403. {
  404. .name = LPASS_BE_PRI_TDM_TX_0,
  405. .stream_name = LPASS_BE_PRI_TDM_TX_0,
  406. .capture_only = 1,
  407. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  408. SND_SOC_DPCM_TRIGGER_POST},
  409. .ops = &msm_common_be_ops,
  410. .ignore_suspend = 1,
  411. SND_SOC_DAILINK_REG(pri_tdm_tx_0),
  412. },
  413. };
  414. static struct snd_soc_dai_link msm_sdx_dai_links[
  415. ARRAY_SIZE(msm_rx_tx_cdc_dma_be_dai_links) +
  416. ARRAY_SIZE(msm_common_be_dai_links) +
  417. ARRAY_SIZE(msm_tdm_dai_links)];
  418. static int msm_populate_dai_link_component_of_node(
  419. struct snd_soc_card *card)
  420. {
  421. int i, j, index, ret = 0;
  422. struct device *cdev = card->dev;
  423. struct snd_soc_dai_link *dai_link = card->dai_link;
  424. struct device_node *np = NULL;
  425. int codecs_enabled = 0;
  426. struct snd_soc_dai_link_component *codecs_comp = NULL;
  427. if (!cdev) {
  428. dev_err(cdev, "%s: Sound card device memory NULL\n", __func__);
  429. return -ENODEV;
  430. }
  431. for (i = 0; i < card->num_links; i++) {
  432. if (dai_link[i].init == NULL)
  433. dai_link[i].init = &msm_common_dai_link_init;
  434. /* populate codec_of_node for snd card dai links */
  435. if (dai_link[i].num_codecs > 0) {
  436. for (j = 0; j < dai_link[i].num_codecs; j++) {
  437. if (dai_link[i].codecs[j].of_node ||
  438. !dai_link[i].codecs[j].name)
  439. continue;
  440. index = of_property_match_string(cdev->of_node,
  441. "asoc-codec-names",
  442. dai_link[i].codecs[j].name);
  443. if (index < 0)
  444. continue;
  445. np = of_parse_phandle(cdev->of_node,
  446. "asoc-codec",
  447. index);
  448. if (!np) {
  449. dev_err(cdev, "%s: retrieving phandle for codec %s failed\n",
  450. __func__,
  451. dai_link[i].codecs[j].name);
  452. ret = -ENODEV;
  453. goto err;
  454. }
  455. dai_link[i].codecs[j].of_node = np;
  456. dai_link[i].codecs[j].name = NULL;
  457. }
  458. }
  459. }
  460. /* In multi-codec scenario, check if codecs are enabled for this platform */
  461. for (i = 0; i < card->num_links; i++) {
  462. codecs_enabled = 0;
  463. if (dai_link[i].num_codecs > 1) {
  464. for (j = 0; j < dai_link[i].num_codecs; j++) {
  465. if (!dai_link[i].codecs[j].of_node)
  466. continue;
  467. np = dai_link[i].codecs[j].of_node;
  468. if (!of_device_is_available(np)) {
  469. dev_err(cdev, "%s: codec is disabled: %s\n",
  470. __func__,
  471. np->full_name);
  472. dai_link[i].codecs[j].of_node = NULL;
  473. continue;
  474. }
  475. codecs_enabled++;
  476. }
  477. if (codecs_enabled > 0 &&
  478. codecs_enabled < dai_link[i].num_codecs) {
  479. codecs_comp = devm_kzalloc(cdev,
  480. sizeof(struct snd_soc_dai_link_component)
  481. * codecs_enabled, GFP_KERNEL);
  482. if (!codecs_comp) {
  483. dev_err(cdev, "%s: %s dailink codec component alloc failed\n",
  484. __func__, dai_link[i].name);
  485. ret = -ENOMEM;
  486. goto err;
  487. }
  488. index = 0;
  489. for (j = 0; j < dai_link[i].num_codecs; j++) {
  490. if(dai_link[i].codecs[j].of_node) {
  491. codecs_comp[index].of_node =
  492. dai_link[i].codecs[j].of_node;
  493. codecs_comp[index].dai_name =
  494. dai_link[i].codecs[j].dai_name;
  495. codecs_comp[index].name = NULL;
  496. index++;
  497. }
  498. }
  499. dai_link[i].codecs = codecs_comp;
  500. dai_link[i].num_codecs = codecs_enabled;
  501. }
  502. }
  503. }
  504. err:
  505. return ret;
  506. }
  507. static int msm_audrx_stub_init(struct snd_soc_pcm_runtime *rtd)
  508. {
  509. return 0;
  510. }
  511. static int msm_snd_stub_hw_params(struct snd_pcm_substream *substream,
  512. struct snd_pcm_hw_params *params)
  513. {
  514. return 0;
  515. }
  516. static struct snd_soc_ops msm_stub_be_ops = {
  517. .hw_params = msm_snd_stub_hw_params,
  518. };
  519. struct snd_soc_card snd_soc_card_stub_msm = {
  520. .name = "sdx-stub-snd-card",
  521. };
  522. static struct snd_soc_dai_link msm_stub_be_dai_links[] = {
  523. /* Backend DAI Links */
  524. {
  525. .name = LPASS_BE_PRI_AUXPCM_RX,
  526. .stream_name = LPASS_BE_PRI_AUXPCM_RX,
  527. .playback_only = 1,
  528. .init = &msm_audrx_stub_init,
  529. .ignore_pmdown_time = 1,
  530. .ignore_suspend = 1,
  531. .ops = &msm_stub_be_ops,
  532. SND_SOC_DAILINK_REG(auxpcm_rx),
  533. },
  534. {
  535. .name = LPASS_BE_PRI_AUXPCM_TX,
  536. .stream_name = LPASS_BE_PRI_AUXPCM_TX,
  537. .capture_only = 1,
  538. .ignore_suspend = 1,
  539. .ops = &msm_stub_be_ops,
  540. SND_SOC_DAILINK_REG(auxpcm_tx),
  541. },
  542. };
  543. static struct snd_soc_dai_link msm_stub_dai_links[
  544. ARRAY_SIZE(msm_stub_be_dai_links)];
  545. static const struct of_device_id sdx_asoc_machine_of_match[] = {
  546. { .compatible = "qcom,sdx-asoc-snd-tavil",
  547. .data = "codec"},
  548. {},
  549. };
  550. static int msm_snd_card_late_probe(struct snd_soc_card *card)
  551. {
  552. struct snd_soc_component *component = NULL;
  553. const char *be_dl_name = LPASS_BE_RX_CDC_DMA_RX_0;
  554. struct snd_soc_pcm_runtime *rtd;
  555. int ret = 0;
  556. void *mbhc_calibration;
  557. rtd = snd_soc_get_pcm_runtime(card, be_dl_name);
  558. if (!rtd) {
  559. dev_err(card->dev,
  560. "%s: snd_soc_get_pcm_runtime for %s failed!\n",
  561. __func__, be_dl_name);
  562. return -EINVAL;
  563. }
  564. component = snd_soc_rtdcom_lookup(rtd, WCD934X_DRV_NAME);
  565. if (!component) {
  566. pr_err("%s component is NULL\n", __func__);
  567. return -EINVAL;
  568. }
  569. mbhc_calibration = def_wcd_mbhc_cal();
  570. if (!mbhc_calibration)
  571. return -ENOMEM;
  572. wcd_mbhc_cfg.calibration = mbhc_calibration;
  573. ret = tavil_mbhc_hs_detect(component, &wcd_mbhc_cfg);
  574. if (ret) {
  575. dev_err(component->dev, "%s: mbhc hs detect failed, err:%d\n",
  576. __func__, ret);
  577. goto err_hs_detect;
  578. }
  579. return 0;
  580. err_hs_detect:
  581. kfree(mbhc_calibration);
  582. return ret;
  583. }
  584. static struct snd_soc_card *populate_snd_card_dailinks(struct device *dev)
  585. {
  586. struct snd_soc_card *card = NULL;
  587. struct snd_soc_dai_link *dailink = NULL;
  588. int total_links = 0;
  589. int rc = 0;
  590. u32 val = 0;
  591. const struct of_device_id *match;
  592. match = of_match_node(sdx_asoc_machine_of_match, dev->of_node);
  593. if (!match) {
  594. dev_err(dev, "%s: No DT match found for sound card\n",
  595. __func__);
  596. return NULL;
  597. }
  598. if (!strcmp(match->data, "codec")) {
  599. card = &snd_soc_card_sdx_msm;
  600. memcpy(msm_sdx_dai_links + total_links,
  601. msm_rx_tx_cdc_dma_be_dai_links,
  602. sizeof(msm_rx_tx_cdc_dma_be_dai_links));
  603. total_links +=
  604. ARRAY_SIZE(msm_rx_tx_cdc_dma_be_dai_links);
  605. memcpy(msm_sdx_dai_links + total_links,
  606. msm_common_be_dai_links,
  607. sizeof(msm_common_be_dai_links));
  608. total_links +=
  609. ARRAY_SIZE(msm_common_be_dai_links);
  610. rc = of_property_read_u32(dev->of_node,
  611. "qcom,tdm-audio-intf", &val);
  612. if (!rc && val) {
  613. memcpy(msm_sdx_dai_links + total_links,
  614. msm_tdm_dai_links,
  615. sizeof(msm_tdm_dai_links));
  616. total_links += ARRAY_SIZE(msm_tdm_dai_links);
  617. }
  618. dailink = msm_sdx_dai_links;
  619. } else if(!strcmp(match->data, "stub_codec")) {
  620. card = &snd_soc_card_stub_msm;
  621. memcpy(msm_stub_dai_links,
  622. msm_stub_be_dai_links,
  623. sizeof(msm_stub_be_dai_links));
  624. dailink = msm_stub_dai_links;
  625. total_links = ARRAY_SIZE(msm_stub_be_dai_links);
  626. }
  627. if (card) {
  628. card->dai_link = dailink;
  629. card->num_links = total_links;
  630. card->late_probe = msm_snd_card_late_probe;
  631. }
  632. return card;
  633. }
  634. static int msm_int_audrx_init(struct snd_soc_pcm_runtime *rtd)
  635. {
  636. u8 spkleft_ports[WSA881X_MAX_SWR_PORTS] = {0, 1, 2, 3};
  637. u8 spkright_ports[WSA881X_MAX_SWR_PORTS] = {0, 1, 2, 3};
  638. u8 spkleft_port_types[WSA881X_MAX_SWR_PORTS] = {SPKR_L, SPKR_L_COMP,
  639. SPKR_L_BOOST, SPKR_L_VI};
  640. u8 spkright_port_types[WSA881X_MAX_SWR_PORTS] = {SPKR_R, SPKR_R_COMP,
  641. SPKR_R_BOOST, SPKR_R_VI};
  642. unsigned int ch_rate[WSA881X_MAX_SWR_PORTS] = {SWR_CLK_RATE_2P4MHZ, SWR_CLK_RATE_0P6MHZ,
  643. SWR_CLK_RATE_0P3MHZ, SWR_CLK_RATE_1P2MHZ};
  644. unsigned int ch_mask[WSA881X_MAX_SWR_PORTS] = {0x1, 0xF, 0x3, 0x3};
  645. struct snd_soc_component *component = NULL;
  646. struct snd_soc_dapm_context *dapm = NULL;
  647. struct snd_card *card = NULL;
  648. struct snd_info_entry *entry = NULL;
  649. struct msm_asoc_mach_data *pdata =
  650. snd_soc_card_get_drvdata(rtd->card);
  651. int ret = 0;
  652. if (codec_reg_done) {
  653. return 0;
  654. }
  655. if (pdata->wsa_max_devs > 0) {
  656. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.1");
  657. if (!component) {
  658. pr_err("%s: wsa-codec.1 component is NULL\n", __func__);
  659. return -EINVAL;
  660. }
  661. dapm = snd_soc_component_get_dapm(component);
  662. wsa881x_set_channel_map(component, &spkleft_ports[0],
  663. WSA881X_MAX_SWR_PORTS, &ch_mask[0],
  664. &ch_rate[0], &spkleft_port_types[0]);
  665. if (dapm->component) {
  666. snd_soc_dapm_ignore_suspend(dapm, "spkrLeft IN");
  667. snd_soc_dapm_ignore_suspend(dapm, "spkrLeft SPKR");
  668. }
  669. wsa881x_codec_info_create_codec_entry(pdata->codec_root,
  670. component);
  671. }
  672. /* If current platform has more than one WSA */
  673. if (pdata->wsa_max_devs > 1) {
  674. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.2");
  675. if (!component) {
  676. pr_err("%s: wsa-codec.2 component is NULL\n", __func__);
  677. return -EINVAL;
  678. }
  679. dapm = snd_soc_component_get_dapm(component);
  680. wsa881x_set_channel_map(component, &spkright_ports[0],
  681. WSA881X_MAX_SWR_PORTS, &ch_mask[0],
  682. &ch_rate[0], &spkright_port_types[0]);
  683. if (dapm->component) {
  684. snd_soc_dapm_ignore_suspend(dapm, "spkrRight IN");
  685. snd_soc_dapm_ignore_suspend(dapm, "spkrRight SPKR");
  686. }
  687. wsa881x_codec_info_create_codec_entry(pdata->codec_root,
  688. component);
  689. }
  690. card = rtd->card->snd_card;
  691. if (!pdata->codec_root) {
  692. entry = msm_snd_info_create_subdir(card->module, "codecs",
  693. card->proc_root);
  694. if (!entry) {
  695. pr_debug("%s: Cannot create codecs module entry\n",
  696. __func__);
  697. ret = 0;
  698. goto err;
  699. }
  700. pdata->codec_root = entry;
  701. }
  702. msm_common_dai_link_init(rtd);
  703. err:
  704. return ret;
  705. }
  706. static int msm_aux_codec_init(struct snd_soc_pcm_runtime *rtd)
  707. {
  708. struct snd_soc_component *component = NULL;
  709. struct snd_soc_dapm_context *dapm = NULL;
  710. struct snd_info_entry *entry;
  711. struct snd_card *card = NULL;
  712. struct msm_asoc_mach_data *pdata;
  713. component = snd_soc_rtdcom_lookup(rtd, WCD934X_DRV_NAME);
  714. if (!component) {
  715. pr_err("%s component is NULL\n", __func__);
  716. return -EINVAL;
  717. }
  718. dapm = snd_soc_component_get_dapm(component);
  719. card = component->card->snd_card;
  720. snd_soc_dapm_ignore_suspend(dapm, "EAR");
  721. snd_soc_dapm_ignore_suspend(dapm, "AUX");
  722. snd_soc_dapm_ignore_suspend(dapm, "HPHL");
  723. snd_soc_dapm_ignore_suspend(dapm, "HPHR");
  724. snd_soc_dapm_ignore_suspend(dapm, "AMIC1");
  725. snd_soc_dapm_ignore_suspend(dapm, "AMIC2");
  726. snd_soc_dapm_ignore_suspend(dapm, "AMIC3");
  727. snd_soc_dapm_ignore_suspend(dapm, "AMIC4");
  728. snd_soc_dapm_sync(dapm);
  729. pdata = snd_soc_card_get_drvdata(component->card);
  730. if (!pdata->codec_root) {
  731. entry = msm_snd_info_create_subdir(card->module, "codecs",
  732. card->proc_root);
  733. if (!entry) {
  734. dev_dbg(component->dev, "%s: Cannot create codecs module entry\n",
  735. __func__);
  736. return 0;
  737. }
  738. pdata->codec_root = entry;
  739. }
  740. tavil_codec_info_create_codec_entry(pdata->codec_root, component);
  741. #if 0
  742. codec_variant = wcd934x_get_codec_variant(component);
  743. dev_dbg(component->dev, "%s: variant %d\n", __func__, codec_variant);
  744. if (codec_variant == WCD9380)
  745. ret = snd_soc_add_component_controls(component,
  746. msm_int_wcd9380_snd_controls,
  747. ARRAY_SIZE(msm_int_wcd9380_snd_controls));
  748. else if (codec_variant == WCD9385)
  749. ret = snd_soc_add_component_controls(component,
  750. msm_int_wcd9385_snd_controls,
  751. ARRAY_SIZE(msm_int_wcd9385_snd_controls));
  752. if (ret < 0) {
  753. dev_err(component->dev, "%s: add codec specific snd controls failed: %d\n",
  754. __func__, ret);
  755. return ret;
  756. }
  757. #endif
  758. msm_common_dai_link_init(rtd);
  759. msm_int_audrx_init(rtd);
  760. return 0;
  761. }
  762. static int sdx_ssr_enable(struct device *dev, void *data)
  763. {
  764. struct platform_device *pdev = to_platform_device(dev);
  765. struct snd_soc_card *card = platform_get_drvdata(pdev);
  766. int ret = 0;
  767. if (!card) {
  768. dev_err(dev, "%s: card is NULL\n", __func__);
  769. ret = -EINVAL;
  770. goto err;
  771. }
  772. if (!strcmp(card->name, "sdx-stub-snd-card")) {
  773. /* TODO */
  774. dev_dbg(dev, "%s: TODO \n", __func__);
  775. }
  776. #if IS_ENABLED(CONFIG_AUDIO_QGKI)
  777. snd_soc_card_change_online_state(card, 1);
  778. #endif /* CONFIG_AUDIO_QGKI */
  779. dev_dbg(dev, "%s: setting snd_card to ONLINE\n", __func__);
  780. err:
  781. return ret;
  782. }
  783. static void sdx_ssr_disable(struct device *dev, void *data)
  784. {
  785. struct platform_device *pdev = to_platform_device(dev);
  786. struct snd_soc_card *card = platform_get_drvdata(pdev);
  787. if (!card) {
  788. dev_err(dev, "%s: card is NULL\n", __func__);
  789. return;
  790. }
  791. dev_dbg(dev, "%s: setting snd_card to OFFLINE\n", __func__);
  792. #if IS_ENABLED(CONFIG_AUDIO_QGKI)
  793. snd_soc_card_change_online_state(card, 0);
  794. #endif /* CONFIG_AUDIO_QGKI */
  795. if (!strcmp(card->name, "sdx-stub-snd-card")) {
  796. /* TODO */
  797. dev_dbg(dev, "%s: TODO \n", __func__);
  798. }
  799. }
  800. static const struct snd_event_ops sdx_ssr_ops = {
  801. .enable = sdx_ssr_enable,
  802. .disable = sdx_ssr_disable,
  803. };
  804. static int msm_audio_ssr_compare(struct device *dev, void *data)
  805. {
  806. struct device_node *node = data;
  807. dev_dbg(dev, "%s: dev->of_node = 0x%p, node = 0x%p\n",
  808. __func__, dev->of_node, node);
  809. return (dev->of_node && dev->of_node == node);
  810. }
  811. static int msm_audio_ssr_register(struct device *dev)
  812. {
  813. struct device_node *np = dev->of_node;
  814. struct snd_event_clients *ssr_clients = NULL;
  815. struct device_node *node = NULL;
  816. int ret = 0;
  817. int i = 0;
  818. for (i = 0; ; i++) {
  819. node = of_parse_phandle(np, "qcom,msm_audio_ssr_devs", i);
  820. if (!node)
  821. break;
  822. snd_event_mstr_add_client(&ssr_clients,
  823. msm_audio_ssr_compare, node);
  824. }
  825. ret = snd_event_master_register(dev, &sdx_ssr_ops,
  826. ssr_clients, NULL);
  827. if (!ret)
  828. snd_event_notify(dev, SND_EVENT_UP);
  829. return ret;
  830. }
  831. struct msm_common_pdata *msm_common_get_pdata(struct snd_soc_card *card)
  832. {
  833. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  834. if (!pdata)
  835. return NULL;
  836. return pdata->common_pdata;
  837. }
  838. void msm_common_set_pdata(struct snd_soc_card *card,
  839. struct msm_common_pdata *common_pdata)
  840. {
  841. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  842. if (!pdata)
  843. return;
  844. pdata->common_pdata = common_pdata;
  845. }
  846. static int msm_asoc_machine_probe(struct platform_device *pdev)
  847. {
  848. struct snd_soc_card *card = NULL;
  849. struct msm_asoc_mach_data *pdata = NULL;
  850. const char *mbhc_audio_jack_type = NULL;
  851. int ret = 0;
  852. struct clk *lpass_audio_hw_vote = NULL;
  853. if (!pdev->dev.of_node) {
  854. dev_err(&pdev->dev, "%s: No platform supplied from device tree\n", __func__);
  855. return -EINVAL;
  856. }
  857. pdata = devm_kzalloc(&pdev->dev,
  858. sizeof(struct msm_asoc_mach_data), GFP_KERNEL);
  859. if (!pdata)
  860. return -ENOMEM;
  861. card = populate_snd_card_dailinks(&pdev->dev);
  862. if (!card) {
  863. dev_err(&pdev->dev, "%s: Card uninitialized\n", __func__);
  864. ret = -EINVAL;
  865. goto err;
  866. }
  867. card->dev = &pdev->dev;
  868. platform_set_drvdata(pdev, card);
  869. snd_soc_card_set_drvdata(card, pdata);
  870. ret = snd_soc_of_parse_card_name(card, "qcom,model");
  871. if (ret) {
  872. dev_err(&pdev->dev, "%s: parse card name failed, err:%d\n",
  873. __func__, ret);
  874. goto err;
  875. }
  876. ret = snd_soc_of_parse_audio_routing(card, "qcom,audio-routing");
  877. if (ret) {
  878. dev_err(&pdev->dev, "%s: parse audio routing failed, err:%d\n",
  879. __func__, ret);
  880. goto err;
  881. }
  882. ret = msm_populate_dai_link_component_of_node(card);
  883. if (ret) {
  884. ret = -EPROBE_DEFER;
  885. goto err;
  886. }
  887. /* Get maximum WSA device count for this platform */
  888. ret = of_property_read_u32(pdev->dev.of_node,
  889. "qcom,wsa-max-devs", &pdata->wsa_max_devs);
  890. if (ret) {
  891. dev_info(&pdev->dev,
  892. "%s: wsa-max-devs property missing in DT %s, ret = %d\n",
  893. __func__, pdev->dev.of_node->full_name, ret);
  894. pdata->wsa_max_devs = 0;
  895. }
  896. ret = devm_snd_soc_register_card(&pdev->dev, card);
  897. if (ret == -EPROBE_DEFER) {
  898. if (codec_reg_done)
  899. ret = -EINVAL;
  900. goto err;
  901. } else if (ret) {
  902. dev_err(&pdev->dev, "%s: snd_soc_register_card failed (%d)\n",
  903. __func__, ret);
  904. goto err;
  905. }
  906. dev_info(&pdev->dev, "%s: Sound card %s registered\n",
  907. __func__, card->name);
  908. pdata->hph_en1_gpio_p = of_parse_phandle(pdev->dev.of_node,
  909. "qcom,hph-en1-gpio", 0);
  910. if (!pdata->hph_en1_gpio_p) {
  911. dev_dbg(&pdev->dev, "%s: property %s not detected in node %s\n",
  912. __func__, "qcom,hph-en1-gpio",
  913. pdev->dev.of_node->full_name);
  914. }
  915. pdata->hph_en0_gpio_p = of_parse_phandle(pdev->dev.of_node,
  916. "qcom,hph-en0-gpio", 0);
  917. if (!pdata->hph_en0_gpio_p) {
  918. dev_dbg(&pdev->dev, "%s: property %s not detected in node %s\n",
  919. __func__, "qcom,hph-en0-gpio",
  920. pdev->dev.of_node->full_name);
  921. }
  922. ret = of_property_read_string(pdev->dev.of_node,
  923. "qcom,mbhc-audio-jack-type", &mbhc_audio_jack_type);
  924. if (ret) {
  925. dev_dbg(&pdev->dev, "%s: Looking up %s property in node %s failed\n",
  926. __func__, "qcom,mbhc-audio-jack-type",
  927. pdev->dev.of_node->full_name);
  928. dev_dbg(&pdev->dev, "Jack type properties set to default\n");
  929. } else {
  930. if (!strcmp(mbhc_audio_jack_type, "4-pole-jack")) {
  931. wcd_mbhc_cfg.enable_anc_mic_detect = false;
  932. dev_dbg(&pdev->dev, "This hardware has 4 pole jack");
  933. } else if (!strcmp(mbhc_audio_jack_type, "5-pole-jack")) {
  934. wcd_mbhc_cfg.enable_anc_mic_detect = true;
  935. dev_dbg(&pdev->dev, "This hardware has 5 pole jack");
  936. } else if (!strcmp(mbhc_audio_jack_type, "6-pole-jack")) {
  937. wcd_mbhc_cfg.enable_anc_mic_detect = true;
  938. dev_dbg(&pdev->dev, "This hardware has 6 pole jack");
  939. } else {
  940. wcd_mbhc_cfg.enable_anc_mic_detect = false;
  941. dev_dbg(&pdev->dev, "Unknown value, set to default\n");
  942. }
  943. }
  944. /*
  945. * Parse US-Euro gpio info from DT. Report no error if us-euro
  946. * entry is not found in DT file as some targets do not support
  947. * US-Euro detection
  948. */
  949. pdata->us_euro_gpio_p = of_parse_phandle(pdev->dev.of_node,
  950. "qcom,us-euro-gpios", 0);
  951. if (!pdata->us_euro_gpio_p) {
  952. dev_dbg(&pdev->dev, "property %s not detected in node %s",
  953. "qcom,us-euro-gpios", pdev->dev.of_node->full_name);
  954. } else {
  955. dev_dbg(&pdev->dev, "%s detected\n",
  956. "qcom,us-euro-gpios");
  957. wcd_mbhc_cfg.swap_gnd_mic = msm_swap_gnd_mic;
  958. }
  959. if (wcd_mbhc_cfg.enable_usbc_analog)
  960. wcd_mbhc_cfg.swap_gnd_mic = msm_usbc_swap_gnd_mic;
  961. pdata->fsa_handle = of_parse_phandle(pdev->dev.of_node,
  962. "fsa4480-i2c-handle", 0);
  963. if (!pdata->fsa_handle)
  964. dev_dbg(&pdev->dev, "property %s not detected in node %s\n",
  965. "fsa4480-i2c-handle", pdev->dev.of_node->full_name);
  966. pdata->dmic01_gpio_p = of_parse_phandle(pdev->dev.of_node,
  967. "qcom,cdc-dmic01-gpios",
  968. 0);
  969. pdata->dmic23_gpio_p = of_parse_phandle(pdev->dev.of_node,
  970. "qcom,cdc-dmic23-gpios",
  971. 0);
  972. pdata->dmic45_gpio_p = of_parse_phandle(pdev->dev.of_node,
  973. "qcom,cdc-dmic45-gpios",
  974. 0);
  975. if (pdata->dmic01_gpio_p)
  976. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic01_gpio_p, false);
  977. if (pdata->dmic23_gpio_p)
  978. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic23_gpio_p, false);
  979. if (pdata->dmic45_gpio_p)
  980. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic45_gpio_p, false);
  981. msm_common_snd_init(pdev, card);
  982. #if 0
  983. pdata->mi2s_gpio_p[PRIM_MI2S] = of_parse_phandle(pdev->dev.of_node,
  984. "qcom,pri-mi2s-gpios", 0);
  985. pdata->mi2s_gpio_p[SEC_MI2S] = of_parse_phandle(pdev->dev.of_node,
  986. "qcom,sec-mi2s-gpios", 0);
  987. pdata->mi2s_gpio_p[TERT_MI2S] = of_parse_phandle(pdev->dev.of_node,
  988. "qcom,tert-mi2s-gpios", 0);
  989. pdata->mi2s_gpio_p[QUAT_MI2S] = of_parse_phandle(pdev->dev.of_node,
  990. "qcom,quat-mi2s-gpios", 0);
  991. pdata->mi2s_gpio_p[QUIN_MI2S] = of_parse_phandle(pdev->dev.of_node,
  992. "qcom,quin-mi2s-gpios", 0);
  993. pdata->mi2s_gpio_p[SEN_MI2S] = of_parse_phandle(pdev->dev.of_node,
  994. "qcom,sen-mi2s-gpios", 0);
  995. for (index = PRIM_MI2S; index < MI2S_MAX; index++)
  996. atomic_set(&(pdata->mi2s_gpio_ref_count[index]), 0);
  997. #endif
  998. /* Register LPASS audio hw vote */
  999. lpass_audio_hw_vote = devm_clk_get(&pdev->dev, "lpass_audio_hw_vote");
  1000. if (IS_ERR(lpass_audio_hw_vote)) {
  1001. ret = PTR_ERR(lpass_audio_hw_vote);
  1002. dev_dbg(&pdev->dev, "%s: clk get %s failed %d\n",
  1003. __func__, "lpass_audio_hw_vote", ret);
  1004. lpass_audio_hw_vote = NULL;
  1005. ret = 0;
  1006. }
  1007. pdata->lpass_audio_hw_vote = lpass_audio_hw_vote;
  1008. pdata->core_audio_vote_count = 0;
  1009. ret = msm_audio_ssr_register(&pdev->dev);
  1010. if (ret)
  1011. pr_err("%s: Registration with SND event FWK failed ret = %d\n",
  1012. __func__, ret);
  1013. is_initial_boot = true;
  1014. /* Add QoS request for audio tasks */
  1015. msm_audio_add_qos_request();
  1016. return 0;
  1017. err:
  1018. devm_kfree(&pdev->dev, pdata);
  1019. return ret;
  1020. }
  1021. static int msm_asoc_machine_remove(struct platform_device *pdev)
  1022. {
  1023. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1024. struct msm_asoc_mach_data *pdata = NULL;
  1025. struct msm_common_pdata *common_pdata = NULL;
  1026. if (card)
  1027. pdata = snd_soc_card_get_drvdata(card);
  1028. if (pdata)
  1029. common_pdata = pdata->common_pdata;
  1030. msm_common_snd_deinit(common_pdata);
  1031. snd_event_master_deregister(&pdev->dev);
  1032. snd_soc_unregister_card(card);
  1033. msm_audio_remove_qos_request();
  1034. return 0;
  1035. }
  1036. static struct platform_driver sdx_asoc_machine_driver = {
  1037. .driver = {
  1038. .name = DRV_NAME,
  1039. .owner = THIS_MODULE,
  1040. .pm = &snd_soc_pm_ops,
  1041. .of_match_table = sdx_asoc_machine_of_match,
  1042. .suppress_bind_attrs = true,
  1043. },
  1044. .probe = msm_asoc_machine_probe,
  1045. .remove = msm_asoc_machine_remove,
  1046. };
  1047. module_platform_driver(sdx_asoc_machine_driver);
  1048. MODULE_SOFTDEP("pre: bt_fm_slim");
  1049. MODULE_DESCRIPTION("ALSA SoC msm");
  1050. MODULE_LICENSE("GPL v2");
  1051. MODULE_ALIAS("platform:" DRV_NAME);
  1052. MODULE_DEVICE_TABLE(of, sdx_asoc_machine_of_match);