1 // SPDX-License-Identifier: GPL-2.0
3 // MediaTek ALSA SoC Audio DAI ADDA Control
5 // Copyright (c) 2020 MediaTek Inc.
6 // Author: Shane Chien <shane.chien@mediatek.com>
9 #include <linux/delay.h>
10 #include <linux/regmap.h>
12 #include "mt8192-afe-clk.h"
13 #include "mt8192-afe-common.h"
14 #include "mt8192-afe-gpio.h"
15 #include "mt8192-interconnection.h"
27 AUDIO_SDM_LEVEL_MUTE
= 0,
28 AUDIO_SDM_LEVEL_NORMAL
= 0x1d,
29 /* if you change level normal */
30 /* you need to change formula of hp impedance and dc trim too */
44 MTK_AFE_ADDA_DL_RATE_8K
= 0,
45 MTK_AFE_ADDA_DL_RATE_11K
= 1,
46 MTK_AFE_ADDA_DL_RATE_12K
= 2,
47 MTK_AFE_ADDA_DL_RATE_16K
= 3,
48 MTK_AFE_ADDA_DL_RATE_22K
= 4,
49 MTK_AFE_ADDA_DL_RATE_24K
= 5,
50 MTK_AFE_ADDA_DL_RATE_32K
= 6,
51 MTK_AFE_ADDA_DL_RATE_44K
= 7,
52 MTK_AFE_ADDA_DL_RATE_48K
= 8,
53 MTK_AFE_ADDA_DL_RATE_96K
= 9,
54 MTK_AFE_ADDA_DL_RATE_192K
= 10,
58 MTK_AFE_ADDA_UL_RATE_8K
= 0,
59 MTK_AFE_ADDA_UL_RATE_16K
= 1,
60 MTK_AFE_ADDA_UL_RATE_32K
= 2,
61 MTK_AFE_ADDA_UL_RATE_48K
= 3,
62 MTK_AFE_ADDA_UL_RATE_96K
= 4,
63 MTK_AFE_ADDA_UL_RATE_192K
= 5,
64 MTK_AFE_ADDA_UL_RATE_48K_HD
= 6,
67 #define SDM_AUTO_RESET_THRESHOLD 0x190000
69 static unsigned int adda_dl_rate_transform(struct mtk_base_afe
*afe
,
74 return MTK_AFE_ADDA_DL_RATE_8K
;
76 return MTK_AFE_ADDA_DL_RATE_11K
;
78 return MTK_AFE_ADDA_DL_RATE_12K
;
80 return MTK_AFE_ADDA_DL_RATE_16K
;
82 return MTK_AFE_ADDA_DL_RATE_22K
;
84 return MTK_AFE_ADDA_DL_RATE_24K
;
86 return MTK_AFE_ADDA_DL_RATE_32K
;
88 return MTK_AFE_ADDA_DL_RATE_44K
;
90 return MTK_AFE_ADDA_DL_RATE_48K
;
92 return MTK_AFE_ADDA_DL_RATE_96K
;
94 return MTK_AFE_ADDA_DL_RATE_192K
;
96 dev_warn(afe
->dev
, "%s(), rate %d invalid, use 48kHz!!!\n",
98 return MTK_AFE_ADDA_DL_RATE_48K
;
102 static unsigned int adda_ul_rate_transform(struct mtk_base_afe
*afe
,
107 return MTK_AFE_ADDA_UL_RATE_8K
;
109 return MTK_AFE_ADDA_UL_RATE_16K
;
111 return MTK_AFE_ADDA_UL_RATE_32K
;
113 return MTK_AFE_ADDA_UL_RATE_48K
;
115 return MTK_AFE_ADDA_UL_RATE_96K
;
117 return MTK_AFE_ADDA_UL_RATE_192K
;
119 dev_warn(afe
->dev
, "%s(), rate %d invalid, use 48kHz!!!\n",
121 return MTK_AFE_ADDA_UL_RATE_48K
;
126 static const struct snd_kcontrol_new mtk_adda_dl_ch1_mix
[] = {
127 SOC_DAPM_SINGLE_AUTODISABLE("DL1_CH1", AFE_CONN3
, I_DL1_CH1
, 1, 0),
128 SOC_DAPM_SINGLE_AUTODISABLE("DL12_CH1", AFE_CONN3
, I_DL12_CH1
, 1, 0),
129 SOC_DAPM_SINGLE_AUTODISABLE("DL2_CH1", AFE_CONN3
, I_DL2_CH1
, 1, 0),
130 SOC_DAPM_SINGLE_AUTODISABLE("DL3_CH1", AFE_CONN3
, I_DL3_CH1
, 1, 0),
131 SOC_DAPM_SINGLE_AUTODISABLE("DL4_CH1", AFE_CONN3_1
, I_DL4_CH1
, 1, 0),
132 SOC_DAPM_SINGLE_AUTODISABLE("DL5_CH1", AFE_CONN3_1
, I_DL5_CH1
, 1, 0),
133 SOC_DAPM_SINGLE_AUTODISABLE("DL6_CH1", AFE_CONN3_1
, I_DL6_CH1
, 1, 0),
134 SOC_DAPM_SINGLE_AUTODISABLE("DL8_CH1", AFE_CONN3_1
, I_DL8_CH1
, 1, 0),
135 SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH3", AFE_CONN3
,
136 I_ADDA_UL_CH3
, 1, 0),
137 SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH2", AFE_CONN3
,
138 I_ADDA_UL_CH2
, 1, 0),
139 SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH1", AFE_CONN3
,
140 I_ADDA_UL_CH1
, 1, 0),
141 SOC_DAPM_SINGLE_AUTODISABLE("GAIN1_OUT_CH1", AFE_CONN3
,
142 I_GAIN1_OUT_CH1
, 1, 0),
143 SOC_DAPM_SINGLE_AUTODISABLE("PCM_1_CAP_CH1", AFE_CONN3
,
144 I_PCM_1_CAP_CH1
, 1, 0),
145 SOC_DAPM_SINGLE_AUTODISABLE("PCM_2_CAP_CH1", AFE_CONN3
,
146 I_PCM_2_CAP_CH1
, 1, 0),
147 SOC_DAPM_SINGLE_AUTODISABLE("SRC_1_OUT_CH1", AFE_CONN3_1
,
148 I_SRC_1_OUT_CH1
, 1, 0),
149 SOC_DAPM_SINGLE_AUTODISABLE("SRC_2_OUT_CH1", AFE_CONN3_1
,
150 I_SRC_2_OUT_CH1
, 1, 0),
153 static const struct snd_kcontrol_new mtk_adda_dl_ch2_mix
[] = {
154 SOC_DAPM_SINGLE_AUTODISABLE("DL1_CH1", AFE_CONN4
, I_DL1_CH1
, 1, 0),
155 SOC_DAPM_SINGLE_AUTODISABLE("DL1_CH2", AFE_CONN4
, I_DL1_CH2
, 1, 0),
156 SOC_DAPM_SINGLE_AUTODISABLE("DL12_CH2", AFE_CONN4
, I_DL12_CH2
, 1, 0),
157 SOC_DAPM_SINGLE_AUTODISABLE("DL2_CH1", AFE_CONN4
, I_DL2_CH1
, 1, 0),
158 SOC_DAPM_SINGLE_AUTODISABLE("DL2_CH2", AFE_CONN4
, I_DL2_CH2
, 1, 0),
159 SOC_DAPM_SINGLE_AUTODISABLE("DL3_CH1", AFE_CONN4
, I_DL3_CH1
, 1, 0),
160 SOC_DAPM_SINGLE_AUTODISABLE("DL3_CH2", AFE_CONN4
, I_DL3_CH2
, 1, 0),
161 SOC_DAPM_SINGLE_AUTODISABLE("DL4_CH2", AFE_CONN4_1
, I_DL4_CH2
, 1, 0),
162 SOC_DAPM_SINGLE_AUTODISABLE("DL5_CH2", AFE_CONN4_1
, I_DL5_CH2
, 1, 0),
163 SOC_DAPM_SINGLE_AUTODISABLE("DL6_CH2", AFE_CONN4_1
, I_DL6_CH2
, 1, 0),
164 SOC_DAPM_SINGLE_AUTODISABLE("DL8_CH2", AFE_CONN4_1
, I_DL8_CH2
, 1, 0),
165 SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH3", AFE_CONN4
,
166 I_ADDA_UL_CH3
, 1, 0),
167 SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH2", AFE_CONN4
,
168 I_ADDA_UL_CH2
, 1, 0),
169 SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH1", AFE_CONN4
,
170 I_ADDA_UL_CH1
, 1, 0),
171 SOC_DAPM_SINGLE_AUTODISABLE("GAIN1_OUT_CH2", AFE_CONN4
,
172 I_GAIN1_OUT_CH2
, 1, 0),
173 SOC_DAPM_SINGLE_AUTODISABLE("PCM_1_CAP_CH1", AFE_CONN4
,
174 I_PCM_1_CAP_CH1
, 1, 0),
175 SOC_DAPM_SINGLE_AUTODISABLE("PCM_2_CAP_CH1", AFE_CONN4
,
176 I_PCM_2_CAP_CH1
, 1, 0),
177 SOC_DAPM_SINGLE_AUTODISABLE("PCM_1_CAP_CH2", AFE_CONN4
,
178 I_PCM_1_CAP_CH2
, 1, 0),
179 SOC_DAPM_SINGLE_AUTODISABLE("PCM_2_CAP_CH2", AFE_CONN4
,
180 I_PCM_2_CAP_CH2
, 1, 0),
181 SOC_DAPM_SINGLE_AUTODISABLE("SRC_1_OUT_CH2", AFE_CONN4_1
,
182 I_SRC_1_OUT_CH2
, 1, 0),
183 SOC_DAPM_SINGLE_AUTODISABLE("SRC_2_OUT_CH2", AFE_CONN4_1
,
184 I_SRC_2_OUT_CH2
, 1, 0),
187 static const struct snd_kcontrol_new mtk_adda_dl_ch3_mix
[] = {
188 SOC_DAPM_SINGLE_AUTODISABLE("DL1_CH1", AFE_CONN52
, I_DL1_CH1
, 1, 0),
189 SOC_DAPM_SINGLE_AUTODISABLE("DL12_CH1", AFE_CONN52
, I_DL12_CH1
, 1, 0),
190 SOC_DAPM_SINGLE_AUTODISABLE("DL2_CH1", AFE_CONN52
, I_DL2_CH1
, 1, 0),
191 SOC_DAPM_SINGLE_AUTODISABLE("DL3_CH1", AFE_CONN52
, I_DL3_CH1
, 1, 0),
192 SOC_DAPM_SINGLE_AUTODISABLE("DL4_CH1", AFE_CONN52_1
, I_DL4_CH1
, 1, 0),
193 SOC_DAPM_SINGLE_AUTODISABLE("DL5_CH1", AFE_CONN52_1
, I_DL5_CH1
, 1, 0),
194 SOC_DAPM_SINGLE_AUTODISABLE("DL6_CH1", AFE_CONN52_1
, I_DL6_CH1
, 1, 0),
195 SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH3", AFE_CONN52
,
196 I_ADDA_UL_CH3
, 1, 0),
197 SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH2", AFE_CONN52
,
198 I_ADDA_UL_CH2
, 1, 0),
199 SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH1", AFE_CONN52
,
200 I_ADDA_UL_CH1
, 1, 0),
201 SOC_DAPM_SINGLE_AUTODISABLE("GAIN1_OUT_CH1", AFE_CONN52
,
202 I_GAIN1_OUT_CH1
, 1, 0),
203 SOC_DAPM_SINGLE_AUTODISABLE("PCM_1_CAP_CH1", AFE_CONN52
,
204 I_PCM_1_CAP_CH1
, 1, 0),
205 SOC_DAPM_SINGLE_AUTODISABLE("PCM_2_CAP_CH1", AFE_CONN52
,
206 I_PCM_2_CAP_CH1
, 1, 0),
209 static const struct snd_kcontrol_new mtk_adda_dl_ch4_mix
[] = {
210 SOC_DAPM_SINGLE_AUTODISABLE("DL1_CH1", AFE_CONN53
, I_DL1_CH1
, 1, 0),
211 SOC_DAPM_SINGLE_AUTODISABLE("DL1_CH2", AFE_CONN53
, I_DL1_CH2
, 1, 0),
212 SOC_DAPM_SINGLE_AUTODISABLE("DL12_CH2", AFE_CONN53
, I_DL12_CH2
, 1, 0),
213 SOC_DAPM_SINGLE_AUTODISABLE("DL2_CH1", AFE_CONN53
, I_DL2_CH1
, 1, 0),
214 SOC_DAPM_SINGLE_AUTODISABLE("DL2_CH2", AFE_CONN53
, I_DL2_CH2
, 1, 0),
215 SOC_DAPM_SINGLE_AUTODISABLE("DL3_CH1", AFE_CONN53
, I_DL3_CH1
, 1, 0),
216 SOC_DAPM_SINGLE_AUTODISABLE("DL3_CH2", AFE_CONN53
, I_DL3_CH2
, 1, 0),
217 SOC_DAPM_SINGLE_AUTODISABLE("DL4_CH2", AFE_CONN53_1
, I_DL4_CH2
, 1, 0),
218 SOC_DAPM_SINGLE_AUTODISABLE("DL5_CH2", AFE_CONN53_1
, I_DL5_CH2
, 1, 0),
219 SOC_DAPM_SINGLE_AUTODISABLE("DL6_CH2", AFE_CONN53_1
, I_DL6_CH1
, 1, 0),
220 SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH3", AFE_CONN53
,
221 I_ADDA_UL_CH3
, 1, 0),
222 SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH2", AFE_CONN53
,
223 I_ADDA_UL_CH2
, 1, 0),
224 SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH1", AFE_CONN53
,
225 I_ADDA_UL_CH1
, 1, 0),
226 SOC_DAPM_SINGLE_AUTODISABLE("GAIN1_OUT_CH2", AFE_CONN53
,
227 I_GAIN1_OUT_CH2
, 1, 0),
228 SOC_DAPM_SINGLE_AUTODISABLE("PCM_1_CAP_CH1", AFE_CONN53
,
229 I_PCM_1_CAP_CH1
, 1, 0),
230 SOC_DAPM_SINGLE_AUTODISABLE("PCM_2_CAP_CH1", AFE_CONN53
,
231 I_PCM_2_CAP_CH1
, 1, 0),
232 SOC_DAPM_SINGLE_AUTODISABLE("PCM_1_CAP_CH2", AFE_CONN53
,
233 I_PCM_1_CAP_CH2
, 1, 0),
234 SOC_DAPM_SINGLE_AUTODISABLE("PCM_2_CAP_CH2", AFE_CONN53
,
235 I_PCM_2_CAP_CH2
, 1, 0),
238 static const struct snd_kcontrol_new mtk_stf_ch1_mix
[] = {
239 SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH1", AFE_CONN19
,
240 I_ADDA_UL_CH1
, 1, 0),
243 static const struct snd_kcontrol_new mtk_stf_ch2_mix
[] = {
244 SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH2", AFE_CONN20
,
245 I_ADDA_UL_CH2
, 1, 0),
249 SUPPLY_SEQ_ADDA_AFE_ON
,
250 SUPPLY_SEQ_ADDA_DL_ON
,
251 SUPPLY_SEQ_ADDA_AUD_PAD_TOP
,
252 SUPPLY_SEQ_ADDA_MTKAIF_CFG
,
253 SUPPLY_SEQ_ADDA6_MTKAIF_CFG
,
254 SUPPLY_SEQ_ADDA_FIFO
,
255 SUPPLY_SEQ_ADDA_AP_DMIC
,
256 SUPPLY_SEQ_ADDA_UL_ON
,
259 static int mtk_adda_ul_src_dmic(struct mtk_base_afe
*afe
, int id
)
264 case MT8192_DAI_ADDA
:
265 case MT8192_DAI_AP_DMIC
:
266 reg
= AFE_ADDA_UL_SRC_CON0
;
268 case MT8192_DAI_ADDA_CH34
:
269 case MT8192_DAI_AP_DMIC_CH34
:
270 reg
= AFE_ADDA6_UL_SRC_CON0
;
276 /* dmic mode, 3.25M*/
277 regmap_update_bits(afe
->regmap
, reg
,
278 DIGMIC_3P25M_1P625M_SEL_CTL_MASK_SFT
,
280 regmap_update_bits(afe
->regmap
, reg
,
281 DMIC_LOW_POWER_MODE_CTL_MASK_SFT
,
284 /* turn on dmic, ch1, ch2 */
285 regmap_update_bits(afe
->regmap
, reg
,
286 UL_SDM_3_LEVEL_CTL_MASK_SFT
,
287 0x1 << UL_SDM_3_LEVEL_CTL_SFT
);
288 regmap_update_bits(afe
->regmap
, reg
,
289 UL_MODE_3P25M_CH1_CTL_MASK_SFT
,
290 0x1 << UL_MODE_3P25M_CH1_CTL_SFT
);
291 regmap_update_bits(afe
->regmap
, reg
,
292 UL_MODE_3P25M_CH2_CTL_MASK_SFT
,
293 0x1 << UL_MODE_3P25M_CH2_CTL_SFT
);
297 static int mtk_adda_ul_event(struct snd_soc_dapm_widget
*w
,
298 struct snd_kcontrol
*kcontrol
,
301 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
302 struct mtk_base_afe
*afe
= snd_soc_component_get_drvdata(cmpnt
);
303 struct mt8192_afe_private
*afe_priv
= afe
->platform_priv
;
304 int mtkaif_dmic
= afe_priv
->mtkaif_dmic
;
306 dev_info(afe
->dev
, "%s(), name %s, event 0x%x, mtkaif_dmic %d\n",
307 __func__
, w
->name
, event
, mtkaif_dmic
);
310 case SND_SOC_DAPM_PRE_PMU
:
311 mt8192_afe_gpio_request(afe
->dev
, true, MT8192_DAI_ADDA
, 1);
313 /* update setting to dmic */
315 /* mtkaif_rxif_data_mode = 1, dmic */
316 regmap_update_bits(afe
->regmap
, AFE_ADDA_MTKAIF_RX_CFG0
,
319 /* dmic mode, 3.25M*/
320 regmap_update_bits(afe
->regmap
, AFE_ADDA_MTKAIF_RX_CFG0
,
321 MTKAIF_RXIF_VOICE_MODE_MASK_SFT
,
323 mtk_adda_ul_src_dmic(afe
, MT8192_DAI_ADDA
);
326 case SND_SOC_DAPM_POST_PMD
:
327 /* should delayed 1/fs(smallest is 8k) = 125us before afe off */
328 usleep_range(125, 135);
329 mt8192_afe_gpio_request(afe
->dev
, false, MT8192_DAI_ADDA
, 1);
338 static int mtk_adda_ch34_ul_event(struct snd_soc_dapm_widget
*w
,
339 struct snd_kcontrol
*kcontrol
,
342 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
343 struct mtk_base_afe
*afe
= snd_soc_component_get_drvdata(cmpnt
);
344 struct mt8192_afe_private
*afe_priv
= afe
->platform_priv
;
345 int mtkaif_dmic
= afe_priv
->mtkaif_dmic_ch34
;
346 int mtkaif_adda6_only
= afe_priv
->mtkaif_adda6_only
;
349 "%s(), name %s, event 0x%x, mtkaif_dmic %d, mtkaif_adda6_only %d\n",
350 __func__
, w
->name
, event
, mtkaif_dmic
, mtkaif_adda6_only
);
353 case SND_SOC_DAPM_PRE_PMU
:
354 mt8192_afe_gpio_request(afe
->dev
, true, MT8192_DAI_ADDA_CH34
,
357 /* update setting to dmic */
359 /* mtkaif_rxif_data_mode = 1, dmic */
360 regmap_update_bits(afe
->regmap
,
361 AFE_ADDA6_MTKAIF_RX_CFG0
,
364 /* dmic mode, 3.25M*/
365 regmap_update_bits(afe
->regmap
,
366 AFE_ADDA6_MTKAIF_RX_CFG0
,
367 MTKAIF_RXIF_VOICE_MODE_MASK_SFT
,
369 mtk_adda_ul_src_dmic(afe
, MT8192_DAI_ADDA_CH34
);
372 /* when using adda6 without adda enabled,
373 * RG_ADDA6_MTKAIF_RX_SYNC_WORD2_DISABLE_SFT need to be set or
374 * data cannot be received.
376 if (mtkaif_adda6_only
) {
377 regmap_update_bits(afe
->regmap
,
378 AFE_ADDA_MTKAIF_SYNCWORD_CFG
,
379 0x1 << 23, 0x1 << 23);
382 case SND_SOC_DAPM_POST_PMD
:
383 /* should delayed 1/fs(smallest is 8k) = 125us before afe off */
384 usleep_range(125, 135);
385 mt8192_afe_gpio_request(afe
->dev
, false, MT8192_DAI_ADDA_CH34
,
389 afe_priv
->mtkaif_dmic_ch34
= 0;
391 if (mtkaif_adda6_only
) {
392 regmap_update_bits(afe
->regmap
,
393 AFE_ADDA_MTKAIF_SYNCWORD_CFG
,
394 0x1 << 23, 0x0 << 23);
404 static int mtk_adda_pad_top_event(struct snd_soc_dapm_widget
*w
,
405 struct snd_kcontrol
*kcontrol
,
408 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
409 struct mtk_base_afe
*afe
= snd_soc_component_get_drvdata(cmpnt
);
410 struct mt8192_afe_private
*afe_priv
= afe
->platform_priv
;
413 case SND_SOC_DAPM_PRE_PMU
:
414 if (afe_priv
->mtkaif_protocol
== MTKAIF_PROTOCOL_2_CLK_P2
)
415 regmap_write(afe
->regmap
, AFE_AUD_PAD_TOP
, 0x38);
416 else if (afe_priv
->mtkaif_protocol
== MTKAIF_PROTOCOL_2
)
417 regmap_write(afe
->regmap
, AFE_AUD_PAD_TOP
, 0x30);
419 regmap_write(afe
->regmap
, AFE_AUD_PAD_TOP
, 0x30);
428 static int mtk_adda_mtkaif_cfg_event(struct snd_soc_dapm_widget
*w
,
429 struct snd_kcontrol
*kcontrol
,
432 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
433 struct mtk_base_afe
*afe
= snd_soc_component_get_drvdata(cmpnt
);
434 struct mt8192_afe_private
*afe_priv
= afe
->platform_priv
;
439 case SND_SOC_DAPM_PRE_PMU
:
440 if (afe_priv
->mtkaif_protocol
== MTKAIF_PROTOCOL_2_CLK_P2
) {
442 regmap_write(afe
->regmap
, AFE_ADDA_MTKAIF_CFG0
,
444 regmap_write(afe
->regmap
, AFE_ADDA6_MTKAIF_CFG0
,
447 if (strcmp(w
->name
, "ADDA_MTKAIF_CFG") == 0 &&
448 (afe_priv
->mtkaif_chosen_phase
[0] < 0 ||
449 afe_priv
->mtkaif_chosen_phase
[1] < 0)) {
451 "%s(), mtkaif_chosen_phase[0/1]:%d/%d\n",
453 afe_priv
->mtkaif_chosen_phase
[0],
454 afe_priv
->mtkaif_chosen_phase
[1]);
456 } else if (strcmp(w
->name
, "ADDA6_MTKAIF_CFG") == 0 &&
457 afe_priv
->mtkaif_chosen_phase
[2] < 0) {
459 "%s(), mtkaif_chosen_phase[2]:%d\n",
461 afe_priv
->mtkaif_chosen_phase
[2]);
465 /* mtkaif_rxif_clkinv_adc inverse for calibration */
466 regmap_update_bits(afe
->regmap
, AFE_ADDA_MTKAIF_CFG0
,
467 MTKAIF_RXIF_CLKINV_ADC_MASK_SFT
,
468 0x1 << MTKAIF_RXIF_CLKINV_ADC_SFT
);
469 regmap_update_bits(afe
->regmap
, AFE_ADDA6_MTKAIF_CFG0
,
470 MTKAIF_RXIF_CLKINV_ADC_MASK_SFT
,
471 0x1 << MTKAIF_RXIF_CLKINV_ADC_SFT
);
473 /* set delay for ch12 */
474 if (afe_priv
->mtkaif_phase_cycle
[0] >=
475 afe_priv
->mtkaif_phase_cycle
[1]) {
476 delay_data
= DELAY_DATA_MISO1
;
477 delay_cycle
= afe_priv
->mtkaif_phase_cycle
[0] -
478 afe_priv
->mtkaif_phase_cycle
[1];
480 delay_data
= DELAY_DATA_MISO2
;
481 delay_cycle
= afe_priv
->mtkaif_phase_cycle
[1] -
482 afe_priv
->mtkaif_phase_cycle
[0];
485 regmap_update_bits(afe
->regmap
,
486 AFE_ADDA_MTKAIF_RX_CFG2
,
487 MTKAIF_RXIF_DELAY_DATA_MASK_SFT
,
489 MTKAIF_RXIF_DELAY_DATA_SFT
);
491 regmap_update_bits(afe
->regmap
,
492 AFE_ADDA_MTKAIF_RX_CFG2
,
493 MTKAIF_RXIF_DELAY_CYCLE_MASK_SFT
,
495 MTKAIF_RXIF_DELAY_CYCLE_SFT
);
497 /* set delay between ch3 and ch2 */
498 if (afe_priv
->mtkaif_phase_cycle
[2] >=
499 afe_priv
->mtkaif_phase_cycle
[1]) {
500 delay_data
= DELAY_DATA_MISO1
; /* ch3 */
501 delay_cycle
= afe_priv
->mtkaif_phase_cycle
[2] -
502 afe_priv
->mtkaif_phase_cycle
[1];
504 delay_data
= DELAY_DATA_MISO2
; /* ch2 */
505 delay_cycle
= afe_priv
->mtkaif_phase_cycle
[1] -
506 afe_priv
->mtkaif_phase_cycle
[2];
509 regmap_update_bits(afe
->regmap
,
510 AFE_ADDA6_MTKAIF_RX_CFG2
,
511 MTKAIF_RXIF_DELAY_DATA_MASK_SFT
,
513 MTKAIF_RXIF_DELAY_DATA_SFT
);
514 regmap_update_bits(afe
->regmap
,
515 AFE_ADDA6_MTKAIF_RX_CFG2
,
516 MTKAIF_RXIF_DELAY_CYCLE_MASK_SFT
,
518 MTKAIF_RXIF_DELAY_CYCLE_SFT
);
519 } else if (afe_priv
->mtkaif_protocol
== MTKAIF_PROTOCOL_2
) {
520 regmap_write(afe
->regmap
, AFE_ADDA_MTKAIF_CFG0
,
522 regmap_write(afe
->regmap
, AFE_ADDA6_MTKAIF_CFG0
,
525 regmap_write(afe
->regmap
, AFE_ADDA_MTKAIF_CFG0
, 0x0);
526 regmap_write(afe
->regmap
, AFE_ADDA6_MTKAIF_CFG0
, 0x0);
536 static int mtk_adda_dl_event(struct snd_soc_dapm_widget
*w
,
537 struct snd_kcontrol
*kcontrol
,
540 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
541 struct mtk_base_afe
*afe
= snd_soc_component_get_drvdata(cmpnt
);
543 dev_info(afe
->dev
, "%s(), name %s, event 0x%x\n",
544 __func__
, w
->name
, event
);
547 case SND_SOC_DAPM_PRE_PMU
:
548 mt8192_afe_gpio_request(afe
->dev
, true, MT8192_DAI_ADDA
, 0);
550 case SND_SOC_DAPM_POST_PMD
:
551 /* should delayed 1/fs(smallest is 8k) = 125us before afe off */
552 usleep_range(125, 135);
553 mt8192_afe_gpio_request(afe
->dev
, false, MT8192_DAI_ADDA
, 0);
562 static int mtk_adda_ch34_dl_event(struct snd_soc_dapm_widget
*w
,
563 struct snd_kcontrol
*kcontrol
,
566 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
567 struct mtk_base_afe
*afe
= snd_soc_component_get_drvdata(cmpnt
);
569 dev_info(afe
->dev
, "%s(), name %s, event 0x%x\n",
570 __func__
, w
->name
, event
);
573 case SND_SOC_DAPM_PRE_PMU
:
574 mt8192_afe_gpio_request(afe
->dev
, true, MT8192_DAI_ADDA_CH34
,
577 case SND_SOC_DAPM_POST_PMD
:
578 /* should delayed 1/fs(smallest is 8k) = 125us before afe off */
579 usleep_range(125, 135);
580 mt8192_afe_gpio_request(afe
->dev
, false, MT8192_DAI_ADDA_CH34
,
591 static int stf_positive_gain_get(struct snd_kcontrol
*kcontrol
,
592 struct snd_ctl_elem_value
*ucontrol
)
594 struct snd_soc_component
*cmpnt
= snd_soc_kcontrol_component(kcontrol
);
595 struct mtk_base_afe
*afe
= snd_soc_component_get_drvdata(cmpnt
);
596 struct mt8192_afe_private
*afe_priv
= afe
->platform_priv
;
598 ucontrol
->value
.integer
.value
[0] = afe_priv
->stf_positive_gain_db
;
602 static int stf_positive_gain_set(struct snd_kcontrol
*kcontrol
,
603 struct snd_ctl_elem_value
*ucontrol
)
605 struct snd_soc_component
*cmpnt
= snd_soc_kcontrol_component(kcontrol
);
606 struct mtk_base_afe
*afe
= snd_soc_component_get_drvdata(cmpnt
);
607 struct mt8192_afe_private
*afe_priv
= afe
->platform_priv
;
608 int gain_db
= ucontrol
->value
.integer
.value
[0];
610 afe_priv
->stf_positive_gain_db
= gain_db
;
612 if (gain_db
>= 0 && gain_db
<= 24) {
613 regmap_update_bits(afe
->regmap
,
615 POSITIVE_GAIN_MASK_SFT
,
616 (gain_db
/ 6) << POSITIVE_GAIN_SFT
);
618 dev_warn(afe
->dev
, "%s(), gain_db %d invalid\n",
624 static int mt8192_adda_dmic_get(struct snd_kcontrol
*kcontrol
,
625 struct snd_ctl_elem_value
*ucontrol
)
627 struct snd_soc_component
*cmpnt
= snd_soc_kcontrol_component(kcontrol
);
628 struct mtk_base_afe
*afe
= snd_soc_component_get_drvdata(cmpnt
);
629 struct mt8192_afe_private
*afe_priv
= afe
->platform_priv
;
631 ucontrol
->value
.integer
.value
[0] = afe_priv
->mtkaif_dmic
;
635 static int mt8192_adda_dmic_set(struct snd_kcontrol
*kcontrol
,
636 struct snd_ctl_elem_value
*ucontrol
)
638 struct snd_soc_component
*cmpnt
= snd_soc_kcontrol_component(kcontrol
);
639 struct mtk_base_afe
*afe
= snd_soc_component_get_drvdata(cmpnt
);
640 struct mt8192_afe_private
*afe_priv
= afe
->platform_priv
;
643 dmic_on
= ucontrol
->value
.integer
.value
[0];
645 dev_info(afe
->dev
, "%s(), kcontrol name %s, dmic_on %d\n",
646 __func__
, kcontrol
->id
.name
, dmic_on
);
648 afe_priv
->mtkaif_dmic
= dmic_on
;
649 afe_priv
->mtkaif_dmic_ch34
= dmic_on
;
653 static int mt8192_adda6_only_get(struct snd_kcontrol
*kcontrol
,
654 struct snd_ctl_elem_value
*ucontrol
)
656 struct snd_soc_component
*cmpnt
= snd_soc_kcontrol_component(kcontrol
);
657 struct mtk_base_afe
*afe
= snd_soc_component_get_drvdata(cmpnt
);
658 struct mt8192_afe_private
*afe_priv
= afe
->platform_priv
;
660 ucontrol
->value
.integer
.value
[0] = afe_priv
->mtkaif_adda6_only
;
664 static int mt8192_adda6_only_set(struct snd_kcontrol
*kcontrol
,
665 struct snd_ctl_elem_value
*ucontrol
)
667 struct snd_soc_component
*cmpnt
= snd_soc_kcontrol_component(kcontrol
);
668 struct mtk_base_afe
*afe
= snd_soc_component_get_drvdata(cmpnt
);
669 struct mt8192_afe_private
*afe_priv
= afe
->platform_priv
;
670 int mtkaif_adda6_only
;
672 mtkaif_adda6_only
= ucontrol
->value
.integer
.value
[0];
674 dev_info(afe
->dev
, "%s(), kcontrol name %s, mtkaif_adda6_only %d\n",
675 __func__
, kcontrol
->id
.name
, mtkaif_adda6_only
);
677 afe_priv
->mtkaif_adda6_only
= mtkaif_adda6_only
;
681 static const struct snd_kcontrol_new mtk_adda_controls
[] = {
682 SOC_SINGLE("Sidetone_Gain", AFE_SIDETONE_GAIN
,
683 SIDE_TONE_GAIN_SFT
, SIDE_TONE_GAIN_MASK
, 0),
684 SOC_SINGLE_EXT("Sidetone_Positive_Gain_dB", SND_SOC_NOPM
, 0, 100, 0,
685 stf_positive_gain_get
, stf_positive_gain_set
),
686 SOC_SINGLE("ADDA_DL_GAIN", AFE_ADDA_DL_SRC2_CON1
,
687 DL_2_GAIN_CTL_PRE_SFT
, DL_2_GAIN_CTL_PRE_MASK
, 0),
688 SOC_SINGLE_BOOL_EXT("MTKAIF_DMIC Switch", 0,
689 mt8192_adda_dmic_get
, mt8192_adda_dmic_set
),
690 SOC_SINGLE_BOOL_EXT("MTKAIF_ADDA6_ONLY Switch", 0,
691 mt8192_adda6_only_get
, mt8192_adda6_only_set
),
694 static const struct snd_kcontrol_new stf_ctl
=
695 SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM
, 0, 1, 0);
697 static const u16 stf_coeff_table_16k
[] = {
698 0x049C, 0x09E8, 0x09E0, 0x089C,
699 0xFF54, 0xF488, 0xEAFC, 0xEBAC,
700 0xfA40, 0x17AC, 0x3D1C, 0x6028,
704 static const u16 stf_coeff_table_32k
[] = {
705 0xFE52, 0x0042, 0x00C5, 0x0194,
706 0x029A, 0x03B7, 0x04BF, 0x057D,
707 0x05BE, 0x0555, 0x0426, 0x0230,
708 0xFF92, 0xFC89, 0xF973, 0xF6C6,
709 0xF500, 0xF49D, 0xF603, 0xF970,
710 0xFEF3, 0x065F, 0x0F4F, 0x1928,
711 0x2329, 0x2C80, 0x345E, 0x3A0D,
715 static const u16 stf_coeff_table_48k
[] = {
716 0x0401, 0xFFB0, 0xFF5A, 0xFECE,
717 0xFE10, 0xFD28, 0xFC21, 0xFB08,
718 0xF9EF, 0xF8E8, 0xF80A, 0xF76C,
719 0xF724, 0xF746, 0xF7E6, 0xF90F,
720 0xFACC, 0xFD1E, 0xFFFF, 0x0364,
721 0x0737, 0x0B62, 0x0FC1, 0x1431,
722 0x188A, 0x1CA4, 0x2056, 0x237D,
723 0x25F9, 0x27B0, 0x2890
726 static int mtk_stf_event(struct snd_soc_dapm_widget
*w
,
727 struct snd_kcontrol
*kcontrol
,
730 struct snd_soc_component
*cmpnt
= snd_soc_dapm_to_component(w
->dapm
);
731 struct mtk_base_afe
*afe
= snd_soc_component_get_drvdata(cmpnt
);
734 const u16
*stf_coeff_table
;
735 unsigned int ul_rate
, reg_value
;
738 regmap_read(afe
->regmap
, AFE_ADDA_UL_SRC_CON0
, &ul_rate
);
739 ul_rate
= ul_rate
>> UL_VOICE_MODE_CH1_CH2_CTL_SFT
;
740 ul_rate
= ul_rate
& UL_VOICE_MODE_CH1_CH2_CTL_MASK
;
742 if (ul_rate
== MTK_AFE_ADDA_UL_RATE_48K
) {
743 half_tap_num
= ARRAY_SIZE(stf_coeff_table_48k
);
744 stf_coeff_table
= stf_coeff_table_48k
;
745 } else if (ul_rate
== MTK_AFE_ADDA_UL_RATE_32K
) {
746 half_tap_num
= ARRAY_SIZE(stf_coeff_table_32k
);
747 stf_coeff_table
= stf_coeff_table_32k
;
749 half_tap_num
= ARRAY_SIZE(stf_coeff_table_16k
);
750 stf_coeff_table
= stf_coeff_table_16k
;
753 regmap_read(afe
->regmap
, AFE_SIDETONE_CON1
, ®_value
);
755 dev_info(afe
->dev
, "%s(), name %s, event 0x%x, ul_rate 0x%x, AFE_SIDETONE_CON1 0x%x\n",
756 __func__
, w
->name
, event
, ul_rate
, reg_value
);
759 case SND_SOC_DAPM_PRE_PMU
:
760 /* set side tone gain = 0 */
761 regmap_update_bits(afe
->regmap
,
763 SIDE_TONE_GAIN_MASK_SFT
,
765 regmap_update_bits(afe
->regmap
,
767 POSITIVE_GAIN_MASK_SFT
,
769 /* don't bypass stf */
770 regmap_update_bits(afe
->regmap
,
774 /* set stf half tap num */
775 regmap_update_bits(afe
->regmap
,
777 SIDE_TONE_HALF_TAP_NUM_MASK_SFT
,
778 half_tap_num
<< SIDE_TONE_HALF_TAP_NUM_SFT
);
780 /* set side tone coefficient */
781 regmap_read(afe
->regmap
, AFE_SIDETONE_CON0
, ®_value
);
782 for (coef_addr
= 0; coef_addr
< half_tap_num
; coef_addr
++) {
783 bool old_w_ready
= (reg_value
>> W_RDY_SFT
) & 0x1;
784 bool new_w_ready
= 0;
787 regmap_update_bits(afe
->regmap
,
794 SIDE_TONE_COEFFICIENT_ADDR_SFT
) |
795 stf_coeff_table
[coef_addr
]);
797 /* wait until flag write_ready changed */
798 for (try_cnt
= 0; try_cnt
< 10; try_cnt
++) {
799 regmap_read(afe
->regmap
,
800 AFE_SIDETONE_CON0
, ®_value
);
801 new_w_ready
= (reg_value
>> W_RDY_SFT
) & 0x1;
804 if (new_w_ready
== old_w_ready
) {
808 "%s(), write coeff not ready",
815 /* need write -> read -> write to write next coeff */
816 regmap_update_bits(afe
->regmap
,
822 case SND_SOC_DAPM_POST_PMD
:
824 regmap_update_bits(afe
->regmap
,
829 /* set side tone gain = 0 */
830 regmap_update_bits(afe
->regmap
,
832 SIDE_TONE_GAIN_MASK_SFT
,
834 regmap_update_bits(afe
->regmap
,
836 POSITIVE_GAIN_MASK_SFT
,
848 STF_SRC_ADDA_ADDA6
= 0,
852 static const char *const stf_o19o20_mux_map
[] = {
857 static int stf_o19o20_mux_map_value
[] = {
862 static SOC_VALUE_ENUM_SINGLE_DECL(stf_o19o20_mux_map_enum
,
864 STF_SOURCE_FROM_O19O20_SFT
,
865 STF_SOURCE_FROM_O19O20_MASK
,
867 stf_o19o20_mux_map_value
);
869 static const struct snd_kcontrol_new stf_o19O20_mux_control
=
870 SOC_DAPM_ENUM("STF_O19O20_MUX", stf_o19o20_mux_map_enum
);
877 static const char *const stf_adda_mux_map
[] = {
882 static int stf_adda_mux_map_value
[] = {
887 static SOC_VALUE_ENUM_SINGLE_DECL(stf_adda_mux_map_enum
,
889 STF_O19O20_OUT_EN_SEL_SFT
,
890 STF_O19O20_OUT_EN_SEL_MASK
,
892 stf_adda_mux_map_value
);
894 static const struct snd_kcontrol_new stf_adda_mux_control
=
895 SOC_DAPM_ENUM("STF_ADDA_MUX", stf_adda_mux_map_enum
);
899 ADDA_UL_MUX_MTKAIF
= 0,
901 ADDA_UL_MUX_MASK
= 0x1,
904 static const char * const adda_ul_mux_map
[] = {
908 static int adda_ul_map_value
[] = {
913 static SOC_VALUE_ENUM_SINGLE_DECL(adda_ul_mux_map_enum
,
920 static const struct snd_kcontrol_new adda_ul_mux_control
=
921 SOC_DAPM_ENUM("ADDA_UL_MUX Select", adda_ul_mux_map_enum
);
923 static const struct snd_kcontrol_new adda_ch34_ul_mux_control
=
924 SOC_DAPM_ENUM("ADDA_CH34_UL_MUX Select", adda_ul_mux_map_enum
);
926 static const struct snd_soc_dapm_widget mtk_dai_adda_widgets
[] = {
927 /* inter-connections */
928 SND_SOC_DAPM_MIXER("ADDA_DL_CH1", SND_SOC_NOPM
, 0, 0,
930 ARRAY_SIZE(mtk_adda_dl_ch1_mix
)),
931 SND_SOC_DAPM_MIXER("ADDA_DL_CH2", SND_SOC_NOPM
, 0, 0,
933 ARRAY_SIZE(mtk_adda_dl_ch2_mix
)),
935 SND_SOC_DAPM_MIXER("ADDA_DL_CH3", SND_SOC_NOPM
, 0, 0,
937 ARRAY_SIZE(mtk_adda_dl_ch3_mix
)),
938 SND_SOC_DAPM_MIXER("ADDA_DL_CH4", SND_SOC_NOPM
, 0, 0,
940 ARRAY_SIZE(mtk_adda_dl_ch4_mix
)),
942 SND_SOC_DAPM_SUPPLY_S("ADDA Enable", SUPPLY_SEQ_ADDA_AFE_ON
,
943 AFE_ADDA_UL_DL_CON0
, ADDA_AFE_ON_SFT
, 0,
946 SND_SOC_DAPM_SUPPLY_S("ADDA Playback Enable", SUPPLY_SEQ_ADDA_DL_ON
,
947 AFE_ADDA_DL_SRC2_CON0
,
948 DL_2_SRC_ON_TMP_CTL_PRE_SFT
, 0,
950 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
951 SND_SOC_DAPM_SUPPLY_S("ADDA CH34 Playback Enable",
952 SUPPLY_SEQ_ADDA_DL_ON
,
953 AFE_ADDA_3RD_DAC_DL_SRC2_CON0
,
954 DL_2_SRC_ON_TMP_CTL_PRE_SFT
, 0,
955 mtk_adda_ch34_dl_event
,
956 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
958 SND_SOC_DAPM_SUPPLY_S("ADDA Capture Enable", SUPPLY_SEQ_ADDA_UL_ON
,
959 AFE_ADDA_UL_SRC_CON0
,
960 UL_SRC_ON_TMP_CTL_SFT
, 0,
962 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
963 SND_SOC_DAPM_SUPPLY_S("ADDA CH34 Capture Enable", SUPPLY_SEQ_ADDA_UL_ON
,
964 AFE_ADDA6_UL_SRC_CON0
,
965 UL_SRC_ON_TMP_CTL_SFT
, 0,
966 mtk_adda_ch34_ul_event
,
967 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
969 SND_SOC_DAPM_SUPPLY_S("AUD_PAD_TOP", SUPPLY_SEQ_ADDA_AUD_PAD_TOP
,
971 RG_RX_FIFO_ON_SFT
, 0,
972 mtk_adda_pad_top_event
,
973 SND_SOC_DAPM_PRE_PMU
),
974 SND_SOC_DAPM_SUPPLY_S("ADDA_MTKAIF_CFG", SUPPLY_SEQ_ADDA_MTKAIF_CFG
,
976 mtk_adda_mtkaif_cfg_event
,
977 SND_SOC_DAPM_PRE_PMU
),
978 SND_SOC_DAPM_SUPPLY_S("ADDA6_MTKAIF_CFG", SUPPLY_SEQ_ADDA6_MTKAIF_CFG
,
980 mtk_adda_mtkaif_cfg_event
,
981 SND_SOC_DAPM_PRE_PMU
),
983 SND_SOC_DAPM_SUPPLY_S("AP_DMIC_EN", SUPPLY_SEQ_ADDA_AP_DMIC
,
984 AFE_ADDA_UL_SRC_CON0
,
985 UL_AP_DMIC_ON_SFT
, 0,
987 SND_SOC_DAPM_SUPPLY_S("AP_DMIC_CH34_EN", SUPPLY_SEQ_ADDA_AP_DMIC
,
988 AFE_ADDA6_UL_SRC_CON0
,
989 UL_AP_DMIC_ON_SFT
, 0,
992 SND_SOC_DAPM_SUPPLY_S("ADDA_FIFO", SUPPLY_SEQ_ADDA_FIFO
,
994 AFE_ADDA_FIFO_AUTO_RST_SFT
, 1,
996 SND_SOC_DAPM_SUPPLY_S("ADDA_CH34_FIFO", SUPPLY_SEQ_ADDA_FIFO
,
998 AFE_ADDA6_FIFO_AUTO_RST_SFT
, 1,
1001 SND_SOC_DAPM_MUX("ADDA_UL_Mux", SND_SOC_NOPM
, 0, 0,
1002 &adda_ul_mux_control
),
1003 SND_SOC_DAPM_MUX("ADDA_CH34_UL_Mux", SND_SOC_NOPM
, 0, 0,
1004 &adda_ch34_ul_mux_control
),
1006 SND_SOC_DAPM_INPUT("AP_DMIC_INPUT"),
1007 SND_SOC_DAPM_INPUT("AP_DMIC_CH34_INPUT"),
1010 SND_SOC_DAPM_SWITCH_E("Sidetone Filter",
1011 AFE_SIDETONE_CON1
, SIDE_TONE_ON_SFT
, 0,
1014 SND_SOC_DAPM_PRE_PMU
|
1015 SND_SOC_DAPM_POST_PMD
),
1016 SND_SOC_DAPM_MUX("STF_O19O20_MUX", SND_SOC_NOPM
, 0, 0,
1017 &stf_o19O20_mux_control
),
1018 SND_SOC_DAPM_MUX("STF_ADDA_MUX", SND_SOC_NOPM
, 0, 0,
1019 &stf_adda_mux_control
),
1020 SND_SOC_DAPM_MIXER("STF_CH1", SND_SOC_NOPM
, 0, 0,
1022 ARRAY_SIZE(mtk_stf_ch1_mix
)),
1023 SND_SOC_DAPM_MIXER("STF_CH2", SND_SOC_NOPM
, 0, 0,
1025 ARRAY_SIZE(mtk_stf_ch2_mix
)),
1026 SND_SOC_DAPM_OUTPUT("STF_OUTPUT"),
1029 SND_SOC_DAPM_CLOCK_SUPPLY("top_mux_audio_h"),
1031 SND_SOC_DAPM_CLOCK_SUPPLY("aud_dac_clk"),
1032 SND_SOC_DAPM_CLOCK_SUPPLY("aud_dac_predis_clk"),
1033 SND_SOC_DAPM_CLOCK_SUPPLY("aud_3rd_dac_clk"),
1034 SND_SOC_DAPM_CLOCK_SUPPLY("aud_3rd_dac_predis_clk"),
1036 SND_SOC_DAPM_CLOCK_SUPPLY("aud_adc_clk"),
1037 SND_SOC_DAPM_CLOCK_SUPPLY("aud_adda6_adc_clk"),
1040 static const struct snd_soc_dapm_route mtk_dai_adda_routes
[] = {
1042 {"ADDA_DL_CH1", "DL1_CH1", "DL1"},
1043 {"ADDA_DL_CH2", "DL1_CH1", "DL1"},
1044 {"ADDA_DL_CH2", "DL1_CH2", "DL1"},
1046 {"ADDA_DL_CH1", "DL12_CH1", "DL12"},
1047 {"ADDA_DL_CH2", "DL12_CH2", "DL12"},
1049 {"ADDA_DL_CH1", "DL6_CH1", "DL6"},
1050 {"ADDA_DL_CH2", "DL6_CH2", "DL6"},
1052 {"ADDA_DL_CH1", "DL8_CH1", "DL8"},
1053 {"ADDA_DL_CH2", "DL8_CH2", "DL8"},
1055 {"ADDA_DL_CH1", "DL2_CH1", "DL2"},
1056 {"ADDA_DL_CH2", "DL2_CH1", "DL2"},
1057 {"ADDA_DL_CH2", "DL2_CH2", "DL2"},
1059 {"ADDA_DL_CH1", "DL3_CH1", "DL3"},
1060 {"ADDA_DL_CH2", "DL3_CH1", "DL3"},
1061 {"ADDA_DL_CH2", "DL3_CH2", "DL3"},
1063 {"ADDA_DL_CH1", "DL4_CH1", "DL4"},
1064 {"ADDA_DL_CH2", "DL4_CH2", "DL4"},
1066 {"ADDA_DL_CH1", "DL5_CH1", "DL5"},
1067 {"ADDA_DL_CH2", "DL5_CH2", "DL5"},
1069 {"ADDA Playback", NULL
, "ADDA_DL_CH1"},
1070 {"ADDA Playback", NULL
, "ADDA_DL_CH2"},
1072 {"ADDA Playback", NULL
, "ADDA Enable"},
1073 {"ADDA Playback", NULL
, "ADDA Playback Enable"},
1075 {"ADDA_DL_CH3", "DL1_CH1", "DL1"},
1076 {"ADDA_DL_CH4", "DL1_CH1", "DL1"},
1077 {"ADDA_DL_CH4", "DL1_CH2", "DL1"},
1079 {"ADDA_DL_CH3", "DL12_CH1", "DL12"},
1080 {"ADDA_DL_CH4", "DL12_CH2", "DL12"},
1082 {"ADDA_DL_CH3", "DL6_CH1", "DL6"},
1083 {"ADDA_DL_CH4", "DL6_CH2", "DL6"},
1085 {"ADDA_DL_CH3", "DL2_CH1", "DL2"},
1086 {"ADDA_DL_CH4", "DL2_CH1", "DL2"},
1087 {"ADDA_DL_CH4", "DL2_CH2", "DL2"},
1089 {"ADDA_DL_CH3", "DL3_CH1", "DL3"},
1090 {"ADDA_DL_CH4", "DL3_CH1", "DL3"},
1091 {"ADDA_DL_CH4", "DL3_CH2", "DL3"},
1093 {"ADDA_DL_CH3", "DL4_CH1", "DL4"},
1094 {"ADDA_DL_CH4", "DL4_CH2", "DL4"},
1096 {"ADDA_DL_CH3", "DL5_CH1", "DL5"},
1097 {"ADDA_DL_CH4", "DL5_CH2", "DL5"},
1099 {"ADDA CH34 Playback", NULL
, "ADDA_DL_CH3"},
1100 {"ADDA CH34 Playback", NULL
, "ADDA_DL_CH4"},
1102 {"ADDA CH34 Playback", NULL
, "ADDA Enable"},
1103 {"ADDA CH34 Playback", NULL
, "ADDA CH34 Playback Enable"},
1106 {"ADDA_UL_Mux", "MTKAIF", "ADDA Capture"},
1107 {"ADDA_UL_Mux", "AP_DMIC", "AP DMIC Capture"},
1109 {"ADDA_CH34_UL_Mux", "MTKAIF", "ADDA CH34 Capture"},
1110 {"ADDA_CH34_UL_Mux", "AP_DMIC", "AP DMIC CH34 Capture"},
1112 {"ADDA Capture", NULL
, "ADDA Enable"},
1113 {"ADDA Capture", NULL
, "ADDA Capture Enable"},
1114 {"ADDA Capture", NULL
, "AUD_PAD_TOP"},
1115 {"ADDA Capture", NULL
, "ADDA_MTKAIF_CFG"},
1117 {"AP DMIC Capture", NULL
, "ADDA Enable"},
1118 {"AP DMIC Capture", NULL
, "ADDA Capture Enable"},
1119 {"AP DMIC Capture", NULL
, "ADDA_FIFO"},
1120 {"AP DMIC Capture", NULL
, "AP_DMIC_EN"},
1122 {"ADDA CH34 Capture", NULL
, "ADDA Enable"},
1123 {"ADDA CH34 Capture", NULL
, "ADDA CH34 Capture Enable"},
1124 {"ADDA CH34 Capture", NULL
, "AUD_PAD_TOP"},
1125 {"ADDA CH34 Capture", NULL
, "ADDA6_MTKAIF_CFG"},
1127 {"AP DMIC CH34 Capture", NULL
, "ADDA Enable"},
1128 {"AP DMIC CH34 Capture", NULL
, "ADDA CH34 Capture Enable"},
1129 {"AP DMIC CH34 Capture", NULL
, "ADDA_CH34_FIFO"},
1130 {"AP DMIC CH34 Capture", NULL
, "AP_DMIC_CH34_EN"},
1132 {"AP DMIC Capture", NULL
, "AP_DMIC_INPUT"},
1133 {"AP DMIC CH34 Capture", NULL
, "AP_DMIC_CH34_INPUT"},
1135 /* sidetone filter */
1136 {"STF_ADDA_MUX", "ADDA", "ADDA_UL_Mux"},
1137 {"STF_ADDA_MUX", "ADDA6", "ADDA_CH34_UL_Mux"},
1139 {"STF_O19O20_MUX", "ADDA_ADDA6", "STF_ADDA_MUX"},
1140 {"STF_O19O20_MUX", "O19O20", "STF_CH1"},
1141 {"STF_O19O20_MUX", "O19O20", "STF_CH2"},
1143 {"Sidetone Filter", "Switch", "STF_O19O20_MUX"},
1144 {"STF_OUTPUT", NULL
, "Sidetone Filter"},
1145 {"ADDA Playback", NULL
, "Sidetone Filter"},
1146 {"ADDA CH34 Playback", NULL
, "Sidetone Filter"},
1149 {"ADDA Playback", NULL
, "aud_dac_clk"},
1150 {"ADDA Playback", NULL
, "aud_dac_predis_clk"},
1152 {"ADDA CH34 Playback", NULL
, "aud_3rd_dac_clk"},
1153 {"ADDA CH34 Playback", NULL
, "aud_3rd_dac_predis_clk"},
1155 {"ADDA Capture Enable", NULL
, "aud_adc_clk"},
1156 {"ADDA CH34 Capture Enable", NULL
, "aud_adda6_adc_clk"},
1160 static int mtk_dai_adda_hw_params(struct snd_pcm_substream
*substream
,
1161 struct snd_pcm_hw_params
*params
,
1162 struct snd_soc_dai
*dai
)
1164 struct mtk_base_afe
*afe
= snd_soc_dai_get_drvdata(dai
);
1165 unsigned int rate
= params_rate(params
);
1168 dev_info(afe
->dev
, "%s(), id %d, stream %d, rate %d\n",
1174 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
1175 unsigned int dl_src2_con0
= 0;
1176 unsigned int dl_src2_con1
= 0;
1178 /* set sampling rate */
1179 dl_src2_con0
= adda_dl_rate_transform(afe
, rate
) <<
1180 DL_2_INPUT_MODE_CTL_SFT
;
1182 /* set output mode, UP_SAMPLING_RATE_X8 */
1183 dl_src2_con0
|= (0x3 << DL_2_OUTPUT_SEL_CTL_SFT
);
1185 /* turn off mute function */
1186 dl_src2_con0
|= (0x01 << DL_2_MUTE_CH2_OFF_CTL_PRE_SFT
);
1187 dl_src2_con0
|= (0x01 << DL_2_MUTE_CH1_OFF_CTL_PRE_SFT
);
1189 /* set voice input data if input sample rate is 8k or 16k */
1190 if (rate
== 8000 || rate
== 16000)
1191 dl_src2_con0
|= 0x01 << DL_2_VOICE_MODE_CTL_PRE_SFT
;
1193 /* SA suggest apply -0.3db to audio/speech path */
1194 dl_src2_con1
= MTK_AFE_ADDA_DL_GAIN_NORMAL
<<
1195 DL_2_GAIN_CTL_PRE_SFT
;
1197 /* turn on down-link gain */
1198 dl_src2_con0
|= (0x01 << DL_2_GAIN_ON_CTL_PRE_SFT
);
1200 if (id
== MT8192_DAI_ADDA
) {
1201 /* clean predistortion */
1202 regmap_write(afe
->regmap
, AFE_ADDA_PREDIS_CON0
, 0);
1203 regmap_write(afe
->regmap
, AFE_ADDA_PREDIS_CON1
, 0);
1205 regmap_write(afe
->regmap
,
1206 AFE_ADDA_DL_SRC2_CON0
, dl_src2_con0
);
1207 regmap_write(afe
->regmap
,
1208 AFE_ADDA_DL_SRC2_CON1
, dl_src2_con1
);
1211 regmap_update_bits(afe
->regmap
,
1212 AFE_ADDA_DL_SDM_DCCOMP_CON
,
1213 ATTGAIN_CTL_MASK_SFT
,
1214 AUDIO_SDM_LEVEL_NORMAL
<<
1218 regmap_update_bits(afe
->regmap
,
1219 AFE_ADDA_DL_SDM_DCCOMP_CON
,
1220 USE_3RD_SDM_MASK_SFT
,
1221 AUDIO_SDM_2ND
<< USE_3RD_SDM_SFT
);
1223 /* sdm auto reset */
1224 regmap_write(afe
->regmap
,
1225 AFE_ADDA_DL_SDM_AUTO_RESET_CON
,
1226 SDM_AUTO_RESET_THRESHOLD
);
1227 regmap_update_bits(afe
->regmap
,
1228 AFE_ADDA_DL_SDM_AUTO_RESET_CON
,
1229 ADDA_SDM_AUTO_RESET_ONOFF_MASK_SFT
,
1230 0x1 << ADDA_SDM_AUTO_RESET_ONOFF_SFT
);
1232 /* clean predistortion */
1233 regmap_write(afe
->regmap
,
1234 AFE_ADDA_3RD_DAC_PREDIS_CON0
, 0);
1235 regmap_write(afe
->regmap
,
1236 AFE_ADDA_3RD_DAC_PREDIS_CON1
, 0);
1238 regmap_write(afe
->regmap
, AFE_ADDA_3RD_DAC_DL_SRC2_CON0
,
1240 regmap_write(afe
->regmap
, AFE_ADDA_3RD_DAC_DL_SRC2_CON1
,
1244 regmap_update_bits(afe
->regmap
,
1245 AFE_ADDA_3RD_DAC_DL_SDM_DCCOMP_CON
,
1246 ATTGAIN_CTL_MASK_SFT
,
1247 AUDIO_SDM_LEVEL_NORMAL
<<
1251 regmap_update_bits(afe
->regmap
,
1252 AFE_ADDA_3RD_DAC_DL_SDM_DCCOMP_CON
,
1253 USE_3RD_SDM_MASK_SFT
,
1254 AUDIO_SDM_2ND
<< USE_3RD_SDM_SFT
);
1256 /* sdm auto reset */
1257 regmap_write(afe
->regmap
,
1258 AFE_ADDA_3RD_DAC_DL_SDM_AUTO_RESET_CON
,
1259 SDM_AUTO_RESET_THRESHOLD
);
1260 regmap_update_bits(afe
->regmap
,
1261 AFE_ADDA_3RD_DAC_DL_SDM_AUTO_RESET_CON
,
1262 ADDA_3RD_DAC_SDM_AUTO_RESET_ONOFF_MASK_SFT
,
1263 0x1 << ADDA_3RD_DAC_SDM_AUTO_RESET_ONOFF_SFT
);
1266 unsigned int voice_mode
= 0;
1267 unsigned int ul_src_con0
= 0; /* default value */
1269 voice_mode
= adda_ul_rate_transform(afe
, rate
);
1271 ul_src_con0
|= (voice_mode
<< 17) & (0x7 << 17);
1274 ul_src_con0
|= (1 << UL_IIR_ON_TMP_CTL_SFT
) &
1275 UL_IIR_ON_TMP_CTL_MASK_SFT
;
1276 ul_src_con0
|= (UL_IIR_SW
<< UL_IIRMODE_CTL_SFT
) &
1277 UL_IIRMODE_CTL_MASK_SFT
;
1280 case MT8192_DAI_ADDA
:
1281 case MT8192_DAI_AP_DMIC
:
1283 regmap_write(afe
->regmap
,
1284 AFE_ADDA_IIR_COEF_02_01
, 0x00000000);
1285 regmap_write(afe
->regmap
,
1286 AFE_ADDA_IIR_COEF_04_03
, 0x00003FB8);
1287 regmap_write(afe
->regmap
,
1288 AFE_ADDA_IIR_COEF_06_05
, 0x3FB80000);
1289 regmap_write(afe
->regmap
,
1290 AFE_ADDA_IIR_COEF_08_07
, 0x3FB80000);
1291 regmap_write(afe
->regmap
,
1292 AFE_ADDA_IIR_COEF_10_09
, 0x0000C048);
1294 regmap_write(afe
->regmap
,
1295 AFE_ADDA_UL_SRC_CON0
, ul_src_con0
);
1297 /* Using Internal ADC */
1298 regmap_update_bits(afe
->regmap
,
1303 /* mtkaif_rxif_data_mode = 0, amic */
1304 regmap_update_bits(afe
->regmap
,
1305 AFE_ADDA_MTKAIF_RX_CFG0
,
1309 case MT8192_DAI_ADDA_CH34
:
1310 case MT8192_DAI_AP_DMIC_CH34
:
1312 regmap_write(afe
->regmap
,
1313 AFE_ADDA6_IIR_COEF_02_01
, 0x00000000);
1314 regmap_write(afe
->regmap
,
1315 AFE_ADDA6_IIR_COEF_04_03
, 0x00003FB8);
1316 regmap_write(afe
->regmap
,
1317 AFE_ADDA6_IIR_COEF_06_05
, 0x3FB80000);
1318 regmap_write(afe
->regmap
,
1319 AFE_ADDA6_IIR_COEF_08_07
, 0x3FB80000);
1320 regmap_write(afe
->regmap
,
1321 AFE_ADDA6_IIR_COEF_10_09
, 0x0000C048);
1323 regmap_write(afe
->regmap
,
1324 AFE_ADDA6_UL_SRC_CON0
, ul_src_con0
);
1326 /* Using Internal ADC */
1327 regmap_update_bits(afe
->regmap
,
1332 /* mtkaif_rxif_data_mode = 0, amic */
1333 regmap_update_bits(afe
->regmap
,
1334 AFE_ADDA6_MTKAIF_RX_CFG0
,
1344 case MT8192_DAI_AP_DMIC
:
1345 case MT8192_DAI_AP_DMIC_CH34
:
1346 mtk_adda_ul_src_dmic(afe
, id
);
1356 static const struct snd_soc_dai_ops mtk_dai_adda_ops
= {
1357 .hw_params
= mtk_dai_adda_hw_params
,
1361 #define MTK_ADDA_PLAYBACK_RATES (SNDRV_PCM_RATE_8000_48000 |\
1362 SNDRV_PCM_RATE_96000 |\
1363 SNDRV_PCM_RATE_192000)
1365 #define MTK_ADDA_CAPTURE_RATES (SNDRV_PCM_RATE_8000 |\
1366 SNDRV_PCM_RATE_16000 |\
1367 SNDRV_PCM_RATE_32000 |\
1368 SNDRV_PCM_RATE_48000 |\
1369 SNDRV_PCM_RATE_96000 |\
1370 SNDRV_PCM_RATE_192000)
1372 #define MTK_ADDA_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
1373 SNDRV_PCM_FMTBIT_S24_LE |\
1374 SNDRV_PCM_FMTBIT_S32_LE)
1376 static struct snd_soc_dai_driver mtk_dai_adda_driver
[] = {
1379 .id
= MT8192_DAI_ADDA
,
1381 .stream_name
= "ADDA Playback",
1384 .rates
= MTK_ADDA_PLAYBACK_RATES
,
1385 .formats
= MTK_ADDA_FORMATS
,
1388 .stream_name
= "ADDA Capture",
1391 .rates
= MTK_ADDA_CAPTURE_RATES
,
1392 .formats
= MTK_ADDA_FORMATS
,
1394 .ops
= &mtk_dai_adda_ops
,
1397 .name
= "ADDA_CH34",
1398 .id
= MT8192_DAI_ADDA_CH34
,
1400 .stream_name
= "ADDA CH34 Playback",
1403 .rates
= MTK_ADDA_PLAYBACK_RATES
,
1404 .formats
= MTK_ADDA_FORMATS
,
1407 .stream_name
= "ADDA CH34 Capture",
1410 .rates
= MTK_ADDA_CAPTURE_RATES
,
1411 .formats
= MTK_ADDA_FORMATS
,
1413 .ops
= &mtk_dai_adda_ops
,
1417 .id
= MT8192_DAI_AP_DMIC
,
1419 .stream_name
= "AP DMIC Capture",
1422 .rates
= MTK_ADDA_CAPTURE_RATES
,
1423 .formats
= MTK_ADDA_FORMATS
,
1425 .ops
= &mtk_dai_adda_ops
,
1428 .name
= "AP_DMIC_CH34",
1429 .id
= MT8192_DAI_AP_DMIC_CH34
,
1431 .stream_name
= "AP DMIC CH34 Capture",
1434 .rates
= MTK_ADDA_CAPTURE_RATES
,
1435 .formats
= MTK_ADDA_FORMATS
,
1437 .ops
= &mtk_dai_adda_ops
,
1441 int mt8192_dai_adda_register(struct mtk_base_afe
*afe
)
1443 struct mtk_base_afe_dai
*dai
;
1444 struct mt8192_afe_private
*afe_priv
= afe
->platform_priv
;
1446 dev_info(afe
->dev
, "%s()\n", __func__
);
1448 dai
= devm_kzalloc(afe
->dev
, sizeof(*dai
), GFP_KERNEL
);
1452 list_add(&dai
->list
, &afe
->sub_dais
);
1454 dai
->dai_drivers
= mtk_dai_adda_driver
;
1455 dai
->num_dai_drivers
= ARRAY_SIZE(mtk_dai_adda_driver
);
1457 dai
->controls
= mtk_adda_controls
;
1458 dai
->num_controls
= ARRAY_SIZE(mtk_adda_controls
);
1459 dai
->dapm_widgets
= mtk_dai_adda_widgets
;
1460 dai
->num_dapm_widgets
= ARRAY_SIZE(mtk_dai_adda_widgets
);
1461 dai
->dapm_routes
= mtk_dai_adda_routes
;
1462 dai
->num_dapm_routes
= ARRAY_SIZE(mtk_dai_adda_routes
);
1464 /* ap dmic priv share with adda */
1465 afe_priv
->dai_priv
[MT8192_DAI_AP_DMIC
] =
1466 afe_priv
->dai_priv
[MT8192_DAI_ADDA
];
1467 afe_priv
->dai_priv
[MT8192_DAI_AP_DMIC_CH34
] =
1468 afe_priv
->dai_priv
[MT8192_DAI_ADDA_CH34
];