diff options
author | Lars-Peter Clausen <lars@metafoo.de> | 2013-09-28 05:31:00 -0400 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2013-10-01 11:19:10 -0400 |
commit | ae76751f67110f497848afd71d06a0b6bb4a7c89 (patch) | |
tree | ab3a7fb974ab00125f2db151bf7c64d60626f971 | |
parent | ecc7e948bca09b97b6b1d0f4b4516bee34e8ce6b (diff) |
iio:ad5755: Report scale as fractional value
Move the complexity of calculating the fixed point scale to the core.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
-rw-r--r-- | drivers/iio/dac/ad5755.c | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/drivers/iio/dac/ad5755.c b/drivers/iio/dac/ad5755.c index f305a0c83418..bd31dbc340c1 100644 --- a/drivers/iio/dac/ad5755.c +++ b/drivers/iio/dac/ad5755.c | |||
@@ -253,15 +253,6 @@ static inline int ad5755_get_offset(struct ad5755_state *st, | |||
253 | return (min * (1 << chan->scan_type.realbits)) / (max - min); | 253 | return (min * (1 << chan->scan_type.realbits)) / (max - min); |
254 | } | 254 | } |
255 | 255 | ||
256 | static inline int ad5755_get_scale(struct ad5755_state *st, | ||
257 | struct iio_chan_spec const *chan) | ||
258 | { | ||
259 | int min, max; | ||
260 | |||
261 | ad5755_get_min_max(st, chan, &min, &max); | ||
262 | return ((max - min) * 1000000000ULL) >> chan->scan_type.realbits; | ||
263 | } | ||
264 | |||
265 | static int ad5755_chan_reg_info(struct ad5755_state *st, | 256 | static int ad5755_chan_reg_info(struct ad5755_state *st, |
266 | struct iio_chan_spec const *chan, long info, bool write, | 257 | struct iio_chan_spec const *chan, long info, bool write, |
267 | unsigned int *reg, unsigned int *shift, unsigned int *offset) | 258 | unsigned int *reg, unsigned int *shift, unsigned int *offset) |
@@ -303,13 +294,15 @@ static int ad5755_read_raw(struct iio_dev *indio_dev, | |||
303 | { | 294 | { |
304 | struct ad5755_state *st = iio_priv(indio_dev); | 295 | struct ad5755_state *st = iio_priv(indio_dev); |
305 | unsigned int reg, shift, offset; | 296 | unsigned int reg, shift, offset; |
297 | int min, max; | ||
306 | int ret; | 298 | int ret; |
307 | 299 | ||
308 | switch (info) { | 300 | switch (info) { |
309 | case IIO_CHAN_INFO_SCALE: | 301 | case IIO_CHAN_INFO_SCALE: |
310 | *val = 0; | 302 | ad5755_get_min_max(st, chan, &min, &max); |
311 | *val2 = ad5755_get_scale(st, chan); | 303 | *val = max - min; |
312 | return IIO_VAL_INT_PLUS_NANO; | 304 | *val2 = chan->scan_type.realbits; |
305 | return IIO_VAL_FRACTIONAL_LOG2; | ||
313 | case IIO_CHAN_INFO_OFFSET: | 306 | case IIO_CHAN_INFO_OFFSET: |
314 | *val = ad5755_get_offset(st, chan); | 307 | *val = ad5755_get_offset(st, chan); |
315 | return IIO_VAL_INT; | 308 | return IIO_VAL_INT; |