kalama.c 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972
  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("%s: rtd is NULL\n", __func__);
  167. return;
  168. }
  169. pdata = snd_soc_card_get_drvdata(rtd->card);
  170. if (!pdata) {
  171. pr_err("%s: pdata is NULL\n", __func__);
  172. return;
  173. }
  174. if (!pdata->get_dev_num) {
  175. pr_err("%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("%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("%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("%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("%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(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(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(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("%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("%s: gpio set cannot be de-activated %sd",
  303. __func__, "dmic_gpio");
  304. return ret;
  305. }
  306. }
  307. break;
  308. default:
  309. pr_err("%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. static struct snd_soc_dai_link msm_wcn_be_dai_links[] = {
  429. {
  430. .name = LPASS_BE_SLIMBUS_7_RX,
  431. .stream_name = LPASS_BE_SLIMBUS_7_RX,
  432. .playback_only = 1,
  433. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  434. SND_SOC_DPCM_TRIGGER_POST},
  435. .init = &msm_wcn_init,
  436. .ops = &msm_common_be_ops,
  437. /* dai link has playback support */
  438. .ignore_pmdown_time = 1,
  439. .ignore_suspend = 1,
  440. SND_SOC_DAILINK_REG(slimbus_7_rx),
  441. },
  442. {
  443. .name = LPASS_BE_SLIMBUS_7_TX,
  444. .stream_name = LPASS_BE_SLIMBUS_7_TX,
  445. .capture_only = 1,
  446. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  447. SND_SOC_DPCM_TRIGGER_POST},
  448. .ops = &msm_common_be_ops,
  449. .ignore_suspend = 1,
  450. SND_SOC_DAILINK_REG(slimbus_7_tx),
  451. },
  452. };
  453. static struct snd_soc_dai_link ext_disp_be_dai_link[] = {
  454. /* DISP PORT BACK END DAI Link */
  455. {
  456. .name = LPASS_BE_DISPLAY_PORT_RX,
  457. .stream_name = LPASS_BE_DISPLAY_PORT_RX,
  458. .playback_only = 1,
  459. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  460. SND_SOC_DPCM_TRIGGER_POST},
  461. .ignore_pmdown_time = 1,
  462. .ignore_suspend = 1,
  463. SND_SOC_DAILINK_REG(display_port),
  464. },
  465. };
  466. static struct snd_soc_dai_link msm_wsa_cdc_dma_be_dai_links[] = {
  467. /* WSA CDC DMA Backend DAI Links */
  468. {
  469. .name = LPASS_BE_WSA_CDC_DMA_RX_0,
  470. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_0,
  471. .playback_only = 1,
  472. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  473. SND_SOC_DPCM_TRIGGER_POST},
  474. .ignore_pmdown_time = 1,
  475. .ignore_suspend = 1,
  476. .ops = &msm_common_be_ops,
  477. SND_SOC_DAILINK_REG(wsa_dma_rx0),
  478. .init = &msm_int_wsa_init,
  479. },
  480. {
  481. .name = LPASS_BE_WSA_CDC_DMA_RX_1,
  482. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_1,
  483. .playback_only = 1,
  484. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  485. SND_SOC_DPCM_TRIGGER_POST},
  486. .ignore_pmdown_time = 1,
  487. .ignore_suspend = 1,
  488. .ops = &msm_common_be_ops,
  489. SND_SOC_DAILINK_REG(wsa_dma_rx1),
  490. },
  491. {
  492. .name = LPASS_BE_WSA_CDC_DMA_TX_1,
  493. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_1,
  494. .capture_only = 1,
  495. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  496. SND_SOC_DPCM_TRIGGER_POST},
  497. .ignore_suspend = 1,
  498. .ops = &msm_common_be_ops,
  499. SND_SOC_DAILINK_REG(wsa_dma_tx1),
  500. },
  501. {
  502. .name = LPASS_BE_WSA_CDC_DMA_TX_0,
  503. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_0,
  504. .capture_only = 1,
  505. .ignore_suspend = 1,
  506. .ops = &msm_common_be_ops,
  507. /* .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, */
  508. SND_SOC_DAILINK_REG(vi_feedback),
  509. },
  510. {
  511. .name = LPASS_BE_WSA_CDC_DMA_RX_0_VIRT,
  512. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_0_VIRT,
  513. .playback_only = 1,
  514. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  515. SND_SOC_DPCM_TRIGGER_POST},
  516. .ignore_pmdown_time = 1,
  517. .ignore_suspend = 1,
  518. .ops = &msm_common_be_ops,
  519. SND_SOC_DAILINK_REG(wsa_dma_rx0),
  520. .init = &msm_int_wsa_init,
  521. },
  522. };
  523. static struct snd_soc_dai_link msm_wsa2_cdc_dma_be_dai_links[] = {
  524. /* WSA2 CDC DMA Backend DAI Links */
  525. {
  526. .name = LPASS_BE_WSA2_CDC_DMA_RX_0,
  527. .stream_name = LPASS_BE_WSA2_CDC_DMA_RX_0,
  528. .playback_only = 1,
  529. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  530. SND_SOC_DPCM_TRIGGER_POST},
  531. .ignore_pmdown_time = 1,
  532. .ignore_suspend = 1,
  533. .ops = &msm_common_be_ops,
  534. SND_SOC_DAILINK_REG(wsa2_dma_rx0),
  535. },
  536. {
  537. .name = LPASS_BE_WSA2_CDC_DMA_RX_1,
  538. .stream_name = LPASS_BE_WSA2_CDC_DMA_RX_1,
  539. .playback_only = 1,
  540. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  541. SND_SOC_DPCM_TRIGGER_POST},
  542. .ignore_pmdown_time = 1,
  543. .ignore_suspend = 1,
  544. .ops = &msm_common_be_ops,
  545. SND_SOC_DAILINK_REG(wsa2_dma_rx1),
  546. },
  547. {
  548. .name = LPASS_BE_WSA2_CDC_DMA_TX_1,
  549. .stream_name = LPASS_BE_WSA2_CDC_DMA_TX_1,
  550. .capture_only = 1,
  551. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  552. SND_SOC_DPCM_TRIGGER_POST},
  553. .ignore_suspend = 1,
  554. .ops = &msm_common_be_ops,
  555. SND_SOC_DAILINK_REG(wsa2_dma_tx1),
  556. },
  557. {
  558. .name = LPASS_BE_WSA2_CDC_DMA_TX_0,
  559. .stream_name = LPASS_BE_WSA2_CDC_DMA_TX_0,
  560. .capture_only = 1,
  561. .ignore_suspend = 1,
  562. .ops = &msm_common_be_ops,
  563. /* .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, */
  564. SND_SOC_DAILINK_REG(wsa2_vi_feedback),
  565. },
  566. };
  567. static struct snd_soc_dai_link msm_wsa_wsa2_cdc_dma_be_dai_links[] = {
  568. /* WSA CDC DMA Backend DAI Links */
  569. {
  570. .name = LPASS_BE_WSA_CDC_DMA_RX_0,
  571. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_0,
  572. .playback_only = 1,
  573. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  574. SND_SOC_DPCM_TRIGGER_POST},
  575. .ignore_pmdown_time = 1,
  576. .ignore_suspend = 1,
  577. .ops = &msm_common_be_ops,
  578. SND_SOC_DAILINK_REG(wsa_wsa2_dma_rx0),
  579. .init = &msm_int_wsa_init,
  580. },
  581. {
  582. .name = LPASS_BE_WSA_CDC_DMA_RX_1,
  583. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_1,
  584. .playback_only = 1,
  585. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  586. SND_SOC_DPCM_TRIGGER_POST},
  587. .ignore_pmdown_time = 1,
  588. .ignore_suspend = 1,
  589. .ops = &msm_common_be_ops,
  590. SND_SOC_DAILINK_REG(wsa_wsa2_dma_rx1),
  591. },
  592. {
  593. .name = LPASS_BE_WSA_CDC_DMA_TX_1,
  594. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_1,
  595. .capture_only = 1,
  596. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  597. SND_SOC_DPCM_TRIGGER_POST},
  598. .ignore_suspend = 1,
  599. .ops = &msm_common_be_ops,
  600. SND_SOC_DAILINK_REG(wsa_wsa2_dma_tx1),
  601. },
  602. {
  603. .name = LPASS_BE_WSA_CDC_DMA_TX_0,
  604. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_0,
  605. .capture_only = 1,
  606. .ignore_suspend = 1,
  607. .ops = &msm_common_be_ops,
  608. /* .no_host_mode = SND_SOC_DAI_LINK_NO_HOST, */
  609. SND_SOC_DAILINK_REG(wsa_wsa2_vi_feedback),
  610. },
  611. };
  612. static struct snd_soc_dai_link msm_rx_tx_cdc_dma_be_dai_links[] = {
  613. /* RX CDC DMA Backend DAI Links */
  614. {
  615. .name = LPASS_BE_RX_CDC_DMA_RX_0,
  616. .stream_name = LPASS_BE_RX_CDC_DMA_RX_0,
  617. .playback_only = 1,
  618. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  619. SND_SOC_DPCM_TRIGGER_POST},
  620. .ignore_pmdown_time = 1,
  621. .ignore_suspend = 1,
  622. .ops = &msm_common_be_ops,
  623. SND_SOC_DAILINK_REG(rx_dma_rx0),
  624. .init = &msm_rx_tx_codec_init,
  625. },
  626. {
  627. .name = LPASS_BE_RX_CDC_DMA_RX_1,
  628. .stream_name = LPASS_BE_RX_CDC_DMA_RX_1,
  629. .playback_only = 1,
  630. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  631. SND_SOC_DPCM_TRIGGER_POST},
  632. .ignore_pmdown_time = 1,
  633. .ignore_suspend = 1,
  634. .ops = &msm_common_be_ops,
  635. SND_SOC_DAILINK_REG(rx_dma_rx1),
  636. },
  637. {
  638. .name = LPASS_BE_RX_CDC_DMA_RX_2,
  639. .stream_name = LPASS_BE_RX_CDC_DMA_RX_2,
  640. .playback_only = 1,
  641. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  642. SND_SOC_DPCM_TRIGGER_POST},
  643. .ignore_pmdown_time = 1,
  644. .ignore_suspend = 1,
  645. .ops = &msm_common_be_ops,
  646. SND_SOC_DAILINK_REG(rx_dma_rx2),
  647. },
  648. {
  649. .name = LPASS_BE_RX_CDC_DMA_RX_3,
  650. .stream_name = LPASS_BE_RX_CDC_DMA_RX_3,
  651. .playback_only = 1,
  652. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  653. SND_SOC_DPCM_TRIGGER_POST},
  654. .ignore_pmdown_time = 1,
  655. .ignore_suspend = 1,
  656. .ops = &msm_common_be_ops,
  657. SND_SOC_DAILINK_REG(rx_dma_rx3),
  658. },
  659. {
  660. .name = LPASS_BE_RX_CDC_DMA_RX_5,
  661. .stream_name = LPASS_BE_RX_CDC_DMA_RX_5,
  662. .playback_only = 1,
  663. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  664. SND_SOC_DPCM_TRIGGER_POST},
  665. .ignore_pmdown_time = 1,
  666. .ignore_suspend = 1,
  667. .ops = &msm_common_be_ops,
  668. SND_SOC_DAILINK_REG(rx_dma_rx5),
  669. },
  670. {
  671. .name = LPASS_BE_RX_CDC_DMA_RX_6,
  672. .stream_name = LPASS_BE_RX_CDC_DMA_RX_6,
  673. .playback_only = 1,
  674. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  675. SND_SOC_DPCM_TRIGGER_POST},
  676. .ignore_pmdown_time = 1,
  677. .ignore_suspend = 1,
  678. .ops = &msm_common_be_ops,
  679. SND_SOC_DAILINK_REG(rx_dma_rx6),
  680. },
  681. /* TX CDC DMA Backend DAI Links */
  682. {
  683. .name = LPASS_BE_TX_CDC_DMA_TX_3,
  684. .stream_name = LPASS_BE_TX_CDC_DMA_TX_3,
  685. .capture_only = 1,
  686. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  687. SND_SOC_DPCM_TRIGGER_POST},
  688. .ignore_suspend = 1,
  689. .ops = &msm_common_be_ops,
  690. SND_SOC_DAILINK_REG(tx_dma_tx3),
  691. },
  692. {
  693. .name = LPASS_BE_TX_CDC_DMA_TX_4,
  694. .stream_name = LPASS_BE_TX_CDC_DMA_TX_4,
  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_tx4),
  701. },
  702. };
  703. static struct snd_soc_dai_link msm_va_cdc_dma_be_dai_links[] = {
  704. {
  705. .name = LPASS_BE_VA_CDC_DMA_TX_0,
  706. .stream_name = LPASS_BE_VA_CDC_DMA_TX_0,
  707. .capture_only = 1,
  708. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  709. SND_SOC_DPCM_TRIGGER_POST},
  710. .ignore_suspend = 1,
  711. .ops = &msm_common_be_ops,
  712. SND_SOC_DAILINK_REG(va_dma_tx0),
  713. },
  714. {
  715. .name = LPASS_BE_VA_CDC_DMA_TX_1,
  716. .stream_name = LPASS_BE_VA_CDC_DMA_TX_1,
  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_tx1),
  723. },
  724. {
  725. .name = LPASS_BE_VA_CDC_DMA_TX_2,
  726. .stream_name = LPASS_BE_VA_CDC_DMA_TX_2,
  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_tx2),
  733. },
  734. };
  735. /*
  736. * I2S interface pinctrl mapping
  737. * ------------------------------------
  738. * Primary - pri_mi2s
  739. * Secondary - lpi_i2s3
  740. * Tertiary - tert_mi2s
  741. * Quaternary - quat_mi2s (lpi_i2s0)
  742. * Quinary - lpi_i2s1
  743. * Senary - lpi_i2s2
  744. * ------------------------------------
  745. */
  746. static struct snd_soc_dai_link msm_mi2s_dai_links[] = {
  747. {
  748. .name = LPASS_BE_PRI_MI2S_RX,
  749. .stream_name = LPASS_BE_PRI_MI2S_RX,
  750. .playback_only = 1,
  751. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  752. SND_SOC_DPCM_TRIGGER_POST},
  753. .ops = &msm_common_be_ops,
  754. .ignore_suspend = 1,
  755. .ignore_pmdown_time = 1,
  756. SND_SOC_DAILINK_REG(pri_mi2s_rx),
  757. },
  758. {
  759. .name = LPASS_BE_PRI_MI2S_TX,
  760. .stream_name = LPASS_BE_PRI_MI2S_TX,
  761. .capture_only = 1,
  762. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  763. SND_SOC_DPCM_TRIGGER_POST},
  764. .ops = &msm_common_be_ops,
  765. .ignore_suspend = 1,
  766. SND_SOC_DAILINK_REG(pri_mi2s_tx),
  767. },
  768. {
  769. .name = LPASS_BE_SEC_MI2S_RX,
  770. .stream_name = LPASS_BE_SEC_MI2S_RX,
  771. .playback_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. .ignore_pmdown_time = 1,
  777. SND_SOC_DAILINK_REG(sec_mi2s_rx),
  778. },
  779. {
  780. .name = LPASS_BE_SEC_MI2S_TX,
  781. .stream_name = LPASS_BE_SEC_MI2S_TX,
  782. .capture_only = 1,
  783. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  784. SND_SOC_DPCM_TRIGGER_POST},
  785. .ops = &msm_common_be_ops,
  786. .ignore_suspend = 1,
  787. SND_SOC_DAILINK_REG(sec_mi2s_tx),
  788. },
  789. {
  790. .name = LPASS_BE_TERT_MI2S_RX,
  791. .stream_name = LPASS_BE_TERT_MI2S_RX,
  792. .playback_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. .ignore_pmdown_time = 1,
  798. SND_SOC_DAILINK_REG(tert_mi2s_rx),
  799. },
  800. {
  801. .name = LPASS_BE_TERT_MI2S_TX,
  802. .stream_name = LPASS_BE_TERT_MI2S_TX,
  803. .capture_only = 1,
  804. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  805. SND_SOC_DPCM_TRIGGER_POST},
  806. .ops = &msm_common_be_ops,
  807. .ignore_suspend = 1,
  808. SND_SOC_DAILINK_REG(tert_mi2s_tx),
  809. },
  810. {
  811. .name = LPASS_BE_QUAT_MI2S_RX,
  812. .stream_name = LPASS_BE_QUAT_MI2S_RX,
  813. .playback_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. .ignore_pmdown_time = 1,
  819. SND_SOC_DAILINK_REG(quat_mi2s_rx),
  820. },
  821. {
  822. .name = LPASS_BE_QUAT_MI2S_TX,
  823. .stream_name = LPASS_BE_QUAT_MI2S_TX,
  824. .capture_only = 1,
  825. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  826. SND_SOC_DPCM_TRIGGER_POST},
  827. .ops = &msm_common_be_ops,
  828. .ignore_suspend = 1,
  829. SND_SOC_DAILINK_REG(quat_mi2s_tx),
  830. },
  831. {
  832. .name = LPASS_BE_QUIN_MI2S_RX,
  833. .stream_name = LPASS_BE_QUIN_MI2S_RX,
  834. .playback_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. .ignore_pmdown_time = 1,
  840. SND_SOC_DAILINK_REG(quin_mi2s_rx),
  841. },
  842. {
  843. .name = LPASS_BE_QUIN_MI2S_TX,
  844. .stream_name = LPASS_BE_QUIN_MI2S_TX,
  845. .capture_only = 1,
  846. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  847. SND_SOC_DPCM_TRIGGER_POST},
  848. .ops = &msm_common_be_ops,
  849. .ignore_suspend = 1,
  850. SND_SOC_DAILINK_REG(quin_mi2s_tx),
  851. },
  852. {
  853. .name = LPASS_BE_SEN_MI2S_RX,
  854. .stream_name = LPASS_BE_SEN_MI2S_RX,
  855. .playback_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. .ignore_pmdown_time = 1,
  861. SND_SOC_DAILINK_REG(sen_mi2s_rx),
  862. },
  863. {
  864. .name = LPASS_BE_SEN_MI2S_TX,
  865. .stream_name = LPASS_BE_SEN_MI2S_TX,
  866. .capture_only = 1,
  867. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  868. SND_SOC_DPCM_TRIGGER_POST},
  869. .ops = &msm_common_be_ops,
  870. .ignore_suspend = 1,
  871. SND_SOC_DAILINK_REG(sen_mi2s_tx),
  872. },
  873. {
  874. .name = LPASS_BE_SEP_MI2S_RX,
  875. .stream_name = LPASS_BE_SEP_MI2S_RX,
  876. .playback_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. .ignore_pmdown_time = 1,
  882. SND_SOC_DAILINK_REG(sep_mi2s_rx),
  883. },
  884. {
  885. .name = LPASS_BE_SEP_MI2S_TX,
  886. .stream_name = LPASS_BE_SEP_MI2S_TX,
  887. .capture_only = 1,
  888. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  889. SND_SOC_DPCM_TRIGGER_POST},
  890. .ops = &msm_common_be_ops,
  891. .ignore_suspend = 1,
  892. SND_SOC_DAILINK_REG(sep_mi2s_tx),
  893. },
  894. };
  895. static struct snd_soc_dai_link msm_tdm_dai_links[] = {
  896. {
  897. .name = LPASS_BE_PRI_TDM_RX_0,
  898. .stream_name = LPASS_BE_PRI_TDM_RX_0,
  899. .playback_only = 1,
  900. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  901. SND_SOC_DPCM_TRIGGER_POST},
  902. .ops = &msm_common_be_ops,
  903. .ignore_suspend = 1,
  904. .ignore_pmdown_time = 1,
  905. SND_SOC_DAILINK_REG(pri_tdm_rx_0),
  906. },
  907. {
  908. .name = LPASS_BE_PRI_TDM_TX_0,
  909. .stream_name = LPASS_BE_PRI_TDM_TX_0,
  910. .capture_only = 1,
  911. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  912. SND_SOC_DPCM_TRIGGER_POST},
  913. .ops = &msm_common_be_ops,
  914. .ignore_suspend = 1,
  915. SND_SOC_DAILINK_REG(pri_tdm_tx_0),
  916. },
  917. {
  918. .name = LPASS_BE_SEC_TDM_RX_0,
  919. .stream_name = LPASS_BE_SEC_TDM_RX_0,
  920. .playback_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. .ignore_pmdown_time = 1,
  926. SND_SOC_DAILINK_REG(sec_tdm_rx_0),
  927. },
  928. {
  929. .name = LPASS_BE_SEC_TDM_TX_0,
  930. .stream_name = LPASS_BE_SEC_TDM_TX_0,
  931. .capture_only = 1,
  932. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  933. SND_SOC_DPCM_TRIGGER_POST},
  934. .ops = &msm_common_be_ops,
  935. .ignore_suspend = 1,
  936. SND_SOC_DAILINK_REG(sec_tdm_tx_0),
  937. },
  938. {
  939. .name = LPASS_BE_TERT_TDM_RX_0,
  940. .stream_name = LPASS_BE_TERT_TDM_RX_0,
  941. .playback_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. .ignore_pmdown_time = 1,
  947. SND_SOC_DAILINK_REG(tert_tdm_rx_0),
  948. },
  949. {
  950. .name = LPASS_BE_TERT_TDM_TX_0,
  951. .stream_name = LPASS_BE_TERT_TDM_TX_0,
  952. .capture_only = 1,
  953. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  954. SND_SOC_DPCM_TRIGGER_POST},
  955. .ops = &msm_common_be_ops,
  956. .ignore_suspend = 1,
  957. SND_SOC_DAILINK_REG(tert_tdm_tx_0),
  958. },
  959. {
  960. .name = LPASS_BE_QUAT_TDM_RX_0,
  961. .stream_name = LPASS_BE_QUAT_TDM_RX_0,
  962. .playback_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. .ignore_pmdown_time = 1,
  968. SND_SOC_DAILINK_REG(quat_tdm_rx_0),
  969. },
  970. {
  971. .name = LPASS_BE_QUAT_TDM_TX_0,
  972. .stream_name = LPASS_BE_QUAT_TDM_TX_0,
  973. .capture_only = 1,
  974. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  975. SND_SOC_DPCM_TRIGGER_POST},
  976. .ops = &msm_common_be_ops,
  977. .ignore_suspend = 1,
  978. SND_SOC_DAILINK_REG(quat_tdm_tx_0),
  979. },
  980. {
  981. .name = LPASS_BE_QUIN_TDM_RX_0,
  982. .stream_name = LPASS_BE_QUIN_TDM_RX_0,
  983. .playback_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. .ignore_pmdown_time = 1,
  989. SND_SOC_DAILINK_REG(quin_tdm_rx_0),
  990. },
  991. {
  992. .name = LPASS_BE_QUIN_TDM_TX_0,
  993. .stream_name = LPASS_BE_QUIN_TDM_TX_0,
  994. .capture_only = 1,
  995. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  996. SND_SOC_DPCM_TRIGGER_POST},
  997. .ops = &msm_common_be_ops,
  998. .ignore_suspend = 1,
  999. SND_SOC_DAILINK_REG(quin_tdm_tx_0),
  1000. },
  1001. {
  1002. .name = LPASS_BE_SEN_TDM_RX_0,
  1003. .stream_name = LPASS_BE_SEN_TDM_RX_0,
  1004. .playback_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. .ignore_pmdown_time = 1,
  1010. SND_SOC_DAILINK_REG(sen_tdm_rx_0),
  1011. },
  1012. {
  1013. .name = LPASS_BE_SEN_TDM_TX_0,
  1014. .stream_name = LPASS_BE_SEN_TDM_TX_0,
  1015. .capture_only = 1,
  1016. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1017. SND_SOC_DPCM_TRIGGER_POST},
  1018. .ops = &msm_common_be_ops,
  1019. .ignore_suspend = 1,
  1020. SND_SOC_DAILINK_REG(sen_tdm_tx_0),
  1021. },
  1022. {
  1023. .name = LPASS_BE_SEP_TDM_RX_0,
  1024. .stream_name = LPASS_BE_SEP_TDM_RX_0,
  1025. .playback_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. .ignore_pmdown_time = 1,
  1031. SND_SOC_DAILINK_REG(sep_tdm_rx_0),
  1032. },
  1033. {
  1034. .name = LPASS_BE_SEP_TDM_TX_0,
  1035. .stream_name = LPASS_BE_SEP_TDM_TX_0,
  1036. .capture_only = 1,
  1037. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1038. SND_SOC_DPCM_TRIGGER_POST},
  1039. .ops = &msm_common_be_ops,
  1040. .ignore_suspend = 1,
  1041. SND_SOC_DAILINK_REG(sep_tdm_tx_0),
  1042. },
  1043. };
  1044. static struct snd_soc_dai_link msm_kalama_dai_links[
  1045. ARRAY_SIZE(msm_wsa_cdc_dma_be_dai_links) +
  1046. ARRAY_SIZE(msm_wsa2_cdc_dma_be_dai_links) +
  1047. ARRAY_SIZE(msm_wsa_wsa2_cdc_dma_be_dai_links) +
  1048. ARRAY_SIZE(msm_rx_tx_cdc_dma_be_dai_links) +
  1049. ARRAY_SIZE(msm_va_cdc_dma_be_dai_links) +
  1050. ARRAY_SIZE(ext_disp_be_dai_link) +
  1051. ARRAY_SIZE(msm_common_be_dai_links) +
  1052. ARRAY_SIZE(msm_wcn_be_dai_links) +
  1053. ARRAY_SIZE(msm_mi2s_dai_links) +
  1054. ARRAY_SIZE(msm_tdm_dai_links)];
  1055. static int msm_populate_dai_link_component_of_node(
  1056. struct snd_soc_card *card)
  1057. {
  1058. int i, j, index, ret = 0;
  1059. struct device *cdev = card->dev;
  1060. struct snd_soc_dai_link *dai_link = card->dai_link;
  1061. struct device_node *np = NULL;
  1062. int codecs_enabled = 0;
  1063. struct snd_soc_dai_link_component *codecs_comp = NULL;
  1064. if (!cdev) {
  1065. dev_err(cdev, "%s: Sound card device memory NULL\n", __func__);
  1066. return -ENODEV;
  1067. }
  1068. for (i = 0; i < card->num_links; i++) {
  1069. if (dai_link[i].init == NULL)
  1070. dai_link[i].init = &msm_common_dai_link_init;
  1071. /* populate codec_of_node for snd card dai links */
  1072. if (dai_link[i].num_codecs > 0) {
  1073. for (j = 0; j < dai_link[i].num_codecs; j++) {
  1074. if (dai_link[i].codecs[j].of_node ||
  1075. !dai_link[i].codecs[j].name)
  1076. continue;
  1077. index = of_property_match_string(cdev->of_node,
  1078. "asoc-codec-names",
  1079. dai_link[i].codecs[j].name);
  1080. if (index < 0)
  1081. continue;
  1082. np = of_parse_phandle(cdev->of_node,
  1083. "asoc-codec",
  1084. index);
  1085. if (!np) {
  1086. dev_err(cdev, "%s: retrieving phandle for codec %s failed\n",
  1087. __func__,
  1088. dai_link[i].codecs[j].name);
  1089. ret = -ENODEV;
  1090. goto err;
  1091. }
  1092. dai_link[i].codecs[j].of_node = np;
  1093. dai_link[i].codecs[j].name = NULL;
  1094. }
  1095. }
  1096. }
  1097. /* In multi-codec scenario, check if codecs are enabled for this platform */
  1098. for (i = 0; i < card->num_links; i++) {
  1099. codecs_enabled = 0;
  1100. if (dai_link[i].num_codecs > 1) {
  1101. for (j = 0; j < dai_link[i].num_codecs; j++) {
  1102. if (!dai_link[i].codecs[j].of_node)
  1103. continue;
  1104. np = dai_link[i].codecs[j].of_node;
  1105. if (!of_device_is_available(np)) {
  1106. dev_err(cdev, "%s: codec is disabled: %s\n",
  1107. __func__,
  1108. np->full_name);
  1109. dai_link[i].codecs[j].of_node = NULL;
  1110. continue;
  1111. }
  1112. codecs_enabled++;
  1113. }
  1114. if (codecs_enabled > 0 &&
  1115. codecs_enabled < dai_link[i].num_codecs) {
  1116. codecs_comp = devm_kzalloc(cdev,
  1117. sizeof(struct snd_soc_dai_link_component)
  1118. * codecs_enabled, GFP_KERNEL);
  1119. if (!codecs_comp) {
  1120. dev_err(cdev, "%s: %s dailink codec component alloc failed\n",
  1121. __func__, dai_link[i].name);
  1122. ret = -ENOMEM;
  1123. goto err;
  1124. }
  1125. index = 0;
  1126. for (j = 0; j < dai_link[i].num_codecs; j++) {
  1127. if(dai_link[i].codecs[j].of_node) {
  1128. codecs_comp[index].of_node =
  1129. dai_link[i].codecs[j].of_node;
  1130. codecs_comp[index].dai_name =
  1131. dai_link[i].codecs[j].dai_name;
  1132. codecs_comp[index].name = NULL;
  1133. index++;
  1134. }
  1135. }
  1136. dai_link[i].codecs = codecs_comp;
  1137. dai_link[i].num_codecs = codecs_enabled;
  1138. }
  1139. }
  1140. }
  1141. err:
  1142. return ret;
  1143. }
  1144. static int msm_audrx_stub_init(struct snd_soc_pcm_runtime *rtd)
  1145. {
  1146. return 0;
  1147. }
  1148. static int msm_snd_stub_hw_params(struct snd_pcm_substream *substream,
  1149. struct snd_pcm_hw_params *params)
  1150. {
  1151. return 0;
  1152. }
  1153. static struct snd_soc_ops msm_stub_be_ops = {
  1154. .hw_params = msm_snd_stub_hw_params,
  1155. };
  1156. struct snd_soc_card snd_soc_card_stub_msm = {
  1157. .name = "kalama-stub-snd-card",
  1158. };
  1159. static struct snd_soc_dai_link msm_stub_be_dai_links[] = {
  1160. /* Backend DAI Links */
  1161. {
  1162. .name = LPASS_BE_PRI_AUXPCM_RX,
  1163. .stream_name = LPASS_BE_PRI_AUXPCM_RX,
  1164. .playback_only = 1,
  1165. .init = &msm_audrx_stub_init,
  1166. .ignore_pmdown_time = 1,
  1167. .ignore_suspend = 1,
  1168. .ops = &msm_stub_be_ops,
  1169. SND_SOC_DAILINK_REG(auxpcm_rx),
  1170. },
  1171. {
  1172. .name = LPASS_BE_PRI_AUXPCM_TX,
  1173. .stream_name = LPASS_BE_PRI_AUXPCM_TX,
  1174. .capture_only = 1,
  1175. .ignore_suspend = 1,
  1176. .ops = &msm_stub_be_ops,
  1177. SND_SOC_DAILINK_REG(auxpcm_tx),
  1178. },
  1179. };
  1180. static struct snd_soc_dai_link msm_stub_dai_links[
  1181. ARRAY_SIZE(msm_stub_be_dai_links)];
  1182. static const struct of_device_id kalama_asoc_machine_of_match[] = {
  1183. { .compatible = "qcom,kalama-asoc-snd",
  1184. .data = "codec"},
  1185. { .compatible = "qcom,kalama-asoc-snd-stub",
  1186. .data = "stub_codec"},
  1187. {},
  1188. };
  1189. static int msm_snd_card_late_probe(struct snd_soc_card *card)
  1190. {
  1191. struct snd_soc_component *component = NULL;
  1192. struct snd_soc_pcm_runtime *rtd;
  1193. int ret = 0;
  1194. void *mbhc_calibration;
  1195. rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
  1196. if (!rtd) {
  1197. dev_err(card->dev,
  1198. "%s: snd_soc_get_pcm_runtime for %s failed!\n",
  1199. __func__, card->dai_link[0]);
  1200. return -EINVAL;
  1201. }
  1202. component = snd_soc_rtdcom_lookup(rtd, WCD938X_DRV_NAME);
  1203. if (!component) {
  1204. pr_err("%s component is NULL\n", __func__);
  1205. return -EINVAL;
  1206. }
  1207. mbhc_calibration = def_wcd_mbhc_cal();
  1208. if (!mbhc_calibration)
  1209. return -ENOMEM;
  1210. wcd_mbhc_cfg.calibration = mbhc_calibration;
  1211. ret = wcd938x_mbhc_hs_detect(component, &wcd_mbhc_cfg);
  1212. if (ret) {
  1213. dev_err(component->dev, "%s: mbhc hs detect failed, err:%d\n",
  1214. __func__, ret);
  1215. goto err_hs_detect;
  1216. }
  1217. return 0;
  1218. err_hs_detect:
  1219. kfree(mbhc_calibration);
  1220. return ret;
  1221. }
  1222. static struct snd_soc_card *populate_snd_card_dailinks(struct device *dev, int wsa_max_devs)
  1223. {
  1224. struct snd_soc_card *card = NULL;
  1225. struct snd_soc_dai_link *dailink = NULL;
  1226. int total_links = 0;
  1227. int rc = 0;
  1228. u32 val = 0;
  1229. const struct of_device_id *match;
  1230. match = of_match_node(kalama_asoc_machine_of_match, dev->of_node);
  1231. if (!match) {
  1232. dev_err(dev, "%s: No DT match found for sound card\n",
  1233. __func__);
  1234. return NULL;
  1235. }
  1236. if (!strcmp(match->data, "codec")) {
  1237. card = &snd_soc_card_kalama_msm;
  1238. /* late probe uses dai link at index '0' to get wcd component */
  1239. memcpy(msm_kalama_dai_links + total_links,
  1240. msm_rx_tx_cdc_dma_be_dai_links,
  1241. sizeof(msm_rx_tx_cdc_dma_be_dai_links));
  1242. total_links +=
  1243. ARRAY_SIZE(msm_rx_tx_cdc_dma_be_dai_links);
  1244. switch (wsa_max_devs) {
  1245. case MONO_SPEAKER:
  1246. case STEREO_SPEAKER:
  1247. memcpy(msm_kalama_dai_links + total_links,
  1248. msm_wsa_cdc_dma_be_dai_links,
  1249. sizeof(msm_wsa_cdc_dma_be_dai_links));
  1250. total_links += ARRAY_SIZE(msm_wsa_cdc_dma_be_dai_links);
  1251. break;
  1252. case QUAD_SPEAKER:
  1253. memcpy(msm_kalama_dai_links + total_links,
  1254. msm_wsa2_cdc_dma_be_dai_links,
  1255. sizeof(msm_wsa2_cdc_dma_be_dai_links));
  1256. total_links += ARRAY_SIZE(msm_wsa2_cdc_dma_be_dai_links);
  1257. memcpy(msm_kalama_dai_links + total_links,
  1258. msm_wsa_wsa2_cdc_dma_be_dai_links,
  1259. sizeof(msm_wsa_wsa2_cdc_dma_be_dai_links));
  1260. total_links += ARRAY_SIZE(msm_wsa_wsa2_cdc_dma_be_dai_links);
  1261. break;
  1262. default:
  1263. dev_dbg(dev,
  1264. "%s: Unexpected number of WSAs, wsa_max_devs: %d\n",
  1265. __func__, wsa_max_devs);
  1266. break;
  1267. }
  1268. memcpy(msm_kalama_dai_links + total_links,
  1269. msm_va_cdc_dma_be_dai_links,
  1270. sizeof(msm_va_cdc_dma_be_dai_links));
  1271. total_links += ARRAY_SIZE(msm_va_cdc_dma_be_dai_links);
  1272. memcpy(msm_kalama_dai_links + total_links,
  1273. msm_common_be_dai_links,
  1274. sizeof(msm_common_be_dai_links));
  1275. total_links += ARRAY_SIZE(msm_common_be_dai_links);
  1276. rc = of_property_read_u32(dev->of_node,
  1277. "qcom,mi2s-audio-intf", &val);
  1278. if (!rc && val) {
  1279. memcpy(msm_kalama_dai_links + total_links,
  1280. msm_mi2s_dai_links,
  1281. sizeof(msm_mi2s_dai_links));
  1282. total_links += ARRAY_SIZE(msm_mi2s_dai_links);
  1283. }
  1284. rc = of_property_read_u32(dev->of_node,
  1285. "qcom,tdm-audio-intf", &val);
  1286. if (!rc && val) {
  1287. memcpy(msm_kalama_dai_links + total_links,
  1288. msm_tdm_dai_links,
  1289. sizeof(msm_tdm_dai_links));
  1290. total_links += ARRAY_SIZE(msm_tdm_dai_links);
  1291. }
  1292. rc = of_property_read_u32(dev->of_node,
  1293. "qcom,ext-disp-audio-rx", &val);
  1294. if (!rc && val) {
  1295. dev_dbg(dev, "%s(): ext disp audio support present\n",
  1296. __func__);
  1297. memcpy(msm_kalama_dai_links + total_links,
  1298. ext_disp_be_dai_link,
  1299. sizeof(ext_disp_be_dai_link));
  1300. total_links += ARRAY_SIZE(ext_disp_be_dai_link);
  1301. }
  1302. rc = of_property_read_u32(dev->of_node, "qcom,wcn-bt", &val);
  1303. if (!rc && val) {
  1304. dev_dbg(dev, "%s(): WCN BT support present\n",
  1305. __func__);
  1306. memcpy(msm_kalama_dai_links + total_links,
  1307. msm_wcn_be_dai_links,
  1308. sizeof(msm_wcn_be_dai_links));
  1309. total_links += ARRAY_SIZE(msm_wcn_be_dai_links);
  1310. }
  1311. dailink = msm_kalama_dai_links;
  1312. } else if(!strcmp(match->data, "stub_codec")) {
  1313. card = &snd_soc_card_stub_msm;
  1314. memcpy(msm_stub_dai_links,
  1315. msm_stub_be_dai_links,
  1316. sizeof(msm_stub_be_dai_links));
  1317. dailink = msm_stub_dai_links;
  1318. total_links = ARRAY_SIZE(msm_stub_be_dai_links);
  1319. }
  1320. if (card) {
  1321. card->dai_link = dailink;
  1322. card->num_links = total_links;
  1323. if (!strcmp(match->data, "codec"))
  1324. card->late_probe = msm_snd_card_late_probe;
  1325. }
  1326. return card;
  1327. }
  1328. static int msm_int_wsa_init(struct snd_soc_pcm_runtime *rtd)
  1329. {
  1330. u8 spkleft_ports[WSA884X_MAX_SWR_PORTS] = {0, 1, 2, 3, 4, 5};
  1331. u8 spkright_ports[WSA884X_MAX_SWR_PORTS] = {0, 1, 2, 3, 4, 5};
  1332. u8 spkleft_port_types[WSA884X_MAX_SWR_PORTS] = {SPKR_L, SPKR_L_COMP,
  1333. SPKR_L_BOOST, PBR, SPKR_L_VI, CPS};
  1334. u8 spkright_port_types[WSA884X_MAX_SWR_PORTS] = {SPKR_R, SPKR_R_COMP,
  1335. SPKR_R_BOOST, PBR, SPKR_R_VI, CPS};
  1336. unsigned int ch_rate[WSA884X_MAX_SWR_PORTS] = {SWR_CLK_RATE_2P4MHZ, SWR_CLK_RATE_0P6MHZ,
  1337. SWR_CLK_RATE_0P3MHZ, SWR_CLK_RATE_48KHZ,
  1338. SWR_CLK_RATE_1P2MHZ, SWR_CLK_RATE_24KHZ};
  1339. unsigned int ch_mask[WSA884X_MAX_SWR_PORTS] = {0x1, 0xF, 0x3, 0x1, 0x3, 0x3};
  1340. struct snd_soc_component *component = NULL;
  1341. struct msm_asoc_mach_data *pdata =
  1342. snd_soc_card_get_drvdata(rtd->card);
  1343. if (pdata->wsa_max_devs > 0) {
  1344. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.1");
  1345. if (!component) {
  1346. pr_err("%s: wsa-codec.1 component is NULL\n", __func__);
  1347. return -EINVAL;
  1348. }
  1349. wsa884x_set_channel_map(component, &spkleft_ports[0],
  1350. WSA884X_MAX_SWR_PORTS, &ch_mask[0],
  1351. &ch_rate[0], &spkleft_port_types[0]);
  1352. wsa884x_codec_info_create_codec_entry(pdata->codec_root,
  1353. component);
  1354. }
  1355. /* If current platform has more than one WSA */
  1356. if (pdata->wsa_max_devs > 1) {
  1357. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.2");
  1358. if (!component) {
  1359. pr_err("%s: wsa-codec.2 component is NULL\n", __func__);
  1360. return -EINVAL;
  1361. }
  1362. wsa884x_set_channel_map(component, &spkright_ports[0],
  1363. WSA884X_MAX_SWR_PORTS, &ch_mask[0],
  1364. &ch_rate[0], &spkright_port_types[0]);
  1365. wsa884x_codec_info_create_codec_entry(pdata->codec_root,
  1366. component);
  1367. }
  1368. if (pdata->wsa_max_devs > 2) {
  1369. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.3");
  1370. if (!component) {
  1371. pr_err("%s: wsa-codec.3 component is NULL\n", __func__);
  1372. return -EINVAL;
  1373. }
  1374. wsa884x_set_channel_map(component, &spkleft_ports[0],
  1375. WSA884X_MAX_SWR_PORTS, &ch_mask[0],
  1376. &ch_rate[0], &spkleft_port_types[0]);
  1377. wsa884x_codec_info_create_codec_entry(pdata->codec_root,
  1378. component);
  1379. }
  1380. if (pdata->wsa_max_devs > 3) {
  1381. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.4");
  1382. if (!component) {
  1383. pr_err("%s: wsa-codec.4 component is NULL\n", __func__);
  1384. return -EINVAL;
  1385. }
  1386. wsa884x_set_channel_map(component, &spkright_ports[0],
  1387. WSA884X_MAX_SWR_PORTS, &ch_mask[0],
  1388. &ch_rate[0], &spkright_port_types[0]);
  1389. wsa884x_codec_info_create_codec_entry(pdata->codec_root,
  1390. component);
  1391. }
  1392. msm_common_dai_link_init(rtd);
  1393. return 0;
  1394. }
  1395. static int msm_rx_tx_codec_init(struct snd_soc_pcm_runtime *rtd)
  1396. {
  1397. int codec_variant = -1;
  1398. struct snd_soc_component *component = NULL;
  1399. struct snd_soc_component *lpass_cdc_component = NULL;
  1400. struct snd_soc_dapm_context *dapm = NULL;
  1401. struct snd_info_entry *entry = NULL;
  1402. struct snd_card *card = NULL;
  1403. struct msm_asoc_mach_data *pdata =
  1404. snd_soc_card_get_drvdata(rtd->card);
  1405. int ret = 0;
  1406. lpass_cdc_component = snd_soc_rtdcom_lookup(rtd, "lpass-cdc");
  1407. if (!lpass_cdc_component) {
  1408. pr_err("%s: could not find component for lpass-cdc\n",
  1409. __func__);
  1410. return ret;
  1411. }
  1412. dapm = snd_soc_component_get_dapm(lpass_cdc_component);
  1413. snd_soc_dapm_new_controls(dapm, msm_int_dapm_widgets,
  1414. ARRAY_SIZE(msm_int_dapm_widgets));
  1415. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic0");
  1416. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic1");
  1417. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic2");
  1418. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic3");
  1419. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic4");
  1420. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic5");
  1421. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic6");
  1422. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic7");
  1423. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic1");
  1424. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic2");
  1425. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic3");
  1426. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic4");
  1427. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic5");
  1428. lpass_cdc_set_port_map(lpass_cdc_component, ARRAY_SIZE(sm_port_map), sm_port_map);
  1429. card = rtd->card->snd_card;
  1430. if (!pdata->codec_root) {
  1431. entry = msm_snd_info_create_subdir(card->module, "codecs",
  1432. card->proc_root);
  1433. if (!entry) {
  1434. pr_debug("%s: Cannot create codecs module entry\n",
  1435. __func__);
  1436. return ret;
  1437. }
  1438. pdata->codec_root = entry;
  1439. }
  1440. lpass_cdc_info_create_codec_entry(pdata->codec_root, lpass_cdc_component);
  1441. lpass_cdc_register_wake_irq(lpass_cdc_component, false);
  1442. if (pdata->wcd_disabled)
  1443. goto done;
  1444. component = snd_soc_rtdcom_lookup(rtd, WCD938X_DRV_NAME);
  1445. if (!component) {
  1446. pr_err("%s could not find component for %s\n",
  1447. __func__, WCD938X_DRV_NAME);
  1448. return -EINVAL;
  1449. }
  1450. dapm = snd_soc_component_get_dapm(component);
  1451. card = component->card->snd_card;
  1452. snd_soc_dapm_ignore_suspend(dapm, "EAR");
  1453. snd_soc_dapm_ignore_suspend(dapm, "AUX");
  1454. snd_soc_dapm_ignore_suspend(dapm, "HPHL");
  1455. snd_soc_dapm_ignore_suspend(dapm, "HPHR");
  1456. snd_soc_dapm_ignore_suspend(dapm, "AMIC1");
  1457. snd_soc_dapm_ignore_suspend(dapm, "AMIC2");
  1458. snd_soc_dapm_ignore_suspend(dapm, "AMIC3");
  1459. snd_soc_dapm_ignore_suspend(dapm, "AMIC4");
  1460. snd_soc_dapm_sync(dapm);
  1461. pdata = snd_soc_card_get_drvdata(component->card);
  1462. if (!pdata->codec_root) {
  1463. entry = msm_snd_info_create_subdir(card->module, "codecs",
  1464. card->proc_root);
  1465. if (!entry) {
  1466. dev_dbg(component->dev, "%s: Cannot create codecs module entry\n",
  1467. __func__);
  1468. return 0;
  1469. }
  1470. pdata->codec_root = entry;
  1471. }
  1472. wcd938x_info_create_codec_entry(pdata->codec_root, component);
  1473. codec_variant = wcd938x_get_codec_variant(component);
  1474. dev_dbg(component->dev, "%s: variant %d\n", __func__, codec_variant);
  1475. if (codec_variant == WCD9385)
  1476. ret = lpass_cdc_rx_set_fir_capability(lpass_cdc_component, true);
  1477. else
  1478. ret = lpass_cdc_rx_set_fir_capability(lpass_cdc_component, false);
  1479. if (ret < 0) {
  1480. dev_err(component->dev, "%s: set fir capability failed: %d\n",
  1481. __func__, ret);
  1482. return ret;
  1483. }
  1484. done:
  1485. codec_reg_done = true;
  1486. msm_common_dai_link_init(rtd);
  1487. return ret;
  1488. }
  1489. static int kalama_ssr_enable(struct device *dev, void *data)
  1490. {
  1491. struct platform_device *pdev = to_platform_device(dev);
  1492. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1493. struct snd_soc_pcm_runtime *rtd = NULL, *rtd_wcd = NULL, *rtd_wsa = NULL;
  1494. struct msm_asoc_mach_data *pdata = NULL;
  1495. int ret = 0;
  1496. if (!card) {
  1497. dev_err(dev, "%s: card is NULL\n", __func__);
  1498. ret = -EINVAL;
  1499. goto err;
  1500. }
  1501. if (!strcmp(card->name, "kalama-stub-snd-card")) {
  1502. /* TODO */
  1503. dev_dbg(dev, "%s: TODO \n", __func__);
  1504. }
  1505. snd_card_notify_user(SND_CARD_STATUS_ONLINE);
  1506. dev_dbg(dev, "%s: setting snd_card to ONLINE\n", __func__);
  1507. pdata = snd_soc_card_get_drvdata(card);
  1508. if (!pdata) {
  1509. dev_dbg(dev, "%s: pdata is NULL \n", __func__);
  1510. goto err;
  1511. }
  1512. rtd_wcd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
  1513. if (!rtd_wcd) {
  1514. dev_dbg(dev,
  1515. "%s: snd_soc_get_pcm_runtime for %s failed!\n",
  1516. __func__, card->dai_link[0]);
  1517. }
  1518. if (pdata->wsa_max_devs > 0) {
  1519. rtd_wsa = snd_soc_get_pcm_runtime(card,
  1520. &card->dai_link[ARRAY_SIZE(msm_rx_tx_cdc_dma_be_dai_links)]);
  1521. if (!rtd_wsa) {
  1522. dev_dbg(dev,
  1523. "%s: snd_soc_get_pcm_runtime for %s failed!\n",
  1524. __func__, card->dai_link[ARRAY_SIZE(msm_rx_tx_cdc_dma_be_dai_links)]);
  1525. }
  1526. }
  1527. /* set UPD configuration */
  1528. if(!pdata->upd_config.backend_used) {
  1529. dev_dbg(dev,
  1530. "%s: upd- backend_used is NULL\n", __func__);
  1531. goto err;
  1532. }
  1533. if (!strcmp(pdata->upd_config.backend_used, "wsa")) {
  1534. if (!rtd_wsa)
  1535. goto err;
  1536. else
  1537. rtd = rtd_wsa;
  1538. } else if(!strcmp(pdata->upd_config.backend_used, "wcd")) {
  1539. if (!rtd_wcd &&!pdata->wcd_disabled)
  1540. goto err;
  1541. else
  1542. rtd = rtd_wcd;
  1543. } else {
  1544. dev_err(card->dev, "%s: Invalid backend to set UPD config\n",
  1545. __func__);
  1546. goto err;
  1547. }
  1548. msm_set_upd_config(rtd);
  1549. err:
  1550. return ret;
  1551. }
  1552. static void kalama_ssr_disable(struct device *dev, void *data)
  1553. {
  1554. struct platform_device *pdev = to_platform_device(dev);
  1555. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1556. if (!card) {
  1557. dev_err(dev, "%s: card is NULL\n", __func__);
  1558. return;
  1559. }
  1560. dev_dbg(dev, "%s: setting snd_card to OFFLINE\n", __func__);
  1561. snd_card_notify_user(SND_CARD_STATUS_OFFLINE);
  1562. if (!strcmp(card->name, "kalama-stub-snd-card")) {
  1563. /* TODO */
  1564. dev_dbg(dev, "%s: TODO \n", __func__);
  1565. }
  1566. }
  1567. static const struct snd_event_ops kalama_ssr_ops = {
  1568. .enable = kalama_ssr_enable,
  1569. .disable = kalama_ssr_disable,
  1570. };
  1571. static int msm_audio_ssr_compare(struct device *dev, void *data)
  1572. {
  1573. struct device_node *node = data;
  1574. dev_dbg(dev, "%s: dev->of_node = 0x%p, node = 0x%p\n",
  1575. __func__, dev->of_node, node);
  1576. return (dev->of_node && dev->of_node == node);
  1577. }
  1578. static int msm_audio_ssr_register(struct device *dev)
  1579. {
  1580. struct device_node *np = dev->of_node;
  1581. struct snd_event_clients *ssr_clients = NULL;
  1582. struct device_node *node = NULL;
  1583. int ret = 0;
  1584. int i = 0;
  1585. for (i = 0; ; i++) {
  1586. node = of_parse_phandle(np, "qcom,msm_audio_ssr_devs", i);
  1587. if (!node)
  1588. break;
  1589. snd_event_mstr_add_client(&ssr_clients,
  1590. msm_audio_ssr_compare, node);
  1591. }
  1592. ret = snd_event_master_register(dev, &kalama_ssr_ops,
  1593. ssr_clients, NULL);
  1594. if (!ret)
  1595. snd_event_notify(dev, SND_EVENT_UP);
  1596. return ret;
  1597. }
  1598. struct msm_common_pdata *msm_common_get_pdata(struct snd_soc_card *card)
  1599. {
  1600. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  1601. if (!pdata)
  1602. return NULL;
  1603. return pdata->common_pdata;
  1604. }
  1605. void msm_common_set_pdata(struct snd_soc_card *card,
  1606. struct msm_common_pdata *common_pdata)
  1607. {
  1608. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  1609. if (!pdata)
  1610. return;
  1611. pdata->common_pdata = common_pdata;
  1612. }
  1613. static int msm_asoc_machine_probe(struct platform_device *pdev)
  1614. {
  1615. struct snd_soc_card *card = NULL;
  1616. struct msm_asoc_mach_data *pdata = NULL;
  1617. int ret = 0;
  1618. struct clk *lpass_audio_hw_vote = NULL;
  1619. const struct of_device_id *match;
  1620. if (!pdev->dev.of_node) {
  1621. dev_err(&pdev->dev, "%s: No platform supplied from device tree\n", __func__);
  1622. return -EINVAL;
  1623. }
  1624. pdata = devm_kzalloc(&pdev->dev,
  1625. sizeof(struct msm_asoc_mach_data), GFP_KERNEL);
  1626. if (!pdata)
  1627. return -ENOMEM;
  1628. of_property_read_u32(pdev->dev.of_node,
  1629. "qcom,wcd-disabled",
  1630. &pdata->wcd_disabled);
  1631. /* Get maximum WSA device count for this platform */
  1632. ret = of_property_read_u32(pdev->dev.of_node,
  1633. "qcom,wsa-max-devs", &pdata->wsa_max_devs);
  1634. if (ret) {
  1635. dev_info(&pdev->dev,
  1636. "%s: wsa-max-devs property missing in DT %s, ret = %d\n",
  1637. __func__, pdev->dev.of_node->full_name, ret);
  1638. pdata->wsa_max_devs = 0;
  1639. }
  1640. card = populate_snd_card_dailinks(&pdev->dev, pdata->wsa_max_devs);
  1641. if (!card) {
  1642. dev_err(&pdev->dev, "%s: Card uninitialized\n", __func__);
  1643. ret = -EINVAL;
  1644. goto err;
  1645. }
  1646. match = of_match_node(kalama_asoc_machine_of_match, pdev->dev.of_node);
  1647. if (!match) {
  1648. dev_err(&pdev->dev, "%s: No DT match found for sound card\n",
  1649. __func__);
  1650. ret = -EINVAL;
  1651. goto err;
  1652. }
  1653. card->dev = &pdev->dev;
  1654. platform_set_drvdata(pdev, card);
  1655. snd_soc_card_set_drvdata(card, pdata);
  1656. ret = snd_soc_of_parse_card_name(card, "qcom,model");
  1657. if (ret) {
  1658. dev_err(&pdev->dev, "%s: parse card name failed, err:%d\n",
  1659. __func__, ret);
  1660. goto err;
  1661. }
  1662. if(!strcmp(match->data, "codec")) {
  1663. ret = snd_soc_of_parse_audio_routing(card, "qcom,audio-routing");
  1664. if (ret) {
  1665. dev_err(&pdev->dev, "%s: parse audio routing failed, err:%d\n",
  1666. __func__, ret);
  1667. goto err;
  1668. }
  1669. }
  1670. ret = msm_populate_dai_link_component_of_node(card);
  1671. if (ret) {
  1672. ret = -EPROBE_DEFER;
  1673. goto err;
  1674. }
  1675. /* parse upd configuration */
  1676. msm_parse_upd_configuration(pdev, pdata);
  1677. ret = devm_snd_soc_register_card(&pdev->dev, card);
  1678. if (ret == -EPROBE_DEFER) {
  1679. if (codec_reg_done)
  1680. ret = -EINVAL;
  1681. goto err;
  1682. } else if (ret) {
  1683. dev_err(&pdev->dev, "%s: snd_soc_register_card failed (%d)\n",
  1684. __func__, ret);
  1685. goto err;
  1686. }
  1687. dev_info(&pdev->dev, "%s: Sound card %s registered\n",
  1688. __func__, card->name);
  1689. if (wcd_mbhc_cfg.enable_usbc_analog)
  1690. wcd_mbhc_cfg.swap_gnd_mic = msm_usbc_swap_gnd_mic;
  1691. pdata->fsa_handle = of_parse_phandle(pdev->dev.of_node,
  1692. "fsa4480-i2c-handle", 0);
  1693. if (!pdata->fsa_handle)
  1694. dev_dbg(&pdev->dev, "property %s not detected in node %s\n",
  1695. "fsa4480-i2c-handle", pdev->dev.of_node->full_name);
  1696. pdata->dmic01_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1697. "qcom,cdc-dmic01-gpios",
  1698. 0);
  1699. pdata->dmic23_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1700. "qcom,cdc-dmic23-gpios",
  1701. 0);
  1702. pdata->dmic45_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1703. "qcom,cdc-dmic45-gpios",
  1704. 0);
  1705. pdata->dmic67_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1706. "qcom,cdc-dmic67-gpios",
  1707. 0);
  1708. if (pdata->dmic01_gpio_p)
  1709. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic01_gpio_p, false);
  1710. if (pdata->dmic23_gpio_p)
  1711. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic23_gpio_p, false);
  1712. if (pdata->dmic45_gpio_p)
  1713. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic45_gpio_p, false);
  1714. if (pdata->dmic67_gpio_p)
  1715. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic67_gpio_p, false);
  1716. msm_common_snd_init(pdev, card);
  1717. /* Register LPASS audio hw vote */
  1718. lpass_audio_hw_vote = devm_clk_get(&pdev->dev, "lpass_audio_hw_vote");
  1719. if (IS_ERR(lpass_audio_hw_vote)) {
  1720. ret = PTR_ERR(lpass_audio_hw_vote);
  1721. dev_dbg(&pdev->dev, "%s: clk get %s failed %d\n",
  1722. __func__, "lpass_audio_hw_vote", ret);
  1723. lpass_audio_hw_vote = NULL;
  1724. ret = 0;
  1725. }
  1726. pdata->lpass_audio_hw_vote = lpass_audio_hw_vote;
  1727. pdata->core_audio_vote_count = 0;
  1728. ret = msm_audio_ssr_register(&pdev->dev);
  1729. if (ret)
  1730. pr_err("%s: Registration with SND event FWK failed ret = %d\n",
  1731. __func__, ret);
  1732. is_initial_boot = true;
  1733. /* change card status to ONLINE */
  1734. dev_dbg(&pdev->dev, "%s: setting snd_card to ONLINE\n", __func__);
  1735. snd_card_set_card_status(SND_CARD_STATUS_ONLINE);
  1736. return 0;
  1737. err:
  1738. devm_kfree(&pdev->dev, pdata);
  1739. return ret;
  1740. }
  1741. static int msm_asoc_machine_remove(struct platform_device *pdev)
  1742. {
  1743. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1744. struct msm_asoc_mach_data *pdata = NULL;
  1745. struct msm_common_pdata *common_pdata = NULL;
  1746. if (card)
  1747. pdata = snd_soc_card_get_drvdata(card);
  1748. if (pdata)
  1749. common_pdata = pdata->common_pdata;
  1750. msm_common_snd_deinit(common_pdata);
  1751. snd_event_master_deregister(&pdev->dev);
  1752. snd_soc_unregister_card(card);
  1753. return 0;
  1754. }
  1755. static struct platform_driver kalama_asoc_machine_driver = {
  1756. .driver = {
  1757. .name = DRV_NAME,
  1758. .owner = THIS_MODULE,
  1759. .pm = &snd_soc_pm_ops,
  1760. .of_match_table = kalama_asoc_machine_of_match,
  1761. .suppress_bind_attrs = true,
  1762. },
  1763. .probe = msm_asoc_machine_probe,
  1764. .remove = msm_asoc_machine_remove,
  1765. };
  1766. static int __init msm_asoc_machine_init(void)
  1767. {
  1768. snd_card_sysfs_init();
  1769. return platform_driver_register(&kalama_asoc_machine_driver);
  1770. }
  1771. module_init(msm_asoc_machine_init);
  1772. static void __exit msm_asoc_machine_exit(void)
  1773. {
  1774. platform_driver_unregister(&kalama_asoc_machine_driver);
  1775. }
  1776. module_exit(msm_asoc_machine_exit);
  1777. MODULE_SOFTDEP("pre: bt_fm_slim");
  1778. MODULE_DESCRIPTION("ALSA SoC msm");
  1779. MODULE_LICENSE("GPL v2");
  1780. MODULE_ALIAS("platform:" DRV_NAME);
  1781. MODULE_DEVICE_TABLE(of, kalama_asoc_machine_of_match);