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