summaryrefslogtreecommitdiffstats
path: root/drivers/of
diff options
context:
space:
mode:
authorBenjamin Herrenschmidt <benh@kernel.crashing.org>2016-07-08 08:35:59 +1000
committerMichael Ellerman <mpe@ellerman.id.au>2016-07-20 14:29:56 +1000
commitb9c13fe32faaa71c4e4f8a426d79f8c93495e9f9 (patch)
treefd5e37fb5b98fb52b13411c3f25c930bb01ce89e /drivers/of
parente2413a7dae52fab290b7a8d11ec8579657bab95b (diff)
downloadop-kernel-dev-b9c13fe32faaa71c4e4f8a426d79f8c93495e9f9.zip
op-kernel-dev-b9c13fe32faaa71c4e4f8a426d79f8c93495e9f9.tar.gz
dt: Add of_device_compatible_match()
This provides an equivalent of of_fdt_match() for non-flat trees. This is more practical than matching an array of of_device_id structs when converting a bunch of existing users of of_fdt_match(). Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org> Acked-by: Rob Herring <robh@kernel.org> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Diffstat (limited to 'drivers/of')
-rw-r--r--drivers/of/base.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c
index ebf84e3..c382e1fc 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -493,6 +493,28 @@ int of_device_is_compatible(const struct device_node *device,
}
EXPORT_SYMBOL(of_device_is_compatible);
+/** Checks if the device is compatible with any of the entries in
+ * a NULL terminated array of strings. Returns the best match
+ * score or 0.
+ */
+int of_device_compatible_match(struct device_node *device,
+ const char *const *compat)
+{
+ unsigned int tmp, score = 0;
+
+ if (!compat)
+ return 0;
+
+ while (*compat) {
+ tmp = of_device_is_compatible(device, *compat);
+ if (tmp > score)
+ score = tmp;
+ compat++;
+ }
+
+ return score;
+}
+
/**
* 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.
OpenPOWER on IntegriCloud