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