armv8: lx2160a: add MMU table entries for PCIe
[oweals/u-boot.git] / arch / arm / mach-rockchip / bootrom.c
index e369fdc25a88e90131d80fb2cba2644e34f8d430..9ccb45e6acd26e70cf3a782d428c28a95d1e4f08 100644 (file)
@@ -1,11 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0+
 /**
  * Copyright (c) 2017 Google, Inc
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
-#include <asm/arch/bootrom.h>
+#include <asm/arch-rockchip/bootrom.h>
+#include <asm/arch-rockchip/boot_mode.h>
+#include <asm/io.h>
 #include <asm/setjmp.h>
 #include <asm/system.h>
 
  */
 static jmp_buf brom_ctx __section(".data");
 
+static void _back_to_bootrom(enum rockchip_bootrom_cmd brom_cmd)
+{
+       longjmp(brom_ctx, brom_cmd);
+}
+
 void back_to_bootrom(enum rockchip_bootrom_cmd brom_cmd)
 {
 #if CONFIG_IS_ENABLED(LIBCOMMON_SUPPORT)
        puts("Returning to boot ROM...\n");
 #endif
-       longjmp(brom_ctx, brom_cmd);
+       _back_to_bootrom(brom_cmd);
+}
+
+/*
+ * we back to bootrom download mode if get a
+ * BOOT_BROM_DOWNLOAD flag in boot mode register
+ *
+ * note: the boot mode register is configured by
+ * application(next stage bootloader, kernel, etc),
+ * and the bootrom never check this register, so we need
+ * to check it and back to bootrom at very early bootstage(before
+ * some basic configurations(such as interrupts) been
+ * changed by TPL/SPL, as the bootrom download operation
+ * relys on many default settings(such as interrupts) by
+ * it's self.
+ */
+static bool check_back_to_brom_dnl_flag(void)
+{
+       u32 boot_mode;
+
+       if (CONFIG_ROCKCHIP_BOOT_MODE_REG) {
+               boot_mode = readl(CONFIG_ROCKCHIP_BOOT_MODE_REG);
+               if (boot_mode == BOOT_BROM_DOWNLOAD) {
+                       writel(0, CONFIG_ROCKCHIP_BOOT_MODE_REG);
+                       return true;
+               }
+       }
+
+       return false;
 }
 
 /*
@@ -34,6 +68,8 @@ int save_boot_params(void)
 
        switch (ret) {
        case 0:
+               if (check_back_to_brom_dnl_flag())
+                       _back_to_bootrom(BROM_BOOT_ENTER_DNL);
                /*
                 * This is the initial pass through this function
                 * (i.e. saving the context), setjmp just setup up the
@@ -54,7 +90,13 @@ int save_boot_params(void)
                 */
                ret = 0;
                break;
-
+       case BROM_BOOT_ENTER_DNL:
+               /*
+                * A non-zero return value will instruct the BROM enter
+                * download mode.
+                */
+               ret = 1;
+               break;
        default:
 #if CONFIG_IS_ENABLED(LIBCOMMON_SUPPORT)
                puts("FATAL: unexpected command to back_to_bootrom()\n");