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