Devicetree
 help / color / mirror / Atom feed
* [PATCH 1/2] dt-bindings: input: touchscreen: st,stmfts: add st,fts
       [not found] <1796369755.32249.0@17236081.qq.com>
  2026-12-04  7:35 ` [PATCH 2/2] Input: add STMicroelectronics FTM5 touchscreen driver sthho law
@ 2026-12-04  7:35 ` sthho law
  2026-12-04  7:49   ` sashiko-bot
  1 sibling, 1 reply; 6+ messages in thread
From: sthho law @ 2026-12-04  7:35 UTC (permalink / raw)
  To: 17236081
  Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Richard Acayan,
	devicetree, linux-kernel

The STMicroelectronics FingerTip controllers exist in two firmware
generations.  Panels running the FTM4 firmware report "st,stmfts",
panels running the FTM5 firmware report "st,fts" and answer a different
command set.  The wiring, the supplies and the interrupt are the same,
so both generations belong in this binding.

Allow "st,fts" next to "st,stmfts".

Signed-off-by: sthho law <17236081@qq.com>
---
 .../devicetree/bindings/input/touchscreen/st,stmfts.yaml  | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/input/touchscreen/st,stmfts.yaml b/Documentation/devicetree/bindings/input/touchscreen/st,stmfts.yaml
index 64c4f24..c0fd879 100644
--- a/Documentation/devicetree/bindings/input/touchscreen/st,stmfts.yaml
+++ b/Documentation/devicetree/bindings/input/touchscreen/st,stmfts.yaml
@@ -19,7 +19,13 @@ allOf:
 
 properties:
   compatible:
-    const: st,stmfts
+    enum:
+      - st,stmfts
+      - st,fts
+    description: |
+      Panels running the FTM4 firmware use "st,stmfts", panels running the
+      FTM5 firmware use "st,fts".  Both are FingerTip controllers with the
+      same wiring.
 
   reg:
     maxItems: 1


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

* [PATCH 2/2] Input: add STMicroelectronics FTM5 touchscreen driver
       [not found] <1796369755.32249.0@17236081.qq.com>
@ 2026-12-04  7:35 ` sthho law
  2026-12-04  7:59   ` sashiko-bot
  2026-12-04  7:35 ` [PATCH 1/2] dt-bindings: input: touchscreen: st,stmfts: add st,fts sthho law
  1 sibling, 1 reply; 6+ messages in thread
From: sthho law @ 2026-12-04  7:35 UTC (permalink / raw)
  To: 17236081
  Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Richard Acayan,
	devicetree, linux-kernel

Add a driver for the FTM5 generation of the STMicroelectronics FingerTip
controllers.  The existing stmfts.c speaks the FTM4 protocol, which FTM5
firmware does not answer: the system information command (0x80) returns
only zeros and a reset never produces the status event the driver waits
for, so probing such a panel fails with -ETIMEDOUT.  On the Meizu 16X
panel reported here the FTM4 probe timed out after 1.0 s while the chip
did acknowledge its I2C address, and the chip identifies itself as 0x3936
when its hardware registers are read out through the FTM5 protocol.

FTM5 reaches its hardware registers through the 0xFA command, selects the
scan mode with "0xA0 <mode> <settings>" and reports touch data as fixed
size 8 byte records that are read with 0x86.  Implement that protocol.

The controller drives its interrupt line low while its FIFO is not empty,
so a missed edge leaves the panel silent until the next touch.  A slow
workqueue drain empties the FIFO as well, which keeps the line moving
independently of the interrupt state.

The panel rails also feed the display and stay enabled, so suspend only
stops scanning and resume restarts the firmware and re-enables scanning.

Signed-off-by: sthho law <17236081@qq.com>
---
 drivers/input/touchscreen/Kconfig      |  10 +
 drivers/input/touchscreen/Makefile     |   1 +
 drivers/input/touchscreen/fts5_touch.c | 478 +++++++++++++++++++++++++
 3 files changed, 489 insertions(+)
 create mode 100644 drivers/input/touchscreen/fts5_touch.c

diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
index 9b9ae8a..32f1026 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -370,6 +370,16 @@ config TOUCHSCREEN_EXC3000
 	  To compile this driver as a module, choose M here: the
 	  module will be called exc3000.
 
+config TOUCHSCREEN_FTS5
+	tristate "STMicroelectronics FTM5 touchscreen"
+	depends on I2C
+	help
+	  Say Y here if you want support for STMicroelectronics FTM5
+	  (FingerTip) touchscreen controllers.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called fts5_touch.
+
 config TOUCHSCREEN_FUJITSU
 	tristate "Fujitsu serial touchscreen"
 	select SERIO
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile
index bfd9de8..0b59a5b 100644
--- a/drivers/input/touchscreen/Makefile
+++ b/drivers/input/touchscreen/Makefile
@@ -43,6 +43,7 @@ obj-$(CONFIG_TOUCHSCREEN_ELO)		+= elo.o
 obj-$(CONFIG_TOUCHSCREEN_EGALAX)	+= egalax_ts.o
 obj-$(CONFIG_TOUCHSCREEN_EGALAX_SERIAL)	+= egalax_ts_serial.o
 obj-$(CONFIG_TOUCHSCREEN_EXC3000)	+= exc3000.o
+obj-$(CONFIG_TOUCHSCREEN_FTS5)		+= fts5_touch.o
 obj-$(CONFIG_TOUCHSCREEN_FUJITSU)	+= fujitsu_ts.o
 obj-$(CONFIG_TOUCHSCREEN_GOODIX)	+= goodix_ts.o
 obj-$(CONFIG_TOUCHSCREEN_GOODIX_BERLIN_CORE)	+= goodix_berlin_core.o
diff --git a/drivers/input/touchscreen/fts5_touch.c b/drivers/input/touchscreen/fts5_touch.c
new file mode 100644
index 0000000..60a0f8f
--- /dev/null
+++ b/drivers/input/touchscreen/fts5_touch.c
@@ -0,0 +1,478 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * STMicroelectronics FTM5 (FingerTip) touchscreen driver
+ *
+ * The FTM5 firmware generation uses a different command set than the FTM4
+ * controllers handled by stmfts.c: hardware registers are accessed through
+ * the 0xFA command, scanning is started with 0xA0 <mode> <settings> and
+ * touch events are fixed size 8 byte records that are pulled out with 0x86.
+ */
+
+#include <linux/delay.h>
+#include <linux/i2c.h>
+#include <linux/input.h>
+#include <linux/input/mt.h>
+#include <linux/input/touchscreen.h>
+#include <linux/interrupt.h>
+#include <linux/minmax.h>
+#include <linux/module.h>
+#include <linux/pm.h>
+#include <linux/property.h>
+#include <linux/regulator/consumer.h>
+#include <linux/slab.h>
+
+#define FTS5_CMD_HW_REG			0xfa
+#define FTS5_CMD_SCAN_MODE		0xa0
+#define FTS5_CMD_READ_EVENTS		0x86
+
+#define FTS5_REG_CHIP_ID		0x20000000
+#define FTS5_REG_SYSTEM_RESET		0x20000024
+#define FTS5_SYSTEM_RESET		0x81
+
+#define FTS5_EVENT_SIZE			8
+#define FTS5_FIFO_DEPTH			32
+
+#define FTS5_SCAN_MODE_ACTIVE		0x00
+#define FTS5_SCAN_MODE_LOW_POWER	0x01
+#define FTS5_SCAN_MULTI_TOUCH		BIT(0)
+
+/* the upper nibble of the first event byte selects the event class */
+#define FTS5_EVENT_ID(ev)		((ev)[0] & 0xf0)
+#define FTS5_EVENT_ID_READY		0x00
+#define FTS5_EVENT_ID_ENTER		0x10
+#define FTS5_EVENT_ID_MOTION		0x20
+#define FTS5_EVENT_ID_LEAVE		0x30
+#define FTS5_EVENT_ID_ERROR		0xf0
+
+#define FTS5_MAX_CONTACTS		10
+
+struct fts5_data {
+	struct i2c_client *client;
+	struct input_dev *input;
+	struct touchscreen_properties prop;
+	struct regulator_bulk_data supplies[2];
+	u8 *buf;
+	unsigned long contacts;
+	bool ready;
+	struct delayed_work poll;
+};
+
+static int fts5_i2c_write(struct fts5_data *ts, const u8 *data, int len)
+{
+	struct i2c_msg msg = {
+		.addr = ts->client->addr,
+		.len = len,
+		.buf = (u8 *)data,
+	};
+
+	if (i2c_transfer(ts->client->adapter, &msg, 1) != 1)
+		return -EIO;
+
+	return 0;
+}
+
+static int fts5_i2c_wr_rd(struct fts5_data *ts, const u8 *wbuf, int wlen,
+			  u8 *rbuf, int rlen)
+{
+	struct i2c_msg msg[2] = {
+		{
+			.addr = ts->client->addr,
+			.len = wlen,
+			.buf = (u8 *)wbuf,
+		}, {
+			.addr = ts->client->addr,
+			.flags = I2C_M_RD,
+			.len = rlen,
+			.buf = rbuf,
+		},
+	};
+
+	if (i2c_transfer(ts->client->adapter, msg, 2) != 2)
+		return -EIO;
+
+	return 0;
+}
+
+static int fts5_reg_read(struct fts5_data *ts, u32 reg, u8 *val, int len)
+{
+	u8 cmd[5] = {
+		FTS5_CMD_HW_REG,
+		(u8)(reg >> 24),
+		(u8)(reg >> 16),
+		(u8)(reg >> 8),
+		(u8)reg,
+	};
+
+	return fts5_i2c_wr_rd(ts, cmd, sizeof(cmd), val, len);
+}
+
+static int fts5_reg_write(struct fts5_data *ts, u32 reg, u8 val)
+{
+	u8 cmd[6] = {
+		FTS5_CMD_HW_REG,
+		(u8)(reg >> 24),
+		(u8)(reg >> 16),
+		(u8)(reg >> 8),
+		(u8)reg,
+		val,
+	};
+
+	return fts5_i2c_write(ts, cmd, sizeof(cmd));
+}
+
+static int fts5_read_events(struct fts5_data *ts, u8 *buf, int count)
+{
+	u8 cmd = FTS5_CMD_READ_EVENTS;
+
+	return fts5_i2c_wr_rd(ts, &cmd, 1, buf, FTS5_EVENT_SIZE * count);
+}
+
+static int fts5_scan_mode(struct fts5_data *ts, u8 mode, u8 settings)
+{
+	/* select the FTM5 system command page */
+	const u8 page[7] = {
+		FTS5_CMD_HW_REG, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
+	};
+	u8 scan[3] = { FTS5_CMD_SCAN_MODE, mode, settings };
+	int ret;
+
+	ret = fts5_i2c_write(ts, page, sizeof(page));
+	if (ret)
+		return ret;
+
+	return fts5_i2c_write(ts, scan, sizeof(scan));
+}
+
+static void fts5_report_contact(struct fts5_data *ts, const u8 *ev, bool down)
+{
+	struct input_dev *input = ts->input;
+	unsigned int slot = ev[1] >> 4;
+	unsigned int x = (((int)ev[3] & 0x0f) << 8) | ev[2];
+	unsigned int y = ((int)ev[4] << 4) | ((ev[3] & 0xf0) >> 4);
+	unsigned int pressure = ev[5] ? ev[5] : 1;
+	unsigned int major = ((ev[0] & 0x0c) << 2) | (ev[6] >> 4);
+	unsigned int minor = ((ev[7] & 0xc0) >> 2) | (ev[6] & 0x0f);
+
+	if (slot >= FTS5_MAX_CONTACTS)
+		return;
+
+	if (ts->prop.max_x)
+		x = clamp_val(x, 0, ts->prop.max_x);
+	if (ts->prop.max_y)
+		y = clamp_val(y, 0, ts->prop.max_y);
+
+	input_mt_slot(input, slot);
+
+	if (down) {
+		__set_bit(slot, &ts->contacts);
+		input_mt_report_slot_state(input, MT_TOOL_FINGER, true);
+		touchscreen_report_pos(input, &ts->prop, x, y, true);
+		input_report_abs(input, ABS_MT_PRESSURE, pressure);
+		input_report_abs(input, ABS_MT_TOUCH_MAJOR, major);
+		input_report_abs(input, ABS_MT_TOUCH_MINOR, minor);
+		input_report_key(input, BTN_TOUCH, 1);
+	} else {
+		__clear_bit(slot, &ts->contacts);
+		input_mt_report_slot_state(input, MT_TOOL_FINGER, false);
+		if (!ts->contacts)
+			input_report_key(input, BTN_TOUCH, 0);
+	}
+}
+
+static void fts5_handle_event(struct fts5_data *ts, const u8 *ev)
+{
+	switch (FTS5_EVENT_ID(ev)) {
+	case FTS5_EVENT_ID_ENTER:
+	case FTS5_EVENT_ID_MOTION:
+		fts5_report_contact(ts, ev, true);
+		break;
+	case FTS5_EVENT_ID_LEAVE:
+		fts5_report_contact(ts, ev, false);
+		break;
+	case FTS5_EVENT_ID_ERROR:
+		dev_warn_ratelimited(&ts->client->dev, "firmware error %*ph\n",
+				     6, ev + 1);
+		break;
+	default:
+		break;
+	}
+}
+
+static int fts5_drain(struct fts5_data *ts)
+{
+	int count = 0;
+	int i, ret;
+
+	for (i = 0; i < 2 * FTS5_FIFO_DEPTH; i++) {
+		ret = fts5_read_events(ts, ts->buf, 1);
+		if (ret) {
+			dev_warn_ratelimited(&ts->client->dev, "read events: %d\n",
+					     ret);
+			break;
+		}
+
+		if (!FTS5_EVENT_ID(ts->buf))
+			break;
+
+		fts5_handle_event(ts, ts->buf);
+		count++;
+	}
+
+	if (count)
+		input_sync(ts->input);
+
+	return count;
+}
+
+/*
+ * The controller drives nIRQ low while its FIFO is not empty, so a missed
+ * edge silences the panel until the next event.  Empty the FIFO from a slow
+ * workqueue as well, which keeps the line moving regardless of the IRQ state.
+ */
+static void fts5_poll(struct work_struct *work)
+{
+	struct fts5_data *ts = container_of(to_delayed_work(work),
+					    struct fts5_data, poll);
+
+	if (ts->ready)
+		fts5_drain(ts);
+
+	schedule_delayed_work(&ts->poll, msecs_to_jiffies(100));
+}
+
+static irqreturn_t fts5_irq(int irq, void *data)
+{
+	struct fts5_data *ts = data;
+
+	if (ts->ready)
+		fts5_drain(ts);
+
+	return IRQ_HANDLED;
+}
+
+static int fts5_startup(struct fts5_data *ts)
+{
+	struct device *dev = &ts->client->dev;
+	u8 id[4];
+	int ret, i;
+
+	ret = fts5_reg_read(ts, FTS5_REG_CHIP_ID, id, sizeof(id));
+	if (ret)
+		return ret;
+
+	dev_dbg(dev, "chip id %*ph\n", 4, id);
+
+	ret = fts5_reg_write(ts, FTS5_REG_SYSTEM_RESET, FTS5_SYSTEM_RESET);
+	if (ret)
+		return ret;
+
+	msleep(150);
+
+	/*
+	 * A freshly reset controller reports CONTROLLER_READY; firmware that is
+	 * already running does not, so a timeout is not fatal.
+	 */
+	for (i = 0; i < 20; i++) {
+		ret = fts5_read_events(ts, ts->buf, 1);
+		if (!ret && FTS5_EVENT_ID(ts->buf) == FTS5_EVENT_ID_READY)
+			break;
+
+		msleep(20);
+	}
+
+	if (i == 20)
+		dev_dbg(dev, "no CONTROLLER_READY event\n");
+
+	return fts5_scan_mode(ts, FTS5_SCAN_MODE_ACTIVE, FTS5_SCAN_MULTI_TOUCH);
+}
+
+static void fts5_release_contacts(struct fts5_data *ts)
+{
+	int i;
+
+	for (i = 0; i < FTS5_MAX_CONTACTS; i++) {
+		input_mt_slot(ts->input, i);
+		input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
+	}
+
+	input_report_key(ts->input, BTN_TOUCH, 0);
+	input_sync(ts->input);
+	ts->contacts = 0;
+}
+
+static int fts5_suspend(struct device *dev)
+{
+	struct fts5_data *ts = dev_get_drvdata(dev);
+	int ret;
+
+	if (!ts)
+		return 0;
+
+	ts->ready = false;
+	disable_irq(ts->client->irq);
+	cancel_delayed_work_sync(&ts->poll);
+	fts5_release_contacts(ts);
+
+	ret = fts5_scan_mode(ts, FTS5_SCAN_MODE_LOW_POWER, 0);
+	if (ret)
+		dev_warn(dev, "failed to stop scanning: %d\n", ret);
+
+	return 0;
+}
+
+static int fts5_resume(struct device *dev)
+{
+	struct fts5_data *ts = dev_get_drvdata(dev);
+	int ret;
+
+	if (!ts)
+		return 0;
+
+	ret = fts5_startup(ts);
+	if (ret)
+		dev_err(dev, "failed to resume: %d\n", ret);
+
+	ts->ready = !ret;
+	fts5_drain(ts);
+	enable_irq(ts->client->irq);
+	schedule_delayed_work(&ts->poll, msecs_to_jiffies(100));
+
+	return ret;
+}
+
+static DEFINE_SIMPLE_DEV_PM_OPS(fts5_pm_ops, fts5_suspend, fts5_resume);
+
+static void fts5_power_off(void *data)
+{
+	struct fts5_data *ts = data;
+
+	regulator_bulk_disable(ARRAY_SIZE(ts->supplies), ts->supplies);
+}
+
+static void fts5_remove(struct i2c_client *client)
+{
+	struct fts5_data *ts = i2c_get_clientdata(client);
+
+	ts->ready = false;
+	cancel_delayed_work_sync(&ts->poll);
+	fts5_release_contacts(ts);
+}
+
+static int fts5_probe(struct i2c_client *client)
+{
+	struct device *dev = &client->dev;
+	struct fts5_data *ts;
+	struct input_dev *input;
+	int ret;
+
+	ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL);
+	if (!ts)
+		return -ENOMEM;
+
+	ts->client = client;
+	ts->buf = devm_kzalloc(dev, FTS5_EVENT_SIZE * FTS5_FIFO_DEPTH,
+			       GFP_KERNEL);
+	if (!ts->buf)
+		return -ENOMEM;
+
+	ts->supplies[0].supply = "avdd";
+	ts->supplies[1].supply = "vdd";
+
+	ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(ts->supplies),
+				      ts->supplies);
+	if (ret)
+		return ret;
+
+	ret = regulator_bulk_enable(ARRAY_SIZE(ts->supplies), ts->supplies);
+	if (ret)
+		return ret;
+
+	ret = devm_add_action_or_reset(dev, fts5_power_off, ts);
+	if (ret)
+		return ret;
+
+	/* let the rails settle before the controller is talked to */
+	msleep(20);
+
+	ret = fts5_startup(ts);
+	if (ret) {
+		dev_err(dev, "failed to start: %d\n", ret);
+		return ret;
+	}
+
+	input = devm_input_allocate_device(dev);
+	if (!input)
+		return -ENOMEM;
+
+	input->name = "STMicroelectronics FTM5 Touchscreen";
+	input->id.bustype = BUS_I2C;
+
+	/*
+	 * Declare the multi-touch axes before parsing, touchscreen_parse_properties()
+	 * only fills in the limits that the device tree provides.
+	 */
+	input_set_abs_params(input, ABS_MT_POSITION_X, 0, 0, 0, 0);
+	input_set_abs_params(input, ABS_MT_POSITION_Y, 0, 0, 0, 0);
+	touchscreen_parse_properties(input, true, &ts->prop);
+
+	input_set_abs_params(input, ABS_MT_PRESSURE, 0, 255, 0, 0);
+	input_set_abs_params(input, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
+	input_set_abs_params(input, ABS_MT_TOUCH_MINOR, 0, 255, 0, 0);
+	input_set_capability(input, EV_KEY, BTN_TOUCH);
+
+	ret = input_mt_init_slots(input, FTS5_MAX_CONTACTS, INPUT_MT_DIRECT);
+	if (ret)
+		return ret;
+
+	ret = input_register_device(input);
+	if (ret)
+		return ret;
+
+	ts->input = input;
+
+	/*
+	 * The trigger type comes from the device tree, so request the
+	 * interrupt without IRQF_TRIGGER_* flags.
+	 */
+	ret = devm_request_threaded_irq(dev, client->irq, NULL, fts5_irq,
+					IRQF_ONESHOT, dev_name(dev), ts);
+	if (ret) {
+		dev_err(dev, "failed to request irq %d: %d\n", client->irq, ret);
+		return ret;
+	}
+
+	INIT_DELAYED_WORK(&ts->poll, fts5_poll);
+	schedule_delayed_work(&ts->poll, msecs_to_jiffies(100));
+	ts->ready = true;
+
+	i2c_set_clientdata(client, ts);
+
+	return 0;
+}
+
+static const struct of_device_id fts5_of_match[] = {
+	{ .compatible = "st,fts" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, fts5_of_match);
+
+static const struct i2c_device_id fts5_id[] = {
+	{ "fts5_touch" },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, fts5_id);
+
+static struct i2c_driver fts5_driver = {
+	.driver = {
+		.name = "fts5_touch",
+		.of_match_table = fts5_of_match,
+		.pm = pm_sleep_ptr(&fts5_pm_ops),
+	},
+	.probe = fts5_probe,
+	.remove = fts5_remove,
+	.id_table = fts5_id,
+};
+module_i2c_driver(fts5_driver);
+
+MODULE_DESCRIPTION("STMicroelectronics FTM5 touchscreen driver");
+MODULE_LICENSE("GPL");


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

* [PATCH 1/2] dt-bindings: input: touchscreen: st,stmfts: add st,fts
       [not found] <1796370440.32551.0@17236081.qq.com>
@ 2026-12-04  7:47 ` sthho law
  2026-12-04  7:59   ` sashiko-bot
  0 siblings, 1 reply; 6+ messages in thread
From: sthho law @ 2026-12-04  7:47 UTC (permalink / raw)
  To: 17236081
  Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Richard Acayan,
	devicetree, linux-kernel

The STMicroelectronics FingerTip controllers exist in two firmware
generations.  Panels running the FTM4 firmware report "st,stmfts",
panels running the FTM5 firmware report "st,fts" and answer a different
command set.  The wiring, the supplies and the interrupt are the same,
so both generations belong in this binding.

Allow "st,fts" next to "st,stmfts".

Signed-off-by: sthho law <17236081@qq.com>
---
 .../devicetree/bindings/input/touchscreen/st,stmfts.yaml  | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/input/touchscreen/st,stmfts.yaml b/Documentation/devicetree/bindings/input/touchscreen/st,stmfts.yaml
index 64c4f24..c0fd879 100644
--- a/Documentation/devicetree/bindings/input/touchscreen/st,stmfts.yaml
+++ b/Documentation/devicetree/bindings/input/touchscreen/st,stmfts.yaml
@@ -19,7 +19,13 @@ allOf:
 
 properties:
   compatible:
-    const: st,stmfts
+    enum:
+      - st,stmfts
+      - st,fts
+    description: |
+      Panels running the FTM4 firmware use "st,stmfts", panels running the
+      FTM5 firmware use "st,fts".  Both are FingerTip controllers with the
+      same wiring.
 
   reg:
     maxItems: 1


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

* Re: [PATCH 1/2] dt-bindings: input: touchscreen: st,stmfts: add st,fts
  2026-12-04  7:35 ` [PATCH 1/2] dt-bindings: input: touchscreen: st,stmfts: add st,fts sthho law
@ 2026-12-04  7:49   ` sashiko-bot
  0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-12-04  7:49 UTC (permalink / raw)
  To: sthho law; +Cc: devicetree, robh, conor+dt

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] dt-bindings: st,stmfts: generic device-family compatible
  string st,fts
--

commit c6f7ae3dc40b93a6dc1df1428737c87e1e61a263
Author: sthho law <17236081@qq.com>

dt-bindings: input: touchscreen: st,stmfts: add st,fts

This commit adds "st,fts" to the compatible enum in the STMicroelectronics
FingerTip touchscreen binding for panels running FTM5 firmware.

> diff --git a/Documentation/devicetree/bindings/input/touchscreen/st,stmfts.yaml b/Documentation/devicetree/bindings/input/touchscreen/st,stmfts.yaml
> index 64c4f24ea3dd0..c0fd879dda3ab 100644
> --- a/Documentation/devicetree/bindings/input/touchscreen/st,stmfts.yaml
> +++ b/Documentation/devicetree/bindings/input/touchscreen/st,stmfts.yaml
> @@ -19,7 +19,13 @@ allOf:
>
>  properties:
>    compatible:
> -    const: st,stmfts
> +    enum:
> +      - st,stmfts
> +      - st,fts
> +    description: |
> +      Panels running the FTM4 firmware use "st,stmfts", panels running the
> +      FTM5 firmware use "st,fts".  Both are FingerTip controllers with the
> +      same wiring.

[Severity: Medium]
Should "st,fts" be replaced with a specific controller IC model compatible?

Documentation/devicetree/bindings/writing-bindings.rst requires specific
compatible strings and forbids device-family names.  "st,fts" only names the
FingerTip S family, creating a permanent DT ABI that cannot cleanly separate
specific FTM5 controller variants, hardware quirks, or future generations.

The schema and commit message also distinguish "st,stmfts" and "st,fts" by
firmware generation rather than controller silicon.  In addition, the commit
message states that panels report these compatibles, whereas DT compatibles
are defined by bindings and written in DTS files.

Defining compatible string(s) for the specific ST controller IC model(s)
being supported (with an explicit fallback only when multiple models share
the same programming interface) would avoid locking in a generic family name.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/tencent_24E2E7771214F73657B404816A24822DDE08@qq.com?part=1

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

* Re: [PATCH 2/2] Input: add STMicroelectronics FTM5 touchscreen driver
  2026-12-04  7:35 ` [PATCH 2/2] Input: add STMicroelectronics FTM5 touchscreen driver sthho law
@ 2026-12-04  7:59   ` sashiko-bot
  0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-12-04  7:59 UTC (permalink / raw)
  To: sthho law; +Cc: devicetree, robh, conor+dt

Thank you for your contribution! Sashiko AI review found 14 potential
issues to consider:
- [High] Input: unsynchronized fts5_drain() calls race on ts->buf and MT
  state
- [High] Input: FTS5_EVENT_ID_READY aliases empty FIFO under 0xf0 mask
- [High] Input: fts5_resume() enables IRQ and polling after
  fts5_startup() failure
- [Medium] Input: fts5_probe() and fts5_suspend() misorder IRQ enable
  and ts->ready
- [Medium] Input: fts5_remove() releases contacts while devm IRQ is
  still active
- [Medium] Input: fts5_touch advertises INPUT_MT_DIRECT without pointer
  emulation
- [Medium] Input: unconditional 10 Hz fts5_poll() continuously wakes CPU
  and I2C
- [Medium] input: fts5_probe() sets ABS_MT_PRESSURE after
  touchscreen_parse_properties()
- [Medium] input: fts5_probe() ignores optional reset-gpios defined in
  st,stmfts.yaml
- [Medium] input: fts5_probe() leaves X/Y axis maximums at 0 when DT
  sizes are absent
- [Low] input: fts5_i2c_write() and fts5_i2c_wr_rd() discard
  i2c_transfer() errnos
- [Low] input: fts5_id table uses positional initializer instead of
  named initializer
- [Low] input: fts5_touch.c violates Input error variable and return
  conventions
- [Low] input: fts5_probe() omits client->irq > 0 check before
  requesting IRQ
--

commit 0699178567233d6ab1558029861fa1f8b53c9dac
Author: sthho law <17236081@qq.com>

Input: add STMicroelectronics FTM5 touchscreen driver

This commit adds an I2C touchscreen driver for STMicroelectronics FTM5
FingerTip controllers, implementing the FTM5 register, scan mode, and
8-byte event FIFO protocol with a periodic workqueue drain and sleep
power management.

> diff --git a/drivers/input/touchscreen/fts5_touch.c b/drivers/input/touchscreen/fts5_touch.c
> new file mode 100644
> index 0000000000000..60a0f8f50b57e
> --- /dev/null
> +++ b/drivers/input/touchscreen/fts5_touch.c
> @@ -0,0 +1,478 @@

[ ... ]

> +/* the upper nibble of the first event byte selects the event class */
> +#define FTS5_EVENT_ID(ev)		((ev)[0] & 0xf0)
> +#define FTS5_EVENT_ID_READY		0x00

[Severity: High]
Does masking to the upper nibble make FTS5_EVENT_ID_READY indistinguishable
from an empty FIFO?

fts5_startup() polls for FTS5_EVENT_ID(ts->buf) == FTS5_EVENT_ID_READY while
fts5_drain() stops on !FTS5_EVENT_ID(ts->buf), so both evaluate
(ts->buf[0] & 0xf0) == 0x00.  As a result, fts5_startup() breaks out on the
first empty 0x00 read before the controller finishes resetting, and
fts5_drain() aborts early on any 0x01..0x0f event, leaving later touch
events in the FIFO with active-low nIRQ asserted.

Matching the exact empty-FIFO byte (0x00) separately from the
CONTROLLER_READY event byte avoids both issues.

[ ... ]

> +static int fts5_i2c_write(struct fts5_data *ts, const u8 *data, int len)
> +{
> +	struct i2c_msg msg = {
> +		.addr = ts->client->addr,
> +		.len = len,
> +		.buf = (u8 *)data,
> +	};
> +
> +	if (i2c_transfer(ts->client->adapter, &msg, 1) != 1)
> +		return -EIO;
> +
> +	return 0;
> +}
> +
> +static int fts5_i2c_wr_rd(struct fts5_data *ts, const u8 *wbuf, int wlen,
> +			  u8 *rbuf, int rlen)
> +{
> +	struct i2c_msg msg[2] = {
> +		{
> +			.addr = ts->client->addr,
> +			.len = wlen,
> +			.buf = (u8 *)wbuf,
> +		}, {
> +			.addr = ts->client->addr,
> +			.flags = I2C_M_RD,
> +			.len = rlen,
> +			.buf = rbuf,
> +		},
> +	};
> +
> +	if (i2c_transfer(ts->client->adapter, msg, 2) != 2)
> +		return -EIO;
> +
> +	return 0;
> +}

[Severity: Low]
Should fts5_i2c_write() and fts5_i2c_wr_rd() propagate negative error codes
from i2c_transfer() instead of replacing them with -EIO?  Returning -EIO
only on a short transfer count preserves bus errors like -ETIMEDOUT or
-ENXIO.

Also, fts5_probe() does not check i2c_check_functionality(client->adapter,
I2C_FUNC_I2C), so an SMBus-only adapter powers on the regulators and sleeps
before failing in fts5_startup().

[ ... ]

> +static int fts5_scan_mode(struct fts5_data *ts, u8 mode, u8 settings)
> +{
> +	/* select the FTM5 system command page */
> +	const u8 page[7] = {
> +		FTS5_CMD_HW_REG, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
> +	};
> +	u8 scan[3] = { FTS5_CMD_SCAN_MODE, mode, settings };
> +	int ret;
> +
> +	ret = fts5_i2c_write(ts, page, sizeof(page));
> +	if (ret)
> +		return ret;
> +
> +	return fts5_i2c_write(ts, scan, sizeof(scan));
> +}

[Severity: Low]
Input subsystem convention prefers naming error-only variables error (or
err) instead of ret, and checking the final error-returning call with an
explicit return 0 on the success path in functions with multiple failure
points.  The same pattern appears in fts5_startup(), fts5_resume(),
fts5_suspend(), fts5_drain(), and fts5_probe().

[ ... ]

> +static int fts5_drain(struct fts5_data *ts)
> +{
> +	int count = 0;
> +	int i, ret;
> +
> +	for (i = 0; i < 2 * FTS5_FIFO_DEPTH; i++) {
> +		ret = fts5_read_events(ts, ts->buf, 1);
> +		if (ret) {
> +			dev_warn_ratelimited(&ts->client->dev, "read events: %d\n",
> +					     ret);
> +			break;
> +		}
> +
> +		if (!FTS5_EVENT_ID(ts->buf))
> +			break;
> +
> +		fts5_handle_event(ts, ts->buf);
> +		count++;
> +	}
> +
> +	if (count)
> +		input_sync(ts->input);
> +
> +	return count;
> +}

[Severity: High]
Can fts5_irq() and fts5_poll() run fts5_drain() concurrently and corrupt
ts->buf, ts->contacts, and multi-touch slot state?

Both the threaded IRQ handler and the 100 ms delayed work run in process
context with no lock in struct fts5_data:

IRQ thread                          kworker (fts5_poll)
fts5_irq()                          fts5_poll()
  fts5_drain()                        fts5_drain()
    fts5_read_events(..., ts->buf)
    fts5_handle_event(..., ts->buf)
      fts5_report_contact()             fts5_read_events(..., ts->buf)
        reads ts->buf[0..7]  <-- torn event / overwritten buffer
        __set_bit(..., &ts->contacts)   fts5_report_contact()
        input_mt_slot()                   input_mt_slot()  <-- clobbers slot

Because i2c_transfer() only locks the adapter during the transfer, one
thread can overwrite ts->buf while the other decodes it.  Concurrent
non-atomic bitops on ts->contacts can also leave BTN_TOUCH stuck, and
input_mt_report_slot_state() relies on callers to serialize updates to
mt->slot and tracking IDs.

Serializing FIFO drains, contact release, and state transitions with a
mutex in struct fts5_data would prevent this race.

> +/*
> + * The controller drives nIRQ low while its FIFO is not empty, so a missed
> + * edge silences the panel until the next event.  Empty the FIFO from a slow
> + * workqueue as well, which keeps the line moving regardless of the IRQ state.
> + */
> +static void fts5_poll(struct work_struct *work)
> +{
> +	struct fts5_data *ts = container_of(to_delayed_work(work),
> +					    struct fts5_data, poll);
> +
> +	if (ts->ready)
> +		fts5_drain(ts);
> +
> +	schedule_delayed_work(&ts->poll, msecs_to_jiffies(100));
> +}

[Severity: Medium]
Is this unconditional 10 Hz polling workqueue needed when nIRQ is driven
low while the FIFO is non-empty?

Running fts5_poll() every 100 ms from probe until remove wakes the CPU and
issues I2C transfers continuously while awake, even when idle or when no
consumer has opened the input device.  With an active-low level-triggered
interrupt (IRQ_TYPE_LEVEL_LOW, as documented in st,stmfts.yaml) and
IRQF_ONESHOT, there is no missed-edge problem.

In addition, the driver has no input->open/close callbacks or runtime PM to
stop scanning when unused, and fts5_remove() leaves the controller scanning
even though the shared display rails stay powered.

[ ... ]

> +static int fts5_resume(struct device *dev)
> +{
> +	struct fts5_data *ts = dev_get_drvdata(dev);
> +	int ret;
> +
> +	if (!ts)
> +		return 0;
> +
> +	ret = fts5_startup(ts);
> +	if (ret)
> +		dev_err(dev, "failed to resume: %d\n", ret);
> +
> +	ts->ready = !ret;
> +	fts5_drain(ts);
> +	enable_irq(ts->client->irq);
> +	schedule_delayed_work(&ts->poll, msecs_to_jiffies(100));
> +
> +	return ret;
> +}

[Severity: High]
Can fts5_resume() trigger an infinite interrupt storm if fts5_startup()
fails?

When fts5_startup() returns an error, ts->ready stays false, yet
fts5_resume() still drains the failed controller, enables client->irq, and
restarts the 100 ms poll work.  If an active-low level-triggered nIRQ is
asserted, fts5_irq() sees ts->ready == false, skips draining the FIFO, and
returns IRQ_HANDLED, causing the threaded IRQ to spin forever and bypassing
spurious-IRQ detection.

On startup failure, fts5_resume() should skip draining, enabling the IRQ,
and scheduling ts->poll, while tracking IRQ enable state so a later
fts5_suspend() does not call disable_irq() twice.

[ ... ]

> +static void fts5_remove(struct i2c_client *client)
> +{
> +	struct fts5_data *ts = i2c_get_clientdata(client);
> +
> +	ts->ready = false;
> +	cancel_delayed_work_sync(&ts->poll);
> +	fts5_release_contacts(ts);
> +}

[Severity: Medium]
Can an active fts5_irq() thread race with fts5_release_contacts() during
driver removal?

i2c_device_remove() calls fts5_remove() before devres_release_group() frees
the devm-managed IRQ:

CPU0                                CPU1 (IRQ thread)
fts5_remove()                       fts5_irq()
                                      if (ts->ready) -> true
  ts->ready = false
  cancel_delayed_work_sync(...)
  fts5_release_contacts()             fts5_drain()
    clears MT slots / contacts          fts5_report_contact()  <-- races

While cancel_delayed_work_sync() blocks with ts->ready == false and the IRQ
still enabled, an asserted active-low level IRQ also causes fts5_irq() to
return IRQ_HANDLED repeatedly without draining.  Managing the work teardown
via devres ordered with IRQ disable/synchronization avoids both the race
and mixing devm with manual cleanup.

[ ... ]

> +	ret = regulator_bulk_enable(ARRAY_SIZE(ts->supplies), ts->supplies);
> +	if (ret)
> +		return ret;
> +
> +	ret = devm_add_action_or_reset(dev, fts5_power_off, ts);
> +	if (ret)
> +		return ret;
> +
> +	/* let the rails settle before the controller is talked to */
> +	msleep(20);
> +
> +	ret = fts5_startup(ts);

[Severity: Medium]
Should fts5_probe() request and deassert the optional reset-gpios property?

Commit "dt-bindings: input: touchscreen: st,stmfts: add st,fts" adds st,fts
to the shared st,stmfts.yaml binding, which documents an optional
active-low reset-gpios line.  On boards where that line defaults asserted,
the controller stays held in reset and fts5_startup() fails over I2C.

[ ... ]

> +	input_set_abs_params(input, ABS_MT_POSITION_X, 0, 0, 0, 0);
> +	input_set_abs_params(input, ABS_MT_POSITION_Y, 0, 0, 0, 0);
> +	touchscreen_parse_properties(input, true, &ts->prop);

[Severity: Medium]
What happens if touchscreen-size-x or touchscreen-size-y is omitted from
the device tree?

Neither property is required by st,stmfts.yaml.  Without them, the input
device registers X and Y with range [0, 0], and enabling
touchscreen-inverted-x or touchscreen-inverted-y causes unsigned underflow
(prop->max_x - *x) in touchscreen_apply_prop_to_x_y().  Setting a non-zero
default range before touchscreen_parse_properties() or rejecting zero
max_x/max_y would prevent this.

> +	input_set_abs_params(input, ABS_MT_PRESSURE, 0, 255, 0, 0);

[Severity: Medium]
Does setting ABS_MT_PRESSURE after touchscreen_parse_properties() discard
device tree pressure properties?

When touchscreen-max-pressure or touchscreen-fuzz-pressure is present,
touchscreen_set_params() warns that ABS_MT_PRESSURE is not set up yet and
skips it, and this call would overwrite any parsed limits anyway.  Moving
this call before touchscreen_parse_properties() fixes both.

[ ... ]

> +	input_set_capability(input, EV_KEY, BTN_TOUCH);
> +
> +	ret = input_mt_init_slots(input, FTS5_MAX_CONTACTS, INPUT_MT_DIRECT);

[Severity: Medium]
Does passing INPUT_MT_DIRECT without calling input_mt_sync_frame() leave
advertised single-touch axes unreported?

input_mt_init_slots() with INPUT_MT_DIRECT sets BTN_TOUCH (making the
explicit input_set_capability() above redundant) and copies
ABS_MT_POSITION_X/Y and ABS_MT_PRESSURE to ABS_X, ABS_Y, and ABS_PRESSURE.
Because neither fts5_drain() nor fts5_release_contacts() calls
input_mt_sync_frame() or input_mt_report_pointer_emulation(), those
advertised single-touch axes stay at 0 for single-touch userspace clients.

Calling input_mt_sync_frame() before input_sync() in fts5_drain() and
fts5_release_contacts() handles pointer emulation and removes the need for
manual ts->contacts tracking.

[ ... ]

> +	ret = input_register_device(input);
> +	if (ret)
> +		return ret;
> +
> +	ts->input = input;
> +
> +	/*
> +	 * The trigger type comes from the device tree, so request the
> +	 * interrupt without IRQF_TRIGGER_* flags.
> +	 */
> +	ret = devm_request_threaded_irq(dev, client->irq, NULL, fts5_irq,
> +					IRQF_ONESHOT, dev_name(dev), ts);

[Severity: Low]
Should fts5_probe() verify client->irq > 0 before requesting the interrupt?

When no IRQ is assigned (for example via sysfs new_device),
i2c_device_probe() sets client->irq to 0.  request_threaded_irq() does not
reject 0 unconditionally and looks up irq_to_desc(0), so validating
client->irq early fails cleanly before powering on the hardware or
registering the input device.

[ ... ]

> +	INIT_DELAYED_WORK(&ts->poll, fts5_poll);
> +	schedule_delayed_work(&ts->poll, msecs_to_jiffies(100));
> +	ts->ready = true;

[Severity: Medium]
Can enabling the IRQ and starting ts->poll before ts->ready is set cause
spurious handling or a level-IRQ spin during probe?

fts5_startup() has already enabled active scanning, and
devm_request_threaded_irq() enables client->irq without IRQF_NO_AUTOEN
while ts->ready is still false.  If nIRQ is already asserted low,
fts5_irq() fires, skips draining, and returns IRQ_HANDLED repeatedly until
ts->ready = true becomes visible (and fts5_suspend() opens the same window
by clearing ts->ready before disable_irq()).

In addition, input_register_device() exposes the input device before IRQ
acquisition succeeds, and plain bool ts->ready is accessed across threads
without locking or READ_ONCE()/WRITE_ONCE().  Requesting the IRQ with
IRQF_NO_AUTOEN before input_register_device(), disabling it before clearing
ts->ready on suspend, and protecting state transitions with a mutex would
close these windows.

[ ... ]

> +static const struct i2c_device_id fts5_id[] = {
> +	{ "fts5_touch" },
> +	{ }
> +};

[Severity: Low]
I2C subsystem convention expects new struct i2c_device_id entries to use
named initializers, i.e. { .name = "fts5_touch" }.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/tencent_24E2E7771214F73657B404816A24822DDE08@qq.com?part=2

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

* Re: [PATCH 1/2] dt-bindings: input: touchscreen: st,stmfts: add st,fts
  2026-12-04  7:47 ` sthho law
@ 2026-12-04  7:59   ` sashiko-bot
  0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-12-04  7:59 UTC (permalink / raw)
  To: sthho law; +Cc: devicetree, robh, conor+dt

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] dt-bindings: input: st,stmfts: overly generic device-family
  compatible st,fts
--

commit 1d92223f6a309f91c58b758b3207a4d7c155be5d
Author: sthho law <17236081@qq.com>

dt-bindings: input: touchscreen: st,stmfts: add st,fts

This commit adds the "st,fts" compatible string alongside "st,stmfts" in
the STMicroelectronics FingerTip touchscreen binding.

> diff --git a/Documentation/devicetree/bindings/input/touchscreen/st,stmfts.yaml b/Documentation/devicetree/bindings/input/touchscreen/st,stmfts.yaml
> index 64c4f24ea3dd0..c0fd879dda3ab 100644
> --- a/Documentation/devicetree/bindings/input/touchscreen/st,stmfts.yaml
> +++ b/Documentation/devicetree/bindings/input/touchscreen/st,stmfts.yaml
> @@ -19,7 +19,13 @@ allOf:
>  
>  properties:
>    compatible:
> -    const: st,stmfts
> +    enum:
> +      - st,stmfts
> +      - st,fts
> +    description: |
> +      Panels running the FTM4 firmware use "st,stmfts", panels running the
> +      FTM5 firmware use "st,fts".  Both are FingerTip controllers with the
> +      same wiring.

[Severity: Medium]
Is "st,fts" too generic to add as a Devicetree compatible string?

FTS refers to the entire STMicroelectronics FingerTipS controller family
rather than a specific controller model, and
Documentation/devicetree/bindings/writing-bindings.rst prohibits
device-family names in compatible strings.

No in-tree DTS currently uses "st,fts", so adopting it as permanent ABI
would prevent distinguishing specific FingerTipS silicon models or future
generations later without adding quirks or breaking ABI.

Also, the commit message and description tie compatibles to firmware
generations reported by panels, whereas Devicetree compatibles should name
concrete controller hardware models.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/tencent_3ED5BA051BBD45CEA724F0EF5BAEAE089C09@qq.com?part=1

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

end of thread, other threads:[~2026-12-04  7:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1796369755.32249.0@17236081.qq.com>
2026-12-04  7:35 ` [PATCH 2/2] Input: add STMicroelectronics FTM5 touchscreen driver sthho law
2026-12-04  7:59   ` sashiko-bot
2026-12-04  7:35 ` [PATCH 1/2] dt-bindings: input: touchscreen: st,stmfts: add st,fts sthho law
2026-12-04  7:49   ` sashiko-bot
     [not found] <1796370440.32551.0@17236081.qq.com>
2026-12-04  7:47 ` sthho law
2026-12-04  7:59   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox