* [PATCH] iio: accel: adxl345: check ACT_INACT_CTRL for activity axes in IRQ
@ 2026-12-06 10:05 Wenqiang Zhao
0 siblings, 0 replies; only message in thread
From: Wenqiang Zhao @ 2026-12-06 10:05 UTC (permalink / raw)
To: Jonathan Cameron, Michael Hennerich, Nuno Sá
Cc: David Lechner, Andy Shevchenko, Lothar Rubusch, linux, linux-iio,
linux-kernel, Wenqiang Zhao
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)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-12-06 10:05 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-06 10:05 [PATCH] iio: accel: adxl345: check ACT_INACT_CTRL for activity axes in IRQ Wenqiang Zhao
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®