[PATCH RFC v7 7/8] gpiolib: add gpio_device_get_fwnode() helper
Miao Wang <[email protected]>
| Newsgroups | org.kernel.feeds.b4-sent,dev.linux.lists.mfd,org.kernel.vger.linux-gpio,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
Add a helper function to retrieve the fwnode associated with a struct gpio_device. This is useful for drivers that need to access the fwnode of a GPIO device for various purposes, such as creating software nodes or handling GPIOs in a platform-specific manner. Signed-off-by: Miao Wang <[email protected]> --- drivers/gpio/gpiolib.c | 13 +++++++++++++ include/linux/gpio/driver.h | 1 + 2 files changed, 14 insertions(+) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index e5fb60111151f6de20b424551acf213fb058e190..3774ebbbe550cdce0989a2d06f2ab658529c3bab 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1583,6 +1583,19 @@ struct device *gpio_device_to_device(struct gpio_device *gdev) } EXPORT_SYMBOL_GPL(gpio_device_to_device); +/** + * gpio_device_get_fwnode() - Retrieve the fwnode of the underlying device. + * @gdev: GPIO device for which to return the fwnode. + * + * Returns: + * The fwnode handle of the underlying device. + */ +struct fwnode_handle *gpio_device_get_fwnode(struct gpio_device *gdev) +{ + return dev_fwnode(gpio_device_to_device(gdev)); +} +EXPORT_SYMBOL_GPL(gpio_device_get_fwnode); + #ifdef CONFIG_GPIOLIB_IRQCHIP /* diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index 17511434ed077dde8807bd7630c342e146e5230b..4dd9120707ec72a978f5f916cc5473a91b65d2b9 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -641,6 +641,7 @@ DEFINE_FREE(gpio_device_put, struct gpio_device *, if (!IS_ERR_OR_NULL(_T)) gpio_device_put(_T)) struct device *gpio_device_to_device(struct gpio_device *gdev); +struct fwnode_handle *gpio_device_get_fwnode(struct gpio_device *gdev); bool gpiochip_line_is_irq(struct gpio_chip *gc, unsigned int offset); int gpiochip_reqres_irq(struct gpio_chip *gc, unsigned int offset); -- 2.49.0