[PATCH v5 2/7] Input: novatek-nvt-ts - split bus independent core out
From: Qianhui Xu
Date: Wed Dec 02 2026 - 04:11:04 EST
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@xxxxxxxxxxxxxxxx>
---
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@xxxxxxxxxx>
L: linux-input@xxxxxxxxxxxxxxx
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@xxxxxxxxxx>
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@xxxxxxxxxx>
*/
#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@xxxxxxxxxx>");
-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@xxxxxxxxxx>
+ */
+
+#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@xxxxxxxxxx>");
+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 */