* [PATCH v2] gpio: pca953x: Override IRQ for one of the expanders on Galileo Gen 2
@ 2020-05-25 19:08 Andy Shevchenko
2020-05-26 5:31 ` Mika Westerberg
0 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2020-05-25 19:08 UTC (permalink / raw)
To: linux-gpio, Linus Walleij, Bartosz Golaszewski
Cc: Andy Shevchenko, Mika Westerberg
ACPI table on Intel Galileo Gen 2 has wrong pin number for IRQ resource
of one of the I²C GPIO expanders. Since we know what that number is and
luckily have GPIO bases fixed for SoC's controllers, we may use a simple
DMI quirk to match the platform and retrieve GpioInt() pin on it for
the expander in question.
Suggested-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
v2: did everything in the driver (Mika)
drivers/gpio/gpio-pca953x.c | 65 +++++++++++++++++++++++++++++++++++++
1 file changed, 65 insertions(+)
diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index 1fca8dd7824f..0d30f19782a2 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -10,6 +10,7 @@
#include <linux/acpi.h>
#include <linux/bitmap.h>
+#include <linux/dmi.h>
#include <linux/gpio/driver.h>
#include <linux/gpio/consumer.h>
#include <linux/i2c.h>
@@ -107,6 +108,62 @@ static const struct i2c_device_id pca953x_id[] = {
};
MODULE_DEVICE_TABLE(i2c, pca953x_id);
+#ifdef CONFIG_GPIO_PCA953X_IRQ
+static const struct dmi_system_id pca953x_dmi_acpi_irq_info[] = {
+ {
+ /*
+ * On Intel Galileo Gen 2 board the IRQ pin of one of
+ * the I²C GPIO expanders, which has GpioInt() resource,
+ * is provided as an absolute number instead of being
+ * relative. Since first controller (gpio-sch.c) and
+ * second (gpio-dwapb.c) are at the fixed bases, we may
+ * safely refer to the number in the global space to get
+ * an IRQ out of it.
+ */
+ .matches = {
+ DMI_EXACT_MATCH(DMI_BOARD_NAME, "GalileoGen2"),
+ },
+ },
+ {}
+};
+
+#ifdef CONFIG_ACPI
+static acpi_status pca953x_acpi_get_pin(struct acpi_resource *ares, void *data)
+{
+ struct acpi_resource_gpio *agpio;
+ int *pin = data;
+
+ if (!acpi_gpio_get_irq_resource(ares, &agpio))
+ return AE_OK;
+
+ *pin = agpio->pin_table[0];
+ return AE_CTRL_TERMINATE;
+}
+
+static int pca953x_acpi_find_pin(acpi_handle handle)
+{
+ int p = -ENOENT;
+
+ acpi_walk_resources(handle, METHOD_NAME__CRS, pca953x_acpi_get_pin, &p);
+ return p;
+}
+#else
+static inline int pca953x_acpi_find_pin(acpi_handle handle) { return -ENXIO; }
+#endif
+
+static int pca953x_acpi_get_irq(struct device *dev)
+{
+ int pin;
+
+ pin = pca953x_acpi_find_pin(ACPI_HANDLE(dev));
+ if (pin < 0)
+ return pin;
+
+ dev_info(dev, "Applying ACPI interrupt quirk (GPIO %d)\n", pin);
+ return gpiod_to_irq(gpio_to_desc(pin));
+}
+#endif
+
static const struct acpi_device_id pca953x_acpi_ids[] = {
{ "INT3491", 16 | PCA953X_TYPE | PCA_LATCH_INT, },
{ }
@@ -750,8 +807,16 @@ static int pca953x_irq_setup(struct pca953x_chip *chip, int irq_base)
struct irq_chip *irq_chip = &chip->irq_chip;
DECLARE_BITMAP(reg_direction, MAX_LINE);
DECLARE_BITMAP(irq_stat, MAX_LINE);
+ const struct dmi_system_id *id;
int ret;
+ id = dmi_first_match(pca953x_dmi_acpi_irq_info);
+ if (id) {
+ ret = pca953x_acpi_get_irq(&client->dev);
+ if (ret > 0)
+ client->irq = ret;
+ }
+
if (!client->irq)
return 0;
--
2.26.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2] gpio: pca953x: Override IRQ for one of the expanders on Galileo Gen 2
2020-05-25 19:08 [PATCH v2] gpio: pca953x: Override IRQ for one of the expanders on Galileo Gen 2 Andy Shevchenko
@ 2020-05-26 5:31 ` Mika Westerberg
2020-05-26 13:11 ` Andy Shevchenko
0 siblings, 1 reply; 6+ messages in thread
From: Mika Westerberg @ 2020-05-26 5:31 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: linux-gpio, Linus Walleij, Bartosz Golaszewski
On Mon, May 25, 2020 at 10:08:45PM +0300, Andy Shevchenko wrote:
> ACPI table on Intel Galileo Gen 2 has wrong pin number for IRQ resource
> of one of the I²C GPIO expanders. Since we know what that number is and
> luckily have GPIO bases fixed for SoC's controllers, we may use a simple
> DMI quirk to match the platform and retrieve GpioInt() pin on it for
> the expander in question.
>
> Suggested-by: Mika Westerberg <mika.westerberg@linux.intel.com>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> v2: did everything in the driver (Mika)
> drivers/gpio/gpio-pca953x.c | 65 +++++++++++++++++++++++++++++++++++++
> 1 file changed, 65 insertions(+)
>
> diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
> index 1fca8dd7824f..0d30f19782a2 100644
> --- a/drivers/gpio/gpio-pca953x.c
> +++ b/drivers/gpio/gpio-pca953x.c
> @@ -10,6 +10,7 @@
>
> #include <linux/acpi.h>
> #include <linux/bitmap.h>
> +#include <linux/dmi.h>
> #include <linux/gpio/driver.h>
> #include <linux/gpio/consumer.h>
> #include <linux/i2c.h>
> @@ -107,6 +108,62 @@ static const struct i2c_device_id pca953x_id[] = {
> };
> MODULE_DEVICE_TABLE(i2c, pca953x_id);
>
> +#ifdef CONFIG_GPIO_PCA953X_IRQ
> +static const struct dmi_system_id pca953x_dmi_acpi_irq_info[] = {
> + {
> + /*
> + * On Intel Galileo Gen 2 board the IRQ pin of one of
> + * the I²C GPIO expanders, which has GpioInt() resource,
> + * is provided as an absolute number instead of being
> + * relative. Since first controller (gpio-sch.c) and
> + * second (gpio-dwapb.c) are at the fixed bases, we may
> + * safely refer to the number in the global space to get
> + * an IRQ out of it.
> + */
> + .matches = {
> + DMI_EXACT_MATCH(DMI_BOARD_NAME, "GalileoGen2"),
> + },
> + },
> + {}
> +};
> +
> +#ifdef CONFIG_ACPI
> +static acpi_status pca953x_acpi_get_pin(struct acpi_resource *ares, void *data)
> +{
> + struct acpi_resource_gpio *agpio;
> + int *pin = data;
> +
> + if (!acpi_gpio_get_irq_resource(ares, &agpio))
> + return AE_OK;
> +
> + *pin = agpio->pin_table[0];
> + return AE_CTRL_TERMINATE;
> +}
> +
> +static int pca953x_acpi_find_pin(acpi_handle handle)
> +{
> + int p = -ENOENT;
> +
> + acpi_walk_resources(handle, METHOD_NAME__CRS, pca953x_acpi_get_pin, &p);
> + return p;
> +}
> +#else
> +static inline int pca953x_acpi_find_pin(acpi_handle handle) { return -ENXIO; }
> +#endif
> +
> +static int pca953x_acpi_get_irq(struct device *dev)
> +{
> + int pin;
> +
> + pin = pca953x_acpi_find_pin(ACPI_HANDLE(dev));
> + if (pin < 0)
> + return pin;
> +
> + dev_info(dev, "Applying ACPI interrupt quirk (GPIO %d)\n", pin);
> + return gpiod_to_irq(gpio_to_desc(pin));
You need to request the GPIO as well, I missed that from my example.
Sorry about that.
Otherwise looks good.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] gpio: pca953x: Override IRQ for one of the expanders on Galileo Gen 2
2020-05-26 5:31 ` Mika Westerberg
@ 2020-05-26 13:11 ` Andy Shevchenko
2020-05-26 13:34 ` Mika Westerberg
2020-05-27 5:43 ` Linus Walleij
0 siblings, 2 replies; 6+ messages in thread
From: Andy Shevchenko @ 2020-05-26 13:11 UTC (permalink / raw)
To: Mika Westerberg; +Cc: linux-gpio, Linus Walleij, Bartosz Golaszewski
On Tue, May 26, 2020 at 08:31:01AM +0300, Mika Westerberg wrote:
> On Mon, May 25, 2020 at 10:08:45PM +0300, Andy Shevchenko wrote:
...
> > + dev_info(dev, "Applying ACPI interrupt quirk (GPIO %d)\n", pin);
> > + return gpiod_to_irq(gpio_to_desc(pin));
>
> You need to request the GPIO as well, I missed that from my example.
How? I can't find a function to request GPIO by its descriptor in
include/linux/gpio/*.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] gpio: pca953x: Override IRQ for one of the expanders on Galileo Gen 2
2020-05-26 13:11 ` Andy Shevchenko
@ 2020-05-26 13:34 ` Mika Westerberg
2020-05-27 5:43 ` Linus Walleij
1 sibling, 0 replies; 6+ messages in thread
From: Mika Westerberg @ 2020-05-26 13:34 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: linux-gpio, Linus Walleij, Bartosz Golaszewski
On Tue, May 26, 2020 at 04:11:19PM +0300, Andy Shevchenko wrote:
> On Tue, May 26, 2020 at 08:31:01AM +0300, Mika Westerberg wrote:
> > On Mon, May 25, 2020 at 10:08:45PM +0300, Andy Shevchenko wrote:
>
> ...
>
> > > + dev_info(dev, "Applying ACPI interrupt quirk (GPIO %d)\n", pin);
> > > + return gpiod_to_irq(gpio_to_desc(pin));
> >
> > You need to request the GPIO as well, I missed that from my example.
>
> How? I can't find a function to request GPIO by its descriptor in
> include/linux/gpio/*.
Not by descriptor but by number which you are already using here anyway.
The function that does that is gpio_request(). I know we should use GPIO
descriptors everywhere but this is a special case for a special hardware
with a broken firmware, so IMHO it should be fine ;-) Once the legacy
API is gets removed this whole hack can be removed as well and nobody
will notice.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] gpio: pca953x: Override IRQ for one of the expanders on Galileo Gen 2
2020-05-26 13:11 ` Andy Shevchenko
2020-05-26 13:34 ` Mika Westerberg
@ 2020-05-27 5:43 ` Linus Walleij
2020-05-27 9:10 ` Andy Shevchenko
1 sibling, 1 reply; 6+ messages in thread
From: Linus Walleij @ 2020-05-27 5:43 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Mika Westerberg, open list:GPIO SUBSYSTEM, Bartosz Golaszewski
On Tue, May 26, 2020 at 3:11 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
> On Tue, May 26, 2020 at 08:31:01AM +0300, Mika Westerberg wrote:
> > On Mon, May 25, 2020 at 10:08:45PM +0300, Andy Shevchenko wrote:
>
> ...
>
> > > + dev_info(dev, "Applying ACPI interrupt quirk (GPIO %d)\n", pin);
> > > + return gpiod_to_irq(gpio_to_desc(pin));
> >
> > You need to request the GPIO as well, I missed that from my example.
>
> How? I can't find a function to request GPIO by its descriptor in
> include/linux/gpio/*.
If a gpiochip need to request one of its own GPIOs it should use
gpiochip_request_own_desc() but I don't know if you have all
info at hand to use that in this driver.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] gpio: pca953x: Override IRQ for one of the expanders on Galileo Gen 2
2020-05-27 5:43 ` Linus Walleij
@ 2020-05-27 9:10 ` Andy Shevchenko
0 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2020-05-27 9:10 UTC (permalink / raw)
To: Linus Walleij
Cc: Mika Westerberg, open list:GPIO SUBSYSTEM, Bartosz Golaszewski
On Wed, May 27, 2020 at 07:43:28AM +0200, Linus Walleij wrote:
> On Tue, May 26, 2020 at 3:11 PM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> > On Tue, May 26, 2020 at 08:31:01AM +0300, Mika Westerberg wrote:
> > > On Mon, May 25, 2020 at 10:08:45PM +0300, Andy Shevchenko wrote:
> >
> > ...
> >
> > > > + dev_info(dev, "Applying ACPI interrupt quirk (GPIO %d)\n", pin);
> > > > + return gpiod_to_irq(gpio_to_desc(pin));
> > >
> > > You need to request the GPIO as well, I missed that from my example.
> >
> > How? I can't find a function to request GPIO by its descriptor in
> > include/linux/gpio/*.
>
> If a gpiochip need to request one of its own GPIOs it should use
> gpiochip_request_own_desc()
It's not the case here.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-05-27 9:10 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-25 19:08 [PATCH v2] gpio: pca953x: Override IRQ for one of the expanders on Galileo Gen 2 Andy Shevchenko
2020-05-26 5:31 ` Mika Westerberg
2020-05-26 13:11 ` Andy Shevchenko
2020-05-26 13:34 ` Mika Westerberg
2020-05-27 5:43 ` Linus Walleij
2020-05-27 9:10 ` Andy Shevchenko
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.