1 // SPDX-License-Identifier: GPL-2.0
3 * MediaTek ALSA SoC Audio DAI ADDA Control
5 * Copyright (c) 2021 MediaTek Inc.
6 * Author: Bicycle Tsai <bicycle.tsai@mediatek.com>
7 * Trevor Wu <trevor.wu@mediatek.com>
10 #include <linux/delay.h>
11 #include <linux/regmap.h>
12 #include "mt8195-afe-clk.h"
13 #include "mt8195-afe-common.h"
14 #include "mt8195-reg.h"
15 #include "../common/mtk-dai-adda-common.h"
17 #define ADDA_DL_GAIN_LOOPBACK 0x1800
18 #define ADDA_HIRES_THRES 48000
23 SUPPLY_SEQ_ADDA_DL_ON
,
24 SUPPLY_SEQ_ADDA_MTKAIF_CFG
,
25 SUPPLY_SEQ_ADDA_UL_ON
,
26 SUPPLY_SEQ_ADDA_AFE_ON
,
34 struct mtk_dai_adda_priv
{
38 static int mt8195_adda_mtkaif_init(struct mtk_base_afe
*afe
)
40 struct mt8195_afe_private
*afe_priv
= afe
->platform_priv
;
41 struct mtkaif_param
*param
= &afe_priv
->mtkaif_params
;
44 unsigned int mask
= 0;
47 /* set rx protocol 2 & mtkaif_rxif_clkinv_adc inverse */
48 mask
= (MTKAIF_RXIF_CLKINV_ADC
| MTKAIF_RXIF_PROTOCOL2
);
49 val
= (MTKAIF_RXIF_CLKINV_ADC
| MTKAIF_RXIF_PROTOCOL2
);
51 regmap_update_bits(afe
->regmap
, AFE_ADDA_MTKAIF_CFG0
, mask
, val
);
52 regmap_update_bits(afe
->regmap
, AFE_ADDA6_MTKAIF_CFG0
, mask
, val
);
54 mask
= RG_RX_PROTOCOL2
;
55 val
= RG_RX_PROTOCOL2
;
56 regmap_update_bits(afe
->regmap
, AFE_AUD_PAD_TOP
, mask
, val
);
58 if (!param
->mtkaif_calibration_ok
) {
59 dev_info(afe
->dev
, "%s(), calibration fail\n", __func__
);
63 /* set delay for ch1, ch2 */
64 if (param
->mtkaif_phase_cycle
[MT8195_MTKAIF_MISO_0
] >=
65 param
->mtkaif_phase_cycle
[MT8195_MTKAIF_MISO_1
]) {
66 delay_data
= DELAY_DATA_MISO1
;
68 param
->mtkaif_phase_cycle
[MT8195_MTKAIF_MISO_0
] -
69 param
->mtkaif_phase_cycle
[MT8195_MTKAIF_MISO_1
];
71 delay_data
= DELAY_DATA_MISO0
;
73 param
->mtkaif_phase_cycle
[MT8195_MTKAIF_MISO_1
] -
74 param
->mtkaif_phase_cycle
[MT8195_MTKAIF_MISO_0
];
78 mask
= (MTKAIF_RXIF_DELAY_DATA
| MTKAIF_RXIF_DELAY_CYCLE_MASK
);
79 val
|= MTKAIF_RXIF_DELAY_CYCLE(delay_cycle
) &
80 MTKAIF_RXIF_DELAY_CYCLE_MASK
;
81 val
|= delay_data
<< MTKAIF_RXIF_DELAY_DATA_SHIFT
;
82 regmap_update_bits(afe
->regmap
, AFE_ADDA_MTKAIF_RX_CFG2
, mask
, val
);
84 /* set delay between ch3 and ch2 */
85 if (param
->mtkaif_phase_cycle
[MT8195_MTKAIF_MISO_2
] >=
86 param
->mtkaif_phase_cycle
[MT8195_MTKAIF_MISO_1
]) {
87 delay_data
= DELAY_DATA_MISO1
;
89 param
->mtkaif_phase_cycle
[MT8195_MTKAIF_MISO_2
] -
90 param
->mtkaif_phase_cycle
[MT8195_MTKAIF_MISO_1
];
92 delay_data
= DELAY_DATA_MISO2
;
94 param
->mtkaif_phase_cycle
[MT8195_MTKAIF_MISO_1
] -
95 param
->mtkaif_phase_cycle
[MT8195_MTKAIF_MISO_2
];
99 mask
= (MTKAIF_RXIF_DELAY_DATA
| MTKAIF_RXIF_DELAY_CYCLE_MASK
);
100 val
|= MTKAIF_RXIF_DELAY_CYCLE(delay_cycle
) &
101 MTKAIF_RXIF_DELAY_CYCLE_MASK
;
102 val
|= delay_data
<< MTKAIF_RXIF_DELAY_DATA_SHIFT
;
103 regmap_update_bits(afe
->regmap
, AFE_ADDA6_MTKAIF_RX_CFG2
, mask
, val
);
108 static int mtk_adda_mtkaif_cfg_event(struct snd_soc_dapm_widget
*w
,
109 struct snd_kcontrol
*kcontrol
,
112 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
113 struct mtk_base_afe
*afe
= snd_soc_component_get_drvdata(cmpnt
);
115 dev_dbg(afe
->dev
, "%s(), name %s, event 0x%x\n",
116 __func__
, w
->name
, event
);
119 case SND_SOC_DAPM_PRE_PMU
:
120 mt8195_adda_mtkaif_init(afe
);
129 static int mtk_adda_dl_event(struct snd_soc_dapm_widget
*w
,
130 struct snd_kcontrol
*kcontrol
,
133 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
134 struct mtk_base_afe
*afe
= snd_soc_component_get_drvdata(cmpnt
);
136 dev_dbg(afe
->dev
, "%s(), name %s, event 0x%x\n",
137 __func__
, w
->name
, event
);
140 case SND_SOC_DAPM_POST_PMD
:
141 /* should delayed 1/fs(smallest is 8k) = 125us before afe off */
142 usleep_range(125, 135);
151 static void mtk_adda_ul_mictype(struct mtk_base_afe
*afe
, int adda
, bool dmic
)
153 unsigned int reg
= 0;
154 unsigned int mask
= 0;
155 unsigned int val
= 0;
159 reg
= AFE_ADDA_UL_SRC_CON0
;
162 reg
= AFE_ADDA6_UL_SRC_CON0
;
165 dev_info(afe
->dev
, "%s(), wrong parameter\n", __func__
);
169 mask
= (UL_SDM3_LEVEL_CTL
| UL_MODE_3P25M_CH1_CTL
|
170 UL_MODE_3P25M_CH2_CTL
);
172 /* turn on dmic, ch1, ch2 */
176 regmap_update_bits(afe
->regmap
, reg
, mask
, val
);
179 static int mtk_adda_ul_event(struct snd_soc_dapm_widget
*w
,
180 struct snd_kcontrol
*kcontrol
,
183 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
184 struct mtk_base_afe
*afe
= snd_soc_component_get_drvdata(cmpnt
);
185 struct mt8195_afe_private
*afe_priv
= afe
->platform_priv
;
186 struct mtkaif_param
*param
= &afe_priv
->mtkaif_params
;
188 dev_dbg(afe
->dev
, "%s(), name %s, event 0x%x\n",
189 __func__
, w
->name
, event
);
192 case SND_SOC_DAPM_PRE_PMU
:
193 mtk_adda_ul_mictype(afe
, MTK_AFE_ADDA
, param
->mtkaif_dmic_on
);
195 case SND_SOC_DAPM_POST_PMD
:
196 /* should delayed 1/fs(smallest is 8k) = 125us before afe off */
197 usleep_range(125, 135);
206 static int mtk_adda6_ul_event(struct snd_soc_dapm_widget
*w
,
207 struct snd_kcontrol
*kcontrol
,
210 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
211 struct mtk_base_afe
*afe
= snd_soc_component_get_drvdata(cmpnt
);
212 struct mt8195_afe_private
*afe_priv
= afe
->platform_priv
;
213 struct mtkaif_param
*param
= &afe_priv
->mtkaif_params
;
216 dev_dbg(afe
->dev
, "%s(), name %s, event 0x%x\n",
217 __func__
, w
->name
, event
);
220 case SND_SOC_DAPM_PRE_PMU
:
221 mtk_adda_ul_mictype(afe
, MTK_AFE_ADDA6
, param
->mtkaif_dmic_on
);
223 val
= (param
->mtkaif_adda6_only
?
224 ADDA6_MTKAIF_RX_SYNC_WORD2_DISABLE
: 0);
226 regmap_update_bits(afe
->regmap
,
227 AFE_ADDA_MTKAIF_SYNCWORD_CFG
,
228 ADDA6_MTKAIF_RX_SYNC_WORD2_DISABLE
,
231 case SND_SOC_DAPM_POST_PMD
:
232 /* should delayed 1/fs(smallest is 8k) = 125us before afe off */
233 usleep_range(125, 135);
242 static int mtk_audio_hires_event(struct snd_soc_dapm_widget
*w
,
243 struct snd_kcontrol
*kcontrol
,
246 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
247 struct mtk_base_afe
*afe
= snd_soc_component_get_drvdata(cmpnt
);
248 struct mt8195_afe_private
*afe_priv
= afe
->platform_priv
;
249 struct clk
*clk
= afe_priv
->clk
[MT8195_CLK_TOP_AUDIO_H_SEL
];
250 struct clk
*clk_parent
;
252 dev_dbg(afe
->dev
, "%s(), name %s, event 0x%x\n",
253 __func__
, w
->name
, event
);
256 case SND_SOC_DAPM_PRE_PMU
:
257 clk_parent
= afe_priv
->clk
[MT8195_CLK_TOP_APLL1
];
259 case SND_SOC_DAPM_POST_PMD
:
260 clk_parent
= afe_priv
->clk
[MT8195_CLK_XTAL_26M
];
265 mt8195_afe_set_clk_parent(afe
, clk
, clk_parent
);
270 static struct mtk_dai_adda_priv
*get_adda_priv_by_name(struct mtk_base_afe
*afe
,
273 struct mt8195_afe_private
*afe_priv
= afe
->platform_priv
;
276 if (strstr(name
, "aud_adc_hires"))
277 dai_id
= MT8195_AFE_IO_UL_SRC1
;
278 else if (strstr(name
, "aud_adda6_adc_hires"))
279 dai_id
= MT8195_AFE_IO_UL_SRC2
;
280 else if (strstr(name
, "aud_dac_hires"))
281 dai_id
= MT8195_AFE_IO_DL_SRC
;
285 return afe_priv
->dai_priv
[dai_id
];
288 static int mtk_afe_adda_hires_connect(struct snd_soc_dapm_widget
*source
,
289 struct snd_soc_dapm_widget
*sink
)
291 struct snd_soc_dapm_widget
*w
= source
;
292 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
293 struct mtk_base_afe
*afe
= snd_soc_component_get_drvdata(cmpnt
);
294 struct mtk_dai_adda_priv
*adda_priv
;
296 adda_priv
= get_adda_priv_by_name(afe
, w
->name
);
299 dev_info(afe
->dev
, "adda_priv == NULL");
303 return (adda_priv
->hires_required
) ? 1 : 0;
306 static const struct snd_kcontrol_new mtk_dai_adda_o176_mix
[] = {
307 SOC_DAPM_SINGLE_AUTODISABLE("I000 Switch", AFE_CONN176
, 0, 1, 0),
308 SOC_DAPM_SINGLE_AUTODISABLE("I002 Switch", AFE_CONN176
, 2, 1, 0),
309 SOC_DAPM_SINGLE_AUTODISABLE("I020 Switch", AFE_CONN176
, 20, 1, 0),
310 SOC_DAPM_SINGLE_AUTODISABLE("I022 Switch", AFE_CONN176
, 22, 1, 0),
311 SOC_DAPM_SINGLE_AUTODISABLE("I070 Switch", AFE_CONN176_2
, 6, 1, 0),
314 static const struct snd_kcontrol_new mtk_dai_adda_o177_mix
[] = {
315 SOC_DAPM_SINGLE_AUTODISABLE("I001 Switch", AFE_CONN177
, 1, 1, 0),
316 SOC_DAPM_SINGLE_AUTODISABLE("I003 Switch", AFE_CONN177
, 3, 1, 0),
317 SOC_DAPM_SINGLE_AUTODISABLE("I021 Switch", AFE_CONN177
, 21, 1, 0),
318 SOC_DAPM_SINGLE_AUTODISABLE("I023 Switch", AFE_CONN177
, 23, 1, 0),
319 SOC_DAPM_SINGLE_AUTODISABLE("I071 Switch", AFE_CONN177_2
, 7, 1, 0),
322 static const char * const adda_dlgain_mux_map
[] = {
326 static SOC_ENUM_SINGLE_DECL(adda_dlgain_mux_map_enum
,
328 adda_dlgain_mux_map
);
330 static const struct snd_kcontrol_new adda_dlgain_mux_control
=
331 SOC_DAPM_ENUM("DL_GAIN_MUX", adda_dlgain_mux_map_enum
);
333 static const struct snd_soc_dapm_widget mtk_dai_adda_widgets
[] = {
334 SND_SOC_DAPM_MIXER("I168", SND_SOC_NOPM
, 0, 0, NULL
, 0),
335 SND_SOC_DAPM_MIXER("I169", SND_SOC_NOPM
, 0, 0, NULL
, 0),
336 SND_SOC_DAPM_MIXER("I170", SND_SOC_NOPM
, 0, 0, NULL
, 0),
337 SND_SOC_DAPM_MIXER("I171", SND_SOC_NOPM
, 0, 0, NULL
, 0),
339 SND_SOC_DAPM_MIXER("O176", SND_SOC_NOPM
, 0, 0,
340 mtk_dai_adda_o176_mix
,
341 ARRAY_SIZE(mtk_dai_adda_o176_mix
)),
342 SND_SOC_DAPM_MIXER("O177", SND_SOC_NOPM
, 0, 0,
343 mtk_dai_adda_o177_mix
,
344 ARRAY_SIZE(mtk_dai_adda_o177_mix
)),
346 SND_SOC_DAPM_SUPPLY_S("ADDA Enable", SUPPLY_SEQ_ADDA_AFE_ON
,
348 ADDA_AFE_ON_SHIFT
, 0,
352 SND_SOC_DAPM_SUPPLY_S("ADDA Playback Enable", SUPPLY_SEQ_ADDA_DL_ON
,
353 AFE_ADDA_DL_SRC2_CON0
,
354 DL_2_SRC_ON_TMP_CTRL_PRE_SHIFT
, 0,
356 SND_SOC_DAPM_POST_PMD
),
358 SND_SOC_DAPM_SUPPLY_S("ADDA Capture Enable", SUPPLY_SEQ_ADDA_UL_ON
,
359 AFE_ADDA_UL_SRC_CON0
,
360 UL_SRC_ON_TMP_CTL_SHIFT
, 0,
362 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
364 SND_SOC_DAPM_SUPPLY_S("ADDA6 Capture Enable", SUPPLY_SEQ_ADDA_UL_ON
,
365 AFE_ADDA6_UL_SRC_CON0
,
366 UL_SRC_ON_TMP_CTL_SHIFT
, 0,
368 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
370 SND_SOC_DAPM_SUPPLY_S("AUDIO_HIRES", SUPPLY_SEQ_CLOCK_SEL
,
373 mtk_audio_hires_event
,
374 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
376 SND_SOC_DAPM_SUPPLY_S("ADDA_MTKAIF_CFG", SUPPLY_SEQ_ADDA_MTKAIF_CFG
,
379 mtk_adda_mtkaif_cfg_event
,
380 SND_SOC_DAPM_PRE_PMU
),
382 SND_SOC_DAPM_MUX("DL_GAIN_MUX", SND_SOC_NOPM
, 0, 0,
383 &adda_dlgain_mux_control
),
385 SND_SOC_DAPM_PGA("DL_GAIN", AFE_ADDA_DL_SRC2_CON0
,
386 DL_2_GAIN_ON_CTL_PRE_SHIFT
, 0, NULL
, 0),
388 SND_SOC_DAPM_INPUT("ADDA_INPUT"),
389 SND_SOC_DAPM_OUTPUT("ADDA_OUTPUT"),
391 SND_SOC_DAPM_CLOCK_SUPPLY("aud_dac"),
392 SND_SOC_DAPM_CLOCK_SUPPLY("aud_adc"),
393 SND_SOC_DAPM_CLOCK_SUPPLY("aud_adda6_adc"),
394 SND_SOC_DAPM_CLOCK_SUPPLY("aud_dac_hires"),
395 SND_SOC_DAPM_CLOCK_SUPPLY("aud_adc_hires"),
396 SND_SOC_DAPM_CLOCK_SUPPLY("aud_adda6_adc_hires"),
399 static const struct snd_soc_dapm_route mtk_dai_adda_routes
[] = {
400 {"ADDA Capture", NULL
, "ADDA Enable"},
401 {"ADDA Capture", NULL
, "ADDA Capture Enable"},
402 {"ADDA Capture", NULL
, "ADDA_MTKAIF_CFG"},
403 {"ADDA Capture", NULL
, "aud_adc"},
404 {"ADDA Capture", NULL
, "aud_adc_hires", mtk_afe_adda_hires_connect
},
405 {"aud_adc_hires", NULL
, "AUDIO_HIRES"},
407 {"ADDA6 Capture", NULL
, "ADDA Enable"},
408 {"ADDA6 Capture", NULL
, "ADDA6 Capture Enable"},
409 {"ADDA6 Capture", NULL
, "ADDA_MTKAIF_CFG"},
410 {"ADDA6 Capture", NULL
, "aud_adda6_adc"},
411 {"ADDA6 Capture", NULL
, "aud_adda6_adc_hires",
412 mtk_afe_adda_hires_connect
},
413 {"aud_adda6_adc_hires", NULL
, "AUDIO_HIRES"},
415 {"I168", NULL
, "ADDA Capture"},
416 {"I169", NULL
, "ADDA Capture"},
417 {"I170", NULL
, "ADDA6 Capture"},
418 {"I171", NULL
, "ADDA6 Capture"},
420 {"ADDA Playback", NULL
, "ADDA Enable"},
421 {"ADDA Playback", NULL
, "ADDA Playback Enable"},
422 {"ADDA Playback", NULL
, "aud_dac"},
423 {"ADDA Playback", NULL
, "aud_dac_hires", mtk_afe_adda_hires_connect
},
424 {"aud_dac_hires", NULL
, "AUDIO_HIRES"},
426 {"DL_GAIN", NULL
, "O176"},
427 {"DL_GAIN", NULL
, "O177"},
429 {"DL_GAIN_MUX", "Bypass", "O176"},
430 {"DL_GAIN_MUX", "Bypass", "O177"},
431 {"DL_GAIN_MUX", "Connect", "DL_GAIN"},
433 {"ADDA Playback", NULL
, "DL_GAIN_MUX"},
435 {"O176", "I000 Switch", "I000"},
436 {"O177", "I001 Switch", "I001"},
438 {"O176", "I002 Switch", "I002"},
439 {"O177", "I003 Switch", "I003"},
441 {"O176", "I020 Switch", "I020"},
442 {"O177", "I021 Switch", "I021"},
444 {"O176", "I022 Switch", "I022"},
445 {"O177", "I023 Switch", "I023"},
447 {"O176", "I070 Switch", "I070"},
448 {"O177", "I071 Switch", "I071"},
450 {"ADDA Capture", NULL
, "ADDA_INPUT"},
451 {"ADDA6 Capture", NULL
, "ADDA_INPUT"},
452 {"ADDA_OUTPUT", NULL
, "ADDA Playback"},
455 static int mt8195_adda_dl_gain_put(struct snd_kcontrol
*kcontrol
,
456 struct snd_ctl_elem_value
*ucontrol
)
458 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
459 struct mtk_base_afe
*afe
= snd_soc_component_get_drvdata(component
);
460 unsigned int reg
= AFE_ADDA_DL_SRC2_CON1
;
461 unsigned int mask
= DL_2_GAIN_CTL_PRE_MASK
;
462 unsigned int value
= (unsigned int)(ucontrol
->value
.integer
.value
[0]);
464 regmap_update_bits(afe
->regmap
, reg
, mask
, DL_2_GAIN_CTL_PRE(value
));
468 static int mt8195_adda_dl_gain_get(struct snd_kcontrol
*kcontrol
,
469 struct snd_ctl_elem_value
*ucontrol
)
471 struct snd_soc_component
*component
= snd_kcontrol_chip(kcontrol
);
472 struct mtk_base_afe
*afe
= snd_soc_component_get_drvdata(component
);
473 unsigned int reg
= AFE_ADDA_DL_SRC2_CON1
;
474 unsigned int mask
= DL_2_GAIN_CTL_PRE_MASK
;
475 unsigned int value
= 0;
477 regmap_read(afe
->regmap
, reg
, &value
);
479 ucontrol
->value
.integer
.value
[0] = ((value
& mask
) >>
480 DL_2_GAIN_CTL_PRE_SHIFT
);
484 static int mt8195_adda6_only_get(struct snd_kcontrol
*kcontrol
,
485 struct snd_ctl_elem_value
*ucontrol
)
487 struct snd_soc_component
*cmpnt
= snd_soc_kcontrol_component(kcontrol
);
488 struct mtk_base_afe
*afe
= snd_soc_component_get_drvdata(cmpnt
);
489 struct mt8195_afe_private
*afe_priv
= afe
->platform_priv
;
490 struct mtkaif_param
*param
= &afe_priv
->mtkaif_params
;
492 ucontrol
->value
.integer
.value
[0] = param
->mtkaif_adda6_only
;
496 static int mt8195_adda6_only_set(struct snd_kcontrol
*kcontrol
,
497 struct snd_ctl_elem_value
*ucontrol
)
499 struct snd_soc_component
*cmpnt
= snd_soc_kcontrol_component(kcontrol
);
500 struct mtk_base_afe
*afe
= snd_soc_component_get_drvdata(cmpnt
);
501 struct mt8195_afe_private
*afe_priv
= afe
->platform_priv
;
502 struct mtkaif_param
*param
= &afe_priv
->mtkaif_params
;
503 int mtkaif_adda6_only
;
505 mtkaif_adda6_only
= ucontrol
->value
.integer
.value
[0];
507 dev_info(afe
->dev
, "%s(), kcontrol name %s, mtkaif_adda6_only %d\n",
508 __func__
, kcontrol
->id
.name
, mtkaif_adda6_only
);
510 param
->mtkaif_adda6_only
= mtkaif_adda6_only
;
515 static int mt8195_adda_dmic_get(struct snd_kcontrol
*kcontrol
,
516 struct snd_ctl_elem_value
*ucontrol
)
518 struct snd_soc_component
*cmpnt
= snd_soc_kcontrol_component(kcontrol
);
519 struct mtk_base_afe
*afe
= snd_soc_component_get_drvdata(cmpnt
);
520 struct mt8195_afe_private
*afe_priv
= afe
->platform_priv
;
521 struct mtkaif_param
*param
= &afe_priv
->mtkaif_params
;
523 ucontrol
->value
.integer
.value
[0] = param
->mtkaif_dmic_on
;
527 static int mt8195_adda_dmic_set(struct snd_kcontrol
*kcontrol
,
528 struct snd_ctl_elem_value
*ucontrol
)
530 struct snd_soc_component
*cmpnt
= snd_soc_kcontrol_component(kcontrol
);
531 struct mtk_base_afe
*afe
= snd_soc_component_get_drvdata(cmpnt
);
532 struct mt8195_afe_private
*afe_priv
= afe
->platform_priv
;
533 struct mtkaif_param
*param
= &afe_priv
->mtkaif_params
;
536 dmic_on
= ucontrol
->value
.integer
.value
[0];
538 dev_dbg(afe
->dev
, "%s(), kcontrol name %s, dmic_on %d\n",
539 __func__
, kcontrol
->id
.name
, dmic_on
);
541 param
->mtkaif_dmic_on
= dmic_on
;
545 static const struct snd_kcontrol_new mtk_dai_adda_controls
[] = {
546 SOC_SINGLE_EXT("ADDA_DL_Gain", SND_SOC_NOPM
, 0, 65535, 0,
547 mt8195_adda_dl_gain_get
, mt8195_adda_dl_gain_put
),
548 SOC_SINGLE_BOOL_EXT("MTKAIF_DMIC", 0,
549 mt8195_adda_dmic_get
, mt8195_adda_dmic_set
),
550 SOC_SINGLE_BOOL_EXT("MTKAIF_ADDA6_ONLY", 0,
551 mt8195_adda6_only_get
,
552 mt8195_adda6_only_set
),
555 static int mtk_dai_da_configure(struct mtk_base_afe
*afe
,
556 unsigned int rate
, int id
)
558 unsigned int val
= 0;
559 unsigned int mask
= 0;
561 /* set sampling rate */
562 mask
|= DL_2_INPUT_MODE_CTL_MASK
;
563 val
|= DL_2_INPUT_MODE_CTL(mtk_adda_dl_rate_transform(afe
, rate
));
565 /* turn off saturation */
566 mask
|= DL_2_CH1_SATURATION_EN_CTL
;
567 mask
|= DL_2_CH2_SATURATION_EN_CTL
;
569 /* turn off mute function */
570 mask
|= DL_2_MUTE_CH1_OFF_CTL_PRE
;
571 mask
|= DL_2_MUTE_CH2_OFF_CTL_PRE
;
572 val
|= DL_2_MUTE_CH1_OFF_CTL_PRE
;
573 val
|= DL_2_MUTE_CH2_OFF_CTL_PRE
;
575 /* set voice input data if input sample rate is 8k or 16k */
576 mask
|= DL_2_VOICE_MODE_CTL_PRE
;
577 if (rate
== 8000 || rate
== 16000)
578 val
|= DL_2_VOICE_MODE_CTL_PRE
;
580 regmap_update_bits(afe
->regmap
, AFE_ADDA_DL_SRC2_CON0
, mask
, val
);
586 mask
|= DL_USE_NEW_2ND_SDM
;
587 val
|= DL_USE_NEW_2ND_SDM
;
588 regmap_update_bits(afe
->regmap
, AFE_ADDA_DL_SDM_DCCOMP_CON
, mask
, val
);
593 static int mtk_dai_ad_configure(struct mtk_base_afe
*afe
,
594 unsigned int rate
, int id
)
596 unsigned int val
= 0;
597 unsigned int mask
= 0;
599 mask
|= UL_VOICE_MODE_CTL_MASK
;
600 val
|= UL_VOICE_MODE_CTL(mtk_adda_ul_rate_transform(afe
, rate
));
603 case MT8195_AFE_IO_UL_SRC1
:
604 regmap_update_bits(afe
->regmap
, AFE_ADDA_UL_SRC_CON0
,
607 case MT8195_AFE_IO_UL_SRC2
:
608 regmap_update_bits(afe
->regmap
, AFE_ADDA6_UL_SRC_CON0
,
617 static int mtk_dai_adda_hw_params(struct snd_pcm_substream
*substream
,
618 struct snd_pcm_hw_params
*params
,
619 struct snd_soc_dai
*dai
)
621 struct mtk_base_afe
*afe
= snd_soc_dai_get_drvdata(dai
);
622 struct mt8195_afe_private
*afe_priv
= afe
->platform_priv
;
623 struct mtk_dai_adda_priv
*adda_priv
;
624 unsigned int rate
= params_rate(params
);
627 if (dai
->id
!= MT8195_AFE_IO_DL_SRC
&&
628 dai
->id
!= MT8195_AFE_IO_UL_SRC1
&&
629 dai
->id
!= MT8195_AFE_IO_UL_SRC2
)
631 adda_priv
= afe_priv
->dai_priv
[dai
->id
];
633 dev_dbg(afe
->dev
, "%s(), id %d, stream %d, rate %d\n",
634 __func__
, dai
->id
, substream
->stream
, rate
);
636 if (rate
> ADDA_HIRES_THRES
)
637 adda_priv
->hires_required
= 1;
639 adda_priv
->hires_required
= 0;
641 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
642 ret
= mtk_dai_da_configure(afe
, rate
, dai
->id
);
644 ret
= mtk_dai_ad_configure(afe
, rate
, dai
->id
);
649 static const struct snd_soc_dai_ops mtk_dai_adda_ops
= {
650 .hw_params
= mtk_dai_adda_hw_params
,
654 #define MTK_ADDA_PLAYBACK_RATES (SNDRV_PCM_RATE_8000_48000 |\
655 SNDRV_PCM_RATE_96000 |\
656 SNDRV_PCM_RATE_192000)
658 #define MTK_ADDA_CAPTURE_RATES (SNDRV_PCM_RATE_8000 |\
659 SNDRV_PCM_RATE_16000 |\
660 SNDRV_PCM_RATE_32000 |\
661 SNDRV_PCM_RATE_48000 |\
662 SNDRV_PCM_RATE_96000 |\
663 SNDRV_PCM_RATE_192000)
665 #define MTK_ADDA_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
666 SNDRV_PCM_FMTBIT_S24_LE |\
667 SNDRV_PCM_FMTBIT_S32_LE)
669 static struct snd_soc_dai_driver mtk_dai_adda_driver
[] = {
672 .id
= MT8195_AFE_IO_DL_SRC
,
674 .stream_name
= "ADDA Playback",
677 .rates
= MTK_ADDA_PLAYBACK_RATES
,
678 .formats
= MTK_ADDA_FORMATS
,
680 .ops
= &mtk_dai_adda_ops
,
684 .id
= MT8195_AFE_IO_UL_SRC1
,
686 .stream_name
= "ADDA Capture",
689 .rates
= MTK_ADDA_CAPTURE_RATES
,
690 .formats
= MTK_ADDA_FORMATS
,
692 .ops
= &mtk_dai_adda_ops
,
696 .id
= MT8195_AFE_IO_UL_SRC2
,
698 .stream_name
= "ADDA6 Capture",
701 .rates
= MTK_ADDA_CAPTURE_RATES
,
702 .formats
= MTK_ADDA_FORMATS
,
704 .ops
= &mtk_dai_adda_ops
,
708 static int init_adda_priv_data(struct mtk_base_afe
*afe
)
710 struct mt8195_afe_private
*afe_priv
= afe
->platform_priv
;
711 struct mtk_dai_adda_priv
*adda_priv
;
712 static const int adda_dai_list
[] = {
713 MT8195_AFE_IO_DL_SRC
,
714 MT8195_AFE_IO_UL_SRC1
,
715 MT8195_AFE_IO_UL_SRC2
719 for (i
= 0; i
< ARRAY_SIZE(adda_dai_list
); i
++) {
720 adda_priv
= devm_kzalloc(afe
->dev
,
721 sizeof(struct mtk_dai_adda_priv
),
726 afe_priv
->dai_priv
[adda_dai_list
[i
]] = adda_priv
;
732 int mt8195_dai_adda_register(struct mtk_base_afe
*afe
)
734 struct mtk_base_afe_dai
*dai
;
736 dai
= devm_kzalloc(afe
->dev
, sizeof(*dai
), GFP_KERNEL
);
740 list_add(&dai
->list
, &afe
->sub_dais
);
742 dai
->dai_drivers
= mtk_dai_adda_driver
;
743 dai
->num_dai_drivers
= ARRAY_SIZE(mtk_dai_adda_driver
);
745 dai
->dapm_widgets
= mtk_dai_adda_widgets
;
746 dai
->num_dapm_widgets
= ARRAY_SIZE(mtk_dai_adda_widgets
);
747 dai
->dapm_routes
= mtk_dai_adda_routes
;
748 dai
->num_dapm_routes
= ARRAY_SIZE(mtk_dai_adda_routes
);
749 dai
->controls
= mtk_dai_adda_controls
;
750 dai
->num_controls
= ARRAY_SIZE(mtk_dai_adda_controls
);
752 return init_adda_priv_data(afe
);