diff mbox series

[1/7] iio: adc: ad7091r-base: Set alert config and drvdata

Message ID b485b1ccafad79f9ac3bb1a6b5e6d68b24ad4ad5.1700595310.git.marcelo.schmitt1@gmail.com (mailing list archive)
State Changes Requested
Headers show
Series Add support for AD7091R-2/-4/-8 | expand

Commit Message

Marcelo Schmitt Nov. 21, 2023, 9:34 p.m. UTC
From: Marcelo Schmitt <marcelo.schmitt@analog.com>

Write 1 to bit 4 in the configuration register to set ALERT/BUSY/GPO pin
to be used as ALERT.
Set device driver data so it can be retrieved when handling alert
events, avoiding null pointer dereference.

Fixes: <ca69300173b6> (iio: adc: Add support for AD7091R5 ADC)
Signed-off-by: Marcelo Schmitt <marcelo.schmitt@analog.com>
---
 drivers/iio/adc/ad7091r-base.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/drivers/iio/adc/ad7091r-base.c b/drivers/iio/adc/ad7091r-base.c
index 8e252cde735b..3ecac3164446 100644
--- a/drivers/iio/adc/ad7091r-base.c
+++ b/drivers/iio/adc/ad7091r-base.c
@@ -28,6 +28,7 @@ 
 #define AD7091R_REG_RESULT_CONV_RESULT(x)   ((x) & 0xfff)
 
 /* AD7091R_REG_CONF */
+#define AD7091R_REG_CONF_ALERT_EN   BIT(4)
 #define AD7091R_REG_CONF_AUTO   BIT(8)
 #define AD7091R_REG_CONF_CMD    BIT(10)
 
@@ -232,9 +233,16 @@  int ad7091r_probe(struct device *dev, const char *name,
 	iio_dev->channels = chip_info->channels;
 
 	if (irq) {
+		ret = regmap_update_bits(st->map, AD7091R_REG_CONF,
+					 AD7091R_REG_CONF_ALERT_EN, BIT(4));
+		if (ret)
+			return ret;
+
+		dev_set_drvdata(st->dev, iio_dev);
 		ret = devm_request_threaded_irq(dev, irq, NULL,
-				ad7091r_event_handler,
-				IRQF_TRIGGER_FALLING | IRQF_ONESHOT, name, st);
+						ad7091r_event_handler,
+						IRQF_TRIGGER_FALLING |
+						IRQF_ONESHOT, name, st);
 		if (ret)
 			return ret;
 	}