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 2/3] iio: adc: ad7923: support extended range
Date: Fri, 9 Sep 2022 17:14:12 +0200 [thread overview]
Message-ID: <20220909151413.1164754-3-nuno.sa@analog.com> (raw)
In-Reply-To: <20220909151413.1164754-1-nuno.sa@analog.com>
By default the driver was always setting the RANGE bit which means that
the analog input goes from 0 to VREF. However, we might want to have 0
to 2xVREF. This change adds a new FW property to allow for the range
selection while keeping the default behavior if nothing is provided.
Signed-off-by: Nuno Sá <nuno.sa@analog.com>
---
drivers/iio/adc/ad7923.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/adc/ad7923.c b/drivers/iio/adc/ad7923.c
index 910cf05e75cd..4bd0ae209d18 100644
--- a/drivers/iio/adc/ad7923.c
+++ b/drivers/iio/adc/ad7923.c
@@ -6,8 +6,10 @@
* Copyright 2012 CS Systemes d'Information
*/
+#include <linux/bitfield.h>
#include <linux/device.h>
#include <linux/kernel.h>
+#include <linux/property.h>
#include <linux/slab.h>
#include <linux/sysfs.h>
#include <linux/spi/spi.h>
@@ -45,6 +47,8 @@
/* val = value, dec = left shift, bits = number of bits of the mask */
#define EXTRACT(val, dec, bits) (((val) >> (dec)) & ((1 << (bits)) - 1))
+#define AD7923_RANGE_0_VREF 1
+
struct ad7923_state {
struct spi_device *spi;
struct spi_transfer ring_xfer[5];
@@ -300,6 +304,7 @@ static void ad7923_regulator_disable(void *data)
static int ad7923_probe(struct spi_device *spi)
{
+ u32 ad7923_range = FIELD_PREP(AD7923_RANGE, AD7923_RANGE_0_VREF), val;
struct ad7923_state *st;
struct iio_dev *indio_dev;
const struct ad7923_chip_info *info;
@@ -311,8 +316,17 @@ static int ad7923_probe(struct spi_device *spi)
st = iio_priv(indio_dev);
+ ret = device_property_read_u32(&spi->dev, "adi,range-select", &val);
+ if (!ret) {
+ if (val > AD7923_RANGE_0_VREF)
+ return dev_err_probe(&spi->dev, -EINVAL,
+ "Invalid range (%u) selected\n", val);
+
+ ad7923_range = FIELD_PREP(AD7923_RANGE, val);
+ }
+
st->spi = spi;
- st->settings = AD7923_CODING | AD7923_RANGE |
+ st->settings = AD7923_CODING | ad7923_range |
AD7923_PM_MODE_WRITE(AD7923_PM_MODE_OPS);
info = &ad7923_chip_info[spi_get_device_id(spi)->driver_data];
--
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 ` [PATCH 1/3] iio: adc: ad7923: fix channel readings for some variants Nuno Sá
2022-09-11 11:26 ` Jonathan Cameron
2022-09-12 7:02 ` Nuno Sá
2022-09-09 15:14 ` Nuno Sá [this message]
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-3-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).