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

iio:adis16400: Increase samplerate precession

The devices supported by this drivers support sample rates with less than one
sample per second. To support this increase the samplerate precession to allow
setting (and reading) the samplerate with a milli-HZ precession.
Signed-off-by: default avatarLars-Peter Clausen <lars@metafoo.de>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent d6b09bd8
...@@ -53,16 +53,15 @@ static int adis16334_get_freq(struct adis16400_state *st) ...@@ -53,16 +53,15 @@ static int adis16334_get_freq(struct adis16400_state *st)
t >>= ADIS16334_RATE_DIV_SHIFT; t >>= ADIS16334_RATE_DIV_SHIFT;
return (8192 >> t) / 10; return 819200 >> t;
} }
static int adis16334_set_freq(struct adis16400_state *st, unsigned int freq) static int adis16334_set_freq(struct adis16400_state *st, unsigned int freq)
{ {
unsigned int t; unsigned int t;
freq *= 10; if (freq < 819200)
if (freq < 8192) t = ilog2(819200 / freq);
t = ilog2(8192 / freq);
else else
t = 0; t = 0;
...@@ -84,7 +83,7 @@ static int adis16400_get_freq(struct adis16400_state *st) ...@@ -84,7 +83,7 @@ static int adis16400_get_freq(struct adis16400_state *st)
if (ret < 0) if (ret < 0)
return ret; return ret;
sps = (t & ADIS16400_SMPL_PRD_TIME_BASE) ? 53 : 1638; sps = (t & ADIS16400_SMPL_PRD_TIME_BASE) ? 52851 : 1638404;
sps /= (t & ADIS16400_SMPL_PRD_DIV_MASK) + 1; sps /= (t & ADIS16400_SMPL_PRD_DIV_MASK) + 1;
return sps; return sps;
...@@ -94,7 +93,7 @@ static int adis16400_set_freq(struct adis16400_state *st, unsigned int freq) ...@@ -94,7 +93,7 @@ static int adis16400_set_freq(struct adis16400_state *st, unsigned int freq)
{ {
unsigned int t; unsigned int t;
t = 1638 / freq; t = 1638404 / freq;
if (t > 0) if (t > 0)
t--; t--;
t &= ADIS16400_SMPL_PRD_DIV_MASK; t &= ADIS16400_SMPL_PRD_DIV_MASK;
...@@ -119,7 +118,7 @@ static ssize_t adis16400_read_frequency(struct device *dev, ...@@ -119,7 +118,7 @@ static ssize_t adis16400_read_frequency(struct device *dev,
if (ret < 0) if (ret < 0)
return ret; return ret;
return sprintf(buf, "%d\n", ret); return sprintf(buf, "%d.%.3d\n", ret / 1000, ret % 1000);
} }
static const unsigned adis16400_3db_divisors[] = { static const unsigned adis16400_3db_divisors[] = {
...@@ -158,14 +157,16 @@ static ssize_t adis16400_write_frequency(struct device *dev, ...@@ -158,14 +157,16 @@ static ssize_t adis16400_write_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 adis16400_state *st = iio_priv(indio_dev); struct adis16400_state *st = iio_priv(indio_dev);
long val; int i, f, val;
int ret; int ret;
ret = kstrtol(buf, 10, &val); ret = iio_str_to_fixpoint(buf, 100, &i, &f);
if (ret) if (ret)
return ret; return ret;
if (val == 0) val = i * 1000 + f;
if (val <= 0)
return -EINVAL; return -EINVAL;
mutex_lock(&indio_dev->mlock); mutex_lock(&indio_dev->mlock);
...@@ -281,7 +282,8 @@ static int adis16400_write_raw(struct iio_dev *indio_dev, ...@@ -281,7 +282,8 @@ static int adis16400_write_raw(struct iio_dev *indio_dev,
return sps; return sps;
} }
ret = adis16400_set_filter(indio_dev, sps, val); ret = adis16400_set_filter(indio_dev, sps,
val * 1000 + val2 / 1000);
mutex_unlock(&indio_dev->mlock); mutex_unlock(&indio_dev->mlock);
return ret; return ret;
default: default:
...@@ -355,9 +357,11 @@ static int adis16400_read_raw(struct iio_dev *indio_dev, ...@@ -355,9 +357,11 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
return ret; return ret;
} }
ret = st->variant->get_freq(st); ret = st->variant->get_freq(st);
if (ret >= 0) if (ret >= 0) {
*val = ret / adis16400_3db_divisors[val16 & 0x07]; ret /= adis16400_3db_divisors[val16 & 0x07];
*val2 = 0; *val = ret / 1000;
*val2 = (ret % 1000) * 1000;
}
mutex_unlock(&indio_dev->mlock); mutex_unlock(&indio_dev->mlock);
if (ret < 0) if (ret < 0)
return ret; return ret;
......
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