xref: /linux/sound/soc/codecs/da7213.h (revision ba199dc909a20fe62270ae4e93f263987bb9d119)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * da7213.h - DA7213 ASoC Codec Driver
4  *
5  * Copyright (c) 2013 Dialog Semiconductor
6  *
7  * Author: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
8  * Author: David Rau <David.Rau.opensource@dm.renesas.com>
9  */
10 
11 #ifndef _DA7213_H
12 #define _DA7213_H
13 
14 #include <linux/clk.h>
15 #include <linux/regmap.h>
16 #include <linux/regulator/consumer.h>
17 #include <sound/da7213.h>
18 
19 /*
20  * Registers
21  */
22 
23 /* Status Registers */
24 #define DA7213_STATUS1			0x02
25 #define DA7213_PLL_STATUS		0x03
26 #define DA7213_AUX_L_GAIN_STATUS	0x04
27 #define DA7213_AUX_R_GAIN_STATUS	0x05
28 #define DA7213_MIC_1_GAIN_STATUS	0x06
29 #define DA7213_MIC_2_GAIN_STATUS	0x07
30 #define DA7213_MIXIN_L_GAIN_STATUS	0x08
31 #define DA7213_MIXIN_R_GAIN_STATUS	0x09
32 #define DA7213_ADC_L_GAIN_STATUS	0x0A
33 #define DA7213_ADC_R_GAIN_STATUS	0x0B
34 #define DA7213_DAC_L_GAIN_STATUS	0x0C
35 #define DA7213_DAC_R_GAIN_STATUS	0x0D
36 #define DA7213_HP_L_GAIN_STATUS		0x0E
37 #define DA7213_HP_R_GAIN_STATUS		0x0F
38 #define DA7213_LINE_GAIN_STATUS		0x10
39 
40 /* System Initialisation Registers */
41 #define DA7213_DIG_ROUTING_DAI		0x21
42 #define DA7213_SR			0x22
43 #define DA7213_REFERENCES		0x23
44 #define DA7213_PLL_FRAC_TOP		0x24
45 #define DA7213_PLL_FRAC_BOT		0x25
46 #define DA7213_PLL_INTEGER		0x26
47 #define DA7213_PLL_CTRL			0x27
48 #define DA7213_DAI_CLK_MODE		0x28
49 #define DA7213_DAI_CTRL			0x29
50 #define DA7213_DIG_ROUTING_DAC		0x2A
51 #define DA7213_ALC_CTRL1		0x2B
52 
53 /* Input - Gain, Select and Filter Registers */
54 #define DA7213_AUX_L_GAIN		0x30
55 #define DA7213_AUX_R_GAIN		0x31
56 #define DA7213_MIXIN_L_SELECT		0x32
57 #define DA7213_MIXIN_R_SELECT		0x33
58 #define DA7213_MIXIN_L_GAIN		0x34
59 #define DA7213_MIXIN_R_GAIN		0x35
60 #define DA7213_ADC_L_GAIN		0x36
61 #define DA7213_ADC_R_GAIN		0x37
62 #define DA7213_ADC_FILTERS1		0x38
63 #define DA7213_MIC_1_GAIN		0x39
64 #define DA7213_MIC_2_GAIN		0x3A
65 
66 /* Output - Gain, Select and Filter Registers */
67 #define DA7213_DAC_FILTERS5		0x40
68 #define DA7213_DAC_FILTERS2		0x41
69 #define DA7213_DAC_FILTERS3		0x42
70 #define DA7213_DAC_FILTERS4		0x43
71 #define DA7213_DAC_FILTERS1		0x44
72 #define DA7213_DAC_L_GAIN		0x45
73 #define DA7213_DAC_R_GAIN		0x46
74 #define DA7213_CP_CTRL			0x47
75 #define DA7213_HP_L_GAIN		0x48
76 #define DA7213_HP_R_GAIN		0x49
77 #define DA7213_LINE_GAIN		0x4A
78 #define DA7213_MIXOUT_L_SELECT		0x4B
79 #define DA7213_MIXOUT_R_SELECT		0x4C
80 
81 /* System Controller Registers */
82 #define DA7213_SYSTEM_MODES_INPUT	0x50
83 #define DA7213_SYSTEM_MODES_OUTPUT	0x51
84 
85 /* Control Registers */
86 #define DA7213_AUX_L_CTRL		0x60
87 #define DA7213_AUX_R_CTRL		0x61
88 #define DA7213_MICBIAS_CTRL		0x62
89 #define DA7213_MIC_1_CTRL		0x63
90 #define DA7213_MIC_2_CTRL		0x64
91 #define DA7213_MIXIN_L_CTRL		0x65
92 #define DA7213_MIXIN_R_CTRL		0x66
93 #define DA7213_ADC_L_CTRL		0x67
94 #define DA7213_ADC_R_CTRL		0x68
95 #define DA7213_DAC_L_CTRL		0x69
96 #define DA7213_DAC_R_CTRL		0x6A
97 #define DA7213_HP_L_CTRL		0x6B
98 #define DA7213_HP_R_CTRL		0x6C
99 #define DA7213_LINE_CTRL		0x6D
100 #define DA7213_MIXOUT_L_CTRL		0x6E
101 #define DA7213_MIXOUT_R_CTRL		0x6F
102 
103 /* Configuration Registers */
104 #define DA7213_LDO_CTRL			0x90
105 #define DA7213_IO_CTRL			0x91
106 #define DA7213_GAIN_RAMP_CTRL		0x92
107 #define DA7213_MIC_CONFIG		0x93
108 #define DA7213_PC_COUNT			0x94
109 #define DA7213_CP_VOL_THRESHOLD1	0x95
110 #define DA7213_CP_DELAY			0x96
111 #define DA7213_CP_DETECTOR		0x97
112 #define DA7213_DAI_OFFSET		0x98
113 #define DA7213_DIG_CTRL			0x99
114 #define DA7213_ALC_CTRL2		0x9A
115 #define DA7213_ALC_CTRL3		0x9B
116 #define DA7213_ALC_NOISE		0x9C
117 #define DA7213_ALC_TARGET_MIN		0x9D
118 #define DA7213_ALC_TARGET_MAX		0x9E
119 #define DA7213_ALC_GAIN_LIMITS		0x9F
120 #define DA7213_ALC_ANA_GAIN_LIMITS	0xA0
121 #define DA7213_ALC_ANTICLIP_CTRL	0xA1
122 #define DA7213_ALC_ANTICLIP_LEVEL	0xA2
123 
124 #define DA7213_ALC_OFFSET_AUTO_M_L	0xA3
125 #define DA7213_ALC_OFFSET_AUTO_U_L	0xA4
126 #define DA7213_ALC_OFFSET_MAN_M_L	0xA6
127 #define DA7213_ALC_OFFSET_MAN_U_L	0xA7
128 #define DA7213_ALC_OFFSET_AUTO_M_R	0xA8
129 #define DA7213_ALC_OFFSET_AUTO_U_R	0xA9
130 #define DA7213_ALC_OFFSET_MAN_M_R	0xAB
131 #define DA7213_ALC_OFFSET_MAN_U_R	0xAC
132 #define DA7213_ALC_CIC_OP_LVL_CTRL	0xAD
133 #define DA7213_ALC_CIC_OP_LVL_DATA	0xAE
134 #define DA7213_DAC_NG_SETUP_TIME	0xAF
135 #define DA7213_DAC_NG_OFF_THRESHOLD	0xB0
136 #define DA7213_DAC_NG_ON_THRESHOLD	0xB1
137 #define DA7213_DAC_NG_CTRL		0xB2
138 
139 #define DA7213_TONE_GEN_CFG1		0xB4
140 #define DA7213_TONE_GEN_CFG2		0xB5
141 #define DA7213_TONE_GEN_CYCLES		0xB6
142 #define DA7213_TONE_GEN_FREQ1_L		0xB7
143 #define DA7213_TONE_GEN_FREQ1_U		0xB8
144 #define DA7213_TONE_GEN_FREQ2_L		0xB9
145 #define DA7213_TONE_GEN_FREQ2_U		0xBA
146 #define DA7213_TONE_GEN_ON_PER		0xBB
147 #define DA7213_TONE_GEN_OFF_PER		0xBC
148 
149 /*
150  * Bit fields
151  */
152 
153 #define DA7213_SWITCH_EN_MAX		0x1
154 
155 /* DA7213_PLL_STATUS = 0x03 */
156 #define DA7213_PLL_SRM_LOCK					(0x1 << 1)
157 
158 /* DA7213_SR = 0x22 */
159 #define DA7213_SR_8000						(0x1 << 0)
160 #define DA7213_SR_11025						(0x2 << 0)
161 #define DA7213_SR_12000						(0x3 << 0)
162 #define DA7213_SR_16000						(0x5 << 0)
163 #define DA7213_SR_22050						(0x6 << 0)
164 #define DA7213_SR_24000						(0x7 << 0)
165 #define DA7213_SR_32000						(0x9 << 0)
166 #define DA7213_SR_44100						(0xA << 0)
167 #define DA7213_SR_48000						(0xB << 0)
168 #define DA7213_SR_88200						(0xE << 0)
169 #define DA7213_SR_96000						(0xF << 0)
170 
171 /* DA7213_REFERENCES = 0x23 */
172 #define DA7213_BIAS_EN						(0x1 << 3)
173 #define DA7213_VMID_EN						(0x1 << 7)
174 
175 /* DA7213_PLL_CTRL = 0x27 */
176 #define DA7213_PLL_INDIV_5_TO_9_MHZ				(0x0 << 2)
177 #define DA7213_PLL_INDIV_9_TO_18_MHZ				(0x1 << 2)
178 #define DA7213_PLL_INDIV_18_TO_36_MHZ				(0x2 << 2)
179 #define DA7213_PLL_INDIV_36_TO_54_MHZ				(0x3 << 2)
180 #define DA7213_PLL_INDIV_MASK					(0x3 << 2)
181 #define DA7213_PLL_MCLK_SQR_EN					(0x1 << 4)
182 #define DA7213_PLL_32K_MODE					(0x1 << 5)
183 #define DA7213_PLL_SRM_EN					(0x1 << 6)
184 #define DA7213_PLL_EN						(0x1 << 7)
185 #define DA7213_PLL_MODE_MASK					(0x7 << 5)
186 
187 /* DA7213_DAI_CLK_MODE = 0x28 */
188 #define DA7213_DAI_BCLKS_PER_WCLK_32				(0x0 << 0)
189 #define DA7213_DAI_BCLKS_PER_WCLK_64				(0x1 << 0)
190 #define DA7213_DAI_BCLKS_PER_WCLK_128				(0x2 << 0)
191 #define DA7213_DAI_BCLKS_PER_WCLK_256				(0x3 << 0)
192 #define DA7213_DAI_BCLKS_PER_WCLK_MASK				(0x3 << 0)
193 #define DA7213_DAI_CLK_POL_INV					(0x1 << 2)
194 #define DA7213_DAI_CLK_POL_MASK					(0x1 << 2)
195 #define DA7213_DAI_WCLK_POL_INV					(0x1 << 3)
196 #define DA7213_DAI_WCLK_POL_MASK				(0x1 << 3)
197 #define DA7213_DAI_CLK_EN_MASK					(0x1 << 7)
198 
199 /* DA7213_DAI_CTRL = 0x29 */
200 #define DA7213_DAI_FORMAT_I2S_MODE				(0x0 << 0)
201 #define DA7213_DAI_FORMAT_LEFT_J				(0x1 << 0)
202 #define DA7213_DAI_FORMAT_RIGHT_J				(0x2 << 0)
203 #define DA7213_DAI_FORMAT_DSP					(0x3 << 0)
204 #define DA7213_DAI_FORMAT_MASK					(0x3 << 0)
205 #define DA7213_DAI_WORD_LENGTH_S16_LE				(0x0 << 2)
206 #define DA7213_DAI_WORD_LENGTH_S20_LE				(0x1 << 2)
207 #define DA7213_DAI_WORD_LENGTH_S24_LE				(0x2 << 2)
208 #define DA7213_DAI_WORD_LENGTH_S32_LE				(0x3 << 2)
209 #define DA7213_DAI_WORD_LENGTH_MASK				(0x3 << 2)
210 #define DA7213_DAI_MONO_MODE_EN					(0x1 << 4)
211 #define DA7213_DAI_MONO_MODE_MASK				(0x1 << 4)
212 #define DA7213_DAI_EN_SHIFT					7
213 
214 /* DA7213_DIG_ROUTING_DAI = 0x21 */
215 #define DA7213_DAI_L_SRC_SHIFT					0
216 #define DA7213_DAI_R_SRC_SHIFT					4
217 #define DA7213_DAI_SRC_MAX					4
218 
219 /* DA7213_DIG_ROUTING_DAC = 0x2A */
220 #define DA7213_DAC_L_SRC_SHIFT					0
221 #define DA7213_DAC_L_MONO_SHIFT					3
222 #define DA7213_DAC_R_SRC_SHIFT					4
223 #define DA7213_DAC_R_MONO_SHIFT					7
224 #define DA7213_DAC_SRC_MAX					4
225 #define DA7213_DAC_MONO_MAX					0x1
226 
227 /* DA7213_ALC_CTRL1 = 0x2B */
228 #define DA7213_ALC_OFFSET_EN_SHIFT				0
229 #define DA7213_ALC_OFFSET_EN_MAX				0x1
230 #define DA7213_ALC_OFFSET_EN					(0x1 << 0)
231 #define DA7213_ALC_SYNC_MODE					(0x1 << 1)
232 #define DA7213_ALC_CALIB_MODE_MAN				(0x1 << 2)
233 #define DA7213_ALC_L_EN_SHIFT					3
234 #define DA7213_ALC_AUTO_CALIB_EN				(0x1 << 4)
235 #define DA7213_ALC_CALIB_OVERFLOW				(0x1 << 5)
236 #define DA7213_ALC_R_EN_SHIFT					7
237 #define DA7213_ALC_EN_MAX					0x1
238 
239 /* DA7213_AUX_L/R_GAIN = 0x30/0x31 */
240 #define DA7213_AUX_AMP_GAIN_SHIFT				0
241 #define DA7213_AUX_AMP_GAIN_MAX					0x3F
242 
243 /* DA7213_MIXIN_L/R_SELECT = 0x32/0x33 */
244 #define DA7213_DMIC_EN_SHIFT					7
245 #define DA7213_DMIC_EN_MAX					0x1
246 
247 /* DA7213_MIXIN_L_SELECT = 0x32 */
248 #define DA7213_MIXIN_L_MIX_SELECT_AUX_L_SHIFT			0
249 #define DA7213_MIXIN_L_MIX_SELECT_MIC_1_SHIFT			1
250 #define DA7213_MIXIN_L_MIX_SELECT_MIC_1				(0x1 << 1)
251 #define DA7213_MIXIN_L_MIX_SELECT_MIC_2_SHIFT			2
252 #define DA7213_MIXIN_L_MIX_SELECT_MIC_2				(0x1 << 2)
253 #define DA7213_MIXIN_L_MIX_SELECT_MIXIN_R_SHIFT			3
254 #define DA7213_MIXIN_L_MIX_SELECT_MAX				0x1
255 
256 /* DA7213_MIXIN_R_SELECT =  0x33 */
257 #define DA7213_MIXIN_R_MIX_SELECT_AUX_R_SHIFT			0
258 #define DA7213_MIXIN_R_MIX_SELECT_MIC_2_SHIFT			1
259 #define DA7213_MIXIN_R_MIX_SELECT_MIC_2				(0x1 << 1)
260 #define DA7213_MIXIN_R_MIX_SELECT_MIC_1_SHIFT			2
261 #define DA7213_MIXIN_R_MIX_SELECT_MIC_1				(0x1 << 2)
262 #define DA7213_MIXIN_R_MIX_SELECT_MIXIN_L_SHIFT			3
263 #define DA7213_MIXIN_R_MIX_SELECT_MAX				0x1
264 #define DA7213_MIC_BIAS_OUTPUT_SELECT_2				(0x1 << 6)
265 
266 /* DA7213_MIXIN_L/R_GAIN = 0x34/0x35 */
267 #define DA7213_MIXIN_AMP_GAIN_SHIFT				0
268 #define DA7213_MIXIN_AMP_GAIN_MAX				0xF
269 
270 /* DA7213_ADC_L/R_GAIN = 0x36/0x37 */
271 #define DA7213_ADC_AMP_GAIN_SHIFT				0
272 #define DA7213_ADC_AMP_GAIN_MAX					0x7F
273 
274 /* DA7213_ADC/DAC_FILTERS1 = 0x38/0x44 */
275 #define DA7213_VOICE_HPF_CORNER_SHIFT				0
276 #define DA7213_VOICE_HPF_CORNER_MAX				8
277 #define DA7213_VOICE_EN_SHIFT					3
278 #define DA7213_VOICE_EN_MAX					0x1
279 #define DA7213_AUDIO_HPF_CORNER_SHIFT				4
280 #define DA7213_AUDIO_HPF_CORNER_MAX				4
281 #define DA7213_HPF_EN_SHIFT					7
282 #define DA7213_HPF_EN_MAX					0x1
283 
284 /* DA7213_MIC_1/2_GAIN = 0x39/0x3A */
285 #define DA7213_MIC_AMP_GAIN_SHIFT				0
286 #define DA7213_MIC_AMP_GAIN_MAX					0x7
287 
288 /* DA7213_DAC_FILTERS5 = 0x40 */
289 #define DA7213_DAC_SOFTMUTE_EN_SHIFT				7
290 #define DA7213_DAC_SOFTMUTE_EN_MAX				0x1
291 #define DA7213_DAC_SOFTMUTE_RATE_SHIFT				4
292 #define DA7213_DAC_SOFTMUTE_RATE_MAX				7
293 
294 /* DA7213_DAC_FILTERS2/3/4 = 0x41/0x42/0x43 */
295 #define DA7213_DAC_EQ_BAND_MAX					0xF
296 
297 /* DA7213_DAC_FILTERS2 = 0x41 */
298 #define DA7213_DAC_EQ_BAND1_SHIFT				0
299 #define DA7213_DAC_EQ_BAND2_SHIFT				4
300 
301 /* DA7213_DAC_FILTERS2 = 0x42 */
302 #define DA7213_DAC_EQ_BAND3_SHIFT				0
303 #define DA7213_DAC_EQ_BAND4_SHIFT				4
304 
305 /* DA7213_DAC_FILTERS4 = 0x43 */
306 #define DA7213_DAC_EQ_BAND5_SHIFT				0
307 #define DA7213_DAC_EQ_EN_SHIFT					7
308 #define DA7213_DAC_EQ_EN_MAX					0x1
309 
310 /* DA7213_DAC_L/R_GAIN = 0x45/0x46 */
311 #define DA7213_DAC_AMP_GAIN_SHIFT				0
312 #define DA7213_DAC_AMP_GAIN_MAX					0x7F
313 
314 /* DA7213_HP_L/R_GAIN = 0x45/0x46 */
315 #define DA7213_HP_AMP_GAIN_SHIFT				0
316 #define DA7213_HP_AMP_GAIN_MAX					0x3F
317 
318 /* DA7213_CP_CTRL = 0x47 */
319 #define DA7213_CP_EN_SHIFT					7
320 
321 /* DA7213_LINE_GAIN = 0x4A */
322 #define DA7213_LINE_AMP_GAIN_SHIFT				0
323 #define DA7213_LINE_AMP_GAIN_MAX				0x3F
324 
325 /* DA7213_MIXOUT_L_SELECT = 0x4B */
326 #define DA7213_MIXOUT_L_MIX_SELECT_AUX_L_SHIFT			0
327 #define DA7213_MIXOUT_L_MIX_SELECT_MIXIN_L_SHIFT		1
328 #define DA7213_MIXOUT_L_MIX_SELECT_MIXIN_R_SHIFT		2
329 #define DA7213_MIXOUT_L_MIX_SELECT_DAC_L_SHIFT			3
330 #define DA7213_MIXOUT_L_MIX_SELECT_AUX_L_INVERTED_SHIFT		4
331 #define DA7213_MIXOUT_L_MIX_SELECT_MIXIN_L_INVERTED_SHIFT	5
332 #define DA7213_MIXOUT_L_MIX_SELECT_MIXIN_R_INVERTED_SHIFT	6
333 #define DA7213_MIXOUT_L_MIX_SELECT_MAX				0x1
334 
335 /* DA7213_MIXOUT_R_SELECT = 0x4C */
336 #define DA7213_MIXOUT_R_MIX_SELECT_AUX_R_SHIFT			0
337 #define DA7213_MIXOUT_R_MIX_SELECT_MIXIN_R_SHIFT		1
338 #define DA7213_MIXOUT_R_MIX_SELECT_MIXIN_L_SHIFT		2
339 #define DA7213_MIXOUT_R_MIX_SELECT_DAC_R_SHIFT			3
340 #define DA7213_MIXOUT_R_MIX_SELECT_AUX_R_INVERTED_SHIFT		4
341 #define DA7213_MIXOUT_R_MIX_SELECT_MIXIN_R_INVERTED_SHIFT	5
342 #define DA7213_MIXOUT_R_MIX_SELECT_MIXIN_L_INVERTED_SHIFT	6
343 #define DA7213_MIXOUT_R_MIX_SELECT_MAX				0x1
344 
345 /*
346  * DA7213_AUX_L/R_CTRL = 0x60/0x61,
347  * DA7213_MIC_1/2_CTRL = 0x63/0x64,
348  * DA7213_MIXIN_L/R_CTRL = 0x65/0x66,
349  * DA7213_ADC_L/R_CTRL = 0x65/0x66,
350  * DA7213_DAC_L/R_CTRL = 0x69/0x6A,
351  * DA7213_HP_L/R_CTRL = 0x6B/0x6C,
352  * DA7213_LINE_CTRL = 0x6D
353  */
354 #define DA7213_MUTE_EN_SHIFT					6
355 #define DA7213_MUTE_EN_MAX					0x1
356 #define DA7213_MUTE_EN						(0x1 << 6)
357 
358 /*
359  * DA7213_AUX_L/R_CTRL = 0x60/0x61,
360  * DA7213_MIXIN_L/R_CTRL = 0x65/0x66,
361  * DA7213_ADC_L/R_CTRL = 0x65/0x66,
362  * DA7213_DAC_L/R_CTRL = 0x69/0x6A,
363  * DA7213_HP_L/R_CTRL = 0x6B/0x6C,
364  * DA7213_LINE_CTRL = 0x6D
365  */
366 #define DA7213_GAIN_RAMP_EN_SHIFT				5
367 #define DA7213_GAIN_RAMP_EN_MAX					0x1
368 #define DA7213_GAIN_RAMP_EN					(0x1 << 5)
369 
370 /*
371  * DA7213_AUX_L/R_CTRL = 0x60/0x61,
372  * DA7213_MIXIN_L/R_CTRL = 0x65/0x66,
373  * DA7213_HP_L/R_CTRL = 0x6B/0x6C,
374  * DA7213_LINE_CTRL = 0x6D
375  */
376 #define DA7213_ZC_EN_SHIFT					4
377 #define DA7213_ZC_EN_MAX					0x1
378 
379 /*
380  * DA7213_AUX_L/R_CTRL = 0x60/0x61,
381  * DA7213_MIC_1/2_CTRL = 0x63/0x64,
382  * DA7213_MIXIN_L/R_CTRL = 0x65/0x66,
383  * DA7213_HP_L/R_CTRL = 0x6B/0x6C,
384  * DA7213_MIXOUT_L/R_CTRL = 0x6E/0x6F,
385  * DA7213_LINE_CTRL = 0x6D
386  */
387 #define DA7213_AMP_EN_SHIFT					7
388 
389 /* DA7213_MIC_1/2_CTRL = 0x63/0x64 */
390 #define DA7213_MIC_AMP_IN_SEL_SHIFT				2
391 #define DA7213_MIC_AMP_IN_SEL_MAX				3
392 
393 /* DA7213_MICBIAS_CTRL = 0x62 */
394 #define DA7213_MICBIAS1_LEVEL_SHIFT				0
395 #define DA7213_MICBIAS1_LEVEL_MASK				(0x3 << 0)
396 #define DA7213_MICBIAS1_EN_SHIFT				3
397 #define DA7213_MICBIAS2_LEVEL_SHIFT				4
398 #define DA7213_MICBIAS2_LEVEL_MASK				(0x3 << 4)
399 #define DA7213_MICBIAS2_EN_SHIFT				7
400 
401 /* DA7213_MIXIN_L/R_CTRL = 0x65/0x66 */
402 #define DA7213_MIXIN_MIX_EN					(0x1 << 3)
403 
404 /* DA7213_ADC_L/R_CTRL = 0x67/0x68 */
405 #define DA7213_ADC_EN_SHIFT					7
406 #define DA7213_ADC_EN						(0x1 << 7)
407 
408 /* DA7213_DAC_L/R_CTRL =  0x69/0x6A*/
409 #define DA7213_DAC_EN_SHIFT					7
410 
411 /* DA7213_HP_L/R_CTRL = 0x6B/0x6C */
412 #define DA7213_HP_AMP_OE					(0x1 << 3)
413 
414 /* DA7213_LINE_CTRL = 0x6D */
415 #define DA7213_LINE_AMP_OE					(0x1 << 3)
416 
417 /* DA7213_MIXOUT_L/R_CTRL = 0x6E/0x6F */
418 #define DA7213_MIXOUT_MIX_EN					(0x1 << 3)
419 
420 /* DA7213_GAIN_RAMP_CTRL = 0x92 */
421 #define DA7213_GAIN_RAMP_RATE_SHIFT				0
422 #define DA7213_GAIN_RAMP_RATE_MAX				4
423 
424 /* DA7213_MIC_CONFIG = 0x93 */
425 #define DA7213_DMIC_DATA_SEL_SHIFT				0
426 #define DA7213_DMIC_DATA_SEL_MASK				(0x1 << 0)
427 #define DA7213_DMIC_SAMPLEPHASE_SHIFT				1
428 #define DA7213_DMIC_SAMPLEPHASE_MASK				(0x1 << 1)
429 #define DA7213_DMIC_CLK_RATE_SHIFT				2
430 #define DA7213_DMIC_CLK_RATE_MASK				(0x1 << 2)
431 
432 /* DA7213_PC_COUNT = 0x94 */
433 #define DA7213_PC_FREERUN_MASK					(0x1 << 0)
434 
435 /* DA7213_DIG_CTRL = 0x99 */
436 #define DA7213_DAC_L_INV_SHIFT					3
437 #define DA7213_DAC_R_INV_SHIFT					7
438 #define DA7213_DAC_INV_MAX					0x1
439 
440 /* DA7213_ALC_CTRL2 = 0x9A */
441 #define DA7213_ALC_ATTACK_SHIFT					0
442 #define DA7213_ALC_ATTACK_MAX					13
443 #define DA7213_ALC_RELEASE_SHIFT				4
444 #define DA7213_ALC_RELEASE_MAX					11
445 
446 /* DA7213_ALC_CTRL3 = 0x9B */
447 #define DA7213_ALC_HOLD_SHIFT					0
448 #define DA7213_ALC_HOLD_MAX					16
449 #define DA7213_ALC_INTEG_ATTACK_SHIFT				4
450 #define DA7213_ALC_INTEG_RELEASE_SHIFT				6
451 #define DA7213_ALC_INTEG_MAX					4
452 
453 /*
454  * DA7213_ALC_NOISE = 0x9C,
455  * DA7213_ALC_TARGET_MIN/MAX = 0x9D/0x9E
456  */
457 #define DA7213_ALC_THRESHOLD_SHIFT				0
458 #define DA7213_ALC_THRESHOLD_MAX				0x3F
459 
460 /* DA7213_ALC_GAIN_LIMITS = 0x9F */
461 #define DA7213_ALC_ATTEN_MAX_SHIFT				0
462 #define DA7213_ALC_GAIN_MAX_SHIFT				4
463 #define DA7213_ALC_ATTEN_GAIN_MAX_MAX				0xF
464 
465 /* DA7213_ALC_ANA_GAIN_LIMITS = 0xA0 */
466 #define DA7213_ALC_ANA_GAIN_MIN_SHIFT				0
467 #define DA7213_ALC_ANA_GAIN_MAX_SHIFT				4
468 #define DA7213_ALC_ANA_GAIN_MAX					0x7
469 
470 /* DA7213_ALC_ANTICLIP_CTRL = 0xA1 */
471 #define DA7213_ALC_ANTICLIP_EN_SHIFT				7
472 #define DA7213_ALC_ANTICLIP_EN_MAX				0x1
473 
474 /* DA7213_ALC_ANTICLIP_LEVEL = 0xA2 */
475 #define DA7213_ALC_ANTICLIP_LEVEL_SHIFT				0
476 #define DA7213_ALC_ANTICLIP_LEVEL_MAX				0x7F
477 
478 /* DA7213_ALC_CIC_OP_LVL_CTRL = 0xAD */
479 #define DA7213_ALC_DATA_MIDDLE					(0x2 << 0)
480 #define DA7213_ALC_DATA_TOP					(0x3 << 0)
481 #define DA7213_ALC_CIC_OP_CHANNEL_LEFT				(0x0 << 7)
482 #define DA7213_ALC_CIC_OP_CHANNEL_RIGHT				(0x1 << 7)
483 
484 /* DA7213_DAC_NG_SETUP_TIME = 0xAF */
485 #define DA7213_DAC_NG_SETUP_TIME_SHIFT				0
486 #define DA7213_DAC_NG_SETUP_TIME_MAX				4
487 #define DA7213_DAC_NG_RAMPUP_RATE_SHIFT				2
488 #define DA7213_DAC_NG_RAMPDN_RATE_SHIFT				3
489 #define DA7213_DAC_NG_RAMP_RATE_MAX				2
490 
491 /* DA7213_DAC_NG_OFF/ON_THRESH = 0xB0/0xB1 */
492 #define DA7213_DAC_NG_THRESHOLD_SHIFT				0
493 #define DA7213_DAC_NG_THRESHOLD_MAX				0x7
494 
495 /* DA7213_DAC_NG_CTRL = 0xB2 */
496 #define DA7213_DAC_NG_EN_SHIFT					7
497 #define DA7213_DAC_NG_EN_MAX					0x1
498 
499 /* DA7213_TONE_GEN_CFG1 = 0xB4 */
500 #define DA7213_DTMF_REG_SHIFT		0
501 #define DA7213_DTMF_REG_MASK		(0xF << 0)
502 #define DA7213_DTMF_REG_MAX		16
503 #define DA7213_DTMF_EN_SHIFT		4
504 #define DA7213_DTMF_EN_MASK		(0x1 << 4)
505 #define DA7213_START_STOPN_SHIFT	7
506 #define DA7213_START_STOPN_MASK		(0x1 << 7)
507 
508 /* DA7213_TONE_GEN_CFG2 = 0xB5 */
509 #define DA7213_SWG_SEL_SHIFT		0
510 #define DA7213_SWG_SEL_MASK		(0x3 << 0)
511 #define DA7213_SWG_SEL_MAX		4
512 #define DA7213_SWG_SEL_SRAMP		(0x3 << 0)
513 #define DA7213_TONE_GEN_GAIN_SHIFT	4
514 #define DA7213_TONE_GEN_GAIN_MASK	(0xF << 4)
515 #define DA7213_TONE_GEN_GAIN_MAX	0xF
516 #define DA7213_TONE_GEN_GAIN_MINUS_9DB	(0x3 << 4)
517 #define DA7213_TONE_GEN_GAIN_MINUS_15DB	(0x5 << 4)
518 
519 /* DA7213_TONE_GEN_CYCLES = 0xB6 */
520 #define DA7213_BEEP_CYCLES_SHIFT	0
521 #define DA7213_BEEP_CYCLES_MASK		(0x7 << 0)
522 
523 /* DA7213_TONE_GEN_FREQ1_L = 0xB7 */
524 #define DA7213_FREQ1_L_SHIFT	0
525 #define DA7213_FREQ1_L_MASK	(0xFF << 0)
526 #define DA7213_FREQ_MAX		0xFFFF
527 
528 /* DA7213_TONE_GEN_FREQ1_U = 0xB8 */
529 #define DA7213_FREQ1_U_SHIFT	0
530 #define DA7213_FREQ1_U_MASK	(0xFF << 0)
531 
532 /* DA7213_TONE_GEN_FREQ2_L = 0xB9 */
533 #define DA7213_FREQ2_L_SHIFT	0
534 #define DA7213_FREQ2_L_MASK	(0xFF << 0)
535 
536 /* DA7213_TONE_GEN_FREQ2_U = 0xBA */
537 #define DA7213_FREQ2_U_SHIFT	0
538 #define DA7213_FREQ2_U_MASK	(0xFF << 0)
539 
540 /* DA7213_TONE_GEN_ON_PER = 0xBB */
541 #define DA7213_BEEP_ON_PER_SHIFT	0
542 #define DA7213_BEEP_ON_PER_MASK		(0x3F << 0)
543 #define DA7213_BEEP_ON_OFF_MAX		0x3F
544 
545 /* DA7213_TONE_GEN_OFF_PER = 0xBC */
546 #define DA7213_BEEP_OFF_PER_SHIFT	0
547 #define DA7213_BEEP_OFF_PER_MASK	(0x3F << 0)
548 
549 /*
550  * General defines
551  */
552 
553 /* Register inversion */
554 #define DA7213_NO_INVERT		0
555 #define DA7213_INVERT			1
556 
557 /* Byte related defines */
558 #define DA7213_BYTE_SHIFT		8
559 #define DA7213_BYTE_MASK		0xFF
560 
561 /* ALC related */
562 #define DA7213_ALC_OFFSET_15_8		0x00FF00
563 #define DA7213_ALC_OFFSET_19_16		0x0F0000
564 #define DA7213_ALC_AVG_ITERATIONS	5
565 
566 /* PLL related */
567 #define DA7213_PLL_FREQ_OUT_90316800		90316800
568 #define DA7213_PLL_FREQ_OUT_98304000		98304000
569 #define DA7213_PLL_FREQ_OUT_94310400		94310400
570 #define DA7213_PLL_INDIV_5_TO_9_MHZ_VAL		2
571 #define DA7213_PLL_INDIV_9_TO_18_MHZ_VAL	4
572 #define DA7213_PLL_INDIV_18_TO_36_MHZ_VAL	8
573 #define DA7213_PLL_INDIV_36_TO_54_MHZ_VAL	16
574 #define DA7213_SRM_CHECK_RETRIES		8
575 
576 enum da7213_clk_src {
577 	DA7213_CLKSRC_MCLK = 0,
578 	DA7213_CLKSRC_MCLK_SQR,
579 };
580 
581 enum da7213_sys_clk {
582 	DA7213_SYSCLK_MCLK = 0,
583 	DA7213_SYSCLK_PLL,
584 	DA7213_SYSCLK_PLL_SRM,
585 	DA7213_SYSCLK_PLL_32KHZ
586 };
587 
588 /* Regulators */
589 enum da7213_supplies {
590 	DA7213_SUPPLY_VDDA = 0,
591 	DA7213_SUPPLY_VDDIO,
592 	DA7213_NUM_SUPPLIES,
593 };
594 
595 /* Codec private data */
596 struct da7213_priv {
597 	struct regmap *regmap;
598 	struct mutex ctrl_lock;
599 	struct regulator_bulk_data supplies[DA7213_NUM_SUPPLIES];
600 	struct clk *mclk;
601 	unsigned int mclk_rate;
602 	unsigned int out_rate;
603 	int clk_src;
604 	bool master;
605 	bool alc_calib_auto;
606 	bool alc_en;
607 	bool fixed_clk_auto_pll;
608 	struct da7213_platform_data *pdata;
609 	int fmt;
610 };
611 
612 #endif /* _DA7213_H */
613