1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
3
4 #include <linux/module.h>
5 #include <linux/init.h>
6 #include <linux/clk.h>
7 #include <linux/io.h>
8 #include <linux/platform_device.h>
9 #include <linux/pm_runtime.h>
10 #include <linux/regmap.h>
11 #include <sound/soc.h>
12 #include <sound/soc-dapm.h>
13 #include <sound/tlv.h>
14 #include <linux/of_clk.h>
15 #include <linux/clk-provider.h>
16
17 #include "lpass-macro-common.h"
18
19 #define CDC_TX_CLK_RST_CTRL_MCLK_CONTROL (0x0000)
20 #define CDC_TX_MCLK_EN_MASK BIT(0)
21 #define CDC_TX_MCLK_ENABLE BIT(0)
22 #define CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL (0x0004)
23 #define CDC_TX_FS_CNT_EN_MASK BIT(0)
24 #define CDC_TX_FS_CNT_ENABLE BIT(0)
25 #define CDC_TX_CLK_RST_CTRL_SWR_CONTROL (0x0008)
26 #define CDC_TX_SWR_RESET_MASK BIT(1)
27 #define CDC_TX_SWR_RESET_ENABLE BIT(1)
28 #define CDC_TX_SWR_CLK_EN_MASK BIT(0)
29 #define CDC_TX_SWR_CLK_ENABLE BIT(0)
30 #define CDC_TX_TOP_CSR_TOP_CFG0 (0x0080)
31 #define CDC_TX_TOP_CSR_ANC_CFG (0x0084)
32 #define CDC_TX_TOP_CSR_SWR_CTRL (0x0088)
33 #define CDC_TX_TOP_CSR_FREQ_MCLK (0x0090)
34 #define CDC_TX_TOP_CSR_DEBUG_BUS (0x0094)
35 #define CDC_TX_TOP_CSR_DEBUG_EN (0x0098)
36 #define CDC_TX_TOP_CSR_TX_I2S_CTL (0x00A4)
37 #define CDC_TX_TOP_CSR_I2S_CLK (0x00A8)
38 #define CDC_TX_TOP_CSR_I2S_RESET (0x00AC)
39 #define CDC_TX_TOP_CSR_SWR_DMICn_CTL(n) (0x00C0 + n * 0x4)
40 #define CDC_TX_TOP_CSR_SWR_DMIC0_CTL (0x00C0)
41 #define CDC_TX_SWR_DMIC_CLK_SEL_MASK GENMASK(3, 1)
42 #define CDC_TX_TOP_CSR_SWR_DMIC1_CTL (0x00C4)
43 #define CDC_TX_TOP_CSR_SWR_DMIC2_CTL (0x00C8)
44 #define CDC_TX_TOP_CSR_SWR_DMIC3_CTL (0x00CC)
45 #define CDC_TX_TOP_CSR_SWR_AMIC0_CTL (0x00D0)
46 #define CDC_TX_TOP_CSR_SWR_AMIC1_CTL (0x00D4)
47 #define CDC_TX_INP_MUX_ADC_MUXn_CFG0(n) (0x0100 + 0x8 * n)
48 #define CDC_TX_MACRO_SWR_MIC_MUX_SEL_MASK GENMASK(3, 0)
49 #define CDC_TX_INP_MUX_ADC_MUX0_CFG0 (0x0100)
50 #define CDC_TX_INP_MUX_ADC_MUXn_CFG1(n) (0x0104 + 0x8 * n)
51 #define CDC_TX_INP_MUX_ADC_MUX0_CFG1 (0x0104)
52 #define CDC_TX_INP_MUX_ADC_MUX1_CFG0 (0x0108)
53 #define CDC_TX_INP_MUX_ADC_MUX1_CFG1 (0x010C)
54 #define CDC_TX_INP_MUX_ADC_MUX2_CFG0 (0x0110)
55 #define CDC_TX_INP_MUX_ADC_MUX2_CFG1 (0x0114)
56 #define CDC_TX_INP_MUX_ADC_MUX3_CFG0 (0x0118)
57 #define CDC_TX_INP_MUX_ADC_MUX3_CFG1 (0x011C)
58 #define CDC_TX_INP_MUX_ADC_MUX4_CFG0 (0x0120)
59 #define CDC_TX_INP_MUX_ADC_MUX4_CFG1 (0x0124)
60 #define CDC_TX_INP_MUX_ADC_MUX5_CFG0 (0x0128)
61 #define CDC_TX_INP_MUX_ADC_MUX5_CFG1 (0x012C)
62 #define CDC_TX_INP_MUX_ADC_MUX6_CFG0 (0x0130)
63 #define CDC_TX_INP_MUX_ADC_MUX6_CFG1 (0x0134)
64 #define CDC_TX_INP_MUX_ADC_MUX7_CFG0 (0x0138)
65 #define CDC_TX_INP_MUX_ADC_MUX7_CFG1 (0x013C)
66 #define CDC_TX_ANC0_CLK_RESET_CTL (0x0200)
67 #define CDC_TX_ANC0_MODE_1_CTL (0x0204)
68 #define CDC_TX_ANC0_MODE_2_CTL (0x0208)
69 #define CDC_TX_ANC0_FF_SHIFT (0x020C)
70 #define CDC_TX_ANC0_FB_SHIFT (0x0210)
71 #define CDC_TX_ANC0_LPF_FF_A_CTL (0x0214)
72 #define CDC_TX_ANC0_LPF_FF_B_CTL (0x0218)
73 #define CDC_TX_ANC0_LPF_FB_CTL (0x021C)
74 #define CDC_TX_ANC0_SMLPF_CTL (0x0220)
75 #define CDC_TX_ANC0_DCFLT_SHIFT_CTL (0x0224)
76 #define CDC_TX_ANC0_IIR_ADAPT_CTL (0x0228)
77 #define CDC_TX_ANC0_IIR_COEFF_1_CTL (0x022C)
78 #define CDC_TX_ANC0_IIR_COEFF_2_CTL (0x0230)
79 #define CDC_TX_ANC0_FF_A_GAIN_CTL (0x0234)
80 #define CDC_TX_ANC0_FF_B_GAIN_CTL (0x0238)
81 #define CDC_TX_ANC0_FB_GAIN_CTL (0x023C)
82 #define CDC_TXn_TX_PATH_CTL(n) (0x0400 + 0x80 * n)
83 #define CDC_TXn_PCM_RATE_MASK GENMASK(3, 0)
84 #define CDC_TXn_PGA_MUTE_MASK BIT(4)
85 #define CDC_TXn_CLK_EN_MASK BIT(5)
86 #define CDC_TX0_TX_PATH_CTL (0x0400)
87 #define CDC_TXn_TX_PATH_CFG0(n) (0x0404 + 0x80 * n)
88 #define CDC_TX0_TX_PATH_CFG0 (0x0404)
89 #define CDC_TXn_PH_EN_MASK BIT(0)
90 #define CDC_TXn_ADC_MODE_MASK GENMASK(2, 1)
91 #define CDC_TXn_HPF_CUT_FREQ_MASK GENMASK(6, 5)
92 #define CDC_TXn_ADC_DMIC_SEL_MASK BIT(7)
93 #define CDC_TX0_TX_PATH_CFG1 (0x0408)
94 #define CDC_TXn_TX_VOL_CTL(n) (0x040C + 0x80 * n)
95 #define CDC_TX0_TX_VOL_CTL (0x040C)
96 #define CDC_TX0_TX_PATH_SEC0 (0x0410)
97 #define CDC_TX0_TX_PATH_SEC1 (0x0414)
98 #define CDC_TXn_TX_PATH_SEC2(n) (0x0418 + 0x80 * n)
99 #define CDC_TXn_HPF_F_CHANGE_MASK BIT(1)
100 #define CDC_TXn_HPF_ZERO_GATE_MASK BIT(0)
101 #define CDC_TX0_TX_PATH_SEC2 (0x0418)
102 #define CDC_TX0_TX_PATH_SEC3 (0x041C)
103 #define CDC_TX0_TX_PATH_SEC4 (0x0420)
104 #define CDC_TX0_TX_PATH_SEC5 (0x0424)
105 #define CDC_TX0_TX_PATH_SEC6 (0x0428)
106 #define CDC_TX0_TX_PATH_SEC7 (0x042C)
107 #define CDC_TX0_MBHC_CTL_EN_MASK BIT(6)
108 #define CDC_TX1_TX_PATH_CTL (0x0480)
109 #define CDC_TX1_TX_PATH_CFG0 (0x0484)
110 #define CDC_TX1_TX_PATH_CFG1 (0x0488)
111 #define CDC_TX1_TX_VOL_CTL (0x048C)
112 #define CDC_TX1_TX_PATH_SEC0 (0x0490)
113 #define CDC_TX1_TX_PATH_SEC1 (0x0494)
114 #define CDC_TX1_TX_PATH_SEC2 (0x0498)
115 #define CDC_TX1_TX_PATH_SEC3 (0x049C)
116 #define CDC_TX1_TX_PATH_SEC4 (0x04A0)
117 #define CDC_TX1_TX_PATH_SEC5 (0x04A4)
118 #define CDC_TX1_TX_PATH_SEC6 (0x04A8)
119 #define CDC_TX2_TX_PATH_CTL (0x0500)
120 #define CDC_TX2_TX_PATH_CFG0 (0x0504)
121 #define CDC_TX2_TX_PATH_CFG1 (0x0508)
122 #define CDC_TX2_TX_VOL_CTL (0x050C)
123 #define CDC_TX2_TX_PATH_SEC0 (0x0510)
124 #define CDC_TX2_TX_PATH_SEC1 (0x0514)
125 #define CDC_TX2_TX_PATH_SEC2 (0x0518)
126 #define CDC_TX2_TX_PATH_SEC3 (0x051C)
127 #define CDC_TX2_TX_PATH_SEC4 (0x0520)
128 #define CDC_TX2_TX_PATH_SEC5 (0x0524)
129 #define CDC_TX2_TX_PATH_SEC6 (0x0528)
130 #define CDC_TX3_TX_PATH_CTL (0x0580)
131 #define CDC_TX3_TX_PATH_CFG0 (0x0584)
132 #define CDC_TX3_TX_PATH_CFG1 (0x0588)
133 #define CDC_TX3_TX_VOL_CTL (0x058C)
134 #define CDC_TX3_TX_PATH_SEC0 (0x0590)
135 #define CDC_TX3_TX_PATH_SEC1 (0x0594)
136 #define CDC_TX3_TX_PATH_SEC2 (0x0598)
137 #define CDC_TX3_TX_PATH_SEC3 (0x059C)
138 #define CDC_TX3_TX_PATH_SEC4 (0x05A0)
139 #define CDC_TX3_TX_PATH_SEC5 (0x05A4)
140 #define CDC_TX3_TX_PATH_SEC6 (0x05A8)
141 #define CDC_TX4_TX_PATH_CTL (0x0600)
142 #define CDC_TX4_TX_PATH_CFG0 (0x0604)
143 #define CDC_TX4_TX_PATH_CFG1 (0x0608)
144 #define CDC_TX4_TX_VOL_CTL (0x060C)
145 #define CDC_TX4_TX_PATH_SEC0 (0x0610)
146 #define CDC_TX4_TX_PATH_SEC1 (0x0614)
147 #define CDC_TX4_TX_PATH_SEC2 (0x0618)
148 #define CDC_TX4_TX_PATH_SEC3 (0x061C)
149 #define CDC_TX4_TX_PATH_SEC4 (0x0620)
150 #define CDC_TX4_TX_PATH_SEC5 (0x0624)
151 #define CDC_TX4_TX_PATH_SEC6 (0x0628)
152 #define CDC_TX5_TX_PATH_CTL (0x0680)
153 #define CDC_TX5_TX_PATH_CFG0 (0x0684)
154 #define CDC_TX5_TX_PATH_CFG1 (0x0688)
155 #define CDC_TX5_TX_VOL_CTL (0x068C)
156 #define CDC_TX5_TX_PATH_SEC0 (0x0690)
157 #define CDC_TX5_TX_PATH_SEC1 (0x0694)
158 #define CDC_TX5_TX_PATH_SEC2 (0x0698)
159 #define CDC_TX5_TX_PATH_SEC3 (0x069C)
160 #define CDC_TX5_TX_PATH_SEC4 (0x06A0)
161 #define CDC_TX5_TX_PATH_SEC5 (0x06A4)
162 #define CDC_TX5_TX_PATH_SEC6 (0x06A8)
163 #define CDC_TX6_TX_PATH_CTL (0x0700)
164 #define CDC_TX6_TX_PATH_CFG0 (0x0704)
165 #define CDC_TX6_TX_PATH_CFG1 (0x0708)
166 #define CDC_TX6_TX_VOL_CTL (0x070C)
167 #define CDC_TX6_TX_PATH_SEC0 (0x0710)
168 #define CDC_TX6_TX_PATH_SEC1 (0x0714)
169 #define CDC_TX6_TX_PATH_SEC2 (0x0718)
170 #define CDC_TX6_TX_PATH_SEC3 (0x071C)
171 #define CDC_TX6_TX_PATH_SEC4 (0x0720)
172 #define CDC_TX6_TX_PATH_SEC5 (0x0724)
173 #define CDC_TX6_TX_PATH_SEC6 (0x0728)
174 #define CDC_TX7_TX_PATH_CTL (0x0780)
175 #define CDC_TX7_TX_PATH_CFG0 (0x0784)
176 #define CDC_TX7_TX_PATH_CFG1 (0x0788)
177 #define CDC_TX7_TX_VOL_CTL (0x078C)
178 #define CDC_TX7_TX_PATH_SEC0 (0x0790)
179 #define CDC_TX7_TX_PATH_SEC1 (0x0794)
180 #define CDC_TX7_TX_PATH_SEC2 (0x0798)
181 #define CDC_TX7_TX_PATH_SEC3 (0x079C)
182 #define CDC_TX7_TX_PATH_SEC4 (0x07A0)
183 #define CDC_TX7_TX_PATH_SEC5 (0x07A4)
184 #define CDC_TX7_TX_PATH_SEC6 (0x07A8)
185 #define TX_MAX_OFFSET (0x07A8)
186
187 #define TX_MACRO_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
188 SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\
189 SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000)
190 #define TX_MACRO_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
191 SNDRV_PCM_FMTBIT_S24_LE |\
192 SNDRV_PCM_FMTBIT_S24_3LE)
193
194 #define CF_MIN_3DB_4HZ 0x0
195 #define CF_MIN_3DB_75HZ 0x1
196 #define CF_MIN_3DB_150HZ 0x2
197 #define TX_ADC_MAX 5
198 #define TX_ADC_TO_DMIC(n) ((n - TX_ADC_MAX)/2)
199 #define NUM_DECIMATORS 8
200 #define TX_NUM_CLKS_MAX 5
201 #define TX_MACRO_DMIC_UNMUTE_DELAY_MS 40
202 #define TX_MACRO_AMIC_UNMUTE_DELAY_MS 100
203 #define TX_MACRO_DMIC_HPF_DELAY_MS 300
204 #define TX_MACRO_AMIC_HPF_DELAY_MS 300
205 #define MCLK_FREQ 19200000
206
207 enum {
208 TX_MACRO_AIF_INVALID = 0,
209 TX_MACRO_AIF1_CAP,
210 TX_MACRO_AIF2_CAP,
211 TX_MACRO_AIF3_CAP,
212 TX_MACRO_MAX_DAIS
213 };
214
215 enum {
216 TX_MACRO_DEC0,
217 TX_MACRO_DEC1,
218 TX_MACRO_DEC2,
219 TX_MACRO_DEC3,
220 TX_MACRO_DEC4,
221 TX_MACRO_DEC5,
222 TX_MACRO_DEC6,
223 TX_MACRO_DEC7,
224 TX_MACRO_DEC_MAX,
225 };
226
227 enum {
228 TX_MACRO_CLK_DIV_2,
229 TX_MACRO_CLK_DIV_3,
230 TX_MACRO_CLK_DIV_4,
231 TX_MACRO_CLK_DIV_6,
232 TX_MACRO_CLK_DIV_8,
233 TX_MACRO_CLK_DIV_16,
234 };
235
236 enum {
237 MSM_DMIC,
238 SWR_MIC,
239 ANC_FB_TUNE1
240 };
241
242 struct tx_mute_work {
243 struct tx_macro *tx;
244 u8 decimator;
245 struct delayed_work dwork;
246 };
247
248 struct hpf_work {
249 struct tx_macro *tx;
250 u8 decimator;
251 u8 hpf_cut_off_freq;
252 struct delayed_work dwork;
253 };
254
255 struct tx_macro {
256 struct device *dev;
257 struct snd_soc_component *component;
258 struct hpf_work tx_hpf_work[NUM_DECIMATORS];
259 struct tx_mute_work tx_mute_dwork[NUM_DECIMATORS];
260 unsigned long active_ch_mask[TX_MACRO_MAX_DAIS];
261 unsigned long active_ch_cnt[TX_MACRO_MAX_DAIS];
262 int active_decimator[TX_MACRO_MAX_DAIS];
263 struct regmap *regmap;
264 struct clk *mclk;
265 struct clk *npl;
266 struct clk *macro;
267 struct clk *dcodec;
268 struct clk *fsgen;
269 struct clk_hw hw;
270 bool dec_active[NUM_DECIMATORS];
271 int tx_mclk_users;
272 u16 dmic_clk_div;
273 bool bcs_enable;
274 int dec_mode[NUM_DECIMATORS];
275 struct lpass_macro *pds;
276 bool bcs_clk_en;
277 };
278 #define to_tx_macro(_hw) container_of(_hw, struct tx_macro, hw)
279
280 static const DECLARE_TLV_DB_SCALE(digital_gain, -8400, 100, -8400);
281
282 static struct reg_default tx_defaults[] = {
283 /* TX Macro */
284 { CDC_TX_CLK_RST_CTRL_MCLK_CONTROL, 0x00 },
285 { CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL, 0x00 },
286 { CDC_TX_CLK_RST_CTRL_SWR_CONTROL, 0x00},
287 { CDC_TX_TOP_CSR_TOP_CFG0, 0x00},
288 { CDC_TX_TOP_CSR_ANC_CFG, 0x00},
289 { CDC_TX_TOP_CSR_SWR_CTRL, 0x00},
290 { CDC_TX_TOP_CSR_FREQ_MCLK, 0x00},
291 { CDC_TX_TOP_CSR_DEBUG_BUS, 0x00},
292 { CDC_TX_TOP_CSR_DEBUG_EN, 0x00},
293 { CDC_TX_TOP_CSR_TX_I2S_CTL, 0x0C},
294 { CDC_TX_TOP_CSR_I2S_CLK, 0x00},
295 { CDC_TX_TOP_CSR_I2S_RESET, 0x00},
296 { CDC_TX_TOP_CSR_SWR_DMIC0_CTL, 0x00},
297 { CDC_TX_TOP_CSR_SWR_DMIC1_CTL, 0x00},
298 { CDC_TX_TOP_CSR_SWR_DMIC2_CTL, 0x00},
299 { CDC_TX_TOP_CSR_SWR_DMIC3_CTL, 0x00},
300 { CDC_TX_TOP_CSR_SWR_AMIC0_CTL, 0x00},
301 { CDC_TX_TOP_CSR_SWR_AMIC1_CTL, 0x00},
302 { CDC_TX_INP_MUX_ADC_MUX0_CFG0, 0x00},
303 { CDC_TX_INP_MUX_ADC_MUX0_CFG1, 0x00},
304 { CDC_TX_INP_MUX_ADC_MUX1_CFG0, 0x00},
305 { CDC_TX_INP_MUX_ADC_MUX1_CFG1, 0x00},
306 { CDC_TX_INP_MUX_ADC_MUX2_CFG0, 0x00},
307 { CDC_TX_INP_MUX_ADC_MUX2_CFG1, 0x00},
308 { CDC_TX_INP_MUX_ADC_MUX3_CFG0, 0x00},
309 { CDC_TX_INP_MUX_ADC_MUX3_CFG1, 0x00},
310 { CDC_TX_INP_MUX_ADC_MUX4_CFG0, 0x00},
311 { CDC_TX_INP_MUX_ADC_MUX4_CFG1, 0x00},
312 { CDC_TX_INP_MUX_ADC_MUX5_CFG0, 0x00},
313 { CDC_TX_INP_MUX_ADC_MUX5_CFG1, 0x00},
314 { CDC_TX_INP_MUX_ADC_MUX6_CFG0, 0x00},
315 { CDC_TX_INP_MUX_ADC_MUX6_CFG1, 0x00},
316 { CDC_TX_INP_MUX_ADC_MUX7_CFG0, 0x00},
317 { CDC_TX_INP_MUX_ADC_MUX7_CFG1, 0x00},
318 { CDC_TX_ANC0_CLK_RESET_CTL, 0x00},
319 { CDC_TX_ANC0_MODE_1_CTL, 0x00},
320 { CDC_TX_ANC0_MODE_2_CTL, 0x00},
321 { CDC_TX_ANC0_FF_SHIFT, 0x00},
322 { CDC_TX_ANC0_FB_SHIFT, 0x00},
323 { CDC_TX_ANC0_LPF_FF_A_CTL, 0x00},
324 { CDC_TX_ANC0_LPF_FF_B_CTL, 0x00},
325 { CDC_TX_ANC0_LPF_FB_CTL, 0x00},
326 { CDC_TX_ANC0_SMLPF_CTL, 0x00},
327 { CDC_TX_ANC0_DCFLT_SHIFT_CTL, 0x00},
328 { CDC_TX_ANC0_IIR_ADAPT_CTL, 0x00},
329 { CDC_TX_ANC0_IIR_COEFF_1_CTL, 0x00},
330 { CDC_TX_ANC0_IIR_COEFF_2_CTL, 0x00},
331 { CDC_TX_ANC0_FF_A_GAIN_CTL, 0x00},
332 { CDC_TX_ANC0_FF_B_GAIN_CTL, 0x00},
333 { CDC_TX_ANC0_FB_GAIN_CTL, 0x00},
334 { CDC_TX0_TX_PATH_CTL, 0x04},
335 { CDC_TX0_TX_PATH_CFG0, 0x10},
336 { CDC_TX0_TX_PATH_CFG1, 0x0B},
337 { CDC_TX0_TX_VOL_CTL, 0x00},
338 { CDC_TX0_TX_PATH_SEC0, 0x00},
339 { CDC_TX0_TX_PATH_SEC1, 0x00},
340 { CDC_TX0_TX_PATH_SEC2, 0x01},
341 { CDC_TX0_TX_PATH_SEC3, 0x3C},
342 { CDC_TX0_TX_PATH_SEC4, 0x20},
343 { CDC_TX0_TX_PATH_SEC5, 0x00},
344 { CDC_TX0_TX_PATH_SEC6, 0x00},
345 { CDC_TX0_TX_PATH_SEC7, 0x25},
346 { CDC_TX1_TX_PATH_CTL, 0x04},
347 { CDC_TX1_TX_PATH_CFG0, 0x10},
348 { CDC_TX1_TX_PATH_CFG1, 0x0B},
349 { CDC_TX1_TX_VOL_CTL, 0x00},
350 { CDC_TX1_TX_PATH_SEC0, 0x00},
351 { CDC_TX1_TX_PATH_SEC1, 0x00},
352 { CDC_TX1_TX_PATH_SEC2, 0x01},
353 { CDC_TX1_TX_PATH_SEC3, 0x3C},
354 { CDC_TX1_TX_PATH_SEC4, 0x20},
355 { CDC_TX1_TX_PATH_SEC5, 0x00},
356 { CDC_TX1_TX_PATH_SEC6, 0x00},
357 { CDC_TX2_TX_PATH_CTL, 0x04},
358 { CDC_TX2_TX_PATH_CFG0, 0x10},
359 { CDC_TX2_TX_PATH_CFG1, 0x0B},
360 { CDC_TX2_TX_VOL_CTL, 0x00},
361 { CDC_TX2_TX_PATH_SEC0, 0x00},
362 { CDC_TX2_TX_PATH_SEC1, 0x00},
363 { CDC_TX2_TX_PATH_SEC2, 0x01},
364 { CDC_TX2_TX_PATH_SEC3, 0x3C},
365 { CDC_TX2_TX_PATH_SEC4, 0x20},
366 { CDC_TX2_TX_PATH_SEC5, 0x00},
367 { CDC_TX2_TX_PATH_SEC6, 0x00},
368 { CDC_TX3_TX_PATH_CTL, 0x04},
369 { CDC_TX3_TX_PATH_CFG0, 0x10},
370 { CDC_TX3_TX_PATH_CFG1, 0x0B},
371 { CDC_TX3_TX_VOL_CTL, 0x00},
372 { CDC_TX3_TX_PATH_SEC0, 0x00},
373 { CDC_TX3_TX_PATH_SEC1, 0x00},
374 { CDC_TX3_TX_PATH_SEC2, 0x01},
375 { CDC_TX3_TX_PATH_SEC3, 0x3C},
376 { CDC_TX3_TX_PATH_SEC4, 0x20},
377 { CDC_TX3_TX_PATH_SEC5, 0x00},
378 { CDC_TX3_TX_PATH_SEC6, 0x00},
379 { CDC_TX4_TX_PATH_CTL, 0x04},
380 { CDC_TX4_TX_PATH_CFG0, 0x10},
381 { CDC_TX4_TX_PATH_CFG1, 0x0B},
382 { CDC_TX4_TX_VOL_CTL, 0x00},
383 { CDC_TX4_TX_PATH_SEC0, 0x00},
384 { CDC_TX4_TX_PATH_SEC1, 0x00},
385 { CDC_TX4_TX_PATH_SEC2, 0x01},
386 { CDC_TX4_TX_PATH_SEC3, 0x3C},
387 { CDC_TX4_TX_PATH_SEC4, 0x20},
388 { CDC_TX4_TX_PATH_SEC5, 0x00},
389 { CDC_TX4_TX_PATH_SEC6, 0x00},
390 { CDC_TX5_TX_PATH_CTL, 0x04},
391 { CDC_TX5_TX_PATH_CFG0, 0x10},
392 { CDC_TX5_TX_PATH_CFG1, 0x0B},
393 { CDC_TX5_TX_VOL_CTL, 0x00},
394 { CDC_TX5_TX_PATH_SEC0, 0x00},
395 { CDC_TX5_TX_PATH_SEC1, 0x00},
396 { CDC_TX5_TX_PATH_SEC2, 0x01},
397 { CDC_TX5_TX_PATH_SEC3, 0x3C},
398 { CDC_TX5_TX_PATH_SEC4, 0x20},
399 { CDC_TX5_TX_PATH_SEC5, 0x00},
400 { CDC_TX5_TX_PATH_SEC6, 0x00},
401 { CDC_TX6_TX_PATH_CTL, 0x04},
402 { CDC_TX6_TX_PATH_CFG0, 0x10},
403 { CDC_TX6_TX_PATH_CFG1, 0x0B},
404 { CDC_TX6_TX_VOL_CTL, 0x00},
405 { CDC_TX6_TX_PATH_SEC0, 0x00},
406 { CDC_TX6_TX_PATH_SEC1, 0x00},
407 { CDC_TX6_TX_PATH_SEC2, 0x01},
408 { CDC_TX6_TX_PATH_SEC3, 0x3C},
409 { CDC_TX6_TX_PATH_SEC4, 0x20},
410 { CDC_TX6_TX_PATH_SEC5, 0x00},
411 { CDC_TX6_TX_PATH_SEC6, 0x00},
412 { CDC_TX7_TX_PATH_CTL, 0x04},
413 { CDC_TX7_TX_PATH_CFG0, 0x10},
414 { CDC_TX7_TX_PATH_CFG1, 0x0B},
415 { CDC_TX7_TX_VOL_CTL, 0x00},
416 { CDC_TX7_TX_PATH_SEC0, 0x00},
417 { CDC_TX7_TX_PATH_SEC1, 0x00},
418 { CDC_TX7_TX_PATH_SEC2, 0x01},
419 { CDC_TX7_TX_PATH_SEC3, 0x3C},
420 { CDC_TX7_TX_PATH_SEC4, 0x20},
421 { CDC_TX7_TX_PATH_SEC5, 0x00},
422 { CDC_TX7_TX_PATH_SEC6, 0x00},
423 };
424
tx_is_volatile_register(struct device * dev,unsigned int reg)425 static bool tx_is_volatile_register(struct device *dev, unsigned int reg)
426 {
427 /* Update volatile list for tx/tx macros */
428 switch (reg) {
429 case CDC_TX_TOP_CSR_SWR_DMIC0_CTL:
430 case CDC_TX_TOP_CSR_SWR_DMIC1_CTL:
431 case CDC_TX_TOP_CSR_SWR_DMIC2_CTL:
432 case CDC_TX_TOP_CSR_SWR_DMIC3_CTL:
433 return true;
434 }
435 return false;
436 }
437
tx_is_rw_register(struct device * dev,unsigned int reg)438 static bool tx_is_rw_register(struct device *dev, unsigned int reg)
439 {
440 switch (reg) {
441 case CDC_TX_CLK_RST_CTRL_MCLK_CONTROL:
442 case CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL:
443 case CDC_TX_CLK_RST_CTRL_SWR_CONTROL:
444 case CDC_TX_TOP_CSR_TOP_CFG0:
445 case CDC_TX_TOP_CSR_ANC_CFG:
446 case CDC_TX_TOP_CSR_SWR_CTRL:
447 case CDC_TX_TOP_CSR_FREQ_MCLK:
448 case CDC_TX_TOP_CSR_DEBUG_BUS:
449 case CDC_TX_TOP_CSR_DEBUG_EN:
450 case CDC_TX_TOP_CSR_TX_I2S_CTL:
451 case CDC_TX_TOP_CSR_I2S_CLK:
452 case CDC_TX_TOP_CSR_I2S_RESET:
453 case CDC_TX_TOP_CSR_SWR_DMIC0_CTL:
454 case CDC_TX_TOP_CSR_SWR_DMIC1_CTL:
455 case CDC_TX_TOP_CSR_SWR_DMIC2_CTL:
456 case CDC_TX_TOP_CSR_SWR_DMIC3_CTL:
457 case CDC_TX_TOP_CSR_SWR_AMIC0_CTL:
458 case CDC_TX_TOP_CSR_SWR_AMIC1_CTL:
459 case CDC_TX_ANC0_CLK_RESET_CTL:
460 case CDC_TX_ANC0_MODE_1_CTL:
461 case CDC_TX_ANC0_MODE_2_CTL:
462 case CDC_TX_ANC0_FF_SHIFT:
463 case CDC_TX_ANC0_FB_SHIFT:
464 case CDC_TX_ANC0_LPF_FF_A_CTL:
465 case CDC_TX_ANC0_LPF_FF_B_CTL:
466 case CDC_TX_ANC0_LPF_FB_CTL:
467 case CDC_TX_ANC0_SMLPF_CTL:
468 case CDC_TX_ANC0_DCFLT_SHIFT_CTL:
469 case CDC_TX_ANC0_IIR_ADAPT_CTL:
470 case CDC_TX_ANC0_IIR_COEFF_1_CTL:
471 case CDC_TX_ANC0_IIR_COEFF_2_CTL:
472 case CDC_TX_ANC0_FF_A_GAIN_CTL:
473 case CDC_TX_ANC0_FF_B_GAIN_CTL:
474 case CDC_TX_ANC0_FB_GAIN_CTL:
475 case CDC_TX_INP_MUX_ADC_MUX0_CFG0:
476 case CDC_TX_INP_MUX_ADC_MUX0_CFG1:
477 case CDC_TX_INP_MUX_ADC_MUX1_CFG0:
478 case CDC_TX_INP_MUX_ADC_MUX1_CFG1:
479 case CDC_TX_INP_MUX_ADC_MUX2_CFG0:
480 case CDC_TX_INP_MUX_ADC_MUX2_CFG1:
481 case CDC_TX_INP_MUX_ADC_MUX3_CFG0:
482 case CDC_TX_INP_MUX_ADC_MUX3_CFG1:
483 case CDC_TX_INP_MUX_ADC_MUX4_CFG0:
484 case CDC_TX_INP_MUX_ADC_MUX4_CFG1:
485 case CDC_TX_INP_MUX_ADC_MUX5_CFG0:
486 case CDC_TX_INP_MUX_ADC_MUX5_CFG1:
487 case CDC_TX_INP_MUX_ADC_MUX6_CFG0:
488 case CDC_TX_INP_MUX_ADC_MUX6_CFG1:
489 case CDC_TX_INP_MUX_ADC_MUX7_CFG0:
490 case CDC_TX_INP_MUX_ADC_MUX7_CFG1:
491 case CDC_TX0_TX_PATH_CTL:
492 case CDC_TX0_TX_PATH_CFG0:
493 case CDC_TX0_TX_PATH_CFG1:
494 case CDC_TX0_TX_VOL_CTL:
495 case CDC_TX0_TX_PATH_SEC0:
496 case CDC_TX0_TX_PATH_SEC1:
497 case CDC_TX0_TX_PATH_SEC2:
498 case CDC_TX0_TX_PATH_SEC3:
499 case CDC_TX0_TX_PATH_SEC4:
500 case CDC_TX0_TX_PATH_SEC5:
501 case CDC_TX0_TX_PATH_SEC6:
502 case CDC_TX0_TX_PATH_SEC7:
503 case CDC_TX1_TX_PATH_CTL:
504 case CDC_TX1_TX_PATH_CFG0:
505 case CDC_TX1_TX_PATH_CFG1:
506 case CDC_TX1_TX_VOL_CTL:
507 case CDC_TX1_TX_PATH_SEC0:
508 case CDC_TX1_TX_PATH_SEC1:
509 case CDC_TX1_TX_PATH_SEC2:
510 case CDC_TX1_TX_PATH_SEC3:
511 case CDC_TX1_TX_PATH_SEC4:
512 case CDC_TX1_TX_PATH_SEC5:
513 case CDC_TX1_TX_PATH_SEC6:
514 case CDC_TX2_TX_PATH_CTL:
515 case CDC_TX2_TX_PATH_CFG0:
516 case CDC_TX2_TX_PATH_CFG1:
517 case CDC_TX2_TX_VOL_CTL:
518 case CDC_TX2_TX_PATH_SEC0:
519 case CDC_TX2_TX_PATH_SEC1:
520 case CDC_TX2_TX_PATH_SEC2:
521 case CDC_TX2_TX_PATH_SEC3:
522 case CDC_TX2_TX_PATH_SEC4:
523 case CDC_TX2_TX_PATH_SEC5:
524 case CDC_TX2_TX_PATH_SEC6:
525 case CDC_TX3_TX_PATH_CTL:
526 case CDC_TX3_TX_PATH_CFG0:
527 case CDC_TX3_TX_PATH_CFG1:
528 case CDC_TX3_TX_VOL_CTL:
529 case CDC_TX3_TX_PATH_SEC0:
530 case CDC_TX3_TX_PATH_SEC1:
531 case CDC_TX3_TX_PATH_SEC2:
532 case CDC_TX3_TX_PATH_SEC3:
533 case CDC_TX3_TX_PATH_SEC4:
534 case CDC_TX3_TX_PATH_SEC5:
535 case CDC_TX3_TX_PATH_SEC6:
536 case CDC_TX4_TX_PATH_CTL:
537 case CDC_TX4_TX_PATH_CFG0:
538 case CDC_TX4_TX_PATH_CFG1:
539 case CDC_TX4_TX_VOL_CTL:
540 case CDC_TX4_TX_PATH_SEC0:
541 case CDC_TX4_TX_PATH_SEC1:
542 case CDC_TX4_TX_PATH_SEC2:
543 case CDC_TX4_TX_PATH_SEC3:
544 case CDC_TX4_TX_PATH_SEC4:
545 case CDC_TX4_TX_PATH_SEC5:
546 case CDC_TX4_TX_PATH_SEC6:
547 case CDC_TX5_TX_PATH_CTL:
548 case CDC_TX5_TX_PATH_CFG0:
549 case CDC_TX5_TX_PATH_CFG1:
550 case CDC_TX5_TX_VOL_CTL:
551 case CDC_TX5_TX_PATH_SEC0:
552 case CDC_TX5_TX_PATH_SEC1:
553 case CDC_TX5_TX_PATH_SEC2:
554 case CDC_TX5_TX_PATH_SEC3:
555 case CDC_TX5_TX_PATH_SEC4:
556 case CDC_TX5_TX_PATH_SEC5:
557 case CDC_TX5_TX_PATH_SEC6:
558 case CDC_TX6_TX_PATH_CTL:
559 case CDC_TX6_TX_PATH_CFG0:
560 case CDC_TX6_TX_PATH_CFG1:
561 case CDC_TX6_TX_VOL_CTL:
562 case CDC_TX6_TX_PATH_SEC0:
563 case CDC_TX6_TX_PATH_SEC1:
564 case CDC_TX6_TX_PATH_SEC2:
565 case CDC_TX6_TX_PATH_SEC3:
566 case CDC_TX6_TX_PATH_SEC4:
567 case CDC_TX6_TX_PATH_SEC5:
568 case CDC_TX6_TX_PATH_SEC6:
569 case CDC_TX7_TX_PATH_CTL:
570 case CDC_TX7_TX_PATH_CFG0:
571 case CDC_TX7_TX_PATH_CFG1:
572 case CDC_TX7_TX_VOL_CTL:
573 case CDC_TX7_TX_PATH_SEC0:
574 case CDC_TX7_TX_PATH_SEC1:
575 case CDC_TX7_TX_PATH_SEC2:
576 case CDC_TX7_TX_PATH_SEC3:
577 case CDC_TX7_TX_PATH_SEC4:
578 case CDC_TX7_TX_PATH_SEC5:
579 case CDC_TX7_TX_PATH_SEC6:
580 return true;
581 }
582
583 return false;
584 }
585
586 static const struct regmap_config tx_regmap_config = {
587 .name = "tx_macro",
588 .reg_bits = 16,
589 .val_bits = 32,
590 .reg_stride = 4,
591 .cache_type = REGCACHE_FLAT,
592 .max_register = TX_MAX_OFFSET,
593 .reg_defaults = tx_defaults,
594 .num_reg_defaults = ARRAY_SIZE(tx_defaults),
595 .writeable_reg = tx_is_rw_register,
596 .volatile_reg = tx_is_volatile_register,
597 .readable_reg = tx_is_rw_register,
598 };
599
tx_macro_mclk_enable(struct tx_macro * tx,bool mclk_enable)600 static int tx_macro_mclk_enable(struct tx_macro *tx,
601 bool mclk_enable)
602 {
603 struct regmap *regmap = tx->regmap;
604
605 if (mclk_enable) {
606 if (tx->tx_mclk_users == 0) {
607 /* 9.6MHz MCLK, set value 0x00 if other frequency */
608 regmap_update_bits(regmap, CDC_TX_TOP_CSR_FREQ_MCLK, 0x01, 0x01);
609 regmap_update_bits(regmap, CDC_TX_CLK_RST_CTRL_MCLK_CONTROL,
610 CDC_TX_MCLK_EN_MASK,
611 CDC_TX_MCLK_ENABLE);
612 regmap_update_bits(regmap, CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL,
613 CDC_TX_FS_CNT_EN_MASK,
614 CDC_TX_FS_CNT_ENABLE);
615 regcache_mark_dirty(regmap);
616 regcache_sync(regmap);
617 }
618 tx->tx_mclk_users++;
619 } else {
620 if (tx->tx_mclk_users <= 0) {
621 dev_err(tx->dev, "clock already disabled\n");
622 tx->tx_mclk_users = 0;
623 goto exit;
624 }
625 tx->tx_mclk_users--;
626 if (tx->tx_mclk_users == 0) {
627 regmap_update_bits(regmap, CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL,
628 CDC_TX_FS_CNT_EN_MASK, 0x0);
629 regmap_update_bits(regmap, CDC_TX_CLK_RST_CTRL_MCLK_CONTROL,
630 CDC_TX_MCLK_EN_MASK, 0x0);
631 }
632 }
633 exit:
634 return 0;
635 }
636
is_amic_enabled(struct snd_soc_component * component,u8 decimator)637 static bool is_amic_enabled(struct snd_soc_component *component, u8 decimator)
638 {
639 u16 adc_mux_reg, adc_reg, adc_n;
640
641 adc_mux_reg = CDC_TX_INP_MUX_ADC_MUXn_CFG1(decimator);
642
643 if (snd_soc_component_read(component, adc_mux_reg) & SWR_MIC) {
644 adc_reg = CDC_TX_INP_MUX_ADC_MUXn_CFG0(decimator);
645 adc_n = snd_soc_component_read_field(component, adc_reg,
646 CDC_TX_MACRO_SWR_MIC_MUX_SEL_MASK);
647 if (adc_n < TX_ADC_MAX)
648 return true;
649 }
650
651 return false;
652 }
653
tx_macro_tx_hpf_corner_freq_callback(struct work_struct * work)654 static void tx_macro_tx_hpf_corner_freq_callback(struct work_struct *work)
655 {
656 struct delayed_work *hpf_delayed_work;
657 struct hpf_work *hpf_work;
658 struct tx_macro *tx;
659 struct snd_soc_component *component;
660 u16 dec_cfg_reg, hpf_gate_reg;
661 u8 hpf_cut_off_freq;
662
663 hpf_delayed_work = to_delayed_work(work);
664 hpf_work = container_of(hpf_delayed_work, struct hpf_work, dwork);
665 tx = hpf_work->tx;
666 component = tx->component;
667 hpf_cut_off_freq = hpf_work->hpf_cut_off_freq;
668
669 dec_cfg_reg = CDC_TXn_TX_PATH_CFG0(hpf_work->decimator);
670 hpf_gate_reg = CDC_TXn_TX_PATH_SEC2(hpf_work->decimator);
671
672 if (is_amic_enabled(component, hpf_work->decimator)) {
673 snd_soc_component_write_field(component,
674 dec_cfg_reg,
675 CDC_TXn_HPF_CUT_FREQ_MASK,
676 hpf_cut_off_freq);
677 snd_soc_component_update_bits(component, hpf_gate_reg,
678 CDC_TXn_HPF_F_CHANGE_MASK |
679 CDC_TXn_HPF_ZERO_GATE_MASK,
680 0x02);
681 snd_soc_component_update_bits(component, hpf_gate_reg,
682 CDC_TXn_HPF_F_CHANGE_MASK |
683 CDC_TXn_HPF_ZERO_GATE_MASK,
684 0x01);
685 } else {
686 snd_soc_component_write_field(component, dec_cfg_reg,
687 CDC_TXn_HPF_CUT_FREQ_MASK,
688 hpf_cut_off_freq);
689 snd_soc_component_write_field(component, hpf_gate_reg,
690 CDC_TXn_HPF_F_CHANGE_MASK, 0x1);
691 /* Minimum 1 clk cycle delay is required as per HW spec */
692 usleep_range(1000, 1010);
693 snd_soc_component_write_field(component, hpf_gate_reg,
694 CDC_TXn_HPF_F_CHANGE_MASK, 0x0);
695 }
696 }
697
tx_macro_mute_update_callback(struct work_struct * work)698 static void tx_macro_mute_update_callback(struct work_struct *work)
699 {
700 struct tx_mute_work *tx_mute_dwork;
701 struct snd_soc_component *component;
702 struct tx_macro *tx;
703 struct delayed_work *delayed_work;
704 u8 decimator;
705
706 delayed_work = to_delayed_work(work);
707 tx_mute_dwork = container_of(delayed_work, struct tx_mute_work, dwork);
708 tx = tx_mute_dwork->tx;
709 component = tx->component;
710 decimator = tx_mute_dwork->decimator;
711
712 snd_soc_component_write_field(component, CDC_TXn_TX_PATH_CTL(decimator),
713 CDC_TXn_PGA_MUTE_MASK, 0x0);
714 }
715
tx_macro_mclk_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)716 static int tx_macro_mclk_event(struct snd_soc_dapm_widget *w,
717 struct snd_kcontrol *kcontrol, int event)
718 {
719 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
720 struct tx_macro *tx = snd_soc_component_get_drvdata(component);
721
722 switch (event) {
723 case SND_SOC_DAPM_PRE_PMU:
724 tx_macro_mclk_enable(tx, true);
725 break;
726 case SND_SOC_DAPM_POST_PMD:
727 tx_macro_mclk_enable(tx, false);
728 break;
729 default:
730 break;
731 }
732
733 return 0;
734 }
735
tx_macro_put_dec_enum(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)736 static int tx_macro_put_dec_enum(struct snd_kcontrol *kcontrol,
737 struct snd_ctl_elem_value *ucontrol)
738 {
739 struct snd_soc_dapm_widget *widget = snd_soc_dapm_kcontrol_widget(kcontrol);
740 struct snd_soc_component *component = snd_soc_dapm_to_component(widget->dapm);
741 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
742 unsigned int val, dmic;
743 u16 mic_sel_reg;
744 u16 dmic_clk_reg;
745 struct tx_macro *tx = snd_soc_component_get_drvdata(component);
746
747 val = ucontrol->value.enumerated.item[0];
748 if (val >= e->items)
749 return -EINVAL;
750
751 switch (e->reg) {
752 case CDC_TX_INP_MUX_ADC_MUX0_CFG0:
753 mic_sel_reg = CDC_TX0_TX_PATH_CFG0;
754 break;
755 case CDC_TX_INP_MUX_ADC_MUX1_CFG0:
756 mic_sel_reg = CDC_TX1_TX_PATH_CFG0;
757 break;
758 case CDC_TX_INP_MUX_ADC_MUX2_CFG0:
759 mic_sel_reg = CDC_TX2_TX_PATH_CFG0;
760 break;
761 case CDC_TX_INP_MUX_ADC_MUX3_CFG0:
762 mic_sel_reg = CDC_TX3_TX_PATH_CFG0;
763 break;
764 case CDC_TX_INP_MUX_ADC_MUX4_CFG0:
765 mic_sel_reg = CDC_TX4_TX_PATH_CFG0;
766 break;
767 case CDC_TX_INP_MUX_ADC_MUX5_CFG0:
768 mic_sel_reg = CDC_TX5_TX_PATH_CFG0;
769 break;
770 case CDC_TX_INP_MUX_ADC_MUX6_CFG0:
771 mic_sel_reg = CDC_TX6_TX_PATH_CFG0;
772 break;
773 case CDC_TX_INP_MUX_ADC_MUX7_CFG0:
774 mic_sel_reg = CDC_TX7_TX_PATH_CFG0;
775 break;
776 default:
777 dev_err(component->dev, "Error in configuration!!\n");
778 return -EINVAL;
779 }
780
781 if (val != 0) {
782 if (val < 5) {
783 snd_soc_component_write_field(component, mic_sel_reg,
784 CDC_TXn_ADC_DMIC_SEL_MASK, 0);
785 } else {
786 snd_soc_component_write_field(component, mic_sel_reg,
787 CDC_TXn_ADC_DMIC_SEL_MASK, 1);
788 dmic = TX_ADC_TO_DMIC(val);
789 dmic_clk_reg = CDC_TX_TOP_CSR_SWR_DMICn_CTL(dmic);
790 snd_soc_component_write_field(component, dmic_clk_reg,
791 CDC_TX_SWR_DMIC_CLK_SEL_MASK,
792 tx->dmic_clk_div);
793 }
794 }
795
796 return snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
797 }
798
tx_macro_tx_mixer_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)799 static int tx_macro_tx_mixer_get(struct snd_kcontrol *kcontrol,
800 struct snd_ctl_elem_value *ucontrol)
801 {
802 struct snd_soc_dapm_widget *widget = snd_soc_dapm_kcontrol_widget(kcontrol);
803 struct snd_soc_component *component = snd_soc_dapm_to_component(widget->dapm);
804 struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value;
805 u32 dai_id = widget->shift;
806 u32 dec_id = mc->shift;
807 struct tx_macro *tx = snd_soc_component_get_drvdata(component);
808
809 if (test_bit(dec_id, &tx->active_ch_mask[dai_id]))
810 ucontrol->value.integer.value[0] = 1;
811 else
812 ucontrol->value.integer.value[0] = 0;
813
814 return 0;
815 }
816
tx_macro_tx_mixer_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)817 static int tx_macro_tx_mixer_put(struct snd_kcontrol *kcontrol,
818 struct snd_ctl_elem_value *ucontrol)
819 {
820 struct snd_soc_dapm_widget *widget = snd_soc_dapm_kcontrol_widget(kcontrol);
821 struct snd_soc_component *component = snd_soc_dapm_to_component(widget->dapm);
822 struct snd_soc_dapm_update *update = NULL;
823 struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value;
824 u32 dai_id = widget->shift;
825 u32 dec_id = mc->shift;
826 u32 enable = ucontrol->value.integer.value[0];
827 struct tx_macro *tx = snd_soc_component_get_drvdata(component);
828
829 if (enable) {
830 if (tx->active_decimator[dai_id] == dec_id)
831 return 0;
832
833 set_bit(dec_id, &tx->active_ch_mask[dai_id]);
834 tx->active_ch_cnt[dai_id]++;
835 tx->active_decimator[dai_id] = dec_id;
836 } else {
837 if (tx->active_decimator[dai_id] == -1)
838 return 0;
839
840 tx->active_ch_cnt[dai_id]--;
841 clear_bit(dec_id, &tx->active_ch_mask[dai_id]);
842 tx->active_decimator[dai_id] = -1;
843 }
844 snd_soc_dapm_mixer_update_power(widget->dapm, kcontrol, enable, update);
845
846 return 1;
847 }
848
tx_macro_enable_dec(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)849 static int tx_macro_enable_dec(struct snd_soc_dapm_widget *w,
850 struct snd_kcontrol *kcontrol, int event)
851 {
852 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
853 u8 decimator;
854 u16 tx_vol_ctl_reg, dec_cfg_reg, hpf_gate_reg, tx_gain_ctl_reg;
855 u8 hpf_cut_off_freq;
856 int hpf_delay = TX_MACRO_DMIC_HPF_DELAY_MS;
857 int unmute_delay = TX_MACRO_DMIC_UNMUTE_DELAY_MS;
858 u16 adc_mux_reg, adc_reg, adc_n, dmic;
859 u16 dmic_clk_reg;
860 struct tx_macro *tx = snd_soc_component_get_drvdata(component);
861
862 decimator = w->shift;
863 tx_vol_ctl_reg = CDC_TXn_TX_PATH_CTL(decimator);
864 hpf_gate_reg = CDC_TXn_TX_PATH_SEC2(decimator);
865 dec_cfg_reg = CDC_TXn_TX_PATH_CFG0(decimator);
866 tx_gain_ctl_reg = CDC_TXn_TX_VOL_CTL(decimator);
867
868 switch (event) {
869 case SND_SOC_DAPM_PRE_PMU:
870 adc_mux_reg = CDC_TX_INP_MUX_ADC_MUXn_CFG1(decimator);
871 if (snd_soc_component_read(component, adc_mux_reg) & SWR_MIC) {
872 adc_reg = CDC_TX_INP_MUX_ADC_MUXn_CFG0(decimator);
873 adc_n = snd_soc_component_read(component, adc_reg) &
874 CDC_TX_MACRO_SWR_MIC_MUX_SEL_MASK;
875 if (adc_n >= TX_ADC_MAX) {
876 dmic = TX_ADC_TO_DMIC(adc_n);
877 dmic_clk_reg = CDC_TX_TOP_CSR_SWR_DMICn_CTL(dmic);
878
879 snd_soc_component_write_field(component, dmic_clk_reg,
880 CDC_TX_SWR_DMIC_CLK_SEL_MASK,
881 tx->dmic_clk_div);
882 }
883 }
884 snd_soc_component_write_field(component, dec_cfg_reg,
885 CDC_TXn_ADC_MODE_MASK,
886 tx->dec_mode[decimator]);
887 /* Enable TX PGA Mute */
888 snd_soc_component_write_field(component, tx_vol_ctl_reg,
889 CDC_TXn_PGA_MUTE_MASK, 0x1);
890 break;
891 case SND_SOC_DAPM_POST_PMU:
892 snd_soc_component_write_field(component, tx_vol_ctl_reg,
893 CDC_TXn_CLK_EN_MASK, 0x1);
894 if (!is_amic_enabled(component, decimator)) {
895 snd_soc_component_update_bits(component, hpf_gate_reg, 0x01, 0x00);
896 /* Minimum 1 clk cycle delay is required as per HW spec */
897 usleep_range(1000, 1010);
898 }
899 hpf_cut_off_freq = snd_soc_component_read_field(component, dec_cfg_reg,
900 CDC_TXn_HPF_CUT_FREQ_MASK);
901
902 tx->tx_hpf_work[decimator].hpf_cut_off_freq =
903 hpf_cut_off_freq;
904
905 if (hpf_cut_off_freq != CF_MIN_3DB_150HZ)
906 snd_soc_component_write_field(component, dec_cfg_reg,
907 CDC_TXn_HPF_CUT_FREQ_MASK,
908 CF_MIN_3DB_150HZ);
909
910 if (is_amic_enabled(component, decimator)) {
911 hpf_delay = TX_MACRO_AMIC_HPF_DELAY_MS;
912 unmute_delay = TX_MACRO_AMIC_UNMUTE_DELAY_MS;
913 }
914 /* schedule work queue to Remove Mute */
915 queue_delayed_work(system_freezable_wq,
916 &tx->tx_mute_dwork[decimator].dwork,
917 msecs_to_jiffies(unmute_delay));
918 if (tx->tx_hpf_work[decimator].hpf_cut_off_freq != CF_MIN_3DB_150HZ) {
919 queue_delayed_work(system_freezable_wq,
920 &tx->tx_hpf_work[decimator].dwork,
921 msecs_to_jiffies(hpf_delay));
922 snd_soc_component_update_bits(component, hpf_gate_reg,
923 CDC_TXn_HPF_F_CHANGE_MASK |
924 CDC_TXn_HPF_ZERO_GATE_MASK,
925 0x02);
926 if (!is_amic_enabled(component, decimator))
927 snd_soc_component_update_bits(component, hpf_gate_reg,
928 CDC_TXn_HPF_F_CHANGE_MASK |
929 CDC_TXn_HPF_ZERO_GATE_MASK,
930 0x00);
931 snd_soc_component_update_bits(component, hpf_gate_reg,
932 CDC_TXn_HPF_F_CHANGE_MASK |
933 CDC_TXn_HPF_ZERO_GATE_MASK,
934 0x01);
935
936 /*
937 * 6ms delay is required as per HW spec
938 */
939 usleep_range(6000, 6010);
940 }
941 /* apply gain after decimator is enabled */
942 snd_soc_component_write(component, tx_gain_ctl_reg,
943 snd_soc_component_read(component,
944 tx_gain_ctl_reg));
945 if (tx->bcs_enable) {
946 snd_soc_component_update_bits(component, dec_cfg_reg,
947 0x01, 0x01);
948 tx->bcs_clk_en = true;
949 }
950 break;
951 case SND_SOC_DAPM_PRE_PMD:
952 hpf_cut_off_freq =
953 tx->tx_hpf_work[decimator].hpf_cut_off_freq;
954 snd_soc_component_write_field(component, tx_vol_ctl_reg,
955 CDC_TXn_PGA_MUTE_MASK, 0x1);
956 if (cancel_delayed_work_sync(
957 &tx->tx_hpf_work[decimator].dwork)) {
958 if (hpf_cut_off_freq != CF_MIN_3DB_150HZ) {
959 snd_soc_component_write_field(
960 component, dec_cfg_reg,
961 CDC_TXn_HPF_CUT_FREQ_MASK,
962 hpf_cut_off_freq);
963 if (is_amic_enabled(component, decimator))
964 snd_soc_component_update_bits(component,
965 hpf_gate_reg,
966 CDC_TXn_HPF_F_CHANGE_MASK |
967 CDC_TXn_HPF_ZERO_GATE_MASK,
968 0x02);
969 else
970 snd_soc_component_update_bits(component,
971 hpf_gate_reg,
972 CDC_TXn_HPF_F_CHANGE_MASK |
973 CDC_TXn_HPF_ZERO_GATE_MASK,
974 0x03);
975
976 /*
977 * Minimum 1 clk cycle delay is required
978 * as per HW spec
979 */
980 usleep_range(1000, 1010);
981 snd_soc_component_update_bits(component, hpf_gate_reg,
982 CDC_TXn_HPF_F_CHANGE_MASK |
983 CDC_TXn_HPF_ZERO_GATE_MASK,
984 0x1);
985 }
986 }
987 cancel_delayed_work_sync(&tx->tx_mute_dwork[decimator].dwork);
988 break;
989 case SND_SOC_DAPM_POST_PMD:
990 snd_soc_component_write_field(component, tx_vol_ctl_reg,
991 CDC_TXn_CLK_EN_MASK, 0x0);
992 snd_soc_component_write_field(component, dec_cfg_reg,
993 CDC_TXn_ADC_MODE_MASK, 0x0);
994 snd_soc_component_write_field(component, tx_vol_ctl_reg,
995 CDC_TXn_PGA_MUTE_MASK, 0x0);
996 if (tx->bcs_enable) {
997 snd_soc_component_write_field(component, dec_cfg_reg,
998 CDC_TXn_PH_EN_MASK, 0x0);
999 snd_soc_component_write_field(component,
1000 CDC_TX0_TX_PATH_SEC7,
1001 CDC_TX0_MBHC_CTL_EN_MASK,
1002 0x0);
1003 tx->bcs_clk_en = false;
1004 }
1005 break;
1006 }
1007 return 0;
1008 }
1009
tx_macro_dec_mode_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1010 static int tx_macro_dec_mode_get(struct snd_kcontrol *kcontrol,
1011 struct snd_ctl_elem_value *ucontrol)
1012 {
1013 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
1014 struct tx_macro *tx = snd_soc_component_get_drvdata(component);
1015 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1016 int path = e->shift_l;
1017
1018 ucontrol->value.integer.value[0] = tx->dec_mode[path];
1019
1020 return 0;
1021 }
1022
tx_macro_dec_mode_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1023 static int tx_macro_dec_mode_put(struct snd_kcontrol *kcontrol,
1024 struct snd_ctl_elem_value *ucontrol)
1025 {
1026 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
1027 int value = ucontrol->value.integer.value[0];
1028 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1029 int path = e->shift_l;
1030 struct tx_macro *tx = snd_soc_component_get_drvdata(component);
1031
1032 if (tx->dec_mode[path] == value)
1033 return 0;
1034
1035 tx->dec_mode[path] = value;
1036
1037 return 1;
1038 }
1039
tx_macro_get_bcs(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1040 static int tx_macro_get_bcs(struct snd_kcontrol *kcontrol,
1041 struct snd_ctl_elem_value *ucontrol)
1042 {
1043 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
1044 struct tx_macro *tx = snd_soc_component_get_drvdata(component);
1045
1046 ucontrol->value.integer.value[0] = tx->bcs_enable;
1047
1048 return 0;
1049 }
1050
tx_macro_set_bcs(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)1051 static int tx_macro_set_bcs(struct snd_kcontrol *kcontrol,
1052 struct snd_ctl_elem_value *ucontrol)
1053 {
1054 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
1055 int value = ucontrol->value.integer.value[0];
1056 struct tx_macro *tx = snd_soc_component_get_drvdata(component);
1057
1058 tx->bcs_enable = value;
1059
1060 return 0;
1061 }
1062
tx_macro_hw_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * params,struct snd_soc_dai * dai)1063 static int tx_macro_hw_params(struct snd_pcm_substream *substream,
1064 struct snd_pcm_hw_params *params,
1065 struct snd_soc_dai *dai)
1066 {
1067 struct snd_soc_component *component = dai->component;
1068 u32 sample_rate;
1069 u8 decimator;
1070 int tx_fs_rate;
1071 struct tx_macro *tx = snd_soc_component_get_drvdata(component);
1072
1073 sample_rate = params_rate(params);
1074 switch (sample_rate) {
1075 case 8000:
1076 tx_fs_rate = 0;
1077 break;
1078 case 16000:
1079 tx_fs_rate = 1;
1080 break;
1081 case 32000:
1082 tx_fs_rate = 3;
1083 break;
1084 case 48000:
1085 tx_fs_rate = 4;
1086 break;
1087 case 96000:
1088 tx_fs_rate = 5;
1089 break;
1090 case 192000:
1091 tx_fs_rate = 6;
1092 break;
1093 case 384000:
1094 tx_fs_rate = 7;
1095 break;
1096 default:
1097 dev_err(component->dev, "%s: Invalid TX sample rate: %d\n",
1098 __func__, params_rate(params));
1099 return -EINVAL;
1100 }
1101
1102 for_each_set_bit(decimator, &tx->active_ch_mask[dai->id], TX_MACRO_DEC_MAX)
1103 snd_soc_component_update_bits(component, CDC_TXn_TX_PATH_CTL(decimator),
1104 CDC_TXn_PCM_RATE_MASK,
1105 tx_fs_rate);
1106 return 0;
1107 }
1108
tx_macro_get_channel_map(struct snd_soc_dai * dai,unsigned int * tx_num,unsigned int * tx_slot,unsigned int * rx_num,unsigned int * rx_slot)1109 static int tx_macro_get_channel_map(struct snd_soc_dai *dai,
1110 unsigned int *tx_num, unsigned int *tx_slot,
1111 unsigned int *rx_num, unsigned int *rx_slot)
1112 {
1113 struct snd_soc_component *component = dai->component;
1114 struct tx_macro *tx = snd_soc_component_get_drvdata(component);
1115
1116 switch (dai->id) {
1117 case TX_MACRO_AIF1_CAP:
1118 case TX_MACRO_AIF2_CAP:
1119 case TX_MACRO_AIF3_CAP:
1120 *tx_slot = tx->active_ch_mask[dai->id];
1121 *tx_num = tx->active_ch_cnt[dai->id];
1122 break;
1123 default:
1124 break;
1125 }
1126 return 0;
1127 }
1128
tx_macro_digital_mute(struct snd_soc_dai * dai,int mute,int stream)1129 static int tx_macro_digital_mute(struct snd_soc_dai *dai, int mute, int stream)
1130 {
1131 struct snd_soc_component *component = dai->component;
1132 struct tx_macro *tx = snd_soc_component_get_drvdata(component);
1133 u8 decimator;
1134
1135 /* active decimator not set yet */
1136 if (tx->active_decimator[dai->id] == -1)
1137 return 0;
1138
1139 decimator = tx->active_decimator[dai->id];
1140
1141 if (mute)
1142 snd_soc_component_write_field(component,
1143 CDC_TXn_TX_PATH_CTL(decimator),
1144 CDC_TXn_PGA_MUTE_MASK, 0x1);
1145 else
1146 snd_soc_component_update_bits(component,
1147 CDC_TXn_TX_PATH_CTL(decimator),
1148 CDC_TXn_PGA_MUTE_MASK, 0x0);
1149
1150 return 0;
1151 }
1152
1153 static const struct snd_soc_dai_ops tx_macro_dai_ops = {
1154 .hw_params = tx_macro_hw_params,
1155 .get_channel_map = tx_macro_get_channel_map,
1156 .mute_stream = tx_macro_digital_mute,
1157 };
1158
1159 static struct snd_soc_dai_driver tx_macro_dai[] = {
1160 {
1161 .name = "tx_macro_tx1",
1162 .id = TX_MACRO_AIF1_CAP,
1163 .capture = {
1164 .stream_name = "TX_AIF1 Capture",
1165 .rates = TX_MACRO_RATES,
1166 .formats = TX_MACRO_FORMATS,
1167 .rate_max = 192000,
1168 .rate_min = 8000,
1169 .channels_min = 1,
1170 .channels_max = 8,
1171 },
1172 .ops = &tx_macro_dai_ops,
1173 },
1174 {
1175 .name = "tx_macro_tx2",
1176 .id = TX_MACRO_AIF2_CAP,
1177 .capture = {
1178 .stream_name = "TX_AIF2 Capture",
1179 .rates = TX_MACRO_RATES,
1180 .formats = TX_MACRO_FORMATS,
1181 .rate_max = 192000,
1182 .rate_min = 8000,
1183 .channels_min = 1,
1184 .channels_max = 8,
1185 },
1186 .ops = &tx_macro_dai_ops,
1187 },
1188 {
1189 .name = "tx_macro_tx3",
1190 .id = TX_MACRO_AIF3_CAP,
1191 .capture = {
1192 .stream_name = "TX_AIF3 Capture",
1193 .rates = TX_MACRO_RATES,
1194 .formats = TX_MACRO_FORMATS,
1195 .rate_max = 192000,
1196 .rate_min = 8000,
1197 .channels_min = 1,
1198 .channels_max = 8,
1199 },
1200 .ops = &tx_macro_dai_ops,
1201 },
1202 };
1203
1204 static const char * const adc_mux_text[] = {
1205 "MSM_DMIC", "SWR_MIC", "ANC_FB_TUNE1"
1206 };
1207
1208 static SOC_ENUM_SINGLE_DECL(tx_dec0_enum, CDC_TX_INP_MUX_ADC_MUX0_CFG1,
1209 0, adc_mux_text);
1210 static SOC_ENUM_SINGLE_DECL(tx_dec1_enum, CDC_TX_INP_MUX_ADC_MUX1_CFG1,
1211 0, adc_mux_text);
1212 static SOC_ENUM_SINGLE_DECL(tx_dec2_enum, CDC_TX_INP_MUX_ADC_MUX2_CFG1,
1213 0, adc_mux_text);
1214 static SOC_ENUM_SINGLE_DECL(tx_dec3_enum, CDC_TX_INP_MUX_ADC_MUX3_CFG1,
1215 0, adc_mux_text);
1216 static SOC_ENUM_SINGLE_DECL(tx_dec4_enum, CDC_TX_INP_MUX_ADC_MUX4_CFG1,
1217 0, adc_mux_text);
1218 static SOC_ENUM_SINGLE_DECL(tx_dec5_enum, CDC_TX_INP_MUX_ADC_MUX5_CFG1,
1219 0, adc_mux_text);
1220 static SOC_ENUM_SINGLE_DECL(tx_dec6_enum, CDC_TX_INP_MUX_ADC_MUX6_CFG1,
1221 0, adc_mux_text);
1222 static SOC_ENUM_SINGLE_DECL(tx_dec7_enum, CDC_TX_INP_MUX_ADC_MUX7_CFG1,
1223 0, adc_mux_text);
1224
1225 static const struct snd_kcontrol_new tx_dec0_mux = SOC_DAPM_ENUM("tx_dec0", tx_dec0_enum);
1226 static const struct snd_kcontrol_new tx_dec1_mux = SOC_DAPM_ENUM("tx_dec1", tx_dec1_enum);
1227 static const struct snd_kcontrol_new tx_dec2_mux = SOC_DAPM_ENUM("tx_dec2", tx_dec2_enum);
1228 static const struct snd_kcontrol_new tx_dec3_mux = SOC_DAPM_ENUM("tx_dec3", tx_dec3_enum);
1229 static const struct snd_kcontrol_new tx_dec4_mux = SOC_DAPM_ENUM("tx_dec4", tx_dec4_enum);
1230 static const struct snd_kcontrol_new tx_dec5_mux = SOC_DAPM_ENUM("tx_dec5", tx_dec5_enum);
1231 static const struct snd_kcontrol_new tx_dec6_mux = SOC_DAPM_ENUM("tx_dec6", tx_dec6_enum);
1232 static const struct snd_kcontrol_new tx_dec7_mux = SOC_DAPM_ENUM("tx_dec7", tx_dec7_enum);
1233
1234 static const char * const smic_mux_text[] = {
1235 "ZERO", "ADC0", "ADC1", "ADC2", "ADC3", "SWR_DMIC0",
1236 "SWR_DMIC1", "SWR_DMIC2", "SWR_DMIC3", "SWR_DMIC4",
1237 "SWR_DMIC5", "SWR_DMIC6", "SWR_DMIC7"
1238 };
1239
1240 static SOC_ENUM_SINGLE_DECL(tx_smic0_enum, CDC_TX_INP_MUX_ADC_MUX0_CFG0,
1241 0, smic_mux_text);
1242
1243 static SOC_ENUM_SINGLE_DECL(tx_smic1_enum, CDC_TX_INP_MUX_ADC_MUX1_CFG0,
1244 0, smic_mux_text);
1245
1246 static SOC_ENUM_SINGLE_DECL(tx_smic2_enum, CDC_TX_INP_MUX_ADC_MUX2_CFG0,
1247 0, smic_mux_text);
1248
1249 static SOC_ENUM_SINGLE_DECL(tx_smic3_enum, CDC_TX_INP_MUX_ADC_MUX3_CFG0,
1250 0, smic_mux_text);
1251
1252 static SOC_ENUM_SINGLE_DECL(tx_smic4_enum, CDC_TX_INP_MUX_ADC_MUX4_CFG0,
1253 0, smic_mux_text);
1254
1255 static SOC_ENUM_SINGLE_DECL(tx_smic5_enum, CDC_TX_INP_MUX_ADC_MUX5_CFG0,
1256 0, smic_mux_text);
1257
1258 static SOC_ENUM_SINGLE_DECL(tx_smic6_enum, CDC_TX_INP_MUX_ADC_MUX6_CFG0,
1259 0, smic_mux_text);
1260
1261 static SOC_ENUM_SINGLE_DECL(tx_smic7_enum, CDC_TX_INP_MUX_ADC_MUX7_CFG0,
1262 0, smic_mux_text);
1263
1264 static const struct snd_kcontrol_new tx_smic0_mux = SOC_DAPM_ENUM_EXT("tx_smic0", tx_smic0_enum,
1265 snd_soc_dapm_get_enum_double, tx_macro_put_dec_enum);
1266 static const struct snd_kcontrol_new tx_smic1_mux = SOC_DAPM_ENUM_EXT("tx_smic1", tx_smic1_enum,
1267 snd_soc_dapm_get_enum_double, tx_macro_put_dec_enum);
1268 static const struct snd_kcontrol_new tx_smic2_mux = SOC_DAPM_ENUM_EXT("tx_smic2", tx_smic2_enum,
1269 snd_soc_dapm_get_enum_double, tx_macro_put_dec_enum);
1270 static const struct snd_kcontrol_new tx_smic3_mux = SOC_DAPM_ENUM_EXT("tx_smic3", tx_smic3_enum,
1271 snd_soc_dapm_get_enum_double, tx_macro_put_dec_enum);
1272 static const struct snd_kcontrol_new tx_smic4_mux = SOC_DAPM_ENUM_EXT("tx_smic4", tx_smic4_enum,
1273 snd_soc_dapm_get_enum_double, tx_macro_put_dec_enum);
1274 static const struct snd_kcontrol_new tx_smic5_mux = SOC_DAPM_ENUM_EXT("tx_smic5", tx_smic5_enum,
1275 snd_soc_dapm_get_enum_double, tx_macro_put_dec_enum);
1276 static const struct snd_kcontrol_new tx_smic6_mux = SOC_DAPM_ENUM_EXT("tx_smic6", tx_smic6_enum,
1277 snd_soc_dapm_get_enum_double, tx_macro_put_dec_enum);
1278 static const struct snd_kcontrol_new tx_smic7_mux = SOC_DAPM_ENUM_EXT("tx_smic7", tx_smic7_enum,
1279 snd_soc_dapm_get_enum_double, tx_macro_put_dec_enum);
1280
1281 static const char * const dec_mode_mux_text[] = {
1282 "ADC_DEFAULT", "ADC_LOW_PWR", "ADC_HIGH_PERF",
1283 };
1284
1285 static const struct soc_enum dec_mode_mux_enum[] = {
1286 SOC_ENUM_SINGLE(SND_SOC_NOPM, 0, ARRAY_SIZE(dec_mode_mux_text),
1287 dec_mode_mux_text),
1288 SOC_ENUM_SINGLE(SND_SOC_NOPM, 1, ARRAY_SIZE(dec_mode_mux_text),
1289 dec_mode_mux_text),
1290 SOC_ENUM_SINGLE(SND_SOC_NOPM, 2, ARRAY_SIZE(dec_mode_mux_text),
1291 dec_mode_mux_text),
1292 SOC_ENUM_SINGLE(SND_SOC_NOPM, 3, ARRAY_SIZE(dec_mode_mux_text),
1293 dec_mode_mux_text),
1294 SOC_ENUM_SINGLE(SND_SOC_NOPM, 4, ARRAY_SIZE(dec_mode_mux_text),
1295 dec_mode_mux_text),
1296 SOC_ENUM_SINGLE(SND_SOC_NOPM, 5, ARRAY_SIZE(dec_mode_mux_text),
1297 dec_mode_mux_text),
1298 SOC_ENUM_SINGLE(SND_SOC_NOPM, 6, ARRAY_SIZE(dec_mode_mux_text),
1299 dec_mode_mux_text),
1300 SOC_ENUM_SINGLE(SND_SOC_NOPM, 7, ARRAY_SIZE(dec_mode_mux_text),
1301 dec_mode_mux_text),
1302 };
1303
1304 static const struct snd_kcontrol_new tx_aif1_cap_mixer[] = {
1305 SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
1306 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1307 SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
1308 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1309 SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
1310 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1311 SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
1312 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1313 SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, TX_MACRO_DEC4, 1, 0,
1314 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1315 SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, TX_MACRO_DEC5, 1, 0,
1316 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1317 SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, TX_MACRO_DEC6, 1, 0,
1318 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1319 SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, TX_MACRO_DEC7, 1, 0,
1320 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1321 };
1322
1323 static const struct snd_kcontrol_new tx_aif2_cap_mixer[] = {
1324 SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
1325 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1326 SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
1327 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1328 SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
1329 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1330 SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
1331 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1332 SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, TX_MACRO_DEC4, 1, 0,
1333 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1334 SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, TX_MACRO_DEC5, 1, 0,
1335 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1336 SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, TX_MACRO_DEC6, 1, 0,
1337 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1338 SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, TX_MACRO_DEC7, 1, 0,
1339 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1340 };
1341
1342 static const struct snd_kcontrol_new tx_aif3_cap_mixer[] = {
1343 SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
1344 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1345 SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
1346 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1347 SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
1348 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1349 SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
1350 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1351 SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, TX_MACRO_DEC4, 1, 0,
1352 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1353 SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, TX_MACRO_DEC5, 1, 0,
1354 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1355 SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, TX_MACRO_DEC6, 1, 0,
1356 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1357 SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, TX_MACRO_DEC7, 1, 0,
1358 tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
1359 };
1360
1361 static const struct snd_soc_dapm_widget tx_macro_dapm_widgets[] = {
1362 SND_SOC_DAPM_AIF_OUT("TX_AIF1 CAP", "TX_AIF1 Capture", 0,
1363 SND_SOC_NOPM, TX_MACRO_AIF1_CAP, 0),
1364
1365 SND_SOC_DAPM_AIF_OUT("TX_AIF2 CAP", "TX_AIF2 Capture", 0,
1366 SND_SOC_NOPM, TX_MACRO_AIF2_CAP, 0),
1367
1368 SND_SOC_DAPM_AIF_OUT("TX_AIF3 CAP", "TX_AIF3 Capture", 0,
1369 SND_SOC_NOPM, TX_MACRO_AIF3_CAP, 0),
1370
1371 SND_SOC_DAPM_MIXER("TX_AIF1_CAP Mixer", SND_SOC_NOPM, TX_MACRO_AIF1_CAP, 0,
1372 tx_aif1_cap_mixer, ARRAY_SIZE(tx_aif1_cap_mixer)),
1373
1374 SND_SOC_DAPM_MIXER("TX_AIF2_CAP Mixer", SND_SOC_NOPM, TX_MACRO_AIF2_CAP, 0,
1375 tx_aif2_cap_mixer, ARRAY_SIZE(tx_aif2_cap_mixer)),
1376
1377 SND_SOC_DAPM_MIXER("TX_AIF3_CAP Mixer", SND_SOC_NOPM, TX_MACRO_AIF3_CAP, 0,
1378 tx_aif3_cap_mixer, ARRAY_SIZE(tx_aif3_cap_mixer)),
1379
1380 SND_SOC_DAPM_MUX("TX SMIC MUX0", SND_SOC_NOPM, 0, 0, &tx_smic0_mux),
1381 SND_SOC_DAPM_MUX("TX SMIC MUX1", SND_SOC_NOPM, 0, 0, &tx_smic1_mux),
1382 SND_SOC_DAPM_MUX("TX SMIC MUX2", SND_SOC_NOPM, 0, 0, &tx_smic2_mux),
1383 SND_SOC_DAPM_MUX("TX SMIC MUX3", SND_SOC_NOPM, 0, 0, &tx_smic3_mux),
1384 SND_SOC_DAPM_MUX("TX SMIC MUX4", SND_SOC_NOPM, 0, 0, &tx_smic4_mux),
1385 SND_SOC_DAPM_MUX("TX SMIC MUX5", SND_SOC_NOPM, 0, 0, &tx_smic5_mux),
1386 SND_SOC_DAPM_MUX("TX SMIC MUX6", SND_SOC_NOPM, 0, 0, &tx_smic6_mux),
1387 SND_SOC_DAPM_MUX("TX SMIC MUX7", SND_SOC_NOPM, 0, 0, &tx_smic7_mux),
1388
1389 SND_SOC_DAPM_INPUT("TX SWR_ADC0"),
1390 SND_SOC_DAPM_INPUT("TX SWR_ADC1"),
1391 SND_SOC_DAPM_INPUT("TX SWR_ADC2"),
1392 SND_SOC_DAPM_INPUT("TX SWR_ADC3"),
1393 SND_SOC_DAPM_INPUT("TX SWR_DMIC0"),
1394 SND_SOC_DAPM_INPUT("TX SWR_DMIC1"),
1395 SND_SOC_DAPM_INPUT("TX SWR_DMIC2"),
1396 SND_SOC_DAPM_INPUT("TX SWR_DMIC3"),
1397 SND_SOC_DAPM_INPUT("TX SWR_DMIC4"),
1398 SND_SOC_DAPM_INPUT("TX SWR_DMIC5"),
1399 SND_SOC_DAPM_INPUT("TX SWR_DMIC6"),
1400 SND_SOC_DAPM_INPUT("TX SWR_DMIC7"),
1401
1402 SND_SOC_DAPM_MUX_E("TX DEC0 MUX", SND_SOC_NOPM,
1403 TX_MACRO_DEC0, 0,
1404 &tx_dec0_mux, tx_macro_enable_dec,
1405 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1406 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
1407
1408 SND_SOC_DAPM_MUX_E("TX DEC1 MUX", SND_SOC_NOPM,
1409 TX_MACRO_DEC1, 0,
1410 &tx_dec1_mux, tx_macro_enable_dec,
1411 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1412 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
1413
1414 SND_SOC_DAPM_MUX_E("TX DEC2 MUX", SND_SOC_NOPM,
1415 TX_MACRO_DEC2, 0,
1416 &tx_dec2_mux, tx_macro_enable_dec,
1417 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1418 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
1419
1420 SND_SOC_DAPM_MUX_E("TX DEC3 MUX", SND_SOC_NOPM,
1421 TX_MACRO_DEC3, 0,
1422 &tx_dec3_mux, tx_macro_enable_dec,
1423 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1424 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
1425
1426 SND_SOC_DAPM_MUX_E("TX DEC4 MUX", SND_SOC_NOPM,
1427 TX_MACRO_DEC4, 0,
1428 &tx_dec4_mux, tx_macro_enable_dec,
1429 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1430 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
1431
1432 SND_SOC_DAPM_MUX_E("TX DEC5 MUX", SND_SOC_NOPM,
1433 TX_MACRO_DEC5, 0,
1434 &tx_dec5_mux, tx_macro_enable_dec,
1435 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1436 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
1437
1438 SND_SOC_DAPM_MUX_E("TX DEC6 MUX", SND_SOC_NOPM,
1439 TX_MACRO_DEC6, 0,
1440 &tx_dec6_mux, tx_macro_enable_dec,
1441 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1442 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
1443
1444 SND_SOC_DAPM_MUX_E("TX DEC7 MUX", SND_SOC_NOPM,
1445 TX_MACRO_DEC7, 0,
1446 &tx_dec7_mux, tx_macro_enable_dec,
1447 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
1448 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
1449
1450 SND_SOC_DAPM_SUPPLY_S("TX_MCLK", 0, SND_SOC_NOPM, 0, 0,
1451 tx_macro_mclk_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1452
1453 SND_SOC_DAPM_SUPPLY_S("TX_SWR_CLK", 0, SND_SOC_NOPM, 0, 0, NULL, 0),
1454
1455 SND_SOC_DAPM_SUPPLY_S("VA_SWR_CLK", 0, SND_SOC_NOPM, 0, 0,
1456 NULL, 0),
1457 };
1458
1459 static const struct snd_soc_dapm_route tx_audio_map[] = {
1460 {"TX_AIF1 CAP", NULL, "TX_MCLK"},
1461 {"TX_AIF2 CAP", NULL, "TX_MCLK"},
1462 {"TX_AIF3 CAP", NULL, "TX_MCLK"},
1463
1464 {"TX_AIF1 CAP", NULL, "TX_AIF1_CAP Mixer"},
1465 {"TX_AIF2 CAP", NULL, "TX_AIF2_CAP Mixer"},
1466 {"TX_AIF3 CAP", NULL, "TX_AIF3_CAP Mixer"},
1467
1468 {"TX_AIF1_CAP Mixer", "DEC0", "TX DEC0 MUX"},
1469 {"TX_AIF1_CAP Mixer", "DEC1", "TX DEC1 MUX"},
1470 {"TX_AIF1_CAP Mixer", "DEC2", "TX DEC2 MUX"},
1471 {"TX_AIF1_CAP Mixer", "DEC3", "TX DEC3 MUX"},
1472 {"TX_AIF1_CAP Mixer", "DEC4", "TX DEC4 MUX"},
1473 {"TX_AIF1_CAP Mixer", "DEC5", "TX DEC5 MUX"},
1474 {"TX_AIF1_CAP Mixer", "DEC6", "TX DEC6 MUX"},
1475 {"TX_AIF1_CAP Mixer", "DEC7", "TX DEC7 MUX"},
1476
1477 {"TX_AIF2_CAP Mixer", "DEC0", "TX DEC0 MUX"},
1478 {"TX_AIF2_CAP Mixer", "DEC1", "TX DEC1 MUX"},
1479 {"TX_AIF2_CAP Mixer", "DEC2", "TX DEC2 MUX"},
1480 {"TX_AIF2_CAP Mixer", "DEC3", "TX DEC3 MUX"},
1481 {"TX_AIF2_CAP Mixer", "DEC4", "TX DEC4 MUX"},
1482 {"TX_AIF2_CAP Mixer", "DEC5", "TX DEC5 MUX"},
1483 {"TX_AIF2_CAP Mixer", "DEC6", "TX DEC6 MUX"},
1484 {"TX_AIF2_CAP Mixer", "DEC7", "TX DEC7 MUX"},
1485
1486 {"TX_AIF3_CAP Mixer", "DEC0", "TX DEC0 MUX"},
1487 {"TX_AIF3_CAP Mixer", "DEC1", "TX DEC1 MUX"},
1488 {"TX_AIF3_CAP Mixer", "DEC2", "TX DEC2 MUX"},
1489 {"TX_AIF3_CAP Mixer", "DEC3", "TX DEC3 MUX"},
1490 {"TX_AIF3_CAP Mixer", "DEC4", "TX DEC4 MUX"},
1491 {"TX_AIF3_CAP Mixer", "DEC5", "TX DEC5 MUX"},
1492 {"TX_AIF3_CAP Mixer", "DEC6", "TX DEC6 MUX"},
1493 {"TX_AIF3_CAP Mixer", "DEC7", "TX DEC7 MUX"},
1494
1495 {"TX DEC0 MUX", NULL, "TX_MCLK"},
1496 {"TX DEC1 MUX", NULL, "TX_MCLK"},
1497 {"TX DEC2 MUX", NULL, "TX_MCLK"},
1498 {"TX DEC3 MUX", NULL, "TX_MCLK"},
1499 {"TX DEC4 MUX", NULL, "TX_MCLK"},
1500 {"TX DEC5 MUX", NULL, "TX_MCLK"},
1501 {"TX DEC6 MUX", NULL, "TX_MCLK"},
1502 {"TX DEC7 MUX", NULL, "TX_MCLK"},
1503
1504 {"TX DEC0 MUX", "SWR_MIC", "TX SMIC MUX0"},
1505 {"TX SMIC MUX0", NULL, "TX_SWR_CLK"},
1506 {"TX SMIC MUX0", "ADC0", "TX SWR_ADC0"},
1507 {"TX SMIC MUX0", "ADC1", "TX SWR_ADC1"},
1508 {"TX SMIC MUX0", "ADC2", "TX SWR_ADC2"},
1509 {"TX SMIC MUX0", "ADC3", "TX SWR_ADC3"},
1510 {"TX SMIC MUX0", "SWR_DMIC0", "TX SWR_DMIC0"},
1511 {"TX SMIC MUX0", "SWR_DMIC1", "TX SWR_DMIC1"},
1512 {"TX SMIC MUX0", "SWR_DMIC2", "TX SWR_DMIC2"},
1513 {"TX SMIC MUX0", "SWR_DMIC3", "TX SWR_DMIC3"},
1514 {"TX SMIC MUX0", "SWR_DMIC4", "TX SWR_DMIC4"},
1515 {"TX SMIC MUX0", "SWR_DMIC5", "TX SWR_DMIC5"},
1516 {"TX SMIC MUX0", "SWR_DMIC6", "TX SWR_DMIC6"},
1517 {"TX SMIC MUX0", "SWR_DMIC7", "TX SWR_DMIC7"},
1518
1519 {"TX DEC1 MUX", "SWR_MIC", "TX SMIC MUX1"},
1520 {"TX SMIC MUX1", NULL, "TX_SWR_CLK"},
1521 {"TX SMIC MUX1", "ADC0", "TX SWR_ADC0"},
1522 {"TX SMIC MUX1", "ADC1", "TX SWR_ADC1"},
1523 {"TX SMIC MUX1", "ADC2", "TX SWR_ADC2"},
1524 {"TX SMIC MUX1", "ADC3", "TX SWR_ADC3"},
1525 {"TX SMIC MUX1", "SWR_DMIC0", "TX SWR_DMIC0"},
1526 {"TX SMIC MUX1", "SWR_DMIC1", "TX SWR_DMIC1"},
1527 {"TX SMIC MUX1", "SWR_DMIC2", "TX SWR_DMIC2"},
1528 {"TX SMIC MUX1", "SWR_DMIC3", "TX SWR_DMIC3"},
1529 {"TX SMIC MUX1", "SWR_DMIC4", "TX SWR_DMIC4"},
1530 {"TX SMIC MUX1", "SWR_DMIC5", "TX SWR_DMIC5"},
1531 {"TX SMIC MUX1", "SWR_DMIC6", "TX SWR_DMIC6"},
1532 {"TX SMIC MUX1", "SWR_DMIC7", "TX SWR_DMIC7"},
1533
1534 {"TX DEC2 MUX", "SWR_MIC", "TX SMIC MUX2"},
1535 {"TX SMIC MUX2", NULL, "TX_SWR_CLK"},
1536 {"TX SMIC MUX2", "ADC0", "TX SWR_ADC0"},
1537 {"TX SMIC MUX2", "ADC1", "TX SWR_ADC1"},
1538 {"TX SMIC MUX2", "ADC2", "TX SWR_ADC2"},
1539 {"TX SMIC MUX2", "ADC3", "TX SWR_ADC3"},
1540 {"TX SMIC MUX2", "SWR_DMIC0", "TX SWR_DMIC0"},
1541 {"TX SMIC MUX2", "SWR_DMIC1", "TX SWR_DMIC1"},
1542 {"TX SMIC MUX2", "SWR_DMIC2", "TX SWR_DMIC2"},
1543 {"TX SMIC MUX2", "SWR_DMIC3", "TX SWR_DMIC3"},
1544 {"TX SMIC MUX2", "SWR_DMIC4", "TX SWR_DMIC4"},
1545 {"TX SMIC MUX2", "SWR_DMIC5", "TX SWR_DMIC5"},
1546 {"TX SMIC MUX2", "SWR_DMIC6", "TX SWR_DMIC6"},
1547 {"TX SMIC MUX2", "SWR_DMIC7", "TX SWR_DMIC7"},
1548
1549 {"TX DEC3 MUX", "SWR_MIC", "TX SMIC MUX3"},
1550 {"TX SMIC MUX3", NULL, "TX_SWR_CLK"},
1551 {"TX SMIC MUX3", "ADC0", "TX SWR_ADC0"},
1552 {"TX SMIC MUX3", "ADC1", "TX SWR_ADC1"},
1553 {"TX SMIC MUX3", "ADC2", "TX SWR_ADC2"},
1554 {"TX SMIC MUX3", "ADC3", "TX SWR_ADC3"},
1555 {"TX SMIC MUX3", "SWR_DMIC0", "TX SWR_DMIC0"},
1556 {"TX SMIC MUX3", "SWR_DMIC1", "TX SWR_DMIC1"},
1557 {"TX SMIC MUX3", "SWR_DMIC2", "TX SWR_DMIC2"},
1558 {"TX SMIC MUX3", "SWR_DMIC3", "TX SWR_DMIC3"},
1559 {"TX SMIC MUX3", "SWR_DMIC4", "TX SWR_DMIC4"},
1560 {"TX SMIC MUX3", "SWR_DMIC5", "TX SWR_DMIC5"},
1561 {"TX SMIC MUX3", "SWR_DMIC6", "TX SWR_DMIC6"},
1562 {"TX SMIC MUX3", "SWR_DMIC7", "TX SWR_DMIC7"},
1563
1564 {"TX DEC4 MUX", "SWR_MIC", "TX SMIC MUX4"},
1565 {"TX SMIC MUX4", NULL, "TX_SWR_CLK"},
1566 {"TX SMIC MUX4", "ADC0", "TX SWR_ADC0"},
1567 {"TX SMIC MUX4", "ADC1", "TX SWR_ADC1"},
1568 {"TX SMIC MUX4", "ADC2", "TX SWR_ADC2"},
1569 {"TX SMIC MUX4", "ADC3", "TX SWR_ADC3"},
1570 {"TX SMIC MUX4", "SWR_DMIC0", "TX SWR_DMIC0"},
1571 {"TX SMIC MUX4", "SWR_DMIC1", "TX SWR_DMIC1"},
1572 {"TX SMIC MUX4", "SWR_DMIC2", "TX SWR_DMIC2"},
1573 {"TX SMIC MUX4", "SWR_DMIC3", "TX SWR_DMIC3"},
1574 {"TX SMIC MUX4", "SWR_DMIC4", "TX SWR_DMIC4"},
1575 {"TX SMIC MUX4", "SWR_DMIC5", "TX SWR_DMIC5"},
1576 {"TX SMIC MUX4", "SWR_DMIC6", "TX SWR_DMIC6"},
1577 {"TX SMIC MUX4", "SWR_DMIC7", "TX SWR_DMIC7"},
1578
1579 {"TX DEC5 MUX", "SWR_MIC", "TX SMIC MUX5"},
1580 {"TX SMIC MUX5", NULL, "TX_SWR_CLK"},
1581 {"TX SMIC MUX5", "ADC0", "TX SWR_ADC0"},
1582 {"TX SMIC MUX5", "ADC1", "TX SWR_ADC1"},
1583 {"TX SMIC MUX5", "ADC2", "TX SWR_ADC2"},
1584 {"TX SMIC MUX5", "ADC3", "TX SWR_ADC3"},
1585 {"TX SMIC MUX5", "SWR_DMIC0", "TX SWR_DMIC0"},
1586 {"TX SMIC MUX5", "SWR_DMIC1", "TX SWR_DMIC1"},
1587 {"TX SMIC MUX5", "SWR_DMIC2", "TX SWR_DMIC2"},
1588 {"TX SMIC MUX5", "SWR_DMIC3", "TX SWR_DMIC3"},
1589 {"TX SMIC MUX5", "SWR_DMIC4", "TX SWR_DMIC4"},
1590 {"TX SMIC MUX5", "SWR_DMIC5", "TX SWR_DMIC5"},
1591 {"TX SMIC MUX5", "SWR_DMIC6", "TX SWR_DMIC6"},
1592 {"TX SMIC MUX5", "SWR_DMIC7", "TX SWR_DMIC7"},
1593
1594 {"TX DEC6 MUX", "SWR_MIC", "TX SMIC MUX6"},
1595 {"TX SMIC MUX6", NULL, "TX_SWR_CLK"},
1596 {"TX SMIC MUX6", "ADC0", "TX SWR_ADC0"},
1597 {"TX SMIC MUX6", "ADC1", "TX SWR_ADC1"},
1598 {"TX SMIC MUX6", "ADC2", "TX SWR_ADC2"},
1599 {"TX SMIC MUX6", "ADC3", "TX SWR_ADC3"},
1600 {"TX SMIC MUX6", "SWR_DMIC0", "TX SWR_DMIC0"},
1601 {"TX SMIC MUX6", "SWR_DMIC1", "TX SWR_DMIC1"},
1602 {"TX SMIC MUX6", "SWR_DMIC2", "TX SWR_DMIC2"},
1603 {"TX SMIC MUX6", "SWR_DMIC3", "TX SWR_DMIC3"},
1604 {"TX SMIC MUX6", "SWR_DMIC4", "TX SWR_DMIC4"},
1605 {"TX SMIC MUX6", "SWR_DMIC5", "TX SWR_DMIC5"},
1606 {"TX SMIC MUX6", "SWR_DMIC6", "TX SWR_DMIC6"},
1607 {"TX SMIC MUX6", "SWR_DMIC7", "TX SWR_DMIC7"},
1608
1609 {"TX DEC7 MUX", "SWR_MIC", "TX SMIC MUX7"},
1610 {"TX SMIC MUX7", NULL, "TX_SWR_CLK"},
1611 {"TX SMIC MUX7", "ADC0", "TX SWR_ADC0"},
1612 {"TX SMIC MUX7", "ADC1", "TX SWR_ADC1"},
1613 {"TX SMIC MUX7", "ADC2", "TX SWR_ADC2"},
1614 {"TX SMIC MUX7", "ADC3", "TX SWR_ADC3"},
1615 {"TX SMIC MUX7", "SWR_DMIC0", "TX SWR_DMIC0"},
1616 {"TX SMIC MUX7", "SWR_DMIC1", "TX SWR_DMIC1"},
1617 {"TX SMIC MUX7", "SWR_DMIC2", "TX SWR_DMIC2"},
1618 {"TX SMIC MUX7", "SWR_DMIC3", "TX SWR_DMIC3"},
1619 {"TX SMIC MUX7", "SWR_DMIC4", "TX SWR_DMIC4"},
1620 {"TX SMIC MUX7", "SWR_DMIC5", "TX SWR_DMIC5"},
1621 {"TX SMIC MUX7", "SWR_DMIC6", "TX SWR_DMIC6"},
1622 {"TX SMIC MUX7", "SWR_DMIC7", "TX SWR_DMIC7"},
1623 };
1624
1625 static const struct snd_kcontrol_new tx_macro_snd_controls[] = {
1626 SOC_SINGLE_S8_TLV("TX_DEC0 Volume",
1627 CDC_TX0_TX_VOL_CTL,
1628 -84, 40, digital_gain),
1629 SOC_SINGLE_S8_TLV("TX_DEC1 Volume",
1630 CDC_TX1_TX_VOL_CTL,
1631 -84, 40, digital_gain),
1632 SOC_SINGLE_S8_TLV("TX_DEC2 Volume",
1633 CDC_TX2_TX_VOL_CTL,
1634 -84, 40, digital_gain),
1635 SOC_SINGLE_S8_TLV("TX_DEC3 Volume",
1636 CDC_TX3_TX_VOL_CTL,
1637 -84, 40, digital_gain),
1638 SOC_SINGLE_S8_TLV("TX_DEC4 Volume",
1639 CDC_TX4_TX_VOL_CTL,
1640 -84, 40, digital_gain),
1641 SOC_SINGLE_S8_TLV("TX_DEC5 Volume",
1642 CDC_TX5_TX_VOL_CTL,
1643 -84, 40, digital_gain),
1644 SOC_SINGLE_S8_TLV("TX_DEC6 Volume",
1645 CDC_TX6_TX_VOL_CTL,
1646 -84, 40, digital_gain),
1647 SOC_SINGLE_S8_TLV("TX_DEC7 Volume",
1648 CDC_TX7_TX_VOL_CTL,
1649 -84, 40, digital_gain),
1650
1651 SOC_ENUM_EXT("DEC0 MODE", dec_mode_mux_enum[0],
1652 tx_macro_dec_mode_get, tx_macro_dec_mode_put),
1653
1654 SOC_ENUM_EXT("DEC1 MODE", dec_mode_mux_enum[1],
1655 tx_macro_dec_mode_get, tx_macro_dec_mode_put),
1656
1657 SOC_ENUM_EXT("DEC2 MODE", dec_mode_mux_enum[2],
1658 tx_macro_dec_mode_get, tx_macro_dec_mode_put),
1659
1660 SOC_ENUM_EXT("DEC3 MODE", dec_mode_mux_enum[3],
1661 tx_macro_dec_mode_get, tx_macro_dec_mode_put),
1662
1663 SOC_ENUM_EXT("DEC4 MODE", dec_mode_mux_enum[4],
1664 tx_macro_dec_mode_get, tx_macro_dec_mode_put),
1665
1666 SOC_ENUM_EXT("DEC5 MODE", dec_mode_mux_enum[5],
1667 tx_macro_dec_mode_get, tx_macro_dec_mode_put),
1668
1669 SOC_ENUM_EXT("DEC6 MODE", dec_mode_mux_enum[6],
1670 tx_macro_dec_mode_get, tx_macro_dec_mode_put),
1671
1672 SOC_ENUM_EXT("DEC7 MODE", dec_mode_mux_enum[7],
1673 tx_macro_dec_mode_get, tx_macro_dec_mode_put),
1674
1675 SOC_SINGLE_EXT("DEC0_BCS Switch", SND_SOC_NOPM, 0, 1, 0,
1676 tx_macro_get_bcs, tx_macro_set_bcs),
1677 };
1678
tx_macro_component_probe(struct snd_soc_component * comp)1679 static int tx_macro_component_probe(struct snd_soc_component *comp)
1680 {
1681 struct tx_macro *tx = snd_soc_component_get_drvdata(comp);
1682 int i;
1683
1684 snd_soc_component_init_regmap(comp, tx->regmap);
1685
1686 for (i = 0; i < NUM_DECIMATORS; i++) {
1687 tx->tx_hpf_work[i].tx = tx;
1688 tx->tx_hpf_work[i].decimator = i;
1689 INIT_DELAYED_WORK(&tx->tx_hpf_work[i].dwork,
1690 tx_macro_tx_hpf_corner_freq_callback);
1691 }
1692
1693 for (i = 0; i < NUM_DECIMATORS; i++) {
1694 tx->tx_mute_dwork[i].tx = tx;
1695 tx->tx_mute_dwork[i].decimator = i;
1696 INIT_DELAYED_WORK(&tx->tx_mute_dwork[i].dwork,
1697 tx_macro_mute_update_callback);
1698 }
1699 tx->component = comp;
1700
1701 snd_soc_component_update_bits(comp, CDC_TX0_TX_PATH_SEC7, 0x3F,
1702 0x0A);
1703 /* Enable swr mic0 and mic1 clock */
1704 snd_soc_component_update_bits(comp, CDC_TX_TOP_CSR_SWR_AMIC0_CTL, 0xFF, 0x00);
1705 snd_soc_component_update_bits(comp, CDC_TX_TOP_CSR_SWR_AMIC1_CTL, 0xFF, 0x00);
1706
1707 return 0;
1708 }
1709
swclk_gate_enable(struct clk_hw * hw)1710 static int swclk_gate_enable(struct clk_hw *hw)
1711 {
1712 struct tx_macro *tx = to_tx_macro(hw);
1713 struct regmap *regmap = tx->regmap;
1714 int ret;
1715
1716 ret = clk_prepare_enable(tx->mclk);
1717 if (ret) {
1718 dev_err(tx->dev, "failed to enable mclk\n");
1719 return ret;
1720 }
1721
1722 tx_macro_mclk_enable(tx, true);
1723 regmap_update_bits(regmap, CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
1724 CDC_TX_SWR_RESET_MASK, CDC_TX_SWR_RESET_ENABLE);
1725
1726 regmap_update_bits(regmap, CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
1727 CDC_TX_SWR_CLK_EN_MASK,
1728 CDC_TX_SWR_CLK_ENABLE);
1729 regmap_update_bits(regmap, CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
1730 CDC_TX_SWR_RESET_MASK, 0x0);
1731
1732 return 0;
1733 }
1734
swclk_gate_disable(struct clk_hw * hw)1735 static void swclk_gate_disable(struct clk_hw *hw)
1736 {
1737 struct tx_macro *tx = to_tx_macro(hw);
1738 struct regmap *regmap = tx->regmap;
1739
1740 regmap_update_bits(regmap, CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
1741 CDC_TX_SWR_CLK_EN_MASK, 0x0);
1742
1743 tx_macro_mclk_enable(tx, false);
1744 clk_disable_unprepare(tx->mclk);
1745 }
1746
swclk_gate_is_enabled(struct clk_hw * hw)1747 static int swclk_gate_is_enabled(struct clk_hw *hw)
1748 {
1749 struct tx_macro *tx = to_tx_macro(hw);
1750 int ret, val;
1751
1752 regmap_read(tx->regmap, CDC_TX_CLK_RST_CTRL_SWR_CONTROL, &val);
1753 ret = val & BIT(0);
1754
1755 return ret;
1756 }
1757
swclk_recalc_rate(struct clk_hw * hw,unsigned long parent_rate)1758 static unsigned long swclk_recalc_rate(struct clk_hw *hw,
1759 unsigned long parent_rate)
1760 {
1761 return parent_rate / 2;
1762 }
1763
1764 static const struct clk_ops swclk_gate_ops = {
1765 .prepare = swclk_gate_enable,
1766 .unprepare = swclk_gate_disable,
1767 .is_enabled = swclk_gate_is_enabled,
1768 .recalc_rate = swclk_recalc_rate,
1769
1770 };
1771
tx_macro_register_mclk_output(struct tx_macro * tx)1772 static int tx_macro_register_mclk_output(struct tx_macro *tx)
1773 {
1774 struct device *dev = tx->dev;
1775 const char *parent_clk_name = NULL;
1776 const char *clk_name = "lpass-tx-mclk";
1777 struct clk_hw *hw;
1778 struct clk_init_data init;
1779 int ret;
1780
1781 parent_clk_name = __clk_get_name(tx->npl);
1782
1783 init.name = clk_name;
1784 init.ops = &swclk_gate_ops;
1785 init.flags = 0;
1786 init.parent_names = &parent_clk_name;
1787 init.num_parents = 1;
1788 tx->hw.init = &init;
1789 hw = &tx->hw;
1790 ret = devm_clk_hw_register(dev, hw);
1791 if (ret)
1792 return ret;
1793
1794 return devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get, hw);
1795 }
1796
1797 static const struct snd_soc_component_driver tx_macro_component_drv = {
1798 .name = "RX-MACRO",
1799 .probe = tx_macro_component_probe,
1800 .controls = tx_macro_snd_controls,
1801 .num_controls = ARRAY_SIZE(tx_macro_snd_controls),
1802 .dapm_widgets = tx_macro_dapm_widgets,
1803 .num_dapm_widgets = ARRAY_SIZE(tx_macro_dapm_widgets),
1804 .dapm_routes = tx_audio_map,
1805 .num_dapm_routes = ARRAY_SIZE(tx_audio_map),
1806 };
1807
tx_macro_probe(struct platform_device * pdev)1808 static int tx_macro_probe(struct platform_device *pdev)
1809 {
1810 struct device *dev = &pdev->dev;
1811 struct device_node *np = dev->of_node;
1812 struct tx_macro *tx;
1813 void __iomem *base;
1814 int ret, reg;
1815
1816 tx = devm_kzalloc(dev, sizeof(*tx), GFP_KERNEL);
1817 if (!tx)
1818 return -ENOMEM;
1819
1820 tx->macro = devm_clk_get_optional(dev, "macro");
1821 if (IS_ERR(tx->macro))
1822 return PTR_ERR(tx->macro);
1823
1824 tx->dcodec = devm_clk_get_optional(dev, "dcodec");
1825 if (IS_ERR(tx->dcodec))
1826 return PTR_ERR(tx->dcodec);
1827
1828 tx->mclk = devm_clk_get(dev, "mclk");
1829 if (IS_ERR(tx->mclk))
1830 return PTR_ERR(tx->mclk);
1831
1832 tx->npl = devm_clk_get(dev, "npl");
1833 if (IS_ERR(tx->npl))
1834 return PTR_ERR(tx->npl);
1835
1836 tx->fsgen = devm_clk_get(dev, "fsgen");
1837 if (IS_ERR(tx->fsgen))
1838 return PTR_ERR(tx->fsgen);
1839
1840 tx->pds = lpass_macro_pds_init(dev);
1841 if (IS_ERR(tx->pds))
1842 return PTR_ERR(tx->pds);
1843
1844 base = devm_platform_ioremap_resource(pdev, 0);
1845 if (IS_ERR(base)) {
1846 ret = PTR_ERR(base);
1847 goto err;
1848 }
1849
1850 /* Update defaults for lpass sc7280 */
1851 if (of_device_is_compatible(np, "qcom,sc7280-lpass-tx-macro")) {
1852 for (reg = 0; reg < ARRAY_SIZE(tx_defaults); reg++) {
1853 switch (tx_defaults[reg].reg) {
1854 case CDC_TX_TOP_CSR_SWR_AMIC0_CTL:
1855 case CDC_TX_TOP_CSR_SWR_AMIC1_CTL:
1856 tx_defaults[reg].def = 0x0E;
1857 break;
1858 default:
1859 break;
1860 }
1861 }
1862 }
1863
1864 tx->regmap = devm_regmap_init_mmio(dev, base, &tx_regmap_config);
1865 if (IS_ERR(tx->regmap)) {
1866 ret = PTR_ERR(tx->regmap);
1867 goto err;
1868 }
1869
1870 dev_set_drvdata(dev, tx);
1871
1872 tx->dev = dev;
1873
1874 /* Set active_decimator default value */
1875 tx->active_decimator[TX_MACRO_AIF1_CAP] = -1;
1876 tx->active_decimator[TX_MACRO_AIF2_CAP] = -1;
1877 tx->active_decimator[TX_MACRO_AIF3_CAP] = -1;
1878
1879 /* set MCLK and NPL rates */
1880 clk_set_rate(tx->mclk, MCLK_FREQ);
1881 clk_set_rate(tx->npl, MCLK_FREQ);
1882
1883 ret = clk_prepare_enable(tx->macro);
1884 if (ret)
1885 goto err;
1886
1887 ret = clk_prepare_enable(tx->dcodec);
1888 if (ret)
1889 goto err_dcodec;
1890
1891 ret = clk_prepare_enable(tx->mclk);
1892 if (ret)
1893 goto err_mclk;
1894
1895 ret = clk_prepare_enable(tx->npl);
1896 if (ret)
1897 goto err_npl;
1898
1899 ret = clk_prepare_enable(tx->fsgen);
1900 if (ret)
1901 goto err_fsgen;
1902
1903 ret = devm_snd_soc_register_component(dev, &tx_macro_component_drv,
1904 tx_macro_dai,
1905 ARRAY_SIZE(tx_macro_dai));
1906 if (ret)
1907 goto err_clkout;
1908
1909 pm_runtime_set_autosuspend_delay(dev, 3000);
1910 pm_runtime_use_autosuspend(dev);
1911 pm_runtime_mark_last_busy(dev);
1912 pm_runtime_set_active(dev);
1913 pm_runtime_enable(dev);
1914
1915 ret = tx_macro_register_mclk_output(tx);
1916 if (ret)
1917 goto err_clkout;
1918
1919 return 0;
1920
1921 err_clkout:
1922 clk_disable_unprepare(tx->fsgen);
1923 err_fsgen:
1924 clk_disable_unprepare(tx->npl);
1925 err_npl:
1926 clk_disable_unprepare(tx->mclk);
1927 err_mclk:
1928 clk_disable_unprepare(tx->dcodec);
1929 err_dcodec:
1930 clk_disable_unprepare(tx->macro);
1931 err:
1932 lpass_macro_pds_exit(tx->pds);
1933
1934 return ret;
1935 }
1936
tx_macro_remove(struct platform_device * pdev)1937 static int tx_macro_remove(struct platform_device *pdev)
1938 {
1939 struct tx_macro *tx = dev_get_drvdata(&pdev->dev);
1940
1941 clk_disable_unprepare(tx->macro);
1942 clk_disable_unprepare(tx->dcodec);
1943 clk_disable_unprepare(tx->mclk);
1944 clk_disable_unprepare(tx->npl);
1945 clk_disable_unprepare(tx->fsgen);
1946
1947 lpass_macro_pds_exit(tx->pds);
1948
1949 return 0;
1950 }
1951
tx_macro_runtime_suspend(struct device * dev)1952 static int __maybe_unused tx_macro_runtime_suspend(struct device *dev)
1953 {
1954 struct tx_macro *tx = dev_get_drvdata(dev);
1955
1956 regcache_cache_only(tx->regmap, true);
1957 regcache_mark_dirty(tx->regmap);
1958
1959 clk_disable_unprepare(tx->fsgen);
1960 clk_disable_unprepare(tx->npl);
1961 clk_disable_unprepare(tx->mclk);
1962
1963 return 0;
1964 }
1965
tx_macro_runtime_resume(struct device * dev)1966 static int __maybe_unused tx_macro_runtime_resume(struct device *dev)
1967 {
1968 struct tx_macro *tx = dev_get_drvdata(dev);
1969 int ret;
1970
1971 ret = clk_prepare_enable(tx->mclk);
1972 if (ret) {
1973 dev_err(dev, "unable to prepare mclk\n");
1974 return ret;
1975 }
1976
1977 ret = clk_prepare_enable(tx->npl);
1978 if (ret) {
1979 dev_err(dev, "unable to prepare npl\n");
1980 goto err_npl;
1981 }
1982
1983 ret = clk_prepare_enable(tx->fsgen);
1984 if (ret) {
1985 dev_err(dev, "unable to prepare fsgen\n");
1986 goto err_fsgen;
1987 }
1988
1989 regcache_cache_only(tx->regmap, false);
1990 regcache_sync(tx->regmap);
1991
1992 return 0;
1993 err_fsgen:
1994 clk_disable_unprepare(tx->npl);
1995 err_npl:
1996 clk_disable_unprepare(tx->mclk);
1997
1998 return ret;
1999 }
2000
2001 static const struct dev_pm_ops tx_macro_pm_ops = {
2002 SET_RUNTIME_PM_OPS(tx_macro_runtime_suspend, tx_macro_runtime_resume, NULL)
2003 };
2004
2005 static const struct of_device_id tx_macro_dt_match[] = {
2006 { .compatible = "qcom,sc7280-lpass-tx-macro" },
2007 { .compatible = "qcom,sm8250-lpass-tx-macro" },
2008 { .compatible = "qcom,sm8450-lpass-tx-macro" },
2009 { .compatible = "qcom,sc8280xp-lpass-tx-macro" },
2010 { }
2011 };
2012 MODULE_DEVICE_TABLE(of, tx_macro_dt_match);
2013 static struct platform_driver tx_macro_driver = {
2014 .driver = {
2015 .name = "tx_macro",
2016 .of_match_table = tx_macro_dt_match,
2017 .suppress_bind_attrs = true,
2018 .pm = &tx_macro_pm_ops,
2019 },
2020 .probe = tx_macro_probe,
2021 .remove = tx_macro_remove,
2022 };
2023
2024 module_platform_driver(tx_macro_driver);
2025
2026 MODULE_DESCRIPTION("TX macro driver");
2027 MODULE_LICENSE("GPL");
2028