blob: 646ecb37e7378bf3ba01eb8b0cf4a79dfeff9163 [file] [log] [blame]
Vitaly Andrianovef509b92014-04-04 13:16:53 -04001/*
2 * K2HK EVM : Board initialization
3 *
4 * (C) Copyright 2012-2014
5 * Texas Instruments Incorporated, <www.ti.com>
6 *
7 * SPDX-License-Identifier: GPL-2.0+
8 */
9
10#include <common.h>
11#include <exports.h>
12#include <fdt_support.h>
13#include <libfdt.h>
14
Khoronzhuk, Ivan0b868582014-07-09 19:48:40 +030015#include <asm/arch/ddr3.h>
Vitaly Andrianovef509b92014-04-04 13:16:53 -040016#include <asm/arch/hardware.h>
17#include <asm/arch/clock.h>
18#include <asm/io.h>
19#include <asm/mach-types.h>
Karicheri, Muralidharanfc9a8e82014-04-01 15:01:13 -040020#include <asm/arch/emac_defs.h>
Vitaly Andrianovef509b92014-04-04 13:16:53 -040021#include <asm/arch/psc_defs.h>
Khoronzhuk, Ivan909ea9a2014-06-07 05:10:49 +030022#include <asm/ti-common/ti-aemif.h>
Vitaly Andrianovef509b92014-04-04 13:16:53 -040023
24DECLARE_GLOBAL_DATA_PTR;
25
Vitaly Andrianovef509b92014-04-04 13:16:53 -040026unsigned int external_clk[ext_clk_count] = {
27 [sys_clk] = 122880000,
28 [alt_core_clk] = 125000000,
29 [pa_clk] = 122880000,
30 [tetris_clk] = 125000000,
31 [ddr3a_clk] = 100000000,
32 [ddr3b_clk] = 100000000,
33 [mcm_clk] = 312500000,
34 [pcie_clk] = 100000000,
35 [sgmii_srio_clk] = 156250000,
36 [xgmii_clk] = 156250000,
37 [usb_clk] = 100000000,
38 [rp1_clk] = 123456789 /* TODO: cannot find
39 what is that */
40};
41
Khoronzhuk, Ivan909ea9a2014-06-07 05:10:49 +030042static struct aemif_config aemif_configs[] = {
Vitaly Andrianovef509b92014-04-04 13:16:53 -040043 { /* CS0 */
Khoronzhuk, Ivan909ea9a2014-06-07 05:10:49 +030044 .mode = AEMIF_MODE_NAND,
Vitaly Andrianovef509b92014-04-04 13:16:53 -040045 .wr_setup = 0xf,
46 .wr_strobe = 0x3f,
47 .wr_hold = 7,
48 .rd_setup = 0xf,
49 .rd_strobe = 0x3f,
50 .rd_hold = 7,
51 .turn_around = 3,
Khoronzhuk, Ivan909ea9a2014-06-07 05:10:49 +030052 .width = AEMIF_WIDTH_8,
Vitaly Andrianovef509b92014-04-04 13:16:53 -040053 },
54
55};
56
57static struct pll_init_data pll_config[] = {
58 CORE_PLL_1228,
59 PASS_PLL_983,
60 TETRIS_PLL_1200,
61};
62
63int dram_init(void)
64{
Khoronzhuk, Ivan0b868582014-07-09 19:48:40 +030065 ddr3_init();
Vitaly Andrianovef509b92014-04-04 13:16:53 -040066
67 gd->ram_size = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE,
68 CONFIG_MAX_RAM_BANK_SIZE);
Khoronzhuk, Ivan909ea9a2014-06-07 05:10:49 +030069 aemif_init(ARRAY_SIZE(aemif_configs), aemif_configs);
Vitaly Andrianovef509b92014-04-04 13:16:53 -040070 return 0;
71}
72
Karicheri, Muralidharanfc9a8e82014-04-01 15:01:13 -040073#ifdef CONFIG_DRIVER_TI_KEYSTONE_NET
74struct eth_priv_t eth_priv_cfg[] = {
75 {
76 .int_name = "K2HK_EMAC",
77 .rx_flow = 22,
78 .phy_addr = 0,
79 .slave_port = 1,
80 .sgmii_link_type = SGMII_LINK_MAC_PHY,
81 },
82 {
83 .int_name = "K2HK_EMAC1",
84 .rx_flow = 23,
85 .phy_addr = 1,
86 .slave_port = 2,
87 .sgmii_link_type = SGMII_LINK_MAC_PHY,
88 },
89 {
90 .int_name = "K2HK_EMAC2",
91 .rx_flow = 24,
92 .phy_addr = 2,
93 .slave_port = 3,
94 .sgmii_link_type = SGMII_LINK_MAC_MAC_FORCED,
95 },
96 {
97 .int_name = "K2HK_EMAC3",
98 .rx_flow = 25,
99 .phy_addr = 3,
100 .slave_port = 4,
101 .sgmii_link_type = SGMII_LINK_MAC_MAC_FORCED,
102 },
103};
104
105int get_eth_env_param(char *env_name)
106{
107 char *env;
108 int res = -1;
109
110 env = getenv(env_name);
111 if (env)
112 res = simple_strtol(env, NULL, 0);
113
114 return res;
115}
116
117int board_eth_init(bd_t *bis)
118{
119 int j;
120 int res;
121 char link_type_name[32];
122
123 for (j = 0; j < (sizeof(eth_priv_cfg) / sizeof(struct eth_priv_t));
124 j++) {
125 sprintf(link_type_name, "sgmii%d_link_type", j);
126 res = get_eth_env_param(link_type_name);
127 if (res >= 0)
128 eth_priv_cfg[j].sgmii_link_type = res;
129
130 keystone2_emac_initialize(&eth_priv_cfg[j]);
131 }
132
133 return 0;
134}
135#endif
136
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400137#if defined(CONFIG_BOARD_EARLY_INIT_F)
138int board_early_init_f(void)
139{
140 init_plls(ARRAY_SIZE(pll_config), pll_config);
141 return 0;
142}
143#endif
144
145int board_init(void)
146{
147 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
148
149 return 0;
150}
151
152#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
153#define K2_DDR3_START_ADDR 0x80000000
154void ft_board_setup(void *blob, bd_t *bd)
155{
156 u64 start[2];
157 u64 size[2];
158 char name[32], *env, *endp;
159 int lpae, nodeoffset;
Murali Karicheri0bedbb82014-07-09 23:44:45 +0300160 int unitrd_fixup = 0;
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400161 u32 ddr3a_size;
162 int nbanks;
163
164 env = getenv("mem_lpae");
165 lpae = env && simple_strtol(env, NULL, 0);
Murali Karicheri0bedbb82014-07-09 23:44:45 +0300166 env = getenv("uinitrd_fixup");
167 unitrd_fixup = env && simple_strtol(env, NULL, 0);
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400168
169 ddr3a_size = 0;
170 if (lpae) {
171 env = getenv("ddr3a_size");
172 if (env)
173 ddr3a_size = simple_strtol(env, NULL, 10);
174 if ((ddr3a_size != 8) && (ddr3a_size != 4))
175 ddr3a_size = 0;
176 }
177
178 nbanks = 1;
179 start[0] = bd->bi_dram[0].start;
180 size[0] = bd->bi_dram[0].size;
181
182 /* adjust memory start address for LPAE */
183 if (lpae) {
184 start[0] -= K2_DDR3_START_ADDR;
185 start[0] += CONFIG_SYS_LPAE_SDRAM_BASE;
186 }
187
188 if ((size[0] == 0x80000000) && (ddr3a_size != 0)) {
189 size[1] = ((u64)ddr3a_size - 2) << 30;
190 start[1] = 0x880000000;
191 nbanks++;
192 }
193
194 /* reserve memory at start of bank */
195 sprintf(name, "mem_reserve_head");
196 env = getenv(name);
197 if (env) {
198 start[0] += ustrtoul(env, &endp, 0);
199 size[0] -= ustrtoul(env, &endp, 0);
200 }
201
202 sprintf(name, "mem_reserve");
203 env = getenv(name);
204 if (env)
205 size[0] -= ustrtoul(env, &endp, 0);
206
207 fdt_fixup_memory_banks(blob, start, size, nbanks);
208
209 /* Fix up the initrd */
Murali Karicheri0bedbb82014-07-09 23:44:45 +0300210 if (lpae && unitrd_fixup) {
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400211 u64 initrd_start, initrd_end;
212 u32 *prop1, *prop2;
213 int err;
Murali Karicheri0bedbb82014-07-09 23:44:45 +0300214
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400215 nodeoffset = fdt_path_offset(blob, "/chosen");
216 if (nodeoffset >= 0) {
217 prop1 = (u32 *)fdt_getprop(blob, nodeoffset,
218 "linux,initrd-start", NULL);
219 prop2 = (u32 *)fdt_getprop(blob, nodeoffset,
220 "linux,initrd-end", NULL);
221 if (prop1 && prop2) {
222 initrd_start = __be32_to_cpu(*prop1);
223 initrd_start -= K2_DDR3_START_ADDR;
224 initrd_start += CONFIG_SYS_LPAE_SDRAM_BASE;
225 initrd_start = __cpu_to_be64(initrd_start);
226 initrd_end = __be32_to_cpu(*prop2);
227 initrd_end -= K2_DDR3_START_ADDR;
228 initrd_end += CONFIG_SYS_LPAE_SDRAM_BASE;
229 initrd_end = __cpu_to_be64(initrd_end);
230
231 err = fdt_delprop(blob, nodeoffset,
232 "linux,initrd-start");
233 if (err < 0)
234 puts("error deleting initrd-start\n");
235
236 err = fdt_delprop(blob, nodeoffset,
237 "linux,initrd-end");
238 if (err < 0)
239 puts("error deleting initrd-end\n");
240
241 err = fdt_setprop(blob, nodeoffset,
242 "linux,initrd-start",
243 &initrd_start,
244 sizeof(initrd_start));
245 if (err < 0)
246 puts("error adding initrd-start\n");
247
248 err = fdt_setprop(blob, nodeoffset,
249 "linux,initrd-end",
250 &initrd_end,
251 sizeof(initrd_end));
252 if (err < 0)
253 puts("error adding linux,initrd-end\n");
254 }
255 }
256 }
257}
258
259void ft_board_setup_ex(void *blob, bd_t *bd)
260{
261 int lpae;
262 char *env;
263 u64 *reserve_start, size;
264
265 env = getenv("mem_lpae");
266 lpae = env && simple_strtol(env, NULL, 0);
267
268 if (lpae) {
269 /*
270 * the initrd and other reserved memory areas are
271 * embedded in in the DTB itslef. fix up these addresses
272 * to 36 bit format
273 */
274 reserve_start = (u64 *)((char *)blob +
275 fdt_off_mem_rsvmap(blob));
276 while (1) {
277 *reserve_start = __cpu_to_be64(*reserve_start);
278 size = __cpu_to_be64(*(reserve_start + 1));
279 if (size) {
280 *reserve_start -= K2_DDR3_START_ADDR;
281 *reserve_start +=
282 CONFIG_SYS_LPAE_SDRAM_BASE;
283 *reserve_start =
284 __cpu_to_be64(*reserve_start);
285 } else {
286 break;
287 }
288 reserve_start += 2;
289 }
290 }
291}
292#endif