blob: ec9cfd85376e3f62a836b677b3ac1818559da2de [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glassc267cf72014-02-26 15:59:22 -07002/*
3 * Copyright (c) 2013 Google, Inc
4 *
5 * (C) Copyright 2012
6 * Marek Vasut <marex@denx.de>
Simon Glassc267cf72014-02-26 15:59:22 -07007 */
8
Tom Rini23415e52015-12-07 08:23:29 -05009#include <command.h>
Simon Glassc8b5e222022-05-08 04:39:26 -060010#include <dm/root.h>
Simon Glassd9f9a892015-06-23 15:38:35 -060011#include <dm/util.h>
Simon Glassc267cf72014-02-26 15:59:22 -070012
Simon Glasse9daa5d2022-05-08 04:39:20 -060013static int do_dm_dump_driver_compat(struct cmd_tbl *cmdtp, int flag, int argc,
14 char * const argv[])
Simon Glassc267cf72014-02-26 15:59:22 -070015{
Simon Glasse9daa5d2022-05-08 04:39:20 -060016 dm_dump_driver_compat();
Simon Glassc267cf72014-02-26 15:59:22 -070017
18 return 0;
19}
20
Simon Glassed38aef2020-05-10 11:40:03 -060021static int do_dm_dump_devres(struct cmd_tbl *cmdtp, int flag, int argc,
22 char *const argv[])
Masahiro Yamadaf929c0b2015-07-25 21:52:38 +090023{
24 dm_dump_devres();
25
26 return 0;
27}
28
Simon Glassed38aef2020-05-10 11:40:03 -060029static int do_dm_dump_drivers(struct cmd_tbl *cmdtp, int flag, int argc,
30 char *const argv[])
Sean Anderson02827572020-01-17 14:48:09 -050031{
32 dm_dump_drivers();
33
34 return 0;
35}
36
Simon Glassc8b5e222022-05-08 04:39:26 -060037#if CONFIG_IS_ENABLED(DM_STATS)
38static int do_dm_dump_mem(struct cmd_tbl *cmdtp, int flag, int argc,
39 char *const argv[])
40{
41 struct dm_stats mem;
42
43 dm_get_mem(&mem);
44 dm_dump_mem(&mem);
45
46 return 0;
47}
48#endif /* DM_STATS */
49
Simon Glasse9daa5d2022-05-08 04:39:20 -060050static int do_dm_dump_static_driver_info(struct cmd_tbl *cmdtp, int flag,
51 int argc, char * const argv[])
Niel Fourie39832fb2020-03-24 16:17:05 +010052{
Simon Glasse9daa5d2022-05-08 04:39:20 -060053 dm_dump_static_driver_info();
Niel Fourie39832fb2020-03-24 16:17:05 +010054
55 return 0;
56}
57
Simon Glasse9daa5d2022-05-08 04:39:20 -060058static int do_dm_dump_tree(struct cmd_tbl *cmdtp, int flag, int argc,
59 char *const argv[])
Niel Fourie39832fb2020-03-24 16:17:05 +010060{
AKASHI Takahirof06f0822023-08-23 10:49:47 +090061 bool extended = false, sort = false;
62 char *device = NULL;
Simon Glasse5314c12023-01-17 10:47:12 -070063
AKASHI Takahirof06f0822023-08-23 10:49:47 +090064 for (; argc > 1; argc--, argv++) {
65 if (argv[1][0] != '-')
66 break;
Simon Glasse5314c12023-01-17 10:47:12 -070067
AKASHI Takahirof06f0822023-08-23 10:49:47 +090068 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;
75 }
76 }
77 if (argc > 1)
78 device = argv[1];
79
80 dm_dump_tree(device, extended, sort);
Niel Fourie39832fb2020-03-24 16:17:05 +010081
82 return 0;
83}
84
Simon Glasse9daa5d2022-05-08 04:39:20 -060085static int do_dm_dump_uclass(struct cmd_tbl *cmdtp, int flag, int argc,
86 char *const argv[])
87{
AKASHI Takahirof06f0822023-08-23 10:49:47 +090088 bool extended = false;
89 char *uclass = NULL;
90
91 if (argc > 1) {
92 if (!strcmp(argv[1], "-e")) {
93 extended = true;
94 argc--;
95 argv++;
96 }
97 if (argc > 1)
98 uclass = argv[1];
99 }
100
101 dm_dump_uclass(uclass, extended);
Simon Glasse9daa5d2022-05-08 04:39:20 -0600102
103 return 0;
104}
105
Simon Glassc8b5e222022-05-08 04:39:26 -0600106#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
113
Tom Rini03f146c2023-10-07 15:13:08 -0400114U_BOOT_LONGHELP(dm,
Simon Glasse9daa5d2022-05-08 04:39:20 -0600115 "compat Dump list of drivers with compatibility strings\n"
Sean Anderson02827572020-01-17 14:48:09 -0500116 "dm devres Dump list of device resources for each device\n"
Niel Fourie39832fb2020-03-24 16:17:05 +0100117 "dm drivers Dump list of drivers with uclass and instances\n"
Simon Glassc8b5e222022-05-08 04:39:26 -0600118 DM_MEM_HELP
Simon Glasse9daa5d2022-05-08 04:39:20 -0600119 "dm static Dump list of drivers with static platform data\n"
AKASHI Takahirof06f0822023-08-23 10:49:47 +0900120 "dm tree [-s][-e][name] Dump tree of driver model devices (-s=sort)\n"
Tom Rini03f146c2023-10-07 15:13:08 -0400121 "dm uclass [-e][name] Dump list of instances for each uclass");
Ovidiu Panaite4c5b792022-05-08 13:01:42 +0300122
123U_BOOT_CMD_WITH_SUBCMDS(dm, "Driver model low level access", dm_help_text,
Simon Glasse9daa5d2022-05-08 04:39:20 -0600124 U_BOOT_SUBCMD_MKENT(compat, 1, 1, do_dm_dump_driver_compat),
Ovidiu Panaite4c5b792022-05-08 13:01:42 +0300125 U_BOOT_SUBCMD_MKENT(devres, 1, 1, do_dm_dump_devres),
126 U_BOOT_SUBCMD_MKENT(drivers, 1, 1, do_dm_dump_drivers),
Simon Glassc8b5e222022-05-08 04:39:26 -0600127 DM_MEM
Simon Glasse9daa5d2022-05-08 04:39:20 -0600128 U_BOOT_SUBCMD_MKENT(static, 1, 1, do_dm_dump_static_driver_info),
AKASHI Takahirof06f0822023-08-23 10:49:47 +0900129 U_BOOT_SUBCMD_MKENT(tree, 4, 1, do_dm_dump_tree),
130 U_BOOT_SUBCMD_MKENT(uclass, 3, 1, do_dm_dump_uclass));