1 // SPDX-License-Identifier: GPL-2.0+
3 * Keystone : Board initialization
6 * Texas Instruments Incorporated, <www.ti.com>
15 #include <fdt_support.h>
16 #include <asm/arch/ddr3.h>
17 #include <asm/arch/psc_defs.h>
18 #include <asm/arch/clock.h>
19 #include <asm/ti-common/ti-aemif.h>
20 #include <asm/ti-common/keystone_net.h>
22 DECLARE_GLOBAL_DATA_PTR;
24 #if defined(CONFIG_TI_AEMIF)
25 static struct aemif_config aemif_configs[] = {
27 .mode = AEMIF_MODE_NAND,
35 .width = AEMIF_WIDTH_8,
44 ddr3_size = ddr3_init();
46 gd->ram_size = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE,
47 CONFIG_MAX_RAM_BANK_SIZE);
48 #if defined(CONFIG_TI_AEMIF)
49 if (!board_is_k2g_ice())
50 aemif_init(ARRAY_SIZE(aemif_configs), aemif_configs);
53 if (!board_is_k2g_ice()) {
55 ddr3_init_ecc(KS2_DDR3A_EMIF_CTRL_BASE, ddr3_size);
57 ddr3_init_ecc(KS2_DDR3A_EMIF_CTRL_BASE,
64 struct image_header *spl_get_load_buffer(ssize_t offset, size_t size)
66 return (struct image_header *)(CONFIG_SYS_TEXT_BASE);
71 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
75 #ifdef CONFIG_SPL_BUILD
76 void spl_board_init(void)
78 spl_init_keystone_plls();
79 preloader_console_init();
82 u32 spl_boot_device(void)
84 #if defined(CONFIG_SPL_SPI_LOAD)
85 return BOOT_DEVICE_SPI;
87 puts("Unknown boot device\n");
93 #ifdef CONFIG_OF_BOARD_SETUP
94 int ft_board_setup(void *blob, bd_t *bd)
104 env = env_get("mem_lpae");
105 lpae = env && simple_strtol(env, NULL, 0);
109 ddr3a_size = ddr3_get_size();
110 if ((ddr3a_size != 8) && (ddr3a_size != 4))
115 start[0] = bd->bi_dram[0].start;
116 size[0] = bd->bi_dram[0].size;
118 /* adjust memory start address for LPAE */
120 start[0] -= CONFIG_SYS_SDRAM_BASE;
121 start[0] += CONFIG_SYS_LPAE_SDRAM_BASE;
124 if ((size[0] == 0x80000000) && (ddr3a_size != 0)) {
125 size[1] = ((u64)ddr3a_size - 2) << 30;
126 start[1] = 0x880000000;
130 /* reserve memory at start of bank */
131 env = env_get("mem_reserve_head");
133 start[0] += ustrtoul(env, &endp, 0);
134 size[0] -= ustrtoul(env, &endp, 0);
137 env = env_get("mem_reserve");
139 size[0] -= ustrtoul(env, &endp, 0);
141 fdt_fixup_memory_banks(blob, start, size, nbanks);
146 void ft_board_setup_ex(void *blob, bd_t *bd)
152 int unitrd_fixup = 0;
154 env = env_get("mem_lpae");
155 lpae = env && simple_strtol(env, NULL, 0);
156 env = env_get("uinitrd_fixup");
157 unitrd_fixup = env && simple_strtol(env, NULL, 0);
159 /* Fix up the initrd */
160 if (lpae && unitrd_fixup) {
164 u64 initrd_start, initrd_end;
166 nodeoffset = fdt_path_offset(blob, "/chosen");
167 if (nodeoffset >= 0) {
168 prop1 = (u64 *)fdt_getprop(blob, nodeoffset,
169 "linux,initrd-start", NULL);
170 prop2 = (u64 *)fdt_getprop(blob, nodeoffset,
171 "linux,initrd-end", NULL);
172 if (prop1 && prop2) {
173 initrd_start = __be64_to_cpu(*prop1);
174 initrd_start -= CONFIG_SYS_SDRAM_BASE;
175 initrd_start += CONFIG_SYS_LPAE_SDRAM_BASE;
176 initrd_start = __cpu_to_be64(initrd_start);
177 initrd_end = __be64_to_cpu(*prop2);
178 initrd_end -= CONFIG_SYS_SDRAM_BASE;
179 initrd_end += CONFIG_SYS_LPAE_SDRAM_BASE;
180 initrd_end = __cpu_to_be64(initrd_end);
182 err = fdt_delprop(blob, nodeoffset,
183 "linux,initrd-start");
185 puts("error deleting initrd-start\n");
187 err = fdt_delprop(blob, nodeoffset,
190 puts("error deleting initrd-end\n");
192 err = fdt_setprop(blob, nodeoffset,
193 "linux,initrd-start",
195 sizeof(initrd_start));
197 puts("error adding initrd-start\n");
199 err = fdt_setprop(blob, nodeoffset,
204 puts("error adding linux,initrd-end\n");
211 * the initrd and other reserved memory areas are
212 * embedded in in the DTB itslef. fix up these addresses
215 reserve_start = (u64 *)((char *)blob +
216 fdt_off_mem_rsvmap(blob));
218 *reserve_start = __cpu_to_be64(*reserve_start);
219 size = __cpu_to_be64(*(reserve_start + 1));
221 *reserve_start -= CONFIG_SYS_SDRAM_BASE;
223 CONFIG_SYS_LPAE_SDRAM_BASE;
225 __cpu_to_be64(*reserve_start);
233 ddr3_check_ecc_int(KS2_DDR3A_EMIF_CTRL_BASE);
235 #endif /* CONFIG_OF_BOARD_SETUP */
237 #if defined(CONFIG_DTB_RESELECT)
238 int __weak embedded_dtb_select(void)