3 * Marvell Semiconductor <www.marvell.com>
4 * Written-by: Lei Wen <leiwen@marvell.com>,
6 * SPDX-License-Identifier: GPL-2.0+
11 #include <asm/arch/pantheon.h>
13 DECLARE_GLOBAL_DATA_PTR;
16 * Pantheon DRAM controller supports upto 8 banks
17 * for chip select 0 and 1
21 * DDR Memory Control Registers
24 struct panthddr_map_registers {
25 u32 cs; /* Memory Address Map Register -CS */
29 struct panthddr_registers {
30 u8 pad[0x100 - 0x000];
31 struct panthddr_map_registers mmap[2];
35 * panth_sdram_base - reads SDRAM Base Address Register
37 u32 panth_sdram_base(int chip_sel)
39 struct panthddr_registers *ddr_regs =
40 (struct panthddr_registers *)PANTHEON_DRAM_BASE;
42 u32 CS_valid = 0x01 & readl(&ddr_regs->mmap[chip_sel].cs);
47 result = readl(&ddr_regs->mmap[chip_sel].cs) & 0xFF800000;
52 * panth_sdram_size - reads SDRAM size
54 u32 panth_sdram_size(int chip_sel)
56 struct panthddr_registers *ddr_regs =
57 (struct panthddr_registers *)PANTHEON_DRAM_BASE;
59 u32 CS_valid = 0x01 & readl(&ddr_regs->mmap[chip_sel].cs);
64 result = readl(&ddr_regs->mmap[chip_sel].cs);
65 result = (result >> 16) & 0xF;
67 printf("Unknown DRAM Size\n");
70 return ((0x8 << (result - 0x7)) * 1024 * 1024);
74 #ifndef CONFIG_SYS_BOARD_DRAM_INIT
80 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
81 gd->bd->bi_dram[i].start = panth_sdram_base(i);
82 gd->bd->bi_dram[i].size = panth_sdram_size(i);
84 * It is assumed that all memory banks are consecutive
86 * If the gap is found, ram_size will be reported for
87 * consecutive memory only
89 if (gd->bd->bi_dram[i].start != gd->ram_size)
92 gd->ram_size += gd->bd->bi_dram[i].size;
96 for (; i < CONFIG_NR_DRAM_BANKS; i++) {
98 * If above loop terminated prematurely, we need to set
99 * remaining banks' start address & size as 0. Otherwise other
100 * u-boot functions and Linux kernel gets wrong values which
101 * could result in crash
103 gd->bd->bi_dram[i].start = 0;
104 gd->bd->bi_dram[i].size = 0;
110 * If this function is not defined here,
111 * board.c alters dram bank zero configuration defined above.
113 void dram_init_banksize(void)
117 #endif /* CONFIG_SYS_BOARD_DRAM_INIT */