Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Gustavo Silva <gustavograzs@gmail.com>
Cc: "Alex Lanzano" <lanzano.alex@gmail.com>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/3] iio: imu: bmi270: add step counter watermark event
Date: Sat, 26 Apr 2025 14:47:39 +0100	[thread overview]
Message-ID: <20250426144739.31b8bd36@jic23-huawei> (raw)
In-Reply-To: <20250424-bmi270-events-v1-2-a6c722673e5f@gmail.com>

On Thu, 24 Apr 2025 21:14:51 -0300
Gustavo Silva <gustavograzs@gmail.com> wrote:

> Add support for generating events when the step counter reaches the
> configurable watermark.
> 
> Signed-off-by: Gustavo Silva <gustavograzs@gmail.com>

Main thing in here is I think the event type isn't the right one.

> @@ -119,6 +128,7 @@ struct bmi270_data {
>  	 /* Protect device's private data from concurrent access */
>  	struct mutex mutex;
>  	int steps_enabled;
> +	unsigned int feature_events;

Why do we need this rather than just checking the register?


> +
> +static int bmi270_step_wtrmrk_en(struct bmi270_data *data, bool state)
> +{
> +	int ret, reg, field_value;
> +
> +	guard(mutex)(&data->mutex);
> +	if (!data->steps_enabled)
> +		return -EINVAL;
> +
> +	reg = bmi270_int_map_reg(data->irq_pin);
> +	if (reg < 0)
> +		return -EINVAL;
> +
> +	field_value = FIELD_PREP(BMI270_INT_MAP_FEAT_STEP_CNT_WTRMRK_MSK, state);
> +	ret = regmap_update_bits(data->regmap, reg,
> +				 BMI270_INT_MAP_FEAT_STEP_CNT_WTRMRK_MSK,
> +				 field_value);
> +	if (ret)
> +		return ret;
> +
> +	set_mask_bits(&data->feature_events,
> +		      BMI270_INT_MAP_FEAT_STEP_CNT_WTRMRK_MSK, field_value);

Given we wrote the register, why do we need a cached value?  Can't we just read
it back again (or rely on a regmap cache for it if enabled in this driver)

> +	return 0;
> +}
> +
>  static int bmi270_set_scale(struct bmi270_data *data, int chan_type, int uscale)
>  {
>  	int i;
> @@ -539,19 +585,32 @@ static irqreturn_t bmi270_irq_thread_handler(int irq, void *private)
>  {
>  	struct iio_dev *indio_dev = private;
>  	struct bmi270_data *data = iio_priv(indio_dev);
> -	unsigned int status;
> +	unsigned int status0, status1;
> +	s64 timestamp = iio_get_time_ns(indio_dev);
>  	int ret;
>  
>  	scoped_guard(mutex, &data->mutex) {
> +		ret = regmap_read(data->regmap, BMI270_INT_STATUS_0_REG,
> +				  &status0);
> +		if (ret)
> +			return IRQ_NONE;
> +
>  		ret = regmap_read(data->regmap, BMI270_INT_STATUS_1_REG,
> -				  &status);
> +				  &status1);
>  		if (ret)
>  			return IRQ_NONE;
>  	}
>  
> -	if (FIELD_GET(BMI270_INT_STATUS_1_ACC_GYR_DRDY_MSK, status))
> +	if (FIELD_GET(BMI270_INT_STATUS_1_ACC_GYR_DRDY_MSK, status1))
>  		iio_trigger_poll_nested(data->trig);
>  
> +	if (FIELD_GET(BMI270_INT_STATUS_0_STEP_CNT_MSK, status0))
> +		iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_STEPS, 0,
> +							     IIO_NO_MOD,
why use IIO_MOD_EVENT_CODE() if not modified?

> +							     IIO_EV_TYPE_CHANGE,
> +							     IIO_EV_DIR_NONE),
As below. This looks like a rising threshold event.

Change tends to be for things like activity detection (walking/standing etc)
 
> +			       timestamp);
> +
>  	return IRQ_HANDLED;
>  }
>  
> @@ -761,10 +820,111 @@ static int bmi270_read_avail(struct iio_dev *indio_dev,
>  	}
>  }
>
> +
> +static const struct iio_event_spec bmi270_step_wtrmrk_event = {
> +	.type = IIO_EV_TYPE_CHANGE,

Change would be a per step event.
IIUC this is a rising threshold.

> +	.dir = IIO_EV_DIR_NONE,
> +	.mask_shared_by_type = BIT(IIO_EV_INFO_ENABLE) |
> +			       BIT(IIO_EV_INFO_VALUE),
> +};



  parent reply	other threads:[~2025-04-26 13:47 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-25  0:14 [PATCH 0/3] BMI270: Add support for step counter and motion events Gustavo Silva
2025-04-25  0:14 ` [PATCH 1/3] iio: imu: bmi270: add channel for step counter Gustavo Silva
2025-04-25  4:28   ` Andy Shevchenko
2025-04-26 13:40   ` Jonathan Cameron
2025-04-27  0:19     ` Gustavo Silva
2025-05-05 13:13       ` Jonathan Cameron
2025-05-07 10:35   ` kernel test robot
2025-04-25  0:14 ` [PATCH 2/3] iio: imu: bmi270: add step counter watermark event Gustavo Silva
2025-04-25  4:33   ` Andy Shevchenko
2025-04-26 23:01     ` Gustavo Silva
2025-04-26 13:47   ` Jonathan Cameron [this message]
2025-04-27  0:57     ` Gustavo Silva
2025-05-05 13:21       ` Jonathan Cameron
2025-04-25  0:14 ` [PATCH 3/3] iio: imu: bmi270: add support for motion events Gustavo Silva
2025-04-25  5:25   ` Andy Shevchenko
2025-04-26 23:06     ` Gustavo Silva
2025-04-26 14:12   ` 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=20250426144739.31b8bd36@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=gustavograzs@gmail.com \
    --cc=lanzano.alex@gmail.com \
    --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