0252-clk-bcm2835-add-a-round-up-ability-to-the-clock-divi.patch 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. From 929fdf6bd4f3dcbe4d545e920ec41437225b777f Mon Sep 17 00:00:00 2001
  2. From: Remi Pommarel <repk@triplefau.lt>
  3. Date: Sun, 6 Dec 2015 17:22:46 +0100
  4. Subject: [PATCH] clk: bcm2835: add a round up ability to the clock divisor
  5. Make bcm2835_clock_choose_div to optionally round up the chosen MASH divisor
  6. so that the resulting average rate will not be higher than the requested one.
  7. Signed-off-by: Remi Pommarel <repk@triplefau.lt>
  8. Reviewed-by: Eric Anholt <eric@anholt.net>
  9. Signed-off-by: Michael Turquette <mturquette@baylibre.com>
  10. (cherry picked from commit 9c95b32ca09364e4687b72c4e17b78dc1c420026)
  11. ---
  12. drivers/clk/bcm/clk-bcm2835.c | 22 ++++++++++++----------
  13. 1 file changed, 12 insertions(+), 10 deletions(-)
  14. --- a/drivers/clk/bcm/clk-bcm2835.c
  15. +++ b/drivers/clk/bcm/clk-bcm2835.c
  16. @@ -1172,22 +1172,24 @@ static int bcm2835_clock_is_on(struct cl
  17. static u32 bcm2835_clock_choose_div(struct clk_hw *hw,
  18. unsigned long rate,
  19. - unsigned long parent_rate)
  20. + unsigned long parent_rate,
  21. + bool round_up)
  22. {
  23. struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
  24. const struct bcm2835_clock_data *data = clock->data;
  25. - u32 unused_frac_mask = GENMASK(CM_DIV_FRAC_BITS - data->frac_bits, 0);
  26. + u32 unused_frac_mask =
  27. + GENMASK(CM_DIV_FRAC_BITS - data->frac_bits, 0) >> 1;
  28. u64 temp = (u64)parent_rate << CM_DIV_FRAC_BITS;
  29. + u64 rem;
  30. u32 div;
  31. - do_div(temp, rate);
  32. + rem = do_div(temp, rate);
  33. div = temp;
  34. - /* Round and mask off the unused bits */
  35. - if (unused_frac_mask != 0) {
  36. - div += unused_frac_mask >> 1;
  37. - div &= ~unused_frac_mask;
  38. - }
  39. + /* Round up and mask off the unused bits */
  40. + if (round_up && ((div & unused_frac_mask) != 0 || rem != 0))
  41. + div += unused_frac_mask + 1;
  42. + div &= ~unused_frac_mask;
  43. /* clamp to min divider of 1 */
  44. div = max_t(u32, div, 1 << CM_DIV_FRAC_BITS);
  45. @@ -1227,7 +1229,7 @@ static long bcm2835_clock_round_rate(str
  46. unsigned long *parent_rate)
  47. {
  48. struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
  49. - u32 div = bcm2835_clock_choose_div(hw, rate, *parent_rate);
  50. + u32 div = bcm2835_clock_choose_div(hw, rate, *parent_rate, false);
  51. return bcm2835_clock_rate_from_divisor(clock, *parent_rate, div);
  52. }
  53. @@ -1296,7 +1298,7 @@ static int bcm2835_clock_set_rate(struct
  54. struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
  55. struct bcm2835_cprman *cprman = clock->cprman;
  56. const struct bcm2835_clock_data *data = clock->data;
  57. - u32 div = bcm2835_clock_choose_div(hw, rate, parent_rate);
  58. + u32 div = bcm2835_clock_choose_div(hw, rate, parent_rate, false);
  59. cprman_write(cprman, data->div_reg, div);