Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

gpiolib: provide gpio_device_find_by_fwnode()

One of the ways of looking up GPIO devices is using their fwnode.
Provide a helper for that to avoid every user implementing their
own matching function.

Reviewed-by: Dipen Patel <dipenp@nvidia.com>
Tested-by: Dipen Patel <dipenp@nvidia.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/20231010151709.4104747-2-andriy.shevchenko@linux.intel.com
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

authored by

Andy Shevchenko and committed by
Bartosz Golaszewski
668706b1 74975b4f

+21
+20
drivers/gpio/gpiolib.c
··· 1145 1145 } 1146 1146 EXPORT_SYMBOL_GPL(gpio_device_find_by_label); 1147 1147 1148 + static int gpio_chip_match_by_fwnode(struct gpio_chip *gc, void *fwnode) 1149 + { 1150 + return device_match_fwnode(&gc->gpiodev->dev, fwnode); 1151 + } 1152 + 1153 + /** 1154 + * gpio_device_find_by_fwnode() - wrapper around gpio_device_find() finding 1155 + * the GPIO device by its fwnode 1156 + * @fwnode: Firmware node to lookup 1157 + * 1158 + * Returns: 1159 + * Reference to the GPIO device or NULL. Reference must be released with 1160 + * gpio_device_put(). 1161 + */ 1162 + struct gpio_device *gpio_device_find_by_fwnode(const struct fwnode_handle *fwnode) 1163 + { 1164 + return gpio_device_find((void *)fwnode, gpio_chip_match_by_fwnode); 1165 + } 1166 + EXPORT_SYMBOL_GPL(gpio_device_find_by_fwnode); 1167 + 1148 1168 /** 1149 1169 * gpio_device_get() - Increase the reference count of this GPIO device 1150 1170 * @gdev: GPIO device to increase the refcount for
+1
include/linux/gpio/driver.h
··· 611 611 struct gpio_device *gpio_device_find(void *data, 612 612 int (*match)(struct gpio_chip *gc, void *data)); 613 613 struct gpio_device *gpio_device_find_by_label(const char *label); 614 + struct gpio_device *gpio_device_find_by_fwnode(const struct fwnode_handle *fwnode); 614 615 615 616 struct gpio_device *gpio_device_get(struct gpio_device *gdev); 616 617 void gpio_device_put(struct gpio_device *gdev);