linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lothar Rubusch <l.rubusch@gmail.com>
To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org,
	dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org,
	corbet@lwn.net
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-doc@vger.kernel.org, eraretuya@gmail.com,
	l.rubusch@gmail.com,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [PATCH v11 1/8] iio: accel: adxl345: simplify interrupt mapping
Date: Wed,  2 Jul 2025 23:03:08 +0000	[thread overview]
Message-ID: <20250702230315.19297-2-l.rubusch@gmail.com> (raw)
In-Reply-To: <20250702230315.19297-1-l.rubusch@gmail.com>

Refactor the sensor interrupt mapping by utilizing regmap_assign_bits(),
which accepts a boolean value directly. Introduce a helper function to
streamline the identification of the configured interrupt line pin. Also,
use identifiers from units.h to represent the full 8-bit register when
setting bits.

This is a purely refactoring change and does not affect functionality.

Signed-off-by: Lothar Rubusch <l.rubusch@gmail.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/iio/accel/adxl345_core.c | 34 +++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c
index e21ec6c15d15..6c437d7a59ed 100644
--- a/drivers/iio/accel/adxl345_core.c
+++ b/drivers/iio/accel/adxl345_core.c
@@ -1088,6 +1088,19 @@ static const struct iio_info adxl345_info = {
 	.hwfifo_set_watermark = adxl345_set_watermark,
 };
 
+static int adxl345_get_int_line(struct device *dev, int *irq)
+{
+	*irq = fwnode_irq_get_byname(dev_fwnode(dev), "INT1");
+	if (*irq > 0)
+		return ADXL345_INT1;
+
+	*irq = fwnode_irq_get_byname(dev_fwnode(dev), "INT2");
+	if (*irq > 0)
+		return ADXL345_INT2;
+
+	return ADXL345_INT_NONE;
+}
+
 /**
  * adxl345_core_probe() - Probe and setup for the accelerometer.
  * @dev:	Driver model representation of the device
@@ -1203,23 +1216,16 @@ int adxl345_core_probe(struct device *dev, struct regmap *regmap,
 	if (ret)
 		return ret;
 
-	irq = fwnode_irq_get_byname(dev_fwnode(dev), "INT1");
-	if (irq < 0) {
-		intio = ADXL345_INT2;
-		irq = fwnode_irq_get_byname(dev_fwnode(dev), "INT2");
-		if (irq < 0)
-			intio = ADXL345_INT_NONE;
-	}
-
+	intio = adxl345_get_int_line(dev, &irq);
 	if (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.
+		 * In the INT map register, bits set to 0 route their
+		 * corresponding interrupts to the INT1 pin, while bits set to 1
+		 * route them to the INT2 pin. The intio should handle this
+		 * mapping accordingly.
 		 */
-		regval = intio ? 0xff : 0;
-
-		ret = regmap_write(st->regmap, ADXL345_REG_INT_MAP, regval);
+		ret = regmap_assign_bits(st->regmap, ADXL345_REG_INT_MAP,
+					 U8_MAX, intio);
 		if (ret)
 			return ret;
 
-- 
2.39.5


  reply	other threads:[~2025-07-02 23:03 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-02 23:03 [PATCH v11 0/8] iio: accel: adxl345: add interrupt based sensor events Lothar Rubusch
2025-07-02 23:03 ` Lothar Rubusch [this message]
2025-07-06 16:10   ` [PATCH v11 1/8] iio: accel: adxl345: simplify interrupt mapping Jonathan Cameron
2025-07-02 23:03 ` [PATCH v11 2/8] iio: accel: adxl345: simplify reading the FIFO Lothar Rubusch
2025-07-06 16:11   ` Jonathan Cameron
2025-07-02 23:03 ` [PATCH v11 3/8] iio: accel: adxl345: add activity event feature Lothar Rubusch
2025-07-03 14:24   ` Andy Shevchenko
2025-07-06 16:09     ` Jonathan Cameron
2025-07-20 18:36       ` Lothar Rubusch
2025-07-24 13:43         ` Jonathan Cameron
2025-07-02 23:03 ` [PATCH v11 4/8] iio: accel: adxl345: add inactivity feature Lothar Rubusch
2025-07-03 14:26   ` Andy Shevchenko
2025-07-03 14:59     ` Lothar Rubusch
2025-07-03 15:45       ` Andy Shevchenko
2025-07-06 12:08         ` Jonathan Cameron
2025-07-02 23:03 ` [PATCH v11 5/8] iio: accel: adxl345: add coupling detection for activity/inactivity Lothar Rubusch
2025-07-02 23:03 ` [PATCH v11 6/8] iio: accel: adxl345: extend inactivity time for less than 1s Lothar Rubusch
2025-07-02 23:03 ` [PATCH v11 7/8] docs: iio: add documentation for adxl345 driver Lothar Rubusch
2025-07-02 23:03 ` [PATCH v11 8/8] docs: iio: describe inactivity and free-fall detection on the ADXL345 Lothar Rubusch
2025-07-06 16:16   ` Jonathan Cameron
2025-07-20 18:49     ` Lothar Rubusch
2025-07-24 13:47       ` 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=20250702230315.19297-2-l.rubusch@gmail.com \
    --to=l.rubusch@gmail.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=andy@kernel.org \
    --cc=corbet@lwn.net \
    --cc=dlechner@baylibre.com \
    --cc=eraretuya@gmail.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    /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).