From: Shawn Guo <shawn.guo@linaro.org>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Bartosz Golaszewski <bgolaszewski@baylibre.com>,
Bjorn Andersson <bjorn.andersson@linaro.org>,
linux-gpio@vger.kernel.org, linux-acpi@vger.kernel.org,
linux-arm-msm@vger.kernel.org, Shawn Guo <shawn.guo@linaro.org>
Subject: [PATCH] gpiolib: acpi: support override broken GPIO number in ACPI table
Date: Fri, 26 Feb 2021 11:39:19 +0800 [thread overview]
Message-ID: <20210226033919.8871-1-shawn.guo@linaro.org> (raw)
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
next reply other threads:[~2021-02-26 3:40 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-26 3:39 Shawn Guo [this message]
2021-02-26 9:12 ` [PATCH] gpiolib: acpi: support override broken GPIO number in ACPI table 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210226033919.8871-1-shawn.guo@linaro.org \
--to=shawn.guo@linaro.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=bgolaszewski@baylibre.com \
--cc=bjorn.andersson@linaro.org \
--cc=linus.walleij@linaro.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=mika.westerberg@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).