1607ac485SJiaxin Yu // SPDX-License-Identifier: GPL-2.0
2607ac485SJiaxin Yu //
3607ac485SJiaxin Yu // MediaTek ALSA SoC Audio DAI ADDA Control
4607ac485SJiaxin Yu //
5607ac485SJiaxin Yu // Copyright (c) 2020 MediaTek Inc.
6607ac485SJiaxin Yu // Author: Shane Chien <shane.chien@mediatek.com>
7607ac485SJiaxin Yu //
8607ac485SJiaxin Yu
9607ac485SJiaxin Yu #include <linux/delay.h>
10607ac485SJiaxin Yu #include <linux/regmap.h>
11607ac485SJiaxin Yu
12607ac485SJiaxin Yu #include "mt8192-afe-clk.h"
13607ac485SJiaxin Yu #include "mt8192-afe-common.h"
14607ac485SJiaxin Yu #include "mt8192-afe-gpio.h"
15607ac485SJiaxin Yu #include "mt8192-interconnection.h"
16*d6c01755SAngeloGioacchino Del Regno #include "../common/mtk-dai-adda-common.h"
17607ac485SJiaxin Yu
18607ac485SJiaxin Yu enum {
19607ac485SJiaxin Yu UL_IIR_SW = 0,
20607ac485SJiaxin Yu UL_IIR_5HZ,
21607ac485SJiaxin Yu UL_IIR_10HZ,
22607ac485SJiaxin Yu UL_IIR_25HZ,
23607ac485SJiaxin Yu UL_IIR_50HZ,
24607ac485SJiaxin Yu UL_IIR_75HZ,
25607ac485SJiaxin Yu };
26607ac485SJiaxin Yu
27607ac485SJiaxin Yu enum {
28607ac485SJiaxin Yu AUDIO_SDM_LEVEL_MUTE = 0,
29607ac485SJiaxin Yu AUDIO_SDM_LEVEL_NORMAL = 0x1d,
30607ac485SJiaxin Yu /* if you change level normal */
31607ac485SJiaxin Yu /* you need to change formula of hp impedance and dc trim too */
32607ac485SJiaxin Yu };
33607ac485SJiaxin Yu
34607ac485SJiaxin Yu enum {
35607ac485SJiaxin Yu AUDIO_SDM_2ND = 0,
36607ac485SJiaxin Yu AUDIO_SDM_3RD,
37607ac485SJiaxin Yu };
38607ac485SJiaxin Yu
39607ac485SJiaxin Yu #define SDM_AUTO_RESET_THRESHOLD 0x190000
40607ac485SJiaxin Yu
41607ac485SJiaxin Yu /* dai component */
42607ac485SJiaxin Yu static const struct snd_kcontrol_new mtk_adda_dl_ch1_mix[] = {
43607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("DL1_CH1", AFE_CONN3, I_DL1_CH1, 1, 0),
44607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("DL12_CH1", AFE_CONN3, I_DL12_CH1, 1, 0),
45607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("DL2_CH1", AFE_CONN3, I_DL2_CH1, 1, 0),
46607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("DL3_CH1", AFE_CONN3, I_DL3_CH1, 1, 0),
47607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("DL4_CH1", AFE_CONN3_1, I_DL4_CH1, 1, 0),
48607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("DL5_CH1", AFE_CONN3_1, I_DL5_CH1, 1, 0),
49607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("DL6_CH1", AFE_CONN3_1, I_DL6_CH1, 1, 0),
50607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("DL8_CH1", AFE_CONN3_1, I_DL8_CH1, 1, 0),
51607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH3", AFE_CONN3,
52607ac485SJiaxin Yu I_ADDA_UL_CH3, 1, 0),
53607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH2", AFE_CONN3,
54607ac485SJiaxin Yu I_ADDA_UL_CH2, 1, 0),
55607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH1", AFE_CONN3,
56607ac485SJiaxin Yu I_ADDA_UL_CH1, 1, 0),
57607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("GAIN1_OUT_CH1", AFE_CONN3,
58607ac485SJiaxin Yu I_GAIN1_OUT_CH1, 1, 0),
59607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("PCM_1_CAP_CH1", AFE_CONN3,
60607ac485SJiaxin Yu I_PCM_1_CAP_CH1, 1, 0),
61607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("PCM_2_CAP_CH1", AFE_CONN3,
62607ac485SJiaxin Yu I_PCM_2_CAP_CH1, 1, 0),
63607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("SRC_1_OUT_CH1", AFE_CONN3_1,
64607ac485SJiaxin Yu I_SRC_1_OUT_CH1, 1, 0),
65607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("SRC_2_OUT_CH1", AFE_CONN3_1,
66607ac485SJiaxin Yu I_SRC_2_OUT_CH1, 1, 0),
67607ac485SJiaxin Yu };
68607ac485SJiaxin Yu
69607ac485SJiaxin Yu static const struct snd_kcontrol_new mtk_adda_dl_ch2_mix[] = {
70607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("DL1_CH1", AFE_CONN4, I_DL1_CH1, 1, 0),
71607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("DL1_CH2", AFE_CONN4, I_DL1_CH2, 1, 0),
72607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("DL12_CH2", AFE_CONN4, I_DL12_CH2, 1, 0),
73607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("DL2_CH1", AFE_CONN4, I_DL2_CH1, 1, 0),
74607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("DL2_CH2", AFE_CONN4, I_DL2_CH2, 1, 0),
75607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("DL3_CH1", AFE_CONN4, I_DL3_CH1, 1, 0),
76607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("DL3_CH2", AFE_CONN4, I_DL3_CH2, 1, 0),
77607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("DL4_CH2", AFE_CONN4_1, I_DL4_CH2, 1, 0),
78607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("DL5_CH2", AFE_CONN4_1, I_DL5_CH2, 1, 0),
79607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("DL6_CH2", AFE_CONN4_1, I_DL6_CH2, 1, 0),
80607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("DL8_CH2", AFE_CONN4_1, I_DL8_CH2, 1, 0),
81607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH3", AFE_CONN4,
82607ac485SJiaxin Yu I_ADDA_UL_CH3, 1, 0),
83607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH2", AFE_CONN4,
84607ac485SJiaxin Yu I_ADDA_UL_CH2, 1, 0),
85607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH1", AFE_CONN4,
86607ac485SJiaxin Yu I_ADDA_UL_CH1, 1, 0),
87607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("GAIN1_OUT_CH2", AFE_CONN4,
88607ac485SJiaxin Yu I_GAIN1_OUT_CH2, 1, 0),
89607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("PCM_1_CAP_CH1", AFE_CONN4,
90607ac485SJiaxin Yu I_PCM_1_CAP_CH1, 1, 0),
91607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("PCM_2_CAP_CH1", AFE_CONN4,
92607ac485SJiaxin Yu I_PCM_2_CAP_CH1, 1, 0),
93607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("PCM_1_CAP_CH2", AFE_CONN4,
94607ac485SJiaxin Yu I_PCM_1_CAP_CH2, 1, 0),
95607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("PCM_2_CAP_CH2", AFE_CONN4,
96607ac485SJiaxin Yu I_PCM_2_CAP_CH2, 1, 0),
97607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("SRC_1_OUT_CH2", AFE_CONN4_1,
98607ac485SJiaxin Yu I_SRC_1_OUT_CH2, 1, 0),
99607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("SRC_2_OUT_CH2", AFE_CONN4_1,
100607ac485SJiaxin Yu I_SRC_2_OUT_CH2, 1, 0),
101607ac485SJiaxin Yu };
102607ac485SJiaxin Yu
103607ac485SJiaxin Yu static const struct snd_kcontrol_new mtk_adda_dl_ch3_mix[] = {
104607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("DL1_CH1", AFE_CONN52, I_DL1_CH1, 1, 0),
105607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("DL12_CH1", AFE_CONN52, I_DL12_CH1, 1, 0),
106607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("DL2_CH1", AFE_CONN52, I_DL2_CH1, 1, 0),
107607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("DL3_CH1", AFE_CONN52, I_DL3_CH1, 1, 0),
108607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("DL4_CH1", AFE_CONN52_1, I_DL4_CH1, 1, 0),
109607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("DL5_CH1", AFE_CONN52_1, I_DL5_CH1, 1, 0),
110607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("DL6_CH1", AFE_CONN52_1, I_DL6_CH1, 1, 0),
111607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH3", AFE_CONN52,
112607ac485SJiaxin Yu I_ADDA_UL_CH3, 1, 0),
113607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH2", AFE_CONN52,
114607ac485SJiaxin Yu I_ADDA_UL_CH2, 1, 0),
115607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH1", AFE_CONN52,
116607ac485SJiaxin Yu I_ADDA_UL_CH1, 1, 0),
117607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("GAIN1_OUT_CH1", AFE_CONN52,
118607ac485SJiaxin Yu I_GAIN1_OUT_CH1, 1, 0),
119607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("PCM_1_CAP_CH1", AFE_CONN52,
120607ac485SJiaxin Yu I_PCM_1_CAP_CH1, 1, 0),
121607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("PCM_2_CAP_CH1", AFE_CONN52,
122607ac485SJiaxin Yu I_PCM_2_CAP_CH1, 1, 0),
123607ac485SJiaxin Yu };
124607ac485SJiaxin Yu
125607ac485SJiaxin Yu static const struct snd_kcontrol_new mtk_adda_dl_ch4_mix[] = {
126607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("DL1_CH1", AFE_CONN53, I_DL1_CH1, 1, 0),
127607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("DL1_CH2", AFE_CONN53, I_DL1_CH2, 1, 0),
128607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("DL12_CH2", AFE_CONN53, I_DL12_CH2, 1, 0),
129607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("DL2_CH1", AFE_CONN53, I_DL2_CH1, 1, 0),
130607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("DL2_CH2", AFE_CONN53, I_DL2_CH2, 1, 0),
131607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("DL3_CH1", AFE_CONN53, I_DL3_CH1, 1, 0),
132607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("DL3_CH2", AFE_CONN53, I_DL3_CH2, 1, 0),
133607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("DL4_CH2", AFE_CONN53_1, I_DL4_CH2, 1, 0),
134607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("DL5_CH2", AFE_CONN53_1, I_DL5_CH2, 1, 0),
135607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("DL6_CH2", AFE_CONN53_1, I_DL6_CH1, 1, 0),
136607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH3", AFE_CONN53,
137607ac485SJiaxin Yu I_ADDA_UL_CH3, 1, 0),
138607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH2", AFE_CONN53,
139607ac485SJiaxin Yu I_ADDA_UL_CH2, 1, 0),
140607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH1", AFE_CONN53,
141607ac485SJiaxin Yu I_ADDA_UL_CH1, 1, 0),
142607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("GAIN1_OUT_CH2", AFE_CONN53,
143607ac485SJiaxin Yu I_GAIN1_OUT_CH2, 1, 0),
144607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("PCM_1_CAP_CH1", AFE_CONN53,
145607ac485SJiaxin Yu I_PCM_1_CAP_CH1, 1, 0),
146607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("PCM_2_CAP_CH1", AFE_CONN53,
147607ac485SJiaxin Yu I_PCM_2_CAP_CH1, 1, 0),
148607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("PCM_1_CAP_CH2", AFE_CONN53,
149607ac485SJiaxin Yu I_PCM_1_CAP_CH2, 1, 0),
150607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("PCM_2_CAP_CH2", AFE_CONN53,
151607ac485SJiaxin Yu I_PCM_2_CAP_CH2, 1, 0),
152607ac485SJiaxin Yu };
153607ac485SJiaxin Yu
154607ac485SJiaxin Yu static const struct snd_kcontrol_new mtk_stf_ch1_mix[] = {
155607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH1", AFE_CONN19,
156607ac485SJiaxin Yu I_ADDA_UL_CH1, 1, 0),
157607ac485SJiaxin Yu };
158607ac485SJiaxin Yu
159607ac485SJiaxin Yu static const struct snd_kcontrol_new mtk_stf_ch2_mix[] = {
160607ac485SJiaxin Yu SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH2", AFE_CONN20,
161607ac485SJiaxin Yu I_ADDA_UL_CH2, 1, 0),
162607ac485SJiaxin Yu };
163607ac485SJiaxin Yu
164607ac485SJiaxin Yu enum {
165607ac485SJiaxin Yu SUPPLY_SEQ_ADDA_AFE_ON,
166607ac485SJiaxin Yu SUPPLY_SEQ_ADDA_DL_ON,
167607ac485SJiaxin Yu SUPPLY_SEQ_ADDA_AUD_PAD_TOP,
168607ac485SJiaxin Yu SUPPLY_SEQ_ADDA_MTKAIF_CFG,
169607ac485SJiaxin Yu SUPPLY_SEQ_ADDA6_MTKAIF_CFG,
170607ac485SJiaxin Yu SUPPLY_SEQ_ADDA_FIFO,
171607ac485SJiaxin Yu SUPPLY_SEQ_ADDA_AP_DMIC,
172607ac485SJiaxin Yu SUPPLY_SEQ_ADDA_UL_ON,
173607ac485SJiaxin Yu };
174607ac485SJiaxin Yu
mtk_adda_ul_src_dmic(struct mtk_base_afe * afe,int id)175607ac485SJiaxin Yu static int mtk_adda_ul_src_dmic(struct mtk_base_afe *afe, int id)
176607ac485SJiaxin Yu {
177607ac485SJiaxin Yu unsigned int reg;
178607ac485SJiaxin Yu
179607ac485SJiaxin Yu switch (id) {
180607ac485SJiaxin Yu case MT8192_DAI_ADDA:
181607ac485SJiaxin Yu case MT8192_DAI_AP_DMIC:
182607ac485SJiaxin Yu reg = AFE_ADDA_UL_SRC_CON0;
183607ac485SJiaxin Yu break;
184607ac485SJiaxin Yu case MT8192_DAI_ADDA_CH34:
185607ac485SJiaxin Yu case MT8192_DAI_AP_DMIC_CH34:
186607ac485SJiaxin Yu reg = AFE_ADDA6_UL_SRC_CON0;
187607ac485SJiaxin Yu break;
188607ac485SJiaxin Yu default:
189607ac485SJiaxin Yu return -EINVAL;
190607ac485SJiaxin Yu }
191607ac485SJiaxin Yu
192607ac485SJiaxin Yu /* dmic mode, 3.25M*/
193607ac485SJiaxin Yu regmap_update_bits(afe->regmap, reg,
194607ac485SJiaxin Yu DIGMIC_3P25M_1P625M_SEL_CTL_MASK_SFT,
195607ac485SJiaxin Yu 0x0);
196607ac485SJiaxin Yu regmap_update_bits(afe->regmap, reg,
197607ac485SJiaxin Yu DMIC_LOW_POWER_MODE_CTL_MASK_SFT,
198607ac485SJiaxin Yu 0x0);
199607ac485SJiaxin Yu
200607ac485SJiaxin Yu /* turn on dmic, ch1, ch2 */
201607ac485SJiaxin Yu regmap_update_bits(afe->regmap, reg,
202607ac485SJiaxin Yu UL_SDM_3_LEVEL_CTL_MASK_SFT,
203607ac485SJiaxin Yu 0x1 << UL_SDM_3_LEVEL_CTL_SFT);
204607ac485SJiaxin Yu regmap_update_bits(afe->regmap, reg,
205607ac485SJiaxin Yu UL_MODE_3P25M_CH1_CTL_MASK_SFT,
206607ac485SJiaxin Yu 0x1 << UL_MODE_3P25M_CH1_CTL_SFT);
207607ac485SJiaxin Yu regmap_update_bits(afe->regmap, reg,
208607ac485SJiaxin Yu UL_MODE_3P25M_CH2_CTL_MASK_SFT,
209607ac485SJiaxin Yu 0x1 << UL_MODE_3P25M_CH2_CTL_SFT);
210607ac485SJiaxin Yu return 0;
211607ac485SJiaxin Yu }
212607ac485SJiaxin Yu
mtk_adda_ul_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)213607ac485SJiaxin Yu static int mtk_adda_ul_event(struct snd_soc_dapm_widget *w,
214607ac485SJiaxin Yu struct snd_kcontrol *kcontrol,
215607ac485SJiaxin Yu int event)
216607ac485SJiaxin Yu {
217607ac485SJiaxin Yu struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
218607ac485SJiaxin Yu struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt);
219607ac485SJiaxin Yu struct mt8192_afe_private *afe_priv = afe->platform_priv;
220607ac485SJiaxin Yu int mtkaif_dmic = afe_priv->mtkaif_dmic;
221607ac485SJiaxin Yu
222607ac485SJiaxin Yu switch (event) {
223607ac485SJiaxin Yu case SND_SOC_DAPM_PRE_PMU:
224607ac485SJiaxin Yu mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA, 1);
225607ac485SJiaxin Yu
226607ac485SJiaxin Yu /* update setting to dmic */
227607ac485SJiaxin Yu if (mtkaif_dmic) {
228607ac485SJiaxin Yu /* mtkaif_rxif_data_mode = 1, dmic */
229607ac485SJiaxin Yu regmap_update_bits(afe->regmap, AFE_ADDA_MTKAIF_RX_CFG0,
230607ac485SJiaxin Yu 0x1, 0x1);
231607ac485SJiaxin Yu
232607ac485SJiaxin Yu /* dmic mode, 3.25M*/
233607ac485SJiaxin Yu regmap_update_bits(afe->regmap, AFE_ADDA_MTKAIF_RX_CFG0,
234607ac485SJiaxin Yu MTKAIF_RXIF_VOICE_MODE_MASK_SFT,
235607ac485SJiaxin Yu 0x0);
236607ac485SJiaxin Yu mtk_adda_ul_src_dmic(afe, MT8192_DAI_ADDA);
237607ac485SJiaxin Yu }
238607ac485SJiaxin Yu break;
239607ac485SJiaxin Yu case SND_SOC_DAPM_POST_PMD:
240607ac485SJiaxin Yu /* should delayed 1/fs(smallest is 8k) = 125us before afe off */
241607ac485SJiaxin Yu usleep_range(125, 135);
242607ac485SJiaxin Yu mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA, 1);
243607ac485SJiaxin Yu break;
244607ac485SJiaxin Yu default:
245607ac485SJiaxin Yu break;
246607ac485SJiaxin Yu }
247607ac485SJiaxin Yu
248607ac485SJiaxin Yu return 0;
249607ac485SJiaxin Yu }
250607ac485SJiaxin Yu
mtk_adda_ch34_ul_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)251607ac485SJiaxin Yu static int mtk_adda_ch34_ul_event(struct snd_soc_dapm_widget *w,
252607ac485SJiaxin Yu struct snd_kcontrol *kcontrol,
253607ac485SJiaxin Yu int event)
254607ac485SJiaxin Yu {
255607ac485SJiaxin Yu struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
256607ac485SJiaxin Yu struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt);
257607ac485SJiaxin Yu struct mt8192_afe_private *afe_priv = afe->platform_priv;
258607ac485SJiaxin Yu int mtkaif_dmic = afe_priv->mtkaif_dmic_ch34;
259607ac485SJiaxin Yu int mtkaif_adda6_only = afe_priv->mtkaif_adda6_only;
260607ac485SJiaxin Yu
261607ac485SJiaxin Yu switch (event) {
262607ac485SJiaxin Yu case SND_SOC_DAPM_PRE_PMU:
263607ac485SJiaxin Yu mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA_CH34,
264607ac485SJiaxin Yu 1);
265607ac485SJiaxin Yu
266607ac485SJiaxin Yu /* update setting to dmic */
267607ac485SJiaxin Yu if (mtkaif_dmic) {
268607ac485SJiaxin Yu /* mtkaif_rxif_data_mode = 1, dmic */
269607ac485SJiaxin Yu regmap_update_bits(afe->regmap,
270607ac485SJiaxin Yu AFE_ADDA6_MTKAIF_RX_CFG0,
271607ac485SJiaxin Yu 0x1, 0x1);
272607ac485SJiaxin Yu
273607ac485SJiaxin Yu /* dmic mode, 3.25M*/
274607ac485SJiaxin Yu regmap_update_bits(afe->regmap,
275607ac485SJiaxin Yu AFE_ADDA6_MTKAIF_RX_CFG0,
276607ac485SJiaxin Yu MTKAIF_RXIF_VOICE_MODE_MASK_SFT,
277607ac485SJiaxin Yu 0x0);
278607ac485SJiaxin Yu mtk_adda_ul_src_dmic(afe, MT8192_DAI_ADDA_CH34);
279607ac485SJiaxin Yu }
280607ac485SJiaxin Yu
281607ac485SJiaxin Yu /* when using adda6 without adda enabled,
282607ac485SJiaxin Yu * RG_ADDA6_MTKAIF_RX_SYNC_WORD2_DISABLE_SFT need to be set or
283607ac485SJiaxin Yu * data cannot be received.
284607ac485SJiaxin Yu */
285607ac485SJiaxin Yu if (mtkaif_adda6_only) {
286607ac485SJiaxin Yu regmap_update_bits(afe->regmap,
287607ac485SJiaxin Yu AFE_ADDA_MTKAIF_SYNCWORD_CFG,
288607ac485SJiaxin Yu 0x1 << 23, 0x1 << 23);
289607ac485SJiaxin Yu }
290607ac485SJiaxin Yu break;
291607ac485SJiaxin Yu case SND_SOC_DAPM_POST_PMD:
292607ac485SJiaxin Yu /* should delayed 1/fs(smallest is 8k) = 125us before afe off */
293607ac485SJiaxin Yu usleep_range(125, 135);
294607ac485SJiaxin Yu mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA_CH34,
295607ac485SJiaxin Yu 1);
296607ac485SJiaxin Yu
297607ac485SJiaxin Yu /* reset dmic */
298607ac485SJiaxin Yu afe_priv->mtkaif_dmic_ch34 = 0;
299607ac485SJiaxin Yu
300607ac485SJiaxin Yu if (mtkaif_adda6_only) {
301607ac485SJiaxin Yu regmap_update_bits(afe->regmap,
302607ac485SJiaxin Yu AFE_ADDA_MTKAIF_SYNCWORD_CFG,
303607ac485SJiaxin Yu 0x1 << 23, 0x0 << 23);
304607ac485SJiaxin Yu }
305607ac485SJiaxin Yu break;
306607ac485SJiaxin Yu default:
307607ac485SJiaxin Yu break;
308607ac485SJiaxin Yu }
309607ac485SJiaxin Yu
310607ac485SJiaxin Yu return 0;
311607ac485SJiaxin Yu }
312607ac485SJiaxin Yu
mtk_adda_pad_top_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)313607ac485SJiaxin Yu static int mtk_adda_pad_top_event(struct snd_soc_dapm_widget *w,
314607ac485SJiaxin Yu struct snd_kcontrol *kcontrol,
315607ac485SJiaxin Yu int event)
316607ac485SJiaxin Yu {
317607ac485SJiaxin Yu struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
318607ac485SJiaxin Yu struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt);
319607ac485SJiaxin Yu struct mt8192_afe_private *afe_priv = afe->platform_priv;
320607ac485SJiaxin Yu
321607ac485SJiaxin Yu switch (event) {
322607ac485SJiaxin Yu case SND_SOC_DAPM_PRE_PMU:
323607ac485SJiaxin Yu if (afe_priv->mtkaif_protocol == MTKAIF_PROTOCOL_2_CLK_P2)
324607ac485SJiaxin Yu regmap_write(afe->regmap, AFE_AUD_PAD_TOP, 0x38);
325607ac485SJiaxin Yu else
326607ac485SJiaxin Yu regmap_write(afe->regmap, AFE_AUD_PAD_TOP, 0x30);
327607ac485SJiaxin Yu break;
328607ac485SJiaxin Yu default:
329607ac485SJiaxin Yu break;
330607ac485SJiaxin Yu }
331607ac485SJiaxin Yu
332607ac485SJiaxin Yu return 0;
333607ac485SJiaxin Yu }
334607ac485SJiaxin Yu
mtk_adda_mtkaif_cfg_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)335607ac485SJiaxin Yu static int mtk_adda_mtkaif_cfg_event(struct snd_soc_dapm_widget *w,
336607ac485SJiaxin Yu struct snd_kcontrol *kcontrol,
337607ac485SJiaxin Yu int event)
338607ac485SJiaxin Yu {
339607ac485SJiaxin Yu struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
340607ac485SJiaxin Yu struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt);
341607ac485SJiaxin Yu struct mt8192_afe_private *afe_priv = afe->platform_priv;
342607ac485SJiaxin Yu int delay_data;
343607ac485SJiaxin Yu int delay_cycle;
344607ac485SJiaxin Yu
345607ac485SJiaxin Yu switch (event) {
346607ac485SJiaxin Yu case SND_SOC_DAPM_PRE_PMU:
347607ac485SJiaxin Yu if (afe_priv->mtkaif_protocol == MTKAIF_PROTOCOL_2_CLK_P2) {
348607ac485SJiaxin Yu /* set protocol 2 */
349607ac485SJiaxin Yu regmap_write(afe->regmap, AFE_ADDA_MTKAIF_CFG0,
350607ac485SJiaxin Yu 0x00010000);
351607ac485SJiaxin Yu regmap_write(afe->regmap, AFE_ADDA6_MTKAIF_CFG0,
352607ac485SJiaxin Yu 0x00010000);
353607ac485SJiaxin Yu
35486cfaf99SKrzysztof Kozlowski if (snd_soc_dapm_widget_name_cmp(w, "ADDA_MTKAIF_CFG") == 0 &&
355607ac485SJiaxin Yu (afe_priv->mtkaif_chosen_phase[0] < 0 ||
356607ac485SJiaxin Yu afe_priv->mtkaif_chosen_phase[1] < 0)) {
357607ac485SJiaxin Yu dev_warn(afe->dev,
358607ac485SJiaxin Yu "%s(), mtkaif_chosen_phase[0/1]:%d/%d\n",
359607ac485SJiaxin Yu __func__,
360607ac485SJiaxin Yu afe_priv->mtkaif_chosen_phase[0],
361607ac485SJiaxin Yu afe_priv->mtkaif_chosen_phase[1]);
362607ac485SJiaxin Yu break;
36386cfaf99SKrzysztof Kozlowski } else if (snd_soc_dapm_widget_name_cmp(w, "ADDA6_MTKAIF_CFG") == 0 &&
364607ac485SJiaxin Yu afe_priv->mtkaif_chosen_phase[2] < 0) {
365607ac485SJiaxin Yu dev_warn(afe->dev,
366607ac485SJiaxin Yu "%s(), mtkaif_chosen_phase[2]:%d\n",
367607ac485SJiaxin Yu __func__,
368607ac485SJiaxin Yu afe_priv->mtkaif_chosen_phase[2]);
369607ac485SJiaxin Yu break;
370607ac485SJiaxin Yu }
371607ac485SJiaxin Yu
372607ac485SJiaxin Yu /* mtkaif_rxif_clkinv_adc inverse for calibration */
373607ac485SJiaxin Yu regmap_update_bits(afe->regmap, AFE_ADDA_MTKAIF_CFG0,
374607ac485SJiaxin Yu MTKAIF_RXIF_CLKINV_ADC_MASK_SFT,
375607ac485SJiaxin Yu 0x1 << MTKAIF_RXIF_CLKINV_ADC_SFT);
376607ac485SJiaxin Yu regmap_update_bits(afe->regmap, AFE_ADDA6_MTKAIF_CFG0,
377607ac485SJiaxin Yu MTKAIF_RXIF_CLKINV_ADC_MASK_SFT,
378607ac485SJiaxin Yu 0x1 << MTKAIF_RXIF_CLKINV_ADC_SFT);
379607ac485SJiaxin Yu
380607ac485SJiaxin Yu /* set delay for ch12 */
381607ac485SJiaxin Yu if (afe_priv->mtkaif_phase_cycle[0] >=
382607ac485SJiaxin Yu afe_priv->mtkaif_phase_cycle[1]) {
383607ac485SJiaxin Yu delay_data = DELAY_DATA_MISO1;
384607ac485SJiaxin Yu delay_cycle = afe_priv->mtkaif_phase_cycle[0] -
385607ac485SJiaxin Yu afe_priv->mtkaif_phase_cycle[1];
386607ac485SJiaxin Yu } else {
387607ac485SJiaxin Yu delay_data = DELAY_DATA_MISO2;
388607ac485SJiaxin Yu delay_cycle = afe_priv->mtkaif_phase_cycle[1] -
389607ac485SJiaxin Yu afe_priv->mtkaif_phase_cycle[0];
390607ac485SJiaxin Yu }
391607ac485SJiaxin Yu
392607ac485SJiaxin Yu regmap_update_bits(afe->regmap,
393607ac485SJiaxin Yu AFE_ADDA_MTKAIF_RX_CFG2,
394607ac485SJiaxin Yu MTKAIF_RXIF_DELAY_DATA_MASK_SFT,
395607ac485SJiaxin Yu delay_data <<
396607ac485SJiaxin Yu MTKAIF_RXIF_DELAY_DATA_SFT);
397607ac485SJiaxin Yu
398607ac485SJiaxin Yu regmap_update_bits(afe->regmap,
399607ac485SJiaxin Yu AFE_ADDA_MTKAIF_RX_CFG2,
400607ac485SJiaxin Yu MTKAIF_RXIF_DELAY_CYCLE_MASK_SFT,
401607ac485SJiaxin Yu delay_cycle <<
402607ac485SJiaxin Yu MTKAIF_RXIF_DELAY_CYCLE_SFT);
403607ac485SJiaxin Yu
404607ac485SJiaxin Yu /* set delay between ch3 and ch2 */
405607ac485SJiaxin Yu if (afe_priv->mtkaif_phase_cycle[2] >=
406607ac485SJiaxin Yu afe_priv->mtkaif_phase_cycle[1]) {
407607ac485SJiaxin Yu delay_data = DELAY_DATA_MISO1; /* ch3 */
408607ac485SJiaxin Yu delay_cycle = afe_priv->mtkaif_phase_cycle[2] -
409607ac485SJiaxin Yu afe_priv->mtkaif_phase_cycle[1];
410607ac485SJiaxin Yu } else {
411607ac485SJiaxin Yu delay_data = DELAY_DATA_MISO2; /* ch2 */
412607ac485SJiaxin Yu delay_cycle = afe_priv->mtkaif_phase_cycle[1] -
413607ac485SJiaxin Yu afe_priv->mtkaif_phase_cycle[2];
414607ac485SJiaxin Yu }
415607ac485SJiaxin Yu
416607ac485SJiaxin Yu regmap_update_bits(afe->regmap,
417607ac485SJiaxin Yu AFE_ADDA6_MTKAIF_RX_CFG2,
418607ac485SJiaxin Yu MTKAIF_RXIF_DELAY_DATA_MASK_SFT,
419607ac485SJiaxin Yu delay_data <<
420607ac485SJiaxin Yu MTKAIF_RXIF_DELAY_DATA_SFT);
421607ac485SJiaxin Yu regmap_update_bits(afe->regmap,
422607ac485SJiaxin Yu AFE_ADDA6_MTKAIF_RX_CFG2,
423607ac485SJiaxin Yu MTKAIF_RXIF_DELAY_CYCLE_MASK_SFT,
424607ac485SJiaxin Yu delay_cycle <<
425607ac485SJiaxin Yu MTKAIF_RXIF_DELAY_CYCLE_SFT);
426607ac485SJiaxin Yu } else if (afe_priv->mtkaif_protocol == MTKAIF_PROTOCOL_2) {
427607ac485SJiaxin Yu regmap_write(afe->regmap, AFE_ADDA_MTKAIF_CFG0,
428607ac485SJiaxin Yu 0x00010000);
429607ac485SJiaxin Yu regmap_write(afe->regmap, AFE_ADDA6_MTKAIF_CFG0,
430607ac485SJiaxin Yu 0x00010000);
431607ac485SJiaxin Yu } else {
432607ac485SJiaxin Yu regmap_write(afe->regmap, AFE_ADDA_MTKAIF_CFG0, 0x0);
433607ac485SJiaxin Yu regmap_write(afe->regmap, AFE_ADDA6_MTKAIF_CFG0, 0x0);
434607ac485SJiaxin Yu }
435607ac485SJiaxin Yu break;
436607ac485SJiaxin Yu default:
437607ac485SJiaxin Yu break;
438607ac485SJiaxin Yu }
439607ac485SJiaxin Yu
440607ac485SJiaxin Yu return 0;
441607ac485SJiaxin Yu }
442607ac485SJiaxin Yu
mtk_adda_dl_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)443607ac485SJiaxin Yu static int mtk_adda_dl_event(struct snd_soc_dapm_widget *w,
444607ac485SJiaxin Yu struct snd_kcontrol *kcontrol,
445607ac485SJiaxin Yu int event)
446607ac485SJiaxin Yu {
447607ac485SJiaxin Yu struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
448607ac485SJiaxin Yu struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt);
449607ac485SJiaxin Yu
450607ac485SJiaxin Yu switch (event) {
451607ac485SJiaxin Yu case SND_SOC_DAPM_PRE_PMU:
452607ac485SJiaxin Yu mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA, 0);
453607ac485SJiaxin Yu break;
454607ac485SJiaxin Yu case SND_SOC_DAPM_POST_PMD:
455607ac485SJiaxin Yu /* should delayed 1/fs(smallest is 8k) = 125us before afe off */
456607ac485SJiaxin Yu usleep_range(125, 135);
457607ac485SJiaxin Yu mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA, 0);
458607ac485SJiaxin Yu break;
459607ac485SJiaxin Yu default:
460607ac485SJiaxin Yu break;
461607ac485SJiaxin Yu }
462607ac485SJiaxin Yu
463607ac485SJiaxin Yu return 0;
464607ac485SJiaxin Yu }
465607ac485SJiaxin Yu
mtk_adda_ch34_dl_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)466607ac485SJiaxin Yu static int mtk_adda_ch34_dl_event(struct snd_soc_dapm_widget *w,
467607ac485SJiaxin Yu struct snd_kcontrol *kcontrol,
468607ac485SJiaxin Yu int event)
469607ac485SJiaxin Yu {
470607ac485SJiaxin Yu struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
471607ac485SJiaxin Yu struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt);
472607ac485SJiaxin Yu
473607ac485SJiaxin Yu switch (event) {
474607ac485SJiaxin Yu case SND_SOC_DAPM_PRE_PMU:
475607ac485SJiaxin Yu mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA_CH34,
476607ac485SJiaxin Yu 0);
477607ac485SJiaxin Yu break;
478607ac485SJiaxin Yu case SND_SOC_DAPM_POST_PMD:
479607ac485SJiaxin Yu /* should delayed 1/fs(smallest is 8k) = 125us before afe off */
480607ac485SJiaxin Yu usleep_range(125, 135);
481607ac485SJiaxin Yu mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA_CH34,
482607ac485SJiaxin Yu 0);
483607ac485SJiaxin Yu break;
484607ac485SJiaxin Yu default:
485607ac485SJiaxin Yu break;
486607ac485SJiaxin Yu }
487607ac485SJiaxin Yu
488607ac485SJiaxin Yu return 0;
489607ac485SJiaxin Yu }
490607ac485SJiaxin Yu
491607ac485SJiaxin Yu /* stf */
stf_positive_gain_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)492607ac485SJiaxin Yu static int stf_positive_gain_get(struct snd_kcontrol *kcontrol,
493607ac485SJiaxin Yu struct snd_ctl_elem_value *ucontrol)
494607ac485SJiaxin Yu {
495607ac485SJiaxin Yu struct snd_soc_component *cmpnt = snd_soc_kcontrol_component(kcontrol);
496607ac485SJiaxin Yu struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt);
497607ac485SJiaxin Yu struct mt8192_afe_private *afe_priv = afe->platform_priv;
498607ac485SJiaxin Yu
499607ac485SJiaxin Yu ucontrol->value.integer.value[0] = afe_priv->stf_positive_gain_db;
500607ac485SJiaxin Yu return 0;
501607ac485SJiaxin Yu }
502607ac485SJiaxin Yu
stf_positive_gain_set(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)503607ac485SJiaxin Yu static int stf_positive_gain_set(struct snd_kcontrol *kcontrol,
504607ac485SJiaxin Yu struct snd_ctl_elem_value *ucontrol)
505607ac485SJiaxin Yu {
506607ac485SJiaxin Yu struct snd_soc_component *cmpnt = snd_soc_kcontrol_component(kcontrol);
507607ac485SJiaxin Yu struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt);
508607ac485SJiaxin Yu struct mt8192_afe_private *afe_priv = afe->platform_priv;
509607ac485SJiaxin Yu int gain_db = ucontrol->value.integer.value[0];
510b373076fSMark Brown bool change = false;
511607ac485SJiaxin Yu
512607ac485SJiaxin Yu afe_priv->stf_positive_gain_db = gain_db;
513607ac485SJiaxin Yu
514607ac485SJiaxin Yu if (gain_db >= 0 && gain_db <= 24) {
515b373076fSMark Brown regmap_update_bits_check(afe->regmap,
516607ac485SJiaxin Yu AFE_SIDETONE_GAIN,
517607ac485SJiaxin Yu POSITIVE_GAIN_MASK_SFT,
518b373076fSMark Brown (gain_db / 6) << POSITIVE_GAIN_SFT,
519b373076fSMark Brown &change);
52005437a91SMark Brown } else {
52105437a91SMark Brown return -EINVAL;
522607ac485SJiaxin Yu }
523b373076fSMark Brown
524b373076fSMark Brown return change;
525607ac485SJiaxin Yu }
526607ac485SJiaxin Yu
mt8192_adda_dmic_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)527607ac485SJiaxin Yu static int mt8192_adda_dmic_get(struct snd_kcontrol *kcontrol,
528607ac485SJiaxin Yu struct snd_ctl_elem_value *ucontrol)
529607ac485SJiaxin Yu {
530607ac485SJiaxin Yu struct snd_soc_component *cmpnt = snd_soc_kcontrol_component(kcontrol);
531607ac485SJiaxin Yu struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt);
532607ac485SJiaxin Yu struct mt8192_afe_private *afe_priv = afe->platform_priv;
533607ac485SJiaxin Yu
534607ac485SJiaxin Yu ucontrol->value.integer.value[0] = afe_priv->mtkaif_dmic;
535607ac485SJiaxin Yu return 0;
536607ac485SJiaxin Yu }
537607ac485SJiaxin Yu
mt8192_adda_dmic_set(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)538607ac485SJiaxin Yu static int mt8192_adda_dmic_set(struct snd_kcontrol *kcontrol,
539607ac485SJiaxin Yu struct snd_ctl_elem_value *ucontrol)
540607ac485SJiaxin Yu {
541607ac485SJiaxin Yu struct snd_soc_component *cmpnt = snd_soc_kcontrol_component(kcontrol);
542607ac485SJiaxin Yu struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt);
543607ac485SJiaxin Yu struct mt8192_afe_private *afe_priv = afe->platform_priv;
544607ac485SJiaxin Yu int dmic_on;
545b373076fSMark Brown bool change;
546607ac485SJiaxin Yu
547607ac485SJiaxin Yu dmic_on = ucontrol->value.integer.value[0];
548607ac485SJiaxin Yu
549b373076fSMark Brown change = (afe_priv->mtkaif_dmic != dmic_on) ||
550b373076fSMark Brown (afe_priv->mtkaif_dmic_ch34 != dmic_on);
551b373076fSMark Brown
552607ac485SJiaxin Yu afe_priv->mtkaif_dmic = dmic_on;
553607ac485SJiaxin Yu afe_priv->mtkaif_dmic_ch34 = dmic_on;
554b373076fSMark Brown
555b373076fSMark Brown return change;
556607ac485SJiaxin Yu }
557607ac485SJiaxin Yu
mt8192_adda6_only_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)558607ac485SJiaxin Yu static int mt8192_adda6_only_get(struct snd_kcontrol *kcontrol,
559607ac485SJiaxin Yu struct snd_ctl_elem_value *ucontrol)
560607ac485SJiaxin Yu {
561607ac485SJiaxin Yu struct snd_soc_component *cmpnt = snd_soc_kcontrol_component(kcontrol);
562607ac485SJiaxin Yu struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt);
563607ac485SJiaxin Yu struct mt8192_afe_private *afe_priv = afe->platform_priv;
564607ac485SJiaxin Yu
565607ac485SJiaxin Yu ucontrol->value.integer.value[0] = afe_priv->mtkaif_adda6_only;
566607ac485SJiaxin Yu return 0;
567607ac485SJiaxin Yu }
568607ac485SJiaxin Yu
mt8192_adda6_only_set(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)569607ac485SJiaxin Yu static int mt8192_adda6_only_set(struct snd_kcontrol *kcontrol,
570607ac485SJiaxin Yu struct snd_ctl_elem_value *ucontrol)
571607ac485SJiaxin Yu {
572607ac485SJiaxin Yu struct snd_soc_component *cmpnt = snd_soc_kcontrol_component(kcontrol);
573607ac485SJiaxin Yu struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt);
574607ac485SJiaxin Yu struct mt8192_afe_private *afe_priv = afe->platform_priv;
575607ac485SJiaxin Yu int mtkaif_adda6_only;
576b373076fSMark Brown bool change;
577607ac485SJiaxin Yu
578607ac485SJiaxin Yu mtkaif_adda6_only = ucontrol->value.integer.value[0];
579607ac485SJiaxin Yu
580b373076fSMark Brown change = afe_priv->mtkaif_adda6_only != mtkaif_adda6_only;
581607ac485SJiaxin Yu afe_priv->mtkaif_adda6_only = mtkaif_adda6_only;
582b373076fSMark Brown
583b373076fSMark Brown return change;
584607ac485SJiaxin Yu }
585607ac485SJiaxin Yu
586607ac485SJiaxin Yu static const struct snd_kcontrol_new mtk_adda_controls[] = {
587607ac485SJiaxin Yu SOC_SINGLE("Sidetone_Gain", AFE_SIDETONE_GAIN,
588607ac485SJiaxin Yu SIDE_TONE_GAIN_SFT, SIDE_TONE_GAIN_MASK, 0),
589ce40d93bSMark Brown SOC_SINGLE_EXT("Sidetone_Positive_Gain_dB", SND_SOC_NOPM, 0, 24, 0,
590607ac485SJiaxin Yu stf_positive_gain_get, stf_positive_gain_set),
591607ac485SJiaxin Yu SOC_SINGLE("ADDA_DL_GAIN", AFE_ADDA_DL_SRC2_CON1,
592607ac485SJiaxin Yu DL_2_GAIN_CTL_PRE_SFT, DL_2_GAIN_CTL_PRE_MASK, 0),
593607ac485SJiaxin Yu SOC_SINGLE_BOOL_EXT("MTKAIF_DMIC Switch", 0,
594607ac485SJiaxin Yu mt8192_adda_dmic_get, mt8192_adda_dmic_set),
595607ac485SJiaxin Yu SOC_SINGLE_BOOL_EXT("MTKAIF_ADDA6_ONLY Switch", 0,
596607ac485SJiaxin Yu mt8192_adda6_only_get, mt8192_adda6_only_set),
597607ac485SJiaxin Yu };
598607ac485SJiaxin Yu
599607ac485SJiaxin Yu static const struct snd_kcontrol_new stf_ctl =
600607ac485SJiaxin Yu SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0);
601607ac485SJiaxin Yu
602607ac485SJiaxin Yu static const u16 stf_coeff_table_16k[] = {
603607ac485SJiaxin Yu 0x049C, 0x09E8, 0x09E0, 0x089C,
604607ac485SJiaxin Yu 0xFF54, 0xF488, 0xEAFC, 0xEBAC,
605607ac485SJiaxin Yu 0xfA40, 0x17AC, 0x3D1C, 0x6028,
606607ac485SJiaxin Yu 0x7538
607607ac485SJiaxin Yu };
608607ac485SJiaxin Yu
609607ac485SJiaxin Yu static const u16 stf_coeff_table_32k[] = {
610607ac485SJiaxin Yu 0xFE52, 0x0042, 0x00C5, 0x0194,
611607ac485SJiaxin Yu 0x029A, 0x03B7, 0x04BF, 0x057D,
612607ac485SJiaxin Yu 0x05BE, 0x0555, 0x0426, 0x0230,
613607ac485SJiaxin Yu 0xFF92, 0xFC89, 0xF973, 0xF6C6,
614607ac485SJiaxin Yu 0xF500, 0xF49D, 0xF603, 0xF970,
615607ac485SJiaxin Yu 0xFEF3, 0x065F, 0x0F4F, 0x1928,
616607ac485SJiaxin Yu 0x2329, 0x2C80, 0x345E, 0x3A0D,
617607ac485SJiaxin Yu 0x3D08
618607ac485SJiaxin Yu };
619607ac485SJiaxin Yu
620607ac485SJiaxin Yu static const u16 stf_coeff_table_48k[] = {
621607ac485SJiaxin Yu 0x0401, 0xFFB0, 0xFF5A, 0xFECE,
622607ac485SJiaxin Yu 0xFE10, 0xFD28, 0xFC21, 0xFB08,
623607ac485SJiaxin Yu 0xF9EF, 0xF8E8, 0xF80A, 0xF76C,
624607ac485SJiaxin Yu 0xF724, 0xF746, 0xF7E6, 0xF90F,
625607ac485SJiaxin Yu 0xFACC, 0xFD1E, 0xFFFF, 0x0364,
626607ac485SJiaxin Yu 0x0737, 0x0B62, 0x0FC1, 0x1431,
627607ac485SJiaxin Yu 0x188A, 0x1CA4, 0x2056, 0x237D,
628607ac485SJiaxin Yu 0x25F9, 0x27B0, 0x2890
629607ac485SJiaxin Yu };
630607ac485SJiaxin Yu
mtk_stf_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)631607ac485SJiaxin Yu static int mtk_stf_event(struct snd_soc_dapm_widget *w,
632607ac485SJiaxin Yu struct snd_kcontrol *kcontrol,
633607ac485SJiaxin Yu int event)
634607ac485SJiaxin Yu {
635607ac485SJiaxin Yu struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
636607ac485SJiaxin Yu struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt);
637607ac485SJiaxin Yu
638607ac485SJiaxin Yu size_t half_tap_num;
639607ac485SJiaxin Yu const u16 *stf_coeff_table;
640607ac485SJiaxin Yu unsigned int ul_rate, reg_value;
641607ac485SJiaxin Yu size_t coef_addr;
642607ac485SJiaxin Yu
643607ac485SJiaxin Yu regmap_read(afe->regmap, AFE_ADDA_UL_SRC_CON0, &ul_rate);
644607ac485SJiaxin Yu ul_rate = ul_rate >> UL_VOICE_MODE_CH1_CH2_CTL_SFT;
645607ac485SJiaxin Yu ul_rate = ul_rate & UL_VOICE_MODE_CH1_CH2_CTL_MASK;
646607ac485SJiaxin Yu
647607ac485SJiaxin Yu if (ul_rate == MTK_AFE_ADDA_UL_RATE_48K) {
648607ac485SJiaxin Yu half_tap_num = ARRAY_SIZE(stf_coeff_table_48k);
649607ac485SJiaxin Yu stf_coeff_table = stf_coeff_table_48k;
650607ac485SJiaxin Yu } else if (ul_rate == MTK_AFE_ADDA_UL_RATE_32K) {
651607ac485SJiaxin Yu half_tap_num = ARRAY_SIZE(stf_coeff_table_32k);
652607ac485SJiaxin Yu stf_coeff_table = stf_coeff_table_32k;
653607ac485SJiaxin Yu } else {
654607ac485SJiaxin Yu half_tap_num = ARRAY_SIZE(stf_coeff_table_16k);
655607ac485SJiaxin Yu stf_coeff_table = stf_coeff_table_16k;
656607ac485SJiaxin Yu }
657607ac485SJiaxin Yu
658607ac485SJiaxin Yu regmap_read(afe->regmap, AFE_SIDETONE_CON1, ®_value);
659607ac485SJiaxin Yu
660607ac485SJiaxin Yu switch (event) {
661607ac485SJiaxin Yu case SND_SOC_DAPM_PRE_PMU:
662607ac485SJiaxin Yu /* set side tone gain = 0 */
663607ac485SJiaxin Yu regmap_update_bits(afe->regmap,
664607ac485SJiaxin Yu AFE_SIDETONE_GAIN,
665607ac485SJiaxin Yu SIDE_TONE_GAIN_MASK_SFT,
666607ac485SJiaxin Yu 0);
667607ac485SJiaxin Yu regmap_update_bits(afe->regmap,
668607ac485SJiaxin Yu AFE_SIDETONE_GAIN,
669607ac485SJiaxin Yu POSITIVE_GAIN_MASK_SFT,
670607ac485SJiaxin Yu 0);
671607ac485SJiaxin Yu /* don't bypass stf */
672607ac485SJiaxin Yu regmap_update_bits(afe->regmap,
673607ac485SJiaxin Yu AFE_SIDETONE_CON1,
674607ac485SJiaxin Yu 0x1f << 27,
675607ac485SJiaxin Yu 0x0);
676607ac485SJiaxin Yu /* set stf half tap num */
677607ac485SJiaxin Yu regmap_update_bits(afe->regmap,
678607ac485SJiaxin Yu AFE_SIDETONE_CON1,
679607ac485SJiaxin Yu SIDE_TONE_HALF_TAP_NUM_MASK_SFT,
680607ac485SJiaxin Yu half_tap_num << SIDE_TONE_HALF_TAP_NUM_SFT);
681607ac485SJiaxin Yu
682607ac485SJiaxin Yu /* set side tone coefficient */
683607ac485SJiaxin Yu regmap_read(afe->regmap, AFE_SIDETONE_CON0, ®_value);
684607ac485SJiaxin Yu for (coef_addr = 0; coef_addr < half_tap_num; coef_addr++) {
685607ac485SJiaxin Yu bool old_w_ready = (reg_value >> W_RDY_SFT) & 0x1;
686607ac485SJiaxin Yu bool new_w_ready = 0;
687607ac485SJiaxin Yu int try_cnt = 0;
688607ac485SJiaxin Yu
689607ac485SJiaxin Yu regmap_update_bits(afe->regmap,
690607ac485SJiaxin Yu AFE_SIDETONE_CON0,
691607ac485SJiaxin Yu 0x39FFFFF,
692607ac485SJiaxin Yu (1 << R_W_EN_SFT) |
693607ac485SJiaxin Yu (1 << R_W_SEL_SFT) |
694607ac485SJiaxin Yu (0 << SEL_CH2_SFT) |
695607ac485SJiaxin Yu (coef_addr <<
696607ac485SJiaxin Yu SIDE_TONE_COEFFICIENT_ADDR_SFT) |
697607ac485SJiaxin Yu stf_coeff_table[coef_addr]);
698607ac485SJiaxin Yu
699607ac485SJiaxin Yu /* wait until flag write_ready changed */
700607ac485SJiaxin Yu for (try_cnt = 0; try_cnt < 10; try_cnt++) {
701607ac485SJiaxin Yu regmap_read(afe->regmap,
702607ac485SJiaxin Yu AFE_SIDETONE_CON0, ®_value);
703607ac485SJiaxin Yu new_w_ready = (reg_value >> W_RDY_SFT) & 0x1;
704607ac485SJiaxin Yu
705607ac485SJiaxin Yu /* flip => ok */
706607ac485SJiaxin Yu if (new_w_ready == old_w_ready) {
707607ac485SJiaxin Yu udelay(3);
708607ac485SJiaxin Yu if (try_cnt == 9) {
709607ac485SJiaxin Yu dev_warn(afe->dev,
710607ac485SJiaxin Yu "%s(), write coeff not ready",
711607ac485SJiaxin Yu __func__);
712607ac485SJiaxin Yu }
713607ac485SJiaxin Yu } else {
714607ac485SJiaxin Yu break;
715607ac485SJiaxin Yu }
716607ac485SJiaxin Yu }
717607ac485SJiaxin Yu /* need write -> read -> write to write next coeff */
718607ac485SJiaxin Yu regmap_update_bits(afe->regmap,
719607ac485SJiaxin Yu AFE_SIDETONE_CON0,
720607ac485SJiaxin Yu R_W_SEL_MASK_SFT,
721607ac485SJiaxin Yu 0x0);
722607ac485SJiaxin Yu }
723607ac485SJiaxin Yu break;
724607ac485SJiaxin Yu case SND_SOC_DAPM_POST_PMD:
725607ac485SJiaxin Yu /* bypass stf */
726607ac485SJiaxin Yu regmap_update_bits(afe->regmap,
727607ac485SJiaxin Yu AFE_SIDETONE_CON1,
728607ac485SJiaxin Yu 0x1f << 27,
729607ac485SJiaxin Yu 0x1f << 27);
730607ac485SJiaxin Yu
731607ac485SJiaxin Yu /* set side tone gain = 0 */
732607ac485SJiaxin Yu regmap_update_bits(afe->regmap,
733607ac485SJiaxin Yu AFE_SIDETONE_GAIN,
734607ac485SJiaxin Yu SIDE_TONE_GAIN_MASK_SFT,
735607ac485SJiaxin Yu 0);
736607ac485SJiaxin Yu regmap_update_bits(afe->regmap,
737607ac485SJiaxin Yu AFE_SIDETONE_GAIN,
738607ac485SJiaxin Yu POSITIVE_GAIN_MASK_SFT,
739607ac485SJiaxin Yu 0);
740607ac485SJiaxin Yu break;
741607ac485SJiaxin Yu default:
742607ac485SJiaxin Yu break;
743607ac485SJiaxin Yu }
744607ac485SJiaxin Yu
745607ac485SJiaxin Yu return 0;
746607ac485SJiaxin Yu }
747607ac485SJiaxin Yu
748607ac485SJiaxin Yu /* stf mux */
749607ac485SJiaxin Yu enum {
750607ac485SJiaxin Yu STF_SRC_ADDA_ADDA6 = 0,
751607ac485SJiaxin Yu STF_SRC_O19O20,
752607ac485SJiaxin Yu };
753607ac485SJiaxin Yu
754607ac485SJiaxin Yu static const char *const stf_o19o20_mux_map[] = {
755607ac485SJiaxin Yu "ADDA_ADDA6",
756607ac485SJiaxin Yu "O19O20",
757607ac485SJiaxin Yu };
758607ac485SJiaxin Yu
759607ac485SJiaxin Yu static int stf_o19o20_mux_map_value[] = {
760607ac485SJiaxin Yu STF_SRC_ADDA_ADDA6,
761607ac485SJiaxin Yu STF_SRC_O19O20,
762607ac485SJiaxin Yu };
763607ac485SJiaxin Yu
764607ac485SJiaxin Yu static SOC_VALUE_ENUM_SINGLE_DECL(stf_o19o20_mux_map_enum,
765607ac485SJiaxin Yu AFE_SIDETONE_CON1,
766607ac485SJiaxin Yu STF_SOURCE_FROM_O19O20_SFT,
767607ac485SJiaxin Yu STF_SOURCE_FROM_O19O20_MASK,
768607ac485SJiaxin Yu stf_o19o20_mux_map,
769607ac485SJiaxin Yu stf_o19o20_mux_map_value);
770607ac485SJiaxin Yu
771607ac485SJiaxin Yu static const struct snd_kcontrol_new stf_o19O20_mux_control =
772607ac485SJiaxin Yu SOC_DAPM_ENUM("STF_O19O20_MUX", stf_o19o20_mux_map_enum);
773607ac485SJiaxin Yu
774607ac485SJiaxin Yu enum {
775607ac485SJiaxin Yu STF_SRC_ADDA = 0,
776607ac485SJiaxin Yu STF_SRC_ADDA6,
777607ac485SJiaxin Yu };
778607ac485SJiaxin Yu
779607ac485SJiaxin Yu static const char *const stf_adda_mux_map[] = {
780607ac485SJiaxin Yu "ADDA",
781607ac485SJiaxin Yu "ADDA6",
782607ac485SJiaxin Yu };
783607ac485SJiaxin Yu
784607ac485SJiaxin Yu static int stf_adda_mux_map_value[] = {
785607ac485SJiaxin Yu STF_SRC_ADDA,
786607ac485SJiaxin Yu STF_SRC_ADDA6,
787607ac485SJiaxin Yu };
788607ac485SJiaxin Yu
789607ac485SJiaxin Yu static SOC_VALUE_ENUM_SINGLE_DECL(stf_adda_mux_map_enum,
790607ac485SJiaxin Yu AFE_SIDETONE_CON1,
791607ac485SJiaxin Yu STF_O19O20_OUT_EN_SEL_SFT,
792607ac485SJiaxin Yu STF_O19O20_OUT_EN_SEL_MASK,
793607ac485SJiaxin Yu stf_adda_mux_map,
794607ac485SJiaxin Yu stf_adda_mux_map_value);
795607ac485SJiaxin Yu
796607ac485SJiaxin Yu static const struct snd_kcontrol_new stf_adda_mux_control =
797607ac485SJiaxin Yu SOC_DAPM_ENUM("STF_ADDA_MUX", stf_adda_mux_map_enum);
798607ac485SJiaxin Yu
799607ac485SJiaxin Yu /* ADDA UL MUX */
800607ac485SJiaxin Yu enum {
801607ac485SJiaxin Yu ADDA_UL_MUX_MTKAIF = 0,
802607ac485SJiaxin Yu ADDA_UL_MUX_AP_DMIC,
803607ac485SJiaxin Yu ADDA_UL_MUX_MASK = 0x1,
804607ac485SJiaxin Yu };
805607ac485SJiaxin Yu
806607ac485SJiaxin Yu static const char * const adda_ul_mux_map[] = {
807607ac485SJiaxin Yu "MTKAIF", "AP_DMIC"
808607ac485SJiaxin Yu };
809607ac485SJiaxin Yu
810607ac485SJiaxin Yu static int adda_ul_map_value[] = {
811607ac485SJiaxin Yu ADDA_UL_MUX_MTKAIF,
812607ac485SJiaxin Yu ADDA_UL_MUX_AP_DMIC,
813607ac485SJiaxin Yu };
814607ac485SJiaxin Yu
815607ac485SJiaxin Yu static SOC_VALUE_ENUM_SINGLE_DECL(adda_ul_mux_map_enum,
816607ac485SJiaxin Yu SND_SOC_NOPM,
817607ac485SJiaxin Yu 0,
818607ac485SJiaxin Yu ADDA_UL_MUX_MASK,
819607ac485SJiaxin Yu adda_ul_mux_map,
820607ac485SJiaxin Yu adda_ul_map_value);
821607ac485SJiaxin Yu
822607ac485SJiaxin Yu static const struct snd_kcontrol_new adda_ul_mux_control =
823607ac485SJiaxin Yu SOC_DAPM_ENUM("ADDA_UL_MUX Select", adda_ul_mux_map_enum);
824607ac485SJiaxin Yu
825607ac485SJiaxin Yu static const struct snd_kcontrol_new adda_ch34_ul_mux_control =
826607ac485SJiaxin Yu SOC_DAPM_ENUM("ADDA_CH34_UL_MUX Select", adda_ul_mux_map_enum);
827607ac485SJiaxin Yu
828607ac485SJiaxin Yu static const struct snd_soc_dapm_widget mtk_dai_adda_widgets[] = {
829607ac485SJiaxin Yu /* inter-connections */
830607ac485SJiaxin Yu SND_SOC_DAPM_MIXER("ADDA_DL_CH1", SND_SOC_NOPM, 0, 0,
831607ac485SJiaxin Yu mtk_adda_dl_ch1_mix,
832607ac485SJiaxin Yu ARRAY_SIZE(mtk_adda_dl_ch1_mix)),
833607ac485SJiaxin Yu SND_SOC_DAPM_MIXER("ADDA_DL_CH2", SND_SOC_NOPM, 0, 0,
834607ac485SJiaxin Yu mtk_adda_dl_ch2_mix,
835607ac485SJiaxin Yu ARRAY_SIZE(mtk_adda_dl_ch2_mix)),
836607ac485SJiaxin Yu
837607ac485SJiaxin Yu SND_SOC_DAPM_MIXER("ADDA_DL_CH3", SND_SOC_NOPM, 0, 0,
838607ac485SJiaxin Yu mtk_adda_dl_ch3_mix,
839607ac485SJiaxin Yu ARRAY_SIZE(mtk_adda_dl_ch3_mix)),
840607ac485SJiaxin Yu SND_SOC_DAPM_MIXER("ADDA_DL_CH4", SND_SOC_NOPM, 0, 0,
841607ac485SJiaxin Yu mtk_adda_dl_ch4_mix,
842607ac485SJiaxin Yu ARRAY_SIZE(mtk_adda_dl_ch4_mix)),
843607ac485SJiaxin Yu
844607ac485SJiaxin Yu SND_SOC_DAPM_SUPPLY_S("ADDA Enable", SUPPLY_SEQ_ADDA_AFE_ON,
845607ac485SJiaxin Yu AFE_ADDA_UL_DL_CON0, ADDA_AFE_ON_SFT, 0,
846607ac485SJiaxin Yu NULL, 0),
847607ac485SJiaxin Yu
848607ac485SJiaxin Yu SND_SOC_DAPM_SUPPLY_S("ADDA Playback Enable", SUPPLY_SEQ_ADDA_DL_ON,
849607ac485SJiaxin Yu AFE_ADDA_DL_SRC2_CON0,
850607ac485SJiaxin Yu DL_2_SRC_ON_TMP_CTL_PRE_SFT, 0,
851607ac485SJiaxin Yu mtk_adda_dl_event,
852607ac485SJiaxin Yu SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
853607ac485SJiaxin Yu SND_SOC_DAPM_SUPPLY_S("ADDA CH34 Playback Enable",
854607ac485SJiaxin Yu SUPPLY_SEQ_ADDA_DL_ON,
855607ac485SJiaxin Yu AFE_ADDA_3RD_DAC_DL_SRC2_CON0,
856607ac485SJiaxin Yu DL_2_SRC_ON_TMP_CTL_PRE_SFT, 0,
857607ac485SJiaxin Yu mtk_adda_ch34_dl_event,
858607ac485SJiaxin Yu SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
859607ac485SJiaxin Yu
860607ac485SJiaxin Yu SND_SOC_DAPM_SUPPLY_S("ADDA Capture Enable", SUPPLY_SEQ_ADDA_UL_ON,
861607ac485SJiaxin Yu AFE_ADDA_UL_SRC_CON0,
862607ac485SJiaxin Yu UL_SRC_ON_TMP_CTL_SFT, 0,
863607ac485SJiaxin Yu mtk_adda_ul_event,
864607ac485SJiaxin Yu SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
865607ac485SJiaxin Yu SND_SOC_DAPM_SUPPLY_S("ADDA CH34 Capture Enable", SUPPLY_SEQ_ADDA_UL_ON,
866607ac485SJiaxin Yu AFE_ADDA6_UL_SRC_CON0,
867607ac485SJiaxin Yu UL_SRC_ON_TMP_CTL_SFT, 0,
868607ac485SJiaxin Yu mtk_adda_ch34_ul_event,
869607ac485SJiaxin Yu SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
870607ac485SJiaxin Yu
871607ac485SJiaxin Yu SND_SOC_DAPM_SUPPLY_S("AUD_PAD_TOP", SUPPLY_SEQ_ADDA_AUD_PAD_TOP,
872607ac485SJiaxin Yu AFE_AUD_PAD_TOP,
873607ac485SJiaxin Yu RG_RX_FIFO_ON_SFT, 0,
874607ac485SJiaxin Yu mtk_adda_pad_top_event,
875607ac485SJiaxin Yu SND_SOC_DAPM_PRE_PMU),
876607ac485SJiaxin Yu SND_SOC_DAPM_SUPPLY_S("ADDA_MTKAIF_CFG", SUPPLY_SEQ_ADDA_MTKAIF_CFG,
877607ac485SJiaxin Yu SND_SOC_NOPM, 0, 0,
878607ac485SJiaxin Yu mtk_adda_mtkaif_cfg_event,
879607ac485SJiaxin Yu SND_SOC_DAPM_PRE_PMU),
880607ac485SJiaxin Yu SND_SOC_DAPM_SUPPLY_S("ADDA6_MTKAIF_CFG", SUPPLY_SEQ_ADDA6_MTKAIF_CFG,
881607ac485SJiaxin Yu SND_SOC_NOPM, 0, 0,
882607ac485SJiaxin Yu mtk_adda_mtkaif_cfg_event,
883607ac485SJiaxin Yu SND_SOC_DAPM_PRE_PMU),
884607ac485SJiaxin Yu
885607ac485SJiaxin Yu SND_SOC_DAPM_SUPPLY_S("AP_DMIC_EN", SUPPLY_SEQ_ADDA_AP_DMIC,
886607ac485SJiaxin Yu AFE_ADDA_UL_SRC_CON0,
887607ac485SJiaxin Yu UL_AP_DMIC_ON_SFT, 0,
888607ac485SJiaxin Yu NULL, 0),
889607ac485SJiaxin Yu SND_SOC_DAPM_SUPPLY_S("AP_DMIC_CH34_EN", SUPPLY_SEQ_ADDA_AP_DMIC,
890607ac485SJiaxin Yu AFE_ADDA6_UL_SRC_CON0,
891607ac485SJiaxin Yu UL_AP_DMIC_ON_SFT, 0,
892607ac485SJiaxin Yu NULL, 0),
893607ac485SJiaxin Yu
894607ac485SJiaxin Yu SND_SOC_DAPM_SUPPLY_S("ADDA_FIFO", SUPPLY_SEQ_ADDA_FIFO,
895607ac485SJiaxin Yu AFE_ADDA_UL_DL_CON0,
896607ac485SJiaxin Yu AFE_ADDA_FIFO_AUTO_RST_SFT, 1,
897607ac485SJiaxin Yu NULL, 0),
898607ac485SJiaxin Yu SND_SOC_DAPM_SUPPLY_S("ADDA_CH34_FIFO", SUPPLY_SEQ_ADDA_FIFO,
899607ac485SJiaxin Yu AFE_ADDA_UL_DL_CON0,
900607ac485SJiaxin Yu AFE_ADDA6_FIFO_AUTO_RST_SFT, 1,
901607ac485SJiaxin Yu NULL, 0),
902607ac485SJiaxin Yu
903607ac485SJiaxin Yu SND_SOC_DAPM_MUX("ADDA_UL_Mux", SND_SOC_NOPM, 0, 0,
904607ac485SJiaxin Yu &adda_ul_mux_control),
905607ac485SJiaxin Yu SND_SOC_DAPM_MUX("ADDA_CH34_UL_Mux", SND_SOC_NOPM, 0, 0,
906607ac485SJiaxin Yu &adda_ch34_ul_mux_control),
907607ac485SJiaxin Yu
908607ac485SJiaxin Yu SND_SOC_DAPM_INPUT("AP_DMIC_INPUT"),
909607ac485SJiaxin Yu SND_SOC_DAPM_INPUT("AP_DMIC_CH34_INPUT"),
910607ac485SJiaxin Yu
911607ac485SJiaxin Yu /* stf */
912607ac485SJiaxin Yu SND_SOC_DAPM_SWITCH_E("Sidetone Filter",
913607ac485SJiaxin Yu AFE_SIDETONE_CON1, SIDE_TONE_ON_SFT, 0,
914607ac485SJiaxin Yu &stf_ctl,
915607ac485SJiaxin Yu mtk_stf_event,
916607ac485SJiaxin Yu SND_SOC_DAPM_PRE_PMU |
917607ac485SJiaxin Yu SND_SOC_DAPM_POST_PMD),
918607ac485SJiaxin Yu SND_SOC_DAPM_MUX("STF_O19O20_MUX", SND_SOC_NOPM, 0, 0,
919607ac485SJiaxin Yu &stf_o19O20_mux_control),
920607ac485SJiaxin Yu SND_SOC_DAPM_MUX("STF_ADDA_MUX", SND_SOC_NOPM, 0, 0,
921607ac485SJiaxin Yu &stf_adda_mux_control),
922607ac485SJiaxin Yu SND_SOC_DAPM_MIXER("STF_CH1", SND_SOC_NOPM, 0, 0,
923607ac485SJiaxin Yu mtk_stf_ch1_mix,
924607ac485SJiaxin Yu ARRAY_SIZE(mtk_stf_ch1_mix)),
925607ac485SJiaxin Yu SND_SOC_DAPM_MIXER("STF_CH2", SND_SOC_NOPM, 0, 0,
926607ac485SJiaxin Yu mtk_stf_ch2_mix,
927607ac485SJiaxin Yu ARRAY_SIZE(mtk_stf_ch2_mix)),
928607ac485SJiaxin Yu SND_SOC_DAPM_OUTPUT("STF_OUTPUT"),
929607ac485SJiaxin Yu
930607ac485SJiaxin Yu /* clock */
931607ac485SJiaxin Yu SND_SOC_DAPM_CLOCK_SUPPLY("top_mux_audio_h"),
932607ac485SJiaxin Yu
933607ac485SJiaxin Yu SND_SOC_DAPM_CLOCK_SUPPLY("aud_dac_clk"),
934607ac485SJiaxin Yu SND_SOC_DAPM_CLOCK_SUPPLY("aud_dac_predis_clk"),
935607ac485SJiaxin Yu SND_SOC_DAPM_CLOCK_SUPPLY("aud_3rd_dac_clk"),
936607ac485SJiaxin Yu SND_SOC_DAPM_CLOCK_SUPPLY("aud_3rd_dac_predis_clk"),
937607ac485SJiaxin Yu
938607ac485SJiaxin Yu SND_SOC_DAPM_CLOCK_SUPPLY("aud_adc_clk"),
939607ac485SJiaxin Yu SND_SOC_DAPM_CLOCK_SUPPLY("aud_adda6_adc_clk"),
940607ac485SJiaxin Yu };
941607ac485SJiaxin Yu
942607ac485SJiaxin Yu static const struct snd_soc_dapm_route mtk_dai_adda_routes[] = {
943607ac485SJiaxin Yu /* playback */
944607ac485SJiaxin Yu {"ADDA_DL_CH1", "DL1_CH1", "DL1"},
945607ac485SJiaxin Yu {"ADDA_DL_CH2", "DL1_CH1", "DL1"},
946607ac485SJiaxin Yu {"ADDA_DL_CH2", "DL1_CH2", "DL1"},
947607ac485SJiaxin Yu
948607ac485SJiaxin Yu {"ADDA_DL_CH1", "DL12_CH1", "DL12"},
949607ac485SJiaxin Yu {"ADDA_DL_CH2", "DL12_CH2", "DL12"},
950607ac485SJiaxin Yu
951607ac485SJiaxin Yu {"ADDA_DL_CH1", "DL6_CH1", "DL6"},
952607ac485SJiaxin Yu {"ADDA_DL_CH2", "DL6_CH2", "DL6"},
953607ac485SJiaxin Yu
954607ac485SJiaxin Yu {"ADDA_DL_CH1", "DL8_CH1", "DL8"},
955607ac485SJiaxin Yu {"ADDA_DL_CH2", "DL8_CH2", "DL8"},
956607ac485SJiaxin Yu
957607ac485SJiaxin Yu {"ADDA_DL_CH1", "DL2_CH1", "DL2"},
958607ac485SJiaxin Yu {"ADDA_DL_CH2", "DL2_CH1", "DL2"},
959607ac485SJiaxin Yu {"ADDA_DL_CH2", "DL2_CH2", "DL2"},
960607ac485SJiaxin Yu
961607ac485SJiaxin Yu {"ADDA_DL_CH1", "DL3_CH1", "DL3"},
962607ac485SJiaxin Yu {"ADDA_DL_CH2", "DL3_CH1", "DL3"},
963607ac485SJiaxin Yu {"ADDA_DL_CH2", "DL3_CH2", "DL3"},
964607ac485SJiaxin Yu
965607ac485SJiaxin Yu {"ADDA_DL_CH1", "DL4_CH1", "DL4"},
966607ac485SJiaxin Yu {"ADDA_DL_CH2", "DL4_CH2", "DL4"},
967607ac485SJiaxin Yu
968607ac485SJiaxin Yu {"ADDA_DL_CH1", "DL5_CH1", "DL5"},
969607ac485SJiaxin Yu {"ADDA_DL_CH2", "DL5_CH2", "DL5"},
970607ac485SJiaxin Yu
971607ac485SJiaxin Yu {"ADDA Playback", NULL, "ADDA_DL_CH1"},
972607ac485SJiaxin Yu {"ADDA Playback", NULL, "ADDA_DL_CH2"},
973607ac485SJiaxin Yu
974607ac485SJiaxin Yu {"ADDA Playback", NULL, "ADDA Enable"},
975607ac485SJiaxin Yu {"ADDA Playback", NULL, "ADDA Playback Enable"},
976607ac485SJiaxin Yu
977607ac485SJiaxin Yu {"ADDA_DL_CH3", "DL1_CH1", "DL1"},
978607ac485SJiaxin Yu {"ADDA_DL_CH4", "DL1_CH1", "DL1"},
979607ac485SJiaxin Yu {"ADDA_DL_CH4", "DL1_CH2", "DL1"},
980607ac485SJiaxin Yu
981607ac485SJiaxin Yu {"ADDA_DL_CH3", "DL12_CH1", "DL12"},
982607ac485SJiaxin Yu {"ADDA_DL_CH4", "DL12_CH2", "DL12"},
983607ac485SJiaxin Yu
984607ac485SJiaxin Yu {"ADDA_DL_CH3", "DL6_CH1", "DL6"},
985607ac485SJiaxin Yu {"ADDA_DL_CH4", "DL6_CH2", "DL6"},
986607ac485SJiaxin Yu
987607ac485SJiaxin Yu {"ADDA_DL_CH3", "DL2_CH1", "DL2"},
988607ac485SJiaxin Yu {"ADDA_DL_CH4", "DL2_CH1", "DL2"},
989607ac485SJiaxin Yu {"ADDA_DL_CH4", "DL2_CH2", "DL2"},
990607ac485SJiaxin Yu
991607ac485SJiaxin Yu {"ADDA_DL_CH3", "DL3_CH1", "DL3"},
992607ac485SJiaxin Yu {"ADDA_DL_CH4", "DL3_CH1", "DL3"},
993607ac485SJiaxin Yu {"ADDA_DL_CH4", "DL3_CH2", "DL3"},
994607ac485SJiaxin Yu
995607ac485SJiaxin Yu {"ADDA_DL_CH3", "DL4_CH1", "DL4"},
996607ac485SJiaxin Yu {"ADDA_DL_CH4", "DL4_CH2", "DL4"},
997607ac485SJiaxin Yu
998607ac485SJiaxin Yu {"ADDA_DL_CH3", "DL5_CH1", "DL5"},
999607ac485SJiaxin Yu {"ADDA_DL_CH4", "DL5_CH2", "DL5"},
1000607ac485SJiaxin Yu
1001607ac485SJiaxin Yu {"ADDA CH34 Playback", NULL, "ADDA_DL_CH3"},
1002607ac485SJiaxin Yu {"ADDA CH34 Playback", NULL, "ADDA_DL_CH4"},
1003607ac485SJiaxin Yu
1004607ac485SJiaxin Yu {"ADDA CH34 Playback", NULL, "ADDA Enable"},
1005607ac485SJiaxin Yu {"ADDA CH34 Playback", NULL, "ADDA CH34 Playback Enable"},
1006607ac485SJiaxin Yu
1007607ac485SJiaxin Yu /* capture */
1008607ac485SJiaxin Yu {"ADDA_UL_Mux", "MTKAIF", "ADDA Capture"},
1009607ac485SJiaxin Yu {"ADDA_UL_Mux", "AP_DMIC", "AP DMIC Capture"},
1010607ac485SJiaxin Yu
1011607ac485SJiaxin Yu {"ADDA_CH34_UL_Mux", "MTKAIF", "ADDA CH34 Capture"},
1012607ac485SJiaxin Yu {"ADDA_CH34_UL_Mux", "AP_DMIC", "AP DMIC CH34 Capture"},
1013607ac485SJiaxin Yu
1014607ac485SJiaxin Yu {"ADDA Capture", NULL, "ADDA Enable"},
1015607ac485SJiaxin Yu {"ADDA Capture", NULL, "ADDA Capture Enable"},
1016607ac485SJiaxin Yu {"ADDA Capture", NULL, "AUD_PAD_TOP"},
1017607ac485SJiaxin Yu {"ADDA Capture", NULL, "ADDA_MTKAIF_CFG"},
1018607ac485SJiaxin Yu
1019607ac485SJiaxin Yu {"AP DMIC Capture", NULL, "ADDA Enable"},
1020607ac485SJiaxin Yu {"AP DMIC Capture", NULL, "ADDA Capture Enable"},
1021607ac485SJiaxin Yu {"AP DMIC Capture", NULL, "ADDA_FIFO"},
1022607ac485SJiaxin Yu {"AP DMIC Capture", NULL, "AP_DMIC_EN"},
1023607ac485SJiaxin Yu
1024607ac485SJiaxin Yu {"ADDA CH34 Capture", NULL, "ADDA Enable"},
1025607ac485SJiaxin Yu {"ADDA CH34 Capture", NULL, "ADDA CH34 Capture Enable"},
1026607ac485SJiaxin Yu {"ADDA CH34 Capture", NULL, "AUD_PAD_TOP"},
1027607ac485SJiaxin Yu {"ADDA CH34 Capture", NULL, "ADDA6_MTKAIF_CFG"},
1028607ac485SJiaxin Yu
1029607ac485SJiaxin Yu {"AP DMIC CH34 Capture", NULL, "ADDA Enable"},
1030607ac485SJiaxin Yu {"AP DMIC CH34 Capture", NULL, "ADDA CH34 Capture Enable"},
1031607ac485SJiaxin Yu {"AP DMIC CH34 Capture", NULL, "ADDA_CH34_FIFO"},
1032607ac485SJiaxin Yu {"AP DMIC CH34 Capture", NULL, "AP_DMIC_CH34_EN"},
1033607ac485SJiaxin Yu
1034607ac485SJiaxin Yu {"AP DMIC Capture", NULL, "AP_DMIC_INPUT"},
1035607ac485SJiaxin Yu {"AP DMIC CH34 Capture", NULL, "AP_DMIC_CH34_INPUT"},
1036607ac485SJiaxin Yu
1037607ac485SJiaxin Yu /* sidetone filter */
1038607ac485SJiaxin Yu {"STF_ADDA_MUX", "ADDA", "ADDA_UL_Mux"},
1039607ac485SJiaxin Yu {"STF_ADDA_MUX", "ADDA6", "ADDA_CH34_UL_Mux"},
1040607ac485SJiaxin Yu
1041607ac485SJiaxin Yu {"STF_O19O20_MUX", "ADDA_ADDA6", "STF_ADDA_MUX"},
1042607ac485SJiaxin Yu {"STF_O19O20_MUX", "O19O20", "STF_CH1"},
1043607ac485SJiaxin Yu {"STF_O19O20_MUX", "O19O20", "STF_CH2"},
1044607ac485SJiaxin Yu
1045607ac485SJiaxin Yu {"Sidetone Filter", "Switch", "STF_O19O20_MUX"},
1046607ac485SJiaxin Yu {"STF_OUTPUT", NULL, "Sidetone Filter"},
1047607ac485SJiaxin Yu {"ADDA Playback", NULL, "Sidetone Filter"},
1048607ac485SJiaxin Yu {"ADDA CH34 Playback", NULL, "Sidetone Filter"},
1049607ac485SJiaxin Yu
1050607ac485SJiaxin Yu /* clk */
1051607ac485SJiaxin Yu {"ADDA Playback", NULL, "aud_dac_clk"},
1052607ac485SJiaxin Yu {"ADDA Playback", NULL, "aud_dac_predis_clk"},
1053607ac485SJiaxin Yu
1054607ac485SJiaxin Yu {"ADDA CH34 Playback", NULL, "aud_3rd_dac_clk"},
1055607ac485SJiaxin Yu {"ADDA CH34 Playback", NULL, "aud_3rd_dac_predis_clk"},
1056607ac485SJiaxin Yu
1057607ac485SJiaxin Yu {"ADDA Capture Enable", NULL, "aud_adc_clk"},
1058607ac485SJiaxin Yu {"ADDA CH34 Capture Enable", NULL, "aud_adda6_adc_clk"},
1059607ac485SJiaxin Yu };
1060607ac485SJiaxin Yu
1061607ac485SJiaxin Yu /* dai ops */
mtk_dai_adda_hw_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * params,struct snd_soc_dai * dai)1062607ac485SJiaxin Yu static int mtk_dai_adda_hw_params(struct snd_pcm_substream *substream,
1063607ac485SJiaxin Yu struct snd_pcm_hw_params *params,
1064607ac485SJiaxin Yu struct snd_soc_dai *dai)
1065607ac485SJiaxin Yu {
1066607ac485SJiaxin Yu struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
1067607ac485SJiaxin Yu unsigned int rate = params_rate(params);
1068607ac485SJiaxin Yu int id = dai->id;
1069607ac485SJiaxin Yu
1070607ac485SJiaxin Yu if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
1071607ac485SJiaxin Yu unsigned int dl_src2_con0 = 0;
1072607ac485SJiaxin Yu unsigned int dl_src2_con1 = 0;
1073607ac485SJiaxin Yu
1074607ac485SJiaxin Yu /* set sampling rate */
1075*d6c01755SAngeloGioacchino Del Regno dl_src2_con0 = mtk_adda_dl_rate_transform(afe, rate) <<
1076607ac485SJiaxin Yu DL_2_INPUT_MODE_CTL_SFT;
1077607ac485SJiaxin Yu
1078607ac485SJiaxin Yu /* set output mode, UP_SAMPLING_RATE_X8 */
1079607ac485SJiaxin Yu dl_src2_con0 |= (0x3 << DL_2_OUTPUT_SEL_CTL_SFT);
1080607ac485SJiaxin Yu
1081607ac485SJiaxin Yu /* turn off mute function */
1082607ac485SJiaxin Yu dl_src2_con0 |= (0x01 << DL_2_MUTE_CH2_OFF_CTL_PRE_SFT);
1083607ac485SJiaxin Yu dl_src2_con0 |= (0x01 << DL_2_MUTE_CH1_OFF_CTL_PRE_SFT);
1084607ac485SJiaxin Yu
1085607ac485SJiaxin Yu /* set voice input data if input sample rate is 8k or 16k */
1086607ac485SJiaxin Yu if (rate == 8000 || rate == 16000)
1087607ac485SJiaxin Yu dl_src2_con0 |= 0x01 << DL_2_VOICE_MODE_CTL_PRE_SFT;
1088607ac485SJiaxin Yu
1089607ac485SJiaxin Yu /* SA suggest apply -0.3db to audio/speech path */
1090607ac485SJiaxin Yu dl_src2_con1 = MTK_AFE_ADDA_DL_GAIN_NORMAL <<
1091607ac485SJiaxin Yu DL_2_GAIN_CTL_PRE_SFT;
1092607ac485SJiaxin Yu
1093607ac485SJiaxin Yu /* turn on down-link gain */
1094607ac485SJiaxin Yu dl_src2_con0 |= (0x01 << DL_2_GAIN_ON_CTL_PRE_SFT);
1095607ac485SJiaxin Yu
1096607ac485SJiaxin Yu if (id == MT8192_DAI_ADDA) {
1097607ac485SJiaxin Yu /* clean predistortion */
1098607ac485SJiaxin Yu regmap_write(afe->regmap, AFE_ADDA_PREDIS_CON0, 0);
1099607ac485SJiaxin Yu regmap_write(afe->regmap, AFE_ADDA_PREDIS_CON1, 0);
1100607ac485SJiaxin Yu
1101607ac485SJiaxin Yu regmap_write(afe->regmap,
1102607ac485SJiaxin Yu AFE_ADDA_DL_SRC2_CON0, dl_src2_con0);
1103607ac485SJiaxin Yu regmap_write(afe->regmap,
1104607ac485SJiaxin Yu AFE_ADDA_DL_SRC2_CON1, dl_src2_con1);
1105607ac485SJiaxin Yu
1106607ac485SJiaxin Yu /* set sdm gain */
1107607ac485SJiaxin Yu regmap_update_bits(afe->regmap,
1108607ac485SJiaxin Yu AFE_ADDA_DL_SDM_DCCOMP_CON,
1109607ac485SJiaxin Yu ATTGAIN_CTL_MASK_SFT,
1110607ac485SJiaxin Yu AUDIO_SDM_LEVEL_NORMAL <<
1111607ac485SJiaxin Yu ATTGAIN_CTL_SFT);
1112607ac485SJiaxin Yu
1113607ac485SJiaxin Yu /* 2nd sdm */
1114607ac485SJiaxin Yu regmap_update_bits(afe->regmap,
1115607ac485SJiaxin Yu AFE_ADDA_DL_SDM_DCCOMP_CON,
1116607ac485SJiaxin Yu USE_3RD_SDM_MASK_SFT,
1117607ac485SJiaxin Yu AUDIO_SDM_2ND << USE_3RD_SDM_SFT);
1118607ac485SJiaxin Yu
1119607ac485SJiaxin Yu /* sdm auto reset */
1120607ac485SJiaxin Yu regmap_write(afe->regmap,
1121607ac485SJiaxin Yu AFE_ADDA_DL_SDM_AUTO_RESET_CON,
1122607ac485SJiaxin Yu SDM_AUTO_RESET_THRESHOLD);
1123607ac485SJiaxin Yu regmap_update_bits(afe->regmap,
1124607ac485SJiaxin Yu AFE_ADDA_DL_SDM_AUTO_RESET_CON,
1125607ac485SJiaxin Yu ADDA_SDM_AUTO_RESET_ONOFF_MASK_SFT,
1126607ac485SJiaxin Yu 0x1 << ADDA_SDM_AUTO_RESET_ONOFF_SFT);
1127607ac485SJiaxin Yu } else {
1128607ac485SJiaxin Yu /* clean predistortion */
1129607ac485SJiaxin Yu regmap_write(afe->regmap,
1130607ac485SJiaxin Yu AFE_ADDA_3RD_DAC_PREDIS_CON0, 0);
1131607ac485SJiaxin Yu regmap_write(afe->regmap,
1132607ac485SJiaxin Yu AFE_ADDA_3RD_DAC_PREDIS_CON1, 0);
1133607ac485SJiaxin Yu
1134607ac485SJiaxin Yu regmap_write(afe->regmap, AFE_ADDA_3RD_DAC_DL_SRC2_CON0,
1135607ac485SJiaxin Yu dl_src2_con0);
1136607ac485SJiaxin Yu regmap_write(afe->regmap, AFE_ADDA_3RD_DAC_DL_SRC2_CON1,
1137607ac485SJiaxin Yu dl_src2_con1);
1138607ac485SJiaxin Yu
1139607ac485SJiaxin Yu /* set sdm gain */
1140607ac485SJiaxin Yu regmap_update_bits(afe->regmap,
1141607ac485SJiaxin Yu AFE_ADDA_3RD_DAC_DL_SDM_DCCOMP_CON,
1142607ac485SJiaxin Yu ATTGAIN_CTL_MASK_SFT,
1143607ac485SJiaxin Yu AUDIO_SDM_LEVEL_NORMAL <<
1144607ac485SJiaxin Yu ATTGAIN_CTL_SFT);
1145607ac485SJiaxin Yu
1146607ac485SJiaxin Yu /* 2nd sdm */
1147607ac485SJiaxin Yu regmap_update_bits(afe->regmap,
1148607ac485SJiaxin Yu AFE_ADDA_3RD_DAC_DL_SDM_DCCOMP_CON,
1149607ac485SJiaxin Yu USE_3RD_SDM_MASK_SFT,
1150607ac485SJiaxin Yu AUDIO_SDM_2ND << USE_3RD_SDM_SFT);
1151607ac485SJiaxin Yu
1152607ac485SJiaxin Yu /* sdm auto reset */
1153607ac485SJiaxin Yu regmap_write(afe->regmap,
1154607ac485SJiaxin Yu AFE_ADDA_3RD_DAC_DL_SDM_AUTO_RESET_CON,
1155607ac485SJiaxin Yu SDM_AUTO_RESET_THRESHOLD);
1156607ac485SJiaxin Yu regmap_update_bits(afe->regmap,
1157607ac485SJiaxin Yu AFE_ADDA_3RD_DAC_DL_SDM_AUTO_RESET_CON,
1158607ac485SJiaxin Yu ADDA_3RD_DAC_SDM_AUTO_RESET_ONOFF_MASK_SFT,
1159607ac485SJiaxin Yu 0x1 << ADDA_3RD_DAC_SDM_AUTO_RESET_ONOFF_SFT);
1160607ac485SJiaxin Yu }
1161607ac485SJiaxin Yu } else {
1162607ac485SJiaxin Yu unsigned int voice_mode = 0;
1163607ac485SJiaxin Yu unsigned int ul_src_con0 = 0; /* default value */
1164607ac485SJiaxin Yu
1165*d6c01755SAngeloGioacchino Del Regno voice_mode = mtk_adda_ul_rate_transform(afe, rate);
1166607ac485SJiaxin Yu
1167607ac485SJiaxin Yu ul_src_con0 |= (voice_mode << 17) & (0x7 << 17);
1168607ac485SJiaxin Yu
1169607ac485SJiaxin Yu /* enable iir */
1170607ac485SJiaxin Yu ul_src_con0 |= (1 << UL_IIR_ON_TMP_CTL_SFT) &
1171607ac485SJiaxin Yu UL_IIR_ON_TMP_CTL_MASK_SFT;
1172607ac485SJiaxin Yu ul_src_con0 |= (UL_IIR_SW << UL_IIRMODE_CTL_SFT) &
1173607ac485SJiaxin Yu UL_IIRMODE_CTL_MASK_SFT;
1174607ac485SJiaxin Yu
1175607ac485SJiaxin Yu switch (id) {
1176607ac485SJiaxin Yu case MT8192_DAI_ADDA:
1177607ac485SJiaxin Yu case MT8192_DAI_AP_DMIC:
1178607ac485SJiaxin Yu /* 35Hz @ 48k */
1179607ac485SJiaxin Yu regmap_write(afe->regmap,
1180607ac485SJiaxin Yu AFE_ADDA_IIR_COEF_02_01, 0x00000000);
1181607ac485SJiaxin Yu regmap_write(afe->regmap,
1182607ac485SJiaxin Yu AFE_ADDA_IIR_COEF_04_03, 0x00003FB8);
1183607ac485SJiaxin Yu regmap_write(afe->regmap,
1184607ac485SJiaxin Yu AFE_ADDA_IIR_COEF_06_05, 0x3FB80000);
1185607ac485SJiaxin Yu regmap_write(afe->regmap,
1186607ac485SJiaxin Yu AFE_ADDA_IIR_COEF_08_07, 0x3FB80000);
1187607ac485SJiaxin Yu regmap_write(afe->regmap,
1188607ac485SJiaxin Yu AFE_ADDA_IIR_COEF_10_09, 0x0000C048);
1189607ac485SJiaxin Yu
1190607ac485SJiaxin Yu regmap_write(afe->regmap,
1191607ac485SJiaxin Yu AFE_ADDA_UL_SRC_CON0, ul_src_con0);
1192607ac485SJiaxin Yu
1193607ac485SJiaxin Yu /* Using Internal ADC */
1194607ac485SJiaxin Yu regmap_update_bits(afe->regmap,
1195607ac485SJiaxin Yu AFE_ADDA_TOP_CON0,
1196607ac485SJiaxin Yu 0x1 << 0,
1197607ac485SJiaxin Yu 0x0 << 0);
1198607ac485SJiaxin Yu
1199607ac485SJiaxin Yu /* mtkaif_rxif_data_mode = 0, amic */
1200607ac485SJiaxin Yu regmap_update_bits(afe->regmap,
1201607ac485SJiaxin Yu AFE_ADDA_MTKAIF_RX_CFG0,
1202607ac485SJiaxin Yu 0x1 << 0,
1203607ac485SJiaxin Yu 0x0 << 0);
1204607ac485SJiaxin Yu break;
1205607ac485SJiaxin Yu case MT8192_DAI_ADDA_CH34:
1206607ac485SJiaxin Yu case MT8192_DAI_AP_DMIC_CH34:
1207607ac485SJiaxin Yu /* 35Hz @ 48k */
1208607ac485SJiaxin Yu regmap_write(afe->regmap,
1209607ac485SJiaxin Yu AFE_ADDA6_IIR_COEF_02_01, 0x00000000);
1210607ac485SJiaxin Yu regmap_write(afe->regmap,
1211607ac485SJiaxin Yu AFE_ADDA6_IIR_COEF_04_03, 0x00003FB8);
1212607ac485SJiaxin Yu regmap_write(afe->regmap,
1213607ac485SJiaxin Yu AFE_ADDA6_IIR_COEF_06_05, 0x3FB80000);
1214607ac485SJiaxin Yu regmap_write(afe->regmap,
1215607ac485SJiaxin Yu AFE_ADDA6_IIR_COEF_08_07, 0x3FB80000);
1216607ac485SJiaxin Yu regmap_write(afe->regmap,
1217607ac485SJiaxin Yu AFE_ADDA6_IIR_COEF_10_09, 0x0000C048);
1218607ac485SJiaxin Yu
1219607ac485SJiaxin Yu regmap_write(afe->regmap,
1220607ac485SJiaxin Yu AFE_ADDA6_UL_SRC_CON0, ul_src_con0);
1221607ac485SJiaxin Yu
1222607ac485SJiaxin Yu /* Using Internal ADC */
1223607ac485SJiaxin Yu regmap_update_bits(afe->regmap,
1224607ac485SJiaxin Yu AFE_ADDA6_TOP_CON0,
1225607ac485SJiaxin Yu 0x1 << 0,
1226607ac485SJiaxin Yu 0x0 << 0);
1227607ac485SJiaxin Yu
1228607ac485SJiaxin Yu /* mtkaif_rxif_data_mode = 0, amic */
1229607ac485SJiaxin Yu regmap_update_bits(afe->regmap,
1230607ac485SJiaxin Yu AFE_ADDA6_MTKAIF_RX_CFG0,
1231607ac485SJiaxin Yu 0x1 << 0,
1232607ac485SJiaxin Yu 0x0 << 0);
1233607ac485SJiaxin Yu break;
1234607ac485SJiaxin Yu default:
1235607ac485SJiaxin Yu break;
1236607ac485SJiaxin Yu }
1237607ac485SJiaxin Yu
1238607ac485SJiaxin Yu /* ap dmic */
1239607ac485SJiaxin Yu switch (id) {
1240607ac485SJiaxin Yu case MT8192_DAI_AP_DMIC:
1241607ac485SJiaxin Yu case MT8192_DAI_AP_DMIC_CH34:
1242607ac485SJiaxin Yu mtk_adda_ul_src_dmic(afe, id);
1243607ac485SJiaxin Yu break;
1244607ac485SJiaxin Yu default:
1245607ac485SJiaxin Yu break;
1246607ac485SJiaxin Yu }
1247607ac485SJiaxin Yu }
1248607ac485SJiaxin Yu
1249607ac485SJiaxin Yu return 0;
1250607ac485SJiaxin Yu }
1251607ac485SJiaxin Yu
1252607ac485SJiaxin Yu static const struct snd_soc_dai_ops mtk_dai_adda_ops = {
1253607ac485SJiaxin Yu .hw_params = mtk_dai_adda_hw_params,
1254607ac485SJiaxin Yu };
1255607ac485SJiaxin Yu
1256607ac485SJiaxin Yu /* dai driver */
1257607ac485SJiaxin Yu #define MTK_ADDA_PLAYBACK_RATES (SNDRV_PCM_RATE_8000_48000 |\
1258607ac485SJiaxin Yu SNDRV_PCM_RATE_96000 |\
1259607ac485SJiaxin Yu SNDRV_PCM_RATE_192000)
1260607ac485SJiaxin Yu
1261607ac485SJiaxin Yu #define MTK_ADDA_CAPTURE_RATES (SNDRV_PCM_RATE_8000 |\
1262607ac485SJiaxin Yu SNDRV_PCM_RATE_16000 |\
1263607ac485SJiaxin Yu SNDRV_PCM_RATE_32000 |\
1264607ac485SJiaxin Yu SNDRV_PCM_RATE_48000 |\
1265607ac485SJiaxin Yu SNDRV_PCM_RATE_96000 |\
1266607ac485SJiaxin Yu SNDRV_PCM_RATE_192000)
1267607ac485SJiaxin Yu
1268607ac485SJiaxin Yu #define MTK_ADDA_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
1269607ac485SJiaxin Yu SNDRV_PCM_FMTBIT_S24_LE |\
1270607ac485SJiaxin Yu SNDRV_PCM_FMTBIT_S32_LE)
1271607ac485SJiaxin Yu
1272607ac485SJiaxin Yu static struct snd_soc_dai_driver mtk_dai_adda_driver[] = {
1273607ac485SJiaxin Yu {
1274607ac485SJiaxin Yu .name = "ADDA",
1275607ac485SJiaxin Yu .id = MT8192_DAI_ADDA,
1276607ac485SJiaxin Yu .playback = {
1277607ac485SJiaxin Yu .stream_name = "ADDA Playback",
1278607ac485SJiaxin Yu .channels_min = 1,
1279607ac485SJiaxin Yu .channels_max = 2,
1280607ac485SJiaxin Yu .rates = MTK_ADDA_PLAYBACK_RATES,
1281607ac485SJiaxin Yu .formats = MTK_ADDA_FORMATS,
1282607ac485SJiaxin Yu },
1283607ac485SJiaxin Yu .capture = {
1284607ac485SJiaxin Yu .stream_name = "ADDA Capture",
1285607ac485SJiaxin Yu .channels_min = 1,
1286607ac485SJiaxin Yu .channels_max = 2,
1287607ac485SJiaxin Yu .rates = MTK_ADDA_CAPTURE_RATES,
1288607ac485SJiaxin Yu .formats = MTK_ADDA_FORMATS,
1289607ac485SJiaxin Yu },
1290607ac485SJiaxin Yu .ops = &mtk_dai_adda_ops,
1291607ac485SJiaxin Yu },
1292607ac485SJiaxin Yu {
1293607ac485SJiaxin Yu .name = "ADDA_CH34",
1294607ac485SJiaxin Yu .id = MT8192_DAI_ADDA_CH34,
1295607ac485SJiaxin Yu .playback = {
1296607ac485SJiaxin Yu .stream_name = "ADDA CH34 Playback",
1297607ac485SJiaxin Yu .channels_min = 1,
1298607ac485SJiaxin Yu .channels_max = 2,
1299607ac485SJiaxin Yu .rates = MTK_ADDA_PLAYBACK_RATES,
1300607ac485SJiaxin Yu .formats = MTK_ADDA_FORMATS,
1301607ac485SJiaxin Yu },
1302607ac485SJiaxin Yu .capture = {
1303607ac485SJiaxin Yu .stream_name = "ADDA CH34 Capture",
1304607ac485SJiaxin Yu .channels_min = 1,
1305607ac485SJiaxin Yu .channels_max = 2,
1306607ac485SJiaxin Yu .rates = MTK_ADDA_CAPTURE_RATES,
1307607ac485SJiaxin Yu .formats = MTK_ADDA_FORMATS,
1308607ac485SJiaxin Yu },
1309607ac485SJiaxin Yu .ops = &mtk_dai_adda_ops,
1310607ac485SJiaxin Yu },
1311607ac485SJiaxin Yu {
1312607ac485SJiaxin Yu .name = "AP_DMIC",
1313607ac485SJiaxin Yu .id = MT8192_DAI_AP_DMIC,
1314607ac485SJiaxin Yu .capture = {
1315607ac485SJiaxin Yu .stream_name = "AP DMIC Capture",
1316607ac485SJiaxin Yu .channels_min = 1,
1317607ac485SJiaxin Yu .channels_max = 2,
1318607ac485SJiaxin Yu .rates = MTK_ADDA_CAPTURE_RATES,
1319607ac485SJiaxin Yu .formats = MTK_ADDA_FORMATS,
1320607ac485SJiaxin Yu },
1321607ac485SJiaxin Yu .ops = &mtk_dai_adda_ops,
1322607ac485SJiaxin Yu },
1323607ac485SJiaxin Yu {
1324607ac485SJiaxin Yu .name = "AP_DMIC_CH34",
1325607ac485SJiaxin Yu .id = MT8192_DAI_AP_DMIC_CH34,
1326607ac485SJiaxin Yu .capture = {
1327607ac485SJiaxin Yu .stream_name = "AP DMIC CH34 Capture",
1328607ac485SJiaxin Yu .channels_min = 1,
1329607ac485SJiaxin Yu .channels_max = 2,
1330607ac485SJiaxin Yu .rates = MTK_ADDA_CAPTURE_RATES,
1331607ac485SJiaxin Yu .formats = MTK_ADDA_FORMATS,
1332607ac485SJiaxin Yu },
1333607ac485SJiaxin Yu .ops = &mtk_dai_adda_ops,
1334607ac485SJiaxin Yu },
1335607ac485SJiaxin Yu };
1336607ac485SJiaxin Yu
mt8192_dai_adda_register(struct mtk_base_afe * afe)1337607ac485SJiaxin Yu int mt8192_dai_adda_register(struct mtk_base_afe *afe)
1338607ac485SJiaxin Yu {
1339607ac485SJiaxin Yu struct mtk_base_afe_dai *dai;
1340607ac485SJiaxin Yu struct mt8192_afe_private *afe_priv = afe->platform_priv;
1341607ac485SJiaxin Yu
1342607ac485SJiaxin Yu dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL);
1343607ac485SJiaxin Yu if (!dai)
1344607ac485SJiaxin Yu return -ENOMEM;
1345607ac485SJiaxin Yu
1346607ac485SJiaxin Yu list_add(&dai->list, &afe->sub_dais);
1347607ac485SJiaxin Yu
1348607ac485SJiaxin Yu dai->dai_drivers = mtk_dai_adda_driver;
1349607ac485SJiaxin Yu dai->num_dai_drivers = ARRAY_SIZE(mtk_dai_adda_driver);
1350607ac485SJiaxin Yu
1351607ac485SJiaxin Yu dai->controls = mtk_adda_controls;
1352607ac485SJiaxin Yu dai->num_controls = ARRAY_SIZE(mtk_adda_controls);
1353607ac485SJiaxin Yu dai->dapm_widgets = mtk_dai_adda_widgets;
1354607ac485SJiaxin Yu dai->num_dapm_widgets = ARRAY_SIZE(mtk_dai_adda_widgets);
1355607ac485SJiaxin Yu dai->dapm_routes = mtk_dai_adda_routes;
1356607ac485SJiaxin Yu dai->num_dapm_routes = ARRAY_SIZE(mtk_dai_adda_routes);
1357607ac485SJiaxin Yu
1358607ac485SJiaxin Yu /* ap dmic priv share with adda */
1359607ac485SJiaxin Yu afe_priv->dai_priv[MT8192_DAI_AP_DMIC] =
1360607ac485SJiaxin Yu afe_priv->dai_priv[MT8192_DAI_ADDA];
1361607ac485SJiaxin Yu afe_priv->dai_priv[MT8192_DAI_AP_DMIC_CH34] =
1362607ac485SJiaxin Yu afe_priv->dai_priv[MT8192_DAI_ADDA_CH34];
1363607ac485SJiaxin Yu
1364607ac485SJiaxin Yu return 0;
1365607ac485SJiaxin Yu }
1366