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

iio:ad5421: Report scale as fractional value

Move the complexity of calculating the fixed point scale to the core.
Signed-off-by: default avatarLars-Peter Clausen <lars@metafoo.de>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent 4f2c1885
...@@ -281,18 +281,11 @@ static inline unsigned int ad5421_get_offset(struct ad5421_state *st) ...@@ -281,18 +281,11 @@ static inline unsigned int ad5421_get_offset(struct ad5421_state *st)
return (min * (1 << 16)) / (max - min); return (min * (1 << 16)) / (max - min);
} }
static inline unsigned int ad5421_get_scale(struct ad5421_state *st)
{
unsigned int min, max;
ad5421_get_current_min_max(st, &min, &max);
return ((max - min) * 1000) / (1 << 16);
}
static int ad5421_read_raw(struct iio_dev *indio_dev, static int ad5421_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan, int *val, int *val2, long m) struct iio_chan_spec const *chan, int *val, int *val2, long m)
{ {
struct ad5421_state *st = iio_priv(indio_dev); struct ad5421_state *st = iio_priv(indio_dev);
unsigned int min, max;
int ret; int ret;
if (chan->type != IIO_CURRENT) if (chan->type != IIO_CURRENT)
...@@ -306,9 +299,10 @@ static int ad5421_read_raw(struct iio_dev *indio_dev, ...@@ -306,9 +299,10 @@ static int ad5421_read_raw(struct iio_dev *indio_dev,
*val = ret; *val = ret;
return IIO_VAL_INT; return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE: case IIO_CHAN_INFO_SCALE:
*val = 0; ad5421_get_current_min_max(st, &min, &max);
*val2 = ad5421_get_scale(st); *val = max - min;
return IIO_VAL_INT_PLUS_MICRO; *val2 = (1 << 16) * 1000;
return IIO_VAL_FRACTIONAL;
case IIO_CHAN_INFO_OFFSET: case IIO_CHAN_INFO_OFFSET:
*val = ad5421_get_offset(st); *val = ad5421_get_offset(st);
return IIO_VAL_INT; return IIO_VAL_INT;
......
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