clock.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. /*
  2. * Atheros AR71XX/AR724X/AR913X common routines
  3. *
  4. * Copyright (C) 2010-2011 Jaiganesh Narayanan <jnarayanan@atheros.com>
  5. * Copyright (C) 2011 Gabor Juhos <juhosg@openwrt.org>
  6. *
  7. * Parts of this file are based on Atheros' 2.6.15/2.6.31 BSP
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License version 2 as published
  11. * by the Free Software Foundation.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/module.h>
  15. #include <linux/init.h>
  16. #include <linux/err.h>
  17. #include <linux/clk.h>
  18. #include <linux/clkdev.h>
  19. #include <linux/clk-provider.h>
  20. #include <linux/of.h>
  21. #include <linux/of_address.h>
  22. #include <dt-bindings/clock/ath79-clk.h>
  23. #include <asm/div64.h>
  24. #include <asm/mach-ath79/ath79.h>
  25. #include <asm/mach-ath79/ar71xx_regs.h>
  26. #include "common.h"
  27. #include "machtypes.h"
  28. #define AR71XX_BASE_FREQ 40000000
  29. #define AR724X_BASE_FREQ 40000000
  30. static struct clk *clks[ATH79_CLK_END];
  31. static struct clk_onecell_data clk_data = {
  32. .clks = clks,
  33. .clk_num = ARRAY_SIZE(clks),
  34. };
  35. static struct clk *__init ath79_add_sys_clkdev(
  36. const char *id, unsigned long rate)
  37. {
  38. struct clk *clk;
  39. int err;
  40. clk = clk_register_fixed_rate(NULL, id, NULL, 0, rate);
  41. if (!clk)
  42. panic("failed to allocate %s clock structure", id);
  43. err = clk_register_clkdev(clk, id, NULL);
  44. if (err)
  45. panic("unable to register %s clock device", id);
  46. return clk;
  47. }
  48. static void __init ar71xx_clocks_init(void)
  49. {
  50. unsigned long ref_rate;
  51. unsigned long cpu_rate;
  52. unsigned long ddr_rate;
  53. unsigned long ahb_rate;
  54. u32 pll;
  55. u32 freq;
  56. u32 div;
  57. ref_rate = AR71XX_BASE_FREQ;
  58. pll = ath79_pll_rr(AR71XX_PLL_REG_CPU_CONFIG);
  59. div = ((pll >> AR71XX_PLL_FB_SHIFT) & AR71XX_PLL_FB_MASK) + 1;
  60. freq = div * ref_rate;
  61. div = ((pll >> AR71XX_CPU_DIV_SHIFT) & AR71XX_CPU_DIV_MASK) + 1;
  62. cpu_rate = freq / div;
  63. div = ((pll >> AR71XX_DDR_DIV_SHIFT) & AR71XX_DDR_DIV_MASK) + 1;
  64. ddr_rate = freq / div;
  65. div = (((pll >> AR71XX_AHB_DIV_SHIFT) & AR71XX_AHB_DIV_MASK) + 1) * 2;
  66. ahb_rate = cpu_rate / div;
  67. ath79_add_sys_clkdev("ref", ref_rate);
  68. clks[ATH79_CLK_CPU] = ath79_add_sys_clkdev("cpu", cpu_rate);
  69. clks[ATH79_CLK_DDR] = ath79_add_sys_clkdev("ddr", ddr_rate);
  70. clks[ATH79_CLK_AHB] = ath79_add_sys_clkdev("ahb", ahb_rate);
  71. clk_add_alias("wdt", NULL, "ahb", NULL);
  72. clk_add_alias("uart", NULL, "ahb", NULL);
  73. }
  74. static struct clk * __init ath79_reg_ffclk(const char *name,
  75. const char *parent_name, unsigned int mult, unsigned int div)
  76. {
  77. struct clk *clk;
  78. clk = clk_register_fixed_factor(NULL, name, parent_name, 0, mult, div);
  79. if (IS_ERR(clk))
  80. panic("failed to allocate %s clock structure", name);
  81. return clk;
  82. }
  83. static void __init ar724x_clk_init(struct clk *ref_clk, void __iomem *pll_base)
  84. {
  85. u32 pll;
  86. u32 mult, div, ddr_div, ahb_div;
  87. pll = __raw_readl(pll_base + AR724X_PLL_REG_CPU_CONFIG);
  88. mult = ((pll >> AR724X_PLL_FB_SHIFT) & AR724X_PLL_FB_MASK);
  89. div = ((pll >> AR724X_PLL_REF_DIV_SHIFT) & AR724X_PLL_REF_DIV_MASK) * 2;
  90. ddr_div = ((pll >> AR724X_DDR_DIV_SHIFT) & AR724X_DDR_DIV_MASK) + 1;
  91. ahb_div = (((pll >> AR724X_AHB_DIV_SHIFT) & AR724X_AHB_DIV_MASK) + 1) * 2;
  92. clks[ATH79_CLK_CPU] = ath79_reg_ffclk("cpu", "ref", mult, div);
  93. clks[ATH79_CLK_DDR] = ath79_reg_ffclk("ddr", "ref", mult, div * ddr_div);
  94. clks[ATH79_CLK_AHB] = ath79_reg_ffclk("ahb", "ref", mult, div * ahb_div);
  95. }
  96. static void __init ar724x_clocks_init(void)
  97. {
  98. struct clk *ref_clk;
  99. ref_clk = ath79_add_sys_clkdev("ref", AR724X_BASE_FREQ);
  100. ar724x_clk_init(ref_clk, ath79_pll_base);
  101. /* just make happy plat_time_init() from arch/mips/ath79/setup.c */
  102. clk_register_clkdev(clks[ATH79_CLK_CPU], "cpu", NULL);
  103. clk_register_clkdev(clks[ATH79_CLK_DDR], "ddr", NULL);
  104. clk_register_clkdev(clks[ATH79_CLK_AHB], "ahb", NULL);
  105. clk_add_alias("wdt", NULL, "ahb", NULL);
  106. clk_add_alias("uart", NULL, "ahb", NULL);
  107. }
  108. static void __init ar9330_clk_init(struct clk *ref_clk, void __iomem *pll_base)
  109. {
  110. u32 clock_ctrl;
  111. u32 ref_div;
  112. u32 ninit_mul;
  113. u32 out_div;
  114. u32 cpu_div;
  115. u32 ddr_div;
  116. u32 ahb_div;
  117. clock_ctrl = __raw_readl(pll_base + AR933X_PLL_CLOCK_CTRL_REG);
  118. if (clock_ctrl & AR933X_PLL_CLOCK_CTRL_BYPASS) {
  119. ref_div = 1;
  120. ninit_mul = 1;
  121. out_div = 1;
  122. cpu_div = 1;
  123. ddr_div = 1;
  124. ahb_div = 1;
  125. } else {
  126. u32 cpu_config;
  127. u32 t;
  128. cpu_config = __raw_readl(pll_base + AR933X_PLL_CPU_CONFIG_REG);
  129. t = (cpu_config >> AR933X_PLL_CPU_CONFIG_REFDIV_SHIFT) &
  130. AR933X_PLL_CPU_CONFIG_REFDIV_MASK;
  131. ref_div = t;
  132. ninit_mul = (cpu_config >> AR933X_PLL_CPU_CONFIG_NINT_SHIFT) &
  133. AR933X_PLL_CPU_CONFIG_NINT_MASK;
  134. t = (cpu_config >> AR933X_PLL_CPU_CONFIG_OUTDIV_SHIFT) &
  135. AR933X_PLL_CPU_CONFIG_OUTDIV_MASK;
  136. if (t == 0)
  137. t = 1;
  138. out_div = (1 << t);
  139. cpu_div = ((clock_ctrl >> AR933X_PLL_CLOCK_CTRL_CPU_DIV_SHIFT) &
  140. AR933X_PLL_CLOCK_CTRL_CPU_DIV_MASK) + 1;
  141. ddr_div = ((clock_ctrl >> AR933X_PLL_CLOCK_CTRL_DDR_DIV_SHIFT) &
  142. AR933X_PLL_CLOCK_CTRL_DDR_DIV_MASK) + 1;
  143. ahb_div = ((clock_ctrl >> AR933X_PLL_CLOCK_CTRL_AHB_DIV_SHIFT) &
  144. AR933X_PLL_CLOCK_CTRL_AHB_DIV_MASK) + 1;
  145. }
  146. clks[ATH79_CLK_CPU] = ath79_reg_ffclk("cpu", "ref",
  147. ninit_mul, ref_div * out_div * cpu_div);
  148. clks[ATH79_CLK_DDR] = ath79_reg_ffclk("ddr", "ref",
  149. ninit_mul, ref_div * out_div * ddr_div);
  150. clks[ATH79_CLK_AHB] = ath79_reg_ffclk("ahb", "ref",
  151. ninit_mul, ref_div * out_div * ahb_div);
  152. }
  153. static void __init ar933x_clocks_init(void)
  154. {
  155. struct clk *ref_clk;
  156. unsigned long ref_rate;
  157. u32 t;
  158. t = ath79_reset_rr(AR933X_RESET_REG_BOOTSTRAP);
  159. if (t & AR933X_BOOTSTRAP_REF_CLK_40)
  160. ref_rate = (40 * 1000 * 1000);
  161. else
  162. ref_rate = (25 * 1000 * 1000);
  163. ref_clk = ath79_add_sys_clkdev("ref", ref_rate);
  164. ar9330_clk_init(ref_clk, ath79_pll_base);
  165. /* just make happy plat_time_init() from arch/mips/ath79/setup.c */
  166. clk_register_clkdev(clks[ATH79_CLK_CPU], "cpu", NULL);
  167. clk_register_clkdev(clks[ATH79_CLK_DDR], "ddr", NULL);
  168. clk_register_clkdev(clks[ATH79_CLK_AHB], "ahb", NULL);
  169. clk_add_alias("wdt", NULL, "ahb", NULL);
  170. clk_add_alias("uart", NULL, "ref", NULL);
  171. }
  172. static u32 __init ar934x_get_pll_freq(u32 ref, u32 ref_div, u32 nint, u32 nfrac,
  173. u32 frac, u32 out_div)
  174. {
  175. u64 t;
  176. u32 ret;
  177. t = ref;
  178. t *= nint;
  179. do_div(t, ref_div);
  180. ret = t;
  181. t = ref;
  182. t *= nfrac;
  183. do_div(t, ref_div * frac);
  184. ret += t;
  185. ret /= (1 << out_div);
  186. return ret;
  187. }
  188. static void __init ar934x_clocks_init(void)
  189. {
  190. unsigned long ref_rate;
  191. unsigned long cpu_rate;
  192. unsigned long ddr_rate;
  193. unsigned long ahb_rate;
  194. u32 pll, out_div, ref_div, nint, nfrac, frac, clk_ctrl, postdiv;
  195. u32 cpu_pll, ddr_pll;
  196. u32 bootstrap;
  197. void __iomem *dpll_base;
  198. dpll_base = ioremap(AR934X_SRIF_BASE, AR934X_SRIF_SIZE);
  199. bootstrap = ath79_reset_rr(AR934X_RESET_REG_BOOTSTRAP);
  200. if (bootstrap & AR934X_BOOTSTRAP_REF_CLK_40)
  201. ref_rate = 40 * 1000 * 1000;
  202. else
  203. ref_rate = 25 * 1000 * 1000;
  204. pll = __raw_readl(dpll_base + AR934X_SRIF_CPU_DPLL2_REG);
  205. if (pll & AR934X_SRIF_DPLL2_LOCAL_PLL) {
  206. out_div = (pll >> AR934X_SRIF_DPLL2_OUTDIV_SHIFT) &
  207. AR934X_SRIF_DPLL2_OUTDIV_MASK;
  208. pll = __raw_readl(dpll_base + AR934X_SRIF_CPU_DPLL1_REG);
  209. nint = (pll >> AR934X_SRIF_DPLL1_NINT_SHIFT) &
  210. AR934X_SRIF_DPLL1_NINT_MASK;
  211. nfrac = pll & AR934X_SRIF_DPLL1_NFRAC_MASK;
  212. ref_div = (pll >> AR934X_SRIF_DPLL1_REFDIV_SHIFT) &
  213. AR934X_SRIF_DPLL1_REFDIV_MASK;
  214. frac = 1 << 18;
  215. } else {
  216. pll = ath79_pll_rr(AR934X_PLL_CPU_CONFIG_REG);
  217. out_div = (pll >> AR934X_PLL_CPU_CONFIG_OUTDIV_SHIFT) &
  218. AR934X_PLL_CPU_CONFIG_OUTDIV_MASK;
  219. ref_div = (pll >> AR934X_PLL_CPU_CONFIG_REFDIV_SHIFT) &
  220. AR934X_PLL_CPU_CONFIG_REFDIV_MASK;
  221. nint = (pll >> AR934X_PLL_CPU_CONFIG_NINT_SHIFT) &
  222. AR934X_PLL_CPU_CONFIG_NINT_MASK;
  223. nfrac = (pll >> AR934X_PLL_CPU_CONFIG_NFRAC_SHIFT) &
  224. AR934X_PLL_CPU_CONFIG_NFRAC_MASK;
  225. frac = 1 << 6;
  226. }
  227. cpu_pll = ar934x_get_pll_freq(ref_rate, ref_div, nint,
  228. nfrac, frac, out_div);
  229. pll = __raw_readl(dpll_base + AR934X_SRIF_DDR_DPLL2_REG);
  230. if (pll & AR934X_SRIF_DPLL2_LOCAL_PLL) {
  231. out_div = (pll >> AR934X_SRIF_DPLL2_OUTDIV_SHIFT) &
  232. AR934X_SRIF_DPLL2_OUTDIV_MASK;
  233. pll = __raw_readl(dpll_base + AR934X_SRIF_DDR_DPLL1_REG);
  234. nint = (pll >> AR934X_SRIF_DPLL1_NINT_SHIFT) &
  235. AR934X_SRIF_DPLL1_NINT_MASK;
  236. nfrac = pll & AR934X_SRIF_DPLL1_NFRAC_MASK;
  237. ref_div = (pll >> AR934X_SRIF_DPLL1_REFDIV_SHIFT) &
  238. AR934X_SRIF_DPLL1_REFDIV_MASK;
  239. frac = 1 << 18;
  240. } else {
  241. pll = ath79_pll_rr(AR934X_PLL_DDR_CONFIG_REG);
  242. out_div = (pll >> AR934X_PLL_DDR_CONFIG_OUTDIV_SHIFT) &
  243. AR934X_PLL_DDR_CONFIG_OUTDIV_MASK;
  244. ref_div = (pll >> AR934X_PLL_DDR_CONFIG_REFDIV_SHIFT) &
  245. AR934X_PLL_DDR_CONFIG_REFDIV_MASK;
  246. nint = (pll >> AR934X_PLL_DDR_CONFIG_NINT_SHIFT) &
  247. AR934X_PLL_DDR_CONFIG_NINT_MASK;
  248. nfrac = (pll >> AR934X_PLL_DDR_CONFIG_NFRAC_SHIFT) &
  249. AR934X_PLL_DDR_CONFIG_NFRAC_MASK;
  250. frac = 1 << 10;
  251. }
  252. ddr_pll = ar934x_get_pll_freq(ref_rate, ref_div, nint,
  253. nfrac, frac, out_div);
  254. clk_ctrl = ath79_pll_rr(AR934X_PLL_CPU_DDR_CLK_CTRL_REG);
  255. postdiv = (clk_ctrl >> AR934X_PLL_CPU_DDR_CLK_CTRL_CPU_POST_DIV_SHIFT) &
  256. AR934X_PLL_CPU_DDR_CLK_CTRL_CPU_POST_DIV_MASK;
  257. if (clk_ctrl & AR934X_PLL_CPU_DDR_CLK_CTRL_CPU_PLL_BYPASS)
  258. cpu_rate = ref_rate;
  259. else if (clk_ctrl & AR934X_PLL_CPU_DDR_CLK_CTRL_CPUCLK_FROM_CPUPLL)
  260. cpu_rate = cpu_pll / (postdiv + 1);
  261. else
  262. cpu_rate = ddr_pll / (postdiv + 1);
  263. postdiv = (clk_ctrl >> AR934X_PLL_CPU_DDR_CLK_CTRL_DDR_POST_DIV_SHIFT) &
  264. AR934X_PLL_CPU_DDR_CLK_CTRL_DDR_POST_DIV_MASK;
  265. if (clk_ctrl & AR934X_PLL_CPU_DDR_CLK_CTRL_DDR_PLL_BYPASS)
  266. ddr_rate = ref_rate;
  267. else if (clk_ctrl & AR934X_PLL_CPU_DDR_CLK_CTRL_DDRCLK_FROM_DDRPLL)
  268. ddr_rate = ddr_pll / (postdiv + 1);
  269. else
  270. ddr_rate = cpu_pll / (postdiv + 1);
  271. postdiv = (clk_ctrl >> AR934X_PLL_CPU_DDR_CLK_CTRL_AHB_POST_DIV_SHIFT) &
  272. AR934X_PLL_CPU_DDR_CLK_CTRL_AHB_POST_DIV_MASK;
  273. if (clk_ctrl & AR934X_PLL_CPU_DDR_CLK_CTRL_AHB_PLL_BYPASS)
  274. ahb_rate = ref_rate;
  275. else if (clk_ctrl & AR934X_PLL_CPU_DDR_CLK_CTRL_AHBCLK_FROM_DDRPLL)
  276. ahb_rate = ddr_pll / (postdiv + 1);
  277. else
  278. ahb_rate = cpu_pll / (postdiv + 1);
  279. ath79_add_sys_clkdev("ref", ref_rate);
  280. clks[ATH79_CLK_CPU] = ath79_add_sys_clkdev("cpu", cpu_rate);
  281. clks[ATH79_CLK_DDR] = ath79_add_sys_clkdev("ddr", ddr_rate);
  282. clks[ATH79_CLK_AHB] = ath79_add_sys_clkdev("ahb", ahb_rate);
  283. clk_add_alias("wdt", NULL, "ref", NULL);
  284. clk_add_alias("uart", NULL, "ref", NULL);
  285. iounmap(dpll_base);
  286. }
  287. static void __init qca955x_clocks_init(void)
  288. {
  289. unsigned long ref_rate;
  290. unsigned long cpu_rate;
  291. unsigned long ddr_rate;
  292. unsigned long ahb_rate;
  293. u32 pll, out_div, ref_div, nint, frac, clk_ctrl, postdiv;
  294. u32 cpu_pll, ddr_pll;
  295. u32 bootstrap;
  296. bootstrap = ath79_reset_rr(QCA955X_RESET_REG_BOOTSTRAP);
  297. if (bootstrap & QCA955X_BOOTSTRAP_REF_CLK_40)
  298. ref_rate = 40 * 1000 * 1000;
  299. else
  300. ref_rate = 25 * 1000 * 1000;
  301. pll = ath79_pll_rr(QCA955X_PLL_CPU_CONFIG_REG);
  302. out_div = (pll >> QCA955X_PLL_CPU_CONFIG_OUTDIV_SHIFT) &
  303. QCA955X_PLL_CPU_CONFIG_OUTDIV_MASK;
  304. ref_div = (pll >> QCA955X_PLL_CPU_CONFIG_REFDIV_SHIFT) &
  305. QCA955X_PLL_CPU_CONFIG_REFDIV_MASK;
  306. nint = (pll >> QCA955X_PLL_CPU_CONFIG_NINT_SHIFT) &
  307. QCA955X_PLL_CPU_CONFIG_NINT_MASK;
  308. frac = (pll >> QCA955X_PLL_CPU_CONFIG_NFRAC_SHIFT) &
  309. QCA955X_PLL_CPU_CONFIG_NFRAC_MASK;
  310. cpu_pll = nint * ref_rate / ref_div;
  311. cpu_pll += frac * ref_rate / (ref_div * (1 << 6));
  312. cpu_pll /= (1 << out_div);
  313. pll = ath79_pll_rr(QCA955X_PLL_DDR_CONFIG_REG);
  314. out_div = (pll >> QCA955X_PLL_DDR_CONFIG_OUTDIV_SHIFT) &
  315. QCA955X_PLL_DDR_CONFIG_OUTDIV_MASK;
  316. ref_div = (pll >> QCA955X_PLL_DDR_CONFIG_REFDIV_SHIFT) &
  317. QCA955X_PLL_DDR_CONFIG_REFDIV_MASK;
  318. nint = (pll >> QCA955X_PLL_DDR_CONFIG_NINT_SHIFT) &
  319. QCA955X_PLL_DDR_CONFIG_NINT_MASK;
  320. frac = (pll >> QCA955X_PLL_DDR_CONFIG_NFRAC_SHIFT) &
  321. QCA955X_PLL_DDR_CONFIG_NFRAC_MASK;
  322. ddr_pll = nint * ref_rate / ref_div;
  323. ddr_pll += frac * ref_rate / (ref_div * (1 << 10));
  324. ddr_pll /= (1 << out_div);
  325. clk_ctrl = ath79_pll_rr(QCA955X_PLL_CLK_CTRL_REG);
  326. postdiv = (clk_ctrl >> QCA955X_PLL_CLK_CTRL_CPU_POST_DIV_SHIFT) &
  327. QCA955X_PLL_CLK_CTRL_CPU_POST_DIV_MASK;
  328. if (clk_ctrl & QCA955X_PLL_CLK_CTRL_CPU_PLL_BYPASS)
  329. cpu_rate = ref_rate;
  330. else if (clk_ctrl & QCA955X_PLL_CLK_CTRL_CPUCLK_FROM_CPUPLL)
  331. cpu_rate = ddr_pll / (postdiv + 1);
  332. else
  333. cpu_rate = cpu_pll / (postdiv + 1);
  334. postdiv = (clk_ctrl >> QCA955X_PLL_CLK_CTRL_DDR_POST_DIV_SHIFT) &
  335. QCA955X_PLL_CLK_CTRL_DDR_POST_DIV_MASK;
  336. if (clk_ctrl & QCA955X_PLL_CLK_CTRL_DDR_PLL_BYPASS)
  337. ddr_rate = ref_rate;
  338. else if (clk_ctrl & QCA955X_PLL_CLK_CTRL_DDRCLK_FROM_DDRPLL)
  339. ddr_rate = cpu_pll / (postdiv + 1);
  340. else
  341. ddr_rate = ddr_pll / (postdiv + 1);
  342. postdiv = (clk_ctrl >> QCA955X_PLL_CLK_CTRL_AHB_POST_DIV_SHIFT) &
  343. QCA955X_PLL_CLK_CTRL_AHB_POST_DIV_MASK;
  344. if (clk_ctrl & QCA955X_PLL_CLK_CTRL_AHB_PLL_BYPASS)
  345. ahb_rate = ref_rate;
  346. else if (clk_ctrl & QCA955X_PLL_CLK_CTRL_AHBCLK_FROM_DDRPLL)
  347. ahb_rate = ddr_pll / (postdiv + 1);
  348. else
  349. ahb_rate = cpu_pll / (postdiv + 1);
  350. ath79_add_sys_clkdev("ref", ref_rate);
  351. clks[ATH79_CLK_CPU] = ath79_add_sys_clkdev("cpu", cpu_rate);
  352. clks[ATH79_CLK_DDR] = ath79_add_sys_clkdev("ddr", ddr_rate);
  353. clks[ATH79_CLK_AHB] = ath79_add_sys_clkdev("ahb", ahb_rate);
  354. clk_add_alias("wdt", NULL, "ref", NULL);
  355. clk_add_alias("uart", NULL, "ref", NULL);
  356. }
  357. void __init ath79_clocks_init(void)
  358. {
  359. if (soc_is_ar71xx())
  360. ar71xx_clocks_init();
  361. else if (soc_is_ar724x() || soc_is_ar913x())
  362. ar724x_clocks_init();
  363. else if (soc_is_ar933x())
  364. ar933x_clocks_init();
  365. else if (soc_is_ar934x())
  366. ar934x_clocks_init();
  367. else if (soc_is_qca955x())
  368. qca955x_clocks_init();
  369. else
  370. BUG();
  371. }
  372. unsigned long __init
  373. ath79_get_sys_clk_rate(const char *id)
  374. {
  375. struct clk *clk;
  376. unsigned long rate;
  377. clk = clk_get(NULL, id);
  378. if (IS_ERR(clk))
  379. panic("unable to get %s clock, err=%d", id, (int) PTR_ERR(clk));
  380. rate = clk_get_rate(clk);
  381. clk_put(clk);
  382. return rate;
  383. }
  384. #ifdef CONFIG_OF
  385. static void __init ath79_clocks_init_dt(struct device_node *np)
  386. {
  387. of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data);
  388. }
  389. CLK_OF_DECLARE(ar7100, "qca,ar7100-pll", ath79_clocks_init_dt);
  390. CLK_OF_DECLARE(ar7240, "qca,ar7240-pll", ath79_clocks_init_dt);
  391. CLK_OF_DECLARE(ar9340, "qca,ar9340-pll", ath79_clocks_init_dt);
  392. CLK_OF_DECLARE(ar9550, "qca,qca9550-pll", ath79_clocks_init_dt);
  393. static void __init ath79_clocks_init_dt_ng(struct device_node *np)
  394. {
  395. struct clk *ref_clk;
  396. void __iomem *pll_base;
  397. const char *dnfn = of_node_full_name(np);
  398. ref_clk = of_clk_get(np, 0);
  399. if (IS_ERR(ref_clk)) {
  400. pr_err("%s: of_clk_get failed\n", dnfn);
  401. goto err;
  402. }
  403. pll_base = of_iomap(np, 0);
  404. if (!pll_base) {
  405. pr_err("%s: can't map pll registers\n", dnfn);
  406. goto err_clk;
  407. }
  408. if (of_device_is_compatible(np, "qca,ar9130-pll"))
  409. ar724x_clk_init(ref_clk, pll_base);
  410. else if (of_device_is_compatible(np, "qca,ar9330-pll"))
  411. ar9330_clk_init(ref_clk, pll_base);
  412. else {
  413. pr_err("%s: could not find any appropriate clk_init()\n", dnfn);
  414. goto err_iounmap;
  415. }
  416. if (of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data)) {
  417. pr_err("%s: could not register clk provider\n", dnfn);
  418. goto err_iounmap;
  419. }
  420. return;
  421. err_iounmap:
  422. iounmap(pll_base);
  423. err_clk:
  424. clk_put(ref_clk);
  425. err:
  426. return;
  427. }
  428. CLK_OF_DECLARE(ar9130_clk, "qca,ar9130-pll", ath79_clocks_init_dt_ng);
  429. CLK_OF_DECLARE(ar9330_clk, "qca,ar9330-pll", ath79_clocks_init_dt_ng);
  430. #endif