2015-01-15 18:01:51 +09:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2014 - 2015 Xilinx, Inc.
|
|
|
|
* Michal Simek <michal.simek@xilinx.com>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2015-10-01 00:26:55 +09:00
|
|
|
#include <sata.h>
|
2015-07-23 20:27:40 +09:00
|
|
|
#include <ahci.h>
|
|
|
|
#include <scsi.h>
|
2016-04-22 21:28:54 +09:00
|
|
|
#include <malloc.h>
|
2015-11-05 16:34:35 +09:00
|
|
|
#include <asm/arch/clk.h>
|
2015-01-15 18:01:51 +09:00
|
|
|
#include <asm/arch/hardware.h>
|
|
|
|
#include <asm/arch/sys_proto.h>
|
|
|
|
#include <asm/io.h>
|
2015-08-04 16:33:26 +09:00
|
|
|
#include <usb.h>
|
|
|
|
#include <dwc3-uboot.h>
|
2016-02-01 23:05:58 +09:00
|
|
|
#include <zynqmppl.h>
|
2016-04-22 18:48:49 +09:00
|
|
|
#include <i2c.h>
|
2016-09-01 18:16:40 +09:00
|
|
|
#include <g_dnl.h>
|
2015-01-15 18:01:51 +09:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2016-02-01 23:05:58 +09: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",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2017-07-25 15:21:36 +09:00
|
|
|
static int chip_id(unsigned char id)
|
2016-02-01 23:05:58 +09:00
|
|
|
{
|
|
|
|
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;
|
2017-07-25 15:21:36 +09:00
|
|
|
int val = -EINVAL;
|
2016-02-01 23:05:58 +09:00
|
|
|
|
|
|
|
smc_call(®s);
|
|
|
|
|
2016-09-30 03:44:41 +09: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
|
|
|
|
*/
|
2017-07-25 15:21:36 +09:00
|
|
|
switch (id) {
|
|
|
|
case IDCODE:
|
|
|
|
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;
|
|
|
|
val = regs.regs[0];
|
|
|
|
break;
|
|
|
|
case VERSION:
|
|
|
|
regs.regs[1] = lower_32_bits(regs.regs[1]);
|
|
|
|
regs.regs[1] &= ZYNQMP_CSU_SILICON_VER_MASK;
|
|
|
|
val = regs.regs[1];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("%s, Invalid Req:0x%x\n", __func__, id);
|
|
|
|
}
|
2016-09-30 03:44:41 +09:00
|
|
|
|
2017-07-25 15:21:36 +09:00
|
|
|
return val;
|
2016-02-01 23:05:58 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *zynqmp_get_silicon_idcode_name(void)
|
|
|
|
{
|
|
|
|
uint32_t i, id;
|
|
|
|
|
2017-07-25 15:21:36 +09:00
|
|
|
id = chip_id(IDCODE);
|
2016-02-01 23:05:58 +09:00
|
|
|
for (i = 0; i < ARRAY_SIZE(zynqmp_devices); i++) {
|
|
|
|
if (zynqmp_devices[i].id == id)
|
|
|
|
return zynqmp_devices[i].name;
|
|
|
|
}
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-02-07 22:32:26 +09:00
|
|
|
int board_early_init_f(void)
|
|
|
|
{
|
|
|
|
#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_CLK_ZYNQMP)
|
|
|
|
zynqmp_pmufw_version();
|
|
|
|
#endif
|
2017-07-12 20:08:41 +09:00
|
|
|
|
2017-07-12 20:21:27 +09:00
|
|
|
#if defined(CONFIG_SPL_BUILD) || defined(CONFIG_ZYNQMP_PSU_INIT_ENABLED)
|
2017-07-12 20:08:41 +09:00
|
|
|
psu_init();
|
|
|
|
#endif
|
|
|
|
|
2017-02-07 22:32:26 +09:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-01 23:05:58 +09:00
|
|
|
#define ZYNQMP_VERSION_SIZE 9
|
|
|
|
|
2015-01-15 18:01:51 +09:00
|
|
|
int board_init(void)
|
|
|
|
{
|
2015-06-22 21:31:06 +09:00
|
|
|
printf("EL Level:\tEL%d\n", current_el());
|
|
|
|
|
2016-02-01 23:05:58 +09: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 18:01:51 +09:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int board_early_init_r(void)
|
|
|
|
{
|
|
|
|
u32 val;
|
|
|
|
|
2017-07-12 17:32:18 +09:00
|
|
|
val = readl(&crlapb_base->timestamp_ref_ctrl);
|
|
|
|
val &= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
|
|
|
|
|
|
|
|
if (current_el() == 3 && !val) {
|
2015-11-05 16:34:35 +09:00
|
|
|
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 18:01:51 +09:00
|
|
|
|
2015-11-05 16:34:35 +09: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 18:01:51 +09:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-22 18:48:49 +09: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 17:34:53 +09:00
|
|
|
#if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE)
|
2017-03-31 23:40:32 +09:00
|
|
|
int dram_init_banksize(void)
|
2016-12-09 21:56:54 +09:00
|
|
|
{
|
2016-12-18 23:03:34 +09:00
|
|
|
fdtdec_setup_memory_banksize();
|
2017-03-31 23:40:32 +09:00
|
|
|
|
|
|
|
return 0;
|
2016-12-07 00:31:53 +09:00
|
|
|
}
|
2016-02-08 17:34:53 +09:00
|
|
|
|
2016-12-09 21:56:54 +09:00
|
|
|
int dram_init(void)
|
2016-12-07 00:31:53 +09:00
|
|
|
{
|
2016-12-18 23:03:34 +09:00
|
|
|
if (fdtdec_setup_memory_size() != 0)
|
|
|
|
return -EINVAL;
|
2016-12-07 00:31:53 +09:00
|
|
|
|
2016-12-09 21:56:54 +09:00
|
|
|
return 0;
|
2016-02-08 17:34:53 +09:00
|
|
|
}
|
|
|
|
#else
|
2015-01-15 18:01:51 +09:00
|
|
|
int dram_init(void)
|
|
|
|
{
|
|
|
|
gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2016-02-08 17:34:53 +09:00
|
|
|
#endif
|
2015-01-15 18:01:51 +09:00
|
|
|
|
|
|
|
void reset_cpu(ulong addr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int board_late_init(void)
|
|
|
|
{
|
|
|
|
u32 reg = 0;
|
|
|
|
u8 bootmode;
|
2016-04-22 21:28:54 +09:00
|
|
|
const char *mode;
|
|
|
|
char *new_targets;
|
|
|
|
|
|
|
|
if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
|
|
|
|
debug("Saved variables - Skipping\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2015-01-15 18:01:51 +09:00
|
|
|
|
|
|
|
reg = readl(&crlapb_base->boot_mode);
|
2016-10-25 18:43:02 +09:00
|
|
|
if (reg >> BOOT_MODE_ALT_SHIFT)
|
|
|
|
reg >>= BOOT_MODE_ALT_SHIFT;
|
|
|
|
|
2015-01-15 18:01:51 +09:00
|
|
|
bootmode = reg & BOOT_MODES_MASK;
|
|
|
|
|
2015-09-21 00:20:42 +09:00
|
|
|
puts("Bootmode: ");
|
2015-01-15 18:01:51 +09:00
|
|
|
switch (bootmode) {
|
2016-08-19 21:14:52 +09:00
|
|
|
case USB_MODE:
|
|
|
|
puts("USB_MODE\n");
|
|
|
|
mode = "usb";
|
|
|
|
break;
|
2015-03-13 14:40:26 +09:00
|
|
|
case JTAG_MODE:
|
2015-09-21 00:20:42 +09:00
|
|
|
puts("JTAG_MODE\n");
|
2016-04-22 21:28:54 +09:00
|
|
|
mode = "pxe dhcp";
|
2015-03-13 14:40:26 +09:00
|
|
|
break;
|
|
|
|
case QSPI_MODE_24BIT:
|
|
|
|
case QSPI_MODE_32BIT:
|
2016-04-22 21:28:54 +09:00
|
|
|
mode = "qspi0";
|
2015-09-21 00:20:42 +09:00
|
|
|
puts("QSPI_MODE\n");
|
2015-03-13 14:40:26 +09:00
|
|
|
break;
|
2015-04-15 22:02:28 +09:00
|
|
|
case EMMC_MODE:
|
2015-10-05 22:59:38 +09:00
|
|
|
puts("EMMC_MODE\n");
|
2016-04-22 21:28:54 +09:00
|
|
|
mode = "mmc0";
|
2015-10-05 22:59:38 +09:00
|
|
|
break;
|
|
|
|
case SD_MODE:
|
2015-09-21 00:20:42 +09:00
|
|
|
puts("SD_MODE\n");
|
2016-04-22 21:28:54 +09:00
|
|
|
mode = "mmc0";
|
2015-01-15 18:01:51 +09:00
|
|
|
break;
|
2016-09-21 15:15:05 +09:00
|
|
|
case SD1_LSHFT_MODE:
|
|
|
|
puts("LVL_SHFT_");
|
|
|
|
/* fall through */
|
2015-10-05 17:51:12 +09:00
|
|
|
case SD_MODE1:
|
2015-09-21 00:20:42 +09:00
|
|
|
puts("SD_MODE1\n");
|
2015-11-06 18:22:37 +09:00
|
|
|
#if defined(CONFIG_ZYNQ_SDHCI0) && defined(CONFIG_ZYNQ_SDHCI1)
|
2016-04-22 21:28:54 +09:00
|
|
|
mode = "mmc1";
|
|
|
|
#else
|
|
|
|
mode = "mmc0";
|
2015-11-06 18:22:37 +09:00
|
|
|
#endif
|
2015-10-05 17:51:12 +09:00
|
|
|
break;
|
|
|
|
case NAND_MODE:
|
2015-09-21 00:20:42 +09:00
|
|
|
puts("NAND_MODE\n");
|
2016-04-22 21:28:54 +09:00
|
|
|
mode = "nand0";
|
2015-10-05 17:51:12 +09:00
|
|
|
break;
|
2015-01-15 18:01:51 +09:00
|
|
|
default:
|
2016-04-22 21:28:54 +09:00
|
|
|
mode = "";
|
2015-01-15 18:01:51 +09:00
|
|
|
printf("Invalid Boot Mode:0x%x\n", bootmode);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-04-22 21:28:54 +09: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 18:01:51 +09:00
|
|
|
return 0;
|
|
|
|
}
|
2015-08-04 16:31:05 +09:00
|
|
|
|
|
|
|
int checkboard(void)
|
|
|
|
{
|
2016-01-25 19:04:21 +09:00
|
|
|
puts("Board: Xilinx ZynqMP\n");
|
2015-08-04 16:31:05 +09:00
|
|
|
return 0;
|
|
|
|
}
|
2015-08-04 16:33:26 +09:00
|
|
|
|
|
|
|
#ifdef CONFIG_USB_DWC3
|
2016-08-08 17:11:26 +09:00
|
|
|
static struct dwc3_device dwc3_device_data0 = {
|
2015-08-04 16:33:26 +09:00
|
|
|
.maximum_speed = USB_SPEED_HIGH,
|
|
|
|
.base = ZYNQMP_USB0_XHCI_BASEADDR,
|
|
|
|
.dr_mode = USB_DR_MODE_PERIPHERAL,
|
|
|
|
.index = 0,
|
|
|
|
};
|
|
|
|
|
2016-08-08 17:11:26 +09: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 18:16:40 +09:00
|
|
|
int usb_gadget_handle_interrupts(int index)
|
2015-08-04 16:33:26 +09:00
|
|
|
{
|
2016-09-01 18:16:40 +09:00
|
|
|
dwc3_uboot_handle_interrupt(index);
|
2015-08-04 16:33:26 +09:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int board_usb_init(int index, enum usb_init_type init)
|
|
|
|
{
|
2016-08-08 17:11:26 +09:00
|
|
|
debug("%s: index %x\n", __func__, index);
|
|
|
|
|
2016-09-01 18:27:32 +09:00
|
|
|
#if defined(CONFIG_USB_GADGET_DOWNLOAD)
|
|
|
|
g_dnl_set_serialnumber(CONFIG_SYS_CONFIG_NAME);
|
|
|
|
#endif
|
|
|
|
|
2016-08-08 17:11:26 +09: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 16:33:26 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
int board_usb_cleanup(int index, enum usb_init_type init)
|
|
|
|
{
|
|
|
|
dwc3_uboot_exit(index);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|