0256-clk-bcm2835-correctly-enable-fractional-clock-suppor.patch 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. From d1b891afed88e5f675fa30f1dcc8e728472208ac Mon Sep 17 00:00:00 2001
  2. From: Martin Sperl <kernel@martin.sperl.org>
  3. Date: Mon, 29 Feb 2016 11:39:21 +0000
  4. Subject: [PATCH] clk: bcm2835: correctly enable fractional clock support
  5. The current driver calculates the clock divider with
  6. fractional support enabled.
  7. But it does not enable fractional support in the
  8. control register itself resulting in an integer only divider,
  9. but in clk_set_rate responds back the fractionally divided
  10. clock frequency.
  11. This patch enables fractional support in the control register
  12. whenever there is a fractional bit set in the requested clock divider.
  13. Mash clock limits are are also handled for the PWM clock
  14. applying the correct divider limits (2 and max_int) applicable to
  15. basic fractional divider support (mash order of 1).
  16. It also adds locking to protect the read/modify/write cycle of
  17. the register modification.
  18. Fixes: 41691b8862e2 ("clk: bcm2835: Add support for programming the
  19. audio domain clocks")
  20. Signed-off-by: Martin Sperl <kernel@martin.sperl.org>
  21. Signed-off-by: Eric Anholt <eric@anholt.net>
  22. Reviewed-by: Eric Anholt <eric@anholt.net>
  23. (cherry picked from commit 959ca92a3235fc4b17c1e18483fc390b3d612254)
  24. ---
  25. drivers/clk/bcm/clk-bcm2835.c | 45 +++++++++++++++++++++++++++++++++++++------
  26. 1 file changed, 39 insertions(+), 6 deletions(-)
  27. --- a/drivers/clk/bcm/clk-bcm2835.c
  28. +++ b/drivers/clk/bcm/clk-bcm2835.c
  29. @@ -51,6 +51,7 @@
  30. #define CM_GNRICCTL 0x000
  31. #define CM_GNRICDIV 0x004
  32. # define CM_DIV_FRAC_BITS 12
  33. +# define CM_DIV_FRAC_MASK GENMASK(CM_DIV_FRAC_BITS - 1, 0)
  34. #define CM_VPUCTL 0x008
  35. #define CM_VPUDIV 0x00c
  36. @@ -128,6 +129,7 @@
  37. # define CM_GATE BIT(CM_GATE_BIT)
  38. # define CM_BUSY BIT(7)
  39. # define CM_BUSYD BIT(8)
  40. +# define CM_FRAC BIT(9)
  41. # define CM_SRC_SHIFT 0
  42. # define CM_SRC_BITS 4
  43. # define CM_SRC_MASK 0xf
  44. @@ -647,6 +649,7 @@ struct bcm2835_clock_data {
  45. u32 frac_bits;
  46. bool is_vpu_clock;
  47. + bool is_mash_clock;
  48. };
  49. static const char *const bcm2835_clock_per_parents[] = {
  50. @@ -828,6 +831,7 @@ static const struct bcm2835_clock_data b
  51. .div_reg = CM_PWMDIV,
  52. .int_bits = 12,
  53. .frac_bits = 12,
  54. + .is_mash_clock = true,
  55. };
  56. struct bcm2835_pll {
  57. @@ -1204,7 +1208,7 @@ static u32 bcm2835_clock_choose_div(stru
  58. GENMASK(CM_DIV_FRAC_BITS - data->frac_bits, 0) >> 1;
  59. u64 temp = (u64)parent_rate << CM_DIV_FRAC_BITS;
  60. u64 rem;
  61. - u32 div;
  62. + u32 div, mindiv, maxdiv;
  63. rem = do_div(temp, rate);
  64. div = temp;
  65. @@ -1214,11 +1218,23 @@ static u32 bcm2835_clock_choose_div(stru
  66. div += unused_frac_mask + 1;
  67. div &= ~unused_frac_mask;
  68. - /* clamp to min divider of 1 */
  69. - div = max_t(u32, div, 1 << CM_DIV_FRAC_BITS);
  70. - /* clamp to the highest possible fractional divider */
  71. - div = min_t(u32, div, GENMASK(data->int_bits + CM_DIV_FRAC_BITS - 1,
  72. - CM_DIV_FRAC_BITS - data->frac_bits));
  73. + /* different clamping limits apply for a mash clock */
  74. + if (data->is_mash_clock) {
  75. + /* clamp to min divider of 2 */
  76. + mindiv = 2 << CM_DIV_FRAC_BITS;
  77. + /* clamp to the highest possible integer divider */
  78. + maxdiv = (BIT(data->int_bits) - 1) << CM_DIV_FRAC_BITS;
  79. + } else {
  80. + /* clamp to min divider of 1 */
  81. + mindiv = 1 << CM_DIV_FRAC_BITS;
  82. + /* clamp to the highest possible fractional divider */
  83. + maxdiv = GENMASK(data->int_bits + CM_DIV_FRAC_BITS - 1,
  84. + CM_DIV_FRAC_BITS - data->frac_bits);
  85. + }
  86. +
  87. + /* apply the clamping limits */
  88. + div = max_t(u32, div, mindiv);
  89. + div = min_t(u32, div, maxdiv);
  90. return div;
  91. }
  92. @@ -1312,9 +1328,26 @@ static int bcm2835_clock_set_rate(struct
  93. struct bcm2835_cprman *cprman = clock->cprman;
  94. const struct bcm2835_clock_data *data = clock->data;
  95. u32 div = bcm2835_clock_choose_div(hw, rate, parent_rate, false);
  96. + u32 ctl;
  97. +
  98. + spin_lock(&cprman->regs_lock);
  99. +
  100. + /*
  101. + * Setting up frac support
  102. + *
  103. + * In principle it is recommended to stop/start the clock first,
  104. + * but as we set CLK_SET_RATE_GATE during registration of the
  105. + * clock this requirement should be take care of by the
  106. + * clk-framework.
  107. + */
  108. + ctl = cprman_read(cprman, data->ctl_reg) & ~CM_FRAC;
  109. + ctl |= (div & CM_DIV_FRAC_MASK) ? CM_FRAC : 0;
  110. + cprman_write(cprman, data->ctl_reg, ctl);
  111. cprman_write(cprman, data->div_reg, div);
  112. + spin_unlock(&cprman->regs_lock);
  113. +
  114. return 0;
  115. }