summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2017-05-19 05:09:27 +0300
committerSimon Glass <sjg@chromium.org>2017-06-01 16:03:12 +0300
commita4b8e372d5b15d7dd302cac667e87049b59b13c7 (patch)
treea806a79b586f5489a48a8ba01c41f9e0140f8fd3
parenteed36609b5494b94bdca0e2bdc5ac2bd07ab2518 (diff)
downloadu-boot-a4b8e372d5b15d7dd302cac667e87049b59b13c7.tar.xz
dm: Add more livetree helpers and definitions
Add some definitions and helpers for livetree in the main of.h header file. These include: - reading multi-cell integers - default number of address/size cells - functions for comparing names Signed-off-by: Simon Glass <sjg@chromium.org>
-rw-r--r--drivers/core/ofnode.c4
-rw-r--r--include/dm/of.h36
2 files changed, 38 insertions, 2 deletions
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index 6805fe2424..ac312d6546 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -457,8 +457,8 @@ fdt_addr_t ofnode_get_addr_size(ofnode node, const char *property,
na = of_n_addr_cells(np);
ns = of_n_addr_cells(np);
- *sizep = fdt_read_number(prop + na, ns);
- return fdt_read_number(prop, na);
+ *sizep = of_read_number(prop + na, ns);
+ return of_read_number(prop, na);
} else {
return fdtdec_get_addr_size(gd->fdt_blob,
ofnode_to_offset(node), property,
diff --git a/include/dm/of.h b/include/dm/of.h
index 6b5afab1c1..d4d941e75c 100644
--- a/include/dm/of.h
+++ b/include/dm/of.h
@@ -103,4 +103,40 @@ static inline bool of_live_active(void)
}
#endif
+#define OF_BAD_ADDR ((u64)-1)
+
+static inline const char *of_node_full_name(const struct device_node *np)
+{
+ return np ? np->full_name : "<no-node>";
+}
+
+/* Default #address and #size cells */
+#if !defined(OF_ROOT_NODE_ADDR_CELLS_DEFAULT)
+#define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 1
+#define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1
+#endif
+
+/* Default string compare functions */
+#if !defined(of_compat_cmp)
+#define of_compat_cmp(s1, s2, l) strcasecmp((s1), (s2))
+#define of_prop_cmp(s1, s2) strcmp((s1), (s2))
+#define of_node_cmp(s1, s2) strcasecmp((s1), (s2))
+#endif
+
+/* Helper to read a big number; size is in cells (not bytes) */
+static inline u64 of_read_number(const __be32 *cell, int size)
+{
+ u64 r = 0;
+ while (size--)
+ r = (r << 32) | be32_to_cpu(*(cell++));
+ return r;
+}
+
+/* Like of_read_number, but we want an unsigned long result */
+static inline unsigned long of_read_ulong(const __be32 *cell, int size)
+{
+ /* toss away upper bits if unsigned long is smaller than u64 */
+ return of_read_number(cell, size);
+}
+
#endif