Re: [PATCH RFC v8 6/8] gpiolib: add gpio_device_get_fwnode() helper
Bartosz Golaszewski <[email protected]>
| Newsgroups | dev.linux.lists.mfd,org.kernel.vger.linux-gpio,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <CAMRc=Mc7+kXwHcYtcF9jgmAzSGF+wydOnsvA7Hby0KxhAL2YUA@mail.gmail.com> |
On Mon, 10 Aug 2026 15:04:29 +0200, Miao Wang via B4 Relay <[email protected]> said: > From: Miao Wang <[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. > + */ 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 <[email protected]> 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 > > >