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