blob: 3c4e5aaf2940103e6bfb9b06b0c528d5d6f999a8 [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
Jim Liu4359b332022-04-19 13:32:19 +08007#include <dm.h>
Jim Liuc4ab55c2023-06-13 15:45:54 +08008#include <env.h>
Jim Liu4359b332022-04-19 13:32:19 +08009#include <asm/io.h>
10#include <asm/arch/gcr.h>
11#include <asm/mach-types.h>
Jim Liuc32c95c2023-11-14 16:51:59 +080012#include "../common/uart.h"
Jim Liu4359b332022-04-19 13:32:19 +080013
14DECLARE_GLOBAL_DATA_PTR;
15
16int board_init(void)
17{
18 return 0;
19}
20
21int dram_init(void)
22{
23 struct npcm_gcr *gcr = (struct npcm_gcr *)NPCM_GCR_BA;
24
25 int ramsize = (readl(&gcr->intcr3) >> 8) & 0x7;
26
27 switch (ramsize) {
28 case 0:
29 gd->ram_size = 0x08000000; /* 128 MB. */
30 break;
31 case 1:
32 gd->ram_size = 0x10000000; /* 256 MB. */
33 break;
34 case 2:
35 gd->ram_size = 0x20000000; /* 512 MB. */
36 break;
37 case 3:
38 gd->ram_size = 0x40000000; /* 1024 MB. */
39 break;
40 case 4:
41 gd->ram_size = 0x80000000; /* 2048 MB. */
42 break;
43
44 default:
45 break;
46 }
47
Jim Liu4359b332022-04-19 13:32:19 +080048 return 0;
49}
Jim Liuc32c95c2023-11-14 16:51:59 +080050
51int last_stage_init(void)
52{
Jim Liu63273612024-04-23 15:22:08 +080053
54 char value[32];
55 struct udevice *dev = gd->cur_serial_dev;
56
57 if (gd->ram_size > 0) {
58 sprintf(value, "%ldM", (gd->ram_size / 0x100000));
59 env_set("mem", value);
60 }
61
62 if (dev && (dev->seq_ >= 0)) {
63 void *addr;
64 addr = dev_read_addr_ptr(dev);
65 if (addr) {
66 sprintf(value, "uart8250,mmio32,0x%x", (u32)addr);
67 env_set("earlycon", value);
68 }
69 sprintf(value, "ttyS%d,115200n8", dev->seq_);
70 env_set("console", value);
71 board_set_console();
72 }
Jim Liuc32c95c2023-11-14 16:51:59 +080073
74 return 0;
75}