usb.c 18 KB

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