Skip to content

Commit 159c156

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: [email protected] Signed-off-by: Hans de Goede <[email protected]> Reviewed-by: Dmitry Torokhov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Bartosz Golaszewski <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent ca988dc commit 159c156

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
@@ -4317,6 +4317,23 @@ static struct gpio_desc *gpiod_find_by_fwnode(struct fwnode_handle *fwnode,
43174317
return desc;
43184318
}
43194319

4320+
static struct gpio_desc *gpiod_fwnode_lookup(struct fwnode_handle *fwnode,
4321+
struct device *consumer,
4322+
const char *con_id,
4323+
unsigned int idx,
4324+
enum gpiod_flags *flags,
4325+
unsigned long *lookupflags)
4326+
{
4327+
struct gpio_desc *desc;
4328+
4329+
desc = gpiod_find_by_fwnode(fwnode, consumer, con_id, idx, flags, lookupflags);
4330+
if (gpiod_not_found(desc) && !IS_ERR_OR_NULL(fwnode))
4331+
desc = gpiod_find_by_fwnode(fwnode->secondary, consumer, con_id,
4332+
idx, flags, lookupflags);
4333+
4334+
return desc;
4335+
}
4336+
43204337
struct gpio_desc *gpiod_find_and_request(struct device *consumer,
43214338
struct fwnode_handle *fwnode,
43224339
const char *con_id,
@@ -4335,8 +4352,8 @@ struct gpio_desc *gpiod_find_and_request(struct device *consumer,
43354352
int ret = 0;
43364353

43374354
scoped_guard(srcu, &gpio_devices_srcu) {
4338-
desc = gpiod_find_by_fwnode(fwnode, consumer, con_id, idx,
4339-
&flags, &lookupflags);
4355+
desc = gpiod_fwnode_lookup(fwnode, consumer, con_id, idx,
4356+
&flags, &lookupflags);
43404357
if (gpiod_not_found(desc) && platform_lookup_allowed) {
43414358
/*
43424359
* Either we are not using DT or ACPI, or their lookup

0 commit comments

Comments
 (0)