]>
git.ipfire.org Git - people/ms/u-boot.git/blob - test/dm/cmd_dm.c
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
->req_seq
!= -1)
81 printf(", %d", 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 #ifdef CONFIG_DM_TEST
112 static int do_dm_test(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
115 return dm_test_main();
117 #define TEST_HELP "\ndm test Run tests"
122 static cmd_tbl_t test_commands
[] = {
123 U_BOOT_CMD_MKENT(tree
, 0, 1, do_dm_dump_all
, "", ""),
124 U_BOOT_CMD_MKENT(uclass
, 1, 1, do_dm_dump_uclass
, "", ""),
125 #ifdef CONFIG_DM_TEST
126 U_BOOT_CMD_MKENT(test
, 1, 1, do_dm_test
, "", ""),
130 static int do_dm(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
136 return CMD_RET_USAGE
;
137 test_cmd
= find_cmd_tbl(argv
[1], test_commands
,
138 ARRAY_SIZE(test_commands
));
141 if (!test_cmd
|| argc
> test_cmd
->maxargs
)
142 return CMD_RET_USAGE
;
144 ret
= test_cmd
->cmd(test_cmd
, flag
, argc
, argv
);
146 return cmd_process_error(test_cmd
, ret
);
151 "Driver model low level access",
152 "tree Dump driver model tree ('*' = activated)\n"
153 "dm uclass Dump list of instances for each uclass"