blob: c840e92d9c42e5aca559828d6af75fef0af09022 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Michal Simek04b7e622015-01-15 10:01:51 +01002/*
3 * (C) Copyright 2014 - 2015 Xilinx, Inc.
4 * Michal Simek <michal.simek@xilinx.com>
Michal Simek04b7e622015-01-15 10:01:51 +01005 */
6
7#include <common.h>
Michal Simekd54b1af2015-09-30 17:26:55 +02008#include <sata.h>
Michal Simekb216cc12015-07-23 13:27:40 +02009#include <ahci.h>
10#include <scsi.h>
Michal Simekecfb6dc2016-04-22 14:28:54 +020011#include <malloc.h>
Michal Simekbf0f9ca2018-04-19 15:43:38 +020012#include <wdt.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>
Michal Simekf183a982018-04-25 11:20:43 +020018#include <dm/device.h>
Michal Simekbf0f9ca2018-04-19 15:43:38 +020019#include <dm/uclass.h>
Siva Durga Prasad Paladuguba1f68e2015-08-04 13:03:26 +053020#include <usb.h>
21#include <dwc3-uboot.h>
Michal Simek8111aff2016-02-01 15:05:58 +010022#include <zynqmppl.h>
Michal Simek76d0a772016-09-01 11:16:40 +020023#include <g_dnl.h>
Michal Simek04b7e622015-01-15 10:01:51 +010024
25DECLARE_GLOBAL_DATA_PTR;
26
Michal Simek8111aff2016-02-01 15:05:58 +010027#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
28 !defined(CONFIG_SPL_BUILD)
29static xilinx_desc zynqmppl = XILINX_ZYNQMP_DESC;
30
31static const struct {
Michal Simek6908b862017-11-06 12:55:59 +010032 u32 id;
Michal Simek50d8cef2017-08-22 14:58:53 +020033 u32 ver;
Michal Simek8111aff2016-02-01 15:05:58 +010034 char *name;
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +053035 bool evexists;
Michal Simek8111aff2016-02-01 15:05:58 +010036} zynqmp_devices[] = {
37 {
38 .id = 0x10,
39 .name = "3eg",
40 },
41 {
Michal Simek50d8cef2017-08-22 14:58:53 +020042 .id = 0x10,
43 .ver = 0x2c,
44 .name = "3cg",
45 },
46 {
Michal Simek8111aff2016-02-01 15:05:58 +010047 .id = 0x11,
48 .name = "2eg",
49 },
50 {
Michal Simek50d8cef2017-08-22 14:58:53 +020051 .id = 0x11,
52 .ver = 0x2c,
53 .name = "2cg",
54 },
55 {
Michal Simek8111aff2016-02-01 15:05:58 +010056 .id = 0x20,
57 .name = "5ev",
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +053058 .evexists = 1,
Michal Simek8111aff2016-02-01 15:05:58 +010059 },
60 {
Michal Simek50d8cef2017-08-22 14:58:53 +020061 .id = 0x20,
62 .ver = 0x100,
63 .name = "5eg",
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +053064 .evexists = 1,
Michal Simek50d8cef2017-08-22 14:58:53 +020065 },
66 {
67 .id = 0x20,
68 .ver = 0x12c,
69 .name = "5cg",
Siva Durga Prasad Paladugu951c0192018-10-26 17:47:55 +053070 .evexists = 1,
Michal Simek50d8cef2017-08-22 14:58:53 +020071 },
72 {
Michal Simek8111aff2016-02-01 15:05:58 +010073 .id = 0x21,
74 .name = "4ev",
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +053075 .evexists = 1,
Michal Simek8111aff2016-02-01 15:05:58 +010076 },
77 {
Michal Simek50d8cef2017-08-22 14:58:53 +020078 .id = 0x21,
79 .ver = 0x100,
80 .name = "4eg",
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +053081 .evexists = 1,
Michal Simek50d8cef2017-08-22 14:58:53 +020082 },
83 {
84 .id = 0x21,
85 .ver = 0x12c,
86 .name = "4cg",
Siva Durga Prasad Paladugu951c0192018-10-26 17:47:55 +053087 .evexists = 1,
Michal Simek50d8cef2017-08-22 14:58:53 +020088 },
89 {
Michal Simek8111aff2016-02-01 15:05:58 +010090 .id = 0x30,
91 .name = "7ev",
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +053092 .evexists = 1,
Michal Simek8111aff2016-02-01 15:05:58 +010093 },
94 {
Michal Simek50d8cef2017-08-22 14:58:53 +020095 .id = 0x30,
96 .ver = 0x100,
97 .name = "7eg",
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +053098 .evexists = 1,
Michal Simek50d8cef2017-08-22 14:58:53 +020099 },
100 {
101 .id = 0x30,
102 .ver = 0x12c,
103 .name = "7cg",
Siva Durga Prasad Paladugu951c0192018-10-26 17:47:55 +0530104 .evexists = 1,
Michal Simek50d8cef2017-08-22 14:58:53 +0200105 },
106 {
Michal Simek8111aff2016-02-01 15:05:58 +0100107 .id = 0x38,
108 .name = "9eg",
109 },
110 {
Michal Simek50d8cef2017-08-22 14:58:53 +0200111 .id = 0x38,
112 .ver = 0x2c,
113 .name = "9cg",
114 },
115 {
Michal Simek8111aff2016-02-01 15:05:58 +0100116 .id = 0x39,
117 .name = "6eg",
118 },
119 {
Michal Simek50d8cef2017-08-22 14:58:53 +0200120 .id = 0x39,
121 .ver = 0x2c,
122 .name = "6cg",
123 },
124 {
Michal Simek8111aff2016-02-01 15:05:58 +0100125 .id = 0x40,
126 .name = "11eg",
127 },
Michal Simek50d8cef2017-08-22 14:58:53 +0200128 { /* For testing purpose only */
129 .id = 0x50,
130 .ver = 0x2c,
131 .name = "15cg",
132 },
Michal Simek8111aff2016-02-01 15:05:58 +0100133 {
134 .id = 0x50,
135 .name = "15eg",
136 },
137 {
138 .id = 0x58,
139 .name = "19eg",
140 },
141 {
142 .id = 0x59,
143 .name = "17eg",
144 },
Michal Simekb510e532017-06-02 08:08:59 +0200145 {
146 .id = 0x61,
147 .name = "21dr",
148 },
149 {
150 .id = 0x63,
151 .name = "23dr",
152 },
153 {
154 .id = 0x65,
155 .name = "25dr",
156 },
157 {
158 .id = 0x64,
159 .name = "27dr",
160 },
161 {
162 .id = 0x60,
163 .name = "28dr",
164 },
165 {
166 .id = 0x62,
167 .name = "29dr",
168 },
Siva Durga Prasad Paladugu70866b42019-03-23 15:00:06 +0530169 {
170 .id = 0x66,
171 .name = "39dr",
172 },
Michal Simek8111aff2016-02-01 15:05:58 +0100173};
Siva Durga Prasad Paladugu8d526532017-07-25 11:51:37 +0530174#endif
Michal Simek8111aff2016-02-01 15:05:58 +0100175
Siva Durga Prasad Paladugucd35d522017-07-25 11:51:38 +0530176int chip_id(unsigned char id)
Michal Simek8111aff2016-02-01 15:05:58 +0100177{
178 struct pt_regs regs;
Siva Durga Prasad Paladugu9f0a8e92017-07-25 11:51:36 +0530179 int val = -EINVAL;
Michal Simek8111aff2016-02-01 15:05:58 +0100180
Siva Durga Prasad Paladugu8d526532017-07-25 11:51:37 +0530181 if (current_el() != 3) {
182 regs.regs[0] = ZYNQMP_SIP_SVC_CSU_DMA_CHIPID;
183 regs.regs[1] = 0;
184 regs.regs[2] = 0;
185 regs.regs[3] = 0;
Michal Simek8111aff2016-02-01 15:05:58 +0100186
Siva Durga Prasad Paladugu8d526532017-07-25 11:51:37 +0530187 smc_call(&regs);
188
189 /*
190 * SMC returns:
191 * regs[0][31:0] = status of the operation
192 * regs[0][63:32] = CSU.IDCODE register
193 * regs[1][31:0] = CSU.version register
Michal Simek50d8cef2017-08-22 14:58:53 +0200194 * regs[1][63:32] = CSU.IDCODE2 register
Siva Durga Prasad Paladugu8d526532017-07-25 11:51:37 +0530195 */
196 switch (id) {
197 case IDCODE:
198 regs.regs[0] = upper_32_bits(regs.regs[0]);
199 regs.regs[0] &= ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK |
200 ZYNQMP_CSU_IDCODE_SVD_MASK;
201 regs.regs[0] >>= ZYNQMP_CSU_IDCODE_SVD_SHIFT;
202 val = regs.regs[0];
203 break;
204 case VERSION:
205 regs.regs[1] = lower_32_bits(regs.regs[1]);
206 regs.regs[1] &= ZYNQMP_CSU_SILICON_VER_MASK;
207 val = regs.regs[1];
208 break;
Michal Simek50d8cef2017-08-22 14:58:53 +0200209 case IDCODE2:
210 regs.regs[1] = lower_32_bits(regs.regs[1]);
211 regs.regs[1] >>= ZYNQMP_CSU_VERSION_EMPTY_SHIFT;
212 val = regs.regs[1];
213 break;
Siva Durga Prasad Paladugu8d526532017-07-25 11:51:37 +0530214 default:
215 printf("%s, Invalid Req:0x%x\n", __func__, id);
216 }
217 } else {
218 switch (id) {
219 case IDCODE:
220 val = readl(ZYNQMP_CSU_IDCODE_ADDR);
221 val &= ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK |
222 ZYNQMP_CSU_IDCODE_SVD_MASK;
223 val >>= ZYNQMP_CSU_IDCODE_SVD_SHIFT;
224 break;
225 case VERSION:
226 val = readl(ZYNQMP_CSU_VER_ADDR);
227 val &= ZYNQMP_CSU_SILICON_VER_MASK;
228 break;
229 default:
230 printf("%s, Invalid Req:0x%x\n", __func__, id);
231 }
Siva Durga Prasad Paladugu9f0a8e92017-07-25 11:51:36 +0530232 }
Soren Brinkmannd7696a52016-09-29 11:44:41 -0700233
Siva Durga Prasad Paladugu9f0a8e92017-07-25 11:51:36 +0530234 return val;
Michal Simek8111aff2016-02-01 15:05:58 +0100235}
236
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530237#define ZYNQMP_VERSION_SIZE 9
238#define ZYNQMP_PL_STATUS_BIT 9
Siva Durga Prasad Paladugu951c0192018-10-26 17:47:55 +0530239#define ZYNQMP_IPDIS_VCU_BIT 8
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530240#define ZYNQMP_PL_STATUS_MASK BIT(ZYNQMP_PL_STATUS_BIT)
241#define ZYNQMP_CSU_VERSION_MASK ~(ZYNQMP_PL_STATUS_MASK)
Siva Durga Prasad Paladugu951c0192018-10-26 17:47:55 +0530242#define ZYNQMP_CSU_VCUDIS_VER_MASK ZYNQMP_CSU_VERSION_MASK & \
243 ~BIT(ZYNQMP_IPDIS_VCU_BIT)
244#define MAX_VARIANTS_EV 3
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530245
Siva Durga Prasad Paladugu8d526532017-07-25 11:51:37 +0530246#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
247 !defined(CONFIG_SPL_BUILD)
Michal Simek8111aff2016-02-01 15:05:58 +0100248static char *zynqmp_get_silicon_idcode_name(void)
249{
Siva Durga Prasad Paladugu951c0192018-10-26 17:47:55 +0530250 u32 i, id, ver, j;
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530251 char *buf;
252 static char name[ZYNQMP_VERSION_SIZE];
Michal Simek8111aff2016-02-01 15:05:58 +0100253
Siva Durga Prasad Paladugu9f0a8e92017-07-25 11:51:36 +0530254 id = chip_id(IDCODE);
Michal Simek50d8cef2017-08-22 14:58:53 +0200255 ver = chip_id(IDCODE2);
256
Michal Simek8111aff2016-02-01 15:05:58 +0100257 for (i = 0; i < ARRAY_SIZE(zynqmp_devices); i++) {
Siva Durga Prasad Paladugu951c0192018-10-26 17:47:55 +0530258 if (zynqmp_devices[i].id == id) {
259 if (zynqmp_devices[i].evexists &&
260 !(ver & ZYNQMP_PL_STATUS_MASK))
261 break;
262 if (zynqmp_devices[i].ver == (ver &
263 ZYNQMP_CSU_VERSION_MASK))
264 break;
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530265 }
Michal Simek8111aff2016-02-01 15:05:58 +0100266 }
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530267
268 if (i >= ARRAY_SIZE(zynqmp_devices))
269 return "unknown";
270
Siva Durga Prasad Paladugu951c0192018-10-26 17:47:55 +0530271 strncat(name, "zu", 2);
272 if (!zynqmp_devices[i].evexists ||
273 (ver & ZYNQMP_PL_STATUS_MASK)) {
274 strncat(name, zynqmp_devices[i].name,
275 ZYNQMP_VERSION_SIZE - 3);
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530276 return name;
Siva Durga Prasad Paladugu951c0192018-10-26 17:47:55 +0530277 }
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530278
Siva Durga Prasad Paladugu951c0192018-10-26 17:47:55 +0530279 /*
280 * Here we are means, PL not powered up and ev variant
281 * exists. So, we need to ignore VCU disable bit(8) in
282 * version and findout if its CG or EG/EV variant.
283 */
284 for (j = 0; j < MAX_VARIANTS_EV; j++, i++) {
285 if ((zynqmp_devices[i].ver & ~BIT(ZYNQMP_IPDIS_VCU_BIT)) ==
286 (ver & ZYNQMP_CSU_VCUDIS_VER_MASK)) {
287 strncat(name, zynqmp_devices[i].name,
288 ZYNQMP_VERSION_SIZE - 3);
289 break;
290 }
291 }
292
293 if (j >= MAX_VARIANTS_EV)
294 return "unknown";
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530295
296 if (strstr(name, "eg") || strstr(name, "ev")) {
297 buf = strstr(name, "e");
298 *buf = '\0';
299 }
300
301 return name;
Michal Simek8111aff2016-02-01 15:05:58 +0100302}
303#endif
304
Michal Simek8b353302017-02-07 14:32:26 +0100305int board_early_init_f(void)
306{
Michal Simekc8785f22018-01-10 11:48:48 +0100307 int ret = 0;
Michal Simek8b353302017-02-07 14:32:26 +0100308#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_CLK_ZYNQMP)
Siva Durga Prasad Paladugu8406d472018-08-21 15:44:49 +0530309 u32 pm_api_version;
310
311 pm_api_version = zynqmp_pmufw_version();
312 printf("PMUFW:\tv%d.%d\n",
313 pm_api_version >> ZYNQMP_PM_VERSION_MAJOR_SHIFT,
314 pm_api_version & ZYNQMP_PM_VERSION_MINOR_MASK);
315
316 if (pm_api_version < ZYNQMP_PM_VERSION)
317 panic("PMUFW version error. Expected: v%d.%d\n",
318 ZYNQMP_PM_VERSION_MAJOR, ZYNQMP_PM_VERSION_MINOR);
Michal Simek8b353302017-02-07 14:32:26 +0100319#endif
Michal Simeke0f36102017-07-12 13:08:41 +0200320
Michal Simek1a1ab5a2018-01-15 12:52:59 +0100321#if defined(CONFIG_ZYNQMP_PSU_INIT_ENABLED)
Michal Simekc8785f22018-01-10 11:48:48 +0100322 ret = psu_init();
Michal Simeke0f36102017-07-12 13:08:41 +0200323#endif
324
Michal Simekc8785f22018-01-10 11:48:48 +0100325 return ret;
Michal Simek8b353302017-02-07 14:32:26 +0100326}
327
Michal Simek04b7e622015-01-15 10:01:51 +0100328int board_init(void)
329{
Michal Simekfb7242d2015-06-22 14:31:06 +0200330 printf("EL Level:\tEL%d\n", current_el());
331
Michal Simek8111aff2016-02-01 15:05:58 +0100332#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
333 !defined(CONFIG_SPL_BUILD) || (defined(CONFIG_SPL_FPGA_SUPPORT) && \
334 defined(CONFIG_SPL_BUILD))
335 if (current_el() != 3) {
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530336 zynqmppl.name = zynqmp_get_silicon_idcode_name();
Michal Simek8111aff2016-02-01 15:05:58 +0100337 printf("Chip ID:\t%s\n", zynqmppl.name);
338 fpga_init();
339 fpga_add(fpga_xilinx, &zynqmppl);
340 }
Michal Simekbf0f9ca2018-04-19 15:43:38 +0200341#endif
342
Michal Simek04b7e622015-01-15 10:01:51 +0100343 return 0;
344}
345
346int board_early_init_r(void)
347{
348 u32 val;
349
Siva Durga Prasad Paladugu64d90002017-12-07 15:05:30 +0530350 if (current_el() != 3)
351 return 0;
352
Michal Simek245d5282017-07-12 10:32:18 +0200353 val = readl(&crlapb_base->timestamp_ref_ctrl);
354 val &= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
355
Siva Durga Prasad Paladugu64d90002017-12-07 15:05:30 +0530356 if (!val) {
Michal Simekc23d3f82015-11-05 08:34:35 +0100357 val = readl(&crlapb_base->timestamp_ref_ctrl);
358 val |= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
359 writel(val, &crlapb_base->timestamp_ref_ctrl);
Michal Simek04b7e622015-01-15 10:01:51 +0100360
Michal Simekc23d3f82015-11-05 08:34:35 +0100361 /* Program freq register in System counter */
362 writel(zynqmp_get_system_timer_freq(),
363 &iou_scntr_secure->base_frequency_id_register);
364 /* And enable system counter */
365 writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN,
366 &iou_scntr_secure->counter_control_register);
367 }
Michal Simek04b7e622015-01-15 10:01:51 +0100368 return 0;
369}
370
Nitin Jainb2eb59b2018-02-16 12:56:17 +0530371unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc,
372 char * const argv[])
373{
374 int ret = 0;
375
376 if (current_el() > 1) {
377 smp_kick_all_cpus();
378 dcache_disable();
379 armv8_switch_to_el1(0x0, 0, 0, 0, (unsigned long)entry,
380 ES_TO_AARCH64);
381 } else {
382 printf("FAIL: current EL is not above EL1\n");
383 ret = EINVAL;
384 }
385 return ret;
386}
387
Michal Simek8faa66a2016-02-08 09:34:53 +0100388#if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE)
Simon Glass2f949c32017-03-31 08:40:32 -0600389int dram_init_banksize(void)
Michal Simek8faa66a2016-02-08 09:34:53 +0100390{
Nitin Jain9bcc76f2018-04-20 12:30:40 +0530391 int ret;
392
393 ret = fdtdec_setup_memory_banksize();
394 if (ret)
395 return ret;
396
397 mem_map_fill();
398
399 return 0;
Tom Riniedcfdbd2016-12-09 07:56:54 -0500400}
Michal Simek8faa66a2016-02-08 09:34:53 +0100401
Tom Riniedcfdbd2016-12-09 07:56:54 -0500402int dram_init(void)
403{
Siva Durga Prasad Paladugub3d55ea2018-07-16 15:56:11 +0530404 if (fdtdec_setup_mem_size_base() != 0)
Nathan Rossiac04bfa2016-12-19 00:03:34 +1000405 return -EINVAL;
Tom Riniedcfdbd2016-12-09 07:56:54 -0500406
407 return 0;
Michal Simek8faa66a2016-02-08 09:34:53 +0100408}
409#else
Nitin Jain9bcc76f2018-04-20 12:30:40 +0530410int dram_init_banksize(void)
411{
412#if defined(CONFIG_NR_DRAM_BANKS)
413 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
414 gd->bd->bi_dram[0].size = get_effective_memsize();
415#endif
416
417 mem_map_fill();
418
419 return 0;
420}
421
Michal Simek04b7e622015-01-15 10:01:51 +0100422int dram_init(void)
423{
Michal Simek1b846212018-04-11 16:12:28 +0200424 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
425 CONFIG_SYS_SDRAM_SIZE);
Michal Simek04b7e622015-01-15 10:01:51 +0100426
427 return 0;
428}
Michal Simek8faa66a2016-02-08 09:34:53 +0100429#endif
Michal Simek04b7e622015-01-15 10:01:51 +0100430
Michal Simek04b7e622015-01-15 10:01:51 +0100431void reset_cpu(ulong addr)
432{
433}
434
Michal Simek342edfe2018-12-20 09:33:38 +0100435#if defined(CONFIG_BOARD_LATE_INIT)
Michal Simek29b9b712018-05-17 14:06:06 +0200436static const struct {
437 u32 bit;
438 const char *name;
439} reset_reasons[] = {
440 { RESET_REASON_DEBUG_SYS, "DEBUG" },
441 { RESET_REASON_SOFT, "SOFT" },
442 { RESET_REASON_SRST, "SRST" },
443 { RESET_REASON_PSONLY, "PS-ONLY" },
444 { RESET_REASON_PMU, "PMU" },
445 { RESET_REASON_INTERNAL, "INTERNAL" },
446 { RESET_REASON_EXTERNAL, "EXTERNAL" },
447 {}
448};
449
T Karthik Reddy09b6def2019-03-13 20:24:18 +0530450static int reset_reason(void)
Michal Simek29b9b712018-05-17 14:06:06 +0200451{
T Karthik Reddy09b6def2019-03-13 20:24:18 +0530452 u32 reg;
453 int i, ret;
Michal Simek29b9b712018-05-17 14:06:06 +0200454 const char *reason = NULL;
455
T Karthik Reddy09b6def2019-03-13 20:24:18 +0530456 ret = zynqmp_mmio_read((ulong)&crlapb_base->reset_reason, &reg);
457 if (ret)
458 return -EINVAL;
Michal Simek29b9b712018-05-17 14:06:06 +0200459
460 puts("Reset reason:\t");
461
462 for (i = 0; i < ARRAY_SIZE(reset_reasons); i++) {
T Karthik Reddy09b6def2019-03-13 20:24:18 +0530463 if (reg & reset_reasons[i].bit) {
Michal Simek29b9b712018-05-17 14:06:06 +0200464 reason = reset_reasons[i].name;
465 printf("%s ", reset_reasons[i].name);
466 break;
467 }
468 }
469
470 puts("\n");
471
472 env_set("reset_reason", reason);
473
T Karthik Reddy09b6def2019-03-13 20:24:18 +0530474 ret = zynqmp_mmio_write(~0, ~0, (ulong)&crlapb_base->reset_reason);
475 if (ret)
476 return -EINVAL;
Michal Simek29b9b712018-05-17 14:06:06 +0200477
478 return ret;
479}
480
Michal Simek1ca66d72019-02-14 13:14:30 +0100481static int set_fdtfile(void)
482{
483 char *compatible, *fdtfile;
484 const char *suffix = ".dtb";
485 const char *vendor = "xilinx/";
486
487 if (env_get("fdtfile"))
488 return 0;
489
490 compatible = (char *)fdt_getprop(gd->fdt_blob, 0, "compatible", NULL);
491 if (compatible) {
492 debug("Compatible: %s\n", compatible);
493
494 /* Discard vendor prefix */
495 strsep(&compatible, ",");
496
497 fdtfile = calloc(1, strlen(vendor) + strlen(compatible) +
498 strlen(suffix) + 1);
499 if (!fdtfile)
500 return -ENOMEM;
501
502 sprintf(fdtfile, "%s%s%s", vendor, compatible, suffix);
503
504 env_set("fdtfile", fdtfile);
505 free(fdtfile);
506 }
507
508 return 0;
509}
510
Michal Simek04b7e622015-01-15 10:01:51 +0100511int board_late_init(void)
512{
513 u32 reg = 0;
514 u8 bootmode;
Michal Simekf183a982018-04-25 11:20:43 +0200515 struct udevice *dev;
516 int bootseq = -1;
517 int bootseq_len = 0;
Michal Simek7410b142018-04-25 11:10:34 +0200518 int env_targets_len = 0;
Michal Simekecfb6dc2016-04-22 14:28:54 +0200519 const char *mode;
520 char *new_targets;
Siva Durga Prasad Paladugu245c5562017-12-20 16:35:06 +0530521 char *env_targets;
Siva Durga Prasad Paladugue6fd3bb2017-02-21 17:58:28 +0530522 int ret;
Michal Simekecfb6dc2016-04-22 14:28:54 +0200523
Michal Simek482f5492018-10-05 08:55:16 +0200524#if defined(CONFIG_USB_ETHER) && !defined(CONFIG_USB_GADGET_DOWNLOAD)
525 usb_ether_init();
526#endif
527
Michal Simekecfb6dc2016-04-22 14:28:54 +0200528 if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
529 debug("Saved variables - Skipping\n");
530 return 0;
531 }
Michal Simek04b7e622015-01-15 10:01:51 +0100532
Michal Simek1ca66d72019-02-14 13:14:30 +0100533 ret = set_fdtfile();
534 if (ret)
535 return ret;
536
Siva Durga Prasad Paladugue6fd3bb2017-02-21 17:58:28 +0530537 ret = zynqmp_mmio_read((ulong)&crlapb_base->boot_mode, &reg);
538 if (ret)
539 return -EINVAL;
540
Michal Simek833e0c42016-10-25 11:43:02 +0200541 if (reg >> BOOT_MODE_ALT_SHIFT)
542 reg >>= BOOT_MODE_ALT_SHIFT;
543
Michal Simek04b7e622015-01-15 10:01:51 +0100544 bootmode = reg & BOOT_MODES_MASK;
545
Michal Simekc5d95232015-09-20 17:20:42 +0200546 puts("Bootmode: ");
Michal Simek04b7e622015-01-15 10:01:51 +0100547 switch (bootmode) {
Michal Simek12398ea2016-08-19 14:14:52 +0200548 case USB_MODE:
549 puts("USB_MODE\n");
550 mode = "usb";
Michal Simek43380352017-12-01 15:18:24 +0100551 env_set("modeboot", "usb_dfu_spl");
Michal Simek12398ea2016-08-19 14:14:52 +0200552 break;
Siva Durga Prasad Paladugu30f0fc72015-03-13 11:10:26 +0530553 case JTAG_MODE:
Michal Simekc5d95232015-09-20 17:20:42 +0200554 puts("JTAG_MODE\n");
Michal Simekecfb6dc2016-04-22 14:28:54 +0200555 mode = "pxe dhcp";
Michal Simek43380352017-12-01 15:18:24 +0100556 env_set("modeboot", "jtagboot");
Siva Durga Prasad Paladugu30f0fc72015-03-13 11:10:26 +0530557 break;
558 case QSPI_MODE_24BIT:
559 case QSPI_MODE_32BIT:
Michal Simekecfb6dc2016-04-22 14:28:54 +0200560 mode = "qspi0";
Michal Simekc5d95232015-09-20 17:20:42 +0200561 puts("QSPI_MODE\n");
Michal Simek43380352017-12-01 15:18:24 +0100562 env_set("modeboot", "qspiboot");
Siva Durga Prasad Paladugu30f0fc72015-03-13 11:10:26 +0530563 break;
Michal Simek02d66cd2015-04-15 15:02:28 +0200564 case EMMC_MODE:
Michal Simekdf7ff0a2015-10-05 15:59:38 +0200565 puts("EMMC_MODE\n");
Michal Simekecfb6dc2016-04-22 14:28:54 +0200566 mode = "mmc0";
Michal Simek43380352017-12-01 15:18:24 +0100567 env_set("modeboot", "emmcboot");
Michal Simekdf7ff0a2015-10-05 15:59:38 +0200568 break;
569 case SD_MODE:
Michal Simekc5d95232015-09-20 17:20:42 +0200570 puts("SD_MODE\n");
Michal Simekf183a982018-04-25 11:20:43 +0200571 if (uclass_get_device_by_name(UCLASS_MMC,
Siva Durga Prasad Paladugue91778d2019-01-03 15:44:24 +0530572 "mmc@ff160000", &dev) &&
573 uclass_get_device_by_name(UCLASS_MMC,
Michal Simekf183a982018-04-25 11:20:43 +0200574 "sdhci@ff160000", &dev)) {
575 puts("Boot from SD0 but without SD0 enabled!\n");
576 return -1;
577 }
578 debug("mmc0 device found at %p, seq %d\n", dev, dev->seq);
579
580 mode = "mmc";
581 bootseq = dev->seq;
Michal Simek43380352017-12-01 15:18:24 +0100582 env_set("modeboot", "sdboot");
Michal Simek04b7e622015-01-15 10:01:51 +0100583 break;
Siva Durga Prasad Paladugu29a77d22016-09-21 11:45:05 +0530584 case SD1_LSHFT_MODE:
585 puts("LVL_SHFT_");
586 /* fall through */
Michal Simek108e1842015-10-05 10:51:12 +0200587 case SD_MODE1:
Michal Simekc5d95232015-09-20 17:20:42 +0200588 puts("SD_MODE1\n");
Michal Simekf183a982018-04-25 11:20:43 +0200589 if (uclass_get_device_by_name(UCLASS_MMC,
Siva Durga Prasad Paladugue91778d2019-01-03 15:44:24 +0530590 "mmc@ff170000", &dev) &&
591 uclass_get_device_by_name(UCLASS_MMC,
Michal Simekf183a982018-04-25 11:20:43 +0200592 "sdhci@ff170000", &dev)) {
593 puts("Boot from SD1 but without SD1 enabled!\n");
594 return -1;
595 }
596 debug("mmc1 device found at %p, seq %d\n", dev, dev->seq);
597
598 mode = "mmc";
599 bootseq = dev->seq;
Michal Simek43380352017-12-01 15:18:24 +0100600 env_set("modeboot", "sdboot");
Michal Simek108e1842015-10-05 10:51:12 +0200601 break;
602 case NAND_MODE:
Michal Simekc5d95232015-09-20 17:20:42 +0200603 puts("NAND_MODE\n");
Michal Simekecfb6dc2016-04-22 14:28:54 +0200604 mode = "nand0";
Michal Simek43380352017-12-01 15:18:24 +0100605 env_set("modeboot", "nandboot");
Michal Simek108e1842015-10-05 10:51:12 +0200606 break;
Michal Simek04b7e622015-01-15 10:01:51 +0100607 default:
Michal Simekecfb6dc2016-04-22 14:28:54 +0200608 mode = "";
Michal Simek04b7e622015-01-15 10:01:51 +0100609 printf("Invalid Boot Mode:0x%x\n", bootmode);
610 break;
611 }
612
Michal Simekf183a982018-04-25 11:20:43 +0200613 if (bootseq >= 0) {
614 bootseq_len = snprintf(NULL, 0, "%i", bootseq);
615 debug("Bootseq len: %x\n", bootseq_len);
616 }
617
Michal Simekecfb6dc2016-04-22 14:28:54 +0200618 /*
619 * One terminating char + one byte for space between mode
620 * and default boot_targets
621 */
Siva Durga Prasad Paladugu245c5562017-12-20 16:35:06 +0530622 env_targets = env_get("boot_targets");
Michal Simek7410b142018-04-25 11:10:34 +0200623 if (env_targets)
624 env_targets_len = strlen(env_targets);
625
Michal Simekf183a982018-04-25 11:20:43 +0200626 new_targets = calloc(1, strlen(mode) + env_targets_len + 2 +
627 bootseq_len);
Michal Simek089b84d2018-06-13 09:42:41 +0200628 if (!new_targets)
629 return -ENOMEM;
Michal Simek7410b142018-04-25 11:10:34 +0200630
Michal Simekf183a982018-04-25 11:20:43 +0200631 if (bootseq >= 0)
632 sprintf(new_targets, "%s%x %s", mode, bootseq,
633 env_targets ? env_targets : "");
634 else
635 sprintf(new_targets, "%s %s", mode,
636 env_targets ? env_targets : "");
Michal Simekecfb6dc2016-04-22 14:28:54 +0200637
Simon Glass6a38e412017-08-03 12:22:09 -0600638 env_set("boot_targets", new_targets);
Michal Simekecfb6dc2016-04-22 14:28:54 +0200639
Michal Simek29b9b712018-05-17 14:06:06 +0200640 reset_reason();
641
Michal Simek04b7e622015-01-15 10:01:51 +0100642 return 0;
643}
Michal Simek342edfe2018-12-20 09:33:38 +0100644#endif
Siva Durga Prasad Paladugu650e0a32015-08-04 13:01:05 +0530645
646int checkboard(void)
647{
Michal Simek47ce9362016-01-25 11:04:21 +0100648 puts("Board: Xilinx ZynqMP\n");
Siva Durga Prasad Paladugu650e0a32015-08-04 13:01:05 +0530649 return 0;
650}