Skip to content

Commit ced2af4

Browse files
Saravana Kannangregkh
authored andcommitted
gpiolib: Don't probe gpio_device if it's not the primary device
Dmitry reported[1] boot error messages caused by commit 4731210 ("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: 4731210 ("gpiolib: Bind gpio_device to a driver to enable fw_devlink=on by default") Tested-by: Dmitry Osipenko <digetx@gmail.com> Tested-by: Geert Uytterhoeven <geert+renesas@glider.be> Acked-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Signed-off-by: Saravana Kannan <saravanak@google.com> Link: https://lore.kernel.org/r/20210205020730.1746354-1-saravanak@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 5c3db63 commit ced2af4

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

‎drivers/gpio/gpiolib.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@
5656
static DEFINE_IDA(gpio_ida);
5757
static dev_t gpio_devt;
5858
#define GPIO_DEV_MAX 256 /* 256 GPIO chip devices supported */
59+
static int gpio_bus_match(struct device *dev, struct device_driver *drv);
5960
static struct bus_type gpio_bus_type = {
6061
.name = "gpio",
62+
.match = gpio_bus_match,
6163
};
6264

6365
/*
@@ -4199,6 +4201,18 @@ void gpiod_put_array(struct gpio_descs *descs)
41994201
}
42004202
EXPORT_SYMBOL_GPL(gpiod_put_array);
42014203

4204+
4205+
static int gpio_bus_match(struct device *dev, struct device_driver *drv)
4206+
{
4207+
/*
4208+
* Only match if the fwnode doesn't already have a proper struct device
4209+
* created for it.
4210+
*/
4211+
if (dev->fwnode && dev->fwnode->dev != dev)
4212+
return 0;
4213+
return 1;
4214+
}
4215+
42024216
static int gpio_stub_drv_probe(struct device *dev)
42034217
{
42044218
/*

0 commit comments

Comments
 (0)