summaryrefslogtreecommitdiff
path: root/include/dm
diff options
context:
space:
mode:
authorSimon Glass <[email protected]>2022-07-30 15:52:13 -0600
committerTom Rini <[email protected]>2022-08-12 08:14:24 -0400
commit39e42be12b9456e604ac3e228973b1cb1136864c (patch)
tree14b0f51e7ad986d730b39d8b0bf0440ddf1b5659 /include/dm
parent7b1dfc9fd7e2efed345c3fe9a2412b5300ac285e (diff)
dm: core: Allow writing to a flat tree with ofnode
In generally it is not permitted to implement an ofnode function only for flat tree or live tree. Both must be supported. Also the code for live tree access should be in of_access.c rather than ofnode.c which is really just for holding the API-conversion code. Update ofnode_write_prop() accordingly and fix the test so it can work with flat tree too. Signed-off-by: Simon Glass <[email protected]>
Diffstat (limited to 'include/dm')
-rw-r--r--include/dm/of_access.h12
-rw-r--r--include/dm/ofnode.h18
2 files changed, 30 insertions, 0 deletions
diff --git a/include/dm/of_access.h b/include/dm/of_access.h
index 078f2ea06cd..5b7821d0a1b 100644
--- a/include/dm/of_access.h
+++ b/include/dm/of_access.h
@@ -519,4 +519,16 @@ int of_alias_get_highest_id(const char *stem);
*/
struct device_node *of_get_stdout(void);
+/**
+ * of_write_prop() - Write a property to the device tree
+ *
+ * @np: device node to which the property value is to be written
+ * @propname: name of the property to write
+ * @value: value of the property
+ * @len: length of the property in bytes
+ * Returns: 0 if OK, -ve on error
+ */
+int of_write_prop(struct device_node *np, const char *propname, int len,
+ const void *value);
+
#endif
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index 071a9d63f67..16c8890b097 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -45,6 +45,24 @@ static inline const struct device_node *ofnode_to_np(ofnode node)
}
/**
+ * ofnode_to_npw() - convert an ofnode to a writeable live DT node pointer
+ *
+ * This cannot be called if the reference contains an offset.
+ *
+ * @node: Reference containing struct device_node * (possibly invalid)
+ * Return: pointer to device node (can be NULL)
+ */
+static inline struct device_node *ofnode_to_npw(ofnode node)
+{
+#ifdef OF_CHECKS
+ if (!of_live_active())
+ return NULL;
+#endif
+ /* Drop constant */
+ return (struct device_node *)node.np;
+}
+
+/**
* ofnode_to_offset() - convert an ofnode to a flat DT offset
*
* This cannot be called if the reference contains a node pointer.