Skip to content

Commit 61ae3a5

Browse files
Hans de Goedegregkh
authored andcommitted
gpiolib: Extend software-node support to support secondary software-nodes
commit c6ccc4d upstream. When a software-node gets added to a device which already has another fwnode as primary node it will become the secondary fwnode for that device. Currently if a software-node with GPIO properties ends up as the secondary fwnode then gpiod_find_by_fwnode() will fail to find the GPIOs. Add a new gpiod_fwnode_lookup() helper which falls back to calling gpiod_find_by_fwnode() with the secondary fwnode if the GPIO was not found in the primary fwnode. Fixes: e7f9ff5 ("gpiolib: add support for software nodes") Cc: stable@vger.kernel.org Signed-off-by: Hans de Goede <hansg@kernel.org> Reviewed-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Link: https://lore.kernel.org/r/20250920200955.20403-1-hansg@kernel.org Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a2cb881 commit 61ae3a5

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

drivers/gpio/gpiolib.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4605,6 +4605,23 @@ static struct gpio_desc *gpiod_find_by_fwnode(struct fwnode_handle *fwnode,
46054605
return desc;
46064606
}
46074607

4608+
static struct gpio_desc *gpiod_fwnode_lookup(struct fwnode_handle *fwnode,
4609+
struct device *consumer,
4610+
const char *con_id,
4611+
unsigned int idx,
4612+
enum gpiod_flags *flags,
4613+
unsigned long *lookupflags)
4614+
{
4615+
struct gpio_desc *desc;
4616+
4617+
desc = gpiod_find_by_fwnode(fwnode, consumer, con_id, idx, flags, lookupflags);
4618+
if (gpiod_not_found(desc) && !IS_ERR_OR_NULL(fwnode))
4619+
desc = gpiod_find_by_fwnode(fwnode->secondary, consumer, con_id,
4620+
idx, flags, lookupflags);
4621+
4622+
return desc;
4623+
}
4624+
46084625
struct gpio_desc *gpiod_find_and_request(struct device *consumer,
46094626
struct fwnode_handle *fwnode,
46104627
const char *con_id,
@@ -4623,8 +4640,8 @@ struct gpio_desc *gpiod_find_and_request(struct device *consumer,
46234640
int ret = 0;
46244641

46254642
scoped_guard(srcu, &gpio_devices_srcu) {
4626-
desc = gpiod_find_by_fwnode(fwnode, consumer, con_id, idx,
4627-
&flags, &lookupflags);
4643+
desc = gpiod_fwnode_lookup(fwnode, consumer, con_id, idx,
4644+
&flags, &lookupflags);
46284645
if (gpiod_not_found(desc) && platform_lookup_allowed) {
46294646
/*
46304647
* Either we are not using DT or ACPI, or their lookup

0 commit comments

Comments
 (0)