Linux IIO development
 help / color / mirror / Atom feed
From: Lothar Rubusch <l.rubusch@gmail.com>
To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	eraretuya@gmail.com, l.rubusch@gmail.com
Subject: [PATCH v2 04/14] iio: accel: adxl345: refac set_interrupts and IRQ map
Date: Mon, 10 Feb 2025 11:01:09 +0000	[thread overview]
Message-ID: <20250210110119.260858-5-l.rubusch@gmail.com> (raw)
In-Reply-To: <20250210110119.260858-1-l.rubusch@gmail.com>

Split the current set_interrupts() functionality. Separate writing the
interrupt map from writing the interrupt enable register.

Move writing the interrupt map into the probe(). The interrupt map will
setup which event finally will go over the INT line. Thus, all events
are mapped to this interrupt line now once at the beginning.

On the other side the function set_interrupts() will now be focussed on
enabling interrupts for event features. Thus it will be renamed to
write_interrupts() to better distinguish from further usage of get/set
in the conext of the sensor features.

Also, add the missing initial reset of the interrupt enable register.

Signed-off-by: Lothar Rubusch <l.rubusch@gmail.com>
---
 drivers/iio/accel/adxl345_core.c | 46 +++++++++++++++-----------------
 1 file changed, 22 insertions(+), 24 deletions(-)

diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c
index 2928c1c0760f..910ad21279ed 100644
--- a/drivers/iio/accel/adxl345_core.c
+++ b/drivers/iio/accel/adxl345_core.c
@@ -14,10 +14,10 @@
 #include <linux/regmap.h>
 #include <linux/units.h>
 
-#include <linux/iio/iio.h>
-#include <linux/iio/sysfs.h>
 #include <linux/iio/buffer.h>
+#include <linux/iio/iio.h>
 #include <linux/iio/kfifo_buf.h>
+#include <linux/iio/sysfs.h>
 
 #include "adxl345.h"
 
@@ -96,26 +96,6 @@ static int adxl345_set_measure_en(struct adxl345_state *st, bool en)
 	return regmap_write(st->regmap, ADXL345_REG_POWER_CTL, val);
 }
 
-static int adxl345_set_interrupts(struct adxl345_state *st)
-{
-	int ret;
-	unsigned int int_enable = st->int_map;
-	unsigned int int_map;
-
-	/*
-	 * Any bits set to 0 in the INT map register send their respective
-	 * interrupts to the INT1 pin, whereas bits set to 1 send their respective
-	 * interrupts to the INT2 pin. The intio shall convert this accordingly.
-	 */
-	int_map = st->intio ? st->int_map : ~st->int_map;
-
-	ret = regmap_write(st->regmap, ADXL345_REG_INT_MAP, int_map);
-	if (ret)
-		return ret;
-
-	return regmap_write(st->regmap, ADXL345_REG_INT_ENABLE, int_enable);
-}
-
 static int adxl345_read_raw(struct iio_dev *indio_dev,
 			    struct iio_chan_spec const *chan,
 			    int *val, int *val2, long mask)
@@ -376,7 +356,7 @@ static int adxl345_buffer_postenable(struct iio_dev *indio_dev)
 	struct adxl345_state *st = iio_priv(indio_dev);
 	int ret;
 
-	ret = adxl345_set_interrupts(st);
+	ret = regmap_write(st->regmap, ADXL345_REG_INT_ENABLE, st->int_map);
 	if (ret < 0)
 		return ret;
 
@@ -395,7 +375,7 @@ static int adxl345_buffer_predisable(struct iio_dev *indio_dev)
 		return ret;
 
 	st->int_map = 0x00;
-	return adxl345_set_interrupts(st);
+	return regmap_write(st->regmap, ADXL345_REG_INT_ENABLE, st->int_map);
 }
 
 static const struct iio_buffer_setup_ops adxl345_buffer_ops = {
@@ -514,6 +494,8 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap,
 		return -ENODEV;
 	st->fifo_delay = fifo_delay_default;
 
+	st->int_map = 0x00;			/* reset interrupts */
+
 	indio_dev->name = st->info->name;
 	indio_dev->info = &adxl345_info;
 	indio_dev->modes = INDIO_DIRECT_MODE;
@@ -521,6 +503,11 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap,
 	indio_dev->num_channels = ARRAY_SIZE(adxl345_channels);
 	indio_dev->available_scan_masks = adxl345_scan_masks;
 
+	/* Reset interrupts at start up */
+	ret = regmap_write(st->regmap, ADXL345_REG_INT_ENABLE, st->int_map);
+	if (ret)
+		return ret;
+
 	if (setup) {
 		/* Perform optional initial bus specific configuration */
 		ret = setup(dev, st->regmap);
@@ -571,6 +558,17 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap,
 	}
 
 	if (st->intio != ADXL345_INT_NONE) {
+		/*
+		 * Any bits set to 0 in the INT map register send their respective
+		 * interrupts to the INT1 pin, whereas bits set to 1 send their respective
+		 * interrupts to the INT2 pin. The intio shall convert this accordingly.
+		 */
+		regval = st->intio ? 0xff : 0;
+
+		ret = regmap_write(st->regmap, ADXL345_REG_INT_MAP, regval);
+		if (ret)
+			return ret;
+
 		/* FIFO_STREAM mode is going to be activated later */
 		ret = devm_iio_kfifo_buffer_setup(dev, indio_dev, &adxl345_buffer_ops);
 		if (ret)
-- 
2.39.5


  parent reply	other threads:[~2025-02-10 11:01 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-10 11:01 [PATCH v2 00/14] iio: accel: adxl345: add interrupt based sensor events Lothar Rubusch
2025-02-10 11:01 ` [PATCH v2 01/14] iio: accel: adxl345: reorganize measurement enable Lothar Rubusch
2025-02-10 11:01 ` [PATCH v2 02/14] iio: accel: adxl345: add debug register access Lothar Rubusch
2025-02-10 11:01 ` [PATCH v2 03/14] iio: accel: adxl345: reorganize irq handler Lothar Rubusch
2025-02-16 17:05   ` Jonathan Cameron
2025-02-10 11:01 ` Lothar Rubusch [this message]
2025-02-16 17:11   ` [PATCH v2 04/14] iio: accel: adxl345: refac set_interrupts and IRQ map Jonathan Cameron
2025-02-10 11:01 ` [PATCH v2 05/14] iio: accel: adxl345: add single tap feature Lothar Rubusch
2025-02-16 17:20   ` Jonathan Cameron
2025-02-10 11:01 ` [PATCH v2 06/14] iio: accel: adxl345: add double " Lothar Rubusch
2025-02-16 17:23   ` Jonathan Cameron
2025-02-10 11:01 ` [PATCH v2 07/14] iio: accel: adxl345: add double tap suppress bit Lothar Rubusch
2025-02-16 17:28   ` Jonathan Cameron
2025-02-18 22:29     ` Lothar Rubusch
2025-02-20 17:47       ` Jonathan Cameron
2025-02-10 11:01 ` [PATCH v2 08/14] iio: accel: adxl345: add freefall feature Lothar Rubusch
2025-02-16 17:33   ` Jonathan Cameron
2025-02-10 11:01 ` [PATCH v2 09/14] iio: accel: adxl345: extend sample frequency adjustments Lothar Rubusch
2025-02-16 17:38   ` Jonathan Cameron
2025-02-10 11:01 ` [PATCH v2 10/14] iio: accel: adxl345: add g-range configuration Lothar Rubusch
2025-02-16 17:41   ` Jonathan Cameron
2025-02-10 11:01 ` [PATCH v2 11/14] iio: accel: adxl345: add activity event feature Lothar Rubusch
2025-02-16 17:43   ` Jonathan Cameron
2025-02-10 11:01 ` [PATCH v2 12/14] iio: accel: adxl345: add inactivity feature Lothar Rubusch
2025-02-16 17:47   ` Jonathan Cameron
2025-02-10 11:01 ` [PATCH v2 13/14] iio: accel: adxl345: add coupling detection for activity/inactivity Lothar Rubusch
2025-02-16 17:54   ` Jonathan Cameron
2025-02-10 11:01 ` [PATCH v2 14/14] docs: iio: add documentation for adxl345 driver Lothar Rubusch
2025-02-16 18:00   ` 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=20250210110119.260858-5-l.rubusch@gmail.com \
    --to=l.rubusch@gmail.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=eraretuya@gmail.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.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