Re: [PATCH v3 10/12] iio: accel: adxl313: add inactivity sensing
From: Jonathan Cameron
Date: Sun May 25 2025 - 09:11:31 EST
On Fri, 23 May 2025 22:35:21 +0000
Lothar Rubusch <l.rubusch@xxxxxxxxx> wrote:
> Extend the interrupt handler to process interrupts as inactivity events.
> Add functions to set threshold and period registers for inactivity. Add
> functions to enable / disable inactivity. Extend the fake iio channel to
> deal with inactivity events on x, y and z combined with AND.
>
> Signed-off-by: Lothar Rubusch <l.rubusch@xxxxxxxxx>
Hi Lothar, Comments inline.
> static const struct regmap_range adxl312_readable_reg_range[] = {
> @@ -254,6 +258,14 @@ static const struct iio_event_spec adxl313_fake_chan_events[] = {
> .mask_separate = BIT(IIO_EV_INFO_ENABLE),
> .mask_shared_by_type = BIT(IIO_EV_INFO_VALUE),
> },
> + {
> + /* inactivity */
Ah. I only noticed this here, but the axis for these two types of
detection should be different so awe shouldn't see them in a single
array of events.
> + .type = IIO_EV_TYPE_MAG,
> + .dir = IIO_EV_DIR_FALLING,
> + .mask_separate = BIT(IIO_EV_INFO_ENABLE),
> + .mask_shared_by_type = BIT(IIO_EV_INFO_VALUE) |
> + BIT(IIO_EV_INFO_PERIOD),
> + },
> };
> @@ -550,16 +606,30 @@ static int adxl313_write_event_value(struct iio_dev *indio_dev,
> if (type != IIO_EV_TYPE_MAG)
> return -EINVAL;
>
> - if (info != IIO_EV_INFO_VALUE)
> - return -EINVAL;
> -
> - /* Scale factor 15.625 mg/LSB */
> - regval = DIV_ROUND_CLOSEST(MICRO * val + val2, 15625);
> - switch (dir) {
> - case IIO_EV_DIR_RISING:
> - ret = regmap_write(data->regmap,
> - adxl313_act_thresh_reg[ADXL313_ACTIVITY],
> - regval);
> + switch (info) {
I got lost in earlier discussion you were having with Andy on this, but
personally, if a series is going to introduce a simple test then flip
it to a switch statement later, I'd rather see the switch statement from
the start and reduce the churn a little.
> + case IIO_EV_INFO_VALUE:
> + /* The scale factor is 15.625 mg/LSB */
> + regval = DIV_ROUND_CLOSEST(MICRO * val + val2, 15625);
> + switch (dir) {
> + case IIO_EV_DIR_RISING:
> + ret = regmap_write(data->regmap,
> + adxl313_act_thresh_reg[ADXL313_ACTIVITY],
> + regval);
> + if (ret)
> + return ret;
> + return adxl313_set_measure_en(data, true);
> + case IIO_EV_DIR_FALLING:
> + ret = regmap_write(data->regmap,
> + adxl313_act_thresh_reg[ADXL313_INACTIVITY],
> + regval);
> + if (ret)
> + return ret;
> + return adxl313_set_measure_en(data, true);
> + default:
> + return -EINVAL;
> + }
> + case IIO_EV_INFO_PERIOD:
> + ret = adxl313_set_inact_time_s(data, val);
> if (ret)