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