waipio.c 51 KB

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