diff mbox series

[v3,2/4] mx6cuboxi: customize board_boot_order to access eMMC

Message ID 20200519182424.19959-3-walter.lozano@collabora.com
State Accepted
Commit 6c3fbf3e456c49c2f43c0c286106a0d4b099b67b
Delegated to: Stefano Babic
Headers show
Series mx6cuboxi: enable support for OF_CONTROL and DM in SPL | expand

Commit Message

Walter Lozano May 19, 2020, 6:24 p.m. UTC
In SPL legacy code only one MMC device is created, based on BOOT_CFG
register, which can be either SD or eMMC. In this context
board_boot_order return always MMC1 when configure to boot from
SD/eMMC. After switching to DM both SD and eMMC devices are created
based on the information available on DT, but as board_boot_order
only returns MMC1 is not possible to boot from eMMC.

This patch customizes board_boot_order taking into account BOOT_CFG
register to point to correct MMC1 / MMC2 device. Additionally, handle
IO mux for the desired boot device.

Signed-off-by: Walter Lozano <walter.lozano@collabora.com>
---
 board/solidrun/mx6cuboxi/mx6cuboxi.c | 48 ++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

Comments

Stefano Babic June 23, 2020, 7:51 a.m. UTC | #1
> In SPL legacy code only one MMC device is created, based on BOOT_CFG
> register, which can be either SD or eMMC. In this context
> board_boot_order return always MMC1 when configure to boot from
> SD/eMMC. After switching to DM both SD and eMMC devices are created
> based on the information available on DT, but as board_boot_order
> only returns MMC1 is not possible to boot from eMMC.
> This patch customizes board_boot_order taking into account BOOT_CFG
> register to point to correct MMC1 / MMC2 device. Additionally, handle
> IO mux for the desired boot device.
> Signed-off-by: Walter Lozano <walter.lozano@collabora.com>
Applied to u-boot-imx, master, thanks !

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/board/solidrun/mx6cuboxi/mx6cuboxi.c b/board/solidrun/mx6cuboxi/mx6cuboxi.c
index 6a96f9ecdb..cb06b6c46e 100644
--- a/board/solidrun/mx6cuboxi/mx6cuboxi.c
+++ b/board/solidrun/mx6cuboxi/mx6cuboxi.c
@@ -624,6 +624,54 @@  int board_fit_config_name_match(const char *name)
 	return strcmp(name, tmp_name);
 }
 
+void board_boot_order(u32 *spl_boot_list)
+{
+	struct src *psrc = (struct src *)SRC_BASE_ADDR;
+	unsigned int reg = readl(&psrc->sbmr1) >> 11;
+	u32 boot_mode = imx6_src_get_boot_mode() & IMX6_BMODE_MASK;
+	unsigned int bmode = readl(&src_base->sbmr2);
+
+	/* If bmode is serial or USB phy is active, return serial */
+	if (((bmode >> 24) & 0x03) == 0x01 || is_usbotg_phy_active()) {
+		spl_boot_list[0] = BOOT_DEVICE_BOARD;
+		return;
+	}
+
+	switch (boot_mode >> IMX6_BMODE_SHIFT) {
+	case IMX6_BMODE_SD:
+	case IMX6_BMODE_ESD:
+	case IMX6_BMODE_MMC:
+	case IMX6_BMODE_EMMC:
+		/*
+		 * Upon reading BOOT_CFG register the following map is done:
+		 * Bit 11 and 12 of BOOT_CFG register can determine the current
+		 * mmc port
+		 * 0x1                  SD2
+		 * 0x2                  SD3
+		 */
+
+		reg &= 0x3; /* Only care about bottom 2 bits */
+		switch (reg) {
+		case 1:
+			SETUP_IOMUX_PADS(usdhc2_pads);
+			spl_boot_list[0] = BOOT_DEVICE_MMC1;
+			break;
+		case 2:
+			SETUP_IOMUX_PADS(usdhc3_pads);
+			spl_boot_list[0] = BOOT_DEVICE_MMC2;
+			break;
+		}
+		break;
+	default:
+		/* By default use USB downloader */
+		spl_boot_list[0] = BOOT_DEVICE_BOARD;
+		break;
+	}
+
+	/* As a last resort, use serial downloader */
+	spl_boot_list[1] = BOOT_DEVICE_BOARD;
+}
+
 #ifdef CONFIG_SPL_BUILD
 #include <asm/arch/mx6-ddr.h>
 static const struct mx6dq_iomux_ddr_regs mx6q_ddr_ioregs = {