lahaina.c 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484
  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. .dpcm_capture = 1,
  343. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  344. SND_SOC_DPCM_TRIGGER_POST},
  345. .ignore_suspend = 1,
  346. SND_SOC_DAILINK_REG(proxy_tx),
  347. },
  348. /* Proxy Rx BACK END DAI Link */
  349. {
  350. .name = LPASS_BE_RT_PROXY_PCM_RX,
  351. .stream_name = LPASS_BE_RT_PROXY_PCM_RX,
  352. #if IS_ENABLED(CONFIG_AUDIO_QGKI)
  353. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  354. #endif /* CONFIG_AUDIO_QGKI */
  355. .dpcm_playback = 1,
  356. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  357. SND_SOC_DPCM_TRIGGER_POST},
  358. .ignore_pmdown_time = 1,
  359. .ignore_suspend = 1,
  360. SND_SOC_DAILINK_REG(proxy_rx),
  361. },
  362. {
  363. .name = LPASS_BE_USB_AUDIO_RX,
  364. .stream_name = LPASS_BE_USB_AUDIO_RX,
  365. #if IS_ENABLED(CONFIG_AUDIO_QGKI)
  366. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  367. #endif /* CONFIG_AUDIO_QGKI */
  368. .dpcm_playback = 1,
  369. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  370. SND_SOC_DPCM_TRIGGER_POST},
  371. .ignore_pmdown_time = 1,
  372. .ignore_suspend = 1,
  373. .ops = &msm_common_be_ops,
  374. SND_SOC_DAILINK_REG(usb_audio_rx),
  375. },
  376. {
  377. .name = LPASS_BE_USB_AUDIO_TX,
  378. .stream_name = LPASS_BE_USB_AUDIO_TX,
  379. #if IS_ENABLED(CONFIG_AUDIO_QGKI)
  380. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  381. #endif /* CONFIG_AUDIO_QGKI */
  382. .dpcm_capture = 1,
  383. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  384. SND_SOC_DPCM_TRIGGER_POST},
  385. .ignore_suspend = 1,
  386. .ops = &msm_common_be_ops,
  387. SND_SOC_DAILINK_REG(usb_audio_tx),
  388. },
  389. };
  390. static struct snd_soc_dai_link msm_wcn_be_dai_links[] = {
  391. {
  392. .name = LPASS_BE_SLIMBUS_7_RX,
  393. .stream_name = LPASS_BE_SLIMBUS_7_RX,
  394. #if IS_ENABLED(CONFIG_AUDIO_QGKI)
  395. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  396. #endif /* CONFIG_AUDIO_QGKI */
  397. .dpcm_playback = 1,
  398. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  399. SND_SOC_DPCM_TRIGGER_POST},
  400. .init = &msm_wcn_init,
  401. .ops = &msm_common_be_ops,
  402. /* dai link has playback support */
  403. .ignore_pmdown_time = 1,
  404. .ignore_suspend = 1,
  405. SND_SOC_DAILINK_REG(slimbus_7_rx),
  406. },
  407. {
  408. .name = LPASS_BE_SLIMBUS_7_TX,
  409. .stream_name = LPASS_BE_SLIMBUS_7_TX,
  410. #if IS_ENABLED(CONFIG_AUDIO_QGKI)
  411. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  412. #endif /* CONFIG_AUDIO_QGKI */
  413. .dpcm_capture = 1,
  414. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  415. SND_SOC_DPCM_TRIGGER_POST},
  416. .ops = &msm_common_be_ops,
  417. .ignore_suspend = 1,
  418. SND_SOC_DAILINK_REG(slimbus_7_tx),
  419. },
  420. };
  421. #if IS_ENABLED(CONFIG_AUDIO_QGKI)
  422. static struct snd_soc_dai_link ext_disp_be_dai_link[] = {
  423. /* DISP PORT BACK END DAI Link */
  424. {
  425. .name = LPASS_BE_DISPLAY_PORT_RX,
  426. .stream_name = LPASS_BE_DISPLAY_PORT_RX,
  427. #if IS_ENABLED(CONFIG_AUDIO_QGKI)
  428. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  429. #endif /* CONFIG_AUDIO_QGKI */
  430. .dpcm_playback = 1,
  431. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  432. SND_SOC_DPCM_TRIGGER_POST},
  433. .ignore_pmdown_time = 1,
  434. .ignore_suspend = 1,
  435. SND_SOC_DAILINK_REG(display_port),
  436. },
  437. #if 0
  438. /* DISP PORT 1 BACK END DAI Link */
  439. {
  440. .name = LPASS_BE_DISPLAY_PORT1,
  441. .stream_name = LPASS_BE_DISPLAY_PORT1,
  442. #if IS_ENABLED(CONFIG_AUDIO_QGKI)
  443. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  444. #endif /* CONFIG_AUDIO_QGKI */
  445. .dpcm_playback = 1,
  446. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  447. SND_SOC_DPCM_TRIGGER_POST},
  448. .ignore_pmdown_time = 1,
  449. .ignore_suspend = 1,
  450. SND_SOC_DAILINK_REG(display_port1),
  451. },
  452. #endif
  453. };
  454. #endif
  455. static struct snd_soc_dai_link msm_wsa_cdc_dma_be_dai_links[] = {
  456. /* WSA CDC DMA Backend DAI Links */
  457. {
  458. .name = LPASS_BE_WSA_CDC_DMA_RX_0,
  459. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_0,
  460. #if IS_ENABLED(CONFIG_AUDIO_QGKI)
  461. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  462. #endif /* CONFIG_AUDIO_QGKI */
  463. .dpcm_playback = 1,
  464. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  465. SND_SOC_DPCM_TRIGGER_POST},
  466. .ignore_pmdown_time = 1,
  467. .ignore_suspend = 1,
  468. .ops = &msm_common_be_ops,
  469. SND_SOC_DAILINK_REG(wsa_dma_rx0),
  470. .init = &msm_int_audrx_init,
  471. },
  472. {
  473. .name = LPASS_BE_WSA_CDC_DMA_RX_1,
  474. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_1,
  475. #if IS_ENABLED(CONFIG_AUDIO_QGKI)
  476. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  477. #endif /* CONFIG_AUDIO_QGKI */
  478. .dpcm_playback = 1,
  479. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  480. SND_SOC_DPCM_TRIGGER_POST},
  481. .ignore_pmdown_time = 1,
  482. .ignore_suspend = 1,
  483. .ops = &msm_common_be_ops,
  484. SND_SOC_DAILINK_REG(wsa_dma_rx1),
  485. },
  486. {
  487. .name = LPASS_BE_WSA_CDC_DMA_TX_1,
  488. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_1,
  489. #if IS_ENABLED(CONFIG_AUDIO_QGKI)
  490. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  491. #endif /* CONFIG_AUDIO_QGKI */
  492. .dpcm_capture = 1,
  493. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  494. SND_SOC_DPCM_TRIGGER_POST},
  495. .ignore_suspend = 1,
  496. .ops = &msm_common_be_ops,
  497. SND_SOC_DAILINK_REG(wsa_dma_tx1),
  498. },
  499. };
  500. static struct snd_soc_dai_link msm_rx_tx_cdc_dma_be_dai_links[] = {
  501. /* RX CDC DMA Backend DAI Links */
  502. {
  503. .name = LPASS_BE_RX_CDC_DMA_RX_0,
  504. .stream_name = LPASS_BE_RX_CDC_DMA_RX_0,
  505. #if IS_ENABLED(CONFIG_AUDIO_QGKI)
  506. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  507. #endif /* CONFIG_AUDIO_QGKI */
  508. .dpcm_playback = 1,
  509. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  510. SND_SOC_DPCM_TRIGGER_POST},
  511. .ignore_pmdown_time = 1,
  512. .ignore_suspend = 1,
  513. .ops = &msm_common_be_ops,
  514. SND_SOC_DAILINK_REG(rx_dma_rx0),
  515. .init = &msm_aux_codec_init,
  516. },
  517. {
  518. .name = LPASS_BE_RX_CDC_DMA_RX_1,
  519. .stream_name = LPASS_BE_RX_CDC_DMA_RX_1,
  520. #if IS_ENABLED(CONFIG_AUDIO_QGKI)
  521. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  522. #endif /* CONFIG_AUDIO_QGKI */
  523. .dpcm_playback = 1,
  524. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  525. SND_SOC_DPCM_TRIGGER_POST},
  526. .ignore_pmdown_time = 1,
  527. .ignore_suspend = 1,
  528. .ops = &msm_common_be_ops,
  529. SND_SOC_DAILINK_REG(rx_dma_rx1),
  530. },
  531. {
  532. .name = LPASS_BE_RX_CDC_DMA_RX_2,
  533. .stream_name = LPASS_BE_RX_CDC_DMA_RX_2,
  534. #if IS_ENABLED(CONFIG_AUDIO_QGKI)
  535. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  536. #endif /* CONFIG_AUDIO_QGKI */
  537. .dpcm_playback = 1,
  538. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  539. SND_SOC_DPCM_TRIGGER_POST},
  540. .ignore_pmdown_time = 1,
  541. .ignore_suspend = 1,
  542. .ops = &msm_common_be_ops,
  543. SND_SOC_DAILINK_REG(rx_dma_rx2),
  544. },
  545. {
  546. .name = LPASS_BE_RX_CDC_DMA_RX_3,
  547. .stream_name = LPASS_BE_RX_CDC_DMA_RX_3,
  548. #if IS_ENABLED(CONFIG_AUDIO_QGKI)
  549. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  550. #endif /* CONFIG_AUDIO_QGKI */
  551. .dpcm_playback = 1,
  552. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  553. SND_SOC_DPCM_TRIGGER_POST},
  554. .ignore_pmdown_time = 1,
  555. .ignore_suspend = 1,
  556. .ops = &msm_common_be_ops,
  557. SND_SOC_DAILINK_REG(rx_dma_rx3),
  558. },
  559. {
  560. .name = LPASS_BE_RX_CDC_DMA_RX_6,
  561. .stream_name = LPASS_BE_RX_CDC_DMA_RX_6,
  562. #if IS_ENABLED(CONFIG_AUDIO_QGKI)
  563. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  564. #endif /* CONFIG_AUDIO_QGKI */
  565. .dpcm_playback = 1,
  566. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  567. SND_SOC_DPCM_TRIGGER_POST},
  568. .ignore_pmdown_time = 1,
  569. .ignore_suspend = 1,
  570. .ops = &msm_common_be_ops,
  571. SND_SOC_DAILINK_REG(rx_dma_rx6),
  572. },
  573. /* TX CDC DMA Backend DAI Links */
  574. {
  575. .name = LPASS_BE_TX_CDC_DMA_TX_3,
  576. .stream_name = LPASS_BE_TX_CDC_DMA_TX_3,
  577. #if IS_ENABLED(CONFIG_AUDIO_QGKI)
  578. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  579. #endif /* CONFIG_AUDIO_QGKI */
  580. .dpcm_capture = 1,
  581. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  582. SND_SOC_DPCM_TRIGGER_POST},
  583. .ignore_suspend = 1,
  584. .ops = &msm_common_be_ops,
  585. SND_SOC_DAILINK_REG(tx_dma_tx3),
  586. },
  587. {
  588. .name = LPASS_BE_TX_CDC_DMA_TX_4,
  589. .stream_name = LPASS_BE_TX_CDC_DMA_TX_4,
  590. #if IS_ENABLED(CONFIG_AUDIO_QGKI)
  591. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  592. #endif /* CONFIG_AUDIO_QGKI */
  593. .dpcm_capture = 1,
  594. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  595. SND_SOC_DPCM_TRIGGER_POST},
  596. .ignore_suspend = 1,
  597. .ops = &msm_common_be_ops,
  598. SND_SOC_DAILINK_REG(tx_dma_tx4),
  599. },
  600. };
  601. static struct snd_soc_dai_link msm_va_cdc_dma_be_dai_links[] = {
  602. {
  603. .name = LPASS_BE_VA_CDC_DMA_TX_0,
  604. .stream_name = LPASS_BE_VA_CDC_DMA_TX_0,
  605. #if IS_ENABLED(CONFIG_AUDIO_QGKI)
  606. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  607. #endif /* CONFIG_AUDIO_QGKI */
  608. .dpcm_capture = 1,
  609. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  610. SND_SOC_DPCM_TRIGGER_POST},
  611. .ignore_suspend = 1,
  612. .ops = &msm_common_be_ops,
  613. SND_SOC_DAILINK_REG(va_dma_tx0),
  614. },
  615. {
  616. .name = LPASS_BE_VA_CDC_DMA_TX_1,
  617. .stream_name = LPASS_BE_VA_CDC_DMA_TX_1,
  618. #if IS_ENABLED(CONFIG_AUDIO_QGKI)
  619. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  620. #endif /* CONFIG_AUDIO_QGKI */
  621. .dpcm_capture = 1,
  622. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  623. SND_SOC_DPCM_TRIGGER_POST},
  624. .ignore_suspend = 1,
  625. .ops = &msm_common_be_ops,
  626. SND_SOC_DAILINK_REG(va_dma_tx1),
  627. },
  628. {
  629. .name = LPASS_BE_VA_CDC_DMA_TX_2,
  630. .stream_name = LPASS_BE_VA_CDC_DMA_TX_2,
  631. #if IS_ENABLED(CONFIG_AUDIO_QGKI)
  632. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  633. #endif /* CONFIG_AUDIO_QGKI */
  634. .dpcm_capture = 1,
  635. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  636. SND_SOC_DPCM_TRIGGER_POST},
  637. .ignore_suspend = 1,
  638. .ops = &msm_common_be_ops,
  639. SND_SOC_DAILINK_REG(va_dma_tx2),
  640. },
  641. };
  642. static struct snd_soc_dai_link msm_lahaina_dai_links[
  643. ARRAY_SIZE(msm_wsa_cdc_dma_be_dai_links) +
  644. ARRAY_SIZE(msm_rx_tx_cdc_dma_be_dai_links) +
  645. ARRAY_SIZE(msm_va_cdc_dma_be_dai_links) +
  646. #if IS_ENABLED(CONFIG_AUDIO_QGKI)
  647. ARRAY_SIZE(ext_disp_be_dai_link) +
  648. #endif
  649. ARRAY_SIZE(msm_common_be_dai_links) +
  650. ARRAY_SIZE(msm_wcn_be_dai_links)];
  651. static int msm_populate_dai_link_component_of_node(
  652. struct snd_soc_card *card)
  653. {
  654. int i, j, index, ret = 0;
  655. struct device *cdev = card->dev;
  656. struct snd_soc_dai_link *dai_link = card->dai_link;
  657. struct device_node *np = NULL;
  658. int codecs_enabled = 0;
  659. struct snd_soc_dai_link_component *codecs_comp = NULL;
  660. if (!cdev) {
  661. dev_err(cdev, "%s: Sound card device memory NULL\n", __func__);
  662. return -ENODEV;
  663. }
  664. for (i = 0; i < card->num_links; i++) {
  665. if (dai_link[i].init == NULL)
  666. dai_link[i].init = &msm_common_dai_link_init;
  667. /* populate codec_of_node for snd card dai links */
  668. if (dai_link[i].num_codecs > 0) {
  669. for (j = 0; j < dai_link[i].num_codecs; j++) {
  670. if (dai_link[i].codecs[j].of_node ||
  671. !dai_link[i].codecs[j].name)
  672. continue;
  673. index = of_property_match_string(cdev->of_node,
  674. "asoc-codec-names",
  675. dai_link[i].codecs[j].name);
  676. if (index < 0)
  677. continue;
  678. np = of_parse_phandle(cdev->of_node,
  679. "asoc-codec",
  680. index);
  681. if (!np) {
  682. dev_err(cdev, "%s: retrieving phandle for codec %s failed\n",
  683. __func__,
  684. dai_link[i].codecs[j].name);
  685. ret = -ENODEV;
  686. goto err;
  687. }
  688. dai_link[i].codecs[j].of_node = np;
  689. dai_link[i].codecs[j].name = NULL;
  690. }
  691. }
  692. }
  693. /* In multi-codec scenario, check if codecs are enabled for this platform */
  694. for (i = 0; i < card->num_links; i++) {
  695. codecs_enabled = 0;
  696. if (dai_link[i].num_codecs > 1) {
  697. for (j = 0; j < dai_link[i].num_codecs; j++) {
  698. if (!dai_link[i].codecs[j].of_node)
  699. continue;
  700. np = dai_link[i].codecs[j].of_node;
  701. if (!of_device_is_available(np)) {
  702. dev_err(cdev, "%s: codec is disabled: %s\n",
  703. __func__,
  704. np->full_name);
  705. dai_link[i].codecs[j].of_node = NULL;
  706. continue;
  707. }
  708. codecs_enabled++;
  709. }
  710. if (codecs_enabled > 0 &&
  711. codecs_enabled < dai_link[i].num_codecs) {
  712. codecs_comp = devm_kzalloc(cdev,
  713. sizeof(struct snd_soc_dai_link_component)
  714. * codecs_enabled, GFP_KERNEL);
  715. if (!codecs_comp) {
  716. dev_err(cdev, "%s: %s dailink codec component alloc failed\n",
  717. __func__, dai_link[i].name);
  718. ret = -ENOMEM;
  719. goto err;
  720. }
  721. index = 0;
  722. for (j = 0; j < dai_link[i].num_codecs; j++) {
  723. if(dai_link[i].codecs[j].of_node) {
  724. codecs_comp[index].of_node =
  725. dai_link[i].codecs[j].of_node;
  726. codecs_comp[index].dai_name =
  727. dai_link[i].codecs[j].dai_name;
  728. codecs_comp[index].name = NULL;
  729. index++;
  730. }
  731. }
  732. dai_link[i].codecs = codecs_comp;
  733. dai_link[i].num_codecs = codecs_enabled;
  734. }
  735. }
  736. }
  737. err:
  738. return ret;
  739. }
  740. static int msm_audrx_stub_init(struct snd_soc_pcm_runtime *rtd)
  741. {
  742. return 0;
  743. }
  744. static int msm_snd_stub_hw_params(struct snd_pcm_substream *substream,
  745. struct snd_pcm_hw_params *params)
  746. {
  747. return 0;
  748. }
  749. static struct snd_soc_ops msm_stub_be_ops = {
  750. .hw_params = msm_snd_stub_hw_params,
  751. };
  752. struct snd_soc_card snd_soc_card_stub_msm = {
  753. .name = "lahaina-stub-snd-card",
  754. };
  755. static struct snd_soc_dai_link msm_stub_be_dai_links[] = {
  756. /* Backend DAI Links */
  757. {
  758. .name = LPASS_BE_PRI_AUXPCM_RX,
  759. .stream_name = LPASS_BE_PRI_AUXPCM_RX,
  760. .dpcm_playback = 1,
  761. .init = &msm_audrx_stub_init,
  762. .ignore_pmdown_time = 1,
  763. .ignore_suspend = 1,
  764. .ops = &msm_stub_be_ops,
  765. SND_SOC_DAILINK_REG(auxpcm_rx),
  766. },
  767. {
  768. .name = LPASS_BE_PRI_AUXPCM_TX,
  769. .stream_name = LPASS_BE_PRI_AUXPCM_TX,
  770. .dpcm_capture = 1,
  771. .ignore_suspend = 1,
  772. .ops = &msm_stub_be_ops,
  773. SND_SOC_DAILINK_REG(auxpcm_tx),
  774. },
  775. };
  776. static struct snd_soc_dai_link msm_stub_dai_links[
  777. ARRAY_SIZE(msm_stub_be_dai_links)];
  778. static const struct of_device_id lahaina_asoc_machine_of_match[] = {
  779. { .compatible = "qcom,lahaina-asoc-snd",
  780. .data = "codec"},
  781. { .compatible = "qcom,lahaina-asoc-snd-stub",
  782. .data = "stub_codec"},
  783. {},
  784. };
  785. static struct snd_soc_card *populate_snd_card_dailinks(struct device *dev)
  786. {
  787. struct snd_soc_card *card = NULL;
  788. struct snd_soc_dai_link *dailink = NULL;
  789. int total_links = 0;
  790. int rc = 0;
  791. u32 val = 0;
  792. const struct of_device_id *match;
  793. match = of_match_node(lahaina_asoc_machine_of_match, dev->of_node);
  794. if (!match) {
  795. dev_err(dev, "%s: No DT match found for sound card\n",
  796. __func__);
  797. return NULL;
  798. }
  799. if (!strcmp(match->data, "codec")) {
  800. card = &snd_soc_card_lahaina_msm;
  801. memcpy(msm_lahaina_dai_links + total_links,
  802. msm_wsa_cdc_dma_be_dai_links,
  803. sizeof(msm_wsa_cdc_dma_be_dai_links));
  804. total_links += ARRAY_SIZE(msm_wsa_cdc_dma_be_dai_links);
  805. memcpy(msm_lahaina_dai_links + total_links,
  806. msm_rx_tx_cdc_dma_be_dai_links,
  807. sizeof(msm_rx_tx_cdc_dma_be_dai_links));
  808. total_links +=
  809. ARRAY_SIZE(msm_rx_tx_cdc_dma_be_dai_links);
  810. memcpy(msm_lahaina_dai_links + total_links,
  811. msm_va_cdc_dma_be_dai_links,
  812. sizeof(msm_va_cdc_dma_be_dai_links));
  813. total_links += ARRAY_SIZE(msm_va_cdc_dma_be_dai_links);
  814. memcpy(msm_lahaina_dai_links + total_links,
  815. msm_common_be_dai_links,
  816. sizeof(msm_common_be_dai_links));
  817. total_links += ARRAY_SIZE(msm_common_be_dai_links);
  818. #if IS_ENABLED(CONFIG_AUDIO_QGKI)
  819. rc = of_property_read_u32(dev->of_node,
  820. "qcom,ext-disp-audio-rx", &val);
  821. if (!rc && val) {
  822. dev_dbg(dev, "%s(): ext disp audio support present\n",
  823. __func__);
  824. memcpy(msm_lahaina_dai_links + total_links,
  825. ext_disp_be_dai_link,
  826. sizeof(ext_disp_be_dai_link));
  827. total_links += ARRAY_SIZE(ext_disp_be_dai_link);
  828. }
  829. #endif
  830. rc = of_property_read_u32(dev->of_node, "qcom,wcn-bt", &val);
  831. if (!rc && val) {
  832. dev_dbg(dev, "%s(): WCN BT support present\n",
  833. __func__);
  834. memcpy(msm_lahaina_dai_links + total_links,
  835. msm_wcn_be_dai_links,
  836. sizeof(msm_wcn_be_dai_links));
  837. total_links += ARRAY_SIZE(msm_wcn_be_dai_links);
  838. }
  839. dailink = msm_lahaina_dai_links;
  840. } else if(!strcmp(match->data, "stub_codec")) {
  841. card = &snd_soc_card_stub_msm;
  842. memcpy(msm_stub_dai_links,
  843. msm_stub_be_dai_links,
  844. sizeof(msm_stub_be_dai_links));
  845. dailink = msm_stub_dai_links;
  846. total_links = ARRAY_SIZE(msm_stub_be_dai_links);
  847. }
  848. if (card) {
  849. card->dai_link = dailink;
  850. card->num_links = total_links;
  851. }
  852. return card;
  853. }
  854. static int msm_int_audrx_init(struct snd_soc_pcm_runtime *rtd)
  855. {
  856. u8 spkleft_ports[WSA883X_MAX_SWR_PORTS] = {0, 1, 2, 3};
  857. u8 spkright_ports[WSA883X_MAX_SWR_PORTS] = {0, 1, 2, 3};
  858. u8 spkleft_port_types[WSA883X_MAX_SWR_PORTS] = {SPKR_L, SPKR_L_COMP,
  859. SPKR_L_BOOST, SPKR_L_VI};
  860. u8 spkright_port_types[WSA883X_MAX_SWR_PORTS] = {SPKR_R, SPKR_R_COMP,
  861. SPKR_R_BOOST, SPKR_R_VI};
  862. unsigned int ch_rate[WSA883X_MAX_SWR_PORTS] = {SWR_CLK_RATE_2P4MHZ, SWR_CLK_RATE_0P6MHZ,
  863. SWR_CLK_RATE_0P3MHZ, SWR_CLK_RATE_1P2MHZ};
  864. unsigned int ch_mask[WSA883X_MAX_SWR_PORTS] = {0x1, 0xF, 0x3, 0x3};
  865. struct snd_soc_component *component = NULL;
  866. struct snd_soc_dapm_context *dapm = NULL;
  867. struct snd_card *card = NULL;
  868. struct snd_info_entry *entry = NULL;
  869. struct msm_asoc_mach_data *pdata =
  870. snd_soc_card_get_drvdata(rtd->card);
  871. int ret = 0;
  872. if (pdata->wsa_max_devs > 0) {
  873. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.1");
  874. if (!component) {
  875. pr_err("%s: wsa-codec.1 component is NULL\n", __func__);
  876. return -EINVAL;
  877. }
  878. dapm = snd_soc_component_get_dapm(component);
  879. wsa883x_set_channel_map(component, &spkleft_ports[0],
  880. WSA883X_MAX_SWR_PORTS, &ch_mask[0],
  881. &ch_rate[0], &spkleft_port_types[0]);
  882. if (dapm->component) {
  883. snd_soc_dapm_ignore_suspend(dapm, "spkrLeft IN");
  884. snd_soc_dapm_ignore_suspend(dapm, "spkrLeft SPKR");
  885. }
  886. wsa883x_codec_info_create_codec_entry(pdata->codec_root,
  887. component);
  888. }
  889. /* If current platform has more than one WSA */
  890. if (pdata->wsa_max_devs > 1) {
  891. component = snd_soc_rtdcom_lookup(rtd, "wsa-codec.2");
  892. if (!component) {
  893. pr_err("%s: wsa-codec.2 component is NULL\n", __func__);
  894. return -EINVAL;
  895. }
  896. dapm = snd_soc_component_get_dapm(component);
  897. wsa883x_set_channel_map(component, &spkright_ports[0],
  898. WSA883X_MAX_SWR_PORTS, &ch_mask[0],
  899. &ch_rate[0], &spkright_port_types[0]);
  900. if (dapm->component) {
  901. snd_soc_dapm_ignore_suspend(dapm, "spkrRight IN");
  902. snd_soc_dapm_ignore_suspend(dapm, "spkrRight SPKR");
  903. }
  904. wsa883x_codec_info_create_codec_entry(pdata->codec_root,
  905. component);
  906. }
  907. component = snd_soc_rtdcom_lookup(rtd, "bolero_codec");
  908. if (!component) {
  909. pr_err("%s: could not find component for bolero_codec\n",
  910. __func__);
  911. return ret;
  912. }
  913. dapm = snd_soc_component_get_dapm(component);
  914. snd_soc_dapm_new_controls(dapm, msm_int_dapm_widgets,
  915. ARRAY_SIZE(msm_int_dapm_widgets));
  916. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic0");
  917. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic1");
  918. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic2");
  919. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic3");
  920. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic4");
  921. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic5");
  922. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic6");
  923. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic7");
  924. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic1");
  925. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic2");
  926. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic3");
  927. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic4");
  928. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic5");
  929. snd_soc_dapm_ignore_suspend(dapm, "WSA_SPK1 OUT");
  930. snd_soc_dapm_ignore_suspend(dapm, "WSA_SPK2 OUT");
  931. snd_soc_dapm_ignore_suspend(dapm, "WSA AIF VI");
  932. snd_soc_dapm_ignore_suspend(dapm, "VIINPUT_WSA");
  933. snd_soc_dapm_sync(dapm);
  934. bolero_set_port_map(component, ARRAY_SIZE(sm_port_map), sm_port_map);
  935. card = rtd->card->snd_card;
  936. if (!pdata->codec_root) {
  937. entry = msm_snd_info_create_subdir(card->module, "codecs",
  938. card->proc_root);
  939. if (!entry) {
  940. pr_debug("%s: Cannot create codecs module entry\n",
  941. __func__);
  942. ret = 0;
  943. goto err;
  944. }
  945. pdata->codec_root = entry;
  946. }
  947. bolero_info_create_codec_entry(pdata->codec_root, component);
  948. bolero_register_wake_irq(component, false);
  949. codec_reg_done = true;
  950. msm_common_dai_link_init(rtd);
  951. err:
  952. return ret;
  953. }
  954. static int msm_aux_codec_init(struct snd_soc_pcm_runtime *rtd)
  955. {
  956. struct snd_soc_component *component = NULL;
  957. struct snd_soc_dapm_context *dapm = NULL;
  958. int ret = 0;
  959. void *mbhc_calibration;
  960. struct snd_info_entry *entry;
  961. struct snd_card *card = NULL;
  962. struct msm_asoc_mach_data *pdata;
  963. component = snd_soc_rtdcom_lookup(rtd, WCD938X_DRV_NAME);
  964. if (!component) {
  965. pr_err("%s component is NULL\n", __func__);
  966. return -EINVAL;
  967. }
  968. dapm = snd_soc_component_get_dapm(component);
  969. card = component->card->snd_card;
  970. snd_soc_dapm_ignore_suspend(dapm, "EAR");
  971. snd_soc_dapm_ignore_suspend(dapm, "AUX");
  972. snd_soc_dapm_ignore_suspend(dapm, "HPHL");
  973. snd_soc_dapm_ignore_suspend(dapm, "HPHR");
  974. snd_soc_dapm_ignore_suspend(dapm, "AMIC1");
  975. snd_soc_dapm_ignore_suspend(dapm, "AMIC2");
  976. snd_soc_dapm_ignore_suspend(dapm, "AMIC3");
  977. snd_soc_dapm_ignore_suspend(dapm, "AMIC4");
  978. snd_soc_dapm_sync(dapm);
  979. pdata = snd_soc_card_get_drvdata(component->card);
  980. if (!pdata->codec_root) {
  981. entry = msm_snd_info_create_subdir(card->module, "codecs",
  982. card->proc_root);
  983. if (!entry) {
  984. dev_dbg(component->dev, "%s: Cannot create codecs module entry\n",
  985. __func__);
  986. ret = 0;
  987. goto mbhc_cfg_cal;
  988. }
  989. pdata->codec_root = entry;
  990. }
  991. wcd938x_info_create_codec_entry(pdata->codec_root, component);
  992. #if 0
  993. codec_variant = wcd938x_get_codec_variant(component);
  994. dev_dbg(component->dev, "%s: variant %d\n", __func__, codec_variant);
  995. if (codec_variant == WCD9380)
  996. ret = snd_soc_add_component_controls(component,
  997. msm_int_wcd9380_snd_controls,
  998. ARRAY_SIZE(msm_int_wcd9380_snd_controls));
  999. else if (codec_variant == WCD9385)
  1000. ret = snd_soc_add_component_controls(component,
  1001. msm_int_wcd9385_snd_controls,
  1002. ARRAY_SIZE(msm_int_wcd9385_snd_controls));
  1003. if (ret < 0) {
  1004. dev_err(component->dev, "%s: add codec specific snd controls failed: %d\n",
  1005. __func__, ret);
  1006. return ret;
  1007. }
  1008. #endif
  1009. mbhc_cfg_cal:
  1010. mbhc_calibration = def_wcd_mbhc_cal();
  1011. if (!mbhc_calibration)
  1012. return -ENOMEM;
  1013. wcd_mbhc_cfg.calibration = mbhc_calibration;
  1014. ret = wcd938x_mbhc_hs_detect(component, &wcd_mbhc_cfg);
  1015. if (ret) {
  1016. dev_err(component->dev, "%s: mbhc hs detect failed, err:%d\n",
  1017. __func__, ret);
  1018. goto err_hs_detect;
  1019. }
  1020. return 0;
  1021. err_hs_detect:
  1022. kfree(mbhc_calibration);
  1023. return ret;
  1024. }
  1025. static int lahaina_ssr_enable(struct device *dev, void *data)
  1026. {
  1027. struct platform_device *pdev = to_platform_device(dev);
  1028. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1029. int ret = 0;
  1030. if (!card) {
  1031. dev_err(dev, "%s: card is NULL\n", __func__);
  1032. ret = -EINVAL;
  1033. goto err;
  1034. }
  1035. if (!strcmp(card->name, "lahaina-stub-snd-card")) {
  1036. /* TODO */
  1037. dev_dbg(dev, "%s: TODO \n", __func__);
  1038. }
  1039. #if IS_ENABLED(CONFIG_AUDIO_QGKI)
  1040. snd_soc_card_change_online_state(card, 1);
  1041. #endif /* CONFIG_AUDIO_QGKI */
  1042. dev_dbg(dev, "%s: setting snd_card to ONLINE\n", __func__);
  1043. err:
  1044. return ret;
  1045. }
  1046. static void lahaina_ssr_disable(struct device *dev, void *data)
  1047. {
  1048. struct platform_device *pdev = to_platform_device(dev);
  1049. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1050. if (!card) {
  1051. dev_err(dev, "%s: card is NULL\n", __func__);
  1052. return;
  1053. }
  1054. dev_dbg(dev, "%s: setting snd_card to OFFLINE\n", __func__);
  1055. #if IS_ENABLED(CONFIG_AUDIO_QGKI)
  1056. snd_soc_card_change_online_state(card, 0);
  1057. #endif /* CONFIG_AUDIO_QGKI */
  1058. if (!strcmp(card->name, "lahaina-stub-snd-card")) {
  1059. /* TODO */
  1060. dev_dbg(dev, "%s: TODO \n", __func__);
  1061. }
  1062. }
  1063. static const struct snd_event_ops lahaina_ssr_ops = {
  1064. .enable = lahaina_ssr_enable,
  1065. .disable = lahaina_ssr_disable,
  1066. };
  1067. static int msm_audio_ssr_compare(struct device *dev, void *data)
  1068. {
  1069. struct device_node *node = data;
  1070. dev_dbg(dev, "%s: dev->of_node = 0x%p, node = 0x%p\n",
  1071. __func__, dev->of_node, node);
  1072. return (dev->of_node && dev->of_node == node);
  1073. }
  1074. static int msm_audio_ssr_register(struct device *dev)
  1075. {
  1076. struct device_node *np = dev->of_node;
  1077. struct snd_event_clients *ssr_clients = NULL;
  1078. struct device_node *node = NULL;
  1079. int ret = 0;
  1080. int i = 0;
  1081. for (i = 0; ; i++) {
  1082. node = of_parse_phandle(np, "qcom,msm_audio_ssr_devs", i);
  1083. if (!node)
  1084. break;
  1085. snd_event_mstr_add_client(&ssr_clients,
  1086. msm_audio_ssr_compare, node);
  1087. }
  1088. ret = snd_event_master_register(dev, &lahaina_ssr_ops,
  1089. ssr_clients, NULL);
  1090. if (!ret)
  1091. snd_event_notify(dev, SND_EVENT_UP);
  1092. return ret;
  1093. }
  1094. struct msm_common_pdata *msm_common_get_pdata(struct snd_soc_card *card)
  1095. {
  1096. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  1097. if (!pdata)
  1098. return NULL;
  1099. return pdata->common_pdata;
  1100. }
  1101. void msm_common_set_pdata(struct snd_soc_card *card,
  1102. struct msm_common_pdata *common_pdata)
  1103. {
  1104. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  1105. if (!pdata)
  1106. return;
  1107. pdata->common_pdata = common_pdata;
  1108. }
  1109. static int msm_asoc_machine_probe(struct platform_device *pdev)
  1110. {
  1111. struct snd_soc_card *card = NULL;
  1112. struct msm_asoc_mach_data *pdata = NULL;
  1113. const char *mbhc_audio_jack_type = NULL;
  1114. int ret = 0;
  1115. struct clk *lpass_audio_hw_vote = NULL;
  1116. if (!pdev->dev.of_node) {
  1117. dev_err(&pdev->dev, "%s: No platform supplied from device tree\n", __func__);
  1118. return -EINVAL;
  1119. }
  1120. pdata = devm_kzalloc(&pdev->dev,
  1121. sizeof(struct msm_asoc_mach_data), GFP_KERNEL);
  1122. if (!pdata)
  1123. return -ENOMEM;
  1124. of_property_read_u32(pdev->dev.of_node,
  1125. "qcom,lito-is-v2-enabled",
  1126. &pdata->lito_v2_enabled);
  1127. card = populate_snd_card_dailinks(&pdev->dev);
  1128. if (!card) {
  1129. dev_err(&pdev->dev, "%s: Card uninitialized\n", __func__);
  1130. ret = -EINVAL;
  1131. goto err;
  1132. }
  1133. card->dev = &pdev->dev;
  1134. platform_set_drvdata(pdev, card);
  1135. snd_soc_card_set_drvdata(card, pdata);
  1136. ret = snd_soc_of_parse_card_name(card, "qcom,model");
  1137. if (ret) {
  1138. dev_err(&pdev->dev, "%s: parse card name failed, err:%d\n",
  1139. __func__, ret);
  1140. goto err;
  1141. }
  1142. ret = snd_soc_of_parse_audio_routing(card, "qcom,audio-routing");
  1143. if (ret) {
  1144. dev_err(&pdev->dev, "%s: parse audio routing failed, err:%d\n",
  1145. __func__, ret);
  1146. goto err;
  1147. }
  1148. ret = msm_populate_dai_link_component_of_node(card);
  1149. if (ret) {
  1150. ret = -EPROBE_DEFER;
  1151. goto err;
  1152. }
  1153. /* Get maximum WSA device count for this platform */
  1154. ret = of_property_read_u32(pdev->dev.of_node,
  1155. "qcom,wsa-max-devs", &pdata->wsa_max_devs);
  1156. if (ret) {
  1157. dev_info(&pdev->dev,
  1158. "%s: wsa-max-devs property missing in DT %s, ret = %d\n",
  1159. __func__, pdev->dev.of_node->full_name, ret);
  1160. pdata->wsa_max_devs = 0;
  1161. }
  1162. ret = devm_snd_soc_register_card(&pdev->dev, card);
  1163. if (ret == -EPROBE_DEFER) {
  1164. if (codec_reg_done)
  1165. ret = -EINVAL;
  1166. goto err;
  1167. } else if (ret) {
  1168. dev_err(&pdev->dev, "%s: snd_soc_register_card failed (%d)\n",
  1169. __func__, ret);
  1170. goto err;
  1171. }
  1172. dev_info(&pdev->dev, "%s: Sound card %s registered\n",
  1173. __func__, card->name);
  1174. pdata->hph_en1_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1175. "qcom,hph-en1-gpio", 0);
  1176. if (!pdata->hph_en1_gpio_p) {
  1177. dev_dbg(&pdev->dev, "%s: property %s not detected in node %s\n",
  1178. __func__, "qcom,hph-en1-gpio",
  1179. pdev->dev.of_node->full_name);
  1180. }
  1181. pdata->hph_en0_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1182. "qcom,hph-en0-gpio", 0);
  1183. if (!pdata->hph_en0_gpio_p) {
  1184. dev_dbg(&pdev->dev, "%s: property %s not detected in node %s\n",
  1185. __func__, "qcom,hph-en0-gpio",
  1186. pdev->dev.of_node->full_name);
  1187. }
  1188. ret = of_property_read_string(pdev->dev.of_node,
  1189. "qcom,mbhc-audio-jack-type", &mbhc_audio_jack_type);
  1190. if (ret) {
  1191. dev_dbg(&pdev->dev, "%s: Looking up %s property in node %s failed\n",
  1192. __func__, "qcom,mbhc-audio-jack-type",
  1193. pdev->dev.of_node->full_name);
  1194. dev_dbg(&pdev->dev, "Jack type properties set to default\n");
  1195. } else {
  1196. if (!strcmp(mbhc_audio_jack_type, "4-pole-jack")) {
  1197. wcd_mbhc_cfg.enable_anc_mic_detect = false;
  1198. dev_dbg(&pdev->dev, "This hardware has 4 pole jack");
  1199. } else if (!strcmp(mbhc_audio_jack_type, "5-pole-jack")) {
  1200. wcd_mbhc_cfg.enable_anc_mic_detect = true;
  1201. dev_dbg(&pdev->dev, "This hardware has 5 pole jack");
  1202. } else if (!strcmp(mbhc_audio_jack_type, "6-pole-jack")) {
  1203. wcd_mbhc_cfg.enable_anc_mic_detect = true;
  1204. dev_dbg(&pdev->dev, "This hardware has 6 pole jack");
  1205. } else {
  1206. wcd_mbhc_cfg.enable_anc_mic_detect = false;
  1207. dev_dbg(&pdev->dev, "Unknown value, set to default\n");
  1208. }
  1209. }
  1210. /*
  1211. * Parse US-Euro gpio info from DT. Report no error if us-euro
  1212. * entry is not found in DT file as some targets do not support
  1213. * US-Euro detection
  1214. */
  1215. pdata->us_euro_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1216. "qcom,us-euro-gpios", 0);
  1217. if (!pdata->us_euro_gpio_p) {
  1218. dev_dbg(&pdev->dev, "property %s not detected in node %s",
  1219. "qcom,us-euro-gpios", pdev->dev.of_node->full_name);
  1220. } else {
  1221. dev_dbg(&pdev->dev, "%s detected\n",
  1222. "qcom,us-euro-gpios");
  1223. wcd_mbhc_cfg.swap_gnd_mic = msm_swap_gnd_mic;
  1224. }
  1225. if (wcd_mbhc_cfg.enable_usbc_analog)
  1226. wcd_mbhc_cfg.swap_gnd_mic = msm_usbc_swap_gnd_mic;
  1227. pdata->fsa_handle = of_parse_phandle(pdev->dev.of_node,
  1228. "fsa4480-i2c-handle", 0);
  1229. if (!pdata->fsa_handle)
  1230. dev_dbg(&pdev->dev, "property %s not detected in node %s\n",
  1231. "fsa4480-i2c-handle", pdev->dev.of_node->full_name);
  1232. pdata->dmic01_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1233. "qcom,cdc-dmic01-gpios",
  1234. 0);
  1235. pdata->dmic23_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1236. "qcom,cdc-dmic23-gpios",
  1237. 0);
  1238. pdata->dmic45_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1239. "qcom,cdc-dmic45-gpios",
  1240. 0);
  1241. if (pdata->dmic01_gpio_p)
  1242. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic01_gpio_p, false);
  1243. if (pdata->dmic23_gpio_p)
  1244. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic23_gpio_p, false);
  1245. if (pdata->dmic45_gpio_p)
  1246. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic45_gpio_p, false);
  1247. msm_common_snd_init(pdev, card);
  1248. #if 0
  1249. pdata->mi2s_gpio_p[PRIM_MI2S] = of_parse_phandle(pdev->dev.of_node,
  1250. "qcom,pri-mi2s-gpios", 0);
  1251. pdata->mi2s_gpio_p[SEC_MI2S] = of_parse_phandle(pdev->dev.of_node,
  1252. "qcom,sec-mi2s-gpios", 0);
  1253. pdata->mi2s_gpio_p[TERT_MI2S] = of_parse_phandle(pdev->dev.of_node,
  1254. "qcom,tert-mi2s-gpios", 0);
  1255. pdata->mi2s_gpio_p[QUAT_MI2S] = of_parse_phandle(pdev->dev.of_node,
  1256. "qcom,quat-mi2s-gpios", 0);
  1257. pdata->mi2s_gpio_p[QUIN_MI2S] = of_parse_phandle(pdev->dev.of_node,
  1258. "qcom,quin-mi2s-gpios", 0);
  1259. pdata->mi2s_gpio_p[SEN_MI2S] = of_parse_phandle(pdev->dev.of_node,
  1260. "qcom,sen-mi2s-gpios", 0);
  1261. for (index = PRIM_MI2S; index < MI2S_MAX; index++)
  1262. atomic_set(&(pdata->mi2s_gpio_ref_count[index]), 0);
  1263. #endif
  1264. /* Register LPASS audio hw vote */
  1265. lpass_audio_hw_vote = devm_clk_get(&pdev->dev, "lpass_audio_hw_vote");
  1266. if (IS_ERR(lpass_audio_hw_vote)) {
  1267. ret = PTR_ERR(lpass_audio_hw_vote);
  1268. dev_dbg(&pdev->dev, "%s: clk get %s failed %d\n",
  1269. __func__, "lpass_audio_hw_vote", ret);
  1270. lpass_audio_hw_vote = NULL;
  1271. ret = 0;
  1272. }
  1273. pdata->lpass_audio_hw_vote = lpass_audio_hw_vote;
  1274. pdata->core_audio_vote_count = 0;
  1275. ret = msm_audio_ssr_register(&pdev->dev);
  1276. if (ret)
  1277. pr_err("%s: Registration with SND event FWK failed ret = %d\n",
  1278. __func__, ret);
  1279. is_initial_boot = true;
  1280. /* Add QoS request for audio tasks */
  1281. msm_audio_add_qos_request();
  1282. return 0;
  1283. err:
  1284. devm_kfree(&pdev->dev, pdata);
  1285. return ret;
  1286. }
  1287. static int msm_asoc_machine_remove(struct platform_device *pdev)
  1288. {
  1289. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1290. struct msm_asoc_mach_data *pdata = NULL;
  1291. struct msm_common_pdata *common_pdata = NULL;
  1292. if (card)
  1293. pdata = snd_soc_card_get_drvdata(card);
  1294. if (pdata)
  1295. common_pdata = pdata->common_pdata;
  1296. msm_common_snd_deinit(common_pdata);
  1297. snd_event_master_deregister(&pdev->dev);
  1298. snd_soc_unregister_card(card);
  1299. msm_audio_remove_qos_request();
  1300. return 0;
  1301. }
  1302. static struct platform_driver lahaina_asoc_machine_driver = {
  1303. .driver = {
  1304. .name = DRV_NAME,
  1305. .owner = THIS_MODULE,
  1306. .pm = &snd_soc_pm_ops,
  1307. .of_match_table = lahaina_asoc_machine_of_match,
  1308. .suppress_bind_attrs = true,
  1309. },
  1310. .probe = msm_asoc_machine_probe,
  1311. .remove = msm_asoc_machine_remove,
  1312. };
  1313. module_platform_driver(lahaina_asoc_machine_driver);
  1314. MODULE_SOFTDEP("pre: bt_fm_slim");
  1315. MODULE_DESCRIPTION("ALSA SoC msm");
  1316. MODULE_LICENSE("GPL v2");
  1317. MODULE_ALIAS("platform:" DRV_NAME);
  1318. MODULE_DEVICE_TABLE(of, lahaina_asoc_machine_of_match);