Commit 351e9b206934c2d4a6a0acd1547caf077e4e675c
Committed by
Marek Vasut
1 parent
4b19ed6c76
Exists in
master
and in
50 other branches
usb: ums: add ums exit feature by ctrl+c or by detach usb cable
This patch allows exiting from UMS mode to u-boot prompt by detaching usb cable or by pressing ctrl+c. Add new config: CONFIG_USB_CABLE_CHECK. If defined then board file should provide function: usb_cable_connected() (include/usb.h) that return 1 if cable is connected and 0 otherwise. Changes v2: - add a note to the README Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com> Cc: Marek Vasut <marex@denx.de>
Showing 4 changed files with 51 additions and 11 deletions Side-by-side Diff
README
... | ... | @@ -1367,6 +1367,13 @@ |
1367 | 1367 | for your device |
1368 | 1368 | - CONFIG_USBD_PRODUCTID 0xFFFF |
1369 | 1369 | |
1370 | + Some USB device drivers may need to check USB cable attachment. | |
1371 | + In this case you can enable following config in BoardName.h: | |
1372 | + CONFIG_USB_CABLE_CHECK | |
1373 | + This enables function definition: | |
1374 | + - usb_cable_connected() in include/usb.h | |
1375 | + Implementation of this function is board-specific. | |
1376 | + | |
1370 | 1377 | - ULPI Layer Support: |
1371 | 1378 | The ULPI (UTMI Low Pin (count) Interface) PHYs are supported via |
1372 | 1379 | the generic ULPI layer. The generic layer accesses the ULPI PHY |
common/cmd_usb_mass_storage.c
... | ... | @@ -5,6 +5,7 @@ |
5 | 5 | * SPDX-License-Identifier: GPL-2.0+ |
6 | 6 | */ |
7 | 7 | |
8 | +#include <errno.h> | |
8 | 9 | #include <common.h> |
9 | 10 | #include <command.h> |
10 | 11 | #include <g_dnl.h> |
11 | 12 | |
12 | 13 | |
... | ... | @@ -42,16 +43,20 @@ |
42 | 43 | g_dnl_register("ums"); |
43 | 44 | |
44 | 45 | while (1) { |
45 | - /* Handle control-c and timeouts */ | |
46 | - if (ctrlc()) { | |
47 | - error("The remote end did not respond in time."); | |
48 | - goto exit; | |
49 | - } | |
50 | - | |
51 | 46 | usb_gadget_handle_interrupts(); |
52 | - /* Check if USB cable has been detached */ | |
53 | - if (fsg_main_thread(NULL) == EIO) | |
47 | + | |
48 | + rc = fsg_main_thread(NULL); | |
49 | + if (rc) { | |
50 | + /* Check I/O error */ | |
51 | + if (rc == -EIO) | |
52 | + printf("\rCheck USB cable connection\n"); | |
53 | + | |
54 | + /* Check CTRL+C */ | |
55 | + if (rc == -EPIPE) | |
56 | + printf("\rCTRL+C - Operation aborted\n"); | |
57 | + | |
54 | 58 | goto exit; |
59 | + } | |
55 | 60 | } |
56 | 61 | exit: |
57 | 62 | g_dnl_unregister(); |
drivers/usb/gadget/f_mass_storage.c
... | ... | @@ -243,6 +243,7 @@ |
243 | 243 | #include <config.h> |
244 | 244 | #include <malloc.h> |
245 | 245 | #include <common.h> |
246 | +#include <usb.h> | |
246 | 247 | |
247 | 248 | #include <linux/err.h> |
248 | 249 | #include <linux/usb/ch9.h> |
... | ... | @@ -675,6 +676,18 @@ |
675 | 676 | k++; |
676 | 677 | } |
677 | 678 | |
679 | + if (k == 10) { | |
680 | + /* Handle CTRL+C */ | |
681 | + if (ctrlc()) | |
682 | + return -EPIPE; | |
683 | +#ifdef CONFIG_USB_CABLE_CHECK | |
684 | + /* Check cable connection */ | |
685 | + if (!usb_cable_connected()) | |
686 | + return -EIO; | |
687 | +#endif | |
688 | + k = 0; | |
689 | + } | |
690 | + | |
678 | 691 | usb_gadget_handle_interrupts(); |
679 | 692 | } |
680 | 693 | common->thread_wakeup_needed = 0; |
... | ... | @@ -2387,6 +2400,7 @@ |
2387 | 2400 | |
2388 | 2401 | int fsg_main_thread(void *common_) |
2389 | 2402 | { |
2403 | + int ret; | |
2390 | 2404 | struct fsg_common *common = the_fsg_common; |
2391 | 2405 | /* The main loop */ |
2392 | 2406 | do { |
2393 | 2407 | |
... | ... | @@ -2396,12 +2410,16 @@ |
2396 | 2410 | } |
2397 | 2411 | |
2398 | 2412 | if (!common->running) { |
2399 | - sleep_thread(common); | |
2413 | + ret = sleep_thread(common); | |
2414 | + if (ret) | |
2415 | + return ret; | |
2416 | + | |
2400 | 2417 | continue; |
2401 | 2418 | } |
2402 | 2419 | |
2403 | - if (get_next_command(common)) | |
2404 | - continue; | |
2420 | + ret = get_next_command(common); | |
2421 | + if (ret) | |
2422 | + return ret; | |
2405 | 2423 | |
2406 | 2424 | if (!exception_in_progress(common)) |
2407 | 2425 | common->state = FSG_STATE_DATA_PHASE; |
include/usb.h
... | ... | @@ -197,6 +197,16 @@ |
197 | 197 | */ |
198 | 198 | int board_usb_cleanup(int index, enum usb_init_type init); |
199 | 199 | |
200 | +/* | |
201 | + * If CONFIG_USB_CABLE_CHECK is set then this function | |
202 | + * should be defined in board file. | |
203 | + * | |
204 | + * @return 1 if cable is connected and 0 otherwise. | |
205 | + */ | |
206 | +#ifdef CONFIG_USB_CABLE_CHECK | |
207 | +int usb_cable_connected(void); | |
208 | +#endif | |
209 | + | |
200 | 210 | #ifdef CONFIG_USB_STORAGE |
201 | 211 | |
202 | 212 | #define USB_MAX_STOR_DEV 5 |