aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio/dac/ad5764.c
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:11 -0400
commit3f83dae88422992140b6125ab866cdec9fd7b3b6 (patch)
tree1b3b8194819cd975eb6e63c3ab08f80e914ac767 /drivers/iio/dac/ad5764.c
parentae76751f67110f497848afd71d06a0b6bb4a7c89 (diff)
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: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio/dac/ad5764.c')
-rw-r--r--drivers/iio/dac/ad5764.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/drivers/iio/dac/ad5764.c b/drivers/iio/dac/ad5764.c
index df7e028d9db5..a8ff5b2ed13e 100644
--- a/drivers/iio/dac/ad5764.c
+++ b/drivers/iio/dac/ad5764.c
@@ -217,7 +217,6 @@ static int ad5764_read_raw(struct iio_dev *indio_dev,
217 struct iio_chan_spec const *chan, int *val, int *val2, long info) 217 struct iio_chan_spec const *chan, int *val, int *val2, long info)
218{ 218{
219 struct ad5764_state *st = iio_priv(indio_dev); 219 struct ad5764_state *st = iio_priv(indio_dev);
220 unsigned long scale_uv;
221 unsigned int reg; 220 unsigned int reg;
222 int vref; 221 int vref;
223 int ret; 222 int ret;
@@ -245,15 +244,14 @@ static int ad5764_read_raw(struct iio_dev *indio_dev,
245 *val = sign_extend32(*val, 5); 244 *val = sign_extend32(*val, 5);
246 return IIO_VAL_INT; 245 return IIO_VAL_INT;
247 case IIO_CHAN_INFO_SCALE: 246 case IIO_CHAN_INFO_SCALE:
248 /* vout = 4 * vref + ((dac_code / 65535) - 0.5) */ 247 /* vout = 4 * vref + ((dac_code / 65536) - 0.5) */
249 vref = ad5764_get_channel_vref(st, chan->channel); 248 vref = ad5764_get_channel_vref(st, chan->channel);
250 if (vref < 0) 249 if (vref < 0)
251 return vref; 250 return vref;
252 251
253 scale_uv = (vref * 4 * 100) >> chan->scan_type.realbits; 252 *val = vref * 4 / 1000;
254 *val = scale_uv / 100000; 253 *val2 = chan->scan_type.realbits;
255 *val2 = (scale_uv % 100000) * 10; 254 return IIO_VAL_FRACTIONAL_LOG2;
256 return IIO_VAL_INT_PLUS_MICRO;
257 case IIO_CHAN_INFO_OFFSET: 255 case IIO_CHAN_INFO_OFFSET:
258 *val = -(1 << chan->scan_type.realbits) / 2; 256 *val = -(1 << chan->scan_type.realbits) / 2;
259 return IIO_VAL_INT; 257 return IIO_VAL_INT;