All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 0/2] iio: proximity: add Imagis ISG5320A (Samsung Galaxy XCover5)
@ 2026-11-16  7:40 Adil Hüsrev Tepe
  2026-11-16  7:40 ` [PATCH v1 1/2] dt-bindings: iio: proximity: add Imagis ISG5320A Adil Hüsrev Tepe
                   ` (4 more replies)
  0 siblings, 5 replies; 18+ messages in thread
From: Adil Hüsrev Tepe @ 2026-11-16  7:40 UTC (permalink / raw)
  To: Jonathan Cameron, Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: David Lechner, Nuno Sá, Andy Shevchenko, linux-iio,
	devicetree, linux-kernel, Adil Hüsrev Tepe

This series adds an IIO driver and its binding for the Imagis ISG5320A
capacitive SAR/grip proximity sensor, as fitted on the Samsung Galaxy
XCover5 (Exynos850).

  1  dt-bindings: add imagis,isg5320a
  2  the IIO proximity driver

The driver exposes one IIO_PROXIMITY channel (the B-channel signal minus
its baseline) and a rising/falling threshold event. Tested on an XCover5:
it probes, registers the IIO device and reads a stable baseline value.

Based on v7.4-rc1.

Tool usage
----------
Derived from the Samsung vendor driver during XCover5 mainline bring-up
with an AI coding assistant (Claude Code, Anthropic), which drafted the
mainline IIO driver and the binding. I reviewed every line and tested
probe and read-back on hardware. 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

 .../iio/proximity/imagis,isg5320a.yaml        |  56 ++
 drivers/iio/proximity/Kconfig                 |  11 +
 drivers/iio/proximity/Makefile                |   1 +
 drivers/iio/proximity/isg5320a.c              | 857 ++++++++++++++++++
 4 files changed, 925 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/proximity/imagis,isg5320a.yaml
 create mode 100644 drivers/iio/proximity/isg5320a.c

-- 
2.53.0


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v1 1/2] dt-bindings: iio: proximity: add Imagis ISG5320A
  2026-11-16  7:40 [PATCH v1 0/2] iio: proximity: add Imagis ISG5320A (Samsung Galaxy XCover5) Adil Hüsrev Tepe
@ 2026-11-16  7:40 ` Adil Hüsrev Tepe
  2026-11-16  7:51   ` sashiko-bot
  2026-11-16  7:40 ` [PATCH v1 2/2] iio: proximity: add Imagis ISG5320A SAR sensor driver Adil Hüsrev Tepe
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 18+ messages in thread
From: Adil Hüsrev Tepe @ 2026-11-16  7:40 UTC (permalink / raw)
  To: Jonathan Cameron, Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: David Lechner, Nuno Sá, Andy Shevchenko, linux-iio,
	devicetree, linux-kernel, Adil Hüsrev Tepe

Add a binding for the Imagis ISG5320A capacitive SAR/grip proximity
sensor (I2C), as fitted on the Samsung Galaxy XCover5.

The binding was drafted during XCover5 mainline bring-up with the help
of an AI coding assistant (Claude Code, Anthropic) and reviewed and
validated (dt_binding_check, yamllint) by me.

Signed-off-by: Adil Hüsrev Tepe <tadilhusrev@gmail.com>
---
 .../iio/proximity/imagis,isg5320a.yaml        | 56 +++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/proximity/imagis,isg5320a.yaml

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 000000000..b23d6bafd
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/proximity/imagis,isg5320a.yaml
@@ -0,0 +1,56 @@
+# 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 sensor (I2C), exposed as one IIO
+  proximity channel (B-channel diff = CDC16_T - BSL16_B). As fitted on the
+  Samsung Galaxy XCover5.
+
+properties:
+  compatible:
+    const: imagis,isg5320a
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+    description: active-low data-ready / proximity interrupt
+
+  vdd-supply:
+    description: sensor supply
+
+  wakeup-source: true
+
+required:
+  - compatible
+  - reg
+  - interrupts
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+        grip@28 {
+            compatible = "imagis,isg5320a";
+            reg = <0x28>;
+            interrupt-parent = <&gpa2>;
+            interrupts = <0 IRQ_TYPE_LEVEL_LOW>;
+            vdd-supply = <&grip_vdd>;
+            wakeup-source;
+        };
+    };
+...
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v1 2/2] iio: proximity: add Imagis ISG5320A SAR sensor driver
  2026-11-16  7:40 [PATCH v1 0/2] iio: proximity: add Imagis ISG5320A (Samsung Galaxy XCover5) Adil Hüsrev Tepe
  2026-11-16  7:40 ` [PATCH v1 1/2] dt-bindings: iio: proximity: add Imagis ISG5320A Adil Hüsrev Tepe
@ 2026-11-16  7:40 ` Adil Hüsrev Tepe
  2026-11-16  7:58   ` sashiko-bot
  2026-11-16 10:53   ` Andy Shevchenko
  2026-11-16 10:48 ` [PATCH v1 0/2] iio: proximity: add Imagis ISG5320A (Samsung Galaxy XCover5) Andy Shevchenko
                   ` (2 subsequent siblings)
  4 siblings, 2 replies; 18+ messages in thread
From: Adil Hüsrev Tepe @ 2026-11-16  7:40 UTC (permalink / raw)
  To: Jonathan Cameron, Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: David Lechner, Nuno Sá, Andy Shevchenko, linux-iio,
	devicetree, linux-kernel, 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.

The driver was derived from the Samsung vendor driver during XCover5
mainline bring-up with the help of an AI coding assistant (Claude Code,
Anthropic), which drafted the mainline IIO driver; I reviewed every line
and tested it on hardware.

Signed-off-by: Adil Hüsrev Tepe <tadilhusrev@gmail.com>
---
 drivers/iio/proximity/Kconfig    |  11 +
 drivers/iio/proximity/Makefile   |   1 +
 drivers/iio/proximity/isg5320a.c | 857 +++++++++++++++++++++++++++++++
 3 files changed, 869 insertions(+)
 create mode 100644 drivers/iio/proximity/isg5320a.c

diff --git a/drivers/iio/proximity/Kconfig b/drivers/iio/proximity/Kconfig
index bb77fad2a..c5df6f0e0 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 SAR proximity sensor"
+	depends on I2C
+	select REGMAP_I2C
+	help
+	  Say Y here to build a driver for the Imagis ISG5320A capacitive
+	  SAR/grip proximity 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 4352833dd..6aa606fa5 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 000000000..533267035
--- /dev/null
+++ b/drivers/iio/proximity/isg5320a.c
@@ -0,0 +1,857 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Imagis ISG5320A capacitive grip (SAR proximity) sensor.
+ *
+ * Register map, init table and every write sequence below come from the
+ * Samsung vendor driver (drivers/sensors/isg5320a.c + isg5320a_reg.h,
+ * Galaxy XCover5 5.10 tree, Copyright (C) Imagis Technology). Citations of
+ * the form "vendor :NNN" refer to lines in that isg5320a.c. This driver
+ * writes no register the vendor driver does not write, and only with the
+ * values the vendor writes; regmap enforces that through writeable_reg.
+ *
+ * The chip is used as one proximity channel: the vendor's "diff" value
+ * (CDC16_T - BSL16_B, i.e. 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/bits.h>
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/gpio/consumer.h>
+#include <linux/i2c.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/kernel.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/pm.h>
+#include <linux/pm_runtime.h>
+#include <linux/pm_wakeup.h>
+#include <linux/property.h>
+#include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
+
+#include <linux/iio/events.h>
+#include <linux/iio/iio.h>
+
+/* Registers (vendor isg5320a_reg.h :19-79) */
+#define ISG5320A_REG_IRQSRC		0x00	/* read releases the INT line */
+#define ISG5320A_REG_IRQSTS		0x01
+#define   ISG5320A_IRQSTS_PROX		BIT(4)	/* ISG5320A_PROX_STATE, reg.h :81 */
+#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_REG_SCANCTRL2		0x39
+#define   ISG5320A_SCAN2_RESET		0x00
+#define   ISG5320A_SCAN2_CLEAR		0x60
+#define   ISG5320A_BFCAL_START		0x07
+/* CDC16_T_H, CDC16_T_L, BSL16_B_H, BSL16_B_L (vendor :453) */
+#define ISG5320A_REG_CDC16_T_H		0x5C
+/* B_PROXCTL3..5: threshold, close hysteresis, far hysteresis (vendor :890) */
+#define ISG5320A_REG_B_PROXCTL3		0x9B
+#define ISG5320A_REG_DIGITAL_ACC	0xA4
+#define ISG5320A_REG_PROTECT		0xCD
+#define   ISG5320A_PROTECT_UNLOCK	0xDE
+#define ISG5320A_REG_SOFTRESET		0xFD
+#define   ISG5320A_SOFTRESET_VAL	0xDE
+#define ISG5320A_REG_CHIPID		0xFE
+#define ISG5320A_MAX_REG		0xFE
+
+#define ISG5320A_VENDOR_CHIP_ID		0x32	/* vendor :39, never checked */
+#define ISG5320A_RESET_CONDITION	5000	/* reg.h :99, for cfcal_th */
+
+#define ISG5320A_AUTOSUSPEND_MS		5000
+
+struct isg5320a_reg_data {
+	u8 addr;
+	u8 val;
+};
+
+/*
+ * Vendor setup_reg[] for "XCOVER5 ALL" (isg5320a_reg.h :283-435). The other
+ * table (:130-282) is under CONFIG_SENSORS_ISG5320A_XCOVER5_KOR, which the
+ * stock exynos850-xcover5xx_defconfig leaves unset; it differs only in
+ * 0x9C (threshold low byte), 0xA0 (far hysteresis low byte) and 0xBA.
+ */
+static const struct isg5320a_reg_data 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 }, { 0x41, 0x11 }, { 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 }, { 0xC5, 0x00 }, { 0x13, 0x3A },
+	{ 0x18, 0xF1 }, /* A ch : CS0, B ch : 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 },
+};
+
+struct isg5320a_data {
+	struct device *dev;
+	struct regmap *regmap;
+	struct gpio_desc *int_gpio;
+	int irq;
+	/* Serialises multi-register chip sequences and the cached sample. */
+	struct mutex lock;
+	/* Serialises event enable/disable (sleeps in disable_irq()). */
+	struct mutex ev_lock;
+	bool ev_enabled;
+	bool close;
+	u16 cdc;
+	u16 base;
+	u16 thresh;
+	u16 close_hyst;
+	u16 far_hyst;
+	u32 cfcal_th;
+};
+
+static bool isg5320a_writeable_reg(struct device *dev, unsigned int reg)
+{
+	unsigned int i;
+
+	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 (i = 0; i < ARRAY_SIZE(isg5320a_setup_reg); i++)
+		if (isg5320a_setup_reg[i].addr == 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;
+}
+
+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,
+};
+
+/* Wait for the INT line to reach @level: up to 10 x 5 ms (vendor :262, :281). */
+static int isg5320a_wait_int(struct isg5320a_data *data, int level)
+{
+	int cnt;
+
+	if (!data->int_gpio) {
+		msleep(50);
+		return 0;
+	}
+
+	for (cnt = 0; cnt < 10; cnt++) {
+		if (gpiod_get_raw_value_cansleep(data->int_gpio) == level)
+			return cnt;
+		usleep_range(5000, 5100);
+	}
+
+	return -ETIMEDOUT;
+}
+
+/* vendor isg5320a_reset(), :247-292, plus a CHIPID read the vendor never does */
+static int isg5320a_reset(struct isg5320a_data *data)
+{
+	struct device *dev = data->dev;
+	unsigned int val;
+	int ret;
+
+	usleep_range(5000, 5100);				/* :255-256 */
+
+	ret = regmap_read(data->regmap, ISG5320A_REG_IRQSRC, &val);	/* :258 */
+	if (ret)
+		return dev_err_probe(dev, ret, "no response at IRQSRC\n");
+
+	ret = regmap_read(data->regmap, ISG5320A_REG_CHIPID, &val);
+	if (ret)
+		return dev_err_probe(dev, ret, "CHIPID read failed\n");
+	if (val == ISG5320A_VENDOR_CHIP_ID)
+		dev_info(dev, "CHIPID 0x%02x\n", val);
+	else
+		dev_warn(dev, "CHIPID 0x%02x (vendor header says 0x%02x; not enforced)\n",
+			 val, ISG5320A_VENDOR_CHIP_ID);
+
+	if (isg5320a_wait_int(data, 1) < 0)			/* :262-266 */
+		dev_warn(dev, "INT did not go high before reset\n");
+
+	ret = regmap_write(data->regmap, ISG5320A_REG_PROTECT,	/* :268-271 */
+			   ISG5320A_PROTECT_UNLOCK);
+	if (ret)
+		dev_warn(dev, "unlock protect failed: %d\n", ret);
+
+	ret = regmap_write(data->regmap, ISG5320A_REG_SOFTRESET,	/* :273-276 */
+			   ISG5320A_SOFTRESET_VAL);
+	if (ret)
+		dev_warn(dev, "soft reset write failed: %d\n", ret);
+
+	usleep_range(1000, 1100);				/* :278 */
+
+	ret = isg5320a_wait_int(data, 0);			/* :280-289 */
+	if (ret < 0)
+		return dev_err_probe(dev, -EIO, "INT not asserted after soft reset\n");
+	dev_dbg(dev, "reset done, wait cnt %d\n", ret);
+
+	return 0;
+}
+
+/* vendor isg5320a_initialize(), :614-660, without the /sdcard override */
+static int isg5320a_initialize(struct isg5320a_data *data)
+{
+	struct device *dev = data->dev;
+	unsigned int i, val, mismatch = 0;
+	u8 buf[6];
+	int ret;
+
+	guard(mutex)(&data->lock);
+
+	ret = regmap_read(data->regmap, ISG5320A_REG_IRQSRC, &val);	/* :625 */
+	if (ret)
+		return ret;
+	ret = regmap_write(data->regmap, ISG5320A_REG_SCANCTRL1,	/* :626 */
+			   ISG5320A_SCAN_STOP);
+	if (ret)
+		return ret;
+	msleep(30);						/* :627 */
+
+	for (i = 0; i < ARRAY_SIZE(isg5320a_setup_reg); i++) {	/* :631-637 */
+		const struct isg5320a_reg_data *r = &isg5320a_setup_reg[i];
+
+		ret = regmap_write(data->regmap, r->addr, r->val);
+		if (ret)
+			return dev_err_probe(dev, ret, "init write 0x%02x failed\n",
+					     r->addr);
+		ret = regmap_read(data->regmap, r->addr, &val);
+		if (ret)
+			return ret;
+		if (val != r->val) {
+			mismatch++;
+			dev_dbg(dev, "reg 0x%02x wrote 0x%02x read 0x%02x\n",
+				r->addr, r->val, val);
+		}
+	}
+	dev_info(dev, "init table: %zu writes, %u read back different\n",
+		 ARRAY_SIZE(isg5320a_setup_reg), mismatch);
+
+	/* :646-650 reads the threshold; :890-897 reads all six bytes */
+	ret = regmap_bulk_read(data->regmap, ISG5320A_REG_B_PROXCTL3, buf,
+			       sizeof(buf));
+	if (ret)
+		return ret;
+	data->thresh = (buf[0] << 8) | buf[1];
+	data->close_hyst = (buf[2] << 8) | buf[3];
+	data->far_hyst = (buf[4] << 8) | buf[5];
+
+	ret = regmap_read(data->regmap, ISG5320A_REG_DIGITAL_ACC, &val);	/* :653-657 */
+	if (ret)
+		return ret;
+	data->cfcal_th = ISG5320A_RESET_CONDITION * val / 8;
+
+	dev_info(dev, "threshold %u, close hyst %u, far hyst %u, cfcal_th %u\n",
+		 data->thresh, data->close_hyst, data->far_hyst, data->cfcal_th);
+
+	return 0;
+}
+
+/* vendor isg5320a_set_mode(SLEEP), :749-755 */
+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;
+	ret = regmap_write(data->regmap, ISG5320A_REG_SCANCTRL1, ISG5320A_SCAN_STOP);
+	if (ret)
+		return ret;
+	ret = regmap_write(data->regmap, ISG5320A_REG_OSCCON, ISG5320A_OSC_SLEEP);
+	if (ret)
+		return ret;
+	return regmap_write(data->regmap, ISG5320A_REG_BS_ON_WD, ISG5320A_BS_WD_OFF);
+}
+
+/*
+ * vendor isg5320a_set_mode(NORMAL), :749 + :757-758, which runs
+ * isg5320a_force_calibration(data, false), :302-321.
+ */
+static int isg5320a_mode_normal(struct isg5320a_data *data)
+{
+	struct regmap *map = data->regmap;
+	unsigned int val;
+	int ret;
+
+	guard(mutex)(&data->lock);
+
+	ret = regmap_read(map, ISG5320A_REG_IRQSRC, &val);			/* :749 */
+	if (ret)
+		return ret;
+	ret = regmap_write(map, ISG5320A_REG_BS_ON_WD, ISG5320A_BS_WD_ON);	/* :757 */
+	if (ret)
+		return ret;
+
+	ret = regmap_write(map, ISG5320A_REG_SCANCTRL1, ISG5320A_SCAN_STOP);	/* :303 */
+	if (ret)
+		return ret;
+	msleep(30);								/* :305 */
+	ret = regmap_write(map, ISG5320A_REG_BS_ON_WD, ISG5320A_BS_WD_OFF);	/* :306 */
+	if (ret)
+		return ret;
+	ret = regmap_write(map, ISG5320A_REG_SCANCTRL2, ISG5320A_SCAN2_CLEAR);	/* :307 */
+	if (ret)
+		return ret;
+	msleep(100);								/* :309 */
+	ret = regmap_write(map, ISG5320A_REG_OSCCON, ISG5320A_OSC_NORMAL);	/* :310 */
+	if (ret)
+		return ret;
+	ret = regmap_write(map, ISG5320A_REG_BS_ON_WD, ISG5320A_BS_WD_ON);	/* :312 */
+	if (ret)
+		return ret;
+	ret = regmap_write(map, ISG5320A_REG_SCANCTRL2, ISG5320A_SCAN2_RESET);	/* :313 */
+	if (ret)
+		return ret;
+	ret = regmap_write(map, ISG5320A_REG_SCANCTRL1, ISG5320A_CFCAL_START);	/* :316 */
+	if (ret)
+		return ret;
+	msleep(500);								/* :318 */
+	ret = regmap_write(map, ISG5320A_REG_SCANCTRL2, ISG5320A_BFCAL_START);	/* :321 */
+	if (ret)
+		return ret;
+
+	/* The vendor sw_reset path waits 300 ms after BFCAL before reading (:850-852). */
+	msleep(300);
+
+	return 0;
+}
+
+/* vendor isg5320a_get_raw_data(), :445-466; caller holds data->lock */
+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 discarded and the last value kept (:459-464) */
+	v = (buf[0] << 8) | buf[1];
+	if (v != 0 && v != 0xFFFF)
+		data->cdc = v;
+	v = (buf[2] << 8) | buf[3];
+	if (v != 0 && v != 0xFFFF)
+		data->base = v;
+
+	return 0;
+}
+
+static int isg5320a_get_sample(struct isg5320a_data *data, u16 *cdc, u16 *base)
+{
+	struct device *dev = data->dev;
+	int ret;
+
+	ret = pm_runtime_resume_and_get(dev);
+	if (ret)
+		return ret;
+
+	scoped_guard(mutex, &data->lock) {
+		ret = isg5320a_read_sample(data);
+		*cdc = data->cdc;
+		*base = data->base;
+	}
+
+	pm_runtime_put_autosuspend(dev);
+
+	/*
+	 * The vendor cal_work (:1640-1647) force-recalibrates when cdc drops
+	 * below cfcal_th. That loop is not ported; only report the condition.
+	 */
+	if (!ret && *cdc < data->cfcal_th)
+		dev_warn_ratelimited(dev, "cdc %u below cfcal_th %u (vendor would recalibrate)\n",
+				     *cdc, data->cfcal_th);
+
+	return ret;
+}
+
+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);
+	unsigned int src, sts;
+	bool changed = false;
+	bool close = false;
+	int ret;
+
+	scoped_guard(mutex, &data->lock) {
+		isg5320a_read_sample(data);				/* :581 */
+
+		ret = regmap_read(data->regmap, ISG5320A_REG_IRQSRC, &src);	/* :583 */
+		if (ret)
+			break;
+		ret = regmap_read(data->regmap, ISG5320A_REG_IRQSTS, &sts);	/* :598 */
+		if (ret)
+			break;
+
+		close = sts & ISG5320A_IRQSTS_PROX;			/* :518 */
+		changed = close != data->close;
+		data->close = close;
+	}
+
+	if (ret) {
+		dev_err_ratelimited(data->dev, "irq status read failed: %d\n", ret);
+		return IRQ_HANDLED;
+	}
+
+	dev_dbg(data->dev, "irq src 0x%02x sts 0x%02x cdc %u base %u\n",
+		src, sts, data->cdc, data->base);
+
+	if (changed && READ_ONCE(data->ev_enabled)) {
+		enum iio_event_direction dir;
+
+		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);
+	u16 cdc, base;
+	int ret;
+
+	switch (mask) {
+	case IIO_CHAN_INFO_RAW:
+		ret = isg5320a_get_sample(data, &cdc, &base);
+		if (ret)
+			return ret;
+		*val = (int)cdc - (int)base;				/* :465 */
+		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;
+
+	return READ_ONCE(data->ev_enabled);
+}
+
+/* vendor isg5320a_set_enable(), :681-742 (minus the work items) */
+static int isg5320a_events_on(struct isg5320a_data *data)
+{
+	struct device *dev = data->dev;
+	unsigned int val;
+	int ret;
+
+	ret = pm_runtime_resume_and_get(dev);
+	if (ret)
+		return ret;
+
+	scoped_guard(mutex, &data->lock) {
+		ret = regmap_read(data->regmap, ISG5320A_REG_IRQSTS, &val);	/* :700 */
+		if (ret)
+			break;
+		data->close = val & ISG5320A_IRQSTS_PROX;		/* :708-713 */
+		isg5320a_read_sample(data);				/* :704 */
+		ret = regmap_read(data->regmap, ISG5320A_REG_IRQSRC, &val);	/* :718 */
+		if (ret)
+			break;
+		ret = regmap_write(data->regmap, ISG5320A_REG_IRQFUNC,	/* :719 */
+				   ISG5320A_IRQFUNC_ENABLE);
+	}
+	if (ret) {
+		pm_runtime_put_autosuspend(dev);
+		return ret;
+	}
+
+	WRITE_ONCE(data->ev_enabled, true);
+	enable_irq(data->irq);						/* :721 */
+	if (device_may_wakeup(dev))
+		enable_irq_wake(data->irq);				/* :722 */
+
+	dev_dbg(dev, "events on, initial state %s\n", data->close ? "close" : "far");
+
+	return 0;
+}
+
+static void isg5320a_events_off(struct isg5320a_data *data)
+{
+	struct device *dev = data->dev;
+	int ret = 0;
+
+	scoped_guard(mutex, &data->lock)
+		ret = regmap_write(data->regmap, ISG5320A_REG_IRQFUNC,	/* :726 */
+				   ISG5320A_IRQFUNC_DISABLE);
+	if (ret)
+		dev_warn(dev, "IRQFUNC disable failed: %d\n", ret);
+
+	WRITE_ONCE(data->ev_enabled, false);
+	disable_irq(data->irq);						/* :728 */
+	if (device_may_wakeup(dev))
+		disable_irq_wake(data->irq);				/* :729 */
+}
+
+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);
+
+	isg5320a_events_off(data);
+	pm_runtime_put_autosuspend(data->dev);
+
+	return 0;
+}
+
+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;
+
+	/* vendor normal_threshold_show, :896-897 */
+	switch (dir) {
+	case IIO_EV_DIR_RISING:
+		*val = data->thresh + data->close_hyst;
+		return IIO_VAL_INT;
+	case IIO_EV_DIR_FALLING:
+		*val = (int)data->thresh - (int)data->far_hyst;
+		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),
+	},
+};
+
+#define ISG5320A_CHANNEL(_events, _nevents)			\
+	{							\
+		.type = IIO_PROXIMITY,				\
+		.indexed = 1,					\
+		.channel = 0,					\
+		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),	\
+		.event_spec = _events,				\
+		.num_event_specs = _nevents,			\
+	}
+
+static const struct iio_chan_spec isg5320a_channels[] = {
+	ISG5320A_CHANNEL(isg5320a_events, ARRAY_SIZE(isg5320a_events)),
+};
+
+static const struct iio_chan_spec isg5320a_channels_noirq[] = {
+	ISG5320A_CHANNEL(NULL, 0),
+};
+
+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 const struct iio_info isg5320a_info_noirq = {
+	.read_raw = isg5320a_read_raw,
+};
+
+/* vendor isg5320a_remove(), :2030-2033 */
+static void isg5320a_teardown(void *arg)
+{
+	struct isg5320a_data *data = arg;
+	struct device *dev = data->dev;
+
+	pm_runtime_disable(dev);
+
+	if (data->ev_enabled) {
+		isg5320a_events_off(data);
+		pm_runtime_put_noidle(dev);
+	}
+
+	if (!pm_runtime_status_suspended(dev))
+		isg5320a_mode_sleep(data);
+
+	pm_runtime_set_suspended(dev);
+	pm_runtime_dont_use_autosuspend(dev);
+}
+
+static int isg5320a_probe(struct i2c_client *client)
+{
+	struct device *dev = &client->dev;
+	struct isg5320a_data *data;
+	struct iio_dev *indio_dev;
+	unsigned long irqflags;
+	int ret;
+
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
+	if (!indio_dev)
+		return -ENOMEM;
+
+	data = iio_priv(indio_dev);
+	data->dev = dev;
+	data->irq = client->irq;
+	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;
+
+	/* The vendor node has no supply; the board relies on an always-on LDO. */
+	ret = devm_regulator_get_enable_optional(dev, "vdd");
+	if (ret && ret != -ENODEV)
+		return dev_err_probe(dev, ret, "failed to enable vdd\n");
+	/*
+	 * If the rail was just switched on, give the chip time to come out
+	 * of power-on reset. The vendor never switches it, so this value
+	 * (10 ms) is a guess, not from the vendor source.
+	 */
+	if (!ret)
+		usleep_range(10000, 11000);
+
+	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");
+
+	/*
+	 * Optional: lets the reset sequence watch the INT level as the vendor
+	 * does. It is requested before the IRQ (same order as vendor :1873 vs
+	 * :1931), since on Samsung pinctrl the IRQ request switches the pin
+	 * back to its EINT function.
+	 */
+	data->int_gpio = devm_gpiod_get_optional(dev, "int", GPIOD_IN);
+	if (IS_ERR(data->int_gpio))
+		return dev_err_probe(dev, PTR_ERR(data->int_gpio), "int gpio\n");
+	if (!data->int_gpio)
+		dev_info(dev, "no int-gpios, reset uses fixed delays\n");
+
+	ret = isg5320a_reset(data);				/* :1915 */
+	if (ret)
+		return ret;
+
+	msleep(300);			/* vendor runs init_work 300 ms later, :1981 */
+
+	ret = isg5320a_initialize(data);			/* :1620 */
+	if (ret)
+		return dev_err_probe(dev, ret, "init failed\n");
+
+	ret = isg5320a_mode_normal(data);			/* :1621 */
+	if (ret)
+		return dev_err_probe(dev, ret, "start failed\n");
+
+	if (data->irq > 0) {
+		irqflags = irq_get_trigger_type(data->irq);
+		if (!irqflags)
+			irqflags = IRQF_TRIGGER_FALLING;	/* :1932 */
+
+		ret = devm_request_threaded_irq(dev, data->irq, NULL,
+						isg5320a_irq_thread,
+						irqflags | IRQF_ONESHOT |
+						IRQF_NO_AUTOEN,
+						"isg5320a", indio_dev);
+		if (ret)
+			return dev_err_probe(dev, ret, "irq request failed\n");
+
+		if (device_property_read_bool(dev, "wakeup-source"))
+			device_init_wakeup(dev, true);
+	}
+
+	pm_runtime_set_autosuspend_delay(dev, ISG5320A_AUTOSUSPEND_MS);
+	pm_runtime_use_autosuspend(dev);
+	pm_runtime_set_active(dev);
+	pm_runtime_get_noresume(dev);
+	pm_runtime_enable(dev);
+	pm_runtime_put_autosuspend(dev);
+
+	ret = devm_add_action_or_reset(dev, isg5320a_teardown, data);
+	if (ret)
+		return ret;
+
+	indio_dev->name = "isg5320a";
+	indio_dev->modes = INDIO_DIRECT_MODE;
+	if (data->irq > 0) {
+		indio_dev->info = &isg5320a_info;
+		indio_dev->channels = isg5320a_channels;
+		indio_dev->num_channels = ARRAY_SIZE(isg5320a_channels);
+	} else {
+		indio_dev->info = &isg5320a_info_noirq;
+		indio_dev->channels = isg5320a_channels_noirq;
+		indio_dev->num_channels = ARRAY_SIZE(isg5320a_channels_noirq);
+	}
+
+	return devm_iio_device_register(dev, indio_dev);
+}
+
+/* vendor isg5320a_shutdown(), :2071-2080 */
+static void isg5320a_shutdown(struct i2c_client *client)
+{
+	struct isg5320a_data *data = iio_priv(i2c_get_clientdata(client));
+
+	guard(mutex)(&data->ev_lock);
+
+	if (data->ev_enabled)
+		regmap_write(data->regmap, ISG5320A_REG_IRQFUNC,
+			     ISG5320A_IRQFUNC_DISABLE);
+	isg5320a_mode_sleep(data);
+}
+
+static int isg5320a_runtime_suspend(struct device *dev)
+{
+	struct isg5320a_data *data = iio_priv(dev_get_drvdata(dev));
+
+	return isg5320a_mode_sleep(data);
+}
+
+static int isg5320a_runtime_resume(struct device *dev)
+{
+	struct isg5320a_data *data = iio_priv(dev_get_drvdata(dev));
+
+	return isg5320a_mode_normal(data);
+}
+
+/*
+ * Runtime PM only. System sleep leaves the chip as it is, as the vendor
+ * does (its suspend/resume only stop and restart the work items), so an
+ * enabled grip event can still wake the system.
+ */
+static const struct dev_pm_ops isg5320a_pm_ops = {
+	RUNTIME_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[] = {
+	{ "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,
+	.shutdown = isg5320a_shutdown,
+	.id_table = isg5320a_id,
+};
+module_i2c_driver(isg5320a_driver);
+
+MODULE_AUTHOR("Adil Hüsrev Tepe <tadilhusrev@gmail.com>");
+MODULE_DESCRIPTION("Imagis ISG5320A capacitive grip sensor");
+MODULE_LICENSE("GPL");
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH v1 1/2] dt-bindings: iio: proximity: add Imagis ISG5320A
  2026-11-16  7:40 ` [PATCH v1 1/2] dt-bindings: iio: proximity: add Imagis ISG5320A Adil Hüsrev Tepe
@ 2026-11-16  7:51   ` sashiko-bot
  0 siblings, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-11-16  7:51 UTC (permalink / raw)
  To: Adil Hüsrev Tepe; +Cc: devicetree, robh, conor+dt

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] dt-bindings: iio: proximity: imagis,isg5320a: style and example
  issues
- [Low] dt-bindings: iio: proximity: imagis,isg5320a: OS-specific
  description
--

commit e012fe4a93b96b30e3eac1a75009b8703a8aa96e
Author: Adil Hüsrev Tepe <tadilhusrev@gmail.com>

dt-bindings: iio: proximity: add Imagis ISG5320A

This commit adds a Devicetree binding schema for the Imagis ISG5320A I2C
capacitive SAR/grip proximity sensor.

> 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 0000000000000..b23d6bafd39e3
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/iio/proximity/imagis,isg5320a.yaml
> @@ -0,0 +1,56 @@

[ ... ]

> +description:
> +  Imagis ISG5320A capacitive SAR/grip sensor (I2C), exposed as one IIO
> +  proximity channel (B-channel diff = CDC16_T - BSL16_B). As fitted on the
> +  Samsung Galaxy XCover5.
> +
> +properties:
> +  compatible:
> +    const: imagis,isg5320a
> +
> +  reg:
> +    maxItems: 1
> +
> +  interrupts:
> +    maxItems: 1
> +    description: active-low data-ready / proximity interrupt
> +
> +  vdd-supply:
> +    description: sensor supply
> +
> +  wakeup-source: true
> +
> +required:
> +  - compatible
> +  - reg
> +  - interrupts

[Severity: Low]
Could the description focus on the hardware characteristics of the ISG5320A
rather than how the Linux IIO driver exposes a single channel or which
board uses it?

Also, vdd-supply can simply be "vdd-supply: true" and should be listed
under required since the sensor needs its VDD rail to operate.

> +
> +additionalProperties: false
> +
> +examples:
> +  - |
> +    #include <dt-bindings/gpio/gpio.h>
> +    #include <dt-bindings/interrupt-controller/irq.h>
> +    i2c {
> +        #address-cells = <1>;
> +        #size-cells = <0>;
> +        grip@28 {
> +            compatible = "imagis,isg5320a";
> +            reg = <0x28>;
> +            interrupt-parent = <&gpa2>;
> +            interrupts = <0 IRQ_TYPE_LEVEL_LOW>;
> +            vdd-supply = <&grip_vdd>;
> +            wakeup-source;
> +        };
> +    };

[Severity: Low]
Does the example need a blank line between "#size-cells = <0>;" and the
child node?  Without it, "scripts/dtc/dt-check-style --mode=strict" warns
on required-blank-lines.

Also, the unused <dt-bindings/gpio/gpio.h> include can be dropped, and the
node name should use the generic "proximity@28" instead of "grip@28".

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261116074013.355363-1-tadilhusrev@gmail.com?part=1

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v1 2/2] iio: proximity: add Imagis ISG5320A SAR sensor driver
  2026-11-16  7:40 ` [PATCH v1 2/2] iio: proximity: add Imagis ISG5320A SAR sensor driver Adil Hüsrev Tepe
@ 2026-11-16  7:58   ` sashiko-bot
  2026-11-16 10:53   ` Andy Shevchenko
  1 sibling, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-11-16  7:58 UTC (permalink / raw)
  To: Adil Hüsrev Tepe; +Cc: devicetree, robh, conor+dt

Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [Medium] iio: proximity: isg5320a: unbalanced IRQ wake in
  isg5320a_events_off()
- [Medium] iio: proximity: isg5320a: ignored regmap_write() errors in
  isg5320a_reset()
- [Medium] iio: proximity: isg5320a: undocumented int-gpios and raw GPIO
  polling
- [Medium] iio: proximity: isg5320a: unsynchronized IRQ and sleep in
  isg5320a_shutdown()
- [Medium] iio: proximity: isg5320a: chip left active on IRQ error in
  isg5320a_probe()
- [Low] iio: proximity: isg5320a: positional initializer in
  isg5320a_id[]
--

commit 9f24b9dcaaade133d53e6aef3bc6e657c2c94db0
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 I2C capacitive
SAR/grip proximity sensor, exposing a single proximity channel and
threshold events.

> diff --git a/drivers/iio/proximity/isg5320a.c b/drivers/iio/proximity/isg5320a.c
> new file mode 100644
> index 0000000000000..53326703535e5
> --- /dev/null
> +++ b/drivers/iio/proximity/isg5320a.c

[ ... ]

> +/* Wait for the INT line to reach @level: up to 10 x 5 ms (vendor :262, :281). */
> +static int isg5320a_wait_int(struct isg5320a_data *data, int level)
> +{
> +	int cnt;
> +
> +	if (!data->int_gpio) {
> +		msleep(50);
> +		return 0;
> +	}
> +
> +	for (cnt = 0; cnt < 10; cnt++) {
> +		if (gpiod_get_raw_value_cansleep(data->int_gpio) == level)
> +			return cnt;
> +		usleep_range(5000, 5100);
> +	}
> +
> +	return -ETIMEDOUT;
> +}
> +
> +/* vendor isg5320a_reset(), :247-292, plus a CHIPID read the vendor never does */
> +static int isg5320a_reset(struct isg5320a_data *data)
> +{

[ ... ]

> +	if (isg5320a_wait_int(data, 1) < 0)			/* :262-266 */
> +		dev_warn(dev, "INT did not go high before reset\n");
> +
> +	ret = regmap_write(data->regmap, ISG5320A_REG_PROTECT,	/* :268-271 */
> +			   ISG5320A_PROTECT_UNLOCK);
> +	if (ret)
> +		dev_warn(dev, "unlock protect failed: %d\n", ret);
> +
> +	ret = regmap_write(data->regmap, ISG5320A_REG_SOFTRESET,	/* :273-276 */
> +			   ISG5320A_SOFTRESET_VAL);
> +	if (ret)
> +		dev_warn(dev, "soft reset write failed: %d\n", ret);
> +
> +	usleep_range(1000, 1100);				/* :278 */
> +
> +	ret = isg5320a_wait_int(data, 0);			/* :280-289 */
> +	if (ret < 0)
> +		return dev_err_probe(dev, -EIO, "INT not asserted after soft reset\n");
> +	dev_dbg(dev, "reset done, wait cnt %d\n", ret);
> +
> +	return 0;
> +}

[Severity: Medium]
Should isg5320a_reset() return an error if writing ISG5320A_REG_PROTECT or
ISG5320A_REG_SOFTRESET fails?

When data->int_gpio is NULL (or if the interrupt line was already low
before reset), isg5320a_wait_int(data, 0) returns 0, so isg5320a_reset()
succeeds and isg5320a_probe() continues initializing an unreset device.

[ ... ]

> +	WRITE_ONCE(data->ev_enabled, true);
> +	enable_irq(data->irq);						/* :721 */
> +	if (device_may_wakeup(dev))
> +		enable_irq_wake(data->irq);				/* :722 */
> +
> +	dev_dbg(dev, "events on, initial state %s\n", data->close ? "close" : "far");
> +
> +	return 0;
> +}
> +
> +static void isg5320a_events_off(struct isg5320a_data *data)
> +{
> +	struct device *dev = data->dev;
> +	int ret = 0;
> +
> +	scoped_guard(mutex, &data->lock)
> +		ret = regmap_write(data->regmap, ISG5320A_REG_IRQFUNC,	/* :726 */
> +				   ISG5320A_IRQFUNC_DISABLE);
> +	if (ret)
> +		dev_warn(dev, "IRQFUNC disable failed: %d\n", ret);
> +
> +	WRITE_ONCE(data->ev_enabled, false);
> +	disable_irq(data->irq);						/* :728 */
> +	if (device_may_wakeup(dev))
> +		disable_irq_wake(data->irq);				/* :729 */
> +}

[Severity: Medium]
Can toggling /sys/devices/.../power/wakeup while threshold events are
enabled cause an unbalanced IRQ wake in isg5320a_events_off()?

isg5320a_events_on() and isg5320a_events_off() both check
device_may_wakeup(dev) dynamically.  If userspace enables power/wakeup
after events are turned on, isg5320a_events_off() calls
disable_irq_wake(data->irq) without a matching enable_irq_wake(),
triggering the "Unbalanced IRQ %d wake disable" warning in
irq_set_irq_wake().  Conversely, disabling power/wakeup while events are
active skips disable_irq_wake() and leaks the wake reference even after
unbind.

Note that when wakeup-source is present in Devicetree, i2c_device_probe()
already calls device_init_wakeup() and dev_pm_set_wake_irq() for the
client IRQ, so manual device_init_wakeup() in isg5320a_probe() and manual
enable_irq_wake()/disable_irq_wake() calls here also duplicate the I2C
core wakeup handling.

[ ... ]

> +	/*
> +	 * Optional: lets the reset sequence watch the INT level as the vendor
> +	 * does. It is requested before the IRQ (same order as vendor :1873 vs
> +	 * :1931), since on Samsung pinctrl the IRQ request switches the pin
> +	 * back to its EINT function.
> +	 */
> +	data->int_gpio = devm_gpiod_get_optional(dev, "int", GPIOD_IN);
> +	if (IS_ERR(data->int_gpio))
> +		return dev_err_probe(dev, PTR_ERR(data->int_gpio), "int gpio\n");
> +	if (!data->int_gpio)
> +		dev_info(dev, "no int-gpios, reset uses fixed delays\n");

[Severity: Medium]
Why does isg5320a_probe() request an "int" GPIO that is not in the
Devicetree binding?

Documentation/devicetree/bindings/iio/proximity/imagis,isg5320a.yaml only
defines interrupts and forbids additional properties, and
i2c_device_probe() has already mapped that pin as client->irq before
isg5320a_probe() runs, which causes GPIO/irqchip conflicts on many
platforms.  In addition, isg5320a_wait_int() uses
gpiod_get_raw_value_cansleep(data->int_gpio), which ignores both GPIO
active-low polarity and negative error returns.

> +
> +	ret = isg5320a_reset(data);				/* :1915 */
> +	if (ret)
> +		return ret;
> +
> +	msleep(300);			/* vendor runs init_work 300 ms later, :1981 */
> +
> +	ret = isg5320a_initialize(data);			/* :1620 */
> +	if (ret)
> +		return dev_err_probe(dev, ret, "init failed\n");
> +
> +	ret = isg5320a_mode_normal(data);			/* :1621 */
> +	if (ret)
> +		return dev_err_probe(dev, ret, "start failed\n");
> +
> +	if (data->irq > 0) {
> +		irqflags = irq_get_trigger_type(data->irq);
> +		if (!irqflags)
> +			irqflags = IRQF_TRIGGER_FALLING;	/* :1932 */
> +
> +		ret = devm_request_threaded_irq(dev, data->irq, NULL,
> +						isg5320a_irq_thread,
> +						irqflags | IRQF_ONESHOT |
> +						IRQF_NO_AUTOEN,
> +						"isg5320a", indio_dev);
> +		if (ret)
> +			return dev_err_probe(dev, ret, "irq request failed\n");

[Severity: Medium]
Does an error from devm_request_threaded_irq() leave the sensor running in
normal mode?

isg5320a_mode_normal() has already started the oscillator, watchdog, and
scanning, but the isg5320a_teardown() devres action that puts the chip
back to sleep is not registered until after the IRQ request succeeds.

[ ... ]

> +/* vendor isg5320a_shutdown(), :2071-2080 */
> +static void isg5320a_shutdown(struct i2c_client *client)
> +{
> +	struct isg5320a_data *data = iio_priv(i2c_get_clientdata(client));
> +
> +	guard(mutex)(&data->ev_lock);
> +
> +	if (data->ev_enabled)
> +		regmap_write(data->regmap, ISG5320A_REG_IRQFUNC,
> +			     ISG5320A_IRQFUNC_DISABLE);
> +	isg5320a_mode_sleep(data);
> +}

[Severity: Medium]
Can isg5320a_irq_thread() race with isg5320a_shutdown()?

Because the driver provides a custom .shutdown callback,
i2c_device_shutdown() does not disable client->irq automatically.  Unlike
isg5320a_teardown(), which calls isg5320a_events_off() and checks
!pm_runtime_status_suspended(dev), isg5320a_shutdown() writes
ISG5320A_REG_IRQFUNC without holding data->lock, leaves data->irq enabled
while putting the chip to sleep, and runs isg5320a_mode_sleep() even when
the device is already runtime-suspended.

[ ... ]

> +static const struct i2c_device_id isg5320a_id[] = {
> +	{ "isg5320a" },
> +	{ }
> +};

[Severity: Low]
This isn't a bug, but I2C convention is to use a named initializer
({ .name = "isg5320a" }) for new struct i2c_device_id entries.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261116074013.355363-1-tadilhusrev@gmail.com?part=2

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v1 0/2] iio: proximity: add Imagis ISG5320A (Samsung Galaxy XCover5)
  2026-11-16  7:40 [PATCH v1 0/2] iio: proximity: add Imagis ISG5320A (Samsung Galaxy XCover5) Adil Hüsrev Tepe
  2026-11-16  7:40 ` [PATCH v1 1/2] dt-bindings: iio: proximity: add Imagis ISG5320A Adil Hüsrev Tepe
  2026-11-16  7:40 ` [PATCH v1 2/2] iio: proximity: add Imagis ISG5320A SAR sensor driver Adil Hüsrev Tepe
@ 2026-11-16 10:48 ` Andy Shevchenko
  2026-11-17 10:44 ` [PATCH v2 1/2] dt-bindings: iio: proximity: add Imagis ISG5320A Adil Hüsrev Tepe
  2026-11-17 17:33 ` [PATCH v3 0/2] iio: proximity: add Imagis ISG5320A (Samsung Galaxy XCover5) Adil Hüsrev Tepe
  4 siblings, 0 replies; 18+ messages in thread
From: Andy Shevchenko @ 2026-11-16 10:48 UTC (permalink / raw)
  To: Adil Hüsrev Tepe
  Cc: Jonathan Cameron, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	David Lechner, Nuno Sá, Andy Shevchenko, linux-iio,
	devicetree, linux-kernel

On Mon, Nov 16, 2026 at 10:40:11AM +0300, Adil Hüsrev Tepe wrote:
> This series adds an IIO driver and its binding for the Imagis ISG5320A
> capacitive SAR/grip proximity sensor, as fitted on the Samsung Galaxy
> XCover5 (Exynos850).
> 
>   1  dt-bindings: add imagis,isg5320a
>   2  the IIO proximity driver
> 
> The driver exposes one IIO_PROXIMITY channel (the B-channel signal minus
> its baseline) and a rising/falling threshold event. Tested on an XCover5:
> it probes, registers the IIO device and reads a stable baseline value.
> 
> Based on v7.4-rc1.
> 
> Tool usage
> ----------
> Derived from the Samsung vendor driver during XCover5 mainline bring-up
> with an AI coding assistant (Claude Code, Anthropic), which drafted the
> mainline IIO driver and the binding. I reviewed every line and tested
> probe and read-back on hardware. Review comments are welcome and I will
> answer them myself.

Why a brand new driver?

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v1 2/2] iio: proximity: add Imagis ISG5320A SAR sensor driver
  2026-11-16  7:40 ` [PATCH v1 2/2] iio: proximity: add Imagis ISG5320A SAR sensor driver Adil Hüsrev Tepe
  2026-11-16  7:58   ` sashiko-bot
@ 2026-11-16 10:53   ` Andy Shevchenko
  1 sibling, 0 replies; 18+ messages in thread
From: Andy Shevchenko @ 2026-11-16 10:53 UTC (permalink / raw)
  To: Adil Hüsrev Tepe
  Cc: Jonathan Cameron, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	David Lechner, Nuno Sá, Andy Shevchenko, linux-iio,
	devicetree, linux-kernel

On Mon, Nov 16, 2026 at 10:40:13AM +0300, Adil Hüsrev Tepe wrote:
> 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.
> 
> The driver was derived from the Samsung vendor driver during XCover5
> mainline bring-up with the help of an AI coding assistant (Claude Code,
> Anthropic), which drafted the mainline IIO driver; I reviewed every line
> and tested it on hardware.

...

> +config ISG5320A
> +	tristate "Imagis ISG5320A SAR proximity sensor"

Make sure this, top level comment and MODULE_DESCRIPTION() have the same or
quite similar text.


> +	depends on I2C
> +	select REGMAP_I2C
> +	help
> +	  Say Y here to build a driver for the Imagis ISG5320A capacitive
> +	  SAR/grip proximity sensor.
> +
> +	  To compile this driver as a module, choose M here: the module will
> +	  be called isg5320a.

...

> +#include <linux/bits.h>
> +#include <linux/delay.h>
> +#include <linux/device.h>
> +#include <linux/gpio/consumer.h>
> +#include <linux/i2c.h>
> +#include <linux/interrupt.h>
> +#include <linux/irq.h>

> +#include <linux/kernel.h>

Definitely no.
Also, please follow IWYU principle.

> +#include <linux/mod_devicetable.h>
> +#include <linux/module.h>
> +#include <linux/mutex.h>
> +#include <linux/pm.h>
> +#include <linux/pm_runtime.h>
> +#include <linux/pm_wakeup.h>
> +#include <linux/property.h>
> +#include <linux/regmap.h>
> +#include <linux/regulator/consumer.h>

...

Also, take in use *ACQUIRE*() macros, in particular for runtime PM where it
makes sense.

...

I stopped here. You can now go via mailing list archive (linux-iio@) and check
what are the usual comments against new drier. You have many small things to
improve, I believe.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v2 1/2] dt-bindings: iio: proximity: add Imagis ISG5320A
  2026-11-16  7:40 [PATCH v1 0/2] iio: proximity: add Imagis ISG5320A (Samsung Galaxy XCover5) Adil Hüsrev Tepe
                   ` (2 preceding siblings ...)
  2026-11-16 10:48 ` [PATCH v1 0/2] iio: proximity: add Imagis ISG5320A (Samsung Galaxy XCover5) Andy Shevchenko
@ 2026-11-17 10:44 ` Adil Hüsrev Tepe
  2026-11-17 10:44   ` [PATCH v2 2/2] iio: proximity: add Imagis ISG5320A SAR sensor driver Adil Hüsrev Tepe
  2026-11-17 10:54   ` [PATCH v2 1/2] dt-bindings: iio: proximity: add Imagis ISG5320A sashiko-bot
  2026-11-17 17:33 ` [PATCH v3 0/2] iio: proximity: add Imagis ISG5320A (Samsung Galaxy XCover5) Adil Hüsrev Tepe
  4 siblings, 2 replies; 18+ messages in thread
From: Adil Hüsrev Tepe @ 2026-11-17 10:44 UTC (permalink / raw)
  To: jic23, robh, krzk+dt, conor+dt
  Cc: dlechner, nuno.sa, andy, linux-iio, devicetree, linux-kernel,
	Adil Hüsrev Tepe

Add a binding for the Imagis ISG5320A capacitive SAR/grip proximity
sensor (I2C), as fitted on the Samsung Galaxy XCover5.

v1 -> v2 (addressing Sashiko AI's review of v1,
https://sashiko.dev/#/patchset/20261116074013.355363-1-tadilhusrev@gmail.com?part=1):
- Document int-gpios: the driver optionally reads it during the reset
  sequence; it was undocumented in v1.
- Reword the description to the chip's own characteristics instead of
  how the Linux IIO channel is exposed.
- Simplify vdd-supply to "vdd-supply: true" (left optional: the
  XCover5's own grip sensor has no vdd-supply node at all, an
  always-on LDO not modeled in DT, which the driver's
  devm_regulator_get_enable_optional() already tolerates).
- Rename the example node to "proximity@28", drop the unused gpio.h
  include, and add the blank line dt-check-style wants before the
  child node.

The binding was drafted during XCover5 mainline bring-up with the help
of an AI coding assistant (Claude Code, Anthropic) and reviewed and
validated (dt_binding_check, yamllint) by me.

Signed-off-by: Adil Hüsrev Tepe <tadilhusrev@gmail.com>
---
 .../iio/proximity/imagis,isg5320a.yaml        | 62 +++++++++++++++++++
 1 file changed, 62 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/proximity/imagis,isg5320a.yaml

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 000000000..ccb84b29f
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/proximity/imagis,isg5320a.yaml
@@ -0,0 +1,62 @@
+# 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.
+  As fitted on the Samsung Galaxy XCover5.
+
+properties:
+  compatible:
+    const: imagis,isg5320a
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+    description: active-low data-ready / proximity interrupt
+
+  int-gpios:
+    maxItems: 1
+    description:
+      GPIO connected to the same INT line as the "interrupts" property. When
+      present it is polled during the reset sequence to observe the INT level,
+      as the vendor driver does; otherwise the reset falls back to fixed delays.
+
+  vdd-supply: true
+
+  wakeup-source: true
+
+required:
+  - compatible
+  - reg
+  - interrupts
+
+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_LEVEL_LOW>;
+            vdd-supply = <&grip_vdd>;
+            wakeup-source;
+        };
+    };
+...
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 2/2] iio: proximity: add Imagis ISG5320A SAR sensor driver
  2026-11-17 10:44 ` [PATCH v2 1/2] dt-bindings: iio: proximity: add Imagis ISG5320A Adil Hüsrev Tepe
@ 2026-11-17 10:44   ` Adil Hüsrev Tepe
  2026-11-17 11:08     ` sashiko-bot
  2026-11-17 13:56     ` Andy Shevchenko
  2026-11-17 10:54   ` [PATCH v2 1/2] dt-bindings: iio: proximity: add Imagis ISG5320A sashiko-bot
  1 sibling, 2 replies; 18+ messages in thread
From: Adil Hüsrev Tepe @ 2026-11-17 10:44 UTC (permalink / raw)
  To: jic23, robh, krzk+dt, conor+dt
  Cc: dlechner, nuno.sa, andy, linux-iio, devicetree, linux-kernel,
	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.

v1 -> v2 (addressing Andy Shevchenko's and Sashiko AI's review of v1,
https://sashiko.dev/#/patchset/20261116074013.355363-1-tadilhusrev@gmail.com?part=2):
- Drop the unused #include <linux/kernel.h>; audit includes for the
  IWYU principle (array_size.h, cleanup.h, errno.h, types.h for
  symbols actually used).
- Use ACQUIRE(pm_runtime_active_auto_try_enabled)/ACQUIRE_ERR() in
  isg5320a_get_sample() instead of open-coded
  pm_runtime_resume_and_get()/pm_runtime_put_autosuspend().
- Make the Kconfig prompt, this file's top comment, and
  MODULE_DESCRIPTION() use the same wording.
- Propagate the PROTECT-unlock write failure in isg5320a_reset()
  instead of only warning (matches the existing SOFTRESET handling).
- isg5320a_wait_int() now reads the INT gpio with
  gpiod_get_value_cansleep() (logical, polarity-aware) instead of
  _raw_, and returns a real error instead of looping to -ETIMEDOUT on
  a failed read.
- Cache device_may_wakeup() at isg5320a_events_on() time
  (irq_wake_enabled) and use that cached value in
  isg5320a_events_off(), instead of re-checking device_may_wakeup() at
  disable time: toggling /sys/.../power/wakeup between enable and
  disable no longer produces an unbalanced
  enable_irq_wake()/disable_irq_wake() pair.
- isg5320a_shutdown() now calls isg5320a_events_off() (disables the
  IRQ and takes data->lock around the IRQFUNC write) instead of
  writing IRQFUNC unlocked with the IRQ still enabled, and only calls
  isg5320a_mode_sleep() when the device isn't already
  runtime-suspended.
- Register the isg5320a_teardown() devres action right after
  isg5320a_mode_normal() succeeds instead of after the IRQ request, so
  a later probe failure (e.g. devm_request_threaded_irq()) still puts
  the chip back to sleep instead of leaving it scanning unbound.
- Use a named initializer in isg5320a_id[].

The driver was derived from the Samsung vendor driver during XCover5
mainline bring-up with the help of an AI coding assistant (Claude Code,
Anthropic), which drafted the mainline IIO driver; I reviewed every
line, built it (arm64, 0 warnings), ran checkpatch --strict (clean),
and tested it live on a Samsung Galaxy XCover5 (2026-11-17): the driver
binds and registers as iio:device4 "isg5320a", with a live
in_proximity0_raw read-back.

Signed-off-by: Adil Hüsrev Tepe <tadilhusrev@gmail.com>
---
 drivers/iio/proximity/Kconfig    |  11 +
 drivers/iio/proximity/Makefile   |   1 +
 drivers/iio/proximity/isg5320a.c | 880 +++++++++++++++++++++++++++++++
 3 files changed, 892 insertions(+)
 create mode 100644 drivers/iio/proximity/isg5320a.c

diff --git a/drivers/iio/proximity/Kconfig b/drivers/iio/proximity/Kconfig
index bb77fad2a..311a7b9e4 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 4352833dd..6aa606fa5 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 000000000..baa8d07ec
--- /dev/null
+++ b/drivers/iio/proximity/isg5320a.c
@@ -0,0 +1,880 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Imagis ISG5320A capacitive SAR/grip sensor.
+ *
+ * Register map, init table and every write sequence below come from the
+ * Samsung vendor driver (drivers/sensors/isg5320a.c + isg5320a_reg.h,
+ * Galaxy XCover5 5.10 tree, Copyright (C) Imagis Technology). Citations of
+ * the form "vendor :NNN" refer to lines in that isg5320a.c. This driver
+ * writes no register the vendor driver does not write, and only with the
+ * values the vendor writes; regmap enforces that through writeable_reg.
+ *
+ * The chip is used as one proximity channel: the vendor's "diff" value
+ * (CDC16_T - BSL16_B, i.e. 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/device.h>
+#include <linux/errno.h>
+#include <linux/gpio/consumer.h>
+#include <linux/i2c.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/pm.h>
+#include <linux/pm_runtime.h>
+#include <linux/pm_wakeup.h>
+#include <linux/property.h>
+#include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
+#include <linux/types.h>
+
+#include <linux/iio/events.h>
+#include <linux/iio/iio.h>
+
+/* Registers (vendor isg5320a_reg.h :19-79) */
+#define ISG5320A_REG_IRQSRC		0x00	/* read releases the INT line */
+#define ISG5320A_REG_IRQSTS		0x01
+#define   ISG5320A_IRQSTS_PROX		BIT(4)	/* ISG5320A_PROX_STATE, reg.h :81 */
+#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_REG_SCANCTRL2		0x39
+#define   ISG5320A_SCAN2_RESET		0x00
+#define   ISG5320A_SCAN2_CLEAR		0x60
+#define   ISG5320A_BFCAL_START		0x07
+/* CDC16_T_H, CDC16_T_L, BSL16_B_H, BSL16_B_L (vendor :453) */
+#define ISG5320A_REG_CDC16_T_H		0x5C
+/* B_PROXCTL3..5: threshold, close hysteresis, far hysteresis (vendor :890) */
+#define ISG5320A_REG_B_PROXCTL3		0x9B
+#define ISG5320A_REG_DIGITAL_ACC	0xA4
+#define ISG5320A_REG_PROTECT		0xCD
+#define   ISG5320A_PROTECT_UNLOCK	0xDE
+#define ISG5320A_REG_SOFTRESET		0xFD
+#define   ISG5320A_SOFTRESET_VAL	0xDE
+#define ISG5320A_REG_CHIPID		0xFE
+#define ISG5320A_MAX_REG		0xFE
+
+#define ISG5320A_VENDOR_CHIP_ID		0x32	/* vendor :39, never checked */
+#define ISG5320A_RESET_CONDITION	5000	/* reg.h :99, for cfcal_th */
+
+#define ISG5320A_AUTOSUSPEND_MS		5000
+
+struct isg5320a_reg_data {
+	u8 addr;
+	u8 val;
+};
+
+/*
+ * Vendor setup_reg[] for "XCOVER5 ALL" (isg5320a_reg.h :283-435). The other
+ * table (:130-282) is under CONFIG_SENSORS_ISG5320A_XCOVER5_KOR, which the
+ * stock exynos850-xcover5xx_defconfig leaves unset; it differs only in
+ * 0x9C (threshold low byte), 0xA0 (far hysteresis low byte) and 0xBA.
+ */
+static const struct isg5320a_reg_data 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 }, { 0x41, 0x11 }, { 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 }, { 0xC5, 0x00 }, { 0x13, 0x3A },
+	{ 0x18, 0xF1 }, /* A ch : CS0, B ch : 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 },
+};
+
+struct isg5320a_data {
+	struct device *dev;
+	struct regmap *regmap;
+	struct gpio_desc *int_gpio;
+	int irq;
+	/* Serialises multi-register chip sequences and the cached sample. */
+	struct mutex lock;
+	/* Serialises event enable/disable (sleeps in disable_irq()). */
+	struct mutex ev_lock;
+	bool ev_enabled;
+	bool irq_wake_enabled;
+	bool close;
+	u16 cdc;
+	u16 base;
+	u16 thresh;
+	u16 close_hyst;
+	u16 far_hyst;
+	u32 cfcal_th;
+};
+
+static bool isg5320a_writeable_reg(struct device *dev, unsigned int reg)
+{
+	unsigned int i;
+
+	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 (i = 0; i < ARRAY_SIZE(isg5320a_setup_reg); i++)
+		if (isg5320a_setup_reg[i].addr == 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;
+}
+
+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,
+};
+
+/* Wait for the INT line to reach @level: up to 10 x 5 ms (vendor :262, :281). */
+static int isg5320a_wait_int(struct isg5320a_data *data, int level)
+{
+	int cnt, val;
+
+	if (!data->int_gpio) {
+		msleep(50);
+		return 0;
+	}
+
+	for (cnt = 0; cnt < 10; cnt++) {
+		/* Logical, not raw: honours the GPIO's DT polarity. */
+		val = gpiod_get_value_cansleep(data->int_gpio);
+		if (val < 0)
+			return val;
+		if (val == level)
+			return cnt;
+		usleep_range(5000, 5100);
+	}
+
+	return -ETIMEDOUT;
+}
+
+/* vendor isg5320a_reset(), :247-292, plus a CHIPID read the vendor never does */
+static int isg5320a_reset(struct isg5320a_data *data)
+{
+	struct device *dev = data->dev;
+	unsigned int val;
+	int ret;
+
+	usleep_range(5000, 5100);				/* :255-256 */
+
+	ret = regmap_read(data->regmap, ISG5320A_REG_IRQSRC, &val);	/* :258 */
+	if (ret)
+		return dev_err_probe(dev, ret, "no response at IRQSRC\n");
+
+	ret = regmap_read(data->regmap, ISG5320A_REG_CHIPID, &val);
+	if (ret)
+		return dev_err_probe(dev, ret, "CHIPID read failed\n");
+	if (val == ISG5320A_VENDOR_CHIP_ID)
+		dev_info(dev, "CHIPID 0x%02x\n", val);
+	else
+		dev_warn(dev, "CHIPID 0x%02x (vendor header says 0x%02x; not enforced)\n",
+			 val, ISG5320A_VENDOR_CHIP_ID);
+
+	if (isg5320a_wait_int(data, 1) < 0)			/* :262-266 */
+		dev_warn(dev, "INT did not go high before reset\n");
+
+	ret = regmap_write(data->regmap, ISG5320A_REG_PROTECT,	/* :268-271 */
+			   ISG5320A_PROTECT_UNLOCK);
+	if (ret)
+		return dev_err_probe(dev, ret, "unlock protect failed\n");
+
+	ret = regmap_write(data->regmap, ISG5320A_REG_SOFTRESET,	/* :273-276 */
+			   ISG5320A_SOFTRESET_VAL);
+	if (ret)
+		return dev_err_probe(dev, ret, "soft reset write failed\n");
+
+	usleep_range(1000, 1100);				/* :278 */
+
+	ret = isg5320a_wait_int(data, 0);			/* :280-289 */
+	if (ret < 0)
+		return dev_err_probe(dev, -EIO, "INT not asserted after soft reset\n");
+	dev_dbg(dev, "reset done, wait cnt %d\n", ret);
+
+	return 0;
+}
+
+/* vendor isg5320a_initialize(), :614-660, without the /sdcard override */
+static int isg5320a_initialize(struct isg5320a_data *data)
+{
+	struct device *dev = data->dev;
+	unsigned int i, val, mismatch = 0;
+	u8 buf[6];
+	int ret;
+
+	guard(mutex)(&data->lock);
+
+	ret = regmap_read(data->regmap, ISG5320A_REG_IRQSRC, &val);	/* :625 */
+	if (ret)
+		return ret;
+	ret = regmap_write(data->regmap, ISG5320A_REG_SCANCTRL1,	/* :626 */
+			   ISG5320A_SCAN_STOP);
+	if (ret)
+		return ret;
+	msleep(30);						/* :627 */
+
+	for (i = 0; i < ARRAY_SIZE(isg5320a_setup_reg); i++) {	/* :631-637 */
+		const struct isg5320a_reg_data *r = &isg5320a_setup_reg[i];
+
+		ret = regmap_write(data->regmap, r->addr, r->val);
+		if (ret)
+			return dev_err_probe(dev, ret, "init write 0x%02x failed\n",
+					     r->addr);
+		ret = regmap_read(data->regmap, r->addr, &val);
+		if (ret)
+			return ret;
+		if (val != r->val) {
+			mismatch++;
+			dev_dbg(dev, "reg 0x%02x wrote 0x%02x read 0x%02x\n",
+				r->addr, r->val, val);
+		}
+	}
+	dev_info(dev, "init table: %zu writes, %u read back different\n",
+		 ARRAY_SIZE(isg5320a_setup_reg), mismatch);
+
+	/* :646-650 reads the threshold; :890-897 reads all six bytes */
+	ret = regmap_bulk_read(data->regmap, ISG5320A_REG_B_PROXCTL3, buf,
+			       sizeof(buf));
+	if (ret)
+		return ret;
+	data->thresh = (buf[0] << 8) | buf[1];
+	data->close_hyst = (buf[2] << 8) | buf[3];
+	data->far_hyst = (buf[4] << 8) | buf[5];
+
+	ret = regmap_read(data->regmap, ISG5320A_REG_DIGITAL_ACC, &val);	/* :653-657 */
+	if (ret)
+		return ret;
+	data->cfcal_th = ISG5320A_RESET_CONDITION * val / 8;
+
+	dev_info(dev, "threshold %u, close hyst %u, far hyst %u, cfcal_th %u\n",
+		 data->thresh, data->close_hyst, data->far_hyst, data->cfcal_th);
+
+	return 0;
+}
+
+/* vendor isg5320a_set_mode(SLEEP), :749-755 */
+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;
+	ret = regmap_write(data->regmap, ISG5320A_REG_SCANCTRL1, ISG5320A_SCAN_STOP);
+	if (ret)
+		return ret;
+	ret = regmap_write(data->regmap, ISG5320A_REG_OSCCON, ISG5320A_OSC_SLEEP);
+	if (ret)
+		return ret;
+	return regmap_write(data->regmap, ISG5320A_REG_BS_ON_WD, ISG5320A_BS_WD_OFF);
+}
+
+/*
+ * vendor isg5320a_set_mode(NORMAL), :749 + :757-758, which runs
+ * isg5320a_force_calibration(data, false), :302-321.
+ */
+static int isg5320a_mode_normal(struct isg5320a_data *data)
+{
+	struct regmap *map = data->regmap;
+	unsigned int val;
+	int ret;
+
+	guard(mutex)(&data->lock);
+
+	ret = regmap_read(map, ISG5320A_REG_IRQSRC, &val);			/* :749 */
+	if (ret)
+		return ret;
+	ret = regmap_write(map, ISG5320A_REG_BS_ON_WD, ISG5320A_BS_WD_ON);	/* :757 */
+	if (ret)
+		return ret;
+
+	ret = regmap_write(map, ISG5320A_REG_SCANCTRL1, ISG5320A_SCAN_STOP);	/* :303 */
+	if (ret)
+		return ret;
+	msleep(30);								/* :305 */
+	ret = regmap_write(map, ISG5320A_REG_BS_ON_WD, ISG5320A_BS_WD_OFF);	/* :306 */
+	if (ret)
+		return ret;
+	ret = regmap_write(map, ISG5320A_REG_SCANCTRL2, ISG5320A_SCAN2_CLEAR);	/* :307 */
+	if (ret)
+		return ret;
+	msleep(100);								/* :309 */
+	ret = regmap_write(map, ISG5320A_REG_OSCCON, ISG5320A_OSC_NORMAL);	/* :310 */
+	if (ret)
+		return ret;
+	ret = regmap_write(map, ISG5320A_REG_BS_ON_WD, ISG5320A_BS_WD_ON);	/* :312 */
+	if (ret)
+		return ret;
+	ret = regmap_write(map, ISG5320A_REG_SCANCTRL2, ISG5320A_SCAN2_RESET);	/* :313 */
+	if (ret)
+		return ret;
+	ret = regmap_write(map, ISG5320A_REG_SCANCTRL1, ISG5320A_CFCAL_START);	/* :316 */
+	if (ret)
+		return ret;
+	msleep(500);								/* :318 */
+	ret = regmap_write(map, ISG5320A_REG_SCANCTRL2, ISG5320A_BFCAL_START);	/* :321 */
+	if (ret)
+		return ret;
+
+	/* The vendor sw_reset path waits 300 ms after BFCAL before reading (:850-852). */
+	msleep(300);
+
+	return 0;
+}
+
+/* vendor isg5320a_get_raw_data(), :445-466; caller holds data->lock */
+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 discarded and the last value kept (:459-464) */
+	v = (buf[0] << 8) | buf[1];
+	if (v != 0 && v != 0xFFFF)
+		data->cdc = v;
+	v = (buf[2] << 8) | buf[3];
+	if (v != 0 && v != 0xFFFF)
+		data->base = v;
+
+	return 0;
+}
+
+static int isg5320a_get_sample(struct isg5320a_data *data, u16 *cdc, u16 *base)
+{
+	struct device *dev = data->dev;
+	int ret;
+
+	ACQUIRE(pm_runtime_active_auto_try_enabled, pm)(dev);
+	ret = ACQUIRE_ERR(pm_runtime_active_auto_try_enabled, &pm);
+	if (ret < 0)
+		return ret;
+
+	scoped_guard(mutex, &data->lock) {
+		ret = isg5320a_read_sample(data);
+		*cdc = data->cdc;
+		*base = data->base;
+	}
+	if (ret)
+		return ret;
+
+	/*
+	 * The vendor cal_work (:1640-1647) force-recalibrates when cdc drops
+	 * below cfcal_th. That loop is not ported; only report the condition.
+	 */
+	if (*cdc < data->cfcal_th)
+		dev_warn_ratelimited(dev, "cdc %u below cfcal_th %u (vendor would recalibrate)\n",
+				     *cdc, data->cfcal_th);
+
+	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);
+	unsigned int src, sts;
+	bool changed = false;
+	bool close = false;
+	int ret;
+
+	scoped_guard(mutex, &data->lock) {
+		isg5320a_read_sample(data);				/* :581 */
+
+		ret = regmap_read(data->regmap, ISG5320A_REG_IRQSRC, &src);	/* :583 */
+		if (ret)
+			break;
+		ret = regmap_read(data->regmap, ISG5320A_REG_IRQSTS, &sts);	/* :598 */
+		if (ret)
+			break;
+
+		close = sts & ISG5320A_IRQSTS_PROX;			/* :518 */
+		changed = close != data->close;
+		data->close = close;
+	}
+
+	if (ret) {
+		dev_err_ratelimited(data->dev, "irq status read failed: %d\n", ret);
+		return IRQ_HANDLED;
+	}
+
+	dev_dbg(data->dev, "irq src 0x%02x sts 0x%02x cdc %u base %u\n",
+		src, sts, data->cdc, data->base);
+
+	if (changed && READ_ONCE(data->ev_enabled)) {
+		enum iio_event_direction dir;
+
+		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);
+	u16 cdc, base;
+	int ret;
+
+	switch (mask) {
+	case IIO_CHAN_INFO_RAW:
+		ret = isg5320a_get_sample(data, &cdc, &base);
+		if (ret)
+			return ret;
+		*val = (int)cdc - (int)base;				/* :465 */
+		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;
+
+	return READ_ONCE(data->ev_enabled);
+}
+
+/* vendor isg5320a_set_enable(), :681-742 (minus the work items) */
+static int isg5320a_events_on(struct isg5320a_data *data)
+{
+	struct device *dev = data->dev;
+	unsigned int val;
+	int ret;
+
+	ret = pm_runtime_resume_and_get(dev);
+	if (ret)
+		return ret;
+
+	scoped_guard(mutex, &data->lock) {
+		ret = regmap_read(data->regmap, ISG5320A_REG_IRQSTS, &val);	/* :700 */
+		if (ret)
+			break;
+		data->close = val & ISG5320A_IRQSTS_PROX;		/* :708-713 */
+		isg5320a_read_sample(data);				/* :704 */
+		ret = regmap_read(data->regmap, ISG5320A_REG_IRQSRC, &val);	/* :718 */
+		if (ret)
+			break;
+		ret = regmap_write(data->regmap, ISG5320A_REG_IRQFUNC,	/* :719 */
+				   ISG5320A_IRQFUNC_ENABLE);
+	}
+	if (ret) {
+		pm_runtime_put_autosuspend(dev);
+		return ret;
+	}
+
+	WRITE_ONCE(data->ev_enabled, true);
+	enable_irq(data->irq);						/* :721 */
+	/* Cache the decision: device_may_wakeup(dev) may change before events_off(). */
+	data->irq_wake_enabled = device_may_wakeup(dev);
+	if (data->irq_wake_enabled)
+		enable_irq_wake(data->irq);				/* :722 */
+
+	dev_dbg(dev, "events on, initial state %s\n", data->close ? "close" : "far");
+
+	return 0;
+}
+
+static void isg5320a_events_off(struct isg5320a_data *data)
+{
+	struct device *dev = data->dev;
+	int ret = 0;
+
+	scoped_guard(mutex, &data->lock)
+		ret = regmap_write(data->regmap, ISG5320A_REG_IRQFUNC,	/* :726 */
+				   ISG5320A_IRQFUNC_DISABLE);
+	if (ret)
+		dev_warn(dev, "IRQFUNC disable failed: %d\n", ret);
+
+	WRITE_ONCE(data->ev_enabled, false);
+	disable_irq(data->irq);						/* :728 */
+	if (data->irq_wake_enabled) {
+		disable_irq_wake(data->irq);				/* :729 */
+		data->irq_wake_enabled = false;
+	}
+}
+
+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);
+
+	isg5320a_events_off(data);
+	pm_runtime_put_autosuspend(data->dev);
+
+	return 0;
+}
+
+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;
+
+	/* vendor normal_threshold_show, :896-897 */
+	switch (dir) {
+	case IIO_EV_DIR_RISING:
+		*val = data->thresh + data->close_hyst;
+		return IIO_VAL_INT;
+	case IIO_EV_DIR_FALLING:
+		*val = (int)data->thresh - (int)data->far_hyst;
+		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),
+	},
+};
+
+#define ISG5320A_CHANNEL(_events, _nevents)			\
+	{							\
+		.type = IIO_PROXIMITY,				\
+		.indexed = 1,					\
+		.channel = 0,					\
+		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),	\
+		.event_spec = _events,				\
+		.num_event_specs = _nevents,			\
+	}
+
+static const struct iio_chan_spec isg5320a_channels[] = {
+	ISG5320A_CHANNEL(isg5320a_events, ARRAY_SIZE(isg5320a_events)),
+};
+
+static const struct iio_chan_spec isg5320a_channels_noirq[] = {
+	ISG5320A_CHANNEL(NULL, 0),
+};
+
+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 const struct iio_info isg5320a_info_noirq = {
+	.read_raw = isg5320a_read_raw,
+};
+
+/* vendor isg5320a_remove(), :2030-2033 */
+static void isg5320a_teardown(void *arg)
+{
+	struct isg5320a_data *data = arg;
+	struct device *dev = data->dev;
+
+	pm_runtime_disable(dev);
+
+	if (data->ev_enabled) {
+		isg5320a_events_off(data);
+		pm_runtime_put_noidle(dev);
+	}
+
+	if (!pm_runtime_status_suspended(dev))
+		isg5320a_mode_sleep(data);
+
+	pm_runtime_set_suspended(dev);
+	pm_runtime_dont_use_autosuspend(dev);
+}
+
+static int isg5320a_probe(struct i2c_client *client)
+{
+	struct device *dev = &client->dev;
+	struct isg5320a_data *data;
+	struct iio_dev *indio_dev;
+	unsigned long irqflags;
+	int ret;
+
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
+	if (!indio_dev)
+		return -ENOMEM;
+
+	data = iio_priv(indio_dev);
+	data->dev = dev;
+	data->irq = client->irq;
+	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;
+
+	/* The vendor node has no supply; the board relies on an always-on LDO. */
+	ret = devm_regulator_get_enable_optional(dev, "vdd");
+	if (ret && ret != -ENODEV)
+		return dev_err_probe(dev, ret, "failed to enable vdd\n");
+	/*
+	 * If the rail was just switched on, give the chip time to come out
+	 * of power-on reset. The vendor never switches it, so this value
+	 * (10 ms) is a guess, not from the vendor source.
+	 */
+	if (!ret)
+		usleep_range(10000, 11000);
+
+	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");
+
+	/*
+	 * Optional: lets the reset sequence watch the INT level as the vendor
+	 * does. It is requested before the IRQ (same order as vendor :1873 vs
+	 * :1931), since on Samsung pinctrl the IRQ request switches the pin
+	 * back to its EINT function.
+	 */
+	data->int_gpio = devm_gpiod_get_optional(dev, "int", GPIOD_IN);
+	if (IS_ERR(data->int_gpio))
+		return dev_err_probe(dev, PTR_ERR(data->int_gpio), "int gpio\n");
+	if (!data->int_gpio)
+		dev_info(dev, "no int-gpios, reset uses fixed delays\n");
+
+	ret = isg5320a_reset(data);				/* :1915 */
+	if (ret)
+		return ret;
+
+	msleep(300);			/* vendor runs init_work 300 ms later, :1981 */
+
+	ret = isg5320a_initialize(data);			/* :1620 */
+	if (ret)
+		return dev_err_probe(dev, ret, "init failed\n");
+
+	ret = isg5320a_mode_normal(data);			/* :1621 */
+	if (ret)
+		return dev_err_probe(dev, ret, "start failed\n");
+
+	/*
+	 * Registered now, with the chip already active, so that a later
+	 * failure (e.g. the IRQ request below) still puts it back to sleep
+	 * instead of leaving it scanning with nothing bound to it.
+	 */
+	pm_runtime_set_autosuspend_delay(dev, ISG5320A_AUTOSUSPEND_MS);
+	pm_runtime_use_autosuspend(dev);
+	pm_runtime_set_active(dev);
+	pm_runtime_get_noresume(dev);
+	pm_runtime_enable(dev);
+	pm_runtime_put_autosuspend(dev);
+
+	ret = devm_add_action_or_reset(dev, isg5320a_teardown, data);
+	if (ret)
+		return ret;
+
+	if (data->irq > 0) {
+		irqflags = irq_get_trigger_type(data->irq);
+		if (!irqflags)
+			irqflags = IRQF_TRIGGER_FALLING;	/* :1932 */
+
+		ret = devm_request_threaded_irq(dev, data->irq, NULL,
+						isg5320a_irq_thread,
+						irqflags | IRQF_ONESHOT |
+						IRQF_NO_AUTOEN,
+						"isg5320a", indio_dev);
+		if (ret)
+			return dev_err_probe(dev, ret, "irq request failed\n");
+
+		if (device_property_read_bool(dev, "wakeup-source"))
+			device_init_wakeup(dev, true);
+	}
+
+	indio_dev->name = "isg5320a";
+	indio_dev->modes = INDIO_DIRECT_MODE;
+	if (data->irq > 0) {
+		indio_dev->info = &isg5320a_info;
+		indio_dev->channels = isg5320a_channels;
+		indio_dev->num_channels = ARRAY_SIZE(isg5320a_channels);
+	} else {
+		indio_dev->info = &isg5320a_info_noirq;
+		indio_dev->channels = isg5320a_channels_noirq;
+		indio_dev->num_channels = ARRAY_SIZE(isg5320a_channels_noirq);
+	}
+
+	return devm_iio_device_register(dev, indio_dev);
+}
+
+/* vendor isg5320a_shutdown(), :2071-2080, synchronized like isg5320a_teardown() */
+static void isg5320a_shutdown(struct i2c_client *client)
+{
+	struct isg5320a_data *data = iio_priv(i2c_get_clientdata(client));
+	struct device *dev = data->dev;
+
+	guard(mutex)(&data->ev_lock);
+
+	if (data->ev_enabled) {
+		isg5320a_events_off(data);
+		pm_runtime_put_noidle(dev);
+	}
+
+	if (!pm_runtime_status_suspended(dev))
+		isg5320a_mode_sleep(data);
+}
+
+static int isg5320a_runtime_suspend(struct device *dev)
+{
+	struct isg5320a_data *data = iio_priv(dev_get_drvdata(dev));
+
+	return isg5320a_mode_sleep(data);
+}
+
+static int isg5320a_runtime_resume(struct device *dev)
+{
+	struct isg5320a_data *data = iio_priv(dev_get_drvdata(dev));
+
+	return isg5320a_mode_normal(data);
+}
+
+/*
+ * Runtime PM only. System sleep leaves the chip as it is, as the vendor
+ * does (its suspend/resume only stop and restart the work items), so an
+ * enabled grip event can still wake the system.
+ */
+static const struct dev_pm_ops isg5320a_pm_ops = {
+	RUNTIME_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,
+	.shutdown = isg5320a_shutdown,
+	.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] 18+ messages in thread

* Re: [PATCH v2 1/2] dt-bindings: iio: proximity: add Imagis ISG5320A
  2026-11-17 10:44 ` [PATCH v2 1/2] dt-bindings: iio: proximity: add Imagis ISG5320A Adil Hüsrev Tepe
  2026-11-17 10:44   ` [PATCH v2 2/2] iio: proximity: add Imagis ISG5320A SAR sensor driver Adil Hüsrev Tepe
@ 2026-11-17 10:54   ` sashiko-bot
  1 sibling, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-11-17 10:54 UTC (permalink / raw)
  To: Adil Hüsrev Tepe; +Cc: devicetree, robh, conor+dt

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] dt-bindings: iio: proximity: duplicate int-gpios property in
  imagis,isg5320a
- [Low] dt-bindings: iio: proximity: patch changelog in permanent commit
  message
--

commit a0ca949bf69221deb4e3e78d116e407964e58ad3
Author: Adil Hüsrev Tepe <tadilhusrev@gmail.com>

dt-bindings: iio: proximity: add Imagis ISG5320A

This commit adds a Devicetree binding schema for the Imagis ISG5320A
I2C capacitive SAR/grip proximity sensor.

> v1 -> v2 (addressing Sashiko AI's review of v1,
> https://sashiko.dev/#/patchset/20261116074013.355363-1-tadilhusrev@gmail.com?part=1):
> - Document int-gpios: the driver optionally reads it during the reset
>   sequence; it was undocumented in v1.
> - Reword the description to the chip's own characteristics instead of
>   how the Linux IIO channel is exposed.
> - Simplify vdd-supply to "vdd-supply: true" (left optional: the
>   XCover5's own grip sensor has no vdd-supply node at all, an
>   always-on LDO not modeled in DT, which the driver's
>   devm_regulator_get_enable_optional() already tolerates).
> - Rename the example node to "proximity@28", drop the unused gpio.h
>   include, and add the blank line dt-check-style wants before the
>   child node.

[Severity: Low]
Should this patch revision changelog be placed below the "---" separator
line rather than in the commit message body so that it is not recorded in
the permanent git history?

> 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 0000000000000..ccb84b29f468b
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/iio/proximity/imagis,isg5320a.yaml
> @@ -0,0 +1,62 @@

[ ... ]

> +  interrupts:
> +    maxItems: 1
> +    description: active-low data-ready / proximity interrupt
> +
> +  int-gpios:
> +    maxItems: 1
> +    description:
> +      GPIO connected to the same INT line as the "interrupts" property. When
> +      present it is polled during the reset sequence to observe the INT level,
> +      as the vendor driver does; otherwise the reset falls back to fixed delays.

[Severity: Low]
Should int-gpios be dropped from the binding?

A single physical interrupt line that is only observed by the host is
already described by the required interrupts property and should not be
duplicated as both interrupts and int-gpios on the same node. Requesting
the same pin as both a GPIO input and an interrupt can also cause pinmux
or GPIO-IRQ lock conflicts on platforms where the interrupt parent is a
GPIO controller (such as Exynos pinctrl). In addition, Devicetree bindings
describe hardware rather than driver polling or reset implementation
details.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117104414.1182364-1-tadilhusrev@gmail.com?part=1

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 2/2] iio: proximity: add Imagis ISG5320A SAR sensor driver
  2026-11-17 10:44   ` [PATCH v2 2/2] iio: proximity: add Imagis ISG5320A SAR sensor driver Adil Hüsrev Tepe
@ 2026-11-17 11:08     ` sashiko-bot
  2026-11-17 13:56     ` Andy Shevchenko
  1 sibling, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-11-17 11:08 UTC (permalink / raw)
  To: Adil Hüsrev Tepe; +Cc: devicetree, robh, conor+dt

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] iio: proximity: isg5320a: inverted INT polarity in
  isg5320a_reset()
- [Medium] iio: proximity: isg5320a: free_irq() runs before
  isg5320a_teardown()
- [Medium] iio: proximity: isg5320a: broken wakeup handling in
  isg5320a_events_on()
- [Low] iio: proximity: isg5320a: unchecked enable_irq_wake() in
  isg5320a_events_on()
--

commit b880374f416c9c620d39544cb088cc6a533d446b
Author: Adil Hüsrev Tepe <tadilhusrev@gmail.com>

iio: proximity: add Imagis ISG5320A SAR sensor driver

This commit adds an IIO proximity driver for the Imagis ISG5320A I2C
capacitive SAR/grip sensor, exposing a raw proximity channel and
rising/falling threshold events.

> diff --git a/drivers/iio/proximity/isg5320a.c b/drivers/iio/proximity/isg5320a.c
> new file mode 100644
> index 0000000000000..baa8d07ecfd7f
> --- /dev/null
> +++ b/drivers/iio/proximity/isg5320a.c
> @@ -0,0 +1,880 @@
[ ... ]
> +/* Wait for the INT line to reach @level: up to 10 x 5 ms (vendor :262, :281). */
> +static int isg5320a_wait_int(struct isg5320a_data *data, int level)
> +{
> +	int cnt, val;
> +
> +	if (!data->int_gpio) {
> +		msleep(50);
> +		return 0;
> +	}
> +
> +	for (cnt = 0; cnt < 10; cnt++) {
> +		/* Logical, not raw: honours the GPIO's DT polarity. */
> +		val = gpiod_get_value_cansleep(data->int_gpio);
> +		if (val < 0)
> +			return val;
> +		if (val == level)
> +			return cnt;
> +		usleep_range(5000, 5100);
> +	}
> +
> +	return -ETIMEDOUT;
> +}
> +
> +/* vendor isg5320a_reset(), :247-292, plus a CHIPID read the vendor never does */
> +static int isg5320a_reset(struct isg5320a_data *data)
> +{
[ ... ]
> +	if (isg5320a_wait_int(data, 1) < 0)			/* :262-266 */
> +		dev_warn(dev, "INT did not go high before reset\n");
> +
> +	ret = regmap_write(data->regmap, ISG5320A_REG_PROTECT,	/* :268-271 */
> +			   ISG5320A_PROTECT_UNLOCK);
> +	if (ret)
> +		return dev_err_probe(dev, ret, "unlock protect failed\n");
> +
> +	ret = regmap_write(data->regmap, ISG5320A_REG_SOFTRESET,	/* :273-276 */
> +			   ISG5320A_SOFTRESET_VAL);
> +	if (ret)
> +		return dev_err_probe(dev, ret, "soft reset write failed\n");
> +
> +	usleep_range(1000, 1100);				/* :278 */
> +
> +	ret = isg5320a_wait_int(data, 0);			/* :280-289 */
> +	if (ret < 0)
> +		return dev_err_probe(dev, -EIO, "INT not asserted after soft reset\n");

[Severity: High]
Are the @level arguments passed to isg5320a_wait_int() inverted for an
active-low interrupt GPIO?

gpiod_get_value_cansleep() returns the logical state (0 when deasserted,
1 when asserted), whereas the callers here still pass the physical line
levels (1 for released/high before reset, 0 for asserted/low after soft
reset).  When int-gpios is described as GPIO_ACTIVE_LOW in Device Tree,
isg5320a_wait_int(data, 0) waits for INT to be deasserted after soft
reset, timing out and failing probe.

Also, dev_err_probe() overwrites ret with -EIO instead of propagating the
error returned by isg5320a_wait_int().

[ ... ]
> +static int isg5320a_events_on(struct isg5320a_data *data)
> +{
[ ... ]
> +	WRITE_ONCE(data->ev_enabled, true);
> +	enable_irq(data->irq);						/* :721 */
> +	/* Cache the decision: device_may_wakeup(dev) may change before events_off(). */
> +	data->irq_wake_enabled = device_may_wakeup(dev);
> +	if (data->irq_wake_enabled)
> +		enable_irq_wake(data->irq);				/* :722 */

[Severity: Low]
What happens if enable_irq_wake(data->irq) fails here?
data->irq_wake_enabled remains true while desc->wake_depth stays at 0, so
isg5320a_events_off() will later call disable_irq_wake(data->irq) and
trigger an unbalanced IRQ wake disable warning.

[Severity: Medium]
Does arming enable_irq_wake() in isg5320a_events_on() respect changes to
/sys/.../power/wakeup while events are enabled?

If userspace disables wakeup via sysfs after enabling proximity events,
IRQD_WAKEUP_STATE remains set on data->irq and isg5320a_pm_ops has no
system sleep callbacks to stop the sensor, so the interrupt still wakes
the system from suspend.  Conversely, on Device Tree systems with
wakeup-source, i2c_device_probe() registers client->irq via
dev_pm_set_wake_irq() (which also makes the device_init_wakeup() call in
isg5320a_probe() redundant), arming the wake IRQ on every suspend even
when data->ev_enabled is false.

Wakeup arming and sensor sleep/resume state across system suspend should
be handled in system sleep PM callbacks instead of isg5320a_events_on()
and isg5320a_events_off().

[ ... ]
> +static void isg5320a_events_off(struct isg5320a_data *data)
> +{
> +	struct device *dev = data->dev;
> +	int ret = 0;
> +
> +	scoped_guard(mutex, &data->lock)
> +		ret = regmap_write(data->regmap, ISG5320A_REG_IRQFUNC,	/* :726 */
> +				   ISG5320A_IRQFUNC_DISABLE);
> +	if (ret)
> +		dev_warn(dev, "IRQFUNC disable failed: %d\n", ret);
> +
> +	WRITE_ONCE(data->ev_enabled, false);
> +	disable_irq(data->irq);						/* :728 */
> +	if (data->irq_wake_enabled) {
> +		disable_irq_wake(data->irq);				/* :729 */
> +		data->irq_wake_enabled = false;
> +	}
> +}
[ ... ]
> +/* vendor isg5320a_remove(), :2030-2033 */
> +static void isg5320a_teardown(void *arg)
> +{
> +	struct isg5320a_data *data = arg;
> +	struct device *dev = data->dev;
> +
> +	pm_runtime_disable(dev);
> +
> +	if (data->ev_enabled) {
> +		isg5320a_events_off(data);
> +		pm_runtime_put_noidle(dev);
> +	}
> +
> +	if (!pm_runtime_status_suspended(dev))
> +		isg5320a_mode_sleep(data);
> +
> +	pm_runtime_set_suspended(dev);
> +	pm_runtime_dont_use_autosuspend(dev);
> +}
> +
> +static int isg5320a_probe(struct i2c_client *client)
> +{
[ ... ]
> +	ret = devm_add_action_or_reset(dev, isg5320a_teardown, data);
> +	if (ret)
> +		return ret;
> +
> +	if (data->irq > 0) {
> +		irqflags = irq_get_trigger_type(data->irq);
> +		if (!irqflags)
> +			irqflags = IRQF_TRIGGER_FALLING;	/* :1932 */
> +
> +		ret = devm_request_threaded_irq(dev, data->irq, NULL,
> +						isg5320a_irq_thread,
> +						irqflags | IRQF_ONESHOT |
> +						IRQF_NO_AUTOEN,
> +						"isg5320a", indio_dev);
> +		if (ret)
> +			return dev_err_probe(dev, ret, "irq request failed\n");
> +
> +		if (device_property_read_bool(dev, "wakeup-source"))
> +			device_init_wakeup(dev, true);
> +	}
> +
> +	indio_dev->name = "isg5320a";
> +	indio_dev->modes = INDIO_DIRECT_MODE;
> +	if (data->irq > 0) {
> +		indio_dev->info = &isg5320a_info;
> +		indio_dev->channels = isg5320a_channels;
> +		indio_dev->num_channels = ARRAY_SIZE(isg5320a_channels);
> +	} else {
> +		indio_dev->info = &isg5320a_info_noirq;
> +		indio_dev->channels = isg5320a_channels_noirq;
> +		indio_dev->num_channels = ARRAY_SIZE(isg5320a_channels_noirq);
> +	}
> +
> +	return devm_iio_device_register(dev, indio_dev);
> +}

[Severity: Medium]
Doesn't registering isg5320a_teardown() before devm_request_threaded_irq()
and devm_iio_device_register() cause devres to free data->irq before
isg5320a_teardown() runs?

If the driver is unbound while proximity events are enabled, devres
unregisters indio_dev and calls free_irq(data->irq, indio_dev) while
ISG5320A_REG_IRQFUNC and IRQ wake are still active, and
isg5320a_teardown() -> isg5320a_events_off() then calls disable_irq() and
disable_irq_wake() on an IRQ that has already been shut down and
released.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117104414.1182364-1-tadilhusrev@gmail.com?part=2

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 2/2] iio: proximity: add Imagis ISG5320A SAR sensor driver
  2026-11-17 10:44   ` [PATCH v2 2/2] iio: proximity: add Imagis ISG5320A SAR sensor driver Adil Hüsrev Tepe
  2026-11-17 11:08     ` sashiko-bot
@ 2026-11-17 13:56     ` Andy Shevchenko
  1 sibling, 0 replies; 18+ messages in thread
From: Andy Shevchenko @ 2026-11-17 13:56 UTC (permalink / raw)
  To: Adil Hüsrev Tepe
  Cc: jic23, robh, krzk+dt, conor+dt, dlechner, nuno.sa, andy,
	linux-iio, devicetree, linux-kernel

On Tue, Nov 17, 2026 at 01:44:14PM +0300, Adil Hüsrev Tepe wrote:
> 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.

> v1 -> v2 (addressing Andy Shevchenko's and Sashiko AI's review of v1,
> https://sashiko.dev/#/patchset/20261116074013.355363-1-tadilhusrev@gmail.com?part=2):
> - Drop the unused #include <linux/kernel.h>; audit includes for the
>   IWYU principle (array_size.h, cleanup.h, errno.h, types.h for
>   symbols actually used).
> - Use ACQUIRE(pm_runtime_active_auto_try_enabled)/ACQUIRE_ERR() in
>   isg5320a_get_sample() instead of open-coded
>   pm_runtime_resume_and_get()/pm_runtime_put_autosuspend().
> - Make the Kconfig prompt, this file's top comment, and
>   MODULE_DESCRIPTION() use the same wording.
> - Propagate the PROTECT-unlock write failure in isg5320a_reset()
>   instead of only warning (matches the existing SOFTRESET handling).
> - isg5320a_wait_int() now reads the INT gpio with
>   gpiod_get_value_cansleep() (logical, polarity-aware) instead of
>   _raw_, and returns a real error instead of looping to -ETIMEDOUT on
>   a failed read.
> - Cache device_may_wakeup() at isg5320a_events_on() time
>   (irq_wake_enabled) and use that cached value in
>   isg5320a_events_off(), instead of re-checking device_may_wakeup() at
>   disable time: toggling /sys/.../power/wakeup between enable and
>   disable no longer produces an unbalanced
>   enable_irq_wake()/disable_irq_wake() pair.
> - isg5320a_shutdown() now calls isg5320a_events_off() (disables the
>   IRQ and takes data->lock around the IRQFUNC write) instead of
>   writing IRQFUNC unlocked with the IRQ still enabled, and only calls
>   isg5320a_mode_sleep() when the device isn't already
>   runtime-suspended.
> - Register the isg5320a_teardown() devres action right after
>   isg5320a_mode_normal() succeeds instead of after the IRQ request, so
>   a later probe failure (e.g. devm_request_threaded_irq()) still puts
>   the chip back to sleep instead of leaving it scanning unbound.
> - Use a named initializer in isg5320a_id[].

Changelog should be in the comment block, after the '---' line below.

> The driver was derived from the Samsung vendor driver during XCover5
> mainline bring-up with the help of an AI coding assistant (Claude Code,
> Anthropic), which drafted the mainline IIO driver; I reviewed every
> line, built it (arm64, 0 warnings), ran checkpatch --strict (clean),
> and tested it live on a Samsung Galaxy XCover5 (2026-11-17): the driver
> binds and registers as iio:device4 "isg5320a", with a live
> in_proximity0_raw read-back.

This paragraph has to be in the cover letter and not here.

...

> +#include <linux/array_size.h>
> +#include <linux/bits.h>
> +#include <linux/cleanup.h>
> +#include <linux/delay.h>
> +#include <linux/device.h>
> +#include <linux/errno.h>
> +#include <linux/gpio/consumer.h>
> +#include <linux/i2c.h>
> +#include <linux/interrupt.h>
> +#include <linux/irq.h>

> +#include <linux/mod_devicetable.h>

Nope. This should not be included in a new code.

> +#include <linux/module.h>
> +#include <linux/mutex.h>
> +#include <linux/pm.h>
> +#include <linux/pm_runtime.h>

> +#include <linux/pm_wakeup.h>

Have you read what's written in the top of that file?
Please, drop it here.

> +#include <linux/property.h>
> +#include <linux/regmap.h>
> +#include <linux/regulator/consumer.h>
> +#include <linux/types.h>
> +
> +#include <linux/iio/events.h>
> +#include <linux/iio/iio.h>

...

> +#define ISG5320A_RESET_CONDITION	5000	/* reg.h :99, for cfcal_th */

This is a cryptic comment. Either drop it, or better to explain on top of the
definition.

...

> +#define ISG5320A_AUTOSUSPEND_MS		5000

(5 * MSEC_PER_SEC)

will require time.h to be included.

...

> +struct isg5320a_reg_data {
> +	u8 addr;
> +	u8 val;
> +};

> +/*
> + * Vendor setup_reg[] for "XCOVER5 ALL" (isg5320a_reg.h :283-435). The other
> + * table (:130-282) is under CONFIG_SENSORS_ISG5320A_XCOVER5_KOR, which the
> + * stock exynos850-xcover5xx_defconfig leaves unset; it differs only in
> + * 0x9C (threshold low byte), 0xA0 (far hysteresis low byte) and 0xBA.
> + */
> +static const struct isg5320a_reg_data 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 }, { 0x41, 0x11 }, { 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 }, { 0xC5, 0x00 }, { 0x13, 0x3A },
> +	{ 0x18, 0xF1 }, /* A ch : CS0, B ch : 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 },
> +};

...

> +struct isg5320a_data {
> +	struct device *dev;
> +	struct regmap *regmap;

One of the above is redundant.

> +	struct gpio_desc *int_gpio;
> +	int irq;
> +	/* Serialises multi-register chip sequences and the cached sample. */
> +	struct mutex lock;
> +	/* Serialises event enable/disable (sleeps in disable_irq()). */
> +	struct mutex ev_lock;

> +	bool ev_enabled;
> +	bool irq_wake_enabled;
> +	bool close;

If they are protected by the same lock or have no clashes, use

	bool XXX:1;

to pack all of them into a single boolean. Move them to the end, so
there will be a chance to reduce a gap. Check with `pahole`.

> +	u16 cdc;
> +	u16 base;
> +	u16 thresh;
> +	u16 close_hyst;
> +	u16 far_hyst;
> +	u32 cfcal_th;

Move it upper, before u16 ones.

> +};

...

> +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,

Why?! This has to be justified in the comment above.

> +};

...

> +/* Wait for the INT line to reach @level: up to 10 x 5 ms (vendor :262, :281). */
> +static int isg5320a_wait_int(struct isg5320a_data *data, int level)
> +{
> +	int cnt, val;
> +
> +	if (!data->int_gpio) {

> +		msleep(50);

All sleeps has to be explained.

> +		return 0;
> +	}
> +
> +	for (cnt = 0; cnt < 10; cnt++) {
> +		/* Logical, not raw: honours the GPIO's DT polarity. */
> +		val = gpiod_get_value_cansleep(data->int_gpio);
> +		if (val < 0)
> +			return val;
> +		if (val == level)
> +			return cnt;
> +		usleep_range(5000, 5100);
> +	}

In iopoll.h you may find readx_poll_timeout().

> +	return -ETIMEDOUT;
> +}

...

> +static int isg5320a_reset(struct isg5320a_data *data)
> +{
> +	struct device *dev = data->dev;
> +	unsigned int val;
> +	int ret;
> +
> +	usleep_range(5000, 5100);				/* :255-256 */

Why?! Also use fsleep(5 * USEC_PER_MSEC).

> +	ret = regmap_read(data->regmap, ISG5320A_REG_IRQSRC, &val);	/* :258 */
> +	if (ret)
> +		return dev_err_probe(dev, ret, "no response at IRQSRC\n");
> +
> +	ret = regmap_read(data->regmap, ISG5320A_REG_CHIPID, &val);
> +	if (ret)
> +		return dev_err_probe(dev, ret, "CHIPID read failed\n");

> +	if (val == ISG5320A_VENDOR_CHIP_ID)
> +		dev_info(dev, "CHIPID 0x%02x\n", val);

Useless.

> +	else
> +		dev_warn(dev, "CHIPID 0x%02x (vendor header says 0x%02x; not enforced)\n",
> +			 val, ISG5320A_VENDOR_CHIP_ID);
> +
> +	if (isg5320a_wait_int(data, 1) < 0)			/* :262-266 */
> +		dev_warn(dev, "INT did not go high before reset\n");
> +
> +	ret = regmap_write(data->regmap, ISG5320A_REG_PROTECT,	/* :268-271 */
> +			   ISG5320A_PROTECT_UNLOCK);
> +	if (ret)
> +		return dev_err_probe(dev, ret, "unlock protect failed\n");
> +
> +	ret = regmap_write(data->regmap, ISG5320A_REG_SOFTRESET,	/* :273-276 */
> +			   ISG5320A_SOFTRESET_VAL);
> +	if (ret)
> +		return dev_err_probe(dev, ret, "soft reset write failed\n");

> +	usleep_range(1000, 1100);				/* :278 */

fsleep (1 * USEC_PER_MSEC) and why?


> +	ret = isg5320a_wait_int(data, 0);			/* :280-289 */
> +	if (ret < 0)
> +		return dev_err_probe(dev, -EIO, "INT not asserted after soft reset\n");
> +	dev_dbg(dev, "reset done, wait cnt %d\n", ret);
> +
> +	return 0;
> +}

...

> +/* vendor isg5320a_initialize(), :614-660, without the /sdcard override */
> +static int isg5320a_initialize(struct isg5320a_data *data)
> +{
> +	struct device *dev = data->dev;
> +	unsigned int i, val, mismatch = 0;
> +	u8 buf[6];
> +	int ret;
> +
> +	guard(mutex)(&data->lock);
> +
> +	ret = regmap_read(data->regmap, ISG5320A_REG_IRQSRC, &val);	/* :625 */
> +	if (ret)
> +		return ret;
> +	ret = regmap_write(data->regmap, ISG5320A_REG_SCANCTRL1,	/* :626 */
> +			   ISG5320A_SCAN_STOP);
> +	if (ret)
> +		return ret;

> +	msleep(30);						/* :627 */

Do all this needs to be under the mutex?

> +	for (i = 0; i < ARRAY_SIZE(isg5320a_setup_reg); i++) {	/* :631-637 */
> +		const struct isg5320a_reg_data *r = &isg5320a_setup_reg[i];
> +
> +		ret = regmap_write(data->regmap, r->addr, r->val);
> +		if (ret)
> +			return dev_err_probe(dev, ret, "init write 0x%02x failed\n",
> +					     r->addr);

Don't we have something like reg_defaults_raw field and the respective
struct reg_default?

> +		ret = regmap_read(data->regmap, r->addr, &val);
> +		if (ret)
> +			return ret;
> +		if (val != r->val) {
> +			mismatch++;
> +			dev_dbg(dev, "reg 0x%02x wrote 0x%02x read 0x%02x\n",
> +				r->addr, r->val, val);
> +		}
> +	}
> +	dev_info(dev, "init table: %zu writes, %u read back different\n",
> +		 ARRAY_SIZE(isg5320a_setup_reg), mismatch);
> +
> +	/* :646-650 reads the threshold; :890-897 reads all six bytes */
> +	ret = regmap_bulk_read(data->regmap, ISG5320A_REG_B_PROXCTL3, buf,
> +			       sizeof(buf));
> +	if (ret)
> +		return ret;

> +	data->thresh = (buf[0] << 8) | buf[1];
> +	data->close_hyst = (buf[2] << 8) | buf[3];
> +	data->far_hyst = (buf[4] << 8) | buf[5];

We have get_unaligned_?eXX(), we have ?eXX_to_cpu() and cpu_to_?eXX(), use them.

> +	ret = regmap_read(data->regmap, ISG5320A_REG_DIGITAL_ACC, &val);	/* :653-657 */
> +	if (ret)
> +		return ret;
> +	data->cfcal_th = ISG5320A_RESET_CONDITION * val / 8;
> +
> +	dev_info(dev, "threshold %u, close hyst %u, far hyst %u, cfcal_th %u\n",
> +		 data->thresh, data->close_hyst, data->far_hyst, data->cfcal_th);
> +
> +	return 0;
> +}

...

> +	/*
> +	 * Registered now, with the chip already active, so that a later
> +	 * failure (e.g. the IRQ request below) still puts it back to sleep
> +	 * instead of leaving it scanning with nothing bound to it.
> +	 */
> +	pm_runtime_set_autosuspend_delay(dev, ISG5320A_AUTOSUSPEND_MS);
> +	pm_runtime_use_autosuspend(dev);
> +	pm_runtime_set_active(dev);
> +	pm_runtime_get_noresume(dev);
> +	pm_runtime_enable(dev);
> +	pm_runtime_put_autosuspend(dev);
> +
> +	ret = devm_add_action_or_reset(dev, isg5320a_teardown, data);
> +	if (ret)
> +		return ret;

Do you understand how it works? Why don't you use devn_pm_runtime*() calls?

...

> +	if (data->irq > 0) {
> +		irqflags = irq_get_trigger_type(data->irq);
> +		if (!irqflags)
> +			irqflags = IRQF_TRIGGER_FALLING;	/* :1932 */

Why?! It's a new driver, let the firmware to describe thing properly (and you
never know if there is a NOT gate in the middle which make the default working
in a wrong way (and on top, but I haven't checked this, the shared interrupt
case if supported by HW).

> +		ret = devm_request_threaded_irq(dev, data->irq, NULL,
> +						isg5320a_irq_thread,
> +						irqflags | IRQF_ONESHOT |
> +						IRQF_NO_AUTOEN,
> +						"isg5320a", indio_dev);
> +		if (ret)
> +			return dev_err_probe(dev, ret, "irq request failed\n");

Read mailing list and IIO Git history to understand what's wrong here.

> +
> +		if (device_property_read_bool(dev, "wakeup-source"))
> +			device_init_wakeup(dev, true);
> +	}

...

Overall impression, that this driver was written without enough understanding
on what's going on. Take your time, check datasheet and corner cases, test them
on real HW, et cetera.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v3 0/2] iio: proximity: add Imagis ISG5320A (Samsung Galaxy XCover5)
  2026-11-16  7:40 [PATCH v1 0/2] iio: proximity: add Imagis ISG5320A (Samsung Galaxy XCover5) Adil Hüsrev Tepe
                   ` (3 preceding siblings ...)
  2026-11-17 10:44 ` [PATCH v2 1/2] dt-bindings: iio: proximity: add Imagis ISG5320A Adil Hüsrev Tepe
@ 2026-11-17 17:33 ` Adil Hüsrev Tepe
  2026-11-17 17:33   ` [PATCH v3 1/2] dt-bindings: iio: proximity: add Imagis ISG5320A Adil Hüsrev Tepe
                     ` (2 more replies)
  4 siblings, 3 replies; 18+ messages in thread
From: Adil Hüsrev Tepe @ 2026-11-17 17:33 UTC (permalink / raw)
  To: jic23, robh, krzk+dt, conor+dt
  Cc: dlechner, nuno.sa, andy, linux-iio, devicetree, linux-kernel,
	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).

  Patch 1  dt-bindings
  Patch 2  the IIO driver

v3 fixes the real review findings on v2: Sashiko AI caught a High-
severity INT-polarity bug in the reset sequence (eliminated by
dropping int-gpios from the driver and binding entirely, since the
pin is already described by the required "interrupts" property) plus
a Medium-severity devm unwind-order bug and a Low-severity unchecked
enable_irq_wake(). Both are now live-tested, not just built. Per-patch
details are below each patch's "---" line, as Andy Shevchenko asked.

Tested on a Samsung Galaxy XCover5 running 7.4-rc1 plus this series
(2026-11-17, kernel 7.4.0-rc1-00023-gdcb8b91fb779+ #30): the driver
binds, registers as iio:device4 "isg5320a", and in_proximity0_raw
tracked a live hand-proximity test (baseline ~0, swinging to
-12817/9748/10759 as a hand approached/withdrew the sensor).
checkpatch.pl --strict and dt_binding_check are clean.

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 and
drafted these changelogs. I reviewed every line, built it (arm64, 0
warnings), ran checkpatch --strict (clean), and tested it on hardware
as described above, 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   |  55 ++
 drivers/iio/proximity/Kconfig                     |  11 +
 drivers/iio/proximity/Makefile                    |   1 +
 drivers/iio/proximity/isg5320a.c                  | 848 +++++++++++++++++++
 4 files changed, 915 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/proximity/imagis,isg5320a.yaml
 create mode 100644 drivers/iio/proximity/isg5320a.c

--
2.53.0

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v3 1/2] dt-bindings: iio: proximity: add Imagis ISG5320A
  2026-11-17 17:33 ` [PATCH v3 0/2] iio: proximity: add Imagis ISG5320A (Samsung Galaxy XCover5) Adil Hüsrev Tepe
@ 2026-11-17 17:33   ` Adil Hüsrev Tepe
  2026-11-17 17:33   ` [PATCH v3 2/2] iio: proximity: add Imagis ISG5320A SAR sensor driver Adil Hüsrev Tepe
  2026-11-18  9:00   ` [PATCH v3 0/2] iio: proximity: add Imagis ISG5320A (Samsung Galaxy XCover5) Joshua Crofts
  2 siblings, 0 replies; 18+ messages in thread
From: Adil Hüsrev Tepe @ 2026-11-17 17:33 UTC (permalink / raw)
  To: jic23, robh, krzk+dt, conor+dt
  Cc: dlechner, nuno.sa, andy, linux-iio, devicetree, linux-kernel,
	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>
---
v2 -> v3 (addressing Sashiko AI's review of v2,
https://sashiko.dev/#/patchset/20261117104414.1182364-1-tadilhusrev@gmail.com?part=1):
- Drop int-gpios entirely instead of just documenting it. The pin is
  already described by the required "interrupts" property; polling it
  as a second GPIO duplicates that and risks pinmux/GPIO-IRQ lock
  conflicts on platforms where the interrupt parent is a GPIO
  controller (such as Exynos pinctrl), and a binding should describe
  hardware, not a driver's internal reset-polling implementation. The
  driver's matching change is in "iio: proximity: add Imagis ISG5320A
  SAR sensor driver".
- Move this changelog below the "---" line instead of leaving it in
  the commit message body (also flagged by Sashiko AI on v2).

v1 -> v2 (addressing Sashiko AI's review of v1,
https://sashiko.dev/#/patchset/20261116074013.355363-1-tadilhusrev@gmail.com?part=1):
- Document int-gpios: the driver optionally reads it during the reset
  sequence; it was undocumented in v1.
- Reword the description to the chip's own characteristics instead of
  how the Linux IIO channel is exposed.
- Simplify vdd-supply to "vdd-supply: true" (left optional: the
  XCover5's own grip sensor has no vdd-supply node at all, an
  always-on LDO not modeled in DT, which the driver's
  devm_regulator_get_enable_optional() already tolerates).
- Rename the example node to "proximity@28", drop the unused gpio.h
  include, and add the blank line dt-check-style wants before the
  child node.
---
 .../iio/proximity/imagis,isg5320a.yaml        | 55 +++++++++++++++++++
 1 file changed, 55 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/proximity/imagis,isg5320a.yaml

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 000000000..22259e341
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/proximity/imagis,isg5320a.yaml
@@ -0,0 +1,55 @@
+# 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.
+  As fitted on the Samsung Galaxy XCover5.
+
+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
+
+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_LEVEL_LOW>;
+            vdd-supply = <&grip_vdd>;
+            wakeup-source;
+        };
+    };
+...
--
2.53.0

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v3 2/2] iio: proximity: add Imagis ISG5320A SAR sensor driver
  2026-11-17 17:33 ` [PATCH v3 0/2] iio: proximity: add Imagis ISG5320A (Samsung Galaxy XCover5) Adil Hüsrev Tepe
  2026-11-17 17:33   ` [PATCH v3 1/2] dt-bindings: iio: proximity: add Imagis ISG5320A Adil Hüsrev Tepe
@ 2026-11-17 17:33   ` Adil Hüsrev Tepe
  2026-11-17 17:55     ` sashiko-bot
  2026-11-18  9:53     ` Joshua Crofts
  2026-11-18  9:00   ` [PATCH v3 0/2] iio: proximity: add Imagis ISG5320A (Samsung Galaxy XCover5) Joshua Crofts
  2 siblings, 2 replies; 18+ messages in thread
From: Adil Hüsrev Tepe @ 2026-11-17 17:33 UTC (permalink / raw)
  To: jic23, robh, krzk+dt, conor+dt
  Cc: dlechner, nuno.sa, andy, linux-iio, devicetree, linux-kernel,
	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.

Tested on a Samsung Galaxy XCover5 (re-confirmed 2026-11-17, kernel
7.4.0-rc1-00023-gdcb8b91fb779+ #30): the driver binds, registers as
iio:device4 "isg5320a", and in_proximity0_raw tracked a live
hand-proximity test (baseline ~0, swinging to -12817/9748/10759 as a
hand approached/withdrew the sensor).

Signed-off-by: Adil Hüsrev Tepe <tadilhusrev@gmail.com>
---
v2 -> v3 (addressing Sashiko AI's review of v2,
https://sashiko.dev/#/patchset/20261117104414.1182364-1-tadilhusrev@gmail.com?part=2,
and Andy Shevchenko's review of the same):
- [High] isg5320a_reset() read the INT gpio with
  gpiod_get_value_cansleep() (logical, polarity-aware) but still
  passed the vendor's physical level arguments (1 before reset, 0
  after), which is inverted under this board's GPIO_ACTIVE_LOW wiring
  and could time out. Fixed by dropping int-gpios entirely (see the
  matching dt-bindings patch): the reset sequence now always uses the
  fixed-delay fallback that was already coded for the no-int-gpio
  case, so the polarity bug is eliminated by construction.
- [Medium] the isg5320a_teardown() devm action was registered before
  devm_request_threaded_irq(), so devm's LIFO unwind freed the IRQ
  before teardown ran, and teardown's isg5320a_events_off() could
  disable_irq()/disable_irq_wake() an already-freed IRQ. Fixed by
  registering the teardown action after the IRQ request.
- [Low] isg5320a_events_on() marked irq_wake_enabled from
  device_may_wakeup() alone, not from whether enable_irq_wake() itself
  succeeded. Fixed by only marking it enabled on success.
- Moved this changelog below the "---" line and the AI-coding-
  assistant disclosure to the cover letter, instead of leaving both in
  the commit message body (flagged by Andy Shevchenko).

v1 -> v2 (addressing Andy Shevchenko's and Sashiko AI's review of v1,
https://sashiko.dev/#/patchset/20261116074013.355363-1-tadilhusrev@gmail.com?part=2):
- Drop the unused #include <linux/kernel.h>; audit includes for the
  IWYU principle (array_size.h, cleanup.h, errno.h, types.h for
  symbols actually used).
- Use ACQUIRE(pm_runtime_active_auto_try_enabled)/ACQUIRE_ERR() in
  isg5320a_get_sample() instead of open-coded
  pm_runtime_resume_and_get()/pm_runtime_put_autosuspend().
- Make the Kconfig prompt, this file's top comment, and
  MODULE_DESCRIPTION() use the same wording.
- Propagate the PROTECT-unlock write failure in isg5320a_reset()
  instead of only warning (matches the existing SOFTRESET handling).
- isg5320a_wait_int() read the INT gpio with
  gpiod_get_value_cansleep() (logical, polarity-aware) instead of
  _raw_, and returned a real error instead of looping to -ETIMEDOUT on
  a failed read (superseded in v3 above by dropping int-gpios).
- Cache device_may_wakeup() at isg5320a_events_on() time
  (irq_wake_enabled) and use that cached value in
  isg5320a_events_off(), instead of re-checking device_may_wakeup() at
  disable time: toggling /sys/.../power/wakeup between enable and
  disable no longer produces an unbalanced
  enable_irq_wake()/disable_irq_wake() pair.
- isg5320a_shutdown() now calls isg5320a_events_off() (disables the
  IRQ and takes data->lock around the IRQFUNC write) instead of
  writing IRQFUNC unlocked with the IRQ still enabled, and only calls
  isg5320a_mode_sleep() when the device isn't already
  runtime-suspended.
- Register the isg5320a_teardown() devres action right after
  isg5320a_mode_normal() succeeds instead of after the IRQ request
  (superseded in v3 above by moving it after the IRQ request instead).
- Use a named initializer in isg5320a_id[].
---
 drivers/iio/proximity/Kconfig    |  11 +
 drivers/iio/proximity/Makefile   |   1 +
 drivers/iio/proximity/isg5320a.c | 848 ++++++++++++++++++++++++++++++
 3 files changed, 860 insertions(+)
 create mode 100644 drivers/iio/proximity/isg5320a.c

diff --git a/drivers/iio/proximity/Kconfig b/drivers/iio/proximity/Kconfig
index bb77fad2a..311a7b9e4 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 4352833dd..6aa606fa5 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 000000000..4df0e09d3
--- /dev/null
+++ b/drivers/iio/proximity/isg5320a.c
@@ -0,0 +1,848 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Imagis ISG5320A capacitive SAR/grip sensor.
+ *
+ * Register map, init table and every write sequence below come from the
+ * Samsung vendor driver (drivers/sensors/isg5320a.c + isg5320a_reg.h,
+ * Galaxy XCover5 5.10 tree, Copyright (C) Imagis Technology). Citations of
+ * the form "vendor :NNN" refer to lines in that isg5320a.c. This driver
+ * writes no register the vendor driver does not write, and only with the
+ * values the vendor writes; regmap enforces that through writeable_reg.
+ *
+ * The chip is used as one proximity channel: the vendor's "diff" value
+ * (CDC16_T - BSL16_B, i.e. 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/device.h>
+#include <linux/errno.h>
+#include <linux/i2c.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/pm.h>
+#include <linux/pm_runtime.h>
+#include <linux/pm_wakeup.h>
+#include <linux/property.h>
+#include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
+#include <linux/types.h>
+
+#include <linux/iio/events.h>
+#include <linux/iio/iio.h>
+
+/* Registers (vendor isg5320a_reg.h :19-79) */
+#define ISG5320A_REG_IRQSRC		0x00	/* read releases the INT line */
+#define ISG5320A_REG_IRQSTS		0x01
+#define   ISG5320A_IRQSTS_PROX		BIT(4)	/* ISG5320A_PROX_STATE, reg.h :81 */
+#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_REG_SCANCTRL2		0x39
+#define   ISG5320A_SCAN2_RESET		0x00
+#define   ISG5320A_SCAN2_CLEAR		0x60
+#define   ISG5320A_BFCAL_START		0x07
+/* CDC16_T_H, CDC16_T_L, BSL16_B_H, BSL16_B_L (vendor :453) */
+#define ISG5320A_REG_CDC16_T_H		0x5C
+/* B_PROXCTL3..5: threshold, close hysteresis, far hysteresis (vendor :890) */
+#define ISG5320A_REG_B_PROXCTL3		0x9B
+#define ISG5320A_REG_DIGITAL_ACC	0xA4
+#define ISG5320A_REG_PROTECT		0xCD
+#define   ISG5320A_PROTECT_UNLOCK	0xDE
+#define ISG5320A_REG_SOFTRESET		0xFD
+#define   ISG5320A_SOFTRESET_VAL	0xDE
+#define ISG5320A_REG_CHIPID		0xFE
+#define ISG5320A_MAX_REG		0xFE
+
+#define ISG5320A_VENDOR_CHIP_ID		0x32	/* vendor :39, never checked */
+#define ISG5320A_RESET_CONDITION	5000	/* reg.h :99, for cfcal_th */
+
+#define ISG5320A_AUTOSUSPEND_MS		5000
+
+struct isg5320a_reg_data {
+	u8 addr;
+	u8 val;
+};
+
+/*
+ * Vendor setup_reg[] for "XCOVER5 ALL" (isg5320a_reg.h :283-435). The other
+ * table (:130-282) is under CONFIG_SENSORS_ISG5320A_XCOVER5_KOR, which the
+ * stock exynos850-xcover5xx_defconfig leaves unset; it differs only in
+ * 0x9C (threshold low byte), 0xA0 (far hysteresis low byte) and 0xBA.
+ */
+static const struct isg5320a_reg_data 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 }, { 0x41, 0x11 }, { 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 }, { 0xC5, 0x00 }, { 0x13, 0x3A },
+	{ 0x18, 0xF1 }, /* A ch : CS0, B ch : 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 },
+};
+
+struct isg5320a_data {
+	struct device *dev;
+	struct regmap *regmap;
+	int irq;
+	/* Serialises multi-register chip sequences and the cached sample. */
+	struct mutex lock;
+	/* Serialises event enable/disable (sleeps in disable_irq()). */
+	struct mutex ev_lock;
+	bool ev_enabled;
+	bool irq_wake_enabled;
+	bool close;
+	u16 cdc;
+	u16 base;
+	u16 thresh;
+	u16 close_hyst;
+	u16 far_hyst;
+	u32 cfcal_th;
+};
+
+static bool isg5320a_writeable_reg(struct device *dev, unsigned int reg)
+{
+	unsigned int i;
+
+	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 (i = 0; i < ARRAY_SIZE(isg5320a_setup_reg); i++)
+		if (isg5320a_setup_reg[i].addr == 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;
+}
+
+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,
+};
+
+/* vendor isg5320a_reset(), :247-292, plus a CHIPID read the vendor never does */
+static int isg5320a_reset(struct isg5320a_data *data)
+{
+	struct device *dev = data->dev;
+	unsigned int val;
+	int ret;
+
+	usleep_range(5000, 5100);				/* :255-256 */
+
+	ret = regmap_read(data->regmap, ISG5320A_REG_IRQSRC, &val);	/* :258 */
+	if (ret)
+		return dev_err_probe(dev, ret, "no response at IRQSRC\n");
+
+	ret = regmap_read(data->regmap, ISG5320A_REG_CHIPID, &val);
+	if (ret)
+		return dev_err_probe(dev, ret, "CHIPID read failed\n");
+	if (val == ISG5320A_VENDOR_CHIP_ID)
+		dev_info(dev, "CHIPID 0x%02x\n", val);
+	else
+		dev_warn(dev, "CHIPID 0x%02x (vendor header says 0x%02x; not enforced)\n",
+			 val, ISG5320A_VENDOR_CHIP_ID);
+
+	msleep(50);						/* :262-266 */
+
+	ret = regmap_write(data->regmap, ISG5320A_REG_PROTECT,	/* :268-271 */
+			   ISG5320A_PROTECT_UNLOCK);
+	if (ret)
+		return dev_err_probe(dev, ret, "unlock protect failed\n");
+
+	ret = regmap_write(data->regmap, ISG5320A_REG_SOFTRESET,	/* :273-276 */
+			   ISG5320A_SOFTRESET_VAL);
+	if (ret)
+		return dev_err_probe(dev, ret, "soft reset write failed\n");
+
+	usleep_range(1000, 1100);				/* :278 */
+
+	msleep(50);						/* :280-289 */
+	dev_dbg(dev, "reset done\n");
+
+	return 0;
+}
+
+/* vendor isg5320a_initialize(), :614-660, without the /sdcard override */
+static int isg5320a_initialize(struct isg5320a_data *data)
+{
+	struct device *dev = data->dev;
+	unsigned int i, val, mismatch = 0;
+	u8 buf[6];
+	int ret;
+
+	guard(mutex)(&data->lock);
+
+	ret = regmap_read(data->regmap, ISG5320A_REG_IRQSRC, &val);	/* :625 */
+	if (ret)
+		return ret;
+	ret = regmap_write(data->regmap, ISG5320A_REG_SCANCTRL1,	/* :626 */
+			   ISG5320A_SCAN_STOP);
+	if (ret)
+		return ret;
+	msleep(30);						/* :627 */
+
+	for (i = 0; i < ARRAY_SIZE(isg5320a_setup_reg); i++) {	/* :631-637 */
+		const struct isg5320a_reg_data *r = &isg5320a_setup_reg[i];
+
+		ret = regmap_write(data->regmap, r->addr, r->val);
+		if (ret)
+			return dev_err_probe(dev, ret, "init write 0x%02x failed\n",
+					     r->addr);
+		ret = regmap_read(data->regmap, r->addr, &val);
+		if (ret)
+			return ret;
+		if (val != r->val) {
+			mismatch++;
+			dev_dbg(dev, "reg 0x%02x wrote 0x%02x read 0x%02x\n",
+				r->addr, r->val, val);
+		}
+	}
+	dev_info(dev, "init table: %zu writes, %u read back different\n",
+		 ARRAY_SIZE(isg5320a_setup_reg), mismatch);
+
+	/* :646-650 reads the threshold; :890-897 reads all six bytes */
+	ret = regmap_bulk_read(data->regmap, ISG5320A_REG_B_PROXCTL3, buf,
+			       sizeof(buf));
+	if (ret)
+		return ret;
+	data->thresh = (buf[0] << 8) | buf[1];
+	data->close_hyst = (buf[2] << 8) | buf[3];
+	data->far_hyst = (buf[4] << 8) | buf[5];
+
+	ret = regmap_read(data->regmap, ISG5320A_REG_DIGITAL_ACC, &val);	/* :653-657 */
+	if (ret)
+		return ret;
+	data->cfcal_th = ISG5320A_RESET_CONDITION * val / 8;
+
+	dev_info(dev, "threshold %u, close hyst %u, far hyst %u, cfcal_th %u\n",
+		 data->thresh, data->close_hyst, data->far_hyst, data->cfcal_th);
+
+	return 0;
+}
+
+/* vendor isg5320a_set_mode(SLEEP), :749-755 */
+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;
+	ret = regmap_write(data->regmap, ISG5320A_REG_SCANCTRL1, ISG5320A_SCAN_STOP);
+	if (ret)
+		return ret;
+	ret = regmap_write(data->regmap, ISG5320A_REG_OSCCON, ISG5320A_OSC_SLEEP);
+	if (ret)
+		return ret;
+	return regmap_write(data->regmap, ISG5320A_REG_BS_ON_WD, ISG5320A_BS_WD_OFF);
+}
+
+/*
+ * vendor isg5320a_set_mode(NORMAL), :749 + :757-758, which runs
+ * isg5320a_force_calibration(data, false), :302-321.
+ */
+static int isg5320a_mode_normal(struct isg5320a_data *data)
+{
+	struct regmap *map = data->regmap;
+	unsigned int val;
+	int ret;
+
+	guard(mutex)(&data->lock);
+
+	ret = regmap_read(map, ISG5320A_REG_IRQSRC, &val);			/* :749 */
+	if (ret)
+		return ret;
+	ret = regmap_write(map, ISG5320A_REG_BS_ON_WD, ISG5320A_BS_WD_ON);	/* :757 */
+	if (ret)
+		return ret;
+
+	ret = regmap_write(map, ISG5320A_REG_SCANCTRL1, ISG5320A_SCAN_STOP);	/* :303 */
+	if (ret)
+		return ret;
+	msleep(30);								/* :305 */
+	ret = regmap_write(map, ISG5320A_REG_BS_ON_WD, ISG5320A_BS_WD_OFF);	/* :306 */
+	if (ret)
+		return ret;
+	ret = regmap_write(map, ISG5320A_REG_SCANCTRL2, ISG5320A_SCAN2_CLEAR);	/* :307 */
+	if (ret)
+		return ret;
+	msleep(100);								/* :309 */
+	ret = regmap_write(map, ISG5320A_REG_OSCCON, ISG5320A_OSC_NORMAL);	/* :310 */
+	if (ret)
+		return ret;
+	ret = regmap_write(map, ISG5320A_REG_BS_ON_WD, ISG5320A_BS_WD_ON);	/* :312 */
+	if (ret)
+		return ret;
+	ret = regmap_write(map, ISG5320A_REG_SCANCTRL2, ISG5320A_SCAN2_RESET);	/* :313 */
+	if (ret)
+		return ret;
+	ret = regmap_write(map, ISG5320A_REG_SCANCTRL1, ISG5320A_CFCAL_START);	/* :316 */
+	if (ret)
+		return ret;
+	msleep(500);								/* :318 */
+	ret = regmap_write(map, ISG5320A_REG_SCANCTRL2, ISG5320A_BFCAL_START);	/* :321 */
+	if (ret)
+		return ret;
+
+	/* The vendor sw_reset path waits 300 ms after BFCAL before reading (:850-852). */
+	msleep(300);
+
+	return 0;
+}
+
+/* vendor isg5320a_get_raw_data(), :445-466; caller holds data->lock */
+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 discarded and the last value kept (:459-464) */
+	v = (buf[0] << 8) | buf[1];
+	if (v != 0 && v != 0xFFFF)
+		data->cdc = v;
+	v = (buf[2] << 8) | buf[3];
+	if (v != 0 && v != 0xFFFF)
+		data->base = v;
+
+	return 0;
+}
+
+static int isg5320a_get_sample(struct isg5320a_data *data, u16 *cdc, u16 *base)
+{
+	struct device *dev = data->dev;
+	int ret;
+
+	ACQUIRE(pm_runtime_active_auto_try_enabled, pm)(dev);
+	ret = ACQUIRE_ERR(pm_runtime_active_auto_try_enabled, &pm);
+	if (ret < 0)
+		return ret;
+
+	scoped_guard(mutex, &data->lock) {
+		ret = isg5320a_read_sample(data);
+		*cdc = data->cdc;
+		*base = data->base;
+	}
+	if (ret)
+		return ret;
+
+	/*
+	 * The vendor cal_work (:1640-1647) force-recalibrates when cdc drops
+	 * below cfcal_th. That loop is not ported; only report the condition.
+	 */
+	if (*cdc < data->cfcal_th)
+		dev_warn_ratelimited(dev, "cdc %u below cfcal_th %u (vendor would recalibrate)\n",
+				     *cdc, data->cfcal_th);
+
+	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);
+	unsigned int src, sts;
+	bool changed = false;
+	bool close = false;
+	int ret;
+
+	scoped_guard(mutex, &data->lock) {
+		isg5320a_read_sample(data);				/* :581 */
+
+		ret = regmap_read(data->regmap, ISG5320A_REG_IRQSRC, &src);	/* :583 */
+		if (ret)
+			break;
+		ret = regmap_read(data->regmap, ISG5320A_REG_IRQSTS, &sts);	/* :598 */
+		if (ret)
+			break;
+
+		close = sts & ISG5320A_IRQSTS_PROX;			/* :518 */
+		changed = close != data->close;
+		data->close = close;
+	}
+
+	if (ret) {
+		dev_err_ratelimited(data->dev, "irq status read failed: %d\n", ret);
+		return IRQ_HANDLED;
+	}
+
+	dev_dbg(data->dev, "irq src 0x%02x sts 0x%02x cdc %u base %u\n",
+		src, sts, data->cdc, data->base);
+
+	if (changed && READ_ONCE(data->ev_enabled)) {
+		enum iio_event_direction dir;
+
+		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);
+	u16 cdc, base;
+	int ret;
+
+	switch (mask) {
+	case IIO_CHAN_INFO_RAW:
+		ret = isg5320a_get_sample(data, &cdc, &base);
+		if (ret)
+			return ret;
+		*val = (int)cdc - (int)base;				/* :465 */
+		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;
+
+	return READ_ONCE(data->ev_enabled);
+}
+
+/* vendor isg5320a_set_enable(), :681-742 (minus the work items) */
+static int isg5320a_events_on(struct isg5320a_data *data)
+{
+	struct device *dev = data->dev;
+	unsigned int val;
+	int ret;
+
+	ret = pm_runtime_resume_and_get(dev);
+	if (ret)
+		return ret;
+
+	scoped_guard(mutex, &data->lock) {
+		ret = regmap_read(data->regmap, ISG5320A_REG_IRQSTS, &val);	/* :700 */
+		if (ret)
+			break;
+		data->close = val & ISG5320A_IRQSTS_PROX;		/* :708-713 */
+		isg5320a_read_sample(data);				/* :704 */
+		ret = regmap_read(data->regmap, ISG5320A_REG_IRQSRC, &val);	/* :718 */
+		if (ret)
+			break;
+		ret = regmap_write(data->regmap, ISG5320A_REG_IRQFUNC,	/* :719 */
+				   ISG5320A_IRQFUNC_ENABLE);
+	}
+	if (ret) {
+		pm_runtime_put_autosuspend(dev);
+		return ret;
+	}
+
+	WRITE_ONCE(data->ev_enabled, true);
+	enable_irq(data->irq);						/* :721 */
+	/*
+	 * Cache the decision: device_may_wakeup(dev) may change before
+	 * events_off(), and we must only clear a wake enable we actually
+	 * set, so only mark it enabled if enable_irq_wake() succeeded.
+	 */
+	if (device_may_wakeup(dev))
+		data->irq_wake_enabled = !enable_irq_wake(data->irq);	/* :722 */
+
+	dev_dbg(dev, "events on, initial state %s\n", data->close ? "close" : "far");
+
+	return 0;
+}
+
+static void isg5320a_events_off(struct isg5320a_data *data)
+{
+	struct device *dev = data->dev;
+	int ret = 0;
+
+	scoped_guard(mutex, &data->lock)
+		ret = regmap_write(data->regmap, ISG5320A_REG_IRQFUNC,	/* :726 */
+				   ISG5320A_IRQFUNC_DISABLE);
+	if (ret)
+		dev_warn(dev, "IRQFUNC disable failed: %d\n", ret);
+
+	WRITE_ONCE(data->ev_enabled, false);
+	disable_irq(data->irq);						/* :728 */
+	if (data->irq_wake_enabled) {
+		disable_irq_wake(data->irq);				/* :729 */
+		data->irq_wake_enabled = false;
+	}
+}
+
+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);
+
+	isg5320a_events_off(data);
+	pm_runtime_put_autosuspend(data->dev);
+
+	return 0;
+}
+
+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;
+
+	/* vendor normal_threshold_show, :896-897 */
+	switch (dir) {
+	case IIO_EV_DIR_RISING:
+		*val = data->thresh + data->close_hyst;
+		return IIO_VAL_INT;
+	case IIO_EV_DIR_FALLING:
+		*val = (int)data->thresh - (int)data->far_hyst;
+		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),
+	},
+};
+
+#define ISG5320A_CHANNEL(_events, _nevents)			\
+	{							\
+		.type = IIO_PROXIMITY,				\
+		.indexed = 1,					\
+		.channel = 0,					\
+		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),	\
+		.event_spec = _events,				\
+		.num_event_specs = _nevents,			\
+	}
+
+static const struct iio_chan_spec isg5320a_channels[] = {
+	ISG5320A_CHANNEL(isg5320a_events, ARRAY_SIZE(isg5320a_events)),
+};
+
+static const struct iio_chan_spec isg5320a_channels_noirq[] = {
+	ISG5320A_CHANNEL(NULL, 0),
+};
+
+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 const struct iio_info isg5320a_info_noirq = {
+	.read_raw = isg5320a_read_raw,
+};
+
+/* vendor isg5320a_remove(), :2030-2033 */
+static void isg5320a_teardown(void *arg)
+{
+	struct isg5320a_data *data = arg;
+	struct device *dev = data->dev;
+
+	pm_runtime_disable(dev);
+
+	if (data->ev_enabled) {
+		isg5320a_events_off(data);
+		pm_runtime_put_noidle(dev);
+	}
+
+	if (!pm_runtime_status_suspended(dev))
+		isg5320a_mode_sleep(data);
+
+	pm_runtime_set_suspended(dev);
+	pm_runtime_dont_use_autosuspend(dev);
+}
+
+static int isg5320a_probe(struct i2c_client *client)
+{
+	struct device *dev = &client->dev;
+	struct isg5320a_data *data;
+	struct iio_dev *indio_dev;
+	unsigned long irqflags;
+	int ret;
+
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
+	if (!indio_dev)
+		return -ENOMEM;
+
+	data = iio_priv(indio_dev);
+	data->dev = dev;
+	data->irq = client->irq;
+	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;
+
+	/* The vendor node has no supply; the board relies on an always-on LDO. */
+	ret = devm_regulator_get_enable_optional(dev, "vdd");
+	if (ret && ret != -ENODEV)
+		return dev_err_probe(dev, ret, "failed to enable vdd\n");
+	/*
+	 * If the rail was just switched on, give the chip time to come out
+	 * of power-on reset. The vendor never switches it, so this value
+	 * (10 ms) is a guess, not from the vendor source.
+	 */
+	if (!ret)
+		usleep_range(10000, 11000);
+
+	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);				/* :1915 */
+	if (ret)
+		return ret;
+
+	msleep(300);			/* vendor runs init_work 300 ms later, :1981 */
+
+	ret = isg5320a_initialize(data);			/* :1620 */
+	if (ret)
+		return dev_err_probe(dev, ret, "init failed\n");
+
+	ret = isg5320a_mode_normal(data);			/* :1621 */
+	if (ret)
+		return dev_err_probe(dev, ret, "start failed\n");
+
+	/*
+	 * The chip is already active, so a later failure (e.g. the IRQ
+	 * request below) must still put it back to sleep instead of leaving
+	 * it scanning with nothing bound to it.
+	 */
+	pm_runtime_set_autosuspend_delay(dev, ISG5320A_AUTOSUSPEND_MS);
+	pm_runtime_use_autosuspend(dev);
+	pm_runtime_set_active(dev);
+	pm_runtime_get_noresume(dev);
+	pm_runtime_enable(dev);
+	pm_runtime_put_autosuspend(dev);
+
+	if (data->irq > 0) {
+		irqflags = irq_get_trigger_type(data->irq);
+		if (!irqflags)
+			irqflags = IRQF_TRIGGER_FALLING;	/* :1932 */
+
+		ret = devm_request_threaded_irq(dev, data->irq, NULL,
+						isg5320a_irq_thread,
+						irqflags | IRQF_ONESHOT |
+						IRQF_NO_AUTOEN,
+						"isg5320a", indio_dev);
+		if (ret)
+			return dev_err_probe(dev, ret, "irq request failed\n");
+
+		if (device_property_read_bool(dev, "wakeup-source"))
+			device_init_wakeup(dev, true);
+	}
+
+	/*
+	 * Registered after the IRQ request, so devm's LIFO unwind runs this
+	 * teardown (which may disable_irq()/disable_irq_wake() the IRQ in
+	 * isg5320a_events_off()) before the IRQ itself is freed, not after.
+	 */
+	ret = devm_add_action_or_reset(dev, isg5320a_teardown, data);
+	if (ret)
+		return ret;
+
+	indio_dev->name = "isg5320a";
+	indio_dev->modes = INDIO_DIRECT_MODE;
+	if (data->irq > 0) {
+		indio_dev->info = &isg5320a_info;
+		indio_dev->channels = isg5320a_channels;
+		indio_dev->num_channels = ARRAY_SIZE(isg5320a_channels);
+	} else {
+		indio_dev->info = &isg5320a_info_noirq;
+		indio_dev->channels = isg5320a_channels_noirq;
+		indio_dev->num_channels = ARRAY_SIZE(isg5320a_channels_noirq);
+	}
+
+	return devm_iio_device_register(dev, indio_dev);
+}
+
+/* vendor isg5320a_shutdown(), :2071-2080, synchronized like isg5320a_teardown() */
+static void isg5320a_shutdown(struct i2c_client *client)
+{
+	struct isg5320a_data *data = iio_priv(i2c_get_clientdata(client));
+	struct device *dev = data->dev;
+
+	guard(mutex)(&data->ev_lock);
+
+	if (data->ev_enabled) {
+		isg5320a_events_off(data);
+		pm_runtime_put_noidle(dev);
+	}
+
+	if (!pm_runtime_status_suspended(dev))
+		isg5320a_mode_sleep(data);
+}
+
+static int isg5320a_runtime_suspend(struct device *dev)
+{
+	struct isg5320a_data *data = iio_priv(dev_get_drvdata(dev));
+
+	return isg5320a_mode_sleep(data);
+}
+
+static int isg5320a_runtime_resume(struct device *dev)
+{
+	struct isg5320a_data *data = iio_priv(dev_get_drvdata(dev));
+
+	return isg5320a_mode_normal(data);
+}
+
+/*
+ * Runtime PM only. System sleep leaves the chip as it is, as the vendor
+ * does (its suspend/resume only stop and restart the work items), so an
+ * enabled grip event can still wake the system.
+ */
+static const struct dev_pm_ops isg5320a_pm_ops = {
+	RUNTIME_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,
+	.shutdown = isg5320a_shutdown,
+	.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] 18+ messages in thread

* Re: [PATCH v3 2/2] iio: proximity: add Imagis ISG5320A SAR sensor driver
  2026-11-17 17:33   ` [PATCH v3 2/2] iio: proximity: add Imagis ISG5320A SAR sensor driver Adil Hüsrev Tepe
@ 2026-11-17 17:55     ` sashiko-bot
  2026-11-18  9:53     ` Joshua Crofts
  1 sibling, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-11-17 17:55 UTC (permalink / raw)
  To: Adil Hüsrev Tepe; +Cc: devicetree, robh, conor+dt

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] iio: proximity: isg5320a: missing teardown on IRQ error in
  isg5320a_probe()
- [Low] iio: proximity: isg5320a: disable runtime PM in
  isg5320a_shutdown()
--

commit baa300415c1a96074ec67b396caa0dfe08ba9dae
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 I2C capacitive
SAR/grip sensor, exposing a proximity channel and threshold events.

> diff --git a/drivers/iio/proximity/isg5320a.c b/drivers/iio/proximity/isg5320a.c
> new file mode 100644
> index 0000000000000..4df0e09d39143
> --- /dev/null
> +++ b/drivers/iio/proximity/isg5320a.c
[ ... ]
> +static int isg5320a_probe(struct i2c_client *client)
> +{
[ ... ]
> +	ret = isg5320a_mode_normal(data);			/* :1621 */
> +	if (ret)
> +		return dev_err_probe(dev, ret, "start failed\n");
> +
> +	/*
> +	 * The chip is already active, so a later failure (e.g. the IRQ
> +	 * request below) must still put it back to sleep instead of leaving
> +	 * it scanning with nothing bound to it.
> +	 */
> +	pm_runtime_set_autosuspend_delay(dev, ISG5320A_AUTOSUSPEND_MS);
> +	pm_runtime_use_autosuspend(dev);
> +	pm_runtime_set_active(dev);
> +	pm_runtime_get_noresume(dev);
> +	pm_runtime_enable(dev);
> +	pm_runtime_put_autosuspend(dev);
> +
> +	if (data->irq > 0) {
> +		irqflags = irq_get_trigger_type(data->irq);
> +		if (!irqflags)
> +			irqflags = IRQF_TRIGGER_FALLING;	/* :1932 */
> +
> +		ret = devm_request_threaded_irq(dev, data->irq, NULL,
> +						isg5320a_irq_thread,
> +						irqflags | IRQF_ONESHOT |
> +						IRQF_NO_AUTOEN,
> +						"isg5320a", indio_dev);
> +		if (ret)
> +			return dev_err_probe(dev, ret, "irq request failed\n");
> +
> +		if (device_property_read_bool(dev, "wakeup-source"))
> +			device_init_wakeup(dev, true);
> +	}
> +
> +	/*
> +	 * Registered after the IRQ request, so devm's LIFO unwind runs this
> +	 * teardown (which may disable_irq()/disable_irq_wake() the IRQ in
> +	 * isg5320a_events_off()) before the IRQ itself is freed, not after.
> +	 */
> +	ret = devm_add_action_or_reset(dev, isg5320a_teardown, data);
> +	if (ret)
> +		return ret;

[Severity: Medium]
Does a failure in devm_request_threaded_irq() skip isg5320a_teardown()?

isg5320a_mode_normal() has already started the sensor and runtime PM is
enabled with an armed autosuspend timer, but isg5320a_teardown() is only
registered after devm_request_threaded_irq() succeeds.  If the IRQ request
fails (for example with -EPROBE_DEFER), the chip is left scanning, runtime
PM stays enabled on the unbound device, and the pending autosuspend timer
can fire isg5320a_runtime_suspend() while devres is freeing data->regmap
and indio_dev.

Requesting the IRQ (which uses IRQF_NO_AUTOEN) before calling
isg5320a_mode_normal() and enabling runtime PM would let
isg5320a_teardown() be registered immediately after pm_runtime_enable()
while still unwinding before the IRQ is freed.

[ ... ]
> +/* vendor isg5320a_shutdown(), :2071-2080, synchronized like isg5320a_teardown() */
> +static void isg5320a_shutdown(struct i2c_client *client)
> +{
> +	struct isg5320a_data *data = iio_priv(i2c_get_clientdata(client));
> +	struct device *dev = data->dev;
> +
> +	guard(mutex)(&data->ev_lock);
> +
> +	if (data->ev_enabled) {
> +		isg5320a_events_off(data);
> +		pm_runtime_put_noidle(dev);
> +	}
> +
> +	if (!pm_runtime_status_suspended(dev))
> +		isg5320a_mode_sleep(data);
> +}

[Severity: Low]
Can a concurrent sysfs access resume the sensor or re-enable events during
or after isg5320a_shutdown()?

Unlike isg5320a_teardown(), isg5320a_shutdown() runs while indio_dev is
still registered and does not call pm_runtime_disable(dev).  A concurrent
isg5320a_read_raw() -> isg5320a_get_sample() does not take data->ev_lock
and can runtime-resume the chip back into normal mode, or a later
isg5320a_write_event_config() call can re-enable the interrupt and wakeup
source after shutdown finishes:

CPU0                                  CPU1
isg5320a_shutdown()
  guard(mutex)(&data->ev_lock)
  !pm_runtime_status_suspended(dev)
  isg5320a_mode_sleep(data)
                                      isg5320a_read_raw()
                                        isg5320a_get_sample()
                                          pm_runtime_resume_and_get(dev)
                                            isg5320a_runtime_resume()
                                              isg5320a_mode_normal(data)
                                                <-- chip left scanning

Calling pm_runtime_disable(dev) before checking
pm_runtime_status_suspended(dev) and pm_runtime_set_suspended(dev) after
isg5320a_mode_sleep(data), as in isg5320a_teardown(), would prevent
later runtime resumes and event enables.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117173333.1853986-1-tadilhusrev@gmail.com?part=2

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 0/2] iio: proximity: add Imagis ISG5320A (Samsung Galaxy XCover5)
  2026-11-17 17:33 ` [PATCH v3 0/2] iio: proximity: add Imagis ISG5320A (Samsung Galaxy XCover5) Adil Hüsrev Tepe
  2026-11-17 17:33   ` [PATCH v3 1/2] dt-bindings: iio: proximity: add Imagis ISG5320A Adil Hüsrev Tepe
  2026-11-17 17:33   ` [PATCH v3 2/2] iio: proximity: add Imagis ISG5320A SAR sensor driver Adil Hüsrev Tepe
@ 2026-11-18  9:00   ` Joshua Crofts
  2 siblings, 0 replies; 18+ messages in thread
From: Joshua Crofts @ 2026-11-18  9:00 UTC (permalink / raw)
  To: Adil Hüsrev Tepe
  Cc: jic23, robh, krzk+dt, conor+dt, dlechner, nuno.sa, andy,
	linux-iio, devicetree, linux-kernel

On Tue, 17 Nov 2026 20:33:31 +0300
Adil Hüsrev Tepe <tadilhusrev@gmail.com> wrote:

> 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).
> 
>   Patch 1  dt-bindings
>   Patch 2  the IIO driver
> 
> v3 fixes the real review findings on v2: Sashiko AI caught a High-
> severity INT-polarity bug in the reset sequence (eliminated by
> dropping int-gpios from the driver and binding entirely, since the
> pin is already described by the required "interrupts" property) plus
> a Medium-severity devm unwind-order bug and a Low-severity unchecked
> enable_irq_wake(). Both are now live-tested, not just built. Per-patch
> details are below each patch's "---" line, as Andy Shevchenko asked.
> 
> Tested on a Samsung Galaxy XCover5 running 7.4-rc1 plus this series
> (2026-11-17, kernel 7.4.0-rc1-00023-gdcb8b91fb779+ #30): the driver
> binds, registers as iio:device4 "isg5320a", and in_proximity0_raw
> tracked a live hand-proximity test (baseline ~0, swinging to
> -12817/9748/10759 as a hand approached/withdrew the sensor).
> checkpatch.pl --strict and dt_binding_check are clean.
> 
> 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 and
> drafted these changelogs. I reviewed every line, built it (arm64, 0
> warnings), ran checkpatch --strict (clean), and tested it on hardware
> as described above, 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   |  55 ++
>  drivers/iio/proximity/Kconfig                     |  11 +
>  drivers/iio/proximity/Makefile                    |   1 +
>  drivers/iio/proximity/isg5320a.c                  | 848 +++++++++++++++++++
>  4 files changed, 915 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/iio/proximity/imagis,isg5320a.yaml
>  create mode 100644 drivers/iio/proximity/isg5320a.c
> 
> --
> 2.53.0
> 

Not only you sent this as a reply to v1 (which obscured this new version
in my inbox), you also sent a v3 the same day you sent a v2. This is a (relatively)
big addition, please don't do this. For trivial patches it should be at least 24 hours
between revisions, for new drivers ~1 week.

I know it's tempting to send a new version after a Sashiko review/trivial issue you
found, but you'll save the reviewers' and maintainer's sanity by waiting :)

Thanks!

-- 
Kind regards,
Joshua Crofts

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 2/2] iio: proximity: add Imagis ISG5320A SAR sensor driver
  2026-11-17 17:33   ` [PATCH v3 2/2] iio: proximity: add Imagis ISG5320A SAR sensor driver Adil Hüsrev Tepe
  2026-11-17 17:55     ` sashiko-bot
@ 2026-11-18  9:53     ` Joshua Crofts
  1 sibling, 0 replies; 18+ messages in thread
From: Joshua Crofts @ 2026-11-18  9:53 UTC (permalink / raw)
  To: Adil Hüsrev Tepe
  Cc: jic23, robh, krzk+dt, conor+dt, dlechner, nuno.sa, andy,
	linux-iio, devicetree, linux-kernel

On Tue, 17 Nov 2026 20:33:33 +0300
Adil Hüsrev Tepe <tadilhusrev@gmail.com> wrote:

> 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.
> 
> Tested on a Samsung Galaxy XCover5 (re-confirmed 2026-11-17, kernel
> 7.4.0-rc1-00023-gdcb8b91fb779+ #30): the driver binds, registers as
> iio:device4 "isg5320a", and in_proximity0_raw tracked a live
> hand-proximity test (baseline ~0, swinging to -12817/9748/10759 as a
> hand approached/withdrew the sensor).
> 
> Signed-off-by: Adil Hüsrev Tepe <tadilhusrev@gmail.com>
> ---

Hi Adil, some comments inline.

...

> diff --git a/drivers/iio/proximity/isg5320a.c b/drivers/iio/proximity/isg5320a.c
> new file mode 100644
> index 000000000..4df0e09d3
> --- /dev/null
> +++ b/drivers/iio/proximity/isg5320a.c
> @@ -0,0 +1,848 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Imagis ISG5320A capacitive SAR/grip sensor.
> + *
> + * Register map, init table and every write sequence below come from the
> + * Samsung vendor driver (drivers/sensors/isg5320a.c + isg5320a_reg.h,
> + * Galaxy XCover5 5.10 tree, Copyright (C) Imagis Technology). Citations of
> + * the form "vendor :NNN" refer to lines in that isg5320a.c. This driver
> + * writes no register the vendor driver does not write, and only with the
> + * values the vendor writes; regmap enforces that through writeable_reg.
> + *
> + * The chip is used as one proximity channel: the vendor's "diff" value
> + * (CDC16_T - BSL16_B, i.e. 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/device.h>
> +#include <linux/errno.h>

+ err.h

> +#include <linux/i2c.h>
> +#include <linux/interrupt.h>
> +#include <linux/irq.h>
> +#include <linux/mod_devicetable.h>

Remove this, i2c.h includes the correct device tables.

> +#include <linux/module.h>
> +#include <linux/mutex.h>
> +#include <linux/pm.h>
> +#include <linux/pm_runtime.h>
> +#include <linux/pm_wakeup.h>
> +#include <linux/property.h>
> +#include <linux/regmap.h>
> +#include <linux/regulator/consumer.h>
> +#include <linux/types.h>
> +

Otherwise good to see that IWYU is slowly catching on in new
submissions :)

> +#include <linux/iio/events.h>
> +#include <linux/iio/iio.h>
> +

...

> +
> +struct isg5320a_data {
> +	struct device *dev;
> +	struct regmap *regmap;
> +	int irq;
> +	/* Serialises multi-register chip sequences and the cached sample. */
> +	struct mutex lock;
> +	/* Serialises event enable/disable (sleeps in disable_irq()). */
> +	struct mutex ev_lock;
> +	bool ev_enabled;
> +	bool irq_wake_enabled;
> +	bool close;
> +	u16 cdc;
> +	u16 base;
> +	u16 thresh;
> +	u16 close_hyst;
> +	u16 far_hyst;
> +	u32 cfcal_th;
> +};

I ran pahole and found this layout to be optimal without any holes:

        struct device *            dev;                  /*     0     8 */
        struct regmap *            regmap;               /*     8     8 */
        struct mutex               lock __attribute__((__aligned__(8))); /*    16    24 */
        struct mutex               ev_lock __attribute__((__aligned__(8))); /*    40    24 */
        /* --- cacheline 1 boundary (64 bytes) --- */
        int                        irq;                  /*    64     4 */
        u32                        cfcal_th;             /*    68     4 */
        u16                        cdc;                  /*    72     2 */
        u16                        base;                 /*    74     2 */
        u16                        thresh;               /*    76     2 */
        u16                        close_hyst;           /*    78     2 */
        u16                        far_hyst;             /*    80     2 */
        bool                       ev_enabled;           /*    82     1 */
        bool                       irq_wake_enabled;     /*    83     1 */
        bool                       close;                /*    84     1 */

> +
> +static bool isg5320a_writeable_reg(struct device *dev, unsigned int reg)
> +{
> +	unsigned int i;
> +
> +	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 (i = 0; i < ARRAY_SIZE(isg5320a_setup_reg); i++)

for (unsigned int i = 0; ...

> +		if (isg5320a_setup_reg[i].addr == 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;
> +}
> +
> +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,
> +};
> +
> +/* vendor isg5320a_reset(), :247-292, plus a CHIPID read the vendor never does */
> +static int isg5320a_reset(struct isg5320a_data *data)
> +{
> +	struct device *dev = data->dev;
> +	unsigned int val;
> +	int ret;
> +
> +	usleep_range(5000, 5100);				/* :255-256 */

fsleep() would be better. Same goes for other usleep_range() calls.

> +
> +	ret = regmap_read(data->regmap, ISG5320A_REG_IRQSRC, &val);	/* :258 */
> +	if (ret)
> +		return dev_err_probe(dev, ret, "no response at IRQSRC\n");

Do we need these dev_err_probe() calls at each regmap operation? return ret is good
enough.

> +
> +	ret = regmap_read(data->regmap, ISG5320A_REG_CHIPID, &val);
> +	if (ret)
> +		return dev_err_probe(dev, ret, "CHIPID read failed\n");
> +	if (val == ISG5320A_VENDOR_CHIP_ID)
> +		dev_info(dev, "CHIPID 0x%02x\n", val);
> +	else
> +		dev_warn(dev, "CHIPID 0x%02x (vendor header says 0x%02x; not enforced)\n",
> +			 val, ISG5320A_VENDOR_CHIP_ID);
> +
> +	msleep(50);						/* :262-266 */
> +
> +	ret = regmap_write(data->regmap, ISG5320A_REG_PROTECT,	/* :268-271 */
> +			   ISG5320A_PROTECT_UNLOCK);
> +	if (ret)
> +		return dev_err_probe(dev, ret, "unlock protect failed\n");
> +
> +	ret = regmap_write(data->regmap, ISG5320A_REG_SOFTRESET,	/* :273-276 */
> +			   ISG5320A_SOFTRESET_VAL);
> +	if (ret)
> +		return dev_err_probe(dev, ret, "soft reset write failed\n");
> +
> +	usleep_range(1000, 1100);				/* :278 */
> +
> +	msleep(50);						/* :280-289 */
> +	dev_dbg(dev, "reset done\n");
> +
> +	return 0;
> +}
> +
> +/* vendor isg5320a_initialize(), :614-660, without the /sdcard override */
> +static int isg5320a_initialize(struct isg5320a_data *data)
> +{
> +	struct device *dev = data->dev;
> +	unsigned int i, val, mismatch = 0;
> +	u8 buf[6];
> +	int ret;
> +
> +	guard(mutex)(&data->lock);
> +
> +	ret = regmap_read(data->regmap, ISG5320A_REG_IRQSRC, &val);	/* :625 */
> +	if (ret)
> +		return ret;

Blank lines between each function call + if statement group, it improves readability.

> +	ret = regmap_write(data->regmap, ISG5320A_REG_SCANCTRL1,	/* :626 */
> +			   ISG5320A_SCAN_STOP);
> +	if (ret)
> +		return ret;
> +	msleep(30);						/* :627 */
> +
> +	for (i = 0; i < ARRAY_SIZE(isg5320a_setup_reg); i++) {	/* :631-637 */

unsigned int i = 0 as well.

> +		const struct isg5320a_reg_data *r = &isg5320a_setup_reg[i];
> +
> +		ret = regmap_write(data->regmap, r->addr, r->val);
> +		if (ret)
> +			return dev_err_probe(dev, ret, "init write 0x%02x failed\n",
> +					     r->addr);
> +		ret = regmap_read(data->regmap, r->addr, &val);
> +		if (ret)
> +			return ret;
> +		if (val != r->val) {
> +			mismatch++;
> +			dev_dbg(dev, "reg 0x%02x wrote 0x%02x read 0x%02x\n",
> +				r->addr, r->val, val);
> +		}
> +	}
> +	dev_info(dev, "init table: %zu writes, %u read back different\n",
> +		 ARRAY_SIZE(isg5320a_setup_reg), mismatch);
> +
> +	/* :646-650 reads the threshold; :890-897 reads all six bytes */
> +	ret = regmap_bulk_read(data->regmap, ISG5320A_REG_B_PROXCTL3, buf,
> +			       sizeof(buf));
> +	if (ret)
> +		return ret;
> +	data->thresh = (buf[0] << 8) | buf[1];
> +	data->close_hyst = (buf[2] << 8) | buf[3];
> +	data->far_hyst = (buf[4] << 8) | buf[5];
> +
> +	ret = regmap_read(data->regmap, ISG5320A_REG_DIGITAL_ACC, &val);	/* :653-657 */
> +	if (ret)
> +		return ret;
> +	data->cfcal_th = ISG5320A_RESET_CONDITION * val / 8;
> +
> +	dev_info(dev, "threshold %u, close hyst %u, far hyst %u, cfcal_th %u\n",
> +		 data->thresh, data->close_hyst, data->far_hyst, data->cfcal_th);
> +
> +	return 0;
> +}
> +

...

> +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;
> +
> +	return READ_ONCE(data->ev_enabled);
> +}
> +
> +/* vendor isg5320a_set_enable(), :681-742 (minus the work items) */
> +static int isg5320a_events_on(struct isg5320a_data *data)
> +{
> +	struct device *dev = data->dev;
> +	unsigned int val;
> +	int ret;
> +
> +	ret = pm_runtime_resume_and_get(dev);

You could use PM_RUNTIME_ACQUIRE_AUTOSUSPEND() to ensure the device is suspended
on scope exit. It works on the same cleanup.h magic as guard().

> +	if (ret)
> +		return ret;
> +
> +	scoped_guard(mutex, &data->lock) {
> +		ret = regmap_read(data->regmap, ISG5320A_REG_IRQSTS, &val);	/* :700 */
> +		if (ret)
> +			break;

With the macro mentioned above you could just return here and don't need the if (ret)
check below.

> +		data->close = val & ISG5320A_IRQSTS_PROX;		/* :708-713 */
> +		isg5320a_read_sample(data);				/* :704 */
> +		ret = regmap_read(data->regmap, ISG5320A_REG_IRQSRC, &val);	/* :718 */
> +		if (ret)
> +			break;
> +		ret = regmap_write(data->regmap, ISG5320A_REG_IRQFUNC,	/* :719 */
> +				   ISG5320A_IRQFUNC_ENABLE);
> +	}
> +	if (ret) {
> +		pm_runtime_put_autosuspend(dev);
> +		return ret;
> +	}
> +
> +	WRITE_ONCE(data->ev_enabled, true);
> +	enable_irq(data->irq);						/* :721 */
> +	/*
> +	 * Cache the decision: device_may_wakeup(dev) may change before
> +	 * events_off(), and we must only clear a wake enable we actually
> +	 * set, so only mark it enabled if enable_irq_wake() succeeded.
> +	 */
> +	if (device_may_wakeup(dev))
> +		data->irq_wake_enabled = !enable_irq_wake(data->irq);	/* :722 */
> +
> +	dev_dbg(dev, "events on, initial state %s\n", data->close ? "close" : "far");
> +
> +	return 0;
> +}
> +

...

> +/* vendor isg5320a_remove(), :2030-2033 */
> +static void isg5320a_teardown(void *arg)
> +{
> +	struct isg5320a_data *data = arg;
> +	struct device *dev = data->dev;
> +
> +	pm_runtime_disable(dev);
> +
> +	if (data->ev_enabled) {
> +		isg5320a_events_off(data);
> +		pm_runtime_put_noidle(dev);
> +	}
> +
> +	if (!pm_runtime_status_suspended(dev))
> +		isg5320a_mode_sleep(data);
> +
> +	pm_runtime_set_suspended(dev);

> +	pm_runtime_dont_use_autosuspend(dev);

No need for this, I've changed the PM runtime core to call this automatically
on driver exit :)

> +}
> +
> +static int isg5320a_probe(struct i2c_client *client)
> +{
> +	struct device *dev = &client->dev;
> +	struct isg5320a_data *data;
> +	struct iio_dev *indio_dev;
> +	unsigned long irqflags;
> +	int ret;
> +
> +	indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
> +	if (!indio_dev)
> +		return -ENOMEM;
> +
> +	data = iio_priv(indio_dev);
> +	data->dev = dev;
> +	data->irq = client->irq;
> +	i2c_set_clientdata(client, indio_dev);
> +
> +	ret = devm_mutex_init(dev, &data->lock);
> +	if (ret)
> +		return ret;

+ blank line

> +	ret = devm_mutex_init(dev, &data->ev_lock);
> +	if (ret)
> +		return ret;
> +
> +	/* The vendor node has no supply; the board relies on an always-on LDO. */
> +	ret = devm_regulator_get_enable_optional(dev, "vdd");
> +	if (ret && ret != -ENODEV)
> +		return dev_err_probe(dev, ret, "failed to enable vdd\n");
> +	/*
> +	 * If the rail was just switched on, give the chip time to come out
> +	 * of power-on reset. The vendor never switches it, so this value
> +	 * (10 ms) is a guess, not from the vendor source.
> +	 */
> +	if (!ret)
> +		usleep_range(10000, 11000);

fsleep()

> +
> +	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);				/* :1915 */
> +	if (ret)
> +		return ret;
> +
> +	msleep(300);			/* vendor runs init_work 300 ms later, :1981 */
> +
> +	ret = isg5320a_initialize(data);			/* :1620 */
> +	if (ret)
> +		return dev_err_probe(dev, ret, "init failed\n");
> +
> +	ret = isg5320a_mode_normal(data);			/* :1621 */
> +	if (ret)
> +		return dev_err_probe(dev, ret, "start failed\n");
> +
> +	/*
> +	 * The chip is already active, so a later failure (e.g. the IRQ
> +	 * request below) must still put it back to sleep instead of leaving
> +	 * it scanning with nothing bound to it.
> +	 */
> +	pm_runtime_set_autosuspend_delay(dev, ISG5320A_AUTOSUSPEND_MS);
> +	pm_runtime_use_autosuspend(dev);
> +	pm_runtime_set_active(dev);
> +	pm_runtime_get_noresume(dev);
> +	pm_runtime_enable(dev);
> +	pm_runtime_put_autosuspend(dev);
> +
> +	if (data->irq > 0) {
> +		irqflags = irq_get_trigger_type(data->irq);
> +		if (!irqflags)
> +			irqflags = IRQF_TRIGGER_FALLING;	/* :1932 */
> +
> +		ret = devm_request_threaded_irq(dev, data->irq, NULL,
> +						isg5320a_irq_thread,
> +						irqflags | IRQF_ONESHOT |
> +						IRQF_NO_AUTOEN,
> +						"isg5320a", indio_dev);
> +		if (ret)
> +			return dev_err_probe(dev, ret, "irq request failed\n");

Duplicate error call, devm_request_threaded_irq() already does this on failure.

> +
> +		if (device_property_read_bool(dev, "wakeup-source"))
> +			device_init_wakeup(dev, true);
> +	}
> +
> +	/*
> +	 * Registered after the IRQ request, so devm's LIFO unwind runs this
> +	 * teardown (which may disable_irq()/disable_irq_wake() the IRQ in
> +	 * isg5320a_events_off()) before the IRQ itself is freed, not after.
> +	 */
> +	ret = devm_add_action_or_reset(dev, isg5320a_teardown, data);
> +	if (ret)
> +		return ret;
> +
> +	indio_dev->name = "isg5320a";
> +	indio_dev->modes = INDIO_DIRECT_MODE;
> +	if (data->irq > 0) {
> +		indio_dev->info = &isg5320a_info;
> +		indio_dev->channels = isg5320a_channels;
> +		indio_dev->num_channels = ARRAY_SIZE(isg5320a_channels);
> +	} else {
> +		indio_dev->info = &isg5320a_info_noirq;
> +		indio_dev->channels = isg5320a_channels_noirq;
> +		indio_dev->num_channels = ARRAY_SIZE(isg5320a_channels_noirq);
> +	}
> +
> +	return devm_iio_device_register(dev, indio_dev);
> +}

-- 
Kind regards,
Joshua Crofts

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2026-11-18  9:54 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16  7:40 [PATCH v1 0/2] iio: proximity: add Imagis ISG5320A (Samsung Galaxy XCover5) Adil Hüsrev Tepe
2026-11-16  7:40 ` [PATCH v1 1/2] dt-bindings: iio: proximity: add Imagis ISG5320A Adil Hüsrev Tepe
2026-11-16  7:51   ` sashiko-bot
2026-11-16  7:40 ` [PATCH v1 2/2] iio: proximity: add Imagis ISG5320A SAR sensor driver Adil Hüsrev Tepe
2026-11-16  7:58   ` sashiko-bot
2026-11-16 10:53   ` Andy Shevchenko
2026-11-16 10:48 ` [PATCH v1 0/2] iio: proximity: add Imagis ISG5320A (Samsung Galaxy XCover5) Andy Shevchenko
2026-11-17 10:44 ` [PATCH v2 1/2] dt-bindings: iio: proximity: add Imagis ISG5320A Adil Hüsrev Tepe
2026-11-17 10:44   ` [PATCH v2 2/2] iio: proximity: add Imagis ISG5320A SAR sensor driver Adil Hüsrev Tepe
2026-11-17 11:08     ` sashiko-bot
2026-11-17 13:56     ` Andy Shevchenko
2026-11-17 10:54   ` [PATCH v2 1/2] dt-bindings: iio: proximity: add Imagis ISG5320A sashiko-bot
2026-11-17 17:33 ` [PATCH v3 0/2] iio: proximity: add Imagis ISG5320A (Samsung Galaxy XCover5) Adil Hüsrev Tepe
2026-11-17 17:33   ` [PATCH v3 1/2] dt-bindings: iio: proximity: add Imagis ISG5320A Adil Hüsrev Tepe
2026-11-17 17:33   ` [PATCH v3 2/2] iio: proximity: add Imagis ISG5320A SAR sensor driver Adil Hüsrev Tepe
2026-11-17 17:55     ` sashiko-bot
2026-11-18  9:53     ` Joshua Crofts
2026-11-18  9:00   ` [PATCH v3 0/2] iio: proximity: add Imagis ISG5320A (Samsung Galaxy XCover5) Joshua Crofts

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.