]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
84c7204b MS |
2 | /* |
3 | * (C) Copyright 2014 - 2015 Xilinx, Inc. | |
4 | * Michal Simek <[email protected]> | |
84c7204b MS |
5 | */ |
6 | ||
7 | #include <common.h> | |
62270f43 | 8 | #include <cpu_func.h> |
c0adba57 | 9 | #include <debug_uart.h> |
9fb625ce | 10 | #include <env.h> |
5255932f | 11 | #include <init.h> |
679b994a | 12 | #include <sata.h> |
6fe6f135 MS |
13 | #include <ahci.h> |
14 | #include <scsi.h> | |
b72894f1 | 15 | #include <malloc.h> |
4490e013 | 16 | #include <wdt.h> |
0785dfd8 | 17 | #include <asm/arch/clk.h> |
84c7204b MS |
18 | #include <asm/arch/hardware.h> |
19 | #include <asm/arch/sys_proto.h> | |
2ad341ed | 20 | #include <asm/arch/psu_init_gpl.h> |
84c7204b | 21 | #include <asm/io.h> |
2882b39d | 22 | #include <dm/device.h> |
4490e013 | 23 | #include <dm/uclass.h> |
16fa00a7 SDPP |
24 | #include <usb.h> |
25 | #include <dwc3-uboot.h> | |
47e60cbd | 26 | #include <zynqmppl.h> |
009ab7b9 | 27 | #include <zynqmp_firmware.h> |
9feff385 | 28 | #include <g_dnl.h> |
80fdef12 | 29 | #include "../common/board.h" |
84c7204b | 30 | |
c28a9cfa LC |
31 | #include "pm_cfg_obj.h" |
32 | ||
84c7204b MS |
33 | DECLARE_GLOBAL_DATA_PTR; |
34 | ||
47e60cbd MS |
35 | #if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \ |
36 | !defined(CONFIG_SPL_BUILD) | |
37 | static xilinx_desc zynqmppl = XILINX_ZYNQMP_DESC; | |
38 | ||
39 | static const struct { | |
8ebdf9ef | 40 | u32 id; |
494fffe7 | 41 | u32 ver; |
47e60cbd | 42 | char *name; |
83bf2ff0 | 43 | bool evexists; |
47e60cbd MS |
44 | } zynqmp_devices[] = { |
45 | { | |
46 | .id = 0x10, | |
47 | .name = "3eg", | |
48 | }, | |
494fffe7 MS |
49 | { |
50 | .id = 0x10, | |
51 | .ver = 0x2c, | |
52 | .name = "3cg", | |
53 | }, | |
47e60cbd MS |
54 | { |
55 | .id = 0x11, | |
56 | .name = "2eg", | |
57 | }, | |
494fffe7 MS |
58 | { |
59 | .id = 0x11, | |
60 | .ver = 0x2c, | |
61 | .name = "2cg", | |
62 | }, | |
47e60cbd MS |
63 | { |
64 | .id = 0x20, | |
65 | .name = "5ev", | |
83bf2ff0 | 66 | .evexists = 1, |
47e60cbd | 67 | }, |
494fffe7 MS |
68 | { |
69 | .id = 0x20, | |
70 | .ver = 0x100, | |
71 | .name = "5eg", | |
83bf2ff0 | 72 | .evexists = 1, |
494fffe7 MS |
73 | }, |
74 | { | |
75 | .id = 0x20, | |
76 | .ver = 0x12c, | |
77 | .name = "5cg", | |
5473f245 | 78 | .evexists = 1, |
494fffe7 | 79 | }, |
47e60cbd MS |
80 | { |
81 | .id = 0x21, | |
82 | .name = "4ev", | |
83bf2ff0 | 83 | .evexists = 1, |
47e60cbd | 84 | }, |
494fffe7 MS |
85 | { |
86 | .id = 0x21, | |
87 | .ver = 0x100, | |
88 | .name = "4eg", | |
83bf2ff0 | 89 | .evexists = 1, |
494fffe7 MS |
90 | }, |
91 | { | |
92 | .id = 0x21, | |
93 | .ver = 0x12c, | |
94 | .name = "4cg", | |
5473f245 | 95 | .evexists = 1, |
494fffe7 | 96 | }, |
47e60cbd MS |
97 | { |
98 | .id = 0x30, | |
99 | .name = "7ev", | |
83bf2ff0 | 100 | .evexists = 1, |
47e60cbd | 101 | }, |
494fffe7 MS |
102 | { |
103 | .id = 0x30, | |
104 | .ver = 0x100, | |
105 | .name = "7eg", | |
83bf2ff0 | 106 | .evexists = 1, |
494fffe7 MS |
107 | }, |
108 | { | |
109 | .id = 0x30, | |
110 | .ver = 0x12c, | |
111 | .name = "7cg", | |
5473f245 | 112 | .evexists = 1, |
494fffe7 | 113 | }, |
47e60cbd MS |
114 | { |
115 | .id = 0x38, | |
116 | .name = "9eg", | |
117 | }, | |
494fffe7 MS |
118 | { |
119 | .id = 0x38, | |
120 | .ver = 0x2c, | |
121 | .name = "9cg", | |
122 | }, | |
47e60cbd MS |
123 | { |
124 | .id = 0x39, | |
125 | .name = "6eg", | |
126 | }, | |
494fffe7 MS |
127 | { |
128 | .id = 0x39, | |
129 | .ver = 0x2c, | |
130 | .name = "6cg", | |
131 | }, | |
47e60cbd MS |
132 | { |
133 | .id = 0x40, | |
134 | .name = "11eg", | |
135 | }, | |
494fffe7 MS |
136 | { /* For testing purpose only */ |
137 | .id = 0x50, | |
138 | .ver = 0x2c, | |
139 | .name = "15cg", | |
140 | }, | |
47e60cbd MS |
141 | { |
142 | .id = 0x50, | |
143 | .name = "15eg", | |
144 | }, | |
145 | { | |
146 | .id = 0x58, | |
147 | .name = "19eg", | |
148 | }, | |
149 | { | |
150 | .id = 0x59, | |
151 | .name = "17eg", | |
152 | }, | |
b030fedf MS |
153 | { |
154 | .id = 0x61, | |
155 | .name = "21dr", | |
156 | }, | |
157 | { | |
158 | .id = 0x63, | |
159 | .name = "23dr", | |
160 | }, | |
161 | { | |
162 | .id = 0x65, | |
163 | .name = "25dr", | |
164 | }, | |
165 | { | |
166 | .id = 0x64, | |
167 | .name = "27dr", | |
168 | }, | |
169 | { | |
170 | .id = 0x60, | |
171 | .name = "28dr", | |
172 | }, | |
173 | { | |
174 | .id = 0x62, | |
175 | .name = "29dr", | |
176 | }, | |
c7490907 SDPP |
177 | { |
178 | .id = 0x66, | |
179 | .name = "39dr", | |
180 | }, | |
134b0c8d SDPP |
181 | { |
182 | .id = 0x7b, | |
183 | .name = "48dr", | |
184 | }, | |
185 | { | |
186 | .id = 0x7e, | |
187 | .name = "49dr", | |
188 | }, | |
47e60cbd | 189 | }; |
74ba69db | 190 | #endif |
47e60cbd | 191 | |
f52bf5a3 | 192 | int chip_id(unsigned char id) |
47e60cbd MS |
193 | { |
194 | struct pt_regs regs; | |
db3123b4 | 195 | int val = -EINVAL; |
47e60cbd | 196 | |
74ba69db SDPP |
197 | if (current_el() != 3) { |
198 | regs.regs[0] = ZYNQMP_SIP_SVC_CSU_DMA_CHIPID; | |
199 | regs.regs[1] = 0; | |
200 | regs.regs[2] = 0; | |
201 | regs.regs[3] = 0; | |
202 | ||
203 | smc_call(®s); | |
204 | ||
205 | /* | |
206 | * SMC returns: | |
207 | * regs[0][31:0] = status of the operation | |
208 | * regs[0][63:32] = CSU.IDCODE register | |
209 | * regs[1][31:0] = CSU.version register | |
494fffe7 | 210 | * regs[1][63:32] = CSU.IDCODE2 register |
74ba69db SDPP |
211 | */ |
212 | switch (id) { | |
213 | case IDCODE: | |
214 | regs.regs[0] = upper_32_bits(regs.regs[0]); | |
215 | regs.regs[0] &= ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK | | |
216 | ZYNQMP_CSU_IDCODE_SVD_MASK; | |
217 | regs.regs[0] >>= ZYNQMP_CSU_IDCODE_SVD_SHIFT; | |
218 | val = regs.regs[0]; | |
219 | break; | |
220 | case VERSION: | |
221 | regs.regs[1] = lower_32_bits(regs.regs[1]); | |
222 | regs.regs[1] &= ZYNQMP_CSU_SILICON_VER_MASK; | |
223 | val = regs.regs[1]; | |
224 | break; | |
494fffe7 MS |
225 | case IDCODE2: |
226 | regs.regs[1] = lower_32_bits(regs.regs[1]); | |
227 | regs.regs[1] >>= ZYNQMP_CSU_VERSION_EMPTY_SHIFT; | |
228 | val = regs.regs[1]; | |
229 | break; | |
74ba69db SDPP |
230 | default: |
231 | printf("%s, Invalid Req:0x%x\n", __func__, id); | |
232 | } | |
233 | } else { | |
234 | switch (id) { | |
235 | case IDCODE: | |
236 | val = readl(ZYNQMP_CSU_IDCODE_ADDR); | |
237 | val &= ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK | | |
238 | ZYNQMP_CSU_IDCODE_SVD_MASK; | |
239 | val >>= ZYNQMP_CSU_IDCODE_SVD_SHIFT; | |
240 | break; | |
241 | case VERSION: | |
242 | val = readl(ZYNQMP_CSU_VER_ADDR); | |
243 | val &= ZYNQMP_CSU_SILICON_VER_MASK; | |
244 | break; | |
245 | default: | |
246 | printf("%s, Invalid Req:0x%x\n", __func__, id); | |
247 | } | |
db3123b4 | 248 | } |
0cba6abb | 249 | |
db3123b4 | 250 | return val; |
47e60cbd MS |
251 | } |
252 | ||
83bf2ff0 SDPP |
253 | #define ZYNQMP_VERSION_SIZE 9 |
254 | #define ZYNQMP_PL_STATUS_BIT 9 | |
5473f245 | 255 | #define ZYNQMP_IPDIS_VCU_BIT 8 |
83bf2ff0 SDPP |
256 | #define ZYNQMP_PL_STATUS_MASK BIT(ZYNQMP_PL_STATUS_BIT) |
257 | #define ZYNQMP_CSU_VERSION_MASK ~(ZYNQMP_PL_STATUS_MASK) | |
5473f245 SDPP |
258 | #define ZYNQMP_CSU_VCUDIS_VER_MASK ZYNQMP_CSU_VERSION_MASK & \ |
259 | ~BIT(ZYNQMP_IPDIS_VCU_BIT) | |
260 | #define MAX_VARIANTS_EV 3 | |
83bf2ff0 | 261 | |
74ba69db SDPP |
262 | #if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \ |
263 | !defined(CONFIG_SPL_BUILD) | |
47e60cbd MS |
264 | static char *zynqmp_get_silicon_idcode_name(void) |
265 | { | |
5473f245 | 266 | u32 i, id, ver, j; |
83bf2ff0 SDPP |
267 | char *buf; |
268 | static char name[ZYNQMP_VERSION_SIZE]; | |
47e60cbd | 269 | |
db3123b4 | 270 | id = chip_id(IDCODE); |
494fffe7 MS |
271 | ver = chip_id(IDCODE2); |
272 | ||
47e60cbd | 273 | for (i = 0; i < ARRAY_SIZE(zynqmp_devices); i++) { |
5473f245 SDPP |
274 | if (zynqmp_devices[i].id == id) { |
275 | if (zynqmp_devices[i].evexists && | |
276 | !(ver & ZYNQMP_PL_STATUS_MASK)) | |
277 | break; | |
278 | if (zynqmp_devices[i].ver == (ver & | |
279 | ZYNQMP_CSU_VERSION_MASK)) | |
280 | break; | |
83bf2ff0 | 281 | } |
47e60cbd | 282 | } |
83bf2ff0 SDPP |
283 | |
284 | if (i >= ARRAY_SIZE(zynqmp_devices)) | |
285 | return "unknown"; | |
286 | ||
5473f245 SDPP |
287 | strncat(name, "zu", 2); |
288 | if (!zynqmp_devices[i].evexists || | |
289 | (ver & ZYNQMP_PL_STATUS_MASK)) { | |
290 | strncat(name, zynqmp_devices[i].name, | |
291 | ZYNQMP_VERSION_SIZE - 3); | |
83bf2ff0 | 292 | return name; |
5473f245 | 293 | } |
83bf2ff0 | 294 | |
5473f245 SDPP |
295 | /* |
296 | * Here we are means, PL not powered up and ev variant | |
297 | * exists. So, we need to ignore VCU disable bit(8) in | |
298 | * version and findout if its CG or EG/EV variant. | |
299 | */ | |
300 | for (j = 0; j < MAX_VARIANTS_EV; j++, i++) { | |
301 | if ((zynqmp_devices[i].ver & ~BIT(ZYNQMP_IPDIS_VCU_BIT)) == | |
302 | (ver & ZYNQMP_CSU_VCUDIS_VER_MASK)) { | |
303 | strncat(name, zynqmp_devices[i].name, | |
304 | ZYNQMP_VERSION_SIZE - 3); | |
305 | break; | |
306 | } | |
307 | } | |
308 | ||
309 | if (j >= MAX_VARIANTS_EV) | |
310 | return "unknown"; | |
83bf2ff0 SDPP |
311 | |
312 | if (strstr(name, "eg") || strstr(name, "ev")) { | |
313 | buf = strstr(name, "e"); | |
314 | *buf = '\0'; | |
315 | } | |
316 | ||
317 | return name; | |
47e60cbd MS |
318 | } |
319 | #endif | |
320 | ||
fb4000e8 MS |
321 | int board_early_init_f(void) |
322 | { | |
88f05a92 | 323 | #if defined(CONFIG_ZYNQMP_PSU_INIT_ENABLED) |
c0adba57 MS |
324 | int ret; |
325 | ||
f32e79f1 | 326 | ret = psu_init(); |
c0adba57 MS |
327 | if (ret) |
328 | return ret; | |
f8451f14 MS |
329 | |
330 | /* Delay is required for clocks to be propagated */ | |
331 | udelay(1000000); | |
55de0929 MS |
332 | #endif |
333 | ||
c0adba57 MS |
334 | #ifdef CONFIG_DEBUG_UART |
335 | /* Uart debug for sure */ | |
336 | debug_uart_init(); | |
337 | puts("Debug uart enabled\n"); /* or printch() */ | |
338 | #endif | |
339 | ||
340 | return 0; | |
fb4000e8 MS |
341 | } |
342 | ||
c5143013 MS |
343 | static int multi_boot(void) |
344 | { | |
345 | u32 multiboot; | |
346 | ||
347 | multiboot = readl(&csu_base->multi_boot); | |
348 | ||
349 | printf("Multiboot:\t%x\n", multiboot); | |
350 | ||
351 | return 0; | |
352 | } | |
353 | ||
84c7204b MS |
354 | int board_init(void) |
355 | { | |
66ef85da | 356 | #if defined(CONFIG_ZYNQMP_FIRMWARE) |
325a22dc IE |
357 | struct udevice *dev; |
358 | ||
359 | uclass_get_device_by_name(UCLASS_FIRMWARE, "zynqmp-power", &dev); | |
360 | if (!dev) | |
361 | panic("PMU Firmware device not found - Enable it"); | |
66ef85da | 362 | #endif |
325a22dc | 363 | |
c28a9cfa LC |
364 | #if defined(CONFIG_SPL_BUILD) |
365 | /* Check *at build time* if the filename is an non-empty string */ | |
366 | if (sizeof(CONFIG_ZYNQMP_SPL_PM_CFG_OBJ_FILE) > 1) | |
367 | zynqmp_pmufw_load_config_object(zynqmp_pm_cfg_obj, | |
368 | zynqmp_pm_cfg_obj_size); | |
369 | #endif | |
370 | ||
a0736efb MS |
371 | printf("EL Level:\tEL%d\n", current_el()); |
372 | ||
47e60cbd MS |
373 | #if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \ |
374 | !defined(CONFIG_SPL_BUILD) || (defined(CONFIG_SPL_FPGA_SUPPORT) && \ | |
375 | defined(CONFIG_SPL_BUILD)) | |
376 | if (current_el() != 3) { | |
83bf2ff0 | 377 | zynqmppl.name = zynqmp_get_silicon_idcode_name(); |
47e60cbd MS |
378 | printf("Chip ID:\t%s\n", zynqmppl.name); |
379 | fpga_init(); | |
380 | fpga_add(fpga_xilinx, &zynqmppl); | |
381 | } | |
382 | #endif | |
383 | ||
c5143013 MS |
384 | if (current_el() == 3) |
385 | multi_boot(); | |
386 | ||
84c7204b MS |
387 | return 0; |
388 | } | |
389 | ||
390 | int board_early_init_r(void) | |
391 | { | |
392 | u32 val; | |
393 | ||
ec60a279 SDPP |
394 | if (current_el() != 3) |
395 | return 0; | |
396 | ||
90a35db4 MS |
397 | val = readl(&crlapb_base->timestamp_ref_ctrl); |
398 | val &= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT; | |
399 | ||
ec60a279 | 400 | if (!val) { |
0785dfd8 MS |
401 | val = readl(&crlapb_base->timestamp_ref_ctrl); |
402 | val |= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT; | |
403 | writel(val, &crlapb_base->timestamp_ref_ctrl); | |
84c7204b | 404 | |
0785dfd8 MS |
405 | /* Program freq register in System counter */ |
406 | writel(zynqmp_get_system_timer_freq(), | |
407 | &iou_scntr_secure->base_frequency_id_register); | |
408 | /* And enable system counter */ | |
409 | writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN, | |
410 | &iou_scntr_secure->counter_control_register); | |
411 | } | |
84c7204b MS |
412 | return 0; |
413 | } | |
414 | ||
51916864 NJ |
415 | unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc, |
416 | char * const argv[]) | |
417 | { | |
418 | int ret = 0; | |
419 | ||
420 | if (current_el() > 1) { | |
421 | smp_kick_all_cpus(); | |
422 | dcache_disable(); | |
423 | armv8_switch_to_el1(0x0, 0, 0, 0, (unsigned long)entry, | |
424 | ES_TO_AARCH64); | |
425 | } else { | |
426 | printf("FAIL: current EL is not above EL1\n"); | |
427 | ret = EINVAL; | |
428 | } | |
429 | return ret; | |
430 | } | |
431 | ||
8d59d7f6 | 432 | #if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE) |
76b00aca | 433 | int dram_init_banksize(void) |
361a8799 | 434 | { |
0678941a NJ |
435 | int ret; |
436 | ||
437 | ret = fdtdec_setup_memory_banksize(); | |
438 | if (ret) | |
439 | return ret; | |
440 | ||
441 | mem_map_fill(); | |
442 | ||
443 | return 0; | |
8a5db0ab | 444 | } |
8d59d7f6 | 445 | |
361a8799 | 446 | int dram_init(void) |
8a5db0ab | 447 | { |
12308b12 | 448 | if (fdtdec_setup_mem_size_base() != 0) |
950f86ca | 449 | return -EINVAL; |
8a5db0ab | 450 | |
361a8799 | 451 | return 0; |
8d59d7f6 MS |
452 | } |
453 | #else | |
0678941a NJ |
454 | int dram_init_banksize(void) |
455 | { | |
456 | #if defined(CONFIG_NR_DRAM_BANKS) | |
457 | gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE; | |
458 | gd->bd->bi_dram[0].size = get_effective_memsize(); | |
459 | #endif | |
460 | ||
461 | mem_map_fill(); | |
462 | ||
463 | return 0; | |
464 | } | |
465 | ||
84c7204b MS |
466 | int dram_init(void) |
467 | { | |
61dc92a2 MS |
468 | gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE, |
469 | CONFIG_SYS_SDRAM_SIZE); | |
84c7204b MS |
470 | |
471 | return 0; | |
472 | } | |
8d59d7f6 | 473 | #endif |
84c7204b | 474 | |
84c7204b MS |
475 | void reset_cpu(ulong addr) |
476 | { | |
477 | } | |
478 | ||
0bf3f9cb | 479 | #if defined(CONFIG_BOARD_LATE_INIT) |
d348beaa MS |
480 | static const struct { |
481 | u32 bit; | |
482 | const char *name; | |
483 | } reset_reasons[] = { | |
484 | { RESET_REASON_DEBUG_SYS, "DEBUG" }, | |
485 | { RESET_REASON_SOFT, "SOFT" }, | |
486 | { RESET_REASON_SRST, "SRST" }, | |
487 | { RESET_REASON_PSONLY, "PS-ONLY" }, | |
488 | { RESET_REASON_PMU, "PMU" }, | |
489 | { RESET_REASON_INTERNAL, "INTERNAL" }, | |
490 | { RESET_REASON_EXTERNAL, "EXTERNAL" }, | |
491 | {} | |
492 | }; | |
493 | ||
be52372f | 494 | static int reset_reason(void) |
d348beaa | 495 | { |
be52372f KR |
496 | u32 reg; |
497 | int i, ret; | |
d348beaa MS |
498 | const char *reason = NULL; |
499 | ||
be52372f KR |
500 | ret = zynqmp_mmio_read((ulong)&crlapb_base->reset_reason, ®); |
501 | if (ret) | |
502 | return -EINVAL; | |
d348beaa MS |
503 | |
504 | puts("Reset reason:\t"); | |
505 | ||
506 | for (i = 0; i < ARRAY_SIZE(reset_reasons); i++) { | |
be52372f | 507 | if (reg & reset_reasons[i].bit) { |
d348beaa MS |
508 | reason = reset_reasons[i].name; |
509 | printf("%s ", reset_reasons[i].name); | |
510 | break; | |
511 | } | |
512 | } | |
513 | ||
514 | puts("\n"); | |
515 | ||
516 | env_set("reset_reason", reason); | |
517 | ||
3d037524 | 518 | ret = zynqmp_mmio_write((ulong)&crlapb_base->reset_reason, ~0, ~0); |
be52372f KR |
519 | if (ret) |
520 | return -EINVAL; | |
d348beaa MS |
521 | |
522 | return ret; | |
523 | } | |
524 | ||
91d7e0c4 MS |
525 | static int set_fdtfile(void) |
526 | { | |
527 | char *compatible, *fdtfile; | |
528 | const char *suffix = ".dtb"; | |
529 | const char *vendor = "xilinx/"; | |
530 | ||
531 | if (env_get("fdtfile")) | |
532 | return 0; | |
533 | ||
534 | compatible = (char *)fdt_getprop(gd->fdt_blob, 0, "compatible", NULL); | |
535 | if (compatible) { | |
536 | debug("Compatible: %s\n", compatible); | |
537 | ||
538 | /* Discard vendor prefix */ | |
539 | strsep(&compatible, ","); | |
540 | ||
541 | fdtfile = calloc(1, strlen(vendor) + strlen(compatible) + | |
542 | strlen(suffix) + 1); | |
543 | if (!fdtfile) | |
544 | return -ENOMEM; | |
545 | ||
546 | sprintf(fdtfile, "%s%s%s", vendor, compatible, suffix); | |
547 | ||
548 | env_set("fdtfile", fdtfile); | |
549 | free(fdtfile); | |
550 | } | |
551 | ||
552 | return 0; | |
553 | } | |
554 | ||
84c7204b MS |
555 | int board_late_init(void) |
556 | { | |
557 | u32 reg = 0; | |
558 | u8 bootmode; | |
2882b39d MS |
559 | struct udevice *dev; |
560 | int bootseq = -1; | |
561 | int bootseq_len = 0; | |
0478b0b9 | 562 | int env_targets_len = 0; |
b72894f1 MS |
563 | const char *mode; |
564 | char *new_targets; | |
01c42d3d | 565 | char *env_targets; |
d1db89f4 | 566 | int ret; |
b72894f1 | 567 | |
e615f39e MS |
568 | #if defined(CONFIG_USB_ETHER) && !defined(CONFIG_USB_GADGET_DOWNLOAD) |
569 | usb_ether_init(); | |
570 | #endif | |
571 | ||
b72894f1 MS |
572 | if (!(gd->flags & GD_FLG_ENV_DEFAULT)) { |
573 | debug("Saved variables - Skipping\n"); | |
574 | return 0; | |
575 | } | |
84c7204b | 576 | |
91d7e0c4 MS |
577 | ret = set_fdtfile(); |
578 | if (ret) | |
579 | return ret; | |
580 | ||
d1db89f4 SDPP |
581 | ret = zynqmp_mmio_read((ulong)&crlapb_base->boot_mode, ®); |
582 | if (ret) | |
583 | return -EINVAL; | |
584 | ||
47359a03 MS |
585 | if (reg >> BOOT_MODE_ALT_SHIFT) |
586 | reg >>= BOOT_MODE_ALT_SHIFT; | |
587 | ||
84c7204b MS |
588 | bootmode = reg & BOOT_MODES_MASK; |
589 | ||
fb90917c | 590 | puts("Bootmode: "); |
84c7204b | 591 | switch (bootmode) { |
d58fc12e MS |
592 | case USB_MODE: |
593 | puts("USB_MODE\n"); | |
594 | mode = "usb"; | |
07656ba5 | 595 | env_set("modeboot", "usb_dfu_spl"); |
d58fc12e | 596 | break; |
0a5bcc8c | 597 | case JTAG_MODE: |
fb90917c | 598 | puts("JTAG_MODE\n"); |
5d2274c0 | 599 | mode = "jtag pxe dhcp"; |
07656ba5 | 600 | env_set("modeboot", "jtagboot"); |
0a5bcc8c SDPP |
601 | break; |
602 | case QSPI_MODE_24BIT: | |
603 | case QSPI_MODE_32BIT: | |
b72894f1 | 604 | mode = "qspi0"; |
fb90917c | 605 | puts("QSPI_MODE\n"); |
07656ba5 | 606 | env_set("modeboot", "qspiboot"); |
0a5bcc8c | 607 | break; |
39c56f55 | 608 | case EMMC_MODE: |
78678fee | 609 | puts("EMMC_MODE\n"); |
18be60b8 KR |
610 | if (uclass_get_device_by_name(UCLASS_MMC, |
611 | "mmc@ff160000", &dev) && | |
612 | uclass_get_device_by_name(UCLASS_MMC, | |
613 | "sdhci@ff160000", &dev)) { | |
614 | puts("Boot from EMMC but without SD0 enabled!\n"); | |
615 | return -1; | |
616 | } | |
617 | debug("mmc0 device found at %p, seq %d\n", dev, dev->seq); | |
618 | ||
619 | mode = "mmc"; | |
620 | bootseq = dev->seq; | |
78678fee MS |
621 | break; |
622 | case SD_MODE: | |
fb90917c | 623 | puts("SD_MODE\n"); |
2882b39d | 624 | if (uclass_get_device_by_name(UCLASS_MMC, |
e7c9de66 SDPP |
625 | "mmc@ff160000", &dev) && |
626 | uclass_get_device_by_name(UCLASS_MMC, | |
2882b39d MS |
627 | "sdhci@ff160000", &dev)) { |
628 | puts("Boot from SD0 but without SD0 enabled!\n"); | |
629 | return -1; | |
630 | } | |
631 | debug("mmc0 device found at %p, seq %d\n", dev, dev->seq); | |
632 | ||
633 | mode = "mmc"; | |
634 | bootseq = dev->seq; | |
07656ba5 | 635 | env_set("modeboot", "sdboot"); |
84c7204b | 636 | break; |
e1992276 SDPP |
637 | case SD1_LSHFT_MODE: |
638 | puts("LVL_SHFT_"); | |
639 | /* fall through */ | |
af813acd | 640 | case SD_MODE1: |
fb90917c | 641 | puts("SD_MODE1\n"); |
2882b39d | 642 | if (uclass_get_device_by_name(UCLASS_MMC, |
e7c9de66 SDPP |
643 | "mmc@ff170000", &dev) && |
644 | uclass_get_device_by_name(UCLASS_MMC, | |
2882b39d MS |
645 | "sdhci@ff170000", &dev)) { |
646 | puts("Boot from SD1 but without SD1 enabled!\n"); | |
647 | return -1; | |
648 | } | |
649 | debug("mmc1 device found at %p, seq %d\n", dev, dev->seq); | |
650 | ||
651 | mode = "mmc"; | |
652 | bootseq = dev->seq; | |
07656ba5 | 653 | env_set("modeboot", "sdboot"); |
af813acd MS |
654 | break; |
655 | case NAND_MODE: | |
fb90917c | 656 | puts("NAND_MODE\n"); |
b72894f1 | 657 | mode = "nand0"; |
07656ba5 | 658 | env_set("modeboot", "nandboot"); |
af813acd | 659 | break; |
84c7204b | 660 | default: |
b72894f1 | 661 | mode = ""; |
84c7204b MS |
662 | printf("Invalid Boot Mode:0x%x\n", bootmode); |
663 | break; | |
664 | } | |
665 | ||
2882b39d MS |
666 | if (bootseq >= 0) { |
667 | bootseq_len = snprintf(NULL, 0, "%i", bootseq); | |
668 | debug("Bootseq len: %x\n", bootseq_len); | |
669 | } | |
670 | ||
b72894f1 MS |
671 | /* |
672 | * One terminating char + one byte for space between mode | |
673 | * and default boot_targets | |
674 | */ | |
01c42d3d | 675 | env_targets = env_get("boot_targets"); |
0478b0b9 MS |
676 | if (env_targets) |
677 | env_targets_len = strlen(env_targets); | |
678 | ||
2882b39d MS |
679 | new_targets = calloc(1, strlen(mode) + env_targets_len + 2 + |
680 | bootseq_len); | |
1e3e68f1 MS |
681 | if (!new_targets) |
682 | return -ENOMEM; | |
0478b0b9 | 683 | |
2882b39d MS |
684 | if (bootseq >= 0) |
685 | sprintf(new_targets, "%s%x %s", mode, bootseq, | |
686 | env_targets ? env_targets : ""); | |
687 | else | |
688 | sprintf(new_targets, "%s %s", mode, | |
689 | env_targets ? env_targets : ""); | |
b72894f1 | 690 | |
382bee57 | 691 | env_set("boot_targets", new_targets); |
b72894f1 | 692 | |
d348beaa MS |
693 | reset_reason(); |
694 | ||
80fdef12 | 695 | return board_late_init_xilinx(); |
84c7204b | 696 | } |
0bf3f9cb | 697 | #endif |
84696ff5 SDPP |
698 | |
699 | int checkboard(void) | |
700 | { | |
5af08556 | 701 | puts("Board: Xilinx ZynqMP\n"); |
84696ff5 SDPP |
702 | return 0; |
703 | } |