* [PATCH v2 1/7] Input: novatek-nvt-ts - add transport ops abstraction
@ 2026-12-02 1:05 Qianhui Xu
2026-12-02 1:05 ` [PATCH v2 2/7] Input: novatek-nvt-ts - split bus independent core out Qianhui Xu
` (5 more replies)
0 siblings, 6 replies; 10+ messages in thread
From: Qianhui Xu @ 2026-12-02 1:05 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] 10+ messages in thread
* [PATCH v2 2/7] Input: novatek-nvt-ts - split bus independent core out
2026-12-02 1:05 [PATCH v2 1/7] Input: novatek-nvt-ts - add transport ops abstraction Qianhui Xu
@ 2026-12-02 1:05 ` Qianhui Xu
2026-12-02 1:05 ` [PATCH v2 3/7] Input: novatek-nvt-ts - add SPI bus support Qianhui Xu
` (4 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Qianhui Xu @ 2026-12-02 1:05 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>
---
Changes in v2:
- set the bus device driver data with dev_set_drvdata() so that
dev_get_drvdata() in nvt_ts_suspend()/nvt_ts_resume() returns the private
data. v1 removed i2c_set_clientdata() here without a replacement and
dereferenced NULL on system suspend and resume.
- resolve the per controller data in the bus glue and pass it to the core:
device_get_match_data() only consults OF/ACPI match tables and returns
NULL for a device matched through the i2c_device_id table.
MAINTAINERS | 2 +-
drivers/input/touchscreen/Makefile | 1 +
...novatek-nvt-ts.c => novatek-nvt-ts-core.c} | 159 +++---------------
.../input/touchscreen/novatek-nvt-ts-i2c.c | 87 ++++++++++
drivers/input/touchscreen/novatek-nvt-ts.h | 81 +++++++++
5 files changed, 191 insertions(+), 139 deletions(-)
rename drivers/input/touchscreen/{novatek-nvt-ts.c => novatek-nvt-ts-core.c} (60%)
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 60%
rename from drivers/input/touchscreen/novatek-nvt-ts.c
rename to drivers/input/touchscreen/novatek-nvt-ts-core.c
index d1aa42533db2a..2f363f17e1462 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 = ®,
- },
- {
- .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,
+ const struct nvt_ts_i2c_chip_data *chip, 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,11 @@ static int nvt_ts_probe(struct i2c_client *client)
if (!data)
return -ENOMEM;
- chip = device_get_match_data(&client->dev);
- if (!chip)
- return -EINVAL;
+ dev_set_drvdata(dev, data);
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 +216,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 +236,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 +251,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..8991a0d531a45
--- /dev/null
+++ b/drivers/input/touchscreen/novatek-nvt-ts-i2c.c
@@ -0,0 +1,87 @@
+// 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 = ®,
+ },
+ {
+ .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)
+{
+ const struct nvt_ts_i2c_chip_data *chip = i2c_get_match_data(client);
+
+ if (!chip)
+ return -EINVAL;
+
+ return nvt_ts_probe(&client->dev, &nvt_ts_i2c_bus_ops, chip, 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..096f7ade4f513
--- /dev/null
+++ b/drivers/input/touchscreen/novatek-nvt-ts.h
@@ -0,0 +1,81 @@
+/* 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,
+ const struct nvt_ts_i2c_chip_data *chip, 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] 10+ messages in thread
* [PATCH v2 3/7] Input: novatek-nvt-ts - add SPI bus support
2026-12-02 1:05 [PATCH v2 1/7] Input: novatek-nvt-ts - add transport ops abstraction Qianhui Xu
2026-12-02 1:05 ` [PATCH v2 2/7] Input: novatek-nvt-ts - split bus independent core out Qianhui Xu
@ 2026-12-02 1:05 ` Qianhui Xu
2026-12-02 1:05 ` [PATCH v2 4/7] dt-bindings: input: novatek,nvt-ts - allow SPI wiring Qianhui Xu
` (3 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Qianhui Xu @ 2026-12-02 1:05 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>
---
Changes in v2: use spi_get_device_match_data() in the SPI glue and pass the
result into the core; device_get_match_data() returns NULL for a device
matched through spi_device_id, so the probe failed with -EINVAL.
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 | 76 +++++++++++++++++++
4 files changed, 104 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 2f363f17e1462..747fa8bbe3157 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,
const struct nvt_ts_i2c_chip_data *chip, int irq,
@@ -250,11 +252,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..c937e51d4b995
--- /dev/null
+++ b/drivers/input/touchscreen/novatek-nvt-ts-spi.c
@@ -0,0 +1,76 @@
+// 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)
+{
+ const struct nvt_ts_i2c_chip_data *chip = spi_get_device_match_data(spi);
+
+ if (!chip)
+ return -EINVAL;
+
+ return nvt_ts_probe(&spi->dev, &nvt_ts_spi_bus_ops, chip, 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] 10+ messages in thread
* [PATCH v2 4/7] dt-bindings: input: novatek,nvt-ts - allow SPI wiring
2026-12-02 1:05 [PATCH v2 1/7] Input: novatek-nvt-ts - add transport ops abstraction Qianhui Xu
2026-12-02 1:05 ` [PATCH v2 2/7] Input: novatek-nvt-ts - split bus independent core out Qianhui Xu
2026-12-02 1:05 ` [PATCH v2 3/7] Input: novatek-nvt-ts - add SPI bus support Qianhui Xu
@ 2026-12-02 1:05 ` Qianhui Xu
2026-12-02 1:05 ` [PATCH v2 5/7] Input: novatek-nvt-ts - add NT36536 packet decoding Qianhui Xu
` (2 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Qianhui Xu @ 2026-12-02 1:05 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] 10+ messages in thread
* [PATCH v2 5/7] Input: novatek-nvt-ts - add NT36536 packet decoding
2026-12-02 1:05 [PATCH v2 1/7] Input: novatek-nvt-ts - add transport ops abstraction Qianhui Xu
` (2 preceding siblings ...)
2026-12-02 1:05 ` [PATCH v2 4/7] dt-bindings: input: novatek,nvt-ts - allow SPI wiring Qianhui Xu
@ 2026-12-02 1:05 ` Qianhui Xu
2026-12-02 1:19 ` sashiko-bot
2026-12-02 1:05 ` [PATCH v2 6/7] dt-bindings: input: novatek,nvt-ts - add the NT36536 compatible Qianhui Xu
2026-12-02 1:05 ` [PATCH v2 7/7] Input: novatek-nvt-ts - add no-flash firmware download Qianhui Xu
5 siblings, 1 reply; 10+ messages in thread
From: Qianhui Xu @ 2026-12-02 1:05 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-i2c.c | 2 +-
.../input/touchscreen/novatek-nvt-ts-spi.c | 4 +-
drivers/input/touchscreen/novatek-nvt-ts.h | 28 ++-
4 files changed, 178 insertions(+), 39 deletions(-)
diff --git a/drivers/input/touchscreen/novatek-nvt-ts-core.c b/drivers/input/touchscreen/novatek-nvt-ts-core.c
index 747fa8bbe3157..f67170474c76e 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;
}
@@ -137,9 +211,10 @@ int nvt_ts_resume(struct device *dev)
EXPORT_SYMBOL_GPL(nvt_ts_resume);
int nvt_ts_probe(struct device *dev, const struct nvt_ts_bus_ops *bus_ops,
- const struct nvt_ts_i2c_chip_data *chip, int irq,
+ const struct nvt_ts_chip_data *chip, int irq,
unsigned int bustype, const char *name)
{
+ unsigned long irq_flags;
int error, width, height, irq_type;
struct nvt_ts_data *data;
struct input_dev *input;
@@ -157,6 +232,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;
/*
@@ -187,33 +263,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;
@@ -223,9 +318,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);
@@ -235,9 +338,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);
@@ -254,15 +361,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-i2c.c b/drivers/input/touchscreen/novatek-nvt-ts-i2c.c
index 8991a0d531a45..1dec7bbba7cec 100644
--- a/drivers/input/touchscreen/novatek-nvt-ts-i2c.c
+++ b/drivers/input/touchscreen/novatek-nvt-ts-i2c.c
@@ -45,7 +45,7 @@ static const struct nvt_ts_bus_ops nvt_ts_i2c_bus_ops = {
static int nvt_ts_i2c_probe(struct i2c_client *client)
{
- const struct nvt_ts_i2c_chip_data *chip = i2c_get_match_data(client);
+ const struct nvt_ts_chip_data *chip = i2c_get_match_data(client);
if (!chip)
return -EINVAL;
diff --git a/drivers/input/touchscreen/novatek-nvt-ts-spi.c b/drivers/input/touchscreen/novatek-nvt-ts-spi.c
index c937e51d4b995..a5939337f9fb3 100644
--- a/drivers/input/touchscreen/novatek-nvt-ts-spi.c
+++ b/drivers/input/touchscreen/novatek-nvt-ts-spi.c
@@ -34,7 +34,7 @@ static const struct nvt_ts_bus_ops nvt_ts_spi_bus_ops = {
static int nvt_ts_spi_probe(struct spi_device *spi)
{
- const struct nvt_ts_i2c_chip_data *chip = spi_get_device_match_data(spi);
+ const struct nvt_ts_chip_data *chip = spi_get_device_match_data(spi);
if (!chip)
return -EINVAL;
@@ -45,6 +45,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 },
{ }
};
@@ -52,6 +53,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 096f7ade4f513..286b96155970b 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,30 +59,41 @@ 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,
- const struct nvt_ts_i2c_chip_data *chip, int irq,
+ const struct nvt_ts_chip_data *chip, 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;
+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] 10+ messages in thread
* [PATCH v2 6/7] dt-bindings: input: novatek,nvt-ts - add the NT36536 compatible
2026-12-02 1:05 [PATCH v2 1/7] Input: novatek-nvt-ts - add transport ops abstraction Qianhui Xu
` (3 preceding siblings ...)
2026-12-02 1:05 ` [PATCH v2 5/7] Input: novatek-nvt-ts - add NT36536 packet decoding Qianhui Xu
@ 2026-12-02 1:05 ` Qianhui Xu
2026-12-02 1:15 ` sashiko-bot
2026-12-02 1:05 ` [PATCH v2 7/7] Input: novatek-nvt-ts - add no-flash firmware download Qianhui Xu
5 siblings, 1 reply; 10+ messages in thread
From: Qianhui Xu @ 2026-12-02 1:05 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] 10+ messages in thread
* [PATCH v2 7/7] Input: novatek-nvt-ts - add no-flash firmware download
2026-12-02 1:05 [PATCH v2 1/7] Input: novatek-nvt-ts - add transport ops abstraction Qianhui Xu
` (4 preceding siblings ...)
2026-12-02 1:05 ` [PATCH v2 6/7] dt-bindings: input: novatek,nvt-ts - add the NT36536 compatible Qianhui Xu
@ 2026-12-02 1:05 ` Qianhui Xu
2026-12-02 1:18 ` sashiko-bot
5 siblings, 1 reply; 10+ messages in thread
From: Qianhui Xu @ 2026-12-02 1:05 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 f67170474c76e..104028ea654c8 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;
}
@@ -235,6 +756,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 a5939337f9fb3..9039b685f7a07 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 286b96155970b..8f99a847513b8 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] 10+ messages in thread
* Re: [PATCH v2 6/7] dt-bindings: input: novatek,nvt-ts - add the NT36536 compatible
2026-12-02 1:05 ` [PATCH v2 6/7] dt-bindings: input: novatek,nvt-ts - add the NT36536 compatible Qianhui Xu
@ 2026-12-02 1:15 ` sashiko-bot
0 siblings, 0 replies; 10+ messages in thread
From: sashiko-bot @ 2026-12-02 1:15 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 DT axis setup in nvt_ts_probe()
- [High] Input: novatek-nvt-ts: missing linux/bitfield.h include for
FIELD_GET()
- [Medium] Input: novatek-nvt-ts: unregistered ABS_MT_TOUCH_MAJOR in
nvt_ts_probe()
--
commit 2354ad35fa28bbbffb01b63befc83c37b13ef941
Author: Qianhui Xu <xiaqinghuan@mail.ustc.edu.cn>
Input: novatek-nvt-ts - add NT36536 packet decoding
This commit adds packet decoding and SPI match entries for the NT36536
touchscreen controller, and makes the parameter block read in nvt_ts_probe()
conditional on chip_id.
> diff --git a/drivers/input/touchscreen/novatek-nvt-ts-core.c b/drivers/input/touchscreen/novatek-nvt-ts-core.c
> index 747fa8bbe3157..f67170474c76e 100644
> --- a/drivers/input/touchscreen/novatek-nvt-ts-core.c
> +++ b/drivers/input/touchscreen/novatek-nvt-ts-core.c
[ ... ]
> @@ -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;
> +}
> +
[ ... ]
> +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]);
[Severity: High]
Does this need to include linux/bitfield.h for FIELD_GET()? On architectures
such as x86 that do not pull it in transitively, the build fails with an
implicit function declaration.
> + 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]
Are these ABS_MT_TOUCH_MAJOR events dropped by the input core? nvt_ts_probe()
only sets up ABS_MT_POSITION_X and ABS_MT_POSITION_Y via
input_set_abs_params(), so ABS_MT_TOUCH_MAJOR is never set in input->absbit.
[ ... ]
> @@ -223,9 +318,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 touchscreen_parse_properties() fail to set up the X and Y axes when
chip->chip_id is 0?
When width and height are 0, skipping input_set_abs_params() before
touchscreen_parse_properties() leaves ABS_MT_POSITION_X and ABS_MT_POSITION_Y
unset in input->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;
}
...
}
As a result, touchscreen_parse_properties() logs a warning for both axes,
leaves data->prop.max_x and data->prop.max_y at 0, and the subsequent
input_set_abs_params() calls configure both axis maximums to -1.
Setting the capabilities with input_set_capability(input, EV_ABS,
ABS_MT_POSITION_X) and ABS_MT_POSITION_Y before touchscreen_parse_properties()
lets touchscreen_parse_properties() configure the axes directly from device
tree without calling input_set_abs_params() afterwards.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202010542.2508257-1-xiaqinghuan@mail.ustc.edu.cn?part=6
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 7/7] Input: novatek-nvt-ts - add no-flash firmware download
2026-12-02 1:05 ` [PATCH v2 7/7] Input: novatek-nvt-ts - add no-flash firmware download Qianhui Xu
@ 2026-12-02 1:18 ` sashiko-bot
0 siblings, 0 replies; 10+ messages in thread
From: sashiko-bot @ 2026-12-02 1:18 UTC (permalink / raw)
To: Qianhui Xu; +Cc: linux-input, devicetree, robh, conor+dt, dmitry.torokhov
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] Input: novatek-nvt-ts - wrong descriptor offsets in
nvt_ts_fw_parse()
- [High] Input: novatek-nvt-ts - DMA from stack in nvt_ts_spi_write()
callers
- [Medium] Input: novatek-nvt-ts - unbalanced disable in nvt_ts_stop()
after resume
- [Low] Input: novatek-nvt-ts - use __free() in firmware upload helpers
--
commit e236976afca44670bc57ab40318b3d9300e8ddbd
Author: Qianhui Xu <xiaqinghuan@mail.ustc.edu.cn>
Input: novatek-nvt-ts - add no-flash firmware download
This commit adds optional SRAM firmware download support for Novatek
touchscreen controllers without on-board flash, and implements the SPI bus
write callback.
> diff --git a/drivers/input/touchscreen/novatek-nvt-ts-core.c b/drivers/input/touchscreen/novatek-nvt-ts-core.c
> index f67170474c76e..104028ea654c8 100644
> --- a/drivers/input/touchscreen/novatek-nvt-ts-core.c
> +++ b/drivers/input/touchscreen/novatek-nvt-ts-core.c
[ ... ]
> @@ -158,6 +166,505 @@ static irqreturn_t nvt_ts_irq(int irq, void *dev_id)
> return IRQ_HANDLED;
> }
>
> +/*
> + * NT36xxx firmware download
[ ... ]
> +/*
> + * 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)
> +{
[ ... ]
> + 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);
[Severity: High]
Does the sentinel search loop check the wrong offsets for the 16-byte
descriptors starting at 0x30?
Unlike the two 12-byte descriptors at 0x00 and 0x0c, the descriptors at
0x30+ store sram_addr at pos + 0, size at pos + 4, and file_offs at pos + 8.
Checking pos + 4 and pos + 8 tests size != 0 && file_offs == 0 instead of
sram_addr != 0 && size == 0, so a sentinel descriptor with size == 0 never
matches. That leaves limit at header_end and causes all cascade firmware
images to fail the limit > header_end / 2 check with -EINVAL.
[ ... ]
> +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;
[ ... ]
> +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;
> +}
[Severity: Low]
This isn't a bug, but declaring xfer with __free(kfree) in
nvt_ts_fw_upload() and fw with __free(firmware) = NULL in
nvt_ts_load_firmware() would drop the out_free label and manual
release_firmware() call.
> +
> 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;
> }
[Severity: Medium]
Can a firmware load failure during nvt_ts_resume() cause an unbalanced
disable_irq() and regulator_bulk_disable() when nvt_ts_stop() runs later?
If the input device is open across suspend and resume, nvt_ts_suspend()
calls nvt_ts_stop(), disabling data->irq and data->regulators. If
nvt_ts_load_firmware() then fails in nvt_ts_resume() -> nvt_ts_start(),
nvt_ts_start() disables the regulators again and returns without calling
enable_irq(). Because input_device_enabled(data->input) remains true, the
next close or suspend calls nvt_ts_stop(), which disables the already
disabled regulators and increments the IRQ disable depth a second time so a
later open cannot re-enable the IRQ.
> diff --git a/drivers/input/touchscreen/novatek-nvt-ts-spi.c b/drivers/input/touchscreen/novatek-nvt-ts-spi.c
> index a5939337f9fb3..9039b685f7a07 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 calling spi_write() here perform DMA directly from the stack?
Unlike spi_write_then_read() in nvt_ts_spi_read(), spi_write() does not
bounce tx_buf and requires a DMA-safe buffer. However,
nvt_ts_fw_set_page(), nvt_ts_fw_write_byte(), nvt_ts_fw_write_value(),
nvt_ts_fw_identify(), and nvt_ts_fw_upload() all pass stack-allocated arrays
to nvt_ts_write_data(), which triggers DMA-from-stack warnings and can fail
or corrupt transfers on controllers that use DMA with vmap stacks.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202010542.2508257-1-xiaqinghuan@mail.ustc.edu.cn?part=7
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 5/7] Input: novatek-nvt-ts - add NT36536 packet decoding
2026-12-02 1:05 ` [PATCH v2 5/7] Input: novatek-nvt-ts - add NT36536 packet decoding Qianhui Xu
@ 2026-12-02 1:19 ` sashiko-bot
0 siblings, 0 replies; 10+ messages in thread
From: sashiko-bot @ 2026-12-02 1:19 UTC (permalink / raw)
To: Qianhui Xu; +Cc: linux-input, devicetree, robh, conor+dt, dmitry.torokhov
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] Input: novatek-nvt-ts - broken X/Y axis setup in nvt_ts_probe()
when chip_id is 0
- [High] Input: novatek-nvt-ts - missing linux/bitfield.h include in
novatek-nvt-ts-core.c
- [High] Input: novatek-nvt-ts: off-by-one payload offset in
nvt_ts_report_nt36xxx()
- [Medium] Input: novatek-nvt-ts - unregistered ABS_MT_TOUCH_MAJOR axis
in nvt_ts_probe()
--
commit 2354ad35fa28bbbffb01b63befc83c37b13ef941
Author: Qianhui Xu <xiaqinghuan@mail.ustc.edu.cn>
Input: novatek-nvt-ts - add NT36536 packet decoding
This commit adds a per-chip touch reporting callback, implements NT36xxx
packet decoding with checksum validation, skips reading the parameter block
when chip_id is 0, and adds 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 747fa8bbe3157..f67170474c76e 100644
> --- a/drivers/input/touchscreen/novatek-nvt-ts-core.c
> +++ b/drivers/input/touchscreen/novatek-nvt-ts-core.c
[ ... ]
> @@ -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];
[Severity: High]
Are the checksum and touch record offsets in data->buf off by one byte?
nvt_ts_spi_read() already sends the register address and dummy byte in a
separate two-byte cmd buffer via spi_write_then_read() before reading the
response into buf:
drivers/input/touchscreen/novatek-nvt-ts-spi.c:nvt_ts_spi_read() {
...
u8 cmd[2] = { reg & 0x7f, 0 };
return spi_write_then_read(spi, cmd, sizeof(cmd), buf, count);
}
The first payload byte therefore lands at data->buf[0] rather than
data->buf[1] (matching nvt_ts_report_nt11205()). Starting the checksum
loop and record decoding at index 1 skips the first byte of record 0, folds
the checksum byte at data->buf[64] into sum, compares against data->buf[65],
and shifts every touch record by one byte.
> + u8 state = FIELD_GET(NVT_TS_TOUCH_TYPE_MASK, touch[0]);
[Severity: High]
Does using FIELD_GET() here require including <linux/bitfield.h>? Neither
novatek-nvt-ts-core.c nor novatek-nvt-ts.h includes it, which breaks the
build on architectures such as x86_64 that do not pull it in transitively.
> + 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]
Are these ABS_MT_TOUCH_MAJOR events dropped by the input core?
nvt_ts_probe() never registers ABS_MT_TOUCH_MAJOR via
input_set_abs_params(), so the bit is not set in input->absbit and
input_get_disposition() ignores every reported width value.
[ ... ]
> @@ -223,9 +318,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 touchscreen_parse_properties() reject the DT geometry when chip_id is 0
(so width and height are 0)?
Inside touchscreen_parse_properties(), touchscreen_set_params() checks that
the axis bit is already set in dev->absbit before applying properties:
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;
}
...
}
Because ABS_MT_POSITION_X and ABS_MT_POSITION_Y are not enabled before
touchscreen_parse_properties(), it warns and leaves data->prop.max_x and
data->prop.max_y at 0, and the subsequent input_set_abs_params() calls set
the maximum X and Y coordinates to -1. In addition, when the axes are set
up beforehand (for example with input_set_capability(input, EV_ABS, ...)),
touchscreen_parse_properties() already configures input->absinfo with
size - 1, fuzz, resolution and axis swapping, so calling
input_set_abs_params() afterwards with data->prop.max_x - 1 would subtract 1
a second time and overwrite those properties.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202010542.2508257-1-xiaqinghuan@mail.ustc.edu.cn?part=5
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-12-02 1:19 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 1:05 [PATCH v2 1/7] Input: novatek-nvt-ts - add transport ops abstraction Qianhui Xu
2026-12-02 1:05 ` [PATCH v2 2/7] Input: novatek-nvt-ts - split bus independent core out Qianhui Xu
2026-12-02 1:05 ` [PATCH v2 3/7] Input: novatek-nvt-ts - add SPI bus support Qianhui Xu
2026-12-02 1:05 ` [PATCH v2 4/7] dt-bindings: input: novatek,nvt-ts - allow SPI wiring Qianhui Xu
2026-12-02 1:05 ` [PATCH v2 5/7] Input: novatek-nvt-ts - add NT36536 packet decoding Qianhui Xu
2026-12-02 1:19 ` sashiko-bot
2026-12-02 1:05 ` [PATCH v2 6/7] dt-bindings: input: novatek,nvt-ts - add the NT36536 compatible Qianhui Xu
2026-12-02 1:15 ` sashiko-bot
2026-12-02 1:05 ` [PATCH v2 7/7] Input: novatek-nvt-ts - add no-flash firmware download Qianhui Xu
2026-12-02 1:18 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox