1 // SPDX-License-Identifier: GPL-2.0
3 // mt8192-mt6359-rt1015-rt5682.c --
4 // MT8192-MT6359-RT1015-RT6358 ALSA SoC machine driver
6 // Copyright (c) 2020 MediaTek Inc.
7 // Author: Jiaxin Yu <jiaxin.yu@mediatek.com>
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>
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"
27 #define RT1015_CODEC_DAI "rt1015-aif"
28 #define RT1015_DEV0_NAME "rt1015.1-0028"
29 #define RT1015_DEV1_NAME "rt1015.1-0029"
31 #define RT1015_RT5682_CARD_NAME "mt8192_mt6359_rt1015_rt5682"
32 #define RT1015P_RT5682_CARD_NAME "mt8192_mt6359_rt1015p_rt5682"
33 #define RT1015P_RT5682S_CARD_NAME "mt8192_mt6359_rt1015p_rt5682s"
35 #define RT1015_RT5682_OF_NAME "mediatek,mt8192_mt6359_rt1015_rt5682"
36 #define RT1015P_RT5682_OF_NAME "mediatek,mt8192_mt6359_rt1015p_rt5682"
37 #define RT1015P_RT5682S_OF_NAME "mediatek,mt8192_mt6359_rt1015p_rt5682s"
39 struct mt8192_mt6359_priv {
40 struct snd_soc_jack headset_jack;
41 struct snd_soc_jack hdmi_jack;
44 static int mt8192_rt1015_i2s_hw_params(struct snd_pcm_substream *substream,
45 struct snd_pcm_hw_params *params)
47 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
48 struct snd_soc_card *card = rtd->card;
49 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
50 struct snd_soc_dai *codec_dai;
51 unsigned int rate = params_rate(params);
52 unsigned int mclk_fs_ratio = 128;
53 unsigned int mclk_fs = rate * mclk_fs_ratio;
56 for_each_rtd_codec_dais(rtd, i, codec_dai) {
57 ret = snd_soc_dai_set_pll(codec_dai, 0,
59 params_rate(params) * 64,
60 params_rate(params) * 256);
62 dev_err(card->dev, "failed to set pll\n");
66 ret = snd_soc_dai_set_sysclk(codec_dai,
68 params_rate(params) * 256,
71 dev_err(card->dev, "failed to set sysclk\n");
76 return snd_soc_dai_set_sysclk(cpu_dai, 0, mclk_fs, SND_SOC_CLOCK_OUT);
79 static int mt8192_rt5682x_i2s_hw_params(struct snd_pcm_substream *substream,
80 struct snd_pcm_hw_params *params)
82 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
83 struct snd_soc_card *card = rtd->card;
84 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
85 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
86 unsigned int rate = params_rate(params);
87 unsigned int mclk_fs_ratio = 128;
88 unsigned int mclk_fs = rate * mclk_fs_ratio;
92 bitwidth = snd_pcm_format_width(params_format(params));
94 dev_err(card->dev, "invalid bit width: %d\n", bitwidth);
98 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x00, 0x0, 0x2, bitwidth);
100 dev_err(card->dev, "failed to set tdm slot\n");
104 ret = snd_soc_dai_set_pll(codec_dai, RT5682_PLL1,
106 params_rate(params) * 64,
107 params_rate(params) * 512);
109 dev_err(card->dev, "failed to set pll\n");
113 ret = snd_soc_dai_set_sysclk(codec_dai,
115 params_rate(params) * 512,
118 dev_err(card->dev, "failed to set sysclk\n");
122 return snd_soc_dai_set_sysclk(cpu_dai, 0, mclk_fs, SND_SOC_CLOCK_OUT);
125 static const struct snd_soc_ops mt8192_rt1015_i2s_ops = {
126 .hw_params = mt8192_rt1015_i2s_hw_params,
129 static const struct snd_soc_ops mt8192_rt5682x_i2s_ops = {
130 .hw_params = mt8192_rt5682x_i2s_hw_params,
133 static int mt8192_mt6359_mtkaif_calibration(struct snd_soc_pcm_runtime *rtd)
135 struct snd_soc_component *cmpnt_afe =
136 snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
137 struct snd_soc_component *cmpnt_codec =
138 asoc_rtd_to_codec(rtd, 0)->component;
139 struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe);
140 struct mt8192_afe_private *afe_priv = afe->platform_priv;
142 unsigned int monitor;
143 int test_done_1, test_done_2, test_done_3;
144 int cycle_1, cycle_2, cycle_3;
145 int prev_cycle_1, prev_cycle_2, prev_cycle_3;
146 int chosen_phase_1, chosen_phase_2, chosen_phase_3;
150 dev_info(afe->dev, "%s(), start\n", __func__);
152 pm_runtime_get_sync(afe->dev);
153 mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA, 1);
154 mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA, 0);
155 mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA_CH34, 1);
156 mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA_CH34, 0);
158 mt6359_mtkaif_calibration_enable(cmpnt_codec);
160 /* set clock protocol 2 */
161 regmap_update_bits(afe->regmap, AFE_AUD_PAD_TOP, 0xff, 0x38);
162 regmap_update_bits(afe->regmap, AFE_AUD_PAD_TOP, 0xff, 0x39);
164 /* set test type to synchronizer pulse */
165 regmap_update_bits(afe_priv->topckgen,
166 CKSYS_AUD_TOP_CFG, 0xffff, 0x4);
168 mtkaif_calib_ok = true;
169 afe_priv->mtkaif_calibration_num_phase = 42; /* mt6359: 0 ~ 42 */
170 afe_priv->mtkaif_chosen_phase[0] = -1;
171 afe_priv->mtkaif_chosen_phase[1] = -1;
172 afe_priv->mtkaif_chosen_phase[2] = -1;
175 phase <= afe_priv->mtkaif_calibration_num_phase &&
178 mt6359_set_mtkaif_calibration_phase(cmpnt_codec,
179 phase, phase, phase);
181 regmap_update_bits(afe_priv->topckgen,
182 CKSYS_AUD_TOP_CFG, 0x1, 0x1);
191 while (test_done_1 == 0 ||
194 regmap_read(afe_priv->topckgen,
195 CKSYS_AUD_TOP_MON, &monitor);
197 test_done_1 = (monitor >> 28) & 0x1;
198 test_done_2 = (monitor >> 29) & 0x1;
199 test_done_3 = (monitor >> 30) & 0x1;
200 if (test_done_1 == 1)
201 cycle_1 = monitor & 0xf;
203 if (test_done_2 == 1)
204 cycle_2 = (monitor >> 4) & 0xf;
206 if (test_done_3 == 1)
207 cycle_3 = (monitor >> 8) & 0xf;
209 /* handle if never test done */
210 if (++counter > 10000) {
211 dev_err(afe->dev, "%s(), test fail, cycle_1 %d, cycle_2 %d, cycle_3 %d, monitor 0x%x\n",
213 cycle_1, cycle_2, cycle_3, monitor);
214 mtkaif_calib_ok = false;
220 prev_cycle_1 = cycle_1;
221 prev_cycle_2 = cycle_2;
222 prev_cycle_3 = cycle_3;
225 if (cycle_1 != prev_cycle_1 &&
226 afe_priv->mtkaif_chosen_phase[0] < 0) {
227 afe_priv->mtkaif_chosen_phase[0] = phase - 1;
228 afe_priv->mtkaif_phase_cycle[0] = prev_cycle_1;
231 if (cycle_2 != prev_cycle_2 &&
232 afe_priv->mtkaif_chosen_phase[1] < 0) {
233 afe_priv->mtkaif_chosen_phase[1] = phase - 1;
234 afe_priv->mtkaif_phase_cycle[1] = prev_cycle_2;
237 if (cycle_3 != prev_cycle_3 &&
238 afe_priv->mtkaif_chosen_phase[2] < 0) {
239 afe_priv->mtkaif_chosen_phase[2] = phase - 1;
240 afe_priv->mtkaif_phase_cycle[2] = prev_cycle_3;
243 regmap_update_bits(afe_priv->topckgen,
244 CKSYS_AUD_TOP_CFG, 0x1, 0x0);
246 if (afe_priv->mtkaif_chosen_phase[0] >= 0 &&
247 afe_priv->mtkaif_chosen_phase[1] >= 0 &&
248 afe_priv->mtkaif_chosen_phase[2] >= 0)
252 if (afe_priv->mtkaif_chosen_phase[0] < 0)
255 chosen_phase_1 = afe_priv->mtkaif_chosen_phase[0];
257 if (afe_priv->mtkaif_chosen_phase[1] < 0)
260 chosen_phase_2 = afe_priv->mtkaif_chosen_phase[1];
262 if (afe_priv->mtkaif_chosen_phase[2] < 0)
265 chosen_phase_3 = afe_priv->mtkaif_chosen_phase[2];
267 mt6359_set_mtkaif_calibration_phase(cmpnt_codec,
272 /* disable rx fifo */
273 regmap_update_bits(afe->regmap, AFE_AUD_PAD_TOP, 0xff, 0x38);
275 mt6359_mtkaif_calibration_disable(cmpnt_codec);
277 mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA, 1);
278 mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA, 0);
279 mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA_CH34, 1);
280 mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA_CH34, 0);
281 pm_runtime_put(afe->dev);
283 dev_info(afe->dev, "%s(), mtkaif_chosen_phase[0/1/2]:%d/%d/%d\n",
285 afe_priv->mtkaif_chosen_phase[0],
286 afe_priv->mtkaif_chosen_phase[1],
287 afe_priv->mtkaif_chosen_phase[2]);
292 static int mt8192_mt6359_init(struct snd_soc_pcm_runtime *rtd)
294 struct snd_soc_component *cmpnt_afe =
295 snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
296 struct snd_soc_component *cmpnt_codec =
297 asoc_rtd_to_codec(rtd, 0)->component;
298 struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe);
299 struct mt8192_afe_private *afe_priv = afe->platform_priv;
301 /* set mtkaif protocol */
302 mt6359_set_mtkaif_protocol(cmpnt_codec,
303 MT6359_MTKAIF_PROTOCOL_2_CLK_P2);
304 afe_priv->mtkaif_protocol = MTKAIF_PROTOCOL_2_CLK_P2;
306 /* mtkaif calibration */
307 mt8192_mt6359_mtkaif_calibration(rtd);
312 static int mt8192_rt5682_init(struct snd_soc_pcm_runtime *rtd)
314 struct snd_soc_component *cmpnt_codec =
315 asoc_rtd_to_codec(rtd, 0)->component;
316 struct mt8192_mt6359_priv *priv = snd_soc_card_get_drvdata(rtd->card);
317 struct snd_soc_jack *jack = &priv->headset_jack;
320 ret = snd_soc_card_jack_new(rtd->card, "Headset Jack",
321 SND_JACK_HEADSET | SND_JACK_BTN_0 |
322 SND_JACK_BTN_1 | SND_JACK_BTN_2 |
326 dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
330 snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
331 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
332 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
333 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
335 return snd_soc_component_set_jack(cmpnt_codec, jack, NULL);
338 static int mt8192_mt6359_hdmi_init(struct snd_soc_pcm_runtime *rtd)
340 struct snd_soc_component *cmpnt_codec =
341 asoc_rtd_to_codec(rtd, 0)->component;
342 struct mt8192_mt6359_priv *priv = snd_soc_card_get_drvdata(rtd->card);
345 ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT,
348 dev_err(rtd->dev, "HDMI Jack creation failed: %d\n", ret);
352 return snd_soc_component_set_jack(cmpnt_codec, &priv->hdmi_jack, NULL);
355 static int mt8192_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
356 struct snd_pcm_hw_params *params)
358 /* fix BE i2s format to S24_LE, clean param mask first */
359 snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT),
360 0, (__force unsigned int)SNDRV_PCM_FORMAT_LAST);
362 params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
368 mt8192_mt6359_cap1_startup(struct snd_pcm_substream *substream)
370 static const unsigned int channels[] = {
373 static const struct snd_pcm_hw_constraint_list constraints_channels = {
374 .count = ARRAY_SIZE(channels),
378 static const unsigned int rates[] = {
379 8000, 16000, 32000, 48000, 96000, 192000
381 static const struct snd_pcm_hw_constraint_list constraints_rates = {
382 .count = ARRAY_SIZE(rates),
387 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
388 struct snd_pcm_runtime *runtime = substream->runtime;
391 ret = snd_pcm_hw_constraint_list(runtime, 0,
392 SNDRV_PCM_HW_PARAM_CHANNELS,
393 &constraints_channels);
395 dev_err(rtd->dev, "hw_constraint_list channels failed\n");
399 ret = snd_pcm_hw_constraint_list(runtime, 0,
400 SNDRV_PCM_HW_PARAM_RATE,
403 dev_err(rtd->dev, "hw_constraint_list rate failed\n");
410 static const struct snd_soc_ops mt8192_mt6359_capture1_ops = {
411 .startup = mt8192_mt6359_cap1_startup,
415 mt8192_mt6359_rt5682_startup(struct snd_pcm_substream *substream)
417 static const unsigned int channels[] = {
420 static const struct snd_pcm_hw_constraint_list constraints_channels = {
421 .count = ARRAY_SIZE(channels),
425 static const unsigned int rates[] = {
428 static const struct snd_pcm_hw_constraint_list constraints_rates = {
429 .count = ARRAY_SIZE(rates),
434 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
435 struct snd_pcm_runtime *runtime = substream->runtime;
438 ret = snd_pcm_hw_constraint_list(runtime, 0,
439 SNDRV_PCM_HW_PARAM_CHANNELS,
440 &constraints_channels);
442 dev_err(rtd->dev, "hw_constraint_list channels failed\n");
446 ret = snd_pcm_hw_constraint_list(runtime, 0,
447 SNDRV_PCM_HW_PARAM_RATE,
450 dev_err(rtd->dev, "hw_constraint_list rate failed\n");
457 static const struct snd_soc_ops mt8192_mt6359_rt5682_ops = {
458 .startup = mt8192_mt6359_rt5682_startup,
462 SND_SOC_DAILINK_DEFS(playback1,
463 DAILINK_COMP_ARRAY(COMP_CPU("DL1")),
464 DAILINK_COMP_ARRAY(COMP_DUMMY()),
465 DAILINK_COMP_ARRAY(COMP_EMPTY()));
467 SND_SOC_DAILINK_DEFS(playback12,
468 DAILINK_COMP_ARRAY(COMP_CPU("DL12")),
469 DAILINK_COMP_ARRAY(COMP_DUMMY()),
470 DAILINK_COMP_ARRAY(COMP_EMPTY()));
472 SND_SOC_DAILINK_DEFS(playback2,
473 DAILINK_COMP_ARRAY(COMP_CPU("DL2")),
474 DAILINK_COMP_ARRAY(COMP_DUMMY()),
475 DAILINK_COMP_ARRAY(COMP_EMPTY()));
477 SND_SOC_DAILINK_DEFS(playback3,
478 DAILINK_COMP_ARRAY(COMP_CPU("DL3")),
479 DAILINK_COMP_ARRAY(COMP_DUMMY()),
480 DAILINK_COMP_ARRAY(COMP_EMPTY()));
482 SND_SOC_DAILINK_DEFS(playback4,
483 DAILINK_COMP_ARRAY(COMP_CPU("DL4")),
484 DAILINK_COMP_ARRAY(COMP_DUMMY()),
485 DAILINK_COMP_ARRAY(COMP_EMPTY()));
487 SND_SOC_DAILINK_DEFS(playback5,
488 DAILINK_COMP_ARRAY(COMP_CPU("DL5")),
489 DAILINK_COMP_ARRAY(COMP_DUMMY()),
490 DAILINK_COMP_ARRAY(COMP_EMPTY()));
492 SND_SOC_DAILINK_DEFS(playback6,
493 DAILINK_COMP_ARRAY(COMP_CPU("DL6")),
494 DAILINK_COMP_ARRAY(COMP_DUMMY()),
495 DAILINK_COMP_ARRAY(COMP_EMPTY()));
497 SND_SOC_DAILINK_DEFS(playback7,
498 DAILINK_COMP_ARRAY(COMP_CPU("DL7")),
499 DAILINK_COMP_ARRAY(COMP_DUMMY()),
500 DAILINK_COMP_ARRAY(COMP_EMPTY()));
502 SND_SOC_DAILINK_DEFS(playback8,
503 DAILINK_COMP_ARRAY(COMP_CPU("DL8")),
504 DAILINK_COMP_ARRAY(COMP_DUMMY()),
505 DAILINK_COMP_ARRAY(COMP_EMPTY()));
507 SND_SOC_DAILINK_DEFS(playback9,
508 DAILINK_COMP_ARRAY(COMP_CPU("DL9")),
509 DAILINK_COMP_ARRAY(COMP_DUMMY()),
510 DAILINK_COMP_ARRAY(COMP_EMPTY()));
512 SND_SOC_DAILINK_DEFS(capture1,
513 DAILINK_COMP_ARRAY(COMP_CPU("UL1")),
514 DAILINK_COMP_ARRAY(COMP_DUMMY()),
515 DAILINK_COMP_ARRAY(COMP_EMPTY()));
517 SND_SOC_DAILINK_DEFS(capture2,
518 DAILINK_COMP_ARRAY(COMP_CPU("UL2")),
519 DAILINK_COMP_ARRAY(COMP_DUMMY()),
520 DAILINK_COMP_ARRAY(COMP_EMPTY()));
522 SND_SOC_DAILINK_DEFS(capture3,
523 DAILINK_COMP_ARRAY(COMP_CPU("UL3")),
524 DAILINK_COMP_ARRAY(COMP_DUMMY()),
525 DAILINK_COMP_ARRAY(COMP_EMPTY()));
527 SND_SOC_DAILINK_DEFS(capture4,
528 DAILINK_COMP_ARRAY(COMP_CPU("UL4")),
529 DAILINK_COMP_ARRAY(COMP_DUMMY()),
530 DAILINK_COMP_ARRAY(COMP_EMPTY()));
532 SND_SOC_DAILINK_DEFS(capture5,
533 DAILINK_COMP_ARRAY(COMP_CPU("UL5")),
534 DAILINK_COMP_ARRAY(COMP_DUMMY()),
535 DAILINK_COMP_ARRAY(COMP_EMPTY()));
537 SND_SOC_DAILINK_DEFS(capture6,
538 DAILINK_COMP_ARRAY(COMP_CPU("UL6")),
539 DAILINK_COMP_ARRAY(COMP_DUMMY()),
540 DAILINK_COMP_ARRAY(COMP_EMPTY()));
542 SND_SOC_DAILINK_DEFS(capture7,
543 DAILINK_COMP_ARRAY(COMP_CPU("UL7")),
544 DAILINK_COMP_ARRAY(COMP_DUMMY()),
545 DAILINK_COMP_ARRAY(COMP_EMPTY()));
547 SND_SOC_DAILINK_DEFS(capture8,
548 DAILINK_COMP_ARRAY(COMP_CPU("UL8")),
549 DAILINK_COMP_ARRAY(COMP_DUMMY()),
550 DAILINK_COMP_ARRAY(COMP_EMPTY()));
552 SND_SOC_DAILINK_DEFS(capture_mono1,
553 DAILINK_COMP_ARRAY(COMP_CPU("UL_MONO_1")),
554 DAILINK_COMP_ARRAY(COMP_DUMMY()),
555 DAILINK_COMP_ARRAY(COMP_EMPTY()));
557 SND_SOC_DAILINK_DEFS(capture_mono2,
558 DAILINK_COMP_ARRAY(COMP_CPU("UL_MONO_2")),
559 DAILINK_COMP_ARRAY(COMP_DUMMY()),
560 DAILINK_COMP_ARRAY(COMP_EMPTY()));
562 SND_SOC_DAILINK_DEFS(capture_mono3,
563 DAILINK_COMP_ARRAY(COMP_CPU("UL_MONO_3")),
564 DAILINK_COMP_ARRAY(COMP_DUMMY()),
565 DAILINK_COMP_ARRAY(COMP_EMPTY()));
567 SND_SOC_DAILINK_DEFS(playback_hdmi,
568 DAILINK_COMP_ARRAY(COMP_CPU("HDMI")),
569 DAILINK_COMP_ARRAY(COMP_DUMMY()),
570 DAILINK_COMP_ARRAY(COMP_EMPTY()));
573 SND_SOC_DAILINK_DEFS(primary_codec,
574 DAILINK_COMP_ARRAY(COMP_CPU("ADDA")),
575 DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
576 "mt6359-snd-codec-aif1"),
577 COMP_CODEC("dmic-codec",
579 DAILINK_COMP_ARRAY(COMP_EMPTY()));
581 SND_SOC_DAILINK_DEFS(primary_codec_ch34,
582 DAILINK_COMP_ARRAY(COMP_CPU("ADDA_CH34")),
583 DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
584 "mt6359-snd-codec-aif2")),
585 DAILINK_COMP_ARRAY(COMP_EMPTY()));
587 SND_SOC_DAILINK_DEFS(ap_dmic,
588 DAILINK_COMP_ARRAY(COMP_CPU("AP_DMIC")),
589 DAILINK_COMP_ARRAY(COMP_DUMMY()),
590 DAILINK_COMP_ARRAY(COMP_EMPTY()));
592 SND_SOC_DAILINK_DEFS(ap_dmic_ch34,
593 DAILINK_COMP_ARRAY(COMP_CPU("AP_DMIC_CH34")),
594 DAILINK_COMP_ARRAY(COMP_DUMMY()),
595 DAILINK_COMP_ARRAY(COMP_EMPTY()));
597 SND_SOC_DAILINK_DEFS(i2s0,
598 DAILINK_COMP_ARRAY(COMP_CPU("I2S0")),
599 DAILINK_COMP_ARRAY(COMP_DUMMY()),
600 DAILINK_COMP_ARRAY(COMP_EMPTY()));
602 SND_SOC_DAILINK_DEFS(i2s1,
603 DAILINK_COMP_ARRAY(COMP_CPU("I2S1")),
604 DAILINK_COMP_ARRAY(COMP_DUMMY()),
605 DAILINK_COMP_ARRAY(COMP_EMPTY()));
607 SND_SOC_DAILINK_DEFS(i2s2,
608 DAILINK_COMP_ARRAY(COMP_CPU("I2S2")),
609 DAILINK_COMP_ARRAY(COMP_DUMMY()),
610 DAILINK_COMP_ARRAY(COMP_EMPTY()));
612 SND_SOC_DAILINK_DEFS(i2s3,
613 DAILINK_COMP_ARRAY(COMP_CPU("I2S3")),
614 DAILINK_COMP_ARRAY(COMP_EMPTY()),
615 DAILINK_COMP_ARRAY(COMP_EMPTY()));
617 SND_SOC_DAILINK_DEFS(i2s5,
618 DAILINK_COMP_ARRAY(COMP_CPU("I2S5")),
619 DAILINK_COMP_ARRAY(COMP_DUMMY()),
620 DAILINK_COMP_ARRAY(COMP_EMPTY()));
622 SND_SOC_DAILINK_DEFS(i2s6,
623 DAILINK_COMP_ARRAY(COMP_CPU("I2S6")),
624 DAILINK_COMP_ARRAY(COMP_DUMMY()),
625 DAILINK_COMP_ARRAY(COMP_EMPTY()));
627 SND_SOC_DAILINK_DEFS(i2s7,
628 DAILINK_COMP_ARRAY(COMP_CPU("I2S7")),
629 DAILINK_COMP_ARRAY(COMP_DUMMY()),
630 DAILINK_COMP_ARRAY(COMP_EMPTY()));
632 SND_SOC_DAILINK_DEFS(i2s8,
633 DAILINK_COMP_ARRAY(COMP_CPU("I2S8")),
634 DAILINK_COMP_ARRAY(COMP_EMPTY()),
635 DAILINK_COMP_ARRAY(COMP_EMPTY()));
637 SND_SOC_DAILINK_DEFS(i2s9,
638 DAILINK_COMP_ARRAY(COMP_CPU("I2S9")),
639 DAILINK_COMP_ARRAY(COMP_EMPTY()),
640 DAILINK_COMP_ARRAY(COMP_EMPTY()));
642 SND_SOC_DAILINK_DEFS(connsys_i2s,
643 DAILINK_COMP_ARRAY(COMP_CPU("CONNSYS_I2S")),
644 DAILINK_COMP_ARRAY(COMP_DUMMY()),
645 DAILINK_COMP_ARRAY(COMP_EMPTY()));
647 SND_SOC_DAILINK_DEFS(pcm1,
648 DAILINK_COMP_ARRAY(COMP_CPU("PCM 1")),
649 DAILINK_COMP_ARRAY(COMP_DUMMY()),
650 DAILINK_COMP_ARRAY(COMP_EMPTY()));
652 SND_SOC_DAILINK_DEFS(pcm2,
653 DAILINK_COMP_ARRAY(COMP_CPU("PCM 2")),
654 DAILINK_COMP_ARRAY(COMP_DUMMY()),
655 DAILINK_COMP_ARRAY(COMP_EMPTY()));
657 SND_SOC_DAILINK_DEFS(tdm,
658 DAILINK_COMP_ARRAY(COMP_CPU("TDM")),
659 DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "i2s-hifi")),
660 DAILINK_COMP_ARRAY(COMP_EMPTY()));
662 static struct snd_soc_dai_link mt8192_mt6359_dai_links[] = {
663 /* Front End DAI links */
665 .name = "Playback_1",
666 .stream_name = "Playback_1",
667 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
668 SND_SOC_DPCM_TRIGGER_PRE},
671 SND_SOC_DAILINK_REG(playback1),
674 .name = "Playback_12",
675 .stream_name = "Playback_12",
676 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
677 SND_SOC_DPCM_TRIGGER_PRE},
680 SND_SOC_DAILINK_REG(playback12),
683 .name = "Playback_2",
684 .stream_name = "Playback_2",
685 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
686 SND_SOC_DPCM_TRIGGER_PRE},
689 SND_SOC_DAILINK_REG(playback2),
692 .name = "Playback_3",
693 .stream_name = "Playback_3",
694 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
695 SND_SOC_DPCM_TRIGGER_PRE},
698 .ops = &mt8192_mt6359_rt5682_ops,
699 SND_SOC_DAILINK_REG(playback3),
702 .name = "Playback_4",
703 .stream_name = "Playback_4",
704 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
705 SND_SOC_DPCM_TRIGGER_PRE},
708 SND_SOC_DAILINK_REG(playback4),
711 .name = "Playback_5",
712 .stream_name = "Playback_5",
713 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
714 SND_SOC_DPCM_TRIGGER_PRE},
717 SND_SOC_DAILINK_REG(playback5),
720 .name = "Playback_6",
721 .stream_name = "Playback_6",
722 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
723 SND_SOC_DPCM_TRIGGER_PRE},
726 SND_SOC_DAILINK_REG(playback6),
729 .name = "Playback_7",
730 .stream_name = "Playback_7",
731 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
732 SND_SOC_DPCM_TRIGGER_PRE},
735 SND_SOC_DAILINK_REG(playback7),
738 .name = "Playback_8",
739 .stream_name = "Playback_8",
740 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
741 SND_SOC_DPCM_TRIGGER_PRE},
744 SND_SOC_DAILINK_REG(playback8),
747 .name = "Playback_9",
748 .stream_name = "Playback_9",
749 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
750 SND_SOC_DPCM_TRIGGER_PRE},
753 SND_SOC_DAILINK_REG(playback9),
757 .stream_name = "Capture_1",
758 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
759 SND_SOC_DPCM_TRIGGER_PRE},
762 .ops = &mt8192_mt6359_capture1_ops,
763 SND_SOC_DAILINK_REG(capture1),
767 .stream_name = "Capture_2",
768 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
769 SND_SOC_DPCM_TRIGGER_PRE},
772 .ops = &mt8192_mt6359_rt5682_ops,
773 SND_SOC_DAILINK_REG(capture2),
777 .stream_name = "Capture_3",
778 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
779 SND_SOC_DPCM_TRIGGER_PRE},
782 SND_SOC_DAILINK_REG(capture3),
786 .stream_name = "Capture_4",
787 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
788 SND_SOC_DPCM_TRIGGER_PRE},
791 SND_SOC_DAILINK_REG(capture4),
795 .stream_name = "Capture_5",
796 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
797 SND_SOC_DPCM_TRIGGER_PRE},
800 SND_SOC_DAILINK_REG(capture5),
804 .stream_name = "Capture_6",
805 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
806 SND_SOC_DPCM_TRIGGER_PRE},
809 SND_SOC_DAILINK_REG(capture6),
813 .stream_name = "Capture_7",
814 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
815 SND_SOC_DPCM_TRIGGER_PRE},
818 SND_SOC_DAILINK_REG(capture7),
822 .stream_name = "Capture_8",
823 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
824 SND_SOC_DPCM_TRIGGER_PRE},
827 SND_SOC_DAILINK_REG(capture8),
830 .name = "Capture_Mono_1",
831 .stream_name = "Capture_Mono_1",
832 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
833 SND_SOC_DPCM_TRIGGER_PRE},
836 SND_SOC_DAILINK_REG(capture_mono1),
839 .name = "Capture_Mono_2",
840 .stream_name = "Capture_Mono_2",
841 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
842 SND_SOC_DPCM_TRIGGER_PRE},
845 SND_SOC_DAILINK_REG(capture_mono2),
848 .name = "Capture_Mono_3",
849 .stream_name = "Capture_Mono_3",
850 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
851 SND_SOC_DPCM_TRIGGER_PRE},
854 SND_SOC_DAILINK_REG(capture_mono3),
857 .name = "playback_hdmi",
858 .stream_name = "Playback_HDMI",
859 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
860 SND_SOC_DPCM_TRIGGER_PRE},
863 SND_SOC_DAILINK_REG(playback_hdmi),
865 /* Back End DAI links */
867 .name = "Primary Codec",
872 .init = mt8192_mt6359_init,
873 SND_SOC_DAILINK_REG(primary_codec),
876 .name = "Primary Codec CH34",
881 SND_SOC_DAILINK_REG(primary_codec_ch34),
888 SND_SOC_DAILINK_REG(ap_dmic),
891 .name = "AP_DMIC_CH34",
895 SND_SOC_DAILINK_REG(ap_dmic_ch34),
902 .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
903 SND_SOC_DAILINK_REG(i2s0),
910 .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
911 SND_SOC_DAILINK_REG(i2s1),
918 .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
919 SND_SOC_DAILINK_REG(i2s2),
926 .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
927 SND_SOC_DAILINK_REG(i2s3),
934 .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
935 SND_SOC_DAILINK_REG(i2s5),
942 .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
943 SND_SOC_DAILINK_REG(i2s6),
950 .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
951 SND_SOC_DAILINK_REG(i2s7),
958 .init = mt8192_rt5682_init,
959 .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
960 SND_SOC_DAILINK_REG(i2s8),
961 .ops = &mt8192_rt5682x_i2s_ops,
968 .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
969 SND_SOC_DAILINK_REG(i2s9),
970 .ops = &mt8192_rt5682x_i2s_ops,
973 .name = "CONNSYS_I2S",
977 SND_SOC_DAILINK_REG(connsys_i2s),
985 SND_SOC_DAILINK_REG(pcm1),
993 SND_SOC_DAILINK_REG(pcm2),
998 .dai_fmt = SND_SOC_DAIFMT_DSP_A |
999 SND_SOC_DAIFMT_IB_NF |
1000 SND_SOC_DAIFMT_CBM_CFM,
1002 .ignore_suspend = 1,
1003 .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
1005 .init = mt8192_mt6359_hdmi_init,
1006 SND_SOC_DAILINK_REG(tdm),
1010 static const struct snd_soc_dapm_widget
1011 mt8192_mt6359_rt1015_rt5682_widgets[] = {
1012 SND_SOC_DAPM_SPK("Left Spk", NULL),
1013 SND_SOC_DAPM_SPK("Right Spk", NULL),
1014 SND_SOC_DAPM_HP("Headphone Jack", NULL),
1015 SND_SOC_DAPM_MIC("Headset Mic", NULL),
1016 SND_SOC_DAPM_OUTPUT("TDM Out"),
1019 static const struct snd_soc_dapm_route mt8192_mt6359_rt1015_rt5682_routes[] = {
1021 { "Left Spk", NULL, "Left SPO" },
1022 { "Right Spk", NULL, "Right SPO" },
1024 { "Headphone Jack", NULL, "HPOL" },
1025 { "Headphone Jack", NULL, "HPOR" },
1026 { "IN1P", NULL, "Headset Mic" },
1028 { "TDM Out", NULL, "TDM" },
1031 static const struct snd_kcontrol_new mt8192_mt6359_rt1015_rt5682_controls[] = {
1032 SOC_DAPM_PIN_SWITCH("Left Spk"),
1033 SOC_DAPM_PIN_SWITCH("Right Spk"),
1034 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
1035 SOC_DAPM_PIN_SWITCH("Headset Mic"),
1038 static struct snd_soc_codec_conf rt1015_amp_conf[] = {
1040 .dlc = COMP_CODEC_CONF(RT1015_DEV0_NAME),
1041 .name_prefix = "Left",
1044 .dlc = COMP_CODEC_CONF(RT1015_DEV1_NAME),
1045 .name_prefix = "Right",
1049 static struct snd_soc_card mt8192_mt6359_rt1015_rt5682_card = {
1050 .name = RT1015_RT5682_CARD_NAME,
1051 .owner = THIS_MODULE,
1052 .dai_link = mt8192_mt6359_dai_links,
1053 .num_links = ARRAY_SIZE(mt8192_mt6359_dai_links),
1054 .controls = mt8192_mt6359_rt1015_rt5682_controls,
1055 .num_controls = ARRAY_SIZE(mt8192_mt6359_rt1015_rt5682_controls),
1056 .dapm_widgets = mt8192_mt6359_rt1015_rt5682_widgets,
1057 .num_dapm_widgets = ARRAY_SIZE(mt8192_mt6359_rt1015_rt5682_widgets),
1058 .dapm_routes = mt8192_mt6359_rt1015_rt5682_routes,
1059 .num_dapm_routes = ARRAY_SIZE(mt8192_mt6359_rt1015_rt5682_routes),
1060 .codec_conf = rt1015_amp_conf,
1061 .num_configs = ARRAY_SIZE(rt1015_amp_conf),
1064 static const struct snd_soc_dapm_widget mt8192_mt6359_rt1015p_rt5682x_widgets[] = {
1065 SND_SOC_DAPM_SPK("Speakers", NULL),
1066 SND_SOC_DAPM_HP("Headphone Jack", NULL),
1067 SND_SOC_DAPM_MIC("Headset Mic", NULL),
1070 static const struct snd_soc_dapm_route mt8192_mt6359_rt1015p_rt5682x_routes[] = {
1072 { "Speakers", NULL, "Speaker" },
1074 { "Headphone Jack", NULL, "HPOL" },
1075 { "Headphone Jack", NULL, "HPOR" },
1076 { "IN1P", NULL, "Headset Mic" },
1079 static const struct snd_kcontrol_new mt8192_mt6359_rt1015p_rt5682x_controls[] = {
1080 SOC_DAPM_PIN_SWITCH("Speakers"),
1081 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
1082 SOC_DAPM_PIN_SWITCH("Headset Mic"),
1085 static struct snd_soc_card mt8192_mt6359_rt1015p_rt5682x_card = {
1086 .owner = THIS_MODULE,
1087 .dai_link = mt8192_mt6359_dai_links,
1088 .num_links = ARRAY_SIZE(mt8192_mt6359_dai_links),
1089 .controls = mt8192_mt6359_rt1015p_rt5682x_controls,
1090 .num_controls = ARRAY_SIZE(mt8192_mt6359_rt1015p_rt5682x_controls),
1091 .dapm_widgets = mt8192_mt6359_rt1015p_rt5682x_widgets,
1092 .num_dapm_widgets = ARRAY_SIZE(mt8192_mt6359_rt1015p_rt5682x_widgets),
1093 .dapm_routes = mt8192_mt6359_rt1015p_rt5682x_routes,
1094 .num_dapm_routes = ARRAY_SIZE(mt8192_mt6359_rt1015p_rt5682x_routes),
1097 static int mt8192_mt6359_card_set_be_link(struct snd_soc_card *card,
1098 struct snd_soc_dai_link *link,
1099 struct device_node *node,
1104 if (node && strcmp(link->name, link_name) == 0) {
1105 ret = snd_soc_of_get_dai_link_codecs(card->dev, node, link);
1107 dev_err_probe(card->dev, ret, "get dai link codecs fail\n");
1115 static int mt8192_mt6359_dev_probe(struct platform_device *pdev)
1117 struct snd_soc_card *card;
1118 struct device_node *platform_node, *hdmi_codec, *headset_codec, *speaker_codec;
1120 struct snd_soc_dai_link *dai_link;
1121 struct mt8192_mt6359_priv *priv;
1123 card = (struct snd_soc_card *)of_device_get_match_data(&pdev->dev);
1126 card->dev = &pdev->dev;
1128 if (of_device_is_compatible(pdev->dev.of_node, RT1015P_RT5682_OF_NAME))
1129 card->name = RT1015P_RT5682_CARD_NAME;
1130 else if (of_device_is_compatible(pdev->dev.of_node, RT1015P_RT5682S_OF_NAME))
1131 card->name = RT1015P_RT5682S_CARD_NAME;
1133 dev_dbg(&pdev->dev, "No need to set card name\n");
1135 hdmi_codec = of_parse_phandle(pdev->dev.of_node, "mediatek,hdmi-codec", 0);
1137 dev_dbg(&pdev->dev, "The machine has no hdmi-codec\n");
1139 platform_node = of_parse_phandle(pdev->dev.of_node, "mediatek,platform", 0);
1140 if (!platform_node) {
1142 dev_err_probe(&pdev->dev, ret, "Property 'platform' missing or invalid\n");
1143 goto err_platform_node;
1146 speaker_codec = of_get_child_by_name(pdev->dev.of_node, "speaker-codecs");
1147 if (!speaker_codec) {
1149 dev_err_probe(&pdev->dev, ret, "Property 'speaker-codecs' missing or invalid\n");
1150 goto err_speaker_codec;
1153 headset_codec = of_get_child_by_name(pdev->dev.of_node, "headset-codec");
1154 if (!headset_codec) {
1156 dev_err_probe(&pdev->dev, ret, "Property 'headset-codec' missing or invalid\n");
1157 goto err_headset_codec;
1160 for_each_card_prelinks(card, i, dai_link) {
1161 ret = mt8192_mt6359_card_set_be_link(card, dai_link, speaker_codec, "I2S3");
1163 dev_err_probe(&pdev->dev, ret, "%s set speaker_codec fail\n",
1168 ret = mt8192_mt6359_card_set_be_link(card, dai_link, headset_codec, "I2S8");
1170 dev_err_probe(&pdev->dev, ret, "%s set headset_codec fail\n",
1175 ret = mt8192_mt6359_card_set_be_link(card, dai_link, headset_codec, "I2S9");
1177 dev_err_probe(&pdev->dev, ret, "%s set headset_codec fail\n",
1182 if (hdmi_codec && strcmp(dai_link->name, "TDM") == 0) {
1183 dai_link->codecs->of_node = hdmi_codec;
1184 dai_link->ignore = 0;
1187 if (strcmp(dai_link->codecs[0].dai_name, RT1015_CODEC_DAI) == 0)
1188 dai_link->ops = &mt8192_rt1015_i2s_ops;
1190 if (!dai_link->platforms->name)
1191 dai_link->platforms->of_node = platform_node;
1194 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
1199 snd_soc_card_set_drvdata(card, priv);
1201 ret = mt8192_afe_gpio_init(&pdev->dev);
1203 dev_err_probe(&pdev->dev, ret, "%s init gpio error\n", __func__);
1207 ret = devm_snd_soc_register_card(&pdev->dev, card);
1209 dev_err_probe(&pdev->dev, ret, "%s snd_soc_register_card fail\n", __func__);
1212 of_node_put(headset_codec);
1214 of_node_put(speaker_codec);
1216 of_node_put(platform_node);
1218 of_node_put(hdmi_codec);
1223 static const struct of_device_id mt8192_mt6359_dt_match[] = {
1225 .compatible = RT1015_RT5682_OF_NAME,
1226 .data = &mt8192_mt6359_rt1015_rt5682_card,
1229 .compatible = RT1015P_RT5682_OF_NAME,
1230 .data = &mt8192_mt6359_rt1015p_rt5682x_card,
1233 .compatible = RT1015P_RT5682S_OF_NAME,
1234 .data = &mt8192_mt6359_rt1015p_rt5682x_card,
1240 static const struct dev_pm_ops mt8192_mt6359_pm_ops = {
1241 .poweroff = snd_soc_poweroff,
1242 .restore = snd_soc_resume,
1245 static struct platform_driver mt8192_mt6359_driver = {
1247 .name = "mt8192_mt6359",
1249 .of_match_table = mt8192_mt6359_dt_match,
1251 .pm = &mt8192_mt6359_pm_ops,
1253 .probe = mt8192_mt6359_dev_probe,
1256 module_platform_driver(mt8192_mt6359_driver);
1258 /* Module information */
1259 MODULE_DESCRIPTION("MT8192-MT6359 ALSA SoC machine driver");
1260 MODULE_AUTHOR("Jiaxin Yu <jiaxin.yu@mediatek.com>");
1261 MODULE_LICENSE("GPL v2");
1262 MODULE_ALIAS("mt8192_mt6359 soc card");