diff options
Diffstat (limited to 'include/dm/ofnode.h')
-rw-r--r-- | include/dm/ofnode.h | 122 |
1 files changed, 60 insertions, 62 deletions
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index bb60433124b..7ce1e4c6d91 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -19,41 +19,7 @@ struct resource; -/** - * typedef union ofnode_union ofnode - reference to a device tree node - * - * This union can hold either a straightforward pointer to a struct device_node - * in the live device tree, or an offset within the flat device tree. In the - * latter case, the pointer value is just the integer offset within the flat DT. - * - * Thus we can reference nodes in both the live tree (once available) and the - * flat tree (until then). Functions are available to translate between an - * ofnode and either an offset or a `struct device_node *`. - * - * The reference can also hold a null offset, in which case the pointer value - * here is NULL. This corresponds to a struct device_node * value of - * NULL, or an offset of -1. - * - * There is no ambiguity as to whether ofnode holds an offset or a node - * pointer: when the live tree is active it holds a node pointer, otherwise it - * holds an offset. The value itself does not need to be unique and in theory - * the same value could point to a valid device node or a valid offset. We - * could arrange for a unique value to be used (e.g. by making the pointer - * point to an offset within the flat device tree in the case of an offset) but - * this increases code size slightly due to the subtraction. Since it offers no - * real benefit, the approach described here seems best. - * - * For now these points use constant types, since we don't allow writing - * the DT. - * - * @np: Pointer to device node, used for live tree - * @of_offset: Pointer into flat device tree, used for flat tree. Note that this - * is not a really a pointer to a node: it is an offset value. See above. - */ -typedef union ofnode_union { - const struct device_node *np; - long of_offset; -} ofnode; +#include <dm/ofnode_decl.h> struct ofnode_phandle_args { ofnode node; @@ -62,45 +28,38 @@ struct ofnode_phandle_args { }; /** - * struct ofprop - reference to a property of a device tree node - * - * This struct hold the reference on one property of one node, - * using struct ofnode and an offset within the flat device tree or either - * a pointer to a struct property in the live device tree. - * - * Thus we can reference arguments in both the live tree and the flat tree. + * ofnode_to_np() - convert an ofnode to a live DT node pointer * - * The property reference can also hold a null reference. This corresponds to - * a struct property NULL pointer or an offset of -1. + * This cannot be called if the reference contains an offset. * - * @node: Pointer to device node - * @offset: Pointer into flat device tree, used for flat tree. - * @prop: Pointer to property, used for live treee. + * @node: Reference containing struct device_node * (possibly invalid) + * Return: pointer to device node (can be NULL) */ - -struct ofprop { - ofnode node; - union { - int offset; - const struct property *prop; - }; -}; +static inline const struct device_node *ofnode_to_np(ofnode node) +{ +#ifdef OF_CHECKS + if (!of_live_active()) + return NULL; +#endif + return node.np; +} /** - * ofnode_to_np() - convert an ofnode to a live DT node pointer + * 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 const struct device_node *ofnode_to_np(ofnode node) +static inline struct device_node *ofnode_to_npw(ofnode node) { #ifdef OF_CHECKS if (!of_live_active()) return NULL; #endif - return node.np; + /* Drop constant */ + return (struct device_node *)node.np; } /** @@ -236,6 +195,23 @@ static inline ofnode ofnode_root(void) } /** + * oftree_default() - Returns the default device tree (U-Boot's control FDT) + * + * Returns: reference to the control FDT + */ +static inline oftree oftree_default(void) +{ + oftree tree; + + if (of_live_active()) + tree.np = gd_of_root(); + else + tree.fdt = (void *)gd->fdt_blob; + + return tree; +} + +/** * ofnode_name_eq() - Check if the node name is equivalent to a given name * ignoring the unit address * @@ -699,12 +675,23 @@ int ofnode_count_phandle_with_args(ofnode node, const char *list_name, /** * ofnode_path() - find a node by full path * + * This uses the control FDT. + * * @path: Full path to node, e.g. "/bus/spi@1" * Return: reference to the node found. Use ofnode_valid() to check if it exists */ ofnode ofnode_path(const char *path); /** + * ofnode_path_root() - find a node by full path from a root node + * + * @tree: Device tree to use + * @path: Full path to node, e.g. "/bus/spi@1" + * Return: reference to the node found. Use ofnode_valid() to check if it exists + */ +ofnode ofnode_path_root(oftree tree, const char *path); + +/** * ofnode_read_chosen_prop() - get the value of a chosen property * * This looks for a property within the /chosen node and returns its value @@ -1140,17 +1127,18 @@ int ofnode_device_is_compatible(ofnode node, const char *compat); * ofnode_write_prop() - Set a property of a ofnode * * Note that the value passed to the function is *not* allocated by the - * function itself, but must be allocated by the caller if necessary. + * function itself, but must be allocated by the caller if necessary. However + * it does allocate memory for the property struct and name. * * @node: The node for whose property should be set * @propname: The name of the property to set - * @len: The length of the new value of the property * @value: The new value of the property (must be valid prior to calling * the function) + * @len: The length of the new value of the property * Return: 0 if successful, -ve on error */ -int ofnode_write_prop(ofnode node, const char *propname, int len, - const void *value); +int ofnode_write_prop(ofnode node, const char *propname, const void *value, + int len); /** * ofnode_write_string() - Set a string property of a ofnode @@ -1167,6 +1155,16 @@ int ofnode_write_prop(ofnode node, const char *propname, int len, int ofnode_write_string(ofnode node, const char *propname, const char *value); /** + * ofnode_write_u32() - Set an integer property of an ofnode + * + * @node: The node for whose string property should be set + * @propname: The name of the string property to set + * @value: The new value of the 32-bit integer property + * Return: 0 if successful, -ve on error + */ +int ofnode_write_u32(ofnode node, const char *propname, u32 value); + +/** * ofnode_set_enabled() - Enable or disable a device tree node given by its * ofnode * |