2014-02-26 22:59:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013 Google, Inc
|
|
|
|
*
|
|
|
|
* (C) Copyright 2012
|
|
|
|
* Marek Vasut <marex@denx.de>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <malloc.h>
|
2015-03-22 22:08:59 +00:00
|
|
|
#include <mapmem.h>
|
2014-02-26 22:59:22 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <dm/root.h>
|
|
|
|
#include <dm/test.h>
|
|
|
|
#include <dm/uclass-internal.h>
|
|
|
|
|
2014-11-29 08:01:56 +00:00
|
|
|
static void show_devices(struct udevice *dev, int depth, int last_flag)
|
|
|
|
{
|
|
|
|
int i, is_last;
|
|
|
|
struct udevice *child;
|
|
|
|
char class_name[12];
|
|
|
|
|
|
|
|
/* print the first 11 characters to not break the tree-format. */
|
|
|
|
strlcpy(class_name, dev->uclass->uc_drv->name, sizeof(class_name));
|
|
|
|
printf(" %-11s [ %c ] ", class_name,
|
|
|
|
dev->flags & DM_FLAG_ACTIVATED ? '+' : ' ');
|
|
|
|
|
|
|
|
for (i = depth; i >= 0; i--) {
|
|
|
|
is_last = (last_flag >> i) & 1;
|
|
|
|
if (i) {
|
|
|
|
if (is_last)
|
|
|
|
printf(" ");
|
|
|
|
else
|
|
|
|
printf("| ");
|
|
|
|
} else {
|
|
|
|
if (is_last)
|
|
|
|
printf("`-- ");
|
|
|
|
else
|
|
|
|
printf("|-- ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("%s\n", dev->name);
|
|
|
|
|
|
|
|
list_for_each_entry(child, &dev->child_head, sibling_node) {
|
|
|
|
is_last = list_is_last(&child->sibling_node, &dev->child_head);
|
|
|
|
show_devices(child, depth + 1, (last_flag << 1) | is_last);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int do_dm_dump_all(cmd_tbl_t *cmdtp, int flag, int argc,
|
|
|
|
char * const argv[])
|
|
|
|
{
|
|
|
|
struct udevice *root;
|
|
|
|
|
|
|
|
root = dm_root();
|
|
|
|
if (root) {
|
|
|
|
printf(" Class Probed Name\n");
|
|
|
|
printf("----------------------------------------\n");
|
|
|
|
show_devices(root, -1, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-07-23 12:55:10 +00:00
|
|
|
/**
|
|
|
|
* dm_display_line() - Display information about a single device
|
|
|
|
*
|
|
|
|
* Displays a single line of information with an option prefix
|
|
|
|
*
|
|
|
|
* @dev: Device to display
|
|
|
|
*/
|
2014-11-29 08:01:56 +00:00
|
|
|
static void dm_display_line(struct udevice *dev)
|
2014-07-23 12:55:10 +00:00
|
|
|
{
|
2014-11-29 08:01:56 +00:00
|
|
|
printf("- %c %s @ %08lx",
|
2014-07-23 12:55:10 +00:00
|
|
|
dev->flags & DM_FLAG_ACTIVATED ? '*' : ' ',
|
|
|
|
dev->name, (ulong)map_to_sysmem(dev));
|
2015-03-05 19:25:23 +00:00
|
|
|
if (dev->seq != -1 || dev->req_seq != -1)
|
2015-03-25 18:23:03 +00:00
|
|
|
printf(", seq %d, (req %d)", dev->seq, dev->req_seq);
|
2014-07-23 12:55:10 +00:00
|
|
|
puts("\n");
|
|
|
|
}
|
|
|
|
|
2014-02-26 22:59:22 +00:00
|
|
|
static int do_dm_dump_uclass(cmd_tbl_t *cmdtp, int flag, int argc,
|
|
|
|
char * const argv[])
|
|
|
|
{
|
|
|
|
struct uclass *uc;
|
|
|
|
int ret;
|
|
|
|
int id;
|
|
|
|
|
|
|
|
for (id = 0; id < UCLASS_COUNT; id++) {
|
2014-05-22 10:43:05 +00:00
|
|
|
struct udevice *dev;
|
2014-02-26 22:59:22 +00:00
|
|
|
|
|
|
|
ret = uclass_get(id, &uc);
|
|
|
|
if (ret)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
printf("uclass %d: %s\n", id, uc->uc_drv->name);
|
2014-07-23 12:55:11 +00:00
|
|
|
if (list_empty(&uc->dev_head))
|
|
|
|
continue;
|
|
|
|
list_for_each_entry(dev, &uc->dev_head, uclass_node) {
|
2014-11-29 08:01:56 +00:00
|
|
|
dm_display_line(dev);
|
2014-02-26 22:59:22 +00:00
|
|
|
}
|
|
|
|
puts("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-12 05:29:50 +00:00
|
|
|
#ifdef CONFIG_DM_TEST
|
2014-02-26 22:59:22 +00:00
|
|
|
static int do_dm_test(cmd_tbl_t *cmdtp, int flag, int argc,
|
|
|
|
char * const argv[])
|
|
|
|
{
|
2015-03-25 18:23:04 +00:00
|
|
|
const char *test_name = NULL;
|
|
|
|
|
|
|
|
if (argc > 0)
|
|
|
|
test_name = argv[0];
|
|
|
|
|
|
|
|
return dm_test_main(test_name);
|
2014-02-26 22:59:22 +00:00
|
|
|
}
|
2014-06-12 05:29:50 +00:00
|
|
|
#define TEST_HELP "\ndm test Run tests"
|
|
|
|
#else
|
|
|
|
#define TEST_HELP
|
|
|
|
#endif
|
2014-02-26 22:59:22 +00:00
|
|
|
|
|
|
|
static cmd_tbl_t test_commands[] = {
|
|
|
|
U_BOOT_CMD_MKENT(tree, 0, 1, do_dm_dump_all, "", ""),
|
|
|
|
U_BOOT_CMD_MKENT(uclass, 1, 1, do_dm_dump_uclass, "", ""),
|
2014-06-12 05:29:50 +00:00
|
|
|
#ifdef CONFIG_DM_TEST
|
2014-02-26 22:59:22 +00:00
|
|
|
U_BOOT_CMD_MKENT(test, 1, 1, do_dm_test, "", ""),
|
2014-06-12 05:29:50 +00:00
|
|
|
#endif
|
2014-02-26 22:59:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int do_dm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
|
|
|
{
|
|
|
|
cmd_tbl_t *test_cmd;
|
|
|
|
int ret;
|
|
|
|
|
2015-03-25 18:23:04 +00:00
|
|
|
if (argc < 2)
|
2014-02-26 22:59:22 +00:00
|
|
|
return CMD_RET_USAGE;
|
|
|
|
test_cmd = find_cmd_tbl(argv[1], test_commands,
|
|
|
|
ARRAY_SIZE(test_commands));
|
|
|
|
argc -= 2;
|
|
|
|
argv += 2;
|
|
|
|
if (!test_cmd || argc > test_cmd->maxargs)
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
|
|
|
|
ret = test_cmd->cmd(test_cmd, flag, argc, argv);
|
|
|
|
|
|
|
|
return cmd_process_error(test_cmd, ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_CMD(
|
2015-03-25 18:23:04 +00:00
|
|
|
dm, 3, 1, do_dm,
|
2014-02-26 22:59:22 +00:00
|
|
|
"Driver model low level access",
|
2014-07-23 12:55:10 +00:00
|
|
|
"tree Dump driver model tree ('*' = activated)\n"
|
2014-06-12 05:29:50 +00:00
|
|
|
"dm uclass Dump list of instances for each uclass"
|
|
|
|
TEST_HELP
|
2014-02-26 22:59:22 +00:00
|
|
|
);
|