blob: ac23625325902f94141f796d2cbcabc91ebdf667 [file] [log] [blame]
Michal Simek84c72042015-01-15 10:01:51 +01001/*
2 * (C) Copyright 2014 - 2015 Xilinx, Inc.
3 * Michal Simek <michal.simek@xilinx.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
9#include <netdev.h>
Michal Simek6fe6f132015-07-23 13:27:40 +020010#include <ahci.h>
11#include <scsi.h>
Michal Simek0785dfd2015-11-05 08:34:35 +010012#include <asm/arch/clk.h>
Michal Simek84c72042015-01-15 10:01:51 +010013#include <asm/arch/hardware.h>
14#include <asm/arch/sys_proto.h>
15#include <asm/io.h>
Siva Durga Prasad Paladugu16fa00a2015-08-04 13:03:26 +053016#include <usb.h>
17#include <dwc3-uboot.h>
Michal Simek84c72042015-01-15 10:01:51 +010018
19DECLARE_GLOBAL_DATA_PTR;
20
21int board_init(void)
22{
Michal Simeka0736ef2015-06-22 14:31:06 +020023 printf("EL Level:\tEL%d\n", current_el());
24
Michal Simek84c72042015-01-15 10:01:51 +010025 return 0;
26}
27
28int board_early_init_r(void)
29{
30 u32 val;
31
Michal Simek0785dfd2015-11-05 08:34:35 +010032 if (current_el() == 3) {
33 val = readl(&crlapb_base->timestamp_ref_ctrl);
34 val |= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
35 writel(val, &crlapb_base->timestamp_ref_ctrl);
Michal Simek84c72042015-01-15 10:01:51 +010036
Michal Simek0785dfd2015-11-05 08:34:35 +010037 /* Program freq register in System counter */
38 writel(zynqmp_get_system_timer_freq(),
39 &iou_scntr_secure->base_frequency_id_register);
40 /* And enable system counter */
41 writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN,
42 &iou_scntr_secure->counter_control_register);
43 }
Michal Simek84c72042015-01-15 10:01:51 +010044 /* Program freq register in System counter and enable system counter */
45 writel(gd->cpu_clk, &iou_scntr->base_frequency_id_register);
46 writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_HDBG |
47 ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN,
48 &iou_scntr->counter_control_register);
49
50 return 0;
51}
52
53int dram_init(void)
54{
55 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
56
57 return 0;
58}
59
60int timer_init(void)
61{
62 return 0;
63}
64
65void reset_cpu(ulong addr)
66{
67}
68
Michal Simek6fe6f132015-07-23 13:27:40 +020069#ifdef CONFIG_SCSI_AHCI_PLAT
70void scsi_init(void)
71{
72 ahci_init((void __iomem *)ZYNQMP_SATA_BASEADDR);
73 scsi_scan(1);
74}
75#endif
76
Michal Simek84c72042015-01-15 10:01:51 +010077int board_late_init(void)
78{
79 u32 reg = 0;
80 u8 bootmode;
81
82 reg = readl(&crlapb_base->boot_mode);
83 bootmode = reg & BOOT_MODES_MASK;
84
Michal Simekfb909172015-09-20 17:20:42 +020085 puts("Bootmode: ");
Michal Simek84c72042015-01-15 10:01:51 +010086 switch (bootmode) {
Siva Durga Prasad Paladugu0a5bcc82015-03-13 11:10:26 +053087 case JTAG_MODE:
Michal Simekfb909172015-09-20 17:20:42 +020088 puts("JTAG_MODE\n");
89 setenv("modeboot", "jtagboot");
Siva Durga Prasad Paladugu0a5bcc82015-03-13 11:10:26 +053090 break;
91 case QSPI_MODE_24BIT:
92 case QSPI_MODE_32BIT:
93 setenv("modeboot", "qspiboot");
Michal Simekfb909172015-09-20 17:20:42 +020094 puts("QSPI_MODE\n");
Siva Durga Prasad Paladugu0a5bcc82015-03-13 11:10:26 +053095 break;
Michal Simek39c56f52015-04-15 15:02:28 +020096 case EMMC_MODE:
Michal Simek78678fe2015-10-05 15:59:38 +020097 puts("EMMC_MODE\n");
98 setenv("modeboot", "sdboot");
99 break;
100 case SD_MODE:
Michal Simekfb909172015-09-20 17:20:42 +0200101 puts("SD_MODE\n");
Michal Simek84c72042015-01-15 10:01:51 +0100102 setenv("modeboot", "sdboot");
103 break;
Michal Simekaf813ac2015-10-05 10:51:12 +0200104 case SD_MODE1:
Michal Simekfb909172015-09-20 17:20:42 +0200105 puts("SD_MODE1\n");
Michal Simek2d9925b2015-11-06 10:22:37 +0100106#if defined(CONFIG_ZYNQ_SDHCI0) && defined(CONFIG_ZYNQ_SDHCI1)
107 setenv("sdbootdev", "1");
108#endif
109 setenv("modeboot", "sdboot");
Michal Simekaf813ac2015-10-05 10:51:12 +0200110 break;
111 case NAND_MODE:
Michal Simekfb909172015-09-20 17:20:42 +0200112 puts("NAND_MODE\n");
Michal Simekaf813ac2015-10-05 10:51:12 +0200113 setenv("modeboot", "nandboot");
114 break;
Michal Simek84c72042015-01-15 10:01:51 +0100115 default:
116 printf("Invalid Boot Mode:0x%x\n", bootmode);
117 break;
118 }
119
120 return 0;
121}
Siva Durga Prasad Paladugu84696ff2015-08-04 13:01:05 +0530122
123int checkboard(void)
124{
125 puts("Board:\tXilinx ZynqMP\n");
126 return 0;
127}
Siva Durga Prasad Paladugu16fa00a2015-08-04 13:03:26 +0530128
129#ifdef CONFIG_USB_DWC3
130static struct dwc3_device dwc3_device_data = {
131 .maximum_speed = USB_SPEED_HIGH,
132 .base = ZYNQMP_USB0_XHCI_BASEADDR,
133 .dr_mode = USB_DR_MODE_PERIPHERAL,
134 .index = 0,
135};
136
137int usb_gadget_handle_interrupts(void)
138{
139 dwc3_uboot_handle_interrupt(0);
140 return 0;
141}
142
143int board_usb_init(int index, enum usb_init_type init)
144{
145 return dwc3_uboot_init(&dwc3_device_data);
146}
147
148int board_usb_cleanup(int index, enum usb_init_type init)
149{
150 dwc3_uboot_exit(index);
151 return 0;
152}
153#endif