Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2001 |
| 4 | * Denis Peter, MPL AG Switzerland |
| 5 | * |
Simon Glass | 19e8151 | 2015-03-25 12:22:02 -0600 | [diff] [blame] | 6 | * Adapted for U-Boot driver model |
| 7 | * (C) Copyright 2015 Google, Inc |
| 8 | * |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 9 | * Most of this source has been derived from the Linux USB |
| 10 | * project. |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <common.h> |
Simon Glass | 655306c | 2020-05-10 11:39:58 -0600 | [diff] [blame] | 14 | #include <blk.h> |
Simon Glass | 1ea9789 | 2020-05-10 11:40:00 -0600 | [diff] [blame] | 15 | #include <bootstage.h> |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 16 | #include <command.h> |
Simon Glass | a73bda4 | 2015-11-08 23:47:45 -0700 | [diff] [blame] | 17 | #include <console.h> |
Simon Glass | 19e8151 | 2015-03-25 12:22:02 -0600 | [diff] [blame] | 18 | #include <dm.h> |
Hans de Goede | ee705fc | 2016-04-03 00:04:39 +0200 | [diff] [blame] | 19 | #include <dm/uclass-internal.h> |
Simon Glass | 2dd337a | 2015-09-02 17:24:58 -0600 | [diff] [blame] | 20 | #include <memalign.h> |
wdenk | 8d5d28a | 2005-04-02 22:37:54 +0000 | [diff] [blame] | 21 | #include <asm/byteorder.h> |
Tom Rini | 7342452 | 2011-12-15 08:40:51 -0700 | [diff] [blame] | 22 | #include <asm/unaligned.h> |
Grant Likely | ffc2dd7 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 23 | #include <part.h> |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 24 | #include <usb.h> |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 25 | |
wdenk | acd0536 | 2005-02-24 23:23:29 +0000 | [diff] [blame] | 26 | #ifdef CONFIG_USB_STORAGE |
Wolfgang Denk | dc770c7 | 2008-07-14 15:19:07 +0200 | [diff] [blame] | 27 | static int usb_stor_curr_dev = -1; /* current device */ |
wdenk | acd0536 | 2005-02-24 23:23:29 +0000 | [diff] [blame] | 28 | #endif |
Simon Glass | 5b026f9 | 2015-07-06 16:47:50 -0600 | [diff] [blame] | 29 | #if defined(CONFIG_USB_HOST_ETHER) && !defined(CONFIG_DM_ETH) |
Simon Glass | db19dc5 | 2015-07-06 16:47:48 -0600 | [diff] [blame] | 30 | static int __maybe_unused usb_ether_curr_dev = -1; /* current ethernet device */ |
Simon Glass | 1e9961d | 2011-02-16 11:14:33 -0800 | [diff] [blame] | 31 | #endif |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 32 | |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 33 | /* some display routines (info command) */ |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 34 | static char *usb_get_class_desc(unsigned char dclass) |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 35 | { |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 36 | switch (dclass) { |
| 37 | case USB_CLASS_PER_INTERFACE: |
| 38 | return "See Interface"; |
| 39 | case USB_CLASS_AUDIO: |
| 40 | return "Audio"; |
| 41 | case USB_CLASS_COMM: |
| 42 | return "Communication"; |
| 43 | case USB_CLASS_HID: |
| 44 | return "Human Interface"; |
| 45 | case USB_CLASS_PRINTER: |
| 46 | return "Printer"; |
| 47 | case USB_CLASS_MASS_STORAGE: |
| 48 | return "Mass Storage"; |
| 49 | case USB_CLASS_HUB: |
| 50 | return "Hub"; |
| 51 | case USB_CLASS_DATA: |
| 52 | return "CDC Data"; |
| 53 | case USB_CLASS_VENDOR_SPEC: |
| 54 | return "Vendor specific"; |
| 55 | default: |
| 56 | return ""; |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 57 | } |
| 58 | } |
| 59 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 60 | static void usb_display_class_sub(unsigned char dclass, unsigned char subclass, |
| 61 | unsigned char proto) |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 62 | { |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 63 | switch (dclass) { |
| 64 | case USB_CLASS_PER_INTERFACE: |
| 65 | printf("See Interface"); |
| 66 | break; |
| 67 | case USB_CLASS_HID: |
| 68 | printf("Human Interface, Subclass: "); |
| 69 | switch (subclass) { |
| 70 | case USB_SUB_HID_NONE: |
| 71 | printf("None"); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 72 | break; |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 73 | case USB_SUB_HID_BOOT: |
| 74 | printf("Boot "); |
| 75 | switch (proto) { |
| 76 | case USB_PROT_HID_NONE: |
| 77 | printf("None"); |
| 78 | break; |
| 79 | case USB_PROT_HID_KEYBOARD: |
| 80 | printf("Keyboard"); |
| 81 | break; |
| 82 | case USB_PROT_HID_MOUSE: |
| 83 | printf("Mouse"); |
| 84 | break; |
| 85 | default: |
| 86 | printf("reserved"); |
| 87 | break; |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 88 | } |
| 89 | break; |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 90 | default: |
| 91 | printf("reserved"); |
| 92 | break; |
| 93 | } |
| 94 | break; |
| 95 | case USB_CLASS_MASS_STORAGE: |
| 96 | printf("Mass Storage, "); |
| 97 | switch (subclass) { |
| 98 | case US_SC_RBC: |
| 99 | printf("RBC "); |
| 100 | break; |
| 101 | case US_SC_8020: |
| 102 | printf("SFF-8020i (ATAPI)"); |
| 103 | break; |
| 104 | case US_SC_QIC: |
| 105 | printf("QIC-157 (Tape)"); |
| 106 | break; |
| 107 | case US_SC_UFI: |
| 108 | printf("UFI"); |
| 109 | break; |
| 110 | case US_SC_8070: |
| 111 | printf("SFF-8070"); |
| 112 | break; |
| 113 | case US_SC_SCSI: |
| 114 | printf("Transp. SCSI"); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 115 | break; |
| 116 | default: |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 117 | printf("reserved"); |
| 118 | break; |
| 119 | } |
| 120 | printf(", "); |
| 121 | switch (proto) { |
| 122 | case US_PR_CB: |
| 123 | printf("Command/Bulk"); |
| 124 | break; |
| 125 | case US_PR_CBI: |
| 126 | printf("Command/Bulk/Int"); |
| 127 | break; |
| 128 | case US_PR_BULK: |
| 129 | printf("Bulk only"); |
| 130 | break; |
| 131 | default: |
| 132 | printf("reserved"); |
| 133 | break; |
| 134 | } |
| 135 | break; |
| 136 | default: |
| 137 | printf("%s", usb_get_class_desc(dclass)); |
| 138 | break; |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 139 | } |
| 140 | } |
| 141 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 142 | static void usb_display_string(struct usb_device *dev, int index) |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 143 | { |
Puneet Saxena | 6c9bb60 | 2012-04-03 14:56:06 +0530 | [diff] [blame] | 144 | ALLOC_CACHE_ALIGN_BUFFER(char, buffer, 256); |
| 145 | |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 146 | if (index != 0) { |
| 147 | if (usb_string(dev, index, &buffer[0], 256) > 0) |
| 148 | printf("String: \"%s\"", buffer); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 149 | } |
| 150 | } |
| 151 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 152 | static void usb_display_desc(struct usb_device *dev) |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 153 | { |
Bin Meng | aec8af3 | 2017-07-19 21:50:07 +0800 | [diff] [blame] | 154 | uint packet_size = dev->descriptor.bMaxPacketSize0; |
| 155 | |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 156 | if (dev->descriptor.bDescriptorType == USB_DT_DEVICE) { |
| 157 | printf("%d: %s, USB Revision %x.%x\n", dev->devnum, |
Tom Rix | 83b9e1d | 2009-10-31 12:37:38 -0500 | [diff] [blame] | 158 | usb_get_class_desc(dev->config.if_desc[0].desc.bInterfaceClass), |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 159 | (dev->descriptor.bcdUSB>>8) & 0xff, |
| 160 | dev->descriptor.bcdUSB & 0xff); |
| 161 | |
| 162 | if (strlen(dev->mf) || strlen(dev->prod) || |
| 163 | strlen(dev->serial)) |
| 164 | printf(" - %s %s %s\n", dev->mf, dev->prod, |
| 165 | dev->serial); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 166 | if (dev->descriptor.bDeviceClass) { |
| 167 | printf(" - Class: "); |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 168 | usb_display_class_sub(dev->descriptor.bDeviceClass, |
| 169 | dev->descriptor.bDeviceSubClass, |
| 170 | dev->descriptor.bDeviceProtocol); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 171 | printf("\n"); |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 172 | } else { |
| 173 | printf(" - Class: (from Interface) %s\n", |
| 174 | usb_get_class_desc( |
Tom Rix | 83b9e1d | 2009-10-31 12:37:38 -0500 | [diff] [blame] | 175 | dev->config.if_desc[0].desc.bInterfaceClass)); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 176 | } |
Bin Meng | aec8af3 | 2017-07-19 21:50:07 +0800 | [diff] [blame] | 177 | if (dev->descriptor.bcdUSB >= cpu_to_le16(0x0300)) |
| 178 | packet_size = 1 << packet_size; |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 179 | printf(" - PacketSize: %d Configurations: %d\n", |
Bin Meng | aec8af3 | 2017-07-19 21:50:07 +0800 | [diff] [blame] | 180 | packet_size, dev->descriptor.bNumConfigurations); |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 181 | printf(" - Vendor: 0x%04x Product 0x%04x Version %d.%d\n", |
| 182 | dev->descriptor.idVendor, dev->descriptor.idProduct, |
| 183 | (dev->descriptor.bcdDevice>>8) & 0xff, |
| 184 | dev->descriptor.bcdDevice & 0xff); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | } |
| 188 | |
Ilya Yanok | a1cf10f | 2012-11-06 13:48:20 +0000 | [diff] [blame] | 189 | static void usb_display_conf_desc(struct usb_config_descriptor *config, |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 190 | struct usb_device *dev) |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 191 | { |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 192 | printf(" Configuration: %d\n", config->bConfigurationValue); |
| 193 | printf(" - Interfaces: %d %s%s%dmA\n", config->bNumInterfaces, |
| 194 | (config->bmAttributes & 0x40) ? "Self Powered " : "Bus Powered ", |
| 195 | (config->bmAttributes & 0x20) ? "Remote Wakeup " : "", |
Tom Rix | 83b9e1d | 2009-10-31 12:37:38 -0500 | [diff] [blame] | 196 | config->bMaxPower*2); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 197 | if (config->iConfiguration) { |
| 198 | printf(" - "); |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 199 | usb_display_string(dev, config->iConfiguration); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 200 | printf("\n"); |
| 201 | } |
| 202 | } |
| 203 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 204 | static void usb_display_if_desc(struct usb_interface_descriptor *ifdesc, |
| 205 | struct usb_device *dev) |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 206 | { |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 207 | printf(" Interface: %d\n", ifdesc->bInterfaceNumber); |
| 208 | printf(" - Alternate Setting %d, Endpoints: %d\n", |
| 209 | ifdesc->bAlternateSetting, ifdesc->bNumEndpoints); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 210 | printf(" - Class "); |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 211 | usb_display_class_sub(ifdesc->bInterfaceClass, |
| 212 | ifdesc->bInterfaceSubClass, ifdesc->bInterfaceProtocol); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 213 | printf("\n"); |
| 214 | if (ifdesc->iInterface) { |
| 215 | printf(" - "); |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 216 | usb_display_string(dev, ifdesc->iInterface); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 217 | printf("\n"); |
| 218 | } |
| 219 | } |
| 220 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 221 | static void usb_display_ep_desc(struct usb_endpoint_descriptor *epdesc) |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 222 | { |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 223 | printf(" - Endpoint %d %s ", epdesc->bEndpointAddress & 0xf, |
| 224 | (epdesc->bEndpointAddress & 0x80) ? "In" : "Out"); |
| 225 | switch ((epdesc->bmAttributes & 0x03)) { |
| 226 | case 0: |
| 227 | printf("Control"); |
| 228 | break; |
| 229 | case 1: |
| 230 | printf("Isochronous"); |
| 231 | break; |
| 232 | case 2: |
| 233 | printf("Bulk"); |
| 234 | break; |
| 235 | case 3: |
| 236 | printf("Interrupt"); |
| 237 | break; |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 238 | } |
Tom Rini | 7342452 | 2011-12-15 08:40:51 -0700 | [diff] [blame] | 239 | printf(" MaxPacket %d", get_unaligned(&epdesc->wMaxPacketSize)); |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 240 | if ((epdesc->bmAttributes & 0x03) == 0x3) |
| 241 | printf(" Interval %dms", epdesc->bInterval); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 242 | printf("\n"); |
| 243 | } |
| 244 | |
| 245 | /* main routine to diasplay the configs, interfaces and endpoints */ |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 246 | static void usb_display_config(struct usb_device *dev) |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 247 | { |
Tom Rix | 83b9e1d | 2009-10-31 12:37:38 -0500 | [diff] [blame] | 248 | struct usb_config *config; |
| 249 | struct usb_interface *ifdesc; |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 250 | struct usb_endpoint_descriptor *epdesc; |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 251 | int i, ii; |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 252 | |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 253 | config = &dev->config; |
Tom Rix | 83b9e1d | 2009-10-31 12:37:38 -0500 | [diff] [blame] | 254 | usb_display_conf_desc(&config->desc, dev); |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 255 | for (i = 0; i < config->no_of_if; i++) { |
| 256 | ifdesc = &config->if_desc[i]; |
Tom Rix | 83b9e1d | 2009-10-31 12:37:38 -0500 | [diff] [blame] | 257 | usb_display_if_desc(&ifdesc->desc, dev); |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 258 | for (ii = 0; ii < ifdesc->no_of_ep; ii++) { |
| 259 | epdesc = &ifdesc->ep_desc[ii]; |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 260 | usb_display_ep_desc(epdesc); |
| 261 | } |
| 262 | } |
| 263 | printf("\n"); |
| 264 | } |
| 265 | |
Simon Glass | 19e8151 | 2015-03-25 12:22:02 -0600 | [diff] [blame] | 266 | /* |
| 267 | * With driver model this isn't right since we can have multiple controllers |
| 268 | * and the device numbering starts at 1 on each bus. |
| 269 | * TODO(sjg@chromium.org): Add a way to specify the controller/bus. |
| 270 | */ |
Julius Werner | d404670 | 2013-02-28 18:08:40 +0000 | [diff] [blame] | 271 | static struct usb_device *usb_find_device(int devnum) |
| 272 | { |
Simon Glass | 19e8151 | 2015-03-25 12:22:02 -0600 | [diff] [blame] | 273 | #ifdef CONFIG_DM_USB |
| 274 | struct usb_device *udev; |
| 275 | struct udevice *hub; |
| 276 | struct uclass *uc; |
| 277 | int ret; |
| 278 | |
| 279 | /* Device addresses start at 1 */ |
| 280 | devnum++; |
| 281 | ret = uclass_get(UCLASS_USB_HUB, &uc); |
| 282 | if (ret) |
| 283 | return NULL; |
| 284 | |
| 285 | uclass_foreach_dev(hub, uc) { |
| 286 | struct udevice *dev; |
| 287 | |
| 288 | if (!device_active(hub)) |
| 289 | continue; |
Simon Glass | de44acf | 2015-09-28 23:32:01 -0600 | [diff] [blame] | 290 | udev = dev_get_parent_priv(hub); |
Simon Glass | 19e8151 | 2015-03-25 12:22:02 -0600 | [diff] [blame] | 291 | if (udev->devnum == devnum) |
| 292 | return udev; |
| 293 | |
| 294 | for (device_find_first_child(hub, &dev); |
| 295 | dev; |
| 296 | device_find_next_child(&dev)) { |
| 297 | if (!device_active(hub)) |
| 298 | continue; |
| 299 | |
Simon Glass | de44acf | 2015-09-28 23:32:01 -0600 | [diff] [blame] | 300 | udev = dev_get_parent_priv(dev); |
Simon Glass | 19e8151 | 2015-03-25 12:22:02 -0600 | [diff] [blame] | 301 | if (udev->devnum == devnum) |
| 302 | return udev; |
| 303 | } |
| 304 | } |
| 305 | #else |
Simon Glass | 729e257 | 2015-03-25 12:22:00 -0600 | [diff] [blame] | 306 | struct usb_device *udev; |
Julius Werner | d404670 | 2013-02-28 18:08:40 +0000 | [diff] [blame] | 307 | int d; |
| 308 | |
| 309 | for (d = 0; d < USB_MAX_DEVICE; d++) { |
Simon Glass | 729e257 | 2015-03-25 12:22:00 -0600 | [diff] [blame] | 310 | udev = usb_get_dev_index(d); |
| 311 | if (udev == NULL) |
Julius Werner | d404670 | 2013-02-28 18:08:40 +0000 | [diff] [blame] | 312 | return NULL; |
Simon Glass | 729e257 | 2015-03-25 12:22:00 -0600 | [diff] [blame] | 313 | if (udev->devnum == devnum) |
| 314 | return udev; |
Julius Werner | d404670 | 2013-02-28 18:08:40 +0000 | [diff] [blame] | 315 | } |
Simon Glass | 19e8151 | 2015-03-25 12:22:02 -0600 | [diff] [blame] | 316 | #endif |
Julius Werner | d404670 | 2013-02-28 18:08:40 +0000 | [diff] [blame] | 317 | |
| 318 | return NULL; |
| 319 | } |
| 320 | |
Ismael Luceno Cortes | 93431a8 | 2019-04-01 16:09:13 +0000 | [diff] [blame] | 321 | static inline const char *portspeed(int speed) |
Stefan Roese | 6a6d9d1 | 2009-01-22 10:11:21 +0100 | [diff] [blame] | 322 | { |
Vivek Gautam | df3f221 | 2013-04-12 16:34:38 +0530 | [diff] [blame] | 323 | switch (speed) { |
| 324 | case USB_SPEED_SUPER: |
Ismael Luceno Cortes | 93431a8 | 2019-04-01 16:09:13 +0000 | [diff] [blame] | 325 | return "5 Gb/s"; |
Vivek Gautam | df3f221 | 2013-04-12 16:34:38 +0530 | [diff] [blame] | 326 | case USB_SPEED_HIGH: |
Ismael Luceno Cortes | 93431a8 | 2019-04-01 16:09:13 +0000 | [diff] [blame] | 327 | return "480 Mb/s"; |
Vivek Gautam | df3f221 | 2013-04-12 16:34:38 +0530 | [diff] [blame] | 328 | case USB_SPEED_LOW: |
Ismael Luceno Cortes | 93431a8 | 2019-04-01 16:09:13 +0000 | [diff] [blame] | 329 | return "1.5 Mb/s"; |
Vivek Gautam | df3f221 | 2013-04-12 16:34:38 +0530 | [diff] [blame] | 330 | default: |
Ismael Luceno Cortes | 93431a8 | 2019-04-01 16:09:13 +0000 | [diff] [blame] | 331 | return "12 Mb/s"; |
Vivek Gautam | df3f221 | 2013-04-12 16:34:38 +0530 | [diff] [blame] | 332 | } |
Stefan Roese | 6a6d9d1 | 2009-01-22 10:11:21 +0100 | [diff] [blame] | 333 | } |
| 334 | |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 335 | /* shows the device tree recursively */ |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 336 | static void usb_show_tree_graph(struct usb_device *dev, char *pre) |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 337 | { |
Simon Glass | 19e8151 | 2015-03-25 12:22:02 -0600 | [diff] [blame] | 338 | int index; |
Wolfgang Denk | 6c7c558 | 2011-10-05 23:01:59 +0200 | [diff] [blame] | 339 | int has_child, last_child; |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 340 | |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 341 | index = strlen(pre); |
| 342 | printf(" %s", pre); |
Simon Glass | 19e8151 | 2015-03-25 12:22:02 -0600 | [diff] [blame] | 343 | #ifdef CONFIG_DM_USB |
| 344 | has_child = device_has_active_children(dev->dev); |
Suneel Garapati | e7728fe | 2017-10-23 17:28:40 -0700 | [diff] [blame] | 345 | if (device_get_uclass_id(dev->dev) == UCLASS_MASS_STORAGE) { |
| 346 | struct udevice *child; |
| 347 | |
| 348 | for (device_find_first_child(dev->dev, &child); |
| 349 | child; |
| 350 | device_find_next_child(&child)) { |
| 351 | if (device_get_uclass_id(child) == UCLASS_BLK) |
| 352 | has_child = 0; |
| 353 | } |
| 354 | } |
Simon Glass | 19e8151 | 2015-03-25 12:22:02 -0600 | [diff] [blame] | 355 | #else |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 356 | /* check if the device has connected children */ |
Simon Glass | 19e8151 | 2015-03-25 12:22:02 -0600 | [diff] [blame] | 357 | int i; |
| 358 | |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 359 | has_child = 0; |
| 360 | for (i = 0; i < dev->maxchild; i++) { |
| 361 | if (dev->children[i] != NULL) |
| 362 | has_child = 1; |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 363 | } |
Simon Glass | 19e8151 | 2015-03-25 12:22:02 -0600 | [diff] [blame] | 364 | #endif |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 365 | /* check if we are the last one */ |
Simon Glass | 19e8151 | 2015-03-25 12:22:02 -0600 | [diff] [blame] | 366 | #ifdef CONFIG_DM_USB |
Hans de Goede | f97c8e2 | 2015-06-17 21:33:50 +0200 | [diff] [blame] | 367 | /* Not the root of the usb tree? */ |
| 368 | if (device_get_uclass_id(dev->dev->parent) != UCLASS_USB) { |
| 369 | last_child = device_is_last_sibling(dev->dev); |
Simon Glass | 19e8151 | 2015-03-25 12:22:02 -0600 | [diff] [blame] | 370 | #else |
Hans de Goede | f97c8e2 | 2015-06-17 21:33:50 +0200 | [diff] [blame] | 371 | if (dev->parent != NULL) { /* not root? */ |
| 372 | last_child = 1; |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 373 | for (i = 0; i < dev->parent->maxchild; i++) { |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 374 | /* search for children */ |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 375 | if (dev->parent->children[i] == dev) { |
| 376 | /* found our pointer, see if we have a |
| 377 | * little sister |
| 378 | */ |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 379 | while (i++ < dev->parent->maxchild) { |
| 380 | if (dev->parent->children[i] != NULL) { |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 381 | /* found a sister */ |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 382 | last_child = 0; |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 383 | break; |
| 384 | } /* if */ |
| 385 | } /* while */ |
| 386 | } /* device found */ |
| 387 | } /* for all children of the parent */ |
Simon Glass | 19e8151 | 2015-03-25 12:22:02 -0600 | [diff] [blame] | 388 | #endif |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 389 | printf("\b+-"); |
| 390 | /* correct last child */ |
Simon Glass | 729e257 | 2015-03-25 12:22:00 -0600 | [diff] [blame] | 391 | if (last_child && index) |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 392 | pre[index-1] = ' '; |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 393 | } /* if not root hub */ |
| 394 | else |
| 395 | printf(" "); |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 396 | printf("%d ", dev->devnum); |
| 397 | pre[index++] = ' '; |
| 398 | pre[index++] = has_child ? '|' : ' '; |
| 399 | pre[index] = 0; |
| 400 | printf(" %s (%s, %dmA)\n", usb_get_class_desc( |
Tom Rix | 83b9e1d | 2009-10-31 12:37:38 -0500 | [diff] [blame] | 401 | dev->config.if_desc[0].desc.bInterfaceClass), |
Stefan Roese | 6a6d9d1 | 2009-01-22 10:11:21 +0100 | [diff] [blame] | 402 | portspeed(dev->speed), |
Tom Rix | 83b9e1d | 2009-10-31 12:37:38 -0500 | [diff] [blame] | 403 | dev->config.desc.bMaxPower * 2); |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 404 | if (strlen(dev->mf) || strlen(dev->prod) || strlen(dev->serial)) |
| 405 | printf(" %s %s %s %s\n", pre, dev->mf, dev->prod, dev->serial); |
| 406 | printf(" %s\n", pre); |
Simon Glass | 19e8151 | 2015-03-25 12:22:02 -0600 | [diff] [blame] | 407 | #ifdef CONFIG_DM_USB |
| 408 | struct udevice *child; |
| 409 | |
| 410 | for (device_find_first_child(dev->dev, &child); |
| 411 | child; |
| 412 | device_find_next_child(&child)) { |
| 413 | struct usb_device *udev; |
| 414 | |
| 415 | if (!device_active(child)) |
| 416 | continue; |
| 417 | |
Simon Glass | de44acf | 2015-09-28 23:32:01 -0600 | [diff] [blame] | 418 | udev = dev_get_parent_priv(child); |
Simon Glass | 19e8151 | 2015-03-25 12:22:02 -0600 | [diff] [blame] | 419 | |
Suneel Garapati | e7728fe | 2017-10-23 17:28:40 -0700 | [diff] [blame] | 420 | /* |
| 421 | * Ignore emulators and block child devices, we only want |
| 422 | * real devices |
| 423 | */ |
| 424 | if ((device_get_uclass_id(child) != UCLASS_USB_EMUL) && |
| 425 | (device_get_uclass_id(child) != UCLASS_BLK)) { |
Simon Glass | 19e8151 | 2015-03-25 12:22:02 -0600 | [diff] [blame] | 426 | usb_show_tree_graph(udev, pre); |
| 427 | pre[index] = 0; |
| 428 | } |
| 429 | } |
| 430 | #else |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 431 | if (dev->maxchild > 0) { |
| 432 | for (i = 0; i < dev->maxchild; i++) { |
| 433 | if (dev->children[i] != NULL) { |
| 434 | usb_show_tree_graph(dev->children[i], pre); |
| 435 | pre[index] = 0; |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 436 | } |
| 437 | } |
| 438 | } |
Simon Glass | 19e8151 | 2015-03-25 12:22:02 -0600 | [diff] [blame] | 439 | #endif |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | /* main routine for the tree command */ |
Simon Glass | 09def3a | 2015-11-08 23:47:51 -0700 | [diff] [blame] | 443 | static void usb_show_subtree(struct usb_device *dev) |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 444 | { |
| 445 | char preamble[32]; |
| 446 | |
Simon Glass | 729e257 | 2015-03-25 12:22:00 -0600 | [diff] [blame] | 447 | memset(preamble, '\0', sizeof(preamble)); |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 448 | usb_show_tree_graph(dev, &preamble[0]); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 449 | } |
| 450 | |
Simon Glass | 09def3a | 2015-11-08 23:47:51 -0700 | [diff] [blame] | 451 | #ifdef CONFIG_DM_USB |
Hans de Goede | f4451d9 | 2016-07-03 20:22:04 +0200 | [diff] [blame] | 452 | typedef void (*usb_dev_func_t)(struct usb_device *udev); |
| 453 | |
| 454 | static void usb_for_each_root_dev(usb_dev_func_t func) |
| 455 | { |
Simon Glass | 09def3a | 2015-11-08 23:47:51 -0700 | [diff] [blame] | 456 | struct udevice *bus; |
| 457 | |
Hans de Goede | ee705fc | 2016-04-03 00:04:39 +0200 | [diff] [blame] | 458 | for (uclass_find_first_device(UCLASS_USB, &bus); |
Simon Glass | 09def3a | 2015-11-08 23:47:51 -0700 | [diff] [blame] | 459 | bus; |
Hans de Goede | ee705fc | 2016-04-03 00:04:39 +0200 | [diff] [blame] | 460 | uclass_find_next_device(&bus)) { |
Simon Glass | 09def3a | 2015-11-08 23:47:51 -0700 | [diff] [blame] | 461 | struct usb_device *udev; |
| 462 | struct udevice *dev; |
| 463 | |
Hans de Goede | ee705fc | 2016-04-03 00:04:39 +0200 | [diff] [blame] | 464 | if (!device_active(bus)) |
| 465 | continue; |
| 466 | |
Simon Glass | 09def3a | 2015-11-08 23:47:51 -0700 | [diff] [blame] | 467 | device_find_first_child(bus, &dev); |
| 468 | if (dev && device_active(dev)) { |
| 469 | udev = dev_get_parent_priv(dev); |
Hans de Goede | f4451d9 | 2016-07-03 20:22:04 +0200 | [diff] [blame] | 470 | func(udev); |
Simon Glass | 09def3a | 2015-11-08 23:47:51 -0700 | [diff] [blame] | 471 | } |
| 472 | } |
Hans de Goede | f4451d9 | 2016-07-03 20:22:04 +0200 | [diff] [blame] | 473 | } |
| 474 | #endif |
| 475 | |
| 476 | void usb_show_tree(void) |
| 477 | { |
| 478 | #ifdef CONFIG_DM_USB |
| 479 | usb_for_each_root_dev(usb_show_subtree); |
Simon Glass | 09def3a | 2015-11-08 23:47:51 -0700 | [diff] [blame] | 480 | #else |
| 481 | struct usb_device *udev; |
| 482 | int i; |
| 483 | |
| 484 | for (i = 0; i < USB_MAX_DEVICE; i++) { |
| 485 | udev = usb_get_dev_index(i); |
| 486 | if (udev == NULL) |
| 487 | break; |
| 488 | if (udev->parent == NULL) |
| 489 | usb_show_subtree(udev); |
| 490 | } |
| 491 | #endif |
| 492 | } |
| 493 | |
Julius Werner | d404670 | 2013-02-28 18:08:40 +0000 | [diff] [blame] | 494 | static int usb_test(struct usb_device *dev, int port, char* arg) |
| 495 | { |
| 496 | int mode; |
| 497 | |
| 498 | if (port > dev->maxchild) { |
| 499 | printf("Device is no hub or does not have %d ports.\n", port); |
| 500 | return 1; |
| 501 | } |
| 502 | |
| 503 | switch (arg[0]) { |
| 504 | case 'J': |
| 505 | case 'j': |
| 506 | printf("Setting Test_J mode"); |
| 507 | mode = USB_TEST_MODE_J; |
| 508 | break; |
| 509 | case 'K': |
| 510 | case 'k': |
| 511 | printf("Setting Test_K mode"); |
| 512 | mode = USB_TEST_MODE_K; |
| 513 | break; |
| 514 | case 'S': |
| 515 | case 's': |
| 516 | printf("Setting Test_SE0_NAK mode"); |
| 517 | mode = USB_TEST_MODE_SE0_NAK; |
| 518 | break; |
| 519 | case 'P': |
| 520 | case 'p': |
| 521 | printf("Setting Test_Packet mode"); |
| 522 | mode = USB_TEST_MODE_PACKET; |
| 523 | break; |
| 524 | case 'F': |
| 525 | case 'f': |
| 526 | printf("Setting Test_Force_Enable mode"); |
| 527 | mode = USB_TEST_MODE_FORCE_ENABLE; |
| 528 | break; |
| 529 | default: |
| 530 | printf("Unrecognized test mode: %s\nAvailable modes: " |
| 531 | "J, K, S[E0_NAK], P[acket], F[orce_Enable]\n", arg); |
| 532 | return 1; |
| 533 | } |
| 534 | |
| 535 | if (port) |
| 536 | printf(" on downstream facing port %d...\n", port); |
| 537 | else |
| 538 | printf(" on upstream facing port...\n"); |
| 539 | |
| 540 | if (usb_control_msg(dev, usb_sndctrlpipe(dev, 0), USB_REQ_SET_FEATURE, |
| 541 | port ? USB_RT_PORT : USB_RECIP_DEVICE, |
| 542 | port ? USB_PORT_FEAT_TEST : USB_FEAT_TEST, |
| 543 | (mode << 8) | port, |
| 544 | NULL, 0, USB_CNTL_TIMEOUT) == -1) { |
| 545 | printf("Error during SET_FEATURE.\n"); |
| 546 | return 1; |
| 547 | } else { |
| 548 | printf("Test mode successfully set. Use 'usb start' " |
| 549 | "to return to normal operation.\n"); |
| 550 | return 0; |
| 551 | } |
| 552 | } |
| 553 | |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 554 | |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 555 | /****************************************************************************** |
| 556 | * usb boot command intepreter. Derived from diskboot |
| 557 | */ |
| 558 | #ifdef CONFIG_USB_STORAGE |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 559 | static int do_usbboot(struct cmd_tbl *cmdtp, int flag, int argc, |
| 560 | char *const argv[]) |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 561 | { |
Rob Herring | a20cbf9 | 2012-09-21 04:02:30 +0000 | [diff] [blame] | 562 | return common_diskboot(cmdtp, "usb", argc, argv); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 563 | } |
| 564 | #endif /* CONFIG_USB_STORAGE */ |
| 565 | |
Hans de Goede | 3e51df0 | 2014-09-20 16:54:38 +0200 | [diff] [blame] | 566 | static int do_usb_stop_keyboard(int force) |
Hans de Goede | c7c1174 | 2014-09-20 16:54:35 +0200 | [diff] [blame] | 567 | { |
Hans de Goede | a88d437 | 2016-04-03 09:18:53 +0200 | [diff] [blame] | 568 | #if !defined CONFIG_DM_USB && defined CONFIG_USB_KEYBOARD |
Hans de Goede | 3e51df0 | 2014-09-20 16:54:38 +0200 | [diff] [blame] | 569 | if (usb_kbd_deregister(force) != 0) { |
Hans de Goede | c7c1174 | 2014-09-20 16:54:35 +0200 | [diff] [blame] | 570 | printf("USB not stopped: usbkbd still using USB\n"); |
| 571 | return 1; |
| 572 | } |
| 573 | #endif |
| 574 | return 0; |
| 575 | } |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 576 | |
Hans de Goede | 2af8256 | 2015-01-06 14:27:41 +0100 | [diff] [blame] | 577 | static void do_usb_start(void) |
| 578 | { |
| 579 | bootstage_mark_name(BOOTSTAGE_ID_USB_START, "usb_start"); |
| 580 | |
| 581 | if (usb_init() < 0) |
| 582 | return; |
| 583 | |
Simon Glass | 19e8151 | 2015-03-25 12:22:02 -0600 | [diff] [blame] | 584 | /* Driver model will probe the devices as they are found */ |
Simon Glass | 02f0c28 | 2015-09-08 11:15:11 -0600 | [diff] [blame] | 585 | # ifdef CONFIG_USB_STORAGE |
Hans de Goede | 2af8256 | 2015-01-06 14:27:41 +0100 | [diff] [blame] | 586 | /* try to recognize storage devices immediately */ |
| 587 | usb_stor_curr_dev = usb_stor_scan(1); |
Simon Glass | 02f0c28 | 2015-09-08 11:15:11 -0600 | [diff] [blame] | 588 | # endif |
Michal Simek | cd8f86f | 2016-12-21 09:35:08 +0100 | [diff] [blame] | 589 | #ifndef CONFIG_DM_USB |
Simon Glass | 02f0c28 | 2015-09-08 11:15:11 -0600 | [diff] [blame] | 590 | # ifdef CONFIG_USB_KEYBOARD |
| 591 | drv_usb_kbd_init(); |
| 592 | # endif |
| 593 | #endif /* !CONFIG_DM_USB */ |
Hans de Goede | 2af8256 | 2015-01-06 14:27:41 +0100 | [diff] [blame] | 594 | } |
Simon Glass | 19e8151 | 2015-03-25 12:22:02 -0600 | [diff] [blame] | 595 | |
| 596 | #ifdef CONFIG_DM_USB |
Hans de Goede | f88d6fa | 2016-07-03 20:22:05 +0200 | [diff] [blame] | 597 | static void usb_show_info(struct usb_device *udev) |
Simon Glass | 19e8151 | 2015-03-25 12:22:02 -0600 | [diff] [blame] | 598 | { |
| 599 | struct udevice *child; |
Simon Glass | 19e8151 | 2015-03-25 12:22:02 -0600 | [diff] [blame] | 600 | |
Simon Glass | 19e8151 | 2015-03-25 12:22:02 -0600 | [diff] [blame] | 601 | usb_display_desc(udev); |
| 602 | usb_display_config(udev); |
Hans de Goede | f88d6fa | 2016-07-03 20:22:05 +0200 | [diff] [blame] | 603 | for (device_find_first_child(udev->dev, &child); |
Simon Glass | 19e8151 | 2015-03-25 12:22:02 -0600 | [diff] [blame] | 604 | child; |
| 605 | device_find_next_child(&child)) { |
Suneel Garapati | e7728fe | 2017-10-23 17:28:40 -0700 | [diff] [blame] | 606 | if (device_active(child) && |
| 607 | (device_get_uclass_id(child) != UCLASS_USB_EMUL) && |
| 608 | (device_get_uclass_id(child) != UCLASS_BLK)) { |
Hans de Goede | f88d6fa | 2016-07-03 20:22:05 +0200 | [diff] [blame] | 609 | udev = dev_get_parent_priv(child); |
| 610 | usb_show_info(udev); |
Simon Glass | 19e8151 | 2015-03-25 12:22:02 -0600 | [diff] [blame] | 611 | } |
| 612 | } |
Simon Glass | 19e8151 | 2015-03-25 12:22:02 -0600 | [diff] [blame] | 613 | } |
| 614 | #endif |
Hans de Goede | 2af8256 | 2015-01-06 14:27:41 +0100 | [diff] [blame] | 615 | |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 616 | /****************************************************************************** |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 617 | * usb command intepreter |
| 618 | */ |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 619 | static int do_usb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 620 | { |
Simon Glass | 729e257 | 2015-03-25 12:22:00 -0600 | [diff] [blame] | 621 | struct usb_device *udev = NULL; |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 622 | int i; |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 623 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 624 | if (argc < 2) |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 625 | return CMD_RET_USAGE; |
Serge Ziryukin | 84e20a2 | 2010-04-25 21:32:36 +0300 | [diff] [blame] | 626 | |
Hans de Goede | 2af8256 | 2015-01-06 14:27:41 +0100 | [diff] [blame] | 627 | if (strncmp(argv[1], "start", 5) == 0) { |
| 628 | if (usb_started) |
| 629 | return 0; /* Already started */ |
| 630 | printf("starting USB...\n"); |
| 631 | do_usb_start(); |
| 632 | return 0; |
| 633 | } |
| 634 | |
| 635 | if (strncmp(argv[1], "reset", 5) == 0) { |
| 636 | printf("resetting USB...\n"); |
Hans de Goede | 3e51df0 | 2014-09-20 16:54:38 +0200 | [diff] [blame] | 637 | if (do_usb_stop_keyboard(1) != 0) |
Hans de Goede | c7c1174 | 2014-09-20 16:54:35 +0200 | [diff] [blame] | 638 | return 1; |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 639 | usb_stop(); |
Hans de Goede | 2af8256 | 2015-01-06 14:27:41 +0100 | [diff] [blame] | 640 | do_usb_start(); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 641 | return 0; |
| 642 | } |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 643 | if (strncmp(argv[1], "stop", 4) == 0) { |
Hans de Goede | c7c1174 | 2014-09-20 16:54:35 +0200 | [diff] [blame] | 644 | if (argc != 2) |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 645 | console_assign(stdin, "serial"); |
Hans de Goede | 3e51df0 | 2014-09-20 16:54:38 +0200 | [diff] [blame] | 646 | if (do_usb_stop_keyboard(0) != 0) |
Hans de Goede | c7c1174 | 2014-09-20 16:54:35 +0200 | [diff] [blame] | 647 | return 1; |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 648 | printf("stopping USB..\n"); |
| 649 | usb_stop(); |
| 650 | return 0; |
| 651 | } |
Bartlomiej Sieka | e39589f | 2006-08-03 23:20:13 +0200 | [diff] [blame] | 652 | if (!usb_started) { |
| 653 | printf("USB is stopped. Please issue 'usb start' first.\n"); |
| 654 | return 1; |
| 655 | } |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 656 | if (strncmp(argv[1], "tree", 4) == 0) { |
Lucas Stach | e6d3345 | 2012-09-26 00:14:36 +0200 | [diff] [blame] | 657 | puts("USB device tree:\n"); |
Simon Glass | 09def3a | 2015-11-08 23:47:51 -0700 | [diff] [blame] | 658 | usb_show_tree(); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 659 | return 0; |
| 660 | } |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 661 | if (strncmp(argv[1], "inf", 3) == 0) { |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 662 | if (argc == 2) { |
Simon Glass | 19e8151 | 2015-03-25 12:22:02 -0600 | [diff] [blame] | 663 | #ifdef CONFIG_DM_USB |
Hans de Goede | f88d6fa | 2016-07-03 20:22:05 +0200 | [diff] [blame] | 664 | usb_for_each_root_dev(usb_show_info); |
Simon Glass | 19e8151 | 2015-03-25 12:22:02 -0600 | [diff] [blame] | 665 | #else |
| 666 | int d; |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 667 | for (d = 0; d < USB_MAX_DEVICE; d++) { |
Simon Glass | 729e257 | 2015-03-25 12:22:00 -0600 | [diff] [blame] | 668 | udev = usb_get_dev_index(d); |
| 669 | if (udev == NULL) |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 670 | break; |
Simon Glass | 729e257 | 2015-03-25 12:22:00 -0600 | [diff] [blame] | 671 | usb_display_desc(udev); |
| 672 | usb_display_config(udev); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 673 | } |
Simon Glass | 19e8151 | 2015-03-25 12:22:02 -0600 | [diff] [blame] | 674 | #endif |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 675 | return 0; |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 676 | } else { |
Simon Glass | 19e8151 | 2015-03-25 12:22:02 -0600 | [diff] [blame] | 677 | /* |
| 678 | * With driver model this isn't right since we can |
| 679 | * have multiple controllers and the device numbering |
| 680 | * starts at 1 on each bus. |
| 681 | */ |
Simon Glass | ff9b903 | 2021-07-24 09:03:30 -0600 | [diff] [blame] | 682 | i = dectoul(argv[2], NULL); |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 683 | printf("config for device %d\n", i); |
Simon Glass | 729e257 | 2015-03-25 12:22:00 -0600 | [diff] [blame] | 684 | udev = usb_find_device(i); |
| 685 | if (udev == NULL) { |
Loïc Minier | 5d0569a | 2011-02-03 22:04:26 +0100 | [diff] [blame] | 686 | printf("*** No device available ***\n"); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 687 | return 0; |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 688 | } else { |
Simon Glass | 729e257 | 2015-03-25 12:22:00 -0600 | [diff] [blame] | 689 | usb_display_desc(udev); |
| 690 | usb_display_config(udev); |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 691 | } |
| 692 | } |
| 693 | return 0; |
| 694 | } |
Julius Werner | d404670 | 2013-02-28 18:08:40 +0000 | [diff] [blame] | 695 | if (strncmp(argv[1], "test", 4) == 0) { |
| 696 | if (argc < 5) |
| 697 | return CMD_RET_USAGE; |
Simon Glass | ff9b903 | 2021-07-24 09:03:30 -0600 | [diff] [blame] | 698 | i = dectoul(argv[2], NULL); |
Simon Glass | 729e257 | 2015-03-25 12:22:00 -0600 | [diff] [blame] | 699 | udev = usb_find_device(i); |
| 700 | if (udev == NULL) { |
Julius Werner | d404670 | 2013-02-28 18:08:40 +0000 | [diff] [blame] | 701 | printf("Device %d does not exist.\n", i); |
| 702 | return 1; |
| 703 | } |
Simon Glass | ff9b903 | 2021-07-24 09:03:30 -0600 | [diff] [blame] | 704 | i = dectoul(argv[3], NULL); |
Simon Glass | 729e257 | 2015-03-25 12:22:00 -0600 | [diff] [blame] | 705 | return usb_test(udev, i, argv[4]); |
Julius Werner | d404670 | 2013-02-28 18:08:40 +0000 | [diff] [blame] | 706 | } |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 707 | #ifdef CONFIG_USB_STORAGE |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 708 | if (strncmp(argv[1], "stor", 4) == 0) |
Aras Vaichas | 7ede186 | 2008-03-25 12:09:07 +1100 | [diff] [blame] | 709 | return usb_stor_info(); |
Wolfgang Denk | c7a4f7d | 2005-07-21 11:57:57 +0200 | [diff] [blame] | 710 | |
Simon Glass | dbfa32c | 2022-08-11 19:34:59 -0600 | [diff] [blame] | 711 | return blk_common_cmd(argc, argv, UCLASS_USB, &usb_stor_curr_dev); |
Simon Glass | d9289f3 | 2017-07-29 11:34:58 -0600 | [diff] [blame] | 712 | #else |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 713 | return CMD_RET_USAGE; |
Simon Glass | d9289f3 | 2017-07-29 11:34:58 -0600 | [diff] [blame] | 714 | #endif /* CONFIG_USB_STORAGE */ |
wdenk | e887afc | 2002-08-27 09:44:07 +0000 | [diff] [blame] | 715 | } |
| 716 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 717 | U_BOOT_CMD( |
| 718 | usb, 5, 1, do_usb, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 719 | "USB sub-system", |
Veli-Pekka Peltola | ddb90d3 | 2011-11-02 16:59:56 +0200 | [diff] [blame] | 720 | "start - start (scan) USB controller\n" |
| 721 | "usb reset - reset (rescan) USB controller\n" |
Veli-Pekka Peltola | 1f47a4d | 2011-11-02 16:59:55 +0200 | [diff] [blame] | 722 | "usb stop [f] - stop USB [f]=force stop\n" |
| 723 | "usb tree - show USB device tree\n" |
wdenk | 20c98a6 | 2004-04-23 20:32:05 +0000 | [diff] [blame] | 724 | "usb info [dev] - show available USB devices\n" |
Julius Werner | d404670 | 2013-02-28 18:08:40 +0000 | [diff] [blame] | 725 | "usb test [dev] [port] [mode] - set USB 2.0 test mode\n" |
| 726 | " (specify port 0 to indicate the device's upstream port)\n" |
| 727 | " Available modes: J, K, S[E0_NAK], P[acket], F[orce_Enable]\n" |
| 728 | #ifdef CONFIG_USB_STORAGE |
Veli-Pekka Peltola | 1f47a4d | 2011-11-02 16:59:55 +0200 | [diff] [blame] | 729 | "usb storage - show details of USB storage devices\n" |
wdenk | a2b932d | 2005-06-27 13:30:03 +0000 | [diff] [blame] | 730 | "usb dev [dev] - show or set current USB storage device\n" |
Michael Trimarchi | 5f2e7fc | 2008-11-26 17:41:34 +0100 | [diff] [blame] | 731 | "usb part [dev] - print partition table of one or all USB storage" |
Julius Werner | d404670 | 2013-02-28 18:08:40 +0000 | [diff] [blame] | 732 | " devices\n" |
wdenk | 20c98a6 | 2004-04-23 20:32:05 +0000 | [diff] [blame] | 733 | "usb read addr blk# cnt - read `cnt' blocks starting at block `blk#'\n" |
Sergei Poselenov | 95b57aa | 2010-08-09 16:01:42 +0400 | [diff] [blame] | 734 | " to memory address `addr'\n" |
Mahavir Jain | d43a0b8 | 2009-11-03 12:22:10 +0530 | [diff] [blame] | 735 | "usb write addr blk# cnt - write `cnt' blocks starting at block `blk#'\n" |
| 736 | " from memory address `addr'" |
Julius Werner | d404670 | 2013-02-28 18:08:40 +0000 | [diff] [blame] | 737 | #endif /* CONFIG_USB_STORAGE */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 738 | ); |
| 739 | |
| 740 | |
Julius Werner | d404670 | 2013-02-28 18:08:40 +0000 | [diff] [blame] | 741 | #ifdef CONFIG_USB_STORAGE |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 742 | U_BOOT_CMD( |
| 743 | usbboot, 3, 1, do_usbboot, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 744 | "boot from USB device", |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 745 | "loadAddr dev:part" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 746 | ); |
Julius Werner | d404670 | 2013-02-28 18:08:40 +0000 | [diff] [blame] | 747 | #endif /* CONFIG_USB_STORAGE */ |