2015-01-15 09:01:51 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2014 - 2015 Xilinx, Inc.
|
|
|
|
* Michal Simek <michal.simek@xilinx.com>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2015-09-30 15:26:55 +00:00
|
|
|
#include <sata.h>
|
2015-07-23 11:27:40 +00:00
|
|
|
#include <ahci.h>
|
|
|
|
#include <scsi.h>
|
2016-04-22 12:28:54 +00:00
|
|
|
#include <malloc.h>
|
2015-11-05 07:34:35 +00:00
|
|
|
#include <asm/arch/clk.h>
|
2015-01-15 09:01:51 +00:00
|
|
|
#include <asm/arch/hardware.h>
|
|
|
|
#include <asm/arch/sys_proto.h>
|
|
|
|
#include <asm/io.h>
|
2015-08-04 07:33:26 +00:00
|
|
|
#include <usb.h>
|
|
|
|
#include <dwc3-uboot.h>
|
2016-02-01 14:05:58 +00:00
|
|
|
#include <zynqmppl.h>
|
2016-04-22 09:48:49 +00:00
|
|
|
#include <i2c.h>
|
2016-09-01 09:16:40 +00:00
|
|
|
#include <g_dnl.h>
|
2015-01-15 09:01:51 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2016-02-01 14:05:58 +00:00
|
|
|
#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
|
|
|
|
!defined(CONFIG_SPL_BUILD)
|
|
|
|
static xilinx_desc zynqmppl = XILINX_ZYNQMP_DESC;
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
uint32_t id;
|
|
|
|
char *name;
|
|
|
|
} zynqmp_devices[] = {
|
|
|
|
{
|
|
|
|
.id = 0x10,
|
|
|
|
.name = "3eg",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = 0x11,
|
|
|
|
.name = "2eg",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = 0x20,
|
|
|
|
.name = "5ev",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = 0x21,
|
|
|
|
.name = "4ev",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = 0x30,
|
|
|
|
.name = "7ev",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = 0x38,
|
|
|
|
.name = "9eg",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = 0x39,
|
|
|
|
.name = "6eg",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = 0x40,
|
|
|
|
.name = "11eg",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = 0x50,
|
|
|
|
.name = "15eg",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = 0x58,
|
|
|
|
.name = "19eg",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = 0x59,
|
|
|
|
.name = "17eg",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int chip_id(void)
|
|
|
|
{
|
|
|
|
struct pt_regs regs;
|
|
|
|
regs.regs[0] = ZYNQMP_SIP_SVC_CSU_DMA_CHIPID;
|
|
|
|
regs.regs[1] = 0;
|
|
|
|
regs.regs[2] = 0;
|
|
|
|
regs.regs[3] = 0;
|
|
|
|
|
|
|
|
smc_call(®s);
|
|
|
|
|
2016-09-29 18:44:41 +00:00
|
|
|
/*
|
|
|
|
* SMC returns:
|
|
|
|
* regs[0][31:0] = status of the operation
|
|
|
|
* regs[0][63:32] = CSU.IDCODE register
|
|
|
|
* regs[1][31:0] = CSU.version register
|
|
|
|
*/
|
|
|
|
regs.regs[0] = upper_32_bits(regs.regs[0]);
|
|
|
|
regs.regs[0] &= ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK |
|
|
|
|
ZYNQMP_CSU_IDCODE_SVD_MASK;
|
|
|
|
regs.regs[0] >>= ZYNQMP_CSU_IDCODE_SVD_SHIFT;
|
|
|
|
|
2016-02-01 14:05:58 +00:00
|
|
|
return regs.regs[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *zynqmp_get_silicon_idcode_name(void)
|
|
|
|
{
|
|
|
|
uint32_t i, id;
|
|
|
|
|
|
|
|
id = chip_id();
|
|
|
|
for (i = 0; i < ARRAY_SIZE(zynqmp_devices); i++) {
|
|
|
|
if (zynqmp_devices[i].id == id)
|
|
|
|
return zynqmp_devices[i].name;
|
|
|
|
}
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define ZYNQMP_VERSION_SIZE 9
|
|
|
|
|
2015-01-15 09:01:51 +00:00
|
|
|
int board_init(void)
|
|
|
|
{
|
2015-06-22 12:31:06 +00:00
|
|
|
printf("EL Level:\tEL%d\n", current_el());
|
|
|
|
|
2016-02-01 14:05:58 +00:00
|
|
|
#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
|
|
|
|
!defined(CONFIG_SPL_BUILD) || (defined(CONFIG_SPL_FPGA_SUPPORT) && \
|
|
|
|
defined(CONFIG_SPL_BUILD))
|
|
|
|
if (current_el() != 3) {
|
|
|
|
static char version[ZYNQMP_VERSION_SIZE];
|
|
|
|
|
|
|
|
strncat(version, "xczu", ZYNQMP_VERSION_SIZE);
|
|
|
|
zynqmppl.name = strncat(version,
|
|
|
|
zynqmp_get_silicon_idcode_name(),
|
|
|
|
ZYNQMP_VERSION_SIZE);
|
|
|
|
printf("Chip ID:\t%s\n", zynqmppl.name);
|
|
|
|
fpga_init();
|
|
|
|
fpga_add(fpga_xilinx, &zynqmppl);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-01-15 09:01:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int board_early_init_r(void)
|
|
|
|
{
|
|
|
|
u32 val;
|
|
|
|
|
2015-11-05 07:34:35 +00:00
|
|
|
if (current_el() == 3) {
|
|
|
|
val = readl(&crlapb_base->timestamp_ref_ctrl);
|
|
|
|
val |= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
|
|
|
|
writel(val, &crlapb_base->timestamp_ref_ctrl);
|
2015-01-15 09:01:51 +00:00
|
|
|
|
2015-11-05 07:34:35 +00:00
|
|
|
/* Program freq register in System counter */
|
|
|
|
writel(zynqmp_get_system_timer_freq(),
|
|
|
|
&iou_scntr_secure->base_frequency_id_register);
|
|
|
|
/* And enable system counter */
|
|
|
|
writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN,
|
|
|
|
&iou_scntr_secure->counter_control_register);
|
|
|
|
}
|
2015-01-15 09:01:51 +00:00
|
|
|
/* Program freq register in System counter and enable system counter */
|
|
|
|
writel(gd->cpu_clk, &iou_scntr->base_frequency_id_register);
|
|
|
|
writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_HDBG |
|
|
|
|
ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN,
|
|
|
|
&iou_scntr->counter_control_register);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-22 09:48:49 +00:00
|
|
|
int zynq_board_read_rom_ethaddr(unsigned char *ethaddr)
|
|
|
|
{
|
|
|
|
#if defined(CONFIG_ZYNQ_GEM_EEPROM_ADDR) && \
|
|
|
|
defined(CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET) && \
|
|
|
|
defined(CONFIG_ZYNQ_EEPROM_BUS)
|
|
|
|
i2c_set_bus_num(CONFIG_ZYNQ_EEPROM_BUS);
|
|
|
|
|
|
|
|
if (eeprom_read(CONFIG_ZYNQ_GEM_EEPROM_ADDR,
|
|
|
|
CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET,
|
|
|
|
ethaddr, 6))
|
|
|
|
printf("I2C EEPROM MAC address read failed\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-08 08:34:53 +00:00
|
|
|
#if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE)
|
2017-03-31 14:40:32 +00:00
|
|
|
int dram_init_banksize(void)
|
2016-12-09 12:56:54 +00:00
|
|
|
{
|
2016-12-18 14:03:34 +00:00
|
|
|
fdtdec_setup_memory_banksize();
|
2017-03-31 14:40:32 +00:00
|
|
|
|
|
|
|
return 0;
|
2016-12-06 15:31:53 +00:00
|
|
|
}
|
2016-02-08 08:34:53 +00:00
|
|
|
|
2016-12-09 12:56:54 +00:00
|
|
|
int dram_init(void)
|
2016-12-06 15:31:53 +00:00
|
|
|
{
|
2016-12-18 14:03:34 +00:00
|
|
|
if (fdtdec_setup_memory_size() != 0)
|
|
|
|
return -EINVAL;
|
2016-12-06 15:31:53 +00:00
|
|
|
|
2016-12-09 12:56:54 +00:00
|
|
|
return 0;
|
2016-02-08 08:34:53 +00:00
|
|
|
}
|
|
|
|
#else
|
2015-01-15 09:01:51 +00:00
|
|
|
int dram_init(void)
|
|
|
|
{
|
|
|
|
gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2016-02-08 08:34:53 +00:00
|
|
|
#endif
|
2015-01-15 09:01:51 +00:00
|
|
|
|
|
|
|
void reset_cpu(ulong addr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int board_late_init(void)
|
|
|
|
{
|
|
|
|
u32 reg = 0;
|
|
|
|
u8 bootmode;
|
2016-04-22 12:28:54 +00:00
|
|
|
const char *mode;
|
|
|
|
char *new_targets;
|
|
|
|
|
|
|
|
if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
|
|
|
|
debug("Saved variables - Skipping\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2015-01-15 09:01:51 +00:00
|
|
|
|
|
|
|
reg = readl(&crlapb_base->boot_mode);
|
2016-10-25 09:43:02 +00:00
|
|
|
if (reg >> BOOT_MODE_ALT_SHIFT)
|
|
|
|
reg >>= BOOT_MODE_ALT_SHIFT;
|
|
|
|
|
2015-01-15 09:01:51 +00:00
|
|
|
bootmode = reg & BOOT_MODES_MASK;
|
|
|
|
|
2015-09-20 15:20:42 +00:00
|
|
|
puts("Bootmode: ");
|
2015-01-15 09:01:51 +00:00
|
|
|
switch (bootmode) {
|
2016-08-19 12:14:52 +00:00
|
|
|
case USB_MODE:
|
|
|
|
puts("USB_MODE\n");
|
|
|
|
mode = "usb";
|
|
|
|
break;
|
2015-03-13 05:40:26 +00:00
|
|
|
case JTAG_MODE:
|
2015-09-20 15:20:42 +00:00
|
|
|
puts("JTAG_MODE\n");
|
2016-04-22 12:28:54 +00:00
|
|
|
mode = "pxe dhcp";
|
2015-03-13 05:40:26 +00:00
|
|
|
break;
|
|
|
|
case QSPI_MODE_24BIT:
|
|
|
|
case QSPI_MODE_32BIT:
|
2016-04-22 12:28:54 +00:00
|
|
|
mode = "qspi0";
|
2015-09-20 15:20:42 +00:00
|
|
|
puts("QSPI_MODE\n");
|
2015-03-13 05:40:26 +00:00
|
|
|
break;
|
2015-04-15 13:02:28 +00:00
|
|
|
case EMMC_MODE:
|
2015-10-05 13:59:38 +00:00
|
|
|
puts("EMMC_MODE\n");
|
2016-04-22 12:28:54 +00:00
|
|
|
mode = "mmc0";
|
2015-10-05 13:59:38 +00:00
|
|
|
break;
|
|
|
|
case SD_MODE:
|
2015-09-20 15:20:42 +00:00
|
|
|
puts("SD_MODE\n");
|
2016-04-22 12:28:54 +00:00
|
|
|
mode = "mmc0";
|
2015-01-15 09:01:51 +00:00
|
|
|
break;
|
2016-09-21 06:15:05 +00:00
|
|
|
case SD1_LSHFT_MODE:
|
|
|
|
puts("LVL_SHFT_");
|
|
|
|
/* fall through */
|
2015-10-05 08:51:12 +00:00
|
|
|
case SD_MODE1:
|
2015-09-20 15:20:42 +00:00
|
|
|
puts("SD_MODE1\n");
|
2015-11-06 09:22:37 +00:00
|
|
|
#if defined(CONFIG_ZYNQ_SDHCI0) && defined(CONFIG_ZYNQ_SDHCI1)
|
2016-04-22 12:28:54 +00:00
|
|
|
mode = "mmc1";
|
|
|
|
#else
|
|
|
|
mode = "mmc0";
|
2015-11-06 09:22:37 +00:00
|
|
|
#endif
|
2015-10-05 08:51:12 +00:00
|
|
|
break;
|
|
|
|
case NAND_MODE:
|
2015-09-20 15:20:42 +00:00
|
|
|
puts("NAND_MODE\n");
|
2016-04-22 12:28:54 +00:00
|
|
|
mode = "nand0";
|
2015-10-05 08:51:12 +00:00
|
|
|
break;
|
2015-01-15 09:01:51 +00:00
|
|
|
default:
|
2016-04-22 12:28:54 +00:00
|
|
|
mode = "";
|
2015-01-15 09:01:51 +00:00
|
|
|
printf("Invalid Boot Mode:0x%x\n", bootmode);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-04-22 12:28:54 +00:00
|
|
|
/*
|
|
|
|
* One terminating char + one byte for space between mode
|
|
|
|
* and default boot_targets
|
|
|
|
*/
|
|
|
|
new_targets = calloc(1, strlen(mode) +
|
|
|
|
strlen(getenv("boot_targets")) + 2);
|
|
|
|
|
|
|
|
sprintf(new_targets, "%s %s", mode, getenv("boot_targets"));
|
|
|
|
setenv("boot_targets", new_targets);
|
|
|
|
|
2015-01-15 09:01:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2015-08-04 07:31:05 +00:00
|
|
|
|
|
|
|
int checkboard(void)
|
|
|
|
{
|
2016-01-25 10:04:21 +00:00
|
|
|
puts("Board: Xilinx ZynqMP\n");
|
2015-08-04 07:31:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2015-08-04 07:33:26 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_USB_DWC3
|
2016-08-08 08:11:26 +00:00
|
|
|
static struct dwc3_device dwc3_device_data0 = {
|
2015-08-04 07:33:26 +00:00
|
|
|
.maximum_speed = USB_SPEED_HIGH,
|
|
|
|
.base = ZYNQMP_USB0_XHCI_BASEADDR,
|
|
|
|
.dr_mode = USB_DR_MODE_PERIPHERAL,
|
|
|
|
.index = 0,
|
|
|
|
};
|
|
|
|
|
2016-08-08 08:11:26 +00:00
|
|
|
static struct dwc3_device dwc3_device_data1 = {
|
|
|
|
.maximum_speed = USB_SPEED_HIGH,
|
|
|
|
.base = ZYNQMP_USB1_XHCI_BASEADDR,
|
|
|
|
.dr_mode = USB_DR_MODE_PERIPHERAL,
|
|
|
|
.index = 1,
|
|
|
|
};
|
|
|
|
|
2016-09-01 09:16:40 +00:00
|
|
|
int usb_gadget_handle_interrupts(int index)
|
2015-08-04 07:33:26 +00:00
|
|
|
{
|
2016-09-01 09:16:40 +00:00
|
|
|
dwc3_uboot_handle_interrupt(index);
|
2015-08-04 07:33:26 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int board_usb_init(int index, enum usb_init_type init)
|
|
|
|
{
|
2016-08-08 08:11:26 +00:00
|
|
|
debug("%s: index %x\n", __func__, index);
|
|
|
|
|
2016-09-01 09:27:32 +00:00
|
|
|
#if defined(CONFIG_USB_GADGET_DOWNLOAD)
|
|
|
|
g_dnl_set_serialnumber(CONFIG_SYS_CONFIG_NAME);
|
|
|
|
#endif
|
|
|
|
|
2016-08-08 08:11:26 +00:00
|
|
|
switch (index) {
|
|
|
|
case 0:
|
|
|
|
return dwc3_uboot_init(&dwc3_device_data0);
|
|
|
|
case 1:
|
|
|
|
return dwc3_uboot_init(&dwc3_device_data1);
|
|
|
|
};
|
|
|
|
|
|
|
|
return -1;
|
2015-08-04 07:33:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int board_usb_cleanup(int index, enum usb_init_type init)
|
|
|
|
{
|
|
|
|
dwc3_uboot_exit(index);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|