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