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/ddr3.h>
16 #include <asm/arch/hardware.h>
17 #include <asm/arch/clock.h>
19 #include <asm/mach-types.h>
20 #include <asm/arch/emac_defs.h>
21 #include <asm/arch/psc_defs.h>
22 #include <asm/ti-common/ti-aemif.h>
24 DECLARE_GLOBAL_DATA_PTR
;
26 u32 device_big_endian
;
28 unsigned int external_clk
[ext_clk_count
] = {
29 [sys_clk
] = 122880000,
30 [alt_core_clk
] = 125000000,
32 [tetris_clk
] = 125000000,
33 [ddr3a_clk
] = 100000000,
34 [ddr3b_clk
] = 100000000,
35 [mcm_clk
] = 312500000,
36 [pcie_clk
] = 100000000,
37 [sgmii_srio_clk
] = 156250000,
38 [xgmii_clk
] = 156250000,
39 [usb_clk
] = 100000000,
40 [rp1_clk
] = 123456789 /* TODO: cannot find
44 static struct aemif_config aemif_configs
[] = {
46 .mode
= AEMIF_MODE_NAND
,
54 .width
= AEMIF_WIDTH_8
,
59 static struct pll_init_data pll_config
[] = {
69 gd
->ram_size
= get_ram_size((long *)CONFIG_SYS_SDRAM_BASE
,
70 CONFIG_MAX_RAM_BANK_SIZE
);
71 aemif_init(ARRAY_SIZE(aemif_configs
), aemif_configs
);
75 #ifdef CONFIG_DRIVER_TI_KEYSTONE_NET
76 struct eth_priv_t eth_priv_cfg
[] = {
78 .int_name
= "K2HK_EMAC",
82 .sgmii_link_type
= SGMII_LINK_MAC_PHY
,
85 .int_name
= "K2HK_EMAC1",
89 .sgmii_link_type
= SGMII_LINK_MAC_PHY
,
92 .int_name
= "K2HK_EMAC2",
96 .sgmii_link_type
= SGMII_LINK_MAC_MAC_FORCED
,
99 .int_name
= "K2HK_EMAC3",
103 .sgmii_link_type
= SGMII_LINK_MAC_MAC_FORCED
,
107 int get_eth_env_param(char *env_name
)
112 env
= getenv(env_name
);
114 res
= simple_strtol(env
, NULL
, 0);
119 int board_eth_init(bd_t
*bis
)
123 char link_type_name
[32];
125 for (j
= 0; j
< (sizeof(eth_priv_cfg
) / sizeof(struct eth_priv_t
));
127 sprintf(link_type_name
, "sgmii%d_link_type", j
);
128 res
= get_eth_env_param(link_type_name
);
130 eth_priv_cfg
[j
].sgmii_link_type
= res
;
132 keystone2_emac_initialize(ð_priv_cfg
[j
]);
139 /* Byte swap the 32-bit data if the device is BE */
140 int cpu_to_bus(u32
*ptr
, u32 length
)
144 if (device_big_endian
)
145 for (i
= 0; i
< length
; i
++, ptr
++)
146 *ptr
= __swab32(*ptr
);
151 #if defined(CONFIG_BOARD_EARLY_INIT_F)
152 int board_early_init_f(void)
154 init_plls(ARRAY_SIZE(pll_config
), pll_config
);
161 gd
->bd
->bi_boot_params
= CONFIG_SYS_SDRAM_BASE
+ 0x100;
166 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
167 #define K2_DDR3_START_ADDR 0x80000000
168 void ft_board_setup(void *blob
, bd_t
*bd
)
172 char name
[32], *env
, *endp
;
173 int lpae
, nodeoffset
;
177 env
= getenv("mem_lpae");
178 lpae
= env
&& simple_strtol(env
, NULL
, 0);
182 env
= getenv("ddr3a_size");
184 ddr3a_size
= simple_strtol(env
, NULL
, 10);
185 if ((ddr3a_size
!= 8) && (ddr3a_size
!= 4))
190 start
[0] = bd
->bi_dram
[0].start
;
191 size
[0] = bd
->bi_dram
[0].size
;
193 /* adjust memory start address for LPAE */
195 start
[0] -= K2_DDR3_START_ADDR
;
196 start
[0] += CONFIG_SYS_LPAE_SDRAM_BASE
;
199 if ((size
[0] == 0x80000000) && (ddr3a_size
!= 0)) {
200 size
[1] = ((u64
)ddr3a_size
- 2) << 30;
201 start
[1] = 0x880000000;
205 /* reserve memory at start of bank */
206 sprintf(name
, "mem_reserve_head");
209 start
[0] += ustrtoul(env
, &endp
, 0);
210 size
[0] -= ustrtoul(env
, &endp
, 0);
213 sprintf(name
, "mem_reserve");
216 size
[0] -= ustrtoul(env
, &endp
, 0);
218 fdt_fixup_memory_banks(blob
, start
, size
, nbanks
);
220 /* Fix up the initrd */
222 u64 initrd_start
, initrd_end
;
225 nodeoffset
= fdt_path_offset(blob
, "/chosen");
226 if (nodeoffset
>= 0) {
227 prop1
= (u32
*)fdt_getprop(blob
, nodeoffset
,
228 "linux,initrd-start", NULL
);
229 prop2
= (u32
*)fdt_getprop(blob
, nodeoffset
,
230 "linux,initrd-end", NULL
);
231 if (prop1
&& prop2
) {
232 initrd_start
= __be32_to_cpu(*prop1
);
233 initrd_start
-= K2_DDR3_START_ADDR
;
234 initrd_start
+= CONFIG_SYS_LPAE_SDRAM_BASE
;
235 initrd_start
= __cpu_to_be64(initrd_start
);
236 initrd_end
= __be32_to_cpu(*prop2
);
237 initrd_end
-= K2_DDR3_START_ADDR
;
238 initrd_end
+= CONFIG_SYS_LPAE_SDRAM_BASE
;
239 initrd_end
= __cpu_to_be64(initrd_end
);
241 err
= fdt_delprop(blob
, nodeoffset
,
242 "linux,initrd-start");
244 puts("error deleting initrd-start\n");
246 err
= fdt_delprop(blob
, nodeoffset
,
249 puts("error deleting initrd-end\n");
251 err
= fdt_setprop(blob
, nodeoffset
,
252 "linux,initrd-start",
254 sizeof(initrd_start
));
256 puts("error adding initrd-start\n");
258 err
= fdt_setprop(blob
, nodeoffset
,
263 puts("error adding linux,initrd-end\n");
269 void ft_board_setup_ex(void *blob
, bd_t
*bd
)
273 u64
*reserve_start
, size
;
275 env
= getenv("mem_lpae");
276 lpae
= env
&& simple_strtol(env
, NULL
, 0);
280 * the initrd and other reserved memory areas are
281 * embedded in in the DTB itslef. fix up these addresses
284 reserve_start
= (u64
*)((char *)blob
+
285 fdt_off_mem_rsvmap(blob
));
287 *reserve_start
= __cpu_to_be64(*reserve_start
);
288 size
= __cpu_to_be64(*(reserve_start
+ 1));
290 *reserve_start
-= K2_DDR3_START_ADDR
;
292 CONFIG_SYS_LPAE_SDRAM_BASE
;
294 __cpu_to_be64(*reserve_start
);