Merge git://git.denx.de/u-boot-fsl-qoriq
[oweals/u-boot.git] / drivers / core / ofnode.c
index c3fb0ae7b9124188d2f1d0e9b5a28300fa282027..0030ab962ef1912bbc75673ed2c09ec172053fcf 100644 (file)
@@ -315,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())
@@ -378,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;
@@ -455,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);
@@ -615,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);
+}