lahaina.c 41 KB

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