"Das U-Boot" Source Tree

riscv: spacemit: k1: probe dram size during boot phase.

Implement functionality to probe and calculate the DRAM size
during the boot phase for the RISC-V spacemit K1 platform.

Tested-by: Marcel Ziswiler <marcel@ziswiler.com> # BPI-F3 16G
Signed-off-by: Huan Zhou <me@per1cycle.org>
Reviewed-by: Leo Yu-Chi Liang <ycliang@andestech.com>

authored by

Huan Zhou and committed by
Leo Yu-Chi Liang
3691fbcc b6d150b9

+38 -2
+38 -2
arch/riscv/cpu/k1/dram.c
··· 4 4 */ 5 5 6 6 #include <asm/global_data.h> 7 + #include <asm/io.h> 7 8 #include <config.h> 9 + #include <bitfield.h> 8 10 #include <fdt_support.h> 9 11 #include <linux/sizes.h> 10 12 13 + #define DDR_BASE 0xC0000000 11 14 DECLARE_GLOBAL_DATA_PTR; 12 15 16 + static phys_size_t ddr_map_size(u32 val) 17 + { 18 + u32 tmp; 19 + 20 + if (!(val & 0x1)) 21 + return 0; 22 + 23 + tmp = bitfield_extract(val, 16, 5); 24 + switch (tmp) { 25 + case 0xd: 26 + return 512; 27 + case 0xe: 28 + return 1024; 29 + case 0xf: 30 + return 2048; 31 + case 0x10: 32 + return 4096; 33 + case 0x11: 34 + return 8192; 35 + default: 36 + pr_info("Invalid DRAM density %x\n", val); 37 + return 0; 38 + } 39 + } 40 + 41 + phys_size_t ddr_get_density(void) 42 + { 43 + phys_size_t cs0_size = ddr_map_size(readl((void *)DDR_BASE + 0x200)); 44 + phys_size_t cs1_size = ddr_map_size(readl((void *)DDR_BASE + 0x208)); 45 + phys_size_t ddr_size = cs0_size + cs1_size; 46 + 47 + return ddr_size; 48 + } 49 + 13 50 int dram_init(void) 14 51 { 15 52 gd->ram_base = CFG_SYS_SDRAM_BASE; 16 - /* TODO get ram size from ddr controller */ 17 - gd->ram_size = SZ_4G; 53 + gd->ram_size = ddr_get_density() * SZ_1M; 18 54 return 0; 19 55 } 20 56