The get_ram_size() function in U-Boot can only deal with memory size
smaller than 2GiB. To enable the support of 3GiB DRAM on newer 64-bit
SoCs, an alternative way to detect DRAM size is needed.

Add the possibility to use some DRAM size recalculating code in DRAM
driver.

Signed-off-by: Icenowy Zheng <[email protected]>
---
New patch in v2.

 arch/arm/include/asm/arch-sunxi/dram.h | 3 +++
 arch/arm/mach-sunxi/Kconfig            | 7 +++++++
 board/sunxi/board.c                    | 8 ++++++++
 3 files changed, 18 insertions(+)

diff --git a/arch/arm/include/asm/arch-sunxi/dram.h 
b/arch/arm/include/asm/arch-sunxi/dram.h
index d08b82371d..7443fc3507 100644
--- a/arch/arm/include/asm/arch-sunxi/dram.h
+++ b/arch/arm/include/asm/arch-sunxi/dram.h
@@ -35,5 +35,8 @@
 unsigned long long sunxi_dram_init(void);
 void mctl_await_completion(u32 *reg, u32 mask, u32 val);
 bool mctl_mem_matches(u32 offset);
+#if defined(CONFIG_DRAM_CAN_RECALCULATE_SIZE)
+unsigned long long sunxi_dram_recalculate_size(void);
+#endif
 
 #endif /* _SUNXI_DRAM_H */
diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig
index 029821c82d..b206472ead 100644
--- a/arch/arm/mach-sunxi/Kconfig
+++ b/arch/arm/mach-sunxi/Kconfig
@@ -6,6 +6,13 @@ config SPL_LDSCRIPT
 config IDENT_STRING
        default " Allwinner Technology"
 
+config DRAM_CAN_RECALCULATE_SIZE
+       bool
+       help
+         Select this if the DRAM controller driver is capable of
+         re-calculating the size in main U-Boot. It's usable for
+         size bigger than 2GiB.
+
 config DRAM_SUN4I
        bool
        help
diff --git a/board/sunxi/board.c b/board/sunxi/board.c
index 73dd41437d..96192a7ec3 100644
--- a/board/sunxi/board.c
+++ b/board/sunxi/board.c
@@ -256,7 +256,16 @@ int board_init(void)
 
 int dram_init(void)
 {
+#ifndef CONFIG_DRAM_CAN_RECALCULATE_SIZE
        gd->ram_size = get_ram_size((long *)PHYS_SDRAM_0, PHYS_SDRAM_0_SIZE);
+#else
+       unsigned long long real_dram_size = sunxi_dram_recalculate_size();
+
+       if (real_dram_size > CONFIG_SUNXI_DRAM_MAX_SIZE)
+               gd->ram_size = CONFIG_SUNXI_DRAM_MAX_SIZE;
+       else
+               gd->ram_size = (phys_size_t)real_dram_size;
+#endif
 
        return 0;
 }
-- 
2.15.1

_______________________________________________
U-Boot mailing list
[email protected]
https://lists.denx.de/listinfo/u-boot

Reply via email to