Merge branch 'master' of git://www.denx.de/git/u-boot-imx
[oweals/u-boot.git] / common / cmd_usb.c
index b2aa44c2a724eab626800598f17696261b6f2f57..27813f0d7af680fffa67b0dba509da1ba020e43a 100644 (file)
@@ -430,10 +430,10 @@ static int do_usbboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 }
 #endif /* CONFIG_USB_STORAGE */
 
-static int do_usb_stop_keyboard(void)
+static int do_usb_stop_keyboard(int force)
 {
 #ifdef CONFIG_USB_KEYBOARD
-       if (usb_kbd_deregister() != 0) {
+       if (usb_kbd_deregister(force) != 0) {
                printf("USB not stopped: usbkbd still using USB\n");
                return 1;
        }
@@ -441,6 +441,26 @@ static int do_usb_stop_keyboard(void)
        return 0;
 }
 
+static void do_usb_start(void)
+{
+       bootstage_mark_name(BOOTSTAGE_ID_USB_START, "usb_start");
+
+       if (usb_init() < 0)
+               return;
+
+#ifdef CONFIG_USB_STORAGE
+       /* try to recognize storage devices immediately */
+       usb_stor_curr_dev = usb_stor_scan(1);
+#endif
+#ifdef CONFIG_USB_HOST_ETHER
+       /* try to recognize ethernet devices immediately */
+       usb_ether_curr_dev = usb_host_eth_scan(1);
+#endif
+#ifdef CONFIG_USB_KEYBOARD
+       drv_usb_kbd_init();
+#endif
+}
+
 /******************************************************************************
  * usb command intepreter
  */
@@ -457,32 +477,26 @@ static int do_usb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
        if (argc < 2)
                return CMD_RET_USAGE;
 
-       if ((strncmp(argv[1], "reset", 5) == 0) ||
-                (strncmp(argv[1], "start", 5) == 0)) {
-               bootstage_mark_name(BOOTSTAGE_ID_USB_START, "usb_start");
-               if (do_usb_stop_keyboard() != 0)
+       if (strncmp(argv[1], "start", 5) == 0) {
+               if (usb_started)
+                       return 0; /* Already started */
+               printf("starting USB...\n");
+               do_usb_start();
+               return 0;
+       }
+
+       if (strncmp(argv[1], "reset", 5) == 0) {
+               printf("resetting USB...\n");
+               if (do_usb_stop_keyboard(1) != 0)
                        return 1;
                usb_stop();
-               printf("(Re)start USB...\n");
-               if (usb_init() >= 0) {
-#ifdef CONFIG_USB_STORAGE
-                       /* try to recognize storage devices immediately */
-                       usb_stor_curr_dev = usb_stor_scan(1);
-#endif
-#ifdef CONFIG_USB_HOST_ETHER
-                       /* try to recognize ethernet devices immediately */
-                       usb_ether_curr_dev = usb_host_eth_scan(1);
-#endif
-#ifdef CONFIG_USB_KEYBOARD
-                       drv_usb_kbd_init();
-#endif
-               }
+               do_usb_start();
                return 0;
        }
        if (strncmp(argv[1], "stop", 4) == 0) {
                if (argc != 2)
                        console_assign(stdin, "serial");
-               if (do_usb_stop_keyboard() != 0)
+               if (do_usb_stop_keyboard(0) != 0)
                        return 1;
                printf("stopping USB..\n");
                usb_stop();