blob: 9585944d80c154dcad71e2e946e5bdf74f24f635 [file] [log] [blame]
Masami Hiramatsu7c741272021-06-04 18:45:10 +09001// 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 Ganuccb36462022-04-15 11:29:34 +053013#include <efi.h>
14#include <efi_loader.h>
Masami Hiramatsu7c741272021-06-04 18:45:10 +090015#include <env_internal.h>
16#include <fdt_support.h>
17#include <log.h>
18
Sughosh Ganuccb36462022-04-15 11:29:34 +053019#include <linux/kernel.h>
20
Simon Glassb8196212023-02-05 15:39:42 -070021#if IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT)
Sughosh Ganuccb36462022-04-15 11:29:34 +053022struct efi_fw_image fw_images[] = {
Jassi Brareeee4322023-05-31 00:29:56 -050023#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 Ganuccb36462022-04-15 11:29:34 +053030 {
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 Brareeee4322023-05-31 00:29:56 -050045#endif
Sughosh Ganuccb36462022-04-15 11:29:34 +053046};
47
48struct 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 Kojima5d2438b2023-06-07 14:41:51 +090052 .num_images = ARRAY_SIZE(fw_images),
Sughosh Ganuccb36462022-04-15 11:29:34 +053053 .images = fw_images,
54};
55
Sughosh Ganuccb36462022-04-15 11:29:34 +053056#endif /* EFI_HAVE_CAPSULE_SUPPORT */
57
Masami Hiramatsu7c741272021-06-04 18:45:10 +090058static 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
84struct mm_region *mem_map = sc2a11_mem_map;
85
86#define DDR_REGION_INDEX(i) (1 + (i))
87#define MAX_DDR_REGIONS 3
88
89struct draminfo_entry {
90 u64 base;
91 u64 size;
92};
93
94struct draminfo {
95 u32 nr_regions;
96 u32 reserved;
97 struct draminfo_entry entry[3];
98};
99
Masami Hiramatsu7c741272021-06-04 18:45:10 +0900100DECLARE_GLOBAL_DATA_PTR;
101
102#define LOAD_OFFSET 0x100
103
Masami Hiramatsub4d946e2021-07-12 19:35:44 +0900104/* 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
111static 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 Hiramatsu7c741272021-06-04 18:45:10 +0900117/*
118 * Miscellaneous platform dependent initialisations
119 */
120int board_init(void)
121{
122 gd->bd->bi_boot_params = CONFIG_SYS_LOAD_ADDR + LOAD_OFFSET;
123
Masami Hiramatsu41e6ff72021-11-18 14:45:25 +0900124 gd->env_addr = (ulong)&default_environment[0];
125
Masami Hiramatsub4d946e2021-07-12 19:35:44 +0900126 synquacer_setup_scbm_smmu();
127
Masami Hiramatsu7c741272021-06-04 18:45:10 +0900128 return 0;
129}
130
131int 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
144int dram_init(void)
145{
Jassi Brar84a549f2022-09-12 12:05:29 -0500146 struct draminfo *synquacer_draminfo = (void *)SQ_DRAMINFO_BASE;
147 struct draminfo_entry *ent = synquacer_draminfo->entry;
Masahisa Kojima1e5a70f2023-10-03 11:29:57 +0900148 unsigned long size = 0;
149 int i;
Jassi Brar84a549f2022-09-12 12:05:29 -0500150
Masahisa Kojima1e5a70f2023-10-03 11:29:57 +0900151 for (i = 0; i < synquacer_draminfo->nr_regions; i++)
152 size += ent[i].size;
153
154 gd->ram_size = size;
Jassi Brar84a549f2022-09-12 12:05:29 -0500155 gd->ram_base = ent[0].base;
156
157 return 0;
158}
159
Masahisa Kojima1e5a70f2023-10-03 11:29:57 +0900160phys_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 Brar84a549f2022-09-12 12:05:29 -0500169int 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
186void build_mem_map(void)
187{
188 struct draminfo *synquacer_draminfo = (void *)SQ_DRAMINFO_BASE;
Masami Hiramatsu7c741272021-06-04 18:45:10 +0900189 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 Brar84a549f2022-09-12 12:05:29 -0500195 return;
Masami Hiramatsu7c741272021-06-04 18:45:10 +0900196 }
197
Masami Hiramatsu7c741272021-06-04 18:45:10 +0900198 /* 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 Brar88abf7a2022-09-12 12:05:15 -0500206 mem_map[ri].virt = mem_map[ri].phys;
Masami Hiramatsu7c741272021-06-04 18:45:10 +0900207 if (i == 0)
208 continue;
209
210 mr = &mem_map[DDR_REGION_INDEX(0)];
Masami Hiramatsu7c741272021-06-04 18:45:10 +0900211 mem_map[ri].attrs = mr->attrs;
212 }
Masami Hiramatsu7c741272021-06-04 18:45:10 +0900213}
214
Jassi Brar84a549f2022-09-12 12:05:29 -0500215void enable_caches(void)
Masami Hiramatsu7c741272021-06-04 18:45:10 +0900216{
Jassi Brar84a549f2022-09-12 12:05:29 -0500217 build_mem_map();
Masami Hiramatsu7c741272021-06-04 18:45:10 +0900218
Jassi Brar84a549f2022-09-12 12:05:29 -0500219 icache_enable();
220 dcache_enable();
Masami Hiramatsu7c741272021-06-04 18:45:10 +0900221}
222
223int print_cpuinfo(void)
224{
225 printf("CPU: SC2A11:Cortex-A53 MPCore 24cores\n");
226 return 0;
227}