]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - test/dm/cmd_dm.c
dm: test: replace dm_scan_dt() by of dm_extended_scan_fdt() in dm_do_test
[people/ms/u-boot.git] / test / dm / cmd_dm.c
index 79a674efcc5bc35559698cad5413723a7308d4dc..a3c5971a8b1466ce773fe634f2076f79c65bd0cf 100644 (file)
  */
 
 #include <common.h>
+#include <command.h>
 #include <dm.h>
 #include <malloc.h>
+#include <mapmem.h>
 #include <errno.h>
 #include <asm/io.h>
 #include <dm/root.h>
-#include <dm/test.h>
-#include <dm/uclass-internal.h>
-
-static void show_devices(struct udevice *dev, int depth, int last_flag)
-{
-       int i, is_last;
-       struct udevice *child;
-       char class_name[12];
-
-       /* print the first 11 characters to not break the tree-format. */
-       strlcpy(class_name, dev->uclass->uc_drv->name, sizeof(class_name));
-       printf(" %-11s [ %c ]    ", class_name,
-              dev->flags & DM_FLAG_ACTIVATED ? '+' : ' ');
-
-       for (i = depth; i >= 0; i--) {
-               is_last = (last_flag >> i) & 1;
-               if (i) {
-                       if (is_last)
-                               printf("    ");
-                       else
-                               printf("|   ");
-               } else {
-                       if (is_last)
-                               printf("`-- ");
-                       else
-                               printf("|-- ");
-               }
-       }
-
-       printf("%s\n", dev->name);
-
-       list_for_each_entry(child, &dev->child_head, sibling_node) {
-               is_last = list_is_last(&child->sibling_node, &dev->child_head);
-               show_devices(child, depth + 1, (last_flag << 1) | is_last);
-       }
-}
+#include <dm/util.h>
 
 static int do_dm_dump_all(cmd_tbl_t *cmdtp, int flag, int argc,
                          char * const argv[])
 {
-       struct udevice *root;
-
-       root = dm_root();
-       if (root) {
-               printf(" Class       Probed   Name\n");
-               printf("----------------------------------------\n");
-               show_devices(root, -1, 0);
-       }
+       dm_dump_all();
 
        return 0;
 }
 
-/**
- * dm_display_line() - Display information about a single device
- *
- * Displays a single line of information with an option prefix
- *
- * @dev:       Device to display
- */
-static void dm_display_line(struct udevice *dev)
-{
-       printf("- %c %s @ %08lx",
-              dev->flags & DM_FLAG_ACTIVATED ? '*' : ' ',
-              dev->name, (ulong)map_to_sysmem(dev));
-       if (dev->req_seq != -1)
-               printf(", %d", dev->req_seq);
-       puts("\n");
-}
-
 static int do_dm_dump_uclass(cmd_tbl_t *cmdtp, int flag, int argc,
                             char * const argv[])
 {
-       struct uclass *uc;
-       int ret;
-       int id;
-
-       for (id = 0; id < UCLASS_COUNT; id++) {
-               struct udevice *dev;
-
-               ret = uclass_get(id, &uc);
-               if (ret)
-                       continue;
-
-               printf("uclass %d: %s\n", id, uc->uc_drv->name);
-               if (list_empty(&uc->dev_head))
-                       continue;
-               list_for_each_entry(dev, &uc->dev_head, uclass_node) {
-                       dm_display_line(dev);
-               }
-               puts("\n");
-       }
+       dm_dump_uclass();
 
        return 0;
 }
 
-#ifdef CONFIG_DM_TEST
-static int do_dm_test(cmd_tbl_t *cmdtp, int flag, int argc,
-                         char * const argv[])
+static int do_dm_dump_devres(cmd_tbl_t *cmdtp, int flag, int argc,
+                            char * const argv[])
 {
-       return dm_test_main();
+       dm_dump_devres();
+
+       return 0;
 }
-#define TEST_HELP "\ndm test         Run tests"
-#else
-#define TEST_HELP
-#endif
 
 static cmd_tbl_t test_commands[] = {
        U_BOOT_CMD_MKENT(tree, 0, 1, do_dm_dump_all, "", ""),
        U_BOOT_CMD_MKENT(uclass, 1, 1, do_dm_dump_uclass, "", ""),
-#ifdef CONFIG_DM_TEST
-       U_BOOT_CMD_MKENT(test, 1, 1, do_dm_test, "", ""),
-#endif
+       U_BOOT_CMD_MKENT(devres, 1, 1, do_dm_dump_devres, "", ""),
 };
 
+static __maybe_unused void dm_reloc(void)
+{
+       static int relocated;
+
+       if (!relocated) {
+               fixup_cmdtable(test_commands, ARRAY_SIZE(test_commands));
+               relocated = 1;
+       }
+}
+
 static int do_dm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
        cmd_tbl_t *test_cmd;
        int ret;
 
-       if (argc != 2)
+#ifdef CONFIG_NEEDS_MANUAL_RELOC
+       dm_reloc();
+#endif
+
+       if (argc < 2)
                return CMD_RET_USAGE;
        test_cmd = find_cmd_tbl(argv[1], test_commands,
                                ARRAY_SIZE(test_commands));
@@ -147,9 +81,9 @@ static int do_dm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 }
 
 U_BOOT_CMD(
-       dm,     2,      1,      do_dm,
+       dm,     3,      1,      do_dm,
        "Driver model low level access",
        "tree         Dump driver model tree ('*' = activated)\n"
-       "dm uclass        Dump list of instances for each uclass"
-       TEST_HELP
+       "dm uclass        Dump list of instances for each uclass\n"
+       "dm devres        Dump list of device resources for each device"
 );