2 * Copyright (c) 2013 Google, Inc
5 * Marek Vasut <marex@denx.de>
7 * SPDX-License-Identifier: GPL-2.0+
17 #include <dm/uclass-internal.h>
19 static void show_devices(struct udevice *dev, int depth, int last_flag)
22 struct udevice *child;
25 /* print the first 11 characters to not break the tree-format. */
26 strlcpy(class_name, dev->uclass->uc_drv->name, sizeof(class_name));
27 printf(" %-11s [ %c ] ", class_name,
28 dev->flags & DM_FLAG_ACTIVATED ? '+' : ' ');
30 for (i = depth; i >= 0; i--) {
31 is_last = (last_flag >> i) & 1;
45 printf("%s\n", dev->name);
47 list_for_each_entry(child, &dev->child_head, sibling_node) {
48 is_last = list_is_last(&child->sibling_node, &dev->child_head);
49 show_devices(child, depth + 1, (last_flag << 1) | is_last);
53 static int do_dm_dump_all(cmd_tbl_t *cmdtp, int flag, int argc,
60 printf(" Class Probed Name\n");
61 printf("----------------------------------------\n");
62 show_devices(root, -1, 0);
69 * dm_display_line() - Display information about a single device
71 * Displays a single line of information with an option prefix
73 * @dev: Device to display
75 static void dm_display_line(struct udevice *dev)
77 printf("- %c %s @ %08lx",
78 dev->flags & DM_FLAG_ACTIVATED ? '*' : ' ',
79 dev->name, (ulong)map_to_sysmem(dev));
80 if (dev->seq != -1 || dev->req_seq != -1)
81 printf(", seq %d, (req %d)", dev->seq, dev->req_seq);
85 static int do_dm_dump_uclass(cmd_tbl_t *cmdtp, int flag, int argc,
92 for (id = 0; id < UCLASS_COUNT; id++) {
95 ret = uclass_get(id, &uc);
99 printf("uclass %d: %s\n", id, uc->uc_drv->name);
100 if (list_empty(&uc->dev_head))
102 list_for_each_entry(dev, &uc->dev_head, uclass_node) {
103 dm_display_line(dev);
111 static cmd_tbl_t test_commands[] = {
112 U_BOOT_CMD_MKENT(tree, 0, 1, do_dm_dump_all, "", ""),
113 U_BOOT_CMD_MKENT(uclass, 1, 1, do_dm_dump_uclass, "", ""),
116 static int do_dm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
122 return CMD_RET_USAGE;
123 test_cmd = find_cmd_tbl(argv[1], test_commands,
124 ARRAY_SIZE(test_commands));
127 if (!test_cmd || argc > test_cmd->maxargs)
128 return CMD_RET_USAGE;
130 ret = test_cmd->cmd(test_cmd, flag, argc, argv);
132 return cmd_process_error(test_cmd, ret);
137 "Driver model low level access",
138 "tree Dump driver model tree ('*' = activated)\n"
139 "dm uclass Dump list of instances for each uclass"