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