From: "Martin Hundebøll" <mnhu@prevas.dk>
To: <linux-iio@vger.kernel.org>
Cc: "Martin Hundebøll" <mnhu@prevas.dk>,
"Jonathan Cameron" <jic23@kernel.org>
Subject: [PATCH] iio: dac: ad5446: return unshifted values in read_raw
Date: Tue, 30 Aug 2016 08:27:43 +0200 [thread overview]
Message-ID: <20160830062743.10611-1-mnhu@prevas.dk> (raw)
The Analog Devices DAC chips supported by the ad5456 driver ignore
between 0 and 6 of the least significant bits, and thus the written raw
value is shifted accordingly before being cached and written.
Since the shifted value is cached, it is returned to the user in
ad5446_read_raw(), which might be confusing to the user (at least it was
for me).
Instead store the unshifted value and do the shifting when needed (i.e.
when writing data and disabling powerdown mode).
Signed-off-by: Martin Hundebøll <mnhu@prevas.dk>
---
drivers/iio/dac/ad5446.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/dac/ad5446.c b/drivers/iio/dac/ad5446.c
index 46bb62a..8d172d7 100644
--- a/drivers/iio/dac/ad5446.c
+++ b/drivers/iio/dac/ad5446.c
@@ -118,7 +118,7 @@ static ssize_t ad5446_write_dac_powerdown(struct iio_dev *indio_dev,
shift = chan->scan_type.realbits + chan->scan_type.shift;
val = st->pwr_down_mode << shift;
} else {
- val = st->cached_val;
+ val = st->cached_val << chan->scan_type.shift;
}
ret = st->chip_info->write(st, val);
@@ -195,9 +195,9 @@ static int ad5446_write_raw(struct iio_dev *indio_dev,
if (val >= (1 << chan->scan_type.realbits) || val < 0)
return -EINVAL;
- val <<= chan->scan_type.shift;
mutex_lock(&indio_dev->mlock);
st->cached_val = val;
+ val <<= chan->scan_type.shift;
if (!st->pwr_down)
ret = st->chip_info->write(st, val);
mutex_unlock(&indio_dev->mlock);
--
2.9.3
next reply other threads:[~2016-08-30 6:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-30 6:27 Martin Hundebøll [this message]
2016-09-03 16:21 ` [PATCH] iio: dac: ad5446: return unshifted values in read_raw Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160830062743.10611-1-mnhu@prevas.dk \
--to=mnhu@prevas.dk \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).