]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/cmd_usb.c
lcd: introduce lcd_set_cmap
[karo-tx-uboot.git] / common / cmd_usb.c
index 70e803b5bb6c6dfe27cac2ef8ebed8cc10f3b075..27813f0d7af680fffa67b0dba509da1ba020e43a 100644 (file)
@@ -5,24 +5,7 @@
  * Most of this source has been derived from the Linux USB
  * project.
  *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
- *
+ * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
@@ -447,6 +430,36 @@ 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(int force)
+{
+#ifdef CONFIG_USB_KEYBOARD
+       if (usb_kbd_deregister(force) != 0) {
+               printf("USB not stopped: usbkbd still using USB\n");
+               return 1;
+       }
+#endif
+       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
@@ -464,40 +477,27 @@ 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 (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) {
-#ifdef CONFIG_USB_KEYBOARD
-               if (argc == 2) {
-                       if (usb_kbd_deregister() != 0) {
-                               printf("USB not stopped: usbkbd still"
-                                       " using USB\n");
-                               return 1;
-                       }
-               } else {
-                       /* forced stop, switch console in to serial */
+               if (argc != 2)
                        console_assign(stdin, "serial");
-                       usb_kbd_deregister();
-               }
-#endif
+               if (do_usb_stop_keyboard(0) != 0)
+                       return 1;
                printf("stopping USB..\n");
                usb_stop();
                return 0;