xref: /openbmc/u-boot/cmd/dm.c (revision 522e0354)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (c) 2013 Google, Inc
4  *
5  * (C) Copyright 2012
6  * Marek Vasut <marex@denx.de>
7  */
8 
9 #include <common.h>
10 #include <command.h>
11 #include <dm.h>
12 #include <malloc.h>
13 #include <mapmem.h>
14 #include <errno.h>
15 #include <asm/io.h>
16 #include <dm/root.h>
17 #include <dm/util.h>
18 
do_dm_dump_all(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])19 static int do_dm_dump_all(cmd_tbl_t *cmdtp, int flag, int argc,
20 			  char * const argv[])
21 {
22 	dm_dump_all();
23 
24 	return 0;
25 }
26 
do_dm_dump_uclass(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])27 static int do_dm_dump_uclass(cmd_tbl_t *cmdtp, int flag, int argc,
28 			     char * const argv[])
29 {
30 	dm_dump_uclass();
31 
32 	return 0;
33 }
34 
do_dm_dump_devres(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])35 static int do_dm_dump_devres(cmd_tbl_t *cmdtp, int flag, int argc,
36 			     char * const argv[])
37 {
38 	dm_dump_devres();
39 
40 	return 0;
41 }
42 
43 static cmd_tbl_t test_commands[] = {
44 	U_BOOT_CMD_MKENT(tree, 0, 1, do_dm_dump_all, "", ""),
45 	U_BOOT_CMD_MKENT(uclass, 1, 1, do_dm_dump_uclass, "", ""),
46 	U_BOOT_CMD_MKENT(devres, 1, 1, do_dm_dump_devres, "", ""),
47 };
48 
dm_reloc(void)49 static __maybe_unused void dm_reloc(void)
50 {
51 	static int relocated;
52 
53 	if (!relocated) {
54 		fixup_cmdtable(test_commands, ARRAY_SIZE(test_commands));
55 		relocated = 1;
56 	}
57 }
58 
do_dm(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])59 static int do_dm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
60 {
61 	cmd_tbl_t *test_cmd;
62 	int ret;
63 
64 #ifdef CONFIG_NEEDS_MANUAL_RELOC
65 	dm_reloc();
66 #endif
67 
68 	if (argc < 2)
69 		return CMD_RET_USAGE;
70 	test_cmd = find_cmd_tbl(argv[1], test_commands,
71 				ARRAY_SIZE(test_commands));
72 	argc -= 2;
73 	argv += 2;
74 	if (!test_cmd || argc > test_cmd->maxargs)
75 		return CMD_RET_USAGE;
76 
77 	ret = test_cmd->cmd(test_cmd, flag, argc, argv);
78 
79 	return cmd_process_error(test_cmd, ret);
80 }
81 
82 U_BOOT_CMD(
83 	dm,	3,	1,	do_dm,
84 	"Driver model low level access",
85 	"tree          Dump driver model tree ('*' = activated)\n"
86 	"dm uclass        Dump list of instances for each uclass\n"
87 	"dm devres        Dump list of device resources for each device"
88 );
89