2018-08-22 12:55:27 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
|
|
|
* (C) Copyright 2014 - 2018 Xilinx, Inc.
|
|
|
|
* Michal Simek <michal.simek@xilinx.com>
|
|
|
|
*/
|
|
|
|
|
2023-01-20 05:36:16 +00:00
|
|
|
#include <command.h>
|
2018-08-22 12:55:27 +00:00
|
|
|
#include <common.h>
|
2019-12-28 17:45:01 +00:00
|
|
|
#include <cpu_func.h>
|
2020-05-10 17:40:03 +00:00
|
|
|
#include <env.h>
|
2018-08-22 12:55:27 +00:00
|
|
|
#include <fdtdec.h>
|
2019-11-14 19:57:46 +00:00
|
|
|
#include <init.h>
|
2021-02-23 15:07:46 +00:00
|
|
|
#include <env_internal.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2018-08-22 12:55:27 +00:00
|
|
|
#include <malloc.h>
|
2019-11-14 19:57:30 +00:00
|
|
|
#include <time.h>
|
2020-05-10 17:39:56 +00:00
|
|
|
#include <asm/cache.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2018-08-22 12:55:27 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/arch/hardware.h>
|
2019-04-29 16:39:09 +00:00
|
|
|
#include <asm/arch/sys_proto.h>
|
2019-01-31 11:58:14 +00:00
|
|
|
#include <dm/device.h>
|
|
|
|
#include <dm/uclass.h>
|
2019-08-05 10:24:59 +00:00
|
|
|
#include <versalpl.h>
|
2020-03-31 10:39:37 +00:00
|
|
|
#include "../common/board.h"
|
2018-08-22 12:55:27 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2019-08-05 10:24:59 +00:00
|
|
|
#if defined(CONFIG_FPGA_VERSALPL)
|
2022-07-22 14:16:04 +00:00
|
|
|
static xilinx_desc versalpl = {
|
|
|
|
xilinx_versal, csu_dma, 1, &versal_op, 0, &versal_op, NULL,
|
|
|
|
FPGA_LEGACY
|
|
|
|
};
|
2019-08-05 10:24:59 +00:00
|
|
|
#endif
|
|
|
|
|
2018-08-22 12:55:27 +00:00
|
|
|
int board_init(void)
|
|
|
|
{
|
|
|
|
printf("EL Level:\tEL%d\n", current_el());
|
|
|
|
|
2019-08-05 10:24:59 +00:00
|
|
|
#if defined(CONFIG_FPGA_VERSALPL)
|
|
|
|
fpga_init();
|
|
|
|
fpga_add(fpga_xilinx, &versalpl);
|
|
|
|
#endif
|
|
|
|
|
2020-08-03 11:01:45 +00:00
|
|
|
if (CONFIG_IS_ENABLED(DM_I2C) && CONFIG_IS_ENABLED(I2C_EEPROM))
|
|
|
|
xilinx_read_eeprom();
|
|
|
|
|
2018-08-22 12:55:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int board_early_init_r(void)
|
|
|
|
{
|
2019-01-28 10:08:00 +00:00
|
|
|
u32 val;
|
|
|
|
|
|
|
|
if (current_el() != 3)
|
|
|
|
return 0;
|
|
|
|
|
2019-01-28 10:12:41 +00:00
|
|
|
debug("iou_switch ctrl div0 %x\n",
|
|
|
|
readl(&crlapb_base->iou_switch_ctrl));
|
|
|
|
|
2019-01-28 10:08:00 +00:00
|
|
|
writel(IOU_SWITCH_CTRL_CLKACT_BIT |
|
2019-01-28 10:12:41 +00:00
|
|
|
(CONFIG_IOU_SWITCH_DIVISOR0 << IOU_SWITCH_CTRL_DIVISOR0_SHIFT),
|
2019-01-28 10:08:00 +00:00
|
|
|
&crlapb_base->iou_switch_ctrl);
|
|
|
|
|
|
|
|
/* Global timer init - Program time stamp reference clk */
|
|
|
|
val = readl(&crlapb_base->timestamp_ref_ctrl);
|
|
|
|
val |= CRL_APB_TIMESTAMP_REF_CTRL_CLKACT_BIT;
|
|
|
|
writel(val, &crlapb_base->timestamp_ref_ctrl);
|
|
|
|
|
|
|
|
debug("ref ctrl 0x%x\n",
|
|
|
|
readl(&crlapb_base->timestamp_ref_ctrl));
|
|
|
|
|
|
|
|
/* Clear reset of timestamp reg */
|
|
|
|
writel(0, &crlapb_base->rst_timestamp);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Program freq register in System counter and
|
|
|
|
* enable system counter.
|
|
|
|
*/
|
2022-04-13 09:47:17 +00:00
|
|
|
writel(CONFIG_COUNTER_FREQUENCY,
|
2019-01-28 10:08:00 +00:00
|
|
|
&iou_scntr_secure->base_frequency_id_register);
|
|
|
|
|
|
|
|
debug("counter val 0x%x\n",
|
|
|
|
readl(&iou_scntr_secure->base_frequency_id_register));
|
|
|
|
|
|
|
|
writel(IOU_SCNTRS_CONTROL_EN,
|
|
|
|
&iou_scntr_secure->counter_control_register);
|
|
|
|
|
|
|
|
debug("scntrs control 0x%x\n",
|
|
|
|
readl(&iou_scntr_secure->counter_control_register));
|
|
|
|
debug("timer 0x%llx\n", get_ticks());
|
|
|
|
debug("timer 0x%llx\n", get_ticks());
|
2018-08-22 12:55:27 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-05-06 05:53:45 +00:00
|
|
|
unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc,
|
|
|
|
char *const argv[])
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (current_el() > 1) {
|
|
|
|
smp_kick_all_cpus();
|
|
|
|
dcache_disable();
|
|
|
|
armv8_switch_to_el1(0x0, 0, 0, 0, (unsigned long)entry,
|
|
|
|
ES_TO_AARCH64);
|
|
|
|
} else {
|
|
|
|
printf("FAIL: current EL is not above EL1\n");
|
|
|
|
ret = EINVAL;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-04-08 09:04:41 +00:00
|
|
|
static u8 versal_get_bootmode(void)
|
2019-01-31 11:58:14 +00:00
|
|
|
{
|
2020-04-08 09:04:41 +00:00
|
|
|
u8 bootmode;
|
2019-01-31 11:58:14 +00:00
|
|
|
u32 reg = 0;
|
2020-04-08 09:04:41 +00:00
|
|
|
|
|
|
|
reg = readl(&crp_base->boot_mode_usr);
|
|
|
|
|
|
|
|
if (reg >> BOOT_MODE_ALT_SHIFT)
|
|
|
|
reg >>= BOOT_MODE_ALT_SHIFT;
|
|
|
|
|
|
|
|
bootmode = reg & BOOT_MODES_MASK;
|
|
|
|
|
|
|
|
return bootmode;
|
|
|
|
}
|
|
|
|
|
|
|
|
int board_late_init(void)
|
|
|
|
{
|
2019-01-31 11:58:14 +00:00
|
|
|
u8 bootmode;
|
|
|
|
struct udevice *dev;
|
|
|
|
int bootseq = -1;
|
|
|
|
int bootseq_len = 0;
|
|
|
|
int env_targets_len = 0;
|
|
|
|
const char *mode;
|
|
|
|
char *new_targets;
|
|
|
|
char *env_targets;
|
|
|
|
|
|
|
|
if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
|
|
|
|
debug("Saved variables - Skipping\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-28 10:45:47 +00:00
|
|
|
if (!CONFIG_IS_ENABLED(ENV_VARS_UBOOT_RUNTIME_CONFIG))
|
|
|
|
return 0;
|
|
|
|
|
2020-04-08 09:04:41 +00:00
|
|
|
bootmode = versal_get_bootmode();
|
2019-01-31 11:58:14 +00:00
|
|
|
|
|
|
|
puts("Bootmode: ");
|
|
|
|
switch (bootmode) {
|
2019-07-11 10:37:57 +00:00
|
|
|
case USB_MODE:
|
|
|
|
puts("USB_MODE\n");
|
2021-03-31 05:24:57 +00:00
|
|
|
mode = "usb_dfu0 usb_dfu1";
|
2019-07-11 10:37:57 +00:00
|
|
|
break;
|
2019-01-31 11:58:14 +00:00
|
|
|
case JTAG_MODE:
|
|
|
|
puts("JTAG_MODE\n");
|
2019-06-25 11:43:14 +00:00
|
|
|
mode = "jtag pxe dhcp";
|
2019-01-31 11:58:14 +00:00
|
|
|
break;
|
|
|
|
case QSPI_MODE_24BIT:
|
|
|
|
puts("QSPI_MODE_24\n");
|
|
|
|
mode = "xspi0";
|
|
|
|
break;
|
|
|
|
case QSPI_MODE_32BIT:
|
|
|
|
puts("QSPI_MODE_32\n");
|
|
|
|
mode = "xspi0";
|
|
|
|
break;
|
|
|
|
case OSPI_MODE:
|
|
|
|
puts("OSPI_MODE\n");
|
|
|
|
mode = "xspi0";
|
|
|
|
break;
|
|
|
|
case EMMC_MODE:
|
|
|
|
puts("EMMC_MODE\n");
|
2019-12-16 11:44:26 +00:00
|
|
|
if (uclass_get_device_by_name(UCLASS_MMC,
|
2021-11-18 11:57:20 +00:00
|
|
|
"mmc@f1050000", &dev) &&
|
|
|
|
uclass_get_device_by_name(UCLASS_MMC,
|
2019-12-16 11:44:26 +00:00
|
|
|
"sdhci@f1050000", &dev)) {
|
|
|
|
puts("Boot from EMMC but without SD1 enabled!\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2020-12-17 04:20:07 +00:00
|
|
|
debug("mmc1 device found at %p, seq %d\n", dev, dev_seq(dev));
|
2019-12-16 11:44:26 +00:00
|
|
|
mode = "mmc";
|
2020-12-17 04:20:07 +00:00
|
|
|
bootseq = dev_seq(dev);
|
2019-01-31 11:58:14 +00:00
|
|
|
break;
|
|
|
|
case SD_MODE:
|
|
|
|
puts("SD_MODE\n");
|
|
|
|
if (uclass_get_device_by_name(UCLASS_MMC,
|
2021-11-18 11:57:20 +00:00
|
|
|
"mmc@f1040000", &dev) &&
|
|
|
|
uclass_get_device_by_name(UCLASS_MMC,
|
2019-01-31 11:58:14 +00:00
|
|
|
"sdhci@f1040000", &dev)) {
|
|
|
|
puts("Boot from SD0 but without SD0 enabled!\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2020-12-17 04:20:07 +00:00
|
|
|
debug("mmc0 device found at %p, seq %d\n", dev, dev_seq(dev));
|
2019-01-31 11:58:14 +00:00
|
|
|
|
|
|
|
mode = "mmc";
|
2020-12-17 04:20:07 +00:00
|
|
|
bootseq = dev_seq(dev);
|
2019-01-31 11:58:14 +00:00
|
|
|
break;
|
|
|
|
case SD1_LSHFT_MODE:
|
|
|
|
puts("LVL_SHFT_");
|
|
|
|
/* fall through */
|
|
|
|
case SD_MODE1:
|
|
|
|
puts("SD_MODE1\n");
|
|
|
|
if (uclass_get_device_by_name(UCLASS_MMC,
|
2021-11-18 11:57:20 +00:00
|
|
|
"mmc@f1050000", &dev) &&
|
|
|
|
uclass_get_device_by_name(UCLASS_MMC,
|
2019-01-31 11:58:14 +00:00
|
|
|
"sdhci@f1050000", &dev)) {
|
|
|
|
puts("Boot from SD1 but without SD1 enabled!\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2020-12-17 04:20:07 +00:00
|
|
|
debug("mmc1 device found at %p, seq %d\n", dev, dev_seq(dev));
|
2019-01-31 11:58:14 +00:00
|
|
|
|
|
|
|
mode = "mmc";
|
2020-12-17 04:20:07 +00:00
|
|
|
bootseq = dev_seq(dev);
|
2019-01-31 11:58:14 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mode = "";
|
|
|
|
printf("Invalid Boot Mode:0x%x\n", bootmode);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bootseq >= 0) {
|
|
|
|
bootseq_len = snprintf(NULL, 0, "%i", bootseq);
|
|
|
|
debug("Bootseq len: %x\n", bootseq_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* One terminating char + one byte for space between mode
|
|
|
|
* and default boot_targets
|
|
|
|
*/
|
|
|
|
env_targets = env_get("boot_targets");
|
|
|
|
if (env_targets)
|
|
|
|
env_targets_len = strlen(env_targets);
|
|
|
|
|
|
|
|
new_targets = calloc(1, strlen(mode) + env_targets_len + 2 +
|
|
|
|
bootseq_len);
|
|
|
|
if (!new_targets)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
if (bootseq >= 0)
|
|
|
|
sprintf(new_targets, "%s%x %s", mode, bootseq,
|
|
|
|
env_targets ? env_targets : "");
|
|
|
|
else
|
|
|
|
sprintf(new_targets, "%s %s", mode,
|
|
|
|
env_targets ? env_targets : "");
|
|
|
|
|
|
|
|
env_set("boot_targets", new_targets);
|
|
|
|
|
2020-03-31 10:39:37 +00:00
|
|
|
return board_late_init_xilinx();
|
2019-01-31 11:58:14 +00:00
|
|
|
}
|
|
|
|
|
2018-08-22 12:55:27 +00:00
|
|
|
int dram_init_banksize(void)
|
|
|
|
{
|
2019-04-29 16:39:09 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = fdtdec_setup_memory_banksize();
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
mem_map_fill();
|
2018-08-22 12:55:27 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int dram_init(void)
|
|
|
|
{
|
2020-07-10 10:42:09 +00:00
|
|
|
if (fdtdec_setup_mem_size_base_lowest() != 0)
|
2018-08-22 12:55:27 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-12-15 15:47:52 +00:00
|
|
|
void reset_cpu(void)
|
2018-08-22 12:55:27 +00:00
|
|
|
{
|
|
|
|
}
|
2021-02-23 15:07:46 +00:00
|
|
|
|
|
|
|
enum env_location env_get_location(enum env_operation op, int prio)
|
|
|
|
{
|
|
|
|
u32 bootmode = versal_get_bootmode();
|
|
|
|
|
|
|
|
if (prio)
|
|
|
|
return ENVL_UNKNOWN;
|
|
|
|
|
|
|
|
switch (bootmode) {
|
|
|
|
case EMMC_MODE:
|
|
|
|
case SD_MODE:
|
|
|
|
case SD1_LSHFT_MODE:
|
|
|
|
case SD_MODE1:
|
|
|
|
if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT))
|
|
|
|
return ENVL_FAT;
|
|
|
|
if (IS_ENABLED(CONFIG_ENV_IS_IN_EXT4))
|
|
|
|
return ENVL_EXT4;
|
2021-11-24 11:16:55 +00:00
|
|
|
return ENVL_NOWHERE;
|
2021-02-23 15:07:46 +00:00
|
|
|
case OSPI_MODE:
|
|
|
|
case QSPI_MODE_24BIT:
|
|
|
|
case QSPI_MODE_32BIT:
|
|
|
|
if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))
|
|
|
|
return ENVL_SPI_FLASH;
|
2021-11-24 11:16:55 +00:00
|
|
|
return ENVL_NOWHERE;
|
2021-02-23 15:07:46 +00:00
|
|
|
case JTAG_MODE:
|
|
|
|
default:
|
|
|
|
return ENVL_NOWHERE;
|
|
|
|
}
|
|
|
|
}
|