Skip to contentSkip to conversation

input: edt-ft5x06: add support for DFROBOT touch controller to

RFC PATCH In review Tim Harvey 2 participants 7 messages Dec 16, 2021 – Jan 21, 2022

Subsystems (3)
lore
Share & tools
lore

Tim Harvey

author
#0 lore raw

cover input: edt-ft5x06: add support for DFROBOT touch controller to

The DFROBOT DFR0678 [1] and DFR0550 [2] touchscreen displays are meant to be compatible with the official RaspberryPi 7in display. However instead of directly conntecting the FT5x06 touch controller to the I2C bus going to the host processor they route it through an MCU and emulate a virtual FT5x06 controller but don't do a very good job at it. The method the RaspberryPi firmware used to read the touch data is supported (which consists of reading R2 to get the number of touch points, then reading 4 bytes of data for each point in discrete I2C transactions. If you try to use the FT5x06 driver which reads all registers starting at R0 at once you will get invalid point data.

Additionally the RaspberryPi displays like these do not have a touch controller IRQ so polling mode has to be added.

Also additionally these controllers do not appear to send UP events so an additional patch slightly modified from the raspberry-pi kernel is used to track ID's and report up events.

I'm sending this series as an RFC as I'm not really clear if this is the best approach vs just adding a new touchscreen driver (which I have prepared and will probably send in another RFC).

Tim
[1] - https://www.dfrobot.com/product-2193.html
[2] - https://www.dfrobot.com/product-1784.html

Tim Harvey (4):
dt-bindings: input: touchscreen: edt-ft5x06: add poll-interval
input: edt-ft5x06 - add polled input support
input: edt-ft5x06 - add support for DFROBOT touch controllers
input: edt-ft5x06 - Handle unreliable TOUCH_UP events

 .../input/touchscreen/edt-ft5x06.yaml         |   7 +-
 drivers/input/touchscreen/edt-ft5x06.c        | 144 ++++++++++++++----
 2 files changed, 123 insertions(+), 28 deletions(-)
Signature · 1 line
2.17.1
author
#1 lore raw

RFC PATCH 1/4 dt-bindings: input: touchscreen: edt-ft5x06: add poll-interval

Some devices might not provide an interrupt line for the touchscreen. In that case the driver defaults to using a polled interface.

Cc Nicolas Saenz Julienne <[email protected]>
---
 .../devicetree/bindings/input/touchscreen/edt-ft5x06.yaml   | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/input/touchscreen/edt-ft5x06.yaml +5 -1
index 2e8da7470513..a0d4dabf03b8 100644
@@ -47,6 +47,11 @@ properties:
   interrupts:
     maxItems: 1
 
+  poll-interval:
+    description: Poll interval time in milliseconds, only relevant if no
+                 interrupt was provided.
+    $ref: /schemas/types.yaml#/definitions/uint32
+
   reset-gpios:
     maxItems: 1
 
@@ -99,7 +104,6 @@ additionalProperties: false
 required:
   - compatible
   - reg
-  - interrupts
 
 examples:
   - |
Signature · 1 line
2.17.1
#2 lore raw

Re: [RFC PATCH 1/4] dt-bindings: input: touchscreen: edt-ft5x06: add poll-interval

Quoted 1 line · Tim Harvey

Please CC the DT list.

Quoted 14 lines

Some devices might not provide an interrupt line for the touchscreen. In that case the driver defaults to using a polled interface.

Cc Nicolas Saenz Julienne <[email protected]>
---
 .../devicetree/bindings/input/touchscreen/edt-ft5x06.yaml   | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/input/touchscreen/edt-ft5x06.yaml +0 -0
index 2e8da7470513..a0d4dabf03b8 100644

Documentation/devicetree/bindings/input/touchscreen/edt-ft5x06.yaml properties: · line 53

Quoted 7 lines
Documentation/devicetree/bindings/input/touchscreen/edt-ft5x06.yaml +4 -0
@@ -47,6 +47,11 @@ properties:
   interrupts:
     maxItems: 1
 
+  poll-interval:
+    description: Poll interval time in milliseconds, only relevant if no
+                 interrupt was provided.
+    $ref: /schemas/types.yaml#/definitions/uint32

Reference input.yaml so we aren't redefining this property.

Quoted 15 lines
Documentation/devicetree/bindings/input/touchscreen/edt-ft5x06.yaml +1 -2
+
   reset-gpios:
     maxItems: 1
 
@@ -99,7 +104,6 @@ additionalProperties: false
 required:
   - compatible
   - reg
-  - interrupts
 
 examples:
   - |
--

2.17.1

author
#3 lore raw

RFC PATCH 2/4 input: edt-ft5x06 - add polled input support

In reply to Tim Harvey

Some hardware configurations might pass on providing an interrupt line. In that case there is always the option to use a polled input approach. This patch adapts the driver for it.

The polled approach is only triggered if no interrupt is provided by the firmware or platform data.

Cc Nicolas Saenz Julienne <[email protected]>
Cc Dave Stevenson <[email protected]>
---
 drivers/input/touchscreen/edt-ft5x06.c | 63 ++++++++++++++++++--------
 1 file changed, 45 insertions(+), 18 deletions(-)
drivers/input/touchscreen/edt-ft5x06.c +45 -18
index bb2e1cbffba7..06662f2258b1 100644
@@ -187,9 +187,8 @@ static bool edt_ft5x06_ts_check_crc(struct edt_ft5x06_ts_data *tsdata,
 	return true;
 }
 
-static irqreturn_t edt_ft5x06_ts_isr(int irq, void *dev_id)
+static void edt_ft5x06_process(struct edt_ft5x06_ts_data *tsdata)
 {
-	struct edt_ft5x06_ts_data *tsdata = dev_id;
 	struct device *dev = &tsdata->client->dev;
 	u8 cmd;
 	u8 rdbuf[63];
@@ -216,7 +215,7 @@ static irqreturn_t edt_ft5x06_ts_isr(int irq, void *dev_id)
 		break;
 
 	default:
-		goto out;
+		return;
 	}
 
 	memset(rdbuf, 0, sizeof(rdbuf));
@@ -228,7 +227,7 @@ static irqreturn_t edt_ft5x06_ts_isr(int irq, void *dev_id)
 	if (error) {
 		dev_err_ratelimited(dev, "Unable to fetch data, error: %d\n",
 				    error);
-		goto out;
+		return;
 	}
 
 	/* M09/M12 does not send header or CRC */
@@ -238,11 +237,11 @@ static irqreturn_t edt_ft5x06_ts_isr(int irq, void *dev_id)
 			dev_err_ratelimited(dev,
 					"Unexpected header: %02x%02x%02x!\n",
 					rdbuf[0], rdbuf[1], rdbuf[2]);
-			goto out;
+			return;
 		}
 
 		if (!edt_ft5x06_ts_check_crc(tsdata, rdbuf, datalen))
-			goto out;
+			return;
 	}
 
 	for (i = 0; i < tsdata->max_support_points; i++) {
@@ -274,11 +273,23 @@ static irqreturn_t edt_ft5x06_ts_isr(int irq, void *dev_id)
 
 	input_mt_report_pointer_emulation(tsdata->input, true);
 	input_sync(tsdata->input);
+}
 
-out:
+static irqreturn_t edt_ft5x06_ts_isr(int irq, void *dev_id)
+{
+	struct edt_ft5x06_ts_data *tsdata = dev_id;
+
+	edt_ft5x06_process(tsdata);
 	return IRQ_HANDLED;
 }
 
+static void edt_ft5x06_ts_poll(struct input_dev *dev)
+{
+	struct edt_ft5x06_ts_data *tsdata = input_get_drvdata(dev);
+
+	edt_ft5x06_process(tsdata);
+}
+
 static int edt_ft5x06_register_write(struct edt_ft5x06_ts_data *tsdata,
 				     u8 addr, u8 value)
 {
@@ -1080,6 +1091,7 @@ static int edt_ft5x06_ts_probe(struct i2c_client *client,
 	u8 buf[2] = { 0xfc, 0x00 };
 	struct input_dev *input;
 	unsigned long irq_flags;
+	u32 poll_interval = 0;
 	int error;
 	char fw_version[EDT_NAME_LEN];
 
@@ -1234,17 +1246,32 @@ static int edt_ft5x06_ts_probe(struct i2c_client *client,
 
 	i2c_set_clientdata(client, tsdata);
 
-	irq_flags = irq_get_trigger_type(client->irq);
-	if (irq_flags == IRQF_TRIGGER_NONE)
-		irq_flags = IRQF_TRIGGER_FALLING;
-	irq_flags |= IRQF_ONESHOT;
-
-	error = devm_request_threaded_irq(&client->dev, client->irq,
-					NULL, edt_ft5x06_ts_isr, irq_flags,
-					client->name, tsdata);
-	if (error) {
-		dev_err(&client->dev, "Unable to request touchscreen IRQ.\n");
-		return error;
+	device_property_read_u32(&client->dev, "poll-interval",
+				 &poll_interval);
+	if (poll_interval) {
+		error = input_setup_polling(input, edt_ft5x06_ts_poll);
+		if (error) {
+			dev_err(&client->dev,
+				"Unable to set up polling mode: %d\n", error);
+			return error;
+		}
+		input_set_drvdata(input, tsdata);
+		input_set_poll_interval(input, poll_interval);
+		dev_info(&client->dev, "Polling device at %dms\n",
+			 poll_interval);
+	} else {
+		irq_flags = irq_get_trigger_type(client->irq);
+		if (irq_flags == IRQF_TRIGGER_NONE)
+			irq_flags = IRQF_TRIGGER_FALLING;
+		irq_flags |= IRQF_ONESHOT;
+
+		error = devm_request_threaded_irq(&client->dev, client->irq,
+						NULL, edt_ft5x06_ts_isr, irq_flags,
+						client->name, tsdata);
+		if (error) {
+			dev_err(&client->dev, "Unable to request touchscreen IRQ.\n");
+			return error;
+		}
 	}
 
 	error = devm_device_add_group(&client->dev, &edt_ft5x06_attr_group);
Signature · 1 line
2.17.1
author
#4 lore raw

RFC PATCH 3/4 input: edt-ft5x06 - add support for DFROBOT touch controllers

In reply to Tim Harvey

Add support for the touch controller found on a DFROBOT DFR0550/DFR0776 touchscreen display.

These touchscreen displays are intended to be compatible with the official Raspberry Pi 7in display which has an FTx06 touch controller directly attached to the 15pin connector to the host processor. However these displays have an FTx06 touch controller that connected to an I2C master on a STM32F103 micro controller which polls the FTx06 and emulates a virtual I2C device connected to the 15pin connector to the host processor.

The emulated FTx06 implements a subset of the FTx06 register set but must be read with individual transactions between reading the number of points and the point data itself.

Additionally there is no IRQ made available.

---
 .../input/touchscreen/edt-ft5x06.yaml         |  1 +
 drivers/input/touchscreen/edt-ft5x06.c        | 65 ++++++++++++++++---
 2 files changed, 58 insertions(+), 8 deletions(-)
Documentation/devicetree/bindings/input/touchscreen/edt-ft5x06.yaml +1 -0
index a0d4dabf03b8..45a9cb1d4f14 100644
@@ -40,6 +40,7 @@ properties:
       - edt,edt-ft5506
       - evervision,ev-ft5726
       - focaltech,ft6236
+      - dfr,dfr0550
 
   reg:
     maxItems: 1
drivers/input/touchscreen/edt-ft5x06.c +57 -8

150 lines not on this page · raw message

Signature · 1 line
2.17.1
author
#5 lore raw

RFC PATCH 4/4 input: edt-ft5x06 - Handle unreliable TOUCH_UP events

In reply to Tim Harvey

The ft5x06 is unreliable in sending touch up events, so some touch IDs can become stuck in the detected state.

Ensure that IDs that are unreported by the controller are released.

---
 drivers/input/touchscreen/edt-ft5x06.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/input/touchscreen/edt-ft5x06.c +15 -1
index a3622d6e8e65..53906fcbaa51 100644
@@ -126,6 +126,7 @@ struct edt_ft5x06_ts_data {
 	int offset_y;
 	int report_rate;
 	int max_support_points;
+	unsigned int known_ids;
 
 	char name[EDT_NAME_LEN];
 
@@ -198,6 +199,8 @@ static void edt_ft5x06_process(struct edt_ft5x06_ts_data *tsdata)
 	int offset, tplen, datalen, crclen;
 	int error;
 	int num_points;
+	unsigned int active_ids = 0, known_ids = tsdata->known_ids;
+	long released_ids;
 
 	switch (tsdata->version) {
 	case EDT_M06:
@@ -297,10 +300,21 @@ static void edt_ft5x06_process(struct edt_ft5x06_ts_data *tsdata)
 
 		input_mt_slot(tsdata->input, id);
 		if (input_mt_report_slot_state(tsdata->input, MT_TOOL_FINGER,
-					       type != TOUCH_EVENT_UP))
+					       type != TOUCH_EVENT_UP)) {
 			touchscreen_report_pos(tsdata->input, &tsdata->prop,
 					       x, y, true);
+			active_ids |= BIT(id);
+		} else {
+			known_ids &= ~BIT(id);
+		}
+	}
+
+	released_ids = known_ids & ~active_ids;
+	for_each_set_bit_from(i, &released_ids, tsdata->max_support_points) {
+		input_mt_slot(tsdata->input, i);
+		input_mt_report_slot_inactive(tsdata->input);
 	}
+	tsdata->known_ids = active_ids;
 
 	input_mt_report_pointer_emulation(tsdata->input, true);
 	input_sync(tsdata->input);
Signature · 1 line
2.17.1
author
#6 lore raw
In reply to Tim Harvey
Quoted 33 lines · Tim Harvey

The DFROBOT DFR0678 [1] and DFR0550 [2] touchscreen displays are meant to be compatible with the official RaspberryPi 7in display. However instead of directly conntecting the FT5x06 touch controller to the I2C bus going to the host processor they route it through an MCU and emulate a virtual FT5x06 controller but don't do a very good job at it. The method the RaspberryPi firmware used to read the touch data is supported (which consists of reading R2 to get the number of touch points, then reading 4 bytes of data for each point in discrete I2C transactions. If you try to use the FT5x06 driver which reads all registers starting at R0 at once you will get invalid point data.

Additionally the RaspberryPi displays like these do not have a touch controller IRQ so polling mode has to be added.

Also additionally these controllers do not appear to send UP events so an additional patch slightly modified from the raspberry-pi kernel is used to track ID's and report up events.

I'm sending this series as an RFC as I'm not really clear if this is the best approach vs just adding a new touchscreen driver (which I have prepared and will probably send in another RFC).

Tim
[1] - https://www.dfrobot.com/product-2193.html
[2] - https://www.dfrobot.com/product-1784.html

Tim Harvey (4):
dt-bindings: input: touchscreen: edt-ft5x06: add poll-interval
input: edt-ft5x06 - add polled input support
input: edt-ft5x06 - add support for DFROBOT touch controllers
input: edt-ft5x06 - Handle unreliable TOUCH_UP events

Quoted 5 lines
 .../input/touchscreen/edt-ft5x06.yaml         |   7 +-
 drivers/input/touchscreen/edt-ft5x06.c        | 144 ++++++++++++++----
 2 files changed, 123 insertions(+), 28 deletions(-)

--

Any feedback on this?

The other approach I posted an RFC series for was to add a completely new driver [1]

Best regards,

Tim
[1] https://patchwork.kernel.org/project/linux-input/list/?series=596975