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"
21 #define ST_ISM330DLC_DEV_NAME "ism330dlc"
23 enum st_lsm6dsx_hw_id
{
32 #define ST_LSM6DSX_BUFF_SIZE 400
33 #define ST_LSM6DSX_CHAN_SIZE 2
34 #define ST_LSM6DSX_SAMPLE_SIZE 6
35 #define ST_LSM6DSX_MAX_WORD_LEN ((32 / ST_LSM6DSX_SAMPLE_SIZE) * \
36 ST_LSM6DSX_SAMPLE_SIZE)
37 #define ST_LSM6DSX_SHIFT_VAL(val, mask) (((val) << __ffs(mask)) & (mask))
39 struct st_lsm6dsx_reg
{
45 * struct st_lsm6dsx_fifo_ops - ST IMU FIFO settings
46 * @fifo_th: FIFO threshold register info (addr + mask).
47 * @fifo_diff: FIFO diff status register info (addr + mask).
48 * @th_wl: FIFO threshold word length.
50 struct st_lsm6dsx_fifo_ops
{
63 * struct st_lsm6dsx_hw_ts_settings - ST IMU hw timer settings
64 * @timer_en: Hw timer enable register info (addr + mask).
65 * @hr_timer: Hw timer resolution register info (addr + mask).
66 * @fifo_en: Hw timer FIFO enable register info (addr + mask).
67 * @decimator: Hw timer FIFO decimator register info (addr + mask).
69 struct st_lsm6dsx_hw_ts_settings
{
70 struct st_lsm6dsx_reg timer_en
;
71 struct st_lsm6dsx_reg hr_timer
;
72 struct st_lsm6dsx_reg fifo_en
;
73 struct st_lsm6dsx_reg decimator
;
77 * struct st_lsm6dsx_settings - ST IMU sensor settings
78 * @wai: Sensor WhoAmI default value.
79 * @max_fifo_size: Sensor max fifo length in FIFO words.
80 * @id: List of hw id supported by the driver configuration.
81 * @decimator: List of decimator register info (addr + mask).
82 * @fifo_ops: Sensor hw FIFO parameters.
83 * @ts_settings: Hw timer related settings.
85 struct st_lsm6dsx_settings
{
88 enum st_lsm6dsx_hw_id id
[ST_LSM6DSX_MAX_ID
];
89 struct st_lsm6dsx_reg decimator
[ST_LSM6DSX_MAX_ID
];
90 struct st_lsm6dsx_fifo_ops fifo_ops
;
91 struct st_lsm6dsx_hw_ts_settings ts_settings
;
94 enum st_lsm6dsx_sensor_id
{
100 enum st_lsm6dsx_fifo_mode
{
101 ST_LSM6DSX_FIFO_BYPASS
= 0x0,
102 ST_LSM6DSX_FIFO_CONT
= 0x6,
106 * struct st_lsm6dsx_sensor - ST IMU sensor instance
107 * @name: Sensor name.
108 * @id: Sensor identifier.
109 * @hw: Pointer to instance of struct st_lsm6dsx_hw.
110 * @gain: Configured sensor sensitivity.
111 * @odr: Output data rate of the sensor [Hz].
112 * @watermark: Sensor watermark level.
113 * @sip: Number of samples in a given pattern.
114 * @decimator: FIFO decimation factor.
115 * @ts_ref: Sensor timestamp reference for hw one.
117 struct st_lsm6dsx_sensor
{
119 enum st_lsm6dsx_sensor_id id
;
120 struct st_lsm6dsx_hw
*hw
;
132 * struct st_lsm6dsx_hw - ST IMU MEMS hw instance
133 * @dev: Pointer to instance of struct device (I2C or SPI).
134 * @regmap: Register map of the device.
135 * @irq: Device interrupt line (I2C or SPI).
136 * @fifo_lock: Mutex to prevent concurrent access to the hw FIFO.
137 * @conf_lock: Mutex to prevent concurrent FIFO configuration update.
138 * @fifo_mode: FIFO operating mode supported by the device.
139 * @enable_mask: Enabled sensor bitmask.
140 * @ts_sip: Total number of timestamp samples in a given pattern.
141 * @sip: Total number of samples (acc/gyro/ts) in a given pattern.
142 * @buff: Device read buffer.
143 * @iio_devs: Pointers to acc/gyro iio_dev instances.
144 * @settings: Pointer to the specific sensor settings in use.
146 struct st_lsm6dsx_hw
{
148 struct regmap
*regmap
;
151 struct mutex fifo_lock
;
152 struct mutex conf_lock
;
154 enum st_lsm6dsx_fifo_mode fifo_mode
;
161 struct iio_dev
*iio_devs
[ST_LSM6DSX_ID_MAX
];
163 const struct st_lsm6dsx_settings
*settings
;
166 extern const struct dev_pm_ops st_lsm6dsx_pm_ops
;
168 int st_lsm6dsx_probe(struct device
*dev
, int irq
, int hw_id
, const char *name
,
169 struct regmap
*regmap
);
170 int st_lsm6dsx_sensor_enable(struct st_lsm6dsx_sensor
*sensor
);
171 int st_lsm6dsx_sensor_disable(struct st_lsm6dsx_sensor
*sensor
);
172 int st_lsm6dsx_fifo_setup(struct st_lsm6dsx_hw
*hw
);
173 int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor
*sensor
,
175 int st_lsm6dsx_flush_fifo(struct st_lsm6dsx_hw
*hw
);
176 int st_lsm6dsx_set_fifo_mode(struct st_lsm6dsx_hw
*hw
,
177 enum st_lsm6dsx_fifo_mode fifo_mode
);
179 #endif /* ST_LSM6DSX_H */