* [PATCH v4 2/7] Input: novatek-nvt-ts - split bus independent core out
2026-12-02 6:14 [PATCH v4 1/7] Input: novatek-nvt-ts - add transport ops abstraction Qianhui Xu
@ 2026-12-02 6:14 ` Qianhui Xu
2026-12-02 6:14 ` [PATCH v4 3/7] Input: novatek-nvt-ts - add SPI bus support Qianhui Xu
` (4 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Qianhui Xu @ 2026-12-02 6:14 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. The reset line is optional in the
binding, so probe no longer fails on boards that reset the controller in
band.
Update the MAINTAINERS file pattern to cover the new files.
Signed-off-by: Qianhui Xu <xiaqinghuan@mail.ustc.edu.cn>
---
Changes in v3:
- make the reset GPIO optional: the binding does not require it, and these
controllers are reset in band rather than through a GPIO. A missing GPIO
is fine for gpiod_set_value_cansleep(), so the power sequences are unchanged.
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.
*** AI-assistance disclosure ***
This patch was prepared with the help of an LLM coding assistant. The
author reviewed every line, checked every quoted claim against the tree,
and ran the gates quoted in the cover letter; the design decisions and
any errors are the author's.
MAINTAINERS | 2 +-
drivers/input/touchscreen/Makefile | 1 +
...novatek-nvt-ts.c => novatek-nvt-ts-core.c} | 165 +++---------------
.../input/touchscreen/novatek-nvt-ts-i2c.c | 87 +++++++++
drivers/input/touchscreen/novatek-nvt-ts.h | 81 +++++++++
5 files changed, 196 insertions(+), 140 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..aaa121d1f963b 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
@@ -262,7 +175,11 @@ static int nvt_ts_probe(struct i2c_client *client)
return error;
}
- data->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
+ /*
+ * The reset line is optional: some boards reset the controller in band
+ * and have no such GPIO. gpiod_set_value_cansleep() ignores NULL.
+ */
+ data->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
error = PTR_ERR_OR_ZERO(data->reset_gpio);
if (error) {
regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators);
@@ -303,8 +220,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 +240,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 +255,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 */
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH v4 3/7] Input: novatek-nvt-ts - add SPI bus support
2026-12-02 6:14 [PATCH v4 1/7] Input: novatek-nvt-ts - add transport ops abstraction Qianhui Xu
2026-12-02 6:14 ` [PATCH v4 2/7] Input: novatek-nvt-ts - split bus independent core out Qianhui Xu
@ 2026-12-02 6:14 ` Qianhui Xu
2026-12-02 6:21 ` sashiko-bot
2026-12-02 6:14 ` [PATCH v4 4/7] dt-bindings: input: novatek,nvt-ts - allow SPI wiring Qianhui Xu
` (3 subsequent siblings)
5 siblings, 1 reply; 9+ messages in thread
From: Qianhui Xu @ 2026-12-02 6:14 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: a read is one full-duplex
transfer that clocks out the register address byte and one dummy byte while
the payload is clocked in behind them.
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 v3:
- read with a single full-duplex transfer instead of spi_write_then_read():
the address byte and one dummy byte are clocked out while the payload is
clocked in. Split into two transfers, the controller returns the bytes it
was sent instead of the payload.
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.
*** AI-assistance disclosure ***
This patch was prepared with the help of an LLM coding assistant. The
author reviewed every line, checked every quoted claim against the tree,
and ran the gates quoted in the cover letter; the design decisions and
any errors are the author's.
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 | 103 ++++++++++++++++++
4 files changed, 131 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 aaa121d1f963b..d0e2c8bf22157 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,
@@ -254,11 +256,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..8840e764623d3
--- /dev/null
+++ b/drivers/input/touchscreen/novatek-nvt-ts-spi.c
@@ -0,0 +1,103 @@
+// 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/slab.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);
+ struct spi_transfer xfer = { };
+ u8 *tx, *rx;
+ int error;
+
+ /*
+ * The read has to be one full-duplex transfer: the address byte and one
+ * dummy byte go out while the payload comes in. Split into a write and
+ * a read transfer the controller hands back the bytes it was sent
+ * instead of the payload.
+ *
+ * Both buffers are mapped for DMA as is, so neither the caller's buffer
+ * nor a stack buffer can be used.
+ */
+ tx = kmalloc(count + 2, GFP_KERNEL);
+ rx = kmalloc(count + 2, GFP_KERNEL);
+ if (!tx || !rx) {
+ error = -ENOMEM;
+ goto out;
+ }
+
+ memset(tx, 0, count + 2);
+ tx[0] = reg & 0x7f;
+ xfer.tx_buf = tx;
+ xfer.rx_buf = rx;
+ xfer.len = count + 2;
+
+ error = spi_sync_transfer(spi, &xfer, 1);
+ if (!error)
+ memcpy(buf, rx + 2, count);
+out:
+ kfree(rx);
+ kfree(tx);
+
+ return error;
+}
+
+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");
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH v4 3/7] Input: novatek-nvt-ts - add SPI bus support
2026-12-02 6:14 ` [PATCH v4 3/7] Input: novatek-nvt-ts - add SPI bus support Qianhui Xu
@ 2026-12-02 6:21 ` sashiko-bot
0 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-12-02 6:21 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:
- [Low] Input: novatek-nvt-ts - open-coded kzalloc() and kfree() in
nvt_ts_spi_read()
--
commit 5f4104996cb50a4abaced3ceff54734af0768c3b
Author: Qianhui Xu <xiaqinghuan@mail.ustc.edu.cn>
Input: novatek-nvt-ts - add SPI bus support
This commit adds an SPI driver for Novatek NVT touchscreen controllers and
builds the shared core as a separate Kconfig symbol.
> 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..8840e764623d3
> --- /dev/null
> +++ b/drivers/input/touchscreen/novatek-nvt-ts-spi.c
> @@ -0,0 +1,103 @@
[ ... ]
> +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);
> + struct spi_transfer xfer = { };
> + u8 *tx, *rx;
> + int error;
> +
> + /*
> + * The read has to be one full-duplex transfer: the address byte and one
> + * dummy byte go out while the payload comes in. Split into a write and
> + * a read transfer the controller hands back the bytes it was sent
> + * instead of the payload.
> + *
> + * Both buffers are mapped for DMA as is, so neither the caller's buffer
> + * nor a stack buffer can be used.
> + */
> + tx = kmalloc(count + 2, GFP_KERNEL);
> + rx = kmalloc(count + 2, GFP_KERNEL);
> + if (!tx || !rx) {
> + error = -ENOMEM;
> + goto out;
> + }
> +
> + memset(tx, 0, count + 2);
> + tx[0] = reg & 0x7f;
> + xfer.tx_buf = tx;
> + xfer.rx_buf = rx;
> + xfer.len = count + 2;
> +
> + error = spi_sync_transfer(spi, &xfer, 1);
> + if (!error)
> + memcpy(buf, rx + 2, count);
> +out:
> + kfree(rx);
> + kfree(tx);
> +
> + return error;
> +}
[Severity: Low]
This isn't a bug, but could tx and rx use __free(kfree), with tx allocated
via kzalloc() instead of kmalloc() followed by memset()? That would drop
the manual memset() and the out label.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202061414.548247-1-xiaqinghuan@mail.ustc.edu.cn?part=3
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v4 4/7] dt-bindings: input: novatek,nvt-ts - allow SPI wiring
2026-12-02 6:14 [PATCH v4 1/7] Input: novatek-nvt-ts - add transport ops abstraction Qianhui Xu
2026-12-02 6:14 ` [PATCH v4 2/7] Input: novatek-nvt-ts - split bus independent core out Qianhui Xu
2026-12-02 6:14 ` [PATCH v4 3/7] Input: novatek-nvt-ts - add SPI bus support Qianhui Xu
@ 2026-12-02 6:14 ` Qianhui Xu
2026-12-02 6:14 ` [PATCH v4 5/7] Input: novatek-nvt-ts - add NT36536 packet decoding Qianhui Xu
` (2 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Qianhui Xu @ 2026-12-02 6:14 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>
---
*** AI-assistance disclosure ***
This patch was prepared with the help of an LLM coding assistant. The
author reviewed every line, checked every quoted claim against the tree,
and ran the gates quoted in the cover letter; the design decisions and
any errors are the author's.
.../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>;
+ };
+ };
+
...
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH v4 5/7] Input: novatek-nvt-ts - add NT36536 packet decoding
2026-12-02 6:14 [PATCH v4 1/7] Input: novatek-nvt-ts - add transport ops abstraction Qianhui Xu
` (2 preceding siblings ...)
2026-12-02 6:14 ` [PATCH v4 4/7] dt-bindings: input: novatek,nvt-ts - allow SPI wiring Qianhui Xu
@ 2026-12-02 6:14 ` Qianhui Xu
2026-12-02 6:14 ` [PATCH v4 6/7] dt-bindings: input: novatek,nvt-ts - add the NT36536 compatible Qianhui Xu
2026-12-02 6:14 ` [PATCH v4 7/7] Input: novatek-nvt-ts - add no-flash firmware download Qianhui Xu
5 siblings, 0 replies; 9+ messages in thread
From: Qianhui Xu @ 2026-12-02 6:14 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 report starts with the touch records and the checksum of their first
64 bytes follows at offset 64, 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>
---
Changes in v4:
- only register ABS_MT_TOUCH_MAJOR for controllers whose packets carry the
contact width; the NT11205 and NT36672A do not report one.
- the NT36xxx report is 108 bytes, the first 64 bytes are summed up by the
byte at offset 64; read that much instead of 109 bytes.
Changes in v3:
- include <linux/bitfield.h> for FIELD_GET(); it is currently only reachable
through architecture headers, so the file does not build on x86_64.
- decode the touch records from the start of the report and checksum its
first 64 bytes: the first byte of a register read is the first report
byte, so the previous offsets shifted every record by one.
- set up ABS_MT_TOUCH_MAJOR, otherwise the input core drops the width that
the NT36xxx decoder reports.
- for controllers without a parameter block, set the X and Y capabilities
before touchscreen_parse_properties() so that the device tree geometry is
applied to them, and reject a device tree that carries none.
- keep EXPORT_SYMBOL_GPL(nvt_nt36672a_ts_data) next to its definition.
*** AI-assistance disclosure ***
This patch was prepared with the help of an LLM coding assistant. The
author reviewed every line, checked every quoted claim against the tree,
and ran the gates quoted in the cover letter; the design decisions and
any errors are the author's.
.../input/touchscreen/novatek-nvt-ts-core.c | 192 +++++++++++++++---
.../input/touchscreen/novatek-nvt-ts-i2c.c | 2 +-
.../input/touchscreen/novatek-nvt-ts-spi.c | 4 +-
drivers/input/touchscreen/novatek-nvt-ts.h | 30 ++-
4 files changed, 189 insertions(+), 39 deletions(-)
diff --git a/drivers/input/touchscreen/novatek-nvt-ts-core.c b/drivers/input/touchscreen/novatek-nvt-ts-core.c
index d0e2c8bf22157..89e7f1eaf39c9 100644
--- a/drivers/input/touchscreen/novatek-nvt-ts-core.c
+++ b/drivers/input/touchscreen/novatek-nvt-ts-core.c
@@ -9,8 +9,10 @@
* Copyright (c) 2023 Hans de Goede <hdegoede@redhat.com>
*/
+#include <linux/bitfield.h>
#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 +33,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 +47,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 +86,77 @@ 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 bytes of the report.
+ */
+static bool nvt_ts_nt36xxx_checksum_ok(const u8 *buf)
+{
+ u8 sum = 0;
+ int i;
+
+ for (i = 0; i < NVT_TS_NT36XXX_CHECKSUM; i++)
+ sum += buf[i];
+
+ return (u8)(~sum + 1) == buf[NVT_TS_NT36XXX_CHECKSUM];
+}
+
+/*
+ * NT36xxx packet: 6 byte touch records at the start of the report with the
+ * checksum at offset 64, 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[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 +213,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 +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;
/*
@@ -191,33 +269,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;
@@ -227,9 +324,23 @@ 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);
+ else
+ input_set_capability(input, EV_ABS, ABS_MT_POSITION_X);
+ if (height)
+ input_set_abs_params(input, ABS_MT_POSITION_Y, 0, height - 1, 0, 0);
+ else
+ input_set_capability(input, EV_ABS, ABS_MT_POSITION_Y);
+ if (chip->reports_width)
+ input_set_abs_params(input, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
+
touchscreen_parse_properties(input, true, &data->prop);
+ if (!input_abs_get_max(input, ABS_MT_POSITION_X) ||
+ !input_abs_get_max(input, ABS_MT_POSITION_Y)) {
+ dev_err(dev, "touchscreen-size-x and/or -y missing\n");
+ return -EINVAL;
+ }
error = input_mt_init_slots(input, data->max_touches,
INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED);
@@ -239,9 +350,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);
@@ -258,16 +373,29 @@ 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,
};
EXPORT_SYMBOL_GPL(nvt_nt36672a_ts_data);
+/*
+ * 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,
+ .reports_width = true,
+ .report_touches = nvt_ts_report_nt36xxx,
+};
+EXPORT_SYMBOL_GPL(nvt_nt36536_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-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 8840e764623d3..4691b97a7e523 100644
--- a/drivers/input/touchscreen/novatek-nvt-ts-spi.c
+++ b/drivers/input/touchscreen/novatek-nvt-ts-spi.c
@@ -61,7 +61,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;
@@ -72,6 +72,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 },
{ }
};
@@ -79,6 +80,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..7e2b207acb947 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 touch report: 108 bytes, checksum at 64 covers the first 64 */
+#define NVT_TS_NT36XXX_PACKET_SIZE 108
+#define NVT_TS_NT36XXX_CHECKSUM 64
+
+/* 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,43 @@ 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
+ * @reports_width: the packets of this controller carry the contact width
+ * @report_touches: decode one touch packet into input events
+ */
+struct nvt_ts_chip_data {
u8 chip_id;
+ unsigned int max_touches;
+ bool reports_width;
+ 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 */
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH v4 6/7] dt-bindings: input: novatek,nvt-ts - add the NT36536 compatible
2026-12-02 6:14 [PATCH v4 1/7] Input: novatek-nvt-ts - add transport ops abstraction Qianhui Xu
` (3 preceding siblings ...)
2026-12-02 6:14 ` [PATCH v4 5/7] Input: novatek-nvt-ts - add NT36536 packet decoding Qianhui Xu
@ 2026-12-02 6:14 ` Qianhui Xu
2026-12-02 6:14 ` [PATCH v4 7/7] Input: novatek-nvt-ts - add no-flash firmware download Qianhui Xu
5 siblings, 0 replies; 9+ messages in thread
From: Qianhui Xu @ 2026-12-02 6:14 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>
---
*** AI-assistance disclosure ***
This patch was prepared with the help of an LLM coding assistant. The
author reviewed every line, checked every quoted claim against the tree,
and ran the gates quoted in the cover letter; the design decisions and
any errors are the author's.
.../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:
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH v4 7/7] Input: novatek-nvt-ts - add no-flash firmware download
2026-12-02 6:14 [PATCH v4 1/7] Input: novatek-nvt-ts - add transport ops abstraction Qianhui Xu
` (4 preceding siblings ...)
2026-12-02 6:14 ` [PATCH v4 6/7] dt-bindings: input: novatek,nvt-ts - add the NT36536 compatible Qianhui Xu
@ 2026-12-02 6:14 ` Qianhui Xu
2026-12-02 6:21 ` sashiko-bot
5 siblings, 1 reply; 9+ messages in thread
From: Qianhui Xu @ 2026-12-02 6:14 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>
---
Changes in v3:
- copy the command to a DMA safe buffer in the SPI write callback:
spi_write() maps the buffer for DMA instead of bouncing it, while the
upload helpers build their commands on the stack.
- track whether the controller is powered up, so that a firmware upload that
fails in nvt_ts_start() during resume does not make the next
nvt_ts_stop() disable the regulators and the interrupt a second time.
- fix the description of the cascade marker: it is the descriptor that
copies a non-zero length from the start of the file, not one with a zero
length. The search is unchanged, a zero length descriptor is simply never
added as a partition; the marker is what locates the second header of the
cascade image we have.
- release the upload buffer and the firmware with __free() instead of the
out_free label and release_firmware().
- report an unexpected trim ID, otherwise probing fails with -ENODEV and
no message at all.
- upload the last byte of every partition: the length field in the container
is the offset of that byte, not the number of bytes, so the payload is one
byte longer than the field says. Without it the boot loader never started
the automatic copy and the upload timed out on the hardware.
*** AI-assistance disclosure ***
This patch was prepared with the help of an LLM coding assistant. The
author reviewed every line, checked every quoted claim against the tree,
and ran the gates quoted in the cover letter; the design decisions and
any errors are the author's.
.../input/touchscreen/novatek,nvt-ts.yaml | 9 +-
drivers/input/touchscreen/Kconfig | 1 +
.../input/touchscreen/novatek-nvt-ts-core.c | 542 +++++++++++++++++-
.../input/touchscreen/novatek-nvt-ts-spi.c | 24 +
drivers/input/touchscreen/novatek-nvt-ts.h | 6 +
5 files changed, 580 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 89e7f1eaf39c9..fb03ef3202622 100644
--- a/drivers/input/touchscreen/novatek-nvt-ts-core.c
+++ b/drivers/input/touchscreen/novatek-nvt-ts-core.c
@@ -11,11 +11,13 @@
#include <linux/bitfield.h>
#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>
@@ -33,6 +35,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.
@@ -160,6 +168,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;
+
+ /* The firmware image is only valid for this silicon */
+ if (trim[1] != 0x15 || trim[4] != 0x23 ||
+ trim[5] != 0x65 || trim[6] != 0x03) {
+ dev_err(data->dev, "unexpected trim ID %*ph\n",
+ (int)sizeof(trim) - 1, trim + 1);
+ 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 that describes a non-zero
+ * length copied from the start of the file.
+ */
+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)
+{
+ /*
+ * The container stores the file offset of the last byte of a
+ * partition, not its length: both headers of a cascade image are
+ * `limit` bytes long and carry limit - 1, and the length registers are
+ * programmed with the same value. Copy that last byte as well, the
+ * boot loader does not start the automatic copy without it.
+ */
+ size_t remaining = partition->size + 1;
+ 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)
+{
+ u8 *xfer __free(kfree) = NULL;
+ 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 };
+ 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)
+ return error;
+
+ error = nvt_ts_fw_bootloader_reset(data);
+ if (error)
+ return error;
+
+ error = nvt_ts_fw_set_crc_banks(data, partitions);
+ if (error)
+ return error;
+
+ if (cascade) {
+ error = nvt_ts_fw_write_byte(data, NVT_TS_FW_AUTO_COPY_ADDR, 0x56);
+ if (error)
+ return error;
+ }
+
+ for (i = 0; i < num_partitions; i++) {
+ error = nvt_ts_fw_write_partition(data, fw, &partitions[i], xfer);
+ if (error)
+ return error;
+ }
+
+ if (cascade) {
+ error = nvt_ts_fw_wait_auto_copy(data);
+ if (error)
+ return error;
+ }
+
+ error = nvt_ts_fw_set_page(data, NVT_TS_FW_EVENT_BUF_ADDR);
+ if (error)
+ return error;
+
+ /* 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)
+ return error;
+
+ error = nvt_ts_write_data(data, host_cmd, sizeof(host_cmd));
+ if (error)
+ return error;
+
+ error = nvt_ts_fw_write_byte(data, NVT_TS_FW_BOOT_RDY_ADDR, 1);
+ if (error)
+ return error;
+
+ error = nvt_ts_fw_wait_reset(data);
+ if (error)
+ return error;
+
+ return nvt_ts_fw_check_info(data);
+}
+
+static int nvt_ts_load_firmware(struct nvt_ts_data *data)
+{
+ const struct firmware *fw __free(firmware) = NULL;
+ 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;
+ }
+
+ return nvt_ts_fw_upload(data, fw);
+}
+
static int nvt_ts_start(struct input_dev *dev)
{
struct nvt_ts_data *data = input_get_drvdata(dev);
@@ -171,9 +678,24 @@ 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);
+ data->powered = true;
+
return 0;
}
@@ -181,6 +703,10 @@ static void nvt_ts_stop(struct input_dev *dev)
{
struct nvt_ts_data *data = input_get_drvdata(dev);
+ if (!data->powered)
+ return;
+
+ data->powered = false;
disable_irq(data->irq);
gpiod_set_value_cansleep(data->reset_gpio, 1);
regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators);
@@ -237,6 +763,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 4691b97a7e523..7fb36e11c68a7 100644
--- a/drivers/input/touchscreen/novatek-nvt-ts-spi.c
+++ b/drivers/input/touchscreen/novatek-nvt-ts-spi.c
@@ -55,8 +55,32 @@ static int nvt_ts_spi_read(struct nvt_ts_data *data, u8 reg, u8 *buf,
return error;
}
+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);
+ u8 *xfer;
+ int error;
+
+ /*
+ * Unlike spi_write_then_read(), spi_write() does not bounce the buffer
+ * and maps it for DMA as is, while the firmware upload helpers build
+ * their commands on the stack.
+ */
+ xfer = kmalloc(count, GFP_KERNEL);
+ if (!xfer)
+ return -ENOMEM;
+
+ memcpy(xfer, buf, count);
+ error = spi_write(spi, xfer, count);
+ kfree(xfer);
+
+ return error;
+}
+
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 7e2b207acb947..fafe394e30666 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);
};
/**
@@ -83,7 +87,9 @@ 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;
+ bool powered; /* regulators on, controller out of reset */
u8 buf[NVT_TS_MAX_PACKET];
};
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH v4 7/7] Input: novatek-nvt-ts - add no-flash firmware download
2026-12-02 6:14 ` [PATCH v4 7/7] Input: novatek-nvt-ts - add no-flash firmware download Qianhui Xu
@ 2026-12-02 6:21 ` sashiko-bot
0 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-12-02 6:21 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:
- [Low] Input: novatek-nvt-ts - define and init __free() xfer in
nvt_ts_fw_upload()
--
commit 37d2804e1f12997c5e5c4cc59ef2a593b658cd11
Author: Qianhui Xu <xiaqinghuan@mail.ustc.edu.cn>
Input: novatek-nvt-ts - add no-flash firmware download
This commit adds host-side SRAM firmware upload support for Novatek
touchscreen controllers without on-board flash.
> diff --git a/drivers/input/touchscreen/novatek-nvt-ts-core.c b/drivers/input/touchscreen/novatek-nvt-ts-core.c
> index 89e7f1eaf39c9..fb03ef3202622 100644
> --- a/drivers/input/touchscreen/novatek-nvt-ts-core.c
> +++ b/drivers/input/touchscreen/novatek-nvt-ts-core.c
[ ... ]
> @@ -160,6 +168,505 @@ static irqreturn_t nvt_ts_irq(int irq, void *dev_id)
[ ... ]
> +static int nvt_ts_fw_upload(struct nvt_ts_data *data,
> + const struct firmware *fw)
> +{
> + u8 *xfer __free(kfree) = NULL;
> + 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 };
> + 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;
[Severity: Low]
This isn't a bug, but cleanup.h conventions prefer defining and initializing
__free() variables in a single statement at the allocation site rather than
declaring xfer = NULL at the top of nvt_ts_fw_upload() and assigning it later:
u8 *xfer __free(kfree) = kmalloc(NVT_TS_FW_XFER_LEN + 1, GFP_KERNEL);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202061414.548247-1-xiaqinghuan@mail.ustc.edu.cn?part=7
^ permalink raw reply [flat|nested] 9+ messages in thread