From: Wenqiang Zhao <berringtoni36@gmail.com>
To: "Jonathan Cameron" <jic23@kernel.org>,
"Michael Hennerich" <Michael.Hennerich@analog.com>,
"Nuno Sá" <nuno.sa@analog.com>
Cc: David Lechner <dlechner@baylibre.com>,
Andy Shevchenko <andy@kernel.org>,
Lothar Rubusch <l.rubusch@gmail.com>,
linux@analog.com, linux-iio@vger.kernel.org,
linux-kernel@vger.kernel.org,
Wenqiang Zhao <berringtoni36@gmail.com>
Subject: [PATCH] iio: accel: adxl345: check ACT_INACT_CTRL for activity axes in IRQ
Date: Sun, 6 Dec 2026 18:05:13 +0800 [thread overview]
Message-ID: <20261206100513.89195-1-berringtoni36@gmail.com> (raw)
In adxl345_irq_handler(), checking whether to read the volatile
ADXL345_REG_ACT_TAP_STATUS (0x2B) register before ADXL345_REG_INT_SOURCE
clears the interrupt mistakenly tests ADXL345_ACT_XYZ_EN against
axis_ctrl, which was read from ADXL345_REG_TAP_AXIS (0x2A).
In the ADXL345 register map, ADXL345_REG_TAP_AXIS only contains tap axis
enable bits in bits 2:0 and TAP_SUPPRESS in bit 3, while bits 7:4 are
reserved and read as 0. The activity axis enable bits
(ADXL345_ACT_XYZ_EN, bits 6:4) reside in ADXL345_REG_ACT_INACT_CTRL
(0x27). As a result, FIELD_GET(ADXL345_ACT_XYZ_EN, axis_ctrl) always
evaluates to 0, so whenever activity detection is enabled without tap
detection, ADXL345_REG_ACT_TAP_STATUS is never read and pushed activity
events always carry IIO_NO_MOD instead of the triggering X/Y/Z axis.
Read ADXL345_REG_ACT_INACT_CTRL into a separate variable and check
ADXL345_ACT_XYZ_EN against it. ADXL345_REG_ACT_INACT_CTRL is non-volatile
and initialized during adxl345_core_probe(), so reading it in the IRQ
handler is served from regcache without extra bus transactions.
Fixes: 66a1af6d8a63 ("iio: accel: adxl345: add activity event feature")
Signed-off-by: Wenqiang Zhao <berringtoni36@gmail.com>
---
Testing and limitations:
- Linux kernel Kbuild compile-tested on x86_64 (Linux v7.4-rc5, GCC 11.4.0,
CONFIG_ADXL345=m, CONFIG_ADXL345_I2C=m, CONFIG_ADXL345_SPI=m) with
`make W=1` and objtool:
* drivers/iio/accel/adxl345_core.o, adxl345_i2c.o, adxl345_spi.o built
with 0 warnings and 0 errors.
- Host reproducer extracting production adxl345_push_event() and
adxl345_irq_handler() compiled with clang -std=gnu11 -Wall -Wextra
-Wno-unused-parameter -Werror -fsanitize=undefined:
* Unpatched fixes-togreg (23c47e17ad8c): 6/14 passed, 8/14 failed (all
6 DC/AC activity-only X/Y/Z cases lost axis modifier, reserved
TAP_AXIS upper bits triggered spurious status read, and
ACT_INACT_CTRL read error was not checked).
* Patched: 14/14 passed with no UBSan diagnostics.
- Verified clean apply on jic23/iio.git fixes-togreg (23c47e17ad8c),
testing (27bae9cc834c), and Linux v7.4-rc5 (fe6ff8d5d675); full-tree
checkpatch.pl --strict reported 0 errors, 0 warnings, 0 checks.
- Not tested on physical ADXL345 hardware.
drivers/iio/accel/adxl345_core.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c
index 6c9080d88..66d96c230 100644
--- a/drivers/iio/accel/adxl345_core.c
+++ b/drivers/iio/accel/adxl345_core.c
@@ -1789,6 +1789,7 @@ static irqreturn_t adxl345_irq_handler(int irq, void *p)
{
struct iio_dev *indio_dev = p;
struct adxl345_state *st = iio_priv(indio_dev);
+ unsigned int act_ctrl;
unsigned int regval;
enum iio_modifier tap_dir = IIO_NO_MOD;
enum iio_modifier act_dir = IIO_NO_MOD;
@@ -1800,8 +1801,12 @@ static irqreturn_t adxl345_irq_handler(int irq, void *p)
if (ret)
return IRQ_NONE;
+ ret = regmap_read(st->regmap, ADXL345_REG_ACT_INACT_CTRL, &act_ctrl);
+ if (ret)
+ return IRQ_NONE;
+
if (FIELD_GET(ADXL345_REG_TAP_AXIS_MSK, axis_ctrl) ||
- FIELD_GET(ADXL345_ACT_XYZ_EN, axis_ctrl)) {
+ FIELD_GET(ADXL345_ACT_XYZ_EN, act_ctrl)) {
ret = regmap_read(st->regmap, ADXL345_REG_ACT_TAP_STATUS, ®val);
if (ret)
return IRQ_NONE;
--
2.50.1 (Apple Git-155)
reply other threads:[~2026-12-06 10:05 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261206100513.89195-1-berringtoni36@gmail.com \
--to=berringtoni36@gmail.com \
--cc=Michael.Hennerich@analog.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=l.rubusch@gmail.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@analog.com \
--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
all inboxes | Powered by JetHome®