Re: [PATCH RFC v8 6/8] gpiolib: add gpio_device_get_fwnode() helper
From: Bartosz Golaszewski
Date: Tue Aug 11 2026 - 04:00:15 EST
On Mon, 10 Aug 2026 15:04:29 +0200, Miao Wang via B4 Relay
<devnull+shankerwangmiao.gmail.com@xxxxxxxxxx> said:
> From: Miao Wang <shankerwangmiao@xxxxxxxxx>
>
> 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 <shankerwangmiao@xxxxxxxxx>
> ---
> 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.
> + */
Please extend the kernel doc to also say that the call does not bump the
reference count of the firmware node as the caller already holds a reference
to the GPIO device that owns it so no call to fwnode_handle_put() is required.
With that:
Acked-by: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxxxxxxxx>
And it can go through the MFD tree.
Thanks,
Bartosz
> +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
>
>
>