blob: 2052af6649a52c0d8924cc55cd16fc8cad7cbcbf [file] [log] [blame]
Jim Liu4359b332022-04-19 13:32:19 +08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 *
4 * Copyright (c) 2021 Nuvoton Technology Corp.
5 */
6
7#include <common.h>
8#include <dm.h>
Jim Liuc4ab55c2023-06-13 15:45:54 +08009#include <env.h>
Jim Liu4359b332022-04-19 13:32:19 +080010#include <asm/io.h>
11#include <asm/arch/gcr.h>
12#include <asm/mach-types.h>
13
14DECLARE_GLOBAL_DATA_PTR;
15
16int board_init(void)
17{
18 return 0;
19}
20
21int dram_init(void)
22{
Jim Liuc4ab55c2023-06-13 15:45:54 +080023 char value[32];
Jim Liu4359b332022-04-19 13:32:19 +080024 struct npcm_gcr *gcr = (struct npcm_gcr *)NPCM_GCR_BA;
25
26 int ramsize = (readl(&gcr->intcr3) >> 8) & 0x7;
27
28 switch (ramsize) {
29 case 0:
30 gd->ram_size = 0x08000000; /* 128 MB. */
31 break;
32 case 1:
33 gd->ram_size = 0x10000000; /* 256 MB. */
34 break;
35 case 2:
36 gd->ram_size = 0x20000000; /* 512 MB. */
37 break;
38 case 3:
39 gd->ram_size = 0x40000000; /* 1024 MB. */
40 break;
41 case 4:
42 gd->ram_size = 0x80000000; /* 2048 MB. */
43 break;
44
45 default:
46 break;
47 }
48
Jim Liuc4ab55c2023-06-13 15:45:54 +080049 if (gd->ram_size > 0) {
50 sprintf(value, "%ldM", (gd->ram_size / 0x100000));
51 env_set("mem", value);
52 }
53
Jim Liu4359b332022-04-19 13:32:19 +080054 return 0;
55}