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(void)
82 regs
.regs
[0] = ZYNQMP_SIP_SVC_CSU_DMA_CHIPID
;
91 * regs[0][31:0] = status of the operation
92 * regs[0][63:32] = CSU.IDCODE register
93 * regs[1][31:0] = CSU.version register
95 regs
.regs
[0] = upper_32_bits(regs
.regs
[0]);
96 regs
.regs
[0] &= ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK
|
97 ZYNQMP_CSU_IDCODE_SVD_MASK
;
98 regs
.regs
[0] >>= ZYNQMP_CSU_IDCODE_SVD_SHIFT
;
103 static char *zynqmp_get_silicon_idcode_name(void)
108 for (i
= 0; i
< ARRAY_SIZE(zynqmp_devices
); i
++) {
109 if (zynqmp_devices
[i
].id
== id
)
110 return zynqmp_devices
[i
].name
;
116 int board_early_init_f(void)
118 #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_CLK_ZYNQMP)
119 zynqmp_pmufw_version();
124 #define ZYNQMP_VERSION_SIZE 9
128 printf("EL Level:\tEL%d\n", current_el());
130 #if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
131 !defined(CONFIG_SPL_BUILD) || (defined(CONFIG_SPL_FPGA_SUPPORT) && \
132 defined(CONFIG_SPL_BUILD))
133 if (current_el() != 3) {
134 static char version
[ZYNQMP_VERSION_SIZE
];
136 strncat(version
, "xczu", ZYNQMP_VERSION_SIZE
);
137 zynqmppl
.name
= strncat(version
,
138 zynqmp_get_silicon_idcode_name(),
139 ZYNQMP_VERSION_SIZE
);
140 printf("Chip ID:\t%s\n", zynqmppl
.name
);
142 fpga_add(fpga_xilinx
, &zynqmppl
);
149 int board_early_init_r(void)
153 if (current_el() == 3) {
154 val
= readl(&crlapb_base
->timestamp_ref_ctrl
);
155 val
|= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT
;
156 writel(val
, &crlapb_base
->timestamp_ref_ctrl
);
158 /* Program freq register in System counter */
159 writel(zynqmp_get_system_timer_freq(),
160 &iou_scntr_secure
->base_frequency_id_register
);
161 /* And enable system counter */
162 writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN
,
163 &iou_scntr_secure
->counter_control_register
);
165 /* Program freq register in System counter and enable system counter */
166 writel(gd
->cpu_clk
, &iou_scntr
->base_frequency_id_register
);
167 writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_HDBG
|
168 ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN
,
169 &iou_scntr
->counter_control_register
);
174 int zynq_board_read_rom_ethaddr(unsigned char *ethaddr
)
176 #if defined(CONFIG_ZYNQ_GEM_EEPROM_ADDR) && \
177 defined(CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET) && \
178 defined(CONFIG_ZYNQ_EEPROM_BUS)
179 i2c_set_bus_num(CONFIG_ZYNQ_EEPROM_BUS
);
181 if (eeprom_read(CONFIG_ZYNQ_GEM_EEPROM_ADDR
,
182 CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET
,
184 printf("I2C EEPROM MAC address read failed\n");
190 #if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE)
191 int dram_init_banksize(void)
193 fdtdec_setup_memory_banksize();
200 if (fdtdec_setup_memory_size() != 0)
208 gd
->ram_size
= CONFIG_SYS_SDRAM_SIZE
;
214 void reset_cpu(ulong addr
)
218 int board_late_init(void)
225 if (!(gd
->flags
& GD_FLG_ENV_DEFAULT
)) {
226 debug("Saved variables - Skipping\n");
230 reg
= readl(&crlapb_base
->boot_mode
);
231 if (reg
>> BOOT_MODE_ALT_SHIFT
)
232 reg
>>= BOOT_MODE_ALT_SHIFT
;
234 bootmode
= reg
& BOOT_MODES_MASK
;
246 case QSPI_MODE_24BIT
:
247 case QSPI_MODE_32BIT
:
264 #if defined(CONFIG_ZYNQ_SDHCI0) && defined(CONFIG_ZYNQ_SDHCI1)
276 printf("Invalid Boot Mode:0x%x\n", bootmode
);
281 * One terminating char + one byte for space between mode
282 * and default boot_targets
284 new_targets
= calloc(1, strlen(mode
) +
285 strlen(getenv("boot_targets")) + 2);
287 sprintf(new_targets
, "%s %s", mode
, getenv("boot_targets"));
288 setenv("boot_targets", new_targets
);
295 puts("Board: Xilinx ZynqMP\n");
299 #ifdef CONFIG_USB_DWC3
300 static struct dwc3_device dwc3_device_data0
= {
301 .maximum_speed
= USB_SPEED_HIGH
,
302 .base
= ZYNQMP_USB0_XHCI_BASEADDR
,
303 .dr_mode
= USB_DR_MODE_PERIPHERAL
,
307 static struct dwc3_device dwc3_device_data1
= {
308 .maximum_speed
= USB_SPEED_HIGH
,
309 .base
= ZYNQMP_USB1_XHCI_BASEADDR
,
310 .dr_mode
= USB_DR_MODE_PERIPHERAL
,
314 int usb_gadget_handle_interrupts(int index
)
316 dwc3_uboot_handle_interrupt(index
);
320 int board_usb_init(int index
, enum usb_init_type init
)
322 debug("%s: index %x\n", __func__
, index
);
324 #if defined(CONFIG_USB_GADGET_DOWNLOAD)
325 g_dnl_set_serialnumber(CONFIG_SYS_CONFIG_NAME
);
330 return dwc3_uboot_init(&dwc3_device_data0
);
332 return dwc3_uboot_init(&dwc3_device_data1
);
338 int board_usb_cleanup(int index
, enum usb_init_type init
)
340 dwc3_uboot_exit(index
);