[PATCH v3 04/14] software node: Add software_node_match_device() API

Manivannan Sadhasivam via B4 Relay posted 14 patches 4 weeks, 1 day ago
There is a newer version of this series
[PATCH v3 04/14] software node: Add software_node_match_device() API
Posted by Manivannan Sadhasivam via B4 Relay 4 weeks, 1 day ago
From: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>

Add software_node_match_device() API to match the swnode device with the
swnode driver. The matching is based on the compatible property in the
device and the driver's of_match_table.

Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
---
 drivers/base/swnode.c    | 16 ++++++++++++++++
 include/linux/property.h |  3 +++
 2 files changed, 19 insertions(+)

diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
index cd722712b8e9..4a3b367dea02 100644
--- a/drivers/base/swnode.c
+++ b/drivers/base/swnode.c
@@ -372,6 +372,22 @@ void property_entries_free(const struct property_entry *properties)
 }
 EXPORT_SYMBOL_GPL(property_entries_free);
 
+bool software_node_match_device(struct device *dev, const struct device_driver *drv)
+{
+	const struct of_device_id *id;
+
+	if (!drv->of_match_table)
+		return false;
+
+	for (id = drv->of_match_table; id->compatible[0]; id++) {
+		if (device_is_compatible(dev, id->compatible))
+			return true;
+	}
+
+	return false;
+}
+EXPORT_SYMBOL_GPL(software_node_match_device);
+
 /* -------------------------------------------------------------------------- */
 /* fwnode operations */
 
diff --git a/include/linux/property.h b/include/linux/property.h
index 272bfbdea7bf..7fe75ab732f6 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -14,6 +14,7 @@
 #include <linux/array_size.h>
 #include <linux/bits.h>
 #include <linux/cleanup.h>
+#include <linux/device.h>
 #include <linux/fwnode.h>
 #include <linux/stddef.h>
 #include <linux/types.h>
@@ -597,6 +598,8 @@ void software_node_unregister_node_group(const struct software_node * const *nod
 int software_node_register(const struct software_node *node);
 void software_node_unregister(const struct software_node *node);
 
+bool software_node_match_device(struct device *dev, const struct device_driver *drv);
+
 struct fwnode_handle *
 fwnode_create_software_node(const struct property_entry *properties,
 			    const struct fwnode_handle *parent);

-- 
2.48.1
Re: [PATCH v3 04/14] software node: Add software_node_match_device() API
Posted by Andy Shevchenko 3 weeks, 6 days ago
On Sat, Jan 10, 2026 at 12:26:22PM +0530, Manivannan Sadhasivam via B4 Relay wrote:

> Add software_node_match_device() API to match the swnode device with the
> swnode driver. The matching is based on the compatible property in the
> device and the driver's of_match_table.

NAK. swnodes != real firmware nodes.

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v3 04/14] software node: Add software_node_match_device() API
Posted by Bartosz Golaszewski 3 weeks, 6 days ago
On Mon, 12 Jan 2026 09:31:44 +0100, Andy Shevchenko
<andriy.shevchenko@linux.intel.com> said:
> On Sat, Jan 10, 2026 at 12:26:22PM +0530, Manivannan Sadhasivam via B4 Relay wrote:
>
>> Add software_node_match_device() API to match the swnode device with the
>> swnode driver. The matching is based on the compatible property in the
>> device and the driver's of_match_table.
>
> NAK. swnodes != real firmware nodes.
>

While I'm not arguing that this is *the* solution, I think it warrants
a discussion on proper matching of devices that are only backed by a software
node - for instance a serdev device on the auxiliary bus. I understand what
software nodes were historically but perhaps it's time to extend their role as
a full-blown firmware node allowing matching with drivers.

Reusing existing OF IDs is just one way, we could potentially think about a
high-level fwnode-based device to driver matching?

Bartosz
Re: [PATCH v3 04/14] software node: Add software_node_match_device() API
Posted by Andy Shevchenko 3 weeks, 6 days ago
On Mon, Jan 12, 2026 at 06:03:34AM -0500, Bartosz Golaszewski wrote:
> On Mon, 12 Jan 2026 09:31:44 +0100, Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> said:
> > On Sat, Jan 10, 2026 at 12:26:22PM +0530, Manivannan Sadhasivam via B4 Relay wrote:
> >
> >> Add software_node_match_device() API to match the swnode device with the
> >> swnode driver. The matching is based on the compatible property in the
> >> device and the driver's of_match_table.
> >
> > NAK. swnodes != real firmware nodes.
> 
> While I'm not arguing that this is *the* solution, I think it warrants
> a discussion on proper matching of devices that are only backed by a software
> node - for instance a serdev device on the auxiliary bus. I understand what
> software nodes were historically but perhaps it's time to extend their role as
> a full-blown firmware node allowing matching with drivers.
> 
> Reusing existing OF IDs is just one way, we could potentially think about a
> high-level fwnode-based device to driver matching?

There is already proposed and agree way to do that via DT overlays.
If one needs to describe the (PnP or hotpluggable) hardware, it's
the way to go as the HW maybe much complex than the just one small UART
appendix.

As per auxdevice, this should not be enumerable by compatible. The auxdevice
usually are created by other devices (from real ones) that _know_ the topology.
I don't see why we need to open the can of worms with the software nodes
to enumerate them as real ones.

P.S. Collect others' opinions (esp. device property reviewers and maintainers)
and we will see. But I do not see any even looking good justification for that.
It might be that I didn't get fully the use case and the other means can not
be used. But taking into account history of the rejection of the matching against
OF compatible string in swnodes suggests that this will stay the way it's now.

-- 
With Best Regards,
Andy Shevchenko