Skip to content

Commit af7cc8e

Browse files
Mircea Capriorugregkh
authored andcommitted
iio: dac: ad5686: fix bit shift read register
commit 0e76df5 upstream. This patch solves the register readback issue with the bit shift. When the dac resolution was lower than the register size (ex. 12 bits out of 16 bits) the readback value was not shifted with the difference in bits and the value was higher. Also a mask is applied on the read value in order to get the value relative to the actual bit size. Fixes: 0357e48 ("iio:dac:ad5686: Refactor the driver") Signed-off-by: Mircea Caprioru <mircea.caprioru@analog.com> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a854ab8 commit af7cc8e

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

drivers/iio/dac/ad5686.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ static int ad5686_read_raw(struct iio_dev *indio_dev,
124124
mutex_unlock(&indio_dev->mlock);
125125
if (ret < 0)
126126
return ret;
127-
*val = ret;
127+
*val = (ret >> chan->scan_type.shift) &
128+
GENMASK(chan->scan_type.realbits - 1, 0);
128129
return IIO_VAL_INT;
129130
case IIO_CHAN_INFO_SCALE:
130131
*val = st->vref_mv;

0 commit comments

Comments
 (0)