owl-composite.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. // SPDX-License-Identifier: GPL-2.0+
  2. //
  3. // OWL composite clock driver
  4. //
  5. // Copyright (c) 2014 Actions Semi Inc.
  6. // Author: David Liu <liuwei@actions-semi.com>
  7. //
  8. // Copyright (c) 2018 Linaro Ltd.
  9. // Author: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
  10. #include <linux/clk-provider.h>
  11. #include <linux/regmap.h>
  12. #include "owl-composite.h"
  13. static u8 owl_comp_get_parent(struct clk_hw *hw)
  14. {
  15. struct owl_composite *comp = hw_to_owl_comp(hw);
  16. return owl_mux_helper_get_parent(&comp->common, &comp->mux_hw);
  17. }
  18. static int owl_comp_set_parent(struct clk_hw *hw, u8 index)
  19. {
  20. struct owl_composite *comp = hw_to_owl_comp(hw);
  21. return owl_mux_helper_set_parent(&comp->common, &comp->mux_hw, index);
  22. }
  23. static void owl_comp_disable(struct clk_hw *hw)
  24. {
  25. struct owl_composite *comp = hw_to_owl_comp(hw);
  26. struct owl_clk_common *common = &comp->common;
  27. owl_gate_set(common, &comp->gate_hw, false);
  28. }
  29. static int owl_comp_enable(struct clk_hw *hw)
  30. {
  31. struct owl_composite *comp = hw_to_owl_comp(hw);
  32. struct owl_clk_common *common = &comp->common;
  33. owl_gate_set(common, &comp->gate_hw, true);
  34. return 0;
  35. }
  36. static int owl_comp_is_enabled(struct clk_hw *hw)
  37. {
  38. struct owl_composite *comp = hw_to_owl_comp(hw);
  39. struct owl_clk_common *common = &comp->common;
  40. return owl_gate_clk_is_enabled(common, &comp->gate_hw);
  41. }
  42. static long owl_comp_div_round_rate(struct clk_hw *hw, unsigned long rate,
  43. unsigned long *parent_rate)
  44. {
  45. struct owl_composite *comp = hw_to_owl_comp(hw);
  46. return owl_divider_helper_round_rate(&comp->common, &comp->rate.div_hw,
  47. rate, parent_rate);
  48. }
  49. static unsigned long owl_comp_div_recalc_rate(struct clk_hw *hw,
  50. unsigned long parent_rate)
  51. {
  52. struct owl_composite *comp = hw_to_owl_comp(hw);
  53. return owl_divider_helper_recalc_rate(&comp->common, &comp->rate.div_hw,
  54. parent_rate);
  55. }
  56. static int owl_comp_div_set_rate(struct clk_hw *hw, unsigned long rate,
  57. unsigned long parent_rate)
  58. {
  59. struct owl_composite *comp = hw_to_owl_comp(hw);
  60. return owl_divider_helper_set_rate(&comp->common, &comp->rate.div_hw,
  61. rate, parent_rate);
  62. }
  63. static long owl_comp_fact_round_rate(struct clk_hw *hw, unsigned long rate,
  64. unsigned long *parent_rate)
  65. {
  66. struct owl_composite *comp = hw_to_owl_comp(hw);
  67. return owl_factor_helper_round_rate(&comp->common,
  68. &comp->rate.factor_hw,
  69. rate, parent_rate);
  70. }
  71. static unsigned long owl_comp_fact_recalc_rate(struct clk_hw *hw,
  72. unsigned long parent_rate)
  73. {
  74. struct owl_composite *comp = hw_to_owl_comp(hw);
  75. return owl_factor_helper_recalc_rate(&comp->common,
  76. &comp->rate.factor_hw,
  77. parent_rate);
  78. }
  79. static int owl_comp_fact_set_rate(struct clk_hw *hw, unsigned long rate,
  80. unsigned long parent_rate)
  81. {
  82. struct owl_composite *comp = hw_to_owl_comp(hw);
  83. return owl_factor_helper_set_rate(&comp->common,
  84. &comp->rate.factor_hw,
  85. rate, parent_rate);
  86. }
  87. static long owl_comp_fix_fact_round_rate(struct clk_hw *hw, unsigned long rate,
  88. unsigned long *parent_rate)
  89. {
  90. struct owl_composite *comp = hw_to_owl_comp(hw);
  91. struct clk_fixed_factor *fix_fact_hw = &comp->rate.fix_fact_hw;
  92. return comp->fix_fact_ops->round_rate(&fix_fact_hw->hw, rate, parent_rate);
  93. }
  94. static unsigned long owl_comp_fix_fact_recalc_rate(struct clk_hw *hw,
  95. unsigned long parent_rate)
  96. {
  97. struct owl_composite *comp = hw_to_owl_comp(hw);
  98. struct clk_fixed_factor *fix_fact_hw = &comp->rate.fix_fact_hw;
  99. return comp->fix_fact_ops->recalc_rate(&fix_fact_hw->hw, parent_rate);
  100. }
  101. static int owl_comp_fix_fact_set_rate(struct clk_hw *hw, unsigned long rate,
  102. unsigned long parent_rate)
  103. {
  104. /*
  105. * We must report success but we can do so unconditionally because
  106. * owl_comp_fix_fact_round_rate returns values that ensure this call is
  107. * a nop.
  108. */
  109. return 0;
  110. }
  111. const struct clk_ops owl_comp_div_ops = {
  112. /* mux_ops */
  113. .get_parent = owl_comp_get_parent,
  114. .set_parent = owl_comp_set_parent,
  115. /* gate_ops */
  116. .disable = owl_comp_disable,
  117. .enable = owl_comp_enable,
  118. .is_enabled = owl_comp_is_enabled,
  119. /* div_ops */
  120. .round_rate = owl_comp_div_round_rate,
  121. .recalc_rate = owl_comp_div_recalc_rate,
  122. .set_rate = owl_comp_div_set_rate,
  123. };
  124. const struct clk_ops owl_comp_fact_ops = {
  125. /* mux_ops */
  126. .get_parent = owl_comp_get_parent,
  127. .set_parent = owl_comp_set_parent,
  128. /* gate_ops */
  129. .disable = owl_comp_disable,
  130. .enable = owl_comp_enable,
  131. .is_enabled = owl_comp_is_enabled,
  132. /* fact_ops */
  133. .round_rate = owl_comp_fact_round_rate,
  134. .recalc_rate = owl_comp_fact_recalc_rate,
  135. .set_rate = owl_comp_fact_set_rate,
  136. };
  137. const struct clk_ops owl_comp_fix_fact_ops = {
  138. /* gate_ops */
  139. .disable = owl_comp_disable,
  140. .enable = owl_comp_enable,
  141. .is_enabled = owl_comp_is_enabled,
  142. /* fix_fact_ops */
  143. .round_rate = owl_comp_fix_fact_round_rate,
  144. .recalc_rate = owl_comp_fix_fact_recalc_rate,
  145. .set_rate = owl_comp_fix_fact_set_rate,
  146. };
  147. const struct clk_ops owl_comp_pass_ops = {
  148. /* mux_ops */
  149. .get_parent = owl_comp_get_parent,
  150. .set_parent = owl_comp_set_parent,
  151. /* gate_ops */
  152. .disable = owl_comp_disable,
  153. .enable = owl_comp_enable,
  154. .is_enabled = owl_comp_is_enabled,
  155. };