s5p-clock.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. };
  36. struct clk s5p_clk_27m = {
  37. .name = "clk_27m",
  38. .id = -1,
  39. .rate = 27000000,
  40. };
  41. /* 48MHz USB Phy clock output */
  42. struct clk clk_48m = {
  43. .name = "clk_48m",
  44. .id = -1,
  45. .rate = 48000000,
  46. };
  47. /* APLL clock output
  48. * No need .ctrlbit, this is always on
  49. */
  50. struct clk clk_fout_apll = {
  51. .name = "fout_apll",
  52. .id = -1,
  53. };
  54. /* BPLL clock output */
  55. struct clk clk_fout_bpll = {
  56. .name = "fout_bpll",
  57. .id = -1,
  58. };
  59. struct clk clk_fout_bpll_div2 = {
  60. .name = "fout_bpll_div2",
  61. .id = -1,
  62. };
  63. /* CPLL clock output */
  64. struct clk clk_fout_cpll = {
  65. .name = "fout_cpll",
  66. .id = -1,
  67. };
  68. /* MPLL clock output
  69. * No need .ctrlbit, this is always on
  70. */
  71. struct clk clk_fout_mpll = {
  72. .name = "fout_mpll",
  73. .id = -1,
  74. };
  75. struct clk clk_fout_mpll_div2 = {
  76. .name = "fout_mpll_div2",
  77. .id = -1,
  78. };
  79. /* EPLL clock output */
  80. struct clk clk_fout_epll = {
  81. .name = "fout_epll",
  82. .id = -1,
  83. .ctrlbit = (1 << 31),
  84. };
  85. /* DPLL clock output */
  86. struct clk clk_fout_dpll = {
  87. .name = "fout_dpll",
  88. .id = -1,
  89. .ctrlbit = (1 << 31),
  90. };
  91. /* VPLL clock output */
  92. struct clk clk_fout_vpll = {
  93. .name = "fout_vpll",
  94. .id = -1,
  95. .ctrlbit = (1 << 31),
  96. };
  97. /* Possible clock sources for APLL Mux */
  98. static struct clk *clk_src_apll_list[] = {
  99. [0] = &clk_fin_apll,
  100. [1] = &clk_fout_apll,
  101. };
  102. struct clksrc_sources clk_src_apll = {
  103. .sources = clk_src_apll_list,
  104. .nr_sources = ARRAY_SIZE(clk_src_apll_list),
  105. };
  106. /* Possible clock sources for BPLL Mux */
  107. static struct clk *clk_src_bpll_list[] = {
  108. [0] = &clk_fin_bpll,
  109. [1] = &clk_fout_bpll,
  110. };
  111. struct clksrc_sources clk_src_bpll = {
  112. .sources = clk_src_bpll_list,
  113. .nr_sources = ARRAY_SIZE(clk_src_bpll_list),
  114. };
  115. static struct clk *clk_src_bpll_fout_list[] = {
  116. [0] = &clk_fout_bpll_div2,
  117. [1] = &clk_fout_bpll,
  118. };
  119. struct clksrc_sources clk_src_bpll_fout = {
  120. .sources = clk_src_bpll_fout_list,
  121. .nr_sources = ARRAY_SIZE(clk_src_bpll_fout_list),
  122. };
  123. /* Possible clock sources for CPLL Mux */
  124. static struct clk *clk_src_cpll_list[] = {
  125. [0] = &clk_fin_cpll,
  126. [1] = &clk_fout_cpll,
  127. };
  128. struct clksrc_sources clk_src_cpll = {
  129. .sources = clk_src_cpll_list,
  130. .nr_sources = ARRAY_SIZE(clk_src_cpll_list),
  131. };
  132. /* Possible clock sources for MPLL Mux */
  133. static struct clk *clk_src_mpll_list[] = {
  134. [0] = &clk_fin_mpll,
  135. [1] = &clk_fout_mpll,
  136. };
  137. struct clksrc_sources clk_src_mpll = {
  138. .sources = clk_src_mpll_list,
  139. .nr_sources = ARRAY_SIZE(clk_src_mpll_list),
  140. };
  141. static struct clk *clk_src_mpll_fout_list[] = {
  142. [0] = &clk_fout_mpll_div2,
  143. [1] = &clk_fout_mpll,
  144. };
  145. struct clksrc_sources clk_src_mpll_fout = {
  146. .sources = clk_src_mpll_fout_list,
  147. .nr_sources = ARRAY_SIZE(clk_src_mpll_fout_list),
  148. };
  149. /* Possible clock sources for EPLL Mux */
  150. static struct clk *clk_src_epll_list[] = {
  151. [0] = &clk_fin_epll,
  152. [1] = &clk_fout_epll,
  153. };
  154. struct clksrc_sources clk_src_epll = {
  155. .sources = clk_src_epll_list,
  156. .nr_sources = ARRAY_SIZE(clk_src_epll_list),
  157. };
  158. /* Possible clock sources for DPLL Mux */
  159. static struct clk *clk_src_dpll_list[] = {
  160. [0] = &clk_fin_dpll,
  161. [1] = &clk_fout_dpll,
  162. };
  163. struct clksrc_sources clk_src_dpll = {
  164. .sources = clk_src_dpll_list,
  165. .nr_sources = ARRAY_SIZE(clk_src_dpll_list),
  166. };
  167. struct clk clk_vpll = {
  168. .name = "vpll",
  169. .id = -1,
  170. };
  171. int s5p_gatectrl(void __iomem *reg, struct clk *clk, int enable)
  172. {
  173. unsigned int ctrlbit = clk->ctrlbit;
  174. u32 con;
  175. con = __raw_readl(reg);
  176. con = enable ? (con | ctrlbit) : (con & ~ctrlbit);
  177. __raw_writel(con, reg);
  178. return 0;
  179. }
  180. int s5p_epll_enable(struct clk *clk, int enable)
  181. {
  182. unsigned int ctrlbit = clk->ctrlbit;
  183. unsigned int epll_con = __raw_readl(S5P_EPLL_CON) & ~ctrlbit;
  184. if (enable)
  185. __raw_writel(epll_con | ctrlbit, S5P_EPLL_CON);
  186. else
  187. __raw_writel(epll_con, S5P_EPLL_CON);
  188. return 0;
  189. }
  190. unsigned long s5p_epll_get_rate(struct clk *clk)
  191. {
  192. return clk->rate;
  193. }
  194. int s5p_spdif_set_rate(struct clk *clk, unsigned long rate)
  195. {
  196. struct clk *pclk;
  197. int ret;
  198. pclk = clk_get_parent(clk);
  199. if (IS_ERR(pclk))
  200. return -EINVAL;
  201. ret = pclk->ops->set_rate(pclk, rate);
  202. clk_put(pclk);
  203. return ret;
  204. }
  205. unsigned long s5p_spdif_get_rate(struct clk *clk)
  206. {
  207. struct clk *pclk;
  208. int rate;
  209. pclk = clk_get_parent(clk);
  210. if (IS_ERR(pclk))
  211. return -EINVAL;
  212. rate = pclk->ops->get_rate(pclk);
  213. clk_put(pclk);
  214. return rate;
  215. }
  216. struct clk_ops s5p_sclk_spdif_ops = {
  217. .set_rate = s5p_spdif_set_rate,
  218. .get_rate = s5p_spdif_get_rate,
  219. };
  220. static struct clk *s5p_clks[] __initdata = {
  221. &clk_ext_xtal_mux,
  222. &clk_48m,
  223. &s5p_clk_27m,
  224. &clk_fout_apll,
  225. &clk_fout_mpll,
  226. &clk_fout_epll,
  227. &clk_fout_dpll,
  228. &clk_fout_vpll,
  229. &clk_vpll,
  230. &clk_xusbxti,
  231. };
  232. void __init s5p_register_clocks(unsigned long xtal_freq)
  233. {
  234. int ret;
  235. clk_ext_xtal_mux.rate = xtal_freq;
  236. ret = s3c24xx_register_clocks(s5p_clks, ARRAY_SIZE(s5p_clks));
  237. if (ret > 0)
  238. printk(KERN_ERR "Failed to register s5p clocks\n");
  239. }