iio: imu: st_lsm6dsx: move interrupt thread to core
Subsystems (2)
PATCH v6 1/6 iio: imu: st_lsm6dsx: move interrupt thread to core
This prepares the interrupt to be used for other stuff than fifo reading + event readings.
--- .../iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 78 +--------------- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 88 +++++++++++++++++++ 2 files changed, 89 insertions(+), 77 deletions(-)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c +1 -77
@@ -30,8 +30,6 @@* Denis Ciocca <[email protected]> */ #include <linux/module.h> -#include <linux/interrupt.h> -#include <linux/irq.h> #include <linux/iio/kfifo_buf.h> #include <linux/iio/iio.h> #include <linux/iio/buffer.h>
@@ -42,10 +40,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)
@@ -654,25 +648,6 @@ int st_lsm6dsx_update_fifo(struct st_lsm6dsx_sensor *sensor, bool enable)return err; } -static irqreturn_t st_lsm6dsx_handler_irq (int irq,void *private) -{ -struct st_lsm6dsx_hw *hw = private; - -return hw->sip >0 ?IRQ_WAKE_THREAD :IRQ_NONE ; -} - -static irqreturn_t st_lsm6dsx_handler_thread (int irq,void *private) -{ -struct st_lsm6dsx_hw *hw = private; -int count; - -mutex_lock (&hw->fifo_lock); - count = hw->settings->fifo_ops.read_fifo (hw); -mutex_unlock (&hw->fifo_lock); - -return count ?IRQ_HANDLED :IRQ_NONE ; -} -static int st_lsm6dsx_buffer_preenable (struct iio_dev *iio_dev) {struct st_lsm6dsx_sensor *sensor =iio_priv (iio_dev);
@@ -702,59 +677,8 @@ static const struct iio_buffer_setup_ops st_lsm6dsx_buffer_ops = {int st_lsm6dsx_fifo_setup (struct st_lsm6dsx_hw *hw) { -struct device_node *np = hw->dev->of_node; -struct st_sensors_platform_data *pdata;struct iio_buffer *buffer; -unsigned long irq_type; -bool irq_active_low; -int i, err; - - irq_type =irqd_get_trigger_type (irq_get_irq_data (hw->irq)); - -switch (irq_type) { -case IRQF_TRIGGER_HIGH : -case IRQF_TRIGGER_RISING : - irq_active_low = false; -break ; -case IRQF_TRIGGER_LOW : -case IRQF_TRIGGER_FALLING : - irq_active_low = true; -break ; -default : -dev_info (hw->dev,"mode %lx unsupported\n" , irq_type); -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)); -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 )); -if (err <0 ) -return err; - - irq_type |=IRQF_SHARED ; - } - - err =devm_request_threaded_irq (hw->dev, hw->irq, - st_lsm6dsx_handler_irq, - st_lsm6dsx_handler_thread, - irq_type |IRQF_ONESHOT , -"lsm6dsx" , hw); -if (err) { -dev_err (hw->dev,"failed to request trigger irq %d\n" , - hw->irq); -return err; - } +int i;for (i =0 ; i <ST_LSM6DSX_ID_MAX ; i++) {if (!hw->iio_devs[i])
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +88 -0
112 lines not on this page · raw message
Signature · 1 line
2.23.0
PATCH v6 2/6 iio: imu: st_lsm6dsx: add motion events
Add event channels that controls the creation of motion events. Tested on ISM330DLC
---
Changes since v4:
* Added check for event support
* Added registers for more devices that support this event
Changes since v5:
* Moved wakeup_src masks to PATCH 5/6
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 41 ++++ drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 194 ++++++++++++++++++- 2 files changed, 231 insertions(+), 4 deletions(-)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +41 -0
@@ -12,6 +12,7 @@#define ST_LSM6DSX_H #include <linux/device.h> +#include <linux/iio/iio.h> #define ST_LSM6DS3_DEV_NAME "lsm6ds3"#define ST_LSM6DS3H_DEV_NAME "lsm6ds3h"
@@ -54,6 +55,26 @@ enum st_lsm6dsx_hw_id { * ST_LSM6DSX_TAGGED_SAMPLE_SIZE)#define ST_LSM6DSX_SHIFT_VAL (val, mask) (((val) << __ffs(mask)) & (mask)) +#define ST_LSM6DSX_CHANNEL_ACC (chan_type, addr, mod, scan_idx) \ +{ \ + .type = chan_type, \ + .address = addr, \ + .modified = 1, \ + .channel2 = mod, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ + .info_mask_shared_by_type = 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, \ + }, \ + .event_spec = &st_lsm6dsx_event, \ + .num_event_specs = 1, \ +} +#define ST_LSM6DSX_CHANNEL (chan_type, addr, mod, scan_idx) \ { \ .type = chan_type, \
@@ -162,6 +183,11 @@ struct st_lsm6dsx_shub_settings {u8 batch_en; }; +struct st_lsm6dsx_event_settings { +struct st_lsm6dsx_reg enable_reg; +struct st_lsm6dsx_reg wakeup_reg; +}; +enum st_lsm6dsx_ext_sensor_id {ST_LSM6DSX_ID_MAGN , };
@@ -223,6 +249,9 @@ struct st_lsm6dsx_settings {u8 wai;u8 int1_addr;u8 int2_addr; +u8 int1_func_addr; +u8 int2_func_addr; +u8 int_func_mask;u8 reset_addr;u16 max_fifo_size;struct {
@@ -240,6 +269,7 @@ struct st_lsm6dsx_settings {struct st_lsm6dsx_fifo_ops fifo_ops;struct st_lsm6dsx_hw_ts_settings ts_settings;struct st_lsm6dsx_shub_settings shub_settings; +struct st_lsm6dsx_event_settings event_settings; };enum st_lsm6dsx_sensor_id {
@@ -320,6 +350,10 @@ struct st_lsm6dsx_hw {u8 ts_sip;u8 sip; +u8 event_threshold; +bool enable_event; +struct st_lsm6dsx_reg irq_routing; +u8 *buff;struct iio_dev *iio_devs[ST_LSM6DSX_ID_MAX ];
@@ -327,6 +361,13 @@ struct st_lsm6dsx_hw {const struct st_lsm6dsx_settings *settings; }; +static const struct iio_event_spec st_lsm6dsx_event = { + .type =IIO_EV_TYPE_THRESH , + .dir =IIO_EV_DIR_EITHER , + .mask_separate =BIT (IIO_EV_INFO_VALUE ) | +BIT (IIO_EV_INFO_ENABLE ) +}; +static const unsigned long st_lsm6dsx_available_scan_masks[] = {0x7 ,0x0 };extern const struct dev_pm_ops st_lsm6dsx_pm_ops;
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +190 -4
284 lines not on this page · raw message
Signature · 1 line
2.23.0
PATCH v6 3/6 iio: imu: st_lsm6dsx: add wakeup-source option
In reply to Sean NyekjaerThis add ways for the SoC to wake from accelerometer wake events.
In the suspend function we skip disabling the sensor if wakeup-source and events are activated.
---
Changes since v4:
* More devices supports wakeup
Changes since v5:
* None
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +14 -0
@@ -1802,6 +1802,9 @@ int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id,return err; } +if (dev->of_node &&of_property_read_bool (dev->of_node,"wakeup-source" )) +device_init_wakeup (dev, true); +return 0 ; }EXPORT_SYMBOL (st_lsm6dsx_probe);
@@ -1820,6 +1823,12 @@ static int __maybe_unused st_lsm6dsx_suspend(struct device *dev)if (!(hw->enable_mask &BIT (sensor->id)))continue ; +if (device_may_wakeup (dev) && i ==ST_LSM6DSX_ID_ACC ) { +/* Enable wake from IRQ */ +enable_irq_wake (hw->irq); +continue ; + } +if (sensor->id ==ST_LSM6DSX_ID_EXT0 || sensor->id ==ST_LSM6DSX_ID_EXT1 || sensor->id ==ST_LSM6DSX_ID_EXT2 )
@@ -1852,6 +1861,11 @@ static int __maybe_unused st_lsm6dsx_resume(struct device *dev)if (!(hw->suspend_mask &BIT (sensor->id)))continue ; +if (device_may_wakeup (dev) && i ==ST_LSM6DSX_ID_ACC ) { +disable_irq_wake (hw->irq); +continue ; + } +if (sensor->id ==ST_LSM6DSX_ID_EXT0 || sensor->id ==ST_LSM6DSX_ID_EXT1 || sensor->id ==ST_LSM6DSX_ID_EXT2 )
Signature · 1 line
2.23.0
PATCH v6 4/6 iio: imu: st_lsm6dsx: always enter interrupt thread
In reply to Sean NyekjaerThe interrupt source can come from multiple sources, fifo and wake interrupts.
Enter interrupt thread to check which interrupt that has fired.
--- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +1 -3
@@ -1661,9 +1661,7 @@ static struct iio_dev *st_lsm6dsx_alloc_iiodev(struct st_lsm6dsx_hw *hw,static irqreturn_t st_lsm6dsx_handler_irq (int irq,void *private) { -struct st_lsm6dsx_hw *hw = private; - -return hw->sip >0 ?IRQ_WAKE_THREAD :IRQ_NONE ; +return IRQ_WAKE_THREAD ; }static irqreturn_t st_lsm6dsx_handler_thread (int irq,void *private)
Signature · 1 line
2.23.0
PATCH v6 5/6 iio: imu: st_lsm6dsx: add motion report function and call from interrupt
In reply to Sean NyekjaerReport iio motion events to iio subsystem
---
Changes since v4:
* Updated bitmask as pr Jonathans comments
Changes since v5:
* None
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 5 ++ drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 70 ++++++++++++++++++++ 2 files changed, 75 insertions(+)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +5 -0
@@ -186,6 +186,11 @@ struct st_lsm6dsx_shub_settings {struct st_lsm6dsx_event_settings {struct st_lsm6dsx_reg enable_reg;struct st_lsm6dsx_reg wakeup_reg; +u8 wakeup_src_reg; +u8 wakeup_src_status_mask; +u8 wakeup_src_z_mask; +u8 wakeup_src_y_mask; +u8 wakeup_src_x_mask; };enum st_lsm6dsx_ext_sensor_id {
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +70 -0
118 lines not on this page · raw message
Signature · 1 line
2.23.0
Re: [PATCH v6 5/6] iio: imu: st_lsm6dsx: add motion report function and call from interrupt
Quoted 14 lines · Sean Nyekjaer
Report iio motion events to iio subsystem
Signed-off-by Sean Nyekjaer <[email protected]>---
Changes since v4:
* Updated bitmask as pr Jonathans commentsChanges since v5:
* Nonedrivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 5 ++ drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 70 ++++++++++++++++++++ 2 files changed, 75 insertions(+)
[...]
Quoted 23 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +22
-0+void st_lsm6dsx_report_motion_event (struct st_lsm6dsx_hw *hw,int data) +{ +s64 timestamp =iio_get_time_ns (hw->iio_devs[ST_LSM6DSX_ID_ACC ]); + +if (data & hw->settings->event_settings.wakeup_src_z_mask) +iio_push_event (hw->iio_devs[ST_LSM6DSX_ID_ACC ], +IIO_MOD_EVENT_CODE (IIO_ACCEL , +0 , +IIO_MOD_Z , +IIO_EV_TYPE_THRESH , +IIO_EV_DIR_EITHER ), + timestamp); + +if (data & hw->settings->event_settings.wakeup_src_x_mask) +iio_push_event (hw->iio_devs[ST_LSM6DSX_ID_ACC ], +IIO_MOD_EVENT_CODE (IIO_ACCEL , +0 , +IIO_MOD_Y , +IIO_EV_TYPE_THRESH , +IIO_EV_DIR_EITHER ), + timestamp); +
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c static struct iio_dev *st_lsm6dsx_alloc_iiodev(struct st_lsm6dsx_hw *hw, · line 1719
Quoted 10 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +10
-0+if (data & hw->settings->event_settings.wakeup_src_x_mask) +iio_push_event (hw->iio_devs[ST_LSM6DSX_ID_ACC ], +IIO_MOD_EVENT_CODE (IIO_ACCEL , +0 , +IIO_MOD_X , +IIO_EV_TYPE_THRESH , +IIO_EV_DIR_EITHER ), + timestamp); +} +
I was looking at this again, and if the user enables events for channel x, we continue to report events for y, z. Is it okay or is it better to filter them out?
/Sean
Jonathan Cameron
maintainerRe: [PATCH v6 5/6] iio: imu: st_lsm6dsx: add motion report function and call from interrupt
Quoted 45 lines · On Mon, 9 Sep 2019 13:51:13 +0200 Sean Nyekjaer <[email protected]> wrote:
Quoted 14 lines · Sean Nyekjaer
Report iio motion events to iio subsystem
Signed-off-by Sean Nyekjaer <[email protected]>---
Changes since v4:
* Updated bitmask as pr Jonathans commentsChanges since v5:
* Nonedrivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 5 ++ drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 70 ++++++++++++++++++++ 2 files changed, 75 insertions(+)[...]
Quoted 29 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +28
-0+void st_lsm6dsx_report_motion_event (struct st_lsm6dsx_hw *hw,int data) +{ +s64 timestamp =iio_get_time_ns (hw->iio_devs[ST_LSM6DSX_ID_ACC ]); + +if (data & hw->settings->event_settings.wakeup_src_z_mask) +iio_push_event (hw->iio_devs[ST_LSM6DSX_ID_ACC ], +IIO_MOD_EVENT_CODE (IIO_ACCEL , +0 , +IIO_MOD_Z , +IIO_EV_TYPE_THRESH , +IIO_EV_DIR_EITHER ), + timestamp); + +if (data & hw->settings->event_settings.wakeup_src_x_mask) +iio_push_event (hw->iio_devs[ST_LSM6DSX_ID_ACC ], +IIO_MOD_EVENT_CODE (IIO_ACCEL , +0 , +IIO_MOD_Y , +IIO_EV_TYPE_THRESH , +IIO_EV_DIR_EITHER ), + timestamp); + +if (data & hw->settings->event_settings.wakeup_src_x_mask) + iio_push_event(hw->iio_devs[ST_LSM6DSX_ID_ACC], + IIO_MOD_EVENT_CODE(IIO_ACCEL, + 0, + IIO_MOD_X, + IIO_EV_TYPE_THRESH,
Quoted 8 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c static struct iio_dev *st_lsm6dsx_alloc_iiodev(struct st_lsm6dsx_hw *hw, · line 1719
Quoted 4 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +4
-0+ IIO_EV_DIR_EITHER), + timestamp); +} +I was looking at this again, and if the user enables events for channel x, we continue to report events for y, z.
Is it okay or is it better to filter them out?
Better to filter them out. It'll be a bit of a surprise for userspace otherwise.
Thanks,
Jonathan
Quoted 2 lines
/Sean
Re: [PATCH v6 5/6] iio: imu: st_lsm6dsx: add motion report function and call from interrupt
Quoted 56 lines · Jonathan Cameron
Quoted 45 lines · On Mon, 9 Sep 2019 13:51:13 +0200 Sean Nyekjaer <[email protected]> wrote:
Quoted 14 lines · Sean Nyekjaer
Report iio motion events to iio subsystem
Signed-off-by Sean Nyekjaer <[email protected]>---
Changes since v4:
* Updated bitmask as pr Jonathans commentsChanges since v5:
* Nonedrivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 5 ++ drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 70 ++++++++++++++++++++ 2 files changed, 75 insertions(+)[...]
Quoted 29 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +28
-0+void st_lsm6dsx_report_motion_event (struct st_lsm6dsx_hw *hw,int data) +{ +s64 timestamp =iio_get_time_ns (hw->iio_devs[ST_LSM6DSX_ID_ACC ]); + +if (data & hw->settings->event_settings.wakeup_src_z_mask) +iio_push_event (hw->iio_devs[ST_LSM6DSX_ID_ACC ], +IIO_MOD_EVENT_CODE (IIO_ACCEL , +0 , +IIO_MOD_Z , +IIO_EV_TYPE_THRESH , +IIO_EV_DIR_EITHER ), + timestamp); + +if (data & hw->settings->event_settings.wakeup_src_x_mask) +iio_push_event (hw->iio_devs[ST_LSM6DSX_ID_ACC ], +IIO_MOD_EVENT_CODE (IIO_ACCEL , +0 , +IIO_MOD_Y , +IIO_EV_TYPE_THRESH , +IIO_EV_DIR_EITHER ), + timestamp); + +if (data & hw->settings->event_settings.wakeup_src_x_mask) + iio_push_event(hw->iio_devs[ST_LSM6DSX_ID_ACC], + IIO_MOD_EVENT_CODE(IIO_ACCEL, + 0, + IIO_MOD_X, + IIO_EV_TYPE_THRESH,Quoted 8 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c static struct iio_dev *st_lsm6dsx_alloc_iiodev(struct st_lsm6dsx_hw *hw, · line 1719
Quoted 4 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +4
-0+ IIO_EV_DIR_EITHER), + timestamp); +} +I was looking at this again, and if the user enables events for channel x, we continue to report events for y, z.
Is it okay or is it better to filter them out?
Quoted 7 lines
Better to filter them out. It'll be a bit of a surprise for userspace otherwise.
Thanks,
Jonathan
Okay, but keep in mind that we can't distinguish which channel we're waking up to. So even if some channel is disabled, we still wake up on it ...
/Sean
Jonathan Cameron
maintainerRe: [PATCH v6 5/6] iio: imu: st_lsm6dsx: add motion report function and call from interrupt
Quoted 60 lines · On Sun, 15 Sep 2019 14:24:57 +0200 Sean Nyekjaer <[email protected]> wrote:
Quoted 59 lines · Jonathan Cameron
Quoted 45 lines · On Mon, 9 Sep 2019 13:51:13 +0200 Sean Nyekjaer <[email protected]> wrote:
Quoted 14 lines · Sean Nyekjaer
Report iio motion events to iio subsystem
Signed-off-by Sean Nyekjaer <[email protected]>---
Changes since v4:
* Updated bitmask as pr Jonathans commentsChanges since v5:
* Nonedrivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 5 ++ drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 70 ++++++++++++++++++++ 2 files changed, 75 insertions(+)[...]
Quoted 29 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +28
-0+void st_lsm6dsx_report_motion_event (struct st_lsm6dsx_hw *hw,int data) +{ +s64 timestamp =iio_get_time_ns (hw->iio_devs[ST_LSM6DSX_ID_ACC ]); + +if (data & hw->settings->event_settings.wakeup_src_z_mask) +iio_push_event (hw->iio_devs[ST_LSM6DSX_ID_ACC ], +IIO_MOD_EVENT_CODE (IIO_ACCEL , +0 , +IIO_MOD_Z , +IIO_EV_TYPE_THRESH , +IIO_EV_DIR_EITHER ), + timestamp); + +if (data & hw->settings->event_settings.wakeup_src_x_mask) +iio_push_event (hw->iio_devs[ST_LSM6DSX_ID_ACC ], +IIO_MOD_EVENT_CODE (IIO_ACCEL , +0 , +IIO_MOD_Y , +IIO_EV_TYPE_THRESH , +IIO_EV_DIR_EITHER ), + timestamp); + +if (data & hw->settings->event_settings.wakeup_src_x_mask) + iio_push_event(hw->iio_devs[ST_LSM6DSX_ID_ACC], + IIO_MOD_EVENT_CODE(IIO_ACCEL, + 0, + IIO_MOD_X, + IIO_EV_TYPE_THRESH,Quoted 8 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c static struct iio_dev *st_lsm6dsx_alloc_iiodev(struct st_lsm6dsx_hw *hw, · line 1719
Quoted 4 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +4
-0+ IIO_EV_DIR_EITHER), + timestamp); +} +I was looking at this again, and if the user enables events for channel x, we continue to report events for y, z.
Is it okay or is it better to filter them out?Better to filter them out. It'll be a bit of a surprise for userspace otherwise.
Quoted 7 lines
Quoted 4 lines
Thanks,
Jonathan
Okay, but keep in mind that we can't distinguish which channel we're waking up to. So even if some channel is disabled, we still wake up on it ...
Hmm. Alternative is to not filter it, but make sure that the enable and disable interfaces treat all of them as one control. In theory I think the ABI would allow for events/in_accel_thresh_both_en in a similar fashion to the shared_by_type of the info elements for the channel, but given I'm not sure anything implements it, it's likely to be a hole in userspace code. We do have devices that do in_accel_thresh_both_en when the events are rising and falling separately but they two can't be enabled independently. This is kind of similar to that but on the channel rather than the direction.
Jonathan
Quoted 2 lines
/Sean
Lorenzo Bianconi
maintainerRe: [PATCH v6 5/6] iio: imu: st_lsm6dsx: add motion report function and call from interrupt
In reply to Sean NyekjaerQuoted 14 lines
Report iio motion events to iio subsystem
Signed-off-by Sean Nyekjaer <[email protected]>---
Changes since v4:
* Updated bitmask as pr Jonathans commentsChanges since v5:
* Nonedrivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 5 ++ drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 70 ++++++++++++++++++++ 2 files changed, 75 insertions(+)
[...]
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c static irqreturn_t st_lsm6dsx_handler_thread(int irq, void *private) · line 1731
Quoted 10 lines
static
irqreturn_tst_lsm6dsx_handler_irq(int irq, void *private){drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +3
-0return IRQ_WAKE_THREAD ;@@ -1668,6 +1726,18 @@ static irqreturn_t st_lsm6dsx_handler_thread(int irq, void *private) {struct st_lsm6dsx_hw *hw = private;int count; +int data, err; + +if (hw->enable_event) {
Maybe I understood the issue between the buffered reading and event generation. I guess it is a race here between when the device is generating the interrupt and when you set enable_event. I think there are two solutions:
1- trivial one: always read wakeup_src_reg
2- set hw->enable_event as first instruction in st_lsm6dsx_write_event_config() and roll back in case of error.
Could you please try that changes and double check if you are still able to trigger the issue?
Regards,
Lorenzo
Quoted 15 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +9
-0+ err =regmap_read (hw->regmap, + hw->settings->event_settings.wakeup_src_reg, + &data); +if (err <0 ) +return IRQ_NONE ; + +if (data & hw->settings->event_settings.wakeup_src_status_mask) +st_lsm6dsx_report_motion_event (hw, data); + }mutex_lock (&hw->fifo_lock); count = hw->settings->fifo_ops.read_fifo (hw);Signature · 1 line
2.23.0
Re: [PATCH v6 5/6] iio: imu: st_lsm6dsx: add motion report function and call from interrupt
Quoted 18 lines · Lorenzo Bianconi
Review static irqreturn_t st_lsm6dsx_handler_thread(int irq, void *private) · line 1731
Quoted 10 lines
static irqreturn_t st_lsm6dsx_handler_irq(int irq, void *private) { return IRQ_WAKE_THREAD;(quoted diff) +3
-0@@ -1668,6 +1726,18 @@ static irqreturn_t st_lsm6dsx_handler_thread(int irq, void *private) { struct st_lsm6dsx_hw *hw = private; int count; + int data, err; + + if (hw->enable_event) {Maybe I understood the issue between the buffered reading and event generation. I guess it is a race here between when the device is generating the interrupt and when you set
enable_event. I think there are two solutions:
1- trivial one: always readwakeup_src_reg
2- sethw->enable_eventas first instruction inst_lsm6dsx_write_event_config()and roll back in case of error.
Quoted 3 lines
Could you please try that changes and double check if you are still able to trigger the issue?
1. Without the last [PATCH v6 6/6] and this diff:
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +0 -1
@@ -1728,7 +1728,6 @@ static irqreturn_t st_lsm6dsx_handler_thread(int irq, void *private)int count;int data, err; -if (hw->enable_event) { err = regmap_read(hw->regmap,
hw->settings->event_settings.wakeup_src_reg,
&data);
@@ -1737,7 +1736,6 @@ static irqreturn_t st_lsm6dsx_handler_thread(int irq, void *private)
if (data &hw->settings->event_settings.wakeup_src_status_mask)
st_lsm6dsx_report_motion_event(hw, data);
- }
mutex_lock(&hw->fifo_lock);
count = hw->settings->fifo_ops.read_fifo(hw);$ cd /sys/bus/iio/devices/iio:device2 $ echo 1 > events/in_accel_x_thresh_either_en $ echo 1 > events/in_accel_x_thresh_either_value $ echo 1 > scan_elements/in_accel_x_en $ echo 1 > buffer/enable
FIFO interrupts ticking in... until I trigger the first event. :-(
The event is reported correctly. The interrupt pin is staying high.
The result is the same if I enable the FIFO first.
I don't think we have a race in the driver around this, to me it looks like something in the ism330 device should be cleared. Could the device go into sleep or power down mode?
2. Seems like an okay idea, do you want this in v7?
/Sean
Lorenzo Bianconi
maintainerRe: [PATCH v6 5/6] iio: imu: st_lsm6dsx: add motion report function and call from interrupt
Quoted 10 lines
Quoted 10 lines
Maybe I understood the issue between the buffered reading and event generation. I guess it is a race here between when the device is generating the interrupt and when you set
enable_event. I think there are two solutions:
1- trivial one: always readwakeup_src_reg
2- sethw->enable_eventas first instruction inst_lsm6dsx_write_event_config()and roll back in case of error.Could you please try that changes and double check if you are still able to trigger the issue?
[...]
Quoted 6 lines
$ cd /sys/bus/iio/devices/iio:device2 $ echo 1 > events/in_accel_x_thresh_either_en $ echo 1 > events/in_accel_x_thresh_either_value $ echo 1 > scan_elements/in_accel_x_en $ echo 1 > buffer/enable
Quoted 6 lines
FIFO interrupts ticking in... until I trigger the first event. :-( The event is reported correctly. The interrupt pin is staying high. The result is the same if I enable the FIFO first.
I don't think we have a race in the driver around this, to me it looks like something in the ism330 device should be cleared.
Could the device go into sleep or power down mode?
probably a silly question..are you tracing the interrupt line with an oscilloscope or a logical analyser? If you dump interrupt counters in /proc/interrupts will you see an interrupt storm for the selected irq pin?
Regards,
Lorenzo
Quoted 4 lines
2. Seems like an okay idea, do you want this in v7?
/Sean
Re: [PATCH v6 5/6] iio: imu: st_lsm6dsx: add motion report function and call from interrupt
Quoted 5 lines · Lorenzo Bianconi
probably a silly question..are you tracing the interrupt line with an oscilloscope or a logical analyser? If you dump interrupt counters in
/proc/interruptswill you see an interrupt storm for the selected irq pin?
Not a silly question ;-)
An Oscilloscope :-)
The interrupt counter is stopping.
If I switch to IRQ_TYPE_LEVEL_HIGH, (to test if additional readings of the event and FIFO registers would help. It results in interrupt storm and the line continues to stay high.
/Sean
Lorenzo Bianconi
maintainerRe: [PATCH v6 5/6] iio: imu: st_lsm6dsx: add motion report function and call from interrupt
Quoted 9 lines · Lorenzo Bianconi
Quoted 5 lines
probably a silly question..are you tracing the interrupt line with an oscilloscope or a logical analyser? If you dump interrupt counters in
/proc/interruptswill you see an interrupt storm for the selected irq pin?
Quoted 3 lines
Not a silly question ;-)
An Oscilloscope :-)
ack, thx
Could you please try to carry out the following test?
1- set the FIFO watermark to a high level (e.g. 128)
$echo 256 > /sys/bus/iio/devices/iio:device{x}/buffer/length $echo 128 > /sys/bus/iio/devices/iio:device{x}/buffer/watermark
2- set a low acc odr (e.g 13Hz)
$echo 13 > /sys/bus/iio/devices/iio:device{x}/sampling_frequency
3- start reading from the accel and generate a wake-upp event
Is still happen? Are you able to decode bus transaction? (register addresses, data read, ..)
Quoted 5 lines
The interrupt counter is stopping.
If I switch toIRQ_TYPE_LEVEL_HIGH, (to test if additional readings of the event and FIFO registers would help. It results in interrupt storm and the line continues to stay high.
@Denis, @Mario, @Armando: any thoughts about this?
Regards,
Lorenzo
Quoted 1 line
/Sean
Lorenzo Bianconi
maintainerRe: [PATCH v6 5/6] iio: imu: st_lsm6dsx: add motion report function and call from interrupt
Quoted 20 lines
Quoted 9 lines
Quoted 5 lines
probably a silly question..are you tracing the interrupt line with an oscilloscope or a logical analyser? If you dump interrupt counters in
/proc/interruptswill you see an interrupt storm for the selected irq pin?Not a silly question ;-)
An Oscilloscope :-)
ack, thx
Could you please try to carry out the following test?
1- set the FIFO watermark to a high level (e.g. 128)
$echo 256 > /sys/bus/iio/devices/iio:device{x}/buffer/length $echo 128 > /sys/bus/iio/devices/iio:device{x}/buffer/watermark
2- set a low acc odr (e.g 13Hz)
$echo 13 > /sys/bus/iio/devices/iio:device{x}/sampling_frequency
3- start reading from the accel and generate a wake-upp event
Quoted 8 lines
Is still happen? Are you able to decode bus transaction? (register addresses, data read, ..)
Quoted 5 lines
The interrupt counter is stopping.
If I switch toIRQ_TYPE_LEVEL_HIGH, (to test if additional readings of the event and FIFO registers would help. It results in interrupt storm and the line continues to stay high.
Could you please try to enable the LIR (Latched interrupt - BIT(0) in 0x58)? Please remember that on ISM330DLC the interrupt will be automatically cleared reading the wake up src register after a time slice equals to 1/ODR so the it will be set for longer time if you run the device at low ODR
Regards,
Lorenzo
Quoted 7 lines
@Denis, @Mario, @Armando: any thoughts about this?
Regards,
LorenzoQuoted 1 line
/Sean
Re: [PATCH v6 5/6] iio: imu: st_lsm6dsx: add motion report function and call from interrupt
Quoted 11 lines · Lorenzo Bianconi
Quoted 11 lines
Could you please try to carry out the following test?
1- set the FIFO watermark to a high level (e.g. 128)
$echo 256 > /sys/bus/iio/devices/iio:device{x}/buffer/length $echo 128 > /sys/bus/iio/devices/iio:device{x}/buffer/watermark
2- set a low acc odr (e.g 13Hz)
$echo 13 > /sys/bus/iio/devices/iio:device{x}/sampling_frequency
3- start reading from the accel and generate a wake-upp eventIs still happen? Are you able to decode bus transaction? (register addresses, data read, ..)
Do you still want this tested?
[...]
Quoted 4 lines
Could you please try to enable the LIR (Latched interrupt - BIT(0) in
0x58)? Please remember that on ISM330DLC the interrupt will be automatically cleared reading the wake up src register after a time slice equals to 1/ODR so the it will be set for longer time if you run the device at low ODR
"iio: imu: st_lsm6dsx: enable LIR for sensor events" "iio: imu: st_lsm6dsx: enable clear on read for latched interrupts" Does allow us to get events and buffered reads simultaneously.
I will drop PATCH 6/6.
/Sean
Lorenzo Bianconi
maintainerRe: [PATCH v6 5/6] iio: imu: st_lsm6dsx: add motion report function and call from interrupt
Quoted 10 lines · Sean Nyekjaer
Quoted 8 lines · Lorenzo Bianconi
Quoted 8 lines
Could you please try to carry out the following test?
1- set the FIFO watermark to a high level (e.g. 128)
$echo 256 > /sys/bus/iio/devices/iio:device{x}/buffer/length $echo 128 > /sys/bus/iio/devices/iio:device{x}/buffer/watermark
2- set a low acc odr (e.g 13Hz)
$echo 13 > /sys/bus/iio/devices/iio:device{x}/sampling_frequency
3- start reading from the accel and generate a wake-upp event
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
Is still happen? Are you able to decode bus transaction? (register addresses, data read, ..)
Do you still want this tested?
no, not necessary
Quoted 9 lines
[...]
Quoted 4 lines
Could you please try to enable the LIR (Latched interrupt - BIT(0) in
0x58)? Please remember that on ISM330DLC the interrupt will be automatically cleared reading the wake up src register after a time slice equals to 1/ODR so the it will be set for longer time if you run the device at low ODR
Quoted 4 lines
"iio: imu:
st_lsm6dsx: enable LIR for sensor events" "iio: imu:st_lsm6dsx: enable clear on read for latched interrupts" Does allow us to get events and buffered reads simultaneously.
cool :)
Regards,
Lorenzo
Quoted 3 lines
I will drop PATCH 6/6.
/Sean
PATCH v6 6/6 iio: imu: st_lsm6dsx: prohibit the use of events and buffered reads simultaneously
In reply to Sean NyekjaerWhen events and buffered reads is enabled simultaneously, and the first event accours the interrupt pin stays high.
This can be reverted when we find a solution to allow events and buffered reads simultaneously.
---
Changes since v4:
* Use fifo configuration mutex to prevent a race in hw->enable_event check.
Changes since v5:
* Updated do not return without unlocking mutexes
* Lock mutex before unlock
* Runtime tested ;-)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 5 +++++ drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 13 ++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c +5 -0
@@ -603,6 +603,11 @@ int st_lsm6dsx_update_fifo(struct st_lsm6dsx_sensor *sensor, bool enable)mutex_lock (&hw->conf_lock); +if (hw->enable_event) { + err = -EBUSY ; + goto out; + } +if (hw->fifo_mode !=ST_LSM6DSX_FIFO_BYPASS ) { err =st_lsm6dsx_flush_fifo (hw);if (err <0 )
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +10 -3
@@ -1340,8 +1340,12 @@ static int st_lsm6dsx_write_event_config(struct iio_dev *iio_dev,if (type !=IIO_EV_TYPE_THRESH )return -EINVAL ; -if (hw->fifo_mode !=ST_LSM6DSX_FIFO_BYPASS ) -return -EBUSY ; +mutex_lock (&hw->conf_lock); + +if (hw->fifo_mode !=ST_LSM6DSX_FIFO_BYPASS ) { + err = -EBUSY ; + goto out; + }/* do not enable events if they are already enabled */ if (state && hw->enable_event)
@@ -1357,7 +1361,10 @@ static int st_lsm6dsx_write_event_config(struct iio_dev *iio_dev, hw->enable_event = state; -return 0 ; +out: +mutex_unlock (&hw->conf_lock); + +return err; }int st_lsm6dsx_set_watermark (struct iio_dev *iio_dev,unsigned int val)
Signature · 1 line
2.23.0
Lorenzo Bianconi
maintainerRe: [PATCH v6 6/6] iio: imu: st_lsm6dsx: prohibit the use of events and buffered reads simultaneously
Quoted 16 lines
When events and buffered reads is enabled simultaneously, and the first event accours the interrupt pin stays high.
This can be reverted when we find a solution to allow events and buffered reads simultaneously.
Signed-off-by Sean Nyekjaer <[email protected]>---
Changes since v4:
* Use fifo configuration mutex to prevent a race inhw->enable_eventcheck.Changes since v5:
* Updated do not return without unlocking mutexes
* Lock mutex before unlock
* Runtime tested ;-)
[...]
Quoted 4 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +0
-0@@ -1340,8 +1340,12 @@ static int st_lsm6dsx_write_event_config(struct iio_dev *iio_dev,if (type !=IIO_EV_TYPE_THRESH )
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c static int st_lsm6dsx_write_event_config(struct iio_dev *iio_dev, · line 1348
Quoted 10 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +6
-2return -EINVAL ; -if (hw->fifo_mode !=ST_LSM6DSX_FIFO_BYPASS ) -return -EBUSY ; +mutex_lock (&hw->conf_lock); + +if (hw->fifo_mode !=ST_LSM6DSX_FIFO_BYPASS ) { + err = -EBUSY ; + goto out; + }
This patch is still broken!!! Returning in case of error you need to relase the lock.
Quoted 18 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +4
-1/* do not enable events if they are already enabled */ if (state && hw->enable_event)@@ -1357,7 +1361,10 @@ static int st_lsm6dsx_write_event_config(struct iio_dev *iio_dev, hw->enable_event = state; -return 0 ; +out: +mutex_unlock (&hw->conf_lock); + +return err; }int st_lsm6dsx_set_watermark (struct iio_dev *iio_dev,unsigned int val)Signature · 1 line
2.23.0
Re: [PATCH v6 6/6] iio: imu: st_lsm6dsx: prohibit the use of events and buffered reads simultaneously
Quoted 25 lines · Lorenzo Bianconi
Quoted 16 lines
When events and buffered reads is enabled simultaneously, and the first event accours the interrupt pin stays high.
This can be reverted when we find a solution to allow events and buffered reads simultaneously.
Signed-off-by Sean Nyekjaer <[email protected]>---
Changes since v4:
* Use fifo configuration mutex to prevent a race inhw->enable_eventcheck.Changes since v5:
* Updated do not return without unlocking mutexes
* Lock mutex before unlock
* Runtime tested ;-)[...]
Quoted 6 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +0
-0@@ -1340,8 +1340,12 @@ static int st_lsm6dsx_write_event_config(struct iio_dev *iio_dev,if (type !=IIO_EV_TYPE_THRESH )return -EINVAL ;
Quoted 12 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c static int st_lsm6dsx_write_event_config(struct iio_dev *iio_dev, · line 1348
Quoted 8 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +6
-2-if (hw->fifo_mode !=ST_LSM6DSX_FIFO_BYPASS ) -return -EBUSY ; +mutex_lock (&hw->conf_lock); + +if (hw->fifo_mode !=ST_LSM6DSX_FIFO_BYPASS ) { + err = -EBUSY ; + goto out; + }This patch is still broken!!! Returning in case of error you need to relase the lock.
Hmm,
please read below this:
- return 0;
+out:
+ mutex_unlock(&hw->conf_lock);
+
+ return err;
Quoted 18 lines
Quoted 18 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +4
-1/* do not enable events if they are already enabled */ if (state && hw->enable_event)@@ -1357,7 +1361,10 @@ static int st_lsm6dsx_write_event_config(struct iio_dev *iio_dev, hw->enable_event = state; -return 0 ; +out: +mutex_unlock (&hw->conf_lock); + +return err; }int st_lsm6dsx_set_watermark (struct iio_dev *iio_dev,unsigned int val)Signature · 1 line
2.23.0
Re: [PATCH v6 6/6] iio: imu: st_lsm6dsx: prohibit the use of events and buffered reads simultaneously
Quoted 50 lines · Sean Nyekjaer
Quoted 28 lines · Lorenzo Bianconi
Quoted 16 lines
When events and buffered reads is enabled simultaneously, and the first event accours the interrupt pin stays high.
This can be reverted when we find a solution to allow events and buffered reads simultaneously.
Signed-off-by Sean Nyekjaer <[email protected]>---
Changes since v4:
* Use fifo configuration mutex to prevent a race inhw->enable_eventcheck.Changes since v5:
* Updated do not return without unlocking mutexes
* Lock mutex before unlock
* Runtime tested ;-)[...]
Quoted 9 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +1
-2@@ -1340,8 +1340,12 @@ static int st_lsm6dsx_write_event_config(struct iio_dev *iio_dev, if (type != IIO_EV_TYPE_THRESH) return -EINVAL; - if (hw->fifo_mode != ST_LSM6DSX_FIFO_BYPASS) - return -EBUSY; + mutex_lock(&hw->conf_lock);Quoted 9 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c static int st_lsm6dsx_write_event_config(struct iio_dev *iio_dev, · line 1348
Quoted 5 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +5
-0+ + if (hw->fifo_mode != ST_LSM6DSX_FIFO_BYPASS) { + err = -EBUSY; + goto out; + }This patch is still broken!!! Returning in case of error you need to relase the lock.
Hmm,
please read below this:
- return 0;
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +4
-0+out: + mutex_unlock(&hw->conf_lock); + + return err;
Quoted 1 line
Quoted 1 line
I see what you mean...
I will update this function with:
goto's :-)
/Sean
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +4
-1/* do not enable events if they are already enabled */ if (state && hw->enable_event)@@ -1357,7 +1361,10 @@ static int st_lsm6dsx_write_event_config(struct iio_dev *iio_dev, hw->enable_event = state; - return 0; +out: + mutex_unlock(&hw->conf_lock); + + return err; } int st_lsm6dsx_set_watermark(struct iio_dev *iio_dev, unsigned int val)Signature · 1 line
2.23.0
PATCH 6/6 iio: imu: st_lsm6dsx: prohibit the use of events and buffered reads simultaneously
In reply to Sean NyekjaerWhen events and buffered reads is enabled simultaneously, and the first event accours the interrupt pin stays high.
This can be reverted when we find a solution to allow events and buffered reads simultaneously.
---
Changes since v4:
* Use fifo configuration mutex to prevent a race in hw->enable_event check.
Changes since v5:
* Updated do not return without unlocking mutexes
* Lock mutex before unlock
* Runtime tested
* Make sure we unlock the mutex in case of failure
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 5 +++++ drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 18 ++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c +5 -0
@@ -603,6 +603,11 @@ int st_lsm6dsx_update_fifo(struct st_lsm6dsx_sensor *sensor, bool enable)mutex_lock (&hw->conf_lock); +if (hw->enable_event) { + err = -EBUSY ; + goto out; + } +if (hw->fifo_mode !=ST_LSM6DSX_FIFO_BYPASS ) { err =st_lsm6dsx_flush_fifo (hw);if (err <0 )
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +14 -4
@@ -1340,21 +1340,31 @@ static int st_lsm6dsx_write_event_config(struct iio_dev *iio_dev,if (type !=IIO_EV_TYPE_THRESH )return -EINVAL ; +mutex_lock (&hw->conf_lock); + +if (hw->fifo_mode !=ST_LSM6DSX_FIFO_BYPASS ) { + err = -EBUSY ; + goto out; + } +/* do not enable events if they are already enabled */ if (state && hw->enable_event) -return 0 ; + goto out; err =st_lsm6dsx_event_setup (hw, state);if (err <0 ) -return err; + goto out; err =st_lsm6dsx_sensor_set_enable (sensor, state);if (err <0 ) -return err; + goto out; hw->enable_event = state; -return 0 ; +out: +mutex_unlock (&hw->conf_lock); + +return err; }int st_lsm6dsx_set_watermark (struct iio_dev *iio_dev,unsigned int val)
Signature · 1 line
2.23.0