waipio.c 51 KB

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