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