2017-01-11 05:55:18 +08:00
|
|
|
/*
|
|
|
|
* STMicroelectronics st_lsm6dsx sensor driver
|
|
|
|
*
|
|
|
|
* Copyright 2016 STMicroelectronics Inc.
|
|
|
|
*
|
|
|
|
* Lorenzo Bianconi <lorenzo.bianconi@st.com>
|
|
|
|
* Denis Ciocca <denis.ciocca@st.com>
|
|
|
|
*
|
|
|
|
* Licensed under the GPL-2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ST_LSM6DSX_H
|
|
|
|
#define ST_LSM6DSX_H
|
|
|
|
|
|
|
|
#include <linux/device.h>
|
|
|
|
|
|
|
|
#define ST_LSM6DS3_DEV_NAME "lsm6ds3"
|
2017-01-29 18:49:27 +08:00
|
|
|
#define ST_LSM6DS3H_DEV_NAME "lsm6ds3h"
|
2017-01-29 18:49:25 +08:00
|
|
|
#define ST_LSM6DSL_DEV_NAME "lsm6dsl"
|
2017-01-11 05:55:18 +08:00
|
|
|
#define ST_LSM6DSM_DEV_NAME "lsm6dsm"
|
2018-03-31 04:33:50 +08:00
|
|
|
#define ST_ISM330DLC_DEV_NAME "ism330dlc"
|
2018-08-31 04:52:58 +08:00
|
|
|
#define ST_LSM6DSO_DEV_NAME "lsm6dso"
|
2017-01-11 05:55:18 +08:00
|
|
|
|
|
|
|
enum st_lsm6dsx_hw_id {
|
|
|
|
ST_LSM6DS3_ID,
|
2017-01-29 18:49:27 +08:00
|
|
|
ST_LSM6DS3H_ID,
|
2017-01-29 18:49:25 +08:00
|
|
|
ST_LSM6DSL_ID,
|
2017-01-11 05:55:18 +08:00
|
|
|
ST_LSM6DSM_ID,
|
2018-03-31 04:33:50 +08:00
|
|
|
ST_ISM330DLC_ID,
|
2018-08-31 04:52:58 +08:00
|
|
|
ST_LSM6DSO_ID,
|
2017-01-29 18:49:24 +08:00
|
|
|
ST_LSM6DSX_MAX_ID,
|
2017-01-11 05:55:18 +08:00
|
|
|
};
|
|
|
|
|
2018-08-31 04:52:58 +08:00
|
|
|
#define ST_LSM6DSX_BUFF_SIZE 512
|
2017-01-11 05:55:18 +08:00
|
|
|
#define ST_LSM6DSX_CHAN_SIZE 2
|
|
|
|
#define ST_LSM6DSX_SAMPLE_SIZE 6
|
2018-08-31 04:52:58 +08:00
|
|
|
#define ST_LSM6DSX_TAG_SIZE 1
|
|
|
|
#define ST_LSM6DSX_TAGGED_SAMPLE_SIZE (ST_LSM6DSX_SAMPLE_SIZE + \
|
|
|
|
ST_LSM6DSX_TAG_SIZE)
|
2018-01-02 02:54:44 +08:00
|
|
|
#define ST_LSM6DSX_MAX_WORD_LEN ((32 / ST_LSM6DSX_SAMPLE_SIZE) * \
|
|
|
|
ST_LSM6DSX_SAMPLE_SIZE)
|
2018-08-31 04:52:58 +08:00
|
|
|
#define ST_LSM6DSX_MAX_TAGGED_WORD_LEN ((32 / ST_LSM6DSX_TAGGED_SAMPLE_SIZE) \
|
|
|
|
* ST_LSM6DSX_TAGGED_SAMPLE_SIZE)
|
2018-01-02 02:54:44 +08:00
|
|
|
#define ST_LSM6DSX_SHIFT_VAL(val, mask) (((val) << __ffs(mask)) & (mask))
|
2017-01-11 05:55:18 +08:00
|
|
|
|
2018-11-11 22:15:33 +08:00
|
|
|
#define ST_LSM6DSX_CHANNEL(chan_type, addr, mod, scan_idx) \
|
|
|
|
{ \
|
|
|
|
.type = chan_type, \
|
|
|
|
.address = addr, \
|
|
|
|
.modified = 1, \
|
|
|
|
.channel2 = mod, \
|
|
|
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
|
|
|
|
BIT(IIO_CHAN_INFO_SCALE), \
|
|
|
|
.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
|
|
|
|
.scan_index = scan_idx, \
|
|
|
|
.scan_type = { \
|
|
|
|
.sign = 's', \
|
|
|
|
.realbits = 16, \
|
|
|
|
.storagebits = 16, \
|
|
|
|
.endianness = IIO_LE, \
|
|
|
|
}, \
|
|
|
|
}
|
|
|
|
|
2017-01-11 05:55:18 +08:00
|
|
|
struct st_lsm6dsx_reg {
|
|
|
|
u8 addr;
|
|
|
|
u8 mask;
|
|
|
|
};
|
|
|
|
|
2018-08-31 04:52:55 +08:00
|
|
|
struct st_lsm6dsx_hw;
|
|
|
|
|
2018-11-11 22:15:33 +08:00
|
|
|
struct st_lsm6dsx_odr {
|
|
|
|
u16 hz;
|
|
|
|
u8 val;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define ST_LSM6DSX_ODR_LIST_SIZE 6
|
|
|
|
struct st_lsm6dsx_odr_table_entry {
|
|
|
|
struct st_lsm6dsx_reg reg;
|
|
|
|
struct st_lsm6dsx_odr odr_avl[ST_LSM6DSX_ODR_LIST_SIZE];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct st_lsm6dsx_fs {
|
|
|
|
u32 gain;
|
|
|
|
u8 val;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define ST_LSM6DSX_FS_LIST_SIZE 4
|
|
|
|
struct st_lsm6dsx_fs_table_entry {
|
|
|
|
struct st_lsm6dsx_reg reg;
|
|
|
|
struct st_lsm6dsx_fs fs_avl[ST_LSM6DSX_FS_LIST_SIZE];
|
|
|
|
};
|
|
|
|
|
2017-10-03 00:37:40 +08:00
|
|
|
/**
|
|
|
|
* struct st_lsm6dsx_fifo_ops - ST IMU FIFO settings
|
2018-08-31 04:52:55 +08:00
|
|
|
* @read_fifo: Read FIFO callback.
|
2017-10-03 00:37:40 +08:00
|
|
|
* @fifo_th: FIFO threshold register info (addr + mask).
|
|
|
|
* @fifo_diff: FIFO diff status register info (addr + mask).
|
|
|
|
* @th_wl: FIFO threshold word length.
|
|
|
|
*/
|
|
|
|
struct st_lsm6dsx_fifo_ops {
|
2018-08-31 04:52:55 +08:00
|
|
|
int (*read_fifo)(struct st_lsm6dsx_hw *hw);
|
2017-10-03 00:37:40 +08:00
|
|
|
struct {
|
|
|
|
u8 addr;
|
|
|
|
u16 mask;
|
|
|
|
} fifo_th;
|
|
|
|
struct {
|
|
|
|
u8 addr;
|
|
|
|
u16 mask;
|
|
|
|
} fifo_diff;
|
|
|
|
u8 th_wl;
|
|
|
|
};
|
|
|
|
|
2018-01-14 01:57:56 +08:00
|
|
|
/**
|
|
|
|
* struct st_lsm6dsx_hw_ts_settings - ST IMU hw timer settings
|
|
|
|
* @timer_en: Hw timer enable register info (addr + mask).
|
|
|
|
* @hr_timer: Hw timer resolution register info (addr + mask).
|
|
|
|
* @fifo_en: Hw timer FIFO enable register info (addr + mask).
|
|
|
|
* @decimator: Hw timer FIFO decimator register info (addr + mask).
|
|
|
|
*/
|
|
|
|
struct st_lsm6dsx_hw_ts_settings {
|
|
|
|
struct st_lsm6dsx_reg timer_en;
|
|
|
|
struct st_lsm6dsx_reg hr_timer;
|
|
|
|
struct st_lsm6dsx_reg fifo_en;
|
|
|
|
struct st_lsm6dsx_reg decimator;
|
|
|
|
};
|
|
|
|
|
2018-11-11 22:15:33 +08:00
|
|
|
/**
|
|
|
|
* struct st_lsm6dsx_shub_settings - ST IMU hw i2c controller settings
|
|
|
|
* @page_mux: register page mux info (addr + mask).
|
|
|
|
* @master_en: master config register info (addr + mask).
|
|
|
|
* @pullup_en: i2c controller pull-up register info (addr + mask).
|
|
|
|
* @aux_sens: aux sensor register info (addr + mask).
|
2018-11-11 22:15:35 +08:00
|
|
|
* @wr_once: write_once register info (addr + mask).
|
2018-11-11 22:15:33 +08:00
|
|
|
* @shub_out: sensor hub first output register info.
|
|
|
|
* @slv0_addr: slave0 address in secondary page.
|
|
|
|
* @dw_slv0_addr: slave0 write register address in secondary page.
|
2018-11-11 22:15:35 +08:00
|
|
|
* @batch_en: Enable/disable FIFO batching.
|
2018-11-11 22:15:33 +08:00
|
|
|
*/
|
|
|
|
struct st_lsm6dsx_shub_settings {
|
|
|
|
struct st_lsm6dsx_reg page_mux;
|
|
|
|
struct st_lsm6dsx_reg master_en;
|
|
|
|
struct st_lsm6dsx_reg pullup_en;
|
|
|
|
struct st_lsm6dsx_reg aux_sens;
|
2018-11-11 22:15:35 +08:00
|
|
|
struct st_lsm6dsx_reg wr_once;
|
2018-11-11 22:15:33 +08:00
|
|
|
u8 shub_out;
|
|
|
|
u8 slv0_addr;
|
|
|
|
u8 dw_slv0_addr;
|
2018-11-11 22:15:35 +08:00
|
|
|
u8 batch_en;
|
2018-11-11 22:15:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
enum st_lsm6dsx_ext_sensor_id {
|
|
|
|
ST_LSM6DSX_ID_MAGN,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct st_lsm6dsx_ext_dev_settings - i2c controller slave settings
|
|
|
|
* @i2c_addr: I2c slave address list.
|
|
|
|
* @wai: Wai address info.
|
|
|
|
* @id: external sensor id.
|
|
|
|
* @odr: Output data rate of the sensor [Hz].
|
|
|
|
* @gain: Configured sensor sensitivity.
|
|
|
|
* @temp_comp: Temperature compensation register info (addr + mask).
|
|
|
|
* @pwr_table: Power on register info (addr + mask).
|
|
|
|
* @off_canc: Offset cancellation register info (addr + mask).
|
|
|
|
* @bdu: Block data update register info (addr + mask).
|
|
|
|
* @out: Output register info.
|
|
|
|
*/
|
|
|
|
struct st_lsm6dsx_ext_dev_settings {
|
|
|
|
u8 i2c_addr[2];
|
|
|
|
struct {
|
|
|
|
u8 addr;
|
|
|
|
u8 val;
|
|
|
|
} wai;
|
|
|
|
enum st_lsm6dsx_ext_sensor_id id;
|
|
|
|
struct st_lsm6dsx_odr_table_entry odr_table;
|
|
|
|
struct st_lsm6dsx_fs_table_entry fs_table;
|
|
|
|
struct st_lsm6dsx_reg temp_comp;
|
|
|
|
struct {
|
|
|
|
struct st_lsm6dsx_reg reg;
|
|
|
|
u8 off_val;
|
|
|
|
u8 on_val;
|
|
|
|
} pwr_table;
|
|
|
|
struct st_lsm6dsx_reg off_canc;
|
|
|
|
struct st_lsm6dsx_reg bdu;
|
|
|
|
struct {
|
|
|
|
u8 addr;
|
|
|
|
u8 len;
|
|
|
|
} out;
|
|
|
|
};
|
|
|
|
|
2017-10-03 00:37:39 +08:00
|
|
|
/**
|
|
|
|
* struct st_lsm6dsx_settings - ST IMU sensor settings
|
|
|
|
* @wai: Sensor WhoAmI default value.
|
|
|
|
* @max_fifo_size: Sensor max fifo length in FIFO words.
|
|
|
|
* @id: List of hw id supported by the driver configuration.
|
|
|
|
* @decimator: List of decimator register info (addr + mask).
|
2018-08-31 04:52:58 +08:00
|
|
|
* @batch: List of FIFO batching register info (addr + mask).
|
2017-10-03 00:37:40 +08:00
|
|
|
* @fifo_ops: Sensor hw FIFO parameters.
|
2018-01-14 01:57:56 +08:00
|
|
|
* @ts_settings: Hw timer related settings.
|
2018-11-11 22:15:33 +08:00
|
|
|
* @shub_settings: i2c controller related settings.
|
2017-10-03 00:37:39 +08:00
|
|
|
*/
|
2017-01-11 05:55:18 +08:00
|
|
|
struct st_lsm6dsx_settings {
|
|
|
|
u8 wai;
|
|
|
|
u16 max_fifo_size;
|
2017-01-29 18:49:24 +08:00
|
|
|
enum st_lsm6dsx_hw_id id[ST_LSM6DSX_MAX_ID];
|
2017-10-03 00:37:39 +08:00
|
|
|
struct st_lsm6dsx_reg decimator[ST_LSM6DSX_MAX_ID];
|
2018-08-31 04:52:58 +08:00
|
|
|
struct st_lsm6dsx_reg batch[ST_LSM6DSX_MAX_ID];
|
2017-10-03 00:37:40 +08:00
|
|
|
struct st_lsm6dsx_fifo_ops fifo_ops;
|
2018-01-14 01:57:56 +08:00
|
|
|
struct st_lsm6dsx_hw_ts_settings ts_settings;
|
2018-11-11 22:15:33 +08:00
|
|
|
struct st_lsm6dsx_shub_settings shub_settings;
|
2017-01-11 05:55:18 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
enum st_lsm6dsx_sensor_id {
|
|
|
|
ST_LSM6DSX_ID_GYRO,
|
2018-11-11 22:15:31 +08:00
|
|
|
ST_LSM6DSX_ID_ACC,
|
|
|
|
ST_LSM6DSX_ID_EXT0,
|
|
|
|
ST_LSM6DSX_ID_EXT1,
|
|
|
|
ST_LSM6DSX_ID_EXT2,
|
2017-01-11 05:55:18 +08:00
|
|
|
ST_LSM6DSX_ID_MAX,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum st_lsm6dsx_fifo_mode {
|
|
|
|
ST_LSM6DSX_FIFO_BYPASS = 0x0,
|
|
|
|
ST_LSM6DSX_FIFO_CONT = 0x6,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct st_lsm6dsx_sensor - ST IMU sensor instance
|
2017-04-04 01:27:39 +08:00
|
|
|
* @name: Sensor name.
|
2017-01-11 05:55:18 +08:00
|
|
|
* @id: Sensor identifier.
|
|
|
|
* @hw: Pointer to instance of struct st_lsm6dsx_hw.
|
|
|
|
* @gain: Configured sensor sensitivity.
|
|
|
|
* @odr: Output data rate of the sensor [Hz].
|
|
|
|
* @watermark: Sensor watermark level.
|
|
|
|
* @sip: Number of samples in a given pattern.
|
|
|
|
* @decimator: FIFO decimation factor.
|
2018-01-14 01:57:56 +08:00
|
|
|
* @ts_ref: Sensor timestamp reference for hw one.
|
2018-11-11 22:15:33 +08:00
|
|
|
* @ext_info: Sensor settings if it is connected to i2c controller
|
2017-01-11 05:55:18 +08:00
|
|
|
*/
|
|
|
|
struct st_lsm6dsx_sensor {
|
2017-04-04 01:27:39 +08:00
|
|
|
char name[32];
|
2017-01-11 05:55:18 +08:00
|
|
|
enum st_lsm6dsx_sensor_id id;
|
|
|
|
struct st_lsm6dsx_hw *hw;
|
|
|
|
|
|
|
|
u32 gain;
|
|
|
|
u16 odr;
|
|
|
|
|
|
|
|
u16 watermark;
|
|
|
|
u8 sip;
|
|
|
|
u8 decimator;
|
2018-01-14 01:57:56 +08:00
|
|
|
s64 ts_ref;
|
2018-11-11 22:15:33 +08:00
|
|
|
|
|
|
|
struct {
|
|
|
|
const struct st_lsm6dsx_ext_dev_settings *settings;
|
|
|
|
u8 addr;
|
|
|
|
} ext_info;
|
2017-01-11 05:55:18 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct st_lsm6dsx_hw - ST IMU MEMS hw instance
|
|
|
|
* @dev: Pointer to instance of struct device (I2C or SPI).
|
2018-01-02 02:54:44 +08:00
|
|
|
* @regmap: Register map of the device.
|
2017-01-11 05:55:18 +08:00
|
|
|
* @irq: Device interrupt line (I2C or SPI).
|
|
|
|
* @fifo_lock: Mutex to prevent concurrent access to the hw FIFO.
|
2018-01-02 02:54:43 +08:00
|
|
|
* @conf_lock: Mutex to prevent concurrent FIFO configuration update.
|
2018-11-11 22:15:28 +08:00
|
|
|
* @page_lock: Mutex to prevent concurrent memory page configuration.
|
2017-01-11 05:55:18 +08:00
|
|
|
* @fifo_mode: FIFO operating mode supported by the device.
|
|
|
|
* @enable_mask: Enabled sensor bitmask.
|
2018-01-14 01:57:56 +08:00
|
|
|
* @ts_sip: Total number of timestamp samples in a given pattern.
|
|
|
|
* @sip: Total number of samples (acc/gyro/ts) in a given pattern.
|
2018-01-07 06:23:24 +08:00
|
|
|
* @buff: Device read buffer.
|
2017-01-11 05:55:18 +08:00
|
|
|
* @iio_devs: Pointers to acc/gyro iio_dev instances.
|
|
|
|
* @settings: Pointer to the specific sensor settings in use.
|
|
|
|
*/
|
|
|
|
struct st_lsm6dsx_hw {
|
|
|
|
struct device *dev;
|
2018-01-02 02:54:44 +08:00
|
|
|
struct regmap *regmap;
|
2017-01-11 05:55:18 +08:00
|
|
|
int irq;
|
|
|
|
|
|
|
|
struct mutex fifo_lock;
|
2018-01-02 02:54:43 +08:00
|
|
|
struct mutex conf_lock;
|
2018-11-11 22:15:28 +08:00
|
|
|
struct mutex page_lock;
|
2017-01-11 05:55:18 +08:00
|
|
|
|
|
|
|
enum st_lsm6dsx_fifo_mode fifo_mode;
|
|
|
|
u8 enable_mask;
|
2018-01-14 01:57:56 +08:00
|
|
|
u8 ts_sip;
|
2017-01-11 05:55:18 +08:00
|
|
|
u8 sip;
|
|
|
|
|
2018-01-07 06:23:24 +08:00
|
|
|
u8 *buff;
|
|
|
|
|
2017-01-11 05:55:18 +08:00
|
|
|
struct iio_dev *iio_devs[ST_LSM6DSX_ID_MAX];
|
|
|
|
|
|
|
|
const struct st_lsm6dsx_settings *settings;
|
|
|
|
};
|
|
|
|
|
2018-11-11 22:15:33 +08:00
|
|
|
static const unsigned long st_lsm6dsx_available_scan_masks[] = {0x7, 0x0};
|
2017-04-28 04:31:56 +08:00
|
|
|
extern const struct dev_pm_ops st_lsm6dsx_pm_ops;
|
|
|
|
|
2017-04-04 01:27:39 +08:00
|
|
|
int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id, const char *name,
|
2018-01-02 02:54:44 +08:00
|
|
|
struct regmap *regmap);
|
2018-11-11 22:15:32 +08:00
|
|
|
int st_lsm6dsx_sensor_set_enable(struct st_lsm6dsx_sensor *sensor,
|
|
|
|
bool enable);
|
2017-01-11 05:55:18 +08:00
|
|
|
int st_lsm6dsx_fifo_setup(struct st_lsm6dsx_hw *hw);
|
2018-11-11 22:15:30 +08:00
|
|
|
int st_lsm6dsx_set_watermark(struct iio_dev *iio_dev, unsigned int val);
|
2017-01-11 05:55:18 +08:00
|
|
|
int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor,
|
|
|
|
u16 watermark);
|
2017-04-28 04:31:55 +08:00
|
|
|
int st_lsm6dsx_flush_fifo(struct st_lsm6dsx_hw *hw);
|
|
|
|
int st_lsm6dsx_set_fifo_mode(struct st_lsm6dsx_hw *hw,
|
|
|
|
enum st_lsm6dsx_fifo_mode fifo_mode);
|
2018-08-31 04:52:55 +08:00
|
|
|
int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw);
|
2018-08-31 04:52:58 +08:00
|
|
|
int st_lsm6dsx_read_tagged_fifo(struct st_lsm6dsx_hw *hw);
|
2018-08-31 04:52:56 +08:00
|
|
|
int st_lsm6dsx_check_odr(struct st_lsm6dsx_sensor *sensor, u16 odr, u8 *val);
|
2018-11-11 22:15:33 +08:00
|
|
|
int st_lsm6dsx_shub_probe(struct st_lsm6dsx_hw *hw, const char *name);
|
|
|
|
int st_lsm6dsx_shub_set_enable(struct st_lsm6dsx_sensor *sensor, bool enable);
|
|
|
|
int st_lsm6dsx_set_page(struct st_lsm6dsx_hw *hw, bool enable);
|
2017-01-11 05:55:18 +08:00
|
|
|
|
2018-11-11 22:15:28 +08:00
|
|
|
static inline int
|
|
|
|
st_lsm6dsx_update_bits_locked(struct st_lsm6dsx_hw *hw, unsigned int addr,
|
|
|
|
unsigned int mask, unsigned int val)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
mutex_lock(&hw->page_lock);
|
|
|
|
err = regmap_update_bits(hw->regmap, addr, mask, val);
|
|
|
|
mutex_unlock(&hw->page_lock);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
st_lsm6dsx_read_locked(struct st_lsm6dsx_hw *hw, unsigned int addr,
|
|
|
|
void *val, unsigned int len)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
mutex_lock(&hw->page_lock);
|
|
|
|
err = regmap_bulk_read(hw->regmap, addr, val, len);
|
|
|
|
mutex_unlock(&hw->page_lock);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
st_lsm6dsx_write_locked(struct st_lsm6dsx_hw *hw, unsigned int addr,
|
|
|
|
unsigned int val)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
mutex_lock(&hw->page_lock);
|
|
|
|
err = regmap_write(hw->regmap, addr, val);
|
|
|
|
mutex_unlock(&hw->page_lock);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2017-01-11 05:55:18 +08:00
|
|
|
#endif /* ST_LSM6DSX_H */
|