Jim Liu | 4359b33 | 2022-04-19 13:32:19 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * |
| 4 | * Copyright (c) 2021 Nuvoton Technology Corp. |
| 5 | */ |
| 6 | |
Jim Liu | 4359b33 | 2022-04-19 13:32:19 +0800 | [diff] [blame] | 7 | #include <dm.h> |
Jim Liu | c4ab55c | 2023-06-13 15:45:54 +0800 | [diff] [blame] | 8 | #include <env.h> |
Jim Liu | 4359b33 | 2022-04-19 13:32:19 +0800 | [diff] [blame] | 9 | #include <asm/io.h> |
| 10 | #include <asm/arch/gcr.h> |
| 11 | #include <asm/mach-types.h> |
Jim Liu | c32c95c | 2023-11-14 16:51:59 +0800 | [diff] [blame] | 12 | #include "../common/uart.h" |
Jim Liu | 4359b33 | 2022-04-19 13:32:19 +0800 | [diff] [blame] | 13 | |
| 14 | DECLARE_GLOBAL_DATA_PTR; |
| 15 | |
| 16 | int board_init(void) |
| 17 | { |
| 18 | return 0; |
| 19 | } |
| 20 | |
| 21 | int 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 Liu | 4359b33 | 2022-04-19 13:32:19 +0800 | [diff] [blame] | 48 | return 0; |
| 49 | } |
Jim Liu | c32c95c | 2023-11-14 16:51:59 +0800 | [diff] [blame] | 50 | |
| 51 | int last_stage_init(void) |
| 52 | { |
Jim Liu | 6327361 | 2024-04-23 15:22:08 +0800 | [diff] [blame] | 53 | |
| 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 Liu | c32c95c | 2023-11-14 16:51:59 +0800 | [diff] [blame] | 73 | |
| 74 | return 0; |
| 75 | } |