187-clk-sunxi-automatic-reparenting.patch 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. From b416520f239aeaa4207ebe84c22247cff2da444f Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Emilio=20L=C3=B3pez?= <emilio@elopez.com.ar>
  3. Date: Thu, 5 Sep 2013 19:52:41 -0300
  4. Subject: [PATCH] clk: sunxi: factors: automatic reparenting support
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. This commit implements .determine_rate, so that our factor clocks can be
  9. reparented when needed.
  10. Signed-off-by: Emilio López <emilio@elopez.com.ar>
  11. ---
  12. drivers/clk/sunxi/clk-factors.c | 36 ++++++++++++++++++++++++++++++++++++
  13. 1 file changed, 36 insertions(+)
  14. --- a/drivers/clk/sunxi/clk-factors.c
  15. +++ b/drivers/clk/sunxi/clk-factors.c
  16. @@ -77,6 +77,41 @@ static long clk_factors_round_rate(struc
  17. return rate;
  18. }
  19. +static long clk_factors_determine_rate(struct clk_hw *hw, unsigned long rate,
  20. + unsigned long *best_parent_rate,
  21. + struct clk **best_parent_p)
  22. +{
  23. + struct clk *clk = hw->clk, *parent, *best_parent = NULL;
  24. + int i, num_parents;
  25. + unsigned long parent_rate, best = 0, child_rate, best_child_rate = 0;
  26. +
  27. + /* find the parent that can help provide the fastest rate <= rate */
  28. + num_parents = __clk_get_num_parents(clk);
  29. + for (i = 0; i < num_parents; i++) {
  30. + parent = clk_get_parent_by_index(clk, i);
  31. + if (!parent)
  32. + continue;
  33. + if (__clk_get_flags(clk) & CLK_SET_RATE_PARENT)
  34. + parent_rate = __clk_round_rate(parent, rate);
  35. + else
  36. + parent_rate = __clk_get_rate(parent);
  37. +
  38. + child_rate = clk_factors_round_rate(hw, rate, &parent_rate);
  39. +
  40. + if (child_rate <= rate && child_rate > best_child_rate) {
  41. + best_parent = parent;
  42. + best = parent_rate;
  43. + best_child_rate = child_rate;
  44. + }
  45. + }
  46. +
  47. + if (best_parent)
  48. + *best_parent_p = best_parent;
  49. + *best_parent_rate = best;
  50. +
  51. + return best_child_rate;
  52. +}
  53. +
  54. static int clk_factors_set_rate(struct clk_hw *hw, unsigned long rate,
  55. unsigned long parent_rate)
  56. {
  57. @@ -113,6 +148,7 @@ static int clk_factors_set_rate(struct c
  58. }
  59. const struct clk_ops clk_factors_ops = {
  60. + .determine_rate = clk_factors_determine_rate,
  61. .recalc_rate = clk_factors_recalc_rate,
  62. .round_rate = clk_factors_round_rate,
  63. .set_rate = clk_factors_set_rate,