Merge branch 'master' of git://git.denx.de/u-boot-video
[oweals/u-boot.git] / lib / fdtdec.c
index 45f3fe7baf8e76505e4b769bb945a62452ba1522..d28f2cbb1cf6a9aad1492bb294a3f84a02619826 100644 (file)
@@ -1,6 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (c) 2011 The Chromium OS Authors.
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #ifndef USE_HOSTCC
@@ -11,7 +11,7 @@
 #include <errno.h>
 #include <fdtdec.h>
 #include <fdt_support.h>
-#include <libfdt.h>
+#include <linux/libfdt.h>
 #include <serial.h>
 #include <asm/sections.h>
 #include <linux/ctype.h>
@@ -48,7 +48,6 @@ static const char * const compat_names[COMPAT_COUNT] = {
        COMPAT(SAMSUNG_EXYNOS_MIPI_DSI, "samsung,exynos-mipi-dsi"),
        COMPAT(SAMSUNG_EXYNOS_DWMMC, "samsung,exynos-dwmmc"),
        COMPAT(SAMSUNG_EXYNOS_MMC, "samsung,exynos-mmc"),
-       COMPAT(MAXIM_MAX77686_PMIC, "maxim,max77686"),
        COMPAT(GENERIC_SPI_FLASH, "spi-flash"),
        COMPAT(MAXIM_98095_CODEC, "maxim,max98095-codec"),
        COMPAT(SAMSUNG_EXYNOS5_I2C, "samsung,exynos5-hsi2c"),
@@ -71,6 +70,9 @@ static const char * const compat_names[COMPAT_COUNT] = {
        COMPAT(ALTERA_SOCFPGA_F2SDR0, "altr,socfpga-fpga2sdram0-bridge"),
        COMPAT(ALTERA_SOCFPGA_F2SDR1, "altr,socfpga-fpga2sdram1-bridge"),
        COMPAT(ALTERA_SOCFPGA_F2SDR2, "altr,socfpga-fpga2sdram2-bridge"),
+       COMPAT(ALTERA_SOCFPGA_FPGA0, "altr,socfpga-a10-fpga-mgr"),
+       COMPAT(ALTERA_SOCFPGA_NOC, "altr,socfpga-a10-noc"),
+       COMPAT(ALTERA_SOCFPGA_CLK_INIT, "altr,socfpga-a10-clk-init")
 };
 
 const char *fdtdec_get_compatible(enum fdt_compat_id id)
@@ -81,8 +83,9 @@ const char *fdtdec_get_compatible(enum fdt_compat_id id)
 }
 
 fdt_addr_t fdtdec_get_addr_size_fixed(const void *blob, int node,
-               const char *prop_name, int index, int na, int ns,
-               fdt_size_t *sizep, bool translate)
+                                     const char *prop_name, int index, int na,
+                                     int ns, fdt_size_t *sizep,
+                                     bool translate)
 {
        const fdt32_t *prop, *prop_end;
        const fdt32_t *prop_addr, *prop_size, *prop_after_size;
@@ -136,8 +139,9 @@ fdt_addr_t fdtdec_get_addr_size_fixed(const void *blob, int node,
 }
 
 fdt_addr_t fdtdec_get_addr_size_auto_parent(const void *blob, int parent,
-               int node, const char *prop_name, int index, fdt_size_t *sizep,
-               bool translate)
+                                           int node, const char *prop_name,
+                                           int index, fdt_size_t *sizep,
+                                           bool translate)
 {
        int na, ns;
 
@@ -162,8 +166,9 @@ fdt_addr_t fdtdec_get_addr_size_auto_parent(const void *blob, int parent,
 }
 
 fdt_addr_t fdtdec_get_addr_size_auto_noparent(const void *blob, int node,
-               const char *prop_name, int index, fdt_size_t *sizep,
-               bool translate)
+                                             const char *prop_name, int index,
+                                             fdt_size_t *sizep,
+                                             bool translate)
 {
        int parent;
 
@@ -180,7 +185,7 @@ fdt_addr_t fdtdec_get_addr_size_auto_noparent(const void *blob, int node,
 }
 
 fdt_addr_t fdtdec_get_addr_size(const void *blob, int node,
-               const char *prop_name, fdt_size_t *sizep)
+                               const char *prop_name, fdt_size_t *sizep)
 {
        int ns = sizep ? (sizeof(fdt_size_t) / sizeof(fdt32_t)) : 0;
 
@@ -189,15 +194,14 @@ fdt_addr_t fdtdec_get_addr_size(const void *blob, int node,
                                          ns, sizep, false);
 }
 
-fdt_addr_t fdtdec_get_addr(const void *blob, int node,
-               const char *prop_name)
+fdt_addr_t fdtdec_get_addr(const void *blob, int node, const char *prop_name)
 {
        return fdtdec_get_addr_size(blob, node, prop_name, NULL);
 }
 
 #if defined(CONFIG_PCI) && defined(CONFIG_DM_PCI)
 int fdtdec_get_pci_addr(const void *blob, int node, enum fdt_pci_space type,
-               const char *prop_name, struct fdt_pci_addr *addr)
+                       const char *prop_name, struct fdt_pci_addr *addr)
 {
        const u32 *cell;
        int len;
@@ -229,10 +233,10 @@ int fdtdec_get_pci_addr(const void *blob, int 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) {
@@ -241,10 +245,10 @@ int fdtdec_get_pci_addr(const void *blob, int node, enum fdt_pci_space type,
                }
 
                return 0;
-       } else {
-               ret = -EINVAL;
        }
 
+       ret = -EINVAL;
+
 fail:
        debug("(not found)\n");
        return ret;
@@ -261,11 +265,9 @@ int fdtdec_get_pci_vendev(const void *blob, int node, u16 *vendor, u16 *device)
 
        end = list + len;
        while (list < end) {
-               char *s;
-
                len = strlen(list);
                if (len >= strlen("pciVVVV,DDDD")) {
-                       s = strstr(list, "pci");
+                       char *s = strstr(list, "pci");
 
                        /*
                         * check if the string is something like pciVVVV,DDDD.RR
@@ -295,7 +297,7 @@ int fdtdec_get_pci_bar32(struct udevice *dev, struct fdt_pci_addr *addr,
 
        /* extract the bar number from fdt_pci_addr */
        barnum = addr->phys_hi & 0xff;
-       if ((barnum < PCI_BASE_ADDRESS_0) || (barnum > PCI_CARDBUS_CIS))
+       if (barnum < PCI_BASE_ADDRESS_0 || barnum > PCI_CARDBUS_CIS)
                return -EINVAL;
 
        barnum = (barnum - PCI_BASE_ADDRESS_0) / 4;
@@ -306,7 +308,7 @@ int fdtdec_get_pci_bar32(struct udevice *dev, struct fdt_pci_addr *addr,
 #endif
 
 uint64_t fdtdec_get_uint64(const void *blob, int node, const char *prop_name,
-               uint64_t default_val)
+                          uint64_t default_val)
 {
        const uint64_t *cell64;
        int length;
@@ -331,7 +333,7 @@ int fdtdec_get_is_enabled(const void *blob, int node)
         */
        cell = fdt_getprop(blob, node, "status", NULL);
        if (cell)
-               return 0 == strcmp(cell, "okay");
+               return strcmp(cell, "okay") == 0;
        return 1;
 }
 
@@ -341,20 +343,19 @@ enum fdt_compat_id fdtdec_lookup(const void *blob, int node)
 
        /* Search our drivers */
        for (id = COMPAT_UNKNOWN; id < COMPAT_COUNT; id++)
-               if (0 == fdt_node_check_compatible(blob, node,
-                               compat_names[id]))
+               if (fdt_node_check_compatible(blob, node,
+                                             compat_names[id]) == 0)
                        return id;
        return COMPAT_UNKNOWN;
 }
 
-int fdtdec_next_compatible(const void *blob, int node,
-               enum fdt_compat_id id)
+int fdtdec_next_compatible(const void *blob, int node, enum fdt_compat_id id)
 {
        return fdt_node_offset_by_compatible(blob, node, compat_names[id]);
 }
 
 int fdtdec_next_compatible_subnode(const void *blob, int node,
-               enum fdt_compat_id id, int *depthp)
+                                  enum fdt_compat_id id, int *depthp)
 {
        do {
                node = fdt_next_node(blob, node, depthp);
@@ -368,8 +369,8 @@ int fdtdec_next_compatible_subnode(const void *blob, int node,
        return -FDT_ERR_NOTFOUND;
 }
 
-int fdtdec_next_alias(const void *blob, const char *name,
-               enum fdt_compat_id id, int *upto)
+int fdtdec_next_alias(const void *blob, const char *name, enum fdt_compat_id id,
+                     int *upto)
 {
 #define MAX_STR_LEN 20
        char str[MAX_STR_LEN + 20];
@@ -391,7 +392,8 @@ int fdtdec_next_alias(const void *blob, const char *name,
 }
 
 int fdtdec_find_aliases_for_id(const void *blob, const char *name,
-                       enum fdt_compat_id id, int *node_list, int maxcount)
+                              enum fdt_compat_id id, int *node_list,
+                              int maxcount)
 {
        memset(node_list, '\0', sizeof(*node_list) * maxcount);
 
@@ -400,7 +402,8 @@ int fdtdec_find_aliases_for_id(const void *blob, const char *name,
 
 /* TODO: Can we tighten this code up a little? */
 int fdtdec_add_aliases_for_id(const void *blob, const char *name,
-                       enum fdt_compat_id id, int *node_list, int maxcount)
+                             enum fdt_compat_id id, int *node_list,
+                             int maxcount)
 {
        int name_len = strlen(name);
        int nodes[maxcount];
@@ -427,7 +430,7 @@ int fdtdec_add_aliases_for_id(const void *blob, const char *name,
        }
        if (node >= 0)
                debug("%s: warning: maxcount exceeded with alias '%s'\n",
-                      __func__, name);
+                     __func__, name);
 
        /* Now find all the aliases */
        for (offset = fdt_first_property_offset(blob, alias_node);
@@ -450,7 +453,7 @@ int fdtdec_add_aliases_for_id(const void *blob, const char *name,
                number = simple_strtoul(path + name_len, NULL, 10);
                if (number < 0 || number >= maxcount) {
                        debug("%s: warning: alias '%s' is out of range\n",
-                              __func__, path);
+                             __func__, path);
                        continue;
                }
 
@@ -496,7 +499,7 @@ int fdtdec_add_aliases_for_id(const void *blob, const char *name,
                if (!node_list[i]) {
                        for (; j < maxcount; j++)
                                if (nodes[j] &&
-                                       fdtdec_get_is_enabled(blob, nodes[j]))
+                                   fdtdec_get_is_enabled(blob, nodes[j]))
                                        break;
 
                        /* Have we run out of nodes to add? */
@@ -639,7 +642,8 @@ int fdtdec_lookup_phandle(const void *blob, int node, const char *prop_name)
  * @return pointer to cell, which is only valid if err == 0
  */
 static const void *get_prop_check_min_len(const void *blob, int node,
-               const char *prop_name, int min_len, int *err)
+                                         const char *prop_name, int min_len,
+                                         int *err)
 {
        const void *cell;
        int len;
@@ -656,15 +660,17 @@ static const void *get_prop_check_min_len(const void *blob, int node,
 }
 
 int fdtdec_get_int_array(const void *blob, int node, const char *prop_name,
-               u32 *array, int count)
+                        u32 *array, int count)
 {
        const u32 *cell;
-       int i, err = 0;
+       int err = 0;
 
        debug("%s: %s\n", __func__, prop_name);
        cell = get_prop_check_min_len(blob, node, prop_name,
                                      sizeof(u32) * count, &err);
        if (!err) {
+               int i;
+
                for (i = 0; i < count; i++)
                        array[i] = fdt32_to_cpu(cell[i]);
        }
@@ -848,7 +854,7 @@ int fdtdec_get_child_count(const void *blob, int node)
 }
 
 int fdtdec_get_byte_array(const void *blob, int node, const char *prop_name,
-               u8 *array, int count)
+                         u8 *array, int count)
 {
        const u8 *cell;
        int err;
@@ -860,7 +866,7 @@ int fdtdec_get_byte_array(const void *blob, int node, const char *prop_name,
 }
 
 const u8 *fdtdec_locate_byte_array(const void *blob, int node,
-                            const char *prop_name, int count)
+                                  const char *prop_name, int count)
 {
        const u8 *cell;
        int err;
@@ -872,7 +878,7 @@ const u8 *fdtdec_locate_byte_array(const void *blob, int node,
 }
 
 int fdtdec_get_config_int(const void *blob, const char *prop_name,
-               int default_val)
+                         int default_val)
 {
        int config_node;
 
@@ -915,28 +921,6 @@ char *fdtdec_get_config_string(const void *blob, const char *prop_name)
        return (char *)nodep;
 }
 
-int fdtdec_decode_region(const void *blob, int node, const char *prop_name,
-                        fdt_addr_t *basep, fdt_size_t *sizep)
-{
-       const fdt_addr_t *cell;
-       int len;
-
-       debug("%s: %s: %s\n", __func__, fdt_get_name(blob, node, NULL),
-             prop_name);
-       cell = fdt_getprop(blob, node, prop_name, &len);
-       if (!cell || (len < sizeof(fdt_addr_t) * 2)) {
-               debug("cell=%p, len=%d\n", cell, len);
-               return -1;
-       }
-
-       *basep = fdt_addr_to_cpu(*cell);
-       *sizep = fdt_size_to_cpu(cell[1]);
-       debug("%s: base=%08lx, size=%lx\n", __func__, (ulong)*basep,
-             (ulong)*sizep);
-
-       return 0;
-}
-
 u64 fdtdec_get_number(const fdt32_t *ptr, unsigned int cells)
 {
        u64 number = 0;
@@ -969,7 +953,8 @@ int fdt_get_resource(const void *fdt, int node, const char *property,
 
        while (ptr + na + ns <= end) {
                if (i == index) {
-                       res->start = res->end = fdtdec_get_number(ptr, na);
+                       res->start = fdtdec_get_number(ptr, na);
+                       res->end = res->start;
                        res->end += fdtdec_get_number(&ptr[na], ns) - 1;
                        return 0;
                }
@@ -994,67 +979,6 @@ int fdt_get_named_resource(const void *fdt, int node, const char *property,
        return fdt_get_resource(fdt, node, property, index, res);
 }
 
-int fdtdec_decode_memory_region(const void *blob, int config_node,
-                               const char *mem_type, const char *suffix,
-                               fdt_addr_t *basep, fdt_size_t *sizep)
-{
-       char prop_name[50];
-       const char *mem;
-       fdt_size_t size, offset_size;
-       fdt_addr_t base, offset;
-       int node;
-
-       if (config_node == -1) {
-               config_node = fdt_path_offset(blob, "/config");
-               if (config_node < 0) {
-                       debug("%s: Cannot find /config node\n", __func__);
-                       return -ENOENT;
-               }
-       }
-       if (!suffix)
-               suffix = "";
-
-       snprintf(prop_name, sizeof(prop_name), "%s-memory%s", mem_type,
-                suffix);
-       mem = fdt_getprop(blob, config_node, prop_name, NULL);
-       if (!mem) {
-               debug("%s: No memory type for '%s', using /memory\n", __func__,
-                     prop_name);
-               mem = "/memory";
-       }
-
-       node = fdt_path_offset(blob, mem);
-       if (node < 0) {
-               debug("%s: Failed to find node '%s': %s\n", __func__, mem,
-                     fdt_strerror(node));
-               return -ENOENT;
-       }
-
-       /*
-        * Not strictly correct - the memory may have multiple banks. We just
-        * use the first
-        */
-       if (fdtdec_decode_region(blob, node, "reg", &base, &size)) {
-               debug("%s: Failed to decode memory region %s\n", __func__,
-                     mem);
-               return -EINVAL;
-       }
-
-       snprintf(prop_name, sizeof(prop_name), "%s-offset%s", mem_type,
-                suffix);
-       if (fdtdec_decode_region(blob, config_node, prop_name, &offset,
-                                &offset_size)) {
-               debug("%s: Failed to decode memory region '%s'\n", __func__,
-                     prop_name);
-               return -EINVAL;
-       }
-
-       *basep = base + offset;
-       *sizep = offset_size;
-
-       return 0;
-}
-
 static int decode_timing_property(const void *blob, int node, const char *name,
                                  struct timing_entry *result)
 {
@@ -1147,7 +1071,7 @@ int fdtdec_decode_display_timing(const void *blob, int parent, int index,
        return ret;
 }
 
-int fdtdec_setup_memory_size(void)
+int fdtdec_setup_mem_size_base(void)
 {
        int ret, mem;
        struct fdt_resource res;
@@ -1165,6 +1089,7 @@ int fdtdec_setup_memory_size(void)
        }
 
        gd->ram_size = (phys_size_t)(res.end - res.start + 1);
+       gd->ram_base = (unsigned long)res.start;
        debug("%s: Initial DRAM size %llx\n", __func__,
              (unsigned long long)gd->ram_size);
 
@@ -1172,23 +1097,43 @@ int fdtdec_setup_memory_size(void)
 }
 
 #if defined(CONFIG_NR_DRAM_BANKS)
+
+static int get_next_memory_node(const void *blob, int mem)
+{
+       do {
+               mem = fdt_node_offset_by_prop_value(gd->fdt_blob, mem,
+                                                   "device_type", "memory", 7);
+       } while (!fdtdec_get_is_enabled(blob, mem));
+
+       return mem;
+}
+
 int fdtdec_setup_memory_banksize(void)
 {
-       int bank, ret, mem;
+       int bank, ret, mem, reg = 0;
        struct fdt_resource res;
 
-       mem = fdt_path_offset(gd->fdt_blob, "/memory");
+       mem = get_next_memory_node(gd->fdt_blob, -1);
        if (mem < 0) {
                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", bank, &res);
-               if (ret == -FDT_ERR_NOTFOUND)
-                       break;
-               if (ret != 0)
+               ret = fdt_get_resource(gd->fdt_blob, mem, "reg", reg++, &res);
+               if (ret == -FDT_ERR_NOTFOUND) {
+                       reg = 0;
+                       mem = get_next_memory_node(gd->fdt_blob, mem);
+                       if (mem == -FDT_ERR_NOTFOUND)
+                               break;
+
+                       ret = fdt_get_resource(gd->fdt_blob, mem, "reg", reg++, &res);
+                       if (ret == -FDT_ERR_NOTFOUND)
+                               break;
+               }
+               if (ret != 0) {
                        return -EINVAL;
+               }
 
                gd->bd->bi_dram[bank].start = (phys_addr_t)res.start;
                gd->bd->bi_dram[bank].size =
@@ -1253,11 +1198,34 @@ static int uncompress_blob(const void *src, ulong sz_src, void **dstp)
 # else
 static int uncompress_blob(const void *src, ulong sz_src, void **dstp)
 {
-       return -ENOTSUPP;
+       *dstp = (void *)src;
+       return 0;
 }
 # endif
 #endif
 
+#if defined(CONFIG_OF_BOARD) || defined(CONFIG_OF_SEPARATE)
+/*
+ * For CONFIG_OF_SEPARATE, the board may optionally implement this to
+ * provide and/or fixup the fdt.
+ */
+__weak void *board_fdt_blob_setup(void)
+{
+       void *fdt_blob = NULL;
+#ifdef CONFIG_SPL_BUILD
+       /* FDT is at end of BSS unless it is in a different memory region */
+       if (IS_ENABLED(CONFIG_SPL_SEPARATE_BSS))
+               fdt_blob = (ulong *)&_image_binary_end;
+       else
+               fdt_blob = (ulong *)&__bss_end;
+#else
+       /* FDT is at end of image */
+       fdt_blob = (ulong *)&_end;
+#endif
+       return fdt_blob;
+}
+#endif
+
 int fdtdec_setup(void)
 {
 #if CONFIG_IS_ENABLED(OF_CONTROL)
@@ -1266,19 +1234,12 @@ int fdtdec_setup(void)
 # endif
 # ifdef CONFIG_OF_EMBED
        /* Get a pointer to the FDT */
-       gd->fdt_blob = __dtb_dt_begin;
-# elif defined CONFIG_OF_SEPARATE
 #  ifdef CONFIG_SPL_BUILD
-       /* FDT is at end of BSS unless it is in a different memory region */
-       if (IS_ENABLED(CONFIG_SPL_SEPARATE_BSS))
-               gd->fdt_blob = (ulong *)&_image_binary_end;
-       else
-               gd->fdt_blob = (ulong *)&__bss_end;
+       gd->fdt_blob = __dtb_dt_spl_begin;
 #  else
-       /* FDT is at end of image */
-       gd->fdt_blob = (ulong *)&_end;
+       gd->fdt_blob = __dtb_dt_begin;
 #  endif
-# elif defined(CONFIG_OF_BOARD)
+# elif defined(CONFIG_OF_BOARD) || defined(CONFIG_OF_SEPARATE)
        /* Allow the board to override the fdt address. */
        gd->fdt_blob = board_fdt_blob_setup();
 # elif defined(CONFIG_OF_HOSTFILE)
@@ -1289,8 +1250,12 @@ int fdtdec_setup(void)
 # endif
 # ifndef CONFIG_SPL_BUILD
        /* Allow the early environment to override the fdt address */
+#  if CONFIG_IS_ENABLED(OF_PRIOR_STAGE)
+       gd->fdt_blob = (void *)prior_stage_fdt_address;
+#  else
        gd->fdt_blob = (void *)env_get_ulong("fdtcontroladdr", 16,
                                                (uintptr_t)gd->fdt_blob);
+#  endif
 # endif
 
 # if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
@@ -1316,4 +1281,111 @@ int fdtdec_setup(void)
        return fdtdec_prepare_fdt();
 }
 
+#ifdef CONFIG_NR_DRAM_BANKS
+int fdtdec_decode_ram_size(const void *blob, const char *area, int board_id,
+                          phys_addr_t *basep, phys_size_t *sizep, bd_t *bd)
+{
+       int addr_cells, size_cells;
+       const u32 *cell, *end;
+       u64 total_size, size, addr;
+       int node, child;
+       bool auto_size;
+       int bank;
+       int len;
+
+       debug("%s: board_id=%d\n", __func__, board_id);
+       if (!area)
+               area = "/memory";
+       node = fdt_path_offset(blob, area);
+       if (node < 0) {
+               debug("No %s node found\n", area);
+               return -ENOENT;
+       }
+
+       cell = fdt_getprop(blob, node, "reg", &len);
+       if (!cell) {
+               debug("No reg property found\n");
+               return -ENOENT;
+       }
+
+       addr_cells = fdt_address_cells(blob, node);
+       size_cells = fdt_size_cells(blob, node);
+
+       /* Check the board id and mask */
+       for (child = fdt_first_subnode(blob, node);
+            child >= 0;
+            child = fdt_next_subnode(blob, child)) {
+               int match_mask, match_value;
+
+               match_mask = fdtdec_get_int(blob, child, "match-mask", -1);
+               match_value = fdtdec_get_int(blob, child, "match-value", -1);
+
+               if (match_value >= 0 &&
+                   ((board_id & match_mask) == match_value)) {
+                       /* Found matching mask */
+                       debug("Found matching mask %d\n", match_mask);
+                       node = child;
+                       cell = fdt_getprop(blob, node, "reg", &len);
+                       if (!cell) {
+                               debug("No memory-banks property found\n");
+                               return -EINVAL;
+                       }
+                       break;
+               }
+       }
+       /* Note: if no matching subnode was found we use the parent node */
+
+       if (bd) {
+               memset(bd->bi_dram, '\0', sizeof(bd->bi_dram[0]) *
+                                               CONFIG_NR_DRAM_BANKS);
+       }
+
+       auto_size = fdtdec_get_bool(blob, node, "auto-size");
+
+       total_size = 0;
+       end = cell + len / 4 - addr_cells - size_cells;
+       debug("cell at %p, end %p\n", cell, end);
+       for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
+               if (cell > end)
+                       break;
+               addr = 0;
+               if (addr_cells == 2)
+                       addr += (u64)fdt32_to_cpu(*cell++) << 32UL;
+               addr += fdt32_to_cpu(*cell++);
+               if (bd)
+                       bd->bi_dram[bank].start = addr;
+               if (basep && !bank)
+                       *basep = (phys_addr_t)addr;
+
+               size = 0;
+               if (size_cells == 2)
+                       size += (u64)fdt32_to_cpu(*cell++) << 32UL;
+               size += fdt32_to_cpu(*cell++);
+
+               if (auto_size) {
+                       u64 new_size;
+
+                       debug("Auto-sizing %llx, size %llx: ", addr, size);
+                       new_size = get_ram_size((long *)(uintptr_t)addr, size);
+                       if (new_size == size) {
+                               debug("OK\n");
+                       } else {
+                               debug("sized to %llx\n", new_size);
+                               size = new_size;
+                       }
+               }
+
+               if (bd)
+                       bd->bi_dram[bank].size = size;
+               total_size += size;
+       }
+
+       debug("Memory size %llu\n", total_size);
+       if (sizep)
+               *sizep = (phys_size_t)total_size;
+
+       return 0;
+}
+#endif /* CONFIG_NR_DRAM_BANKS */
+
 #endif /* !USE_HOSTCC */