xref: /linux/sound/soc/mediatek/mt8186/mt8186-mt6366.c (revision 7f4f3b14e8079ecde096bd734af10e30d40c27b7)
1 // SPDX-License-Identifier: GPL-2.0
2 //
3 // mt8186-mt6366.c
4 //	--  MT8186-MT6366 ALSA SoC machine driver
5 //
6 // Copyright (c) 2022 MediaTek Inc.
7 // Author: Jiaxin Yu <jiaxin.yu@mediatek.com>
8 //
9 // Copyright (c) 2024 Collabora Ltd.
10 //                    AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
11 //
12 
13 #include <linux/gpio/consumer.h>
14 #include <linux/input.h>
15 #include <linux/module.h>
16 #include <linux/of.h>
17 #include <sound/jack.h>
18 #include <sound/pcm_params.h>
19 #include <sound/rt5682.h>
20 #include <sound/soc.h>
21 
22 #include "../../codecs/da7219.h"
23 #include "../../codecs/mt6358.h"
24 #include "../../codecs/rt5682.h"
25 #include "../common/mtk-afe-platform-driver.h"
26 #include "../common/mtk-dsp-sof-common.h"
27 #include "../common/mtk-soc-card.h"
28 #include "../common/mtk-soundcard-driver.h"
29 #include "mt8186-afe-common.h"
30 #include "mt8186-afe-clk.h"
31 #include "mt8186-afe-gpio.h"
32 #include "mt8186-mt6366-common.h"
33 
34 #define RT1019_CODEC_DAI	"HiFi"
35 #define RT1019_DEV0_NAME	"rt1019p"
36 
37 #define RT5682S_CODEC_DAI	"rt5682s-aif1"
38 #define RT5682S_DEV0_NAME	"rt5682s.5-001a"
39 
40 #define DA7219_CODEC_DAI	"da7219-hifi"
41 #define DA7219_DEV_NAME		"da7219.5-001a"
42 
43 #define SOF_DMA_DL1 "SOF_DMA_DL1"
44 #define SOF_DMA_DL2 "SOF_DMA_DL2"
45 #define SOF_DMA_UL1 "SOF_DMA_UL1"
46 #define SOF_DMA_UL2 "SOF_DMA_UL2"
47 
48 #define DA7219_CODEC_PRESENT	BIT(0)
49 
50 struct mt8186_mt6366_rt1019_rt5682s_priv {
51 	struct gpio_desc *dmic_sel;
52 	int dmic_switch;
53 };
54 
55 enum mt8186_jacks {
56 	MT8186_JACK_HEADSET,
57 	MT8186_JACK_HDMI,
58 	MT8186_JACK_MAX,
59 };
60 
61 /* Headset jack detection DAPM pins */
62 static struct snd_soc_jack_pin mt8186_jack_pins[] = {
63 	{
64 		.pin = "Headphone",
65 		.mask = SND_JACK_HEADPHONE,
66 	},
67 	{
68 		.pin = "Headset Mic",
69 		.mask = SND_JACK_MICROPHONE,
70 	},
71 };
72 
73 static struct snd_soc_codec_conf mt8186_mt6366_rt1019_rt5682s_codec_conf[] = {
74 	{
75 		.dlc = COMP_CODEC_CONF("mt6358-sound"),
76 		.name_prefix = "Mt6366",
77 	},
78 	{
79 		.dlc = COMP_CODEC_CONF("bt-sco"),
80 		.name_prefix = "Mt8186 bt",
81 	},
82 	{
83 		.dlc = COMP_CODEC_CONF("hdmi-audio-codec"),
84 		.name_prefix = "Mt8186 hdmi",
85 	},
86 };
87 
88 static int dmic_get(struct snd_kcontrol *kcontrol,
89 		    struct snd_ctl_elem_value *ucontrol)
90 {
91 	struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol);
92 	struct mtk_soc_card_data *soc_card_data =
93 		snd_soc_card_get_drvdata(dapm->card);
94 	struct mt8186_mt6366_rt1019_rt5682s_priv *priv = soc_card_data->mach_priv;
95 
96 	ucontrol->value.integer.value[0] = priv->dmic_switch;
97 	return 0;
98 }
99 
100 static int dmic_set(struct snd_kcontrol *kcontrol,
101 		    struct snd_ctl_elem_value *ucontrol)
102 {
103 	struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol);
104 	struct mtk_soc_card_data *soc_card_data =
105 		snd_soc_card_get_drvdata(dapm->card);
106 	struct mt8186_mt6366_rt1019_rt5682s_priv *priv = soc_card_data->mach_priv;
107 
108 	priv->dmic_switch = ucontrol->value.integer.value[0];
109 	if (priv->dmic_sel) {
110 		gpiod_set_value(priv->dmic_sel, priv->dmic_switch);
111 		dev_dbg(dapm->card->dev, "dmic_set_value %d\n",
112 			 priv->dmic_switch);
113 	}
114 	return 0;
115 }
116 
117 static const char * const dmic_mux_text[] = {
118 	"Front Mic",
119 	"Rear Mic",
120 };
121 
122 static SOC_ENUM_SINGLE_DECL(mt8186_dmic_enum,
123 			    SND_SOC_NOPM, 0, dmic_mux_text);
124 
125 static const struct snd_kcontrol_new mt8186_dmic_mux_control =
126 	SOC_DAPM_ENUM_EXT("DMIC Select Mux", mt8186_dmic_enum,
127 			  dmic_get, dmic_set);
128 
129 static const struct snd_soc_dapm_widget dmic_widgets[] = {
130 	SND_SOC_DAPM_MIC("DMIC", NULL),
131 	SND_SOC_DAPM_MUX("Dmic Mux", SND_SOC_NOPM, 0, 0, &mt8186_dmic_mux_control),
132 };
133 
134 static const struct snd_soc_dapm_route dmic_map[] = {
135 	/* digital mics */
136 	{"Dmic Mux", "Front Mic", "DMIC"},
137 	{"Dmic Mux", "Rear Mic", "DMIC"},
138 };
139 
140 static int primary_codec_init(struct snd_soc_pcm_runtime *rtd)
141 {
142 	struct snd_soc_card *card = rtd->card;
143 	struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(card);
144 	struct mt8186_mt6366_rt1019_rt5682s_priv *priv = soc_card_data->mach_priv;
145 	int ret;
146 
147 	ret = mt8186_mt6366_init(rtd);
148 
149 	if (ret) {
150 		dev_err(card->dev, "mt8186_mt6366_init failed: %d\n", ret);
151 		return ret;
152 	}
153 
154 	if (!priv->dmic_sel) {
155 		dev_dbg(card->dev, "dmic_sel is null\n");
156 		return 0;
157 	}
158 
159 	ret = snd_soc_dapm_new_controls(&card->dapm, dmic_widgets,
160 					ARRAY_SIZE(dmic_widgets));
161 	if (ret) {
162 		dev_err(card->dev, "DMic widget addition failed: %d\n", ret);
163 		/* Don't need to add routes if widget addition failed */
164 		return ret;
165 	}
166 
167 	ret = snd_soc_dapm_add_routes(&card->dapm, dmic_map,
168 				      ARRAY_SIZE(dmic_map));
169 
170 	if (ret)
171 		dev_err(card->dev, "DMic map addition failed: %d\n", ret);
172 
173 	return ret;
174 }
175 
176 static int mt8186_headset_codec_init(struct snd_soc_pcm_runtime *rtd)
177 {
178 	struct snd_soc_component *cmpnt_afe =
179 		snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
180 	struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe);
181 	struct mtk_soc_card_data *soc_card_data =
182 		snd_soc_card_get_drvdata(rtd->card);
183 	struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8186_JACK_HEADSET];
184 	struct snd_soc_component *cmpnt_codec =
185 		snd_soc_rtd_to_codec(rtd, 0)->component;
186 	const int hs_keys_rt5682[] = {
187 		KEY_PLAYPAUSE, KEY_VOLUMEUP, KEY_VOLUMEDOWN, KEY_VOICECOMMAND
188 	};
189 	const int hs_keys_da7219[] = {
190 		KEY_PLAYPAUSE, KEY_VOICECOMMAND, KEY_VOLUMEUP, KEY_VOLUMEDOWN
191 	};
192 	const int *hs_keys;
193 	int ret;
194 	int type;
195 
196 	ret = mt8186_dai_i2s_set_share(afe, "I2S1", "I2S0");
197 	if (ret) {
198 		dev_err(rtd->dev, "Failed to set up shared clocks\n");
199 		return ret;
200 	}
201 
202 	ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack",
203 				    SND_JACK_HEADSET | SND_JACK_BTN_0 |
204 				    SND_JACK_BTN_1 | SND_JACK_BTN_2 |
205 				    SND_JACK_BTN_3,
206 				    jack, mt8186_jack_pins,
207 				    ARRAY_SIZE(mt8186_jack_pins));
208 	if (ret) {
209 		dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
210 		return ret;
211 	}
212 
213 	if (soc_card_data->card_data->flags & DA7219_CODEC_PRESENT)
214 		hs_keys = hs_keys_da7219;
215 	else
216 		hs_keys = hs_keys_rt5682;
217 
218 	snd_jack_set_key(jack->jack, SND_JACK_BTN_0, hs_keys[0]);
219 	snd_jack_set_key(jack->jack, SND_JACK_BTN_1, hs_keys[1]);
220 	snd_jack_set_key(jack->jack, SND_JACK_BTN_2, hs_keys[2]);
221 	snd_jack_set_key(jack->jack, SND_JACK_BTN_3, hs_keys[3]);
222 
223 	type = SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 | SND_JACK_BTN_2 | SND_JACK_BTN_3;
224 	return snd_soc_component_set_jack(cmpnt_codec, jack, (void *)&type);
225 }
226 
227 static int mt8186_da7219_i2s_hw_params(struct snd_pcm_substream *substream,
228 				       struct snd_pcm_hw_params *params)
229 {
230 	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
231 	struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
232 	struct snd_soc_dai *codec_dai;
233 	unsigned int rate = params_rate(params);
234 	unsigned int mclk_fs_ratio = 256;
235 	unsigned int mclk_fs = rate * mclk_fs_ratio;
236 	unsigned int freq;
237 	int ret, j;
238 
239 	ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk_fs, SND_SOC_CLOCK_OUT);
240 	if (ret < 0) {
241 		dev_err(rtd->dev, "failed to set cpu dai sysclk: %d\n", ret);
242 		return ret;
243 	}
244 
245 	for_each_rtd_codec_dais(rtd, j, codec_dai) {
246 		if (strcmp(codec_dai->component->name, DA7219_DEV_NAME))
247 			continue;
248 
249 		ret = snd_soc_dai_set_sysclk(codec_dai, DA7219_CLKSRC_MCLK,
250 					     mclk_fs, SND_SOC_CLOCK_IN);
251 		if (ret < 0) {
252 			dev_err(rtd->dev, "failed to set sysclk: %d\n", ret);
253 			return ret;
254 		}
255 
256 		if ((rate % 8000) == 0)
257 			freq = DA7219_PLL_FREQ_OUT_98304;
258 		else
259 			freq = DA7219_PLL_FREQ_OUT_90316;
260 
261 		ret = snd_soc_dai_set_pll(codec_dai, 0, DA7219_SYSCLK_PLL_SRM,
262 					  0, freq);
263 		if (ret) {
264 			dev_err(rtd->dev, "failed to start PLL: %d\n", ret);
265 			return ret;
266 		}
267 	}
268 
269 	return 0;
270 }
271 
272 static int mt8186_da7219_i2s_hw_free(struct snd_pcm_substream *substream)
273 {
274 	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
275 	struct snd_soc_dai *codec_dai;
276 	int j, ret;
277 
278 	for_each_rtd_codec_dais(rtd, j, codec_dai) {
279 		if (strcmp(codec_dai->component->name, DA7219_DEV_NAME))
280 			continue;
281 
282 		ret = snd_soc_dai_set_pll(codec_dai, 0, DA7219_SYSCLK_MCLK, 0, 0);
283 		if (ret < 0) {
284 			dev_err(rtd->dev, "failed to stop PLL: %d\n", ret);
285 			return ret;
286 		}
287 	}
288 
289 	return 0;
290 }
291 
292 static const struct snd_soc_ops mt8186_da7219_i2s_ops = {
293 	.hw_params = mt8186_da7219_i2s_hw_params,
294 	.hw_free = mt8186_da7219_i2s_hw_free,
295 };
296 
297 static int mt8186_rt5682s_i2s_hw_params(struct snd_pcm_substream *substream,
298 					struct snd_pcm_hw_params *params)
299 {
300 	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
301 	struct snd_soc_card *card = rtd->card;
302 	struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
303 	struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
304 	unsigned int rate = params_rate(params);
305 	unsigned int mclk_fs_ratio = 128;
306 	unsigned int mclk_fs = rate * mclk_fs_ratio;
307 	int bitwidth;
308 	int ret;
309 
310 	bitwidth = snd_pcm_format_width(params_format(params));
311 	if (bitwidth < 0) {
312 		dev_err(card->dev, "invalid bit width: %d\n", bitwidth);
313 		return bitwidth;
314 	}
315 
316 	ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x00, 0x0, 0x2, bitwidth);
317 	if (ret) {
318 		dev_err(card->dev, "failed to set tdm slot\n");
319 		return ret;
320 	}
321 
322 	ret = snd_soc_dai_set_pll(codec_dai, RT5682_PLL1,
323 				  RT5682_PLL1_S_BCLK1,
324 				  params_rate(params) * 64,
325 				  params_rate(params) * 512);
326 	if (ret) {
327 		dev_err(card->dev, "failed to set pll\n");
328 		return ret;
329 	}
330 
331 	ret = snd_soc_dai_set_sysclk(codec_dai,
332 				     RT5682_SCLK_S_PLL1,
333 				     params_rate(params) * 512,
334 				     SND_SOC_CLOCK_IN);
335 	if (ret) {
336 		dev_err(card->dev, "failed to set sysclk\n");
337 		return ret;
338 	}
339 
340 	return snd_soc_dai_set_sysclk(cpu_dai, 0, mclk_fs, SND_SOC_CLOCK_OUT);
341 }
342 
343 static const struct snd_soc_ops mt8186_rt5682s_i2s_ops = {
344 	.hw_params = mt8186_rt5682s_i2s_hw_params,
345 };
346 
347 static int mt8186_mt6366_rt1019_rt5682s_hdmi_init(struct snd_soc_pcm_runtime *rtd)
348 {
349 	struct snd_soc_component *cmpnt_afe =
350 		snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
351 	struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe);
352 	struct snd_soc_component *cmpnt_codec =
353 		snd_soc_rtd_to_codec(rtd, 0)->component;
354 	struct mtk_soc_card_data *soc_card_data =
355 		snd_soc_card_get_drvdata(rtd->card);
356 	struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8186_JACK_HDMI];
357 	int ret;
358 
359 	ret = mt8186_dai_i2s_set_share(afe, "I2S2", "I2S3");
360 	if (ret) {
361 		dev_err(rtd->dev, "Failed to set up shared clocks\n");
362 		return ret;
363 	}
364 
365 	ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT, jack);
366 	if (ret) {
367 		dev_err(rtd->dev, "HDMI Jack creation failed: %d\n", ret);
368 		return ret;
369 	}
370 
371 	return snd_soc_component_set_jack(cmpnt_codec, jack, NULL);
372 }
373 
374 static int mt8186_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
375 				  struct snd_pcm_hw_params *params,
376 				  snd_pcm_format_t fmt)
377 {
378 	struct snd_interval *channels = hw_param_interval(params,
379 		SNDRV_PCM_HW_PARAM_CHANNELS);
380 
381 	dev_dbg(rtd->dev, "%s(), fix format to %d\n", __func__, fmt);
382 
383 	/* fix BE i2s channel to 2 channel */
384 	channels->min = 2;
385 	channels->max = 2;
386 
387 	/* clean param mask first */
388 	snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT),
389 			     0, (__force unsigned int)SNDRV_PCM_FORMAT_LAST);
390 
391 	params_set_format(params, fmt);
392 
393 	return 0;
394 }
395 
396 static int mt8186_i2s_hw_params_24le_fixup(struct snd_soc_pcm_runtime *rtd,
397 					   struct snd_pcm_hw_params *params)
398 {
399 	return mt8186_hw_params_fixup(rtd, params, SNDRV_PCM_FORMAT_S24_LE);
400 }
401 
402 static int mt8186_i2s_hw_params_32le_fixup(struct snd_soc_pcm_runtime *rtd,
403 					   struct snd_pcm_hw_params *params)
404 {
405 	return mt8186_hw_params_fixup(rtd, params, SNDRV_PCM_FORMAT_S32_LE);
406 }
407 
408 /* fixup the BE DAI link to match any values from topology */
409 static int mt8186_sof_dai_link_fixup(struct snd_soc_pcm_runtime *rtd,
410 				     struct snd_pcm_hw_params *params)
411 {
412 	struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card);
413 	int ret;
414 
415 	ret = mtk_sof_dai_link_fixup(rtd, params);
416 
417 	if (!strcmp(rtd->dai_link->name, "I2S0") ||
418 	    !strcmp(rtd->dai_link->name, "I2S1") ||
419 	    !strcmp(rtd->dai_link->name, "I2S2")) {
420 		if (soc_card_data->card_data->flags & DA7219_CODEC_PRESENT)
421 			mt8186_i2s_hw_params_32le_fixup(rtd, params);
422 		else
423 			mt8186_i2s_hw_params_24le_fixup(rtd, params);
424 	} else if (!strcmp(rtd->dai_link->name, "I2S3")) {
425 		if (soc_card_data->card_data->flags & DA7219_CODEC_PRESENT)
426 			mt8186_i2s_hw_params_24le_fixup(rtd, params);
427 		else
428 			mt8186_i2s_hw_params_32le_fixup(rtd, params);
429 	}
430 
431 	return ret;
432 }
433 
434 /* FE */
435 SND_SOC_DAILINK_DEFS(playback1,
436 		     DAILINK_COMP_ARRAY(COMP_CPU("DL1")),
437 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
438 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
439 
440 SND_SOC_DAILINK_DEFS(playback12,
441 		     DAILINK_COMP_ARRAY(COMP_CPU("DL12")),
442 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
443 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
444 
445 SND_SOC_DAILINK_DEFS(playback2,
446 		     DAILINK_COMP_ARRAY(COMP_CPU("DL2")),
447 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
448 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
449 
450 SND_SOC_DAILINK_DEFS(playback3,
451 		     DAILINK_COMP_ARRAY(COMP_CPU("DL3")),
452 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
453 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
454 
455 SND_SOC_DAILINK_DEFS(playback4,
456 		     DAILINK_COMP_ARRAY(COMP_CPU("DL4")),
457 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
458 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
459 
460 SND_SOC_DAILINK_DEFS(playback5,
461 		     DAILINK_COMP_ARRAY(COMP_CPU("DL5")),
462 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
463 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
464 
465 SND_SOC_DAILINK_DEFS(playback6,
466 		     DAILINK_COMP_ARRAY(COMP_CPU("DL6")),
467 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
468 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
469 
470 SND_SOC_DAILINK_DEFS(playback7,
471 		     DAILINK_COMP_ARRAY(COMP_CPU("DL7")),
472 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
473 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
474 
475 SND_SOC_DAILINK_DEFS(playback8,
476 		     DAILINK_COMP_ARRAY(COMP_CPU("DL8")),
477 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
478 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
479 
480 SND_SOC_DAILINK_DEFS(capture1,
481 		     DAILINK_COMP_ARRAY(COMP_CPU("UL1")),
482 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
483 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
484 
485 SND_SOC_DAILINK_DEFS(capture2,
486 		     DAILINK_COMP_ARRAY(COMP_CPU("UL2")),
487 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
488 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
489 
490 SND_SOC_DAILINK_DEFS(capture3,
491 		     DAILINK_COMP_ARRAY(COMP_CPU("UL3")),
492 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
493 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
494 
495 SND_SOC_DAILINK_DEFS(capture4,
496 		     DAILINK_COMP_ARRAY(COMP_CPU("UL4")),
497 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
498 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
499 
500 SND_SOC_DAILINK_DEFS(capture5,
501 		     DAILINK_COMP_ARRAY(COMP_CPU("UL5")),
502 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
503 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
504 
505 SND_SOC_DAILINK_DEFS(capture6,
506 		     DAILINK_COMP_ARRAY(COMP_CPU("UL6")),
507 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
508 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
509 
510 SND_SOC_DAILINK_DEFS(capture7,
511 		     DAILINK_COMP_ARRAY(COMP_CPU("UL7")),
512 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
513 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
514 
515 /* hostless */
516 SND_SOC_DAILINK_DEFS(hostless_lpbk,
517 		     DAILINK_COMP_ARRAY(COMP_CPU("Hostless LPBK DAI")),
518 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
519 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
520 SND_SOC_DAILINK_DEFS(hostless_fm,
521 		     DAILINK_COMP_ARRAY(COMP_CPU("Hostless FM DAI")),
522 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
523 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
524 SND_SOC_DAILINK_DEFS(hostless_src1,
525 		     DAILINK_COMP_ARRAY(COMP_CPU("Hostless_SRC_1_DAI")),
526 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
527 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
528 SND_SOC_DAILINK_DEFS(hostless_src_bargein,
529 		     DAILINK_COMP_ARRAY(COMP_CPU("Hostless_SRC_Bargein_DAI")),
530 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
531 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
532 
533 /* BE */
534 SND_SOC_DAILINK_DEFS(adda,
535 		     DAILINK_COMP_ARRAY(COMP_CPU("ADDA")),
536 		     DAILINK_COMP_ARRAY(COMP_CODEC("mt6358-sound",
537 						   "mt6358-snd-codec-aif1"),
538 					COMP_CODEC("dmic-codec",
539 						   "dmic-hifi")),
540 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
541 SND_SOC_DAILINK_DEFS(i2s0,
542 		     DAILINK_COMP_ARRAY(COMP_CPU("I2S0")),
543 		     DAILINK_COMP_ARRAY(COMP_EMPTY()),
544 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
545 SND_SOC_DAILINK_DEFS(i2s1,
546 		     DAILINK_COMP_ARRAY(COMP_CPU("I2S1")),
547 		     DAILINK_COMP_ARRAY(COMP_EMPTY()),
548 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
549 SND_SOC_DAILINK_DEFS(i2s2,
550 		     DAILINK_COMP_ARRAY(COMP_CPU("I2S2")),
551 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
552 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
553 SND_SOC_DAILINK_DEFS(i2s3,
554 		     DAILINK_COMP_ARRAY(COMP_CPU("I2S3")),
555 		     DAILINK_COMP_ARRAY(COMP_EMPTY()),
556 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
557 SND_SOC_DAILINK_DEFS(hw_gain1,
558 		     DAILINK_COMP_ARRAY(COMP_CPU("HW Gain 1")),
559 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
560 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
561 SND_SOC_DAILINK_DEFS(hw_gain2,
562 		     DAILINK_COMP_ARRAY(COMP_CPU("HW Gain 2")),
563 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
564 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
565 SND_SOC_DAILINK_DEFS(hw_src1,
566 		     DAILINK_COMP_ARRAY(COMP_CPU("HW_SRC_1")),
567 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
568 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
569 SND_SOC_DAILINK_DEFS(hw_src2,
570 		     DAILINK_COMP_ARRAY(COMP_CPU("HW_SRC_2")),
571 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
572 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
573 SND_SOC_DAILINK_DEFS(connsys_i2s,
574 		     DAILINK_COMP_ARRAY(COMP_CPU("CONNSYS_I2S")),
575 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
576 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
577 SND_SOC_DAILINK_DEFS(pcm1,
578 		     DAILINK_COMP_ARRAY(COMP_CPU("PCM 1")),
579 		     DAILINK_COMP_ARRAY(COMP_CODEC("bt-sco", "bt-sco-pcm-wb")),
580 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
581 SND_SOC_DAILINK_DEFS(tdm_in,
582 		     DAILINK_COMP_ARRAY(COMP_CPU("TDM IN")),
583 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
584 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
585 
586 /* hostless */
587 SND_SOC_DAILINK_DEFS(hostless_ul1,
588 		     DAILINK_COMP_ARRAY(COMP_CPU("Hostless_UL1 DAI")),
589 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
590 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
591 SND_SOC_DAILINK_DEFS(hostless_ul2,
592 		     DAILINK_COMP_ARRAY(COMP_CPU("Hostless_UL2 DAI")),
593 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
594 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
595 SND_SOC_DAILINK_DEFS(hostless_ul3,
596 		     DAILINK_COMP_ARRAY(COMP_CPU("Hostless_UL3 DAI")),
597 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
598 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
599 SND_SOC_DAILINK_DEFS(hostless_ul5,
600 		     DAILINK_COMP_ARRAY(COMP_CPU("Hostless_UL5 DAI")),
601 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
602 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
603 SND_SOC_DAILINK_DEFS(hostless_ul6,
604 		     DAILINK_COMP_ARRAY(COMP_CPU("Hostless_UL6 DAI")),
605 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
606 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
607 SND_SOC_DAILINK_DEFS(hostless_hw_gain_aaudio,
608 		     DAILINK_COMP_ARRAY(COMP_CPU("Hostless HW Gain AAudio DAI")),
609 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
610 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
611 SND_SOC_DAILINK_DEFS(hostless_src_aaudio,
612 		     DAILINK_COMP_ARRAY(COMP_CPU("Hostless SRC AAudio DAI")),
613 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
614 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
615 SND_SOC_DAILINK_DEFS(AFE_SOF_DL1,
616 		     DAILINK_COMP_ARRAY(COMP_CPU("SOF_DL1")),
617 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
618 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
619 
620 SND_SOC_DAILINK_DEFS(AFE_SOF_DL2,
621 		     DAILINK_COMP_ARRAY(COMP_CPU("SOF_DL2")),
622 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
623 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
624 
625 SND_SOC_DAILINK_DEFS(AFE_SOF_UL1,
626 		     DAILINK_COMP_ARRAY(COMP_CPU("SOF_UL1")),
627 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
628 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
629 
630 SND_SOC_DAILINK_DEFS(AFE_SOF_UL2,
631 		     DAILINK_COMP_ARRAY(COMP_CPU("SOF_UL2")),
632 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
633 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
634 
635 static const struct sof_conn_stream g_sof_conn_streams[] = {
636 	{ "I2S1", "AFE_SOF_DL1", SOF_DMA_DL1, SNDRV_PCM_STREAM_PLAYBACK},
637 	{ "I2S3", "AFE_SOF_DL2", SOF_DMA_DL2, SNDRV_PCM_STREAM_PLAYBACK},
638 	{ "Primary Codec", "AFE_SOF_UL1", SOF_DMA_UL1, SNDRV_PCM_STREAM_CAPTURE},
639 	{ "I2S0", "AFE_SOF_UL2", SOF_DMA_UL2, SNDRV_PCM_STREAM_CAPTURE},
640 };
641 
642 static struct snd_soc_dai_link mt8186_mt6366_rt1019_rt5682s_dai_links[] = {
643 	/* Front End DAI links */
644 	{
645 		.name = "Playback_1",
646 		.stream_name = "Playback_1",
647 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
648 			    SND_SOC_DPCM_TRIGGER_PRE},
649 		.dynamic = 1,
650 		.playback_only = 1,
651 		.dpcm_merged_format = 1,
652 		.dpcm_merged_chan = 1,
653 		.dpcm_merged_rate = 1,
654 		.ops = &mtk_soundcard_common_playback_ops,
655 		SND_SOC_DAILINK_REG(playback1),
656 	},
657 	{
658 		.name = "Playback_12",
659 		.stream_name = "Playback_12",
660 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
661 			    SND_SOC_DPCM_TRIGGER_PRE},
662 		.dynamic = 1,
663 		.playback_only = 1,
664 		SND_SOC_DAILINK_REG(playback12),
665 	},
666 	{
667 		.name = "Playback_2",
668 		.stream_name = "Playback_2",
669 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
670 			    SND_SOC_DPCM_TRIGGER_PRE},
671 		.dynamic = 1,
672 		.playback_only = 1,
673 		.dpcm_merged_format = 1,
674 		.dpcm_merged_chan = 1,
675 		.dpcm_merged_rate = 1,
676 		SND_SOC_DAILINK_REG(playback2),
677 	},
678 	{
679 		.name = "Playback_3",
680 		.stream_name = "Playback_3",
681 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
682 			    SND_SOC_DPCM_TRIGGER_PRE},
683 		.dynamic = 1,
684 		.playback_only = 1,
685 		.dpcm_merged_format = 1,
686 		.dpcm_merged_chan = 1,
687 		.dpcm_merged_rate = 1,
688 		.ops = &mtk_soundcard_common_playback_ops,
689 		SND_SOC_DAILINK_REG(playback3),
690 	},
691 	{
692 		.name = "Playback_4",
693 		.stream_name = "Playback_4",
694 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
695 			    SND_SOC_DPCM_TRIGGER_PRE},
696 		.dynamic = 1,
697 		.playback_only = 1,
698 		SND_SOC_DAILINK_REG(playback4),
699 	},
700 	{
701 		.name = "Playback_5",
702 		.stream_name = "Playback_5",
703 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
704 			    SND_SOC_DPCM_TRIGGER_PRE},
705 		.dynamic = 1,
706 		.playback_only = 1,
707 		SND_SOC_DAILINK_REG(playback5),
708 	},
709 	{
710 		.name = "Playback_6",
711 		.stream_name = "Playback_6",
712 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
713 			    SND_SOC_DPCM_TRIGGER_PRE},
714 		.dynamic = 1,
715 		.playback_only = 1,
716 		SND_SOC_DAILINK_REG(playback6),
717 	},
718 	{
719 		.name = "Playback_7",
720 		.stream_name = "Playback_7",
721 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
722 			    SND_SOC_DPCM_TRIGGER_PRE},
723 		.dynamic = 1,
724 		.playback_only = 1,
725 		SND_SOC_DAILINK_REG(playback7),
726 	},
727 	{
728 		.name = "Playback_8",
729 		.stream_name = "Playback_8",
730 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
731 			    SND_SOC_DPCM_TRIGGER_PRE},
732 		.dynamic = 1,
733 		.playback_only = 1,
734 		SND_SOC_DAILINK_REG(playback8),
735 	},
736 	{
737 		.name = "Capture_1",
738 		.stream_name = "Capture_1",
739 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
740 			    SND_SOC_DPCM_TRIGGER_PRE},
741 		.dynamic = 1,
742 		.capture_only = 1,
743 		SND_SOC_DAILINK_REG(capture1),
744 	},
745 	{
746 		.name = "Capture_2",
747 		.stream_name = "Capture_2",
748 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
749 			    SND_SOC_DPCM_TRIGGER_PRE},
750 		.dynamic = 1,
751 		.capture_only = 1,
752 		.dpcm_merged_format = 1,
753 		.dpcm_merged_chan = 1,
754 		.dpcm_merged_rate = 1,
755 		.ops = &mtk_soundcard_common_capture_ops,
756 		SND_SOC_DAILINK_REG(capture2),
757 	},
758 	{
759 		.name = "Capture_3",
760 		.stream_name = "Capture_3",
761 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
762 			    SND_SOC_DPCM_TRIGGER_PRE},
763 		.dynamic = 1,
764 		.capture_only = 1,
765 		SND_SOC_DAILINK_REG(capture3),
766 	},
767 	{
768 		.name = "Capture_4",
769 		.stream_name = "Capture_4",
770 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
771 			    SND_SOC_DPCM_TRIGGER_PRE},
772 		.dynamic = 1,
773 		.capture_only = 1,
774 		.dpcm_merged_format = 1,
775 		.dpcm_merged_chan = 1,
776 		.dpcm_merged_rate = 1,
777 		.ops = &mtk_soundcard_common_capture_ops,
778 		SND_SOC_DAILINK_REG(capture4),
779 	},
780 	{
781 		.name = "Capture_5",
782 		.stream_name = "Capture_5",
783 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
784 			    SND_SOC_DPCM_TRIGGER_PRE},
785 		.dynamic = 1,
786 		.capture_only = 1,
787 		SND_SOC_DAILINK_REG(capture5),
788 	},
789 	{
790 		.name = "Capture_6",
791 		.stream_name = "Capture_6",
792 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
793 			    SND_SOC_DPCM_TRIGGER_PRE},
794 		.dynamic = 1,
795 		.capture_only = 1,
796 		.dpcm_merged_format = 1,
797 		.dpcm_merged_chan = 1,
798 		.dpcm_merged_rate = 1,
799 		SND_SOC_DAILINK_REG(capture6),
800 	},
801 	{
802 		.name = "Capture_7",
803 		.stream_name = "Capture_7",
804 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
805 			    SND_SOC_DPCM_TRIGGER_PRE},
806 		.dynamic = 1,
807 		.capture_only = 1,
808 		SND_SOC_DAILINK_REG(capture7),
809 	},
810 	{
811 		.name = "Hostless_LPBK",
812 		.stream_name = "Hostless_LPBK",
813 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
814 			    SND_SOC_DPCM_TRIGGER_PRE},
815 		.dynamic = 1,
816 		.ignore_suspend = 1,
817 		SND_SOC_DAILINK_REG(hostless_lpbk),
818 	},
819 	{
820 		.name = "Hostless_FM",
821 		.stream_name = "Hostless_FM",
822 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
823 			    SND_SOC_DPCM_TRIGGER_PRE},
824 		.dynamic = 1,
825 		.ignore_suspend = 1,
826 		SND_SOC_DAILINK_REG(hostless_fm),
827 	},
828 	{
829 		.name = "Hostless_SRC_1",
830 		.stream_name = "Hostless_SRC_1",
831 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
832 			    SND_SOC_DPCM_TRIGGER_PRE},
833 		.dynamic = 1,
834 		.ignore_suspend = 1,
835 		SND_SOC_DAILINK_REG(hostless_src1),
836 	},
837 	{
838 		.name = "Hostless_SRC_Bargein",
839 		.stream_name = "Hostless_SRC_Bargein",
840 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
841 			    SND_SOC_DPCM_TRIGGER_PRE},
842 		.dynamic = 1,
843 		.ignore_suspend = 1,
844 		SND_SOC_DAILINK_REG(hostless_src_bargein),
845 	},
846 	{
847 		.name = "Hostless_HW_Gain_AAudio",
848 		.stream_name = "Hostless_HW_Gain_AAudio",
849 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
850 			    SND_SOC_DPCM_TRIGGER_PRE},
851 		.dynamic = 1,
852 		.capture_only = 1,
853 		.ignore_suspend = 1,
854 		SND_SOC_DAILINK_REG(hostless_hw_gain_aaudio),
855 	},
856 	{
857 		.name = "Hostless_SRC_AAudio",
858 		.stream_name = "Hostless_SRC_AAudio",
859 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
860 			    SND_SOC_DPCM_TRIGGER_PRE},
861 		.dynamic = 1,
862 		.ignore_suspend = 1,
863 		SND_SOC_DAILINK_REG(hostless_src_aaudio),
864 	},
865 	/* Back End DAI links */
866 	{
867 		.name = "Primary Codec",
868 		.no_pcm = 1,
869 		.ignore_suspend = 1,
870 		.init = primary_codec_init,
871 		SND_SOC_DAILINK_REG(adda),
872 	},
873 	{
874 		.name = "I2S3",
875 		.no_pcm = 1,
876 		.dai_fmt = SND_SOC_DAIFMT_I2S |
877 			   SND_SOC_DAIFMT_IB_IF |
878 			   SND_SOC_DAIFMT_CBM_CFM,
879 		.playback_only = 1,
880 		.ignore_suspend = 1,
881 		.init = mt8186_mt6366_rt1019_rt5682s_hdmi_init,
882 		SND_SOC_DAILINK_REG(i2s3),
883 	},
884 	{
885 		.name = "I2S0",
886 		.no_pcm = 1,
887 		.capture_only = 1,
888 		.ignore_suspend = 1,
889 		.ops = &mt8186_rt5682s_i2s_ops,
890 		SND_SOC_DAILINK_REG(i2s0),
891 	},
892 	{
893 		.name = "I2S1",
894 		.no_pcm = 1,
895 		.playback_only = 1,
896 		.ignore_suspend = 1,
897 		.init = mt8186_headset_codec_init,
898 		SND_SOC_DAILINK_REG(i2s1),
899 	},
900 	{
901 		.name = "I2S2",
902 		.no_pcm = 1,
903 		.capture_only = 1,
904 		.ignore_suspend = 1,
905 		SND_SOC_DAILINK_REG(i2s2),
906 	},
907 	{
908 		.name = "HW Gain 1",
909 		.no_pcm = 1,
910 		.ignore_suspend = 1,
911 		SND_SOC_DAILINK_REG(hw_gain1),
912 	},
913 	{
914 		.name = "HW Gain 2",
915 		.no_pcm = 1,
916 		.ignore_suspend = 1,
917 		SND_SOC_DAILINK_REG(hw_gain2),
918 	},
919 	{
920 		.name = "HW_SRC_1",
921 		.no_pcm = 1,
922 		.ignore_suspend = 1,
923 		SND_SOC_DAILINK_REG(hw_src1),
924 	},
925 	{
926 		.name = "HW_SRC_2",
927 		.no_pcm = 1,
928 		.ignore_suspend = 1,
929 		SND_SOC_DAILINK_REG(hw_src2),
930 	},
931 	{
932 		.name = "CONNSYS_I2S",
933 		.no_pcm = 1,
934 		.capture_only = 1,
935 		.ignore_suspend = 1,
936 		SND_SOC_DAILINK_REG(connsys_i2s),
937 	},
938 	{
939 		.name = "PCM 1",
940 		.dai_fmt = SND_SOC_DAIFMT_I2S |
941 			   SND_SOC_DAIFMT_NB_IF,
942 		.no_pcm = 1,
943 		.ignore_suspend = 1,
944 		SND_SOC_DAILINK_REG(pcm1),
945 	},
946 	{
947 		.name = "TDM IN",
948 		.no_pcm = 1,
949 		.capture_only = 1,
950 		.ignore_suspend = 1,
951 		SND_SOC_DAILINK_REG(tdm_in),
952 	},
953 	/* dummy BE for ul memif to record from dl memif */
954 	{
955 		.name = "Hostless_UL1",
956 		.no_pcm = 1,
957 		.capture_only = 1,
958 		.ignore_suspend = 1,
959 		SND_SOC_DAILINK_REG(hostless_ul1),
960 	},
961 	{
962 		.name = "Hostless_UL2",
963 		.no_pcm = 1,
964 		.capture_only = 1,
965 		.ignore_suspend = 1,
966 		SND_SOC_DAILINK_REG(hostless_ul2),
967 	},
968 	{
969 		.name = "Hostless_UL3",
970 		.no_pcm = 1,
971 		.capture_only = 1,
972 		.ignore_suspend = 1,
973 		SND_SOC_DAILINK_REG(hostless_ul3),
974 	},
975 	{
976 		.name = "Hostless_UL5",
977 		.no_pcm = 1,
978 		.capture_only = 1,
979 		.ignore_suspend = 1,
980 		SND_SOC_DAILINK_REG(hostless_ul5),
981 	},
982 	{
983 		.name = "Hostless_UL6",
984 		.no_pcm = 1,
985 		.capture_only = 1,
986 		.ignore_suspend = 1,
987 		SND_SOC_DAILINK_REG(hostless_ul6),
988 	},
989 	/* SOF BE */
990 	{
991 		.name = "AFE_SOF_DL1",
992 		.no_pcm = 1,
993 		.playback_only = 1,
994 		SND_SOC_DAILINK_REG(AFE_SOF_DL1),
995 	},
996 	{
997 		.name = "AFE_SOF_DL2",
998 		.no_pcm = 1,
999 		.playback_only = 1,
1000 		SND_SOC_DAILINK_REG(AFE_SOF_DL2),
1001 	},
1002 	{
1003 		.name = "AFE_SOF_UL1",
1004 		.no_pcm = 1,
1005 		.capture_only = 1,
1006 		SND_SOC_DAILINK_REG(AFE_SOF_UL1),
1007 	},
1008 	{
1009 		.name = "AFE_SOF_UL2",
1010 		.no_pcm = 1,
1011 		.capture_only = 1,
1012 		SND_SOC_DAILINK_REG(AFE_SOF_UL2),
1013 	},
1014 };
1015 
1016 static const struct snd_soc_dapm_widget
1017 mt8186_mt6366_da7219_max98357_widgets[] = {
1018 	SND_SOC_DAPM_SPK("Speakers", NULL),
1019 	SND_SOC_DAPM_HP("Headphones", NULL),
1020 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
1021 	SND_SOC_DAPM_LINE("Line Out", NULL),
1022 	SND_SOC_DAPM_LINE("HDMI1", NULL),
1023 	SND_SOC_DAPM_MIXER(SOF_DMA_DL1, SND_SOC_NOPM, 0, 0, NULL, 0),
1024 	SND_SOC_DAPM_MIXER(SOF_DMA_DL2, SND_SOC_NOPM, 0, 0, NULL, 0),
1025 	SND_SOC_DAPM_MIXER(SOF_DMA_UL1, SND_SOC_NOPM, 0, 0, NULL, 0),
1026 	SND_SOC_DAPM_MIXER(SOF_DMA_UL2, SND_SOC_NOPM, 0, 0, NULL, 0),
1027 };
1028 
1029 static const struct snd_soc_dapm_widget
1030 mt8186_mt6366_rt1019_rt5682s_widgets[] = {
1031 	SND_SOC_DAPM_SPK("Speakers", NULL),
1032 	SND_SOC_DAPM_HP("Headphone", NULL),
1033 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
1034 	SND_SOC_DAPM_OUTPUT("HDMI1"),
1035 	SND_SOC_DAPM_MIXER(SOF_DMA_DL1, SND_SOC_NOPM, 0, 0, NULL, 0),
1036 	SND_SOC_DAPM_MIXER(SOF_DMA_DL2, SND_SOC_NOPM, 0, 0, NULL, 0),
1037 	SND_SOC_DAPM_MIXER(SOF_DMA_UL1, SND_SOC_NOPM, 0, 0, NULL, 0),
1038 	SND_SOC_DAPM_MIXER(SOF_DMA_UL2, SND_SOC_NOPM, 0, 0, NULL, 0),
1039 };
1040 
1041 static const struct snd_soc_dapm_route
1042 mt8186_mt6366_rt1019_rt5682s_routes[] = {
1043 	/* SPK */
1044 	{ "Speakers", NULL, "Speaker" },
1045 	/* Headset */
1046 	{ "Headphone", NULL, "HPOL" },
1047 	{ "Headphone", NULL, "HPOR" },
1048 	{ "IN1P", NULL, "Headset Mic" },
1049 	/* HDMI */
1050 	{ "HDMI1", NULL, "TX" },
1051 	/* SOF Uplink */
1052 	{SOF_DMA_UL1, NULL, "UL1_CH1"},
1053 	{SOF_DMA_UL1, NULL, "UL1_CH2"},
1054 	{SOF_DMA_UL2, NULL, "UL2_CH1"},
1055 	{SOF_DMA_UL2, NULL, "UL2_CH2"},
1056 	/* SOF Downlink */
1057 	{"DSP_DL1_VIRT", NULL, SOF_DMA_DL1},
1058 	{"DSP_DL2_VIRT", NULL, SOF_DMA_DL2},
1059 };
1060 
1061 static const struct snd_soc_dapm_route mt8186_mt6366_rt5650_routes[] = {
1062 	/* SPK */
1063 	{"Speakers", NULL, "SPOL"},
1064 	{"Speakers", NULL, "SPOR"},
1065 	/* Headset */
1066 	{ "Headphone", NULL, "HPOL" },
1067 	{ "Headphone", NULL, "HPOR" },
1068 	{ "IN1P", NULL, "Headset Mic" },
1069 	{ "IN1N", NULL, "Headset Mic"},
1070 	/* HDMI */
1071 	{ "HDMI1", NULL, "TX" },
1072 	/* SOF Uplink */
1073 	{SOF_DMA_UL1, NULL, "UL1_CH1"},
1074 	{SOF_DMA_UL1, NULL, "UL1_CH2"},
1075 	{SOF_DMA_UL2, NULL, "UL2_CH1"},
1076 	{SOF_DMA_UL2, NULL, "UL2_CH2"},
1077 	/* SOF Downlink */
1078 	{"DSP_DL1_VIRT", NULL, SOF_DMA_DL1},
1079 	{"DSP_DL2_VIRT", NULL, SOF_DMA_DL2},
1080 };
1081 
1082 static const struct snd_kcontrol_new mt8186_mt6366_da7219_max98357_controls[] = {
1083 	SOC_DAPM_PIN_SWITCH("Speakers"),
1084 	SOC_DAPM_PIN_SWITCH("Headphones"),
1085 	SOC_DAPM_PIN_SWITCH("Headset Mic"),
1086 	SOC_DAPM_PIN_SWITCH("Line Out"),
1087 	SOC_DAPM_PIN_SWITCH("HDMI1"),
1088 };
1089 
1090 static const struct snd_kcontrol_new
1091 mt8186_mt6366_rt1019_rt5682s_controls[] = {
1092 	SOC_DAPM_PIN_SWITCH("Speakers"),
1093 	SOC_DAPM_PIN_SWITCH("Headphone"),
1094 	SOC_DAPM_PIN_SWITCH("Headset Mic"),
1095 	SOC_DAPM_PIN_SWITCH("HDMI1"),
1096 };
1097 
1098 static struct snd_soc_card mt8186_mt6366_da7219_max98357_soc_card = {
1099 	.name = "mt8186_da7219_max98357",
1100 	.owner = THIS_MODULE,
1101 	.dai_link = mt8186_mt6366_rt1019_rt5682s_dai_links,
1102 	.num_links = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_dai_links),
1103 	.controls = mt8186_mt6366_da7219_max98357_controls,
1104 	.num_controls = ARRAY_SIZE(mt8186_mt6366_da7219_max98357_controls),
1105 	.dapm_widgets = mt8186_mt6366_da7219_max98357_widgets,
1106 	.num_dapm_widgets = ARRAY_SIZE(mt8186_mt6366_da7219_max98357_widgets),
1107 	.dapm_routes = mt8186_mt6366_rt1019_rt5682s_routes,
1108 	.num_dapm_routes = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_routes),
1109 	.codec_conf = mt8186_mt6366_rt1019_rt5682s_codec_conf,
1110 	.num_configs = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_codec_conf),
1111 };
1112 
1113 static struct snd_soc_card mt8186_mt6366_rt1019_rt5682s_soc_card = {
1114 	.name = "mt8186_rt1019_rt5682s",
1115 	.owner = THIS_MODULE,
1116 	.dai_link = mt8186_mt6366_rt1019_rt5682s_dai_links,
1117 	.num_links = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_dai_links),
1118 	.controls = mt8186_mt6366_rt1019_rt5682s_controls,
1119 	.num_controls = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_controls),
1120 	.dapm_widgets = mt8186_mt6366_rt1019_rt5682s_widgets,
1121 	.num_dapm_widgets = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_widgets),
1122 	.dapm_routes = mt8186_mt6366_rt1019_rt5682s_routes,
1123 	.num_dapm_routes = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_routes),
1124 	.codec_conf = mt8186_mt6366_rt1019_rt5682s_codec_conf,
1125 	.num_configs = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_codec_conf),
1126 };
1127 
1128 static struct snd_soc_card mt8186_mt6366_rt5682s_max98360_soc_card = {
1129 	.name = "mt8186_rt5682s_max98360",
1130 	.owner = THIS_MODULE,
1131 	.dai_link = mt8186_mt6366_rt1019_rt5682s_dai_links,
1132 	.num_links = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_dai_links),
1133 	.controls = mt8186_mt6366_rt1019_rt5682s_controls,
1134 	.num_controls = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_controls),
1135 	.dapm_widgets = mt8186_mt6366_rt1019_rt5682s_widgets,
1136 	.num_dapm_widgets = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_widgets),
1137 	.dapm_routes = mt8186_mt6366_rt1019_rt5682s_routes,
1138 	.num_dapm_routes = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_routes),
1139 	.codec_conf = mt8186_mt6366_rt1019_rt5682s_codec_conf,
1140 	.num_configs = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_codec_conf),
1141 };
1142 
1143 static struct snd_soc_card mt8186_mt6366_rt5650_soc_card = {
1144 	.name = "mt8186_rt5650",
1145 	.owner = THIS_MODULE,
1146 	.dai_link = mt8186_mt6366_rt1019_rt5682s_dai_links,
1147 	.num_links = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_dai_links),
1148 	.controls = mt8186_mt6366_rt1019_rt5682s_controls,
1149 	.num_controls = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_controls),
1150 	.dapm_widgets = mt8186_mt6366_rt1019_rt5682s_widgets,
1151 	.num_dapm_widgets = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_widgets),
1152 	.dapm_routes = mt8186_mt6366_rt5650_routes,
1153 	.num_dapm_routes = ARRAY_SIZE(mt8186_mt6366_rt5650_routes),
1154 	.codec_conf = mt8186_mt6366_rt1019_rt5682s_codec_conf,
1155 	.num_configs = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_codec_conf),
1156 };
1157 
1158 static int mt8186_mt6366_legacy_probe(struct mtk_soc_card_data *soc_card_data)
1159 {
1160 	struct mtk_platform_card_data *card_data = soc_card_data->card_data;
1161 	struct snd_soc_card *card = card_data->card;
1162 	struct device *dev = card->dev;
1163 	struct snd_soc_dai_link *dai_link;
1164 	struct device_node *headset_codec, *playback_codec;
1165 	int ret, i;
1166 
1167 	playback_codec = of_get_child_by_name(dev->of_node, "playback-codecs");
1168 	if (!playback_codec)
1169 		return dev_err_probe(dev, -EINVAL,
1170 				     "Property 'playback-codecs' missing or invalid\n");
1171 
1172 	headset_codec = of_get_child_by_name(dev->of_node, "headset-codec");
1173 	if (!headset_codec) {
1174 		of_node_put(playback_codec);
1175 		return dev_err_probe(dev, -EINVAL,
1176 				     "Property 'headset-codec' missing or invalid\n");
1177 	}
1178 
1179 	for_each_card_prelinks(card, i, dai_link) {
1180 		ret = mt8186_mt6366_card_set_be_link(card, dai_link, playback_codec, "I2S3");
1181 		if (ret) {
1182 			dev_err_probe(dev, ret, "%s set playback_codec fail\n",
1183 				      dai_link->name);
1184 			break;
1185 		}
1186 
1187 		ret = mt8186_mt6366_card_set_be_link(card, dai_link, headset_codec, "I2S0");
1188 		if (ret) {
1189 			dev_err_probe(dev, ret, "%s set headset_codec fail\n",
1190 				      dai_link->name);
1191 			break;
1192 		}
1193 
1194 		ret = mt8186_mt6366_card_set_be_link(card, dai_link, headset_codec, "I2S1");
1195 		if (ret) {
1196 			dev_err_probe(dev, ret, "%s set headset_codec fail\n",
1197 				      dai_link->name);
1198 			break;
1199 		}
1200 	}
1201 	of_node_put(headset_codec);
1202 	of_node_put(playback_codec);
1203 
1204 	return ret;
1205 }
1206 
1207 static int mt8186_mt6366_soc_card_probe(struct mtk_soc_card_data *soc_card_data, bool legacy)
1208 {
1209 	struct mtk_platform_card_data *card_data = soc_card_data->card_data;
1210 	struct snd_soc_card *card = card_data->card;
1211 	struct snd_soc_dai_link *dai_link;
1212 	struct mt8186_mt6366_rt1019_rt5682s_priv *mach_priv;
1213 	int i, ret;
1214 
1215 	mach_priv = devm_kzalloc(card->dev, sizeof(*mach_priv), GFP_KERNEL);
1216 	if (!mach_priv)
1217 		return -ENOMEM;
1218 
1219 	soc_card_data->mach_priv = mach_priv;
1220 
1221 	mach_priv->dmic_sel = devm_gpiod_get_optional(card->dev,
1222 						      "dmic", GPIOD_OUT_LOW);
1223 	if (IS_ERR(mach_priv->dmic_sel))
1224 		return dev_err_probe(card->dev, PTR_ERR(mach_priv->dmic_sel),
1225 				     "DMIC gpio failed\n");
1226 
1227 	for_each_card_prelinks(card, i, dai_link) {
1228 		if (strcmp(dai_link->name, "I2S0") == 0 ||
1229 		    strcmp(dai_link->name, "I2S1") == 0 ||
1230 		    strcmp(dai_link->name, "I2S2") == 0) {
1231 			if (card_data->flags & DA7219_CODEC_PRESENT) {
1232 				dai_link->be_hw_params_fixup = mt8186_i2s_hw_params_32le_fixup;
1233 				dai_link->ops = &mt8186_da7219_i2s_ops;
1234 			} else {
1235 				dai_link->be_hw_params_fixup = mt8186_i2s_hw_params_24le_fixup;
1236 				dai_link->ops = &mt8186_rt5682s_i2s_ops;
1237 			}
1238 		} else if (strcmp(dai_link->name, "I2S3") == 0) {
1239 			if (card_data->flags & DA7219_CODEC_PRESENT)
1240 				dai_link->be_hw_params_fixup = mt8186_i2s_hw_params_24le_fixup;
1241 			else
1242 				dai_link->be_hw_params_fixup = mt8186_i2s_hw_params_32le_fixup;
1243 		}
1244 	}
1245 
1246 	if (legacy) {
1247 		ret = mt8186_mt6366_legacy_probe(soc_card_data);
1248 		if (ret)
1249 			return ret;
1250 	}
1251 
1252 	ret = mt8186_afe_gpio_init(card->dev);
1253 	if (ret)
1254 		return dev_err_probe(card->dev, ret, "init AFE gpio error\n");
1255 
1256 	return 0;
1257 }
1258 
1259 static const unsigned int mt8186_pcm_playback_channels[] = { 2 };
1260 static const unsigned int mt8186_pcm_capture_channels[] = { 1, 2 };
1261 static const unsigned int mt8186_pcm_rates[] = { 48000 };
1262 
1263 static const struct snd_pcm_hw_constraint_list mt8186_rate_constraint = {
1264 	.list = mt8186_pcm_rates,
1265 	.count = ARRAY_SIZE(mt8186_pcm_rates)
1266 };
1267 
1268 static const struct mtk_pcm_constraints_data mt8186_pcm_constraints[MTK_CONSTRAINT_CAPTURE + 1] = {
1269 	[MTK_CONSTRAINT_PLAYBACK] = {
1270 		.channels = &(const struct snd_pcm_hw_constraint_list) {
1271 			.list = mt8186_pcm_playback_channels,
1272 			.count = ARRAY_SIZE(mt8186_pcm_playback_channels)
1273 		},
1274 		.rates = &mt8186_rate_constraint,
1275 	},
1276 	[MTK_CONSTRAINT_CAPTURE] = {
1277 		.channels = &(const struct snd_pcm_hw_constraint_list) {
1278 			.list = mt8186_pcm_capture_channels,
1279 			.count = ARRAY_SIZE(mt8186_pcm_capture_channels)
1280 		},
1281 		.rates = &mt8186_rate_constraint,
1282 	}
1283 };
1284 
1285 static const struct mtk_sof_priv mt8186_sof_priv = {
1286 	.conn_streams = g_sof_conn_streams,
1287 	.num_streams = ARRAY_SIZE(g_sof_conn_streams),
1288 	.sof_dai_link_fixup = mt8186_sof_dai_link_fixup
1289 };
1290 
1291 static const struct mtk_soundcard_pdata mt8186_mt6366_da7219_max98357_pdata = {
1292 	.card_data = &(struct mtk_platform_card_data) {
1293 		.card = &mt8186_mt6366_da7219_max98357_soc_card,
1294 		.num_jacks = MT8186_JACK_MAX,
1295 		.pcm_constraints = mt8186_pcm_constraints,
1296 		.num_pcm_constraints = ARRAY_SIZE(mt8186_pcm_constraints),
1297 		.flags = DA7219_CODEC_PRESENT,
1298 	},
1299 	.sof_priv = &mt8186_sof_priv,
1300 	.soc_probe = mt8186_mt6366_soc_card_probe
1301 };
1302 
1303 static const struct mtk_soundcard_pdata mt8186_mt6366_rt1019_rt5682s_pdata = {
1304 	.card_data = &(struct mtk_platform_card_data) {
1305 		.card = &mt8186_mt6366_rt1019_rt5682s_soc_card,
1306 		.num_jacks = MT8186_JACK_MAX,
1307 		.pcm_constraints = mt8186_pcm_constraints,
1308 		.num_pcm_constraints = ARRAY_SIZE(mt8186_pcm_constraints),
1309 	},
1310 	.sof_priv = &mt8186_sof_priv,
1311 	.soc_probe = mt8186_mt6366_soc_card_probe
1312 };
1313 
1314 static const struct mtk_soundcard_pdata mt8186_mt6366_rt5682s_max98360_pdata = {
1315 	.card_data = &(struct mtk_platform_card_data) {
1316 		.card = &mt8186_mt6366_rt5682s_max98360_soc_card,
1317 		.num_jacks = MT8186_JACK_MAX,
1318 		.pcm_constraints = mt8186_pcm_constraints,
1319 		.num_pcm_constraints = ARRAY_SIZE(mt8186_pcm_constraints),
1320 	},
1321 	.sof_priv = &mt8186_sof_priv,
1322 	.soc_probe = mt8186_mt6366_soc_card_probe
1323 };
1324 
1325 static const struct mtk_soundcard_pdata mt8186_mt6366_rt5650_pdata = {
1326 	.card_data = &(struct mtk_platform_card_data) {
1327 		.card = &mt8186_mt6366_rt5650_soc_card,
1328 		.num_jacks = MT8186_JACK_MAX,
1329 		.pcm_constraints = mt8186_pcm_constraints,
1330 		.num_pcm_constraints = ARRAY_SIZE(mt8186_pcm_constraints),
1331 	},
1332 	.sof_priv = &mt8186_sof_priv,
1333 	.soc_probe = mt8186_mt6366_soc_card_probe
1334 };
1335 
1336 #if IS_ENABLED(CONFIG_OF)
1337 static const struct of_device_id mt8186_mt6366_dt_match[] = {
1338 	{
1339 		.compatible = "mediatek,mt8186-mt6366-rt1019-rt5682s-sound",
1340 		.data = &mt8186_mt6366_rt1019_rt5682s_pdata,
1341 	},
1342 	{
1343 		.compatible = "mediatek,mt8186-mt6366-rt5682s-max98360-sound",
1344 		.data = &mt8186_mt6366_rt5682s_max98360_pdata,
1345 	},
1346 	{
1347 		.compatible = "mediatek,mt8186-mt6366-rt5650-sound",
1348 		.data = &mt8186_mt6366_rt5650_pdata,
1349 	},
1350 	{
1351 		.compatible = "mediatek,mt8186-mt6366-da7219-max98357-sound",
1352 		.data = &mt8186_mt6366_da7219_max98357_pdata,
1353 	},
1354 	{ /* sentinel */ }
1355 };
1356 MODULE_DEVICE_TABLE(of, mt8186_mt6366_dt_match);
1357 #endif
1358 
1359 static struct platform_driver mt8186_mt6366_driver = {
1360 	.driver = {
1361 		.name = "mt8186_mt6366",
1362 #if IS_ENABLED(CONFIG_OF)
1363 		.of_match_table = mt8186_mt6366_dt_match,
1364 #endif
1365 		.pm = &snd_soc_pm_ops,
1366 	},
1367 	.probe = mtk_soundcard_common_probe,
1368 };
1369 
1370 module_platform_driver(mt8186_mt6366_driver);
1371 
1372 /* Module information */
1373 MODULE_DESCRIPTION("MT8186-MT6366 ALSA SoC machine driver");
1374 MODULE_AUTHOR("Jiaxin Yu <jiaxin.yu@mediatek.com>");
1375 MODULE_LICENSE("GPL v2");
1376 MODULE_ALIAS("mt8186_mt6366 soc card");
1377