Re: [PATCH 2/3] iio: imu: bmi270: add step counter watermark event

From: Andy Shevchenko
Date: Fri Apr 25 2025 - 00:34:23 EST


On Fri, Apr 25, 2025 at 3:15 AM Gustavo Silva <gustavograzs@xxxxxxxxx> wrote:
>
> Add support for generating events when the step counter reaches the
> configurable watermark.

With the below being addressed,
Reviewed-by: Andy Shevchenko <andy@xxxxxxxxxx>

...

> +static int bmi270_write_event_config(struct iio_dev *indio_dev,
> + const struct iio_chan_spec *chan,
> + enum iio_event_type type,
> + enum iio_event_direction dir, bool state)
> +{
> + struct bmi270_data *data = iio_priv(indio_dev);
> +
> + switch (type) {
> + case IIO_EV_TYPE_CHANGE:
> + return bmi270_step_wtrmrk_en(data, state);
> + default:
> + return -EINVAL;
> + }

> +
> + return 0;

Dead code.

> +}

...

> + switch (type) {
> + case IIO_EV_TYPE_CHANGE:

> + if (!in_range(val, 0, 20461))

I prefer that + 1 to be separated and the value defined.

(0, _FOO + 1)

> + return -EINVAL;

> + raw = val / 20;

Needs a comment. Is this in the Datasheet? Then reference to the
section / table / formula would be nice to have.

> + return bmi270_update_feature_reg(data, BMI270_SC_26_REG,
> + BMI270_STEP_SC26_WTRMRK_MSK,
> + FIELD_PREP(BMI270_STEP_SC26_WTRMRK_MSK,
> + raw));
> + default:
> + return -EINVAL;
> + }

...

> + raw = FIELD_GET(BMI270_STEP_SC26_WTRMRK_MSK, reg_val);
> + *val = raw * 20;

Same.

> + return IIO_VAL_INT;


--
With Best Regards,
Andy Shevchenko