blob: 0f44b04c1efa85231e7640450cc6cae9955468dd [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
Michal Simek8d59d7f2016-02-08 09:34:53 +010053#if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE)
54/*
55 * fdt_get_reg - Fill buffer by information from DT
56 */
57static phys_size_t fdt_get_reg(const void *fdt, int nodeoffset, void *buf,
58 const u32 *cell, int n)
59{
60 int i = 0, b, banks;
61 int parent_offset = fdt_parent_offset(fdt, nodeoffset);
62 int address_cells = fdt_address_cells(fdt, parent_offset);
63 int size_cells = fdt_size_cells(fdt, parent_offset);
64 char *p = buf;
65 phys_addr_t val;
66 phys_size_t vals;
67
68 debug("%s: addr_cells=%x, size_cell=%x, buf=%p, cell=%p\n",
69 __func__, address_cells, size_cells, buf, cell);
70
71 /* Check memory bank setup */
72 banks = n % (address_cells + size_cells);
73 if (banks)
74 panic("Incorrect memory setup cells=%d, ac=%d, sc=%d\n",
75 n, address_cells, size_cells);
76
77 banks = n / (address_cells + size_cells);
78
79 for (b = 0; b < banks; b++) {
80 debug("%s: Bank #%d:\n", __func__, b);
81 if (address_cells == 2) {
82 val = cell[i + 1];
83 val <<= 32;
84 val |= cell[i];
85 val = fdt64_to_cpu(val);
86 debug("%s: addr64=%llx, ptr=%p, cell=%p\n",
87 __func__, val, p, &cell[i]);
88 *(phys_addr_t *)p = val;
89 } else {
90 debug("%s: addr32=%x, ptr=%p\n",
91 __func__, fdt32_to_cpu(cell[i]), p);
92 *(phys_addr_t *)p = fdt32_to_cpu(cell[i]);
93 }
94 p += sizeof(phys_addr_t);
95 i += address_cells;
96
97 debug("%s: pa=%p, i=%x, size=%zu\n", __func__, p, i,
98 sizeof(phys_addr_t));
99
100 if (size_cells == 2) {
101 vals = cell[i + 1];
102 vals <<= 32;
103 vals |= cell[i];
104 vals = fdt64_to_cpu(vals);
105
106 debug("%s: size64=%llx, ptr=%p, cell=%p\n",
107 __func__, vals, p, &cell[i]);
108 *(phys_size_t *)p = vals;
109 } else {
110 debug("%s: size32=%x, ptr=%p\n",
111 __func__, fdt32_to_cpu(cell[i]), p);
112 *(phys_size_t *)p = fdt32_to_cpu(cell[i]);
113 }
114 p += sizeof(phys_size_t);
115 i += size_cells;
116
117 debug("%s: ps=%p, i=%x, size=%zu\n",
118 __func__, p, i, sizeof(phys_size_t));
119 }
120
121 /* Return the first address size */
122 return *(phys_size_t *)((char *)buf + sizeof(phys_addr_t));
123}
124
125#define FDT_REG_SIZE sizeof(u32)
126/* Temp location for sharing data for storing */
127/* Up to 64-bit address + 64-bit size */
128static u8 tmp[CONFIG_NR_DRAM_BANKS * 16];
129
130void dram_init_banksize(void)
131{
132 int bank;
133
134 memcpy(&gd->bd->bi_dram[0], &tmp, sizeof(tmp));
135
136 for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
137 debug("Bank #%d: start %llx\n", bank,
138 (unsigned long long)gd->bd->bi_dram[bank].start);
139 debug("Bank #%d: size %llx\n", bank,
140 (unsigned long long)gd->bd->bi_dram[bank].size);
141 }
142}
143
144int dram_init(void)
145{
146 int node, len;
147 const void *blob = gd->fdt_blob;
148 const u32 *cell;
149
150 memset(&tmp, 0, sizeof(tmp));
151
152 /* find or create "/memory" node. */
153 node = fdt_subnode_offset(blob, 0, "memory");
154 if (node < 0) {
155 printf("%s: Can't get memory node\n", __func__);
156 return node;
157 }
158
159 /* Get pointer to cells and lenght of it */
160 cell = fdt_getprop(blob, node, "reg", &len);
161 if (!cell) {
162 printf("%s: Can't get reg property\n", __func__);
163 return -1;
164 }
165
166 gd->ram_size = fdt_get_reg(blob, node, &tmp, cell, len / FDT_REG_SIZE);
167
168 debug("%s: Initial DRAM size %llx\n", __func__, gd->ram_size);
169
170 return 0;
171}
172#else
Michal Simek84c72042015-01-15 10:01:51 +0100173int dram_init(void)
174{
175 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
176
177 return 0;
178}
Michal Simek8d59d7f2016-02-08 09:34:53 +0100179#endif
Michal Simek84c72042015-01-15 10:01:51 +0100180
Michal Simek84c72042015-01-15 10:01:51 +0100181void reset_cpu(ulong addr)
182{
183}
184
Michal Simek6fe6f132015-07-23 13:27:40 +0200185#ifdef CONFIG_SCSI_AHCI_PLAT
186void scsi_init(void)
187{
188 ahci_init((void __iomem *)ZYNQMP_SATA_BASEADDR);
189 scsi_scan(1);
190}
191#endif
192
Michal Simek84c72042015-01-15 10:01:51 +0100193int board_late_init(void)
194{
195 u32 reg = 0;
196 u8 bootmode;
197
198 reg = readl(&crlapb_base->boot_mode);
199 bootmode = reg & BOOT_MODES_MASK;
200
Michal Simekfb909172015-09-20 17:20:42 +0200201 puts("Bootmode: ");
Michal Simek84c72042015-01-15 10:01:51 +0100202 switch (bootmode) {
Siva Durga Prasad Paladugu0a5bcc82015-03-13 11:10:26 +0530203 case JTAG_MODE:
Michal Simekfb909172015-09-20 17:20:42 +0200204 puts("JTAG_MODE\n");
205 setenv("modeboot", "jtagboot");
Siva Durga Prasad Paladugu0a5bcc82015-03-13 11:10:26 +0530206 break;
207 case QSPI_MODE_24BIT:
208 case QSPI_MODE_32BIT:
209 setenv("modeboot", "qspiboot");
Michal Simekfb909172015-09-20 17:20:42 +0200210 puts("QSPI_MODE\n");
Siva Durga Prasad Paladugu0a5bcc82015-03-13 11:10:26 +0530211 break;
Michal Simek39c56f52015-04-15 15:02:28 +0200212 case EMMC_MODE:
Michal Simek78678fe2015-10-05 15:59:38 +0200213 puts("EMMC_MODE\n");
214 setenv("modeboot", "sdboot");
215 break;
216 case SD_MODE:
Michal Simekfb909172015-09-20 17:20:42 +0200217 puts("SD_MODE\n");
Michal Simek84c72042015-01-15 10:01:51 +0100218 setenv("modeboot", "sdboot");
219 break;
Michal Simekaf813ac2015-10-05 10:51:12 +0200220 case SD_MODE1:
Michal Simekfb909172015-09-20 17:20:42 +0200221 puts("SD_MODE1\n");
Michal Simek2d9925b2015-11-06 10:22:37 +0100222#if defined(CONFIG_ZYNQ_SDHCI0) && defined(CONFIG_ZYNQ_SDHCI1)
223 setenv("sdbootdev", "1");
224#endif
225 setenv("modeboot", "sdboot");
Michal Simekaf813ac2015-10-05 10:51:12 +0200226 break;
227 case NAND_MODE:
Michal Simekfb909172015-09-20 17:20:42 +0200228 puts("NAND_MODE\n");
Michal Simekaf813ac2015-10-05 10:51:12 +0200229 setenv("modeboot", "nandboot");
230 break;
Michal Simek84c72042015-01-15 10:01:51 +0100231 default:
232 printf("Invalid Boot Mode:0x%x\n", bootmode);
233 break;
234 }
235
236 return 0;
237}
Siva Durga Prasad Paladugu84696ff2015-08-04 13:01:05 +0530238
239int checkboard(void)
240{
Michal Simek5af08552016-01-25 11:04:21 +0100241 puts("Board: Xilinx ZynqMP\n");
Siva Durga Prasad Paladugu84696ff2015-08-04 13:01:05 +0530242 return 0;
243}
Siva Durga Prasad Paladugu16fa00a2015-08-04 13:03:26 +0530244
245#ifdef CONFIG_USB_DWC3
246static struct dwc3_device dwc3_device_data = {
247 .maximum_speed = USB_SPEED_HIGH,
248 .base = ZYNQMP_USB0_XHCI_BASEADDR,
249 .dr_mode = USB_DR_MODE_PERIPHERAL,
250 .index = 0,
251};
252
253int usb_gadget_handle_interrupts(void)
254{
255 dwc3_uboot_handle_interrupt(0);
256 return 0;
257}
258
259int board_usb_init(int index, enum usb_init_type init)
260{
261 return dwc3_uboot_init(&dwc3_device_data);
262}
263
264int board_usb_cleanup(int index, enum usb_init_type init)
265{
266 dwc3_uboot_exit(index);
267 return 0;
268}
269#endif