clock.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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 <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. /* MPLL clock output
  55. * No need .ctrlbit, this is always on
  56. */
  57. struct clk clk_fout_mpll = {
  58. .name = "fout_mpll",
  59. .id = -1,
  60. };
  61. /* EPLL clock output */
  62. struct clk clk_fout_epll = {
  63. .name = "fout_epll",
  64. .id = -1,
  65. .ctrlbit = (1 << 31),
  66. };
  67. /* DPLL clock output */
  68. struct clk clk_fout_dpll = {
  69. .name = "fout_dpll",
  70. .id = -1,
  71. .ctrlbit = (1 << 31),
  72. };
  73. /* VPLL clock output */
  74. struct clk clk_fout_vpll = {
  75. .name = "fout_vpll",
  76. .id = -1,
  77. .ctrlbit = (1 << 31),
  78. };
  79. /* ARM clock */
  80. struct clk clk_arm = {
  81. .name = "armclk",
  82. .id = -1,
  83. .rate = 0,
  84. .ctrlbit = 0,
  85. };
  86. /* Possible clock sources for APLL Mux */
  87. static struct clk *clk_src_apll_list[] = {
  88. [0] = &clk_fin_apll,
  89. [1] = &clk_fout_apll,
  90. };
  91. struct clksrc_sources clk_src_apll = {
  92. .sources = clk_src_apll_list,
  93. .nr_sources = ARRAY_SIZE(clk_src_apll_list),
  94. };
  95. /* Possible clock sources for MPLL Mux */
  96. static struct clk *clk_src_mpll_list[] = {
  97. [0] = &clk_fin_mpll,
  98. [1] = &clk_fout_mpll,
  99. };
  100. struct clksrc_sources clk_src_mpll = {
  101. .sources = clk_src_mpll_list,
  102. .nr_sources = ARRAY_SIZE(clk_src_mpll_list),
  103. };
  104. /* Possible clock sources for EPLL Mux */
  105. static struct clk *clk_src_epll_list[] = {
  106. [0] = &clk_fin_epll,
  107. [1] = &clk_fout_epll,
  108. };
  109. struct clksrc_sources clk_src_epll = {
  110. .sources = clk_src_epll_list,
  111. .nr_sources = ARRAY_SIZE(clk_src_epll_list),
  112. };
  113. /* Possible clock sources for DPLL Mux */
  114. static struct clk *clk_src_dpll_list[] = {
  115. [0] = &clk_fin_dpll,
  116. [1] = &clk_fout_dpll,
  117. };
  118. struct clksrc_sources clk_src_dpll = {
  119. .sources = clk_src_dpll_list,
  120. .nr_sources = ARRAY_SIZE(clk_src_dpll_list),
  121. };
  122. struct clk clk_vpll = {
  123. .name = "vpll",
  124. .id = -1,
  125. };
  126. int s5p_gatectrl(void __iomem *reg, struct clk *clk, int enable)
  127. {
  128. unsigned int ctrlbit = clk->ctrlbit;
  129. u32 con;
  130. con = __raw_readl(reg);
  131. con = enable ? (con | ctrlbit) : (con & ~ctrlbit);
  132. __raw_writel(con, reg);
  133. return 0;
  134. }
  135. static struct clk *s5p_clks[] __initdata = {
  136. &clk_ext_xtal_mux,
  137. &clk_48m,
  138. &s5p_clk_27m,
  139. &clk_fout_apll,
  140. &clk_fout_mpll,
  141. &clk_fout_epll,
  142. &clk_fout_dpll,
  143. &clk_fout_vpll,
  144. &clk_arm,
  145. &clk_vpll,
  146. &clk_xusbxti,
  147. };
  148. void __init s5p_register_clocks(unsigned long xtal_freq)
  149. {
  150. int ret;
  151. clk_ext_xtal_mux.rate = xtal_freq;
  152. ret = s3c24xx_register_clocks(s5p_clks, ARRAY_SIZE(s5p_clks));
  153. if (ret > 0)
  154. printk(KERN_ERR "Failed to register s5p clocks\n");
  155. }