blob: cb72914adb3c112238faf8a5c8b9a2677cbe53d6 [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 Glassed38aef2020-05-10 11:40:03 -06008#include <command.h>
Simon Glass370382c2019-11-14 12:57:35 -07009#include <cpu_func.h>
Michal Simek09a7d7d2020-01-07 09:02:52 +010010#include <debug_uart.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060011#include <env.h>
Simon Glassa7b51302019-11-14 12:57:46 -070012#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060013#include <log.h>
Simon Glass274e0b02020-05-10 11:39:56 -060014#include <net.h>
Michal Simekd54b1af2015-09-30 17:26:55 +020015#include <sata.h>
Michal Simekb216cc12015-07-23 13:27:40 +020016#include <ahci.h>
17#include <scsi.h>
Michal Simekecfb6dc2016-04-22 14:28:54 +020018#include <malloc.h>
Michal Simekbf0f9ca2018-04-19 15:43:38 +020019#include <wdt.h>
Michal Simekc23d3f82015-11-05 08:34:35 +010020#include <asm/arch/clk.h>
Michal Simek04b7e622015-01-15 10:01:51 +010021#include <asm/arch/hardware.h>
22#include <asm/arch/sys_proto.h>
Michal Simekf2f08642018-01-10 09:36:09 +010023#include <asm/arch/psu_init_gpl.h>
Simon Glass274e0b02020-05-10 11:39:56 -060024#include <asm/cache.h>
Michal Simek04b7e622015-01-15 10:01:51 +010025#include <asm/io.h>
Simon Glass6b9f0102020-05-10 11:40:06 -060026#include <asm/ptrace.h>
Michal Simekf183a982018-04-25 11:20:43 +020027#include <dm/device.h>
Michal Simekbf0f9ca2018-04-19 15:43:38 +020028#include <dm/uclass.h>
Siva Durga Prasad Paladuguba1f68e2015-08-04 13:03:26 +053029#include <usb.h>
30#include <dwc3-uboot.h>
Michal Simek8111aff2016-02-01 15:05:58 +010031#include <zynqmppl.h>
Ibai Erkiagac8a3efa2019-09-27 11:37:01 +010032#include <zynqmp_firmware.h>
Michal Simek76d0a772016-09-01 11:16:40 +020033#include <g_dnl.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060034#include <linux/bitops.h>
Simon Glassdbd79542020-05-10 11:40:11 -060035#include <linux/delay.h>
36#include <linux/sizes.h>
Michal Simek705d44a2020-03-31 12:39:37 +020037#include "../common/board.h"
Michal Simek04b7e622015-01-15 10:01:51 +010038
Luca Ceresoli23e65002019-05-21 18:06:43 +020039#include "pm_cfg_obj.h"
40
Michal Simek04b7e622015-01-15 10:01:51 +010041DECLARE_GLOBAL_DATA_PTR;
42
Michal Simek8111aff2016-02-01 15:05:58 +010043#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
44 !defined(CONFIG_SPL_BUILD)
45static xilinx_desc zynqmppl = XILINX_ZYNQMP_DESC;
46
47static const struct {
Michal Simek6908b862017-11-06 12:55:59 +010048 u32 id;
Michal Simek50d8cef2017-08-22 14:58:53 +020049 u32 ver;
Michal Simek8111aff2016-02-01 15:05:58 +010050 char *name;
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +053051 bool evexists;
Michal Simek8111aff2016-02-01 15:05:58 +010052} zynqmp_devices[] = {
53 {
54 .id = 0x10,
55 .name = "3eg",
56 },
57 {
Michal Simek50d8cef2017-08-22 14:58:53 +020058 .id = 0x10,
59 .ver = 0x2c,
60 .name = "3cg",
61 },
62 {
Michal Simek8111aff2016-02-01 15:05:58 +010063 .id = 0x11,
64 .name = "2eg",
65 },
66 {
Michal Simek50d8cef2017-08-22 14:58:53 +020067 .id = 0x11,
68 .ver = 0x2c,
69 .name = "2cg",
70 },
71 {
Michal Simek8111aff2016-02-01 15:05:58 +010072 .id = 0x20,
73 .name = "5ev",
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +053074 .evexists = 1,
Michal Simek8111aff2016-02-01 15:05:58 +010075 },
76 {
Michal Simek50d8cef2017-08-22 14:58:53 +020077 .id = 0x20,
78 .ver = 0x100,
79 .name = "5eg",
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +053080 .evexists = 1,
Michal Simek50d8cef2017-08-22 14:58:53 +020081 },
82 {
83 .id = 0x20,
84 .ver = 0x12c,
85 .name = "5cg",
Siva Durga Prasad Paladugu951c0192018-10-26 17:47:55 +053086 .evexists = 1,
Michal Simek50d8cef2017-08-22 14:58:53 +020087 },
88 {
Michal Simek8111aff2016-02-01 15:05:58 +010089 .id = 0x21,
90 .name = "4ev",
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +053091 .evexists = 1,
Michal Simek8111aff2016-02-01 15:05:58 +010092 },
93 {
Michal Simek50d8cef2017-08-22 14:58:53 +020094 .id = 0x21,
95 .ver = 0x100,
96 .name = "4eg",
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +053097 .evexists = 1,
Michal Simek50d8cef2017-08-22 14:58:53 +020098 },
99 {
100 .id = 0x21,
101 .ver = 0x12c,
102 .name = "4cg",
Siva Durga Prasad Paladugu951c0192018-10-26 17:47:55 +0530103 .evexists = 1,
Michal Simek50d8cef2017-08-22 14:58:53 +0200104 },
105 {
Michal Simek8111aff2016-02-01 15:05:58 +0100106 .id = 0x30,
107 .name = "7ev",
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530108 .evexists = 1,
Michal Simek8111aff2016-02-01 15:05:58 +0100109 },
110 {
Michal Simek50d8cef2017-08-22 14:58:53 +0200111 .id = 0x30,
112 .ver = 0x100,
113 .name = "7eg",
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530114 .evexists = 1,
Michal Simek50d8cef2017-08-22 14:58:53 +0200115 },
116 {
117 .id = 0x30,
118 .ver = 0x12c,
119 .name = "7cg",
Siva Durga Prasad Paladugu951c0192018-10-26 17:47:55 +0530120 .evexists = 1,
Michal Simek50d8cef2017-08-22 14:58:53 +0200121 },
122 {
Michal Simek8111aff2016-02-01 15:05:58 +0100123 .id = 0x38,
124 .name = "9eg",
125 },
126 {
Michal Simek50d8cef2017-08-22 14:58:53 +0200127 .id = 0x38,
128 .ver = 0x2c,
129 .name = "9cg",
130 },
131 {
Michal Simek8111aff2016-02-01 15:05:58 +0100132 .id = 0x39,
133 .name = "6eg",
134 },
135 {
Michal Simek50d8cef2017-08-22 14:58:53 +0200136 .id = 0x39,
137 .ver = 0x2c,
138 .name = "6cg",
139 },
140 {
Michal Simek8111aff2016-02-01 15:05:58 +0100141 .id = 0x40,
142 .name = "11eg",
143 },
Michal Simek50d8cef2017-08-22 14:58:53 +0200144 { /* For testing purpose only */
145 .id = 0x50,
146 .ver = 0x2c,
147 .name = "15cg",
148 },
Michal Simek8111aff2016-02-01 15:05:58 +0100149 {
150 .id = 0x50,
151 .name = "15eg",
152 },
153 {
154 .id = 0x58,
155 .name = "19eg",
156 },
157 {
158 .id = 0x59,
159 .name = "17eg",
160 },
Michal Simekb510e532017-06-02 08:08:59 +0200161 {
162 .id = 0x61,
163 .name = "21dr",
164 },
165 {
166 .id = 0x63,
167 .name = "23dr",
168 },
169 {
170 .id = 0x65,
171 .name = "25dr",
172 },
173 {
174 .id = 0x64,
175 .name = "27dr",
176 },
177 {
178 .id = 0x60,
179 .name = "28dr",
180 },
181 {
182 .id = 0x62,
183 .name = "29dr",
184 },
Siva Durga Prasad Paladugu70866b42019-03-23 15:00:06 +0530185 {
186 .id = 0x66,
187 .name = "39dr",
188 },
Siva Durga Prasad Paladugu85f61a82019-07-23 11:56:17 +0530189 {
190 .id = 0x7b,
191 .name = "48dr",
192 },
193 {
194 .id = 0x7e,
195 .name = "49dr",
196 },
Michal Simek8111aff2016-02-01 15:05:58 +0100197};
Siva Durga Prasad Paladugu8d526532017-07-25 11:51:37 +0530198#endif
Michal Simek8111aff2016-02-01 15:05:58 +0100199
Siva Durga Prasad Paladugucd35d522017-07-25 11:51:38 +0530200int chip_id(unsigned char id)
Michal Simek8111aff2016-02-01 15:05:58 +0100201{
202 struct pt_regs regs;
Siva Durga Prasad Paladugu9f0a8e92017-07-25 11:51:36 +0530203 int val = -EINVAL;
Michal Simek8111aff2016-02-01 15:05:58 +0100204
Siva Durga Prasad Paladugu8d526532017-07-25 11:51:37 +0530205 if (current_el() != 3) {
206 regs.regs[0] = ZYNQMP_SIP_SVC_CSU_DMA_CHIPID;
207 regs.regs[1] = 0;
208 regs.regs[2] = 0;
209 regs.regs[3] = 0;
Michal Simek8111aff2016-02-01 15:05:58 +0100210
Siva Durga Prasad Paladugu8d526532017-07-25 11:51:37 +0530211 smc_call(&regs);
212
213 /*
214 * SMC returns:
215 * regs[0][31:0] = status of the operation
216 * regs[0][63:32] = CSU.IDCODE register
217 * regs[1][31:0] = CSU.version register
Michal Simek50d8cef2017-08-22 14:58:53 +0200218 * regs[1][63:32] = CSU.IDCODE2 register
Siva Durga Prasad Paladugu8d526532017-07-25 11:51:37 +0530219 */
220 switch (id) {
221 case IDCODE:
222 regs.regs[0] = upper_32_bits(regs.regs[0]);
223 regs.regs[0] &= ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK |
224 ZYNQMP_CSU_IDCODE_SVD_MASK;
225 regs.regs[0] >>= ZYNQMP_CSU_IDCODE_SVD_SHIFT;
226 val = regs.regs[0];
227 break;
228 case VERSION:
229 regs.regs[1] = lower_32_bits(regs.regs[1]);
230 regs.regs[1] &= ZYNQMP_CSU_SILICON_VER_MASK;
231 val = regs.regs[1];
232 break;
Michal Simek50d8cef2017-08-22 14:58:53 +0200233 case IDCODE2:
234 regs.regs[1] = lower_32_bits(regs.regs[1]);
235 regs.regs[1] >>= ZYNQMP_CSU_VERSION_EMPTY_SHIFT;
236 val = regs.regs[1];
237 break;
Siva Durga Prasad Paladugu8d526532017-07-25 11:51:37 +0530238 default:
239 printf("%s, Invalid Req:0x%x\n", __func__, id);
240 }
241 } else {
242 switch (id) {
243 case IDCODE:
244 val = readl(ZYNQMP_CSU_IDCODE_ADDR);
245 val &= ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK |
246 ZYNQMP_CSU_IDCODE_SVD_MASK;
247 val >>= ZYNQMP_CSU_IDCODE_SVD_SHIFT;
248 break;
249 case VERSION:
250 val = readl(ZYNQMP_CSU_VER_ADDR);
251 val &= ZYNQMP_CSU_SILICON_VER_MASK;
252 break;
253 default:
254 printf("%s, Invalid Req:0x%x\n", __func__, id);
255 }
Siva Durga Prasad Paladugu9f0a8e92017-07-25 11:51:36 +0530256 }
Soren Brinkmannd7696a52016-09-29 11:44:41 -0700257
Siva Durga Prasad Paladugu9f0a8e92017-07-25 11:51:36 +0530258 return val;
Michal Simek8111aff2016-02-01 15:05:58 +0100259}
260
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530261#define ZYNQMP_VERSION_SIZE 9
262#define ZYNQMP_PL_STATUS_BIT 9
Siva Durga Prasad Paladugu951c0192018-10-26 17:47:55 +0530263#define ZYNQMP_IPDIS_VCU_BIT 8
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530264#define ZYNQMP_PL_STATUS_MASK BIT(ZYNQMP_PL_STATUS_BIT)
265#define ZYNQMP_CSU_VERSION_MASK ~(ZYNQMP_PL_STATUS_MASK)
Siva Durga Prasad Paladugu951c0192018-10-26 17:47:55 +0530266#define ZYNQMP_CSU_VCUDIS_VER_MASK ZYNQMP_CSU_VERSION_MASK & \
267 ~BIT(ZYNQMP_IPDIS_VCU_BIT)
268#define MAX_VARIANTS_EV 3
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530269
Siva Durga Prasad Paladugu8d526532017-07-25 11:51:37 +0530270#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
271 !defined(CONFIG_SPL_BUILD)
Michal Simek8111aff2016-02-01 15:05:58 +0100272static char *zynqmp_get_silicon_idcode_name(void)
273{
Siva Durga Prasad Paladugu951c0192018-10-26 17:47:55 +0530274 u32 i, id, ver, j;
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530275 char *buf;
276 static char name[ZYNQMP_VERSION_SIZE];
Michal Simek8111aff2016-02-01 15:05:58 +0100277
Siva Durga Prasad Paladugu9f0a8e92017-07-25 11:51:36 +0530278 id = chip_id(IDCODE);
Michal Simek50d8cef2017-08-22 14:58:53 +0200279 ver = chip_id(IDCODE2);
280
Michal Simek8111aff2016-02-01 15:05:58 +0100281 for (i = 0; i < ARRAY_SIZE(zynqmp_devices); i++) {
Siva Durga Prasad Paladugu951c0192018-10-26 17:47:55 +0530282 if (zynqmp_devices[i].id == id) {
283 if (zynqmp_devices[i].evexists &&
284 !(ver & ZYNQMP_PL_STATUS_MASK))
285 break;
286 if (zynqmp_devices[i].ver == (ver &
287 ZYNQMP_CSU_VERSION_MASK))
288 break;
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530289 }
Michal Simek8111aff2016-02-01 15:05:58 +0100290 }
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530291
292 if (i >= ARRAY_SIZE(zynqmp_devices))
293 return "unknown";
294
Siva Durga Prasad Paladugu951c0192018-10-26 17:47:55 +0530295 strncat(name, "zu", 2);
296 if (!zynqmp_devices[i].evexists ||
297 (ver & ZYNQMP_PL_STATUS_MASK)) {
298 strncat(name, zynqmp_devices[i].name,
299 ZYNQMP_VERSION_SIZE - 3);
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530300 return name;
Siva Durga Prasad Paladugu951c0192018-10-26 17:47:55 +0530301 }
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530302
Siva Durga Prasad Paladugu951c0192018-10-26 17:47:55 +0530303 /*
304 * Here we are means, PL not powered up and ev variant
305 * exists. So, we need to ignore VCU disable bit(8) in
306 * version and findout if its CG or EG/EV variant.
307 */
308 for (j = 0; j < MAX_VARIANTS_EV; j++, i++) {
309 if ((zynqmp_devices[i].ver & ~BIT(ZYNQMP_IPDIS_VCU_BIT)) ==
310 (ver & ZYNQMP_CSU_VCUDIS_VER_MASK)) {
311 strncat(name, zynqmp_devices[i].name,
312 ZYNQMP_VERSION_SIZE - 3);
313 break;
314 }
315 }
316
317 if (j >= MAX_VARIANTS_EV)
318 return "unknown";
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530319
320 if (strstr(name, "eg") || strstr(name, "ev")) {
321 buf = strstr(name, "e");
322 *buf = '\0';
323 }
324
325 return name;
Michal Simek8111aff2016-02-01 15:05:58 +0100326}
327#endif
328
Michal Simek8b353302017-02-07 14:32:26 +0100329int board_early_init_f(void)
330{
Michal Simek1a1ab5a2018-01-15 12:52:59 +0100331#if defined(CONFIG_ZYNQMP_PSU_INIT_ENABLED)
Michal Simek09a7d7d2020-01-07 09:02:52 +0100332 int ret;
333
Michal Simekc8785f22018-01-10 11:48:48 +0100334 ret = psu_init();
Michal Simek09a7d7d2020-01-07 09:02:52 +0100335 if (ret)
336 return ret;
Michal Simek1f55e572020-03-20 08:59:02 +0100337
338 /* Delay is required for clocks to be propagated */
339 udelay(1000000);
Michal Simeke0f36102017-07-12 13:08:41 +0200340#endif
341
Michal Simek09a7d7d2020-01-07 09:02:52 +0100342#ifdef CONFIG_DEBUG_UART
343 /* Uart debug for sure */
344 debug_uart_init();
345 puts("Debug uart enabled\n"); /* or printch() */
346#endif
347
348 return 0;
Michal Simek8b353302017-02-07 14:32:26 +0100349}
350
Michal Simek46900462020-02-11 12:43:14 +0100351static int multi_boot(void)
352{
353 u32 multiboot;
354
355 multiboot = readl(&csu_base->multi_boot);
356
357 printf("Multiboot:\t%x\n", multiboot);
358
359 return 0;
360}
361
Michal Simek04b7e622015-01-15 10:01:51 +0100362int board_init(void)
363{
Michal Simek826d7eca2020-03-04 08:48:16 +0100364#if defined(CONFIG_ZYNQMP_FIRMWARE)
Ibai Erkiaga2d9b95b2019-09-27 11:37:04 +0100365 struct udevice *dev;
366
367 uclass_get_device_by_name(UCLASS_FIRMWARE, "zynqmp-power", &dev);
368 if (!dev)
369 panic("PMU Firmware device not found - Enable it");
Michal Simek826d7eca2020-03-04 08:48:16 +0100370#endif
Ibai Erkiaga2d9b95b2019-09-27 11:37:04 +0100371
Luca Ceresoli23e65002019-05-21 18:06:43 +0200372#if defined(CONFIG_SPL_BUILD)
373 /* Check *at build time* if the filename is an non-empty string */
374 if (sizeof(CONFIG_ZYNQMP_SPL_PM_CFG_OBJ_FILE) > 1)
375 zynqmp_pmufw_load_config_object(zynqmp_pm_cfg_obj,
376 zynqmp_pm_cfg_obj_size);
377#endif
378
Michal Simekfb7242d2015-06-22 14:31:06 +0200379 printf("EL Level:\tEL%d\n", current_el());
380
Michal Simek8111aff2016-02-01 15:05:58 +0100381#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
382 !defined(CONFIG_SPL_BUILD) || (defined(CONFIG_SPL_FPGA_SUPPORT) && \
383 defined(CONFIG_SPL_BUILD))
384 if (current_el() != 3) {
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530385 zynqmppl.name = zynqmp_get_silicon_idcode_name();
Michal Simek8111aff2016-02-01 15:05:58 +0100386 printf("Chip ID:\t%s\n", zynqmppl.name);
387 fpga_init();
388 fpga_add(fpga_xilinx, &zynqmppl);
389 }
Michal Simekbf0f9ca2018-04-19 15:43:38 +0200390#endif
391
Michal Simek46900462020-02-11 12:43:14 +0100392 if (current_el() == 3)
393 multi_boot();
394
Michal Simek04b7e622015-01-15 10:01:51 +0100395 return 0;
396}
397
398int board_early_init_r(void)
399{
400 u32 val;
401
Siva Durga Prasad Paladugu64d90002017-12-07 15:05:30 +0530402 if (current_el() != 3)
403 return 0;
404
Michal Simek245d5282017-07-12 10:32:18 +0200405 val = readl(&crlapb_base->timestamp_ref_ctrl);
406 val &= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
407
Siva Durga Prasad Paladugu64d90002017-12-07 15:05:30 +0530408 if (!val) {
Michal Simekc23d3f82015-11-05 08:34:35 +0100409 val = readl(&crlapb_base->timestamp_ref_ctrl);
410 val |= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
411 writel(val, &crlapb_base->timestamp_ref_ctrl);
Michal Simek04b7e622015-01-15 10:01:51 +0100412
Michal Simekc23d3f82015-11-05 08:34:35 +0100413 /* Program freq register in System counter */
414 writel(zynqmp_get_system_timer_freq(),
415 &iou_scntr_secure->base_frequency_id_register);
416 /* And enable system counter */
417 writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN,
418 &iou_scntr_secure->counter_control_register);
419 }
Michal Simek04b7e622015-01-15 10:01:51 +0100420 return 0;
421}
422
Nitin Jainb2eb59b2018-02-16 12:56:17 +0530423unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc,
Simon Glassed38aef2020-05-10 11:40:03 -0600424 char *const argv[])
Nitin Jainb2eb59b2018-02-16 12:56:17 +0530425{
426 int ret = 0;
427
428 if (current_el() > 1) {
429 smp_kick_all_cpus();
430 dcache_disable();
431 armv8_switch_to_el1(0x0, 0, 0, 0, (unsigned long)entry,
432 ES_TO_AARCH64);
433 } else {
434 printf("FAIL: current EL is not above EL1\n");
435 ret = EINVAL;
436 }
437 return ret;
438}
439
Michal Simek8faa66a2016-02-08 09:34:53 +0100440#if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE)
Simon Glass2f949c32017-03-31 08:40:32 -0600441int dram_init_banksize(void)
Michal Simek8faa66a2016-02-08 09:34:53 +0100442{
Nitin Jain9bcc76f2018-04-20 12:30:40 +0530443 int ret;
444
445 ret = fdtdec_setup_memory_banksize();
446 if (ret)
447 return ret;
448
449 mem_map_fill();
450
451 return 0;
Tom Riniedcfdbd2016-12-09 07:56:54 -0500452}
Michal Simek8faa66a2016-02-08 09:34:53 +0100453
Tom Riniedcfdbd2016-12-09 07:56:54 -0500454int dram_init(void)
455{
Siva Durga Prasad Paladugub3d55ea2018-07-16 15:56:11 +0530456 if (fdtdec_setup_mem_size_base() != 0)
Nathan Rossiac04bfa2016-12-19 00:03:34 +1000457 return -EINVAL;
Tom Riniedcfdbd2016-12-09 07:56:54 -0500458
459 return 0;
Michal Simek8faa66a2016-02-08 09:34:53 +0100460}
461#else
Nitin Jain9bcc76f2018-04-20 12:30:40 +0530462int dram_init_banksize(void)
463{
464#if defined(CONFIG_NR_DRAM_BANKS)
465 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
466 gd->bd->bi_dram[0].size = get_effective_memsize();
467#endif
468
469 mem_map_fill();
470
471 return 0;
472}
473
Michal Simek04b7e622015-01-15 10:01:51 +0100474int dram_init(void)
475{
Michal Simek1b846212018-04-11 16:12:28 +0200476 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
477 CONFIG_SYS_SDRAM_SIZE);
Michal Simek04b7e622015-01-15 10:01:51 +0100478
479 return 0;
480}
Michal Simek8faa66a2016-02-08 09:34:53 +0100481#endif
Michal Simek04b7e622015-01-15 10:01:51 +0100482
Michal Simek04b7e622015-01-15 10:01:51 +0100483void reset_cpu(ulong addr)
484{
485}
486
Michal Simek342edfe2018-12-20 09:33:38 +0100487#if defined(CONFIG_BOARD_LATE_INIT)
Michal Simek29b9b712018-05-17 14:06:06 +0200488static const struct {
489 u32 bit;
490 const char *name;
491} reset_reasons[] = {
492 { RESET_REASON_DEBUG_SYS, "DEBUG" },
493 { RESET_REASON_SOFT, "SOFT" },
494 { RESET_REASON_SRST, "SRST" },
495 { RESET_REASON_PSONLY, "PS-ONLY" },
496 { RESET_REASON_PMU, "PMU" },
497 { RESET_REASON_INTERNAL, "INTERNAL" },
498 { RESET_REASON_EXTERNAL, "EXTERNAL" },
499 {}
500};
501
T Karthik Reddy09b6def2019-03-13 20:24:18 +0530502static int reset_reason(void)
Michal Simek29b9b712018-05-17 14:06:06 +0200503{
T Karthik Reddy09b6def2019-03-13 20:24:18 +0530504 u32 reg;
505 int i, ret;
Michal Simek29b9b712018-05-17 14:06:06 +0200506 const char *reason = NULL;
507
T Karthik Reddy09b6def2019-03-13 20:24:18 +0530508 ret = zynqmp_mmio_read((ulong)&crlapb_base->reset_reason, &reg);
509 if (ret)
510 return -EINVAL;
Michal Simek29b9b712018-05-17 14:06:06 +0200511
512 puts("Reset reason:\t");
513
514 for (i = 0; i < ARRAY_SIZE(reset_reasons); i++) {
T Karthik Reddy09b6def2019-03-13 20:24:18 +0530515 if (reg & reset_reasons[i].bit) {
Michal Simek29b9b712018-05-17 14:06:06 +0200516 reason = reset_reasons[i].name;
517 printf("%s ", reset_reasons[i].name);
518 break;
519 }
520 }
521
522 puts("\n");
523
524 env_set("reset_reason", reason);
525
Michal Simek4c4efde2020-03-23 14:02:01 +0100526 ret = zynqmp_mmio_write((ulong)&crlapb_base->reset_reason, ~0, ~0);
T Karthik Reddy09b6def2019-03-13 20:24:18 +0530527 if (ret)
528 return -EINVAL;
Michal Simek29b9b712018-05-17 14:06:06 +0200529
530 return ret;
531}
532
Michal Simek1ca66d72019-02-14 13:14:30 +0100533static int set_fdtfile(void)
534{
535 char *compatible, *fdtfile;
536 const char *suffix = ".dtb";
537 const char *vendor = "xilinx/";
538
539 if (env_get("fdtfile"))
540 return 0;
541
542 compatible = (char *)fdt_getprop(gd->fdt_blob, 0, "compatible", NULL);
543 if (compatible) {
544 debug("Compatible: %s\n", compatible);
545
546 /* Discard vendor prefix */
547 strsep(&compatible, ",");
548
549 fdtfile = calloc(1, strlen(vendor) + strlen(compatible) +
550 strlen(suffix) + 1);
551 if (!fdtfile)
552 return -ENOMEM;
553
554 sprintf(fdtfile, "%s%s%s", vendor, compatible, suffix);
555
556 env_set("fdtfile", fdtfile);
557 free(fdtfile);
558 }
559
560 return 0;
561}
562
Michal Simek9c91e612020-04-08 11:04:41 +0200563static u8 zynqmp_get_bootmode(void)
Michal Simek04b7e622015-01-15 10:01:51 +0100564{
Michal Simek9c91e612020-04-08 11:04:41 +0200565 u8 bootmode;
Michal Simek04b7e622015-01-15 10:01:51 +0100566 u32 reg = 0;
Michal Simek9c91e612020-04-08 11:04:41 +0200567 int ret;
568
569 ret = zynqmp_mmio_read((ulong)&crlapb_base->boot_mode, &reg);
570 if (ret)
571 return -EINVAL;
572
573 if (reg >> BOOT_MODE_ALT_SHIFT)
574 reg >>= BOOT_MODE_ALT_SHIFT;
575
576 bootmode = reg & BOOT_MODES_MASK;
577
578 return bootmode;
579}
580
581int board_late_init(void)
582{
Michal Simek04b7e622015-01-15 10:01:51 +0100583 u8 bootmode;
Michal Simekf183a982018-04-25 11:20:43 +0200584 struct udevice *dev;
585 int bootseq = -1;
586 int bootseq_len = 0;
Michal Simek7410b142018-04-25 11:10:34 +0200587 int env_targets_len = 0;
Michal Simekecfb6dc2016-04-22 14:28:54 +0200588 const char *mode;
589 char *new_targets;
Siva Durga Prasad Paladugu245c5562017-12-20 16:35:06 +0530590 char *env_targets;
Siva Durga Prasad Paladugue6fd3bb2017-02-21 17:58:28 +0530591 int ret;
Michal Simekecfb6dc2016-04-22 14:28:54 +0200592
Michal Simek482f5492018-10-05 08:55:16 +0200593#if defined(CONFIG_USB_ETHER) && !defined(CONFIG_USB_GADGET_DOWNLOAD)
594 usb_ether_init();
595#endif
596
Michal Simekecfb6dc2016-04-22 14:28:54 +0200597 if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
598 debug("Saved variables - Skipping\n");
599 return 0;
600 }
Michal Simek04b7e622015-01-15 10:01:51 +0100601
Michal Simek1ca66d72019-02-14 13:14:30 +0100602 ret = set_fdtfile();
603 if (ret)
604 return ret;
605
Michal Simek9c91e612020-04-08 11:04:41 +0200606 bootmode = zynqmp_get_bootmode();
Michal Simek04b7e622015-01-15 10:01:51 +0100607
Michal Simekc5d95232015-09-20 17:20:42 +0200608 puts("Bootmode: ");
Michal Simek04b7e622015-01-15 10:01:51 +0100609 switch (bootmode) {
Michal Simek12398ea2016-08-19 14:14:52 +0200610 case USB_MODE:
611 puts("USB_MODE\n");
612 mode = "usb";
Michal Simek43380352017-12-01 15:18:24 +0100613 env_set("modeboot", "usb_dfu_spl");
Michal Simek12398ea2016-08-19 14:14:52 +0200614 break;
Siva Durga Prasad Paladugu30f0fc72015-03-13 11:10:26 +0530615 case JTAG_MODE:
Michal Simekc5d95232015-09-20 17:20:42 +0200616 puts("JTAG_MODE\n");
Siva Durga Prasad Paladugu9c441702019-06-25 17:41:09 +0530617 mode = "jtag pxe dhcp";
Michal Simek43380352017-12-01 15:18:24 +0100618 env_set("modeboot", "jtagboot");
Siva Durga Prasad Paladugu30f0fc72015-03-13 11:10:26 +0530619 break;
620 case QSPI_MODE_24BIT:
621 case QSPI_MODE_32BIT:
Michal Simekecfb6dc2016-04-22 14:28:54 +0200622 mode = "qspi0";
Michal Simekc5d95232015-09-20 17:20:42 +0200623 puts("QSPI_MODE\n");
Michal Simek43380352017-12-01 15:18:24 +0100624 env_set("modeboot", "qspiboot");
Siva Durga Prasad Paladugu30f0fc72015-03-13 11:10:26 +0530625 break;
Michal Simek02d66cd2015-04-15 15:02:28 +0200626 case EMMC_MODE:
Michal Simekdf7ff0a2015-10-05 15:59:38 +0200627 puts("EMMC_MODE\n");
T Karthik Reddy19735c32019-12-17 06:41:42 -0700628 if (uclass_get_device_by_name(UCLASS_MMC,
629 "mmc@ff160000", &dev) &&
630 uclass_get_device_by_name(UCLASS_MMC,
631 "sdhci@ff160000", &dev)) {
632 puts("Boot from EMMC but without SD0 enabled!\n");
633 return -1;
634 }
635 debug("mmc0 device found at %p, seq %d\n", dev, dev->seq);
636
637 mode = "mmc";
638 bootseq = dev->seq;
Michal Simekdf7ff0a2015-10-05 15:59:38 +0200639 break;
640 case SD_MODE:
Michal Simekc5d95232015-09-20 17:20:42 +0200641 puts("SD_MODE\n");
Michal Simekf183a982018-04-25 11:20:43 +0200642 if (uclass_get_device_by_name(UCLASS_MMC,
Siva Durga Prasad Paladugue91778d2019-01-03 15:44:24 +0530643 "mmc@ff160000", &dev) &&
644 uclass_get_device_by_name(UCLASS_MMC,
Michal Simekf183a982018-04-25 11:20:43 +0200645 "sdhci@ff160000", &dev)) {
646 puts("Boot from SD0 but without SD0 enabled!\n");
647 return -1;
648 }
649 debug("mmc0 device found at %p, seq %d\n", dev, dev->seq);
650
651 mode = "mmc";
652 bootseq = dev->seq;
Michal Simek43380352017-12-01 15:18:24 +0100653 env_set("modeboot", "sdboot");
Michal Simek04b7e622015-01-15 10:01:51 +0100654 break;
Siva Durga Prasad Paladugu29a77d22016-09-21 11:45:05 +0530655 case SD1_LSHFT_MODE:
656 puts("LVL_SHFT_");
657 /* fall through */
Michal Simek108e1842015-10-05 10:51:12 +0200658 case SD_MODE1:
Michal Simekc5d95232015-09-20 17:20:42 +0200659 puts("SD_MODE1\n");
Michal Simekf183a982018-04-25 11:20:43 +0200660 if (uclass_get_device_by_name(UCLASS_MMC,
Siva Durga Prasad Paladugue91778d2019-01-03 15:44:24 +0530661 "mmc@ff170000", &dev) &&
662 uclass_get_device_by_name(UCLASS_MMC,
Michal Simekf183a982018-04-25 11:20:43 +0200663 "sdhci@ff170000", &dev)) {
664 puts("Boot from SD1 but without SD1 enabled!\n");
665 return -1;
666 }
667 debug("mmc1 device found at %p, seq %d\n", dev, dev->seq);
668
669 mode = "mmc";
670 bootseq = dev->seq;
Michal Simek43380352017-12-01 15:18:24 +0100671 env_set("modeboot", "sdboot");
Michal Simek108e1842015-10-05 10:51:12 +0200672 break;
673 case NAND_MODE:
Michal Simekc5d95232015-09-20 17:20:42 +0200674 puts("NAND_MODE\n");
Michal Simekecfb6dc2016-04-22 14:28:54 +0200675 mode = "nand0";
Michal Simek43380352017-12-01 15:18:24 +0100676 env_set("modeboot", "nandboot");
Michal Simek108e1842015-10-05 10:51:12 +0200677 break;
Michal Simek04b7e622015-01-15 10:01:51 +0100678 default:
Michal Simekecfb6dc2016-04-22 14:28:54 +0200679 mode = "";
Michal Simek04b7e622015-01-15 10:01:51 +0100680 printf("Invalid Boot Mode:0x%x\n", bootmode);
681 break;
682 }
683
Michal Simekf183a982018-04-25 11:20:43 +0200684 if (bootseq >= 0) {
685 bootseq_len = snprintf(NULL, 0, "%i", bootseq);
686 debug("Bootseq len: %x\n", bootseq_len);
687 }
688
Michal Simekecfb6dc2016-04-22 14:28:54 +0200689 /*
690 * One terminating char + one byte for space between mode
691 * and default boot_targets
692 */
Siva Durga Prasad Paladugu245c5562017-12-20 16:35:06 +0530693 env_targets = env_get("boot_targets");
Michal Simek7410b142018-04-25 11:10:34 +0200694 if (env_targets)
695 env_targets_len = strlen(env_targets);
696
Michal Simekf183a982018-04-25 11:20:43 +0200697 new_targets = calloc(1, strlen(mode) + env_targets_len + 2 +
698 bootseq_len);
Michal Simek089b84d2018-06-13 09:42:41 +0200699 if (!new_targets)
700 return -ENOMEM;
Michal Simek7410b142018-04-25 11:10:34 +0200701
Michal Simekf183a982018-04-25 11:20:43 +0200702 if (bootseq >= 0)
703 sprintf(new_targets, "%s%x %s", mode, bootseq,
704 env_targets ? env_targets : "");
705 else
706 sprintf(new_targets, "%s %s", mode,
707 env_targets ? env_targets : "");
Michal Simekecfb6dc2016-04-22 14:28:54 +0200708
Simon Glass6a38e412017-08-03 12:22:09 -0600709 env_set("boot_targets", new_targets);
Michal Simekecfb6dc2016-04-22 14:28:54 +0200710
Michal Simek29b9b712018-05-17 14:06:06 +0200711 reset_reason();
712
Michal Simek705d44a2020-03-31 12:39:37 +0200713 return board_late_init_xilinx();
Michal Simek04b7e622015-01-15 10:01:51 +0100714}
Michal Simek342edfe2018-12-20 09:33:38 +0100715#endif
Siva Durga Prasad Paladugu650e0a32015-08-04 13:01:05 +0530716
717int checkboard(void)
718{
Michal Simek47ce9362016-01-25 11:04:21 +0100719 puts("Board: Xilinx ZynqMP\n");
Siva Durga Prasad Paladugu650e0a32015-08-04 13:01:05 +0530720 return 0;
721}