Skip to contentSkip to conversation

commit f34fd6ee1be8 breaks current dwapb gpio DT users

DISCUSSION Jisheng Zhang 3 participants 5 messages Feb 17, 2024 – Feb 19, 2024 GPIO

lore
Share & tools
lore
#0 lore raw

Hi Emil, Linus,

commit f34fd6ee1be8 ("gpio: dwapb: Use generic request, free and set_config") breaks all current dwapb gpio DT users, for example, getting cd-gpios will always fail as -EPROBE_DEFER. Before the commit, dwapb_gpio_set_config() returns -ENOTSUPP for !PIN_CONFIG_INPUT_DEBOUNCE then gpio_set_config_with_argument_optional() will happily ignore -ENOTSUPP. After the commit, dwapb_gpio_set_config() will return -EPROBE_DEFER unless the gpio-ranges are set in DT.

The key problem here is: almost all dwapb gpio DT users don't set the gpio-ranges DT property, so I guess current dwapb gpio DT users have this problem and the commit also breaks old DT compatbility. So could we getback to previous behavior?

Thanks in advance

#1 lore raw
Quoted 10 lines · Jisheng Zhang

Hi Emil, Linus,

commit f34fd6ee1be8 ("gpio: dwapb: Use generic request, free and set_config") breaks all current dwapb gpio DT users, for example, getting cd-gpios will always fail as -EPROBE_DEFER. Before the commit, dwapb_gpio_set_config() returns -ENOTSUPP for !PIN_CONFIG_INPUT_DEBOUNCE then gpio_set_config_with_argument_optional() will happily ignore

(quoted diff) +0 -2
-ENOTSUPP. After the commit, dwapb_gpio_set_config() will return
-EPROBE_DEFER unless the gpio-ranges are set in DT.
Quoted 4 lines

The key problem here is: almost all dwapb gpio DT users don't set the gpio-ranges DT property, so I guess current dwapb gpio DT users have this problem and the commit also breaks old DT compatbility. So could we getback to previous behavior?

Hi Jisheng

It seems like the gpiochip_generic_request() and gpiochip_generic_free() functions have guards to handle when gpio-ranges are not set that gpiochip_generic_config() lacks. Could you try the patch below?

Otherwise I'm also fine with just reverting the patch if this is not the right solution.

/Emil

drivers/gpio/gpiolib.c +5 -0
index 8b3a0f45b574..e434e8cc1229 100644
@@ -2042,6 +2042,11 @@ EXPORT_SYMBOL_GPL(gpiochip_generic_free);
 int gpiochip_generic_config(struct gpio_chip *gc, unsigned int offset,
                            unsigned long config)
 {
+#ifdef CONFIG_PINCTRL
+       if (list_empty(&gc->gpiodev->pin_ranges))
+               return -ENOTSUPP;
+#endif
+
        return pinctrl_gpio_set_config(gc, offset, config);
 }
 EXPORT_SYMBOL_GPL(gpiochip_generic_config);
author Tested-by
#2 lore raw
Quoted 33 lines · Emil Renner Berthing
Quoted 10 lines · Jisheng Zhang

Hi Emil, Linus,

commit f34fd6ee1be8 ("gpio: dwapb: Use generic request, free and set_config") breaks all current dwapb gpio DT users, for example, getting cd-gpios will always fail as -EPROBE_DEFER. Before the commit, dwapb_gpio_set_config() returns -ENOTSUPP for !PIN_CONFIG_INPUT_DEBOUNCE then gpio_set_config_with_argument_optional() will happily ignore

(quoted diff) +0 -2
-ENOTSUPP. After the commit, dwapb_gpio_set_config() will return
-EPROBE_DEFER unless the gpio-ranges are set in DT.
Quoted 4 lines

The key problem here is: almost all dwapb gpio DT users don't set the gpio-ranges DT property, so I guess current dwapb gpio DT users have this problem and the commit also breaks old DT compatbility. So could we getback to previous behavior?

Hi Jisheng

It seems like the gpiochip_generic_request() and gpiochip_generic_free() functions have guards to handle when gpio-ranges are not set that gpiochip_generic_config() lacks. Could you try the patch below?

Otherwise I'm also fine with just reverting the patch if this is not the right solution.

/Emil

drivers/gpio/gpiolib.c +0 -0
index 8b3a0f45b574..e434e8cc1229 100644
@@ -2042,6 +2042,11 @@ EXPORT_SYMBOL_GPL(gpiochip_generic_free);
 int gpiochip_generic_config(struct gpio_chip *gc, unsigned int offset,

drivers/gpio/gpiolib.c EXPORT_SYMBOL_GPL(gpiochip_generic_free); · line 2052

Quoted 10 lines
drivers/gpio/gpiolib.c +5 -0
                            unsigned long config)
 {
+#ifdef CONFIG_PINCTRL
+       if (list_empty(&gc->gpiodev->pin_ranges))
+               return -ENOTSUPP;
+#endif
+
        return pinctrl_gpio_set_config(gc, offset, config);
 }
 EXPORT_SYMBOL_GPL(gpiochip_generic_config);

Hi Emil,

The above patch can fix the gpio issue. So,

Thanks

Reviewed-by
#3 lore raw
In reply to Emil Renner Berthing

drivers/gpio/gpiolib.c EXPORT_SYMBOL_GPL(gpiochip_generic_free); · line 2045

Quoted 7 lines · Emil Renner Berthing
drivers/gpio/gpiolib.c +1 -0
@@ -2042,6 +2042,11 @@ EXPORT_SYMBOL_GPL(gpiochip_generic_free);
 int gpiochip_generic_config(struct gpio_chip *gc, unsigned int offset,
                            unsigned long config)
 {
+#ifdef CONFIG_PINCTRL

Please do this:

if (IS_ENABLED(CONFIG_PINCTRL) && list_empty(&gc->gpiodev->pin_ranges))
...

The ifdef is so ugly.

drivers/gpio/gpiolib.c EXPORT_SYMBOL_GPL(gpiochip_generic_free); · line 2048

Quoted 3 lines
drivers/gpio/gpiolib.c +3 -0
+       if (list_empty(&gc->gpiodev->pin_ranges))
+               return -ENOTSUPP;
+#endif

That looks like a reasonable fix, I try to wrap my head around if it would affect
any users but can't figure it out, we have to test.

Can you please send it as a proper patch? With the above fixed:

Yours,
Linus Walleij

#4 lore raw
Quoted 13 lines · Linus Walleij

drivers/gpio/gpiolib.c EXPORT_SYMBOL_GPL(gpiochip_generic_free); · line 2045

Quoted 7 lines · Emil Renner Berthing
drivers/gpio/gpiolib.c +1 -0
@@ -2042,6 +2042,11 @@ EXPORT_SYMBOL_GPL(gpiochip_generic_free);
 int gpiochip_generic_config(struct gpio_chip *gc, unsigned int offset,
                            unsigned long config)
 {
+#ifdef CONFIG_PINCTRL

Please do this:

Quoted 4 lines

if (IS_ENABLED(CONFIG_PINCTRL) && list_empty(&gc->gpiodev->pin_ranges))
...

The ifdef is so ugly.

I agree, but I'm not sure it will work in this case since the pin_ranges member is only there when CONFIG_PINCTRL=y. That would also explain why gpiochip_generic_request() and gpiochip_generic_free() use ifdefs.

Quoted 11 lines

drivers/gpio/gpiolib.c EXPORT_SYMBOL_GPL(gpiochip_generic_free); · line 2048

Quoted 4 lines
drivers/gpio/gpiolib.c +3 -0
+       if (list_empty(&gc->gpiodev->pin_ranges))
+               return -ENOTSUPP;
+#endif

That looks like a reasonable fix, I try to wrap my head around if it would affect
any users but can't figure it out, we have to test.

Can you please send it as a proper patch? With the above fixed:

Will do, thanks!

/Emil