2017-01-10 22:55:18 +01: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 11:49:27 +01:00
# define ST_LSM6DS3H_DEV_NAME "lsm6ds3h"
2017-01-29 11:49:25 +01:00
# define ST_LSM6DSL_DEV_NAME "lsm6dsl"
2017-01-10 22:55:18 +01:00
# define ST_LSM6DSM_DEV_NAME "lsm6dsm"
enum st_lsm6dsx_hw_id {
ST_LSM6DS3_ID ,
2017-01-29 11:49:27 +01:00
ST_LSM6DS3H_ID ,
2017-01-29 11:49:25 +01:00
ST_LSM6DSL_ID ,
2017-01-10 22:55:18 +01:00
ST_LSM6DSM_ID ,
2017-01-29 11:49:24 +01:00
ST_LSM6DSX_MAX_ID ,
2017-01-10 22:55:18 +01:00
} ;
2018-01-06 23:23:24 +01:00
# define ST_LSM6DSX_BUFF_SIZE 256
2017-01-10 22:55:18 +01:00
# define ST_LSM6DSX_CHAN_SIZE 2
# define ST_LSM6DSX_SAMPLE_SIZE 6
2018-01-01 19:54:44 +01:00
# define ST_LSM6DSX_MAX_WORD_LEN ((32 / ST_LSM6DSX_SAMPLE_SIZE) * \
ST_LSM6DSX_SAMPLE_SIZE )
# define ST_LSM6DSX_SHIFT_VAL(val, mask) (((val) << __ffs(mask)) & (mask))
2017-01-10 22:55:18 +01:00
struct st_lsm6dsx_reg {
u8 addr ;
u8 mask ;
} ;
2017-10-02 18:37:40 +02:00
/**
* struct st_lsm6dsx_fifo_ops - ST IMU FIFO settings
* @ 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 {
struct {
u8 addr ;
u16 mask ;
} fifo_th ;
struct {
u8 addr ;
u16 mask ;
} fifo_diff ;
u8 th_wl ;
} ;
2017-10-02 18:37:39 +02: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 ) .
2017-10-02 18:37:40 +02:00
* @ fifo_ops : Sensor hw FIFO parameters .
2017-10-02 18:37:39 +02:00
*/
2017-01-10 22:55:18 +01:00
struct st_lsm6dsx_settings {
u8 wai ;
u16 max_fifo_size ;
2017-01-29 11:49:24 +01:00
enum st_lsm6dsx_hw_id id [ ST_LSM6DSX_MAX_ID ] ;
2017-10-02 18:37:39 +02:00
struct st_lsm6dsx_reg decimator [ ST_LSM6DSX_MAX_ID ] ;
2017-10-02 18:37:40 +02:00
struct st_lsm6dsx_fifo_ops fifo_ops ;
2017-01-10 22:55:18 +01:00
} ;
enum st_lsm6dsx_sensor_id {
ST_LSM6DSX_ID_ACC ,
ST_LSM6DSX_ID_GYRO ,
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-03 19:27:39 +02:00
* @ name : Sensor name .
2017-01-10 22:55:18 +01: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 .
* @ delta_ts : Delta time between two consecutive interrupts .
* @ ts : Latest timestamp from the interrupt handler .
*/
struct st_lsm6dsx_sensor {
2017-04-03 19:27:39 +02:00
char name [ 32 ] ;
2017-01-10 22:55:18 +01:00
enum st_lsm6dsx_sensor_id id ;
struct st_lsm6dsx_hw * hw ;
u32 gain ;
u16 odr ;
u16 watermark ;
u8 sip ;
u8 decimator ;
s64 delta_ts ;
s64 ts ;
} ;
/**
* struct st_lsm6dsx_hw - ST IMU MEMS hw instance
* @ dev : Pointer to instance of struct device ( I2C or SPI ) .
2018-01-01 19:54:44 +01:00
* @ regmap : Register map of the device .
2017-01-10 22:55:18 +01:00
* @ irq : Device interrupt line ( I2C or SPI ) .
* @ fifo_lock : Mutex to prevent concurrent access to the hw FIFO .
2018-01-01 19:54:43 +01:00
* @ conf_lock : Mutex to prevent concurrent FIFO configuration update .
2017-01-10 22:55:18 +01:00
* @ fifo_mode : FIFO operating mode supported by the device .
* @ enable_mask : Enabled sensor bitmask .
* @ sip : Total number of samples ( acc / gyro ) in a given pattern .
2018-01-06 23:23:24 +01:00
* @ buff : Device read buffer .
2017-01-10 22:55:18 +01: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-01 19:54:44 +01:00
struct regmap * regmap ;
2017-01-10 22:55:18 +01:00
int irq ;
struct mutex fifo_lock ;
2018-01-01 19:54:43 +01:00
struct mutex conf_lock ;
2017-01-10 22:55:18 +01:00
enum st_lsm6dsx_fifo_mode fifo_mode ;
u8 enable_mask ;
u8 sip ;
2018-01-06 23:23:24 +01:00
u8 * buff ;
2017-01-10 22:55:18 +01:00
struct iio_dev * iio_devs [ ST_LSM6DSX_ID_MAX ] ;
const struct st_lsm6dsx_settings * settings ;
} ;
2017-04-27 22:31:56 +02:00
extern const struct dev_pm_ops st_lsm6dsx_pm_ops ;
2017-04-03 19:27:39 +02:00
int st_lsm6dsx_probe ( struct device * dev , int irq , int hw_id , const char * name ,
2018-01-01 19:54:44 +01:00
struct regmap * regmap ) ;
2017-01-10 22:55:18 +01:00
int st_lsm6dsx_sensor_enable ( struct st_lsm6dsx_sensor * sensor ) ;
int st_lsm6dsx_sensor_disable ( struct st_lsm6dsx_sensor * sensor ) ;
int st_lsm6dsx_fifo_setup ( struct st_lsm6dsx_hw * hw ) ;
int st_lsm6dsx_update_watermark ( struct st_lsm6dsx_sensor * sensor ,
u16 watermark ) ;
2017-04-27 22:31:55 +02: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 ) ;
2017-01-10 22:55:18 +01:00
# endif /* ST_LSM6DSX_H */