Merge git://git.denx.de/u-boot-fsl-qoriq
[oweals/u-boot.git] / arch / arm / mach-imx / spl.c
index 3853e7739d2e665d87f3f0d6d3711c25a099d880..d0d1b73aa638bd12130e380b47a086e6ccaf8d55 100644 (file)
 #include <asm/spl.h>
 #include <spl.h>
 #include <asm/mach-imx/hab.h>
+#include <asm/mach-imx/boot_mode.h>
+#include <g_dnl.h>
+
+DECLARE_GLOBAL_DATA_PTR;
 
 #if defined(CONFIG_MX6)
 /* determine boot device from SRC_SBMR1 (BOOT_CFG[4:1]) or SRC_GPR9 register */
@@ -29,6 +33,18 @@ u32 spl_boot_device(void)
        if (((bmode >> 24) & 0x03) == 0x01) /* Serial Downloader */
                return BOOT_DEVICE_BOARD;
 
+       /*
+        * The above method does not detect that the boot ROM used
+        * serial downloader in case the boot ROM decided to use the
+        * serial downloader as a fall back (primary boot source failed).
+        *
+        * Infer that the boot ROM used the USB serial downloader by
+        * checking whether the USB PHY is currently active... This
+        * assumes that SPL did not (yet) initialize the USB PHY...
+        */
+       if (is_usbotg_phy_active())
+               return BOOT_DEVICE_BOARD;
+
        /* BOOT_CFG1[7:4] - see IMX6DQRM Table 8-8 */
        switch ((reg & IMX6_BMODE_MASK) >> IMX6_BMODE_SHIFT) {
         /* EIM: See 8.5.1, Table 8-9 */
@@ -80,6 +96,35 @@ u32 spl_boot_device(void)
        }
        return BOOT_DEVICE_NONE;
 }
+
+#elif defined(CONFIG_MX7)
+/* Translate iMX7 boot device to the SPL boot device enumeration */
+u32 spl_boot_device(void)
+{
+       enum boot_device boot_device_spl = get_boot_device();
+
+       switch (boot_device_spl) {
+       case SD1_BOOT:
+       case MMC1_BOOT:
+               return BOOT_DEVICE_MMC1;
+       case SD2_BOOT:
+       case MMC2_BOOT:
+               return BOOT_DEVICE_MMC2;
+       case SPI_NOR_BOOT:
+               return BOOT_DEVICE_SPI;
+       default:
+               return BOOT_DEVICE_NONE;
+       }
+}
+#endif /* CONFIG_MX6 || CONFIG_MX7 */
+
+#ifdef CONFIG_SPL_USB_GADGET_SUPPORT
+int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
+{
+       put_unaligned(CONFIG_USB_GADGET_PRODUCT_NUM + 0xfff, &dev->idProduct);
+
+       return 0;
+}
 #endif
 
 #if defined(CONFIG_SPL_MMC_SUPPORT)
@@ -128,3 +173,13 @@ __weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
 }
 
 #endif
+
+#if defined(CONFIG_MX6) && defined(CONFIG_SPL_OS_BOOT)
+int dram_init_banksize(void)
+{
+       gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
+       gd->bd->bi_dram[0].size = imx_ddr_size();
+
+       return 0;
+}
+#endif