summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2023-04-14 20:35:44 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2023-04-17 09:08:33 +0200
commitf09de517765a4fab6a0edcfe32f4e35a056f683f (patch)
treefd18e0243f56d843f65c699b4910b0aa9db9ab13
parentf42ad4fa1566028ffa82e22be3a551af0fd822cd (diff)
downloadbarebox-f09de517765a4fab6a0edcfe32f4e35a056f683f.tar.gz
of: implement of_copy_property
For use in fixups, it can be useful to copy a property verbatim from the barebox DT to the kernel DT. Add a helper that does just that. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230414183545.2039170-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--drivers/of/base.c16
-rw-r--r--include/of.h10
-rw-r--r--test/self/of_manipulation.c2
3 files changed, 27 insertions, 1 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c
index ea4be9c512..9eaa93b5bb 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2318,6 +2318,22 @@ struct property *of_rename_property(struct device_node *np,
return pp;
}
+struct property *of_copy_property(const struct device_node *src,
+ const char *propname,
+ struct device_node *dst)
+{
+ struct property *prop;
+
+ prop = of_find_property(src, propname, NULL);
+ if (!prop)
+ return NULL;
+
+ return of_new_property(dst, propname,
+ of_property_get_value(prop), prop->length);
+}
+EXPORT_SYMBOL_GPL(of_copy_property);
+
+
/**
* of_set_property - create a property for a given node
* @node - the node
diff --git a/include/of.h b/include/of.h
index b88f39ebfa..106a570418 100644
--- a/include/of.h
+++ b/include/of.h
@@ -152,6 +152,9 @@ extern struct property *__of_new_property(struct device_node *node,
extern void of_delete_property(struct property *pp);
extern struct property *of_rename_property(struct device_node *np,
const char *old_name, const char *new_name);
+extern struct property *of_copy_property(const struct device_node *src,
+ const char *propname,
+ struct device_node *dst);
extern struct device_node *of_find_node_by_name(struct device_node *from,
const char *name);
@@ -577,6 +580,13 @@ static inline struct property *__of_new_property(struct device_node *node,
return NULL;
}
+static inline struct property *of_copy_property(const struct device_node *src,
+ const char *propname,
+ struct device_node *dst)
+{
+ return NULL;
+}
+
static inline void of_delete_property(struct property *pp)
{
}
diff --git a/test/self/of_manipulation.c b/test/self/of_manipulation.c
index f7f95fa269..64913ac1ea 100644
--- a/test/self/of_manipulation.c
+++ b/test/self/of_manipulation.c
@@ -63,7 +63,7 @@ static void test_of_basics(struct device_node *root)
of_property_write_u32(node2, "property2", 2);
of_property_write_u32(node1, "property3", 1);
- of_property_write_u32(node1, "property2", 2);
+ of_copy_property(node2, "property2", node1);
of_rename_property(node1, "property3", "property1");
assert_equal(node1, node2);