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 */
274 u8 odr_mask
; /* ODR bit mask */
275 u8 whoami
; /* indicates measurement precision */
276 s16 (*read_data
) (struct lis3lv02d
*lis3
, int reg
);
280 * relationship between 1 LBS and mG
281 * (1/1000th of earth gravity)
284 struct input_dev
*idev
; /* input device */
285 struct platform_device
*pdev
; /* platform device */
286 struct regulator_bulk_data regulators
[2];
287 atomic_t count
; /* interrupt count after last read */
288 union axis_conversion ac
; /* hw -> logical axis */
291 u32 irq
; /* IRQ number */
292 struct fasync_struct
*async_queue
; /* queue for the misc device */
293 wait_queue_head_t misc_wait
; /* Wait queue for the misc device */
294 unsigned long misc_opened
; /* bit0: whether the device is open */
295 struct miscdevice miscdev
;
297 int data_ready_count
[2];
298 atomic_t wake_thread
;
299 unsigned char irq_cfg
;
300 unsigned int shift_adj
;
302 struct lis3lv02d_platform_data
*pdata
; /* for passing board config */
303 struct mutex mutex
; /* Serialize poll and selftest */
306 struct device_node
*of_node
;
310 int lis3lv02d_init_device(struct lis3lv02d
*lis3
);
311 int lis3lv02d_joystick_enable(struct lis3lv02d
*lis3
);
312 void lis3lv02d_joystick_disable(struct lis3lv02d
*lis3
);
313 void lis3lv02d_poweroff(struct lis3lv02d
*lis3
);
314 int lis3lv02d_poweron(struct lis3lv02d
*lis3
);
315 void lis3lv02d_remove_fs(struct lis3lv02d
*lis3
);
316 int lis3lv02d_init_dt(struct lis3lv02d
*lis3
);
318 extern struct lis3lv02d lis3_dev
;