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