s5p-clock.c 4.9 KB

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