blob: 30f757627f43c33eeaceebff770d724d7dc70e37 [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 Glass09140112020-05-10 11:40:03 -06008#include <command.h>
Simon Glass62270f42019-11-14 12:57:35 -07009#include <cpu_func.h>
Michal Simekc0adba52020-01-07 09:02:52 +010010#include <debug_uart.h>
Simon Glass9fb625c2019-08-01 09:46:51 -060011#include <env.h>
Michal Simek1025bd02020-07-30 13:37:49 +020012#include <env_internal.h>
Simon Glass52559322019-11-14 12:57:46 -070013#include <init.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060014#include <log.h>
Simon Glass90526e92020-05-10 11:39:56 -060015#include <net.h>
Michal Simek679b9942015-09-30 17:26:55 +020016#include <sata.h>
Michal Simek6fe6f132015-07-23 13:27:40 +020017#include <ahci.h>
18#include <scsi.h>
Michal Simekb72894f2016-04-22 14:28:54 +020019#include <malloc.h>
Michal Simek4490e012018-04-19 15:43:38 +020020#include <wdt.h>
Michal Simek0785dfd2015-11-05 08:34:35 +010021#include <asm/arch/clk.h>
Michal Simek84c72042015-01-15 10:01:51 +010022#include <asm/arch/hardware.h>
23#include <asm/arch/sys_proto.h>
Michal Simek2ad341e2018-01-10 09:36:09 +010024#include <asm/arch/psu_init_gpl.h>
Simon Glass90526e92020-05-10 11:39:56 -060025#include <asm/cache.h>
Michal Simek84c72042015-01-15 10:01:51 +010026#include <asm/io.h>
Simon Glass25a58182020-05-10 11:40:06 -060027#include <asm/ptrace.h>
Michal Simek2882b392018-04-25 11:20:43 +020028#include <dm/device.h>
Michal Simek4490e012018-04-19 15:43:38 +020029#include <dm/uclass.h>
Siva Durga Prasad Paladugu16fa00a2015-08-04 13:03:26 +053030#include <usb.h>
31#include <dwc3-uboot.h>
Michal Simek47e60cb2016-02-01 15:05:58 +010032#include <zynqmppl.h>
Ibai Erkiaga009ab7b2019-09-27 11:37:01 +010033#include <zynqmp_firmware.h>
Michal Simek9feff382016-09-01 11:16:40 +020034#include <g_dnl.h>
Simon Glasscd93d622020-05-10 11:40:13 -060035#include <linux/bitops.h>
Simon Glassc05ed002020-05-10 11:40:11 -060036#include <linux/delay.h>
37#include <linux/sizes.h>
Michal Simek80fdef12020-03-31 12:39:37 +020038#include "../common/board.h"
Michal Simek84c72042015-01-15 10:01:51 +010039
Luca Ceresolic28a9cf2019-05-21 18:06:43 +020040#include "pm_cfg_obj.h"
41
Ibai Erkiagafa793162020-08-04 23:17:31 +010042#define ZYNQMP_VERSION_SIZE 7
43#define EFUSE_VCU_DIS_MASK 0x100
44#define EFUSE_VCU_DIS_SHIFT 8
45#define EFUSE_GPU_DIS_MASK 0x20
46#define EFUSE_GPU_DIS_SHIFT 5
47#define IDCODE2_PL_INIT_MASK 0x200
48#define IDCODE2_PL_INIT_SHIFT 9
49
Michal Simek84c72042015-01-15 10:01:51 +010050DECLARE_GLOBAL_DATA_PTR;
51
Michal Simek29bd8ad2020-09-09 14:41:56 +020052#if CONFIG_IS_ENABLED(FPGA) && defined(CONFIG_FPGA_ZYNQMPPL)
Michal Simek47e60cb2016-02-01 15:05:58 +010053static xilinx_desc zynqmppl = XILINX_ZYNQMP_DESC;
54
Ibai Erkiagafa793162020-08-04 23:17:31 +010055enum {
56 ZYNQMP_VARIANT_EG = BIT(0U),
57 ZYNQMP_VARIANT_EV = BIT(1U),
58 ZYNQMP_VARIANT_CG = BIT(2U),
59 ZYNQMP_VARIANT_DR = BIT(3U),
60};
61
Michal Simek47e60cb2016-02-01 15:05:58 +010062static const struct {
Michal Simek8ebdf9e2017-11-06 12:55:59 +010063 u32 id;
Ibai Erkiagafa793162020-08-04 23:17:31 +010064 u8 device;
65 u8 variants;
Michal Simek47e60cb2016-02-01 15:05:58 +010066} zynqmp_devices[] = {
67 {
Ibai Erkiagafa793162020-08-04 23:17:31 +010068 .id = 0x04711093,
69 .device = 2,
70 .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG,
Michal Simek47e60cb2016-02-01 15:05:58 +010071 },
72 {
Ibai Erkiagafa793162020-08-04 23:17:31 +010073 .id = 0x04710093,
74 .device = 3,
75 .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG,
Michal Simek494fffe2017-08-22 14:58:53 +020076 },
77 {
Ibai Erkiagafa793162020-08-04 23:17:31 +010078 .id = 0x04721093,
79 .device = 4,
80 .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG |
81 ZYNQMP_VARIANT_EV,
Michal Simek47e60cb2016-02-01 15:05:58 +010082 },
83 {
Ibai Erkiagafa793162020-08-04 23:17:31 +010084 .id = 0x04720093,
85 .device = 5,
86 .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG |
87 ZYNQMP_VARIANT_EV,
Michal Simek494fffe2017-08-22 14:58:53 +020088 },
89 {
Ibai Erkiagafa793162020-08-04 23:17:31 +010090 .id = 0x04739093,
91 .device = 6,
92 .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG,
Michal Simek47e60cb2016-02-01 15:05:58 +010093 },
94 {
Ibai Erkiagafa793162020-08-04 23:17:31 +010095 .id = 0x04730093,
96 .device = 7,
97 .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG |
98 ZYNQMP_VARIANT_EV,
Michal Simek494fffe2017-08-22 14:58:53 +020099 },
100 {
Ibai Erkiagafa793162020-08-04 23:17:31 +0100101 .id = 0x04738093,
102 .device = 9,
103 .variants = ZYNQMP_VARIANT_EG,
Michal Simek494fffe2017-08-22 14:58:53 +0200104 },
105 {
Ibai Erkiagafa793162020-08-04 23:17:31 +0100106 .id = 0x04740093,
107 .device = 11,
108 .variants = ZYNQMP_VARIANT_EG,
Michal Simek47e60cb2016-02-01 15:05:58 +0100109 },
110 {
Ibai Erkiagafa793162020-08-04 23:17:31 +0100111 .id = 0x04750093,
112 .device = 15,
113 .variants = ZYNQMP_VARIANT_EG,
Michal Simek494fffe2017-08-22 14:58:53 +0200114 },
115 {
Ibai Erkiagafa793162020-08-04 23:17:31 +0100116 .id = 0x04759093,
117 .device = 17,
118 .variants = ZYNQMP_VARIANT_EG,
Michal Simek494fffe2017-08-22 14:58:53 +0200119 },
120 {
Ibai Erkiagafa793162020-08-04 23:17:31 +0100121 .id = 0x04758093,
122 .device = 19,
123 .variants = ZYNQMP_VARIANT_EG,
Michal Simek47e60cb2016-02-01 15:05:58 +0100124 },
125 {
Ibai Erkiagafa793162020-08-04 23:17:31 +0100126 .id = 0x047E1093,
127 .device = 21,
128 .variants = ZYNQMP_VARIANT_DR,
Michal Simek494fffe2017-08-22 14:58:53 +0200129 },
130 {
Ibai Erkiagafa793162020-08-04 23:17:31 +0100131 .id = 0x047E3093,
132 .device = 23,
133 .variants = ZYNQMP_VARIANT_DR,
Michal Simek494fffe2017-08-22 14:58:53 +0200134 },
135 {
Ibai Erkiagafa793162020-08-04 23:17:31 +0100136 .id = 0x047E5093,
137 .device = 25,
138 .variants = ZYNQMP_VARIANT_DR,
Michal Simek47e60cb2016-02-01 15:05:58 +0100139 },
140 {
Ibai Erkiagafa793162020-08-04 23:17:31 +0100141 .id = 0x047E4093,
142 .device = 27,
143 .variants = ZYNQMP_VARIANT_DR,
Michal Simek494fffe2017-08-22 14:58:53 +0200144 },
145 {
Ibai Erkiagafa793162020-08-04 23:17:31 +0100146 .id = 0x047E0093,
147 .device = 28,
148 .variants = ZYNQMP_VARIANT_DR,
Michal Simek47e60cb2016-02-01 15:05:58 +0100149 },
150 {
Ibai Erkiagafa793162020-08-04 23:17:31 +0100151 .id = 0x047E2093,
152 .device = 29,
153 .variants = ZYNQMP_VARIANT_DR,
Michal Simek494fffe2017-08-22 14:58:53 +0200154 },
155 {
Ibai Erkiagafa793162020-08-04 23:17:31 +0100156 .id = 0x047E6093,
157 .device = 39,
158 .variants = ZYNQMP_VARIANT_DR,
Michal Simek494fffe2017-08-22 14:58:53 +0200159 },
Michal Simek47e60cb2016-02-01 15:05:58 +0100160 {
Michal Simeke17c5ec2020-09-11 09:22:15 +0200161 .id = 0x047FD093,
162 .device = 43,
163 .variants = ZYNQMP_VARIANT_DR,
164 },
165 {
166 .id = 0x047F8093,
167 .device = 46,
168 .variants = ZYNQMP_VARIANT_DR,
169 },
170 {
171 .id = 0x047FF093,
172 .device = 47,
173 .variants = ZYNQMP_VARIANT_DR,
174 },
175 {
Ibai Erkiagafa793162020-08-04 23:17:31 +0100176 .id = 0x047FB093,
177 .device = 48,
178 .variants = ZYNQMP_VARIANT_DR,
Michal Simek47e60cb2016-02-01 15:05:58 +0100179 },
180 {
Ibai Erkiagafa793162020-08-04 23:17:31 +0100181 .id = 0x047FE093,
182 .device = 49,
183 .variants = ZYNQMP_VARIANT_DR,
Siva Durga Prasad Paladugu134b0c82019-07-23 11:56:17 +0530184 },
Michal Simek47e60cb2016-02-01 15:05:58 +0100185};
186
Michal Simek47e60cb2016-02-01 15:05:58 +0100187static char *zynqmp_get_silicon_idcode_name(void)
188{
Ibai Erkiagafa793162020-08-04 23:17:31 +0100189 u32 i;
190 u32 idcode, idcode2;
Michal Simekced4d462020-08-05 12:41:35 +0200191 char name[ZYNQMP_VERSION_SIZE];
Ibai Erkiaga050f10f2020-08-04 23:17:30 +0100192 u32 ret_payload[PAYLOAD_ARG_CNT];
Michal Simek47e60cb2016-02-01 15:05:58 +0100193
Ibai Erkiaga050f10f2020-08-04 23:17:30 +0100194 xilinx_pm_request(PM_GET_CHIPID, 0, 0, 0, 0, ret_payload);
195
196 /*
197 * Firmware returns:
198 * payload[0][31:0] = status of the operation
199 * payload[1]] = IDCODE
200 * payload[2][19:0] = Version
201 * payload[2][28:20] = EXTENDED_IDCODE
202 * payload[2][29] = PL_INIT
203 */
204
Ibai Erkiagafa793162020-08-04 23:17:31 +0100205 idcode = ret_payload[1];
206 idcode2 = ret_payload[2] >> ZYNQMP_CSU_VERSION_EMPTY_SHIFT;
207 debug("%s, IDCODE: 0x%0X, IDCODE2: 0x%0X\r\n", __func__, idcode,
208 idcode2);
Michal Simek494fffe2017-08-22 14:58:53 +0200209
Michal Simek47e60cb2016-02-01 15:05:58 +0100210 for (i = 0; i < ARRAY_SIZE(zynqmp_devices); i++) {
Ibai Erkiagafa793162020-08-04 23:17:31 +0100211 if (zynqmp_devices[i].id == (idcode & 0x0FFFFFFF))
212 break;
Michal Simek47e60cb2016-02-01 15:05:58 +0100213 }
Siva Durga Prasad Paladugu83bf2ff2018-03-02 16:20:10 +0530214
215 if (i >= ARRAY_SIZE(zynqmp_devices))
216 return "unknown";
217
Ibai Erkiagafa793162020-08-04 23:17:31 +0100218 /* Add device prefix to the name */
Michal Simekced4d462020-08-05 12:41:35 +0200219 strncpy(name, "zu", ZYNQMP_VERSION_SIZE);
Ibai Erkiagafa793162020-08-04 23:17:31 +0100220 strncat(&name[2], simple_itoa(zynqmp_devices[i].device), 2);
Siva Durga Prasad Paladugu83bf2ff2018-03-02 16:20:10 +0530221
Ibai Erkiagafa793162020-08-04 23:17:31 +0100222 if (zynqmp_devices[i].variants & ZYNQMP_VARIANT_EV) {
223 /* Devices with EV variant might be EG/CG/EV family */
224 if (idcode2 & IDCODE2_PL_INIT_MASK) {
225 u32 family = ((idcode2 & EFUSE_VCU_DIS_MASK) >>
226 EFUSE_VCU_DIS_SHIFT) << 1 |
227 ((idcode2 & EFUSE_GPU_DIS_MASK) >>
228 EFUSE_GPU_DIS_SHIFT);
229
230 /*
231 * Get family name based on extended idcode values as
232 * determined on UG1087, EXTENDED_IDCODE register
233 * description
234 */
235 switch (family) {
236 case 0x00:
237 strncat(name, "ev", 2);
238 break;
239 case 0x10:
240 strncat(name, "eg", 2);
241 break;
242 case 0x11:
243 strncat(name, "cg", 2);
244 break;
245 default:
246 /* Do not append family name*/
247 break;
248 }
249 } else {
250 /*
251 * When PL powered down the VCU Disable efuse cannot be
252 * read. So, ignore the bit and just findout if it is CG
253 * or EG/EV variant.
254 */
255 strncat(name, (idcode2 & EFUSE_GPU_DIS_MASK) ? "cg" :
256 "e", 2);
Siva Durga Prasad Paladugu5473f242018-10-26 17:47:55 +0530257 }
Ibai Erkiagafa793162020-08-04 23:17:31 +0100258 } else if (zynqmp_devices[i].variants & ZYNQMP_VARIANT_CG) {
259 /* Devices with CG variant might be EG or CG family */
260 strncat(name, (idcode2 & EFUSE_GPU_DIS_MASK) ? "cg" : "eg", 2);
261 } else if (zynqmp_devices[i].variants & ZYNQMP_VARIANT_EG) {
262 strncat(name, "eg", 2);
263 } else if (zynqmp_devices[i].variants & ZYNQMP_VARIANT_DR) {
264 strncat(name, "dr", 2);
265 } else {
266 debug("Variant not identified\n");
Siva Durga Prasad Paladugu83bf2ff2018-03-02 16:20:10 +0530267 }
268
Michal Simekced4d462020-08-05 12:41:35 +0200269 return strdup(name);
Michal Simek47e60cb2016-02-01 15:05:58 +0100270}
271#endif
272
Michal Simekfb4000e2017-02-07 14:32:26 +0100273int board_early_init_f(void)
274{
Michal Simek88f05a92018-01-15 12:52:59 +0100275#if defined(CONFIG_ZYNQMP_PSU_INIT_ENABLED)
Michal Simekc0adba52020-01-07 09:02:52 +0100276 int ret;
277
Michal Simekf32e79f2018-01-10 11:48:48 +0100278 ret = psu_init();
Michal Simekc0adba52020-01-07 09:02:52 +0100279 if (ret)
280 return ret;
Michal Simekf8451f12020-03-20 08:59:02 +0100281
282 /* Delay is required for clocks to be propagated */
283 udelay(1000000);
Michal Simek55de0922017-07-12 13:08:41 +0200284#endif
285
Michal Simekc0adba52020-01-07 09:02:52 +0100286#ifdef CONFIG_DEBUG_UART
287 /* Uart debug for sure */
288 debug_uart_init();
289 puts("Debug uart enabled\n"); /* or printch() */
290#endif
291
292 return 0;
Michal Simekfb4000e2017-02-07 14:32:26 +0100293}
294
Michal Simekc5143012020-02-11 12:43:14 +0100295static int multi_boot(void)
296{
297 u32 multiboot;
298
299 multiboot = readl(&csu_base->multi_boot);
300
Michal Simek3ccea692020-05-27 12:50:33 +0200301 printf("Multiboot:\t%d\n", multiboot);
Michal Simekc5143012020-02-11 12:43:14 +0100302
303 return 0;
304}
305
Mike Looijmansdfbe4922019-10-18 07:34:13 +0200306#define PS_SYSMON_ANALOG_BUS_VAL 0x3210
307#define PS_SYSMON_ANALOG_BUS_REG 0xFFA50914
308
Michal Simek84c72042015-01-15 10:01:51 +0100309int board_init(void)
310{
Michal Simek66ef85d2020-03-04 08:48:16 +0100311#if defined(CONFIG_ZYNQMP_FIRMWARE)
Ibai Erkiaga325a22d2019-09-27 11:37:04 +0100312 struct udevice *dev;
313
314 uclass_get_device_by_name(UCLASS_FIRMWARE, "zynqmp-power", &dev);
315 if (!dev)
316 panic("PMU Firmware device not found - Enable it");
Michal Simek66ef85d2020-03-04 08:48:16 +0100317#endif
Ibai Erkiaga325a22d2019-09-27 11:37:04 +0100318
Luca Ceresolic28a9cf2019-05-21 18:06:43 +0200319#if defined(CONFIG_SPL_BUILD)
320 /* Check *at build time* if the filename is an non-empty string */
321 if (sizeof(CONFIG_ZYNQMP_SPL_PM_CFG_OBJ_FILE) > 1)
322 zynqmp_pmufw_load_config_object(zynqmp_pm_cfg_obj,
323 zynqmp_pm_cfg_obj_size);
324#endif
325
Michal Simeka0736ef2015-06-22 14:31:06 +0200326 printf("EL Level:\tEL%d\n", current_el());
327
Mike Looijmansdfbe4922019-10-18 07:34:13 +0200328 /* Bug in ROM sets wrong value in this register */
329 writel(PS_SYSMON_ANALOG_BUS_VAL, PS_SYSMON_ANALOG_BUS_REG);
330
Michal Simek29bd8ad2020-09-09 14:41:56 +0200331#if CONFIG_IS_ENABLED(FPGA) && defined(CONFIG_FPGA_ZYNQMPPL)
Ibai Erkiaga4b2ad7b2020-08-04 23:17:29 +0100332 zynqmppl.name = zynqmp_get_silicon_idcode_name();
333 printf("Chip ID:\t%s\n", zynqmppl.name);
334 fpga_init();
335 fpga_add(fpga_xilinx, &zynqmppl);
Michal Simek47e60cb2016-02-01 15:05:58 +0100336#endif
337
Michal Simekc5143012020-02-11 12:43:14 +0100338 if (current_el() == 3)
339 multi_boot();
340
Michal Simek84c72042015-01-15 10:01:51 +0100341 return 0;
342}
343
344int board_early_init_r(void)
345{
346 u32 val;
347
Siva Durga Prasad Paladuguec60a272017-12-07 15:05:30 +0530348 if (current_el() != 3)
349 return 0;
350
Michal Simek90a35db2017-07-12 10:32:18 +0200351 val = readl(&crlapb_base->timestamp_ref_ctrl);
352 val &= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
353
Siva Durga Prasad Paladuguec60a272017-12-07 15:05:30 +0530354 if (!val) {
Michal Simek0785dfd2015-11-05 08:34:35 +0100355 val = readl(&crlapb_base->timestamp_ref_ctrl);
356 val |= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
357 writel(val, &crlapb_base->timestamp_ref_ctrl);
Michal Simek84c72042015-01-15 10:01:51 +0100358
Michal Simek0785dfd2015-11-05 08:34:35 +0100359 /* Program freq register in System counter */
360 writel(zynqmp_get_system_timer_freq(),
361 &iou_scntr_secure->base_frequency_id_register);
362 /* And enable system counter */
363 writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN,
364 &iou_scntr_secure->counter_control_register);
365 }
Michal Simek84c72042015-01-15 10:01:51 +0100366 return 0;
367}
368
Nitin Jain51916862018-02-16 12:56:17 +0530369unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc,
Simon Glass09140112020-05-10 11:40:03 -0600370 char *const argv[])
Nitin Jain51916862018-02-16 12:56:17 +0530371{
372 int ret = 0;
373
374 if (current_el() > 1) {
375 smp_kick_all_cpus();
376 dcache_disable();
377 armv8_switch_to_el1(0x0, 0, 0, 0, (unsigned long)entry,
378 ES_TO_AARCH64);
379 } else {
380 printf("FAIL: current EL is not above EL1\n");
381 ret = EINVAL;
382 }
383 return ret;
384}
385
Michal Simek8d59d7f2016-02-08 09:34:53 +0100386#if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE)
Simon Glass76b00ac2017-03-31 08:40:32 -0600387int dram_init_banksize(void)
Tom Rini361a8792016-12-09 07:56:54 -0500388{
Nitin Jain06789412018-04-20 12:30:40 +0530389 int ret;
390
391 ret = fdtdec_setup_memory_banksize();
392 if (ret)
393 return ret;
394
395 mem_map_fill();
396
397 return 0;
Michal Simek8d59d7f2016-02-08 09:34:53 +0100398}
399
400int dram_init(void)
401{
Siva Durga Prasad Paladugu12308b12018-07-16 15:56:11 +0530402 if (fdtdec_setup_mem_size_base() != 0)
Nathan Rossi950f86c2016-12-19 00:03:34 +1000403 return -EINVAL;
Michal Simek8d59d7f2016-02-08 09:34:53 +0100404
405 return 0;
406}
407#else
Nitin Jain06789412018-04-20 12:30:40 +0530408int dram_init_banksize(void)
409{
410#if defined(CONFIG_NR_DRAM_BANKS)
411 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
412 gd->bd->bi_dram[0].size = get_effective_memsize();
413#endif
414
415 mem_map_fill();
416
417 return 0;
418}
419
Michal Simek84c72042015-01-15 10:01:51 +0100420int dram_init(void)
421{
Michal Simek61dc92a2018-04-11 16:12:28 +0200422 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
423 CONFIG_SYS_SDRAM_SIZE);
Michal Simek84c72042015-01-15 10:01:51 +0100424
425 return 0;
426}
Michal Simek8d59d7f2016-02-08 09:34:53 +0100427#endif
Michal Simek84c72042015-01-15 10:01:51 +0100428
Michal Simek84c72042015-01-15 10:01:51 +0100429void reset_cpu(ulong addr)
430{
431}
432
Michal Simek4d9bc792020-08-20 10:54:45 +0200433static u8 __maybe_unused zynqmp_get_bootmode(void)
434{
435 u8 bootmode;
436 u32 reg = 0;
437 int ret;
438
439 ret = zynqmp_mmio_read((ulong)&crlapb_base->boot_mode, &reg);
440 if (ret)
441 return -EINVAL;
442
443 if (reg >> BOOT_MODE_ALT_SHIFT)
444 reg >>= BOOT_MODE_ALT_SHIFT;
445
446 bootmode = reg & BOOT_MODES_MASK;
447
448 return bootmode;
449}
450
Michal Simek0bf3f9c2018-12-20 09:33:38 +0100451#if defined(CONFIG_BOARD_LATE_INIT)
Michal Simekd348bea2018-05-17 14:06:06 +0200452static const struct {
453 u32 bit;
454 const char *name;
455} reset_reasons[] = {
456 { RESET_REASON_DEBUG_SYS, "DEBUG" },
457 { RESET_REASON_SOFT, "SOFT" },
458 { RESET_REASON_SRST, "SRST" },
459 { RESET_REASON_PSONLY, "PS-ONLY" },
460 { RESET_REASON_PMU, "PMU" },
461 { RESET_REASON_INTERNAL, "INTERNAL" },
462 { RESET_REASON_EXTERNAL, "EXTERNAL" },
463 {}
464};
465
T Karthik Reddybe523722019-03-13 20:24:18 +0530466static int reset_reason(void)
Michal Simekd348bea2018-05-17 14:06:06 +0200467{
T Karthik Reddybe523722019-03-13 20:24:18 +0530468 u32 reg;
469 int i, ret;
Michal Simekd348bea2018-05-17 14:06:06 +0200470 const char *reason = NULL;
471
T Karthik Reddybe523722019-03-13 20:24:18 +0530472 ret = zynqmp_mmio_read((ulong)&crlapb_base->reset_reason, &reg);
473 if (ret)
474 return -EINVAL;
Michal Simekd348bea2018-05-17 14:06:06 +0200475
476 puts("Reset reason:\t");
477
478 for (i = 0; i < ARRAY_SIZE(reset_reasons); i++) {
T Karthik Reddybe523722019-03-13 20:24:18 +0530479 if (reg & reset_reasons[i].bit) {
Michal Simekd348bea2018-05-17 14:06:06 +0200480 reason = reset_reasons[i].name;
481 printf("%s ", reset_reasons[i].name);
482 break;
483 }
484 }
485
486 puts("\n");
487
488 env_set("reset_reason", reason);
489
Michal Simek3d037522020-03-23 14:02:01 +0100490 ret = zynqmp_mmio_write((ulong)&crlapb_base->reset_reason, ~0, ~0);
T Karthik Reddybe523722019-03-13 20:24:18 +0530491 if (ret)
492 return -EINVAL;
Michal Simekd348bea2018-05-17 14:06:06 +0200493
494 return ret;
495}
496
Michal Simek91d7e0c2019-02-14 13:14:30 +0100497static int set_fdtfile(void)
498{
499 char *compatible, *fdtfile;
500 const char *suffix = ".dtb";
501 const char *vendor = "xilinx/";
Igor Lantsman1b208d52020-06-24 14:33:46 +0200502 int fdt_compat_len;
Michal Simek91d7e0c2019-02-14 13:14:30 +0100503
504 if (env_get("fdtfile"))
505 return 0;
506
Igor Lantsman1b208d52020-06-24 14:33:46 +0200507 compatible = (char *)fdt_getprop(gd->fdt_blob, 0, "compatible",
508 &fdt_compat_len);
509 if (compatible && fdt_compat_len) {
510 char *name;
511
Michal Simek91d7e0c2019-02-14 13:14:30 +0100512 debug("Compatible: %s\n", compatible);
513
Igor Lantsman1b208d52020-06-24 14:33:46 +0200514 name = strchr(compatible, ',');
515 if (!name)
516 return -EINVAL;
Michal Simek91d7e0c2019-02-14 13:14:30 +0100517
Igor Lantsman1b208d52020-06-24 14:33:46 +0200518 name++;
519
520 fdtfile = calloc(1, strlen(vendor) + strlen(name) +
Michal Simek91d7e0c2019-02-14 13:14:30 +0100521 strlen(suffix) + 1);
522 if (!fdtfile)
523 return -ENOMEM;
524
Igor Lantsman1b208d52020-06-24 14:33:46 +0200525 sprintf(fdtfile, "%s%s%s", vendor, name, suffix);
Michal Simek91d7e0c2019-02-14 13:14:30 +0100526
527 env_set("fdtfile", fdtfile);
528 free(fdtfile);
529 }
530
531 return 0;
532}
533
Michal Simek84c72042015-01-15 10:01:51 +0100534int board_late_init(void)
535{
Michal Simek84c72042015-01-15 10:01:51 +0100536 u8 bootmode;
Michal Simek2882b392018-04-25 11:20:43 +0200537 struct udevice *dev;
538 int bootseq = -1;
539 int bootseq_len = 0;
Michal Simek0478b0b2018-04-25 11:10:34 +0200540 int env_targets_len = 0;
Michal Simekb72894f2016-04-22 14:28:54 +0200541 const char *mode;
542 char *new_targets;
Siva Durga Prasad Paladugu01c42d32017-12-20 16:35:06 +0530543 char *env_targets;
Siva Durga Prasad Paladugud1db89f2017-02-21 17:58:28 +0530544 int ret;
Michal Simekb72894f2016-04-22 14:28:54 +0200545
Michal Simeke615f392018-10-05 08:55:16 +0200546#if defined(CONFIG_USB_ETHER) && !defined(CONFIG_USB_GADGET_DOWNLOAD)
547 usb_ether_init();
548#endif
549
Michal Simekb72894f2016-04-22 14:28:54 +0200550 if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
551 debug("Saved variables - Skipping\n");
552 return 0;
553 }
Michal Simek84c72042015-01-15 10:01:51 +0100554
Michal Simek62b96262020-07-28 12:45:47 +0200555 if (!CONFIG_IS_ENABLED(ENV_VARS_UBOOT_RUNTIME_CONFIG))
556 return 0;
557
Michal Simek91d7e0c2019-02-14 13:14:30 +0100558 ret = set_fdtfile();
559 if (ret)
560 return ret;
561
Michal Simek51f6c522020-04-08 11:04:41 +0200562 bootmode = zynqmp_get_bootmode();
Michal Simek84c72042015-01-15 10:01:51 +0100563
Michal Simekfb909172015-09-20 17:20:42 +0200564 puts("Bootmode: ");
Michal Simek84c72042015-01-15 10:01:51 +0100565 switch (bootmode) {
Michal Simekd58fc122016-08-19 14:14:52 +0200566 case USB_MODE:
567 puts("USB_MODE\n");
568 mode = "usb";
Michal Simek07656ba2017-12-01 15:18:24 +0100569 env_set("modeboot", "usb_dfu_spl");
Michal Simekd58fc122016-08-19 14:14:52 +0200570 break;
Siva Durga Prasad Paladugu0a5bcc82015-03-13 11:10:26 +0530571 case JTAG_MODE:
Michal Simekfb909172015-09-20 17:20:42 +0200572 puts("JTAG_MODE\n");
Siva Durga Prasad Paladugu5d2274c2019-06-25 17:41:09 +0530573 mode = "jtag pxe dhcp";
Michal Simek07656ba2017-12-01 15:18:24 +0100574 env_set("modeboot", "jtagboot");
Siva Durga Prasad Paladugu0a5bcc82015-03-13 11:10:26 +0530575 break;
576 case QSPI_MODE_24BIT:
577 case QSPI_MODE_32BIT:
Michal Simekb72894f2016-04-22 14:28:54 +0200578 mode = "qspi0";
Michal Simekfb909172015-09-20 17:20:42 +0200579 puts("QSPI_MODE\n");
Michal Simek07656ba2017-12-01 15:18:24 +0100580 env_set("modeboot", "qspiboot");
Siva Durga Prasad Paladugu0a5bcc82015-03-13 11:10:26 +0530581 break;
Michal Simek39c56f52015-04-15 15:02:28 +0200582 case EMMC_MODE:
Michal Simek78678fe2015-10-05 15:59:38 +0200583 puts("EMMC_MODE\n");
T Karthik Reddy18be60b2019-12-17 06:41:42 -0700584 if (uclass_get_device_by_name(UCLASS_MMC,
585 "mmc@ff160000", &dev) &&
586 uclass_get_device_by_name(UCLASS_MMC,
587 "sdhci@ff160000", &dev)) {
588 puts("Boot from EMMC but without SD0 enabled!\n");
589 return -1;
590 }
591 debug("mmc0 device found at %p, seq %d\n", dev, dev->seq);
592
593 mode = "mmc";
594 bootseq = dev->seq;
Michal Simek78678fe2015-10-05 15:59:38 +0200595 break;
596 case SD_MODE:
Michal Simekfb909172015-09-20 17:20:42 +0200597 puts("SD_MODE\n");
Michal Simek2882b392018-04-25 11:20:43 +0200598 if (uclass_get_device_by_name(UCLASS_MMC,
Siva Durga Prasad Paladugue7c9de62019-01-03 15:44:24 +0530599 "mmc@ff160000", &dev) &&
600 uclass_get_device_by_name(UCLASS_MMC,
Michal Simek2882b392018-04-25 11:20:43 +0200601 "sdhci@ff160000", &dev)) {
602 puts("Boot from SD0 but without SD0 enabled!\n");
603 return -1;
604 }
605 debug("mmc0 device found at %p, seq %d\n", dev, dev->seq);
606
607 mode = "mmc";
608 bootseq = dev->seq;
Michal Simek07656ba2017-12-01 15:18:24 +0100609 env_set("modeboot", "sdboot");
Michal Simek84c72042015-01-15 10:01:51 +0100610 break;
Siva Durga Prasad Paladugue1992272016-09-21 11:45:05 +0530611 case SD1_LSHFT_MODE:
612 puts("LVL_SHFT_");
613 /* fall through */
Michal Simekaf813ac2015-10-05 10:51:12 +0200614 case SD_MODE1:
Michal Simekfb909172015-09-20 17:20:42 +0200615 puts("SD_MODE1\n");
Michal Simek2882b392018-04-25 11:20:43 +0200616 if (uclass_get_device_by_name(UCLASS_MMC,
Siva Durga Prasad Paladugue7c9de62019-01-03 15:44:24 +0530617 "mmc@ff170000", &dev) &&
618 uclass_get_device_by_name(UCLASS_MMC,
Michal Simek2882b392018-04-25 11:20:43 +0200619 "sdhci@ff170000", &dev)) {
620 puts("Boot from SD1 but without SD1 enabled!\n");
621 return -1;
622 }
623 debug("mmc1 device found at %p, seq %d\n", dev, dev->seq);
624
625 mode = "mmc";
626 bootseq = dev->seq;
Michal Simek07656ba2017-12-01 15:18:24 +0100627 env_set("modeboot", "sdboot");
Michal Simekaf813ac2015-10-05 10:51:12 +0200628 break;
629 case NAND_MODE:
Michal Simekfb909172015-09-20 17:20:42 +0200630 puts("NAND_MODE\n");
Michal Simekb72894f2016-04-22 14:28:54 +0200631 mode = "nand0";
Michal Simek07656ba2017-12-01 15:18:24 +0100632 env_set("modeboot", "nandboot");
Michal Simekaf813ac2015-10-05 10:51:12 +0200633 break;
Michal Simek84c72042015-01-15 10:01:51 +0100634 default:
Michal Simekb72894f2016-04-22 14:28:54 +0200635 mode = "";
Michal Simek84c72042015-01-15 10:01:51 +0100636 printf("Invalid Boot Mode:0x%x\n", bootmode);
637 break;
638 }
639
Michal Simek2882b392018-04-25 11:20:43 +0200640 if (bootseq >= 0) {
641 bootseq_len = snprintf(NULL, 0, "%i", bootseq);
642 debug("Bootseq len: %x\n", bootseq_len);
643 }
644
Michal Simekb72894f2016-04-22 14:28:54 +0200645 /*
646 * One terminating char + one byte for space between mode
647 * and default boot_targets
648 */
Siva Durga Prasad Paladugu01c42d32017-12-20 16:35:06 +0530649 env_targets = env_get("boot_targets");
Michal Simek0478b0b2018-04-25 11:10:34 +0200650 if (env_targets)
651 env_targets_len = strlen(env_targets);
652
Michal Simek2882b392018-04-25 11:20:43 +0200653 new_targets = calloc(1, strlen(mode) + env_targets_len + 2 +
654 bootseq_len);
Michal Simek1e3e68f2018-06-13 09:42:41 +0200655 if (!new_targets)
656 return -ENOMEM;
Michal Simek0478b0b2018-04-25 11:10:34 +0200657
Michal Simek2882b392018-04-25 11:20:43 +0200658 if (bootseq >= 0)
659 sprintf(new_targets, "%s%x %s", mode, bootseq,
660 env_targets ? env_targets : "");
661 else
662 sprintf(new_targets, "%s %s", mode,
663 env_targets ? env_targets : "");
Michal Simekb72894f2016-04-22 14:28:54 +0200664
Simon Glass382bee52017-08-03 12:22:09 -0600665 env_set("boot_targets", new_targets);
Michal Simekb72894f2016-04-22 14:28:54 +0200666
Michal Simekd348bea2018-05-17 14:06:06 +0200667 reset_reason();
668
Michal Simek80fdef12020-03-31 12:39:37 +0200669 return board_late_init_xilinx();
Michal Simek84c72042015-01-15 10:01:51 +0100670}
Michal Simek0bf3f9c2018-12-20 09:33:38 +0100671#endif
Siva Durga Prasad Paladugu84696ff2015-08-04 13:01:05 +0530672
673int checkboard(void)
674{
Michal Simek5af08552016-01-25 11:04:21 +0100675 puts("Board: Xilinx ZynqMP\n");
Siva Durga Prasad Paladugu84696ff2015-08-04 13:01:05 +0530676 return 0;
677}
Michal Simek1025bd02020-07-30 13:37:49 +0200678
679enum env_location env_get_location(enum env_operation op, int prio)
680{
681 u32 bootmode = zynqmp_get_bootmode();
682
683 if (prio)
684 return ENVL_UNKNOWN;
685
686 switch (bootmode) {
687 case EMMC_MODE:
688 case SD_MODE:
689 case SD1_LSHFT_MODE:
690 case SD_MODE1:
691 if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT))
692 return ENVL_FAT;
693 if (IS_ENABLED(CONFIG_ENV_IS_IN_EXT4))
694 return ENVL_EXT4;
695 return ENVL_UNKNOWN;
696 case NAND_MODE:
697 if (IS_ENABLED(CONFIG_ENV_IS_IN_NAND))
698 return ENVL_NAND;
699 if (IS_ENABLED(CONFIG_ENV_IS_IN_UBI))
700 return ENVL_UBI;
701 return ENVL_UNKNOWN;
702 case QSPI_MODE_24BIT:
703 case QSPI_MODE_32BIT:
704 if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))
705 return ENVL_SPI_FLASH;
706 return ENVL_UNKNOWN;
707 case JTAG_MODE:
708 default:
709 return ENVL_NOWHERE;
710 }
711}