0021-MIPS-ath79-add-helpers-for-setting-clocks-and-expose.patch 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. From 288a8eb0d41f09fda242e05f8a7bd1f5b3489477 Mon Sep 17 00:00:00 2001
  2. From: Felix Fietkau <nbd@nbd.name>
  3. Date: Tue, 6 Mar 2018 13:19:26 +0100
  4. Subject: [PATCH 21/33] MIPS: ath79: add helpers for setting clocks and expose
  5. the ref clock
  6. Preparation for transitioning the legacy clock setup code over
  7. to OF.
  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 | 128 ++++++++++++++++++----------------
  12. include/dt-bindings/clock/ath79-clk.h | 3 +-
  13. 2 files changed, 68 insertions(+), 63 deletions(-)
  14. --- a/arch/mips/ath79/clock.c
  15. +++ b/arch/mips/ath79/clock.c
  16. @@ -37,20 +37,46 @@ static struct clk_onecell_data clk_data
  17. .clk_num = ARRAY_SIZE(clks),
  18. };
  19. -static struct clk *__init ath79_add_sys_clkdev(
  20. - const char *id, unsigned long rate)
  21. +static const char * const clk_names[ATH79_CLK_END] = {
  22. + [ATH79_CLK_CPU] = "cpu",
  23. + [ATH79_CLK_DDR] = "ddr",
  24. + [ATH79_CLK_AHB] = "ahb",
  25. + [ATH79_CLK_REF] = "ref",
  26. +};
  27. +
  28. +static const char * __init ath79_clk_name(int type)
  29. {
  30. - struct clk *clk;
  31. - int err;
  32. + BUG_ON(type >= ARRAY_SIZE(clk_names) || !clk_names[type]);
  33. + return clk_names[type];
  34. +}
  35. - clk = clk_register_fixed_rate(NULL, id, NULL, 0, rate);
  36. +static void __init __ath79_set_clk(int type, const char *name, struct clk *clk)
  37. +{
  38. if (IS_ERR(clk))
  39. - panic("failed to allocate %s clock structure", id);
  40. + panic("failed to allocate %s clock structure", clk_names[type]);
  41. - err = clk_register_clkdev(clk, id, NULL);
  42. - if (err)
  43. - panic("unable to register %s clock device", id);
  44. + clks[type] = clk;
  45. + clk_register_clkdev(clk, name, NULL);
  46. +}
  47. +static struct clk * __init ath79_set_clk(int type, unsigned long rate)
  48. +{
  49. + const char *name = ath79_clk_name(type);
  50. + struct clk *clk;
  51. +
  52. + clk = clk_register_fixed_rate(NULL, name, NULL, 0, rate);
  53. + __ath79_set_clk(type, name, clk);
  54. + return clk;
  55. +}
  56. +
  57. +static struct clk * __init ath79_set_ff_clk(int type, const char *parent,
  58. + unsigned int mult, unsigned int div)
  59. +{
  60. + const char *name = ath79_clk_name(type);
  61. + struct clk *clk;
  62. +
  63. + clk = clk_register_fixed_factor(NULL, name, parent, 0, mult, div);
  64. + __ath79_set_clk(type, name, clk);
  65. return clk;
  66. }
  67. @@ -80,27 +106,15 @@ static void __init ar71xx_clocks_init(vo
  68. div = (((pll >> AR71XX_AHB_DIV_SHIFT) & AR71XX_AHB_DIV_MASK) + 1) * 2;
  69. ahb_rate = cpu_rate / div;
  70. - ath79_add_sys_clkdev("ref", ref_rate);
  71. - clks[ATH79_CLK_CPU] = ath79_add_sys_clkdev("cpu", cpu_rate);
  72. - clks[ATH79_CLK_DDR] = ath79_add_sys_clkdev("ddr", ddr_rate);
  73. - clks[ATH79_CLK_AHB] = ath79_add_sys_clkdev("ahb", ahb_rate);
  74. + ath79_set_clk(ATH79_CLK_REF, ref_rate);
  75. + ath79_set_clk(ATH79_CLK_CPU, cpu_rate);
  76. + ath79_set_clk(ATH79_CLK_DDR, ddr_rate);
  77. + ath79_set_clk(ATH79_CLK_AHB, ahb_rate);
  78. clk_add_alias("wdt", NULL, "ahb", NULL);
  79. clk_add_alias("uart", NULL, "ahb", NULL);
  80. }
  81. -static struct clk * __init ath79_reg_ffclk(const char *name,
  82. - const char *parent_name, unsigned int mult, unsigned int div)
  83. -{
  84. - struct clk *clk;
  85. -
  86. - clk = clk_register_fixed_factor(NULL, name, parent_name, 0, mult, div);
  87. - if (IS_ERR(clk))
  88. - panic("failed to allocate %s clock structure", name);
  89. -
  90. - return clk;
  91. -}
  92. -
  93. static void __init ar724x_clk_init(struct clk *ref_clk, void __iomem *pll_base)
  94. {
  95. u32 pll;
  96. @@ -114,24 +128,19 @@ static void __init ar724x_clk_init(struc
  97. ddr_div = ((pll >> AR724X_DDR_DIV_SHIFT) & AR724X_DDR_DIV_MASK) + 1;
  98. ahb_div = (((pll >> AR724X_AHB_DIV_SHIFT) & AR724X_AHB_DIV_MASK) + 1) * 2;
  99. - clks[ATH79_CLK_CPU] = ath79_reg_ffclk("cpu", "ref", mult, div);
  100. - clks[ATH79_CLK_DDR] = ath79_reg_ffclk("ddr", "ref", mult, div * ddr_div);
  101. - clks[ATH79_CLK_AHB] = ath79_reg_ffclk("ahb", "ref", mult, div * ahb_div);
  102. + ath79_set_ff_clk(ATH79_CLK_CPU, "ref", mult, div);
  103. + ath79_set_ff_clk(ATH79_CLK_DDR, "ref", mult, div * ddr_div);
  104. + ath79_set_ff_clk(ATH79_CLK_AHB, "ref", mult, div * ahb_div);
  105. }
  106. static void __init ar724x_clocks_init(void)
  107. {
  108. struct clk *ref_clk;
  109. - ref_clk = ath79_add_sys_clkdev("ref", AR724X_BASE_FREQ);
  110. + ref_clk = ath79_set_clk(ATH79_CLK_REF, AR724X_BASE_FREQ);
  111. ar724x_clk_init(ref_clk, ath79_pll_base);
  112. - /* just make happy plat_time_init() from arch/mips/ath79/setup.c */
  113. - clk_register_clkdev(clks[ATH79_CLK_CPU], "cpu", NULL);
  114. - clk_register_clkdev(clks[ATH79_CLK_DDR], "ddr", NULL);
  115. - clk_register_clkdev(clks[ATH79_CLK_AHB], "ahb", NULL);
  116. -
  117. clk_add_alias("wdt", NULL, "ahb", NULL);
  118. clk_add_alias("uart", NULL, "ahb", NULL);
  119. }
  120. @@ -186,12 +195,12 @@ static void __init ar9330_clk_init(struc
  121. AR933X_PLL_CLOCK_CTRL_AHB_DIV_MASK) + 1;
  122. }
  123. - clks[ATH79_CLK_CPU] = ath79_reg_ffclk("cpu", "ref",
  124. - ninit_mul, ref_div * out_div * cpu_div);
  125. - clks[ATH79_CLK_DDR] = ath79_reg_ffclk("ddr", "ref",
  126. - ninit_mul, ref_div * out_div * ddr_div);
  127. - clks[ATH79_CLK_AHB] = ath79_reg_ffclk("ahb", "ref",
  128. - ninit_mul, ref_div * out_div * ahb_div);
  129. + ath79_set_ff_clk(ATH79_CLK_CPU, "ref", ninit_mul,
  130. + ref_div * out_div * cpu_div);
  131. + ath79_set_ff_clk(ATH79_CLK_DDR, "ref", ninit_mul,
  132. + ref_div * out_div * ddr_div);
  133. + ath79_set_ff_clk(ATH79_CLK_AHB, "ref", ninit_mul,
  134. + ref_div * out_div * ahb_div);
  135. }
  136. static void __init ar933x_clocks_init(void)
  137. @@ -206,15 +215,10 @@ static void __init ar933x_clocks_init(vo
  138. else
  139. ref_rate = (25 * 1000 * 1000);
  140. - ref_clk = ath79_add_sys_clkdev("ref", ref_rate);
  141. + ref_clk = ath79_set_clk(ATH79_CLK_REF, ref_rate);
  142. ar9330_clk_init(ref_clk, ath79_pll_base);
  143. - /* just make happy plat_time_init() from arch/mips/ath79/setup.c */
  144. - clk_register_clkdev(clks[ATH79_CLK_CPU], "cpu", NULL);
  145. - clk_register_clkdev(clks[ATH79_CLK_DDR], "ddr", NULL);
  146. - clk_register_clkdev(clks[ATH79_CLK_AHB], "ahb", NULL);
  147. -
  148. clk_add_alias("wdt", NULL, "ahb", NULL);
  149. clk_add_alias("uart", NULL, "ref", NULL);
  150. }
  151. @@ -344,10 +348,10 @@ static void __init ar934x_clocks_init(vo
  152. else
  153. ahb_rate = cpu_pll / (postdiv + 1);
  154. - ath79_add_sys_clkdev("ref", ref_rate);
  155. - clks[ATH79_CLK_CPU] = ath79_add_sys_clkdev("cpu", cpu_rate);
  156. - clks[ATH79_CLK_DDR] = ath79_add_sys_clkdev("ddr", ddr_rate);
  157. - clks[ATH79_CLK_AHB] = ath79_add_sys_clkdev("ahb", ahb_rate);
  158. + ath79_set_clk(ATH79_CLK_REF, ref_rate);
  159. + ath79_set_clk(ATH79_CLK_CPU, cpu_rate);
  160. + ath79_set_clk(ATH79_CLK_DDR, ddr_rate);
  161. + ath79_set_clk(ATH79_CLK_AHB, ahb_rate);
  162. clk_add_alias("wdt", NULL, "ref", NULL);
  163. clk_add_alias("uart", NULL, "ref", NULL);
  164. @@ -431,10 +435,10 @@ static void __init qca953x_clocks_init(v
  165. else
  166. ahb_rate = cpu_pll / (postdiv + 1);
  167. - ath79_add_sys_clkdev("ref", ref_rate);
  168. - ath79_add_sys_clkdev("cpu", cpu_rate);
  169. - ath79_add_sys_clkdev("ddr", ddr_rate);
  170. - ath79_add_sys_clkdev("ahb", ahb_rate);
  171. + ath79_set_clk(ATH79_CLK_REF, ref_rate);
  172. + ath79_set_clk(ATH79_CLK_CPU, cpu_rate);
  173. + ath79_set_clk(ATH79_CLK_DDR, ddr_rate);
  174. + ath79_set_clk(ATH79_CLK_AHB, ahb_rate);
  175. clk_add_alias("wdt", NULL, "ref", NULL);
  176. clk_add_alias("uart", NULL, "ref", NULL);
  177. @@ -516,10 +520,10 @@ static void __init qca955x_clocks_init(v
  178. else
  179. ahb_rate = cpu_pll / (postdiv + 1);
  180. - ath79_add_sys_clkdev("ref", ref_rate);
  181. - clks[ATH79_CLK_CPU] = ath79_add_sys_clkdev("cpu", cpu_rate);
  182. - clks[ATH79_CLK_DDR] = ath79_add_sys_clkdev("ddr", ddr_rate);
  183. - clks[ATH79_CLK_AHB] = ath79_add_sys_clkdev("ahb", ahb_rate);
  184. + ath79_set_clk(ATH79_CLK_REF, ref_rate);
  185. + ath79_set_clk(ATH79_CLK_CPU, cpu_rate);
  186. + ath79_set_clk(ATH79_CLK_DDR, ddr_rate);
  187. + ath79_set_clk(ATH79_CLK_AHB, ahb_rate);
  188. clk_add_alias("wdt", NULL, "ref", NULL);
  189. clk_add_alias("uart", NULL, "ref", NULL);
  190. @@ -620,10 +624,10 @@ static void __init qca956x_clocks_init(v
  191. else
  192. ahb_rate = cpu_pll / (postdiv + 1);
  193. - ath79_add_sys_clkdev("ref", ref_rate);
  194. - ath79_add_sys_clkdev("cpu", cpu_rate);
  195. - ath79_add_sys_clkdev("ddr", ddr_rate);
  196. - ath79_add_sys_clkdev("ahb", ahb_rate);
  197. + ath79_set_clk(ATH79_CLK_REF, ref_rate);
  198. + ath79_set_clk(ATH79_CLK_CPU, cpu_rate);
  199. + ath79_set_clk(ATH79_CLK_DDR, ddr_rate);
  200. + ath79_set_clk(ATH79_CLK_AHB, ahb_rate);
  201. clk_add_alias("wdt", NULL, "ref", NULL);
  202. clk_add_alias("uart", NULL, "ref", NULL);
  203. --- a/include/dt-bindings/clock/ath79-clk.h
  204. +++ b/include/dt-bindings/clock/ath79-clk.h
  205. @@ -13,7 +13,8 @@
  206. #define ATH79_CLK_CPU 0
  207. #define ATH79_CLK_DDR 1
  208. #define ATH79_CLK_AHB 2
  209. +#define ATH79_CLK_REF 3
  210. -#define ATH79_CLK_END 3
  211. +#define ATH79_CLK_END 4
  212. #endif /* __DT_BINDINGS_ATH79_CLK_H */