realtek: determine memory size during initialization
authorMarkus Stockhausen <markus.stockhausen@gmx.de>
Tue, 30 Dec 2025 09:33:32 +0000 (10:33 +0100)
committerHauke Mehrtens <hauke@hauke-m.de>
Wed, 31 Dec 2025 20:55:32 +0000 (21:55 +0100)
For proper highmem initialization on RTL930x the size of the
installed memory is needed during early bootup. Enhance the
soc_info structure and fill the data from the registers.

While we are here remove the obsolete compatible variable from
the soc_info structure.

Adapt boot message to show the memory size.

old: SoC Type: Realtek RTL9301 rev B (6487)
new: Realtek RTL9301 rev B (6487) SoC with 512 MB

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/21327
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
target/linux/realtek/files-6.12/arch/mips/include/asm/mach-rtl838x/mach-rtl83xx.h
target/linux/realtek/files-6.12/arch/mips/rtl838x/prom.c

index 0a983995915af40ee9b18f59a4a6763bfbc4df75..8639661a94c68ba038474a1a679ad7da9cee69f4 100644 (file)
@@ -48,8 +48,8 @@ struct rtl83xx_soc_info {
        unsigned int revision;
        unsigned int cpu;
        bool testchip;
-       unsigned char *compatible;
        int cpu_port;
+       int memory_size;
 };
 
 #endif /* _MACH_RTL838X_H_ */
index 94d659913cbaa50f5952a46e32469c54994d67a3..f8c13ee49f6ef418d3455d27e3693f13f44d2fcf 100644 (file)
 
 #include <mach-rtl83xx.h>
 
+#define RTL_SOC_BASE                   ((volatile void *) 0xB8000000)
+#define RTL83XX_DRAM_CONFIG            0x1004
+#define RTL931X_DRAM_CONFIG            0x14304c
+
+#define soc_r32(reg)                   readl(RTL_SOC_BASE + reg)
+#define soc_w32(val, reg)              writel(val, RTL_SOC_BASE + reg)
+
 struct rtl83xx_soc_info soc_info;
 const void *fdt;
 
@@ -228,14 +235,31 @@ static void __init set_system_type(void)
                 soc_info.name, es, revision, soc_info.cpu);
 }
 
+static void get_system_memory(void)
+{
+       unsigned int dcr, bits;
+
+       if (soc_info.family == RTL9310_FAMILY_ID) {
+               dcr = soc_r32(RTL931X_DRAM_CONFIG);
+               bits = (dcr >> 12) + ((dcr >> 6) & 0x3f) + (dcr & 0x3f);
+       } else {
+               dcr = soc_r32(RTL83XX_DRAM_CONFIG);
+               bits = ((dcr >> 28) & 0x3) + ((dcr >> 24) & 0x3) +
+                      ((dcr >> 20) & 0xf) + ((dcr >> 16) & 0xf) + 20;
+       }
+
+       soc_info.memory_size = 1 << bits;
+}
+
 void __init prom_init(void)
 {
        u32 model = read_model();
 
        parse_model(model);
        set_system_type();
+       get_system_memory();
 
-       pr_info("SoC Type: %s\n", get_system_type());
+       pr_info("%s SoC with %d MB\n", get_system_type(), soc_info.memory_size >> 20);
 
        /*
         * fw_arg2 is be the pointer to the environment. Some devices (e.g. HP JG924A) hand