Skip to content

Commit

Permalink
staging: iio: ad7192: use iio_device_{claim|release}_direct_mode()
Browse files Browse the repository at this point in the history
Replace the code that guarantees the device stays in direct mode with
iio_device_{claim|release}_direct_mode() which does same.

Signed-off-by: Alison Schofield <[email protected]>
Signed-off-by: Jonathan Cameron <[email protected]>
  • Loading branch information
AlisonSchofield authored and jic23 committed Mar 12, 2016
1 parent 08a3380 commit 1c118b7
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions drivers/staging/iio/adc/ad7192.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,9 @@ static ssize_t ad7192_write_frequency(struct device *dev,
if (lval == 0)
return -EINVAL;

mutex_lock(&indio_dev->mlock);
if (iio_buffer_enabled(indio_dev)) {
mutex_unlock(&indio_dev->mlock);
return -EBUSY;
}
ret = iio_device_claim_direct_mode(indio_dev);
if (ret)
return ret;

div = st->mclk / (lval * st->f_order * 1024);
if (div < 1 || div > 1023) {
Expand All @@ -366,7 +364,7 @@ static ssize_t ad7192_write_frequency(struct device *dev,
ad_sd_write_reg(&st->sd, AD7192_REG_MODE, 3, st->mode);

out:
mutex_unlock(&indio_dev->mlock);
iio_device_release_direct_mode(indio_dev);

return ret ? ret : len;
}
Expand Down Expand Up @@ -434,11 +432,9 @@ static ssize_t ad7192_set(struct device *dev,
if (ret < 0)
return ret;

mutex_lock(&indio_dev->mlock);
if (iio_buffer_enabled(indio_dev)) {
mutex_unlock(&indio_dev->mlock);
return -EBUSY;
}
ret = iio_device_claim_direct_mode(indio_dev);
if (ret)
return ret;

switch ((u32)this_attr->address) {
case AD7192_REG_GPOCON:
Expand All @@ -461,7 +457,7 @@ static ssize_t ad7192_set(struct device *dev,
ret = -EINVAL;
}

mutex_unlock(&indio_dev->mlock);
iio_device_release_direct_mode(indio_dev);

return ret ? ret : len;
}
Expand Down Expand Up @@ -555,11 +551,9 @@ static int ad7192_write_raw(struct iio_dev *indio_dev,
int ret, i;
unsigned int tmp;

mutex_lock(&indio_dev->mlock);
if (iio_buffer_enabled(indio_dev)) {
mutex_unlock(&indio_dev->mlock);
return -EBUSY;
}
ret = iio_device_claim_direct_mode(indio_dev);
if (ret)
return ret;

switch (mask) {
case IIO_CHAN_INFO_SCALE:
Expand All @@ -582,7 +576,7 @@ static int ad7192_write_raw(struct iio_dev *indio_dev,
ret = -EINVAL;
}

mutex_unlock(&indio_dev->mlock);
iio_device_release_direct_mode(indio_dev);

return ret;
}
Expand Down

0 comments on commit 1c118b7

Please sign in to comment.