Merge tag 'xilinx-for-v2025.01-rc3-v2' of https://source.denx.de/u-boot/custodians...
[u-boot.git] / cmd / dm.c
blobec9cfd85376e3f62a836b677b3ac1818559da2de
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (c) 2013 Google, Inc
5 * (C) Copyright 2012
6 * Marek Vasut <marex@denx.de>
7 */
9 #include <command.h>
10 #include <dm/root.h>
11 #include <dm/util.h>
13 static int do_dm_dump_driver_compat(struct cmd_tbl *cmdtp, int flag, int argc,
14 char * const argv[])
16 dm_dump_driver_compat();
18 return 0;
21 static int do_dm_dump_devres(struct cmd_tbl *cmdtp, int flag, int argc,
22 char *const argv[])
24 dm_dump_devres();
26 return 0;
29 static int do_dm_dump_drivers(struct cmd_tbl *cmdtp, int flag, int argc,
30 char *const argv[])
32 dm_dump_drivers();
34 return 0;
37 #if CONFIG_IS_ENABLED(DM_STATS)
38 static int do_dm_dump_mem(struct cmd_tbl *cmdtp, int flag, int argc,
39 char *const argv[])
41 struct dm_stats mem;
43 dm_get_mem(&mem);
44 dm_dump_mem(&mem);
46 return 0;
48 #endif /* DM_STATS */
50 static int do_dm_dump_static_driver_info(struct cmd_tbl *cmdtp, int flag,
51 int argc, char * const argv[])
53 dm_dump_static_driver_info();
55 return 0;
58 static int do_dm_dump_tree(struct cmd_tbl *cmdtp, int flag, int argc,
59 char *const argv[])
61 bool extended = false, sort = false;
62 char *device = NULL;
64 for (; argc > 1; argc--, argv++) {
65 if (argv[1][0] != '-')
66 break;
68 if (!strcmp(argv[1], "-e")) {
69 extended = true;
70 } else if (!strcmp(argv[1], "-s")) {
71 sort = true;
72 } else {
73 printf("Unknown parameter: %s\n", argv[1]);
74 return 0;
77 if (argc > 1)
78 device = argv[1];
80 dm_dump_tree(device, extended, sort);
82 return 0;
85 static int do_dm_dump_uclass(struct cmd_tbl *cmdtp, int flag, int argc,
86 char *const argv[])
88 bool extended = false;
89 char *uclass = NULL;
91 if (argc > 1) {
92 if (!strcmp(argv[1], "-e")) {
93 extended = true;
94 argc--;
95 argv++;
97 if (argc > 1)
98 uclass = argv[1];
101 dm_dump_uclass(uclass, extended);
103 return 0;
106 #if CONFIG_IS_ENABLED(DM_STATS)
107 #define DM_MEM_HELP "dm mem Provide a summary of memory usage\n"
108 #define DM_MEM U_BOOT_SUBCMD_MKENT(mem, 1, 1, do_dm_dump_mem),
109 #else
110 #define DM_MEM_HELP
111 #define DM_MEM
112 #endif
114 U_BOOT_LONGHELP(dm,
115 "compat Dump list of drivers with compatibility strings\n"
116 "dm devres Dump list of device resources for each device\n"
117 "dm drivers Dump list of drivers with uclass and instances\n"
118 DM_MEM_HELP
119 "dm static Dump list of drivers with static platform data\n"
120 "dm tree [-s][-e][name] Dump tree of driver model devices (-s=sort)\n"
121 "dm uclass [-e][name] Dump list of instances for each uclass");
123 U_BOOT_CMD_WITH_SUBCMDS(dm, "Driver model low level access", dm_help_text,
124 U_BOOT_SUBCMD_MKENT(compat, 1, 1, do_dm_dump_driver_compat),
125 U_BOOT_SUBCMD_MKENT(devres, 1, 1, do_dm_dump_devres),
126 U_BOOT_SUBCMD_MKENT(drivers, 1, 1, do_dm_dump_drivers),
127 DM_MEM
128 U_BOOT_SUBCMD_MKENT(static, 1, 1, do_dm_dump_static_driver_info),
129 U_BOOT_SUBCMD_MKENT(tree, 4, 1, do_dm_dump_tree),
130 U_BOOT_SUBCMD_MKENT(uclass, 3, 1, do_dm_dump_uclass));