xref: /linux/sound/soc/mediatek/mt8195/mt8195-mt6359.c (revision 6e7fd890f1d6ac83805409e9c346240de2705584)
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 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
832 
833 SND_SOC_DAILINK_DEFS(ETDM2_OUT_BE,
834 		     DAILINK_COMP_ARRAY(COMP_CPU("ETDM2_OUT")),
835 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
836 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
837 
838 SND_SOC_DAILINK_DEFS(ETDM3_OUT_BE,
839 		     DAILINK_COMP_ARRAY(COMP_CPU("ETDM3_OUT")),
840 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
841 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
842 
843 SND_SOC_DAILINK_DEFS(PCM1_BE,
844 		     DAILINK_COMP_ARRAY(COMP_CPU("PCM1")),
845 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
846 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
847 
848 SND_SOC_DAILINK_DEFS(UL_SRC1_BE,
849 		     DAILINK_COMP_ARRAY(COMP_CPU("UL_SRC1")),
850 		     DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
851 						   "mt6359-snd-codec-aif1"),
852 					COMP_CODEC("dmic-codec",
853 						   "dmic-hifi")),
854 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
855 
856 SND_SOC_DAILINK_DEFS(UL_SRC2_BE,
857 		     DAILINK_COMP_ARRAY(COMP_CPU("UL_SRC2")),
858 		     DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
859 						   "mt6359-snd-codec-aif2")),
860 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
861 
862 SND_SOC_DAILINK_DEFS(AFE_SOF_DL2,
863 		     DAILINK_COMP_ARRAY(COMP_CPU("SOF_DL2")),
864 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
865 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
866 
867 SND_SOC_DAILINK_DEFS(AFE_SOF_DL3,
868 		     DAILINK_COMP_ARRAY(COMP_CPU("SOF_DL3")),
869 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
870 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
871 
872 SND_SOC_DAILINK_DEFS(AFE_SOF_UL4,
873 		     DAILINK_COMP_ARRAY(COMP_CPU("SOF_UL4")),
874 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
875 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
876 
877 SND_SOC_DAILINK_DEFS(AFE_SOF_UL5,
878 		     DAILINK_COMP_ARRAY(COMP_CPU("SOF_UL5")),
879 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
880 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
881 
882 /* codec */
883 SND_SOC_DAILINK_DEF(rt1019_comps,
884 		    DAILINK_COMP_ARRAY(COMP_CODEC(RT1019_DEV0_NAME,
885 						  RT1019_CODEC_DAI)));
886 
887 SND_SOC_DAILINK_DEF(rt1011_comps,
888 		    DAILINK_COMP_ARRAY(COMP_CODEC(RT1011_DEV0_NAME,
889 						  RT1011_CODEC_DAI),
890 				       COMP_CODEC(RT1011_DEV1_NAME,
891 						  RT1011_CODEC_DAI)));
892 
893 SND_SOC_DAILINK_DEF(max98390_comps,
894 		    DAILINK_COMP_ARRAY(COMP_CODEC(MAX98390_DEV0_NAME,
895 						  MAX98390_CODEC_DAI),
896 				       COMP_CODEC(MAX98390_DEV1_NAME,
897 						  MAX98390_CODEC_DAI)));
898 
899 static const struct sof_conn_stream g_sof_conn_streams[] = {
900 	{ "ETDM2_OUT_BE", "AFE_SOF_DL2", SOF_DMA_DL2, SNDRV_PCM_STREAM_PLAYBACK},
901 	{ "ETDM1_OUT_BE", "AFE_SOF_DL3", SOF_DMA_DL3, SNDRV_PCM_STREAM_PLAYBACK},
902 	{ "UL_SRC1_BE", "AFE_SOF_UL4", SOF_DMA_UL4, SNDRV_PCM_STREAM_CAPTURE},
903 	{ "ETDM2_IN_BE", "AFE_SOF_UL5", SOF_DMA_UL5, SNDRV_PCM_STREAM_CAPTURE},
904 };
905 
906 static struct snd_soc_dai_link mt8195_mt6359_dai_links[] = {
907 	/* FE */
908 	[DAI_LINK_DL2_FE] = {
909 		.name = "DL2_FE",
910 		.stream_name = "DL2 Playback",
911 		.trigger = {
912 			SND_SOC_DPCM_TRIGGER_POST,
913 			SND_SOC_DPCM_TRIGGER_POST,
914 		},
915 		.dynamic = 1,
916 		.dpcm_playback = 1,
917 		.ops = &mtk_soundcard_common_playback_ops,
918 		SND_SOC_DAILINK_REG(DL2_FE),
919 	},
920 	[DAI_LINK_DL3_FE] = {
921 		.name = "DL3_FE",
922 		.stream_name = "DL3 Playback",
923 		.trigger = {
924 			SND_SOC_DPCM_TRIGGER_POST,
925 			SND_SOC_DPCM_TRIGGER_POST,
926 		},
927 		.dynamic = 1,
928 		.dpcm_playback = 1,
929 		.ops = &mtk_soundcard_common_playback_ops,
930 		SND_SOC_DAILINK_REG(DL3_FE),
931 	},
932 	[DAI_LINK_DL6_FE] = {
933 		.name = "DL6_FE",
934 		.stream_name = "DL6 Playback",
935 		.trigger = {
936 			SND_SOC_DPCM_TRIGGER_POST,
937 			SND_SOC_DPCM_TRIGGER_POST,
938 		},
939 		.dynamic = 1,
940 		.dpcm_playback = 1,
941 		.ops = &mtk_soundcard_common_playback_ops,
942 		SND_SOC_DAILINK_REG(DL6_FE),
943 	},
944 	[DAI_LINK_DL7_FE] = {
945 		.name = "DL7_FE",
946 		.stream_name = "DL7 Playback",
947 		.trigger = {
948 			SND_SOC_DPCM_TRIGGER_PRE,
949 			SND_SOC_DPCM_TRIGGER_PRE,
950 		},
951 		.dynamic = 1,
952 		.dpcm_playback = 1,
953 		SND_SOC_DAILINK_REG(DL7_FE),
954 	},
955 	[DAI_LINK_DL8_FE] = {
956 		.name = "DL8_FE",
957 		.stream_name = "DL8 Playback",
958 		.trigger = {
959 			SND_SOC_DPCM_TRIGGER_POST,
960 			SND_SOC_DPCM_TRIGGER_POST,
961 		},
962 		.dynamic = 1,
963 		.dpcm_playback = 1,
964 		.ops = &mtk_soundcard_common_playback_ops,
965 		SND_SOC_DAILINK_REG(DL8_FE),
966 	},
967 	[DAI_LINK_DL10_FE] = {
968 		.name = "DL10_FE",
969 		.stream_name = "DL10 Playback",
970 		.trigger = {
971 			SND_SOC_DPCM_TRIGGER_POST,
972 			SND_SOC_DPCM_TRIGGER_POST,
973 		},
974 		.dynamic = 1,
975 		.dpcm_playback = 1,
976 		.ops = &mt8195_hdmitx_dptx_playback_ops,
977 		SND_SOC_DAILINK_REG(DL10_FE),
978 	},
979 	[DAI_LINK_DL11_FE] = {
980 		.name = "DL11_FE",
981 		.stream_name = "DL11 Playback",
982 		.trigger = {
983 			SND_SOC_DPCM_TRIGGER_POST,
984 			SND_SOC_DPCM_TRIGGER_POST,
985 		},
986 		.dynamic = 1,
987 		.dpcm_playback = 1,
988 		.ops = &mtk_soundcard_common_playback_ops,
989 		SND_SOC_DAILINK_REG(DL11_FE),
990 	},
991 	[DAI_LINK_UL1_FE] = {
992 		.name = "UL1_FE",
993 		.stream_name = "UL1 Capture",
994 		.trigger = {
995 			SND_SOC_DPCM_TRIGGER_PRE,
996 			SND_SOC_DPCM_TRIGGER_PRE,
997 		},
998 		.dynamic = 1,
999 		.dpcm_capture = 1,
1000 		SND_SOC_DAILINK_REG(UL1_FE),
1001 	},
1002 	[DAI_LINK_UL2_FE] = {
1003 		.name = "UL2_FE",
1004 		.stream_name = "UL2 Capture",
1005 		.trigger = {
1006 			SND_SOC_DPCM_TRIGGER_POST,
1007 			SND_SOC_DPCM_TRIGGER_POST,
1008 		},
1009 		.dynamic = 1,
1010 		.dpcm_capture = 1,
1011 		.ops = &mtk_soundcard_common_capture_ops,
1012 		SND_SOC_DAILINK_REG(UL2_FE),
1013 	},
1014 	[DAI_LINK_UL3_FE] = {
1015 		.name = "UL3_FE",
1016 		.stream_name = "UL3 Capture",
1017 		.trigger = {
1018 			SND_SOC_DPCM_TRIGGER_POST,
1019 			SND_SOC_DPCM_TRIGGER_POST,
1020 		},
1021 		.dynamic = 1,
1022 		.dpcm_capture = 1,
1023 		.ops = &mtk_soundcard_common_capture_ops,
1024 		SND_SOC_DAILINK_REG(UL3_FE),
1025 	},
1026 	[DAI_LINK_UL4_FE] = {
1027 		.name = "UL4_FE",
1028 		.stream_name = "UL4 Capture",
1029 		.trigger = {
1030 			SND_SOC_DPCM_TRIGGER_POST,
1031 			SND_SOC_DPCM_TRIGGER_POST,
1032 		},
1033 		.dynamic = 1,
1034 		.dpcm_capture = 1,
1035 		.ops = &mtk_soundcard_common_capture_ops,
1036 		SND_SOC_DAILINK_REG(UL4_FE),
1037 	},
1038 	[DAI_LINK_UL5_FE] = {
1039 		.name = "UL5_FE",
1040 		.stream_name = "UL5 Capture",
1041 		.trigger = {
1042 			SND_SOC_DPCM_TRIGGER_POST,
1043 			SND_SOC_DPCM_TRIGGER_POST,
1044 		},
1045 		.dynamic = 1,
1046 		.dpcm_capture = 1,
1047 		.ops = &mtk_soundcard_common_capture_ops,
1048 		SND_SOC_DAILINK_REG(UL5_FE),
1049 	},
1050 	[DAI_LINK_UL6_FE] = {
1051 		.name = "UL6_FE",
1052 		.stream_name = "UL6 Capture",
1053 		.trigger = {
1054 			SND_SOC_DPCM_TRIGGER_PRE,
1055 			SND_SOC_DPCM_TRIGGER_PRE,
1056 		},
1057 		.dynamic = 1,
1058 		.dpcm_capture = 1,
1059 		SND_SOC_DAILINK_REG(UL6_FE),
1060 	},
1061 	[DAI_LINK_UL8_FE] = {
1062 		.name = "UL8_FE",
1063 		.stream_name = "UL8 Capture",
1064 		.trigger = {
1065 			SND_SOC_DPCM_TRIGGER_POST,
1066 			SND_SOC_DPCM_TRIGGER_POST,
1067 		},
1068 		.dynamic = 1,
1069 		.dpcm_capture = 1,
1070 		.ops = &mtk_soundcard_common_capture_ops,
1071 		SND_SOC_DAILINK_REG(UL8_FE),
1072 	},
1073 	[DAI_LINK_UL9_FE] = {
1074 		.name = "UL9_FE",
1075 		.stream_name = "UL9 Capture",
1076 		.trigger = {
1077 			SND_SOC_DPCM_TRIGGER_POST,
1078 			SND_SOC_DPCM_TRIGGER_POST,
1079 		},
1080 		.dynamic = 1,
1081 		.dpcm_capture = 1,
1082 		.ops = &mtk_soundcard_common_capture_ops,
1083 		SND_SOC_DAILINK_REG(UL9_FE),
1084 	},
1085 	[DAI_LINK_UL10_FE] = {
1086 		.name = "UL10_FE",
1087 		.stream_name = "UL10 Capture",
1088 		.trigger = {
1089 			SND_SOC_DPCM_TRIGGER_POST,
1090 			SND_SOC_DPCM_TRIGGER_POST,
1091 		},
1092 		.dynamic = 1,
1093 		.dpcm_capture = 1,
1094 		.ops = &mtk_soundcard_common_capture_ops,
1095 		SND_SOC_DAILINK_REG(UL10_FE),
1096 	},
1097 	/* BE */
1098 	[DAI_LINK_DL_SRC_BE] = {
1099 		.name = "DL_SRC_BE",
1100 		.no_pcm = 1,
1101 		.dpcm_playback = 1,
1102 		SND_SOC_DAILINK_REG(DL_SRC_BE),
1103 	},
1104 	[DAI_LINK_DPTX_BE] = {
1105 		.name = "DPTX_BE",
1106 		.no_pcm = 1,
1107 		.dpcm_playback = 1,
1108 		.ops = &mt8195_dptx_ops,
1109 		.be_hw_params_fixup = mt8195_dptx_hw_params_fixup,
1110 		SND_SOC_DAILINK_REG(DPTX_BE),
1111 	},
1112 	[DAI_LINK_ETDM1_IN_BE] = {
1113 		.name = "ETDM1_IN_BE",
1114 		.no_pcm = 1,
1115 		.dai_fmt = SND_SOC_DAIFMT_I2S |
1116 			SND_SOC_DAIFMT_NB_NF |
1117 			SND_SOC_DAIFMT_CBS_CFS,
1118 		.dpcm_capture = 1,
1119 		SND_SOC_DAILINK_REG(ETDM1_IN_BE),
1120 	},
1121 	[DAI_LINK_ETDM2_IN_BE] = {
1122 		.name = "ETDM2_IN_BE",
1123 		.no_pcm = 1,
1124 		.dai_fmt = SND_SOC_DAIFMT_I2S |
1125 			SND_SOC_DAIFMT_NB_NF |
1126 			SND_SOC_DAIFMT_CBS_CFS,
1127 		.dpcm_capture = 1,
1128 		.be_hw_params_fixup = mt8195_etdm_hw_params_fixup,
1129 		SND_SOC_DAILINK_REG(ETDM2_IN_BE),
1130 	},
1131 	[DAI_LINK_ETDM1_OUT_BE] = {
1132 		.name = "ETDM1_OUT_BE",
1133 		.no_pcm = 1,
1134 		.dai_fmt = SND_SOC_DAIFMT_I2S |
1135 			SND_SOC_DAIFMT_NB_NF |
1136 			SND_SOC_DAIFMT_CBS_CFS,
1137 		.dpcm_playback = 1,
1138 		.be_hw_params_fixup = mt8195_etdm_hw_params_fixup,
1139 		SND_SOC_DAILINK_REG(ETDM1_OUT_BE),
1140 	},
1141 	[DAI_LINK_ETDM2_OUT_BE] = {
1142 		.name = "ETDM2_OUT_BE",
1143 		.no_pcm = 1,
1144 		.dai_fmt = SND_SOC_DAIFMT_I2S |
1145 			SND_SOC_DAIFMT_NB_NF |
1146 			SND_SOC_DAIFMT_CBS_CFS,
1147 		.dpcm_playback = 1,
1148 		SND_SOC_DAILINK_REG(ETDM2_OUT_BE),
1149 	},
1150 	[DAI_LINK_ETDM3_OUT_BE] = {
1151 		.name = "ETDM3_OUT_BE",
1152 		.no_pcm = 1,
1153 		.dai_fmt = SND_SOC_DAIFMT_I2S |
1154 			SND_SOC_DAIFMT_NB_NF |
1155 			SND_SOC_DAIFMT_CBS_CFS,
1156 		.dpcm_playback = 1,
1157 		SND_SOC_DAILINK_REG(ETDM3_OUT_BE),
1158 	},
1159 	[DAI_LINK_PCM1_BE] = {
1160 		.name = "PCM1_BE",
1161 		.no_pcm = 1,
1162 		.dai_fmt = SND_SOC_DAIFMT_I2S |
1163 			SND_SOC_DAIFMT_NB_NF |
1164 			SND_SOC_DAIFMT_CBS_CFS,
1165 		.dpcm_playback = 1,
1166 		.dpcm_capture = 1,
1167 		SND_SOC_DAILINK_REG(PCM1_BE),
1168 	},
1169 	[DAI_LINK_UL_SRC1_BE] = {
1170 		.name = "UL_SRC1_BE",
1171 		.no_pcm = 1,
1172 		.dpcm_capture = 1,
1173 		SND_SOC_DAILINK_REG(UL_SRC1_BE),
1174 	},
1175 	[DAI_LINK_UL_SRC2_BE] = {
1176 		.name = "UL_SRC2_BE",
1177 		.no_pcm = 1,
1178 		.dpcm_capture = 1,
1179 		SND_SOC_DAILINK_REG(UL_SRC2_BE),
1180 	},
1181 	/* SOF BE */
1182 	[DAI_LINK_SOF_DL2_BE] = {
1183 		.name = "AFE_SOF_DL2",
1184 		.no_pcm = 1,
1185 		.dpcm_playback = 1,
1186 		.ops = &mt8195_sof_be_ops,
1187 		SND_SOC_DAILINK_REG(AFE_SOF_DL2),
1188 	},
1189 	[DAI_LINK_SOF_DL3_BE] = {
1190 		.name = "AFE_SOF_DL3",
1191 		.no_pcm = 1,
1192 		.dpcm_playback = 1,
1193 		.ops = &mt8195_sof_be_ops,
1194 		SND_SOC_DAILINK_REG(AFE_SOF_DL3),
1195 	},
1196 	[DAI_LINK_SOF_UL4_BE] = {
1197 		.name = "AFE_SOF_UL4",
1198 		.no_pcm = 1,
1199 		.dpcm_capture = 1,
1200 		.ops = &mt8195_sof_be_ops,
1201 		SND_SOC_DAILINK_REG(AFE_SOF_UL4),
1202 	},
1203 	[DAI_LINK_SOF_UL5_BE] = {
1204 		.name = "AFE_SOF_UL5",
1205 		.no_pcm = 1,
1206 		.dpcm_capture = 1,
1207 		.ops = &mt8195_sof_be_ops,
1208 		SND_SOC_DAILINK_REG(AFE_SOF_UL5),
1209 	},
1210 };
1211 
1212 static struct snd_soc_codec_conf rt1011_codec_conf[] = {
1213 	{
1214 		.dlc = COMP_CODEC_CONF(RT1011_DEV0_NAME),
1215 		.name_prefix = "Left",
1216 	},
1217 	{
1218 		.dlc = COMP_CODEC_CONF(RT1011_DEV1_NAME),
1219 		.name_prefix = "Right",
1220 	},
1221 };
1222 
1223 static struct snd_soc_codec_conf max98390_codec_conf[] = {
1224 	{
1225 		.dlc = COMP_CODEC_CONF(MAX98390_DEV0_NAME),
1226 		.name_prefix = "Right",
1227 	},
1228 	{
1229 		.dlc = COMP_CODEC_CONF(MAX98390_DEV1_NAME),
1230 		.name_prefix = "Left",
1231 	},
1232 };
1233 
1234 static struct snd_soc_card mt8195_mt6359_soc_card = {
1235 	.owner = THIS_MODULE,
1236 	.dai_link = mt8195_mt6359_dai_links,
1237 	.num_links = ARRAY_SIZE(mt8195_mt6359_dai_links),
1238 	.controls = mt8195_mt6359_controls,
1239 	.num_controls = ARRAY_SIZE(mt8195_mt6359_controls),
1240 	.dapm_widgets = mt8195_mt6359_widgets,
1241 	.num_dapm_widgets = ARRAY_SIZE(mt8195_mt6359_widgets),
1242 	.dapm_routes = mt8195_mt6359_routes,
1243 	.num_dapm_routes = ARRAY_SIZE(mt8195_mt6359_routes),
1244 	.set_bias_level_post = mt8195_set_bias_level_post,
1245 };
1246 
1247 /* fixup the BE DAI link to match any values from topology */
1248 static int mt8195_dai_link_fixup(struct snd_soc_pcm_runtime *rtd,
1249 				 struct snd_pcm_hw_params *params)
1250 {
1251 	int ret;
1252 
1253 	ret = mtk_sof_dai_link_fixup(rtd, params);
1254 
1255 	if (!strcmp(rtd->dai_link->name, "ETDM2_IN_BE") ||
1256 	    !strcmp(rtd->dai_link->name, "ETDM1_OUT_BE")) {
1257 		mt8195_etdm_hw_params_fixup(rtd, params);
1258 	}
1259 
1260 	return ret;
1261 }
1262 
1263 static int mt8195_mt6359_legacy_probe(struct mtk_soc_card_data *soc_card_data)
1264 {
1265 	struct mtk_platform_card_data *card_data = soc_card_data->card_data;
1266 	struct snd_soc_card *card = card_data->card;
1267 	struct device_node *codec_node, *dp_node, *hdmi_node;
1268 	struct snd_soc_dai_link *dai_link;
1269 	struct device *dev = card->dev;
1270 	bool is5682s, init6359 = false;
1271 	int i;
1272 
1273 	if (strstr(card->name, "_5682s")) {
1274 		codec_node = of_find_compatible_node(NULL, NULL, "realtek,rt5682s");
1275 		is5682s = true;
1276 	} else {
1277 		codec_node = of_find_compatible_node(NULL, NULL, "realtek,rt5682i");
1278 		is5682s = false;
1279 	}
1280 
1281 	dp_node = of_parse_phandle(dev->of_node, "mediatek,dptx-codec", 0);
1282 	hdmi_node = of_parse_phandle(dev->of_node, "mediatek,hdmi-codec", 0);
1283 
1284 	for_each_card_prelinks(card, i, dai_link) {
1285 		if (strcmp(dai_link->name, "DPTX_BE") == 0) {
1286 			if (!dp_node) {
1287 				dev_dbg(dev, "No property 'dptx-codec'\n");
1288 			} else {
1289 				dai_link->codecs->of_node = dp_node;
1290 				dai_link->codecs->name = NULL;
1291 				dai_link->codecs->dai_name = "i2s-hifi";
1292 				dai_link->init = mt8195_dptx_codec_init;
1293 			}
1294 		} else if (strcmp(dai_link->name, "ETDM3_OUT_BE") == 0) {
1295 			if (!hdmi_node) {
1296 				dev_dbg(dev, "No property 'hdmi-codec'\n");
1297 			} else {
1298 				dai_link->codecs->of_node = hdmi_node;
1299 				dai_link->codecs->name = NULL;
1300 				dai_link->codecs->dai_name = "i2s-hifi";
1301 				dai_link->init = mt8195_hdmi_codec_init;
1302 			}
1303 		} else if (strcmp(dai_link->name, "ETDM1_OUT_BE") == 0) {
1304 			if (!codec_node) {
1305 				dev_err(dev, "Codec not found!\n");
1306 			} else {
1307 				dai_link->codecs->of_node = codec_node;
1308 				dai_link->codecs->name = NULL;
1309 				dai_link->codecs->dai_name =
1310 					is5682s ? RT5682S_CODEC_DAI : RT5682_CODEC_DAI;
1311 				dai_link->init = mt8195_rt5682_init;
1312 				dai_link->ops = &mt8195_rt5682_etdm_ops;
1313 			}
1314 		} else if (strcmp(dai_link->name, "ETDM2_IN_BE") == 0) {
1315 			if (!codec_node) {
1316 				dev_err(dev, "Codec not found!\n");
1317 			} else {
1318 				dai_link->codecs->of_node = codec_node;
1319 				dai_link->codecs->name = NULL;
1320 				dai_link->codecs->dai_name =
1321 					is5682s ? RT5682S_CODEC_DAI : RT5682_CODEC_DAI;
1322 				dai_link->ops = &mt8195_rt5682_etdm_ops;
1323 			}
1324 		} else if (strcmp(dai_link->name, "DL_SRC_BE") == 0 ||
1325 			   strcmp(dai_link->name, "UL_SRC1_BE") == 0 ||
1326 			   strcmp(dai_link->name, "UL_SRC2_BE") == 0) {
1327 			if (!init6359) {
1328 				dai_link->init = mt8195_mt6359_init;
1329 				init6359 = true;
1330 			}
1331 		} else if (strcmp(dai_link->name, "ETDM2_OUT_BE") == 0) {
1332 			switch (card_data->flags) {
1333 			case RT1011_SPEAKER_AMP_PRESENT:
1334 				dai_link->codecs = rt1011_comps;
1335 				dai_link->num_codecs = ARRAY_SIZE(rt1011_comps);
1336 				dai_link->init = mt8195_rt1011_init;
1337 				dai_link->ops = &mt8195_rt1011_etdm_ops;
1338 				dai_link->be_hw_params_fixup = mt8195_etdm_hw_params_fixup;
1339 				card->codec_conf = rt1011_codec_conf;
1340 				card->num_configs = ARRAY_SIZE(rt1011_codec_conf);
1341 				break;
1342 			case RT1019_SPEAKER_AMP_PRESENT:
1343 				dai_link->codecs = rt1019_comps;
1344 				dai_link->num_codecs = ARRAY_SIZE(rt1019_comps);
1345 				dai_link->init = mt8195_rt1019_init;
1346 				break;
1347 			case MAX98390_SPEAKER_AMP_PRESENT:
1348 				dai_link->codecs = max98390_comps;
1349 				dai_link->num_codecs = ARRAY_SIZE(max98390_comps);
1350 				dai_link->init = mt8195_max98390_init;
1351 				card->codec_conf = max98390_codec_conf;
1352 				card->num_configs = ARRAY_SIZE(max98390_codec_conf);
1353 				break;
1354 			default:
1355 				break;
1356 			}
1357 		}
1358 	}
1359 
1360 	return 0;
1361 }
1362 
1363 static int mt8195_mt6359_soc_card_probe(struct mtk_soc_card_data *soc_card_data, bool legacy)
1364 {
1365 	struct mtk_platform_card_data *card_data = soc_card_data->card_data;
1366 	struct snd_soc_card *card = card_data->card;
1367 	struct mt8195_mt6359_priv *mach_priv;
1368 	struct snd_soc_dai_link *dai_link;
1369 	u8 codec_init = 0;
1370 	int i;
1371 
1372 	mach_priv = devm_kzalloc(card->dev, sizeof(*mach_priv), GFP_KERNEL);
1373 	if (!mach_priv)
1374 		return -ENOMEM;
1375 
1376 	soc_card_data->mach_priv = mach_priv;
1377 
1378 	if (legacy)
1379 		return mt8195_mt6359_legacy_probe(soc_card_data);
1380 
1381 	for_each_card_prelinks(card, i, dai_link) {
1382 		if (strcmp(dai_link->name, "DPTX_BE") == 0) {
1383 			if (strcmp(dai_link->codecs->dai_name, "snd-soc-dummy-dai"))
1384 				dai_link->init = mt8195_dptx_codec_init;
1385 		} else if (strcmp(dai_link->name, "ETDM3_OUT_BE") == 0) {
1386 			if (strcmp(dai_link->codecs->dai_name, "snd-soc-dummy-dai"))
1387 				dai_link->init = mt8195_hdmi_codec_init;
1388 		} else if (strcmp(dai_link->name, "DL_SRC_BE") == 0 ||
1389 			   strcmp(dai_link->name, "UL_SRC1_BE") == 0 ||
1390 			   strcmp(dai_link->name, "UL_SRC2_BE") == 0) {
1391 			if (!(codec_init & MT6359_CODEC_INIT)) {
1392 				dai_link->init = mt8195_mt6359_init;
1393 				codec_init |= MT6359_CODEC_INIT;
1394 			}
1395 		} else if (strcmp(dai_link->name, "ETDM1_OUT_BE") == 0 ||
1396 			   strcmp(dai_link->name, "ETDM2_OUT_BE") == 0 ||
1397 			   strcmp(dai_link->name, "ETDM1_IN_BE") == 0 ||
1398 			   strcmp(dai_link->name, "ETDM2_IN_BE") == 0) {
1399 			if (!strcmp(dai_link->codecs->dai_name, MAX98390_CODEC_DAI)) {
1400 				if (!(codec_init & MAX98390_CODEC_INIT)) {
1401 					dai_link->init = mt8195_max98390_init;
1402 					codec_init |= MAX98390_CODEC_INIT;
1403 				}
1404 			} else if (!strcmp(dai_link->codecs->dai_name, RT1011_CODEC_DAI)) {
1405 				dai_link->ops = &mt8195_rt1011_etdm_ops;
1406 				if (!(codec_init & RT1011_CODEC_INIT)) {
1407 					dai_link->init = mt8195_rt1011_init;
1408 					codec_init |= RT1011_CODEC_INIT;
1409 				}
1410 			} else if (!strcmp(dai_link->codecs->dai_name, RT1019_CODEC_DAI)) {
1411 				if (!(codec_init & RT1019_CODEC_INIT)) {
1412 					dai_link->init = mt8195_rt1019_init;
1413 					codec_init |= RT1019_CODEC_INIT;
1414 				}
1415 			} else if (!strcmp(dai_link->codecs->dai_name, RT5682_CODEC_DAI) ||
1416 				   !strcmp(dai_link->codecs->dai_name, RT5682S_CODEC_DAI)) {
1417 				dai_link->ops = &mt8195_rt5682_etdm_ops;
1418 				if (!(codec_init & RT5682_CODEC_INIT)) {
1419 					dai_link->init = mt8195_rt5682_init;
1420 					codec_init |= RT5682_CODEC_INIT;
1421 				}
1422 			} else {
1423 				if (strcmp(dai_link->codecs->dai_name, "snd-soc-dummy-dai")) {
1424 					if (!(codec_init & DUMB_CODEC_INIT)) {
1425 						dai_link->init = mt8195_dumb_amp_init;
1426 						codec_init |= DUMB_CODEC_INIT;
1427 					}
1428 				}
1429 			}
1430 		}
1431 	}
1432 
1433 	return 0;
1434 }
1435 
1436 static const unsigned int mt8195_pcm_playback_channels[] = { 2 };
1437 static const unsigned int mt8195_pcm_capture_channels[] = { 1, 2 };
1438 static const unsigned int mt8195_pcm_hdmidp_channels[] = { 2, 4, 6, 8 };
1439 static const unsigned int mt8195_pcm_rates[] = { 48000 };
1440 
1441 static const struct snd_pcm_hw_constraint_list mt8195_rate_constraint = {
1442 	.list = mt8195_pcm_rates,
1443 	.count = ARRAY_SIZE(mt8195_pcm_rates)
1444 };
1445 
1446 static const struct mtk_pcm_constraints_data mt8195_pcm_constraints[MTK_CONSTRAINT_HDMIDP + 1] = {
1447 	[MTK_CONSTRAINT_PLAYBACK] = {
1448 		.channels = &(const struct snd_pcm_hw_constraint_list) {
1449 			.list = mt8195_pcm_playback_channels,
1450 			.count = ARRAY_SIZE(mt8195_pcm_playback_channels)
1451 		},
1452 		.rates = &mt8195_rate_constraint,
1453 	},
1454 	[MTK_CONSTRAINT_CAPTURE] = {
1455 		.channels =  &(const struct snd_pcm_hw_constraint_list) {
1456 			.list = mt8195_pcm_capture_channels,
1457 			.count = ARRAY_SIZE(mt8195_pcm_capture_channels)
1458 		},
1459 		.rates = &mt8195_rate_constraint,
1460 	},
1461 	[MTK_CONSTRAINT_HDMIDP] = {
1462 		.channels =  &(const struct snd_pcm_hw_constraint_list) {
1463 			.list = mt8195_pcm_hdmidp_channels,
1464 			.count = ARRAY_SIZE(mt8195_pcm_hdmidp_channels)
1465 		},
1466 		.rates = &mt8195_rate_constraint,
1467 	},
1468 };
1469 
1470 static const struct mtk_sof_priv mt8195_sof_priv = {
1471 	.conn_streams = g_sof_conn_streams,
1472 	.num_streams = ARRAY_SIZE(g_sof_conn_streams),
1473 	.sof_dai_link_fixup = mt8195_dai_link_fixup
1474 };
1475 
1476 static const struct mtk_soundcard_pdata mt8195_mt6359_rt1019_rt5682_card = {
1477 	.card_name = "mt8195_r1019_5682",
1478 	.card_data = &(struct mtk_platform_card_data) {
1479 		.card = &mt8195_mt6359_soc_card,
1480 		.num_jacks = MT8195_JACK_MAX,
1481 		.pcm_constraints = mt8195_pcm_constraints,
1482 		.num_pcm_constraints = ARRAY_SIZE(mt8195_pcm_constraints),
1483 		.flags = RT1019_SPEAKER_AMP_PRESENT
1484 	},
1485 	.sof_priv = &mt8195_sof_priv,
1486 	.soc_probe = mt8195_mt6359_soc_card_probe
1487 };
1488 
1489 static const struct mtk_soundcard_pdata mt8195_mt6359_rt1011_rt5682_card = {
1490 	.card_name = "mt8195_r1011_5682",
1491 	.card_data = &(struct mtk_platform_card_data) {
1492 		.card = &mt8195_mt6359_soc_card,
1493 		.num_jacks = MT8195_JACK_MAX,
1494 		.pcm_constraints = mt8195_pcm_constraints,
1495 		.num_pcm_constraints = ARRAY_SIZE(mt8195_pcm_constraints),
1496 		.flags = RT1011_SPEAKER_AMP_PRESENT
1497 	},
1498 	.sof_priv = &mt8195_sof_priv,
1499 	.soc_probe = mt8195_mt6359_soc_card_probe
1500 };
1501 
1502 static const struct mtk_soundcard_pdata mt8195_mt6359_max98390_rt5682_card = {
1503 	.card_name = "mt8195_m98390_r5682",
1504 	.card_data = &(struct mtk_platform_card_data) {
1505 		.card = &mt8195_mt6359_soc_card,
1506 		.num_jacks = MT8195_JACK_MAX,
1507 		.pcm_constraints = mt8195_pcm_constraints,
1508 		.num_pcm_constraints = ARRAY_SIZE(mt8195_pcm_constraints),
1509 		.flags = MAX98390_SPEAKER_AMP_PRESENT
1510 	},
1511 	.sof_priv = &mt8195_sof_priv,
1512 	.soc_probe = mt8195_mt6359_soc_card_probe
1513 };
1514 
1515 static const struct of_device_id mt8195_mt6359_dt_match[] = {
1516 	{
1517 		.compatible = "mediatek,mt8195_mt6359_rt1019_rt5682",
1518 		.data = &mt8195_mt6359_rt1019_rt5682_card,
1519 	},
1520 	{
1521 		.compatible = "mediatek,mt8195_mt6359_rt1011_rt5682",
1522 		.data = &mt8195_mt6359_rt1011_rt5682_card,
1523 	},
1524 	{
1525 		.compatible = "mediatek,mt8195_mt6359_max98390_rt5682",
1526 		.data = &mt8195_mt6359_max98390_rt5682_card,
1527 	},
1528 	{},
1529 };
1530 MODULE_DEVICE_TABLE(of, mt8195_mt6359_dt_match);
1531 
1532 static struct platform_driver mt8195_mt6359_driver = {
1533 	.driver = {
1534 		.name = "mt8195_mt6359",
1535 		.of_match_table = mt8195_mt6359_dt_match,
1536 		.pm = &snd_soc_pm_ops,
1537 	},
1538 	.probe = mtk_soundcard_common_probe,
1539 };
1540 
1541 module_platform_driver(mt8195_mt6359_driver);
1542 
1543 /* Module information */
1544 MODULE_DESCRIPTION("MT8195-MT6359 ALSA SoC machine driver");
1545 MODULE_AUTHOR("Trevor Wu <trevor.wu@mediatek.com>");
1546 MODULE_AUTHOR("YC Hung <yc.hung@mediatek.com>");
1547 MODULE_LICENSE("GPL");
1548 MODULE_ALIAS("mt8195_mt6359 soc card");
1549