1 // SPDX-License-Identifier: GPL-2.0+
3 * Keystone : Board initialization
6 * Texas Instruments Incorporated, <www.ti.com>
14 #include <fdt_support.h>
15 #include <asm/arch/ddr3.h>
16 #include <asm/arch/psc_defs.h>
17 #include <asm/arch/clock.h>
18 #include <asm/ti-common/ti-aemif.h>
19 #include <asm/ti-common/keystone_net.h>
21 DECLARE_GLOBAL_DATA_PTR;
23 #if defined(CONFIG_TI_AEMIF)
24 static struct aemif_config aemif_configs[] = {
26 .mode = AEMIF_MODE_NAND,
34 .width = AEMIF_WIDTH_8,
43 ddr3_size = ddr3_init();
45 gd->ram_size = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE,
46 CONFIG_MAX_RAM_BANK_SIZE);
47 #if defined(CONFIG_TI_AEMIF)
48 if (!board_is_k2g_ice())
49 aemif_init(ARRAY_SIZE(aemif_configs), aemif_configs);
52 if (!board_is_k2g_ice()) {
54 ddr3_init_ecc(KS2_DDR3A_EMIF_CTRL_BASE, ddr3_size);
56 ddr3_init_ecc(KS2_DDR3A_EMIF_CTRL_BASE,
63 struct image_header *spl_get_load_buffer(ssize_t offset, size_t size)
65 return (struct image_header *)(CONFIG_SYS_TEXT_BASE);
70 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
74 #ifdef CONFIG_SPL_BUILD
75 void spl_board_init(void)
77 spl_init_keystone_plls();
78 preloader_console_init();
81 u32 spl_boot_device(void)
83 #if defined(CONFIG_SPL_SPI_LOAD)
84 return BOOT_DEVICE_SPI;
86 puts("Unknown boot device\n");
92 #ifdef CONFIG_OF_BOARD_SETUP
93 int ft_board_setup(void *blob, bd_t *bd)
103 env = env_get("mem_lpae");
104 lpae = env && simple_strtol(env, NULL, 0);
108 ddr3a_size = ddr3_get_size();
109 if ((ddr3a_size != 8) && (ddr3a_size != 4))
114 start[0] = bd->bi_dram[0].start;
115 size[0] = bd->bi_dram[0].size;
117 /* adjust memory start address for LPAE */
119 start[0] -= CONFIG_SYS_SDRAM_BASE;
120 start[0] += CONFIG_SYS_LPAE_SDRAM_BASE;
123 if ((size[0] == 0x80000000) && (ddr3a_size != 0)) {
124 size[1] = ((u64)ddr3a_size - 2) << 30;
125 start[1] = 0x880000000;
129 /* reserve memory at start of bank */
130 env = env_get("mem_reserve_head");
132 start[0] += ustrtoul(env, &endp, 0);
133 size[0] -= ustrtoul(env, &endp, 0);
136 env = env_get("mem_reserve");
138 size[0] -= ustrtoul(env, &endp, 0);
140 fdt_fixup_memory_banks(blob, start, size, nbanks);
145 void ft_board_setup_ex(void *blob, bd_t *bd)
151 int unitrd_fixup = 0;
153 env = env_get("mem_lpae");
154 lpae = env && simple_strtol(env, NULL, 0);
155 env = env_get("uinitrd_fixup");
156 unitrd_fixup = env && simple_strtol(env, NULL, 0);
158 /* Fix up the initrd */
159 if (lpae && unitrd_fixup) {
163 u64 initrd_start, initrd_end;
165 nodeoffset = fdt_path_offset(blob, "/chosen");
166 if (nodeoffset >= 0) {
167 prop1 = (u64 *)fdt_getprop(blob, nodeoffset,
168 "linux,initrd-start", NULL);
169 prop2 = (u64 *)fdt_getprop(blob, nodeoffset,
170 "linux,initrd-end", NULL);
171 if (prop1 && prop2) {
172 initrd_start = __be64_to_cpu(*prop1);
173 initrd_start -= CONFIG_SYS_SDRAM_BASE;
174 initrd_start += CONFIG_SYS_LPAE_SDRAM_BASE;
175 initrd_start = __cpu_to_be64(initrd_start);
176 initrd_end = __be64_to_cpu(*prop2);
177 initrd_end -= CONFIG_SYS_SDRAM_BASE;
178 initrd_end += CONFIG_SYS_LPAE_SDRAM_BASE;
179 initrd_end = __cpu_to_be64(initrd_end);
181 err = fdt_delprop(blob, nodeoffset,
182 "linux,initrd-start");
184 puts("error deleting initrd-start\n");
186 err = fdt_delprop(blob, nodeoffset,
189 puts("error deleting initrd-end\n");
191 err = fdt_setprop(blob, nodeoffset,
192 "linux,initrd-start",
194 sizeof(initrd_start));
196 puts("error adding initrd-start\n");
198 err = fdt_setprop(blob, nodeoffset,
203 puts("error adding linux,initrd-end\n");
210 * the initrd and other reserved memory areas are
211 * embedded in in the DTB itslef. fix up these addresses
214 reserve_start = (u64 *)((char *)blob +
215 fdt_off_mem_rsvmap(blob));
217 *reserve_start = __cpu_to_be64(*reserve_start);
218 size = __cpu_to_be64(*(reserve_start + 1));
220 *reserve_start -= CONFIG_SYS_SDRAM_BASE;
222 CONFIG_SYS_LPAE_SDRAM_BASE;
224 __cpu_to_be64(*reserve_start);
232 ddr3_check_ecc_int(KS2_DDR3A_EMIF_CTRL_BASE);
234 #endif /* CONFIG_OF_BOARD_SETUP */
236 #if defined(CONFIG_DTB_RESELECT)
237 int __weak embedded_dtb_select(void)