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> |
| 13 | |
| 14 | DECLARE_GLOBAL_DATA_PTR; |
| 15 | |
| 16 | int board_init(void) |
| 17 | { |
| 18 | return 0; |
| 19 | } |
| 20 | |
| 21 | int dram_init(void) |
| 22 | { |
Jim Liu | c4ab55c | 2023-06-13 15:45:54 +0800 | [diff] [blame] | 23 | char value[32]; |
Jim Liu | 4359b33 | 2022-04-19 13:32:19 +0800 | [diff] [blame] | 24 | 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 Liu | c4ab55c | 2023-06-13 15:45:54 +0800 | [diff] [blame] | 49 | if (gd->ram_size > 0) { |
| 50 | sprintf(value, "%ldM", (gd->ram_size / 0x100000)); |
| 51 | env_set("mem", value); |
| 52 | } |
| 53 | |
Jim Liu | 4359b33 | 2022-04-19 13:32:19 +0800 | [diff] [blame] | 54 | return 0; |
| 55 | } |