Skip to contentSkip to conversation

Input: Add I2C attached EETI EXC3000 multi touch driver

PATCH In review Ahmet Inan 2 participants 7 messages Sep 20, 2017 – Sep 28, 2017

Subsystems (3)
lore
Share & tools
lore

Ahmet Inan

author
#0 lore raw

PATCH 1/1 Input: Add I2C attached EETI EXC3000 multi touch driver

The 3000 series have a new protocol which allows to report up to 5 points in a single 66 byte frame. One must always read in 66 byte frames. To support up to 10 points, two consecutive frames need to be read:
The first frame says how many points until sync.
The second frame must say zero points or be discarded.

To be able to work with the higher 400KHz I2C bus rate, one must successfully send a special package prior _each_ read or the controller will refuse to cooperate.

It is important not to rely on the i2c_master_recv return value:
Ignoring failed transfers sometimes causes hanging touch events, as the controller thinks that the transfer succeeded and won't resend the event.

This is a minimal implementation based on egalax_i2c.c (which can be found on the internet) and egalax_ts.c but without the vendor interface and no power management support.

---
 .../bindings/input/touchscreen/exc3000.txt         |  18 +++
 drivers/input/touchscreen/Kconfig                  |  10 ++
 drivers/input/touchscreen/Makefile                 |   1 +
 drivers/input/touchscreen/exc3000.c                | 154 +++++++++++++++++++++
 4 files changed, 183 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/touchscreen/exc3000.txt
 create mode 100644 drivers/input/touchscreen/exc3000.c
Documentation/devicetree/bindings/input/touchscreen/exc3000.txt new file +18 -0
new file mode 100644
index 000000000000..9b6f0919abd0
@@ -0,0 +1,18 @@
+* EETI EXC3000 Multiple Touch Controller
+
+Required properties:
+- compatible: must be "eeti,exc3000"
+- reg: i2c slave address
+- interrupt-parent: the phandle for the interrupt controller
+- interrupts: touch controller interrupt
+- irq-gpios: the gpio pin to be used as irq pin
+
+Example:
+
+	exc3000@2a {
+		compatible = "eeti,exc3000";
+		reg = <0x2a>;
+		interrupt-parent = <&gpio1>;
+		interrupts = <9 2>;
+		irq-gpios = <&gpio1 9 0>;
+	};
drivers/input/touchscreen/Kconfig +10 -0
index 0bf78ff1ae88..9ea2d9287b38 100644
@@ -314,6 +314,16 @@ config TOUCHSCREEN_EGALAX_SERIAL
 	  To compile this driver as a module, choose M here: the
 	  module will be called egalax_ts_serial.
 
+config TOUCHSCREEN_EXC3000
+	tristate "EETI EXC3000 multi-touch panel support"
+	depends on I2C
+	help
+	  Say Y here to enable support for I2C connected EETI
+	  EXC3000 multi-touch panels.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called exc3000.
+
 config TOUCHSCREEN_FUJITSU
 	tristate "Fujitsu serial touchscreen"
 	select SERIO
drivers/input/touchscreen/Makefile +1 -0
index f720bc30ada9..48118379fee7 100644
@@ -38,6 +38,7 @@ obj-$(CONFIG_TOUCHSCREEN_ELAN)		+= elants_i2c.o
 obj-$(CONFIG_TOUCHSCREEN_ELO)		+= elo.o
 obj-$(CONFIG_TOUCHSCREEN_EGALAX)	+= egalax_ts.o
 obj-$(CONFIG_TOUCHSCREEN_EGALAX_SERIAL)	+= egalax_ts_serial.o
+obj-$(CONFIG_TOUCHSCREEN_EXC3000)	+= exc3000.o
 obj-$(CONFIG_TOUCHSCREEN_FUJITSU)	+= fujitsu_ts.o
 obj-$(CONFIG_TOUCHSCREEN_GOODIX)	+= goodix.o
 obj-$(CONFIG_TOUCHSCREEN_ILI210X)	+= ili210x.o
drivers/input/touchscreen/exc3000.c new file +154 -0

154 lines not on this page · raw message

Signature · 1 line
2.11.0
maintainer
#1 lore raw

Hi Ahmet,

Quoted 6 lines · Ahmet Inan

The 3000 series have a new protocol which allows to report up to 5 points in a single 66 byte frame. One must always read in 66 byte frames. To support up to 10 points, two consecutive frames need to be read:
The first frame says how many points until sync.
The second frame must say zero points or be discarded.

Quoted 7 lines

To be able to work with the higher 400KHz I2C bus rate, one must successfully send a special package prior _each_ read or the controller will refuse to cooperate.

It is important not to rely on the i2c_master_recv return value:
Ignoring failed transfers sometimes causes hanging touch events, as the controller thinks that the transfer succeeded and won't resend the event.

This statement worries me, because you are basically end up reporting garbage. Does the controller sends all active contacts in each frame, or only changed ones? You can use INPUT_MT_DROP_UNUSED to let input core automatically drop contacts that were not reported within the last frame. And fire up a timer to release everything if last transfer errors out.

Quoted 89 lines

This is a minimal implementation based on egalax_i2c.c (which can be found on the internet) and egalax_ts.c but without the vendor interface and no power management support.

---
 .../bindings/input/touchscreen/exc3000.txt         |  18 +++
 drivers/input/touchscreen/Kconfig                  |  10 ++
 drivers/input/touchscreen/Makefile                 |   1 +
 drivers/input/touchscreen/exc3000.c                | 154 +++++++++++++++++++++
 4 files changed, 183 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/touchscreen/exc3000.txt
 create mode 100644 drivers/input/touchscreen/exc3000.c
Documentation/devicetree/bindings/input/touchscreen/exc3000.txt new file +18 -0
new file mode 100644
index 000000000000..9b6f0919abd0
@@ -0,0 +1,18 @@
+* EETI EXC3000 Multiple Touch Controller
+
+Required properties:
+- compatible: must be "eeti,exc3000"
+- reg: i2c slave address
+- interrupt-parent: the phandle for the interrupt controller
+- interrupts: touch controller interrupt
+- irq-gpios: the gpio pin to be used as irq pin
+
+Example:
+
+	exc3000@2a {
+		compatible = "eeti,exc3000";
+		reg = <0x2a>;
+		interrupt-parent = <&gpio1>;
+		interrupts = <9 2>;
+		irq-gpios = <&gpio1 9 0>;
+	};
drivers/input/touchscreen/Kconfig +10 -0
index 0bf78ff1ae88..9ea2d9287b38 100644
@@ -314,6 +314,16 @@ config TOUCHSCREEN_EGALAX_SERIAL
 	  To compile this driver as a module, choose M here: the
 	  module will be called egalax_ts_serial.
 
+config TOUCHSCREEN_EXC3000
+	tristate "EETI EXC3000 multi-touch panel support"
+	depends on I2C
+	help
+	  Say Y here to enable support for I2C connected EETI
+	  EXC3000 multi-touch panels.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called exc3000.
+
 config TOUCHSCREEN_FUJITSU
 	tristate "Fujitsu serial touchscreen"
 	select SERIO
drivers/input/touchscreen/Makefile +1 -0
index f720bc30ada9..48118379fee7 100644
@@ -38,6 +38,7 @@ obj-$(CONFIG_TOUCHSCREEN_ELAN)		+= elants_i2c.o
 obj-$(CONFIG_TOUCHSCREEN_ELO)		+= elo.o
 obj-$(CONFIG_TOUCHSCREEN_EGALAX)	+= egalax_ts.o
 obj-$(CONFIG_TOUCHSCREEN_EGALAX_SERIAL)	+= egalax_ts_serial.o
+obj-$(CONFIG_TOUCHSCREEN_EXC3000)	+= exc3000.o
 obj-$(CONFIG_TOUCHSCREEN_FUJITSU)	+= fujitsu_ts.o
 obj-$(CONFIG_TOUCHSCREEN_GOODIX)	+= goodix.o
 obj-$(CONFIG_TOUCHSCREEN_ILI210X)	+= ili210x.o
drivers/input/touchscreen/exc3000.c new file +11 -0
new file mode 100644
index 000000000000..c8a1a8b04bf2
@@ -0,0 +1,154 @@
+/*
+ * Driver for I2C connected EETI EXC3000 multiple touch controller
+ *
+ * Copyright (C) 2017 Ahmet Inan <[email protected]>
+ *
+ * minimal implementation based on egalax_ts.c and egalax_i2c.c
+ *
+ * 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.
+ */

drivers/input/touchscreen/exc3000.c line 21

Quoted 10 lines
drivers/input/touchscreen/exc3000.c new file +10 -0
+
+#include <linux/module.h>
+#include <linux/interrupt.h>
+#include <linux/i2c.h>
+#include <linux/input.h>
+#include <linux/irq.h>
+#include <linux/input/mt.h>
+
+#define NUM_SLOTS 10
+#define PER_FRAME 5

What per frame?

#define EXC3000_NUM_SLOTS 10
#define EXC3000_SLOTS_PER_FRAME 5

drivers/input/touchscreen/exc3000.c line 28

Quoted 7 lines
drivers/input/touchscreen/exc3000.c new file +7 -0
+#define LEN_FRAME 66
+#define LEN_POINT 10
+
+struct exc3000_data {
+	struct i2c_client *client;
+	struct input_dev *input;
+	unsigned char buf[2 * LEN_FRAME];

u8 for byte data.

drivers/input/touchscreen/exc3000.c line 39

Quoted 11 lines
drivers/input/touchscreen/exc3000.c new file +11 -0
+};
+
+static void exc3000_process(struct input_dev *input,
+		unsigned char *buf, int num)
+{
+	while (num--) {
+		int dn, id, x, y;
+
+		dn = buf[0] & 1;
+		id = buf[1];
+		x = (buf[3] << 8) | buf[2];
		get_unaligned_le16()

drivers/input/touchscreen/exc3000.c line 40

Quoted 1 line
drivers/input/touchscreen/exc3000.c new file +1 -0
+		y = (buf[5] << 8) | buf[4];
		get_unaligned_le16()

Also, why parse these for released contacts?

Quoted 14 lines
drivers/input/touchscreen/exc3000.c new file +14 -0
+		buf += LEN_POINT;
+		if (id >= NUM_SLOTS)
+			continue;
+		input_mt_slot(input, id);
+		input_mt_report_slot_state(input, MT_TOOL_FINGER, dn);
+		if (dn) {
+			input_report_abs(input, ABS_MT_POSITION_X, x);
+			input_report_abs(input, ABS_MT_POSITION_Y, y);
+		}
+	}
+}
+
+static int exc3000_read(struct i2c_client *client, unsigned char *buf)
+{

drivers/input/touchscreen/exc3000.c line 64

Quoted 10 lines
drivers/input/touchscreen/exc3000.c new file +10 -0
+	if (i2c_master_send(client, "'", 2) != 2)
+		return 1;
+	memset(buf, 0, LEN_FRAME);
+	i2c_master_recv(client, buf, LEN_FRAME);
+	return buf[0] != 0x42 || buf[1] != 0x00 || buf[2] != 0x06;
+}
+
+static irqreturn_t exc3000_interrupt(int irq, void *dev_id)
+{
+	struct exc3000_data *data = (struct exc3000_data *)dev_id;

No need to cast.

Quoted 5 lines
drivers/input/touchscreen/exc3000.c new file +5 -0
+	struct i2c_client *client = data->client;
+	struct input_dev *input = data->input;
+	unsigned char *buf = data->buf;
+
+	if (exc3000_read(client, buf) || !buf[3] || buf[3] > NUM_SLOTS)

drivers/input/touchscreen/exc3000.c line 79

Quoted 10 lines
drivers/input/touchscreen/exc3000.c new file +10 -0
+		return IRQ_HANDLED;
+	if (buf[3] <= PER_FRAME) {
+		exc3000_process(input, buf + 4, buf[3]);
+	} else {
+		if (exc3000_read(client, buf + LEN_FRAME) || buf[LEN_FRAME + 3])
+			return IRQ_HANDLED;
+		exc3000_process(input, buf + 4, PER_FRAME);
+		exc3000_process(input, buf + LEN_FRAME + 4, buf[3] - PER_FRAME);
+	}
+	input_mt_report_pointer_emulation(input, true);

Not needed with right flags to input_mt_init_slots (INPUT_MT_DIRECT) and call to input_mt_sync_frame() here.

drivers/input/touchscreen/exc3000.c line 91

Quoted 12 lines
drivers/input/touchscreen/exc3000.c new file +12 -0
+	input_sync(input);
+	return IRQ_HANDLED;
+}
+
+static int exc3000_probe(struct i2c_client *client,
+		const struct i2c_device_id *id)
+{
+	struct exc3000_data *data;
+	struct input_dev *input;
+	int error;
+
+	data = (struct exc3000_data *)devm_kzalloc(&client->dev,

No need to cast.

drivers/input/touchscreen/exc3000.c line 92

Quoted 1 line
drivers/input/touchscreen/exc3000.c new file +1 -0
+			sizeof(struct exc3000_data), GFP_KERNEL);

sizeof(*data)

drivers/input/touchscreen/exc3000.c line 103

Quoted 11 lines
drivers/input/touchscreen/exc3000.c new file +11 -0
+	if (!data)
+		return -ENOMEM;
+
+	input = devm_input_allocate_device(&client->dev);
+	if (!input)
+		return -ENOMEM;
+
+	input->name = "EETI EXC3000 Touch Screen";
+	input->id.bustype = BUS_I2C;
+
+	__set_bit(EV_ABS, input->evbit);

Not needed as input_set_abs_params() does this for you.

drivers/input/touchscreen/exc3000.c line 105

Quoted 2 lines
drivers/input/touchscreen/exc3000.c new file +2 -0
+	__set_bit(EV_KEY, input->evbit);
+	__set_bit(BTN_TOUCH, input->keybit);
	input_set_capability(input, EV_KEY, BTN_TOUCH);

drivers/input/touchscreen/exc3000.c line 109

Quoted 4 lines
drivers/input/touchscreen/exc3000.c new file +4 -0
+	input_set_abs_params(input, ABS_X, 0, 4096, 0, 0);
+	input_set_abs_params(input, ABS_Y, 0, 4096, 0, 0);
+	input_set_abs_params(input, ABS_MT_POSITION_X, 0, 4096, 0, 0);
+	input_set_abs_params(input, ABS_MT_POSITION_Y, 0, 4096, 0, 0);

touchscreen_parse_properties() ?

drivers/input/touchscreen/exc3000.c line 110

Quoted 1 line
drivers/input/touchscreen/exc3000.c new file +1 -0
+	input_mt_init_slots(input, NUM_SLOTS, 0);

Needs error handling. INPUT_MT_DIRECT?

drivers/input/touchscreen/exc3000.c line 121

Quoted 11 lines
drivers/input/touchscreen/exc3000.c new file +11 -0
+
+	error = input_register_device(input);
+	if (error)
+		return error;
+
+	data->input = input;
+	data->client = client;
+	i2c_set_clientdata(client, data);
+
+	error = devm_request_threaded_irq(&client->dev, client->irq, NULL,
+			exc3000_interrupt, IRQF_TRIGGER_LOW | IRQF_ONESHOT,

Do not specify trigger explicitly, rely on platform to set it up.

drivers/input/touchscreen/exc3000.c line 133

Quoted 12 lines
drivers/input/touchscreen/exc3000.c new file +12 -0
+			client->name, data);
+	if (error)
+		return error;
+
+	return 0;
+}
+
+static const struct i2c_device_id exc3000_id[] = {
+	{ "exc3000", 0 },
+	{ }
+};
+

#ifdef CONFIG_OF

drivers/input/touchscreen/exc3000.c line 137

Quoted 4 lines
drivers/input/touchscreen/exc3000.c new file +4 -0
+static const struct of_device_id exc3000_dt_ids[] = {
+	{ .compatible = "eeti,exc3000" },
+	{ }
+};

#endif

drivers/input/touchscreen/exc3000.c line 144

Quoted 7 lines
drivers/input/touchscreen/exc3000.c new file +7 -0
+
+MODULE_DEVICE_TABLE(i2c, exc3000_id);
+
+static struct i2c_driver exc3000_driver = {
+	.driver = {
+		.name	= "exc3000",
+		.of_match_table = exc3000_dt_ids,

of_match_ptr()

Quoted 13 lines
drivers/input/touchscreen/exc3000.c new file +10 -0
+	},
+	.id_table	= exc3000_id,
+	.probe		= exc3000_probe,
+};
+
+module_i2c_driver(exc3000_driver);
+
+MODULE_AUTHOR("Ahmet Inan <[email protected]>");
+MODULE_DESCRIPTION("I2C connected EETI EXC3000 multiple touch controller driver");
+MODULE_LICENSE("GPL");
Signature · 1 line
2.11.0

Thanks.

Signature · 1 line
Dmitry
#2 lore raw

Dear Dmitry,

Quoted 10 lines
Quoted 3 lines

It is important not to rely on the i2c_master_recv return value:
Ignoring failed transfers sometimes causes hanging touch events, as the controller thinks that the transfer succeeded and won't resend the event.

This statement worries me, because you are basically end up reporting garbage. Does the controller sends all active contacts in each frame, or only changed ones? You can use INPUT_MT_DROP_UNUSED to let input core automatically drop contacts that were not reported within the last frame. And fire up a timer to release everything if last transfer errors out.

Thank you for the suggestions. I indeed felt uncomfortable about ignoring the return value of i2c_master_recv() but INPUT_MT_DROP_UNUSED helped and now it works awesome!

Quoted 6 lines

drivers/input/touchscreen/exc3000.c line 109

Quoted 4 lines
drivers/input/touchscreen/exc3000.c new file +4 -0
+	input_set_abs_params(input, ABS_X, 0, 4096, 0, 0);
+	input_set_abs_params(input, ABS_Y, 0, 4096, 0, 0);
+	input_set_abs_params(input, ABS_MT_POSITION_X, 0, 4096, 0, 0);
+	input_set_abs_params(input, ABS_MT_POSITION_Y, 0, 4096, 0, 0);

touchscreen_parse_properties() ?

Need do wrap my head around this. I've send you a new patch with all (but this one) suggested improvements. I will send send you a follow-up patch with touchscreen_parse_properties() if you're OK with the current patch and want to merge it.

Best Regards,

Ahmet

#3 lore raw

Dear Dmitry,

please hold merging my EXC3000 patch - something just bit me hard and now I get unexplainable hangs since reboot.

Will send you a fixed patch.

Best Regards,

Ahmet

#4 lore raw

Dear Dmitry,

Quoted 2 lines

please hold merging my EXC3000 patch - something just bit me hard and now I get unexplainable hangs since reboot.

Found out what the hang was: need to specify "active low level-sensitive" in the dt. Fixed it also in the documentation.

I've send you another patch and sorry for the noise ..

Best Regards,

Ahmet

#5 lore raw
In reply to DISTEC Inan, Ahmet

Dear Dmitry,

Quoted 8 lines
Quoted 6 lines

drivers/input/touchscreen/exc3000.c line 109

Quoted 4 lines
drivers/input/touchscreen/exc3000.c new file +4 -0
+	input_set_abs_params(input, ABS_X, 0, 4096, 0, 0);
+	input_set_abs_params(input, ABS_Y, 0, 4096, 0, 0);
+	input_set_abs_params(input, ABS_MT_POSITION_X, 0, 4096, 0, 0);
+	input_set_abs_params(input, ABS_MT_POSITION_Y, 0, 4096, 0, 0);

touchscreen_parse_properties() ?

Need do wrap my head around this.

Thank you for suggesting the use of touchscreen_parse_properties():
Using touchscreen_report_pos() made it very easy to add inversion and swapping support of axes to the driver.

I've also added the new properties from touchscreen.txt to exc3000.txt.

Best Regards,

Ahmet

#6 lore raw
In reply to DISTEC Inan, Ahmet

Dear Dmitry,

Quoted 10 lines
Quoted 10 lines
Quoted 3 lines

It is important not to rely on the i2c_master_recv return value:
Ignoring failed transfers sometimes causes hanging touch events, as the controller thinks that the transfer succeeded and won't resend the event.

This statement worries me, because you are basically end up reporting garbage. Does the controller sends all active contacts in each frame, or only changed ones? You can use INPUT_MT_DROP_UNUSED to let input core automatically drop contacts that were not reported within the last frame. And fire up a timer to release everything if last transfer errors out.

Quoted 3 lines

Thank you for the suggestions. I indeed felt uncomfortable about ignoring the return value of i2c_master_recv() but INPUT_MT_DROP_UNUSED helped and now it works awesome!

I've just got another EXC3000-Controller-Board to play with and it looks like I need to add that timer you suggested:
I still get sporadically hanging touches with this one :(
So I will send you another patch the moment I figured out how.

Best Regards,

Ahmet