Commit 0aee99a1 authored by Alexandru Ardelean's avatar Alexandru Ardelean Committed by Jonathan Cameron

iio: gyro: adis16136: rework locks using ADIS library's state lock

This replaces indio_dev's mlock with the state lock/mutex from the ADIS
library.

The __adis16136_get_freq() function has been prefixed to mark it as
unlocked. The adis16136_{set,get}_filter() functions now hold the state
lock for all the ops that they do.
Signed-off-by: default avatarAlexandru Ardelean <alexandru.ardelean@analog.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent ce476cd1
...@@ -185,12 +185,12 @@ static int adis16136_set_freq(struct adis16136 *adis16136, unsigned int freq) ...@@ -185,12 +185,12 @@ static int adis16136_set_freq(struct adis16136 *adis16136, unsigned int freq)
return adis_write_reg_16(&adis16136->adis, ADIS16136_REG_SMPL_PRD, t); return adis_write_reg_16(&adis16136->adis, ADIS16136_REG_SMPL_PRD, t);
} }
static int adis16136_get_freq(struct adis16136 *adis16136, unsigned int *freq) static int __adis16136_get_freq(struct adis16136 *adis16136, unsigned int *freq)
{ {
uint16_t t; uint16_t t;
int ret; int ret;
ret = adis_read_reg_16(&adis16136->adis, ADIS16136_REG_SMPL_PRD, &t); ret = __adis_read_reg_16(&adis16136->adis, ADIS16136_REG_SMPL_PRD, &t);
if (ret) if (ret)
return ret; return ret;
...@@ -224,10 +224,13 @@ static ssize_t adis16136_read_frequency(struct device *dev, ...@@ -224,10 +224,13 @@ static ssize_t adis16136_read_frequency(struct device *dev,
{ {
struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct iio_dev *indio_dev = dev_to_iio_dev(dev);
struct adis16136 *adis16136 = iio_priv(indio_dev); struct adis16136 *adis16136 = iio_priv(indio_dev);
struct mutex *slock = &adis16136->adis.state_lock;
unsigned int freq; unsigned int freq;
int ret; int ret;
ret = adis16136_get_freq(adis16136, &freq); mutex_lock(slock);
ret = __adis16136_get_freq(adis16136, &freq);
mutex_unlock(slock);
if (ret) if (ret)
return ret; return ret;
...@@ -252,42 +255,50 @@ static const unsigned adis16136_3db_divisors[] = { ...@@ -252,42 +255,50 @@ static const unsigned adis16136_3db_divisors[] = {
static int adis16136_set_filter(struct iio_dev *indio_dev, int val) static int adis16136_set_filter(struct iio_dev *indio_dev, int val)
{ {
struct adis16136 *adis16136 = iio_priv(indio_dev); struct adis16136 *adis16136 = iio_priv(indio_dev);
struct mutex *slock = &adis16136->adis.state_lock;
unsigned int freq; unsigned int freq;
int i, ret; int i, ret;
ret = adis16136_get_freq(adis16136, &freq); mutex_lock(slock);
ret = __adis16136_get_freq(adis16136, &freq);
if (ret) if (ret)
return ret; goto out_unlock;
for (i = ARRAY_SIZE(adis16136_3db_divisors) - 1; i >= 1; i--) { for (i = ARRAY_SIZE(adis16136_3db_divisors) - 1; i >= 1; i--) {
if (freq / adis16136_3db_divisors[i] >= val) if (freq / adis16136_3db_divisors[i] >= val)
break; break;
} }
return adis_write_reg_16(&adis16136->adis, ADIS16136_REG_AVG_CNT, i); ret = __adis_write_reg_16(&adis16136->adis, ADIS16136_REG_AVG_CNT, i);
out_unlock:
mutex_unlock(slock);
return ret;
} }
static int adis16136_get_filter(struct iio_dev *indio_dev, int *val) static int adis16136_get_filter(struct iio_dev *indio_dev, int *val)
{ {
struct adis16136 *adis16136 = iio_priv(indio_dev); struct adis16136 *adis16136 = iio_priv(indio_dev);
struct mutex *slock = &adis16136->adis.state_lock;
unsigned int freq; unsigned int freq;
uint16_t val16; uint16_t val16;
int ret; int ret;
mutex_lock(&indio_dev->mlock); mutex_lock(slock);
ret = adis_read_reg_16(&adis16136->adis, ADIS16136_REG_AVG_CNT, &val16); ret = __adis_read_reg_16(&adis16136->adis, ADIS16136_REG_AVG_CNT,
&val16);
if (ret) if (ret)
goto err_unlock; goto err_unlock;
ret = adis16136_get_freq(adis16136, &freq); ret = __adis16136_get_freq(adis16136, &freq);
if (ret) if (ret)
goto err_unlock; goto err_unlock;
*val = freq / adis16136_3db_divisors[val16 & 0x07]; *val = freq / adis16136_3db_divisors[val16 & 0x07];
err_unlock: err_unlock:
mutex_unlock(&indio_dev->mlock); mutex_unlock(slock);
return ret ? ret : IIO_VAL_INT; return ret ? ret : IIO_VAL_INT;
} }
......
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