265a8b0ae8a0b882ed590ac203c9e633f8bd7122
[oweals/u-boot.git] / arch / arm / mach-mvebu / armada8k / dram.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2016 Stefan Roese <sr@denx.de>
4  */
5
6 #include <common.h>
7 #include <asm/arch/cpu.h>
8 #include <asm/arch/soc.h>
9 #include <asm/system.h>
10 #include <linux/sizes.h>
11
12 DECLARE_GLOBAL_DATA_PTR;
13
14 #define MV_SIP_DRAM_SIZE        0x82000010
15
16 u64 a8k_dram_scan_ap_sz(void)
17 {
18         struct pt_regs pregs;
19
20         pregs.regs[0] = MV_SIP_DRAM_SIZE;
21         pregs.regs[1] = SOC_REGS_PHY_BASE;
22         smc_call(&pregs);
23
24         return pregs.regs[0];
25 }
26
27 int a8k_dram_init_banksize(void)
28 {
29         /*
30          * The firmware (ATF) leaves a 1G whole above the 3G mark for IO
31          * devices. Higher RAM is mapped at 4G.
32          *
33          * Config 2 DRAM banks:
34          * Bank 0 - max size 4G - 1G
35          * Bank 1 - ram size - 4G + 1G
36          */
37         phys_size_t max_bank0_size = SZ_4G - SZ_1G;
38
39         gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
40         if (gd->ram_size <= max_bank0_size) {
41                 gd->bd->bi_dram[0].size = gd->ram_size;
42                 return 0;
43         }
44
45         gd->bd->bi_dram[0].size = max_bank0_size;
46         if (CONFIG_NR_DRAM_BANKS > 1) {
47                 gd->bd->bi_dram[1].start = SZ_4G;
48                 gd->bd->bi_dram[1].size = gd->ram_size - max_bank0_size;
49         }
50
51         return 0;
52 }