gpio: pca953x: Better quirk for Intel Galileo Gen 2
cover gpio: pca953x: Better quirk for Intel Galileo Gen 2
It appears that after commit to the gpio-dwapb driver the quirk for Intel Galileo Gen 2 stopped working. I tried a few approaches but none of them worked besides the fact that they copy like a ~10% of the gpiolib-acpi functionality.
Instead I decided to come back to a mix of v1 [1] of the initial series (the v3 has been applied) and Mika's suggestion about using gpio_to_desc() API.
Unfortunately it requires to have a quirk in the core, but in comparison to v1 it much less intrusive and doesn't use any predefined numbers.
I would like to create an immutable branch and send TWIMC (GPIO and ACPI subsystems I guess). This is material for v5.12-rcX.
[1]: https://lore.kernel.org/linux-gpio/[email protected]/
Andy Shevchenko (3):
gpiolib: acpi: Add ACPI_GPIO_QUIRK_ABSOLUTE_NUMBER quirk
gpiolib: acpi: Allow to find GpioInt() resource by name and index
gpio: pca953x: Set IRQ type when handle Intel Galileo Gen 2
drivers/gpio/gpio-pca953x.c | 78 +++++++++++------------------------ drivers/gpio/gpiolib-acpi.c | 19 ++++++--- include/linux/acpi.h | 10 ++++- include/linux/gpio/consumer.h | 2 + 4 files changed, 47 insertions(+), 62 deletions(-)
Signature · 1 line
2.30.0
PATCH 1/3 gpiolib: acpi: Add ACPI_GPIO_QUIRK_ABSOLUTE_NUMBER quirk
On some systems the ACPI tables has wrong pin number and instead of having a relative one it provides an absolute one in the global GPIO number space.
Add ACPI_GPIO_QUIRK_ABSOLUTE_NUMBER quirk to cope with such cases.
Depends-on: 0ea683931adb ("gpio: dwapb: Convert driver to using the GPIO-lib-based IRQ-chip")
--- drivers/gpio/gpiolib-acpi.c | 7 ++++++- include/linux/gpio/consumer.h | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-)
drivers/gpio/gpiolib-acpi.c +6 -1
@@ -677,6 +677,7 @@ static int acpi_populate_gpio_lookup(struct acpi_resource *ares, void *data)if (!lookup->desc) {const struct acpi_resource_gpio *agpio = &ares->data.gpio;bool gpioint = agpio->connection_type ==ACPI_RESOURCE_GPIO_TYPE_INT ; +struct gpio_desc *desc;u16 pin_index;if (lookup->info.quirks &ACPI_GPIO_QUIRK_ONLY_GPIOIO && gpioint)
@@ -689,8 +690,12 @@ static int acpi_populate_gpio_lookup(struct acpi_resource *ares, void *data)if (pin_index >= agpio->pin_table_length)return 1 ; - lookup->desc =acpi_get_gpiod (agpio->resource_source.string_ptr, +if (lookup->info.quirks &ACPI_GPIO_QUIRK_ABSOLUTE_NUMBER ) + desc =gpio_to_desc (agpio->pin_table[pin_index]); +else + desc =acpi_get_gpiod (agpio->resource_source.string_ptr, agpio->pin_table[pin_index]); + lookup->desc = desc; lookup->info.pin_config = agpio->pin_config; lookup->info.debounce = agpio->debounce_timeout; lookup->info.gpioint = gpioint;
include/linux/gpio/consumer.h +2 -0
@@ -674,6 +674,8 @@ struct acpi_gpio_mapping {* get GpioIo type explicitly, this quirk may be used. */ #define ACPI_GPIO_QUIRK_ONLY_GPIOIO BIT(1) +/* Use given pin as an absolute GPIO number in the system */ +#define ACPI_GPIO_QUIRK_ABSOLUTE_NUMBER BIT(2)unsigned int quirks; };
Signature · 1 line
2.30.0
Re: [PATCH v1 1/3] gpiolib: acpi: Add ACPI_GPIO_QUIRK_ABSOLUTE_NUMBER quirk
Quoted 9 lines · Andy Shevchenko
On some systems the ACPI tables has wrong pin number and instead of having a relative one it provides an absolute one in the global GPIO number space.
Add
ACPI_GPIO_QUIRK_ABSOLUTE_NUMBERquirk to cope with such cases.Fixes ba8c90c61847 ("gpio: pca953x: Override IRQ for one of the expanders on Galileo Gen 2")Depends-on:
0ea683931adb("gpio: dwapb: Convert driver to using the GPIO-lib-based IRQ-chip")Signed-off-by Andy Shevchenko <[email protected]>
OH THE HORROR!
However, we discussed it before. It is as it is.
It's the right place to fix the problem, so:
Yours,
Linus Walleij
Re: [PATCH v1 1/3] gpiolib: acpi: Add ACPI_GPIO_QUIRK_ABSOLUTE_NUMBER quirk
Quoted 7 lines · Linus Walleij
Quoted 4 lines · Andy Shevchenko
On some systems the ACPI tables has wrong pin number and instead of having a relative one it provides an absolute one in the global GPIO number space.
Quoted 8 lines
Quoted 5 lines
Add
ACPI_GPIO_QUIRK_ABSOLUTE_NUMBERquirk to cope with such cases.Fixes ba8c90c61847 ("gpio: pca953x: Override IRQ for one of the expanders on Galileo Gen 2")Depends-on:
0ea683931adb("gpio: dwapb: Convert driver to using the GPIO-lib-based IRQ-chip")Signed-off-by Andy Shevchenko <[email protected]>OH THE HORROR!
However, we discussed it before. It is as it is.
Unfortunately :-( (And recently it seems MS does something really "creative" on ARM ACPI platform)
Quoted 2 lines
It's the right place to fix the problem, so:
Acked-by Linus Walleij <[email protected]>
I am waiting for Mika, but if he keeps silent let's say to the end of the day, I will submit it as is to the v5.12-rcX fixes.
Thanks!
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v1 1/3] gpiolib: acpi: Add ACPI_GPIO_QUIRK_ABSOLUTE_NUMBER quirk
Quoted 17 lines · Andy Shevchenko
Quoted 7 lines · Linus Walleij
Quoted 4 lines · Andy Shevchenko
On some systems the ACPI tables has wrong pin number and instead of having a relative one it provides an absolute one in the global GPIO number space.
Quoted 8 lines
Quoted 5 lines
Add
ACPI_GPIO_QUIRK_ABSOLUTE_NUMBERquirk to cope with such cases.Fixes ba8c90c61847 ("gpio: pca953x: Override IRQ for one of the expanders on Galileo Gen 2")Depends-on:
0ea683931adb("gpio: dwapb: Convert driver to using the GPIO-lib-based IRQ-chip")Signed-off-by Andy Shevchenko <[email protected]>OH THE HORROR!
However, we discussed it before. It is as it is.
Quoted 8 lines
Unfortunately :-( (And recently it seems MS does something really "creative" on ARM ACPI platform)
Quoted 2 lines
It's the right place to fix the problem, so:
Acked-by Linus Walleij <[email protected]>I am waiting for Mika, but if he keeps silent let's say to the end of the day, I will submit it as is to the v5.12-rcX fixes.
Sorry for the delay - I somehow missed this. Feel free to add my ACK too.
Re: [PATCH v1 1/3] gpiolib: acpi: Add ACPI_GPIO_QUIRK_ABSOLUTE_NUMBER quirk
Quoted 21 lines · Mika Westerberg
Quoted 20 lines · Andy Shevchenko
Quoted 7 lines · Linus Walleij
Quoted 4 lines · Andy Shevchenko
On some systems the ACPI tables has wrong pin number and instead of having a relative one it provides an absolute one in the global GPIO number space.
Quoted 8 lines
Quoted 5 lines
Add
ACPI_GPIO_QUIRK_ABSOLUTE_NUMBERquirk to cope with such cases.Fixes ba8c90c61847 ("gpio: pca953x: Override IRQ for one of the expanders on Galileo Gen 2")Depends-on:
0ea683931adb("gpio: dwapb: Convert driver to using the GPIO-lib-based IRQ-chip")Signed-off-by Andy Shevchenko <[email protected]>OH THE HORROR!
However, we discussed it before. It is as it is.Unfortunately :-( (And recently it seems MS does something really "creative" on ARM ACPI platform)
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
It's the right place to fix the problem, so:
Acked-by Linus Walleij <[email protected]>I am waiting for Mika, but if he keeps silent let's say to the end of the day, I will submit it as is to the v5.12-rcX fixes.
Sorry for the delay - I somehow missed this. Feel free to add my ACK too.
Thanks, Mika!
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v1 1/3] gpiolib: acpi: Add ACPI_GPIO_QUIRK_ABSOLUTE_NUMBER quirk
Quoted 29 lines · Andy Shevchenko
Quoted 27 lines · Mika Westerberg
Quoted 25 lines · Andy Shevchenko
Quoted 7 lines · Linus Walleij
Quoted 4 lines · Andy Shevchenko
On some systems the ACPI tables has wrong pin number and instead of having a relative one it provides an absolute one in the global GPIO number space.
Quoted 8 lines
Quoted 5 lines
Add
ACPI_GPIO_QUIRK_ABSOLUTE_NUMBERquirk to cope with such cases.Fixes ba8c90c61847 ("gpio: pca953x: Override IRQ for one of the expanders on Galileo Gen 2")Depends-on:
0ea683931adb("gpio: dwapb: Convert driver to using the GPIO-lib-based IRQ-chip")Signed-off-by Andy Shevchenko <[email protected]>OH THE HORROR!
However, we discussed it before. It is as it is.Unfortunately :-( (And recently it seems MS does something really "creative" on ARM ACPI platform)
Quoted 2 lines
It's the right place to fix the problem, so:
Acked-by Linus Walleij <[email protected]>I am waiting for Mika, but if he keeps silent let's say to the end of the day, I will submit it as is to the v5.12-rcX fixes.
Quoted 10 lines
Quoted 1 line
Sorry for the delay - I somehow missed this. Feel free to add my ACK too.
Thanks, Mika!
--
With Best Regards,
Andy Shevchenko
Hi Andy,
Do you want me to take these, or will you include them in your PR?
Bart
Re: [PATCH v1 1/3] gpiolib: acpi: Add ACPI_GPIO_QUIRK_ABSOLUTE_NUMBER quirk
Quoted 4 lines · Bartosz Golaszewski
On Tue, Mar 2, 2021 at 4:21 PM Andy Shevchenko
<[email protected]> wrote:Do you want me to take these, or will you include them in your PR?
I'll send PR.
I'm waiting for vger to process the queue (it has some lags).
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 2/3 gpiolib: acpi: Allow to find GpioInt() resource by name and index
In reply to Andy ShevchenkoCurrently only search by index is supported. However, in some cases we might need to pass the quirks to the acpi_dev_gpio_irq_get().
For this, split out acpi_dev_gpio_irq_get_by() and replace acpi_dev_gpio_irq_get() by calling above with NULL for name parameter.
Depends-on: 0ea683931adb ("gpio: dwapb: Convert driver to using the GPIO-lib-based IRQ-chip")
--- drivers/gpio/gpiolib-acpi.c | 12 ++++++++---- include/linux/acpi.h | 10 ++++++++-- 2 files changed, 16 insertions(+), 6 deletions(-)
drivers/gpio/gpiolib-acpi.c +8 -4
@@ -945,8 +945,9 @@ struct gpio_desc *acpi_node_get_gpiod(struct fwnode_handle *fwnode, }/** -* acpi_dev_gpio_irq_get() - Find GpioInt and translate it to Linux IRQ number +* acpi_dev_gpio_irq_get_by() - Find GpioInt and translate it to Linux IRQ number * @adev: pointer to a ACPI device to get IRQ from +* @name: optional name of GpioInt resource * @index: index of GpioInt resource (starting from %0) * * If the device has one or more GpioInt resources, this function can be
@@ -956,9 +957,12 @@ struct gpio_desc *acpi_node_get_gpiod(struct fwnode_handle *fwnode,* The function is idempotent, though each time it runs it will configure GPIO * pin direction according to the flags in GpioInt resource. * +* The function takes optional @name parameter. If the resource has a property +* name, then only those will be taken into account. +* * Return: Linux IRQ number (> %0) on success, negative errno on failure. */ -int acpi_dev_gpio_irq_get (struct acpi_device *adev,int index) +int acpi_dev_gpio_irq_get_by (struct acpi_device *adev,const char *name,int index) {int idx, i;unsigned int irq_flags;
@@ -968,7 +972,7 @@ int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index)struct acpi_gpio_info info;struct gpio_desc *desc; - desc =acpi_get_gpiod_by_index (adev,NULL , i, &info); + desc =acpi_get_gpiod_by_index (adev, name, i, &info);/* Ignore -EPROBE_DEFER, it only matters if idx matches */ if (IS_ERR (desc) &&PTR_ERR (desc) != -EPROBE_DEFER )
@@ -1013,7 +1017,7 @@ int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index) }return -ENOENT ; } -EXPORT_SYMBOL_GPL (acpi_dev_gpio_irq_get); +EXPORT_SYMBOL_GPL (acpi_dev_gpio_irq_get_by); static acpi_status acpi_gpio_adr_space_handler(u32 function, acpi_physical_address address,
include/linux/acpi.h +8 -2
@@ -1072,19 +1072,25 @@ void __acpi_handle_debug(struct _ddebug *descriptor, acpi_handle handle, const c#if defined(CONFIG_ACPI ) && defined(CONFIG_GPIOLIB )bool acpi_gpio_get_irq_resource (struct acpi_resource *ares,struct acpi_resource_gpio **agpio); -int acpi_dev_gpio_irq_get (struct acpi_device *adev,int index); +int acpi_dev_gpio_irq_get_by (struct acpi_device *adev,const char *name,int index);#else static inline bool acpi_gpio_get_irq_resource (struct acpi_resource *ares,struct acpi_resource_gpio **agpio) {return false; } -static inline int acpi_dev_gpio_irq_get (struct acpi_device *adev,int index) +static inline int acpi_dev_gpio_irq_get_by (struct acpi_device *adev, +const char *name,int index) {return -ENXIO ; }#endif +static inline int acpi_dev_gpio_irq_get (struct acpi_device *adev,int index) +{ +return acpi_dev_gpio_irq_get_by (adev,NULL , index); +} +/* Device properties */ #ifdef CONFIG_ACPI
Signature · 1 line
2.30.0
Re: [PATCH v1 2/3] gpiolib: acpi: Allow to find GpioInt() resource by name and index
Quoted 9 lines · Andy Shevchenko
Currently only search by index is supported. However, in some cases we might need to pass the quirks to the
acpi_dev_gpio_irq_get().For this, split out
acpi_dev_gpio_irq_get_by()and replaceacpi_dev_gpio_irq_get()by calling above with NULL for name parameter.Fixes ba8c90c61847 ("gpio: pca953x: Override IRQ for one of the expanders on Galileo Gen 2")Depends-on:
0ea683931adb("gpio: dwapb: Convert driver to using the GPIO-lib-based IRQ-chip")Signed-off-by Andy Shevchenko <[email protected]>
Yours,
Linus Walleij
PATCH 3/3 gpio: pca953x: Set IRQ type when handle Intel Galileo Gen 2
In reply to Andy ShevchenkoThe commit 0ea683931adb ("gpio: dwapb: Convert driver to using the GPIO-lib-based IRQ-chip") indeliberately made a regression on how IRQ line from GPIO I²C expander is handled. I.e. it reveals that the quirk for Intel Galileo Gen 2 misses the part of setting IRQ type which previously was predefined by gpio-dwapb driver. Now, we have to reorganize the approach to call necessary parts, which can be done via ACPI_GPIO_QUIRK_ABSOLUTE_NUMBER quirk.
Without this fix and with above mentioned change the kernel hangs on the first IRQ event with:
gpio gpiochip3: Persistence not supported for GPIO 1
irq 32, desc: 62f8fb50, depth: 0, count: 0, unhandled: 0
->handle_irq(): 41c7b0ab, handle_bad_irq+0x0/0x40
->irq_data.chip(): e03f1e72, 0xc2539218
->action(): 0ecc7e6f
->action->handler(): 8a3db21e, irq_default_primary_handler+0x0/0x10
IRQ_NOPROBE set
unexpected IRQ trap at vector 20Depends-on: 0ea683931adb ("gpio: dwapb: Convert driver to using the GPIO-lib-based IRQ-chip")
--- drivers/gpio/gpio-pca953x.c | 78 +++++++++++-------------------------- 1 file changed, 23 insertions(+), 55 deletions(-)
drivers/gpio/gpio-pca953x.c +23 -55
@@ -112,8 +112,29 @@ MODULE_DEVICE_TABLE(i2c, pca953x_id); #ifdef CONFIG_GPIO_PCA953X_IRQ #include <linux/dmi.h> -#include <linux/gpio.h> -#include <linux/list.h> + +static const struct acpi_gpio_params pca953x_irq_gpios = { 0, 0, true }; + +static const struct acpi_gpio_mapping pca953x_acpi_irq_gpios[] = { + { "irq-gpios", &pca953x_irq_gpios, 1, ACPI_GPIO_QUIRK_ABSOLUTE_NUMBER }, + { } +}; + +static int pca953x_acpi_get_irq(struct device *dev) +{ + int ret; + + ret = devm_acpi_dev_add_driver_gpios(dev, pca953x_acpi_irq_gpios); + if (ret) + dev_warn(dev, "can't add GPIO ACPI mapping\n"); + + ret = acpi_dev_gpio_irq_get_by(ACPI_COMPANION(dev), "irq-gpios", 0); + if (ret < 0) + return ret; + + dev_info(dev, "ACPI interrupt quirk (IRQ %d)\n", ret); + return ret; +} static const struct dmi_system_id pca953x_dmi_acpi_irq_info[] = { {
@@ -132,59 +153,6 @@ static const struct dmi_system_id pca953x_dmi_acpi_irq_info[] = { }, {} }; - -#ifdef CONFIG_ACPI -static int 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)) - *pin = agpio->pin_table[0 ]; -return 1 ; -} - -static int pca953x_acpi_find_pin (struct device *dev) -{ -struct acpi_device *adev =ACPI_COMPANION (dev); -int pin = -ENOENT , ret; -LIST_HEAD (r); - - ret =acpi_dev_get_resources (adev, &r, pca953x_acpi_get_pin, &pin); -acpi_dev_free_resource_list (&r); -if (ret <0 ) -return ret; - -return pin; -} -#else -static inline int pca953x_acpi_find_pin (struct device *dev) {return -ENXIO ; } -#endif - -static int pca953x_acpi_get_irq (struct device *dev) -{ -int pin, ret; - - pin =pca953x_acpi_find_pin (dev); -if (pin <0 ) -return pin; - -dev_info (dev,"Applying ACPI interrupt quirk (GPIO %d)\n" , pin); - -if (!gpio_is_valid (pin)) -return -EINVAL ; - - ret =gpio_request (pin,"pca953x interrupt" ); -if (ret) -return ret; - - ret =gpio_to_irq (pin); - -/* When pin is used as an IRQ, no need to keep it requested */ -gpio_free (pin); - -return ret; -}#endif static const struct acpi_device_id pca953x_acpi_ids[] = {
Signature · 1 line
2.30.0
Re: [PATCH v1 3/3] gpio: pca953x: Set IRQ type when handle Intel Galileo Gen 2
Quoted 20 lines · Andy Shevchenko
The commit
0ea683931adb("gpio: dwapb: Convert driver to using the GPIO-lib-based IRQ-chip") indeliberately made a regression on how IRQ line from GPIO I²C expander is handled. I.e. it reveals that the quirk for Intel Galileo Gen 2 misses the part of setting IRQ type which previously was predefined by gpio-dwapb driver. Now, we have to reorganize the approach to call necessary parts, which can be done viaACPI_GPIO_QUIRK_ABSOLUTE_NUMBERquirk.Without this fix and with above mentioned change the kernel hangs on the first IRQ event with:
gpio gpiochip3: Persistence not supported for GPIO 1 irq 32, desc: 62f8fb50, depth: 0, count: 0, unhandled: 0 ->handle_irq(): 41c7b0ab, handle_bad_irq+0x0/0x40 ->irq_data.chip(): e03f1e72, 0xc2539218 ->action(): 0ecc7e6f ->action->handler(): 8a3db21e, irq_default_primary_handler+0x0/0x10 IRQ_NOPROBE set unexpected IRQ trap at vector 20
Quoted 2 lines
Fixes ba8c90c61847 ("gpio: pca953x: Override IRQ for one of the expanders on Galileo Gen 2")Depends-on:
0ea683931adb("gpio: dwapb: Convert driver to using the GPIO-lib-based IRQ-chip")
I never saw that before, seems useful!
Quoted 1 line
Signed-off-by Andy Shevchenko <[email protected]>
Not only does it fix the bug, it also looks so much better by separation of concerns.
Yours,
Linus Walleij