xref: /linux/sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c (revision e3fc2fd77c63cd2e37ebd33a336602a68650f22b)
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 		.dpcm_playback = 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 		.dpcm_playback = 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 		.dpcm_playback = 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 		.dpcm_playback = 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 		.dpcm_playback = 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 		.dpcm_playback = 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 		.dpcm_playback = 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 		.dpcm_playback = 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 		.dpcm_playback = 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 		.dpcm_playback = 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 		.dpcm_capture = 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 		.dpcm_capture = 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 		.dpcm_capture = 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 		.dpcm_capture = 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 		.dpcm_capture = 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 		.dpcm_capture = 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 		.dpcm_capture = 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 		.dpcm_capture = 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 		.dpcm_capture = 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 		.dpcm_capture = 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 		.dpcm_capture = 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 		.dpcm_playback = 1,
794 		SND_SOC_DAILINK_REG(playback_hdmi),
795 	},
796 	/* Back End DAI links */
797 	{
798 		.name = "Primary Codec",
799 		.no_pcm = 1,
800 		.dpcm_playback = 1,
801 		.dpcm_capture = 1,
802 		.ignore_suspend = 1,
803 		.init = mt8192_mt6359_init,
804 		SND_SOC_DAILINK_REG(primary_codec),
805 	},
806 	{
807 		.name = "Primary Codec CH34",
808 		.no_pcm = 1,
809 		.dpcm_playback = 1,
810 		.dpcm_capture = 1,
811 		.ignore_suspend = 1,
812 		SND_SOC_DAILINK_REG(primary_codec_ch34),
813 	},
814 	{
815 		.name = "AP_DMIC",
816 		.no_pcm = 1,
817 		.dpcm_capture = 1,
818 		.ignore_suspend = 1,
819 		SND_SOC_DAILINK_REG(ap_dmic),
820 	},
821 	{
822 		.name = "AP_DMIC_CH34",
823 		.no_pcm = 1,
824 		.dpcm_capture = 1,
825 		.ignore_suspend = 1,
826 		SND_SOC_DAILINK_REG(ap_dmic_ch34),
827 	},
828 	{
829 		.name = "I2S0",
830 		.no_pcm = 1,
831 		.dpcm_capture = 1,
832 		.ignore_suspend = 1,
833 		.be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
834 		SND_SOC_DAILINK_REG(i2s0),
835 	},
836 	{
837 		.name = "I2S1",
838 		.no_pcm = 1,
839 		.dpcm_playback = 1,
840 		.ignore_suspend = 1,
841 		.be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
842 		SND_SOC_DAILINK_REG(i2s1),
843 	},
844 	{
845 		.name = "I2S2",
846 		.no_pcm = 1,
847 		.dpcm_capture = 1,
848 		.ignore_suspend = 1,
849 		.be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
850 		SND_SOC_DAILINK_REG(i2s2),
851 	},
852 	{
853 		.name = "I2S3",
854 		.no_pcm = 1,
855 		.dpcm_playback = 1,
856 		.ignore_suspend = 1,
857 		.be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
858 		SND_SOC_DAILINK_REG(i2s3),
859 	},
860 	{
861 		.name = "I2S5",
862 		.no_pcm = 1,
863 		.dpcm_playback = 1,
864 		.ignore_suspend = 1,
865 		.be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
866 		SND_SOC_DAILINK_REG(i2s5),
867 	},
868 	{
869 		.name = "I2S6",
870 		.no_pcm = 1,
871 		.dpcm_capture = 1,
872 		.ignore_suspend = 1,
873 		.be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
874 		SND_SOC_DAILINK_REG(i2s6),
875 	},
876 	{
877 		.name = "I2S7",
878 		.no_pcm = 1,
879 		.dpcm_playback = 1,
880 		.ignore_suspend = 1,
881 		.be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
882 		SND_SOC_DAILINK_REG(i2s7),
883 	},
884 	{
885 		.name = "I2S8",
886 		.no_pcm = 1,
887 		.dpcm_capture = 1,
888 		.ignore_suspend = 1,
889 		.init = mt8192_rt5682_init,
890 		.be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
891 		SND_SOC_DAILINK_REG(i2s8),
892 		.ops = &mt8192_rt5682x_i2s_ops,
893 	},
894 	{
895 		.name = "I2S9",
896 		.no_pcm = 1,
897 		.dpcm_playback = 1,
898 		.ignore_suspend = 1,
899 		.be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
900 		SND_SOC_DAILINK_REG(i2s9),
901 		.ops = &mt8192_rt5682x_i2s_ops,
902 	},
903 	{
904 		.name = "CONNSYS_I2S",
905 		.no_pcm = 1,
906 		.dpcm_capture = 1,
907 		.ignore_suspend = 1,
908 		SND_SOC_DAILINK_REG(connsys_i2s),
909 	},
910 	{
911 		.name = "PCM 1",
912 		.no_pcm = 1,
913 		.dpcm_playback = 1,
914 		.dpcm_capture = 1,
915 		.ignore_suspend = 1,
916 		SND_SOC_DAILINK_REG(pcm1),
917 	},
918 	{
919 		.name = "PCM 2",
920 		.no_pcm = 1,
921 		.dpcm_playback = 1,
922 		.dpcm_capture = 1,
923 		.ignore_suspend = 1,
924 		SND_SOC_DAILINK_REG(pcm2),
925 	},
926 	{
927 		.name = "TDM",
928 		.no_pcm = 1,
929 		.dai_fmt = SND_SOC_DAIFMT_DSP_A |
930 			   SND_SOC_DAIFMT_IB_NF |
931 			   SND_SOC_DAIFMT_CBM_CFM,
932 		.dpcm_playback = 1,
933 		.ignore_suspend = 1,
934 		.be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
935 		.ignore = 1,
936 		.init = mt8192_mt6359_hdmi_init,
937 		SND_SOC_DAILINK_REG(tdm),
938 	},
939 };
940 
941 static const struct snd_soc_dapm_widget
942 mt8192_mt6359_rt1015_rt5682_widgets[] = {
943 	SND_SOC_DAPM_SPK("Left Spk", NULL),
944 	SND_SOC_DAPM_SPK("Right Spk", NULL),
945 	SND_SOC_DAPM_HP("Headphone Jack", NULL),
946 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
947 	SND_SOC_DAPM_OUTPUT("TDM Out"),
948 };
949 
950 static const struct snd_soc_dapm_route mt8192_mt6359_rt1015_rt5682_routes[] = {
951 	/* speaker */
952 	{ "Left Spk", NULL, "Left SPO" },
953 	{ "Right Spk", NULL, "Right SPO" },
954 	/* headset */
955 	{ "Headphone Jack", NULL, "HPOL" },
956 	{ "Headphone Jack", NULL, "HPOR" },
957 	{ "IN1P", NULL, "Headset Mic" },
958 	/* TDM */
959 	{ "TDM Out", NULL, "TDM" },
960 };
961 
962 static const struct snd_kcontrol_new mt8192_mt6359_rt1015_rt5682_controls[] = {
963 	SOC_DAPM_PIN_SWITCH("Left Spk"),
964 	SOC_DAPM_PIN_SWITCH("Right Spk"),
965 	SOC_DAPM_PIN_SWITCH("Headphone Jack"),
966 	SOC_DAPM_PIN_SWITCH("Headset Mic"),
967 };
968 
969 static struct snd_soc_codec_conf rt1015_amp_conf[] = {
970 	{
971 		.dlc = COMP_CODEC_CONF(RT1015_DEV0_NAME),
972 		.name_prefix = "Left",
973 	},
974 	{
975 		.dlc = COMP_CODEC_CONF(RT1015_DEV1_NAME),
976 		.name_prefix = "Right",
977 	},
978 };
979 
980 static struct snd_soc_card mt8192_mt6359_rt1015_rt5682_card = {
981 	.name = RT1015_RT5682_CARD_NAME,
982 	.driver_name = DRIVER_NAME,
983 	.owner = THIS_MODULE,
984 	.dai_link = mt8192_mt6359_dai_links,
985 	.num_links = ARRAY_SIZE(mt8192_mt6359_dai_links),
986 	.controls = mt8192_mt6359_rt1015_rt5682_controls,
987 	.num_controls = ARRAY_SIZE(mt8192_mt6359_rt1015_rt5682_controls),
988 	.dapm_widgets = mt8192_mt6359_rt1015_rt5682_widgets,
989 	.num_dapm_widgets = ARRAY_SIZE(mt8192_mt6359_rt1015_rt5682_widgets),
990 	.dapm_routes = mt8192_mt6359_rt1015_rt5682_routes,
991 	.num_dapm_routes = ARRAY_SIZE(mt8192_mt6359_rt1015_rt5682_routes),
992 	.codec_conf = rt1015_amp_conf,
993 	.num_configs = ARRAY_SIZE(rt1015_amp_conf),
994 };
995 
996 static const struct snd_soc_dapm_widget mt8192_mt6359_rt1015p_rt5682x_widgets[] = {
997 	SND_SOC_DAPM_SPK("Speakers", NULL),
998 	SND_SOC_DAPM_HP("Headphone Jack", NULL),
999 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
1000 };
1001 
1002 static const struct snd_soc_dapm_route mt8192_mt6359_rt1015p_rt5682x_routes[] = {
1003 	/* speaker */
1004 	{ "Speakers", NULL, "Speaker" },
1005 	/* headset */
1006 	{ "Headphone Jack", NULL, "HPOL" },
1007 	{ "Headphone Jack", NULL, "HPOR" },
1008 	{ "IN1P", NULL, "Headset Mic" },
1009 };
1010 
1011 static const struct snd_kcontrol_new mt8192_mt6359_rt1015p_rt5682x_controls[] = {
1012 	SOC_DAPM_PIN_SWITCH("Speakers"),
1013 	SOC_DAPM_PIN_SWITCH("Headphone Jack"),
1014 	SOC_DAPM_PIN_SWITCH("Headset Mic"),
1015 };
1016 
1017 static struct snd_soc_card mt8192_mt6359_rt1015p_rt5682x_card = {
1018 	.driver_name = DRIVER_NAME,
1019 	.owner = THIS_MODULE,
1020 	.dai_link = mt8192_mt6359_dai_links,
1021 	.num_links = ARRAY_SIZE(mt8192_mt6359_dai_links),
1022 	.controls = mt8192_mt6359_rt1015p_rt5682x_controls,
1023 	.num_controls = ARRAY_SIZE(mt8192_mt6359_rt1015p_rt5682x_controls),
1024 	.dapm_widgets = mt8192_mt6359_rt1015p_rt5682x_widgets,
1025 	.num_dapm_widgets = ARRAY_SIZE(mt8192_mt6359_rt1015p_rt5682x_widgets),
1026 	.dapm_routes = mt8192_mt6359_rt1015p_rt5682x_routes,
1027 	.num_dapm_routes = ARRAY_SIZE(mt8192_mt6359_rt1015p_rt5682x_routes),
1028 };
1029 
1030 static int mt8192_mt6359_card_set_be_link(struct snd_soc_card *card,
1031 					  struct snd_soc_dai_link *link,
1032 					  struct device_node *node,
1033 					  char *link_name)
1034 {
1035 	int ret;
1036 
1037 	if (node && strcmp(link->name, link_name) == 0) {
1038 		ret = snd_soc_of_get_dai_link_codecs(card->dev, node, link);
1039 		if (ret < 0) {
1040 			dev_err_probe(card->dev, ret, "get dai link codecs fail\n");
1041 			return ret;
1042 		}
1043 	}
1044 
1045 	return 0;
1046 }
1047 
1048 static int mt8192_mt6359_legacy_probe(struct mtk_soc_card_data *soc_card_data)
1049 {
1050 	struct mtk_platform_card_data *card_data = soc_card_data->card_data;
1051 	struct snd_soc_card *card = card_data->card;
1052 	struct device *dev = card->dev;
1053 	struct device_node *hdmi_codec, *headset_codec, *speaker_codec;
1054 	struct snd_soc_dai_link *dai_link;
1055 	int i, ret = 0;
1056 
1057 	hdmi_codec = of_parse_phandle(dev->of_node, "mediatek,hdmi-codec", 0);
1058 	if (!hdmi_codec)
1059 		dev_dbg(dev, "The machine has no hdmi-codec\n");
1060 
1061 	speaker_codec = of_get_child_by_name(dev->of_node, "speaker-codecs");
1062 	if (!speaker_codec) {
1063 		ret = -EINVAL;
1064 		dev_err_probe(dev, ret, "Property 'speaker-codecs' missing or invalid\n");
1065 		goto err_speaker_codec;
1066 	}
1067 
1068 	headset_codec = of_get_child_by_name(dev->of_node, "headset-codec");
1069 	if (!headset_codec) {
1070 		ret = -EINVAL;
1071 		dev_err_probe(dev, ret, "Property 'headset-codec' missing or invalid\n");
1072 		goto err_headset_codec;
1073 	}
1074 
1075 	for_each_card_prelinks(card, i, dai_link) {
1076 		ret = mt8192_mt6359_card_set_be_link(card, dai_link, speaker_codec, "I2S3");
1077 		if (ret) {
1078 			dev_err_probe(dev, ret, "%s set speaker_codec fail\n",
1079 				      dai_link->name);
1080 			break;
1081 		}
1082 
1083 		ret = mt8192_mt6359_card_set_be_link(card, dai_link, headset_codec, "I2S8");
1084 		if (ret) {
1085 			dev_err_probe(dev, ret, "%s set headset_codec fail\n",
1086 				      dai_link->name);
1087 			break;
1088 		}
1089 
1090 		ret = mt8192_mt6359_card_set_be_link(card, dai_link, headset_codec, "I2S9");
1091 		if (ret) {
1092 			dev_err_probe(dev, ret, "%s set headset_codec fail\n",
1093 				      dai_link->name);
1094 			break;
1095 		}
1096 
1097 		if (hdmi_codec && strcmp(dai_link->name, "TDM") == 0) {
1098 			dai_link->codecs->of_node = hdmi_codec;
1099 			dai_link->ignore = 0;
1100 		}
1101 
1102 		if (dai_link->num_codecs && dai_link->codecs[0].dai_name &&
1103 		    strcmp(dai_link->codecs[0].dai_name, RT1015_CODEC_DAI) == 0)
1104 			dai_link->ops = &mt8192_rt1015_i2s_ops;
1105 	}
1106 
1107 	of_node_put(headset_codec);
1108 err_headset_codec:
1109 	of_node_put(speaker_codec);
1110 err_speaker_codec:
1111 	of_node_put(hdmi_codec);
1112 	return ret;
1113 }
1114 
1115 static int mt8192_mt6359_soc_card_probe(struct mtk_soc_card_data *soc_card_data, bool legacy)
1116 {
1117 	struct mtk_platform_card_data *card_data = soc_card_data->card_data;
1118 	struct snd_soc_card *card = card_data->card;
1119 	int ret;
1120 
1121 	if (legacy) {
1122 		ret = mt8192_mt6359_legacy_probe(soc_card_data);
1123 		if (ret)
1124 			return ret;
1125 	} else {
1126 		struct snd_soc_dai_link *dai_link;
1127 		int i;
1128 
1129 		for_each_card_prelinks(card, i, dai_link)
1130 			if (dai_link->num_codecs && dai_link->codecs[0].dai_name &&
1131 			    strcmp(dai_link->codecs[0].dai_name, RT1015_CODEC_DAI) == 0)
1132 				dai_link->ops = &mt8192_rt1015_i2s_ops;
1133 	}
1134 
1135 	ret = mt8192_afe_gpio_init(card->dev);
1136 	if (ret)
1137 		return dev_err_probe(card->dev, ret, "%s init gpio error\n", __func__);
1138 
1139 	return 0;
1140 }
1141 
1142 static const unsigned int mt8192_pcm_playback_channels[] = { 1, 2 };
1143 static const unsigned int mt8192_pcm_playback_rates[] = { 48000 };
1144 
1145 static const unsigned int mt8192_pcm_capture_channels[] = { 1, 2, 4 };
1146 static const unsigned int mt8192_pcm_capture_rates[] = {
1147 	8000, 16000, 32000, 48000, 96000, 192000
1148 };
1149 
1150 static const struct mtk_pcm_constraints_data mt8192_pcm_constraints[MTK_CONSTRAINT_CAPTURE + 1] = {
1151 	[MTK_CONSTRAINT_PLAYBACK] = {
1152 		.channels =  &(const struct snd_pcm_hw_constraint_list) {
1153 			.list = mt8192_pcm_playback_channels,
1154 			.count = ARRAY_SIZE(mt8192_pcm_playback_channels)
1155 		},
1156 		.rates =  &(const struct snd_pcm_hw_constraint_list) {
1157 			.list = mt8192_pcm_playback_rates,
1158 			.count = ARRAY_SIZE(mt8192_pcm_playback_rates)
1159 		}
1160 	},
1161 	[MTK_CONSTRAINT_CAPTURE] = {
1162 		.channels =  &(const struct snd_pcm_hw_constraint_list) {
1163 			.list = mt8192_pcm_capture_channels,
1164 			.count = ARRAY_SIZE(mt8192_pcm_capture_channels)
1165 		},
1166 		.rates =  &(const struct snd_pcm_hw_constraint_list) {
1167 			.list = mt8192_pcm_capture_rates,
1168 			.count = ARRAY_SIZE(mt8192_pcm_capture_rates)
1169 		}
1170 	}
1171 };
1172 
1173 static const struct mtk_soundcard_pdata mt8192_mt6359_rt1015_rt5682_pdata = {
1174 	.card_name = RT1015_RT5682_CARD_NAME,
1175 	.card_data = &(struct mtk_platform_card_data) {
1176 		.card = &mt8192_mt6359_rt1015_rt5682_card,
1177 		.num_jacks = MT8192_JACK_MAX,
1178 		.pcm_constraints = mt8192_pcm_constraints,
1179 		.num_pcm_constraints = ARRAY_SIZE(mt8192_pcm_constraints),
1180 	},
1181 	.soc_probe = mt8192_mt6359_soc_card_probe
1182 };
1183 
1184 static const struct mtk_soundcard_pdata mt8192_mt6359_rt1015p_rt5682_pdata = {
1185 	.card_name = RT1015P_RT5682_CARD_NAME,
1186 	.card_data = &(struct mtk_platform_card_data) {
1187 		.card = &mt8192_mt6359_rt1015p_rt5682x_card,
1188 		.num_jacks = MT8192_JACK_MAX,
1189 		.pcm_constraints = mt8192_pcm_constraints,
1190 		.num_pcm_constraints = ARRAY_SIZE(mt8192_pcm_constraints),
1191 	},
1192 	.soc_probe = mt8192_mt6359_soc_card_probe
1193 };
1194 
1195 static const struct mtk_soundcard_pdata mt8192_mt6359_rt1015p_rt5682s_pdata = {
1196 	.card_name = RT1015P_RT5682S_CARD_NAME,
1197 	.card_data = &(struct mtk_platform_card_data) {
1198 		.card = &mt8192_mt6359_rt1015p_rt5682x_card,
1199 		.num_jacks = MT8192_JACK_MAX,
1200 		.pcm_constraints = mt8192_pcm_constraints,
1201 		.num_pcm_constraints = ARRAY_SIZE(mt8192_pcm_constraints),
1202 	},
1203 	.soc_probe = mt8192_mt6359_soc_card_probe
1204 };
1205 
1206 #ifdef CONFIG_OF
1207 static const struct of_device_id mt8192_mt6359_dt_match[] = {
1208 	{
1209 		.compatible = RT1015_RT5682_OF_NAME,
1210 		.data = &mt8192_mt6359_rt1015_rt5682_pdata,
1211 	},
1212 	{
1213 		.compatible = RT1015P_RT5682_OF_NAME,
1214 		.data = &mt8192_mt6359_rt1015p_rt5682_pdata,
1215 	},
1216 	{
1217 		.compatible = RT1015P_RT5682S_OF_NAME,
1218 		.data = &mt8192_mt6359_rt1015p_rt5682s_pdata,
1219 	},
1220 	{}
1221 };
1222 MODULE_DEVICE_TABLE(of, mt8192_mt6359_dt_match);
1223 #endif
1224 
1225 static const struct dev_pm_ops mt8192_mt6359_pm_ops = {
1226 	.poweroff = snd_soc_poweroff,
1227 	.restore = snd_soc_resume,
1228 };
1229 
1230 static struct platform_driver mt8192_mt6359_driver = {
1231 	.driver = {
1232 		.name = DRIVER_NAME,
1233 #ifdef CONFIG_OF
1234 		.of_match_table = mt8192_mt6359_dt_match,
1235 #endif
1236 		.pm = &mt8192_mt6359_pm_ops,
1237 	},
1238 	.probe = mtk_soundcard_common_probe,
1239 };
1240 
1241 module_platform_driver(mt8192_mt6359_driver);
1242 
1243 /* Module information */
1244 MODULE_DESCRIPTION("MT8192-MT6359 ALSA SoC machine driver");
1245 MODULE_AUTHOR("Jiaxin Yu <jiaxin.yu@mediatek.com>");
1246 MODULE_LICENSE("GPL v2");
1247 MODULE_ALIAS("mt8192_mt6359 soc card");
1248