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