public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] software node: allow referencing software nodes by name
@ 2026-03-24  4:46 Dmitry Torokhov
  2026-03-24  7:59 ` Greg Kroah-Hartman
  2026-03-24  9:46 ` Bartosz Golaszewski
  0 siblings, 2 replies; 16+ messages in thread
From: Dmitry Torokhov @ 2026-03-24  4:46 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Andy Shevchenko, Daniel Scally, Heikki Krogerus, Sakari Ailus,
	Bartosz Golaszewski, Greg Kroah-Hartman, Danilo Krummrich,
	Rafael J. Wysocki, linux-acpi, driver-core, linux-kernel

Currently static device properties references require either an
instance of software node or an instance of fwnode_handle to be
available when defining a reference property. This may not be very
convenient when device node is instantiated from a different module
(which is usually the case).

The original implementation for describing GPIOs using software nodes
worked around this by creating a detached from gpiochip instances
software nodes, and performing matching using gpiochip label and node
name. The gpiolib maintainers rightfully questioned this approach, and
currently recommend to attach secondary software node to gpiochip
instance, export the symbol, and use it in board file when instantiating
static properties. This unfortunately results in tight coupling between
gpiochip drivers and board code, necessitates creation of header files,
requires adding Kconfig dependencies, limits options for choosing module
vs built-in compilation, and alters device initialization/probing order.

Solve the issue by providing an option to use software node name in
place of the node instance when describing reference properties. When
evaluating reference driver core will attempt to resolve the name to
concrete node instance and, in case of GPIO references, will use
identity match on firmware node to locate corresponding gpiochip device.

This approach has a drawback of needing to know name of the node that
gpiochip device will be using, however benefits (minimal coupling, no
need for adding dependencies) outweigh this drawback.

To deal cases with software nodes not being created or registered at
time of look up, assume that the node with matching name will get
registered eventually and return -EPROBE_DEFER in the meantime.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/base/swnode.c    | 25 +++++++++++++++++++------
 include/linux/property.h |  4 ++++
 2 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
index 51320837f3a9..9903f252d1d6 100644
--- a/drivers/base/swnode.c
+++ b/drivers/base/swnode.c
@@ -510,7 +510,6 @@ software_node_get_reference_args(const struct fwnode_handle *fwnode,
 	const struct software_node_ref_args *ref_array;
 	const struct software_node_ref_args *ref;
 	const struct property_entry *prop;
-	struct fwnode_handle *refnode;
 	u32 nargs_prop_val;
 	int error;
 	int i;
@@ -546,12 +545,26 @@ software_node_get_reference_args(const struct fwnode_handle *fwnode,
 	 * relevant properties and bump the reference count.
 	 */
 
-	if (ref->swnode)
-		refnode = software_node_fwnode(ref->swnode);
-	else if (ref->fwnode)
-		refnode = ref->fwnode;
-	else
+	struct fwnode_handle *refnode __free(fwnode_handle) = NULL;
+	if (ref->swnode) {
+		refnode = fwnode_handle_get(software_node_fwnode(ref->swnode));
+	} else if (ref->fwnode) {
+		refnode = fwnode_handle_get(ref->fwnode);
+	} else if (ref->swnode_name) {
+		const struct software_node *ref_swnode =
+			software_node_find_by_name(NULL, ref->swnode_name);
+		/*
+		 * When using a name instead of a software node structure
+		 * assume the node will appear at some point.
+		 */
+		if (!ref_swnode)
+			return -EPROBE_DEFER;
+
+		/* Reference is already taken by software_node_find_by_name() */
+		refnode = software_node_fwnode(ref_swnode);
+	} else {
 		return -EINVAL;
+	}
 
 	if (!refnode)
 		return -ENOENT;
diff --git a/include/linux/property.h b/include/linux/property.h
index e30ef23a9af3..44e96ee47272 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -363,6 +363,7 @@ struct software_node;
 struct software_node_ref_args {
 	const struct software_node *swnode;
 	struct fwnode_handle *fwnode;
+	const char *swnode_name;
 	unsigned int nargs;
 	u64 args[NR_FWNODE_REFERENCE_ARGS];
 };
@@ -373,6 +374,9 @@ struct software_node_ref_args {
 			   const struct software_node *: _ref_,	\
 			   struct software_node *: _ref_,	\
 			   default: NULL),			\
+	.swnode_name = _Generic(_ref_,				\
+				const char *: _ref_,		\
+				default: NULL),			\
 	.fwnode = _Generic(_ref_,				\
 			   struct fwnode_handle *: _ref_,	\
 			   default: NULL),			\
-- 
2.53.0.1018.g2bb0e51243-goog


-- 
Dmitry

^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2026-03-26 19:01 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-24  4:46 [PATCH] software node: allow referencing software nodes by name Dmitry Torokhov
2026-03-24  7:59 ` Greg Kroah-Hartman
2026-03-24 16:25   ` Dmitry Torokhov
2026-03-24  9:46 ` Bartosz Golaszewski
2026-03-24 19:30   ` Dmitry Torokhov
2026-03-25 16:32     ` Bartosz Golaszewski
2026-03-25 18:11       ` Dmitry Torokhov
2026-03-26  8:26       ` Andy Shevchenko
2026-03-26  8:28         ` Andy Shevchenko
2026-03-26  8:34         ` Bartosz Golaszewski
2026-03-26  8:39           ` Andy Shevchenko
2026-03-26  8:47             ` Bartosz Golaszewski
2026-03-26  9:03               ` Andy Shevchenko
2026-03-26  8:48             ` Andy Shevchenko
2026-03-26 15:47               ` Bartosz Golaszewski
2026-03-26 19:01                 ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox