Added straight from the Kernel.

Signed-off-by: Sascha Hauer <s.ha...@pengutronix.de>
---
 drivers/of/base.c | 46 ++++++++++++++++++++++++++++------------------
 include/of.h      | 12 ++++++++++++
 2 files changed, 40 insertions(+), 18 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 80ceeab13b..9ede052274 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -78,36 +78,46 @@ static struct device_node *of_aliases;
 #define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1
 #define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 1
 
-int of_n_addr_cells(struct device_node *np)
+int of_bus_n_addr_cells(struct device_node *np)
 {
-       const __be32 *ip;
+       u32 cells;
+
+       for (; np; np = np->parent)
+               if (!of_property_read_u32(np, "#address-cells", &cells))
+                       return cells;
 
-       do {
-               if (np->parent)
-                       np = np->parent;
-               ip = of_get_property(np, "#address-cells", NULL);
-               if (ip)
-                       return be32_to_cpup(ip);
-       } while (np->parent);
        /* No #address-cells property for the root node */
        return OF_ROOT_NODE_ADDR_CELLS_DEFAULT;
 }
+
+int of_n_addr_cells(struct device_node *np)
+{
+       if (np->parent)
+               np = np->parent;
+
+       return of_bus_n_addr_cells(np);
+}
 EXPORT_SYMBOL(of_n_addr_cells);
 
-int of_n_size_cells(struct device_node *np)
+int of_bus_n_size_cells(struct device_node *np)
 {
-       const __be32 *ip;
+       u32 cells;
+
+       for (; np; np = np->parent)
+               if (!of_property_read_u32(np, "#size-cells", &cells))
+                       return cells;
 
-       do {
-               if (np->parent)
-                       np = np->parent;
-               ip = of_get_property(np, "#size-cells", NULL);
-               if (ip)
-                       return be32_to_cpup(ip);
-       } while (np->parent);
        /* No #size-cells property for the root node */
        return OF_ROOT_NODE_SIZE_CELLS_DEFAULT;
 }
+
+int of_n_size_cells(struct device_node *np)
+{
+       if (np->parent)
+               np = np->parent;
+
+       return of_bus_n_size_cells(np);
+}
 EXPORT_SYMBOL(of_n_size_cells);
 
 struct property *of_find_property(const struct device_node *np,
diff --git a/include/of.h b/include/of.h
index f63a3efe13..67601ce80c 100644
--- a/include/of.h
+++ b/include/of.h
@@ -113,7 +113,9 @@ struct device_node *of_unflatten_dtb_const(const void 
*infdt);
 struct cdev;
 
 #ifdef CONFIG_OFTREE
+extern int of_bus_n_addr_cells(struct device_node *np);
 extern int of_n_addr_cells(struct device_node *np);
+extern int of_bus_n_size_cells(struct device_node *np);
 extern int of_n_size_cells(struct device_node *np);
 
 extern struct property *of_find_property(const struct device_node *np,
@@ -328,11 +330,21 @@ static inline struct device_d 
*of_platform_device_create(struct device_node *np,
        return NULL;
 }
 
+static inline int of_bus_n_addr_cells(struct device_node *np)
+{
+       return 0;
+}
+
 static inline int of_n_addr_cells(struct device_node *np)
 {
        return 0;
 }
 
+static inline int of_bus_n_size_cells(struct device_node *np)
+{
+       return 0;
+}
+
 static inline int of_n_size_cells(struct device_node *np)
 {
        return 0;
-- 
2.24.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

Reply via email to