diff mbox series

[RFC,01/10] property: add fwnode_match_node()

Message ID 20220221162652.103834-2-clement.leger@bootlin.com (mailing list archive)
State RFC
Headers show
Series add support for fwnode in i2c mux system and sfp | expand

Checks

Context Check Description
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8225 this patch: 8225
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 1497 this patch: 1497
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 7759 this patch: 7759
netdev/checkpatch warning WARNING: line length of 81 exceeds 80 columns WARNING: line length of 91 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 5 this patch: 5
netdev/source_inline success Was 0 now: 0
netdev/tree_selection success Guessing tree name failed - patch did not apply

Commit Message

Clément Léger Feb. 21, 2022, 4:26 p.m. UTC
Add a function equivalent to of_match_node() which is usable for fwnode
support. Matching is based on the compatible property and it returns
the best matches for the node according to the compatible list
ordering.

Signed-off-by: Clément Léger <clement.leger@bootlin.com>
---
 drivers/base/property.c  | 23 +++++++++++++++++++++++
 include/linux/property.h |  3 +++
 2 files changed, 26 insertions(+)

Comments

Andy Shevchenko Feb. 21, 2022, 5:44 p.m. UTC | #1
On Mon, Feb 21, 2022 at 05:26:43PM +0100, Clément Léger wrote:
> Add a function equivalent to of_match_node() which is usable for fwnode
> support. Matching is based on the compatible property and it returns
> the best matches for the node according to the compatible list
> ordering.

Not sure I understand the purpose of this API.
We have device_get_match_data(), maybe you want similar for fwnode?
Clément Léger Feb. 22, 2022, 8:14 a.m. UTC | #2
Le Mon, 21 Feb 2022 19:44:52 +0200,
Andy Shevchenko <andriy.shevchenko@linux.intel.com> a écrit :

> On Mon, Feb 21, 2022 at 05:26:43PM +0100, Clément Léger wrote:
> > Add a function equivalent to of_match_node() which is usable for
> > fwnode support. Matching is based on the compatible property and it
> > returns the best matches for the node according to the compatible
> > list ordering.  
> 
> Not sure I understand the purpose of this API.
> We have device_get_match_data(), maybe you want similar for fwnode?
> 

Hi Andy,

Actually device_get_match_data() is calling the .device_get_match_data
callback of the dev fwnode. This function is meant to be used by the
next patch (fwnode_get_match_data()) to be used as a generic fwnode
operation and thus be usable with software_node.
diff mbox series

Patch

diff --git a/drivers/base/property.c b/drivers/base/property.c
index e6497f6877ee..434c2713fd99 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -1158,6 +1158,29 @@  int fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode,
 }
 EXPORT_SYMBOL(fwnode_graph_parse_endpoint);
 
+const struct of_device_id *fwnode_match_node(const struct fwnode_handle *fwnode,
+					     const struct of_device_id *matches)
+{
+	int index;
+	const struct of_device_id *best_match = NULL;
+	int best_index = INT_MAX;
+
+	if (!matches)
+		return NULL;
+
+	for (; matches->name[0] || matches->type[0] || matches->compatible[0]; matches++) {
+		index = fwnode_property_match_string(fwnode, "compatible",
+						     matches->compatible);
+		if (index >= 0 && index < best_index) {
+			best_match = matches;
+			best_index = index;
+		}
+	}
+
+	return best_match;
+}
+EXPORT_SYMBOL(fwnode_match_node);
+
 const void *device_get_match_data(struct device *dev)
 {
 	return fwnode_call_ptr_op(dev_fwnode(dev), device_get_match_data, dev);
diff --git a/include/linux/property.h b/include/linux/property.h
index 7399a0b45f98..978ecf6be34e 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -446,6 +446,9 @@  static inline void *device_connection_find_match(struct device *dev,
 	return fwnode_connection_find_match(dev_fwnode(dev), con_id, data, match);
 }
 
+const struct of_device_id *fwnode_match_node(const struct fwnode_handle *fwnode,
+					     const struct of_device_id *matches);
+
 /* -------------------------------------------------------------------------- */
 /* Software fwnode support - when HW description is incomplete or missing */