[PATCH 06/13] arm: mach-k3: am6_init: Do USB fixups to facilitate host and device boot modes

Faiz Abbas faiz_abbas at ti.com
Thu Jul 2 10:02:26 CEST 2020


U-boot only supports either USB host or device mode for a node at a time in dts
To support both host and dfu bootmodes, set "peripheral" as the default dr_mode
but fixup property to "host" if host bootmode is detected

This needs to happen before the dwc3 generic layer binds the usb device to a host
or device driver. Therefore, open code the configurations in spl_early_init()
and add the fixup after the fdtdec_setup() and before the dm_init_scan()

Also use the same fixup function to set the USB-PCIe Serdes mux to PCIe in both the
host and device cases. This is required for accessing the interface at USB 2.0 speeds

Signed-off-by: Faiz Abbas <faiz_abbas at ti.com>
---
 arch/arm/mach-k3/am6_init.c | 68 +++++++++++++++++++++++++++++++++++--
 1 file changed, 66 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-k3/am6_init.c b/arch/arm/mach-k3/am6_init.c
index 42d13a39f8..b65860fef3 100644
--- a/arch/arm/mach-k3/am6_init.c
+++ b/arch/arm/mach-k3/am6_init.c
@@ -7,6 +7,7 @@
  */
 
 #include <common.h>
+#include <fdt_support.h>
 #include <init.h>
 #include <asm/io.h>
 #include <spl.h>
@@ -17,11 +18,15 @@
 #include <dm.h>
 #include <dm/uclass-internal.h>
 #include <dm/pinctrl.h>
+#include <dm/root.h>
+#include <linux/compiler.h>
 #include <linux/soc/ti/ti_sci_protocol.h>
 #include <log.h>
 #include <mmc.h>
 #include <stdlib.h>
 
+DECLARE_GLOBAL_DATA_PTR;
+
 #ifdef CONFIG_SPL_BUILD
 #ifdef CONFIG_K3_LOAD_SYSFW
 #ifdef CONFIG_TI_SECURE_DEVICE
@@ -119,7 +124,67 @@ void k3_mmc_restart_clock(void)
 void k3_mmc_stop_clock(void) {}
 void k3_mmc_restart_clock(void) {}
 #endif
+#if CONFIG_IS_ENABLED(DFU) || CONFIG_IS_ENABLED(USB_STORAGE)
+#define CTRLMMR_SERDES0_CTRL	0x00104080
+#define PCIE_LANE0		0x1
+void fixup_usb_boot(void)
+{
+	int ret;
 
+	switch (spl_boot_device()) {
+	case BOOT_DEVICE_USB:
+		/*
+		 * If bootmode is Host bootmode, fixup the dr_mode to host
+		 * before the dwc3 bind takes place
+		 */
+		ret = fdt_find_and_setprop((void *)gd->fdt_blob,
+				"/interconnect at 100000/dwc3 at 4000000/usb at 10000",
+				"dr_mode", "host", 11, 0);
+		if (ret)
+			printf("%s: fdt_find_and_setprop() failed:%d\n", __func__,
+			       ret);
+		/* fallthrough */
+	case BOOT_DEVICE_DFU:
+		/*
+		 * The serdes mux between PCIe and USB3 needs to be set to PCIe for
+		 * accessing the interface at USB 2.0
+		 */
+		writel(PCIE_LANE0, CTRLMMR_SERDES0_CTRL);
+	default:
+		;
+	}
+}
+#endif
+int am6_spl_early_init(void)
+{
+	int ret;
+#if CONFIG_VAL(SYS_MALLOC_F_LEN)
+#ifdef CONFIG_MALLOC_F_ADDR
+	gd->malloc_base = CONFIG_MALLOC_F_ADDR;
+#endif
+	gd->malloc_limit = CONFIG_VAL(SYS_MALLOC_F_LEN);
+	gd->malloc_ptr = 0;
+#endif
+	ret = fdtdec_setup();
+	if (ret) {
+		printf("fdtdec_setup() returned error %d\n", ret);
+		return ret;
+	}
+
+#if CONFIG_IS_ENABLED(DFU) || CONFIG_IS_ENABLED(USB_STORAGE)
+	fixup_usb_boot();
+#endif
+	/* With CONFIG_SPL_OF_PLATDATA, bring in all devices */
+	ret = dm_init_and_scan(!CONFIG_IS_ENABLED(OF_PLATDATA));
+	if (ret) {
+		printf("dm_init_and_scan() returned error %d\n", ret);
+		return ret;
+	}
+
+	gd->flags |= GD_FLG_SPL_EARLY_INIT;
+
+	return 0;
+}
 void board_init_f(ulong dummy)
 {
 #if defined(CONFIG_K3_LOAD_SYSFW) || defined(CONFIG_K3_AM654_DDRSS)
@@ -141,9 +206,8 @@ void board_init_f(ulong dummy)
 	disable_linefill_optimization();
 	setup_k3_mpu_regions();
 #endif
-
 	/* Init DM early in-order to invoke system controller */
-	spl_early_init();
+	am6_spl_early_init();
 
 #ifdef CONFIG_K3_EARLY_CONS
 	/*
-- 
2.17.1



More information about the U-Boot mailing list