tizen 2.4 release
[profile/mobile/platform/kernel/u-boot-tm1.git] / drivers / sound / codec / sprd-codec-v3.h
1 /*
2  * sound/soc/sprd/codec/sprd/sprd-codec-v2.h
3  *
4  * SPRD-CODEC -- SpreadTrum Tiger intergrated codec.
5  *
6  * Copyright (C) 2013 SpreadTrum Ltd.
7  *
8  * This software is licensed under the terms of the GNU General Public
9  * License version 2, as published by the Free Software Foundation, and
10  * may be copied, distributed, and modified under those terms.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY ork FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  */
17 #ifndef __SPRD_CODEC_V3_H
18 #define __SPRD_CODEC_V3_H
19
20 #include <asm/arch/regs_adi.h>
21 #include <asm/arch/regs_global.h>
22 #include <asm/arch/sprd-audio.h>
23 #include <asm/arch/adi.h>
24 #include <asm/io.h>
25
26 #ifndef CONFIG_SPRD_CODEC_USE_INT
27 /* #define CONFIG_SPRD_CODEC_USE_INT */
28 #endif
29 #ifndef CONFIG_CODEC_DAC_MUTE_WAIT
30 /* #define CONFIG_CODEC_DAC_MUTE_WAIT */
31 #endif
32
33 /* unit: ms */
34 #define SPRD_CODEC_LDO_WAIT_TIME        (5)
35 #define SPRD_CODEC_LDO_VCM_TIME         (2)
36 #ifdef CONFIG_SPRD_CODEC_USE_INT
37 #define SPRD_CODEC_DAC_MUTE_TIMEOUT     (600)
38 #else
39 #define SPRD_CODEC_DAC_MUTE_WAIT_TIME   (40)
40 #endif
41
42 #ifdef CONFIG_SPRD_CODEC_USE_INT
43 #define SPRD_CODEC_HP_POP_TIMEOUT       (1000)
44 #else
45 #define SPRD_CODEC_HP_POP_TIME_STEP     (10)
46 #define SPRD_CODEC_HP_POP_TIME_COUNT    (80)    /* max 800ms will timeout */
47 #endif
48
49 #define SPRD_CODEC_RATE_8000   (10)
50 #define SPRD_CODEC_RATE_9600   ( 9)
51 #define SPRD_CODEC_RATE_11025  ( 8)
52 #define SPRD_CODEC_RATE_12000  ( 7)
53 #define SPRD_CODEC_RATE_16000  ( 6)
54 #define SPRD_CODEC_RATE_22050  ( 5)
55 #define SPRD_CODEC_RATE_24000  ( 4)
56 #define SPRD_CODEC_RATE_32000  ( 3)
57 #define SPRD_CODEC_RATE_44100  ( 2)
58 #define SPRD_CODEC_RATE_48000  ( 1)
59 #define SPRD_CODEC_RATE_96000  ( 0)
60
61 /* AUD_TOP_CTL */
62 #define DAC_EN_L                (0)
63 #define ADC_EN_L                (1)
64 #define DAC_EN_R                (2)
65 #define ADC_EN_R                (3)
66 #define ADC_SINC_SEL    (8)
67 #define ADC_SINC_SEL_MASK  (0x3)
68 #define ADC1_EN_L               (10)
69 #define ADC1_EN_R               (11)
70 #define ADC1_SINC_SEL   (14)
71 #define ADC1_SINC_SEL_MASK  (0x3)
72 #define ADC1_DMIC_SEL   (15)
73
74 /* AUD_DAC_CTL */
75 #define DAC_MUTE_START          (14)
76 #define DAC_MUTE_EN             (15)
77
78 /* AUD_ADC_CTL */
79 #define ADC_SRC_N                       (0)
80 #define ADC_SRC_N_MASK      (0x0f)
81 #define ADC1_SRC_N                      (4)
82 #define ADC1_SRC_N_MASK      (0xf0)
83
84 /* AUD_AUD_STS0 */
85 #define DAC_MUTE_U_MASK         (5)
86 #define DAC_MUTE_D_MASK         (4)
87 #define DAC_MUTE_U_RAW          (3)
88 #define DAC_MUTE_D_RAW          (2)
89 #define DAC_MUTE_ST             (0)
90 #define DAC_MUTE_ST_MASK        (0x3)
91
92 /* AUD_INT_CLR */
93 /* AUD_INT_EN */
94 #define DAC_MUTE_U              (1)
95 #define DAC_MUTE_D              (0)
96
97 /*AUD_DMIC_CTL*/
98 #define ADC_DMIC_CLK_MODE               (0)
99 #define ADC_DMIC_CLK_MODE_MASK  (0x3)
100 #define ADC_DMIC_LR_SEL         (2)
101 #define ADC1_DMIC_CLK_MODE      (3)
102 #define ADC1_DMIC_CLK_MODE_MASK (0x3)
103 #define ADC1_DMIC_LR_SEL                (5)
104 #define ADC_DMIC_EN                             (6)
105 #define ADC1_DMIC_EN                    (7)
106
107 /* AUDIF_ENB */
108 #define AUDIFA_DACL_EN          (0)
109 #define AUDIFA_ADCL_EN          (1)
110 #define AUDIFA_DACR_EN          (2)
111 #define AUDIFA_ADCR_EN          (3)
112 #define AUDIFA_ADIE_LOOP_EN     (5)
113
114 /* AUDIF_INT_EN */
115 /* AUDIF_INT_CLR */
116 /* AUDIF_INT_RAW */
117 /* AUDIF_INT_MASK */
118 #define AUDIO_POP_IRQ           (7)
119 #define OVP_IRQ                 (6)
120 #define OTP_IRQ                 (5)
121 #define PA_OCP_IRQ              (4)
122 #define LOR_OCP_IRQ             (3)
123 #define LOL_OCP_IRQ             (2)
124 #define EAR_OCP_IRQ             (1)
125 #define HP_OCP_IRQ              (0)
126
127 #define LDO_V_29                (0)
128 #define LDO_V_31                (1)
129 #define LDO_V_32                (2)
130 #define LDO_V_33                (3)
131 #define LDO_V_34                (4)
132 #define LDO_V_35                (5)
133 #define LDO_V_36                (6)
134 #define LDO_V_38                (7)
135
136 #define MIC_LDO_V_21            (0)
137 #define MIC_LDO_V_19            (1)
138 #define MIC_LDO_V_23            (2)
139 #define MIC_LDO_V_25            (3)
140
141 /* PMUR2_PMUR1 */
142 #define PA_SW_EN                (15)
143 #define PA_LDO_EN               (14)
144 #define PA_EN                   (13)
145 #define PAR_SW_EN               (12)
146 #define PAR_LDO_EN              (11)
147 #define PAR_EN                  (10)
148 #define VB_EN                   (7)
149 #define VBO_EN                  (6)
150 #define HEADMICBIAS_EN          (5)
151 #define MICBIAS_V               (3)
152 #define MICBIAS_V_MASK          (0x3)
153 #define MICBIAS_HV_EN           (2)
154 #define HEADMIC_SLEEP_EN        (1)
155
156 /* PMUR4_PMUR3 */
157 #define MICBIAS_EN              (15)
158 #define AUXMICBIAS_EN           (14)
159 #define VCM_V                   (11)
160 #define VCM_V_MASK              (0x7)
161 #define BG_I                    (9)
162 #define BG_I_MASK               (0x3)
163 #define BG_EN                   (7)
164 #define BG_RST                  (6)
165 #define BG_IBIAS_EN             (5)
166 #define VCM_EN                  (4)
167 #define VCM_BUF_EN              (3)
168 #define ICM_PLUS_EN             (2)
169 #define SEL_VCMI                (1)
170 #define VCMI_FAST_EN            (0)
171
172 /* PMUR6_PMUR5 */
173 #define PA_SWOCP_PD             (15)
174 #define PA_LDOOCP_PD            (14)
175 #define PA_LDO_V                (11)
176 #define PA_LDO_V_MASK           (0x7)
177 #define VCM_CAL                 (0)
178 #define VCM_CAL_MASK            (0x1F)
179
180 /* PMUR8_PMUR7 */
181
182 /* CCR */
183 #define ADC_CLK_EN              (7)
184 #define ADC_CLK_RST             (6)
185 #define ADC_CLK_F               (4)
186 #define ADC_CLK_F_MASK          (0x3)
187 #define DAC_CLK_EN              (3)
188 #define DAC_CLK_F               (1)
189 #define DAC_CLK_F_MASK          (0x3)
190 #define DRV_CLK_EN              (0)
191
192 /* AACR2_AACR1 */
193 #define ADCPGAL_BYP             (14)
194 #define ADCPGAL_BYP_MASK        (0x3)
195 #define ADCPGAL_EN              (12)
196 #define ADCPGAL_EN_MASK         (0x3)
197 #define ADCPGAR_BYP             (10)
198 #define ADCPGAR_BYP_MASK        (0x3)
199 #define ADCPGAR_EN              (8)
200 #define ADCPGAR_EN_MASK         (0x3)
201 #define ADC_IBUF_PD             (7)
202 #define ADC_VREF1P5             (6)
203 #define ADCL_PD                 (5)
204 #define ADCL_RST                (4)
205 #define ADCR_PD                 (3)
206 #define ADCR_RST                (2)
207
208 /* AAICR2_AAICR1 */
209 #define MIC_ADCR                (15)
210 #define AUXMIC_ADCR             (14)
211 #define HEADMIC_ADCR            (13)
212 #define AIL_ADCR                (12)
213 #define AIR_ADCR                (11)
214 #define MIC_ADCL                (7)
215 #define AUXMIC_ADCL             (6)
216 #define HEADMIC_ADCL            (5)
217 #define AIL_ADCL                (4)
218 #define AIR_ADCL                (3)
219
220 /* DACGR_DACR */
221 #define DACL_EN                 (7)
222 #define DACR_EN                 (6)
223 #define DACBUF_I_S              (5)
224
225 /* DAOCR2 */
226 #define ADCL_AOL                (7)
227 #define ADCR_AOL                (6)
228 #define DACL_AOL                (5)
229 #define DACR_AOL                (4)
230 #define ADCL_AOR                (3)
231 #define ADCR_AOR                (2)
232 #define DACL_AOR                (1)
233 #define DACR_AOR                (0)
234
235 /* DAOCR3_DAOCR1 */
236 #define DACL_EAR                (15)
237 #define ADCL_P_HPL              (7)
238 #define ADCR_P_HPL              (6)
239 #define DACL_P_HPL              (5)
240 #define DACR_P_HPL              (4)
241 #define ADCL_N_HPR              (3)
242 #define ADCR_P_HPR              (2)
243 #define DACL_N_HPR              (1)
244 #define DACR_P_HPR              (0)
245
246 /* DCR2_DCR1 */
247 #define PA_D_EN                 (15)
248 #define PA_DTRI_F               (13)
249 #define PA_DTRI_F_MASK          (0x03)
250 #define PA_DEMI_EN              (12)
251 #define PA_SS_EN                (11)
252 #define PA_SS_RST               (10)
253 #define DRV_STOP_EN             (9)
254
255 #define HPL_EN                  (7)
256 #define HPR_EN                  (6)
257 #define EAR_EN                  (5)
258 #define AOL_EN                  (4)
259 #define AOR_EN                  (3)
260 #define DIFF_EN                 (2)
261 #define HP_VCMI_EN              (1)
262
263 /* DCR4_DCR3 */
264 #define DRV_OCP_AOL_PD          (7)
265 #define DRV_OCP_AOR_PD          (6)
266 #define DRV_OCP_EAR_PD          (5)
267 #define DRV_OCP_HP_PD           (4)
268
269 /* DCR6_DCR5 */
270 #define AUD_NG_EN               (7)
271 #define AUD_NG_DA_EN    (6)
272 #define AUD_NG_PA_EN    (5)
273 /* DCR8_DCR7 */
274 #define AUDIO_CHP_LPW           (15)
275 #define AUDIO_CHP_MODE          (14)
276 #define AUDIO_CHP_REF_EN        (7)
277 #define AUDIO_CHP_EN            (6)
278 #define AUDIO_CHP_HPL_EN        (5)
279 #define AUDIO_CHP_HPR_EN        (4)
280 #define AUDIO_CHP_LMUTE         (3)
281 #define AUDIO_CHP_RMUTE         (2)
282 #define AUDIO_CHP_OSC           (0)
283 #define AUDIO_CHP_OSC_MASK      (0x03)
284
285 /* PNRCR2_PNRCR1 */
286 #define HP_POP_CTL              (6)
287 #define HP_POP_CTL_MASK         (0x03)
288 #define HP_POP_CTL_DIS          (0)
289 #define HP_POP_CTL_UP           (1)
290 #define HP_POP_CTL_DOWN         (2)
291 #define HP_POP_CTL_HOLD         (3)
292
293 #define HP_POP_STEP             (3)
294 #define HP_POP_STEP_MASK        (0x07)
295 #define HP_POP_STEP_012         (0)
296 #define HP_POP_STEP_025         (1)
297 #define HP_POP_STEP_05          (2)
298 #define HP_POP_STEP_1           (3)
299 #define HP_POP_STEP_2           (4)
300 #define HP_POP_STEP_4           (5)
301 #define HP_POP_STEP_8           (6)
302 #define HP_POP_STEP_16          (7)
303
304 /* IFR2_IFR1 */
305 #define HP_POP_FLG              (4)
306 #define HP_POP_FLG_MASK         (0x03)
307 #define HP_POP_FLG_NEAR_CMP     (3)
308
309 #define SPRD_CODEC_DP_BASE (CODEC_DP_BASE)
310
311 #define AUD_TOP_CTL             (SPRD_CODEC_DP_BASE + 0x0000)
312 #define AUD_AUD_CTR             (SPRD_CODEC_DP_BASE + 0x0004)
313 #define AUD_I2S_CTL             (SPRD_CODEC_DP_BASE + 0x0008)
314 #define AUD_DAC_CTL             (SPRD_CODEC_DP_BASE + 0x000C)
315 #define AUD_SDM_CTL0            (SPRD_CODEC_DP_BASE + 0x0010)
316 #define AUD_SDM_CTL1            (SPRD_CODEC_DP_BASE + 0x0014)
317 #define AUD_ADC_CTL             (SPRD_CODEC_DP_BASE + 0x0018)
318 #define AUD_LOOP_CTL            (SPRD_CODEC_DP_BASE + 0x001C)
319 #define AUD_AUD_STS0            (SPRD_CODEC_DP_BASE + 0x0020)
320 #define AUD_INT_CLR             (SPRD_CODEC_DP_BASE + 0x0024)
321 #define AUD_INT_EN              (SPRD_CODEC_DP_BASE + 0x0028)
322
323 #define AUD_DMIC_CTL    (SPRD_CODEC_DP_BASE + 0x0030)
324 #define AUD_ADC1_I2S_CTL        (SPRD_CODEC_DP_BASE + 0x0034)
325 #define SPRD_CODEC_DP_END       (SPRD_CODEC_DP_BASE + 0x0034)
326
327 #define IS_SPRD_CODEC_DP_RANG(reg) (((reg) >= SPRD_CODEC_DP_BASE) && ((reg) < SPRD_CODEC_DP_END))
328
329 #define SPRD_CODEC_AP_BASE (CODEC_AP_BASE)
330
331 #define AUDIF_ENB                       (SPRD_CODEC_AP_BASE + 0x0000)
332 #define AUDIF_OCP_OTP_TMR_CTL           (SPRD_CODEC_AP_BASE + 0x0004)
333 #define AUDIF_OVPTMR_SHUTDOWN_CTL       (SPRD_CODEC_AP_BASE + 0x0008)
334 #define AUDIF_INT_CLR                   (SPRD_CODEC_AP_BASE + 0x000C)
335 #define AUDIF_INT_EN                    (SPRD_CODEC_AP_BASE + 0x0010)
336 #define AUDIF_INT_RAW                   (SPRD_CODEC_AP_BASE + 0x0014)
337 #define AUDIF_INT_MASK                  (SPRD_CODEC_AP_BASE + 0x0018)
338 /* 0x001C ~ 0x003C is reserved for ADIE digital part */
339
340 #define PMUR2_PMUR1                     (SPRD_CODEC_AP_BASE + 0x0040)
341 #define PMUR4_PMUR3                     (SPRD_CODEC_AP_BASE + 0x0044)
342 #define PMUR6_PMUR5                     (SPRD_CODEC_AP_BASE + 0x0048)
343 #define PMUR8_PMUR7                     (SPRD_CODEC_AP_BASE + 0x004C)
344 /* 0x0050 ~ 0x005C is reserved for analog power part */
345
346 #define CCR                             (SPRD_CODEC_AP_BASE + 0x0060)
347 #define AACR2_AACR1                     (SPRD_CODEC_AP_BASE + 0x0064)
348 #define AAICR2_AAICR1                   (SPRD_CODEC_AP_BASE + 0x0068)
349 #define ACGR1                           (SPRD_CODEC_AP_BASE + 0x006C)
350 #define ACGR3_ACGR2                     (SPRD_CODEC_AP_BASE + 0x0070)
351
352 #define DACGR_DACR                      (SPRD_CODEC_AP_BASE + 0x0074)
353 #define DAOCR2                          (SPRD_CODEC_AP_BASE + 0x0078)
354 #define DAOCR3_DAOCR1                   (SPRD_CODEC_AP_BASE + 0x007C)
355 #define DCR2_DCR1                       (SPRD_CODEC_AP_BASE + 0x0080)
356 #define DCR4_DCR3                       (SPRD_CODEC_AP_BASE + 0x0084)
357 #define DCR6_DCR5                       (SPRD_CODEC_AP_BASE + 0x0088)
358 #define DCR8_DCR7                       (SPRD_CODEC_AP_BASE + 0x008C)
359 #define DCGR2_DCGR1                     (SPRD_CODEC_AP_BASE + 0x0090)
360 #define DCGR3                           (SPRD_CODEC_AP_BASE + 0x0094)
361
362 #define PNRCR2_PNRCR1                   (SPRD_CODEC_AP_BASE + 0x0098)
363 #define PNRCR3                          (SPRD_CODEC_AP_BASE + 0x009C)
364
365 #define HIBDR2_HIBDR1                   (SPRD_CODEC_AP_BASE + 0x00A0)
366 #define HIBDR3                          (SPRD_CODEC_AP_BASE + 0x00A4)
367 /* 0x00A8 ~ 0x00BC is reserved */
368
369 #define IFR2_IFR1                       (SPRD_CODEC_AP_BASE + 0x00C0)
370 #define AUD_DANGL               (SPRD_CODEC_AP_BASE + 0x00C4)
371 #define AUD_DANGR               (SPRD_CODEC_AP_BASE + 0x00C8)
372 /* 0x00C4 ~ 0x00C8 is reserved */
373 #define IFR4_IFR3                       (SPRD_CODEC_AP_BASE + 0x00CC)
374 /* 0x00D0 ~ 0x00D8 is reserved */
375
376 #define SPRD_CODEC_AP_END               (SPRD_CODEC_AP_BASE + 0x00CC)
377 #define IS_SPRD_CODEC_AP_RANG(reg) (((reg) >= SPRD_CODEC_AP_BASE) && ((reg) < SPRD_CODEC_AP_END))
378
379 #define SPRD_CODEC_IIS1_ID   1
380
381 #define ID_FUN(id, lr) ((int)(((id) << 1) | (lr)))
382
383 enum {
384         SPRD_CODEC_PGA_SPKL = 0,
385         SPRD_CODEC_PGA_SPKR,
386         SPRD_CODEC_PGA_HPL,
387         SPRD_CODEC_PGA_HPR,
388         SPRD_CODEC_PGA_EAR,
389         SPRD_CODEC_PGA_ADCL,
390         SPRD_CODEC_PGA_ADCR,
391         SPRD_CODEC_PGA_DACL,
392         SPRD_CODEC_PGA_DACR,
393         SPRD_CODEC_PGA_MIC,
394         SPRD_CODEC_PGA_AUXMIC,
395         SPRD_CODEC_PGA_HEADMIC,
396         SPRD_CODEC_PGA_AIL,
397         SPRD_CODEC_PGA_AIR,
398
399         SPRD_CODEC_PGA_MAX
400 };
401
402 enum {
403         SPRD_CODEC_LEFT = 0,
404         SPRD_CODEC_RIGHT = 1,
405 };
406
407 enum {
408         SPRD_CODEC_MIXER_START = 0,
409         SPRD_CODEC_AIL = SPRD_CODEC_MIXER_START,
410         SPRD_CODEC_AIR,
411         SPRD_CODEC_MAIN_MIC,
412         SPRD_CODEC_AUX_MIC,
413         SPRD_CODEC_HP_MIC,
414         SPRD_CODEC_ADC_MIXER_MAX,
415         SPRD_CODEC_HP_DACL = SPRD_CODEC_ADC_MIXER_MAX,
416         SPRD_CODEC_HP_DACR,
417         SPRD_CODEC_HP_ADCL,
418         SPRD_CODEC_HP_ADCR,
419         SPRD_CODEC_HP_MIXER_MAX,
420         SPRD_CODEC_SPK_DACL = SPRD_CODEC_HP_MIXER_MAX,
421         SPRD_CODEC_SPK_DACR,
422         SPRD_CODEC_SPK_ADCL,
423         SPRD_CODEC_SPK_ADCR,
424         SPRD_CODEC_SPK_MIXER_MAX,
425         SPRD_CODEC_EAR_DACL = SPRD_CODEC_SPK_MIXER_MAX,
426         SPRD_CODEC_EAR_MIXER_MAX,
427
428         SPRD_CODEC_MIXER_MAX = SPRD_CODEC_EAR_MIXER_MAX << SPRD_CODEC_RIGHT
429 };
430
431 enum {
432         SPRD_CODEC_MIC_BIAS,
433         SPRD_CODEC_AUXMIC_BIAS,
434         SPRD_CODEC_HEADMIC_BIAS,
435         SPRD_CODEC_MIC_BIAS_MAX
436 };
437
438 int sprd_codec_init(void);
439 void sprd_codec_exit(void);
440 int sprd_codec_pcm_set_sample_rate(int playback, int rate);
441 int sprd_codec_digital_loop(int enable);
442
443 int mixer_get(int id);
444 int mixer_set(int id, int on);
445 int mixer_enable(int id, int enable);
446 int pga_enable(int id, int pgaval, int enable);
447 int hp_switch(int enable);
448 int ear_switch(int enable);
449 int spkl_switch(int enable);
450 int spkr_switch(int enable);
451 int dacl_digital_switch(int enable);
452 int dacr_digital_switch(int enable);
453
454 int adcl_digital_switch(int enable);
455 int adcr_digital_switch(int enable);
456 int adcl_switch(int enable);
457 int adcr_switch(int enable);
458 int mic_bias_enable(int id, int enable);
459
460 int sprd_inter_speaker_pa(int on);
461
462 #endif /* __SPRD_CODEC_V3_H */