st_lsm6dsx: do not access active-low/open-drain if not supported
Subsystems (2)
Lorenzo Bianconi
maintainercover st_lsm6dsx: do not access active-low/open-drain if not supported
Move active low and open drain register definitions in hw_settings register map in order to avoid to access them if the sensor does not support them.
Group irq related definition in irq_config structure in st_lsm6dsx_settings.
@Jonathan: I post this series now since in this way Bobby can test it and maybe you want to apply it on top of togreg branch. If you prefer to add it on testing branch I can rebase it ontop of Sean's series.
Lorenzo Bianconi (3):
iio: imu: st_lsm6dsx: move irq related definitions in irq_config
iio: imu: st_lsm6dsx: do not access active-low/open-drain regs if not
supported
iio: imu: st_lsm6dsx: add sanity check for read_fifo pointer
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 17 +- .../iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 35 ++- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 243 ++++++++++++------ 3 files changed, 203 insertions(+), 92 deletions(-)
Signature · 1 line
2.21.0
Lorenzo Bianconi
maintainerPATCH 1/3 iio: imu: st_lsm6dsx: move irq related definitions in irq_config
Group irq related definition in irq_config structure in st_lsm6dsx_settings. This is a preliminary patch to check OpenDrain/Active low registers before accessing them
--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 15 +- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 195 ++++++++++++------- 2 files changed, 130 insertions(+), 80 deletions(-)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +7 -8
@@ -205,26 +205,21 @@ struct st_lsm6dsx_ext_dev_settings {/** * struct st_lsm6dsx_settings - ST IMU sensor settings * @wai: Sensor WhoAmI default value. -* @int1_addr: Control Register address for INT1 -* @int2_addr: Control Register address for INT2 * @reset_addr: register address for reset/reboot * @max_fifo_size: Sensor max fifo length in FIFO words. * @id: List of hw id/device name supported by the driver configuration. * @channels: IIO channels supported by the device. +* @irq_config: interrupts related registers. * @odr_table: Hw sensors odr table (Hz + val). * @fs_table: Hw sensors gain table (gain + val). * @decimator: List of decimator register info (addr + mask). * @batch: List of FIFO batching register info (addr + mask). -* @lir: Latched interrupt register info (addr + mask). -* @clear_on_read: Clear on read register info (addr + mask). * @fifo_ops: Sensor hw FIFO parameters. * @ts_settings: Hw timer related settings. * @shub_settings: i2c controller related settings. */ struct st_lsm6dsx_settings {u8 wai; -u8 int1_addr; -u8 int2_addr;u8 reset_addr;u16 max_fifo_size;struct {
@@ -235,12 +230,16 @@ struct st_lsm6dsx_settings {const struct iio_chan_spec *chan;int len; } channels[2 ]; +struct { +struct st_lsm6dsx_reg irq1; +struct st_lsm6dsx_reg irq2; +struct st_lsm6dsx_reg lir; +struct st_lsm6dsx_reg clear_on_read; + } irq_config;struct st_lsm6dsx_odr_table_entry odr_table[2 ];struct st_lsm6dsx_fs_table_entry fs_table[2 ];struct st_lsm6dsx_reg decimator[ST_LSM6DSX_MAX_ID ];struct st_lsm6dsx_reg batch[ST_LSM6DSX_MAX_ID ]; -struct st_lsm6dsx_reg lir; -struct st_lsm6dsx_reg clear_on_read;struct st_lsm6dsx_fifo_ops fifo_ops;struct st_lsm6dsx_hw_ts_settings ts_settings;struct st_lsm6dsx_shub_settings shub_settings;
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +123 -72
356 lines not on this page · raw message
Signature · 1 line
2.21.0
Re: [PATCH 1/3] iio: imu: st_lsm6dsx: move irq related definitions in irq_config
Quoted 6 lines · Lorenzo Bianconi
Group irq related definition in
irq_configstructure inst_lsm6dsx_settings. This is a preliminary patch to check OpenDrain/Active low registers before accessing themSigned-off-by Lorenzo Bianconi <[email protected]>---
Lorenzo Bianconi
maintainerPATCH 2/3 iio: imu: st_lsm6dsx: do not access active-low/open-drain regs if not supported
In reply to Lorenzo BianconiMove active low and open drain register definitions in hw_settings register map in order to avoid to access them if the sensor does not support them
--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 2 + .../iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 29 ++++++----- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 48 +++++++++++++++++++ 3 files changed, 67 insertions(+), 12 deletions(-)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +2 -0
@@ -235,6 +235,8 @@ struct st_lsm6dsx_settings {struct st_lsm6dsx_reg irq2;struct st_lsm6dsx_reg lir;struct st_lsm6dsx_reg clear_on_read; +struct st_lsm6dsx_reg hla; +struct st_lsm6dsx_reg od; } irq_config;struct st_lsm6dsx_odr_table_entry odr_table[2 ];struct st_lsm6dsx_fs_table_entry fs_table[2 ];
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c +17 -12
@@ -42,10 +42,6 @@#include "st_lsm6dsx.h" -#define ST_LSM6DSX_REG_HLACTIVE_ADDR 0x12 -#define ST_LSM6DSX_REG_HLACTIVE_MASK BIT(5) -#define ST_LSM6DSX_REG_PP_OD_ADDR 0x12 -#define ST_LSM6DSX_REG_PP_OD_MASK BIT(4)#define ST_LSM6DSX_REG_FIFO_MODE_ADDR 0x0a#define ST_LSM6DSX_FIFO_MODE_MASK GENMASK(2, 0)#define ST_LSM6DSX_FIFO_ODR_MASK GENMASK(6, 3)
@@ -704,6 +700,7 @@ int st_lsm6dsx_fifo_setup(struct st_lsm6dsx_hw *hw) {struct device_node *np = hw->dev->of_node;struct st_sensors_platform_data *pdata; +const struct st_lsm6dsx_reg *reg;struct iio_buffer *buffer;unsigned long irq_type;bool irq_active_low;
@@ -711,6 +708,7 @@ int st_lsm6dsx_fifo_setup(struct st_lsm6dsx_hw *hw) irq_type =irqd_get_trigger_type (irq_get_irq_data (hw->irq)); + reg = &hw->settings->irq_config.hla;switch (irq_type) {case IRQF_TRIGGER_HIGH :case IRQF_TRIGGER_RISING :
@@ -718,6 +716,10 @@ int st_lsm6dsx_fifo_setup(struct st_lsm6dsx_hw *hw)break ;case IRQF_TRIGGER_LOW :case IRQF_TRIGGER_FALLING : +if (!reg->addr) { +dev_info (hw->dev,"mode %lx unsupported\n" , irq_type); +return -EINVAL ; + } irq_active_low = true;break ;default :
@@ -725,20 +727,23 @@ int st_lsm6dsx_fifo_setup(struct st_lsm6dsx_hw *hw)return -EINVAL ; } - err =regmap_update_bits (hw->regmap,ST_LSM6DSX_REG_HLACTIVE_ADDR , -ST_LSM6DSX_REG_HLACTIVE_MASK , -FIELD_PREP (ST_LSM6DSX_REG_HLACTIVE_MASK , - irq_active_low)); + err =regmap_update_bits (hw->regmap, reg->addr, reg->mask, +ST_LSM6DSX_SHIFT_VAL (irq_active_low, + reg->mask));if (err <0 )return err; pdata = (struct st_sensors_platform_data *)hw->dev->platform_data;if ((np &&of_property_read_bool (np,"drive-open-drain" )) || (pdata && pdata->open_drain)) { - err =regmap_update_bits (hw->regmap,ST_LSM6DSX_REG_PP_OD_ADDR , -ST_LSM6DSX_REG_PP_OD_MASK , -FIELD_PREP (ST_LSM6DSX_REG_PP_OD_MASK , -1 )); + reg = &hw->settings->irq_config.od; +if (!reg->addr) { +dev_info (hw->dev,"open drain mode unsupported\n" ); +return -EINVAL ; + } + + err =regmap_update_bits (hw->regmap, reg->addr, reg->mask, +ST_LSM6DSX_SHIFT_VAL (1 , reg->mask));if (err <0 )return err;
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +48 -0
84 lines not on this page · raw message
Signature · 1 line
2.21.0
Re: [PATCH 2/3] iio: imu: st_lsm6dsx: do not access active-low/open-drain regs if not supported
Quoted 4 lines · Lorenzo Bianconi
Move active low and open drain register definitions in
hw_settingsregister map in order to avoid to access them if the sensor does not support them
Quoted 8 lines
Fixes 52f4b1f19679 ("iio: imu: st_lsm6dsx: add support for accel/gyro unit of lsm9ds1")Signed-off-by Lorenzo Bianconi <[email protected]>--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 2 + .../iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 29 ++++++----- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 48 +++++++++++++++++++ 3 files changed, 67 insertions(+), 12 deletions(-)
Re: [PATCH 2/3] iio: imu: st_lsm6dsx: do not access active-low/open-drain regs if not supported
Quoted 15 lines · Lorenzo Bianconi
Quoted 4 lines
Move active low and open drain register definitions in
hw_settingsregister map in order to avoid to access them if the sensor does not support themQuoted 8 lines
Fixes 52f4b1f19679 ("iio: imu: st_lsm6dsx: add support for accel/gyro unit of lsm9ds1")Signed-off-by Lorenzo Bianconi <[email protected]>--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 2 + .../iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 29 ++++++----- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 48 +++++++++++++++++++ 3 files changed, 67 insertions(+), 12 deletions(-)
Quoted 1 line
Tested-by Martin Kepplinger <[email protected]>
Hi Martin,
thx for testing the series. I will rework this patch in v2 since even LSM9DS1 supports Open Drain/Active Low.
Regards,
Lorenzo
Quoted 2 lines
Lorenzo Bianconi
maintainerPATCH 3/3 iio: imu: st_lsm6dsx: add sanity check for read_fifo pointer
In reply to Lorenzo BianconiCheck read_fifo pointer before using it since we can't assume it is always set adding new sensors
--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c +6 -0
@@ -588,6 +588,9 @@ int st_lsm6dsx_flush_fifo(struct st_lsm6dsx_hw *hw) {int err; +if (!hw->settings->fifo_ops.read_fifo) +return -ENOTSUPP ; +mutex_lock (&hw->fifo_lock); hw->settings->fifo_ops.read_fifo (hw);
@@ -662,6 +665,9 @@ static irqreturn_t st_lsm6dsx_handler_thread(int irq, void *private)struct st_lsm6dsx_hw *hw = private;int count; +if (!hw->settings->fifo_ops.read_fifo) +return IRQ_NONE ; +mutex_lock (&hw->fifo_lock); count = hw->settings->fifo_ops.read_fifo (hw);mutex_unlock (&hw->fifo_lock);
Signature · 1 line
2.21.0
Re: [PATCH 3/3] iio: imu: st_lsm6dsx: add sanity check for read_fifo pointer
Quoted 8 lines · Lorenzo Bianconi
Check
read_fifopointer before using it since we can't assume it is always set adding new sensorsSigned-off-by Lorenzo Bianconi <[email protected]>--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 6 ++++++ 1 file changed, 6 insertions(+)