adxl34x.h 11 KB

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