049-clk-iproc-Separate-status-and-control-variables.patch 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. From eeb32564795a3584dba6281f445ff2aa552be36b Mon Sep 17 00:00:00 2001
  2. From: Jon Mason <jonmason@broadcom.com>
  3. Date: Thu, 15 Oct 2015 15:48:30 -0400
  4. Subject: [PATCH 49/50] clk: iproc: Separate status and control variables
  5. Some PLLs have separate registers for Status and Control. The means the
  6. pll_base needs to be split into 2 new variables, so that those PLLs can
  7. specify device tree registers for those independently. Also, add a new
  8. driver flag to identify this presence of the split, and let the driver
  9. know that additional registers need to be used.
  10. Signed-off-by: Jon Mason <jonmason@broadcom.com>
  11. ---
  12. drivers/clk/bcm/clk-iproc-pll.c | 96 ++++++++++++++++++++++++-----------------
  13. drivers/clk/bcm/clk-iproc.h | 6 +++
  14. 2 files changed, 62 insertions(+), 40 deletions(-)
  15. --- a/drivers/clk/bcm/clk-iproc-pll.c
  16. +++ b/drivers/clk/bcm/clk-iproc-pll.c
  17. @@ -74,7 +74,8 @@ struct iproc_clk {
  18. };
  19. struct iproc_pll {
  20. - void __iomem *pll_base;
  21. + void __iomem *status_base;
  22. + void __iomem *control_base;
  23. void __iomem *pwr_base;
  24. void __iomem *asiu_base;
  25. @@ -127,7 +128,7 @@ static int pll_wait_for_lock(struct ipro
  26. const struct iproc_pll_ctrl *ctrl = pll->ctrl;
  27. for (i = 0; i < LOCK_DELAY; i++) {
  28. - u32 val = readl(pll->pll_base + ctrl->status.offset);
  29. + u32 val = readl(pll->status_base + ctrl->status.offset);
  30. if (val & (1 << ctrl->status.shift))
  31. return 0;
  32. @@ -145,7 +146,7 @@ static void iproc_pll_write(const struct
  33. writel(val, base + offset);
  34. if (unlikely(ctrl->flags & IPROC_CLK_NEEDS_READ_BACK &&
  35. - base == pll->pll_base))
  36. + (base == pll->status_base || base == pll->control_base)))
  37. val = readl(base + offset);
  38. }
  39. @@ -161,9 +162,9 @@ static void __pll_disable(struct iproc_p
  40. }
  41. if (ctrl->flags & IPROC_CLK_EMBED_PWRCTRL) {
  42. - val = readl(pll->pll_base + ctrl->aon.offset);
  43. + val = readl(pll->control_base + ctrl->aon.offset);
  44. val |= (bit_mask(ctrl->aon.pwr_width) << ctrl->aon.pwr_shift);
  45. - iproc_pll_write(pll, pll->pll_base, ctrl->aon.offset, val);
  46. + iproc_pll_write(pll, pll->control_base, ctrl->aon.offset, val);
  47. }
  48. if (pll->pwr_base) {
  49. @@ -184,9 +185,9 @@ static int __pll_enable(struct iproc_pll
  50. u32 val;
  51. if (ctrl->flags & IPROC_CLK_EMBED_PWRCTRL) {
  52. - val = readl(pll->pll_base + ctrl->aon.offset);
  53. + val = readl(pll->control_base + ctrl->aon.offset);
  54. val &= ~(bit_mask(ctrl->aon.pwr_width) << ctrl->aon.pwr_shift);
  55. - iproc_pll_write(pll, pll->pll_base, ctrl->aon.offset, val);
  56. + iproc_pll_write(pll, pll->control_base, ctrl->aon.offset, val);
  57. }
  58. if (pll->pwr_base) {
  59. @@ -213,9 +214,9 @@ static void __pll_put_in_reset(struct ip
  60. const struct iproc_pll_ctrl *ctrl = pll->ctrl;
  61. const struct iproc_pll_reset_ctrl *reset = &ctrl->reset;
  62. - val = readl(pll->pll_base + reset->offset);
  63. + val = readl(pll->control_base + reset->offset);
  64. val &= ~(1 << reset->reset_shift | 1 << reset->p_reset_shift);
  65. - iproc_pll_write(pll, pll->pll_base, reset->offset, val);
  66. + iproc_pll_write(pll, pll->control_base, reset->offset, val);
  67. }
  68. static void __pll_bring_out_reset(struct iproc_pll *pll, unsigned int kp,
  69. @@ -226,17 +227,17 @@ static void __pll_bring_out_reset(struct
  70. const struct iproc_pll_reset_ctrl *reset = &ctrl->reset;
  71. const struct iproc_pll_dig_filter_ctrl *dig_filter = &ctrl->dig_filter;
  72. - val = readl(pll->pll_base + dig_filter->offset);
  73. + val = readl(pll->control_base + dig_filter->offset);
  74. val &= ~(bit_mask(dig_filter->ki_width) << dig_filter->ki_shift |
  75. bit_mask(dig_filter->kp_width) << dig_filter->kp_shift |
  76. bit_mask(dig_filter->ka_width) << dig_filter->ka_shift);
  77. val |= ki << dig_filter->ki_shift | kp << dig_filter->kp_shift |
  78. ka << dig_filter->ka_shift;
  79. - iproc_pll_write(pll, pll->pll_base, dig_filter->offset, val);
  80. + iproc_pll_write(pll, pll->control_base, dig_filter->offset, val);
  81. - val = readl(pll->pll_base + reset->offset);
  82. + val = readl(pll->control_base + reset->offset);
  83. val |= 1 << reset->reset_shift | 1 << reset->p_reset_shift;
  84. - iproc_pll_write(pll, pll->pll_base, reset->offset, val);
  85. + iproc_pll_write(pll, pll->control_base, reset->offset, val);
  86. }
  87. static int pll_set_rate(struct iproc_clk *clk, unsigned int rate_index,
  88. @@ -291,9 +292,9 @@ static int pll_set_rate(struct iproc_clk
  89. /* put PLL in reset */
  90. __pll_put_in_reset(pll);
  91. - iproc_pll_write(pll, pll->pll_base, ctrl->vco_ctrl.u_offset, 0);
  92. + iproc_pll_write(pll, pll->control_base, ctrl->vco_ctrl.u_offset, 0);
  93. - val = readl(pll->pll_base + ctrl->vco_ctrl.l_offset);
  94. + val = readl(pll->control_base + ctrl->vco_ctrl.l_offset);
  95. if (rate >= VCO_LOW && rate < VCO_MID)
  96. val |= (1 << PLL_VCO_LOW_SHIFT);
  97. @@ -303,29 +304,29 @@ static int pll_set_rate(struct iproc_clk
  98. else
  99. val |= (1 << PLL_VCO_HIGH_SHIFT);
  100. - iproc_pll_write(pll, pll->pll_base, ctrl->vco_ctrl.l_offset, val);
  101. + iproc_pll_write(pll, pll->control_base, ctrl->vco_ctrl.l_offset, val);
  102. /* program integer part of NDIV */
  103. - val = readl(pll->pll_base + ctrl->ndiv_int.offset);
  104. + val = readl(pll->control_base + ctrl->ndiv_int.offset);
  105. val &= ~(bit_mask(ctrl->ndiv_int.width) << ctrl->ndiv_int.shift);
  106. val |= vco->ndiv_int << ctrl->ndiv_int.shift;
  107. - iproc_pll_write(pll, pll->pll_base, ctrl->ndiv_int.offset, val);
  108. + iproc_pll_write(pll, pll->control_base, ctrl->ndiv_int.offset, val);
  109. /* program fractional part of NDIV */
  110. if (ctrl->flags & IPROC_CLK_PLL_HAS_NDIV_FRAC) {
  111. - val = readl(pll->pll_base + ctrl->ndiv_frac.offset);
  112. + val = readl(pll->control_base + ctrl->ndiv_frac.offset);
  113. val &= ~(bit_mask(ctrl->ndiv_frac.width) <<
  114. ctrl->ndiv_frac.shift);
  115. val |= vco->ndiv_frac << ctrl->ndiv_frac.shift;
  116. - iproc_pll_write(pll, pll->pll_base, ctrl->ndiv_frac.offset,
  117. + iproc_pll_write(pll, pll->control_base, ctrl->ndiv_frac.offset,
  118. val);
  119. }
  120. /* program PDIV */
  121. - val = readl(pll->pll_base + ctrl->pdiv.offset);
  122. + val = readl(pll->control_base + ctrl->pdiv.offset);
  123. val &= ~(bit_mask(ctrl->pdiv.width) << ctrl->pdiv.shift);
  124. val |= vco->pdiv << ctrl->pdiv.shift;
  125. - iproc_pll_write(pll, pll->pll_base, ctrl->pdiv.offset, val);
  126. + iproc_pll_write(pll, pll->control_base, ctrl->pdiv.offset, val);
  127. __pll_bring_out_reset(pll, kp, ka, ki);
  128. @@ -372,7 +373,7 @@ static unsigned long iproc_pll_recalc_ra
  129. return 0;
  130. /* PLL needs to be locked */
  131. - val = readl(pll->pll_base + ctrl->status.offset);
  132. + val = readl(pll->status_base + ctrl->status.offset);
  133. if ((val & (1 << ctrl->status.shift)) == 0) {
  134. clk->rate = 0;
  135. return 0;
  136. @@ -383,19 +384,19 @@ static unsigned long iproc_pll_recalc_ra
  137. *
  138. * ((ndiv_int + ndiv_frac / 2^20) * (parent clock rate / pdiv)
  139. */
  140. - val = readl(pll->pll_base + ctrl->ndiv_int.offset);
  141. + val = readl(pll->control_base + ctrl->ndiv_int.offset);
  142. ndiv_int = (val >> ctrl->ndiv_int.shift) &
  143. bit_mask(ctrl->ndiv_int.width);
  144. ndiv = ndiv_int << 20;
  145. if (ctrl->flags & IPROC_CLK_PLL_HAS_NDIV_FRAC) {
  146. - val = readl(pll->pll_base + ctrl->ndiv_frac.offset);
  147. + val = readl(pll->control_base + ctrl->ndiv_frac.offset);
  148. ndiv_frac = (val >> ctrl->ndiv_frac.shift) &
  149. bit_mask(ctrl->ndiv_frac.width);
  150. ndiv += ndiv_frac;
  151. }
  152. - val = readl(pll->pll_base + ctrl->pdiv.offset);
  153. + val = readl(pll->control_base + ctrl->pdiv.offset);
  154. pdiv = (val >> ctrl->pdiv.shift) & bit_mask(ctrl->pdiv.width);
  155. clk->rate = (ndiv * parent_rate) >> 20;
  156. @@ -460,14 +461,14 @@ static int iproc_clk_enable(struct clk_h
  157. u32 val;
  158. /* channel enable is active low */
  159. - val = readl(pll->pll_base + ctrl->enable.offset);
  160. + val = readl(pll->control_base + ctrl->enable.offset);
  161. val &= ~(1 << ctrl->enable.enable_shift);
  162. - iproc_pll_write(pll, pll->pll_base, ctrl->enable.offset, val);
  163. + iproc_pll_write(pll, pll->control_base, ctrl->enable.offset, val);
  164. /* also make sure channel is not held */
  165. - val = readl(pll->pll_base + ctrl->enable.offset);
  166. + val = readl(pll->control_base + ctrl->enable.offset);
  167. val &= ~(1 << ctrl->enable.hold_shift);
  168. - iproc_pll_write(pll, pll->pll_base, ctrl->enable.offset, val);
  169. + iproc_pll_write(pll, pll->control_base, ctrl->enable.offset, val);
  170. return 0;
  171. }
  172. @@ -482,9 +483,9 @@ static void iproc_clk_disable(struct clk
  173. if (ctrl->flags & IPROC_CLK_AON)
  174. return;
  175. - val = readl(pll->pll_base + ctrl->enable.offset);
  176. + val = readl(pll->control_base + ctrl->enable.offset);
  177. val |= 1 << ctrl->enable.enable_shift;
  178. - iproc_pll_write(pll, pll->pll_base, ctrl->enable.offset, val);
  179. + iproc_pll_write(pll, pll->control_base, ctrl->enable.offset, val);
  180. }
  181. static unsigned long iproc_clk_recalc_rate(struct clk_hw *hw,
  182. @@ -499,7 +500,7 @@ static unsigned long iproc_clk_recalc_ra
  183. if (parent_rate == 0)
  184. return 0;
  185. - val = readl(pll->pll_base + ctrl->mdiv.offset);
  186. + val = readl(pll->control_base + ctrl->mdiv.offset);
  187. mdiv = (val >> ctrl->mdiv.shift) & bit_mask(ctrl->mdiv.width);
  188. if (mdiv == 0)
  189. mdiv = 256;
  190. @@ -546,14 +547,14 @@ static int iproc_clk_set_rate(struct clk
  191. if (div > 256)
  192. return -EINVAL;
  193. - val = readl(pll->pll_base + ctrl->mdiv.offset);
  194. + val = readl(pll->control_base + ctrl->mdiv.offset);
  195. if (div == 256) {
  196. val &= ~(bit_mask(ctrl->mdiv.width) << ctrl->mdiv.shift);
  197. } else {
  198. val &= ~(bit_mask(ctrl->mdiv.width) << ctrl->mdiv.shift);
  199. val |= div << ctrl->mdiv.shift;
  200. }
  201. - iproc_pll_write(pll, pll->pll_base, ctrl->mdiv.offset, val);
  202. + iproc_pll_write(pll, pll->control_base, ctrl->mdiv.offset, val);
  203. clk->rate = parent_rate / div;
  204. return 0;
  205. @@ -578,9 +579,10 @@ static void iproc_pll_sw_cfg(struct ipro
  206. if (ctrl->flags & IPROC_CLK_PLL_NEEDS_SW_CFG) {
  207. u32 val;
  208. - val = readl(pll->pll_base + ctrl->sw_ctrl.offset);
  209. + val = readl(pll->control_base + ctrl->sw_ctrl.offset);
  210. val |= BIT(ctrl->sw_ctrl.shift);
  211. - iproc_pll_write(pll, pll->pll_base, ctrl->sw_ctrl.offset, val);
  212. + iproc_pll_write(pll, pll->control_base, ctrl->sw_ctrl.offset,
  213. + val);
  214. }
  215. }
  216. @@ -615,8 +617,8 @@ void __init iproc_pll_clk_setup(struct d
  217. if (WARN_ON(!pll->clks))
  218. goto err_clks;
  219. - pll->pll_base = of_iomap(node, 0);
  220. - if (WARN_ON(!pll->pll_base))
  221. + pll->control_base = of_iomap(node, 0);
  222. + if (WARN_ON(!pll->control_base))
  223. goto err_pll_iomap;
  224. /* Some SoCs do not require the pwr_base, thus failing is not fatal */
  225. @@ -629,6 +631,16 @@ void __init iproc_pll_clk_setup(struct d
  226. goto err_asiu_iomap;
  227. }
  228. + if (pll_ctrl->flags & IPROC_CLK_PLL_SPLIT_STAT_CTRL) {
  229. + /* Some SoCs have a split status/control. If this does not
  230. + * exist, assume they are unified.
  231. + */
  232. + pll->status_base = of_iomap(node, 2);
  233. + if (!pll->status_base)
  234. + goto err_status_iomap;
  235. + } else
  236. + pll->status_base = pll->control_base;
  237. +
  238. /* initialize and register the PLL itself */
  239. pll->ctrl = pll_ctrl;
  240. @@ -699,6 +711,10 @@ err_clk_register:
  241. clk_unregister(pll->clk_data.clks[i]);
  242. err_pll_register:
  243. + if (pll->status_base != pll->control_base)
  244. + iounmap(pll->status_base);
  245. +
  246. +err_status_iomap:
  247. if (pll->asiu_base)
  248. iounmap(pll->asiu_base);
  249. @@ -706,7 +722,7 @@ err_asiu_iomap:
  250. if (pll->pwr_base)
  251. iounmap(pll->pwr_base);
  252. - iounmap(pll->pll_base);
  253. + iounmap(pll->control_base);
  254. err_pll_iomap:
  255. kfree(pll->clks);
  256. --- a/drivers/clk/bcm/clk-iproc.h
  257. +++ b/drivers/clk/bcm/clk-iproc.h
  258. @@ -55,6 +55,12 @@
  259. #define IPROC_CLK_EMBED_PWRCTRL BIT(5)
  260. /*
  261. + * Some PLLs have separate registers for Status and Control. Identify this to
  262. + * let the driver know if additional registers need to be used
  263. + */
  264. +#define IPROC_CLK_PLL_SPLIT_STAT_CTRL BIT(6)
  265. +
  266. +/*
  267. * Parameters for VCO frequency configuration
  268. *
  269. * VCO frequency =