blob: 1afc980243bbcc4f002c20cd6ac353919c2a2b19 [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>
Simon Glassed38aef2020-05-10 11:40:03 -06008#include <command.h>
Simon Glass370382c2019-11-14 12:57:35 -07009#include <cpu_func.h>
Michal Simek09a7d7d2020-01-07 09:02:52 +010010#include <debug_uart.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060011#include <env.h>
Simon Glassa7b51302019-11-14 12:57:46 -070012#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060013#include <log.h>
Simon Glass274e0b02020-05-10 11:39:56 -060014#include <net.h>
Michal Simekd54b1af2015-09-30 17:26:55 +020015#include <sata.h>
Michal Simekb216cc12015-07-23 13:27:40 +020016#include <ahci.h>
17#include <scsi.h>
Michal Simekecfb6dc2016-04-22 14:28:54 +020018#include <malloc.h>
Michal Simekbf0f9ca2018-04-19 15:43:38 +020019#include <wdt.h>
Michal Simekc23d3f82015-11-05 08:34:35 +010020#include <asm/arch/clk.h>
Michal Simek04b7e622015-01-15 10:01:51 +010021#include <asm/arch/hardware.h>
22#include <asm/arch/sys_proto.h>
Michal Simekf2f08642018-01-10 09:36:09 +010023#include <asm/arch/psu_init_gpl.h>
Simon Glass274e0b02020-05-10 11:39:56 -060024#include <asm/cache.h>
Michal Simek04b7e622015-01-15 10:01:51 +010025#include <asm/io.h>
Simon Glass6b9f0102020-05-10 11:40:06 -060026#include <asm/ptrace.h>
Michal Simekf183a982018-04-25 11:20:43 +020027#include <dm/device.h>
Michal Simekbf0f9ca2018-04-19 15:43:38 +020028#include <dm/uclass.h>
Siva Durga Prasad Paladuguba1f68e2015-08-04 13:03:26 +053029#include <usb.h>
30#include <dwc3-uboot.h>
Michal Simek8111aff2016-02-01 15:05:58 +010031#include <zynqmppl.h>
Ibai Erkiagac8a3efa2019-09-27 11:37:01 +010032#include <zynqmp_firmware.h>
Michal Simek76d0a772016-09-01 11:16:40 +020033#include <g_dnl.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060034#include <linux/bitops.h>
Simon Glassdbd79542020-05-10 11:40:11 -060035#include <linux/delay.h>
36#include <linux/sizes.h>
Michal Simek705d44a2020-03-31 12:39:37 +020037#include "../common/board.h"
Michal Simek04b7e622015-01-15 10:01:51 +010038
Luca Ceresoli23e65002019-05-21 18:06:43 +020039#include "pm_cfg_obj.h"
40
Ibai Erkiaga4f736182020-08-04 23:17:31 +010041#define ZYNQMP_VERSION_SIZE 7
42#define EFUSE_VCU_DIS_MASK 0x100
43#define EFUSE_VCU_DIS_SHIFT 8
44#define EFUSE_GPU_DIS_MASK 0x20
45#define EFUSE_GPU_DIS_SHIFT 5
46#define IDCODE2_PL_INIT_MASK 0x200
47#define IDCODE2_PL_INIT_SHIFT 9
48
Michal Simek04b7e622015-01-15 10:01:51 +010049DECLARE_GLOBAL_DATA_PTR;
50
Michal Simek8111aff2016-02-01 15:05:58 +010051#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
Ibai Erkiaga4f736182020-08-04 23:17:31 +010052 !defined(CONFIG_SPL_BUILD) || (defined(CONFIG_SPL_FPGA_SUPPORT) && \
53 defined(CONFIG_SPL_BUILD))
54
Michal Simek8111aff2016-02-01 15:05:58 +010055static xilinx_desc zynqmppl = XILINX_ZYNQMP_DESC;
56
Ibai Erkiaga4f736182020-08-04 23:17:31 +010057enum {
58 ZYNQMP_VARIANT_EG = BIT(0U),
59 ZYNQMP_VARIANT_EV = BIT(1U),
60 ZYNQMP_VARIANT_CG = BIT(2U),
61 ZYNQMP_VARIANT_DR = BIT(3U),
62};
63
Michal Simek8111aff2016-02-01 15:05:58 +010064static const struct {
Michal Simek6908b862017-11-06 12:55:59 +010065 u32 id;
Ibai Erkiaga4f736182020-08-04 23:17:31 +010066 u8 device;
67 u8 variants;
Michal Simek8111aff2016-02-01 15:05:58 +010068} zynqmp_devices[] = {
69 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +010070 .id = 0x04711093,
71 .device = 2,
72 .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG,
Michal Simek8111aff2016-02-01 15:05:58 +010073 },
74 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +010075 .id = 0x04710093,
76 .device = 3,
77 .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG,
Michal Simek50d8cef2017-08-22 14:58:53 +020078 },
79 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +010080 .id = 0x04721093,
81 .device = 4,
82 .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG |
83 ZYNQMP_VARIANT_EV,
Michal Simek50d8cef2017-08-22 14:58:53 +020084 },
85 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +010086 .id = 0x04720093,
87 .device = 5,
88 .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG |
89 ZYNQMP_VARIANT_EV,
Michal Simek8111aff2016-02-01 15:05:58 +010090 },
91 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +010092 .id = 0x04739093,
93 .device = 6,
94 .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG,
Michal Simek50d8cef2017-08-22 14:58:53 +020095 },
96 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +010097 .id = 0x04730093,
98 .device = 7,
99 .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG |
100 ZYNQMP_VARIANT_EV,
Michal Simek8111aff2016-02-01 15:05:58 +0100101 },
102 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100103 .id = 0x04738093,
104 .device = 9,
105 .variants = ZYNQMP_VARIANT_EG,
Michal Simek50d8cef2017-08-22 14:58:53 +0200106 },
107 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100108 .id = 0x04740093,
109 .device = 11,
110 .variants = ZYNQMP_VARIANT_EG,
Michal Simek50d8cef2017-08-22 14:58:53 +0200111 },
Michal Simek8111aff2016-02-01 15:05:58 +0100112 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100113 .id = 0x04750093,
114 .device = 15,
115 .variants = ZYNQMP_VARIANT_EG,
Michal Simek8111aff2016-02-01 15:05:58 +0100116 },
117 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100118 .id = 0x04759093,
119 .device = 17,
120 .variants = ZYNQMP_VARIANT_EG,
Michal Simek8111aff2016-02-01 15:05:58 +0100121 },
122 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100123 .id = 0x04758093,
124 .device = 19,
125 .variants = ZYNQMP_VARIANT_EG,
Michal Simek8111aff2016-02-01 15:05:58 +0100126 },
Michal Simekb510e532017-06-02 08:08:59 +0200127 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100128 .id = 0x047E1093,
129 .device = 21,
130 .variants = ZYNQMP_VARIANT_DR,
Michal Simekb510e532017-06-02 08:08:59 +0200131 },
132 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100133 .id = 0x047E3093,
134 .device = 23,
135 .variants = ZYNQMP_VARIANT_DR,
Michal Simekb510e532017-06-02 08:08:59 +0200136 },
137 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100138 .id = 0x047E5093,
139 .device = 25,
140 .variants = ZYNQMP_VARIANT_DR,
Michal Simekb510e532017-06-02 08:08:59 +0200141 },
142 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100143 .id = 0x047E4093,
144 .device = 27,
145 .variants = ZYNQMP_VARIANT_DR,
Michal Simekb510e532017-06-02 08:08:59 +0200146 },
147 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100148 .id = 0x047E0093,
149 .device = 28,
150 .variants = ZYNQMP_VARIANT_DR,
Michal Simekb510e532017-06-02 08:08:59 +0200151 },
152 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100153 .id = 0x047E2093,
154 .device = 29,
155 .variants = ZYNQMP_VARIANT_DR,
Michal Simekb510e532017-06-02 08:08:59 +0200156 },
Siva Durga Prasad Paladugu70866b42019-03-23 15:00:06 +0530157 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100158 .id = 0x047E6093,
159 .device = 39,
160 .variants = ZYNQMP_VARIANT_DR,
Siva Durga Prasad Paladugu70866b42019-03-23 15:00:06 +0530161 },
Siva Durga Prasad Paladugu85f61a82019-07-23 11:56:17 +0530162 {
Michal Simek3fd2ed32020-09-11 09:22:15 +0200163 .id = 0x047FD093,
164 .device = 43,
165 .variants = ZYNQMP_VARIANT_DR,
166 },
167 {
168 .id = 0x047F8093,
169 .device = 46,
170 .variants = ZYNQMP_VARIANT_DR,
171 },
172 {
173 .id = 0x047FF093,
174 .device = 47,
175 .variants = ZYNQMP_VARIANT_DR,
176 },
177 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100178 .id = 0x047FB093,
179 .device = 48,
180 .variants = ZYNQMP_VARIANT_DR,
Siva Durga Prasad Paladugu85f61a82019-07-23 11:56:17 +0530181 },
182 {
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100183 .id = 0x047FE093,
184 .device = 49,
185 .variants = ZYNQMP_VARIANT_DR,
Siva Durga Prasad Paladugu85f61a82019-07-23 11:56:17 +0530186 },
Michal Simek8111aff2016-02-01 15:05:58 +0100187};
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530188
Michal Simek8111aff2016-02-01 15:05:58 +0100189static char *zynqmp_get_silicon_idcode_name(void)
190{
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100191 u32 i;
192 u32 idcode, idcode2;
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530193 static char name[ZYNQMP_VERSION_SIZE];
Ibai Erkiagac318ecb2020-08-04 23:17:30 +0100194 u32 ret_payload[PAYLOAD_ARG_CNT];
195
196 xilinx_pm_request(PM_GET_CHIPID, 0, 0, 0, 0, ret_payload);
197
198 /*
199 * Firmware returns:
200 * payload[0][31:0] = status of the operation
201 * payload[1]] = IDCODE
202 * payload[2][19:0] = Version
203 * payload[2][28:20] = EXTENDED_IDCODE
204 * payload[2][29] = PL_INIT
205 */
206
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100207 idcode = ret_payload[1];
208 idcode2 = ret_payload[2] >> ZYNQMP_CSU_VERSION_EMPTY_SHIFT;
209 debug("%s, IDCODE: 0x%0X, IDCODE2: 0x%0X\r\n", __func__, idcode,
210 idcode2);
Michal Simek50d8cef2017-08-22 14:58:53 +0200211
Michal Simek8111aff2016-02-01 15:05:58 +0100212 for (i = 0; i < ARRAY_SIZE(zynqmp_devices); i++) {
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100213 if (zynqmp_devices[i].id == (idcode & 0x0FFFFFFF))
214 break;
Michal Simek8111aff2016-02-01 15:05:58 +0100215 }
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530216
217 if (i >= ARRAY_SIZE(zynqmp_devices))
218 return "unknown";
219
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100220 /* Add device prefix to the name */
Siva Durga Prasad Paladugu951c0192018-10-26 17:47:55 +0530221 strncat(name, "zu", 2);
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100222 strncat(&name[2], simple_itoa(zynqmp_devices[i].device), 2);
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530223
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100224 if (zynqmp_devices[i].variants & ZYNQMP_VARIANT_EV) {
225 /* Devices with EV variant might be EG/CG/EV family */
226 if (idcode2 & IDCODE2_PL_INIT_MASK) {
227 u32 family = ((idcode2 & EFUSE_VCU_DIS_MASK) >>
228 EFUSE_VCU_DIS_SHIFT) << 1 |
229 ((idcode2 & EFUSE_GPU_DIS_MASK) >>
230 EFUSE_GPU_DIS_SHIFT);
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530231
Ibai Erkiaga4f736182020-08-04 23:17:31 +0100232 /*
233 * Get family name based on extended idcode values as
234 * determined on UG1087, EXTENDED_IDCODE register
235 * description
236 */
237 switch (family) {
238 case 0x00:
239 strncat(name, "ev", 2);
240 break;
241 case 0x10:
242 strncat(name, "eg", 2);
243 break;
244 case 0x11:
245 strncat(name, "cg", 2);
246 break;
247 default:
248 /* Do not append family name*/
249 break;
250 }
251 } else {
252 /*
253 * When PL powered down the VCU Disable efuse cannot be
254 * read. So, ignore the bit and just findout if it is CG
255 * or EG/EV variant.
256 */
257 strncat(name, (idcode2 & EFUSE_GPU_DIS_MASK) ? "cg" :
258 "e", 2);
259 }
260 } else if (zynqmp_devices[i].variants & ZYNQMP_VARIANT_CG) {
261 /* Devices with CG variant might be EG or CG family */
262 strncat(name, (idcode2 & EFUSE_GPU_DIS_MASK) ? "cg" : "eg", 2);
263 } else if (zynqmp_devices[i].variants & ZYNQMP_VARIANT_EG) {
264 strncat(name, "eg", 2);
265 } else if (zynqmp_devices[i].variants & ZYNQMP_VARIANT_DR) {
266 strncat(name, "dr", 2);
267 } else {
268 debug("Variant not identified\n");
Siva Durga Prasad Paladuguba2622d2018-03-02 16:20:10 +0530269 }
270
271 return name;
Michal Simek8111aff2016-02-01 15:05:58 +0100272}
273#endif
274
Michal Simek8b353302017-02-07 14:32:26 +0100275int board_early_init_f(void)
276{
Michal Simek1a1ab5a2018-01-15 12:52:59 +0100277#if defined(CONFIG_ZYNQMP_PSU_INIT_ENABLED)
Michal Simek09a7d7d2020-01-07 09:02:52 +0100278 int ret;
279
Michal Simekc8785f22018-01-10 11:48:48 +0100280 ret = psu_init();
Michal Simek09a7d7d2020-01-07 09:02:52 +0100281 if (ret)
282 return ret;
Michal Simek1f55e572020-03-20 08:59:02 +0100283
284 /* Delay is required for clocks to be propagated */
285 udelay(1000000);
Michal Simeke0f36102017-07-12 13:08:41 +0200286#endif
287
Michal Simek09a7d7d2020-01-07 09:02:52 +0100288#ifdef CONFIG_DEBUG_UART
289 /* Uart debug for sure */
290 debug_uart_init();
291 puts("Debug uart enabled\n"); /* or printch() */
292#endif
293
294 return 0;
Michal Simek8b353302017-02-07 14:32:26 +0100295}
296
Michal Simek46900462020-02-11 12:43:14 +0100297static int multi_boot(void)
298{
299 u32 multiboot;
300
301 multiboot = readl(&csu_base->multi_boot);
302
Michal Simekc55f2d52020-05-27 12:50:33 +0200303 printf("Multiboot:\t%d\n", multiboot);
Michal Simek46900462020-02-11 12:43:14 +0100304
305 return 0;
306}
307
Mike Looijmans9863e2f2019-10-18 07:34:13 +0200308#define PS_SYSMON_ANALOG_BUS_VAL 0x3210
309#define PS_SYSMON_ANALOG_BUS_REG 0xFFA50914
310
Michal Simek04b7e622015-01-15 10:01:51 +0100311int board_init(void)
312{
Michal Simek826d7eca2020-03-04 08:48:16 +0100313#if defined(CONFIG_ZYNQMP_FIRMWARE)
Ibai Erkiaga2d9b95b2019-09-27 11:37:04 +0100314 struct udevice *dev;
315
316 uclass_get_device_by_name(UCLASS_FIRMWARE, "zynqmp-power", &dev);
317 if (!dev)
318 panic("PMU Firmware device not found - Enable it");
Michal Simek826d7eca2020-03-04 08:48:16 +0100319#endif
Ibai Erkiaga2d9b95b2019-09-27 11:37:04 +0100320
Luca Ceresoli23e65002019-05-21 18:06:43 +0200321#if defined(CONFIG_SPL_BUILD)
322 /* Check *at build time* if the filename is an non-empty string */
323 if (sizeof(CONFIG_ZYNQMP_SPL_PM_CFG_OBJ_FILE) > 1)
324 zynqmp_pmufw_load_config_object(zynqmp_pm_cfg_obj,
325 zynqmp_pm_cfg_obj_size);
326#endif
327
Michal Simekfb7242d2015-06-22 14:31:06 +0200328 printf("EL Level:\tEL%d\n", current_el());
329
Mike Looijmans9863e2f2019-10-18 07:34:13 +0200330 /* Bug in ROM sets wrong value in this register */
331 writel(PS_SYSMON_ANALOG_BUS_VAL, PS_SYSMON_ANALOG_BUS_REG);
332
Michal Simek8111aff2016-02-01 15:05:58 +0100333#if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
334 !defined(CONFIG_SPL_BUILD) || (defined(CONFIG_SPL_FPGA_SUPPORT) && \
335 defined(CONFIG_SPL_BUILD))
Ibai Erkiagae91ca7c2020-08-04 23:17:29 +0100336 zynqmppl.name = zynqmp_get_silicon_idcode_name();
337 printf("Chip ID:\t%s\n", zynqmppl.name);
338 fpga_init();
339 fpga_add(fpga_xilinx, &zynqmppl);
Michal Simekbf0f9ca2018-04-19 15:43:38 +0200340#endif
341
Michal Simek46900462020-02-11 12:43:14 +0100342 if (current_el() == 3)
343 multi_boot();
344
Michal Simek04b7e622015-01-15 10:01:51 +0100345 return 0;
346}
347
348int board_early_init_r(void)
349{
350 u32 val;
351
Siva Durga Prasad Paladugu64d90002017-12-07 15:05:30 +0530352 if (current_el() != 3)
353 return 0;
354
Michal Simek245d5282017-07-12 10:32:18 +0200355 val = readl(&crlapb_base->timestamp_ref_ctrl);
356 val &= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
357
Siva Durga Prasad Paladugu64d90002017-12-07 15:05:30 +0530358 if (!val) {
Michal Simekc23d3f82015-11-05 08:34:35 +0100359 val = readl(&crlapb_base->timestamp_ref_ctrl);
360 val |= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
361 writel(val, &crlapb_base->timestamp_ref_ctrl);
Michal Simek04b7e622015-01-15 10:01:51 +0100362
Michal Simekc23d3f82015-11-05 08:34:35 +0100363 /* Program freq register in System counter */
364 writel(zynqmp_get_system_timer_freq(),
365 &iou_scntr_secure->base_frequency_id_register);
366 /* And enable system counter */
367 writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN,
368 &iou_scntr_secure->counter_control_register);
369 }
Michal Simek04b7e622015-01-15 10:01:51 +0100370 return 0;
371}
372
Nitin Jainb2eb59b2018-02-16 12:56:17 +0530373unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc,
Simon Glassed38aef2020-05-10 11:40:03 -0600374 char *const argv[])
Nitin Jainb2eb59b2018-02-16 12:56:17 +0530375{
376 int ret = 0;
377
378 if (current_el() > 1) {
379 smp_kick_all_cpus();
380 dcache_disable();
381 armv8_switch_to_el1(0x0, 0, 0, 0, (unsigned long)entry,
382 ES_TO_AARCH64);
383 } else {
384 printf("FAIL: current EL is not above EL1\n");
385 ret = EINVAL;
386 }
387 return ret;
388}
389
Michal Simek8faa66a2016-02-08 09:34:53 +0100390#if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE)
Simon Glass2f949c32017-03-31 08:40:32 -0600391int dram_init_banksize(void)
Michal Simek8faa66a2016-02-08 09:34:53 +0100392{
Nitin Jain9bcc76f2018-04-20 12:30:40 +0530393 int ret;
394
395 ret = fdtdec_setup_memory_banksize();
396 if (ret)
397 return ret;
398
399 mem_map_fill();
400
401 return 0;
Tom Riniedcfdbd2016-12-09 07:56:54 -0500402}
Michal Simek8faa66a2016-02-08 09:34:53 +0100403
Tom Riniedcfdbd2016-12-09 07:56:54 -0500404int dram_init(void)
405{
Siva Durga Prasad Paladugub3d55ea2018-07-16 15:56:11 +0530406 if (fdtdec_setup_mem_size_base() != 0)
Nathan Rossiac04bfa2016-12-19 00:03:34 +1000407 return -EINVAL;
Tom Riniedcfdbd2016-12-09 07:56:54 -0500408
409 return 0;
Michal Simek8faa66a2016-02-08 09:34:53 +0100410}
411#else
Nitin Jain9bcc76f2018-04-20 12:30:40 +0530412int dram_init_banksize(void)
413{
414#if defined(CONFIG_NR_DRAM_BANKS)
415 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
416 gd->bd->bi_dram[0].size = get_effective_memsize();
417#endif
418
419 mem_map_fill();
420
421 return 0;
422}
423
Michal Simek04b7e622015-01-15 10:01:51 +0100424int dram_init(void)
425{
Michal Simek1b846212018-04-11 16:12:28 +0200426 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
427 CONFIG_SYS_SDRAM_SIZE);
Michal Simek04b7e622015-01-15 10:01:51 +0100428
429 return 0;
430}
Michal Simek8faa66a2016-02-08 09:34:53 +0100431#endif
Michal Simek04b7e622015-01-15 10:01:51 +0100432
Michal Simek04b7e622015-01-15 10:01:51 +0100433void reset_cpu(ulong addr)
434{
435}
436
Michal Simek342edfe2018-12-20 09:33:38 +0100437#if defined(CONFIG_BOARD_LATE_INIT)
Michal Simek29b9b712018-05-17 14:06:06 +0200438static const struct {
439 u32 bit;
440 const char *name;
441} reset_reasons[] = {
442 { RESET_REASON_DEBUG_SYS, "DEBUG" },
443 { RESET_REASON_SOFT, "SOFT" },
444 { RESET_REASON_SRST, "SRST" },
445 { RESET_REASON_PSONLY, "PS-ONLY" },
446 { RESET_REASON_PMU, "PMU" },
447 { RESET_REASON_INTERNAL, "INTERNAL" },
448 { RESET_REASON_EXTERNAL, "EXTERNAL" },
449 {}
450};
451
T Karthik Reddy09b6def2019-03-13 20:24:18 +0530452static int reset_reason(void)
Michal Simek29b9b712018-05-17 14:06:06 +0200453{
T Karthik Reddy09b6def2019-03-13 20:24:18 +0530454 u32 reg;
455 int i, ret;
Michal Simek29b9b712018-05-17 14:06:06 +0200456 const char *reason = NULL;
457
T Karthik Reddy09b6def2019-03-13 20:24:18 +0530458 ret = zynqmp_mmio_read((ulong)&crlapb_base->reset_reason, &reg);
459 if (ret)
460 return -EINVAL;
Michal Simek29b9b712018-05-17 14:06:06 +0200461
462 puts("Reset reason:\t");
463
464 for (i = 0; i < ARRAY_SIZE(reset_reasons); i++) {
T Karthik Reddy09b6def2019-03-13 20:24:18 +0530465 if (reg & reset_reasons[i].bit) {
Michal Simek29b9b712018-05-17 14:06:06 +0200466 reason = reset_reasons[i].name;
467 printf("%s ", reset_reasons[i].name);
468 break;
469 }
470 }
471
472 puts("\n");
473
474 env_set("reset_reason", reason);
475
Michal Simek4c4efde2020-03-23 14:02:01 +0100476 ret = zynqmp_mmio_write((ulong)&crlapb_base->reset_reason, ~0, ~0);
T Karthik Reddy09b6def2019-03-13 20:24:18 +0530477 if (ret)
478 return -EINVAL;
Michal Simek29b9b712018-05-17 14:06:06 +0200479
480 return ret;
481}
482
Michal Simek1ca66d72019-02-14 13:14:30 +0100483static int set_fdtfile(void)
484{
485 char *compatible, *fdtfile;
486 const char *suffix = ".dtb";
487 const char *vendor = "xilinx/";
Igor Lantsmane167bac2020-06-24 14:33:46 +0200488 int fdt_compat_len;
Michal Simek1ca66d72019-02-14 13:14:30 +0100489
490 if (env_get("fdtfile"))
491 return 0;
492
Igor Lantsmane167bac2020-06-24 14:33:46 +0200493 compatible = (char *)fdt_getprop(gd->fdt_blob, 0, "compatible",
494 &fdt_compat_len);
495 if (compatible && fdt_compat_len) {
496 char *name;
497
Michal Simek1ca66d72019-02-14 13:14:30 +0100498 debug("Compatible: %s\n", compatible);
499
Igor Lantsmane167bac2020-06-24 14:33:46 +0200500 name = strchr(compatible, ',');
501 if (!name)
502 return -EINVAL;
Michal Simek1ca66d72019-02-14 13:14:30 +0100503
Igor Lantsmane167bac2020-06-24 14:33:46 +0200504 name++;
505
506 fdtfile = calloc(1, strlen(vendor) + strlen(name) +
Michal Simek1ca66d72019-02-14 13:14:30 +0100507 strlen(suffix) + 1);
508 if (!fdtfile)
509 return -ENOMEM;
510
Igor Lantsmane167bac2020-06-24 14:33:46 +0200511 sprintf(fdtfile, "%s%s%s", vendor, name, suffix);
Michal Simek1ca66d72019-02-14 13:14:30 +0100512
513 env_set("fdtfile", fdtfile);
514 free(fdtfile);
515 }
516
517 return 0;
518}
519
Michal Simek9c91e612020-04-08 11:04:41 +0200520static u8 zynqmp_get_bootmode(void)
Michal Simek04b7e622015-01-15 10:01:51 +0100521{
Michal Simek9c91e612020-04-08 11:04:41 +0200522 u8 bootmode;
Michal Simek04b7e622015-01-15 10:01:51 +0100523 u32 reg = 0;
Michal Simek9c91e612020-04-08 11:04:41 +0200524 int ret;
525
526 ret = zynqmp_mmio_read((ulong)&crlapb_base->boot_mode, &reg);
527 if (ret)
528 return -EINVAL;
529
530 if (reg >> BOOT_MODE_ALT_SHIFT)
531 reg >>= BOOT_MODE_ALT_SHIFT;
532
533 bootmode = reg & BOOT_MODES_MASK;
534
535 return bootmode;
536}
537
538int board_late_init(void)
539{
Michal Simek04b7e622015-01-15 10:01:51 +0100540 u8 bootmode;
Michal Simekf183a982018-04-25 11:20:43 +0200541 struct udevice *dev;
542 int bootseq = -1;
543 int bootseq_len = 0;
Michal Simek7410b142018-04-25 11:10:34 +0200544 int env_targets_len = 0;
Michal Simekecfb6dc2016-04-22 14:28:54 +0200545 const char *mode;
546 char *new_targets;
Siva Durga Prasad Paladugu245c5562017-12-20 16:35:06 +0530547 char *env_targets;
Siva Durga Prasad Paladugue6fd3bb2017-02-21 17:58:28 +0530548 int ret;
Michal Simekecfb6dc2016-04-22 14:28:54 +0200549
Michal Simek482f5492018-10-05 08:55:16 +0200550#if defined(CONFIG_USB_ETHER) && !defined(CONFIG_USB_GADGET_DOWNLOAD)
551 usb_ether_init();
552#endif
553
Michal Simekecfb6dc2016-04-22 14:28:54 +0200554 if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
555 debug("Saved variables - Skipping\n");
556 return 0;
557 }
Michal Simek04b7e622015-01-15 10:01:51 +0100558
Michal Simekbab07b62020-07-28 12:45:47 +0200559 if (!CONFIG_IS_ENABLED(ENV_VARS_UBOOT_RUNTIME_CONFIG))
560 return 0;
561
Michal Simek1ca66d72019-02-14 13:14:30 +0100562 ret = set_fdtfile();
563 if (ret)
564 return ret;
565
Michal Simek9c91e612020-04-08 11:04:41 +0200566 bootmode = zynqmp_get_bootmode();
Michal Simek04b7e622015-01-15 10:01:51 +0100567
Michal Simekc5d95232015-09-20 17:20:42 +0200568 puts("Bootmode: ");
Michal Simek04b7e622015-01-15 10:01:51 +0100569 switch (bootmode) {
Michal Simek12398ea2016-08-19 14:14:52 +0200570 case USB_MODE:
571 puts("USB_MODE\n");
572 mode = "usb";
Michal Simek43380352017-12-01 15:18:24 +0100573 env_set("modeboot", "usb_dfu_spl");
Michal Simek12398ea2016-08-19 14:14:52 +0200574 break;
Siva Durga Prasad Paladugu30f0fc72015-03-13 11:10:26 +0530575 case JTAG_MODE:
Michal Simekc5d95232015-09-20 17:20:42 +0200576 puts("JTAG_MODE\n");
Siva Durga Prasad Paladugu9c441702019-06-25 17:41:09 +0530577 mode = "jtag pxe dhcp";
Michal Simek43380352017-12-01 15:18:24 +0100578 env_set("modeboot", "jtagboot");
Siva Durga Prasad Paladugu30f0fc72015-03-13 11:10:26 +0530579 break;
580 case QSPI_MODE_24BIT:
581 case QSPI_MODE_32BIT:
Michal Simekecfb6dc2016-04-22 14:28:54 +0200582 mode = "qspi0";
Michal Simekc5d95232015-09-20 17:20:42 +0200583 puts("QSPI_MODE\n");
Michal Simek43380352017-12-01 15:18:24 +0100584 env_set("modeboot", "qspiboot");
Siva Durga Prasad Paladugu30f0fc72015-03-13 11:10:26 +0530585 break;
Michal Simek02d66cd2015-04-15 15:02:28 +0200586 case EMMC_MODE:
Michal Simekdf7ff0a2015-10-05 15:59:38 +0200587 puts("EMMC_MODE\n");
T Karthik Reddy19735c32019-12-17 06:41:42 -0700588 if (uclass_get_device_by_name(UCLASS_MMC,
589 "mmc@ff160000", &dev) &&
590 uclass_get_device_by_name(UCLASS_MMC,
591 "sdhci@ff160000", &dev)) {
592 puts("Boot from EMMC but without SD0 enabled!\n");
593 return -1;
594 }
595 debug("mmc0 device found at %p, seq %d\n", dev, dev->seq);
596
597 mode = "mmc";
598 bootseq = dev->seq;
Michal Simekdf7ff0a2015-10-05 15:59:38 +0200599 break;
600 case SD_MODE:
Michal Simekc5d95232015-09-20 17:20:42 +0200601 puts("SD_MODE\n");
Michal Simekf183a982018-04-25 11:20:43 +0200602 if (uclass_get_device_by_name(UCLASS_MMC,
Siva Durga Prasad Paladugue91778d2019-01-03 15:44:24 +0530603 "mmc@ff160000", &dev) &&
604 uclass_get_device_by_name(UCLASS_MMC,
Michal Simekf183a982018-04-25 11:20:43 +0200605 "sdhci@ff160000", &dev)) {
606 puts("Boot from SD0 but without SD0 enabled!\n");
607 return -1;
608 }
609 debug("mmc0 device found at %p, seq %d\n", dev, dev->seq);
610
611 mode = "mmc";
612 bootseq = dev->seq;
Michal Simek43380352017-12-01 15:18:24 +0100613 env_set("modeboot", "sdboot");
Michal Simek04b7e622015-01-15 10:01:51 +0100614 break;
Siva Durga Prasad Paladugu29a77d22016-09-21 11:45:05 +0530615 case SD1_LSHFT_MODE:
616 puts("LVL_SHFT_");
617 /* fall through */
Michal Simek108e1842015-10-05 10:51:12 +0200618 case SD_MODE1:
Michal Simekc5d95232015-09-20 17:20:42 +0200619 puts("SD_MODE1\n");
Michal Simekf183a982018-04-25 11:20:43 +0200620 if (uclass_get_device_by_name(UCLASS_MMC,
Siva Durga Prasad Paladugue91778d2019-01-03 15:44:24 +0530621 "mmc@ff170000", &dev) &&
622 uclass_get_device_by_name(UCLASS_MMC,
Michal Simekf183a982018-04-25 11:20:43 +0200623 "sdhci@ff170000", &dev)) {
624 puts("Boot from SD1 but without SD1 enabled!\n");
625 return -1;
626 }
627 debug("mmc1 device found at %p, seq %d\n", dev, dev->seq);
628
629 mode = "mmc";
630 bootseq = dev->seq;
Michal Simek43380352017-12-01 15:18:24 +0100631 env_set("modeboot", "sdboot");
Michal Simek108e1842015-10-05 10:51:12 +0200632 break;
633 case NAND_MODE:
Michal Simekc5d95232015-09-20 17:20:42 +0200634 puts("NAND_MODE\n");
Michal Simekecfb6dc2016-04-22 14:28:54 +0200635 mode = "nand0";
Michal Simek43380352017-12-01 15:18:24 +0100636 env_set("modeboot", "nandboot");
Michal Simek108e1842015-10-05 10:51:12 +0200637 break;
Michal Simek04b7e622015-01-15 10:01:51 +0100638 default:
Michal Simekecfb6dc2016-04-22 14:28:54 +0200639 mode = "";
Michal Simek04b7e622015-01-15 10:01:51 +0100640 printf("Invalid Boot Mode:0x%x\n", bootmode);
641 break;
642 }
643
Michal Simekf183a982018-04-25 11:20:43 +0200644 if (bootseq >= 0) {
645 bootseq_len = snprintf(NULL, 0, "%i", bootseq);
646 debug("Bootseq len: %x\n", bootseq_len);
647 }
648
Michal Simekecfb6dc2016-04-22 14:28:54 +0200649 /*
650 * One terminating char + one byte for space between mode
651 * and default boot_targets
652 */
Siva Durga Prasad Paladugu245c5562017-12-20 16:35:06 +0530653 env_targets = env_get("boot_targets");
Michal Simek7410b142018-04-25 11:10:34 +0200654 if (env_targets)
655 env_targets_len = strlen(env_targets);
656
Michal Simekf183a982018-04-25 11:20:43 +0200657 new_targets = calloc(1, strlen(mode) + env_targets_len + 2 +
658 bootseq_len);
Michal Simek089b84d2018-06-13 09:42:41 +0200659 if (!new_targets)
660 return -ENOMEM;
Michal Simek7410b142018-04-25 11:10:34 +0200661
Michal Simekf183a982018-04-25 11:20:43 +0200662 if (bootseq >= 0)
663 sprintf(new_targets, "%s%x %s", mode, bootseq,
664 env_targets ? env_targets : "");
665 else
666 sprintf(new_targets, "%s %s", mode,
667 env_targets ? env_targets : "");
Michal Simekecfb6dc2016-04-22 14:28:54 +0200668
Simon Glass6a38e412017-08-03 12:22:09 -0600669 env_set("boot_targets", new_targets);
Michal Simekecfb6dc2016-04-22 14:28:54 +0200670
Michal Simek29b9b712018-05-17 14:06:06 +0200671 reset_reason();
672
Michal Simek705d44a2020-03-31 12:39:37 +0200673 return board_late_init_xilinx();
Michal Simek04b7e622015-01-15 10:01:51 +0100674}
Michal Simek342edfe2018-12-20 09:33:38 +0100675#endif
Siva Durga Prasad Paladugu650e0a32015-08-04 13:01:05 +0530676
677int checkboard(void)
678{
Michal Simek47ce9362016-01-25 11:04:21 +0100679 puts("Board: Xilinx ZynqMP\n");
Siva Durga Prasad Paladugu650e0a32015-08-04 13:01:05 +0530680 return 0;
681}