sdx-target.c 32 KB

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