blob: 0d1bd5412b166e37f04f7cf67197e668def35edb [file] [log] [blame]
Michal Simek04b7e622015-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 Simekd54b1af2015-09-30 17:26:55 +02009#include <sata.h>
Michal Simekb216cc12015-07-23 13:27:40 +020010#include <ahci.h>
11#include <scsi.h>
Michal Simekecfb6dc2016-04-22 14:28:54 +020012#include <malloc.h>
Michal Simekc23d3f82015-11-05 08:34:35 +010013#include <asm/arch/clk.h>
Michal Simek04b7e622015-01-15 10:01:51 +010014#include <asm/arch/hardware.h>
15#include <asm/arch/sys_proto.h>
Michal Simekf2f08642018-01-10 09:36:09 +010016#include <asm/arch/psu_init_gpl.h>
Michal Simek04b7e622015-01-15 10:01:51 +010017#include <asm/io.h>
Siva Durga Prasad Paladuguba1f68e2015-08-04 13:03:26 +053018#include <usb.h>
19#include <dwc3-uboot.h>
Michal Simek8111aff2016-02-01 15:05:58 +010020#include <zynqmppl.h>
Michal Simekeec32f62016-04-22 11:48:49 +020021#include <i2c.h>
Michal Simek76d0a772016-09-01 11:16:40 +020022#include <g_dnl.h>
Michal Simek04b7e622015-01-15 10:01:51 +010023
24DECLARE_GLOBAL_DATA_PTR;
25
Michal Simek8111aff2016-02-01 15:05:58 +010026#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
27 !defined(CONFIG_SPL_BUILD)
28static xilinx_desc zynqmppl = XILINX_ZYNQMP_DESC;
29
30static const struct {
Michal Simek6908b862017-11-06 12:55:59 +010031 u32 id;
Michal Simek50d8cef2017-08-22 14:58:53 +020032 u32 ver;
Michal Simek8111aff2016-02-01 15:05:58 +010033 char *name;
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +053034 bool evexists;
Michal Simek8111aff2016-02-01 15:05:58 +010035} zynqmp_devices[] = {
36 {
37 .id = 0x10,
38 .name = "3eg",
39 },
40 {
Michal Simek50d8cef2017-08-22 14:58:53 +020041 .id = 0x10,
42 .ver = 0x2c,
43 .name = "3cg",
44 },
45 {
Michal Simek8111aff2016-02-01 15:05:58 +010046 .id = 0x11,
47 .name = "2eg",
48 },
49 {
Michal Simek50d8cef2017-08-22 14:58:53 +020050 .id = 0x11,
51 .ver = 0x2c,
52 .name = "2cg",
53 },
54 {
Michal Simek8111aff2016-02-01 15:05:58 +010055 .id = 0x20,
56 .name = "5ev",
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +053057 .evexists = 1,
Michal Simek8111aff2016-02-01 15:05:58 +010058 },
59 {
Michal Simek50d8cef2017-08-22 14:58:53 +020060 .id = 0x20,
61 .ver = 0x100,
62 .name = "5eg",
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +053063 .evexists = 1,
Michal Simek50d8cef2017-08-22 14:58:53 +020064 },
65 {
66 .id = 0x20,
67 .ver = 0x12c,
68 .name = "5cg",
69 },
70 {
Michal Simek8111aff2016-02-01 15:05:58 +010071 .id = 0x21,
72 .name = "4ev",
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +053073 .evexists = 1,
Michal Simek8111aff2016-02-01 15:05:58 +010074 },
75 {
Michal Simek50d8cef2017-08-22 14:58:53 +020076 .id = 0x21,
77 .ver = 0x100,
78 .name = "4eg",
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +053079 .evexists = 1,
Michal Simek50d8cef2017-08-22 14:58:53 +020080 },
81 {
82 .id = 0x21,
83 .ver = 0x12c,
84 .name = "4cg",
85 },
86 {
Michal Simek8111aff2016-02-01 15:05:58 +010087 .id = 0x30,
88 .name = "7ev",
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +053089 .evexists = 1,
Michal Simek8111aff2016-02-01 15:05:58 +010090 },
91 {
Michal Simek50d8cef2017-08-22 14:58:53 +020092 .id = 0x30,
93 .ver = 0x100,
94 .name = "7eg",
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +053095 .evexists = 1,
Michal Simek50d8cef2017-08-22 14:58:53 +020096 },
97 {
98 .id = 0x30,
99 .ver = 0x12c,
100 .name = "7cg",
101 },
102 {
Michal Simek8111aff2016-02-01 15:05:58 +0100103 .id = 0x38,
104 .name = "9eg",
105 },
106 {
Michal Simek50d8cef2017-08-22 14:58:53 +0200107 .id = 0x38,
108 .ver = 0x2c,
109 .name = "9cg",
110 },
111 {
Michal Simek8111aff2016-02-01 15:05:58 +0100112 .id = 0x39,
113 .name = "6eg",
114 },
115 {
Michal Simek50d8cef2017-08-22 14:58:53 +0200116 .id = 0x39,
117 .ver = 0x2c,
118 .name = "6cg",
119 },
120 {
Michal Simek8111aff2016-02-01 15:05:58 +0100121 .id = 0x40,
122 .name = "11eg",
123 },
Michal Simek50d8cef2017-08-22 14:58:53 +0200124 { /* For testing purpose only */
125 .id = 0x50,
126 .ver = 0x2c,
127 .name = "15cg",
128 },
Michal Simek8111aff2016-02-01 15:05:58 +0100129 {
130 .id = 0x50,
131 .name = "15eg",
132 },
133 {
134 .id = 0x58,
135 .name = "19eg",
136 },
137 {
138 .id = 0x59,
139 .name = "17eg",
140 },
Michal Simekb510e532017-06-02 08:08:59 +0200141 {
142 .id = 0x61,
143 .name = "21dr",
144 },
145 {
146 .id = 0x63,
147 .name = "23dr",
148 },
149 {
150 .id = 0x65,
151 .name = "25dr",
152 },
153 {
154 .id = 0x64,
155 .name = "27dr",
156 },
157 {
158 .id = 0x60,
159 .name = "28dr",
160 },
161 {
162 .id = 0x62,
163 .name = "29dr",
164 },
Michal Simek8111aff2016-02-01 15:05:58 +0100165};
Siva Durga Prasad Paladugu8d526532017-07-25 11:51:37 +0530166#endif
Michal Simek8111aff2016-02-01 15:05:58 +0100167
Siva Durga Prasad Paladugucd35d522017-07-25 11:51:38 +0530168int chip_id(unsigned char id)
Michal Simek8111aff2016-02-01 15:05:58 +0100169{
170 struct pt_regs regs;
Siva Durga Prasad Paladugu9f0a8e92017-07-25 11:51:36 +0530171 int val = -EINVAL;
Michal Simek8111aff2016-02-01 15:05:58 +0100172
Siva Durga Prasad Paladugu8d526532017-07-25 11:51:37 +0530173 if (current_el() != 3) {
174 regs.regs[0] = ZYNQMP_SIP_SVC_CSU_DMA_CHIPID;
175 regs.regs[1] = 0;
176 regs.regs[2] = 0;
177 regs.regs[3] = 0;
Michal Simek8111aff2016-02-01 15:05:58 +0100178
Siva Durga Prasad Paladugu8d526532017-07-25 11:51:37 +0530179 smc_call(&regs);
180
181 /*
182 * SMC returns:
183 * regs[0][31:0] = status of the operation
184 * regs[0][63:32] = CSU.IDCODE register
185 * regs[1][31:0] = CSU.version register
Michal Simek50d8cef2017-08-22 14:58:53 +0200186 * regs[1][63:32] = CSU.IDCODE2 register
Siva Durga Prasad Paladugu8d526532017-07-25 11:51:37 +0530187 */
188 switch (id) {
189 case IDCODE:
190 regs.regs[0] = upper_32_bits(regs.regs[0]);
191 regs.regs[0] &= ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK |
192 ZYNQMP_CSU_IDCODE_SVD_MASK;
193 regs.regs[0] >>= ZYNQMP_CSU_IDCODE_SVD_SHIFT;
194 val = regs.regs[0];
195 break;
196 case VERSION:
197 regs.regs[1] = lower_32_bits(regs.regs[1]);
198 regs.regs[1] &= ZYNQMP_CSU_SILICON_VER_MASK;
199 val = regs.regs[1];
200 break;
Michal Simek50d8cef2017-08-22 14:58:53 +0200201 case IDCODE2:
202 regs.regs[1] = lower_32_bits(regs.regs[1]);
203 regs.regs[1] >>= ZYNQMP_CSU_VERSION_EMPTY_SHIFT;
204 val = regs.regs[1];
205 break;
Siva Durga Prasad Paladugu8d526532017-07-25 11:51:37 +0530206 default:
207 printf("%s, Invalid Req:0x%x\n", __func__, id);
208 }
209 } else {
210 switch (id) {
211 case IDCODE:
212 val = readl(ZYNQMP_CSU_IDCODE_ADDR);
213 val &= ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK |
214 ZYNQMP_CSU_IDCODE_SVD_MASK;
215 val >>= ZYNQMP_CSU_IDCODE_SVD_SHIFT;
216 break;
217 case VERSION:
218 val = readl(ZYNQMP_CSU_VER_ADDR);
219 val &= ZYNQMP_CSU_SILICON_VER_MASK;
220 break;
221 default:
222 printf("%s, Invalid Req:0x%x\n", __func__, id);
223 }
Siva Durga Prasad Paladugu9f0a8e92017-07-25 11:51:36 +0530224 }
Soren Brinkmannd7696a52016-09-29 11:44:41 -0700225
Siva Durga Prasad Paladugu9f0a8e92017-07-25 11:51:36 +0530226 return val;
Michal Simek8111aff2016-02-01 15:05:58 +0100227}
228
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530229#define ZYNQMP_VERSION_SIZE 9
230#define ZYNQMP_PL_STATUS_BIT 9
231#define ZYNQMP_PL_STATUS_MASK BIT(ZYNQMP_PL_STATUS_BIT)
232#define ZYNQMP_CSU_VERSION_MASK ~(ZYNQMP_PL_STATUS_MASK)
233
Siva Durga Prasad Paladugu8d526532017-07-25 11:51:37 +0530234#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
235 !defined(CONFIG_SPL_BUILD)
Michal Simek8111aff2016-02-01 15:05:58 +0100236static char *zynqmp_get_silicon_idcode_name(void)
237{
Michal Simek50d8cef2017-08-22 14:58:53 +0200238 u32 i, id, ver;
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530239 char *buf;
240 static char name[ZYNQMP_VERSION_SIZE];
Michal Simek8111aff2016-02-01 15:05:58 +0100241
Siva Durga Prasad Paladugu9f0a8e92017-07-25 11:51:36 +0530242 id = chip_id(IDCODE);
Michal Simek50d8cef2017-08-22 14:58:53 +0200243 ver = chip_id(IDCODE2);
244
Michal Simek8111aff2016-02-01 15:05:58 +0100245 for (i = 0; i < ARRAY_SIZE(zynqmp_devices); i++) {
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530246 if ((zynqmp_devices[i].id == id) &&
247 (zynqmp_devices[i].ver == (ver &
248 ZYNQMP_CSU_VERSION_MASK))) {
249 strncat(name, "zu", 2);
250 strncat(name, zynqmp_devices[i].name,
251 ZYNQMP_VERSION_SIZE - 3);
252 break;
253 }
Michal Simek8111aff2016-02-01 15:05:58 +0100254 }
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530255
256 if (i >= ARRAY_SIZE(zynqmp_devices))
257 return "unknown";
258
259 if (!zynqmp_devices[i].evexists)
260 return name;
261
262 if (ver & ZYNQMP_PL_STATUS_MASK)
263 return name;
264
265 if (strstr(name, "eg") || strstr(name, "ev")) {
266 buf = strstr(name, "e");
267 *buf = '\0';
268 }
269
270 return name;
Michal Simek8111aff2016-02-01 15:05:58 +0100271}
272#endif
273
Michal Simek8b353302017-02-07 14:32:26 +0100274int board_early_init_f(void)
275{
Michal Simekc8785f22018-01-10 11:48:48 +0100276 int ret = 0;
Michal Simek8b353302017-02-07 14:32:26 +0100277#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_CLK_ZYNQMP)
278 zynqmp_pmufw_version();
279#endif
Michal Simeke0f36102017-07-12 13:08:41 +0200280
Michal Simek1a1ab5a2018-01-15 12:52:59 +0100281#if defined(CONFIG_ZYNQMP_PSU_INIT_ENABLED)
Michal Simekc8785f22018-01-10 11:48:48 +0100282 ret = psu_init();
Michal Simeke0f36102017-07-12 13:08:41 +0200283#endif
284
Michal Simekc8785f22018-01-10 11:48:48 +0100285 return ret;
Michal Simek8b353302017-02-07 14:32:26 +0100286}
287
Michal Simek04b7e622015-01-15 10:01:51 +0100288int board_init(void)
289{
Michal Simekfb7242d2015-06-22 14:31:06 +0200290 printf("EL Level:\tEL%d\n", current_el());
291
Michal Simek8111aff2016-02-01 15:05:58 +0100292#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
293 !defined(CONFIG_SPL_BUILD) || (defined(CONFIG_SPL_FPGA_SUPPORT) && \
294 defined(CONFIG_SPL_BUILD))
295 if (current_el() != 3) {
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530296 zynqmppl.name = zynqmp_get_silicon_idcode_name();
Michal Simek8111aff2016-02-01 15:05:58 +0100297 printf("Chip ID:\t%s\n", zynqmppl.name);
298 fpga_init();
299 fpga_add(fpga_xilinx, &zynqmppl);
300 }
301#endif
302
Michal Simek04b7e622015-01-15 10:01:51 +0100303 return 0;
304}
305
306int board_early_init_r(void)
307{
308 u32 val;
309
Siva Durga Prasad Paladugu64d90002017-12-07 15:05:30 +0530310 if (current_el() != 3)
311 return 0;
312
Michal Simek245d5282017-07-12 10:32:18 +0200313 val = readl(&crlapb_base->timestamp_ref_ctrl);
314 val &= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
315
Siva Durga Prasad Paladugu64d90002017-12-07 15:05:30 +0530316 if (!val) {
Michal Simekc23d3f82015-11-05 08:34:35 +0100317 val = readl(&crlapb_base->timestamp_ref_ctrl);
318 val |= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
319 writel(val, &crlapb_base->timestamp_ref_ctrl);
Michal Simek04b7e622015-01-15 10:01:51 +0100320
Michal Simekc23d3f82015-11-05 08:34:35 +0100321 /* Program freq register in System counter */
322 writel(zynqmp_get_system_timer_freq(),
323 &iou_scntr_secure->base_frequency_id_register);
324 /* And enable system counter */
325 writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN,
326 &iou_scntr_secure->counter_control_register);
327 }
Michal Simek04b7e622015-01-15 10:01:51 +0100328 return 0;
329}
330
Michal Simekeec32f62016-04-22 11:48:49 +0200331int zynq_board_read_rom_ethaddr(unsigned char *ethaddr)
332{
333#if defined(CONFIG_ZYNQ_GEM_EEPROM_ADDR) && \
334 defined(CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET) && \
335 defined(CONFIG_ZYNQ_EEPROM_BUS)
336 i2c_set_bus_num(CONFIG_ZYNQ_EEPROM_BUS);
337
338 if (eeprom_read(CONFIG_ZYNQ_GEM_EEPROM_ADDR,
339 CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET,
340 ethaddr, 6))
341 printf("I2C EEPROM MAC address read failed\n");
342#endif
343
344 return 0;
345}
346
Nitin Jainb2eb59b2018-02-16 12:56:17 +0530347unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc,
348 char * const argv[])
349{
350 int ret = 0;
351
352 if (current_el() > 1) {
353 smp_kick_all_cpus();
354 dcache_disable();
355 armv8_switch_to_el1(0x0, 0, 0, 0, (unsigned long)entry,
356 ES_TO_AARCH64);
357 } else {
358 printf("FAIL: current EL is not above EL1\n");
359 ret = EINVAL;
360 }
361 return ret;
362}
363
Michal Simek8faa66a2016-02-08 09:34:53 +0100364#if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE)
Simon Glass2f949c32017-03-31 08:40:32 -0600365int dram_init_banksize(void)
Michal Simek8faa66a2016-02-08 09:34:53 +0100366{
Michal Simekd5b7de62017-11-03 15:25:51 +0100367 return fdtdec_setup_memory_banksize();
Tom Riniedcfdbd2016-12-09 07:56:54 -0500368}
Michal Simek8faa66a2016-02-08 09:34:53 +0100369
Tom Riniedcfdbd2016-12-09 07:56:54 -0500370int dram_init(void)
371{
Nathan Rossiac04bfa2016-12-19 00:03:34 +1000372 if (fdtdec_setup_memory_size() != 0)
373 return -EINVAL;
Tom Riniedcfdbd2016-12-09 07:56:54 -0500374
375 return 0;
Michal Simek8faa66a2016-02-08 09:34:53 +0100376}
377#else
Michal Simek04b7e622015-01-15 10:01:51 +0100378int dram_init(void)
379{
380 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
381
382 return 0;
383}
Michal Simek8faa66a2016-02-08 09:34:53 +0100384#endif
Michal Simek04b7e622015-01-15 10:01:51 +0100385
Michal Simek04b7e622015-01-15 10:01:51 +0100386void reset_cpu(ulong addr)
387{
388}
389
Michal Simek04b7e622015-01-15 10:01:51 +0100390int board_late_init(void)
391{
392 u32 reg = 0;
393 u8 bootmode;
Michal Simekecfb6dc2016-04-22 14:28:54 +0200394 const char *mode;
395 char *new_targets;
Siva Durga Prasad Paladugu245c5562017-12-20 16:35:06 +0530396 char *env_targets;
Siva Durga Prasad Paladugue6fd3bb2017-02-21 17:58:28 +0530397 int ret;
Michal Simekecfb6dc2016-04-22 14:28:54 +0200398
399 if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
400 debug("Saved variables - Skipping\n");
401 return 0;
402 }
Michal Simek04b7e622015-01-15 10:01:51 +0100403
Siva Durga Prasad Paladugue6fd3bb2017-02-21 17:58:28 +0530404 ret = zynqmp_mmio_read((ulong)&crlapb_base->boot_mode, &reg);
405 if (ret)
406 return -EINVAL;
407
Michal Simek833e0c42016-10-25 11:43:02 +0200408 if (reg >> BOOT_MODE_ALT_SHIFT)
409 reg >>= BOOT_MODE_ALT_SHIFT;
410
Michal Simek04b7e622015-01-15 10:01:51 +0100411 bootmode = reg & BOOT_MODES_MASK;
412
Michal Simekc5d95232015-09-20 17:20:42 +0200413 puts("Bootmode: ");
Michal Simek04b7e622015-01-15 10:01:51 +0100414 switch (bootmode) {
Michal Simek12398ea2016-08-19 14:14:52 +0200415 case USB_MODE:
416 puts("USB_MODE\n");
417 mode = "usb";
Michal Simek43380352017-12-01 15:18:24 +0100418 env_set("modeboot", "usb_dfu_spl");
Michal Simek12398ea2016-08-19 14:14:52 +0200419 break;
Siva Durga Prasad Paladugu30f0fc72015-03-13 11:10:26 +0530420 case JTAG_MODE:
Michal Simekc5d95232015-09-20 17:20:42 +0200421 puts("JTAG_MODE\n");
Michal Simekecfb6dc2016-04-22 14:28:54 +0200422 mode = "pxe dhcp";
Michal Simek43380352017-12-01 15:18:24 +0100423 env_set("modeboot", "jtagboot");
Siva Durga Prasad Paladugu30f0fc72015-03-13 11:10:26 +0530424 break;
425 case QSPI_MODE_24BIT:
426 case QSPI_MODE_32BIT:
Michal Simekecfb6dc2016-04-22 14:28:54 +0200427 mode = "qspi0";
Michal Simekc5d95232015-09-20 17:20:42 +0200428 puts("QSPI_MODE\n");
Michal Simek43380352017-12-01 15:18:24 +0100429 env_set("modeboot", "qspiboot");
Siva Durga Prasad Paladugu30f0fc72015-03-13 11:10:26 +0530430 break;
Michal Simek02d66cd2015-04-15 15:02:28 +0200431 case EMMC_MODE:
Michal Simekdf7ff0a2015-10-05 15:59:38 +0200432 puts("EMMC_MODE\n");
Michal Simekecfb6dc2016-04-22 14:28:54 +0200433 mode = "mmc0";
Michal Simek43380352017-12-01 15:18:24 +0100434 env_set("modeboot", "emmcboot");
Michal Simekdf7ff0a2015-10-05 15:59:38 +0200435 break;
436 case SD_MODE:
Michal Simekc5d95232015-09-20 17:20:42 +0200437 puts("SD_MODE\n");
Michal Simekecfb6dc2016-04-22 14:28:54 +0200438 mode = "mmc0";
Michal Simek43380352017-12-01 15:18:24 +0100439 env_set("modeboot", "sdboot");
Michal Simek04b7e622015-01-15 10:01:51 +0100440 break;
Siva Durga Prasad Paladugu29a77d22016-09-21 11:45:05 +0530441 case SD1_LSHFT_MODE:
442 puts("LVL_SHFT_");
443 /* fall through */
Michal Simek108e1842015-10-05 10:51:12 +0200444 case SD_MODE1:
Michal Simekc5d95232015-09-20 17:20:42 +0200445 puts("SD_MODE1\n");
Michal Simek6d902452015-11-06 10:22:37 +0100446#if defined(CONFIG_ZYNQ_SDHCI0) && defined(CONFIG_ZYNQ_SDHCI1)
Michal Simekecfb6dc2016-04-22 14:28:54 +0200447 mode = "mmc1";
Michal Simek43380352017-12-01 15:18:24 +0100448 env_set("sdbootdev", "1");
Michal Simekecfb6dc2016-04-22 14:28:54 +0200449#else
450 mode = "mmc0";
Michal Simek6d902452015-11-06 10:22:37 +0100451#endif
Michal Simek43380352017-12-01 15:18:24 +0100452 env_set("modeboot", "sdboot");
Michal Simek108e1842015-10-05 10:51:12 +0200453 break;
454 case NAND_MODE:
Michal Simekc5d95232015-09-20 17:20:42 +0200455 puts("NAND_MODE\n");
Michal Simekecfb6dc2016-04-22 14:28:54 +0200456 mode = "nand0";
Michal Simek43380352017-12-01 15:18:24 +0100457 env_set("modeboot", "nandboot");
Michal Simek108e1842015-10-05 10:51:12 +0200458 break;
Michal Simek04b7e622015-01-15 10:01:51 +0100459 default:
Michal Simekecfb6dc2016-04-22 14:28:54 +0200460 mode = "";
Michal Simek04b7e622015-01-15 10:01:51 +0100461 printf("Invalid Boot Mode:0x%x\n", bootmode);
462 break;
463 }
464
Michal Simekecfb6dc2016-04-22 14:28:54 +0200465 /*
466 * One terminating char + one byte for space between mode
467 * and default boot_targets
468 */
Siva Durga Prasad Paladugu245c5562017-12-20 16:35:06 +0530469 env_targets = env_get("boot_targets");
470 if (env_targets) {
471 new_targets = calloc(1, strlen(mode) +
472 strlen(env_targets) + 2);
473 sprintf(new_targets, "%s %s", mode, env_targets);
474 } else {
475 new_targets = calloc(1, strlen(mode) + 2);
476 sprintf(new_targets, "%s", mode);
477 }
Michal Simekecfb6dc2016-04-22 14:28:54 +0200478
Simon Glass6a38e412017-08-03 12:22:09 -0600479 env_set("boot_targets", new_targets);
Michal Simekecfb6dc2016-04-22 14:28:54 +0200480
Michal Simek04b7e622015-01-15 10:01:51 +0100481 return 0;
482}
Siva Durga Prasad Paladugu650e0a32015-08-04 13:01:05 +0530483
484int checkboard(void)
485{
Michal Simek47ce9362016-01-25 11:04:21 +0100486 puts("Board: Xilinx ZynqMP\n");
Siva Durga Prasad Paladugu650e0a32015-08-04 13:01:05 +0530487 return 0;
488}
Siva Durga Prasad Paladuguba1f68e2015-08-04 13:03:26 +0530489
490#ifdef CONFIG_USB_DWC3
Michal Simekea526be2016-08-08 10:11:26 +0200491static struct dwc3_device dwc3_device_data0 = {
Siva Durga Prasad Paladuguba1f68e2015-08-04 13:03:26 +0530492 .maximum_speed = USB_SPEED_HIGH,
493 .base = ZYNQMP_USB0_XHCI_BASEADDR,
494 .dr_mode = USB_DR_MODE_PERIPHERAL,
495 .index = 0,
496};
497
Michal Simekea526be2016-08-08 10:11:26 +0200498static struct dwc3_device dwc3_device_data1 = {
499 .maximum_speed = USB_SPEED_HIGH,
500 .base = ZYNQMP_USB1_XHCI_BASEADDR,
501 .dr_mode = USB_DR_MODE_PERIPHERAL,
502 .index = 1,
503};
504
Michal Simek76d0a772016-09-01 11:16:40 +0200505int usb_gadget_handle_interrupts(int index)
Siva Durga Prasad Paladuguba1f68e2015-08-04 13:03:26 +0530506{
Michal Simek76d0a772016-09-01 11:16:40 +0200507 dwc3_uboot_handle_interrupt(index);
Siva Durga Prasad Paladuguba1f68e2015-08-04 13:03:26 +0530508 return 0;
509}
510
511int board_usb_init(int index, enum usb_init_type init)
512{
Michal Simekea526be2016-08-08 10:11:26 +0200513 debug("%s: index %x\n", __func__, index);
514
Michal Simek7987d2a2016-09-01 11:27:32 +0200515#if defined(CONFIG_USB_GADGET_DOWNLOAD)
516 g_dnl_set_serialnumber(CONFIG_SYS_CONFIG_NAME);
517#endif
518
Michal Simekea526be2016-08-08 10:11:26 +0200519 switch (index) {
520 case 0:
521 return dwc3_uboot_init(&dwc3_device_data0);
522 case 1:
523 return dwc3_uboot_init(&dwc3_device_data1);
524 };
525
526 return -1;
Siva Durga Prasad Paladuguba1f68e2015-08-04 13:03:26 +0530527}
528
529int board_usb_cleanup(int index, enum usb_init_type init)
530{
531 dwc3_uboot_exit(index);
532 return 0;
533}
534#endif