2 * K2HK EVM : Board initialization
4 * (C) Copyright 2012-2014
5 * Texas Instruments Incorporated, <www.ti.com>
7 * SPDX-License-Identifier: GPL-2.0+
12 #include <fdt_support.h>
15 #include <asm/arch/hardware.h>
16 #include <asm/arch/clock.h>
18 #include <asm/mach-types.h>
19 #include <asm/arch/emac_defs.h>
20 #include <asm/arch/psc_defs.h>
21 #include <asm/ti-common/ti-aemif.h>
23 DECLARE_GLOBAL_DATA_PTR;
25 u32 device_big_endian;
27 unsigned int external_clk[ext_clk_count] = {
28 [sys_clk] = 122880000,
29 [alt_core_clk] = 125000000,
31 [tetris_clk] = 125000000,
32 [ddr3a_clk] = 100000000,
33 [ddr3b_clk] = 100000000,
34 [mcm_clk] = 312500000,
35 [pcie_clk] = 100000000,
36 [sgmii_srio_clk] = 156250000,
37 [xgmii_clk] = 156250000,
38 [usb_clk] = 100000000,
39 [rp1_clk] = 123456789 /* TODO: cannot find
43 static struct aemif_config aemif_configs[] = {
45 .mode = AEMIF_MODE_NAND,
53 .width = AEMIF_WIDTH_8,
58 static struct pll_init_data pll_config[] = {
68 gd->ram_size = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE,
69 CONFIG_MAX_RAM_BANK_SIZE);
70 aemif_init(ARRAY_SIZE(aemif_configs), aemif_configs);
74 #ifdef CONFIG_DRIVER_TI_KEYSTONE_NET
75 struct eth_priv_t eth_priv_cfg[] = {
77 .int_name = "K2HK_EMAC",
81 .sgmii_link_type = SGMII_LINK_MAC_PHY,
84 .int_name = "K2HK_EMAC1",
88 .sgmii_link_type = SGMII_LINK_MAC_PHY,
91 .int_name = "K2HK_EMAC2",
95 .sgmii_link_type = SGMII_LINK_MAC_MAC_FORCED,
98 .int_name = "K2HK_EMAC3",
102 .sgmii_link_type = SGMII_LINK_MAC_MAC_FORCED,
106 int get_eth_env_param(char *env_name)
111 env = getenv(env_name);
113 res = simple_strtol(env, NULL, 0);
118 int board_eth_init(bd_t *bis)
122 char link_type_name[32];
124 for (j = 0; j < (sizeof(eth_priv_cfg) / sizeof(struct eth_priv_t));
126 sprintf(link_type_name, "sgmii%d_link_type", j);
127 res = get_eth_env_param(link_type_name);
129 eth_priv_cfg[j].sgmii_link_type = res;
131 keystone2_emac_initialize(ð_priv_cfg[j]);
138 /* Byte swap the 32-bit data if the device is BE */
139 int cpu_to_bus(u32 *ptr, u32 length)
143 if (device_big_endian)
144 for (i = 0; i < length; i++, ptr++)
145 *ptr = __swab32(*ptr);
150 #if defined(CONFIG_BOARD_EARLY_INIT_F)
151 int board_early_init_f(void)
153 init_plls(ARRAY_SIZE(pll_config), pll_config);
160 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
165 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
166 #define K2_DDR3_START_ADDR 0x80000000
167 void ft_board_setup(void *blob, bd_t *bd)
171 char name[32], *env, *endp;
172 int lpae, nodeoffset;
176 env = getenv("mem_lpae");
177 lpae = env && simple_strtol(env, NULL, 0);
181 env = getenv("ddr3a_size");
183 ddr3a_size = simple_strtol(env, NULL, 10);
184 if ((ddr3a_size != 8) && (ddr3a_size != 4))
189 start[0] = bd->bi_dram[0].start;
190 size[0] = bd->bi_dram[0].size;
192 /* adjust memory start address for LPAE */
194 start[0] -= K2_DDR3_START_ADDR;
195 start[0] += CONFIG_SYS_LPAE_SDRAM_BASE;
198 if ((size[0] == 0x80000000) && (ddr3a_size != 0)) {
199 size[1] = ((u64)ddr3a_size - 2) << 30;
200 start[1] = 0x880000000;
204 /* reserve memory at start of bank */
205 sprintf(name, "mem_reserve_head");
208 start[0] += ustrtoul(env, &endp, 0);
209 size[0] -= ustrtoul(env, &endp, 0);
212 sprintf(name, "mem_reserve");
215 size[0] -= ustrtoul(env, &endp, 0);
217 fdt_fixup_memory_banks(blob, start, size, nbanks);
219 /* Fix up the initrd */
221 u64 initrd_start, initrd_end;
224 nodeoffset = fdt_path_offset(blob, "/chosen");
225 if (nodeoffset >= 0) {
226 prop1 = (u32 *)fdt_getprop(blob, nodeoffset,
227 "linux,initrd-start", NULL);
228 prop2 = (u32 *)fdt_getprop(blob, nodeoffset,
229 "linux,initrd-end", NULL);
230 if (prop1 && prop2) {
231 initrd_start = __be32_to_cpu(*prop1);
232 initrd_start -= K2_DDR3_START_ADDR;
233 initrd_start += CONFIG_SYS_LPAE_SDRAM_BASE;
234 initrd_start = __cpu_to_be64(initrd_start);
235 initrd_end = __be32_to_cpu(*prop2);
236 initrd_end -= K2_DDR3_START_ADDR;
237 initrd_end += CONFIG_SYS_LPAE_SDRAM_BASE;
238 initrd_end = __cpu_to_be64(initrd_end);
240 err = fdt_delprop(blob, nodeoffset,
241 "linux,initrd-start");
243 puts("error deleting initrd-start\n");
245 err = fdt_delprop(blob, nodeoffset,
248 puts("error deleting initrd-end\n");
250 err = fdt_setprop(blob, nodeoffset,
251 "linux,initrd-start",
253 sizeof(initrd_start));
255 puts("error adding initrd-start\n");
257 err = fdt_setprop(blob, nodeoffset,
262 puts("error adding linux,initrd-end\n");
268 void ft_board_setup_ex(void *blob, bd_t *bd)
272 u64 *reserve_start, size;
274 env = getenv("mem_lpae");
275 lpae = env && simple_strtol(env, NULL, 0);
279 * the initrd and other reserved memory areas are
280 * embedded in in the DTB itslef. fix up these addresses
283 reserve_start = (u64 *)((char *)blob +
284 fdt_off_mem_rsvmap(blob));
286 *reserve_start = __cpu_to_be64(*reserve_start);
287 size = __cpu_to_be64(*(reserve_start + 1));
289 *reserve_start -= K2_DDR3_START_ADDR;
291 CONFIG_SYS_LPAE_SDRAM_BASE;
293 __cpu_to_be64(*reserve_start);