summaryrefslogtreecommitdiff
path: root/drivers/core
diff options
context:
space:
mode:
authorJens Wiklander <jens.wiklander@linaro.org>2018-08-20 11:09:58 +0200
committerSimon Glass <sjg@chromium.org>2018-09-18 08:12:21 -0600
commit61fba0faba432ae1cefc3984f863c28880d30329 (patch)
treee55b6dd9e140132a6ed6c913c14251df0ffcb21c /drivers/core
parent427ddd84204cc0693e3f80f90f257b3d24b04307 (diff)
ofnode: add ofnode_by_prop_value()
Adds ofnode_by_prop_value() to search for nodes with a given property and value, an ofnode version of fdt_node_offset_by_prop_value(). Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers/core')
-rw-r--r--drivers/core/of_access.c27
-rw-r--r--drivers/core/ofnode.c14
2 files changed, 41 insertions, 0 deletions
diff --git a/drivers/core/of_access.c b/drivers/core/of_access.c
index 0729dfcdb3..14c020a687 100644
--- a/drivers/core/of_access.c
+++ b/drivers/core/of_access.c
@@ -376,6 +376,33 @@ struct device_node *of_find_compatible_node(struct device_node *from,
return np;
}
+static int of_device_has_prop_value(const struct device_node *device,
+ const char *propname, const void *propval,
+ int proplen)
+{
+ struct property *prop = of_find_property(device, propname, NULL);
+
+ if (!prop || !prop->value || prop->length != proplen)
+ return 0;
+ return !memcmp(prop->value, propval, proplen);
+}
+
+struct device_node *of_find_node_by_prop_value(struct device_node *from,
+ const char *propname,
+ const void *propval, int proplen)
+{
+ struct device_node *np;
+
+ for_each_of_allnodes_from(from, np) {
+ if (of_device_has_prop_value(np, propname, propval, proplen) &&
+ of_node_get(np))
+ break;
+ }
+ of_node_put(from);
+
+ return np;
+}
+
struct device_node *of_find_node_by_phandle(phandle handle)
{
struct device_node *np;
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index 0cfb0fbabb..a7e1927723 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -777,3 +777,17 @@ ofnode ofnode_by_compatible(ofnode from, const char *compat)
gd->fdt_blob, ofnode_to_offset(from), compat));
}
}
+
+ofnode ofnode_by_prop_value(ofnode from, const char *propname,
+ const void *propval, int proplen)
+{
+ if (of_live_active()) {
+ return np_to_ofnode(of_find_node_by_prop_value(
+ (struct device_node *)ofnode_to_np(from), propname,
+ propval, proplen));
+ } else {
+ return offset_to_ofnode(fdt_node_offset_by_prop_value(
+ gd->fdt_blob, ofnode_to_offset(from),
+ propname, propval, proplen));
+ }
+}