Skip to content

Commit

Permalink
staging:iio:dac:ad5791: Use correct DAC bit-size
Browse files Browse the repository at this point in the history
Commit c5b9939 ("staging:iio:dac:ad5791 chan spec conversion.") introduced a
small bug, using storagebits instead of realbits throughout the driver, which
causes the driver to work incorrectly. This patch fixes it.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Acked-by: Jonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Lars-Peter Clausen authored and Greg Kroah-Hartman committed Oct 19, 2011
1 parent 1b99232 commit 021c0a3
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions drivers/staging/iio/dac/ad5791.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,11 @@ static int ad5791_read_raw(struct iio_dev *indio_dev,
return ret;
*val &= AD5791_DAC_MASK;
*val >>= chan->scan_type.shift;
*val -= (1 << (chan->scan_type.storagebits - 1));
*val -= (1 << (chan->scan_type.realbits - 1));
return IIO_VAL_INT;
case (1 << IIO_CHAN_INFO_SCALE_SHARED):
*val = 0;
*val2 = (st->vref_mv * 1000) >> chan->scan_type.storagebits;
*val2 = (st->vref_mv * 1000) >> chan->scan_type.realbits;
return IIO_VAL_INT_PLUS_MICRO;
default:
return -EINVAL;
Expand All @@ -257,8 +257,8 @@ static int ad5791_write_raw(struct iio_dev *indio_dev,

switch (mask) {
case 0:
val += (1 << (chan->scan_type.storagebits - 1));
val &= AD5791_RES_MASK(chan->scan_type.storagebits);
val += (1 << (chan->scan_type.realbits - 1));
val &= AD5791_RES_MASK(chan->scan_type.realbits);
val <<= chan->scan_type.shift;

return ad5791_spi_write(st->spi, chan->address, val);
Expand Down

0 comments on commit 021c0a3

Please sign in to comment.