blob: ecdae5e261f635b6fba2b68c22c7554d41a1c18e [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>
Michal Simek679b9942015-09-30 17:26:55 +02009#include <sata.h>
Michal Simek6fe6f132015-07-23 13:27:40 +020010#include <ahci.h>
11#include <scsi.h>
Michal Simekb72894f2016-04-22 14:28:54 +020012#include <malloc.h>
Michal Simek0785dfd2015-11-05 08:34:35 +010013#include <asm/arch/clk.h>
Michal Simek84c72042015-01-15 10:01:51 +010014#include <asm/arch/hardware.h>
15#include <asm/arch/sys_proto.h>
16#include <asm/io.h>
Siva Durga Prasad Paladugu16fa00a2015-08-04 13:03:26 +053017#include <usb.h>
18#include <dwc3-uboot.h>
Michal Simek47e60cb2016-02-01 15:05:58 +010019#include <zynqmppl.h>
Michal Simek6919b4b2016-04-22 11:48:49 +020020#include <i2c.h>
Michal Simek9feff382016-09-01 11:16:40 +020021#include <g_dnl.h>
Michal Simek84c72042015-01-15 10:01:51 +010022
23DECLARE_GLOBAL_DATA_PTR;
24
Michal Simek47e60cb2016-02-01 15:05:58 +010025#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
26 !defined(CONFIG_SPL_BUILD)
27static xilinx_desc zynqmppl = XILINX_ZYNQMP_DESC;
28
29static const struct {
30 uint32_t id;
31 char *name;
32} zynqmp_devices[] = {
33 {
34 .id = 0x10,
35 .name = "3eg",
36 },
37 {
38 .id = 0x11,
39 .name = "2eg",
40 },
41 {
42 .id = 0x20,
43 .name = "5ev",
44 },
45 {
46 .id = 0x21,
47 .name = "4ev",
48 },
49 {
50 .id = 0x30,
51 .name = "7ev",
52 },
53 {
54 .id = 0x38,
55 .name = "9eg",
56 },
57 {
58 .id = 0x39,
59 .name = "6eg",
60 },
61 {
62 .id = 0x40,
63 .name = "11eg",
64 },
65 {
66 .id = 0x50,
67 .name = "15eg",
68 },
69 {
70 .id = 0x58,
71 .name = "19eg",
72 },
73 {
74 .id = 0x59,
75 .name = "17eg",
76 },
77};
78
79static int chip_id(void)
80{
81 struct pt_regs regs;
82 regs.regs[0] = ZYNQMP_SIP_SVC_CSU_DMA_CHIPID;
83 regs.regs[1] = 0;
84 regs.regs[2] = 0;
85 regs.regs[3] = 0;
86
87 smc_call(&regs);
88
Soren Brinkmann0cba6ab2016-09-29 11:44:41 -070089 /*
90 * SMC returns:
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
94 */
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;
99
Michal Simek47e60cb2016-02-01 15:05:58 +0100100 return regs.regs[0];
101}
102
103static char *zynqmp_get_silicon_idcode_name(void)
104{
105 uint32_t i, id;
106
107 id = chip_id();
108 for (i = 0; i < ARRAY_SIZE(zynqmp_devices); i++) {
109 if (zynqmp_devices[i].id == id)
110 return zynqmp_devices[i].name;
111 }
112 return "unknown";
113}
114#endif
115
Michal Simekfb4000e2017-02-07 14:32:26 +0100116int board_early_init_f(void)
117{
118#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_CLK_ZYNQMP)
119 zynqmp_pmufw_version();
120#endif
Michal Simek55de0922017-07-12 13:08:41 +0200121
Michal Simekfd1b6352017-07-12 13:21:27 +0200122#if defined(CONFIG_SPL_BUILD) || defined(CONFIG_ZYNQMP_PSU_INIT_ENABLED)
Michal Simek55de0922017-07-12 13:08:41 +0200123 psu_init();
124#endif
125
Michal Simekfb4000e2017-02-07 14:32:26 +0100126 return 0;
127}
128
Michal Simek47e60cb2016-02-01 15:05:58 +0100129#define ZYNQMP_VERSION_SIZE 9
130
Michal Simek84c72042015-01-15 10:01:51 +0100131int board_init(void)
132{
Michal Simeka0736ef2015-06-22 14:31:06 +0200133 printf("EL Level:\tEL%d\n", current_el());
134
Michal Simek47e60cb2016-02-01 15:05:58 +0100135#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
136 !defined(CONFIG_SPL_BUILD) || (defined(CONFIG_SPL_FPGA_SUPPORT) && \
137 defined(CONFIG_SPL_BUILD))
138 if (current_el() != 3) {
139 static char version[ZYNQMP_VERSION_SIZE];
140
141 strncat(version, "xczu", ZYNQMP_VERSION_SIZE);
142 zynqmppl.name = strncat(version,
143 zynqmp_get_silicon_idcode_name(),
144 ZYNQMP_VERSION_SIZE);
145 printf("Chip ID:\t%s\n", zynqmppl.name);
146 fpga_init();
147 fpga_add(fpga_xilinx, &zynqmppl);
148 }
149#endif
150
Michal Simek84c72042015-01-15 10:01:51 +0100151 return 0;
152}
153
154int board_early_init_r(void)
155{
156 u32 val;
157
Michal Simek0785dfd2015-11-05 08:34:35 +0100158 if (current_el() == 3) {
159 val = readl(&crlapb_base->timestamp_ref_ctrl);
160 val |= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
161 writel(val, &crlapb_base->timestamp_ref_ctrl);
Michal Simek84c72042015-01-15 10:01:51 +0100162
Michal Simek0785dfd2015-11-05 08:34:35 +0100163 /* Program freq register in System counter */
164 writel(zynqmp_get_system_timer_freq(),
165 &iou_scntr_secure->base_frequency_id_register);
166 /* And enable system counter */
167 writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN,
168 &iou_scntr_secure->counter_control_register);
169 }
Michal Simek84c72042015-01-15 10:01:51 +0100170 /* Program freq register in System counter and enable system counter */
171 writel(gd->cpu_clk, &iou_scntr->base_frequency_id_register);
172 writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_HDBG |
173 ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN,
174 &iou_scntr->counter_control_register);
175
176 return 0;
177}
178
Michal Simek6919b4b2016-04-22 11:48:49 +0200179int zynq_board_read_rom_ethaddr(unsigned char *ethaddr)
180{
181#if defined(CONFIG_ZYNQ_GEM_EEPROM_ADDR) && \
182 defined(CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET) && \
183 defined(CONFIG_ZYNQ_EEPROM_BUS)
184 i2c_set_bus_num(CONFIG_ZYNQ_EEPROM_BUS);
185
186 if (eeprom_read(CONFIG_ZYNQ_GEM_EEPROM_ADDR,
187 CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET,
188 ethaddr, 6))
189 printf("I2C EEPROM MAC address read failed\n");
190#endif
191
192 return 0;
193}
194
Michal Simek8d59d7f2016-02-08 09:34:53 +0100195#if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE)
Simon Glass76b00ac2017-03-31 08:40:32 -0600196int dram_init_banksize(void)
Tom Rini361a8792016-12-09 07:56:54 -0500197{
Nathan Rossi950f86c2016-12-19 00:03:34 +1000198 fdtdec_setup_memory_banksize();
Simon Glass76b00ac2017-03-31 08:40:32 -0600199
200 return 0;
Michal Simek8d59d7f2016-02-08 09:34:53 +0100201}
202
203int dram_init(void)
204{
Nathan Rossi950f86c2016-12-19 00:03:34 +1000205 if (fdtdec_setup_memory_size() != 0)
206 return -EINVAL;
Michal Simek8d59d7f2016-02-08 09:34:53 +0100207
208 return 0;
209}
210#else
Michal Simek84c72042015-01-15 10:01:51 +0100211int dram_init(void)
212{
213 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
214
215 return 0;
216}
Michal Simek8d59d7f2016-02-08 09:34:53 +0100217#endif
Michal Simek84c72042015-01-15 10:01:51 +0100218
Michal Simek84c72042015-01-15 10:01:51 +0100219void reset_cpu(ulong addr)
220{
221}
222
Michal Simek84c72042015-01-15 10:01:51 +0100223int board_late_init(void)
224{
225 u32 reg = 0;
226 u8 bootmode;
Michal Simekb72894f2016-04-22 14:28:54 +0200227 const char *mode;
228 char *new_targets;
229
230 if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
231 debug("Saved variables - Skipping\n");
232 return 0;
233 }
Michal Simek84c72042015-01-15 10:01:51 +0100234
235 reg = readl(&crlapb_base->boot_mode);
Michal Simek47359a02016-10-25 11:43:02 +0200236 if (reg >> BOOT_MODE_ALT_SHIFT)
237 reg >>= BOOT_MODE_ALT_SHIFT;
238
Michal Simek84c72042015-01-15 10:01:51 +0100239 bootmode = reg & BOOT_MODES_MASK;
240
Michal Simekfb909172015-09-20 17:20:42 +0200241 puts("Bootmode: ");
Michal Simek84c72042015-01-15 10:01:51 +0100242 switch (bootmode) {
Michal Simekd58fc122016-08-19 14:14:52 +0200243 case USB_MODE:
244 puts("USB_MODE\n");
245 mode = "usb";
246 break;
Siva Durga Prasad Paladugu0a5bcc82015-03-13 11:10:26 +0530247 case JTAG_MODE:
Michal Simekfb909172015-09-20 17:20:42 +0200248 puts("JTAG_MODE\n");
Michal Simekb72894f2016-04-22 14:28:54 +0200249 mode = "pxe dhcp";
Siva Durga Prasad Paladugu0a5bcc82015-03-13 11:10:26 +0530250 break;
251 case QSPI_MODE_24BIT:
252 case QSPI_MODE_32BIT:
Michal Simekb72894f2016-04-22 14:28:54 +0200253 mode = "qspi0";
Michal Simekfb909172015-09-20 17:20:42 +0200254 puts("QSPI_MODE\n");
Siva Durga Prasad Paladugu0a5bcc82015-03-13 11:10:26 +0530255 break;
Michal Simek39c56f52015-04-15 15:02:28 +0200256 case EMMC_MODE:
Michal Simek78678fe2015-10-05 15:59:38 +0200257 puts("EMMC_MODE\n");
Michal Simekb72894f2016-04-22 14:28:54 +0200258 mode = "mmc0";
Michal Simek78678fe2015-10-05 15:59:38 +0200259 break;
260 case SD_MODE:
Michal Simekfb909172015-09-20 17:20:42 +0200261 puts("SD_MODE\n");
Michal Simekb72894f2016-04-22 14:28:54 +0200262 mode = "mmc0";
Michal Simek84c72042015-01-15 10:01:51 +0100263 break;
Siva Durga Prasad Paladugue1992272016-09-21 11:45:05 +0530264 case SD1_LSHFT_MODE:
265 puts("LVL_SHFT_");
266 /* fall through */
Michal Simekaf813ac2015-10-05 10:51:12 +0200267 case SD_MODE1:
Michal Simekfb909172015-09-20 17:20:42 +0200268 puts("SD_MODE1\n");
Michal Simek2d9925b2015-11-06 10:22:37 +0100269#if defined(CONFIG_ZYNQ_SDHCI0) && defined(CONFIG_ZYNQ_SDHCI1)
Michal Simekb72894f2016-04-22 14:28:54 +0200270 mode = "mmc1";
271#else
272 mode = "mmc0";
Michal Simek2d9925b2015-11-06 10:22:37 +0100273#endif
Michal Simekaf813ac2015-10-05 10:51:12 +0200274 break;
275 case NAND_MODE:
Michal Simekfb909172015-09-20 17:20:42 +0200276 puts("NAND_MODE\n");
Michal Simekb72894f2016-04-22 14:28:54 +0200277 mode = "nand0";
Michal Simekaf813ac2015-10-05 10:51:12 +0200278 break;
Michal Simek84c72042015-01-15 10:01:51 +0100279 default:
Michal Simekb72894f2016-04-22 14:28:54 +0200280 mode = "";
Michal Simek84c72042015-01-15 10:01:51 +0100281 printf("Invalid Boot Mode:0x%x\n", bootmode);
282 break;
283 }
284
Michal Simekb72894f2016-04-22 14:28:54 +0200285 /*
286 * One terminating char + one byte for space between mode
287 * and default boot_targets
288 */
289 new_targets = calloc(1, strlen(mode) +
290 strlen(getenv("boot_targets")) + 2);
291
292 sprintf(new_targets, "%s %s", mode, getenv("boot_targets"));
293 setenv("boot_targets", new_targets);
294
Michal Simek84c72042015-01-15 10:01:51 +0100295 return 0;
296}
Siva Durga Prasad Paladugu84696ff2015-08-04 13:01:05 +0530297
298int checkboard(void)
299{
Michal Simek5af08552016-01-25 11:04:21 +0100300 puts("Board: Xilinx ZynqMP\n");
Siva Durga Prasad Paladugu84696ff2015-08-04 13:01:05 +0530301 return 0;
302}
Siva Durga Prasad Paladugu16fa00a2015-08-04 13:03:26 +0530303
304#ifdef CONFIG_USB_DWC3
Michal Simek275bd6d2016-08-08 10:11:26 +0200305static struct dwc3_device dwc3_device_data0 = {
Siva Durga Prasad Paladugu16fa00a2015-08-04 13:03:26 +0530306 .maximum_speed = USB_SPEED_HIGH,
307 .base = ZYNQMP_USB0_XHCI_BASEADDR,
308 .dr_mode = USB_DR_MODE_PERIPHERAL,
309 .index = 0,
310};
311
Michal Simek275bd6d2016-08-08 10:11:26 +0200312static struct dwc3_device dwc3_device_data1 = {
313 .maximum_speed = USB_SPEED_HIGH,
314 .base = ZYNQMP_USB1_XHCI_BASEADDR,
315 .dr_mode = USB_DR_MODE_PERIPHERAL,
316 .index = 1,
317};
318
Michal Simek9feff382016-09-01 11:16:40 +0200319int usb_gadget_handle_interrupts(int index)
Siva Durga Prasad Paladugu16fa00a2015-08-04 13:03:26 +0530320{
Michal Simek9feff382016-09-01 11:16:40 +0200321 dwc3_uboot_handle_interrupt(index);
Siva Durga Prasad Paladugu16fa00a2015-08-04 13:03:26 +0530322 return 0;
323}
324
325int board_usb_init(int index, enum usb_init_type init)
326{
Michal Simek275bd6d2016-08-08 10:11:26 +0200327 debug("%s: index %x\n", __func__, index);
328
Michal Simek8ecd50c2016-09-01 11:27:32 +0200329#if defined(CONFIG_USB_GADGET_DOWNLOAD)
330 g_dnl_set_serialnumber(CONFIG_SYS_CONFIG_NAME);
331#endif
332
Michal Simek275bd6d2016-08-08 10:11:26 +0200333 switch (index) {
334 case 0:
335 return dwc3_uboot_init(&dwc3_device_data0);
336 case 1:
337 return dwc3_uboot_init(&dwc3_device_data1);
338 };
339
340 return -1;
Siva Durga Prasad Paladugu16fa00a2015-08-04 13:03:26 +0530341}
342
343int board_usb_cleanup(int index, enum usb_init_type init)
344{
345 dwc3_uboot_exit(index);
346 return 0;
347}
348#endif