* [PATCH 1/2] gpiolib: introduce devm_fwnode_gpiod_get_optional() wrapper
2026-01-23 9:51 [PATCH 0/2] gpiolib: introduce devm_fwnode_gpiod_get_optional Michael Tretter
@ 2026-01-23 9:51 ` Michael Tretter
2026-01-26 7:17 ` Matti Vaittinen
2026-01-23 9:51 ` [PATCH 2/2] regulator: bd71815: switch to devm_fwnode_gpiod_get_optional Michael Tretter
2026-01-26 13:50 ` [PATCH 0/2] gpiolib: introduce devm_fwnode_gpiod_get_optional Bartosz Golaszewski
2 siblings, 1 reply; 12+ messages in thread
From: Michael Tretter @ 2026-01-23 9:51 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Matti Vaittinen,
Liam Girdwood, Mark Brown
Cc: linux-gpio, kernel, Michael Tretter, Stefan Kerkmann
From: Stefan Kerkmann <s.kerkmann@pengutronix.de>
The helper makes it easier to handle optional GPIOs and simplifies the
error handling code.
Signed-off-by: Stefan Kerkmann <s.kerkmann@pengutronix.de>
Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
---
include/linux/gpio/consumer.h | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
index cafeb7a40ad1..9328b67e26c0 100644
--- a/include/linux/gpio/consumer.h
+++ b/include/linux/gpio/consumer.h
@@ -607,6 +607,23 @@ struct gpio_desc *devm_fwnode_gpiod_get(struct device *dev,
flags, label);
}
+static inline
+struct gpio_desc *devm_fwnode_gpiod_get_optional(struct device *dev,
+ struct fwnode_handle *fwnode,
+ const char *con_id,
+ enum gpiod_flags flags,
+ const char *label)
+{
+ struct gpio_desc *desc;
+
+ desc = devm_fwnode_gpiod_get_index(dev, fwnode, con_id, 0,
+ flags, label);
+ if (IS_ERR(desc) && PTR_ERR(desc) == -ENOENT)
+ return NULL;
+
+ return desc;
+}
+
struct acpi_gpio_params {
unsigned int crs_entry_index;
unsigned short line_index;
--
2.47.3
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH 1/2] gpiolib: introduce devm_fwnode_gpiod_get_optional() wrapper
2026-01-23 9:51 ` [PATCH 1/2] gpiolib: introduce devm_fwnode_gpiod_get_optional() wrapper Michael Tretter
@ 2026-01-26 7:17 ` Matti Vaittinen
0 siblings, 0 replies; 12+ messages in thread
From: Matti Vaittinen @ 2026-01-26 7:17 UTC (permalink / raw)
To: Michael Tretter, Linus Walleij, Bartosz Golaszewski,
Liam Girdwood, Mark Brown
Cc: linux-gpio, kernel, Stefan Kerkmann
On 23/01/2026 11:51, Michael Tretter wrote:
> From: Stefan Kerkmann <s.kerkmann@pengutronix.de>
>
> The helper makes it easier to handle optional GPIOs and simplifies the
> error handling code.
>
> Signed-off-by: Stefan Kerkmann <s.kerkmann@pengutronix.de>
> Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
> ---
> include/linux/gpio/consumer.h | 17 +++++++++++++++++
> 1 file changed, 17 insertions(+)
>
> diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
> index cafeb7a40ad1..9328b67e26c0 100644
> --- a/include/linux/gpio/consumer.h
> +++ b/include/linux/gpio/consumer.h
> @@ -607,6 +607,23 @@ struct gpio_desc *devm_fwnode_gpiod_get(struct device *dev,
> flags, label);
> }
>
> +static inline
> +struct gpio_desc *devm_fwnode_gpiod_get_optional(struct device *dev,
> + struct fwnode_handle *fwnode,
> + const char *con_id,
> + enum gpiod_flags flags,
> + const char *label)
I would like to see the kerneldoc for this. Other than that, it looks
great to me.
> +{
> + struct gpio_desc *desc;
> +
> + desc = devm_fwnode_gpiod_get_index(dev, fwnode, con_id, 0,
> + flags, label);
> + if (IS_ERR(desc) && PTR_ERR(desc) == -ENOENT)
> + return NULL;
> +
> + return desc;
> +}
> +
> struct acpi_gpio_params {
> unsigned int crs_entry_index;
> unsigned short line_index;
>
Yours,
-- Matti
--
---
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland
~~ When things go utterly wrong vim users can always type :help! ~~
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 2/2] regulator: bd71815: switch to devm_fwnode_gpiod_get_optional
2026-01-23 9:51 [PATCH 0/2] gpiolib: introduce devm_fwnode_gpiod_get_optional Michael Tretter
2026-01-23 9:51 ` [PATCH 1/2] gpiolib: introduce devm_fwnode_gpiod_get_optional() wrapper Michael Tretter
@ 2026-01-23 9:51 ` Michael Tretter
2026-01-26 7:18 ` Matti Vaittinen
2026-01-26 12:08 ` Mark Brown
2026-01-26 13:50 ` [PATCH 0/2] gpiolib: introduce devm_fwnode_gpiod_get_optional Bartosz Golaszewski
2 siblings, 2 replies; 12+ messages in thread
From: Michael Tretter @ 2026-01-23 9:51 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski, Matti Vaittinen,
Liam Girdwood, Mark Brown
Cc: linux-gpio, kernel, Michael Tretter
Use the devm_fwnode_gpiod_get_optional variant to simplify the error
handling code.
Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
---
drivers/regulator/bd71815-regulator.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/drivers/regulator/bd71815-regulator.c b/drivers/regulator/bd71815-regulator.c
index 8da57a7bb2f1..668714f35464 100644
--- a/drivers/regulator/bd71815-regulator.c
+++ b/drivers/regulator/bd71815-regulator.c
@@ -571,15 +571,12 @@ static int bd7181x_probe(struct platform_device *pdev)
return -ENODEV;
}
- ldo4_en = devm_fwnode_gpiod_get(&pdev->dev,
- dev_fwnode(pdev->dev.parent),
- "rohm,vsel", GPIOD_ASIS, "ldo4-en");
- if (IS_ERR(ldo4_en)) {
- ret = PTR_ERR(ldo4_en);
- if (ret != -ENOENT)
- return ret;
- ldo4_en = NULL;
- }
+ ldo4_en = devm_fwnode_gpiod_get_optional(&pdev->dev,
+ dev_fwnode(pdev->dev.parent),
+ "rohm,vsel", GPIOD_ASIS,
+ "ldo4-en");
+ if (IS_ERR(ldo4_en))
+ return PTR_ERR(ldo4_en);
/* Disable to go to ship-mode */
ret = regmap_update_bits(regmap, BD71815_REG_PWRCTRL, RESTARTEN, 0);
--
2.47.3
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [PATCH 2/2] regulator: bd71815: switch to devm_fwnode_gpiod_get_optional
2026-01-23 9:51 ` [PATCH 2/2] regulator: bd71815: switch to devm_fwnode_gpiod_get_optional Michael Tretter
@ 2026-01-26 7:18 ` Matti Vaittinen
2026-01-26 12:08 ` Mark Brown
1 sibling, 0 replies; 12+ messages in thread
From: Matti Vaittinen @ 2026-01-26 7:18 UTC (permalink / raw)
To: Michael Tretter, Linus Walleij, Bartosz Golaszewski,
Liam Girdwood, Mark Brown
Cc: linux-gpio, kernel
On 23/01/2026 11:51, Michael Tretter wrote:
> Use the devm_fwnode_gpiod_get_optional variant to simplify the error
> handling code.
>
> Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
Thanks!
Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com>
Yours,
-- Matti
---
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland
~~ When things go utterly wrong vim users can always type :help! ~~
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/2] regulator: bd71815: switch to devm_fwnode_gpiod_get_optional
2026-01-23 9:51 ` [PATCH 2/2] regulator: bd71815: switch to devm_fwnode_gpiod_get_optional Michael Tretter
2026-01-26 7:18 ` Matti Vaittinen
@ 2026-01-26 12:08 ` Mark Brown
1 sibling, 0 replies; 12+ messages in thread
From: Mark Brown @ 2026-01-26 12:08 UTC (permalink / raw)
To: Michael Tretter
Cc: Linus Walleij, Bartosz Golaszewski, Matti Vaittinen,
Liam Girdwood, linux-gpio, kernel
[-- Attachment #1: Type: text/plain, Size: 196 bytes --]
On Fri, Jan 23, 2026 at 10:51:06AM +0100, Michael Tretter wrote:
> Use the devm_fwnode_gpiod_get_optional variant to simplify the error
> handling code.
Acked-by: Mark Brown <broonie@kernel.org>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 0/2] gpiolib: introduce devm_fwnode_gpiod_get_optional
2026-01-23 9:51 [PATCH 0/2] gpiolib: introduce devm_fwnode_gpiod_get_optional Michael Tretter
2026-01-23 9:51 ` [PATCH 1/2] gpiolib: introduce devm_fwnode_gpiod_get_optional() wrapper Michael Tretter
2026-01-23 9:51 ` [PATCH 2/2] regulator: bd71815: switch to devm_fwnode_gpiod_get_optional Michael Tretter
@ 2026-01-26 13:50 ` Bartosz Golaszewski
2026-01-26 14:01 ` Mark Brown
2026-01-26 14:30 ` Michael Tretter
2 siblings, 2 replies; 12+ messages in thread
From: Bartosz Golaszewski @ 2026-01-26 13:50 UTC (permalink / raw)
To: Michael Tretter
Cc: Linus Walleij, Matti Vaittinen, Liam Girdwood, Mark Brown,
linux-gpio, kernel, Stefan Kerkmann
On Fri, Jan 23, 2026 at 10:51 AM Michael Tretter
<m.tretter@pengutronix.de> wrote:
>
> There are various helpers to simplify the handling of optional gpios.
> The devm_fwnode_gpiod_get() lacks the _optional variant, and drivers
> have to explicitly handle the error for optional gpios.
>
> Introduce a devm_fwnode_gpiod_get_optional helper and simplify the
> BD71815 voltage regulator driver by using this helper.
>
> Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
> ---
> Michael Tretter (1):
> regulator: bd71815: switch to devm_fwnode_gpiod_get_optional
>
> Stefan Kerkmann (1):
> gpiolib: introduce devm_fwnode_gpiod_get_optional() wrapper
>
> drivers/regulator/bd71815-regulator.c | 15 ++++++---------
> include/linux/gpio/consumer.h | 17 +++++++++++++++++
> 2 files changed, 23 insertions(+), 9 deletions(-)
> ---
> base-commit: c072629f05d7bca1148ab17690d7922a31423984
> change-id: 20260123-gpio-devm_fwnode_gpiod_get_optional-e96227cd393b
>
> Best regards,
> --
> Michael Tretter <m.tretter@pengutronix.de>
>
If you can send a v2 with added kerneldoc, I can queue this up for
v7.0 and Mark can then queue patch 2 in the next cycle. Unless it's
urgent, let me know if it is.
Bart
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 0/2] gpiolib: introduce devm_fwnode_gpiod_get_optional
2026-01-26 13:50 ` [PATCH 0/2] gpiolib: introduce devm_fwnode_gpiod_get_optional Bartosz Golaszewski
@ 2026-01-26 14:01 ` Mark Brown
2026-01-26 15:14 ` Bartosz Golaszewski
2026-01-26 14:30 ` Michael Tretter
1 sibling, 1 reply; 12+ messages in thread
From: Mark Brown @ 2026-01-26 14:01 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Michael Tretter, Linus Walleij, Matti Vaittinen, Liam Girdwood,
linux-gpio, kernel, Stefan Kerkmann
[-- Attachment #1: Type: text/plain, Size: 295 bytes --]
On Mon, Jan 26, 2026 at 02:50:27PM +0100, Bartosz Golaszewski wrote:
> If you can send a v2 with added kerneldoc, I can queue this up for
> v7.0 and Mark can then queue patch 2 in the next cycle. Unless it's
> urgent, let me know if it is.
I'm happy for you to just apply patch 2 if you want.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 0/2] gpiolib: introduce devm_fwnode_gpiod_get_optional
2026-01-26 14:01 ` Mark Brown
@ 2026-01-26 15:14 ` Bartosz Golaszewski
2026-01-26 15:20 ` Mark Brown
0 siblings, 1 reply; 12+ messages in thread
From: Bartosz Golaszewski @ 2026-01-26 15:14 UTC (permalink / raw)
To: Mark Brown
Cc: Michael Tretter, Linus Walleij, Matti Vaittinen, Liam Girdwood,
linux-gpio, kernel, Stefan Kerkmann
On Mon, Jan 26, 2026 at 3:01 PM Mark Brown <broonie@kernel.org> wrote:
>
> On Mon, Jan 26, 2026 at 02:50:27PM +0100, Bartosz Golaszewski wrote:
>
> > If you can send a v2 with added kerneldoc, I can queue this up for
> > v7.0 and Mark can then queue patch 2 in the next cycle. Unless it's
> > urgent, let me know if it is.
>
> I'm happy for you to just apply patch 2 if you want.
Sure, just please leave your Ack under v2.
Bart
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 0/2] gpiolib: introduce devm_fwnode_gpiod_get_optional
2026-01-26 15:14 ` Bartosz Golaszewski
@ 2026-01-26 15:20 ` Mark Brown
2026-01-27 9:13 ` Bartosz Golaszewski
0 siblings, 1 reply; 12+ messages in thread
From: Mark Brown @ 2026-01-26 15:20 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Michael Tretter, Linus Walleij, Matti Vaittinen, Liam Girdwood,
linux-gpio, kernel, Stefan Kerkmann
[-- Attachment #1: Type: text/plain, Size: 304 bytes --]
On Mon, Jan 26, 2026 at 04:14:14PM +0100, Bartosz Golaszewski wrote:
> On Mon, Jan 26, 2026 at 3:01 PM Mark Brown <broonie@kernel.org> wrote:
> > I'm happy for you to just apply patch 2 if you want.
> Sure, just please leave your Ack under v2.
I think he carried it forward from v1 already?
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 0/2] gpiolib: introduce devm_fwnode_gpiod_get_optional
2026-01-26 15:20 ` Mark Brown
@ 2026-01-27 9:13 ` Bartosz Golaszewski
0 siblings, 0 replies; 12+ messages in thread
From: Bartosz Golaszewski @ 2026-01-27 9:13 UTC (permalink / raw)
To: Mark Brown
Cc: Michael Tretter, Linus Walleij, Matti Vaittinen, Liam Girdwood,
linux-gpio, kernel, Stefan Kerkmann
On Mon, Jan 26, 2026 at 4:20 PM Mark Brown <broonie@kernel.org> wrote:
>
> On Mon, Jan 26, 2026 at 04:14:14PM +0100, Bartosz Golaszewski wrote:
> > On Mon, Jan 26, 2026 at 3:01 PM Mark Brown <broonie@kernel.org> wrote:
>
> > > I'm happy for you to just apply patch 2 if you want.
>
> > Sure, just please leave your Ack under v2.
>
> I think he carried it forward from v1 already?
Indeed. Thanks.
Bart
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 0/2] gpiolib: introduce devm_fwnode_gpiod_get_optional
2026-01-26 13:50 ` [PATCH 0/2] gpiolib: introduce devm_fwnode_gpiod_get_optional Bartosz Golaszewski
2026-01-26 14:01 ` Mark Brown
@ 2026-01-26 14:30 ` Michael Tretter
1 sibling, 0 replies; 12+ messages in thread
From: Michael Tretter @ 2026-01-26 14:30 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Linus Walleij, Matti Vaittinen, Liam Girdwood, Mark Brown,
linux-gpio, kernel, Stefan Kerkmann
On Mon, 26 Jan 2026 14:50:27 +0100, Bartosz Golaszewski wrote:
> On Fri, Jan 23, 2026 at 10:51 AM Michael Tretter
> <m.tretter@pengutronix.de> wrote:
> >
> > There are various helpers to simplify the handling of optional gpios.
> > The devm_fwnode_gpiod_get() lacks the _optional variant, and drivers
> > have to explicitly handle the error for optional gpios.
> >
> > Introduce a devm_fwnode_gpiod_get_optional helper and simplify the
> > BD71815 voltage regulator driver by using this helper.
> >
> > Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
> > ---
> > Michael Tretter (1):
> > regulator: bd71815: switch to devm_fwnode_gpiod_get_optional
> >
> > Stefan Kerkmann (1):
> > gpiolib: introduce devm_fwnode_gpiod_get_optional() wrapper
> >
> > drivers/regulator/bd71815-regulator.c | 15 ++++++---------
> > include/linux/gpio/consumer.h | 17 +++++++++++++++++
> > 2 files changed, 23 insertions(+), 9 deletions(-)
> > ---
> > base-commit: c072629f05d7bca1148ab17690d7922a31423984
> > change-id: 20260123-gpio-devm_fwnode_gpiod_get_optional-e96227cd393b
> >
> > Best regards,
> > --
> > Michael Tretter <m.tretter@pengutronix.de>
> >
>
> If you can send a v2 with added kerneldoc, I can queue this up for
> v7.0 and Mark can then queue patch 2 in the next cycle. Unless it's
> urgent, let me know if it is.
The patch isn't urgent. I just sent v2 with added kerneldoc, anyway.
Thanks!
Michael
^ permalink raw reply [flat|nested] 12+ messages in thread