1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * lis3lv02d.h - ST LIS3LV02DL accelerometer driver
5 * Copyright (C) 2007-2008 Yan Burman
6 * Copyright (C) 2008-2009 Eric Piel
8 #include <linux/platform_device.h>
9 #include <linux/input.h>
10 #include <linux/regulator/consumer.h>
11 #include <linux/miscdevice.h>
14 * This driver tries to support the "digital" accelerometer chips from
15 * STMicroelectronics such as LIS3LV02DL, LIS302DL, LIS3L02DQ, LIS331DL,
16 * LIS331DLH, LIS35DE, or LIS202DL. They are very similar in terms of
17 * programming, with almost the same registers. In addition to differing
18 * on physical properties, they differ on the number of axes (2/3),
19 * precision (8/12 bits), and special features (freefall detection,
20 * click...). Unfortunately, not all the differences can be probed via
21 * a register. They can be connected either via I²C or SPI.
24 #include <linux/lis3lv02d.h>
38 HP_FILTER_RESET = 0x23,
55 FF_WU_DURATION_1 = 0x33,
59 FF_WU_DURATION_2 = 0x37,
64 CLICK_TIMELIMIT = 0x3D,
75 FF_WU_DURATION = 0x36,
86 WAI_3DLH = 0x32, /* 16 bits: LIS331DLH */
87 WAI_3DC = 0x33, /* 8 bits: LIS3DC, HP3DC */
88 WAI_12B = 0x3A, /* 12 bits: LIS3LV02D[LQ]... */
89 WAI_8B = 0x3B, /* 8 bits: LIS[23]02D[LQ]... */
90 WAI_6B = 0x52, /* 6 bits: LIS331DLF - not supported */
102 enum lis3lv02d_ctrl1_12b {
113 /* Delta to ctrl1_12b version */
114 enum lis3lv02d_ctrl1_8b {
122 enum lis3lv02d_ctrl1_3dc {
129 enum lis331dlh_ctrl1 {
137 enum lis331dlh_ctrl2 {
140 CTRL2_FDS_3DLH = 0x10,
141 CTRL2_BOOT_3DLH = 0x80,
144 enum lis331dlh_ctrl4 {
150 enum lis3lv02d_ctrl2 {
157 CTRL2_BDU = 0x40, /* Block Data Update */
158 CTRL2_FS = 0x80, /* Full Scale selection */
161 enum lis3lv02d_ctrl4_3dc {
172 CTRL2_BOOT_8B = 0x40,
175 enum lis3lv02d_ctrl3 {
184 enum lis3lv02d_status_reg {
195 enum lis3lv02d_ff_wu_cfg {
196 FF_WU_CFG_XLIE = 0x01,
197 FF_WU_CFG_XHIE = 0x02,
198 FF_WU_CFG_YLIE = 0x04,
199 FF_WU_CFG_YHIE = 0x08,
200 FF_WU_CFG_ZLIE = 0x10,
201 FF_WU_CFG_ZHIE = 0x20,
202 FF_WU_CFG_LIR = 0x40,
203 FF_WU_CFG_AOI = 0x80,
206 enum lis3lv02d_ff_wu_src {
216 enum lis3lv02d_dd_cfg {
227 enum lis3lv02d_dd_src {
237 enum lis3lv02d_click_src_8b {
238 CLICK_SINGLE_X = 0x01,
239 CLICK_DOUBLE_X = 0x02,
240 CLICK_SINGLE_Y = 0x04,
241 CLICK_DOUBLE_Y = 0x08,
242 CLICK_SINGLE_Z = 0x10,
243 CLICK_DOUBLE_Z = 0x20,
247 enum lis3lv02d_reg_state {
252 union axis_conversion {
261 void *bus_priv; /* used by the bus layer only */
262 struct device *pm_dev; /* for pm_runtime purposes */
263 int (*init) (struct lis3lv02d *lis3);
264 int (*write) (struct lis3lv02d *lis3, int reg, u8 val);
265 int (*read) (struct lis3lv02d *lis3, int reg, u8 *ret);
266 int (*blkread) (struct lis3lv02d *lis3, int reg, int len, u8 *ret);
267 int (*reg_ctrl) (struct lis3lv02d *lis3, bool state);
269 int *odrs; /* Supported output data rates */
270 u8 *regs; /* Regs to store / restore */
275 u8 odr_mask; /* ODR bit mask */
276 u8 whoami; /* indicates measurement precision */
277 s16 (*read_data) (struct lis3lv02d *lis3, int reg);
281 * relationship between 1 LBS and mG
282 * (1/1000th of earth gravity)
285 struct input_dev *idev; /* input device */
286 struct platform_device *pdev; /* platform device */
287 struct regulator_bulk_data regulators[2];
288 atomic_t count; /* interrupt count after last read */
289 union axis_conversion ac; /* hw -> logical axis */
292 u32 irq; /* IRQ number */
293 struct fasync_struct *async_queue; /* queue for the misc device */
294 wait_queue_head_t misc_wait; /* Wait queue for the misc device */
295 unsigned long misc_opened; /* bit0: whether the device is open */
296 struct miscdevice miscdev;
298 int data_ready_count[2];
299 atomic_t wake_thread;
300 unsigned char irq_cfg;
301 unsigned int shift_adj;
303 struct lis3lv02d_platform_data *pdata; /* for passing board config */
304 struct mutex mutex; /* Serialize poll and selftest */
307 struct device_node *of_node;
311 int lis3lv02d_init_device(struct lis3lv02d *lis3);
312 int lis3lv02d_joystick_enable(struct lis3lv02d *lis3);
313 void lis3lv02d_joystick_disable(struct lis3lv02d *lis3);
314 void lis3lv02d_poweroff(struct lis3lv02d *lis3);
315 int lis3lv02d_poweron(struct lis3lv02d *lis3);
316 int lis3lv02d_remove_fs(struct lis3lv02d *lis3);
317 int lis3lv02d_init_dt(struct lis3lv02d *lis3);
319 extern struct lis3lv02d lis3_dev;