scmi_clock.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * Copyright (c) 2024, Rockchip, Inc. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <drivers/scmi-msg.h>
  7. #include <drivers/scmi.h>
  8. #include "scmi_clock.h"
  9. #pragma weak rockchip_scmi_clock_count
  10. #pragma weak rockchip_scmi_get_clock
  11. size_t rockchip_scmi_clock_count(unsigned int agent_id __unused)
  12. {
  13. return 0;
  14. }
  15. rk_scmi_clock_t *rockchip_scmi_get_clock(uint32_t agent_id __unused,
  16. uint32_t scmi_id __unused)
  17. {
  18. return NULL;
  19. }
  20. size_t plat_scmi_clock_count(unsigned int agent_id)
  21. {
  22. return rockchip_scmi_clock_count(agent_id);
  23. }
  24. const char *plat_scmi_clock_get_name(unsigned int agent_id,
  25. unsigned int scmi_id)
  26. {
  27. rk_scmi_clock_t *clock;
  28. clock = rockchip_scmi_get_clock(agent_id, scmi_id);
  29. if (clock == NULL)
  30. return NULL;
  31. return clock->name;
  32. }
  33. int32_t plat_scmi_clock_rates_array(unsigned int agent_id,
  34. unsigned int scmi_id,
  35. unsigned long *rates,
  36. size_t *nb_elts,
  37. uint32_t start_idx)
  38. {
  39. uint32_t i;
  40. unsigned long *rate_table;
  41. rk_scmi_clock_t *clock;
  42. clock = rockchip_scmi_get_clock(agent_id, scmi_id);
  43. if (clock == NULL)
  44. return SCMI_NOT_FOUND;
  45. rate_table = clock->rate_table;
  46. if (rate_table == NULL)
  47. return SCMI_NOT_SUPPORTED;
  48. if (rates == 0) {
  49. *nb_elts = clock->rate_cnt;
  50. goto out;
  51. }
  52. if (start_idx + *nb_elts > clock->rate_cnt)
  53. return SCMI_OUT_OF_RANGE;
  54. for (i = 0; i < *nb_elts; i++)
  55. rates[i] = rate_table[start_idx + i];
  56. out:
  57. return SCMI_SUCCESS;
  58. }
  59. int32_t plat_scmi_clock_rates_by_step(unsigned int agent_id __unused,
  60. unsigned int scmi_id __unused,
  61. unsigned long *steps __unused)
  62. {
  63. return SCMI_NOT_SUPPORTED;
  64. }
  65. unsigned long plat_scmi_clock_get_rate(unsigned int agent_id,
  66. unsigned int scmi_id)
  67. {
  68. rk_scmi_clock_t *clock;
  69. unsigned long rate = 0;
  70. clock = rockchip_scmi_get_clock(agent_id, scmi_id);
  71. if (clock == NULL)
  72. return 0;
  73. if (clock->clk_ops && clock->clk_ops->get_rate)
  74. rate = clock->clk_ops->get_rate(clock);
  75. /* return cur_rate if no get_rate ops or get_rate return 0 */
  76. if (rate == 0)
  77. rate = clock->cur_rate;
  78. return rate;
  79. }
  80. int32_t plat_scmi_clock_set_rate(unsigned int agent_id,
  81. unsigned int scmi_id,
  82. unsigned long rate)
  83. {
  84. rk_scmi_clock_t *clock;
  85. int32_t status = 0;
  86. clock = rockchip_scmi_get_clock(agent_id, scmi_id);
  87. if (clock == NULL)
  88. return SCMI_NOT_FOUND;
  89. if (clock->clk_ops && clock->clk_ops->set_rate) {
  90. status = clock->clk_ops->set_rate(clock, rate);
  91. if (status == SCMI_SUCCESS)
  92. clock->cur_rate = rate;
  93. } else {
  94. status = SCMI_NOT_SUPPORTED;
  95. }
  96. return status;
  97. }
  98. int32_t plat_scmi_clock_get_state(unsigned int agent_id,
  99. unsigned int scmi_id)
  100. {
  101. rk_scmi_clock_t *clock;
  102. clock = rockchip_scmi_get_clock(agent_id, scmi_id);
  103. if (clock == NULL)
  104. return 0;
  105. return clock->enable;
  106. }
  107. int32_t plat_scmi_clock_set_state(unsigned int agent_id,
  108. unsigned int scmi_id,
  109. bool enable_not_disable)
  110. {
  111. rk_scmi_clock_t *clock;
  112. int32_t status = 0;
  113. clock = rockchip_scmi_get_clock(agent_id, scmi_id);
  114. if (clock == NULL)
  115. return SCMI_NOT_FOUND;
  116. if (clock->clk_ops && clock->clk_ops->set_status) {
  117. status = clock->clk_ops->set_status(clock, enable_not_disable);
  118. if (status == SCMI_SUCCESS)
  119. clock->enable = enable_not_disable;
  120. } else {
  121. status = SCMI_NOT_SUPPORTED;
  122. }
  123. return status;
  124. }