kalama.c 53 KB

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