usb.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  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 <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 const char *portspeed(int speed)
  297. {
  298. switch (speed) {
  299. case USB_SPEED_SUPER:
  300. return "5 Gb/s";
  301. case USB_SPEED_HIGH:
  302. return "480 Mb/s";
  303. case USB_SPEED_LOW:
  304. return "1.5 Mb/s";
  305. default:
  306. return "12 Mb/s";
  307. }
  308. }
  309. /* shows the device tree recursively */
  310. static void usb_show_tree_graph(struct usb_device *dev, char *pre)
  311. {
  312. int index;
  313. int has_child, last_child;
  314. index = strlen(pre);
  315. printf(" %s", pre);
  316. #ifdef CONFIG_DM_USB
  317. has_child = device_has_active_children(dev->dev);
  318. if (device_get_uclass_id(dev->dev) == UCLASS_MASS_STORAGE) {
  319. struct udevice *child;
  320. for (device_find_first_child(dev->dev, &child);
  321. child;
  322. device_find_next_child(&child)) {
  323. if (device_get_uclass_id(child) == UCLASS_BLK)
  324. has_child = 0;
  325. }
  326. }
  327. #else
  328. /* check if the device has connected children */
  329. int i;
  330. has_child = 0;
  331. for (i = 0; i < dev->maxchild; i++) {
  332. if (dev->children[i] != NULL)
  333. has_child = 1;
  334. }
  335. #endif
  336. /* check if we are the last one */
  337. #ifdef CONFIG_DM_USB
  338. /* Not the root of the usb tree? */
  339. if (device_get_uclass_id(dev->dev->parent) != UCLASS_USB) {
  340. last_child = device_is_last_sibling(dev->dev);
  341. #else
  342. if (dev->parent != NULL) { /* not root? */
  343. last_child = 1;
  344. for (i = 0; i < dev->parent->maxchild; i++) {
  345. /* search for children */
  346. if (dev->parent->children[i] == dev) {
  347. /* found our pointer, see if we have a
  348. * little sister
  349. */
  350. while (i++ < dev->parent->maxchild) {
  351. if (dev->parent->children[i] != NULL) {
  352. /* found a sister */
  353. last_child = 0;
  354. break;
  355. } /* if */
  356. } /* while */
  357. } /* device found */
  358. } /* for all children of the parent */
  359. #endif
  360. printf("\b+-");
  361. /* correct last child */
  362. if (last_child && index)
  363. pre[index-1] = ' ';
  364. } /* if not root hub */
  365. else
  366. printf(" ");
  367. printf("%d ", dev->devnum);
  368. pre[index++] = ' ';
  369. pre[index++] = has_child ? '|' : ' ';
  370. pre[index] = 0;
  371. printf(" %s (%s, %dmA)\n", usb_get_class_desc(
  372. dev->config.if_desc[0].desc.bInterfaceClass),
  373. portspeed(dev->speed),
  374. dev->config.desc.bMaxPower * 2);
  375. if (strlen(dev->mf) || strlen(dev->prod) || strlen(dev->serial))
  376. printf(" %s %s %s %s\n", pre, dev->mf, dev->prod, dev->serial);
  377. printf(" %s\n", pre);
  378. #ifdef CONFIG_DM_USB
  379. struct udevice *child;
  380. for (device_find_first_child(dev->dev, &child);
  381. child;
  382. device_find_next_child(&child)) {
  383. struct usb_device *udev;
  384. if (!device_active(child))
  385. continue;
  386. udev = dev_get_parent_priv(child);
  387. /*
  388. * Ignore emulators and block child devices, we only want
  389. * real devices
  390. */
  391. if ((device_get_uclass_id(child) != UCLASS_USB_EMUL) &&
  392. (device_get_uclass_id(child) != UCLASS_BLK)) {
  393. usb_show_tree_graph(udev, pre);
  394. pre[index] = 0;
  395. }
  396. }
  397. #else
  398. if (dev->maxchild > 0) {
  399. for (i = 0; i < dev->maxchild; i++) {
  400. if (dev->children[i] != NULL) {
  401. usb_show_tree_graph(dev->children[i], pre);
  402. pre[index] = 0;
  403. }
  404. }
  405. }
  406. #endif
  407. }
  408. /* main routine for the tree command */
  409. static void usb_show_subtree(struct usb_device *dev)
  410. {
  411. char preamble[32];
  412. memset(preamble, '\0', sizeof(preamble));
  413. usb_show_tree_graph(dev, &preamble[0]);
  414. }
  415. #ifdef CONFIG_DM_USB
  416. typedef void (*usb_dev_func_t)(struct usb_device *udev);
  417. static void usb_for_each_root_dev(usb_dev_func_t func)
  418. {
  419. struct udevice *bus;
  420. for (uclass_find_first_device(UCLASS_USB, &bus);
  421. bus;
  422. uclass_find_next_device(&bus)) {
  423. struct usb_device *udev;
  424. struct udevice *dev;
  425. if (!device_active(bus))
  426. continue;
  427. device_find_first_child(bus, &dev);
  428. if (dev && device_active(dev)) {
  429. udev = dev_get_parent_priv(dev);
  430. func(udev);
  431. }
  432. }
  433. }
  434. #endif
  435. void usb_show_tree(void)
  436. {
  437. #ifdef CONFIG_DM_USB
  438. usb_for_each_root_dev(usb_show_subtree);
  439. #else
  440. struct usb_device *udev;
  441. int i;
  442. for (i = 0; i < USB_MAX_DEVICE; i++) {
  443. udev = usb_get_dev_index(i);
  444. if (udev == NULL)
  445. break;
  446. if (udev->parent == NULL)
  447. usb_show_subtree(udev);
  448. }
  449. #endif
  450. }
  451. static int usb_test(struct usb_device *dev, int port, char* arg)
  452. {
  453. int mode;
  454. if (port > dev->maxchild) {
  455. printf("Device is no hub or does not have %d ports.\n", port);
  456. return 1;
  457. }
  458. switch (arg[0]) {
  459. case 'J':
  460. case 'j':
  461. printf("Setting Test_J mode");
  462. mode = USB_TEST_MODE_J;
  463. break;
  464. case 'K':
  465. case 'k':
  466. printf("Setting Test_K mode");
  467. mode = USB_TEST_MODE_K;
  468. break;
  469. case 'S':
  470. case 's':
  471. printf("Setting Test_SE0_NAK mode");
  472. mode = USB_TEST_MODE_SE0_NAK;
  473. break;
  474. case 'P':
  475. case 'p':
  476. printf("Setting Test_Packet mode");
  477. mode = USB_TEST_MODE_PACKET;
  478. break;
  479. case 'F':
  480. case 'f':
  481. printf("Setting Test_Force_Enable mode");
  482. mode = USB_TEST_MODE_FORCE_ENABLE;
  483. break;
  484. default:
  485. printf("Unrecognized test mode: %s\nAvailable modes: "
  486. "J, K, S[E0_NAK], P[acket], F[orce_Enable]\n", arg);
  487. return 1;
  488. }
  489. if (port)
  490. printf(" on downstream facing port %d...\n", port);
  491. else
  492. printf(" on upstream facing port...\n");
  493. if (usb_control_msg(dev, usb_sndctrlpipe(dev, 0), USB_REQ_SET_FEATURE,
  494. port ? USB_RT_PORT : USB_RECIP_DEVICE,
  495. port ? USB_PORT_FEAT_TEST : USB_FEAT_TEST,
  496. (mode << 8) | port,
  497. NULL, 0, USB_CNTL_TIMEOUT) == -1) {
  498. printf("Error during SET_FEATURE.\n");
  499. return 1;
  500. } else {
  501. printf("Test mode successfully set. Use 'usb start' "
  502. "to return to normal operation.\n");
  503. return 0;
  504. }
  505. }
  506. /******************************************************************************
  507. * usb boot command intepreter. Derived from diskboot
  508. */
  509. #ifdef CONFIG_USB_STORAGE
  510. static int do_usbboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  511. {
  512. return common_diskboot(cmdtp, "usb", argc, argv);
  513. }
  514. #endif /* CONFIG_USB_STORAGE */
  515. static int do_usb_stop_keyboard(int force)
  516. {
  517. #if !defined CONFIG_DM_USB && defined CONFIG_USB_KEYBOARD
  518. if (usb_kbd_deregister(force) != 0) {
  519. printf("USB not stopped: usbkbd still using USB\n");
  520. return 1;
  521. }
  522. #endif
  523. return 0;
  524. }
  525. static void do_usb_start(void)
  526. {
  527. bootstage_mark_name(BOOTSTAGE_ID_USB_START, "usb_start");
  528. if (usb_init() < 0)
  529. return;
  530. /* Driver model will probe the devices as they are found */
  531. # ifdef CONFIG_USB_STORAGE
  532. /* try to recognize storage devices immediately */
  533. usb_stor_curr_dev = usb_stor_scan(1);
  534. # endif
  535. #ifndef CONFIG_DM_USB
  536. # ifdef CONFIG_USB_KEYBOARD
  537. drv_usb_kbd_init();
  538. # endif
  539. #endif /* !CONFIG_DM_USB */
  540. #ifdef CONFIG_USB_HOST_ETHER
  541. # ifdef CONFIG_DM_ETH
  542. # ifndef CONFIG_DM_USB
  543. # error "You must use CONFIG_DM_USB if you want to use CONFIG_USB_HOST_ETHER with CONFIG_DM_ETH"
  544. # endif
  545. # else
  546. /* try to recognize ethernet devices immediately */
  547. usb_ether_curr_dev = usb_host_eth_scan(1);
  548. # endif
  549. #endif
  550. }
  551. #ifdef CONFIG_DM_USB
  552. static void usb_show_info(struct usb_device *udev)
  553. {
  554. struct udevice *child;
  555. usb_display_desc(udev);
  556. usb_display_config(udev);
  557. for (device_find_first_child(udev->dev, &child);
  558. child;
  559. device_find_next_child(&child)) {
  560. if (device_active(child) &&
  561. (device_get_uclass_id(child) != UCLASS_USB_EMUL) &&
  562. (device_get_uclass_id(child) != UCLASS_BLK)) {
  563. udev = dev_get_parent_priv(child);
  564. usb_show_info(udev);
  565. }
  566. }
  567. }
  568. #endif
  569. /******************************************************************************
  570. * usb command intepreter
  571. */
  572. static int do_usb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  573. {
  574. struct usb_device *udev = NULL;
  575. int i;
  576. extern char usb_started;
  577. if (argc < 2)
  578. return CMD_RET_USAGE;
  579. if (strncmp(argv[1], "start", 5) == 0) {
  580. if (usb_started)
  581. return 0; /* Already started */
  582. printf("starting USB...\n");
  583. do_usb_start();
  584. return 0;
  585. }
  586. if (strncmp(argv[1], "reset", 5) == 0) {
  587. printf("resetting USB...\n");
  588. if (do_usb_stop_keyboard(1) != 0)
  589. return 1;
  590. usb_stop();
  591. do_usb_start();
  592. return 0;
  593. }
  594. if (strncmp(argv[1], "stop", 4) == 0) {
  595. if (argc != 2)
  596. console_assign(stdin, "serial");
  597. if (do_usb_stop_keyboard(0) != 0)
  598. return 1;
  599. printf("stopping USB..\n");
  600. usb_stop();
  601. return 0;
  602. }
  603. if (!usb_started) {
  604. printf("USB is stopped. Please issue 'usb start' first.\n");
  605. return 1;
  606. }
  607. if (strncmp(argv[1], "tree", 4) == 0) {
  608. puts("USB device tree:\n");
  609. usb_show_tree();
  610. return 0;
  611. }
  612. if (strncmp(argv[1], "inf", 3) == 0) {
  613. if (argc == 2) {
  614. #ifdef CONFIG_DM_USB
  615. usb_for_each_root_dev(usb_show_info);
  616. #else
  617. int d;
  618. for (d = 0; d < USB_MAX_DEVICE; d++) {
  619. udev = usb_get_dev_index(d);
  620. if (udev == NULL)
  621. break;
  622. usb_display_desc(udev);
  623. usb_display_config(udev);
  624. }
  625. #endif
  626. return 0;
  627. } else {
  628. /*
  629. * With driver model this isn't right since we can
  630. * have multiple controllers and the device numbering
  631. * starts at 1 on each bus.
  632. */
  633. i = simple_strtoul(argv[2], NULL, 10);
  634. printf("config for device %d\n", i);
  635. udev = usb_find_device(i);
  636. if (udev == NULL) {
  637. printf("*** No device available ***\n");
  638. return 0;
  639. } else {
  640. usb_display_desc(udev);
  641. usb_display_config(udev);
  642. }
  643. }
  644. return 0;
  645. }
  646. if (strncmp(argv[1], "test", 4) == 0) {
  647. if (argc < 5)
  648. return CMD_RET_USAGE;
  649. i = simple_strtoul(argv[2], NULL, 10);
  650. udev = usb_find_device(i);
  651. if (udev == NULL) {
  652. printf("Device %d does not exist.\n", i);
  653. return 1;
  654. }
  655. i = simple_strtoul(argv[3], NULL, 10);
  656. return usb_test(udev, i, argv[4]);
  657. }
  658. #ifdef CONFIG_USB_STORAGE
  659. if (strncmp(argv[1], "stor", 4) == 0)
  660. return usb_stor_info();
  661. return blk_common_cmd(argc, argv, IF_TYPE_USB, &usb_stor_curr_dev);
  662. #else
  663. return CMD_RET_USAGE;
  664. #endif /* CONFIG_USB_STORAGE */
  665. }
  666. U_BOOT_CMD(
  667. usb, 5, 1, do_usb,
  668. "USB sub-system",
  669. "start - start (scan) USB controller\n"
  670. "usb reset - reset (rescan) USB controller\n"
  671. "usb stop [f] - stop USB [f]=force stop\n"
  672. "usb tree - show USB device tree\n"
  673. "usb info [dev] - show available USB devices\n"
  674. "usb test [dev] [port] [mode] - set USB 2.0 test mode\n"
  675. " (specify port 0 to indicate the device's upstream port)\n"
  676. " Available modes: J, K, S[E0_NAK], P[acket], F[orce_Enable]\n"
  677. #ifdef CONFIG_USB_STORAGE
  678. "usb storage - show details of USB storage devices\n"
  679. "usb dev [dev] - show or set current USB storage device\n"
  680. "usb part [dev] - print partition table of one or all USB storage"
  681. " devices\n"
  682. "usb read addr blk# cnt - read `cnt' blocks starting at block `blk#'\n"
  683. " to memory address `addr'\n"
  684. "usb write addr blk# cnt - write `cnt' blocks starting at block `blk#'\n"
  685. " from memory address `addr'"
  686. #endif /* CONFIG_USB_STORAGE */
  687. );
  688. #ifdef CONFIG_USB_STORAGE
  689. U_BOOT_CMD(
  690. usbboot, 3, 1, do_usbboot,
  691. "boot from USB device",
  692. "loadAddr dev:part"
  693. );
  694. #endif /* CONFIG_USB_STORAGE */