xref: /openbmc/u-boot/board/xilinx/zynqmp/zynqmp.c (revision 16fa00a71147de0fb87062f912478a0551d148d3)
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>
1284c7204bSMichal Simek #include <asm/arch/hardware.h>
1384c7204bSMichal Simek #include <asm/arch/sys_proto.h>
1484c7204bSMichal Simek #include <asm/io.h>
15*16fa00a7SSiva Durga Prasad Paladugu #include <usb.h>
16*16fa00a7SSiva Durga Prasad Paladugu #include <dwc3-uboot.h>
1784c7204bSMichal Simek 
1884c7204bSMichal Simek DECLARE_GLOBAL_DATA_PTR;
1984c7204bSMichal Simek 
2084c7204bSMichal Simek int board_init(void)
2184c7204bSMichal Simek {
22a0736efbSMichal Simek 	printf("EL Level:\tEL%d\n", current_el());
23a0736efbSMichal Simek 
2484c7204bSMichal Simek 	return 0;
2584c7204bSMichal Simek }
2684c7204bSMichal Simek 
2784c7204bSMichal Simek int board_early_init_r(void)
2884c7204bSMichal Simek {
2984c7204bSMichal Simek 	u32 val;
3084c7204bSMichal Simek 
3184c7204bSMichal Simek 	val = readl(&crlapb_base->timestamp_ref_ctrl);
3284c7204bSMichal Simek 	val |= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
3384c7204bSMichal Simek 	writel(val, &crlapb_base->timestamp_ref_ctrl);
3484c7204bSMichal Simek 
3584c7204bSMichal Simek 	/* Program freq register in System counter and enable system counter */
3684c7204bSMichal Simek 	writel(gd->cpu_clk, &iou_scntr->base_frequency_id_register);
3784c7204bSMichal Simek 	writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_HDBG |
3884c7204bSMichal Simek 	       ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN,
3984c7204bSMichal Simek 	       &iou_scntr->counter_control_register);
4084c7204bSMichal Simek 
4184c7204bSMichal Simek 	return 0;
4284c7204bSMichal Simek }
4384c7204bSMichal Simek 
4484c7204bSMichal Simek int dram_init(void)
4584c7204bSMichal Simek {
4684c7204bSMichal Simek 	gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
4784c7204bSMichal Simek 
4884c7204bSMichal Simek 	return 0;
4984c7204bSMichal Simek }
5084c7204bSMichal Simek 
5184c7204bSMichal Simek int timer_init(void)
5284c7204bSMichal Simek {
5384c7204bSMichal Simek 	return 0;
5484c7204bSMichal Simek }
5584c7204bSMichal Simek 
5684c7204bSMichal Simek void reset_cpu(ulong addr)
5784c7204bSMichal Simek {
5884c7204bSMichal Simek }
5984c7204bSMichal Simek 
606fe6f135SMichal Simek #ifdef CONFIG_SCSI_AHCI_PLAT
616fe6f135SMichal Simek void scsi_init(void)
626fe6f135SMichal Simek {
636fe6f135SMichal Simek 	ahci_init((void __iomem *)ZYNQMP_SATA_BASEADDR);
646fe6f135SMichal Simek 	scsi_scan(1);
656fe6f135SMichal Simek }
666fe6f135SMichal Simek #endif
676fe6f135SMichal Simek 
68cb7ea820SMichal Simek int board_eth_init(bd_t *bis)
69cb7ea820SMichal Simek {
70cb7ea820SMichal Simek 	u32 ret = 0;
71cb7ea820SMichal Simek 
72cb7ea820SMichal Simek #if defined(CONFIG_ZYNQ_GEM)
73cb7ea820SMichal Simek # if defined(CONFIG_ZYNQ_GEM0)
74cb7ea820SMichal Simek 	ret |= zynq_gem_initialize(bis, ZYNQ_GEM_BASEADDR0,
75cb7ea820SMichal Simek 						CONFIG_ZYNQ_GEM_PHY_ADDR0, 0);
76cb7ea820SMichal Simek # endif
77cb7ea820SMichal Simek # if defined(CONFIG_ZYNQ_GEM1)
78cb7ea820SMichal Simek 	ret |= zynq_gem_initialize(bis, ZYNQ_GEM_BASEADDR1,
79cb7ea820SMichal Simek 						CONFIG_ZYNQ_GEM_PHY_ADDR1, 0);
80cb7ea820SMichal Simek # endif
81cb7ea820SMichal Simek # if defined(CONFIG_ZYNQ_GEM2)
82cb7ea820SMichal Simek 	ret |= zynq_gem_initialize(bis, ZYNQ_GEM_BASEADDR2,
83cb7ea820SMichal Simek 						CONFIG_ZYNQ_GEM_PHY_ADDR2, 0);
84cb7ea820SMichal Simek # endif
85cb7ea820SMichal Simek # if defined(CONFIG_ZYNQ_GEM3)
86cb7ea820SMichal Simek 	ret |= zynq_gem_initialize(bis, ZYNQ_GEM_BASEADDR3,
87cb7ea820SMichal Simek 						CONFIG_ZYNQ_GEM_PHY_ADDR3, 0);
88cb7ea820SMichal Simek # endif
89cb7ea820SMichal Simek #endif
90cb7ea820SMichal Simek 	return ret;
91cb7ea820SMichal Simek }
92cb7ea820SMichal Simek 
9384c7204bSMichal Simek #ifdef CONFIG_CMD_MMC
9484c7204bSMichal Simek int board_mmc_init(bd_t *bd)
9584c7204bSMichal Simek {
9684c7204bSMichal Simek 	int ret = 0;
9784c7204bSMichal Simek 
9816247d28SMichal Simek 	u32 ver = zynqmp_get_silicon_version();
9916247d28SMichal Simek 
10016247d28SMichal Simek 	if (ver != ZYNQMP_CSU_VERSION_VELOCE) {
10184c7204bSMichal Simek #if defined(CONFIG_ZYNQ_SDHCI)
10284c7204bSMichal Simek # if defined(CONFIG_ZYNQ_SDHCI0)
10384c7204bSMichal Simek 		ret = zynq_sdhci_init(ZYNQ_SDHCI_BASEADDR0);
10484c7204bSMichal Simek # endif
10584c7204bSMichal Simek # if defined(CONFIG_ZYNQ_SDHCI1)
10684c7204bSMichal Simek 		ret |= zynq_sdhci_init(ZYNQ_SDHCI_BASEADDR1);
10784c7204bSMichal Simek # endif
10884c7204bSMichal Simek #endif
10916247d28SMichal Simek 	}
11084c7204bSMichal Simek 
11184c7204bSMichal Simek 	return ret;
11284c7204bSMichal Simek }
11384c7204bSMichal Simek #endif
11484c7204bSMichal Simek 
11584c7204bSMichal Simek int board_late_init(void)
11684c7204bSMichal Simek {
11784c7204bSMichal Simek 	u32 reg = 0;
11884c7204bSMichal Simek 	u8 bootmode;
11984c7204bSMichal Simek 
12084c7204bSMichal Simek 	reg = readl(&crlapb_base->boot_mode);
12184c7204bSMichal Simek 	bootmode = reg & BOOT_MODES_MASK;
12284c7204bSMichal Simek 
12384c7204bSMichal Simek 	switch (bootmode) {
12484c7204bSMichal Simek 	case SD_MODE:
12539c56f55SMichal Simek 	case EMMC_MODE:
12684c7204bSMichal Simek 		setenv("modeboot", "sdboot");
12784c7204bSMichal Simek 		break;
12884c7204bSMichal Simek 	default:
12984c7204bSMichal Simek 		printf("Invalid Boot Mode:0x%x\n", bootmode);
13084c7204bSMichal Simek 		break;
13184c7204bSMichal Simek 	}
13284c7204bSMichal Simek 
13384c7204bSMichal Simek 	return 0;
13484c7204bSMichal Simek }
13584696ff5SSiva Durga Prasad Paladugu 
13684696ff5SSiva Durga Prasad Paladugu int checkboard(void)
13784696ff5SSiva Durga Prasad Paladugu {
13884696ff5SSiva Durga Prasad Paladugu 	puts("Board:\tXilinx ZynqMP\n");
13984696ff5SSiva Durga Prasad Paladugu 	return 0;
14084696ff5SSiva Durga Prasad Paladugu }
141*16fa00a7SSiva Durga Prasad Paladugu 
142*16fa00a7SSiva Durga Prasad Paladugu #ifdef CONFIG_USB_DWC3
143*16fa00a7SSiva Durga Prasad Paladugu static struct dwc3_device dwc3_device_data = {
144*16fa00a7SSiva Durga Prasad Paladugu 	.maximum_speed = USB_SPEED_HIGH,
145*16fa00a7SSiva Durga Prasad Paladugu 	.base = ZYNQMP_USB0_XHCI_BASEADDR,
146*16fa00a7SSiva Durga Prasad Paladugu 	.dr_mode = USB_DR_MODE_PERIPHERAL,
147*16fa00a7SSiva Durga Prasad Paladugu 	.index = 0,
148*16fa00a7SSiva Durga Prasad Paladugu };
149*16fa00a7SSiva Durga Prasad Paladugu 
150*16fa00a7SSiva Durga Prasad Paladugu int usb_gadget_handle_interrupts(void)
151*16fa00a7SSiva Durga Prasad Paladugu {
152*16fa00a7SSiva Durga Prasad Paladugu 	dwc3_uboot_handle_interrupt(0);
153*16fa00a7SSiva Durga Prasad Paladugu 	return 0;
154*16fa00a7SSiva Durga Prasad Paladugu }
155*16fa00a7SSiva Durga Prasad Paladugu 
156*16fa00a7SSiva Durga Prasad Paladugu int board_usb_init(int index, enum usb_init_type init)
157*16fa00a7SSiva Durga Prasad Paladugu {
158*16fa00a7SSiva Durga Prasad Paladugu 	return dwc3_uboot_init(&dwc3_device_data);
159*16fa00a7SSiva Durga Prasad Paladugu }
160*16fa00a7SSiva Durga Prasad Paladugu 
161*16fa00a7SSiva Durga Prasad Paladugu int board_usb_cleanup(int index, enum usb_init_type init)
162*16fa00a7SSiva Durga Prasad Paladugu {
163*16fa00a7SSiva Durga Prasad Paladugu 	dwc3_uboot_exit(index);
164*16fa00a7SSiva Durga Prasad Paladugu 	return 0;
165*16fa00a7SSiva Durga Prasad Paladugu }
166*16fa00a7SSiva Durga Prasad Paladugu #endif
167