devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marcelo Schmitt <marcelo.schmitt@analog.com>
To: <apw@canonical.com>, <joe@perches.com>, <dwaipayanray1@gmail.com>,
	<lukas.bulwahn@gmail.com>, <paul.cercueil@analog.com>,
	<Michael.Hennerich@analog.com>, <lars@metafoo.de>,
	<jic23@kernel.org>, <robh+dt@kernel.org>,
	<krzysztof.kozlowski+dt@linaro.org>, <conor+dt@kernel.org>,
	<dan.carpenter@linaro.org>, <dlechner@baylibre.com>,
	<marcelo.schmitt1@gmail.com>
Cc: <linux-iio@vger.kernel.org>, <devicetree@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Subject: [PATCH v5 02/11] iio: adc: ad7091r: Enable internal vref if external vref is not supplied
Date: Tue, 19 Dec 2023 17:26:27 -0300	[thread overview]
Message-ID: <b865033fa6a4fc4bf2b4a98ec51a6144e0f64f77.1703013352.git.marcelo.schmitt1@gmail.com> (raw)
In-Reply-To: <cover.1703013352.git.marcelo.schmitt1@gmail.com>

The ADC needs a voltage reference to work correctly.
Users can provide an external voltage reference or use the chip internal
reference to operate the ADC.
The availability of an in chip reference for the ADC saves the user from
having to supply an external voltage reference, which makes the external
reference an optional property as described in the device tree
documentation.
Though, to use the internal reference, it must be enabled by writing to
the configuration register.
Enable AD7091R internal voltage reference if no external vref is supplied.

Fixes: 260442cc5be4 ("iio: adc: ad7091r5: Add scale and external VREF support")
Signed-off-by: Marcelo Schmitt <marcelo.schmitt@analog.com>
---
 drivers/iio/adc/ad7091r-base.c | 7 +++++++
 drivers/iio/adc/ad7091r-base.h | 2 ++
 2 files changed, 9 insertions(+)

diff --git a/drivers/iio/adc/ad7091r-base.c b/drivers/iio/adc/ad7091r-base.c
index 6d93da154810..7ccc9b44dcd8 100644
--- a/drivers/iio/adc/ad7091r-base.c
+++ b/drivers/iio/adc/ad7091r-base.c
@@ -406,7 +406,14 @@ int ad7091r_probe(struct device *dev, const char *name,
 	if (IS_ERR(st->vref)) {
 		if (PTR_ERR(st->vref) == -EPROBE_DEFER)
 			return -EPROBE_DEFER;
+
 		st->vref = NULL;
+		/* Enable internal vref */
+		ret = regmap_set_bits(st->map, AD7091R_REG_CONF,
+				      AD7091R_REG_CONF_INT_VREF);
+		if (ret)
+			return dev_err_probe(st->dev, ret,
+					     "Error on enable internal reference\n");
 	} else {
 		ret = regulator_enable(st->vref);
 		if (ret)
diff --git a/drivers/iio/adc/ad7091r-base.h b/drivers/iio/adc/ad7091r-base.h
index 7a78976a2f80..b9e1c8bf3440 100644
--- a/drivers/iio/adc/ad7091r-base.h
+++ b/drivers/iio/adc/ad7091r-base.h
@@ -8,6 +8,8 @@
 #ifndef __DRIVERS_IIO_ADC_AD7091R_BASE_H__
 #define __DRIVERS_IIO_ADC_AD7091R_BASE_H__
 
+#define AD7091R_REG_CONF_INT_VREF	BIT(0)
+
 /* AD7091R_REG_CH_LIMIT */
 #define AD7091R_HIGH_LIMIT		0xFFF
 #define AD7091R_LOW_LIMIT		0x0
-- 
2.42.0


  parent reply	other threads:[~2023-12-19 20:27 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-19 20:25 [PATCH v5 00/11] Add support for AD7091R-2/-4/-8 Marcelo Schmitt
2023-12-19 20:26 ` [PATCH v5 01/11] iio: adc: ad7091r: Allow users to configure device events Marcelo Schmitt
2023-12-19 20:26 ` Marcelo Schmitt [this message]
2023-12-19 20:27 ` [PATCH v5 03/11] iio: adc: ad7091r: Move generic AD7091R code to base driver and header file Marcelo Schmitt
2023-12-19 20:27 ` [PATCH v5 04/11] iio: adc: ad7091r: Move chip init data to container struct Marcelo Schmitt
2023-12-19 20:28 ` [PATCH v5 05/11] iio: adc: ad7091r: Remove unneeded probe parameters Marcelo Schmitt
2023-12-19 20:28 ` [PATCH v5 06/11] iio: adc: ad7091r: Set device mode through chip_info callback Marcelo Schmitt
2023-12-19 20:29 ` [PATCH v5 07/11] iio: adc: ad7091r: Add chip_info callback to get conversion result channel Marcelo Schmitt
2023-12-19 20:29 ` [PATCH v5 08/11] iio: adc: Split AD7091R-5 config symbol Marcelo Schmitt
2023-12-19 20:32 ` [PATCH v5 09/11] dt-bindings: iio: Add AD7091R-8 Marcelo Schmitt
2023-12-19 20:32 ` [PATCH v5 10/11] iio: adc: Add support for AD7091R-8 Marcelo Schmitt
2023-12-19 20:32 ` [PATCH v5 11/11] MAINTAINERS: Add MAINTAINERS entry for AD7091R Marcelo Schmitt
2023-12-21 16:59   ` Jonathan Cameron
2023-12-22 12:49     ` Marcelo Schmitt
2023-12-26 15:45       ` Jonathan Cameron
2023-12-21 16:53 ` [PATCH v5 00/11] Add support for AD7091R-2/-4/-8 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=b865033fa6a4fc4bf2b4a98ec51a6144e0f64f77.1703013352.git.marcelo.schmitt1@gmail.com \
    --to=marcelo.schmitt@analog.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=apw@canonical.com \
    --cc=conor+dt@kernel.org \
    --cc=dan.carpenter@linaro.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=dwaipayanray1@gmail.com \
    --cc=jic23@kernel.org \
    --cc=joe@perches.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lukas.bulwahn@gmail.com \
    --cc=marcelo.schmitt1@gmail.com \
    --cc=paul.cercueil@analog.com \
    --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).