linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/9] input: elants: Support Asus TF300T touchscreen
@ 2020-04-13 13:32 Michał Mirosław
  2020-04-13 13:32 ` [PATCH v3 3/9] input: elants: remove unused axes Michał Mirosław
                   ` (8 more replies)
  0 siblings, 9 replies; 24+ messages in thread
From: Michał Mirosław @ 2020-04-13 13:32 UTC (permalink / raw)
  To: Dmitry Osipenko, Dmitry Torokhov, Henrik Rydberg, James Chen,
	Johnny Chuang, Rob Herring, Scott Liu, David Heidelberg
  Cc: linux-input, linux-kernel

This series cleans up the driver a bit and implements changes needed to
support EKTF3624-based touchscreen used in Asus TF300T and similar
Tegra3-based tablets.

---
v2: extended with Dmitry's patches (replaced v1 patches 3 and 4)
v3: rebased for v5.7-rc1

Dmitry Osipenko (3):
  input: elants: support 0x66 reply opcode for reporting touches
  dt-bindings: input: elants-i2c: Document common touchscreen properties
  dt-bindings: input: elants-i2c: Document eKTF3624

Michał Mirosław (6):
  input: elants: document some registers and values
  input: elants: support old touch report format
  input: elants: remove unused axes
  input: elants: override touchscreen info with DT properties
  input: elants: refactor elants_i2c_execute_command()
  input: elants: read touchscreen size for EKTF3624

 .../devicetree/bindings/input/elants_i2c.txt  |   6 +-
 drivers/input/touchscreen/elants_i2c.c        | 365 ++++++++++++------
 2 files changed, 242 insertions(+), 129 deletions(-)

-- 
2.20.1


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

* [PATCH v3 3/9] input: elants: remove unused axes
  2020-04-13 13:32 [PATCH v3 0/9] input: elants: Support Asus TF300T touchscreen Michał Mirosław
@ 2020-04-13 13:32 ` Michał Mirosław
  2020-04-26  4:52   ` Dmitry Torokhov
  2020-04-13 13:32 ` [PATCH v3 2/9] input: elants: support old touch report format Michał Mirosław
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 24+ messages in thread
From: Michał Mirosław @ 2020-04-13 13:32 UTC (permalink / raw)
  To: Dmitry Osipenko, Dmitry Torokhov, Henrik Rydberg, James Chen,
	Johnny Chuang, Rob Herring, Scott Liu, David Heidelberg
  Cc: linux-input, linux-kernel

Driver only ever reports MT events. Clear capabilities of all others.

Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
Reviewed-by: Dmitry Osipenko <digetx@gmail.com>
Tested-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/input/touchscreen/elants_i2c.c | 11 -----------
 1 file changed, 11 deletions(-)

diff --git a/drivers/input/touchscreen/elants_i2c.c b/drivers/input/touchscreen/elants_i2c.c
index ddebd3741145..fcd3d189f184 100644
--- a/drivers/input/touchscreen/elants_i2c.c
+++ b/drivers/input/touchscreen/elants_i2c.c
@@ -1312,17 +1312,6 @@ static int elants_i2c_probe(struct i2c_client *client,
 	ts->input->name = "Elan Touchscreen";
 	ts->input->id.bustype = BUS_I2C;
 
-	__set_bit(BTN_TOUCH, ts->input->keybit);
-	__set_bit(EV_ABS, ts->input->evbit);
-	__set_bit(EV_KEY, ts->input->evbit);
-
-	/* Single touch input params setup */
-	input_set_abs_params(ts->input, ABS_X, 0, ts->x_max, 0, 0);
-	input_set_abs_params(ts->input, ABS_Y, 0, ts->y_max, 0, 0);
-	input_set_abs_params(ts->input, ABS_PRESSURE, 0, 255, 0, 0);
-	input_abs_set_res(ts->input, ABS_X, ts->x_res);
-	input_abs_set_res(ts->input, ABS_Y, ts->y_res);
-
 	/* Multitouch input params setup */
 	error = input_mt_init_slots(ts->input, MAX_CONTACT_NUM,
 				    INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED);
-- 
2.20.1


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

* [PATCH v3 2/9] input: elants: support old touch report format
  2020-04-13 13:32 [PATCH v3 0/9] input: elants: Support Asus TF300T touchscreen Michał Mirosław
  2020-04-13 13:32 ` [PATCH v3 3/9] input: elants: remove unused axes Michał Mirosław
@ 2020-04-13 13:32 ` Michał Mirosław
  2020-04-13 13:32 ` [PATCH v3 1/9] input: elants: document some registers and values Michał Mirosław
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 24+ messages in thread
From: Michał Mirosław @ 2020-04-13 13:32 UTC (permalink / raw)
  To: Dmitry Osipenko, Dmitry Torokhov, Henrik Rydberg, James Chen,
	Johnny Chuang, Rob Herring, Scott Liu, David Heidelberg
  Cc: linux-input, linux-kernel

Support ELAN touchpad sensor with older firmware as found on eg. Asus
Transformer Pads.

Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
Reviewed-by: Dmitry Osipenko <digetx@gmail.com>
Tested-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/input/touchscreen/elants_i2c.c | 36 ++++++++++++++++++--------
 1 file changed, 25 insertions(+), 11 deletions(-)

diff --git a/drivers/input/touchscreen/elants_i2c.c b/drivers/input/touchscreen/elants_i2c.c
index b528bd687cca..ddebd3741145 100644
--- a/drivers/input/touchscreen/elants_i2c.c
+++ b/drivers/input/touchscreen/elants_i2c.c
@@ -67,6 +67,7 @@
 #define CMD_HEADER_REK		0x66
 
 /* FW position data */
+#define PACKET_SIZE_OLD		40
 #define PACKET_SIZE		55
 #define MAX_CONTACT_NUM		10
 #define FW_POS_HEADER		0
@@ -853,7 +854,8 @@ static int elants_i2c_fw_update(struct elants_data *ts)
  * Event reporting.
  */
 
-static void elants_i2c_mt_event(struct elants_data *ts, u8 *buf)
+static void elants_i2c_mt_event(struct elants_data *ts, u8 *buf,
+				size_t report_len)
 {
 	struct input_dev *input = ts->input;
 	unsigned int n_fingers;
@@ -865,7 +867,8 @@ static void elants_i2c_mt_event(struct elants_data *ts, u8 *buf)
 			buf[FW_POS_STATE];
 
 	dev_dbg(&ts->client->dev,
-		"n_fingers: %u, state: %04x\n",  n_fingers, finger_state);
+		"n_fingers: %u, state: %04x, report_len: %zu\n",
+		n_fingers, finger_state, report_len);
 
 	for (i = 0; i < MAX_CONTACT_NUM && n_fingers; i++) {
 		if (finger_state & 1) {
@@ -875,8 +878,16 @@ static void elants_i2c_mt_event(struct elants_data *ts, u8 *buf)
 			pos = &buf[FW_POS_XY + i * 3];
 			x = (((u16)pos[0] & 0xf0) << 4) | pos[1];
 			y = (((u16)pos[0] & 0x0f) << 8) | pos[2];
-			p = buf[FW_POS_PRESSURE + i];
-			w = buf[FW_POS_WIDTH + i];
+			if (report_len == PACKET_SIZE_OLD) {
+				w = buf[FW_POS_WIDTH + i / 2];
+				w >>= 4 * (~i & 1);	// little-endian-nibbles
+				w |= w << 4;
+				w |= !w;
+				p = w;
+			} else {
+				p = buf[FW_POS_PRESSURE + i];
+				w = buf[FW_POS_WIDTH + i];
+			}
 
 			dev_dbg(&ts->client->dev, "i=%d x=%d y=%d p=%d w=%d\n",
 				i, x, y, p, w);
@@ -909,7 +920,8 @@ static u8 elants_i2c_calculate_checksum(u8 *buf)
 	return checksum;
 }
 
-static void elants_i2c_event(struct elants_data *ts, u8 *buf)
+static void elants_i2c_event(struct elants_data *ts, u8 *buf,
+			     size_t report_len)
 {
 	u8 checksum = elants_i2c_calculate_checksum(buf);
 
@@ -923,7 +935,7 @@ static void elants_i2c_event(struct elants_data *ts, u8 *buf)
 			 "%s: unknown packet type: %02x\n",
 			 __func__, buf[FW_POS_HEADER]);
 	else
-		elants_i2c_mt_event(ts, buf);
+		elants_i2c_mt_event(ts, buf, report_len);
 }
 
 static irqreturn_t elants_i2c_irq(int irq, void *_dev)
@@ -981,7 +993,8 @@ static irqreturn_t elants_i2c_irq(int irq, void *_dev)
 			break;
 
 		case QUEUE_HEADER_SINGLE:
-			elants_i2c_event(ts, &ts->buf[HEADER_SIZE]);
+			elants_i2c_event(ts, &ts->buf[HEADER_SIZE],
+					 ts->buf[FW_HDR_LENGTH]);
 			break;
 
 		case QUEUE_HEADER_NORMAL:
@@ -994,17 +1007,18 @@ static irqreturn_t elants_i2c_irq(int irq, void *_dev)
 			}
 
 			report_len = ts->buf[FW_HDR_LENGTH] / report_count;
-			if (report_len != PACKET_SIZE) {
+			if (report_len != PACKET_SIZE &&
+			    report_len != PACKET_SIZE_OLD) {
 				dev_err(&client->dev,
-					"mismatching report length: %*ph\n",
+					"unsupported report length: %*ph\n",
 					HEADER_SIZE, ts->buf);
 				break;
 			}
 
 			for (i = 0; i < report_count; i++) {
 				u8 *buf = ts->buf + HEADER_SIZE +
-							i * PACKET_SIZE;
-				elants_i2c_event(ts, buf);
+					  i * report_len;
+				elants_i2c_event(ts, buf, report_len);
 			}
 			break;
 
-- 
2.20.1


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

* [PATCH v3 1/9] input: elants: document some registers and values
  2020-04-13 13:32 [PATCH v3 0/9] input: elants: Support Asus TF300T touchscreen Michał Mirosław
  2020-04-13 13:32 ` [PATCH v3 3/9] input: elants: remove unused axes Michał Mirosław
  2020-04-13 13:32 ` [PATCH v3 2/9] input: elants: support old touch report format Michał Mirosław
@ 2020-04-13 13:32 ` Michał Mirosław
  2020-04-13 13:32 ` [PATCH v3 4/9] input: elants: override touchscreen info with DT properties Michał Mirosław
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 24+ messages in thread
From: Michał Mirosław @ 2020-04-13 13:32 UTC (permalink / raw)
  To: Dmitry Torokhov, Dmitry Osipenko, Henrik Rydberg, James Chen,
	Johnny Chuang, Rob Herring, Scott Liu, David Heidelberg
  Cc: linux-input, linux-kernel

Add information found in downstream kernels, to make the code less
magic.

Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
Reviewed-by: Dmitry Osipenko <digetx@gmail.com>
Tested-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/input/touchscreen/elants_i2c.c | 29 +++++++++++++++++++++-----
 1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/drivers/input/touchscreen/elants_i2c.c b/drivers/input/touchscreen/elants_i2c.c
index 14c577c16b16..b528bd687cca 100644
--- a/drivers/input/touchscreen/elants_i2c.c
+++ b/drivers/input/touchscreen/elants_i2c.c
@@ -79,7 +79,11 @@
 
 #define HEADER_REPORT_10_FINGER	0x62
 
-/* Header (4 bytes) plus 3 fill 10-finger packets */
+/* Power state */
+#define PWR_STATE_DEEP_SLEEP	0
+#define PWR_STATE_NORMAL	1
+
+/* Header (4 bytes) plus 3 full 10-finger packets */
 #define MAX_PACKET_SIZE		169
 
 #define BOOT_TIME_DELAY_MS	50
@@ -89,10 +93,21 @@
 #define E_ELAN_INFO_BC_VER	0x10
 #define E_ELAN_INFO_TEST_VER	0xE0
 #define E_ELAN_INFO_FW_ID	0xF0
+#define E_POWER_MODE		0x40
+#define E_POWER_STATE		0x50
+#define E_INFO_X_RES		0x60
+#define E_INFO_Y_RES		0x63
 #define E_INFO_OSR		0xD6
 #define E_INFO_PHY_SCAN		0xD7
 #define E_INFO_PHY_DRIVER	0xD8
 
+/* FW write command, 0x54 0x?? 0x0, 0x01 */
+#define E_POWER_MODE_BATTERY	0x40
+#define E_POWER_MODE_AC		0x41
+#define E_POWER_MODE_USB	0x42
+#define E_POWER_STATE_SLEEP	0x50
+#define E_POWER_STATE_RESUME	0x58
+
 #define MAX_RETRIES		3
 #define MAX_FW_UPDATE_RETRIES	30
 
@@ -237,8 +252,8 @@ static int elants_i2c_calibrate(struct elants_data *ts)
 {
 	struct i2c_client *client = ts->client;
 	int ret, error;
-	static const u8 w_flashkey[] = { 0x54, 0xC0, 0xE1, 0x5A };
-	static const u8 rek[] = { 0x54, 0x29, 0x00, 0x01 };
+	static const u8 w_flashkey[] = { CMD_HEADER_WRITE, 0xC0, 0xE1, 0x5A };
+	static const u8 rek[] = { CMD_HEADER_WRITE, 0x29, 0x00, 0x01 };
 	static const u8 rek_resp[] = { CMD_HEADER_REK, 0x66, 0x66, 0x66 };
 
 	disable_irq(client->irq);
@@ -1357,7 +1372,9 @@ static int __maybe_unused elants_i2c_suspend(struct device *dev)
 {
 	struct i2c_client *client = to_i2c_client(dev);
 	struct elants_data *ts = i2c_get_clientdata(client);
-	const u8 set_sleep_cmd[] = { 0x54, 0x50, 0x00, 0x01 };
+	const u8 set_sleep_cmd[] = {
+		CMD_HEADER_WRITE, E_POWER_STATE_SLEEP, 0x00, 0x01
+	};
 	int retry_cnt;
 	int error;
 
@@ -1394,7 +1411,9 @@ static int __maybe_unused elants_i2c_resume(struct device *dev)
 {
 	struct i2c_client *client = to_i2c_client(dev);
 	struct elants_data *ts = i2c_get_clientdata(client);
-	const u8 set_active_cmd[] = { 0x54, 0x58, 0x00, 0x01 };
+	const u8 set_active_cmd[] = {
+		CMD_HEADER_WRITE, E_POWER_STATE_RESUME, 0x00, 0x01
+	};
 	int retry_cnt;
 	int error;
 
-- 
2.20.1


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

* [PATCH v3 4/9] input: elants: override touchscreen info with DT properties
  2020-04-13 13:32 [PATCH v3 0/9] input: elants: Support Asus TF300T touchscreen Michał Mirosław
                   ` (2 preceding siblings ...)
  2020-04-13 13:32 ` [PATCH v3 1/9] input: elants: document some registers and values Michał Mirosław
@ 2020-04-13 13:32 ` Michał Mirosław
  2020-04-26  5:11   ` Dmitry Torokhov
  2020-04-13 13:32 ` [PATCH v3 5/9] input: elants: refactor elants_i2c_execute_command() Michał Mirosław
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 24+ messages in thread
From: Michał Mirosław @ 2020-04-13 13:32 UTC (permalink / raw)
  To: Dmitry Osipenko, Dmitry Torokhov, Henrik Rydberg, James Chen,
	Johnny Chuang, Rob Herring, Scott Liu, David Heidelberg
  Cc: linux-input, linux-kernel

Allow overriding of information from hardware and support additional
common DT properties like axis inversion. This is required for eg.
Nexus 7 and TF300T where the programmed values in firmware differ
from reality.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
[moved "prop" before DMA buffer]
Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
---
 drivers/input/touchscreen/elants_i2c.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/input/touchscreen/elants_i2c.c b/drivers/input/touchscreen/elants_i2c.c
index fcd3d189f184..87d686ce08f2 100644
--- a/drivers/input/touchscreen/elants_i2c.c
+++ b/drivers/input/touchscreen/elants_i2c.c
@@ -32,6 +32,7 @@
 #include <linux/slab.h>
 #include <linux/firmware.h>
 #include <linux/input/mt.h>
+#include <linux/input/touchscreen.h>
 #include <linux/acpi.h>
 #include <linux/of.h>
 #include <linux/gpio/consumer.h>
@@ -150,6 +151,7 @@ struct elants_data {
 	unsigned int y_res;
 	unsigned int x_max;
 	unsigned int y_max;
+	struct touchscreen_properties prop;
 
 	enum elants_state state;
 	enum elants_iap_mode iap_mode;
@@ -894,8 +896,7 @@ static void elants_i2c_mt_event(struct elants_data *ts, u8 *buf,
 
 			input_mt_slot(input, i);
 			input_mt_report_slot_state(input, MT_TOOL_FINGER, true);
-			input_event(input, EV_ABS, ABS_MT_POSITION_X, x);
-			input_event(input, EV_ABS, ABS_MT_POSITION_Y, y);
+			touchscreen_report_pos(input, &ts->prop, x, y, true);
 			input_event(input, EV_ABS, ABS_MT_PRESSURE, p);
 			input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, w);
 
@@ -1329,6 +1330,8 @@ static int elants_i2c_probe(struct i2c_client *client,
 	input_abs_set_res(ts->input, ABS_MT_POSITION_Y, ts->y_res);
 	input_abs_set_res(ts->input, ABS_MT_TOUCH_MAJOR, 1);
 
+	touchscreen_parse_properties(ts->input, true, &ts->prop);
+
 	error = input_register_device(ts->input);
 	if (error) {
 		dev_err(&client->dev,
-- 
2.20.1


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

* [PATCH v3 5/9] input: elants: refactor elants_i2c_execute_command()
  2020-04-13 13:32 [PATCH v3 0/9] input: elants: Support Asus TF300T touchscreen Michał Mirosław
                   ` (3 preceding siblings ...)
  2020-04-13 13:32 ` [PATCH v3 4/9] input: elants: override touchscreen info with DT properties Michał Mirosław
@ 2020-04-13 13:32 ` Michał Mirosław
  2020-04-26  5:08   ` Dmitry Torokhov
  2020-04-13 13:32 ` [PATCH v3 6/9] input: elants: read touchscreen size for EKTF3624 Michał Mirosław
                   ` (3 subsequent siblings)
  8 siblings, 1 reply; 24+ messages in thread
From: Michał Mirosław @ 2020-04-13 13:32 UTC (permalink / raw)
  To: Dmitry Osipenko, Dmitry Torokhov, Henrik Rydberg, James Chen,
	Johnny Chuang, Rob Herring, Scott Liu, David Heidelberg
  Cc: linux-input, linux-kernel

Apply some DRY-ing to elants_i2c_execute_command() callers.  This pulls
polling and error printk()s into a single function.

Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
---
 drivers/input/touchscreen/elants_i2c.c | 189 +++++++++++++------------
 1 file changed, 96 insertions(+), 93 deletions(-)

diff --git a/drivers/input/touchscreen/elants_i2c.c b/drivers/input/touchscreen/elants_i2c.c
index 87d686ce08f2..b0f083f7f2a9 100644
--- a/drivers/input/touchscreen/elants_i2c.c
+++ b/drivers/input/touchscreen/elants_i2c.c
@@ -205,7 +205,8 @@ static int elants_i2c_read(struct i2c_client *client, void *data, size_t size)
 
 static int elants_i2c_execute_command(struct i2c_client *client,
 				      const u8 *cmd, size_t cmd_size,
-				      u8 *resp, size_t resp_size)
+				      u8 *resp, size_t resp_size,
+				      int retries, const char *cmd_name)
 {
 	struct i2c_msg msgs[2];
 	int ret;
@@ -225,30 +226,55 @@ static int elants_i2c_execute_command(struct i2c_client *client,
 		break;
 
 	default:
-		dev_err(&client->dev, "%s: invalid command %*ph\n",
-			__func__, (int)cmd_size, cmd);
+		dev_err(&client->dev, "(%s): invalid command: %*ph\n",
+			cmd_name, (int)cmd_size, cmd);
 		return -EINVAL;
 	}
 
-	msgs[0].addr = client->addr;
-	msgs[0].flags = client->flags & I2C_M_TEN;
-	msgs[0].len = cmd_size;
-	msgs[0].buf = (u8 *)cmd;
+	for (;;) {
+		msgs[0].addr = client->addr;
+		msgs[0].flags = client->flags & I2C_M_TEN;
+		msgs[0].len = cmd_size;
+		msgs[0].buf = (u8 *)cmd;
 
-	msgs[1].addr = client->addr;
-	msgs[1].flags = client->flags & I2C_M_TEN;
-	msgs[1].flags |= I2C_M_RD;
-	msgs[1].len = resp_size;
-	msgs[1].buf = resp;
+		msgs[1].addr = client->addr;
+		msgs[1].flags = client->flags & I2C_M_TEN;
+		msgs[1].flags |= I2C_M_RD;
+		msgs[1].len = resp_size;
+		msgs[1].buf = resp;
 
-	ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
-	if (ret < 0)
-		return ret;
+		ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
+		if (ret < 0) {
+			if (--retries > 0) {
+				dev_dbg(&client->dev,
+					"(%s) I2C transfer failed: %d (retrying)\n",
+					cmd_name, ret);
+				continue;
+			}
 
-	if (ret != ARRAY_SIZE(msgs) || resp[FW_HDR_TYPE] != expected_response)
-		return -EIO;
+			dev_err(&client->dev,
+				"(%s) I2C transfer failed: %d\n",
+				cmd_name, ret);
+			return ret;
+		}
 
-	return 0;
+		if (ret != ARRAY_SIZE(msgs) ||
+		    resp[FW_HDR_TYPE] != expected_response) {
+			if (--retries > 0) {
+				dev_dbg(&client->dev,
+					"(%s) unexpected response: %*ph (retrying)\n",
+					cmd_name, ret, resp);
+				continue;
+			}
+
+			dev_err(&client->dev,
+				"(%s) unexpected response: %*ph\n",
+				cmd_name, ret, resp);
+			return -EIO;
+		}
+
+		return --retries;
+	}
 }
 
 static int elants_i2c_calibrate(struct elants_data *ts)
@@ -321,27 +347,20 @@ static u16 elants_i2c_parse_version(u8 *buf)
 static int elants_i2c_query_hw_version(struct elants_data *ts)
 {
 	struct i2c_client *client = ts->client;
-	int error, retry_cnt;
+	int retry_cnt = MAX_RETRIES;
 	const u8 cmd[] = { CMD_HEADER_READ, E_ELAN_INFO_FW_ID, 0x00, 0x01 };
 	u8 resp[HEADER_SIZE];
 
-	for (retry_cnt = 0; retry_cnt < MAX_RETRIES; retry_cnt++) {
-		error = elants_i2c_execute_command(client, cmd, sizeof(cmd),
-						   resp, sizeof(resp));
-		if (!error) {
-			ts->hw_version = elants_i2c_parse_version(resp);
-			if (ts->hw_version != 0xffff)
-				return 0;
-		}
+	while (retry_cnt) {
+		retry_cnt = elants_i2c_execute_command(client, cmd, sizeof(cmd),
+						       resp, sizeof(resp),
+						       retry_cnt, "read fw id");
+		if (retry_cnt < 0)
+			return retry_cnt;
 
-		dev_dbg(&client->dev, "read fw id error=%d, buf=%*phC\n",
-			error, (int)sizeof(resp), resp);
-	}
-
-	if (error) {
-		dev_err(&client->dev,
-			"Failed to read fw id: %d\n", error);
-		return error;
+		ts->hw_version = elants_i2c_parse_version(resp);
+		if (ts->hw_version != 0xffff)
+			return 0;
 	}
 
 	dev_err(&client->dev, "Invalid fw id: %#04x\n", ts->hw_version);
@@ -352,26 +371,28 @@ static int elants_i2c_query_hw_version(struct elants_data *ts)
 static int elants_i2c_query_fw_version(struct elants_data *ts)
 {
 	struct i2c_client *client = ts->client;
-	int error, retry_cnt;
+	int retry_cnt = MAX_RETRIES;
 	const u8 cmd[] = { CMD_HEADER_READ, E_ELAN_INFO_FW_VER, 0x00, 0x01 };
 	u8 resp[HEADER_SIZE];
 
-	for (retry_cnt = 0; retry_cnt < MAX_RETRIES; retry_cnt++) {
-		error = elants_i2c_execute_command(client, cmd, sizeof(cmd),
-						   resp, sizeof(resp));
-		if (!error) {
-			ts->fw_version = elants_i2c_parse_version(resp);
-			if (ts->fw_version != 0x0000 &&
-			    ts->fw_version != 0xffff)
-				return 0;
-		}
+	while (retry_cnt) {
+		retry_cnt = elants_i2c_execute_command(client, cmd,
+						       sizeof(cmd),
+						       resp, sizeof(resp),
+						       retry_cnt,
+						       "read fw version");
+		if (retry_cnt < 0)
+			return retry_cnt;
 
-		dev_dbg(&client->dev, "read fw version error=%d, buf=%*phC\n",
-			error, (int)sizeof(resp), resp);
+		ts->fw_version = elants_i2c_parse_version(resp);
+		if (ts->fw_version != 0x0000 && ts->fw_version != 0xffff)
+			return 0;
+
+		dev_dbg(&client->dev, "(read fw version) resp %*phC\n",
+			(int)sizeof(resp), resp);
 	}
 
-	dev_err(&client->dev,
-		"Failed to read fw version or fw version is invalid\n");
+	dev_err(&client->dev, "Invalid fw ver: %#04x\n", ts->fw_version);
 
 	return -EINVAL;
 }
@@ -379,25 +400,20 @@ static int elants_i2c_query_fw_version(struct elants_data *ts)
 static int elants_i2c_query_test_version(struct elants_data *ts)
 {
 	struct i2c_client *client = ts->client;
-	int error, retry_cnt;
+	int error;
 	u16 version;
 	const u8 cmd[] = { CMD_HEADER_READ, E_ELAN_INFO_TEST_VER, 0x00, 0x01 };
 	u8 resp[HEADER_SIZE];
 
-	for (retry_cnt = 0; retry_cnt < MAX_RETRIES; retry_cnt++) {
-		error = elants_i2c_execute_command(client, cmd, sizeof(cmd),
-						   resp, sizeof(resp));
-		if (!error) {
-			version = elants_i2c_parse_version(resp);
-			ts->test_version = version >> 8;
-			ts->solution_version = version & 0xff;
+	error = elants_i2c_execute_command(client, cmd, sizeof(cmd),
+					   resp, sizeof(resp), MAX_RETRIES,
+					   "read test version");
+	if (error >= 0) {
+		version = elants_i2c_parse_version(resp);
+		ts->test_version = version >> 8;
+		ts->solution_version = version & 0xff;
 
-			return 0;
-		}
-
-		dev_dbg(&client->dev,
-			"read test version error rc=%d, buf=%*phC\n",
-			error, (int)sizeof(resp), resp);
+		return 0;
 	}
 
 	dev_err(&client->dev, "Failed to read test version\n");
@@ -414,13 +430,10 @@ static int elants_i2c_query_bc_version(struct elants_data *ts)
 	int error;
 
 	error = elants_i2c_execute_command(client, cmd, sizeof(cmd),
-					   resp, sizeof(resp));
-	if (error) {
-		dev_err(&client->dev,
-			"read BC version error=%d, buf=%*phC\n",
-			error, (int)sizeof(resp), resp);
+					   resp, sizeof(resp), 1,
+					   "read BC version");
+	if (error)
 		return error;
-	}
 
 	version = elants_i2c_parse_version(resp);
 	ts->bc_version = version >> 8;
@@ -452,12 +465,10 @@ static int elants_i2c_query_ts_info(struct elants_data *ts)
 	error = elants_i2c_execute_command(client,
 					   get_resolution_cmd,
 					   sizeof(get_resolution_cmd),
-					   resp, sizeof(resp));
-	if (error) {
-		dev_err(&client->dev, "get resolution command failed: %d\n",
-			error);
+					   resp, sizeof(resp), 1,
+					   "get resolution");
+	if (error)
 		return error;
-	}
 
 	rows = resp[2] + resp[6] + resp[10];
 	cols = resp[3] + resp[7] + resp[11];
@@ -465,36 +476,29 @@ static int elants_i2c_query_ts_info(struct elants_data *ts)
 	/* Process mm_to_pixel information */
 	error = elants_i2c_execute_command(client,
 					   get_osr_cmd, sizeof(get_osr_cmd),
-					   resp, sizeof(resp));
-	if (error) {
-		dev_err(&client->dev, "get osr command failed: %d\n",
-			error);
+					   resp, sizeof(resp), 1, "get osr");
+	if (error)
 		return error;
-	}
 
 	osr = resp[3];
 
 	error = elants_i2c_execute_command(client,
 					   get_physical_scan_cmd,
 					   sizeof(get_physical_scan_cmd),
-					   resp, sizeof(resp));
-	if (error) {
-		dev_err(&client->dev, "get physical scan command failed: %d\n",
-			error);
+					   resp, sizeof(resp), 1,
+					   "get physical scan");
+	if (error)
 		return error;
-	}
 
 	phy_x = get_unaligned_be16(&resp[2]);
 
 	error = elants_i2c_execute_command(client,
 					   get_physical_drive_cmd,
 					   sizeof(get_physical_drive_cmd),
-					   resp, sizeof(resp));
-	if (error) {
-		dev_err(&client->dev, "get physical drive command failed: %d\n",
-			error);
+					   resp, sizeof(resp), 1,
+					   "get physical drive");
+	if (error)
 		return error;
-	}
 
 	phy_y = get_unaligned_be16(&resp[2]);
 
@@ -649,11 +653,10 @@ static int elants_i2c_validate_remark_id(struct elants_data *ts,
 
 	/* Compare TS Remark ID and FW Remark ID */
 	error = elants_i2c_execute_command(client, cmd, sizeof(cmd),
-					resp, sizeof(resp));
-	if (error) {
-		dev_err(&client->dev, "failed to query Remark ID: %d\n", error);
+					   resp, sizeof(resp),
+					   1, "read Remark ID");
+	if (error < 0)
 		return error;
-	}
 
 	ts_remark_id = get_unaligned_be16(&resp[3]);
 
-- 
2.20.1


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

* [PATCH v3 6/9] input: elants: read touchscreen size for EKTF3624
  2020-04-13 13:32 [PATCH v3 0/9] input: elants: Support Asus TF300T touchscreen Michał Mirosław
                   ` (4 preceding siblings ...)
  2020-04-13 13:32 ` [PATCH v3 5/9] input: elants: refactor elants_i2c_execute_command() Michał Mirosław
@ 2020-04-13 13:32 ` Michał Mirosław
  2020-04-26  5:10   ` Dmitry Torokhov
  2020-04-13 13:32 ` [PATCH v3 7/9] input: elants: support 0x66 reply opcode for reporting touches Michał Mirosław
                   ` (2 subsequent siblings)
  8 siblings, 1 reply; 24+ messages in thread
From: Michał Mirosław @ 2020-04-13 13:32 UTC (permalink / raw)
  To: Dmitry Osipenko, Dmitry Torokhov, Henrik Rydberg, James Chen,
	Johnny Chuang, Rob Herring, Scott Liu, David Heidelberg
  Cc: linux-input, linux-kernel

EKTF3624 as present in Asus TF300T tablet has touchscreen size encoded
in different registers.

Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
Reviewed-by: Dmitry Osipenko <digetx@gmail.com>
Tested-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/input/touchscreen/elants_i2c.c | 82 ++++++++++++++++++++++++--
 1 file changed, 77 insertions(+), 5 deletions(-)

diff --git a/drivers/input/touchscreen/elants_i2c.c b/drivers/input/touchscreen/elants_i2c.c
index b0f083f7f2a9..2b936e920874 100644
--- a/drivers/input/touchscreen/elants_i2c.c
+++ b/drivers/input/touchscreen/elants_i2c.c
@@ -34,7 +34,7 @@
 #include <linux/input/mt.h>
 #include <linux/input/touchscreen.h>
 #include <linux/acpi.h>
-#include <linux/of.h>
+#include <linux/of_device.h>
 #include <linux/gpio/consumer.h>
 #include <linux/regulator/consumer.h>
 #include <asm/unaligned.h>
@@ -42,6 +42,10 @@
 /* Device, Driver information */
 #define DEVICE_NAME	"elants_i2c"
 
+/* Device IDs */
+#define EKTH3500	0
+#define EKTF3624	1
+
 /* Convert from rows or columns into resolution */
 #define ELAN_TS_RESOLUTION(n, m)   (((n) - 1) * (m))
 
@@ -164,6 +168,7 @@ struct elants_data {
 
 	bool wake_irq_enabled;
 	bool keep_power_in_suspend;
+	u8 chip_id;
 
 	/* Must be last to be used for DMA operations */
 	u8 buf[MAX_PACKET_SIZE] ____cacheline_aligned;
@@ -442,7 +447,58 @@ static int elants_i2c_query_bc_version(struct elants_data *ts)
 	return 0;
 }
 
-static int elants_i2c_query_ts_info(struct elants_data *ts)
+static int elants_i2c_query_ts_info_ektf(struct elants_data *ts)
+{
+	struct i2c_client *client = ts->client;
+	int error;
+	u8 resp[4];
+	u16 phy_x, phy_y;
+	const u8 get_xres_cmd[] = {
+		CMD_HEADER_READ, E_INFO_X_RES, 0x00, 0x00
+	};
+	const u8 get_yres_cmd[] = {
+		CMD_HEADER_READ, E_INFO_Y_RES, 0x00, 0x00
+	};
+
+	/* Get X/Y size in mm */
+	error = elants_i2c_execute_command(client, get_xres_cmd,
+					   sizeof(get_xres_cmd),
+					   resp, sizeof(resp), 1,
+					   "get X size");
+	if (error)
+		return error;
+
+	phy_x = resp[2] | ((resp[3] & 0xF0) << 4);
+
+	error = elants_i2c_execute_command(client, get_yres_cmd,
+					   sizeof(get_yres_cmd),
+					   resp, sizeof(resp), 1,
+					   "get Y size");
+	if (error)
+		return error;
+
+	phy_y = resp[2] | ((resp[3] & 0xF0) << 4);
+
+	if (!phy_x || !phy_y) {
+		dev_warn(&client->dev,
+			 "invalid size data: %d x %d mm\n",
+			 phy_x, phy_y);
+		return 0;
+	}
+
+	dev_dbg(&client->dev, "phy_x=%d, phy_y=%d\n", phy_x, phy_y);
+
+	/* calculate resolution from size */
+	ts->x_max = 2240-1;
+	ts->x_res = DIV_ROUND_CLOSEST(ts->prop.max_x, phy_x);
+
+	ts->y_max = 1408-1;
+	ts->y_res = DIV_ROUND_CLOSEST(ts->prop.max_y, phy_y);
+
+	return 0;
+}
+
+static int elants_i2c_query_ts_info_ekth(struct elants_data *ts)
 {
 	struct i2c_client *client = ts->client;
 	int error;
@@ -593,8 +649,20 @@ static int elants_i2c_initialize(struct elants_data *ts)
 		error = elants_i2c_query_fw_version(ts);
 	if (!error)
 		error = elants_i2c_query_test_version(ts);
-	if (!error)
-		error = elants_i2c_query_ts_info(ts);
+
+	switch (ts->chip_id) {
+	case EKTH3500:
+		if (!error)
+			error = elants_i2c_query_ts_info_ekth(ts);
+		break;
+	case EKTF3624:
+		if (!error)
+			error = elants_i2c_query_ts_info_ektf(ts);
+		break;
+	default:
+		unreachable();
+		break;
+	}
 
 	if (error)
 		ts->iap_mode = ELAN_IAP_RECOVERY;
@@ -1245,6 +1313,9 @@ static int elants_i2c_probe(struct i2c_client *client,
 	ts->client = client;
 	i2c_set_clientdata(client, ts);
 
+	if (client->dev.of_node)
+		ts->chip_id = (uintptr_t)of_device_get_match_data(&client->dev);
+
 	ts->vcc33 = devm_regulator_get(&client->dev, "vcc33");
 	if (IS_ERR(ts->vcc33)) {
 		error = PTR_ERR(ts->vcc33);
@@ -1470,7 +1541,8 @@ MODULE_DEVICE_TABLE(acpi, elants_acpi_id);
 
 #ifdef CONFIG_OF
 static const struct of_device_id elants_of_match[] = {
-	{ .compatible = "elan,ekth3500" },
+	{ .compatible = "elan,ekth3500", .data = (void *)EKTH3500 },
+	{ .compatible = "elan,ektf3624", .data = (void *)EKTF3624 },
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, elants_of_match);
-- 
2.20.1


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

* [PATCH v3 8/9] dt-bindings: input: elants-i2c: Document common touchscreen properties
  2020-04-13 13:32 [PATCH v3 0/9] input: elants: Support Asus TF300T touchscreen Michał Mirosław
                   ` (6 preceding siblings ...)
  2020-04-13 13:32 ` [PATCH v3 7/9] input: elants: support 0x66 reply opcode for reporting touches Michał Mirosław
@ 2020-04-13 13:32 ` Michał Mirosław
  2020-04-13 13:32 ` [PATCH v3 9/9] dt-bindings: input: elants-i2c: Document eKTF3624 Michał Mirosław
  8 siblings, 0 replies; 24+ messages in thread
From: Michał Mirosław @ 2020-04-13 13:32 UTC (permalink / raw)
  To: Dmitry Osipenko, Dmitry Torokhov, Henrik Rydberg, James Chen,
	Johnny Chuang, Rob Herring, Scott Liu, David Heidelberg
  Cc: linux-input, linux-kernel

From: Dmitry Osipenko <digetx@gmail.com>

Document support of the common touchscreen properties.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
Reviewed-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
---
 Documentation/devicetree/bindings/input/elants_i2c.txt | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/input/elants_i2c.txt b/Documentation/devicetree/bindings/input/elants_i2c.txt
index 5edac8be0802..45fab32bbc19 100644
--- a/Documentation/devicetree/bindings/input/elants_i2c.txt
+++ b/Documentation/devicetree/bindings/input/elants_i2c.txt
@@ -14,9 +14,13 @@ Optional properties:
 - reset-gpios: reset gpio the chip is connected to.
 - vcc33-supply: a phandle for the regulator supplying 3.3V power.
 - vccio-supply: a phandle for the regulator supplying IO power.
+- see [2] for additional properties
+
+For additional optional properties see: touchscreen.txt
 
 [0]: Documentation/devicetree/bindings/interrupt-controller/interrupts.txt
 [1]: Documentation/devicetree/bindings/pinctrl/pinctrl-bindings.txt
+[2]: Documentation/devicetree/bindings/input/touchscreen/touchscreen.txt
 
 Example:
 	&i2c1 {
-- 
2.20.1


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

* [PATCH v3 7/9] input: elants: support 0x66 reply opcode for reporting touches
  2020-04-13 13:32 [PATCH v3 0/9] input: elants: Support Asus TF300T touchscreen Michał Mirosław
                   ` (5 preceding siblings ...)
  2020-04-13 13:32 ` [PATCH v3 6/9] input: elants: read touchscreen size for EKTF3624 Michał Mirosław
@ 2020-04-13 13:32 ` Michał Mirosław
  2020-04-26  5:15   ` Dmitry Torokhov
  2020-04-13 13:32 ` [PATCH v3 8/9] dt-bindings: input: elants-i2c: Document common touchscreen properties Michał Mirosław
  2020-04-13 13:32 ` [PATCH v3 9/9] dt-bindings: input: elants-i2c: Document eKTF3624 Michał Mirosław
  8 siblings, 1 reply; 24+ messages in thread
From: Michał Mirosław @ 2020-04-13 13:32 UTC (permalink / raw)
  To: Dmitry Osipenko, Dmitry Torokhov, Henrik Rydberg, James Chen,
	Johnny Chuang, Rob Herring, Scott Liu, David Heidelberg
  Cc: linux-input, linux-kernel

From: Dmitry Osipenko <digetx@gmail.com>

eKTF3624 touchscreen firmware uses two variants of the reply opcodes for
reporting touch events: one is 0x63 (used by older firmware) and other is
0x66 (used by newer firmware). The 0x66 variant is equal to 0x63 of
eKTH3500, while 0x63 needs small adjustment of the touch pressure value.

Nexus 7 tablet device has eKTF3624 touchscreen and it uses 0x66 opcode for
reporting touch events, let's support it now. Other devices, eg. ASUS TF300T,
use 0x63.

Note: CMD_HEADER_REK is used for replying to calibration requests, it has
the same 0x66 opcode number which eKTF3624 uses for reporting touches.
The calibration replies are handled separately from the the rest of the
commands in the driver by entering into ELAN_WAIT_RECALIBRATION state
and thus this change shouldn't change the old behavior.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
Tested-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
---
 drivers/input/touchscreen/elants_i2c.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/input/touchscreen/elants_i2c.c b/drivers/input/touchscreen/elants_i2c.c
index 2b936e920874..9751139e8507 100644
--- a/drivers/input/touchscreen/elants_i2c.c
+++ b/drivers/input/touchscreen/elants_i2c.c
@@ -60,6 +60,15 @@
 #define QUEUE_HEADER_NORMAL	0X63
 #define QUEUE_HEADER_WAIT	0x64
 
+/*
+ * Depending on firmware version, eKTF3624 touchscreens may utilize one of
+ * these opcodes for the touch events: 0x63 and 0x66. The 0x63 is used by
+ * older firmware version and differs from 0x66 such that touch pressure
+ * value needs to be adjusted. The 0x66 opcode of newer firmware is equal
+ * to 0x63 of eKTH3500.
+ */
+#define QUEUE_HEADER_NORMAL2	0x66
+
 /* Command header definition */
 #define CMD_HEADER_WRITE	0x54
 #define CMD_HEADER_READ		0x53
@@ -1050,7 +1059,6 @@ static irqreturn_t elants_i2c_irq(int irq, void *_dev)
 		switch (ts->buf[FW_HDR_TYPE]) {
 		case CMD_HEADER_HELLO:
 		case CMD_HEADER_RESP:
-		case CMD_HEADER_REK:
 			break;
 
 		case QUEUE_HEADER_WAIT:
@@ -1070,6 +1078,7 @@ static irqreturn_t elants_i2c_irq(int irq, void *_dev)
 			break;
 
 		case QUEUE_HEADER_NORMAL:
+		case QUEUE_HEADER_NORMAL2:
 			report_count = ts->buf[FW_HDR_COUNT];
 			if (report_count == 0 || report_count > 3) {
 				dev_err(&client->dev,
-- 
2.20.1


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

* [PATCH v3 9/9] dt-bindings: input: elants-i2c: Document eKTF3624
  2020-04-13 13:32 [PATCH v3 0/9] input: elants: Support Asus TF300T touchscreen Michał Mirosław
                   ` (7 preceding siblings ...)
  2020-04-13 13:32 ` [PATCH v3 8/9] dt-bindings: input: elants-i2c: Document common touchscreen properties Michał Mirosław
@ 2020-04-13 13:32 ` Michał Mirosław
  8 siblings, 0 replies; 24+ messages in thread
From: Michał Mirosław @ 2020-04-13 13:32 UTC (permalink / raw)
  To: Dmitry Osipenko, Dmitry Torokhov, Henrik Rydberg, James Chen,
	Johnny Chuang, Rob Herring, Scott Liu, David Heidelberg
  Cc: linux-input, linux-kernel

From: Dmitry Osipenko <digetx@gmail.com>

The eKTF3624 hardware is similar to eKTH3500.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
Reviewed-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
---
 Documentation/devicetree/bindings/input/elants_i2c.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/input/elants_i2c.txt b/Documentation/devicetree/bindings/input/elants_i2c.txt
index 45fab32bbc19..1bc60303f0ea 100644
--- a/Documentation/devicetree/bindings/input/elants_i2c.txt
+++ b/Documentation/devicetree/bindings/input/elants_i2c.txt
@@ -1,7 +1,7 @@
 Elantech I2C Touchscreen
 
 Required properties:
-- compatible: must be "elan,ekth3500".
+- compatible: must be "elan,ekth3500" or "elan,ektf3624".
 - reg: I2C address of the chip.
 - interrupts: interrupt to which the chip is connected (see interrupt
   binding[0]).
-- 
2.20.1


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

* Re: [PATCH v3 3/9] input: elants: remove unused axes
  2020-04-13 13:32 ` [PATCH v3 3/9] input: elants: remove unused axes Michał Mirosław
@ 2020-04-26  4:52   ` Dmitry Torokhov
  2020-04-26  5:07     ` Dmitry Osipenko
  2020-04-26 11:21     ` Michał Mirosław
  0 siblings, 2 replies; 24+ messages in thread
From: Dmitry Torokhov @ 2020-04-26  4:52 UTC (permalink / raw)
  To: Michał Mirosław
  Cc: Dmitry Osipenko, Henrik Rydberg, James Chen, Johnny Chuang,
	Rob Herring, Scott Liu, David Heidelberg, linux-input,
	linux-kernel

On Mon, Apr 13, 2020 at 03:32:23PM +0200, Michał Mirosław wrote:
> Driver only ever reports MT events. Clear capabilities of all others.

This is not true. input_mt_sync_frame() calls
input_mt_report_pointer_emulation() which does emut single-touch events
for the benefit of older userspace (or userspace that is not interested
in multitouch).

Thanks.

-- 
Dmitry

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

* Re: [PATCH v3 3/9] input: elants: remove unused axes
  2020-04-26  4:52   ` Dmitry Torokhov
@ 2020-04-26  5:07     ` Dmitry Osipenko
  2020-04-26 11:21     ` Michał Mirosław
  1 sibling, 0 replies; 24+ messages in thread
From: Dmitry Osipenko @ 2020-04-26  5:07 UTC (permalink / raw)
  To: Dmitry Torokhov, Michał Mirosław
  Cc: Henrik Rydberg, James Chen, Johnny Chuang, Rob Herring,
	Scott Liu, David Heidelberg, linux-input, linux-kernel

26.04.2020 07:52, Dmitry Torokhov пишет:
> On Mon, Apr 13, 2020 at 03:32:23PM +0200, Michał Mirosław wrote:
>> Driver only ever reports MT events. Clear capabilities of all others.
> 
> This is not true. input_mt_sync_frame() calls
> input_mt_report_pointer_emulation() which does emut single-touch events
> for the benefit of older userspace (or userspace that is not interested
> in multitouch).

That's a good catch, thank you very much for the clarification!

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

* Re: [PATCH v3 5/9] input: elants: refactor elants_i2c_execute_command()
  2020-04-13 13:32 ` [PATCH v3 5/9] input: elants: refactor elants_i2c_execute_command() Michał Mirosław
@ 2020-04-26  5:08   ` Dmitry Torokhov
  0 siblings, 0 replies; 24+ messages in thread
From: Dmitry Torokhov @ 2020-04-26  5:08 UTC (permalink / raw)
  To: Michał Mirosław
  Cc: Dmitry Osipenko, Henrik Rydberg, James Chen, Johnny Chuang,
	Rob Herring, Scott Liu, David Heidelberg, linux-input,
	linux-kernel

On Mon, Apr 13, 2020 at 03:32:24PM +0200, Michał Mirosław wrote:
> Apply some DRY-ing to elants_i2c_execute_command() callers.  This pulls
> polling and error printk()s into a single function.
> 
> Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
> ---
>  drivers/input/touchscreen/elants_i2c.c | 189 +++++++++++++------------
>  1 file changed, 96 insertions(+), 93 deletions(-)
> 
> diff --git a/drivers/input/touchscreen/elants_i2c.c b/drivers/input/touchscreen/elants_i2c.c
> index 87d686ce08f2..b0f083f7f2a9 100644
> --- a/drivers/input/touchscreen/elants_i2c.c
> +++ b/drivers/input/touchscreen/elants_i2c.c
> @@ -205,7 +205,8 @@ static int elants_i2c_read(struct i2c_client *client, void *data, size_t size)
>  
>  static int elants_i2c_execute_command(struct i2c_client *client,
>  				      const u8 *cmd, size_t cmd_size,
> -				      u8 *resp, size_t resp_size)
> +				      u8 *resp, size_t resp_size,
> +				      int retries, const char *cmd_name)
>  {
>  	struct i2c_msg msgs[2];
>  	int ret;
> @@ -225,30 +226,55 @@ static int elants_i2c_execute_command(struct i2c_client *client,
>  		break;
>  
>  	default:
> -		dev_err(&client->dev, "%s: invalid command %*ph\n",
> -			__func__, (int)cmd_size, cmd);
> +		dev_err(&client->dev, "(%s): invalid command: %*ph\n",
> +			cmd_name, (int)cmd_size, cmd);
>  		return -EINVAL;
>  	}
>  
> -	msgs[0].addr = client->addr;
> -	msgs[0].flags = client->flags & I2C_M_TEN;
> -	msgs[0].len = cmd_size;
> -	msgs[0].buf = (u8 *)cmd;
> +	for (;;) {
> +		msgs[0].addr = client->addr;
> +		msgs[0].flags = client->flags & I2C_M_TEN;
> +		msgs[0].len = cmd_size;
> +		msgs[0].buf = (u8 *)cmd;
>  
> -	msgs[1].addr = client->addr;
> -	msgs[1].flags = client->flags & I2C_M_TEN;
> -	msgs[1].flags |= I2C_M_RD;
> -	msgs[1].len = resp_size;
> -	msgs[1].buf = resp;
> +		msgs[1].addr = client->addr;
> +		msgs[1].flags = client->flags & I2C_M_TEN;
> +		msgs[1].flags |= I2C_M_RD;
> +		msgs[1].len = resp_size;
> +		msgs[1].buf = resp;
>  
> -	ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
> -	if (ret < 0)
> -		return ret;
> +		ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
> +		if (ret < 0) {
> +			if (--retries > 0) {
> +				dev_dbg(&client->dev,
> +					"(%s) I2C transfer failed: %d (retrying)\n",
> +					cmd_name, ret);
> +				continue;
> +			}
>  
> -	if (ret != ARRAY_SIZE(msgs) || resp[FW_HDR_TYPE] != expected_response)
> -		return -EIO;
> +			dev_err(&client->dev,
> +				"(%s) I2C transfer failed: %d\n",
> +				cmd_name, ret);
> +			return ret;
> +		}
>  
> -	return 0;
> +		if (ret != ARRAY_SIZE(msgs) ||
> +		    resp[FW_HDR_TYPE] != expected_response) {
> +			if (--retries > 0) {
> +				dev_dbg(&client->dev,
> +					"(%s) unexpected response: %*ph (retrying)\n",
> +					cmd_name, ret, resp);
> +				continue;
> +			}
> +
> +			dev_err(&client->dev,
> +				"(%s) unexpected response: %*ph\n",
> +				cmd_name, ret, resp);
> +			return -EIO;
> +		}
> +
> +		return --retries;

I'd prefer if we returned 0 on success and I'd be OK when flashing
firmware to have separate retry counters for the command themselves and
for checking the response.

Thanks.

-- 
Dmitry

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

* Re: [PATCH v3 6/9] input: elants: read touchscreen size for EKTF3624
  2020-04-13 13:32 ` [PATCH v3 6/9] input: elants: read touchscreen size for EKTF3624 Michał Mirosław
@ 2020-04-26  5:10   ` Dmitry Torokhov
  0 siblings, 0 replies; 24+ messages in thread
From: Dmitry Torokhov @ 2020-04-26  5:10 UTC (permalink / raw)
  To: Michał Mirosław, Johnny Chuang
  Cc: Dmitry Osipenko, Henrik Rydberg, James Chen, Rob Herring,
	Scott Liu, David Heidelberg, linux-input, linux-kernel

On Mon, Apr 13, 2020 at 03:32:25PM +0200, Michał Mirosław wrote:
> EKTF3624 as present in Asus TF300T tablet has touchscreen size encoded
> in different registers.

Is this property of chip or property of the device? Johnny, I really
need your input here.

Thanks.

> 
> Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
> Reviewed-by: Dmitry Osipenko <digetx@gmail.com>
> Tested-by: Dmitry Osipenko <digetx@gmail.com>
> ---
>  drivers/input/touchscreen/elants_i2c.c | 82 ++++++++++++++++++++++++--
>  1 file changed, 77 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/input/touchscreen/elants_i2c.c b/drivers/input/touchscreen/elants_i2c.c
> index b0f083f7f2a9..2b936e920874 100644
> --- a/drivers/input/touchscreen/elants_i2c.c
> +++ b/drivers/input/touchscreen/elants_i2c.c
> @@ -34,7 +34,7 @@
>  #include <linux/input/mt.h>
>  #include <linux/input/touchscreen.h>
>  #include <linux/acpi.h>
> -#include <linux/of.h>
> +#include <linux/of_device.h>
>  #include <linux/gpio/consumer.h>
>  #include <linux/regulator/consumer.h>
>  #include <asm/unaligned.h>
> @@ -42,6 +42,10 @@
>  /* Device, Driver information */
>  #define DEVICE_NAME	"elants_i2c"
>  
> +/* Device IDs */
> +#define EKTH3500	0
> +#define EKTF3624	1
> +
>  /* Convert from rows or columns into resolution */
>  #define ELAN_TS_RESOLUTION(n, m)   (((n) - 1) * (m))
>  
> @@ -164,6 +168,7 @@ struct elants_data {
>  
>  	bool wake_irq_enabled;
>  	bool keep_power_in_suspend;
> +	u8 chip_id;
>  
>  	/* Must be last to be used for DMA operations */
>  	u8 buf[MAX_PACKET_SIZE] ____cacheline_aligned;
> @@ -442,7 +447,58 @@ static int elants_i2c_query_bc_version(struct elants_data *ts)
>  	return 0;
>  }
>  
> -static int elants_i2c_query_ts_info(struct elants_data *ts)
> +static int elants_i2c_query_ts_info_ektf(struct elants_data *ts)
> +{
> +	struct i2c_client *client = ts->client;
> +	int error;
> +	u8 resp[4];
> +	u16 phy_x, phy_y;
> +	const u8 get_xres_cmd[] = {
> +		CMD_HEADER_READ, E_INFO_X_RES, 0x00, 0x00
> +	};
> +	const u8 get_yres_cmd[] = {
> +		CMD_HEADER_READ, E_INFO_Y_RES, 0x00, 0x00
> +	};
> +
> +	/* Get X/Y size in mm */
> +	error = elants_i2c_execute_command(client, get_xres_cmd,
> +					   sizeof(get_xres_cmd),
> +					   resp, sizeof(resp), 1,
> +					   "get X size");
> +	if (error)
> +		return error;
> +
> +	phy_x = resp[2] | ((resp[3] & 0xF0) << 4);
> +
> +	error = elants_i2c_execute_command(client, get_yres_cmd,
> +					   sizeof(get_yres_cmd),
> +					   resp, sizeof(resp), 1,
> +					   "get Y size");
> +	if (error)
> +		return error;
> +
> +	phy_y = resp[2] | ((resp[3] & 0xF0) << 4);
> +
> +	if (!phy_x || !phy_y) {
> +		dev_warn(&client->dev,
> +			 "invalid size data: %d x %d mm\n",
> +			 phy_x, phy_y);
> +		return 0;
> +	}
> +
> +	dev_dbg(&client->dev, "phy_x=%d, phy_y=%d\n", phy_x, phy_y);
> +
> +	/* calculate resolution from size */
> +	ts->x_max = 2240-1;
> +	ts->x_res = DIV_ROUND_CLOSEST(ts->prop.max_x, phy_x);
> +
> +	ts->y_max = 1408-1;
> +	ts->y_res = DIV_ROUND_CLOSEST(ts->prop.max_y, phy_y);
> +
> +	return 0;
> +}
> +
> +static int elants_i2c_query_ts_info_ekth(struct elants_data *ts)
>  {
>  	struct i2c_client *client = ts->client;
>  	int error;
> @@ -593,8 +649,20 @@ static int elants_i2c_initialize(struct elants_data *ts)
>  		error = elants_i2c_query_fw_version(ts);
>  	if (!error)
>  		error = elants_i2c_query_test_version(ts);
> -	if (!error)
> -		error = elants_i2c_query_ts_info(ts);
> +
> +	switch (ts->chip_id) {
> +	case EKTH3500:
> +		if (!error)
> +			error = elants_i2c_query_ts_info_ekth(ts);
> +		break;
> +	case EKTF3624:
> +		if (!error)
> +			error = elants_i2c_query_ts_info_ektf(ts);
> +		break;
> +	default:
> +		unreachable();
> +		break;
> +	}
>  
>  	if (error)
>  		ts->iap_mode = ELAN_IAP_RECOVERY;
> @@ -1245,6 +1313,9 @@ static int elants_i2c_probe(struct i2c_client *client,
>  	ts->client = client;
>  	i2c_set_clientdata(client, ts);
>  
> +	if (client->dev.of_node)
> +		ts->chip_id = (uintptr_t)of_device_get_match_data(&client->dev);
> +
>  	ts->vcc33 = devm_regulator_get(&client->dev, "vcc33");
>  	if (IS_ERR(ts->vcc33)) {
>  		error = PTR_ERR(ts->vcc33);
> @@ -1470,7 +1541,8 @@ MODULE_DEVICE_TABLE(acpi, elants_acpi_id);
>  
>  #ifdef CONFIG_OF
>  static const struct of_device_id elants_of_match[] = {
> -	{ .compatible = "elan,ekth3500" },
> +	{ .compatible = "elan,ekth3500", .data = (void *)EKTH3500 },
> +	{ .compatible = "elan,ektf3624", .data = (void *)EKTF3624 },
>  	{ /* sentinel */ }
>  };
>  MODULE_DEVICE_TABLE(of, elants_of_match);
> -- 
> 2.20.1
> 

-- 
Dmitry

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

* Re: [PATCH v3 4/9] input: elants: override touchscreen info with DT properties
  2020-04-13 13:32 ` [PATCH v3 4/9] input: elants: override touchscreen info with DT properties Michał Mirosław
@ 2020-04-26  5:11   ` Dmitry Torokhov
  2020-04-26  5:12     ` Dmitry Torokhov
  0 siblings, 1 reply; 24+ messages in thread
From: Dmitry Torokhov @ 2020-04-26  5:11 UTC (permalink / raw)
  To: Michał Mirosław
  Cc: Dmitry Osipenko, Henrik Rydberg, James Chen, Johnny Chuang,
	Rob Herring, Scott Liu, David Heidelberg, linux-input,
	linux-kernel

On Mon, Apr 13, 2020 at 03:32:24PM +0200, Michał Mirosław wrote:
> Allow overriding of information from hardware and support additional
> common DT properties like axis inversion. This is required for eg.
> Nexus 7 and TF300T where the programmed values in firmware differ
> from reality.
> 
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
> [moved "prop" before DMA buffer]
> Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>

This needs a companion patch for the DT bindings.

> ---
>  drivers/input/touchscreen/elants_i2c.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/input/touchscreen/elants_i2c.c b/drivers/input/touchscreen/elants_i2c.c
> index fcd3d189f184..87d686ce08f2 100644
> --- a/drivers/input/touchscreen/elants_i2c.c
> +++ b/drivers/input/touchscreen/elants_i2c.c
> @@ -32,6 +32,7 @@
>  #include <linux/slab.h>
>  #include <linux/firmware.h>
>  #include <linux/input/mt.h>
> +#include <linux/input/touchscreen.h>
>  #include <linux/acpi.h>
>  #include <linux/of.h>
>  #include <linux/gpio/consumer.h>
> @@ -150,6 +151,7 @@ struct elants_data {
>  	unsigned int y_res;
>  	unsigned int x_max;
>  	unsigned int y_max;
> +	struct touchscreen_properties prop;
>  
>  	enum elants_state state;
>  	enum elants_iap_mode iap_mode;
> @@ -894,8 +896,7 @@ static void elants_i2c_mt_event(struct elants_data *ts, u8 *buf,
>  
>  			input_mt_slot(input, i);
>  			input_mt_report_slot_state(input, MT_TOOL_FINGER, true);
> -			input_event(input, EV_ABS, ABS_MT_POSITION_X, x);
> -			input_event(input, EV_ABS, ABS_MT_POSITION_Y, y);
> +			touchscreen_report_pos(input, &ts->prop, x, y, true);
>  			input_event(input, EV_ABS, ABS_MT_PRESSURE, p);
>  			input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, w);
>  
> @@ -1329,6 +1330,8 @@ static int elants_i2c_probe(struct i2c_client *client,
>  	input_abs_set_res(ts->input, ABS_MT_POSITION_Y, ts->y_res);
>  	input_abs_set_res(ts->input, ABS_MT_TOUCH_MAJOR, 1);
>  
> +	touchscreen_parse_properties(ts->input, true, &ts->prop);
> +
>  	error = input_register_device(ts->input);
>  	if (error) {
>  		dev_err(&client->dev,
> -- 
> 2.20.1
> 

-- 
Dmitry

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

* Re: [PATCH v3 4/9] input: elants: override touchscreen info with DT properties
  2020-04-26  5:11   ` Dmitry Torokhov
@ 2020-04-26  5:12     ` Dmitry Torokhov
  0 siblings, 0 replies; 24+ messages in thread
From: Dmitry Torokhov @ 2020-04-26  5:12 UTC (permalink / raw)
  To: Michał Mirosław
  Cc: Dmitry Osipenko, Henrik Rydberg, James Chen, Johnny Chuang,
	Rob Herring, Scott Liu, David Heidelberg, linux-input,
	linux-kernel

On Sat, Apr 25, 2020 at 10:11:22PM -0700, Dmitry Torokhov wrote:
> On Mon, Apr 13, 2020 at 03:32:24PM +0200, Michał Mirosław wrote:
> > Allow overriding of information from hardware and support additional
> > common DT properties like axis inversion. This is required for eg.
> > Nexus 7 and TF300T where the programmed values in firmware differ
> > from reality.
> > 
> > Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
> > [moved "prop" before DMA buffer]
> > Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
> 
> This needs a companion patch for the DT bindings.

Ah, sorry, I missed the fact that it was later in the sequence.

> 
> > ---
> >  drivers/input/touchscreen/elants_i2c.c | 7 +++++--
> >  1 file changed, 5 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/input/touchscreen/elants_i2c.c b/drivers/input/touchscreen/elants_i2c.c
> > index fcd3d189f184..87d686ce08f2 100644
> > --- a/drivers/input/touchscreen/elants_i2c.c
> > +++ b/drivers/input/touchscreen/elants_i2c.c
> > @@ -32,6 +32,7 @@
> >  #include <linux/slab.h>
> >  #include <linux/firmware.h>
> >  #include <linux/input/mt.h>
> > +#include <linux/input/touchscreen.h>
> >  #include <linux/acpi.h>
> >  #include <linux/of.h>
> >  #include <linux/gpio/consumer.h>
> > @@ -150,6 +151,7 @@ struct elants_data {
> >  	unsigned int y_res;
> >  	unsigned int x_max;
> >  	unsigned int y_max;
> > +	struct touchscreen_properties prop;
> >  
> >  	enum elants_state state;
> >  	enum elants_iap_mode iap_mode;
> > @@ -894,8 +896,7 @@ static void elants_i2c_mt_event(struct elants_data *ts, u8 *buf,
> >  
> >  			input_mt_slot(input, i);
> >  			input_mt_report_slot_state(input, MT_TOOL_FINGER, true);
> > -			input_event(input, EV_ABS, ABS_MT_POSITION_X, x);
> > -			input_event(input, EV_ABS, ABS_MT_POSITION_Y, y);
> > +			touchscreen_report_pos(input, &ts->prop, x, y, true);
> >  			input_event(input, EV_ABS, ABS_MT_PRESSURE, p);
> >  			input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, w);
> >  
> > @@ -1329,6 +1330,8 @@ static int elants_i2c_probe(struct i2c_client *client,
> >  	input_abs_set_res(ts->input, ABS_MT_POSITION_Y, ts->y_res);
> >  	input_abs_set_res(ts->input, ABS_MT_TOUCH_MAJOR, 1);
> >  
> > +	touchscreen_parse_properties(ts->input, true, &ts->prop);
> > +
> >  	error = input_register_device(ts->input);
> >  	if (error) {
> >  		dev_err(&client->dev,
> > -- 
> > 2.20.1
> > 
> 
> -- 
> Dmitry

-- 
Dmitry

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

* Re: [PATCH v3 7/9] input: elants: support 0x66 reply opcode for reporting touches
  2020-04-13 13:32 ` [PATCH v3 7/9] input: elants: support 0x66 reply opcode for reporting touches Michał Mirosław
@ 2020-04-26  5:15   ` Dmitry Torokhov
  2020-04-26  5:21     ` Dmitry Osipenko
  0 siblings, 1 reply; 24+ messages in thread
From: Dmitry Torokhov @ 2020-04-26  5:15 UTC (permalink / raw)
  To: Michał Mirosław
  Cc: Dmitry Osipenko, Henrik Rydberg, James Chen, Johnny Chuang,
	Rob Herring, Scott Liu, David Heidelberg, linux-input,
	linux-kernel

On Mon, Apr 13, 2020 at 03:32:26PM +0200, Michał Mirosław wrote:
> From: Dmitry Osipenko <digetx@gmail.com>
> 
> eKTF3624 touchscreen firmware uses two variants of the reply opcodes for
> reporting touch events: one is 0x63 (used by older firmware) and other is
> 0x66 (used by newer firmware). The 0x66 variant is equal to 0x63 of
> eKTH3500, while 0x63 needs small adjustment of the touch pressure value.
> 
> Nexus 7 tablet device has eKTF3624 touchscreen and it uses 0x66 opcode for
> reporting touch events, let's support it now. Other devices, eg. ASUS TF300T,
> use 0x63.
> 
> Note: CMD_HEADER_REK is used for replying to calibration requests, it has
> the same 0x66 opcode number which eKTF3624 uses for reporting touches.
> The calibration replies are handled separately from the the rest of the
> commands in the driver by entering into ELAN_WAIT_RECALIBRATION state
> and thus this change shouldn't change the old behavior.
> 
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
> Tested-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
> Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
> ---
>  drivers/input/touchscreen/elants_i2c.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/input/touchscreen/elants_i2c.c b/drivers/input/touchscreen/elants_i2c.c
> index 2b936e920874..9751139e8507 100644
> --- a/drivers/input/touchscreen/elants_i2c.c
> +++ b/drivers/input/touchscreen/elants_i2c.c
> @@ -60,6 +60,15 @@
>  #define QUEUE_HEADER_NORMAL	0X63
>  #define QUEUE_HEADER_WAIT	0x64
>  
> +/*
> + * Depending on firmware version, eKTF3624 touchscreens may utilize one of
> + * these opcodes for the touch events: 0x63 and 0x66. The 0x63 is used by
> + * older firmware version and differs from 0x66 such that touch pressure
> + * value needs to be adjusted.

Who is responsible for the adjustment? Where does it happen?

Thanks.

-- 
Dmitry

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

* Re: [PATCH v3 7/9] input: elants: support 0x66 reply opcode for reporting touches
  2020-04-26  5:15   ` Dmitry Torokhov
@ 2020-04-26  5:21     ` Dmitry Osipenko
  0 siblings, 0 replies; 24+ messages in thread
From: Dmitry Osipenko @ 2020-04-26  5:21 UTC (permalink / raw)
  To: Dmitry Torokhov, Michał Mirosław
  Cc: Henrik Rydberg, James Chen, Johnny Chuang, Rob Herring,
	Scott Liu, David Heidelberg, linux-input, linux-kernel

26.04.2020 08:15, Dmitry Torokhov пишет:
> On Mon, Apr 13, 2020 at 03:32:26PM +0200, Michał Mirosław wrote:
>> From: Dmitry Osipenko <digetx@gmail.com>
>>
>> eKTF3624 touchscreen firmware uses two variants of the reply opcodes for
>> reporting touch events: one is 0x63 (used by older firmware) and other is
>> 0x66 (used by newer firmware). The 0x66 variant is equal to 0x63 of
>> eKTH3500, while 0x63 needs small adjustment of the touch pressure value.
>>
>> Nexus 7 tablet device has eKTF3624 touchscreen and it uses 0x66 opcode for
>> reporting touch events, let's support it now. Other devices, eg. ASUS TF300T,
>> use 0x63.
>>
>> Note: CMD_HEADER_REK is used for replying to calibration requests, it has
>> the same 0x66 opcode number which eKTF3624 uses for reporting touches.
>> The calibration replies are handled separately from the the rest of the
>> commands in the driver by entering into ELAN_WAIT_RECALIBRATION state
>> and thus this change shouldn't change the old behavior.
>>
>> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
>> Tested-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
>> Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
>> ---
>>  drivers/input/touchscreen/elants_i2c.c | 11 ++++++++++-
>>  1 file changed, 10 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/input/touchscreen/elants_i2c.c b/drivers/input/touchscreen/elants_i2c.c
>> index 2b936e920874..9751139e8507 100644
>> --- a/drivers/input/touchscreen/elants_i2c.c
>> +++ b/drivers/input/touchscreen/elants_i2c.c
>> @@ -60,6 +60,15 @@
>>  #define QUEUE_HEADER_NORMAL	0X63
>>  #define QUEUE_HEADER_WAIT	0x64
>>  
>> +/*
>> + * Depending on firmware version, eKTF3624 touchscreens may utilize one of
>> + * these opcodes for the touch events: 0x63 and 0x66. The 0x63 is used by
>> + * older firmware version and differs from 0x66 such that touch pressure
>> + * value needs to be adjusted.
> 
> Who is responsible for the adjustment? Where does it happen?


Please see the patch #2 ("support old touch report format") which adds
support for parsing of the older packet format that requires the
pressure value adjustment.

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

* Re: [PATCH v3 3/9] input: elants: remove unused axes
  2020-04-26  4:52   ` Dmitry Torokhov
  2020-04-26  5:07     ` Dmitry Osipenko
@ 2020-04-26 11:21     ` Michał Mirosław
  2020-04-26 15:39       ` Dmitry Osipenko
  1 sibling, 1 reply; 24+ messages in thread
From: Michał Mirosław @ 2020-04-26 11:21 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Dmitry Osipenko, Henrik Rydberg, James Chen, Johnny Chuang,
	Rob Herring, Scott Liu, David Heidelberg, linux-input,
	linux-kernel

On Sat, Apr 25, 2020 at 09:52:00PM -0700, Dmitry Torokhov wrote:
> On Mon, Apr 13, 2020 at 03:32:23PM +0200, Michał Mirosław wrote:
> > Driver only ever reports MT events. Clear capabilities of all others.
> This is not true. input_mt_sync_frame() calls
> input_mt_report_pointer_emulation() which does emut single-touch events
> for the benefit of older userspace (or userspace that is not interested
> in multitouch).

Oh, I didn't notice that. Looking at the code, I see that
input_mt_init_slots() sets up the emulated axes in this case.

Do you need me to update the commitmsg?

Best Regards,
Michał Mirosław

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

* Re: [PATCH v3 3/9] input: elants: remove unused axes
  2020-04-26 11:21     ` Michał Mirosław
@ 2020-04-26 15:39       ` Dmitry Osipenko
  2020-04-26 15:41         ` Dmitry Osipenko
  0 siblings, 1 reply; 24+ messages in thread
From: Dmitry Osipenko @ 2020-04-26 15:39 UTC (permalink / raw)
  To: Michał Mirosław, Dmitry Torokhov
  Cc: Henrik Rydberg, James Chen, Johnny Chuang, Rob Herring,
	Scott Liu, David Heidelberg, linux-input, linux-kernel

26.04.2020 14:21, Michał Mirosław пишет:
> On Sat, Apr 25, 2020 at 09:52:00PM -0700, Dmitry Torokhov wrote:
>> On Mon, Apr 13, 2020 at 03:32:23PM +0200, Michał Mirosław wrote:
>>> Driver only ever reports MT events. Clear capabilities of all others.
>> This is not true. input_mt_sync_frame() calls
>> input_mt_report_pointer_emulation() which does emut single-touch events
>> for the benefit of older userspace (or userspace that is not interested
>> in multitouch).
> 
> Oh, I didn't notice that. Looking at the code, I see that
> input_mt_init_slots() sets up the emulated axes in this case.
> 
> Do you need me to update the commitmsg?

I tried Ubuntu 12.04 that uses ancient libinput (or whatever it was back
then), which doesn't support MT. Mouse doesn't move at all with this
patch being applied. Without this patch mouse moves, but it's not usable
because the cursor's position is wrong, i.e. mouse position doesn't
match the screen touches.

This means that input_mt_report_pointer_emulation() doesn't set up
everything needed for the legacy pointer emulation.

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

* Re: [PATCH v3 3/9] input: elants: remove unused axes
  2020-04-26 15:39       ` Dmitry Osipenko
@ 2020-04-26 15:41         ` Dmitry Osipenko
  2020-04-26 16:11           ` Dmitry Osipenko
  2020-04-26 16:12           ` Michał Mirosław
  0 siblings, 2 replies; 24+ messages in thread
From: Dmitry Osipenko @ 2020-04-26 15:41 UTC (permalink / raw)
  To: Michał Mirosław, Dmitry Torokhov
  Cc: Henrik Rydberg, James Chen, Johnny Chuang, Rob Herring,
	Scott Liu, David Heidelberg, linux-input, linux-kernel

26.04.2020 18:39, Dmitry Osipenko пишет:
> 26.04.2020 14:21, Michał Mirosław пишет:
>> On Sat, Apr 25, 2020 at 09:52:00PM -0700, Dmitry Torokhov wrote:
>>> On Mon, Apr 13, 2020 at 03:32:23PM +0200, Michał Mirosław wrote:
>>>> Driver only ever reports MT events. Clear capabilities of all others.
>>> This is not true. input_mt_sync_frame() calls
>>> input_mt_report_pointer_emulation() which does emut single-touch events
>>> for the benefit of older userspace (or userspace that is not interested
>>> in multitouch).
>>
>> Oh, I didn't notice that. Looking at the code, I see that
>> input_mt_init_slots() sets up the emulated axes in this case.
>>
>> Do you need me to update the commitmsg?
> 
> I tried Ubuntu 12.04 that uses ancient libinput (or whatever it was back
> then), which doesn't support MT. Mouse doesn't move at all with this
> patch being applied. Without this patch mouse moves, but it's not usable
> because the cursor's position is wrong, i.e. mouse position doesn't
> match the screen touches.
> 
> This means that input_mt_report_pointer_emulation() doesn't set up
> everything needed for the legacy pointer emulation.
> 

I meant the input_mt_init_slots().

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

* Re: [PATCH v3 3/9] input: elants: remove unused axes
  2020-04-26 15:41         ` Dmitry Osipenko
@ 2020-04-26 16:11           ` Dmitry Osipenko
  2020-04-26 16:12           ` Michał Mirosław
  1 sibling, 0 replies; 24+ messages in thread
From: Dmitry Osipenko @ 2020-04-26 16:11 UTC (permalink / raw)
  To: Michał Mirosław, Dmitry Torokhov
  Cc: Henrik Rydberg, James Chen, Johnny Chuang, Rob Herring,
	Scott Liu, David Heidelberg, linux-input, linux-kernel

26.04.2020 18:41, Dmitry Osipenko пишет:
> 26.04.2020 18:39, Dmitry Osipenko пишет:
>> 26.04.2020 14:21, Michał Mirosław пишет:
>>> On Sat, Apr 25, 2020 at 09:52:00PM -0700, Dmitry Torokhov wrote:
>>>> On Mon, Apr 13, 2020 at 03:32:23PM +0200, Michał Mirosław wrote:
>>>>> Driver only ever reports MT events. Clear capabilities of all others.
>>>> This is not true. input_mt_sync_frame() calls
>>>> input_mt_report_pointer_emulation() which does emut single-touch events
>>>> for the benefit of older userspace (or userspace that is not interested
>>>> in multitouch).
>>>
>>> Oh, I didn't notice that. Looking at the code, I see that
>>> input_mt_init_slots() sets up the emulated axes in this case.
>>>
>>> Do you need me to update the commitmsg?
>>
>> I tried Ubuntu 12.04 that uses ancient libinput (or whatever it was back
>> then), which doesn't support MT. Mouse doesn't move at all with this
>> patch being applied.

> Without this patch mouse moves, but it's not usable
>> because the cursor's position is wrong, i.e. mouse position doesn't
>> match the screen touches.

The fix for the legacy pointer emulation is trivial:

--- >8 ---
diff --git a/drivers/input/touchscreen/elants_i2c.c
b/drivers/input/touchscreen/elants_i2c.c
index 060c60c04f25..3644b5b48081 100644
--- a/drivers/input/touchscreen/elants_i2c.c
+++ b/drivers/input/touchscreen/elants_i2c.c
@@ -1414,6 +1414,8 @@ static int elants_i2c_probe(struct i2c_client *client,
 	input_abs_set_res(ts->input, ABS_X, ts->x_res);
 	input_abs_set_res(ts->input, ABS_Y, ts->y_res);

+	touchscreen_parse_properties(ts->input, false, &ts->prop);
+
 	/* Multitouch input params setup */
 	error = input_mt_init_slots(ts->input, MAX_CONTACT_NUM,
 				    INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED);
--- >8 ---

Michał, please incorporate this change into the next version.

>> This means that input_mt_report_pointer_emulation() doesn't set up
>> everything needed for the legacy pointer emulation.
>>
> 
> I meant the input_mt_init_slots().
> 


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

* Re: [PATCH v3 3/9] input: elants: remove unused axes
  2020-04-26 15:41         ` Dmitry Osipenko
  2020-04-26 16:11           ` Dmitry Osipenko
@ 2020-04-26 16:12           ` Michał Mirosław
  2020-04-26 16:14             ` Dmitry Osipenko
  1 sibling, 1 reply; 24+ messages in thread
From: Michał Mirosław @ 2020-04-26 16:12 UTC (permalink / raw)
  To: Dmitry Osipenko
  Cc: Dmitry Torokhov, Henrik Rydberg, James Chen, Johnny Chuang,
	Rob Herring, Scott Liu, David Heidelberg, linux-input,
	linux-kernel

On Sun, Apr 26, 2020 at 06:41:34PM +0300, Dmitry Osipenko wrote:
> 26.04.2020 18:39, Dmitry Osipenko пишет:
> > 26.04.2020 14:21, Michał Mirosław пишет:
> >> On Sat, Apr 25, 2020 at 09:52:00PM -0700, Dmitry Torokhov wrote:
> >>> On Mon, Apr 13, 2020 at 03:32:23PM +0200, Michał Mirosław wrote:
> >>>> Driver only ever reports MT events. Clear capabilities of all others.
> >>> This is not true. input_mt_sync_frame() calls
> >>> input_mt_report_pointer_emulation() which does emut single-touch events
> >>> for the benefit of older userspace (or userspace that is not interested
> >>> in multitouch).
> >>
> >> Oh, I didn't notice that. Looking at the code, I see that
> >> input_mt_init_slots() sets up the emulated axes in this case.
> >>
> >> Do you need me to update the commitmsg?
> > 
> > I tried Ubuntu 12.04 that uses ancient libinput (or whatever it was back
> > then), which doesn't support MT. Mouse doesn't move at all with this
> > patch being applied. Without this patch mouse moves, but it's not usable
> > because the cursor's position is wrong, i.e. mouse position doesn't
> > match the screen touches.
> > 
> > This means that input_mt_report_pointer_emulation() doesn't set up
> > everything needed for the legacy pointer emulation.
> > 
> 
> I meant the input_mt_init_slots().

Can you try v4 and see if it helps? input_mt_init_slots() needs other
axes set up before for it to use correct ranges.

Best Regards
Michał Mirosław

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

* Re: [PATCH v3 3/9] input: elants: remove unused axes
  2020-04-26 16:12           ` Michał Mirosław
@ 2020-04-26 16:14             ` Dmitry Osipenko
  0 siblings, 0 replies; 24+ messages in thread
From: Dmitry Osipenko @ 2020-04-26 16:14 UTC (permalink / raw)
  To: Michał Mirosław
  Cc: Dmitry Torokhov, Henrik Rydberg, James Chen, Johnny Chuang,
	Rob Herring, Scott Liu, David Heidelberg, linux-input,
	linux-kernel

26.04.2020 19:12, Michał Mirosław пишет:
> On Sun, Apr 26, 2020 at 06:41:34PM +0300, Dmitry Osipenko wrote:
>> 26.04.2020 18:39, Dmitry Osipenko пишет:
>>> 26.04.2020 14:21, Michał Mirosław пишет:
>>>> On Sat, Apr 25, 2020 at 09:52:00PM -0700, Dmitry Torokhov wrote:
>>>>> On Mon, Apr 13, 2020 at 03:32:23PM +0200, Michał Mirosław wrote:
>>>>>> Driver only ever reports MT events. Clear capabilities of all others.
>>>>> This is not true. input_mt_sync_frame() calls
>>>>> input_mt_report_pointer_emulation() which does emut single-touch events
>>>>> for the benefit of older userspace (or userspace that is not interested
>>>>> in multitouch).
>>>>
>>>> Oh, I didn't notice that. Looking at the code, I see that
>>>> input_mt_init_slots() sets up the emulated axes in this case.
>>>>
>>>> Do you need me to update the commitmsg?
>>>
>>> I tried Ubuntu 12.04 that uses ancient libinput (or whatever it was back
>>> then), which doesn't support MT. Mouse doesn't move at all with this
>>> patch being applied. Without this patch mouse moves, but it's not usable
>>> because the cursor's position is wrong, i.e. mouse position doesn't
>>> match the screen touches.
>>>
>>> This means that input_mt_report_pointer_emulation() doesn't set up
>>> everything needed for the legacy pointer emulation.
>>>
>>
>> I meant the input_mt_init_slots().
> 
> Can you try v4 and see if it helps? input_mt_init_slots() needs other
> axes set up before for it to use correct ranges.


Sure! I'll try it right now.


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

end of thread, other threads:[~2020-04-26 16:14 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-13 13:32 [PATCH v3 0/9] input: elants: Support Asus TF300T touchscreen Michał Mirosław
2020-04-13 13:32 ` [PATCH v3 3/9] input: elants: remove unused axes Michał Mirosław
2020-04-26  4:52   ` Dmitry Torokhov
2020-04-26  5:07     ` Dmitry Osipenko
2020-04-26 11:21     ` Michał Mirosław
2020-04-26 15:39       ` Dmitry Osipenko
2020-04-26 15:41         ` Dmitry Osipenko
2020-04-26 16:11           ` Dmitry Osipenko
2020-04-26 16:12           ` Michał Mirosław
2020-04-26 16:14             ` Dmitry Osipenko
2020-04-13 13:32 ` [PATCH v3 2/9] input: elants: support old touch report format Michał Mirosław
2020-04-13 13:32 ` [PATCH v3 1/9] input: elants: document some registers and values Michał Mirosław
2020-04-13 13:32 ` [PATCH v3 4/9] input: elants: override touchscreen info with DT properties Michał Mirosław
2020-04-26  5:11   ` Dmitry Torokhov
2020-04-26  5:12     ` Dmitry Torokhov
2020-04-13 13:32 ` [PATCH v3 5/9] input: elants: refactor elants_i2c_execute_command() Michał Mirosław
2020-04-26  5:08   ` Dmitry Torokhov
2020-04-13 13:32 ` [PATCH v3 6/9] input: elants: read touchscreen size for EKTF3624 Michał Mirosław
2020-04-26  5:10   ` Dmitry Torokhov
2020-04-13 13:32 ` [PATCH v3 7/9] input: elants: support 0x66 reply opcode for reporting touches Michał Mirosław
2020-04-26  5:15   ` Dmitry Torokhov
2020-04-26  5:21     ` Dmitry Osipenko
2020-04-13 13:32 ` [PATCH v3 8/9] dt-bindings: input: elants-i2c: Document common touchscreen properties Michał Mirosław
2020-04-13 13:32 ` [PATCH v3 9/9] dt-bindings: input: elants-i2c: Document eKTF3624 Michał Mirosław

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).