All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] Input: egalax_ts - clean up capability initialization
@ 2018-09-20 14:22 Lucas Stach
  2018-09-20 14:22 ` [PATCH 2/4] Input: egalax_ts - use touchscreen helpers Lucas Stach
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Lucas Stach @ 2018-09-20 14:22 UTC (permalink / raw)
  To: Dmitry Torokhov, Rob Herring
  Cc: linux-input, devicetree, patchwork-lst, kernel, Chris Healy

Just provide the proper flags to input_mt_init_slots(), which will
so the right thing and set the proper capability bits.

Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
---
 drivers/input/touchscreen/egalax_ts.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/input/touchscreen/egalax_ts.c b/drivers/input/touchscreen/egalax_ts.c
index 80e69bb8283e..5e7a60089c3d 100644
--- a/drivers/input/touchscreen/egalax_ts.c
+++ b/drivers/input/touchscreen/egalax_ts.c
@@ -199,17 +199,12 @@ static int egalax_ts_probe(struct i2c_client *client,
 	input_dev->name = "EETI eGalax Touch Screen";
 	input_dev->id.bustype = BUS_I2C;
 
-	__set_bit(EV_ABS, input_dev->evbit);
-	__set_bit(EV_KEY, input_dev->evbit);
-	__set_bit(BTN_TOUCH, input_dev->keybit);
-
-	input_set_abs_params(input_dev, ABS_X, 0, EGALAX_MAX_X, 0, 0);
-	input_set_abs_params(input_dev, ABS_Y, 0, EGALAX_MAX_Y, 0, 0);
 	input_set_abs_params(input_dev,
 			     ABS_MT_POSITION_X, 0, EGALAX_MAX_X, 0, 0);
 	input_set_abs_params(input_dev,
 			     ABS_MT_POSITION_Y, 0, EGALAX_MAX_Y, 0, 0);
-	input_mt_init_slots(input_dev, MAX_SUPPORT_POINTS, 0);
+	input_mt_init_slots(input_dev, MAX_SUPPORT_POINTS,
+			    INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED);
 
 	error = devm_request_threaded_irq(&client->dev, client->irq, NULL,
 					  egalax_ts_interrupt,
-- 
2.19.0

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

* [PATCH 2/4] Input: egalax_ts - use touchscreen helpers
  2018-09-20 14:22 [PATCH 1/4] Input: egalax_ts - clean up capability initialization Lucas Stach
@ 2018-09-20 14:22 ` Lucas Stach
  2018-09-20 14:22 ` [PATCH 3/4] Input: egalax_ts - add property for protocol version Lucas Stach
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Lucas Stach @ 2018-09-20 14:22 UTC (permalink / raw)
  To: Dmitry Torokhov, Rob Herring
  Cc: linux-input, devicetree, patchwork-lst, kernel, Chris Healy

Using those helpers the driver will support all the common OF
touchscreen properties like rotation and axis swap.

Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
---
 drivers/input/touchscreen/egalax_ts.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/input/touchscreen/egalax_ts.c b/drivers/input/touchscreen/egalax_ts.c
index 5e7a60089c3d..4c751f8f806d 100644
--- a/drivers/input/touchscreen/egalax_ts.c
+++ b/drivers/input/touchscreen/egalax_ts.c
@@ -25,6 +25,7 @@
 #include <linux/bitops.h>
 #include <linux/input/mt.h>
 #include <linux/of_gpio.h>
+#include <linux/input/touchscreen.h>
 
 /*
  * Mouse Mode: some panel may configure the controller to mouse mode,
@@ -52,13 +53,12 @@
 
 #define MAX_I2C_DATA_LEN	10
 
-#define EGALAX_MAX_X	32760
-#define EGALAX_MAX_Y	32760
 #define EGALAX_MAX_TRIES 100
 
 struct egalax_ts {
 	struct i2c_client		*client;
 	struct input_dev		*input_dev;
+	struct touchscreen_properties	props;
 };
 
 static irqreturn_t egalax_ts_interrupt(int irq, void *dev_id)
@@ -105,8 +105,7 @@ static irqreturn_t egalax_ts_interrupt(int irq, void *dev_id)
 		down ? "down" : "up", id, x, y, z);
 
 	if (down) {
-		input_report_abs(input_dev, ABS_MT_POSITION_X, x);
-		input_report_abs(input_dev, ABS_MT_POSITION_Y, y);
+		touchscreen_report_pos(input_dev, &ts->props, x, y, true);
 		input_report_abs(input_dev, ABS_MT_PRESSURE, z);
 	}
 
@@ -199,10 +198,14 @@ static int egalax_ts_probe(struct i2c_client *client,
 	input_dev->name = "EETI eGalax Touch Screen";
 	input_dev->id.bustype = BUS_I2C;
 
-	input_set_abs_params(input_dev,
-			     ABS_MT_POSITION_X, 0, EGALAX_MAX_X, 0, 0);
-	input_set_abs_params(input_dev,
-			     ABS_MT_POSITION_Y, 0, EGALAX_MAX_Y, 0, 0);
+	touchscreen_parse_properties(ts->input_dev, true, &ts->props);
+	if (!ts->props.max_x && !ts->props.max_y)
+		ts->props.max_x = ts->props.max_y = 32760;
+
+	input_set_abs_params(input_dev, ABS_MT_POSITION_X,
+			     0, ts->props.max_x, 0, 0);
+	input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
+			     0, ts->props.max_y, 0, 0);
 	input_mt_init_slots(input_dev, MAX_SUPPORT_POINTS,
 			    INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED);
 
-- 
2.19.0

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

* [PATCH 3/4] Input: egalax_ts - add property for protocol version
  2018-09-20 14:22 [PATCH 1/4] Input: egalax_ts - clean up capability initialization Lucas Stach
  2018-09-20 14:22 ` [PATCH 2/4] Input: egalax_ts - use touchscreen helpers Lucas Stach
@ 2018-09-20 14:22 ` Lucas Stach
  2018-09-24 22:28   ` Rob Herring
  2018-09-20 14:22 ` [PATCH 4/4] Input: egalax_ts - add support for new " Lucas Stach
  2018-11-05 17:19 ` [PATCH 1/4] Input: egalax_ts - clean up capability initialization Lucas Stach
  3 siblings, 1 reply; 6+ messages in thread
From: Lucas Stach @ 2018-09-20 14:22 UTC (permalink / raw)
  To: Dmitry Torokhov, Rob Herring
  Cc: linux-input, devicetree, patchwork-lst, kernel, Chris Healy

EETI changed the i2c protocol in an incompatible way at some point. The
documentation doesn't state if there is a way to autodetect the used
protocol. Thus we introduce a DT property to let the driver know about
the protocol version used by the touch controller.

Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
---
 .../devicetree/bindings/input/touchscreen/egalax-ts.txt   | 8 ++++++++
 drivers/input/touchscreen/egalax_ts.c                     | 4 ++++
 2 files changed, 12 insertions(+)

diff --git a/Documentation/devicetree/bindings/input/touchscreen/egalax-ts.txt b/Documentation/devicetree/bindings/input/touchscreen/egalax-ts.txt
index 92fb2620f5e2..41be6287589d 100644
--- a/Documentation/devicetree/bindings/input/touchscreen/egalax-ts.txt
+++ b/Documentation/devicetree/bindings/input/touchscreen/egalax-ts.txt
@@ -7,6 +7,13 @@ Required properties:
 - wakeup-gpios: the gpio pin to be used for waking up the controller
   and also used as irq pin
 
+Optional properties:
+- eeti,protocol-version: protocol version used by the controller
+	0: This is the default protocol used when the property is absent. This
+	protocol supports up to 5 touch points with 1 points per report.
+	1: Protocol supports up to 10 touch points with a maximum of 5 points
+	per report.
+
 Example:
 
 	touchscreen@4 {
@@ -15,4 +22,5 @@ Example:
 		interrupt-parent = <&gpio1>;
 		interrupts = <9 2>;
 		wakeup-gpios = <&gpio1 9 0>;
+		eeti,protocol-version = <1>;
 	};
diff --git a/drivers/input/touchscreen/egalax_ts.c b/drivers/input/touchscreen/egalax_ts.c
index 4c751f8f806d..0f924d8c17c8 100644
--- a/drivers/input/touchscreen/egalax_ts.c
+++ b/drivers/input/touchscreen/egalax_ts.c
@@ -58,6 +58,7 @@
 struct egalax_ts {
 	struct i2c_client		*client;
 	struct input_dev		*input_dev;
+	int				protocol_version;
 	struct touchscreen_properties	props;
 };
 
@@ -195,6 +196,9 @@ static int egalax_ts_probe(struct i2c_client *client,
 		return error;
 	}
 
+	of_property_read_u32(client->dev.of_node, "eeti,protocol-version",
+			     &ts->protocol_version);
+
 	input_dev->name = "EETI eGalax Touch Screen";
 	input_dev->id.bustype = BUS_I2C;
 
-- 
2.19.0

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

* [PATCH 4/4] Input: egalax_ts - add support for new protocol version
  2018-09-20 14:22 [PATCH 1/4] Input: egalax_ts - clean up capability initialization Lucas Stach
  2018-09-20 14:22 ` [PATCH 2/4] Input: egalax_ts - use touchscreen helpers Lucas Stach
  2018-09-20 14:22 ` [PATCH 3/4] Input: egalax_ts - add property for protocol version Lucas Stach
@ 2018-09-20 14:22 ` Lucas Stach
  2018-11-05 17:19 ` [PATCH 1/4] Input: egalax_ts - clean up capability initialization Lucas Stach
  3 siblings, 0 replies; 6+ messages in thread
From: Lucas Stach @ 2018-09-20 14:22 UTC (permalink / raw)
  To: Dmitry Torokhov, Rob Herring
  Cc: linux-input, devicetree, patchwork-lst, kernel, Chris Healy

This implements support for the new protocol that supports up to
10 touch slots spread over up to 2 i2c messages.

Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
---
 drivers/input/touchscreen/egalax_ts.c | 132 +++++++++++++++++++++-----
 1 file changed, 106 insertions(+), 26 deletions(-)

diff --git a/drivers/input/touchscreen/egalax_ts.c b/drivers/input/touchscreen/egalax_ts.c
index 0f924d8c17c8..ef25aec71d56 100644
--- a/drivers/input/touchscreen/egalax_ts.c
+++ b/drivers/input/touchscreen/egalax_ts.c
@@ -41,6 +41,7 @@
 #define REPORT_MODE_VENDOR		0x3
 /* Multiple Touch Mode */
 #define REPORT_MODE_MTTOUCH		0x4
+#define REPORT_MODE_MTTOUCH_NEW		0x6
 
 #define MAX_SUPPORT_POINTS		5
 
@@ -51,8 +52,9 @@
 #define EVENT_IN_RANGE		(0x1 << 1)
 #define EVENT_DOWN_UP		(0X1 << 0)
 
-#define MAX_I2C_DATA_LEN	10
+#define MAX_I2C_DATA_LEN	(64 + 2)
 
+#define EGALAX_POINT_SIZE	10
 #define EGALAX_MAX_TRIES 100
 
 struct egalax_ts {
@@ -62,41 +64,66 @@ struct egalax_ts {
 	struct touchscreen_properties	props;
 };
 
-static irqreturn_t egalax_ts_interrupt(int irq, void *dev_id)
+static int egalax_ts_handle_points(struct egalax_ts *ts, u8 *msg,
+				   int num_points)
 {
-	struct egalax_ts *ts = dev_id;
 	struct input_dev *input_dev = ts->input_dev;
 	struct i2c_client *client = ts->client;
-	u8 buf[MAX_I2C_DATA_LEN];
-	int id, ret, x, y, z;
-	int tries = 0;
-	bool down, valid;
-	u8 state;
+	bool down;
+	int i, id, x, y;
+
+	for (i = 0; i < min(MAX_SUPPORT_POINTS, num_points);
+	     i++, msg += EGALAX_POINT_SIZE, num_points--) {
+		down = !!(msg[0] & EVENT_DOWN_UP);
+		id = msg[1];
+		x = (msg[3] << 8) | msg[2];
+		y = (msg[5] << 8) | msg[4];
+
+		if (id > 10) {
+			dev_warn(&client->dev,
+				 "dropping out of range event %d\n", id);
+			continue;
+		}
+
+		input_mt_slot(input_dev, id);
+		input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, down);
+
+		dev_dbg(&client->dev, "%s id:%d x:%d y:%d",
+			down ? "down" : "up", id, x, y);
+
+		if (down)
+			touchscreen_report_pos(input_dev, &ts->props,
+					       x, y, true);
+	}
 
-	do {
-		ret = i2c_master_recv(client, buf, MAX_I2C_DATA_LEN);
-	} while (ret == -EAGAIN && tries++ < EGALAX_MAX_TRIES);
+	if (!num_points) {
+		input_mt_sync_frame(input_dev);
+		input_sync(input_dev);
+	}
 
-	if (ret < 0)
-		return IRQ_HANDLED;
+	return num_points;
+}
 
-	if (buf[0] != REPORT_MODE_MTTOUCH) {
-		/* ignore mouse events and vendor events */
-		return IRQ_HANDLED;
-	}
+static void egalax_ts_handle_points_legacy(struct egalax_ts *ts, u8 *msg)
+{
+	struct input_dev *input_dev = ts->input_dev;
+	struct i2c_client *client = ts->client;
+	bool down, valid;
+	int id, x, y, z;
+	u8 state;
 
-	state = buf[1];
-	x = (buf[3] << 8) | buf[2];
-	y = (buf[5] << 8) | buf[4];
-	z = (buf[7] << 8) | buf[6];
+	state = msg[0];
+	x = (msg[2] << 8) | msg[2];
+	y = (msg[4] << 8) | msg[3];
+	z = (msg[6] << 8) | msg[5];
 
 	valid = state & EVENT_VALID_MASK;
 	id = (state & EVENT_ID_MASK) >> EVENT_ID_OFFSET;
 	down = state & EVENT_DOWN_UP;
 
-	if (!valid || id > MAX_SUPPORT_POINTS) {
+	if (!valid || id > 5) {
 		dev_dbg(&client->dev, "point invalid\n");
-		return IRQ_HANDLED;
+		return;
 	}
 
 	input_mt_slot(input_dev, id);
@@ -112,6 +139,52 @@ static irqreturn_t egalax_ts_interrupt(int irq, void *dev_id)
 
 	input_mt_report_pointer_emulation(input_dev, true);
 	input_sync(input_dev);
+}
+
+static irqreturn_t egalax_ts_interrupt(int irq, void *dev_id)
+{
+	struct egalax_ts *ts = dev_id;
+	struct i2c_client *client = ts->client;
+	u8 buf[MAX_I2C_DATA_LEN], *payload;
+	int ret, num_points, tries = 0;
+	int remaining = 0;
+
+again:
+	do {
+		ret = i2c_master_recv(client, buf, MAX_I2C_DATA_LEN);
+	} while (ret == -EAGAIN && tries++ < EGALAX_MAX_TRIES);
+
+	if (ret < 0) {
+		dev_err_ratelimited(&client->dev,
+				    "reading touch info failed: %d\n", ret);
+		return IRQ_HANDLED;
+	}
+
+	if (ts->protocol_version == 0) {
+		payload = &buf[0];
+		num_points = 1;
+	} else {
+		payload = &buf[2];
+		num_points = buf[3];
+
+	}
+
+	switch (payload[0]) {
+	case REPORT_MODE_MTTOUCH:
+		egalax_ts_handle_points_legacy(ts, payload + 1);
+		break;
+	case REPORT_MODE_MTTOUCH_NEW:
+		if (!remaining)
+			remaining = payload[1];
+		remaining = egalax_ts_handle_points(ts, payload + 2, remaining);
+		break;
+	default:
+		/* ignore unknown report IDs */
+		break;
+	}
+
+	if (remaining)
+		goto again;
 
 	return IRQ_HANDLED;
 }
@@ -166,6 +239,7 @@ static int egalax_ts_probe(struct i2c_client *client,
 {
 	struct egalax_ts *ts;
 	struct input_dev *input_dev;
+	unsigned int max_points = MAX_SUPPORT_POINTS;
 	int error;
 
 	ts = devm_kzalloc(&client->dev, sizeof(struct egalax_ts), GFP_KERNEL);
@@ -203,14 +277,20 @@ static int egalax_ts_probe(struct i2c_client *client,
 	input_dev->id.bustype = BUS_I2C;
 
 	touchscreen_parse_properties(ts->input_dev, true, &ts->props);
-	if (!ts->props.max_x && !ts->props.max_y)
-		ts->props.max_x = ts->props.max_y = 32760;
+	if (!ts->props.max_x && !ts->props.max_y) {
+		if (ts->protocol_version == 0)
+			ts->props.max_x = ts->props.max_y = 32760;
+		else
+			ts->props.max_x = ts->props.max_y = 4095;
+	}
+	if (ts->protocol_version != 0)
+		max_points *= 2;
 
 	input_set_abs_params(input_dev, ABS_MT_POSITION_X,
 			     0, ts->props.max_x, 0, 0);
 	input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
 			     0, ts->props.max_y, 0, 0);
-	input_mt_init_slots(input_dev, MAX_SUPPORT_POINTS,
+	input_mt_init_slots(input_dev, max_points,
 			    INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED);
 
 	error = devm_request_threaded_irq(&client->dev, client->irq, NULL,
-- 
2.19.0

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

* Re: [PATCH 3/4] Input: egalax_ts - add property for protocol version
  2018-09-20 14:22 ` [PATCH 3/4] Input: egalax_ts - add property for protocol version Lucas Stach
@ 2018-09-24 22:28   ` Rob Herring
  0 siblings, 0 replies; 6+ messages in thread
From: Rob Herring @ 2018-09-24 22:28 UTC (permalink / raw)
  To: Lucas Stach
  Cc: Dmitry Torokhov, linux-input, devicetree, patchwork-lst, kernel,
	Chris Healy

On Thu, Sep 20, 2018 at 04:22:55PM +0200, Lucas Stach wrote:
> EETI changed the i2c protocol in an incompatible way at some point. The
> documentation doesn't state if there is a way to autodetect the used
> protocol. Thus we introduce a DT property to let the driver know about
> the protocol version used by the touch controller.
> 
> Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
> ---
>  .../devicetree/bindings/input/touchscreen/egalax-ts.txt   | 8 ++++++++
>  drivers/input/touchscreen/egalax_ts.c                     | 4 ++++
>  2 files changed, 12 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/input/touchscreen/egalax-ts.txt b/Documentation/devicetree/bindings/input/touchscreen/egalax-ts.txt
> index 92fb2620f5e2..41be6287589d 100644
> --- a/Documentation/devicetree/bindings/input/touchscreen/egalax-ts.txt
> +++ b/Documentation/devicetree/bindings/input/touchscreen/egalax-ts.txt
> @@ -7,6 +7,13 @@ Required properties:
>  - wakeup-gpios: the gpio pin to be used for waking up the controller
>    and also used as irq pin
>  
> +Optional properties:
> +- eeti,protocol-version: protocol version used by the controller
> +	0: This is the default protocol used when the property is absent. This
> +	protocol supports up to 5 touch points with 1 points per report.
> +	1: Protocol supports up to 10 touch points with a maximum of 5 points
> +	per report.

This should be part of the compatible property. If we're not doing 
compatibles for each version of the chip, then we should at least do it 
for the protocol.

Rob

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

* Re: [PATCH 1/4] Input: egalax_ts - clean up capability initialization
  2018-09-20 14:22 [PATCH 1/4] Input: egalax_ts - clean up capability initialization Lucas Stach
                   ` (2 preceding siblings ...)
  2018-09-20 14:22 ` [PATCH 4/4] Input: egalax_ts - add support for new " Lucas Stach
@ 2018-11-05 17:19 ` Lucas Stach
  3 siblings, 0 replies; 6+ messages in thread
From: Lucas Stach @ 2018-11-05 17:19 UTC (permalink / raw)
  To: Dmitry Torokhov, Rob Herring
  Cc: devicetree, patchwork-lst, Chris Healy, kernel, linux-input

Hi all,

we can drop this whole series. I realized that all I need is already
implemented in the EXC3000 driver.

Regards,
Lucas

Am Donnerstag, den 20.09.2018, 16:22 +0200 schrieb Lucas Stach:
> Just provide the proper flags to input_mt_init_slots(), which will
> so the right thing and set the proper capability bits.
> 
> > Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
> ---
>  drivers/input/touchscreen/egalax_ts.c | 9 ++-------
>  1 file changed, 2 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/input/touchscreen/egalax_ts.c b/drivers/input/touchscreen/egalax_ts.c
> index 80e69bb8283e..5e7a60089c3d 100644
> --- a/drivers/input/touchscreen/egalax_ts.c
> +++ b/drivers/input/touchscreen/egalax_ts.c
> @@ -199,17 +199,12 @@ static int egalax_ts_probe(struct i2c_client *client,
> >  	input_dev->name = "EETI eGalax Touch Screen";
> >  	input_dev->id.bustype = BUS_I2C;
>  
> > -	__set_bit(EV_ABS, input_dev->evbit);
> > -	__set_bit(EV_KEY, input_dev->evbit);
> > -	__set_bit(BTN_TOUCH, input_dev->keybit);
> -
> > -	input_set_abs_params(input_dev, ABS_X, 0, EGALAX_MAX_X, 0, 0);
> > -	input_set_abs_params(input_dev, ABS_Y, 0, EGALAX_MAX_Y, 0, 0);
> >  	input_set_abs_params(input_dev,
> >  			     ABS_MT_POSITION_X, 0, EGALAX_MAX_X, 0, 0);
> >  	input_set_abs_params(input_dev,
> >  			     ABS_MT_POSITION_Y, 0, EGALAX_MAX_Y, 0, 0);
> > -	input_mt_init_slots(input_dev, MAX_SUPPORT_POINTS, 0);
> > +	input_mt_init_slots(input_dev, MAX_SUPPORT_POINTS,
> > +			    INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED);
>  
> >  	error = devm_request_threaded_irq(&client->dev, client->irq, NULL,
> >  					  egalax_ts_interrupt,

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

end of thread, other threads:[~2018-11-05 17:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-20 14:22 [PATCH 1/4] Input: egalax_ts - clean up capability initialization Lucas Stach
2018-09-20 14:22 ` [PATCH 2/4] Input: egalax_ts - use touchscreen helpers Lucas Stach
2018-09-20 14:22 ` [PATCH 3/4] Input: egalax_ts - add property for protocol version Lucas Stach
2018-09-24 22:28   ` Rob Herring
2018-09-20 14:22 ` [PATCH 4/4] Input: egalax_ts - add support for new " Lucas Stach
2018-11-05 17:19 ` [PATCH 1/4] Input: egalax_ts - clean up capability initialization Lucas Stach

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.