All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hans de Goede <hansg@kernel.org>
To: Mika Westerberg <westeri@kernel.org>,
	Andy Shevchenko <andy@kernel.org>,
	Bartosz Golaszewski <brgl@bgdev.pl>,
	Linus Walleij <linus.walleij@linaro.org>
Cc: Hans de Goede <hansg@kernel.org>,
	linux-gpio@vger.kernel.org, stable@vger.kernel.org,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>
Subject: [PATCH] gpiolib: Extend software-node support to support secondary software-nodes
Date: Sat, 13 Sep 2025 20:43:09 +0200	[thread overview]
Message-ID: <20250913184309.81881-1-hansg@kernel.org> (raw)

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.

Fixes: e7f9ff5dc90c ("gpiolib: add support for software nodes")
Cc: stable@vger.kernel.org
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Hans de Goede <hansg@kernel.org>
---
I found this issue while testing "platform/x86: x86-android-tablets:
convert wm1502 devices to GPIO references":
https://lore.kernel.org/platform-driver-x86/20250810-x86-andoroid-tablet-v2-7-9c7a1b3c32b2@gmail.com/
which adds a software node with GPIO lookup info the a spi-10WM5102:00
device which has an ACPI fwnode as primary fwnode.
---
 drivers/gpio/gpiolib.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 0d2b470a252e..b619fea498c8 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -4601,6 +4601,12 @@ static struct gpio_desc *gpiod_find_by_fwnode(struct fwnode_handle *fwnode,
 		desc = swnode_find_gpio(fwnode, con_id, idx, lookupflags);
 	}
 
+	if (desc == ERR_PTR(-ENOENT) && fwnode && is_software_node(fwnode->secondary)) {
+		dev_dbg(consumer, "using secondary-swnode '%pfw' for '%s' GPIO lookup\n",
+			fwnode->secondary, name);
+		desc = swnode_find_gpio(fwnode->secondary, con_id, idx, lookupflags);
+	}
+
 	return desc;
 }
 
-- 
2.51.0


             reply	other threads:[~2025-09-13 18:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-13 18:43 Hans de Goede [this message]
2025-09-14 13:34 ` [PATCH] gpiolib: Extend software-node support to support secondary software-nodes Andy Shevchenko
2025-09-14 13:37   ` Andy Shevchenko
2025-09-15  1:21 ` Dmitry Torokhov
2025-09-15 17:49   ` Hans de Goede
2025-09-16  8:01     ` Andy Shevchenko
2025-09-16  9:31     ` Bartosz Golaszewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250913184309.81881-1-hansg@kernel.org \
    --to=hansg@kernel.org \
    --cc=andy@kernel.org \
    --cc=brgl@bgdev.pl \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=westeri@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.