aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2015-11-08 23:47:51 -0700
committerSimon Glass <sjg@chromium.org>2015-11-19 20:27:51 -0700
commit45bfa47e123cdb0df8e273e3f0c84907c7394f6a (patch)
treeebc3274067b42a2c76cc0c055754fd74da36321c
parent9ce8b40206f4f96de6164c2a0c0a725c9323c4b9 (diff)
downloadu-boot-45bfa47e123cdb0df8e273e3f0c84907c7394f6a.zip
u-boot-45bfa47e123cdb0df8e273e3f0c84907c7394f6a.tar.gz
u-boot-45bfa47e123cdb0df8e273e3f0c84907c7394f6a.tar.bz2
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>
-rw-r--r--common/cmd_usb.c58
-rw-r--r--include/usb.h8
2 files changed, 41 insertions, 25 deletions
diff --git a/common/cmd_usb.c b/common/cmd_usb.c
index c2d9803..a540b42 100644
--- a/common/cmd_usb.c
+++ b/common/cmd_usb.c
@@ -429,7 +429,7 @@ static void usb_show_tree_graph(struct usb_device *dev, char *pre)
}
/* main routine for the tree command */
-static void usb_show_tree(struct usb_device *dev)
+static void usb_show_subtree(struct usb_device *dev)
{
char preamble[32];
@@ -437,6 +437,37 @@ static void usb_show_tree(struct usb_device *dev)
usb_show_tree_graph(dev, &preamble[0]);
}
+void usb_show_tree(void)
+{
+#ifdef CONFIG_DM_USB
+ struct udevice *bus;
+
+ for (uclass_first_device(UCLASS_USB, &bus);
+ bus;
+ uclass_next_device(&bus)) {
+ struct usb_device *udev;
+ struct udevice *dev;
+
+ device_find_first_child(bus, &dev);
+ if (dev && device_active(dev)) {
+ udev = dev_get_parent_priv(dev);
+ usb_show_subtree(udev);
+ }
+ }
+#else
+ struct usb_device *udev;
+ int i;
+
+ for (i = 0; i < USB_MAX_DEVICE; i++) {
+ udev = usb_get_dev_index(i);
+ if (udev == NULL)
+ break;
+ if (udev->parent == NULL)
+ usb_show_subtree(udev);
+ }
+#endif
+}
+
static int usb_test(struct usb_device *dev, int port, char* arg)
{
int mode;
@@ -631,30 +662,7 @@ static int do_usb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
}
if (strncmp(argv[1], "tree", 4) == 0) {
puts("USB device tree:\n");
-#ifdef CONFIG_DM_USB
- struct udevice *bus;
-
- for (uclass_first_device(UCLASS_USB, &bus);
- bus;
- uclass_next_device(&bus)) {
- struct usb_device *udev;
- struct udevice *dev;
-
- device_find_first_child(bus, &dev);
- if (dev && device_active(dev)) {
- udev = dev_get_parent_priv(dev);
- usb_show_tree(udev);
- }
- }
-#else
- for (i = 0; i < USB_MAX_DEVICE; i++) {
- udev = usb_get_dev_index(i);
- if (udev == NULL)
- break;
- if (udev->parent == NULL)
- usb_show_tree(udev);
- }
-#endif
+ usb_show_tree();
return 0;
}
if (strncmp(argv[1], "inf", 3) == 0) {
diff --git a/include/usb.h b/include/usb.h
index 3d0facb..a09c7f1 100644
--- a/include/usb.h
+++ b/include/usb.h
@@ -957,4 +957,12 @@ int usb_emul_find(struct udevice *bus, ulong pipe, struct udevice **emulp);
*/
void usb_emul_reset(struct udevice *dev);
+/**
+ * usb_show_tree() - show the USB device tree
+ *
+ * This shows a list of active USB devices along with basic information about
+ * each.
+ */
+void usb_show_tree(void);
+
#endif /*_USB_H_ */