Commit 19198f8b013b70ae6f497422e5418cc009dea145
Exists in
v2017.01-smarct4x
and in
40 other branches
Merge branch 'master' of git://git.denx.de/u-boot-dm
Showing 2 changed files Inline Diff
include/dm.h
1 | /* | 1 | /* |
2 | * Copyright (c) 2013 Google, Inc | 2 | * Copyright (c) 2013 Google, Inc |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: GPL-2.0+ | 4 | * SPDX-License-Identifier: GPL-2.0+ |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #ifndef _DM_H_ | 7 | #ifndef _DM_H_ |
8 | #define _DM_H | 8 | #define _DM_H_ |
9 | 9 | ||
10 | #include <dm/device.h> | 10 | #include <dm/device.h> |
11 | #include <dm/platdata.h> | 11 | #include <dm/platdata.h> |
12 | #include <dm/uclass.h> | 12 | #include <dm/uclass.h> |
13 | 13 | ||
14 | #endif | 14 | #endif |
15 | 15 |
test/dm/cmd_dm.c
1 | /* | 1 | /* |
2 | * Copyright (c) 2013 Google, Inc | 2 | * Copyright (c) 2013 Google, Inc |
3 | * | 3 | * |
4 | * (C) Copyright 2012 | 4 | * (C) Copyright 2012 |
5 | * Marek Vasut <marex@denx.de> | 5 | * Marek Vasut <marex@denx.de> |
6 | * | 6 | * |
7 | * SPDX-License-Identifier: GPL-2.0+ | 7 | * SPDX-License-Identifier: GPL-2.0+ |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <common.h> | 10 | #include <common.h> |
11 | #include <dm.h> | 11 | #include <dm.h> |
12 | #include <malloc.h> | 12 | #include <malloc.h> |
13 | #include <errno.h> | 13 | #include <errno.h> |
14 | #include <asm/io.h> | 14 | #include <asm/io.h> |
15 | #include <dm/root.h> | 15 | #include <dm/root.h> |
16 | #include <dm/test.h> | 16 | #include <dm/test.h> |
17 | #include <dm/uclass-internal.h> | 17 | #include <dm/uclass-internal.h> |
18 | 18 | ||
19 | static int display_succ(struct udevice *in, char *buf) | 19 | static int display_succ(struct udevice *in, char *buf) |
20 | { | 20 | { |
21 | int len; | 21 | int len; |
22 | int ip = 0; | 22 | int ip = 0; |
23 | char local[16]; | 23 | char local[16]; |
24 | struct udevice *pos, *n, *prev = NULL; | 24 | struct udevice *pos, *n, *prev = NULL; |
25 | 25 | ||
26 | printf("%s- %s @ %08lx", buf, in->name, (ulong)map_to_sysmem(in)); | 26 | printf("%s- %c %s @ %08lx", buf, |
27 | if (in->flags & DM_FLAG_ACTIVATED) | 27 | in->flags & DM_FLAG_ACTIVATED ? '*' : ' ', |
28 | puts(" - activated"); | 28 | in->name, (ulong)map_to_sysmem(in)); |
29 | puts("\n"); | 29 | puts("\n"); |
30 | 30 | ||
31 | if (list_empty(&in->child_head)) | 31 | if (list_empty(&in->child_head)) |
32 | return 0; | 32 | return 0; |
33 | 33 | ||
34 | len = strlen(buf); | 34 | len = strlen(buf); |
35 | strncpy(local, buf, sizeof(local)); | 35 | strncpy(local, buf, sizeof(local)); |
36 | snprintf(local + len, 2, "|"); | 36 | snprintf(local + len, 2, "|"); |
37 | if (len && local[len - 1] == '`') | 37 | if (len && local[len - 1] == '`') |
38 | local[len - 1] = ' '; | 38 | local[len - 1] = ' '; |
39 | 39 | ||
40 | list_for_each_entry_safe(pos, n, &in->child_head, sibling_node) { | 40 | list_for_each_entry_safe(pos, n, &in->child_head, sibling_node) { |
41 | if (ip++) | 41 | if (ip++) |
42 | display_succ(prev, local); | 42 | display_succ(prev, local); |
43 | prev = pos; | 43 | prev = pos; |
44 | } | 44 | } |
45 | 45 | ||
46 | snprintf(local + len, 2, "`"); | 46 | snprintf(local + len, 2, "`"); |
47 | display_succ(prev, local); | 47 | display_succ(prev, local); |
48 | 48 | ||
49 | return 0; | 49 | return 0; |
50 | } | 50 | } |
51 | 51 | ||
52 | static int dm_dump(struct udevice *dev) | 52 | static int dm_dump(struct udevice *dev) |
53 | { | 53 | { |
54 | if (!dev) | 54 | if (!dev) |
55 | return -EINVAL; | 55 | return -EINVAL; |
56 | return display_succ(dev, ""); | 56 | return display_succ(dev, ""); |
57 | } | 57 | } |
58 | 58 | ||
59 | static int do_dm_dump_all(cmd_tbl_t *cmdtp, int flag, int argc, | 59 | static int do_dm_dump_all(cmd_tbl_t *cmdtp, int flag, int argc, |
60 | char * const argv[]) | 60 | char * const argv[]) |
61 | { | 61 | { |
62 | struct udevice *root; | 62 | struct udevice *root; |
63 | 63 | ||
64 | root = dm_root(); | 64 | root = dm_root(); |
65 | printf("ROOT %08lx\n", (ulong)map_to_sysmem(root)); | 65 | printf("ROOT %08lx\n", (ulong)map_to_sysmem(root)); |
66 | return dm_dump(root); | 66 | return dm_dump(root); |
67 | } | 67 | } |
68 | 68 | ||
69 | static int do_dm_dump_uclass(cmd_tbl_t *cmdtp, int flag, int argc, | 69 | static int do_dm_dump_uclass(cmd_tbl_t *cmdtp, int flag, int argc, |
70 | char * const argv[]) | 70 | char * const argv[]) |
71 | { | 71 | { |
72 | struct uclass *uc; | 72 | struct uclass *uc; |
73 | int ret; | 73 | int ret; |
74 | int id; | 74 | int id; |
75 | 75 | ||
76 | for (id = 0; id < UCLASS_COUNT; id++) { | 76 | for (id = 0; id < UCLASS_COUNT; id++) { |
77 | struct udevice *dev; | 77 | struct udevice *dev; |
78 | 78 | ||
79 | ret = uclass_get(id, &uc); | 79 | ret = uclass_get(id, &uc); |
80 | if (ret) | 80 | if (ret) |
81 | continue; | 81 | continue; |
82 | 82 | ||
83 | printf("uclass %d: %s\n", id, uc->uc_drv->name); | 83 | printf("uclass %d: %s\n", id, uc->uc_drv->name); |
84 | for (ret = uclass_first_device(id, &dev); | 84 | for (ret = uclass_first_device(id, &dev); |
85 | dev; | 85 | dev; |
86 | ret = uclass_next_device(&dev)) { | 86 | ret = uclass_next_device(&dev)) { |
87 | printf(" %s @ %08lx:\n", dev->name, | 87 | printf(" %c %s @ %08lx:\n", |
88 | (ulong)map_to_sysmem(dev)); | 88 | dev->flags & DM_FLAG_ACTIVATED ? '*' : ' ', |
89 | dev->name, (ulong)map_to_sysmem(dev)); | ||
89 | } | 90 | } |
90 | puts("\n"); | 91 | puts("\n"); |
91 | } | 92 | } |
92 | 93 | ||
93 | return 0; | 94 | return 0; |
94 | } | 95 | } |
95 | 96 | ||
96 | #ifdef CONFIG_DM_TEST | 97 | #ifdef CONFIG_DM_TEST |
97 | static int do_dm_test(cmd_tbl_t *cmdtp, int flag, int argc, | 98 | static int do_dm_test(cmd_tbl_t *cmdtp, int flag, int argc, |
98 | char * const argv[]) | 99 | char * const argv[]) |
99 | { | 100 | { |
100 | return dm_test_main(); | 101 | return dm_test_main(); |
101 | } | 102 | } |
102 | #define TEST_HELP "\ndm test Run tests" | 103 | #define TEST_HELP "\ndm test Run tests" |
103 | #else | 104 | #else |
104 | #define TEST_HELP | 105 | #define TEST_HELP |
105 | #endif | 106 | #endif |
106 | 107 | ||
107 | static cmd_tbl_t test_commands[] = { | 108 | static cmd_tbl_t test_commands[] = { |
108 | U_BOOT_CMD_MKENT(tree, 0, 1, do_dm_dump_all, "", ""), | 109 | U_BOOT_CMD_MKENT(tree, 0, 1, do_dm_dump_all, "", ""), |
109 | U_BOOT_CMD_MKENT(uclass, 1, 1, do_dm_dump_uclass, "", ""), | 110 | U_BOOT_CMD_MKENT(uclass, 1, 1, do_dm_dump_uclass, "", ""), |
110 | #ifdef CONFIG_DM_TEST | 111 | #ifdef CONFIG_DM_TEST |
111 | U_BOOT_CMD_MKENT(test, 1, 1, do_dm_test, "", ""), | 112 | U_BOOT_CMD_MKENT(test, 1, 1, do_dm_test, "", ""), |
112 | #endif | 113 | #endif |
113 | }; | 114 | }; |
114 | 115 | ||
115 | static int do_dm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) | 116 | static int do_dm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
116 | { | 117 | { |
117 | cmd_tbl_t *test_cmd; | 118 | cmd_tbl_t *test_cmd; |
118 | int ret; | 119 | int ret; |
119 | 120 | ||
120 | if (argc != 2) | 121 | if (argc != 2) |
121 | return CMD_RET_USAGE; | 122 | return CMD_RET_USAGE; |
122 | test_cmd = find_cmd_tbl(argv[1], test_commands, | 123 | test_cmd = find_cmd_tbl(argv[1], test_commands, |
123 | ARRAY_SIZE(test_commands)); | 124 | ARRAY_SIZE(test_commands)); |
124 | argc -= 2; | 125 | argc -= 2; |
125 | argv += 2; | 126 | argv += 2; |
126 | if (!test_cmd || argc > test_cmd->maxargs) | 127 | if (!test_cmd || argc > test_cmd->maxargs) |
127 | return CMD_RET_USAGE; | 128 | return CMD_RET_USAGE; |
128 | 129 | ||
129 | ret = test_cmd->cmd(test_cmd, flag, argc, argv); | 130 | ret = test_cmd->cmd(test_cmd, flag, argc, argv); |
130 | 131 | ||
131 | return cmd_process_error(test_cmd, ret); | 132 | return cmd_process_error(test_cmd, ret); |
132 | } | 133 | } |
133 | 134 | ||
134 | U_BOOT_CMD( | 135 | U_BOOT_CMD( |
135 | dm, 2, 1, do_dm, | 136 | dm, 2, 1, do_dm, |
136 | "Driver model low level access", | 137 | "Driver model low level access", |
137 | "tree Dump driver model tree\n" | 138 | "tree Dump driver model tree\n" |
138 | "dm uclass Dump list of instances for each uclass" | 139 | "dm uclass Dump list of instances for each uclass" |
139 | TEST_HELP | 140 | TEST_HELP |
140 | ); | 141 | ); |
141 | 142 |