]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
lib: fdt: Convert fdtdes_setup_mem..() to livetree API
authorMichal Simek <michal.simek@xilinx.com>
Fri, 10 Jul 2020 11:34:44 +0000 (13:34 +0200)
committerMichal Simek <michal.simek@xilinx.com>
Thu, 20 Aug 2020 07:49:20 +0000 (09:49 +0200)
Convert fdtdec_setup_mem_size_base(), get_next_memory_node(),
fdtdec_setup_memory_banksize() and fdtdec_setup_mem_size_base_lowest() to
livetree API.

Tested on ZynqMP zcu104 board.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
lib/fdtdec.c

index da94bc5e15a161e4c0f7bf88c2f70c1fbac1d69e..30a1c6a217b86c6140088792f862f018dbeb14b0 100644 (file)
@@ -24,6 +24,7 @@
 #include <asm/sections.h>
 #include <linux/ctype.h>
 #include <linux/lzo.h>
+#include <linux/ioport.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -1032,16 +1033,17 @@ int fdtdec_decode_display_timing(const void *blob, int parent, int index,
 
 int fdtdec_setup_mem_size_base(void)
 {
-       int ret, mem;
-       struct fdt_resource res;
+       int ret;
+       ofnode mem;
+       struct resource res;
 
-       mem = fdt_path_offset(gd->fdt_blob, "/memory");
-       if (mem < 0) {
+       mem = ofnode_path("/memory");
+       if (!ofnode_valid(mem)) {
                debug("%s: Missing /memory node\n", __func__);
                return -EINVAL;
        }
 
-       ret = fdt_get_resource(gd->fdt_blob, mem, "reg", 0, &res);
+       ret = ofnode_read_resource(mem, 0, &res);
        if (ret != 0) {
                debug("%s: Unable to decode first memory bank\n", __func__);
                return -EINVAL;
@@ -1057,42 +1059,42 @@ int fdtdec_setup_mem_size_base(void)
 
 #if defined(CONFIG_NR_DRAM_BANKS)
 
-static int get_next_memory_node(const void *blob, int mem)
+ofnode get_next_memory_node(ofnode mem)
 {
        do {
-               mem = fdt_node_offset_by_prop_value(gd->fdt_blob, mem,
-                                                   "device_type", "memory", 7);
-       } while (!fdtdec_get_is_enabled(blob, mem));
+               mem = ofnode_by_prop_value(mem, "device_type", "memory", 7);
+       } while (!ofnode_is_available(mem));
 
        return mem;
 }
 
 int fdtdec_setup_memory_banksize(void)
 {
-       int bank, ret, mem, reg = 0;
-       struct fdt_resource res;
+       int bank, ret, reg = 0;
+       struct resource res;
+       ofnode mem = ofnode_null();
 
-       mem = get_next_memory_node(gd->fdt_blob, -1);
-       if (mem < 0) {
+       mem = get_next_memory_node(mem);
+       if (!ofnode_valid(mem)) {
                debug("%s: Missing /memory node\n", __func__);
                return -EINVAL;
        }
 
        for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
-               ret = fdt_get_resource(gd->fdt_blob, mem, "reg", reg++, &res);
-               if (ret == -FDT_ERR_NOTFOUND) {
+               ret = ofnode_read_resource(mem, reg++, &res);
+               if (ret < 0) {
                        reg = 0;
-                       mem = get_next_memory_node(gd->fdt_blob, mem);
-                       if (mem == -FDT_ERR_NOTFOUND)
+                       mem = get_next_memory_node(mem);
+                       if (ofnode_valid(mem))
                                break;
 
-                       ret = fdt_get_resource(gd->fdt_blob, mem, "reg", reg++, &res);
-                       if (ret == -FDT_ERR_NOTFOUND)
+                       ret = ofnode_read_resource(mem, reg++, &res);
+                       if (ret < 0)
                                break;
                }
-               if (ret != 0) {
+
+               if (ret != 0)
                        return -EINVAL;
-               }
 
                gd->bd->bi_dram[bank].start = (phys_addr_t)res.start;
                gd->bd->bi_dram[bank].size =
@@ -1109,32 +1111,33 @@ int fdtdec_setup_memory_banksize(void)
 
 int fdtdec_setup_mem_size_base_lowest(void)
 {
-       int bank, ret, mem, reg = 0;
-       struct fdt_resource res;
+       int bank, ret, reg = 0;
+       struct resource res;
        unsigned long base;
        phys_size_t size;
-       const void *blob = gd->fdt_blob;
+       ofnode mem = ofnode_null();
 
        gd->ram_base = (unsigned long)~0;
 
-       mem = get_next_memory_node(blob, -1);
-       if (mem < 0) {
+       mem = get_next_memory_node(mem);
+       if (!ofnode_valid(mem)) {
                debug("%s: Missing /memory node\n", __func__);
                return -EINVAL;
        }
 
        for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
-               ret = fdt_get_resource(blob, mem, "reg", reg++, &res);
-               if (ret == -FDT_ERR_NOTFOUND) {
+               ret = ofnode_read_resource(mem, reg++, &res);
+               if (ret < 0) {
                        reg = 0;
-                       mem = get_next_memory_node(blob, mem);
-                       if (mem == -FDT_ERR_NOTFOUND)
+                       mem = get_next_memory_node(mem);
+                       if (ofnode_valid(mem))
                                break;
 
-                       ret = fdt_get_resource(blob, mem, "reg", reg++, &res);
-                       if (ret == -FDT_ERR_NOTFOUND)
+                       ret = ofnode_read_resource(mem, reg++, &res);
+                       if (ret < 0)
                                break;
                }
+
                if (ret != 0)
                        return -EINVAL;