[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHp75VemOXhpRp2hfDhvzi3y5j5oL-_0xMmWRWkwEtX7Ks5nMQ@mail.gmail.com>
Date: Sun, 1 Jun 2025 22:38:01 +0300
From: Andy Shevchenko <andy.shevchenko@...il.com>
To: Lothar Rubusch <l.rubusch@...il.com>
Cc: jic23@...nel.org, dlechner@...libre.com, nuno.sa@...log.com,
andy@...nel.org, corbet@....net, lucas.p.stankus@...il.com, lars@...afoo.de,
Michael.Hennerich@...log.com, bagasdotme@...il.com, linux-iio@...r.kernel.org,
linux-doc@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v4 07/11] iio: accel: adxl313: add activity sensing
On Sun, Jun 1, 2025 at 8:22 PM Lothar Rubusch <l.rubusch@...il.com> wrote:
>
> Add possibilities to set a threshold for activity sensing. Extend the
> interrupt handler to process activity interrupts. Provide functions to set
> the activity threshold and to enable/disable activity sensing. Further add
> a fake channel for having x, y and z axis anded on the iio channel.
IIO
And what does the 'anded' mean?
> This is a preparatory patch. Some of the definitions and functions are
> supposed to be extended for inactivity later on.
...
> +static int adxl313_is_act_inact_en(struct adxl313_data *data,
> + enum adxl313_activity_type type)
> +{
> + unsigned int axis_ctrl;
> + unsigned int regval;
> + int axis_en, int_en, ret;
> +
> + ret = regmap_read(data->regmap, ADXL313_REG_ACT_INACT_CTL, &axis_ctrl);
> + if (ret)
> + return ret;
> +
> + /* Check if axis for activity are enabled */
> + if (type != ADXL313_ACTIVITY)
> + return 0;
> +
> + axis_en = FIELD_GET(ADXL313_ACT_XYZ_EN, axis_ctrl);
If it's false, it will be false anyway. No need to defer the check:
if (!axis_en)
return false;
> + /* The axis are enabled, now check if specific interrupt is enabled */
> + ret = regmap_read(data->regmap, ADXL313_REG_INT_ENABLE, ®val);
> + if (ret)
> + return ret;
> +
> + int_en = adxl313_act_int_reg[type] & regval;
> +
> + return axis_en && int_en;
return ... & regval;
> +}
I have already commented on this a couple of times.
...
> + /* Scale factor 15.625 mg/LSB */
> + regval = DIV_ROUND_CLOSEST(MICRO * val + val2, 15625);
I would rather do
val * MICRO + val2
which is read more naturally (we will easily get that the expression
uses MICRO scale).
...
> + int ret = -ENOENT;
> +
> + if (FIELD_GET(ADXL313_INT_ACTIVITY, int_stat)) {
> + ret = iio_push_event(indio_dev,
> + IIO_MOD_EVENT_CODE(IIO_ACCEL, 0,
> + IIO_MOD_X_OR_Y_OR_Z,
> + IIO_EV_TYPE_MAG,
> + IIO_EV_DIR_RISING),
> + ts);
> + if (ret)
> + return ret;
> + }
>
> if (FIELD_GET(ADXL313_INT_WATERMARK, int_stat)) {
> samples = adxl313_get_samples(data);
> if (samples < 0)
> return samples;
>
> - return adxl313_fifo_push(indio_dev, samples);
> + ret = adxl313_fifo_push(indio_dev, samples);
This is not needed...
> }
>
> /* Return error if no event data was pushed to the IIO channel. */
> - return -ENOENT;
> + return ret;
...and this looks wrong.
Before the case was clear, if we have no respective bit set in the
int_stat, we return ENOENT. Now it depends on the other bit. If this
is correct behaviour, it needs a comment.
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists