From: "Nuno Sá" <nuno.sa@analog.com>
To: <linux-iio@vger.kernel.org>, <devicetree@vger.kernel.org>
Cc: "Michael Hennerich" <Michael.Hennerich@analog.com>,
"Jonathan Cameron" <jic23@kernel.org>,
"Lars-Peter Clausen" <lars@metafoo.de>,
"Rob Herring" <robh+dt@kernel.org>,
"Nuno Sá" <nuno.sa@analog.com>,
"Krzysztof Kozlowski" <krzysztof.kozlowski+dt@linaro.org>
Subject: [PATCH 1/3] iio: adc: ad7923: fix channel readings for some variants
Date: Fri, 9 Sep 2022 17:14:11 +0200 [thread overview]
Message-ID: <20220909151413.1164754-2-nuno.sa@analog.com> (raw)
In-Reply-To: <20220909151413.1164754-1-nuno.sa@analog.com>
Some of the supported devices have 4 or 2 LSB trailing bits that should
not be taken into account. Hence we need to shift these bits out which
fits perfectly on the scan type shift property. This change fixes both
raw and buffered reads.
Fixes: f2f7a449707e ("iio:adc:ad7923: Add support for the ad7904/ad7914/ad7924")
Fixes: 851644a60d20 ("iio: adc: ad7923: Add support for the ad7908/ad7918/ad7928")
Signed-off-by: Nuno Sá <nuno.sa@analog.com>
---
drivers/iio/adc/ad7923.c | 46 +++++++++++++++++++++-------------------
1 file changed, 24 insertions(+), 22 deletions(-)
diff --git a/drivers/iio/adc/ad7923.c b/drivers/iio/adc/ad7923.c
index edad1f30121d..910cf05e75cd 100644
--- a/drivers/iio/adc/ad7923.c
+++ b/drivers/iio/adc/ad7923.c
@@ -80,7 +80,7 @@ enum ad7923_id {
AD7928
};
-#define AD7923_V_CHAN(index, bits) \
+#define AD7923_V_CHAN(index, bits, _shift) \
{ \
.type = IIO_VOLTAGE, \
.indexed = 1, \
@@ -93,38 +93,39 @@ enum ad7923_id {
.sign = 'u', \
.realbits = (bits), \
.storagebits = 16, \
+ .shift = (_shift), \
.endianness = IIO_BE, \
}, \
}
-#define DECLARE_AD7923_CHANNELS(name, bits) \
+#define DECLARE_AD7923_CHANNELS(name, bits, shift) \
const struct iio_chan_spec name ## _channels[] = { \
- AD7923_V_CHAN(0, bits), \
- AD7923_V_CHAN(1, bits), \
- AD7923_V_CHAN(2, bits), \
- AD7923_V_CHAN(3, bits), \
+ AD7923_V_CHAN(0, bits, shift), \
+ AD7923_V_CHAN(1, bits, shift), \
+ AD7923_V_CHAN(2, bits, shift), \
+ AD7923_V_CHAN(3, bits, shift), \
IIO_CHAN_SOFT_TIMESTAMP(4), \
}
-#define DECLARE_AD7908_CHANNELS(name, bits) \
+#define DECLARE_AD7908_CHANNELS(name, bits, shift) \
const struct iio_chan_spec name ## _channels[] = { \
- AD7923_V_CHAN(0, bits), \
- AD7923_V_CHAN(1, bits), \
- AD7923_V_CHAN(2, bits), \
- AD7923_V_CHAN(3, bits), \
- AD7923_V_CHAN(4, bits), \
- AD7923_V_CHAN(5, bits), \
- AD7923_V_CHAN(6, bits), \
- AD7923_V_CHAN(7, bits), \
+ AD7923_V_CHAN(0, bits, shift), \
+ AD7923_V_CHAN(1, bits, shift), \
+ AD7923_V_CHAN(2, bits, shift), \
+ AD7923_V_CHAN(3, bits, shift), \
+ AD7923_V_CHAN(4, bits, shift), \
+ AD7923_V_CHAN(5, bits, shift), \
+ AD7923_V_CHAN(6, bits, shift), \
+ AD7923_V_CHAN(7, bits, shift), \
IIO_CHAN_SOFT_TIMESTAMP(8), \
}
-static DECLARE_AD7923_CHANNELS(ad7904, 8);
-static DECLARE_AD7923_CHANNELS(ad7914, 10);
-static DECLARE_AD7923_CHANNELS(ad7924, 12);
-static DECLARE_AD7908_CHANNELS(ad7908, 8);
-static DECLARE_AD7908_CHANNELS(ad7918, 10);
-static DECLARE_AD7908_CHANNELS(ad7928, 12);
+static DECLARE_AD7923_CHANNELS(ad7904, 8, 4);
+static DECLARE_AD7923_CHANNELS(ad7914, 10, 2);
+static DECLARE_AD7923_CHANNELS(ad7924, 12, 0);
+static DECLARE_AD7908_CHANNELS(ad7908, 8, 4);
+static DECLARE_AD7908_CHANNELS(ad7918, 10, 2);
+static DECLARE_AD7908_CHANNELS(ad7928, 12, 0);
static const struct ad7923_chip_info ad7923_chip_info[] = {
[AD7904] = {
@@ -268,7 +269,8 @@ static int ad7923_read_raw(struct iio_dev *indio_dev,
return ret;
if (chan->address == EXTRACT(ret, 12, 4))
- *val = EXTRACT(ret, 0, 12);
+ *val = EXTRACT(ret, chan->scan_type.shift,
+ chan->scan_type.realbits);
else
return -EIO;
--
2.37.3
next prev parent reply other threads:[~2022-09-09 15:13 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-09 15:14 [PATCH 0/3] ad7923 fixes and full range support Nuno Sá
2022-09-09 15:14 ` Nuno Sá [this message]
2022-09-11 11:26 ` [PATCH 1/3] iio: adc: ad7923: fix channel readings for some variants Jonathan Cameron
2022-09-12 7:02 ` Nuno Sá
2022-09-09 15:14 ` [PATCH 2/3] iio: adc: ad7923: support extended range Nuno Sá
2022-09-09 15:14 ` [PATCH 3/3] dt-bindings: iio: adi,ad7923: add range-select property Nuno Sá
2022-09-11 11:28 ` Jonathan Cameron
2022-09-12 7:04 ` Nuno Sá
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=20220909151413.1164754-2-nuno.sa@analog.com \
--to=nuno.sa@analog.com \
--cc=Michael.Hennerich@analog.com \
--cc=devicetree@vger.kernel.org \
--cc=jic23@kernel.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=robh+dt@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).