mirror of
https://github.com/torvalds/linux.git
synced 2024-11-10 14:11:52 +00:00
iio: imu: adis16400: make use of the new lock helpers
Use the new auto cleanup based locks so error paths are simpler. While at it, removed 'ret' from adis16400_write_raw() by doing return adis_write_reg_16(); instead of ret = adis_write_reg_16(); return ret; Signed-off-by: Nuno Sa <nuno.sa@analog.com> Link: https://patch.msgid.link/20240618-dev-iio-adis-cleanup-v1-6-bd93ce7845c7@analog.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
parent
8d61d01cde
commit
9d9dae6ae8
@ -497,41 +497,38 @@ static int adis16400_write_raw(struct iio_dev *indio_dev,
|
|||||||
struct iio_chan_spec const *chan, int val, int val2, long info)
|
struct iio_chan_spec const *chan, int val, int val2, long info)
|
||||||
{
|
{
|
||||||
struct adis16400_state *st = iio_priv(indio_dev);
|
struct adis16400_state *st = iio_priv(indio_dev);
|
||||||
int ret, sps;
|
int sps;
|
||||||
|
|
||||||
switch (info) {
|
switch (info) {
|
||||||
case IIO_CHAN_INFO_CALIBBIAS:
|
case IIO_CHAN_INFO_CALIBBIAS:
|
||||||
ret = adis_write_reg_16(&st->adis,
|
return adis_write_reg_16(&st->adis,
|
||||||
adis16400_addresses[chan->scan_index], val);
|
adis16400_addresses[chan->scan_index],
|
||||||
return ret;
|
val);
|
||||||
case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
|
case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
|
||||||
/*
|
/*
|
||||||
* Need to cache values so we can update if the frequency
|
* Need to cache values so we can update if the frequency
|
||||||
* changes.
|
* changes.
|
||||||
*/
|
*/
|
||||||
adis_dev_lock(&st->adis);
|
adis_dev_auto_scoped_lock(&st->adis) {
|
||||||
st->filt_int = val;
|
st->filt_int = val;
|
||||||
/* Work out update to current value */
|
/* Work out update to current value */
|
||||||
sps = st->variant->get_freq(st);
|
sps = st->variant->get_freq(st);
|
||||||
if (sps < 0) {
|
if (sps < 0)
|
||||||
adis_dev_unlock(&st->adis);
|
return sps;
|
||||||
return sps;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = __adis16400_set_filter(indio_dev, sps,
|
return __adis16400_set_filter(indio_dev, sps,
|
||||||
val * 1000 + val2 / 1000);
|
val * 1000 + val2 / 1000);
|
||||||
adis_dev_unlock(&st->adis);
|
}
|
||||||
return ret;
|
unreachable();
|
||||||
case IIO_CHAN_INFO_SAMP_FREQ:
|
case IIO_CHAN_INFO_SAMP_FREQ:
|
||||||
sps = val * 1000 + val2 / 1000;
|
sps = val * 1000 + val2 / 1000;
|
||||||
|
|
||||||
if (sps <= 0)
|
if (sps <= 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
adis_dev_lock(&st->adis);
|
adis_dev_auto_scoped_lock(&st->adis)
|
||||||
ret = st->variant->set_freq(st, sps);
|
return st->variant->set_freq(st, sps);
|
||||||
adis_dev_unlock(&st->adis);
|
unreachable();
|
||||||
return ret;
|
|
||||||
default:
|
default:
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
@ -596,29 +593,30 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
|
|||||||
*val = st->variant->temp_offset;
|
*val = st->variant->temp_offset;
|
||||||
return IIO_VAL_INT;
|
return IIO_VAL_INT;
|
||||||
case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
|
case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
|
||||||
adis_dev_lock(&st->adis);
|
adis_dev_auto_scoped_lock(&st->adis) {
|
||||||
/* Need both the number of taps and the sampling frequency */
|
/*
|
||||||
ret = __adis_read_reg_16(&st->adis,
|
* Need both the number of taps and the sampling
|
||||||
ADIS16400_SENS_AVG,
|
* frequency
|
||||||
&val16);
|
*/
|
||||||
if (ret) {
|
ret = __adis_read_reg_16(&st->adis, ADIS16400_SENS_AVG,
|
||||||
adis_dev_unlock(&st->adis);
|
&val16);
|
||||||
return ret;
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
ret = st->variant->get_freq(st);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
ret = st->variant->get_freq(st);
|
|
||||||
adis_dev_unlock(&st->adis);
|
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
ret /= adis16400_3db_divisors[val16 & 0x07];
|
ret /= adis16400_3db_divisors[val16 & 0x07];
|
||||||
*val = ret / 1000;
|
*val = ret / 1000;
|
||||||
*val2 = (ret % 1000) * 1000;
|
*val2 = (ret % 1000) * 1000;
|
||||||
return IIO_VAL_INT_PLUS_MICRO;
|
return IIO_VAL_INT_PLUS_MICRO;
|
||||||
case IIO_CHAN_INFO_SAMP_FREQ:
|
case IIO_CHAN_INFO_SAMP_FREQ:
|
||||||
adis_dev_lock(&st->adis);
|
adis_dev_auto_scoped_lock(&st->adis) {
|
||||||
ret = st->variant->get_freq(st);
|
ret = st->variant->get_freq(st);
|
||||||
adis_dev_unlock(&st->adis);
|
if (ret)
|
||||||
if (ret)
|
return ret;
|
||||||
return ret;
|
}
|
||||||
*val = ret / 1000;
|
*val = ret / 1000;
|
||||||
*val2 = (ret % 1000) * 1000;
|
*val2 = (ret % 1000) * 1000;
|
||||||
return IIO_VAL_INT_PLUS_MICRO;
|
return IIO_VAL_INT_PLUS_MICRO;
|
||||||
|
Loading…
Reference in New Issue
Block a user