diff options
author | Michael Ellerman <mpe@ellerman.id.au> | 2023-12-14 21:31:48 +1100 |
---|---|---|
committer | Michael Ellerman <mpe@ellerman.id.au> | 2024-03-03 22:20:29 +1100 |
commit | c029b22f8a98e14988f800d5c0176a9eaec3c8db (patch) | |
tree | 23c568ae23dfdee7aa0646fdfd89bff9f5e2ef83 /drivers/of | |
parent | af1ebca503f4c5bb9345dd251faaa825431ce972 (diff) |
of: Add of_machine_compatible_match()
We have of_machine_is_compatible() to check if a machine is compatible
with a single compatible string. However some code is able to support
multiple compatible boards, and so wants to check for one of many
compatible strings.
So add of_machine_compatible_match() which takes a NULL terminated
array of compatible strings to check against the root node's
compatible property.
Compared to an open coded match this is slightly more self
documenting, and also avoids the caller needing to juggle the root
node either directly or via of_find_node_by_path().
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20231214103152.12269-1-mpe@ellerman.id.au
Diffstat (limited to 'drivers/of')
-rw-r--r-- | drivers/of/base.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c index b0ad8fc06e80..3c85afb2697c 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -395,6 +395,27 @@ int of_device_compatible_match(const struct device_node *device, EXPORT_SYMBOL_GPL(of_device_compatible_match); /** + * of_machine_compatible_match - Test root of device tree against a compatible array + * @compats: NULL terminated array of compatible strings to look for in root node's compatible property. + * + * Returns true if the root node has any of the given compatible values in its + * compatible property. + */ +bool of_machine_compatible_match(const char *const *compats) +{ + struct device_node *root; + int rc = 0; + + root = of_find_node_by_path("/"); + if (root) { + rc = of_device_compatible_match(root, compats); + of_node_put(root); + } + + return rc != 0; +} + +/** * of_machine_is_compatible - Test root of device tree for a given compatible value * @compat: compatible string to look for in root node's compatible property. * |