* [PATCH v1] gpiolib: Don't probe gpio_device if it's not the primary device
@ 2021-02-05 2:07 Saravana Kannan
2021-02-05 10:02 ` Bartosz Golaszewski
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Saravana Kannan @ 2021-02-05 2:07 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Saravana Kannan, Greg Kroah-Hartman
Cc: Dmitry Osipenko, kernel-team, linux-gpio, linux-kernel
Dmitry reported[1] boot error messages caused by
commit 4731210c09f5 ("gpiolib: Bind gpio_device to a driver to enable fw_devlink=on by default").
gpio-1022 (cpu-pwr-req-hog): hogged as input
max77620-pinctrl max77620-pinctrl: pin gpio4 already requested by max77620-pinctrl; cannot claim for gpiochip1
max77620-pinctrl max77620-pinctrl: pin-4 (gpiochip1) status -22
max77620-pinctrl max77620-pinctrl: could not request pin 4 (gpio4) from group gpio4 on device max77620-pinctrl
gpio_stub_drv gpiochip1: Error applying setting, reverse things back
gpio_stub_drv: probe of gpiochip1 failed with error -22
This happens because when we try to probe a device, driver core calls
into pinctrl to set up the pins. However, if the GPIO DT node already
has a proper device created and probed, trying to probe the gpio_device
with a stub driver makes the pins be claimed twice. pinctrl doesn't like
this and throws an error.
So, this patch makes sure the gpio_stub_drv doesn't match with a
gpio_device if it's not the primary device for the fwnode.
[1] - https://lore.kernel.org/lkml/544ad0e4-0954-274c-8e77-866aaa5661a8@gmail.com/
Fixes: 4731210c09f5 ("gpiolib: Bind gpio_device to a driver to enable fw_devlink=on by default")
Signed-off-by: Saravana Kannan <saravanak@google.com>
Tested-by: Dmitry Osipenko <digetx@gmail.com>
---
Greg/Linus,
This will need to go into driver-core because the Fixes is in
driver-core too.
Thanks,
Saravana
drivers/gpio/gpiolib.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 8e0564c50840..8ad679a928b0 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -56,8 +56,10 @@
static DEFINE_IDA(gpio_ida);
static dev_t gpio_devt;
#define GPIO_DEV_MAX 256 /* 256 GPIO chip devices supported */
+static int gpio_bus_match(struct device *dev, struct device_driver *drv);
static struct bus_type gpio_bus_type = {
.name = "gpio",
+ .match = gpio_bus_match,
};
/*
@@ -4199,6 +4201,18 @@ void gpiod_put_array(struct gpio_descs *descs)
}
EXPORT_SYMBOL_GPL(gpiod_put_array);
+
+static int gpio_bus_match(struct device *dev, struct device_driver *drv)
+{
+ /*
+ * Only match if the fwnode doesn't already have a proper struct device
+ * created for it.
+ */
+ if (dev->fwnode && dev->fwnode->dev != dev)
+ return 0;
+ return 1;
+}
+
static int gpio_stub_drv_probe(struct device *dev)
{
/*
--
2.30.0.365.g02bc693789-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v1] gpiolib: Don't probe gpio_device if it's not the primary device
2021-02-05 2:07 [PATCH v1] gpiolib: Don't probe gpio_device if it's not the primary device Saravana Kannan
@ 2021-02-05 10:02 ` Bartosz Golaszewski
2021-02-09 12:04 ` Geert Uytterhoeven
2021-02-12 9:37 ` Linus Walleij
2 siblings, 0 replies; 4+ messages in thread
From: Bartosz Golaszewski @ 2021-02-05 10:02 UTC (permalink / raw)
To: Saravana Kannan
Cc: Linus Walleij, Bartosz Golaszewski, Greg Kroah-Hartman,
Dmitry Osipenko, kernel-team, open list:GPIO SUBSYSTEM,
Linux Kernel Mailing List
On Fri, Feb 5, 2021 at 3:08 AM Saravana Kannan <saravanak@google.com> wrote:
>
> Dmitry reported[1] boot error messages caused by
> commit 4731210c09f5 ("gpiolib: Bind gpio_device to a driver to enable fw_devlink=on by default").
>
> gpio-1022 (cpu-pwr-req-hog): hogged as input
> max77620-pinctrl max77620-pinctrl: pin gpio4 already requested by max77620-pinctrl; cannot claim for gpiochip1
> max77620-pinctrl max77620-pinctrl: pin-4 (gpiochip1) status -22
> max77620-pinctrl max77620-pinctrl: could not request pin 4 (gpio4) from group gpio4 on device max77620-pinctrl
> gpio_stub_drv gpiochip1: Error applying setting, reverse things back
> gpio_stub_drv: probe of gpiochip1 failed with error -22
>
> This happens because when we try to probe a device, driver core calls
> into pinctrl to set up the pins. However, if the GPIO DT node already
> has a proper device created and probed, trying to probe the gpio_device
> with a stub driver makes the pins be claimed twice. pinctrl doesn't like
> this and throws an error.
>
> So, this patch makes sure the gpio_stub_drv doesn't match with a
> gpio_device if it's not the primary device for the fwnode.
>
> [1] - https://lore.kernel.org/lkml/544ad0e4-0954-274c-8e77-866aaa5661a8@gmail.com/
> Fixes: 4731210c09f5 ("gpiolib: Bind gpio_device to a driver to enable fw_devlink=on by default")
> Signed-off-by: Saravana Kannan <saravanak@google.com>
> Tested-by: Dmitry Osipenko <digetx@gmail.com>
> ---
> Greg/Linus,
>
> This will need to go into driver-core because the Fixes is in
> driver-core too.
>
> Thanks,
> Saravana
>
> drivers/gpio/gpiolib.c | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
>
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index 8e0564c50840..8ad679a928b0 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -56,8 +56,10 @@
> static DEFINE_IDA(gpio_ida);
> static dev_t gpio_devt;
> #define GPIO_DEV_MAX 256 /* 256 GPIO chip devices supported */
> +static int gpio_bus_match(struct device *dev, struct device_driver *drv);
> static struct bus_type gpio_bus_type = {
> .name = "gpio",
> + .match = gpio_bus_match,
> };
>
> /*
> @@ -4199,6 +4201,18 @@ void gpiod_put_array(struct gpio_descs *descs)
> }
> EXPORT_SYMBOL_GPL(gpiod_put_array);
>
> +
> +static int gpio_bus_match(struct device *dev, struct device_driver *drv)
> +{
> + /*
> + * Only match if the fwnode doesn't already have a proper struct device
> + * created for it.
> + */
> + if (dev->fwnode && dev->fwnode->dev != dev)
> + return 0;
> + return 1;
> +}
> +
> static int gpio_stub_drv_probe(struct device *dev)
> {
> /*
> --
> 2.30.0.365.g02bc693789-goog
>
Acked-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v1] gpiolib: Don't probe gpio_device if it's not the primary device
2021-02-05 2:07 [PATCH v1] gpiolib: Don't probe gpio_device if it's not the primary device Saravana Kannan
2021-02-05 10:02 ` Bartosz Golaszewski
@ 2021-02-09 12:04 ` Geert Uytterhoeven
2021-02-12 9:37 ` Linus Walleij
2 siblings, 0 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2021-02-09 12:04 UTC (permalink / raw)
To: Saravana Kannan
Cc: Linus Walleij, Bartosz Golaszewski, Greg Kroah-Hartman,
Dmitry Osipenko, Android Kernel Team, open list:GPIO SUBSYSTEM,
Linux Kernel Mailing List, Linux-Renesas
Hi Saravana,
On Fri, Feb 5, 2021 at 3:09 AM Saravana Kannan <saravanak@google.com> wrote:
> Dmitry reported[1] boot error messages caused by
> commit 4731210c09f5 ("gpiolib: Bind gpio_device to a driver to enable fw_devlink=on by default").
>
> gpio-1022 (cpu-pwr-req-hog): hogged as input
> max77620-pinctrl max77620-pinctrl: pin gpio4 already requested by max77620-pinctrl; cannot claim for gpiochip1
> max77620-pinctrl max77620-pinctrl: pin-4 (gpiochip1) status -22
> max77620-pinctrl max77620-pinctrl: could not request pin 4 (gpio4) from group gpio4 on device max77620-pinctrl
> gpio_stub_drv gpiochip1: Error applying setting, reverse things back
> gpio_stub_drv: probe of gpiochip1 failed with error -22
Similar issue on Salvator-XS:
sh-pfc e6060000.pinctrl: pin GP_2_0 already requested by 7-0030;
cannot claim for gpiochip9
sh-pfc e6060000.pinctrl: pin-64 (gpiochip9) status -22
sh-pfc e6060000.pinctrl: could not request pin 64 (GP_2_0) from
group intc_ex_irq0 on device sh-pfc
gpio_stub_drv gpiochip9: Error applying setting, reverse things back
gpio_stub_drv: probe of gpiochip9 failed with error -22
> This happens because when we try to probe a device, driver core calls
> into pinctrl to set up the pins. However, if the GPIO DT node already
> has a proper device created and probed, trying to probe the gpio_device
> with a stub driver makes the pins be claimed twice. pinctrl doesn't like
> this and throws an error.
>
> So, this patch makes sure the gpio_stub_drv doesn't match with a
> gpio_device if it's not the primary device for the fwnode.
>
> [1] - https://lore.kernel.org/lkml/544ad0e4-0954-274c-8e77-866aaa5661a8@gmail.com/
> Fixes: 4731210c09f5 ("gpiolib: Bind gpio_device to a driver to enable fw_devlink=on by default")
> Signed-off-by: Saravana Kannan <saravanak@google.com>
> Tested-by: Dmitry Osipenko <digetx@gmail.com>
Tested-by: Geert Uytterhoeven <geert+renesas@glider.be>
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v1] gpiolib: Don't probe gpio_device if it's not the primary device
2021-02-05 2:07 [PATCH v1] gpiolib: Don't probe gpio_device if it's not the primary device Saravana Kannan
2021-02-05 10:02 ` Bartosz Golaszewski
2021-02-09 12:04 ` Geert Uytterhoeven
@ 2021-02-12 9:37 ` Linus Walleij
2 siblings, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2021-02-12 9:37 UTC (permalink / raw)
To: Saravana Kannan
Cc: Bartosz Golaszewski, Greg Kroah-Hartman, Dmitry Osipenko,
Android Kernel Team, open list:GPIO SUBSYSTEM, linux-kernel
On Fri, Feb 5, 2021 at 3:07 AM Saravana Kannan <saravanak@google.com> wrote:
> Dmitry reported[1] boot error messages caused by
> commit 4731210c09f5 ("gpiolib: Bind gpio_device to a driver to enable fw_devlink=on by default").
>
> gpio-1022 (cpu-pwr-req-hog): hogged as input
> max77620-pinctrl max77620-pinctrl: pin gpio4 already requested by max77620-pinctrl; cannot claim for gpiochip1
> max77620-pinctrl max77620-pinctrl: pin-4 (gpiochip1) status -22
> max77620-pinctrl max77620-pinctrl: could not request pin 4 (gpio4) from group gpio4 on device max77620-pinctrl
> gpio_stub_drv gpiochip1: Error applying setting, reverse things back
> gpio_stub_drv: probe of gpiochip1 failed with error -22
>
> This happens because when we try to probe a device, driver core calls
> into pinctrl to set up the pins. However, if the GPIO DT node already
> has a proper device created and probed, trying to probe the gpio_device
> with a stub driver makes the pins be claimed twice. pinctrl doesn't like
> this and throws an error.
>
> So, this patch makes sure the gpio_stub_drv doesn't match with a
> gpio_device if it's not the primary device for the fwnode.
>
> [1] - https://lore.kernel.org/lkml/544ad0e4-0954-274c-8e77-866aaa5661a8@gmail.com/
> Fixes: 4731210c09f5 ("gpiolib: Bind gpio_device to a driver to enable fw_devlink=on by default")
> Signed-off-by: Saravana Kannan <saravanak@google.com>
> Tested-by: Dmitry Osipenko <digetx@gmail.com>
> ---
> Greg/Linus,
>
> This will need to go into driver-core because the Fixes is in
> driver-core too.
OK that seems to be the right solution. Maybe I would try to
explain the situation in the comment in gpio_bus_match
a bit more, but anyway:
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-02-12 9:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-05 2:07 [PATCH v1] gpiolib: Don't probe gpio_device if it's not the primary device Saravana Kannan
2021-02-05 10:02 ` Bartosz Golaszewski
2021-02-09 12:04 ` Geert Uytterhoeven
2021-02-12 9:37 ` Linus Walleij
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).