0024-MIPS-ath79-make-specifying-the-reference-clock-in-DT.patch 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. From 5fadb2544ed0bb72ddddd846aa303bb9ed2d211c Mon Sep 17 00:00:00 2001
  2. From: Felix Fietkau <nbd@nbd.name>
  3. Date: Tue, 6 Mar 2018 13:24:07 +0100
  4. Subject: [PATCH 24/33] MIPS: ath79: make specifying the reference clock in DT
  5. optional
  6. It can be autodetected for many SoCs using the strapping options.
  7. If the clock is specified in DT, the autodetected value is ignored
  8. Signed-off-by: Felix Fietkau <nbd@nbd.name>
  9. Signed-off-by: John Crispin <john@phrozen.org>
  10. ---
  11. arch/mips/ath79/clock.c | 84 +++++++++++++++++++++++--------------------------
  12. 1 file changed, 40 insertions(+), 44 deletions(-)
  13. --- a/arch/mips/ath79/clock.c
  14. +++ b/arch/mips/ath79/clock.c
  15. @@ -80,6 +80,18 @@ static struct clk * __init ath79_set_ff_
  16. return clk;
  17. }
  18. +static unsigned long __init ath79_setup_ref_clk(unsigned long rate)
  19. +{
  20. + struct clk *clk = clks[ATH79_CLK_REF];
  21. +
  22. + if (clk)
  23. + rate = clk_get_rate(clk);
  24. + else
  25. + clk = ath79_set_clk(ATH79_CLK_REF, rate);
  26. +
  27. + return rate;
  28. +}
  29. +
  30. static void __init ar71xx_clocks_init(void __iomem *pll_base)
  31. {
  32. unsigned long ref_rate;
  33. @@ -90,7 +102,7 @@ static void __init ar71xx_clocks_init(vo
  34. u32 freq;
  35. u32 div;
  36. - ref_rate = AR71XX_BASE_FREQ;
  37. + ref_rate = ath79_setup_ref_clk(AR71XX_BASE_FREQ);
  38. pll = __raw_readl(pll_base + AR71XX_PLL_REG_CPU_CONFIG);
  39. @@ -106,16 +118,17 @@ static void __init ar71xx_clocks_init(vo
  40. div = (((pll >> AR71XX_AHB_DIV_SHIFT) & AR71XX_AHB_DIV_MASK) + 1) * 2;
  41. ahb_rate = cpu_rate / div;
  42. - ath79_set_clk(ATH79_CLK_REF, ref_rate);
  43. ath79_set_clk(ATH79_CLK_CPU, cpu_rate);
  44. ath79_set_clk(ATH79_CLK_DDR, ddr_rate);
  45. ath79_set_clk(ATH79_CLK_AHB, ahb_rate);
  46. }
  47. -static void __init ar724x_clk_init(struct clk *ref_clk, void __iomem *pll_base)
  48. +static void __init ar724x_clocks_init(void __iomem *pll_base)
  49. {
  50. - u32 pll;
  51. u32 mult, div, ddr_div, ahb_div;
  52. + u32 pll;
  53. +
  54. + ath79_setup_ref_clk(AR71XX_BASE_FREQ);
  55. pll = __raw_readl(pll_base + AR724X_PLL_REG_CPU_CONFIG);
  56. @@ -130,17 +143,9 @@ static void __init ar724x_clk_init(struc
  57. ath79_set_ff_clk(ATH79_CLK_AHB, "ref", mult, div * ahb_div);
  58. }
  59. -static void __init ar724x_clocks_init(void __iomem *pll_base)
  60. -{
  61. - struct clk *ref_clk;
  62. -
  63. - ref_clk = ath79_set_clk(ATH79_CLK_REF, AR724X_BASE_FREQ);
  64. -
  65. - ar724x_clk_init(ref_clk, pll_base);
  66. -}
  67. -
  68. -static void __init ar9330_clk_init(struct clk *ref_clk, void __iomem *pll_base)
  69. +static void __init ar933x_clocks_init(void __iomem *pll_base)
  70. {
  71. + unsigned long ref_rate;
  72. u32 clock_ctrl;
  73. u32 ref_div;
  74. u32 ninit_mul;
  75. @@ -149,6 +154,15 @@ static void __init ar9330_clk_init(struc
  76. u32 cpu_div;
  77. u32 ddr_div;
  78. u32 ahb_div;
  79. + u32 t;
  80. +
  81. + t = ath79_reset_rr(AR933X_RESET_REG_BOOTSTRAP);
  82. + if (t & AR933X_BOOTSTRAP_REF_CLK_40)
  83. + ref_rate = (40 * 1000 * 1000);
  84. + else
  85. + ref_rate = (25 * 1000 * 1000);
  86. +
  87. + ath79_setup_ref_clk(ref_rate);
  88. clock_ctrl = __raw_readl(pll_base + AR933X_PLL_CLOCK_CTRL_REG);
  89. if (clock_ctrl & AR933X_PLL_CLOCK_CTRL_BYPASS) {
  90. @@ -197,23 +211,6 @@ static void __init ar9330_clk_init(struc
  91. ref_div * out_div * ahb_div);
  92. }
  93. -static void __init ar933x_clocks_init(void __iomem *pll_base)
  94. -{
  95. - struct clk *ref_clk;
  96. - unsigned long ref_rate;
  97. - u32 t;
  98. -
  99. - t = ath79_reset_rr(AR933X_RESET_REG_BOOTSTRAP);
  100. - if (t & AR933X_BOOTSTRAP_REF_CLK_40)
  101. - ref_rate = (40 * 1000 * 1000);
  102. - else
  103. - ref_rate = (25 * 1000 * 1000);
  104. -
  105. - ref_clk = ath79_set_clk(ATH79_CLK_REF, ref_rate);
  106. -
  107. - ar9330_clk_init(ref_clk, ath79_pll_base);
  108. -}
  109. -
  110. static u32 __init ar934x_get_pll_freq(u32 ref, u32 ref_div, u32 nint, u32 nfrac,
  111. u32 frac, u32 out_div)
  112. {
  113. @@ -253,6 +250,8 @@ static void __init ar934x_clocks_init(vo
  114. else
  115. ref_rate = 25 * 1000 * 1000;
  116. + ref_rate = ath79_setup_ref_clk(ref_rate);
  117. +
  118. pll = __raw_readl(dpll_base + AR934X_SRIF_CPU_DPLL2_REG);
  119. if (pll & AR934X_SRIF_DPLL2_LOCAL_PLL) {
  120. out_div = (pll >> AR934X_SRIF_DPLL2_OUTDIV_SHIFT) &
  121. @@ -339,7 +338,6 @@ static void __init ar934x_clocks_init(vo
  122. else
  123. ahb_rate = cpu_pll / (postdiv + 1);
  124. - ath79_set_clk(ATH79_CLK_REF, ref_rate);
  125. ath79_set_clk(ATH79_CLK_CPU, cpu_rate);
  126. ath79_set_clk(ATH79_CLK_DDR, ddr_rate);
  127. ath79_set_clk(ATH79_CLK_AHB, ahb_rate);
  128. @@ -363,6 +361,8 @@ static void __init qca953x_clocks_init(v
  129. else
  130. ref_rate = 25 * 1000 * 1000;
  131. + ref_rate = ath79_setup_ref_clk(ref_rate);
  132. +
  133. pll = __raw_readl(pll_base + QCA953X_PLL_CPU_CONFIG_REG);
  134. out_div = (pll >> QCA953X_PLL_CPU_CONFIG_OUTDIV_SHIFT) &
  135. QCA953X_PLL_CPU_CONFIG_OUTDIV_MASK;
  136. @@ -423,7 +423,6 @@ static void __init qca953x_clocks_init(v
  137. else
  138. ahb_rate = cpu_pll / (postdiv + 1);
  139. - ath79_set_clk(ATH79_CLK_REF, ref_rate);
  140. ath79_set_clk(ATH79_CLK_CPU, cpu_rate);
  141. ath79_set_clk(ATH79_CLK_DDR, ddr_rate);
  142. ath79_set_clk(ATH79_CLK_AHB, ahb_rate);
  143. @@ -445,6 +444,8 @@ static void __init qca955x_clocks_init(v
  144. else
  145. ref_rate = 25 * 1000 * 1000;
  146. + ref_rate = ath79_setup_ref_clk(ref_rate);
  147. +
  148. pll = __raw_readl(pll_base + QCA955X_PLL_CPU_CONFIG_REG);
  149. out_div = (pll >> QCA955X_PLL_CPU_CONFIG_OUTDIV_SHIFT) &
  150. QCA955X_PLL_CPU_CONFIG_OUTDIV_MASK;
  151. @@ -505,7 +506,6 @@ static void __init qca955x_clocks_init(v
  152. else
  153. ahb_rate = cpu_pll / (postdiv + 1);
  154. - ath79_set_clk(ATH79_CLK_REF, ref_rate);
  155. ath79_set_clk(ATH79_CLK_CPU, cpu_rate);
  156. ath79_set_clk(ATH79_CLK_DDR, ddr_rate);
  157. ath79_set_clk(ATH79_CLK_AHB, ahb_rate);
  158. @@ -537,6 +537,8 @@ static void __init qca956x_clocks_init(v
  159. else
  160. ref_rate = 25 * 1000 * 1000;
  161. + ref_rate = ath79_setup_ref_clk(ref_rate);
  162. +
  163. pll = __raw_readl(pll_base + QCA956X_PLL_CPU_CONFIG_REG);
  164. out_div = (pll >> QCA956X_PLL_CPU_CONFIG_OUTDIV_SHIFT) &
  165. QCA956X_PLL_CPU_CONFIG_OUTDIV_MASK;
  166. @@ -606,7 +608,6 @@ static void __init qca956x_clocks_init(v
  167. else
  168. ahb_rate = cpu_pll / (postdiv + 1);
  169. - ath79_set_clk(ATH79_CLK_REF, ref_rate);
  170. ath79_set_clk(ATH79_CLK_CPU, cpu_rate);
  171. ath79_set_clk(ATH79_CLK_DDR, ddr_rate);
  172. ath79_set_clk(ATH79_CLK_AHB, ahb_rate);
  173. @@ -682,10 +683,8 @@ static void __init ath79_clocks_init_dt_
  174. void __iomem *pll_base;
  175. ref_clk = of_clk_get(np, 0);
  176. - if (IS_ERR(ref_clk)) {
  177. - pr_err("%pOF: of_clk_get failed\n", np);
  178. - goto err;
  179. - }
  180. + if (!IS_ERR(ref_clk))
  181. + clks[ATH79_CLK_REF] = ref_clk;
  182. pll_base = of_iomap(np, 0);
  183. if (!pll_base) {
  184. @@ -694,9 +693,9 @@ static void __init ath79_clocks_init_dt_
  185. }
  186. if (of_device_is_compatible(np, "qca,ar9130-pll"))
  187. - ar724x_clk_init(ref_clk, pll_base);
  188. + ar724x_clocks_init(pll_base);
  189. else if (of_device_is_compatible(np, "qca,ar9330-pll"))
  190. - ar9330_clk_init(ref_clk, pll_base);
  191. + ar933x_clocks_init(pll_base);
  192. else {
  193. pr_err("%pOF: could not find any appropriate clk_init()\n", np);
  194. goto err_iounmap;
  195. @@ -714,9 +713,6 @@ err_iounmap:
  196. err_clk:
  197. clk_put(ref_clk);
  198. -
  199. -err:
  200. - return;
  201. }
  202. CLK_OF_DECLARE(ar9130_clk, "qca,ar9130-pll", ath79_clocks_init_dt_ng);
  203. CLK_OF_DECLARE(ar9330_clk, "qca,ar9330-pll", ath79_clocks_init_dt_ng);