From: Jonathan Cameron <jic23@kernel.org>
To: Lothar Rubusch <l.rubusch@gmail.com>
Cc: lars@metafoo.de, Michael.Hennerich@analog.com,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
eraretuya@gmail.com
Subject: Re: [PATCH v7 09/11] iio: accel: adxl345: add inactivity feature
Date: Sun, 27 Apr 2025 13:38:47 +0100 [thread overview]
Message-ID: <20250427133847.6f3b164c@jic23-huawei> (raw)
In-Reply-To: <20250421220641.105567-10-l.rubusch@gmail.com>
On Mon, 21 Apr 2025 22:06:39 +0000
Lothar Rubusch <l.rubusch@gmail.com> wrote:
> Add the inactivity feature of the sensor. 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 time
> after which it will go into inactivity state if measurements under
> threshold.
>
> When a ODR is configured this time for inactivity is adjusted with a
> corresponding reasonable default value, in order to have higher
> frequencies and 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 beween 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>
Tweaked - see below for why. Please sanity check I didn't mess it up!
diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c
index dd8cea5c48f3..a61c97c086e9 100644
--- a/drivers/iio/accel/adxl345_core.c
+++ b/drivers/iio/accel/adxl345_core.c
@@ -241,16 +241,14 @@ static const struct iio_event_spec adxl345_all_event_spec[] = {
.mask_shared_by_type = BIT(IIO_EV_INFO_VALUE) |
BIT(IIO_EV_INFO_PERIOD),
},
-};
-
-/* inactivity */
-static const struct iio_event_spec adxl345_inactivity_event_spec = {
+ /* inactivity */
+ {
.type = IIO_EV_TYPE_THRESH,
.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),
-
+ BIT(IIO_EV_INFO_PERIOD),
+ },
};
static const struct iio_chan_spec adxl345_channels[] = {
@@ -265,14 +263,6 @@ static const struct iio_chan_spec adxl345_channels[] = {
.event_spec = adxl345_all_event_spec,
.num_event_specs = ARRAY_SIZE(adxl345_all_event_spec),
},
- {
- .type = IIO_ACCEL,
- .modified = 1,
- .channel2 = IIO_MOD_X_AND_Y_AND_Z,
- .scan_index = -1, /* Fake channel */
- .event_spec = &adxl345_inactivity_event_spec,
- .num_event_specs = 1,
- },
};
static const unsigned long adxl345_scan_masks[] = {
> ---
> drivers/iio/accel/adxl345_core.c | 172 ++++++++++++++++++++++++++++++-
> 1 file changed, 167 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c
> index 680981609d83..b25efcad069b 100644
> --- a/drivers/iio/accel/adxl345_core.c
> +++ b/drivers/iio/accel/adxl345_core.c
> @@ -37,11 +37,17 @@
>
> +/* inactivity */
> +static const struct iio_event_spec adxl345_inactivity_event_spec = {
> + .type = IIO_EV_TYPE_THRESH,
> + .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),
> +
> +};
> +
> static const struct iio_chan_spec adxl345_channels[] = {
> ADXL345_CHANNEL(0, chan_x, X),
> ADXL345_CHANNEL(1, chan_y, Y),
> @@ -244,6 +263,14 @@ static const struct iio_chan_spec adxl345_channels[] = {
> .event_spec = &adxl345_freefall_event_spec,
> .num_event_specs = 1,
> },
> + {
> + .type = IIO_ACCEL,
> + .modified = 1,
> + .channel2 = IIO_MOD_X_AND_Y_AND_Z,
> + .scan_index = -1, /* Fake channel */
> + .event_spec = &adxl345_inactivity_event_spec,
> + .num_event_specs = 1,
Why do we need a separate fake channel for this?
Should reuse the one that we have for freefall which has the same definition.
+ {
+ .type = IIO_ACCEL,
+ .modified = 1,
+ .channel2 = IIO_MOD_X_AND_Y_AND_Z,
+ .scan_index = -1, /* Fake channel */
+ .event_spec = &adxl345_freefall_event_spec,
+ .num_event_specs = 1,
+ },
> + },
> };
>
> static const unsigned long adxl345_scan_masks[] = {
> @@ -287,7 +314,8 @@ static int adxl345_set_measure_en(struct adxl345_state *st, bool en)
> {
> unsigned int val = en ? ADXL345_POWER_CTL_MEASURE : ADXL345_POWER_CTL_STANDBY;
>
> - return regmap_write(st->regmap, ADXL345_REG_POWER_CTL, val);
> + return regmap_update_bits(st->regmap, ADXL345_REG_POWER_CTL,
> + ADXL345_POWER_CTL_MEASURE, val);
> }
next prev parent reply other threads:[~2025-04-27 12:38 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-21 22:06 [PATCH v7 00/11] iio: accel: adxl345: add interrupt based sensor events Lothar Rubusch
2025-04-21 22:06 ` [PATCH v7 01/11] iio: accel: adxl345: introduce adxl345_push_event function Lothar Rubusch
2025-04-21 22:06 ` [PATCH v7 02/11] iio: accel: adxl345: add single tap feature Lothar Rubusch
2025-04-21 22:06 ` [PATCH v7 03/11] iio: accel: adxl345: add double " Lothar Rubusch
2025-04-21 22:06 ` [PATCH v7 04/11] iio: accel: adxl345: set the tap suppress bit permanently Lothar Rubusch
2025-04-27 12:21 ` Jonathan Cameron
2025-04-21 22:06 ` [PATCH v7 05/11] iio: accel: adxl345: add freefall feature Lothar Rubusch
2025-04-27 12:37 ` Jonathan Cameron
2025-04-21 22:06 ` [PATCH v7 06/11] iio: accel: adxl345: extend sample frequency adjustments Lothar Rubusch
2025-04-21 22:06 ` [PATCH v7 07/11] iio: accel: adxl345: add g-range configuration Lothar Rubusch
2025-04-27 12:37 ` Jonathan Cameron
2025-04-21 22:06 ` [PATCH v7 08/11] iio: accel: adxl345: add activity event feature Lothar Rubusch
2025-04-27 12:47 ` Jonathan Cameron
2025-04-30 22:53 ` Lothar Rubusch
2025-05-04 10:29 ` Jonathan Cameron
2025-05-04 17:47 ` Lothar Rubusch
2025-05-05 12:37 ` Jonathan Cameron
2025-05-06 22:37 ` Lothar Rubusch
2025-05-07 19:48 ` Jonathan Cameron
2025-05-07 21:40 ` Lothar Rubusch
2025-05-15 7:22 ` Jonathan Cameron
2025-04-21 22:06 ` [PATCH v7 09/11] iio: accel: adxl345: add inactivity feature Lothar Rubusch
2025-04-27 12:38 ` Jonathan Cameron [this message]
2025-04-27 12:49 ` Jonathan Cameron
2025-04-21 22:06 ` [PATCH v7 10/11] iio: accel: adxl345: add coupling detection for activity/inactivity Lothar Rubusch
2025-04-27 13:00 ` Jonathan Cameron
2025-05-01 7:35 ` Lothar Rubusch
2025-05-04 10:39 ` Jonathan Cameron
2025-05-07 20:04 ` Lothar Rubusch
2025-05-15 7:36 ` Jonathan Cameron
2025-04-21 22:06 ` [PATCH v7 11/11] docs: iio: add documentation for adxl345 driver Lothar Rubusch
2025-04-27 13:01 ` [PATCH v7 00/11] iio: accel: adxl345: add interrupt based sensor events 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=20250427133847.6f3b164c@jic23-huawei \
--to=jic23@kernel.org \
--cc=Michael.Hennerich@analog.com \
--cc=eraretuya@gmail.com \
--cc=l.rubusch@gmail.com \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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