Commit 3603e31db54ddba820b7a7b9c7659e272f8c65de

Authored by Przemyslaw Marczak
Committed by Marek Vasut
1 parent 7da7651251

usb: ums: wait for usb cable connection before enter ums mode

Before this change ums mode can not be entered when device
was using the same usb port for usb/uart communication.
Switching USB cable from UART to USB always causes ums exit.

Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>

Showing 2 changed files with 27 additions and 0 deletions Side-by-side Diff

common/cmd_usb_mass_storage.c
... ... @@ -42,6 +42,30 @@
42 42  
43 43 g_dnl_register("ums");
44 44  
  45 + /* Timeout unit: seconds */
  46 + int cable_ready_timeout = UMS_CABLE_READY_TIMEOUT;
  47 +
  48 + if (!usb_cable_connected()) {
  49 + puts("Please connect USB cable.\n");
  50 +
  51 + while (!usb_cable_connected()) {
  52 + if (ctrlc()) {
  53 + puts("\rCTRL+C - Operation aborted.\n");
  54 + goto exit;
  55 + }
  56 + if (!cable_ready_timeout) {
  57 + puts("\rUSB cable not detected.\n" \
  58 + "Command exit.\n");
  59 + goto exit;
  60 + }
  61 +
  62 + printf("\rAuto exit in: %.2d s.", cable_ready_timeout);
  63 + mdelay(1000);
  64 + cable_ready_timeout--;
  65 + }
  66 + puts("\r\n");
  67 + }
  68 +
45 69 while (1) {
46 70 usb_gadget_handle_interrupts();
47 71  
include/usb_mass_storage.h
... ... @@ -20,6 +20,9 @@
20 20 #define UMS_NUM_SECTORS 0
21 21 #endif
22 22  
  23 +/* Wait at maximum 60 seconds for cable connection */
  24 +#define UMS_CABLE_READY_TIMEOUT 60
  25 +
23 26 struct ums {
24 27 int (*read_sector)(struct ums *ums_dev,
25 28 ulong start, lbaint_t blkcnt, void *buf);