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