1 // SPDX-License-Identifier: GPL-2.0
3 * mt8188-mt6359.c -- MT8188-MT6359 ALSA SoC machine driver
5 * Copyright (c) 2022 MediaTek Inc.
6 * Author: Trevor Wu <trevor.wu@mediatek.com>
9 #include <linux/bitfield.h>
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/soc.h>
17 #include "mt8188-afe-common.h"
18 #include "../../codecs/nau8825.h"
19 #include "../../codecs/mt6359.h"
20 #include "../../codecs/rt5682.h"
21 #include "../common/mtk-afe-platform-driver.h"
22 #include "../common/mtk-soundcard-driver.h"
23 #include "../common/mtk-dsp-sof-common.h"
24 #include "../common/mtk-soc-card.h"
26 #define CKSYS_AUD_TOP_CFG 0x032c
27 #define RG_TEST_ON BIT(0)
28 #define RG_TEST_TYPE BIT(2)
29 #define CKSYS_AUD_TOP_MON 0x0330
30 #define TEST_MISO_COUNT_1 GENMASK(3, 0)
31 #define TEST_MISO_COUNT_2 GENMASK(7, 4)
32 #define TEST_MISO_DONE_1 BIT(28)
33 #define TEST_MISO_DONE_2 BIT(29)
35 #define NAU8825_HS_PRESENT BIT(0)
36 #define RT5682S_HS_PRESENT BIT(1)
37 #define ES8326_HS_PRESENT BIT(2)
38 #define MAX98390_TWO_AMP BIT(3)
42 #define MAX98390_CODEC_DAI "max98390-aif1"
43 #define MAX98390_DEV0_NAME "max98390.0-0038" /* rear right */
44 #define MAX98390_DEV1_NAME "max98390.0-0039" /* rear left */
45 #define MAX98390_DEV2_NAME "max98390.0-003a" /* front right */
46 #define MAX98390_DEV3_NAME "max98390.0-003b" /* front left */
51 #define NAU8825_CODEC_DAI "nau8825-hifi"
56 #define ES8326_CODEC_DAI "ES8326 HiFi"
58 #define SOF_DMA_DL2 "SOF_DMA_DL2"
59 #define SOF_DMA_DL3 "SOF_DMA_DL3"
60 #define SOF_DMA_UL4 "SOF_DMA_UL4"
61 #define SOF_DMA_UL5 "SOF_DMA_UL5"
63 #define RT5682S_CODEC_DAI "rt5682s-aif1"
66 SND_SOC_DAILINK_DEFS(playback2
,
67 DAILINK_COMP_ARRAY(COMP_CPU("DL2")),
68 DAILINK_COMP_ARRAY(COMP_DUMMY()),
69 DAILINK_COMP_ARRAY(COMP_EMPTY()));
71 SND_SOC_DAILINK_DEFS(playback3
,
72 DAILINK_COMP_ARRAY(COMP_CPU("DL3")),
73 DAILINK_COMP_ARRAY(COMP_DUMMY()),
74 DAILINK_COMP_ARRAY(COMP_EMPTY()));
76 SND_SOC_DAILINK_DEFS(playback6
,
77 DAILINK_COMP_ARRAY(COMP_CPU("DL6")),
78 DAILINK_COMP_ARRAY(COMP_DUMMY()),
79 DAILINK_COMP_ARRAY(COMP_EMPTY()));
81 SND_SOC_DAILINK_DEFS(playback7
,
82 DAILINK_COMP_ARRAY(COMP_CPU("DL7")),
83 DAILINK_COMP_ARRAY(COMP_DUMMY()),
84 DAILINK_COMP_ARRAY(COMP_EMPTY()));
86 SND_SOC_DAILINK_DEFS(playback8
,
87 DAILINK_COMP_ARRAY(COMP_CPU("DL8")),
88 DAILINK_COMP_ARRAY(COMP_DUMMY()),
89 DAILINK_COMP_ARRAY(COMP_EMPTY()));
91 SND_SOC_DAILINK_DEFS(playback10
,
92 DAILINK_COMP_ARRAY(COMP_CPU("DL10")),
93 DAILINK_COMP_ARRAY(COMP_DUMMY()),
94 DAILINK_COMP_ARRAY(COMP_EMPTY()));
96 SND_SOC_DAILINK_DEFS(playback11
,
97 DAILINK_COMP_ARRAY(COMP_CPU("DL11")),
98 DAILINK_COMP_ARRAY(COMP_DUMMY()),
99 DAILINK_COMP_ARRAY(COMP_EMPTY()));
101 SND_SOC_DAILINK_DEFS(capture1
,
102 DAILINK_COMP_ARRAY(COMP_CPU("UL1")),
103 DAILINK_COMP_ARRAY(COMP_DUMMY()),
104 DAILINK_COMP_ARRAY(COMP_EMPTY()));
106 SND_SOC_DAILINK_DEFS(capture2
,
107 DAILINK_COMP_ARRAY(COMP_CPU("UL2")),
108 DAILINK_COMP_ARRAY(COMP_DUMMY()),
109 DAILINK_COMP_ARRAY(COMP_EMPTY()));
111 SND_SOC_DAILINK_DEFS(capture3
,
112 DAILINK_COMP_ARRAY(COMP_CPU("UL3")),
113 DAILINK_COMP_ARRAY(COMP_DUMMY()),
114 DAILINK_COMP_ARRAY(COMP_EMPTY()));
116 SND_SOC_DAILINK_DEFS(capture4
,
117 DAILINK_COMP_ARRAY(COMP_CPU("UL4")),
118 DAILINK_COMP_ARRAY(COMP_DUMMY()),
119 DAILINK_COMP_ARRAY(COMP_EMPTY()));
121 SND_SOC_DAILINK_DEFS(capture5
,
122 DAILINK_COMP_ARRAY(COMP_CPU("UL5")),
123 DAILINK_COMP_ARRAY(COMP_DUMMY()),
124 DAILINK_COMP_ARRAY(COMP_EMPTY()));
126 SND_SOC_DAILINK_DEFS(capture6
,
127 DAILINK_COMP_ARRAY(COMP_CPU("UL6")),
128 DAILINK_COMP_ARRAY(COMP_DUMMY()),
129 DAILINK_COMP_ARRAY(COMP_EMPTY()));
131 SND_SOC_DAILINK_DEFS(capture8
,
132 DAILINK_COMP_ARRAY(COMP_CPU("UL8")),
133 DAILINK_COMP_ARRAY(COMP_DUMMY()),
134 DAILINK_COMP_ARRAY(COMP_EMPTY()));
136 SND_SOC_DAILINK_DEFS(capture9
,
137 DAILINK_COMP_ARRAY(COMP_CPU("UL9")),
138 DAILINK_COMP_ARRAY(COMP_DUMMY()),
139 DAILINK_COMP_ARRAY(COMP_EMPTY()));
141 SND_SOC_DAILINK_DEFS(capture10
,
142 DAILINK_COMP_ARRAY(COMP_CPU("UL10")),
143 DAILINK_COMP_ARRAY(COMP_DUMMY()),
144 DAILINK_COMP_ARRAY(COMP_EMPTY()));
147 SND_SOC_DAILINK_DEFS(dl_src
,
148 DAILINK_COMP_ARRAY(COMP_CPU("DL_SRC")),
149 DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
150 "mt6359-snd-codec-aif1")),
151 DAILINK_COMP_ARRAY(COMP_EMPTY()));
153 SND_SOC_DAILINK_DEFS(dptx
,
154 DAILINK_COMP_ARRAY(COMP_CPU("DPTX")),
155 DAILINK_COMP_ARRAY(COMP_DUMMY()),
156 DAILINK_COMP_ARRAY(COMP_EMPTY()));
158 SND_SOC_DAILINK_DEFS(etdm1_in
,
159 DAILINK_COMP_ARRAY(COMP_CPU("ETDM1_IN")),
160 DAILINK_COMP_ARRAY(COMP_DUMMY()),
161 DAILINK_COMP_ARRAY(COMP_EMPTY()));
163 SND_SOC_DAILINK_DEFS(etdm2_in
,
164 DAILINK_COMP_ARRAY(COMP_CPU("ETDM2_IN")),
165 DAILINK_COMP_ARRAY(COMP_DUMMY()),
166 DAILINK_COMP_ARRAY(COMP_EMPTY()));
168 SND_SOC_DAILINK_DEFS(etdm1_out
,
169 DAILINK_COMP_ARRAY(COMP_CPU("ETDM1_OUT")),
170 DAILINK_COMP_ARRAY(COMP_DUMMY()),
171 DAILINK_COMP_ARRAY(COMP_EMPTY()));
173 SND_SOC_DAILINK_DEFS(etdm2_out
,
174 DAILINK_COMP_ARRAY(COMP_CPU("ETDM2_OUT")),
175 DAILINK_COMP_ARRAY(COMP_DUMMY()),
176 DAILINK_COMP_ARRAY(COMP_EMPTY()));
178 SND_SOC_DAILINK_DEFS(etdm3_out
,
179 DAILINK_COMP_ARRAY(COMP_CPU("ETDM3_OUT")),
180 DAILINK_COMP_ARRAY(COMP_DUMMY()),
181 DAILINK_COMP_ARRAY(COMP_EMPTY()));
183 SND_SOC_DAILINK_DEFS(pcm1
,
184 DAILINK_COMP_ARRAY(COMP_CPU("PCM1")),
185 DAILINK_COMP_ARRAY(COMP_DUMMY()),
186 DAILINK_COMP_ARRAY(COMP_EMPTY()));
188 SND_SOC_DAILINK_DEFS(ul_src
,
189 DAILINK_COMP_ARRAY(COMP_CPU("UL_SRC")),
190 DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
191 "mt6359-snd-codec-aif1")),
192 DAILINK_COMP_ARRAY(COMP_EMPTY()));
194 SND_SOC_DAILINK_DEFS(AFE_SOF_DL2
,
195 DAILINK_COMP_ARRAY(COMP_CPU("SOF_DL2")),
196 DAILINK_COMP_ARRAY(COMP_DUMMY()),
197 DAILINK_COMP_ARRAY(COMP_EMPTY()));
199 SND_SOC_DAILINK_DEFS(AFE_SOF_DL3
,
200 DAILINK_COMP_ARRAY(COMP_CPU("SOF_DL3")),
201 DAILINK_COMP_ARRAY(COMP_DUMMY()),
202 DAILINK_COMP_ARRAY(COMP_EMPTY()));
204 SND_SOC_DAILINK_DEFS(AFE_SOF_UL4
,
205 DAILINK_COMP_ARRAY(COMP_CPU("SOF_UL4")),
206 DAILINK_COMP_ARRAY(COMP_DUMMY()),
207 DAILINK_COMP_ARRAY(COMP_EMPTY()));
209 SND_SOC_DAILINK_DEFS(AFE_SOF_UL5
,
210 DAILINK_COMP_ARRAY(COMP_CPU("SOF_UL5")),
211 DAILINK_COMP_ARRAY(COMP_DUMMY()),
212 DAILINK_COMP_ARRAY(COMP_EMPTY()));
214 static const struct sof_conn_stream g_sof_conn_streams
[] = {
216 .sof_link
= "AFE_SOF_DL2",
217 .sof_dma
= SOF_DMA_DL2
,
218 .stream_dir
= SNDRV_PCM_STREAM_PLAYBACK
221 .sof_link
= "AFE_SOF_DL3",
222 .sof_dma
= SOF_DMA_DL3
,
223 .stream_dir
= SNDRV_PCM_STREAM_PLAYBACK
226 .sof_link
= "AFE_SOF_UL4",
227 .sof_dma
= SOF_DMA_UL4
,
228 .stream_dir
= SNDRV_PCM_STREAM_CAPTURE
231 .sof_link
= "AFE_SOF_UL5",
232 .sof_dma
= SOF_DMA_UL5
,
233 .stream_dir
= SNDRV_PCM_STREAM_CAPTURE
244 static struct snd_soc_jack_pin mt8188_hdmi_jack_pins
[] = {
247 .mask
= SND_JACK_LINEOUT
,
251 static struct snd_soc_jack_pin mt8188_dp_jack_pins
[] = {
254 .mask
= SND_JACK_LINEOUT
,
258 static struct snd_soc_jack_pin nau8825_jack_pins
[] = {
260 .pin
= "Headphone Jack",
261 .mask
= SND_JACK_HEADPHONE
,
264 .pin
= "Headset Mic",
265 .mask
= SND_JACK_MICROPHONE
,
269 static const struct snd_kcontrol_new mt8188_dumb_spk_controls
[] = {
270 SOC_DAPM_PIN_SWITCH("Ext Spk"),
273 static const struct snd_soc_dapm_widget mt8188_dumb_spk_widgets
[] = {
274 SND_SOC_DAPM_SPK("Ext Spk", NULL
),
277 static const struct snd_kcontrol_new mt8188_dual_spk_controls
[] = {
278 SOC_DAPM_PIN_SWITCH("Left Spk"),
279 SOC_DAPM_PIN_SWITCH("Right Spk"),
282 static const struct snd_soc_dapm_widget mt8188_dual_spk_widgets
[] = {
283 SND_SOC_DAPM_SPK("Left Spk", NULL
),
284 SND_SOC_DAPM_SPK("Right Spk", NULL
),
287 static const struct snd_kcontrol_new mt8188_rear_spk_controls
[] = {
288 SOC_DAPM_PIN_SWITCH("Rear Left Spk"),
289 SOC_DAPM_PIN_SWITCH("Rear Right Spk"),
292 static const struct snd_soc_dapm_widget mt8188_rear_spk_widgets
[] = {
293 SND_SOC_DAPM_SPK("Rear Left Spk", NULL
),
294 SND_SOC_DAPM_SPK("Rear Right Spk", NULL
),
297 static const struct snd_soc_dapm_widget mt8188_mt6359_widgets
[] = {
298 SND_SOC_DAPM_HP("Headphone", NULL
),
299 SND_SOC_DAPM_MIC("Headset Mic", NULL
),
300 SND_SOC_DAPM_SINK("HDMI"),
301 SND_SOC_DAPM_SINK("DP"),
302 SND_SOC_DAPM_MIXER(SOF_DMA_DL2
, SND_SOC_NOPM
, 0, 0, NULL
, 0),
303 SND_SOC_DAPM_MIXER(SOF_DMA_DL3
, SND_SOC_NOPM
, 0, 0, NULL
, 0),
304 SND_SOC_DAPM_MIXER(SOF_DMA_UL4
, SND_SOC_NOPM
, 0, 0, NULL
, 0),
305 SND_SOC_DAPM_MIXER(SOF_DMA_UL5
, SND_SOC_NOPM
, 0, 0, NULL
, 0),
307 /* dynamic pinctrl */
308 SND_SOC_DAPM_PINCTRL("ETDM_SPK_PIN", "aud_etdm_spk_on", "aud_etdm_spk_off"),
309 SND_SOC_DAPM_PINCTRL("ETDM_HP_PIN", "aud_etdm_hp_on", "aud_etdm_hp_off"),
310 SND_SOC_DAPM_PINCTRL("MTKAIF_PIN", "aud_mtkaif_on", "aud_mtkaif_off"),
313 static const struct snd_kcontrol_new mt8188_mt6359_controls
[] = {
314 SOC_DAPM_PIN_SWITCH("Headphone"),
315 SOC_DAPM_PIN_SWITCH("Headset Mic"),
318 static const struct snd_soc_dapm_widget mt8188_nau8825_widgets
[] = {
319 SND_SOC_DAPM_HP("Headphone Jack", NULL
),
322 static const struct snd_kcontrol_new mt8188_nau8825_controls
[] = {
323 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
326 static const struct snd_soc_dapm_route mt8188_mt6359_routes
[] = {
328 {SOF_DMA_UL4
, NULL
, "O034"},
329 {SOF_DMA_UL4
, NULL
, "O035"},
330 {SOF_DMA_UL5
, NULL
, "O036"},
331 {SOF_DMA_UL5
, NULL
, "O037"},
333 {"I070", NULL
, SOF_DMA_DL2
},
334 {"I071", NULL
, SOF_DMA_DL2
},
335 {"I020", NULL
, SOF_DMA_DL3
},
336 {"I021", NULL
, SOF_DMA_DL3
},
339 static int mt8188_mt6359_mtkaif_calibration(struct snd_soc_pcm_runtime
*rtd
)
341 struct snd_soc_component
*cmpnt_afe
=
342 snd_soc_rtdcom_lookup(rtd
, AFE_PCM_NAME
);
343 struct snd_soc_component
*cmpnt_codec
=
344 snd_soc_rtd_to_codec(rtd
, 0)->component
;
345 struct snd_soc_dapm_widget
*pin_w
= NULL
, *w
;
346 struct mtk_base_afe
*afe
;
347 struct mt8188_afe_private
*afe_priv
;
348 struct mtkaif_param
*param
;
349 int chosen_phase_1
, chosen_phase_2
;
350 int prev_cycle_1
, prev_cycle_2
;
351 u8 test_done_1
, test_done_2
;
352 int cycle_1
, cycle_2
;
353 int mtkaif_chosen_phase
[MT8188_MTKAIF_MISO_NUM
];
354 int mtkaif_phase_cycle
[MT8188_MTKAIF_MISO_NUM
];
355 int mtkaif_calibration_num_phase
;
356 bool mtkaif_calibration_ok
;
365 afe
= snd_soc_component_get_drvdata(cmpnt_afe
);
366 afe_priv
= afe
->platform_priv
;
367 param
= &afe_priv
->mtkaif_params
;
369 dev_dbg(afe
->dev
, "%s(), start\n", __func__
);
371 param
->mtkaif_calibration_ok
= false;
372 for (i
= 0; i
< MT8188_MTKAIF_MISO_NUM
; i
++) {
373 param
->mtkaif_chosen_phase
[i
] = -1;
374 param
->mtkaif_phase_cycle
[i
] = 0;
375 mtkaif_chosen_phase
[i
] = -1;
376 mtkaif_phase_cycle
[i
] = 0;
379 if (IS_ERR(afe_priv
->topckgen
)) {
380 dev_info(afe
->dev
, "%s() Cannot find topckgen controller\n",
385 for_each_card_widgets(rtd
->card
, w
) {
386 if (!strcmp(w
->name
, "MTKAIF_PIN")) {
393 dapm_pinctrl_event(pin_w
, NULL
, SND_SOC_DAPM_PRE_PMU
);
395 dev_dbg(afe
->dev
, "%s(), no pinmux widget, please check if default on\n", __func__
);
397 pm_runtime_get_sync(afe
->dev
);
398 mt6359_mtkaif_calibration_enable(cmpnt_codec
);
400 /* set test type to synchronizer pulse */
401 regmap_write(afe_priv
->topckgen
, CKSYS_AUD_TOP_CFG
, RG_TEST_TYPE
);
402 mtkaif_calibration_num_phase
= 42; /* mt6359: 0 ~ 42 */
403 mtkaif_calibration_ok
= true;
406 phase
<= mtkaif_calibration_num_phase
&& mtkaif_calibration_ok
;
408 mt6359_set_mtkaif_calibration_phase(cmpnt_codec
,
409 phase
, phase
, phase
);
411 regmap_set_bits(afe_priv
->topckgen
, CKSYS_AUD_TOP_CFG
, RG_TEST_ON
);
420 while (!(test_done_1
& test_done_2
)) {
421 regmap_read(afe_priv
->topckgen
,
422 CKSYS_AUD_TOP_MON
, &monitor
);
423 test_done_1
= FIELD_GET(TEST_MISO_DONE_1
, monitor
);
424 test_done_2
= FIELD_GET(TEST_MISO_DONE_2
, monitor
);
426 if (test_done_1
== 1)
427 cycle_1
= FIELD_GET(TEST_MISO_COUNT_1
, monitor
);
429 if (test_done_2
== 1)
430 cycle_2
= FIELD_GET(TEST_MISO_COUNT_2
, monitor
);
432 /* handle if never test done */
433 if (++counter
> 10000) {
434 dev_err(afe
->dev
, "%s(), test fail, cycle_1 %d, cycle_2 %d, monitor 0x%x\n",
435 __func__
, cycle_1
, cycle_2
, monitor
);
436 mtkaif_calibration_ok
= false;
442 prev_cycle_1
= cycle_1
;
443 prev_cycle_2
= cycle_2
;
446 if (cycle_1
!= prev_cycle_1
&&
447 mtkaif_chosen_phase
[MT8188_MTKAIF_MISO_0
] < 0) {
448 mtkaif_chosen_phase
[MT8188_MTKAIF_MISO_0
] = phase
- 1;
449 mtkaif_phase_cycle
[MT8188_MTKAIF_MISO_0
] = prev_cycle_1
;
452 if (cycle_2
!= prev_cycle_2
&&
453 mtkaif_chosen_phase
[MT8188_MTKAIF_MISO_1
] < 0) {
454 mtkaif_chosen_phase
[MT8188_MTKAIF_MISO_1
] = phase
- 1;
455 mtkaif_phase_cycle
[MT8188_MTKAIF_MISO_1
] = prev_cycle_2
;
458 regmap_clear_bits(afe_priv
->topckgen
, CKSYS_AUD_TOP_CFG
, RG_TEST_ON
);
460 if (mtkaif_chosen_phase
[MT8188_MTKAIF_MISO_0
] >= 0 &&
461 mtkaif_chosen_phase
[MT8188_MTKAIF_MISO_1
] >= 0)
465 if (mtkaif_chosen_phase
[MT8188_MTKAIF_MISO_0
] < 0) {
466 mtkaif_calibration_ok
= false;
469 chosen_phase_1
= mtkaif_chosen_phase
[MT8188_MTKAIF_MISO_0
];
472 if (mtkaif_chosen_phase
[MT8188_MTKAIF_MISO_1
] < 0) {
473 mtkaif_calibration_ok
= false;
476 chosen_phase_2
= mtkaif_chosen_phase
[MT8188_MTKAIF_MISO_1
];
479 mt6359_set_mtkaif_calibration_phase(cmpnt_codec
,
484 mt6359_mtkaif_calibration_disable(cmpnt_codec
);
485 pm_runtime_put(afe
->dev
);
487 param
->mtkaif_calibration_ok
= mtkaif_calibration_ok
;
488 param
->mtkaif_chosen_phase
[MT8188_MTKAIF_MISO_0
] = chosen_phase_1
;
489 param
->mtkaif_chosen_phase
[MT8188_MTKAIF_MISO_1
] = chosen_phase_2
;
491 for (i
= 0; i
< MT8188_MTKAIF_MISO_NUM
; i
++)
492 param
->mtkaif_phase_cycle
[i
] = mtkaif_phase_cycle
[i
];
495 dapm_pinctrl_event(pin_w
, NULL
, SND_SOC_DAPM_POST_PMD
);
497 dev_dbg(afe
->dev
, "%s(), end, calibration ok %d\n",
498 __func__
, param
->mtkaif_calibration_ok
);
503 static int mt8188_mt6359_init(struct snd_soc_pcm_runtime
*rtd
)
505 struct snd_soc_component
*cmpnt_codec
=
506 snd_soc_rtd_to_codec(rtd
, 0)->component
;
508 /* set mtkaif protocol */
509 mt6359_set_mtkaif_protocol(cmpnt_codec
,
510 MT6359_MTKAIF_PROTOCOL_2_CLK_P2
);
512 /* mtkaif calibration */
513 mt8188_mt6359_mtkaif_calibration(rtd
);
537 DAI_LINK_ETDM1_IN_BE
,
538 DAI_LINK_ETDM2_IN_BE
,
539 DAI_LINK_ETDM1_OUT_BE
,
540 DAI_LINK_ETDM2_OUT_BE
,
541 DAI_LINK_ETDM3_OUT_BE
,
544 DAI_LINK_REGULAR_LAST
= DAI_LINK_UL_SRC_BE
,
546 DAI_LINK_SOF_DL2_BE
= DAI_LINK_SOF_START
,
550 DAI_LINK_SOF_END
= DAI_LINK_SOF_UL5_BE
,
553 #define DAI_LINK_REGULAR_NUM (DAI_LINK_REGULAR_LAST + 1)
555 static int mt8188_dptx_hw_params(struct snd_pcm_substream
*substream
,
556 struct snd_pcm_hw_params
*params
)
558 struct snd_soc_pcm_runtime
*rtd
= snd_soc_substream_to_rtd(substream
);
559 unsigned int rate
= params_rate(params
);
560 unsigned int mclk_fs_ratio
= 256;
561 unsigned int mclk_fs
= rate
* mclk_fs_ratio
;
562 struct snd_soc_dai
*dai
= snd_soc_rtd_to_cpu(rtd
, 0);
564 return snd_soc_dai_set_sysclk(dai
, 0, mclk_fs
, SND_SOC_CLOCK_OUT
);
567 static const struct snd_soc_ops mt8188_dptx_ops
= {
568 .hw_params
= mt8188_dptx_hw_params
,
571 static int mt8188_dptx_hw_params_fixup(struct snd_soc_pcm_runtime
*rtd
,
572 struct snd_pcm_hw_params
*params
)
574 /* fix BE i2s format to 32bit, clean param mask first */
575 snd_mask_reset_range(hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
),
576 0, (__force
unsigned int)SNDRV_PCM_FORMAT_LAST
);
578 params_set_format(params
, SNDRV_PCM_FORMAT_S32_LE
);
583 static int mt8188_hdmi_codec_init(struct snd_soc_pcm_runtime
*rtd
)
585 struct mtk_soc_card_data
*soc_card_data
= snd_soc_card_get_drvdata(rtd
->card
);
586 struct snd_soc_jack
*jack
= &soc_card_data
->card_data
->jacks
[MT8188_JACK_HDMI
];
587 struct snd_soc_component
*component
= snd_soc_rtd_to_codec(rtd
, 0)->component
;
590 ret
= snd_soc_card_jack_new_pins(rtd
->card
, "HDMI Jack",
591 SND_JACK_LINEOUT
, jack
,
592 mt8188_hdmi_jack_pins
,
593 ARRAY_SIZE(mt8188_hdmi_jack_pins
));
595 dev_err(rtd
->dev
, "%s, new jack failed: %d\n", __func__
, ret
);
599 ret
= snd_soc_component_set_jack(component
, jack
, NULL
);
601 dev_err(rtd
->dev
, "%s, set jack failed on %s (ret=%d)\n",
602 __func__
, component
->name
, ret
);
609 static int mt8188_dptx_codec_init(struct snd_soc_pcm_runtime
*rtd
)
611 struct mtk_soc_card_data
*soc_card_data
= snd_soc_card_get_drvdata(rtd
->card
);
612 struct snd_soc_jack
*jack
= &soc_card_data
->card_data
->jacks
[MT8188_JACK_DP
];
613 struct snd_soc_component
*component
= snd_soc_rtd_to_codec(rtd
, 0)->component
;
616 ret
= snd_soc_card_jack_new_pins(rtd
->card
, "DP Jack", SND_JACK_LINEOUT
,
617 jack
, mt8188_dp_jack_pins
,
618 ARRAY_SIZE(mt8188_dp_jack_pins
));
620 dev_err(rtd
->dev
, "%s, new jack failed: %d\n", __func__
, ret
);
624 ret
= snd_soc_component_set_jack(component
, jack
, NULL
);
626 dev_err(rtd
->dev
, "%s, set jack failed on %s (ret=%d)\n",
627 __func__
, component
->name
, ret
);
634 static int mt8188_dumb_amp_init(struct snd_soc_pcm_runtime
*rtd
)
636 struct snd_soc_card
*card
= rtd
->card
;
639 ret
= snd_soc_dapm_new_controls(&card
->dapm
, mt8188_dumb_spk_widgets
,
640 ARRAY_SIZE(mt8188_dumb_spk_widgets
));
642 dev_err(rtd
->dev
, "unable to add Dumb Speaker dapm, ret %d\n", ret
);
646 ret
= snd_soc_add_card_controls(card
, mt8188_dumb_spk_controls
,
647 ARRAY_SIZE(mt8188_dumb_spk_controls
));
649 dev_err(rtd
->dev
, "unable to add Dumb card controls, ret %d\n", ret
);
656 static int mt8188_max98390_hw_params(struct snd_pcm_substream
*substream
,
657 struct snd_pcm_hw_params
*params
)
659 struct snd_soc_pcm_runtime
*rtd
= snd_soc_substream_to_rtd(substream
);
660 unsigned int bit_width
= params_width(params
);
661 struct snd_soc_dai
*cpu_dai
= snd_soc_rtd_to_cpu(rtd
, 0);
662 struct snd_soc_dai
*codec_dai
;
665 snd_soc_dai_set_tdm_slot(cpu_dai
, 0xf, 0xf, 4, bit_width
);
667 for_each_rtd_codec_dais(rtd
, i
, codec_dai
) {
668 if (!strcmp(codec_dai
->component
->name
, MAX98390_DEV0_NAME
))
669 snd_soc_dai_set_tdm_slot(codec_dai
, 0x8, 0x3, 4, bit_width
);
671 if (!strcmp(codec_dai
->component
->name
, MAX98390_DEV1_NAME
))
672 snd_soc_dai_set_tdm_slot(codec_dai
, 0x4, 0x3, 4, bit_width
);
674 if (!strcmp(codec_dai
->component
->name
, MAX98390_DEV2_NAME
))
675 snd_soc_dai_set_tdm_slot(codec_dai
, 0x2, 0x3, 4, bit_width
);
677 if (!strcmp(codec_dai
->component
->name
, MAX98390_DEV3_NAME
))
678 snd_soc_dai_set_tdm_slot(codec_dai
, 0x1, 0x3, 4, bit_width
);
683 static const struct snd_soc_ops mt8188_max98390_ops
= {
684 .hw_params
= mt8188_max98390_hw_params
,
687 static int mt8188_max98390_codec_init(struct snd_soc_pcm_runtime
*rtd
)
689 struct snd_soc_card
*card
= rtd
->card
;
692 /* add regular speakers dapm route */
693 ret
= snd_soc_dapm_new_controls(&card
->dapm
, mt8188_dual_spk_widgets
,
694 ARRAY_SIZE(mt8188_dual_spk_widgets
));
696 dev_err(rtd
->dev
, "unable to add Left/Right Speaker widget, ret %d\n", ret
);
700 ret
= snd_soc_add_card_controls(card
, mt8188_dual_spk_controls
,
701 ARRAY_SIZE(mt8188_dual_spk_controls
));
703 dev_err(rtd
->dev
, "unable to add Left/Right card controls, ret %d\n", ret
);
707 if (rtd
->dai_link
->num_codecs
<= 2)
710 /* add widgets/controls/dapm for rear speakers */
711 ret
= snd_soc_dapm_new_controls(&card
->dapm
, mt8188_rear_spk_widgets
,
712 ARRAY_SIZE(mt8188_rear_spk_widgets
));
714 dev_err(rtd
->dev
, "unable to add Rear Speaker widget, ret %d\n", ret
);
715 /* Don't need to add routes if widget addition failed */
719 ret
= snd_soc_add_card_controls(card
, mt8188_rear_spk_controls
,
720 ARRAY_SIZE(mt8188_rear_spk_controls
));
722 dev_err(rtd
->dev
, "unable to add Rear card controls, ret %d\n", ret
);
729 static int mt8188_headset_codec_init(struct snd_soc_pcm_runtime
*rtd
)
731 struct snd_soc_card
*card
= rtd
->card
;
732 struct mtk_soc_card_data
*soc_card_data
= snd_soc_card_get_drvdata(rtd
->card
);
733 struct snd_soc_jack
*jack
= &soc_card_data
->card_data
->jacks
[MT8188_JACK_HEADSET
];
734 struct snd_soc_component
*component
= snd_soc_rtd_to_codec(rtd
, 0)->component
;
735 struct mtk_platform_card_data
*card_data
= soc_card_data
->card_data
;
738 ret
= snd_soc_dapm_new_controls(&card
->dapm
, mt8188_nau8825_widgets
,
739 ARRAY_SIZE(mt8188_nau8825_widgets
));
741 dev_err(rtd
->dev
, "unable to add nau8825 card widget, ret %d\n", ret
);
745 ret
= snd_soc_add_card_controls(card
, mt8188_nau8825_controls
,
746 ARRAY_SIZE(mt8188_nau8825_controls
));
748 dev_err(rtd
->dev
, "unable to add nau8825 card controls, ret %d\n", ret
);
752 ret
= snd_soc_card_jack_new_pins(rtd
->card
, "Headset Jack",
753 SND_JACK_HEADSET
| SND_JACK_BTN_0
|
754 SND_JACK_BTN_1
| SND_JACK_BTN_2
|
758 ARRAY_SIZE(nau8825_jack_pins
));
760 dev_err(rtd
->dev
, "Headset Jack creation failed: %d\n", ret
);
764 if (card_data
->flags
& ES8326_HS_PRESENT
) {
765 snd_jack_set_key(jack
->jack
, SND_JACK_BTN_0
, KEY_PLAYPAUSE
);
766 snd_jack_set_key(jack
->jack
, SND_JACK_BTN_1
, KEY_VOLUMEUP
);
767 snd_jack_set_key(jack
->jack
, SND_JACK_BTN_2
, KEY_VOLUMEDOWN
);
768 snd_jack_set_key(jack
->jack
, SND_JACK_BTN_3
, KEY_VOICECOMMAND
);
770 snd_jack_set_key(jack
->jack
, SND_JACK_BTN_0
, KEY_PLAYPAUSE
);
771 snd_jack_set_key(jack
->jack
, SND_JACK_BTN_1
, KEY_VOICECOMMAND
);
772 snd_jack_set_key(jack
->jack
, SND_JACK_BTN_2
, KEY_VOLUMEUP
);
773 snd_jack_set_key(jack
->jack
, SND_JACK_BTN_3
, KEY_VOLUMEDOWN
);
776 ret
= snd_soc_component_set_jack(component
, jack
, NULL
);
779 dev_err(rtd
->dev
, "Headset Jack call-back failed: %d\n", ret
);
786 static void mt8188_headset_codec_exit(struct snd_soc_pcm_runtime
*rtd
)
788 struct snd_soc_component
*component
= snd_soc_rtd_to_codec(rtd
, 0)->component
;
790 snd_soc_component_set_jack(component
, NULL
, NULL
);
794 static int mt8188_nau8825_hw_params(struct snd_pcm_substream
*substream
,
795 struct snd_pcm_hw_params
*params
)
797 struct snd_soc_pcm_runtime
*rtd
= snd_soc_substream_to_rtd(substream
);
798 struct snd_soc_dai
*codec_dai
= snd_soc_rtd_to_codec(rtd
, 0);
799 unsigned int rate
= params_rate(params
);
800 unsigned int bit_width
= params_width(params
);
803 clk_freq
= rate
* 2 * bit_width
;
805 /* Configure clock for codec */
806 ret
= snd_soc_dai_set_sysclk(codec_dai
, NAU8825_CLK_FLL_BLK
, 0,
809 dev_err(codec_dai
->dev
, "can't set BCLK clock %d\n", ret
);
813 /* Configure pll for codec */
814 ret
= snd_soc_dai_set_pll(codec_dai
, 0, 0, clk_freq
,
815 params_rate(params
) * 256);
817 dev_err(codec_dai
->dev
, "can't set BCLK: %d\n", ret
);
824 static const struct snd_soc_ops mt8188_nau8825_ops
= {
825 .hw_params
= mt8188_nau8825_hw_params
,
828 static int mt8188_rt5682s_i2s_hw_params(struct snd_pcm_substream
*substream
,
829 struct snd_pcm_hw_params
*params
)
831 struct snd_soc_pcm_runtime
*rtd
= snd_soc_substream_to_rtd(substream
);
832 struct snd_soc_card
*card
= rtd
->card
;
833 struct snd_soc_dai
*cpu_dai
= snd_soc_rtd_to_cpu(rtd
, 0);
834 struct snd_soc_dai
*codec_dai
= snd_soc_rtd_to_codec(rtd
, 0);
835 unsigned int rate
= params_rate(params
);
839 bitwidth
= snd_pcm_format_width(params_format(params
));
841 dev_err(card
->dev
, "invalid bit width: %d\n", bitwidth
);
845 ret
= snd_soc_dai_set_tdm_slot(codec_dai
, 0x00, 0x0, 0x2, bitwidth
);
847 dev_err(card
->dev
, "failed to set tdm slot\n");
851 ret
= snd_soc_dai_set_pll(codec_dai
, RT5682_PLL1
, RT5682_PLL1_S_BCLK1
,
852 rate
* 32, rate
* 512);
854 dev_err(card
->dev
, "failed to set pll\n");
858 ret
= snd_soc_dai_set_sysclk(codec_dai
, RT5682_SCLK_S_PLL1
,
859 rate
* 512, SND_SOC_CLOCK_IN
);
861 dev_err(card
->dev
, "failed to set sysclk\n");
865 return snd_soc_dai_set_sysclk(cpu_dai
, 0, rate
* 128,
869 static const struct snd_soc_ops mt8188_rt5682s_i2s_ops
= {
870 .hw_params
= mt8188_rt5682s_i2s_hw_params
,
873 static int mt8188_sof_be_hw_params(struct snd_pcm_substream
*substream
,
874 struct snd_pcm_hw_params
*params
)
876 struct snd_soc_pcm_runtime
*rtd
= snd_soc_substream_to_rtd(substream
);
877 struct snd_soc_component
*cmpnt_afe
= NULL
;
878 struct snd_soc_pcm_runtime
*runtime
;
880 /* find afe component */
881 for_each_card_rtds(rtd
->card
, runtime
) {
882 cmpnt_afe
= snd_soc_rtdcom_lookup(runtime
, AFE_PCM_NAME
);
887 if (cmpnt_afe
&& !pm_runtime_active(cmpnt_afe
->dev
)) {
888 dev_err(rtd
->dev
, "afe pm runtime is not active!!\n");
895 static const struct snd_soc_ops mt8188_sof_be_ops
= {
896 .hw_params
= mt8188_sof_be_hw_params
,
899 static int mt8188_es8326_hw_params(struct snd_pcm_substream
*substream
,
900 struct snd_pcm_hw_params
*params
)
902 struct snd_soc_pcm_runtime
*rtd
= snd_soc_substream_to_rtd(substream
);
903 struct snd_soc_dai
*cpu_dai
= snd_soc_rtd_to_cpu(rtd
, 0);
904 struct snd_soc_dai
*codec_dai
= snd_soc_rtd_to_codec(rtd
, 0);
905 unsigned int rate
= params_rate(params
);
908 /* Configure MCLK for codec */
909 ret
= snd_soc_dai_set_sysclk(codec_dai
, 0, rate
* 256, SND_SOC_CLOCK_IN
);
911 dev_err(codec_dai
->dev
, "can't set MCLK %d\n", ret
);
915 /* Configure MCLK for cpu */
916 return snd_soc_dai_set_sysclk(cpu_dai
, 0, rate
* 256, SND_SOC_CLOCK_OUT
);
919 static const struct snd_soc_ops mt8188_es8326_ops
= {
920 .hw_params
= mt8188_es8326_hw_params
,
923 static struct snd_soc_dai_link mt8188_mt6359_dai_links
[] = {
925 [DAI_LINK_DL2_FE
] = {
927 .stream_name
= "DL2 Playback",
929 SND_SOC_DPCM_TRIGGER_POST
,
930 SND_SOC_DPCM_TRIGGER_POST
,
934 .dpcm_merged_chan
= 1,
935 .dpcm_merged_rate
= 1,
936 .dpcm_merged_format
= 1,
937 SND_SOC_DAILINK_REG(playback2
),
939 [DAI_LINK_DL3_FE
] = {
941 .stream_name
= "DL3 Playback",
943 SND_SOC_DPCM_TRIGGER_POST
,
944 SND_SOC_DPCM_TRIGGER_POST
,
948 .dpcm_merged_chan
= 1,
949 .dpcm_merged_rate
= 1,
950 .dpcm_merged_format
= 1,
951 SND_SOC_DAILINK_REG(playback3
),
953 [DAI_LINK_DL6_FE
] = {
955 .stream_name
= "DL6 Playback",
957 SND_SOC_DPCM_TRIGGER_POST
,
958 SND_SOC_DPCM_TRIGGER_POST
,
962 .dpcm_merged_chan
= 1,
963 .dpcm_merged_rate
= 1,
964 .dpcm_merged_format
= 1,
965 SND_SOC_DAILINK_REG(playback6
),
967 [DAI_LINK_DL7_FE
] = {
969 .stream_name
= "DL7 Playback",
971 SND_SOC_DPCM_TRIGGER_PRE
,
972 SND_SOC_DPCM_TRIGGER_PRE
,
976 SND_SOC_DAILINK_REG(playback7
),
978 [DAI_LINK_DL8_FE
] = {
980 .stream_name
= "DL8 Playback",
982 SND_SOC_DPCM_TRIGGER_POST
,
983 SND_SOC_DPCM_TRIGGER_POST
,
987 SND_SOC_DAILINK_REG(playback8
),
989 [DAI_LINK_DL10_FE
] = {
991 .stream_name
= "DL10 Playback",
993 SND_SOC_DPCM_TRIGGER_POST
,
994 SND_SOC_DPCM_TRIGGER_POST
,
998 SND_SOC_DAILINK_REG(playback10
),
1000 [DAI_LINK_DL11_FE
] = {
1002 .stream_name
= "DL11 Playback",
1004 SND_SOC_DPCM_TRIGGER_POST
,
1005 SND_SOC_DPCM_TRIGGER_POST
,
1009 SND_SOC_DAILINK_REG(playback11
),
1011 [DAI_LINK_UL1_FE
] = {
1013 .stream_name
= "UL1 Capture",
1015 SND_SOC_DPCM_TRIGGER_PRE
,
1016 SND_SOC_DPCM_TRIGGER_PRE
,
1020 SND_SOC_DAILINK_REG(capture1
),
1022 [DAI_LINK_UL2_FE
] = {
1024 .stream_name
= "UL2 Capture",
1026 SND_SOC_DPCM_TRIGGER_POST
,
1027 SND_SOC_DPCM_TRIGGER_POST
,
1031 SND_SOC_DAILINK_REG(capture2
),
1033 [DAI_LINK_UL3_FE
] = {
1035 .stream_name
= "UL3 Capture",
1037 SND_SOC_DPCM_TRIGGER_POST
,
1038 SND_SOC_DPCM_TRIGGER_POST
,
1042 SND_SOC_DAILINK_REG(capture3
),
1044 [DAI_LINK_UL4_FE
] = {
1046 .stream_name
= "UL4 Capture",
1048 SND_SOC_DPCM_TRIGGER_POST
,
1049 SND_SOC_DPCM_TRIGGER_POST
,
1053 .dpcm_merged_chan
= 1,
1054 .dpcm_merged_rate
= 1,
1055 .dpcm_merged_format
= 1,
1056 SND_SOC_DAILINK_REG(capture4
),
1058 [DAI_LINK_UL5_FE
] = {
1060 .stream_name
= "UL5 Capture",
1062 SND_SOC_DPCM_TRIGGER_POST
,
1063 SND_SOC_DPCM_TRIGGER_POST
,
1067 .dpcm_merged_chan
= 1,
1068 .dpcm_merged_rate
= 1,
1069 .dpcm_merged_format
= 1,
1070 SND_SOC_DAILINK_REG(capture5
),
1072 [DAI_LINK_UL6_FE
] = {
1074 .stream_name
= "UL6 Capture",
1076 SND_SOC_DPCM_TRIGGER_PRE
,
1077 SND_SOC_DPCM_TRIGGER_PRE
,
1081 SND_SOC_DAILINK_REG(capture6
),
1083 [DAI_LINK_UL8_FE
] = {
1085 .stream_name
= "UL8 Capture",
1087 SND_SOC_DPCM_TRIGGER_POST
,
1088 SND_SOC_DPCM_TRIGGER_POST
,
1092 SND_SOC_DAILINK_REG(capture8
),
1094 [DAI_LINK_UL9_FE
] = {
1096 .stream_name
= "UL9 Capture",
1098 SND_SOC_DPCM_TRIGGER_POST
,
1099 SND_SOC_DPCM_TRIGGER_POST
,
1103 SND_SOC_DAILINK_REG(capture9
),
1105 [DAI_LINK_UL10_FE
] = {
1107 .stream_name
= "UL10 Capture",
1109 SND_SOC_DPCM_TRIGGER_POST
,
1110 SND_SOC_DPCM_TRIGGER_POST
,
1114 SND_SOC_DAILINK_REG(capture10
),
1117 [DAI_LINK_DL_SRC_BE
] = {
1118 .name
= "DL_SRC_BE",
1121 SND_SOC_DAILINK_REG(dl_src
),
1123 [DAI_LINK_DPTX_BE
] = {
1125 .ops
= &mt8188_dptx_ops
,
1126 .be_hw_params_fixup
= mt8188_dptx_hw_params_fixup
,
1129 SND_SOC_DAILINK_REG(dptx
),
1131 [DAI_LINK_ETDM1_IN_BE
] = {
1132 .name
= "ETDM1_IN_BE",
1134 .dai_fmt
= SND_SOC_DAIFMT_I2S
|
1135 SND_SOC_DAIFMT_NB_NF
|
1136 SND_SOC_DAIFMT_CBP_CFP
,
1138 .ignore_suspend
= 1,
1139 SND_SOC_DAILINK_REG(etdm1_in
),
1141 [DAI_LINK_ETDM2_IN_BE
] = {
1142 .name
= "ETDM2_IN_BE",
1144 .dai_fmt
= SND_SOC_DAIFMT_I2S
|
1145 SND_SOC_DAIFMT_NB_NF
|
1146 SND_SOC_DAIFMT_CBP_CFP
,
1148 SND_SOC_DAILINK_REG(etdm2_in
),
1150 [DAI_LINK_ETDM1_OUT_BE
] = {
1151 .name
= "ETDM1_OUT_BE",
1153 .dai_fmt
= SND_SOC_DAIFMT_I2S
|
1154 SND_SOC_DAIFMT_NB_NF
|
1155 SND_SOC_DAIFMT_CBC_CFC
,
1157 SND_SOC_DAILINK_REG(etdm1_out
),
1159 [DAI_LINK_ETDM2_OUT_BE
] = {
1160 .name
= "ETDM2_OUT_BE",
1162 .dai_fmt
= SND_SOC_DAIFMT_I2S
|
1163 SND_SOC_DAIFMT_NB_NF
|
1164 SND_SOC_DAIFMT_CBC_CFC
,
1166 SND_SOC_DAILINK_REG(etdm2_out
),
1168 [DAI_LINK_ETDM3_OUT_BE
] = {
1169 .name
= "ETDM3_OUT_BE",
1171 .dai_fmt
= SND_SOC_DAIFMT_I2S
|
1172 SND_SOC_DAIFMT_NB_NF
|
1173 SND_SOC_DAIFMT_CBC_CFC
,
1175 SND_SOC_DAILINK_REG(etdm3_out
),
1177 [DAI_LINK_PCM1_BE
] = {
1180 .dai_fmt
= SND_SOC_DAIFMT_I2S
|
1181 SND_SOC_DAIFMT_NB_NF
|
1182 SND_SOC_DAIFMT_CBC_CFC
,
1183 SND_SOC_DAILINK_REG(pcm1
),
1185 [DAI_LINK_UL_SRC_BE
] = {
1186 .name
= "UL_SRC_BE",
1189 SND_SOC_DAILINK_REG(ul_src
),
1193 [DAI_LINK_SOF_DL2_BE
] = {
1194 .name
= "AFE_SOF_DL2",
1197 .ops
= &mt8188_sof_be_ops
,
1198 SND_SOC_DAILINK_REG(AFE_SOF_DL2
),
1200 [DAI_LINK_SOF_DL3_BE
] = {
1201 .name
= "AFE_SOF_DL3",
1204 .ops
= &mt8188_sof_be_ops
,
1205 SND_SOC_DAILINK_REG(AFE_SOF_DL3
),
1207 [DAI_LINK_SOF_UL4_BE
] = {
1208 .name
= "AFE_SOF_UL4",
1211 .ops
= &mt8188_sof_be_ops
,
1212 SND_SOC_DAILINK_REG(AFE_SOF_UL4
),
1214 [DAI_LINK_SOF_UL5_BE
] = {
1215 .name
= "AFE_SOF_UL5",
1218 .ops
= &mt8188_sof_be_ops
,
1219 SND_SOC_DAILINK_REG(AFE_SOF_UL5
),
1223 static void mt8188_fixup_controls(struct snd_soc_card
*card
)
1225 struct mtk_soc_card_data
*soc_card_data
= snd_soc_card_get_drvdata(card
);
1226 struct mtk_platform_card_data
*card_data
= soc_card_data
->card_data
;
1227 struct snd_kcontrol
*kctl
;
1229 if (card_data
->flags
& (NAU8825_HS_PRESENT
| RT5682S_HS_PRESENT
| ES8326_HS_PRESENT
)) {
1230 struct snd_soc_dapm_widget
*w
, *next_w
;
1232 for_each_card_widgets_safe(card
, w
, next_w
) {
1233 if (strcmp(w
->name
, "Headphone"))
1236 snd_soc_dapm_free_widget(w
);
1239 kctl
= snd_ctl_find_id_mixer(card
->snd_card
, "Headphone Switch");
1241 snd_ctl_remove(card
->snd_card
, kctl
);
1243 dev_warn(card
->dev
, "Cannot find ctl : Headphone Switch\n");
1247 static struct snd_soc_card mt8188_mt6359_soc_card
= {
1248 .owner
= THIS_MODULE
,
1249 .dai_link
= mt8188_mt6359_dai_links
,
1250 .num_links
= ARRAY_SIZE(mt8188_mt6359_dai_links
),
1251 .dapm_widgets
= mt8188_mt6359_widgets
,
1252 .num_dapm_widgets
= ARRAY_SIZE(mt8188_mt6359_widgets
),
1253 .dapm_routes
= mt8188_mt6359_routes
,
1254 .num_dapm_routes
= ARRAY_SIZE(mt8188_mt6359_routes
),
1255 .controls
= mt8188_mt6359_controls
,
1256 .num_controls
= ARRAY_SIZE(mt8188_mt6359_controls
),
1257 .fixup_controls
= mt8188_fixup_controls
,
1260 static int mt8188_mt6359_soc_card_probe(struct mtk_soc_card_data
*soc_card_data
, bool legacy
)
1262 struct mtk_platform_card_data
*card_data
= soc_card_data
->card_data
;
1263 struct snd_soc_card
*card
= soc_card_data
->card_data
->card
;
1264 struct snd_soc_dai_link
*dai_link
;
1265 bool init_mt6359
= false;
1266 bool init_es8326
= false;
1267 bool init_nau8825
= false;
1268 bool init_rt5682s
= false;
1269 bool init_max98390
= false;
1270 bool init_dumb
= false;
1276 for_each_card_prelinks(card
, i
, dai_link
) {
1277 if (strcmp(dai_link
->name
, "DPTX_BE") == 0) {
1278 if (dai_link
->num_codecs
&&
1279 strcmp(dai_link
->codecs
->dai_name
, "snd-soc-dummy-dai"))
1280 dai_link
->init
= mt8188_dptx_codec_init
;
1281 } else if (strcmp(dai_link
->name
, "ETDM3_OUT_BE") == 0) {
1282 if (dai_link
->num_codecs
&&
1283 strcmp(dai_link
->codecs
->dai_name
, "snd-soc-dummy-dai"))
1284 dai_link
->init
= mt8188_hdmi_codec_init
;
1285 } else if (strcmp(dai_link
->name
, "DL_SRC_BE") == 0 ||
1286 strcmp(dai_link
->name
, "UL_SRC_BE") == 0) {
1288 dai_link
->init
= mt8188_mt6359_init
;
1291 } else if (strcmp(dai_link
->name
, "ETDM1_OUT_BE") == 0 ||
1292 strcmp(dai_link
->name
, "ETDM2_OUT_BE") == 0 ||
1293 strcmp(dai_link
->name
, "ETDM1_IN_BE") == 0 ||
1294 strcmp(dai_link
->name
, "ETDM2_IN_BE") == 0) {
1295 if (!dai_link
->num_codecs
)
1298 if (!strcmp(dai_link
->codecs
->dai_name
, MAX98390_CODEC_DAI
)) {
1300 * The TDM protocol settings with fixed 4 slots are defined in
1301 * mt8188_max98390_ops. Two amps is I2S mode,
1302 * SOC and codec don't require TDM settings.
1304 if (!(card_data
->flags
& MAX98390_TWO_AMP
)) {
1305 dai_link
->ops
= &mt8188_max98390_ops
;
1307 if (!init_max98390
) {
1308 dai_link
->init
= mt8188_max98390_codec_init
;
1309 init_max98390
= true;
1311 } else if (!strcmp(dai_link
->codecs
->dai_name
, NAU8825_CODEC_DAI
)) {
1312 dai_link
->ops
= &mt8188_nau8825_ops
;
1313 if (!init_nau8825
) {
1314 dai_link
->init
= mt8188_headset_codec_init
;
1315 dai_link
->exit
= mt8188_headset_codec_exit
;
1316 init_nau8825
= true;
1318 } else if (!strcmp(dai_link
->codecs
->dai_name
, RT5682S_CODEC_DAI
)) {
1319 dai_link
->ops
= &mt8188_rt5682s_i2s_ops
;
1320 if (!init_rt5682s
) {
1321 dai_link
->init
= mt8188_headset_codec_init
;
1322 dai_link
->exit
= mt8188_headset_codec_exit
;
1323 init_rt5682s
= true;
1325 } else if (!strcmp(dai_link
->codecs
->dai_name
, ES8326_CODEC_DAI
)) {
1326 dai_link
->ops
= &mt8188_es8326_ops
;
1328 dai_link
->init
= mt8188_headset_codec_init
;
1329 dai_link
->exit
= mt8188_headset_codec_exit
;
1333 if (strcmp(dai_link
->codecs
->dai_name
, "snd-soc-dummy-dai")) {
1335 dai_link
->init
= mt8188_dumb_amp_init
;
1346 static const struct mtk_sof_priv mt8188_sof_priv
= {
1347 .conn_streams
= g_sof_conn_streams
,
1348 .num_streams
= ARRAY_SIZE(g_sof_conn_streams
),
1351 static const struct mtk_soundcard_pdata mt8188_evb_card
= {
1352 .card_name
= "mt8188_mt6359",
1353 .card_data
= &(struct mtk_platform_card_data
) {
1354 .card
= &mt8188_mt6359_soc_card
,
1355 .num_jacks
= MT8188_JACK_MAX
,
1357 .sof_priv
= &mt8188_sof_priv
,
1358 .soc_probe
= mt8188_mt6359_soc_card_probe
,
1361 static const struct mtk_soundcard_pdata mt8188_nau8825_card
= {
1362 .card_name
= "mt8188_nau8825",
1363 .card_data
= &(struct mtk_platform_card_data
) {
1364 .card
= &mt8188_mt6359_soc_card
,
1365 .num_jacks
= MT8188_JACK_MAX
,
1366 .flags
= NAU8825_HS_PRESENT
1368 .sof_priv
= &mt8188_sof_priv
,
1369 .soc_probe
= mt8188_mt6359_soc_card_probe
,
1372 static const struct mtk_soundcard_pdata mt8188_rt5682s_card
= {
1373 .card_name
= "mt8188_rt5682s",
1374 .card_data
= &(struct mtk_platform_card_data
) {
1375 .card
= &mt8188_mt6359_soc_card
,
1376 .num_jacks
= MT8188_JACK_MAX
,
1377 .flags
= RT5682S_HS_PRESENT
| MAX98390_TWO_AMP
1379 .sof_priv
= &mt8188_sof_priv
,
1380 .soc_probe
= mt8188_mt6359_soc_card_probe
,
1383 static const struct mtk_soundcard_pdata mt8188_es8326_card
= {
1384 .card_name
= "mt8188_es8326",
1385 .card_data
= &(struct mtk_platform_card_data
) {
1386 .card
= &mt8188_mt6359_soc_card
,
1387 .num_jacks
= MT8188_JACK_MAX
,
1388 .flags
= ES8326_HS_PRESENT
| MAX98390_TWO_AMP
1390 .sof_priv
= &mt8188_sof_priv
,
1391 .soc_probe
= mt8188_mt6359_soc_card_probe
,
1394 static const struct of_device_id mt8188_mt6359_dt_match
[] = {
1395 { .compatible
= "mediatek,mt8188-mt6359-evb", .data
= &mt8188_evb_card
, },
1396 { .compatible
= "mediatek,mt8188-nau8825", .data
= &mt8188_nau8825_card
, },
1397 { .compatible
= "mediatek,mt8188-rt5682s", .data
= &mt8188_rt5682s_card
, },
1398 { .compatible
= "mediatek,mt8188-es8326", .data
= &mt8188_es8326_card
, },
1401 MODULE_DEVICE_TABLE(of
, mt8188_mt6359_dt_match
);
1403 static struct platform_driver mt8188_mt6359_driver
= {
1405 .name
= "mt8188_mt6359",
1406 .of_match_table
= mt8188_mt6359_dt_match
,
1407 .pm
= &snd_soc_pm_ops
,
1409 .probe
= mtk_soundcard_common_probe
,
1412 module_platform_driver(mt8188_mt6359_driver
);
1414 /* Module information */
1415 MODULE_DESCRIPTION("MT8188-MT6359 ALSA SoC machine driver");
1416 MODULE_AUTHOR("Trevor Wu <trevor.wu@mediatek.com>");
1417 MODULE_LICENSE("GPL");
1418 MODULE_ALIAS("mt8188 mt6359 soc card");