1 /*
2  * include/linux/input/adxl34x.h
3  *
4  * Digital Accelerometer characteristics are highly application specific
5  * and may vary between boards and models. The platform_data for the
6  * device's "struct device" holds this information.
7  *
8  * Copyright 2009 Analog Devices Inc.
9  *
10  * Licensed under the GPL-2 or later.
11  */
12 
13 #ifndef __LINUX_INPUT_ADXL34X_H__
14 #define __LINUX_INPUT_ADXL34X_H__
15 
16 #include <linux/input.h>
17 
18 struct adxl34x_platform_data {
19 
20 	/*
21 	 * X,Y,Z Axis Offset:
22 	 * offer user offset adjustments in twoscompliment
23 	 * form with a scale factor of 15.6 mg/LSB (i.e. 0x7F = +2 g)
24 	 */
25 
26 	s8 x_axis_offset;
27 	s8 y_axis_offset;
28 	s8 z_axis_offset;
29 
30 	/*
31 	 * TAP_X/Y/Z Enable: Setting TAP_X, Y, or Z Enable enables X,
32 	 * Y, or Z participation in Tap detection. A '0' excludes the
33 	 * selected axis from participation in Tap detection.
34 	 * Setting the SUPPRESS bit suppresses Double Tap detection if
35 	 * acceleration greater than tap_threshold is present during the
36 	 * tap_latency period, i.e. after the first tap but before the
37 	 * opening of the second tap window.
38 	 */
39 
40 #define ADXL_SUPPRESS	(1 << 3)
41 #define ADXL_TAP_X_EN	(1 << 2)
42 #define ADXL_TAP_Y_EN	(1 << 1)
43 #define ADXL_TAP_Z_EN	(1 << 0)
44 
45 	u8 tap_axis_control;
46 
47 	/*
48 	 * tap_threshold:
49 	 * holds the threshold value for tap detection/interrupts.
50 	 * The data format is unsigned. The scale factor is 62.5 mg/LSB
51 	 * (i.e. 0xFF = +16 g). A zero value may result in undesirable
52 	 * behavior if Tap/Double Tap is enabled.
53 	 */
54 
55 	u8 tap_threshold;
56 
57 	/*
58 	 * tap_duration:
59 	 * is an unsigned time value representing the maximum
60 	 * time that an event must be above the tap_threshold threshold
61 	 * to qualify as a tap event. The scale factor is 625 us/LSB. A zero
62 	 * value will prevent Tap/Double Tap functions from working.
63 	 */
64 
65 	u8 tap_duration;
66 
67 	/*
68 	 * tap_latency:
69 	 * is an unsigned time value representing the wait time
70 	 * from the detection of a tap event to the opening of the time
71 	 * window tap_window for a possible second tap event. The scale
72 	 * factor is 1.25 ms/LSB. A zero value will disable the Double Tap
73 	 * function.
74 	 */
75 
76 	u8 tap_latency;
77 
78 	/*
79 	 * tap_window:
80 	 * is an unsigned time value representing the amount
81 	 * of time after the expiration of tap_latency during which a second
82 	 * tap can begin. The scale factor is 1.25 ms/LSB. A zero value will
83 	 * disable the Double Tap function.
84 	 */
85 
86 	u8 tap_window;
87 
88 	/*
89 	 * act_axis_control:
90 	 * X/Y/Z Enable: A '1' enables X, Y, or Z participation in activity
91 	 * or inactivity detection. A '0' excludes the selected axis from
92 	 * participation. If all of the axes are excluded, the function is
93 	 * disabled.
94 	 * AC/DC: A '0' = DC coupled operation and a '1' = AC coupled
95 	 * operation. In DC coupled operation, the current acceleration is
96 	 * compared with activity_threshold and inactivity_threshold directly
97 	 * to determine whether activity or inactivity is detected. In AC
98 	 * coupled operation for activity detection, the acceleration value
99 	 * at the start of activity detection is taken as a reference value.
100 	 * New samples of acceleration are then compared to this
101 	 * reference value and if the magnitude of the difference exceeds
102 	 * activity_threshold the device will trigger an activity interrupt. In
103 	 * AC coupled operation for inactivity detection, a reference value
104 	 * is used again for comparison and is updated whenever the
105 	 * device exceeds the inactivity threshold. Once the reference
106 	 * value is selected, the device compares the magnitude of the
107 	 * difference between the reference value and the current
108 	 * acceleration with inactivity_threshold. If the difference is below
109 	 * inactivity_threshold for a total of inactivity_time, the device is
110 	 * considered inactive and the inactivity interrupt is triggered.
111 	 */
112 
113 #define ADXL_ACT_ACDC		(1 << 7)
114 #define ADXL_ACT_X_EN		(1 << 6)
115 #define ADXL_ACT_Y_EN		(1 << 5)
116 #define ADXL_ACT_Z_EN		(1 << 4)
117 #define ADXL_INACT_ACDC		(1 << 3)
118 #define ADXL_INACT_X_EN		(1 << 2)
119 #define ADXL_INACT_Y_EN		(1 << 1)
120 #define ADXL_INACT_Z_EN		(1 << 0)
121 
122 	u8 act_axis_control;
123 
124 	/*
125 	 * activity_threshold:
126 	 * holds the threshold value for activity detection.
127 	 * The data format is unsigned. The scale factor is
128 	 * 62.5 mg/LSB. A zero value may result in undesirable behavior if
129 	 * Activity interrupt is enabled.
130 	 */
131 
132 	u8 activity_threshold;
133 
134 	/*
135 	 * inactivity_threshold:
136 	 * holds the threshold value for inactivity
137 	 * detection. The data format is unsigned. The scale
138 	 * factor is 62.5 mg/LSB. A zero value may result in undesirable
139 	 * behavior if Inactivity interrupt is enabled.
140 	 */
141 
142 	u8 inactivity_threshold;
143 
144 	/*
145 	 * inactivity_time:
146 	 * is an unsigned time value representing the
147 	 * amount of time that acceleration must be below the value in
148 	 * inactivity_threshold for inactivity to be declared. The scale factor
149 	 * is 1 second/LSB. Unlike the other interrupt functions, which
150 	 * operate on unfiltered data, the inactivity function operates on the
151 	 * filtered output data. At least one output sample must be
152 	 * generated for the inactivity interrupt to be triggered. This will
153 	 * result in the function appearing un-responsive if the
154 	 * inactivity_time register is set with a value less than the time
155 	 * constant of the Output Data Rate. A zero value will result in an
156 	 * interrupt when the output data is below inactivity_threshold.
157 	 */
158 
159 	u8 inactivity_time;
160 
161 	/*
162 	 * free_fall_threshold:
163 	 * holds the threshold value for Free-Fall detection.
164 	 * The data format is unsigned. The root-sum-square(RSS) value
165 	 * of all axes is calculated and compared to the value in
166 	 * free_fall_threshold to determine if a free fall event may be
167 	 * occurring.  The scale factor is 62.5 mg/LSB. A zero value may
168 	 * result in undesirable behavior if Free-Fall interrupt is
169 	 * enabled. Values between 300 and 600 mg (0x05 to 0x09) are
170 	 * recommended.
171 	 */
172 
173 	u8 free_fall_threshold;
174 
175 	/*
176 	 * free_fall_time:
177 	 * is an unsigned time value representing the minimum
178 	 * time that the RSS value of all axes must be less than
179 	 * free_fall_threshold to generate a Free-Fall interrupt. The
180 	 * scale factor is 5 ms/LSB. A zero value may result in
181 	 * undesirable behavior if Free-Fall interrupt is enabled.
182 	 * Values between 100 to 350 ms (0x14 to 0x46) are recommended.
183 	 */
184 
185 	u8 free_fall_time;
186 
187 	/*
188 	 * data_rate:
189 	 * Selects device bandwidth and output data rate.
190 	 * RATE = 3200 Hz / (2^(15 - x)). Default value is 0x0A, or 100 Hz
191 	 * Output Data Rate. An Output Data Rate should be selected that
192 	 * is appropriate for the communication protocol and frequency
193 	 * selected. Selecting too high of an Output Data Rate with a low
194 	 * communication speed will result in samples being discarded.
195 	 */
196 
197 	u8 data_rate;
198 
199 	/*
200 	 * data_range:
201 	 * FULL_RES: When this bit is set with the device is
202 	 * in Full-Resolution Mode, where the output resolution increases
203 	 * with RANGE to maintain a 4 mg/LSB scale factor. When this
204 	 * bit is cleared the device is in 10-bit Mode and RANGE determine the
205 	 * maximum g-Range and scale factor.
206 	 */
207 
208 #define ADXL_FULL_RES		(1 << 3)
209 #define ADXL_RANGE_PM_2g	0
210 #define ADXL_RANGE_PM_4g	1
211 #define ADXL_RANGE_PM_8g	2
212 #define ADXL_RANGE_PM_16g	3
213 
214 	u8 data_range;
215 
216 	/*
217 	 * low_power_mode:
218 	 * A '0' = Normal operation and a '1' = Reduced
219 	 * power operation with somewhat higher noise.
220 	 */
221 
222 	u8 low_power_mode;
223 
224 	/*
225 	 * power_mode:
226 	 * LINK: A '1' with both the activity and inactivity functions
227 	 * enabled will delay the start of the activity function until
228 	 * inactivity is detected. Once activity is detected, inactivity
229 	 * detection will begin and prevent the detection of activity. This
230 	 * bit serially links the activity and inactivity functions. When '0'
231 	 * the inactivity and activity functions are concurrent. Additional
232 	 * information can be found in the ADXL34x datasheet's Application
233 	 * section under Link Mode.
234 	 * AUTO_SLEEP: A '1' sets the ADXL34x to switch to Sleep Mode
235 	 * when inactivity (acceleration has been below inactivity_threshold
236 	 * for at least inactivity_time) is detected and the LINK bit is set.
237 	 * A '0' disables automatic switching to Sleep Mode. See the
238 	 * Sleep Bit section of the ADXL34x datasheet for more information.
239 	 */
240 
241 #define ADXL_LINK	(1 << 5)
242 #define ADXL_AUTO_SLEEP	(1 << 4)
243 
244 	u8 power_mode;
245 
246 	/*
247 	 * fifo_mode:
248 	 * BYPASS The FIFO is bypassed
249 	 * FIFO   FIFO collects up to 32 values then stops collecting data
250 	 * STREAM FIFO holds the last 32 data values. Once full, the FIFO's
251 	 *        oldest data is lost as it is replaced with newer data
252 	 *
253 	 * DEFAULT should be ADXL_FIFO_STREAM
254 	 */
255 
256 #define ADXL_FIFO_BYPASS	0
257 #define ADXL_FIFO_FIFO		1
258 #define ADXL_FIFO_STREAM	2
259 
260 	u8 fifo_mode;
261 
262 	/*
263 	 * watermark:
264 	 * The Watermark feature can be used to reduce the interrupt load
265 	 * of the system. The FIFO fills up to the value stored in watermark
266 	 * [1..32] and then generates an interrupt.
267 	 * A '0' disables the watermark feature.
268 	 */
269 
270 	u8 watermark;
271 
272 	/*
273 	 * When acceleration measurements are received from the ADXL34x
274 	 * events are sent to the event subsystem. The following settings
275 	 * select the event type and event code for new x, y and z axis data
276 	 * respectively.
277 	 */
278 	u32 ev_type;	/* EV_ABS or EV_REL */
279 
280 	u32 ev_code_x;	/* ABS_X,Y,Z or REL_X,Y,Z */
281 	u32 ev_code_y;	/* ABS_X,Y,Z or REL_X,Y,Z */
282 	u32 ev_code_z;	/* ABS_X,Y,Z or REL_X,Y,Z */
283 
284 	/*
285 	 * A valid BTN or KEY Code; use tap_axis_control to disable
286 	 * event reporting
287 	 */
288 
289 	u32 ev_code_tap[3];	/* EV_KEY {X-Axis, Y-Axis, Z-Axis} */
290 
291 	/*
292 	 * A valid BTN or KEY Code for Free-Fall or Activity enables
293 	 * input event reporting. A '0' disables the Free-Fall or
294 	 * Activity reporting.
295 	 */
296 
297 	u32 ev_code_ff;	/* EV_KEY */
298 	u32 ev_code_act_inactivity;	/* EV_KEY */
299 
300 	/*
301 	 * Use ADXL34x INT2 pin instead of INT1 pin for interrupt output
302 	 */
303 	u8 use_int2;
304 
305 	/*
306 	 * ADXL346 only ORIENTATION SENSING feature
307 	 * The orientation function of the ADXL346 reports both 2-D and
308 	 * 3-D orientation concurrently.
309 	 */
310 
311 #define ADXL_EN_ORIENTATION_2D		1
312 #define ADXL_EN_ORIENTATION_3D		2
313 #define ADXL_EN_ORIENTATION_2D_3D	3
314 
315 	u8 orientation_enable;
316 
317 	/*
318 	 * The width of the deadzone region between two or more
319 	 * orientation positions is determined by setting the Deadzone
320 	 * value. The deadzone region size can be specified with a
321 	 * resolution of 3.6deg. The deadzone angle represents the total
322 	 * angle where the orientation is considered invalid.
323 	 */
324 
325 #define ADXL_DEADZONE_ANGLE_0p0		0	/* !!!0.0 [deg] */
326 #define ADXL_DEADZONE_ANGLE_3p6		1	/* 3.6 [deg] */
327 #define ADXL_DEADZONE_ANGLE_7p2		2	/* 7.2 [deg] */
328 #define ADXL_DEADZONE_ANGLE_10p8	3	/* 10.8 [deg] */
329 #define ADXL_DEADZONE_ANGLE_14p4	4	/* 14.4 [deg] */
330 #define ADXL_DEADZONE_ANGLE_18p0	5	/* 18.0 [deg] */
331 #define ADXL_DEADZONE_ANGLE_21p6	6	/* 21.6 [deg] */
332 #define ADXL_DEADZONE_ANGLE_25p2	7	/* 25.2 [deg] */
333 
334 	u8 deadzone_angle;
335 
336 	/*
337 	 * To eliminate most human motion such as walking or shaking,
338 	 * a Divisor value should be selected to effectively limit the
339 	 * orientation bandwidth. Set the depth of the filter used to
340 	 * low-pass filter the measured acceleration for stable
341 	 * orientation sensing
342 	 */
343 
344 #define ADXL_LP_FILTER_DIVISOR_2	0
345 #define ADXL_LP_FILTER_DIVISOR_4	1
346 #define ADXL_LP_FILTER_DIVISOR_8	2
347 #define ADXL_LP_FILTER_DIVISOR_16	3
348 #define ADXL_LP_FILTER_DIVISOR_32	4
349 #define ADXL_LP_FILTER_DIVISOR_64	5
350 #define ADXL_LP_FILTER_DIVISOR_128	6
351 #define ADXL_LP_FILTER_DIVISOR_256	7
352 
353 	u8 divisor_length;
354 
355 	u32 ev_codes_orient_2d[4];	/* EV_KEY {+X, -X, +Y, -Y} */
356 	u32 ev_codes_orient_3d[6];	/* EV_KEY {+Z, +Y, +X, -X, -Y, -Z} */
357 };
358 #endif
359