blob: e9bc68049b4bf93fe7172f76e75970ba270839e6 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Vitaly Andrianovef509b92014-04-04 13:16:53 -04002/*
Hao Zhange5951072014-07-09 23:44:46 +03003 * Keystone : Board initialization
Vitaly Andrianovef509b92014-04-04 13:16:53 -04004 *
Hao Zhange5951072014-07-09 23:44:46 +03005 * (C) Copyright 2014
Vitaly Andrianovef509b92014-04-04 13:16:53 -04006 * Texas Instruments Incorporated, <www.ti.com>
Vitaly Andrianovef509b92014-04-04 13:16:53 -04007 */
8
9#include <common.h>
Vitaly Andrianovb8dafa22016-03-11 08:23:04 -050010#include "board.h"
Simon Glass7b51b572019-08-01 09:46:52 -060011#include <env.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>
Khoronzhuk, Ivan497e9e02014-09-29 22:17:24 +030016#include <asm/arch/psc_defs.h>
Lokesh Vutla8626cb82015-10-08 11:31:47 +053017#include <asm/arch/clock.h>
Khoronzhuk, Ivan909ea9a2014-06-07 05:10:49 +030018#include <asm/ti-common/ti-aemif.h>
Khoronzhuk, Ivan0935cac2014-09-29 22:17:22 +030019#include <asm/ti-common/keystone_net.h>
Vitaly Andrianovef509b92014-04-04 13:16:53 -040020
21DECLARE_GLOBAL_DATA_PTR;
22
Lokesh Vutla8f695232016-04-13 09:50:59 +053023#if defined(CONFIG_TI_AEMIF)
Khoronzhuk, Ivan909ea9a2014-06-07 05:10:49 +030024static struct aemif_config aemif_configs[] = {
Vitaly Andrianovef509b92014-04-04 13:16:53 -040025 { /* CS0 */
Khoronzhuk, Ivan909ea9a2014-06-07 05:10:49 +030026 .mode = AEMIF_MODE_NAND,
Vitaly Andrianovef509b92014-04-04 13:16:53 -040027 .wr_setup = 0xf,
28 .wr_strobe = 0x3f,
29 .wr_hold = 7,
30 .rd_setup = 0xf,
31 .rd_strobe = 0x3f,
32 .rd_hold = 7,
33 .turn_around = 3,
Khoronzhuk, Ivan909ea9a2014-06-07 05:10:49 +030034 .width = AEMIF_WIDTH_8,
Vitaly Andrianovef509b92014-04-04 13:16:53 -040035 },
Vitaly Andrianovef509b92014-04-04 13:16:53 -040036};
Lokesh Vutla8f695232016-04-13 09:50:59 +053037#endif
Vitaly Andrianovef509b92014-04-04 13:16:53 -040038
39int dram_init(void)
40{
Vitaly Andrianov66c98a02015-02-11 14:07:58 -050041 u32 ddr3_size;
42
43 ddr3_size = ddr3_init();
Vitaly Andrianovef509b92014-04-04 13:16:53 -040044
45 gd->ram_size = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE,
46 CONFIG_MAX_RAM_BANK_SIZE);
Lokesh Vutla8f695232016-04-13 09:50:59 +053047#if defined(CONFIG_TI_AEMIF)
Cooper Jr., Frankline66a5da2017-06-16 17:25:25 -050048 if (!board_is_k2g_ice())
49 aemif_init(ARRAY_SIZE(aemif_configs), aemif_configs);
Lokesh Vutla8f695232016-04-13 09:50:59 +053050#endif
51
Cooper Jr., Frankline66a5da2017-06-16 17:25:25 -050052 if (!board_is_k2g_ice()) {
53 if (ddr3_size)
54 ddr3_init_ecc(KS2_DDR3A_EMIF_CTRL_BASE, ddr3_size);
55 else
56 ddr3_init_ecc(KS2_DDR3A_EMIF_CTRL_BASE,
57 gd->ram_size >> 30);
58 }
Lokesh Vutlae92a6b22016-08-27 17:19:15 +053059
Vitaly Andrianovef509b92014-04-04 13:16:53 -040060 return 0;
61}
62
Keerthy3b074fb2018-11-27 17:52:41 +053063struct image_header *spl_get_load_buffer(ssize_t offset, size_t size)
64{
65 return (struct image_header *)(CONFIG_SYS_TEXT_BASE);
66}
67
Hao Zhange5951072014-07-09 23:44:46 +030068int board_init(void)
69{
Jean-Jacques Hiblotc9d52202018-12-04 11:12:57 +010070#if CONFIG_IS_ENABLED(DM_USB)
71 int rc = psc_enable_module(KS2_LPSC_USB);
72
73 if (rc)
74 puts("Cannot enable USB0 module");
75#ifdef KS2_LPSC_USB_1
76 rc = psc_enable_module(KS2_LPSC_USB_1);
77 if (rc)
78 puts("Cannot enable USB1 module");
79#endif
80#endif
81
Nishanth Menon59d4cd22015-07-22 18:05:43 -050082 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
Karicheri, Muralidharanfc9a8e82014-04-01 15:01:13 -040083
Hao Zhange5951072014-07-09 23:44:46 +030084 return 0;
85}
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
Robert P. J. Day7ffe3cd2016-05-19 15:23:12 -0400105#ifdef CONFIG_OF_BOARD_SETUP
Simon Glasse895a4b2014-10-23 18:58:47 -0600106int ft_board_setup(void *blob, bd_t *bd)
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400107{
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];
Hao Zhange5951072014-07-09 23:44:46 +0300114 u32 ddr3a_size;
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400115
Simon Glass00caae62017-08-03 12:22:12 -0600116 env = env_get("mem_lpae");
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400117 lpae = env && simple_strtol(env, NULL, 0);
118
119 ddr3a_size = 0;
120 if (lpae) {
Vitaly Andrianov8efc2432016-03-04 10:36:43 -0600121 ddr3a_size = ddr3_get_size();
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400122 if ((ddr3a_size != 8) && (ddr3a_size != 4))
123 ddr3a_size = 0;
124 }
125
126 nbanks = 1;
127 start[0] = bd->bi_dram[0].start;
128 size[0] = bd->bi_dram[0].size;
129
130 /* adjust memory start address for LPAE */
131 if (lpae) {
Hao Zhange5951072014-07-09 23:44:46 +0300132 start[0] -= CONFIG_SYS_SDRAM_BASE;
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400133 start[0] += CONFIG_SYS_LPAE_SDRAM_BASE;
134 }
135
136 if ((size[0] == 0x80000000) && (ddr3a_size != 0)) {
137 size[1] = ((u64)ddr3a_size - 2) << 30;
138 start[1] = 0x880000000;
139 nbanks++;
140 }
141
142 /* reserve memory at start of bank */
Simon Glass00caae62017-08-03 12:22:12 -0600143 env = env_get("mem_reserve_head");
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400144 if (env) {
145 start[0] += ustrtoul(env, &endp, 0);
146 size[0] -= ustrtoul(env, &endp, 0);
147 }
148
Simon Glass00caae62017-08-03 12:22:12 -0600149 env = env_get("mem_reserve");
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400150 if (env)
151 size[0] -= ustrtoul(env, &endp, 0);
152
153 fdt_fixup_memory_banks(blob, start, size, nbanks);
154
Nicholas Faustini442faf62018-10-03 12:58:49 +0200155 return 0;
156}
157
158void ft_board_setup_ex(void *blob, bd_t *bd)
159{
160 int lpae;
161 u64 size;
162 char *env;
163 u64 *reserve_start;
164 int unitrd_fixup = 0;
165
166 env = env_get("mem_lpae");
167 lpae = env && simple_strtol(env, NULL, 0);
168 env = env_get("uinitrd_fixup");
169 unitrd_fixup = env && simple_strtol(env, NULL, 0);
170
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400171 /* Fix up the initrd */
Murali Karicheri0bedbb82014-07-09 23:44:45 +0300172 if (lpae && unitrd_fixup) {
Nicholas Faustini442faf62018-10-03 12:58:49 +0200173 int nodeoffset;
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400174 int err;
Nicholas Faustini442faf62018-10-03 12:58:49 +0200175 u64 *prop1, *prop2;
Hao Zhange5951072014-07-09 23:44:46 +0300176 u64 initrd_start, initrd_end;
Murali Karicheri0bedbb82014-07-09 23:44:45 +0300177
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400178 nodeoffset = fdt_path_offset(blob, "/chosen");
179 if (nodeoffset >= 0) {
Nicholas Faustini442faf62018-10-03 12:58:49 +0200180 prop1 = (u64 *)fdt_getprop(blob, nodeoffset,
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400181 "linux,initrd-start", NULL);
Nicholas Faustini442faf62018-10-03 12:58:49 +0200182 prop2 = (u64 *)fdt_getprop(blob, nodeoffset,
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400183 "linux,initrd-end", NULL);
184 if (prop1 && prop2) {
Nicholas Faustini442faf62018-10-03 12:58:49 +0200185 initrd_start = __be64_to_cpu(*prop1);
Hao Zhange5951072014-07-09 23:44:46 +0300186 initrd_start -= CONFIG_SYS_SDRAM_BASE;
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400187 initrd_start += CONFIG_SYS_LPAE_SDRAM_BASE;
188 initrd_start = __cpu_to_be64(initrd_start);
Nicholas Faustini442faf62018-10-03 12:58:49 +0200189 initrd_end = __be64_to_cpu(*prop2);
Hao Zhange5951072014-07-09 23:44:46 +0300190 initrd_end -= CONFIG_SYS_SDRAM_BASE;
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400191 initrd_end += CONFIG_SYS_LPAE_SDRAM_BASE;
192 initrd_end = __cpu_to_be64(initrd_end);
193
194 err = fdt_delprop(blob, nodeoffset,
195 "linux,initrd-start");
196 if (err < 0)
197 puts("error deleting initrd-start\n");
198
199 err = fdt_delprop(blob, nodeoffset,
200 "linux,initrd-end");
201 if (err < 0)
202 puts("error deleting initrd-end\n");
203
204 err = fdt_setprop(blob, nodeoffset,
205 "linux,initrd-start",
206 &initrd_start,
207 sizeof(initrd_start));
208 if (err < 0)
209 puts("error adding initrd-start\n");
210
211 err = fdt_setprop(blob, nodeoffset,
212 "linux,initrd-end",
213 &initrd_end,
214 sizeof(initrd_end));
215 if (err < 0)
216 puts("error adding linux,initrd-end\n");
217 }
218 }
219 }
Simon Glasse895a4b2014-10-23 18:58:47 -0600220
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400221 if (lpae) {
222 /*
223 * the initrd and other reserved memory areas are
224 * embedded in in the DTB itslef. fix up these addresses
225 * to 36 bit format
226 */
227 reserve_start = (u64 *)((char *)blob +
228 fdt_off_mem_rsvmap(blob));
229 while (1) {
230 *reserve_start = __cpu_to_be64(*reserve_start);
231 size = __cpu_to_be64(*(reserve_start + 1));
232 if (size) {
Hao Zhange5951072014-07-09 23:44:46 +0300233 *reserve_start -= CONFIG_SYS_SDRAM_BASE;
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400234 *reserve_start +=
235 CONFIG_SYS_LPAE_SDRAM_BASE;
236 *reserve_start =
237 __cpu_to_be64(*reserve_start);
238 } else {
239 break;
240 }
241 reserve_start += 2;
242 }
243 }
Vitaly Andrianov89f44bb2014-10-22 17:47:58 +0300244
245 ddr3_check_ecc_int(KS2_DDR3A_EMIF_CTRL_BASE);
Vitaly Andrianovef509b92014-04-04 13:16:53 -0400246}
Robert P. J. Day7ffe3cd2016-05-19 15:23:12 -0400247#endif /* CONFIG_OF_BOARD_SETUP */
Cooper Jr., Franklin5f48da92017-06-16 17:25:15 -0500248
249#if defined(CONFIG_DTB_RESELECT)
250int __weak embedded_dtb_select(void)
251{
252 return 0;
253}
254#endif