Skip to contentSkip to conversation

Input: goodix - add axis swapping and axis inversion support

RFC PATCH Superseded Karsten Merker 3 participants 6 messages Oct 18, 2015 – Oct 21, 2015

Subsystems (4)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover Input: goodix - add axis swapping and axis inversion support

Hello,

this is v3 of my "Input: goodix - add axis swapping and axis inversion support" patchset.

The goodix touchscreen driver has gained device-tree support in kernel 4.1, but doesn't currently support the touchscreen-swapped-x-y, touchscreen-inverted-x and touchscreen-inverted-y properties. On systems which combine a portrait-mode display with a landscape-mode touchscreen, such as e.g. the MSI Primo 81 tablet, support for these features is necessary to have the touchscreen and the display use the same coordinate system.

With support for axis inversion, the "rotated_screen" flag in the driver can also be removed, as "rotated_screen" is just a special case of x/y axis inversion.

This patchset sits on top of the "[PATCH v9 0/9] Goodix touchscreen enhancements" series by Irina Tirdea:
https://www.spinics.net/lists/linux-input/msg41501.html

The axis swapping has successfully been tested on an (arm-based) MSI Primo 81 tablet; the x/y inversion resp. the rotated_screen functionality has successfully been tested on a WinBook TW100.

@Bastien: You had acked patch No. 1 in v2 of the patchset. I have
not transferred that ack to v3 of the same patch because I have have introduced some changes into that patch (based on Irina's review comments, cf. the changelog below) after your ack. I would apprechiate very much if you could take a look and tell me whether your ack extends to v3 as well.

Regards,
Karsten

Changelog:

v1: * Initial version (based von v6 of Irina Tirdea's "Goodix
touchscreen enhancements" series).

v2: * Rebase against v8 of Irina Tirdea's "Goodix touchscreen
enhancements" series.
* Fix a typo in the commit message.
* Add an update for the goodix dt bindings documentation (patch No. 3).
* Reviews/Tests:
Patch 1+2: Tested-by: Bastien Nocera <[email protected]>

Patch 2+3: Reviewed-by: Irina Tirdea <[email protected]>

v3: * Rebase against v9 of Irina Tirdea's "Goodix touchscreen
enhancements" series.
* Address the review comments for patch No. 1 by Irina Tirdea
(https://www.spinics.net/lists/linux-input/msg41536.html):
- Move reading the dt properties from goodix_ts_probe to goodix_configure_dev to make them work properly in all configurations (with and without gpio declarations).
- Use the new unified device properties API (device_property_*) instead of the classic DT API (of_property_*). This provides support for ACPI 5.1 DSD properties as well as for device-tree properties.

Karsten Merker (3):
Input: goodix - add axis swapping and axis inversion support
Input: goodix - use "inverted_[xy]" flags instead of "rotated_screen"
Input: goodix - update dt bindings documentation (axis
swapping/inversion)

 .../bindings/input/touchscreen/goodix.txt          |  6 +++++
 drivers/input/touchscreen/goodix.c                 | 31 ++++++++++++++++++----
 2 files changed, 32 insertions(+), 5 deletions(-)
Signature · 1 line
2.1.4
#1 lore raw

RFC PATCH v3 1/3 Input: goodix - add axis swapping and axis inversion support

Implement support for the following device-tree and ACPI 5.1 DSD properties in the goodix touchscreen driver:

- touchscreen-inverted-x: X axis is inverted (boolean)
- touchscreen-inverted-y: Y axis is inverted (boolean)
- touchscreen-swapped-x-y: X and Y axis are swapped (boolean)

These are necessary on tablets which have a display in portrait format while the touchscreen is in landscape format, such as e.g. the MSI Primo 81.

---
 drivers/input/touchscreen/goodix.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
drivers/input/touchscreen/goodix.c +25 -0
index 22bfc4b..b585123 100644
@@ -2,6 +2,7 @@
  *  Driver for Goodix Touchscreens
  *
  *  Copyright (c) 2014 Red Hat Inc.
+ *  Copyright (c) 2015 K. Merker <[email protected]>
  *
  *  This code is based on gt9xx.c authored by [email protected]:
  *
@@ -53,6 +54,9 @@ struct goodix_ts_data {
 	atomic_t open_count;
 	/* Protects power management calls and access to suspended flag */
 	struct mutex mutex;
+	bool swapped_x_y;
+	bool inverted_x;
+	bool inverted_y;
 };
 
 #define GOODIX_GPIO_INT_NAME		"irq"
@@ -271,6 +275,14 @@ static void goodix_ts_report_touch(struct goodix_ts_data *ts, u8 *coor_data)
 		input_y = ts->abs_y_max - input_y;
 	}
 
+	/* Inversions have to happen before axis swapping */
+	if (ts->inverted_x)
+		input_x = ts->abs_x_max - input_x;
+	if (ts->inverted_y)
+		input_y = ts->abs_y_max - input_y;
+	if (ts->swapped_x_y)
+		swap(input_x, input_y);
+
 	input_mt_slot(ts->input_dev, id);
 	input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, true);
 	input_report_abs(ts->input_dev, ABS_MT_POSITION_X, input_x);
@@ -666,6 +678,8 @@ static void goodix_read_config(struct goodix_ts_data *ts)
 			 error);
 		ts->abs_x_max = GOODIX_MAX_WIDTH;
 		ts->abs_y_max = GOODIX_MAX_HEIGHT;
+		if (ts->swapped_x_y)
+			swap(ts->abs_x_max, ts->abs_y_max);
 		ts->int_trigger_type = GOODIX_INT_TRIGGER;
 		ts->max_touch_num = GOODIX_MAX_CONTACTS;
 		return;
@@ -673,6 +687,8 @@ static void goodix_read_config(struct goodix_ts_data *ts)
 
 	ts->abs_x_max = get_unaligned_le16(&config[RESOLUTION_LOC]);
 	ts->abs_y_max = get_unaligned_le16(&config[RESOLUTION_LOC + 2]);
+	if (ts->swapped_x_y)
+		swap(ts->abs_x_max, ts->abs_y_max);
 	ts->int_trigger_type = config[TRIGGER_LOC] & 0x03;
 	ts->max_touch_num = config[MAX_CONTACTS_LOC] & 0x0f;
 	if (!ts->abs_x_max || !ts->abs_y_max || !ts->max_touch_num) {
@@ -680,6 +696,8 @@ static void goodix_read_config(struct goodix_ts_data *ts)
 			"Invalid config, using defaults\n");
 		ts->abs_x_max = GOODIX_MAX_WIDTH;
 		ts->abs_y_max = GOODIX_MAX_HEIGHT;
+		if (ts->swapped_x_y)
+			swap(ts->abs_x_max, ts->abs_y_max);
 		ts->max_touch_num = GOODIX_MAX_CONTACTS;
 	}
 
@@ -805,6 +823,13 @@ static int goodix_configure_dev(struct goodix_ts_data *ts)
 {
 	int error;
 
+	ts->swapped_x_y = device_property_read_bool(&ts->client->dev,
+						    "touchscreen-swapped-x-y");
+	ts->inverted_x = device_property_read_bool(&ts->client->dev,
+						   "touchscreen-inverted-x");
+	ts->inverted_y = device_property_read_bool(&ts->client->dev,
+						   "touchscreen-inverted-y");
+
 	goodix_read_config(ts);
 
 	error = goodix_request_input_dev(ts);
Signature · 1 line
2.1.4
Tested-by on v3 1/3
#2 lore raw
Quoted 16 lines

-----Original Message-----
From: Karsten Merker [mailto:[email protected]]
Sent: 18 October, 2015 18:53
To: Bastien Nocera; Dmitry Torokhov; Tirdea, Irina; Aleksei Mamlin; [email protected]; Ian Campbell
Cc: [email protected]; [email protected]; Chen-Yu Tsai; Karsten Merker
Subject: [PATCH RFC V3 1/3] Input: goodix - add axis swapping and axis inversion support

Implement support for the following device-tree and ACPI 5.1 DSD properties in the goodix touchscreen driver:

- touchscreen-inverted-x: X axis is inverted (boolean)
- touchscreen-inverted-y: Y axis is inverted (boolean)
- touchscreen-swapped-x-y: X and Y axis are swapped (boolean)

Quoted 7 lines

These are necessary on tablets which have a display in portrait format while the touchscreen is in landscape format, such as e.g. the MSI Primo 81.

---

Looks good to me, thanks for making the changes.
Tested this with ACPI _DSD properties.

Quoted 83 lines
 drivers/input/touchscreen/goodix.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
drivers/input/touchscreen/goodix.c +25 -1
index 22bfc4b..b585123 100644
@@ -2,6 +2,7 @@
  *  Driver for Goodix Touchscreens
  *
  *  Copyright (c) 2014 Red Hat Inc.
+ *  Copyright (c) 2015 K. Merker <[email protected]>
  *
  *  This code is based on gt9xx.c authored by [email protected]:
  *
@@ -53,6 +54,9 @@ struct goodix_ts_data {
 	atomic_t open_count;
 	/* Protects power management calls and access to suspended flag */
 	struct mutex mutex;
+	bool swapped_x_y;
+	bool inverted_x;
+	bool inverted_y;
 };
 
 #define GOODIX_GPIO_INT_NAME		"irq"
@@ -271,6 +275,14 @@ static void goodix_ts_report_touch(struct goodix_ts_data *ts, u8 *coor_data)
 		input_y = ts->abs_y_max - input_y;
 	}
 
+	/* Inversions have to happen before axis swapping */
+	if (ts->inverted_x)
+		input_x = ts->abs_x_max - input_x;
+	if (ts->inverted_y)
+		input_y = ts->abs_y_max - input_y;
+	if (ts->swapped_x_y)
+		swap(input_x, input_y);
+
 	input_mt_slot(ts->input_dev, id);
 	input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, true);
 	input_report_abs(ts->input_dev, ABS_MT_POSITION_X, input_x);
@@ -666,6 +678,8 @@ static void goodix_read_config(struct goodix_ts_data *ts)
 			 error);
 		ts->abs_x_max = GOODIX_MAX_WIDTH;
 		ts->abs_y_max = GOODIX_MAX_HEIGHT;
+		if (ts->swapped_x_y)
+			swap(ts->abs_x_max, ts->abs_y_max);
 		ts->int_trigger_type = GOODIX_INT_TRIGGER;
 		ts->max_touch_num = GOODIX_MAX_CONTACTS;
 		return;
@@ -673,6 +687,8 @@ static void goodix_read_config(struct goodix_ts_data *ts)
 
 	ts->abs_x_max = get_unaligned_le16(&config[RESOLUTION_LOC]);
 	ts->abs_y_max = get_unaligned_le16(&config[RESOLUTION_LOC + 2]);
+	if (ts->swapped_x_y)
+		swap(ts->abs_x_max, ts->abs_y_max);
 	ts->int_trigger_type = config[TRIGGER_LOC] & 0x03;
 	ts->max_touch_num = config[MAX_CONTACTS_LOC] & 0x0f;
 	if (!ts->abs_x_max || !ts->abs_y_max || !ts->max_touch_num) {
@@ -680,6 +696,8 @@ static void goodix_read_config(struct goodix_ts_data *ts)
 			"Invalid config, using defaults\n");
 		ts->abs_x_max = GOODIX_MAX_WIDTH;
 		ts->abs_y_max = GOODIX_MAX_HEIGHT;
+		if (ts->swapped_x_y)
+			swap(ts->abs_x_max, ts->abs_y_max);
 		ts->max_touch_num = GOODIX_MAX_CONTACTS;
 	}
 
@@ -805,6 +823,13 @@ static int goodix_configure_dev(struct goodix_ts_data *ts)
 {
 	int error;
 
+	ts->swapped_x_y = device_property_read_bool(&ts->client->dev,
+						    "touchscreen-swapped-x-y");
+	ts->inverted_x = device_property_read_bool(&ts->client->dev,
+						   "touchscreen-inverted-x");
+	ts->inverted_y = device_property_read_bool(&ts->client->dev,
+						   "touchscreen-inverted-y");
+
 	goodix_read_config(ts);
 
 	error = goodix_request_input_dev(ts);
--

2.1.4

#3 lore raw

RFC PATCH v3 2/3 Input: goodix - use "inverted_[xy]" flags instead of "rotated_screen"

In reply to Karsten Merker

The goodix touchscreen driver uses a "rotated_screen" flag for systems on which the touchscreen is mounted rotated by 180 degrees with respect to the display. With the addition of support for the dt properties "touchscreen-inverted-x" and "touchscreen-inverted-y", a separate "rotated_screen" flag is not necessary anymore. This patch replaces it by setting the inverted_x and inverted_y flags instead.

---
 drivers/input/touchscreen/goodix.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/input/touchscreen/goodix.c +4 -8
index b585123..22eff28 100644
@@ -40,7 +40,6 @@ struct goodix_ts_data {
 	int abs_y_max;
 	unsigned int max_touch_num;
 	unsigned int int_trigger_type;
-	bool rotated_screen;
 	int cfg_len;
 	struct gpio_desc *gpiod_int;
 	struct gpio_desc *gpiod_rst;
@@ -270,11 +269,6 @@ static void goodix_ts_report_touch(struct goodix_ts_data *ts, u8 *coor_data)
 	int input_y = get_unaligned_le16(&coor_data[3]);
 	int input_w = get_unaligned_le16(&coor_data[5]);
 
-	if (ts->rotated_screen) {
-		input_x = ts->abs_x_max - input_x;
-		input_y = ts->abs_y_max - input_y;
-	}
-
 	/* Inversions have to happen before axis swapping */
 	if (ts->inverted_x)
 		input_x = ts->abs_x_max - input_x;
@@ -701,10 +695,12 @@ static void goodix_read_config(struct goodix_ts_data *ts)
 		ts->max_touch_num = GOODIX_MAX_CONTACTS;
 	}
 
-	ts->rotated_screen = dmi_check_system(rotated_screen);
-	if (ts->rotated_screen)
+	if (dmi_check_system(rotated_screen)) {
+		ts->inverted_x = true;
+		ts->inverted_y = true;
 		dev_dbg(&ts->client->dev,
 			 "Applying '180 degrees rotated screen' quirk\n");
+	}
 }
 
 /**
Signature · 6 lines
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#4 lore raw

RFC PATCH v3 3/3 Input: goodix - update dt bindings documentation (axis swapping/inversion)

In reply to Karsten Merker

The goodix touchscreen driver has gained support for the optional touchscreen-inverted-x, touchscreen-inverted-y and touchscreen-swapped-x-y properties as described in Documentation/devicetree/bindings/input/touchscreen/touchscreen.txt.

Document these properties in the goodix bindings description.

---
 Documentation/devicetree/bindings/input/touchscreen/goodix.txt | 6 ++++++
 1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/input/touchscreen/goodix.txt +6 -0
index 4db3393..4ecd0e1 100644
@@ -14,6 +14,7 @@ Required properties:
  - interrupts		: Interrupt to which the chip is connected
  - irq-gpio		: GPIO pin used for IRQ
  - reset-gpio		: GPIO pin used for reset
+
 Optional properties:
 
  - esd-recovery-timeout-ms : ESD poll time (in milli seconds) for the driver to
@@ -21,6 +22,11 @@ Optional properties:
                             device. ESD is disabled if this property is not set
                             or is set to 0.
 
+ - touchscreen-inverted-x  : X axis is inverted (boolean)
+ - touchscreen-inverted-y  : Y axis is inverted (boolean)
+ - touchscreen-swapped-x-y : X and Y axis are swapped (boolean)
+                             (swapping is done after inverting the axis)
+
 Example:
 
 	i2c@00000000 {
Signature · 6 lines
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Tested-by on the v3 series
#5 lore raw
In reply to Karsten Merker
Quoted 70 lines · On Sun, 18 Oct 2015 17:52:56 +0200 Karsten Merker <[email protected]> wrote:

Hello,

this is v3 of my "Input: goodix - add axis swapping and axis inversion support" patchset.

The goodix touchscreen driver has gained device-tree support in kernel 4.1, but doesn't currently support the touchscreen-swapped-x-y, touchscreen-inverted-x and touchscreen-inverted-y properties. On systems which combine a portrait-mode display with a landscape-mode touchscreen, such as e.g. the MSI Primo 81 tablet, support for these features is necessary to have the touchscreen and the display use the same coordinate system.

With support for axis inversion, the "rotated_screen" flag in the driver can also be removed, as "rotated_screen" is just a special case of x/y axis inversion.

This patchset sits on top of the "[PATCH v9 0/9] Goodix touchscreen enhancements" series by Irina Tirdea:
https://www.spinics.net/lists/linux-input/msg41501.html

The axis swapping has successfully been tested on an (arm-based) MSI Primo 81 tablet; the x/y inversion resp. the rotated_screen functionality has successfully been tested on a WinBook TW100.

@Bastien: You had acked patch No. 1 in v2 of the patchset. I have
not transferred that ack to v3 of the same patch because I have have introduced some changes into that patch (based on Irina's review comments, cf. the changelog below) after your ack. I would apprechiate very much if you could take a look and tell me whether your ack extends to v3 as well.

Regards,
Karsten

Changelog:

v1: * Initial version (based von v6 of Irina Tirdea's "Goodix
touchscreen enhancements" series).

v2: * Rebase against v8 of Irina Tirdea's "Goodix touchscreen
enhancements" series.
* Fix a typo in the commit message.
* Add an update for the goodix dt bindings documentation (patch No. 3).
* Reviews/Tests:
Patch 1+2: Tested-by: Bastien Nocera <[email protected]>

Patch 2+3: Reviewed-by: Irina Tirdea <[email protected]>

v3: * Rebase against v9 of Irina Tirdea's "Goodix touchscreen
enhancements" series.
* Address the review comments for patch No. 1 by Irina Tirdea
(https://www.spinics.net/lists/linux-input/msg41536.html):
- Move reading the dt properties from goodix_ts_probe to goodix_configure_dev to make them work properly in all configurations (with and without gpio declarations).
- Use the new unified device properties API (device_property_*) instead of the classic DT API (of_property_*). This provides support for ACPI 5.1 DSD properties as well as for device-tree properties.

Karsten Merker (3):
Input: goodix - add axis swapping and axis inversion support
Input: goodix - use "inverted_[xy]" flags instead of "rotated_screen"
Input: goodix - update dt bindings documentation (axis
swapping/inversion)

Quoted 6 lines
 .../bindings/input/touchscreen/goodix.txt          |  6 +++++
 drivers/input/touchscreen/goodix.c                 | 31 ++++++++++++++++++----
 2 files changed, 32 insertions(+), 5 deletions(-)
Signature · 1 line
2.1.4

Tested on Wexler TAB7200 with device-tree properties.

Signature · 2 lines
Thanks and regards,
Aleksei Mamlin