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 |
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?
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 --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 */
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(+)