1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2014 - 2018 Xilinx, Inc.
4 * Michal Simek <michal.simek@xilinx.com>
14 #include <asm/cache.h>
16 #include <asm/arch/hardware.h>
17 #include <asm/arch/sys_proto.h>
18 #include <dm/device.h>
19 #include <dm/uclass.h>
21 #include "../common/board.h"
23 DECLARE_GLOBAL_DATA_PTR;
25 #if defined(CONFIG_FPGA_VERSALPL)
26 static xilinx_desc versalpl = XILINX_VERSAL_DESC;
31 printf("EL Level:\tEL%d\n", current_el());
33 #if defined(CONFIG_FPGA_VERSALPL)
35 fpga_add(fpga_xilinx, &versalpl);
41 int board_early_init_r(void)
45 if (current_el() != 3)
48 debug("iou_switch ctrl div0 %x\n",
49 readl(&crlapb_base->iou_switch_ctrl));
51 writel(IOU_SWITCH_CTRL_CLKACT_BIT |
52 (CONFIG_IOU_SWITCH_DIVISOR0 << IOU_SWITCH_CTRL_DIVISOR0_SHIFT),
53 &crlapb_base->iou_switch_ctrl);
55 /* Global timer init - Program time stamp reference clk */
56 val = readl(&crlapb_base->timestamp_ref_ctrl);
57 val |= CRL_APB_TIMESTAMP_REF_CTRL_CLKACT_BIT;
58 writel(val, &crlapb_base->timestamp_ref_ctrl);
60 debug("ref ctrl 0x%x\n",
61 readl(&crlapb_base->timestamp_ref_ctrl));
63 /* Clear reset of timestamp reg */
64 writel(0, &crlapb_base->rst_timestamp);
67 * Program freq register in System counter and
68 * enable system counter.
70 writel(COUNTER_FREQUENCY,
71 &iou_scntr_secure->base_frequency_id_register);
73 debug("counter val 0x%x\n",
74 readl(&iou_scntr_secure->base_frequency_id_register));
76 writel(IOU_SCNTRS_CONTROL_EN,
77 &iou_scntr_secure->counter_control_register);
79 debug("scntrs control 0x%x\n",
80 readl(&iou_scntr_secure->counter_control_register));
81 debug("timer 0x%llx\n", get_ticks());
82 debug("timer 0x%llx\n", get_ticks());
87 static u8 versal_get_bootmode(void)
92 reg = readl(&crp_base->boot_mode_usr);
94 if (reg >> BOOT_MODE_ALT_SHIFT)
95 reg >>= BOOT_MODE_ALT_SHIFT;
97 bootmode = reg & BOOT_MODES_MASK;
102 int board_late_init(void)
108 int env_targets_len = 0;
113 if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
114 debug("Saved variables - Skipping\n");
118 bootmode = versal_get_bootmode();
128 mode = "jtag pxe dhcp";
130 case QSPI_MODE_24BIT:
131 puts("QSPI_MODE_24\n");
134 case QSPI_MODE_32BIT:
135 puts("QSPI_MODE_32\n");
144 if (uclass_get_device_by_name(UCLASS_MMC,
145 "sdhci@f1050000", &dev)) {
146 puts("Boot from EMMC but without SD1 enabled!\n");
149 debug("mmc1 device found at %p, seq %d\n", dev, dev->seq);
155 if (uclass_get_device_by_name(UCLASS_MMC,
156 "sdhci@f1040000", &dev)) {
157 puts("Boot from SD0 but without SD0 enabled!\n");
160 debug("mmc0 device found at %p, seq %d\n", dev, dev->seq);
170 if (uclass_get_device_by_name(UCLASS_MMC,
171 "sdhci@f1050000", &dev)) {
172 puts("Boot from SD1 but without SD1 enabled!\n");
175 debug("mmc1 device found at %p, seq %d\n", dev, dev->seq);
182 printf("Invalid Boot Mode:0x%x\n", bootmode);
187 bootseq_len = snprintf(NULL, 0, "%i", bootseq);
188 debug("Bootseq len: %x\n", bootseq_len);
192 * One terminating char + one byte for space between mode
193 * and default boot_targets
195 env_targets = env_get("boot_targets");
197 env_targets_len = strlen(env_targets);
199 new_targets = calloc(1, strlen(mode) + env_targets_len + 2 +
205 sprintf(new_targets, "%s%x %s", mode, bootseq,
206 env_targets ? env_targets : "");
208 sprintf(new_targets, "%s %s", mode,
209 env_targets ? env_targets : "");
211 env_set("boot_targets", new_targets);
213 return board_late_init_xilinx();
216 int dram_init_banksize(void)
220 ret = fdtdec_setup_memory_banksize();
231 if (fdtdec_setup_mem_size_base() != 0)
237 void reset_cpu(ulong addr)