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

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