]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: imu: st_lsm6dsx: rework code to check for enabled events
authorFrancesco Lavra <flavra@baylibre.com>
Mon, 1 Dec 2025 10:00:13 +0000 (11:00 +0100)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sun, 21 Dec 2025 11:10:26 +0000 (11:10 +0000)
The enable_event field in struct st_lsm6dsx_hw does not lend itself well to
handling multiple event sources, so it will have to be modified to add
support for more event sources. As a preparatory step, remove references to
this field from code that does not deal with event management; rework the
st_lsm6dsx_check_events() function so that it returns whether any events
are currently enabled on a given sensor.

Signed-off-by: Francesco Lavra <flavra@baylibre.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c

index 39ae79991b914cc6a02dfda69f47a15b5fca8ff2..ba2df45b77bb923bdd04e7160c0afc2066c93809 100644 (file)
@@ -1753,11 +1753,11 @@ __st_lsm6dsx_sensor_set_enable(struct st_lsm6dsx_sensor *sensor,
 }
 
 static int
-st_lsm6dsx_check_events(struct st_lsm6dsx_sensor *sensor, bool enable)
+st_lsm6dsx_check_events(struct st_lsm6dsx_sensor *sensor)
 {
        struct st_lsm6dsx_hw *hw = sensor->hw;
 
-       if (sensor->id == ST_LSM6DSX_ID_GYRO || enable)
+       if (sensor->id != ST_LSM6DSX_ID_ACC)
                return 0;
 
        return hw->enable_event;
@@ -1766,7 +1766,7 @@ st_lsm6dsx_check_events(struct st_lsm6dsx_sensor *sensor, bool enable)
 int st_lsm6dsx_sensor_set_enable(struct st_lsm6dsx_sensor *sensor,
                                 bool enable)
 {
-       if (st_lsm6dsx_check_events(sensor, enable))
+       if (st_lsm6dsx_check_events(sensor))
                return 0;
 
        return __st_lsm6dsx_sensor_set_enable(sensor, enable);
@@ -1794,11 +1794,9 @@ static int st_lsm6dsx_read_oneshot(struct st_lsm6dsx_sensor *sensor,
        if (err < 0)
                return err;
 
-       if (!hw->enable_event) {
-               err = st_lsm6dsx_sensor_set_enable(sensor, false);
-               if (err < 0)
-                       return err;
-       }
+       err = st_lsm6dsx_sensor_set_enable(sensor, false);
+       if (err < 0)
+               return err;
 
        *val = (s16)le16_to_cpu(data);
 
@@ -2752,7 +2750,7 @@ static int st_lsm6dsx_suspend(struct device *dev)
                        continue;
 
                if (device_may_wakeup(dev) &&
-                   sensor->id == ST_LSM6DSX_ID_ACC && hw->enable_event) {
+                   st_lsm6dsx_check_events(sensor)) {
                        /* Enable wake from IRQ */
                        enable_irq_wake(hw->irq);
                        continue;
@@ -2783,7 +2781,7 @@ static int st_lsm6dsx_resume(struct device *dev)
 
                sensor = iio_priv(hw->iio_devs[i]);
                if (device_may_wakeup(dev) &&
-                   sensor->id == ST_LSM6DSX_ID_ACC && hw->enable_event)
+                   st_lsm6dsx_check_events(sensor))
                        disable_irq_wake(hw->irq);
 
                if (!(hw->suspend_mask & BIT(sensor->id)))