diff mbox series

[v3,1/6] sifive: fu540: Add runtime boot mode detection

Message ID 20200604203949.550290-2-jagan@amarulasolutions.com
State Accepted
Commit 868e295ef72535300037fc264e770cfdca3f5894
Headers show
Series riscv: sifive/fu540: SPI boot | expand

Commit Message

Jagan Teki June 4, 2020, 8:39 p.m. UTC
Add support to detect boot mode at runtime for
SiFive FU540 boards.

Signed-off-by: Jagan Teki <jagan at amarulasolutions.com>
---
Changes for v3:
- new patch

 board/sifive/fu540/fu540.c | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

Comments

Bin Meng June 22, 2020, 1:50 p.m. UTC | #1
On Fri, Jun 5, 2020 at 4:40 AM Jagan Teki <jagan at amarulasolutions.com> wrote:
>
> Add support to detect boot mode at runtime for
> SiFive FU540 boards.
>
> Signed-off-by: Jagan Teki <jagan at amarulasolutions.com>
> ---
> Changes for v3:
> - new patch
>
>  board/sifive/fu540/fu540.c | 25 +++++++++++++++++++------
>  1 file changed, 19 insertions(+), 6 deletions(-)
>

Reviewed-by: Bin Meng <bin.meng at windriver.com>
Tested-by: Bin Meng <bin.meng at windriver.com>
diff mbox series

Patch

diff --git a/board/sifive/fu540/fu540.c b/board/sifive/fu540/fu540.c
index fa705dea71..a35b79ace3 100644
--- a/board/sifive/fu540/fu540.c
+++ b/board/sifive/fu540/fu540.c
@@ -10,6 +10,7 @@ 
 #include <env.h>
 #include <init.h>
 #include <log.h>
+#include <linux/bitops.h>
 #include <linux/bug.h>
 #include <linux/delay.h>
 #include <linux/io.h>
@@ -120,14 +121,26 @@  int board_init(void)
 }
 
 #ifdef CONFIG_SPL
+#define MODE_SELECT_REG		0x1000
+#define MODE_SELECT_QSPI	0x6
+#define MODE_SELECT_SD		0xb
+#define MODE_SELECT_MASK	GENMASK(3, 0)
+
 u32 spl_boot_device(void)
 {
-#ifdef CONFIG_SPL_MMC_SUPPORT
-	return BOOT_DEVICE_MMC1;
-#else
-	puts("Unknown boot device\n");
-	hang();
-#endif
+	u32 mode_select = readl((void *)MODE_SELECT_REG);
+	u32 boot_device = mode_select & MODE_SELECT_MASK;
+
+	switch (boot_device) {
+	case MODE_SELECT_QSPI:
+		return BOOT_DEVICE_SPI;
+	case MODE_SELECT_SD:
+		return BOOT_DEVICE_MMC1;
+	default:
+		debug("Unsupported boot device 0x%x but trying MMC1\n",
+		      boot_device);
+		return BOOT_DEVICE_MMC1;
+	}
 }
 #endif