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>
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 DRIVER_NAME "mt8192_mt6359"
29 #define RT1015_CODEC_DAI "rt1015-aif"
30 #define RT1015_DEV0_NAME "rt1015.1-0028"
31 #define RT1015_DEV1_NAME "rt1015.1-0029"
33 #define RT1015_RT5682_CARD_NAME "mt8192_mt6359_rt1015_rt5682"
34 #define RT1015P_RT5682_CARD_NAME "mt8192_mt6359_rt1015p_rt5682"
35 #define RT1015P_RT5682S_CARD_NAME "mt8192_mt6359_rt1015p_rt5682s"
37 #define RT1015_RT5682_OF_NAME "mediatek,mt8192_mt6359_rt1015_rt5682"
38 #define RT1015P_RT5682_OF_NAME "mediatek,mt8192_mt6359_rt1015p_rt5682"
39 #define RT1015P_RT5682S_OF_NAME "mediatek,mt8192_mt6359_rt1015p_rt5682s"
41 struct mt8192_mt6359_priv {
42 struct snd_soc_jack headset_jack;
43 struct snd_soc_jack hdmi_jack;
46 /* Headset jack detection DAPM pins */
47 static struct snd_soc_jack_pin mt8192_jack_pins[] = {
49 .pin = "Headphone Jack",
50 .mask = SND_JACK_HEADPHONE,
54 .mask = SND_JACK_MICROPHONE,
58 static int mt8192_rt1015_i2s_hw_params(struct snd_pcm_substream *substream,
59 struct snd_pcm_hw_params *params)
61 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
62 struct snd_soc_card *card = rtd->card;
63 struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
64 struct snd_soc_dai *codec_dai;
65 unsigned int rate = params_rate(params);
66 unsigned int mclk_fs_ratio = 128;
67 unsigned int mclk_fs = rate * mclk_fs_ratio;
70 for_each_rtd_codec_dais(rtd, i, codec_dai) {
71 ret = snd_soc_dai_set_pll(codec_dai, 0,
73 params_rate(params) * 64,
74 params_rate(params) * 256);
76 dev_err(card->dev, "failed to set pll\n");
80 ret = snd_soc_dai_set_sysclk(codec_dai,
82 params_rate(params) * 256,
85 dev_err(card->dev, "failed to set sysclk\n");
90 return snd_soc_dai_set_sysclk(cpu_dai, 0, mclk_fs, SND_SOC_CLOCK_OUT);
93 static int mt8192_rt5682x_i2s_hw_params(struct snd_pcm_substream *substream,
94 struct snd_pcm_hw_params *params)
96 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
97 struct snd_soc_card *card = rtd->card;
98 struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
99 struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
100 unsigned int rate = params_rate(params);
101 unsigned int mclk_fs_ratio = 128;
102 unsigned int mclk_fs = rate * mclk_fs_ratio;
106 bitwidth = snd_pcm_format_width(params_format(params));
108 dev_err(card->dev, "invalid bit width: %d\n", bitwidth);
112 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x00, 0x0, 0x2, bitwidth);
114 dev_err(card->dev, "failed to set tdm slot\n");
118 ret = snd_soc_dai_set_pll(codec_dai, RT5682_PLL1,
120 params_rate(params) * 64,
121 params_rate(params) * 512);
123 dev_err(card->dev, "failed to set pll\n");
127 ret = snd_soc_dai_set_sysclk(codec_dai,
129 params_rate(params) * 512,
132 dev_err(card->dev, "failed to set sysclk\n");
136 return snd_soc_dai_set_sysclk(cpu_dai, 0, mclk_fs, SND_SOC_CLOCK_OUT);
139 static const struct snd_soc_ops mt8192_rt1015_i2s_ops = {
140 .hw_params = mt8192_rt1015_i2s_hw_params,
143 static const struct snd_soc_ops mt8192_rt5682x_i2s_ops = {
144 .hw_params = mt8192_rt5682x_i2s_hw_params,
147 static int mt8192_mt6359_mtkaif_calibration(struct snd_soc_pcm_runtime *rtd)
149 struct snd_soc_component *cmpnt_afe =
150 snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
151 struct snd_soc_component *cmpnt_codec =
152 snd_soc_rtd_to_codec(rtd, 0)->component;
153 struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe);
154 struct mt8192_afe_private *afe_priv = afe->platform_priv;
156 unsigned int monitor;
157 int test_done_1, test_done_2, test_done_3;
158 int cycle_1, cycle_2, cycle_3;
159 int prev_cycle_1, prev_cycle_2, prev_cycle_3;
160 int chosen_phase_1, chosen_phase_2, chosen_phase_3;
164 pm_runtime_get_sync(afe->dev);
165 mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA, 1);
166 mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA, 0);
167 mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA_CH34, 1);
168 mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA_CH34, 0);
170 mt6359_mtkaif_calibration_enable(cmpnt_codec);
172 /* set clock protocol 2 */
173 regmap_update_bits(afe->regmap, AFE_AUD_PAD_TOP, 0xff, 0x38);
174 regmap_update_bits(afe->regmap, AFE_AUD_PAD_TOP, 0xff, 0x39);
176 /* set test type to synchronizer pulse */
177 regmap_update_bits(afe_priv->topckgen,
178 CKSYS_AUD_TOP_CFG, 0xffff, 0x4);
180 mtkaif_calib_ok = true;
181 afe_priv->mtkaif_calibration_num_phase = 42; /* mt6359: 0 ~ 42 */
182 afe_priv->mtkaif_chosen_phase[0] = -1;
183 afe_priv->mtkaif_chosen_phase[1] = -1;
184 afe_priv->mtkaif_chosen_phase[2] = -1;
187 phase <= afe_priv->mtkaif_calibration_num_phase &&
190 mt6359_set_mtkaif_calibration_phase(cmpnt_codec,
191 phase, phase, phase);
193 regmap_update_bits(afe_priv->topckgen,
194 CKSYS_AUD_TOP_CFG, 0x1, 0x1);
203 while (test_done_1 == 0 ||
206 regmap_read(afe_priv->topckgen,
207 CKSYS_AUD_TOP_MON, &monitor);
209 test_done_1 = (monitor >> 28) & 0x1;
210 test_done_2 = (monitor >> 29) & 0x1;
211 test_done_3 = (monitor >> 30) & 0x1;
212 if (test_done_1 == 1)
213 cycle_1 = monitor & 0xf;
215 if (test_done_2 == 1)
216 cycle_2 = (monitor >> 4) & 0xf;
218 if (test_done_3 == 1)
219 cycle_3 = (monitor >> 8) & 0xf;
221 /* handle if never test done */
222 if (++counter > 10000) {
223 dev_err(afe->dev, "%s(), test fail, cycle_1 %d, cycle_2 %d, cycle_3 %d, monitor 0x%x\n",
225 cycle_1, cycle_2, cycle_3, monitor);
226 mtkaif_calib_ok = false;
232 prev_cycle_1 = cycle_1;
233 prev_cycle_2 = cycle_2;
234 prev_cycle_3 = cycle_3;
237 if (cycle_1 != prev_cycle_1 &&
238 afe_priv->mtkaif_chosen_phase[0] < 0) {
239 afe_priv->mtkaif_chosen_phase[0] = phase - 1;
240 afe_priv->mtkaif_phase_cycle[0] = prev_cycle_1;
243 if (cycle_2 != prev_cycle_2 &&
244 afe_priv->mtkaif_chosen_phase[1] < 0) {
245 afe_priv->mtkaif_chosen_phase[1] = phase - 1;
246 afe_priv->mtkaif_phase_cycle[1] = prev_cycle_2;
249 if (cycle_3 != prev_cycle_3 &&
250 afe_priv->mtkaif_chosen_phase[2] < 0) {
251 afe_priv->mtkaif_chosen_phase[2] = phase - 1;
252 afe_priv->mtkaif_phase_cycle[2] = prev_cycle_3;
255 regmap_update_bits(afe_priv->topckgen,
256 CKSYS_AUD_TOP_CFG, 0x1, 0x0);
258 if (afe_priv->mtkaif_chosen_phase[0] >= 0 &&
259 afe_priv->mtkaif_chosen_phase[1] >= 0 &&
260 afe_priv->mtkaif_chosen_phase[2] >= 0)
264 if (afe_priv->mtkaif_chosen_phase[0] < 0)
267 chosen_phase_1 = afe_priv->mtkaif_chosen_phase[0];
269 if (afe_priv->mtkaif_chosen_phase[1] < 0)
272 chosen_phase_2 = afe_priv->mtkaif_chosen_phase[1];
274 if (afe_priv->mtkaif_chosen_phase[2] < 0)
277 chosen_phase_3 = afe_priv->mtkaif_chosen_phase[2];
279 mt6359_set_mtkaif_calibration_phase(cmpnt_codec,
284 /* disable rx fifo */
285 regmap_update_bits(afe->regmap, AFE_AUD_PAD_TOP, 0xff, 0x38);
287 mt6359_mtkaif_calibration_disable(cmpnt_codec);
289 mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA, 1);
290 mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA, 0);
291 mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA_CH34, 1);
292 mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA_CH34, 0);
293 pm_runtime_put(afe->dev);
295 dev_dbg(afe->dev, "%s(), mtkaif_chosen_phase[0/1/2]:%d/%d/%d\n",
297 afe_priv->mtkaif_chosen_phase[0],
298 afe_priv->mtkaif_chosen_phase[1],
299 afe_priv->mtkaif_chosen_phase[2]);
304 static int mt8192_mt6359_init(struct snd_soc_pcm_runtime *rtd)
306 struct snd_soc_component *cmpnt_afe =
307 snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
308 struct snd_soc_component *cmpnt_codec =
309 snd_soc_rtd_to_codec(rtd, 0)->component;
310 struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe);
311 struct mt8192_afe_private *afe_priv = afe->platform_priv;
313 /* set mtkaif protocol */
314 mt6359_set_mtkaif_protocol(cmpnt_codec,
315 MT6359_MTKAIF_PROTOCOL_2_CLK_P2);
316 afe_priv->mtkaif_protocol = MTKAIF_PROTOCOL_2_CLK_P2;
318 /* mtkaif calibration */
319 mt8192_mt6359_mtkaif_calibration(rtd);
324 static int mt8192_rt5682_init(struct snd_soc_pcm_runtime *rtd)
326 struct snd_soc_component *cmpnt_afe =
327 snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
328 struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe);
329 struct snd_soc_component *cmpnt_codec =
330 snd_soc_rtd_to_codec(rtd, 0)->component;
331 struct mt8192_mt6359_priv *priv = snd_soc_card_get_drvdata(rtd->card);
332 struct snd_soc_jack *jack = &priv->headset_jack;
335 ret = mt8192_dai_i2s_set_share(afe, "I2S8", "I2S9");
337 dev_err(rtd->dev, "Failed to set up shared clocks\n");
341 ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack",
342 SND_JACK_HEADSET | SND_JACK_BTN_0 |
343 SND_JACK_BTN_1 | SND_JACK_BTN_2 |
345 jack, mt8192_jack_pins,
346 ARRAY_SIZE(mt8192_jack_pins));
348 dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
352 snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
353 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
354 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
355 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
357 return snd_soc_component_set_jack(cmpnt_codec, jack, NULL);
360 static int mt8192_mt6359_hdmi_init(struct snd_soc_pcm_runtime *rtd)
362 struct snd_soc_component *cmpnt_codec =
363 snd_soc_rtd_to_codec(rtd, 0)->component;
364 struct mt8192_mt6359_priv *priv = snd_soc_card_get_drvdata(rtd->card);
367 ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT,
370 dev_err(rtd->dev, "HDMI Jack creation failed: %d\n", ret);
374 return snd_soc_component_set_jack(cmpnt_codec, &priv->hdmi_jack, NULL);
377 static int mt8192_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
378 struct snd_pcm_hw_params *params)
380 /* fix BE i2s format to S24_LE, clean param mask first */
381 snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT),
382 0, (__force unsigned int)SNDRV_PCM_FORMAT_LAST);
384 params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
390 mt8192_mt6359_cap1_startup(struct snd_pcm_substream *substream)
392 static const unsigned int channels[] = {
395 static const struct snd_pcm_hw_constraint_list constraints_channels = {
396 .count = ARRAY_SIZE(channels),
400 static const unsigned int rates[] = {
401 8000, 16000, 32000, 48000, 96000, 192000
403 static const struct snd_pcm_hw_constraint_list constraints_rates = {
404 .count = ARRAY_SIZE(rates),
409 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
410 struct snd_pcm_runtime *runtime = substream->runtime;
413 ret = snd_pcm_hw_constraint_list(runtime, 0,
414 SNDRV_PCM_HW_PARAM_CHANNELS,
415 &constraints_channels);
417 dev_err(rtd->dev, "hw_constraint_list channels failed\n");
421 ret = snd_pcm_hw_constraint_list(runtime, 0,
422 SNDRV_PCM_HW_PARAM_RATE,
425 dev_err(rtd->dev, "hw_constraint_list rate failed\n");
432 static const struct snd_soc_ops mt8192_mt6359_capture1_ops = {
433 .startup = mt8192_mt6359_cap1_startup,
437 mt8192_mt6359_rt5682_startup(struct snd_pcm_substream *substream)
439 static const unsigned int channels[] = {
442 static const struct snd_pcm_hw_constraint_list constraints_channels = {
443 .count = ARRAY_SIZE(channels),
447 static const unsigned int rates[] = {
450 static const struct snd_pcm_hw_constraint_list constraints_rates = {
451 .count = ARRAY_SIZE(rates),
456 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
457 struct snd_pcm_runtime *runtime = substream->runtime;
460 ret = snd_pcm_hw_constraint_list(runtime, 0,
461 SNDRV_PCM_HW_PARAM_CHANNELS,
462 &constraints_channels);
464 dev_err(rtd->dev, "hw_constraint_list channels failed\n");
468 ret = snd_pcm_hw_constraint_list(runtime, 0,
469 SNDRV_PCM_HW_PARAM_RATE,
472 dev_err(rtd->dev, "hw_constraint_list rate failed\n");
479 static const struct snd_soc_ops mt8192_mt6359_rt5682_ops = {
480 .startup = mt8192_mt6359_rt5682_startup,
484 SND_SOC_DAILINK_DEFS(playback1,
485 DAILINK_COMP_ARRAY(COMP_CPU("DL1")),
486 DAILINK_COMP_ARRAY(COMP_DUMMY()),
487 DAILINK_COMP_ARRAY(COMP_EMPTY()));
489 SND_SOC_DAILINK_DEFS(playback12,
490 DAILINK_COMP_ARRAY(COMP_CPU("DL12")),
491 DAILINK_COMP_ARRAY(COMP_DUMMY()),
492 DAILINK_COMP_ARRAY(COMP_EMPTY()));
494 SND_SOC_DAILINK_DEFS(playback2,
495 DAILINK_COMP_ARRAY(COMP_CPU("DL2")),
496 DAILINK_COMP_ARRAY(COMP_DUMMY()),
497 DAILINK_COMP_ARRAY(COMP_EMPTY()));
499 SND_SOC_DAILINK_DEFS(playback3,
500 DAILINK_COMP_ARRAY(COMP_CPU("DL3")),
501 DAILINK_COMP_ARRAY(COMP_DUMMY()),
502 DAILINK_COMP_ARRAY(COMP_EMPTY()));
504 SND_SOC_DAILINK_DEFS(playback4,
505 DAILINK_COMP_ARRAY(COMP_CPU("DL4")),
506 DAILINK_COMP_ARRAY(COMP_DUMMY()),
507 DAILINK_COMP_ARRAY(COMP_EMPTY()));
509 SND_SOC_DAILINK_DEFS(playback5,
510 DAILINK_COMP_ARRAY(COMP_CPU("DL5")),
511 DAILINK_COMP_ARRAY(COMP_DUMMY()),
512 DAILINK_COMP_ARRAY(COMP_EMPTY()));
514 SND_SOC_DAILINK_DEFS(playback6,
515 DAILINK_COMP_ARRAY(COMP_CPU("DL6")),
516 DAILINK_COMP_ARRAY(COMP_DUMMY()),
517 DAILINK_COMP_ARRAY(COMP_EMPTY()));
519 SND_SOC_DAILINK_DEFS(playback7,
520 DAILINK_COMP_ARRAY(COMP_CPU("DL7")),
521 DAILINK_COMP_ARRAY(COMP_DUMMY()),
522 DAILINK_COMP_ARRAY(COMP_EMPTY()));
524 SND_SOC_DAILINK_DEFS(playback8,
525 DAILINK_COMP_ARRAY(COMP_CPU("DL8")),
526 DAILINK_COMP_ARRAY(COMP_DUMMY()),
527 DAILINK_COMP_ARRAY(COMP_EMPTY()));
529 SND_SOC_DAILINK_DEFS(playback9,
530 DAILINK_COMP_ARRAY(COMP_CPU("DL9")),
531 DAILINK_COMP_ARRAY(COMP_DUMMY()),
532 DAILINK_COMP_ARRAY(COMP_EMPTY()));
534 SND_SOC_DAILINK_DEFS(capture1,
535 DAILINK_COMP_ARRAY(COMP_CPU("UL1")),
536 DAILINK_COMP_ARRAY(COMP_DUMMY()),
537 DAILINK_COMP_ARRAY(COMP_EMPTY()));
539 SND_SOC_DAILINK_DEFS(capture2,
540 DAILINK_COMP_ARRAY(COMP_CPU("UL2")),
541 DAILINK_COMP_ARRAY(COMP_DUMMY()),
542 DAILINK_COMP_ARRAY(COMP_EMPTY()));
544 SND_SOC_DAILINK_DEFS(capture3,
545 DAILINK_COMP_ARRAY(COMP_CPU("UL3")),
546 DAILINK_COMP_ARRAY(COMP_DUMMY()),
547 DAILINK_COMP_ARRAY(COMP_EMPTY()));
549 SND_SOC_DAILINK_DEFS(capture4,
550 DAILINK_COMP_ARRAY(COMP_CPU("UL4")),
551 DAILINK_COMP_ARRAY(COMP_DUMMY()),
552 DAILINK_COMP_ARRAY(COMP_EMPTY()));
554 SND_SOC_DAILINK_DEFS(capture5,
555 DAILINK_COMP_ARRAY(COMP_CPU("UL5")),
556 DAILINK_COMP_ARRAY(COMP_DUMMY()),
557 DAILINK_COMP_ARRAY(COMP_EMPTY()));
559 SND_SOC_DAILINK_DEFS(capture6,
560 DAILINK_COMP_ARRAY(COMP_CPU("UL6")),
561 DAILINK_COMP_ARRAY(COMP_DUMMY()),
562 DAILINK_COMP_ARRAY(COMP_EMPTY()));
564 SND_SOC_DAILINK_DEFS(capture7,
565 DAILINK_COMP_ARRAY(COMP_CPU("UL7")),
566 DAILINK_COMP_ARRAY(COMP_DUMMY()),
567 DAILINK_COMP_ARRAY(COMP_EMPTY()));
569 SND_SOC_DAILINK_DEFS(capture8,
570 DAILINK_COMP_ARRAY(COMP_CPU("UL8")),
571 DAILINK_COMP_ARRAY(COMP_DUMMY()),
572 DAILINK_COMP_ARRAY(COMP_EMPTY()));
574 SND_SOC_DAILINK_DEFS(capture_mono1,
575 DAILINK_COMP_ARRAY(COMP_CPU("UL_MONO_1")),
576 DAILINK_COMP_ARRAY(COMP_DUMMY()),
577 DAILINK_COMP_ARRAY(COMP_EMPTY()));
579 SND_SOC_DAILINK_DEFS(capture_mono2,
580 DAILINK_COMP_ARRAY(COMP_CPU("UL_MONO_2")),
581 DAILINK_COMP_ARRAY(COMP_DUMMY()),
582 DAILINK_COMP_ARRAY(COMP_EMPTY()));
584 SND_SOC_DAILINK_DEFS(capture_mono3,
585 DAILINK_COMP_ARRAY(COMP_CPU("UL_MONO_3")),
586 DAILINK_COMP_ARRAY(COMP_DUMMY()),
587 DAILINK_COMP_ARRAY(COMP_EMPTY()));
589 SND_SOC_DAILINK_DEFS(playback_hdmi,
590 DAILINK_COMP_ARRAY(COMP_CPU("HDMI")),
591 DAILINK_COMP_ARRAY(COMP_DUMMY()),
592 DAILINK_COMP_ARRAY(COMP_EMPTY()));
595 SND_SOC_DAILINK_DEFS(primary_codec,
596 DAILINK_COMP_ARRAY(COMP_CPU("ADDA")),
597 DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
598 "mt6359-snd-codec-aif1"),
599 COMP_CODEC("dmic-codec",
601 DAILINK_COMP_ARRAY(COMP_EMPTY()));
603 SND_SOC_DAILINK_DEFS(primary_codec_ch34,
604 DAILINK_COMP_ARRAY(COMP_CPU("ADDA_CH34")),
605 DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
606 "mt6359-snd-codec-aif2")),
607 DAILINK_COMP_ARRAY(COMP_EMPTY()));
609 SND_SOC_DAILINK_DEFS(ap_dmic,
610 DAILINK_COMP_ARRAY(COMP_CPU("AP_DMIC")),
611 DAILINK_COMP_ARRAY(COMP_DUMMY()),
612 DAILINK_COMP_ARRAY(COMP_EMPTY()));
614 SND_SOC_DAILINK_DEFS(ap_dmic_ch34,
615 DAILINK_COMP_ARRAY(COMP_CPU("AP_DMIC_CH34")),
616 DAILINK_COMP_ARRAY(COMP_DUMMY()),
617 DAILINK_COMP_ARRAY(COMP_EMPTY()));
619 SND_SOC_DAILINK_DEFS(i2s0,
620 DAILINK_COMP_ARRAY(COMP_CPU("I2S0")),
621 DAILINK_COMP_ARRAY(COMP_DUMMY()),
622 DAILINK_COMP_ARRAY(COMP_EMPTY()));
624 SND_SOC_DAILINK_DEFS(i2s1,
625 DAILINK_COMP_ARRAY(COMP_CPU("I2S1")),
626 DAILINK_COMP_ARRAY(COMP_DUMMY()),
627 DAILINK_COMP_ARRAY(COMP_EMPTY()));
629 SND_SOC_DAILINK_DEFS(i2s2,
630 DAILINK_COMP_ARRAY(COMP_CPU("I2S2")),
631 DAILINK_COMP_ARRAY(COMP_DUMMY()),
632 DAILINK_COMP_ARRAY(COMP_EMPTY()));
634 SND_SOC_DAILINK_DEFS(i2s3,
635 DAILINK_COMP_ARRAY(COMP_CPU("I2S3")),
636 DAILINK_COMP_ARRAY(COMP_EMPTY()),
637 DAILINK_COMP_ARRAY(COMP_EMPTY()));
639 SND_SOC_DAILINK_DEFS(i2s5,
640 DAILINK_COMP_ARRAY(COMP_CPU("I2S5")),
641 DAILINK_COMP_ARRAY(COMP_DUMMY()),
642 DAILINK_COMP_ARRAY(COMP_EMPTY()));
644 SND_SOC_DAILINK_DEFS(i2s6,
645 DAILINK_COMP_ARRAY(COMP_CPU("I2S6")),
646 DAILINK_COMP_ARRAY(COMP_DUMMY()),
647 DAILINK_COMP_ARRAY(COMP_EMPTY()));
649 SND_SOC_DAILINK_DEFS(i2s7,
650 DAILINK_COMP_ARRAY(COMP_CPU("I2S7")),
651 DAILINK_COMP_ARRAY(COMP_DUMMY()),
652 DAILINK_COMP_ARRAY(COMP_EMPTY()));
654 SND_SOC_DAILINK_DEFS(i2s8,
655 DAILINK_COMP_ARRAY(COMP_CPU("I2S8")),
656 DAILINK_COMP_ARRAY(COMP_EMPTY()),
657 DAILINK_COMP_ARRAY(COMP_EMPTY()));
659 SND_SOC_DAILINK_DEFS(i2s9,
660 DAILINK_COMP_ARRAY(COMP_CPU("I2S9")),
661 DAILINK_COMP_ARRAY(COMP_EMPTY()),
662 DAILINK_COMP_ARRAY(COMP_EMPTY()));
664 SND_SOC_DAILINK_DEFS(connsys_i2s,
665 DAILINK_COMP_ARRAY(COMP_CPU("CONNSYS_I2S")),
666 DAILINK_COMP_ARRAY(COMP_DUMMY()),
667 DAILINK_COMP_ARRAY(COMP_EMPTY()));
669 SND_SOC_DAILINK_DEFS(pcm1,
670 DAILINK_COMP_ARRAY(COMP_CPU("PCM 1")),
671 DAILINK_COMP_ARRAY(COMP_DUMMY()),
672 DAILINK_COMP_ARRAY(COMP_EMPTY()));
674 SND_SOC_DAILINK_DEFS(pcm2,
675 DAILINK_COMP_ARRAY(COMP_CPU("PCM 2")),
676 DAILINK_COMP_ARRAY(COMP_DUMMY()),
677 DAILINK_COMP_ARRAY(COMP_EMPTY()));
679 SND_SOC_DAILINK_DEFS(tdm,
680 DAILINK_COMP_ARRAY(COMP_CPU("TDM")),
681 DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "i2s-hifi")),
682 DAILINK_COMP_ARRAY(COMP_EMPTY()));
684 static struct snd_soc_dai_link mt8192_mt6359_dai_links[] = {
685 /* Front End DAI links */
687 .name = "Playback_1",
688 .stream_name = "Playback_1",
689 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
690 SND_SOC_DPCM_TRIGGER_PRE},
693 SND_SOC_DAILINK_REG(playback1),
696 .name = "Playback_12",
697 .stream_name = "Playback_12",
698 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
699 SND_SOC_DPCM_TRIGGER_PRE},
702 SND_SOC_DAILINK_REG(playback12),
705 .name = "Playback_2",
706 .stream_name = "Playback_2",
707 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
708 SND_SOC_DPCM_TRIGGER_PRE},
711 SND_SOC_DAILINK_REG(playback2),
714 .name = "Playback_3",
715 .stream_name = "Playback_3",
716 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
717 SND_SOC_DPCM_TRIGGER_PRE},
720 .ops = &mt8192_mt6359_rt5682_ops,
721 SND_SOC_DAILINK_REG(playback3),
724 .name = "Playback_4",
725 .stream_name = "Playback_4",
726 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
727 SND_SOC_DPCM_TRIGGER_PRE},
730 SND_SOC_DAILINK_REG(playback4),
733 .name = "Playback_5",
734 .stream_name = "Playback_5",
735 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
736 SND_SOC_DPCM_TRIGGER_PRE},
739 SND_SOC_DAILINK_REG(playback5),
742 .name = "Playback_6",
743 .stream_name = "Playback_6",
744 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
745 SND_SOC_DPCM_TRIGGER_PRE},
748 SND_SOC_DAILINK_REG(playback6),
751 .name = "Playback_7",
752 .stream_name = "Playback_7",
753 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
754 SND_SOC_DPCM_TRIGGER_PRE},
757 SND_SOC_DAILINK_REG(playback7),
760 .name = "Playback_8",
761 .stream_name = "Playback_8",
762 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
763 SND_SOC_DPCM_TRIGGER_PRE},
766 SND_SOC_DAILINK_REG(playback8),
769 .name = "Playback_9",
770 .stream_name = "Playback_9",
771 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
772 SND_SOC_DPCM_TRIGGER_PRE},
775 SND_SOC_DAILINK_REG(playback9),
779 .stream_name = "Capture_1",
780 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
781 SND_SOC_DPCM_TRIGGER_PRE},
784 .ops = &mt8192_mt6359_capture1_ops,
785 SND_SOC_DAILINK_REG(capture1),
789 .stream_name = "Capture_2",
790 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
791 SND_SOC_DPCM_TRIGGER_PRE},
794 .ops = &mt8192_mt6359_rt5682_ops,
795 SND_SOC_DAILINK_REG(capture2),
799 .stream_name = "Capture_3",
800 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
801 SND_SOC_DPCM_TRIGGER_PRE},
804 SND_SOC_DAILINK_REG(capture3),
808 .stream_name = "Capture_4",
809 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
810 SND_SOC_DPCM_TRIGGER_PRE},
813 SND_SOC_DAILINK_REG(capture4),
817 .stream_name = "Capture_5",
818 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
819 SND_SOC_DPCM_TRIGGER_PRE},
822 SND_SOC_DAILINK_REG(capture5),
826 .stream_name = "Capture_6",
827 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
828 SND_SOC_DPCM_TRIGGER_PRE},
831 SND_SOC_DAILINK_REG(capture6),
835 .stream_name = "Capture_7",
836 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
837 SND_SOC_DPCM_TRIGGER_PRE},
840 SND_SOC_DAILINK_REG(capture7),
844 .stream_name = "Capture_8",
845 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
846 SND_SOC_DPCM_TRIGGER_PRE},
849 SND_SOC_DAILINK_REG(capture8),
852 .name = "Capture_Mono_1",
853 .stream_name = "Capture_Mono_1",
854 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
855 SND_SOC_DPCM_TRIGGER_PRE},
858 SND_SOC_DAILINK_REG(capture_mono1),
861 .name = "Capture_Mono_2",
862 .stream_name = "Capture_Mono_2",
863 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
864 SND_SOC_DPCM_TRIGGER_PRE},
867 SND_SOC_DAILINK_REG(capture_mono2),
870 .name = "Capture_Mono_3",
871 .stream_name = "Capture_Mono_3",
872 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
873 SND_SOC_DPCM_TRIGGER_PRE},
876 SND_SOC_DAILINK_REG(capture_mono3),
879 .name = "playback_hdmi",
880 .stream_name = "Playback_HDMI",
881 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
882 SND_SOC_DPCM_TRIGGER_PRE},
885 SND_SOC_DAILINK_REG(playback_hdmi),
887 /* Back End DAI links */
889 .name = "Primary Codec",
894 .init = mt8192_mt6359_init,
895 SND_SOC_DAILINK_REG(primary_codec),
898 .name = "Primary Codec CH34",
903 SND_SOC_DAILINK_REG(primary_codec_ch34),
910 SND_SOC_DAILINK_REG(ap_dmic),
913 .name = "AP_DMIC_CH34",
917 SND_SOC_DAILINK_REG(ap_dmic_ch34),
924 .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
925 SND_SOC_DAILINK_REG(i2s0),
932 .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
933 SND_SOC_DAILINK_REG(i2s1),
940 .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
941 SND_SOC_DAILINK_REG(i2s2),
948 .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
949 SND_SOC_DAILINK_REG(i2s3),
956 .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
957 SND_SOC_DAILINK_REG(i2s5),
964 .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
965 SND_SOC_DAILINK_REG(i2s6),
972 .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
973 SND_SOC_DAILINK_REG(i2s7),
980 .init = mt8192_rt5682_init,
981 .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
982 SND_SOC_DAILINK_REG(i2s8),
983 .ops = &mt8192_rt5682x_i2s_ops,
990 .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
991 SND_SOC_DAILINK_REG(i2s9),
992 .ops = &mt8192_rt5682x_i2s_ops,
995 .name = "CONNSYS_I2S",
999 SND_SOC_DAILINK_REG(connsys_i2s),
1006 .ignore_suspend = 1,
1007 SND_SOC_DAILINK_REG(pcm1),
1014 .ignore_suspend = 1,
1015 SND_SOC_DAILINK_REG(pcm2),
1020 .dai_fmt = SND_SOC_DAIFMT_DSP_A |
1021 SND_SOC_DAIFMT_IB_NF |
1022 SND_SOC_DAIFMT_CBM_CFM,
1024 .ignore_suspend = 1,
1025 .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
1027 .init = mt8192_mt6359_hdmi_init,
1028 SND_SOC_DAILINK_REG(tdm),
1032 static const struct snd_soc_dapm_widget
1033 mt8192_mt6359_rt1015_rt5682_widgets[] = {
1034 SND_SOC_DAPM_SPK("Left Spk", NULL),
1035 SND_SOC_DAPM_SPK("Right Spk", NULL),
1036 SND_SOC_DAPM_HP("Headphone Jack", NULL),
1037 SND_SOC_DAPM_MIC("Headset Mic", NULL),
1038 SND_SOC_DAPM_OUTPUT("TDM Out"),
1041 static const struct snd_soc_dapm_route mt8192_mt6359_rt1015_rt5682_routes[] = {
1043 { "Left Spk", NULL, "Left SPO" },
1044 { "Right Spk", NULL, "Right SPO" },
1046 { "Headphone Jack", NULL, "HPOL" },
1047 { "Headphone Jack", NULL, "HPOR" },
1048 { "IN1P", NULL, "Headset Mic" },
1050 { "TDM Out", NULL, "TDM" },
1053 static const struct snd_kcontrol_new mt8192_mt6359_rt1015_rt5682_controls[] = {
1054 SOC_DAPM_PIN_SWITCH("Left Spk"),
1055 SOC_DAPM_PIN_SWITCH("Right Spk"),
1056 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
1057 SOC_DAPM_PIN_SWITCH("Headset Mic"),
1060 static struct snd_soc_codec_conf rt1015_amp_conf[] = {
1062 .dlc = COMP_CODEC_CONF(RT1015_DEV0_NAME),
1063 .name_prefix = "Left",
1066 .dlc = COMP_CODEC_CONF(RT1015_DEV1_NAME),
1067 .name_prefix = "Right",
1071 static struct snd_soc_card mt8192_mt6359_rt1015_rt5682_card = {
1072 .name = RT1015_RT5682_CARD_NAME,
1073 .driver_name = DRIVER_NAME,
1074 .owner = THIS_MODULE,
1075 .dai_link = mt8192_mt6359_dai_links,
1076 .num_links = ARRAY_SIZE(mt8192_mt6359_dai_links),
1077 .controls = mt8192_mt6359_rt1015_rt5682_controls,
1078 .num_controls = ARRAY_SIZE(mt8192_mt6359_rt1015_rt5682_controls),
1079 .dapm_widgets = mt8192_mt6359_rt1015_rt5682_widgets,
1080 .num_dapm_widgets = ARRAY_SIZE(mt8192_mt6359_rt1015_rt5682_widgets),
1081 .dapm_routes = mt8192_mt6359_rt1015_rt5682_routes,
1082 .num_dapm_routes = ARRAY_SIZE(mt8192_mt6359_rt1015_rt5682_routes),
1083 .codec_conf = rt1015_amp_conf,
1084 .num_configs = ARRAY_SIZE(rt1015_amp_conf),
1087 static const struct snd_soc_dapm_widget mt8192_mt6359_rt1015p_rt5682x_widgets[] = {
1088 SND_SOC_DAPM_SPK("Speakers", NULL),
1089 SND_SOC_DAPM_HP("Headphone Jack", NULL),
1090 SND_SOC_DAPM_MIC("Headset Mic", NULL),
1093 static const struct snd_soc_dapm_route mt8192_mt6359_rt1015p_rt5682x_routes[] = {
1095 { "Speakers", NULL, "Speaker" },
1097 { "Headphone Jack", NULL, "HPOL" },
1098 { "Headphone Jack", NULL, "HPOR" },
1099 { "IN1P", NULL, "Headset Mic" },
1102 static const struct snd_kcontrol_new mt8192_mt6359_rt1015p_rt5682x_controls[] = {
1103 SOC_DAPM_PIN_SWITCH("Speakers"),
1104 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
1105 SOC_DAPM_PIN_SWITCH("Headset Mic"),
1108 static struct snd_soc_card mt8192_mt6359_rt1015p_rt5682x_card = {
1109 .driver_name = DRIVER_NAME,
1110 .owner = THIS_MODULE,
1111 .dai_link = mt8192_mt6359_dai_links,
1112 .num_links = ARRAY_SIZE(mt8192_mt6359_dai_links),
1113 .controls = mt8192_mt6359_rt1015p_rt5682x_controls,
1114 .num_controls = ARRAY_SIZE(mt8192_mt6359_rt1015p_rt5682x_controls),
1115 .dapm_widgets = mt8192_mt6359_rt1015p_rt5682x_widgets,
1116 .num_dapm_widgets = ARRAY_SIZE(mt8192_mt6359_rt1015p_rt5682x_widgets),
1117 .dapm_routes = mt8192_mt6359_rt1015p_rt5682x_routes,
1118 .num_dapm_routes = ARRAY_SIZE(mt8192_mt6359_rt1015p_rt5682x_routes),
1121 static int mt8192_mt6359_card_set_be_link(struct snd_soc_card *card,
1122 struct snd_soc_dai_link *link,
1123 struct device_node *node,
1128 if (node && strcmp(link->name, link_name) == 0) {
1129 ret = snd_soc_of_get_dai_link_codecs(card->dev, node, link);
1131 dev_err_probe(card->dev, ret, "get dai link codecs fail\n");
1139 static int mt8192_mt6359_dev_probe(struct platform_device *pdev)
1141 struct snd_soc_card *card;
1142 struct device_node *platform_node, *hdmi_codec, *headset_codec, *speaker_codec;
1144 struct snd_soc_dai_link *dai_link;
1145 struct mt8192_mt6359_priv *priv;
1147 card = (struct snd_soc_card *)of_device_get_match_data(&pdev->dev);
1150 card->dev = &pdev->dev;
1152 if (of_device_is_compatible(pdev->dev.of_node, RT1015P_RT5682_OF_NAME))
1153 card->name = RT1015P_RT5682_CARD_NAME;
1154 else if (of_device_is_compatible(pdev->dev.of_node, RT1015P_RT5682S_OF_NAME))
1155 card->name = RT1015P_RT5682S_CARD_NAME;
1157 dev_dbg(&pdev->dev, "No need to set card name\n");
1159 hdmi_codec = of_parse_phandle(pdev->dev.of_node, "mediatek,hdmi-codec", 0);
1161 dev_dbg(&pdev->dev, "The machine has no hdmi-codec\n");
1163 platform_node = of_parse_phandle(pdev->dev.of_node, "mediatek,platform", 0);
1164 if (!platform_node) {
1166 dev_err_probe(&pdev->dev, ret, "Property 'platform' missing or invalid\n");
1167 goto err_platform_node;
1170 speaker_codec = of_get_child_by_name(pdev->dev.of_node, "speaker-codecs");
1171 if (!speaker_codec) {
1173 dev_err_probe(&pdev->dev, ret, "Property 'speaker-codecs' missing or invalid\n");
1174 goto err_speaker_codec;
1177 headset_codec = of_get_child_by_name(pdev->dev.of_node, "headset-codec");
1178 if (!headset_codec) {
1180 dev_err_probe(&pdev->dev, ret, "Property 'headset-codec' missing or invalid\n");
1181 goto err_headset_codec;
1184 for_each_card_prelinks(card, i, dai_link) {
1185 ret = mt8192_mt6359_card_set_be_link(card, dai_link, speaker_codec, "I2S3");
1187 dev_err_probe(&pdev->dev, ret, "%s set speaker_codec fail\n",
1192 ret = mt8192_mt6359_card_set_be_link(card, dai_link, headset_codec, "I2S8");
1194 dev_err_probe(&pdev->dev, ret, "%s set headset_codec fail\n",
1199 ret = mt8192_mt6359_card_set_be_link(card, dai_link, headset_codec, "I2S9");
1201 dev_err_probe(&pdev->dev, ret, "%s set headset_codec fail\n",
1206 if (hdmi_codec && strcmp(dai_link->name, "TDM") == 0) {
1207 dai_link->codecs->of_node = hdmi_codec;
1208 dai_link->ignore = 0;
1211 if (strcmp(dai_link->codecs[0].dai_name, RT1015_CODEC_DAI) == 0)
1212 dai_link->ops = &mt8192_rt1015_i2s_ops;
1214 if (!dai_link->platforms->name)
1215 dai_link->platforms->of_node = platform_node;
1218 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
1223 snd_soc_card_set_drvdata(card, priv);
1225 ret = mt8192_afe_gpio_init(&pdev->dev);
1227 dev_err_probe(&pdev->dev, ret, "%s init gpio error\n", __func__);
1231 ret = devm_snd_soc_register_card(&pdev->dev, card);
1233 dev_err_probe(&pdev->dev, ret, "%s snd_soc_register_card fail\n", __func__);
1236 of_node_put(headset_codec);
1238 of_node_put(speaker_codec);
1240 of_node_put(platform_node);
1242 of_node_put(hdmi_codec);
1247 static const struct of_device_id mt8192_mt6359_dt_match[] = {
1249 .compatible = RT1015_RT5682_OF_NAME,
1250 .data = &mt8192_mt6359_rt1015_rt5682_card,
1253 .compatible = RT1015P_RT5682_OF_NAME,
1254 .data = &mt8192_mt6359_rt1015p_rt5682x_card,
1257 .compatible = RT1015P_RT5682S_OF_NAME,
1258 .data = &mt8192_mt6359_rt1015p_rt5682x_card,
1262 MODULE_DEVICE_TABLE(of, mt8192_mt6359_dt_match);
1265 static const struct dev_pm_ops mt8192_mt6359_pm_ops = {
1266 .poweroff = snd_soc_poweroff,
1267 .restore = snd_soc_resume,
1270 static struct platform_driver mt8192_mt6359_driver = {
1272 .name = DRIVER_NAME,
1274 .of_match_table = mt8192_mt6359_dt_match,
1276 .pm = &mt8192_mt6359_pm_ops,
1278 .probe = mt8192_mt6359_dev_probe,
1281 module_platform_driver(mt8192_mt6359_driver);
1283 /* Module information */
1284 MODULE_DESCRIPTION("MT8192-MT6359 ALSA SoC machine driver");
1285 MODULE_AUTHOR("Jiaxin Yu <jiaxin.yu@mediatek.com>");
1286 MODULE_LICENSE("GPL v2");
1287 MODULE_ALIAS("mt8192_mt6359 soc card");