blob: 4704049aee5e16113c7d08fdd27fdd46e547359c [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass304fbef2015-06-23 15:38:35 -06002/*
3 * Copyright (c) 2015 Google, Inc
Simon Glass304fbef2015-06-23 15:38:35 -06004 */
5
6#include <common.h>
7#include <dm.h>
8#include <mapmem.h>
9#include <dm/root.h>
Masahiro Yamadafce136a2017-06-22 17:10:11 +090010#include <dm/util.h>
Jean-Jacques Hiblot999b2042018-08-09 16:17:43 +020011#include <dm/uclass-internal.h>
Simon Glass304fbef2015-06-23 15:38:35 -060012
13static void show_devices(struct udevice *dev, int depth, int last_flag)
14{
15 int i, is_last;
16 struct udevice *child;
Simon Glass304fbef2015-06-23 15:38:35 -060017
Liviu Dudau5197daf2018-10-15 10:03:06 +010018 /* print the first 20 characters to not break the tree-format. */
Patrick Delaunay2a43dbd2019-09-30 10:19:13 +020019 printf(" %-10.10s %3d [ %c ] %-20.20s ", dev->uclass->uc_drv->name,
Jean-Jacques Hiblot999b2042018-08-09 16:17:43 +020020 dev_get_uclass_index(dev, NULL),
Simon Glassee3e5202017-08-02 12:12:02 -060021 dev->flags & DM_FLAG_ACTIVATED ? '+' : ' ', dev->driver->name);
Simon Glass304fbef2015-06-23 15:38:35 -060022
23 for (i = depth; i >= 0; i--) {
24 is_last = (last_flag >> i) & 1;
25 if (i) {
26 if (is_last)
27 printf(" ");
28 else
29 printf("| ");
30 } else {
31 if (is_last)
32 printf("`-- ");
33 else
34 printf("|-- ");
35 }
36 }
37
38 printf("%s\n", dev->name);
39
40 list_for_each_entry(child, &dev->child_head, sibling_node) {
41 is_last = list_is_last(&child->sibling_node, &dev->child_head);
42 show_devices(child, depth + 1, (last_flag << 1) | is_last);
43 }
44}
45
46void dm_dump_all(void)
47{
48 struct udevice *root;
49
50 root = dm_root();
51 if (root) {
Simon Glass54d2cfe2018-12-05 18:42:52 -070052 printf(" Class Index Probed Driver Name\n");
Liviu Dudau5197daf2018-10-15 10:03:06 +010053 printf("-----------------------------------------------------------\n");
Simon Glass304fbef2015-06-23 15:38:35 -060054 show_devices(root, -1, 0);
55 }
56}
57
58/**
59 * dm_display_line() - Display information about a single device
60 *
61 * Displays a single line of information with an option prefix
62 *
63 * @dev: Device to display
64 */
Jean-Jacques Hiblot999b2042018-08-09 16:17:43 +020065static void dm_display_line(struct udevice *dev, int index)
Simon Glass304fbef2015-06-23 15:38:35 -060066{
Patrick Delaunay2a43dbd2019-09-30 10:19:13 +020067 printf("%-3i %c %s @ %08lx", index,
Simon Glass304fbef2015-06-23 15:38:35 -060068 dev->flags & DM_FLAG_ACTIVATED ? '*' : ' ',
69 dev->name, (ulong)map_to_sysmem(dev));
70 if (dev->seq != -1 || dev->req_seq != -1)
71 printf(", seq %d, (req %d)", dev->seq, dev->req_seq);
72 puts("\n");
73}
74
75void dm_dump_uclass(void)
76{
77 struct uclass *uc;
78 int ret;
79 int id;
80
81 for (id = 0; id < UCLASS_COUNT; id++) {
82 struct udevice *dev;
Jean-Jacques Hiblot999b2042018-08-09 16:17:43 +020083 int i = 0;
Simon Glass304fbef2015-06-23 15:38:35 -060084
85 ret = uclass_get(id, &uc);
86 if (ret)
87 continue;
88
89 printf("uclass %d: %s\n", id, uc->uc_drv->name);
90 if (list_empty(&uc->dev_head))
91 continue;
Liviu Dudau81f351d2018-09-28 14:12:55 +010092 uclass_foreach_dev(dev, uc) {
Jean-Jacques Hiblot999b2042018-08-09 16:17:43 +020093 dm_display_line(dev, i);
94 i++;
Simon Glass304fbef2015-06-23 15:38:35 -060095 }
96 puts("\n");
97 }
98}