lahaina.c 41 KB

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