All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/7] Input: novatek-nvt-ts - add transport ops abstraction
@ 2026-12-02  0:31 Qianhui Xu
  2026-12-02  0:31 ` [PATCH 2/7] Input: novatek-nvt-ts - split bus independent core out Qianhui Xu
                   ` (5 more replies)
  0 siblings, 6 replies; 11+ messages in thread
From: Qianhui Xu @ 2026-12-02  0:31 UTC (permalink / raw)
  To: dmitry.torokhov, hansg
  Cc: linux-input, devicetree, linux-kernel, robh, krzk+dt, conor+dt,
	konrad.dybcio, kholk11, gchan9527

The controllers supported by this driver can be wired to either I2C or SPI
depending on the board; only the framing of a register read differs.

Move the register read into a bus ops structure selected by the transport
specific probe function, and keep the I2C message construction in
nvt_ts_i2c_read(). Store the device and the IRQ number in the common
private structure so that the IRQ, open/close, and PM paths no longer reach
back into the I2C client.

No functional change for existing I2C devices.

Signed-off-by: Qianhui Xu <xiaqinghuan@mail.ustc.edu.cn>

---
 drivers/input/touchscreen/novatek-nvt-ts.c | 54 ++++++++++++++++------
 1 file changed, 41 insertions(+), 13 deletions(-)

diff --git a/drivers/input/touchscreen/novatek-nvt-ts.c b/drivers/input/touchscreen/novatek-nvt-ts.c
index fa718a99e2ba5..d1aa42533db2a 100644
--- a/drivers/input/touchscreen/novatek-nvt-ts.c
+++ b/drivers/input/touchscreen/novatek-nvt-ts.c
@@ -47,13 +47,28 @@ static const int nvt_ts_irq_type[4] = {
 	IRQF_TRIGGER_HIGH
 };
 
+struct nvt_ts_data;
+
+/**
+ * struct nvt_ts_bus_ops - transport specific operations
+ * @read: read @count bytes of the controller into @buf
+ *
+ * The controller exposes a flat register space; transports differ only in
+ * how a register read is framed on the wire.
+ */
+struct nvt_ts_bus_ops {
+	int (*read)(struct nvt_ts_data *data, u8 reg, u8 *buf, size_t count);
+};
+
 struct nvt_ts_i2c_chip_data {
 	u8 chip_id;
 };
 
 struct nvt_ts_data {
-	struct i2c_client *client;
+	struct device *dev;
+	const struct nvt_ts_bus_ops *bus_ops;
 	struct input_dev *input;
+	int irq;
 	struct gpio_desc *reset_gpio;
 	struct regulator_bulk_data regulators[2];
 	struct touchscreen_properties prop;
@@ -61,8 +76,10 @@ struct nvt_ts_data {
 	u8 buf[NVT_TS_TOUCH_SIZE * NVT_TS_MAX_TOUCHES];
 };
 
-static int nvt_ts_read_data(struct i2c_client *client, u8 reg, u8 *data, int count)
+static int nvt_ts_i2c_read(struct nvt_ts_data *data, u8 reg, u8 *buf, size_t count)
 {
+	struct i2c_client *client = to_i2c_client(data->dev);
+
 	struct i2c_msg msg[2] = {
 		{
 			.addr = client->addr,
@@ -73,7 +90,7 @@ static int nvt_ts_read_data(struct i2c_client *client, u8 reg, u8 *data, int cou
 			.addr = client->addr,
 			.flags = I2C_M_RD,
 			.len = count,
-			.buf = data,
+			.buf = buf,
 		}
 	};
 	int ret;
@@ -87,15 +104,24 @@ static int nvt_ts_read_data(struct i2c_client *client, u8 reg, u8 *data, int cou
 	return 0;
 }
 
+static const struct nvt_ts_bus_ops nvt_ts_i2c_bus_ops = {
+	.read = nvt_ts_i2c_read,
+};
+
+static int nvt_ts_read_data(struct nvt_ts_data *data, u8 reg, u8 *buf, size_t count)
+{
+	return data->bus_ops->read(data, reg, buf, count);
+}
+
 static irqreturn_t nvt_ts_irq(int irq, void *dev_id)
 {
 	struct nvt_ts_data *data = dev_id;
-	struct device *dev = &data->client->dev;
+	struct device *dev = data->dev;
 	int i, error, slot, x, y;
 	bool active;
 	u8 *touch;
 
-	error = nvt_ts_read_data(data->client, NVT_TS_TOUCH_START, data->buf,
+	error = nvt_ts_read_data(data, NVT_TS_TOUCH_START, data->buf,
 				 data->max_touches * NVT_TS_TOUCH_SIZE);
 	if (error)
 		return IRQ_HANDLED;
@@ -147,11 +173,11 @@ static int nvt_ts_start(struct input_dev *dev)
 
 	error = regulator_bulk_enable(ARRAY_SIZE(data->regulators), data->regulators);
 	if (error) {
-		dev_err(&data->client->dev, "failed to enable regulators\n");
+		dev_err(data->dev, "failed to enable regulators\n");
 		return error;
 	}
 
-	enable_irq(data->client->irq);
+	enable_irq(data->irq);
 	gpiod_set_value_cansleep(data->reset_gpio, 0);
 
 	return 0;
@@ -161,14 +187,14 @@ static void nvt_ts_stop(struct input_dev *dev)
 {
 	struct nvt_ts_data *data = input_get_drvdata(dev);
 
-	disable_irq(data->client->irq);
+	disable_irq(data->irq);
 	gpiod_set_value_cansleep(data->reset_gpio, 1);
 	regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators);
 }
 
 static int nvt_ts_suspend(struct device *dev)
 {
-	struct nvt_ts_data *data = i2c_get_clientdata(to_i2c_client(dev));
+	struct nvt_ts_data *data = dev_get_drvdata(dev);
 
 	guard(mutex)(&data->input->mutex);
 
@@ -180,7 +206,7 @@ static int nvt_ts_suspend(struct device *dev)
 
 static int nvt_ts_resume(struct device *dev)
 {
-	struct nvt_ts_data *data = i2c_get_clientdata(to_i2c_client(dev));
+	struct nvt_ts_data *data = dev_get_drvdata(dev);
 
 	guard(mutex)(&data->input->mutex);
 
@@ -213,7 +239,9 @@ static int nvt_ts_probe(struct i2c_client *client)
 	if (!chip)
 		return -EINVAL;
 
-	data->client = client;
+	data->dev = dev;
+	data->bus_ops = &nvt_ts_i2c_bus_ops;
+	data->irq = client->irq;
 	i2c_set_clientdata(client, data);
 
 	/*
@@ -244,7 +272,7 @@ static int nvt_ts_probe(struct i2c_client *client)
 
 	/* Wait for controller to come out of reset before params read */
 	msleep(100);
-	error = nvt_ts_read_data(data->client, NVT_TS_PARAMETERS_START,
+	error = nvt_ts_read_data(data, NVT_TS_PARAMETERS_START,
 				 data->buf, NVT_TS_PARAMS_SIZE);
 	gpiod_set_value_cansleep(data->reset_gpio, 1); /* Put back in reset */
 	regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators);
@@ -292,7 +320,7 @@ static int nvt_ts_probe(struct i2c_client *client)
 	data->input = input;
 	input_set_drvdata(input, data);
 
-	error = devm_request_threaded_irq(dev, client->irq, NULL, nvt_ts_irq,
+	error = devm_request_threaded_irq(dev, data->irq, NULL, nvt_ts_irq,
 					  IRQF_ONESHOT | IRQF_NO_AUTOEN |
 						nvt_ts_irq_type[irq_type],
 					  client->name, data);
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-12-02  0:53 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02  0:31 [PATCH 1/7] Input: novatek-nvt-ts - add transport ops abstraction Qianhui Xu
2026-12-02  0:31 ` [PATCH 2/7] Input: novatek-nvt-ts - split bus independent core out Qianhui Xu
2026-12-02  0:38   ` sashiko-bot
2026-12-02  0:31 ` [PATCH 3/7] Input: novatek-nvt-ts - add SPI bus support Qianhui Xu
2026-12-02  0:44   ` sashiko-bot
2026-12-02  0:31 ` [PATCH 4/7] dt-bindings: input: novatek,nvt-ts - allow SPI wiring Qianhui Xu
2026-12-02  0:31 ` [PATCH 5/7] Input: novatek-nvt-ts - add NT36536 packet decoding Qianhui Xu
2026-12-02  0:46   ` sashiko-bot
2026-12-02  0:31 ` [PATCH 6/7] dt-bindings: input: novatek,nvt-ts - add the NT36536 compatible Qianhui Xu
2026-12-02  0:31 ` [PATCH 7/7] Input: novatek-nvt-ts - add no-flash firmware download Qianhui Xu
2026-12-02  0:53   ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.