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_CHAN_SIZE 2
31 #define ST_LSM6DSX_SAMPLE_SIZE 6
32 #define ST_LSM6DSX_SAMPLE_DEPTH (ST_LSM6DSX_SAMPLE_SIZE / \
35 #if defined(CONFIG_SPI_MASTER)
36 #define ST_LSM6DSX_RX_MAX_LENGTH 256
37 #define ST_LSM6DSX_TX_MAX_LENGTH 8
39 struct st_lsm6dsx_transfer_buffer {
40 u8 rx_buf[ST_LSM6DSX_RX_MAX_LENGTH];
41 u8 tx_buf[ST_LSM6DSX_TX_MAX_LENGTH] ____cacheline_aligned;
43 #endif /* CONFIG_SPI_MASTER */
45 struct st_lsm6dsx_transfer_function {
46 int (*read)(struct device *dev, u8 addr, int len, u8 *data);
47 int (*write)(struct device *dev, u8 addr, int len, u8 *data);
50 struct st_lsm6dsx_reg {
55 struct st_lsm6dsx_settings {
58 enum st_lsm6dsx_hw_id id[ST_LSM6DSX_MAX_ID];
61 enum st_lsm6dsx_sensor_id {
67 enum st_lsm6dsx_fifo_mode {
68 ST_LSM6DSX_FIFO_BYPASS = 0x0,
69 ST_LSM6DSX_FIFO_CONT = 0x6,
73 * struct st_lsm6dsx_sensor - ST IMU sensor instance
75 * @id: Sensor identifier.
76 * @hw: Pointer to instance of struct st_lsm6dsx_hw.
77 * @gain: Configured sensor sensitivity.
78 * @odr: Output data rate of the sensor [Hz].
79 * @watermark: Sensor watermark level.
80 * @sip: Number of samples in a given pattern.
81 * @decimator: FIFO decimation factor.
82 * @decimator_mask: Sensor mask for decimation register.
83 * @delta_ts: Delta time between two consecutive interrupts.
84 * @ts: Latest timestamp from the interrupt handler.
86 struct st_lsm6dsx_sensor {
88 enum st_lsm6dsx_sensor_id id;
89 struct st_lsm6dsx_hw *hw;
104 * struct st_lsm6dsx_hw - ST IMU MEMS hw instance
105 * @dev: Pointer to instance of struct device (I2C or SPI).
106 * @irq: Device interrupt line (I2C or SPI).
107 * @lock: Mutex to protect read and write operations.
108 * @fifo_lock: Mutex to prevent concurrent access to the hw FIFO.
109 * @fifo_mode: FIFO operating mode supported by the device.
110 * @enable_mask: Enabled sensor bitmask.
111 * @sip: Total number of samples (acc/gyro) in a given pattern.
112 * @iio_devs: Pointers to acc/gyro iio_dev instances.
113 * @settings: Pointer to the specific sensor settings in use.
114 * @tf: Transfer function structure used by I/O operations.
115 * @tb: Transfer buffers used by SPI I/O operations.
117 struct st_lsm6dsx_hw {
122 struct mutex fifo_lock;
124 enum st_lsm6dsx_fifo_mode fifo_mode;
128 struct iio_dev *iio_devs[ST_LSM6DSX_ID_MAX];
130 const struct st_lsm6dsx_settings *settings;
132 const struct st_lsm6dsx_transfer_function *tf;
133 #if defined(CONFIG_SPI_MASTER)
134 struct st_lsm6dsx_transfer_buffer tb;
135 #endif /* CONFIG_SPI_MASTER */
138 extern const struct dev_pm_ops st_lsm6dsx_pm_ops;
140 int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id, const char *name,
141 const struct st_lsm6dsx_transfer_function *tf_ops);
142 int st_lsm6dsx_sensor_enable(struct st_lsm6dsx_sensor *sensor);
143 int st_lsm6dsx_sensor_disable(struct st_lsm6dsx_sensor *sensor);
144 int st_lsm6dsx_fifo_setup(struct st_lsm6dsx_hw *hw);
145 int st_lsm6dsx_write_with_mask(struct st_lsm6dsx_hw *hw, u8 addr, u8 mask,
147 int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor,
149 int st_lsm6dsx_flush_fifo(struct st_lsm6dsx_hw *hw);
150 int st_lsm6dsx_set_fifo_mode(struct st_lsm6dsx_hw *hw,
151 enum st_lsm6dsx_fifo_mode fifo_mode);
153 #endif /* ST_LSM6DSX_H */