From 351e9b206934c2d4a6a0acd1547caf077e4e675c Mon Sep 17 00:00:00 2001 From: Przemyslaw Marczak Date: Wed, 23 Oct 2013 14:30:46 +0200 Subject: 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 Cc: Marek Vasut --- drivers/usb/gadget/f_mass_storage.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'drivers/usb') diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index be6b418..b1fe8bd 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c @@ -243,6 +243,7 @@ #include #include #include +#include #include #include @@ -675,6 +676,18 @@ static int sleep_thread(struct fsg_common *common) k++; } + if (k == 10) { + /* Handle CTRL+C */ + if (ctrlc()) + return -EPIPE; +#ifdef CONFIG_USB_CABLE_CHECK + /* Check cable connection */ + if (!usb_cable_connected()) + return -EIO; +#endif + k = 0; + } + usb_gadget_handle_interrupts(); } common->thread_wakeup_needed = 0; @@ -2387,6 +2400,7 @@ static void handle_exception(struct fsg_common *common) int fsg_main_thread(void *common_) { + int ret; struct fsg_common *common = the_fsg_common; /* The main loop */ do { @@ -2396,12 +2410,16 @@ int fsg_main_thread(void *common_) } if (!common->running) { - sleep_thread(common); + ret = sleep_thread(common); + if (ret) + return ret; + continue; } - if (get_next_command(common)) - continue; + ret = get_next_command(common); + if (ret) + return ret; if (!exception_in_progress(common)) common->state = FSG_STATE_DATA_PHASE; -- cgit v1.1