usb.c 18 KB

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