blob: b94936474d7e3fa157e39ff605e156d89224747b [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Michal Simek84c72042015-01-15 10:01:51 +01002/*
3 * (C) Copyright 2014 - 2015 Xilinx, Inc.
4 * Michal Simek <michal.simek@xilinx.com>
Michal Simek84c72042015-01-15 10:01:51 +01005 */
6
7#include <common.h>
Simon Glass9fb625c2019-08-01 09:46:51 -06008#include <env.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 Simek4490e012018-04-19 15:43:38 +020013#include <wdt.h>
Michal Simek0785dfd2015-11-05 08:34:35 +010014#include <asm/arch/clk.h>
Michal Simek84c72042015-01-15 10:01:51 +010015#include <asm/arch/hardware.h>
16#include <asm/arch/sys_proto.h>
Michal Simek2ad341e2018-01-10 09:36:09 +010017#include <asm/arch/psu_init_gpl.h>
Michal Simek84c72042015-01-15 10:01:51 +010018#include <asm/io.h>
Michal Simek2882b392018-04-25 11:20:43 +020019#include <dm/device.h>
Michal Simek4490e012018-04-19 15:43:38 +020020#include <dm/uclass.h>
Siva Durga Prasad Paladugu16fa00a2015-08-04 13:03:26 +053021#include <usb.h>
22#include <dwc3-uboot.h>
Michal Simek47e60cb2016-02-01 15:05:58 +010023#include <zynqmppl.h>
Ibai Erkiaga009ab7b2019-09-27 11:37:01 +010024#include <zynqmp_firmware.h>
Michal Simek9feff382016-09-01 11:16:40 +020025#include <g_dnl.h>
T Karthik Reddya69814c2019-08-20 09:30:57 +053026#include <linux/sizes.h>
Michal Simek84c72042015-01-15 10:01:51 +010027
Luca Ceresolic28a9cf2019-05-21 18:06:43 +020028#include "pm_cfg_obj.h"
29
Michal Simek84c72042015-01-15 10:01:51 +010030DECLARE_GLOBAL_DATA_PTR;
31
Michal Simek47e60cb2016-02-01 15:05:58 +010032#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
33 !defined(CONFIG_SPL_BUILD)
34static xilinx_desc zynqmppl = XILINX_ZYNQMP_DESC;
35
36static const struct {
Michal Simek8ebdf9e2017-11-06 12:55:59 +010037 u32 id;
Michal Simek494fffe2017-08-22 14:58:53 +020038 u32 ver;
Michal Simek47e60cb2016-02-01 15:05:58 +010039 char *name;
Siva Durga Prasad Paladugu83bf2ff2018-03-02 16:20:10 +053040 bool evexists;
Michal Simek47e60cb2016-02-01 15:05:58 +010041} zynqmp_devices[] = {
42 {
43 .id = 0x10,
44 .name = "3eg",
45 },
46 {
Michal Simek494fffe2017-08-22 14:58:53 +020047 .id = 0x10,
48 .ver = 0x2c,
49 .name = "3cg",
50 },
51 {
Michal Simek47e60cb2016-02-01 15:05:58 +010052 .id = 0x11,
53 .name = "2eg",
54 },
55 {
Michal Simek494fffe2017-08-22 14:58:53 +020056 .id = 0x11,
57 .ver = 0x2c,
58 .name = "2cg",
59 },
60 {
Michal Simek47e60cb2016-02-01 15:05:58 +010061 .id = 0x20,
62 .name = "5ev",
Siva Durga Prasad Paladugu83bf2ff2018-03-02 16:20:10 +053063 .evexists = 1,
Michal Simek47e60cb2016-02-01 15:05:58 +010064 },
65 {
Michal Simek494fffe2017-08-22 14:58:53 +020066 .id = 0x20,
67 .ver = 0x100,
68 .name = "5eg",
Siva Durga Prasad Paladugu83bf2ff2018-03-02 16:20:10 +053069 .evexists = 1,
Michal Simek494fffe2017-08-22 14:58:53 +020070 },
71 {
72 .id = 0x20,
73 .ver = 0x12c,
74 .name = "5cg",
Siva Durga Prasad Paladugu5473f242018-10-26 17:47:55 +053075 .evexists = 1,
Michal Simek494fffe2017-08-22 14:58:53 +020076 },
77 {
Michal Simek47e60cb2016-02-01 15:05:58 +010078 .id = 0x21,
79 .name = "4ev",
Siva Durga Prasad Paladugu83bf2ff2018-03-02 16:20:10 +053080 .evexists = 1,
Michal Simek47e60cb2016-02-01 15:05:58 +010081 },
82 {
Michal Simek494fffe2017-08-22 14:58:53 +020083 .id = 0x21,
84 .ver = 0x100,
85 .name = "4eg",
Siva Durga Prasad Paladugu83bf2ff2018-03-02 16:20:10 +053086 .evexists = 1,
Michal Simek494fffe2017-08-22 14:58:53 +020087 },
88 {
89 .id = 0x21,
90 .ver = 0x12c,
91 .name = "4cg",
Siva Durga Prasad Paladugu5473f242018-10-26 17:47:55 +053092 .evexists = 1,
Michal Simek494fffe2017-08-22 14:58:53 +020093 },
94 {
Michal Simek47e60cb2016-02-01 15:05:58 +010095 .id = 0x30,
96 .name = "7ev",
Siva Durga Prasad Paladugu83bf2ff2018-03-02 16:20:10 +053097 .evexists = 1,
Michal Simek47e60cb2016-02-01 15:05:58 +010098 },
99 {
Michal Simek494fffe2017-08-22 14:58:53 +0200100 .id = 0x30,
101 .ver = 0x100,
102 .name = "7eg",
Siva Durga Prasad Paladugu83bf2ff2018-03-02 16:20:10 +0530103 .evexists = 1,
Michal Simek494fffe2017-08-22 14:58:53 +0200104 },
105 {
106 .id = 0x30,
107 .ver = 0x12c,
108 .name = "7cg",
Siva Durga Prasad Paladugu5473f242018-10-26 17:47:55 +0530109 .evexists = 1,
Michal Simek494fffe2017-08-22 14:58:53 +0200110 },
111 {
Michal Simek47e60cb2016-02-01 15:05:58 +0100112 .id = 0x38,
113 .name = "9eg",
114 },
115 {
Michal Simek494fffe2017-08-22 14:58:53 +0200116 .id = 0x38,
117 .ver = 0x2c,
118 .name = "9cg",
119 },
120 {
Michal Simek47e60cb2016-02-01 15:05:58 +0100121 .id = 0x39,
122 .name = "6eg",
123 },
124 {
Michal Simek494fffe2017-08-22 14:58:53 +0200125 .id = 0x39,
126 .ver = 0x2c,
127 .name = "6cg",
128 },
129 {
Michal Simek47e60cb2016-02-01 15:05:58 +0100130 .id = 0x40,
131 .name = "11eg",
132 },
Michal Simek494fffe2017-08-22 14:58:53 +0200133 { /* For testing purpose only */
134 .id = 0x50,
135 .ver = 0x2c,
136 .name = "15cg",
137 },
Michal Simek47e60cb2016-02-01 15:05:58 +0100138 {
139 .id = 0x50,
140 .name = "15eg",
141 },
142 {
143 .id = 0x58,
144 .name = "19eg",
145 },
146 {
147 .id = 0x59,
148 .name = "17eg",
149 },
Michal Simekb030fed2017-06-02 08:08:59 +0200150 {
151 .id = 0x61,
152 .name = "21dr",
153 },
154 {
155 .id = 0x63,
156 .name = "23dr",
157 },
158 {
159 .id = 0x65,
160 .name = "25dr",
161 },
162 {
163 .id = 0x64,
164 .name = "27dr",
165 },
166 {
167 .id = 0x60,
168 .name = "28dr",
169 },
170 {
171 .id = 0x62,
172 .name = "29dr",
173 },
Siva Durga Prasad Paladuguc7490902019-03-23 15:00:06 +0530174 {
175 .id = 0x66,
176 .name = "39dr",
177 },
Siva Durga Prasad Paladugu134b0c82019-07-23 11:56:17 +0530178 {
179 .id = 0x7b,
180 .name = "48dr",
181 },
182 {
183 .id = 0x7e,
184 .name = "49dr",
185 },
Michal Simek47e60cb2016-02-01 15:05:58 +0100186};
Siva Durga Prasad Paladugu74ba69d2017-07-25 11:51:37 +0530187#endif
Michal Simek47e60cb2016-02-01 15:05:58 +0100188
Siva Durga Prasad Paladuguf52bf5a2017-07-25 11:51:38 +0530189int chip_id(unsigned char id)
Michal Simek47e60cb2016-02-01 15:05:58 +0100190{
191 struct pt_regs regs;
Siva Durga Prasad Paladugudb3123b2017-07-25 11:51:36 +0530192 int val = -EINVAL;
Michal Simek47e60cb2016-02-01 15:05:58 +0100193
Siva Durga Prasad Paladugu74ba69d2017-07-25 11:51:37 +0530194 if (current_el() != 3) {
195 regs.regs[0] = ZYNQMP_SIP_SVC_CSU_DMA_CHIPID;
196 regs.regs[1] = 0;
197 regs.regs[2] = 0;
198 regs.regs[3] = 0;
Michal Simek47e60cb2016-02-01 15:05:58 +0100199
Siva Durga Prasad Paladugu74ba69d2017-07-25 11:51:37 +0530200 smc_call(&regs);
201
202 /*
203 * SMC returns:
204 * regs[0][31:0] = status of the operation
205 * regs[0][63:32] = CSU.IDCODE register
206 * regs[1][31:0] = CSU.version register
Michal Simek494fffe2017-08-22 14:58:53 +0200207 * regs[1][63:32] = CSU.IDCODE2 register
Siva Durga Prasad Paladugu74ba69d2017-07-25 11:51:37 +0530208 */
209 switch (id) {
210 case IDCODE:
211 regs.regs[0] = upper_32_bits(regs.regs[0]);
212 regs.regs[0] &= ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK |
213 ZYNQMP_CSU_IDCODE_SVD_MASK;
214 regs.regs[0] >>= ZYNQMP_CSU_IDCODE_SVD_SHIFT;
215 val = regs.regs[0];
216 break;
217 case VERSION:
218 regs.regs[1] = lower_32_bits(regs.regs[1]);
219 regs.regs[1] &= ZYNQMP_CSU_SILICON_VER_MASK;
220 val = regs.regs[1];
221 break;
Michal Simek494fffe2017-08-22 14:58:53 +0200222 case IDCODE2:
223 regs.regs[1] = lower_32_bits(regs.regs[1]);
224 regs.regs[1] >>= ZYNQMP_CSU_VERSION_EMPTY_SHIFT;
225 val = regs.regs[1];
226 break;
Siva Durga Prasad Paladugu74ba69d2017-07-25 11:51:37 +0530227 default:
228 printf("%s, Invalid Req:0x%x\n", __func__, id);
229 }
230 } else {
231 switch (id) {
232 case IDCODE:
233 val = readl(ZYNQMP_CSU_IDCODE_ADDR);
234 val &= ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK |
235 ZYNQMP_CSU_IDCODE_SVD_MASK;
236 val >>= ZYNQMP_CSU_IDCODE_SVD_SHIFT;
237 break;
238 case VERSION:
239 val = readl(ZYNQMP_CSU_VER_ADDR);
240 val &= ZYNQMP_CSU_SILICON_VER_MASK;
241 break;
242 default:
243 printf("%s, Invalid Req:0x%x\n", __func__, id);
244 }
Siva Durga Prasad Paladugudb3123b2017-07-25 11:51:36 +0530245 }
Soren Brinkmann0cba6ab2016-09-29 11:44:41 -0700246
Siva Durga Prasad Paladugudb3123b2017-07-25 11:51:36 +0530247 return val;
Michal Simek47e60cb2016-02-01 15:05:58 +0100248}
249
Siva Durga Prasad Paladugu83bf2ff2018-03-02 16:20:10 +0530250#define ZYNQMP_VERSION_SIZE 9
251#define ZYNQMP_PL_STATUS_BIT 9
Siva Durga Prasad Paladugu5473f242018-10-26 17:47:55 +0530252#define ZYNQMP_IPDIS_VCU_BIT 8
Siva Durga Prasad Paladugu83bf2ff2018-03-02 16:20:10 +0530253#define ZYNQMP_PL_STATUS_MASK BIT(ZYNQMP_PL_STATUS_BIT)
254#define ZYNQMP_CSU_VERSION_MASK ~(ZYNQMP_PL_STATUS_MASK)
Siva Durga Prasad Paladugu5473f242018-10-26 17:47:55 +0530255#define ZYNQMP_CSU_VCUDIS_VER_MASK ZYNQMP_CSU_VERSION_MASK & \
256 ~BIT(ZYNQMP_IPDIS_VCU_BIT)
257#define MAX_VARIANTS_EV 3
Siva Durga Prasad Paladugu83bf2ff2018-03-02 16:20:10 +0530258
Siva Durga Prasad Paladugu74ba69d2017-07-25 11:51:37 +0530259#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
260 !defined(CONFIG_SPL_BUILD)
Michal Simek47e60cb2016-02-01 15:05:58 +0100261static char *zynqmp_get_silicon_idcode_name(void)
262{
Siva Durga Prasad Paladugu5473f242018-10-26 17:47:55 +0530263 u32 i, id, ver, j;
Siva Durga Prasad Paladugu83bf2ff2018-03-02 16:20:10 +0530264 char *buf;
265 static char name[ZYNQMP_VERSION_SIZE];
Michal Simek47e60cb2016-02-01 15:05:58 +0100266
Siva Durga Prasad Paladugudb3123b2017-07-25 11:51:36 +0530267 id = chip_id(IDCODE);
Michal Simek494fffe2017-08-22 14:58:53 +0200268 ver = chip_id(IDCODE2);
269
Michal Simek47e60cb2016-02-01 15:05:58 +0100270 for (i = 0; i < ARRAY_SIZE(zynqmp_devices); i++) {
Siva Durga Prasad Paladugu5473f242018-10-26 17:47:55 +0530271 if (zynqmp_devices[i].id == id) {
272 if (zynqmp_devices[i].evexists &&
273 !(ver & ZYNQMP_PL_STATUS_MASK))
274 break;
275 if (zynqmp_devices[i].ver == (ver &
276 ZYNQMP_CSU_VERSION_MASK))
277 break;
Siva Durga Prasad Paladugu83bf2ff2018-03-02 16:20:10 +0530278 }
Michal Simek47e60cb2016-02-01 15:05:58 +0100279 }
Siva Durga Prasad Paladugu83bf2ff2018-03-02 16:20:10 +0530280
281 if (i >= ARRAY_SIZE(zynqmp_devices))
282 return "unknown";
283
Siva Durga Prasad Paladugu5473f242018-10-26 17:47:55 +0530284 strncat(name, "zu", 2);
285 if (!zynqmp_devices[i].evexists ||
286 (ver & ZYNQMP_PL_STATUS_MASK)) {
287 strncat(name, zynqmp_devices[i].name,
288 ZYNQMP_VERSION_SIZE - 3);
Siva Durga Prasad Paladugu83bf2ff2018-03-02 16:20:10 +0530289 return name;
Siva Durga Prasad Paladugu5473f242018-10-26 17:47:55 +0530290 }
Siva Durga Prasad Paladugu83bf2ff2018-03-02 16:20:10 +0530291
Siva Durga Prasad Paladugu5473f242018-10-26 17:47:55 +0530292 /*
293 * Here we are means, PL not powered up and ev variant
294 * exists. So, we need to ignore VCU disable bit(8) in
295 * version and findout if its CG or EG/EV variant.
296 */
297 for (j = 0; j < MAX_VARIANTS_EV; j++, i++) {
298 if ((zynqmp_devices[i].ver & ~BIT(ZYNQMP_IPDIS_VCU_BIT)) ==
299 (ver & ZYNQMP_CSU_VCUDIS_VER_MASK)) {
300 strncat(name, zynqmp_devices[i].name,
301 ZYNQMP_VERSION_SIZE - 3);
302 break;
303 }
304 }
305
306 if (j >= MAX_VARIANTS_EV)
307 return "unknown";
Siva Durga Prasad Paladugu83bf2ff2018-03-02 16:20:10 +0530308
309 if (strstr(name, "eg") || strstr(name, "ev")) {
310 buf = strstr(name, "e");
311 *buf = '\0';
312 }
313
314 return name;
Michal Simek47e60cb2016-02-01 15:05:58 +0100315}
316#endif
317
Michal Simekfb4000e2017-02-07 14:32:26 +0100318int board_early_init_f(void)
319{
Michal Simekf32e79f2018-01-10 11:48:48 +0100320 int ret = 0;
Michal Simek55de0922017-07-12 13:08:41 +0200321
Michal Simek88f05a92018-01-15 12:52:59 +0100322#if defined(CONFIG_ZYNQMP_PSU_INIT_ENABLED)
Michal Simekf32e79f2018-01-10 11:48:48 +0100323 ret = psu_init();
Michal Simek55de0922017-07-12 13:08:41 +0200324#endif
325
Michal Simekf32e79f2018-01-10 11:48:48 +0100326 return ret;
Michal Simekfb4000e2017-02-07 14:32:26 +0100327}
328
Michal Simek84c72042015-01-15 10:01:51 +0100329int board_init(void)
330{
Ibai Erkiaga325a22d2019-09-27 11:37:04 +0100331 struct udevice *dev;
332
333 uclass_get_device_by_name(UCLASS_FIRMWARE, "zynqmp-power", &dev);
334 if (!dev)
335 panic("PMU Firmware device not found - Enable it");
336
Luca Ceresolic28a9cf2019-05-21 18:06:43 +0200337#if defined(CONFIG_SPL_BUILD)
338 /* Check *at build time* if the filename is an non-empty string */
339 if (sizeof(CONFIG_ZYNQMP_SPL_PM_CFG_OBJ_FILE) > 1)
340 zynqmp_pmufw_load_config_object(zynqmp_pm_cfg_obj,
341 zynqmp_pm_cfg_obj_size);
342#endif
343
Michal Simeka0736ef2015-06-22 14:31:06 +0200344 printf("EL Level:\tEL%d\n", current_el());
345
Michal Simek47e60cb2016-02-01 15:05:58 +0100346#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
347 !defined(CONFIG_SPL_BUILD) || (defined(CONFIG_SPL_FPGA_SUPPORT) && \
348 defined(CONFIG_SPL_BUILD))
349 if (current_el() != 3) {
Siva Durga Prasad Paladugu83bf2ff2018-03-02 16:20:10 +0530350 zynqmppl.name = zynqmp_get_silicon_idcode_name();
Michal Simek47e60cb2016-02-01 15:05:58 +0100351 printf("Chip ID:\t%s\n", zynqmppl.name);
352 fpga_init();
353 fpga_add(fpga_xilinx, &zynqmppl);
354 }
355#endif
356
Michal Simek84c72042015-01-15 10:01:51 +0100357 return 0;
358}
359
360int board_early_init_r(void)
361{
362 u32 val;
363
Siva Durga Prasad Paladuguec60a272017-12-07 15:05:30 +0530364 if (current_el() != 3)
365 return 0;
366
Michal Simek90a35db2017-07-12 10:32:18 +0200367 val = readl(&crlapb_base->timestamp_ref_ctrl);
368 val &= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
369
Siva Durga Prasad Paladuguec60a272017-12-07 15:05:30 +0530370 if (!val) {
Michal Simek0785dfd2015-11-05 08:34:35 +0100371 val = readl(&crlapb_base->timestamp_ref_ctrl);
372 val |= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
373 writel(val, &crlapb_base->timestamp_ref_ctrl);
Michal Simek84c72042015-01-15 10:01:51 +0100374
Michal Simek0785dfd2015-11-05 08:34:35 +0100375 /* Program freq register in System counter */
376 writel(zynqmp_get_system_timer_freq(),
377 &iou_scntr_secure->base_frequency_id_register);
378 /* And enable system counter */
379 writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN,
380 &iou_scntr_secure->counter_control_register);
381 }
Michal Simek84c72042015-01-15 10:01:51 +0100382 return 0;
383}
384
Nitin Jain51916862018-02-16 12:56:17 +0530385unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc,
386 char * const argv[])
387{
388 int ret = 0;
389
390 if (current_el() > 1) {
391 smp_kick_all_cpus();
392 dcache_disable();
393 armv8_switch_to_el1(0x0, 0, 0, 0, (unsigned long)entry,
394 ES_TO_AARCH64);
395 } else {
396 printf("FAIL: current EL is not above EL1\n");
397 ret = EINVAL;
398 }
399 return ret;
400}
401
Michal Simek8d59d7f2016-02-08 09:34:53 +0100402#if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE)
Simon Glass76b00ac2017-03-31 08:40:32 -0600403int dram_init_banksize(void)
Tom Rini361a8792016-12-09 07:56:54 -0500404{
Nitin Jain06789412018-04-20 12:30:40 +0530405 int ret;
406
407 ret = fdtdec_setup_memory_banksize();
408 if (ret)
409 return ret;
410
411 mem_map_fill();
412
413 return 0;
Michal Simek8d59d7f2016-02-08 09:34:53 +0100414}
415
416int dram_init(void)
417{
Siva Durga Prasad Paladugu12308b12018-07-16 15:56:11 +0530418 if (fdtdec_setup_mem_size_base() != 0)
Nathan Rossi950f86c2016-12-19 00:03:34 +1000419 return -EINVAL;
Michal Simek8d59d7f2016-02-08 09:34:53 +0100420
421 return 0;
422}
423#else
Nitin Jain06789412018-04-20 12:30:40 +0530424int dram_init_banksize(void)
425{
426#if defined(CONFIG_NR_DRAM_BANKS)
427 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
428 gd->bd->bi_dram[0].size = get_effective_memsize();
429#endif
430
431 mem_map_fill();
432
433 return 0;
434}
435
Michal Simek84c72042015-01-15 10:01:51 +0100436int dram_init(void)
437{
Michal Simek61dc92a2018-04-11 16:12:28 +0200438 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
439 CONFIG_SYS_SDRAM_SIZE);
Michal Simek84c72042015-01-15 10:01:51 +0100440
441 return 0;
442}
Michal Simek8d59d7f2016-02-08 09:34:53 +0100443#endif
Michal Simek84c72042015-01-15 10:01:51 +0100444
Michal Simek84c72042015-01-15 10:01:51 +0100445void reset_cpu(ulong addr)
446{
447}
448
Michal Simek0bf3f9c2018-12-20 09:33:38 +0100449#if defined(CONFIG_BOARD_LATE_INIT)
Michal Simekd348bea2018-05-17 14:06:06 +0200450static const struct {
451 u32 bit;
452 const char *name;
453} reset_reasons[] = {
454 { RESET_REASON_DEBUG_SYS, "DEBUG" },
455 { RESET_REASON_SOFT, "SOFT" },
456 { RESET_REASON_SRST, "SRST" },
457 { RESET_REASON_PSONLY, "PS-ONLY" },
458 { RESET_REASON_PMU, "PMU" },
459 { RESET_REASON_INTERNAL, "INTERNAL" },
460 { RESET_REASON_EXTERNAL, "EXTERNAL" },
461 {}
462};
463
T Karthik Reddybe523722019-03-13 20:24:18 +0530464static int reset_reason(void)
Michal Simekd348bea2018-05-17 14:06:06 +0200465{
T Karthik Reddybe523722019-03-13 20:24:18 +0530466 u32 reg;
467 int i, ret;
Michal Simekd348bea2018-05-17 14:06:06 +0200468 const char *reason = NULL;
469
T Karthik Reddybe523722019-03-13 20:24:18 +0530470 ret = zynqmp_mmio_read((ulong)&crlapb_base->reset_reason, &reg);
471 if (ret)
472 return -EINVAL;
Michal Simekd348bea2018-05-17 14:06:06 +0200473
474 puts("Reset reason:\t");
475
476 for (i = 0; i < ARRAY_SIZE(reset_reasons); i++) {
T Karthik Reddybe523722019-03-13 20:24:18 +0530477 if (reg & reset_reasons[i].bit) {
Michal Simekd348bea2018-05-17 14:06:06 +0200478 reason = reset_reasons[i].name;
479 printf("%s ", reset_reasons[i].name);
480 break;
481 }
482 }
483
484 puts("\n");
485
486 env_set("reset_reason", reason);
487
T Karthik Reddybe523722019-03-13 20:24:18 +0530488 ret = zynqmp_mmio_write(~0, ~0, (ulong)&crlapb_base->reset_reason);
489 if (ret)
490 return -EINVAL;
Michal Simekd348bea2018-05-17 14:06:06 +0200491
492 return ret;
493}
494
Michal Simek91d7e0c2019-02-14 13:14:30 +0100495static int set_fdtfile(void)
496{
497 char *compatible, *fdtfile;
498 const char *suffix = ".dtb";
499 const char *vendor = "xilinx/";
500
501 if (env_get("fdtfile"))
502 return 0;
503
504 compatible = (char *)fdt_getprop(gd->fdt_blob, 0, "compatible", NULL);
505 if (compatible) {
506 debug("Compatible: %s\n", compatible);
507
508 /* Discard vendor prefix */
509 strsep(&compatible, ",");
510
511 fdtfile = calloc(1, strlen(vendor) + strlen(compatible) +
512 strlen(suffix) + 1);
513 if (!fdtfile)
514 return -ENOMEM;
515
516 sprintf(fdtfile, "%s%s%s", vendor, compatible, suffix);
517
518 env_set("fdtfile", fdtfile);
519 free(fdtfile);
520 }
521
522 return 0;
523}
524
Michal Simek84c72042015-01-15 10:01:51 +0100525int board_late_init(void)
526{
527 u32 reg = 0;
528 u8 bootmode;
Michal Simek2882b392018-04-25 11:20:43 +0200529 struct udevice *dev;
530 int bootseq = -1;
531 int bootseq_len = 0;
Michal Simek0478b0b2018-04-25 11:10:34 +0200532 int env_targets_len = 0;
Michal Simekb72894f2016-04-22 14:28:54 +0200533 const char *mode;
534 char *new_targets;
Siva Durga Prasad Paladugu01c42d32017-12-20 16:35:06 +0530535 char *env_targets;
Siva Durga Prasad Paladugud1db89f2017-02-21 17:58:28 +0530536 int ret;
T Karthik Reddya69814c2019-08-20 09:30:57 +0530537 ulong initrd_hi;
Michal Simekb72894f2016-04-22 14:28:54 +0200538
Michal Simeke615f392018-10-05 08:55:16 +0200539#if defined(CONFIG_USB_ETHER) && !defined(CONFIG_USB_GADGET_DOWNLOAD)
540 usb_ether_init();
541#endif
542
Michal Simekb72894f2016-04-22 14:28:54 +0200543 if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
544 debug("Saved variables - Skipping\n");
545 return 0;
546 }
Michal Simek84c72042015-01-15 10:01:51 +0100547
Michal Simek91d7e0c2019-02-14 13:14:30 +0100548 ret = set_fdtfile();
549 if (ret)
550 return ret;
551
Siva Durga Prasad Paladugud1db89f2017-02-21 17:58:28 +0530552 ret = zynqmp_mmio_read((ulong)&crlapb_base->boot_mode, &reg);
553 if (ret)
554 return -EINVAL;
555
Michal Simek47359a02016-10-25 11:43:02 +0200556 if (reg >> BOOT_MODE_ALT_SHIFT)
557 reg >>= BOOT_MODE_ALT_SHIFT;
558
Michal Simek84c72042015-01-15 10:01:51 +0100559 bootmode = reg & BOOT_MODES_MASK;
560
Michal Simekfb909172015-09-20 17:20:42 +0200561 puts("Bootmode: ");
Michal Simek84c72042015-01-15 10:01:51 +0100562 switch (bootmode) {
Michal Simekd58fc122016-08-19 14:14:52 +0200563 case USB_MODE:
564 puts("USB_MODE\n");
565 mode = "usb";
Michal Simek07656ba2017-12-01 15:18:24 +0100566 env_set("modeboot", "usb_dfu_spl");
Michal Simekd58fc122016-08-19 14:14:52 +0200567 break;
Siva Durga Prasad Paladugu0a5bcc82015-03-13 11:10:26 +0530568 case JTAG_MODE:
Michal Simekfb909172015-09-20 17:20:42 +0200569 puts("JTAG_MODE\n");
Siva Durga Prasad Paladugu5d2274c2019-06-25 17:41:09 +0530570 mode = "jtag pxe dhcp";
Michal Simek07656ba2017-12-01 15:18:24 +0100571 env_set("modeboot", "jtagboot");
Siva Durga Prasad Paladugu0a5bcc82015-03-13 11:10:26 +0530572 break;
573 case QSPI_MODE_24BIT:
574 case QSPI_MODE_32BIT:
Michal Simekb72894f2016-04-22 14:28:54 +0200575 mode = "qspi0";
Michal Simekfb909172015-09-20 17:20:42 +0200576 puts("QSPI_MODE\n");
Michal Simek07656ba2017-12-01 15:18:24 +0100577 env_set("modeboot", "qspiboot");
Siva Durga Prasad Paladugu0a5bcc82015-03-13 11:10:26 +0530578 break;
Michal Simek39c56f52015-04-15 15:02:28 +0200579 case EMMC_MODE:
Michal Simek78678fe2015-10-05 15:59:38 +0200580 puts("EMMC_MODE\n");
Michal Simekb72894f2016-04-22 14:28:54 +0200581 mode = "mmc0";
Michal Simek07656ba2017-12-01 15:18:24 +0100582 env_set("modeboot", "emmcboot");
Michal Simek78678fe2015-10-05 15:59:38 +0200583 break;
584 case SD_MODE:
Michal Simekfb909172015-09-20 17:20:42 +0200585 puts("SD_MODE\n");
Michal Simek2882b392018-04-25 11:20:43 +0200586 if (uclass_get_device_by_name(UCLASS_MMC,
Siva Durga Prasad Paladugue7c9de62019-01-03 15:44:24 +0530587 "mmc@ff160000", &dev) &&
588 uclass_get_device_by_name(UCLASS_MMC,
Michal Simek2882b392018-04-25 11:20:43 +0200589 "sdhci@ff160000", &dev)) {
590 puts("Boot from SD0 but without SD0 enabled!\n");
591 return -1;
592 }
593 debug("mmc0 device found at %p, seq %d\n", dev, dev->seq);
594
595 mode = "mmc";
596 bootseq = dev->seq;
Michal Simek07656ba2017-12-01 15:18:24 +0100597 env_set("modeboot", "sdboot");
Michal Simek84c72042015-01-15 10:01:51 +0100598 break;
Siva Durga Prasad Paladugue1992272016-09-21 11:45:05 +0530599 case SD1_LSHFT_MODE:
600 puts("LVL_SHFT_");
601 /* fall through */
Michal Simekaf813ac2015-10-05 10:51:12 +0200602 case SD_MODE1:
Michal Simekfb909172015-09-20 17:20:42 +0200603 puts("SD_MODE1\n");
Michal Simek2882b392018-04-25 11:20:43 +0200604 if (uclass_get_device_by_name(UCLASS_MMC,
Siva Durga Prasad Paladugue7c9de62019-01-03 15:44:24 +0530605 "mmc@ff170000", &dev) &&
606 uclass_get_device_by_name(UCLASS_MMC,
Michal Simek2882b392018-04-25 11:20:43 +0200607 "sdhci@ff170000", &dev)) {
608 puts("Boot from SD1 but without SD1 enabled!\n");
609 return -1;
610 }
611 debug("mmc1 device found at %p, seq %d\n", dev, dev->seq);
612
613 mode = "mmc";
614 bootseq = dev->seq;
Michal Simek07656ba2017-12-01 15:18:24 +0100615 env_set("modeboot", "sdboot");
Michal Simekaf813ac2015-10-05 10:51:12 +0200616 break;
617 case NAND_MODE:
Michal Simekfb909172015-09-20 17:20:42 +0200618 puts("NAND_MODE\n");
Michal Simekb72894f2016-04-22 14:28:54 +0200619 mode = "nand0";
Michal Simek07656ba2017-12-01 15:18:24 +0100620 env_set("modeboot", "nandboot");
Michal Simekaf813ac2015-10-05 10:51:12 +0200621 break;
Michal Simek84c72042015-01-15 10:01:51 +0100622 default:
Michal Simekb72894f2016-04-22 14:28:54 +0200623 mode = "";
Michal Simek84c72042015-01-15 10:01:51 +0100624 printf("Invalid Boot Mode:0x%x\n", bootmode);
625 break;
626 }
627
Michal Simek2882b392018-04-25 11:20:43 +0200628 if (bootseq >= 0) {
629 bootseq_len = snprintf(NULL, 0, "%i", bootseq);
630 debug("Bootseq len: %x\n", bootseq_len);
631 }
632
Michal Simekb72894f2016-04-22 14:28:54 +0200633 /*
634 * One terminating char + one byte for space between mode
635 * and default boot_targets
636 */
Siva Durga Prasad Paladugu01c42d32017-12-20 16:35:06 +0530637 env_targets = env_get("boot_targets");
Michal Simek0478b0b2018-04-25 11:10:34 +0200638 if (env_targets)
639 env_targets_len = strlen(env_targets);
640
Michal Simek2882b392018-04-25 11:20:43 +0200641 new_targets = calloc(1, strlen(mode) + env_targets_len + 2 +
642 bootseq_len);
Michal Simek1e3e68f2018-06-13 09:42:41 +0200643 if (!new_targets)
644 return -ENOMEM;
Michal Simek0478b0b2018-04-25 11:10:34 +0200645
Michal Simek2882b392018-04-25 11:20:43 +0200646 if (bootseq >= 0)
647 sprintf(new_targets, "%s%x %s", mode, bootseq,
648 env_targets ? env_targets : "");
649 else
650 sprintf(new_targets, "%s %s", mode,
651 env_targets ? env_targets : "");
Michal Simekb72894f2016-04-22 14:28:54 +0200652
Simon Glass382bee52017-08-03 12:22:09 -0600653 env_set("boot_targets", new_targets);
Michal Simekb72894f2016-04-22 14:28:54 +0200654
T Karthik Reddya69814c2019-08-20 09:30:57 +0530655 initrd_hi = gd->start_addr_sp - CONFIG_STACK_SIZE;
656 initrd_hi = round_down(initrd_hi, SZ_16M);
657 env_set_addr("initrd_high", (void *)initrd_hi);
658
Michal Simekd348bea2018-05-17 14:06:06 +0200659 reset_reason();
660
Michal Simek84c72042015-01-15 10:01:51 +0100661 return 0;
662}
Michal Simek0bf3f9c2018-12-20 09:33:38 +0100663#endif
Siva Durga Prasad Paladugu84696ff2015-08-04 13:01:05 +0530664
665int checkboard(void)
666{
Michal Simek5af08552016-01-25 11:04:21 +0100667 puts("Board: Xilinx ZynqMP\n");
Siva Durga Prasad Paladugu84696ff2015-08-04 13:01:05 +0530668 return 0;
669}