047-clk-iproc-Add-PLL-base-write-function.patch 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. From acbb7a3de7e4d83b23c0bbb3eaf77d15a041d865 Mon Sep 17 00:00:00 2001
  2. From: Jon Mason <jonmason@broadcom.com>
  3. Date: Thu, 15 Oct 2015 15:48:28 -0400
  4. Subject: [PATCH 47/50] clk: iproc: Add PLL base write function
  5. All writes to the PLL base address must be flushed if the
  6. IPROC_CLK_NEEDS_READ_BACK flag is set. If we add a function to make the
  7. necessary write and reads, we can make sure that any future code which
  8. makes PLL base writes will do the correct thing.
  9. Signed-off-by: Jon Mason <jonmason@broadcom.com>
  10. ---
  11. drivers/clk/bcm/clk-iproc-pll.c | 80 +++++++++++++++++------------------------
  12. 1 file changed, 33 insertions(+), 47 deletions(-)
  13. --- a/drivers/clk/bcm/clk-iproc-pll.c
  14. +++ b/drivers/clk/bcm/clk-iproc-pll.c
  15. @@ -137,6 +137,18 @@ static int pll_wait_for_lock(struct ipro
  16. return -EIO;
  17. }
  18. +static void iproc_pll_write(const struct iproc_pll *pll, void __iomem *base,
  19. + const u32 offset, u32 val)
  20. +{
  21. + const struct iproc_pll_ctrl *ctrl = pll->ctrl;
  22. +
  23. + writel(val, base + offset);
  24. +
  25. + if (unlikely(ctrl->flags & IPROC_CLK_NEEDS_READ_BACK &&
  26. + base == pll->pll_base))
  27. + val = readl(base + offset);
  28. +}
  29. +
  30. static void __pll_disable(struct iproc_pll *pll)
  31. {
  32. const struct iproc_pll_ctrl *ctrl = pll->ctrl;
  33. @@ -145,27 +157,24 @@ static void __pll_disable(struct iproc_p
  34. if (ctrl->flags & IPROC_CLK_PLL_ASIU) {
  35. val = readl(pll->asiu_base + ctrl->asiu.offset);
  36. val &= ~(1 << ctrl->asiu.en_shift);
  37. - writel(val, pll->asiu_base + ctrl->asiu.offset);
  38. + iproc_pll_write(pll, pll->asiu_base, ctrl->asiu.offset, val);
  39. }
  40. if (ctrl->flags & IPROC_CLK_EMBED_PWRCTRL) {
  41. val = readl(pll->pll_base + ctrl->aon.offset);
  42. val |= (bit_mask(ctrl->aon.pwr_width) << ctrl->aon.pwr_shift);
  43. - writel(val, pll->pll_base + ctrl->aon.offset);
  44. -
  45. - if (unlikely(ctrl->flags & IPROC_CLK_NEEDS_READ_BACK))
  46. - readl(pll->pll_base + ctrl->aon.offset);
  47. + iproc_pll_write(pll, pll->pll_base, ctrl->aon.offset, val);
  48. }
  49. if (pll->pwr_base) {
  50. /* latch input value so core power can be shut down */
  51. val = readl(pll->pwr_base + ctrl->aon.offset);
  52. val |= (1 << ctrl->aon.iso_shift);
  53. - writel(val, pll->pwr_base + ctrl->aon.offset);
  54. + iproc_pll_write(pll, pll->pwr_base, ctrl->aon.offset, val);
  55. /* power down the core */
  56. val &= ~(bit_mask(ctrl->aon.pwr_width) << ctrl->aon.pwr_shift);
  57. - writel(val, pll->pwr_base + ctrl->aon.offset);
  58. + iproc_pll_write(pll, pll->pwr_base, ctrl->aon.offset, val);
  59. }
  60. }
  61. @@ -177,10 +186,7 @@ static int __pll_enable(struct iproc_pll
  62. if (ctrl->flags & IPROC_CLK_EMBED_PWRCTRL) {
  63. val = readl(pll->pll_base + ctrl->aon.offset);
  64. val &= ~(bit_mask(ctrl->aon.pwr_width) << ctrl->aon.pwr_shift);
  65. - writel(val, pll->pll_base + ctrl->aon.offset);
  66. -
  67. - if (unlikely(ctrl->flags & IPROC_CLK_NEEDS_READ_BACK))
  68. - readl(pll->pll_base + ctrl->aon.offset);
  69. + iproc_pll_write(pll, pll->pll_base, ctrl->aon.offset, val);
  70. }
  71. if (pll->pwr_base) {
  72. @@ -188,14 +194,14 @@ static int __pll_enable(struct iproc_pll
  73. val = readl(pll->pwr_base + ctrl->aon.offset);
  74. val |= bit_mask(ctrl->aon.pwr_width) << ctrl->aon.pwr_shift;
  75. val &= ~(1 << ctrl->aon.iso_shift);
  76. - writel(val, pll->pwr_base + ctrl->aon.offset);
  77. + iproc_pll_write(pll, pll->pwr_base, ctrl->aon.offset, val);
  78. }
  79. /* certain PLLs also need to be ungated from the ASIU top level */
  80. if (ctrl->flags & IPROC_CLK_PLL_ASIU) {
  81. val = readl(pll->asiu_base + ctrl->asiu.offset);
  82. val |= (1 << ctrl->asiu.en_shift);
  83. - writel(val, pll->asiu_base + ctrl->asiu.offset);
  84. + iproc_pll_write(pll, pll->asiu_base, ctrl->asiu.offset, val);
  85. }
  86. return 0;
  87. @@ -209,9 +215,7 @@ static void __pll_put_in_reset(struct ip
  88. val = readl(pll->pll_base + reset->offset);
  89. val &= ~(1 << reset->reset_shift | 1 << reset->p_reset_shift);
  90. - writel(val, pll->pll_base + reset->offset);
  91. - if (unlikely(ctrl->flags & IPROC_CLK_NEEDS_READ_BACK))
  92. - readl(pll->pll_base + reset->offset);
  93. + iproc_pll_write(pll, pll->pll_base, reset->offset, val);
  94. }
  95. static void __pll_bring_out_reset(struct iproc_pll *pll, unsigned int kp,
  96. @@ -228,9 +232,7 @@ static void __pll_bring_out_reset(struct
  97. val |= ki << reset->ki_shift | kp << reset->kp_shift |
  98. ka << reset->ka_shift;
  99. val |= 1 << reset->reset_shift | 1 << reset->p_reset_shift;
  100. - writel(val, pll->pll_base + reset->offset);
  101. - if (unlikely(ctrl->flags & IPROC_CLK_NEEDS_READ_BACK))
  102. - readl(pll->pll_base + reset->offset);
  103. + iproc_pll_write(pll, pll->pll_base, reset->offset, val);
  104. }
  105. static int pll_set_rate(struct iproc_clk *clk, unsigned int rate_index,
  106. @@ -285,9 +287,8 @@ static int pll_set_rate(struct iproc_clk
  107. /* put PLL in reset */
  108. __pll_put_in_reset(pll);
  109. - writel(0, pll->pll_base + ctrl->vco_ctrl.u_offset);
  110. - if (unlikely(ctrl->flags & IPROC_CLK_NEEDS_READ_BACK))
  111. - readl(pll->pll_base + ctrl->vco_ctrl.u_offset);
  112. + iproc_pll_write(pll, pll->pll_base, ctrl->vco_ctrl.u_offset, 0);
  113. +
  114. val = readl(pll->pll_base + ctrl->vco_ctrl.l_offset);
  115. if (rate >= VCO_LOW && rate < VCO_MID)
  116. @@ -298,17 +299,13 @@ static int pll_set_rate(struct iproc_clk
  117. else
  118. val |= (1 << PLL_VCO_HIGH_SHIFT);
  119. - writel(val, pll->pll_base + ctrl->vco_ctrl.l_offset);
  120. - if (unlikely(ctrl->flags & IPROC_CLK_NEEDS_READ_BACK))
  121. - readl(pll->pll_base + ctrl->vco_ctrl.l_offset);
  122. + iproc_pll_write(pll, pll->pll_base, ctrl->vco_ctrl.l_offset, val);
  123. /* program integer part of NDIV */
  124. val = readl(pll->pll_base + ctrl->ndiv_int.offset);
  125. val &= ~(bit_mask(ctrl->ndiv_int.width) << ctrl->ndiv_int.shift);
  126. val |= vco->ndiv_int << ctrl->ndiv_int.shift;
  127. - writel(val, pll->pll_base + ctrl->ndiv_int.offset);
  128. - if (unlikely(ctrl->flags & IPROC_CLK_NEEDS_READ_BACK))
  129. - readl(pll->pll_base + ctrl->ndiv_int.offset);
  130. + iproc_pll_write(pll, pll->pll_base, ctrl->ndiv_int.offset, val);
  131. /* program fractional part of NDIV */
  132. if (ctrl->flags & IPROC_CLK_PLL_HAS_NDIV_FRAC) {
  133. @@ -316,18 +313,15 @@ static int pll_set_rate(struct iproc_clk
  134. val &= ~(bit_mask(ctrl->ndiv_frac.width) <<
  135. ctrl->ndiv_frac.shift);
  136. val |= vco->ndiv_frac << ctrl->ndiv_frac.shift;
  137. - writel(val, pll->pll_base + ctrl->ndiv_frac.offset);
  138. - if (unlikely(ctrl->flags & IPROC_CLK_NEEDS_READ_BACK))
  139. - readl(pll->pll_base + ctrl->ndiv_frac.offset);
  140. + iproc_pll_write(pll, pll->pll_base, ctrl->ndiv_frac.offset,
  141. + val);
  142. }
  143. /* program PDIV */
  144. val = readl(pll->pll_base + ctrl->pdiv.offset);
  145. val &= ~(bit_mask(ctrl->pdiv.width) << ctrl->pdiv.shift);
  146. val |= vco->pdiv << ctrl->pdiv.shift;
  147. - writel(val, pll->pll_base + ctrl->pdiv.offset);
  148. - if (unlikely(ctrl->flags & IPROC_CLK_NEEDS_READ_BACK))
  149. - readl(pll->pll_base + ctrl->pdiv.offset);
  150. + iproc_pll_write(pll, pll->pll_base, ctrl->pdiv.offset, val);
  151. __pll_bring_out_reset(pll, kp, ka, ki);
  152. @@ -464,14 +458,12 @@ static int iproc_clk_enable(struct clk_h
  153. /* channel enable is active low */
  154. val = readl(pll->pll_base + ctrl->enable.offset);
  155. val &= ~(1 << ctrl->enable.enable_shift);
  156. - writel(val, pll->pll_base + ctrl->enable.offset);
  157. + iproc_pll_write(pll, pll->pll_base, ctrl->enable.offset, val);
  158. /* also make sure channel is not held */
  159. val = readl(pll->pll_base + ctrl->enable.offset);
  160. val &= ~(1 << ctrl->enable.hold_shift);
  161. - writel(val, pll->pll_base + ctrl->enable.offset);
  162. - if (unlikely(ctrl->flags & IPROC_CLK_NEEDS_READ_BACK))
  163. - readl(pll->pll_base + ctrl->enable.offset);
  164. + iproc_pll_write(pll, pll->pll_base, ctrl->enable.offset, val);
  165. return 0;
  166. }
  167. @@ -488,9 +480,7 @@ static void iproc_clk_disable(struct clk
  168. val = readl(pll->pll_base + ctrl->enable.offset);
  169. val |= 1 << ctrl->enable.enable_shift;
  170. - writel(val, pll->pll_base + ctrl->enable.offset);
  171. - if (unlikely(ctrl->flags & IPROC_CLK_NEEDS_READ_BACK))
  172. - readl(pll->pll_base + ctrl->enable.offset);
  173. + iproc_pll_write(pll, pll->pll_base, ctrl->enable.offset, val);
  174. }
  175. static unsigned long iproc_clk_recalc_rate(struct clk_hw *hw,
  176. @@ -559,9 +549,7 @@ static int iproc_clk_set_rate(struct clk
  177. val &= ~(bit_mask(ctrl->mdiv.width) << ctrl->mdiv.shift);
  178. val |= div << ctrl->mdiv.shift;
  179. }
  180. - writel(val, pll->pll_base + ctrl->mdiv.offset);
  181. - if (unlikely(ctrl->flags & IPROC_CLK_NEEDS_READ_BACK))
  182. - readl(pll->pll_base + ctrl->mdiv.offset);
  183. + iproc_pll_write(pll, pll->pll_base, ctrl->mdiv.offset, val);
  184. clk->rate = parent_rate / div;
  185. return 0;
  186. @@ -588,9 +576,7 @@ static void iproc_pll_sw_cfg(struct ipro
  187. val = readl(pll->pll_base + ctrl->sw_ctrl.offset);
  188. val |= BIT(ctrl->sw_ctrl.shift);
  189. - writel(val, pll->pll_base + ctrl->sw_ctrl.offset);
  190. - if (unlikely(ctrl->flags & IPROC_CLK_NEEDS_READ_BACK))
  191. - readl(pll->pll_base + ctrl->sw_ctrl.offset);
  192. + iproc_pll_write(pll, pll->pll_base, ctrl->sw_ctrl.offset, val);
  193. }
  194. }