Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 0681195 | 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 | 0681195 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Tom Rini | cbb2df2 | 2015-12-07 08:23:29 -0500 | [diff] [blame] | 10 | #include <command.h> |
Simon Glass | 0681195 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 11 | #include <dm.h> |
| 12 | #include <malloc.h> |
Joe Hershberger | 0eb25b6 | 2015-03-22 17:08:59 -0500 | [diff] [blame] | 13 | #include <mapmem.h> |
Simon Glass | 0681195 | 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 | 304fbef | 2015-06-23 15:38:35 -0600 | [diff] [blame] | 17 | #include <dm/util.h> |
Simon Glass | 0681195 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 18 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 19 | static int do_dm_dump_all(struct cmd_tbl *cmdtp, int flag, int argc, |
| 20 | char *const argv[]) |
Simon Glass | 0681195 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 21 | { |
Simon Glass | 304fbef | 2015-06-23 15:38:35 -0600 | [diff] [blame] | 22 | dm_dump_all(); |
Masahiro Yamada | a56642c | 2014-11-29 17:01:56 +0900 | [diff] [blame] | 23 | |
| 24 | return 0; |
| 25 | } |
| 26 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 27 | static int do_dm_dump_uclass(struct cmd_tbl *cmdtp, int flag, int argc, |
| 28 | char *const argv[]) |
Simon Glass | 0681195 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 29 | { |
Simon Glass | 304fbef | 2015-06-23 15:38:35 -0600 | [diff] [blame] | 30 | dm_dump_uclass(); |
Simon Glass | 0681195 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 31 | |
| 32 | return 0; |
| 33 | } |
| 34 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 35 | static int do_dm_dump_devres(struct cmd_tbl *cmdtp, int flag, int argc, |
| 36 | char *const argv[]) |
Masahiro Yamada | 40b6f2d | 2015-07-25 21:52:38 +0900 | [diff] [blame] | 37 | { |
| 38 | dm_dump_devres(); |
| 39 | |
| 40 | return 0; |
| 41 | } |
| 42 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 43 | static int do_dm_dump_drivers(struct cmd_tbl *cmdtp, int flag, int argc, |
| 44 | char *const argv[]) |
Sean Anderson | 7b9d60f | 2020-01-17 14:48:09 -0500 | [diff] [blame] | 45 | { |
| 46 | dm_dump_drivers(); |
| 47 | |
| 48 | return 0; |
| 49 | } |
| 50 | |
Niel Fourie | 2e48836 | 2020-03-24 16:17:05 +0100 | [diff] [blame] | 51 | static 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 | |
| 59 | static 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 Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 67 | static struct cmd_tbl test_commands[] = { |
Simon Glass | 0681195 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 68 | U_BOOT_CMD_MKENT(tree, 0, 1, do_dm_dump_all, "", ""), |
| 69 | U_BOOT_CMD_MKENT(uclass, 1, 1, do_dm_dump_uclass, "", ""), |
Masahiro Yamada | 40b6f2d | 2015-07-25 21:52:38 +0900 | [diff] [blame] | 70 | U_BOOT_CMD_MKENT(devres, 1, 1, do_dm_dump_devres, "", ""), |
Sean Anderson | 7b9d60f | 2020-01-17 14:48:09 -0500 | [diff] [blame] | 71 | U_BOOT_CMD_MKENT(drivers, 1, 1, do_dm_dump_drivers, "", ""), |
Niel Fourie | 2e48836 | 2020-03-24 16:17:05 +0100 | [diff] [blame] | 72 | 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 Glass | 0681195 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 74 | }; |
| 75 | |
Michal Simek | d6df048 | 2015-12-04 11:42:01 +0100 | [diff] [blame] | 76 | static __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 Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 86 | static int do_dm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
Simon Glass | 0681195 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 87 | { |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 88 | struct cmd_tbl *test_cmd; |
Simon Glass | 0681195 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 89 | int ret; |
| 90 | |
Michal Simek | d6df048 | 2015-12-04 11:42:01 +0100 | [diff] [blame] | 91 | #ifdef CONFIG_NEEDS_MANUAL_RELOC |
| 92 | dm_reloc(); |
| 93 | #endif |
| 94 | |
Simon Glass | 57f54d5 | 2015-03-25 12:23:04 -0600 | [diff] [blame] | 95 | if (argc < 2) |
Simon Glass | 0681195 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 96 | 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 | |
| 109 | U_BOOT_CMD( |
Simon Glass | 57f54d5 | 2015-03-25 12:23:04 -0600 | [diff] [blame] | 110 | dm, 3, 1, do_dm, |
Simon Glass | 0681195 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 111 | "Driver model low level access", |
Masahiro Yamada | 138c8a7 | 2018-09-07 20:31:21 +0900 | [diff] [blame] | 112 | "tree Dump driver model tree ('*' = activated)\n" |
Masahiro Yamada | 40b6f2d | 2015-07-25 21:52:38 +0900 | [diff] [blame] | 113 | "dm uclass Dump list of instances for each uclass\n" |
Sean Anderson | 7b9d60f | 2020-01-17 14:48:09 -0500 | [diff] [blame] | 114 | "dm devres Dump list of device resources for each device\n" |
Niel Fourie | 2e48836 | 2020-03-24 16:17:05 +0100 | [diff] [blame] | 115 | "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 Glass | 0681195 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 118 | ); |