clock.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  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 <asm/div64.h>
  21. #include <asm/mach-ath79/ath79.h>
  22. #include <asm/mach-ath79/ar71xx_regs.h>
  23. #include "common.h"
  24. #define AR71XX_BASE_FREQ 40000000
  25. #define AR724X_BASE_FREQ 5000000
  26. #define AR913X_BASE_FREQ 5000000
  27. static struct clk *clks[3];
  28. static struct clk_onecell_data clk_data = {
  29. .clks = clks,
  30. .clk_num = ARRAY_SIZE(clks),
  31. };
  32. static struct clk *__init ath79_add_sys_clkdev(
  33. const char *id, unsigned long rate)
  34. {
  35. struct clk *clk;
  36. int err;
  37. clk = clk_register_fixed_rate(NULL, id, NULL, CLK_IS_ROOT, rate);
  38. if (!clk)
  39. panic("failed to allocate %s clock structure", id);
  40. err = clk_register_clkdev(clk, id, NULL);
  41. if (err)
  42. panic("unable to register %s clock device", id);
  43. return clk;
  44. }
  45. static void __init ar71xx_clocks_init(void)
  46. {
  47. unsigned long ref_rate;
  48. unsigned long cpu_rate;
  49. unsigned long ddr_rate;
  50. unsigned long ahb_rate;
  51. u32 pll;
  52. u32 freq;
  53. u32 div;
  54. ref_rate = AR71XX_BASE_FREQ;
  55. pll = ath79_pll_rr(AR71XX_PLL_REG_CPU_CONFIG);
  56. div = ((pll >> AR71XX_PLL_FB_SHIFT) & AR71XX_PLL_FB_MASK) + 1;
  57. freq = div * ref_rate;
  58. div = ((pll >> AR71XX_CPU_DIV_SHIFT) & AR71XX_CPU_DIV_MASK) + 1;
  59. cpu_rate = freq / div;
  60. div = ((pll >> AR71XX_DDR_DIV_SHIFT) & AR71XX_DDR_DIV_MASK) + 1;
  61. ddr_rate = freq / div;
  62. div = (((pll >> AR71XX_AHB_DIV_SHIFT) & AR71XX_AHB_DIV_MASK) + 1) * 2;
  63. ahb_rate = cpu_rate / div;
  64. ath79_add_sys_clkdev("ref", ref_rate);
  65. clks[0] = ath79_add_sys_clkdev("cpu", cpu_rate);
  66. clks[1] = ath79_add_sys_clkdev("ddr", ddr_rate);
  67. clks[2] = ath79_add_sys_clkdev("ahb", ahb_rate);
  68. clk_add_alias("wdt", NULL, "ahb", NULL);
  69. clk_add_alias("uart", NULL, "ahb", NULL);
  70. }
  71. static void __init ar724x_clocks_init(void)
  72. {
  73. unsigned long ref_rate;
  74. unsigned long cpu_rate;
  75. unsigned long ddr_rate;
  76. unsigned long ahb_rate;
  77. u32 pll;
  78. u32 freq;
  79. u32 div;
  80. ref_rate = AR724X_BASE_FREQ;
  81. pll = ath79_pll_rr(AR724X_PLL_REG_CPU_CONFIG);
  82. div = ((pll >> AR724X_PLL_FB_SHIFT) & AR724X_PLL_FB_MASK);
  83. freq = div * ref_rate;
  84. div = ((pll >> AR724X_PLL_REF_DIV_SHIFT) & AR724X_PLL_REF_DIV_MASK);
  85. freq *= div;
  86. cpu_rate = freq;
  87. div = ((pll >> AR724X_DDR_DIV_SHIFT) & AR724X_DDR_DIV_MASK) + 1;
  88. ddr_rate = freq / div;
  89. div = (((pll >> AR724X_AHB_DIV_SHIFT) & AR724X_AHB_DIV_MASK) + 1) * 2;
  90. ahb_rate = cpu_rate / div;
  91. ath79_add_sys_clkdev("ref", ref_rate);
  92. clks[0] = ath79_add_sys_clkdev("cpu", cpu_rate);
  93. clks[1] = ath79_add_sys_clkdev("ddr", ddr_rate);
  94. clks[2] = ath79_add_sys_clkdev("ahb", ahb_rate);
  95. clk_add_alias("wdt", NULL, "ahb", NULL);
  96. clk_add_alias("uart", NULL, "ahb", NULL);
  97. }
  98. static void __init ar913x_clocks_init(void)
  99. {
  100. unsigned long ref_rate;
  101. unsigned long cpu_rate;
  102. unsigned long ddr_rate;
  103. unsigned long ahb_rate;
  104. u32 pll;
  105. u32 freq;
  106. u32 div;
  107. ref_rate = AR913X_BASE_FREQ;
  108. pll = ath79_pll_rr(AR913X_PLL_REG_CPU_CONFIG);
  109. div = ((pll >> AR913X_PLL_FB_SHIFT) & AR913X_PLL_FB_MASK);
  110. freq = div * ref_rate;
  111. cpu_rate = freq;
  112. div = ((pll >> AR913X_DDR_DIV_SHIFT) & AR913X_DDR_DIV_MASK) + 1;
  113. ddr_rate = freq / div;
  114. div = (((pll >> AR913X_AHB_DIV_SHIFT) & AR913X_AHB_DIV_MASK) + 1) * 2;
  115. ahb_rate = cpu_rate / div;
  116. ath79_add_sys_clkdev("ref", ref_rate);
  117. clks[0] = ath79_add_sys_clkdev("cpu", cpu_rate);
  118. clks[1] = ath79_add_sys_clkdev("ddr", ddr_rate);
  119. clks[2] = ath79_add_sys_clkdev("ahb", ahb_rate);
  120. clk_add_alias("wdt", NULL, "ahb", NULL);
  121. clk_add_alias("uart", NULL, "ahb", NULL);
  122. }
  123. static void __init ar933x_clocks_init(void)
  124. {
  125. unsigned long ref_rate;
  126. unsigned long cpu_rate;
  127. unsigned long ddr_rate;
  128. unsigned long ahb_rate;
  129. u32 clock_ctrl;
  130. u32 cpu_config;
  131. u32 freq;
  132. u32 t;
  133. t = ath79_reset_rr(AR933X_RESET_REG_BOOTSTRAP);
  134. if (t & AR933X_BOOTSTRAP_REF_CLK_40)
  135. ref_rate = (40 * 1000 * 1000);
  136. else
  137. ref_rate = (25 * 1000 * 1000);
  138. clock_ctrl = ath79_pll_rr(AR933X_PLL_CLOCK_CTRL_REG);
  139. if (clock_ctrl & AR933X_PLL_CLOCK_CTRL_BYPASS) {
  140. cpu_rate = ref_rate;
  141. ahb_rate = ref_rate;
  142. ddr_rate = ref_rate;
  143. } else {
  144. cpu_config = ath79_pll_rr(AR933X_PLL_CPU_CONFIG_REG);
  145. t = (cpu_config >> AR933X_PLL_CPU_CONFIG_REFDIV_SHIFT) &
  146. AR933X_PLL_CPU_CONFIG_REFDIV_MASK;
  147. freq = ref_rate / t;
  148. t = (cpu_config >> AR933X_PLL_CPU_CONFIG_NINT_SHIFT) &
  149. AR933X_PLL_CPU_CONFIG_NINT_MASK;
  150. freq *= t;
  151. t = (cpu_config >> AR933X_PLL_CPU_CONFIG_OUTDIV_SHIFT) &
  152. AR933X_PLL_CPU_CONFIG_OUTDIV_MASK;
  153. if (t == 0)
  154. t = 1;
  155. freq >>= t;
  156. t = ((clock_ctrl >> AR933X_PLL_CLOCK_CTRL_CPU_DIV_SHIFT) &
  157. AR933X_PLL_CLOCK_CTRL_CPU_DIV_MASK) + 1;
  158. cpu_rate = freq / t;
  159. t = ((clock_ctrl >> AR933X_PLL_CLOCK_CTRL_DDR_DIV_SHIFT) &
  160. AR933X_PLL_CLOCK_CTRL_DDR_DIV_MASK) + 1;
  161. ddr_rate = freq / t;
  162. t = ((clock_ctrl >> AR933X_PLL_CLOCK_CTRL_AHB_DIV_SHIFT) &
  163. AR933X_PLL_CLOCK_CTRL_AHB_DIV_MASK) + 1;
  164. ahb_rate = freq / t;
  165. }
  166. ath79_add_sys_clkdev("ref", ref_rate);
  167. clks[0] = ath79_add_sys_clkdev("cpu", cpu_rate);
  168. clks[1] = ath79_add_sys_clkdev("ddr", ddr_rate);
  169. clks[2] = ath79_add_sys_clkdev("ahb", ahb_rate);
  170. clk_add_alias("wdt", NULL, "ahb", NULL);
  171. clk_add_alias("uart", NULL, "ref", NULL);
  172. }
  173. static u32 __init ar934x_get_pll_freq(u32 ref, u32 ref_div, u32 nint, u32 nfrac,
  174. u32 frac, u32 out_div)
  175. {
  176. u64 t;
  177. u32 ret;
  178. t = ref;
  179. t *= nint;
  180. do_div(t, ref_div);
  181. ret = t;
  182. t = ref;
  183. t *= nfrac;
  184. do_div(t, ref_div * frac);
  185. ret += t;
  186. ret /= (1 << out_div);
  187. return ret;
  188. }
  189. static void __init ar934x_clocks_init(void)
  190. {
  191. unsigned long ref_rate;
  192. unsigned long cpu_rate;
  193. unsigned long ddr_rate;
  194. unsigned long ahb_rate;
  195. u32 pll, out_div, ref_div, nint, nfrac, frac, clk_ctrl, postdiv;
  196. u32 cpu_pll, ddr_pll;
  197. u32 bootstrap;
  198. void __iomem *dpll_base;
  199. dpll_base = ioremap(AR934X_SRIF_BASE, AR934X_SRIF_SIZE);
  200. bootstrap = ath79_reset_rr(AR934X_RESET_REG_BOOTSTRAP);
  201. if (bootstrap & AR934X_BOOTSTRAP_REF_CLK_40)
  202. ref_rate = 40 * 1000 * 1000;
  203. else
  204. ref_rate = 25 * 1000 * 1000;
  205. pll = __raw_readl(dpll_base + AR934X_SRIF_CPU_DPLL2_REG);
  206. if (pll & AR934X_SRIF_DPLL2_LOCAL_PLL) {
  207. out_div = (pll >> AR934X_SRIF_DPLL2_OUTDIV_SHIFT) &
  208. AR934X_SRIF_DPLL2_OUTDIV_MASK;
  209. pll = __raw_readl(dpll_base + AR934X_SRIF_CPU_DPLL1_REG);
  210. nint = (pll >> AR934X_SRIF_DPLL1_NINT_SHIFT) &
  211. AR934X_SRIF_DPLL1_NINT_MASK;
  212. nfrac = pll & AR934X_SRIF_DPLL1_NFRAC_MASK;
  213. ref_div = (pll >> AR934X_SRIF_DPLL1_REFDIV_SHIFT) &
  214. AR934X_SRIF_DPLL1_REFDIV_MASK;
  215. frac = 1 << 18;
  216. } else {
  217. pll = ath79_pll_rr(AR934X_PLL_CPU_CONFIG_REG);
  218. out_div = (pll >> AR934X_PLL_CPU_CONFIG_OUTDIV_SHIFT) &
  219. AR934X_PLL_CPU_CONFIG_OUTDIV_MASK;
  220. ref_div = (pll >> AR934X_PLL_CPU_CONFIG_REFDIV_SHIFT) &
  221. AR934X_PLL_CPU_CONFIG_REFDIV_MASK;
  222. nint = (pll >> AR934X_PLL_CPU_CONFIG_NINT_SHIFT) &
  223. AR934X_PLL_CPU_CONFIG_NINT_MASK;
  224. nfrac = (pll >> AR934X_PLL_CPU_CONFIG_NFRAC_SHIFT) &
  225. AR934X_PLL_CPU_CONFIG_NFRAC_MASK;
  226. frac = 1 << 6;
  227. }
  228. cpu_pll = ar934x_get_pll_freq(ref_rate, ref_div, nint,
  229. nfrac, frac, out_div);
  230. pll = __raw_readl(dpll_base + AR934X_SRIF_DDR_DPLL2_REG);
  231. if (pll & AR934X_SRIF_DPLL2_LOCAL_PLL) {
  232. out_div = (pll >> AR934X_SRIF_DPLL2_OUTDIV_SHIFT) &
  233. AR934X_SRIF_DPLL2_OUTDIV_MASK;
  234. pll = __raw_readl(dpll_base + AR934X_SRIF_DDR_DPLL1_REG);
  235. nint = (pll >> AR934X_SRIF_DPLL1_NINT_SHIFT) &
  236. AR934X_SRIF_DPLL1_NINT_MASK;
  237. nfrac = pll & AR934X_SRIF_DPLL1_NFRAC_MASK;
  238. ref_div = (pll >> AR934X_SRIF_DPLL1_REFDIV_SHIFT) &
  239. AR934X_SRIF_DPLL1_REFDIV_MASK;
  240. frac = 1 << 18;
  241. } else {
  242. pll = ath79_pll_rr(AR934X_PLL_DDR_CONFIG_REG);
  243. out_div = (pll >> AR934X_PLL_DDR_CONFIG_OUTDIV_SHIFT) &
  244. AR934X_PLL_DDR_CONFIG_OUTDIV_MASK;
  245. ref_div = (pll >> AR934X_PLL_DDR_CONFIG_REFDIV_SHIFT) &
  246. AR934X_PLL_DDR_CONFIG_REFDIV_MASK;
  247. nint = (pll >> AR934X_PLL_DDR_CONFIG_NINT_SHIFT) &
  248. AR934X_PLL_DDR_CONFIG_NINT_MASK;
  249. nfrac = (pll >> AR934X_PLL_DDR_CONFIG_NFRAC_SHIFT) &
  250. AR934X_PLL_DDR_CONFIG_NFRAC_MASK;
  251. frac = 1 << 10;
  252. }
  253. ddr_pll = ar934x_get_pll_freq(ref_rate, ref_div, nint,
  254. nfrac, frac, out_div);
  255. clk_ctrl = ath79_pll_rr(AR934X_PLL_CPU_DDR_CLK_CTRL_REG);
  256. postdiv = (clk_ctrl >> AR934X_PLL_CPU_DDR_CLK_CTRL_CPU_POST_DIV_SHIFT) &
  257. AR934X_PLL_CPU_DDR_CLK_CTRL_CPU_POST_DIV_MASK;
  258. if (clk_ctrl & AR934X_PLL_CPU_DDR_CLK_CTRL_CPU_PLL_BYPASS)
  259. cpu_rate = ref_rate;
  260. else if (clk_ctrl & AR934X_PLL_CPU_DDR_CLK_CTRL_CPUCLK_FROM_CPUPLL)
  261. cpu_rate = cpu_pll / (postdiv + 1);
  262. else
  263. cpu_rate = ddr_pll / (postdiv + 1);
  264. postdiv = (clk_ctrl >> AR934X_PLL_CPU_DDR_CLK_CTRL_DDR_POST_DIV_SHIFT) &
  265. AR934X_PLL_CPU_DDR_CLK_CTRL_DDR_POST_DIV_MASK;
  266. if (clk_ctrl & AR934X_PLL_CPU_DDR_CLK_CTRL_DDR_PLL_BYPASS)
  267. ddr_rate = ref_rate;
  268. else if (clk_ctrl & AR934X_PLL_CPU_DDR_CLK_CTRL_DDRCLK_FROM_DDRPLL)
  269. ddr_rate = ddr_pll / (postdiv + 1);
  270. else
  271. ddr_rate = cpu_pll / (postdiv + 1);
  272. postdiv = (clk_ctrl >> AR934X_PLL_CPU_DDR_CLK_CTRL_AHB_POST_DIV_SHIFT) &
  273. AR934X_PLL_CPU_DDR_CLK_CTRL_AHB_POST_DIV_MASK;
  274. if (clk_ctrl & AR934X_PLL_CPU_DDR_CLK_CTRL_AHB_PLL_BYPASS)
  275. ahb_rate = ref_rate;
  276. else if (clk_ctrl & AR934X_PLL_CPU_DDR_CLK_CTRL_AHBCLK_FROM_DDRPLL)
  277. ahb_rate = ddr_pll / (postdiv + 1);
  278. else
  279. ahb_rate = cpu_pll / (postdiv + 1);
  280. ath79_add_sys_clkdev("ref", ref_rate);
  281. clks[0] = ath79_add_sys_clkdev("cpu", cpu_rate);
  282. clks[1] = ath79_add_sys_clkdev("ddr", ddr_rate);
  283. clks[2] = ath79_add_sys_clkdev("ahb", ahb_rate);
  284. clk_add_alias("wdt", NULL, "ref", NULL);
  285. clk_add_alias("uart", NULL, "ref", NULL);
  286. iounmap(dpll_base);
  287. }
  288. static void __init qca955x_clocks_init(void)
  289. {
  290. unsigned long ref_rate;
  291. unsigned long cpu_rate;
  292. unsigned long ddr_rate;
  293. unsigned long ahb_rate;
  294. u32 pll, out_div, ref_div, nint, frac, clk_ctrl, postdiv;
  295. u32 cpu_pll, ddr_pll;
  296. u32 bootstrap;
  297. bootstrap = ath79_reset_rr(QCA955X_RESET_REG_BOOTSTRAP);
  298. if (bootstrap & QCA955X_BOOTSTRAP_REF_CLK_40)
  299. ref_rate = 40 * 1000 * 1000;
  300. else
  301. ref_rate = 25 * 1000 * 1000;
  302. pll = ath79_pll_rr(QCA955X_PLL_CPU_CONFIG_REG);
  303. out_div = (pll >> QCA955X_PLL_CPU_CONFIG_OUTDIV_SHIFT) &
  304. QCA955X_PLL_CPU_CONFIG_OUTDIV_MASK;
  305. ref_div = (pll >> QCA955X_PLL_CPU_CONFIG_REFDIV_SHIFT) &
  306. QCA955X_PLL_CPU_CONFIG_REFDIV_MASK;
  307. nint = (pll >> QCA955X_PLL_CPU_CONFIG_NINT_SHIFT) &
  308. QCA955X_PLL_CPU_CONFIG_NINT_MASK;
  309. frac = (pll >> QCA955X_PLL_CPU_CONFIG_NFRAC_SHIFT) &
  310. QCA955X_PLL_CPU_CONFIG_NFRAC_MASK;
  311. cpu_pll = nint * ref_rate / ref_div;
  312. cpu_pll += frac * ref_rate / (ref_div * (1 << 6));
  313. cpu_pll /= (1 << out_div);
  314. pll = ath79_pll_rr(QCA955X_PLL_DDR_CONFIG_REG);
  315. out_div = (pll >> QCA955X_PLL_DDR_CONFIG_OUTDIV_SHIFT) &
  316. QCA955X_PLL_DDR_CONFIG_OUTDIV_MASK;
  317. ref_div = (pll >> QCA955X_PLL_DDR_CONFIG_REFDIV_SHIFT) &
  318. QCA955X_PLL_DDR_CONFIG_REFDIV_MASK;
  319. nint = (pll >> QCA955X_PLL_DDR_CONFIG_NINT_SHIFT) &
  320. QCA955X_PLL_DDR_CONFIG_NINT_MASK;
  321. frac = (pll >> QCA955X_PLL_DDR_CONFIG_NFRAC_SHIFT) &
  322. QCA955X_PLL_DDR_CONFIG_NFRAC_MASK;
  323. ddr_pll = nint * ref_rate / ref_div;
  324. ddr_pll += frac * ref_rate / (ref_div * (1 << 10));
  325. ddr_pll /= (1 << out_div);
  326. clk_ctrl = ath79_pll_rr(QCA955X_PLL_CLK_CTRL_REG);
  327. postdiv = (clk_ctrl >> QCA955X_PLL_CLK_CTRL_CPU_POST_DIV_SHIFT) &
  328. QCA955X_PLL_CLK_CTRL_CPU_POST_DIV_MASK;
  329. if (clk_ctrl & QCA955X_PLL_CLK_CTRL_CPU_PLL_BYPASS)
  330. cpu_rate = ref_rate;
  331. else if (clk_ctrl & QCA955X_PLL_CLK_CTRL_CPUCLK_FROM_CPUPLL)
  332. cpu_rate = ddr_pll / (postdiv + 1);
  333. else
  334. cpu_rate = cpu_pll / (postdiv + 1);
  335. postdiv = (clk_ctrl >> QCA955X_PLL_CLK_CTRL_DDR_POST_DIV_SHIFT) &
  336. QCA955X_PLL_CLK_CTRL_DDR_POST_DIV_MASK;
  337. if (clk_ctrl & QCA955X_PLL_CLK_CTRL_DDR_PLL_BYPASS)
  338. ddr_rate = ref_rate;
  339. else if (clk_ctrl & QCA955X_PLL_CLK_CTRL_DDRCLK_FROM_DDRPLL)
  340. ddr_rate = cpu_pll / (postdiv + 1);
  341. else
  342. ddr_rate = ddr_pll / (postdiv + 1);
  343. postdiv = (clk_ctrl >> QCA955X_PLL_CLK_CTRL_AHB_POST_DIV_SHIFT) &
  344. QCA955X_PLL_CLK_CTRL_AHB_POST_DIV_MASK;
  345. if (clk_ctrl & QCA955X_PLL_CLK_CTRL_AHB_PLL_BYPASS)
  346. ahb_rate = ref_rate;
  347. else if (clk_ctrl & QCA955X_PLL_CLK_CTRL_AHBCLK_FROM_DDRPLL)
  348. ahb_rate = ddr_pll / (postdiv + 1);
  349. else
  350. ahb_rate = cpu_pll / (postdiv + 1);
  351. ath79_add_sys_clkdev("ref", ref_rate);
  352. clks[0] = ath79_add_sys_clkdev("cpu", cpu_rate);
  353. clks[1] = ath79_add_sys_clkdev("ddr", ddr_rate);
  354. clks[2] = ath79_add_sys_clkdev("ahb", ahb_rate);
  355. clk_add_alias("wdt", NULL, "ref", NULL);
  356. clk_add_alias("uart", NULL, "ref", NULL);
  357. }
  358. void __init ath79_clocks_init(void)
  359. {
  360. if (soc_is_ar71xx())
  361. ar71xx_clocks_init();
  362. else if (soc_is_ar724x())
  363. ar724x_clocks_init();
  364. else if (soc_is_ar913x())
  365. ar913x_clocks_init();
  366. else if (soc_is_ar933x())
  367. ar933x_clocks_init();
  368. else if (soc_is_ar934x())
  369. ar934x_clocks_init();
  370. else if (soc_is_qca955x())
  371. qca955x_clocks_init();
  372. else
  373. BUG();
  374. of_clk_init(NULL);
  375. }
  376. unsigned long __init
  377. ath79_get_sys_clk_rate(const char *id)
  378. {
  379. struct clk *clk;
  380. unsigned long rate;
  381. clk = clk_get(NULL, id);
  382. if (IS_ERR(clk))
  383. panic("unable to get %s clock, err=%d", id, (int) PTR_ERR(clk));
  384. rate = clk_get_rate(clk);
  385. clk_put(clk);
  386. return rate;
  387. }
  388. #ifdef CONFIG_OF
  389. static void __init ath79_clocks_init_dt(struct device_node *np)
  390. {
  391. of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data);
  392. }
  393. CLK_OF_DECLARE(ar7100, "qca,ar7100-pll", ath79_clocks_init_dt);
  394. CLK_OF_DECLARE(ar7240, "qca,ar7240-pll", ath79_clocks_init_dt);
  395. CLK_OF_DECLARE(ar9130, "qca,ar9130-pll", ath79_clocks_init_dt);
  396. CLK_OF_DECLARE(ar9330, "qca,ar9330-pll", ath79_clocks_init_dt);
  397. CLK_OF_DECLARE(ar9340, "qca,ar9340-pll", ath79_clocks_init_dt);
  398. CLK_OF_DECLARE(ar9550, "qca,qca9550-pll", ath79_clocks_init_dt);
  399. #endif