blob: 06cdcbdba6b9fa029d28306a19961ff12bda9741 [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>
Michal Simekd54b1af2015-09-30 17:26:55 +02008#include <sata.h>
Michal Simekb216cc12015-07-23 13:27:40 +02009#include <ahci.h>
10#include <scsi.h>
Michal Simekecfb6dc2016-04-22 14:28:54 +020011#include <malloc.h>
Michal Simekbf0f9ca2018-04-19 15:43:38 +020012#include <wdt.h>
Michal Simekc23d3f82015-11-05 08:34:35 +010013#include <asm/arch/clk.h>
Michal Simek04b7e622015-01-15 10:01:51 +010014#include <asm/arch/hardware.h>
15#include <asm/arch/sys_proto.h>
Michal Simekf2f08642018-01-10 09:36:09 +010016#include <asm/arch/psu_init_gpl.h>
Michal Simek04b7e622015-01-15 10:01:51 +010017#include <asm/io.h>
Michal Simekf183a982018-04-25 11:20:43 +020018#include <dm/device.h>
Michal Simekbf0f9ca2018-04-19 15:43:38 +020019#include <dm/uclass.h>
Siva Durga Prasad Paladuguba1f68e2015-08-04 13:03:26 +053020#include <usb.h>
21#include <dwc3-uboot.h>
Michal Simek8111aff2016-02-01 15:05:58 +010022#include <zynqmppl.h>
Michal Simekeec32f62016-04-22 11:48:49 +020023#include <i2c.h>
Michal Simek76d0a772016-09-01 11:16:40 +020024#include <g_dnl.h>
Michal Simek04b7e622015-01-15 10:01:51 +010025
26DECLARE_GLOBAL_DATA_PTR;
27
Michal Simekbf0f9ca2018-04-19 15:43:38 +020028#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_WDT)
29static struct udevice *watchdog_dev;
30#endif
31
Michal Simek8111aff2016-02-01 15:05:58 +010032#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
33 !defined(CONFIG_SPL_BUILD)
34static xilinx_desc zynqmppl = XILINX_ZYNQMP_DESC;
35
36static const struct {
Michal Simek6908b862017-11-06 12:55:59 +010037 u32 id;
Michal Simek50d8cef2017-08-22 14:58:53 +020038 u32 ver;
Michal Simek8111aff2016-02-01 15:05:58 +010039 char *name;
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +053040 bool evexists;
Michal Simek8111aff2016-02-01 15:05:58 +010041} zynqmp_devices[] = {
42 {
43 .id = 0x10,
44 .name = "3eg",
45 },
46 {
Michal Simek50d8cef2017-08-22 14:58:53 +020047 .id = 0x10,
48 .ver = 0x2c,
49 .name = "3cg",
50 },
51 {
Michal Simek8111aff2016-02-01 15:05:58 +010052 .id = 0x11,
53 .name = "2eg",
54 },
55 {
Michal Simek50d8cef2017-08-22 14:58:53 +020056 .id = 0x11,
57 .ver = 0x2c,
58 .name = "2cg",
59 },
60 {
Michal Simek8111aff2016-02-01 15:05:58 +010061 .id = 0x20,
62 .name = "5ev",
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +053063 .evexists = 1,
Michal Simek8111aff2016-02-01 15:05:58 +010064 },
65 {
Michal Simek50d8cef2017-08-22 14:58:53 +020066 .id = 0x20,
67 .ver = 0x100,
68 .name = "5eg",
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +053069 .evexists = 1,
Michal Simek50d8cef2017-08-22 14:58:53 +020070 },
71 {
72 .id = 0x20,
73 .ver = 0x12c,
74 .name = "5cg",
75 },
76 {
Michal Simek8111aff2016-02-01 15:05:58 +010077 .id = 0x21,
78 .name = "4ev",
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +053079 .evexists = 1,
Michal Simek8111aff2016-02-01 15:05:58 +010080 },
81 {
Michal Simek50d8cef2017-08-22 14:58:53 +020082 .id = 0x21,
83 .ver = 0x100,
84 .name = "4eg",
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +053085 .evexists = 1,
Michal Simek50d8cef2017-08-22 14:58:53 +020086 },
87 {
88 .id = 0x21,
89 .ver = 0x12c,
90 .name = "4cg",
91 },
92 {
Michal Simek8111aff2016-02-01 15:05:58 +010093 .id = 0x30,
94 .name = "7ev",
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +053095 .evexists = 1,
Michal Simek8111aff2016-02-01 15:05:58 +010096 },
97 {
Michal Simek50d8cef2017-08-22 14:58:53 +020098 .id = 0x30,
99 .ver = 0x100,
100 .name = "7eg",
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530101 .evexists = 1,
Michal Simek50d8cef2017-08-22 14:58:53 +0200102 },
103 {
104 .id = 0x30,
105 .ver = 0x12c,
106 .name = "7cg",
107 },
108 {
Michal Simek8111aff2016-02-01 15:05:58 +0100109 .id = 0x38,
110 .name = "9eg",
111 },
112 {
Michal Simek50d8cef2017-08-22 14:58:53 +0200113 .id = 0x38,
114 .ver = 0x2c,
115 .name = "9cg",
116 },
117 {
Michal Simek8111aff2016-02-01 15:05:58 +0100118 .id = 0x39,
119 .name = "6eg",
120 },
121 {
Michal Simek50d8cef2017-08-22 14:58:53 +0200122 .id = 0x39,
123 .ver = 0x2c,
124 .name = "6cg",
125 },
126 {
Michal Simek8111aff2016-02-01 15:05:58 +0100127 .id = 0x40,
128 .name = "11eg",
129 },
Michal Simek50d8cef2017-08-22 14:58:53 +0200130 { /* For testing purpose only */
131 .id = 0x50,
132 .ver = 0x2c,
133 .name = "15cg",
134 },
Michal Simek8111aff2016-02-01 15:05:58 +0100135 {
136 .id = 0x50,
137 .name = "15eg",
138 },
139 {
140 .id = 0x58,
141 .name = "19eg",
142 },
143 {
144 .id = 0x59,
145 .name = "17eg",
146 },
Michal Simekb510e532017-06-02 08:08:59 +0200147 {
148 .id = 0x61,
149 .name = "21dr",
150 },
151 {
152 .id = 0x63,
153 .name = "23dr",
154 },
155 {
156 .id = 0x65,
157 .name = "25dr",
158 },
159 {
160 .id = 0x64,
161 .name = "27dr",
162 },
163 {
164 .id = 0x60,
165 .name = "28dr",
166 },
167 {
168 .id = 0x62,
169 .name = "29dr",
170 },
Michal Simek8111aff2016-02-01 15:05:58 +0100171};
Siva Durga Prasad Paladugu8d526532017-07-25 11:51:37 +0530172#endif
Michal Simek8111aff2016-02-01 15:05:58 +0100173
Siva Durga Prasad Paladugucd35d522017-07-25 11:51:38 +0530174int chip_id(unsigned char id)
Michal Simek8111aff2016-02-01 15:05:58 +0100175{
176 struct pt_regs regs;
Siva Durga Prasad Paladugu9f0a8e92017-07-25 11:51:36 +0530177 int val = -EINVAL;
Michal Simek8111aff2016-02-01 15:05:58 +0100178
Siva Durga Prasad Paladugu8d526532017-07-25 11:51:37 +0530179 if (current_el() != 3) {
180 regs.regs[0] = ZYNQMP_SIP_SVC_CSU_DMA_CHIPID;
181 regs.regs[1] = 0;
182 regs.regs[2] = 0;
183 regs.regs[3] = 0;
Michal Simek8111aff2016-02-01 15:05:58 +0100184
Siva Durga Prasad Paladugu8d526532017-07-25 11:51:37 +0530185 smc_call(&regs);
186
187 /*
188 * SMC returns:
189 * regs[0][31:0] = status of the operation
190 * regs[0][63:32] = CSU.IDCODE register
191 * regs[1][31:0] = CSU.version register
Michal Simek50d8cef2017-08-22 14:58:53 +0200192 * regs[1][63:32] = CSU.IDCODE2 register
Siva Durga Prasad Paladugu8d526532017-07-25 11:51:37 +0530193 */
194 switch (id) {
195 case IDCODE:
196 regs.regs[0] = upper_32_bits(regs.regs[0]);
197 regs.regs[0] &= ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK |
198 ZYNQMP_CSU_IDCODE_SVD_MASK;
199 regs.regs[0] >>= ZYNQMP_CSU_IDCODE_SVD_SHIFT;
200 val = regs.regs[0];
201 break;
202 case VERSION:
203 regs.regs[1] = lower_32_bits(regs.regs[1]);
204 regs.regs[1] &= ZYNQMP_CSU_SILICON_VER_MASK;
205 val = regs.regs[1];
206 break;
Michal Simek50d8cef2017-08-22 14:58:53 +0200207 case IDCODE2:
208 regs.regs[1] = lower_32_bits(regs.regs[1]);
209 regs.regs[1] >>= ZYNQMP_CSU_VERSION_EMPTY_SHIFT;
210 val = regs.regs[1];
211 break;
Siva Durga Prasad Paladugu8d526532017-07-25 11:51:37 +0530212 default:
213 printf("%s, Invalid Req:0x%x\n", __func__, id);
214 }
215 } else {
216 switch (id) {
217 case IDCODE:
218 val = readl(ZYNQMP_CSU_IDCODE_ADDR);
219 val &= ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK |
220 ZYNQMP_CSU_IDCODE_SVD_MASK;
221 val >>= ZYNQMP_CSU_IDCODE_SVD_SHIFT;
222 break;
223 case VERSION:
224 val = readl(ZYNQMP_CSU_VER_ADDR);
225 val &= ZYNQMP_CSU_SILICON_VER_MASK;
226 break;
227 default:
228 printf("%s, Invalid Req:0x%x\n", __func__, id);
229 }
Siva Durga Prasad Paladugu9f0a8e92017-07-25 11:51:36 +0530230 }
Soren Brinkmannd7696a52016-09-29 11:44:41 -0700231
Siva Durga Prasad Paladugu9f0a8e92017-07-25 11:51:36 +0530232 return val;
Michal Simek8111aff2016-02-01 15:05:58 +0100233}
234
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530235#define ZYNQMP_VERSION_SIZE 9
236#define ZYNQMP_PL_STATUS_BIT 9
237#define ZYNQMP_PL_STATUS_MASK BIT(ZYNQMP_PL_STATUS_BIT)
238#define ZYNQMP_CSU_VERSION_MASK ~(ZYNQMP_PL_STATUS_MASK)
239
Siva Durga Prasad Paladugu8d526532017-07-25 11:51:37 +0530240#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
241 !defined(CONFIG_SPL_BUILD)
Michal Simek8111aff2016-02-01 15:05:58 +0100242static char *zynqmp_get_silicon_idcode_name(void)
243{
Michal Simek50d8cef2017-08-22 14:58:53 +0200244 u32 i, id, ver;
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530245 char *buf;
246 static char name[ZYNQMP_VERSION_SIZE];
Michal Simek8111aff2016-02-01 15:05:58 +0100247
Siva Durga Prasad Paladugu9f0a8e92017-07-25 11:51:36 +0530248 id = chip_id(IDCODE);
Michal Simek50d8cef2017-08-22 14:58:53 +0200249 ver = chip_id(IDCODE2);
250
Michal Simek8111aff2016-02-01 15:05:58 +0100251 for (i = 0; i < ARRAY_SIZE(zynqmp_devices); i++) {
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530252 if ((zynqmp_devices[i].id == id) &&
253 (zynqmp_devices[i].ver == (ver &
254 ZYNQMP_CSU_VERSION_MASK))) {
255 strncat(name, "zu", 2);
256 strncat(name, zynqmp_devices[i].name,
257 ZYNQMP_VERSION_SIZE - 3);
258 break;
259 }
Michal Simek8111aff2016-02-01 15:05:58 +0100260 }
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530261
262 if (i >= ARRAY_SIZE(zynqmp_devices))
263 return "unknown";
264
265 if (!zynqmp_devices[i].evexists)
266 return name;
267
268 if (ver & ZYNQMP_PL_STATUS_MASK)
269 return name;
270
271 if (strstr(name, "eg") || strstr(name, "ev")) {
272 buf = strstr(name, "e");
273 *buf = '\0';
274 }
275
276 return name;
Michal Simek8111aff2016-02-01 15:05:58 +0100277}
278#endif
279
Michal Simek8b353302017-02-07 14:32:26 +0100280int board_early_init_f(void)
281{
Michal Simekc8785f22018-01-10 11:48:48 +0100282 int ret = 0;
Michal Simek8b353302017-02-07 14:32:26 +0100283#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_CLK_ZYNQMP)
284 zynqmp_pmufw_version();
285#endif
Michal Simeke0f36102017-07-12 13:08:41 +0200286
Michal Simek1a1ab5a2018-01-15 12:52:59 +0100287#if defined(CONFIG_ZYNQMP_PSU_INIT_ENABLED)
Michal Simekc8785f22018-01-10 11:48:48 +0100288 ret = psu_init();
Michal Simeke0f36102017-07-12 13:08:41 +0200289#endif
290
Michal Simekbf0f9ca2018-04-19 15:43:38 +0200291#if defined(CONFIG_WDT) && !defined(CONFIG_SPL_BUILD)
292 /* bss is not cleared at time when watchdog_reset() is called */
293 watchdog_dev = NULL;
294#endif
295
Michal Simekc8785f22018-01-10 11:48:48 +0100296 return ret;
Michal Simek8b353302017-02-07 14:32:26 +0100297}
298
Michal Simek04b7e622015-01-15 10:01:51 +0100299int board_init(void)
300{
Michal Simekfb7242d2015-06-22 14:31:06 +0200301 printf("EL Level:\tEL%d\n", current_el());
302
Michal Simek8111aff2016-02-01 15:05:58 +0100303#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
304 !defined(CONFIG_SPL_BUILD) || (defined(CONFIG_SPL_FPGA_SUPPORT) && \
305 defined(CONFIG_SPL_BUILD))
306 if (current_el() != 3) {
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530307 zynqmppl.name = zynqmp_get_silicon_idcode_name();
Michal Simek8111aff2016-02-01 15:05:58 +0100308 printf("Chip ID:\t%s\n", zynqmppl.name);
309 fpga_init();
310 fpga_add(fpga_xilinx, &zynqmppl);
311 }
312#endif
313
Michal Simekbf0f9ca2018-04-19 15:43:38 +0200314#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_WDT)
Michal Simek169d34b2018-07-11 08:30:07 +0200315 if (uclass_get_device_by_seq(UCLASS_WDT, 0, &watchdog_dev)) {
316 debug("Watchdog: Not found by seq!\n");
317 if (uclass_get_device(UCLASS_WDT, 0, &watchdog_dev)) {
318 puts("Watchdog: Not found!\n");
319 return 0;
320 }
Michal Simekbf0f9ca2018-04-19 15:43:38 +0200321 }
Michal Simek169d34b2018-07-11 08:30:07 +0200322
323 wdt_start(watchdog_dev, 0, 0);
324 puts("Watchdog: Started\n");
Michal Simekbf0f9ca2018-04-19 15:43:38 +0200325#endif
326
Michal Simek04b7e622015-01-15 10:01:51 +0100327 return 0;
328}
329
Michal Simekbf0f9ca2018-04-19 15:43:38 +0200330#ifdef CONFIG_WATCHDOG
331/* Called by macro WATCHDOG_RESET */
332void watchdog_reset(void)
333{
334# if !defined(CONFIG_SPL_BUILD)
335 static ulong next_reset;
336 ulong now;
337
338 if (!watchdog_dev)
339 return;
340
341 now = timer_get_us();
342
343 /* Do not reset the watchdog too often */
344 if (now > next_reset) {
345 wdt_reset(watchdog_dev);
346 next_reset = now + 1000;
347 }
348# endif
349}
350#endif
351
Michal Simek04b7e622015-01-15 10:01:51 +0100352int board_early_init_r(void)
353{
354 u32 val;
355
Siva Durga Prasad Paladugu64d90002017-12-07 15:05:30 +0530356 if (current_el() != 3)
357 return 0;
358
Michal Simek245d5282017-07-12 10:32:18 +0200359 val = readl(&crlapb_base->timestamp_ref_ctrl);
360 val &= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
361
Siva Durga Prasad Paladugu64d90002017-12-07 15:05:30 +0530362 if (!val) {
Michal Simekc23d3f82015-11-05 08:34:35 +0100363 val = readl(&crlapb_base->timestamp_ref_ctrl);
364 val |= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
365 writel(val, &crlapb_base->timestamp_ref_ctrl);
Michal Simek04b7e622015-01-15 10:01:51 +0100366
Michal Simekc23d3f82015-11-05 08:34:35 +0100367 /* Program freq register in System counter */
368 writel(zynqmp_get_system_timer_freq(),
369 &iou_scntr_secure->base_frequency_id_register);
370 /* And enable system counter */
371 writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN,
372 &iou_scntr_secure->counter_control_register);
373 }
Michal Simek04b7e622015-01-15 10:01:51 +0100374 return 0;
375}
376
Michal Simekeec32f62016-04-22 11:48:49 +0200377int zynq_board_read_rom_ethaddr(unsigned char *ethaddr)
378{
379#if defined(CONFIG_ZYNQ_GEM_EEPROM_ADDR) && \
380 defined(CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET) && \
381 defined(CONFIG_ZYNQ_EEPROM_BUS)
382 i2c_set_bus_num(CONFIG_ZYNQ_EEPROM_BUS);
383
384 if (eeprom_read(CONFIG_ZYNQ_GEM_EEPROM_ADDR,
385 CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET,
386 ethaddr, 6))
387 printf("I2C EEPROM MAC address read failed\n");
388#endif
389
390 return 0;
391}
392
Nitin Jainb2eb59b2018-02-16 12:56:17 +0530393unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc,
394 char * const argv[])
395{
396 int ret = 0;
397
398 if (current_el() > 1) {
399 smp_kick_all_cpus();
400 dcache_disable();
401 armv8_switch_to_el1(0x0, 0, 0, 0, (unsigned long)entry,
402 ES_TO_AARCH64);
403 } else {
404 printf("FAIL: current EL is not above EL1\n");
405 ret = EINVAL;
406 }
407 return ret;
408}
409
Michal Simek8faa66a2016-02-08 09:34:53 +0100410#if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE)
Simon Glass2f949c32017-03-31 08:40:32 -0600411int dram_init_banksize(void)
Michal Simek8faa66a2016-02-08 09:34:53 +0100412{
Nitin Jain9bcc76f2018-04-20 12:30:40 +0530413 int ret;
414
415 ret = fdtdec_setup_memory_banksize();
416 if (ret)
417 return ret;
418
419 mem_map_fill();
420
421 return 0;
Tom Riniedcfdbd2016-12-09 07:56:54 -0500422}
Michal Simek8faa66a2016-02-08 09:34:53 +0100423
Tom Riniedcfdbd2016-12-09 07:56:54 -0500424int dram_init(void)
425{
Nathan Rossiac04bfa2016-12-19 00:03:34 +1000426 if (fdtdec_setup_memory_size() != 0)
427 return -EINVAL;
Tom Riniedcfdbd2016-12-09 07:56:54 -0500428
429 return 0;
Michal Simek8faa66a2016-02-08 09:34:53 +0100430}
431#else
Nitin Jain9bcc76f2018-04-20 12:30:40 +0530432int dram_init_banksize(void)
433{
434#if defined(CONFIG_NR_DRAM_BANKS)
435 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
436 gd->bd->bi_dram[0].size = get_effective_memsize();
437#endif
438
439 mem_map_fill();
440
441 return 0;
442}
443
Michal Simek04b7e622015-01-15 10:01:51 +0100444int dram_init(void)
445{
Michal Simek1b846212018-04-11 16:12:28 +0200446 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
447 CONFIG_SYS_SDRAM_SIZE);
Michal Simek04b7e622015-01-15 10:01:51 +0100448
449 return 0;
450}
Michal Simek8faa66a2016-02-08 09:34:53 +0100451#endif
Michal Simek04b7e622015-01-15 10:01:51 +0100452
Michal Simek04b7e622015-01-15 10:01:51 +0100453void reset_cpu(ulong addr)
454{
455}
456
Michal Simek29b9b712018-05-17 14:06:06 +0200457static const struct {
458 u32 bit;
459 const char *name;
460} reset_reasons[] = {
461 { RESET_REASON_DEBUG_SYS, "DEBUG" },
462 { RESET_REASON_SOFT, "SOFT" },
463 { RESET_REASON_SRST, "SRST" },
464 { RESET_REASON_PSONLY, "PS-ONLY" },
465 { RESET_REASON_PMU, "PMU" },
466 { RESET_REASON_INTERNAL, "INTERNAL" },
467 { RESET_REASON_EXTERNAL, "EXTERNAL" },
468 {}
469};
470
471static u32 reset_reason(void)
472{
473 u32 ret;
474 int i;
475 const char *reason = NULL;
476
477 ret = readl(&crlapb_base->reset_reason);
478
479 puts("Reset reason:\t");
480
481 for (i = 0; i < ARRAY_SIZE(reset_reasons); i++) {
482 if (ret & reset_reasons[i].bit) {
483 reason = reset_reasons[i].name;
484 printf("%s ", reset_reasons[i].name);
485 break;
486 }
487 }
488
489 puts("\n");
490
491 env_set("reset_reason", reason);
492
493 writel(~0, &crlapb_base->reset_reason);
494
495 return ret;
496}
497
Michal Simek04b7e622015-01-15 10:01:51 +0100498int board_late_init(void)
499{
500 u32 reg = 0;
501 u8 bootmode;
Michal Simekf183a982018-04-25 11:20:43 +0200502 struct udevice *dev;
503 int bootseq = -1;
504 int bootseq_len = 0;
Michal Simek7410b142018-04-25 11:10:34 +0200505 int env_targets_len = 0;
Michal Simekecfb6dc2016-04-22 14:28:54 +0200506 const char *mode;
507 char *new_targets;
Siva Durga Prasad Paladugu245c5562017-12-20 16:35:06 +0530508 char *env_targets;
Siva Durga Prasad Paladugue6fd3bb2017-02-21 17:58:28 +0530509 int ret;
Michal Simekecfb6dc2016-04-22 14:28:54 +0200510
511 if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
512 debug("Saved variables - Skipping\n");
513 return 0;
514 }
Michal Simek04b7e622015-01-15 10:01:51 +0100515
Siva Durga Prasad Paladugue6fd3bb2017-02-21 17:58:28 +0530516 ret = zynqmp_mmio_read((ulong)&crlapb_base->boot_mode, &reg);
517 if (ret)
518 return -EINVAL;
519
Michal Simek833e0c42016-10-25 11:43:02 +0200520 if (reg >> BOOT_MODE_ALT_SHIFT)
521 reg >>= BOOT_MODE_ALT_SHIFT;
522
Michal Simek04b7e622015-01-15 10:01:51 +0100523 bootmode = reg & BOOT_MODES_MASK;
524
Michal Simekc5d95232015-09-20 17:20:42 +0200525 puts("Bootmode: ");
Michal Simek04b7e622015-01-15 10:01:51 +0100526 switch (bootmode) {
Michal Simek12398ea2016-08-19 14:14:52 +0200527 case USB_MODE:
528 puts("USB_MODE\n");
529 mode = "usb";
Michal Simek43380352017-12-01 15:18:24 +0100530 env_set("modeboot", "usb_dfu_spl");
Michal Simek12398ea2016-08-19 14:14:52 +0200531 break;
Siva Durga Prasad Paladugu30f0fc72015-03-13 11:10:26 +0530532 case JTAG_MODE:
Michal Simekc5d95232015-09-20 17:20:42 +0200533 puts("JTAG_MODE\n");
Michal Simekecfb6dc2016-04-22 14:28:54 +0200534 mode = "pxe dhcp";
Michal Simek43380352017-12-01 15:18:24 +0100535 env_set("modeboot", "jtagboot");
Siva Durga Prasad Paladugu30f0fc72015-03-13 11:10:26 +0530536 break;
537 case QSPI_MODE_24BIT:
538 case QSPI_MODE_32BIT:
Michal Simekecfb6dc2016-04-22 14:28:54 +0200539 mode = "qspi0";
Michal Simekc5d95232015-09-20 17:20:42 +0200540 puts("QSPI_MODE\n");
Michal Simek43380352017-12-01 15:18:24 +0100541 env_set("modeboot", "qspiboot");
Siva Durga Prasad Paladugu30f0fc72015-03-13 11:10:26 +0530542 break;
Michal Simek02d66cd2015-04-15 15:02:28 +0200543 case EMMC_MODE:
Michal Simekdf7ff0a2015-10-05 15:59:38 +0200544 puts("EMMC_MODE\n");
Michal Simekecfb6dc2016-04-22 14:28:54 +0200545 mode = "mmc0";
Michal Simek43380352017-12-01 15:18:24 +0100546 env_set("modeboot", "emmcboot");
Michal Simekdf7ff0a2015-10-05 15:59:38 +0200547 break;
548 case SD_MODE:
Michal Simekc5d95232015-09-20 17:20:42 +0200549 puts("SD_MODE\n");
Michal Simekf183a982018-04-25 11:20:43 +0200550 if (uclass_get_device_by_name(UCLASS_MMC,
551 "sdhci@ff160000", &dev)) {
552 puts("Boot from SD0 but without SD0 enabled!\n");
553 return -1;
554 }
555 debug("mmc0 device found at %p, seq %d\n", dev, dev->seq);
556
557 mode = "mmc";
558 bootseq = dev->seq;
Michal Simek43380352017-12-01 15:18:24 +0100559 env_set("modeboot", "sdboot");
Michal Simek04b7e622015-01-15 10:01:51 +0100560 break;
Siva Durga Prasad Paladugu29a77d22016-09-21 11:45:05 +0530561 case SD1_LSHFT_MODE:
562 puts("LVL_SHFT_");
563 /* fall through */
Michal Simek108e1842015-10-05 10:51:12 +0200564 case SD_MODE1:
Michal Simekc5d95232015-09-20 17:20:42 +0200565 puts("SD_MODE1\n");
Michal Simekf183a982018-04-25 11:20:43 +0200566 if (uclass_get_device_by_name(UCLASS_MMC,
567 "sdhci@ff170000", &dev)) {
568 puts("Boot from SD1 but without SD1 enabled!\n");
569 return -1;
570 }
571 debug("mmc1 device found at %p, seq %d\n", dev, dev->seq);
572
573 mode = "mmc";
574 bootseq = dev->seq;
Michal Simek43380352017-12-01 15:18:24 +0100575 env_set("modeboot", "sdboot");
Michal Simek108e1842015-10-05 10:51:12 +0200576 break;
577 case NAND_MODE:
Michal Simekc5d95232015-09-20 17:20:42 +0200578 puts("NAND_MODE\n");
Michal Simekecfb6dc2016-04-22 14:28:54 +0200579 mode = "nand0";
Michal Simek43380352017-12-01 15:18:24 +0100580 env_set("modeboot", "nandboot");
Michal Simek108e1842015-10-05 10:51:12 +0200581 break;
Michal Simek04b7e622015-01-15 10:01:51 +0100582 default:
Michal Simekecfb6dc2016-04-22 14:28:54 +0200583 mode = "";
Michal Simek04b7e622015-01-15 10:01:51 +0100584 printf("Invalid Boot Mode:0x%x\n", bootmode);
585 break;
586 }
587
Michal Simekf183a982018-04-25 11:20:43 +0200588 if (bootseq >= 0) {
589 bootseq_len = snprintf(NULL, 0, "%i", bootseq);
590 debug("Bootseq len: %x\n", bootseq_len);
591 }
592
Michal Simekecfb6dc2016-04-22 14:28:54 +0200593 /*
594 * One terminating char + one byte for space between mode
595 * and default boot_targets
596 */
Siva Durga Prasad Paladugu245c5562017-12-20 16:35:06 +0530597 env_targets = env_get("boot_targets");
Michal Simek7410b142018-04-25 11:10:34 +0200598 if (env_targets)
599 env_targets_len = strlen(env_targets);
600
Michal Simekf183a982018-04-25 11:20:43 +0200601 new_targets = calloc(1, strlen(mode) + env_targets_len + 2 +
602 bootseq_len);
Michal Simek089b84d2018-06-13 09:42:41 +0200603 if (!new_targets)
604 return -ENOMEM;
Michal Simek7410b142018-04-25 11:10:34 +0200605
Michal Simekf183a982018-04-25 11:20:43 +0200606 if (bootseq >= 0)
607 sprintf(new_targets, "%s%x %s", mode, bootseq,
608 env_targets ? env_targets : "");
609 else
610 sprintf(new_targets, "%s %s", mode,
611 env_targets ? env_targets : "");
Michal Simekecfb6dc2016-04-22 14:28:54 +0200612
Simon Glass6a38e412017-08-03 12:22:09 -0600613 env_set("boot_targets", new_targets);
Michal Simekecfb6dc2016-04-22 14:28:54 +0200614
Michal Simek29b9b712018-05-17 14:06:06 +0200615 reset_reason();
616
Michal Simek04b7e622015-01-15 10:01:51 +0100617 return 0;
618}
Siva Durga Prasad Paladugu650e0a32015-08-04 13:01:05 +0530619
620int checkboard(void)
621{
Michal Simek47ce9362016-01-25 11:04:21 +0100622 puts("Board: Xilinx ZynqMP\n");
Siva Durga Prasad Paladugu650e0a32015-08-04 13:01:05 +0530623 return 0;
624}