]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - drivers/core/ofnode.c
serial: Make full device search optional
[people/ms/u-boot.git] / drivers / core / ofnode.c
index e4b2a85f19ccc69c4a0ca965d7b449bc0e13d9a4..98f4b539ea4d6de876f1058104a260b7a400e035 100644 (file)
@@ -199,13 +199,19 @@ 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);
+
+               if (IS_ENABLED(CONFIG_OF_TRANSLATE)) {
+                       return of_translate_address(ofnode_to_np(node), prop_val);
+               } else {
+                       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));
@@ -295,7 +301,8 @@ int ofnode_parse_phandle_with_args(ofnode node, const char *list_name,
                int ret;
 
                ret = of_parse_phandle_with_args(ofnode_to_np(node),
-                               list_name, cells_name, index, &args);
+                                                list_name, cells_name, index,
+                                                &args);
                if (ret)
                        return ret;
                ofnode_from_of_phandle_args(&args, out_args);
@@ -304,8 +311,9 @@ int ofnode_parse_phandle_with_args(ofnode node, const char *list_name,
                int ret;
 
                ret = fdtdec_parse_phandle_with_args(gd->fdt_blob,
-                               ofnode_to_offset(node), list_name, cells_name,
-                               cell_count, index, &args);
+                                                    ofnode_to_offset(node),
+                                                    list_name, cells_name,
+                                                    cell_count, index, &args);
                if (ret)
                        return ret;
                ofnode_from_fdtdec_phandle_args(&args, out_args);
@@ -314,6 +322,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 +397,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 +475,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);
@@ -518,10 +541,10 @@ int ofnode_read_pci_addr(ofnode node, enum fdt_pci_space type,
                                addr->phys_mid = fdt32_to_cpu(cell[1]);
                                addr->phys_lo = fdt32_to_cpu(cell[1]);
                                break;
-                       } else {
-                               cell += (FDT_PCI_ADDR_CELLS +
-                                        FDT_PCI_SIZE_CELLS);
                        }
+
+                       cell += (FDT_PCI_ADDR_CELLS +
+                                FDT_PCI_SIZE_CELLS);
                }
 
                if (i == num) {
@@ -530,10 +553,10 @@ int ofnode_read_pci_addr(ofnode node, enum fdt_pci_space type,
                }
 
                return 0;
-       } else {
-               ret = -EINVAL;
        }
 
+       ret = -EINVAL;
+
 fail:
        debug("(not found)\n");
        return ret;
@@ -614,3 +637,23 @@ 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);
+}
+
+u64 ofnode_translate_address(ofnode node, const fdt32_t *in_addr)
+{
+       if (ofnode_is_np(node))
+               return of_translate_address(ofnode_to_np(node), in_addr);
+       else
+               return fdt_translate_address(gd->fdt_blob, ofnode_to_offset(node), in_addr);
+}