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