Commit 45bfa47e123cdb0df8e273e3f0c84907c7394f6a
1 parent
9ce8b40206
Exists in
v2017.01-smarct4x
and in
30 other branches
usb: Refactor USB tree output code for testing
Allow the 'usb tree' command to be used from test code, so that we can verify that it works correctly. Signed-off-by: Simon Glass <sjg@chromium.org>
Showing 2 changed files with 41 additions and 25 deletions Side-by-side Diff
common/cmd_usb.c
... | ... | @@ -429,7 +429,7 @@ |
429 | 429 | } |
430 | 430 | |
431 | 431 | /* main routine for the tree command */ |
432 | -static void usb_show_tree(struct usb_device *dev) | |
432 | +static void usb_show_subtree(struct usb_device *dev) | |
433 | 433 | { |
434 | 434 | char preamble[32]; |
435 | 435 | |
... | ... | @@ -437,6 +437,37 @@ |
437 | 437 | usb_show_tree_graph(dev, &preamble[0]); |
438 | 438 | } |
439 | 439 | |
440 | +void usb_show_tree(void) | |
441 | +{ | |
442 | +#ifdef CONFIG_DM_USB | |
443 | + struct udevice *bus; | |
444 | + | |
445 | + for (uclass_first_device(UCLASS_USB, &bus); | |
446 | + bus; | |
447 | + uclass_next_device(&bus)) { | |
448 | + struct usb_device *udev; | |
449 | + struct udevice *dev; | |
450 | + | |
451 | + device_find_first_child(bus, &dev); | |
452 | + if (dev && device_active(dev)) { | |
453 | + udev = dev_get_parent_priv(dev); | |
454 | + usb_show_subtree(udev); | |
455 | + } | |
456 | + } | |
457 | +#else | |
458 | + struct usb_device *udev; | |
459 | + int i; | |
460 | + | |
461 | + for (i = 0; i < USB_MAX_DEVICE; i++) { | |
462 | + udev = usb_get_dev_index(i); | |
463 | + if (udev == NULL) | |
464 | + break; | |
465 | + if (udev->parent == NULL) | |
466 | + usb_show_subtree(udev); | |
467 | + } | |
468 | +#endif | |
469 | +} | |
470 | + | |
440 | 471 | static int usb_test(struct usb_device *dev, int port, char* arg) |
441 | 472 | { |
442 | 473 | int mode; |
... | ... | @@ -631,30 +662,7 @@ |
631 | 662 | } |
632 | 663 | if (strncmp(argv[1], "tree", 4) == 0) { |
633 | 664 | puts("USB device tree:\n"); |
634 | -#ifdef CONFIG_DM_USB | |
635 | - struct udevice *bus; | |
636 | - | |
637 | - for (uclass_first_device(UCLASS_USB, &bus); | |
638 | - bus; | |
639 | - uclass_next_device(&bus)) { | |
640 | - struct usb_device *udev; | |
641 | - struct udevice *dev; | |
642 | - | |
643 | - device_find_first_child(bus, &dev); | |
644 | - if (dev && device_active(dev)) { | |
645 | - udev = dev_get_parent_priv(dev); | |
646 | - usb_show_tree(udev); | |
647 | - } | |
648 | - } | |
649 | -#else | |
650 | - for (i = 0; i < USB_MAX_DEVICE; i++) { | |
651 | - udev = usb_get_dev_index(i); | |
652 | - if (udev == NULL) | |
653 | - break; | |
654 | - if (udev->parent == NULL) | |
655 | - usb_show_tree(udev); | |
656 | - } | |
657 | -#endif | |
665 | + usb_show_tree(); | |
658 | 666 | return 0; |
659 | 667 | } |
660 | 668 | if (strncmp(argv[1], "inf", 3) == 0) { |
include/usb.h
... | ... | @@ -957,5 +957,13 @@ |
957 | 957 | */ |
958 | 958 | void usb_emul_reset(struct udevice *dev); |
959 | 959 | |
960 | +/** | |
961 | + * usb_show_tree() - show the USB device tree | |
962 | + * | |
963 | + * This shows a list of active USB devices along with basic information about | |
964 | + * each. | |
965 | + */ | |
966 | +void usb_show_tree(void); | |
967 | + | |
960 | 968 | #endif /*_USB_H_ */ |