samsung:board: dram_init(): alloc memory to store fdt dram info
authorPrzemyslaw Marczak <p.marczak@samsung.com>
Thu, 18 Sep 2014 14:20:29 +0000 (16:20 +0200)
committerJaehoon Chung <jh80.chung@samsung.com>
Thu, 10 Oct 2019 04:38:35 +0000 (13:38 +0900)
For CONFIG_OF_MULTI the dram_init() function gets memory information
from the device tree blob by the call to fdtdec_decode_memory().
The same is done second time in dram_init_banksize() - this was the
simplest because board info structure is not initialized at dram_init()
stage.

This change uses malloc and gd->priv pointer to store the memory banks
parameters and next uses it in dram_init_banksize().

Thanks to this change, the boot time decreases, because, the function
fdtdec_decode_memory() is called only once.

Change-Id: I8f357c6a641d4440f32d2fe24d7e1e2dc5bc4a3d
Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
board/samsung/common/board.c
board/samsung/common/misc.c
include/samsung/misc.h
include/samsung/multi-plat.h [new file with mode: 0644]

index fdd13c4..ae0b8d4 100644 (file)
@@ -20,6 +20,8 @@
 #include <asm/arch/pinmux.h>
 #include <asm/arch/power.h>
 #include <asm/arch/system.h>
+#include <malloc.h>
+#include <power/pmic.h>
 #include <asm/arch/sromc.h>
 #include <lcd.h>
 #include <i2c.h>
@@ -28,6 +30,7 @@
 #include <samsung/misc.h>
 #include <dm/pinctrl.h>
 #include <dm.h>
+#include <samsung/multi-plat.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -99,15 +102,19 @@ int dram_init(void)
 {
        unsigned int i;
 #ifdef CONFIG_FDTDEC_MEMORY
-       int dram_banks;
+       struct memory_info *mem;
 
-       uint64_t mem_size[CONFIG_NR_DRAM_BANKS];
+       mem = malloc(sizeof(struct memory_info));
 
-       dram_banks = fdtdec_decode_memory(gd->fdt_blob, NULL, mem_size,
+       mem->banks = fdtdec_decode_memory(gd->fdt_blob, &mem->addr[0],
+                                         &mem->size[0],
                                          CONFIG_NR_DRAM_BANKS);
 
-       for (i = 0; i < dram_banks; i++)
-               gd->ram_size += (uint32_t)mem_size[i];
+       for (i = 0; i < mem->banks; i++)
+               gd->ram_size += (uint32_t)mem->size[i];
+
+       /* Save the mem_info for dram_init_banksize() */
+       gd->priv = mem;
 #else
        unsigned long addr;
 
@@ -123,17 +130,11 @@ int dram_init_banksize(void)
 {
        unsigned int i;
 #ifdef CONFIG_FDTDEC_MEMORY
-       int dram_banks;
-
-       uint64_t mem_addr[CONFIG_NR_DRAM_BANKS];
-       uint64_t mem_size[CONFIG_NR_DRAM_BANKS];
-
-       dram_banks = fdtdec_decode_memory(gd->fdt_blob, mem_addr, mem_size,
-                                         CONFIG_NR_DRAM_BANKS);
+       struct memory_info *mem = gd->priv;
 
-       for (i = 0; i < dram_banks; i++) {
-               gd->bd->bi_dram[i].start = (uint32_t)mem_addr[i];
-               gd->bd->bi_dram[i].size = (uint32_t)mem_size[i];
+       for (i = 0; i < mem->banks ; i++) {
+               gd->bd->bi_dram[i].start = (uint32_t)mem->addr[i];
+               gd->bd->bi_dram[i].size = (uint32_t)mem->size[i];
        }
 #else
        unsigned long addr, size;
index 8199647..63b5931 100644 (file)
@@ -101,6 +101,9 @@ void set_board_info(void)
        if (!bdtype)
                bdtype = "";
 
+#ifdef CONFIG_OF_MULTI
+       bdname = get_board_name();
+#endif
        sprintf(info, "%s%s", bdname, bdtype);
        env_set("board_name", info);
 #endif
index a61b099..d39f3e1 100644 (file)
@@ -63,8 +63,13 @@ void draw_logo(void);
 char *get_dfu_alt_system(char *interface, char *devstr);
 char *get_dfu_alt_boot(char *interface, char *devstr);
 #endif
+#ifdef CONFIG_BOARD_TYPES
 void set_board_type(void);
 void set_board_revision(void);
 const char *get_board_type(void);
+#ifdef CONFIG_OF_MULTI
+const char *get_board_name(void);
+#endif
+#endif
 
 #endif /* __SAMSUNG_MISC_COMMON_H__ */
diff --git a/include/samsung/multi-plat.h b/include/samsung/multi-plat.h
new file mode 100644 (file)
index 0000000..29f5f50
--- /dev/null
@@ -0,0 +1,13 @@
+#ifndef __INCLUDE__MULTI_PLAT__H__
+#define __INCLUDE__MULTI_PLAT__H__
+
+#include <common.h>
+
+#ifdef CONFIG_OF_MULTI
+struct memory_info {
+       uint64_t addr[CONFIG_NR_DRAM_BANKS];
+       uint64_t size[CONFIG_NR_DRAM_BANKS];
+       uint32_t banks;
+};
+#endif
+#endif
\ No newline at end of file