usb.c 18 KB

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