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 | |
| 7 | #include <common.h> |
| 8 | #include <dm.h> |
Jim Liu | c4ab55c | 2023-06-13 15:45:54 +0800 | [diff] [blame] | 9 | #include <env.h> |
Jim Liu | 4359b33 | 2022-04-19 13:32:19 +0800 | [diff] [blame] | 10 | #include <asm/io.h> |
| 11 | #include <asm/arch/gcr.h> |
| 12 | #include <asm/mach-types.h> |
Jim Liu | c32c95c | 2023-11-14 16:51:59 +0800 | [diff] [blame] | 13 | #include "../common/uart.h" |
Jim Liu | 4359b33 | 2022-04-19 13:32:19 +0800 | [diff] [blame] | 14 | |
| 15 | DECLARE_GLOBAL_DATA_PTR; |
| 16 | |
| 17 | int board_init(void) |
| 18 | { |
| 19 | return 0; |
| 20 | } |
| 21 | |
| 22 | int dram_init(void) |
| 23 | { |
Jim Liu | c4ab55c | 2023-06-13 15:45:54 +0800 | [diff] [blame] | 24 | char value[32]; |
Jim Liu | 4359b33 | 2022-04-19 13:32:19 +0800 | [diff] [blame] | 25 | struct npcm_gcr *gcr = (struct npcm_gcr *)NPCM_GCR_BA; |
| 26 | |
| 27 | int ramsize = (readl(&gcr->intcr3) >> 8) & 0x7; |
| 28 | |
| 29 | switch (ramsize) { |
| 30 | case 0: |
| 31 | gd->ram_size = 0x08000000; /* 128 MB. */ |
| 32 | break; |
| 33 | case 1: |
| 34 | gd->ram_size = 0x10000000; /* 256 MB. */ |
| 35 | break; |
| 36 | case 2: |
| 37 | gd->ram_size = 0x20000000; /* 512 MB. */ |
| 38 | break; |
| 39 | case 3: |
| 40 | gd->ram_size = 0x40000000; /* 1024 MB. */ |
| 41 | break; |
| 42 | case 4: |
| 43 | gd->ram_size = 0x80000000; /* 2048 MB. */ |
| 44 | break; |
| 45 | |
| 46 | default: |
| 47 | break; |
| 48 | } |
| 49 | |
Jim Liu | c4ab55c | 2023-06-13 15:45:54 +0800 | [diff] [blame] | 50 | if (gd->ram_size > 0) { |
| 51 | sprintf(value, "%ldM", (gd->ram_size / 0x100000)); |
| 52 | env_set("mem", value); |
| 53 | } |
| 54 | |
Jim Liu | 4359b33 | 2022-04-19 13:32:19 +0800 | [diff] [blame] | 55 | return 0; |
| 56 | } |
Jim Liu | c32c95c | 2023-11-14 16:51:59 +0800 | [diff] [blame] | 57 | |
| 58 | int last_stage_init(void) |
| 59 | { |
| 60 | board_set_console(); |
| 61 | |
| 62 | return 0; |
| 63 | } |