blob: 4e307ac5245bfe0d8e9122c94abe4d71a5dde5f8 [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
Simon Glassed38aef2020-05-10 11:40:03 -060051static struct cmd_tbl test_commands[] = {
Simon Glassc267cf72014-02-26 15:59:22 -070052 U_BOOT_CMD_MKENT(tree, 0, 1, do_dm_dump_all, "", ""),
53 U_BOOT_CMD_MKENT(uclass, 1, 1, do_dm_dump_uclass, "", ""),
Masahiro Yamadaf929c0b2015-07-25 21:52:38 +090054 U_BOOT_CMD_MKENT(devres, 1, 1, do_dm_dump_devres, "", ""),
Sean Anderson02827572020-01-17 14:48:09 -050055 U_BOOT_CMD_MKENT(drivers, 1, 1, do_dm_dump_drivers, "", ""),
Simon Glassc267cf72014-02-26 15:59:22 -070056};
57
Michal Simek968d8f42015-12-04 11:42:01 +010058static __maybe_unused void dm_reloc(void)
59{
60 static int relocated;
61
62 if (!relocated) {
63 fixup_cmdtable(test_commands, ARRAY_SIZE(test_commands));
64 relocated = 1;
65 }
66}
67
Simon Glassed38aef2020-05-10 11:40:03 -060068static int do_dm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Simon Glassc267cf72014-02-26 15:59:22 -070069{
Simon Glassed38aef2020-05-10 11:40:03 -060070 struct cmd_tbl *test_cmd;
Simon Glassc267cf72014-02-26 15:59:22 -070071 int ret;
72
Michal Simek968d8f42015-12-04 11:42:01 +010073#ifdef CONFIG_NEEDS_MANUAL_RELOC
74 dm_reloc();
75#endif
76
Simon Glass15061802015-03-25 12:23:04 -060077 if (argc < 2)
Simon Glassc267cf72014-02-26 15:59:22 -070078 return CMD_RET_USAGE;
79 test_cmd = find_cmd_tbl(argv[1], test_commands,
80 ARRAY_SIZE(test_commands));
81 argc -= 2;
82 argv += 2;
83 if (!test_cmd || argc > test_cmd->maxargs)
84 return CMD_RET_USAGE;
85
86 ret = test_cmd->cmd(test_cmd, flag, argc, argv);
87
88 return cmd_process_error(test_cmd, ret);
89}
90
91U_BOOT_CMD(
Simon Glass15061802015-03-25 12:23:04 -060092 dm, 3, 1, do_dm,
Simon Glassc267cf72014-02-26 15:59:22 -070093 "Driver model low level access",
Masahiro Yamada8a5c8a92018-09-07 20:31:21 +090094 "tree Dump driver model tree ('*' = activated)\n"
Masahiro Yamadaf929c0b2015-07-25 21:52:38 +090095 "dm uclass Dump list of instances for each uclass\n"
Sean Anderson02827572020-01-17 14:48:09 -050096 "dm devres Dump list of device resources for each device\n"
Sean Anderson439f1c62020-04-06 10:23:09 -040097 "dm drivers Dump list of drivers and their compatible strings"
Simon Glassc267cf72014-02-26 15:59:22 -070098);