blob: 1dd19fe45b5490c9ef58dec2c11d72609a5c3ebe [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
9#include <common.h>
Tom Rini23415e52015-12-07 08:23:29 -050010#include <command.h>
Simon Glassc267cf72014-02-26 15:59:22 -070011#include <dm.h>
12#include <malloc.h>
Joe Hershberger65b905b2015-03-22 17:08:59 -050013#include <mapmem.h>
Simon Glassc267cf72014-02-26 15:59:22 -070014#include <errno.h>
15#include <asm/io.h>
16#include <dm/root.h>
Simon Glassd9f9a892015-06-23 15:38:35 -060017#include <dm/util.h>
Simon Glassc267cf72014-02-26 15:59:22 -070018
Simon Glassed38aef2020-05-10 11:40:03 -060019static int do_dm_dump_all(struct cmd_tbl *cmdtp, int flag, int argc,
20 char *const argv[])
Simon Glassc267cf72014-02-26 15:59:22 -070021{
Simon Glassd9f9a892015-06-23 15:38:35 -060022 dm_dump_all();
Masahiro Yamadaee7637b2014-11-29 17:01:56 +090023
24 return 0;
25}
26
Simon Glassed38aef2020-05-10 11:40:03 -060027static int do_dm_dump_uclass(struct cmd_tbl *cmdtp, int flag, int argc,
28 char *const argv[])
Simon Glassc267cf72014-02-26 15:59:22 -070029{
Simon Glassd9f9a892015-06-23 15:38:35 -060030 dm_dump_uclass();
Simon Glassc267cf72014-02-26 15:59:22 -070031
32 return 0;
33}
34
Simon Glassed38aef2020-05-10 11:40:03 -060035static int do_dm_dump_devres(struct cmd_tbl *cmdtp, int flag, int argc,
36 char *const argv[])
Masahiro Yamadaf929c0b2015-07-25 21:52:38 +090037{
38 dm_dump_devres();
39
40 return 0;
41}
42
Simon Glassed38aef2020-05-10 11:40:03 -060043static int do_dm_dump_drivers(struct cmd_tbl *cmdtp, int flag, int argc,
44 char *const argv[])
Sean Anderson02827572020-01-17 14:48:09 -050045{
46 dm_dump_drivers();
47
48 return 0;
49}
50
Niel Fourie39832fb2020-03-24 16:17:05 +010051static int do_dm_dump_driver_compat(struct cmd_tbl *cmdtp, int flag, int argc,
52 char * const argv[])
53{
54 dm_dump_driver_compat();
55
56 return 0;
57}
58
59static int do_dm_dump_static_driver_info(struct cmd_tbl *cmdtp, int flag, int argc,
60 char * const argv[])
61{
62 dm_dump_static_driver_info();
63
64 return 0;
65}
66
Simon Glassed38aef2020-05-10 11:40:03 -060067static struct cmd_tbl test_commands[] = {
Simon Glassc267cf72014-02-26 15:59:22 -070068 U_BOOT_CMD_MKENT(tree, 0, 1, do_dm_dump_all, "", ""),
69 U_BOOT_CMD_MKENT(uclass, 1, 1, do_dm_dump_uclass, "", ""),
Masahiro Yamadaf929c0b2015-07-25 21:52:38 +090070 U_BOOT_CMD_MKENT(devres, 1, 1, do_dm_dump_devres, "", ""),
Sean Anderson02827572020-01-17 14:48:09 -050071 U_BOOT_CMD_MKENT(drivers, 1, 1, do_dm_dump_drivers, "", ""),
Niel Fourie39832fb2020-03-24 16:17:05 +010072 U_BOOT_CMD_MKENT(compat, 1, 1, do_dm_dump_driver_compat, "", ""),
73 U_BOOT_CMD_MKENT(static, 1, 1, do_dm_dump_static_driver_info, "", ""),
Simon Glassc267cf72014-02-26 15:59:22 -070074};
75
Michal Simek968d8f42015-12-04 11:42:01 +010076static __maybe_unused void dm_reloc(void)
77{
78 static int relocated;
79
80 if (!relocated) {
81 fixup_cmdtable(test_commands, ARRAY_SIZE(test_commands));
82 relocated = 1;
83 }
84}
85
Simon Glassed38aef2020-05-10 11:40:03 -060086static int do_dm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Simon Glassc267cf72014-02-26 15:59:22 -070087{
Simon Glassed38aef2020-05-10 11:40:03 -060088 struct cmd_tbl *test_cmd;
Simon Glassc267cf72014-02-26 15:59:22 -070089 int ret;
90
Michal Simek968d8f42015-12-04 11:42:01 +010091#ifdef CONFIG_NEEDS_MANUAL_RELOC
92 dm_reloc();
93#endif
94
Simon Glass15061802015-03-25 12:23:04 -060095 if (argc < 2)
Simon Glassc267cf72014-02-26 15:59:22 -070096 return CMD_RET_USAGE;
97 test_cmd = find_cmd_tbl(argv[1], test_commands,
98 ARRAY_SIZE(test_commands));
99 argc -= 2;
100 argv += 2;
101 if (!test_cmd || argc > test_cmd->maxargs)
102 return CMD_RET_USAGE;
103
104 ret = test_cmd->cmd(test_cmd, flag, argc, argv);
105
106 return cmd_process_error(test_cmd, ret);
107}
108
109U_BOOT_CMD(
Simon Glass15061802015-03-25 12:23:04 -0600110 dm, 3, 1, do_dm,
Simon Glassc267cf72014-02-26 15:59:22 -0700111 "Driver model low level access",
Masahiro Yamada8a5c8a92018-09-07 20:31:21 +0900112 "tree Dump driver model tree ('*' = activated)\n"
Masahiro Yamadaf929c0b2015-07-25 21:52:38 +0900113 "dm uclass Dump list of instances for each uclass\n"
Sean Anderson02827572020-01-17 14:48:09 -0500114 "dm devres Dump list of device resources for each device\n"
Niel Fourie39832fb2020-03-24 16:17:05 +0100115 "dm drivers Dump list of drivers with uclass and instances\n"
116 "dm compat Dump list of drivers with compatibility strings\n"
117 "dm static Dump list of drivers with static platform data"
Simon Glassc267cf72014-02-26 15:59:22 -0700118);