lahaina.c 41 KB

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