waipio.c 37 KB

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