waipio.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2016-2021, 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 <linux/pm_qos.h>
  17. #include <sound/control.h>
  18. #include <sound/core.h>
  19. #include <sound/soc.h>
  20. #include <sound/soc-dapm.h>
  21. #include <sound/pcm.h>
  22. #include <sound/pcm_params.h>
  23. #include <sound/info.h>
  24. #include <soc/snd_event.h>
  25. #include <dsp/audio_prm.h>
  26. #include <soc/swr-common.h>
  27. #include <soc/soundwire.h>
  28. #include "device_event.h"
  29. #include "asoc/msm-cdc-pinctrl.h"
  30. #include "asoc/wcd-mbhc-v2.h"
  31. #include "codecs/wcd938x/wcd938x-mbhc.h"
  32. #include "codecs/wsa883x/wsa883x.h"
  33. #include "codecs/wcd938x/wcd938x.h"
  34. #include "codecs/lpass-cdc/lpass-cdc.h"
  35. #include <bindings/audio-codec-port-types.h>
  36. #include "codecs/lpass-cdc/lpass-cdc-wsa-macro.h"
  37. #include "waipio-port-config.h"
  38. #include "msm-audio-defs.h"
  39. #include "msm_common.h"
  40. #include "msm_dailink.h"
  41. #define DRV_NAME "waipio-asoc-snd"
  42. #define __CHIPSET__ "WAIPIO "
  43. #define MSM_DAILINK_NAME(name) (__CHIPSET__#name)
  44. #define WCD9XXX_MBHC_DEF_RLOADS 5
  45. #define WCD9XXX_MBHC_DEF_BUTTONS 8
  46. #define CODEC_EXT_CLK_RATE 9600000
  47. #define DEV_NAME_STR_LEN 32
  48. #define WCD_MBHC_HS_V_MAX 1600
  49. #define MSM_LL_QOS_VALUE 300 /* time in us to ensure LPM doesn't go in C3/C4 */
  50. #define WCN_CDC_SLIM_RX_CH_MAX 2
  51. #define WCN_CDC_SLIM_TX_CH_MAX 2
  52. #define WCN_CDC_SLIM_TX_CH_MAX_LITO 3
  53. struct msm_asoc_mach_data {
  54. struct snd_info_entry *codec_root;
  55. struct msm_common_pdata *common_pdata;
  56. int usbc_en2_gpio; /* used by gpio driver API */
  57. struct device_node *dmic01_gpio_p; /* used by pinctrl API */
  58. struct device_node *dmic23_gpio_p; /* used by pinctrl API */
  59. struct device_node *dmic45_gpio_p; /* used by pinctrl API */
  60. struct pinctrl *usbc_en2_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. int wcd_disabled;
  67. };
  68. static bool is_initial_boot;
  69. static bool codec_reg_done;
  70. static struct snd_soc_card snd_soc_card_waipio_msm;
  71. static int dmic_0_1_gpio_cnt;
  72. static int dmic_2_3_gpio_cnt;
  73. static int dmic_4_5_gpio_cnt;
  74. static void *def_wcd_mbhc_cal(void);
  75. static int msm_rx_tx_codec_init(struct snd_soc_pcm_runtime*);
  76. static int msm_int_wsa_init(struct snd_soc_pcm_runtime*);
  77. /*
  78. * Need to report LINEIN
  79. * if R/L channel impedance is larger than 5K ohm
  80. */
  81. static struct wcd_mbhc_config wcd_mbhc_cfg = {
  82. .read_fw_bin = false,
  83. .calibration = NULL,
  84. .detect_extn_cable = true,
  85. .mono_stero_detection = false,
  86. .swap_gnd_mic = NULL,
  87. .hs_ext_micbias = true,
  88. .key_code[0] = KEY_MEDIA,
  89. .key_code[1] = KEY_VOICECOMMAND,
  90. .key_code[2] = KEY_VOLUMEUP,
  91. .key_code[3] = KEY_VOLUMEDOWN,
  92. .key_code[4] = 0,
  93. .key_code[5] = 0,
  94. .key_code[6] = 0,
  95. .key_code[7] = 0,
  96. .linein_th = 5000,
  97. .moisture_en = false,
  98. .mbhc_micbias = MIC_BIAS_2,
  99. .anc_micbias = MIC_BIAS_2,
  100. .enable_anc_mic_detect = false,
  101. .moisture_duty_cycle_en = true,
  102. };
  103. #ifdef PM_QOS_ENABLE
  104. /* set audio task affinity to core 1 & 2 */
  105. static const unsigned int audio_core_list[] = {1, 2};
  106. static cpumask_t audio_cpu_map = CPU_MASK_NONE;
  107. static struct dev_pm_qos_request *msm_audio_req = NULL;
  108. static void msm_audio_add_qos_request()
  109. {
  110. int i;
  111. int cpu = 0;
  112. msm_audio_req = kzalloc(sizeof(struct dev_pm_qos_request) * NR_CPUS,
  113. GFP_KERNEL);
  114. if (!msm_audio_req) {
  115. pr_err("%s failed to alloc mem for qos req.\n", __func__);
  116. return;
  117. }
  118. for (i = 0; i < ARRAY_SIZE(audio_core_list); i++) {
  119. if (audio_core_list[i] >= NR_CPUS)
  120. pr_err("%s incorrect cpu id: %d specified.\n", __func__, audio_core_list[i]);
  121. else
  122. cpumask_set_cpu(audio_core_list[i], &audio_cpu_map);
  123. }
  124. for_each_cpu(cpu, &audio_cpu_map) {
  125. dev_pm_qos_add_request(get_cpu_device(cpu),
  126. &msm_audio_req[cpu],
  127. DEV_PM_QOS_RESUME_LATENCY,
  128. PM_QOS_CPU_LATENCY_DEFAULT_VALUE);
  129. pr_debug("%s set cpu affinity to core %d.\n", __func__, cpu);
  130. }
  131. }
  132. static void msm_audio_remove_qos_request()
  133. {
  134. int cpu = 0;
  135. if (msm_audio_req) {
  136. for_each_cpu(cpu, &audio_cpu_map) {
  137. dev_pm_qos_remove_request(
  138. &msm_audio_req[cpu]);
  139. pr_debug("%s remove cpu affinity of core %d.\n", __func__, cpu);
  140. }
  141. kfree(msm_audio_req);
  142. }
  143. }
  144. #endif
  145. static bool msm_usbc_swap_gnd_mic(struct snd_soc_component *component, bool active)
  146. {
  147. struct snd_soc_card *card = component->card;
  148. struct msm_asoc_mach_data *pdata =
  149. snd_soc_card_get_drvdata(card);
  150. if (!pdata->fsa_handle)
  151. return false;
  152. return fsa4480_switch_event(pdata->fsa_handle, FSA_MIC_GND_SWAP);
  153. }
  154. static struct snd_soc_ops msm_common_be_ops = {
  155. .startup = msm_common_snd_startup,
  156. .shutdown = msm_common_snd_shutdown,
  157. };
  158. static int msm_dmic_event(struct snd_soc_dapm_widget *w,
  159. struct snd_kcontrol *kcontrol, int event)
  160. {
  161. struct msm_asoc_mach_data *pdata = NULL;
  162. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  163. int ret = 0;
  164. u32 dmic_idx;
  165. int *dmic_gpio_cnt;
  166. struct device_node *dmic_gpio;
  167. char *wname;
  168. wname = strpbrk(w->name, "012345");
  169. if (!wname) {
  170. dev_err(component->dev, "%s: widget not found\n", __func__);
  171. return -EINVAL;
  172. }
  173. ret = kstrtouint(wname, 10, &dmic_idx);
  174. if (ret < 0) {
  175. dev_err(component->dev, "%s: Invalid DMIC line on the codec\n",
  176. __func__);
  177. return -EINVAL;
  178. }
  179. pdata = snd_soc_card_get_drvdata(component->card);
  180. switch (dmic_idx) {
  181. case 0:
  182. case 1:
  183. dmic_gpio_cnt = &dmic_0_1_gpio_cnt;
  184. dmic_gpio = pdata->dmic01_gpio_p;
  185. break;
  186. case 2:
  187. case 3:
  188. dmic_gpio_cnt = &dmic_2_3_gpio_cnt;
  189. dmic_gpio = pdata->dmic23_gpio_p;
  190. break;
  191. case 4:
  192. case 5:
  193. dmic_gpio_cnt = &dmic_4_5_gpio_cnt;
  194. dmic_gpio = pdata->dmic45_gpio_p;
  195. break;
  196. default:
  197. dev_err(component->dev, "%s: Invalid DMIC Selection\n",
  198. __func__);
  199. return -EINVAL;
  200. }
  201. dev_dbg(component->dev, "%s: event %d DMIC%d dmic_gpio_cnt %d\n",
  202. __func__, event, dmic_idx, *dmic_gpio_cnt);
  203. switch (event) {
  204. case SND_SOC_DAPM_PRE_PMU:
  205. (*dmic_gpio_cnt)++;
  206. if (*dmic_gpio_cnt == 1) {
  207. ret = msm_cdc_pinctrl_select_active_state(
  208. dmic_gpio);
  209. if (ret < 0) {
  210. pr_err("%s: gpio set cannot be activated %sd",
  211. __func__, "dmic_gpio");
  212. return ret;
  213. }
  214. }
  215. break;
  216. case SND_SOC_DAPM_POST_PMD:
  217. (*dmic_gpio_cnt)--;
  218. if (*dmic_gpio_cnt == 0) {
  219. ret = msm_cdc_pinctrl_select_sleep_state(
  220. dmic_gpio);
  221. if (ret < 0) {
  222. pr_err("%s: gpio set cannot be de-activated %sd",
  223. __func__, "dmic_gpio");
  224. return ret;
  225. }
  226. }
  227. break;
  228. default:
  229. pr_err("%s: invalid DAPM event %d\n", __func__, event);
  230. return -EINVAL;
  231. }
  232. return 0;
  233. }
  234. static const struct snd_soc_dapm_widget msm_int_dapm_widgets[] = {
  235. SND_SOC_DAPM_MIC("Analog Mic1", NULL),
  236. SND_SOC_DAPM_MIC("Analog Mic2", NULL),
  237. SND_SOC_DAPM_MIC("Analog Mic3", NULL),
  238. SND_SOC_DAPM_MIC("Analog Mic4", NULL),
  239. SND_SOC_DAPM_MIC("Analog Mic5", NULL),
  240. SND_SOC_DAPM_MIC("Digital Mic0", msm_dmic_event),
  241. SND_SOC_DAPM_MIC("Digital Mic1", msm_dmic_event),
  242. SND_SOC_DAPM_MIC("Digital Mic2", msm_dmic_event),
  243. SND_SOC_DAPM_MIC("Digital Mic3", msm_dmic_event),
  244. SND_SOC_DAPM_MIC("Digital Mic4", msm_dmic_event),
  245. SND_SOC_DAPM_MIC("Digital Mic5", msm_dmic_event),
  246. SND_SOC_DAPM_MIC("Digital Mic6", NULL),
  247. SND_SOC_DAPM_MIC("Digital Mic7", NULL),
  248. };
  249. static int msm_wcn_init(struct snd_soc_pcm_runtime *rtd)
  250. {
  251. unsigned int rx_ch[WCN_CDC_SLIM_RX_CH_MAX] = {157, 158};
  252. unsigned int tx_ch[WCN_CDC_SLIM_TX_CH_MAX] = {159, 160};
  253. struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
  254. int ret = 0;
  255. ret = snd_soc_dai_set_channel_map(codec_dai, ARRAY_SIZE(tx_ch),
  256. tx_ch, ARRAY_SIZE(rx_ch), rx_ch);
  257. if (ret)
  258. return ret;
  259. msm_common_dai_link_init(rtd);
  260. return ret;
  261. }
  262. static struct snd_info_entry *msm_snd_info_create_subdir(struct module *mod,
  263. const char *name,
  264. struct snd_info_entry *parent)
  265. {
  266. struct snd_info_entry *entry;
  267. entry = snd_info_create_module_entry(mod, name, parent);
  268. if (!entry)
  269. return NULL;
  270. entry->mode = S_IFDIR | 0555;
  271. if (snd_info_register(entry) < 0) {
  272. snd_info_free_entry(entry);
  273. return NULL;
  274. }
  275. return entry;
  276. }
  277. static void *def_wcd_mbhc_cal(void)
  278. {
  279. void *wcd_mbhc_cal;
  280. struct wcd_mbhc_btn_detect_cfg *btn_cfg;
  281. u16 *btn_high;
  282. wcd_mbhc_cal = kzalloc(WCD_MBHC_CAL_SIZE(WCD_MBHC_DEF_BUTTONS,
  283. WCD9XXX_MBHC_DEF_RLOADS), GFP_KERNEL);
  284. if (!wcd_mbhc_cal)
  285. return NULL;
  286. WCD_MBHC_CAL_PLUG_TYPE_PTR(wcd_mbhc_cal)->v_hs_max = WCD_MBHC_HS_V_MAX;
  287. WCD_MBHC_CAL_BTN_DET_PTR(wcd_mbhc_cal)->num_btn = WCD_MBHC_DEF_BUTTONS;
  288. btn_cfg = WCD_MBHC_CAL_BTN_DET_PTR(wcd_mbhc_cal);
  289. btn_high = ((void *)&btn_cfg->_v_btn_low) +
  290. (sizeof(btn_cfg->_v_btn_low[0]) * btn_cfg->num_btn);
  291. btn_high[0] = 75;
  292. btn_high[1] = 150;
  293. btn_high[2] = 237;
  294. btn_high[3] = 500;
  295. btn_high[4] = 500;
  296. btn_high[5] = 500;
  297. btn_high[6] = 500;
  298. btn_high[7] = 500;
  299. return wcd_mbhc_cal;
  300. }
  301. /* Digital audio interface glue - connects codec <---> CPU */
  302. static struct snd_soc_dai_link msm_common_be_dai_links[] = {
  303. /* Proxy Tx BACK END DAI Link */
  304. {
  305. .name = LPASS_BE_RT_PROXY_PCM_TX,
  306. .stream_name = LPASS_BE_RT_PROXY_PCM_TX,
  307. .capture_only = 1,
  308. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  309. SND_SOC_DPCM_TRIGGER_POST},
  310. .ignore_suspend = 1,
  311. .ops = &msm_common_be_ops,
  312. SND_SOC_DAILINK_REG(proxy_tx),
  313. },
  314. /* Proxy Rx BACK END DAI Link */
  315. {
  316. .name = LPASS_BE_RT_PROXY_PCM_RX,
  317. .stream_name = LPASS_BE_RT_PROXY_PCM_RX,
  318. .playback_only = 1,
  319. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  320. SND_SOC_DPCM_TRIGGER_POST},
  321. .ignore_pmdown_time = 1,
  322. .ignore_suspend = 1,
  323. .ops = &msm_common_be_ops,
  324. SND_SOC_DAILINK_REG(proxy_rx),
  325. },
  326. {
  327. .name = LPASS_BE_USB_AUDIO_RX,
  328. .stream_name = LPASS_BE_USB_AUDIO_RX,
  329. .playback_only = 1,
  330. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  331. SND_SOC_DPCM_TRIGGER_POST},
  332. .ignore_pmdown_time = 1,
  333. .ignore_suspend = 1,
  334. .ops = &msm_common_be_ops,
  335. SND_SOC_DAILINK_REG(usb_audio_rx),
  336. },
  337. {
  338. .name = LPASS_BE_USB_AUDIO_TX,
  339. .stream_name = LPASS_BE_USB_AUDIO_TX,
  340. .capture_only = 1,
  341. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  342. SND_SOC_DPCM_TRIGGER_POST},
  343. .ignore_suspend = 1,
  344. .ops = &msm_common_be_ops,
  345. SND_SOC_DAILINK_REG(usb_audio_tx),
  346. },
  347. {
  348. .name = LPASS_BE_WSA_CDC_DMA_TX_0,
  349. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_0,
  350. .capture_only = 1,
  351. .ignore_suspend = 1,
  352. .ops = &msm_common_be_ops,
  353. /* .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, */
  354. SND_SOC_DAILINK_REG(vi_feedback),
  355. },
  356. #if 0
  357. {
  358. .name = LPASS_BE_WSA2_CDC_DMA_TX_0,
  359. .stream_name = LPASS_BE_WSA2_CDC_DMA_TX_0,
  360. .capture_only = 1,
  361. .ignore_suspend = 1,
  362. .ops = &msm_common_be_ops,
  363. /* .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, */
  364. SND_SOC_DAILINK_REG(wsa2_vi_feedback),
  365. },
  366. #endif
  367. };
  368. static struct snd_soc_dai_link msm_wcn_be_dai_links[] = {
  369. {
  370. .name = LPASS_BE_SLIMBUS_7_RX,
  371. .stream_name = LPASS_BE_SLIMBUS_7_RX,
  372. .playback_only = 1,
  373. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  374. SND_SOC_DPCM_TRIGGER_POST},
  375. .init = &msm_wcn_init,
  376. .ops = &msm_common_be_ops,
  377. /* dai link has playback support */
  378. .ignore_pmdown_time = 1,
  379. .ignore_suspend = 1,
  380. SND_SOC_DAILINK_REG(slimbus_7_rx),
  381. },
  382. {
  383. .name = LPASS_BE_SLIMBUS_7_TX,
  384. .stream_name = LPASS_BE_SLIMBUS_7_TX,
  385. .capture_only = 1,
  386. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  387. SND_SOC_DPCM_TRIGGER_POST},
  388. .ops = &msm_common_be_ops,
  389. .ignore_suspend = 1,
  390. SND_SOC_DAILINK_REG(slimbus_7_tx),
  391. },
  392. };
  393. #if IS_ENABLED(CONFIG_AUDIO_QGKI)
  394. static struct snd_soc_dai_link ext_disp_be_dai_link[] = {
  395. /* DISP PORT BACK END DAI Link */
  396. {
  397. .name = LPASS_BE_DISPLAY_PORT_RX,
  398. .stream_name = LPASS_BE_DISPLAY_PORT_RX,
  399. .playback_only = 1,
  400. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  401. SND_SOC_DPCM_TRIGGER_POST},
  402. .ignore_pmdown_time = 1,
  403. .ignore_suspend = 1,
  404. SND_SOC_DAILINK_REG(display_port),
  405. },
  406. };
  407. #endif
  408. static struct snd_soc_dai_link msm_wsa_cdc_dma_be_dai_links[] = {
  409. /* WSA CDC DMA Backend DAI Links */
  410. {
  411. .name = LPASS_BE_WSA_CDC_DMA_RX_0,
  412. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_0,
  413. .playback_only = 1,
  414. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  415. SND_SOC_DPCM_TRIGGER_POST},
  416. .ignore_pmdown_time = 1,
  417. .ignore_suspend = 1,
  418. .ops = &msm_common_be_ops,
  419. SND_SOC_DAILINK_REG(wsa_dma_rx0),
  420. .init = &msm_int_wsa_init,
  421. },
  422. {
  423. .name = LPASS_BE_WSA_CDC_DMA_RX_1,
  424. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_1,
  425. .playback_only = 1,
  426. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  427. SND_SOC_DPCM_TRIGGER_POST},
  428. .ignore_pmdown_time = 1,
  429. .ignore_suspend = 1,
  430. .ops = &msm_common_be_ops,
  431. SND_SOC_DAILINK_REG(wsa_dma_rx1),
  432. },
  433. {
  434. .name = LPASS_BE_WSA_CDC_DMA_TX_1,
  435. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_1,
  436. .capture_only = 1,
  437. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  438. SND_SOC_DPCM_TRIGGER_POST},
  439. .ignore_suspend = 1,
  440. .ops = &msm_common_be_ops,
  441. SND_SOC_DAILINK_REG(wsa_dma_tx1),
  442. },
  443. };
  444. #if 0
  445. static struct snd_soc_dai_link msm_wsa2_cdc_dma_be_dai_links[] = {
  446. /* WSA2 CDC DMA Backend DAI Links */
  447. {
  448. .name = LPASS_BE_WSA2_CDC_DMA_RX_0,
  449. .stream_name = LPASS_BE_WSA2_CDC_DMA_RX_0,
  450. .playback_only = 1,
  451. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  452. SND_SOC_DPCM_TRIGGER_POST},
  453. .ignore_pmdown_time = 1,
  454. .ignore_suspend = 1,
  455. .ops = &msm_common_be_ops,
  456. SND_SOC_DAILINK_REG(wsa2_dma_rx0),
  457. },
  458. {
  459. .name = LPASS_BE_WSA2_CDC_DMA_RX_1,
  460. .stream_name = LPASS_BE_WSA2_CDC_DMA_RX_1,
  461. .playback_only = 1,
  462. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  463. SND_SOC_DPCM_TRIGGER_POST},
  464. .ignore_pmdown_time = 1,
  465. .ignore_suspend = 1,
  466. .ops = &msm_common_be_ops,
  467. SND_SOC_DAILINK_REG(wsa2_dma_rx1),
  468. },
  469. {
  470. .name = LPASS_BE_WSA2_CDC_DMA_TX_1,
  471. .stream_name = LPASS_BE_WSA2_CDC_DMA_TX_1,
  472. .capture_only = 1,
  473. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  474. SND_SOC_DPCM_TRIGGER_POST},
  475. .ignore_suspend = 1,
  476. .ops = &msm_common_be_ops,
  477. SND_SOC_DAILINK_REG(wsa2_dma_tx1),
  478. },
  479. };
  480. #endif
  481. static struct snd_soc_dai_link msm_rx_tx_cdc_dma_be_dai_links[] = {
  482. /* RX CDC DMA Backend DAI Links */
  483. {
  484. .name = LPASS_BE_RX_CDC_DMA_RX_0,
  485. .stream_name = LPASS_BE_RX_CDC_DMA_RX_0,
  486. .playback_only = 1,
  487. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  488. SND_SOC_DPCM_TRIGGER_POST},
  489. .ignore_pmdown_time = 1,
  490. .ignore_suspend = 1,
  491. .ops = &msm_common_be_ops,
  492. SND_SOC_DAILINK_REG(rx_dma_rx0),
  493. .init = &msm_rx_tx_codec_init,
  494. },
  495. {
  496. .name = LPASS_BE_RX_CDC_DMA_RX_1,
  497. .stream_name = LPASS_BE_RX_CDC_DMA_RX_1,
  498. .playback_only = 1,
  499. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  500. SND_SOC_DPCM_TRIGGER_POST},
  501. .ignore_pmdown_time = 1,
  502. .ignore_suspend = 1,
  503. .ops = &msm_common_be_ops,
  504. SND_SOC_DAILINK_REG(rx_dma_rx1),
  505. },
  506. {
  507. .name = LPASS_BE_RX_CDC_DMA_RX_2,
  508. .stream_name = LPASS_BE_RX_CDC_DMA_RX_2,
  509. .playback_only = 1,
  510. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  511. SND_SOC_DPCM_TRIGGER_POST},
  512. .ignore_pmdown_time = 1,
  513. .ignore_suspend = 1,
  514. .ops = &msm_common_be_ops,
  515. SND_SOC_DAILINK_REG(rx_dma_rx2),
  516. },
  517. {
  518. .name = LPASS_BE_RX_CDC_DMA_RX_3,
  519. .stream_name = LPASS_BE_RX_CDC_DMA_RX_3,
  520. .playback_only = 1,
  521. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  522. SND_SOC_DPCM_TRIGGER_POST},
  523. .ignore_pmdown_time = 1,
  524. .ignore_suspend = 1,
  525. .ops = &msm_common_be_ops,
  526. SND_SOC_DAILINK_REG(rx_dma_rx3),
  527. },
  528. {
  529. .name = LPASS_BE_RX_CDC_DMA_RX_5,
  530. .stream_name = LPASS_BE_RX_CDC_DMA_RX_5,
  531. .playback_only = 1,
  532. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  533. SND_SOC_DPCM_TRIGGER_POST},
  534. .ignore_pmdown_time = 1,
  535. .ignore_suspend = 1,
  536. .ops = &msm_common_be_ops,
  537. SND_SOC_DAILINK_REG(rx_dma_rx5),
  538. },
  539. {
  540. .name = LPASS_BE_RX_CDC_DMA_RX_6,
  541. .stream_name = LPASS_BE_RX_CDC_DMA_RX_6,
  542. .playback_only = 1,
  543. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  544. SND_SOC_DPCM_TRIGGER_POST},
  545. .ignore_pmdown_time = 1,
  546. .ignore_suspend = 1,
  547. .ops = &msm_common_be_ops,
  548. SND_SOC_DAILINK_REG(rx_dma_rx6),
  549. },
  550. /* TX CDC DMA Backend DAI Links */
  551. {
  552. .name = LPASS_BE_TX_CDC_DMA_TX_3,
  553. .stream_name = LPASS_BE_TX_CDC_DMA_TX_3,
  554. .capture_only = 1,
  555. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  556. SND_SOC_DPCM_TRIGGER_POST},
  557. .ignore_suspend = 1,
  558. .ops = &msm_common_be_ops,
  559. SND_SOC_DAILINK_REG(tx_dma_tx3),
  560. },
  561. {
  562. .name = LPASS_BE_TX_CDC_DMA_TX_4,
  563. .stream_name = LPASS_BE_TX_CDC_DMA_TX_4,
  564. .capture_only = 1,
  565. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  566. SND_SOC_DPCM_TRIGGER_POST},
  567. .ignore_suspend = 1,
  568. .ops = &msm_common_be_ops,
  569. SND_SOC_DAILINK_REG(tx_dma_tx4),
  570. },
  571. };
  572. static struct snd_soc_dai_link msm_va_cdc_dma_be_dai_links[] = {
  573. {
  574. .name = LPASS_BE_VA_CDC_DMA_TX_0,
  575. .stream_name = LPASS_BE_VA_CDC_DMA_TX_0,
  576. .capture_only = 1,
  577. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  578. SND_SOC_DPCM_TRIGGER_POST},
  579. .ignore_suspend = 1,
  580. .ops = &msm_common_be_ops,
  581. SND_SOC_DAILINK_REG(va_dma_tx0),
  582. },
  583. {
  584. .name = LPASS_BE_VA_CDC_DMA_TX_1,
  585. .stream_name = LPASS_BE_VA_CDC_DMA_TX_1,
  586. .capture_only = 1,
  587. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  588. SND_SOC_DPCM_TRIGGER_POST},
  589. .ignore_suspend = 1,
  590. .ops = &msm_common_be_ops,
  591. SND_SOC_DAILINK_REG(va_dma_tx1),
  592. },
  593. {
  594. .name = LPASS_BE_VA_CDC_DMA_TX_2,
  595. .stream_name = LPASS_BE_VA_CDC_DMA_TX_2,
  596. .capture_only = 1,
  597. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  598. SND_SOC_DPCM_TRIGGER_POST},
  599. .ignore_suspend = 1,
  600. .ops = &msm_common_be_ops,
  601. SND_SOC_DAILINK_REG(va_dma_tx2),
  602. },
  603. };
  604. /*
  605. * I2S interface pinctrl mapping
  606. * ------------------------------------
  607. * Primary - pri_mi2s
  608. * Secondary - lpi_i2s3
  609. * Tertiary - tert_mi2s
  610. * Quaternary - quat_mi2s (lpi_i2s0)
  611. * Quinary - lpi_i2s1
  612. * Senary - lpi_i2s2
  613. * ------------------------------------
  614. */
  615. static struct snd_soc_dai_link msm_mi2s_dai_links[] = {
  616. {
  617. .name = LPASS_BE_PRI_MI2S_RX,
  618. .stream_name = LPASS_BE_PRI_MI2S_RX,
  619. .playback_only = 1,
  620. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  621. SND_SOC_DPCM_TRIGGER_POST},
  622. .ops = &msm_common_be_ops,
  623. .ignore_suspend = 1,
  624. .ignore_pmdown_time = 1,
  625. SND_SOC_DAILINK_REG(pri_mi2s_rx),
  626. },
  627. {
  628. .name = LPASS_BE_PRI_MI2S_TX,
  629. .stream_name = LPASS_BE_PRI_MI2S_TX,
  630. .capture_only = 1,
  631. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  632. SND_SOC_DPCM_TRIGGER_POST},
  633. .ops = &msm_common_be_ops,
  634. .ignore_suspend = 1,
  635. SND_SOC_DAILINK_REG(pri_mi2s_tx),
  636. },
  637. {
  638. .name = LPASS_BE_SEC_MI2S_RX,
  639. .stream_name = LPASS_BE_SEC_MI2S_RX,
  640. .playback_only = 1,
  641. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  642. SND_SOC_DPCM_TRIGGER_POST},
  643. .ops = &msm_common_be_ops,
  644. .ignore_suspend = 1,
  645. .ignore_pmdown_time = 1,
  646. SND_SOC_DAILINK_REG(sec_mi2s_rx),
  647. },
  648. {
  649. .name = LPASS_BE_SEC_MI2S_TX,
  650. .stream_name = LPASS_BE_SEC_MI2S_TX,
  651. .capture_only = 1,
  652. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  653. SND_SOC_DPCM_TRIGGER_POST},
  654. .ops = &msm_common_be_ops,
  655. .ignore_suspend = 1,
  656. SND_SOC_DAILINK_REG(sec_mi2s_tx),
  657. },
  658. {
  659. .name = LPASS_BE_TERT_MI2S_RX,
  660. .stream_name = LPASS_BE_TERT_MI2S_RX,
  661. .playback_only = 1,
  662. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  663. SND_SOC_DPCM_TRIGGER_POST},
  664. .ops = &msm_common_be_ops,
  665. .ignore_suspend = 1,
  666. .ignore_pmdown_time = 1,
  667. SND_SOC_DAILINK_REG(tert_mi2s_rx),
  668. },
  669. {
  670. .name = LPASS_BE_TERT_MI2S_TX,
  671. .stream_name = LPASS_BE_TERT_MI2S_TX,
  672. .capture_only = 1,
  673. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  674. SND_SOC_DPCM_TRIGGER_POST},
  675. .ops = &msm_common_be_ops,
  676. .ignore_suspend = 1,
  677. SND_SOC_DAILINK_REG(tert_mi2s_tx),
  678. },
  679. {
  680. .name = LPASS_BE_QUAT_MI2S_RX,
  681. .stream_name = LPASS_BE_QUAT_MI2S_RX,
  682. .playback_only = 1,
  683. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  684. SND_SOC_DPCM_TRIGGER_POST},
  685. .ops = &msm_common_be_ops,
  686. .ignore_suspend = 1,
  687. .ignore_pmdown_time = 1,
  688. SND_SOC_DAILINK_REG(quat_mi2s_rx),
  689. },
  690. {
  691. .name = LPASS_BE_QUAT_MI2S_TX,
  692. .stream_name = LPASS_BE_QUAT_MI2S_TX,
  693. .capture_only = 1,
  694. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  695. SND_SOC_DPCM_TRIGGER_POST},
  696. .ops = &msm_common_be_ops,
  697. .ignore_suspend = 1,
  698. SND_SOC_DAILINK_REG(quat_mi2s_tx),
  699. },
  700. {
  701. .name = LPASS_BE_QUIN_MI2S_RX,
  702. .stream_name = LPASS_BE_QUIN_MI2S_RX,
  703. .playback_only = 1,
  704. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  705. SND_SOC_DPCM_TRIGGER_POST},
  706. .ops = &msm_common_be_ops,
  707. .ignore_suspend = 1,
  708. .ignore_pmdown_time = 1,
  709. SND_SOC_DAILINK_REG(quin_mi2s_rx),
  710. },
  711. {
  712. .name = LPASS_BE_QUIN_MI2S_TX,
  713. .stream_name = LPASS_BE_QUIN_MI2S_TX,
  714. .capture_only = 1,
  715. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  716. SND_SOC_DPCM_TRIGGER_POST},
  717. .ops = &msm_common_be_ops,
  718. .ignore_suspend = 1,
  719. SND_SOC_DAILINK_REG(quin_mi2s_tx),
  720. },
  721. {
  722. .name = LPASS_BE_SEN_MI2S_RX,
  723. .stream_name = LPASS_BE_SEN_MI2S_RX,
  724. .playback_only = 1,
  725. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  726. SND_SOC_DPCM_TRIGGER_POST},
  727. .ops = &msm_common_be_ops,
  728. .ignore_suspend = 1,
  729. .ignore_pmdown_time = 1,
  730. SND_SOC_DAILINK_REG(sen_mi2s_rx),
  731. },
  732. {
  733. .name = LPASS_BE_SEN_MI2S_TX,
  734. .stream_name = LPASS_BE_SEN_MI2S_TX,
  735. .capture_only = 1,
  736. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  737. SND_SOC_DPCM_TRIGGER_POST},
  738. .ops = &msm_common_be_ops,
  739. .ignore_suspend = 1,
  740. SND_SOC_DAILINK_REG(sen_mi2s_tx),
  741. },
  742. };
  743. static struct snd_soc_dai_link msm_tdm_dai_links[] = {
  744. {
  745. .name = LPASS_BE_PRI_TDM_RX_0,
  746. .stream_name = LPASS_BE_PRI_TDM_RX_0,
  747. .playback_only = 1,
  748. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  749. SND_SOC_DPCM_TRIGGER_POST},
  750. .ops = &msm_common_be_ops,
  751. .ignore_suspend = 1,
  752. .ignore_pmdown_time = 1,
  753. SND_SOC_DAILINK_REG(pri_tdm_rx_0),
  754. },
  755. {
  756. .name = LPASS_BE_PRI_TDM_TX_0,
  757. .stream_name = LPASS_BE_PRI_TDM_TX_0,
  758. .capture_only = 1,
  759. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  760. SND_SOC_DPCM_TRIGGER_POST},
  761. .ops = &msm_common_be_ops,
  762. .ignore_suspend = 1,
  763. SND_SOC_DAILINK_REG(pri_tdm_tx_0),
  764. },
  765. {
  766. .name = LPASS_BE_SEC_TDM_RX_0,
  767. .stream_name = LPASS_BE_SEC_TDM_RX_0,
  768. .playback_only = 1,
  769. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  770. SND_SOC_DPCM_TRIGGER_POST},
  771. .ops = &msm_common_be_ops,
  772. .ignore_suspend = 1,
  773. .ignore_pmdown_time = 1,
  774. SND_SOC_DAILINK_REG(sec_tdm_rx_0),
  775. },
  776. {
  777. .name = LPASS_BE_SEC_TDM_TX_0,
  778. .stream_name = LPASS_BE_SEC_TDM_TX_0,
  779. .capture_only = 1,
  780. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  781. SND_SOC_DPCM_TRIGGER_POST},
  782. .ops = &msm_common_be_ops,
  783. .ignore_suspend = 1,
  784. SND_SOC_DAILINK_REG(sec_tdm_tx_0),
  785. },
  786. {
  787. .name = LPASS_BE_TERT_TDM_RX_0,
  788. .stream_name = LPASS_BE_TERT_TDM_RX_0,
  789. .playback_only = 1,
  790. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  791. SND_SOC_DPCM_TRIGGER_POST},
  792. .ops = &msm_common_be_ops,
  793. .ignore_suspend = 1,
  794. .ignore_pmdown_time = 1,
  795. SND_SOC_DAILINK_REG(tert_tdm_rx_0),
  796. },
  797. {
  798. .name = LPASS_BE_TERT_TDM_TX_0,
  799. .stream_name = LPASS_BE_TERT_TDM_TX_0,
  800. .capture_only = 1,
  801. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  802. SND_SOC_DPCM_TRIGGER_POST},
  803. .ops = &msm_common_be_ops,
  804. .ignore_suspend = 1,
  805. SND_SOC_DAILINK_REG(tert_tdm_tx_0),
  806. },
  807. {
  808. .name = LPASS_BE_QUAT_TDM_RX_0,
  809. .stream_name = LPASS_BE_QUAT_TDM_RX_0,
  810. .playback_only = 1,
  811. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  812. SND_SOC_DPCM_TRIGGER_POST},
  813. .ops = &msm_common_be_ops,
  814. .ignore_suspend = 1,
  815. .ignore_pmdown_time = 1,
  816. SND_SOC_DAILINK_REG(quat_tdm_rx_0),
  817. },
  818. {
  819. .name = LPASS_BE_QUAT_TDM_TX_0,
  820. .stream_name = LPASS_BE_QUAT_TDM_TX_0,
  821. .capture_only = 1,
  822. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  823. SND_SOC_DPCM_TRIGGER_POST},
  824. .ops = &msm_common_be_ops,
  825. .ignore_suspend = 1,
  826. SND_SOC_DAILINK_REG(quat_tdm_tx_0),
  827. },
  828. {
  829. .name = LPASS_BE_QUIN_TDM_RX_0,
  830. .stream_name = LPASS_BE_QUIN_TDM_RX_0,
  831. .playback_only = 1,
  832. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  833. SND_SOC_DPCM_TRIGGER_POST},
  834. .ops = &msm_common_be_ops,
  835. .ignore_suspend = 1,
  836. .ignore_pmdown_time = 1,
  837. SND_SOC_DAILINK_REG(quin_tdm_rx_0),
  838. },
  839. {
  840. .name = LPASS_BE_QUIN_TDM_TX_0,
  841. .stream_name = LPASS_BE_QUIN_TDM_TX_0,
  842. .capture_only = 1,
  843. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  844. SND_SOC_DPCM_TRIGGER_POST},
  845. .ops = &msm_common_be_ops,
  846. .ignore_suspend = 1,
  847. SND_SOC_DAILINK_REG(quin_tdm_tx_0),
  848. },
  849. {
  850. .name = LPASS_BE_SEN_TDM_RX_0,
  851. .stream_name = LPASS_BE_SEN_TDM_RX_0,
  852. .playback_only = 1,
  853. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  854. SND_SOC_DPCM_TRIGGER_POST},
  855. .ops = &msm_common_be_ops,
  856. .ignore_suspend = 1,
  857. .ignore_pmdown_time = 1,
  858. SND_SOC_DAILINK_REG(sen_tdm_rx_0),
  859. },
  860. {
  861. .name = LPASS_BE_SEN_TDM_TX_0,
  862. .stream_name = LPASS_BE_SEN_TDM_TX_0,
  863. .capture_only = 1,
  864. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  865. SND_SOC_DPCM_TRIGGER_POST},
  866. .ops = &msm_common_be_ops,
  867. .ignore_suspend = 1,
  868. SND_SOC_DAILINK_REG(sen_tdm_tx_0),
  869. },
  870. };
  871. static struct snd_soc_dai_link msm_waipio_dai_links[
  872. ARRAY_SIZE(msm_wsa_cdc_dma_be_dai_links) +
  873. #if 0
  874. ARRAY_SIZE(msm_wsa2_cdc_dma_be_dai_links) +
  875. #endif
  876. ARRAY_SIZE(msm_rx_tx_cdc_dma_be_dai_links) +
  877. ARRAY_SIZE(msm_va_cdc_dma_be_dai_links) +
  878. #if IS_ENABLED(CONFIG_AUDIO_QGKI)
  879. ARRAY_SIZE(ext_disp_be_dai_link) +
  880. #endif
  881. ARRAY_SIZE(msm_common_be_dai_links) +
  882. ARRAY_SIZE(msm_wcn_be_dai_links) +
  883. ARRAY_SIZE(msm_mi2s_dai_links) +
  884. ARRAY_SIZE(msm_tdm_dai_links)];
  885. static int msm_populate_dai_link_component_of_node(
  886. struct snd_soc_card *card)
  887. {
  888. int i, j, index, ret = 0;
  889. struct device *cdev = card->dev;
  890. struct snd_soc_dai_link *dai_link = card->dai_link;
  891. struct device_node *np = NULL;
  892. int codecs_enabled = 0;
  893. struct snd_soc_dai_link_component *codecs_comp = NULL;
  894. if (!cdev) {
  895. dev_err(cdev, "%s: Sound card device memory NULL\n", __func__);
  896. return -ENODEV;
  897. }
  898. for (i = 0; i < card->num_links; i++) {
  899. if (dai_link[i].init == NULL)
  900. dai_link[i].init = &msm_common_dai_link_init;
  901. /* populate codec_of_node for snd card dai links */
  902. if (dai_link[i].num_codecs > 0) {
  903. for (j = 0; j < dai_link[i].num_codecs; j++) {
  904. if (dai_link[i].codecs[j].of_node ||
  905. !dai_link[i].codecs[j].name)
  906. continue;
  907. index = of_property_match_string(cdev->of_node,
  908. "asoc-codec-names",
  909. dai_link[i].codecs[j].name);
  910. if (index < 0)
  911. continue;
  912. np = of_parse_phandle(cdev->of_node,
  913. "asoc-codec",
  914. index);
  915. if (!np) {
  916. dev_err(cdev, "%s: retrieving phandle for codec %s failed\n",
  917. __func__,
  918. dai_link[i].codecs[j].name);
  919. ret = -ENODEV;
  920. goto err;
  921. }
  922. dai_link[i].codecs[j].of_node = np;
  923. dai_link[i].codecs[j].name = NULL;
  924. }
  925. }
  926. }
  927. /* In multi-codec scenario, check if codecs are enabled for this platform */
  928. for (i = 0; i < card->num_links; i++) {
  929. codecs_enabled = 0;
  930. if (dai_link[i].num_codecs > 1) {
  931. for (j = 0; j < dai_link[i].num_codecs; j++) {
  932. if (!dai_link[i].codecs[j].of_node)
  933. continue;
  934. np = dai_link[i].codecs[j].of_node;
  935. if (!of_device_is_available(np)) {
  936. dev_err(cdev, "%s: codec is disabled: %s\n",
  937. __func__,
  938. np->full_name);
  939. dai_link[i].codecs[j].of_node = NULL;
  940. continue;
  941. }
  942. codecs_enabled++;
  943. }
  944. if (codecs_enabled > 0 &&
  945. codecs_enabled < dai_link[i].num_codecs) {
  946. codecs_comp = devm_kzalloc(cdev,
  947. sizeof(struct snd_soc_dai_link_component)
  948. * codecs_enabled, GFP_KERNEL);
  949. if (!codecs_comp) {
  950. dev_err(cdev, "%s: %s dailink codec component alloc failed\n",
  951. __func__, dai_link[i].name);
  952. ret = -ENOMEM;
  953. goto err;
  954. }
  955. index = 0;
  956. for (j = 0; j < dai_link[i].num_codecs; j++) {
  957. if(dai_link[i].codecs[j].of_node) {
  958. codecs_comp[index].of_node =
  959. dai_link[i].codecs[j].of_node;
  960. codecs_comp[index].dai_name =
  961. dai_link[i].codecs[j].dai_name;
  962. codecs_comp[index].name = NULL;
  963. index++;
  964. }
  965. }
  966. dai_link[i].codecs = codecs_comp;
  967. dai_link[i].num_codecs = codecs_enabled;
  968. }
  969. }
  970. }
  971. err:
  972. return ret;
  973. }
  974. static int msm_audrx_stub_init(struct snd_soc_pcm_runtime *rtd)
  975. {
  976. return 0;
  977. }
  978. static int msm_snd_stub_hw_params(struct snd_pcm_substream *substream,
  979. struct snd_pcm_hw_params *params)
  980. {
  981. return 0;
  982. }
  983. static struct snd_soc_ops msm_stub_be_ops = {
  984. .hw_params = msm_snd_stub_hw_params,
  985. };
  986. struct snd_soc_card snd_soc_card_stub_msm = {
  987. .name = "waipio-stub-snd-card",
  988. };
  989. static struct snd_soc_dai_link msm_stub_be_dai_links[] = {
  990. /* Backend DAI Links */
  991. {
  992. .name = LPASS_BE_PRI_AUXPCM_RX,
  993. .stream_name = LPASS_BE_PRI_AUXPCM_RX,
  994. .playback_only = 1,
  995. .init = &msm_audrx_stub_init,
  996. .ignore_pmdown_time = 1,
  997. .ignore_suspend = 1,
  998. .ops = &msm_stub_be_ops,
  999. SND_SOC_DAILINK_REG(auxpcm_rx),
  1000. },
  1001. {
  1002. .name = LPASS_BE_PRI_AUXPCM_TX,
  1003. .stream_name = LPASS_BE_PRI_AUXPCM_TX,
  1004. .capture_only = 1,
  1005. .ignore_suspend = 1,
  1006. .ops = &msm_stub_be_ops,
  1007. SND_SOC_DAILINK_REG(auxpcm_tx),
  1008. },
  1009. };
  1010. static struct snd_soc_dai_link msm_stub_dai_links[
  1011. ARRAY_SIZE(msm_stub_be_dai_links)];
  1012. static const struct of_device_id waipio_asoc_machine_of_match[] = {
  1013. { .compatible = "qcom,waipio-asoc-snd",
  1014. .data = "codec"},
  1015. { .compatible = "qcom,waipio-asoc-snd-stub",
  1016. .data = "stub_codec"},
  1017. {},
  1018. };
  1019. static int msm_snd_card_late_probe(struct snd_soc_card *card)
  1020. {
  1021. struct snd_soc_component *component = NULL;
  1022. struct snd_soc_pcm_runtime *rtd;
  1023. int ret = 0;
  1024. void *mbhc_calibration;
  1025. rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
  1026. if (!rtd) {
  1027. dev_err(card->dev,
  1028. "%s: snd_soc_get_pcm_runtime for %s failed!\n",
  1029. __func__, card->dai_link[0]);
  1030. return -EINVAL;
  1031. }
  1032. component = snd_soc_rtdcom_lookup(rtd, WCD938X_DRV_NAME);
  1033. if (!component) {
  1034. pr_err("%s component is NULL\n", __func__);
  1035. return -EINVAL;
  1036. }
  1037. mbhc_calibration = def_wcd_mbhc_cal();
  1038. if (!mbhc_calibration)
  1039. return -ENOMEM;
  1040. wcd_mbhc_cfg.calibration = mbhc_calibration;
  1041. ret = wcd938x_mbhc_hs_detect(component, &wcd_mbhc_cfg);
  1042. if (ret) {
  1043. dev_err(component->dev, "%s: mbhc hs detect failed, err:%d\n",
  1044. __func__, ret);
  1045. goto err_hs_detect;
  1046. }
  1047. return 0;
  1048. err_hs_detect:
  1049. kfree(mbhc_calibration);
  1050. return ret;
  1051. }
  1052. static struct snd_soc_card *populate_snd_card_dailinks(struct device *dev)
  1053. {
  1054. struct snd_soc_card *card = NULL;
  1055. struct snd_soc_dai_link *dailink = NULL;
  1056. int total_links = 0;
  1057. int rc = 0;
  1058. u32 val = 0;
  1059. const struct of_device_id *match;
  1060. match = of_match_node(waipio_asoc_machine_of_match, dev->of_node);
  1061. if (!match) {
  1062. dev_err(dev, "%s: No DT match found for sound card\n",
  1063. __func__);
  1064. return NULL;
  1065. }
  1066. if (!strcmp(match->data, "codec")) {
  1067. card = &snd_soc_card_waipio_msm;
  1068. /* late probe uses dai link at index '0' to get wcd component */
  1069. memcpy(msm_waipio_dai_links + total_links,
  1070. msm_rx_tx_cdc_dma_be_dai_links,
  1071. sizeof(msm_rx_tx_cdc_dma_be_dai_links));
  1072. total_links +=
  1073. ARRAY_SIZE(msm_rx_tx_cdc_dma_be_dai_links);
  1074. memcpy(msm_waipio_dai_links + total_links,
  1075. msm_wsa_cdc_dma_be_dai_links,
  1076. sizeof(msm_wsa_cdc_dma_be_dai_links));
  1077. total_links += ARRAY_SIZE(msm_wsa_cdc_dma_be_dai_links);
  1078. #if 0
  1079. memcpy(msm_waipio_dai_links + total_links,
  1080. msm_wsa2_cdc_dma_be_dai_links,
  1081. sizeof(msm_wsa2_cdc_dma_be_dai_links));
  1082. total_links += ARRAY_SIZE(msm_wsa2_cdc_dma_be_dai_links);
  1083. #endif
  1084. memcpy(msm_waipio_dai_links + total_links,
  1085. msm_va_cdc_dma_be_dai_links,
  1086. sizeof(msm_va_cdc_dma_be_dai_links));
  1087. total_links += ARRAY_SIZE(msm_va_cdc_dma_be_dai_links);
  1088. memcpy(msm_waipio_dai_links + total_links,
  1089. msm_common_be_dai_links,
  1090. sizeof(msm_common_be_dai_links));
  1091. total_links += ARRAY_SIZE(msm_common_be_dai_links);
  1092. rc = of_property_read_u32(dev->of_node,
  1093. "qcom,mi2s-audio-intf", &val);
  1094. if (!rc && val) {
  1095. memcpy(msm_waipio_dai_links + total_links,
  1096. msm_mi2s_dai_links,
  1097. sizeof(msm_mi2s_dai_links));
  1098. total_links += ARRAY_SIZE(msm_mi2s_dai_links);
  1099. }
  1100. rc = of_property_read_u32(dev->of_node,
  1101. "qcom,tdm-audio-intf", &val);
  1102. if (!rc && val) {
  1103. memcpy(msm_waipio_dai_links + total_links,
  1104. msm_tdm_dai_links,
  1105. sizeof(msm_tdm_dai_links));
  1106. total_links += ARRAY_SIZE(msm_tdm_dai_links);
  1107. }
  1108. #if IS_ENABLED(CONFIG_AUDIO_QGKI)
  1109. rc = of_property_read_u32(dev->of_node,
  1110. "qcom,ext-disp-audio-rx", &val);
  1111. if (!rc && val) {
  1112. dev_dbg(dev, "%s(): ext disp audio support present\n",
  1113. __func__);
  1114. memcpy(msm_waipio_dai_links + total_links,
  1115. ext_disp_be_dai_link,
  1116. sizeof(ext_disp_be_dai_link));
  1117. total_links += ARRAY_SIZE(ext_disp_be_dai_link);
  1118. }
  1119. #endif
  1120. rc = of_property_read_u32(dev->of_node, "qcom,wcn-bt", &val);
  1121. if (!rc && val) {
  1122. dev_dbg(dev, "%s(): WCN BT support present\n",
  1123. __func__);
  1124. memcpy(msm_waipio_dai_links + total_links,
  1125. msm_wcn_be_dai_links,
  1126. sizeof(msm_wcn_be_dai_links));
  1127. total_links += ARRAY_SIZE(msm_wcn_be_dai_links);
  1128. }
  1129. dailink = msm_waipio_dai_links;
  1130. } else if(!strcmp(match->data, "stub_codec")) {
  1131. card = &snd_soc_card_stub_msm;
  1132. memcpy(msm_stub_dai_links,
  1133. msm_stub_be_dai_links,
  1134. sizeof(msm_stub_be_dai_links));
  1135. dailink = msm_stub_dai_links;
  1136. total_links = ARRAY_SIZE(msm_stub_be_dai_links);
  1137. }
  1138. if (card) {
  1139. card->dai_link = dailink;
  1140. card->num_links = total_links;
  1141. card->late_probe = msm_snd_card_late_probe;
  1142. }
  1143. return card;
  1144. }
  1145. static int msm_int_wsa_init(struct snd_soc_pcm_runtime *rtd)
  1146. {
  1147. u8 spkleft_ports[WSA883X_MAX_SWR_PORTS] = {0, 1, 2, 3};
  1148. u8 spkright_ports[WSA883X_MAX_SWR_PORTS] = {0, 1, 2, 3};
  1149. u8 spkleft_port_types[WSA883X_MAX_SWR_PORTS] = {SPKR_L, SPKR_L_COMP,
  1150. SPKR_L_BOOST, SPKR_L_VI};
  1151. u8 spkright_port_types[WSA883X_MAX_SWR_PORTS] = {SPKR_R, SPKR_R_COMP,
  1152. SPKR_R_BOOST, SPKR_R_VI};
  1153. unsigned int ch_rate[WSA883X_MAX_SWR_PORTS] = {SWR_CLK_RATE_2P4MHZ, SWR_CLK_RATE_0P6MHZ,
  1154. SWR_CLK_RATE_0P3MHZ, SWR_CLK_RATE_1P2MHZ};
  1155. unsigned int ch_mask[WSA883X_MAX_SWR_PORTS] = {0x1, 0xF, 0x3, 0x3};
  1156. struct snd_soc_component *component = NULL;
  1157. struct snd_soc_dapm_context *dapm = NULL;
  1158. struct msm_asoc_mach_data *pdata =
  1159. snd_soc_card_get_drvdata(rtd->card);
  1160. if (pdata->wsa_max_devs > 0) {
  1161. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.1");
  1162. if (!component) {
  1163. pr_err("%s: wsa-codec.1 component is NULL\n", __func__);
  1164. return -EINVAL;
  1165. }
  1166. dapm = snd_soc_component_get_dapm(component);
  1167. wsa883x_set_channel_map(component, &spkleft_ports[0],
  1168. WSA883X_MAX_SWR_PORTS, &ch_mask[0],
  1169. &ch_rate[0], &spkleft_port_types[0]);
  1170. if (dapm->component) {
  1171. snd_soc_dapm_ignore_suspend(dapm, "spkrLeft IN");
  1172. snd_soc_dapm_ignore_suspend(dapm, "spkrLeft SPKR");
  1173. }
  1174. wsa883x_codec_info_create_codec_entry(pdata->codec_root,
  1175. component);
  1176. }
  1177. /* If current platform has more than one WSA */
  1178. if (pdata->wsa_max_devs > 1) {
  1179. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.2");
  1180. if (!component) {
  1181. pr_err("%s: wsa-codec.2 component is NULL\n", __func__);
  1182. return -EINVAL;
  1183. }
  1184. dapm = snd_soc_component_get_dapm(component);
  1185. wsa883x_set_channel_map(component, &spkright_ports[0],
  1186. WSA883X_MAX_SWR_PORTS, &ch_mask[0],
  1187. &ch_rate[0], &spkright_port_types[0]);
  1188. if (dapm->component) {
  1189. snd_soc_dapm_ignore_suspend(dapm, "spkrRight IN");
  1190. snd_soc_dapm_ignore_suspend(dapm, "spkrRight SPKR");
  1191. }
  1192. wsa883x_codec_info_create_codec_entry(pdata->codec_root,
  1193. component);
  1194. }
  1195. #if 0
  1196. if (pdata->wsa_max_devs > 2) {
  1197. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.3");
  1198. if (!component) {
  1199. pr_err("%s: wsa-codec.3 component is NULL\n", __func__);
  1200. return -EINVAL;
  1201. }
  1202. dapm = snd_soc_component_get_dapm(component);
  1203. wsa883x_set_channel_map(component, &spkleft_ports[0],
  1204. WSA883X_MAX_SWR_PORTS, &ch_mask[0],
  1205. &ch_rate[0], &spkleft_port_types[0]);
  1206. if (dapm->component) {
  1207. snd_soc_dapm_ignore_suspend(dapm, "spkr2Left IN");
  1208. snd_soc_dapm_ignore_suspend(dapm, "spkr2Left SPKR");
  1209. }
  1210. wsa883x_codec_info_create_codec_entry(pdata->codec_root,
  1211. component);
  1212. }
  1213. if (pdata->wsa_max_devs > 3) {
  1214. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.4");
  1215. if (!component) {
  1216. pr_err("%s: wsa-codec.4 component is NULL\n", __func__);
  1217. return -EINVAL;
  1218. }
  1219. dapm = snd_soc_component_get_dapm(component);
  1220. wsa883x_set_channel_map(component, &spkright_ports[0],
  1221. WSA883X_MAX_SWR_PORTS, &ch_mask[0],
  1222. &ch_rate[0], &spkright_port_types[0]);
  1223. if (dapm->component) {
  1224. snd_soc_dapm_ignore_suspend(dapm, "spkr2Right IN");
  1225. snd_soc_dapm_ignore_suspend(dapm, "spkr2Right SPKR");
  1226. }
  1227. wsa883x_codec_info_create_codec_entry(pdata->codec_root,
  1228. component);
  1229. }
  1230. #endif
  1231. snd_soc_dapm_ignore_suspend(dapm, "WSA_SPK1 OUT");
  1232. snd_soc_dapm_ignore_suspend(dapm, "WSA_SPK2 OUT");
  1233. #if 0
  1234. snd_soc_dapm_ignore_suspend(dapm, "WSA2_SPK1 OUT");
  1235. snd_soc_dapm_ignore_suspend(dapm, "WSA2_SPK2 OUT");
  1236. #endif
  1237. snd_soc_dapm_ignore_suspend(dapm, "WSA AIF VI");
  1238. snd_soc_dapm_ignore_suspend(dapm, "VIINPUT_WSA");
  1239. snd_soc_dapm_sync(dapm);
  1240. msm_common_dai_link_init(rtd);
  1241. return 0;
  1242. }
  1243. static int msm_rx_tx_codec_init(struct snd_soc_pcm_runtime *rtd)
  1244. {
  1245. struct snd_soc_component *component = NULL;
  1246. struct snd_soc_dapm_context *dapm = NULL;
  1247. struct snd_info_entry *entry = NULL;
  1248. struct snd_card *card = NULL;
  1249. struct msm_asoc_mach_data *pdata =
  1250. snd_soc_card_get_drvdata(rtd->card);
  1251. int ret = 0;
  1252. component = snd_soc_rtdcom_lookup(rtd, "lpass-cdc");
  1253. if (!component) {
  1254. pr_err("%s: could not find component for lpass-cdc\n",
  1255. __func__);
  1256. return ret;
  1257. }
  1258. dapm = snd_soc_component_get_dapm(component);
  1259. snd_soc_dapm_new_controls(dapm, msm_int_dapm_widgets,
  1260. ARRAY_SIZE(msm_int_dapm_widgets));
  1261. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic0");
  1262. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic1");
  1263. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic2");
  1264. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic3");
  1265. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic4");
  1266. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic5");
  1267. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic6");
  1268. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic7");
  1269. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic1");
  1270. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic2");
  1271. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic3");
  1272. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic4");
  1273. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic5");
  1274. lpass_cdc_set_port_map(component, ARRAY_SIZE(sm_port_map), sm_port_map);
  1275. card = rtd->card->snd_card;
  1276. if (!pdata->codec_root) {
  1277. entry = msm_snd_info_create_subdir(card->module, "codecs",
  1278. card->proc_root);
  1279. if (!entry) {
  1280. pr_debug("%s: Cannot create codecs module entry\n",
  1281. __func__);
  1282. return ret;
  1283. }
  1284. pdata->codec_root = entry;
  1285. }
  1286. lpass_cdc_info_create_codec_entry(pdata->codec_root, component);
  1287. lpass_cdc_register_wake_irq(component, false);
  1288. if (pdata->wcd_disabled)
  1289. goto done;
  1290. component = snd_soc_rtdcom_lookup(rtd, WCD938X_DRV_NAME);
  1291. if (!component) {
  1292. pr_err("%s component is NULL\n", __func__);
  1293. return -EINVAL;
  1294. }
  1295. dapm = snd_soc_component_get_dapm(component);
  1296. card = component->card->snd_card;
  1297. snd_soc_dapm_ignore_suspend(dapm, "EAR");
  1298. snd_soc_dapm_ignore_suspend(dapm, "AUX");
  1299. snd_soc_dapm_ignore_suspend(dapm, "HPHL");
  1300. snd_soc_dapm_ignore_suspend(dapm, "HPHR");
  1301. snd_soc_dapm_ignore_suspend(dapm, "AMIC1");
  1302. snd_soc_dapm_ignore_suspend(dapm, "AMIC2");
  1303. snd_soc_dapm_ignore_suspend(dapm, "AMIC3");
  1304. snd_soc_dapm_ignore_suspend(dapm, "AMIC4");
  1305. snd_soc_dapm_sync(dapm);
  1306. pdata = snd_soc_card_get_drvdata(component->card);
  1307. if (!pdata->codec_root) {
  1308. entry = msm_snd_info_create_subdir(card->module, "codecs",
  1309. card->proc_root);
  1310. if (!entry) {
  1311. dev_dbg(component->dev, "%s: Cannot create codecs module entry\n",
  1312. __func__);
  1313. return 0;
  1314. }
  1315. pdata->codec_root = entry;
  1316. }
  1317. wcd938x_info_create_codec_entry(pdata->codec_root, component);
  1318. #if 0
  1319. codec_variant = wcd938x_get_codec_variant(component);
  1320. dev_dbg(component->dev, "%s: variant %d\n", __func__, codec_variant);
  1321. if (codec_variant == WCD9380)
  1322. ret = snd_soc_add_component_controls(component,
  1323. msm_int_wcd9380_snd_controls,
  1324. ARRAY_SIZE(msm_int_wcd9380_snd_controls));
  1325. else if (codec_variant == WCD9385)
  1326. ret = snd_soc_add_component_controls(component,
  1327. msm_int_wcd9385_snd_controls,
  1328. ARRAY_SIZE(msm_int_wcd9385_snd_controls));
  1329. if (ret < 0) {
  1330. dev_err(component->dev, "%s: add codec specific snd controls failed: %d\n",
  1331. __func__, ret);
  1332. return ret;
  1333. }
  1334. #endif
  1335. done:
  1336. codec_reg_done = true;
  1337. msm_common_dai_link_init(rtd);
  1338. return ret;
  1339. }
  1340. static int waipio_ssr_enable(struct device *dev, void *data)
  1341. {
  1342. struct platform_device *pdev = to_platform_device(dev);
  1343. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1344. int ret = 0;
  1345. if (!card) {
  1346. dev_err(dev, "%s: card is NULL\n", __func__);
  1347. ret = -EINVAL;
  1348. goto err;
  1349. }
  1350. if (!strcmp(card->name, "waipio-stub-snd-card")) {
  1351. /* TODO */
  1352. dev_dbg(dev, "%s: TODO \n", __func__);
  1353. }
  1354. snd_card_notify_user(1);
  1355. dev_dbg(dev, "%s: setting snd_card to ONLINE\n", __func__);
  1356. err:
  1357. return ret;
  1358. }
  1359. static void waipio_ssr_disable(struct device *dev, void *data)
  1360. {
  1361. struct platform_device *pdev = to_platform_device(dev);
  1362. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1363. if (!card) {
  1364. dev_err(dev, "%s: card is NULL\n", __func__);
  1365. return;
  1366. }
  1367. dev_dbg(dev, "%s: setting snd_card to OFFLINE\n", __func__);
  1368. snd_card_notify_user(0);
  1369. if (!strcmp(card->name, "waipio-stub-snd-card")) {
  1370. /* TODO */
  1371. dev_dbg(dev, "%s: TODO \n", __func__);
  1372. }
  1373. }
  1374. static const struct snd_event_ops waipio_ssr_ops = {
  1375. .enable = waipio_ssr_enable,
  1376. .disable = waipio_ssr_disable,
  1377. };
  1378. static int msm_audio_ssr_compare(struct device *dev, void *data)
  1379. {
  1380. struct device_node *node = data;
  1381. dev_dbg(dev, "%s: dev->of_node = 0x%p, node = 0x%p\n",
  1382. __func__, dev->of_node, node);
  1383. return (dev->of_node && dev->of_node == node);
  1384. }
  1385. static int msm_audio_ssr_register(struct device *dev)
  1386. {
  1387. struct device_node *np = dev->of_node;
  1388. struct snd_event_clients *ssr_clients = NULL;
  1389. struct device_node *node = NULL;
  1390. int ret = 0;
  1391. int i = 0;
  1392. for (i = 0; ; i++) {
  1393. node = of_parse_phandle(np, "qcom,msm_audio_ssr_devs", i);
  1394. if (!node)
  1395. break;
  1396. snd_event_mstr_add_client(&ssr_clients,
  1397. msm_audio_ssr_compare, node);
  1398. }
  1399. ret = snd_event_master_register(dev, &waipio_ssr_ops,
  1400. ssr_clients, NULL);
  1401. if (!ret)
  1402. snd_event_notify(dev, SND_EVENT_UP);
  1403. return ret;
  1404. }
  1405. struct msm_common_pdata *msm_common_get_pdata(struct snd_soc_card *card)
  1406. {
  1407. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  1408. if (!pdata)
  1409. return NULL;
  1410. return pdata->common_pdata;
  1411. }
  1412. void msm_common_set_pdata(struct snd_soc_card *card,
  1413. struct msm_common_pdata *common_pdata)
  1414. {
  1415. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  1416. if (!pdata)
  1417. return;
  1418. pdata->common_pdata = common_pdata;
  1419. }
  1420. static int msm_asoc_machine_probe(struct platform_device *pdev)
  1421. {
  1422. struct snd_soc_card *card = NULL;
  1423. struct msm_asoc_mach_data *pdata = NULL;
  1424. int ret = 0;
  1425. struct clk *lpass_audio_hw_vote = NULL;
  1426. if (!pdev->dev.of_node) {
  1427. dev_err(&pdev->dev, "%s: No platform supplied from device tree\n", __func__);
  1428. return -EINVAL;
  1429. }
  1430. pdata = devm_kzalloc(&pdev->dev,
  1431. sizeof(struct msm_asoc_mach_data), GFP_KERNEL);
  1432. if (!pdata)
  1433. return -ENOMEM;
  1434. of_property_read_u32(pdev->dev.of_node,
  1435. "qcom,wcd-disabled",
  1436. &pdata->wcd_disabled);
  1437. card = populate_snd_card_dailinks(&pdev->dev);
  1438. if (!card) {
  1439. dev_err(&pdev->dev, "%s: Card uninitialized\n", __func__);
  1440. ret = -EINVAL;
  1441. goto err;
  1442. }
  1443. card->dev = &pdev->dev;
  1444. platform_set_drvdata(pdev, card);
  1445. snd_soc_card_set_drvdata(card, pdata);
  1446. ret = snd_soc_of_parse_card_name(card, "qcom,model");
  1447. if (ret) {
  1448. dev_err(&pdev->dev, "%s: parse card name failed, err:%d\n",
  1449. __func__, ret);
  1450. goto err;
  1451. }
  1452. ret = snd_soc_of_parse_audio_routing(card, "qcom,audio-routing");
  1453. if (ret) {
  1454. dev_err(&pdev->dev, "%s: parse audio routing failed, err:%d\n",
  1455. __func__, ret);
  1456. goto err;
  1457. }
  1458. ret = msm_populate_dai_link_component_of_node(card);
  1459. if (ret) {
  1460. ret = -EPROBE_DEFER;
  1461. goto err;
  1462. }
  1463. /* Get maximum WSA device count for this platform */
  1464. ret = of_property_read_u32(pdev->dev.of_node,
  1465. "qcom,wsa-max-devs", &pdata->wsa_max_devs);
  1466. if (ret) {
  1467. dev_info(&pdev->dev,
  1468. "%s: wsa-max-devs property missing in DT %s, ret = %d\n",
  1469. __func__, pdev->dev.of_node->full_name, ret);
  1470. pdata->wsa_max_devs = 0;
  1471. }
  1472. ret = devm_snd_soc_register_card(&pdev->dev, card);
  1473. if (ret == -EPROBE_DEFER) {
  1474. if (codec_reg_done)
  1475. ret = -EINVAL;
  1476. goto err;
  1477. } else if (ret) {
  1478. dev_err(&pdev->dev, "%s: snd_soc_register_card failed (%d)\n",
  1479. __func__, ret);
  1480. goto err;
  1481. }
  1482. dev_info(&pdev->dev, "%s: Sound card %s registered\n",
  1483. __func__, card->name);
  1484. if (wcd_mbhc_cfg.enable_usbc_analog)
  1485. wcd_mbhc_cfg.swap_gnd_mic = msm_usbc_swap_gnd_mic;
  1486. pdata->fsa_handle = of_parse_phandle(pdev->dev.of_node,
  1487. "fsa4480-i2c-handle", 0);
  1488. if (!pdata->fsa_handle)
  1489. dev_dbg(&pdev->dev, "property %s not detected in node %s\n",
  1490. "fsa4480-i2c-handle", pdev->dev.of_node->full_name);
  1491. pdata->dmic01_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1492. "qcom,cdc-dmic01-gpios",
  1493. 0);
  1494. pdata->dmic23_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1495. "qcom,cdc-dmic23-gpios",
  1496. 0);
  1497. pdata->dmic45_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1498. "qcom,cdc-dmic45-gpios",
  1499. 0);
  1500. if (pdata->dmic01_gpio_p)
  1501. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic01_gpio_p, false);
  1502. if (pdata->dmic23_gpio_p)
  1503. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic23_gpio_p, false);
  1504. if (pdata->dmic45_gpio_p)
  1505. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic45_gpio_p, false);
  1506. msm_common_snd_init(pdev, card);
  1507. /* Register LPASS audio hw vote */
  1508. lpass_audio_hw_vote = devm_clk_get(&pdev->dev, "lpass_audio_hw_vote");
  1509. if (IS_ERR(lpass_audio_hw_vote)) {
  1510. ret = PTR_ERR(lpass_audio_hw_vote);
  1511. dev_dbg(&pdev->dev, "%s: clk get %s failed %d\n",
  1512. __func__, "lpass_audio_hw_vote", ret);
  1513. lpass_audio_hw_vote = NULL;
  1514. ret = 0;
  1515. }
  1516. pdata->lpass_audio_hw_vote = lpass_audio_hw_vote;
  1517. pdata->core_audio_vote_count = 0;
  1518. ret = msm_audio_ssr_register(&pdev->dev);
  1519. if (ret)
  1520. pr_err("%s: Registration with SND event FWK failed ret = %d\n",
  1521. __func__, ret);
  1522. is_initial_boot = true;
  1523. #ifdef PM_QOS_ENABLE
  1524. /* Add QoS request for audio tasks */
  1525. msm_audio_add_qos_request();
  1526. #endif
  1527. return 0;
  1528. err:
  1529. devm_kfree(&pdev->dev, pdata);
  1530. return ret;
  1531. }
  1532. static int msm_asoc_machine_remove(struct platform_device *pdev)
  1533. {
  1534. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1535. struct msm_asoc_mach_data *pdata = NULL;
  1536. struct msm_common_pdata *common_pdata = NULL;
  1537. if (card)
  1538. pdata = snd_soc_card_get_drvdata(card);
  1539. if (pdata)
  1540. common_pdata = pdata->common_pdata;
  1541. msm_common_snd_deinit(common_pdata);
  1542. snd_event_master_deregister(&pdev->dev);
  1543. snd_soc_unregister_card(card);
  1544. #ifdef PM_QOS_ENABLE
  1545. msm_audio_remove_qos_request();
  1546. #endif
  1547. return 0;
  1548. }
  1549. static struct platform_driver waipio_asoc_machine_driver = {
  1550. .driver = {
  1551. .name = DRV_NAME,
  1552. .owner = THIS_MODULE,
  1553. .pm = &snd_soc_pm_ops,
  1554. .of_match_table = waipio_asoc_machine_of_match,
  1555. .suppress_bind_attrs = true,
  1556. },
  1557. .probe = msm_asoc_machine_probe,
  1558. .remove = msm_asoc_machine_remove,
  1559. };
  1560. static int __init msm_asoc_machine_init(void)
  1561. {
  1562. snd_card_sysfs_init();
  1563. return platform_driver_register(&waipio_asoc_machine_driver);
  1564. }
  1565. module_init(msm_asoc_machine_init);
  1566. static void __exit msm_asoc_machine_exit(void)
  1567. {
  1568. platform_driver_unregister(&waipio_asoc_machine_driver);
  1569. }
  1570. module_exit(msm_asoc_machine_exit);
  1571. MODULE_SOFTDEP("pre: bt_fm_slim");
  1572. MODULE_DESCRIPTION("ALSA SoC msm");
  1573. MODULE_LICENSE("GPL v2");
  1574. MODULE_ALIAS("platform:" DRV_NAME);
  1575. MODULE_DEVICE_TABLE(of, waipio_asoc_machine_of_match);