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
;
33 } zynqmp_devices
[] = {
116 { /* For testing purpose only */
136 int chip_id(unsigned char id
)
141 if (current_el() != 3) {
142 regs
.regs
[0] = ZYNQMP_SIP_SVC_CSU_DMA_CHIPID
;
151 * regs[0][31:0] = status of the operation
152 * regs[0][63:32] = CSU.IDCODE register
153 * regs[1][31:0] = CSU.version register
154 * regs[1][63:32] = CSU.IDCODE2 register
158 regs
.regs
[0] = upper_32_bits(regs
.regs
[0]);
159 regs
.regs
[0] &= ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK
|
160 ZYNQMP_CSU_IDCODE_SVD_MASK
;
161 regs
.regs
[0] >>= ZYNQMP_CSU_IDCODE_SVD_SHIFT
;
165 regs
.regs
[1] = lower_32_bits(regs
.regs
[1]);
166 regs
.regs
[1] &= ZYNQMP_CSU_SILICON_VER_MASK
;
170 regs
.regs
[1] = lower_32_bits(regs
.regs
[1]);
171 regs
.regs
[1] >>= ZYNQMP_CSU_VERSION_EMPTY_SHIFT
;
175 printf("%s, Invalid Req:0x%x\n", __func__
, id
);
180 val
= readl(ZYNQMP_CSU_IDCODE_ADDR
);
181 val
&= ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK
|
182 ZYNQMP_CSU_IDCODE_SVD_MASK
;
183 val
>>= ZYNQMP_CSU_IDCODE_SVD_SHIFT
;
186 val
= readl(ZYNQMP_CSU_VER_ADDR
);
187 val
&= ZYNQMP_CSU_SILICON_VER_MASK
;
190 printf("%s, Invalid Req:0x%x\n", __func__
, id
);
197 #if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
198 !defined(CONFIG_SPL_BUILD)
199 static char *zynqmp_get_silicon_idcode_name(void)
203 id
= chip_id(IDCODE
);
204 ver
= chip_id(IDCODE2
);
206 for (i
= 0; i
< ARRAY_SIZE(zynqmp_devices
); i
++) {
207 if (zynqmp_devices
[i
].id
== id
&& zynqmp_devices
[i
].ver
== ver
)
208 return zynqmp_devices
[i
].name
;
214 int board_early_init_f(void)
216 #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_CLK_ZYNQMP)
217 zynqmp_pmufw_version();
220 #if defined(CONFIG_SPL_BUILD) || defined(CONFIG_ZYNQMP_PSU_INIT_ENABLED)
227 #define ZYNQMP_VERSION_SIZE 9
231 printf("EL Level:\tEL%d\n", current_el());
233 #if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
234 !defined(CONFIG_SPL_BUILD) || (defined(CONFIG_SPL_FPGA_SUPPORT) && \
235 defined(CONFIG_SPL_BUILD))
236 if (current_el() != 3) {
237 static char version
[ZYNQMP_VERSION_SIZE
];
239 strncat(version
, "xczu", 4);
240 zynqmppl
.name
= strncat(version
,
241 zynqmp_get_silicon_idcode_name(),
242 ZYNQMP_VERSION_SIZE
- 5);
243 printf("Chip ID:\t%s\n", zynqmppl
.name
);
245 fpga_add(fpga_xilinx
, &zynqmppl
);
252 int board_early_init_r(void)
256 val
= readl(&crlapb_base
->timestamp_ref_ctrl
);
257 val
&= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT
;
259 if (current_el() == 3 && !val
) {
260 val
= readl(&crlapb_base
->timestamp_ref_ctrl
);
261 val
|= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT
;
262 writel(val
, &crlapb_base
->timestamp_ref_ctrl
);
264 /* Program freq register in System counter */
265 writel(zynqmp_get_system_timer_freq(),
266 &iou_scntr_secure
->base_frequency_id_register
);
267 /* And enable system counter */
268 writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN
,
269 &iou_scntr_secure
->counter_control_register
);
274 int zynq_board_read_rom_ethaddr(unsigned char *ethaddr
)
276 #if defined(CONFIG_ZYNQ_GEM_EEPROM_ADDR) && \
277 defined(CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET) && \
278 defined(CONFIG_ZYNQ_EEPROM_BUS)
279 i2c_set_bus_num(CONFIG_ZYNQ_EEPROM_BUS
);
281 if (eeprom_read(CONFIG_ZYNQ_GEM_EEPROM_ADDR
,
282 CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET
,
284 printf("I2C EEPROM MAC address read failed\n");
290 #if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE)
291 int dram_init_banksize(void)
293 return fdtdec_setup_memory_banksize();
298 if (fdtdec_setup_memory_size() != 0)
306 gd
->ram_size
= CONFIG_SYS_SDRAM_SIZE
;
312 void reset_cpu(ulong addr
)
316 int board_late_init(void)
323 if (!(gd
->flags
& GD_FLG_ENV_DEFAULT
)) {
324 debug("Saved variables - Skipping\n");
328 reg
= readl(&crlapb_base
->boot_mode
);
329 if (reg
>> BOOT_MODE_ALT_SHIFT
)
330 reg
>>= BOOT_MODE_ALT_SHIFT
;
332 bootmode
= reg
& BOOT_MODES_MASK
;
344 case QSPI_MODE_24BIT
:
345 case QSPI_MODE_32BIT
:
362 #if defined(CONFIG_ZYNQ_SDHCI0) && defined(CONFIG_ZYNQ_SDHCI1)
374 printf("Invalid Boot Mode:0x%x\n", bootmode
);
379 * One terminating char + one byte for space between mode
380 * and default boot_targets
382 new_targets
= calloc(1, strlen(mode
) +
383 strlen(env_get("boot_targets")) + 2);
385 sprintf(new_targets
, "%s %s", mode
, env_get("boot_targets"));
386 env_set("boot_targets", new_targets
);
393 puts("Board: Xilinx ZynqMP\n");
397 #ifdef CONFIG_USB_DWC3
398 static struct dwc3_device dwc3_device_data0
= {
399 .maximum_speed
= USB_SPEED_HIGH
,
400 .base
= ZYNQMP_USB0_XHCI_BASEADDR
,
401 .dr_mode
= USB_DR_MODE_PERIPHERAL
,
405 static struct dwc3_device dwc3_device_data1
= {
406 .maximum_speed
= USB_SPEED_HIGH
,
407 .base
= ZYNQMP_USB1_XHCI_BASEADDR
,
408 .dr_mode
= USB_DR_MODE_PERIPHERAL
,
412 int usb_gadget_handle_interrupts(int index
)
414 dwc3_uboot_handle_interrupt(index
);
418 int board_usb_init(int index
, enum usb_init_type init
)
420 debug("%s: index %x\n", __func__
, index
);
422 #if defined(CONFIG_USB_GADGET_DOWNLOAD)
423 g_dnl_set_serialnumber(CONFIG_SYS_CONFIG_NAME
);
428 return dwc3_uboot_init(&dwc3_device_data0
);
430 return dwc3_uboot_init(&dwc3_device_data1
);
436 int board_usb_cleanup(int index
, enum usb_init_type init
)
438 dwc3_uboot_exit(index
);