MLK-22357-2 sdp/fastboot: Add board_usb_gadget_port_auto() to autodetect the connecte...
authorSherry Sun <sherry.sun@nxp.com>
Fri, 2 Aug 2019 17:58:03 +0000 (13:58 -0400)
committerSherry Sun <sherry.sun@nxp.com>
Thu, 8 Aug 2019 17:12:57 +0000 (13:12 -0400)
On imx8 platform, the usb2 and usb3 ports are both supported. Which
means we can use usb2(ci_udc_otg) and usb3(cdns3_generic_peripheral)
gadget driver to run sdp/fastboot/ums at the same time.

For sdp and the fastboot that runs automatically when uboot starts,
board_usb_gadget_port_auto() is added to autodetect usb port, this
means that we don't have to specify which USB port should be used to
download in code, now we can just connect either usb port then it
will download automatically.

Signed-off-by: Sherry Sun <sherry.sun@nxp.com>
arch/arm/mach-imx/imx8/cpu.c
cmd/fastboot.c
common/spl/spl_sdp.c
drivers/usb/gadget/g_dnl.c
include/configs/imx_env.h
include/g_dnl.h

index 14d5019..3ee5f9e 100644 (file)
@@ -12,6 +12,7 @@
 #include <dm/uclass.h>
 #include <errno.h>
 #include <asm/arch/sci/sci.h>
+#include <asm/arch/clock.h>
 #include <power-domain.h>
 #include <dm/device.h>
 #include <dm/uclass-internal.h>
@@ -1921,3 +1922,51 @@ void board_boot_order(u32 *spl_boot_list)
                        spl_boot_list[0] = BOOT_DEVICE_NOR;
        }
 }
+
+#ifdef CONFIG_USB_PORT_AUTO
+int board_usb_gadget_port_auto(void)
+{
+       int ret;
+       u32 usb2_data;
+       struct power_domain pd;
+       struct power_domain phy_pd;
+
+       if (!power_domain_lookup_name("conn_usb0", &pd)) {
+               ret = power_domain_on(&pd);
+               if (ret) {
+                       printf("conn_usb0 Power up failed!\n");
+                       return ret;
+               }
+
+               if (!power_domain_lookup_name("conn_usb0_phy", &phy_pd)) {
+                       ret = power_domain_on(&phy_pd);
+                       if (ret) {
+                               printf("conn_usb0_phy Power up failed!\n");
+                               return ret;
+                       }
+               } else {
+                       return -1;
+               }
+
+               enable_usboh3_clk(1);
+               usb2_data = readl(USB_BASE_ADDR + 0x154);
+
+               ret = power_domain_off(&phy_pd);
+               if (ret) {
+                       printf("conn_usb0_phy Power off failed!\n");
+                       return ret;
+               }
+               ret = power_domain_off(&pd);
+               if (ret) {
+                       printf("conn_usb0 Power off failed!\n");
+                       return ret;
+               }
+
+               if (!usb2_data)
+                       return 1;
+               else
+                       return 0;
+       }
+       return -1;
+}
+#endif
index ddb5ea6..6210d26 100644 (file)
@@ -41,19 +41,28 @@ static int do_fastboot_usb(int argc, char *const argv[],
        char *usb_controller;
        char *endp;
        int ret;
+       int index;
 
        if (argc < 2)
                return CMD_RET_USAGE;
 
-       usb_controller = argv[1];
-       controller_index = simple_strtoul(usb_controller, &endp, 0);
-       if (*endp != '\0') {
-               pr_err("Error: Wrong USB controller index format\n");
-               return CMD_RET_FAILURE;
-       }
+       if (!strcmp(argv[1], "auto")) {
+               index = board_usb_gadget_port_auto();
+               if (index >= 0)
+                       controller_index = index;
+               else
+                       return CMD_RET_USAGE;
+       } else {
+               usb_controller = argv[1];
+               controller_index = simple_strtoul(usb_controller, &endp, 0);
+               if (*endp != '\0') {
+                       pr_err("Error: Wrong USB controller index format\n");
+                       return CMD_RET_FAILURE;
+               }
 #ifdef CONFIG_FASTBOOT_USB_DEV
-       controller_index = CONFIG_FASTBOOT_USB_DEV;
+               controller_index = CONFIG_FASTBOOT_USB_DEV;
 #endif
+       }
 
        ret = usb_gadget_initialize(controller_index);
        if (ret) {
index debfcfb..b0b2619 100644 (file)
@@ -19,7 +19,12 @@ static int spl_sdp_load_image(struct spl_image_info *spl_image,
                              struct spl_boot_device *bootdev)
 {
        int ret;
-       const int controller_index = CONFIG_SPL_SDP_USB_DEV;
+       int index;
+       int controller_index = CONFIG_SPL_SDP_USB_DEV;
+
+       index = board_usb_gadget_port_auto();
+       if (index >= 0)
+               controller_index = index;
 
        usb_gadget_initialize(controller_index);
 
index f7d25d8..57cdba4 100644 (file)
@@ -307,3 +307,8 @@ void g_dnl_unregister(void)
 {
        usb_composite_unregister(&g_dnl_driver);
 }
+
+int __weak board_usb_gadget_port_auto(void)
+{
+       return -1;
+}
index f03f4f2..234af33 100644 (file)
     #define MFG_BOOT_CMD "bootz "
 #endif
 
+#ifdef CONFIG_USB_PORT_AUTO
+    #define FASTBOOT_CMD "echo \"Run fastboot ...\"; fastboot auto; "
+#else
+    #define FASTBOOT_CMD "echo \"Run fastboot ...\"; fastboot 0; "
+#endif
+
 #define CONFIG_MFG_ENV_SETTINGS_DEFAULT \
        "mfgtool_args=setenv bootargs console=${console},${baudrate} " \
                "rdinit=/linuxrc " \
@@ -26,7 +32,7 @@
                 MFG_BOOT_CMD "${loadaddr} ${initrd_addr} ${fdt_addr}; " \
             "fi; " \
         "else " \
-            "echo \"Run fastboot ...\"; fastboot 0; "  \
+               FASTBOOT_CMD  \
         "fi;\0" \
 
 #endif
index 6d461c7..2425d19 100644 (file)
@@ -43,5 +43,6 @@ bool g_dnl_detach(void);
 void g_dnl_trigger_detach(void);
 void g_dnl_clear_detach(void);
 int run_usb_dnl_gadget(int usbctrl_index, char *usb_dnl_gadget);
+int board_usb_gadget_port_auto(void);
 
 #endif /* __G_DOWNLOAD_H_ */