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 <asm/ptrace.h>
27 #include <dm/device.h>
28 #include <dm/uclass.h>
30 #include <dwc3-uboot.h>
32 #include <zynqmp_firmware.h>
34 #include <linux/bitops.h>
35 #include <linux/delay.h>
36 #include <linux/sizes.h>
37 #include "../common/board.h"
39 #include "pm_cfg_obj.h"
41 DECLARE_GLOBAL_DATA_PTR;
43 #if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
44 !defined(CONFIG_SPL_BUILD)
45 static xilinx_desc zynqmppl = XILINX_ZYNQMP_DESC;
52 } zynqmp_devices[] = {
144 { /* For testing purpose only */
200 #define ZYNQMP_VERSION_SIZE 9
201 #define ZYNQMP_PL_STATUS_BIT 9
202 #define ZYNQMP_IPDIS_VCU_BIT 8
203 #define ZYNQMP_PL_STATUS_MASK BIT(ZYNQMP_PL_STATUS_BIT)
204 #define ZYNQMP_CSU_VERSION_MASK ~(ZYNQMP_PL_STATUS_MASK)
205 #define ZYNQMP_CSU_VCUDIS_VER_MASK ZYNQMP_CSU_VERSION_MASK & \
206 ~BIT(ZYNQMP_IPDIS_VCU_BIT)
207 #define MAX_VARIANTS_EV 3
209 #if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
210 !defined(CONFIG_SPL_BUILD)
211 static char *zynqmp_get_silicon_idcode_name(void)
215 static char name[ZYNQMP_VERSION_SIZE];
216 u32 ret_payload[PAYLOAD_ARG_CNT];
218 xilinx_pm_request(PM_GET_CHIPID, 0, 0, 0, 0, ret_payload);
222 * payload[0][31:0] = status of the operation
223 * payload[1]] = IDCODE
224 * payload[2][19:0] = Version
225 * payload[2][28:20] = EXTENDED_IDCODE
226 * payload[2][29] = PL_INIT
229 /* Get IDCODE field */
231 id &= ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK | ZYNQMP_CSU_IDCODE_SVD_MASK;
232 id >>= ZYNQMP_CSU_IDCODE_SVD_SHIFT;
234 /* Shift silicon version info */
235 ver = ret_payload[2] >> ZYNQMP_CSU_VERSION_EMPTY_SHIFT;
237 debug("%s, ID: 0x%0X, Ver: 0x%0X\r\n", __func__, id, ver);
239 for (i = 0; i < ARRAY_SIZE(zynqmp_devices); i++) {
240 if (zynqmp_devices[i].id == id) {
241 if (zynqmp_devices[i].evexists &&
242 !(ver & ZYNQMP_PL_STATUS_MASK))
244 if (zynqmp_devices[i].ver == (ver &
245 ZYNQMP_CSU_VERSION_MASK))
250 if (i >= ARRAY_SIZE(zynqmp_devices))
253 strncat(name, "zu", 2);
254 if (!zynqmp_devices[i].evexists ||
255 (ver & ZYNQMP_PL_STATUS_MASK)) {
256 strncat(name, zynqmp_devices[i].name,
257 ZYNQMP_VERSION_SIZE - 3);
262 * Here we are means, PL not powered up and ev variant
263 * exists. So, we need to ignore VCU disable bit(8) in
264 * version and findout if its CG or EG/EV variant.
266 for (j = 0; j < MAX_VARIANTS_EV; j++, i++) {
267 if ((zynqmp_devices[i].ver & ~BIT(ZYNQMP_IPDIS_VCU_BIT)) ==
268 (ver & ZYNQMP_CSU_VCUDIS_VER_MASK)) {
269 strncat(name, zynqmp_devices[i].name,
270 ZYNQMP_VERSION_SIZE - 3);
275 if (j >= MAX_VARIANTS_EV)
278 if (strstr(name, "eg") || strstr(name, "ev")) {
279 buf = strstr(name, "e");
287 int board_early_init_f(void)
289 #if defined(CONFIG_ZYNQMP_PSU_INIT_ENABLED)
296 /* Delay is required for clocks to be propagated */
300 #ifdef CONFIG_DEBUG_UART
301 /* Uart debug for sure */
303 puts("Debug uart enabled\n"); /* or printch() */
309 static int multi_boot(void)
313 multiboot = readl(&csu_base->multi_boot);
315 printf("Multiboot:\t%d\n", multiboot);
320 #define PS_SYSMON_ANALOG_BUS_VAL 0x3210
321 #define PS_SYSMON_ANALOG_BUS_REG 0xFFA50914
325 #if defined(CONFIG_ZYNQMP_FIRMWARE)
328 uclass_get_device_by_name(UCLASS_FIRMWARE, "zynqmp-power", &dev);
330 panic("PMU Firmware device not found - Enable it");
333 #if defined(CONFIG_SPL_BUILD)
334 /* Check *at build time* if the filename is an non-empty string */
335 if (sizeof(CONFIG_ZYNQMP_SPL_PM_CFG_OBJ_FILE) > 1)
336 zynqmp_pmufw_load_config_object(zynqmp_pm_cfg_obj,
337 zynqmp_pm_cfg_obj_size);
340 printf("EL Level:\tEL%d\n", current_el());
342 /* Bug in ROM sets wrong value in this register */
343 writel(PS_SYSMON_ANALOG_BUS_VAL, PS_SYSMON_ANALOG_BUS_REG);
345 #if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
346 !defined(CONFIG_SPL_BUILD) || (defined(CONFIG_SPL_FPGA_SUPPORT) && \
347 defined(CONFIG_SPL_BUILD))
348 zynqmppl.name = zynqmp_get_silicon_idcode_name();
349 printf("Chip ID:\t%s\n", zynqmppl.name);
351 fpga_add(fpga_xilinx, &zynqmppl);
354 if (current_el() == 3)
360 int board_early_init_r(void)
364 if (current_el() != 3)
367 val = readl(&crlapb_base->timestamp_ref_ctrl);
368 val &= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
371 val = readl(&crlapb_base->timestamp_ref_ctrl);
372 val |= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
373 writel(val, &crlapb_base->timestamp_ref_ctrl);
375 /* Program freq register in System counter */
376 writel(zynqmp_get_system_timer_freq(),
377 &iou_scntr_secure->base_frequency_id_register);
378 /* And enable system counter */
379 writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN,
380 &iou_scntr_secure->counter_control_register);
385 unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc,
390 if (current_el() > 1) {
393 armv8_switch_to_el1(0x0, 0, 0, 0, (unsigned long)entry,
396 printf("FAIL: current EL is not above EL1\n");
402 #if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE)
403 int dram_init_banksize(void)
407 ret = fdtdec_setup_memory_banksize();
418 if (fdtdec_setup_mem_size_base() != 0)
424 int dram_init_banksize(void)
426 #if defined(CONFIG_NR_DRAM_BANKS)
427 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
428 gd->bd->bi_dram[0].size = get_effective_memsize();
438 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
439 CONFIG_SYS_SDRAM_SIZE);
445 void reset_cpu(ulong addr)
449 #if defined(CONFIG_BOARD_LATE_INIT)
450 static const struct {
453 } reset_reasons[] = {
454 { RESET_REASON_DEBUG_SYS, "DEBUG" },
455 { RESET_REASON_SOFT, "SOFT" },
456 { RESET_REASON_SRST, "SRST" },
457 { RESET_REASON_PSONLY, "PS-ONLY" },
458 { RESET_REASON_PMU, "PMU" },
459 { RESET_REASON_INTERNAL, "INTERNAL" },
460 { RESET_REASON_EXTERNAL, "EXTERNAL" },
464 static int reset_reason(void)
468 const char *reason = NULL;
470 ret = zynqmp_mmio_read((ulong)&crlapb_base->reset_reason, ®);
474 puts("Reset reason:\t");
476 for (i = 0; i < ARRAY_SIZE(reset_reasons); i++) {
477 if (reg & reset_reasons[i].bit) {
478 reason = reset_reasons[i].name;
479 printf("%s ", reset_reasons[i].name);
486 env_set("reset_reason", reason);
488 ret = zynqmp_mmio_write((ulong)&crlapb_base->reset_reason, ~0, ~0);
495 static int set_fdtfile(void)
497 char *compatible, *fdtfile;
498 const char *suffix = ".dtb";
499 const char *vendor = "xilinx/";
502 if (env_get("fdtfile"))
505 compatible = (char *)fdt_getprop(gd->fdt_blob, 0, "compatible",
507 if (compatible && fdt_compat_len) {
510 debug("Compatible: %s\n", compatible);
512 name = strchr(compatible, ',');
518 fdtfile = calloc(1, strlen(vendor) + strlen(name) +
523 sprintf(fdtfile, "%s%s%s", vendor, name, suffix);
525 env_set("fdtfile", fdtfile);
532 static u8 zynqmp_get_bootmode(void)
538 ret = zynqmp_mmio_read((ulong)&crlapb_base->boot_mode, ®);
542 if (reg >> BOOT_MODE_ALT_SHIFT)
543 reg >>= BOOT_MODE_ALT_SHIFT;
545 bootmode = reg & BOOT_MODES_MASK;
550 int board_late_init(void)
556 int env_targets_len = 0;
562 #if defined(CONFIG_USB_ETHER) && !defined(CONFIG_USB_GADGET_DOWNLOAD)
566 if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
567 debug("Saved variables - Skipping\n");
571 if (!CONFIG_IS_ENABLED(ENV_VARS_UBOOT_RUNTIME_CONFIG))
578 bootmode = zynqmp_get_bootmode();
585 env_set("modeboot", "usb_dfu_spl");
589 mode = "jtag pxe dhcp";
590 env_set("modeboot", "jtagboot");
592 case QSPI_MODE_24BIT:
593 case QSPI_MODE_32BIT:
596 env_set("modeboot", "qspiboot");
600 if (uclass_get_device_by_name(UCLASS_MMC,
601 "mmc@ff160000", &dev) &&
602 uclass_get_device_by_name(UCLASS_MMC,
603 "sdhci@ff160000", &dev)) {
604 puts("Boot from EMMC but without SD0 enabled!\n");
607 debug("mmc0 device found at %p, seq %d\n", dev, dev->seq);
614 if (uclass_get_device_by_name(UCLASS_MMC,
615 "mmc@ff160000", &dev) &&
616 uclass_get_device_by_name(UCLASS_MMC,
617 "sdhci@ff160000", &dev)) {
618 puts("Boot from SD0 but without SD0 enabled!\n");
621 debug("mmc0 device found at %p, seq %d\n", dev, dev->seq);
625 env_set("modeboot", "sdboot");
632 if (uclass_get_device_by_name(UCLASS_MMC,
633 "mmc@ff170000", &dev) &&
634 uclass_get_device_by_name(UCLASS_MMC,
635 "sdhci@ff170000", &dev)) {
636 puts("Boot from SD1 but without SD1 enabled!\n");
639 debug("mmc1 device found at %p, seq %d\n", dev, dev->seq);
643 env_set("modeboot", "sdboot");
648 env_set("modeboot", "nandboot");
652 printf("Invalid Boot Mode:0x%x\n", bootmode);
657 bootseq_len = snprintf(NULL, 0, "%i", bootseq);
658 debug("Bootseq len: %x\n", bootseq_len);
662 * One terminating char + one byte for space between mode
663 * and default boot_targets
665 env_targets = env_get("boot_targets");
667 env_targets_len = strlen(env_targets);
669 new_targets = calloc(1, strlen(mode) + env_targets_len + 2 +
675 sprintf(new_targets, "%s%x %s", mode, bootseq,
676 env_targets ? env_targets : "");
678 sprintf(new_targets, "%s %s", mode,
679 env_targets ? env_targets : "");
681 env_set("boot_targets", new_targets);
685 return board_late_init_xilinx();
691 puts("Board: Xilinx ZynqMP\n");