1 // SPDX-License-Identifier: GPL-2.0
4 * MT8195-MT6359 ALSA SoC machine driver code
6 * Copyright (c) 2022 MediaTek Inc.
7 * Author: Trevor Wu <trevor.wu@mediatek.com>
8 * YC Hung <yc.hung@mediatek.com>
11 #include <linux/input.h>
12 #include <linux/module.h>
14 #include <linux/pm_runtime.h>
15 #include <sound/jack.h>
16 #include <sound/pcm_params.h>
17 #include <sound/rt5682.h>
18 #include <sound/soc.h>
19 #include "../../codecs/mt6359.h"
20 #include "../../codecs/rt1011.h"
21 #include "../../codecs/rt5682.h"
22 #include "../common/mtk-afe-platform-driver.h"
23 #include "../common/mtk-dsp-sof-common.h"
24 #include "../common/mtk-soc-card.h"
25 #include "../common/mtk-soundcard-driver.h"
26 #include "mt8195-afe-clk.h"
27 #include "mt8195-afe-common.h"
29 #define RT1011_SPEAKER_AMP_PRESENT BIT(0)
30 #define RT1019_SPEAKER_AMP_PRESENT BIT(1)
31 #define MAX98390_SPEAKER_AMP_PRESENT BIT(2)
33 #define DUMB_CODEC_INIT BIT(0)
34 #define MT6359_CODEC_INIT BIT(1)
35 #define RT1011_CODEC_INIT BIT(2)
36 #define RT1019_CODEC_INIT BIT(3)
37 #define MAX98390_CODEC_INIT BIT(4)
38 #define RT5682_CODEC_INIT BIT(5)
40 #define RT1011_CODEC_DAI "rt1011-aif"
41 #define RT1011_DEV0_NAME "rt1011.2-0038"
42 #define RT1011_DEV1_NAME "rt1011.2-0039"
44 #define RT1019_CODEC_DAI "HiFi"
45 #define RT1019_DEV0_NAME "rt1019p"
47 #define MAX98390_CODEC_DAI "max98390-aif1"
48 #define MAX98390_DEV0_NAME "max98390.2-0038" /* right */
49 #define MAX98390_DEV1_NAME "max98390.2-0039" /* left */
51 #define RT5682_CODEC_DAI "rt5682-aif1"
52 #define RT5682_DEV0_NAME "rt5682.2-001a"
54 #define RT5682S_CODEC_DAI "rt5682s-aif1"
55 #define RT5682S_DEV0_NAME "rt5682s.2-001a"
57 #define SOF_DMA_DL2 "SOF_DMA_DL2"
58 #define SOF_DMA_DL3 "SOF_DMA_DL3"
59 #define SOF_DMA_UL4 "SOF_DMA_UL4"
60 #define SOF_DMA_UL5 "SOF_DMA_UL5"
62 struct mt8195_mt6359_priv
{
63 struct clk
*i2so1_mclk
;
73 /* Headset jack detection DAPM pins */
74 static struct snd_soc_jack_pin mt8195_jack_pins
[] = {
77 .mask
= SND_JACK_HEADPHONE
,
81 .mask
= SND_JACK_MICROPHONE
,
85 static const struct snd_soc_dapm_widget mt8195_mt6359_widgets
[] = {
86 SND_SOC_DAPM_HP("Headphone", NULL
),
87 SND_SOC_DAPM_MIC("Headset Mic", NULL
),
88 SND_SOC_DAPM_MIXER(SOF_DMA_DL2
, SND_SOC_NOPM
, 0, 0, NULL
, 0),
89 SND_SOC_DAPM_MIXER(SOF_DMA_DL3
, SND_SOC_NOPM
, 0, 0, NULL
, 0),
90 SND_SOC_DAPM_MIXER(SOF_DMA_UL4
, SND_SOC_NOPM
, 0, 0, NULL
, 0),
91 SND_SOC_DAPM_MIXER(SOF_DMA_UL5
, SND_SOC_NOPM
, 0, 0, NULL
, 0),
94 static const struct snd_soc_dapm_route mt8195_mt6359_routes
[] = {
96 { "Headphone", NULL
, "HPOL" },
97 { "Headphone", NULL
, "HPOR" },
98 { "IN1P", NULL
, "Headset Mic" },
100 {SOF_DMA_UL4
, NULL
, "O034"},
101 {SOF_DMA_UL4
, NULL
, "O035"},
102 {SOF_DMA_UL5
, NULL
, "O036"},
103 {SOF_DMA_UL5
, NULL
, "O037"},
105 {"I070", NULL
, SOF_DMA_DL2
},
106 {"I071", NULL
, SOF_DMA_DL2
},
107 {"I020", NULL
, SOF_DMA_DL3
},
108 {"I021", NULL
, SOF_DMA_DL3
},
111 static const struct snd_kcontrol_new mt8195_mt6359_controls
[] = {
112 SOC_DAPM_PIN_SWITCH("Headphone"),
113 SOC_DAPM_PIN_SWITCH("Headset Mic"),
116 static const struct snd_soc_dapm_widget mt8195_dual_speaker_widgets
[] = {
117 SND_SOC_DAPM_SPK("Left Spk", NULL
),
118 SND_SOC_DAPM_SPK("Right Spk", NULL
),
121 static const struct snd_kcontrol_new mt8195_dual_speaker_controls
[] = {
122 SOC_DAPM_PIN_SWITCH("Left Spk"),
123 SOC_DAPM_PIN_SWITCH("Right Spk"),
126 static const struct snd_soc_dapm_widget mt8195_speaker_widgets
[] = {
127 SND_SOC_DAPM_SPK("Ext Spk", NULL
),
130 static const struct snd_kcontrol_new mt8195_speaker_controls
[] = {
131 SOC_DAPM_PIN_SWITCH("Ext Spk"),
134 static const struct snd_soc_dapm_route mt8195_rt1011_routes
[] = {
135 { "Left Spk", NULL
, "Left SPO" },
136 { "Right Spk", NULL
, "Right SPO" },
139 static const struct snd_soc_dapm_route mt8195_rt1019_routes
[] = {
140 { "Ext Spk", NULL
, "Speaker" },
143 static const struct snd_soc_dapm_route mt8195_max98390_routes
[] = {
144 { "Left Spk", NULL
, "Left BE_OUT" },
145 { "Right Spk", NULL
, "Right BE_OUT" },
148 #define CKSYS_AUD_TOP_CFG 0x032c
149 #define CKSYS_AUD_TOP_MON 0x0330
151 static int mt8195_mt6359_mtkaif_calibration(struct snd_soc_pcm_runtime
*rtd
)
153 struct snd_soc_component
*cmpnt_afe
=
154 snd_soc_rtdcom_lookup(rtd
, AFE_PCM_NAME
);
155 struct snd_soc_component
*cmpnt_codec
=
156 snd_soc_rtd_to_codec(rtd
, 0)->component
;
157 struct mtk_base_afe
*afe
= snd_soc_component_get_drvdata(cmpnt_afe
);
158 struct mt8195_afe_private
*afe_priv
= afe
->platform_priv
;
159 struct mtkaif_param
*param
= &afe_priv
->mtkaif_params
;
160 int chosen_phase_1
, chosen_phase_2
, chosen_phase_3
;
161 int prev_cycle_1
, prev_cycle_2
, prev_cycle_3
;
162 int test_done_1
, test_done_2
, test_done_3
;
163 int cycle_1
, cycle_2
, cycle_3
;
164 int mtkaif_chosen_phase
[MT8195_MTKAIF_MISO_NUM
];
165 int mtkaif_phase_cycle
[MT8195_MTKAIF_MISO_NUM
];
166 int mtkaif_calibration_num_phase
;
167 bool mtkaif_calibration_ok
;
168 unsigned int monitor
= 0;
173 dev_dbg(afe
->dev
, "%s(), start\n", __func__
);
175 param
->mtkaif_calibration_ok
= false;
176 for (i
= 0; i
< MT8195_MTKAIF_MISO_NUM
; i
++) {
177 param
->mtkaif_chosen_phase
[i
] = -1;
178 param
->mtkaif_phase_cycle
[i
] = 0;
179 mtkaif_chosen_phase
[i
] = -1;
180 mtkaif_phase_cycle
[i
] = 0;
183 if (IS_ERR(afe_priv
->topckgen
)) {
184 dev_info(afe
->dev
, "%s() Cannot find topckgen controller\n",
189 pm_runtime_get_sync(afe
->dev
);
190 mt6359_mtkaif_calibration_enable(cmpnt_codec
);
192 /* set test type to synchronizer pulse */
193 regmap_update_bits(afe_priv
->topckgen
,
194 CKSYS_AUD_TOP_CFG
, 0xffff, 0x4);
195 mtkaif_calibration_num_phase
= 42; /* mt6359: 0 ~ 42 */
196 mtkaif_calibration_ok
= true;
199 phase
<= mtkaif_calibration_num_phase
&& mtkaif_calibration_ok
;
201 mt6359_set_mtkaif_calibration_phase(cmpnt_codec
,
202 phase
, phase
, phase
);
204 regmap_update_bits(afe_priv
->topckgen
,
205 CKSYS_AUD_TOP_CFG
, 0x1, 0x1);
214 while (!(test_done_1
& test_done_2
& test_done_3
)) {
215 regmap_read(afe_priv
->topckgen
,
216 CKSYS_AUD_TOP_MON
, &monitor
);
217 test_done_1
= (monitor
>> 28) & 0x1;
218 test_done_2
= (monitor
>> 29) & 0x1;
219 test_done_3
= (monitor
>> 30) & 0x1;
220 if (test_done_1
== 1)
221 cycle_1
= monitor
& 0xf;
223 if (test_done_2
== 1)
224 cycle_2
= (monitor
>> 4) & 0xf;
226 if (test_done_3
== 1)
227 cycle_3
= (monitor
>> 8) & 0xf;
229 /* handle if never test done */
230 if (++counter
> 10000) {
231 dev_info(afe
->dev
, "%s(), test fail, cycle_1 %d, cycle_2 %d, cycle_3 %d, monitor 0x%x\n",
233 cycle_1
, cycle_2
, cycle_3
, monitor
);
234 mtkaif_calibration_ok
= false;
240 prev_cycle_1
= cycle_1
;
241 prev_cycle_2
= cycle_2
;
242 prev_cycle_3
= cycle_3
;
245 if (cycle_1
!= prev_cycle_1
&&
246 mtkaif_chosen_phase
[MT8195_MTKAIF_MISO_0
] < 0) {
247 mtkaif_chosen_phase
[MT8195_MTKAIF_MISO_0
] = phase
- 1;
248 mtkaif_phase_cycle
[MT8195_MTKAIF_MISO_0
] = prev_cycle_1
;
251 if (cycle_2
!= prev_cycle_2
&&
252 mtkaif_chosen_phase
[MT8195_MTKAIF_MISO_1
] < 0) {
253 mtkaif_chosen_phase
[MT8195_MTKAIF_MISO_1
] = phase
- 1;
254 mtkaif_phase_cycle
[MT8195_MTKAIF_MISO_1
] = prev_cycle_2
;
257 if (cycle_3
!= prev_cycle_3
&&
258 mtkaif_chosen_phase
[MT8195_MTKAIF_MISO_2
] < 0) {
259 mtkaif_chosen_phase
[MT8195_MTKAIF_MISO_2
] = phase
- 1;
260 mtkaif_phase_cycle
[MT8195_MTKAIF_MISO_2
] = prev_cycle_3
;
263 regmap_update_bits(afe_priv
->topckgen
,
264 CKSYS_AUD_TOP_CFG
, 0x1, 0x0);
266 if (mtkaif_chosen_phase
[MT8195_MTKAIF_MISO_0
] >= 0 &&
267 mtkaif_chosen_phase
[MT8195_MTKAIF_MISO_1
] >= 0 &&
268 mtkaif_chosen_phase
[MT8195_MTKAIF_MISO_2
] >= 0)
272 if (mtkaif_chosen_phase
[MT8195_MTKAIF_MISO_0
] < 0) {
273 mtkaif_calibration_ok
= false;
276 chosen_phase_1
= mtkaif_chosen_phase
[MT8195_MTKAIF_MISO_0
];
279 if (mtkaif_chosen_phase
[MT8195_MTKAIF_MISO_1
] < 0) {
280 mtkaif_calibration_ok
= false;
283 chosen_phase_2
= mtkaif_chosen_phase
[MT8195_MTKAIF_MISO_1
];
286 if (mtkaif_chosen_phase
[MT8195_MTKAIF_MISO_2
] < 0) {
287 mtkaif_calibration_ok
= false;
290 chosen_phase_3
= mtkaif_chosen_phase
[MT8195_MTKAIF_MISO_2
];
293 mt6359_set_mtkaif_calibration_phase(cmpnt_codec
,
298 mt6359_mtkaif_calibration_disable(cmpnt_codec
);
299 pm_runtime_put(afe
->dev
);
301 param
->mtkaif_calibration_ok
= mtkaif_calibration_ok
;
302 param
->mtkaif_chosen_phase
[MT8195_MTKAIF_MISO_0
] = chosen_phase_1
;
303 param
->mtkaif_chosen_phase
[MT8195_MTKAIF_MISO_1
] = chosen_phase_2
;
304 param
->mtkaif_chosen_phase
[MT8195_MTKAIF_MISO_2
] = chosen_phase_3
;
305 for (i
= 0; i
< MT8195_MTKAIF_MISO_NUM
; i
++)
306 param
->mtkaif_phase_cycle
[i
] = mtkaif_phase_cycle
[i
];
308 dev_info(afe
->dev
, "%s(), end, calibration ok %d\n",
309 __func__
, param
->mtkaif_calibration_ok
);
314 static int mt8195_mt6359_init(struct snd_soc_pcm_runtime
*rtd
)
316 struct snd_soc_component
*cmpnt_codec
=
317 snd_soc_rtd_to_codec(rtd
, 0)->component
;
319 /* set mtkaif protocol */
320 mt6359_set_mtkaif_protocol(cmpnt_codec
,
321 MT6359_MTKAIF_PROTOCOL_2_CLK_P2
);
323 /* mtkaif calibration */
324 mt8195_mt6359_mtkaif_calibration(rtd
);
329 static int mt8195_hdmitx_dptx_startup(struct snd_pcm_substream
*substream
)
331 return mtk_soundcard_startup(substream
, MTK_CONSTRAINT_HDMIDP
);
334 static const struct snd_soc_ops mt8195_hdmitx_dptx_playback_ops
= {
335 .startup
= mt8195_hdmitx_dptx_startup
,
338 static int mt8195_dptx_hw_params(struct snd_pcm_substream
*substream
,
339 struct snd_pcm_hw_params
*params
)
341 struct snd_soc_pcm_runtime
*rtd
= snd_soc_substream_to_rtd(substream
);
342 struct snd_soc_dai
*cpu_dai
= snd_soc_rtd_to_cpu(rtd
, 0);
344 return snd_soc_dai_set_sysclk(cpu_dai
, 0, params_rate(params
) * 256,
348 static const struct snd_soc_ops mt8195_dptx_ops
= {
349 .hw_params
= mt8195_dptx_hw_params
,
352 static int mt8195_dptx_codec_init(struct snd_soc_pcm_runtime
*rtd
)
354 struct mtk_soc_card_data
*soc_card_data
= snd_soc_card_get_drvdata(rtd
->card
);
355 struct snd_soc_jack
*jack
= &soc_card_data
->card_data
->jacks
[MT8195_JACK_DP
];
356 struct snd_soc_component
*cmpnt_codec
=
357 snd_soc_rtd_to_codec(rtd
, 0)->component
;
360 ret
= snd_soc_card_jack_new(rtd
->card
, "DP Jack", SND_JACK_LINEOUT
, jack
);
364 return snd_soc_component_set_jack(cmpnt_codec
, jack
, NULL
);
367 static int mt8195_hdmi_codec_init(struct snd_soc_pcm_runtime
*rtd
)
369 struct mtk_soc_card_data
*soc_card_data
= snd_soc_card_get_drvdata(rtd
->card
);
370 struct snd_soc_jack
*jack
= &soc_card_data
->card_data
->jacks
[MT8195_JACK_HDMI
];
371 struct snd_soc_component
*cmpnt_codec
=
372 snd_soc_rtd_to_codec(rtd
, 0)->component
;
375 ret
= snd_soc_card_jack_new(rtd
->card
, "HDMI Jack", SND_JACK_LINEOUT
, jack
);
379 return snd_soc_component_set_jack(cmpnt_codec
, jack
, NULL
);
382 static int mt8195_dptx_hw_params_fixup(struct snd_soc_pcm_runtime
*rtd
,
383 struct snd_pcm_hw_params
*params
)
385 /* fix BE i2s format to S24_LE, clean param mask first */
386 snd_mask_reset_range(hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
),
387 0, (__force
unsigned int)SNDRV_PCM_FORMAT_LAST
);
389 params_set_format(params
, SNDRV_PCM_FORMAT_S24_LE
);
394 static int mt8195_rt5682_etdm_hw_params(struct snd_pcm_substream
*substream
,
395 struct snd_pcm_hw_params
*params
)
397 struct snd_soc_pcm_runtime
*rtd
= snd_soc_substream_to_rtd(substream
);
398 struct snd_soc_card
*card
= rtd
->card
;
399 struct snd_soc_dai
*cpu_dai
= snd_soc_rtd_to_cpu(rtd
, 0);
400 struct snd_soc_dai
*codec_dai
= snd_soc_rtd_to_codec(rtd
, 0);
401 unsigned int rate
= params_rate(params
);
405 bitwidth
= snd_pcm_format_width(params_format(params
));
407 dev_err(card
->dev
, "invalid bit width: %d\n", bitwidth
);
411 ret
= snd_soc_dai_set_tdm_slot(codec_dai
, 0x00, 0x0, 0x2, bitwidth
);
413 dev_err(card
->dev
, "failed to set tdm slot\n");
417 ret
= snd_soc_dai_set_pll(codec_dai
, RT5682_PLL1
, RT5682_PLL1_S_MCLK
,
418 rate
* 256, rate
* 512);
420 dev_err(card
->dev
, "failed to set pll\n");
424 ret
= snd_soc_dai_set_sysclk(codec_dai
, RT5682_SCLK_S_PLL1
,
425 rate
* 512, SND_SOC_CLOCK_IN
);
427 dev_err(card
->dev
, "failed to set sysclk\n");
431 return snd_soc_dai_set_sysclk(cpu_dai
, 0, rate
* 256,
435 static const struct snd_soc_ops mt8195_rt5682_etdm_ops
= {
436 .hw_params
= mt8195_rt5682_etdm_hw_params
,
439 static int mt8195_rt5682_init(struct snd_soc_pcm_runtime
*rtd
)
441 struct snd_soc_component
*cmpnt_codec
=
442 snd_soc_rtd_to_codec(rtd
, 0)->component
;
443 struct mtk_soc_card_data
*soc_card_data
= snd_soc_card_get_drvdata(rtd
->card
);
444 struct mt8195_mt6359_priv
*priv
= soc_card_data
->mach_priv
;
445 struct snd_soc_jack
*jack
= &soc_card_data
->card_data
->jacks
[MT8195_JACK_HEADSET
];
446 struct snd_soc_component
*cmpnt_afe
=
447 snd_soc_rtdcom_lookup(rtd
, AFE_PCM_NAME
);
448 struct mtk_base_afe
*afe
= snd_soc_component_get_drvdata(cmpnt_afe
);
449 struct mt8195_afe_private
*afe_priv
= afe
->platform_priv
;
452 priv
->i2so1_mclk
= afe_priv
->clk
[MT8195_CLK_TOP_APLL12_DIV2
];
454 ret
= snd_soc_card_jack_new_pins(rtd
->card
, "Headset Jack",
455 SND_JACK_HEADSET
| SND_JACK_BTN_0
|
456 SND_JACK_BTN_1
| SND_JACK_BTN_2
|
458 jack
, mt8195_jack_pins
,
459 ARRAY_SIZE(mt8195_jack_pins
));
461 dev_err(rtd
->dev
, "Headset Jack creation failed: %d\n", ret
);
465 snd_jack_set_key(jack
->jack
, SND_JACK_BTN_0
, KEY_PLAYPAUSE
);
466 snd_jack_set_key(jack
->jack
, SND_JACK_BTN_1
, KEY_VOICECOMMAND
);
467 snd_jack_set_key(jack
->jack
, SND_JACK_BTN_2
, KEY_VOLUMEUP
);
468 snd_jack_set_key(jack
->jack
, SND_JACK_BTN_3
, KEY_VOLUMEDOWN
);
470 ret
= snd_soc_component_set_jack(cmpnt_codec
, jack
, NULL
);
472 dev_err(rtd
->dev
, "Headset Jack set failed: %d\n", ret
);
479 static int mt8195_rt1011_etdm_hw_params(struct snd_pcm_substream
*substream
,
480 struct snd_pcm_hw_params
*params
)
482 struct snd_soc_pcm_runtime
*rtd
= snd_soc_substream_to_rtd(substream
);
483 struct snd_soc_dai
*codec_dai
;
484 struct snd_soc_card
*card
= rtd
->card
;
487 srate
= params_rate(params
);
489 for_each_rtd_codec_dais(rtd
, i
, codec_dai
) {
490 ret
= snd_soc_dai_set_pll(codec_dai
, 0, RT1011_PLL1_S_BCLK
,
491 64 * srate
, 256 * srate
);
493 dev_err(card
->dev
, "codec_dai clock not set\n");
497 ret
= snd_soc_dai_set_sysclk(codec_dai
,
498 RT1011_FS_SYS_PRE_S_PLL1
,
499 256 * srate
, SND_SOC_CLOCK_IN
);
501 dev_err(card
->dev
, "codec_dai clock not set\n");
508 static const struct snd_soc_ops mt8195_rt1011_etdm_ops
= {
509 .hw_params
= mt8195_rt1011_etdm_hw_params
,
512 static int mt8195_sof_be_hw_params(struct snd_pcm_substream
*substream
,
513 struct snd_pcm_hw_params
*params
)
515 struct snd_soc_pcm_runtime
*rtd
= snd_soc_substream_to_rtd(substream
);
516 struct snd_soc_component
*cmpnt_afe
= NULL
;
517 struct snd_soc_pcm_runtime
*runtime
;
519 /* find afe component */
520 for_each_card_rtds(rtd
->card
, runtime
) {
521 cmpnt_afe
= snd_soc_rtdcom_lookup(runtime
, AFE_PCM_NAME
);
526 if (cmpnt_afe
&& !pm_runtime_active(cmpnt_afe
->dev
)) {
527 dev_err(rtd
->dev
, "afe pm runtime is not active!!\n");
534 static const struct snd_soc_ops mt8195_sof_be_ops
= {
535 .hw_params
= mt8195_sof_be_hw_params
,
538 static int mt8195_rt1011_init(struct snd_soc_pcm_runtime
*rtd
)
540 struct snd_soc_card
*card
= rtd
->card
;
543 ret
= snd_soc_dapm_new_controls(&card
->dapm
, mt8195_dual_speaker_widgets
,
544 ARRAY_SIZE(mt8195_dual_speaker_widgets
));
546 dev_err(rtd
->dev
, "unable to add dapm controls, ret %d\n", ret
);
547 /* Don't need to add routes if widget addition failed */
551 ret
= snd_soc_add_card_controls(card
, mt8195_dual_speaker_controls
,
552 ARRAY_SIZE(mt8195_dual_speaker_controls
));
554 dev_err(rtd
->dev
, "unable to add card controls, ret %d\n", ret
);
558 ret
= snd_soc_dapm_add_routes(&card
->dapm
, mt8195_rt1011_routes
,
559 ARRAY_SIZE(mt8195_rt1011_routes
));
561 dev_err(rtd
->dev
, "unable to add dapm routes, ret %d\n", ret
);
566 static int mt8195_dumb_amp_init(struct snd_soc_pcm_runtime
*rtd
)
568 struct snd_soc_card
*card
= rtd
->card
;
571 ret
= snd_soc_dapm_new_controls(&card
->dapm
, mt8195_speaker_widgets
,
572 ARRAY_SIZE(mt8195_speaker_widgets
));
574 dev_err(rtd
->dev
, "unable to add dapm controls, ret %d\n", ret
);
575 /* Don't need to add routes if widget addition failed */
579 ret
= snd_soc_add_card_controls(card
, mt8195_speaker_controls
,
580 ARRAY_SIZE(mt8195_speaker_controls
));
582 dev_err(rtd
->dev
, "unable to add card controls, ret %d\n", ret
);
589 static int mt8195_rt1019_init(struct snd_soc_pcm_runtime
*rtd
)
591 struct snd_soc_card
*card
= rtd
->card
;
594 ret
= mt8195_dumb_amp_init(rtd
);
598 ret
= snd_soc_dapm_add_routes(&card
->dapm
, mt8195_rt1019_routes
,
599 ARRAY_SIZE(mt8195_rt1019_routes
));
601 dev_err(rtd
->dev
, "unable to add dapm routes, ret %d\n", ret
);
606 static int mt8195_max98390_init(struct snd_soc_pcm_runtime
*rtd
)
608 struct snd_soc_card
*card
= rtd
->card
;
611 ret
= snd_soc_dapm_new_controls(&card
->dapm
, mt8195_dual_speaker_widgets
,
612 ARRAY_SIZE(mt8195_dual_speaker_widgets
));
614 dev_err(rtd
->dev
, "unable to add dapm controls, ret %d\n", ret
);
615 /* Don't need to add routes if widget addition failed */
619 ret
= snd_soc_add_card_controls(card
, mt8195_dual_speaker_controls
,
620 ARRAY_SIZE(mt8195_dual_speaker_controls
));
622 dev_err(rtd
->dev
, "unable to add card controls, ret %d\n", ret
);
626 ret
= snd_soc_dapm_add_routes(&card
->dapm
, mt8195_max98390_routes
,
627 ARRAY_SIZE(mt8195_max98390_routes
));
629 dev_err(rtd
->dev
, "unable to add dapm routes, ret %d\n", ret
);
634 static int mt8195_etdm_hw_params_fixup(struct snd_soc_pcm_runtime
*rtd
,
635 struct snd_pcm_hw_params
*params
)
637 /* fix BE i2s format to S24_LE, clean param mask first */
638 snd_mask_reset_range(hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
),
639 0, (__force
unsigned int)SNDRV_PCM_FORMAT_LAST
);
641 params_set_format(params
, SNDRV_PCM_FORMAT_S24_LE
);
646 static int mt8195_set_bias_level_post(struct snd_soc_card
*card
,
647 struct snd_soc_dapm_context
*dapm
, enum snd_soc_bias_level level
)
649 struct snd_soc_component
*component
= dapm
->component
;
650 struct mtk_soc_card_data
*soc_card_data
= snd_soc_card_get_drvdata(card
);
651 struct mt8195_mt6359_priv
*priv
= soc_card_data
->mach_priv
;
655 * It's required to control mclk directly in the set_bias_level_post
656 * function for rt5682 and rt5682s codec, or the unexpected pop happens
657 * at the end of playback.
660 (strcmp(component
->name
, RT5682_DEV0_NAME
) &&
661 strcmp(component
->name
, RT5682S_DEV0_NAME
)))
665 case SND_SOC_BIAS_OFF
:
666 if (!__clk_is_enabled(priv
->i2so1_mclk
))
669 clk_disable_unprepare(priv
->i2so1_mclk
);
670 dev_dbg(card
->dev
, "Disable i2so1 mclk\n");
672 case SND_SOC_BIAS_ON
:
673 ret
= clk_prepare_enable(priv
->i2so1_mclk
);
675 dev_err(card
->dev
, "Can't enable i2so1 mclk: %d\n", ret
);
678 dev_dbg(card
->dev
, "Enable i2so1 mclk\n");
706 DAI_LINK_ETDM1_IN_BE
,
707 DAI_LINK_ETDM2_IN_BE
,
708 DAI_LINK_ETDM1_OUT_BE
,
709 DAI_LINK_ETDM2_OUT_BE
,
710 DAI_LINK_ETDM3_OUT_BE
,
714 DAI_LINK_REGULAR_LAST
= DAI_LINK_UL_SRC2_BE
,
716 DAI_LINK_SOF_DL2_BE
= DAI_LINK_SOF_START
,
720 DAI_LINK_SOF_END
= DAI_LINK_SOF_UL5_BE
,
723 #define DAI_LINK_REGULAR_NUM (DAI_LINK_REGULAR_LAST + 1)
726 SND_SOC_DAILINK_DEFS(DL2_FE
,
727 DAILINK_COMP_ARRAY(COMP_CPU("DL2")),
728 DAILINK_COMP_ARRAY(COMP_DUMMY()),
729 DAILINK_COMP_ARRAY(COMP_EMPTY()));
731 SND_SOC_DAILINK_DEFS(DL3_FE
,
732 DAILINK_COMP_ARRAY(COMP_CPU("DL3")),
733 DAILINK_COMP_ARRAY(COMP_DUMMY()),
734 DAILINK_COMP_ARRAY(COMP_EMPTY()));
736 SND_SOC_DAILINK_DEFS(DL6_FE
,
737 DAILINK_COMP_ARRAY(COMP_CPU("DL6")),
738 DAILINK_COMP_ARRAY(COMP_DUMMY()),
739 DAILINK_COMP_ARRAY(COMP_EMPTY()));
741 SND_SOC_DAILINK_DEFS(DL7_FE
,
742 DAILINK_COMP_ARRAY(COMP_CPU("DL7")),
743 DAILINK_COMP_ARRAY(COMP_DUMMY()),
744 DAILINK_COMP_ARRAY(COMP_EMPTY()));
746 SND_SOC_DAILINK_DEFS(DL8_FE
,
747 DAILINK_COMP_ARRAY(COMP_CPU("DL8")),
748 DAILINK_COMP_ARRAY(COMP_DUMMY()),
749 DAILINK_COMP_ARRAY(COMP_EMPTY()));
751 SND_SOC_DAILINK_DEFS(DL10_FE
,
752 DAILINK_COMP_ARRAY(COMP_CPU("DL10")),
753 DAILINK_COMP_ARRAY(COMP_DUMMY()),
754 DAILINK_COMP_ARRAY(COMP_EMPTY()));
756 SND_SOC_DAILINK_DEFS(DL11_FE
,
757 DAILINK_COMP_ARRAY(COMP_CPU("DL11")),
758 DAILINK_COMP_ARRAY(COMP_DUMMY()),
759 DAILINK_COMP_ARRAY(COMP_EMPTY()));
761 SND_SOC_DAILINK_DEFS(UL1_FE
,
762 DAILINK_COMP_ARRAY(COMP_CPU("UL1")),
763 DAILINK_COMP_ARRAY(COMP_DUMMY()),
764 DAILINK_COMP_ARRAY(COMP_EMPTY()));
766 SND_SOC_DAILINK_DEFS(UL2_FE
,
767 DAILINK_COMP_ARRAY(COMP_CPU("UL2")),
768 DAILINK_COMP_ARRAY(COMP_DUMMY()),
769 DAILINK_COMP_ARRAY(COMP_EMPTY()));
771 SND_SOC_DAILINK_DEFS(UL3_FE
,
772 DAILINK_COMP_ARRAY(COMP_CPU("UL3")),
773 DAILINK_COMP_ARRAY(COMP_DUMMY()),
774 DAILINK_COMP_ARRAY(COMP_EMPTY()));
776 SND_SOC_DAILINK_DEFS(UL4_FE
,
777 DAILINK_COMP_ARRAY(COMP_CPU("UL4")),
778 DAILINK_COMP_ARRAY(COMP_DUMMY()),
779 DAILINK_COMP_ARRAY(COMP_EMPTY()));
781 SND_SOC_DAILINK_DEFS(UL5_FE
,
782 DAILINK_COMP_ARRAY(COMP_CPU("UL5")),
783 DAILINK_COMP_ARRAY(COMP_DUMMY()),
784 DAILINK_COMP_ARRAY(COMP_EMPTY()));
786 SND_SOC_DAILINK_DEFS(UL6_FE
,
787 DAILINK_COMP_ARRAY(COMP_CPU("UL6")),
788 DAILINK_COMP_ARRAY(COMP_DUMMY()),
789 DAILINK_COMP_ARRAY(COMP_EMPTY()));
791 SND_SOC_DAILINK_DEFS(UL8_FE
,
792 DAILINK_COMP_ARRAY(COMP_CPU("UL8")),
793 DAILINK_COMP_ARRAY(COMP_DUMMY()),
794 DAILINK_COMP_ARRAY(COMP_EMPTY()));
796 SND_SOC_DAILINK_DEFS(UL9_FE
,
797 DAILINK_COMP_ARRAY(COMP_CPU("UL9")),
798 DAILINK_COMP_ARRAY(COMP_DUMMY()),
799 DAILINK_COMP_ARRAY(COMP_EMPTY()));
801 SND_SOC_DAILINK_DEFS(UL10_FE
,
802 DAILINK_COMP_ARRAY(COMP_CPU("UL10")),
803 DAILINK_COMP_ARRAY(COMP_DUMMY()),
804 DAILINK_COMP_ARRAY(COMP_EMPTY()));
807 SND_SOC_DAILINK_DEFS(DL_SRC_BE
,
808 DAILINK_COMP_ARRAY(COMP_CPU("DL_SRC")),
809 DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
810 "mt6359-snd-codec-aif1")),
811 DAILINK_COMP_ARRAY(COMP_EMPTY()));
813 SND_SOC_DAILINK_DEFS(DPTX_BE
,
814 DAILINK_COMP_ARRAY(COMP_CPU("DPTX")),
815 DAILINK_COMP_ARRAY(COMP_DUMMY()),
816 DAILINK_COMP_ARRAY(COMP_EMPTY()));
818 SND_SOC_DAILINK_DEFS(ETDM1_IN_BE
,
819 DAILINK_COMP_ARRAY(COMP_CPU("ETDM1_IN")),
820 DAILINK_COMP_ARRAY(COMP_DUMMY()),
821 DAILINK_COMP_ARRAY(COMP_EMPTY()));
823 SND_SOC_DAILINK_DEFS(ETDM2_IN_BE
,
824 DAILINK_COMP_ARRAY(COMP_CPU("ETDM2_IN")),
825 DAILINK_COMP_ARRAY(COMP_EMPTY()),
826 DAILINK_COMP_ARRAY(COMP_EMPTY()));
828 SND_SOC_DAILINK_DEFS(ETDM1_OUT_BE
,
829 DAILINK_COMP_ARRAY(COMP_CPU("ETDM1_OUT")),
830 DAILINK_COMP_ARRAY(COMP_EMPTY()),
831 DAILINK_COMP_ARRAY(COMP_EMPTY()));
833 SND_SOC_DAILINK_DEFS(ETDM2_OUT_BE
,
834 DAILINK_COMP_ARRAY(COMP_CPU("ETDM2_OUT")),
835 DAILINK_COMP_ARRAY(COMP_DUMMY()),
836 DAILINK_COMP_ARRAY(COMP_EMPTY()));
838 SND_SOC_DAILINK_DEFS(ETDM3_OUT_BE
,
839 DAILINK_COMP_ARRAY(COMP_CPU("ETDM3_OUT")),
840 DAILINK_COMP_ARRAY(COMP_DUMMY()),
841 DAILINK_COMP_ARRAY(COMP_EMPTY()));
843 SND_SOC_DAILINK_DEFS(PCM1_BE
,
844 DAILINK_COMP_ARRAY(COMP_CPU("PCM1")),
845 DAILINK_COMP_ARRAY(COMP_DUMMY()),
846 DAILINK_COMP_ARRAY(COMP_EMPTY()));
848 SND_SOC_DAILINK_DEFS(UL_SRC1_BE
,
849 DAILINK_COMP_ARRAY(COMP_CPU("UL_SRC1")),
850 DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
851 "mt6359-snd-codec-aif1"),
852 COMP_CODEC("dmic-codec",
854 DAILINK_COMP_ARRAY(COMP_EMPTY()));
856 SND_SOC_DAILINK_DEFS(UL_SRC2_BE
,
857 DAILINK_COMP_ARRAY(COMP_CPU("UL_SRC2")),
858 DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
859 "mt6359-snd-codec-aif2")),
860 DAILINK_COMP_ARRAY(COMP_EMPTY()));
862 SND_SOC_DAILINK_DEFS(AFE_SOF_DL2
,
863 DAILINK_COMP_ARRAY(COMP_CPU("SOF_DL2")),
864 DAILINK_COMP_ARRAY(COMP_DUMMY()),
865 DAILINK_COMP_ARRAY(COMP_EMPTY()));
867 SND_SOC_DAILINK_DEFS(AFE_SOF_DL3
,
868 DAILINK_COMP_ARRAY(COMP_CPU("SOF_DL3")),
869 DAILINK_COMP_ARRAY(COMP_DUMMY()),
870 DAILINK_COMP_ARRAY(COMP_EMPTY()));
872 SND_SOC_DAILINK_DEFS(AFE_SOF_UL4
,
873 DAILINK_COMP_ARRAY(COMP_CPU("SOF_UL4")),
874 DAILINK_COMP_ARRAY(COMP_DUMMY()),
875 DAILINK_COMP_ARRAY(COMP_EMPTY()));
877 SND_SOC_DAILINK_DEFS(AFE_SOF_UL5
,
878 DAILINK_COMP_ARRAY(COMP_CPU("SOF_UL5")),
879 DAILINK_COMP_ARRAY(COMP_DUMMY()),
880 DAILINK_COMP_ARRAY(COMP_EMPTY()));
883 SND_SOC_DAILINK_DEF(rt1019_comps
,
884 DAILINK_COMP_ARRAY(COMP_CODEC(RT1019_DEV0_NAME
,
887 SND_SOC_DAILINK_DEF(rt1011_comps
,
888 DAILINK_COMP_ARRAY(COMP_CODEC(RT1011_DEV0_NAME
,
890 COMP_CODEC(RT1011_DEV1_NAME
,
893 SND_SOC_DAILINK_DEF(max98390_comps
,
894 DAILINK_COMP_ARRAY(COMP_CODEC(MAX98390_DEV0_NAME
,
896 COMP_CODEC(MAX98390_DEV1_NAME
,
897 MAX98390_CODEC_DAI
)));
899 static const struct sof_conn_stream g_sof_conn_streams
[] = {
900 { "ETDM2_OUT_BE", "AFE_SOF_DL2", SOF_DMA_DL2
, SNDRV_PCM_STREAM_PLAYBACK
},
901 { "ETDM1_OUT_BE", "AFE_SOF_DL3", SOF_DMA_DL3
, SNDRV_PCM_STREAM_PLAYBACK
},
902 { "UL_SRC1_BE", "AFE_SOF_UL4", SOF_DMA_UL4
, SNDRV_PCM_STREAM_CAPTURE
},
903 { "ETDM2_IN_BE", "AFE_SOF_UL5", SOF_DMA_UL5
, SNDRV_PCM_STREAM_CAPTURE
},
906 static struct snd_soc_dai_link mt8195_mt6359_dai_links
[] = {
908 [DAI_LINK_DL2_FE
] = {
910 .stream_name
= "DL2 Playback",
912 SND_SOC_DPCM_TRIGGER_POST
,
913 SND_SOC_DPCM_TRIGGER_POST
,
917 .ops
= &mtk_soundcard_common_playback_ops
,
918 SND_SOC_DAILINK_REG(DL2_FE
),
920 [DAI_LINK_DL3_FE
] = {
922 .stream_name
= "DL3 Playback",
924 SND_SOC_DPCM_TRIGGER_POST
,
925 SND_SOC_DPCM_TRIGGER_POST
,
929 .ops
= &mtk_soundcard_common_playback_ops
,
930 SND_SOC_DAILINK_REG(DL3_FE
),
932 [DAI_LINK_DL6_FE
] = {
934 .stream_name
= "DL6 Playback",
936 SND_SOC_DPCM_TRIGGER_POST
,
937 SND_SOC_DPCM_TRIGGER_POST
,
941 .ops
= &mtk_soundcard_common_playback_ops
,
942 SND_SOC_DAILINK_REG(DL6_FE
),
944 [DAI_LINK_DL7_FE
] = {
946 .stream_name
= "DL7 Playback",
948 SND_SOC_DPCM_TRIGGER_PRE
,
949 SND_SOC_DPCM_TRIGGER_PRE
,
953 SND_SOC_DAILINK_REG(DL7_FE
),
955 [DAI_LINK_DL8_FE
] = {
957 .stream_name
= "DL8 Playback",
959 SND_SOC_DPCM_TRIGGER_POST
,
960 SND_SOC_DPCM_TRIGGER_POST
,
964 .ops
= &mtk_soundcard_common_playback_ops
,
965 SND_SOC_DAILINK_REG(DL8_FE
),
967 [DAI_LINK_DL10_FE
] = {
969 .stream_name
= "DL10 Playback",
971 SND_SOC_DPCM_TRIGGER_POST
,
972 SND_SOC_DPCM_TRIGGER_POST
,
976 .ops
= &mt8195_hdmitx_dptx_playback_ops
,
977 SND_SOC_DAILINK_REG(DL10_FE
),
979 [DAI_LINK_DL11_FE
] = {
981 .stream_name
= "DL11 Playback",
983 SND_SOC_DPCM_TRIGGER_POST
,
984 SND_SOC_DPCM_TRIGGER_POST
,
988 .ops
= &mtk_soundcard_common_playback_ops
,
989 SND_SOC_DAILINK_REG(DL11_FE
),
991 [DAI_LINK_UL1_FE
] = {
993 .stream_name
= "UL1 Capture",
995 SND_SOC_DPCM_TRIGGER_PRE
,
996 SND_SOC_DPCM_TRIGGER_PRE
,
1000 SND_SOC_DAILINK_REG(UL1_FE
),
1002 [DAI_LINK_UL2_FE
] = {
1004 .stream_name
= "UL2 Capture",
1006 SND_SOC_DPCM_TRIGGER_POST
,
1007 SND_SOC_DPCM_TRIGGER_POST
,
1011 .ops
= &mtk_soundcard_common_capture_ops
,
1012 SND_SOC_DAILINK_REG(UL2_FE
),
1014 [DAI_LINK_UL3_FE
] = {
1016 .stream_name
= "UL3 Capture",
1018 SND_SOC_DPCM_TRIGGER_POST
,
1019 SND_SOC_DPCM_TRIGGER_POST
,
1023 .ops
= &mtk_soundcard_common_capture_ops
,
1024 SND_SOC_DAILINK_REG(UL3_FE
),
1026 [DAI_LINK_UL4_FE
] = {
1028 .stream_name
= "UL4 Capture",
1030 SND_SOC_DPCM_TRIGGER_POST
,
1031 SND_SOC_DPCM_TRIGGER_POST
,
1035 .ops
= &mtk_soundcard_common_capture_ops
,
1036 SND_SOC_DAILINK_REG(UL4_FE
),
1038 [DAI_LINK_UL5_FE
] = {
1040 .stream_name
= "UL5 Capture",
1042 SND_SOC_DPCM_TRIGGER_POST
,
1043 SND_SOC_DPCM_TRIGGER_POST
,
1047 .ops
= &mtk_soundcard_common_capture_ops
,
1048 SND_SOC_DAILINK_REG(UL5_FE
),
1050 [DAI_LINK_UL6_FE
] = {
1052 .stream_name
= "UL6 Capture",
1054 SND_SOC_DPCM_TRIGGER_PRE
,
1055 SND_SOC_DPCM_TRIGGER_PRE
,
1059 SND_SOC_DAILINK_REG(UL6_FE
),
1061 [DAI_LINK_UL8_FE
] = {
1063 .stream_name
= "UL8 Capture",
1065 SND_SOC_DPCM_TRIGGER_POST
,
1066 SND_SOC_DPCM_TRIGGER_POST
,
1070 .ops
= &mtk_soundcard_common_capture_ops
,
1071 SND_SOC_DAILINK_REG(UL8_FE
),
1073 [DAI_LINK_UL9_FE
] = {
1075 .stream_name
= "UL9 Capture",
1077 SND_SOC_DPCM_TRIGGER_POST
,
1078 SND_SOC_DPCM_TRIGGER_POST
,
1082 .ops
= &mtk_soundcard_common_capture_ops
,
1083 SND_SOC_DAILINK_REG(UL9_FE
),
1085 [DAI_LINK_UL10_FE
] = {
1087 .stream_name
= "UL10 Capture",
1089 SND_SOC_DPCM_TRIGGER_POST
,
1090 SND_SOC_DPCM_TRIGGER_POST
,
1094 .ops
= &mtk_soundcard_common_capture_ops
,
1095 SND_SOC_DAILINK_REG(UL10_FE
),
1098 [DAI_LINK_DL_SRC_BE
] = {
1099 .name
= "DL_SRC_BE",
1102 SND_SOC_DAILINK_REG(DL_SRC_BE
),
1104 [DAI_LINK_DPTX_BE
] = {
1108 .ops
= &mt8195_dptx_ops
,
1109 .be_hw_params_fixup
= mt8195_dptx_hw_params_fixup
,
1110 SND_SOC_DAILINK_REG(DPTX_BE
),
1112 [DAI_LINK_ETDM1_IN_BE
] = {
1113 .name
= "ETDM1_IN_BE",
1115 .dai_fmt
= SND_SOC_DAIFMT_I2S
|
1116 SND_SOC_DAIFMT_NB_NF
|
1117 SND_SOC_DAIFMT_CBS_CFS
,
1119 SND_SOC_DAILINK_REG(ETDM1_IN_BE
),
1121 [DAI_LINK_ETDM2_IN_BE
] = {
1122 .name
= "ETDM2_IN_BE",
1124 .dai_fmt
= SND_SOC_DAIFMT_I2S
|
1125 SND_SOC_DAIFMT_NB_NF
|
1126 SND_SOC_DAIFMT_CBS_CFS
,
1128 .be_hw_params_fixup
= mt8195_etdm_hw_params_fixup
,
1129 SND_SOC_DAILINK_REG(ETDM2_IN_BE
),
1131 [DAI_LINK_ETDM1_OUT_BE
] = {
1132 .name
= "ETDM1_OUT_BE",
1134 .dai_fmt
= SND_SOC_DAIFMT_I2S
|
1135 SND_SOC_DAIFMT_NB_NF
|
1136 SND_SOC_DAIFMT_CBS_CFS
,
1138 .be_hw_params_fixup
= mt8195_etdm_hw_params_fixup
,
1139 SND_SOC_DAILINK_REG(ETDM1_OUT_BE
),
1141 [DAI_LINK_ETDM2_OUT_BE
] = {
1142 .name
= "ETDM2_OUT_BE",
1144 .dai_fmt
= SND_SOC_DAIFMT_I2S
|
1145 SND_SOC_DAIFMT_NB_NF
|
1146 SND_SOC_DAIFMT_CBS_CFS
,
1148 SND_SOC_DAILINK_REG(ETDM2_OUT_BE
),
1150 [DAI_LINK_ETDM3_OUT_BE
] = {
1151 .name
= "ETDM3_OUT_BE",
1153 .dai_fmt
= SND_SOC_DAIFMT_I2S
|
1154 SND_SOC_DAIFMT_NB_NF
|
1155 SND_SOC_DAIFMT_CBS_CFS
,
1157 SND_SOC_DAILINK_REG(ETDM3_OUT_BE
),
1159 [DAI_LINK_PCM1_BE
] = {
1162 .dai_fmt
= SND_SOC_DAIFMT_I2S
|
1163 SND_SOC_DAIFMT_NB_NF
|
1164 SND_SOC_DAIFMT_CBS_CFS
,
1165 SND_SOC_DAILINK_REG(PCM1_BE
),
1167 [DAI_LINK_UL_SRC1_BE
] = {
1168 .name
= "UL_SRC1_BE",
1171 SND_SOC_DAILINK_REG(UL_SRC1_BE
),
1173 [DAI_LINK_UL_SRC2_BE
] = {
1174 .name
= "UL_SRC2_BE",
1177 SND_SOC_DAILINK_REG(UL_SRC2_BE
),
1180 [DAI_LINK_SOF_DL2_BE
] = {
1181 .name
= "AFE_SOF_DL2",
1184 .ops
= &mt8195_sof_be_ops
,
1185 SND_SOC_DAILINK_REG(AFE_SOF_DL2
),
1187 [DAI_LINK_SOF_DL3_BE
] = {
1188 .name
= "AFE_SOF_DL3",
1191 .ops
= &mt8195_sof_be_ops
,
1192 SND_SOC_DAILINK_REG(AFE_SOF_DL3
),
1194 [DAI_LINK_SOF_UL4_BE
] = {
1195 .name
= "AFE_SOF_UL4",
1198 .ops
= &mt8195_sof_be_ops
,
1199 SND_SOC_DAILINK_REG(AFE_SOF_UL4
),
1201 [DAI_LINK_SOF_UL5_BE
] = {
1202 .name
= "AFE_SOF_UL5",
1205 .ops
= &mt8195_sof_be_ops
,
1206 SND_SOC_DAILINK_REG(AFE_SOF_UL5
),
1210 static struct snd_soc_codec_conf rt1011_codec_conf
[] = {
1212 .dlc
= COMP_CODEC_CONF(RT1011_DEV0_NAME
),
1213 .name_prefix
= "Left",
1216 .dlc
= COMP_CODEC_CONF(RT1011_DEV1_NAME
),
1217 .name_prefix
= "Right",
1221 static struct snd_soc_codec_conf max98390_codec_conf
[] = {
1223 .dlc
= COMP_CODEC_CONF(MAX98390_DEV0_NAME
),
1224 .name_prefix
= "Right",
1227 .dlc
= COMP_CODEC_CONF(MAX98390_DEV1_NAME
),
1228 .name_prefix
= "Left",
1232 static struct snd_soc_card mt8195_mt6359_soc_card
= {
1233 .owner
= THIS_MODULE
,
1234 .dai_link
= mt8195_mt6359_dai_links
,
1235 .num_links
= ARRAY_SIZE(mt8195_mt6359_dai_links
),
1236 .controls
= mt8195_mt6359_controls
,
1237 .num_controls
= ARRAY_SIZE(mt8195_mt6359_controls
),
1238 .dapm_widgets
= mt8195_mt6359_widgets
,
1239 .num_dapm_widgets
= ARRAY_SIZE(mt8195_mt6359_widgets
),
1240 .dapm_routes
= mt8195_mt6359_routes
,
1241 .num_dapm_routes
= ARRAY_SIZE(mt8195_mt6359_routes
),
1242 .set_bias_level_post
= mt8195_set_bias_level_post
,
1245 /* fixup the BE DAI link to match any values from topology */
1246 static int mt8195_dai_link_fixup(struct snd_soc_pcm_runtime
*rtd
,
1247 struct snd_pcm_hw_params
*params
)
1251 ret
= mtk_sof_dai_link_fixup(rtd
, params
);
1253 if (!strcmp(rtd
->dai_link
->name
, "ETDM2_IN_BE") ||
1254 !strcmp(rtd
->dai_link
->name
, "ETDM1_OUT_BE")) {
1255 mt8195_etdm_hw_params_fixup(rtd
, params
);
1261 static int mt8195_mt6359_legacy_probe(struct mtk_soc_card_data
*soc_card_data
)
1263 struct mtk_platform_card_data
*card_data
= soc_card_data
->card_data
;
1264 struct snd_soc_card
*card
= card_data
->card
;
1265 struct device_node
*codec_node
, *dp_node
, *hdmi_node
;
1266 struct snd_soc_dai_link
*dai_link
;
1267 struct device
*dev
= card
->dev
;
1268 bool is5682s
, init6359
= false;
1271 if (strstr(card
->name
, "_5682s")) {
1272 codec_node
= of_find_compatible_node(NULL
, NULL
, "realtek,rt5682s");
1275 codec_node
= of_find_compatible_node(NULL
, NULL
, "realtek,rt5682i");
1279 dp_node
= of_parse_phandle(dev
->of_node
, "mediatek,dptx-codec", 0);
1280 hdmi_node
= of_parse_phandle(dev
->of_node
, "mediatek,hdmi-codec", 0);
1282 for_each_card_prelinks(card
, i
, dai_link
) {
1283 if (strcmp(dai_link
->name
, "DPTX_BE") == 0) {
1285 dev_dbg(dev
, "No property 'dptx-codec'\n");
1287 dai_link
->codecs
->of_node
= dp_node
;
1288 dai_link
->codecs
->name
= NULL
;
1289 dai_link
->codecs
->dai_name
= "i2s-hifi";
1290 dai_link
->init
= mt8195_dptx_codec_init
;
1292 } else if (strcmp(dai_link
->name
, "ETDM3_OUT_BE") == 0) {
1294 dev_dbg(dev
, "No property 'hdmi-codec'\n");
1296 dai_link
->codecs
->of_node
= hdmi_node
;
1297 dai_link
->codecs
->name
= NULL
;
1298 dai_link
->codecs
->dai_name
= "i2s-hifi";
1299 dai_link
->init
= mt8195_hdmi_codec_init
;
1301 } else if (strcmp(dai_link
->name
, "ETDM1_OUT_BE") == 0) {
1303 dev_err(dev
, "Codec not found!\n");
1305 dai_link
->codecs
->of_node
= codec_node
;
1306 dai_link
->codecs
->name
= NULL
;
1307 dai_link
->codecs
->dai_name
=
1308 is5682s
? RT5682S_CODEC_DAI
: RT5682_CODEC_DAI
;
1309 dai_link
->init
= mt8195_rt5682_init
;
1310 dai_link
->ops
= &mt8195_rt5682_etdm_ops
;
1312 } else if (strcmp(dai_link
->name
, "ETDM2_IN_BE") == 0) {
1314 dev_err(dev
, "Codec not found!\n");
1316 dai_link
->codecs
->of_node
= codec_node
;
1317 dai_link
->codecs
->name
= NULL
;
1318 dai_link
->codecs
->dai_name
=
1319 is5682s
? RT5682S_CODEC_DAI
: RT5682_CODEC_DAI
;
1320 dai_link
->ops
= &mt8195_rt5682_etdm_ops
;
1322 } else if (strcmp(dai_link
->name
, "DL_SRC_BE") == 0 ||
1323 strcmp(dai_link
->name
, "UL_SRC1_BE") == 0 ||
1324 strcmp(dai_link
->name
, "UL_SRC2_BE") == 0) {
1326 dai_link
->init
= mt8195_mt6359_init
;
1329 } else if (strcmp(dai_link
->name
, "ETDM2_OUT_BE") == 0) {
1330 switch (card_data
->flags
) {
1331 case RT1011_SPEAKER_AMP_PRESENT
:
1332 dai_link
->codecs
= rt1011_comps
;
1333 dai_link
->num_codecs
= ARRAY_SIZE(rt1011_comps
);
1334 dai_link
->init
= mt8195_rt1011_init
;
1335 dai_link
->ops
= &mt8195_rt1011_etdm_ops
;
1336 dai_link
->be_hw_params_fixup
= mt8195_etdm_hw_params_fixup
;
1337 card
->codec_conf
= rt1011_codec_conf
;
1338 card
->num_configs
= ARRAY_SIZE(rt1011_codec_conf
);
1340 case RT1019_SPEAKER_AMP_PRESENT
:
1341 dai_link
->codecs
= rt1019_comps
;
1342 dai_link
->num_codecs
= ARRAY_SIZE(rt1019_comps
);
1343 dai_link
->init
= mt8195_rt1019_init
;
1345 case MAX98390_SPEAKER_AMP_PRESENT
:
1346 dai_link
->codecs
= max98390_comps
;
1347 dai_link
->num_codecs
= ARRAY_SIZE(max98390_comps
);
1348 dai_link
->init
= mt8195_max98390_init
;
1349 card
->codec_conf
= max98390_codec_conf
;
1350 card
->num_configs
= ARRAY_SIZE(max98390_codec_conf
);
1361 static int mt8195_mt6359_soc_card_probe(struct mtk_soc_card_data
*soc_card_data
, bool legacy
)
1363 struct mtk_platform_card_data
*card_data
= soc_card_data
->card_data
;
1364 struct snd_soc_card
*card
= card_data
->card
;
1365 struct mt8195_mt6359_priv
*mach_priv
;
1366 struct snd_soc_dai_link
*dai_link
;
1370 mach_priv
= devm_kzalloc(card
->dev
, sizeof(*mach_priv
), GFP_KERNEL
);
1374 soc_card_data
->mach_priv
= mach_priv
;
1377 return mt8195_mt6359_legacy_probe(soc_card_data
);
1379 for_each_card_prelinks(card
, i
, dai_link
) {
1380 if (strcmp(dai_link
->name
, "DPTX_BE") == 0) {
1381 if (dai_link
->num_codecs
&&
1382 strcmp(dai_link
->codecs
->dai_name
, "snd-soc-dummy-dai"))
1383 dai_link
->init
= mt8195_dptx_codec_init
;
1384 } else if (strcmp(dai_link
->name
, "ETDM3_OUT_BE") == 0) {
1385 if (dai_link
->num_codecs
&&
1386 strcmp(dai_link
->codecs
->dai_name
, "snd-soc-dummy-dai"))
1387 dai_link
->init
= mt8195_hdmi_codec_init
;
1388 } else if (strcmp(dai_link
->name
, "DL_SRC_BE") == 0 ||
1389 strcmp(dai_link
->name
, "UL_SRC1_BE") == 0 ||
1390 strcmp(dai_link
->name
, "UL_SRC2_BE") == 0) {
1391 if (!(codec_init
& MT6359_CODEC_INIT
)) {
1392 dai_link
->init
= mt8195_mt6359_init
;
1393 codec_init
|= MT6359_CODEC_INIT
;
1395 } else if (strcmp(dai_link
->name
, "ETDM1_OUT_BE") == 0 ||
1396 strcmp(dai_link
->name
, "ETDM2_OUT_BE") == 0 ||
1397 strcmp(dai_link
->name
, "ETDM1_IN_BE") == 0 ||
1398 strcmp(dai_link
->name
, "ETDM2_IN_BE") == 0) {
1399 if (!dai_link
->num_codecs
)
1402 if (!strcmp(dai_link
->codecs
->dai_name
, MAX98390_CODEC_DAI
)) {
1403 if (!(codec_init
& MAX98390_CODEC_INIT
)) {
1404 dai_link
->init
= mt8195_max98390_init
;
1405 codec_init
|= MAX98390_CODEC_INIT
;
1407 } else if (!strcmp(dai_link
->codecs
->dai_name
, RT1011_CODEC_DAI
)) {
1408 dai_link
->ops
= &mt8195_rt1011_etdm_ops
;
1409 if (!(codec_init
& RT1011_CODEC_INIT
)) {
1410 dai_link
->init
= mt8195_rt1011_init
;
1411 codec_init
|= RT1011_CODEC_INIT
;
1413 } else if (!strcmp(dai_link
->codecs
->dai_name
, RT1019_CODEC_DAI
)) {
1414 if (!(codec_init
& RT1019_CODEC_INIT
)) {
1415 dai_link
->init
= mt8195_rt1019_init
;
1416 codec_init
|= RT1019_CODEC_INIT
;
1418 } else if (!strcmp(dai_link
->codecs
->dai_name
, RT5682_CODEC_DAI
) ||
1419 !strcmp(dai_link
->codecs
->dai_name
, RT5682S_CODEC_DAI
)) {
1420 dai_link
->ops
= &mt8195_rt5682_etdm_ops
;
1421 if (!(codec_init
& RT5682_CODEC_INIT
)) {
1422 dai_link
->init
= mt8195_rt5682_init
;
1423 codec_init
|= RT5682_CODEC_INIT
;
1426 if (strcmp(dai_link
->codecs
->dai_name
, "snd-soc-dummy-dai")) {
1427 if (!(codec_init
& DUMB_CODEC_INIT
)) {
1428 dai_link
->init
= mt8195_dumb_amp_init
;
1429 codec_init
|= DUMB_CODEC_INIT
;
1439 static const unsigned int mt8195_pcm_playback_channels
[] = { 2 };
1440 static const unsigned int mt8195_pcm_capture_channels
[] = { 1, 2 };
1441 static const unsigned int mt8195_pcm_hdmidp_channels
[] = { 2, 4, 6, 8 };
1442 static const unsigned int mt8195_pcm_rates
[] = { 48000 };
1444 static const struct snd_pcm_hw_constraint_list mt8195_rate_constraint
= {
1445 .list
= mt8195_pcm_rates
,
1446 .count
= ARRAY_SIZE(mt8195_pcm_rates
)
1449 static const struct mtk_pcm_constraints_data mt8195_pcm_constraints
[MTK_CONSTRAINT_HDMIDP
+ 1] = {
1450 [MTK_CONSTRAINT_PLAYBACK
] = {
1451 .channels
= &(const struct snd_pcm_hw_constraint_list
) {
1452 .list
= mt8195_pcm_playback_channels
,
1453 .count
= ARRAY_SIZE(mt8195_pcm_playback_channels
)
1455 .rates
= &mt8195_rate_constraint
,
1457 [MTK_CONSTRAINT_CAPTURE
] = {
1458 .channels
= &(const struct snd_pcm_hw_constraint_list
) {
1459 .list
= mt8195_pcm_capture_channels
,
1460 .count
= ARRAY_SIZE(mt8195_pcm_capture_channels
)
1462 .rates
= &mt8195_rate_constraint
,
1464 [MTK_CONSTRAINT_HDMIDP
] = {
1465 .channels
= &(const struct snd_pcm_hw_constraint_list
) {
1466 .list
= mt8195_pcm_hdmidp_channels
,
1467 .count
= ARRAY_SIZE(mt8195_pcm_hdmidp_channels
)
1469 .rates
= &mt8195_rate_constraint
,
1473 static const struct mtk_sof_priv mt8195_sof_priv
= {
1474 .conn_streams
= g_sof_conn_streams
,
1475 .num_streams
= ARRAY_SIZE(g_sof_conn_streams
),
1476 .sof_dai_link_fixup
= mt8195_dai_link_fixup
1479 static const struct mtk_soundcard_pdata mt8195_mt6359_rt1019_rt5682_card
= {
1480 .card_name
= "mt8195_r1019_5682",
1481 .card_data
= &(struct mtk_platform_card_data
) {
1482 .card
= &mt8195_mt6359_soc_card
,
1483 .num_jacks
= MT8195_JACK_MAX
,
1484 .pcm_constraints
= mt8195_pcm_constraints
,
1485 .num_pcm_constraints
= ARRAY_SIZE(mt8195_pcm_constraints
),
1486 .flags
= RT1019_SPEAKER_AMP_PRESENT
1488 .sof_priv
= &mt8195_sof_priv
,
1489 .soc_probe
= mt8195_mt6359_soc_card_probe
1492 static const struct mtk_soundcard_pdata mt8195_mt6359_rt1011_rt5682_card
= {
1493 .card_name
= "mt8195_r1011_5682",
1494 .card_data
= &(struct mtk_platform_card_data
) {
1495 .card
= &mt8195_mt6359_soc_card
,
1496 .num_jacks
= MT8195_JACK_MAX
,
1497 .pcm_constraints
= mt8195_pcm_constraints
,
1498 .num_pcm_constraints
= ARRAY_SIZE(mt8195_pcm_constraints
),
1499 .flags
= RT1011_SPEAKER_AMP_PRESENT
1501 .sof_priv
= &mt8195_sof_priv
,
1502 .soc_probe
= mt8195_mt6359_soc_card_probe
1505 static const struct mtk_soundcard_pdata mt8195_mt6359_max98390_rt5682_card
= {
1506 .card_name
= "mt8195_m98390_r5682",
1507 .card_data
= &(struct mtk_platform_card_data
) {
1508 .card
= &mt8195_mt6359_soc_card
,
1509 .num_jacks
= MT8195_JACK_MAX
,
1510 .pcm_constraints
= mt8195_pcm_constraints
,
1511 .num_pcm_constraints
= ARRAY_SIZE(mt8195_pcm_constraints
),
1512 .flags
= MAX98390_SPEAKER_AMP_PRESENT
1514 .sof_priv
= &mt8195_sof_priv
,
1515 .soc_probe
= mt8195_mt6359_soc_card_probe
1518 static const struct of_device_id mt8195_mt6359_dt_match
[] = {
1520 .compatible
= "mediatek,mt8195_mt6359_rt1019_rt5682",
1521 .data
= &mt8195_mt6359_rt1019_rt5682_card
,
1524 .compatible
= "mediatek,mt8195_mt6359_rt1011_rt5682",
1525 .data
= &mt8195_mt6359_rt1011_rt5682_card
,
1528 .compatible
= "mediatek,mt8195_mt6359_max98390_rt5682",
1529 .data
= &mt8195_mt6359_max98390_rt5682_card
,
1533 MODULE_DEVICE_TABLE(of
, mt8195_mt6359_dt_match
);
1535 static struct platform_driver mt8195_mt6359_driver
= {
1537 .name
= "mt8195_mt6359",
1538 .of_match_table
= mt8195_mt6359_dt_match
,
1539 .pm
= &snd_soc_pm_ops
,
1541 .probe
= mtk_soundcard_common_probe
,
1544 module_platform_driver(mt8195_mt6359_driver
);
1546 /* Module information */
1547 MODULE_DESCRIPTION("MT8195-MT6359 ALSA SoC machine driver");
1548 MODULE_AUTHOR("Trevor Wu <trevor.wu@mediatek.com>");
1549 MODULE_AUTHOR("YC Hung <yc.hung@mediatek.com>");
1550 MODULE_LICENSE("GPL");
1551 MODULE_ALIAS("mt8195_mt6359 soc card");