Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging:iio:dac:ad5791: Use correct DAC bit-size

Commit c5b99396 ("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>

authored by

Lars-Peter Clausen and committed by
Greg Kroah-Hartman
021c0a38 1b992320

+4 -4
+4 -4
drivers/staging/iio/dac/ad5791.c
··· 234 234 return ret; 235 235 *val &= AD5791_DAC_MASK; 236 236 *val >>= chan->scan_type.shift; 237 - *val -= (1 << (chan->scan_type.storagebits - 1)); 237 + *val -= (1 << (chan->scan_type.realbits - 1)); 238 238 return IIO_VAL_INT; 239 239 case (1 << IIO_CHAN_INFO_SCALE_SHARED): 240 240 *val = 0; 241 - *val2 = (st->vref_mv * 1000) >> chan->scan_type.storagebits; 241 + *val2 = (st->vref_mv * 1000) >> chan->scan_type.realbits; 242 242 return IIO_VAL_INT_PLUS_MICRO; 243 243 default: 244 244 return -EINVAL; ··· 257 257 258 258 switch (mask) { 259 259 case 0: 260 - val += (1 << (chan->scan_type.storagebits - 1)); 261 - val &= AD5791_RES_MASK(chan->scan_type.storagebits); 260 + val += (1 << (chan->scan_type.realbits - 1)); 261 + val &= AD5791_RES_MASK(chan->scan_type.realbits); 262 262 val <<= chan->scan_type.shift; 263 263 264 264 return ad5791_spi_write(st->spi, chan->address, val);