waipio.c 46 KB

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