clk.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2013 Xilinx, Inc.
  4. */
  5. #include <common.h>
  6. #include <command.h>
  7. #include <clk.h>
  8. #if defined(CONFIG_DM) && defined(CONFIG_CLK)
  9. #include <dm.h>
  10. #include <dm/device.h>
  11. #include <dm/root.h>
  12. #include <dm/device-internal.h>
  13. #include <linux/clk-provider.h>
  14. #endif
  15. #if defined(CONFIG_DM) && defined(CONFIG_CLK)
  16. static void show_clks(struct udevice *dev, int depth, int last_flag)
  17. {
  18. int i, is_last;
  19. struct udevice *child;
  20. struct clk *clkp;
  21. u32 rate;
  22. clkp = dev_get_clk_ptr(dev);
  23. if (device_get_uclass_id(dev) == UCLASS_CLK && clkp) {
  24. depth++;
  25. rate = clk_get_rate(clkp);
  26. printf(" %-12u %8d ", rate, clkp->enable_count);
  27. for (i = depth; i >= 0; i--) {
  28. is_last = (last_flag >> i) & 1;
  29. if (i) {
  30. if (is_last)
  31. printf(" ");
  32. else
  33. printf("| ");
  34. } else {
  35. if (is_last)
  36. printf("`-- ");
  37. else
  38. printf("|-- ");
  39. }
  40. }
  41. printf("%s\n", dev->name);
  42. }
  43. list_for_each_entry(child, &dev->child_head, sibling_node) {
  44. is_last = list_is_last(&child->sibling_node, &dev->child_head);
  45. show_clks(child, depth, (last_flag << 1) | is_last);
  46. }
  47. }
  48. int __weak soc_clk_dump(void)
  49. {
  50. struct udevice *root;
  51. root = dm_root();
  52. if (root) {
  53. printf(" Rate Usecnt Name\n");
  54. printf("------------------------------------------\n");
  55. show_clks(root, -1, 0);
  56. }
  57. return 0;
  58. }
  59. #else
  60. int __weak soc_clk_dump(void)
  61. {
  62. puts("Not implemented\n");
  63. return 1;
  64. }
  65. #endif
  66. static int do_clk_dump(struct cmd_tbl *cmdtp, int flag, int argc,
  67. char *const argv[])
  68. {
  69. int ret;
  70. ret = soc_clk_dump();
  71. if (ret < 0) {
  72. printf("Clock dump error %d\n", ret);
  73. ret = CMD_RET_FAILURE;
  74. }
  75. return ret;
  76. }
  77. static struct cmd_tbl cmd_clk_sub[] = {
  78. U_BOOT_CMD_MKENT(dump, 1, 1, do_clk_dump, "", ""),
  79. };
  80. static int do_clk(struct cmd_tbl *cmdtp, int flag, int argc,
  81. char *const argv[])
  82. {
  83. struct cmd_tbl *c;
  84. if (argc < 2)
  85. return CMD_RET_USAGE;
  86. /* Strip off leading 'clk' command argument */
  87. argc--;
  88. argv++;
  89. c = find_cmd_tbl(argv[0], &cmd_clk_sub[0], ARRAY_SIZE(cmd_clk_sub));
  90. if (c)
  91. return c->cmd(cmdtp, flag, argc, argv);
  92. else
  93. return CMD_RET_USAGE;
  94. }
  95. #ifdef CONFIG_SYS_LONGHELP
  96. static char clk_help_text[] =
  97. "dump - Print clock frequencies";
  98. #endif
  99. U_BOOT_CMD(clk, 2, 1, do_clk, "CLK sub-system", clk_help_text);