xref: /linux/sound/soc/codecs/lpass-wsa-macro.c (revision 32daa5d7899e03433429bedf9e20d7963179703a)
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/io.h>
7 #include <linux/platform_device.h>
8 #include <linux/clk.h>
9 #include <linux/of_clk.h>
10 #include <linux/clk-provider.h>
11 #include <sound/soc.h>
12 #include <sound/soc-dapm.h>
13 #include <linux/of_platform.h>
14 #include <sound/tlv.h>
15 #include "lpass-wsa-macro.h"
16 
17 #define CDC_WSA_CLK_RST_CTRL_MCLK_CONTROL	(0x0000)
18 #define CDC_WSA_MCLK_EN_MASK			BIT(0)
19 #define CDC_WSA_MCLK_ENABLE			BIT(0)
20 #define CDC_WSA_MCLK_DISABLE			0
21 #define CDC_WSA_CLK_RST_CTRL_FS_CNT_CONTROL	(0x0004)
22 #define CDC_WSA_FS_CNT_EN_MASK			BIT(0)
23 #define CDC_WSA_FS_CNT_ENABLE			BIT(0)
24 #define CDC_WSA_FS_CNT_DISABLE			0
25 #define CDC_WSA_CLK_RST_CTRL_SWR_CONTROL	(0x0008)
26 #define CDC_WSA_SWR_CLK_EN_MASK			BIT(0)
27 #define CDC_WSA_SWR_CLK_ENABLE			BIT(0)
28 #define CDC_WSA_SWR_RST_EN_MASK			BIT(1)
29 #define CDC_WSA_SWR_RST_ENABLE			BIT(1)
30 #define CDC_WSA_SWR_RST_DISABLE			0
31 #define CDC_WSA_TOP_TOP_CFG0			(0x0080)
32 #define CDC_WSA_TOP_TOP_CFG1			(0x0084)
33 #define CDC_WSA_TOP_FREQ_MCLK			(0x0088)
34 #define CDC_WSA_TOP_DEBUG_BUS_SEL		(0x008C)
35 #define CDC_WSA_TOP_DEBUG_EN0			(0x0090)
36 #define CDC_WSA_TOP_DEBUG_EN1			(0x0094)
37 #define CDC_WSA_TOP_DEBUG_DSM_LB		(0x0098)
38 #define CDC_WSA_TOP_RX_I2S_CTL			(0x009C)
39 #define CDC_WSA_TOP_TX_I2S_CTL			(0x00A0)
40 #define CDC_WSA_TOP_I2S_CLK			(0x00A4)
41 #define CDC_WSA_TOP_I2S_RESET			(0x00A8)
42 #define CDC_WSA_RX_INP_MUX_RX_INT0_CFG0		(0x0100)
43 #define CDC_WSA_RX_INTX_1_MIX_INP0_SEL_MASK	GENMASK(2, 0)
44 #define CDC_WSA_RX_INTX_1_MIX_INP1_SEL_MASK	GENMASK(5, 3)
45 #define CDC_WSA_RX_INP_MUX_RX_INT0_CFG1		(0x0104)
46 #define CDC_WSA_RX_INTX_2_SEL_MASK		GENMASK(2, 0)
47 #define CDC_WSA_RX_INTX_1_MIX_INP2_SEL_MASK	GENMASK(5, 3)
48 #define CDC_WSA_RX_INP_MUX_RX_INT1_CFG0		(0x0108)
49 #define CDC_WSA_RX_INP_MUX_RX_INT1_CFG1		(0x010C)
50 #define CDC_WSA_RX_INP_MUX_RX_MIX_CFG0		(0x0110)
51 #define CDC_WSA_RX_MIX_TX1_SEL_MASK		GENMASK(5, 3)
52 #define CDC_WSA_RX_MIX_TX1_SEL_SHFT		3
53 #define CDC_WSA_RX_MIX_TX0_SEL_MASK		GENMASK(2, 0)
54 #define CDC_WSA_RX_INP_MUX_RX_EC_CFG0		(0x0114)
55 #define CDC_WSA_RX_INP_MUX_SOFTCLIP_CFG0	(0x0118)
56 #define CDC_WSA_TX0_SPKR_PROT_PATH_CTL		(0x0244)
57 #define CDC_WSA_TX_SPKR_PROT_RESET_MASK		BIT(5)
58 #define CDC_WSA_TX_SPKR_PROT_RESET		BIT(5)
59 #define CDC_WSA_TX_SPKR_PROT_NO_RESET		0
60 #define CDC_WSA_TX_SPKR_PROT_CLK_EN_MASK	BIT(4)
61 #define CDC_WSA_TX_SPKR_PROT_CLK_ENABLE		BIT(4)
62 #define CDC_WSA_TX_SPKR_PROT_CLK_DISABLE	0
63 #define CDC_WSA_TX_SPKR_PROT_PCM_RATE_MASK	GENMASK(3, 0)
64 #define CDC_WSA_TX_SPKR_PROT_PCM_RATE_8K	0
65 #define CDC_WSA_TX0_SPKR_PROT_PATH_CFG0		(0x0248)
66 #define CDC_WSA_TX1_SPKR_PROT_PATH_CTL		(0x0264)
67 #define CDC_WSA_TX1_SPKR_PROT_PATH_CFG0		(0x0268)
68 #define CDC_WSA_TX2_SPKR_PROT_PATH_CTL		(0x0284)
69 #define CDC_WSA_TX2_SPKR_PROT_PATH_CFG0		(0x0288)
70 #define CDC_WSA_TX3_SPKR_PROT_PATH_CTL		(0x02A4)
71 #define CDC_WSA_TX3_SPKR_PROT_PATH_CFG0		(0x02A8)
72 #define CDC_WSA_INTR_CTRL_CFG			(0x0340)
73 #define CDC_WSA_INTR_CTRL_CLR_COMMIT		(0x0344)
74 #define CDC_WSA_INTR_CTRL_PIN1_MASK0		(0x0360)
75 #define CDC_WSA_INTR_CTRL_PIN1_STATUS0		(0x0368)
76 #define CDC_WSA_INTR_CTRL_PIN1_CLEAR0		(0x0370)
77 #define CDC_WSA_INTR_CTRL_PIN2_MASK0		(0x0380)
78 #define CDC_WSA_INTR_CTRL_PIN2_STATUS0		(0x0388)
79 #define CDC_WSA_INTR_CTRL_PIN2_CLEAR0		(0x0390)
80 #define CDC_WSA_INTR_CTRL_LEVEL0		(0x03C0)
81 #define CDC_WSA_INTR_CTRL_BYPASS0		(0x03C8)
82 #define CDC_WSA_INTR_CTRL_SET0			(0x03D0)
83 #define CDC_WSA_RX0_RX_PATH_CTL			(0x0400)
84 #define CDC_WSA_RX_PATH_CLK_EN_MASK		BIT(5)
85 #define CDC_WSA_RX_PATH_CLK_ENABLE		BIT(5)
86 #define CDC_WSA_RX_PATH_CLK_DISABLE		0
87 #define CDC_WSA_RX_PATH_PGA_MUTE_EN_MASK	BIT(4)
88 #define CDC_WSA_RX_PATH_PGA_MUTE_ENABLE		BIT(4)
89 #define CDC_WSA_RX_PATH_PGA_MUTE_DISABLE	0
90 #define CDC_WSA_RX0_RX_PATH_CFG0		(0x0404)
91 #define CDC_WSA_RX_PATH_COMP_EN_MASK		BIT(1)
92 #define CDC_WSA_RX_PATH_COMP_ENABLE		BIT(1)
93 #define CDC_WSA_RX_PATH_HD2_EN_MASK		BIT(2)
94 #define CDC_WSA_RX_PATH_HD2_ENABLE		BIT(2)
95 #define CDC_WSA_RX_PATH_SPKR_RATE_MASK		BIT(3)
96 #define CDC_WSA_RX_PATH_SPKR_RATE_FS_2P4_3P072	BIT(3)
97 #define CDC_WSA_RX0_RX_PATH_CFG1		(0x0408)
98 #define CDC_WSA_RX_PATH_SMART_BST_EN_MASK	BIT(0)
99 #define CDC_WSA_RX_PATH_SMART_BST_ENABLE	BIT(0)
100 #define CDC_WSA_RX_PATH_SMART_BST_DISABLE	0
101 #define CDC_WSA_RX0_RX_PATH_CFG2		(0x040C)
102 #define CDC_WSA_RX0_RX_PATH_CFG3		(0x0410)
103 #define CDC_WSA_RX_DC_DCOEFF_MASK		GENMASK(1, 0)
104 #define CDC_WSA_RX0_RX_VOL_CTL			(0x0414)
105 #define CDC_WSA_RX0_RX_PATH_MIX_CTL		(0x0418)
106 #define CDC_WSA_RX_PATH_MIX_CLK_EN_MASK		BIT(5)
107 #define CDC_WSA_RX_PATH_MIX_CLK_ENABLE		BIT(5)
108 #define CDC_WSA_RX_PATH_MIX_CLK_DISABLE		0
109 #define CDC_WSA_RX0_RX_PATH_MIX_CFG		(0x041C)
110 #define CDC_WSA_RX0_RX_VOL_MIX_CTL		(0x0420)
111 #define CDC_WSA_RX0_RX_PATH_SEC0		(0x0424)
112 #define CDC_WSA_RX0_RX_PATH_SEC1		(0x0428)
113 #define CDC_WSA_RX_PGA_HALF_DB_MASK		BIT(0)
114 #define CDC_WSA_RX_PGA_HALF_DB_ENABLE		BIT(0)
115 #define CDC_WSA_RX_PGA_HALF_DB_DISABLE		0
116 #define CDC_WSA_RX0_RX_PATH_SEC2		(0x042C)
117 #define CDC_WSA_RX0_RX_PATH_SEC3		(0x0430)
118 #define CDC_WSA_RX_PATH_HD2_SCALE_MASK		GENMASK(1, 0)
119 #define CDC_WSA_RX_PATH_HD2_ALPHA_MASK		GENMASK(5, 2)
120 #define CDC_WSA_RX0_RX_PATH_SEC5		(0x0438)
121 #define CDC_WSA_RX0_RX_PATH_SEC6		(0x043C)
122 #define CDC_WSA_RX0_RX_PATH_SEC7		(0x0440)
123 #define CDC_WSA_RX0_RX_PATH_MIX_SEC0		(0x0444)
124 #define CDC_WSA_RX0_RX_PATH_MIX_SEC1		(0x0448)
125 #define CDC_WSA_RX0_RX_PATH_DSMDEM_CTL		(0x044C)
126 #define CDC_WSA_RX_DSMDEM_CLK_EN_MASK		BIT(0)
127 #define CDC_WSA_RX_DSMDEM_CLK_ENABLE		BIT(0)
128 #define CDC_WSA_RX1_RX_PATH_CTL			(0x0480)
129 #define CDC_WSA_RX1_RX_PATH_CFG0		(0x0484)
130 #define CDC_WSA_RX1_RX_PATH_CFG1		(0x0488)
131 #define CDC_WSA_RX1_RX_PATH_CFG2		(0x048C)
132 #define CDC_WSA_RX1_RX_PATH_CFG3		(0x0490)
133 #define CDC_WSA_RX1_RX_VOL_CTL			(0x0494)
134 #define CDC_WSA_RX1_RX_PATH_MIX_CTL		(0x0498)
135 #define CDC_WSA_RX1_RX_PATH_MIX_CFG		(0x049C)
136 #define CDC_WSA_RX1_RX_VOL_MIX_CTL		(0x04A0)
137 #define CDC_WSA_RX1_RX_PATH_SEC0		(0x04A4)
138 #define CDC_WSA_RX1_RX_PATH_SEC1		(0x04A8)
139 #define CDC_WSA_RX1_RX_PATH_SEC2		(0x04AC)
140 #define CDC_WSA_RX1_RX_PATH_SEC3		(0x04B0)
141 #define CDC_WSA_RX1_RX_PATH_SEC5		(0x04B8)
142 #define CDC_WSA_RX1_RX_PATH_SEC6		(0x04BC)
143 #define CDC_WSA_RX1_RX_PATH_SEC7		(0x04C0)
144 #define CDC_WSA_RX1_RX_PATH_MIX_SEC0		(0x04C4)
145 #define CDC_WSA_RX1_RX_PATH_MIX_SEC1		(0x04C8)
146 #define CDC_WSA_RX1_RX_PATH_DSMDEM_CTL		(0x04CC)
147 #define CDC_WSA_BOOST0_BOOST_PATH_CTL		(0x0500)
148 #define CDC_WSA_BOOST_PATH_CLK_EN_MASK		BIT(4)
149 #define CDC_WSA_BOOST_PATH_CLK_ENABLE		BIT(4)
150 #define CDC_WSA_BOOST_PATH_CLK_DISABLE		0
151 #define CDC_WSA_BOOST0_BOOST_CTL		(0x0504)
152 #define CDC_WSA_BOOST0_BOOST_CFG1		(0x0508)
153 #define CDC_WSA_BOOST0_BOOST_CFG2		(0x050C)
154 #define CDC_WSA_BOOST1_BOOST_PATH_CTL		(0x0540)
155 #define CDC_WSA_BOOST1_BOOST_CTL		(0x0544)
156 #define CDC_WSA_BOOST1_BOOST_CFG1		(0x0548)
157 #define CDC_WSA_BOOST1_BOOST_CFG2		(0x054C)
158 #define CDC_WSA_COMPANDER0_CTL0			(0x0580)
159 #define CDC_WSA_COMPANDER_CLK_EN_MASK		BIT(0)
160 #define CDC_WSA_COMPANDER_CLK_ENABLE		BIT(0)
161 #define CDC_WSA_COMPANDER_SOFT_RST_MASK		BIT(1)
162 #define CDC_WSA_COMPANDER_SOFT_RST_ENABLE	BIT(1)
163 #define CDC_WSA_COMPANDER_HALT_MASK		BIT(2)
164 #define CDC_WSA_COMPANDER_HALT			BIT(2)
165 #define CDC_WSA_COMPANDER0_CTL1			(0x0584)
166 #define CDC_WSA_COMPANDER0_CTL2			(0x0588)
167 #define CDC_WSA_COMPANDER0_CTL3			(0x058C)
168 #define CDC_WSA_COMPANDER0_CTL4			(0x0590)
169 #define CDC_WSA_COMPANDER0_CTL5			(0x0594)
170 #define CDC_WSA_COMPANDER0_CTL6			(0x0598)
171 #define CDC_WSA_COMPANDER0_CTL7			(0x059C)
172 #define CDC_WSA_COMPANDER1_CTL0			(0x05C0)
173 #define CDC_WSA_COMPANDER1_CTL1			(0x05C4)
174 #define CDC_WSA_COMPANDER1_CTL2			(0x05C8)
175 #define CDC_WSA_COMPANDER1_CTL3			(0x05CC)
176 #define CDC_WSA_COMPANDER1_CTL4			(0x05D0)
177 #define CDC_WSA_COMPANDER1_CTL5			(0x05D4)
178 #define CDC_WSA_COMPANDER1_CTL6			(0x05D8)
179 #define CDC_WSA_COMPANDER1_CTL7			(0x05DC)
180 #define CDC_WSA_SOFTCLIP0_CRC			(0x0600)
181 #define CDC_WSA_SOFTCLIP_CLK_EN_MASK		BIT(0)
182 #define CDC_WSA_SOFTCLIP_CLK_ENABLE		BIT(0)
183 #define CDC_WSA_SOFTCLIP0_SOFTCLIP_CTRL		(0x0604)
184 #define CDC_WSA_SOFTCLIP_EN_MASK		BIT(0)
185 #define CDC_WSA_SOFTCLIP_ENABLE			BIT(0)
186 #define CDC_WSA_SOFTCLIP1_CRC			(0x0640)
187 #define CDC_WSA_SOFTCLIP1_SOFTCLIP_CTRL		(0x0644)
188 #define CDC_WSA_EC_HQ0_EC_REF_HQ_PATH_CTL	(0x0680)
189 #define CDC_WSA_EC_HQ_EC_CLK_EN_MASK		BIT(0)
190 #define CDC_WSA_EC_HQ_EC_CLK_ENABLE		BIT(0)
191 #define CDC_WSA_EC_HQ0_EC_REF_HQ_CFG0		(0x0684)
192 #define CDC_WSA_EC_HQ_EC_REF_PCM_RATE_MASK	GENMASK(4, 1)
193 #define CDC_WSA_EC_HQ_EC_REF_PCM_RATE_48K	BIT(3)
194 #define CDC_WSA_EC_HQ1_EC_REF_HQ_PATH_CTL	(0x06C0)
195 #define CDC_WSA_EC_HQ1_EC_REF_HQ_CFG0		(0x06C4)
196 #define CDC_WSA_SPLINE_ASRC0_CLK_RST_CTL	(0x0700)
197 #define CDC_WSA_SPLINE_ASRC0_CTL0		(0x0704)
198 #define CDC_WSA_SPLINE_ASRC0_CTL1		(0x0708)
199 #define CDC_WSA_SPLINE_ASRC0_FIFO_CTL		(0x070C)
200 #define CDC_WSA_SPLINE_ASRC0_STATUS_FMIN_CNTR_LSB	(0x0710)
201 #define CDC_WSA_SPLINE_ASRC0_STATUS_FMIN_CNTR_MSB	(0x0714)
202 #define CDC_WSA_SPLINE_ASRC0_STATUS_FMAX_CNTR_LSB	(0x0718)
203 #define CDC_WSA_SPLINE_ASRC0_STATUS_FMAX_CNTR_MSB	(0x071C)
204 #define CDC_WSA_SPLINE_ASRC0_STATUS_FIFO		(0x0720)
205 #define CDC_WSA_SPLINE_ASRC1_CLK_RST_CTL		(0x0740)
206 #define CDC_WSA_SPLINE_ASRC1_CTL0		(0x0744)
207 #define CDC_WSA_SPLINE_ASRC1_CTL1		(0x0748)
208 #define CDC_WSA_SPLINE_ASRC1_FIFO_CTL		(0x074C)
209 #define CDC_WSA_SPLINE_ASRC1_STATUS_FMIN_CNTR_LSB (0x0750)
210 #define CDC_WSA_SPLINE_ASRC1_STATUS_FMIN_CNTR_MSB (0x0754)
211 #define CDC_WSA_SPLINE_ASRC1_STATUS_FMAX_CNTR_LSB (0x0758)
212 #define CDC_WSA_SPLINE_ASRC1_STATUS_FMAX_CNTR_MSB (0x075C)
213 #define CDC_WSA_SPLINE_ASRC1_STATUS_FIFO	(0x0760)
214 #define WSA_MAX_OFFSET				(0x0760)
215 
216 #define WSA_MACRO_RX_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
217 			SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\
218 			SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000)
219 #define WSA_MACRO_RX_MIX_RATES (SNDRV_PCM_RATE_48000 |\
220 			SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000)
221 #define WSA_MACRO_RX_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
222 		SNDRV_PCM_FMTBIT_S24_LE |\
223 		SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
224 
225 #define WSA_MACRO_ECHO_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
226 			SNDRV_PCM_RATE_48000)
227 #define WSA_MACRO_ECHO_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
228 		SNDRV_PCM_FMTBIT_S24_LE |\
229 		SNDRV_PCM_FMTBIT_S24_3LE)
230 
231 #define NUM_INTERPOLATORS 2
232 #define WSA_NUM_CLKS_MAX	5
233 #define WSA_MACRO_MCLK_FREQ 19200000
234 #define WSA_MACRO_MUX_INP_MASK2 0x38
235 #define WSA_MACRO_MUX_CFG_OFFSET 0x8
236 #define WSA_MACRO_MUX_CFG1_OFFSET 0x4
237 #define WSA_MACRO_RX_COMP_OFFSET 0x40
238 #define WSA_MACRO_RX_SOFTCLIP_OFFSET 0x40
239 #define WSA_MACRO_RX_PATH_OFFSET 0x80
240 #define WSA_MACRO_RX_PATH_CFG3_OFFSET 0x10
241 #define WSA_MACRO_RX_PATH_DSMDEM_OFFSET 0x4C
242 #define WSA_MACRO_FS_RATE_MASK 0x0F
243 #define WSA_MACRO_EC_MIX_TX0_MASK 0x03
244 #define WSA_MACRO_EC_MIX_TX1_MASK 0x18
245 #define WSA_MACRO_MAX_DMA_CH_PER_PORT 0x2
246 
247 enum {
248 	WSA_MACRO_GAIN_OFFSET_M1P5_DB,
249 	WSA_MACRO_GAIN_OFFSET_0_DB,
250 };
251 enum {
252 	WSA_MACRO_RX0 = 0,
253 	WSA_MACRO_RX1,
254 	WSA_MACRO_RX_MIX,
255 	WSA_MACRO_RX_MIX0 = WSA_MACRO_RX_MIX,
256 	WSA_MACRO_RX_MIX1,
257 	WSA_MACRO_RX_MAX,
258 };
259 
260 enum {
261 	WSA_MACRO_TX0 = 0,
262 	WSA_MACRO_TX1,
263 	WSA_MACRO_TX_MAX,
264 };
265 
266 enum {
267 	WSA_MACRO_EC0_MUX = 0,
268 	WSA_MACRO_EC1_MUX,
269 	WSA_MACRO_EC_MUX_MAX,
270 };
271 
272 enum {
273 	WSA_MACRO_COMP1, /* SPK_L */
274 	WSA_MACRO_COMP2, /* SPK_R */
275 	WSA_MACRO_COMP_MAX
276 };
277 
278 enum {
279 	WSA_MACRO_SOFTCLIP0, /* RX0 */
280 	WSA_MACRO_SOFTCLIP1, /* RX1 */
281 	WSA_MACRO_SOFTCLIP_MAX
282 };
283 
284 enum {
285 	INTn_1_INP_SEL_ZERO = 0,
286 	INTn_1_INP_SEL_RX0,
287 	INTn_1_INP_SEL_RX1,
288 	INTn_1_INP_SEL_RX2,
289 	INTn_1_INP_SEL_RX3,
290 	INTn_1_INP_SEL_DEC0,
291 	INTn_1_INP_SEL_DEC1,
292 };
293 
294 enum {
295 	INTn_2_INP_SEL_ZERO = 0,
296 	INTn_2_INP_SEL_RX0,
297 	INTn_2_INP_SEL_RX1,
298 	INTn_2_INP_SEL_RX2,
299 	INTn_2_INP_SEL_RX3,
300 };
301 
302 struct interp_sample_rate {
303 	int sample_rate;
304 	int rate_val;
305 };
306 
307 static struct interp_sample_rate int_prim_sample_rate_val[] = {
308 	{8000, 0x0},	/* 8K */
309 	{16000, 0x1},	/* 16K */
310 	{24000, -EINVAL},/* 24K */
311 	{32000, 0x3},	/* 32K */
312 	{48000, 0x4},	/* 48K */
313 	{96000, 0x5},	/* 96K */
314 	{192000, 0x6},	/* 192K */
315 	{384000, 0x7},	/* 384K */
316 	{44100, 0x8}, /* 44.1K */
317 };
318 
319 static struct interp_sample_rate int_mix_sample_rate_val[] = {
320 	{48000, 0x4},	/* 48K */
321 	{96000, 0x5},	/* 96K */
322 	{192000, 0x6},	/* 192K */
323 };
324 
325 enum {
326 	WSA_MACRO_AIF_INVALID = 0,
327 	WSA_MACRO_AIF1_PB,
328 	WSA_MACRO_AIF_MIX1_PB,
329 	WSA_MACRO_AIF_VI,
330 	WSA_MACRO_AIF_ECHO,
331 	WSA_MACRO_MAX_DAIS,
332 };
333 
334 struct wsa_macro {
335 	struct device *dev;
336 	int comp_enabled[WSA_MACRO_COMP_MAX];
337 	int ec_hq[WSA_MACRO_RX1 + 1];
338 	u16 prim_int_users[WSA_MACRO_RX1 + 1];
339 	u16 wsa_mclk_users;
340 	bool reset_swr;
341 	unsigned long active_ch_mask[WSA_MACRO_MAX_DAIS];
342 	unsigned long active_ch_cnt[WSA_MACRO_MAX_DAIS];
343 	int rx_port_value[WSA_MACRO_RX_MAX];
344 	int ear_spkr_gain;
345 	int spkr_gain_offset;
346 	int spkr_mode;
347 	int is_softclip_on[WSA_MACRO_SOFTCLIP_MAX];
348 	int softclip_clk_users[WSA_MACRO_SOFTCLIP_MAX];
349 	struct regmap *regmap;
350 	struct clk_bulk_data clks[WSA_NUM_CLKS_MAX];
351 	struct clk_hw hw;
352 };
353 #define to_wsa_macro(_hw) container_of(_hw, struct wsa_macro, hw)
354 
355 static const DECLARE_TLV_DB_SCALE(digital_gain, -8400, 100, -8400);
356 
357 static const char *const rx_text[] = {
358 	"ZERO", "RX0", "RX1", "RX_MIX0", "RX_MIX1", "DEC0", "DEC1"
359 };
360 
361 static const char *const rx_mix_text[] = {
362 	"ZERO", "RX0", "RX1", "RX_MIX0", "RX_MIX1"
363 };
364 
365 static const char *const rx_mix_ec_text[] = {
366 	"ZERO", "RX_MIX_TX0", "RX_MIX_TX1"
367 };
368 
369 static const char *const rx_mux_text[] = {
370 	"ZERO", "AIF1_PB", "AIF_MIX1_PB"
371 };
372 
373 static const char *const rx_sidetone_mix_text[] = {
374 	"ZERO", "SRC0"
375 };
376 
377 static const char * const wsa_macro_ear_spkr_pa_gain_text[] = {
378 	"G_DEFAULT", "G_0_DB", "G_1_DB", "G_2_DB", "G_3_DB",
379 	"G_4_DB", "G_5_DB", "G_6_DB"
380 };
381 
382 static SOC_ENUM_SINGLE_EXT_DECL(wsa_macro_ear_spkr_pa_gain_enum,
383 				wsa_macro_ear_spkr_pa_gain_text);
384 
385 /* RX INT0 */
386 static const struct soc_enum rx0_prim_inp0_chain_enum =
387 	SOC_ENUM_SINGLE(CDC_WSA_RX_INP_MUX_RX_INT0_CFG0,
388 		0, 7, rx_text);
389 
390 static const struct soc_enum rx0_prim_inp1_chain_enum =
391 	SOC_ENUM_SINGLE(CDC_WSA_RX_INP_MUX_RX_INT0_CFG0,
392 		3, 7, rx_text);
393 
394 static const struct soc_enum rx0_prim_inp2_chain_enum =
395 	SOC_ENUM_SINGLE(CDC_WSA_RX_INP_MUX_RX_INT0_CFG1,
396 		3, 7, rx_text);
397 
398 static const struct soc_enum rx0_mix_chain_enum =
399 	SOC_ENUM_SINGLE(CDC_WSA_RX_INP_MUX_RX_INT0_CFG1,
400 		0, 5, rx_mix_text);
401 
402 static const struct soc_enum rx0_sidetone_mix_enum =
403 	SOC_ENUM_SINGLE(SND_SOC_NOPM, 0, 2, rx_sidetone_mix_text);
404 
405 static const struct snd_kcontrol_new rx0_prim_inp0_mux =
406 	SOC_DAPM_ENUM("WSA_RX0 INP0 Mux", rx0_prim_inp0_chain_enum);
407 
408 static const struct snd_kcontrol_new rx0_prim_inp1_mux =
409 	SOC_DAPM_ENUM("WSA_RX0 INP1 Mux", rx0_prim_inp1_chain_enum);
410 
411 static const struct snd_kcontrol_new rx0_prim_inp2_mux =
412 	SOC_DAPM_ENUM("WSA_RX0 INP2 Mux", rx0_prim_inp2_chain_enum);
413 
414 static const struct snd_kcontrol_new rx0_mix_mux =
415 	SOC_DAPM_ENUM("WSA_RX0 MIX Mux", rx0_mix_chain_enum);
416 
417 static const struct snd_kcontrol_new rx0_sidetone_mix_mux =
418 	SOC_DAPM_ENUM("WSA_RX0 SIDETONE MIX Mux", rx0_sidetone_mix_enum);
419 
420 /* RX INT1 */
421 static const struct soc_enum rx1_prim_inp0_chain_enum =
422 	SOC_ENUM_SINGLE(CDC_WSA_RX_INP_MUX_RX_INT1_CFG0,
423 		0, 7, rx_text);
424 
425 static const struct soc_enum rx1_prim_inp1_chain_enum =
426 	SOC_ENUM_SINGLE(CDC_WSA_RX_INP_MUX_RX_INT1_CFG0,
427 		3, 7, rx_text);
428 
429 static const struct soc_enum rx1_prim_inp2_chain_enum =
430 	SOC_ENUM_SINGLE(CDC_WSA_RX_INP_MUX_RX_INT1_CFG1,
431 		3, 7, rx_text);
432 
433 static const struct soc_enum rx1_mix_chain_enum =
434 	SOC_ENUM_SINGLE(CDC_WSA_RX_INP_MUX_RX_INT1_CFG1,
435 		0, 5, rx_mix_text);
436 
437 static const struct snd_kcontrol_new rx1_prim_inp0_mux =
438 	SOC_DAPM_ENUM("WSA_RX1 INP0 Mux", rx1_prim_inp0_chain_enum);
439 
440 static const struct snd_kcontrol_new rx1_prim_inp1_mux =
441 	SOC_DAPM_ENUM("WSA_RX1 INP1 Mux", rx1_prim_inp1_chain_enum);
442 
443 static const struct snd_kcontrol_new rx1_prim_inp2_mux =
444 	SOC_DAPM_ENUM("WSA_RX1 INP2 Mux", rx1_prim_inp2_chain_enum);
445 
446 static const struct snd_kcontrol_new rx1_mix_mux =
447 	SOC_DAPM_ENUM("WSA_RX1 MIX Mux", rx1_mix_chain_enum);
448 
449 static const struct soc_enum rx_mix_ec0_enum =
450 	SOC_ENUM_SINGLE(CDC_WSA_RX_INP_MUX_RX_MIX_CFG0,
451 		0, 3, rx_mix_ec_text);
452 
453 static const struct soc_enum rx_mix_ec1_enum =
454 	SOC_ENUM_SINGLE(CDC_WSA_RX_INP_MUX_RX_MIX_CFG0,
455 		3, 3, rx_mix_ec_text);
456 
457 static const struct snd_kcontrol_new rx_mix_ec0_mux =
458 	SOC_DAPM_ENUM("WSA RX_MIX EC0_Mux", rx_mix_ec0_enum);
459 
460 static const struct snd_kcontrol_new rx_mix_ec1_mux =
461 	SOC_DAPM_ENUM("WSA RX_MIX EC1_Mux", rx_mix_ec1_enum);
462 
463 static const struct reg_default wsa_defaults[] = {
464 	/* WSA Macro */
465 	{ CDC_WSA_CLK_RST_CTRL_MCLK_CONTROL, 0x00},
466 	{ CDC_WSA_CLK_RST_CTRL_FS_CNT_CONTROL, 0x00},
467 	{ CDC_WSA_CLK_RST_CTRL_SWR_CONTROL, 0x00},
468 	{ CDC_WSA_TOP_TOP_CFG0, 0x00},
469 	{ CDC_WSA_TOP_TOP_CFG1, 0x00},
470 	{ CDC_WSA_TOP_FREQ_MCLK, 0x00},
471 	{ CDC_WSA_TOP_DEBUG_BUS_SEL, 0x00},
472 	{ CDC_WSA_TOP_DEBUG_EN0, 0x00},
473 	{ CDC_WSA_TOP_DEBUG_EN1, 0x00},
474 	{ CDC_WSA_TOP_DEBUG_DSM_LB, 0x88},
475 	{ CDC_WSA_TOP_RX_I2S_CTL, 0x0C},
476 	{ CDC_WSA_TOP_TX_I2S_CTL, 0x0C},
477 	{ CDC_WSA_TOP_I2S_CLK, 0x02},
478 	{ CDC_WSA_TOP_I2S_RESET, 0x00},
479 	{ CDC_WSA_RX_INP_MUX_RX_INT0_CFG0, 0x00},
480 	{ CDC_WSA_RX_INP_MUX_RX_INT0_CFG1, 0x00},
481 	{ CDC_WSA_RX_INP_MUX_RX_INT1_CFG0, 0x00},
482 	{ CDC_WSA_RX_INP_MUX_RX_INT1_CFG1, 0x00},
483 	{ CDC_WSA_RX_INP_MUX_RX_MIX_CFG0, 0x00},
484 	{ CDC_WSA_RX_INP_MUX_RX_EC_CFG0, 0x00},
485 	{ CDC_WSA_RX_INP_MUX_SOFTCLIP_CFG0, 0x00},
486 	{ CDC_WSA_TX0_SPKR_PROT_PATH_CTL, 0x02},
487 	{ CDC_WSA_TX0_SPKR_PROT_PATH_CFG0, 0x00},
488 	{ CDC_WSA_TX1_SPKR_PROT_PATH_CTL, 0x02},
489 	{ CDC_WSA_TX1_SPKR_PROT_PATH_CFG0, 0x00},
490 	{ CDC_WSA_TX2_SPKR_PROT_PATH_CTL, 0x02},
491 	{ CDC_WSA_TX2_SPKR_PROT_PATH_CFG0, 0x00},
492 	{ CDC_WSA_TX3_SPKR_PROT_PATH_CTL, 0x02},
493 	{ CDC_WSA_TX3_SPKR_PROT_PATH_CFG0, 0x00},
494 	{ CDC_WSA_INTR_CTRL_CFG, 0x00},
495 	{ CDC_WSA_INTR_CTRL_CLR_COMMIT, 0x00},
496 	{ CDC_WSA_INTR_CTRL_PIN1_MASK0, 0xFF},
497 	{ CDC_WSA_INTR_CTRL_PIN1_STATUS0, 0x00},
498 	{ CDC_WSA_INTR_CTRL_PIN1_CLEAR0, 0x00},
499 	{ CDC_WSA_INTR_CTRL_PIN2_MASK0, 0xFF},
500 	{ CDC_WSA_INTR_CTRL_PIN2_STATUS0, 0x00},
501 	{ CDC_WSA_INTR_CTRL_PIN2_CLEAR0, 0x00},
502 	{ CDC_WSA_INTR_CTRL_LEVEL0, 0x00},
503 	{ CDC_WSA_INTR_CTRL_BYPASS0, 0x00},
504 	{ CDC_WSA_INTR_CTRL_SET0, 0x00},
505 	{ CDC_WSA_RX0_RX_PATH_CTL, 0x04},
506 	{ CDC_WSA_RX0_RX_PATH_CFG0, 0x00},
507 	{ CDC_WSA_RX0_RX_PATH_CFG1, 0x64},
508 	{ CDC_WSA_RX0_RX_PATH_CFG2, 0x8F},
509 	{ CDC_WSA_RX0_RX_PATH_CFG3, 0x00},
510 	{ CDC_WSA_RX0_RX_VOL_CTL, 0x00},
511 	{ CDC_WSA_RX0_RX_PATH_MIX_CTL, 0x04},
512 	{ CDC_WSA_RX0_RX_PATH_MIX_CFG, 0x7E},
513 	{ CDC_WSA_RX0_RX_VOL_MIX_CTL, 0x00},
514 	{ CDC_WSA_RX0_RX_PATH_SEC0, 0x04},
515 	{ CDC_WSA_RX0_RX_PATH_SEC1, 0x08},
516 	{ CDC_WSA_RX0_RX_PATH_SEC2, 0x00},
517 	{ CDC_WSA_RX0_RX_PATH_SEC3, 0x00},
518 	{ CDC_WSA_RX0_RX_PATH_SEC5, 0x00},
519 	{ CDC_WSA_RX0_RX_PATH_SEC6, 0x00},
520 	{ CDC_WSA_RX0_RX_PATH_SEC7, 0x00},
521 	{ CDC_WSA_RX0_RX_PATH_MIX_SEC0, 0x08},
522 	{ CDC_WSA_RX0_RX_PATH_MIX_SEC1, 0x00},
523 	{ CDC_WSA_RX0_RX_PATH_DSMDEM_CTL, 0x00},
524 	{ CDC_WSA_RX1_RX_PATH_CFG0, 0x00},
525 	{ CDC_WSA_RX1_RX_PATH_CFG1, 0x64},
526 	{ CDC_WSA_RX1_RX_PATH_CFG2, 0x8F},
527 	{ CDC_WSA_RX1_RX_PATH_CFG3, 0x00},
528 	{ CDC_WSA_RX1_RX_VOL_CTL, 0x00},
529 	{ CDC_WSA_RX1_RX_PATH_MIX_CTL, 0x04},
530 	{ CDC_WSA_RX1_RX_PATH_MIX_CFG, 0x7E},
531 	{ CDC_WSA_RX1_RX_VOL_MIX_CTL, 0x00},
532 	{ CDC_WSA_RX1_RX_PATH_SEC0, 0x04},
533 	{ CDC_WSA_RX1_RX_PATH_SEC1, 0x08},
534 	{ CDC_WSA_RX1_RX_PATH_SEC2, 0x00},
535 	{ CDC_WSA_RX1_RX_PATH_SEC3, 0x00},
536 	{ CDC_WSA_RX1_RX_PATH_SEC5, 0x00},
537 	{ CDC_WSA_RX1_RX_PATH_SEC6, 0x00},
538 	{ CDC_WSA_RX1_RX_PATH_SEC7, 0x00},
539 	{ CDC_WSA_RX1_RX_PATH_MIX_SEC0, 0x08},
540 	{ CDC_WSA_RX1_RX_PATH_MIX_SEC1, 0x00},
541 	{ CDC_WSA_RX1_RX_PATH_DSMDEM_CTL, 0x00},
542 	{ CDC_WSA_BOOST0_BOOST_PATH_CTL, 0x00},
543 	{ CDC_WSA_BOOST0_BOOST_CTL, 0xD0},
544 	{ CDC_WSA_BOOST0_BOOST_CFG1, 0x89},
545 	{ CDC_WSA_BOOST0_BOOST_CFG2, 0x04},
546 	{ CDC_WSA_BOOST1_BOOST_PATH_CTL, 0x00},
547 	{ CDC_WSA_BOOST1_BOOST_CTL, 0xD0},
548 	{ CDC_WSA_BOOST1_BOOST_CFG1, 0x89},
549 	{ CDC_WSA_BOOST1_BOOST_CFG2, 0x04},
550 	{ CDC_WSA_COMPANDER0_CTL0, 0x60},
551 	{ CDC_WSA_COMPANDER0_CTL1, 0xDB},
552 	{ CDC_WSA_COMPANDER0_CTL2, 0xFF},
553 	{ CDC_WSA_COMPANDER0_CTL3, 0x35},
554 	{ CDC_WSA_COMPANDER0_CTL4, 0xFF},
555 	{ CDC_WSA_COMPANDER0_CTL5, 0x00},
556 	{ CDC_WSA_COMPANDER0_CTL6, 0x01},
557 	{ CDC_WSA_COMPANDER0_CTL7, 0x28},
558 	{ CDC_WSA_COMPANDER1_CTL0, 0x60},
559 	{ CDC_WSA_COMPANDER1_CTL1, 0xDB},
560 	{ CDC_WSA_COMPANDER1_CTL2, 0xFF},
561 	{ CDC_WSA_COMPANDER1_CTL3, 0x35},
562 	{ CDC_WSA_COMPANDER1_CTL4, 0xFF},
563 	{ CDC_WSA_COMPANDER1_CTL5, 0x00},
564 	{ CDC_WSA_COMPANDER1_CTL6, 0x01},
565 	{ CDC_WSA_COMPANDER1_CTL7, 0x28},
566 	{ CDC_WSA_SOFTCLIP0_CRC, 0x00},
567 	{ CDC_WSA_SOFTCLIP0_SOFTCLIP_CTRL, 0x38},
568 	{ CDC_WSA_SOFTCLIP1_CRC, 0x00},
569 	{ CDC_WSA_SOFTCLIP1_SOFTCLIP_CTRL, 0x38},
570 	{ CDC_WSA_EC_HQ0_EC_REF_HQ_PATH_CTL, 0x00},
571 	{ CDC_WSA_EC_HQ0_EC_REF_HQ_CFG0, 0x01},
572 	{ CDC_WSA_EC_HQ1_EC_REF_HQ_PATH_CTL, 0x00},
573 	{ CDC_WSA_EC_HQ1_EC_REF_HQ_CFG0, 0x01},
574 	{ CDC_WSA_SPLINE_ASRC0_CLK_RST_CTL, 0x00},
575 	{ CDC_WSA_SPLINE_ASRC0_CTL0, 0x00},
576 	{ CDC_WSA_SPLINE_ASRC0_CTL1, 0x00},
577 	{ CDC_WSA_SPLINE_ASRC0_FIFO_CTL, 0xA8},
578 	{ CDC_WSA_SPLINE_ASRC0_STATUS_FMIN_CNTR_LSB, 0x00},
579 	{ CDC_WSA_SPLINE_ASRC0_STATUS_FMIN_CNTR_MSB, 0x00},
580 	{ CDC_WSA_SPLINE_ASRC0_STATUS_FMAX_CNTR_LSB, 0x00},
581 	{ CDC_WSA_SPLINE_ASRC0_STATUS_FMAX_CNTR_MSB, 0x00},
582 	{ CDC_WSA_SPLINE_ASRC0_STATUS_FIFO, 0x00},
583 	{ CDC_WSA_SPLINE_ASRC1_CLK_RST_CTL, 0x00},
584 	{ CDC_WSA_SPLINE_ASRC1_CTL0, 0x00},
585 	{ CDC_WSA_SPLINE_ASRC1_CTL1, 0x00},
586 	{ CDC_WSA_SPLINE_ASRC1_FIFO_CTL, 0xA8},
587 	{ CDC_WSA_SPLINE_ASRC1_STATUS_FMIN_CNTR_LSB, 0x00},
588 	{ CDC_WSA_SPLINE_ASRC1_STATUS_FMIN_CNTR_MSB, 0x00},
589 	{ CDC_WSA_SPLINE_ASRC1_STATUS_FMAX_CNTR_LSB, 0x00},
590 	{ CDC_WSA_SPLINE_ASRC1_STATUS_FMAX_CNTR_MSB, 0x00},
591 	{ CDC_WSA_SPLINE_ASRC1_STATUS_FIFO, 0x00},
592 };
593 
594 static bool wsa_is_wronly_register(struct device *dev,
595 					unsigned int reg)
596 {
597 	switch (reg) {
598 	case CDC_WSA_INTR_CTRL_CLR_COMMIT:
599 	case CDC_WSA_INTR_CTRL_PIN1_CLEAR0:
600 	case CDC_WSA_INTR_CTRL_PIN2_CLEAR0:
601 		return true;
602 	}
603 
604 	return false;
605 }
606 
607 static bool wsa_is_rw_register(struct device *dev, unsigned int reg)
608 {
609 	switch (reg) {
610 	case CDC_WSA_CLK_RST_CTRL_MCLK_CONTROL:
611 	case CDC_WSA_CLK_RST_CTRL_FS_CNT_CONTROL:
612 	case CDC_WSA_CLK_RST_CTRL_SWR_CONTROL:
613 	case CDC_WSA_TOP_TOP_CFG0:
614 	case CDC_WSA_TOP_TOP_CFG1:
615 	case CDC_WSA_TOP_FREQ_MCLK:
616 	case CDC_WSA_TOP_DEBUG_BUS_SEL:
617 	case CDC_WSA_TOP_DEBUG_EN0:
618 	case CDC_WSA_TOP_DEBUG_EN1:
619 	case CDC_WSA_TOP_DEBUG_DSM_LB:
620 	case CDC_WSA_TOP_RX_I2S_CTL:
621 	case CDC_WSA_TOP_TX_I2S_CTL:
622 	case CDC_WSA_TOP_I2S_CLK:
623 	case CDC_WSA_TOP_I2S_RESET:
624 	case CDC_WSA_RX_INP_MUX_RX_INT0_CFG0:
625 	case CDC_WSA_RX_INP_MUX_RX_INT0_CFG1:
626 	case CDC_WSA_RX_INP_MUX_RX_INT1_CFG0:
627 	case CDC_WSA_RX_INP_MUX_RX_INT1_CFG1:
628 	case CDC_WSA_RX_INP_MUX_RX_MIX_CFG0:
629 	case CDC_WSA_RX_INP_MUX_RX_EC_CFG0:
630 	case CDC_WSA_RX_INP_MUX_SOFTCLIP_CFG0:
631 	case CDC_WSA_TX0_SPKR_PROT_PATH_CTL:
632 	case CDC_WSA_TX0_SPKR_PROT_PATH_CFG0:
633 	case CDC_WSA_TX1_SPKR_PROT_PATH_CTL:
634 	case CDC_WSA_TX1_SPKR_PROT_PATH_CFG0:
635 	case CDC_WSA_TX2_SPKR_PROT_PATH_CTL:
636 	case CDC_WSA_TX2_SPKR_PROT_PATH_CFG0:
637 	case CDC_WSA_TX3_SPKR_PROT_PATH_CTL:
638 	case CDC_WSA_TX3_SPKR_PROT_PATH_CFG0:
639 	case CDC_WSA_INTR_CTRL_CFG:
640 	case CDC_WSA_INTR_CTRL_PIN1_MASK0:
641 	case CDC_WSA_INTR_CTRL_PIN2_MASK0:
642 	case CDC_WSA_INTR_CTRL_LEVEL0:
643 	case CDC_WSA_INTR_CTRL_BYPASS0:
644 	case CDC_WSA_INTR_CTRL_SET0:
645 	case CDC_WSA_RX0_RX_PATH_CTL:
646 	case CDC_WSA_RX0_RX_PATH_CFG0:
647 	case CDC_WSA_RX0_RX_PATH_CFG1:
648 	case CDC_WSA_RX0_RX_PATH_CFG2:
649 	case CDC_WSA_RX0_RX_PATH_CFG3:
650 	case CDC_WSA_RX0_RX_VOL_CTL:
651 	case CDC_WSA_RX0_RX_PATH_MIX_CTL:
652 	case CDC_WSA_RX0_RX_PATH_MIX_CFG:
653 	case CDC_WSA_RX0_RX_VOL_MIX_CTL:
654 	case CDC_WSA_RX0_RX_PATH_SEC0:
655 	case CDC_WSA_RX0_RX_PATH_SEC1:
656 	case CDC_WSA_RX0_RX_PATH_SEC2:
657 	case CDC_WSA_RX0_RX_PATH_SEC3:
658 	case CDC_WSA_RX0_RX_PATH_SEC5:
659 	case CDC_WSA_RX0_RX_PATH_SEC6:
660 	case CDC_WSA_RX0_RX_PATH_SEC7:
661 	case CDC_WSA_RX0_RX_PATH_MIX_SEC0:
662 	case CDC_WSA_RX0_RX_PATH_MIX_SEC1:
663 	case CDC_WSA_RX0_RX_PATH_DSMDEM_CTL:
664 	case CDC_WSA_RX1_RX_PATH_CTL:
665 	case CDC_WSA_RX1_RX_PATH_CFG0:
666 	case CDC_WSA_RX1_RX_PATH_CFG1:
667 	case CDC_WSA_RX1_RX_PATH_CFG2:
668 	case CDC_WSA_RX1_RX_PATH_CFG3:
669 	case CDC_WSA_RX1_RX_VOL_CTL:
670 	case CDC_WSA_RX1_RX_PATH_MIX_CTL:
671 	case CDC_WSA_RX1_RX_PATH_MIX_CFG:
672 	case CDC_WSA_RX1_RX_VOL_MIX_CTL:
673 	case CDC_WSA_RX1_RX_PATH_SEC0:
674 	case CDC_WSA_RX1_RX_PATH_SEC1:
675 	case CDC_WSA_RX1_RX_PATH_SEC2:
676 	case CDC_WSA_RX1_RX_PATH_SEC3:
677 	case CDC_WSA_RX1_RX_PATH_SEC5:
678 	case CDC_WSA_RX1_RX_PATH_SEC6:
679 	case CDC_WSA_RX1_RX_PATH_SEC7:
680 	case CDC_WSA_RX1_RX_PATH_MIX_SEC0:
681 	case CDC_WSA_RX1_RX_PATH_MIX_SEC1:
682 	case CDC_WSA_RX1_RX_PATH_DSMDEM_CTL:
683 	case CDC_WSA_BOOST0_BOOST_PATH_CTL:
684 	case CDC_WSA_BOOST0_BOOST_CTL:
685 	case CDC_WSA_BOOST0_BOOST_CFG1:
686 	case CDC_WSA_BOOST0_BOOST_CFG2:
687 	case CDC_WSA_BOOST1_BOOST_PATH_CTL:
688 	case CDC_WSA_BOOST1_BOOST_CTL:
689 	case CDC_WSA_BOOST1_BOOST_CFG1:
690 	case CDC_WSA_BOOST1_BOOST_CFG2:
691 	case CDC_WSA_COMPANDER0_CTL0:
692 	case CDC_WSA_COMPANDER0_CTL1:
693 	case CDC_WSA_COMPANDER0_CTL2:
694 	case CDC_WSA_COMPANDER0_CTL3:
695 	case CDC_WSA_COMPANDER0_CTL4:
696 	case CDC_WSA_COMPANDER0_CTL5:
697 	case CDC_WSA_COMPANDER0_CTL7:
698 	case CDC_WSA_COMPANDER1_CTL0:
699 	case CDC_WSA_COMPANDER1_CTL1:
700 	case CDC_WSA_COMPANDER1_CTL2:
701 	case CDC_WSA_COMPANDER1_CTL3:
702 	case CDC_WSA_COMPANDER1_CTL4:
703 	case CDC_WSA_COMPANDER1_CTL5:
704 	case CDC_WSA_COMPANDER1_CTL7:
705 	case CDC_WSA_SOFTCLIP0_CRC:
706 	case CDC_WSA_SOFTCLIP0_SOFTCLIP_CTRL:
707 	case CDC_WSA_SOFTCLIP1_CRC:
708 	case CDC_WSA_SOFTCLIP1_SOFTCLIP_CTRL:
709 	case CDC_WSA_EC_HQ0_EC_REF_HQ_PATH_CTL:
710 	case CDC_WSA_EC_HQ0_EC_REF_HQ_CFG0:
711 	case CDC_WSA_EC_HQ1_EC_REF_HQ_PATH_CTL:
712 	case CDC_WSA_EC_HQ1_EC_REF_HQ_CFG0:
713 	case CDC_WSA_SPLINE_ASRC0_CLK_RST_CTL:
714 	case CDC_WSA_SPLINE_ASRC0_CTL0:
715 	case CDC_WSA_SPLINE_ASRC0_CTL1:
716 	case CDC_WSA_SPLINE_ASRC0_FIFO_CTL:
717 	case CDC_WSA_SPLINE_ASRC1_CLK_RST_CTL:
718 	case CDC_WSA_SPLINE_ASRC1_CTL0:
719 	case CDC_WSA_SPLINE_ASRC1_CTL1:
720 	case CDC_WSA_SPLINE_ASRC1_FIFO_CTL:
721 		return true;
722 	}
723 
724 	return false;
725 }
726 
727 static bool wsa_is_writeable_register(struct device *dev, unsigned int reg)
728 {
729 	bool ret;
730 
731 	ret = wsa_is_rw_register(dev, reg);
732 	if (!ret)
733 		return wsa_is_wronly_register(dev, reg);
734 
735 	return ret;
736 }
737 
738 static bool wsa_is_readable_register(struct device *dev, unsigned int reg)
739 {
740 	switch (reg) {
741 	case CDC_WSA_INTR_CTRL_CLR_COMMIT:
742 	case CDC_WSA_INTR_CTRL_PIN1_CLEAR0:
743 	case CDC_WSA_INTR_CTRL_PIN2_CLEAR0:
744 	case CDC_WSA_INTR_CTRL_PIN1_STATUS0:
745 	case CDC_WSA_INTR_CTRL_PIN2_STATUS0:
746 	case CDC_WSA_COMPANDER0_CTL6:
747 	case CDC_WSA_COMPANDER1_CTL6:
748 	case CDC_WSA_SPLINE_ASRC0_STATUS_FMIN_CNTR_LSB:
749 	case CDC_WSA_SPLINE_ASRC0_STATUS_FMIN_CNTR_MSB:
750 	case CDC_WSA_SPLINE_ASRC0_STATUS_FMAX_CNTR_LSB:
751 	case CDC_WSA_SPLINE_ASRC0_STATUS_FMAX_CNTR_MSB:
752 	case CDC_WSA_SPLINE_ASRC0_STATUS_FIFO:
753 	case CDC_WSA_SPLINE_ASRC1_STATUS_FMIN_CNTR_LSB:
754 	case CDC_WSA_SPLINE_ASRC1_STATUS_FMIN_CNTR_MSB:
755 	case CDC_WSA_SPLINE_ASRC1_STATUS_FMAX_CNTR_LSB:
756 	case CDC_WSA_SPLINE_ASRC1_STATUS_FMAX_CNTR_MSB:
757 	case CDC_WSA_SPLINE_ASRC1_STATUS_FIFO:
758 		return true;
759 	}
760 
761 	return wsa_is_rw_register(dev, reg);
762 }
763 
764 static bool wsa_is_volatile_register(struct device *dev, unsigned int reg)
765 {
766 	/* Update volatile list for rx/tx macros */
767 	switch (reg) {
768 	case CDC_WSA_INTR_CTRL_PIN1_STATUS0:
769 	case CDC_WSA_INTR_CTRL_PIN2_STATUS0:
770 	case CDC_WSA_COMPANDER0_CTL6:
771 	case CDC_WSA_COMPANDER1_CTL6:
772 	case CDC_WSA_SPLINE_ASRC0_STATUS_FMIN_CNTR_LSB:
773 	case CDC_WSA_SPLINE_ASRC0_STATUS_FMIN_CNTR_MSB:
774 	case CDC_WSA_SPLINE_ASRC0_STATUS_FMAX_CNTR_LSB:
775 	case CDC_WSA_SPLINE_ASRC0_STATUS_FMAX_CNTR_MSB:
776 	case CDC_WSA_SPLINE_ASRC0_STATUS_FIFO:
777 	case CDC_WSA_SPLINE_ASRC1_STATUS_FMIN_CNTR_LSB:
778 	case CDC_WSA_SPLINE_ASRC1_STATUS_FMIN_CNTR_MSB:
779 	case CDC_WSA_SPLINE_ASRC1_STATUS_FMAX_CNTR_LSB:
780 	case CDC_WSA_SPLINE_ASRC1_STATUS_FMAX_CNTR_MSB:
781 	case CDC_WSA_SPLINE_ASRC1_STATUS_FIFO:
782 		return true;
783 	}
784 	return false;
785 }
786 
787 static const struct regmap_config wsa_regmap_config = {
788 	.name = "wsa_macro",
789 	.reg_bits = 16,
790 	.val_bits = 32, /* 8 but with 32 bit read/write */
791 	.reg_stride = 4,
792 	.cache_type = REGCACHE_FLAT,
793 	.reg_defaults = wsa_defaults,
794 	.num_reg_defaults = ARRAY_SIZE(wsa_defaults),
795 	.max_register = WSA_MAX_OFFSET,
796 	.writeable_reg = wsa_is_writeable_register,
797 	.volatile_reg = wsa_is_volatile_register,
798 	.readable_reg = wsa_is_readable_register,
799 };
800 
801 /**
802  * wsa_macro_set_spkr_mode - Configures speaker compander and smartboost
803  * settings based on speaker mode.
804  *
805  * @component: codec instance
806  * @mode: Indicates speaker configuration mode.
807  *
808  * Returns 0 on success or -EINVAL on error.
809  */
810 int wsa_macro_set_spkr_mode(struct snd_soc_component *component, int mode)
811 {
812 	struct wsa_macro *wsa = snd_soc_component_get_drvdata(component);
813 
814 	wsa->spkr_mode = mode;
815 
816 	switch (mode) {
817 	case WSA_MACRO_SPKR_MODE_1:
818 		snd_soc_component_update_bits(component, CDC_WSA_COMPANDER0_CTL3, 0x80, 0x00);
819 		snd_soc_component_update_bits(component, CDC_WSA_COMPANDER1_CTL3, 0x80, 0x00);
820 		snd_soc_component_update_bits(component, CDC_WSA_COMPANDER0_CTL7, 0x01, 0x00);
821 		snd_soc_component_update_bits(component, CDC_WSA_COMPANDER1_CTL7, 0x01, 0x00);
822 		snd_soc_component_update_bits(component, CDC_WSA_BOOST0_BOOST_CTL, 0x7C, 0x44);
823 		snd_soc_component_update_bits(component, CDC_WSA_BOOST1_BOOST_CTL, 0x7C, 0x44);
824 		break;
825 	default:
826 		snd_soc_component_update_bits(component, CDC_WSA_COMPANDER0_CTL3, 0x80, 0x80);
827 		snd_soc_component_update_bits(component, CDC_WSA_COMPANDER1_CTL3, 0x80, 0x80);
828 		snd_soc_component_update_bits(component, CDC_WSA_COMPANDER0_CTL7, 0x01, 0x01);
829 		snd_soc_component_update_bits(component, CDC_WSA_COMPANDER1_CTL7, 0x01, 0x01);
830 		snd_soc_component_update_bits(component, CDC_WSA_BOOST0_BOOST_CTL, 0x7C, 0x58);
831 		snd_soc_component_update_bits(component, CDC_WSA_BOOST1_BOOST_CTL, 0x7C, 0x58);
832 		break;
833 	}
834 	return 0;
835 }
836 EXPORT_SYMBOL(wsa_macro_set_spkr_mode);
837 
838 static int wsa_macro_set_prim_interpolator_rate(struct snd_soc_dai *dai,
839 						u8 int_prim_fs_rate_reg_val,
840 						u32 sample_rate)
841 {
842 	u8 int_1_mix1_inp;
843 	u32 j, port;
844 	u16 int_mux_cfg0, int_mux_cfg1;
845 	u16 int_fs_reg;
846 	u8 inp0_sel, inp1_sel, inp2_sel;
847 	struct snd_soc_component *component = dai->component;
848 	struct wsa_macro *wsa = snd_soc_component_get_drvdata(component);
849 
850 	for_each_set_bit(port, &wsa->active_ch_mask[dai->id], WSA_MACRO_RX_MAX) {
851 		int_1_mix1_inp = port;
852 		if ((int_1_mix1_inp < WSA_MACRO_RX0) || (int_1_mix1_inp > WSA_MACRO_RX_MIX1)) {
853 			dev_err(component->dev,	"%s: Invalid RX port, Dai ID is %d\n",
854 				__func__, dai->id);
855 			return -EINVAL;
856 		}
857 
858 		int_mux_cfg0 = CDC_WSA_RX_INP_MUX_RX_INT0_CFG0;
859 
860 		/*
861 		 * Loop through all interpolator MUX inputs and find out
862 		 * to which interpolator input, the cdc_dma rx port
863 		 * is connected
864 		 */
865 		for (j = 0; j < NUM_INTERPOLATORS; j++) {
866 			int_mux_cfg1 = int_mux_cfg0 + WSA_MACRO_MUX_CFG1_OFFSET;
867 			inp0_sel = snd_soc_component_read_field(component, int_mux_cfg0,
868 								CDC_WSA_RX_INTX_1_MIX_INP0_SEL_MASK);
869 			inp1_sel = snd_soc_component_read_field(component, int_mux_cfg0,
870 								CDC_WSA_RX_INTX_1_MIX_INP1_SEL_MASK);
871 			inp2_sel = snd_soc_component_read_field(component, int_mux_cfg1,
872 								CDC_WSA_RX_INTX_1_MIX_INP2_SEL_MASK);
873 
874 			if ((inp0_sel == int_1_mix1_inp + INTn_1_INP_SEL_RX0) ||
875 			    (inp1_sel == int_1_mix1_inp + INTn_1_INP_SEL_RX0) ||
876 			    (inp2_sel == int_1_mix1_inp + INTn_1_INP_SEL_RX0)) {
877 				int_fs_reg = CDC_WSA_RX0_RX_PATH_CTL +
878 					     WSA_MACRO_RX_PATH_OFFSET * j;
879 				/* sample_rate is in Hz */
880 				snd_soc_component_update_bits(component, int_fs_reg,
881 							      WSA_MACRO_FS_RATE_MASK,
882 							      int_prim_fs_rate_reg_val);
883 			}
884 			int_mux_cfg0 += WSA_MACRO_MUX_CFG_OFFSET;
885 		}
886 	}
887 
888 	return 0;
889 }
890 
891 static int wsa_macro_set_mix_interpolator_rate(struct snd_soc_dai *dai,
892 					       u8 int_mix_fs_rate_reg_val,
893 					       u32 sample_rate)
894 {
895 	u8 int_2_inp;
896 	u32 j, port;
897 	u16 int_mux_cfg1, int_fs_reg;
898 	u8 int_mux_cfg1_val;
899 	struct snd_soc_component *component = dai->component;
900 	struct wsa_macro *wsa = snd_soc_component_get_drvdata(component);
901 
902 	for_each_set_bit(port, &wsa->active_ch_mask[dai->id], WSA_MACRO_RX_MAX) {
903 		int_2_inp = port;
904 		if ((int_2_inp < WSA_MACRO_RX0) || (int_2_inp > WSA_MACRO_RX_MIX1)) {
905 			dev_err(component->dev,	"%s: Invalid RX port, Dai ID is %d\n",
906 				__func__, dai->id);
907 			return -EINVAL;
908 		}
909 
910 		int_mux_cfg1 = CDC_WSA_RX_INP_MUX_RX_INT0_CFG1;
911 		for (j = 0; j < NUM_INTERPOLATORS; j++) {
912 			int_mux_cfg1_val = snd_soc_component_read_field(component, int_mux_cfg1,
913 									CDC_WSA_RX_INTX_2_SEL_MASK);
914 
915 			if (int_mux_cfg1_val == int_2_inp + INTn_2_INP_SEL_RX0) {
916 				int_fs_reg = CDC_WSA_RX0_RX_PATH_MIX_CTL +
917 					WSA_MACRO_RX_PATH_OFFSET * j;
918 
919 				snd_soc_component_update_bits(component,
920 						      int_fs_reg,
921 						      WSA_MACRO_FS_RATE_MASK,
922 						      int_mix_fs_rate_reg_val);
923 			}
924 			int_mux_cfg1 += WSA_MACRO_MUX_CFG_OFFSET;
925 		}
926 	}
927 	return 0;
928 }
929 
930 static int wsa_macro_set_interpolator_rate(struct snd_soc_dai *dai,
931 					   u32 sample_rate)
932 {
933 	int rate_val = 0;
934 	int i, ret;
935 
936 	/* set mixing path rate */
937 	for (i = 0; i < ARRAY_SIZE(int_mix_sample_rate_val); i++) {
938 		if (sample_rate == int_mix_sample_rate_val[i].sample_rate) {
939 			rate_val = int_mix_sample_rate_val[i].rate_val;
940 			break;
941 		}
942 	}
943 	if ((i == ARRAY_SIZE(int_mix_sample_rate_val)) || (rate_val < 0))
944 		goto prim_rate;
945 
946 	ret = wsa_macro_set_mix_interpolator_rate(dai, (u8) rate_val, sample_rate);
947 prim_rate:
948 	/* set primary path sample rate */
949 	for (i = 0; i < ARRAY_SIZE(int_prim_sample_rate_val); i++) {
950 		if (sample_rate == int_prim_sample_rate_val[i].sample_rate) {
951 			rate_val = int_prim_sample_rate_val[i].rate_val;
952 			break;
953 		}
954 	}
955 	if ((i == ARRAY_SIZE(int_prim_sample_rate_val)) || (rate_val < 0))
956 		return -EINVAL;
957 
958 	ret = wsa_macro_set_prim_interpolator_rate(dai, (u8) rate_val, sample_rate);
959 
960 	return ret;
961 }
962 
963 static int wsa_macro_hw_params(struct snd_pcm_substream *substream,
964 			       struct snd_pcm_hw_params *params,
965 			       struct snd_soc_dai *dai)
966 {
967 	struct snd_soc_component *component = dai->component;
968 	int ret;
969 
970 	switch (substream->stream) {
971 	case SNDRV_PCM_STREAM_PLAYBACK:
972 		ret = wsa_macro_set_interpolator_rate(dai, params_rate(params));
973 		if (ret) {
974 			dev_err(component->dev,
975 				"%s: cannot set sample rate: %u\n",
976 				__func__, params_rate(params));
977 			return ret;
978 		}
979 		break;
980 	default:
981 		break;
982 	}
983 	return 0;
984 }
985 
986 static int wsa_macro_get_channel_map(struct snd_soc_dai *dai,
987 				     unsigned int *tx_num, unsigned int *tx_slot,
988 				     unsigned int *rx_num, unsigned int *rx_slot)
989 {
990 	struct snd_soc_component *component = dai->component;
991 	struct wsa_macro *wsa = snd_soc_component_get_drvdata(component);
992 	u16 val, mask = 0, cnt = 0, temp;
993 
994 	switch (dai->id) {
995 	case WSA_MACRO_AIF_VI:
996 		*tx_slot = wsa->active_ch_mask[dai->id];
997 		*tx_num = wsa->active_ch_cnt[dai->id];
998 		break;
999 	case WSA_MACRO_AIF1_PB:
1000 	case WSA_MACRO_AIF_MIX1_PB:
1001 		for_each_set_bit(temp, &wsa->active_ch_mask[dai->id],
1002 					WSA_MACRO_RX_MAX) {
1003 			mask |= (1 << temp);
1004 			if (++cnt == WSA_MACRO_MAX_DMA_CH_PER_PORT)
1005 				break;
1006 		}
1007 		if (mask & 0x0C)
1008 			mask = mask >> 0x2;
1009 		*rx_slot = mask;
1010 		*rx_num = cnt;
1011 		break;
1012 	case WSA_MACRO_AIF_ECHO:
1013 		val = snd_soc_component_read(component, CDC_WSA_RX_INP_MUX_RX_MIX_CFG0);
1014 		if (val & WSA_MACRO_EC_MIX_TX1_MASK) {
1015 			mask |= 0x2;
1016 			cnt++;
1017 		}
1018 		if (val & WSA_MACRO_EC_MIX_TX0_MASK) {
1019 			mask |= 0x1;
1020 			cnt++;
1021 		}
1022 		*tx_slot = mask;
1023 		*tx_num = cnt;
1024 		break;
1025 	default:
1026 		dev_err(component->dev, "%s: Invalid AIF\n", __func__);
1027 		break;
1028 	}
1029 	return 0;
1030 }
1031 
1032 static struct snd_soc_dai_ops wsa_macro_dai_ops = {
1033 	.hw_params = wsa_macro_hw_params,
1034 	.get_channel_map = wsa_macro_get_channel_map,
1035 };
1036 
1037 static struct snd_soc_dai_driver wsa_macro_dai[] = {
1038 	{
1039 		.name = "wsa_macro_rx1",
1040 		.id = WSA_MACRO_AIF1_PB,
1041 		.playback = {
1042 			.stream_name = "WSA_AIF1 Playback",
1043 			.rates = WSA_MACRO_RX_RATES,
1044 			.formats = WSA_MACRO_RX_FORMATS,
1045 			.rate_max = 384000,
1046 			.rate_min = 8000,
1047 			.channels_min = 1,
1048 			.channels_max = 2,
1049 		},
1050 		.ops = &wsa_macro_dai_ops,
1051 	},
1052 	{
1053 		.name = "wsa_macro_rx_mix",
1054 		.id = WSA_MACRO_AIF_MIX1_PB,
1055 		.playback = {
1056 			.stream_name = "WSA_AIF_MIX1 Playback",
1057 			.rates = WSA_MACRO_RX_MIX_RATES,
1058 			.formats = WSA_MACRO_RX_FORMATS,
1059 			.rate_max = 192000,
1060 			.rate_min = 48000,
1061 			.channels_min = 1,
1062 			.channels_max = 2,
1063 		},
1064 		.ops = &wsa_macro_dai_ops,
1065 	},
1066 	{
1067 		.name = "wsa_macro_vifeedback",
1068 		.id = WSA_MACRO_AIF_VI,
1069 		.capture = {
1070 			.stream_name = "WSA_AIF_VI Capture",
1071 			.rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_48000,
1072 			.formats = WSA_MACRO_RX_FORMATS,
1073 			.rate_max = 48000,
1074 			.rate_min = 8000,
1075 			.channels_min = 1,
1076 			.channels_max = 4,
1077 		},
1078 		.ops = &wsa_macro_dai_ops,
1079 	},
1080 	{
1081 		.name = "wsa_macro_echo",
1082 		.id = WSA_MACRO_AIF_ECHO,
1083 		.capture = {
1084 			.stream_name = "WSA_AIF_ECHO Capture",
1085 			.rates = WSA_MACRO_ECHO_RATES,
1086 			.formats = WSA_MACRO_ECHO_FORMATS,
1087 			.rate_max = 48000,
1088 			.rate_min = 8000,
1089 			.channels_min = 1,
1090 			.channels_max = 2,
1091 		},
1092 		.ops = &wsa_macro_dai_ops,
1093 	},
1094 };
1095 
1096 static void wsa_macro_mclk_enable(struct wsa_macro *wsa, bool mclk_enable)
1097 {
1098 	struct regmap *regmap = wsa->regmap;
1099 
1100 	if (mclk_enable) {
1101 		if (wsa->wsa_mclk_users == 0) {
1102 			regcache_mark_dirty(regmap);
1103 			regcache_sync(regmap);
1104 			/* 9.6MHz MCLK, set value 0x00 if other frequency */
1105 			regmap_update_bits(regmap, CDC_WSA_TOP_FREQ_MCLK, 0x01, 0x01);
1106 			regmap_update_bits(regmap,
1107 					   CDC_WSA_CLK_RST_CTRL_MCLK_CONTROL,
1108 					   CDC_WSA_MCLK_EN_MASK,
1109 					   CDC_WSA_MCLK_ENABLE);
1110 			regmap_update_bits(regmap,
1111 					   CDC_WSA_CLK_RST_CTRL_FS_CNT_CONTROL,
1112 					   CDC_WSA_FS_CNT_EN_MASK,
1113 					   CDC_WSA_FS_CNT_ENABLE);
1114 		}
1115 		wsa->wsa_mclk_users++;
1116 	} else {
1117 		if (wsa->wsa_mclk_users <= 0) {
1118 			dev_err(wsa->dev, "clock already disabled\n");
1119 			wsa->wsa_mclk_users = 0;
1120 			return;
1121 		}
1122 		wsa->wsa_mclk_users--;
1123 		if (wsa->wsa_mclk_users == 0) {
1124 			regmap_update_bits(regmap,
1125 					   CDC_WSA_CLK_RST_CTRL_FS_CNT_CONTROL,
1126 					   CDC_WSA_FS_CNT_EN_MASK,
1127 					   CDC_WSA_FS_CNT_DISABLE);
1128 			regmap_update_bits(regmap,
1129 					   CDC_WSA_CLK_RST_CTRL_MCLK_CONTROL,
1130 					   CDC_WSA_MCLK_EN_MASK,
1131 					   CDC_WSA_MCLK_DISABLE);
1132 		}
1133 	}
1134 }
1135 
1136 static int wsa_macro_mclk_event(struct snd_soc_dapm_widget *w,
1137 				struct snd_kcontrol *kcontrol, int event)
1138 {
1139 	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
1140 	struct wsa_macro *wsa = snd_soc_component_get_drvdata(component);
1141 
1142 	wsa_macro_mclk_enable(wsa, event == SND_SOC_DAPM_PRE_PMU);
1143 	return 0;
1144 }
1145 
1146 static int wsa_macro_enable_vi_feedback(struct snd_soc_dapm_widget *w,
1147 					struct snd_kcontrol *kcontrol,
1148 					int event)
1149 {
1150 	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
1151 	struct wsa_macro *wsa = snd_soc_component_get_drvdata(component);
1152 	u32 tx_reg0, tx_reg1;
1153 
1154 	if (test_bit(WSA_MACRO_TX0, &wsa->active_ch_mask[WSA_MACRO_AIF_VI])) {
1155 		tx_reg0 = CDC_WSA_TX0_SPKR_PROT_PATH_CTL;
1156 		tx_reg1 = CDC_WSA_TX1_SPKR_PROT_PATH_CTL;
1157 	} else if (test_bit(WSA_MACRO_TX1, &wsa->active_ch_mask[WSA_MACRO_AIF_VI])) {
1158 		tx_reg0 = CDC_WSA_TX2_SPKR_PROT_PATH_CTL;
1159 		tx_reg1 = CDC_WSA_TX3_SPKR_PROT_PATH_CTL;
1160 	}
1161 
1162 	switch (event) {
1163 	case SND_SOC_DAPM_POST_PMU:
1164 			/* Enable V&I sensing */
1165 		snd_soc_component_update_bits(component, tx_reg0,
1166 					      CDC_WSA_TX_SPKR_PROT_RESET_MASK,
1167 					      CDC_WSA_TX_SPKR_PROT_RESET);
1168 		snd_soc_component_update_bits(component, tx_reg1,
1169 					      CDC_WSA_TX_SPKR_PROT_RESET_MASK,
1170 					      CDC_WSA_TX_SPKR_PROT_RESET);
1171 		snd_soc_component_update_bits(component, tx_reg0,
1172 					      CDC_WSA_TX_SPKR_PROT_PCM_RATE_MASK,
1173 					      CDC_WSA_TX_SPKR_PROT_PCM_RATE_8K);
1174 		snd_soc_component_update_bits(component, tx_reg1,
1175 					      CDC_WSA_TX_SPKR_PROT_PCM_RATE_MASK,
1176 					      CDC_WSA_TX_SPKR_PROT_PCM_RATE_8K);
1177 		snd_soc_component_update_bits(component, tx_reg0,
1178 					      CDC_WSA_TX_SPKR_PROT_CLK_EN_MASK,
1179 					      CDC_WSA_TX_SPKR_PROT_CLK_ENABLE);
1180 		snd_soc_component_update_bits(component, tx_reg1,
1181 					      CDC_WSA_TX_SPKR_PROT_CLK_EN_MASK,
1182 					      CDC_WSA_TX_SPKR_PROT_CLK_ENABLE);
1183 		snd_soc_component_update_bits(component, tx_reg0,
1184 					      CDC_WSA_TX_SPKR_PROT_RESET_MASK,
1185 					      CDC_WSA_TX_SPKR_PROT_NO_RESET);
1186 		snd_soc_component_update_bits(component, tx_reg1,
1187 					      CDC_WSA_TX_SPKR_PROT_RESET_MASK,
1188 					      CDC_WSA_TX_SPKR_PROT_NO_RESET);
1189 		break;
1190 	case SND_SOC_DAPM_POST_PMD:
1191 		/* Disable V&I sensing */
1192 		snd_soc_component_update_bits(component, tx_reg0,
1193 					      CDC_WSA_TX_SPKR_PROT_RESET_MASK,
1194 					      CDC_WSA_TX_SPKR_PROT_RESET);
1195 		snd_soc_component_update_bits(component, tx_reg1,
1196 					      CDC_WSA_TX_SPKR_PROT_RESET_MASK,
1197 					      CDC_WSA_TX_SPKR_PROT_RESET);
1198 		snd_soc_component_update_bits(component, tx_reg0,
1199 					      CDC_WSA_TX_SPKR_PROT_CLK_EN_MASK,
1200 					      CDC_WSA_TX_SPKR_PROT_CLK_DISABLE);
1201 		snd_soc_component_update_bits(component, tx_reg1,
1202 					      CDC_WSA_TX_SPKR_PROT_CLK_EN_MASK,
1203 					      CDC_WSA_TX_SPKR_PROT_CLK_DISABLE);
1204 		break;
1205 	}
1206 
1207 	return 0;
1208 }
1209 
1210 static int wsa_macro_enable_mix_path(struct snd_soc_dapm_widget *w,
1211 				     struct snd_kcontrol *kcontrol, int event)
1212 {
1213 	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
1214 	u16 path_reg, gain_reg;
1215 	int val;
1216 
1217 	switch (w->shift) {
1218 	case WSA_MACRO_RX_MIX0:
1219 		path_reg = CDC_WSA_RX0_RX_PATH_MIX_CTL;
1220 		gain_reg = CDC_WSA_RX0_RX_VOL_MIX_CTL;
1221 		break;
1222 	case WSA_MACRO_RX_MIX1:
1223 		path_reg = CDC_WSA_RX1_RX_PATH_MIX_CTL;
1224 		gain_reg = CDC_WSA_RX1_RX_VOL_MIX_CTL;
1225 		break;
1226 	default:
1227 		return 0;
1228 	}
1229 
1230 	switch (event) {
1231 	case SND_SOC_DAPM_POST_PMU:
1232 		val = snd_soc_component_read(component, gain_reg);
1233 		snd_soc_component_write(component, gain_reg, val);
1234 		break;
1235 	case SND_SOC_DAPM_POST_PMD:
1236 		snd_soc_component_update_bits(component, path_reg,
1237 					      CDC_WSA_RX_PATH_MIX_CLK_EN_MASK,
1238 					      CDC_WSA_RX_PATH_MIX_CLK_DISABLE);
1239 		break;
1240 	}
1241 
1242 	return 0;
1243 }
1244 
1245 static void wsa_macro_hd2_control(struct snd_soc_component *component,
1246 				  u16 reg, int event)
1247 {
1248 	u16 hd2_scale_reg;
1249 	u16 hd2_enable_reg;
1250 
1251 	if (reg == CDC_WSA_RX0_RX_PATH_CTL) {
1252 		hd2_scale_reg = CDC_WSA_RX0_RX_PATH_SEC3;
1253 		hd2_enable_reg = CDC_WSA_RX0_RX_PATH_CFG0;
1254 	}
1255 	if (reg == CDC_WSA_RX1_RX_PATH_CTL) {
1256 		hd2_scale_reg = CDC_WSA_RX1_RX_PATH_SEC3;
1257 		hd2_enable_reg = CDC_WSA_RX1_RX_PATH_CFG0;
1258 	}
1259 
1260 	if (hd2_enable_reg && SND_SOC_DAPM_EVENT_ON(event)) {
1261 		snd_soc_component_update_bits(component, hd2_scale_reg,
1262 					      CDC_WSA_RX_PATH_HD2_ALPHA_MASK,
1263 					      0x10);
1264 		snd_soc_component_update_bits(component, hd2_scale_reg,
1265 					      CDC_WSA_RX_PATH_HD2_SCALE_MASK,
1266 					      0x1);
1267 		snd_soc_component_update_bits(component, hd2_enable_reg,
1268 					      CDC_WSA_RX_PATH_HD2_EN_MASK,
1269 					      CDC_WSA_RX_PATH_HD2_ENABLE);
1270 	}
1271 
1272 	if (hd2_enable_reg && SND_SOC_DAPM_EVENT_OFF(event)) {
1273 		snd_soc_component_update_bits(component, hd2_enable_reg,
1274 					      CDC_WSA_RX_PATH_HD2_EN_MASK, 0);
1275 		snd_soc_component_update_bits(component, hd2_scale_reg,
1276 					      CDC_WSA_RX_PATH_HD2_SCALE_MASK,
1277 					      0);
1278 		snd_soc_component_update_bits(component, hd2_scale_reg,
1279 					      CDC_WSA_RX_PATH_HD2_ALPHA_MASK,
1280 					      0);
1281 	}
1282 }
1283 
1284 static int wsa_macro_config_compander(struct snd_soc_component *component,
1285 				      int comp, int event)
1286 {
1287 	u16 comp_ctl0_reg, rx_path_cfg0_reg;
1288 	struct wsa_macro *wsa = snd_soc_component_get_drvdata(component);
1289 
1290 	if (!wsa->comp_enabled[comp])
1291 		return 0;
1292 
1293 	comp_ctl0_reg = CDC_WSA_COMPANDER0_CTL0 +
1294 					(comp * WSA_MACRO_RX_COMP_OFFSET);
1295 	rx_path_cfg0_reg = CDC_WSA_RX0_RX_PATH_CFG0 +
1296 					(comp * WSA_MACRO_RX_PATH_OFFSET);
1297 
1298 	if (SND_SOC_DAPM_EVENT_ON(event)) {
1299 		/* Enable Compander Clock */
1300 		snd_soc_component_update_bits(component, comp_ctl0_reg,
1301 					      CDC_WSA_COMPANDER_CLK_EN_MASK,
1302 					      CDC_WSA_COMPANDER_CLK_ENABLE);
1303 		snd_soc_component_update_bits(component, comp_ctl0_reg,
1304 					      CDC_WSA_COMPANDER_SOFT_RST_MASK,
1305 					      CDC_WSA_COMPANDER_SOFT_RST_ENABLE);
1306 		snd_soc_component_update_bits(component, comp_ctl0_reg,
1307 					      CDC_WSA_COMPANDER_SOFT_RST_MASK,
1308 					      0);
1309 		snd_soc_component_update_bits(component, rx_path_cfg0_reg,
1310 					      CDC_WSA_RX_PATH_COMP_EN_MASK,
1311 					      CDC_WSA_RX_PATH_COMP_ENABLE);
1312 	}
1313 
1314 	if (SND_SOC_DAPM_EVENT_OFF(event)) {
1315 		snd_soc_component_update_bits(component, comp_ctl0_reg,
1316 					      CDC_WSA_COMPANDER_HALT_MASK,
1317 					      CDC_WSA_COMPANDER_HALT);
1318 		snd_soc_component_update_bits(component, rx_path_cfg0_reg,
1319 					      CDC_WSA_RX_PATH_COMP_EN_MASK, 0);
1320 		snd_soc_component_update_bits(component, comp_ctl0_reg,
1321 					      CDC_WSA_COMPANDER_SOFT_RST_MASK,
1322 					      CDC_WSA_COMPANDER_SOFT_RST_ENABLE);
1323 		snd_soc_component_update_bits(component, comp_ctl0_reg,
1324 					      CDC_WSA_COMPANDER_SOFT_RST_MASK,
1325 					      0);
1326 		snd_soc_component_update_bits(component, comp_ctl0_reg,
1327 					      CDC_WSA_COMPANDER_CLK_EN_MASK, 0);
1328 		snd_soc_component_update_bits(component, comp_ctl0_reg,
1329 					      CDC_WSA_COMPANDER_HALT_MASK, 0);
1330 	}
1331 
1332 	return 0;
1333 }
1334 
1335 static void wsa_macro_enable_softclip_clk(struct snd_soc_component *component,
1336 					 struct wsa_macro *wsa,
1337 					 int path,
1338 					 bool enable)
1339 {
1340 	u16 softclip_clk_reg = CDC_WSA_SOFTCLIP0_CRC +
1341 			(path * WSA_MACRO_RX_SOFTCLIP_OFFSET);
1342 	u8 softclip_mux_mask = (1 << path);
1343 	u8 softclip_mux_value = (1 << path);
1344 
1345 	if (enable) {
1346 		if (wsa->softclip_clk_users[path] == 0) {
1347 			snd_soc_component_update_bits(component,
1348 						softclip_clk_reg,
1349 						CDC_WSA_SOFTCLIP_CLK_EN_MASK,
1350 						CDC_WSA_SOFTCLIP_CLK_ENABLE);
1351 			snd_soc_component_update_bits(component,
1352 				CDC_WSA_RX_INP_MUX_SOFTCLIP_CFG0,
1353 				softclip_mux_mask, softclip_mux_value);
1354 		}
1355 		wsa->softclip_clk_users[path]++;
1356 	} else {
1357 		wsa->softclip_clk_users[path]--;
1358 		if (wsa->softclip_clk_users[path] == 0) {
1359 			snd_soc_component_update_bits(component,
1360 						softclip_clk_reg,
1361 						CDC_WSA_SOFTCLIP_CLK_EN_MASK,
1362 						0);
1363 			snd_soc_component_update_bits(component,
1364 				CDC_WSA_RX_INP_MUX_SOFTCLIP_CFG0,
1365 				softclip_mux_mask, 0x00);
1366 		}
1367 	}
1368 }
1369 
1370 static int wsa_macro_config_softclip(struct snd_soc_component *component,
1371 				     int path, int event)
1372 {
1373 	u16 softclip_ctrl_reg;
1374 	struct wsa_macro *wsa = snd_soc_component_get_drvdata(component);
1375 	int softclip_path = 0;
1376 
1377 	if (path == WSA_MACRO_COMP1)
1378 		softclip_path = WSA_MACRO_SOFTCLIP0;
1379 	else if (path == WSA_MACRO_COMP2)
1380 		softclip_path = WSA_MACRO_SOFTCLIP1;
1381 
1382 	if (!wsa->is_softclip_on[softclip_path])
1383 		return 0;
1384 
1385 	softclip_ctrl_reg = CDC_WSA_SOFTCLIP0_SOFTCLIP_CTRL +
1386 				(softclip_path * WSA_MACRO_RX_SOFTCLIP_OFFSET);
1387 
1388 	if (SND_SOC_DAPM_EVENT_ON(event)) {
1389 		/* Enable Softclip clock and mux */
1390 		wsa_macro_enable_softclip_clk(component, wsa, softclip_path,
1391 					      true);
1392 		/* Enable Softclip control */
1393 		snd_soc_component_update_bits(component, softclip_ctrl_reg,
1394 					      CDC_WSA_SOFTCLIP_EN_MASK,
1395 					      CDC_WSA_SOFTCLIP_ENABLE);
1396 	}
1397 
1398 	if (SND_SOC_DAPM_EVENT_OFF(event)) {
1399 		snd_soc_component_update_bits(component, softclip_ctrl_reg,
1400 					      CDC_WSA_SOFTCLIP_EN_MASK, 0);
1401 		wsa_macro_enable_softclip_clk(component, wsa, softclip_path,
1402 					      false);
1403 	}
1404 
1405 	return 0;
1406 }
1407 
1408 static bool wsa_macro_adie_lb(struct snd_soc_component *component,
1409 			      int interp_idx)
1410 {
1411 	u16 int_mux_cfg0,  int_mux_cfg1;
1412 	u8 int_n_inp0, int_n_inp1, int_n_inp2;
1413 
1414 	int_mux_cfg0 = CDC_WSA_RX_INP_MUX_RX_INT0_CFG0 + interp_idx * 8;
1415 	int_mux_cfg1 = int_mux_cfg0 + 4;
1416 
1417 	int_n_inp0 = snd_soc_component_read_field(component, int_mux_cfg0,
1418 						  CDC_WSA_RX_INTX_1_MIX_INP0_SEL_MASK);
1419 	if (int_n_inp0 == INTn_1_INP_SEL_DEC0 ||
1420 		int_n_inp0 == INTn_1_INP_SEL_DEC1)
1421 		return true;
1422 
1423 	int_n_inp1 = snd_soc_component_read_field(component, int_mux_cfg0,
1424 						  CDC_WSA_RX_INTX_1_MIX_INP1_SEL_MASK);
1425 	if (int_n_inp1 == INTn_1_INP_SEL_DEC0 ||
1426 		int_n_inp1 == INTn_1_INP_SEL_DEC1)
1427 		return true;
1428 
1429 	int_n_inp2 = snd_soc_component_read_field(component, int_mux_cfg1,
1430 						  CDC_WSA_RX_INTX_1_MIX_INP2_SEL_MASK);
1431 	if (int_n_inp2 == INTn_1_INP_SEL_DEC0 ||
1432 		int_n_inp2 == INTn_1_INP_SEL_DEC1)
1433 		return true;
1434 
1435 	return false;
1436 }
1437 
1438 static int wsa_macro_enable_main_path(struct snd_soc_dapm_widget *w,
1439 				      struct snd_kcontrol *kcontrol,
1440 				      int event)
1441 {
1442 	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
1443 	u16 reg;
1444 
1445 	reg = CDC_WSA_RX0_RX_PATH_CTL + WSA_MACRO_RX_PATH_OFFSET * w->shift;
1446 	switch (event) {
1447 	case SND_SOC_DAPM_PRE_PMU:
1448 		if (wsa_macro_adie_lb(component, w->shift)) {
1449 			snd_soc_component_update_bits(component, reg,
1450 					     CDC_WSA_RX_PATH_CLK_EN_MASK,
1451 					     CDC_WSA_RX_PATH_CLK_ENABLE);
1452 		}
1453 		break;
1454 	default:
1455 		break;
1456 	}
1457 	return 0;
1458 }
1459 
1460 static int wsa_macro_interp_get_primary_reg(u16 reg, u16 *ind)
1461 {
1462 	u16 prim_int_reg = 0;
1463 
1464 	switch (reg) {
1465 	case CDC_WSA_RX0_RX_PATH_CTL:
1466 	case CDC_WSA_RX0_RX_PATH_MIX_CTL:
1467 		prim_int_reg = CDC_WSA_RX0_RX_PATH_CTL;
1468 		*ind = 0;
1469 		break;
1470 	case CDC_WSA_RX1_RX_PATH_CTL:
1471 	case CDC_WSA_RX1_RX_PATH_MIX_CTL:
1472 		prim_int_reg = CDC_WSA_RX1_RX_PATH_CTL;
1473 		*ind = 1;
1474 		break;
1475 	}
1476 
1477 	return prim_int_reg;
1478 }
1479 
1480 static int wsa_macro_enable_prim_interpolator(struct snd_soc_component *component,
1481 					      u16 reg, int event)
1482 {
1483 	u16 prim_int_reg;
1484 	u16 ind = 0;
1485 	struct wsa_macro *wsa = snd_soc_component_get_drvdata(component);
1486 
1487 	prim_int_reg = wsa_macro_interp_get_primary_reg(reg, &ind);
1488 
1489 	switch (event) {
1490 	case SND_SOC_DAPM_PRE_PMU:
1491 		wsa->prim_int_users[ind]++;
1492 		if (wsa->prim_int_users[ind] == 1) {
1493 			snd_soc_component_update_bits(component,
1494 						      prim_int_reg + WSA_MACRO_RX_PATH_CFG3_OFFSET,
1495 						      CDC_WSA_RX_DC_DCOEFF_MASK,
1496 						      0x3);
1497 			snd_soc_component_update_bits(component, prim_int_reg,
1498 					CDC_WSA_RX_PATH_PGA_MUTE_EN_MASK,
1499 					CDC_WSA_RX_PATH_PGA_MUTE_ENABLE);
1500 			wsa_macro_hd2_control(component, prim_int_reg, event);
1501 			snd_soc_component_update_bits(component,
1502 				prim_int_reg + WSA_MACRO_RX_PATH_DSMDEM_OFFSET,
1503 				CDC_WSA_RX_DSMDEM_CLK_EN_MASK,
1504 				CDC_WSA_RX_DSMDEM_CLK_ENABLE);
1505 		}
1506 		if ((reg != prim_int_reg) &&
1507 		    ((snd_soc_component_read(
1508 				component, prim_int_reg)) & 0x10))
1509 			snd_soc_component_update_bits(component, reg,
1510 					0x10, 0x10);
1511 		break;
1512 	case SND_SOC_DAPM_POST_PMD:
1513 		wsa->prim_int_users[ind]--;
1514 		if (wsa->prim_int_users[ind] == 0) {
1515 			snd_soc_component_update_bits(component,
1516 				prim_int_reg + WSA_MACRO_RX_PATH_DSMDEM_OFFSET,
1517 				CDC_WSA_RX_DSMDEM_CLK_EN_MASK, 0);
1518 			wsa_macro_hd2_control(component, prim_int_reg, event);
1519 		}
1520 		break;
1521 	}
1522 
1523 	return 0;
1524 }
1525 
1526 static int wsa_macro_config_ear_spkr_gain(struct snd_soc_component *component,
1527 					  struct wsa_macro *wsa,
1528 					  int event, int gain_reg)
1529 {
1530 	int comp_gain_offset, val;
1531 
1532 	switch (wsa->spkr_mode) {
1533 	/* Compander gain in WSA_MACRO_SPKR_MODE1 case is 12 dB */
1534 	case WSA_MACRO_SPKR_MODE_1:
1535 		comp_gain_offset = -12;
1536 		break;
1537 	/* Default case compander gain is 15 dB */
1538 	default:
1539 		comp_gain_offset = -15;
1540 		break;
1541 	}
1542 
1543 	switch (event) {
1544 	case SND_SOC_DAPM_POST_PMU:
1545 		/* Apply ear spkr gain only if compander is enabled */
1546 		if (wsa->comp_enabled[WSA_MACRO_COMP1] &&
1547 		    (gain_reg == CDC_WSA_RX0_RX_VOL_CTL) &&
1548 		    (wsa->ear_spkr_gain != 0)) {
1549 			/* For example, val is -8(-12+5-1) for 4dB of gain */
1550 			val = comp_gain_offset + wsa->ear_spkr_gain - 1;
1551 			snd_soc_component_write(component, gain_reg, val);
1552 		}
1553 		break;
1554 	case SND_SOC_DAPM_POST_PMD:
1555 		/*
1556 		 * Reset RX0 volume to 0 dB if compander is enabled and
1557 		 * ear_spkr_gain is non-zero.
1558 		 */
1559 		if (wsa->comp_enabled[WSA_MACRO_COMP1] &&
1560 		    (gain_reg == CDC_WSA_RX0_RX_VOL_CTL) &&
1561 		    (wsa->ear_spkr_gain != 0)) {
1562 			snd_soc_component_write(component, gain_reg, 0x0);
1563 		}
1564 		break;
1565 	}
1566 
1567 	return 0;
1568 }
1569 
1570 static int wsa_macro_enable_interpolator(struct snd_soc_dapm_widget *w,
1571 					 struct snd_kcontrol *kcontrol,
1572 					 int event)
1573 {
1574 	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
1575 	u16 gain_reg;
1576 	u16 reg;
1577 	int val;
1578 	int offset_val = 0;
1579 	struct wsa_macro *wsa = snd_soc_component_get_drvdata(component);
1580 
1581 	if (w->shift == WSA_MACRO_COMP1) {
1582 		reg = CDC_WSA_RX0_RX_PATH_CTL;
1583 		gain_reg = CDC_WSA_RX0_RX_VOL_CTL;
1584 	} else if (w->shift == WSA_MACRO_COMP2) {
1585 		reg = CDC_WSA_RX1_RX_PATH_CTL;
1586 		gain_reg = CDC_WSA_RX1_RX_VOL_CTL;
1587 	}
1588 
1589 	switch (event) {
1590 	case SND_SOC_DAPM_PRE_PMU:
1591 		/* Reset if needed */
1592 		wsa_macro_enable_prim_interpolator(component, reg, event);
1593 		break;
1594 	case SND_SOC_DAPM_POST_PMU:
1595 		wsa_macro_config_compander(component, w->shift, event);
1596 		wsa_macro_config_softclip(component, w->shift, event);
1597 		/* apply gain after int clk is enabled */
1598 		if ((wsa->spkr_gain_offset == WSA_MACRO_GAIN_OFFSET_M1P5_DB) &&
1599 		    (wsa->comp_enabled[WSA_MACRO_COMP1] ||
1600 		     wsa->comp_enabled[WSA_MACRO_COMP2])) {
1601 			snd_soc_component_update_bits(component,
1602 					CDC_WSA_RX0_RX_PATH_SEC1,
1603 					CDC_WSA_RX_PGA_HALF_DB_MASK,
1604 					CDC_WSA_RX_PGA_HALF_DB_ENABLE);
1605 			snd_soc_component_update_bits(component,
1606 					CDC_WSA_RX0_RX_PATH_MIX_SEC0,
1607 					CDC_WSA_RX_PGA_HALF_DB_MASK,
1608 					CDC_WSA_RX_PGA_HALF_DB_ENABLE);
1609 			snd_soc_component_update_bits(component,
1610 					CDC_WSA_RX1_RX_PATH_SEC1,
1611 					CDC_WSA_RX_PGA_HALF_DB_MASK,
1612 					CDC_WSA_RX_PGA_HALF_DB_ENABLE);
1613 			snd_soc_component_update_bits(component,
1614 					CDC_WSA_RX1_RX_PATH_MIX_SEC0,
1615 					CDC_WSA_RX_PGA_HALF_DB_MASK,
1616 					CDC_WSA_RX_PGA_HALF_DB_ENABLE);
1617 			offset_val = -2;
1618 		}
1619 		val = snd_soc_component_read(component, gain_reg);
1620 		val += offset_val;
1621 		snd_soc_component_write(component, gain_reg, val);
1622 		wsa_macro_config_ear_spkr_gain(component, wsa,
1623 						event, gain_reg);
1624 		break;
1625 	case SND_SOC_DAPM_POST_PMD:
1626 		wsa_macro_config_compander(component, w->shift, event);
1627 		wsa_macro_config_softclip(component, w->shift, event);
1628 		wsa_macro_enable_prim_interpolator(component, reg, event);
1629 		if ((wsa->spkr_gain_offset == WSA_MACRO_GAIN_OFFSET_M1P5_DB) &&
1630 		    (wsa->comp_enabled[WSA_MACRO_COMP1] ||
1631 		     wsa->comp_enabled[WSA_MACRO_COMP2])) {
1632 			snd_soc_component_update_bits(component,
1633 					CDC_WSA_RX0_RX_PATH_SEC1,
1634 					CDC_WSA_RX_PGA_HALF_DB_MASK,
1635 					CDC_WSA_RX_PGA_HALF_DB_DISABLE);
1636 			snd_soc_component_update_bits(component,
1637 					CDC_WSA_RX0_RX_PATH_MIX_SEC0,
1638 					CDC_WSA_RX_PGA_HALF_DB_MASK,
1639 					CDC_WSA_RX_PGA_HALF_DB_DISABLE);
1640 			snd_soc_component_update_bits(component,
1641 					CDC_WSA_RX1_RX_PATH_SEC1,
1642 					CDC_WSA_RX_PGA_HALF_DB_MASK,
1643 					CDC_WSA_RX_PGA_HALF_DB_DISABLE);
1644 			snd_soc_component_update_bits(component,
1645 					CDC_WSA_RX1_RX_PATH_MIX_SEC0,
1646 					CDC_WSA_RX_PGA_HALF_DB_MASK,
1647 					CDC_WSA_RX_PGA_HALF_DB_DISABLE);
1648 			offset_val = 2;
1649 			val = snd_soc_component_read(component, gain_reg);
1650 			val += offset_val;
1651 			snd_soc_component_write(component, gain_reg, val);
1652 		}
1653 		wsa_macro_config_ear_spkr_gain(component, wsa,
1654 						event, gain_reg);
1655 		break;
1656 	}
1657 
1658 	return 0;
1659 }
1660 
1661 static int wsa_macro_spk_boost_event(struct snd_soc_dapm_widget *w,
1662 				     struct snd_kcontrol *kcontrol,
1663 				     int event)
1664 {
1665 	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
1666 	u16 boost_path_ctl, boost_path_cfg1;
1667 	u16 reg, reg_mix;
1668 
1669 	if (!strcmp(w->name, "WSA_RX INT0 CHAIN")) {
1670 		boost_path_ctl = CDC_WSA_BOOST0_BOOST_PATH_CTL;
1671 		boost_path_cfg1 = CDC_WSA_RX0_RX_PATH_CFG1;
1672 		reg = CDC_WSA_RX0_RX_PATH_CTL;
1673 		reg_mix = CDC_WSA_RX0_RX_PATH_MIX_CTL;
1674 	} else if (!strcmp(w->name, "WSA_RX INT1 CHAIN")) {
1675 		boost_path_ctl = CDC_WSA_BOOST1_BOOST_PATH_CTL;
1676 		boost_path_cfg1 = CDC_WSA_RX1_RX_PATH_CFG1;
1677 		reg = CDC_WSA_RX1_RX_PATH_CTL;
1678 		reg_mix = CDC_WSA_RX1_RX_PATH_MIX_CTL;
1679 	}
1680 
1681 	switch (event) {
1682 	case SND_SOC_DAPM_PRE_PMU:
1683 		snd_soc_component_update_bits(component, boost_path_cfg1,
1684 					      CDC_WSA_RX_PATH_SMART_BST_EN_MASK,
1685 					      CDC_WSA_RX_PATH_SMART_BST_ENABLE);
1686 		snd_soc_component_update_bits(component, boost_path_ctl,
1687 					      CDC_WSA_BOOST_PATH_CLK_EN_MASK,
1688 					      CDC_WSA_BOOST_PATH_CLK_ENABLE);
1689 		if ((snd_soc_component_read(component, reg_mix)) & 0x10)
1690 			snd_soc_component_update_bits(component, reg_mix,
1691 						0x10, 0x00);
1692 		break;
1693 	case SND_SOC_DAPM_POST_PMU:
1694 		snd_soc_component_update_bits(component, reg, 0x10, 0x00);
1695 		break;
1696 	case SND_SOC_DAPM_POST_PMD:
1697 		snd_soc_component_update_bits(component, boost_path_ctl,
1698 					      CDC_WSA_BOOST_PATH_CLK_EN_MASK,
1699 					      CDC_WSA_BOOST_PATH_CLK_DISABLE);
1700 		snd_soc_component_update_bits(component, boost_path_cfg1,
1701 					      CDC_WSA_RX_PATH_SMART_BST_EN_MASK,
1702 					      CDC_WSA_RX_PATH_SMART_BST_DISABLE);
1703 		break;
1704 	}
1705 
1706 	return 0;
1707 }
1708 
1709 static int wsa_macro_enable_echo(struct snd_soc_dapm_widget *w,
1710 				 struct snd_kcontrol *kcontrol,
1711 				 int event)
1712 {
1713 	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
1714 	struct wsa_macro *wsa = snd_soc_component_get_drvdata(component);
1715 	u16 val, ec_tx, ec_hq_reg;
1716 
1717 	val = snd_soc_component_read(component, CDC_WSA_RX_INP_MUX_RX_MIX_CFG0);
1718 
1719 	switch (w->shift) {
1720 	case WSA_MACRO_EC0_MUX:
1721 		val = val & CDC_WSA_RX_MIX_TX0_SEL_MASK;
1722 		ec_tx = val - 1;
1723 		break;
1724 	case WSA_MACRO_EC1_MUX:
1725 		val = val & CDC_WSA_RX_MIX_TX1_SEL_MASK;
1726 		ec_tx = (val >> CDC_WSA_RX_MIX_TX1_SEL_SHFT) - 1;
1727 		break;
1728 	}
1729 
1730 	if (wsa->ec_hq[ec_tx]) {
1731 		ec_hq_reg = CDC_WSA_EC_HQ0_EC_REF_HQ_PATH_CTL +	0x40 * ec_tx;
1732 		snd_soc_component_update_bits(component, ec_hq_reg,
1733 					     CDC_WSA_EC_HQ_EC_CLK_EN_MASK,
1734 					     CDC_WSA_EC_HQ_EC_CLK_ENABLE);
1735 		ec_hq_reg = CDC_WSA_EC_HQ0_EC_REF_HQ_CFG0 + 0x40 * ec_tx;
1736 		/* default set to 48k */
1737 		snd_soc_component_update_bits(component, ec_hq_reg,
1738 				      CDC_WSA_EC_HQ_EC_REF_PCM_RATE_MASK,
1739 				      CDC_WSA_EC_HQ_EC_REF_PCM_RATE_48K);
1740 	}
1741 
1742 	return 0;
1743 }
1744 
1745 static int wsa_macro_get_ec_hq(struct snd_kcontrol *kcontrol,
1746 			       struct snd_ctl_elem_value *ucontrol)
1747 {
1748 
1749 	struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
1750 	int ec_tx = ((struct soc_mixer_control *) kcontrol->private_value)->shift;
1751 	struct wsa_macro *wsa = snd_soc_component_get_drvdata(component);
1752 
1753 	ucontrol->value.integer.value[0] = wsa->ec_hq[ec_tx];
1754 
1755 	return 0;
1756 }
1757 
1758 static int wsa_macro_set_ec_hq(struct snd_kcontrol *kcontrol,
1759 			       struct snd_ctl_elem_value *ucontrol)
1760 {
1761 	struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
1762 	int ec_tx = ((struct soc_mixer_control *) kcontrol->private_value)->shift;
1763 	int value = ucontrol->value.integer.value[0];
1764 	struct wsa_macro *wsa = snd_soc_component_get_drvdata(component);
1765 
1766 	wsa->ec_hq[ec_tx] = value;
1767 
1768 	return 0;
1769 }
1770 
1771 static int wsa_macro_get_compander(struct snd_kcontrol *kcontrol,
1772 				   struct snd_ctl_elem_value *ucontrol)
1773 {
1774 
1775 	struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
1776 	int comp = ((struct soc_mixer_control *) kcontrol->private_value)->shift;
1777 	struct wsa_macro *wsa = snd_soc_component_get_drvdata(component);
1778 
1779 	ucontrol->value.integer.value[0] = wsa->comp_enabled[comp];
1780 	return 0;
1781 }
1782 
1783 static int wsa_macro_set_compander(struct snd_kcontrol *kcontrol,
1784 				   struct snd_ctl_elem_value *ucontrol)
1785 {
1786 	struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
1787 	int comp = ((struct soc_mixer_control *) kcontrol->private_value)->shift;
1788 	int value = ucontrol->value.integer.value[0];
1789 	struct wsa_macro *wsa = snd_soc_component_get_drvdata(component);
1790 
1791 	wsa->comp_enabled[comp] = value;
1792 
1793 	return 0;
1794 }
1795 
1796 static int wsa_macro_ear_spkr_pa_gain_get(struct snd_kcontrol *kcontrol,
1797 					  struct snd_ctl_elem_value *ucontrol)
1798 {
1799 	struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
1800 	struct wsa_macro *wsa = snd_soc_component_get_drvdata(component);
1801 
1802 	ucontrol->value.integer.value[0] = wsa->ear_spkr_gain;
1803 
1804 	return 0;
1805 }
1806 
1807 static int wsa_macro_ear_spkr_pa_gain_put(struct snd_kcontrol *kcontrol,
1808 					  struct snd_ctl_elem_value *ucontrol)
1809 {
1810 	struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
1811 	struct wsa_macro *wsa = snd_soc_component_get_drvdata(component);
1812 
1813 	wsa->ear_spkr_gain =  ucontrol->value.integer.value[0];
1814 
1815 	return 0;
1816 }
1817 
1818 static int wsa_macro_rx_mux_get(struct snd_kcontrol *kcontrol,
1819 				struct snd_ctl_elem_value *ucontrol)
1820 {
1821 	struct snd_soc_dapm_widget *widget =
1822 		snd_soc_dapm_kcontrol_widget(kcontrol);
1823 	struct snd_soc_component *component =
1824 				snd_soc_dapm_to_component(widget->dapm);
1825 	struct wsa_macro *wsa = snd_soc_component_get_drvdata(component);
1826 
1827 	ucontrol->value.integer.value[0] =
1828 			wsa->rx_port_value[widget->shift];
1829 	return 0;
1830 }
1831 
1832 static int wsa_macro_rx_mux_put(struct snd_kcontrol *kcontrol,
1833 				struct snd_ctl_elem_value *ucontrol)
1834 {
1835 	struct snd_soc_dapm_widget *widget =
1836 		snd_soc_dapm_kcontrol_widget(kcontrol);
1837 	struct snd_soc_component *component =
1838 				snd_soc_dapm_to_component(widget->dapm);
1839 	struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1840 	struct snd_soc_dapm_update *update = NULL;
1841 	u32 rx_port_value = ucontrol->value.integer.value[0];
1842 	u32 bit_input;
1843 	u32 aif_rst;
1844 	struct wsa_macro *wsa = snd_soc_component_get_drvdata(component);
1845 
1846 	aif_rst = wsa->rx_port_value[widget->shift];
1847 	if (!rx_port_value) {
1848 		if (aif_rst == 0) {
1849 			dev_err(component->dev, "%s: AIF reset already\n", __func__);
1850 			return 0;
1851 		}
1852 		if (aif_rst >= WSA_MACRO_RX_MAX) {
1853 			dev_err(component->dev, "%s: Invalid AIF reset\n", __func__);
1854 			return 0;
1855 		}
1856 	}
1857 	wsa->rx_port_value[widget->shift] = rx_port_value;
1858 
1859 	bit_input = widget->shift;
1860 
1861 	switch (rx_port_value) {
1862 	case 0:
1863 		if (wsa->active_ch_cnt[aif_rst]) {
1864 			clear_bit(bit_input,
1865 				  &wsa->active_ch_mask[aif_rst]);
1866 			wsa->active_ch_cnt[aif_rst]--;
1867 		}
1868 		break;
1869 	case 1:
1870 	case 2:
1871 		set_bit(bit_input,
1872 			&wsa->active_ch_mask[rx_port_value]);
1873 		wsa->active_ch_cnt[rx_port_value]++;
1874 		break;
1875 	default:
1876 		dev_err(component->dev,
1877 			"%s: Invalid AIF_ID for WSA RX MUX %d\n",
1878 			__func__, rx_port_value);
1879 		return -EINVAL;
1880 	}
1881 
1882 	snd_soc_dapm_mux_update_power(widget->dapm, kcontrol,
1883 					rx_port_value, e, update);
1884 	return 0;
1885 }
1886 
1887 static int wsa_macro_soft_clip_enable_get(struct snd_kcontrol *kcontrol,
1888 					  struct snd_ctl_elem_value *ucontrol)
1889 {
1890 	struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
1891 	struct wsa_macro *wsa = snd_soc_component_get_drvdata(component);
1892 	int path = ((struct soc_mixer_control *)kcontrol->private_value)->shift;
1893 
1894 	ucontrol->value.integer.value[0] = wsa->is_softclip_on[path];
1895 
1896 	return 0;
1897 }
1898 
1899 static int wsa_macro_soft_clip_enable_put(struct snd_kcontrol *kcontrol,
1900 					  struct snd_ctl_elem_value *ucontrol)
1901 {
1902 	struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
1903 	struct wsa_macro *wsa = snd_soc_component_get_drvdata(component);
1904 	int path = ((struct soc_mixer_control *) kcontrol->private_value)->shift;
1905 
1906 	wsa->is_softclip_on[path] =  ucontrol->value.integer.value[0];
1907 
1908 	return 0;
1909 }
1910 
1911 static const struct snd_kcontrol_new wsa_macro_snd_controls[] = {
1912 	SOC_ENUM_EXT("EAR SPKR PA Gain", wsa_macro_ear_spkr_pa_gain_enum,
1913 		     wsa_macro_ear_spkr_pa_gain_get,
1914 		     wsa_macro_ear_spkr_pa_gain_put),
1915 	SOC_SINGLE_EXT("WSA_Softclip0 Enable", SND_SOC_NOPM,
1916 			WSA_MACRO_SOFTCLIP0, 1, 0,
1917 			wsa_macro_soft_clip_enable_get,
1918 			wsa_macro_soft_clip_enable_put),
1919 	SOC_SINGLE_EXT("WSA_Softclip1 Enable", SND_SOC_NOPM,
1920 			WSA_MACRO_SOFTCLIP1, 1, 0,
1921 			wsa_macro_soft_clip_enable_get,
1922 			wsa_macro_soft_clip_enable_put),
1923 
1924 	SOC_SINGLE_S8_TLV("WSA_RX0 Digital Volume", CDC_WSA_RX0_RX_VOL_CTL,
1925 			  -84, 40, digital_gain),
1926 	SOC_SINGLE_S8_TLV("WSA_RX1 Digital Volume", CDC_WSA_RX1_RX_VOL_CTL,
1927 			  -84, 40, digital_gain),
1928 
1929 	SOC_SINGLE("WSA_RX0 Digital Mute", CDC_WSA_RX0_RX_PATH_CTL, 4, 1, 0),
1930 	SOC_SINGLE("WSA_RX1 Digital Mute", CDC_WSA_RX1_RX_PATH_CTL, 4, 1, 0),
1931 	SOC_SINGLE("WSA_RX0_MIX Digital Mute", CDC_WSA_RX0_RX_PATH_MIX_CTL, 4,
1932 		   1, 0),
1933 	SOC_SINGLE("WSA_RX1_MIX Digital Mute", CDC_WSA_RX1_RX_PATH_MIX_CTL, 4,
1934 		   1, 0),
1935 	SOC_SINGLE_EXT("WSA_COMP1 Switch", SND_SOC_NOPM, WSA_MACRO_COMP1, 1, 0,
1936 		       wsa_macro_get_compander, wsa_macro_set_compander),
1937 	SOC_SINGLE_EXT("WSA_COMP2 Switch", SND_SOC_NOPM, WSA_MACRO_COMP2, 1, 0,
1938 		       wsa_macro_get_compander, wsa_macro_set_compander),
1939 	SOC_SINGLE_EXT("WSA_RX0 EC_HQ Switch", SND_SOC_NOPM, WSA_MACRO_RX0, 1, 0,
1940 		       wsa_macro_get_ec_hq, wsa_macro_set_ec_hq),
1941 	SOC_SINGLE_EXT("WSA_RX1 EC_HQ Switch", SND_SOC_NOPM, WSA_MACRO_RX1, 1, 0,
1942 		       wsa_macro_get_ec_hq, wsa_macro_set_ec_hq),
1943 };
1944 
1945 static const struct soc_enum rx_mux_enum =
1946 	SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(rx_mux_text), rx_mux_text);
1947 
1948 static const struct snd_kcontrol_new rx_mux[WSA_MACRO_RX_MAX] = {
1949 	SOC_DAPM_ENUM_EXT("WSA RX0 Mux", rx_mux_enum,
1950 			  wsa_macro_rx_mux_get, wsa_macro_rx_mux_put),
1951 	SOC_DAPM_ENUM_EXT("WSA RX1 Mux", rx_mux_enum,
1952 			  wsa_macro_rx_mux_get, wsa_macro_rx_mux_put),
1953 	SOC_DAPM_ENUM_EXT("WSA RX_MIX0 Mux", rx_mux_enum,
1954 			  wsa_macro_rx_mux_get, wsa_macro_rx_mux_put),
1955 	SOC_DAPM_ENUM_EXT("WSA RX_MIX1 Mux", rx_mux_enum,
1956 			  wsa_macro_rx_mux_get, wsa_macro_rx_mux_put),
1957 };
1958 
1959 static int wsa_macro_vi_feed_mixer_get(struct snd_kcontrol *kcontrol,
1960 				       struct snd_ctl_elem_value *ucontrol)
1961 {
1962 	struct snd_soc_dapm_widget *widget = snd_soc_dapm_kcontrol_widget(kcontrol);
1963 	struct snd_soc_component *component = snd_soc_dapm_to_component(widget->dapm);
1964 	struct soc_mixer_control *mixer = (struct soc_mixer_control *)kcontrol->private_value;
1965 	struct wsa_macro *wsa = snd_soc_component_get_drvdata(component);
1966 	u32 spk_tx_id = mixer->shift;
1967 	u32 dai_id = widget->shift;
1968 
1969 	if (test_bit(spk_tx_id, &wsa->active_ch_mask[dai_id]))
1970 		ucontrol->value.integer.value[0] = 1;
1971 	else
1972 		ucontrol->value.integer.value[0] = 0;
1973 
1974 	return 0;
1975 }
1976 
1977 static int wsa_macro_vi_feed_mixer_put(struct snd_kcontrol *kcontrol,
1978 				       struct snd_ctl_elem_value *ucontrol)
1979 {
1980 	struct snd_soc_dapm_widget *widget = snd_soc_dapm_kcontrol_widget(kcontrol);
1981 	struct snd_soc_component *component = snd_soc_dapm_to_component(widget->dapm);
1982 	struct soc_mixer_control *mixer = (struct soc_mixer_control *)kcontrol->private_value;
1983 	struct wsa_macro *wsa = snd_soc_component_get_drvdata(component);
1984 	u32 enable = ucontrol->value.integer.value[0];
1985 	u32 spk_tx_id = mixer->shift;
1986 
1987 	if (enable) {
1988 		if (spk_tx_id == WSA_MACRO_TX0 &&
1989 			!test_bit(WSA_MACRO_TX0,
1990 				&wsa->active_ch_mask[WSA_MACRO_AIF_VI])) {
1991 			set_bit(WSA_MACRO_TX0,
1992 				&wsa->active_ch_mask[WSA_MACRO_AIF_VI]);
1993 			wsa->active_ch_cnt[WSA_MACRO_AIF_VI]++;
1994 		}
1995 		if (spk_tx_id == WSA_MACRO_TX1 &&
1996 			!test_bit(WSA_MACRO_TX1,
1997 				&wsa->active_ch_mask[WSA_MACRO_AIF_VI])) {
1998 			set_bit(WSA_MACRO_TX1,
1999 				&wsa->active_ch_mask[WSA_MACRO_AIF_VI]);
2000 			wsa->active_ch_cnt[WSA_MACRO_AIF_VI]++;
2001 		}
2002 	} else {
2003 		if (spk_tx_id == WSA_MACRO_TX0 &&
2004 			test_bit(WSA_MACRO_TX0,
2005 				&wsa->active_ch_mask[WSA_MACRO_AIF_VI])) {
2006 			clear_bit(WSA_MACRO_TX0,
2007 				&wsa->active_ch_mask[WSA_MACRO_AIF_VI]);
2008 			wsa->active_ch_cnt[WSA_MACRO_AIF_VI]--;
2009 		}
2010 		if (spk_tx_id == WSA_MACRO_TX1 &&
2011 			test_bit(WSA_MACRO_TX1,
2012 				&wsa->active_ch_mask[WSA_MACRO_AIF_VI])) {
2013 			clear_bit(WSA_MACRO_TX1,
2014 				&wsa->active_ch_mask[WSA_MACRO_AIF_VI]);
2015 			wsa->active_ch_cnt[WSA_MACRO_AIF_VI]--;
2016 		}
2017 	}
2018 	snd_soc_dapm_mixer_update_power(widget->dapm, kcontrol, enable, NULL);
2019 
2020 	return 0;
2021 }
2022 
2023 static const struct snd_kcontrol_new aif_vi_mixer[] = {
2024 	SOC_SINGLE_EXT("WSA_SPKR_VI_1", SND_SOC_NOPM, WSA_MACRO_TX0, 1, 0,
2025 			wsa_macro_vi_feed_mixer_get,
2026 			wsa_macro_vi_feed_mixer_put),
2027 	SOC_SINGLE_EXT("WSA_SPKR_VI_2", SND_SOC_NOPM, WSA_MACRO_TX1, 1, 0,
2028 			wsa_macro_vi_feed_mixer_get,
2029 			wsa_macro_vi_feed_mixer_put),
2030 };
2031 
2032 static const struct snd_soc_dapm_widget wsa_macro_dapm_widgets[] = {
2033 	SND_SOC_DAPM_AIF_IN("WSA AIF1 PB", "WSA_AIF1 Playback", 0,
2034 			    SND_SOC_NOPM, 0, 0),
2035 	SND_SOC_DAPM_AIF_IN("WSA AIF_MIX1 PB", "WSA_AIF_MIX1 Playback", 0,
2036 			    SND_SOC_NOPM, 0, 0),
2037 
2038 	SND_SOC_DAPM_AIF_OUT_E("WSA AIF_VI", "WSA_AIF_VI Capture", 0,
2039 			       SND_SOC_NOPM, WSA_MACRO_AIF_VI, 0,
2040 			       wsa_macro_enable_vi_feedback,
2041 			       SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
2042 	SND_SOC_DAPM_AIF_OUT("WSA AIF_ECHO", "WSA_AIF_ECHO Capture", 0,
2043 			     SND_SOC_NOPM, 0, 0),
2044 
2045 	SND_SOC_DAPM_MIXER("WSA_AIF_VI Mixer", SND_SOC_NOPM, WSA_MACRO_AIF_VI,
2046 			   0, aif_vi_mixer, ARRAY_SIZE(aif_vi_mixer)),
2047 	SND_SOC_DAPM_MUX_E("WSA RX_MIX EC0_MUX", SND_SOC_NOPM,
2048 			   WSA_MACRO_EC0_MUX, 0,
2049 			   &rx_mix_ec0_mux, wsa_macro_enable_echo,
2050 			   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
2051 	SND_SOC_DAPM_MUX_E("WSA RX_MIX EC1_MUX", SND_SOC_NOPM,
2052 			   WSA_MACRO_EC1_MUX, 0,
2053 			   &rx_mix_ec1_mux, wsa_macro_enable_echo,
2054 			   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
2055 
2056 	SND_SOC_DAPM_MUX("WSA RX0 MUX", SND_SOC_NOPM, WSA_MACRO_RX0, 0,
2057 			 &rx_mux[WSA_MACRO_RX0]),
2058 	SND_SOC_DAPM_MUX("WSA RX1 MUX", SND_SOC_NOPM, WSA_MACRO_RX1, 0,
2059 			 &rx_mux[WSA_MACRO_RX1]),
2060 	SND_SOC_DAPM_MUX("WSA RX_MIX0 MUX", SND_SOC_NOPM, WSA_MACRO_RX_MIX0, 0,
2061 			 &rx_mux[WSA_MACRO_RX_MIX0]),
2062 	SND_SOC_DAPM_MUX("WSA RX_MIX1 MUX", SND_SOC_NOPM, WSA_MACRO_RX_MIX1, 0,
2063 			 &rx_mux[WSA_MACRO_RX_MIX1]),
2064 
2065 	SND_SOC_DAPM_MIXER("WSA RX0", SND_SOC_NOPM, 0, 0, NULL, 0),
2066 	SND_SOC_DAPM_MIXER("WSA RX1", SND_SOC_NOPM, 0, 0, NULL, 0),
2067 	SND_SOC_DAPM_MIXER("WSA RX_MIX0", SND_SOC_NOPM, 0, 0, NULL, 0),
2068 	SND_SOC_DAPM_MIXER("WSA RX_MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
2069 
2070 	SND_SOC_DAPM_MUX("WSA_RX0 INP0", SND_SOC_NOPM, 0, 0, &rx0_prim_inp0_mux),
2071 	SND_SOC_DAPM_MUX("WSA_RX0 INP1", SND_SOC_NOPM, 0, 0, &rx0_prim_inp1_mux),
2072 	SND_SOC_DAPM_MUX("WSA_RX0 INP2", SND_SOC_NOPM, 0, 0, &rx0_prim_inp2_mux),
2073 	SND_SOC_DAPM_MUX_E("WSA_RX0 MIX INP", SND_SOC_NOPM, WSA_MACRO_RX_MIX0,
2074 			   0, &rx0_mix_mux, wsa_macro_enable_mix_path,
2075 			   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
2076 	SND_SOC_DAPM_MUX("WSA_RX1 INP0", SND_SOC_NOPM, 0, 0, &rx1_prim_inp0_mux),
2077 	SND_SOC_DAPM_MUX("WSA_RX1 INP1", SND_SOC_NOPM, 0, 0, &rx1_prim_inp1_mux),
2078 	SND_SOC_DAPM_MUX("WSA_RX1 INP2", SND_SOC_NOPM, 0, 0, &rx1_prim_inp2_mux),
2079 	SND_SOC_DAPM_MUX_E("WSA_RX1 MIX INP", SND_SOC_NOPM, WSA_MACRO_RX_MIX1,
2080 			   0, &rx1_mix_mux, wsa_macro_enable_mix_path,
2081 			   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
2082 
2083 	SND_SOC_DAPM_MIXER_E("WSA_RX INT0 MIX", SND_SOC_NOPM, 0, 0, NULL, 0,
2084 			     wsa_macro_enable_main_path, SND_SOC_DAPM_PRE_PMU),
2085 	SND_SOC_DAPM_MIXER_E("WSA_RX INT1 MIX", SND_SOC_NOPM, 1, 0, NULL, 0,
2086 			     wsa_macro_enable_main_path, SND_SOC_DAPM_PRE_PMU),
2087 
2088 	SND_SOC_DAPM_MIXER("WSA_RX INT0 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
2089 	SND_SOC_DAPM_MIXER("WSA_RX INT1 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
2090 
2091 	SND_SOC_DAPM_MUX("WSA_RX0 INT0 SIDETONE MIX", CDC_WSA_RX0_RX_PATH_CFG1,
2092 			 4, 0, &rx0_sidetone_mix_mux),
2093 
2094 	SND_SOC_DAPM_INPUT("WSA SRC0_INP"),
2095 	SND_SOC_DAPM_INPUT("WSA_TX DEC0_INP"),
2096 	SND_SOC_DAPM_INPUT("WSA_TX DEC1_INP"),
2097 
2098 	SND_SOC_DAPM_MIXER_E("WSA_RX INT0 INTERP", SND_SOC_NOPM,
2099 			     WSA_MACRO_COMP1, 0, NULL, 0,
2100 			     wsa_macro_enable_interpolator,
2101 			     SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
2102 			     SND_SOC_DAPM_POST_PMD),
2103 
2104 	SND_SOC_DAPM_MIXER_E("WSA_RX INT1 INTERP", SND_SOC_NOPM,
2105 			     WSA_MACRO_COMP2, 0, NULL, 0,
2106 			     wsa_macro_enable_interpolator,
2107 			     SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
2108 			     SND_SOC_DAPM_POST_PMD),
2109 
2110 	SND_SOC_DAPM_MIXER_E("WSA_RX INT0 CHAIN", SND_SOC_NOPM, 0, 0,
2111 			     NULL, 0, wsa_macro_spk_boost_event,
2112 			     SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
2113 			     SND_SOC_DAPM_POST_PMD),
2114 
2115 	SND_SOC_DAPM_MIXER_E("WSA_RX INT1 CHAIN", SND_SOC_NOPM, 0, 0,
2116 			     NULL, 0, wsa_macro_spk_boost_event,
2117 			     SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
2118 			     SND_SOC_DAPM_POST_PMD),
2119 
2120 	SND_SOC_DAPM_INPUT("VIINPUT_WSA"),
2121 	SND_SOC_DAPM_OUTPUT("WSA_SPK1 OUT"),
2122 	SND_SOC_DAPM_OUTPUT("WSA_SPK2 OUT"),
2123 
2124 	SND_SOC_DAPM_SUPPLY("WSA_RX0_CLK", CDC_WSA_RX0_RX_PATH_CTL, 5, 0, NULL, 0),
2125 	SND_SOC_DAPM_SUPPLY("WSA_RX1_CLK", CDC_WSA_RX1_RX_PATH_CTL, 5, 0, NULL, 0),
2126 	SND_SOC_DAPM_SUPPLY("WSA_RX_MIX0_CLK", CDC_WSA_RX0_RX_PATH_MIX_CTL, 5, 0, NULL, 0),
2127 	SND_SOC_DAPM_SUPPLY("WSA_RX_MIX1_CLK", CDC_WSA_RX1_RX_PATH_MIX_CTL, 5, 0, NULL, 0),
2128 	SND_SOC_DAPM_SUPPLY_S("WSA_MCLK", 0, SND_SOC_NOPM, 0, 0,
2129 			      wsa_macro_mclk_event,
2130 			      SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
2131 };
2132 
2133 static const struct snd_soc_dapm_route wsa_audio_map[] = {
2134 	/* VI Feedback */
2135 	{"WSA_AIF_VI Mixer", "WSA_SPKR_VI_1", "VIINPUT_WSA"},
2136 	{"WSA_AIF_VI Mixer", "WSA_SPKR_VI_2", "VIINPUT_WSA"},
2137 	{"WSA AIF_VI", NULL, "WSA_AIF_VI Mixer"},
2138 	{"WSA AIF_VI", NULL, "WSA_MCLK"},
2139 
2140 	{"WSA RX_MIX EC0_MUX", "RX_MIX_TX0", "WSA_RX INT0 SEC MIX"},
2141 	{"WSA RX_MIX EC1_MUX", "RX_MIX_TX0", "WSA_RX INT0 SEC MIX"},
2142 	{"WSA RX_MIX EC0_MUX", "RX_MIX_TX1", "WSA_RX INT1 SEC MIX"},
2143 	{"WSA RX_MIX EC1_MUX", "RX_MIX_TX1", "WSA_RX INT1 SEC MIX"},
2144 	{"WSA AIF_ECHO", NULL, "WSA RX_MIX EC0_MUX"},
2145 	{"WSA AIF_ECHO", NULL, "WSA RX_MIX EC1_MUX"},
2146 	{"WSA AIF_ECHO", NULL, "WSA_MCLK"},
2147 
2148 	{"WSA AIF1 PB", NULL, "WSA_MCLK"},
2149 	{"WSA AIF_MIX1 PB", NULL, "WSA_MCLK"},
2150 
2151 	{"WSA RX0 MUX", "AIF1_PB", "WSA AIF1 PB"},
2152 	{"WSA RX1 MUX", "AIF1_PB", "WSA AIF1 PB"},
2153 	{"WSA RX_MIX0 MUX", "AIF1_PB", "WSA AIF1 PB"},
2154 	{"WSA RX_MIX1 MUX", "AIF1_PB", "WSA AIF1 PB"},
2155 
2156 	{"WSA RX0 MUX", "AIF_MIX1_PB", "WSA AIF_MIX1 PB"},
2157 	{"WSA RX1 MUX", "AIF_MIX1_PB", "WSA AIF_MIX1 PB"},
2158 	{"WSA RX_MIX0 MUX", "AIF_MIX1_PB", "WSA AIF_MIX1 PB"},
2159 	{"WSA RX_MIX1 MUX", "AIF_MIX1_PB", "WSA AIF_MIX1 PB"},
2160 
2161 	{"WSA RX0", NULL, "WSA RX0 MUX"},
2162 	{"WSA RX1", NULL, "WSA RX1 MUX"},
2163 	{"WSA RX_MIX0", NULL, "WSA RX_MIX0 MUX"},
2164 	{"WSA RX_MIX1", NULL, "WSA RX_MIX1 MUX"},
2165 
2166 	{"WSA RX0", NULL, "WSA_RX0_CLK"},
2167 	{"WSA RX1", NULL, "WSA_RX1_CLK"},
2168 	{"WSA RX_MIX0", NULL, "WSA_RX_MIX0_CLK"},
2169 	{"WSA RX_MIX1", NULL, "WSA_RX_MIX1_CLK"},
2170 
2171 	{"WSA_RX0 INP0", "RX0", "WSA RX0"},
2172 	{"WSA_RX0 INP0", "RX1", "WSA RX1"},
2173 	{"WSA_RX0 INP0", "RX_MIX0", "WSA RX_MIX0"},
2174 	{"WSA_RX0 INP0", "RX_MIX1", "WSA RX_MIX1"},
2175 	{"WSA_RX0 INP0", "DEC0", "WSA_TX DEC0_INP"},
2176 	{"WSA_RX0 INP0", "DEC1", "WSA_TX DEC1_INP"},
2177 	{"WSA_RX INT0 MIX", NULL, "WSA_RX0 INP0"},
2178 
2179 	{"WSA_RX0 INP1", "RX0", "WSA RX0"},
2180 	{"WSA_RX0 INP1", "RX1", "WSA RX1"},
2181 	{"WSA_RX0 INP1", "RX_MIX0", "WSA RX_MIX0"},
2182 	{"WSA_RX0 INP1", "RX_MIX1", "WSA RX_MIX1"},
2183 	{"WSA_RX0 INP1", "DEC0", "WSA_TX DEC0_INP"},
2184 	{"WSA_RX0 INP1", "DEC1", "WSA_TX DEC1_INP"},
2185 	{"WSA_RX INT0 MIX", NULL, "WSA_RX0 INP1"},
2186 
2187 	{"WSA_RX0 INP2", "RX0", "WSA RX0"},
2188 	{"WSA_RX0 INP2", "RX1", "WSA RX1"},
2189 	{"WSA_RX0 INP2", "RX_MIX0", "WSA RX_MIX0"},
2190 	{"WSA_RX0 INP2", "RX_MIX1", "WSA RX_MIX1"},
2191 	{"WSA_RX0 INP2", "DEC0", "WSA_TX DEC0_INP"},
2192 	{"WSA_RX0 INP2", "DEC1", "WSA_TX DEC1_INP"},
2193 	{"WSA_RX INT0 MIX", NULL, "WSA_RX0 INP2"},
2194 
2195 	{"WSA_RX0 MIX INP", "RX0", "WSA RX0"},
2196 	{"WSA_RX0 MIX INP", "RX1", "WSA RX1"},
2197 	{"WSA_RX0 MIX INP", "RX_MIX0", "WSA RX_MIX0"},
2198 	{"WSA_RX0 MIX INP", "RX_MIX1", "WSA RX_MIX1"},
2199 	{"WSA_RX INT0 SEC MIX", NULL, "WSA_RX0 MIX INP"},
2200 
2201 	{"WSA_RX INT0 SEC MIX", NULL, "WSA_RX INT0 MIX"},
2202 	{"WSA_RX INT0 INTERP", NULL, "WSA_RX INT0 SEC MIX"},
2203 	{"WSA_RX0 INT0 SIDETONE MIX", "SRC0", "WSA SRC0_INP"},
2204 	{"WSA_RX INT0 INTERP", NULL, "WSA_RX0 INT0 SIDETONE MIX"},
2205 	{"WSA_RX INT0 CHAIN", NULL, "WSA_RX INT0 INTERP"},
2206 
2207 	{"WSA_SPK1 OUT", NULL, "WSA_RX INT0 CHAIN"},
2208 	{"WSA_SPK1 OUT", NULL, "WSA_MCLK"},
2209 
2210 	{"WSA_RX1 INP0", "RX0", "WSA RX0"},
2211 	{"WSA_RX1 INP0", "RX1", "WSA RX1"},
2212 	{"WSA_RX1 INP0", "RX_MIX0", "WSA RX_MIX0"},
2213 	{"WSA_RX1 INP0", "RX_MIX1", "WSA RX_MIX1"},
2214 	{"WSA_RX1 INP0", "DEC0", "WSA_TX DEC0_INP"},
2215 	{"WSA_RX1 INP0", "DEC1", "WSA_TX DEC1_INP"},
2216 	{"WSA_RX INT1 MIX", NULL, "WSA_RX1 INP0"},
2217 
2218 	{"WSA_RX1 INP1", "RX0", "WSA RX0"},
2219 	{"WSA_RX1 INP1", "RX1", "WSA RX1"},
2220 	{"WSA_RX1 INP1", "RX_MIX0", "WSA RX_MIX0"},
2221 	{"WSA_RX1 INP1", "RX_MIX1", "WSA RX_MIX1"},
2222 	{"WSA_RX1 INP1", "DEC0", "WSA_TX DEC0_INP"},
2223 	{"WSA_RX1 INP1", "DEC1", "WSA_TX DEC1_INP"},
2224 	{"WSA_RX INT1 MIX", NULL, "WSA_RX1 INP1"},
2225 
2226 	{"WSA_RX1 INP2", "RX0", "WSA RX0"},
2227 	{"WSA_RX1 INP2", "RX1", "WSA RX1"},
2228 	{"WSA_RX1 INP2", "RX_MIX0", "WSA RX_MIX0"},
2229 	{"WSA_RX1 INP2", "RX_MIX1", "WSA RX_MIX1"},
2230 	{"WSA_RX1 INP2", "DEC0", "WSA_TX DEC0_INP"},
2231 	{"WSA_RX1 INP2", "DEC1", "WSA_TX DEC1_INP"},
2232 	{"WSA_RX INT1 MIX", NULL, "WSA_RX1 INP2"},
2233 
2234 	{"WSA_RX1 MIX INP", "RX0", "WSA RX0"},
2235 	{"WSA_RX1 MIX INP", "RX1", "WSA RX1"},
2236 	{"WSA_RX1 MIX INP", "RX_MIX0", "WSA RX_MIX0"},
2237 	{"WSA_RX1 MIX INP", "RX_MIX1", "WSA RX_MIX1"},
2238 	{"WSA_RX INT1 SEC MIX", NULL, "WSA_RX1 MIX INP"},
2239 
2240 	{"WSA_RX INT1 SEC MIX", NULL, "WSA_RX INT1 MIX"},
2241 	{"WSA_RX INT1 INTERP", NULL, "WSA_RX INT1 SEC MIX"},
2242 
2243 	{"WSA_RX INT1 CHAIN", NULL, "WSA_RX INT1 INTERP"},
2244 	{"WSA_SPK2 OUT", NULL, "WSA_RX INT1 CHAIN"},
2245 	{"WSA_SPK2 OUT", NULL, "WSA_MCLK"},
2246 };
2247 
2248 static int wsa_swrm_clock(struct wsa_macro *wsa, bool enable)
2249 {
2250 	struct regmap *regmap = wsa->regmap;
2251 
2252 	if (enable) {
2253 		wsa_macro_mclk_enable(wsa, true);
2254 
2255 		/* reset swr ip */
2256 		if (wsa->reset_swr)
2257 			regmap_update_bits(regmap,
2258 					   CDC_WSA_CLK_RST_CTRL_SWR_CONTROL,
2259 					   CDC_WSA_SWR_RST_EN_MASK,
2260 					   CDC_WSA_SWR_RST_ENABLE);
2261 
2262 		regmap_update_bits(regmap, CDC_WSA_CLK_RST_CTRL_SWR_CONTROL,
2263 				   CDC_WSA_SWR_CLK_EN_MASK,
2264 				   CDC_WSA_SWR_CLK_ENABLE);
2265 
2266 		/* Bring out of reset */
2267 		if (wsa->reset_swr)
2268 			regmap_update_bits(regmap,
2269 					   CDC_WSA_CLK_RST_CTRL_SWR_CONTROL,
2270 					   CDC_WSA_SWR_RST_EN_MASK,
2271 					   CDC_WSA_SWR_RST_DISABLE);
2272 		wsa->reset_swr = false;
2273 	} else {
2274 		regmap_update_bits(regmap, CDC_WSA_CLK_RST_CTRL_SWR_CONTROL,
2275 				   CDC_WSA_SWR_CLK_EN_MASK, 0);
2276 		wsa_macro_mclk_enable(wsa, false);
2277 	}
2278 
2279 	return 0;
2280 }
2281 
2282 static int wsa_macro_component_probe(struct snd_soc_component *comp)
2283 {
2284 	struct wsa_macro *wsa = snd_soc_component_get_drvdata(comp);
2285 
2286 	snd_soc_component_init_regmap(comp, wsa->regmap);
2287 
2288 	wsa->spkr_gain_offset = WSA_MACRO_GAIN_OFFSET_M1P5_DB;
2289 
2290 	/* set SPKR rate to FS_2P4_3P072 */
2291 	snd_soc_component_update_bits(comp, CDC_WSA_RX0_RX_PATH_CFG1,
2292 				CDC_WSA_RX_PATH_SPKR_RATE_MASK,
2293 				CDC_WSA_RX_PATH_SPKR_RATE_FS_2P4_3P072);
2294 
2295 	snd_soc_component_update_bits(comp, CDC_WSA_RX1_RX_PATH_CFG1,
2296 				CDC_WSA_RX_PATH_SPKR_RATE_MASK,
2297 				CDC_WSA_RX_PATH_SPKR_RATE_FS_2P4_3P072);
2298 
2299 	wsa_macro_set_spkr_mode(comp, WSA_MACRO_SPKR_MODE_1);
2300 
2301 	return 0;
2302 }
2303 
2304 static int swclk_gate_enable(struct clk_hw *hw)
2305 {
2306 	return wsa_swrm_clock(to_wsa_macro(hw), true);
2307 }
2308 
2309 static void swclk_gate_disable(struct clk_hw *hw)
2310 {
2311 	wsa_swrm_clock(to_wsa_macro(hw), false);
2312 }
2313 
2314 static int swclk_gate_is_enabled(struct clk_hw *hw)
2315 {
2316 	struct wsa_macro *wsa = to_wsa_macro(hw);
2317 	int ret, val;
2318 
2319 	regmap_read(wsa->regmap, CDC_WSA_CLK_RST_CTRL_SWR_CONTROL, &val);
2320 	ret = val & BIT(0);
2321 
2322 	return ret;
2323 }
2324 
2325 static unsigned long swclk_recalc_rate(struct clk_hw *hw,
2326 				       unsigned long parent_rate)
2327 {
2328 	return parent_rate / 2;
2329 }
2330 
2331 static const struct clk_ops swclk_gate_ops = {
2332 	.prepare = swclk_gate_enable,
2333 	.unprepare = swclk_gate_disable,
2334 	.is_enabled = swclk_gate_is_enabled,
2335 	.recalc_rate = swclk_recalc_rate,
2336 };
2337 
2338 static struct clk *wsa_macro_register_mclk_output(struct wsa_macro *wsa)
2339 {
2340 	struct device *dev = wsa->dev;
2341 	struct device_node *np = dev->of_node;
2342 	const char *parent_clk_name;
2343 	const char *clk_name = "mclk";
2344 	struct clk_hw *hw;
2345 	struct clk_init_data init;
2346 	int ret;
2347 
2348 	parent_clk_name = __clk_get_name(wsa->clks[2].clk);
2349 
2350 	init.name = clk_name;
2351 	init.ops = &swclk_gate_ops;
2352 	init.flags = 0;
2353 	init.parent_names = &parent_clk_name;
2354 	init.num_parents = 1;
2355 	wsa->hw.init = &init;
2356 	hw = &wsa->hw;
2357 	ret = clk_hw_register(wsa->dev, hw);
2358 	if (ret)
2359 		return ERR_PTR(ret);
2360 
2361 	of_clk_add_provider(np, of_clk_src_simple_get, hw->clk);
2362 
2363 	return NULL;
2364 }
2365 
2366 static const struct snd_soc_component_driver wsa_macro_component_drv = {
2367 	.name = "WSA MACRO",
2368 	.probe = wsa_macro_component_probe,
2369 	.controls = wsa_macro_snd_controls,
2370 	.num_controls = ARRAY_SIZE(wsa_macro_snd_controls),
2371 	.dapm_widgets = wsa_macro_dapm_widgets,
2372 	.num_dapm_widgets = ARRAY_SIZE(wsa_macro_dapm_widgets),
2373 	.dapm_routes = wsa_audio_map,
2374 	.num_dapm_routes = ARRAY_SIZE(wsa_audio_map),
2375 };
2376 
2377 static int wsa_macro_probe(struct platform_device *pdev)
2378 {
2379 	struct device *dev = &pdev->dev;
2380 	struct wsa_macro *wsa;
2381 	void __iomem *base;
2382 	int ret;
2383 
2384 	wsa = devm_kzalloc(dev, sizeof(*wsa), GFP_KERNEL);
2385 	if (!wsa)
2386 		return -ENOMEM;
2387 
2388 	wsa->clks[0].id = "macro";
2389 	wsa->clks[1].id = "dcodec";
2390 	wsa->clks[2].id = "mclk";
2391 	wsa->clks[3].id = "npl";
2392 	wsa->clks[4].id = "fsgen";
2393 
2394 	ret = devm_clk_bulk_get(dev, WSA_NUM_CLKS_MAX, wsa->clks);
2395 	if (ret) {
2396 		dev_err(dev, "Error getting WSA Clocks (%d)\n", ret);
2397 		return ret;
2398 	}
2399 
2400 	base = devm_platform_ioremap_resource(pdev, 0);
2401 	if (IS_ERR(base))
2402 		return PTR_ERR(base);
2403 
2404 	wsa->regmap = devm_regmap_init_mmio(dev, base, &wsa_regmap_config);
2405 
2406 	dev_set_drvdata(dev, wsa);
2407 
2408 	wsa->reset_swr = true;
2409 	wsa->dev = dev;
2410 
2411 	/* set MCLK and NPL rates */
2412 	clk_set_rate(wsa->clks[2].clk, WSA_MACRO_MCLK_FREQ);
2413 	clk_set_rate(wsa->clks[3].clk, WSA_MACRO_MCLK_FREQ);
2414 
2415 	ret = clk_bulk_prepare_enable(WSA_NUM_CLKS_MAX, wsa->clks);
2416 	if (ret)
2417 		return ret;
2418 
2419 	wsa_macro_register_mclk_output(wsa);
2420 
2421 	ret = devm_snd_soc_register_component(dev, &wsa_macro_component_drv,
2422 					      wsa_macro_dai,
2423 					      ARRAY_SIZE(wsa_macro_dai));
2424 	if (ret)
2425 		goto err;
2426 
2427 	return ret;
2428 err:
2429 	clk_bulk_disable_unprepare(WSA_NUM_CLKS_MAX, wsa->clks);
2430 
2431 	return ret;
2432 
2433 }
2434 
2435 static int wsa_macro_remove(struct platform_device *pdev)
2436 {
2437 	struct wsa_macro *wsa = dev_get_drvdata(&pdev->dev);
2438 
2439 	of_clk_del_provider(pdev->dev.of_node);
2440 
2441 	clk_bulk_disable_unprepare(WSA_NUM_CLKS_MAX, wsa->clks);
2442 
2443 	return 0;
2444 }
2445 
2446 static const struct of_device_id wsa_macro_dt_match[] = {
2447 	{.compatible = "qcom,sm8250-lpass-wsa-macro"},
2448 	{}
2449 };
2450 MODULE_DEVICE_TABLE(of, wsa_macro_dt_match);
2451 
2452 static struct platform_driver wsa_macro_driver = {
2453 	.driver = {
2454 		.name = "wsa_macro",
2455 		.of_match_table = wsa_macro_dt_match,
2456 	},
2457 	.probe = wsa_macro_probe,
2458 	.remove = wsa_macro_remove,
2459 };
2460 
2461 module_platform_driver(wsa_macro_driver);
2462 MODULE_DESCRIPTION("WSA macro driver");
2463 MODULE_LICENSE("GPL");
2464