usb.c 18 KB

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