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