Hi,
On 15-Sep-25 3:21 AM, Dmitry Torokhov wrote:
Hi Hans,
On Sat, Sep 13, 2025 at 08:43:09PM +0200, Hans de Goede wrote:
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 check to gpiod_find_by_fwnode() to try a software-node lookup on the secondary fwnode if the GPIO was not found in the primary fwnode.
Thanks for catching this. I think it would be better if we added handling of the secondary node to gpiod_find_and_request(). This way the fallback will work for all kind of combinations, even if secondary node happens to be an OF or ACPI one.
IOW something like this:
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index b619fea498c8..1a3b5ca00554 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -4630,6 +4630,13 @@ struct gpio_desc *gpiod_find_and_request(struct device *consumer, scoped_guard(srcu, &gpio_devices_srcu) { desc = gpiod_find_by_fwnode(fwnode, consumer, con_id, idx, &flags, &lookupflags); + + if (gpiod_not_found(desc) && fwnode) { + dev_dbg(consumer, "trying secondary fwnode for GPIO lookup\n"); + desc = gpiod_find_by_fwnode(fwnode->secondary, consumer, + con_id, idx, &flags, &lookupflags); + } + if (gpiod_not_found(desc) && platform_lookup_allowed) { /* * Either we are not using DT or ACPI, or their lookup
That should work too, but if there is an OF or ACPI node it should always be the primary one. So my original patch id fine as is.
Either way works for me. If you prefer the above approach instead of my original patch let me know and I'll give it a test-run and then post a v2.
Regards,
Hans