All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 0/3] input: add DFROBOT touchscreen controller
@ 2021-12-16 23:35 Tim Harvey
  2021-12-16 23:35 ` [RFC PATCH 1/3] dt-bindings: Add vendor prefix for DFRobot Tim Harvey
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Tim Harvey @ 2021-12-16 23:35 UTC (permalink / raw)
  To: linux-input, Rob Herring, Dmitry Torokhov; +Cc: 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.

This controller lacks an interrupt and does not send UP events so
polling mode is used and event ID tracking is used to emulate UP events.

This series adds dt bindings and a standalone driver for this touch
controller as opposed to an RFC series I sent out that attempts to add
support to the existing edt-ft5x06 driver.

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

Tim Harvey (3):
  dt-bindings: Add vendor prefix for DFRobot
  dt-bindings: touchscreen: Add dfr0550 bindings
  input: touchscreen: add dfr0550 support

 .../bindings/input/touchscreen/dfr0550.yaml   |  53 +++++
 .../devicetree/bindings/vendor-prefixes.yaml  |   2 +
 MAINTAINERS                                   |   5 +
 drivers/input/touchscreen/Kconfig             |  12 +
 drivers/input/touchscreen/Makefile            |   1 +
 drivers/input/touchscreen/dfr0550.c           | 208 ++++++++++++++++++
 6 files changed, 281 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/touchscreen/dfr0550.yaml
 create mode 100644 drivers/input/touchscreen/dfr0550.c

-- 
2.17.1


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

* [RFC PATCH 1/3] dt-bindings: Add vendor prefix for DFRobot
  2021-12-16 23:35 [RFC PATCH 0/3] input: add DFROBOT touchscreen controller Tim Harvey
@ 2021-12-16 23:35 ` Tim Harvey
  2021-12-16 23:35 ` [RFC PATCH 2/3] dt-bindings: touchscreen: Add dfr0550 bindings Tim Harvey
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Tim Harvey @ 2021-12-16 23:35 UTC (permalink / raw)
  To: linux-input, Rob Herring, Dmitry Torokhov; +Cc: Tim Harvey

Add vendor prefix for DFRobot (http://dfrobot.com)

Signed-off-by: Tim Harvey <tharvey@gateworks.com>
---
 Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/vendor-prefixes.yaml b/Documentation/devicetree/bindings/vendor-prefixes.yaml
index a867f7102c35..02ea75bb452d 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.yaml
+++ b/Documentation/devicetree/bindings/vendor-prefixes.yaml
@@ -293,6 +293,8 @@ patternProperties:
     description: Devantech, Ltd.
   "^dfi,.*":
     description: DFI Inc.
+  "^dfr,.*":
+    description: DFRobot.
   "^dh,.*":
     description: DH electronics GmbH
   "^difrnce,.*":
-- 
2.17.1


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

* [RFC PATCH 2/3] dt-bindings: touchscreen: Add dfr0550 bindings
  2021-12-16 23:35 [RFC PATCH 0/3] input: add DFROBOT touchscreen controller Tim Harvey
  2021-12-16 23:35 ` [RFC PATCH 1/3] dt-bindings: Add vendor prefix for DFRobot Tim Harvey
@ 2021-12-16 23:35 ` Tim Harvey
  2021-12-16 23:35 ` [RFC PATCH 3/3] input: touchscreen: add dfr0550 support Tim Harvey
  2022-01-21 17:25 ` [RFC PATCH 0/3] input: add DFROBOT touchscreen controller Tim Harvey
  3 siblings, 0 replies; 5+ messages in thread
From: Tim Harvey @ 2021-12-16 23:35 UTC (permalink / raw)
  To: linux-input, Rob Herring, Dmitry Torokhov; +Cc: Tim Harvey

This adds device tree bindings for the touchscreen controller used on
the DFRobot DFR0550 touchscreen.

Signed-off-by: Tim Harvey <tharvey@gateworks.com>
---
 .../bindings/input/touchscreen/dfr0550.yaml   | 53 +++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/touchscreen/dfr0550.yaml

diff --git a/Documentation/devicetree/bindings/input/touchscreen/dfr0550.yaml b/Documentation/devicetree/bindings/input/touchscreen/dfr0550.yaml
new file mode 100644
index 000000000000..77373211b4d8
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/touchscreen/dfr0550.yaml
@@ -0,0 +1,53 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/input/touchscreen/dfr0550.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: DFRobot DFR0550 Touch Controller Bindings
+
+maintainers:
+  - Tim Harvey <tharvey@gateworks.com>
+
+allOf:
+  - $ref: touchscreen.yaml#
+
+properties:
+  compatible:
+    const: dfr,dfr0550
+
+  reg:
+    maxItems: 1
+
+  poll-interval:
+    description: Poll interval time in milliseconds.
+    $ref: /schemas/types.yaml#/definitions/uint32
+
+  touchscreen-size-x: true
+  touchscreen-size-y: true
+  touchscreen-fuzz-x: true
+  touchscreen-fuzz-y: true
+  touchscreen-inverted-x: true
+  touchscreen-inverted-y: true
+  touchscreen-swapped-x-y: true
+
+additionalProperties: false
+
+required:
+  - compatible
+  - reg
+  - poll-interval
+
+examples:
+  - |
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      touchscreen@38 {
+        compatible = "dfr,dfr0550";
+        reg = <0x38>;
+      };
+    };
+
+...
-- 
2.17.1


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

* [RFC PATCH 3/3] input: touchscreen: add dfr0550 support
  2021-12-16 23:35 [RFC PATCH 0/3] input: add DFROBOT touchscreen controller Tim Harvey
  2021-12-16 23:35 ` [RFC PATCH 1/3] dt-bindings: Add vendor prefix for DFRobot Tim Harvey
  2021-12-16 23:35 ` [RFC PATCH 2/3] dt-bindings: touchscreen: Add dfr0550 bindings Tim Harvey
@ 2021-12-16 23:35 ` Tim Harvey
  2022-01-21 17:25 ` [RFC PATCH 0/3] input: add DFROBOT touchscreen controller Tim Harvey
  3 siblings, 0 replies; 5+ messages in thread
From: Tim Harvey @ 2021-12-16 23:35 UTC (permalink / raw)
  To: linux-input, Rob Herring, Dmitry Torokhov; +Cc: 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 so this is a polling
driver.

Signed-off-by: Tim Harvey <tharvey@gateworks.com>
---
 MAINTAINERS                         |   5 +
 drivers/input/touchscreen/Kconfig   |  12 ++
 drivers/input/touchscreen/Makefile  |   1 +
 drivers/input/touchscreen/dfr0550.c | 208 ++++++++++++++++++++++++++++
 4 files changed, 226 insertions(+)
 create mode 100644 drivers/input/touchscreen/dfr0550.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 3b79fd441dde..07d581447f4b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -5458,6 +5458,11 @@ F:	include/net/devlink.h
 F:	include/uapi/linux/devlink.h
 F:	net/core/devlink.c
 
+DFR0550 TOUCHSCREEN DRIVER
+M:	Tim Harvey <harvey.tim@gateworks.com>
+S:	Supported
+F:	drivers/input/touchscreen/dfr0550.c
+
 DH ELECTRONICS IMX6 DHCOM BOARD SUPPORT
 M:	Christoph Niedermaier <cniedermaier@dh-electronics.com>
 L:	kernel@dh-electronics.com
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
index d4e74738c5a8..438742314157 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -309,6 +309,18 @@ config TOUCHSCREEN_DA9052
 	  To compile this driver as a module, choose M here: the
 	  module will be called da9052_tsi.
 
+config TOUCHSCREEN_DFR0550
+	tristate "Touchscreen support for DFROBOT DFR0550"
+	depends on I2C
+	help
+	  Say Y here to enable the support for the touchscreen found
+	  on DFROBOT DFR0550 and DFR0678 displays.
+
+	  If unsure, say N.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called dfr0550.
+
 config TOUCHSCREEN_DYNAPRO
 	tristate "Dynapro serial touchscreen"
 	select SERIO
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile
index 7d34100f7f22..8212314975cb 100644
--- a/drivers/input/touchscreen/Makefile
+++ b/drivers/input/touchscreen/Makefile
@@ -31,6 +31,7 @@ obj-$(CONFIG_TOUCHSCREEN_CYTTSP4_I2C)	+= cyttsp4_i2c.o cyttsp_i2c_common.o
 obj-$(CONFIG_TOUCHSCREEN_CYTTSP4_SPI)	+= cyttsp4_spi.o
 obj-$(CONFIG_TOUCHSCREEN_DA9034)	+= da9034-ts.o
 obj-$(CONFIG_TOUCHSCREEN_DA9052)	+= da9052_tsi.o
+obj-$(CONFIG_TOUCHSCREEN_DFR0550)	+= dfr0550.o
 obj-$(CONFIG_TOUCHSCREEN_DYNAPRO)	+= dynapro.o
 obj-$(CONFIG_TOUCHSCREEN_EDT_FT5X06)	+= edt-ft5x06.o
 obj-$(CONFIG_TOUCHSCREEN_HAMPSHIRE)	+= hampshire.o
diff --git a/drivers/input/touchscreen/dfr0550.c b/drivers/input/touchscreen/dfr0550.c
new file mode 100644
index 000000000000..a337efd36bb6
--- /dev/null
+++ b/drivers/input/touchscreen/dfr0550.c
@@ -0,0 +1,208 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Driver 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 so this is a polling driver.
+ */
+
+#include <linux/i2c.h>
+#include <linux/input.h>
+#include <linux/input/mt.h>
+#include <linux/input/touchscreen.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+
+#define TOUCH_EVENT_DOWN		0x00
+#define TOUCH_EVENT_UP			0x01
+#define TOUCH_EVENT_ON			0x02
+#define TOUCH_EVENT_RESERVED		0x03
+
+struct dfr0550_ts_data {
+	struct i2c_client *client;
+	struct input_dev *input;
+	struct touchscreen_properties prop;
+	int max_support_points;
+	unsigned int known_ids;
+	u16 num_x;
+	u16 num_y;
+};
+
+static int dfr0550_i2c_read(struct i2c_client *client, u8 reg, u8 *buf, int len)
+{
+	struct i2c_msg msgs[2];
+	int ret;
+
+	msgs[0].flags = 0;
+	msgs[0].addr  = client->addr;
+	msgs[0].len = 1;
+	msgs[0].buf = &reg;
+
+	msgs[1].flags = I2C_M_RD;
+	msgs[1].addr  = client->addr;
+	msgs[1].len = len;
+	msgs[1].buf = buf;
+
+	ret = i2c_transfer(client->adapter, msgs, 2);
+		return reg < 0 ? ret : (ret != ARRAY_SIZE(msgs) ? -EIO : 0);
+}
+
+static void dfr0550_ts_poll(struct input_dev *input)
+{
+	struct dfr0550_ts_data *ts = input_get_drvdata(input);
+	unsigned int active_ids = 0;
+	int i, type, x, y, id, points;
+	long released_ids;
+	u8 buf[4];
+	int error;
+
+	error = dfr0550_i2c_read(ts->client, 0x02, buf, 1);
+	if (error)
+		goto error;
+	/* official rpi 7in display with ft5x06 shows 0xff until touched */
+	if (buf[0] == 0xff)
+		return;
+	points = min(buf[0] & 0xf, ts->max_support_points);
+
+	for (i = 0; i < points; i++) {
+		error = dfr0550_i2c_read(ts->client, 3+6*i, buf, 4);
+		if (error)
+			goto error;
+
+		type = (buf[0] >> 6) & 0x3;
+		id = (buf[2] >> 4) & 0xf;
+		x = ((buf[0] & 0xf) << 8) + buf[1];
+		y = ((buf[2] & 0xf) << 8) + buf[3];
+
+		active_ids |= BIT(id);
+		if (type == TOUCH_EVENT_UP ||
+		    type == TOUCH_EVENT_ON) {
+			input_mt_slot(input, id);
+			input_mt_report_slot_state(input, MT_TOOL_FINGER, 1);
+			touchscreen_report_pos(input, &ts->prop, x, y, true);
+		}
+	}
+
+	released_ids = ts->known_ids & ~active_ids;
+	for_each_set_bit(i, &released_ids, ts->max_support_points) {
+		input_mt_slot(input, i);
+		input_mt_report_slot_inactive(input);
+	}
+	ts->known_ids = active_ids;
+
+	input_mt_sync_frame(input);
+	input_mt_report_pointer_emulation(input, true);
+	input_sync(input);
+
+	return;
+
+error:
+	dev_err_ratelimited(&ts->client->dev,
+			    "Unable to fetch data, error: %d\n", error);
+}
+
+static int dfr0550_ts_probe(struct i2c_client *client,
+			    const struct i2c_device_id *id)
+{
+	struct dfr0550_ts_data *tsdata;
+	struct input_dev *input;
+	u32 poll_interval = 0;
+	int error;
+
+	tsdata = devm_kzalloc(&client->dev, sizeof(*tsdata), GFP_KERNEL);
+	if (!tsdata)
+		return -ENOMEM;
+
+	input = devm_input_allocate_device(&client->dev);
+	if (!input) {
+		dev_err(&client->dev, "failed to allocate input device.\n");
+		return -ENOMEM;
+	}
+
+	tsdata->client = client;
+	tsdata->input = input;
+
+	input->name = "dfr0550-ts";
+	input->id.bustype = BUS_I2C;
+	input->dev.parent = &client->dev;
+
+	input_set_abs_params(input, ABS_MT_POSITION_X,
+			     0, tsdata->num_x * 64 - 1, 0, 0);
+	input_set_abs_params(input, ABS_MT_POSITION_Y,
+			     0, tsdata->num_y * 64 - 1, 0, 0);
+
+	touchscreen_parse_properties(input, true, &tsdata->prop);
+
+	tsdata->max_support_points = 5;
+	error = input_mt_init_slots(input, tsdata->max_support_points,
+				INPUT_MT_DIRECT);
+	if (error) {
+		dev_err(&client->dev, "Unable to init MT slots.\n");
+		return error;
+	}
+
+	i2c_set_clientdata(client, tsdata);
+
+	device_property_read_u32(&client->dev, "poll-interval",
+				 &poll_interval);
+	error = input_setup_polling(input, dfr0550_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);
+
+	error = input_register_device(input);
+	if (error)
+		return error;
+
+	dev_info(&client->dev, "Polling device at %dms\n", poll_interval);
+
+	return 0;
+}
+
+static int dfr0550_ts_remove(struct i2c_client *client)
+{
+	return 0;
+}
+
+static const struct i2c_device_id dfr0550_ts_id[] = {
+	{ .name = "dfr,dfr0550" },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(i2c, dfr0550_ts_id);
+
+static const struct of_device_id dfr0550_of_match[] = {
+	{ .compatible = "dfr,dfr0550", },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, dfr0550_of_match);
+
+static struct i2c_driver dfr0550_ts_driver = {
+	.driver = {
+		.name = "dfr0550",
+		.of_match_table = dfr0550_of_match,
+		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
+	},
+	.id_table = dfr0550_ts_id,
+	.probe    = dfr0550_ts_probe,
+	.remove   = dfr0550_ts_remove,
+};
+
+module_i2c_driver(dfr0550_ts_driver);
+
+MODULE_AUTHOR("Tim Harvey <tharvey@gateworks.com>");
+MODULE_DESCRIPTION("DFROBOT DFR0550 I2C Touchscreen Driver");
+MODULE_LICENSE("GPL v2");
-- 
2.17.1


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

* Re: [RFC PATCH 0/3] input: add DFROBOT touchscreen controller
  2021-12-16 23:35 [RFC PATCH 0/3] input: add DFROBOT touchscreen controller Tim Harvey
                   ` (2 preceding siblings ...)
  2021-12-16 23:35 ` [RFC PATCH 3/3] input: touchscreen: add dfr0550 support Tim Harvey
@ 2022-01-21 17:25 ` Tim Harvey
  3 siblings, 0 replies; 5+ messages in thread
From: Tim Harvey @ 2022-01-21 17:25 UTC (permalink / raw)
  To: linux-input, Rob Herring, Dmitry Torokhov

On Thu, Dec 16, 2021 at 3:36 PM Tim Harvey <tharvey@gateworks.com> wrote:
>
> 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.
>
> This controller lacks an interrupt and does not send UP events so
> polling mode is used and event ID tracking is used to emulate UP events.
>
> This series adds dt bindings and a standalone driver for this touch
> controller as opposed to an RFC series I sent out that attempts to add
> support to the existing edt-ft5x06 driver.
>
> Tim
> [1] - https://www.dfrobot.com/product-2193.html
> [2] - https://www.dfrobot.com/product-1784.html
>
> Tim Harvey (3):
>   dt-bindings: Add vendor prefix for DFRobot
>   dt-bindings: touchscreen: Add dfr0550 bindings
>   input: touchscreen: add dfr0550 support
>
>  .../bindings/input/touchscreen/dfr0550.yaml   |  53 +++++
>  .../devicetree/bindings/vendor-prefixes.yaml  |   2 +
>  MAINTAINERS                                   |   5 +
>  drivers/input/touchscreen/Kconfig             |  12 +
>  drivers/input/touchscreen/Makefile            |   1 +
>  drivers/input/touchscreen/dfr0550.c           | 208 ++++++++++++++++++
>  6 files changed, 281 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/input/touchscreen/dfr0550.yaml
>  create mode 100644 drivers/input/touchscreen/dfr0550.c
>

Any feedback on this?

The other approach I posted an RFC series for was to add support to
the existing edt-ft5x06 driver [1].

Best regards,

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

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

end of thread, other threads:[~2022-01-21 17:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-16 23:35 [RFC PATCH 0/3] input: add DFROBOT touchscreen controller Tim Harvey
2021-12-16 23:35 ` [RFC PATCH 1/3] dt-bindings: Add vendor prefix for DFRobot Tim Harvey
2021-12-16 23:35 ` [RFC PATCH 2/3] dt-bindings: touchscreen: Add dfr0550 bindings Tim Harvey
2021-12-16 23:35 ` [RFC PATCH 3/3] input: touchscreen: add dfr0550 support Tim Harvey
2022-01-21 17:25 ` [RFC PATCH 0/3] input: add DFROBOT touchscreen controller Tim Harvey

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.