Merge tag 'rockchip-for-v2018.11' of git://git.denx.de/u-boot-rockchip
[oweals/u-boot.git] / arch / arm / mach-uniphier / dram_init.c
index 32d359321ae2899b6f730c77f5604b63feb75e8d..7e7c1d98db4088f1c513646d07f43344e340c8ae 100644 (file)
@@ -1,23 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (C) 2012-2015 Panasonic Corporation
  * Copyright (C) 2015-2017 Socionext Inc.
  *   Author: Masahiro Yamada <yamada.masahiro@socionext.com>
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
-#include <fdt_support.h>
-#include <fdtdec.h>
 #include <linux/errno.h>
+#include <linux/kernel.h>
+#include <linux/printk.h>
 #include <linux/sizes.h>
+#include <asm/global_data.h>
 
 #include "sg-regs.h"
 #include "soc-info.h"
 
-#define pr_warn(fmt, args...)  printf(fmt, ##args)
-#define pr_err(fmt, args...)   printf(fmt, ##args)
-
 DECLARE_GLOBAL_DATA_PTR;
 
 struct uniphier_memif_data {
@@ -205,6 +202,7 @@ int dram_init(void)
                return ret;
 
        for (i = 0; i < ARRAY_SIZE(dram_map); i++) {
+               unsigned long max_size;
 
                if (!dram_map[i].size)
                        break;
@@ -218,9 +216,32 @@ int dram_init(void)
                                                        dram_map[i].base)
                        break;
 
+               /*
+                * Do not use memory that exceeds 32bit address range.  U-Boot
+                * relocates itself to the end of the effectively available RAM.
+                * This could be a problem for DMA engines that do not support
+                * 64bit address (SDMA of SDHCI, UniPhier AV-ether, etc.)
+                */
+               if (dram_map[i].base >= 1ULL << 32)
+                       break;
+
+               max_size = (1ULL << 32) - dram_map[i].base;
+
+               if (dram_map[i].size > max_size) {
+                       gd->ram_size += max_size;
+                       break;
+               }
+
                gd->ram_size += dram_map[i].size;
        }
 
+       /*
+        * LD20 uses the last 64 byte for each channel for dynamic
+        * DDR PHY training
+        */
+       if (uniphier_get_soc_id() == UNIPHIER_LD20_ID)
+               gd->ram_size -= 64;
+
        return 0;
 }
 
@@ -241,36 +262,3 @@ int dram_init_banksize(void)
 
        return 0;
 }
-
-#ifdef CONFIG_OF_BOARD_SETUP
-/*
- * The DRAM PHY requires 64 byte scratch area in each DRAM channel
- * for its dynamic PHY training feature.
- */
-int ft_board_setup(void *fdt, bd_t *bd)
-{
-       unsigned long rsv_addr;
-       const unsigned long rsv_size = 64;
-       int i, ret;
-
-       if (uniphier_get_soc_id() != UNIPHIER_LD20_ID)
-               return 0;
-
-       for (i = 0; i < ARRAY_SIZE(gd->bd->bi_dram); i++) {
-               if (!gd->bd->bi_dram[i].size)
-                       continue;
-
-               rsv_addr = gd->bd->bi_dram[i].start + gd->bd->bi_dram[i].size;
-               rsv_addr -= rsv_size;
-
-               ret = fdt_add_mem_rsv(fdt, rsv_addr, rsv_size);
-               if (ret)
-                       return -ENOSPC;
-
-               printf("   Reserved memory region for DRAM PHY training: addr=%lx size=%lx\n",
-                      rsv_addr, rsv_size);
-       }
-
-       return 0;
-}
-#endif