Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | c267cf7 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2013 Google, Inc |
| 4 | * |
| 5 | * (C) Copyright 2012 |
| 6 | * Marek Vasut <marex@denx.de> |
Simon Glass | c267cf7 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Tom Rini | 23415e5 | 2015-12-07 08:23:29 -0500 | [diff] [blame] | 10 | #include <command.h> |
Simon Glass | c267cf7 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 11 | #include <dm.h> |
| 12 | #include <malloc.h> |
Joe Hershberger | 65b905b | 2015-03-22 17:08:59 -0500 | [diff] [blame] | 13 | #include <mapmem.h> |
Simon Glass | c267cf7 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 14 | #include <errno.h> |
| 15 | #include <asm/io.h> |
| 16 | #include <dm/root.h> |
Simon Glass | d9f9a89 | 2015-06-23 15:38:35 -0600 | [diff] [blame] | 17 | #include <dm/util.h> |
Simon Glass | c267cf7 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 18 | |
| 19 | static int do_dm_dump_all(cmd_tbl_t *cmdtp, int flag, int argc, |
| 20 | char * const argv[]) |
| 21 | { |
Simon Glass | d9f9a89 | 2015-06-23 15:38:35 -0600 | [diff] [blame] | 22 | dm_dump_all(); |
Masahiro Yamada | ee7637b | 2014-11-29 17:01:56 +0900 | [diff] [blame] | 23 | |
| 24 | return 0; |
| 25 | } |
| 26 | |
Simon Glass | c267cf7 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 27 | static int do_dm_dump_uclass(cmd_tbl_t *cmdtp, int flag, int argc, |
| 28 | char * const argv[]) |
| 29 | { |
Simon Glass | d9f9a89 | 2015-06-23 15:38:35 -0600 | [diff] [blame] | 30 | dm_dump_uclass(); |
Simon Glass | c267cf7 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 31 | |
| 32 | return 0; |
| 33 | } |
| 34 | |
Masahiro Yamada | f929c0b | 2015-07-25 21:52:38 +0900 | [diff] [blame] | 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 | |
Simon Glass | c267cf7 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 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, "", ""), |
Masahiro Yamada | f929c0b | 2015-07-25 21:52:38 +0900 | [diff] [blame] | 46 | U_BOOT_CMD_MKENT(devres, 1, 1, do_dm_dump_devres, "", ""), |
Simon Glass | c267cf7 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 47 | }; |
| 48 | |
Michal Simek | 968d8f4 | 2015-12-04 11:42:01 +0100 | [diff] [blame] | 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 | |
Simon Glass | c267cf7 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 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 | |
Michal Simek | 968d8f4 | 2015-12-04 11:42:01 +0100 | [diff] [blame] | 64 | #ifdef CONFIG_NEEDS_MANUAL_RELOC |
| 65 | dm_reloc(); |
| 66 | #endif |
| 67 | |
Simon Glass | 1506180 | 2015-03-25 12:23:04 -0600 | [diff] [blame] | 68 | if (argc < 2) |
Simon Glass | c267cf7 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 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( |
Simon Glass | 1506180 | 2015-03-25 12:23:04 -0600 | [diff] [blame] | 83 | dm, 3, 1, do_dm, |
Simon Glass | c267cf7 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 84 | "Driver model low level access", |
Masahiro Yamada | 8a5c8a9 | 2018-09-07 20:31:21 +0900 | [diff] [blame] | 85 | "tree Dump driver model tree ('*' = activated)\n" |
Masahiro Yamada | f929c0b | 2015-07-25 21:52:38 +0900 | [diff] [blame] | 86 | "dm uclass Dump list of instances for each uclass\n" |
| 87 | "dm devres Dump list of device resources for each device" |
Simon Glass | c267cf7 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 88 | ); |