xref: /linux/sound/soc/mediatek/mt8195/mt8195-mt6359.c (revision 001821b0e79716c4e17c71d8e053a23599a7a508)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * mt8195-mt6359.c  --
4  *	MT8195-MT6359 ALSA SoC machine driver code
5  *
6  * Copyright (c) 2022 MediaTek Inc.
7  * Author: Trevor Wu <trevor.wu@mediatek.com>
8  *	   YC Hung <yc.hung@mediatek.com>
9  */
10 
11 #include <linux/input.h>
12 #include <linux/module.h>
13 #include <linux/of.h>
14 #include <linux/pm_runtime.h>
15 #include <sound/jack.h>
16 #include <sound/pcm_params.h>
17 #include <sound/rt5682.h>
18 #include <sound/soc.h>
19 #include "../../codecs/mt6359.h"
20 #include "../../codecs/rt1011.h"
21 #include "../../codecs/rt5682.h"
22 #include "../common/mtk-afe-platform-driver.h"
23 #include "../common/mtk-dsp-sof-common.h"
24 #include "../common/mtk-soc-card.h"
25 #include "../common/mtk-soundcard-driver.h"
26 #include "mt8195-afe-clk.h"
27 #include "mt8195-afe-common.h"
28 
29 #define RT1011_SPEAKER_AMP_PRESENT		BIT(0)
30 #define RT1019_SPEAKER_AMP_PRESENT		BIT(1)
31 #define MAX98390_SPEAKER_AMP_PRESENT		BIT(2)
32 
33 #define DUMB_CODEC_INIT				BIT(0)
34 #define MT6359_CODEC_INIT			BIT(1)
35 #define RT1011_CODEC_INIT			BIT(2)
36 #define RT1019_CODEC_INIT			BIT(3)
37 #define MAX98390_CODEC_INIT			BIT(4)
38 #define RT5682_CODEC_INIT			BIT(5)
39 
40 #define RT1011_CODEC_DAI	"rt1011-aif"
41 #define RT1011_DEV0_NAME	"rt1011.2-0038"
42 #define RT1011_DEV1_NAME	"rt1011.2-0039"
43 
44 #define RT1019_CODEC_DAI	"HiFi"
45 #define RT1019_DEV0_NAME	"rt1019p"
46 
47 #define MAX98390_CODEC_DAI	"max98390-aif1"
48 #define MAX98390_DEV0_NAME	"max98390.2-0038" /* right */
49 #define MAX98390_DEV1_NAME	"max98390.2-0039" /* left */
50 
51 #define RT5682_CODEC_DAI	"rt5682-aif1"
52 #define RT5682_DEV0_NAME	"rt5682.2-001a"
53 
54 #define RT5682S_CODEC_DAI	"rt5682s-aif1"
55 #define RT5682S_DEV0_NAME	"rt5682s.2-001a"
56 
57 #define SOF_DMA_DL2 "SOF_DMA_DL2"
58 #define SOF_DMA_DL3 "SOF_DMA_DL3"
59 #define SOF_DMA_UL4 "SOF_DMA_UL4"
60 #define SOF_DMA_UL5 "SOF_DMA_UL5"
61 
62 struct mt8195_mt6359_priv {
63 	struct clk *i2so1_mclk;
64 };
65 
66 enum mt8195_jacks {
67 	MT8195_JACK_HEADSET,
68 	MT8195_JACK_DP,
69 	MT8195_JACK_HDMI,
70 	MT8195_JACK_MAX,
71 };
72 
73 /* Headset jack detection DAPM pins */
74 static struct snd_soc_jack_pin mt8195_jack_pins[] = {
75 	{
76 		.pin = "Headphone",
77 		.mask = SND_JACK_HEADPHONE,
78 	},
79 	{
80 		.pin = "Headset Mic",
81 		.mask = SND_JACK_MICROPHONE,
82 	},
83 };
84 
85 static const struct snd_soc_dapm_widget mt8195_mt6359_widgets[] = {
86 	SND_SOC_DAPM_HP("Headphone", NULL),
87 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
88 	SND_SOC_DAPM_MIXER(SOF_DMA_DL2, SND_SOC_NOPM, 0, 0, NULL, 0),
89 	SND_SOC_DAPM_MIXER(SOF_DMA_DL3, SND_SOC_NOPM, 0, 0, NULL, 0),
90 	SND_SOC_DAPM_MIXER(SOF_DMA_UL4, SND_SOC_NOPM, 0, 0, NULL, 0),
91 	SND_SOC_DAPM_MIXER(SOF_DMA_UL5, SND_SOC_NOPM, 0, 0, NULL, 0),
92 };
93 
94 static const struct snd_soc_dapm_route mt8195_mt6359_routes[] = {
95 	/* headset */
96 	{ "Headphone", NULL, "HPOL" },
97 	{ "Headphone", NULL, "HPOR" },
98 	{ "IN1P", NULL, "Headset Mic" },
99 	/* SOF Uplink */
100 	{SOF_DMA_UL4, NULL, "O034"},
101 	{SOF_DMA_UL4, NULL, "O035"},
102 	{SOF_DMA_UL5, NULL, "O036"},
103 	{SOF_DMA_UL5, NULL, "O037"},
104 	/* SOF Downlink */
105 	{"I070", NULL, SOF_DMA_DL2},
106 	{"I071", NULL, SOF_DMA_DL2},
107 	{"I020", NULL, SOF_DMA_DL3},
108 	{"I021", NULL, SOF_DMA_DL3},
109 };
110 
111 static const struct snd_kcontrol_new mt8195_mt6359_controls[] = {
112 	SOC_DAPM_PIN_SWITCH("Headphone"),
113 	SOC_DAPM_PIN_SWITCH("Headset Mic"),
114 };
115 
116 static const struct snd_soc_dapm_widget mt8195_dual_speaker_widgets[] = {
117 	SND_SOC_DAPM_SPK("Left Spk", NULL),
118 	SND_SOC_DAPM_SPK("Right Spk", NULL),
119 };
120 
121 static const struct snd_kcontrol_new mt8195_dual_speaker_controls[] = {
122 	SOC_DAPM_PIN_SWITCH("Left Spk"),
123 	SOC_DAPM_PIN_SWITCH("Right Spk"),
124 };
125 
126 static const struct snd_soc_dapm_widget mt8195_speaker_widgets[] = {
127 	SND_SOC_DAPM_SPK("Ext Spk", NULL),
128 };
129 
130 static const struct snd_kcontrol_new mt8195_speaker_controls[] = {
131 	SOC_DAPM_PIN_SWITCH("Ext Spk"),
132 };
133 
134 static const struct snd_soc_dapm_route mt8195_rt1011_routes[] = {
135 	{ "Left Spk", NULL, "Left SPO" },
136 	{ "Right Spk", NULL, "Right SPO" },
137 };
138 
139 static const struct snd_soc_dapm_route mt8195_rt1019_routes[] = {
140 	{ "Ext Spk", NULL, "Speaker" },
141 };
142 
143 static const struct snd_soc_dapm_route mt8195_max98390_routes[] = {
144 	{ "Left Spk", NULL, "Left BE_OUT" },
145 	{ "Right Spk", NULL, "Right BE_OUT" },
146 };
147 
148 #define CKSYS_AUD_TOP_CFG 0x032c
149 #define CKSYS_AUD_TOP_MON 0x0330
150 
151 static int mt8195_mt6359_mtkaif_calibration(struct snd_soc_pcm_runtime *rtd)
152 {
153 	struct snd_soc_component *cmpnt_afe =
154 		snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
155 	struct snd_soc_component *cmpnt_codec =
156 		snd_soc_rtd_to_codec(rtd, 0)->component;
157 	struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe);
158 	struct mt8195_afe_private *afe_priv = afe->platform_priv;
159 	struct mtkaif_param *param = &afe_priv->mtkaif_params;
160 	int chosen_phase_1, chosen_phase_2, chosen_phase_3;
161 	int prev_cycle_1, prev_cycle_2, prev_cycle_3;
162 	int test_done_1, test_done_2, test_done_3;
163 	int cycle_1, cycle_2, cycle_3;
164 	int mtkaif_chosen_phase[MT8195_MTKAIF_MISO_NUM];
165 	int mtkaif_phase_cycle[MT8195_MTKAIF_MISO_NUM];
166 	int mtkaif_calibration_num_phase;
167 	bool mtkaif_calibration_ok;
168 	unsigned int monitor = 0;
169 	int counter;
170 	int phase;
171 	int i;
172 
173 	dev_dbg(afe->dev, "%s(), start\n", __func__);
174 
175 	param->mtkaif_calibration_ok = false;
176 	for (i = 0; i < MT8195_MTKAIF_MISO_NUM; i++) {
177 		param->mtkaif_chosen_phase[i] = -1;
178 		param->mtkaif_phase_cycle[i] = 0;
179 		mtkaif_chosen_phase[i] = -1;
180 		mtkaif_phase_cycle[i] = 0;
181 	}
182 
183 	if (IS_ERR(afe_priv->topckgen)) {
184 		dev_info(afe->dev, "%s() Cannot find topckgen controller\n",
185 			 __func__);
186 		return 0;
187 	}
188 
189 	pm_runtime_get_sync(afe->dev);
190 	mt6359_mtkaif_calibration_enable(cmpnt_codec);
191 
192 	/* set test type to synchronizer pulse */
193 	regmap_update_bits(afe_priv->topckgen,
194 			   CKSYS_AUD_TOP_CFG, 0xffff, 0x4);
195 	mtkaif_calibration_num_phase = 42;	/* mt6359: 0 ~ 42 */
196 	mtkaif_calibration_ok = true;
197 
198 	for (phase = 0;
199 	     phase <= mtkaif_calibration_num_phase && mtkaif_calibration_ok;
200 	     phase++) {
201 		mt6359_set_mtkaif_calibration_phase(cmpnt_codec,
202 						    phase, phase, phase);
203 
204 		regmap_update_bits(afe_priv->topckgen,
205 				   CKSYS_AUD_TOP_CFG, 0x1, 0x1);
206 
207 		test_done_1 = 0;
208 		test_done_2 = 0;
209 		test_done_3 = 0;
210 		cycle_1 = -1;
211 		cycle_2 = -1;
212 		cycle_3 = -1;
213 		counter = 0;
214 		while (!(test_done_1 & test_done_2 & test_done_3)) {
215 			regmap_read(afe_priv->topckgen,
216 				    CKSYS_AUD_TOP_MON, &monitor);
217 			test_done_1 = (monitor >> 28) & 0x1;
218 			test_done_2 = (monitor >> 29) & 0x1;
219 			test_done_3 = (monitor >> 30) & 0x1;
220 			if (test_done_1 == 1)
221 				cycle_1 = monitor & 0xf;
222 
223 			if (test_done_2 == 1)
224 				cycle_2 = (monitor >> 4) & 0xf;
225 
226 			if (test_done_3 == 1)
227 				cycle_3 = (monitor >> 8) & 0xf;
228 
229 			/* handle if never test done */
230 			if (++counter > 10000) {
231 				dev_info(afe->dev, "%s(), test fail, cycle_1 %d, cycle_2 %d, cycle_3 %d, monitor 0x%x\n",
232 					 __func__,
233 					 cycle_1, cycle_2, cycle_3, monitor);
234 				mtkaif_calibration_ok = false;
235 				break;
236 			}
237 		}
238 
239 		if (phase == 0) {
240 			prev_cycle_1 = cycle_1;
241 			prev_cycle_2 = cycle_2;
242 			prev_cycle_3 = cycle_3;
243 		}
244 
245 		if (cycle_1 != prev_cycle_1 &&
246 		    mtkaif_chosen_phase[MT8195_MTKAIF_MISO_0] < 0) {
247 			mtkaif_chosen_phase[MT8195_MTKAIF_MISO_0] = phase - 1;
248 			mtkaif_phase_cycle[MT8195_MTKAIF_MISO_0] = prev_cycle_1;
249 		}
250 
251 		if (cycle_2 != prev_cycle_2 &&
252 		    mtkaif_chosen_phase[MT8195_MTKAIF_MISO_1] < 0) {
253 			mtkaif_chosen_phase[MT8195_MTKAIF_MISO_1] = phase - 1;
254 			mtkaif_phase_cycle[MT8195_MTKAIF_MISO_1] = prev_cycle_2;
255 		}
256 
257 		if (cycle_3 != prev_cycle_3 &&
258 		    mtkaif_chosen_phase[MT8195_MTKAIF_MISO_2] < 0) {
259 			mtkaif_chosen_phase[MT8195_MTKAIF_MISO_2] = phase - 1;
260 			mtkaif_phase_cycle[MT8195_MTKAIF_MISO_2] = prev_cycle_3;
261 		}
262 
263 		regmap_update_bits(afe_priv->topckgen,
264 				   CKSYS_AUD_TOP_CFG, 0x1, 0x0);
265 
266 		if (mtkaif_chosen_phase[MT8195_MTKAIF_MISO_0] >= 0 &&
267 		    mtkaif_chosen_phase[MT8195_MTKAIF_MISO_1] >= 0 &&
268 		    mtkaif_chosen_phase[MT8195_MTKAIF_MISO_2] >= 0)
269 			break;
270 	}
271 
272 	if (mtkaif_chosen_phase[MT8195_MTKAIF_MISO_0] < 0) {
273 		mtkaif_calibration_ok = false;
274 		chosen_phase_1 = 0;
275 	} else {
276 		chosen_phase_1 = mtkaif_chosen_phase[MT8195_MTKAIF_MISO_0];
277 	}
278 
279 	if (mtkaif_chosen_phase[MT8195_MTKAIF_MISO_1] < 0) {
280 		mtkaif_calibration_ok = false;
281 		chosen_phase_2 = 0;
282 	} else {
283 		chosen_phase_2 = mtkaif_chosen_phase[MT8195_MTKAIF_MISO_1];
284 	}
285 
286 	if (mtkaif_chosen_phase[MT8195_MTKAIF_MISO_2] < 0) {
287 		mtkaif_calibration_ok = false;
288 		chosen_phase_3 = 0;
289 	} else {
290 		chosen_phase_3 = mtkaif_chosen_phase[MT8195_MTKAIF_MISO_2];
291 	}
292 
293 	mt6359_set_mtkaif_calibration_phase(cmpnt_codec,
294 					    chosen_phase_1,
295 					    chosen_phase_2,
296 					    chosen_phase_3);
297 
298 	mt6359_mtkaif_calibration_disable(cmpnt_codec);
299 	pm_runtime_put(afe->dev);
300 
301 	param->mtkaif_calibration_ok = mtkaif_calibration_ok;
302 	param->mtkaif_chosen_phase[MT8195_MTKAIF_MISO_0] = chosen_phase_1;
303 	param->mtkaif_chosen_phase[MT8195_MTKAIF_MISO_1] = chosen_phase_2;
304 	param->mtkaif_chosen_phase[MT8195_MTKAIF_MISO_2] = chosen_phase_3;
305 	for (i = 0; i < MT8195_MTKAIF_MISO_NUM; i++)
306 		param->mtkaif_phase_cycle[i] = mtkaif_phase_cycle[i];
307 
308 	dev_info(afe->dev, "%s(), end, calibration ok %d\n",
309 		 __func__, param->mtkaif_calibration_ok);
310 
311 	return 0;
312 }
313 
314 static int mt8195_mt6359_init(struct snd_soc_pcm_runtime *rtd)
315 {
316 	struct snd_soc_component *cmpnt_codec =
317 		snd_soc_rtd_to_codec(rtd, 0)->component;
318 
319 	/* set mtkaif protocol */
320 	mt6359_set_mtkaif_protocol(cmpnt_codec,
321 				   MT6359_MTKAIF_PROTOCOL_2_CLK_P2);
322 
323 	/* mtkaif calibration */
324 	mt8195_mt6359_mtkaif_calibration(rtd);
325 
326 	return 0;
327 }
328 
329 static int mt8195_hdmitx_dptx_startup(struct snd_pcm_substream *substream)
330 {
331 	return mtk_soundcard_startup(substream, MTK_CONSTRAINT_HDMIDP);
332 }
333 
334 static const struct snd_soc_ops mt8195_hdmitx_dptx_playback_ops = {
335 	.startup = mt8195_hdmitx_dptx_startup,
336 };
337 
338 static int mt8195_dptx_hw_params(struct snd_pcm_substream *substream,
339 				 struct snd_pcm_hw_params *params)
340 {
341 	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
342 	struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
343 
344 	return snd_soc_dai_set_sysclk(cpu_dai, 0, params_rate(params) * 256,
345 				      SND_SOC_CLOCK_OUT);
346 }
347 
348 static const struct snd_soc_ops mt8195_dptx_ops = {
349 	.hw_params = mt8195_dptx_hw_params,
350 };
351 
352 static int mt8195_dptx_codec_init(struct snd_soc_pcm_runtime *rtd)
353 {
354 	struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card);
355 	struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8195_JACK_DP];
356 	struct snd_soc_component *cmpnt_codec =
357 		snd_soc_rtd_to_codec(rtd, 0)->component;
358 	int ret;
359 
360 	ret = snd_soc_card_jack_new(rtd->card, "DP Jack", SND_JACK_LINEOUT, jack);
361 	if (ret)
362 		return ret;
363 
364 	return snd_soc_component_set_jack(cmpnt_codec, jack, NULL);
365 }
366 
367 static int mt8195_hdmi_codec_init(struct snd_soc_pcm_runtime *rtd)
368 {
369 	struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card);
370 	struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8195_JACK_HDMI];
371 	struct snd_soc_component *cmpnt_codec =
372 		snd_soc_rtd_to_codec(rtd, 0)->component;
373 	int ret;
374 
375 	ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT, jack);
376 	if (ret)
377 		return ret;
378 
379 	return snd_soc_component_set_jack(cmpnt_codec, jack, NULL);
380 }
381 
382 static int mt8195_dptx_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
383 				       struct snd_pcm_hw_params *params)
384 {
385 	/* fix BE i2s format to S24_LE, clean param mask first */
386 	snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT),
387 			     0, (__force unsigned int)SNDRV_PCM_FORMAT_LAST);
388 
389 	params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
390 
391 	return 0;
392 }
393 
394 static int mt8195_rt5682_etdm_hw_params(struct snd_pcm_substream *substream,
395 					struct snd_pcm_hw_params *params)
396 {
397 	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
398 	struct snd_soc_card *card = rtd->card;
399 	struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
400 	struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
401 	unsigned int rate = params_rate(params);
402 	int bitwidth;
403 	int ret;
404 
405 	bitwidth = snd_pcm_format_width(params_format(params));
406 	if (bitwidth < 0) {
407 		dev_err(card->dev, "invalid bit width: %d\n", bitwidth);
408 		return bitwidth;
409 	}
410 
411 	ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x00, 0x0, 0x2, bitwidth);
412 	if (ret) {
413 		dev_err(card->dev, "failed to set tdm slot\n");
414 		return ret;
415 	}
416 
417 	ret = snd_soc_dai_set_pll(codec_dai, RT5682_PLL1, RT5682_PLL1_S_MCLK,
418 				  rate * 256, rate * 512);
419 	if (ret) {
420 		dev_err(card->dev, "failed to set pll\n");
421 		return ret;
422 	}
423 
424 	ret = snd_soc_dai_set_sysclk(codec_dai, RT5682_SCLK_S_PLL1,
425 				     rate * 512, SND_SOC_CLOCK_IN);
426 	if (ret) {
427 		dev_err(card->dev, "failed to set sysclk\n");
428 		return ret;
429 	}
430 
431 	return snd_soc_dai_set_sysclk(cpu_dai, 0, rate * 256,
432 				      SND_SOC_CLOCK_OUT);
433 }
434 
435 static const struct snd_soc_ops mt8195_rt5682_etdm_ops = {
436 	.hw_params = mt8195_rt5682_etdm_hw_params,
437 };
438 
439 static int mt8195_rt5682_init(struct snd_soc_pcm_runtime *rtd)
440 {
441 	struct snd_soc_component *cmpnt_codec =
442 		snd_soc_rtd_to_codec(rtd, 0)->component;
443 	struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card);
444 	struct mt8195_mt6359_priv *priv = soc_card_data->mach_priv;
445 	struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8195_JACK_HEADSET];
446 	struct snd_soc_component *cmpnt_afe =
447 		snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
448 	struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe);
449 	struct mt8195_afe_private *afe_priv = afe->platform_priv;
450 	int ret;
451 
452 	priv->i2so1_mclk = afe_priv->clk[MT8195_CLK_TOP_APLL12_DIV2];
453 
454 	ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack",
455 				    SND_JACK_HEADSET | SND_JACK_BTN_0 |
456 				    SND_JACK_BTN_1 | SND_JACK_BTN_2 |
457 				    SND_JACK_BTN_3,
458 				    jack, mt8195_jack_pins,
459 				    ARRAY_SIZE(mt8195_jack_pins));
460 	if (ret) {
461 		dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
462 		return ret;
463 	}
464 
465 	snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
466 	snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
467 	snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
468 	snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
469 
470 	ret = snd_soc_component_set_jack(cmpnt_codec, jack, NULL);
471 	if (ret) {
472 		dev_err(rtd->dev, "Headset Jack set failed: %d\n", ret);
473 		return ret;
474 	}
475 
476 	return 0;
477 };
478 
479 static int mt8195_rt1011_etdm_hw_params(struct snd_pcm_substream *substream,
480 					struct snd_pcm_hw_params *params)
481 {
482 	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
483 	struct snd_soc_dai *codec_dai;
484 	struct snd_soc_card *card = rtd->card;
485 	int srate, i, ret;
486 
487 	srate = params_rate(params);
488 
489 	for_each_rtd_codec_dais(rtd, i, codec_dai) {
490 		ret = snd_soc_dai_set_pll(codec_dai, 0, RT1011_PLL1_S_BCLK,
491 					  64 * srate, 256 * srate);
492 		if (ret < 0) {
493 			dev_err(card->dev, "codec_dai clock not set\n");
494 			return ret;
495 		}
496 
497 		ret = snd_soc_dai_set_sysclk(codec_dai,
498 					     RT1011_FS_SYS_PRE_S_PLL1,
499 					     256 * srate, SND_SOC_CLOCK_IN);
500 		if (ret < 0) {
501 			dev_err(card->dev, "codec_dai clock not set\n");
502 			return ret;
503 		}
504 	}
505 	return 0;
506 }
507 
508 static const struct snd_soc_ops mt8195_rt1011_etdm_ops = {
509 	.hw_params = mt8195_rt1011_etdm_hw_params,
510 };
511 
512 static int mt8195_sof_be_hw_params(struct snd_pcm_substream *substream,
513 				   struct snd_pcm_hw_params *params)
514 {
515 	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
516 	struct snd_soc_component *cmpnt_afe = NULL;
517 	struct snd_soc_pcm_runtime *runtime;
518 
519 	/* find afe component */
520 	for_each_card_rtds(rtd->card, runtime) {
521 		cmpnt_afe = snd_soc_rtdcom_lookup(runtime, AFE_PCM_NAME);
522 		if (cmpnt_afe)
523 			break;
524 	}
525 
526 	if (cmpnt_afe && !pm_runtime_active(cmpnt_afe->dev)) {
527 		dev_err(rtd->dev, "afe pm runtime is not active!!\n");
528 		return -EINVAL;
529 	}
530 
531 	return 0;
532 }
533 
534 static const struct snd_soc_ops mt8195_sof_be_ops = {
535 	.hw_params = mt8195_sof_be_hw_params,
536 };
537 
538 static int mt8195_rt1011_init(struct snd_soc_pcm_runtime *rtd)
539 {
540 	struct snd_soc_card *card = rtd->card;
541 	int ret;
542 
543 	ret = snd_soc_dapm_new_controls(&card->dapm, mt8195_dual_speaker_widgets,
544 					ARRAY_SIZE(mt8195_dual_speaker_widgets));
545 	if (ret) {
546 		dev_err(rtd->dev, "unable to add dapm controls, ret %d\n", ret);
547 		/* Don't need to add routes if widget addition failed */
548 		return ret;
549 	}
550 
551 	ret = snd_soc_add_card_controls(card, mt8195_dual_speaker_controls,
552 					ARRAY_SIZE(mt8195_dual_speaker_controls));
553 	if (ret) {
554 		dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret);
555 		return ret;
556 	}
557 
558 	ret = snd_soc_dapm_add_routes(&card->dapm, mt8195_rt1011_routes,
559 				      ARRAY_SIZE(mt8195_rt1011_routes));
560 	if (ret)
561 		dev_err(rtd->dev, "unable to add dapm routes, ret %d\n", ret);
562 
563 	return ret;
564 }
565 
566 static int mt8195_dumb_amp_init(struct snd_soc_pcm_runtime *rtd)
567 {
568 	struct snd_soc_card *card = rtd->card;
569 	int ret;
570 
571 	ret = snd_soc_dapm_new_controls(&card->dapm, mt8195_speaker_widgets,
572 					ARRAY_SIZE(mt8195_speaker_widgets));
573 	if (ret) {
574 		dev_err(rtd->dev, "unable to add dapm controls, ret %d\n", ret);
575 		/* Don't need to add routes if widget addition failed */
576 		return ret;
577 	}
578 
579 	ret = snd_soc_add_card_controls(card, mt8195_speaker_controls,
580 					ARRAY_SIZE(mt8195_speaker_controls));
581 	if (ret) {
582 		dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret);
583 		return ret;
584 	}
585 
586 	return 0;
587 }
588 
589 static int mt8195_rt1019_init(struct snd_soc_pcm_runtime *rtd)
590 {
591 	struct snd_soc_card *card = rtd->card;
592 	int ret;
593 
594 	ret = mt8195_dumb_amp_init(rtd);
595 	if (ret)
596 		return ret;
597 
598 	ret = snd_soc_dapm_add_routes(&card->dapm, mt8195_rt1019_routes,
599 				      ARRAY_SIZE(mt8195_rt1019_routes));
600 	if (ret)
601 		dev_err(rtd->dev, "unable to add dapm routes, ret %d\n", ret);
602 
603 	return ret;
604 }
605 
606 static int mt8195_max98390_init(struct snd_soc_pcm_runtime *rtd)
607 {
608 	struct snd_soc_card *card = rtd->card;
609 	int ret;
610 
611 	ret = snd_soc_dapm_new_controls(&card->dapm, mt8195_dual_speaker_widgets,
612 					ARRAY_SIZE(mt8195_dual_speaker_widgets));
613 	if (ret) {
614 		dev_err(rtd->dev, "unable to add dapm controls, ret %d\n", ret);
615 		/* Don't need to add routes if widget addition failed */
616 		return ret;
617 	}
618 
619 	ret = snd_soc_add_card_controls(card, mt8195_dual_speaker_controls,
620 					ARRAY_SIZE(mt8195_dual_speaker_controls));
621 	if (ret) {
622 		dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret);
623 		return ret;
624 	}
625 
626 	ret = snd_soc_dapm_add_routes(&card->dapm, mt8195_max98390_routes,
627 				      ARRAY_SIZE(mt8195_max98390_routes));
628 	if (ret)
629 		dev_err(rtd->dev, "unable to add dapm routes, ret %d\n", ret);
630 
631 	return ret;
632 }
633 
634 static int mt8195_etdm_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
635 				       struct snd_pcm_hw_params *params)
636 {
637 	/* fix BE i2s format to S24_LE, clean param mask first */
638 	snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT),
639 			     0, (__force unsigned int)SNDRV_PCM_FORMAT_LAST);
640 
641 	params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
642 
643 	return 0;
644 }
645 
646 static int mt8195_set_bias_level_post(struct snd_soc_card *card,
647 	struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level)
648 {
649 	struct snd_soc_component *component = dapm->component;
650 	struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(card);
651 	struct mt8195_mt6359_priv *priv = soc_card_data->mach_priv;
652 	int ret;
653 
654 	/*
655 	 * It's required to control mclk directly in the set_bias_level_post
656 	 * function for rt5682 and rt5682s codec, or the unexpected pop happens
657 	 * at the end of playback.
658 	 */
659 	if (!component ||
660 	    (strcmp(component->name, RT5682_DEV0_NAME) &&
661 	    strcmp(component->name, RT5682S_DEV0_NAME)))
662 		return 0;
663 
664 	switch (level) {
665 	case SND_SOC_BIAS_OFF:
666 		if (!__clk_is_enabled(priv->i2so1_mclk))
667 			return 0;
668 
669 		clk_disable_unprepare(priv->i2so1_mclk);
670 		dev_dbg(card->dev, "Disable i2so1 mclk\n");
671 		break;
672 	case SND_SOC_BIAS_ON:
673 		ret = clk_prepare_enable(priv->i2so1_mclk);
674 		if (ret) {
675 			dev_err(card->dev, "Can't enable i2so1 mclk: %d\n", ret);
676 			return ret;
677 		}
678 		dev_dbg(card->dev, "Enable i2so1 mclk\n");
679 		break;
680 	default:
681 		break;
682 	}
683 
684 	return 0;
685 }
686 
687 enum {
688 	DAI_LINK_DL2_FE,
689 	DAI_LINK_DL3_FE,
690 	DAI_LINK_DL6_FE,
691 	DAI_LINK_DL7_FE,
692 	DAI_LINK_DL8_FE,
693 	DAI_LINK_DL10_FE,
694 	DAI_LINK_DL11_FE,
695 	DAI_LINK_UL1_FE,
696 	DAI_LINK_UL2_FE,
697 	DAI_LINK_UL3_FE,
698 	DAI_LINK_UL4_FE,
699 	DAI_LINK_UL5_FE,
700 	DAI_LINK_UL6_FE,
701 	DAI_LINK_UL8_FE,
702 	DAI_LINK_UL9_FE,
703 	DAI_LINK_UL10_FE,
704 	DAI_LINK_DL_SRC_BE,
705 	DAI_LINK_DPTX_BE,
706 	DAI_LINK_ETDM1_IN_BE,
707 	DAI_LINK_ETDM2_IN_BE,
708 	DAI_LINK_ETDM1_OUT_BE,
709 	DAI_LINK_ETDM2_OUT_BE,
710 	DAI_LINK_ETDM3_OUT_BE,
711 	DAI_LINK_PCM1_BE,
712 	DAI_LINK_UL_SRC1_BE,
713 	DAI_LINK_UL_SRC2_BE,
714 	DAI_LINK_REGULAR_LAST = DAI_LINK_UL_SRC2_BE,
715 	DAI_LINK_SOF_START,
716 	DAI_LINK_SOF_DL2_BE = DAI_LINK_SOF_START,
717 	DAI_LINK_SOF_DL3_BE,
718 	DAI_LINK_SOF_UL4_BE,
719 	DAI_LINK_SOF_UL5_BE,
720 	DAI_LINK_SOF_END = DAI_LINK_SOF_UL5_BE,
721 };
722 
723 #define	DAI_LINK_REGULAR_NUM	(DAI_LINK_REGULAR_LAST + 1)
724 
725 /* FE */
726 SND_SOC_DAILINK_DEFS(DL2_FE,
727 		     DAILINK_COMP_ARRAY(COMP_CPU("DL2")),
728 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
729 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
730 
731 SND_SOC_DAILINK_DEFS(DL3_FE,
732 		     DAILINK_COMP_ARRAY(COMP_CPU("DL3")),
733 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
734 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
735 
736 SND_SOC_DAILINK_DEFS(DL6_FE,
737 		     DAILINK_COMP_ARRAY(COMP_CPU("DL6")),
738 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
739 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
740 
741 SND_SOC_DAILINK_DEFS(DL7_FE,
742 		     DAILINK_COMP_ARRAY(COMP_CPU("DL7")),
743 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
744 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
745 
746 SND_SOC_DAILINK_DEFS(DL8_FE,
747 		     DAILINK_COMP_ARRAY(COMP_CPU("DL8")),
748 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
749 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
750 
751 SND_SOC_DAILINK_DEFS(DL10_FE,
752 		     DAILINK_COMP_ARRAY(COMP_CPU("DL10")),
753 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
754 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
755 
756 SND_SOC_DAILINK_DEFS(DL11_FE,
757 		     DAILINK_COMP_ARRAY(COMP_CPU("DL11")),
758 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
759 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
760 
761 SND_SOC_DAILINK_DEFS(UL1_FE,
762 		     DAILINK_COMP_ARRAY(COMP_CPU("UL1")),
763 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
764 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
765 
766 SND_SOC_DAILINK_DEFS(UL2_FE,
767 		     DAILINK_COMP_ARRAY(COMP_CPU("UL2")),
768 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
769 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
770 
771 SND_SOC_DAILINK_DEFS(UL3_FE,
772 		     DAILINK_COMP_ARRAY(COMP_CPU("UL3")),
773 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
774 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
775 
776 SND_SOC_DAILINK_DEFS(UL4_FE,
777 		     DAILINK_COMP_ARRAY(COMP_CPU("UL4")),
778 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
779 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
780 
781 SND_SOC_DAILINK_DEFS(UL5_FE,
782 		     DAILINK_COMP_ARRAY(COMP_CPU("UL5")),
783 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
784 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
785 
786 SND_SOC_DAILINK_DEFS(UL6_FE,
787 		     DAILINK_COMP_ARRAY(COMP_CPU("UL6")),
788 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
789 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
790 
791 SND_SOC_DAILINK_DEFS(UL8_FE,
792 		     DAILINK_COMP_ARRAY(COMP_CPU("UL8")),
793 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
794 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
795 
796 SND_SOC_DAILINK_DEFS(UL9_FE,
797 		     DAILINK_COMP_ARRAY(COMP_CPU("UL9")),
798 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
799 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
800 
801 SND_SOC_DAILINK_DEFS(UL10_FE,
802 		     DAILINK_COMP_ARRAY(COMP_CPU("UL10")),
803 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
804 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
805 
806 /* BE */
807 SND_SOC_DAILINK_DEFS(DL_SRC_BE,
808 		     DAILINK_COMP_ARRAY(COMP_CPU("DL_SRC")),
809 		     DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
810 						   "mt6359-snd-codec-aif1")),
811 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
812 
813 SND_SOC_DAILINK_DEFS(DPTX_BE,
814 		     DAILINK_COMP_ARRAY(COMP_CPU("DPTX")),
815 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
816 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
817 
818 SND_SOC_DAILINK_DEFS(ETDM1_IN_BE,
819 		     DAILINK_COMP_ARRAY(COMP_CPU("ETDM1_IN")),
820 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
821 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
822 
823 SND_SOC_DAILINK_DEFS(ETDM2_IN_BE,
824 		     DAILINK_COMP_ARRAY(COMP_CPU("ETDM2_IN")),
825 		     DAILINK_COMP_ARRAY(COMP_EMPTY()),
826 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
827 
828 SND_SOC_DAILINK_DEFS(ETDM1_OUT_BE,
829 		     DAILINK_COMP_ARRAY(COMP_CPU("ETDM1_OUT")),
830 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
831 
832 SND_SOC_DAILINK_DEFS(ETDM2_OUT_BE,
833 		     DAILINK_COMP_ARRAY(COMP_CPU("ETDM2_OUT")),
834 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
835 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
836 
837 SND_SOC_DAILINK_DEFS(ETDM3_OUT_BE,
838 		     DAILINK_COMP_ARRAY(COMP_CPU("ETDM3_OUT")),
839 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
840 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
841 
842 SND_SOC_DAILINK_DEFS(PCM1_BE,
843 		     DAILINK_COMP_ARRAY(COMP_CPU("PCM1")),
844 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
845 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
846 
847 SND_SOC_DAILINK_DEFS(UL_SRC1_BE,
848 		     DAILINK_COMP_ARRAY(COMP_CPU("UL_SRC1")),
849 		     DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
850 						   "mt6359-snd-codec-aif1"),
851 					COMP_CODEC("dmic-codec",
852 						   "dmic-hifi")),
853 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
854 
855 SND_SOC_DAILINK_DEFS(UL_SRC2_BE,
856 		     DAILINK_COMP_ARRAY(COMP_CPU("UL_SRC2")),
857 		     DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
858 						   "mt6359-snd-codec-aif2")),
859 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
860 
861 SND_SOC_DAILINK_DEFS(AFE_SOF_DL2,
862 		     DAILINK_COMP_ARRAY(COMP_CPU("SOF_DL2")),
863 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
864 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
865 
866 SND_SOC_DAILINK_DEFS(AFE_SOF_DL3,
867 		     DAILINK_COMP_ARRAY(COMP_CPU("SOF_DL3")),
868 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
869 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
870 
871 SND_SOC_DAILINK_DEFS(AFE_SOF_UL4,
872 		     DAILINK_COMP_ARRAY(COMP_CPU("SOF_UL4")),
873 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
874 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
875 
876 SND_SOC_DAILINK_DEFS(AFE_SOF_UL5,
877 		     DAILINK_COMP_ARRAY(COMP_CPU("SOF_UL5")),
878 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
879 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
880 
881 /* codec */
882 SND_SOC_DAILINK_DEF(rt1019_comps,
883 		    DAILINK_COMP_ARRAY(COMP_CODEC(RT1019_DEV0_NAME,
884 						  RT1019_CODEC_DAI)));
885 
886 SND_SOC_DAILINK_DEF(rt1011_comps,
887 		    DAILINK_COMP_ARRAY(COMP_CODEC(RT1011_DEV0_NAME,
888 						  RT1011_CODEC_DAI),
889 				       COMP_CODEC(RT1011_DEV1_NAME,
890 						  RT1011_CODEC_DAI)));
891 
892 SND_SOC_DAILINK_DEF(max98390_comps,
893 		    DAILINK_COMP_ARRAY(COMP_CODEC(MAX98390_DEV0_NAME,
894 						  MAX98390_CODEC_DAI),
895 				       COMP_CODEC(MAX98390_DEV1_NAME,
896 						  MAX98390_CODEC_DAI)));
897 
898 static const struct sof_conn_stream g_sof_conn_streams[] = {
899 	{ "ETDM2_OUT_BE", "AFE_SOF_DL2", SOF_DMA_DL2, SNDRV_PCM_STREAM_PLAYBACK},
900 	{ "ETDM1_OUT_BE", "AFE_SOF_DL3", SOF_DMA_DL3, SNDRV_PCM_STREAM_PLAYBACK},
901 	{ "UL_SRC1_BE", "AFE_SOF_UL4", SOF_DMA_UL4, SNDRV_PCM_STREAM_CAPTURE},
902 	{ "ETDM2_IN_BE", "AFE_SOF_UL5", SOF_DMA_UL5, SNDRV_PCM_STREAM_CAPTURE},
903 };
904 
905 static struct snd_soc_dai_link mt8195_mt6359_dai_links[] = {
906 	/* FE */
907 	[DAI_LINK_DL2_FE] = {
908 		.name = "DL2_FE",
909 		.stream_name = "DL2 Playback",
910 		.trigger = {
911 			SND_SOC_DPCM_TRIGGER_POST,
912 			SND_SOC_DPCM_TRIGGER_POST,
913 		},
914 		.dynamic = 1,
915 		.dpcm_playback = 1,
916 		.ops = &mtk_soundcard_common_playback_ops,
917 		SND_SOC_DAILINK_REG(DL2_FE),
918 	},
919 	[DAI_LINK_DL3_FE] = {
920 		.name = "DL3_FE",
921 		.stream_name = "DL3 Playback",
922 		.trigger = {
923 			SND_SOC_DPCM_TRIGGER_POST,
924 			SND_SOC_DPCM_TRIGGER_POST,
925 		},
926 		.dynamic = 1,
927 		.dpcm_playback = 1,
928 		.ops = &mtk_soundcard_common_playback_ops,
929 		SND_SOC_DAILINK_REG(DL3_FE),
930 	},
931 	[DAI_LINK_DL6_FE] = {
932 		.name = "DL6_FE",
933 		.stream_name = "DL6 Playback",
934 		.trigger = {
935 			SND_SOC_DPCM_TRIGGER_POST,
936 			SND_SOC_DPCM_TRIGGER_POST,
937 		},
938 		.dynamic = 1,
939 		.dpcm_playback = 1,
940 		.ops = &mtk_soundcard_common_playback_ops,
941 		SND_SOC_DAILINK_REG(DL6_FE),
942 	},
943 	[DAI_LINK_DL7_FE] = {
944 		.name = "DL7_FE",
945 		.stream_name = "DL7 Playback",
946 		.trigger = {
947 			SND_SOC_DPCM_TRIGGER_PRE,
948 			SND_SOC_DPCM_TRIGGER_PRE,
949 		},
950 		.dynamic = 1,
951 		.dpcm_playback = 1,
952 		SND_SOC_DAILINK_REG(DL7_FE),
953 	},
954 	[DAI_LINK_DL8_FE] = {
955 		.name = "DL8_FE",
956 		.stream_name = "DL8 Playback",
957 		.trigger = {
958 			SND_SOC_DPCM_TRIGGER_POST,
959 			SND_SOC_DPCM_TRIGGER_POST,
960 		},
961 		.dynamic = 1,
962 		.dpcm_playback = 1,
963 		.ops = &mtk_soundcard_common_playback_ops,
964 		SND_SOC_DAILINK_REG(DL8_FE),
965 	},
966 	[DAI_LINK_DL10_FE] = {
967 		.name = "DL10_FE",
968 		.stream_name = "DL10 Playback",
969 		.trigger = {
970 			SND_SOC_DPCM_TRIGGER_POST,
971 			SND_SOC_DPCM_TRIGGER_POST,
972 		},
973 		.dynamic = 1,
974 		.dpcm_playback = 1,
975 		.ops = &mt8195_hdmitx_dptx_playback_ops,
976 		SND_SOC_DAILINK_REG(DL10_FE),
977 	},
978 	[DAI_LINK_DL11_FE] = {
979 		.name = "DL11_FE",
980 		.stream_name = "DL11 Playback",
981 		.trigger = {
982 			SND_SOC_DPCM_TRIGGER_POST,
983 			SND_SOC_DPCM_TRIGGER_POST,
984 		},
985 		.dynamic = 1,
986 		.dpcm_playback = 1,
987 		.ops = &mtk_soundcard_common_playback_ops,
988 		SND_SOC_DAILINK_REG(DL11_FE),
989 	},
990 	[DAI_LINK_UL1_FE] = {
991 		.name = "UL1_FE",
992 		.stream_name = "UL1 Capture",
993 		.trigger = {
994 			SND_SOC_DPCM_TRIGGER_PRE,
995 			SND_SOC_DPCM_TRIGGER_PRE,
996 		},
997 		.dynamic = 1,
998 		.dpcm_capture = 1,
999 		SND_SOC_DAILINK_REG(UL1_FE),
1000 	},
1001 	[DAI_LINK_UL2_FE] = {
1002 		.name = "UL2_FE",
1003 		.stream_name = "UL2 Capture",
1004 		.trigger = {
1005 			SND_SOC_DPCM_TRIGGER_POST,
1006 			SND_SOC_DPCM_TRIGGER_POST,
1007 		},
1008 		.dynamic = 1,
1009 		.dpcm_capture = 1,
1010 		.ops = &mtk_soundcard_common_capture_ops,
1011 		SND_SOC_DAILINK_REG(UL2_FE),
1012 	},
1013 	[DAI_LINK_UL3_FE] = {
1014 		.name = "UL3_FE",
1015 		.stream_name = "UL3 Capture",
1016 		.trigger = {
1017 			SND_SOC_DPCM_TRIGGER_POST,
1018 			SND_SOC_DPCM_TRIGGER_POST,
1019 		},
1020 		.dynamic = 1,
1021 		.dpcm_capture = 1,
1022 		.ops = &mtk_soundcard_common_capture_ops,
1023 		SND_SOC_DAILINK_REG(UL3_FE),
1024 	},
1025 	[DAI_LINK_UL4_FE] = {
1026 		.name = "UL4_FE",
1027 		.stream_name = "UL4 Capture",
1028 		.trigger = {
1029 			SND_SOC_DPCM_TRIGGER_POST,
1030 			SND_SOC_DPCM_TRIGGER_POST,
1031 		},
1032 		.dynamic = 1,
1033 		.dpcm_capture = 1,
1034 		.ops = &mtk_soundcard_common_capture_ops,
1035 		SND_SOC_DAILINK_REG(UL4_FE),
1036 	},
1037 	[DAI_LINK_UL5_FE] = {
1038 		.name = "UL5_FE",
1039 		.stream_name = "UL5 Capture",
1040 		.trigger = {
1041 			SND_SOC_DPCM_TRIGGER_POST,
1042 			SND_SOC_DPCM_TRIGGER_POST,
1043 		},
1044 		.dynamic = 1,
1045 		.dpcm_capture = 1,
1046 		.ops = &mtk_soundcard_common_capture_ops,
1047 		SND_SOC_DAILINK_REG(UL5_FE),
1048 	},
1049 	[DAI_LINK_UL6_FE] = {
1050 		.name = "UL6_FE",
1051 		.stream_name = "UL6 Capture",
1052 		.trigger = {
1053 			SND_SOC_DPCM_TRIGGER_PRE,
1054 			SND_SOC_DPCM_TRIGGER_PRE,
1055 		},
1056 		.dynamic = 1,
1057 		.dpcm_capture = 1,
1058 		SND_SOC_DAILINK_REG(UL6_FE),
1059 	},
1060 	[DAI_LINK_UL8_FE] = {
1061 		.name = "UL8_FE",
1062 		.stream_name = "UL8 Capture",
1063 		.trigger = {
1064 			SND_SOC_DPCM_TRIGGER_POST,
1065 			SND_SOC_DPCM_TRIGGER_POST,
1066 		},
1067 		.dynamic = 1,
1068 		.dpcm_capture = 1,
1069 		.ops = &mtk_soundcard_common_capture_ops,
1070 		SND_SOC_DAILINK_REG(UL8_FE),
1071 	},
1072 	[DAI_LINK_UL9_FE] = {
1073 		.name = "UL9_FE",
1074 		.stream_name = "UL9 Capture",
1075 		.trigger = {
1076 			SND_SOC_DPCM_TRIGGER_POST,
1077 			SND_SOC_DPCM_TRIGGER_POST,
1078 		},
1079 		.dynamic = 1,
1080 		.dpcm_capture = 1,
1081 		.ops = &mtk_soundcard_common_capture_ops,
1082 		SND_SOC_DAILINK_REG(UL9_FE),
1083 	},
1084 	[DAI_LINK_UL10_FE] = {
1085 		.name = "UL10_FE",
1086 		.stream_name = "UL10 Capture",
1087 		.trigger = {
1088 			SND_SOC_DPCM_TRIGGER_POST,
1089 			SND_SOC_DPCM_TRIGGER_POST,
1090 		},
1091 		.dynamic = 1,
1092 		.dpcm_capture = 1,
1093 		.ops = &mtk_soundcard_common_capture_ops,
1094 		SND_SOC_DAILINK_REG(UL10_FE),
1095 	},
1096 	/* BE */
1097 	[DAI_LINK_DL_SRC_BE] = {
1098 		.name = "DL_SRC_BE",
1099 		.no_pcm = 1,
1100 		.dpcm_playback = 1,
1101 		SND_SOC_DAILINK_REG(DL_SRC_BE),
1102 	},
1103 	[DAI_LINK_DPTX_BE] = {
1104 		.name = "DPTX_BE",
1105 		.no_pcm = 1,
1106 		.dpcm_playback = 1,
1107 		.ops = &mt8195_dptx_ops,
1108 		.be_hw_params_fixup = mt8195_dptx_hw_params_fixup,
1109 		SND_SOC_DAILINK_REG(DPTX_BE),
1110 	},
1111 	[DAI_LINK_ETDM1_IN_BE] = {
1112 		.name = "ETDM1_IN_BE",
1113 		.no_pcm = 1,
1114 		.dai_fmt = SND_SOC_DAIFMT_I2S |
1115 			SND_SOC_DAIFMT_NB_NF |
1116 			SND_SOC_DAIFMT_CBS_CFS,
1117 		.dpcm_capture = 1,
1118 		SND_SOC_DAILINK_REG(ETDM1_IN_BE),
1119 	},
1120 	[DAI_LINK_ETDM2_IN_BE] = {
1121 		.name = "ETDM2_IN_BE",
1122 		.no_pcm = 1,
1123 		.dai_fmt = SND_SOC_DAIFMT_I2S |
1124 			SND_SOC_DAIFMT_NB_NF |
1125 			SND_SOC_DAIFMT_CBS_CFS,
1126 		.dpcm_capture = 1,
1127 		.be_hw_params_fixup = mt8195_etdm_hw_params_fixup,
1128 		SND_SOC_DAILINK_REG(ETDM2_IN_BE),
1129 	},
1130 	[DAI_LINK_ETDM1_OUT_BE] = {
1131 		.name = "ETDM1_OUT_BE",
1132 		.no_pcm = 1,
1133 		.dai_fmt = SND_SOC_DAIFMT_I2S |
1134 			SND_SOC_DAIFMT_NB_NF |
1135 			SND_SOC_DAIFMT_CBS_CFS,
1136 		.dpcm_playback = 1,
1137 		.be_hw_params_fixup = mt8195_etdm_hw_params_fixup,
1138 		SND_SOC_DAILINK_REG(ETDM1_OUT_BE),
1139 	},
1140 	[DAI_LINK_ETDM2_OUT_BE] = {
1141 		.name = "ETDM2_OUT_BE",
1142 		.no_pcm = 1,
1143 		.dai_fmt = SND_SOC_DAIFMT_I2S |
1144 			SND_SOC_DAIFMT_NB_NF |
1145 			SND_SOC_DAIFMT_CBS_CFS,
1146 		.dpcm_playback = 1,
1147 		SND_SOC_DAILINK_REG(ETDM2_OUT_BE),
1148 	},
1149 	[DAI_LINK_ETDM3_OUT_BE] = {
1150 		.name = "ETDM3_OUT_BE",
1151 		.no_pcm = 1,
1152 		.dai_fmt = SND_SOC_DAIFMT_I2S |
1153 			SND_SOC_DAIFMT_NB_NF |
1154 			SND_SOC_DAIFMT_CBS_CFS,
1155 		.dpcm_playback = 1,
1156 		SND_SOC_DAILINK_REG(ETDM3_OUT_BE),
1157 	},
1158 	[DAI_LINK_PCM1_BE] = {
1159 		.name = "PCM1_BE",
1160 		.no_pcm = 1,
1161 		.dai_fmt = SND_SOC_DAIFMT_I2S |
1162 			SND_SOC_DAIFMT_NB_NF |
1163 			SND_SOC_DAIFMT_CBS_CFS,
1164 		.dpcm_playback = 1,
1165 		.dpcm_capture = 1,
1166 		SND_SOC_DAILINK_REG(PCM1_BE),
1167 	},
1168 	[DAI_LINK_UL_SRC1_BE] = {
1169 		.name = "UL_SRC1_BE",
1170 		.no_pcm = 1,
1171 		.dpcm_capture = 1,
1172 		SND_SOC_DAILINK_REG(UL_SRC1_BE),
1173 	},
1174 	[DAI_LINK_UL_SRC2_BE] = {
1175 		.name = "UL_SRC2_BE",
1176 		.no_pcm = 1,
1177 		.dpcm_capture = 1,
1178 		SND_SOC_DAILINK_REG(UL_SRC2_BE),
1179 	},
1180 	/* SOF BE */
1181 	[DAI_LINK_SOF_DL2_BE] = {
1182 		.name = "AFE_SOF_DL2",
1183 		.no_pcm = 1,
1184 		.dpcm_playback = 1,
1185 		.ops = &mt8195_sof_be_ops,
1186 		SND_SOC_DAILINK_REG(AFE_SOF_DL2),
1187 	},
1188 	[DAI_LINK_SOF_DL3_BE] = {
1189 		.name = "AFE_SOF_DL3",
1190 		.no_pcm = 1,
1191 		.dpcm_playback = 1,
1192 		.ops = &mt8195_sof_be_ops,
1193 		SND_SOC_DAILINK_REG(AFE_SOF_DL3),
1194 	},
1195 	[DAI_LINK_SOF_UL4_BE] = {
1196 		.name = "AFE_SOF_UL4",
1197 		.no_pcm = 1,
1198 		.dpcm_capture = 1,
1199 		.ops = &mt8195_sof_be_ops,
1200 		SND_SOC_DAILINK_REG(AFE_SOF_UL4),
1201 	},
1202 	[DAI_LINK_SOF_UL5_BE] = {
1203 		.name = "AFE_SOF_UL5",
1204 		.no_pcm = 1,
1205 		.dpcm_capture = 1,
1206 		.ops = &mt8195_sof_be_ops,
1207 		SND_SOC_DAILINK_REG(AFE_SOF_UL5),
1208 	},
1209 };
1210 
1211 static struct snd_soc_codec_conf rt1011_codec_conf[] = {
1212 	{
1213 		.dlc = COMP_CODEC_CONF(RT1011_DEV0_NAME),
1214 		.name_prefix = "Left",
1215 	},
1216 	{
1217 		.dlc = COMP_CODEC_CONF(RT1011_DEV1_NAME),
1218 		.name_prefix = "Right",
1219 	},
1220 };
1221 
1222 static struct snd_soc_codec_conf max98390_codec_conf[] = {
1223 	{
1224 		.dlc = COMP_CODEC_CONF(MAX98390_DEV0_NAME),
1225 		.name_prefix = "Right",
1226 	},
1227 	{
1228 		.dlc = COMP_CODEC_CONF(MAX98390_DEV1_NAME),
1229 		.name_prefix = "Left",
1230 	},
1231 };
1232 
1233 static struct snd_soc_card mt8195_mt6359_soc_card = {
1234 	.owner = THIS_MODULE,
1235 	.dai_link = mt8195_mt6359_dai_links,
1236 	.num_links = ARRAY_SIZE(mt8195_mt6359_dai_links),
1237 	.controls = mt8195_mt6359_controls,
1238 	.num_controls = ARRAY_SIZE(mt8195_mt6359_controls),
1239 	.dapm_widgets = mt8195_mt6359_widgets,
1240 	.num_dapm_widgets = ARRAY_SIZE(mt8195_mt6359_widgets),
1241 	.dapm_routes = mt8195_mt6359_routes,
1242 	.num_dapm_routes = ARRAY_SIZE(mt8195_mt6359_routes),
1243 	.set_bias_level_post = mt8195_set_bias_level_post,
1244 };
1245 
1246 /* fixup the BE DAI link to match any values from topology */
1247 static int mt8195_dai_link_fixup(struct snd_soc_pcm_runtime *rtd,
1248 				 struct snd_pcm_hw_params *params)
1249 {
1250 	int ret;
1251 
1252 	ret = mtk_sof_dai_link_fixup(rtd, params);
1253 
1254 	if (!strcmp(rtd->dai_link->name, "ETDM2_IN_BE") ||
1255 	    !strcmp(rtd->dai_link->name, "ETDM1_OUT_BE")) {
1256 		mt8195_etdm_hw_params_fixup(rtd, params);
1257 	}
1258 
1259 	return ret;
1260 }
1261 
1262 static int mt8195_mt6359_legacy_probe(struct mtk_soc_card_data *soc_card_data)
1263 {
1264 	struct mtk_platform_card_data *card_data = soc_card_data->card_data;
1265 	struct snd_soc_card *card = card_data->card;
1266 	struct device_node *codec_node, *dp_node, *hdmi_node;
1267 	struct snd_soc_dai_link *dai_link;
1268 	struct device *dev = card->dev;
1269 	bool is5682s, init6359 = false;
1270 	int i;
1271 
1272 	if (strstr(card->name, "_5682s")) {
1273 		codec_node = of_find_compatible_node(NULL, NULL, "realtek,rt5682s");
1274 		is5682s = true;
1275 	} else {
1276 		codec_node = of_find_compatible_node(NULL, NULL, "realtek,rt5682i");
1277 		is5682s = false;
1278 	}
1279 
1280 	dp_node = of_parse_phandle(dev->of_node, "mediatek,dptx-codec", 0);
1281 	hdmi_node = of_parse_phandle(dev->of_node, "mediatek,hdmi-codec", 0);
1282 
1283 	for_each_card_prelinks(card, i, dai_link) {
1284 		if (strcmp(dai_link->name, "DPTX_BE") == 0) {
1285 			if (!dp_node) {
1286 				dev_dbg(dev, "No property 'dptx-codec'\n");
1287 			} else {
1288 				dai_link->codecs->of_node = dp_node;
1289 				dai_link->codecs->name = NULL;
1290 				dai_link->codecs->dai_name = "i2s-hifi";
1291 				dai_link->init = mt8195_dptx_codec_init;
1292 			}
1293 		} else if (strcmp(dai_link->name, "ETDM3_OUT_BE") == 0) {
1294 			if (!hdmi_node) {
1295 				dev_dbg(dev, "No property 'hdmi-codec'\n");
1296 			} else {
1297 				dai_link->codecs->of_node = hdmi_node;
1298 				dai_link->codecs->name = NULL;
1299 				dai_link->codecs->dai_name = "i2s-hifi";
1300 				dai_link->init = mt8195_hdmi_codec_init;
1301 			}
1302 		} else if (strcmp(dai_link->name, "ETDM1_OUT_BE") == 0) {
1303 			if (!codec_node) {
1304 				dev_err(dev, "Codec not found!\n");
1305 			} else {
1306 				dai_link->codecs->of_node = codec_node;
1307 				dai_link->codecs->name = NULL;
1308 				dai_link->codecs->dai_name =
1309 					is5682s ? RT5682S_CODEC_DAI : RT5682_CODEC_DAI;
1310 				dai_link->init = mt8195_rt5682_init;
1311 				dai_link->ops = &mt8195_rt5682_etdm_ops;
1312 			}
1313 		} else if (strcmp(dai_link->name, "ETDM2_IN_BE") == 0) {
1314 			if (!codec_node) {
1315 				dev_err(dev, "Codec not found!\n");
1316 			} else {
1317 				dai_link->codecs->of_node = codec_node;
1318 				dai_link->codecs->name = NULL;
1319 				dai_link->codecs->dai_name =
1320 					is5682s ? RT5682S_CODEC_DAI : RT5682_CODEC_DAI;
1321 				dai_link->ops = &mt8195_rt5682_etdm_ops;
1322 			}
1323 		} else if (strcmp(dai_link->name, "DL_SRC_BE") == 0 ||
1324 			   strcmp(dai_link->name, "UL_SRC1_BE") == 0 ||
1325 			   strcmp(dai_link->name, "UL_SRC2_BE") == 0) {
1326 			if (!init6359) {
1327 				dai_link->init = mt8195_mt6359_init;
1328 				init6359 = true;
1329 			}
1330 		} else if (strcmp(dai_link->name, "ETDM2_OUT_BE") == 0) {
1331 			switch (card_data->flags) {
1332 			case RT1011_SPEAKER_AMP_PRESENT:
1333 				dai_link->codecs = rt1011_comps;
1334 				dai_link->num_codecs = ARRAY_SIZE(rt1011_comps);
1335 				dai_link->init = mt8195_rt1011_init;
1336 				dai_link->ops = &mt8195_rt1011_etdm_ops;
1337 				dai_link->be_hw_params_fixup = mt8195_etdm_hw_params_fixup;
1338 				card->codec_conf = rt1011_codec_conf;
1339 				card->num_configs = ARRAY_SIZE(rt1011_codec_conf);
1340 				break;
1341 			case RT1019_SPEAKER_AMP_PRESENT:
1342 				dai_link->codecs = rt1019_comps;
1343 				dai_link->num_codecs = ARRAY_SIZE(rt1019_comps);
1344 				dai_link->init = mt8195_rt1019_init;
1345 				break;
1346 			case MAX98390_SPEAKER_AMP_PRESENT:
1347 				dai_link->codecs = max98390_comps;
1348 				dai_link->num_codecs = ARRAY_SIZE(max98390_comps);
1349 				dai_link->init = mt8195_max98390_init;
1350 				card->codec_conf = max98390_codec_conf;
1351 				card->num_configs = ARRAY_SIZE(max98390_codec_conf);
1352 				break;
1353 			default:
1354 				break;
1355 			}
1356 		}
1357 	}
1358 
1359 	return 0;
1360 }
1361 
1362 static int mt8195_mt6359_soc_card_probe(struct mtk_soc_card_data *soc_card_data, bool legacy)
1363 {
1364 	struct mtk_platform_card_data *card_data = soc_card_data->card_data;
1365 	struct snd_soc_card *card = card_data->card;
1366 	struct mt8195_mt6359_priv *mach_priv;
1367 	struct snd_soc_dai_link *dai_link;
1368 	u8 codec_init = 0;
1369 	int i;
1370 
1371 	mach_priv = devm_kzalloc(card->dev, sizeof(*mach_priv), GFP_KERNEL);
1372 	if (!mach_priv)
1373 		return -ENOMEM;
1374 
1375 	soc_card_data->mach_priv = mach_priv;
1376 
1377 	if (legacy)
1378 		return mt8195_mt6359_legacy_probe(soc_card_data);
1379 
1380 	for_each_card_prelinks(card, i, dai_link) {
1381 		if (strcmp(dai_link->name, "DPTX_BE") == 0) {
1382 			if (strcmp(dai_link->codecs->dai_name, "snd-soc-dummy-dai"))
1383 				dai_link->init = mt8195_dptx_codec_init;
1384 		} else if (strcmp(dai_link->name, "ETDM3_OUT_BE") == 0) {
1385 			if (strcmp(dai_link->codecs->dai_name, "snd-soc-dummy-dai"))
1386 				dai_link->init = mt8195_hdmi_codec_init;
1387 		} else if (strcmp(dai_link->name, "DL_SRC_BE") == 0 ||
1388 			   strcmp(dai_link->name, "UL_SRC1_BE") == 0 ||
1389 			   strcmp(dai_link->name, "UL_SRC2_BE") == 0) {
1390 			if (!(codec_init & MT6359_CODEC_INIT)) {
1391 				dai_link->init = mt8195_mt6359_init;
1392 				codec_init |= MT6359_CODEC_INIT;
1393 			}
1394 		} else if (strcmp(dai_link->name, "ETDM1_OUT_BE") == 0 ||
1395 			   strcmp(dai_link->name, "ETDM2_OUT_BE") == 0 ||
1396 			   strcmp(dai_link->name, "ETDM1_IN_BE") == 0 ||
1397 			   strcmp(dai_link->name, "ETDM2_IN_BE") == 0) {
1398 			if (!strcmp(dai_link->codecs->dai_name, MAX98390_CODEC_DAI)) {
1399 				if (!(codec_init & MAX98390_CODEC_INIT)) {
1400 					dai_link->init = mt8195_max98390_init;
1401 					codec_init |= MAX98390_CODEC_INIT;
1402 				}
1403 			} else if (!strcmp(dai_link->codecs->dai_name, RT1011_CODEC_DAI)) {
1404 				dai_link->ops = &mt8195_rt1011_etdm_ops;
1405 				if (!(codec_init & RT1011_CODEC_INIT)) {
1406 					dai_link->init = mt8195_rt1011_init;
1407 					codec_init |= RT1011_CODEC_INIT;
1408 				}
1409 			} else if (!strcmp(dai_link->codecs->dai_name, RT1019_CODEC_DAI)) {
1410 				if (!(codec_init & RT1019_CODEC_INIT)) {
1411 					dai_link->init = mt8195_rt1019_init;
1412 					codec_init |= RT1019_CODEC_INIT;
1413 				}
1414 			} else if (!strcmp(dai_link->codecs->dai_name, RT5682_CODEC_DAI) ||
1415 				   !strcmp(dai_link->codecs->dai_name, RT5682S_CODEC_DAI)) {
1416 				dai_link->ops = &mt8195_rt5682_etdm_ops;
1417 				if (!(codec_init & RT5682_CODEC_INIT)) {
1418 					dai_link->init = mt8195_rt5682_init;
1419 					codec_init |= RT5682_CODEC_INIT;
1420 				}
1421 			} else {
1422 				if (strcmp(dai_link->codecs->dai_name, "snd-soc-dummy-dai")) {
1423 					if (!(codec_init & DUMB_CODEC_INIT)) {
1424 						dai_link->init = mt8195_dumb_amp_init;
1425 						codec_init |= DUMB_CODEC_INIT;
1426 					}
1427 				}
1428 			}
1429 		}
1430 	}
1431 
1432 	return 0;
1433 }
1434 
1435 static const unsigned int mt8195_pcm_playback_channels[] = { 2 };
1436 static const unsigned int mt8195_pcm_capture_channels[] = { 1, 2 };
1437 static const unsigned int mt8195_pcm_hdmidp_channels[] = { 2, 4, 6, 8 };
1438 static const unsigned int mt8195_pcm_rates[] = { 48000 };
1439 
1440 static const struct snd_pcm_hw_constraint_list mt8195_rate_constraint = {
1441 	.list = mt8195_pcm_rates,
1442 	.count = ARRAY_SIZE(mt8195_pcm_rates)
1443 };
1444 
1445 static const struct mtk_pcm_constraints_data mt8195_pcm_constraints[MTK_CONSTRAINT_HDMIDP + 1] = {
1446 	[MTK_CONSTRAINT_PLAYBACK] = {
1447 		.channels = &(const struct snd_pcm_hw_constraint_list) {
1448 			.list = mt8195_pcm_playback_channels,
1449 			.count = ARRAY_SIZE(mt8195_pcm_playback_channels)
1450 		},
1451 		.rates = &mt8195_rate_constraint,
1452 	},
1453 	[MTK_CONSTRAINT_CAPTURE] = {
1454 		.channels =  &(const struct snd_pcm_hw_constraint_list) {
1455 			.list = mt8195_pcm_capture_channels,
1456 			.count = ARRAY_SIZE(mt8195_pcm_capture_channels)
1457 		},
1458 		.rates = &mt8195_rate_constraint,
1459 	},
1460 	[MTK_CONSTRAINT_HDMIDP] = {
1461 		.channels =  &(const struct snd_pcm_hw_constraint_list) {
1462 			.list = mt8195_pcm_hdmidp_channels,
1463 			.count = ARRAY_SIZE(mt8195_pcm_hdmidp_channels)
1464 		},
1465 		.rates = &mt8195_rate_constraint,
1466 	},
1467 };
1468 
1469 static const struct mtk_sof_priv mt8195_sof_priv = {
1470 	.conn_streams = g_sof_conn_streams,
1471 	.num_streams = ARRAY_SIZE(g_sof_conn_streams),
1472 	.sof_dai_link_fixup = mt8195_dai_link_fixup
1473 };
1474 
1475 static const struct mtk_soundcard_pdata mt8195_mt6359_rt1019_rt5682_card = {
1476 	.card_name = "mt8195_r1019_5682",
1477 	.card_data = &(struct mtk_platform_card_data) {
1478 		.card = &mt8195_mt6359_soc_card,
1479 		.num_jacks = MT8195_JACK_MAX,
1480 		.pcm_constraints = mt8195_pcm_constraints,
1481 		.num_pcm_constraints = ARRAY_SIZE(mt8195_pcm_constraints),
1482 		.flags = RT1019_SPEAKER_AMP_PRESENT
1483 	},
1484 	.sof_priv = &mt8195_sof_priv,
1485 	.soc_probe = mt8195_mt6359_soc_card_probe
1486 };
1487 
1488 static const struct mtk_soundcard_pdata mt8195_mt6359_rt1011_rt5682_card = {
1489 	.card_name = "mt8195_r1011_5682",
1490 	.card_data = &(struct mtk_platform_card_data) {
1491 		.card = &mt8195_mt6359_soc_card,
1492 		.num_jacks = MT8195_JACK_MAX,
1493 		.pcm_constraints = mt8195_pcm_constraints,
1494 		.num_pcm_constraints = ARRAY_SIZE(mt8195_pcm_constraints),
1495 		.flags = RT1011_SPEAKER_AMP_PRESENT
1496 	},
1497 	.sof_priv = &mt8195_sof_priv,
1498 	.soc_probe = mt8195_mt6359_soc_card_probe
1499 };
1500 
1501 static const struct mtk_soundcard_pdata mt8195_mt6359_max98390_rt5682_card = {
1502 	.card_name = "mt8195_m98390_r5682",
1503 	.card_data = &(struct mtk_platform_card_data) {
1504 		.card = &mt8195_mt6359_soc_card,
1505 		.num_jacks = MT8195_JACK_MAX,
1506 		.pcm_constraints = mt8195_pcm_constraints,
1507 		.num_pcm_constraints = ARRAY_SIZE(mt8195_pcm_constraints),
1508 		.flags = MAX98390_SPEAKER_AMP_PRESENT
1509 	},
1510 	.sof_priv = &mt8195_sof_priv,
1511 	.soc_probe = mt8195_mt6359_soc_card_probe
1512 };
1513 
1514 static const struct of_device_id mt8195_mt6359_dt_match[] = {
1515 	{
1516 		.compatible = "mediatek,mt8195_mt6359_rt1019_rt5682",
1517 		.data = &mt8195_mt6359_rt1019_rt5682_card,
1518 	},
1519 	{
1520 		.compatible = "mediatek,mt8195_mt6359_rt1011_rt5682",
1521 		.data = &mt8195_mt6359_rt1011_rt5682_card,
1522 	},
1523 	{
1524 		.compatible = "mediatek,mt8195_mt6359_max98390_rt5682",
1525 		.data = &mt8195_mt6359_max98390_rt5682_card,
1526 	},
1527 	{},
1528 };
1529 MODULE_DEVICE_TABLE(of, mt8195_mt6359_dt_match);
1530 
1531 static struct platform_driver mt8195_mt6359_driver = {
1532 	.driver = {
1533 		.name = "mt8195_mt6359",
1534 		.of_match_table = mt8195_mt6359_dt_match,
1535 		.pm = &snd_soc_pm_ops,
1536 	},
1537 	.probe = mtk_soundcard_common_probe,
1538 };
1539 
1540 module_platform_driver(mt8195_mt6359_driver);
1541 
1542 /* Module information */
1543 MODULE_DESCRIPTION("MT8195-MT6359 ALSA SoC machine driver");
1544 MODULE_AUTHOR("Trevor Wu <trevor.wu@mediatek.com>");
1545 MODULE_AUTHOR("YC Hung <yc.hung@mediatek.com>");
1546 MODULE_LICENSE("GPL");
1547 MODULE_ALIAS("mt8195_mt6359 soc card");
1548