s5p-clock.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /*
  2. * Copyright 2009 Samsung Electronics Co., Ltd.
  3. * http://www.samsung.com/
  4. *
  5. * S5P - Common clock support
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/init.h>
  12. #include <linux/module.h>
  13. #include <linux/kernel.h>
  14. #include <linux/list.h>
  15. #include <linux/errno.h>
  16. #include <linux/err.h>
  17. #include <linux/clk.h>
  18. #include <linux/device.h>
  19. #include <linux/io.h>
  20. #include <asm/div64.h>
  21. #include <mach/regs-clock.h>
  22. #include <plat/clock.h>
  23. #include <plat/clock-clksrc.h>
  24. #include <plat/s5p-clock.h>
  25. /* fin_apll, fin_mpll and fin_epll are all the same clock, which we call
  26. * clk_ext_xtal_mux.
  27. */
  28. struct clk clk_ext_xtal_mux = {
  29. .name = "ext_xtal",
  30. .id = -1,
  31. };
  32. struct clk clk_xusbxti = {
  33. .name = "xusbxti",
  34. .id = -1,
  35. .rate = 24000000,
  36. };
  37. struct clk s5p_clk_27m = {
  38. .name = "clk_27m",
  39. .id = -1,
  40. .rate = 27000000,
  41. };
  42. /* 48MHz USB Phy clock output */
  43. struct clk clk_48m = {
  44. .name = "clk_48m",
  45. .id = -1,
  46. .rate = 48000000,
  47. };
  48. /* APLL clock output
  49. * No need .ctrlbit, this is always on
  50. */
  51. struct clk clk_fout_apll = {
  52. .name = "fout_apll",
  53. .id = -1,
  54. };
  55. /* BPLL clock output */
  56. struct clk clk_fout_bpll = {
  57. .name = "fout_bpll",
  58. .id = -1,
  59. };
  60. struct clk clk_fout_bpll_div2 = {
  61. .name = "fout_bpll_div2",
  62. .id = -1,
  63. };
  64. /* CPLL clock output */
  65. struct clk clk_fout_cpll = {
  66. .name = "fout_cpll",
  67. .id = -1,
  68. };
  69. /* MPLL clock output
  70. * No need .ctrlbit, this is always on
  71. */
  72. struct clk clk_fout_mpll = {
  73. .name = "fout_mpll",
  74. .id = -1,
  75. };
  76. struct clk clk_fout_mpll_div2 = {
  77. .name = "fout_mpll_div2",
  78. .id = -1,
  79. };
  80. /* EPLL clock output */
  81. struct clk clk_fout_epll = {
  82. .name = "fout_epll",
  83. .id = -1,
  84. .ctrlbit = (1 << 31),
  85. };
  86. /* DPLL clock output */
  87. struct clk clk_fout_dpll = {
  88. .name = "fout_dpll",
  89. .id = -1,
  90. .ctrlbit = (1 << 31),
  91. };
  92. /* VPLL clock output */
  93. struct clk clk_fout_vpll = {
  94. .name = "fout_vpll",
  95. .id = -1,
  96. .ctrlbit = (1 << 31),
  97. };
  98. /* Possible clock sources for APLL Mux */
  99. static struct clk *clk_src_apll_list[] = {
  100. [0] = &clk_fin_apll,
  101. [1] = &clk_fout_apll,
  102. };
  103. struct clksrc_sources clk_src_apll = {
  104. .sources = clk_src_apll_list,
  105. .nr_sources = ARRAY_SIZE(clk_src_apll_list),
  106. };
  107. /* Possible clock sources for BPLL Mux */
  108. static struct clk *clk_src_bpll_list[] = {
  109. [0] = &clk_fin_bpll,
  110. [1] = &clk_fout_bpll,
  111. };
  112. struct clksrc_sources clk_src_bpll = {
  113. .sources = clk_src_bpll_list,
  114. .nr_sources = ARRAY_SIZE(clk_src_bpll_list),
  115. };
  116. static struct clk *clk_src_bpll_fout_list[] = {
  117. [0] = &clk_fout_bpll_div2,
  118. [1] = &clk_fout_bpll,
  119. };
  120. struct clksrc_sources clk_src_bpll_fout = {
  121. .sources = clk_src_bpll_fout_list,
  122. .nr_sources = ARRAY_SIZE(clk_src_bpll_fout_list),
  123. };
  124. /* Possible clock sources for CPLL Mux */
  125. static struct clk *clk_src_cpll_list[] = {
  126. [0] = &clk_fin_cpll,
  127. [1] = &clk_fout_cpll,
  128. };
  129. struct clksrc_sources clk_src_cpll = {
  130. .sources = clk_src_cpll_list,
  131. .nr_sources = ARRAY_SIZE(clk_src_cpll_list),
  132. };
  133. /* Possible clock sources for MPLL Mux */
  134. static struct clk *clk_src_mpll_list[] = {
  135. [0] = &clk_fin_mpll,
  136. [1] = &clk_fout_mpll,
  137. };
  138. struct clksrc_sources clk_src_mpll = {
  139. .sources = clk_src_mpll_list,
  140. .nr_sources = ARRAY_SIZE(clk_src_mpll_list),
  141. };
  142. static struct clk *clk_src_mpll_fout_list[] = {
  143. [0] = &clk_fout_mpll_div2,
  144. [1] = &clk_fout_mpll,
  145. };
  146. struct clksrc_sources clk_src_mpll_fout = {
  147. .sources = clk_src_mpll_fout_list,
  148. .nr_sources = ARRAY_SIZE(clk_src_mpll_fout_list),
  149. };
  150. /* Possible clock sources for EPLL Mux */
  151. static struct clk *clk_src_epll_list[] = {
  152. [0] = &clk_fin_epll,
  153. [1] = &clk_fout_epll,
  154. };
  155. struct clksrc_sources clk_src_epll = {
  156. .sources = clk_src_epll_list,
  157. .nr_sources = ARRAY_SIZE(clk_src_epll_list),
  158. };
  159. /* Possible clock sources for DPLL Mux */
  160. static struct clk *clk_src_dpll_list[] = {
  161. [0] = &clk_fin_dpll,
  162. [1] = &clk_fout_dpll,
  163. };
  164. struct clksrc_sources clk_src_dpll = {
  165. .sources = clk_src_dpll_list,
  166. .nr_sources = ARRAY_SIZE(clk_src_dpll_list),
  167. };
  168. struct clk clk_vpll = {
  169. .name = "vpll",
  170. .id = -1,
  171. };
  172. int s5p_gatectrl(void __iomem *reg, struct clk *clk, int enable)
  173. {
  174. unsigned int ctrlbit = clk->ctrlbit;
  175. u32 con;
  176. con = __raw_readl(reg);
  177. con = enable ? (con | ctrlbit) : (con & ~ctrlbit);
  178. __raw_writel(con, reg);
  179. return 0;
  180. }
  181. int s5p_epll_enable(struct clk *clk, int enable)
  182. {
  183. unsigned int ctrlbit = clk->ctrlbit;
  184. unsigned int epll_con = __raw_readl(S5P_EPLL_CON) & ~ctrlbit;
  185. if (enable)
  186. __raw_writel(epll_con | ctrlbit, S5P_EPLL_CON);
  187. else
  188. __raw_writel(epll_con, S5P_EPLL_CON);
  189. return 0;
  190. }
  191. unsigned long s5p_epll_get_rate(struct clk *clk)
  192. {
  193. return clk->rate;
  194. }
  195. int s5p_spdif_set_rate(struct clk *clk, unsigned long rate)
  196. {
  197. struct clk *pclk;
  198. int ret;
  199. pclk = clk_get_parent(clk);
  200. if (IS_ERR(pclk))
  201. return -EINVAL;
  202. ret = pclk->ops->set_rate(pclk, rate);
  203. clk_put(pclk);
  204. return ret;
  205. }
  206. unsigned long s5p_spdif_get_rate(struct clk *clk)
  207. {
  208. struct clk *pclk;
  209. int rate;
  210. pclk = clk_get_parent(clk);
  211. if (IS_ERR(pclk))
  212. return -EINVAL;
  213. rate = pclk->ops->get_rate(pclk);
  214. clk_put(pclk);
  215. return rate;
  216. }
  217. struct clk_ops s5p_sclk_spdif_ops = {
  218. .set_rate = s5p_spdif_set_rate,
  219. .get_rate = s5p_spdif_get_rate,
  220. };
  221. static struct clk *s5p_clks[] __initdata = {
  222. &clk_ext_xtal_mux,
  223. &clk_48m,
  224. &s5p_clk_27m,
  225. &clk_fout_apll,
  226. &clk_fout_mpll,
  227. &clk_fout_epll,
  228. &clk_fout_dpll,
  229. &clk_fout_vpll,
  230. &clk_vpll,
  231. &clk_xusbxti,
  232. };
  233. void __init s5p_register_clocks(unsigned long xtal_freq)
  234. {
  235. int ret;
  236. clk_ext_xtal_mux.rate = xtal_freq;
  237. ret = s3c24xx_register_clocks(s5p_clks, ARRAY_SIZE(s5p_clks));
  238. if (ret > 0)
  239. printk(KERN_ERR "Failed to register s5p clocks\n");
  240. }