All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] riscv: spacemit: k1: probe dram size during boot phase.
@ 2025-01-08  8:49 Huan Zhou
  2025-01-08 11:11 ` Yixun Lan
  2025-01-10 17:34 ` Marcel Ziswiler
  0 siblings, 2 replies; 13+ messages in thread
From: Huan Zhou @ 2025-01-08  8:49 UTC (permalink / raw)
  To: u-boot
  Cc: Ben Dooks, Marcel Ziswiler, Bin Meng, Dan Carpenter, Yixun Lan,
	Frieder Schrempf, Heinrich Schuchardt, Jonas Schwöbel,
	Kever Yang, Leo, Michal Simek, Nishanth Menon, Quentin Schulz,
	Randolph, Rick Chen, Samuel Holland, Sumit Garg, Svyatoslav Ryhel,
	Tom Rini, Yu Chien Peter Lin, Huan Zhou, Kongyang Liu,
	Padmarao Begari, Huan Zhou



---
This patch introduce improvement for get dram size on bananapi BPI-F3,
retrieving the dram size dynamically.
Have tested on bananapi BPIF3 4G and jupiter 8G.

Signed-off-by: Huan Zhou <me@per1cycle.org>
---
 arch/riscv/cpu/k1/dram.c | 40 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 38 insertions(+), 2 deletions(-)

diff --git a/arch/riscv/cpu/k1/dram.c b/arch/riscv/cpu/k1/dram.c
index c477c15cbfb19f0e3a0ee72985b602f5bda352d7..095217f2a4c053f7477d62c0776bcb51e623db47 100644
--- a/arch/riscv/cpu/k1/dram.c
+++ b/arch/riscv/cpu/k1/dram.c
@@ -4,17 +4,53 @@
  */
 
 #include <asm/global_data.h>
+#include <asm/io.h>
 #include <config.h>
+#include <bitfield.h>
 #include <fdt_support.h>
 #include <linux/sizes.h>
 
+#define DDR_BASE 0xC0000000
 DECLARE_GLOBAL_DATA_PTR;
 
+static inline u32 map_format_size(u32 val)
+{
+	u32 tmp;
+
+	if (val & 0x1 == 0)
+		return 0;
+
+	tmp = bitfield_extract(val, 16, 5);
+	switch (tmp) {
+	case 0xd:
+		return 512;
+	case 0xe:
+		return 1024;
+	case 0xf:
+		return 2048;
+	case 0x10:
+		return 4096;
+	case 0x11:
+		return 8192;
+	default:
+		pr_info("Invalid DRAM density %x\n", val);
+		return 0;
+	}
+}
+
+u32 ddr_get_density(void)
+{
+	u32 cs0_size = map_format_size(readl((void *)DDR_BASE + 0x200));
+	u32 cs1_size = map_format_size(readl((void *)DDR_BASE + 0x208));
+	u32 ddr_size = cs0_size + cs1_size;
+
+	return ddr_size;
+}
+
 int dram_init(void)
 {
 	gd->ram_base = CFG_SYS_SDRAM_BASE;
-	/* TODO get ram size from ddr controller */
-	gd->ram_size = SZ_4G;
+	gd->ram_size = (u64)ddr_get_density() * SZ_1M;
 	return 0;
 }
 

---
base-commit: 19fc0b7f7d907119a13e9c207991899f0817f8fc
change-id: 20250108-get-dram-size-65cf59a15201

Best regards,
-- 
Huan Zhou <me@per1cycle.org>


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2025-01-10 17:35 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-08  8:49 [PATCH] riscv: spacemit: k1: probe dram size during boot phase Huan Zhou
2025-01-08 11:11 ` Yixun Lan
2025-01-08 11:21   ` Heinrich Schuchardt
2025-01-08 11:51     ` Huan Zhou
2025-01-08 12:37     ` Dan Carpenter
2025-01-08 12:44       ` Huan Zhou
2025-01-08 17:03       ` Simon Glass
2025-01-08 17:15         ` Tom Rini
2025-01-08 17:18         ` Dan Carpenter
2025-01-09 12:36           ` Simon Glass
2025-01-08 11:21   ` Huan Zhou
2025-01-08 11:36   ` Huan Zhou
2025-01-10 17:34 ` Marcel Ziswiler

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.