xref: /openbmc/u-boot/board/xilinx/zynqmp/zynqmp.c (revision 0785dfd8a7b14cb2c99fc1271c865eb2170c620b)
184c7204bSMichal Simek /*
284c7204bSMichal Simek  * (C) Copyright 2014 - 2015 Xilinx, Inc.
384c7204bSMichal Simek  * Michal Simek <michal.simek@xilinx.com>
484c7204bSMichal Simek  *
584c7204bSMichal Simek  * SPDX-License-Identifier:	GPL-2.0+
684c7204bSMichal Simek  */
784c7204bSMichal Simek 
884c7204bSMichal Simek #include <common.h>
984c7204bSMichal Simek #include <netdev.h>
106fe6f135SMichal Simek #include <ahci.h>
116fe6f135SMichal Simek #include <scsi.h>
12*0785dfd8SMichal Simek #include <asm/arch/clk.h>
1384c7204bSMichal Simek #include <asm/arch/hardware.h>
1484c7204bSMichal Simek #include <asm/arch/sys_proto.h>
1584c7204bSMichal Simek #include <asm/io.h>
1616fa00a7SSiva Durga Prasad Paladugu #include <usb.h>
1716fa00a7SSiva Durga Prasad Paladugu #include <dwc3-uboot.h>
1884c7204bSMichal Simek 
1984c7204bSMichal Simek DECLARE_GLOBAL_DATA_PTR;
2084c7204bSMichal Simek 
2184c7204bSMichal Simek int board_init(void)
2284c7204bSMichal Simek {
23a0736efbSMichal Simek 	printf("EL Level:\tEL%d\n", current_el());
24a0736efbSMichal Simek 
2584c7204bSMichal Simek 	return 0;
2684c7204bSMichal Simek }
2784c7204bSMichal Simek 
2884c7204bSMichal Simek int board_early_init_r(void)
2984c7204bSMichal Simek {
3084c7204bSMichal Simek 	u32 val;
3184c7204bSMichal Simek 
32*0785dfd8SMichal Simek 	if (current_el() == 3) {
3384c7204bSMichal Simek 		val = readl(&crlapb_base->timestamp_ref_ctrl);
3484c7204bSMichal Simek 		val |= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
3584c7204bSMichal Simek 		writel(val, &crlapb_base->timestamp_ref_ctrl);
3684c7204bSMichal Simek 
37*0785dfd8SMichal Simek 		/* Program freq register in System counter */
38*0785dfd8SMichal Simek 		writel(zynqmp_get_system_timer_freq(),
39*0785dfd8SMichal Simek 		       &iou_scntr_secure->base_frequency_id_register);
40*0785dfd8SMichal Simek 		/* And enable system counter */
41*0785dfd8SMichal Simek 		writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN,
42*0785dfd8SMichal Simek 		       &iou_scntr_secure->counter_control_register);
43*0785dfd8SMichal Simek 	}
4484c7204bSMichal Simek 	/* Program freq register in System counter and enable system counter */
4584c7204bSMichal Simek 	writel(gd->cpu_clk, &iou_scntr->base_frequency_id_register);
4684c7204bSMichal Simek 	writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_HDBG |
4784c7204bSMichal Simek 	       ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN,
4884c7204bSMichal Simek 	       &iou_scntr->counter_control_register);
4984c7204bSMichal Simek 
5084c7204bSMichal Simek 	return 0;
5184c7204bSMichal Simek }
5284c7204bSMichal Simek 
5384c7204bSMichal Simek int dram_init(void)
5484c7204bSMichal Simek {
5584c7204bSMichal Simek 	gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
5684c7204bSMichal Simek 
5784c7204bSMichal Simek 	return 0;
5884c7204bSMichal Simek }
5984c7204bSMichal Simek 
6084c7204bSMichal Simek int timer_init(void)
6184c7204bSMichal Simek {
6284c7204bSMichal Simek 	return 0;
6384c7204bSMichal Simek }
6484c7204bSMichal Simek 
6584c7204bSMichal Simek void reset_cpu(ulong addr)
6684c7204bSMichal Simek {
6784c7204bSMichal Simek }
6884c7204bSMichal Simek 
696fe6f135SMichal Simek #ifdef CONFIG_SCSI_AHCI_PLAT
706fe6f135SMichal Simek void scsi_init(void)
716fe6f135SMichal Simek {
726fe6f135SMichal Simek 	ahci_init((void __iomem *)ZYNQMP_SATA_BASEADDR);
736fe6f135SMichal Simek 	scsi_scan(1);
746fe6f135SMichal Simek }
756fe6f135SMichal Simek #endif
766fe6f135SMichal Simek 
7784c7204bSMichal Simek int board_late_init(void)
7884c7204bSMichal Simek {
7984c7204bSMichal Simek 	u32 reg = 0;
8084c7204bSMichal Simek 	u8 bootmode;
8184c7204bSMichal Simek 
8284c7204bSMichal Simek 	reg = readl(&crlapb_base->boot_mode);
8384c7204bSMichal Simek 	bootmode = reg & BOOT_MODES_MASK;
8484c7204bSMichal Simek 
8584c7204bSMichal Simek 	switch (bootmode) {
8684c7204bSMichal Simek 	case SD_MODE:
8739c56f55SMichal Simek 	case EMMC_MODE:
8884c7204bSMichal Simek 		setenv("modeboot", "sdboot");
8984c7204bSMichal Simek 		break;
9084c7204bSMichal Simek 	default:
9184c7204bSMichal Simek 		printf("Invalid Boot Mode:0x%x\n", bootmode);
9284c7204bSMichal Simek 		break;
9384c7204bSMichal Simek 	}
9484c7204bSMichal Simek 
9584c7204bSMichal Simek 	return 0;
9684c7204bSMichal Simek }
9784696ff5SSiva Durga Prasad Paladugu 
9884696ff5SSiva Durga Prasad Paladugu int checkboard(void)
9984696ff5SSiva Durga Prasad Paladugu {
10084696ff5SSiva Durga Prasad Paladugu 	puts("Board:\tXilinx ZynqMP\n");
10184696ff5SSiva Durga Prasad Paladugu 	return 0;
10284696ff5SSiva Durga Prasad Paladugu }
10316fa00a7SSiva Durga Prasad Paladugu 
10416fa00a7SSiva Durga Prasad Paladugu #ifdef CONFIG_USB_DWC3
10516fa00a7SSiva Durga Prasad Paladugu static struct dwc3_device dwc3_device_data = {
10616fa00a7SSiva Durga Prasad Paladugu 	.maximum_speed = USB_SPEED_HIGH,
10716fa00a7SSiva Durga Prasad Paladugu 	.base = ZYNQMP_USB0_XHCI_BASEADDR,
10816fa00a7SSiva Durga Prasad Paladugu 	.dr_mode = USB_DR_MODE_PERIPHERAL,
10916fa00a7SSiva Durga Prasad Paladugu 	.index = 0,
11016fa00a7SSiva Durga Prasad Paladugu };
11116fa00a7SSiva Durga Prasad Paladugu 
11216fa00a7SSiva Durga Prasad Paladugu int usb_gadget_handle_interrupts(void)
11316fa00a7SSiva Durga Prasad Paladugu {
11416fa00a7SSiva Durga Prasad Paladugu 	dwc3_uboot_handle_interrupt(0);
11516fa00a7SSiva Durga Prasad Paladugu 	return 0;
11616fa00a7SSiva Durga Prasad Paladugu }
11716fa00a7SSiva Durga Prasad Paladugu 
11816fa00a7SSiva Durga Prasad Paladugu int board_usb_init(int index, enum usb_init_type init)
11916fa00a7SSiva Durga Prasad Paladugu {
12016fa00a7SSiva Durga Prasad Paladugu 	return dwc3_uboot_init(&dwc3_device_data);
12116fa00a7SSiva Durga Prasad Paladugu }
12216fa00a7SSiva Durga Prasad Paladugu 
12316fa00a7SSiva Durga Prasad Paladugu int board_usb_cleanup(int index, enum usb_init_type init)
12416fa00a7SSiva Durga Prasad Paladugu {
12516fa00a7SSiva Durga Prasad Paladugu 	dwc3_uboot_exit(index);
12616fa00a7SSiva Durga Prasad Paladugu 	return 0;
12716fa00a7SSiva Durga Prasad Paladugu }
12816fa00a7SSiva Durga Prasad Paladugu #endif
129