summaryrefslogtreecommitdiff
path: root/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
diff options
context:
space:
mode:
authorLorenzo Bianconi <lorenzo.bianconi@redhat.com>2018-01-01 19:54:44 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-01-08 16:03:43 +0100
commit51a8b707627b437f17a153812f049daf3da6729d (patch)
tree937647f5a989dceb5e1493e656e8a2cf23928b16 /drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
parent335eaedce461c9092e133ce0c6247f5a0b0baf69 (diff)
downloadlwn-51a8b707627b437f17a153812f049daf3da6729d.tar.gz
lwn-51a8b707627b437f17a153812f049daf3da6729d.zip
iio: imu: st_lsm6dsx: add regmap API support
Introduce regmap API support to access to i2c/spi bus instead of using a custom support. Set max bulk read to (32 / SAMPLE_SIZE) * SAMPLE_SIZE since spi_write_then_read() used in regmap_spi indicates that is the max buffer length to use in order to avoid a kmalloc for each bus access. Remove lock mutex since concurrency is already managed by regmap API Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h')
-rw-r--r--drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h31
1 files changed, 6 insertions, 25 deletions
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
index cebc6bd31b79..ccbe44cef41a 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
@@ -29,21 +29,9 @@ enum st_lsm6dsx_hw_id {
#define ST_LSM6DSX_CHAN_SIZE 2
#define ST_LSM6DSX_SAMPLE_SIZE 6
-
-#if defined(CONFIG_SPI_MASTER)
-#define ST_LSM6DSX_RX_MAX_LENGTH 256
-#define ST_LSM6DSX_TX_MAX_LENGTH 8
-
-struct st_lsm6dsx_transfer_buffer {
- u8 rx_buf[ST_LSM6DSX_RX_MAX_LENGTH];
- u8 tx_buf[ST_LSM6DSX_TX_MAX_LENGTH] ____cacheline_aligned;
-};
-#endif /* CONFIG_SPI_MASTER */
-
-struct st_lsm6dsx_transfer_function {
- int (*read)(struct device *dev, u8 addr, int len, u8 *data);
- int (*write)(struct device *dev, u8 addr, int len, u8 *data);
-};
+#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))
struct st_lsm6dsx_reg {
u8 addr;
@@ -127,8 +115,8 @@ struct st_lsm6dsx_sensor {
/**
* struct st_lsm6dsx_hw - ST IMU MEMS hw instance
* @dev: Pointer to instance of struct device (I2C or SPI).
+ * @regmap: Register map of the device.
* @irq: Device interrupt line (I2C or SPI).
- * @lock: Mutex to protect read and write operations.
* @fifo_lock: Mutex to prevent concurrent access to the hw FIFO.
* @conf_lock: Mutex to prevent concurrent FIFO configuration update.
* @fifo_mode: FIFO operating mode supported by the device.
@@ -136,14 +124,12 @@ struct st_lsm6dsx_sensor {
* @sip: Total number of samples (acc/gyro) in a given pattern.
* @iio_devs: Pointers to acc/gyro iio_dev instances.
* @settings: Pointer to the specific sensor settings in use.
- * @tf: Transfer function structure used by I/O operations.
- * @tb: Transfer buffers used by SPI I/O operations.
*/
struct st_lsm6dsx_hw {
struct device *dev;
+ struct regmap *regmap;
int irq;
- struct mutex lock;
struct mutex fifo_lock;
struct mutex conf_lock;
@@ -154,17 +140,12 @@ struct st_lsm6dsx_hw {
struct iio_dev *iio_devs[ST_LSM6DSX_ID_MAX];
const struct st_lsm6dsx_settings *settings;
-
- const struct st_lsm6dsx_transfer_function *tf;
-#if defined(CONFIG_SPI_MASTER)
- struct st_lsm6dsx_transfer_buffer tb;
-#endif /* CONFIG_SPI_MASTER */
};
extern const struct dev_pm_ops st_lsm6dsx_pm_ops;
int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id, const char *name,
- const struct st_lsm6dsx_transfer_function *tf_ops);
+ struct regmap *regmap);
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);