devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Petre Rodan <petre.rodan@subdimension.ro>
To: "Jonathan Cameron" <jic23@kernel.org>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>
Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	 linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	 linux-kernel@vger.kernel.org
Subject: [PATCH v4 16/19] iio: accel: bma220: add interrupt trigger
Date: Sun, 05 Oct 2025 16:12:25 +0300	[thread overview]
Message-ID: <20251005-b4-bma220_improvements-v4-16-0f449ba31585@subdimension.ro> (raw)
In-Reply-To: <20251005-b4-bma220_improvements-v4-0-0f449ba31585@subdimension.ro>

Add interrupt trigger.

Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
---
v1->v2 no change, just patch split
v2->v3 replace regmap_bulk_read with regmap_read (Jonathan)
 (I just realized BMA220_REG_IF0 is never used, even by future
 event patches)
v4 fix compilation err
---
 drivers/iio/accel/bma220_core.c | 58 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/drivers/iio/accel/bma220_core.c b/drivers/iio/accel/bma220_core.c
index a957751be40c63c25963283be813db97f73bf004..8f0cbd0aacb92a21afc57aaa350547d0c767d4b6 100644
--- a/drivers/iio/accel/bma220_core.c
+++ b/drivers/iio/accel/bma220_core.c
@@ -22,6 +22,7 @@
 #include <linux/iio/buffer.h>
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
+#include <linux/iio/trigger.h>
 #include <linux/iio/trigger_consumer.h>
 #include <linux/iio/triggered_buffer.h>
 
@@ -123,6 +124,7 @@ struct bma220_data {
 	struct regmap *regmap;
 	struct mutex lock;
 	u8 range_idx;
+	struct iio_trigger *trig;
 	struct {
 		s8 chans[3];
 		/* Ensure timestamp is naturally aligned. */
@@ -191,6 +193,22 @@ const struct regmap_config bma220_i2c_regmap_config = {
 };
 EXPORT_SYMBOL_NS_GPL(bma220_i2c_regmap_config, "IIO_BOSCH_BMA220");
 
+static int bma220_data_rdy_trigger_set_state(struct iio_trigger *trig,
+					     bool state)
+{
+	struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
+	struct bma220_data *data = iio_priv(indio_dev);
+
+	return regmap_update_bits(data->regmap, BMA220_REG_IE0,
+				  BMA220_INT_EN_DRDY_MSK,
+				  FIELD_PREP(BMA220_INT_EN_DRDY_MSK, state));
+}
+
+static const struct iio_trigger_ops bma220_trigger_ops = {
+	.set_trigger_state = &bma220_data_rdy_trigger_set_state,
+	.validate_device = &iio_trigger_validate_own_device,
+};
+
 static irqreturn_t bma220_trigger_handler(int irq, void *p)
 {
 	int ret;
@@ -413,6 +431,23 @@ static void bma220_deinit(void *data_ptr)
 			 ERR_PTR(ret));
 }
 
+static irqreturn_t bma220_irq_handler(int irq, void *private)
+{
+	struct iio_dev *indio_dev = private;
+	struct bma220_data *data = iio_priv(indio_dev);
+	int ret;
+	unsigned int bma220_reg_if1;
+
+	ret = regmap_read(data->regmap, BMA220_REG_IF1, &bma220_reg_if1);
+	if (ret)
+		return IRQ_NONE;
+
+	if (FIELD_GET(BMA220_IF_DRDY, bma220_reg_if1))
+		iio_trigger_poll_nested(data->trig);
+
+	return IRQ_HANDLED;
+}
+
 int bma220_common_probe(struct device *dev, struct regmap *regmap, int irq)
 {
 	int ret;
@@ -441,6 +476,29 @@ int bma220_common_probe(struct device *dev, struct regmap *regmap, int irq)
 	indio_dev->num_channels = ARRAY_SIZE(bma220_channels);
 	indio_dev->available_scan_masks = bma220_accel_scan_masks;
 
+	if (irq > 0) {
+		data->trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
+						    indio_dev->name,
+						    iio_device_id(indio_dev));
+		if (!data->trig)
+			return -ENOMEM;
+
+		data->trig->ops = &bma220_trigger_ops;
+		iio_trigger_set_drvdata(data->trig, indio_dev);
+
+		ret = devm_iio_trigger_register(dev, data->trig);
+		if (ret)
+			return dev_err_probe(dev, ret,
+					     "iio trigger register fail\n");
+		indio_dev->trig = iio_trigger_get(data->trig);
+		ret = devm_request_threaded_irq(dev, irq, NULL,
+						&bma220_irq_handler, IRQF_ONESHOT,
+						indio_dev->name, indio_dev);
+		if (ret)
+			return dev_err_probe(dev, ret,
+					     "request irq %d failed\n", irq);
+	}
+
 	ret = devm_add_action_or_reset(dev, bma220_deinit, data);
 	if (ret)
 		return ret;

-- 
2.49.1


  parent reply	other threads:[~2025-10-05 13:13 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-05 13:12 [PATCH v4 00/19] iio: accel: bma220 improvements Petre Rodan
2025-10-05 13:12 ` [PATCH v4 01/19] iio: accel: bma220: remove incorrect kernel-doc marking Petre Rodan
2025-10-12 14:21   ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 02/19] iio: accel: bma220: relax constraints during probe() Petre Rodan
2025-10-12 14:22   ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 03/19] iio: accel: bma220: cleanup license string Petre Rodan
2025-10-12 14:22   ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 04/19] iio: accel: bma220: shorten spi->dev calls Petre Rodan
2025-10-12 14:23   ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 05/19] iio: accel: bma220: move bma220_power function Petre Rodan
2025-10-12 14:24   ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 06/19] iio: accel: bma220: cleanup includes Petre Rodan
2025-10-12 14:25   ` Jonathan Cameron
2025-10-12 14:34   ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 07/19] iio: accel: bma220: split original driver Petre Rodan
2025-10-12 14:52   ` Jonathan Cameron
2025-10-14 16:52     ` Petre Rodan
2025-10-05 13:12 ` [PATCH v4 08/19] iio: accel: bma220: add open firmware table Petre Rodan
2025-10-12 14:54   ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 09/19] iio: accel: bma220: turn power supplies on Petre Rodan
2025-10-12 14:55   ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 10/19] iio: accel: bma220: reset registers during init stage Petre Rodan
2025-10-12 14:56   ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 11/19] iio: accel: bma220: migrate to regmap API Petre Rodan
2025-10-12 15:04   ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 12/19] iio: accel: bma220: populate buffer ts in trigger handler Petre Rodan
2025-10-12 15:06   ` Jonathan Cameron
2025-10-12 20:54     ` Petre Rodan
2025-10-05 13:12 ` [PATCH v4 13/19] iio: accel: bma220: use find_match_table fct Petre Rodan
2025-10-12 15:20   ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 14/19] iio: accel: bma220: add i2c module Petre Rodan
2025-10-12 15:17   ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 15/19] iio: accel: bma220: add i2c watchdog feature Petre Rodan
2025-10-12 15:20   ` Jonathan Cameron
2025-10-05 13:12 ` Petre Rodan [this message]
2025-10-12 15:21   ` [PATCH v4 16/19] iio: accel: bma220: add interrupt trigger Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 17/19] iio: accel: bma220: add LPF cut-off frequency mapping Petre Rodan
2025-10-12 15:23   ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 18/19] iio: accel: bma220: add debugfs reg access Petre Rodan
2025-10-12 15:24   ` Jonathan Cameron
2025-10-05 13:12 ` [PATCH v4 19/19] iio: accel: bma220: add maintainer Petre Rodan
2025-10-12 15:24   ` 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=20251005-b4-bma220_improvements-v4-16-0f449ba31585@subdimension.ro \
    --to=petre.rodan@subdimension.ro \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=andy@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=robh@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;
as well as URLs for NNTP newsgroup(s).