All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Chung <eric.chung@riscstar.com>
To: u-boot-spacemit@groups.io, u-boot@lists.u-boot-project.org,
	 u-boot@lists.u-boot-project.org
Cc: Tom Rini <trini@konsulko.com>, Tim Ouyang <tim609@andestech.com>,
	 Leo Liang <leo.liang@sifive.com>, Peng Fan <peng.fan@nxp.com>,
	 Huan Zhou <pericycle.cc@gmail.com>,
	Raymond Mao <raymond.mao@riscstar.com>,
	 Jaehoon Chung <jh80.chung@samsung.com>,
	 Bhimeswararao Matsa <bhimeswararao.matsa@gmail.com>,
	 Tanmay Kathpalia <tanmay.kathpalia@altera.com>,
	 Kaustabh Chakraborty <kauschluss@disroot.org>,
	Han Xu <han.xu@nxp.com>,  Yanir Levin <yanir.levin@tandemg.com>,
	 Christoph Stoidner <c.stoidner@phytec.de>,
	 Balsundar Ponnusamy <balsundar.ponnusamy@altera.com>,
	 Daniel Palmer <daniel@thingy.jp>, Anshul Dalal <anshuld@ti.com>,
	 Bastien Curutchet <bastien.curutchet@bootlin.com>,
	 Angelo Dureghello <angelo@kernel-space.org>,
	 Johan Jonker <jbx6244@gmail.com>,
	 Sam Protsenko <semen.protsenko@linaro.org>,
	 Guodong Xu <guodong@riscstar.com>, Yao Zi <me@ziyao.cc>,
	 Rick Chen <rick@andestech.com>, Leo <ycliang@andestech.com>,
	 Eric Chung <eric.chung@riscstar.com>
Subject: [PATCH v6 01/11] spacemit: k1: select boot device via config registers
Date: Mon, 27 Jul 2026 14:59:03 +0800	[thread overview]
Message-ID: <20260727-m4-v6-1-2f58566d48ca@riscstar.com> (raw)
In-Reply-To: <20260727-m4-v6-0-2f58566d48ca@riscstar.com>

Add logic to determine the current boot device by reading the
SoC's configuration registers, rather than using a hardcoded
default.

Signed-off-by: Eric Chung <eric.chung@riscstar.com>
Reviewed-by: Yao Zi <me@ziyao.cc>
---
v5:
- Add blank lines around the switch statement.
v2:
- Use FIELD_GET() to parse boot strap mode.
- Remove comments on hacking. Since the sequence between eMMC
  and SD device is exchanged in the upstream DTS. So it isn't
  a hacking any more.
---
 board/spacemit/k1/spl.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 70 insertions(+), 1 deletion(-)

diff --git a/board/spacemit/k1/spl.c b/board/spacemit/k1/spl.c
index d749e21a2d5..613e8c4cf02 100644
--- a/board/spacemit/k1/spl.c
+++ b/board/spacemit/k1/spl.c
@@ -13,6 +13,7 @@
 #include <dm/device.h>
 #include <dm/uclass.h>
 #include <i2c.h>
+#include <linux/bitfield.h>
 #include <linux/ctype.h>
 #include <linux/delay.h>
 #include <log.h>
@@ -22,6 +23,17 @@
 #include <tlv_eeprom.h>
 #include "tlv_codes.h"
 
+/* boot mode configs */
+#define BOOT_DEV_FLAG_REG	0xd4282d10
+#define BOOT_PIN_SEL_REG	0xd4282c20
+
+#define BOOT_STRAP_MODE_OFFSET	9
+#define BOOT_STRAP_MODE_MASK	3
+#define BOOT_STRAP_MODE_EMMC	0
+#define BOOT_STRAP_MODE_SPI	1
+#define BOOT_STRAP_MODE_NAND	2
+#define BOOT_STRAP_MODE_SD	3
+
 #define MUX_MODE4		4
 #define EDGE_NONE		BIT(6)
 #define PULL_UP			(6 << 13)       /* bit[15:13] 110 */
@@ -46,6 +58,17 @@ typedef void (*puts_func_t)(const char *s);
 typedef int (*ddr_init_func_t)(u64 ddr_base, u32 cs_num, u32 data_rate,
 			       puts_func_t puts);
 
+enum board_boot_mode {
+	BOOT_MODE_NONE = 0,
+	BOOT_MODE_USB = 0x55a,
+	BOOT_MODE_EMMC,
+	BOOT_MODE_NAND,
+	BOOT_MODE_SPI,
+	BOOT_MODE_SD,
+	BOOT_MODE_SHELL = 0x55f,
+	BOOT_MODE_BOOTSTRAP,
+};
+
 struct ddr_cfg {
 	u32     data_rate;
 	u32     cs_num;
@@ -354,7 +377,53 @@ void board_init_f(ulong dummy)
 
 u32 spl_boot_device(void)
 {
-	return BOOT_DEVICE_SPI;
+	void __iomem *boot_dev = (void __iomem *)BOOT_DEV_FLAG_REG;
+	void __iomem *boot_strap = (void __iomem *)BOOT_PIN_SEL_REG;
+	u32 mode, sel, ret = 0;
+
+	mode = readl(boot_dev);
+	if (mode == BOOT_MODE_NONE || mode > BOOT_MODE_SD) {
+		sel = FIELD_GET(BOOT_STRAP_MODE_MASK << BOOT_STRAP_MODE_OFFSET,
+				readl(boot_strap));
+		switch (sel) {
+		case BOOT_STRAP_MODE_EMMC:
+			mode = BOOT_MODE_EMMC;
+			break;
+		case BOOT_STRAP_MODE_NAND:
+			mode = BOOT_MODE_NAND;
+			break;
+		case BOOT_STRAP_MODE_SPI:
+			mode = BOOT_MODE_SPI;
+			break;
+		case BOOT_STRAP_MODE_SD:
+		default:
+			mode = BOOT_MODE_SD;
+			break;
+		}
+	}
+
+	switch (mode) {
+	case BOOT_MODE_EMMC:
+		ret = BOOT_DEVICE_MMC1;
+		break;
+	case BOOT_MODE_NAND:
+		ret = BOOT_DEVICE_NAND;
+		break;
+	case BOOT_MODE_SPI:
+		ret = BOOT_DEVICE_SPI;
+		break;
+	case BOOT_MODE_USB:
+		ret = BOOT_DEVICE_USB;
+		break;
+	case BOOT_MODE_SD:
+		ret = BOOT_DEVICE_MMC2;
+		break;
+	default:
+		ret = BOOT_DEVICE_MMC1;
+		break;
+	}
+
+	return ret;
 }
 
 void spl_board_init(void)

-- 
2.51.0


  reply	other threads:[~2026-07-27  6:59 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-27  6:59 [PATCH v6 00/11] spacemit mmc driver Eric Chung
2026-07-27  6:59 ` Eric Chung [this message]
2026-07-27  6:59 ` [PATCH v6 02/11] pinctrl: k1: fix drive strength configuration Eric Chung
2026-07-27  6:59 ` [PATCH v6 03/11] pinctrl: k1: fix pull-up/pull-down configuration Eric Chung
2026-07-27  8:20   ` Yao Zi
2026-07-27  8:24     ` Yao Zi
2026-07-27  6:59 ` [PATCH v6 04/11] pinctrl: k1: add IO power domain configuration support Eric Chung
2026-07-28 17:15   ` Junhui Liu
2026-07-27  6:59 ` [PATCH v6 05/11] mmc: k1: add sdhci platform driver Eric Chung
2026-07-27  6:59 ` [PATCH v6 06/11] dts: k1: add SD card support in u-boot overlay Eric Chung
2026-07-27 11:51   ` Yao Zi
2026-07-27 13:08     ` Eric Chung
2026-07-27 17:07       ` Yao Zi
2026-07-28  1:04         ` Eric Chung
2026-07-28  9:10           ` Yao Zi
2026-07-29 14:05             ` Eric Chung
2026-07-29 15:58               ` Yao Zi
2026-07-30  5:18                 ` Eric Chung
2026-07-27  6:59 ` [PATCH v6 07/11] configs: k1: enable SD and eMMC support Eric Chung
2026-07-27 17:15   ` Yao Zi
2026-07-27  6:59 ` [PATCH v6 08/11] MAINTAINER: update Spacemit K1 entry Eric Chung
2026-07-27  6:59 ` [PATCH v6 09/11] doc: spacemit: flash on K1 SoC based boards Eric Chung
2026-07-27 17:26   ` Yao Zi
2026-07-28  0:53     ` Eric Chung
2026-07-28  9:45       ` Yao Zi
2026-07-29 13:49         ` Eric Chung
2026-07-29 15:32           ` Yao Zi
2026-07-30  6:25             ` Eric Chung
2026-07-30 15:20               ` Yao Zi
2026-07-31  0:31                 ` Eric Chung
2026-07-27  6:59 ` [PATCH v6 10/11] config: k1: enable ENV support for eMMC Eric Chung
2026-07-27  6:59 ` [PATCH v6 11/11] spacemit: k1: load product name from environment variable Eric Chung
2026-07-27 17:41   ` Yao Zi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260727-m4-v6-1-2f58566d48ca@riscstar.com \
    --to=eric.chung@riscstar.com \
    --cc=angelo@kernel-space.org \
    --cc=anshuld@ti.com \
    --cc=balsundar.ponnusamy@altera.com \
    --cc=bastien.curutchet@bootlin.com \
    --cc=bhimeswararao.matsa@gmail.com \
    --cc=c.stoidner@phytec.de \
    --cc=daniel@thingy.jp \
    --cc=guodong@riscstar.com \
    --cc=han.xu@nxp.com \
    --cc=jbx6244@gmail.com \
    --cc=jh80.chung@samsung.com \
    --cc=kauschluss@disroot.org \
    --cc=leo.liang@sifive.com \
    --cc=me@ziyao.cc \
    --cc=peng.fan@nxp.com \
    --cc=pericycle.cc@gmail.com \
    --cc=raymond.mao@riscstar.com \
    --cc=rick@andestech.com \
    --cc=semen.protsenko@linaro.org \
    --cc=tanmay.kathpalia@altera.com \
    --cc=tim609@andestech.com \
    --cc=trini@konsulko.com \
    --cc=u-boot-spacemit@groups.io \
    --cc=u-boot@lists.u-boot-project.org \
    --cc=yanir.levin@tandemg.com \
    --cc=ycliang@andestech.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.