Skip to contentSkip to conversation

gpio: acpi: add quirk to override GpioInt polarity

PATCH Superseded Peter Cai 4 participants 11 messages Aug 31, 2019 – Mar 2, 2020

Subsystems (5)
ACPI HID GPIO Input drivers +1 more subsystems
lore
Share & tools
lore

Peter Cai

author
#0 lore raw

PATCH v2 1/2 gpio: acpi: add quirk to override GpioInt polarity

On GPD P2 Max, the firmware could not reset the touch panel correctly. The kernel needs to take on the job instead, but the GpioInt definition in DSDT specifies ActiveHigh while the GPIO pin should actually be ActiveLow.

We need to override the polarity defined by DSDT. The GPIO driver already allows defining polarity in acpi_gpio_params, but the option is not applied to GpioInt.

This patch adds a new quirk that enables the polarity specified in acpi_gpio_params to also be applied to GpioInt.

---

v2: rebased to gpio/for-next, moved quirk out of the gpioint conditional.

---
 drivers/gpio/gpiolib-acpi.c   | 9 +++++++++
 include/linux/gpio/consumer.h | 6 ++++++
 2 files changed, 15 insertions(+)
drivers/gpio/gpiolib-acpi.c +9 -0
index fdee8afa5339..ab16ea61a8fa 100644
@@ -603,6 +603,15 @@ static int acpi_populate_gpio_lookup(struct acpi_resource *ares, void *data)
 			lookup->info.flags = acpi_gpio_to_gpiod_flags(agpio);
 			lookup->info.polarity = lookup->active_low;
 		}
+
+		/*
+		 * Override the polarity specified by GpioInt if
+		 * ACPI_GPIO_QUIRK_OVERRIDE_POLARITY is set.
+		 */
+		if (lookup->info.quirks & ACPI_GPIO_QUIRK_OVERRIDE_POLARITY) {
+			dev_warn(&lookup->info.adev->dev, FW_BUG "Incorrect polarity specified by GpioInt, overriding.\n");
+			lookup->info.polarity = lookup->active_low;
+		}
 	}
 
 	return 1;
include/linux/gpio/consumer.h +6 -0
index b70af921c614..7e9f24ebb085 100644
@@ -622,6 +622,12 @@ struct acpi_gpio_mapping {
  * get GpioIo type explicitly, this quirk may be used.
  */
 #define ACPI_GPIO_QUIRK_ONLY_GPIOIO		BIT(1)
+/*
+ * Use the GPIO polarity (ActiveHigh / ActiveLow) from acpi_gpio_params
+ * for GpioInt as well. The default behavior is to use the one specified
+ * by GpioInt, which can be incorrect on some devices.
+ */
+#define ACPI_GPIO_QUIRK_OVERRIDE_POLARITY	BIT(2)
 
 	unsigned int quirks;
 };
Signature · 1 line
2.23.0
author
#1 lore raw

PATCH v2 2/2 touchscreen: goodix: define GPIO mapping for GPD P2 Max

The firmware of GPD P2 Max could not handle panel resets although code is present in DSDT. The kernel needs to take on this job instead, but the DSDT does not provide _DSD, rendering kernel helpless when trying to find the respective GPIO pins.

Fortunately, this time GPD has proper DMI vendor / product strings that we could match against. We simply apply an acpi_gpio_mapping table when GPD P2 Max is matched.

Additionally, the DSDT definition of the irq pin specifies a wrong polarity. The new quirk introduced in the previous patch (ACPI_GPIO_QUIRK_OVERRIDE_POLARITY) is applied to correct this.

---

v2: removed '#ifdef CONFIG_ACPI' as per suggestion. The #ifdef guards for CONFIG_DMI is kept for consistency with the other dmi_system_id definition in the same file.

---
 drivers/input/touchscreen/goodix.c | 31 ++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
drivers/input/touchscreen/goodix.c +31 -0
index 5178ea8b5f30..df476f7dcd95 100644
@@ -144,6 +144,31 @@ static const struct dmi_system_id rotated_screen[] = {
 	{}
 };
 
+static const struct acpi_gpio_params irq_gpios_default = { 0, 0, false };
+static const struct acpi_gpio_params reset_gpios_default = { 1, 0, false };
+static const struct acpi_gpio_mapping gpio_mapping_force_irq_active_high[] = {
+	{ "irq-gpios", &irq_gpios_default, 1, ACPI_GPIO_QUIRK_OVERRIDE_POLARITY },
+	{ "reset-gpios", &reset_gpios_default, 1 },
+	{}
+};
+
+/*
+ * Devices that need acpi_gpio_mapping to function correctly
+ */
+static const struct dmi_system_id need_gpio_mapping[] = {
+#if defined(CONFIG_DMI) && defined(CONFIG_X86)
+	{
+		.ident = "GPD P2 Max",
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR, "GPD"),
+			DMI_MATCH(DMI_PRODUCT_NAME, "P2 MAX")
+		},
+		.driver_data = &gpio_mapping_force_irq_active_high
+	},
+#endif
+	{}
+};
+
 /**
  * goodix_i2c_read - read data from a register of the i2c slave device.
  *
@@ -795,6 +820,12 @@ static int goodix_ts_probe(struct i2c_client *client,
 {
 	struct goodix_ts_data *ts;
 	int error;
+	struct dmi_system_id *dmi_match;
+
+	dmi_match = dmi_first_match(need_gpio_mapping);
+	if (dmi_match)
+		devm_acpi_dev_add_driver_gpios(&client->dev,
+					       dmi_match->driver_data);
 
 	dev_dbg(&client->dev, "I2C Address: 0x%02x\n", client->addr);
 
Signature · 1 line
2.23.0
Reviewed-by on v2 2/2
#2 lore raw

Re: [PATCH v2 2/2] touchscreen: goodix: define GPIO mapping for GPD P2 Max

Quoted 5 lines · Peter Cai

The firmware of GPD P2 Max could not handle panel resets although code is present in DSDT. The kernel needs to take on this job instead, but the DSDT does not provide _DSD, rendering kernel helpless when trying to find the respective GPIO pins.

Quoted 7 lines

Fortunately, this time GPD has proper DMI vendor / product strings that we could match against. We simply apply an acpi_gpio_mapping table when GPD P2 Max is matched.

Additionally, the DSDT definition of the irq pin specifies a wrong polarity. The new quirk introduced in the previous patch (ACPI_GPIO_QUIRK_OVERRIDE_POLARITY) is applied to correct this.

FWIW,

though one comment below.

Quoted 48 lines

---

v2: removed '#ifdef CONFIG_ACPI' as per suggestion. The #ifdef guards for CONFIG_DMI is kept for consistency with the other dmi_system_id definition in the same file.

---
 drivers/input/touchscreen/goodix.c | 31 ++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
drivers/input/touchscreen/goodix.c +25 -0
index 5178ea8b5f30..df476f7dcd95 100644
@@ -144,6 +144,31 @@ static const struct dmi_system_id rotated_screen[] = {
 	{}
 };
 
+static const struct acpi_gpio_params irq_gpios_default = { 0, 0, false };
+static const struct acpi_gpio_params reset_gpios_default = { 1, 0, false };
+static const struct acpi_gpio_mapping gpio_mapping_force_irq_active_high[] = {
+	{ "irq-gpios", &irq_gpios_default, 1, ACPI_GPIO_QUIRK_OVERRIDE_POLARITY },
+	{ "reset-gpios", &reset_gpios_default, 1 },
+	{}
+};
+
+/*
+ * Devices that need acpi_gpio_mapping to function correctly
+ */
+static const struct dmi_system_id need_gpio_mapping[] = {
+#if defined(CONFIG_DMI) && defined(CONFIG_X86)
+	{
+		.ident = "GPD P2 Max",
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR, "GPD"),
+			DMI_MATCH(DMI_PRODUCT_NAME, "P2 MAX")
+		},
+		.driver_data = &gpio_mapping_force_irq_active_high
+	},
+#endif
+	{}
+};
+
 /**
  * goodix_i2c_read - read data from a register of the i2c slave device.
  *

drivers/input/touchscreen/goodix.c static int goodix_ts_probe(struct i2c_client *client, · line 824

Quoted 5 lines
drivers/input/touchscreen/goodix.c +1 -0
@@ -795,6 +820,12 @@ static int goodix_ts_probe(struct i2c_client *client,
 {
 	struct goodix_ts_data *ts;
 	int error;
 
+	struct dmi_system_id *dmi_match;

I guess it should be const as kbuild bot complained on v1.

And perhaps you want to keep reverse xmas tree order in definition block:

	const struct dmi_system_id *dmi_match;
	struct goodix_ts_data *ts;
	int error;
Quoted 11 lines
drivers/input/touchscreen/goodix.c +5 -0
+
+	dmi_match = dmi_first_match(need_gpio_mapping);
+	if (dmi_match)
+		devm_acpi_dev_add_driver_gpios(&client->dev,
+					       dmi_match->driver_data);
 
 	dev_dbg(&client->dev, "I2C Address: 0x%02x\n", client->addr);
Signature · 2 lines
-- 
2.23.0
Signature · 2 lines
With Best Regards,
Andy Shevchenko
Acked-by on v2 1/2
#3 lore raw
In reply to Peter Cai
Quoted 11 lines · Peter Cai

On GPD P2 Max, the firmware could not reset the touch panel correctly. The kernel needs to take on the job instead, but the GpioInt definition in DSDT specifies ActiveHigh while the GPIO pin should actually be ActiveLow.

We need to override the polarity defined by DSDT. The GPIO driver already allows defining polarity in acpi_gpio_params, but the option is not applied to GpioInt.

This patch adds a new quirk that enables the polarity specified in acpi_gpio_params to also be applied to GpioInt.

Thank you for an update!

on the condition that Dmitry and other input / Goodix developers are okay with the approach in general.

Quoted 51 lines

---

v2: rebased to gpio/for-next, moved quirk out of the gpioint conditional.

---
 drivers/gpio/gpiolib-acpi.c   | 9 +++++++++
 include/linux/gpio/consumer.h | 6 ++++++
 2 files changed, 15 insertions(+)
drivers/gpio/gpiolib-acpi.c +9 -0
index fdee8afa5339..ab16ea61a8fa 100644
@@ -603,6 +603,15 @@ static int acpi_populate_gpio_lookup(struct acpi_resource *ares, void *data)
 			lookup->info.flags = acpi_gpio_to_gpiod_flags(agpio);
 			lookup->info.polarity = lookup->active_low;
 		}
+
+		/*
+		 * Override the polarity specified by GpioInt if
+		 * ACPI_GPIO_QUIRK_OVERRIDE_POLARITY is set.
+		 */
+		if (lookup->info.quirks & ACPI_GPIO_QUIRK_OVERRIDE_POLARITY) {
+			dev_warn(&lookup->info.adev->dev, FW_BUG "Incorrect polarity specified by GpioInt, overriding.\n");
+			lookup->info.polarity = lookup->active_low;
+		}
 	}
 
 	return 1;
include/linux/gpio/consumer.h +6 -0
index b70af921c614..7e9f24ebb085 100644
@@ -622,6 +622,12 @@ struct acpi_gpio_mapping {
  * get GpioIo type explicitly, this quirk may be used.
  */
 #define ACPI_GPIO_QUIRK_ONLY_GPIOIO		BIT(1)
+/*
+ * Use the GPIO polarity (ActiveHigh / ActiveLow) from acpi_gpio_params
+ * for GpioInt as well. The default behavior is to use the one specified
+ * by GpioInt, which can be incorrect on some devices.
+ */
+#define ACPI_GPIO_QUIRK_OVERRIDE_POLARITY	BIT(2)
 
 	unsigned int quirks;
 };
Signature · 1 line
2.23.0
Signature · 2 lines
With Best Regards,
Andy Shevchenko
Acked-by
#4 lore raw
Quoted 13 lines · Andy Shevchenko
Quoted 11 lines · Peter Cai

On GPD P2 Max, the firmware could not reset the touch panel correctly. The kernel needs to take on the job instead, but the GpioInt definition in DSDT specifies ActiveHigh while the GPIO pin should actually be ActiveLow.

We need to override the polarity defined by DSDT. The GPIO driver already allows defining polarity in acpi_gpio_params, but the option is not applied to GpioInt.

This patch adds a new quirk that enables the polarity specified in acpi_gpio_params to also be applied to GpioInt.

Quoted 6 lines

Thank you for an update!

on the condition that Dmitry and other input / Goodix developers are okay with the approach in general.

In case Dmitry needs to merge this.

Or should I simply merge this patch to the GPIO tree?

Yours,
Linus Walleij

#5 lore raw
Quoted 19 lines · Linus Walleij
Quoted 17 lines · Andy Shevchenko
Quoted 11 lines · Peter Cai

On GPD P2 Max, the firmware could not reset the touch panel correctly. The kernel needs to take on the job instead, but the GpioInt definition in DSDT specifies ActiveHigh while the GPIO pin should actually be ActiveLow.

We need to override the polarity defined by DSDT. The GPIO driver already allows defining polarity in acpi_gpio_params, but the option is not applied to GpioInt.

This patch adds a new quirk that enables the polarity specified in acpi_gpio_params to also be applied to GpioInt.

Thank you for an update!

Quoted 7 lines
Quoted 2 lines

on the condition that Dmitry and other input / Goodix developers are okay with the approach in general.

In case Dmitry needs to merge this.

Or should I simply merge this patch to the GPIO tree?

For my opinion Input subsystem should decide how to proceed with this.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#6 lore raw

PATCH v3 1/2 gpio: acpi: add quirk to override GpioInt polarity

In reply to Peter Cai

On GPD P2 Max, the firmware could not reset the touch panel correctly. The kernel needs to take on the job instead, but the GpioInt definition in DSDT specifies ActiveHigh while the GPIO pin should actually be ActiveLow.

We need to override the polarity defined by DSDT. The GPIO driver already allows defining polarity in acpi_gpio_params, but the option is not applied to GpioInt.

This patch adds a new quirk that enables the polarity specified in acpi_gpio_params to also be applied to GpioInt.

---

v2: rebased to gpio/for-next, moved quirk out of the gpioint conditional.

v3: no change, series update.

---
 drivers/gpio/gpiolib-acpi.c   | 9 +++++++++
 include/linux/gpio/consumer.h | 6 ++++++
 2 files changed, 15 insertions(+)
drivers/gpio/gpiolib-acpi.c +9 -0
index fdee8afa5339..ab16ea61a8fa 100644
@@ -603,6 +603,15 @@ static int acpi_populate_gpio_lookup(struct acpi_resource *ares, void *data)
 			lookup->info.flags = acpi_gpio_to_gpiod_flags(agpio);
 			lookup->info.polarity = lookup->active_low;
 		}
+
+		/*
+		 * Override the polarity specified by GpioInt if
+		 * ACPI_GPIO_QUIRK_OVERRIDE_POLARITY is set.
+		 */
+		if (lookup->info.quirks & ACPI_GPIO_QUIRK_OVERRIDE_POLARITY) {
+			dev_warn(&lookup->info.adev->dev, FW_BUG "Incorrect polarity specified by GpioInt, overriding.\n");
+			lookup->info.polarity = lookup->active_low;
+		}
 	}
 
 	return 1;
include/linux/gpio/consumer.h +6 -0
index b70af921c614..7e9f24ebb085 100644
@@ -622,6 +622,12 @@ struct acpi_gpio_mapping {
  * get GpioIo type explicitly, this quirk may be used.
  */
 #define ACPI_GPIO_QUIRK_ONLY_GPIOIO		BIT(1)
+/*
+ * Use the GPIO polarity (ActiveHigh / ActiveLow) from acpi_gpio_params
+ * for GpioInt as well. The default behavior is to use the one specified
+ * by GpioInt, which can be incorrect on some devices.
+ */
+#define ACPI_GPIO_QUIRK_OVERRIDE_POLARITY	BIT(2)
 
 	unsigned int quirks;
 };
Signature · 1 line
2.23.0
author
#7 lore raw

PATCH v3 2/2 touchscreen: goodix: define GPIO mapping for GPD P2 Max

The firmware of GPD P2 Max could not handle panel resets although code is present in DSDT. The kernel needs to take on this job instead, but the DSDT does not provide _DSD, rendering kernel helpless when trying to find the respective GPIO pins.

Fortunately, this time GPD has proper DMI vendor / product strings that we could match against. We simply apply an acpi_gpio_mapping table when GPD P2 Max is matched.

Additionally, the DSDT definition of the irq pin specifies a wrong polarity. The new quirk introduced in the previous patch (ACPI_GPIO_QUIRK_OVERRIDE_POLARITY) is applied to correct this.

---

v2: removed '#ifdef CONFIG_ACPI' as per suggestion. The #ifdef guards for CONFIG_DMI is kept for consistency with the other dmi_system_id definition in the same file.

v3: minor style adjustments. Added 'const' to dmi_match and moved it in reverse xmas tree order as per suggestion.

---
 drivers/input/touchscreen/goodix.c | 31 ++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
drivers/input/touchscreen/goodix.c +31 -0
index 5178ea8b5f30..49ce478c1134 100644
@@ -144,6 +144,31 @@ static const struct dmi_system_id rotated_screen[] = {
 	{}
 };
 
+static const struct acpi_gpio_params irq_gpios_default = { 0, 0, false };
+static const struct acpi_gpio_params reset_gpios_default = { 1, 0, false };
+static const struct acpi_gpio_mapping gpio_mapping_force_irq_active_high[] = {
+	{ "irq-gpios", &irq_gpios_default, 1, ACPI_GPIO_QUIRK_OVERRIDE_POLARITY },
+	{ "reset-gpios", &reset_gpios_default, 1 },
+	{}
+};
+
+/*
+ * Devices that need acpi_gpio_mapping to function correctly
+ */
+static const struct dmi_system_id need_gpio_mapping[] = {
+#if defined(CONFIG_DMI) && defined(CONFIG_X86)
+	{
+		.ident = "GPD P2 Max",
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR, "GPD"),
+			DMI_MATCH(DMI_PRODUCT_NAME, "P2 MAX")
+		},
+		.driver_data = &gpio_mapping_force_irq_active_high
+	},
+#endif
+	{}
+};
+
 /**
  * goodix_i2c_read - read data from a register of the i2c slave device.
  *
@@ -793,9 +818,15 @@ static void goodix_disable_regulators(void *arg)
 static int goodix_ts_probe(struct i2c_client *client,
 			   const struct i2c_device_id *id)
 {
+	const struct dmi_system_id *dmi_match;
 	struct goodix_ts_data *ts;
 	int error;
 
+	dmi_match = dmi_first_match(need_gpio_mapping);
+	if (dmi_match)
+		devm_acpi_dev_add_driver_gpios(&client->dev,
+					       dmi_match->driver_data);
+
 	dev_dbg(&client->dev, "I2C Address: 0x%02x\n", client->addr);
 
 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
Signature · 1 line
2.23.0
#8 lore raw

Re: [PATCH v3 2/2] touchscreen: goodix: define GPIO mapping for GPD P2 Max

Quoted 13 lines · Peter Cai

The firmware of GPD P2 Max could not handle panel resets although code
is present in DSDT. The kernel needs to take on this job instead, but the DSDT does not provide _DSD, rendering kernel helpless when trying to
find the respective GPIO pins.

Fortunately, this time GPD has proper DMI vendor / product strings that
we could match against. We simply apply an acpi_gpio_mapping table when
GPD P2 Max is matched.

Quoted 3 lines

Additionally, the DSDT definition of the irq pin specifies a wrong polarity. The new quirk introduced in the previous patch (ACPI_GPIO_QUIRK_OVERRIDE_POLARITY) is applied to correct this.

Hans has posted a patchset which reworks GPIO access for ACPI devices.

Could you please check whether you could rebase your patch on top of that?

I also think the comment in "Input: goodix - Add support for getting IRQ + reset GPIOs on Cherry Trail devices" might also be of use:

+ case irq_pin_access_acpi_gpio:
+ /*
+ * The IRQ pin triggers on a falling edge, so its gets
marked
+ * as active-low, use output_raw to avoid the value
inversion.
+ */

Cheers

author
#9 lore raw

Re: [PATCH v3 2/2] touchscreen: goodix: define GPIO mapping for GPD P2 Max

Quoted 35 lines · Bastien Nocera
Quoted 13 lines · Peter Cai

The firmware of GPD P2 Max could not handle panel resets although code
is present in DSDT. The kernel needs to take on this job instead, but the DSDT does not provide _DSD, rendering kernel helpless when trying to
find the respective GPIO pins.

Fortunately, this time GPD has proper DMI vendor / product strings that
we could match against. We simply apply an acpi_gpio_mapping table when
GPD P2 Max is matched.

Quoted 3 lines

Additionally, the DSDT definition of the irq pin specifies a wrong polarity. The new quirk introduced in the previous patch (ACPI_GPIO_QUIRK_OVERRIDE_POLARITY) is applied to correct this.

Hans has posted a patchset which reworks GPIO access for ACPI devices.

Could you please check whether you could rebase your patch on top of that?

I also think the comment in "Input: goodix - Add support for getting IRQ + reset GPIOs on Cherry Trail devices" might also be of use:

(quoted diff) +3 -0
+       case irq_pin_access_acpi_gpio:
+               /*
+                * The IRQ pin triggers on a falling edge, so its gets

marked
+ * as active-low, use output_raw to avoid the value
inversion.
+ */

Quoted 2 lines

Cheers

Sorry I forgot to notify you earlier, but it turned out that the manufacturer of the device has already applied a fix in their ACPI table after this patch was submitted and discussed. This patch is no longer needed.

#10 lore raw

Re: [PATCH v3 2/2] touchscreen: goodix: define GPIO mapping for GPD P2 Max

Quoted 1 line · Peter Cai

<snip>

Quoted 4 lines

Sorry I forgot to notify you earlier, but it turned out that the manufacturer of the device has already applied a fix in their ACPI table after this patch was submitted and discussed. This patch is no longer needed.

That's nice when it happens, thanks for letting me know nonetheless :)

Cheers