Commit cd83c5c1 authored by Lorenzo Bianconi's avatar Lorenzo Bianconi Committed by Jonathan Cameron

iio: imu: st_lsm6dsx: introduce st_lsm6dsx_device_set_enable routine

Introduce st_lsm6dsx_device_set_enable utility routine and remove
duplicated code used to enable/disable sensors
Signed-off-by: default avatarLorenzo Bianconi <lorenzo@kernel.org>
Link: https://lore.kernel.org/r/e3fbe5d4a3bed41130908669f745f78c8505cf47.1665399959.git.lorenzo@kernel.orgSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent c1404d1b
...@@ -509,6 +509,17 @@ st_lsm6dsx_get_mount_matrix(const struct iio_dev *iio_dev, ...@@ -509,6 +509,17 @@ st_lsm6dsx_get_mount_matrix(const struct iio_dev *iio_dev,
return &hw->orientation; return &hw->orientation;
} }
static inline int
st_lsm6dsx_device_set_enable(struct st_lsm6dsx_sensor *sensor, bool enable)
{
if (sensor->id == ST_LSM6DSX_ID_EXT0 ||
sensor->id == ST_LSM6DSX_ID_EXT1 ||
sensor->id == ST_LSM6DSX_ID_EXT2)
return st_lsm6dsx_shub_set_enable(sensor, enable);
return st_lsm6dsx_sensor_set_enable(sensor, enable);
}
static const static const
struct iio_chan_spec_ext_info __maybe_unused st_lsm6dsx_accel_ext_info[] = { struct iio_chan_spec_ext_info __maybe_unused st_lsm6dsx_accel_ext_info[] = {
IIO_MOUNT_MATRIX(IIO_SHARED_BY_ALL, st_lsm6dsx_get_mount_matrix), IIO_MOUNT_MATRIX(IIO_SHARED_BY_ALL, st_lsm6dsx_get_mount_matrix),
......
...@@ -673,17 +673,9 @@ int st_lsm6dsx_update_fifo(struct st_lsm6dsx_sensor *sensor, bool enable) ...@@ -673,17 +673,9 @@ int st_lsm6dsx_update_fifo(struct st_lsm6dsx_sensor *sensor, bool enable)
goto out; goto out;
} }
if (sensor->id == ST_LSM6DSX_ID_EXT0 || err = st_lsm6dsx_device_set_enable(sensor, enable);
sensor->id == ST_LSM6DSX_ID_EXT1 || if (err < 0)
sensor->id == ST_LSM6DSX_ID_EXT2) { goto out;
err = st_lsm6dsx_shub_set_enable(sensor, enable);
if (err < 0)
goto out;
} else {
err = st_lsm6dsx_sensor_set_enable(sensor, enable);
if (err < 0)
goto out;
}
err = st_lsm6dsx_set_fifo_odr(sensor, enable); err = st_lsm6dsx_set_fifo_odr(sensor, enable);
if (err < 0) if (err < 0)
......
...@@ -2317,12 +2317,7 @@ static int st_lsm6dsx_suspend(struct device *dev) ...@@ -2317,12 +2317,7 @@ static int st_lsm6dsx_suspend(struct device *dev)
continue; continue;
} }
if (sensor->id == ST_LSM6DSX_ID_EXT0 || err = st_lsm6dsx_device_set_enable(sensor, false);
sensor->id == ST_LSM6DSX_ID_EXT1 ||
sensor->id == ST_LSM6DSX_ID_EXT2)
err = st_lsm6dsx_shub_set_enable(sensor, false);
else
err = st_lsm6dsx_sensor_set_enable(sensor, false);
if (err < 0) if (err < 0)
return err; return err;
...@@ -2353,12 +2348,7 @@ static int st_lsm6dsx_resume(struct device *dev) ...@@ -2353,12 +2348,7 @@ static int st_lsm6dsx_resume(struct device *dev)
if (!(hw->suspend_mask & BIT(sensor->id))) if (!(hw->suspend_mask & BIT(sensor->id)))
continue; continue;
if (sensor->id == ST_LSM6DSX_ID_EXT0 || err = st_lsm6dsx_device_set_enable(sensor, true);
sensor->id == ST_LSM6DSX_ID_EXT1 ||
sensor->id == ST_LSM6DSX_ID_EXT2)
err = st_lsm6dsx_shub_set_enable(sensor, true);
else
err = st_lsm6dsx_sensor_set_enable(sensor, true);
if (err < 0) if (err < 0)
return err; return err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment