Commit b24150e31ab27ffcd2aa9b33dca42c2070526054
Committed by
Jonathan Cameron
1 parent
d6b09bd85d
Exists in
master
and in
20 other branches
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: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Showing 1 changed file with 18 additions and 14 deletions Side-by-side Diff
drivers/iio/imu/adis16400_core.c
... | ... | @@ -53,16 +53,15 @@ |
53 | 53 | |
54 | 54 | t >>= ADIS16334_RATE_DIV_SHIFT; |
55 | 55 | |
56 | - return (8192 >> t) / 10; | |
56 | + return 819200 >> t; | |
57 | 57 | } |
58 | 58 | |
59 | 59 | static int adis16334_set_freq(struct adis16400_state *st, unsigned int freq) |
60 | 60 | { |
61 | 61 | unsigned int t; |
62 | 62 | |
63 | - freq *= 10; | |
64 | - if (freq < 8192) | |
65 | - t = ilog2(8192 / freq); | |
63 | + if (freq < 819200) | |
64 | + t = ilog2(819200 / freq); | |
66 | 65 | else |
67 | 66 | t = 0; |
68 | 67 | |
... | ... | @@ -84,7 +83,7 @@ |
84 | 83 | if (ret < 0) |
85 | 84 | return ret; |
86 | 85 | |
87 | - sps = (t & ADIS16400_SMPL_PRD_TIME_BASE) ? 53 : 1638; | |
86 | + sps = (t & ADIS16400_SMPL_PRD_TIME_BASE) ? 52851 : 1638404; | |
88 | 87 | sps /= (t & ADIS16400_SMPL_PRD_DIV_MASK) + 1; |
89 | 88 | |
90 | 89 | return sps; |
... | ... | @@ -94,7 +93,7 @@ |
94 | 93 | { |
95 | 94 | unsigned int t; |
96 | 95 | |
97 | - t = 1638 / freq; | |
96 | + t = 1638404 / freq; | |
98 | 97 | if (t > 0) |
99 | 98 | t--; |
100 | 99 | t &= ADIS16400_SMPL_PRD_DIV_MASK; |
... | ... | @@ -119,7 +118,7 @@ |
119 | 118 | if (ret < 0) |
120 | 119 | return ret; |
121 | 120 | |
122 | - return sprintf(buf, "%d\n", ret); | |
121 | + return sprintf(buf, "%d.%.3d\n", ret / 1000, ret % 1000); | |
123 | 122 | } |
124 | 123 | |
125 | 124 | static const unsigned adis16400_3db_divisors[] = { |
126 | 125 | |
127 | 126 | |
... | ... | @@ -158,14 +157,16 @@ |
158 | 157 | { |
159 | 158 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); |
160 | 159 | struct adis16400_state *st = iio_priv(indio_dev); |
161 | - long val; | |
160 | + int i, f, val; | |
162 | 161 | int ret; |
163 | 162 | |
164 | - ret = kstrtol(buf, 10, &val); | |
163 | + ret = iio_str_to_fixpoint(buf, 100, &i, &f); | |
165 | 164 | if (ret) |
166 | 165 | return ret; |
167 | 166 | |
168 | - if (val == 0) | |
167 | + val = i * 1000 + f; | |
168 | + | |
169 | + if (val <= 0) | |
169 | 170 | return -EINVAL; |
170 | 171 | |
171 | 172 | mutex_lock(&indio_dev->mlock); |
... | ... | @@ -281,7 +282,8 @@ |
281 | 282 | return sps; |
282 | 283 | } |
283 | 284 | |
284 | - ret = adis16400_set_filter(indio_dev, sps, val); | |
285 | + ret = adis16400_set_filter(indio_dev, sps, | |
286 | + val * 1000 + val2 / 1000); | |
285 | 287 | mutex_unlock(&indio_dev->mlock); |
286 | 288 | return ret; |
287 | 289 | default: |
... | ... | @@ -355,9 +357,11 @@ |
355 | 357 | return ret; |
356 | 358 | } |
357 | 359 | ret = st->variant->get_freq(st); |
358 | - if (ret >= 0) | |
359 | - *val = ret / adis16400_3db_divisors[val16 & 0x07]; | |
360 | - *val2 = 0; | |
360 | + if (ret >= 0) { | |
361 | + ret /= adis16400_3db_divisors[val16 & 0x07]; | |
362 | + *val = ret / 1000; | |
363 | + *val2 = (ret % 1000) * 1000; | |
364 | + } | |
361 | 365 | mutex_unlock(&indio_dev->mlock); |
362 | 366 | if (ret < 0) |
363 | 367 | return ret; |