board: ti: am64x: Add support for fixing dr_mode while booting from USB
authorAswath Govindraju <a-govindraju@ti.com>
Wed, 4 Aug 2021 13:12:44 +0000 (18:42 +0530)
committerTom Rini <trini@konsulko.com>
Sat, 11 Sep 2021 00:10:20 +0000 (20:10 -0400)
Fix the dr_mode in the U-Boot device tree blob, by reading the mode field
from the USB Boot Configuration fields. The dr_mode will only be fixed when
booting from USB.

Signed-off-by: Aswath Govindraju <a-govindraju@ti.com>
board/ti/am64x/evm.c

index 21c58c7..1a9f69c 100644 (file)
@@ -10,6 +10,7 @@
 #include <common.h>
 #include <asm/io.h>
 #include <spl.h>
 #include <common.h>
 #include <asm/io.h>
 #include <spl.h>
+#include <fdt_support.h>
 #include <asm/arch/hardware.h>
 #include <asm/arch/sys_proto.h>
 #include <env.h>
 #include <asm/arch/hardware.h>
 #include <asm/arch/sys_proto.h>
 #include <env.h>
@@ -60,6 +61,37 @@ int board_fit_config_name_match(const char *name)
 }
 #endif
 
 }
 #endif
 
+#if defined(CONFIG_SPL_BUILD) && CONFIG_IS_ENABLED(USB_STORAGE)
+static int fixup_usb_boot(const void *fdt_blob)
+{
+       int ret = 0;
+
+       switch (spl_boot_device()) {
+       case BOOT_DEVICE_USB:
+               /*
+                * If the boot mode is host, fixup the dr_mode to host
+                * before cdns3 bind takes place
+                */
+               ret = fdt_find_and_setprop((void *)fdt_blob,
+                                          "/bus@f4000/cdns-usb@f900000/usb@f400000",
+                                          "dr_mode", "host", 5, 0);
+               if (ret)
+                       printf("%s: fdt_find_and_setprop() failed:%d\n",
+                              __func__, ret);
+               fallthrough;
+       default:
+               break;
+       }
+
+       return ret;
+}
+
+void spl_perform_fixups(struct spl_image_info *spl_image)
+{
+       fixup_usb_boot(spl_image->fdt_addr);
+}
+#endif
+
 #ifdef CONFIG_TI_I2C_BOARD_DETECT
 int do_board_detect(void)
 {
 #ifdef CONFIG_TI_I2C_BOARD_DETECT
 int do_board_detect(void)
 {