All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/7] Input: novatek-nvt-ts - add transport ops abstraction
@ 2026-12-02  0:31 Qianhui Xu
  2026-12-02  0:31 ` [PATCH 2/7] Input: novatek-nvt-ts - split bus independent core out Qianhui Xu
                   ` (5 more replies)
  0 siblings, 6 replies; 11+ messages in thread
From: Qianhui Xu @ 2026-12-02  0:31 UTC (permalink / raw)
  To: dmitry.torokhov, hansg
  Cc: linux-input, devicetree, linux-kernel, robh, krzk+dt, conor+dt,
	konrad.dybcio, kholk11, gchan9527

The controllers supported by this driver can be wired to either I2C or SPI
depending on the board; only the framing of a register read differs.

Move the register read into a bus ops structure selected by the transport
specific probe function, and keep the I2C message construction in
nvt_ts_i2c_read(). Store the device and the IRQ number in the common
private structure so that the IRQ, open/close, and PM paths no longer reach
back into the I2C client.

No functional change for existing I2C devices.

Signed-off-by: Qianhui Xu <xiaqinghuan@mail.ustc.edu.cn>

---
 drivers/input/touchscreen/novatek-nvt-ts.c | 54 ++++++++++++++++------
 1 file changed, 41 insertions(+), 13 deletions(-)

diff --git a/drivers/input/touchscreen/novatek-nvt-ts.c b/drivers/input/touchscreen/novatek-nvt-ts.c
index fa718a99e2ba5..d1aa42533db2a 100644
--- a/drivers/input/touchscreen/novatek-nvt-ts.c
+++ b/drivers/input/touchscreen/novatek-nvt-ts.c
@@ -47,13 +47,28 @@ static const int nvt_ts_irq_type[4] = {
 	IRQF_TRIGGER_HIGH
 };
 
+struct nvt_ts_data;
+
+/**
+ * struct nvt_ts_bus_ops - transport specific operations
+ * @read: read @count bytes of the controller into @buf
+ *
+ * The controller exposes a flat register space; transports differ only in
+ * how a register read is framed on the wire.
+ */
+struct nvt_ts_bus_ops {
+	int (*read)(struct nvt_ts_data *data, u8 reg, u8 *buf, size_t count);
+};
+
 struct nvt_ts_i2c_chip_data {
 	u8 chip_id;
 };
 
 struct nvt_ts_data {
-	struct i2c_client *client;
+	struct device *dev;
+	const struct nvt_ts_bus_ops *bus_ops;
 	struct input_dev *input;
+	int irq;
 	struct gpio_desc *reset_gpio;
 	struct regulator_bulk_data regulators[2];
 	struct touchscreen_properties prop;
@@ -61,8 +76,10 @@ struct nvt_ts_data {
 	u8 buf[NVT_TS_TOUCH_SIZE * NVT_TS_MAX_TOUCHES];
 };
 
-static int nvt_ts_read_data(struct i2c_client *client, u8 reg, u8 *data, int count)
+static int nvt_ts_i2c_read(struct nvt_ts_data *data, u8 reg, u8 *buf, size_t count)
 {
+	struct i2c_client *client = to_i2c_client(data->dev);
+
 	struct i2c_msg msg[2] = {
 		{
 			.addr = client->addr,
@@ -73,7 +90,7 @@ static int nvt_ts_read_data(struct i2c_client *client, u8 reg, u8 *data, int cou
 			.addr = client->addr,
 			.flags = I2C_M_RD,
 			.len = count,
-			.buf = data,
+			.buf = buf,
 		}
 	};
 	int ret;
@@ -87,15 +104,24 @@ static int nvt_ts_read_data(struct i2c_client *client, u8 reg, u8 *data, int cou
 	return 0;
 }
 
+static const struct nvt_ts_bus_ops nvt_ts_i2c_bus_ops = {
+	.read = nvt_ts_i2c_read,
+};
+
+static int nvt_ts_read_data(struct nvt_ts_data *data, u8 reg, u8 *buf, size_t count)
+{
+	return data->bus_ops->read(data, reg, buf, count);
+}
+
 static irqreturn_t nvt_ts_irq(int irq, void *dev_id)
 {
 	struct nvt_ts_data *data = dev_id;
-	struct device *dev = &data->client->dev;
+	struct device *dev = data->dev;
 	int i, error, slot, x, y;
 	bool active;
 	u8 *touch;
 
-	error = nvt_ts_read_data(data->client, NVT_TS_TOUCH_START, data->buf,
+	error = nvt_ts_read_data(data, NVT_TS_TOUCH_START, data->buf,
 				 data->max_touches * NVT_TS_TOUCH_SIZE);
 	if (error)
 		return IRQ_HANDLED;
@@ -147,11 +173,11 @@ static int nvt_ts_start(struct input_dev *dev)
 
 	error = regulator_bulk_enable(ARRAY_SIZE(data->regulators), data->regulators);
 	if (error) {
-		dev_err(&data->client->dev, "failed to enable regulators\n");
+		dev_err(data->dev, "failed to enable regulators\n");
 		return error;
 	}
 
-	enable_irq(data->client->irq);
+	enable_irq(data->irq);
 	gpiod_set_value_cansleep(data->reset_gpio, 0);
 
 	return 0;
@@ -161,14 +187,14 @@ static void nvt_ts_stop(struct input_dev *dev)
 {
 	struct nvt_ts_data *data = input_get_drvdata(dev);
 
-	disable_irq(data->client->irq);
+	disable_irq(data->irq);
 	gpiod_set_value_cansleep(data->reset_gpio, 1);
 	regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators);
 }
 
 static int nvt_ts_suspend(struct device *dev)
 {
-	struct nvt_ts_data *data = i2c_get_clientdata(to_i2c_client(dev));
+	struct nvt_ts_data *data = dev_get_drvdata(dev);
 
 	guard(mutex)(&data->input->mutex);
 
@@ -180,7 +206,7 @@ static int nvt_ts_suspend(struct device *dev)
 
 static int nvt_ts_resume(struct device *dev)
 {
-	struct nvt_ts_data *data = i2c_get_clientdata(to_i2c_client(dev));
+	struct nvt_ts_data *data = dev_get_drvdata(dev);
 
 	guard(mutex)(&data->input->mutex);
 
@@ -213,7 +239,9 @@ static int nvt_ts_probe(struct i2c_client *client)
 	if (!chip)
 		return -EINVAL;
 
-	data->client = client;
+	data->dev = dev;
+	data->bus_ops = &nvt_ts_i2c_bus_ops;
+	data->irq = client->irq;
 	i2c_set_clientdata(client, data);
 
 	/*
@@ -244,7 +272,7 @@ static int nvt_ts_probe(struct i2c_client *client)
 
 	/* Wait for controller to come out of reset before params read */
 	msleep(100);
-	error = nvt_ts_read_data(data->client, NVT_TS_PARAMETERS_START,
+	error = nvt_ts_read_data(data, NVT_TS_PARAMETERS_START,
 				 data->buf, NVT_TS_PARAMS_SIZE);
 	gpiod_set_value_cansleep(data->reset_gpio, 1); /* Put back in reset */
 	regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators);
@@ -292,7 +320,7 @@ static int nvt_ts_probe(struct i2c_client *client)
 	data->input = input;
 	input_set_drvdata(input, data);
 
-	error = devm_request_threaded_irq(dev, client->irq, NULL, nvt_ts_irq,
+	error = devm_request_threaded_irq(dev, data->irq, NULL, nvt_ts_irq,
 					  IRQF_ONESHOT | IRQF_NO_AUTOEN |
 						nvt_ts_irq_type[irq_type],
 					  client->name, data);
-- 
2.53.0


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

* [PATCH 2/7] Input: novatek-nvt-ts - split bus independent core out
  2026-12-02  0:31 [PATCH 1/7] Input: novatek-nvt-ts - add transport ops abstraction Qianhui Xu
@ 2026-12-02  0:31 ` Qianhui Xu
  2026-12-02  0:38   ` sashiko-bot
  2026-12-02  0:31 ` [PATCH 3/7] Input: novatek-nvt-ts - add SPI bus support Qianhui Xu
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 11+ messages in thread
From: Qianhui Xu @ 2026-12-02  0:31 UTC (permalink / raw)
  To: dmitry.torokhov, hansg
  Cc: linux-input, devicetree, linux-kernel, robh, krzk+dt, conor+dt,
	konrad.dybcio, kholk11, gchan9527

Prepare for controllers that can be wired to SPI as well as I2C: move the
link independent part (parameter parsing, event decoding, open/close, PM)
into novatek-nvt-ts-core.c, keep the I2C message construction and the
i2c_driver in novatek-nvt-ts-i2c.c, and share the private data structure
through novatek-nvt-ts.h.

The module is still built as novatek-nvt-ts.ko from the same Kconfig
symbol, so existing users see no change.

Update the MAINTAINERS file pattern to cover the new files.

Signed-off-by: Qianhui Xu <xiaqinghuan@mail.ustc.edu.cn>

---
 MAINTAINERS                                   |   2 +-
 drivers/input/touchscreen/Makefile            |   1 +
 ...novatek-nvt-ts.c => novatek-nvt-ts-core.c} | 155 +++---------------
 .../input/touchscreen/novatek-nvt-ts-i2c.c    |  82 +++++++++
 drivers/input/touchscreen/novatek-nvt-ts.h    |  80 +++++++++
 5 files changed, 184 insertions(+), 136 deletions(-)
 rename drivers/input/touchscreen/{novatek-nvt-ts.c => novatek-nvt-ts-core.c} (61%)
 create mode 100644 drivers/input/touchscreen/novatek-nvt-ts-i2c.c
 create mode 100644 drivers/input/touchscreen/novatek-nvt-ts.h

diff --git a/MAINTAINERS b/MAINTAINERS
index 84cb98ef4c498..3f04a46750971 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -19968,7 +19968,7 @@ M:	Hans de Goede <hansg@kernel.org>
 L:	linux-input@vger.kernel.org
 S:	Maintained
 F:	Documentation/devicetree/bindings/input/touchscreen/novatek,nvt-ts.yaml
-F:	drivers/input/touchscreen/novatek-nvt-ts.c
+F:	drivers/input/touchscreen/novatek-nvt-ts*
 
 NSDEPS
 M:	Matthias Maennich <maennich@google.com>
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile
index bfd9de83389d8..d7b4bae24c409 100644
--- a/drivers/input/touchscreen/Makefile
+++ b/drivers/input/touchscreen/Makefile
@@ -69,6 +69,7 @@ obj-$(CONFIG_TOUCHSCREEN_MMS114)	+= mms114.o
 obj-$(CONFIG_TOUCHSCREEN_MSG2638)	+= msg2638.o
 obj-$(CONFIG_TOUCHSCREEN_MTOUCH)	+= mtouch.o
 obj-$(CONFIG_TOUCHSCREEN_NOVATEK_NVT_TS)	+= novatek-nvt-ts.o
+novatek-nvt-ts-y := novatek-nvt-ts-core.o novatek-nvt-ts-i2c.o
 obj-$(CONFIG_TOUCHSCREEN_HP600)		+= hp680_ts_input.o
 obj-$(CONFIG_TOUCHSCREEN_HP7XX)		+= jornada720_ts.o
 obj-$(CONFIG_TOUCHSCREEN_IPAQ_MICRO)	+= ipaq-micro-ts.o
diff --git a/drivers/input/touchscreen/novatek-nvt-ts.c b/drivers/input/touchscreen/novatek-nvt-ts-core.c
similarity index 61%
rename from drivers/input/touchscreen/novatek-nvt-ts.c
rename to drivers/input/touchscreen/novatek-nvt-ts-core.c
index d1aa42533db2a..522b5e6131c9e 100644
--- a/drivers/input/touchscreen/novatek-nvt-ts.c
+++ b/drivers/input/touchscreen/novatek-nvt-ts-core.c
@@ -1,44 +1,23 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * Driver for Novatek NT11205 i2c touchscreen controller as found
- * on the Acer Iconia One 7 B1-750 tablet.
+ * Novatek NVT touchscreen controller - bus independent core
+ *
+ * The controllers this driver supports expose a flat register space and one
+ * touch event packet format; the bus attachments only provide the register
+ * read framing.
  *
  * Copyright (c) 2023 Hans de Goede <hdegoede@redhat.com>
  */
 
 #include <linux/delay.h>
-#include <linux/gpio/consumer.h>
 #include <linux/interrupt.h>
-#include <linux/i2c.h>
-#include <linux/input.h>
 #include <linux/input/mt.h>
-#include <linux/input/touchscreen.h>
 #include <linux/module.h>
+#include <linux/property.h>
 
 #include <linux/unaligned.h>
 
-#define NVT_TS_TOUCH_START		0x00
-#define NVT_TS_TOUCH_SIZE		6
-
-#define NVT_TS_PARAMETERS_START		0x78
-/* These are offsets from NVT_TS_PARAMETERS_START */
-#define NVT_TS_PARAMS_WIDTH		0x04
-#define NVT_TS_PARAMS_HEIGHT		0x06
-#define NVT_TS_PARAMS_MAX_TOUCH		0x09
-#define NVT_TS_PARAMS_MAX_BUTTONS	0x0a
-#define NVT_TS_PARAMS_IRQ_TYPE		0x0b
-#define NVT_TS_PARAMS_CHIP_ID		0x0e
-#define NVT_TS_PARAMS_SIZE		0x0f
-
-#define NVT_TS_MAX_TOUCHES		10
-#define NVT_TS_MAX_SIZE			4096
-
-#define NVT_TS_TOUCH_INVALID		0xff
-#define NVT_TS_TOUCH_SLOT_SHIFT		3
-#define NVT_TS_TOUCH_TYPE_MASK		GENMASK(2, 0)
-#define NVT_TS_TOUCH_NEW		1
-#define NVT_TS_TOUCH_UPDATE		2
-#define NVT_TS_TOUCH_RELEASE		3
+#include "novatek-nvt-ts.h"
 
 static const int nvt_ts_irq_type[4] = {
 	IRQF_TRIGGER_RISING,
@@ -47,67 +26,6 @@ static const int nvt_ts_irq_type[4] = {
 	IRQF_TRIGGER_HIGH
 };
 
-struct nvt_ts_data;
-
-/**
- * struct nvt_ts_bus_ops - transport specific operations
- * @read: read @count bytes of the controller into @buf
- *
- * The controller exposes a flat register space; transports differ only in
- * how a register read is framed on the wire.
- */
-struct nvt_ts_bus_ops {
-	int (*read)(struct nvt_ts_data *data, u8 reg, u8 *buf, size_t count);
-};
-
-struct nvt_ts_i2c_chip_data {
-	u8 chip_id;
-};
-
-struct nvt_ts_data {
-	struct device *dev;
-	const struct nvt_ts_bus_ops *bus_ops;
-	struct input_dev *input;
-	int irq;
-	struct gpio_desc *reset_gpio;
-	struct regulator_bulk_data regulators[2];
-	struct touchscreen_properties prop;
-	int max_touches;
-	u8 buf[NVT_TS_TOUCH_SIZE * NVT_TS_MAX_TOUCHES];
-};
-
-static int nvt_ts_i2c_read(struct nvt_ts_data *data, u8 reg, u8 *buf, size_t count)
-{
-	struct i2c_client *client = to_i2c_client(data->dev);
-
-	struct i2c_msg msg[2] = {
-		{
-			.addr = client->addr,
-			.len = 1,
-			.buf = &reg,
-		},
-		{
-			.addr = client->addr,
-			.flags = I2C_M_RD,
-			.len = count,
-			.buf = buf,
-		}
-	};
-	int ret;
-
-	ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg));
-	if (ret != ARRAY_SIZE(msg)) {
-		dev_err(&client->dev, "Error reading from 0x%02x: %d\n", reg, ret);
-		return (ret < 0) ? ret : -EIO;
-	}
-
-	return 0;
-}
-
-static const struct nvt_ts_bus_ops nvt_ts_i2c_bus_ops = {
-	.read = nvt_ts_i2c_read,
-};
-
 static int nvt_ts_read_data(struct nvt_ts_data *data, u8 reg, u8 *buf, size_t count)
 {
 	return data->bus_ops->read(data, reg, buf, count);
@@ -192,7 +110,7 @@ static void nvt_ts_stop(struct input_dev *dev)
 	regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators);
 }
 
-static int nvt_ts_suspend(struct device *dev)
+int nvt_ts_suspend(struct device *dev)
 {
 	struct nvt_ts_data *data = dev_get_drvdata(dev);
 
@@ -204,7 +122,7 @@ static int nvt_ts_suspend(struct device *dev)
 	return 0;
 }
 
-static int nvt_ts_resume(struct device *dev)
+int nvt_ts_resume(struct device *dev)
 {
 	struct nvt_ts_data *data = dev_get_drvdata(dev);
 
@@ -216,17 +134,15 @@ static int nvt_ts_resume(struct device *dev)
 	return 0;
 }
 
-static DEFINE_SIMPLE_DEV_PM_OPS(nvt_ts_pm_ops, nvt_ts_suspend, nvt_ts_resume);
-
-static int nvt_ts_probe(struct i2c_client *client)
+int nvt_ts_probe(struct device *dev, const struct nvt_ts_bus_ops *bus_ops,
+		 int irq, unsigned int bustype, const char *name)
 {
-	struct device *dev = &client->dev;
 	int error, width, height, irq_type;
 	struct nvt_ts_data *data;
 	const struct nvt_ts_i2c_chip_data *chip;
 	struct input_dev *input;
 
-	if (!client->irq) {
+	if (!irq) {
 		dev_err(dev, "Error no irq specified\n");
 		return -EINVAL;
 	}
@@ -235,14 +151,13 @@ static int nvt_ts_probe(struct i2c_client *client)
 	if (!data)
 		return -ENOMEM;
 
-	chip = device_get_match_data(&client->dev);
+	chip = device_get_match_data(dev);
 	if (!chip)
 		return -EINVAL;
 
 	data->dev = dev;
-	data->bus_ops = &nvt_ts_i2c_bus_ops;
-	data->irq = client->irq;
-	i2c_set_clientdata(client, data);
+	data->bus_ops = bus_ops;
+	data->irq = irq;
 
 	/*
 	 * VCC is the analog voltage supply
@@ -303,8 +218,8 @@ static int nvt_ts_probe(struct i2c_client *client)
 	if (!input)
 		return -ENOMEM;
 
-	input->name = client->name;
-	input->id.bustype = BUS_I2C;
+	input->name = name;
+	input->id.bustype = bustype;
 	input->open = nvt_ts_start;
 	input->close = nvt_ts_stop;
 
@@ -323,7 +238,7 @@ static int nvt_ts_probe(struct i2c_client *client)
 	error = devm_request_threaded_irq(dev, data->irq, NULL, nvt_ts_irq,
 					  IRQF_ONESHOT | IRQF_NO_AUTOEN |
 						nvt_ts_irq_type[irq_type],
-					  client->name, data);
+					  name, data);
 	if (error) {
 		dev_err(dev, "failed to request irq: %d\n", error);
 		return error;
@@ -338,40 +253,10 @@ static int nvt_ts_probe(struct i2c_client *client)
 	return 0;
 }
 
-static const struct nvt_ts_i2c_chip_data nvt_nt11205_ts_data = {
+const struct nvt_ts_i2c_chip_data nvt_nt11205_ts_data = {
 	.chip_id = 0x05,
 };
 
-static const struct nvt_ts_i2c_chip_data nvt_nt36672a_ts_data = {
+const struct nvt_ts_i2c_chip_data nvt_nt36672a_ts_data = {
 	.chip_id = 0x08,
 };
-
-static const struct of_device_id nvt_ts_of_match[] = {
-	{ .compatible = "novatek,nt11205-ts", .data = &nvt_nt11205_ts_data },
-	{ .compatible = "novatek,nt36672a-ts", .data = &nvt_nt36672a_ts_data },
-	{ }
-};
-MODULE_DEVICE_TABLE(of, nvt_ts_of_match);
-
-static const struct i2c_device_id nvt_ts_i2c_id[] = {
-	{ .name = "nt11205-ts", .driver_data = (unsigned long)&nvt_nt11205_ts_data },
-	{ .name = "nt36672a-ts", .driver_data = (unsigned long)&nvt_nt36672a_ts_data },
-	{ }
-};
-MODULE_DEVICE_TABLE(i2c, nvt_ts_i2c_id);
-
-static struct i2c_driver nvt_ts_driver = {
-	.driver = {
-		.name	= "novatek-nvt-ts",
-		.pm	= pm_sleep_ptr(&nvt_ts_pm_ops),
-		.of_match_table = nvt_ts_of_match,
-	},
-	.probe = nvt_ts_probe,
-	.id_table = nvt_ts_i2c_id,
-};
-
-module_i2c_driver(nvt_ts_driver);
-
-MODULE_DESCRIPTION("Novatek NT11205 touchscreen driver");
-MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
-MODULE_LICENSE("GPL");
diff --git a/drivers/input/touchscreen/novatek-nvt-ts-i2c.c b/drivers/input/touchscreen/novatek-nvt-ts-i2c.c
new file mode 100644
index 0000000000000..6cb97416a1e62
--- /dev/null
+++ b/drivers/input/touchscreen/novatek-nvt-ts-i2c.c
@@ -0,0 +1,82 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Driver for Novatek NT11205 i2c touchscreen controller as found
+ * on the Acer Iconia One 7 B1-750 tablet.
+ *
+ * Copyright (c) 2023 Hans de Goede <hdegoede@redhat.com>
+ */
+
+#include <linux/i2c.h>
+#include <linux/module.h>
+
+#include "novatek-nvt-ts.h"
+
+static int nvt_ts_i2c_read(struct nvt_ts_data *data, u8 reg, u8 *buf, size_t count)
+{
+	struct i2c_client *client = to_i2c_client(data->dev);
+
+	struct i2c_msg msg[2] = {
+		{
+			.addr = client->addr,
+			.len = 1,
+			.buf = &reg,
+		},
+		{
+			.addr = client->addr,
+			.flags = I2C_M_RD,
+			.len = count,
+			.buf = buf,
+		}
+	};
+	int ret;
+
+	ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg));
+	if (ret != ARRAY_SIZE(msg)) {
+		dev_err(&client->dev, "Error reading from 0x%02x: %d\n", reg, ret);
+		return (ret < 0) ? ret : -EIO;
+	}
+
+	return 0;
+}
+
+static const struct nvt_ts_bus_ops nvt_ts_i2c_bus_ops = {
+	.read = nvt_ts_i2c_read,
+};
+
+static int nvt_ts_i2c_probe(struct i2c_client *client)
+{
+	return nvt_ts_probe(&client->dev, &nvt_ts_i2c_bus_ops, client->irq,
+			    BUS_I2C, client->name);
+}
+
+static const struct of_device_id nvt_ts_of_match[] = {
+	{ .compatible = "novatek,nt11205-ts", .data = &nvt_nt11205_ts_data },
+	{ .compatible = "novatek,nt36672a-ts", .data = &nvt_nt36672a_ts_data },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, nvt_ts_of_match);
+
+static const struct i2c_device_id nvt_ts_i2c_id[] = {
+	{ .name = "nt11205-ts", .driver_data = (unsigned long)&nvt_nt11205_ts_data },
+	{ .name = "nt36672a-ts", .driver_data = (unsigned long)&nvt_nt36672a_ts_data },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, nvt_ts_i2c_id);
+
+static DEFINE_SIMPLE_DEV_PM_OPS(nvt_ts_pm_ops, nvt_ts_suspend, nvt_ts_resume);
+
+static struct i2c_driver nvt_ts_driver = {
+	.driver = {
+		.name	= "novatek-nvt-ts",
+		.pm	= pm_sleep_ptr(&nvt_ts_pm_ops),
+		.of_match_table = nvt_ts_of_match,
+	},
+	.probe = nvt_ts_i2c_probe,
+	.id_table = nvt_ts_i2c_id,
+};
+
+module_i2c_driver(nvt_ts_driver);
+
+MODULE_DESCRIPTION("Novatek NT11205 touchscreen driver");
+MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
+MODULE_LICENSE("GPL");
diff --git a/drivers/input/touchscreen/novatek-nvt-ts.h b/drivers/input/touchscreen/novatek-nvt-ts.h
new file mode 100644
index 0000000000000..5e795a9101ac5
--- /dev/null
+++ b/drivers/input/touchscreen/novatek-nvt-ts.h
@@ -0,0 +1,80 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Novatek NVT touchscreen controller - shared definitions
+ *
+ * The controllers supported by this driver expose a flat register space and
+ * one touch event packet format; buses only differ in register read framing.
+ */
+
+#ifndef _NOVATEK_NVT_TS_H
+#define _NOVATEK_NVT_TS_H
+
+#include <linux/device.h>
+#include <linux/gpio/consumer.h>
+#include <linux/input.h>
+#include <linux/input/touchscreen.h>
+#include <linux/regulator/consumer.h>
+#include <linux/types.h>
+
+#define NVT_TS_TOUCH_START		0x00
+#define NVT_TS_TOUCH_SIZE		6
+
+#define NVT_TS_PARAMETERS_START		0x78
+/* These are offsets from NVT_TS_PARAMETERS_START */
+#define NVT_TS_PARAMS_WIDTH		0x04
+#define NVT_TS_PARAMS_HEIGHT		0x06
+#define NVT_TS_PARAMS_MAX_TOUCH		0x09
+#define NVT_TS_PARAMS_MAX_BUTTONS	0x0a
+#define NVT_TS_PARAMS_IRQ_TYPE		0x0b
+#define NVT_TS_PARAMS_CHIP_ID		0x0e
+#define NVT_TS_PARAMS_SIZE		0x0f
+
+#define NVT_TS_MAX_TOUCHES		10
+#define NVT_TS_MAX_SIZE			4096
+
+#define NVT_TS_TOUCH_INVALID		0xff
+#define NVT_TS_TOUCH_SLOT_SHIFT		3
+#define NVT_TS_TOUCH_TYPE_MASK		GENMASK(2, 0)
+#define NVT_TS_TOUCH_NEW		1
+#define NVT_TS_TOUCH_UPDATE		2
+#define NVT_TS_TOUCH_RELEASE		3
+
+struct nvt_ts_data;
+
+/**
+ * struct nvt_ts_bus_ops - transport specific operations
+ * @read: read @count bytes of the controller into @buf
+ *
+ * The controller exposes a flat register space; transports differ only in
+ * how a register read is framed on the wire.
+ */
+struct nvt_ts_bus_ops {
+	int (*read)(struct nvt_ts_data *data, u8 reg, u8 *buf, size_t count);
+};
+
+struct nvt_ts_i2c_chip_data {
+	u8 chip_id;
+};
+
+struct nvt_ts_data {
+	struct device *dev;
+	const struct nvt_ts_bus_ops *bus_ops;
+	struct input_dev *input;
+	int irq;
+	struct gpio_desc *reset_gpio;
+	struct regulator_bulk_data regulators[2];
+	struct touchscreen_properties prop;
+	int max_touches;
+	u8 buf[NVT_TS_TOUCH_SIZE * NVT_TS_MAX_TOUCHES];
+};
+
+int nvt_ts_probe(struct device *dev, const struct nvt_ts_bus_ops *bus_ops,
+		 int irq, unsigned int bustype, const char *name);
+
+int nvt_ts_suspend(struct device *dev);
+int nvt_ts_resume(struct device *dev);
+
+extern const struct nvt_ts_i2c_chip_data nvt_nt11205_ts_data;
+extern const struct nvt_ts_i2c_chip_data nvt_nt36672a_ts_data;
+
+#endif /* _NOVATEK_NVT_TS_H */
-- 
2.53.0


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

* [PATCH 3/7] Input: novatek-nvt-ts - add SPI bus support
  2026-12-02  0:31 [PATCH 1/7] Input: novatek-nvt-ts - add transport ops abstraction Qianhui Xu
  2026-12-02  0:31 ` [PATCH 2/7] Input: novatek-nvt-ts - split bus independent core out Qianhui Xu
@ 2026-12-02  0:31 ` Qianhui Xu
  2026-12-02  0:44   ` sashiko-bot
  2026-12-02  0:31 ` [PATCH 4/7] dt-bindings: input: novatek,nvt-ts - allow SPI wiring Qianhui Xu
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 11+ messages in thread
From: Qianhui Xu @ 2026-12-02  0:31 UTC (permalink / raw)
  To: dmitry.torokhov, hansg
  Cc: linux-input, devicetree, linux-kernel, robh, krzk+dt, conor+dt,
	konrad.dybcio, kholk11, gchan9527

Some boards wire the same controllers to SPI instead of I2C. Add an
spi_driver that reuses the bus independent core: the register address byte
is followed
by one dummy byte and the payload is clocked out afterwards, so a read is a
single spi_write_then_read() message.

Since the core is now shared between the I2C and the SPI module, build it
as a separate hidden Kconfig symbol (TOUCHSCREEN_NOVATEK_NVT_TS_CORE) that
is selected
by both, and export the probe, the PM callbacks and the per chip data.

The I2C module name and its Kconfig symbol are unchanged.

Signed-off-by: Qianhui Xu <xiaqinghuan@mail.ustc.edu.cn>

---
 drivers/input/touchscreen/Kconfig             | 16 +++++
 drivers/input/touchscreen/Makefile            |  4 +-
 .../input/touchscreen/novatek-nvt-ts-core.c   |  9 +++
 .../input/touchscreen/novatek-nvt-ts-spi.c    | 71 +++++++++++++++++++
 4 files changed, 99 insertions(+), 1 deletion(-)
 create mode 100644 drivers/input/touchscreen/novatek-nvt-ts-spi.c

diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
index 9b9ae8ac3f7fd..9a276729a1630 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -691,9 +691,13 @@ config TOUCHSCREEN_MTOUCH
 	  To compile this driver as a module, choose M here: the
 	  module will be called mtouch.
 
+config TOUCHSCREEN_NOVATEK_NVT_TS_CORE
+	tristate
+
 config TOUCHSCREEN_NOVATEK_NVT_TS
 	tristate "Novatek NT11205 touchscreen support"
 	depends on I2C
+	select TOUCHSCREEN_NOVATEK_NVT_TS_CORE
 	help
 	  Say Y here if you have a Novatek NT11205 touchscreen.
 	  If unsure, say N.
@@ -701,6 +705,18 @@ config TOUCHSCREEN_NOVATEK_NVT_TS
 	  To compile this driver as a module, choose M here: the
 	  module will be called novatek-nvt-ts.
 
+config TOUCHSCREEN_NOVATEK_NVT_TS_SPI
+	tristate "Novatek NVT touchscreen SPI interface"
+	depends on SPI_MASTER
+	select TOUCHSCREEN_NOVATEK_NVT_TS_CORE
+	help
+	  Say Y here if you have a Novatek NVT touchscreen controller
+	  connected to your system over SPI.
+	  If unsure, say N.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called novatek-nvt-ts-spi.
+
 config TOUCHSCREEN_IMAGIS
 	tristate "Imagis touchscreen support"
 	depends on I2C
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile
index d7b4bae24c409..9656a21759865 100644
--- a/drivers/input/touchscreen/Makefile
+++ b/drivers/input/touchscreen/Makefile
@@ -68,8 +68,10 @@ obj-$(CONFIG_TOUCHSCREEN_MIGOR)		+= migor_ts.o
 obj-$(CONFIG_TOUCHSCREEN_MMS114)	+= mms114.o
 obj-$(CONFIG_TOUCHSCREEN_MSG2638)	+= msg2638.o
 obj-$(CONFIG_TOUCHSCREEN_MTOUCH)	+= mtouch.o
+obj-$(CONFIG_TOUCHSCREEN_NOVATEK_NVT_TS_CORE)	+= novatek-nvt-ts-core.o
 obj-$(CONFIG_TOUCHSCREEN_NOVATEK_NVT_TS)	+= novatek-nvt-ts.o
-novatek-nvt-ts-y := novatek-nvt-ts-core.o novatek-nvt-ts-i2c.o
+novatek-nvt-ts-y := novatek-nvt-ts-i2c.o
+obj-$(CONFIG_TOUCHSCREEN_NOVATEK_NVT_TS_SPI)	+= novatek-nvt-ts-spi.o
 obj-$(CONFIG_TOUCHSCREEN_HP600)		+= hp680_ts_input.o
 obj-$(CONFIG_TOUCHSCREEN_HP7XX)		+= jornada720_ts.o
 obj-$(CONFIG_TOUCHSCREEN_IPAQ_MICRO)	+= ipaq-micro-ts.o
diff --git a/drivers/input/touchscreen/novatek-nvt-ts-core.c b/drivers/input/touchscreen/novatek-nvt-ts-core.c
index 522b5e6131c9e..227dc7eaed929 100644
--- a/drivers/input/touchscreen/novatek-nvt-ts-core.c
+++ b/drivers/input/touchscreen/novatek-nvt-ts-core.c
@@ -121,6 +121,7 @@ int nvt_ts_suspend(struct device *dev)
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(nvt_ts_suspend);
 
 int nvt_ts_resume(struct device *dev)
 {
@@ -133,6 +134,7 @@ int nvt_ts_resume(struct device *dev)
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(nvt_ts_resume);
 
 int nvt_ts_probe(struct device *dev, const struct nvt_ts_bus_ops *bus_ops,
 		 int irq, unsigned int bustype, const char *name)
@@ -252,11 +254,18 @@ int nvt_ts_probe(struct device *dev, const struct nvt_ts_bus_ops *bus_ops,
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(nvt_ts_probe);
 
 const struct nvt_ts_i2c_chip_data nvt_nt11205_ts_data = {
 	.chip_id = 0x05,
 };
+EXPORT_SYMBOL_GPL(nvt_nt11205_ts_data);
 
 const struct nvt_ts_i2c_chip_data nvt_nt36672a_ts_data = {
 	.chip_id = 0x08,
 };
+EXPORT_SYMBOL_GPL(nvt_nt36672a_ts_data);
+
+MODULE_DESCRIPTION("Novatek NVT touchscreen core driver");
+MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
+MODULE_LICENSE("GPL");
diff --git a/drivers/input/touchscreen/novatek-nvt-ts-spi.c b/drivers/input/touchscreen/novatek-nvt-ts-spi.c
new file mode 100644
index 0000000000000..42c02f99f50cd
--- /dev/null
+++ b/drivers/input/touchscreen/novatek-nvt-ts-spi.c
@@ -0,0 +1,71 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Novatek NVT touchscreen controller - SPI bus glue
+ *
+ * The controller is reachable over SPI on boards that wire the interrupt and
+ * reset lines to the SoC instead of using an I2C bus; the register space and
+ * the touch packet format are the same, only the read framing differs: the
+ * register address byte is followed by one dummy byte, then the data is
+ * clocked out.
+ */
+
+#include <linux/module.h>
+#include <linux/spi/spi.h>
+
+#include "novatek-nvt-ts.h"
+
+static int nvt_ts_spi_read(struct nvt_ts_data *data, u8 reg, u8 *buf,
+			   size_t count)
+{
+	struct spi_device *spi = to_spi_device(data->dev);
+	u8 cmd[2] = { reg & 0x7f, 0 };
+
+	/*
+	 * One message so that the chip select stays asserted between the
+	 * address/dummy bytes and the payload; spi_write_then_read() bounces
+	 * the buffers when the controller cannot DMA from them.
+	 */
+	return spi_write_then_read(spi, cmd, sizeof(cmd), buf, count);
+}
+
+static const struct nvt_ts_bus_ops nvt_ts_spi_bus_ops = {
+	.read = nvt_ts_spi_read,
+};
+
+static int nvt_ts_spi_probe(struct spi_device *spi)
+{
+	return nvt_ts_probe(&spi->dev, &nvt_ts_spi_bus_ops, spi->irq, BUS_SPI,
+			    dev_name(&spi->dev));
+}
+
+static const struct of_device_id nvt_ts_spi_of_match[] = {
+	{ .compatible = "novatek,nt11205-ts", .data = &nvt_nt11205_ts_data },
+	{ .compatible = "novatek,nt36672a-ts", .data = &nvt_nt36672a_ts_data },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, nvt_ts_spi_of_match);
+
+static const struct spi_device_id nvt_ts_spi_id[] = {
+	{ .name = "nt11205-ts", .driver_data = (unsigned long)&nvt_nt11205_ts_data },
+	{ .name = "nt36672a-ts", .driver_data = (unsigned long)&nvt_nt36672a_ts_data },
+	{ }
+};
+MODULE_DEVICE_TABLE(spi, nvt_ts_spi_id);
+
+static DEFINE_SIMPLE_DEV_PM_OPS(nvt_ts_spi_pm_ops, nvt_ts_suspend, nvt_ts_resume);
+
+static struct spi_driver nvt_ts_spi_driver = {
+	.driver = {
+		.name		= "novatek-nvt-ts-spi",
+		.pm		= pm_sleep_ptr(&nvt_ts_spi_pm_ops),
+		.of_match_table	= nvt_ts_spi_of_match,
+	},
+	.probe		= nvt_ts_spi_probe,
+	.id_table	= nvt_ts_spi_id,
+};
+
+module_spi_driver(nvt_ts_spi_driver);
+
+MODULE_DESCRIPTION("Novatek NVT touchscreen SPI driver");
+MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
+MODULE_LICENSE("GPL");
-- 
2.53.0


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

* [PATCH 4/7] dt-bindings: input: novatek,nvt-ts - allow SPI wiring
  2026-12-02  0:31 [PATCH 1/7] Input: novatek-nvt-ts - add transport ops abstraction Qianhui Xu
  2026-12-02  0:31 ` [PATCH 2/7] Input: novatek-nvt-ts - split bus independent core out Qianhui Xu
  2026-12-02  0:31 ` [PATCH 3/7] Input: novatek-nvt-ts - add SPI bus support Qianhui Xu
@ 2026-12-02  0:31 ` Qianhui Xu
  2026-12-02  0:31 ` [PATCH 5/7] Input: novatek-nvt-ts - add NT36536 packet decoding Qianhui Xu
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 11+ messages in thread
From: Qianhui Xu @ 2026-12-02  0:31 UTC (permalink / raw)
  To: dmitry.torokhov, hansg
  Cc: linux-input, devicetree, linux-kernel, robh, krzk+dt, conor+dt,
	konrad.dybcio, kholk11, gchan9527

The controllers described by this binding can be connected over SPI as well
as over I2C, so reference spi-peripheral-props.yaml and add a SPI example.

The compatible strings are unchanged: the bus is implied by the node the
touchscreen is a child of.

Signed-off-by: Qianhui Xu <xiaqinghuan@mail.ustc.edu.cn>

---
 .../input/touchscreen/novatek,nvt-ts.yaml     | 21 +++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/Documentation/devicetree/bindings/input/touchscreen/novatek,nvt-ts.yaml b/Documentation/devicetree/bindings/input/touchscreen/novatek,nvt-ts.yaml
index bd6a60486d1f1..f1992c1fb76e1 100644
--- a/Documentation/devicetree/bindings/input/touchscreen/novatek,nvt-ts.yaml
+++ b/Documentation/devicetree/bindings/input/touchscreen/novatek,nvt-ts.yaml
@@ -11,6 +11,7 @@ maintainers:
 
 allOf:
   - $ref: touchscreen.yaml#
+  - $ref: /schemas/spi/spi-peripheral-props.yaml#
 
 properties:
   compatible:
@@ -59,4 +60,24 @@ examples:
         };
     };
 
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    spi {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        touchscreen@0 {
+            compatible = "novatek,nt36672a-ts";
+            reg = <0>;
+            spi-max-frequency = <4000000>;
+            interrupts-extended = <&tlmm 31 IRQ_TYPE_EDGE_RISING>;
+            reset-gpios = <&tlmm 32 GPIO_ACTIVE_LOW>;
+            vcc-supply = <&vreg_l22a_2p85>;
+            iovcc-supply = <&vreg_l14a_1p8>;
+            touchscreen-size-x = <1080>;
+            touchscreen-size-y = <2246>;
+        };
+    };
+
 ...
-- 
2.53.0


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

* [PATCH 5/7] Input: novatek-nvt-ts - add NT36536 packet decoding
  2026-12-02  0:31 [PATCH 1/7] Input: novatek-nvt-ts - add transport ops abstraction Qianhui Xu
                   ` (2 preceding siblings ...)
  2026-12-02  0:31 ` [PATCH 4/7] dt-bindings: input: novatek,nvt-ts - allow SPI wiring Qianhui Xu
@ 2026-12-02  0:31 ` Qianhui Xu
  2026-12-02  0:46   ` sashiko-bot
  2026-12-02  0:31 ` [PATCH 6/7] dt-bindings: input: novatek,nvt-ts - add the NT36536 compatible Qianhui Xu
  2026-12-02  0:31 ` [PATCH 7/7] Input: novatek-nvt-ts - add no-flash firmware download Qianhui Xu
  5 siblings, 1 reply; 11+ messages in thread
From: Qianhui Xu @ 2026-12-02  0:31 UTC (permalink / raw)
  To: dmitry.torokhov, hansg
  Cc: linux-input, devicetree, linux-kernel, robh, krzk+dt, conor+dt,
	konrad.dybcio, kholk11, gchan9527

NT36xxx controllers differ from the NT11205 in the touch packet layout:
the payload is 108 bytes followed by a checksum byte, records start at
offset 1, coordinates are 16 bit big endian and the fifth byte of a record
holds the contact width. They also have no parameter block, so the geometry
comes from the device tree and the number of slots from the chip data.

Add a per chip report callback and move the NT11205 decoding behind it, add
the NT36xxx decoding with its packet checksum, and make the parameter block
read conditional on the chip data advertising a chip id.

The NT36536 itself is a no-flash part and needs its firmware downloaded by
the host before it reports touches; that is a separate patch, so this one
only adds the SPI match entries and the binding compatible.

Signed-off-by: Qianhui Xu <xiaqinghuan@mail.ustc.edu.cn>

---
 .../input/touchscreen/novatek-nvt-ts-core.c   | 183 +++++++++++++++---
 .../input/touchscreen/novatek-nvt-ts-spi.c    |   2 +
 drivers/input/touchscreen/novatek-nvt-ts.h    |  26 ++-
 3 files changed, 175 insertions(+), 36 deletions(-)

diff --git a/drivers/input/touchscreen/novatek-nvt-ts-core.c b/drivers/input/touchscreen/novatek-nvt-ts-core.c
index 227dc7eaed929..4303d0901c91d 100644
--- a/drivers/input/touchscreen/novatek-nvt-ts-core.c
+++ b/drivers/input/touchscreen/novatek-nvt-ts-core.c
@@ -11,6 +11,7 @@
 
 #include <linux/delay.h>
 #include <linux/interrupt.h>
+#include <linux/irq.h>
 #include <linux/input/mt.h>
 #include <linux/module.h>
 #include <linux/property.h>
@@ -31,9 +32,12 @@ static int nvt_ts_read_data(struct nvt_ts_data *data, u8 reg, u8 *buf, size_t co
 	return data->bus_ops->read(data, reg, buf, count);
 }
 
-static irqreturn_t nvt_ts_irq(int irq, void *dev_id)
+/*
+ * NT11205/NT36672A packet: one record per touch slot, 6 bytes each, 12 bit
+ * coordinates packed as x = b[1] << 4 | b[3] >> 4, y = b[2] << 4 | b[3] & 0xf.
+ */
+static int nvt_ts_report_nt11205(struct nvt_ts_data *data)
 {
-	struct nvt_ts_data *data = dev_id;
 	struct device *dev = data->dev;
 	int i, error, slot, x, y;
 	bool active;
@@ -42,7 +46,7 @@ static irqreturn_t nvt_ts_irq(int irq, void *dev_id)
 	error = nvt_ts_read_data(data, NVT_TS_TOUCH_START, data->buf,
 				 data->max_touches * NVT_TS_TOUCH_SIZE);
 	if (error)
-		return IRQ_HANDLED;
+		return error;
 
 	for (i = 0; i < data->max_touches; i++) {
 		touch = &data->buf[i * NVT_TS_TOUCH_SIZE];
@@ -81,6 +85,76 @@ static irqreturn_t nvt_ts_irq(int irq, void *dev_id)
 	input_mt_sync_frame(data->input);
 	input_sync(data->input);
 
+	return 0;
+}
+
+/*
+ * NT36xxx checksum: the byte at NVT_TS_NT36XXX_CHECKSUM is the two's
+ * complement of the sum of the first 64 payload bytes.
+ */
+static bool nvt_ts_nt36xxx_checksum_ok(const u8 *buf)
+{
+	u8 sum = 0;
+	int i;
+
+	for (i = 1; i < NVT_TS_NT36XXX_CHECKSUM; i++)
+		sum += buf[i];
+
+	return (u8)(~sum + 1) == buf[NVT_TS_NT36XXX_CHECKSUM];
+}
+
+/*
+ * NT36xxx packet: 108 bytes of payload plus a checksum, records start at
+ * offset 1, coordinates are 16 bit big endian and b[5] carries the width.
+ */
+static int nvt_ts_report_nt36xxx(struct nvt_ts_data *data)
+{
+	struct device *dev = data->dev;
+	int i, error;
+
+	error = nvt_ts_read_data(data, NVT_TS_TOUCH_START, data->buf,
+				 NVT_TS_NT36XXX_PACKET_SIZE);
+	if (error)
+		return error;
+
+	if (!nvt_ts_nt36xxx_checksum_ok(data->buf)) {
+		dev_dbg(dev, "bad touch packet checksum\n");
+		return -EIO;
+	}
+
+	for (i = 0; i < data->max_touches; i++) {
+		const u8 *touch = &data->buf[1 + i * NVT_TS_TOUCH_SIZE];
+		u8 state = FIELD_GET(NVT_TS_TOUCH_TYPE_MASK, touch[0]);
+		unsigned int id = (touch[0] >> NVT_TS_TOUCH_SLOT_SHIFT) - 1;
+		unsigned int x, y, width;
+
+		if (state != NVT_TS_TOUCH_NEW && state != NVT_TS_TOUCH_UPDATE)
+			continue;
+		if (id >= data->max_touches)
+			continue;
+
+		x = get_unaligned_be16(&touch[1]);
+		y = get_unaligned_be16(&touch[3]);
+		width = touch[5] ?: 1;
+
+		input_mt_slot(data->input, id);
+		input_mt_report_slot_state(data->input, MT_TOOL_FINGER, true);
+		touchscreen_report_pos(data->input, &data->prop, x, y, true);
+		input_report_abs(data->input, ABS_MT_TOUCH_MAJOR, width);
+	}
+
+	input_mt_sync_frame(data->input);
+	input_sync(data->input);
+
+	return 0;
+}
+
+static irqreturn_t nvt_ts_irq(int irq, void *dev_id)
+{
+	struct nvt_ts_data *data = dev_id;
+
+	data->chip->report_touches(data);
+
 	return IRQ_HANDLED;
 }
 
@@ -139,9 +213,10 @@ EXPORT_SYMBOL_GPL(nvt_ts_resume);
 int nvt_ts_probe(struct device *dev, const struct nvt_ts_bus_ops *bus_ops,
 		 int irq, unsigned int bustype, const char *name)
 {
+	unsigned long irq_flags;
 	int error, width, height, irq_type;
 	struct nvt_ts_data *data;
-	const struct nvt_ts_i2c_chip_data *chip;
+	const struct nvt_ts_chip_data *chip;
 	struct input_dev *input;
 
 	if (!irq) {
@@ -159,6 +234,7 @@ int nvt_ts_probe(struct device *dev, const struct nvt_ts_bus_ops *bus_ops,
 
 	data->dev = dev;
 	data->bus_ops = bus_ops;
+	data->chip = chip;
 	data->irq = irq;
 
 	/*
@@ -189,33 +265,52 @@ int nvt_ts_probe(struct device *dev, const struct nvt_ts_bus_ops *bus_ops,
 
 	/* Wait for controller to come out of reset before params read */
 	msleep(100);
-	error = nvt_ts_read_data(data, NVT_TS_PARAMETERS_START,
-				 data->buf, NVT_TS_PARAMS_SIZE);
+
+	width = 0;
+	height = 0;
+	irq_type = -1;
+
+	if (chip->chip_id) {
+		/*
+		 * NT11205/NT36672A describe themselves: geometry, slot count
+		 * and interrupt type all come from the parameter block.
+		 */
+		error = nvt_ts_read_data(data, NVT_TS_PARAMETERS_START,
+					 data->buf, NVT_TS_PARAMS_SIZE);
+		if (error)
+			goto out_power_down;
+
+		width = get_unaligned_be16(&data->buf[NVT_TS_PARAMS_WIDTH]);
+		height = get_unaligned_be16(&data->buf[NVT_TS_PARAMS_HEIGHT]);
+		data->max_touches = data->buf[NVT_TS_PARAMS_MAX_TOUCH];
+		irq_type = data->buf[NVT_TS_PARAMS_IRQ_TYPE];
+
+		if (width > NVT_TS_MAX_SIZE || height >= NVT_TS_MAX_SIZE ||
+		    data->max_touches > NVT_TS_MAX_TOUCHES ||
+		    irq_type >= ARRAY_SIZE(nvt_ts_irq_type) ||
+		    data->buf[NVT_TS_PARAMS_CHIP_ID] != chip->chip_id) {
+			dev_err(dev, "Unsupported touchscreen parameters: %*ph\n",
+				NVT_TS_PARAMS_SIZE, data->buf);
+			error = -EIO;
+			goto out_power_down;
+		}
+
+		dev_dbg(dev, "Detected %dx%d touchscreen with %d max touches\n",
+			width, height, data->max_touches);
+
+		if (data->buf[NVT_TS_PARAMS_MAX_BUTTONS])
+			dev_warn(dev, "Touchscreen buttons are not supported\n");
+	} else {
+		/* No parameter block: geometry comes from DT, slots from chip data */
+		data->max_touches = chip->max_touches;
+	}
+
+out_power_down:
 	gpiod_set_value_cansleep(data->reset_gpio, 1); /* Put back in reset */
 	regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators);
 	if (error)
 		return error;
 
-	width  = get_unaligned_be16(&data->buf[NVT_TS_PARAMS_WIDTH]);
-	height = get_unaligned_be16(&data->buf[NVT_TS_PARAMS_HEIGHT]);
-	data->max_touches = data->buf[NVT_TS_PARAMS_MAX_TOUCH];
-	irq_type = data->buf[NVT_TS_PARAMS_IRQ_TYPE];
-
-	if (width > NVT_TS_MAX_SIZE || height >= NVT_TS_MAX_SIZE ||
-	    data->max_touches > NVT_TS_MAX_TOUCHES ||
-	    irq_type >= ARRAY_SIZE(nvt_ts_irq_type) ||
-	    data->buf[NVT_TS_PARAMS_CHIP_ID] != chip->chip_id) {
-		dev_err(dev, "Unsupported touchscreen parameters: %*ph\n",
-			NVT_TS_PARAMS_SIZE, data->buf);
-		return -EIO;
-	}
-
-	dev_dbg(dev, "Detected %dx%d touchscreen with %d max touches\n",
-		width, height, data->max_touches);
-
-	if (data->buf[NVT_TS_PARAMS_MAX_BUTTONS])
-		dev_warn(dev, "Touchscreen buttons are not supported\n");
-
 	input = devm_input_allocate_device(dev);
 	if (!input)
 		return -ENOMEM;
@@ -225,9 +320,17 @@ int nvt_ts_probe(struct device *dev, const struct nvt_ts_bus_ops *bus_ops,
 	input->open = nvt_ts_start;
 	input->close = nvt_ts_stop;
 
-	input_set_abs_params(input, ABS_MT_POSITION_X, 0, width - 1, 0, 0);
-	input_set_abs_params(input, ABS_MT_POSITION_Y, 0, height - 1, 0, 0);
+	if (width)
+		input_set_abs_params(input, ABS_MT_POSITION_X, 0, width - 1, 0, 0);
+	if (height)
+		input_set_abs_params(input, ABS_MT_POSITION_Y, 0, height - 1, 0, 0);
 	touchscreen_parse_properties(input, true, &data->prop);
+	if (!width)
+		input_set_abs_params(input, ABS_MT_POSITION_X, 0,
+				     data->prop.max_x - 1, 0, 0);
+	if (!height)
+		input_set_abs_params(input, ABS_MT_POSITION_Y, 0,
+				     data->prop.max_y - 1, 0, 0);
 
 	error = input_mt_init_slots(input, data->max_touches,
 				    INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED);
@@ -237,9 +340,13 @@ int nvt_ts_probe(struct device *dev, const struct nvt_ts_bus_ops *bus_ops,
 	data->input = input;
 	input_set_drvdata(input, data);
 
+	if (irq_type >= 0)
+		irq_flags = nvt_ts_irq_type[irq_type];
+	else
+		irq_flags = irq_get_trigger_type(data->irq) ?: IRQF_TRIGGER_FALLING;
+
 	error = devm_request_threaded_irq(dev, data->irq, NULL, nvt_ts_irq,
-					  IRQF_ONESHOT | IRQF_NO_AUTOEN |
-						nvt_ts_irq_type[irq_type],
+					  IRQF_ONESHOT | IRQF_NO_AUTOEN | irq_flags,
 					  name, data);
 	if (error) {
 		dev_err(dev, "failed to request irq: %d\n", error);
@@ -256,15 +363,27 @@ int nvt_ts_probe(struct device *dev, const struct nvt_ts_bus_ops *bus_ops,
 }
 EXPORT_SYMBOL_GPL(nvt_ts_probe);
 
-const struct nvt_ts_i2c_chip_data nvt_nt11205_ts_data = {
+const struct nvt_ts_chip_data nvt_nt11205_ts_data = {
 	.chip_id = 0x05,
+	.report_touches = nvt_ts_report_nt11205,
 };
 EXPORT_SYMBOL_GPL(nvt_nt11205_ts_data);
 
-const struct nvt_ts_i2c_chip_data nvt_nt36672a_ts_data = {
+const struct nvt_ts_chip_data nvt_nt36672a_ts_data = {
 	.chip_id = 0x08,
+	.report_touches = nvt_ts_report_nt11205,
+};
+
+/*
+ * NT36xxx parts have no parameter block and (in the no-flash variants) need
+ * their firmware downloaded by the host, so max_touches comes from here.
+ */
+const struct nvt_ts_chip_data nvt_nt36536_ts_data = {
+	.max_touches = NVT_TS_MAX_TOUCHES,
+	.report_touches = nvt_ts_report_nt36xxx,
 };
 EXPORT_SYMBOL_GPL(nvt_nt36672a_ts_data);
+EXPORT_SYMBOL_GPL(nvt_nt36536_ts_data);
 
 MODULE_DESCRIPTION("Novatek NVT touchscreen core driver");
 MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
diff --git a/drivers/input/touchscreen/novatek-nvt-ts-spi.c b/drivers/input/touchscreen/novatek-nvt-ts-spi.c
index 42c02f99f50cd..c7b36e29cb983 100644
--- a/drivers/input/touchscreen/novatek-nvt-ts-spi.c
+++ b/drivers/input/touchscreen/novatek-nvt-ts-spi.c
@@ -40,6 +40,7 @@ static int nvt_ts_spi_probe(struct spi_device *spi)
 
 static const struct of_device_id nvt_ts_spi_of_match[] = {
 	{ .compatible = "novatek,nt11205-ts", .data = &nvt_nt11205_ts_data },
+	{ .compatible = "novatek,nt36536-ts", .data = &nvt_nt36536_ts_data },
 	{ .compatible = "novatek,nt36672a-ts", .data = &nvt_nt36672a_ts_data },
 	{ }
 };
@@ -47,6 +48,7 @@ MODULE_DEVICE_TABLE(of, nvt_ts_spi_of_match);
 
 static const struct spi_device_id nvt_ts_spi_id[] = {
 	{ .name = "nt11205-ts", .driver_data = (unsigned long)&nvt_nt11205_ts_data },
+	{ .name = "nt36536-ts", .driver_data = (unsigned long)&nvt_nt36536_ts_data },
 	{ .name = "nt36672a-ts", .driver_data = (unsigned long)&nvt_nt36672a_ts_data },
 	{ }
 };
diff --git a/drivers/input/touchscreen/novatek-nvt-ts.h b/drivers/input/touchscreen/novatek-nvt-ts.h
index 5e795a9101ac5..0c661fbd6377a 100644
--- a/drivers/input/touchscreen/novatek-nvt-ts.h
+++ b/drivers/input/touchscreen/novatek-nvt-ts.h
@@ -32,6 +32,13 @@
 #define NVT_TS_MAX_TOUCHES		10
 #define NVT_TS_MAX_SIZE			4096
 
+/* NT36xxx reports a 108 byte packet plus a checksum at offset 65 */
+#define NVT_TS_NT36XXX_PACKET_SIZE	109
+#define NVT_TS_NT36XXX_CHECKSUM	65
+
+/* Large enough for every packet this driver reads */
+#define NVT_TS_MAX_PACKET		NVT_TS_NT36XXX_PACKET_SIZE
+
 #define NVT_TS_TOUCH_INVALID		0xff
 #define NVT_TS_TOUCH_SLOT_SHIFT		3
 #define NVT_TS_TOUCH_TYPE_MASK		GENMASK(2, 0)
@@ -52,20 +59,30 @@ struct nvt_ts_bus_ops {
 	int (*read)(struct nvt_ts_data *data, u8 reg, u8 *buf, size_t count);
 };
 
-struct nvt_ts_i2c_chip_data {
+/**
+ * struct nvt_ts_chip_data - per controller variant data
+ * @chip_id: chip id expected in the parameter block, 0 when the controller
+ *	     has no parameter block at all
+ * @max_touches: touch slots, used when there is no parameter block
+ * @report_touches: decode one touch packet into input events
+ */
+struct nvt_ts_chip_data {
 	u8 chip_id;
+	unsigned int max_touches;
+	int (*report_touches)(struct nvt_ts_data *data);
 };
 
 struct nvt_ts_data {
 	struct device *dev;
 	const struct nvt_ts_bus_ops *bus_ops;
+	const struct nvt_ts_chip_data *chip;
 	struct input_dev *input;
 	int irq;
 	struct gpio_desc *reset_gpio;
 	struct regulator_bulk_data regulators[2];
 	struct touchscreen_properties prop;
 	int max_touches;
-	u8 buf[NVT_TS_TOUCH_SIZE * NVT_TS_MAX_TOUCHES];
+	u8 buf[NVT_TS_MAX_PACKET];
 };
 
 int nvt_ts_probe(struct device *dev, const struct nvt_ts_bus_ops *bus_ops,
@@ -74,7 +91,8 @@ int nvt_ts_probe(struct device *dev, const struct nvt_ts_bus_ops *bus_ops,
 int nvt_ts_suspend(struct device *dev);
 int nvt_ts_resume(struct device *dev);
 
-extern const struct nvt_ts_i2c_chip_data nvt_nt11205_ts_data;
-extern const struct nvt_ts_i2c_chip_data nvt_nt36672a_ts_data;
+extern const struct nvt_ts_chip_data nvt_nt11205_ts_data;
+extern const struct nvt_ts_chip_data nvt_nt36672a_ts_data;
+extern const struct nvt_ts_chip_data nvt_nt36536_ts_data;
 
 #endif /* _NOVATEK_NVT_TS_H */
-- 
2.53.0


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

* [PATCH 6/7] dt-bindings: input: novatek,nvt-ts - add the NT36536 compatible
  2026-12-02  0:31 [PATCH 1/7] Input: novatek-nvt-ts - add transport ops abstraction Qianhui Xu
                   ` (3 preceding siblings ...)
  2026-12-02  0:31 ` [PATCH 5/7] Input: novatek-nvt-ts - add NT36536 packet decoding Qianhui Xu
@ 2026-12-02  0:31 ` Qianhui Xu
  2026-12-02  0:31 ` [PATCH 7/7] Input: novatek-nvt-ts - add no-flash firmware download Qianhui Xu
  5 siblings, 0 replies; 11+ messages in thread
From: Qianhui Xu @ 2026-12-02  0:31 UTC (permalink / raw)
  To: dmitry.torokhov, hansg
  Cc: linux-input, devicetree, linux-kernel, robh, krzk+dt, conor+dt,
	konrad.dybcio, kholk11, gchan9527

The NT36536 uses the same register space and SPI framing as the parts
already described here, it just reports a different touch packet layout.

Signed-off-by: Qianhui Xu <xiaqinghuan@mail.ustc.edu.cn>
---
 .../devicetree/bindings/input/touchscreen/novatek,nvt-ts.yaml    | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/input/touchscreen/novatek,nvt-ts.yaml b/Documentation/devicetree/bindings/input/touchscreen/novatek,nvt-ts.yaml
index f1992c1fb76e1..4b6b05397fee3 100644
--- a/Documentation/devicetree/bindings/input/touchscreen/novatek,nvt-ts.yaml
+++ b/Documentation/devicetree/bindings/input/touchscreen/novatek,nvt-ts.yaml
@@ -17,6 +17,7 @@ properties:
   compatible:
     enum:
       - novatek,nt11205-ts
+      - novatek,nt36536-ts
       - novatek,nt36672a-ts
 
   reg:
-- 
2.53.0


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

* [PATCH 7/7] Input: novatek-nvt-ts - add no-flash firmware download
  2026-12-02  0:31 [PATCH 1/7] Input: novatek-nvt-ts - add transport ops abstraction Qianhui Xu
                   ` (4 preceding siblings ...)
  2026-12-02  0:31 ` [PATCH 6/7] dt-bindings: input: novatek,nvt-ts - add the NT36536 compatible Qianhui Xu
@ 2026-12-02  0:31 ` Qianhui Xu
  2026-12-02  0:53   ` sashiko-bot
  5 siblings, 1 reply; 11+ messages in thread
From: Qianhui Xu @ 2026-12-02  0:31 UTC (permalink / raw)
  To: dmitry.torokhov, hansg
  Cc: linux-input, devicetree, linux-kernel, robh, krzk+dt, conor+dt,
	konrad.dybcio, kholk11, gchan9527

Controllers without on-board flash come out of reset with nothing but a
bootloader, so the host has to upload the image before they report touches.
The image is a container of up to 32 partitions, each with a file offset, a
SRAM address, a length and a CRC of the loaded data. Upload it whenever the
controller is powered up, as a no-flash part loses the firmware on power
down: identify the silicon, reset the bootloader, put the CRCs in the
checksum banks, push the partitions into SRAM in 15 KiB chunks, then assert
BOOT_RDY and wait for the reset state and the firmware info to come back.

firmware-name is optional and the image is not shipped with the kernel.
Without it the controller is used as is, which leaves a no-flash part quiet
but keeps the flash based ones working. The image seen so far is 253952
bytes in 4 partitions.

Signed-off-by: Qianhui Xu <xiaqinghuan@mail.ustc.edu.cn>
---
 .../input/touchscreen/novatek,nvt-ts.yaml     |   9 +-
 drivers/input/touchscreen/Kconfig             |   1 +
 .../input/touchscreen/novatek-nvt-ts-core.c   | 537 +++++++++++++++++-
 .../input/touchscreen/novatek-nvt-ts-spi.c    |   9 +
 drivers/input/touchscreen/novatek-nvt-ts.h    |   5 +
 5 files changed, 559 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/input/touchscreen/novatek,nvt-ts.yaml b/Documentation/devicetree/bindings/input/touchscreen/novatek,nvt-ts.yaml
index 4b6b05397fee3..0911e780d16fd 100644
--- a/Documentation/devicetree/bindings/input/touchscreen/novatek,nvt-ts.yaml
+++ b/Documentation/devicetree/bindings/input/touchscreen/novatek,nvt-ts.yaml
@@ -32,6 +32,12 @@ properties:
   vcc-supply: true
   iovcc-supply: true
 
+  firmware-name:
+    description:
+      Firmware file uploaded by the host at open time. Needed by the
+      controllers that have no on-board flash, optional otherwise, and the
+      file itself is not distributed with the kernel.
+
 required:
   - compatible
   - reg
@@ -69,13 +75,14 @@ examples:
         #size-cells = <0>;
 
         touchscreen@0 {
-            compatible = "novatek,nt36672a-ts";
+            compatible = "novatek,nt36536-ts";
             reg = <0>;
             spi-max-frequency = <4000000>;
             interrupts-extended = <&tlmm 31 IRQ_TYPE_EDGE_RISING>;
             reset-gpios = <&tlmm 32 GPIO_ACTIVE_LOW>;
             vcc-supply = <&vreg_l22a_2p85>;
             iovcc-supply = <&vreg_l14a_1p8>;
+            firmware-name = "novatek/nt36536-fw.bin";
             touchscreen-size-x = <1080>;
             touchscreen-size-y = <2246>;
         };
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
index 9a276729a1630..2b7866a1a4fc3 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -693,6 +693,7 @@ config TOUCHSCREEN_MTOUCH
 
 config TOUCHSCREEN_NOVATEK_NVT_TS_CORE
 	tristate
+	select FW_LOADER
 
 config TOUCHSCREEN_NOVATEK_NVT_TS
 	tristate "Novatek NT11205 touchscreen support"
diff --git a/drivers/input/touchscreen/novatek-nvt-ts-core.c b/drivers/input/touchscreen/novatek-nvt-ts-core.c
index 4303d0901c91d..4d374235b2bfb 100644
--- a/drivers/input/touchscreen/novatek-nvt-ts-core.c
+++ b/drivers/input/touchscreen/novatek-nvt-ts-core.c
@@ -10,11 +10,13 @@
  */
 
 #include <linux/delay.h>
+#include <linux/firmware.h>
 #include <linux/interrupt.h>
 #include <linux/irq.h>
 #include <linux/input/mt.h>
 #include <linux/module.h>
 #include <linux/property.h>
+#include <linux/slab.h>
 
 #include <linux/unaligned.h>
 
@@ -32,6 +34,12 @@ static int nvt_ts_read_data(struct nvt_ts_data *data, u8 reg, u8 *buf, size_t co
 	return data->bus_ops->read(data, reg, buf, count);
 }
 
+static int nvt_ts_write_data(struct nvt_ts_data *data, const u8 *buf,
+			     size_t count)
+{
+	return data->bus_ops->write(data, buf, count);
+}
+
 /*
  * NT11205/NT36672A packet: one record per touch slot, 6 bytes each, 12 bit
  * coordinates packed as x = b[1] << 4 | b[3] >> 4, y = b[2] << 4 | b[3] & 0xf.
@@ -158,6 +166,505 @@ static irqreturn_t nvt_ts_irq(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
+/*
+ * NT36xxx firmware download
+ *
+ * The no-flash parts come out of reset with nothing but a bootloader; the host
+ * has to upload the image into SRAM and start it. The image is a container of
+ * partitions, each with a file offset, a SRAM address, a length and a CRC of
+ * the data the bootloader ends up with.
+ */
+#define NVT_TS_FW_XFER_LEN		15360
+#define NVT_TS_FW_MAX_PARTITIONS	32
+#define NVT_TS_FW_END_FLAG_LEN		3
+#define NVT_TS_FW_PID			0x6097
+
+#define NVT_TS_FW_ENG_RESET_ADDR	0x7fff80
+#define NVT_TS_FW_TRIM_ADDR		0x1fb104
+#define NVT_TS_FW_BOOTLOADER_RST_ADDR	0x1fb43e
+#define NVT_TS_FW_BOOT_RDY_ADDR		0x1fb50d
+#define NVT_TS_FW_AUTO_COPY_ADDR	0x1fc825
+#define NVT_TS_FW_CASCADE_STRAP_ADDR	0x1fb12c
+#define NVT_TS_FW_ILM_DES_ADDR		0x1fcc30
+#define NVT_TS_FW_ILM_LENGTH_ADDR	0x1fcc34
+#define NVT_TS_FW_ILM_CRC_ADDR		0x1fcc38
+#define NVT_TS_FW_DLM_DES_ADDR		0x1fcc40
+#define NVT_TS_FW_DLM_LENGTH_ADDR	0x1fcc44
+#define NVT_TS_FW_DLM_CRC_ADDR		0x1fcc48
+#define NVT_TS_FW_EVENT_BUF_ADDR	0x130900
+
+#define NVT_TS_FW_EVENT_HOST_CMD	0x50
+#define NVT_TS_FW_EVENT_RESET_DONE	0x60
+#define NVT_TS_FW_EVENT_INFO		0x78
+#define NVT_TS_FW_RESET_STATE_MIN	0xa0
+#define NVT_TS_FW_RESET_STATE_MAX	0xaf
+
+struct nvt_ts_fw_partition {
+	u32 file_offs;
+	u32 sram_addr;
+	u32 size;
+	u32 crc;
+};
+
+static int nvt_ts_fw_set_page(struct nvt_ts_data *data, u32 addr)
+{
+	u8 buf[] = { 0xff, (addr >> 15) & 0xff, (addr >> 7) & 0xff };
+
+	return nvt_ts_write_data(data, buf, sizeof(buf));
+}
+
+static int nvt_ts_fw_write_byte(struct nvt_ts_data *data, u32 addr, u8 value)
+{
+	u8 buf[] = { (addr & 0x7f) | BIT(7), value };
+	int error;
+
+	error = nvt_ts_fw_set_page(data, addr);
+	if (error)
+		return error;
+
+	return nvt_ts_write_data(data, buf, sizeof(buf));
+}
+
+static int nvt_ts_fw_write_value(struct nvt_ts_data *data, u32 addr, u32 value,
+				 unsigned int size)
+{
+	u8 buf[] = {
+		(addr & 0x7f) | BIT(7),
+		value & 0xff,
+		(value >> 8) & 0xff,
+		(value >> 16) & 0xff,
+		(value >> 24) & 0xff,
+	};
+	int error;
+
+	error = nvt_ts_fw_set_page(data, addr);
+	if (error)
+		return error;
+
+	return nvt_ts_write_data(data, buf, size + 1);
+}
+
+static int nvt_ts_fw_read_block(struct nvt_ts_data *data, u32 addr, u8 *buf,
+				size_t count)
+{
+	int error;
+
+	error = nvt_ts_fw_set_page(data, addr);
+	if (error)
+		return error;
+
+	return nvt_ts_read_data(data, addr & 0x7f, buf, count);
+}
+
+static int nvt_ts_fw_bootloader_reset(struct nvt_ts_data *data)
+{
+	int error;
+
+	error = nvt_ts_fw_write_byte(data, NVT_TS_FW_BOOTLOADER_RST_ADDR, 0x69);
+	if (error)
+		return error;
+
+	usleep_range(5000, 5500);
+
+	return 0;
+}
+
+static int nvt_ts_fw_identify(struct nvt_ts_data *data)
+{
+	u8 trim[7] = { (NVT_TS_FW_TRIM_ADDR & 0x7f) | BIT(7) };
+	u8 strap;
+	int error;
+
+	error = nvt_ts_fw_write_byte(data, NVT_TS_FW_ENG_RESET_ADDR, 0x5a);
+	if (error)
+		return error;
+
+	usleep_range(11000, 11500);
+
+	error = nvt_ts_fw_bootloader_reset(data);
+	if (error)
+		return error;
+
+	/* The bootloader latches the trim read address from a write */
+	error = nvt_ts_fw_set_page(data, NVT_TS_FW_TRIM_ADDR);
+	if (error)
+		return error;
+
+	error = nvt_ts_write_data(data, trim, sizeof(trim));
+	if (error)
+		return error;
+
+	error = nvt_ts_read_data(data, NVT_TS_FW_TRIM_ADDR & 0x7f, trim + 1,
+				 sizeof(trim) - 1);
+	if (error)
+		return error;
+
+	dev_dbg(data->dev, "trim ID %*ph\n", (int)sizeof(trim) - 1, trim + 1);
+	/* The firmware image is only valid for this silicon */
+	if (trim[1] != 0x15 || trim[4] != 0x23 ||
+	    trim[5] != 0x65 || trim[6] != 0x03)
+		return -ENODEV;
+
+	error = nvt_ts_fw_read_block(data, NVT_TS_FW_CASCADE_STRAP_ADDR, &strap,
+				     1);
+	if (error)
+		return error;
+
+	dev_dbg(data->dev, "cascade strap %02x\n", strap);
+
+	return 0;
+}
+
+static int nvt_ts_fw_add_partition(const struct firmware *fw,
+				   struct nvt_ts_fw_partition *partitions,
+				   unsigned int *num_partitions, u32 file_offs,
+				   u32 sram_addr, u32 size, u32 crc)
+{
+	struct nvt_ts_fw_partition *partition;
+
+	if (!size)
+		return 0;
+	if (*num_partitions >= NVT_TS_FW_MAX_PARTITIONS)
+		return -E2BIG;
+	if (file_offs >= fw->size || size >= fw->size - file_offs)
+		return -EINVAL;
+	if (sram_addr > 0x7fffff || size > 0x7fffff - sram_addr)
+		return -EINVAL;
+
+	partition = &partitions[(*num_partitions)++];
+	partition->file_offs = file_offs;
+	partition->sram_addr = sram_addr;
+	partition->size = size;
+	partition->crc = crc;
+
+	return 0;
+}
+
+/*
+ * The image starts with a header that ends at the file offset stored in its
+ * first word, followed by the second header of a cascade pair. The end of the
+ * first header is marked by the only descriptor with a non-zero destination
+ * and a zero length.
+ */
+static int nvt_ts_fw_parse(const struct firmware *fw,
+			   struct nvt_ts_fw_partition *partitions,
+			   unsigned int *num_partitions, bool *cascade)
+{
+	const u8 *data = fw->data;
+	u32 header_end, limit, pos;
+	u32 file_offs, sram_addr, size, crc;
+	unsigned int i;
+	int error;
+
+	if (fw->size < 4096 ||
+	    memcmp(data + fw->size - NVT_TS_FW_END_FLAG_LEN, "NVT",
+		   NVT_TS_FW_END_FLAG_LEN))
+		return -EINVAL;
+	if (data[fw->size - 4096] + data[fw->size - 4095] != 0xff)
+		return -EINVAL;
+
+	header_end = get_unaligned_le32(data);
+	if (header_end < 0x30 || header_end > fw->size || header_end % 16)
+		return -EINVAL;
+
+	/* Overlay images need a separate DLM header parser */
+	if (data[0x28] & BIT(4))
+		return -EOPNOTSUPP;
+
+	*cascade = !!(data[0x20] & BIT(1));
+	if (*cascade && (data[0x29] & BIT(0)))
+		return -EOPNOTSUPP;
+
+	*num_partitions = 0;
+
+	limit = header_end;
+	for (pos = 0x30; pos <= header_end - 0x10; pos += 0x10) {
+		if (get_unaligned_le32(data + pos + 4) &&
+		    !get_unaligned_le32(data + pos + 8)) {
+			limit = pos + 0x10;
+			break;
+		}
+	}
+	if (*cascade && limit > header_end / 2)
+		return -EINVAL;
+
+	for (i = 0; i < 2; i++) {
+		pos = i * 12;
+		file_offs = get_unaligned_le32(data + pos);
+		sram_addr = get_unaligned_le32(data + pos + 4);
+		size = get_unaligned_le32(data + pos + 8);
+		crc = get_unaligned_le32(data + 0x18 + i * 4);
+		if (!size)
+			return -EINVAL;
+
+		error = nvt_ts_fw_add_partition(fw, partitions, num_partitions,
+						file_offs, sram_addr, size, crc);
+		if (error)
+			return error;
+	}
+
+	for (pos = 0x30; pos <= limit - 0x10; pos += 0x10) {
+		sram_addr = get_unaligned_le32(data + pos);
+		size = get_unaligned_le32(data + pos + 4);
+		file_offs = get_unaligned_le32(data + pos + 8);
+		crc = get_unaligned_le32(data + pos + 12);
+
+		error = nvt_ts_fw_add_partition(fw, partitions, num_partitions,
+						file_offs, sram_addr, size, crc);
+		if (error)
+			return error;
+	}
+
+	if (*cascade) {
+		pos = 2 * limit - 0x10;
+		sram_addr = get_unaligned_le32(data + pos);
+		size = get_unaligned_le32(data + pos + 4);
+		file_offs = get_unaligned_le32(data + pos + 8);
+		crc = get_unaligned_le32(data + pos + 12);
+		if (!size || file_offs != limit)
+			return -EINVAL;
+
+		error = nvt_ts_fw_add_partition(fw, partitions, num_partitions,
+						file_offs, sram_addr, size, crc);
+		if (error)
+			return error;
+	}
+
+	return *num_partitions >= 2 ? 0 : -EINVAL;
+}
+
+static int nvt_ts_fw_write_partition(struct nvt_ts_data *data,
+				     const struct firmware *fw,
+				     const struct nvt_ts_fw_partition *partition,
+				     u8 *xfer)
+{
+	size_t remaining = partition->size;
+	u32 file_offs = partition->file_offs;
+	u32 sram_addr = partition->sram_addr;
+	int error;
+
+	while (remaining) {
+		size_t len = min_t(size_t, remaining, NVT_TS_FW_XFER_LEN);
+
+		error = nvt_ts_fw_set_page(data, sram_addr);
+		if (error)
+			return error;
+
+		xfer[0] = (sram_addr & 0x7f) | BIT(7);
+		memcpy(xfer + 1, fw->data + file_offs, len);
+
+		error = nvt_ts_write_data(data, xfer, len + 1);
+		if (error)
+			return error;
+
+		sram_addr += len;
+		file_offs += len;
+		remaining -= len;
+	}
+
+	return 0;
+}
+
+static int nvt_ts_fw_set_crc_banks(struct nvt_ts_data *data,
+				   const struct nvt_ts_fw_partition *partitions)
+{
+	int error;
+
+	error = nvt_ts_fw_write_value(data, NVT_TS_FW_ILM_DES_ADDR,
+				      partitions[0].sram_addr, 3);
+	if (error)
+		return error;
+
+	error = nvt_ts_fw_write_value(data, NVT_TS_FW_ILM_LENGTH_ADDR,
+				      partitions[0].size, 3);
+	if (error)
+		return error;
+
+	error = nvt_ts_fw_write_value(data, NVT_TS_FW_ILM_CRC_ADDR,
+				      partitions[0].crc, 4);
+	if (error)
+		return error;
+
+	error = nvt_ts_fw_write_value(data, NVT_TS_FW_DLM_DES_ADDR,
+				      partitions[1].sram_addr, 3);
+	if (error)
+		return error;
+
+	error = nvt_ts_fw_write_value(data, NVT_TS_FW_DLM_LENGTH_ADDR,
+				      partitions[1].size, 3);
+	if (error)
+		return error;
+
+	return nvt_ts_fw_write_value(data, NVT_TS_FW_DLM_CRC_ADDR,
+				     partitions[1].crc, 4);
+}
+
+static int nvt_ts_fw_wait_auto_copy(struct nvt_ts_data *data)
+{
+	u8 status;
+	int error, retry;
+
+	for (retry = 0; retry < 200; retry++) {
+		error = nvt_ts_fw_read_block(data, NVT_TS_FW_AUTO_COPY_ADDR,
+					     &status, 1);
+		if (error)
+			return error;
+		if (!status)
+			return 0;
+
+		usleep_range(1000, 1500);
+	}
+
+	dev_err(data->dev, "auto-copy timed out, status %02x\n", status);
+
+	return -ETIMEDOUT;
+}
+
+static int nvt_ts_fw_wait_reset(struct nvt_ts_data *data)
+{
+	u8 state[5];
+	int error, retry;
+
+	for (retry = 0; retry < 100; retry++) {
+		usleep_range(10000, 11000);
+		error = nvt_ts_fw_read_block(data,
+					     NVT_TS_FW_EVENT_BUF_ADDR |
+					     NVT_TS_FW_EVENT_RESET_DONE,
+					     state, sizeof(state));
+		if (error)
+			return error;
+		if (state[0] >= NVT_TS_FW_RESET_STATE_MIN &&
+		    state[0] <= NVT_TS_FW_RESET_STATE_MAX)
+			return 0;
+	}
+
+	dev_err(data->dev, "reset state timeout: %*ph\n", (int)sizeof(state),
+		state);
+
+	return -ETIMEDOUT;
+}
+
+static int nvt_ts_fw_check_info(struct nvt_ts_data *data)
+{
+	u8 info[38];
+	u16 pid;
+	int error;
+
+	error = nvt_ts_fw_read_block(data, NVT_TS_FW_EVENT_BUF_ADDR |
+				    NVT_TS_FW_EVENT_INFO, info, sizeof(info));
+	if (error)
+		return error;
+
+	if (info[0] + info[1] != 0xff)
+		return -EIO;
+
+	pid = (info[35] << 8) | info[34];
+	dev_dbg(data->dev, "firmware %02x.%02x event protocol %02x PID %04x\n",
+		info[0], info[13], info[12], pid);
+
+	return pid == NVT_TS_FW_PID ? 0 : -ENODEV;
+}
+
+static int nvt_ts_fw_upload(struct nvt_ts_data *data,
+			    const struct firmware *fw)
+{
+	struct nvt_ts_fw_partition partitions[NVT_TS_FW_MAX_PARTITIONS] = {};
+	unsigned int num_partitions, i;
+	u8 reset_done[7] = { NVT_TS_FW_EVENT_RESET_DONE | BIT(7) };
+	u8 host_cmd[] = { NVT_TS_FW_EVENT_HOST_CMD | BIT(7), 0xae, 0 };
+	u8 *xfer;
+	bool cascade;
+	int error;
+
+	error = nvt_ts_fw_parse(fw, partitions, &num_partitions, &cascade);
+	if (error)
+		return error;
+
+	xfer = kmalloc(NVT_TS_FW_XFER_LEN + 1, GFP_KERNEL);
+	if (!xfer)
+		return -ENOMEM;
+
+	error = nvt_ts_fw_identify(data);
+	if (error)
+		goto out_free;
+
+	error = nvt_ts_fw_bootloader_reset(data);
+	if (error)
+		goto out_free;
+
+	error = nvt_ts_fw_set_crc_banks(data, partitions);
+	if (error)
+		goto out_free;
+
+	if (cascade) {
+		error = nvt_ts_fw_write_byte(data, NVT_TS_FW_AUTO_COPY_ADDR, 0x56);
+		if (error)
+			goto out_free;
+	}
+
+	for (i = 0; i < num_partitions; i++) {
+		error = nvt_ts_fw_write_partition(data, fw, &partitions[i], xfer);
+		if (error)
+			goto out_free;
+	}
+
+	if (cascade) {
+		error = nvt_ts_fw_wait_auto_copy(data);
+		if (error)
+			goto out_free;
+	}
+
+	error = nvt_ts_fw_set_page(data, NVT_TS_FW_EVENT_BUF_ADDR);
+	if (error)
+		goto out_free;
+
+	/* Clear a pending reset event, then ask for the CRC check and boot */
+	error = nvt_ts_write_data(data, reset_done, sizeof(reset_done));
+	if (error)
+		goto out_free;
+
+	error = nvt_ts_write_data(data, host_cmd, sizeof(host_cmd));
+	if (error)
+		goto out_free;
+
+	error = nvt_ts_fw_write_byte(data, NVT_TS_FW_BOOT_RDY_ADDR, 1);
+	if (error)
+		goto out_free;
+
+	error = nvt_ts_fw_wait_reset(data);
+	if (error)
+		goto out_free;
+
+	error = nvt_ts_fw_check_info(data);
+
+out_free:
+	kfree(xfer);
+
+	return error;
+}
+
+static int nvt_ts_load_firmware(struct nvt_ts_data *data)
+{
+	const struct firmware *fw;
+	int error;
+
+	if (!data->firmware_name)
+		return 0;
+
+	error = request_firmware(&fw, data->firmware_name, data->dev);
+	if (error) {
+		dev_err(data->dev, "failed to load %s: %d\n",
+			data->firmware_name, error);
+		return error;
+	}
+
+	error = nvt_ts_fw_upload(data, fw);
+
+	release_firmware(fw);
+
+	return error;
+}
+
 static int nvt_ts_start(struct input_dev *dev)
 {
 	struct nvt_ts_data *data = input_get_drvdata(dev);
@@ -169,9 +676,23 @@ static int nvt_ts_start(struct input_dev *dev)
 		return error;
 	}
 
-	enable_irq(data->irq);
 	gpiod_set_value_cansleep(data->reset_gpio, 0);
 
+	/*
+	 * A controller without on-board flash only starts reporting touches
+	 * once its firmware has been uploaded, and it loses the firmware when
+	 * it is powered down again.
+	 */
+	error = nvt_ts_load_firmware(data);
+	if (error) {
+		gpiod_set_value_cansleep(data->reset_gpio, 1);
+		regulator_bulk_disable(ARRAY_SIZE(data->regulators),
+				       data->regulators);
+		return error;
+	}
+
+	enable_irq(data->irq);
+
 	return 0;
 }
 
@@ -237,6 +758,20 @@ int nvt_ts_probe(struct device *dev, const struct nvt_ts_bus_ops *bus_ops,
 	data->chip = chip;
 	data->irq = irq;
 
+	/*
+	 * firmware-name is optional: without it the controller is used as is,
+	 * which leaves the no-flash parts without firmware and thus without
+	 * touches, but keeps the flash based ones working.
+	 */
+	error = device_property_read_string(dev, "firmware-name",
+					    &data->firmware_name);
+	if (error) {
+		data->firmware_name = NULL;
+	} else if (!bus_ops->write) {
+		dev_err(dev, "firmware-name given, but this bus cannot write\n");
+		return -EOPNOTSUPP;
+	}
+
 	/*
 	 * VCC is the analog voltage supply
 	 * IOVCC is the digital voltage supply
diff --git a/drivers/input/touchscreen/novatek-nvt-ts-spi.c b/drivers/input/touchscreen/novatek-nvt-ts-spi.c
index c7b36e29cb983..5b878695f5ac7 100644
--- a/drivers/input/touchscreen/novatek-nvt-ts-spi.c
+++ b/drivers/input/touchscreen/novatek-nvt-ts-spi.c
@@ -28,8 +28,17 @@ static int nvt_ts_spi_read(struct nvt_ts_data *data, u8 reg, u8 *buf,
 	return spi_write_then_read(spi, cmd, sizeof(cmd), buf, count);
 }
 
+static int nvt_ts_spi_write(struct nvt_ts_data *data, const u8 *buf,
+			    size_t count)
+{
+	struct spi_device *spi = to_spi_device(data->dev);
+
+	return spi_write(spi, buf, count);
+}
+
 static const struct nvt_ts_bus_ops nvt_ts_spi_bus_ops = {
 	.read = nvt_ts_spi_read,
+	.write = nvt_ts_spi_write,
 };
 
 static int nvt_ts_spi_probe(struct spi_device *spi)
diff --git a/drivers/input/touchscreen/novatek-nvt-ts.h b/drivers/input/touchscreen/novatek-nvt-ts.h
index 0c661fbd6377a..80fe85363c564 100644
--- a/drivers/input/touchscreen/novatek-nvt-ts.h
+++ b/drivers/input/touchscreen/novatek-nvt-ts.h
@@ -51,12 +51,16 @@ struct nvt_ts_data;
 /**
  * struct nvt_ts_bus_ops - transport specific operations
  * @read: read @count bytes of the controller into @buf
+ * @write: write @count bytes from @buf, the first byte of @buf being the
+ *	   register address with bit 7 set; optional, only bus attachments
+ *	   that can upload firmware implement it
  *
  * The controller exposes a flat register space; transports differ only in
  * how a register read is framed on the wire.
  */
 struct nvt_ts_bus_ops {
 	int (*read)(struct nvt_ts_data *data, u8 reg, u8 *buf, size_t count);
+	int (*write)(struct nvt_ts_data *data, const u8 *buf, size_t count);
 };
 
 /**
@@ -81,6 +85,7 @@ struct nvt_ts_data {
 	struct gpio_desc *reset_gpio;
 	struct regulator_bulk_data regulators[2];
 	struct touchscreen_properties prop;
+	const char *firmware_name;
 	int max_touches;
 	u8 buf[NVT_TS_MAX_PACKET];
 };
-- 
2.53.0


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

* Re: [PATCH 2/7] Input: novatek-nvt-ts - split bus independent core out
  2026-12-02  0:31 ` [PATCH 2/7] Input: novatek-nvt-ts - split bus independent core out Qianhui Xu
@ 2026-12-02  0:38   ` sashiko-bot
  0 siblings, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-12-02  0:38 UTC (permalink / raw)
  To: Qianhui Xu; +Cc: linux-input, devicetree, robh, conor+dt, dmitry.torokhov

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] Input: missing dev_set_drvdata() in nvt_ts_probe() causes
  suspend NULL deref
--

commit 6091ea62bfff4d047f5416c450fcaedba40ba1e3
Author: Qianhui Xu <xiaqinghuan@mail.ustc.edu.cn>

Input: novatek-nvt-ts - split bus independent core out

This commit splits the Novatek NVT touchscreen driver into a
bus-independent core and an I2C transport module.

> diff --git a/drivers/input/touchscreen/novatek-nvt-ts.c b/drivers/input/touchscreen/novatek-nvt-ts-core.c
> similarity index 61%
> rename from drivers/input/touchscreen/novatek-nvt-ts.c
> rename to drivers/input/touchscreen/novatek-nvt-ts-core.c
> index d1aa42533db2a..522b5e6131c9e 100644
> --- a/drivers/input/touchscreen/novatek-nvt-ts.c
> +++ b/drivers/input/touchscreen/novatek-nvt-ts-core.c

[ ... ]

> @@ -192,7 +110,7 @@ static void nvt_ts_stop(struct input_dev *dev)
>  	regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators);
>  }
>  
> -static int nvt_ts_suspend(struct device *dev)
> +int nvt_ts_suspend(struct device *dev)
>  {
>  	struct nvt_ts_data *data = dev_get_drvdata(dev);
>  
> @@ -204,7 +122,7 @@ static int nvt_ts_suspend(struct device *dev)
>  	return 0;
>  }
>  
> -static int nvt_ts_resume(struct device *dev)
> +int nvt_ts_resume(struct device *dev)
>  {
>  	struct nvt_ts_data *data = dev_get_drvdata(dev);
>  
> @@ -216,17 +134,15 @@ static int nvt_ts_resume(struct device *dev)
>  	return 0;
>  }
>  
> -static DEFINE_SIMPLE_DEV_PM_OPS(nvt_ts_pm_ops, nvt_ts_suspend, nvt_ts_resume);
> -
> -static int nvt_ts_probe(struct i2c_client *client)
> +int nvt_ts_probe(struct device *dev, const struct nvt_ts_bus_ops *bus_ops,
> +		 int irq, unsigned int bustype, const char *name)
>  {
> -	struct device *dev = &client->dev;
>  	int error, width, height, irq_type;
>  	struct nvt_ts_data *data;
>  	const struct nvt_ts_i2c_chip_data *chip;
>  	struct input_dev *input;
>  
> -	if (!client->irq) {
> +	if (!irq) {
>  		dev_err(dev, "Error no irq specified\n");
>  		return -EINVAL;
>  	}
> @@ -235,14 +151,13 @@ static int nvt_ts_probe(struct i2c_client *client)
>  	if (!data)
>  		return -ENOMEM;
>  
> -	chip = device_get_match_data(&client->dev);
> +	chip = device_get_match_data(dev);
>  	if (!chip)
>  		return -EINVAL;
>  
>  	data->dev = dev;
> -	data->bus_ops = &nvt_ts_i2c_bus_ops;
> -	data->irq = client->irq;
> -	i2c_set_clientdata(client, data);
> +	data->bus_ops = bus_ops;
> +	data->irq = irq;

[Severity: High]
Does removing i2c_set_clientdata(client, data) without calling
dev_set_drvdata(dev, data) cause a NULL pointer dereference in
nvt_ts_suspend() and nvt_ts_resume()?

nvt_ts_suspend() and nvt_ts_resume() fetch data via dev_get_drvdata(dev)
and immediately access &data->input->mutex, while input_set_drvdata(input,
data) later in nvt_ts_probe() only sets driver data on the child input
device.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202003159.1321846-1-xiaqinghuan@mail.ustc.edu.cn?part=2

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

* Re: [PATCH 3/7] Input: novatek-nvt-ts - add SPI bus support
  2026-12-02  0:31 ` [PATCH 3/7] Input: novatek-nvt-ts - add SPI bus support Qianhui Xu
@ 2026-12-02  0:44   ` sashiko-bot
  0 siblings, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-12-02  0:44 UTC (permalink / raw)
  To: Qianhui Xu; +Cc: linux-input, devicetree, robh, conor+dt, dmitry.torokhov

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] Input: novatek-nvt-ts: NULL deref in suspend/resume due to
  unset drvdata
- [Medium] Input: novatek-nvt-ts: broken ID-table match data lookup in
  nvt_ts_probe()
--

commit 65e783365c06ee1cad22c37ad9595fc2e94f4d65
Author: Qianhui Xu <xiaqinghuan@mail.ustc.edu.cn>

Input: novatek-nvt-ts - add SPI bus support

This commit builds the Novatek NVT touchscreen core as a separate module
and adds an SPI bus driver sharing that core.

> diff --git a/drivers/input/touchscreen/novatek-nvt-ts-spi.c b/drivers/input/touchscreen/novatek-nvt-ts-spi.c
> new file mode 100644
> index 0000000000000..42c02f99f50cd
> --- /dev/null
> +++ b/drivers/input/touchscreen/novatek-nvt-ts-spi.c
> @@ -0,0 +1,71 @@

[ ... ]

> +static int nvt_ts_spi_probe(struct spi_device *spi)
> +{
> +	return nvt_ts_probe(&spi->dev, &nvt_ts_spi_bus_ops, spi->irq, BUS_SPI,
> +			    dev_name(&spi->dev));
> +}
> +
> +static const struct of_device_id nvt_ts_spi_of_match[] = {
> +	{ .compatible = "novatek,nt11205-ts", .data = &nvt_nt11205_ts_data },
> +	{ .compatible = "novatek,nt36672a-ts", .data = &nvt_nt36672a_ts_data },
> +	{ }
> +};
> +MODULE_DEVICE_TABLE(of, nvt_ts_spi_of_match);
> +
> +static const struct spi_device_id nvt_ts_spi_id[] = {
> +	{ .name = "nt11205-ts", .driver_data = (unsigned long)&nvt_nt11205_ts_data },
> +	{ .name = "nt36672a-ts", .driver_data = (unsigned long)&nvt_nt36672a_ts_data },
> +	{ }
> +};
> +MODULE_DEVICE_TABLE(spi, nvt_ts_spi_id);

[Severity: Medium]
Will devices matched through nvt_ts_spi_id fail to probe with -EINVAL?

nvt_ts_probe() looks up the chip data with device_get_match_data(dev),
which only queries OF and ACPI fwnode match tables and returns NULL for
spi_device_id matches (unlike spi_get_device_match_data()).

> +
> +static DEFINE_SIMPLE_DEV_PM_OPS(nvt_ts_spi_pm_ops, nvt_ts_suspend, nvt_ts_resume);

[Severity: High]
Does system suspend or resume trigger a NULL pointer dereference in
nvt_ts_suspend() and nvt_ts_resume()?

drivers/input/touchscreen/novatek-nvt-ts-core.c:nvt_ts_suspend() {
	struct nvt_ts_data *data = dev_get_drvdata(dev);

	guard(mutex)(&data->input->mutex);
    ...
}

nvt_ts_probe() calls input_set_drvdata(input, data), which sets driver_data
on &input->dev, but never calls dev_set_drvdata(dev, data) on the bus
device (&spi->dev).  When the PM callbacks run for &spi->dev,
dev_get_drvdata(dev) returns NULL and accessing data->input crashes.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202003159.1321846-1-xiaqinghuan@mail.ustc.edu.cn?part=3

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

* Re: [PATCH 5/7] Input: novatek-nvt-ts - add NT36536 packet decoding
  2026-12-02  0:31 ` [PATCH 5/7] Input: novatek-nvt-ts - add NT36536 packet decoding Qianhui Xu
@ 2026-12-02  0:46   ` sashiko-bot
  0 siblings, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-12-02  0:46 UTC (permalink / raw)
  To: Qianhui Xu; +Cc: linux-input, devicetree, robh, conor+dt, dmitry.torokhov

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] Input: novatek-nvt-ts - broken X/Y axis setup in nvt_ts_probe()
- [High] Input: novatek-nvt-ts - missing dev_set_drvdata() in
  nvt_ts_probe()
- [Medium] Input: novatek-nvt-ts - missing ABS_MT_TOUCH_MAJOR setup in
  nvt_ts_probe()
--

commit 629485efc8c5bb9921461a8d9bf9ca2e03a38ccb
Author: Qianhui Xu <xiaqinghuan@mail.ustc.edu.cn>

Input: novatek-nvt-ts - add NT36536 packet decoding

This commit adds a per-chip touch report callback, implements the NT36xxx
packet decoding and checksum verification, makes reading the parameter
block conditional on chip_id, and registers SPI match entries for NT36536.

> diff --git a/drivers/input/touchscreen/novatek-nvt-ts-core.c b/drivers/input/touchscreen/novatek-nvt-ts-core.c
> index 227dc7eaed929..4303d0901c91d 100644
> --- a/drivers/input/touchscreen/novatek-nvt-ts-core.c
> +++ b/drivers/input/touchscreen/novatek-nvt-ts-core.c
[ ... ]
> +/*
> + * NT36xxx packet: 108 bytes of payload plus a checksum, records start at
> + * offset 1, coordinates are 16 bit big endian and b[5] carries the width.
> + */
> +static int nvt_ts_report_nt36xxx(struct nvt_ts_data *data)
> +{
> +	struct device *dev = data->dev;
> +	int i, error;
> +
> +	error = nvt_ts_read_data(data, NVT_TS_TOUCH_START, data->buf,
> +				 NVT_TS_NT36XXX_PACKET_SIZE);
> +	if (error)
> +		return error;
> +
> +	if (!nvt_ts_nt36xxx_checksum_ok(data->buf)) {
> +		dev_dbg(dev, "bad touch packet checksum\n");
> +		return -EIO;
> +	}
> +
> +	for (i = 0; i < data->max_touches; i++) {
> +		const u8 *touch = &data->buf[1 + i * NVT_TS_TOUCH_SIZE];
> +		u8 state = FIELD_GET(NVT_TS_TOUCH_TYPE_MASK, touch[0]);
> +		unsigned int id = (touch[0] >> NVT_TS_TOUCH_SLOT_SHIFT) - 1;
> +		unsigned int x, y, width;
> +
> +		if (state != NVT_TS_TOUCH_NEW && state != NVT_TS_TOUCH_UPDATE)
> +			continue;
> +		if (id >= data->max_touches)
> +			continue;
> +
> +		x = get_unaligned_be16(&touch[1]);
> +		y = get_unaligned_be16(&touch[3]);
> +		width = touch[5] ?: 1;
> +
> +		input_mt_slot(data->input, id);
> +		input_mt_report_slot_state(data->input, MT_TOOL_FINGER, true);
> +		touchscreen_report_pos(data->input, &data->prop, x, y, true);
> +		input_report_abs(data->input, ABS_MT_TOUCH_MAJOR, width);
> +	}

[Severity: Medium]
Does nvt_ts_probe() need to register ABS_MT_TOUCH_MAJOR with
input_set_abs_params()?  Without that, ABS_MT_TOUCH_MAJOR is not set in
data->input->absbit and the input core silently drops every contact width
event reported here.

[ ... ]

> @@ -159,6 +234,7 @@ int nvt_ts_probe(struct device *dev, const struct nvt_ts_bus_ops *bus_ops,
>  
>  	data->dev = dev;
>  	data->bus_ops = bus_ops;
> +	data->chip = chip;
>  	data->irq = irq;

[Severity: High]
Should nvt_ts_probe() call dev_set_drvdata(dev, data) here?

Only input_set_drvdata(input, data) is called later in nvt_ts_probe(),
which sets driver_data on input->dev rather than on the bus device dev.
When the system suspends or resumes, nvt_ts_suspend() and nvt_ts_resume()
call dev_get_drvdata(dev), get NULL, and dereference it at
&data->input->mutex.

[ ... ]

> @@ -225,9 +320,17 @@ int nvt_ts_probe(struct device *dev, const struct nvt_ts_bus_ops *bus_ops,
>  	input->open = nvt_ts_start;
>  	input->close = nvt_ts_stop;
>  
> -	input_set_abs_params(input, ABS_MT_POSITION_X, 0, width - 1, 0, 0);
> -	input_set_abs_params(input, ABS_MT_POSITION_Y, 0, height - 1, 0, 0);
> +	if (width)
> +		input_set_abs_params(input, ABS_MT_POSITION_X, 0, width - 1, 0, 0);
> +	if (height)
> +		input_set_abs_params(input, ABS_MT_POSITION_Y, 0, height - 1, 0, 0);
>  	touchscreen_parse_properties(input, true, &data->prop);
> +	if (!width)
> +		input_set_abs_params(input, ABS_MT_POSITION_X, 0,
> +				     data->prop.max_x - 1, 0, 0);
> +	if (!height)
> +		input_set_abs_params(input, ABS_MT_POSITION_Y, 0,
> +				     data->prop.max_y - 1, 0, 0);

[Severity: High]
Does skipping input_set_abs_params() before touchscreen_parse_properties()
leave ABS_MT_POSITION_X and ABS_MT_POSITION_Y unset when width and height
are 0?

touchscreen_parse_properties() calls touchscreen_set_params(), which
requires the axis bit to already be set in dev->absbit:

drivers/input/touchscreen.c:touchscreen_set_params() {
	if (!test_bit(axis, dev->absbit)) {
		dev_warn(&dev->dev,
			 "Parameters are specified but the axis %lu is not set up\n",
			 axis);
		return;
	}
}

For chips without a parameter block (such as NT36536), width and height
are 0, so touchscreen_set_params() warns and returns early without
configuring the axes, leaving data->prop.max_x and data->prop.max_y at 0.
The subsequent input_set_abs_params() calls then configure the X and Y
maximums as -1.  In addition, when touchscreen_parse_properties() succeeds
it already sets the axis maximums (and any minimum, fuzz, resolution, or
axis swap from DT), so calling input_set_abs_params() afterwards with
data->prop.max_x - 1 would subtract 1 a second time and overwrite those
properties; registering the capabilities with input_set_capability()
before touchscreen_parse_properties() avoids both issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202003159.1321846-1-xiaqinghuan@mail.ustc.edu.cn?part=5

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

* Re: [PATCH 7/7] Input: novatek-nvt-ts - add no-flash firmware download
  2026-12-02  0:31 ` [PATCH 7/7] Input: novatek-nvt-ts - add no-flash firmware download Qianhui Xu
@ 2026-12-02  0:53   ` sashiko-bot
  0 siblings, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-12-02  0:53 UTC (permalink / raw)
  To: Qianhui Xu; +Cc: linux-input, devicetree, robh, conor+dt, dmitry.torokhov

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] Input: novatek-nvt-ts - DMA from stack in nvt_ts_spi_write()
  callers
- [Medium] Input: novatek-nvt-ts - unbalanced IRQ/regulators if
  nvt_ts_start() fails
--

commit ba7ffce013641ae13b88a77b35356567c7d1fd3e
Author: Qianhui Xu <xiaqinghuan@mail.ustc.edu.cn>

Input: novatek-nvt-ts - add no-flash firmware download

This commit adds firmware download support for flashless Novatek
touchscreen controllers, uploading partitioned firmware images to SRAM
when the controller powers up.

> diff --git a/drivers/input/touchscreen/novatek-nvt-ts-core.c b/drivers/input/touchscreen/novatek-nvt-ts-core.c
> index 4303d0901c91d..4d374235b2bfb 100644
> --- a/drivers/input/touchscreen/novatek-nvt-ts-core.c
> +++ b/drivers/input/touchscreen/novatek-nvt-ts-core.c
[ ... ]
> @@ -169,9 +676,23 @@ static int nvt_ts_start(struct input_dev *dev)
>  		return error;
>  	}
>  
> -	enable_irq(data->irq);
>  	gpiod_set_value_cansleep(data->reset_gpio, 0);
>  
> +	/*
> +	 * A controller without on-board flash only starts reporting touches
> +	 * once its firmware has been uploaded, and it loses the firmware when
> +	 * it is powered down again.
> +	 */
> +	error = nvt_ts_load_firmware(data);
> +	if (error) {
> +		gpiod_set_value_cansleep(data->reset_gpio, 1);
> +		regulator_bulk_disable(ARRAY_SIZE(data->regulators),
> +				       data->regulators);
> +		return error;
> +	}
> +
> +	enable_irq(data->irq);
> +
>  	return 0;
>  }

[Severity: Medium]
Can a failure in nvt_ts_load_firmware() during nvt_ts_resume() unbalance
data->irq and data->regulators?

When the device is open, nvt_ts_suspend() calls nvt_ts_stop() to disable
the IRQ and regulators, and nvt_ts_resume() calls nvt_ts_start():

drivers/input/touchscreen/novatek-nvt-ts-core.c:nvt_ts_stop() {
	disable_irq(data->irq);
	gpiod_set_value_cansleep(data->reset_gpio, 1);
	regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators);
}

If nvt_ts_load_firmware() fails on resume, nvt_ts_start() disables the
regulators and returns before calling enable_irq(data->irq), while
input_device_enabled(data->input) remains true.  When the input device is
later closed or suspended again, nvt_ts_stop() runs a second time,
calling regulator_bulk_disable() on already-disabled regulators and
incrementing the IRQ disable depth to 2 so future opens can no longer
re-enable data->irq.

[ ... ]

> diff --git a/drivers/input/touchscreen/novatek-nvt-ts-spi.c b/drivers/input/touchscreen/novatek-nvt-ts-spi.c
> index c7b36e29cb983..5b878695f5ac7 100644
> --- a/drivers/input/touchscreen/novatek-nvt-ts-spi.c
> +++ b/drivers/input/touchscreen/novatek-nvt-ts-spi.c
> @@ -28,8 +28,17 @@ static int nvt_ts_spi_read(struct nvt_ts_data *data, u8 reg, u8 *buf,
>  	return spi_write_then_read(spi, cmd, sizeof(cmd), buf, count);
>  }
>  
> +static int nvt_ts_spi_write(struct nvt_ts_data *data, const u8 *buf,
> +			    size_t count)
> +{
> +	struct spi_device *spi = to_spi_device(data->dev);
> +
> +	return spi_write(spi, buf, count);
> +}

[Severity: High]
Does nvt_ts_spi_write() pass stack-allocated buffers directly to
spi_write()?

Unlike spi_write_then_read() in nvt_ts_spi_read(), spi_write() does not
bounce tx_buf and requires DMA-safe memory.  Callers in the firmware
loader such as nvt_ts_fw_set_page(), nvt_ts_fw_write_byte(),
nvt_ts_fw_write_value(), nvt_ts_fw_identify() and nvt_ts_fw_upload() pass
stack arrays (buf, trim, reset_done and host_cmd) to nvt_ts_write_data(),
which will fail DMA mapping with VMAP_STACK or corrupt stack memory on
SPI controllers that use DMA.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202003159.1321846-1-xiaqinghuan@mail.ustc.edu.cn?part=7

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

end of thread, other threads:[~2026-12-02  0:53 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02  0:31 [PATCH 1/7] Input: novatek-nvt-ts - add transport ops abstraction Qianhui Xu
2026-12-02  0:31 ` [PATCH 2/7] Input: novatek-nvt-ts - split bus independent core out Qianhui Xu
2026-12-02  0:38   ` sashiko-bot
2026-12-02  0:31 ` [PATCH 3/7] Input: novatek-nvt-ts - add SPI bus support Qianhui Xu
2026-12-02  0:44   ` sashiko-bot
2026-12-02  0:31 ` [PATCH 4/7] dt-bindings: input: novatek,nvt-ts - allow SPI wiring Qianhui Xu
2026-12-02  0:31 ` [PATCH 5/7] Input: novatek-nvt-ts - add NT36536 packet decoding Qianhui Xu
2026-12-02  0:46   ` sashiko-bot
2026-12-02  0:31 ` [PATCH 6/7] dt-bindings: input: novatek,nvt-ts - add the NT36536 compatible Qianhui Xu
2026-12-02  0:31 ` [PATCH 7/7] Input: novatek-nvt-ts - add no-flash firmware download Qianhui Xu
2026-12-02  0:53   ` sashiko-bot

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.