Merge git://git.denx.de/u-boot-fsl-qoriq
[oweals/u-boot.git] / drivers / core / ofnode.c
index e4b2a85f19ccc69c4a0ca965d7b449bc0e13d9a4..0030ab962ef1912bbc75673ed2c09ec172053fcf 100644 (file)
@@ -199,13 +199,14 @@ fdt_addr_t ofnode_get_addr_index(ofnode node, int index)
                const __be32 *prop_val;
                uint flags;
                u64 size;
+               int na;
 
-               prop_val = of_get_address(
-                       (struct device_node *)ofnode_to_np(node), index,
-                       &size, &flags);
+               prop_val = of_get_address(ofnode_to_np(node), index, &size,
+                                         &flags);
                if (!prop_val)
                        return FDT_ADDR_T_NONE;
-               return  be32_to_cpup(prop_val);
+               na = of_n_addr_cells(ofnode_to_np(node));
+               return of_read_number(prop_val, na);
        } else {
                return fdt_get_base_address(gd->fdt_blob,
                                            ofnode_to_offset(node));
@@ -314,6 +315,18 @@ int ofnode_parse_phandle_with_args(ofnode node, const char *list_name,
        return 0;
 }
 
+int ofnode_count_phandle_with_args(ofnode node, const char *list_name,
+                                  const char *cells_name)
+{
+       if (ofnode_is_np(node))
+               return of_count_phandle_with_args(ofnode_to_np(node),
+                               list_name, cells_name);
+       else
+               return fdtdec_parse_phandle_with_args(gd->fdt_blob,
+                               ofnode_to_offset(node), list_name, cells_name,
+                               0, -1, NULL);
+}
+
 ofnode ofnode_path(const char *path)
 {
        if (of_live_active())
@@ -377,10 +390,11 @@ int ofnode_decode_display_timing(ofnode parent, int index,
        if (!ofnode_valid(timings))
                return -EINVAL;
 
-       for (i = 0, node = ofnode_first_subnode(timings);
-            ofnode_valid(node) && i != index;
-            node = ofnode_first_subnode(node))
-               i++;
+       i = 0;
+       ofnode_for_each_subnode(node, timings) {
+               if (i++ == index)
+                       break;
+       }
 
        if (!ofnode_valid(node))
                return -EINVAL;
@@ -454,8 +468,10 @@ fdt_addr_t ofnode_get_addr_size(ofnode node, const char *property,
                int na, ns;
                int psize;
                const struct device_node *np = ofnode_to_np(node);
-               const __be32 *prop = of_get_property(np, "reg", &psize);
+               const __be32 *prop = of_get_property(np, property, &psize);
 
+               if (!prop)
+                       return FDT_ADDR_T_NONE;
                na = of_n_addr_cells(np);
                ns = of_n_addr_cells(np);
                *sizep = of_read_number(prop + na, ns);
@@ -614,3 +630,15 @@ int ofnode_read_resource(ofnode node, uint index, struct resource *res)
                return 0;
        }
 }
+
+int ofnode_read_resource_byname(ofnode node, const char *name,
+                               struct resource *res)
+{
+       int index;
+
+       index = ofnode_stringlist_search(node, "reg-names", name);
+       if (index < 0)
+               return index;
+
+       return ofnode_read_resource(node, index, res);
+}