1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2014 - 2015 Xilinx, Inc.
4 * Michal Simek <michal.simek@xilinx.com>
16 #include <asm/arch/clk.h>
17 #include <asm/arch/hardware.h>
18 #include <asm/arch/sys_proto.h>
19 #include <asm/arch/psu_init_gpl.h>
21 #include <dm/device.h>
22 #include <dm/uclass.h>
24 #include <dwc3-uboot.h>
26 #include <zynqmp_firmware.h>
28 #include <linux/sizes.h>
30 #include "pm_cfg_obj.h"
32 DECLARE_GLOBAL_DATA_PTR
;
34 #if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
35 !defined(CONFIG_SPL_BUILD)
36 static xilinx_desc zynqmppl
= XILINX_ZYNQMP_DESC
;
43 } zynqmp_devices
[] = {
135 { /* For testing purpose only */
191 int chip_id(unsigned char id
)
196 if (current_el() != 3) {
197 regs
.regs
[0] = ZYNQMP_SIP_SVC_CSU_DMA_CHIPID
;
206 * regs[0][31:0] = status of the operation
207 * regs[0][63:32] = CSU.IDCODE register
208 * regs[1][31:0] = CSU.version register
209 * regs[1][63:32] = CSU.IDCODE2 register
213 regs
.regs
[0] = upper_32_bits(regs
.regs
[0]);
214 regs
.regs
[0] &= ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK
|
215 ZYNQMP_CSU_IDCODE_SVD_MASK
;
216 regs
.regs
[0] >>= ZYNQMP_CSU_IDCODE_SVD_SHIFT
;
220 regs
.regs
[1] = lower_32_bits(regs
.regs
[1]);
221 regs
.regs
[1] &= ZYNQMP_CSU_SILICON_VER_MASK
;
225 regs
.regs
[1] = lower_32_bits(regs
.regs
[1]);
226 regs
.regs
[1] >>= ZYNQMP_CSU_VERSION_EMPTY_SHIFT
;
230 printf("%s, Invalid Req:0x%x\n", __func__
, id
);
235 val
= readl(ZYNQMP_CSU_IDCODE_ADDR
);
236 val
&= ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK
|
237 ZYNQMP_CSU_IDCODE_SVD_MASK
;
238 val
>>= ZYNQMP_CSU_IDCODE_SVD_SHIFT
;
241 val
= readl(ZYNQMP_CSU_VER_ADDR
);
242 val
&= ZYNQMP_CSU_SILICON_VER_MASK
;
245 printf("%s, Invalid Req:0x%x\n", __func__
, id
);
252 #define ZYNQMP_VERSION_SIZE 9
253 #define ZYNQMP_PL_STATUS_BIT 9
254 #define ZYNQMP_IPDIS_VCU_BIT 8
255 #define ZYNQMP_PL_STATUS_MASK BIT(ZYNQMP_PL_STATUS_BIT)
256 #define ZYNQMP_CSU_VERSION_MASK ~(ZYNQMP_PL_STATUS_MASK)
257 #define ZYNQMP_CSU_VCUDIS_VER_MASK ZYNQMP_CSU_VERSION_MASK & \
258 ~BIT(ZYNQMP_IPDIS_VCU_BIT)
259 #define MAX_VARIANTS_EV 3
261 #if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
262 !defined(CONFIG_SPL_BUILD)
263 static char *zynqmp_get_silicon_idcode_name(void)
267 static char name
[ZYNQMP_VERSION_SIZE
];
269 id
= chip_id(IDCODE
);
270 ver
= chip_id(IDCODE2
);
272 for (i
= 0; i
< ARRAY_SIZE(zynqmp_devices
); i
++) {
273 if (zynqmp_devices
[i
].id
== id
) {
274 if (zynqmp_devices
[i
].evexists
&&
275 !(ver
& ZYNQMP_PL_STATUS_MASK
))
277 if (zynqmp_devices
[i
].ver
== (ver
&
278 ZYNQMP_CSU_VERSION_MASK
))
283 if (i
>= ARRAY_SIZE(zynqmp_devices
))
286 strncat(name
, "zu", 2);
287 if (!zynqmp_devices
[i
].evexists
||
288 (ver
& ZYNQMP_PL_STATUS_MASK
)) {
289 strncat(name
, zynqmp_devices
[i
].name
,
290 ZYNQMP_VERSION_SIZE
- 3);
295 * Here we are means, PL not powered up and ev variant
296 * exists. So, we need to ignore VCU disable bit(8) in
297 * version and findout if its CG or EG/EV variant.
299 for (j
= 0; j
< MAX_VARIANTS_EV
; j
++, i
++) {
300 if ((zynqmp_devices
[i
].ver
& ~BIT(ZYNQMP_IPDIS_VCU_BIT
)) ==
301 (ver
& ZYNQMP_CSU_VCUDIS_VER_MASK
)) {
302 strncat(name
, zynqmp_devices
[i
].name
,
303 ZYNQMP_VERSION_SIZE
- 3);
308 if (j
>= MAX_VARIANTS_EV
)
311 if (strstr(name
, "eg") || strstr(name
, "ev")) {
312 buf
= strstr(name
, "e");
320 int board_early_init_f(void)
324 #if defined(CONFIG_ZYNQMP_PSU_INIT_ENABLED)
335 uclass_get_device_by_name(UCLASS_FIRMWARE
, "zynqmp-power", &dev
);
337 panic("PMU Firmware device not found - Enable it");
339 #if defined(CONFIG_SPL_BUILD)
340 /* Check *at build time* if the filename is an non-empty string */
341 if (sizeof(CONFIG_ZYNQMP_SPL_PM_CFG_OBJ_FILE
) > 1)
342 zynqmp_pmufw_load_config_object(zynqmp_pm_cfg_obj
,
343 zynqmp_pm_cfg_obj_size
);
346 printf("EL Level:\tEL%d\n", current_el());
348 #if defined(CONFIG_FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) && \
349 !defined(CONFIG_SPL_BUILD) || (defined(CONFIG_SPL_FPGA_SUPPORT) && \
350 defined(CONFIG_SPL_BUILD))
351 if (current_el() != 3) {
352 zynqmppl
.name
= zynqmp_get_silicon_idcode_name();
353 printf("Chip ID:\t%s\n", zynqmppl
.name
);
355 fpga_add(fpga_xilinx
, &zynqmppl
);
362 int board_early_init_r(void)
366 if (current_el() != 3)
369 val
= readl(&crlapb_base
->timestamp_ref_ctrl
);
370 val
&= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT
;
373 val
= readl(&crlapb_base
->timestamp_ref_ctrl
);
374 val
|= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT
;
375 writel(val
, &crlapb_base
->timestamp_ref_ctrl
);
377 /* Program freq register in System counter */
378 writel(zynqmp_get_system_timer_freq(),
379 &iou_scntr_secure
->base_frequency_id_register
);
380 /* And enable system counter */
381 writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN
,
382 &iou_scntr_secure
->counter_control_register
);
387 unsigned long do_go_exec(ulong (*entry
)(int, char * const []), int argc
,
392 if (current_el() > 1) {
395 armv8_switch_to_el1(0x0, 0, 0, 0, (unsigned long)entry
,
398 printf("FAIL: current EL is not above EL1\n");
404 #if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE)
405 int dram_init_banksize(void)
409 ret
= fdtdec_setup_memory_banksize();
420 if (fdtdec_setup_mem_size_base() != 0)
426 int dram_init_banksize(void)
428 #if defined(CONFIG_NR_DRAM_BANKS)
429 gd
->bd
->bi_dram
[0].start
= CONFIG_SYS_SDRAM_BASE
;
430 gd
->bd
->bi_dram
[0].size
= get_effective_memsize();
440 gd
->ram_size
= get_ram_size((void *)CONFIG_SYS_SDRAM_BASE
,
441 CONFIG_SYS_SDRAM_SIZE
);
447 void reset_cpu(ulong addr
)
451 #if defined(CONFIG_BOARD_LATE_INIT)
452 static const struct {
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" },
466 static int reset_reason(void)
470 const char *reason
= NULL
;
472 ret
= zynqmp_mmio_read((ulong
)&crlapb_base
->reset_reason
, ®
);
476 puts("Reset reason:\t");
478 for (i
= 0; i
< ARRAY_SIZE(reset_reasons
); i
++) {
479 if (reg
& reset_reasons
[i
].bit
) {
480 reason
= reset_reasons
[i
].name
;
481 printf("%s ", reset_reasons
[i
].name
);
488 env_set("reset_reason", reason
);
490 ret
= zynqmp_mmio_write(~0, ~0, (ulong
)&crlapb_base
->reset_reason
);
497 static int set_fdtfile(void)
499 char *compatible
, *fdtfile
;
500 const char *suffix
= ".dtb";
501 const char *vendor
= "xilinx/";
503 if (env_get("fdtfile"))
506 compatible
= (char *)fdt_getprop(gd
->fdt_blob
, 0, "compatible", NULL
);
508 debug("Compatible: %s\n", compatible
);
510 /* Discard vendor prefix */
511 strsep(&compatible
, ",");
513 fdtfile
= calloc(1, strlen(vendor
) + strlen(compatible
) +
518 sprintf(fdtfile
, "%s%s%s", vendor
, compatible
, suffix
);
520 env_set("fdtfile", fdtfile
);
527 int board_late_init(void)
534 int env_targets_len
= 0;
541 #if defined(CONFIG_USB_ETHER) && !defined(CONFIG_USB_GADGET_DOWNLOAD)
545 if (!(gd
->flags
& GD_FLG_ENV_DEFAULT
)) {
546 debug("Saved variables - Skipping\n");
554 ret
= zynqmp_mmio_read((ulong
)&crlapb_base
->boot_mode
, ®
);
558 if (reg
>> BOOT_MODE_ALT_SHIFT
)
559 reg
>>= BOOT_MODE_ALT_SHIFT
;
561 bootmode
= reg
& BOOT_MODES_MASK
;
568 env_set("modeboot", "usb_dfu_spl");
572 mode
= "jtag pxe dhcp";
573 env_set("modeboot", "jtagboot");
575 case QSPI_MODE_24BIT
:
576 case QSPI_MODE_32BIT
:
579 env_set("modeboot", "qspiboot");
584 env_set("modeboot", "emmcboot");
588 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 SD0 but without SD0 enabled!\n");
595 debug("mmc0 device found at %p, seq %d\n", dev
, dev
->seq
);
599 env_set("modeboot", "sdboot");
606 if (uclass_get_device_by_name(UCLASS_MMC
,
607 "mmc@ff170000", &dev
) &&
608 uclass_get_device_by_name(UCLASS_MMC
,
609 "sdhci@ff170000", &dev
)) {
610 puts("Boot from SD1 but without SD1 enabled!\n");
613 debug("mmc1 device found at %p, seq %d\n", dev
, dev
->seq
);
617 env_set("modeboot", "sdboot");
622 env_set("modeboot", "nandboot");
626 printf("Invalid Boot Mode:0x%x\n", bootmode
);
631 bootseq_len
= snprintf(NULL
, 0, "%i", bootseq
);
632 debug("Bootseq len: %x\n", bootseq_len
);
636 * One terminating char + one byte for space between mode
637 * and default boot_targets
639 env_targets
= env_get("boot_targets");
641 env_targets_len
= strlen(env_targets
);
643 new_targets
= calloc(1, strlen(mode
) + env_targets_len
+ 2 +
649 sprintf(new_targets
, "%s%x %s", mode
, bootseq
,
650 env_targets
? env_targets
: "");
652 sprintf(new_targets
, "%s %s", mode
,
653 env_targets
? env_targets
: "");
655 env_set("boot_targets", new_targets
);
657 initrd_hi
= gd
->start_addr_sp
- CONFIG_STACK_SIZE
;
658 initrd_hi
= round_down(initrd_hi
, SZ_16M
);
659 env_set_addr("initrd_high", (void *)initrd_hi
);
669 puts("Board: Xilinx ZynqMP\n");