usb.c 17 KB

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