[PATCH v5 3/7] Input: novatek-nvt-ts - add SPI bus support
From: Qianhui Xu
Date: Wed Dec 02 2026 - 04:11:03 EST
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@xxxxxxxxxxxxxxxx>
---
Changes in v5:
- allocate tx and rx with __free(kfree) and tx with kzalloc(), which drops
the manual memset() and the out label.
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 | 96 +++++++++++++++++++
4 files changed, 124 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@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..88befe95c1711
--- /dev/null
+++ b/drivers/input/touchscreen/novatek-nvt-ts-spi.c
@@ -0,0 +1,96 @@
+// 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)
+{
+ u8 *tx __free(kfree) = kzalloc(count + 2, GFP_KERNEL);
+ u8 *rx __free(kfree) = kmalloc(count + 2, GFP_KERNEL);
+ struct spi_device *spi = to_spi_device(data->dev);
+ struct spi_transfer xfer = { };
+ 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.
+ */
+ if (!tx || !rx)
+ return -ENOMEM;
+
+ 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);
+
+ 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@xxxxxxxxxx>");
+MODULE_LICENSE("GPL");