2 * Copyright (c) 2013 Google, Inc
5 * Marek Vasut <marex@denx.de>
7 * SPDX-License-Identifier: GPL-2.0+
18 #include <dm/uclass-internal.h>
20 static void show_devices(struct udevice *dev, int depth, int last_flag)
23 struct udevice *child;
26 /* print the first 11 characters to not break the tree-format. */
27 strlcpy(class_name, dev->uclass->uc_drv->name, sizeof(class_name));
28 printf(" %-11s [ %c ] ", class_name,
29 dev->flags & DM_FLAG_ACTIVATED ? '+' : ' ');
31 for (i = depth; i >= 0; i--) {
32 is_last = (last_flag >> i) & 1;
46 printf("%s\n", dev->name);
48 list_for_each_entry(child, &dev->child_head, sibling_node) {
49 is_last = list_is_last(&child->sibling_node, &dev->child_head);
50 show_devices(child, depth + 1, (last_flag << 1) | is_last);
54 static int do_dm_dump_all(cmd_tbl_t *cmdtp, int flag, int argc,
61 printf(" Class Probed Name\n");
62 printf("----------------------------------------\n");
63 show_devices(root, -1, 0);
70 * dm_display_line() - Display information about a single device
72 * Displays a single line of information with an option prefix
74 * @dev: Device to display
76 static void dm_display_line(struct udevice *dev)
78 printf("- %c %s @ %08lx",
79 dev->flags & DM_FLAG_ACTIVATED ? '*' : ' ',
80 dev->name, (ulong)map_to_sysmem(dev));
81 if (dev->seq != -1 || dev->req_seq != -1)
82 printf(", seq %d, (req %d)", dev->seq, dev->req_seq);
86 static int do_dm_dump_uclass(cmd_tbl_t *cmdtp, int flag, int argc,
93 for (id = 0; id < UCLASS_COUNT; id++) {
96 ret = uclass_get(id, &uc);
100 printf("uclass %d: %s\n", id, uc->uc_drv->name);
101 if (list_empty(&uc->dev_head))
103 list_for_each_entry(dev, &uc->dev_head, uclass_node) {
104 dm_display_line(dev);
112 #ifdef CONFIG_DM_TEST
113 static int do_dm_test(cmd_tbl_t *cmdtp, int flag, int argc,
116 const char *test_name = NULL;
121 return dm_test_main(test_name);
123 #define TEST_HELP "\ndm test Run tests"
128 static cmd_tbl_t test_commands[] = {
129 U_BOOT_CMD_MKENT(tree, 0, 1, do_dm_dump_all, "", ""),
130 U_BOOT_CMD_MKENT(uclass, 1, 1, do_dm_dump_uclass, "", ""),
131 #ifdef CONFIG_DM_TEST
132 U_BOOT_CMD_MKENT(test, 1, 1, do_dm_test, "", ""),
136 static int do_dm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
142 return CMD_RET_USAGE;
143 test_cmd = find_cmd_tbl(argv[1], test_commands,
144 ARRAY_SIZE(test_commands));
147 if (!test_cmd || argc > test_cmd->maxargs)
148 return CMD_RET_USAGE;
150 ret = test_cmd->cmd(test_cmd, flag, argc, argv);
152 return cmd_process_error(test_cmd, ret);
157 "Driver model low level access",
158 "tree Dump driver model tree ('*' = activated)\n"
159 "dm uclass Dump list of instances for each uclass"