diff mbox series

goodix touchscreen: Add support for 9-bytes reports

Message ID 20190210103051.31219-1-jekhor@gmail.com (mailing list archive)
State Mainlined
Commit bd3b8480237680b5967aee3c814b92b2fd87a582
Headers show
Series goodix touchscreen: Add support for 9-bytes reports | expand

Commit Message

Yauhen Kharuzhy Feb. 10, 2019, 10:30 a.m. UTC
Some variants of Goodix touchscreen firmwares use 9-bytes finger
report format instead of common 8-bytes format.

This report format may be present as:

struct goodix_contact_data {
        uint8_t unknown1;
        uint8_t track_id;
        uint8_t unknown2;
        uint16_t x;
        uint16_t y;
        uint16_t w;
}__attribute__((packed));

Add support for such format and use it for Lenovo Yoga Book notebook
(which uses a Goodix touchpad as a touch keyboard).

Signed-off-by: Yauhen Kharuzhy <jekhor@gmail.com>
---
 drivers/input/touchscreen/goodix.c | 58 +++++++++++++++++++++++++-----
 1 file changed, 50 insertions(+), 8 deletions(-)

Comments

Bastien Nocera Feb. 10, 2019, 11:36 a.m. UTC | #1
Hey,

On Sun, 2019-02-10 at 13:30 +0300, Yauhen Kharuzhy wrote:
> Some variants of Goodix touchscreen firmwares use 9-bytes finger
> report format instead of common 8-bytes format.
<snip>
> +static const struct dmi_system_id nine_bytes_report[] = {
> +#if defined(CONFIG_DMI) && defined(CONFIG_X86)
> +	{
> +		.ident = "Lenovo YogaBook",
> +		/* YB1-X91L/F and YB1-X90L/F */
> +		.matches = {
> +			DMI_MATCH(DMI_PRODUCT_NAME, "Lenovo YB1-X9")
> +		}
> +	},
> +#endif
> +	{}
> +};

Is this really the only way to know whether the report is 8 or 9 bytes?
Which Goodix model is it? Can you find additional information about the
protocol in the specifications[1]

[1]: https://github.com/hadess/gt9xx/tree/master/specifications
Yauhen Kharuzhy Feb. 10, 2019, 3:36 p.m. UTC | #2
On Sun, Feb 10, 2019 at 12:36:44PM +0100, Bastien Nocera wrote:
> Hey,
> 
> On Sun, 2019-02-10 at 13:30 +0300, Yauhen Kharuzhy wrote:
> > Some variants of Goodix touchscreen firmwares use 9-bytes finger
> > report format instead of common 8-bytes format.
> <snip>
> > +static const struct dmi_system_id nine_bytes_report[] = {
> > +#if defined(CONFIG_DMI) && defined(CONFIG_X86)
> > +	{
> > +		.ident = "Lenovo YogaBook",
> > +		/* YB1-X91L/F and YB1-X90L/F */
> > +		.matches = {
> > +			DMI_MATCH(DMI_PRODUCT_NAME, "Lenovo YB1-X9")
> > +		}
> > +	},
> > +#endif
> > +	{}
> > +};
> 
> Is this really the only way to know whether the report is 8 or 9 bytes?
> Which Goodix model is it? Can you find additional information about the
> protocol in the specifications[1]
> 

I didn't find any way. Driver from Lenovo has 9-byte format hardcoded[1,2] and
I cannot find any mention of such format in the datasheet. Maybe (VendorID +
Firmware version) combination will be suitable as key for detection of
this case but I think that it is almost the same as using of DMI product ID.

YogaBook seems to have GT9110 chip.

I can dump the config and FW vendor & version and publish them for checking soon.

1. https://github.com/jekhor/yogabook-linux-android-kernel/blob/b7aa015ab794b516da7b6cb76e5e2d427e3b8b0c/drivers/input/touchscreen/gt9xx/gt9xx.c#L912
2. https://github.com/jekhor/yogabook-linux-android-kernel/blob/b7aa015ab794b516da7b6cb76e5e2d427e3b8b0c/drivers/input/touchscreen/gt9xx/gt9xx.h#L52
Yauhen Kharuzhy Feb. 10, 2019, 6:51 p.m. UTC | #3
On Sun, Feb 10, 2019 at 06:36:29PM +0300, Yauhen Kharuzhy wrote:
> > 
> > Is this really the only way to know whether the report is 8 or 9 bytes?
> > Which Goodix model is it? Can you find additional information about the
> > protocol in the specifications[1]
> > 
> 
> I didn't find any way. Driver from Lenovo has 9-byte format hardcoded[1,2] and
> I cannot find any mention of such format in the datasheet. Maybe (VendorID +
> Firmware version) combination will be suitable as key for detection of
> this case but I think that it is almost the same as using of DMI product ID.
> 
> YogaBook seems to have GT9110 chip.
> 
> I can dump the config and FW vendor & version and publish them for checking soon.

Here is config & FW version registers dump: https://github.com/jekhor/yogabook-linux/blob/master/yoga/goodix-dump.log
Yauhen Kharuzhy March 8, 2019, 6:55 p.m. UTC | #4
On Sun, Feb 10, 2019 at 09:51:28PM +0300, Yauhen Kharuzhy wrote:
> On Sun, Feb 10, 2019 at 06:36:29PM +0300, Yauhen Kharuzhy wrote:
> > > 
> > > Is this really the only way to know whether the report is 8 or 9 bytes?
> > > Which Goodix model is it? Can you find additional information about the
> > > protocol in the specifications[1]
> > > 
> > 
> > I didn't find any way. Driver from Lenovo has 9-byte format hardcoded[1,2] and
> > I cannot find any mention of such format in the datasheet. Maybe (VendorID +
> > Firmware version) combination will be suitable as key for detection of
> > this case but I think that it is almost the same as using of DMI product ID.
> > 
> > YogaBook seems to have GT9110 chip.
> > 
> > I can dump the config and FW vendor & version and publish them for checking soon.
> 
> Here is config & FW version registers dump: https://github.com/jekhor/yogabook-linux/blob/master/yoga/goodix-dump.log

Hello, just reminder.

Any comments, advices, ideas about supporting this kind of report format?
diff mbox series

Patch

diff --git a/drivers/input/touchscreen/goodix.c b/drivers/input/touchscreen/goodix.c
index f2d9c2c41885..f42860c788b9 100644
--- a/drivers/input/touchscreen/goodix.c
+++ b/drivers/input/touchscreen/goodix.c
@@ -54,6 +54,7 @@  struct goodix_ts_data {
 	const char *cfg_name;
 	struct completion firmware_loading_complete;
 	unsigned long irq_flags;
+	unsigned int contact_size;
 };
 
 #define GOODIX_GPIO_INT_NAME		"irq"
@@ -63,6 +64,7 @@  struct goodix_ts_data {
 #define GOODIX_MAX_WIDTH		4096
 #define GOODIX_INT_TRIGGER		1
 #define GOODIX_CONTACT_SIZE		8
+#define GOODIX_MAX_CONTACT_SIZE		9
 #define GOODIX_MAX_CONTACTS		10
 
 #define GOODIX_CONFIG_MAX_LENGTH	240
@@ -145,6 +147,19 @@  static const struct dmi_system_id rotated_screen[] = {
 	{}
 };
 
+static const struct dmi_system_id nine_bytes_report[] = {
+#if defined(CONFIG_DMI) && defined(CONFIG_X86)
+	{
+		.ident = "Lenovo YogaBook",
+		/* YB1-X91L/F and YB1-X90L/F */
+		.matches = {
+			DMI_MATCH(DMI_PRODUCT_NAME, "Lenovo YB1-X9")
+		}
+	},
+#endif
+	{}
+};
+
 /**
  * goodix_i2c_read - read data from a register of the i2c slave device.
  *
@@ -248,7 +263,7 @@  static int goodix_ts_read_input_report(struct goodix_ts_data *ts, u8 *data)
 	max_timeout = jiffies + msecs_to_jiffies(GOODIX_BUFFER_STATUS_TIMEOUT);
 	do {
 		error = goodix_i2c_read(ts->client, GOODIX_READ_COOR_ADDR,
-					data, GOODIX_CONTACT_SIZE + 1);
+					data, ts->contact_size + 1);
 		if (error) {
 			dev_err(&ts->client->dev, "I2C transfer error: %d\n",
 					error);
@@ -261,12 +276,12 @@  static int goodix_ts_read_input_report(struct goodix_ts_data *ts, u8 *data)
 				return -EPROTO;
 
 			if (touch_num > 1) {
-				data += 1 + GOODIX_CONTACT_SIZE;
+				data += 1 + ts->contact_size;
 				error = goodix_i2c_read(ts->client,
 						GOODIX_READ_COOR_ADDR +
-							1 + GOODIX_CONTACT_SIZE,
+							1 + ts->contact_size,
 						data,
-						GOODIX_CONTACT_SIZE *
+						ts->contact_size *
 							(touch_num - 1));
 				if (error)
 					return error;
@@ -285,7 +300,7 @@  static int goodix_ts_read_input_report(struct goodix_ts_data *ts, u8 *data)
 	return 0;
 }
 
-static void goodix_ts_report_touch(struct goodix_ts_data *ts, u8 *coor_data)
+static void goodix_ts_report_touch_8b(struct goodix_ts_data *ts, u8 *coor_data)
 {
 	int id = coor_data[0] & 0x0F;
 	int input_x = get_unaligned_le16(&coor_data[1]);
@@ -300,6 +315,21 @@  static void goodix_ts_report_touch(struct goodix_ts_data *ts, u8 *coor_data)
 	input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, input_w);
 }
 
+static void goodix_ts_report_touch_9b(struct goodix_ts_data *ts, u8 *coor_data)
+{
+	int id = coor_data[1] & 0x0F;
+	int input_x = get_unaligned_le16(&coor_data[3]);
+	int input_y = get_unaligned_le16(&coor_data[5]);
+	int input_w = get_unaligned_le16(&coor_data[7]);
+
+	input_mt_slot(ts->input_dev, id);
+	input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, true);
+	touchscreen_report_pos(ts->input_dev, &ts->prop,
+			       input_x, input_y, true);
+	input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, input_w);
+	input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, input_w);
+}
+
 /**
  * goodix_process_events - Process incoming events
  *
@@ -310,7 +340,7 @@  static void goodix_ts_report_touch(struct goodix_ts_data *ts, u8 *coor_data)
  */
 static void goodix_process_events(struct goodix_ts_data *ts)
 {
-	u8  point_data[1 + GOODIX_CONTACT_SIZE * GOODIX_MAX_CONTACTS];
+	u8  point_data[1 + GOODIX_MAX_CONTACT_SIZE * GOODIX_MAX_CONTACTS];
 	int touch_num;
 	int i;
 
@@ -325,8 +355,12 @@  static void goodix_process_events(struct goodix_ts_data *ts)
 	input_report_key(ts->input_dev, KEY_LEFTMETA, point_data[0] & BIT(4));
 
 	for (i = 0; i < touch_num; i++)
-		goodix_ts_report_touch(ts,
-				&point_data[1 + GOODIX_CONTACT_SIZE * i]);
+		if (ts->contact_size == 9)
+			goodix_ts_report_touch_9b(ts,
+				&point_data[1 + ts->contact_size * i]);
+		else
+			goodix_ts_report_touch_8b(ts,
+				&point_data[1 + ts->contact_size * i]);
 
 	input_mt_sync_frame(ts->input_dev);
 	input_sync(ts->input_dev);
@@ -709,6 +743,13 @@  static int goodix_configure_dev(struct goodix_ts_data *ts)
 			"Applying '180 degrees rotated screen' quirk\n");
 	}
 
+	if (dmi_check_system(nine_bytes_report)) {
+		ts->contact_size = 9;
+
+		dev_dbg(&ts->client->dev,
+			"Non-standard 9-bytes report format quirk\n");
+	}
+
 	error = input_mt_init_slots(ts->input_dev, ts->max_touch_num,
 				    INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED);
 	if (error) {
@@ -781,6 +822,7 @@  static int goodix_ts_probe(struct i2c_client *client,
 	ts->client = client;
 	i2c_set_clientdata(client, ts);
 	init_completion(&ts->firmware_loading_complete);
+	ts->contact_size = GOODIX_CONTACT_SIZE;
 
 	error = goodix_get_gpio_config(ts);
 	if (error)