summaryrefslogtreecommitdiffstats
path: root/drivers/of
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2013-02-17 17:13:38 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2013-03-06 11:41:27 +0100
commit6be475957926afe3e3af97dcdc9e001f10b0d3d5 (patch)
treef9960fbcaa9a9e9709181603ab859a70be44be21 /drivers/of
parent04bd477ee42687075e13dabb6c11f90a685a5450 (diff)
downloadbarebox-6be475957926afe3e3af97dcdc9e001f10b0d3d5.tar.gz
barebox-6be475957926afe3e3af97dcdc9e001f10b0d3d5.tar.xz
of: Add of_set_property and of_create_node
Add functions to create a new device node and to create/set a new property based on the nodepath. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/of')
-rw-r--r--drivers/of/base.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c
index ad278ad50d..11d17c6d04 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -663,6 +663,41 @@ void of_delete_property(struct property *pp)
free(pp);
}
+/**
+ * of_set_property - create a property for a given node
+ * @node - the node
+ * @name - the name of the property
+ * @val - the value for the property
+ * @len - the length of the properties value
+ * @create - if true, the property is created if not existing already
+ */
+int of_set_property(struct device_node *np, const char *name, const void *val, int len,
+ int create)
+{
+ struct property *pp;
+
+ if (!np)
+ return -ENOENT;
+
+ pp = of_find_property(np, name);
+ if (pp) {
+ void *data;
+
+ free(pp->value);
+ data = xzalloc(len);
+ memcpy(data, val, len);
+ pp->value = data;
+ pp->length = len;
+ } else {
+ if (!create)
+ return -ENOENT;
+
+ pp = of_new_property(np, name, val, len);
+ }
+
+ return 0;
+}
+
static struct device_d *add_of_amba_device(struct device_node *node)
{
struct amba_device *dev;
@@ -942,6 +977,50 @@ struct device_node *of_find_child_by_name(struct device_node *node, const char *
return NULL;
}
+/**
+ * of_create_node - create a new node including its parents
+ * @path - the nodepath to create
+ */
+struct device_node *of_create_node(struct device_node *root, const char *path)
+{
+ char *slash, *p, *freep;
+ struct device_node *tmp, *dn = root;
+
+ if (*path != '/')
+ return NULL;
+
+ path++;
+
+ p = freep = xstrdup(path);
+
+ while (1) {
+ if (!*p)
+ goto out;
+
+ slash = strchr(p, '/');
+ if (slash)
+ *slash = 0;
+
+ tmp = of_find_child_by_name(dn, p);
+ if (tmp)
+ dn = tmp;
+ else
+ dn = of_new_node(dn, p);
+
+ if (!dn)
+ goto out;
+
+ if (!slash)
+ goto out;
+
+ p = slash + 1;
+ }
+out:
+ free(freep);
+
+ return dn;
+}
+
/*
* Parse a flat device tree binary blob and store it in the barebox
* internal tree format,