0581-clk-bcm-Support-rate-change-propagation-on-bcm2835-c.patch 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. From e75f021850a698fec611538e8ff293c22a4604f5 Mon Sep 17 00:00:00 2001
  2. From: Boris Brezillon <boris.brezillon@free-electrons.com>
  3. Date: Thu, 1 Dec 2016 22:00:19 +0100
  4. Subject: [PATCH] clk: bcm: Support rate change propagation on bcm2835 clocks
  5. Some peripheral clocks, like the VEC (Video EnCoder) clock need to be set
  6. to a precise rate (in our case 108MHz). With the current implementation,
  7. where peripheral clocks are not allowed to forward rate change requests
  8. to their parents, it is impossible to match this requirement unless the
  9. bootloader has configured things correctly, or a specific rate has been
  10. assigned through the DT (with the assigned-clk-rates property).
  11. Add a new field to struct bcm2835_clock_data to specify which parent
  12. clocks accept rate change propagation, and support set rate propagation
  13. in bcm2835_clock_determine_rate().
  14. Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
  15. Reviewed-by: Eric Anholt <eric@anholt.net>
  16. Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
  17. (cherry picked from commit 155e8b3b0ee320ae866b97dd31eba8a1f080a772)
  18. ---
  19. drivers/clk/bcm/clk-bcm2835.c | 67 ++++++++++++++++++++++++++++++++++++++++---
  20. 1 file changed, 63 insertions(+), 4 deletions(-)
  21. --- a/drivers/clk/bcm/clk-bcm2835.c
  22. +++ b/drivers/clk/bcm/clk-bcm2835.c
  23. @@ -457,6 +457,9 @@ struct bcm2835_clock_data {
  24. const char *const *parents;
  25. int num_mux_parents;
  26. + /* Bitmap encoding which parents accept rate change propagation. */
  27. + unsigned int set_rate_parent;
  28. +
  29. u32 ctl_reg;
  30. u32 div_reg;
  31. @@ -1061,10 +1064,60 @@ bcm2835_clk_is_pllc(struct clk_hw *hw)
  32. return strncmp(clk_hw_get_name(hw), "pllc", 4) == 0;
  33. }
  34. +static unsigned long bcm2835_clock_choose_div_and_prate(struct clk_hw *hw,
  35. + int parent_idx,
  36. + unsigned long rate,
  37. + u32 *div,
  38. + unsigned long *prate)
  39. +{
  40. + struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
  41. + struct bcm2835_cprman *cprman = clock->cprman;
  42. + const struct bcm2835_clock_data *data = clock->data;
  43. + unsigned long best_rate;
  44. + u32 curdiv, mindiv, maxdiv;
  45. + struct clk_hw *parent;
  46. +
  47. + parent = clk_hw_get_parent_by_index(hw, parent_idx);
  48. +
  49. + if (!(BIT(parent_idx) & data->set_rate_parent)) {
  50. + *prate = clk_hw_get_rate(parent);
  51. + *div = bcm2835_clock_choose_div(hw, rate, *prate, true);
  52. +
  53. + return bcm2835_clock_rate_from_divisor(clock, *prate,
  54. + *div);
  55. + }
  56. +
  57. + if (data->frac_bits)
  58. + dev_warn(cprman->dev,
  59. + "frac bits are not used when propagating rate change");
  60. +
  61. + /* clamp to min divider of 2 if we're dealing with a mash clock */
  62. + mindiv = data->is_mash_clock ? 2 : 1;
  63. + maxdiv = BIT(data->int_bits) - 1;
  64. +
  65. + /* TODO: Be smart, and only test a subset of the available divisors. */
  66. + for (curdiv = mindiv; curdiv <= maxdiv; curdiv++) {
  67. + unsigned long tmp_rate;
  68. +
  69. + tmp_rate = clk_hw_round_rate(parent, rate * curdiv);
  70. + tmp_rate /= curdiv;
  71. + if (curdiv == mindiv ||
  72. + (tmp_rate > best_rate && tmp_rate <= rate))
  73. + best_rate = tmp_rate;
  74. +
  75. + if (best_rate == rate)
  76. + break;
  77. + }
  78. +
  79. + *div = curdiv << CM_DIV_FRAC_BITS;
  80. + *prate = curdiv * best_rate;
  81. +
  82. + return best_rate;
  83. +}
  84. +
  85. static int bcm2835_clock_determine_rate(struct clk_hw *hw,
  86. struct clk_rate_request *req)
  87. {
  88. - struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
  89. struct clk_hw *parent, *best_parent = NULL;
  90. bool current_parent_is_pllc;
  91. unsigned long rate, best_rate = 0;
  92. @@ -1092,9 +1145,8 @@ static int bcm2835_clock_determine_rate(
  93. if (bcm2835_clk_is_pllc(parent) && !current_parent_is_pllc)
  94. continue;
  95. - prate = clk_hw_get_rate(parent);
  96. - div = bcm2835_clock_choose_div(hw, req->rate, prate, true);
  97. - rate = bcm2835_clock_rate_from_divisor(clock, prate, div);
  98. + rate = bcm2835_clock_choose_div_and_prate(hw, i, req->rate,
  99. + &div, &prate);
  100. if (rate > best_rate && rate <= req->rate) {
  101. best_parent = parent;
  102. best_prate = prate;
  103. @@ -1314,6 +1366,13 @@ static struct clk *bcm2835_register_cloc
  104. if ((cprman_read(cprman, data->ctl_reg) & CM_ENABLE) == 0)
  105. init.flags &= ~CLK_IS_CRITICAL;
  106. + /*
  107. + * Pass the CLK_SET_RATE_PARENT flag if we are allowed to propagate
  108. + * rate changes on at least of the parents.
  109. + */
  110. + if (data->set_rate_parent)
  111. + init.flags |= CLK_SET_RATE_PARENT;
  112. +
  113. if (data->is_vpu_clock) {
  114. init.ops = &bcm2835_vpu_clock_clk_ops;
  115. } else {