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,
"Lothar Rubusch" <l.rubusch@gmail.com>
Subject: Re: [PATCH v2 3/3] iio: imu: bmi270: add support for motion events
Date: Sat, 7 Jun 2025 17:02:37 +0100 [thread overview]
Message-ID: <20250607170237.77601f20@jic23-huawei> (raw)
In-Reply-To: <20250605-bmi270-events-v2-3-8b2c07d0c213@gmail.com>
On Thu, 05 Jun 2025 19:05:03 -0300
Gustavo Silva <gustavograzs@gmail.com> wrote:
> Any-motion event can be enabled on a per-axis basis and triggers a
> combined event when motion is detected on any axis.
>
> No-motion event is triggered if the rate of change on all axes falls
> below a specified threshold for a configurable duration. A fake channel
> is used to report this event.
>
> Threshold and duration can be configured from userspace.
>
> Signed-off-by: Gustavo Silva <gustavograzs@gmail.com>
Hi Gustavo,
A few minor comments inline. +CC Lothar given they have been doing a lot of
work with similar events recently and might have time to take a look at this
and see if I'm missing anything wrt to consistency with our recent discussions.
> ---
> drivers/iio/imu/bmi270/bmi270_core.c | 318 ++++++++++++++++++++++++++++++++++-
> 1 file changed, 309 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/iio/imu/bmi270/bmi270_core.c b/drivers/iio/imu/bmi270/bmi270_core.c
> index 0798eb1da3ecc3cecaf7d7d47214bb07f4ec294f..eb0cada50087ccecfd5624a531692873e396deb6 100644
> --- a/drivers/iio/imu/bmi270/bmi270_core.c
> +++ b/drivers/iio/imu/bmi270/bmi270_core.c
...
> @@ -881,10 +1086,17 @@ static int bmi270_write_event_value(struct iio_dev *indio_dev,
> {
> struct bmi270_data *data = iio_priv(indio_dev);
> unsigned int raw;
> + int reg;
>
> guard(mutex)(&data->mutex);
>
> switch (type) {
> + case IIO_EV_TYPE_MAG_ADAPTIVE:
> + reg = BMI270_ANYMO1_REG;
> + break;
> + case IIO_EV_TYPE_ROC:
> + reg = BMI270_NOMO1_REG;
> + break;
> case IIO_EV_TYPE_CHANGE:
> if (!in_range(val, 0, BMI270_STEP_COUNTER_MAX + 1))
> return -EINVAL;
> @@ -897,6 +1109,31 @@ static int bmi270_write_event_value(struct iio_dev *indio_dev,
> default:
> return -EINVAL;
> }
> +
> + switch (info) {
> + case IIO_EV_INFO_VALUE:
> + if (!in_range(val, 0, 1))
> + return -EINVAL;
> +
> + raw = BMI270_INT_MICRO_TO_RAW(val, val2,
> + BMI270_MOTION_THRES_SCALE);
> + return bmi270_update_feature_reg(data, reg,
> + BMI270_FEAT_MOTION_THRESHOLD_MSK,
> + FIELD_PREP(BMI270_FEAT_MOTION_THRESHOLD_MSK,
> + raw));
This is some usual indenting. Use a local variable for the value and
maybe the mask as well just to keep it readable.
> + case IIO_EV_INFO_PERIOD:
> + if (!in_range(val, 0, BMI270_MOTION_DURAT_MAX + 1))
> + return -EINVAL;
> +
> + raw = BMI270_INT_MICRO_TO_RAW(val, val2,
> + BMI270_MOTION_DURAT_SCALE);
Align after (
> + return bmi270_update_feature_reg(data, reg,
> + BMI270_FEAT_MOTION_DURATION_MSK,
> + FIELD_PREP(BMI270_FEAT_MOTION_DURATION_MSK,
> + raw));
As above.
> + default:
> + return -EINVAL;
> + }
> }
>
> static const struct iio_event_spec bmi270_step_wtrmrk_event = {
> @@ -934,6 +1200,22 @@ static const struct iio_event_spec bmi270_step_wtrmrk_event = {
> BIT(IIO_EV_INFO_VALUE),
> };
>
> +static const struct iio_event_spec bmi270_anymotion_event = {
> + .type = IIO_EV_TYPE_MAG_ADAPTIVE,
> + .dir = IIO_EV_DIR_RISING,
> + .mask_separate = BIT(IIO_EV_INFO_ENABLE),
> + .mask_shared_by_type = BIT(IIO_EV_INFO_VALUE) |
> + BIT(IIO_EV_INFO_PERIOD),
As below.
> +};
> +
> +static const struct iio_event_spec bmi270_nomotion_event = {
> + .type = IIO_EV_TYPE_ROC,
> + .dir = IIO_EV_DIR_RISING,
> + .mask_separate = BIT(IIO_EV_INFO_ENABLE),
> + .mask_shared_by_type = BIT(IIO_EV_INFO_VALUE) |
> + BIT(IIO_EV_INFO_PERIOD),
Could make that one line as I think it's 80 chars exactly.
I don't mind that much though.
next prev parent reply other threads:[~2025-06-07 16:02 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-05 22:05 [PATCH v2 0/3] BMI270: Add support for step counter and motion events Gustavo Silva
2025-06-05 22:05 ` [PATCH v2 1/3] iio: imu: bmi270: add channel for step counter Gustavo Silva
2025-06-06 7:43 ` kernel test robot
2025-06-06 9:14 ` Andy Shevchenko
2025-06-07 15:50 ` Jonathan Cameron
2025-06-08 20:03 ` Andy Shevchenko
2025-06-05 22:05 ` [PATCH v2 2/3] iio: imu: bmi270: add step counter watermark event Gustavo Silva
2025-06-07 15:54 ` Jonathan Cameron
2025-06-05 22:05 ` [PATCH v2 3/3] iio: imu: bmi270: add support for motion events Gustavo Silva
2025-06-07 16:02 ` Jonathan Cameron [this message]
2025-06-17 7:28 ` Lothar Rubusch
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=20250607170237.77601f20@jic23-huawei \
--to=jic23@kernel.org \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=gustavograzs@gmail.com \
--cc=l.rubusch@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