This adds a wakeup_enabled hook in sysfs. If wakeup-source is enabled, wake on accelerometer event is default active. Signed-off-by: Sean Nyekjaer <sean@xxxxxxxxxx> --- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 31 ++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c index 092c4d02bd4e..2c8ad7d65d2f 100644 --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c @@ -630,15 +630,46 @@ static ssize_t st_lsm6dsx_sysfs_scale_avail(struct device *dev, return len; } +static ssize_t st_lsm6dsx_sysfs_get_wakeup_enabled(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct st_lsm6dsx_sensor *sensor = iio_priv(dev_get_drvdata(dev)); + struct st_lsm6dsx_hw *hw = sensor->hw; + + if (device_may_wakeup(hw->dev)) + return sprintf(buf, "%d\n", 1); + return sprintf(buf, "%d\n", 0); +} + +static ssize_t st_lsm6dsx_sysfs_set_wakeup_enabled(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct st_lsm6dsx_sensor *sensor = iio_priv(dev_get_drvdata(dev)); + struct st_lsm6dsx_hw *hw = sensor->hw; + + if (strncmp(buf, "1", 1) == 0) + device_set_wakeup_enable(hw->dev, true); + else + device_set_wakeup_enable(hw->dev, false); + + return len; +} + static IIO_DEV_ATTR_SAMP_FREQ_AVAIL(st_lsm6dsx_sysfs_sampling_frequency_avail); static IIO_DEVICE_ATTR(in_accel_scale_available, 0444, st_lsm6dsx_sysfs_scale_avail, NULL, 0); +static IIO_DEVICE_ATTR(wakeup_enabled, 0644, + st_lsm6dsx_sysfs_get_wakeup_enabled, + st_lsm6dsx_sysfs_set_wakeup_enabled, 0); static IIO_DEVICE_ATTR(in_anglvel_scale_available, 0444, st_lsm6dsx_sysfs_scale_avail, NULL, 0); static struct attribute *st_lsm6dsx_acc_attributes[] = { &iio_dev_attr_sampling_frequency_available.dev_attr.attr, &iio_dev_attr_in_accel_scale_available.dev_attr.attr, + &iio_dev_attr_wakeup_enabled.dev_attr.attr, NULL, }; -- 2.22.0