* [PATCH v4 0/2] iio: proximity: add Imagis ISG5320A (Samsung Galaxy XCover5)
@ 2026-12-05 3:35 Adil Hüsrev Tepe
2026-12-05 3:35 ` [PATCH v4 1/2] dt-bindings: iio: proximity: add Imagis ISG5320A Adil Hüsrev Tepe
2026-12-05 3:35 ` [PATCH v4 2/2] iio: proximity: add Imagis ISG5320A SAR sensor driver Adil Hüsrev Tepe
0 siblings, 2 replies; 4+ messages in thread
From: Adil Hüsrev Tepe @ 2026-12-05 3:35 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: linux-iio, devicetree, linux-kernel, phone-devel, Joshua Crofts,
Adil Hüsrev Tepe
This series adds an IIO driver and its DT binding for the Imagis
ISG5320A capacitive SAR/grip proximity sensor (I2C), as fitted on the
Samsung Galaxy XCover5 (SM-G525F, Exynos850).
Andy asked on v1 why this is a brand new driver: mainline has no driver
for this chip or its register map. The two Imagis drivers in the tree,
drivers/input/touchscreen/imagis.c (IST30xx touchscreen controllers)
and drivers/input/misc/isa1200.c (a haptic driver), are for unrelated
devices, and the SAR drivers in drivers/iio/proximity are for chips
from other vendors (Semtech, Awinic, TYHX).
v4 reworks the driver along the v3 reviews from Jonathan Cameron and
Joshua Crofts and the v2 review from Andy Shevchenko, which v3 had not
addressed, and fixes the two Sashiko AI findings on v3:
- Reads much less like a vendor driver: the per-line vendor references,
the init-table read-back check, the CHIPID read and the dev_info()
noise are gone, constant write sequences use regmap_multi_reg_write(),
and the 16-bit registers use get_unaligned_be16().
- The init table was checked against the values read back after a soft
reset (one unit): 29 of the 150 entries repeat them. Two are dropped.
The other 27 are next to a register that the table changes and stay,
because the register layout is not documented.
- The binding now requires vdd-supply, so Krzysztof's Reviewed-by on
v3 1/2 is dropped. The driver uses devm_regulator_get_enable()
instead of the _optional variant and always applies the power-on
delay.
- Power management is simpler: no disable_irq(), no wakeup support for
now (DEFINE_RUNTIME_DEV_PM_OPS), devm_pm_runtime_set_active_enabled(),
no shutdown(), and the chip is put back to sleep if probe fails after
starting it.
Per-patch details are below each patch's "---" line.
v3: https://lore.kernel.org/r/20261117173333.1853986-1-tadilhusrev@gmail.com
Tested on one Samsung Galaxy XCover5 (SM-G525F, Exynos850) as a module
on a v7.4-rc3 based tree (7.4.0-rc3-00023-gdcb8b91fb779+), this exact
code: probe/bind, runtime suspend/resume, raw reads, and threshold
events on a hand grip. With the thresholds at 300 (rising) / 150
(falling), gripping the lower-left of the back swung in_proximity0_raw
from a ~4 baseline to ~13000 and back, and iio_event_monitor reported
the matching proximity threshold rising-on-grip and falling-on-release
events, the chip's GPIO interrupt count tracking them one for one. The
chip can occasionally need a calibration retry at resume, which the
driver now handles; it stayed calibrated through the grip run. System
suspend was not tested.
Build-tested on arm64 with W=1 (no warnings); dt_binding_check passes
for the binding. checkpatch.pl --strict reports one warning on each
patch, the reminder to check MAINTAINERS for the new file.
Based on v7.4-rc1.
Tool usage
----------
This series was developed during XCover5 mainline bring-up with the
help of an AI coding assistant (Claude Code, Anthropic), which drafted
the IIO driver from the Samsung vendor driver's register map, reworked
it for v4 along the reviews, and drafted these changelogs. I reviewed
every line and take full responsibility for the contribution. Review
comments are welcome and I will answer them myself.
---
Adil Hüsrev Tepe (2):
dt-bindings: iio: proximity: add Imagis ISG5320A
iio: proximity: add Imagis ISG5320A SAR sensor driver
.../bindings/iio/proximity/imagis,isg5320a.yaml | 54 ++
drivers/iio/proximity/Kconfig | 11 +
drivers/iio/proximity/Makefile | 1 +
drivers/iio/proximity/isg5320a.c | 745 +++++++++++++++++++++
4 files changed, 811 insertions(+)
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261122-isg5320a-6ee19adaa600
Best regards,
--
Adil Hüsrev Tepe <tadilhusrev@gmail.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v4 1/2] dt-bindings: iio: proximity: add Imagis ISG5320A
2026-12-05 3:35 [PATCH v4 0/2] iio: proximity: add Imagis ISG5320A (Samsung Galaxy XCover5) Adil Hüsrev Tepe
@ 2026-12-05 3:35 ` Adil Hüsrev Tepe
2026-12-05 3:35 ` [PATCH v4 2/2] iio: proximity: add Imagis ISG5320A SAR sensor driver Adil Hüsrev Tepe
1 sibling, 0 replies; 4+ messages in thread
From: Adil Hüsrev Tepe @ 2026-12-05 3:35 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: linux-iio, devicetree, linux-kernel, phone-devel, Joshua Crofts,
Adil Hüsrev Tepe
Add a binding for the Imagis ISG5320A capacitive SAR/grip proximity
sensor (I2C), as fitted on the Samsung Galaxy XCover5.
Signed-off-by: Adil Hüsrev Tepe <tadilhusrev@gmail.com>
---
v4:
- vdd-supply is now required; the chip does not work unpowered. On the
XCover5 it is a PMIC LDO.
- Krzysztof's Reviewed-by on v3 is dropped because of this change.
- The example uses IRQ_TYPE_EDGE_FALLING: the chip pulls INT low on an
event and releases it when IRQSRC is read, and the vendor kernel
requests the interrupt as a falling edge.
- The example no longer sets wakeup-source. The property stays allowed
as hardware description (the vendor kernel uses the INT line as a
wake-up interrupt); the driver has no wakeup support yet.
- Drop the sentence about the phone from the description (Sashiko AI
on v1).
---
.../bindings/iio/proximity/imagis,isg5320a.yaml | 54 ++++++++++++++++++++++
1 file changed, 54 insertions(+)
diff --git a/Documentation/devicetree/bindings/iio/proximity/imagis,isg5320a.yaml b/Documentation/devicetree/bindings/iio/proximity/imagis,isg5320a.yaml
new file mode 100644
index 00000000000..4671557ba58
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/proximity/imagis,isg5320a.yaml
@@ -0,0 +1,54 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/proximity/imagis,isg5320a.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Imagis ISG5320A SAR proximity (grip) sensor
+
+maintainers:
+ - Adil Hüsrev Tepe <tadilhusrev@gmail.com>
+
+description:
+ Imagis ISG5320A capacitive SAR/grip proximity sensor, connected over I2C.
+
+properties:
+ compatible:
+ const: imagis,isg5320a
+
+ reg:
+ maxItems: 1
+
+ interrupts:
+ maxItems: 1
+ description: active-low data-ready / proximity interrupt
+
+ vdd-supply: true
+
+ wakeup-source: true
+
+required:
+ - compatible
+ - reg
+ - interrupts
+ - vdd-supply
+
+additionalProperties: false
+
+examples:
+ - |
+ #include <dt-bindings/interrupt-controller/irq.h>
+
+ i2c {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ proximity@28 {
+ compatible = "imagis,isg5320a";
+ reg = <0x28>;
+ interrupt-parent = <&gpa2>;
+ interrupts = <0 IRQ_TYPE_EDGE_FALLING>;
+ vdd-supply = <&grip_vdd>;
+ };
+ };
+...
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v4 2/2] iio: proximity: add Imagis ISG5320A SAR sensor driver
2026-12-05 3:35 [PATCH v4 0/2] iio: proximity: add Imagis ISG5320A (Samsung Galaxy XCover5) Adil Hüsrev Tepe
2026-12-05 3:35 ` [PATCH v4 1/2] dt-bindings: iio: proximity: add Imagis ISG5320A Adil Hüsrev Tepe
@ 2026-12-05 3:35 ` Adil Hüsrev Tepe
2026-12-05 3:58 ` sashiko-bot
1 sibling, 1 reply; 4+ messages in thread
From: Adil Hüsrev Tepe @ 2026-12-05 3:35 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: linux-iio, devicetree, linux-kernel, phone-devel, Joshua Crofts,
Adil Hüsrev Tepe
Add an IIO driver for the Imagis ISG5320A capacitive SAR/grip sensor
(I2C), as fitted on the Samsung Galaxy XCover5. It exposes one
IIO_PROXIMITY channel (the B-channel signal minus its baseline) and a
rising/falling threshold proximity event.
There is no public datasheet; the register map, init table and the
reset and calibration sequences follow Samsung's vendor driver.
Signed-off-by: Adil Hüsrev Tepe <tadilhusrev@gmail.com>
---
v4 (reviews from Jonathan Cameron, Joshua Crofts, Andy Shevchenko and
Sashiko AI):
- Drop the per-line references to the vendor driver; one general
reference in the header comment.
- Write the init table and the sleep/normal sequences with
regmap_multi_reg_write(); the delays live in the reg_sequence.
- Init table: 29 of the 150 entries equal the value read back after a
soft reset (measured on one unit). The register layout is not
documented and 27 of them are next to a register that the table
changes, so they may be part of a multi-byte value and stay. The
other two (0x41 and 0xC5) are dropped.
- Drop the init-table read-back check, the CHIPID read and the
dev_info()/dev_dbg() output.
- No register cache; a comment says why.
- fsleep() for all delays, with comments saying where the reset and
scan-stop waits come from. The 5 ms before the first access is folded
into the power-on delay.
- get_unaligned_be16() for the 16-bit big-endian registers.
- Get the struct device from the regmap instead of storing it.
- guard() held to the end of the function instead of scoped_guard().
No break or goto next to guard(): the IRQ thread reads the status in
a helper and returns.
- Events are gated at the source (IRQFUNC) only: no disable_irq(), no
IRQF_NO_AUTOEN; the IRQ thread no longer checks ev_enabled.
- No synchronize_irq() either: on unbind the IRQ is freed before the
chip is put to sleep.
- PM_RUNTIME_ACQUIRE_AUTOSUSPEND() in read_raw() and events_on().
events_on() takes one more reference with pm_runtime_get_noresume()
that enabled events keep and events_off() drops, so the get and the
put are both inside these two functions.
- No wakeup support for now: drop enable_irq_wake() and
device_init_wakeup(); use DEFINE_RUNTIME_DEV_PM_OPS() so the chip is
also put to sleep on system suspend.
- devm_pm_runtime_set_active_enabled() and autosuspend without the
get_noresume/put dance.
- The teardown is split into two devm actions, each registered right
after what it undoes. The sleep action follows the chip start, so a
failed IRQ request no longer leaves the chip scanning (Sashiko,
Medium); it puts the chip to sleep unconditionally. The events-off
action follows the IRQ request; on unbind it turns enabled events off
and drops their runtime PM reference.
- Drop shutdown() (Sashiko, Low).
- Drop the IRQF_TRIGGER_FALLING fallback; the trigger comes from DT.
- The interrupt is required, as in the binding; drop the code path for
a device without one.
- Use devm_regulator_get_enable() instead of the _optional variant and
always apply the power-on delay. On the XCover5 the supply is a PMIC
LDO referenced by vdd-supply, not a fixed regulator as I wrote in my
reply to the v3 review.
- Clamp the reported falling threshold at 0; what the chip does with a
far hysteresis above the threshold is not known. With the current
table the value is 300 - 150.
- Open-code the channel specs instead of a macro.
- Drop the cfcal_th warning.
- Reorder struct isg5320a_data (pahole), add err.h, drop
mod_devicetable.h, blank lines between statement groups, no
duplicate error message after devm_request_threaded_irq().
Andy Shevchenko's review of v2, which v3 did not address:
- Headers: mod_devicetable.h and pm_wakeup.h are gone; time.h,
minmax.h, lockdep.h and dev_printk.h are added for what the file
uses.
- ISG5320A_AUTOSUSPEND_MS is (5 * MSEC_PER_SEC).
- ISG5320A_RESET_CONDITION and its comment are gone with the cfcal_th
code.
- The redundant dev pointer in the private struct is gone.
- bool members: ev_enabled and close are protected by different locks,
so they stay two plain bools instead of bit-fields; they are at the
end of the struct.
- REGCACHE_NONE is justified in a comment.
- The sleeps are explained. The INT line is no longer read as a GPIO,
so readx_poll_timeout() does not apply.
- isg5320a_initialize() no longer takes the mutex: it only runs from
probe, before the IRQ is requested, runtime PM is enabled and the IIO
device is registered.
- The init table holds settings to write, not register defaults, and
there is no cache to seed, so it is a struct reg_sequence for
regmap_multi_reg_write() rather than reg_defaults.
- get_unaligned_be16(), the devm runtime PM helper, no trigger-type
fallback and no extra message after devm_request_threaded_irq(), as
listed above.
---
drivers/iio/proximity/Kconfig | 11 +
drivers/iio/proximity/Makefile | 1 +
drivers/iio/proximity/isg5320a.c | 745 +++++++++++++++++++++++++++++++++++++++
3 files changed, 757 insertions(+)
diff --git a/drivers/iio/proximity/Kconfig b/drivers/iio/proximity/Kconfig
index bb77fad2a1b..311a7b9e42a 100644
--- a/drivers/iio/proximity/Kconfig
+++ b/drivers/iio/proximity/Kconfig
@@ -67,6 +67,17 @@ config IRSD200
To compile this driver as a module, choose M here: the module will be
called irsd200.
+config ISG5320A
+ tristate "Imagis ISG5320A capacitive SAR/grip sensor"
+ depends on I2C
+ select REGMAP_I2C
+ help
+ Say Y here to build a driver for the Imagis ISG5320A capacitive
+ SAR/grip sensor.
+
+ To compile this driver as a module, choose M here: the module will
+ be called isg5320a.
+
config ISL29501
tristate "Intersil ISL29501 Time Of Flight sensor"
depends on I2C
diff --git a/drivers/iio/proximity/Makefile b/drivers/iio/proximity/Makefile
index 4352833dd8a..6aa606fa5cb 100644
--- a/drivers/iio/proximity/Makefile
+++ b/drivers/iio/proximity/Makefile
@@ -9,6 +9,7 @@ obj-$(CONFIG_CROS_EC_MKBP_PROXIMITY) += cros_ec_mkbp_proximity.o
obj-$(CONFIG_D3323AA) += d3323aa.o
obj-$(CONFIG_HX9023S) += hx9023s.o
obj-$(CONFIG_IRSD200) += irsd200.o
+obj-$(CONFIG_ISG5320A) += isg5320a.o
obj-$(CONFIG_ISL29501) += isl29501.o
obj-$(CONFIG_LIDAR_LITE_V2) += pulsedlight-lidar-lite-v2.o
obj-$(CONFIG_MB1232) += mb1232.o
diff --git a/drivers/iio/proximity/isg5320a.c b/drivers/iio/proximity/isg5320a.c
new file mode 100644
index 00000000000..407f2c7e2d8
--- /dev/null
+++ b/drivers/iio/proximity/isg5320a.c
@@ -0,0 +1,745 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Imagis ISG5320A capacitive SAR/grip sensor.
+ *
+ * The register map, init table and the reset/calibration sequences and
+ * their timings follow Samsung's vendor driver for the Galaxy XCover5
+ * (drivers/sensors/isg5320a.c, Copyright (C) Imagis Technology); there is
+ * no public datasheet.
+ *
+ * The chip is used as one proximity channel: the B-channel signal minus its
+ * baseline is exposed as in_proximity0_raw, and the chip's CLOSE/FAR
+ * interrupt is exposed as IIO threshold events (rising = grip, falling =
+ * release).
+ */
+
+#include <linux/array_size.h>
+#include <linux/bits.h>
+#include <linux/cleanup.h>
+#include <linux/delay.h>
+#include <linux/dev_printk.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/errno.h>
+#include <linux/i2c.h>
+#include <linux/interrupt.h>
+#include <linux/lockdep.h>
+#include <linux/minmax.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/pm.h>
+#include <linux/pm_runtime.h>
+#include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
+#include <linux/time.h>
+#include <linux/types.h>
+#include <linux/unaligned.h>
+
+#include <linux/iio/events.h>
+#include <linux/iio/iio.h>
+
+#define ISG5320A_REG_IRQSRC 0x00 /* read releases the INT line */
+#define ISG5320A_REG_IRQSTS 0x01
+#define ISG5320A_IRQSTS_PROX BIT(4)
+#define ISG5320A_REG_OSCCON 0x06
+#define ISG5320A_OSC_SLEEP 0xB0
+#define ISG5320A_OSC_NORMAL 0xF0
+#define ISG5320A_REG_IRQFUNC 0x07
+#define ISG5320A_IRQFUNC_ENABLE 0x0D
+#define ISG5320A_IRQFUNC_DISABLE 0x13
+#define ISG5320A_REG_BS_ON_WD 0x19
+#define ISG5320A_BS_WD_OFF 0x0A
+#define ISG5320A_BS_WD_ON 0x8A
+#define ISG5320A_REG_SCANCTRL1 0x38
+#define ISG5320A_SCAN_STOP 0x00
+#define ISG5320A_CFCAL_START 0xDD
+#define ISG5320A_CFCAL_BUSY BIT(4)
+#define ISG5320A_REG_SCANCTRL2 0x39
+#define ISG5320A_SCAN2_RESET 0x00
+#define ISG5320A_SCAN2_CLEAR 0x60
+#define ISG5320A_BFCAL_START 0x07
+/* CDC16_T_H/L then BSL16_B_H/L, all big endian */
+#define ISG5320A_REG_CDC16_T_H 0x5C
+/* B_PROXCTL3..8: threshold, close and far hysteresis, 16 bit big endian */
+#define ISG5320A_REG_B_PROXCTL3 0x9B
+#define ISG5320A_REG_PROTECT 0xCD
+#define ISG5320A_PROTECT_UNLOCK 0xDE
+#define ISG5320A_REG_SOFTRESET 0xFD
+#define ISG5320A_SOFTRESET_VAL 0xDE
+#define ISG5320A_MAX_REG 0xFE
+
+#define ISG5320A_AUTOSUSPEND_MS (5 * MSEC_PER_SEC)
+
+/*
+ * Vendor setup table for the XCover5. The register layout is not documented.
+ * Two entries that only repeat the value the register has after the soft
+ * reset are left out (0x41, 0xC5). Other such entries are kept, because an
+ * adjacent register changes and the two may be parts of one value.
+ */
+static const struct reg_sequence isg5320a_setup_reg[] = {
+ { 0x05, 0xFC }, { 0x06, 0xF1 }, { 0x07, 0x13 }, { 0x08, 0x01 },
+ { 0x09, 0x80 }, { 0x0A, 0x20 }, { 0x0B, 0x00 }, { 0x0C, 0x00 },
+ { 0x12, 0x89 }, { 0x19, 0x8A }, { 0x1B, 0x28 }, { 0x1D, 0x20 },
+ { 0x1E, 0x00 }, { 0x1F, 0x18 }, { 0x20, 0x05 }, { 0x21, 0x10 },
+ { 0x22, 0x10 }, { 0x23, 0x00 }, { 0x24, 0x00 }, { 0x25, 0x05 },
+ { 0x26, 0x05 }, { 0x27, 0x10 }, { 0x28, 0x20 }, { 0x29, 0x00 },
+ { 0x2A, 0x20 }, { 0x2B, 0x00 }, { 0x2C, 0x00 }, { 0x2D, 0x20 },
+ { 0x2F, 0x18 }, { 0x30, 0xC0 }, { 0x60, 0xF0 }, { 0x61, 0x8F },
+ { 0x62, 0x0C }, { 0x63, 0x00 }, { 0x64, 0x00 }, { 0x65, 0x44 },
+ { 0x66, 0x3C }, { 0x67, 0x01 }, { 0x68, 0x00 }, { 0x69, 0x00 },
+ { 0x6A, 0x10 }, { 0x6B, 0x00 }, { 0x6C, 0x10 }, { 0x6D, 0x40 },
+ { 0x6E, 0x22 }, { 0x6F, 0x00 }, { 0x70, 0x01 }, { 0x71, 0x60 },
+ { 0x72, 0xFF }, { 0x73, 0xFF }, { 0x74, 0xFF }, { 0x7B, 0x08 },
+ { 0x7C, 0x00 }, { 0x7D, 0x0C }, { 0x7E, 0x00 }, { 0x7F, 0xF8 },
+ { 0x80, 0xF8 }, { 0x81, 0x00 }, { 0x82, 0xF0 }, { 0x83, 0xF0 },
+ { 0x84, 0xF0 }, { 0x85, 0xF0 }, { 0x86, 0xF0 }, { 0x87, 0xF0 },
+ { 0x88, 0x00 }, { 0x89, 0x00 }, { 0x8A, 0x08 }, { 0x8B, 0x00 },
+ { 0x8C, 0x02 }, { 0x8D, 0x00 }, { 0x99, 0x21 }, { 0x9A, 0x3C },
+ { 0x9B, 0x01 }, { 0x9C, 0x2C }, { 0x9D, 0x00 }, { 0x9E, 0x00 },
+ { 0x9F, 0x00 }, { 0xA0, 0x96 }, { 0xA1, 0xC0 }, { 0xA2, 0x22 },
+ { 0xA3, 0x00 }, { 0xA4, 0x08 }, { 0xA5, 0x60 }, { 0xA6, 0xFF },
+ { 0xA7, 0xFF }, { 0xA8, 0xFF }, { 0xA9, 0x00 }, { 0xAF, 0x40 },
+ { 0xB0, 0x00 }, { 0xB1, 0x60 }, { 0xB2, 0x00 }, { 0xB3, 0xD0 },
+ { 0xB4, 0x10 }, { 0xB5, 0x28 }, { 0xB6, 0xF0 }, { 0xB7, 0xF6 },
+ { 0xB8, 0xFD }, { 0xB9, 0xDE }, { 0xBA, 0xFD }, { 0xBB, 0xF0 },
+ { 0xBC, 0x00 }, { 0xBD, 0xFF }, { 0xBE, 0x01 }, { 0xBF, 0x5E },
+ { 0xC0, 0x00 }, { 0xC1, 0x69 }, { 0xC2, 0xF0 }, { 0xC3, 0x00 },
+ { 0xC4, 0x00 }, { 0x13, 0x3A },
+ { 0x18, 0xF1 }, /* A channel on CS0, B channel on CS1 */
+ { 0x1C, 0x18 }, { 0x35, 0x00 }, { 0x36, 0x00 }, { 0x3A, 0x0A },
+ { 0x3B, 0x50 }, { 0x3C, 0x0A }, { 0x3D, 0x50 }, { 0x3E, 0x60 },
+ { 0x94, 0x10 }, { 0x95, 0xA9 }, { 0x96, 0x11 }, { 0x2E, 0x14 },
+ { 0x0E, 0xE0 }, { 0x0F, 0x1E }, { 0x10, 0xC0 }, { 0x11, 0xC1 },
+ { 0xD0, 0xE0 }, { 0xD1, 0x08 }, { 0xD2, 0x00 }, { 0xD3, 0xFF },
+ { 0xD4, 0xFF }, { 0xD5, 0x1E }, { 0xD6, 0x32 }, { 0xD7, 0xFF },
+ { 0xD8, 0x20 }, { 0xD9, 0x70 }, { 0xDA, 0x7F }, { 0xDB, 0xE0 },
+ { 0xDC, 0x00 }, { 0x76, 0x08 }, { 0x77, 0x00 }, { 0x79, 0x02 },
+ { 0x7A, 0x00 }, { 0xAA, 0x36 }, { 0xAB, 0xB0 }, { 0xAD, 0x04 },
+ { 0xAE, 0x00 },
+};
+
+static const struct reg_sequence isg5320a_sleep_seq[] = {
+ { ISG5320A_REG_SCANCTRL1, ISG5320A_SCAN_STOP },
+ { ISG5320A_REG_OSCCON, ISG5320A_OSC_SLEEP },
+ { ISG5320A_REG_BS_ON_WD, ISG5320A_BS_WD_OFF },
+};
+
+/*
+ * Restart scanning and force a calibration. The delays (in us) match the
+ * vendor driver.
+ */
+static const struct reg_sequence isg5320a_normal_seq[] = {
+ { ISG5320A_REG_BS_ON_WD, ISG5320A_BS_WD_ON },
+ { ISG5320A_REG_SCANCTRL1, ISG5320A_SCAN_STOP, 30 * USEC_PER_MSEC },
+ { ISG5320A_REG_BS_ON_WD, ISG5320A_BS_WD_OFF },
+ { ISG5320A_REG_SCANCTRL2, ISG5320A_SCAN2_CLEAR, 100 * USEC_PER_MSEC },
+ { ISG5320A_REG_OSCCON, ISG5320A_OSC_NORMAL },
+ { ISG5320A_REG_BS_ON_WD, ISG5320A_BS_WD_ON },
+ { ISG5320A_REG_SCANCTRL2, ISG5320A_SCAN2_RESET },
+ { ISG5320A_REG_SCANCTRL1, ISG5320A_CFCAL_START, 500 * USEC_PER_MSEC },
+ /* 300 ms for the calibration to settle, to match the vendor driver */
+ { ISG5320A_REG_SCANCTRL2, ISG5320A_BFCAL_START, 300 * USEC_PER_MSEC },
+};
+
+struct isg5320a_data {
+ struct regmap *regmap;
+ /* Serialises multi-register chip sequences and the cached sample. */
+ struct mutex lock;
+ /* Serialises event enable/disable and protects ev_enabled. */
+ struct mutex ev_lock;
+ u16 cdc;
+ u16 base;
+ u16 thresh;
+ u16 close_hyst;
+ u16 far_hyst;
+ bool ev_enabled;
+ bool close;
+};
+
+static bool isg5320a_writeable_reg(struct device *dev, unsigned int reg)
+{
+ switch (reg) {
+ case ISG5320A_REG_OSCCON:
+ case ISG5320A_REG_IRQFUNC:
+ case ISG5320A_REG_BS_ON_WD:
+ case ISG5320A_REG_SCANCTRL1:
+ case ISG5320A_REG_SCANCTRL2:
+ case ISG5320A_REG_PROTECT:
+ case ISG5320A_REG_SOFTRESET:
+ return true;
+ }
+
+ for (unsigned int i = 0; i < ARRAY_SIZE(isg5320a_setup_reg); i++)
+ if (isg5320a_setup_reg[i].reg == reg)
+ return true;
+
+ return false;
+}
+
+static bool isg5320a_precious_reg(struct device *dev, unsigned int reg)
+{
+ /* Reading IRQSRC acknowledges the interrupt; keep debugfs off it. */
+ return reg == ISG5320A_REG_IRQSRC;
+}
+
+/*
+ * No register cache: configuration registers are only written as whole bytes
+ * from fixed sequences, never read-modify-written. The only reads are the
+ * threshold registers, once at probe, and status and data registers that the
+ * chip updates itself.
+ */
+static const struct regmap_config isg5320a_regmap_config = {
+ .reg_bits = 8,
+ .val_bits = 8,
+ .max_register = ISG5320A_MAX_REG,
+ .writeable_reg = isg5320a_writeable_reg,
+ .precious_reg = isg5320a_precious_reg,
+ .cache_type = REGCACHE_NONE,
+};
+
+/*
+ * Soft reset. The two waits follow the vendor driver, which
+ * - reads IRQSRC to release the INT line and then polls the line for up
+ * to 50 ms until it is high;
+ * - after the reset command waits 1 ms and then polls the line for up to
+ * 50 ms until the chip pulls it low.
+ * The INT line is not polled here, so the full time is waited in both
+ * places.
+ */
+static int isg5320a_reset(struct isg5320a_data *data)
+{
+ unsigned int val;
+ int ret;
+
+ /* Also checks that the chip answers at all. */
+ ret = regmap_read(data->regmap, ISG5320A_REG_IRQSRC, &val);
+ if (ret)
+ return ret;
+
+ fsleep(50 * USEC_PER_MSEC);
+
+ ret = regmap_write(data->regmap, ISG5320A_REG_PROTECT,
+ ISG5320A_PROTECT_UNLOCK);
+ if (ret)
+ return ret;
+
+ ret = regmap_write(data->regmap, ISG5320A_REG_SOFTRESET,
+ ISG5320A_SOFTRESET_VAL);
+ if (ret)
+ return ret;
+
+ fsleep(51 * USEC_PER_MSEC);
+
+ return 0;
+}
+
+static int isg5320a_initialize(struct isg5320a_data *data)
+{
+ unsigned int val;
+ u8 buf[6];
+ int ret;
+
+ ret = regmap_read(data->regmap, ISG5320A_REG_IRQSRC, &val);
+ if (ret)
+ return ret;
+
+ ret = regmap_write(data->regmap, ISG5320A_REG_SCANCTRL1,
+ ISG5320A_SCAN_STOP);
+ if (ret)
+ return ret;
+
+ /* The vendor driver waits 30 ms after stopping the scan. */
+ fsleep(30 * USEC_PER_MSEC);
+
+ ret = regmap_multi_reg_write(data->regmap, isg5320a_setup_reg,
+ ARRAY_SIZE(isg5320a_setup_reg));
+ if (ret)
+ return ret;
+
+ ret = regmap_bulk_read(data->regmap, ISG5320A_REG_B_PROXCTL3, buf,
+ sizeof(buf));
+ if (ret)
+ return ret;
+
+ data->thresh = get_unaligned_be16(&buf[0]);
+ data->close_hyst = get_unaligned_be16(&buf[2]);
+ data->far_hyst = get_unaligned_be16(&buf[4]);
+
+ return 0;
+}
+
+static int isg5320a_mode_sleep(struct isg5320a_data *data)
+{
+ unsigned int val;
+ int ret;
+
+ guard(mutex)(&data->lock);
+
+ ret = regmap_read(data->regmap, ISG5320A_REG_IRQSRC, &val);
+ if (ret)
+ return ret;
+
+ return regmap_multi_reg_write(data->regmap, isg5320a_sleep_seq,
+ ARRAY_SIZE(isg5320a_sleep_seq));
+}
+
+static int isg5320a_mode_normal(struct isg5320a_data *data)
+{
+ unsigned int tries, val;
+ int ret;
+
+ guard(mutex)(&data->lock);
+
+ ret = regmap_read(data->regmap, ISG5320A_REG_IRQSRC, &val);
+ if (ret)
+ return ret;
+
+ /*
+ * The chip clears ISG5320A_CFCAL_BUSY once the calibration has run.
+ * Now and then the bit stays set and nothing is measured. Running
+ * the sequence again on the running chip does not help; it has to be
+ * put to sleep first.
+ */
+ for (tries = 3; tries; tries--) {
+ ret = regmap_multi_reg_write(data->regmap, isg5320a_normal_seq,
+ ARRAY_SIZE(isg5320a_normal_seq));
+ if (ret)
+ return ret;
+
+ ret = regmap_read(data->regmap, ISG5320A_REG_SCANCTRL1, &val);
+ if (ret)
+ return ret;
+
+ if (!(val & ISG5320A_CFCAL_BUSY))
+ return 0;
+
+ ret = regmap_multi_reg_write(data->regmap, isg5320a_sleep_seq,
+ ARRAY_SIZE(isg5320a_sleep_seq));
+ if (ret)
+ return ret;
+ }
+
+ return -ETIMEDOUT;
+}
+
+static int isg5320a_read_sample(struct isg5320a_data *data)
+{
+ u8 buf[4];
+ u16 v;
+ int ret;
+
+ lockdep_assert_held(&data->lock);
+
+ ret = regmap_bulk_read(data->regmap, ISG5320A_REG_CDC16_T_H, buf,
+ sizeof(buf));
+ if (ret)
+ return ret;
+
+ /* 0x0000 and 0xFFFF are not valid samples; keep the previous value. */
+ v = get_unaligned_be16(&buf[0]);
+ if (v != 0 && v != 0xFFFF)
+ data->cdc = v;
+
+ v = get_unaligned_be16(&buf[2]);
+ if (v != 0 && v != 0xFFFF)
+ data->base = v;
+
+ return 0;
+}
+
+static int isg5320a_read_irq_status(struct isg5320a_data *data, bool *close)
+{
+ unsigned int val;
+ int ret;
+
+ lockdep_assert_held(&data->lock);
+
+ ret = isg5320a_read_sample(data);
+ if (ret)
+ return ret;
+
+ ret = regmap_read(data->regmap, ISG5320A_REG_IRQSRC, &val);
+ if (ret)
+ return ret;
+
+ ret = regmap_read(data->regmap, ISG5320A_REG_IRQSTS, &val);
+ if (ret)
+ return ret;
+
+ *close = val & ISG5320A_IRQSTS_PROX;
+
+ return 0;
+}
+
+static irqreturn_t isg5320a_irq_thread(int irq, void *private)
+{
+ struct iio_dev *indio_dev = private;
+ struct isg5320a_data *data = iio_priv(indio_dev);
+ s64 timestamp = iio_get_time_ns(indio_dev);
+ enum iio_event_direction dir;
+ bool close;
+ int ret;
+
+ guard(mutex)(&data->lock);
+
+ ret = isg5320a_read_irq_status(data, &close);
+ if (ret) {
+ dev_err_ratelimited(regmap_get_device(data->regmap),
+ "irq status read failed: %d\n", ret);
+ return IRQ_HANDLED;
+ }
+
+ if (close == data->close)
+ return IRQ_HANDLED;
+
+ data->close = close;
+
+ dir = close ? IIO_EV_DIR_RISING : IIO_EV_DIR_FALLING;
+ iio_push_event(indio_dev,
+ IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY, 0,
+ IIO_EV_TYPE_THRESH, dir),
+ timestamp);
+
+ return IRQ_HANDLED;
+}
+
+static int isg5320a_read_raw(struct iio_dev *indio_dev,
+ const struct iio_chan_spec *chan,
+ int *val, int *val2, long mask)
+{
+ struct isg5320a_data *data = iio_priv(indio_dev);
+ struct device *dev = regmap_get_device(data->regmap);
+ int ret;
+
+ switch (mask) {
+ case IIO_CHAN_INFO_RAW: {
+ PM_RUNTIME_ACQUIRE_AUTOSUSPEND(dev, pm);
+ ret = PM_RUNTIME_ACQUIRE_ERR(&pm);
+ if (ret)
+ return ret;
+
+ guard(mutex)(&data->lock);
+
+ ret = isg5320a_read_sample(data);
+ if (ret)
+ return ret;
+
+ *val = (int)data->cdc - (int)data->base;
+
+ return IIO_VAL_INT;
+ }
+ default:
+ return -EINVAL;
+ }
+}
+
+static int isg5320a_read_event_config(struct iio_dev *indio_dev,
+ const struct iio_chan_spec *chan,
+ enum iio_event_type type,
+ enum iio_event_direction dir)
+{
+ struct isg5320a_data *data = iio_priv(indio_dev);
+
+ if (type != IIO_EV_TYPE_THRESH || dir != IIO_EV_DIR_EITHER)
+ return -EINVAL;
+
+ guard(mutex)(&data->ev_lock);
+
+ return data->ev_enabled;
+}
+
+static int isg5320a_events_on(struct isg5320a_data *data)
+{
+ struct device *dev = regmap_get_device(data->regmap);
+ unsigned int val;
+ int ret;
+
+ PM_RUNTIME_ACQUIRE_AUTOSUSPEND(dev, pm);
+ ret = PM_RUNTIME_ACQUIRE_ERR(&pm);
+ if (ret)
+ return ret;
+
+ guard(mutex)(&data->lock);
+
+ ret = regmap_read(data->regmap, ISG5320A_REG_IRQSTS, &val);
+ if (ret)
+ return ret;
+
+ data->close = val & ISG5320A_IRQSTS_PROX;
+
+ /* Release the INT line before unmasking the interrupt. */
+ ret = regmap_read(data->regmap, ISG5320A_REG_IRQSRC, &val);
+ if (ret)
+ return ret;
+
+ ret = regmap_write(data->regmap, ISG5320A_REG_IRQFUNC,
+ ISG5320A_IRQFUNC_ENABLE);
+ if (ret)
+ return ret;
+
+ /* Enabled events keep the chip awake until isg5320a_events_off(). */
+ pm_runtime_get_noresume(dev);
+ data->ev_enabled = true;
+
+ return 0;
+}
+
+static int isg5320a_events_off(struct isg5320a_data *data)
+{
+ struct device *dev = regmap_get_device(data->regmap);
+ int ret;
+
+ guard(mutex)(&data->lock);
+
+ ret = regmap_write(data->regmap, ISG5320A_REG_IRQFUNC,
+ ISG5320A_IRQFUNC_DISABLE);
+
+ data->ev_enabled = false;
+
+ /* Drop the reference kept by isg5320a_events_on(). */
+ pm_runtime_put_autosuspend(dev);
+
+ return ret;
+}
+
+static int isg5320a_write_event_config(struct iio_dev *indio_dev,
+ const struct iio_chan_spec *chan,
+ enum iio_event_type type,
+ enum iio_event_direction dir,
+ bool state)
+{
+ struct isg5320a_data *data = iio_priv(indio_dev);
+
+ if (type != IIO_EV_TYPE_THRESH || dir != IIO_EV_DIR_EITHER)
+ return -EINVAL;
+
+ guard(mutex)(&data->ev_lock);
+
+ if (state == data->ev_enabled)
+ return 0;
+
+ if (state)
+ return isg5320a_events_on(data);
+
+ return isg5320a_events_off(data);
+}
+
+static int isg5320a_read_event_value(struct iio_dev *indio_dev,
+ const struct iio_chan_spec *chan,
+ enum iio_event_type type,
+ enum iio_event_direction dir,
+ enum iio_event_info info,
+ int *val, int *val2)
+{
+ struct isg5320a_data *data = iio_priv(indio_dev);
+
+ if (type != IIO_EV_TYPE_THRESH || info != IIO_EV_INFO_VALUE)
+ return -EINVAL;
+
+ switch (dir) {
+ case IIO_EV_DIR_RISING:
+ *val = data->thresh + data->close_hyst;
+ return IIO_VAL_INT;
+ case IIO_EV_DIR_FALLING:
+ /*
+ * What the chip does with a far hysteresis above the
+ * threshold is not known; do not report a negative value.
+ */
+ *val = max((int)data->thresh - (int)data->far_hyst, 0);
+ return IIO_VAL_INT;
+ default:
+ return -EINVAL;
+ }
+}
+
+static const struct iio_event_spec isg5320a_events[] = {
+ {
+ .type = IIO_EV_TYPE_THRESH,
+ .dir = IIO_EV_DIR_RISING,
+ .mask_separate = BIT(IIO_EV_INFO_VALUE),
+ },
+ {
+ .type = IIO_EV_TYPE_THRESH,
+ .dir = IIO_EV_DIR_FALLING,
+ .mask_separate = BIT(IIO_EV_INFO_VALUE),
+ },
+ {
+ /* One chip-level IRQ enable (IRQFUNC) covers both directions. */
+ .type = IIO_EV_TYPE_THRESH,
+ .dir = IIO_EV_DIR_EITHER,
+ .mask_separate = BIT(IIO_EV_INFO_ENABLE),
+ },
+};
+
+static const struct iio_chan_spec isg5320a_channels[] = {
+ {
+ .type = IIO_PROXIMITY,
+ .indexed = 1,
+ .channel = 0,
+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+ .event_spec = isg5320a_events,
+ .num_event_specs = ARRAY_SIZE(isg5320a_events),
+ },
+};
+
+static const struct iio_info isg5320a_info = {
+ .read_raw = isg5320a_read_raw,
+ .read_event_config = isg5320a_read_event_config,
+ .write_event_config = isg5320a_write_event_config,
+ .read_event_value = isg5320a_read_event_value,
+};
+
+static void isg5320a_sleep_action(void *arg)
+{
+ struct isg5320a_data *data = arg;
+
+ /*
+ * Undo isg5320a_mode_normal(). Runtime PM is already disabled when
+ * this runs and the chip may or may not be asleep, so the sleep
+ * sequence is written unconditionally; it only sets registers to
+ * fixed values.
+ */
+ isg5320a_mode_sleep(data);
+}
+
+static void isg5320a_events_off_action(void *arg)
+{
+ struct isg5320a_data *data = arg;
+
+ guard(mutex)(&data->ev_lock);
+
+ /* Events left enabled still hold their runtime PM reference. */
+ if (data->ev_enabled)
+ isg5320a_events_off(data);
+}
+
+static int isg5320a_probe(struct i2c_client *client)
+{
+ struct device *dev = &client->dev;
+ struct isg5320a_data *data;
+ struct iio_dev *indio_dev;
+ int ret;
+
+ indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
+ if (!indio_dev)
+ return -ENOMEM;
+
+ data = iio_priv(indio_dev);
+ i2c_set_clientdata(client, indio_dev);
+
+ ret = devm_mutex_init(dev, &data->lock);
+ if (ret)
+ return ret;
+
+ ret = devm_mutex_init(dev, &data->ev_lock);
+ if (ret)
+ return ret;
+
+ ret = devm_regulator_get_enable(dev, "vdd");
+ if (ret)
+ return dev_err_probe(dev, ret, "failed to enable vdd\n");
+
+ /*
+ * The chip's start-up time is not documented. The vendor driver waits
+ * 5 ms before the first access with the supply already on; 15 ms is
+ * used here and works on the XCover5.
+ */
+ fsleep(15 * USEC_PER_MSEC);
+
+ data->regmap = devm_regmap_init_i2c(client, &isg5320a_regmap_config);
+ if (IS_ERR(data->regmap))
+ return dev_err_probe(dev, PTR_ERR(data->regmap),
+ "regmap init failed\n");
+
+ ret = isg5320a_reset(data);
+ if (ret)
+ return dev_err_probe(dev, ret, "reset failed\n");
+
+ /* 300 ms between reset and init, to match the vendor driver */
+ fsleep(300 * USEC_PER_MSEC);
+
+ ret = isg5320a_initialize(data);
+ if (ret)
+ return dev_err_probe(dev, ret, "init failed\n");
+
+ ret = isg5320a_mode_normal(data);
+ if (ret)
+ return dev_err_probe(dev, ret, "start failed\n");
+
+ ret = devm_add_action_or_reset(dev, isg5320a_sleep_action, data);
+ if (ret)
+ return ret;
+
+ pm_runtime_set_autosuspend_delay(dev, ISG5320A_AUTOSUSPEND_MS);
+ pm_runtime_use_autosuspend(dev);
+
+ ret = devm_pm_runtime_set_active_enabled(dev);
+ if (ret)
+ return ret;
+
+ indio_dev->name = "isg5320a";
+ indio_dev->modes = INDIO_DIRECT_MODE;
+ indio_dev->info = &isg5320a_info;
+ indio_dev->channels = isg5320a_channels;
+ indio_dev->num_channels = ARRAY_SIZE(isg5320a_channels);
+
+ ret = devm_request_threaded_irq(dev, client->irq, NULL,
+ isg5320a_irq_thread, IRQF_ONESHOT,
+ "isg5320a", indio_dev);
+ if (ret)
+ return ret;
+
+ /* On unbind: after the IIO device is gone, before the IRQ is freed. */
+ ret = devm_add_action_or_reset(dev, isg5320a_events_off_action, data);
+ if (ret)
+ return ret;
+
+ return devm_iio_device_register(dev, indio_dev);
+}
+
+static int isg5320a_runtime_suspend(struct device *dev)
+{
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct isg5320a_data *data = iio_priv(indio_dev);
+
+ return isg5320a_mode_sleep(data);
+}
+
+static int isg5320a_runtime_resume(struct device *dev)
+{
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct isg5320a_data *data = iio_priv(indio_dev);
+
+ return isg5320a_mode_normal(data);
+}
+
+static DEFINE_RUNTIME_DEV_PM_OPS(isg5320a_pm_ops, isg5320a_runtime_suspend,
+ isg5320a_runtime_resume, NULL);
+
+static const struct of_device_id isg5320a_of_match[] = {
+ { .compatible = "imagis,isg5320a" },
+ { }
+};
+MODULE_DEVICE_TABLE(of, isg5320a_of_match);
+
+static const struct i2c_device_id isg5320a_id[] = {
+ { .name = "isg5320a" },
+ { }
+};
+MODULE_DEVICE_TABLE(i2c, isg5320a_id);
+
+static struct i2c_driver isg5320a_driver = {
+ .driver = {
+ .name = "isg5320a",
+ .of_match_table = isg5320a_of_match,
+ .pm = pm_ptr(&isg5320a_pm_ops),
+ .probe_type = PROBE_PREFER_ASYNCHRONOUS,
+ },
+ .probe = isg5320a_probe,
+ .id_table = isg5320a_id,
+};
+module_i2c_driver(isg5320a_driver);
+
+MODULE_AUTHOR("Adil Hüsrev Tepe <tadilhusrev@gmail.com>");
+MODULE_DESCRIPTION("Imagis ISG5320A capacitive SAR/grip sensor");
+MODULE_LICENSE("GPL");
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v4 2/2] iio: proximity: add Imagis ISG5320A SAR sensor driver
2026-12-05 3:35 ` [PATCH v4 2/2] iio: proximity: add Imagis ISG5320A SAR sensor driver Adil Hüsrev Tepe
@ 2026-12-05 3:58 ` sashiko-bot
0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-12-05 3:58 UTC (permalink / raw)
To: Adil Hüsrev Tepe; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 8 potential
issues to consider:
- [Medium] iio: proximity: isg5320a_events_off() clears state and PM ref
on write error
- [Medium] iio: proximity: isg5320a_probe() skips client->irq validation
before request
- [Medium] iio: proximity: isg5320a IRQ thread races with system suspend
and events_off
- [Medium] iio: proximity: isg5320a leaves data->close stale after
system resume
- [Medium] iio: proximity: isg5320a_irq_thread() races with events
disable and sleep
- [Medium] iio: proximity: isg5320a unconditionally sleeps on suspend
despite wakeup-source
- [Medium] iio: isg5320a: isg5320a_read_irq_status() skips IRQSRC on
sample error
- [Low] iio: proximity: isg5320a_read_irq_status() skips IRQ ack on
sample error
--
commit 73f01735ba874407aefe2dc455ca4c17ad756481
Author: Adil Hüsrev Tepe <tadilhusrev@gmail.com>
iio: proximity: add Imagis ISG5320A SAR sensor driver
This commit adds an IIO driver for the Imagis ISG5320A capacitive
SAR/grip sensor over I2C, exposing a single proximity channel and
rising/falling threshold events with runtime PM support.
> diff --git a/drivers/iio/proximity/isg5320a.c b/drivers/iio/proximity/isg5320a.c
> new file mode 100644
> index 0000000000000..407f2c7e2d8ab
> --- /dev/null
> +++ b/drivers/iio/proximity/isg5320a.c
[ ... ]
> +static int isg5320a_read_irq_status(struct isg5320a_data *data, bool *close)
> +{
> + unsigned int val;
> + int ret;
> +
> + lockdep_assert_held(&data->lock);
> +
> + ret = isg5320a_read_sample(data);
> + if (ret)
> + return ret;
> +
> + ret = regmap_read(data->regmap, ISG5320A_REG_IRQSRC, &val);
> + if (ret)
> + return ret;
> +
> + ret = regmap_read(data->regmap, ISG5320A_REG_IRQSTS, &val);
> + if (ret)
> + return ret;
> +
> + *close = val & ISG5320A_IRQSTS_PROX;
> +
> + return 0;
> +}
[Severity: Medium]
Can an I2C error in isg5320a_read_sample() leave the active-low INT line
stuck asserted?
If the 4-byte bulk read fails, isg5320a_read_irq_status() returns early
without reading ISG5320A_REG_IRQSRC to release INT, and
isg5320a_irq_thread() then returns IRQ_HANDLED. Because
isg5320a_events_on() keeps runtime PM active, nothing else reads
ISG5320A_REG_IRQSRC, so falling-edge interrupts wedge until events are
toggled or the system suspends, and level-low interrupts re-trigger
immediately.
[Severity: Low]
Does isg5320a_read_irq_status() need to read the sample before
acknowledging the interrupt at all?
Neither isg5320a_read_irq_status() nor isg5320a_irq_thread() uses
data->cdc or data->base, and isg5320a_read_raw() calls
isg5320a_read_sample() itself. Reading ISG5320A_REG_IRQSRC and
ISG5320A_REG_IRQSTS first (or dropping the unused sample read here) avoids
gating interrupt acknowledgment on an unrelated bulk transfer.
> +static irqreturn_t isg5320a_irq_thread(int irq, void *private)
> +{
> + struct iio_dev *indio_dev = private;
> + struct isg5320a_data *data = iio_priv(indio_dev);
> + s64 timestamp = iio_get_time_ns(indio_dev);
> + enum iio_event_direction dir;
> + bool close;
> + int ret;
> +
> + guard(mutex)(&data->lock);
> +
> + ret = isg5320a_read_irq_status(data, &close);
> + if (ret) {
> + dev_err_ratelimited(regmap_get_device(data->regmap),
> + "irq status read failed: %d\n", ret);
> + return IRQ_HANDLED;
> + }
> +
> + if (close == data->close)
> + return IRQ_HANDLED;
> +
> + data->close = close;
> +
> + dir = close ? IIO_EV_DIR_RISING : IIO_EV_DIR_FALLING;
> + iio_push_event(indio_dev,
> + IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY, 0,
> + IIO_EV_TYPE_THRESH, dir),
> + timestamp);
> +
> + return IRQ_HANDLED;
> +}
[Severity: Medium]
Can isg5320a_irq_thread() access a runtime-suspended chip or push events
after userspace disables them?
isg5320a_events_off() writes ISG5320A_IRQFUNC_DISABLE and drops the
runtime PM reference without calling synchronize_irq(), and
isg5320a_irq_thread() neither takes a runtime PM reference nor checks
data->ev_enabled:
CPU0 CPU1
isg5320a_events_off()
lock(&data->lock)
isg5320a_irq_thread()
lock(&data->lock) (blocks)
regmap_write(IRQFUNC_DISABLE)
data->ev_enabled = false
pm_runtime_put_autosuspend()
unlock(&data->lock)
...
isg5320a_runtime_suspend()
isg5320a_mode_sleep()
isg5320a_read_irq_status() <-- sleeping
iio_push_event() <-- after disable
If an interrupt fires just before ISG5320A_IRQFUNC_DISABLE takes effect,
the pending thread can push a spurious event after write_event_config()
returns, or read registers after autosuspend has put the sensor to sleep
(for instance if autosuspend_delay_ms is set to 0).
[ ... ]
> +static int isg5320a_events_off(struct isg5320a_data *data)
> +{
> + struct device *dev = regmap_get_device(data->regmap);
> + int ret;
> +
> + guard(mutex)(&data->lock);
> +
> + ret = regmap_write(data->regmap, ISG5320A_REG_IRQFUNC,
> + ISG5320A_IRQFUNC_DISABLE);
> +
> + data->ev_enabled = false;
> +
> + /* Drop the reference kept by isg5320a_events_on(). */
> + pm_runtime_put_autosuspend(dev);
> +
> + return ret;
> +}
[Severity: Medium]
Should data->ev_enabled and the runtime PM reference stay intact when
regmap_write() fails here?
Clearing data->ev_enabled unconditionally causes a retry from
isg5320a_write_event_config() to hit the state == data->ev_enabled
shortcut and return 0 without disabling ISG5320A_REG_IRQFUNC, and
isg5320a_events_off_action() will also skip disabling it on unbind.
Meanwhile, dropping the runtime PM reference lets the sensor autosuspend
with hardware interrupts still enabled.
Keeping the sysfs disable path from clearing state or dropping the PM
reference on error (while still letting the unbind action drop the PM
reference unconditionally) avoids leaving hardware and driver state out
of sync.
[ ... ]
> + ret = devm_request_threaded_irq(dev, client->irq, NULL,
> + isg5320a_irq_thread, IRQF_ONESHOT,
> + "isg5320a", indio_dev);
> + if (ret)
> + return ret;
[Severity: Medium]
What happens if the I2C device is instantiated without an interrupt?
Because the driver has an i2c_device_id table, a device created via sysfs
new_device or incomplete firmware gets client->irq == 0 from
i2c_device_probe(). request_threaded_irq() only rejects IRQ_NOTCONNECTED
and otherwise passes 0 to irq_to_desc(0), which on architectures with a
legacy IRQ 0 either fails with a misleading -EBUSY or binds the handler
to IRQ 0 after powering on and calibrating the sensor.
Checking client->irq <= 0 early in isg5320a_probe() avoids both the
invalid IRQ request and the unnecessary hardware startup.
[ ... ]
> +static int isg5320a_runtime_resume(struct device *dev)
> +{
> + struct iio_dev *indio_dev = dev_get_drvdata(dev);
> + struct isg5320a_data *data = iio_priv(indio_dev);
> +
> + return isg5320a_mode_normal(data);
> +}
[Severity: Medium]
Can data->close become stale across system suspend and resume?
When proximity events are enabled, pm_runtime_force_suspend() puts the
sensor to sleep and pm_runtime_force_resume() restarts and recalibrates
it via isg5320a_mode_normal(), without refreshing data->close from
ISG5320A_REG_IRQSTS as isg5320a_events_on() does. If the device was
gripped before suspend and released while suspended, the recalibrated
chip starts in the far state while data->close is still true, so
isg5320a_irq_thread() suppresses the next rising proximity event.
> +static DEFINE_RUNTIME_DEV_PM_OPS(isg5320a_pm_ops, isg5320a_runtime_suspend,
> + isg5320a_runtime_resume, NULL);
[Severity: Medium]
Does DEFINE_RUNTIME_DEV_PM_OPS() allow isg5320a_irq_thread() to race with
system suspend and resume?
pm_runtime_force_suspend() runs isg5320a_mode_sleep() during
dpm_suspend(), before dpm_suspend_noirq() calls suspend_device_irqs(),
and isg5320a_mode_sleep() does not disable ISG5320A_REG_IRQFUNC or
client->irq:
CPU0 CPU1
dpm_suspend()
pm_runtime_force_suspend()
isg5320a_mode_sleep()
lock(&data->lock)
isg5320a_irq_thread()
lock(&data->lock) (blocks)
regmap_multi_reg_write(sleep)
unlock(&data->lock)
<parent I2C adapter suspends>
isg5320a_read_irq_status() <-- bus/chip
suspended
Symmetrically, on resume dpm_resume_noirq() re-enables client->irq before
pm_runtime_force_resume() wakes and recalibrates the chip with IRQFUNC
still enabled. Using explicit system sleep callbacks that disable/enable
client->irq around sleep would close both windows.
[Severity: Medium]
Does putting the sensor to sleep unconditionally on system suspend break
the wakeup-source property in the DT binding?
Documentation/devicetree/bindings/iio/proximity/imagis,isg5320a.yaml
documents wakeup-source, which causes the I2C core to call
device_init_wakeup() and dev_pm_set_wake_irq() automatically. Because
pm_runtime_force_suspend() always calls isg5320a_mode_sleep() without
checking device_may_wakeup(dev), the chip stops scanning during suspend
and can never wake the system.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261205-isg5320a-v4-0-a9bb8573c064@gmail.com?part=2
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-05 3:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 3:35 [PATCH v4 0/2] iio: proximity: add Imagis ISG5320A (Samsung Galaxy XCover5) Adil Hüsrev Tepe
2026-12-05 3:35 ` [PATCH v4 1/2] dt-bindings: iio: proximity: add Imagis ISG5320A Adil Hüsrev Tepe
2026-12-05 3:35 ` [PATCH v4 2/2] iio: proximity: add Imagis ISG5320A SAR sensor driver Adil Hüsrev Tepe
2026-12-05 3:58 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox