cmd_dm.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. #include <common.h>
  10. #include <dm.h>
  11. #include <malloc.h>
  12. #include <errno.h>
  13. #include <asm/io.h>
  14. #include <dm/root.h>
  15. #include <dm/test.h>
  16. #include <dm/uclass-internal.h>
  17. static void show_devices(struct udevice *dev, int depth, int last_flag)
  18. {
  19. int i, is_last;
  20. struct udevice *child;
  21. char class_name[12];
  22. /* print the first 11 characters to not break the tree-format. */
  23. strlcpy(class_name, dev->uclass->uc_drv->name, sizeof(class_name));
  24. printf(" %-11s [ %c ] ", class_name,
  25. dev->flags & DM_FLAG_ACTIVATED ? '+' : ' ');
  26. for (i = depth; i >= 0; i--) {
  27. is_last = (last_flag >> i) & 1;
  28. if (i) {
  29. if (is_last)
  30. printf(" ");
  31. else
  32. printf("| ");
  33. } else {
  34. if (is_last)
  35. printf("`-- ");
  36. else
  37. printf("|-- ");
  38. }
  39. }
  40. printf("%s\n", dev->name);
  41. list_for_each_entry(child, &dev->child_head, sibling_node) {
  42. is_last = list_is_last(&child->sibling_node, &dev->child_head);
  43. show_devices(child, depth + 1, (last_flag << 1) | is_last);
  44. }
  45. }
  46. static int do_dm_dump_all(cmd_tbl_t *cmdtp, int flag, int argc,
  47. char * const argv[])
  48. {
  49. struct udevice *root;
  50. root = dm_root();
  51. if (root) {
  52. printf(" Class Probed Name\n");
  53. printf("----------------------------------------\n");
  54. show_devices(root, -1, 0);
  55. }
  56. return 0;
  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. */
  65. static void dm_display_line(struct udevice *dev)
  66. {
  67. printf("- %c %s @ %08lx",
  68. 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. static int do_dm_dump_uclass(cmd_tbl_t *cmdtp, int flag, int argc,
  75. char * const argv[])
  76. {
  77. struct uclass *uc;
  78. int ret;
  79. int id;
  80. for (id = 0; id < UCLASS_COUNT; id++) {
  81. struct udevice *dev;
  82. ret = uclass_get(id, &uc);
  83. if (ret)
  84. continue;
  85. printf("uclass %d: %s\n", id, uc->uc_drv->name);
  86. if (list_empty(&uc->dev_head))
  87. continue;
  88. list_for_each_entry(dev, &uc->dev_head, uclass_node) {
  89. dm_display_line(dev);
  90. }
  91. puts("\n");
  92. }
  93. return 0;
  94. }
  95. #ifdef CONFIG_DM_TEST
  96. static int do_dm_test(cmd_tbl_t *cmdtp, int flag, int argc,
  97. char * const argv[])
  98. {
  99. return dm_test_main();
  100. }
  101. #define TEST_HELP "\ndm test Run tests"
  102. #else
  103. #define TEST_HELP
  104. #endif
  105. static cmd_tbl_t test_commands[] = {
  106. U_BOOT_CMD_MKENT(tree, 0, 1, do_dm_dump_all, "", ""),
  107. U_BOOT_CMD_MKENT(uclass, 1, 1, do_dm_dump_uclass, "", ""),
  108. #ifdef CONFIG_DM_TEST
  109. U_BOOT_CMD_MKENT(test, 1, 1, do_dm_test, "", ""),
  110. #endif
  111. };
  112. static int do_dm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  113. {
  114. cmd_tbl_t *test_cmd;
  115. int ret;
  116. if (argc != 2)
  117. return CMD_RET_USAGE;
  118. test_cmd = find_cmd_tbl(argv[1], test_commands,
  119. ARRAY_SIZE(test_commands));
  120. argc -= 2;
  121. argv += 2;
  122. if (!test_cmd || argc > test_cmd->maxargs)
  123. return CMD_RET_USAGE;
  124. ret = test_cmd->cmd(test_cmd, flag, argc, argv);
  125. return cmd_process_error(test_cmd, ret);
  126. }
  127. U_BOOT_CMD(
  128. dm, 2, 1, do_dm,
  129. "Driver model low level access",
  130. "tree Dump driver model tree ('*' = activated)\n"
  131. "dm uclass Dump list of instances for each uclass"
  132. TEST_HELP
  133. );