Merge branch 'next'
[oweals/u-boot.git] / board / xilinx / zynqmp / zynqmp.c
index d649daba96d49ac9a0cfbc391b508621ffcf5050..3c92b1a5825f5a422770f60b617dd56683928997 100644 (file)
@@ -5,7 +5,10 @@
  */
 
 #include <common.h>
+#include <cpu_func.h>
+#include <debug_uart.h>
 #include <env.h>
+#include <init.h>
 #include <sata.h>
 #include <ahci.h>
 #include <scsi.h>
@@ -21,7 +24,9 @@
 #include <usb.h>
 #include <dwc3-uboot.h>
 #include <zynqmppl.h>
+#include <zynqmp_firmware.h>
 #include <g_dnl.h>
+#include <linux/sizes.h>
 
 #include "pm_cfg_obj.h"
 
@@ -173,6 +178,14 @@ static const struct {
                .id = 0x66,
                .name = "39dr",
        },
+       {
+               .id = 0x7b,
+               .name = "48dr",
+       },
+       {
+               .id = 0x7e,
+               .name = "49dr",
+       },
 };
 #endif
 
@@ -307,29 +320,47 @@ static char *zynqmp_get_silicon_idcode_name(void)
 
 int board_early_init_f(void)
 {
-       int ret = 0;
-#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_CLK_ZYNQMP)
-       u32 pm_api_version;
+#if defined(CONFIG_ZYNQMP_PSU_INIT_ENABLED)
+       int ret;
 
-       pm_api_version = zynqmp_pmufw_version();
-       printf("PMUFW:\tv%d.%d\n",
-              pm_api_version >> ZYNQMP_PM_VERSION_MAJOR_SHIFT,
-              pm_api_version & ZYNQMP_PM_VERSION_MINOR_MASK);
+       ret = psu_init();
+       if (ret)
+               return ret;
 
-       if (pm_api_version < ZYNQMP_PM_VERSION)
-               panic("PMUFW version error. Expected: v%d.%d\n",
-                     ZYNQMP_PM_VERSION_MAJOR, ZYNQMP_PM_VERSION_MINOR);
+       /* Delay is required for clocks to be propagated */
+       udelay(1000000);
 #endif
 
-#if defined(CONFIG_ZYNQMP_PSU_INIT_ENABLED)
-       ret = psu_init();
+#ifdef CONFIG_DEBUG_UART
+       /* Uart debug for sure */
+       debug_uart_init();
+       puts("Debug uart enabled\n"); /* or printch() */
 #endif
 
-       return ret;
+       return 0;
+}
+
+static int multi_boot(void)
+{
+       u32 multiboot;
+
+       multiboot = readl(&csu_base->multi_boot);
+
+       printf("Multiboot:\t%x\n", multiboot);
+
+       return 0;
 }
 
 int board_init(void)
 {
+#if defined(CONFIG_ZYNQMP_FIRMWARE)
+       struct udevice *dev;
+
+       uclass_get_device_by_name(UCLASS_FIRMWARE, "zynqmp-power", &dev);
+       if (!dev)
+               panic("PMU Firmware device not found - Enable it");
+#endif
+
 #if defined(CONFIG_SPL_BUILD)
        /* Check *at build time* if the filename is an non-empty string */
        if (sizeof(CONFIG_ZYNQMP_SPL_PM_CFG_OBJ_FILE) > 1)
@@ -350,6 +381,9 @@ int board_init(void)
        }
 #endif
 
+       if (current_el() == 3)
+               multi_boot();
+
        return 0;
 }
 
@@ -481,7 +515,7 @@ static int reset_reason(void)
 
        env_set("reset_reason", reason);
 
-       ret = zynqmp_mmio_write(~0, ~0, (ulong)&crlapb_base->reset_reason);
+       ret = zynqmp_mmio_write((ulong)&crlapb_base->reset_reason, ~0, ~0);
        if (ret)
                return -EINVAL;
 
@@ -530,6 +564,7 @@ int board_late_init(void)
        char *new_targets;
        char *env_targets;
        int ret;
+       ulong initrd_hi;
 
 #if defined(CONFIG_USB_ETHER) && !defined(CONFIG_USB_GADGET_DOWNLOAD)
        usb_ether_init();
@@ -562,7 +597,7 @@ int board_late_init(void)
                break;
        case JTAG_MODE:
                puts("JTAG_MODE\n");
-               mode = "pxe dhcp";
+               mode = "jtag pxe dhcp";
                env_set("modeboot", "jtagboot");
                break;
        case QSPI_MODE_24BIT:
@@ -573,8 +608,17 @@ int board_late_init(void)
                break;
        case EMMC_MODE:
                puts("EMMC_MODE\n");
-               mode = "mmc0";
-               env_set("modeboot", "emmcboot");
+               if (uclass_get_device_by_name(UCLASS_MMC,
+                                             "mmc@ff160000", &dev) &&
+                   uclass_get_device_by_name(UCLASS_MMC,
+                                             "sdhci@ff160000", &dev)) {
+                       puts("Boot from EMMC but without SD0 enabled!\n");
+                       return -1;
+               }
+               debug("mmc0 device found at %p, seq %d\n", dev, dev->seq);
+
+               mode = "mmc";
+               bootseq = dev->seq;
                break;
        case SD_MODE:
                puts("SD_MODE\n");
@@ -647,6 +691,12 @@ int board_late_init(void)
 
        env_set("boot_targets", new_targets);
 
+       initrd_hi = gd->start_addr_sp - CONFIG_STACK_SIZE;
+       initrd_hi = round_down(initrd_hi, SZ_16M);
+       env_set_addr("initrd_high", (void *)initrd_hi);
+
+       env_set_hex("script_offset_f", CONFIG_BOOT_SCRIPT_OFFSET);
+
        reset_reason();
 
        return 0;