blob: fb605c2da1a89e6b43850bc8cc620adf0b5ffbeb [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass06811952014-02-26 15:59:22 -07002/*
3 * Copyright (c) 2013 Google, Inc
4 *
5 * (C) Copyright 2012
6 * Marek Vasut <marex@denx.de>
Simon Glass06811952014-02-26 15:59:22 -07007 */
8
9#include <common.h>
Tom Rinicbb2df22015-12-07 08:23:29 -050010#include <command.h>
Simon Glass2cb4ddb2022-05-08 04:39:26 -060011#include <dm/root.h>
Simon Glass304fbef2015-06-23 15:38:35 -060012#include <dm/util.h>
Simon Glass06811952014-02-26 15:59:22 -070013
Simon Glassdee2f5a2022-05-08 04:39:20 -060014static int do_dm_dump_driver_compat(struct cmd_tbl *cmdtp, int flag, int argc,
15 char * const argv[])
Simon Glass06811952014-02-26 15:59:22 -070016{
Simon Glassdee2f5a2022-05-08 04:39:20 -060017 dm_dump_driver_compat();
Simon Glass06811952014-02-26 15:59:22 -070018
19 return 0;
20}
21
Simon Glass09140112020-05-10 11:40:03 -060022static int do_dm_dump_devres(struct cmd_tbl *cmdtp, int flag, int argc,
23 char *const argv[])
Masahiro Yamada40b6f2d2015-07-25 21:52:38 +090024{
25 dm_dump_devres();
26
27 return 0;
28}
29
Simon Glass09140112020-05-10 11:40:03 -060030static int do_dm_dump_drivers(struct cmd_tbl *cmdtp, int flag, int argc,
31 char *const argv[])
Sean Anderson7b9d60f2020-01-17 14:48:09 -050032{
33 dm_dump_drivers();
34
35 return 0;
36}
37
Simon Glass2cb4ddb2022-05-08 04:39:26 -060038#if CONFIG_IS_ENABLED(DM_STATS)
39static int do_dm_dump_mem(struct cmd_tbl *cmdtp, int flag, int argc,
40 char *const argv[])
41{
42 struct dm_stats mem;
43
44 dm_get_mem(&mem);
45 dm_dump_mem(&mem);
46
47 return 0;
48}
49#endif /* DM_STATS */
50
Simon Glassdee2f5a2022-05-08 04:39:20 -060051static int do_dm_dump_static_driver_info(struct cmd_tbl *cmdtp, int flag,
52 int argc, char * const argv[])
Niel Fourie2e488362020-03-24 16:17:05 +010053{
54 dm_dump_static_driver_info();
55
56 return 0;
57}
58
Simon Glassdee2f5a2022-05-08 04:39:20 -060059static int do_dm_dump_tree(struct cmd_tbl *cmdtp, int flag, int argc,
60 char *const argv[])
61{
AKASHI Takahiro36e45f62023-08-23 10:49:47 +090062 bool extended = false, sort = false;
63 char *device = NULL;
Simon Glass3d012542023-01-17 10:47:12 -070064
AKASHI Takahiro36e45f62023-08-23 10:49:47 +090065 for (; argc > 1; argc--, argv++) {
66 if (argv[1][0] != '-')
67 break;
Simon Glass3d012542023-01-17 10:47:12 -070068
AKASHI Takahiro36e45f62023-08-23 10:49:47 +090069 if (!strcmp(argv[1], "-e")) {
70 extended = true;
71 } else if (!strcmp(argv[1], "-s")) {
72 sort = true;
73 } else {
74 printf("Unknown parameter: %s\n", argv[1]);
75 return 0;
76 }
77 }
78 if (argc > 1)
79 device = argv[1];
80
81 dm_dump_tree(device, extended, sort);
Simon Glassdee2f5a2022-05-08 04:39:20 -060082
83 return 0;
84}
85
86static int do_dm_dump_uclass(struct cmd_tbl *cmdtp, int flag, int argc,
87 char *const argv[])
88{
AKASHI Takahiro36e45f62023-08-23 10:49:47 +090089 bool extended = false;
90 char *uclass = NULL;
91
92 if (argc > 1) {
93 if (!strcmp(argv[1], "-e")) {
94 extended = true;
95 argc--;
96 argv++;
97 }
98 if (argc > 1)
99 uclass = argv[1];
100 }
101
102 dm_dump_uclass(uclass, extended);
Simon Glassdee2f5a2022-05-08 04:39:20 -0600103
104 return 0;
105}
106
Simon Glass2cb4ddb2022-05-08 04:39:26 -0600107#if CONFIG_IS_ENABLED(DM_STATS)
108#define DM_MEM_HELP "dm mem Provide a summary of memory usage\n"
109#define DM_MEM U_BOOT_SUBCMD_MKENT(mem, 1, 1, do_dm_dump_mem),
110#else
111#define DM_MEM_HELP
112#define DM_MEM
113#endif
114
Tom Rini36162182023-10-07 15:13:08 -0400115U_BOOT_LONGHELP(dm,
Simon Glassdee2f5a2022-05-08 04:39:20 -0600116 "compat Dump list of drivers with compatibility strings\n"
Sean Anderson7b9d60f2020-01-17 14:48:09 -0500117 "dm devres Dump list of device resources for each device\n"
Niel Fourie2e488362020-03-24 16:17:05 +0100118 "dm drivers Dump list of drivers with uclass and instances\n"
Simon Glass2cb4ddb2022-05-08 04:39:26 -0600119 DM_MEM_HELP
Simon Glassdee2f5a2022-05-08 04:39:20 -0600120 "dm static Dump list of drivers with static platform data\n"
AKASHI Takahiro36e45f62023-08-23 10:49:47 +0900121 "dm tree [-s][-e][name] Dump tree of driver model devices (-s=sort)\n"
Tom Rini36162182023-10-07 15:13:08 -0400122 "dm uclass [-e][name] Dump list of instances for each uclass");
Ovidiu Panait7f0836a2022-05-08 13:01:42 +0300123
124U_BOOT_CMD_WITH_SUBCMDS(dm, "Driver model low level access", dm_help_text,
Simon Glassdee2f5a2022-05-08 04:39:20 -0600125 U_BOOT_SUBCMD_MKENT(compat, 1, 1, do_dm_dump_driver_compat),
Ovidiu Panait7f0836a2022-05-08 13:01:42 +0300126 U_BOOT_SUBCMD_MKENT(devres, 1, 1, do_dm_dump_devres),
127 U_BOOT_SUBCMD_MKENT(drivers, 1, 1, do_dm_dump_drivers),
Simon Glass2cb4ddb2022-05-08 04:39:26 -0600128 DM_MEM
Simon Glassdee2f5a2022-05-08 04:39:20 -0600129 U_BOOT_SUBCMD_MKENT(static, 1, 1, do_dm_dump_static_driver_info),
AKASHI Takahiro36e45f62023-08-23 10:49:47 +0900130 U_BOOT_SUBCMD_MKENT(tree, 4, 1, do_dm_dump_tree),
131 U_BOOT_SUBCMD_MKENT(uclass, 3, 1, do_dm_dump_uclass));