Masami Hiramatsu | 7c74127 | 2021-06-04 18:45:10 +0900 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * u-boot/board/socionext/developerbox/developerbox.c |
| 4 | * |
| 5 | * Copyright (C) 2016-2017 Socionext Inc. |
| 6 | * Copyright (C) 2021 Linaro Ltd. |
| 7 | */ |
| 8 | #include <asm/types.h> |
| 9 | #include <asm/armv8/mmu.h> |
| 10 | #include <asm/global_data.h> |
| 11 | #include <asm/io.h> |
| 12 | #include <common.h> |
Sughosh Ganu | ccb3646 | 2022-04-15 11:29:34 +0530 | [diff] [blame] | 13 | #include <efi.h> |
| 14 | #include <efi_loader.h> |
Masami Hiramatsu | 7c74127 | 2021-06-04 18:45:10 +0900 | [diff] [blame] | 15 | #include <env_internal.h> |
| 16 | #include <fdt_support.h> |
| 17 | #include <log.h> |
| 18 | |
Sughosh Ganu | ccb3646 | 2022-04-15 11:29:34 +0530 | [diff] [blame] | 19 | #include <linux/kernel.h> |
| 20 | |
Simon Glass | b819621 | 2023-02-05 15:39:42 -0700 | [diff] [blame] | 21 | #if IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) |
Sughosh Ganu | ccb3646 | 2022-04-15 11:29:34 +0530 | [diff] [blame] | 22 | struct efi_fw_image fw_images[] = { |
Jassi Brar | eeee432 | 2023-05-31 00:29:56 -0500 | [diff] [blame] | 23 | { |
| 24 | .image_type_id = DEVELOPERBOX_FIP_IMAGE_GUID, |
| 25 | .fw_name = u"DEVELOPERBOX-FIP", |
| 26 | .image_index = 1, |
| 27 | }, |
Sughosh Ganu | ccb3646 | 2022-04-15 11:29:34 +0530 | [diff] [blame] | 28 | }; |
| 29 | |
| 30 | struct efi_capsule_update_info update_info = { |
Ilias Apalodimas | df41e3f | 2023-10-19 16:54:19 +0300 | [diff] [blame] | 31 | .dfu_string = "mtd nor1=fip.bin raw 600000 400000", |
Masahisa Kojima | 5d2438b | 2023-06-07 14:41:51 +0900 | [diff] [blame] | 32 | .num_images = ARRAY_SIZE(fw_images), |
Sughosh Ganu | ccb3646 | 2022-04-15 11:29:34 +0530 | [diff] [blame] | 33 | .images = fw_images, |
| 34 | }; |
Sughosh Ganu | ccb3646 | 2022-04-15 11:29:34 +0530 | [diff] [blame] | 35 | #endif /* EFI_HAVE_CAPSULE_SUPPORT */ |
| 36 | |
Masami Hiramatsu | 7c74127 | 2021-06-04 18:45:10 +0900 | [diff] [blame] | 37 | static struct mm_region sc2a11_mem_map[] = { |
| 38 | { |
| 39 | .virt = 0x0UL, |
| 40 | .phys = 0x0UL, |
| 41 | .size = 0x80000000UL, |
| 42 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 43 | PTE_BLOCK_OUTER_SHARE |
| 44 | }, { |
| 45 | /* 1st DDR block */ |
| 46 | .virt = 0x80000000UL, |
| 47 | .phys = 0x80000000UL, |
| 48 | .size = PHYS_SDRAM_SIZE, |
| 49 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 50 | PTE_BLOCK_OUTER_SHARE |
| 51 | }, { |
| 52 | /* 2nd DDR place holder */ |
| 53 | 0, |
| 54 | }, { |
| 55 | /* 3rd DDR place holder */ |
| 56 | 0, |
| 57 | }, { |
| 58 | /* List terminator */ |
| 59 | 0, |
| 60 | } |
| 61 | }; |
| 62 | |
| 63 | struct mm_region *mem_map = sc2a11_mem_map; |
| 64 | |
| 65 | #define DDR_REGION_INDEX(i) (1 + (i)) |
| 66 | #define MAX_DDR_REGIONS 3 |
| 67 | |
| 68 | struct draminfo_entry { |
| 69 | u64 base; |
| 70 | u64 size; |
| 71 | }; |
| 72 | |
| 73 | struct draminfo { |
| 74 | u32 nr_regions; |
| 75 | u32 reserved; |
| 76 | struct draminfo_entry entry[3]; |
| 77 | }; |
| 78 | |
Masami Hiramatsu | 7c74127 | 2021-06-04 18:45:10 +0900 | [diff] [blame] | 79 | DECLARE_GLOBAL_DATA_PTR; |
| 80 | |
| 81 | #define LOAD_OFFSET 0x100 |
| 82 | |
Masami Hiramatsu | b4d946e | 2021-07-12 19:35:44 +0900 | [diff] [blame] | 83 | /* SCBM System MMU is used for eMMC and NETSEC */ |
| 84 | #define SCBM_SMMU_ADDR (0x52e00000UL) |
| 85 | #define SMMU_SCR0_OFFS (0x0) |
| 86 | #define SMMU_SCR0_SHCFG_INNER (0x2 << 22) |
| 87 | #define SMMU_SCR0_MTCFG (0x1 << 20) |
| 88 | #define SMMU_SCR0_MEMATTR_INNER_OUTER_WB (0xf << 16) |
| 89 | |
| 90 | static void synquacer_setup_scbm_smmu(void) |
| 91 | { |
| 92 | writel(SMMU_SCR0_SHCFG_INNER | SMMU_SCR0_MTCFG | SMMU_SCR0_MEMATTR_INNER_OUTER_WB, |
| 93 | SCBM_SMMU_ADDR + SMMU_SCR0_OFFS); |
| 94 | } |
| 95 | |
Masami Hiramatsu | 7c74127 | 2021-06-04 18:45:10 +0900 | [diff] [blame] | 96 | /* |
| 97 | * Miscellaneous platform dependent initialisations |
| 98 | */ |
| 99 | int board_init(void) |
| 100 | { |
| 101 | gd->bd->bi_boot_params = CONFIG_SYS_LOAD_ADDR + LOAD_OFFSET; |
| 102 | |
Masami Hiramatsu | 41e6ff7 | 2021-11-18 14:45:25 +0900 | [diff] [blame] | 103 | gd->env_addr = (ulong)&default_environment[0]; |
| 104 | |
Masami Hiramatsu | b4d946e | 2021-07-12 19:35:44 +0900 | [diff] [blame] | 105 | synquacer_setup_scbm_smmu(); |
| 106 | |
Masami Hiramatsu | 7c74127 | 2021-06-04 18:45:10 +0900 | [diff] [blame] | 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | int ft_board_setup(void *blob, struct bd_info *bd) |
| 111 | { |
| 112 | /* Remove SPI NOR and I2C0 for making DT compatible with EDK2 */ |
| 113 | fdt_del_node_and_alias(blob, "spi_nor"); |
| 114 | fdt_del_node_and_alias(blob, "i2c0"); |
| 115 | |
| 116 | return 0; |
| 117 | } |
| 118 | |
| 119 | /* |
| 120 | * DRAM configuration |
| 121 | */ |
| 122 | |
| 123 | int dram_init(void) |
| 124 | { |
Jassi Brar | 84a549f | 2022-09-12 12:05:29 -0500 | [diff] [blame] | 125 | struct draminfo *synquacer_draminfo = (void *)SQ_DRAMINFO_BASE; |
| 126 | struct draminfo_entry *ent = synquacer_draminfo->entry; |
Masahisa Kojima | 1e5a70f | 2023-10-03 11:29:57 +0900 | [diff] [blame] | 127 | unsigned long size = 0; |
| 128 | int i; |
Jassi Brar | 84a549f | 2022-09-12 12:05:29 -0500 | [diff] [blame] | 129 | |
Masahisa Kojima | 1e5a70f | 2023-10-03 11:29:57 +0900 | [diff] [blame] | 130 | for (i = 0; i < synquacer_draminfo->nr_regions; i++) |
| 131 | size += ent[i].size; |
| 132 | |
| 133 | gd->ram_size = size; |
Jassi Brar | 84a549f | 2022-09-12 12:05:29 -0500 | [diff] [blame] | 134 | gd->ram_base = ent[0].base; |
| 135 | |
| 136 | return 0; |
| 137 | } |
| 138 | |
Masahisa Kojima | 1e5a70f | 2023-10-03 11:29:57 +0900 | [diff] [blame] | 139 | phys_addr_t board_get_usable_ram_top(phys_size_t total_size) |
| 140 | { |
| 141 | struct draminfo *synquacer_draminfo = (void *)SQ_DRAMINFO_BASE; |
| 142 | struct draminfo_entry *ent = synquacer_draminfo->entry; |
| 143 | |
| 144 | return ent[synquacer_draminfo->nr_regions - 1].base + |
| 145 | ent[synquacer_draminfo->nr_regions - 1].size; |
| 146 | } |
| 147 | |
Jassi Brar | 84a549f | 2022-09-12 12:05:29 -0500 | [diff] [blame] | 148 | int dram_init_banksize(void) |
| 149 | { |
| 150 | struct draminfo *synquacer_draminfo = (void *)SQ_DRAMINFO_BASE; |
| 151 | struct draminfo_entry *ent = synquacer_draminfo->entry; |
| 152 | int i; |
| 153 | |
| 154 | for (i = 0; i < ARRAY_SIZE(gd->bd->bi_dram); i++) { |
| 155 | if (i < synquacer_draminfo->nr_regions) { |
| 156 | debug("%s: dram[%d] = %llx@%llx\n", __func__, i, ent[i].size, ent[i].base); |
| 157 | gd->bd->bi_dram[i].start = ent[i].base; |
| 158 | gd->bd->bi_dram[i].size = ent[i].size; |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | return 0; |
| 163 | } |
| 164 | |
| 165 | void build_mem_map(void) |
| 166 | { |
| 167 | struct draminfo *synquacer_draminfo = (void *)SQ_DRAMINFO_BASE; |
Masami Hiramatsu | 7c74127 | 2021-06-04 18:45:10 +0900 | [diff] [blame] | 168 | struct draminfo_entry *ent = synquacer_draminfo->entry; |
| 169 | struct mm_region *mr; |
| 170 | int i, ri; |
| 171 | |
| 172 | if (synquacer_draminfo->nr_regions < 1) { |
| 173 | log_err("Failed to get correct DRAM information\n"); |
Jassi Brar | 84a549f | 2022-09-12 12:05:29 -0500 | [diff] [blame] | 174 | return; |
Masami Hiramatsu | 7c74127 | 2021-06-04 18:45:10 +0900 | [diff] [blame] | 175 | } |
| 176 | |
Masami Hiramatsu | 7c74127 | 2021-06-04 18:45:10 +0900 | [diff] [blame] | 177 | /* Update memory region maps */ |
| 178 | for (i = 0; i < synquacer_draminfo->nr_regions; i++) { |
| 179 | if (i >= MAX_DDR_REGIONS) |
| 180 | break; |
| 181 | |
| 182 | ri = DDR_REGION_INDEX(i); |
| 183 | mem_map[ri].phys = ent[i].base; |
| 184 | mem_map[ri].size = ent[i].size; |
Jassi Brar | 88abf7a | 2022-09-12 12:05:15 -0500 | [diff] [blame] | 185 | mem_map[ri].virt = mem_map[ri].phys; |
Masami Hiramatsu | 7c74127 | 2021-06-04 18:45:10 +0900 | [diff] [blame] | 186 | if (i == 0) |
| 187 | continue; |
| 188 | |
| 189 | mr = &mem_map[DDR_REGION_INDEX(0)]; |
Masami Hiramatsu | 7c74127 | 2021-06-04 18:45:10 +0900 | [diff] [blame] | 190 | mem_map[ri].attrs = mr->attrs; |
| 191 | } |
Masami Hiramatsu | 7c74127 | 2021-06-04 18:45:10 +0900 | [diff] [blame] | 192 | } |
| 193 | |
Jassi Brar | 84a549f | 2022-09-12 12:05:29 -0500 | [diff] [blame] | 194 | void enable_caches(void) |
Masami Hiramatsu | 7c74127 | 2021-06-04 18:45:10 +0900 | [diff] [blame] | 195 | { |
Jassi Brar | 84a549f | 2022-09-12 12:05:29 -0500 | [diff] [blame] | 196 | build_mem_map(); |
Masami Hiramatsu | 7c74127 | 2021-06-04 18:45:10 +0900 | [diff] [blame] | 197 | |
Jassi Brar | 84a549f | 2022-09-12 12:05:29 -0500 | [diff] [blame] | 198 | icache_enable(); |
| 199 | dcache_enable(); |
Masami Hiramatsu | 7c74127 | 2021-06-04 18:45:10 +0900 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | int print_cpuinfo(void) |
| 203 | { |
| 204 | printf("CPU: SC2A11:Cortex-A53 MPCore 24cores\n"); |
| 205 | return 0; |
| 206 | } |