135-clk-Avoid-sending-high-rates-to-downstream-clocks-du.patch 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. From 39d42ce5031d2a4f92fa203b87acfbab340b15a2 Mon Sep 17 00:00:00 2001
  2. From: Stephen Boyd <sboyd@codeaurora.org>
  3. Date: Fri, 20 Mar 2015 23:45:22 -0700
  4. Subject: [PATCH 2/2] clk: Avoid sending high rates to downstream clocks during
  5. set_rate
  6. If a clock is on and we call clk_set_rate() on it we may get into
  7. a situation where the clock temporarily increases in rate
  8. dramatically while we walk the tree and call .set_rate() ops. For
  9. example, consider a case where a PLL feeds into a divider.
  10. Initially the divider is set to divide by 1 and the PLL is
  11. running fairly slow (100MHz). The downstream consumer of the
  12. divider output can only handle rates =< 400 MHz, but the divider
  13. can only choose between divisors of 1 and 4.
  14. +-----+ +----------------+
  15. | PLL |-->| div 1 or div 4 |---> consumer device
  16. +-----+ +----------------+
  17. To achieve a rate of 400MHz on the output of the divider, we
  18. would have to set the rate of the PLL to 1.6 GHz and then divide
  19. it by 4. The current code would set the PLL to 1.6GHz first while
  20. the divider is still set to 1, thus causing the downstream
  21. consumer of the clock to receive a few clock cycles of 1.6GHz
  22. clock (far beyond it's maximum acceptable rate). We should be
  23. changing the divider first before increasing the PLL rate to
  24. avoid this problem.
  25. Therefore, set the rate of any child clocks that are increasing
  26. in rate from their current rate so that they can increase their
  27. dividers if necessary. We assume that there isn't such a thing as
  28. minimum rate requirements.
  29. Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
  30. Signed-off-by: Ram Chandra Jangir <rjangi@codeaurora.org>
  31. ---
  32. drivers/clk/clk.c | 34 ++++++++++++++++++++++------------
  33. 1 file changed, 22 insertions(+), 12 deletions(-)
  34. --- a/drivers/clk/clk.c
  35. +++ b/drivers/clk/clk.c
  36. @@ -1427,21 +1427,24 @@ static struct clk_core *clk_propagate_ra
  37. * walk down a subtree and set the new rates notifying the rate
  38. * change on the way
  39. */
  40. -static void clk_change_rate(struct clk_core *core)
  41. +static void
  42. +clk_change_rate(struct clk_core *core, unsigned long best_parent_rate)
  43. {
  44. struct clk_core *child;
  45. struct hlist_node *tmp;
  46. unsigned long old_rate;
  47. - unsigned long best_parent_rate = 0;
  48. bool skip_set_rate = false;
  49. struct clk_core *old_parent;
  50. - old_rate = core->rate;
  51. + hlist_for_each_entry(child, &core->children, child_node) {
  52. + /* Skip children who will be reparented to another clock */
  53. + if (child->new_parent && child->new_parent != core)
  54. + continue;
  55. + if (child->new_rate > child->rate)
  56. + clk_change_rate(child, core->new_rate);
  57. + }
  58. - if (core->new_parent)
  59. - best_parent_rate = core->new_parent->rate;
  60. - else if (core->parent)
  61. - best_parent_rate = core->parent->rate;
  62. + old_rate = core->rate;
  63. if (core->new_parent && core->new_parent != core->parent) {
  64. old_parent = __clk_set_parent_before(core, core->new_parent);
  65. @@ -1467,7 +1470,7 @@ static void clk_change_rate(struct clk_c
  66. trace_clk_set_rate_complete(core, core->new_rate);
  67. - core->rate = clk_recalc(core, best_parent_rate);
  68. + core->rate = core->new_rate;
  69. if (core->notifier_count && old_rate != core->rate)
  70. __clk_notify(core, POST_RATE_CHANGE, old_rate, core->rate);
  71. @@ -1483,12 +1486,13 @@ static void clk_change_rate(struct clk_c
  72. /* Skip children who will be reparented to another clock */
  73. if (child->new_parent && child->new_parent != core)
  74. continue;
  75. - clk_change_rate(child);
  76. + if (child->new_rate != child->rate)
  77. + clk_change_rate(child, core->new_rate);
  78. }
  79. /* handle the new child who might not be in core->children yet */
  80. - if (core->new_child)
  81. - clk_change_rate(core->new_child);
  82. + if (core->new_child && core->new_child->new_rate != core->new_child->rate)
  83. + clk_change_rate(core->new_child, core->new_rate);
  84. }
  85. static int clk_core_set_rate_nolock(struct clk_core *core,
  86. @@ -1497,6 +1501,7 @@ static int clk_core_set_rate_nolock(stru
  87. struct clk_core *top, *fail_clk;
  88. unsigned long rate = req_rate;
  89. int ret = 0;
  90. + unsigned long parent_rate;
  91. if (!core)
  92. return 0;
  93. @@ -1522,8 +1527,13 @@ static int clk_core_set_rate_nolock(stru
  94. return -EBUSY;
  95. }
  96. + if (top->parent)
  97. + parent_rate = top->parent->rate;
  98. + else
  99. + parent_rate = 0;
  100. +
  101. /* change the rates */
  102. - clk_change_rate(top);
  103. + clk_change_rate(top, parent_rate);
  104. core->req_rate = req_rate;