From: Jonathan Cameron <jic23@kernel.org>
To: Lothar Rubusch <l.rubusch@gmail.com>
Cc: lars@metafoo.de, Michael.Hennerich@analog.com,
dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org,
corbet@lwn.net, linux-iio@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
eraretuya@gmail.com
Subject: Re: [PATCH v9 08/11] iio: accel: adxl345: add inactivity feature
Date: Sat, 14 Jun 2025 15:00:24 +0100 [thread overview]
Message-ID: <20250614150024.09c5add4@jic23-huawei> (raw)
In-Reply-To: <20250610215933.84795-9-l.rubusch@gmail.com>
On Tue, 10 Jun 2025 21:59:30 +0000
Lothar Rubusch <l.rubusch@gmail.com> wrote:
> Add the inactivity feature of the sensor to the driver. When activity
> and inactivity are enabled, a link bit will be set linking activity and
> inactivity handling. Additionally, the auto-sleep mode will be enabled.
> Due to the link bit the sensor is going to auto-sleep when inactivity
> was detected.
>
> Inactivity detection needs a threshold to be configured and a period of
> time in seconds. After, it will transition to inactivity state, if
> measurements stay below inactivity threshold.
>
> When a ODR is configured the period for inactivity is adjusted with a
> corresponding reasonable default value, in order to have higher
> frequencies, lower inactivity times, and lower sample frequency but
> give more time until inactivity. Both with reasonable upper and lower
> boundaries, since many of the sensor's features (e.g. auto-sleep) will
> need to operate between 12.5 Hz and 400 Hz. This is a default setting
> when actively changing sample frequency, explicitly setting the time
> until inactivity will overwrite the default.
>
> Similarly, setting the g-range will provide a default value for the
> activity and inactivity thresholds. Both are implicit defaults, but
> equally can be overwritten to be explicitly configured.
>
> Signed-off-by: Lothar Rubusch <l.rubusch@gmail.com>
Just a few trivial comments from me.
J
> ---
> drivers/iio/accel/adxl345_core.c | 238 +++++++++++++++++++++++++++++--
> 1 file changed, 227 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c
> index 04b9f155872f..1670315ebd63 100644
> --- a/drivers/iio/accel/adxl345_core.c
> +++ b/drivers/iio/accel/adxl345_core.c
> @@ -334,12 +423,37 @@ static int adxl345_set_act_inact_en(struct adxl345_state *st,
> en = FIELD_GET(ADXL345_REG_ACT_AXIS_MSK, axis_ctrl) &&
> threshold;
> break;
> + case ADXL345_INACTIVITY:
> + ret = regmap_read(st->regmap, ADXL345_REG_TIME_INACT, &inact_time_s);
> + if (ret)
> + return ret;
> +
> + en = FIELD_GET(ADXL345_REG_INACT_AXIS_MSK, axis_ctrl) &&
> + threshold && inact_time_s;
> + break;
> default:
> return -EINVAL;
> }
>
> ret = regmap_assign_bits(st->regmap, ADXL345_REG_INT_ENABLE,
> - adxl345_act_int_reg[type], cmd_en && en);
> + adxl345_act_int_reg[type], cmd_en);
> + if (ret)
> + return ret;
> +
> + /* Set sleep and link bit when ACT and INACT are enabled. */
> + act_en = adxl345_is_act_inact_en(st, ADXL345_ACTIVITY);
> + if (act_en < 0)
> + return act_en;
> +
> + inact_en = adxl345_is_act_inact_en(st, ADXL345_INACTIVITY);
> + if (inact_en < 0)
> + return inact_en;
> +
> + en = en && act_en && inact_en;
> +
For consistency with above, I'd drop this blank line.
> + ret = regmap_assign_bits(st->regmap, ADXL345_REG_POWER_CTL,
> + (ADXL345_POWER_CTL_AUTO_SLEEP | ADXL345_POWER_CTL_LINK),
Not sure that inner set of brackets are adding anything much to readability.
> + en);
> if (ret)
> return ret;
>
> @@ -887,19 +1072,31 @@ static int adxl345_write_event_value(struct iio_dev *indio_dev,
> case IIO_EV_TYPE_MAG:
> switch (info) {
> case IIO_EV_INFO_VALUE:
> + val = DIV_ROUND_CLOSEST(val * MICRO + val2, 62500);
Put it here in the earlier patch. Though that might not makes sense when
you use some more helpers as Andy suggested. No one really likes 3 levels
of switch!
> switch (dir) {
> case IIO_EV_DIR_RISING:
> - val = DIV_ROUND_CLOSEST(val * MICRO + val2, 62500);
> ret = regmap_write(st->regmap,
> adxl345_act_thresh_reg[ADXL345_ACTIVITY],
> val);
> if (ret)
> return ret;
> break;
> + case IIO_EV_DIR_FALLING:
> + ret = regmap_write(st->regmap,
> + adxl345_act_thresh_reg[ADXL345_INACTIVITY],
> + val);
> + if (ret)
> + return ret;
> + break;
next prev parent reply other threads:[~2025-06-14 14:00 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-10 21:59 [PATCH v9 00/11] iio: accel: adxl345: add interrupt based sensor events Lothar Rubusch
2025-06-10 21:59 ` [PATCH v9 01/11] iio: accel: adxl345: apply scale factor to tap threshold Lothar Rubusch
2025-06-14 13:42 ` Jonathan Cameron
2025-06-15 22:20 ` Lothar Rubusch
2025-06-21 16:55 ` Jonathan Cameron
2025-06-21 18:14 ` Lothar Rubusch
2025-06-10 21:59 ` [PATCH v9 02/11] iio: accel: adxl345: make data struct variable irq function local Lothar Rubusch
2025-06-14 13:43 ` Jonathan Cameron
2025-06-10 21:59 ` [PATCH v9 03/11] iio: accel: adxl345: simplify measure enable Lothar Rubusch
2025-06-14 13:45 ` Jonathan Cameron
2025-06-10 21:59 ` [PATCH v9 04/11] iio: accel: adxl345: simplify interrupt mapping Lothar Rubusch
2025-06-11 15:20 ` Andy Shevchenko
2025-06-10 21:59 ` [PATCH v9 05/11] iio: accel: adxl345: simplify reading the FIFO Lothar Rubusch
2025-06-14 13:47 ` Jonathan Cameron
2025-06-15 22:14 ` Lothar Rubusch
2025-06-21 16:58 ` Jonathan Cameron
2025-06-10 21:59 ` [PATCH v9 06/11] iio: accel: adxl345: replace magic numbers by unit expressions Lothar Rubusch
2025-06-14 13:49 ` Jonathan Cameron
2025-06-10 21:59 ` [PATCH v9 07/11] iio: accel: adxl345: add activity event feature Lothar Rubusch
2025-06-12 11:51 ` Andy Shevchenko
2025-06-21 18:06 ` Lothar Rubusch
2025-06-21 19:55 ` Andy Shevchenko
2025-06-10 21:59 ` [PATCH v9 08/11] iio: accel: adxl345: add inactivity feature Lothar Rubusch
2025-06-12 12:15 ` Andy Shevchenko
2025-06-14 13:55 ` Jonathan Cameron
2025-06-14 19:02 ` Andy Shevchenko
2025-06-21 18:53 ` Lothar Rubusch
2025-06-21 19:24 ` Andy Shevchenko
2025-06-21 19:28 ` Andy Shevchenko
2025-06-14 14:00 ` Jonathan Cameron [this message]
2025-06-10 21:59 ` [PATCH v9 09/11] iio: accel: adxl345: add coupling detection for activity/inactivity Lothar Rubusch
2025-06-14 14:04 ` Jonathan Cameron
2025-06-10 21:59 ` [PATCH v9 10/11] iio: accel: adxl345: extend inactivity time for less than 1s Lothar Rubusch
2025-06-14 14:10 ` Jonathan Cameron
2025-06-10 21:59 ` [PATCH v9 11/11] docs: iio: add documentation for adxl345 driver Lothar Rubusch
2025-06-14 14:17 ` Jonathan Cameron
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=20250614150024.09c5add4@jic23-huawei \
--to=jic23@kernel.org \
--cc=Michael.Hennerich@analog.com \
--cc=andy@kernel.org \
--cc=corbet@lwn.net \
--cc=dlechner@baylibre.com \
--cc=eraretuya@gmail.com \
--cc=l.rubusch@gmail.com \
--cc=lars@metafoo.de \
--cc=linux-doc@vger.kernel.org \
--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