From: Francesco Lavra <flavra@baylibre.com>
To: "Ramona Gradinariu" <ramona.gradinariu@analog.com>,
"Antoniu Miclaus" <antoniu.miclaus@analog.com>,
"Lars-Peter Clausen" <lars@metafoo.de>,
"Michael Hennerich" <Michael.Hennerich@analog.com>,
"Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 2/3] iio: accel: adxl380: Introduce helper function for activity detection
Date: Thu, 15 Jan 2026 18:53:49 +0100 [thread overview]
Message-ID: <20260115175350.1045887-3-flavra@baylibre.com> (raw)
In-Reply-To: <20260115175350.1045887-1-flavra@baylibre.com>
Motion detection functionalities (such as activity and inactivity
detection) are only available when the chip is in a low-power mode; this
affects the available sampling frequency values.
In preparation for adding support for a new frequency value, introduce a
helper function that checks whether activity/inactivity detection is
currently enabled; this function will be reused in a future commit to
determine what frequency values are available at any given time.
No functional changes.
Signed-off-by: Francesco Lavra <flavra@baylibre.com>
---
drivers/iio/accel/adxl380.c | 27 ++++++++++++++++++++++-----
1 file changed, 22 insertions(+), 5 deletions(-)
diff --git a/drivers/iio/accel/adxl380.c b/drivers/iio/accel/adxl380.c
index bbf1f88ca781..b99458a5eae3 100644
--- a/drivers/iio/accel/adxl380.c
+++ b/drivers/iio/accel/adxl380.c
@@ -232,14 +232,33 @@ bool adxl380_readable_noinc_reg(struct device *dev, unsigned int reg)
}
EXPORT_SYMBOL_NS_GPL(adxl380_readable_noinc_reg, "IIO_ADXL380");
+static int adxl380_act_inact_enabled(struct adxl380_state *st, bool *enabled)
+{
+ unsigned int act_inact_ctl;
+ int ret;
+
+ if (!st->chip_info->has_low_power) {
+ *enabled = false;
+ return 0;
+ }
+
+ ret = regmap_read(st->regmap, ADXL380_ACT_INACT_CTL_REG, &act_inact_ctl);
+ if (!ret)
+ *enabled = FIELD_GET(ADXL380_ACT_EN_MSK, act_inact_ctl) ||
+ FIELD_GET(ADXL380_INACT_EN_MSK, act_inact_ctl);
+
+ return ret;
+}
+
static int adxl380_set_measure_en(struct adxl380_state *st, bool en)
{
int ret;
- unsigned int act_inact_ctl;
u8 op_mode = ADXL380_OP_MODE_STANDBY;
if (en) {
- ret = regmap_read(st->regmap, ADXL380_ACT_INACT_CTL_REG, &act_inact_ctl);
+ bool act_inact_enabled;
+
+ ret = adxl380_act_inact_enabled(st, &act_inact_enabled);
if (ret)
return ret;
@@ -248,9 +267,7 @@ static int adxl380_set_measure_en(struct adxl380_state *st, bool en)
* mode and for devices that support low power modes. Otherwise
* go straight to measure mode (same bits as ADXL380_OP_MODE_HP).
*/
- if (st->chip_info->has_low_power &&
- (FIELD_GET(ADXL380_ACT_EN_MSK, act_inact_ctl) ||
- FIELD_GET(ADXL380_INACT_EN_MSK, act_inact_ctl)))
+ if (act_inact_enabled)
op_mode = ADXL380_OP_MODE_VLP;
else
op_mode = ADXL380_OP_MODE_HP;
--
2.39.5
next prev parent reply other threads:[~2026-01-15 17:53 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-15 17:53 [PATCH v2 0/3] accel: adxl380: Add support for 1 kHz sampling frequency Francesco Lavra
2026-01-15 17:53 ` [PATCH v2 1/3] iio: accel: adxl380: Store sampling frequency index in odr struct member Francesco Lavra
2026-01-15 17:53 ` Francesco Lavra [this message]
2026-01-15 20:28 ` [PATCH v2 2/3] iio: accel: adxl380: Introduce helper function for activity detection Andy Shevchenko
2026-01-16 19:32 ` Jonathan Cameron
2026-01-15 17:53 ` [PATCH v2 3/3] iio: accel: adxl380: Add support for 1 kHz sampling frequency Francesco Lavra
2026-01-16 19:42 ` Jonathan Cameron
2026-01-16 19:43 ` [PATCH v2 0/3] " 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=20260115175350.1045887-3-flavra@baylibre.com \
--to=flavra@baylibre.com \
--cc=Michael.Hennerich@analog.com \
--cc=andy@kernel.org \
--cc=antoniu.miclaus@analog.com \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=ramona.gradinariu@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
all inboxes | Powered by JetHome®