xref: /openbmc/linux/sound/soc/codecs/da7219-aad.h (revision 55b37d9c)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * da7219-aad.h - DA7322 ASoC AAD Driver
4  *
5  * Copyright (c) 2015 Dialog Semiconductor Ltd.
6  *
7  * Author: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
8  */
9 
10 #ifndef __DA7219_AAD_H
11 #define __DA7219_AAD_H
12 
13 #include <linux/timer.h>
14 #include <linux/mutex.h>
15 #include <sound/soc.h>
16 #include <sound/jack.h>
17 #include <sound/da7219-aad.h>
18 
19 /*
20  * Registers
21  */
22 
23 #define DA7219_ACCDET_STATUS_A		0xC0
24 #define DA7219_ACCDET_STATUS_B		0xC1
25 #define DA7219_ACCDET_IRQ_EVENT_A	0xC2
26 #define DA7219_ACCDET_IRQ_EVENT_B	0xC3
27 #define DA7219_ACCDET_IRQ_MASK_A	0xC4
28 #define DA7219_ACCDET_IRQ_MASK_B	0xC5
29 #define DA7219_ACCDET_CONFIG_1		0xC6
30 #define DA7219_ACCDET_CONFIG_2		0xC7
31 #define DA7219_ACCDET_CONFIG_3		0xC8
32 #define DA7219_ACCDET_CONFIG_4		0xC9
33 #define DA7219_ACCDET_CONFIG_5		0xCA
34 #define DA7219_ACCDET_CONFIG_6		0xCB
35 #define DA7219_ACCDET_CONFIG_7		0xCC
36 #define DA7219_ACCDET_CONFIG_8		0xCD
37 
38 
39 /*
40  * Bit Fields
41  */
42 
43 /* DA7219_ACCDET_STATUS_A = 0xC0 */
44 #define DA7219_JACK_INSERTION_STS_SHIFT	0
45 #define DA7219_JACK_INSERTION_STS_MASK	(0x1 << 0)
46 #define DA7219_JACK_TYPE_STS_SHIFT	1
47 #define DA7219_JACK_TYPE_STS_MASK	(0x1 << 1)
48 #define DA7219_JACK_PIN_ORDER_STS_SHIFT	2
49 #define DA7219_JACK_PIN_ORDER_STS_MASK	(0x1 << 2)
50 #define DA7219_MICBIAS_UP_STS_SHIFT	3
51 #define DA7219_MICBIAS_UP_STS_MASK	(0x1 << 3)
52 
53 /* DA7219_ACCDET_STATUS_B = 0xC1 */
54 #define DA7219_BUTTON_TYPE_STS_SHIFT	0
55 #define DA7219_BUTTON_TYPE_STS_MASK	(0xFF << 0)
56 
57 /* DA7219_ACCDET_IRQ_EVENT_A = 0xC2 */
58 #define DA7219_E_JACK_INSERTED_SHIFT		0
59 #define DA7219_E_JACK_INSERTED_MASK		(0x1 << 0)
60 #define DA7219_E_JACK_REMOVED_SHIFT		1
61 #define DA7219_E_JACK_REMOVED_MASK		(0x1 << 1)
62 #define DA7219_E_JACK_DETECT_COMPLETE_SHIFT	2
63 #define DA7219_E_JACK_DETECT_COMPLETE_MASK	(0x1 << 2)
64 
65 /* DA7219_ACCDET_IRQ_EVENT_B = 0xC3 */
66 #define DA7219_E_BUTTON_A_PRESSED_SHIFT		0
67 #define DA7219_E_BUTTON_A_PRESSED_MASK		(0x1 << 0)
68 #define DA7219_E_BUTTON_B_PRESSED_SHIFT		1
69 #define DA7219_E_BUTTON_B_PRESSED_MASK		(0x1 << 1)
70 #define DA7219_E_BUTTON_C_PRESSED_SHIFT		2
71 #define DA7219_E_BUTTON_C_PRESSED_MASK		(0x1 << 2)
72 #define DA7219_E_BUTTON_D_PRESSED_SHIFT		3
73 #define DA7219_E_BUTTON_D_PRESSED_MASK		(0x1 << 3)
74 #define DA7219_E_BUTTON_D_RELEASED_SHIFT	4
75 #define DA7219_E_BUTTON_D_RELEASED_MASK		(0x1 << 4)
76 #define DA7219_E_BUTTON_C_RELEASED_SHIFT	5
77 #define DA7219_E_BUTTON_C_RELEASED_MASK		(0x1 << 5)
78 #define DA7219_E_BUTTON_B_RELEASED_SHIFT	6
79 #define DA7219_E_BUTTON_B_RELEASED_MASK		(0x1 << 6)
80 #define DA7219_E_BUTTON_A_RELEASED_SHIFT	7
81 #define DA7219_E_BUTTON_A_RELEASED_MASK		(0x1 << 7)
82 
83 /* DA7219_ACCDET_IRQ_MASK_A = 0xC4 */
84 #define DA7219_M_JACK_INSERTED_SHIFT		0
85 #define DA7219_M_JACK_INSERTED_MASK		(0x1 << 0)
86 #define DA7219_M_JACK_REMOVED_SHIFT		1
87 #define DA7219_M_JACK_REMOVED_MASK		(0x1 << 1)
88 #define DA7219_M_JACK_DETECT_COMPLETE_SHIFT	2
89 #define DA7219_M_JACK_DETECT_COMPLETE_MASK	(0x1 << 2)
90 
91 /* DA7219_ACCDET_IRQ_MASK_B = 0xC5 */
92 #define DA7219_M_BUTTON_A_PRESSED_SHIFT		0
93 #define DA7219_M_BUTTON_A_PRESSED_MASK		(0x1 << 0)
94 #define DA7219_M_BUTTON_B_PRESSED_SHIFT		1
95 #define DA7219_M_BUTTON_B_PRESSED_MASK		(0x1 << 1)
96 #define DA7219_M_BUTTON_C_PRESSED_SHIFT		2
97 #define DA7219_M_BUTTON_C_PRESSED_MASK		(0x1 << 2)
98 #define DA7219_M_BUTTON_D_PRESSED_SHIFT		3
99 #define DA7219_M_BUTTON_D_PRESSED_MASK		(0x1 << 3)
100 #define DA7219_M_BUTTON_D_RELEASED_SHIFT	4
101 #define DA7219_M_BUTTON_D_RELEASED_MASK		(0x1 << 4)
102 #define DA7219_M_BUTTON_C_RELEASED_SHIFT	5
103 #define DA7219_M_BUTTON_C_RELEASED_MASK		(0x1 << 5)
104 #define DA7219_M_BUTTON_B_RELEASED_SHIFT	6
105 #define DA7219_M_BUTTON_B_RELEASED_MASK		(0x1 << 6)
106 #define DA7219_M_BUTTON_A_RELEASED_SHIFT	7
107 #define DA7219_M_BUTTON_A_RELEASED_MASK		(0x1 << 7)
108 
109 /* DA7219_ACCDET_CONFIG_1 = 0xC6 */
110 #define DA7219_ACCDET_EN_SHIFT		0
111 #define DA7219_ACCDET_EN_MASK		(0x1 << 0)
112 #define DA7219_BUTTON_CONFIG_SHIFT	1
113 #define DA7219_BUTTON_CONFIG_MASK	(0x7 << 1)
114 #define DA7219_MIC_DET_THRESH_SHIFT	4
115 #define DA7219_MIC_DET_THRESH_MASK	(0x3 << 4)
116 #define DA7219_JACK_TYPE_DET_EN_SHIFT	6
117 #define DA7219_JACK_TYPE_DET_EN_MASK	(0x1 << 6)
118 #define DA7219_PIN_ORDER_DET_EN_SHIFT	7
119 #define DA7219_PIN_ORDER_DET_EN_MASK	(0x1 << 7)
120 
121 /* DA7219_ACCDET_CONFIG_2 = 0xC7 */
122 #define DA7219_ACCDET_PAUSE_SHIFT	0
123 #define DA7219_ACCDET_PAUSE_MASK	(0x1 << 0)
124 #define DA7219_JACKDET_DEBOUNCE_SHIFT	1
125 #define DA7219_JACKDET_DEBOUNCE_MASK	(0x7 << 1)
126 #define DA7219_JACK_DETECT_RATE_SHIFT	4
127 #define DA7219_JACK_DETECT_RATE_MASK	(0x3 << 4)
128 #define DA7219_JACKDET_REM_DEB_SHIFT	6
129 #define DA7219_JACKDET_REM_DEB_MASK	(0x3 << 6)
130 
131 /* DA7219_ACCDET_CONFIG_3 = 0xC8 */
132 #define DA7219_A_D_BUTTON_THRESH_SHIFT	0
133 #define DA7219_A_D_BUTTON_THRESH_MASK	(0xFF << 0)
134 
135 /* DA7219_ACCDET_CONFIG_4 = 0xC9 */
136 #define DA7219_D_B_BUTTON_THRESH_SHIFT	0
137 #define DA7219_D_B_BUTTON_THRESH_MASK	(0xFF << 0)
138 
139 /* DA7219_ACCDET_CONFIG_5 = 0xCA */
140 #define DA7219_B_C_BUTTON_THRESH_SHIFT	0
141 #define DA7219_B_C_BUTTON_THRESH_MASK	(0xFF << 0)
142 
143 /* DA7219_ACCDET_CONFIG_6 = 0xCB */
144 #define DA7219_C_MIC_BUTTON_THRESH_SHIFT	0
145 #define DA7219_C_MIC_BUTTON_THRESH_MASK		(0xFF << 0)
146 
147 /* DA7219_ACCDET_CONFIG_7 = 0xCC */
148 #define DA7219_BUTTON_AVERAGE_SHIFT	0
149 #define DA7219_BUTTON_AVERAGE_MASK	(0x3 << 0)
150 #define DA7219_ADC_1_BIT_REPEAT_SHIFT	2
151 #define DA7219_ADC_1_BIT_REPEAT_MASK	(0x3 << 2)
152 #define DA7219_PIN_ORDER_FORCE_SHIFT	4
153 #define DA7219_PIN_ORDER_FORCE_MASK	(0x1 << 4)
154 #define DA7219_JACK_TYPE_FORCE_SHIFT	5
155 #define DA7219_JACK_TYPE_FORCE_MASK	(0x1 << 5)
156 
157 /* DA7219_ACCDET_CONFIG_8 = 0xCD */
158 #define DA7219_HPTEST_EN_SHIFT		0
159 #define DA7219_HPTEST_EN_MASK		(0x1 << 0)
160 #define DA7219_HPTEST_RES_SEL_SHIFT	1
161 #define DA7219_HPTEST_RES_SEL_MASK	(0x3 << 1)
162 #define DA7219_HPTEST_RES_SEL_1KOHMS	(0x0 << 1)
163 #define DA7219_HPTEST_COMP_SHIFT	4
164 #define DA7219_HPTEST_COMP_MASK		(0x1 << 4)
165 
166 
167 #define DA7219_AAD_MAX_BUTTONS		4
168 #define DA7219_AAD_REPORT_ALL_MASK	(SND_JACK_MECHANICAL |			\
169 					 SND_JACK_HEADSET | SND_JACK_LINEOUT |	\
170 					 SND_JACK_BTN_0 | SND_JACK_BTN_1 |	\
171 					 SND_JACK_BTN_2 | SND_JACK_BTN_3)
172 
173 #define DA7219_AAD_MICBIAS_CHK_DELAY	10
174 #define DA7219_AAD_MICBIAS_CHK_RETRIES	5
175 
176 #define DA7219_AAD_HPTEST_RAMP_FREQ		0x28
177 #define DA7219_AAD_HPTEST_RAMP_FREQ_INT_OSC	0x4D
178 #define DA7219_AAD_HPTEST_PERIOD		65
179 #define DA7219_AAD_HPTEST_INT_OSC_PATH_DELAY	20
180 
181 enum da7219_aad_event_regs {
182 	DA7219_AAD_IRQ_REG_A = 0,
183 	DA7219_AAD_IRQ_REG_B,
184 	DA7219_AAD_IRQ_REG_MAX,
185 };
186 
187 /* Private data */
188 struct da7219_aad_priv {
189 	struct snd_soc_component *component;
190 	int irq;
191 	int gnd_switch_delay;
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 	struct delayed_work jack_det_work;
201 	struct workqueue_struct *aad_wq;
202 
203 	struct snd_soc_jack *jack;
204 	bool micbias_resume_enable;
205 	bool jack_inserted;
206 };
207 
208 /* AAD control */
209 void da7219_aad_jack_det(struct snd_soc_component *component, struct snd_soc_jack *jack);
210 
211 /* Suspend/Resume */
212 void da7219_aad_suspend(struct snd_soc_component *component);
213 void da7219_aad_resume(struct snd_soc_component *component);
214 
215 /* Init/Exit */
216 int da7219_aad_init(struct snd_soc_component *component);
217 void da7219_aad_exit(struct snd_soc_component *component);
218 
219 /* I2C Probe */
220 int da7219_aad_probe(struct i2c_client *i2c);
221 
222 #endif /* __DA7219_AAD_H */
223