blob: c07d2848ba55853e8d5f5073817b6b6b8f286250 [file] [log] [blame]
Vitaly Andrianovef509b92014-04-04 13:16:53 -04001/*
Hao Zhange5951072014-07-09 23:44:46 +03002 * Keystone : Board initialization
Vitaly Andrianovef509b92014-04-04 13:16:53 -04003 *
Hao Zhange5951072014-07-09 23:44:46 +03004 * (C) Copyright 2014
Vitaly Andrianovef509b92014-04-04 13:16:53 -04005 * Texas Instruments Incorporated, <www.ti.com>
6 *
7 * SPDX-License-Identifier: GPL-2.0+
8 */
9
Hao Zhange5951072014-07-09 23:44:46 +030010#include "board.h"
Vitaly Andrianovef509b92014-04-04 13:16:53 -040011#include <common.h>
Hao Zhang5ec66b12014-10-22 16:32:31 +030012#include <spl.h>
Vitaly Andrianovef509b92014-04-04 13:16:53 -040013#include <exports.h>
14#include <fdt_support.h>
Khoronzhuk, Ivan0b868582014-07-09 19:48:40 +030015#include <asm/arch/ddr3.h>
Karicheri, Muralidharanfc9a8e82014-04-01 15:01:13 -040016#include <asm/arch/emac_defs.h>
Khoronzhuk, Ivan909ea9a2014-06-07 05:10:49 +030017#include <asm/ti-common/ti-aemif.h>
Vitaly Andrianovef509b92014-04-04 13:16:53 -040018
19DECLARE_GLOBAL_DATA_PTR;
20
Khoronzhuk, Ivan909ea9a2014-06-07 05:10:49 +030021static struct aemif_config aemif_configs[] = {
Vitaly Andrianovef509b92014-04-04 13:16:53 -040022 { /* CS0 */
Khoronzhuk, Ivan909ea9a2014-06-07 05:10:49 +030023 .mode = AEMIF_MODE_NAND,
Vitaly Andrianovef509b92014-04-04 13:16:53 -040024 .wr_setup = 0xf,
25 .wr_strobe = 0x3f,
26 .wr_hold = 7,
27 .rd_setup = 0xf,
28 .rd_strobe = 0x3f,
29 .rd_hold = 7,
30 .turn_around = 3,
Khoronzhuk, Ivan909ea9a2014-06-07 05:10:49 +030031 .width = AEMIF_WIDTH_8,
Vitaly Andrianovef509b92014-04-04 13:16:53 -040032 },
Vitaly Andrianovef509b92014-04-04 13:16:53 -040033};
34
35int dram_init(void)
36{
Khoronzhuk, Ivan0b868582014-07-09 19:48:40 +030037 ddr3_init();
Vitaly Andrianovef509b92014-04-04 13:16:53 -040038
39 gd->ram_size = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE,
40 CONFIG_MAX_RAM_BANK_SIZE);
Khoronzhuk, Ivan909ea9a2014-06-07 05:10:49 +030041 aemif_init(ARRAY_SIZE(aemif_configs), aemif_configs);
Vitaly Andrianovef509b92014-04-04 13:16:53 -040042 return 0;
43}
44
Hao Zhange5951072014-07-09 23:44:46 +030045int board_init(void)
46{
47 gd->bd->bi_boot_params = CONFIG_LINUX_BOOT_PARAM_ADDR;
Karicheri, Muralidharanfc9a8e82014-04-01 15:01:13 -040048
Hao Zhange5951072014-07-09 23:44:46 +030049 return 0;
50}
51
52#ifdef CONFIG_DRIVER_TI_KEYSTONE_NET
Karicheri, Muralidharanfc9a8e82014-04-01 15:01:13 -040053int get_eth_env_param(char *env_name)
54{
55 char *env;
Hao Zhange5951072014-07-09 23:44:46 +030056 int res = -1;
Karicheri, Muralidharanfc9a8e82014-04-01 15:01:13 -040057
58 env = getenv(env_name);
59 if (env)
60 res = simple_strtol(env, NULL, 0);
61
62 return res;
63}
64
65int board_eth_init(bd_t *bis)
66{
Hao Zhange5951072014-07-09 23:44:46 +030067 int j;
68 int res;
69 int port_num;
70 char link_type_name[32];
Karicheri, Muralidharanfc9a8e82014-04-01 15:01:13 -040071
Hao Zhange5951072014-07-09 23:44:46 +030072 port_num = get_num_eth_ports();
73
74 for (j = 0; j < port_num; j++) {
Karicheri, Muralidharanfc9a8e82014-04-01 15:01:13 -040075 sprintf(link_type_name, "sgmii%d_link_type", j);
76 res = get_eth_env_param(link_type_name);
77 if (res >= 0)
78 eth_priv_cfg[j].sgmii_link_type = res;
79
80 keystone2_emac_initialize(&eth_priv_cfg[j]);
81 }
82
83 return 0;
84}
85#endif
86
Hao Zhang5ec66b12014-10-22 16:32:31 +030087#ifdef CONFIG_SPL_BUILD
88void spl_board_init(void)
89{
90 spl_init_keystone_plls();
91 preloader_console_init();
92}
93
94u32 spl_boot_device(void)
95{
96#if defined(CONFIG_SPL_SPI_LOAD)
97 return BOOT_DEVICE_SPI;
98#else
99 puts("Unknown boot device\n");
100 hang();
101#endif
102}
103#endif
104
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400105#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400106void ft_board_setup(void *blob, bd_t *bd)
107{
Hao Zhange5951072014-07-09 23:44:46 +0300108 int lpae;
109 char *env;
110 char *endp;
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400111 int nbanks;
Hao Zhange5951072014-07-09 23:44:46 +0300112 u64 size[2];
113 u64 start[2];
114 char name[32];
115 int nodeoffset;
116 u32 ddr3a_size;
117 int unitrd_fixup = 0;
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400118
119 env = getenv("mem_lpae");
120 lpae = env && simple_strtol(env, NULL, 0);
Murali Karicheri0bedbb82014-07-09 23:44:45 +0300121 env = getenv("uinitrd_fixup");
122 unitrd_fixup = env && simple_strtol(env, NULL, 0);
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400123
124 ddr3a_size = 0;
125 if (lpae) {
126 env = getenv("ddr3a_size");
127 if (env)
128 ddr3a_size = simple_strtol(env, NULL, 10);
129 if ((ddr3a_size != 8) && (ddr3a_size != 4))
130 ddr3a_size = 0;
131 }
132
133 nbanks = 1;
134 start[0] = bd->bi_dram[0].start;
135 size[0] = bd->bi_dram[0].size;
136
137 /* adjust memory start address for LPAE */
138 if (lpae) {
Hao Zhange5951072014-07-09 23:44:46 +0300139 start[0] -= CONFIG_SYS_SDRAM_BASE;
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400140 start[0] += CONFIG_SYS_LPAE_SDRAM_BASE;
141 }
142
143 if ((size[0] == 0x80000000) && (ddr3a_size != 0)) {
144 size[1] = ((u64)ddr3a_size - 2) << 30;
145 start[1] = 0x880000000;
146 nbanks++;
147 }
148
149 /* reserve memory at start of bank */
150 sprintf(name, "mem_reserve_head");
151 env = getenv(name);
152 if (env) {
153 start[0] += ustrtoul(env, &endp, 0);
154 size[0] -= ustrtoul(env, &endp, 0);
155 }
156
157 sprintf(name, "mem_reserve");
158 env = getenv(name);
159 if (env)
160 size[0] -= ustrtoul(env, &endp, 0);
161
162 fdt_fixup_memory_banks(blob, start, size, nbanks);
163
164 /* Fix up the initrd */
Murali Karicheri0bedbb82014-07-09 23:44:45 +0300165 if (lpae && unitrd_fixup) {
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400166 int err;
Hao Zhange5951072014-07-09 23:44:46 +0300167 u32 *prop1, *prop2;
168 u64 initrd_start, initrd_end;
Murali Karicheri0bedbb82014-07-09 23:44:45 +0300169
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400170 nodeoffset = fdt_path_offset(blob, "/chosen");
171 if (nodeoffset >= 0) {
172 prop1 = (u32 *)fdt_getprop(blob, nodeoffset,
173 "linux,initrd-start", NULL);
174 prop2 = (u32 *)fdt_getprop(blob, nodeoffset,
175 "linux,initrd-end", NULL);
176 if (prop1 && prop2) {
177 initrd_start = __be32_to_cpu(*prop1);
Hao Zhange5951072014-07-09 23:44:46 +0300178 initrd_start -= CONFIG_SYS_SDRAM_BASE;
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400179 initrd_start += CONFIG_SYS_LPAE_SDRAM_BASE;
180 initrd_start = __cpu_to_be64(initrd_start);
181 initrd_end = __be32_to_cpu(*prop2);
Hao Zhange5951072014-07-09 23:44:46 +0300182 initrd_end -= CONFIG_SYS_SDRAM_BASE;
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400183 initrd_end += CONFIG_SYS_LPAE_SDRAM_BASE;
184 initrd_end = __cpu_to_be64(initrd_end);
185
186 err = fdt_delprop(blob, nodeoffset,
187 "linux,initrd-start");
188 if (err < 0)
189 puts("error deleting initrd-start\n");
190
191 err = fdt_delprop(blob, nodeoffset,
192 "linux,initrd-end");
193 if (err < 0)
194 puts("error deleting initrd-end\n");
195
196 err = fdt_setprop(blob, nodeoffset,
197 "linux,initrd-start",
198 &initrd_start,
199 sizeof(initrd_start));
200 if (err < 0)
201 puts("error adding initrd-start\n");
202
203 err = fdt_setprop(blob, nodeoffset,
204 "linux,initrd-end",
205 &initrd_end,
206 sizeof(initrd_end));
207 if (err < 0)
208 puts("error adding linux,initrd-end\n");
209 }
210 }
211 }
212}
213
214void ft_board_setup_ex(void *blob, bd_t *bd)
215{
Hao Zhange5951072014-07-09 23:44:46 +0300216 int lpae;
217 u64 size;
218 char *env;
219 u64 *reserve_start;
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400220
221 env = getenv("mem_lpae");
222 lpae = env && simple_strtol(env, NULL, 0);
223
224 if (lpae) {
225 /*
226 * the initrd and other reserved memory areas are
227 * embedded in in the DTB itslef. fix up these addresses
228 * to 36 bit format
229 */
230 reserve_start = (u64 *)((char *)blob +
231 fdt_off_mem_rsvmap(blob));
232 while (1) {
233 *reserve_start = __cpu_to_be64(*reserve_start);
234 size = __cpu_to_be64(*(reserve_start + 1));
235 if (size) {
Hao Zhange5951072014-07-09 23:44:46 +0300236 *reserve_start -= CONFIG_SYS_SDRAM_BASE;
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400237 *reserve_start +=
238 CONFIG_SYS_LPAE_SDRAM_BASE;
239 *reserve_start =
240 __cpu_to_be64(*reserve_start);
241 } else {
242 break;
243 }
244 reserve_start += 2;
245 }
246 }
247}
248#endif