Skip to contentSkip to conversation

RMI4 cleanups and switch hid-rmi to rmi_core

PATCH Applied Benjamin Tissoires 3 participants 15 messages Dec 2, 2016 – Dec 3, 2016

Subsystems (2)

v2 of 4 Applied Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover RMI4 cleanups and switch hid-rmi to rmi_core

Hi,

Well, the cleanup part of the series has already been applied, so I guess this is just "switch hid-rmi to rmi_core".

The series applies on top of Dmitri's synaptics-rmi4 branch

However, as mentioned in v1, I'd like to get some testings from actually integrated devices befor we flip the switch for HID. Andrew, Dennis?

Function f03 has been tested in the rmi4-smbus, and the attn data API on a test synaptics board.

Cheers,
Benjamin

Andrew Duggan (3):
HID: rmi: Make hid-rmi a transport driver for synaptics-rmi4
HID: rmi: Handle all Synaptics touchpads using hid-rmi
HID: rmi: Support the Lenovo Thinkpad X1 Tablet dock using hid-rmi

Benjamin Tissoires (2):
Input: synaptics-rmi4 - allow to add attention data
Input: synaptics-rmi4 - store the attn data in the driver

Dennis Wassenberg (1):
Input: synaptics-rmi4 - F03: grab data passed by transport device

Lyude Paul (1):
Input: synaptics-rmi4 - add support for F03

 drivers/hid/Kconfig             |   4 +
 drivers/hid/hid-core.c          |   4 +-
 drivers/hid/hid-ids.h           |   1 +
 drivers/hid/hid-rmi.c           | 974 ++++++----------------------------------
 drivers/input/rmi4/Kconfig      |   9 +
 drivers/input/rmi4/Makefile     |   1 +
 drivers/input/rmi4/rmi_bus.c    |   3 +
 drivers/input/rmi4/rmi_driver.c |  50 ++-
 drivers/input/rmi4/rmi_driver.h |   1 +
 drivers/input/rmi4/rmi_f03.c    | 251 +++++++++++
 drivers/input/rmi4/rmi_f11.c    |  12 +-
 drivers/input/rmi4/rmi_f12.c    |  43 +-
 drivers/input/rmi4/rmi_f30.c    |  11 +-
 include/linux/rmi.h             |  16 +-
 14 files changed, 508 insertions(+), 872 deletions(-)
 create mode 100644 drivers/input/rmi4/rmi_f03.c
Signature · 1 line
2.9.3
#1 lore raw

PATCH v2 1/7 Input: synaptics-rmi4 - add support for F03

From: Lyude Paul <[email protected]>

This adds basic functionality for PS/2 passthrough on Synaptics Touchpads using RMI4 through smbus.

---

changes in v2:
- amended according to Dmitry's suggestions
- add a depend on SERIO in the Kconfig

---
 drivers/input/rmi4/Kconfig      |   9 ++
 drivers/input/rmi4/Makefile     |   1 +
 drivers/input/rmi4/rmi_bus.c    |   3 +
 drivers/input/rmi4/rmi_driver.h |   1 +
 drivers/input/rmi4/rmi_f03.c    | 233 ++++++++++++++++++++++++++++++++++++++++
 5 files changed, 247 insertions(+)
 create mode 100644 drivers/input/rmi4/rmi_f03.c
drivers/input/rmi4/Kconfig +9 -0
index a9c36a5..30cc627 100644
@@ -39,6 +39,15 @@ config RMI4_SMB
 	  To compile this driver as a module, choose M here: the module will be
 	  called rmi_smbus.
 
+config RMI4_F03
+        bool "RMI4 Function 03 (PS2 Guest)"
+        depends on RMI4_CORE && SERIO
+        help
+          Say Y here if you want to add support for RMI4 function 03.
+
+          Function 03 provides PS2 guest support for RMI4 devices. This
+          includes support for TrackPoints on TouchPads.
+
 config RMI4_2D_SENSOR
 	bool
 	depends on RMI4_CORE
drivers/input/rmi4/Makefile +1 -0
index e7f4ca6..a199cbe 100644
@@ -4,6 +4,7 @@ rmi_core-y := rmi_bus.o rmi_driver.o rmi_f01.o
 rmi_core-$(CONFIG_RMI4_2D_SENSOR) += rmi_2d_sensor.o
 
 # Function drivers
+rmi_core-$(CONFIG_RMI4_F03) += rmi_f03.o
 rmi_core-$(CONFIG_RMI4_F11) += rmi_f11.o
 rmi_core-$(CONFIG_RMI4_F12) += rmi_f12.o
 rmi_core-$(CONFIG_RMI4_F30) += rmi_f30.o
drivers/input/rmi4/rmi_bus.c +3 -0
index 81be9c1..1c40d94 100644
@@ -305,6 +305,9 @@ struct bus_type rmi_bus_type = {
 
 static struct rmi_function_handler *fn_handlers[] = {
 	&rmi_f01_handler,
+#ifdef CONFIG_RMI4_F03
+	&rmi_f03_handler,
+#endif
 #ifdef CONFIG_RMI4_F11
 	&rmi_f11_handler,
 #endif
drivers/input/rmi4/rmi_driver.h +1 -0
index cc94585..24f8f76 100644
@@ -121,6 +121,7 @@ static inline void rmi_f34_remove_sysfs(struct rmi_device *rmi_dev)
 #endif /* CONFIG_RMI_F34 */
 
 extern struct rmi_function_handler rmi_f01_handler;
+extern struct rmi_function_handler rmi_f03_handler;
 extern struct rmi_function_handler rmi_f11_handler;
 extern struct rmi_function_handler rmi_f12_handler;
 extern struct rmi_function_handler rmi_f30_handler;
drivers/input/rmi4/rmi_f03.c new file +233 -0

233 lines not on this page · raw message

Signature · 1 line
2.9.3
maintainer
#2 lore raw

Re: [PATCH v2 1/7] Input: synaptics-rmi4 - add support for F03

Hi Benjamin,

Quoted 164 lines · Benjamin Tissoires

From: Lyude Paul <[email protected]>

This adds basic functionality for PS/2 passthrough on Synaptics Touchpads using RMI4 through smbus.

---

changes in v2:
- amended according to Dmitry's suggestions
- add a depend on SERIO in the Kconfig

---
 drivers/input/rmi4/Kconfig      |   9 ++
 drivers/input/rmi4/Makefile     |   1 +
 drivers/input/rmi4/rmi_bus.c    |   3 +
 drivers/input/rmi4/rmi_driver.h |   1 +
 drivers/input/rmi4/rmi_f03.c    | 233 ++++++++++++++++++++++++++++++++++++++++
 5 files changed, 247 insertions(+)
 create mode 100644 drivers/input/rmi4/rmi_f03.c
drivers/input/rmi4/Kconfig +9 -0
index a9c36a5..30cc627 100644
@@ -39,6 +39,15 @@ config RMI4_SMB
 	  To compile this driver as a module, choose M here: the module will be
 	  called rmi_smbus.
 
+config RMI4_F03
+        bool "RMI4 Function 03 (PS2 Guest)"
+        depends on RMI4_CORE && SERIO
+        help
+          Say Y here if you want to add support for RMI4 function 03.
+
+          Function 03 provides PS2 guest support for RMI4 devices. This
+          includes support for TrackPoints on TouchPads.
+
 config RMI4_2D_SENSOR
 	bool
 	depends on RMI4_CORE
drivers/input/rmi4/Makefile +1 -0
index e7f4ca6..a199cbe 100644
@@ -4,6 +4,7 @@ rmi_core-y := rmi_bus.o rmi_driver.o rmi_f01.o
 rmi_core-$(CONFIG_RMI4_2D_SENSOR) += rmi_2d_sensor.o
 
 # Function drivers
+rmi_core-$(CONFIG_RMI4_F03) += rmi_f03.o
 rmi_core-$(CONFIG_RMI4_F11) += rmi_f11.o
 rmi_core-$(CONFIG_RMI4_F12) += rmi_f12.o
 rmi_core-$(CONFIG_RMI4_F30) += rmi_f30.o
drivers/input/rmi4/rmi_bus.c +3 -0
index 81be9c1..1c40d94 100644
@@ -305,6 +305,9 @@ struct bus_type rmi_bus_type = {
 
 static struct rmi_function_handler *fn_handlers[] = {
 	&rmi_f01_handler,
+#ifdef CONFIG_RMI4_F03
+	&rmi_f03_handler,
+#endif
 #ifdef CONFIG_RMI4_F11
 	&rmi_f11_handler,
 #endif
drivers/input/rmi4/rmi_driver.h +1 -0
index cc94585..24f8f76 100644
@@ -121,6 +121,7 @@ static inline void rmi_f34_remove_sysfs(struct rmi_device *rmi_dev)
 #endif /* CONFIG_RMI_F34 */
 
 extern struct rmi_function_handler rmi_f01_handler;
+extern struct rmi_function_handler rmi_f03_handler;
 extern struct rmi_function_handler rmi_f11_handler;
 extern struct rmi_function_handler rmi_f12_handler;
 extern struct rmi_function_handler rmi_f30_handler;
drivers/input/rmi4/rmi_f03.c new file +77 -0
new file mode 100644
index 0000000..fd8f6e5
@@ -0,0 +1,233 @@
+/*
+ * Copyright (C) 2015-2016 Red Hat
+ * Copyright (C) 2015 Lyude Paul <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ */
+
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/serio.h>
+#include <linux/notifier.h>
+#include "rmi_driver.h"
+
+#define RMI_F03_RX_DATA_OFB		0x01
+#define RMI_F03_OB_SIZE			2
+
+#define RMI_F03_OB_OFFSET		2
+#define RMI_F03_OB_DATA_OFFSET		1
+#define RMI_F03_OB_FLAG_TIMEOUT		BIT(6)
+#define RMI_F03_OB_FLAG_PARITY		BIT(7)
+
+#define RMI_F03_DEVICE_COUNT		0x07
+#define RMI_F03_BYTES_PER_DEVICE_MASK	0x70
+#define RMI_F03_BYTES_PER_DEVICE_SHIFT	4
+#define RMI_F03_QUEUE_LENGTH		0x0F
+
+struct f03_data {
+	struct rmi_function *fn;
+
+	struct serio *serio;
+
+	u8 device_count;
+	u8 rx_queue_length;
+};
+
+static int rmi_f03_pt_write(struct serio *id, unsigned char val)
+{
+	struct f03_data *f03 = id->port_data;
+	int error;
+
+	rmi_dbg(RMI_DEBUG_FN, &f03->fn->dev,
+		"%s: Wrote %.2hhx to PS/2 passthrough address",
+		__func__, val);
+
+	error = rmi_write(f03->fn->rmi_dev, f03->fn->fd.data_base_addr, val);
+	if (error) {
+		dev_err(&f03->fn->dev,
+			"%s: Failed to write to F03 TX register (%d).\n",
+			__func__, error);
+		return error;
+	}
+
+	return 0;
+}
+
+static int rmi_f03_initialize(struct f03_data *f03)
+{
+	struct rmi_function *fn = f03->fn;
+	struct device *dev = &fn->dev;
+	int error;
+	u8 bytes_per_device;
+	u8 query1;
+	size_t query2_len;
+
+	error = rmi_read(fn->rmi_dev, fn->fd.query_base_addr, &query1);
+	if (error) {
+		dev_err(dev, "Failed to read query register (%d).\n", error);
+		return error;
+	}
+
+	f03->device_count = query1 & RMI_F03_DEVICE_COUNT;
+	bytes_per_device = (query1 & RMI_F03_BYTES_PER_DEVICE_MASK) >>
+		RMI_F03_BYTES_PER_DEVICE_SHIFT;
+
+	query2_len = f03->device_count * bytes_per_device;

drivers/input/rmi4/rmi_f03.c line 87

Quoted 10 lines
drivers/input/rmi4/rmi_f03.c new file +10 -0
+
+	/*
+	 * The first generation of image sensors don't have a second part to
+	 * their f03 query, as such we have to set some of these values manually
+	 */
+	if (query2_len < 1) {
+		f03->device_count = 1;
+		f03->rx_queue_length = 7;
+	} else {
+		u8 query2[query2_len];

sparse does not like variable length arrays too much, I changed this (and one below) to a static length array, and applied.

Thanks.

Signature · 1 line
Dmitry
#3 lore raw

PATCH v2 2/7 Input: synaptics-rmi4 - F03: grab data passed by transport device

In reply to Benjamin Tissoires

From: Dennis Wassenberg <[email protected]>

First check if there are data available passed by the transport device. If data available use these data. If there are no data available try to read the rmi block if dsata are passed this way.

This is the way the other rmi function handlers will do this.

This patch is needed on HID devices because the firmware reads F03 data registers and adds them to the HID attention report. Reading those registers from the driver after the firmware read them will result in invalid data.

---

no changes in v2

---
 drivers/input/rmi4/rmi_f03.c | 37 +++++++++++++++++++++++++++----------
 1 file changed, 27 insertions(+), 10 deletions(-)
drivers/input/rmi4/rmi_f03.c +27 -10
index fd8f6e5..06279cd 100644
@@ -165,6 +165,7 @@ static int rmi_f03_config(struct rmi_function *fn)
 
 static int rmi_f03_attention(struct rmi_function *fn, unsigned long *irq_bits)
 {
+	struct rmi_device *rmi_dev = fn->rmi_dev;
 	struct f03_data *f03 = dev_get_drvdata(&fn->dev);
 	u16 data_addr = fn->fd.data_base_addr;
 	const u8 ob_len = f03->rx_queue_length * RMI_F03_OB_SIZE;
@@ -173,16 +174,32 @@ static int rmi_f03_attention(struct rmi_function *fn, unsigned long *irq_bits)
 	u8 ob_data;
 	unsigned int serio_flags;
 	int i;
-	int retval;
-
-	/* Grab all of the data registers, and check them for data */
-	retval = rmi_read_block(fn->rmi_dev, data_addr + RMI_F03_OB_OFFSET,
-				&obs, ob_len);
-	if (retval) {
-		dev_err(&fn->dev, "%s: Failed to read F03 output buffers.\n",
-			__func__);
-		serio_interrupt(f03->serio, 0, SERIO_TIMEOUT);
-		return retval;
+	int ret;
+
+	if (!rmi_dev || !rmi_dev->xport)
+		return -ENODEV;
+
+	if (rmi_dev->xport->attn_data) {
+		/* First grab the data passed by the transport device */
+		if (rmi_dev->xport->attn_size < ob_len) {
+			dev_warn(&fn->dev, "F03 interrupted, but data is missing!\n");
+			return 0;
+		}
+
+		memcpy(obs, rmi_dev->xport->attn_data, ob_len);
+
+		rmi_dev->xport->attn_data += ob_len;
+		rmi_dev->xport->attn_size -= ob_len;
+	} else {
+		/* Grab all of the data registers, and check them for data */
+		ret = rmi_read_block(fn->rmi_dev, data_addr + RMI_F03_OB_OFFSET,
+				     &obs, ob_len);
+		if (ret) {
+			dev_err(&fn->dev, "%s: Failed to read F03 output buffers.\n",
+				__func__);
+			serio_interrupt(f03->serio, 0, SERIO_TIMEOUT);
+			return ret;
+		}
 	}
 
 	for (i = 0; i < ob_len; i += RMI_F03_OB_SIZE) {
Signature · 1 line
2.9.3
#4 lore raw

PATCH v2 3/7 Input: synaptics-rmi4 - allow to add attention data

In reply to Benjamin Tissoires

The HID implementation of RMI4 provides the data during the interrupt (in the input report). We need to provide a way for this transport driver to provide the attention data while calling an IRQ.

We use a fifo in rmi_core to not lose any incoming event.

---

no changes in v2

---
 drivers/input/rmi4/rmi_driver.c | 49 +++++++++++++++++++++++++++++++++++++++--
 include/linux/rmi.h             | 11 +++++++++
 2 files changed, 58 insertions(+), 2 deletions(-)
drivers/input/rmi4/rmi_driver.c +47 -2
index a718e51..85062e4 100644
@@ -191,16 +191,53 @@ static int rmi_process_interrupt_requests(struct rmi_device *rmi_dev)
 	return 0;
 }
 
+void rmi_set_attn_data(struct rmi_device *rmi_dev, unsigned long irq_status,
+		       void *data, size_t size)
+{
+	struct rmi_driver_data *drvdata = dev_get_drvdata(&rmi_dev->dev);
+	struct rmi4_attn_data attn_data;
+	void *fifo_data;
+
+	if (!drvdata->enabled)
+		return;
+
+	fifo_data = kmemdup(data, size, GFP_ATOMIC);
+	if (!fifo_data)
+		return;
+
+	attn_data.irq_status = irq_status;
+	attn_data.size = size;
+	attn_data.data = fifo_data;
+
+	kfifo_put(&drvdata->attn_fifo, attn_data);
+}
+EXPORT_SYMBOL_GPL(rmi_set_attn_data);
+
 static irqreturn_t rmi_irq_fn(int irq, void *dev_id)
 {
 	struct rmi_device *rmi_dev = dev_id;
-	int ret;
+	struct rmi_driver_data *drvdata = dev_get_drvdata(&rmi_dev->dev);
+	struct rmi4_attn_data attn_data = {0};
+	int ret, count;
+
+	count = kfifo_get(&drvdata->attn_fifo, &attn_data);
+	if (count) {
+		*(drvdata->irq_status) = attn_data.irq_status;
+		rmi_dev->xport->attn_data = attn_data.data;
+		rmi_dev->xport->attn_size = attn_data.size;
+	}
 
 	ret = rmi_process_interrupt_requests(rmi_dev);
 	if (ret)
 		rmi_dbg(RMI_DEBUG_CORE, &rmi_dev->dev,
 			"Failed to process interrupt request: %d\n", ret);
 
+	if (count)
+		kfree(attn_data.data);
+
+	if (!kfifo_is_empty(&drvdata->attn_fifo))
+		return rmi_irq_fn(irq, dev_id);
+
 	return IRQ_HANDLED;
 }
 
@@ -880,8 +917,9 @@ void rmi_disable_irq(struct rmi_device *rmi_dev, bool enable_wake)
 {
 	struct rmi_device_platform_data *pdata = rmi_get_platform_data(rmi_dev);
 	struct rmi_driver_data *data = dev_get_drvdata(&rmi_dev->dev);
+	struct rmi4_attn_data attn_data = {0};
 	int irq = pdata->irq;
-	int retval;
+	int retval, count;
 
 	mutex_lock(&data->enabled_mutex);
 
@@ -898,6 +936,13 @@ void rmi_disable_irq(struct rmi_device *rmi_dev, bool enable_wake)
 				 retval);
 	}
 
+	/* make sure the fifo is clean */
+	while (!kfifo_is_empty(&data->attn_fifo)) {
+		count = kfifo_get(&data->attn_fifo, &attn_data);
+		if (count)
+			kfree(attn_data.data);
+	}
+
 out:
 	mutex_unlock(&data->enabled_mutex);
 }
include/linux/rmi.h +11 -0
index 7780e40..1d48656 100644
@@ -13,6 +13,7 @@
 #include <linux/device.h>
 #include <linux/interrupt.h>
 #include <linux/input.h>
+#include <linux/kfifo.h>
 #include <linux/list.h>
 #include <linux/module.h>
 #include <linux/types.h>
@@ -331,6 +332,12 @@ struct rmi_device {
 
 };
 
+struct rmi4_attn_data {
+	unsigned long irq_status;
+	size_t size;
+	void *data;
+};
+
 struct rmi_driver_data {
 	struct list_head function_list;
 
@@ -357,11 +364,15 @@ struct rmi_driver_data {
 
 	bool enabled;
 	struct mutex enabled_mutex;
+	DECLARE_KFIFO(attn_fifo, struct rmi4_attn_data, 16);
 };
 
 int rmi_register_transport_device(struct rmi_transport_dev *xport);
 void rmi_unregister_transport_device(struct rmi_transport_dev *xport);
 
+void rmi_set_attn_data(struct rmi_device *rmi_dev, unsigned long irq_status,
+		       void *data, size_t size);
+
 int rmi_driver_suspend(struct rmi_device *rmi_dev, bool enable_wake);
 int rmi_driver_resume(struct rmi_device *rmi_dev, bool clear_wake);
 #endif
Signature · 1 line
2.9.3
Reviewed-by on v2 3/7
#5 lore raw

Re: [PATCH v2 3/7] Input: synaptics-rmi4 - allow to add attention data

Quoted 8 lines · Benjamin Tissoires

The HID implementation of RMI4 provides the data during the interrupt (in the input report). We need to provide a way for this transport driver to provide the attention data while calling an IRQ.

We use a fifo in rmi_core to not lose any incoming event.

Quoted 133 lines

---

no changes in v2

---
  drivers/input/rmi4/rmi_driver.c | 49 +++++++++++++++++++++++++++++++++++++++--
  include/linux/rmi.h             | 11 +++++++++
  2 files changed, 58 insertions(+), 2 deletions(-)
drivers/input/rmi4/rmi_driver.c +47 -2
index a718e51..85062e4 100644
@@ -191,16 +191,53 @@ static int rmi_process_interrupt_requests(struct rmi_device *rmi_dev)
  	return 0;
  }
 
+void rmi_set_attn_data(struct rmi_device *rmi_dev, unsigned long irq_status,
+		       void *data, size_t size)
+{
+	struct rmi_driver_data *drvdata = dev_get_drvdata(&rmi_dev->dev);
+	struct rmi4_attn_data attn_data;
+	void *fifo_data;
+
+	if (!drvdata->enabled)
+		return;
+
+	fifo_data = kmemdup(data, size, GFP_ATOMIC);
+	if (!fifo_data)
+		return;
+
+	attn_data.irq_status = irq_status;
+	attn_data.size = size;
+	attn_data.data = fifo_data;
+
+	kfifo_put(&drvdata->attn_fifo, attn_data);
+}
+EXPORT_SYMBOL_GPL(rmi_set_attn_data);
+
  static irqreturn_t rmi_irq_fn(int irq, void *dev_id)
  {
  	struct rmi_device *rmi_dev = dev_id;
-	int ret;
+	struct rmi_driver_data *drvdata = dev_get_drvdata(&rmi_dev->dev);
+	struct rmi4_attn_data attn_data = {0};
+	int ret, count;
+
+	count = kfifo_get(&drvdata->attn_fifo, &attn_data);
+	if (count) {
+		*(drvdata->irq_status) = attn_data.irq_status;
+		rmi_dev->xport->attn_data = attn_data.data;
+		rmi_dev->xport->attn_size = attn_data.size;
+	}
 
  	ret = rmi_process_interrupt_requests(rmi_dev);
  	if (ret)
  		rmi_dbg(RMI_DEBUG_CORE, &rmi_dev->dev,
  			"Failed to process interrupt request: %d\n", ret);
 
+	if (count)
+		kfree(attn_data.data);
+
+	if (!kfifo_is_empty(&drvdata->attn_fifo))
+		return rmi_irq_fn(irq, dev_id);
+
  	return IRQ_HANDLED;
  }
 
@@ -880,8 +917,9 @@ void rmi_disable_irq(struct rmi_device *rmi_dev, bool enable_wake)
  {
  	struct rmi_device_platform_data *pdata = rmi_get_platform_data(rmi_dev);
  	struct rmi_driver_data *data = dev_get_drvdata(&rmi_dev->dev);
+	struct rmi4_attn_data attn_data = {0};
  	int irq = pdata->irq;
-	int retval;
+	int retval, count;
 
  	mutex_lock(&data->enabled_mutex);
 
@@ -898,6 +936,13 @@ void rmi_disable_irq(struct rmi_device *rmi_dev, bool enable_wake)
  				 retval);
  	}
 
+	/* make sure the fifo is clean */
+	while (!kfifo_is_empty(&data->attn_fifo)) {
+		count = kfifo_get(&data->attn_fifo, &attn_data);
+		if (count)
+			kfree(attn_data.data);
+	}
+
  out:
  	mutex_unlock(&data->enabled_mutex);
  }
include/linux/rmi.h +11 -0
index 7780e40..1d48656 100644
@@ -13,6 +13,7 @@
  #include <linux/device.h>
  #include <linux/interrupt.h>
  #include <linux/input.h>
+#include <linux/kfifo.h>
  #include <linux/list.h>
  #include <linux/module.h>
  #include <linux/types.h>
@@ -331,6 +332,12 @@ struct rmi_device {
 
  };
 
+struct rmi4_attn_data {
+	unsigned long irq_status;
+	size_t size;
+	void *data;
+};
+
  struct rmi_driver_data {
  	struct list_head function_list;
 
@@ -357,11 +364,15 @@ struct rmi_driver_data {
 
  	bool enabled;
  	struct mutex enabled_mutex;
+	DECLARE_KFIFO(attn_fifo, struct rmi4_attn_data, 16);
  };
 
  int rmi_register_transport_device(struct rmi_transport_dev *xport);
  void rmi_unregister_transport_device(struct rmi_transport_dev *xport);
 
+void rmi_set_attn_data(struct rmi_device *rmi_dev, unsigned long irq_status,
+		       void *data, size_t size);
+
  int rmi_driver_suspend(struct rmi_device *rmi_dev, bool enable_wake);
  int rmi_driver_resume(struct rmi_device *rmi_dev, bool clear_wake);
  #endif
maintainer Applied
#6 lore raw

Re: [PATCH v2 3/7] Input: synaptics-rmi4 - allow to add attention data

Quoted 11 lines · Andrew Duggan
Quoted 8 lines · Benjamin Tissoires

The HID implementation of RMI4 provides the data during the interrupt (in the input report). We need to provide a way for this transport driver to provide the attention data while calling an IRQ.

We use a fifo in rmi_core to not lose any incoming event.

Applied, thank you.

Quoted 123 lines
Quoted 121 lines

---

no changes in v2

---
 drivers/input/rmi4/rmi_driver.c | 49 +++++++++++++++++++++++++++++++++++++++--
 include/linux/rmi.h             | 11 +++++++++
 2 files changed, 58 insertions(+), 2 deletions(-)
drivers/input/rmi4/rmi_driver.c +47 -2
index a718e51..85062e4 100644
@@ -191,16 +191,53 @@ static int rmi_process_interrupt_requests(struct rmi_device *rmi_dev)
 	return 0;
 }
+void rmi_set_attn_data(struct rmi_device *rmi_dev, unsigned long irq_status,
+		       void *data, size_t size)
+{
+	struct rmi_driver_data *drvdata = dev_get_drvdata(&rmi_dev->dev);
+	struct rmi4_attn_data attn_data;
+	void *fifo_data;
+
+	if (!drvdata->enabled)
+		return;
+
+	fifo_data = kmemdup(data, size, GFP_ATOMIC);
+	if (!fifo_data)
+		return;
+
+	attn_data.irq_status = irq_status;
+	attn_data.size = size;
+	attn_data.data = fifo_data;
+
+	kfifo_put(&drvdata->attn_fifo, attn_data);
+}
+EXPORT_SYMBOL_GPL(rmi_set_attn_data);
+
 static irqreturn_t rmi_irq_fn(int irq, void *dev_id)
 {
 	struct rmi_device *rmi_dev = dev_id;
-	int ret;
+	struct rmi_driver_data *drvdata = dev_get_drvdata(&rmi_dev->dev);
+	struct rmi4_attn_data attn_data = {0};
+	int ret, count;
+
+	count = kfifo_get(&drvdata->attn_fifo, &attn_data);
+	if (count) {
+		*(drvdata->irq_status) = attn_data.irq_status;
+		rmi_dev->xport->attn_data = attn_data.data;
+		rmi_dev->xport->attn_size = attn_data.size;
+	}
 	ret = rmi_process_interrupt_requests(rmi_dev);
 	if (ret)
 		rmi_dbg(RMI_DEBUG_CORE, &rmi_dev->dev,
 			"Failed to process interrupt request: %d\n", ret);
+	if (count)
+		kfree(attn_data.data);
+
+	if (!kfifo_is_empty(&drvdata->attn_fifo))
+		return rmi_irq_fn(irq, dev_id);
+
 	return IRQ_HANDLED;
 }
@@ -880,8 +917,9 @@ void rmi_disable_irq(struct rmi_device *rmi_dev, bool enable_wake)
 {
 	struct rmi_device_platform_data *pdata = rmi_get_platform_data(rmi_dev);
 	struct rmi_driver_data *data = dev_get_drvdata(&rmi_dev->dev);
+	struct rmi4_attn_data attn_data = {0};
 	int irq = pdata->irq;
-	int retval;
+	int retval, count;
 	mutex_lock(&data->enabled_mutex);
@@ -898,6 +936,13 @@ void rmi_disable_irq(struct rmi_device *rmi_dev, bool enable_wake)
 				 retval);
 	}
+	/* make sure the fifo is clean */
+	while (!kfifo_is_empty(&data->attn_fifo)) {
+		count = kfifo_get(&data->attn_fifo, &attn_data);
+		if (count)
+			kfree(attn_data.data);
+	}
+
 out:
 	mutex_unlock(&data->enabled_mutex);
 }
include/linux/rmi.h +11 -0
index 7780e40..1d48656 100644
@@ -13,6 +13,7 @@
 #include <linux/device.h>
 #include <linux/interrupt.h>
 #include <linux/input.h>
+#include <linux/kfifo.h>
 #include <linux/list.h>
 #include <linux/module.h>
 #include <linux/types.h>
@@ -331,6 +332,12 @@ struct rmi_device {
 };
+struct rmi4_attn_data {
+	unsigned long irq_status;
+	size_t size;
+	void *data;
+};
+
 struct rmi_driver_data {
 	struct list_head function_list;
@@ -357,11 +364,15 @@ struct rmi_driver_data {
 	bool enabled;
 	struct mutex enabled_mutex;
+	DECLARE_KFIFO(attn_fifo, struct rmi4_attn_data, 16);
 };
 int rmi_register_transport_device(struct rmi_transport_dev *xport);
 void rmi_unregister_transport_device(struct rmi_transport_dev *xport);
+void rmi_set_attn_data(struct rmi_device *rmi_dev, unsigned long irq_status,
+		       void *data, size_t size);
+
 int rmi_driver_suspend(struct rmi_device *rmi_dev, bool enable_wake);
 int rmi_driver_resume(struct rmi_device *rmi_dev, bool clear_wake);
 #endif
Signature · 1 line
Dmitry
#7 lore raw

PATCH v2 4/7 Input: synaptics-rmi4 - store the attn data in the driver

In reply to Benjamin Tissoires

Now that we have a proper API to set the attention data, there is no point in keeping it in the transport driver.

---

no changes in v2

---
 drivers/input/rmi4/rmi_driver.c |  5 ++---
 drivers/input/rmi4/rmi_f03.c    | 13 +++++++------
 drivers/input/rmi4/rmi_f11.c    | 12 ++++++------
 drivers/input/rmi4/rmi_f12.c    | 43 +++++++++++++++++++++--------------------
 drivers/input/rmi4/rmi_f30.c    | 11 ++++++-----
 include/linux/rmi.h             |  5 ++---
 6 files changed, 45 insertions(+), 44 deletions(-)
drivers/input/rmi4/rmi_driver.c +2 -3
index 85062e4..05a3c4b 100644
@@ -155,7 +155,7 @@ static int rmi_process_interrupt_requests(struct rmi_device *rmi_dev)
 	if (!data)
 		return 0;
 
-	if (!rmi_dev->xport->attn_data) {
+	if (!data->attn_data.data) {
 		error = rmi_read_block(rmi_dev,
 				data->f01_container->fd.data_base_addr + 1,
 				data->irq_status, data->num_of_irq_regs);
@@ -223,8 +223,7 @@ static irqreturn_t rmi_irq_fn(int irq, void *dev_id)
 	count = kfifo_get(&drvdata->attn_fifo, &attn_data);
 	if (count) {
 		*(drvdata->irq_status) = attn_data.irq_status;
-		rmi_dev->xport->attn_data = attn_data.data;
-		rmi_dev->xport->attn_size = attn_data.size;
+		drvdata->attn_data = attn_data;
 	}
 
 	ret = rmi_process_interrupt_requests(rmi_dev);
drivers/input/rmi4/rmi_f03.c +7 -6
index 06279cd..996dcbb 100644
@@ -166,6 +166,7 @@ static int rmi_f03_config(struct rmi_function *fn)
 static int rmi_f03_attention(struct rmi_function *fn, unsigned long *irq_bits)
 {
 	struct rmi_device *rmi_dev = fn->rmi_dev;
+	struct rmi_driver_data *drvdata = dev_get_drvdata(&rmi_dev->dev);
 	struct f03_data *f03 = dev_get_drvdata(&fn->dev);
 	u16 data_addr = fn->fd.data_base_addr;
 	const u8 ob_len = f03->rx_queue_length * RMI_F03_OB_SIZE;
@@ -176,20 +177,20 @@ static int rmi_f03_attention(struct rmi_function *fn, unsigned long *irq_bits)
 	int i;
 	int ret;
 
-	if (!rmi_dev || !rmi_dev->xport)
+	if (!rmi_dev)
 		return -ENODEV;
 
-	if (rmi_dev->xport->attn_data) {
+	if (drvdata->attn_data.data) {
 		/* First grab the data passed by the transport device */
-		if (rmi_dev->xport->attn_size < ob_len) {
+		if (drvdata->attn_data.size < ob_len) {
 			dev_warn(&fn->dev, "F03 interrupted, but data is missing!\n");
 			return 0;
 		}
 
-		memcpy(obs, rmi_dev->xport->attn_data, ob_len);
+		memcpy(obs, drvdata->attn_data.data, ob_len);
 
-		rmi_dev->xport->attn_data += ob_len;
-		rmi_dev->xport->attn_size -= ob_len;
+		drvdata->attn_data.data += ob_len;
+		drvdata->attn_data.size -= ob_len;
 	} else {
 		/* Grab all of the data registers, and check them for data */
 		ret = rmi_read_block(fn->rmi_dev, data_addr + RMI_F03_OB_OFFSET,
drivers/input/rmi4/rmi_f11.c +6 -6
index 44fc275..bc5e37f 100644
@@ -1284,19 +1284,19 @@ static int rmi_f11_attention(struct rmi_function *fn, unsigned long *irq_bits)
 	int error;
 	int valid_bytes = f11->sensor.pkt_size;
 
-	if (rmi_dev->xport->attn_data) {
+	if (drvdata->attn_data.data) {
 		/*
 		 * The valid data in the attention report is less then
 		 * expected. Only process the complete fingers.
 		 */
-		if (f11->sensor.attn_size > rmi_dev->xport->attn_size)
-			valid_bytes = rmi_dev->xport->attn_size;
+		if (f11->sensor.attn_size > drvdata->attn_data.size)
+			valid_bytes = drvdata->attn_data.size;
 		else
 			valid_bytes = f11->sensor.attn_size;
-		memcpy(f11->sensor.data_pkt, rmi_dev->xport->attn_data,
+		memcpy(f11->sensor.data_pkt, drvdata->attn_data.data,
 			valid_bytes);
-		rmi_dev->xport->attn_data += f11->sensor.attn_size;
-		rmi_dev->xport->attn_size -= f11->sensor.attn_size;
+		drvdata->attn_data.data += f11->sensor.attn_size;
+		drvdata->attn_data.size -= f11->sensor.attn_size;
 	} else {
 		error = rmi_read_block(rmi_dev,
 				data_base_addr, f11->sensor.data_pkt,
drivers/input/rmi4/rmi_f12.c +22 -21

119 lines not on this page · raw message

drivers/input/rmi4/rmi_f30.c +6 -5
index f696137..f4b491e 100644
@@ -99,6 +99,7 @@ static int rmi_f30_attention(struct rmi_function *fn, unsigned long *irq_bits)
 {
 	struct f30_data *f30 = dev_get_drvdata(&fn->dev);
 	struct rmi_device *rmi_dev = fn->rmi_dev;
+	struct rmi_driver_data *drvdata = dev_get_drvdata(&rmi_dev->dev);
 	int retval;
 	int gpiled = 0;
 	int value = 0;
@@ -109,15 +110,15 @@ static int rmi_f30_attention(struct rmi_function *fn, unsigned long *irq_bits)
 		return 0;
 
 	/* Read the gpi led data. */
-	if (rmi_dev->xport->attn_data) {
-		if (rmi_dev->xport->attn_size < f30->register_count) {
+	if (drvdata->attn_data.data) {
+		if (drvdata->attn_data.size < f30->register_count) {
 			dev_warn(&fn->dev, "F30 interrupted, but data is missing\n");
 			return 0;
 		}
-		memcpy(f30->data_regs, rmi_dev->xport->attn_data,
+		memcpy(f30->data_regs, drvdata->attn_data.data,
 			f30->register_count);
-		rmi_dev->xport->attn_data += f30->register_count;
-		rmi_dev->xport->attn_size -= f30->register_count;
+		drvdata->attn_data.data += f30->register_count;
+		drvdata->attn_data.size -= f30->register_count;
 	} else {
 		retval = rmi_read_block(rmi_dev, fn->fd.data_base_addr,
 			f30->data_regs, f30->register_count);
include/linux/rmi.h +2 -3
index 1d48656..ac910f7 100644
@@ -272,9 +272,6 @@ struct rmi_transport_dev {
 	struct rmi_device_platform_data pdata;
 
 	struct input_dev *input;
-
-	void *attn_data;
-	int attn_size;
 };
 
 /**
@@ -364,6 +361,8 @@ struct rmi_driver_data {
 
 	bool enabled;
 	struct mutex enabled_mutex;
+
+	struct rmi4_attn_data attn_data;
 	DECLARE_KFIFO(attn_fifo, struct rmi4_attn_data, 16);
 };
 
Signature · 1 line
2.9.3
Reviewed-by on v2 4/7
#8 lore raw

Re: [PATCH v2 4/7] Input: synaptics-rmi4 - store the attn data in the driver

Quoted 4 lines · Benjamin Tissoires

Now that we have a proper API to set the attention data, there is no point in keeping it in the transport driver.

Quoted 289 lines

---

no changes in v2

---
  drivers/input/rmi4/rmi_driver.c |  5 ++---
  drivers/input/rmi4/rmi_f03.c    | 13 +++++++------
  drivers/input/rmi4/rmi_f11.c    | 12 ++++++------
  drivers/input/rmi4/rmi_f12.c    | 43 +++++++++++++++++++++--------------------
  drivers/input/rmi4/rmi_f30.c    | 11 ++++++-----
  include/linux/rmi.h             |  5 ++---
  6 files changed, 45 insertions(+), 44 deletions(-)
drivers/input/rmi4/rmi_driver.c +2 -3
index 85062e4..05a3c4b 100644
@@ -155,7 +155,7 @@ static int rmi_process_interrupt_requests(struct rmi_device *rmi_dev)
  	if (!data)
  		return 0;
 
-	if (!rmi_dev->xport->attn_data) {
+	if (!data->attn_data.data) {
  		error = rmi_read_block(rmi_dev,
  				data->f01_container->fd.data_base_addr + 1,
  				data->irq_status, data->num_of_irq_regs);
@@ -223,8 +223,7 @@ static irqreturn_t rmi_irq_fn(int irq, void *dev_id)
  	count = kfifo_get(&drvdata->attn_fifo, &attn_data);
  	if (count) {
  		*(drvdata->irq_status) = attn_data.irq_status;
-		rmi_dev->xport->attn_data = attn_data.data;
-		rmi_dev->xport->attn_size = attn_data.size;
+		drvdata->attn_data = attn_data;
  	}
 
  	ret = rmi_process_interrupt_requests(rmi_dev);
drivers/input/rmi4/rmi_f03.c +7 -6
index 06279cd..996dcbb 100644
@@ -166,6 +166,7 @@ static int rmi_f03_config(struct rmi_function *fn)
  static int rmi_f03_attention(struct rmi_function *fn, unsigned long *irq_bits)
  {
  	struct rmi_device *rmi_dev = fn->rmi_dev;
+	struct rmi_driver_data *drvdata = dev_get_drvdata(&rmi_dev->dev);
  	struct f03_data *f03 = dev_get_drvdata(&fn->dev);
  	u16 data_addr = fn->fd.data_base_addr;
  	const u8 ob_len = f03->rx_queue_length * RMI_F03_OB_SIZE;
@@ -176,20 +177,20 @@ static int rmi_f03_attention(struct rmi_function *fn, unsigned long *irq_bits)
  	int i;
  	int ret;
 
-	if (!rmi_dev || !rmi_dev->xport)
+	if (!rmi_dev)
  		return -ENODEV;
 
-	if (rmi_dev->xport->attn_data) {
+	if (drvdata->attn_data.data) {
  		/* First grab the data passed by the transport device */
-		if (rmi_dev->xport->attn_size < ob_len) {
+		if (drvdata->attn_data.size < ob_len) {
  			dev_warn(&fn->dev, "F03 interrupted, but data is missing!\n");
  			return 0;
  		}
 
-		memcpy(obs, rmi_dev->xport->attn_data, ob_len);
+		memcpy(obs, drvdata->attn_data.data, ob_len);
 
-		rmi_dev->xport->attn_data += ob_len;
-		rmi_dev->xport->attn_size -= ob_len;
+		drvdata->attn_data.data += ob_len;
+		drvdata->attn_data.size -= ob_len;
  	} else {
  		/* Grab all of the data registers, and check them for data */
  		ret = rmi_read_block(fn->rmi_dev, data_addr + RMI_F03_OB_OFFSET,
drivers/input/rmi4/rmi_f11.c +6 -6
index 44fc275..bc5e37f 100644
@@ -1284,19 +1284,19 @@ static int rmi_f11_attention(struct rmi_function *fn, unsigned long *irq_bits)
  	int error;
  	int valid_bytes = f11->sensor.pkt_size;
 
-	if (rmi_dev->xport->attn_data) {
+	if (drvdata->attn_data.data) {
  		/*
  		 * The valid data in the attention report is less then
  		 * expected. Only process the complete fingers.
  		 */
-		if (f11->sensor.attn_size > rmi_dev->xport->attn_size)
-			valid_bytes = rmi_dev->xport->attn_size;
+		if (f11->sensor.attn_size > drvdata->attn_data.size)
+			valid_bytes = drvdata->attn_data.size;
  		else
  			valid_bytes = f11->sensor.attn_size;
-		memcpy(f11->sensor.data_pkt, rmi_dev->xport->attn_data,
+		memcpy(f11->sensor.data_pkt, drvdata->attn_data.data,
  			valid_bytes);
-		rmi_dev->xport->attn_data += f11->sensor.attn_size;
-		rmi_dev->xport->attn_size -= f11->sensor.attn_size;
+		drvdata->attn_data.data += f11->sensor.attn_size;
+		drvdata->attn_data.size -= f11->sensor.attn_size;
  	} else {
  		error = rmi_read_block(rmi_dev,
  				data_base_addr, f11->sensor.data_pkt,
drivers/input/rmi4/rmi_f12.c +22 -21
index 82a4964..8c5360c 100644
@@ -208,19 +208,20 @@ static int rmi_f12_attention(struct rmi_function *fn,
  {
  	int retval;
  	struct rmi_device *rmi_dev = fn->rmi_dev;
+	struct rmi_driver_data *drvdata = dev_get_drvdata(&rmi_dev->dev);
  	struct f12_data *f12 = dev_get_drvdata(&fn->dev);
  	struct rmi_2d_sensor *sensor = &f12->sensor;
  	int valid_bytes = sensor->pkt_size;
 
-	if (rmi_dev->xport->attn_data) {
-		if (sensor->attn_size > rmi_dev->xport->attn_size)
-			valid_bytes = rmi_dev->xport->attn_size;
+	if (drvdata->attn_data.data) {
+		if (sensor->attn_size > drvdata->attn_data.size)
+			valid_bytes = drvdata->attn_data.size;
  		else
  			valid_bytes = sensor->attn_size;
-		memcpy(sensor->data_pkt, rmi_dev->xport->attn_data,
+		memcpy(sensor->data_pkt, drvdata->attn_data.data,
  			valid_bytes);
-		rmi_dev->xport->attn_data += sensor->attn_size;
-		rmi_dev->xport->attn_size -= sensor->attn_size;
+		drvdata->attn_data.data += sensor->attn_size;
+		drvdata->attn_data.size -= sensor->attn_size;
  	} else {
  		retval = rmi_read_block(rmi_dev, f12->data_addr,
  					sensor->data_pkt, sensor->pkt_size);
@@ -323,7 +324,7 @@ static int rmi_f12_probe(struct rmi_function *fn)
  	const struct rmi_register_desc_item *item;
  	struct rmi_2d_sensor *sensor;
  	struct rmi_device_platform_data *pdata = rmi_get_platform_data(rmi_dev);
-	struct rmi_transport_dev *xport = rmi_dev->xport;
+	struct rmi_driver_data *drvdata = dev_get_drvdata(&rmi_dev->dev);
  	u16 data_offset = 0;
 
  	rmi_dbg(RMI_DEBUG_FN, &fn->dev, "%s\n", __func__);
@@ -422,7 +423,7 @@ static int rmi_f12_probe(struct rmi_function *fn)
  	 * HID attention reports.
  	 */
  	item = rmi_get_register_desc_item(&f12->data_reg_desc, 0);
-	if (item && !xport->attn_data)
+	if (item && !drvdata->attn_data.data)
  		data_offset += item->reg_size;
 
  	item = rmi_get_register_desc_item(&f12->data_reg_desc, 1);
@@ -436,15 +437,15 @@ static int rmi_f12_probe(struct rmi_function *fn)
  	}
 
  	item = rmi_get_register_desc_item(&f12->data_reg_desc, 2);
-	if (item && !xport->attn_data)
+	if (item && !drvdata->attn_data.data)
  		data_offset += item->reg_size;
 
  	item = rmi_get_register_desc_item(&f12->data_reg_desc, 3);
-	if (item && !xport->attn_data)
+	if (item && !drvdata->attn_data.data)
  		data_offset += item->reg_size;
 
  	item = rmi_get_register_desc_item(&f12->data_reg_desc, 4);
-	if (item && !xport->attn_data)
+	if (item && !drvdata->attn_data.data)
  		data_offset += item->reg_size;
 
  	item = rmi_get_register_desc_item(&f12->data_reg_desc, 5);
@@ -456,22 +457,22 @@ static int rmi_f12_probe(struct rmi_function *fn)
  	}
 
  	item = rmi_get_register_desc_item(&f12->data_reg_desc, 6);
-	if (item && !xport->attn_data) {
+	if (item && !drvdata->attn_data.data) {
  		f12->data6 = item;
  		f12->data6_offset = data_offset;
  		data_offset += item->reg_size;
  	}
 
  	item = rmi_get_register_desc_item(&f12->data_reg_desc, 7);
-	if (item && !xport->attn_data)
+	if (item && !drvdata->attn_data.data)
  		data_offset += item->reg_size;
 
  	item = rmi_get_register_desc_item(&f12->data_reg_desc, 8);
-	if (item && !xport->attn_data)
+	if (item && !drvdata->attn_data.data)
  		data_offset += item->reg_size;
 
  	item = rmi_get_register_desc_item(&f12->data_reg_desc, 9);
-	if (item && !xport->attn_data) {
+	if (item && !drvdata->attn_data.data) {
  		f12->data9 = item;
  		f12->data9_offset = data_offset;
  		data_offset += item->reg_size;
@@ -480,27 +481,27 @@ static int rmi_f12_probe(struct rmi_function *fn)
  	}
 
  	item = rmi_get_register_desc_item(&f12->data_reg_desc, 10);
-	if (item && !xport->attn_data)
+	if (item && !drvdata->attn_data.data)
  		data_offset += item->reg_size;
 
  	item = rmi_get_register_desc_item(&f12->data_reg_desc, 11);
-	if (item && !xport->attn_data)
+	if (item && !drvdata->attn_data.data)
  		data_offset += item->reg_size;
 
  	item = rmi_get_register_desc_item(&f12->data_reg_desc, 12);
-	if (item && !xport->attn_data)
+	if (item && !drvdata->attn_data.data)
  		data_offset += item->reg_size;
 
  	item = rmi_get_register_desc_item(&f12->data_reg_desc, 13);
-	if (item && !xport->attn_data)
+	if (item && !drvdata->attn_data.data)
  		data_offset += item->reg_size;
 
  	item = rmi_get_register_desc_item(&f12->data_reg_desc, 14);
-	if (item && !xport->attn_data)
+	if (item && !drvdata->attn_data.data)
  		data_offset += item->reg_size;
 
  	item = rmi_get_register_desc_item(&f12->data_reg_desc, 15);
-	if (item && !xport->attn_data) {
+	if (item && !drvdata->attn_data.data) {
  		f12->data15 = item;
  		f12->data15_offset = data_offset;
  		data_offset += item->reg_size;
drivers/input/rmi4/rmi_f30.c +6 -5
index f696137..f4b491e 100644
@@ -99,6 +99,7 @@ static int rmi_f30_attention(struct rmi_function *fn, unsigned long *irq_bits)
  {
  	struct f30_data *f30 = dev_get_drvdata(&fn->dev);
  	struct rmi_device *rmi_dev = fn->rmi_dev;
+	struct rmi_driver_data *drvdata = dev_get_drvdata(&rmi_dev->dev);
  	int retval;
  	int gpiled = 0;
  	int value = 0;
@@ -109,15 +110,15 @@ static int rmi_f30_attention(struct rmi_function *fn, unsigned long *irq_bits)
  		return 0;
 
  	/* Read the gpi led data. */
-	if (rmi_dev->xport->attn_data) {
-		if (rmi_dev->xport->attn_size < f30->register_count) {
+	if (drvdata->attn_data.data) {
+		if (drvdata->attn_data.size < f30->register_count) {
  			dev_warn(&fn->dev, "F30 interrupted, but data is missing\n");
  			return 0;
  		}
-		memcpy(f30->data_regs, rmi_dev->xport->attn_data,
+		memcpy(f30->data_regs, drvdata->attn_data.data,
  			f30->register_count);
-		rmi_dev->xport->attn_data += f30->register_count;
-		rmi_dev->xport->attn_size -= f30->register_count;
+		drvdata->attn_data.data += f30->register_count;
+		drvdata->attn_data.size -= f30->register_count;
  	} else {
  		retval = rmi_read_block(rmi_dev, fn->fd.data_base_addr,
  			f30->data_regs, f30->register_count);
include/linux/rmi.h +2 -3
index 1d48656..ac910f7 100644
@@ -272,9 +272,6 @@ struct rmi_transport_dev {
  	struct rmi_device_platform_data pdata;
 
  	struct input_dev *input;
-
-	void *attn_data;
-	int attn_size;
  };
 
  /**
@@ -364,6 +361,8 @@ struct rmi_driver_data {
 
  	bool enabled;
  	struct mutex enabled_mutex;
+
+	struct rmi4_attn_data attn_data;
  	DECLARE_KFIFO(attn_fifo, struct rmi4_attn_data, 16);
  };
 
maintainer Applied
#9 lore raw

Re: [PATCH v2 4/7] Input: synaptics-rmi4 - store the attn data in the driver

Quoted 7 lines · Andrew Duggan
Quoted 4 lines · Benjamin Tissoires

Now that we have a proper API to set the attention data, there is no point in keeping it in the transport driver.

Applied, thank you.

Quoted 263 lines
Quoted 261 lines

---

no changes in v2

---
 drivers/input/rmi4/rmi_driver.c |  5 ++---
 drivers/input/rmi4/rmi_f03.c    | 13 +++++++------
 drivers/input/rmi4/rmi_f11.c    | 12 ++++++------
 drivers/input/rmi4/rmi_f12.c    | 43 +++++++++++++++++++++--------------------
 drivers/input/rmi4/rmi_f30.c    | 11 ++++++-----
 include/linux/rmi.h             |  5 ++---
 6 files changed, 45 insertions(+), 44 deletions(-)
drivers/input/rmi4/rmi_driver.c +2 -3
index 85062e4..05a3c4b 100644
@@ -155,7 +155,7 @@ static int rmi_process_interrupt_requests(struct rmi_device *rmi_dev)
 	if (!data)
 		return 0;
-	if (!rmi_dev->xport->attn_data) {
+	if (!data->attn_data.data) {
 		error = rmi_read_block(rmi_dev,
 				data->f01_container->fd.data_base_addr + 1,
 				data->irq_status, data->num_of_irq_regs);
@@ -223,8 +223,7 @@ static irqreturn_t rmi_irq_fn(int irq, void *dev_id)
 	count = kfifo_get(&drvdata->attn_fifo, &attn_data);
 	if (count) {
 		*(drvdata->irq_status) = attn_data.irq_status;
-		rmi_dev->xport->attn_data = attn_data.data;
-		rmi_dev->xport->attn_size = attn_data.size;
+		drvdata->attn_data = attn_data;
 	}
 	ret = rmi_process_interrupt_requests(rmi_dev);
drivers/input/rmi4/rmi_f03.c +7 -6
index 06279cd..996dcbb 100644
@@ -166,6 +166,7 @@ static int rmi_f03_config(struct rmi_function *fn)
 static int rmi_f03_attention(struct rmi_function *fn, unsigned long *irq_bits)
 {
 	struct rmi_device *rmi_dev = fn->rmi_dev;
+	struct rmi_driver_data *drvdata = dev_get_drvdata(&rmi_dev->dev);
 	struct f03_data *f03 = dev_get_drvdata(&fn->dev);
 	u16 data_addr = fn->fd.data_base_addr;
 	const u8 ob_len = f03->rx_queue_length * RMI_F03_OB_SIZE;
@@ -176,20 +177,20 @@ static int rmi_f03_attention(struct rmi_function *fn, unsigned long *irq_bits)
 	int i;
 	int ret;
-	if (!rmi_dev || !rmi_dev->xport)
+	if (!rmi_dev)
 		return -ENODEV;
-	if (rmi_dev->xport->attn_data) {
+	if (drvdata->attn_data.data) {
 		/* First grab the data passed by the transport device */
-		if (rmi_dev->xport->attn_size < ob_len) {
+		if (drvdata->attn_data.size < ob_len) {
 			dev_warn(&fn->dev, "F03 interrupted, but data is missing!\n");
 			return 0;
 		}
-		memcpy(obs, rmi_dev->xport->attn_data, ob_len);
+		memcpy(obs, drvdata->attn_data.data, ob_len);
-		rmi_dev->xport->attn_data += ob_len;
-		rmi_dev->xport->attn_size -= ob_len;
+		drvdata->attn_data.data += ob_len;
+		drvdata->attn_data.size -= ob_len;
 	} else {
 		/* Grab all of the data registers, and check them for data */
 		ret = rmi_read_block(fn->rmi_dev, data_addr + RMI_F03_OB_OFFSET,
drivers/input/rmi4/rmi_f11.c +6 -6
index 44fc275..bc5e37f 100644
@@ -1284,19 +1284,19 @@ static int rmi_f11_attention(struct rmi_function *fn, unsigned long *irq_bits)
 	int error;
 	int valid_bytes = f11->sensor.pkt_size;
-	if (rmi_dev->xport->attn_data) {
+	if (drvdata->attn_data.data) {
 		/*
 		 * The valid data in the attention report is less then
 		 * expected. Only process the complete fingers.
 		 */
-		if (f11->sensor.attn_size > rmi_dev->xport->attn_size)
-			valid_bytes = rmi_dev->xport->attn_size;
+		if (f11->sensor.attn_size > drvdata->attn_data.size)
+			valid_bytes = drvdata->attn_data.size;
 		else
 			valid_bytes = f11->sensor.attn_size;
-		memcpy(f11->sensor.data_pkt, rmi_dev->xport->attn_data,
+		memcpy(f11->sensor.data_pkt, drvdata->attn_data.data,
 			valid_bytes);
-		rmi_dev->xport->attn_data += f11->sensor.attn_size;
-		rmi_dev->xport->attn_size -= f11->sensor.attn_size;
+		drvdata->attn_data.data += f11->sensor.attn_size;
+		drvdata->attn_data.size -= f11->sensor.attn_size;
 	} else {
 		error = rmi_read_block(rmi_dev,
 				data_base_addr, f11->sensor.data_pkt,
drivers/input/rmi4/rmi_f12.c +22 -21
index 82a4964..8c5360c 100644
@@ -208,19 +208,20 @@ static int rmi_f12_attention(struct rmi_function *fn,
 {
 	int retval;
 	struct rmi_device *rmi_dev = fn->rmi_dev;
+	struct rmi_driver_data *drvdata = dev_get_drvdata(&rmi_dev->dev);
 	struct f12_data *f12 = dev_get_drvdata(&fn->dev);
 	struct rmi_2d_sensor *sensor = &f12->sensor;
 	int valid_bytes = sensor->pkt_size;
-	if (rmi_dev->xport->attn_data) {
-		if (sensor->attn_size > rmi_dev->xport->attn_size)
-			valid_bytes = rmi_dev->xport->attn_size;
+	if (drvdata->attn_data.data) {
+		if (sensor->attn_size > drvdata->attn_data.size)
+			valid_bytes = drvdata->attn_data.size;
 		else
 			valid_bytes = sensor->attn_size;
-		memcpy(sensor->data_pkt, rmi_dev->xport->attn_data,
+		memcpy(sensor->data_pkt, drvdata->attn_data.data,
 			valid_bytes);
-		rmi_dev->xport->attn_data += sensor->attn_size;
-		rmi_dev->xport->attn_size -= sensor->attn_size;
+		drvdata->attn_data.data += sensor->attn_size;
+		drvdata->attn_data.size -= sensor->attn_size;
 	} else {
 		retval = rmi_read_block(rmi_dev, f12->data_addr,
 					sensor->data_pkt, sensor->pkt_size);
@@ -323,7 +324,7 @@ static int rmi_f12_probe(struct rmi_function *fn)
 	const struct rmi_register_desc_item *item;
 	struct rmi_2d_sensor *sensor;
 	struct rmi_device_platform_data *pdata = rmi_get_platform_data(rmi_dev);
-	struct rmi_transport_dev *xport = rmi_dev->xport;
+	struct rmi_driver_data *drvdata = dev_get_drvdata(&rmi_dev->dev);
 	u16 data_offset = 0;
 	rmi_dbg(RMI_DEBUG_FN, &fn->dev, "%s\n", __func__);
@@ -422,7 +423,7 @@ static int rmi_f12_probe(struct rmi_function *fn)
 	 * HID attention reports.
 	 */
 	item = rmi_get_register_desc_item(&f12->data_reg_desc, 0);
-	if (item && !xport->attn_data)
+	if (item && !drvdata->attn_data.data)
 		data_offset += item->reg_size;
 	item = rmi_get_register_desc_item(&f12->data_reg_desc, 1);
@@ -436,15 +437,15 @@ static int rmi_f12_probe(struct rmi_function *fn)
 	}
 	item = rmi_get_register_desc_item(&f12->data_reg_desc, 2);
-	if (item && !xport->attn_data)
+	if (item && !drvdata->attn_data.data)
 		data_offset += item->reg_size;
 	item = rmi_get_register_desc_item(&f12->data_reg_desc, 3);
-	if (item && !xport->attn_data)
+	if (item && !drvdata->attn_data.data)
 		data_offset += item->reg_size;
 	item = rmi_get_register_desc_item(&f12->data_reg_desc, 4);
-	if (item && !xport->attn_data)
+	if (item && !drvdata->attn_data.data)
 		data_offset += item->reg_size;
 	item = rmi_get_register_desc_item(&f12->data_reg_desc, 5);
@@ -456,22 +457,22 @@ static int rmi_f12_probe(struct rmi_function *fn)
 	}
 	item = rmi_get_register_desc_item(&f12->data_reg_desc, 6);
-	if (item && !xport->attn_data) {
+	if (item && !drvdata->attn_data.data) {
 		f12->data6 = item;
 		f12->data6_offset = data_offset;
 		data_offset += item->reg_size;
 	}
 	item = rmi_get_register_desc_item(&f12->data_reg_desc, 7);
-	if (item && !xport->attn_data)
+	if (item && !drvdata->attn_data.data)
 		data_offset += item->reg_size;
 	item = rmi_get_register_desc_item(&f12->data_reg_desc, 8);
-	if (item && !xport->attn_data)
+	if (item && !drvdata->attn_data.data)
 		data_offset += item->reg_size;
 	item = rmi_get_register_desc_item(&f12->data_reg_desc, 9);
-	if (item && !xport->attn_data) {
+	if (item && !drvdata->attn_data.data) {
 		f12->data9 = item;
 		f12->data9_offset = data_offset;
 		data_offset += item->reg_size;
@@ -480,27 +481,27 @@ static int rmi_f12_probe(struct rmi_function *fn)
 	}
 	item = rmi_get_register_desc_item(&f12->data_reg_desc, 10);
-	if (item && !xport->attn_data)
+	if (item && !drvdata->attn_data.data)
 		data_offset += item->reg_size;
 	item = rmi_get_register_desc_item(&f12->data_reg_desc, 11);
-	if (item && !xport->attn_data)
+	if (item && !drvdata->attn_data.data)
 		data_offset += item->reg_size;
 	item = rmi_get_register_desc_item(&f12->data_reg_desc, 12);
-	if (item && !xport->attn_data)
+	if (item && !drvdata->attn_data.data)
 		data_offset += item->reg_size;
 	item = rmi_get_register_desc_item(&f12->data_reg_desc, 13);
-	if (item && !xport->attn_data)
+	if (item && !drvdata->attn_data.data)
 		data_offset += item->reg_size;
 	item = rmi_get_register_desc_item(&f12->data_reg_desc, 14);
-	if (item && !xport->attn_data)
+	if (item && !drvdata->attn_data.data)
 		data_offset += item->reg_size;
 	item = rmi_get_register_desc_item(&f12->data_reg_desc, 15);
-	if (item && !xport->attn_data) {
+	if (item && !drvdata->attn_data.data) {
 		f12->data15 = item;
 		f12->data15_offset = data_offset;
 		data_offset += item->reg_size;
drivers/input/rmi4/rmi_f30.c +6 -5
index f696137..f4b491e 100644
@@ -99,6 +99,7 @@ static int rmi_f30_attention(struct rmi_function *fn, unsigned long *irq_bits)
 {
 	struct f30_data *f30 = dev_get_drvdata(&fn->dev);
 	struct rmi_device *rmi_dev = fn->rmi_dev;
+	struct rmi_driver_data *drvdata = dev_get_drvdata(&rmi_dev->dev);
 	int retval;
 	int gpiled = 0;
 	int value = 0;
@@ -109,15 +110,15 @@ static int rmi_f30_attention(struct rmi_function *fn, unsigned long *irq_bits)
 		return 0;
 	/* Read the gpi led data. */
-	if (rmi_dev->xport->attn_data) {
-		if (rmi_dev->xport->attn_size < f30->register_count) {
+	if (drvdata->attn_data.data) {
+		if (drvdata->attn_data.size < f30->register_count) {
 			dev_warn(&fn->dev, "F30 interrupted, but data is missing\n");
 			return 0;
 		}
-		memcpy(f30->data_regs, rmi_dev->xport->attn_data,
+		memcpy(f30->data_regs, drvdata->attn_data.data,
 			f30->register_count);
-		rmi_dev->xport->attn_data += f30->register_count;
-		rmi_dev->xport->attn_size -= f30->register_count;
+		drvdata->attn_data.data += f30->register_count;
+		drvdata->attn_data.size -= f30->register_count;
 	} else {
 		retval = rmi_read_block(rmi_dev, fn->fd.data_base_addr,
 			f30->data_regs, f30->register_count);
include/linux/rmi.h +2 -3
index 1d48656..ac910f7 100644
@@ -272,9 +272,6 @@ struct rmi_transport_dev {
 	struct rmi_device_platform_data pdata;
 	struct input_dev *input;
-
-	void *attn_data;
-	int attn_size;
 };
 /**
@@ -364,6 +361,8 @@ struct rmi_driver_data {
 	bool enabled;
 	struct mutex enabled_mutex;
+
+	struct rmi4_attn_data attn_data;
 	DECLARE_KFIFO(attn_fifo, struct rmi4_attn_data, 16);
 };
Signature · 1 line
Dmitry
#10 lore raw

PATCH v2 5/7 HID: rmi: Make hid-rmi a transport driver for synaptics-rmi4

In reply to Benjamin Tissoires

From: Andrew Duggan <[email protected]>

The Synaptics RMI4 driver provides support for RMI4 devices. Instead of duplicating the RMI4 processing code, make hid-rmi a transport driver and register it with the Synaptics RMI4 core.

---

no changes in v2

---
 drivers/hid/Kconfig   |   4 +
 drivers/hid/hid-rmi.c | 973 ++++++++------------------------------------------
 2 files changed, 144 insertions(+), 833 deletions(-)
drivers/hid/Kconfig +4 -0
index 69f2b2f..d9847f2 100644
@@ -786,6 +786,10 @@ config HID_SUNPLUS
 config HID_RMI
 	tristate "Synaptics RMI4 device support"
 	depends on HID
+	select RMI4_CORE
+	select RMI4_F11
+	select RMI4_F12
+	select RMI4_F30
 	---help---
 	Support for Synaptics RMI4 touchpads.
 	Say Y here if you have a Synaptics RMI4 touchpads over i2c-hid or usbhid
drivers/hid/hid-rmi.c +140 -833

1,168 lines not on this page · raw message

Signature · 1 line
2.9.3
#11 lore raw

PATCH v2 6/7 HID: rmi: Handle all Synaptics touchpads using hid-rmi

In reply to Benjamin Tissoires

From: Andrew Duggan <[email protected]>

With the addition of HID and F12 support in the synaptics-rmi4 driver touchpads which had been using the hid-multitouch driver can now be support by the synaptics-rmi4 via hid-rmi. The advantage is that additional data can be reported from the RMI registers which is not available in the Microsoft Precision Touchpad collection.

---

no changes in v2

---
 drivers/hid/hid-core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hid/hid-core.c +2 -1
index cff060b..6a35d8c 100644
@@ -826,7 +826,8 @@ static int hid_scan_report(struct hid_device *hid)
 		hid->group = HID_GROUP_WACOM;
 		break;
 	case USB_VENDOR_ID_SYNAPTICS:
-		if (hid->group == HID_GROUP_GENERIC)
+		if (hid->group == HID_GROUP_GENERIC ||
+		    hid->group == HID_GROUP_MULTITOUCH_WIN_8)
 			if ((parser->scan_flags & HID_SCAN_FLAG_VENDOR_SPECIFIC)
 			    && (parser->scan_flags & HID_SCAN_FLAG_GD_POINTER))
 				/*
Signature · 1 line
2.9.3
#12 lore raw

PATCH v2 7/7 HID: rmi: Support the Lenovo Thinkpad X1 Tablet dock using hid-rmi

In reply to Benjamin Tissoires

From: Andrew Duggan <[email protected]>

---

no changes in v2

---
 drivers/hid/hid-core.c | 1 +
 drivers/hid/hid-ids.h  | 1 +
 drivers/hid/hid-rmi.c  | 1 +
 3 files changed, 3 insertions(+)
drivers/hid/hid-core.c +1 -0
index 6a35d8c..34fdfd7 100644
@@ -2127,6 +2127,7 @@ static const struct hid_device_id hid_have_special_driver[] = {
 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO, USB_DEVICE_ID_NINTENDO_WIIMOTE2) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_RAZER, USB_DEVICE_ID_RAZER_BLADE_14) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM6533) },
+	{ HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_X1_COVER) },
 	{ }
 };
 
drivers/hid/hid-ids.h +1 -0
index ec277b9..961ee4f 100644
@@ -623,6 +623,7 @@
 #define USB_DEVICE_ID_LENOVO_CUSBKBD	0x6047
 #define USB_DEVICE_ID_LENOVO_CBTKBD	0x6048
 #define USB_DEVICE_ID_LENOVO_TPPRODOCK	0x6067
+#define USB_DEVICE_ID_LENOVO_X1_COVER	0x6085
 
 #define USB_VENDOR_ID_LG		0x1fd2
 #define USB_DEVICE_ID_LG_MULTITOUCH	0x0064
drivers/hid/hid-rmi.c +1 -0
index 57ed592..11825ad 100644
@@ -715,6 +715,7 @@ static void rmi_remove(struct hid_device *hdev)
 static const struct hid_device_id rmi_id[] = {
 	{ HID_USB_DEVICE(USB_VENDOR_ID_RAZER, USB_DEVICE_ID_RAZER_BLADE_14),
 		.driver_data = RMI_DEVICE_HAS_PHYS_BUTTONS },
+	{ HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_X1_COVER) },
 	{ HID_DEVICE(HID_BUS_ANY, HID_GROUP_RMI, HID_ANY_ID, HID_ANY_ID) },
 	{ }
 };
Signature · 1 line
2.9.3
#13 lore raw
In reply to Benjamin Tissoires

Hi Benjamin,

Thanks for adding the irq handling to hid-rmi and fifo support in the core.

Quoted 9 lines · Benjamin Tissoires

Hi,

Well, the cleanup part of the series has already been applied, so I guess this is just "switch hid-rmi to rmi_core".

The series applies on top of Dmitri's synaptics-rmi4 branch

However, as mentioned in v1, I'd like to get some testings from actually integrated devices befor we flip the switch for HID. Andrew, Dennis?

Tested on a Dell XPS 13 9343 and a Lenovo S21e. That covers the two generations of our HID touchpads which have gone into production.

Andrew

Quoted 38 lines

Function f03 has been tested in the rmi4-smbus, and the attn data API on a test synaptics board.

Cheers,
Benjamin

Andrew Duggan (3):
HID: rmi: Make hid-rmi a transport driver for synaptics-rmi4
HID: rmi: Handle all Synaptics touchpads using hid-rmi
HID: rmi: Support the Lenovo Thinkpad X1 Tablet dock using hid-rmi

Benjamin Tissoires (2):
Input: synaptics-rmi4 - allow to add attention data
Input: synaptics-rmi4 - store the attn data in the driver

Dennis Wassenberg (1):
Input: synaptics-rmi4 - F03: grab data passed by transport device

Lyude Paul (1):
Input: synaptics-rmi4 - add support for F03

  drivers/hid/Kconfig             |   4 +
  drivers/hid/hid-core.c          |   4 +-
  drivers/hid/hid-ids.h           |   1 +
  drivers/hid/hid-rmi.c           | 974 ++++++----------------------------------
  drivers/input/rmi4/Kconfig      |   9 +
  drivers/input/rmi4/Makefile     |   1 +
  drivers/input/rmi4/rmi_bus.c    |   3 +
  drivers/input/rmi4/rmi_driver.c |  50 ++-
  drivers/input/rmi4/rmi_driver.h |   1 +
  drivers/input/rmi4/rmi_f03.c    | 251 +++++++++++
  drivers/input/rmi4/rmi_f11.c    |  12 +-
  drivers/input/rmi4/rmi_f12.c    |  43 +-
  drivers/input/rmi4/rmi_f30.c    |  11 +-
  include/linux/rmi.h             |  16 +-
  14 files changed, 508 insertions(+), 872 deletions(-)

create mode 100644 drivers/input/rmi4/rmi_f03.c

maintainer
#14 lore raw
In reply to Benjamin Tissoires
Quoted 5 lines · Benjamin Tissoires

Hi,

Well, the cleanup part of the series has already been applied, so I guess this is just "switch hid-rmi to rmi_core".

Quoted 7 lines

The series applies on top of Dmitri's synaptics-rmi4 branch

However, as mentioned in v1, I'd like to get some testings from actually integrated devices befor we flip the switch for HID. Andrew, Dennis?

Function f03 has been tested in the rmi4-smbus, and the attn data API on a test synaptics board.

So I applied all Synaptics changes to my synaptics-rmi4 branch, but what do we do with HID changes? Jiri, do you want to pull this branch or do you want me to apply HID changes? Or wait for the next cycle?

Thanks.

Signature · 1 line
Dmitry