Jim Liu | 147c000 | 2022-09-27 16:45:15 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (c) 2022 Nuvoton Technology Corp. |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
| 8 | #include <asm/io.h> |
| 9 | #include <asm/arch/gcr.h> |
| 10 | |
Jim Liu | c5cc4bc | 2023-07-04 16:00:14 +0800 | [diff] [blame] | 11 | #define SR_MII_CTRL_SWR_BIT15 15 |
| 12 | |
| 13 | #define DRAM_512MB_ECC_SIZE 0x1C000000ULL |
| 14 | #define DRAM_512MB_SIZE 0x20000000ULL |
| 15 | #define DRAM_1GB_ECC_SIZE 0x38000000ULL |
| 16 | #define DRAM_1GB_SIZE 0x40000000ULL |
| 17 | #define DRAM_2GB_ECC_SIZE 0x70000000ULL |
| 18 | #define DRAM_2GB_SIZE 0x80000000ULL |
Jim Liu | 25efe15 | 2023-10-23 15:02:24 +0800 | [diff] [blame] | 19 | #define DRAM_4GB_ECC_SIZE 0xE0000000ULL |
Jim Liu | c5cc4bc | 2023-07-04 16:00:14 +0800 | [diff] [blame] | 20 | #define DRAM_4GB_SIZE 0x100000000ULL |
| 21 | |
Jim Liu | 147c000 | 2022-09-27 16:45:15 +0800 | [diff] [blame] | 22 | DECLARE_GLOBAL_DATA_PTR; |
| 23 | |
| 24 | int board_init(void) |
| 25 | { |
| 26 | return 0; |
| 27 | } |
| 28 | |
| 29 | int dram_init(void) |
| 30 | { |
| 31 | struct npcm_gcr *gcr = (struct npcm_gcr *)NPCM_GCR_BA; |
| 32 | |
| 33 | /* |
Jim Liu | c5cc4bc | 2023-07-04 16:00:14 +0800 | [diff] [blame] | 34 | * get dram active size value from bootblock. |
| 35 | * Value sent using scrpad_03 register. |
| 36 | * feature available in bootblock 0.0.6 and above. |
Jim Liu | 147c000 | 2022-09-27 16:45:15 +0800 | [diff] [blame] | 37 | */ |
Jim Liu | c5cc4bc | 2023-07-04 16:00:14 +0800 | [diff] [blame] | 38 | |
| 39 | gd->ram_size = readl(&gcr->scrpad_c); |
Jim Liu | c5cc4bc | 2023-07-04 16:00:14 +0800 | [diff] [blame] | 40 | |
Jim Liu | 25efe15 | 2023-10-23 15:02:24 +0800 | [diff] [blame] | 41 | if (gd->ram_size == 0) |
Jim Liu | c5cc4bc | 2023-07-04 16:00:14 +0800 | [diff] [blame] | 42 | gd->ram_size = readl(&gcr->scrpad_b); |
Jim Liu | 25efe15 | 2023-10-23 15:02:24 +0800 | [diff] [blame] | 43 | else |
Jim Liu | c5cc4bc | 2023-07-04 16:00:14 +0800 | [diff] [blame] | 44 | gd->ram_size *= 0x100000ULL; |
Jim Liu | c5cc4bc | 2023-07-04 16:00:14 +0800 | [diff] [blame] | 45 | |
Jim Liu | c5cc4bc | 2023-07-04 16:00:14 +0800 | [diff] [blame] | 46 | debug("ram_size: %llx ", gd->ram_size); |
| 47 | |
Jim Liu | 25efe15 | 2023-10-23 15:02:24 +0800 | [diff] [blame] | 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | int dram_init_banksize(void) |
| 52 | { |
| 53 | |
| 54 | gd->bd->bi_dram[0].start = 0; |
| 55 | |
Jim Liu | c5cc4bc | 2023-07-04 16:00:14 +0800 | [diff] [blame] | 56 | switch (gd->ram_size) { |
| 57 | case DRAM_512MB_ECC_SIZE: |
| 58 | case DRAM_512MB_SIZE: |
| 59 | case DRAM_1GB_ECC_SIZE: |
| 60 | case DRAM_1GB_SIZE: |
| 61 | case DRAM_2GB_ECC_SIZE: |
| 62 | case DRAM_2GB_SIZE: |
| 63 | gd->bd->bi_dram[0].size = gd->ram_size; |
| 64 | gd->bd->bi_dram[1].start = 0; |
| 65 | gd->bd->bi_dram[1].size = 0; |
| 66 | break; |
| 67 | case DRAM_4GB_ECC_SIZE: |
Jim Liu | 25efe15 | 2023-10-23 15:02:24 +0800 | [diff] [blame] | 68 | gd->bd->bi_dram[0].size = DRAM_2GB_SIZE; |
Jim Liu | c5cc4bc | 2023-07-04 16:00:14 +0800 | [diff] [blame] | 69 | gd->bd->bi_dram[1].start = DRAM_4GB_SIZE; |
Jim Liu | 25efe15 | 2023-10-23 15:02:24 +0800 | [diff] [blame] | 70 | gd->bd->bi_dram[1].size = DRAM_2GB_SIZE - |
| 71 | (DRAM_4GB_SIZE - DRAM_4GB_ECC_SIZE); |
| 72 | /* use bank0 only */ |
| 73 | gd->ram_size = DRAM_2GB_SIZE; |
Jim Liu | c5cc4bc | 2023-07-04 16:00:14 +0800 | [diff] [blame] | 74 | break; |
| 75 | case DRAM_4GB_SIZE: |
| 76 | gd->bd->bi_dram[0].size = DRAM_2GB_SIZE; |
| 77 | gd->bd->bi_dram[1].start = DRAM_4GB_SIZE; |
| 78 | gd->bd->bi_dram[1].size = DRAM_2GB_SIZE; |
Jim Liu | 25efe15 | 2023-10-23 15:02:24 +0800 | [diff] [blame] | 79 | /* use bank0 only */ |
| 80 | gd->ram_size = DRAM_2GB_SIZE; |
Jim Liu | c5cc4bc | 2023-07-04 16:00:14 +0800 | [diff] [blame] | 81 | break; |
| 82 | default: |
| 83 | gd->bd->bi_dram[0].size = DRAM_1GB_SIZE; |
| 84 | gd->bd->bi_dram[1].start = 0; |
| 85 | gd->bd->bi_dram[1].size = 0; |
Jim Liu | 25efe15 | 2023-10-23 15:02:24 +0800 | [diff] [blame] | 86 | gd->ram_size = DRAM_1GB_SIZE; |
Jim Liu | c5cc4bc | 2023-07-04 16:00:14 +0800 | [diff] [blame] | 87 | break; |
| 88 | } |
| 89 | |
Jim Liu | c5cc4bc | 2023-07-04 16:00:14 +0800 | [diff] [blame] | 90 | return 0; |
| 91 | } |
| 92 | |