aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2013-09-28 05:31:00 -0400
committerJonathan Cameron <jic23@kernel.org>2013-10-01 11:19:09 -0400
commitbc7c49bc77ba95609236f23082a38ec160416a8d (patch)
treea12e70772e8e91346c8bbe33d7c4f1eb85d46ffe /drivers/iio
parent4f2c188597858aa215754be7279e91d778502d8e (diff)
iio:ad5421: 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>
Diffstat (limited to 'drivers/iio')
-rw-r--r--drivers/iio/dac/ad5421.c16
1 files changed, 5 insertions, 11 deletions
diff --git a/drivers/iio/dac/ad5421.c b/drivers/iio/dac/ad5421.c
index 1f78b14abb7d..567c4bd546e5 100644
--- a/drivers/iio/dac/ad5421.c
+++ b/drivers/iio/dac/ad5421.c
@@ -281,18 +281,11 @@ static inline unsigned int ad5421_get_offset(struct ad5421_state *st)
281 return (min * (1 << 16)) / (max - min); 281 return (min * (1 << 16)) / (max - min);
282} 282}
283 283
284static inline unsigned int ad5421_get_scale(struct ad5421_state *st)
285{
286 unsigned int min, max;
287
288 ad5421_get_current_min_max(st, &min, &max);
289 return ((max - min) * 1000) / (1 << 16);
290}
291
292static int ad5421_read_raw(struct iio_dev *indio_dev, 284static int ad5421_read_raw(struct iio_dev *indio_dev,
293 struct iio_chan_spec const *chan, int *val, int *val2, long m) 285 struct iio_chan_spec const *chan, int *val, int *val2, long m)
294{ 286{
295 struct ad5421_state *st = iio_priv(indio_dev); 287 struct ad5421_state *st = iio_priv(indio_dev);
288 unsigned int min, max;
296 int ret; 289 int ret;
297 290
298 if (chan->type != IIO_CURRENT) 291 if (chan->type != IIO_CURRENT)
@@ -306,9 +299,10 @@ static int ad5421_read_raw(struct iio_dev *indio_dev,
306 *val = ret; 299 *val = ret;
307 return IIO_VAL_INT; 300 return IIO_VAL_INT;
308 case IIO_CHAN_INFO_SCALE: 301 case IIO_CHAN_INFO_SCALE:
309 *val = 0; 302 ad5421_get_current_min_max(st, &min, &max);
310 *val2 = ad5421_get_scale(st); 303 *val = max - min;
311 return IIO_VAL_INT_PLUS_MICRO; 304 *val2 = (1 << 16) * 1000;
305 return IIO_VAL_FRACTIONAL;
312 case IIO_CHAN_INFO_OFFSET: 306 case IIO_CHAN_INFO_OFFSET:
313 *val = ad5421_get_offset(st); 307 *val = ad5421_get_offset(st);
314 return IIO_VAL_INT; 308 return IIO_VAL_INT;