]> 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 0685b689d8467061aaa4ed6081538558eaa9fe98..98f4b539ea4d6de876f1058104a260b7a400e035 100644 (file)
@@ -205,8 +205,13 @@ fdt_addr_t ofnode_get_addr_index(ofnode node, int index)
                                          &flags);
                if (!prop_val)
                        return FDT_ADDR_T_NONE;
-               na = of_n_addr_cells(ofnode_to_np(node));
-               return of_read_number(prop_val, na);
+
+               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));
@@ -296,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);
@@ -305,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);
@@ -390,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;
@@ -467,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);
@@ -531,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) {
@@ -543,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;
@@ -639,3 +649,11 @@ int ofnode_read_resource_byname(ofnode node, const char *name,
 
        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);
+}