Skip to content

Commit 668706b

Browse files
andy-shevBartosz Golaszewski
authored andcommitted
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 <[email protected]> Tested-by: Dipen Patel <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Andy Shevchenko <[email protected]> Signed-off-by: Bartosz Golaszewski <[email protected]>
1 parent 74975b4 commit 668706b

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

drivers/gpio/gpiolib.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,26 @@ struct gpio_device *gpio_device_find_by_label(const char *label)
11451145
}
11461146
EXPORT_SYMBOL_GPL(gpio_device_find_by_label);
11471147

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+
11481168
/**
11491169
* gpio_device_get() - Increase the reference count of this GPIO device
11501170
* @gdev: GPIO device to increase the refcount for

include/linux/gpio/driver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,7 @@ struct gpio_chip *gpiochip_find(void *data,
611611
struct gpio_device *gpio_device_find(void *data,
612612
int (*match)(struct gpio_chip *gc, void *data));
613613
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);
614615

615616
struct gpio_device *gpio_device_get(struct gpio_device *gdev);
616617
void gpio_device_put(struct gpio_device *gdev);

0 commit comments

Comments
 (0)