linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: dac: ad5686: fix bit shift read register
@ 2018-12-06 13:53 Mircea Caprioru
  2018-12-08 15:44 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Mircea Caprioru @ 2018-12-06 13:53 UTC (permalink / raw)
  To: jic23
  Cc: Michael.Hennerich, knaack.h, lars, pmeerw, gregkh, linux-kernel,
	linux-iio, devel, Mircea Caprioru

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: 0357e488b8 ("iio:dac:ad5686: Refactor the driver")
Signed-off-by: Mircea Caprioru <mircea.caprioru@analog.com>
---
 drivers/iio/dac/ad5686.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
index 54ff76b93366..a332b93ca2c4 100644
--- a/drivers/iio/dac/ad5686.c
+++ b/drivers/iio/dac/ad5686.c
@@ -128,7 +128,8 @@ static int ad5686_read_raw(struct iio_dev *indio_dev,
 		mutex_unlock(&indio_dev->mlock);
 		if (ret < 0)
 			return ret;
-		*val = ret;
+		*val = (ret >> chan->scan_type.shift) &
+			GENMASK(chan->scan_type.realbits - 1, 0);
 		return IIO_VAL_INT;
 	case IIO_CHAN_INFO_SCALE:
 		*val = st->vref_mv;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] iio: dac: ad5686: fix bit shift read register
  2018-12-06 13:53 [PATCH] iio: dac: ad5686: fix bit shift read register Mircea Caprioru
@ 2018-12-08 15:44 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2018-12-08 15:44 UTC (permalink / raw)
  To: Mircea Caprioru
  Cc: Michael.Hennerich, knaack.h, lars, pmeerw, gregkh, linux-kernel,
	linux-iio, devel

On Thu, 6 Dec 2018 15:53:15 +0200
Mircea Caprioru <mircea.caprioru@analog.com> wrote:

> 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: 0357e488b8 ("iio:dac:ad5686: Refactor the driver")
> Signed-off-by: Mircea Caprioru <mircea.caprioru@analog.com>
This seems obvious, but a little strange we've not noticed it
before.    Ah well.  Given the time in the cycle I'm going to
take it for the next merge window rather than rushing it it.

Applied to the togreg branch of iio.git and pushed out as
testing for the autobuilders to play with it.

Thanks,

Jonathan

> ---
>  drivers/iio/dac/ad5686.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
> index 54ff76b93366..a332b93ca2c4 100644
> --- a/drivers/iio/dac/ad5686.c
> +++ b/drivers/iio/dac/ad5686.c
> @@ -128,7 +128,8 @@ static int ad5686_read_raw(struct iio_dev *indio_dev,
>  		mutex_unlock(&indio_dev->mlock);
>  		if (ret < 0)
>  			return ret;
> -		*val = ret;
> +		*val = (ret >> chan->scan_type.shift) &
> +			GENMASK(chan->scan_type.realbits - 1, 0);
>  		return IIO_VAL_INT;
>  	case IIO_CHAN_INFO_SCALE:
>  		*val = st->vref_mv;


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-12-08 15:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-06 13:53 [PATCH] iio: dac: ad5686: fix bit shift read register Mircea Caprioru
2018-12-08 15:44 ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).