Linux IIO development
 help / color / mirror / Atom feed
From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: Lars-Peter Clausen <lars@metafoo.de>,
	Michael Hennerich <Michael.Hennerich@analog.com>,
	Cosmin Tanislav <cosmin.tanislav@analog.com>,
	Jonathan Cameron <jic23@kernel.org>
Cc: devicetree@vger.kernel.org,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Rob Herring <robh+dt@kernel.org>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] iio: addac: ad74413r: wire up digital-input-threshold-microvolt DT property
Date: Fri, 23 Jun 2023 13:33:26 +0200	[thread overview]
Message-ID: <20230623113327.1062170-3-linux@rasmusvillemoes.dk> (raw)
In-Reply-To: <20230623113327.1062170-1-linux@rasmusvillemoes.dk>

The threshold is common to all channels configured as digital
input.

So far, we have not seen the settings in the DIN_THRESH affecting
functions other than digital input, but with a4cba07e64e6 ("iio:
addac: ad74413: don't set DIN_SINK for functions other than digital
input") in mind, do not read and apply the
digital-input-threshold-microvolt setting unless at least one channel
has been configured as one of the digital input variants.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
 drivers/iio/addac/ad74413r.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/drivers/iio/addac/ad74413r.c b/drivers/iio/addac/ad74413r.c
index e3366cf5eb31..efdd7fdd7ab9 100644
--- a/drivers/iio/addac/ad74413r.c
+++ b/drivers/iio/addac/ad74413r.c
@@ -129,6 +129,12 @@ struct ad74413r_state {
 #define AD74413R_GPO_CONFIG_COMPARATOR		0b011
 #define AD74413R_GPO_CONFIG_HIGH_IMPEDANCE	0b100
 
+#define AD74413R_REG_DIN_THRESH		0x22
+#define AD74413R_DIN_COMP_THRESH_MASK	GENMASK(5, 1)
+#define AD74413R_DIN_THRESH_MODE	BIT(0)
+#define AD74413R_DIN_THRESH_MODE_16V	BIT(0)
+#define AD74413R_DIN_THRESH_MODE_AVDD	0
+
 #define AD74413R_REG_ADC_CONV_CTRL	0x23
 #define AD74413R_CONV_SEQ_MASK		GENMASK(9, 8)
 #define AD74413R_CONV_SEQ_ON		0b00
@@ -1446,6 +1452,20 @@ static int ad74413r_probe(struct spi_device *spi)
 	}
 
 	if (st->num_comparator_gpios) {
+		u32 thresh, val, mask;
+
+		if (!device_property_read_u32(st->dev, "digital-input-threshold-microvolt",
+					      &thresh)) {
+			val = thresh/500000 - 1;
+			val = FIELD_PREP(AD74413R_DIN_COMP_THRESH_MASK, val);
+			val |= AD74413R_DIN_THRESH_MODE_16V;
+			mask = AD74413R_DIN_COMP_THRESH_MASK | AD74413R_DIN_THRESH_MODE;
+			ret = regmap_update_bits(st->regmap, AD74413R_REG_DIN_THRESH,
+						 mask, val);
+			if (ret)
+				return ret;
+		}
+
 		st->comp_gpiochip.owner = THIS_MODULE;
 		st->comp_gpiochip.label = st->chip_info->name;
 		st->comp_gpiochip.base = -1;
-- 
2.37.2


  parent reply	other threads:[~2023-06-23 11:33 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-23 11:33 [PATCH 0/2] iio: ad74413r: allow configuring digital input threshold Rasmus Villemoes
2023-06-23 11:33 ` [PATCH 1/2] dt-bindings: iio: ad74413r: add binding for " Rasmus Villemoes
2023-06-23 16:44   ` Conor Dooley
2023-06-23 21:57     ` Rob Herring
2023-06-26  8:15       ` Rasmus Villemoes
2023-06-26  8:29         ` Krzysztof Kozlowski
2023-07-02  9:36           ` Jonathan Cameron
2023-06-23 21:57   ` Rob Herring
2023-06-23 11:33 ` Rasmus Villemoes [this message]
2023-06-25 11:14   ` [PATCH 2/2] iio: addac: ad74413r: wire up digital-input-threshold-microvolt DT property 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=20230623113327.1062170-3-linux@rasmusvillemoes.dk \
    --to=linux@rasmusvillemoes.dk \
    --cc=Michael.Hennerich@analog.com \
    --cc=cosmin.tanislav@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=linux-kernel@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