1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2014 - 2015 Xilinx, Inc.
4 * Michal Simek <michal.simek@xilinx.com>
10 #include <debug_uart.h>
20 #include <asm/arch/clk.h>
21 #include <asm/arch/hardware.h>
22 #include <asm/arch/sys_proto.h>
23 #include <asm/arch/psu_init_gpl.h>
24 #include <asm/cache.h>
26 #include <dm/device.h>
27 #include <dm/uclass.h>
29 #include <dwc3-uboot.h>
31 #include <zynqmp_firmware.h>
33 #include "../common/board.h"
35 #include "pm_cfg_obj.h"
37 DECLARE_GLOBAL_DATA_PTR;
39 #if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
40 !defined(CONFIG_SPL_BUILD)
41 static xilinx_desc zynqmppl = XILINX_ZYNQMP_DESC;
48 } zynqmp_devices[] = {
140 { /* For testing purpose only */
196 int chip_id(unsigned char id)
201 if (current_el() != 3) {
202 regs.regs[0] = ZYNQMP_SIP_SVC_CSU_DMA_CHIPID;
211 * regs[0][31:0] = status of the operation
212 * regs[0][63:32] = CSU.IDCODE register
213 * regs[1][31:0] = CSU.version register
214 * regs[1][63:32] = CSU.IDCODE2 register
218 regs.regs[0] = upper_32_bits(regs.regs[0]);
219 regs.regs[0] &= ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK |
220 ZYNQMP_CSU_IDCODE_SVD_MASK;
221 regs.regs[0] >>= ZYNQMP_CSU_IDCODE_SVD_SHIFT;
225 regs.regs[1] = lower_32_bits(regs.regs[1]);
226 regs.regs[1] &= ZYNQMP_CSU_SILICON_VER_MASK;
230 regs.regs[1] = lower_32_bits(regs.regs[1]);
231 regs.regs[1] >>= ZYNQMP_CSU_VERSION_EMPTY_SHIFT;
235 printf("%s, Invalid Req:0x%x\n", __func__, id);
240 val = readl(ZYNQMP_CSU_IDCODE_ADDR);
241 val &= ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK |
242 ZYNQMP_CSU_IDCODE_SVD_MASK;
243 val >>= ZYNQMP_CSU_IDCODE_SVD_SHIFT;
246 val = readl(ZYNQMP_CSU_VER_ADDR);
247 val &= ZYNQMP_CSU_SILICON_VER_MASK;
250 printf("%s, Invalid Req:0x%x\n", __func__, id);
257 #define ZYNQMP_VERSION_SIZE 9
258 #define ZYNQMP_PL_STATUS_BIT 9
259 #define ZYNQMP_IPDIS_VCU_BIT 8
260 #define ZYNQMP_PL_STATUS_MASK BIT(ZYNQMP_PL_STATUS_BIT)
261 #define ZYNQMP_CSU_VERSION_MASK ~(ZYNQMP_PL_STATUS_MASK)
262 #define ZYNQMP_CSU_VCUDIS_VER_MASK ZYNQMP_CSU_VERSION_MASK & \
263 ~BIT(ZYNQMP_IPDIS_VCU_BIT)
264 #define MAX_VARIANTS_EV 3
266 #if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
267 !defined(CONFIG_SPL_BUILD)
268 static char *zynqmp_get_silicon_idcode_name(void)
272 static char name[ZYNQMP_VERSION_SIZE];
274 id = chip_id(IDCODE);
275 ver = chip_id(IDCODE2);
277 for (i = 0; i < ARRAY_SIZE(zynqmp_devices); i++) {
278 if (zynqmp_devices[i].id == id) {
279 if (zynqmp_devices[i].evexists &&
280 !(ver & ZYNQMP_PL_STATUS_MASK))
282 if (zynqmp_devices[i].ver == (ver &
283 ZYNQMP_CSU_VERSION_MASK))
288 if (i >= ARRAY_SIZE(zynqmp_devices))
291 strncat(name, "zu", 2);
292 if (!zynqmp_devices[i].evexists ||
293 (ver & ZYNQMP_PL_STATUS_MASK)) {
294 strncat(name, zynqmp_devices[i].name,
295 ZYNQMP_VERSION_SIZE - 3);
300 * Here we are means, PL not powered up and ev variant
301 * exists. So, we need to ignore VCU disable bit(8) in
302 * version and findout if its CG or EG/EV variant.
304 for (j = 0; j < MAX_VARIANTS_EV; j++, i++) {
305 if ((zynqmp_devices[i].ver & ~BIT(ZYNQMP_IPDIS_VCU_BIT)) ==
306 (ver & ZYNQMP_CSU_VCUDIS_VER_MASK)) {
307 strncat(name, zynqmp_devices[i].name,
308 ZYNQMP_VERSION_SIZE - 3);
313 if (j >= MAX_VARIANTS_EV)
316 if (strstr(name, "eg") || strstr(name, "ev")) {
317 buf = strstr(name, "e");
325 int board_early_init_f(void)
327 #if defined(CONFIG_ZYNQMP_PSU_INIT_ENABLED)
334 /* Delay is required for clocks to be propagated */
338 #ifdef CONFIG_DEBUG_UART
339 /* Uart debug for sure */
341 puts("Debug uart enabled\n"); /* or printch() */
347 static int multi_boot(void)
351 multiboot = readl(&csu_base->multi_boot);
353 printf("Multiboot:\t%x\n", multiboot);
360 #if defined(CONFIG_ZYNQMP_FIRMWARE)
363 uclass_get_device_by_name(UCLASS_FIRMWARE, "zynqmp-power", &dev);
365 panic("PMU Firmware device not found - Enable it");
368 #if defined(CONFIG_SPL_BUILD)
369 /* Check *at build time* if the filename is an non-empty string */
370 if (sizeof(CONFIG_ZYNQMP_SPL_PM_CFG_OBJ_FILE) > 1)
371 zynqmp_pmufw_load_config_object(zynqmp_pm_cfg_obj,
372 zynqmp_pm_cfg_obj_size);
375 printf("EL Level:\tEL%d\n", current_el());
377 #if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
378 !defined(CONFIG_SPL_BUILD) || (defined(CONFIG_SPL_FPGA_SUPPORT) && \
379 defined(CONFIG_SPL_BUILD))
380 if (current_el() != 3) {
381 zynqmppl.name = zynqmp_get_silicon_idcode_name();
382 printf("Chip ID:\t%s\n", zynqmppl.name);
384 fpga_add(fpga_xilinx, &zynqmppl);
388 if (current_el() == 3)
394 int board_early_init_r(void)
398 if (current_el() != 3)
401 val = readl(&crlapb_base->timestamp_ref_ctrl);
402 val &= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
405 val = readl(&crlapb_base->timestamp_ref_ctrl);
406 val |= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
407 writel(val, &crlapb_base->timestamp_ref_ctrl);
409 /* Program freq register in System counter */
410 writel(zynqmp_get_system_timer_freq(),
411 &iou_scntr_secure->base_frequency_id_register);
412 /* And enable system counter */
413 writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN,
414 &iou_scntr_secure->counter_control_register);
419 unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc,
424 if (current_el() > 1) {
427 armv8_switch_to_el1(0x0, 0, 0, 0, (unsigned long)entry,
430 printf("FAIL: current EL is not above EL1\n");
436 #if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE)
437 int dram_init_banksize(void)
441 ret = fdtdec_setup_memory_banksize();
452 if (fdtdec_setup_mem_size_base() != 0)
458 int dram_init_banksize(void)
460 #if defined(CONFIG_NR_DRAM_BANKS)
461 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
462 gd->bd->bi_dram[0].size = get_effective_memsize();
472 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
473 CONFIG_SYS_SDRAM_SIZE);
479 void reset_cpu(ulong addr)
483 #if defined(CONFIG_BOARD_LATE_INIT)
484 static const struct {
487 } reset_reasons[] = {
488 { RESET_REASON_DEBUG_SYS, "DEBUG" },
489 { RESET_REASON_SOFT, "SOFT" },
490 { RESET_REASON_SRST, "SRST" },
491 { RESET_REASON_PSONLY, "PS-ONLY" },
492 { RESET_REASON_PMU, "PMU" },
493 { RESET_REASON_INTERNAL, "INTERNAL" },
494 { RESET_REASON_EXTERNAL, "EXTERNAL" },
498 static int reset_reason(void)
502 const char *reason = NULL;
504 ret = zynqmp_mmio_read((ulong)&crlapb_base->reset_reason, ®);
508 puts("Reset reason:\t");
510 for (i = 0; i < ARRAY_SIZE(reset_reasons); i++) {
511 if (reg & reset_reasons[i].bit) {
512 reason = reset_reasons[i].name;
513 printf("%s ", reset_reasons[i].name);
520 env_set("reset_reason", reason);
522 ret = zynqmp_mmio_write((ulong)&crlapb_base->reset_reason, ~0, ~0);
529 static int set_fdtfile(void)
531 char *compatible, *fdtfile;
532 const char *suffix = ".dtb";
533 const char *vendor = "xilinx/";
535 if (env_get("fdtfile"))
538 compatible = (char *)fdt_getprop(gd->fdt_blob, 0, "compatible", NULL);
540 debug("Compatible: %s\n", compatible);
542 /* Discard vendor prefix */
543 strsep(&compatible, ",");
545 fdtfile = calloc(1, strlen(vendor) + strlen(compatible) +
550 sprintf(fdtfile, "%s%s%s", vendor, compatible, suffix);
552 env_set("fdtfile", fdtfile);
559 static u8 zynqmp_get_bootmode(void)
565 ret = zynqmp_mmio_read((ulong)&crlapb_base->boot_mode, ®);
569 if (reg >> BOOT_MODE_ALT_SHIFT)
570 reg >>= BOOT_MODE_ALT_SHIFT;
572 bootmode = reg & BOOT_MODES_MASK;
577 int board_late_init(void)
583 int env_targets_len = 0;
589 #if defined(CONFIG_USB_ETHER) && !defined(CONFIG_USB_GADGET_DOWNLOAD)
593 if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
594 debug("Saved variables - Skipping\n");
602 bootmode = zynqmp_get_bootmode();
609 env_set("modeboot", "usb_dfu_spl");
613 mode = "jtag pxe dhcp";
614 env_set("modeboot", "jtagboot");
616 case QSPI_MODE_24BIT:
617 case QSPI_MODE_32BIT:
620 env_set("modeboot", "qspiboot");
624 if (uclass_get_device_by_name(UCLASS_MMC,
625 "mmc@ff160000", &dev) &&
626 uclass_get_device_by_name(UCLASS_MMC,
627 "sdhci@ff160000", &dev)) {
628 puts("Boot from EMMC but without SD0 enabled!\n");
631 debug("mmc0 device found at %p, seq %d\n", dev, dev->seq);
638 if (uclass_get_device_by_name(UCLASS_MMC,
639 "mmc@ff160000", &dev) &&
640 uclass_get_device_by_name(UCLASS_MMC,
641 "sdhci@ff160000", &dev)) {
642 puts("Boot from SD0 but without SD0 enabled!\n");
645 debug("mmc0 device found at %p, seq %d\n", dev, dev->seq);
649 env_set("modeboot", "sdboot");
656 if (uclass_get_device_by_name(UCLASS_MMC,
657 "mmc@ff170000", &dev) &&
658 uclass_get_device_by_name(UCLASS_MMC,
659 "sdhci@ff170000", &dev)) {
660 puts("Boot from SD1 but without SD1 enabled!\n");
663 debug("mmc1 device found at %p, seq %d\n", dev, dev->seq);
667 env_set("modeboot", "sdboot");
672 env_set("modeboot", "nandboot");
676 printf("Invalid Boot Mode:0x%x\n", bootmode);
681 bootseq_len = snprintf(NULL, 0, "%i", bootseq);
682 debug("Bootseq len: %x\n", bootseq_len);
686 * One terminating char + one byte for space between mode
687 * and default boot_targets
689 env_targets = env_get("boot_targets");
691 env_targets_len = strlen(env_targets);
693 new_targets = calloc(1, strlen(mode) + env_targets_len + 2 +
699 sprintf(new_targets, "%s%x %s", mode, bootseq,
700 env_targets ? env_targets : "");
702 sprintf(new_targets, "%s %s", mode,
703 env_targets ? env_targets : "");
705 env_set("boot_targets", new_targets);
709 return board_late_init_xilinx();
715 puts("Board: Xilinx ZynqMP\n");