Simon Glass | 0681195 | 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> |
| 11 | #include <dm.h> |
| 12 | #include <malloc.h> |
| 13 | #include <errno.h> |
| 14 | #include <asm/io.h> |
| 15 | #include <dm/root.h> |
| 16 | #include <dm/test.h> |
| 17 | #include <dm/uclass-internal.h> |
| 18 | |
Simon Glass | fffa24d | 2014-07-23 06:55:10 -0600 | [diff] [blame] | 19 | /** |
| 20 | * dm_display_line() - Display information about a single device |
| 21 | * |
| 22 | * Displays a single line of information with an option prefix |
| 23 | * |
| 24 | * @dev: Device to display |
| 25 | * @buf: Prefix to display at the start of the line |
| 26 | */ |
| 27 | static void dm_display_line(struct udevice *dev, char *buf) |
| 28 | { |
| 29 | printf("%s- %c %s @ %08lx", buf, |
| 30 | dev->flags & DM_FLAG_ACTIVATED ? '*' : ' ', |
| 31 | dev->name, (ulong)map_to_sysmem(dev)); |
Simon Glass | b7d6657 | 2014-07-23 06:55:13 -0600 | [diff] [blame] | 32 | if (dev->req_seq != -1) |
| 33 | printf(", %d", dev->req_seq); |
Simon Glass | fffa24d | 2014-07-23 06:55:10 -0600 | [diff] [blame] | 34 | puts("\n"); |
| 35 | } |
| 36 | |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 37 | static int display_succ(struct udevice *in, char *buf) |
Simon Glass | 0681195 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 38 | { |
| 39 | int len; |
| 40 | int ip = 0; |
| 41 | char local[16]; |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 42 | struct udevice *pos, *n, *prev = NULL; |
Simon Glass | 0681195 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 43 | |
Simon Glass | fffa24d | 2014-07-23 06:55:10 -0600 | [diff] [blame] | 44 | dm_display_line(in, buf); |
Simon Glass | 0681195 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 45 | |
| 46 | if (list_empty(&in->child_head)) |
| 47 | return 0; |
| 48 | |
| 49 | len = strlen(buf); |
| 50 | strncpy(local, buf, sizeof(local)); |
| 51 | snprintf(local + len, 2, "|"); |
| 52 | if (len && local[len - 1] == '`') |
| 53 | local[len - 1] = ' '; |
| 54 | |
| 55 | list_for_each_entry_safe(pos, n, &in->child_head, sibling_node) { |
| 56 | if (ip++) |
| 57 | display_succ(prev, local); |
| 58 | prev = pos; |
| 59 | } |
| 60 | |
| 61 | snprintf(local + len, 2, "`"); |
| 62 | display_succ(prev, local); |
| 63 | |
| 64 | return 0; |
| 65 | } |
| 66 | |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 67 | static int dm_dump(struct udevice *dev) |
Simon Glass | 0681195 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 68 | { |
| 69 | if (!dev) |
| 70 | return -EINVAL; |
| 71 | return display_succ(dev, ""); |
| 72 | } |
| 73 | |
| 74 | static int do_dm_dump_all(cmd_tbl_t *cmdtp, int flag, int argc, |
| 75 | char * const argv[]) |
| 76 | { |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 77 | struct udevice *root; |
Simon Glass | 0681195 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 78 | |
| 79 | root = dm_root(); |
Simon Glass | 184b1b7 | 2014-06-11 23:29:51 -0600 | [diff] [blame] | 80 | printf("ROOT %08lx\n", (ulong)map_to_sysmem(root)); |
Simon Glass | 0681195 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 81 | return dm_dump(root); |
| 82 | } |
| 83 | |
| 84 | static int do_dm_dump_uclass(cmd_tbl_t *cmdtp, int flag, int argc, |
| 85 | char * const argv[]) |
| 86 | { |
| 87 | struct uclass *uc; |
| 88 | int ret; |
| 89 | int id; |
| 90 | |
| 91 | for (id = 0; id < UCLASS_COUNT; id++) { |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 92 | struct udevice *dev; |
Simon Glass | 0681195 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 93 | |
| 94 | ret = uclass_get(id, &uc); |
| 95 | if (ret) |
| 96 | continue; |
| 97 | |
| 98 | printf("uclass %d: %s\n", id, uc->uc_drv->name); |
Simon Glass | 4e8bc21 | 2014-07-23 06:55:11 -0600 | [diff] [blame] | 99 | if (list_empty(&uc->dev_head)) |
| 100 | continue; |
| 101 | list_for_each_entry(dev, &uc->dev_head, uclass_node) { |
Simon Glass | fffa24d | 2014-07-23 06:55:10 -0600 | [diff] [blame] | 102 | dm_display_line(dev, ""); |
Simon Glass | 0681195 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 103 | } |
| 104 | puts("\n"); |
| 105 | } |
| 106 | |
| 107 | return 0; |
| 108 | } |
| 109 | |
Simon Glass | b6a49a7 | 2014-06-11 23:29:50 -0600 | [diff] [blame] | 110 | #ifdef CONFIG_DM_TEST |
Simon Glass | 0681195 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 111 | static int do_dm_test(cmd_tbl_t *cmdtp, int flag, int argc, |
| 112 | char * const argv[]) |
| 113 | { |
| 114 | return dm_test_main(); |
| 115 | } |
Simon Glass | b6a49a7 | 2014-06-11 23:29:50 -0600 | [diff] [blame] | 116 | #define TEST_HELP "\ndm test Run tests" |
| 117 | #else |
| 118 | #define TEST_HELP |
| 119 | #endif |
Simon Glass | 0681195 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 120 | |
| 121 | static cmd_tbl_t test_commands[] = { |
| 122 | U_BOOT_CMD_MKENT(tree, 0, 1, do_dm_dump_all, "", ""), |
| 123 | U_BOOT_CMD_MKENT(uclass, 1, 1, do_dm_dump_uclass, "", ""), |
Simon Glass | b6a49a7 | 2014-06-11 23:29:50 -0600 | [diff] [blame] | 124 | #ifdef CONFIG_DM_TEST |
Simon Glass | 0681195 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 125 | U_BOOT_CMD_MKENT(test, 1, 1, do_dm_test, "", ""), |
Simon Glass | b6a49a7 | 2014-06-11 23:29:50 -0600 | [diff] [blame] | 126 | #endif |
Simon Glass | 0681195 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 127 | }; |
| 128 | |
| 129 | static int do_dm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 130 | { |
| 131 | cmd_tbl_t *test_cmd; |
| 132 | int ret; |
| 133 | |
| 134 | if (argc != 2) |
| 135 | return CMD_RET_USAGE; |
| 136 | test_cmd = find_cmd_tbl(argv[1], test_commands, |
| 137 | ARRAY_SIZE(test_commands)); |
| 138 | argc -= 2; |
| 139 | argv += 2; |
| 140 | if (!test_cmd || argc > test_cmd->maxargs) |
| 141 | return CMD_RET_USAGE; |
| 142 | |
| 143 | ret = test_cmd->cmd(test_cmd, flag, argc, argv); |
| 144 | |
| 145 | return cmd_process_error(test_cmd, ret); |
| 146 | } |
| 147 | |
| 148 | U_BOOT_CMD( |
| 149 | dm, 2, 1, do_dm, |
| 150 | "Driver model low level access", |
Simon Glass | fffa24d | 2014-07-23 06:55:10 -0600 | [diff] [blame] | 151 | "tree Dump driver model tree ('*' = activated)\n" |
Simon Glass | b6a49a7 | 2014-06-11 23:29:50 -0600 | [diff] [blame] | 152 | "dm uclass Dump list of instances for each uclass" |
| 153 | TEST_HELP |
Simon Glass | 0681195 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 154 | ); |