1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2014 - 2018 Xilinx, Inc.
4 * Michal Simek <michal.simek@xilinx.com>
15 #include <asm/cache.h>
17 #include <asm/arch/hardware.h>
18 #include <asm/arch/sys_proto.h>
19 #include <dm/device.h>
20 #include <dm/uclass.h>
22 #include "../common/board.h"
24 DECLARE_GLOBAL_DATA_PTR;
26 #if defined(CONFIG_FPGA_VERSALPL)
27 static xilinx_desc versalpl = XILINX_VERSAL_DESC;
32 printf("EL Level:\tEL%d\n", current_el());
34 #if defined(CONFIG_FPGA_VERSALPL)
36 fpga_add(fpga_xilinx, &versalpl);
42 int board_early_init_r(void)
46 if (current_el() != 3)
49 debug("iou_switch ctrl div0 %x\n",
50 readl(&crlapb_base->iou_switch_ctrl));
52 writel(IOU_SWITCH_CTRL_CLKACT_BIT |
53 (CONFIG_IOU_SWITCH_DIVISOR0 << IOU_SWITCH_CTRL_DIVISOR0_SHIFT),
54 &crlapb_base->iou_switch_ctrl);
56 /* Global timer init - Program time stamp reference clk */
57 val = readl(&crlapb_base->timestamp_ref_ctrl);
58 val |= CRL_APB_TIMESTAMP_REF_CTRL_CLKACT_BIT;
59 writel(val, &crlapb_base->timestamp_ref_ctrl);
61 debug("ref ctrl 0x%x\n",
62 readl(&crlapb_base->timestamp_ref_ctrl));
64 /* Clear reset of timestamp reg */
65 writel(0, &crlapb_base->rst_timestamp);
68 * Program freq register in System counter and
69 * enable system counter.
71 writel(COUNTER_FREQUENCY,
72 &iou_scntr_secure->base_frequency_id_register);
74 debug("counter val 0x%x\n",
75 readl(&iou_scntr_secure->base_frequency_id_register));
77 writel(IOU_SCNTRS_CONTROL_EN,
78 &iou_scntr_secure->counter_control_register);
80 debug("scntrs control 0x%x\n",
81 readl(&iou_scntr_secure->counter_control_register));
82 debug("timer 0x%llx\n", get_ticks());
83 debug("timer 0x%llx\n", get_ticks());
88 static u8 versal_get_bootmode(void)
93 reg = readl(&crp_base->boot_mode_usr);
95 if (reg >> BOOT_MODE_ALT_SHIFT)
96 reg >>= BOOT_MODE_ALT_SHIFT;
98 bootmode = reg & BOOT_MODES_MASK;
103 int board_late_init(void)
109 int env_targets_len = 0;
114 if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
115 debug("Saved variables - Skipping\n");
119 bootmode = versal_get_bootmode();
129 mode = "jtag pxe dhcp";
131 case QSPI_MODE_24BIT:
132 puts("QSPI_MODE_24\n");
135 case QSPI_MODE_32BIT:
136 puts("QSPI_MODE_32\n");
145 if (uclass_get_device_by_name(UCLASS_MMC,
146 "sdhci@f1050000", &dev)) {
147 puts("Boot from EMMC but without SD1 enabled!\n");
150 debug("mmc1 device found at %p, seq %d\n", dev, dev->seq);
156 if (uclass_get_device_by_name(UCLASS_MMC,
157 "sdhci@f1040000", &dev)) {
158 puts("Boot from SD0 but without SD0 enabled!\n");
161 debug("mmc0 device found at %p, seq %d\n", dev, dev->seq);
171 if (uclass_get_device_by_name(UCLASS_MMC,
172 "sdhci@f1050000", &dev)) {
173 puts("Boot from SD1 but without SD1 enabled!\n");
176 debug("mmc1 device found at %p, seq %d\n", dev, dev->seq);
183 printf("Invalid Boot Mode:0x%x\n", bootmode);
188 bootseq_len = snprintf(NULL, 0, "%i", bootseq);
189 debug("Bootseq len: %x\n", bootseq_len);
193 * One terminating char + one byte for space between mode
194 * and default boot_targets
196 env_targets = env_get("boot_targets");
198 env_targets_len = strlen(env_targets);
200 new_targets = calloc(1, strlen(mode) + env_targets_len + 2 +
206 sprintf(new_targets, "%s%x %s", mode, bootseq,
207 env_targets ? env_targets : "");
209 sprintf(new_targets, "%s %s", mode,
210 env_targets ? env_targets : "");
212 env_set("boot_targets", new_targets);
214 return board_late_init_xilinx();
217 int dram_init_banksize(void)
221 ret = fdtdec_setup_memory_banksize();
232 if (fdtdec_setup_mem_size_base() != 0)
238 void reset_cpu(ulong addr)