clock.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /* linux/arch/arm/plat-s5p/clock.c
  2. *
  3. * Copyright 2009 Samsung Electronics Co., Ltd.
  4. * http://www.samsung.com/
  5. *
  6. * S5P - Common clock support
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/init.h>
  13. #include <linux/module.h>
  14. #include <linux/kernel.h>
  15. #include <linux/list.h>
  16. #include <linux/errno.h>
  17. #include <linux/err.h>
  18. #include <linux/clk.h>
  19. #include <linux/sysdev.h>
  20. #include <linux/io.h>
  21. #include <asm/div64.h>
  22. #include <mach/regs-clock.h>
  23. #include <plat/clock.h>
  24. #include <plat/clock-clksrc.h>
  25. #include <plat/s5p-clock.h>
  26. /* fin_apll, fin_mpll and fin_epll are all the same clock, which we call
  27. * clk_ext_xtal_mux.
  28. */
  29. struct clk clk_ext_xtal_mux = {
  30. .name = "ext_xtal",
  31. .id = -1,
  32. };
  33. struct clk clk_xusbxti = {
  34. .name = "xusbxti",
  35. .id = -1,
  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. /* MPLL clock output
  56. * No need .ctrlbit, this is always on
  57. */
  58. struct clk clk_fout_mpll = {
  59. .name = "fout_mpll",
  60. .id = -1,
  61. };
  62. /* EPLL clock output */
  63. struct clk clk_fout_epll = {
  64. .name = "fout_epll",
  65. .id = -1,
  66. .ctrlbit = (1 << 31),
  67. };
  68. /* DPLL clock output */
  69. struct clk clk_fout_dpll = {
  70. .name = "fout_dpll",
  71. .id = -1,
  72. .ctrlbit = (1 << 31),
  73. };
  74. /* VPLL clock output */
  75. struct clk clk_fout_vpll = {
  76. .name = "fout_vpll",
  77. .id = -1,
  78. .ctrlbit = (1 << 31),
  79. };
  80. /* Possible clock sources for APLL Mux */
  81. static struct clk *clk_src_apll_list[] = {
  82. [0] = &clk_fin_apll,
  83. [1] = &clk_fout_apll,
  84. };
  85. struct clksrc_sources clk_src_apll = {
  86. .sources = clk_src_apll_list,
  87. .nr_sources = ARRAY_SIZE(clk_src_apll_list),
  88. };
  89. /* Possible clock sources for MPLL Mux */
  90. static struct clk *clk_src_mpll_list[] = {
  91. [0] = &clk_fin_mpll,
  92. [1] = &clk_fout_mpll,
  93. };
  94. struct clksrc_sources clk_src_mpll = {
  95. .sources = clk_src_mpll_list,
  96. .nr_sources = ARRAY_SIZE(clk_src_mpll_list),
  97. };
  98. /* Possible clock sources for EPLL Mux */
  99. static struct clk *clk_src_epll_list[] = {
  100. [0] = &clk_fin_epll,
  101. [1] = &clk_fout_epll,
  102. };
  103. struct clksrc_sources clk_src_epll = {
  104. .sources = clk_src_epll_list,
  105. .nr_sources = ARRAY_SIZE(clk_src_epll_list),
  106. };
  107. /* Possible clock sources for DPLL Mux */
  108. static struct clk *clk_src_dpll_list[] = {
  109. [0] = &clk_fin_dpll,
  110. [1] = &clk_fout_dpll,
  111. };
  112. struct clksrc_sources clk_src_dpll = {
  113. .sources = clk_src_dpll_list,
  114. .nr_sources = ARRAY_SIZE(clk_src_dpll_list),
  115. };
  116. struct clk clk_vpll = {
  117. .name = "vpll",
  118. .id = -1,
  119. };
  120. int s5p_gatectrl(void __iomem *reg, struct clk *clk, int enable)
  121. {
  122. unsigned int ctrlbit = clk->ctrlbit;
  123. u32 con;
  124. con = __raw_readl(reg);
  125. con = enable ? (con | ctrlbit) : (con & ~ctrlbit);
  126. __raw_writel(con, reg);
  127. return 0;
  128. }
  129. int s5p_epll_enable(struct clk *clk, int enable)
  130. {
  131. unsigned int ctrlbit = clk->ctrlbit;
  132. unsigned int epll_con = __raw_readl(S5P_EPLL_CON) & ~ctrlbit;
  133. if (enable)
  134. __raw_writel(epll_con | ctrlbit, S5P_EPLL_CON);
  135. else
  136. __raw_writel(epll_con, S5P_EPLL_CON);
  137. return 0;
  138. }
  139. unsigned long s5p_epll_get_rate(struct clk *clk)
  140. {
  141. return clk->rate;
  142. }
  143. static struct clk *s5p_clks[] __initdata = {
  144. &clk_ext_xtal_mux,
  145. &clk_48m,
  146. &s5p_clk_27m,
  147. &clk_fout_apll,
  148. &clk_fout_mpll,
  149. &clk_fout_epll,
  150. &clk_fout_dpll,
  151. &clk_fout_vpll,
  152. &clk_vpll,
  153. &clk_xusbxti,
  154. };
  155. void __init s5p_register_clocks(unsigned long xtal_freq)
  156. {
  157. int ret;
  158. clk_ext_xtal_mux.rate = xtal_freq;
  159. ret = s3c24xx_register_clocks(s5p_clks, ARRAY_SIZE(s5p_clks));
  160. if (ret > 0)
  161. printk(KERN_ERR "Failed to register s5p clocks\n");
  162. }