summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSherry Sun <sherry.sun@nxp.com>2019-08-02 13:58:03 -0400
committerYe Li <ye.li@nxp.com>2020-04-26 23:36:23 -0700
commit3bc60e5c03c0474261f9e0666a9814c7ea592c5c (patch)
treeff4479c41bcc0a2609a86ac863cd7d398cea6904
parent8e96b7197a91142c9f70d8fed7b994b2e3d8eb1a (diff)
MLK-22357-2 sdp/fastboot: Add board_usb_gadget_port_auto() to autodetect the connected usb port
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> (cherry picked from commit 2b6fd3da6fffae0732e8e91ef5c1f870ea393ca9)
-rw-r--r--arch/arm/mach-imx/imx8/cpu.c49
-rw-r--r--cmd/fastboot.c23
-rw-r--r--common/spl/spl_sdp.c7
-rw-r--r--drivers/usb/gadget/g_dnl.c5
-rw-r--r--include/configs/imx_env.h8
-rw-r--r--include/g_dnl.h1
6 files changed, 84 insertions, 9 deletions
diff --git a/arch/arm/mach-imx/imx8/cpu.c b/arch/arm/mach-imx/imx8/cpu.c
index 6a5fad9207c..1739fd190bd 100644
--- a/arch/arm/mach-imx/imx8/cpu.c
+++ b/arch/arm/mach-imx/imx8/cpu.c
@@ -13,6 +13,7 @@
#include <dm/lists.h>
#include <dm/uclass.h>
#include <errno.h>
+#include <asm/arch/clock.h>
#include <power-domain.h>
#include <dm/device.h>
#include <dm/uclass-internal.h>
@@ -1066,3 +1067,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
diff --git a/cmd/fastboot.c b/cmd/fastboot.c
index ddb5ea624a1..6210d263288 100644
--- a/cmd/fastboot.c
+++ b/cmd/fastboot.c
@@ -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) {
diff --git a/common/spl/spl_sdp.c b/common/spl/spl_sdp.c
index 644dfa8cc3e..1bf63ce50cd 100644
--- a/common/spl/spl_sdp.c
+++ b/common/spl/spl_sdp.c
@@ -14,7 +14,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);
diff --git a/drivers/usb/gadget/g_dnl.c b/drivers/usb/gadget/g_dnl.c
index f7d25d8fafd..57cdba4201d 100644
--- a/drivers/usb/gadget/g_dnl.c
+++ b/drivers/usb/gadget/g_dnl.c
@@ -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;
+}
diff --git a/include/configs/imx_env.h b/include/configs/imx_env.h
index f03f4f2f59b..234af33e55e 100644
--- a/include/configs/imx_env.h
+++ b/include/configs/imx_env.h
@@ -12,6 +12,12 @@
#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
diff --git a/include/g_dnl.h b/include/g_dnl.h
index 6d461c73d3d..2425d19ed2e 100644
--- a/include/g_dnl.h
+++ b/include/g_dnl.h
@@ -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_ */