blob: 6aad1352c44358b6525b67d2e81f730b6e18bef6 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Michal Simek04b7e622015-01-15 10:01:51 +01002/*
3 * (C) Copyright 2014 - 2015 Xilinx, Inc.
4 * Michal Simek <michal.simek@xilinx.com>
Michal Simek04b7e622015-01-15 10:01:51 +01005 */
6
7#include <common.h>
Simon Glass370382c2019-11-14 12:57:35 -07008#include <cpu_func.h>
Michal Simek09a7d7d2020-01-07 09:02:52 +01009#include <debug_uart.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060010#include <env.h>
Simon Glassa7b51302019-11-14 12:57:46 -070011#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -060012#include <net.h>
Michal Simekd54b1af2015-09-30 17:26:55 +020013#include <sata.h>
Michal Simekb216cc12015-07-23 13:27:40 +020014#include <ahci.h>
15#include <scsi.h>
Michal Simekecfb6dc2016-04-22 14:28:54 +020016#include <malloc.h>
Michal Simekbf0f9ca2018-04-19 15:43:38 +020017#include <wdt.h>
Michal Simekc23d3f82015-11-05 08:34:35 +010018#include <asm/arch/clk.h>
Michal Simek04b7e622015-01-15 10:01:51 +010019#include <asm/arch/hardware.h>
20#include <asm/arch/sys_proto.h>
Michal Simekf2f08642018-01-10 09:36:09 +010021#include <asm/arch/psu_init_gpl.h>
Simon Glass274e0b02020-05-10 11:39:56 -060022#include <asm/cache.h>
Michal Simek04b7e622015-01-15 10:01:51 +010023#include <asm/io.h>
Michal Simekf183a982018-04-25 11:20:43 +020024#include <dm/device.h>
Michal Simekbf0f9ca2018-04-19 15:43:38 +020025#include <dm/uclass.h>
Siva Durga Prasad Paladuguba1f68e2015-08-04 13:03:26 +053026#include <usb.h>
27#include <dwc3-uboot.h>
Michal Simek8111aff2016-02-01 15:05:58 +010028#include <zynqmppl.h>
Ibai Erkiagac8a3efa2019-09-27 11:37:01 +010029#include <zynqmp_firmware.h>
Michal Simek76d0a772016-09-01 11:16:40 +020030#include <g_dnl.h>
Michal Simek705d44a2020-03-31 12:39:37 +020031#include "../common/board.h"
Michal Simek04b7e622015-01-15 10:01:51 +010032
Luca Ceresoli23e65002019-05-21 18:06:43 +020033#include "pm_cfg_obj.h"
34
Michal Simek04b7e622015-01-15 10:01:51 +010035DECLARE_GLOBAL_DATA_PTR;
36
Michal Simek8111aff2016-02-01 15:05:58 +010037#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
38 !defined(CONFIG_SPL_BUILD)
39static xilinx_desc zynqmppl = XILINX_ZYNQMP_DESC;
40
41static const struct {
Michal Simek6908b862017-11-06 12:55:59 +010042 u32 id;
Michal Simek50d8cef2017-08-22 14:58:53 +020043 u32 ver;
Michal Simek8111aff2016-02-01 15:05:58 +010044 char *name;
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +053045 bool evexists;
Michal Simek8111aff2016-02-01 15:05:58 +010046} zynqmp_devices[] = {
47 {
48 .id = 0x10,
49 .name = "3eg",
50 },
51 {
Michal Simek50d8cef2017-08-22 14:58:53 +020052 .id = 0x10,
53 .ver = 0x2c,
54 .name = "3cg",
55 },
56 {
Michal Simek8111aff2016-02-01 15:05:58 +010057 .id = 0x11,
58 .name = "2eg",
59 },
60 {
Michal Simek50d8cef2017-08-22 14:58:53 +020061 .id = 0x11,
62 .ver = 0x2c,
63 .name = "2cg",
64 },
65 {
Michal Simek8111aff2016-02-01 15:05:58 +010066 .id = 0x20,
67 .name = "5ev",
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +053068 .evexists = 1,
Michal Simek8111aff2016-02-01 15:05:58 +010069 },
70 {
Michal Simek50d8cef2017-08-22 14:58:53 +020071 .id = 0x20,
72 .ver = 0x100,
73 .name = "5eg",
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +053074 .evexists = 1,
Michal Simek50d8cef2017-08-22 14:58:53 +020075 },
76 {
77 .id = 0x20,
78 .ver = 0x12c,
79 .name = "5cg",
Siva Durga Prasad Paladugu951c0192018-10-26 17:47:55 +053080 .evexists = 1,
Michal Simek50d8cef2017-08-22 14:58:53 +020081 },
82 {
Michal Simek8111aff2016-02-01 15:05:58 +010083 .id = 0x21,
84 .name = "4ev",
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +053085 .evexists = 1,
Michal Simek8111aff2016-02-01 15:05:58 +010086 },
87 {
Michal Simek50d8cef2017-08-22 14:58:53 +020088 .id = 0x21,
89 .ver = 0x100,
90 .name = "4eg",
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +053091 .evexists = 1,
Michal Simek50d8cef2017-08-22 14:58:53 +020092 },
93 {
94 .id = 0x21,
95 .ver = 0x12c,
96 .name = "4cg",
Siva Durga Prasad Paladugu951c0192018-10-26 17:47:55 +053097 .evexists = 1,
Michal Simek50d8cef2017-08-22 14:58:53 +020098 },
99 {
Michal Simek8111aff2016-02-01 15:05:58 +0100100 .id = 0x30,
101 .name = "7ev",
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530102 .evexists = 1,
Michal Simek8111aff2016-02-01 15:05:58 +0100103 },
104 {
Michal Simek50d8cef2017-08-22 14:58:53 +0200105 .id = 0x30,
106 .ver = 0x100,
107 .name = "7eg",
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530108 .evexists = 1,
Michal Simek50d8cef2017-08-22 14:58:53 +0200109 },
110 {
111 .id = 0x30,
112 .ver = 0x12c,
113 .name = "7cg",
Siva Durga Prasad Paladugu951c0192018-10-26 17:47:55 +0530114 .evexists = 1,
Michal Simek50d8cef2017-08-22 14:58:53 +0200115 },
116 {
Michal Simek8111aff2016-02-01 15:05:58 +0100117 .id = 0x38,
118 .name = "9eg",
119 },
120 {
Michal Simek50d8cef2017-08-22 14:58:53 +0200121 .id = 0x38,
122 .ver = 0x2c,
123 .name = "9cg",
124 },
125 {
Michal Simek8111aff2016-02-01 15:05:58 +0100126 .id = 0x39,
127 .name = "6eg",
128 },
129 {
Michal Simek50d8cef2017-08-22 14:58:53 +0200130 .id = 0x39,
131 .ver = 0x2c,
132 .name = "6cg",
133 },
134 {
Michal Simek8111aff2016-02-01 15:05:58 +0100135 .id = 0x40,
136 .name = "11eg",
137 },
Michal Simek50d8cef2017-08-22 14:58:53 +0200138 { /* For testing purpose only */
139 .id = 0x50,
140 .ver = 0x2c,
141 .name = "15cg",
142 },
Michal Simek8111aff2016-02-01 15:05:58 +0100143 {
144 .id = 0x50,
145 .name = "15eg",
146 },
147 {
148 .id = 0x58,
149 .name = "19eg",
150 },
151 {
152 .id = 0x59,
153 .name = "17eg",
154 },
Michal Simekb510e532017-06-02 08:08:59 +0200155 {
156 .id = 0x61,
157 .name = "21dr",
158 },
159 {
160 .id = 0x63,
161 .name = "23dr",
162 },
163 {
164 .id = 0x65,
165 .name = "25dr",
166 },
167 {
168 .id = 0x64,
169 .name = "27dr",
170 },
171 {
172 .id = 0x60,
173 .name = "28dr",
174 },
175 {
176 .id = 0x62,
177 .name = "29dr",
178 },
Siva Durga Prasad Paladugu70866b42019-03-23 15:00:06 +0530179 {
180 .id = 0x66,
181 .name = "39dr",
182 },
Siva Durga Prasad Paladugu85f61a82019-07-23 11:56:17 +0530183 {
184 .id = 0x7b,
185 .name = "48dr",
186 },
187 {
188 .id = 0x7e,
189 .name = "49dr",
190 },
Michal Simek8111aff2016-02-01 15:05:58 +0100191};
Siva Durga Prasad Paladugu8d526532017-07-25 11:51:37 +0530192#endif
Michal Simek8111aff2016-02-01 15:05:58 +0100193
Siva Durga Prasad Paladugucd35d522017-07-25 11:51:38 +0530194int chip_id(unsigned char id)
Michal Simek8111aff2016-02-01 15:05:58 +0100195{
196 struct pt_regs regs;
Siva Durga Prasad Paladugu9f0a8e92017-07-25 11:51:36 +0530197 int val = -EINVAL;
Michal Simek8111aff2016-02-01 15:05:58 +0100198
Siva Durga Prasad Paladugu8d526532017-07-25 11:51:37 +0530199 if (current_el() != 3) {
200 regs.regs[0] = ZYNQMP_SIP_SVC_CSU_DMA_CHIPID;
201 regs.regs[1] = 0;
202 regs.regs[2] = 0;
203 regs.regs[3] = 0;
Michal Simek8111aff2016-02-01 15:05:58 +0100204
Siva Durga Prasad Paladugu8d526532017-07-25 11:51:37 +0530205 smc_call(&regs);
206
207 /*
208 * SMC returns:
209 * regs[0][31:0] = status of the operation
210 * regs[0][63:32] = CSU.IDCODE register
211 * regs[1][31:0] = CSU.version register
Michal Simek50d8cef2017-08-22 14:58:53 +0200212 * regs[1][63:32] = CSU.IDCODE2 register
Siva Durga Prasad Paladugu8d526532017-07-25 11:51:37 +0530213 */
214 switch (id) {
215 case IDCODE:
216 regs.regs[0] = upper_32_bits(regs.regs[0]);
217 regs.regs[0] &= ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK |
218 ZYNQMP_CSU_IDCODE_SVD_MASK;
219 regs.regs[0] >>= ZYNQMP_CSU_IDCODE_SVD_SHIFT;
220 val = regs.regs[0];
221 break;
222 case VERSION:
223 regs.regs[1] = lower_32_bits(regs.regs[1]);
224 regs.regs[1] &= ZYNQMP_CSU_SILICON_VER_MASK;
225 val = regs.regs[1];
226 break;
Michal Simek50d8cef2017-08-22 14:58:53 +0200227 case IDCODE2:
228 regs.regs[1] = lower_32_bits(regs.regs[1]);
229 regs.regs[1] >>= ZYNQMP_CSU_VERSION_EMPTY_SHIFT;
230 val = regs.regs[1];
231 break;
Siva Durga Prasad Paladugu8d526532017-07-25 11:51:37 +0530232 default:
233 printf("%s, Invalid Req:0x%x\n", __func__, id);
234 }
235 } else {
236 switch (id) {
237 case IDCODE:
238 val = readl(ZYNQMP_CSU_IDCODE_ADDR);
239 val &= ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK |
240 ZYNQMP_CSU_IDCODE_SVD_MASK;
241 val >>= ZYNQMP_CSU_IDCODE_SVD_SHIFT;
242 break;
243 case VERSION:
244 val = readl(ZYNQMP_CSU_VER_ADDR);
245 val &= ZYNQMP_CSU_SILICON_VER_MASK;
246 break;
247 default:
248 printf("%s, Invalid Req:0x%x\n", __func__, id);
249 }
Siva Durga Prasad Paladugu9f0a8e92017-07-25 11:51:36 +0530250 }
Soren Brinkmannd7696a52016-09-29 11:44:41 -0700251
Siva Durga Prasad Paladugu9f0a8e92017-07-25 11:51:36 +0530252 return val;
Michal Simek8111aff2016-02-01 15:05:58 +0100253}
254
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530255#define ZYNQMP_VERSION_SIZE 9
256#define ZYNQMP_PL_STATUS_BIT 9
Siva Durga Prasad Paladugu951c0192018-10-26 17:47:55 +0530257#define ZYNQMP_IPDIS_VCU_BIT 8
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530258#define ZYNQMP_PL_STATUS_MASK BIT(ZYNQMP_PL_STATUS_BIT)
259#define ZYNQMP_CSU_VERSION_MASK ~(ZYNQMP_PL_STATUS_MASK)
Siva Durga Prasad Paladugu951c0192018-10-26 17:47:55 +0530260#define ZYNQMP_CSU_VCUDIS_VER_MASK ZYNQMP_CSU_VERSION_MASK & \
261 ~BIT(ZYNQMP_IPDIS_VCU_BIT)
262#define MAX_VARIANTS_EV 3
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530263
Siva Durga Prasad Paladugu8d526532017-07-25 11:51:37 +0530264#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
265 !defined(CONFIG_SPL_BUILD)
Michal Simek8111aff2016-02-01 15:05:58 +0100266static char *zynqmp_get_silicon_idcode_name(void)
267{
Siva Durga Prasad Paladugu951c0192018-10-26 17:47:55 +0530268 u32 i, id, ver, j;
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530269 char *buf;
270 static char name[ZYNQMP_VERSION_SIZE];
Michal Simek8111aff2016-02-01 15:05:58 +0100271
Siva Durga Prasad Paladugu9f0a8e92017-07-25 11:51:36 +0530272 id = chip_id(IDCODE);
Michal Simek50d8cef2017-08-22 14:58:53 +0200273 ver = chip_id(IDCODE2);
274
Michal Simek8111aff2016-02-01 15:05:58 +0100275 for (i = 0; i < ARRAY_SIZE(zynqmp_devices); i++) {
Siva Durga Prasad Paladugu951c0192018-10-26 17:47:55 +0530276 if (zynqmp_devices[i].id == id) {
277 if (zynqmp_devices[i].evexists &&
278 !(ver & ZYNQMP_PL_STATUS_MASK))
279 break;
280 if (zynqmp_devices[i].ver == (ver &
281 ZYNQMP_CSU_VERSION_MASK))
282 break;
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530283 }
Michal Simek8111aff2016-02-01 15:05:58 +0100284 }
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530285
286 if (i >= ARRAY_SIZE(zynqmp_devices))
287 return "unknown";
288
Siva Durga Prasad Paladugu951c0192018-10-26 17:47:55 +0530289 strncat(name, "zu", 2);
290 if (!zynqmp_devices[i].evexists ||
291 (ver & ZYNQMP_PL_STATUS_MASK)) {
292 strncat(name, zynqmp_devices[i].name,
293 ZYNQMP_VERSION_SIZE - 3);
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530294 return name;
Siva Durga Prasad Paladugu951c0192018-10-26 17:47:55 +0530295 }
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530296
Siva Durga Prasad Paladugu951c0192018-10-26 17:47:55 +0530297 /*
298 * Here we are means, PL not powered up and ev variant
299 * exists. So, we need to ignore VCU disable bit(8) in
300 * version and findout if its CG or EG/EV variant.
301 */
302 for (j = 0; j < MAX_VARIANTS_EV; j++, i++) {
303 if ((zynqmp_devices[i].ver & ~BIT(ZYNQMP_IPDIS_VCU_BIT)) ==
304 (ver & ZYNQMP_CSU_VCUDIS_VER_MASK)) {
305 strncat(name, zynqmp_devices[i].name,
306 ZYNQMP_VERSION_SIZE - 3);
307 break;
308 }
309 }
310
311 if (j >= MAX_VARIANTS_EV)
312 return "unknown";
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530313
314 if (strstr(name, "eg") || strstr(name, "ev")) {
315 buf = strstr(name, "e");
316 *buf = '\0';
317 }
318
319 return name;
Michal Simek8111aff2016-02-01 15:05:58 +0100320}
321#endif
322
Michal Simek8b353302017-02-07 14:32:26 +0100323int board_early_init_f(void)
324{
Michal Simek1a1ab5a2018-01-15 12:52:59 +0100325#if defined(CONFIG_ZYNQMP_PSU_INIT_ENABLED)
Michal Simek09a7d7d2020-01-07 09:02:52 +0100326 int ret;
327
Michal Simekc8785f22018-01-10 11:48:48 +0100328 ret = psu_init();
Michal Simek09a7d7d2020-01-07 09:02:52 +0100329 if (ret)
330 return ret;
Michal Simek1f55e572020-03-20 08:59:02 +0100331
332 /* Delay is required for clocks to be propagated */
333 udelay(1000000);
Michal Simeke0f36102017-07-12 13:08:41 +0200334#endif
335
Michal Simek09a7d7d2020-01-07 09:02:52 +0100336#ifdef CONFIG_DEBUG_UART
337 /* Uart debug for sure */
338 debug_uart_init();
339 puts("Debug uart enabled\n"); /* or printch() */
340#endif
341
342 return 0;
Michal Simek8b353302017-02-07 14:32:26 +0100343}
344
Michal Simek46900462020-02-11 12:43:14 +0100345static int multi_boot(void)
346{
347 u32 multiboot;
348
349 multiboot = readl(&csu_base->multi_boot);
350
351 printf("Multiboot:\t%x\n", multiboot);
352
353 return 0;
354}
355
Michal Simek04b7e622015-01-15 10:01:51 +0100356int board_init(void)
357{
Michal Simek826d7eca2020-03-04 08:48:16 +0100358#if defined(CONFIG_ZYNQMP_FIRMWARE)
Ibai Erkiaga2d9b95b2019-09-27 11:37:04 +0100359 struct udevice *dev;
360
361 uclass_get_device_by_name(UCLASS_FIRMWARE, "zynqmp-power", &dev);
362 if (!dev)
363 panic("PMU Firmware device not found - Enable it");
Michal Simek826d7eca2020-03-04 08:48:16 +0100364#endif
Ibai Erkiaga2d9b95b2019-09-27 11:37:04 +0100365
Luca Ceresoli23e65002019-05-21 18:06:43 +0200366#if defined(CONFIG_SPL_BUILD)
367 /* Check *at build time* if the filename is an non-empty string */
368 if (sizeof(CONFIG_ZYNQMP_SPL_PM_CFG_OBJ_FILE) > 1)
369 zynqmp_pmufw_load_config_object(zynqmp_pm_cfg_obj,
370 zynqmp_pm_cfg_obj_size);
371#endif
372
Michal Simekfb7242d2015-06-22 14:31:06 +0200373 printf("EL Level:\tEL%d\n", current_el());
374
Michal Simek8111aff2016-02-01 15:05:58 +0100375#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
376 !defined(CONFIG_SPL_BUILD) || (defined(CONFIG_SPL_FPGA_SUPPORT) && \
377 defined(CONFIG_SPL_BUILD))
378 if (current_el() != 3) {
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530379 zynqmppl.name = zynqmp_get_silicon_idcode_name();
Michal Simek8111aff2016-02-01 15:05:58 +0100380 printf("Chip ID:\t%s\n", zynqmppl.name);
381 fpga_init();
382 fpga_add(fpga_xilinx, &zynqmppl);
383 }
Michal Simekbf0f9ca2018-04-19 15:43:38 +0200384#endif
385
Michal Simek46900462020-02-11 12:43:14 +0100386 if (current_el() == 3)
387 multi_boot();
388
Michal Simek04b7e622015-01-15 10:01:51 +0100389 return 0;
390}
391
392int board_early_init_r(void)
393{
394 u32 val;
395
Siva Durga Prasad Paladugu64d90002017-12-07 15:05:30 +0530396 if (current_el() != 3)
397 return 0;
398
Michal Simek245d5282017-07-12 10:32:18 +0200399 val = readl(&crlapb_base->timestamp_ref_ctrl);
400 val &= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
401
Siva Durga Prasad Paladugu64d90002017-12-07 15:05:30 +0530402 if (!val) {
Michal Simekc23d3f82015-11-05 08:34:35 +0100403 val = readl(&crlapb_base->timestamp_ref_ctrl);
404 val |= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
405 writel(val, &crlapb_base->timestamp_ref_ctrl);
Michal Simek04b7e622015-01-15 10:01:51 +0100406
Michal Simekc23d3f82015-11-05 08:34:35 +0100407 /* Program freq register in System counter */
408 writel(zynqmp_get_system_timer_freq(),
409 &iou_scntr_secure->base_frequency_id_register);
410 /* And enable system counter */
411 writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN,
412 &iou_scntr_secure->counter_control_register);
413 }
Michal Simek04b7e622015-01-15 10:01:51 +0100414 return 0;
415}
416
Nitin Jainb2eb59b2018-02-16 12:56:17 +0530417unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc,
418 char * const argv[])
419{
420 int ret = 0;
421
422 if (current_el() > 1) {
423 smp_kick_all_cpus();
424 dcache_disable();
425 armv8_switch_to_el1(0x0, 0, 0, 0, (unsigned long)entry,
426 ES_TO_AARCH64);
427 } else {
428 printf("FAIL: current EL is not above EL1\n");
429 ret = EINVAL;
430 }
431 return ret;
432}
433
Michal Simek8faa66a2016-02-08 09:34:53 +0100434#if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE)
Simon Glass2f949c32017-03-31 08:40:32 -0600435int dram_init_banksize(void)
Michal Simek8faa66a2016-02-08 09:34:53 +0100436{
Nitin Jain9bcc76f2018-04-20 12:30:40 +0530437 int ret;
438
439 ret = fdtdec_setup_memory_banksize();
440 if (ret)
441 return ret;
442
443 mem_map_fill();
444
445 return 0;
Tom Riniedcfdbd2016-12-09 07:56:54 -0500446}
Michal Simek8faa66a2016-02-08 09:34:53 +0100447
Tom Riniedcfdbd2016-12-09 07:56:54 -0500448int dram_init(void)
449{
Siva Durga Prasad Paladugub3d55ea2018-07-16 15:56:11 +0530450 if (fdtdec_setup_mem_size_base() != 0)
Nathan Rossiac04bfa2016-12-19 00:03:34 +1000451 return -EINVAL;
Tom Riniedcfdbd2016-12-09 07:56:54 -0500452
453 return 0;
Michal Simek8faa66a2016-02-08 09:34:53 +0100454}
455#else
Nitin Jain9bcc76f2018-04-20 12:30:40 +0530456int dram_init_banksize(void)
457{
458#if defined(CONFIG_NR_DRAM_BANKS)
459 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
460 gd->bd->bi_dram[0].size = get_effective_memsize();
461#endif
462
463 mem_map_fill();
464
465 return 0;
466}
467
Michal Simek04b7e622015-01-15 10:01:51 +0100468int dram_init(void)
469{
Michal Simek1b846212018-04-11 16:12:28 +0200470 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
471 CONFIG_SYS_SDRAM_SIZE);
Michal Simek04b7e622015-01-15 10:01:51 +0100472
473 return 0;
474}
Michal Simek8faa66a2016-02-08 09:34:53 +0100475#endif
Michal Simek04b7e622015-01-15 10:01:51 +0100476
Michal Simek04b7e622015-01-15 10:01:51 +0100477void reset_cpu(ulong addr)
478{
479}
480
Michal Simek342edfe2018-12-20 09:33:38 +0100481#if defined(CONFIG_BOARD_LATE_INIT)
Michal Simek29b9b712018-05-17 14:06:06 +0200482static const struct {
483 u32 bit;
484 const char *name;
485} reset_reasons[] = {
486 { RESET_REASON_DEBUG_SYS, "DEBUG" },
487 { RESET_REASON_SOFT, "SOFT" },
488 { RESET_REASON_SRST, "SRST" },
489 { RESET_REASON_PSONLY, "PS-ONLY" },
490 { RESET_REASON_PMU, "PMU" },
491 { RESET_REASON_INTERNAL, "INTERNAL" },
492 { RESET_REASON_EXTERNAL, "EXTERNAL" },
493 {}
494};
495
T Karthik Reddy09b6def2019-03-13 20:24:18 +0530496static int reset_reason(void)
Michal Simek29b9b712018-05-17 14:06:06 +0200497{
T Karthik Reddy09b6def2019-03-13 20:24:18 +0530498 u32 reg;
499 int i, ret;
Michal Simek29b9b712018-05-17 14:06:06 +0200500 const char *reason = NULL;
501
T Karthik Reddy09b6def2019-03-13 20:24:18 +0530502 ret = zynqmp_mmio_read((ulong)&crlapb_base->reset_reason, &reg);
503 if (ret)
504 return -EINVAL;
Michal Simek29b9b712018-05-17 14:06:06 +0200505
506 puts("Reset reason:\t");
507
508 for (i = 0; i < ARRAY_SIZE(reset_reasons); i++) {
T Karthik Reddy09b6def2019-03-13 20:24:18 +0530509 if (reg & reset_reasons[i].bit) {
Michal Simek29b9b712018-05-17 14:06:06 +0200510 reason = reset_reasons[i].name;
511 printf("%s ", reset_reasons[i].name);
512 break;
513 }
514 }
515
516 puts("\n");
517
518 env_set("reset_reason", reason);
519
Michal Simek4c4efde2020-03-23 14:02:01 +0100520 ret = zynqmp_mmio_write((ulong)&crlapb_base->reset_reason, ~0, ~0);
T Karthik Reddy09b6def2019-03-13 20:24:18 +0530521 if (ret)
522 return -EINVAL;
Michal Simek29b9b712018-05-17 14:06:06 +0200523
524 return ret;
525}
526
Michal Simek1ca66d72019-02-14 13:14:30 +0100527static int set_fdtfile(void)
528{
529 char *compatible, *fdtfile;
530 const char *suffix = ".dtb";
531 const char *vendor = "xilinx/";
532
533 if (env_get("fdtfile"))
534 return 0;
535
536 compatible = (char *)fdt_getprop(gd->fdt_blob, 0, "compatible", NULL);
537 if (compatible) {
538 debug("Compatible: %s\n", compatible);
539
540 /* Discard vendor prefix */
541 strsep(&compatible, ",");
542
543 fdtfile = calloc(1, strlen(vendor) + strlen(compatible) +
544 strlen(suffix) + 1);
545 if (!fdtfile)
546 return -ENOMEM;
547
548 sprintf(fdtfile, "%s%s%s", vendor, compatible, suffix);
549
550 env_set("fdtfile", fdtfile);
551 free(fdtfile);
552 }
553
554 return 0;
555}
556
Michal Simek9c91e612020-04-08 11:04:41 +0200557static u8 zynqmp_get_bootmode(void)
Michal Simek04b7e622015-01-15 10:01:51 +0100558{
Michal Simek9c91e612020-04-08 11:04:41 +0200559 u8 bootmode;
Michal Simek04b7e622015-01-15 10:01:51 +0100560 u32 reg = 0;
Michal Simek9c91e612020-04-08 11:04:41 +0200561 int ret;
562
563 ret = zynqmp_mmio_read((ulong)&crlapb_base->boot_mode, &reg);
564 if (ret)
565 return -EINVAL;
566
567 if (reg >> BOOT_MODE_ALT_SHIFT)
568 reg >>= BOOT_MODE_ALT_SHIFT;
569
570 bootmode = reg & BOOT_MODES_MASK;
571
572 return bootmode;
573}
574
575int board_late_init(void)
576{
Michal Simek04b7e622015-01-15 10:01:51 +0100577 u8 bootmode;
Michal Simekf183a982018-04-25 11:20:43 +0200578 struct udevice *dev;
579 int bootseq = -1;
580 int bootseq_len = 0;
Michal Simek7410b142018-04-25 11:10:34 +0200581 int env_targets_len = 0;
Michal Simekecfb6dc2016-04-22 14:28:54 +0200582 const char *mode;
583 char *new_targets;
Siva Durga Prasad Paladugu245c5562017-12-20 16:35:06 +0530584 char *env_targets;
Siva Durga Prasad Paladugue6fd3bb2017-02-21 17:58:28 +0530585 int ret;
Michal Simekecfb6dc2016-04-22 14:28:54 +0200586
Michal Simek482f5492018-10-05 08:55:16 +0200587#if defined(CONFIG_USB_ETHER) && !defined(CONFIG_USB_GADGET_DOWNLOAD)
588 usb_ether_init();
589#endif
590
Michal Simekecfb6dc2016-04-22 14:28:54 +0200591 if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
592 debug("Saved variables - Skipping\n");
593 return 0;
594 }
Michal Simek04b7e622015-01-15 10:01:51 +0100595
Michal Simek1ca66d72019-02-14 13:14:30 +0100596 ret = set_fdtfile();
597 if (ret)
598 return ret;
599
Michal Simek9c91e612020-04-08 11:04:41 +0200600 bootmode = zynqmp_get_bootmode();
Michal Simek04b7e622015-01-15 10:01:51 +0100601
Michal Simekc5d95232015-09-20 17:20:42 +0200602 puts("Bootmode: ");
Michal Simek04b7e622015-01-15 10:01:51 +0100603 switch (bootmode) {
Michal Simek12398ea2016-08-19 14:14:52 +0200604 case USB_MODE:
605 puts("USB_MODE\n");
606 mode = "usb";
Michal Simek43380352017-12-01 15:18:24 +0100607 env_set("modeboot", "usb_dfu_spl");
Michal Simek12398ea2016-08-19 14:14:52 +0200608 break;
Siva Durga Prasad Paladugu30f0fc72015-03-13 11:10:26 +0530609 case JTAG_MODE:
Michal Simekc5d95232015-09-20 17:20:42 +0200610 puts("JTAG_MODE\n");
Siva Durga Prasad Paladugu9c441702019-06-25 17:41:09 +0530611 mode = "jtag pxe dhcp";
Michal Simek43380352017-12-01 15:18:24 +0100612 env_set("modeboot", "jtagboot");
Siva Durga Prasad Paladugu30f0fc72015-03-13 11:10:26 +0530613 break;
614 case QSPI_MODE_24BIT:
615 case QSPI_MODE_32BIT:
Michal Simekecfb6dc2016-04-22 14:28:54 +0200616 mode = "qspi0";
Michal Simekc5d95232015-09-20 17:20:42 +0200617 puts("QSPI_MODE\n");
Michal Simek43380352017-12-01 15:18:24 +0100618 env_set("modeboot", "qspiboot");
Siva Durga Prasad Paladugu30f0fc72015-03-13 11:10:26 +0530619 break;
Michal Simek02d66cd2015-04-15 15:02:28 +0200620 case EMMC_MODE:
Michal Simekdf7ff0a2015-10-05 15:59:38 +0200621 puts("EMMC_MODE\n");
T Karthik Reddy19735c32019-12-17 06:41:42 -0700622 if (uclass_get_device_by_name(UCLASS_MMC,
623 "mmc@ff160000", &dev) &&
624 uclass_get_device_by_name(UCLASS_MMC,
625 "sdhci@ff160000", &dev)) {
626 puts("Boot from EMMC but without SD0 enabled!\n");
627 return -1;
628 }
629 debug("mmc0 device found at %p, seq %d\n", dev, dev->seq);
630
631 mode = "mmc";
632 bootseq = dev->seq;
Michal Simekdf7ff0a2015-10-05 15:59:38 +0200633 break;
634 case SD_MODE:
Michal Simekc5d95232015-09-20 17:20:42 +0200635 puts("SD_MODE\n");
Michal Simekf183a982018-04-25 11:20:43 +0200636 if (uclass_get_device_by_name(UCLASS_MMC,
Siva Durga Prasad Paladugue91778d2019-01-03 15:44:24 +0530637 "mmc@ff160000", &dev) &&
638 uclass_get_device_by_name(UCLASS_MMC,
Michal Simekf183a982018-04-25 11:20:43 +0200639 "sdhci@ff160000", &dev)) {
640 puts("Boot from SD0 but without SD0 enabled!\n");
641 return -1;
642 }
643 debug("mmc0 device found at %p, seq %d\n", dev, dev->seq);
644
645 mode = "mmc";
646 bootseq = dev->seq;
Michal Simek43380352017-12-01 15:18:24 +0100647 env_set("modeboot", "sdboot");
Michal Simek04b7e622015-01-15 10:01:51 +0100648 break;
Siva Durga Prasad Paladugu29a77d22016-09-21 11:45:05 +0530649 case SD1_LSHFT_MODE:
650 puts("LVL_SHFT_");
651 /* fall through */
Michal Simek108e1842015-10-05 10:51:12 +0200652 case SD_MODE1:
Michal Simekc5d95232015-09-20 17:20:42 +0200653 puts("SD_MODE1\n");
Michal Simekf183a982018-04-25 11:20:43 +0200654 if (uclass_get_device_by_name(UCLASS_MMC,
Siva Durga Prasad Paladugue91778d2019-01-03 15:44:24 +0530655 "mmc@ff170000", &dev) &&
656 uclass_get_device_by_name(UCLASS_MMC,
Michal Simekf183a982018-04-25 11:20:43 +0200657 "sdhci@ff170000", &dev)) {
658 puts("Boot from SD1 but without SD1 enabled!\n");
659 return -1;
660 }
661 debug("mmc1 device found at %p, seq %d\n", dev, dev->seq);
662
663 mode = "mmc";
664 bootseq = dev->seq;
Michal Simek43380352017-12-01 15:18:24 +0100665 env_set("modeboot", "sdboot");
Michal Simek108e1842015-10-05 10:51:12 +0200666 break;
667 case NAND_MODE:
Michal Simekc5d95232015-09-20 17:20:42 +0200668 puts("NAND_MODE\n");
Michal Simekecfb6dc2016-04-22 14:28:54 +0200669 mode = "nand0";
Michal Simek43380352017-12-01 15:18:24 +0100670 env_set("modeboot", "nandboot");
Michal Simek108e1842015-10-05 10:51:12 +0200671 break;
Michal Simek04b7e622015-01-15 10:01:51 +0100672 default:
Michal Simekecfb6dc2016-04-22 14:28:54 +0200673 mode = "";
Michal Simek04b7e622015-01-15 10:01:51 +0100674 printf("Invalid Boot Mode:0x%x\n", bootmode);
675 break;
676 }
677
Michal Simekf183a982018-04-25 11:20:43 +0200678 if (bootseq >= 0) {
679 bootseq_len = snprintf(NULL, 0, "%i", bootseq);
680 debug("Bootseq len: %x\n", bootseq_len);
681 }
682
Michal Simekecfb6dc2016-04-22 14:28:54 +0200683 /*
684 * One terminating char + one byte for space between mode
685 * and default boot_targets
686 */
Siva Durga Prasad Paladugu245c5562017-12-20 16:35:06 +0530687 env_targets = env_get("boot_targets");
Michal Simek7410b142018-04-25 11:10:34 +0200688 if (env_targets)
689 env_targets_len = strlen(env_targets);
690
Michal Simekf183a982018-04-25 11:20:43 +0200691 new_targets = calloc(1, strlen(mode) + env_targets_len + 2 +
692 bootseq_len);
Michal Simek089b84d2018-06-13 09:42:41 +0200693 if (!new_targets)
694 return -ENOMEM;
Michal Simek7410b142018-04-25 11:10:34 +0200695
Michal Simekf183a982018-04-25 11:20:43 +0200696 if (bootseq >= 0)
697 sprintf(new_targets, "%s%x %s", mode, bootseq,
698 env_targets ? env_targets : "");
699 else
700 sprintf(new_targets, "%s %s", mode,
701 env_targets ? env_targets : "");
Michal Simekecfb6dc2016-04-22 14:28:54 +0200702
Simon Glass6a38e412017-08-03 12:22:09 -0600703 env_set("boot_targets", new_targets);
Michal Simekecfb6dc2016-04-22 14:28:54 +0200704
Michal Simek29b9b712018-05-17 14:06:06 +0200705 reset_reason();
706
Michal Simek705d44a2020-03-31 12:39:37 +0200707 return board_late_init_xilinx();
Michal Simek04b7e622015-01-15 10:01:51 +0100708}
Michal Simek342edfe2018-12-20 09:33:38 +0100709#endif
Siva Durga Prasad Paladugu650e0a32015-08-04 13:01:05 +0530710
711int checkboard(void)
712{
Michal Simek47ce9362016-01-25 11:04:21 +0100713 puts("Board: Xilinx ZynqMP\n");
Siva Durga Prasad Paladugu650e0a32015-08-04 13:01:05 +0530714 return 0;
715}