1 // SPDX-License-Identifier: GPL-2.0
2 //
3 // mt8192-mt6359-rt1015-rt5682.c  --
4 //	MT8192-MT6359-RT1015-RT6358 ALSA SoC machine driver
5 //
6 // Copyright (c) 2020 MediaTek Inc.
7 // Author: Jiaxin Yu <jiaxin.yu@mediatek.com>
8 //
9 
10 #include <linux/input.h>
11 #include <linux/module.h>
12 #include <linux/of_device.h>
13 #include <linux/pm_runtime.h>
14 #include <sound/jack.h>
15 #include <sound/pcm_params.h>
16 #include <sound/rt5682.h>
17 #include <sound/soc.h>
18 
19 #include "../../codecs/mt6359.h"
20 #include "../../codecs/rt1015.h"
21 #include "../../codecs/rt5682.h"
22 #include "../common/mtk-afe-platform-driver.h"
23 #include "mt8192-afe-common.h"
24 #include "mt8192-afe-clk.h"
25 #include "mt8192-afe-gpio.h"
26 
27 #define RT1015_CODEC_DAI	"rt1015-aif"
28 #define RT1015_DEV0_NAME	"rt1015.1-0028"
29 #define RT1015_DEV1_NAME	"rt1015.1-0029"
30 
31 #define RT5682_CODEC_DAI	"rt5682-aif1"
32 #define RT5682_DEV0_NAME	"rt5682.1-001a"
33 
34 static struct snd_soc_jack headset_jack;
35 
36 static int mt8192_rt1015_i2s_hw_params(struct snd_pcm_substream *substream,
37 				       struct snd_pcm_hw_params *params)
38 {
39 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
40 	struct snd_soc_card *card = rtd->card;
41 	struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
42 	struct snd_soc_dai *codec_dai;
43 	unsigned int rate = params_rate(params);
44 	unsigned int mclk_fs_ratio = 128;
45 	unsigned int mclk_fs = rate * mclk_fs_ratio;
46 	int ret, i;
47 
48 	for_each_rtd_codec_dais(rtd, i, codec_dai) {
49 		ret = snd_soc_dai_set_bclk_ratio(codec_dai, 64);
50 		if (ret) {
51 			dev_err(card->dev, "failed to set bclk ratio\n");
52 			return ret;
53 		}
54 
55 		ret = snd_soc_dai_set_pll(codec_dai, 0,
56 					  RT1015_PLL_S_BCLK,
57 					  params_rate(params) * 64,
58 					  params_rate(params) * 256);
59 		if (ret) {
60 			dev_err(card->dev, "failed to set pll\n");
61 			return ret;
62 		}
63 
64 		ret = snd_soc_dai_set_sysclk(codec_dai,
65 					     RT1015_SCLK_S_PLL,
66 					     params_rate(params) * 256,
67 					     SND_SOC_CLOCK_IN);
68 		if (ret) {
69 			dev_err(card->dev, "failed to set sysclk\n");
70 			return ret;
71 		}
72 	}
73 
74 	return snd_soc_dai_set_sysclk(cpu_dai, 0, mclk_fs, SND_SOC_CLOCK_OUT);
75 }
76 
77 static int mt8192_rt5682_i2s_hw_params(struct snd_pcm_substream *substream,
78 				       struct snd_pcm_hw_params *params)
79 {
80 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
81 	struct snd_soc_card *card = rtd->card;
82 	struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
83 	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
84 	unsigned int rate = params_rate(params);
85 	unsigned int mclk_fs_ratio = 128;
86 	unsigned int mclk_fs = rate * mclk_fs_ratio;
87 	int bitwidth;
88 	int ret;
89 
90 	bitwidth = snd_pcm_format_width(params_format(params));
91 	if (bitwidth < 0) {
92 		dev_err(card->dev, "invalid bit width: %d\n", bitwidth);
93 		return bitwidth;
94 	}
95 
96 	ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x00, 0x0, 0x2, bitwidth);
97 	if (ret) {
98 		dev_err(card->dev, "failed to set tdm slot\n");
99 		return ret;
100 	}
101 
102 	ret = snd_soc_dai_set_pll(codec_dai, RT5682_PLL1,
103 				  RT5682_PLL1_S_BCLK1,
104 				  params_rate(params) * 64,
105 				  params_rate(params) * 512);
106 	if (ret) {
107 		dev_err(card->dev, "failed to set pll\n");
108 		return ret;
109 	}
110 
111 	ret = snd_soc_dai_set_sysclk(codec_dai,
112 				     RT5682_SCLK_S_PLL1,
113 				     params_rate(params) * 512,
114 				     SND_SOC_CLOCK_IN);
115 	if (ret) {
116 		dev_err(card->dev, "failed to set sysclk\n");
117 		return ret;
118 	}
119 
120 	return snd_soc_dai_set_sysclk(cpu_dai, 0, mclk_fs, SND_SOC_CLOCK_OUT);
121 }
122 
123 static const struct snd_soc_ops mt8192_rt1015_i2s_ops = {
124 	.hw_params = mt8192_rt1015_i2s_hw_params,
125 };
126 
127 static const struct snd_soc_ops mt8192_rt5682_i2s_ops = {
128 	.hw_params = mt8192_rt5682_i2s_hw_params,
129 };
130 
131 static int mt8192_mt6359_mtkaif_calibration(struct snd_soc_pcm_runtime *rtd)
132 {
133 	struct snd_soc_component *cmpnt_afe =
134 		snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
135 	struct snd_soc_component *cmpnt_codec =
136 		asoc_rtd_to_codec(rtd, 0)->component;
137 	struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe);
138 	struct mt8192_afe_private *afe_priv = afe->platform_priv;
139 	int phase;
140 	unsigned int monitor;
141 	int test_done_1, test_done_2, test_done_3;
142 	int cycle_1, cycle_2, cycle_3;
143 	int prev_cycle_1, prev_cycle_2, prev_cycle_3;
144 	int chosen_phase_1, chosen_phase_2, chosen_phase_3;
145 	int counter;
146 	int mtkaif_calib_ok;
147 
148 	dev_info(afe->dev, "%s(), start\n", __func__);
149 
150 	pm_runtime_get_sync(afe->dev);
151 	mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA, 1);
152 	mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA, 0);
153 	mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA_CH34, 1);
154 	mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA_CH34, 0);
155 
156 	mt6359_mtkaif_calibration_enable(cmpnt_codec);
157 
158 	/* set clock protocol 2 */
159 	regmap_update_bits(afe->regmap, AFE_AUD_PAD_TOP, 0xff, 0x38);
160 	regmap_update_bits(afe->regmap, AFE_AUD_PAD_TOP, 0xff, 0x39);
161 
162 	/* set test type to synchronizer pulse */
163 	regmap_update_bits(afe_priv->topckgen,
164 			   CKSYS_AUD_TOP_CFG, 0xffff, 0x4);
165 
166 	mtkaif_calib_ok = true;
167 	afe_priv->mtkaif_calibration_num_phase = 42;	/* mt6359: 0 ~ 42 */
168 	afe_priv->mtkaif_chosen_phase[0] = -1;
169 	afe_priv->mtkaif_chosen_phase[1] = -1;
170 	afe_priv->mtkaif_chosen_phase[2] = -1;
171 
172 	for (phase = 0;
173 	     phase <= afe_priv->mtkaif_calibration_num_phase &&
174 	     mtkaif_calib_ok;
175 	     phase++) {
176 		mt6359_set_mtkaif_calibration_phase(cmpnt_codec,
177 						    phase, phase, phase);
178 
179 		regmap_update_bits(afe_priv->topckgen,
180 				   CKSYS_AUD_TOP_CFG, 0x1, 0x1);
181 
182 		test_done_1 = 0;
183 		test_done_2 = 0;
184 		test_done_3 = 0;
185 		cycle_1 = -1;
186 		cycle_2 = -1;
187 		cycle_3 = -1;
188 		counter = 0;
189 		while (test_done_1 == 0 ||
190 		       test_done_2 == 0 ||
191 		       test_done_3 == 0) {
192 			regmap_read(afe_priv->topckgen,
193 				    CKSYS_AUD_TOP_MON, &monitor);
194 
195 			test_done_1 = (monitor >> 28) & 0x1;
196 			test_done_2 = (monitor >> 29) & 0x1;
197 			test_done_3 = (monitor >> 30) & 0x1;
198 			if (test_done_1 == 1)
199 				cycle_1 = monitor & 0xf;
200 
201 			if (test_done_2 == 1)
202 				cycle_2 = (monitor >> 4) & 0xf;
203 
204 			if (test_done_3 == 1)
205 				cycle_3 = (monitor >> 8) & 0xf;
206 
207 			/* handle if never test done */
208 			if (++counter > 10000) {
209 				dev_err(afe->dev, "%s(), test fail, cycle_1 %d, cycle_2 %d, cycle_3 %d, monitor 0x%x\n",
210 					__func__,
211 					cycle_1, cycle_2, cycle_3, monitor);
212 				mtkaif_calib_ok = false;
213 				break;
214 			}
215 		}
216 
217 		if (phase == 0) {
218 			prev_cycle_1 = cycle_1;
219 			prev_cycle_2 = cycle_2;
220 			prev_cycle_3 = cycle_3;
221 		}
222 
223 		if (cycle_1 != prev_cycle_1 &&
224 		    afe_priv->mtkaif_chosen_phase[0] < 0) {
225 			afe_priv->mtkaif_chosen_phase[0] = phase - 1;
226 			afe_priv->mtkaif_phase_cycle[0] = prev_cycle_1;
227 		}
228 
229 		if (cycle_2 != prev_cycle_2 &&
230 		    afe_priv->mtkaif_chosen_phase[1] < 0) {
231 			afe_priv->mtkaif_chosen_phase[1] = phase - 1;
232 			afe_priv->mtkaif_phase_cycle[1] = prev_cycle_2;
233 		}
234 
235 		if (cycle_3 != prev_cycle_3 &&
236 		    afe_priv->mtkaif_chosen_phase[2] < 0) {
237 			afe_priv->mtkaif_chosen_phase[2] = phase - 1;
238 			afe_priv->mtkaif_phase_cycle[2] = prev_cycle_3;
239 		}
240 
241 		regmap_update_bits(afe_priv->topckgen,
242 				   CKSYS_AUD_TOP_CFG, 0x1, 0x0);
243 
244 		if (afe_priv->mtkaif_chosen_phase[0] >= 0 &&
245 		    afe_priv->mtkaif_chosen_phase[1] >= 0 &&
246 		    afe_priv->mtkaif_chosen_phase[2] >= 0)
247 			break;
248 	}
249 
250 	if (afe_priv->mtkaif_chosen_phase[0] < 0)
251 		chosen_phase_1 = 0;
252 	else
253 		chosen_phase_1 = afe_priv->mtkaif_chosen_phase[0];
254 
255 	if (afe_priv->mtkaif_chosen_phase[1] < 0)
256 		chosen_phase_2 = 0;
257 	else
258 		chosen_phase_2 = afe_priv->mtkaif_chosen_phase[1];
259 
260 	if (afe_priv->mtkaif_chosen_phase[2] < 0)
261 		chosen_phase_3 = 0;
262 	else
263 		chosen_phase_3 = afe_priv->mtkaif_chosen_phase[2];
264 
265 	mt6359_set_mtkaif_calibration_phase(cmpnt_codec,
266 					    chosen_phase_1,
267 					    chosen_phase_2,
268 					    chosen_phase_3);
269 
270 	/* disable rx fifo */
271 	regmap_update_bits(afe->regmap, AFE_AUD_PAD_TOP, 0xff, 0x38);
272 
273 	mt6359_mtkaif_calibration_disable(cmpnt_codec);
274 
275 	mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA, 1);
276 	mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA, 0);
277 	mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA_CH34, 1);
278 	mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA_CH34, 0);
279 	pm_runtime_put(afe->dev);
280 
281 	dev_info(afe->dev, "%s(), mtkaif_chosen_phase[0/1/2]:%d/%d/%d\n",
282 		 __func__,
283 		 afe_priv->mtkaif_chosen_phase[0],
284 		 afe_priv->mtkaif_chosen_phase[1],
285 		 afe_priv->mtkaif_chosen_phase[2]);
286 
287 	return 0;
288 }
289 
290 static int mt8192_mt6359_init(struct snd_soc_pcm_runtime *rtd)
291 {
292 	struct snd_soc_component *cmpnt_afe =
293 		snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
294 	struct snd_soc_component *cmpnt_codec =
295 		asoc_rtd_to_codec(rtd, 0)->component;
296 	struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe);
297 	struct mt8192_afe_private *afe_priv = afe->platform_priv;
298 
299 	/* set mtkaif protocol */
300 	mt6359_set_mtkaif_protocol(cmpnt_codec,
301 				   MT6359_MTKAIF_PROTOCOL_2_CLK_P2);
302 	afe_priv->mtkaif_protocol = MTKAIF_PROTOCOL_2_CLK_P2;
303 
304 	/* mtkaif calibration */
305 	mt8192_mt6359_mtkaif_calibration(rtd);
306 
307 	return 0;
308 }
309 
310 static int mt8192_rt5682_init(struct snd_soc_pcm_runtime *rtd)
311 {
312 	struct snd_soc_component *cmpnt_codec =
313 		asoc_rtd_to_codec(rtd, 0)->component;
314 	struct snd_soc_jack *jack = &headset_jack;
315 	int ret;
316 
317 	ret = snd_soc_card_jack_new(rtd->card, "Headset Jack",
318 				    SND_JACK_HEADSET | SND_JACK_BTN_0 |
319 				    SND_JACK_BTN_1 | SND_JACK_BTN_2 |
320 				    SND_JACK_BTN_3,
321 				    jack, NULL, 0);
322 	if (ret) {
323 		dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
324 		return ret;
325 	}
326 
327 	snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
328 	snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
329 	snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
330 	snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
331 
332 	ret = snd_soc_component_set_jack(cmpnt_codec, jack, NULL);
333 	if (ret) {
334 		dev_err(rtd->dev, "Headset Jack set failed: %d\n", ret);
335 		return ret;
336 	}
337 
338 	return 0;
339 };
340 
341 static int mt8192_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
342 				      struct snd_pcm_hw_params *params)
343 {
344 	/* fix BE i2s format to 32bit, clean param mask first */
345 	snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT),
346 			     0, SNDRV_PCM_FORMAT_LAST);
347 
348 	params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
349 
350 	return 0;
351 }
352 
353 static int
354 mt8192_mt6359_rt1015_rt5682_cap1_startup(struct snd_pcm_substream *substream)
355 {
356 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
357 	struct snd_soc_component *component =
358 		snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
359 	struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
360 	int ret;
361 
362 	static const unsigned int channels[] = {
363 		1, 2, 4
364 	};
365 	static const struct snd_pcm_hw_constraint_list constraints_channels = {
366 		.count = ARRAY_SIZE(channels),
367 		.list = channels,
368 		.mask = 0,
369 	};
370 	static const unsigned int rates[] = {
371 		8000, 16000, 32000, 48000, 96000, 192000
372 	};
373 	static const struct snd_pcm_hw_constraint_list constraints_rates = {
374 		.count = ARRAY_SIZE(rates),
375 		.list  = rates,
376 		.mask = 0,
377 	};
378 
379 	struct snd_pcm_runtime *runtime = substream->runtime;
380 
381 	ret = snd_pcm_hw_constraint_list(runtime, 0,
382 					 SNDRV_PCM_HW_PARAM_CHANNELS,
383 					 &constraints_channels);
384 	if (ret < 0) {
385 		dev_err(afe->dev, "hw_constraint_list channels failed\n");
386 		return ret;
387 	}
388 
389 	ret = snd_pcm_hw_constraint_list(runtime, 0,
390 					 SNDRV_PCM_HW_PARAM_RATE,
391 					 &constraints_rates);
392 	if (ret < 0) {
393 		dev_err(afe->dev, "hw_constraint_list rate failed\n");
394 		return ret;
395 	}
396 
397 	return 0;
398 }
399 
400 static const struct snd_soc_ops mt8192_mt6359_rt1015_rt5682_capture1_ops = {
401 	.startup = mt8192_mt6359_rt1015_rt5682_cap1_startup,
402 };
403 
404 /* FE */
405 SND_SOC_DAILINK_DEFS(playback1,
406 		     DAILINK_COMP_ARRAY(COMP_CPU("DL1")),
407 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
408 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
409 
410 SND_SOC_DAILINK_DEFS(playback12,
411 		     DAILINK_COMP_ARRAY(COMP_CPU("DL12")),
412 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
413 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
414 
415 SND_SOC_DAILINK_DEFS(playback2,
416 		     DAILINK_COMP_ARRAY(COMP_CPU("DL2")),
417 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
418 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
419 
420 SND_SOC_DAILINK_DEFS(playback3,
421 		     DAILINK_COMP_ARRAY(COMP_CPU("DL3")),
422 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
423 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
424 
425 SND_SOC_DAILINK_DEFS(playback4,
426 		     DAILINK_COMP_ARRAY(COMP_CPU("DL4")),
427 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
428 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
429 
430 SND_SOC_DAILINK_DEFS(playback5,
431 		     DAILINK_COMP_ARRAY(COMP_CPU("DL5")),
432 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
433 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
434 
435 SND_SOC_DAILINK_DEFS(playback6,
436 		     DAILINK_COMP_ARRAY(COMP_CPU("DL6")),
437 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
438 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
439 
440 SND_SOC_DAILINK_DEFS(playback7,
441 		     DAILINK_COMP_ARRAY(COMP_CPU("DL7")),
442 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
443 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
444 
445 SND_SOC_DAILINK_DEFS(playback8,
446 		     DAILINK_COMP_ARRAY(COMP_CPU("DL8")),
447 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
448 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
449 
450 SND_SOC_DAILINK_DEFS(playback9,
451 		     DAILINK_COMP_ARRAY(COMP_CPU("DL9")),
452 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
453 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
454 
455 SND_SOC_DAILINK_DEFS(capture1,
456 		     DAILINK_COMP_ARRAY(COMP_CPU("UL1")),
457 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
458 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
459 
460 SND_SOC_DAILINK_DEFS(capture2,
461 		     DAILINK_COMP_ARRAY(COMP_CPU("UL2")),
462 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
463 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
464 
465 SND_SOC_DAILINK_DEFS(capture3,
466 		     DAILINK_COMP_ARRAY(COMP_CPU("UL3")),
467 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
468 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
469 
470 SND_SOC_DAILINK_DEFS(capture4,
471 		     DAILINK_COMP_ARRAY(COMP_CPU("UL4")),
472 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
473 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
474 
475 SND_SOC_DAILINK_DEFS(capture5,
476 		     DAILINK_COMP_ARRAY(COMP_CPU("UL5")),
477 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
478 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
479 
480 SND_SOC_DAILINK_DEFS(capture6,
481 		     DAILINK_COMP_ARRAY(COMP_CPU("UL6")),
482 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
483 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
484 
485 SND_SOC_DAILINK_DEFS(capture7,
486 		     DAILINK_COMP_ARRAY(COMP_CPU("UL7")),
487 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
488 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
489 
490 SND_SOC_DAILINK_DEFS(capture8,
491 		     DAILINK_COMP_ARRAY(COMP_CPU("UL8")),
492 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
493 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
494 
495 SND_SOC_DAILINK_DEFS(capture_mono1,
496 		     DAILINK_COMP_ARRAY(COMP_CPU("UL_MONO_1")),
497 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
498 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
499 
500 SND_SOC_DAILINK_DEFS(capture_mono2,
501 		     DAILINK_COMP_ARRAY(COMP_CPU("UL_MONO_2")),
502 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
503 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
504 
505 SND_SOC_DAILINK_DEFS(capture_mono3,
506 		     DAILINK_COMP_ARRAY(COMP_CPU("UL_MONO_3")),
507 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
508 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
509 
510 SND_SOC_DAILINK_DEFS(playback_hdmi,
511 		     DAILINK_COMP_ARRAY(COMP_CPU("HDMI")),
512 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
513 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
514 
515 /* BE */
516 SND_SOC_DAILINK_DEFS(primary_codec,
517 		     DAILINK_COMP_ARRAY(COMP_CPU("ADDA")),
518 		     DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
519 						   "mt6359-snd-codec-aif1"),
520 					COMP_CODEC("dmic-codec",
521 						   "dmic-hifi")),
522 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
523 
524 SND_SOC_DAILINK_DEFS(primary_codec_ch34,
525 		     DAILINK_COMP_ARRAY(COMP_CPU("ADDA_CH34")),
526 		     DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
527 						   "mt6359-snd-codec-aif2")),
528 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
529 
530 SND_SOC_DAILINK_DEFS(ap_dmic,
531 		     DAILINK_COMP_ARRAY(COMP_CPU("AP_DMIC")),
532 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
533 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
534 
535 SND_SOC_DAILINK_DEFS(ap_dmic_ch34,
536 		     DAILINK_COMP_ARRAY(COMP_CPU("AP_DMIC_CH34")),
537 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
538 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
539 
540 SND_SOC_DAILINK_DEFS(i2s0,
541 		     DAILINK_COMP_ARRAY(COMP_CPU("I2S0")),
542 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
543 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
544 
545 SND_SOC_DAILINK_DEFS(i2s1,
546 		     DAILINK_COMP_ARRAY(COMP_CPU("I2S1")),
547 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
548 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
549 
550 SND_SOC_DAILINK_DEFS(i2s2,
551 		     DAILINK_COMP_ARRAY(COMP_CPU("I2S2")),
552 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
553 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
554 
555 SND_SOC_DAILINK_DEFS(i2s3_rt1015,
556 		     DAILINK_COMP_ARRAY(COMP_CPU("I2S3")),
557 		     DAILINK_COMP_ARRAY(COMP_CODEC(RT1015_DEV0_NAME,
558 						   RT1015_CODEC_DAI),
559 					COMP_CODEC(RT1015_DEV1_NAME,
560 						   RT1015_CODEC_DAI)),
561 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
562 
563 SND_SOC_DAILINK_DEFS(i2s3_rt1015p,
564 		     DAILINK_COMP_ARRAY(COMP_CPU("I2S3")),
565 		     DAILINK_COMP_ARRAY(COMP_CODEC("rt1015p", "HiFi")),
566 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
567 
568 SND_SOC_DAILINK_DEFS(i2s5,
569 		     DAILINK_COMP_ARRAY(COMP_CPU("I2S5")),
570 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
571 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
572 
573 SND_SOC_DAILINK_DEFS(i2s6,
574 		     DAILINK_COMP_ARRAY(COMP_CPU("I2S6")),
575 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
576 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
577 
578 SND_SOC_DAILINK_DEFS(i2s7,
579 		     DAILINK_COMP_ARRAY(COMP_CPU("I2S7")),
580 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
581 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
582 
583 SND_SOC_DAILINK_DEFS(i2s8,
584 		     DAILINK_COMP_ARRAY(COMP_CPU("I2S8")),
585 		     DAILINK_COMP_ARRAY(COMP_CODEC(RT5682_DEV0_NAME,
586 						   RT5682_CODEC_DAI)),
587 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
588 
589 SND_SOC_DAILINK_DEFS(i2s9,
590 		     DAILINK_COMP_ARRAY(COMP_CPU("I2S9")),
591 		     DAILINK_COMP_ARRAY(COMP_CODEC(RT5682_DEV0_NAME,
592 						   RT5682_CODEC_DAI)),
593 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
594 
595 SND_SOC_DAILINK_DEFS(connsys_i2s,
596 		     DAILINK_COMP_ARRAY(COMP_CPU("CONNSYS_I2S")),
597 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
598 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
599 
600 SND_SOC_DAILINK_DEFS(pcm1,
601 		     DAILINK_COMP_ARRAY(COMP_CPU("PCM 1")),
602 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
603 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
604 
605 SND_SOC_DAILINK_DEFS(pcm2,
606 		     DAILINK_COMP_ARRAY(COMP_CPU("PCM 2")),
607 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
608 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
609 
610 SND_SOC_DAILINK_DEFS(tdm,
611 		     DAILINK_COMP_ARRAY(COMP_CPU("TDM")),
612 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
613 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
614 
615 static struct snd_soc_dai_link mt8192_mt6359_dai_links[] = {
616 	/* Front End DAI links */
617 	{
618 		.name = "Playback_1",
619 		.stream_name = "Playback_1",
620 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
621 			    SND_SOC_DPCM_TRIGGER_PRE},
622 		.dynamic = 1,
623 		.dpcm_playback = 1,
624 		SND_SOC_DAILINK_REG(playback1),
625 	},
626 	{
627 		.name = "Playback_12",
628 		.stream_name = "Playback_12",
629 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
630 			    SND_SOC_DPCM_TRIGGER_PRE},
631 		.dynamic = 1,
632 		.dpcm_playback = 1,
633 		SND_SOC_DAILINK_REG(playback12),
634 	},
635 	{
636 		.name = "Playback_2",
637 		.stream_name = "Playback_2",
638 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
639 			    SND_SOC_DPCM_TRIGGER_PRE},
640 		.dynamic = 1,
641 		.dpcm_playback = 1,
642 		SND_SOC_DAILINK_REG(playback2),
643 	},
644 	{
645 		.name = "Playback_3",
646 		.stream_name = "Playback_3",
647 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
648 			    SND_SOC_DPCM_TRIGGER_PRE},
649 		.dynamic = 1,
650 		.dpcm_playback = 1,
651 		SND_SOC_DAILINK_REG(playback3),
652 	},
653 	{
654 		.name = "Playback_4",
655 		.stream_name = "Playback_4",
656 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
657 			    SND_SOC_DPCM_TRIGGER_PRE},
658 		.dynamic = 1,
659 		.dpcm_playback = 1,
660 		SND_SOC_DAILINK_REG(playback4),
661 	},
662 	{
663 		.name = "Playback_5",
664 		.stream_name = "Playback_5",
665 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
666 			    SND_SOC_DPCM_TRIGGER_PRE},
667 		.dynamic = 1,
668 		.dpcm_playback = 1,
669 		SND_SOC_DAILINK_REG(playback5),
670 	},
671 	{
672 		.name = "Playback_6",
673 		.stream_name = "Playback_6",
674 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
675 			    SND_SOC_DPCM_TRIGGER_PRE},
676 		.dynamic = 1,
677 		.dpcm_playback = 1,
678 		SND_SOC_DAILINK_REG(playback6),
679 	},
680 	{
681 		.name = "Playback_7",
682 		.stream_name = "Playback_7",
683 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
684 			    SND_SOC_DPCM_TRIGGER_PRE},
685 		.dynamic = 1,
686 		.dpcm_playback = 1,
687 		SND_SOC_DAILINK_REG(playback7),
688 	},
689 	{
690 		.name = "Playback_8",
691 		.stream_name = "Playback_8",
692 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
693 			    SND_SOC_DPCM_TRIGGER_PRE},
694 		.dynamic = 1,
695 		.dpcm_playback = 1,
696 		SND_SOC_DAILINK_REG(playback8),
697 	},
698 	{
699 		.name = "Playback_9",
700 		.stream_name = "Playback_9",
701 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
702 			    SND_SOC_DPCM_TRIGGER_PRE},
703 		.dynamic = 1,
704 		.dpcm_playback = 1,
705 		SND_SOC_DAILINK_REG(playback9),
706 	},
707 	{
708 		.name = "Capture_1",
709 		.stream_name = "Capture_1",
710 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
711 			    SND_SOC_DPCM_TRIGGER_PRE},
712 		.dynamic = 1,
713 		.dpcm_capture = 1,
714 		.ops = &mt8192_mt6359_rt1015_rt5682_capture1_ops,
715 		SND_SOC_DAILINK_REG(capture1),
716 	},
717 	{
718 		.name = "Capture_2",
719 		.stream_name = "Capture_2",
720 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
721 			    SND_SOC_DPCM_TRIGGER_PRE},
722 		.dynamic = 1,
723 		.dpcm_capture = 1,
724 		SND_SOC_DAILINK_REG(capture2),
725 	},
726 	{
727 		.name = "Capture_3",
728 		.stream_name = "Capture_3",
729 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
730 			    SND_SOC_DPCM_TRIGGER_PRE},
731 		.dynamic = 1,
732 		.dpcm_capture = 1,
733 		SND_SOC_DAILINK_REG(capture3),
734 	},
735 	{
736 		.name = "Capture_4",
737 		.stream_name = "Capture_4",
738 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
739 			    SND_SOC_DPCM_TRIGGER_PRE},
740 		.dynamic = 1,
741 		.dpcm_capture = 1,
742 		SND_SOC_DAILINK_REG(capture4),
743 	},
744 	{
745 		.name = "Capture_5",
746 		.stream_name = "Capture_5",
747 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
748 			    SND_SOC_DPCM_TRIGGER_PRE},
749 		.dynamic = 1,
750 		.dpcm_capture = 1,
751 		SND_SOC_DAILINK_REG(capture5),
752 	},
753 	{
754 		.name = "Capture_6",
755 		.stream_name = "Capture_6",
756 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
757 			    SND_SOC_DPCM_TRIGGER_PRE},
758 		.dynamic = 1,
759 		.dpcm_capture = 1,
760 		SND_SOC_DAILINK_REG(capture6),
761 	},
762 	{
763 		.name = "Capture_7",
764 		.stream_name = "Capture_7",
765 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
766 			    SND_SOC_DPCM_TRIGGER_PRE},
767 		.dynamic = 1,
768 		.dpcm_capture = 1,
769 		SND_SOC_DAILINK_REG(capture7),
770 	},
771 	{
772 		.name = "Capture_8",
773 		.stream_name = "Capture_8",
774 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
775 			    SND_SOC_DPCM_TRIGGER_PRE},
776 		.dynamic = 1,
777 		.dpcm_capture = 1,
778 		SND_SOC_DAILINK_REG(capture8),
779 	},
780 	{
781 		.name = "Capture_Mono_1",
782 		.stream_name = "Capture_Mono_1",
783 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
784 			    SND_SOC_DPCM_TRIGGER_PRE},
785 		.dynamic = 1,
786 		.dpcm_capture = 1,
787 		SND_SOC_DAILINK_REG(capture_mono1),
788 	},
789 	{
790 		.name = "Capture_Mono_2",
791 		.stream_name = "Capture_Mono_2",
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(capture_mono2),
797 	},
798 	{
799 		.name = "Capture_Mono_3",
800 		.stream_name = "Capture_Mono_3",
801 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
802 			    SND_SOC_DPCM_TRIGGER_PRE},
803 		.dynamic = 1,
804 		.dpcm_capture = 1,
805 		SND_SOC_DAILINK_REG(capture_mono3),
806 	},
807 	{
808 		.name = "playback_hdmi",
809 		.stream_name = "Playback_HDMI",
810 		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
811 			    SND_SOC_DPCM_TRIGGER_PRE},
812 		.dynamic = 1,
813 		.dpcm_playback = 1,
814 		SND_SOC_DAILINK_REG(playback_hdmi),
815 	},
816 	/* Back End DAI links */
817 	{
818 		.name = "Primary Codec",
819 		.no_pcm = 1,
820 		.dpcm_playback = 1,
821 		.dpcm_capture = 1,
822 		.ignore_suspend = 1,
823 		.init = mt8192_mt6359_init,
824 		SND_SOC_DAILINK_REG(primary_codec),
825 	},
826 	{
827 		.name = "Primary Codec CH34",
828 		.no_pcm = 1,
829 		.dpcm_playback = 1,
830 		.dpcm_capture = 1,
831 		.ignore_suspend = 1,
832 		SND_SOC_DAILINK_REG(primary_codec_ch34),
833 	},
834 	{
835 		.name = "AP_DMIC",
836 		.no_pcm = 1,
837 		.dpcm_capture = 1,
838 		.ignore_suspend = 1,
839 		SND_SOC_DAILINK_REG(ap_dmic),
840 	},
841 	{
842 		.name = "AP_DMIC_CH34",
843 		.no_pcm = 1,
844 		.dpcm_capture = 1,
845 		.ignore_suspend = 1,
846 		SND_SOC_DAILINK_REG(ap_dmic_ch34),
847 	},
848 	{
849 		.name = "I2S0",
850 		.no_pcm = 1,
851 		.dpcm_capture = 1,
852 		.ignore_suspend = 1,
853 		.be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
854 		SND_SOC_DAILINK_REG(i2s0),
855 	},
856 	{
857 		.name = "I2S1",
858 		.no_pcm = 1,
859 		.dpcm_playback = 1,
860 		.ignore_suspend = 1,
861 		.be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
862 		SND_SOC_DAILINK_REG(i2s1),
863 	},
864 	{
865 		.name = "I2S2",
866 		.no_pcm = 1,
867 		.dpcm_capture = 1,
868 		.ignore_suspend = 1,
869 		.be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
870 		SND_SOC_DAILINK_REG(i2s2),
871 	},
872 	{
873 		.name = "I2S3",
874 		.no_pcm = 1,
875 		.dpcm_playback = 1,
876 		.ignore_suspend = 1,
877 		.be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
878 	},
879 	{
880 		.name = "I2S5",
881 		.no_pcm = 1,
882 		.dpcm_playback = 1,
883 		.ignore_suspend = 1,
884 		.be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
885 		SND_SOC_DAILINK_REG(i2s5),
886 	},
887 	{
888 		.name = "I2S6",
889 		.no_pcm = 1,
890 		.dpcm_capture = 1,
891 		.ignore_suspend = 1,
892 		.be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
893 		SND_SOC_DAILINK_REG(i2s6),
894 	},
895 	{
896 		.name = "I2S7",
897 		.no_pcm = 1,
898 		.dpcm_playback = 1,
899 		.ignore_suspend = 1,
900 		.be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
901 		SND_SOC_DAILINK_REG(i2s7),
902 	},
903 	{
904 		.name = "I2S8",
905 		.no_pcm = 1,
906 		.dpcm_capture = 1,
907 		.ignore_suspend = 1,
908 		.init = mt8192_rt5682_init,
909 		.be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
910 		SND_SOC_DAILINK_REG(i2s8),
911 		.ops = &mt8192_rt5682_i2s_ops,
912 	},
913 	{
914 		.name = "I2S9",
915 		.no_pcm = 1,
916 		.dpcm_playback = 1,
917 		.ignore_suspend = 1,
918 		.be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
919 		SND_SOC_DAILINK_REG(i2s9),
920 		.ops = &mt8192_rt5682_i2s_ops,
921 	},
922 	{
923 		.name = "CONNSYS_I2S",
924 		.no_pcm = 1,
925 		.dpcm_capture = 1,
926 		.ignore_suspend = 1,
927 		SND_SOC_DAILINK_REG(connsys_i2s),
928 	},
929 	{
930 		.name = "PCM 1",
931 		.no_pcm = 1,
932 		.dpcm_playback = 1,
933 		.dpcm_capture = 1,
934 		.ignore_suspend = 1,
935 		SND_SOC_DAILINK_REG(pcm1),
936 	},
937 	{
938 		.name = "PCM 2",
939 		.no_pcm = 1,
940 		.dpcm_playback = 1,
941 		.dpcm_capture = 1,
942 		.ignore_suspend = 1,
943 		SND_SOC_DAILINK_REG(pcm2),
944 	},
945 	{
946 		.name = "TDM",
947 		.no_pcm = 1,
948 		.dpcm_playback = 1,
949 		.ignore_suspend = 1,
950 		SND_SOC_DAILINK_REG(tdm),
951 	},
952 };
953 
954 static const struct snd_soc_dapm_widget
955 mt8192_mt6359_rt1015_rt5682_widgets[] = {
956 	SND_SOC_DAPM_SPK("Left Spk", NULL),
957 	SND_SOC_DAPM_SPK("Right Spk", NULL),
958 	SND_SOC_DAPM_HP("Headphone Jack", NULL),
959 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
960 };
961 
962 static const struct snd_soc_dapm_route mt8192_mt6359_rt1015_rt5682_routes[] = {
963 	/* speaker */
964 	{ "Left Spk", NULL, "Left SPO" },
965 	{ "Right Spk", NULL, "Right SPO" },
966 	/* headset */
967 	{ "Headphone Jack", NULL, "HPOL" },
968 	{ "Headphone Jack", NULL, "HPOR" },
969 	{ "IN1P", NULL, "Headset Mic" },
970 };
971 
972 static const struct snd_kcontrol_new mt8192_mt6359_rt1015_rt5682_controls[] = {
973 	SOC_DAPM_PIN_SWITCH("Left Spk"),
974 	SOC_DAPM_PIN_SWITCH("Right Spk"),
975 	SOC_DAPM_PIN_SWITCH("Headphone Jack"),
976 	SOC_DAPM_PIN_SWITCH("Headset Mic"),
977 };
978 
979 static struct snd_soc_codec_conf rt1015_amp_conf[] = {
980 	{
981 		.dlc = COMP_CODEC_CONF(RT1015_DEV0_NAME),
982 		.name_prefix = "Left",
983 	},
984 	{
985 		.dlc = COMP_CODEC_CONF(RT1015_DEV1_NAME),
986 		.name_prefix = "Right",
987 	},
988 };
989 
990 static struct snd_soc_card mt8192_mt6359_rt1015_rt5682_card = {
991 	.name = "mt8192_mt6359_rt1015_rt5682",
992 	.owner = THIS_MODULE,
993 	.dai_link = mt8192_mt6359_dai_links,
994 	.num_links = ARRAY_SIZE(mt8192_mt6359_dai_links),
995 	.controls = mt8192_mt6359_rt1015_rt5682_controls,
996 	.num_controls = ARRAY_SIZE(mt8192_mt6359_rt1015_rt5682_controls),
997 	.dapm_widgets = mt8192_mt6359_rt1015_rt5682_widgets,
998 	.num_dapm_widgets = ARRAY_SIZE(mt8192_mt6359_rt1015_rt5682_widgets),
999 	.dapm_routes = mt8192_mt6359_rt1015_rt5682_routes,
1000 	.num_dapm_routes = ARRAY_SIZE(mt8192_mt6359_rt1015_rt5682_routes),
1001 	.codec_conf = rt1015_amp_conf,
1002 	.num_configs = ARRAY_SIZE(rt1015_amp_conf),
1003 };
1004 
1005 static const struct snd_soc_dapm_widget
1006 mt8192_mt6359_rt1015p_rt5682_widgets[] = {
1007 	SND_SOC_DAPM_SPK("Speakers", NULL),
1008 	SND_SOC_DAPM_HP("Headphone Jack", NULL),
1009 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
1010 };
1011 
1012 static const struct snd_soc_dapm_route mt8192_mt6359_rt1015p_rt5682_routes[] = {
1013 	/* speaker */
1014 	{ "Speakers", NULL, "Speaker" },
1015 	/* headset */
1016 	{ "Headphone Jack", NULL, "HPOL" },
1017 	{ "Headphone Jack", NULL, "HPOR" },
1018 	{ "IN1P", NULL, "Headset Mic" },
1019 };
1020 
1021 static const struct snd_kcontrol_new mt8192_mt6359_rt1015p_rt5682_controls[] = {
1022 	SOC_DAPM_PIN_SWITCH("Speakers"),
1023 	SOC_DAPM_PIN_SWITCH("Headphone Jack"),
1024 	SOC_DAPM_PIN_SWITCH("Headset Mic"),
1025 };
1026 
1027 static struct snd_soc_card mt8192_mt6359_rt1015p_rt5682_card = {
1028 	.name = "mt8192_mt6359_rt1015p_rt5682",
1029 	.owner = THIS_MODULE,
1030 	.dai_link = mt8192_mt6359_dai_links,
1031 	.num_links = ARRAY_SIZE(mt8192_mt6359_dai_links),
1032 	.controls = mt8192_mt6359_rt1015p_rt5682_controls,
1033 	.num_controls = ARRAY_SIZE(mt8192_mt6359_rt1015p_rt5682_controls),
1034 	.dapm_widgets = mt8192_mt6359_rt1015p_rt5682_widgets,
1035 	.num_dapm_widgets = ARRAY_SIZE(mt8192_mt6359_rt1015p_rt5682_widgets),
1036 	.dapm_routes = mt8192_mt6359_rt1015p_rt5682_routes,
1037 	.num_dapm_routes = ARRAY_SIZE(mt8192_mt6359_rt1015p_rt5682_routes),
1038 };
1039 
1040 static int mt8192_mt6359_dev_probe(struct platform_device *pdev)
1041 {
1042 	struct snd_soc_card *card;
1043 	struct device_node *platform_node;
1044 	int ret, i;
1045 	struct snd_soc_dai_link *dai_link;
1046 	const struct of_device_id *match;
1047 
1048 	platform_node = of_parse_phandle(pdev->dev.of_node,
1049 					 "mediatek,platform", 0);
1050 	if (!platform_node) {
1051 		dev_err(&pdev->dev, "Property 'platform' missing or invalid\n");
1052 		return -EINVAL;
1053 	}
1054 
1055 	match = of_match_device(pdev->dev.driver->of_match_table, &pdev->dev);
1056 	if (!match || !match->data)
1057 		return -EINVAL;
1058 
1059 	card = (struct snd_soc_card *)match->data;
1060 	card->dev = &pdev->dev;
1061 
1062 	for_each_card_prelinks(card, i, dai_link) {
1063 		if (strcmp(dai_link->name, "I2S3") == 0) {
1064 			if (card == &mt8192_mt6359_rt1015_rt5682_card) {
1065 				dai_link->ops = &mt8192_rt1015_i2s_ops;
1066 				dai_link->cpus = i2s3_rt1015_cpus;
1067 				dai_link->num_cpus =
1068 					ARRAY_SIZE(i2s3_rt1015_cpus);
1069 				dai_link->codecs = i2s3_rt1015_codecs;
1070 				dai_link->num_codecs =
1071 					ARRAY_SIZE(i2s3_rt1015_codecs);
1072 				dai_link->platforms = i2s3_rt1015_platforms;
1073 				dai_link->num_platforms =
1074 					ARRAY_SIZE(i2s3_rt1015_platforms);
1075 			} else if (card == &mt8192_mt6359_rt1015p_rt5682_card) {
1076 				dai_link->cpus = i2s3_rt1015p_cpus;
1077 				dai_link->num_cpus =
1078 					ARRAY_SIZE(i2s3_rt1015p_cpus);
1079 				dai_link->codecs = i2s3_rt1015p_codecs;
1080 				dai_link->num_codecs =
1081 					ARRAY_SIZE(i2s3_rt1015p_codecs);
1082 				dai_link->platforms = i2s3_rt1015p_platforms;
1083 				dai_link->num_platforms =
1084 					ARRAY_SIZE(i2s3_rt1015p_platforms);
1085 			}
1086 		}
1087 
1088 		if (!dai_link->platforms->name)
1089 			dai_link->platforms->of_node = platform_node;
1090 	}
1091 
1092 	ret = mt8192_afe_gpio_init(&pdev->dev);
1093 	if (ret) {
1094 		dev_err(&pdev->dev, "init gpio error %d\n", ret);
1095 		return ret;
1096 	}
1097 
1098 	return devm_snd_soc_register_card(&pdev->dev, card);
1099 }
1100 
1101 #ifdef CONFIG_OF
1102 static const struct of_device_id mt8192_mt6359_dt_match[] = {
1103 	{
1104 		.compatible = "mediatek,mt8192_mt6359_rt1015_rt5682",
1105 		.data = &mt8192_mt6359_rt1015_rt5682_card,
1106 	},
1107 	{
1108 		.compatible = "mediatek,mt8192_mt6359_rt1015p_rt5682",
1109 		.data = &mt8192_mt6359_rt1015p_rt5682_card,
1110 	},
1111 	{}
1112 };
1113 #endif
1114 
1115 static const struct dev_pm_ops mt8192_mt6359_pm_ops = {
1116 	.poweroff = snd_soc_poweroff,
1117 	.restore = snd_soc_resume,
1118 };
1119 
1120 static struct platform_driver mt8192_mt6359_driver = {
1121 	.driver = {
1122 		.name = "mt8192_mt6359",
1123 #ifdef CONFIG_OF
1124 		.of_match_table = mt8192_mt6359_dt_match,
1125 #endif
1126 		.pm = &mt8192_mt6359_pm_ops,
1127 	},
1128 	.probe = mt8192_mt6359_dev_probe,
1129 };
1130 
1131 module_platform_driver(mt8192_mt6359_driver);
1132 
1133 /* Module information */
1134 MODULE_DESCRIPTION("MT8192-MT6359 ALSA SoC machine driver");
1135 MODULE_AUTHOR("Jiaxin Yu <jiaxin.yu@mediatek.com>");
1136 MODULE_LICENSE("GPL v2");
1137 MODULE_ALIAS("mt8192_mt6359 soc card");
1138