[PATCH 3/7] Input: novatek-nvt-ts - add SPI bus support

From: Qianhui Xu

Date: Tue Dec 01 2026 - 19:32:32 EST


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@xxxxxxxxxxxxxxxx>

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

diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
index 9b9ae8ac3f7fd..9a276729a1630 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -691,9 +691,13 @@ config TOUCHSCREEN_MTOUCH
To compile this driver as a module, choose M here: the
module will be called mtouch.

+config TOUCHSCREEN_NOVATEK_NVT_TS_CORE
+ tristate
+
config TOUCHSCREEN_NOVATEK_NVT_TS
tristate "Novatek NT11205 touchscreen support"
depends on I2C
+ select TOUCHSCREEN_NOVATEK_NVT_TS_CORE
help
Say Y here if you have a Novatek NT11205 touchscreen.
If unsure, say N.
@@ -701,6 +705,18 @@ config TOUCHSCREEN_NOVATEK_NVT_TS
To compile this driver as a module, choose M here: the
module will be called novatek-nvt-ts.

+config TOUCHSCREEN_NOVATEK_NVT_TS_SPI
+ tristate "Novatek NVT touchscreen SPI interface"
+ depends on SPI_MASTER
+ select TOUCHSCREEN_NOVATEK_NVT_TS_CORE
+ help
+ Say Y here if you have a Novatek NVT touchscreen controller
+ connected to your system over SPI.
+ If unsure, say N.
+
+ To compile this driver as a module, choose M here: the
+ module will be called novatek-nvt-ts-spi.
+
config TOUCHSCREEN_IMAGIS
tristate "Imagis touchscreen support"
depends on I2C
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile
index d7b4bae24c409..9656a21759865 100644
--- a/drivers/input/touchscreen/Makefile
+++ b/drivers/input/touchscreen/Makefile
@@ -68,8 +68,10 @@ obj-$(CONFIG_TOUCHSCREEN_MIGOR) += migor_ts.o
obj-$(CONFIG_TOUCHSCREEN_MMS114) += mms114.o
obj-$(CONFIG_TOUCHSCREEN_MSG2638) += msg2638.o
obj-$(CONFIG_TOUCHSCREEN_MTOUCH) += mtouch.o
+obj-$(CONFIG_TOUCHSCREEN_NOVATEK_NVT_TS_CORE) += novatek-nvt-ts-core.o
obj-$(CONFIG_TOUCHSCREEN_NOVATEK_NVT_TS) += novatek-nvt-ts.o
-novatek-nvt-ts-y := novatek-nvt-ts-core.o novatek-nvt-ts-i2c.o
+novatek-nvt-ts-y := novatek-nvt-ts-i2c.o
+obj-$(CONFIG_TOUCHSCREEN_NOVATEK_NVT_TS_SPI) += novatek-nvt-ts-spi.o
obj-$(CONFIG_TOUCHSCREEN_HP600) += hp680_ts_input.o
obj-$(CONFIG_TOUCHSCREEN_HP7XX) += jornada720_ts.o
obj-$(CONFIG_TOUCHSCREEN_IPAQ_MICRO) += ipaq-micro-ts.o
diff --git a/drivers/input/touchscreen/novatek-nvt-ts-core.c b/drivers/input/touchscreen/novatek-nvt-ts-core.c
index 522b5e6131c9e..227dc7eaed929 100644
--- a/drivers/input/touchscreen/novatek-nvt-ts-core.c
+++ b/drivers/input/touchscreen/novatek-nvt-ts-core.c
@@ -121,6 +121,7 @@ int nvt_ts_suspend(struct device *dev)

return 0;
}
+EXPORT_SYMBOL_GPL(nvt_ts_suspend);

int nvt_ts_resume(struct device *dev)
{
@@ -133,6 +134,7 @@ int nvt_ts_resume(struct device *dev)

return 0;
}
+EXPORT_SYMBOL_GPL(nvt_ts_resume);

int nvt_ts_probe(struct device *dev, const struct nvt_ts_bus_ops *bus_ops,
int irq, unsigned int bustype, const char *name)
@@ -252,11 +254,18 @@ int nvt_ts_probe(struct device *dev, const struct nvt_ts_bus_ops *bus_ops,

return 0;
}
+EXPORT_SYMBOL_GPL(nvt_ts_probe);

const struct nvt_ts_i2c_chip_data nvt_nt11205_ts_data = {
.chip_id = 0x05,
};
+EXPORT_SYMBOL_GPL(nvt_nt11205_ts_data);

const struct nvt_ts_i2c_chip_data nvt_nt36672a_ts_data = {
.chip_id = 0x08,
};
+EXPORT_SYMBOL_GPL(nvt_nt36672a_ts_data);
+
+MODULE_DESCRIPTION("Novatek NVT touchscreen core driver");
+MODULE_AUTHOR("Hans de Goede <hdegoede@xxxxxxxxxx>");
+MODULE_LICENSE("GPL");
diff --git a/drivers/input/touchscreen/novatek-nvt-ts-spi.c b/drivers/input/touchscreen/novatek-nvt-ts-spi.c
new file mode 100644
index 0000000000000..42c02f99f50cd
--- /dev/null
+++ b/drivers/input/touchscreen/novatek-nvt-ts-spi.c
@@ -0,0 +1,71 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Novatek NVT touchscreen controller - SPI bus glue
+ *
+ * The controller is reachable over SPI on boards that wire the interrupt and
+ * reset lines to the SoC instead of using an I2C bus; the register space and
+ * the touch packet format are the same, only the read framing differs: the
+ * register address byte is followed by one dummy byte, then the data is
+ * clocked out.
+ */
+
+#include <linux/module.h>
+#include <linux/spi/spi.h>
+
+#include "novatek-nvt-ts.h"
+
+static int nvt_ts_spi_read(struct nvt_ts_data *data, u8 reg, u8 *buf,
+ size_t count)
+{
+ struct spi_device *spi = to_spi_device(data->dev);
+ u8 cmd[2] = { reg & 0x7f, 0 };
+
+ /*
+ * One message so that the chip select stays asserted between the
+ * address/dummy bytes and the payload; spi_write_then_read() bounces
+ * the buffers when the controller cannot DMA from them.
+ */
+ return spi_write_then_read(spi, cmd, sizeof(cmd), buf, count);
+}
+
+static const struct nvt_ts_bus_ops nvt_ts_spi_bus_ops = {
+ .read = nvt_ts_spi_read,
+};
+
+static int nvt_ts_spi_probe(struct spi_device *spi)
+{
+ return nvt_ts_probe(&spi->dev, &nvt_ts_spi_bus_ops, spi->irq, BUS_SPI,
+ dev_name(&spi->dev));
+}
+
+static const struct of_device_id nvt_ts_spi_of_match[] = {
+ { .compatible = "novatek,nt11205-ts", .data = &nvt_nt11205_ts_data },
+ { .compatible = "novatek,nt36672a-ts", .data = &nvt_nt36672a_ts_data },
+ { }
+};
+MODULE_DEVICE_TABLE(of, nvt_ts_spi_of_match);
+
+static const struct spi_device_id nvt_ts_spi_id[] = {
+ { .name = "nt11205-ts", .driver_data = (unsigned long)&nvt_nt11205_ts_data },
+ { .name = "nt36672a-ts", .driver_data = (unsigned long)&nvt_nt36672a_ts_data },
+ { }
+};
+MODULE_DEVICE_TABLE(spi, nvt_ts_spi_id);
+
+static DEFINE_SIMPLE_DEV_PM_OPS(nvt_ts_spi_pm_ops, nvt_ts_suspend, nvt_ts_resume);
+
+static struct spi_driver nvt_ts_spi_driver = {
+ .driver = {
+ .name = "novatek-nvt-ts-spi",
+ .pm = pm_sleep_ptr(&nvt_ts_spi_pm_ops),
+ .of_match_table = nvt_ts_spi_of_match,
+ },
+ .probe = nvt_ts_spi_probe,
+ .id_table = nvt_ts_spi_id,
+};
+
+module_spi_driver(nvt_ts_spi_driver);
+
+MODULE_DESCRIPTION("Novatek NVT touchscreen SPI driver");
+MODULE_AUTHOR("Hans de Goede <hdegoede@xxxxxxxxxx>");
+MODULE_LICENSE("GPL");
--
2.53.0