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

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