linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpiolib: acpi: support override broken GPIO number in ACPI table
@ 2021-02-26  3:39 Shawn Guo
  2021-02-26  9:12 ` Andy Shevchenko
  2021-03-03  9:47 ` Andy Shevchenko
  0 siblings, 2 replies; 33+ messages in thread
From: Shawn Guo @ 2021-02-26  3:39 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Mika Westerberg, Andy Shevchenko, Bartosz Golaszewski,
	Bjorn Andersson, linux-gpio, linux-acpi, linux-arm-msm,
	Shawn Guo

Running kernel with ACPI on Lenovo Flex 5G laptop, touchpad is just
not working.  That's because the GpioInt number of TSC2 node in ACPI
table is simply wrong, and the number even exceeds the maximum GPIO
lines.  As the touchpad works fine with Windows on the same machine,
presumably this is something Windows-ism.  Although it's obviously
a specification violation, believe of that Microsoft will fix this in
the near future is not really realistic.

It adds the support of overriding broken GPIO number in ACPI table
on particular machines, which are matched using DMI info.  Such
mechanism for fixing up broken firmware and ACPI table is not uncommon
in kernel.  And hopefully it can be useful for other machines that get
broken GPIO number coded in ACPI table.

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
---
 drivers/gpio/gpiolib-acpi.c | 63 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 62 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
index e37a57d0a2f0..30a5c5a954fa 100644
--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -93,6 +93,63 @@ static DEFINE_MUTEX(acpi_gpio_deferred_req_irqs_lock);
 static LIST_HEAD(acpi_gpio_deferred_req_irqs_list);
 static bool acpi_gpio_deferred_req_irqs_done;
 
+struct acpi_gpio_pin_fixup {
+	int pin_broken;
+	int pin_correct;
+};
+
+struct acpi_gpio_pin_override {
+	const struct acpi_gpio_pin_fixup *fixups;
+	int num;
+};
+
+static const struct acpi_gpio_pin_fixup lenovo_flex_5g_fixups[] = {
+	{
+		/* GpioInt of Touchpad (TSC2) */
+		.pin_broken = 0x0280,
+		.pin_correct = 0x0018,
+	},
+};
+
+static const struct acpi_gpio_pin_override lenovo_flex_5g_override = {
+	.fixups = lenovo_flex_5g_fixups,
+	.num = ARRAY_SIZE(lenovo_flex_5g_fixups),
+};
+
+static const struct dmi_system_id acpi_gpio_pin_override_table[] = {
+	{
+		.ident = "Lenovo Flex 5G",
+		.matches = {
+			DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"),
+			DMI_EXACT_MATCH(DMI_PRODUCT_FAMILY, "Flex 5G 14Q8CX05"),
+		},
+		.driver_data = (void *)&lenovo_flex_5g_override,
+	},
+	{ } /* terminator */
+};
+
+static int acpi_gpio_pin_override(int pin)
+{
+	const struct acpi_gpio_pin_override *override;
+	const struct acpi_gpio_pin_fixup *fixup;
+	const struct dmi_system_id *system_id;
+	int i;
+
+	system_id = dmi_first_match(acpi_gpio_pin_override_table);
+	if (!system_id)
+		return pin;
+
+	override = system_id->driver_data;
+
+	for (i = 0; i < override->num; i++) {
+		fixup = &override->fixups[i];
+		if (pin == fixup->pin_broken)
+			return fixup->pin_correct;
+	}
+
+	return pin;
+}
+
 static int acpi_gpiochip_find(struct gpio_chip *gc, void *data)
 {
 	if (!gc->parent)
@@ -125,7 +182,11 @@ static struct gpio_desc *acpi_get_gpiod(char *path, int pin)
 	if (!chip)
 		return ERR_PTR(-EPROBE_DEFER);
 
-	return gpiochip_get_desc(chip, pin);
+	/*
+	 * Give it a chance to correct the broken GPIO pin number in ACPI
+	 * table of particular machines.
+	 */
+	return gpiochip_get_desc(chip, acpi_gpio_pin_override(pin));
 }
 
 static irqreturn_t acpi_gpio_irq_handler(int irq, void *data)
-- 
2.17.1


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

end of thread, other threads:[~2021-03-05 12:13 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-26  3:39 [PATCH] gpiolib: acpi: support override broken GPIO number in ACPI table Shawn Guo
2021-02-26  9:12 ` Andy Shevchenko
2021-02-26  9:39   ` Shawn Guo
2021-02-26 10:57     ` Andy Shevchenko
2021-02-26 11:19       ` Andy Shevchenko
2021-02-27  3:19         ` Shawn Guo
2021-03-01 12:17           ` Andy Shevchenko
2021-03-02  0:27             ` Shawn Guo
2021-03-02 12:21               ` Andy Shevchenko
2021-03-03  5:02                 ` Jeffrey Hugo
2021-03-03  8:06                   ` Andy Shevchenko
2021-03-03  8:45                     ` Shawn Guo
2021-03-03  9:42                       ` Andy Shevchenko
2021-03-03 17:08                     ` Jeffrey Hugo
2021-03-03  9:43                   ` Shawn Guo
2021-03-03 15:10                     ` Jeffrey Hugo
2021-03-03 15:57                       ` Bjorn Andersson
2021-03-03 17:32                         ` Andy Shevchenko
2021-03-04  6:37                         ` Shawn Guo
2021-03-04  6:59                           ` Shawn Guo
2021-02-27  3:46       ` Shawn Guo
2021-03-01 12:19         ` Andy Shevchenko
2021-03-02  0:44           ` Shawn Guo
2021-03-02 10:36             ` Andy Shevchenko
2021-03-03  9:47 ` Andy Shevchenko
2021-03-04 19:32   ` Hans de Goede
2021-03-04 20:16     ` Andy Shevchenko
2021-03-05  1:14     ` Shawn Guo
2021-03-05  9:10       ` Hans de Goede
2021-03-05 10:08         ` Andy Shevchenko
2021-03-05 10:10           ` Andy Shevchenko
2021-03-05 11:26         ` Shawn Guo
2021-03-05 12:12           ` Hans de Goede

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).