xref: /openbmc/u-boot/board/xilinx/zynqmp/zynqmp.c (revision 4490e013ee4f2a4b9b6ca9224221fed2788b6940)
183d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
284c7204bSMichal Simek /*
384c7204bSMichal Simek  * (C) Copyright 2014 - 2015 Xilinx, Inc.
484c7204bSMichal Simek  * Michal Simek <michal.simek@xilinx.com>
584c7204bSMichal Simek  */
684c7204bSMichal Simek 
784c7204bSMichal Simek #include <common.h>
8679b994aSMichal Simek #include <sata.h>
96fe6f135SMichal Simek #include <ahci.h>
106fe6f135SMichal Simek #include <scsi.h>
11b72894f1SMichal Simek #include <malloc.h>
12*4490e013SMichal Simek #include <wdt.h>
130785dfd8SMichal Simek #include <asm/arch/clk.h>
1484c7204bSMichal Simek #include <asm/arch/hardware.h>
1584c7204bSMichal Simek #include <asm/arch/sys_proto.h>
162ad341edSMichal Simek #include <asm/arch/psu_init_gpl.h>
1784c7204bSMichal Simek #include <asm/io.h>
18*4490e013SMichal Simek #include <dm/uclass.h>
1916fa00a7SSiva Durga Prasad Paladugu #include <usb.h>
2016fa00a7SSiva Durga Prasad Paladugu #include <dwc3-uboot.h>
2147e60cbdSMichal Simek #include <zynqmppl.h>
226919b4bfSMichal Simek #include <i2c.h>
239feff385SMichal Simek #include <g_dnl.h>
2484c7204bSMichal Simek 
2584c7204bSMichal Simek DECLARE_GLOBAL_DATA_PTR;
2684c7204bSMichal Simek 
27*4490e013SMichal Simek #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_WDT)
28*4490e013SMichal Simek static struct udevice *watchdog_dev;
29*4490e013SMichal Simek #endif
30*4490e013SMichal Simek 
3147e60cbdSMichal Simek #if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
3247e60cbdSMichal Simek     !defined(CONFIG_SPL_BUILD)
3347e60cbdSMichal Simek static xilinx_desc zynqmppl = XILINX_ZYNQMP_DESC;
3447e60cbdSMichal Simek 
3547e60cbdSMichal Simek static const struct {
368ebdf9efSMichal Simek 	u32 id;
37494fffe7SMichal Simek 	u32 ver;
3847e60cbdSMichal Simek 	char *name;
3983bf2ff0SSiva Durga Prasad Paladugu 	bool evexists;
4047e60cbdSMichal Simek } zynqmp_devices[] = {
4147e60cbdSMichal Simek 	{
4247e60cbdSMichal Simek 		.id = 0x10,
4347e60cbdSMichal Simek 		.name = "3eg",
4447e60cbdSMichal Simek 	},
4547e60cbdSMichal Simek 	{
46494fffe7SMichal Simek 		.id = 0x10,
47494fffe7SMichal Simek 		.ver = 0x2c,
48494fffe7SMichal Simek 		.name = "3cg",
49494fffe7SMichal Simek 	},
50494fffe7SMichal Simek 	{
5147e60cbdSMichal Simek 		.id = 0x11,
5247e60cbdSMichal Simek 		.name = "2eg",
5347e60cbdSMichal Simek 	},
5447e60cbdSMichal Simek 	{
55494fffe7SMichal Simek 		.id = 0x11,
56494fffe7SMichal Simek 		.ver = 0x2c,
57494fffe7SMichal Simek 		.name = "2cg",
58494fffe7SMichal Simek 	},
59494fffe7SMichal Simek 	{
6047e60cbdSMichal Simek 		.id = 0x20,
6147e60cbdSMichal Simek 		.name = "5ev",
6283bf2ff0SSiva Durga Prasad Paladugu 		.evexists = 1,
6347e60cbdSMichal Simek 	},
6447e60cbdSMichal Simek 	{
65494fffe7SMichal Simek 		.id = 0x20,
66494fffe7SMichal Simek 		.ver = 0x100,
67494fffe7SMichal Simek 		.name = "5eg",
6883bf2ff0SSiva Durga Prasad Paladugu 		.evexists = 1,
69494fffe7SMichal Simek 	},
70494fffe7SMichal Simek 	{
71494fffe7SMichal Simek 		.id = 0x20,
72494fffe7SMichal Simek 		.ver = 0x12c,
73494fffe7SMichal Simek 		.name = "5cg",
74494fffe7SMichal Simek 	},
75494fffe7SMichal Simek 	{
7647e60cbdSMichal Simek 		.id = 0x21,
7747e60cbdSMichal Simek 		.name = "4ev",
7883bf2ff0SSiva Durga Prasad Paladugu 		.evexists = 1,
7947e60cbdSMichal Simek 	},
8047e60cbdSMichal Simek 	{
81494fffe7SMichal Simek 		.id = 0x21,
82494fffe7SMichal Simek 		.ver = 0x100,
83494fffe7SMichal Simek 		.name = "4eg",
8483bf2ff0SSiva Durga Prasad Paladugu 		.evexists = 1,
85494fffe7SMichal Simek 	},
86494fffe7SMichal Simek 	{
87494fffe7SMichal Simek 		.id = 0x21,
88494fffe7SMichal Simek 		.ver = 0x12c,
89494fffe7SMichal Simek 		.name = "4cg",
90494fffe7SMichal Simek 	},
91494fffe7SMichal Simek 	{
9247e60cbdSMichal Simek 		.id = 0x30,
9347e60cbdSMichal Simek 		.name = "7ev",
9483bf2ff0SSiva Durga Prasad Paladugu 		.evexists = 1,
9547e60cbdSMichal Simek 	},
9647e60cbdSMichal Simek 	{
97494fffe7SMichal Simek 		.id = 0x30,
98494fffe7SMichal Simek 		.ver = 0x100,
99494fffe7SMichal Simek 		.name = "7eg",
10083bf2ff0SSiva Durga Prasad Paladugu 		.evexists = 1,
101494fffe7SMichal Simek 	},
102494fffe7SMichal Simek 	{
103494fffe7SMichal Simek 		.id = 0x30,
104494fffe7SMichal Simek 		.ver = 0x12c,
105494fffe7SMichal Simek 		.name = "7cg",
106494fffe7SMichal Simek 	},
107494fffe7SMichal Simek 	{
10847e60cbdSMichal Simek 		.id = 0x38,
10947e60cbdSMichal Simek 		.name = "9eg",
11047e60cbdSMichal Simek 	},
11147e60cbdSMichal Simek 	{
112494fffe7SMichal Simek 		.id = 0x38,
113494fffe7SMichal Simek 		.ver = 0x2c,
114494fffe7SMichal Simek 		.name = "9cg",
115494fffe7SMichal Simek 	},
116494fffe7SMichal Simek 	{
11747e60cbdSMichal Simek 		.id = 0x39,
11847e60cbdSMichal Simek 		.name = "6eg",
11947e60cbdSMichal Simek 	},
12047e60cbdSMichal Simek 	{
121494fffe7SMichal Simek 		.id = 0x39,
122494fffe7SMichal Simek 		.ver = 0x2c,
123494fffe7SMichal Simek 		.name = "6cg",
124494fffe7SMichal Simek 	},
125494fffe7SMichal Simek 	{
12647e60cbdSMichal Simek 		.id = 0x40,
12747e60cbdSMichal Simek 		.name = "11eg",
12847e60cbdSMichal Simek 	},
129494fffe7SMichal Simek 	{ /* For testing purpose only */
130494fffe7SMichal Simek 		.id = 0x50,
131494fffe7SMichal Simek 		.ver = 0x2c,
132494fffe7SMichal Simek 		.name = "15cg",
133494fffe7SMichal Simek 	},
13447e60cbdSMichal Simek 	{
13547e60cbdSMichal Simek 		.id = 0x50,
13647e60cbdSMichal Simek 		.name = "15eg",
13747e60cbdSMichal Simek 	},
13847e60cbdSMichal Simek 	{
13947e60cbdSMichal Simek 		.id = 0x58,
14047e60cbdSMichal Simek 		.name = "19eg",
14147e60cbdSMichal Simek 	},
14247e60cbdSMichal Simek 	{
14347e60cbdSMichal Simek 		.id = 0x59,
14447e60cbdSMichal Simek 		.name = "17eg",
14547e60cbdSMichal Simek 	},
146b030fedfSMichal Simek 	{
147b030fedfSMichal Simek 		.id = 0x61,
148b030fedfSMichal Simek 		.name = "21dr",
149b030fedfSMichal Simek 	},
150b030fedfSMichal Simek 	{
151b030fedfSMichal Simek 		.id = 0x63,
152b030fedfSMichal Simek 		.name = "23dr",
153b030fedfSMichal Simek 	},
154b030fedfSMichal Simek 	{
155b030fedfSMichal Simek 		.id = 0x65,
156b030fedfSMichal Simek 		.name = "25dr",
157b030fedfSMichal Simek 	},
158b030fedfSMichal Simek 	{
159b030fedfSMichal Simek 		.id = 0x64,
160b030fedfSMichal Simek 		.name = "27dr",
161b030fedfSMichal Simek 	},
162b030fedfSMichal Simek 	{
163b030fedfSMichal Simek 		.id = 0x60,
164b030fedfSMichal Simek 		.name = "28dr",
165b030fedfSMichal Simek 	},
166b030fedfSMichal Simek 	{
167b030fedfSMichal Simek 		.id = 0x62,
168b030fedfSMichal Simek 		.name = "29dr",
169b030fedfSMichal Simek 	},
17047e60cbdSMichal Simek };
17174ba69dbSSiva Durga Prasad Paladugu #endif
17247e60cbdSMichal Simek 
173f52bf5a3SSiva Durga Prasad Paladugu int chip_id(unsigned char id)
17447e60cbdSMichal Simek {
17547e60cbdSMichal Simek 	struct pt_regs regs;
17674ba69dbSSiva Durga Prasad Paladugu 	int val = -EINVAL;
17774ba69dbSSiva Durga Prasad Paladugu 
17874ba69dbSSiva Durga Prasad Paladugu 	if (current_el() != 3) {
17947e60cbdSMichal Simek 		regs.regs[0] = ZYNQMP_SIP_SVC_CSU_DMA_CHIPID;
18047e60cbdSMichal Simek 		regs.regs[1] = 0;
18147e60cbdSMichal Simek 		regs.regs[2] = 0;
18247e60cbdSMichal Simek 		regs.regs[3] = 0;
18347e60cbdSMichal Simek 
18447e60cbdSMichal Simek 		smc_call(&regs);
18547e60cbdSMichal Simek 
1860cba6abbSSoren Brinkmann 		/*
1870cba6abbSSoren Brinkmann 		 * SMC returns:
1880cba6abbSSoren Brinkmann 		 * regs[0][31:0]  = status of the operation
1890cba6abbSSoren Brinkmann 		 * regs[0][63:32] = CSU.IDCODE register
1900cba6abbSSoren Brinkmann 		 * regs[1][31:0]  = CSU.version register
191494fffe7SMichal Simek 		 * regs[1][63:32] = CSU.IDCODE2 register
1920cba6abbSSoren Brinkmann 		 */
193db3123b4SSiva Durga Prasad Paladugu 		switch (id) {
194db3123b4SSiva Durga Prasad Paladugu 		case IDCODE:
1950cba6abbSSoren Brinkmann 			regs.regs[0] = upper_32_bits(regs.regs[0]);
1960cba6abbSSoren Brinkmann 			regs.regs[0] &= ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK |
1970cba6abbSSoren Brinkmann 					ZYNQMP_CSU_IDCODE_SVD_MASK;
1980cba6abbSSoren Brinkmann 			regs.regs[0] >>= ZYNQMP_CSU_IDCODE_SVD_SHIFT;
199db3123b4SSiva Durga Prasad Paladugu 			val = regs.regs[0];
200db3123b4SSiva Durga Prasad Paladugu 			break;
201db3123b4SSiva Durga Prasad Paladugu 		case VERSION:
202db3123b4SSiva Durga Prasad Paladugu 			regs.regs[1] = lower_32_bits(regs.regs[1]);
203db3123b4SSiva Durga Prasad Paladugu 			regs.regs[1] &= ZYNQMP_CSU_SILICON_VER_MASK;
204db3123b4SSiva Durga Prasad Paladugu 			val = regs.regs[1];
205db3123b4SSiva Durga Prasad Paladugu 			break;
206494fffe7SMichal Simek 		case IDCODE2:
207494fffe7SMichal Simek 			regs.regs[1] = lower_32_bits(regs.regs[1]);
208494fffe7SMichal Simek 			regs.regs[1] >>= ZYNQMP_CSU_VERSION_EMPTY_SHIFT;
209494fffe7SMichal Simek 			val = regs.regs[1];
210494fffe7SMichal Simek 			break;
211db3123b4SSiva Durga Prasad Paladugu 		default:
212db3123b4SSiva Durga Prasad Paladugu 			printf("%s, Invalid Req:0x%x\n", __func__, id);
213db3123b4SSiva Durga Prasad Paladugu 		}
21474ba69dbSSiva Durga Prasad Paladugu 	} else {
21574ba69dbSSiva Durga Prasad Paladugu 		switch (id) {
21674ba69dbSSiva Durga Prasad Paladugu 		case IDCODE:
21774ba69dbSSiva Durga Prasad Paladugu 			val = readl(ZYNQMP_CSU_IDCODE_ADDR);
21874ba69dbSSiva Durga Prasad Paladugu 			val &= ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK |
21974ba69dbSSiva Durga Prasad Paladugu 			       ZYNQMP_CSU_IDCODE_SVD_MASK;
22074ba69dbSSiva Durga Prasad Paladugu 			val >>= ZYNQMP_CSU_IDCODE_SVD_SHIFT;
22174ba69dbSSiva Durga Prasad Paladugu 			break;
22274ba69dbSSiva Durga Prasad Paladugu 		case VERSION:
22374ba69dbSSiva Durga Prasad Paladugu 			val = readl(ZYNQMP_CSU_VER_ADDR);
22474ba69dbSSiva Durga Prasad Paladugu 			val &= ZYNQMP_CSU_SILICON_VER_MASK;
22574ba69dbSSiva Durga Prasad Paladugu 			break;
22674ba69dbSSiva Durga Prasad Paladugu 		default:
22774ba69dbSSiva Durga Prasad Paladugu 			printf("%s, Invalid Req:0x%x\n", __func__, id);
22874ba69dbSSiva Durga Prasad Paladugu 		}
22974ba69dbSSiva Durga Prasad Paladugu 	}
2300cba6abbSSoren Brinkmann 
231db3123b4SSiva Durga Prasad Paladugu 	return val;
23247e60cbdSMichal Simek }
23347e60cbdSMichal Simek 
23483bf2ff0SSiva Durga Prasad Paladugu #define ZYNQMP_VERSION_SIZE		9
23583bf2ff0SSiva Durga Prasad Paladugu #define ZYNQMP_PL_STATUS_BIT		9
23683bf2ff0SSiva Durga Prasad Paladugu #define ZYNQMP_PL_STATUS_MASK		BIT(ZYNQMP_PL_STATUS_BIT)
23783bf2ff0SSiva Durga Prasad Paladugu #define ZYNQMP_CSU_VERSION_MASK		~(ZYNQMP_PL_STATUS_MASK)
23883bf2ff0SSiva Durga Prasad Paladugu 
23974ba69dbSSiva Durga Prasad Paladugu #if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
24074ba69dbSSiva Durga Prasad Paladugu 	!defined(CONFIG_SPL_BUILD)
24147e60cbdSMichal Simek static char *zynqmp_get_silicon_idcode_name(void)
24247e60cbdSMichal Simek {
243494fffe7SMichal Simek 	u32 i, id, ver;
24483bf2ff0SSiva Durga Prasad Paladugu 	char *buf;
24583bf2ff0SSiva Durga Prasad Paladugu 	static char name[ZYNQMP_VERSION_SIZE];
24647e60cbdSMichal Simek 
247db3123b4SSiva Durga Prasad Paladugu 	id = chip_id(IDCODE);
248494fffe7SMichal Simek 	ver = chip_id(IDCODE2);
249494fffe7SMichal Simek 
25047e60cbdSMichal Simek 	for (i = 0; i < ARRAY_SIZE(zynqmp_devices); i++) {
25183bf2ff0SSiva Durga Prasad Paladugu 		if ((zynqmp_devices[i].id == id) &&
25283bf2ff0SSiva Durga Prasad Paladugu 		    (zynqmp_devices[i].ver == (ver &
25383bf2ff0SSiva Durga Prasad Paladugu 		    ZYNQMP_CSU_VERSION_MASK))) {
25483bf2ff0SSiva Durga Prasad Paladugu 			strncat(name, "zu", 2);
25583bf2ff0SSiva Durga Prasad Paladugu 			strncat(name, zynqmp_devices[i].name,
25683bf2ff0SSiva Durga Prasad Paladugu 				ZYNQMP_VERSION_SIZE - 3);
25783bf2ff0SSiva Durga Prasad Paladugu 			break;
25847e60cbdSMichal Simek 		}
25983bf2ff0SSiva Durga Prasad Paladugu 	}
26083bf2ff0SSiva Durga Prasad Paladugu 
26183bf2ff0SSiva Durga Prasad Paladugu 	if (i >= ARRAY_SIZE(zynqmp_devices))
26247e60cbdSMichal Simek 		return "unknown";
26383bf2ff0SSiva Durga Prasad Paladugu 
26483bf2ff0SSiva Durga Prasad Paladugu 	if (!zynqmp_devices[i].evexists)
26583bf2ff0SSiva Durga Prasad Paladugu 		return name;
26683bf2ff0SSiva Durga Prasad Paladugu 
26783bf2ff0SSiva Durga Prasad Paladugu 	if (ver & ZYNQMP_PL_STATUS_MASK)
26883bf2ff0SSiva Durga Prasad Paladugu 		return name;
26983bf2ff0SSiva Durga Prasad Paladugu 
27083bf2ff0SSiva Durga Prasad Paladugu 	if (strstr(name, "eg") || strstr(name, "ev")) {
27183bf2ff0SSiva Durga Prasad Paladugu 		buf = strstr(name, "e");
27283bf2ff0SSiva Durga Prasad Paladugu 		*buf = '\0';
27383bf2ff0SSiva Durga Prasad Paladugu 	}
27483bf2ff0SSiva Durga Prasad Paladugu 
27583bf2ff0SSiva Durga Prasad Paladugu 	return name;
27647e60cbdSMichal Simek }
27747e60cbdSMichal Simek #endif
27847e60cbdSMichal Simek 
279fb4000e8SMichal Simek int board_early_init_f(void)
280fb4000e8SMichal Simek {
281f32e79f1SMichal Simek 	int ret = 0;
282fb4000e8SMichal Simek #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_CLK_ZYNQMP)
283fb4000e8SMichal Simek 	zynqmp_pmufw_version();
284fb4000e8SMichal Simek #endif
28555de0929SMichal Simek 
28688f05a92SMichal Simek #if defined(CONFIG_ZYNQMP_PSU_INIT_ENABLED)
287f32e79f1SMichal Simek 	ret = psu_init();
28855de0929SMichal Simek #endif
28955de0929SMichal Simek 
290*4490e013SMichal Simek #if defined(CONFIG_WDT) && !defined(CONFIG_SPL_BUILD)
291*4490e013SMichal Simek 	/* bss is not cleared at time when watchdog_reset() is called */
292*4490e013SMichal Simek 	watchdog_dev = NULL;
293*4490e013SMichal Simek #endif
294*4490e013SMichal Simek 
295f32e79f1SMichal Simek 	return ret;
296fb4000e8SMichal Simek }
297fb4000e8SMichal Simek 
29884c7204bSMichal Simek int board_init(void)
29984c7204bSMichal Simek {
300a0736efbSMichal Simek 	printf("EL Level:\tEL%d\n", current_el());
301a0736efbSMichal Simek 
30247e60cbdSMichal Simek #if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
30347e60cbdSMichal Simek     !defined(CONFIG_SPL_BUILD) || (defined(CONFIG_SPL_FPGA_SUPPORT) && \
30447e60cbdSMichal Simek     defined(CONFIG_SPL_BUILD))
30547e60cbdSMichal Simek 	if (current_el() != 3) {
30683bf2ff0SSiva Durga Prasad Paladugu 		zynqmppl.name = zynqmp_get_silicon_idcode_name();
30747e60cbdSMichal Simek 		printf("Chip ID:\t%s\n", zynqmppl.name);
30847e60cbdSMichal Simek 		fpga_init();
30947e60cbdSMichal Simek 		fpga_add(fpga_xilinx, &zynqmppl);
31047e60cbdSMichal Simek 	}
31147e60cbdSMichal Simek #endif
31247e60cbdSMichal Simek 
313*4490e013SMichal Simek #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_WDT)
314*4490e013SMichal Simek 	if (uclass_get_device(UCLASS_WDT, 0, &watchdog_dev)) {
315*4490e013SMichal Simek 		puts("Watchdog: Not found!\n");
316*4490e013SMichal Simek 	} else {
317*4490e013SMichal Simek 		wdt_start(watchdog_dev, 0, 0);
318*4490e013SMichal Simek 		puts("Watchdog: Started\n");
319*4490e013SMichal Simek 	}
320*4490e013SMichal Simek #endif
321*4490e013SMichal Simek 
32284c7204bSMichal Simek 	return 0;
32384c7204bSMichal Simek }
32484c7204bSMichal Simek 
325*4490e013SMichal Simek #ifdef CONFIG_WATCHDOG
326*4490e013SMichal Simek /* Called by macro WATCHDOG_RESET */
327*4490e013SMichal Simek void watchdog_reset(void)
328*4490e013SMichal Simek {
329*4490e013SMichal Simek # if !defined(CONFIG_SPL_BUILD)
330*4490e013SMichal Simek 	static ulong next_reset;
331*4490e013SMichal Simek 	ulong now;
332*4490e013SMichal Simek 
333*4490e013SMichal Simek 	if (!watchdog_dev)
334*4490e013SMichal Simek 		return;
335*4490e013SMichal Simek 
336*4490e013SMichal Simek 	now = timer_get_us();
337*4490e013SMichal Simek 
338*4490e013SMichal Simek 	/* Do not reset the watchdog too often */
339*4490e013SMichal Simek 	if (now > next_reset) {
340*4490e013SMichal Simek 		wdt_reset(watchdog_dev);
341*4490e013SMichal Simek 		next_reset = now + 1000;
342*4490e013SMichal Simek 	}
343*4490e013SMichal Simek # endif
344*4490e013SMichal Simek }
345*4490e013SMichal Simek #endif
346*4490e013SMichal Simek 
34784c7204bSMichal Simek int board_early_init_r(void)
34884c7204bSMichal Simek {
34984c7204bSMichal Simek 	u32 val;
35084c7204bSMichal Simek 
351ec60a279SSiva Durga Prasad Paladugu 	if (current_el() != 3)
352ec60a279SSiva Durga Prasad Paladugu 		return 0;
353ec60a279SSiva Durga Prasad Paladugu 
35490a35db4SMichal Simek 	val = readl(&crlapb_base->timestamp_ref_ctrl);
35590a35db4SMichal Simek 	val &= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
35690a35db4SMichal Simek 
357ec60a279SSiva Durga Prasad Paladugu 	if (!val) {
35884c7204bSMichal Simek 		val = readl(&crlapb_base->timestamp_ref_ctrl);
35984c7204bSMichal Simek 		val |= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT;
36084c7204bSMichal Simek 		writel(val, &crlapb_base->timestamp_ref_ctrl);
36184c7204bSMichal Simek 
3620785dfd8SMichal Simek 		/* Program freq register in System counter */
3630785dfd8SMichal Simek 		writel(zynqmp_get_system_timer_freq(),
3640785dfd8SMichal Simek 		       &iou_scntr_secure->base_frequency_id_register);
3650785dfd8SMichal Simek 		/* And enable system counter */
3660785dfd8SMichal Simek 		writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN,
3670785dfd8SMichal Simek 		       &iou_scntr_secure->counter_control_register);
3680785dfd8SMichal Simek 	}
36984c7204bSMichal Simek 	return 0;
37084c7204bSMichal Simek }
37184c7204bSMichal Simek 
3726919b4bfSMichal Simek int zynq_board_read_rom_ethaddr(unsigned char *ethaddr)
3736919b4bfSMichal Simek {
3746919b4bfSMichal Simek #if defined(CONFIG_ZYNQ_GEM_EEPROM_ADDR) && \
3756919b4bfSMichal Simek     defined(CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET) && \
3766919b4bfSMichal Simek     defined(CONFIG_ZYNQ_EEPROM_BUS)
3776919b4bfSMichal Simek 	i2c_set_bus_num(CONFIG_ZYNQ_EEPROM_BUS);
3786919b4bfSMichal Simek 
3796919b4bfSMichal Simek 	if (eeprom_read(CONFIG_ZYNQ_GEM_EEPROM_ADDR,
3806919b4bfSMichal Simek 			CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET,
3816919b4bfSMichal Simek 			ethaddr, 6))
3826919b4bfSMichal Simek 		printf("I2C EEPROM MAC address read failed\n");
3836919b4bfSMichal Simek #endif
3846919b4bfSMichal Simek 
3856919b4bfSMichal Simek 	return 0;
3866919b4bfSMichal Simek }
3876919b4bfSMichal Simek 
38851916864SNitin Jain unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc,
38951916864SNitin Jain 			 char * const argv[])
39051916864SNitin Jain {
39151916864SNitin Jain 	int ret = 0;
39251916864SNitin Jain 
39351916864SNitin Jain 	if (current_el() > 1) {
39451916864SNitin Jain 		smp_kick_all_cpus();
39551916864SNitin Jain 		dcache_disable();
39651916864SNitin Jain 		armv8_switch_to_el1(0x0, 0, 0, 0, (unsigned long)entry,
39751916864SNitin Jain 				    ES_TO_AARCH64);
39851916864SNitin Jain 	} else {
39951916864SNitin Jain 		printf("FAIL: current EL is not above EL1\n");
40051916864SNitin Jain 		ret = EINVAL;
40151916864SNitin Jain 	}
40251916864SNitin Jain 	return ret;
40351916864SNitin Jain }
40451916864SNitin Jain 
4058d59d7f6SMichal Simek #if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE)
40676b00acaSSimon Glass int dram_init_banksize(void)
407361a8799STom Rini {
408da3f003bSMichal Simek 	return fdtdec_setup_memory_banksize();
4098d59d7f6SMichal Simek }
4108d59d7f6SMichal Simek 
4118d59d7f6SMichal Simek int dram_init(void)
4128d59d7f6SMichal Simek {
413950f86caSNathan Rossi 	if (fdtdec_setup_memory_size() != 0)
414950f86caSNathan Rossi 		return -EINVAL;
4158d59d7f6SMichal Simek 
4168d59d7f6SMichal Simek 	return 0;
4178d59d7f6SMichal Simek }
4188d59d7f6SMichal Simek #else
41984c7204bSMichal Simek int dram_init(void)
42084c7204bSMichal Simek {
42161dc92a2SMichal Simek 	gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
42261dc92a2SMichal Simek 				    CONFIG_SYS_SDRAM_SIZE);
42384c7204bSMichal Simek 
42484c7204bSMichal Simek 	return 0;
42584c7204bSMichal Simek }
4268d59d7f6SMichal Simek #endif
42784c7204bSMichal Simek 
42884c7204bSMichal Simek void reset_cpu(ulong addr)
42984c7204bSMichal Simek {
43084c7204bSMichal Simek }
43184c7204bSMichal Simek 
43284c7204bSMichal Simek int board_late_init(void)
43384c7204bSMichal Simek {
43484c7204bSMichal Simek 	u32 reg = 0;
43584c7204bSMichal Simek 	u8 bootmode;
436b72894f1SMichal Simek 	const char *mode;
437b72894f1SMichal Simek 	char *new_targets;
43801c42d3dSSiva Durga Prasad Paladugu 	char *env_targets;
439d1db89f4SSiva Durga Prasad Paladugu 	int ret;
440b72894f1SMichal Simek 
441b72894f1SMichal Simek 	if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
442b72894f1SMichal Simek 		debug("Saved variables - Skipping\n");
443b72894f1SMichal Simek 		return 0;
444b72894f1SMichal Simek 	}
44584c7204bSMichal Simek 
446d1db89f4SSiva Durga Prasad Paladugu 	ret = zynqmp_mmio_read((ulong)&crlapb_base->boot_mode, &reg);
447d1db89f4SSiva Durga Prasad Paladugu 	if (ret)
448d1db89f4SSiva Durga Prasad Paladugu 		return -EINVAL;
449d1db89f4SSiva Durga Prasad Paladugu 
45047359a03SMichal Simek 	if (reg >> BOOT_MODE_ALT_SHIFT)
45147359a03SMichal Simek 		reg >>= BOOT_MODE_ALT_SHIFT;
45247359a03SMichal Simek 
45384c7204bSMichal Simek 	bootmode = reg & BOOT_MODES_MASK;
45484c7204bSMichal Simek 
455fb90917cSMichal Simek 	puts("Bootmode: ");
45684c7204bSMichal Simek 	switch (bootmode) {
457d58fc12eSMichal Simek 	case USB_MODE:
458d58fc12eSMichal Simek 		puts("USB_MODE\n");
459d58fc12eSMichal Simek 		mode = "usb";
46007656ba5SMichal Simek 		env_set("modeboot", "usb_dfu_spl");
461d58fc12eSMichal Simek 		break;
4620a5bcc8cSSiva Durga Prasad Paladugu 	case JTAG_MODE:
463fb90917cSMichal Simek 		puts("JTAG_MODE\n");
464b72894f1SMichal Simek 		mode = "pxe dhcp";
46507656ba5SMichal Simek 		env_set("modeboot", "jtagboot");
4660a5bcc8cSSiva Durga Prasad Paladugu 		break;
4670a5bcc8cSSiva Durga Prasad Paladugu 	case QSPI_MODE_24BIT:
4680a5bcc8cSSiva Durga Prasad Paladugu 	case QSPI_MODE_32BIT:
469b72894f1SMichal Simek 		mode = "qspi0";
470fb90917cSMichal Simek 		puts("QSPI_MODE\n");
47107656ba5SMichal Simek 		env_set("modeboot", "qspiboot");
4720a5bcc8cSSiva Durga Prasad Paladugu 		break;
47339c56f55SMichal Simek 	case EMMC_MODE:
47478678feeSMichal Simek 		puts("EMMC_MODE\n");
475b72894f1SMichal Simek 		mode = "mmc0";
47607656ba5SMichal Simek 		env_set("modeboot", "emmcboot");
47778678feeSMichal Simek 		break;
47878678feeSMichal Simek 	case SD_MODE:
479fb90917cSMichal Simek 		puts("SD_MODE\n");
480b72894f1SMichal Simek 		mode = "mmc0";
48107656ba5SMichal Simek 		env_set("modeboot", "sdboot");
48284c7204bSMichal Simek 		break;
483e1992276SSiva Durga Prasad Paladugu 	case SD1_LSHFT_MODE:
484e1992276SSiva Durga Prasad Paladugu 		puts("LVL_SHFT_");
485e1992276SSiva Durga Prasad Paladugu 		/* fall through */
486af813acdSMichal Simek 	case SD_MODE1:
487fb90917cSMichal Simek 		puts("SD_MODE1\n");
4882d9925bcSMichal Simek #if defined(CONFIG_ZYNQ_SDHCI0) && defined(CONFIG_ZYNQ_SDHCI1)
489b72894f1SMichal Simek 		mode = "mmc1";
49007656ba5SMichal Simek 		env_set("sdbootdev", "1");
491b72894f1SMichal Simek #else
492b72894f1SMichal Simek 		mode = "mmc0";
4932d9925bcSMichal Simek #endif
49407656ba5SMichal Simek 		env_set("modeboot", "sdboot");
495af813acdSMichal Simek 		break;
496af813acdSMichal Simek 	case NAND_MODE:
497fb90917cSMichal Simek 		puts("NAND_MODE\n");
498b72894f1SMichal Simek 		mode = "nand0";
49907656ba5SMichal Simek 		env_set("modeboot", "nandboot");
500af813acdSMichal Simek 		break;
50184c7204bSMichal Simek 	default:
502b72894f1SMichal Simek 		mode = "";
50384c7204bSMichal Simek 		printf("Invalid Boot Mode:0x%x\n", bootmode);
50484c7204bSMichal Simek 		break;
50584c7204bSMichal Simek 	}
50684c7204bSMichal Simek 
507b72894f1SMichal Simek 	/*
508b72894f1SMichal Simek 	 * One terminating char + one byte for space between mode
509b72894f1SMichal Simek 	 * and default boot_targets
510b72894f1SMichal Simek 	 */
51101c42d3dSSiva Durga Prasad Paladugu 	env_targets = env_get("boot_targets");
51201c42d3dSSiva Durga Prasad Paladugu 	if (env_targets) {
513b72894f1SMichal Simek 		new_targets = calloc(1, strlen(mode) +
51401c42d3dSSiva Durga Prasad Paladugu 				     strlen(env_targets) + 2);
51501c42d3dSSiva Durga Prasad Paladugu 		sprintf(new_targets, "%s %s", mode, env_targets);
51601c42d3dSSiva Durga Prasad Paladugu 	} else {
51701c42d3dSSiva Durga Prasad Paladugu 		new_targets = calloc(1, strlen(mode) + 2);
51801c42d3dSSiva Durga Prasad Paladugu 		sprintf(new_targets, "%s", mode);
51901c42d3dSSiva Durga Prasad Paladugu 	}
520b72894f1SMichal Simek 
521382bee57SSimon Glass 	env_set("boot_targets", new_targets);
522b72894f1SMichal Simek 
52384c7204bSMichal Simek 	return 0;
52484c7204bSMichal Simek }
52584696ff5SSiva Durga Prasad Paladugu 
52684696ff5SSiva Durga Prasad Paladugu int checkboard(void)
52784696ff5SSiva Durga Prasad Paladugu {
5285af08556SMichal Simek 	puts("Board: Xilinx ZynqMP\n");
52984696ff5SSiva Durga Prasad Paladugu 	return 0;
53084696ff5SSiva Durga Prasad Paladugu }
53116fa00a7SSiva Durga Prasad Paladugu 
53216fa00a7SSiva Durga Prasad Paladugu #ifdef CONFIG_USB_DWC3
533275bd6d1SMichal Simek static struct dwc3_device dwc3_device_data0 = {
53416fa00a7SSiva Durga Prasad Paladugu 	.maximum_speed = USB_SPEED_HIGH,
53516fa00a7SSiva Durga Prasad Paladugu 	.base = ZYNQMP_USB0_XHCI_BASEADDR,
53616fa00a7SSiva Durga Prasad Paladugu 	.dr_mode = USB_DR_MODE_PERIPHERAL,
53716fa00a7SSiva Durga Prasad Paladugu 	.index = 0,
53816fa00a7SSiva Durga Prasad Paladugu };
53916fa00a7SSiva Durga Prasad Paladugu 
540275bd6d1SMichal Simek static struct dwc3_device dwc3_device_data1 = {
541275bd6d1SMichal Simek 	.maximum_speed = USB_SPEED_HIGH,
542275bd6d1SMichal Simek 	.base = ZYNQMP_USB1_XHCI_BASEADDR,
543275bd6d1SMichal Simek 	.dr_mode = USB_DR_MODE_PERIPHERAL,
544275bd6d1SMichal Simek 	.index = 1,
545275bd6d1SMichal Simek };
546275bd6d1SMichal Simek 
5479feff385SMichal Simek int usb_gadget_handle_interrupts(int index)
54816fa00a7SSiva Durga Prasad Paladugu {
5499feff385SMichal Simek 	dwc3_uboot_handle_interrupt(index);
55016fa00a7SSiva Durga Prasad Paladugu 	return 0;
55116fa00a7SSiva Durga Prasad Paladugu }
55216fa00a7SSiva Durga Prasad Paladugu 
55316fa00a7SSiva Durga Prasad Paladugu int board_usb_init(int index, enum usb_init_type init)
55416fa00a7SSiva Durga Prasad Paladugu {
555275bd6d1SMichal Simek 	debug("%s: index %x\n", __func__, index);
556275bd6d1SMichal Simek 
5578ecd50c8SMichal Simek #if defined(CONFIG_USB_GADGET_DOWNLOAD)
5588ecd50c8SMichal Simek 	g_dnl_set_serialnumber(CONFIG_SYS_CONFIG_NAME);
5598ecd50c8SMichal Simek #endif
5608ecd50c8SMichal Simek 
561275bd6d1SMichal Simek 	switch (index) {
562275bd6d1SMichal Simek 	case 0:
563275bd6d1SMichal Simek 		return dwc3_uboot_init(&dwc3_device_data0);
564275bd6d1SMichal Simek 	case 1:
565275bd6d1SMichal Simek 		return dwc3_uboot_init(&dwc3_device_data1);
566275bd6d1SMichal Simek 	};
567275bd6d1SMichal Simek 
568275bd6d1SMichal Simek 	return -1;
56916fa00a7SSiva Durga Prasad Paladugu }
57016fa00a7SSiva Durga Prasad Paladugu 
57116fa00a7SSiva Durga Prasad Paladugu int board_usb_cleanup(int index, enum usb_init_type init)
57216fa00a7SSiva Durga Prasad Paladugu {
57316fa00a7SSiva Durga Prasad Paladugu 	dwc3_uboot_exit(index);
57416fa00a7SSiva Durga Prasad Paladugu 	return 0;
57516fa00a7SSiva Durga Prasad Paladugu }
57616fa00a7SSiva Durga Prasad Paladugu #endif
577