usb.c 17 KB

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