Merge tag 'armsoc-defconfig' of git://git.kernel.org/pub/scm/linux/kernel/git/arm...
[firefly-linux-kernel-4.4.55.git] / sound / soc / codecs / da7219-aad.h
1 /*
2  * da7219-aad.h - DA7322 ASoC AAD Driver
3  *
4  * Copyright (c) 2015 Dialog Semiconductor Ltd.
5  *
6  * Author: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
7  *
8  * This program is free software; you can redistribute  it and/or modify it
9  * under  the terms of  the GNU General  Public License as published by the
10  * Free Software Foundation;  either version 2 of the  License, or (at your
11  * option) any later version.
12  */
13
14 #ifndef __DA7219_AAD_H
15 #define __DA7219_AAD_H
16
17 #include <linux/timer.h>
18 #include <sound/soc.h>
19 #include <sound/jack.h>
20 #include <sound/da7219-aad.h>
21
22 /*
23  * Registers
24  */
25
26 #define DA7219_ACCDET_STATUS_A          0xC0
27 #define DA7219_ACCDET_STATUS_B          0xC1
28 #define DA7219_ACCDET_IRQ_EVENT_A       0xC2
29 #define DA7219_ACCDET_IRQ_EVENT_B       0xC3
30 #define DA7219_ACCDET_IRQ_MASK_A        0xC4
31 #define DA7219_ACCDET_IRQ_MASK_B        0xC5
32 #define DA7219_ACCDET_CONFIG_1          0xC6
33 #define DA7219_ACCDET_CONFIG_2          0xC7
34 #define DA7219_ACCDET_CONFIG_3          0xC8
35 #define DA7219_ACCDET_CONFIG_4          0xC9
36 #define DA7219_ACCDET_CONFIG_5          0xCA
37 #define DA7219_ACCDET_CONFIG_6          0xCB
38 #define DA7219_ACCDET_CONFIG_7          0xCC
39 #define DA7219_ACCDET_CONFIG_8          0xCD
40
41
42 /*
43  * Bit Fields
44  */
45
46 /* DA7219_ACCDET_STATUS_A = 0xC0 */
47 #define DA7219_JACK_INSERTION_STS_SHIFT 0
48 #define DA7219_JACK_INSERTION_STS_MASK  (0x1 << 0)
49 #define DA7219_JACK_TYPE_STS_SHIFT      1
50 #define DA7219_JACK_TYPE_STS_MASK       (0x1 << 1)
51 #define DA7219_JACK_PIN_ORDER_STS_SHIFT 2
52 #define DA7219_JACK_PIN_ORDER_STS_MASK  (0x1 << 2)
53 #define DA7219_MICBIAS_UP_STS_SHIFT     3
54 #define DA7219_MICBIAS_UP_STS_MASK      (0x1 << 3)
55
56 /* DA7219_ACCDET_STATUS_B = 0xC1 */
57 #define DA7219_BUTTON_TYPE_STS_SHIFT    0
58 #define DA7219_BUTTON_TYPE_STS_MASK     (0xFF << 0)
59
60 /* DA7219_ACCDET_IRQ_EVENT_A = 0xC2 */
61 #define DA7219_E_JACK_INSERTED_SHIFT            0
62 #define DA7219_E_JACK_INSERTED_MASK             (0x1 << 0)
63 #define DA7219_E_JACK_REMOVED_SHIFT             1
64 #define DA7219_E_JACK_REMOVED_MASK              (0x1 << 1)
65 #define DA7219_E_JACK_DETECT_COMPLETE_SHIFT     2
66 #define DA7219_E_JACK_DETECT_COMPLETE_MASK      (0x1 << 2)
67
68 /* DA7219_ACCDET_IRQ_EVENT_B = 0xC3 */
69 #define DA7219_E_BUTTON_A_PRESSED_SHIFT         0
70 #define DA7219_E_BUTTON_A_PRESSED_MASK          (0x1 << 0)
71 #define DA7219_E_BUTTON_B_PRESSED_SHIFT         1
72 #define DA7219_E_BUTTON_B_PRESSED_MASK          (0x1 << 1)
73 #define DA7219_E_BUTTON_C_PRESSED_SHIFT         2
74 #define DA7219_E_BUTTON_C_PRESSED_MASK          (0x1 << 2)
75 #define DA7219_E_BUTTON_D_PRESSED_SHIFT         3
76 #define DA7219_E_BUTTON_D_PRESSED_MASK          (0x1 << 3)
77 #define DA7219_E_BUTTON_D_RELEASED_SHIFT        4
78 #define DA7219_E_BUTTON_D_RELEASED_MASK         (0x1 << 4)
79 #define DA7219_E_BUTTON_C_RELEASED_SHIFT        5
80 #define DA7219_E_BUTTON_C_RELEASED_MASK         (0x1 << 5)
81 #define DA7219_E_BUTTON_B_RELEASED_SHIFT        6
82 #define DA7219_E_BUTTON_B_RELEASED_MASK         (0x1 << 6)
83 #define DA7219_E_BUTTON_A_RELEASED_SHIFT        7
84 #define DA7219_E_BUTTON_A_RELEASED_MASK         (0x1 << 7)
85
86 /* DA7219_ACCDET_IRQ_MASK_A = 0xC4 */
87 #define DA7219_M_JACK_INSERTED_SHIFT            0
88 #define DA7219_M_JACK_INSERTED_MASK             (0x1 << 0)
89 #define DA7219_M_JACK_REMOVED_SHIFT             1
90 #define DA7219_M_JACK_REMOVED_MASK              (0x1 << 1)
91 #define DA7219_M_JACK_DETECT_COMPLETE_SHIFT     2
92 #define DA7219_M_JACK_DETECT_COMPLETE_MASK      (0x1 << 2)
93
94 /* DA7219_ACCDET_IRQ_MASK_B = 0xC5 */
95 #define DA7219_M_BUTTON_A_PRESSED_SHIFT         0
96 #define DA7219_M_BUTTON_A_PRESSED_MASK          (0x1 << 0)
97 #define DA7219_M_BUTTON_B_PRESSED_SHIFT         1
98 #define DA7219_M_BUTTON_B_PRESSED_MASK          (0x1 << 1)
99 #define DA7219_M_BUTTON_C_PRESSED_SHIFT         2
100 #define DA7219_M_BUTTON_C_PRESSED_MASK          (0x1 << 2)
101 #define DA7219_M_BUTTON_D_PRESSED_SHIFT         3
102 #define DA7219_M_BUTTON_D_PRESSED_MASK          (0x1 << 3)
103 #define DA7219_M_BUTTON_D_RELEASED_SHIFT        4
104 #define DA7219_M_BUTTON_D_RELEASED_MASK         (0x1 << 4)
105 #define DA7219_M_BUTTON_C_RELEASED_SHIFT        5
106 #define DA7219_M_BUTTON_C_RELEASED_MASK         (0x1 << 5)
107 #define DA7219_M_BUTTON_B_RELEASED_SHIFT        6
108 #define DA7219_M_BUTTON_B_RELEASED_MASK         (0x1 << 6)
109 #define DA7219_M_BUTTON_A_RELEASED_SHIFT        7
110 #define DA7219_M_BUTTON_A_RELEASED_MASK         (0x1 << 7)
111
112 /* DA7219_ACCDET_CONFIG_1 = 0xC6 */
113 #define DA7219_ACCDET_EN_SHIFT          0
114 #define DA7219_ACCDET_EN_MASK           (0x1 << 0)
115 #define DA7219_BUTTON_CONFIG_SHIFT      1
116 #define DA7219_BUTTON_CONFIG_MASK       (0x7 << 1)
117 #define DA7219_MIC_DET_THRESH_SHIFT     4
118 #define DA7219_MIC_DET_THRESH_MASK      (0x3 << 4)
119 #define DA7219_JACK_TYPE_DET_EN_SHIFT   6
120 #define DA7219_JACK_TYPE_DET_EN_MASK    (0x1 << 6)
121 #define DA7219_PIN_ORDER_DET_EN_SHIFT   7
122 #define DA7219_PIN_ORDER_DET_EN_MASK    (0x1 << 7)
123
124 /* DA7219_ACCDET_CONFIG_2 = 0xC7 */
125 #define DA7219_ACCDET_PAUSE_SHIFT       0
126 #define DA7219_ACCDET_PAUSE_MASK        (0x1 << 0)
127 #define DA7219_JACKDET_DEBOUNCE_SHIFT   1
128 #define DA7219_JACKDET_DEBOUNCE_MASK    (0x7 << 1)
129 #define DA7219_JACK_DETECT_RATE_SHIFT   4
130 #define DA7219_JACK_DETECT_RATE_MASK    (0x3 << 4)
131 #define DA7219_JACKDET_REM_DEB_SHIFT    6
132 #define DA7219_JACKDET_REM_DEB_MASK     (0x3 << 6)
133
134 /* DA7219_ACCDET_CONFIG_3 = 0xC8 */
135 #define DA7219_A_D_BUTTON_THRESH_SHIFT  0
136 #define DA7219_A_D_BUTTON_THRESH_MASK   (0xFF << 0)
137
138 /* DA7219_ACCDET_CONFIG_4 = 0xC9 */
139 #define DA7219_D_B_BUTTON_THRESH_SHIFT  0
140 #define DA7219_D_B_BUTTON_THRESH_MASK   (0xFF << 0)
141
142 /* DA7219_ACCDET_CONFIG_5 = 0xCA */
143 #define DA7219_B_C_BUTTON_THRESH_SHIFT  0
144 #define DA7219_B_C_BUTTON_THRESH_MASK   (0xFF << 0)
145
146 /* DA7219_ACCDET_CONFIG_6 = 0xCB */
147 #define DA7219_C_MIC_BUTTON_THRESH_SHIFT        0
148 #define DA7219_C_MIC_BUTTON_THRESH_MASK         (0xFF << 0)
149
150 /* DA7219_ACCDET_CONFIG_7 = 0xCC */
151 #define DA7219_BUTTON_AVERAGE_SHIFT     0
152 #define DA7219_BUTTON_AVERAGE_MASK      (0x3 << 0)
153 #define DA7219_ADC_1_BIT_REPEAT_SHIFT   2
154 #define DA7219_ADC_1_BIT_REPEAT_MASK    (0x3 << 2)
155 #define DA7219_PIN_ORDER_FORCE_SHIFT    4
156 #define DA7219_PIN_ORDER_FORCE_MASK     (0x1 << 4)
157 #define DA7219_JACK_TYPE_FORCE_SHIFT    5
158 #define DA7219_JACK_TYPE_FORCE_MASK     (0x1 << 5)
159
160 /* DA7219_ACCDET_CONFIG_8 = 0xCD */
161 #define DA7219_HPTEST_EN_SHIFT          0
162 #define DA7219_HPTEST_EN_MASK           (0x1 << 0)
163 #define DA7219_HPTEST_RES_SEL_SHIFT     1
164 #define DA7219_HPTEST_RES_SEL_MASK      (0x3 << 1)
165 #define DA7219_HPTEST_RES_SEL_1KOHMS    (0x0 << 1)
166 #define DA7219_HPTEST_COMP_SHIFT        4
167 #define DA7219_HPTEST_COMP_MASK         (0x1 << 4)
168
169
170 #define DA7219_AAD_MAX_BUTTONS          4
171 #define DA7219_AAD_REPORT_ALL_MASK      (SND_JACK_MECHANICAL |                  \
172                                          SND_JACK_HEADSET | SND_JACK_LINEOUT |  \
173                                          SND_JACK_BTN_0 | SND_JACK_BTN_1 |      \
174                                          SND_JACK_BTN_2 | SND_JACK_BTN_3)
175
176 #define DA7219_AAD_MICBIAS_CHK_DELAY    10
177 #define DA7219_AAD_MICBIAS_CHK_RETRIES  5
178
179 #define DA7219_AAD_HPTEST_RAMP_FREQ     0x28
180 #define DA7219_AAD_HPTEST_PERIOD        65
181
182 enum da7219_aad_event_regs {
183         DA7219_AAD_IRQ_REG_A = 0,
184         DA7219_AAD_IRQ_REG_B,
185         DA7219_AAD_IRQ_REG_MAX,
186 };
187
188 /* Private data */
189 struct da7219_aad_priv {
190         struct snd_soc_codec *codec;
191         int irq;
192
193         u8 micbias_pulse_lvl;
194         u32 micbias_pulse_time;
195
196         u8 btn_cfg;
197
198         struct work_struct btn_det_work;
199         struct work_struct hptest_work;
200
201         struct snd_soc_jack *jack;
202         bool jack_inserted;
203 };
204
205 /* AAD control */
206 void da7219_aad_jack_det(struct snd_soc_codec *codec, struct snd_soc_jack *jack);
207
208 /* Init/Exit */
209 int da7219_aad_init(struct snd_soc_codec *codec);
210 void da7219_aad_exit(struct snd_soc_codec *codec);
211
212 #endif /* __DA7219_AAD_H */