Devicetree
 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
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ 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] 5+ 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
       [not found] ` <20261202003159.1321846-3-xiaqinghuan@mail.ustc.edu.cn>
       [not found] ` <20261202003159.1321846-5-xiaqinghuan@mail.ustc.edu.cn>
  2 siblings, 1 reply; 5+ 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] 5+ 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; 5+ 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] 5+ messages in thread

* Re: [PATCH 3/7] Input: novatek-nvt-ts - add SPI bus support
       [not found] ` <20261202003159.1321846-3-xiaqinghuan@mail.ustc.edu.cn>
@ 2026-12-02  0:44   ` sashiko-bot
  0 siblings, 0 replies; 5+ 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] 5+ messages in thread

* Re: [PATCH 5/7] Input: novatek-nvt-ts - add NT36536 packet decoding
       [not found] ` <20261202003159.1321846-5-xiaqinghuan@mail.ustc.edu.cn>
@ 2026-12-02  0:46   ` sashiko-bot
  0 siblings, 0 replies; 5+ 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] 5+ messages in thread

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

Thread overview: 5+ 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
     [not found] ` <20261202003159.1321846-3-xiaqinghuan@mail.ustc.edu.cn>
2026-12-02  0:44   ` [PATCH 3/7] Input: novatek-nvt-ts - add SPI bus support sashiko-bot
     [not found] ` <20261202003159.1321846-5-xiaqinghuan@mail.ustc.edu.cn>
2026-12-02  0:46   ` [PATCH 5/7] Input: novatek-nvt-ts - add NT36536 packet decoding sashiko-bot

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