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

iio:ad5764: Report scale as fractional value

Move the complexity of calculating the fixed point scale to the core.

Also fix a off by one error in the comment describing the transfer function.
Signed-off-by: default avatarLars-Peter Clausen <lars@metafoo.de>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent ae76751f
...@@ -217,7 +217,6 @@ static int ad5764_read_raw(struct iio_dev *indio_dev, ...@@ -217,7 +217,6 @@ static int ad5764_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan, int *val, int *val2, long info) struct iio_chan_spec const *chan, int *val, int *val2, long info)
{ {
struct ad5764_state *st = iio_priv(indio_dev); struct ad5764_state *st = iio_priv(indio_dev);
unsigned long scale_uv;
unsigned int reg; unsigned int reg;
int vref; int vref;
int ret; int ret;
...@@ -245,15 +244,14 @@ static int ad5764_read_raw(struct iio_dev *indio_dev, ...@@ -245,15 +244,14 @@ static int ad5764_read_raw(struct iio_dev *indio_dev,
*val = sign_extend32(*val, 5); *val = sign_extend32(*val, 5);
return IIO_VAL_INT; return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE: case IIO_CHAN_INFO_SCALE:
/* vout = 4 * vref + ((dac_code / 65535) - 0.5) */ /* vout = 4 * vref + ((dac_code / 65536) - 0.5) */
vref = ad5764_get_channel_vref(st, chan->channel); vref = ad5764_get_channel_vref(st, chan->channel);
if (vref < 0) if (vref < 0)
return vref; return vref;
scale_uv = (vref * 4 * 100) >> chan->scan_type.realbits; *val = vref * 4 / 1000;
*val = scale_uv / 100000; *val2 = chan->scan_type.realbits;
*val2 = (scale_uv % 100000) * 10; return IIO_VAL_FRACTIONAL_LOG2;
return IIO_VAL_INT_PLUS_MICRO;
case IIO_CHAN_INFO_OFFSET: case IIO_CHAN_INFO_OFFSET:
*val = -(1 << chan->scan_type.realbits) / 2; *val = -(1 << chan->scan_type.realbits) / 2;
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