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