On Sun, 1 Jun 2025 17:21:36 +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> > @@ -555,16 +621,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) { > + case IIO_EV_INFO_VALUE: > + /* 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); > + 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) > return ret; > return adxl313_set_measure_en(data, true); Having the enable in the case statement but he disable outside is misbalanced. Do it one way or the other (either always disable / enable outside, or both inside each relevant case statement. If we need to do this, I'd have a helper function do_adxl313_write_event_value() or similar that is called between disabling and enabling measurement mode and contains all the other stuff in this function (or along those lines anyway). You can chose whether or not to reenable measurement mode depending on what is returned by the helper function.