cmd_clock.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * keystone2: commands for clocks
  4. *
  5. * (C) Copyright 2012-2014
  6. * Texas Instruments Incorporated, <www.ti.com>
  7. */
  8. #include <common.h>
  9. #include <command.h>
  10. #include <asm/arch/hardware.h>
  11. #include <asm/arch/clock.h>
  12. #include <asm/arch/psc_defs.h>
  13. struct pll_init_data cmd_pll_data = {
  14. .pll = MAIN_PLL,
  15. .pll_m = 16,
  16. .pll_d = 1,
  17. .pll_od = 2,
  18. };
  19. int do_pll_cmd(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
  20. {
  21. if (argc != 5)
  22. goto pll_cmd_usage;
  23. if (strncmp(argv[1], "pa", 2) == 0)
  24. cmd_pll_data.pll = PASS_PLL;
  25. #ifndef CONFIG_SOC_K2E
  26. else if (strncmp(argv[1], "arm", 3) == 0)
  27. cmd_pll_data.pll = TETRIS_PLL;
  28. #endif
  29. #ifdef CONFIG_SOC_K2HK
  30. else if (strncmp(argv[1], "ddr3a", 5) == 0)
  31. cmd_pll_data.pll = DDR3A_PLL;
  32. else if (strncmp(argv[1], "ddr3b", 5) == 0)
  33. cmd_pll_data.pll = DDR3B_PLL;
  34. #else
  35. else if (strncmp(argv[1], "ddr3", 4) == 0)
  36. cmd_pll_data.pll = DDR3_PLL;
  37. #endif
  38. else
  39. goto pll_cmd_usage;
  40. cmd_pll_data.pll_m = dectoul(argv[2], NULL);
  41. cmd_pll_data.pll_d = dectoul(argv[3], NULL);
  42. cmd_pll_data.pll_od = dectoul(argv[4], NULL);
  43. printf("Trying to set pll %d; mult %d; div %d; OD %d\n",
  44. cmd_pll_data.pll, cmd_pll_data.pll_m,
  45. cmd_pll_data.pll_d, cmd_pll_data.pll_od);
  46. init_pll(&cmd_pll_data);
  47. return 0;
  48. pll_cmd_usage:
  49. return cmd_usage(cmdtp);
  50. }
  51. U_BOOT_CMD(
  52. pllset, 5, 0, do_pll_cmd,
  53. "set pll multiplier and pre divider",
  54. PLLSET_CMD_LIST " <mult> <div> <OD>\n"
  55. );
  56. int do_getclk_cmd(struct cmd_tbl *cmdtp, int flag, int argc,
  57. char *const argv[])
  58. {
  59. unsigned int clk;
  60. unsigned long freq;
  61. if (argc != 2)
  62. goto getclk_cmd_usage;
  63. clk = dectoul(argv[1], NULL);
  64. freq = ks_clk_get_rate(clk);
  65. if (freq)
  66. printf("clock index [%d] - frequency %lu\n", clk, freq);
  67. else
  68. printf("clock index [%d] Not available\n", clk);
  69. return 0;
  70. getclk_cmd_usage:
  71. return cmd_usage(cmdtp);
  72. }
  73. U_BOOT_CMD(
  74. getclk, 2, 0, do_getclk_cmd,
  75. "get clock rate",
  76. "<clk index>\n"
  77. "The indexes for clocks:\n"
  78. CLOCK_INDEXES_LIST
  79. );
  80. int do_psc_cmd(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
  81. {
  82. int psc_module;
  83. int res;
  84. if (argc != 3)
  85. goto psc_cmd_usage;
  86. psc_module = dectoul(argv[1], NULL);
  87. if (strcmp(argv[2], "en") == 0) {
  88. res = psc_enable_module(psc_module);
  89. printf("psc_enable_module(%d) - %s\n", psc_module,
  90. (res) ? "ERROR" : "OK");
  91. return 0;
  92. }
  93. if (strcmp(argv[2], "di") == 0) {
  94. res = psc_disable_module(psc_module);
  95. printf("psc_disable_module(%d) - %s\n", psc_module,
  96. (res) ? "ERROR" : "OK");
  97. return 0;
  98. }
  99. if (strcmp(argv[2], "domain") == 0) {
  100. res = psc_disable_domain(psc_module);
  101. printf("psc_disable_domain(%d) - %s\n", psc_module,
  102. (res) ? "ERROR" : "OK");
  103. return 0;
  104. }
  105. psc_cmd_usage:
  106. return cmd_usage(cmdtp);
  107. }
  108. U_BOOT_CMD(
  109. psc, 3, 0, do_psc_cmd,
  110. "<enable/disable psc module os disable domain>",
  111. "<mod/domain index> <en|di|domain>\n"
  112. "Intended to control Power and Sleep Controller (PSC) domains and\n"
  113. "modules. The module or domain index exectly corresponds to ones\n"
  114. "listed in official TRM. For instance, to enable MSMC RAM clock\n"
  115. "domain use command: psc 14 en.\n"
  116. );