2 * (C) Copyright 2014 - 2015 Xilinx, Inc.
3 * Michal Simek <michal.simek@xilinx.com>
5 * SPDX-License-Identifier: GPL-2.0+
13 #include <asm/arch/clk.h>
14 #include <asm/arch/hardware.h>
15 #include <asm/arch/sys_proto.h>
18 #include <dwc3-uboot.h>
23 DECLARE_GLOBAL_DATA_PTR;
25 #if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
26 !defined(CONFIG_SPL_BUILD)
27 static xilinx_desc zynqmppl = XILINX_ZYNQMP_DESC;
32 } zynqmp_devices[] = {
79 static int chip_id(unsigned char id)
82 regs.regs[0] = ZYNQMP_SIP_SVC_CSU_DMA_CHIPID;
92 * regs[0][31:0] = status of the operation
93 * regs[0][63:32] = CSU.IDCODE register
94 * regs[1][31:0] = CSU.version register
98 regs.regs[0] = upper_32_bits(regs.regs[0]);
99 regs.regs[0] &= ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK |
100 ZYNQMP_CSU_IDCODE_SVD_MASK;
101 regs.regs[0] >>= ZYNQMP_CSU_IDCODE_SVD_SHIFT;
105 regs.regs[1] = lower_32_bits(regs.regs[1]);
106 regs.regs[1] &= ZYNQMP_CSU_SILICON_VER_MASK;
110 printf("%s, Invalid Req:0x%x\n", __func__, id);
116 static char *zynqmp_get_silicon_idcode_name(void)
120 id = chip_id(IDCODE);
121 for (i = 0; i < ARRAY_SIZE(zynqmp_devices); i++) {
122 if (zynqmp_devices[i].id == id)
123 return zynqmp_devices[i].name;
129 int board_early_init_f(void)
131 #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_CLK_ZYNQMP)
132 zynqmp_pmufw_version();
135 #if defined(CONFIG_SPL_BUILD) || defined(CONFIG_ZYNQMP_PSU_INIT_ENABLED)
142 #define ZYNQMP_VERSION_SIZE 9
146 printf("EL Level:\tEL%d\n", current_el());
148 #if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
149 !defined(CONFIG_SPL_BUILD) || (defined(CONFIG_SPL_FPGA_SUPPORT) && \
150 defined(CONFIG_SPL_BUILD))
151 if (current_el() != 3) {
152 static char version[ZYNQMP_VERSION_SIZE];
154 strncat(version, "xczu", ZYNQMP_VERSION_SIZE);
155 zynqmppl.name = strncat(version,
156 zynqmp_get_silicon_idcode_name(),
157 ZYNQMP_VERSION_SIZE);
158 printf("Chip ID:\t%s\n", zynqmppl.name);
160 fpga_add(fpga_xilinx, &zynqmppl);
167 int board_early_init_r(void)
171 val = readl(&crlapb_base->timestamp_ref_ctrl);
172 val &= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
174 if (current_el() == 3 && !val) {
175 val = readl(&crlapb_base->timestamp_ref_ctrl);
176 val |= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
177 writel(val, &crlapb_base->timestamp_ref_ctrl);
179 /* Program freq register in System counter */
180 writel(zynqmp_get_system_timer_freq(),
181 &iou_scntr_secure->base_frequency_id_register);
182 /* And enable system counter */
183 writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN,
184 &iou_scntr_secure->counter_control_register);
189 int zynq_board_read_rom_ethaddr(unsigned char *ethaddr)
191 #if defined(CONFIG_ZYNQ_GEM_EEPROM_ADDR) && \
192 defined(CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET) && \
193 defined(CONFIG_ZYNQ_EEPROM_BUS)
194 i2c_set_bus_num(CONFIG_ZYNQ_EEPROM_BUS);
196 if (eeprom_read(CONFIG_ZYNQ_GEM_EEPROM_ADDR,
197 CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET,
199 printf("I2C EEPROM MAC address read failed\n");
205 #if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE)
206 int dram_init_banksize(void)
208 fdtdec_setup_memory_banksize();
215 if (fdtdec_setup_memory_size() != 0)
223 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
229 void reset_cpu(ulong addr)
233 int board_late_init(void)
240 if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
241 debug("Saved variables - Skipping\n");
245 reg = readl(&crlapb_base->boot_mode);
246 if (reg >> BOOT_MODE_ALT_SHIFT)
247 reg >>= BOOT_MODE_ALT_SHIFT;
249 bootmode = reg & BOOT_MODES_MASK;
261 case QSPI_MODE_24BIT:
262 case QSPI_MODE_32BIT:
279 #if defined(CONFIG_ZYNQ_SDHCI0) && defined(CONFIG_ZYNQ_SDHCI1)
291 printf("Invalid Boot Mode:0x%x\n", bootmode);
296 * One terminating char + one byte for space between mode
297 * and default boot_targets
299 new_targets = calloc(1, strlen(mode) +
300 strlen(getenv("boot_targets")) + 2);
302 sprintf(new_targets, "%s %s", mode, getenv("boot_targets"));
303 setenv("boot_targets", new_targets);
310 puts("Board: Xilinx ZynqMP\n");
314 #ifdef CONFIG_USB_DWC3
315 static struct dwc3_device dwc3_device_data0 = {
316 .maximum_speed = USB_SPEED_HIGH,
317 .base = ZYNQMP_USB0_XHCI_BASEADDR,
318 .dr_mode = USB_DR_MODE_PERIPHERAL,
322 static struct dwc3_device dwc3_device_data1 = {
323 .maximum_speed = USB_SPEED_HIGH,
324 .base = ZYNQMP_USB1_XHCI_BASEADDR,
325 .dr_mode = USB_DR_MODE_PERIPHERAL,
329 int usb_gadget_handle_interrupts(int index)
331 dwc3_uboot_handle_interrupt(index);
335 int board_usb_init(int index, enum usb_init_type init)
337 debug("%s: index %x\n", __func__, index);
339 #if defined(CONFIG_USB_GADGET_DOWNLOAD)
340 g_dnl_set_serialnumber(CONFIG_SYS_CONFIG_NAME);
345 return dwc3_uboot_init(&dwc3_device_data0);
347 return dwc3_uboot_init(&dwc3_device_data1);
353 int board_usb_cleanup(int index, enum usb_init_type init)
355 dwc3_uboot_exit(index);