#include <fdtdec.h>
#include <dm/of.h>
+#include <dm/of_access.h>
+#include <log.h>
/* Enable checks to protect against invalid calls */
#undef OF_CHECKS
* 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; /* will be used for future live tree */
+ const struct device_node *np;
long of_offset;
} ofnode;
};
/**
- * _ofnode_to_np() - convert an ofnode to a live DT node pointer
+ * ofnode_to_np() - convert an ofnode to a live DT node pointer
*
* This cannot be called if the reference contains an offset.
*
if (of_live_active())
return node.np != NULL;
else
- return node.of_offset != -1;
+ return node.of_offset >= 0;
}
/**
* live tree is in use.
*/
assert(!ofnode_valid(node) ||
- (of_live_active() ? _ofnode_to_np(node)
- : _ofnode_to_np(node)));
+ (of_live_active() ? ofnode_to_np(node)
+ : ofnode_to_np(node)));
#endif
return of_live_active() && ofnode_valid(node);
}
return node;
}
+static inline ofnode ofnode_root(void)
+{
+ ofnode node;
+
+ if (of_live_active())
+ node.np = gd_of_root();
+ else
+ node.of_offset = 0;
+
+ return node;
+}
+
/**
* ofnode_read_u32() - Read a 32-bit integer from a property
*
*/
ofnode ofnode_find_subnode(ofnode node, const char *subnode_name);
+#if CONFIG_IS_ENABLED(DM_INLINE_OFNODE)
+#include <asm/global_data.h>
+
+static inline bool ofnode_is_enabled(ofnode node)
+{
+ if (ofnode_is_np(node)) {
+ return of_device_is_available(ofnode_to_np(node));
+ } else {
+ return fdtdec_get_is_enabled(gd->fdt_blob,
+ ofnode_to_offset(node));
+ }
+}
+
+static inline ofnode ofnode_first_subnode(ofnode node)
+{
+ assert(ofnode_valid(node));
+ if (ofnode_is_np(node))
+ return np_to_ofnode(node.np->child);
+
+ return offset_to_ofnode(
+ fdt_first_subnode(gd->fdt_blob, ofnode_to_offset(node)));
+}
+
+static inline ofnode ofnode_next_subnode(ofnode node)
+{
+ assert(ofnode_valid(node));
+ if (ofnode_is_np(node))
+ return np_to_ofnode(node.np->sibling);
+
+ return offset_to_ofnode(
+ fdt_next_subnode(gd->fdt_blob, ofnode_to_offset(node)));
+}
+#else
+/**
+ * ofnode_is_enabled() - Checks whether a node is enabled.
+ * This looks for a 'status' property. If this exists, then returns true if
+ * the status is 'okay' and false otherwise. If there is no status property,
+ * it returns true on the assumption that anything mentioned should be enabled
+ * by default.
+ *
+ * @node: node to examine
+ * @return false (not enabled) or true (enabled)
+ */
+bool ofnode_is_enabled(ofnode node);
+
/**
* ofnode_first_subnode() - find the first subnode of a parent node
*
* has no more siblings)
*/
ofnode ofnode_next_subnode(ofnode node);
+#endif /* DM_INLINE_OFNODE */
/**
* ofnode_get_parent() - get the ofnode's parent (enclosing ofnode)
* @node: device tree node containing a list
* @list_name: property name that contains a list
* @cells_name: property name that specifies phandles' arguments count
+ * @cells_count: Cell count to use if @cells_name is NULL
* @return number of phandle on success, -ENOENT if @list_name does not
* exist, -EINVAL if a phandle was not found, @cells_name could not
* be found.
*/
int ofnode_count_phandle_with_args(ofnode node, const char *list_name,
- const char *cells_name);
+ const char *cells_name, int cell_count);
/**
* ofnode_path() - find a node by full path
*/
ofnode ofnode_get_chosen_node(const char *propname);
+/**
+ * ofnode_read_aliases_prop() - get the value of a aliases property
+ *
+ * This looks for a property within the /aliases node and returns its value
+ *
+ * @propname: Property name to look for
+ * @sizep: Returns size of property, or FDT_ERR_... error code if function
+ * returns NULL
+ * @return property value if found, else NULL
+ */
+const void *ofnode_read_aliases_prop(const char *propname, int *sizep);
+
+/**
+ * ofnode_get_aliases_node() - get a referenced node from the aliases node
+ *
+ * This looks up a named property in the aliases node and uses that as a path to
+ * look up a code.
+ *
+ * @return the referenced node if present, else ofnode_null()
+ */
+ofnode ofnode_get_aliases_node(const char *propname);
+
struct display_timing;
/**
* ofnode_decode_display_timing() - decode display timings