Commit 2da03b43 authored by Miquel Raynal's avatar Miquel Raynal Committed by Jonathan Cameron

iio: st_sensors: Use iio_device_claim/release_direct_mode() when relevant

The st_sensors_core driver hardcodes the content of the
iio_device_claim_direct_mode() and iio_device_release_direct_mode()
helpers. Let's get rid of this handcrafted implementation and use the
proper core helpers instead. Additionally, this lowers the tab level
(which is always good) and prevents the use of the ->currentmode
variable which is not supposed to be used like this anyway.

Cc: Denis Ciocca <denis.ciocca@st.com>
Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/r/20220207143840.707510-9-miquel.raynal@bootlin.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 12345968
......@@ -555,32 +555,28 @@ int st_sensors_read_info_raw(struct iio_dev *indio_dev,
int err;
struct st_sensor_data *sdata = iio_priv(indio_dev);
mutex_lock(&indio_dev->mlock);
if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) {
err = -EBUSY;
err = iio_device_claim_direct_mode(indio_dev);
if (err)
return err;
mutex_lock(&sdata->odr_lock);
err = st_sensors_set_enable(indio_dev, true);
if (err < 0)
goto out;
} else {
mutex_lock(&sdata->odr_lock);
err = st_sensors_set_enable(indio_dev, true);
if (err < 0) {
mutex_unlock(&sdata->odr_lock);
goto out;
}
msleep((sdata->sensor_settings->bootime * 1000) / sdata->odr);
err = st_sensors_read_axis_data(indio_dev, ch, val);
if (err < 0) {
mutex_unlock(&sdata->odr_lock);
goto out;
}
msleep((sdata->sensor_settings->bootime * 1000) / sdata->odr);
err = st_sensors_read_axis_data(indio_dev, ch, val);
if (err < 0)
goto out;
*val = *val >> ch->scan_type.shift;
*val = *val >> ch->scan_type.shift;
err = st_sensors_set_enable(indio_dev, false);
err = st_sensors_set_enable(indio_dev, false);
mutex_unlock(&sdata->odr_lock);
}
out:
mutex_unlock(&indio_dev->mlock);
mutex_unlock(&sdata->odr_lock);
iio_device_release_direct_mode(indio_dev);
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