Commit bdb20bdb authored by Lars-Peter Clausen's avatar Lars-Peter Clausen Committed by Jonathan Cameron

staging:iio:adis16400: Fix and cleanup 3db filter setting

The 3db divisors table is partially wrong and incomplete. Also the code rounds
up to the next higher frequency if the requested frequency would matches one of
the available frequencies. These two issues are fixed by this patch. The patch
also changes the driver to round down the filter frequency if it is larger than
the largest supported frequency instead of rejecting it as an invalid value.
Signed-off-by: default avatarLars-Peter Clausen <lars@metafoo.de>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent 06220b89
...@@ -242,33 +242,32 @@ static ssize_t adis16400_read_frequency(struct device *dev, ...@@ -242,33 +242,32 @@ static ssize_t adis16400_read_frequency(struct device *dev,
static const unsigned adis16400_3db_divisors[] = { static const unsigned adis16400_3db_divisors[] = {
[0] = 2, /* Special case */ [0] = 2, /* Special case */
[1] = 5, [1] = 6,
[2] = 10, [2] = 12,
[3] = 50, [3] = 25,
[4] = 200, [4] = 50,
[5] = 100,
[6] = 200,
[7] = 200, /* Not a valid setting */
}; };
static int adis16400_set_filter(struct iio_dev *indio_dev, int sps, int val) static int adis16400_set_filter(struct iio_dev *indio_dev, int sps, int val)
{ {
int i, ret; int i, ret;
u16 val16; u16 val16;
for (i = ARRAY_SIZE(adis16400_3db_divisors) - 1; i >= 0; i--)
if (sps/adis16400_3db_divisors[i] > val) for (i = ARRAY_SIZE(adis16400_3db_divisors) - 1; i >= 1; i--) {
if (sps / adis16400_3db_divisors[i] >= val)
break; break;
if (i == -1) }
ret = -EINVAL;
else { ret = adis16400_spi_read_reg_16(indio_dev, ADIS16400_SENS_AVG,
ret = adis16400_spi_read_reg_16(indio_dev,
ADIS16400_SENS_AVG,
&val16); &val16);
if (ret < 0) if (ret < 0)
goto error_ret; return ret;
ret = adis16400_spi_write_reg_16(indio_dev, ret = adis16400_spi_write_reg_16(indio_dev, ADIS16400_SENS_AVG,
ADIS16400_SENS_AVG, (val16 & ~0x07) | i);
(val16 & ~0x03) | i);
}
error_ret:
return ret; return ret;
} }
...@@ -653,9 +652,9 @@ static int adis16400_read_raw(struct iio_dev *indio_dev, ...@@ -653,9 +652,9 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
mutex_unlock(&indio_dev->mlock); mutex_unlock(&indio_dev->mlock);
return ret; return ret;
} }
val16 = st->variant->get_freq(indio_dev); ret = st->variant->get_freq(indio_dev);
if (ret > 0) if (ret >= 0)
*val = ret/adis16400_3db_divisors[val16 & 0x03]; *val = ret / adis16400_3db_divisors[val16 & 0x07];
*val2 = 0; *val2 = 0;
mutex_unlock(&indio_dev->mlock); mutex_unlock(&indio_dev->mlock);
if (ret < 0) if (ret < 0)
......
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