[PATCH 2/2] iio: addac: ad74413r: wire up digital-input-threshold-microvolt DT property

From: Rasmus Villemoes
Date: Fri Jun 23 2023 - 07:33:45 EST


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@xxxxxxxxxxxxxxxxxx>
---
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