From patchwork Wed Oct 16 13:21:14 2013
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Przemyslaw Marczak
X-Patchwork-Id: 283944
X-Patchwork-Delegate: marek.vasut@gmail.com
Return-Path:
X-Original-To: incoming@patchwork.ozlabs.org
Delivered-To: patchwork-incoming@bilbo.ozlabs.org
Received: from theia.denx.de (theia.denx.de [85.214.87.163])
by ozlabs.org (Postfix) with ESMTP id 0127B2C0090
for ;
Thu, 17 Oct 2013 00:22:38 +1100 (EST)
Received: from localhost (localhost [127.0.0.1])
by theia.denx.de (Postfix) with ESMTP id 204F54A0DA;
Wed, 16 Oct 2013 15:22:20 +0200 (CEST)
X-Virus-Scanned: Debian amavisd-new at theia.denx.de
Received: from theia.denx.de ([127.0.0.1])
by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id 9yd0G40m6jPE; Wed, 16 Oct 2013 15:22:19 +0200 (CEST)
Received: from theia.denx.de (localhost [127.0.0.1])
by theia.denx.de (Postfix) with ESMTP id 6A77B4A0D1;
Wed, 16 Oct 2013 15:22:00 +0200 (CEST)
Received: from localhost (localhost [127.0.0.1])
by theia.denx.de (Postfix) with ESMTP id 4CF754A018
for ; Wed, 16 Oct 2013 15:21:47 +0200 (CEST)
X-Virus-Scanned: Debian amavisd-new at theia.denx.de
Received: from theia.denx.de ([127.0.0.1])
by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id GorWrDbu65ez for ;
Wed, 16 Oct 2013 15:21:40 +0200 (CEST)
X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5
BL_NJABL=SKIP(-1.5) (only DNSBL check requested)
Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com
[210.118.77.12]) by theia.denx.de (Postfix) with ESMTP id 059E44A088
for ; Wed, 16 Oct 2013 15:21:33 +0200 (CEST)
Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245])
by mailout2.w1.samsung.com
(Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit
(built Nov
17 2011)) with ESMTP id <0MUR000CQJRPSF90@mailout2.w1.samsung.com>
for u-boot@lists.denx.de; Wed, 16 Oct 2013 14:21:26 +0100 (BST)
X-AuditID: cbfec7f5-b7ef66d00000795a-8e-525e92d61fa5
Received: from eusync3.samsung.com ( [203.254.199.213])
by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id 5B.0C.31066.6D29E525;
Wed, 16 Oct 2013 14:21:26 +0100 (BST)
Received: from AMDC1186.digital.local ([106.116.147.185])
by eusync3.samsung.com
(Oracle Communications Messaging Server 7u4-23.01(7.0.4.23.0) 64bit
(built Aug
10 2011)) with ESMTPA id <0MUR00AYTJRMLP60@eusync3.samsung.com>; Wed,
16 Oct 2013 14:21:26 +0100 (BST)
From: Przemyslaw Marczak
To: u-boot@lists.denx.de
Date: Wed, 16 Oct 2013 15:21:14 +0200
Message-id: <1381929675-26165-5-git-send-email-p.marczak@samsung.com>
X-Mailer: git-send-email 1.7.9.5
In-reply-to: <1381929675-26165-1-git-send-email-p.marczak@samsung.com>
References: <1381929675-26165-1-git-send-email-p.marczak@samsung.com>
X-Brightmail-Tracker:
H4sIAAAAAAAAA+NgFrrDJMWRmVeSWpSXmKPExsVy+t/xq7rXJsUFGfR2Cli8ebiZ0eJNWyOj
xY7LN1gs3u7tZHdg8Zg36wSLx9k7Oxg9+rasYgxgjuKySUnNySxLLdK3S+DK2N9zirXggExF
71epBsYDYl2MnBwSAiYSZ+Z0sUHYYhIX7q0Hsrk4hASWMkrMPjeVBcLpY5LoONrFDlLFJmAg
sefSGWYQW0RAQuJX/1VGEJtZIFXi0uvVrCC2sECYxMxX+1hAbBYBVYkvPcfAenkFXCXe/f8C
VM8BtE1BYs4kG5Awp4CbxKurEK1CQCVtPz6xT2DkXcDIsIpRNLU0uaA4KT3XSK84Mbe4NC9d
Lzk/dxMjJES+7mBceszqEKMAB6MSD69CbGyQEGtiWXFl7iFGCQ5mJRHeiOC4ICHelMTKqtSi
/Pii0pzU4kOMTBycwADQP7drj9g6S6Pvhe+MD6+2PHwi+/j1FfYHv3w59Oxq1c2thT+uuz3I
i7g44dzMp58TFnEsv/P3TN/bYIcoluJbS2fZhUaFHm8+subyvZaJ5U1mrN0TjPR0zdScPq99
F3X5efyJAp05Nce9/9nlX53u+PjvbcXZafsPS+wWSDT+/3y2zpT63dxCq5RYijMSDbWYi4oT
AbvJ+KfvAQAA
Cc: Marek Vasut , Przemyslaw Marczak
Subject: [U-Boot] [PATCH 4/4] usb: ums: add ums exit feature by ctrl+c or by
detach usb cable
X-BeenThere: u-boot@lists.denx.de
X-Mailman-Version: 2.1.11
Precedence: list
List-Id: U-Boot discussion
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
MIME-Version: 1.0
Sender: u-boot-bounces@lists.denx.de
Errors-To: u-boot-bounces@lists.denx.de
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.
Signed-off-by: Przemyslaw Marczak
Cc: Marek Vasut
---
common/cmd_usb_mass_storage.c | 21 +++++++++++++--------
drivers/usb/gadget/f_mass_storage.c | 24 +++++++++++++++++++++---
include/usb.h | 10 ++++++++++
3 files changed, 44 insertions(+), 11 deletions(-)
diff --git a/common/cmd_usb_mass_storage.c b/common/cmd_usb_mass_storage.c
index f6ceba7..9224d3c 100644
--- a/common/cmd_usb_mass_storage.c
+++ b/common/cmd_usb_mass_storage.c
@@ -5,6 +5,7 @@
* SPDX-License-Identifier: GPL-2.0+
*/
+#include
#include
#include
#include
@@ -47,16 +48,20 @@ int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag,
g_dnl_register("ums");
while (1) {
- /* Handle control-c and timeouts */
- if (ctrlc()) {
- error("The remote end did not respond in time.");
- goto exit;
- }
-
usb_gadget_handle_interrupts();
- /* Check if USB cable has been detached */
- if (fsg_main_thread(NULL) == EIO)
+
+ rc = fsg_main_thread(NULL);
+ if (rc) {
+ /* Check I/O error */
+ if (rc == -EIO)
+ printf("\rCheck USB cable connection\n");
+
+ /* Check CTRL+C */
+ if (rc == -EPIPE)
+ printf("\rCTRL+C - Operation aborted\n");
+
goto exit;
+ }
}
exit:
g_dnl_unregister();
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index 9560deb..a49572d 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -245,6 +245,7 @@
#include
#include
#include
+#include
#include
#include
@@ -678,6 +679,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;
@@ -2389,6 +2402,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 {
@@ -2398,12 +2412,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;
diff --git a/include/usb.h b/include/usb.h
index 17fb68c..8c1789f 100644
--- a/include/usb.h
+++ b/include/usb.h
@@ -197,6 +197,16 @@ int board_usb_init(int index, enum board_usb_init_type init);
*/
int board_usb_cleanup(int index, enum board_usb_init_type init);
+/*
+ * If CONFIG_USB_CABLE_CHECK is set then this function
+ * should be defined in board file.
+ *
+ * @return 1 if cable is connected and 0 otherwise.
+ */
+#ifdef CONFIG_USB_CABLE_CHECK
+int usb_cable_connected(void);
+#endif
+
#ifdef CONFIG_USB_STORAGE
#define USB_MAX_STOR_DEV 5