diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2022-09-05 12:35:42 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2022-09-13 12:07:55 +0200 |
commit | ca5e915485dfe6651cc42292e27889c96c438bcc (patch) | |
tree | 5a752b3618c91b56311e7e858f77bba0a1cf8137 /drivers | |
parent | 2dc4f905ec49301d76a568697dd7e105fcf149be (diff) | |
download | barebox-ca5e915485dfe6651cc42292e27889c96c438bcc.tar.gz barebox-ca5e915485dfe6651cc42292e27889c96c438bcc.tar.xz |
gpiolib: implement gpio_get_chip_by_dev()
gpio_of_xlate() already needs the ability to find a struct gpio_chip *
via a struct device_d. Exporting this functionality to elsewhere in the
code will allow restricting commands to manipulate only a single GPIO
bank.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Link: https://lore.barebox.org/20220905103546.1476277-2-a.fatoum@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/gpio/gpiolib.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 97a99b84e3..cf61213ca1 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -636,6 +636,18 @@ static int of_gpio_simple_xlate(struct gpio_chip *chip, return chip->base + gpiospec->args[0]; } +struct gpio_chip *gpio_get_chip_by_dev(struct device_d *dev) +{ + struct gpio_chip *chip; + + list_for_each_entry(chip, &chip_list, list) { + if (chip->dev == dev) + return chip; + } + + return NULL; +} + int gpio_of_xlate(struct device_d *dev, struct of_phandle_args *gpiospec, int *flags) { struct gpio_chip *chip; @@ -643,16 +655,14 @@ int gpio_of_xlate(struct device_d *dev, struct of_phandle_args *gpiospec, int *f if (!dev) return -ENODEV; - list_for_each_entry(chip, &chip_list, list) { - if (chip->dev != dev) - continue; - if (chip->ops->of_xlate) - return chip->ops->of_xlate(chip, gpiospec, flags); - else - return of_gpio_simple_xlate(chip, gpiospec, flags); - } + chip = gpio_get_chip_by_dev(dev); + if (!chip) + return -EPROBE_DEFER; - return -EPROBE_DEFER; + if (chip->ops->of_xlate) + return chip->ops->of_xlate(chip, gpiospec, flags); + else + return of_gpio_simple_xlate(chip, gpiospec, flags); } struct gpio_chip *gpio_get_chip(int gpio) |