Commit 9517d599751612e55001e8717c1762cfd381df92
Committed by
Ye Li
1 parent
0a3c6ed9b3
Exists in
emb_lf_v2022.04
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) (cherry picked from commit 7c8e0606ea4aaeceae1f1d1e17db1503ac9f841e) (cherry picked from commit f680079db70dfb53a96dbafe0b3f6bf8f3f6ca42) (cherry picked from commit 6767d87d4db3947b62164a44f35280ea7daa8e0c)
Showing 6 changed files with 84 additions and 10 deletions Side-by-side Diff
arch/arm/mach-imx/imx8/cpu.c
... | ... | @@ -17,7 +17,7 @@ |
17 | 17 | #include <dm/lists.h> |
18 | 18 | #include <dm/uclass.h> |
19 | 19 | #include <errno.h> |
20 | -#include <spl.h> | |
20 | +#include <asm/arch/clock.h> | |
21 | 21 | #include <thermal.h> |
22 | 22 | #include <asm/arch/sci/sci.h> |
23 | 23 | #include <power-domain.h> |
... | ... | @@ -1027,4 +1027,52 @@ |
1027 | 1027 | |
1028 | 1028 | return -ENODEV; |
1029 | 1029 | } |
1030 | + | |
1031 | +#ifdef CONFIG_USB_PORT_AUTO | |
1032 | +int board_usb_gadget_port_auto(void) | |
1033 | +{ | |
1034 | + int ret; | |
1035 | + u32 usb2_data; | |
1036 | + struct power_domain pd; | |
1037 | + struct power_domain phy_pd; | |
1038 | + | |
1039 | + if (!power_domain_lookup_name("conn_usb0", &pd)) { | |
1040 | + ret = power_domain_on(&pd); | |
1041 | + if (ret) { | |
1042 | + printf("conn_usb0 Power up failed!\n"); | |
1043 | + return ret; | |
1044 | + } | |
1045 | + | |
1046 | + if (!power_domain_lookup_name("conn_usb0_phy", &phy_pd)) { | |
1047 | + ret = power_domain_on(&phy_pd); | |
1048 | + if (ret) { | |
1049 | + printf("conn_usb0_phy Power up failed!\n"); | |
1050 | + return ret; | |
1051 | + } | |
1052 | + } else { | |
1053 | + return -1; | |
1054 | + } | |
1055 | + | |
1056 | + enable_usboh3_clk(1); | |
1057 | + usb2_data = readl(USB_BASE_ADDR + 0x154); | |
1058 | + | |
1059 | + ret = power_domain_off(&phy_pd); | |
1060 | + if (ret) { | |
1061 | + printf("conn_usb0_phy Power off failed!\n"); | |
1062 | + return ret; | |
1063 | + } | |
1064 | + ret = power_domain_off(&pd); | |
1065 | + if (ret) { | |
1066 | + printf("conn_usb0 Power off failed!\n"); | |
1067 | + return ret; | |
1068 | + } | |
1069 | + | |
1070 | + if (!usb2_data) | |
1071 | + return 1; | |
1072 | + else | |
1073 | + return 0; | |
1074 | + } | |
1075 | + return -1; | |
1076 | +} | |
1077 | +#endif |
cmd/fastboot.c
... | ... | @@ -42,19 +42,28 @@ |
42 | 42 | char *usb_controller; |
43 | 43 | char *endp; |
44 | 44 | int ret; |
45 | + int index; | |
45 | 46 | |
46 | 47 | if (argc < 2) |
47 | 48 | return CMD_RET_USAGE; |
48 | 49 | |
49 | - usb_controller = argv[1]; | |
50 | - controller_index = simple_strtoul(usb_controller, &endp, 0); | |
51 | - if (*endp != '\0') { | |
52 | - pr_err("Error: Wrong USB controller index format\n"); | |
53 | - return CMD_RET_FAILURE; | |
54 | - } | |
50 | + if (!strcmp(argv[1], "auto")) { | |
51 | + index = board_usb_gadget_port_auto(); | |
52 | + if (index >= 0) | |
53 | + controller_index = index; | |
54 | + else | |
55 | + return CMD_RET_USAGE; | |
56 | + } else { | |
57 | + usb_controller = argv[1]; | |
58 | + controller_index = simple_strtoul(usb_controller, &endp, 0); | |
59 | + if (*endp != '\0') { | |
60 | + pr_err("Error: Wrong USB controller index format\n"); | |
61 | + return CMD_RET_FAILURE; | |
62 | + } | |
55 | 63 | #ifdef CONFIG_FASTBOOT_USB_DEV |
56 | - controller_index = CONFIG_FASTBOOT_USB_DEV; | |
64 | + controller_index = CONFIG_FASTBOOT_USB_DEV; | |
57 | 65 | #endif |
66 | + } | |
58 | 67 | |
59 | 68 | ret = usb_gadget_initialize(controller_index); |
60 | 69 | if (ret) { |
common/spl/spl_sdp.c
... | ... | @@ -15,7 +15,12 @@ |
15 | 15 | struct spl_boot_device *bootdev) |
16 | 16 | { |
17 | 17 | int ret; |
18 | - const int controller_index = CONFIG_SPL_SDP_USB_DEV; | |
18 | + int index; | |
19 | + int controller_index = CONFIG_SPL_SDP_USB_DEV; | |
20 | + | |
21 | + index = board_usb_gadget_port_auto(); | |
22 | + if (index >= 0) | |
23 | + controller_index = index; | |
19 | 24 | |
20 | 25 | usb_gadget_initialize(controller_index); |
21 | 26 |
drivers/usb/gadget/g_dnl.c
include/configs/imx_env.h
... | ... | @@ -12,6 +12,12 @@ |
12 | 12 | #define MFG_BOOT_CMD "bootz " |
13 | 13 | #endif |
14 | 14 | |
15 | +#ifdef CONFIG_USB_PORT_AUTO | |
16 | + #define FASTBOOT_CMD "echo \"Run fastboot ...\"; fastboot auto; " | |
17 | +#else | |
18 | + #define FASTBOOT_CMD "echo \"Run fastboot ...\"; fastboot 0; " | |
19 | +#endif | |
20 | + | |
15 | 21 | #define CONFIG_MFG_ENV_SETTINGS_DEFAULT \ |
16 | 22 | "mfgtool_args=setenv bootargs console=${console},${baudrate} " \ |
17 | 23 | "rdinit=/linuxrc " \ |
... | ... | @@ -26,7 +32,7 @@ |
26 | 32 | MFG_BOOT_CMD "${loadaddr} ${initrd_addr} ${fdt_addr}; " \ |
27 | 33 | "fi; " \ |
28 | 34 | "else " \ |
29 | - "echo \"Run fastboot ...\"; fastboot 0; " \ | |
35 | + FASTBOOT_CMD \ | |
30 | 36 | "fi;\0" \ |
31 | 37 | |
32 | 38 | #endif |
include/g_dnl.h