public inbox for devicetree@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Petre Rodan <petre.rodan@subdimension.ro>
Cc: "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>,
	"Jonathan Cameron" <Jonathan.Cameron@huawei.com>,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 15/18] iio: accel: bma220: add interrupt trigger
Date: Sat, 27 Sep 2025 15:12:48 +0100	[thread overview]
Message-ID: <20250927151248.6c784f7c@jic23-huawei> (raw)
In-Reply-To: <20250913-b4-bma220_improvements-v3-15-0b97279b4e45@subdimension.ro>

On Sat, 13 Sep 2025 18:39:36 +0300
Petre Rodan <petre.rodan@subdimension.ro> wrote:

> Add interrupt trigger.
> 
> Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
Hi Petre

A few lock questions from a fresh look.
Sorry for delay - busy few weeks and a few days lain up in bed with
a cold.

> ---
> 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)
> ---
>  drivers/iio/accel/bma220_core.c | 61 +++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 61 insertions(+)
> 
> diff --git a/drivers/iio/accel/bma220_core.c b/drivers/iio/accel/bma220_core.c
> index 425a8b981e141aa496351f29df0597c989aa4a0a..6297882bcf1b955291a2d8747984648bc6ee8512 100644
> --- a/drivers/iio/accel/bma220_core.c
> +++ b/drivers/iio/accel/bma220_core.c
> @@ -23,6 +23,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>
>  
> @@ -125,6 +126,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. */
> @@ -193,6 +195,23 @@ 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);
> +
> +	guard(mutex)(&data->lock);

What is this lock protecting? 

> +	return regmap_update_bits(data->regmap, BMA220_REG_IE0,
> +				  BMA220_INT_EN_DRDY_MSK,
> +				  FIELD_PREP(BMA220_INT_EN_DRDY_MSK, state));
> +}

> @@ -417,6 +436,24 @@ 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 rv;
> +	unsigned int bma220_reg_if1;
> +
> +	guard(mutex)(&data->lock);

What is the lock protecting here?  The internal locks in regmap
superficially look like they'd be enough given we only have a single
read.  I'd expect any necessary locking to be on the otherside
of that use of the iio trigger framework (so the poll function thread).

> +	rv = regmap_read(data->regmap, BMA220_REG_IF1, &bma220_reg_if1);
> +	if (rv)
> +		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;
> @@ -446,6 +483,30 @@ 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_TRIGGER_RISING | IRQF_ONESHOT,
Interrupt polarity should be coming from firmware.

It's a historically common mistake to encode it in the driver as it breaks
fairly standard things like using an inverter as a cheap level converter
in front of the interrupt pin.

So IRQF_ONEHSOT only should be all that is needed here.

> +						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;
> 


  parent reply	other threads:[~2025-09-27 14:12 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-13 15:39 [PATCH v3 00/18] iio: accel: bma220 improvements Petre Rodan
2025-09-13 15:39 ` [PATCH v3 01/18] dt-bindings: iio: accel: bosch,bma220 cleanup typo Petre Rodan
2025-09-13 15:39 ` [PATCH v3 02/18] dt-bindings: iio: accel: bosch,bma220 setup SPI clock mode Petre Rodan
2025-09-13 15:39 ` [PATCH v3 03/18] dt-bindings: iio: accel: bosch,bma220 set irq type in example block Petre Rodan
2025-09-18  2:08   ` Krzysztof Kozlowski
2025-09-27 14:00     ` Jonathan Cameron
2025-09-13 15:39 ` [PATCH v3 04/18] iio: accel: bma220: split original driver Petre Rodan
2025-09-14 12:45   ` Andy Shevchenko
2025-09-15  5:05     ` Petre Rodan
2025-09-13 15:39 ` [PATCH v3 05/18] iio: accel: bma220: add open firmware table Petre Rodan
2025-09-13 15:39 ` [PATCH v3 06/18] iio: accel: bma220: turn power supplies on Petre Rodan
2025-09-14 12:04   ` Andy Shevchenko
2025-09-13 15:39 ` [PATCH v3 07/18] iio: accel: bma220: move bma220_power() fct Petre Rodan
2025-09-14 12:05   ` Andy Shevchenko
2025-09-27 14:04     ` Jonathan Cameron
2025-09-13 15:39 ` [PATCH v3 08/18] iio: accel: bma220: reset registers during init stage Petre Rodan
2025-09-14 12:07   ` Andy Shevchenko
2025-09-13 15:39 ` [PATCH v3 09/18] iio: accel: bma220: relax constraints during probe() Petre Rodan
2025-09-14 12:13   ` Andy Shevchenko
2025-09-13 15:39 ` [PATCH v3 10/18] iio: accel: bma220: migrate to regmap API Petre Rodan
2025-09-14 12:21   ` Andy Shevchenko
2025-09-15  5:49     ` Petre Rodan
2025-09-13 15:39 ` [PATCH v3 11/18] iio: accel: bma220: populate buffer ts in trigger handler Petre Rodan
2025-09-27 14:07   ` Jonathan Cameron
2025-09-13 15:39 ` [PATCH v3 12/18] iio: accel: bma220: use find_match_table fct Petre Rodan
2025-09-13 15:39 ` [PATCH v3 13/18] iio: accel: bma220: add i2c module Petre Rodan
2025-09-13 15:39 ` [PATCH v3 14/18] iio: accel: bma220: add i2c watchdog feature Petre Rodan
2025-09-13 15:39 ` [PATCH v3 15/18] iio: accel: bma220: add interrupt trigger Petre Rodan
2025-09-13 16:32   ` Petre Rodan
2025-09-14 12:09     ` Andy Shevchenko
2025-09-13 18:12   ` kernel test robot
2025-09-14 12:12   ` Andy Shevchenko
2025-09-27 14:12   ` Jonathan Cameron [this message]
2025-09-13 15:39 ` [PATCH v3 16/18] iio: accel: bma220: add LPF cut-off frequency mapping Petre Rodan
2025-09-13 15:39 ` [PATCH v3 17/18] iio: accel: bma220: add debugfs reg access Petre Rodan
2025-09-13 15:39 ` [PATCH v3 18/18] iio: accel: bma220: add maintainer Petre Rodan

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=20250927151248.6c784f7c@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=andy@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=petre.rodan@subdimension.ro \
    --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