2 * STMicroelectronics st_lsm6dsx sensor driver
4 * Copyright 2016 STMicroelectronics Inc.
6 * Lorenzo Bianconi <lorenzo.bianconi@st.com>
7 * Denis Ciocca <denis.ciocca@st.com>
9 * Licensed under the GPL-2.
15 #include <linux/device.h>
17 #define ST_LSM6DS3_DEV_NAME "lsm6ds3"
18 #define ST_LSM6DS3H_DEV_NAME "lsm6ds3h"
19 #define ST_LSM6DSL_DEV_NAME "lsm6dsl"
20 #define ST_LSM6DSM_DEV_NAME "lsm6dsm"
22 enum st_lsm6dsx_hw_id
{
30 #define ST_LSM6DSX_BUFF_SIZE 256
31 #define ST_LSM6DSX_CHAN_SIZE 2
32 #define ST_LSM6DSX_SAMPLE_SIZE 6
33 #define ST_LSM6DSX_MAX_WORD_LEN ((32 / ST_LSM6DSX_SAMPLE_SIZE) * \
34 ST_LSM6DSX_SAMPLE_SIZE)
35 #define ST_LSM6DSX_SHIFT_VAL(val, mask) (((val) << __ffs(mask)) & (mask))
37 struct st_lsm6dsx_reg
{
43 * struct st_lsm6dsx_fifo_ops - ST IMU FIFO settings
44 * @fifo_th: FIFO threshold register info (addr + mask).
45 * @fifo_diff: FIFO diff status register info (addr + mask).
46 * @th_wl: FIFO threshold word length.
48 struct st_lsm6dsx_fifo_ops
{
61 * struct st_lsm6dsx_settings - ST IMU sensor settings
62 * @wai: Sensor WhoAmI default value.
63 * @max_fifo_size: Sensor max fifo length in FIFO words.
64 * @id: List of hw id supported by the driver configuration.
65 * @decimator: List of decimator register info (addr + mask).
66 * @fifo_ops: Sensor hw FIFO parameters.
68 struct st_lsm6dsx_settings
{
71 enum st_lsm6dsx_hw_id id
[ST_LSM6DSX_MAX_ID
];
72 struct st_lsm6dsx_reg decimator
[ST_LSM6DSX_MAX_ID
];
73 struct st_lsm6dsx_fifo_ops fifo_ops
;
76 enum st_lsm6dsx_sensor_id
{
82 enum st_lsm6dsx_fifo_mode
{
83 ST_LSM6DSX_FIFO_BYPASS
= 0x0,
84 ST_LSM6DSX_FIFO_CONT
= 0x6,
88 * struct st_lsm6dsx_sensor - ST IMU sensor instance
90 * @id: Sensor identifier.
91 * @hw: Pointer to instance of struct st_lsm6dsx_hw.
92 * @gain: Configured sensor sensitivity.
93 * @odr: Output data rate of the sensor [Hz].
94 * @watermark: Sensor watermark level.
95 * @sip: Number of samples in a given pattern.
96 * @decimator: FIFO decimation factor.
97 * @delta_ts: Delta time between two consecutive interrupts.
98 * @ts: Latest timestamp from the interrupt handler.
100 struct st_lsm6dsx_sensor
{
102 enum st_lsm6dsx_sensor_id id
;
103 struct st_lsm6dsx_hw
*hw
;
117 * struct st_lsm6dsx_hw - ST IMU MEMS hw instance
118 * @dev: Pointer to instance of struct device (I2C or SPI).
119 * @regmap: Register map of the device.
120 * @irq: Device interrupt line (I2C or SPI).
121 * @fifo_lock: Mutex to prevent concurrent access to the hw FIFO.
122 * @conf_lock: Mutex to prevent concurrent FIFO configuration update.
123 * @fifo_mode: FIFO operating mode supported by the device.
124 * @enable_mask: Enabled sensor bitmask.
125 * @sip: Total number of samples (acc/gyro) in a given pattern.
126 * @buff: Device read buffer.
127 * @iio_devs: Pointers to acc/gyro iio_dev instances.
128 * @settings: Pointer to the specific sensor settings in use.
130 struct st_lsm6dsx_hw
{
132 struct regmap
*regmap
;
135 struct mutex fifo_lock
;
136 struct mutex conf_lock
;
138 enum st_lsm6dsx_fifo_mode fifo_mode
;
144 struct iio_dev
*iio_devs
[ST_LSM6DSX_ID_MAX
];
146 const struct st_lsm6dsx_settings
*settings
;
149 extern const struct dev_pm_ops st_lsm6dsx_pm_ops
;
151 int st_lsm6dsx_probe(struct device
*dev
, int irq
, int hw_id
, const char *name
,
152 struct regmap
*regmap
);
153 int st_lsm6dsx_sensor_enable(struct st_lsm6dsx_sensor
*sensor
);
154 int st_lsm6dsx_sensor_disable(struct st_lsm6dsx_sensor
*sensor
);
155 int st_lsm6dsx_fifo_setup(struct st_lsm6dsx_hw
*hw
);
156 int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor
*sensor
,
158 int st_lsm6dsx_flush_fifo(struct st_lsm6dsx_hw
*hw
);
159 int st_lsm6dsx_set_fifo_mode(struct st_lsm6dsx_hw
*hw
,
160 enum st_lsm6dsx_fifo_mode fifo_mode
);
162 #endif /* ST_LSM6DSX_H */