Do not report non enabled motion events. Wakeup will still be on all channels as it's not possible to do the filtering in hw. Signed-off-by: Sean Nyekjaer <sean@xxxxxxxxxx> --- Hope it's okay to do this as an RFC. To get the most obvious stuff reviewed before v9 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 1 + drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h index 938192212485..dd46209f94e8 100644 --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h @@ -362,6 +362,7 @@ struct st_lsm6dsx_hw { u8 event_threshold; bool enable_event; + u8 event_en_mask; struct st_lsm6dsx_reg irq_routing; u8 *buff; diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c index 7596a6ed7d97..2d66e3758921 100644 --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c @@ -1377,9 +1377,12 @@ static int st_lsm6dsx_write_event_config(struct iio_dev *iio_dev, if (type != IIO_EV_TYPE_THRESH) return -EINVAL; + if (hw->event_en_mask & BIT(chan->channel2)) + 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) @@ -1391,6 +1394,12 @@ static int st_lsm6dsx_write_event_config(struct iio_dev *iio_dev, hw->enable_event = state; +out: + if (state) + hw->event_en_mask |= BIT(chan->channel2); + else + hw->event_en_mask &= ~BIT(chan->channel2); + return 0; } @@ -1746,7 +1755,8 @@ 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) + if (data & hw->settings->event_settings.wakeup_src_z_mask && + hw->event_en_mask & BIT(IIO_MOD_Z)) iio_push_event(hw->iio_devs[ST_LSM6DSX_ID_ACC], IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, @@ -1755,7 +1765,8 @@ void st_lsm6dsx_report_motion_event(struct st_lsm6dsx_hw *hw, int data) IIO_EV_DIR_EITHER), timestamp); - if (data & hw->settings->event_settings.wakeup_src_y_mask) + if (data & hw->settings->event_settings.wakeup_src_y_mask && + hw->event_en_mask & BIT(IIO_MOD_Y)) iio_push_event(hw->iio_devs[ST_LSM6DSX_ID_ACC], IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, @@ -1764,7 +1775,8 @@ void st_lsm6dsx_report_motion_event(struct st_lsm6dsx_hw *hw, int data) IIO_EV_DIR_EITHER), timestamp); - if (data & hw->settings->event_settings.wakeup_src_x_mask) + if (data & hw->settings->event_settings.wakeup_src_x_mask && + hw->event_en_mask & BIT(IIO_MOD_X)) iio_push_event(hw->iio_devs[ST_LSM6DSX_ID_ACC], IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, -- 2.23.0