clock-s3c2443.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /* linux/arch/arm/mach-s3c2443/clock.c
  2. *
  3. * Copyright (c) 2007, 2010 Simtec Electronics
  4. * Ben Dooks <ben@simtec.co.uk>
  5. *
  6. * S3C2443 Clock control 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 as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <linux/init.h>
  23. #include <linux/module.h>
  24. #include <linux/kernel.h>
  25. #include <linux/list.h>
  26. #include <linux/errno.h>
  27. #include <linux/err.h>
  28. #include <linux/device.h>
  29. #include <linux/clk.h>
  30. #include <linux/mutex.h>
  31. #include <linux/serial_core.h>
  32. #include <linux/io.h>
  33. #include <asm/mach/map.h>
  34. #include <mach/hardware.h>
  35. #include <mach/regs-s3c2443-clock.h>
  36. #include <plat/cpu-freq.h>
  37. #include <plat/s3c2443.h>
  38. #include <plat/clock.h>
  39. #include <plat/clock-clksrc.h>
  40. #include <plat/cpu.h>
  41. /* We currently have to assume that the system is running
  42. * from the XTPll input, and that all ***REFCLKs are being
  43. * fed from it, as we cannot read the state of OM[4] from
  44. * software.
  45. *
  46. * It would be possible for each board initialisation to
  47. * set the correct muxing at initialisation
  48. */
  49. /* clock selections */
  50. /* armdiv
  51. *
  52. * this clock is sourced from msysclk and can have a number of
  53. * divider values applied to it to then be fed into armclk.
  54. * The real clock definition is done in s3c2443-clock.c,
  55. * only the armdiv divisor table must be defined here.
  56. */
  57. static unsigned int armdiv[16] = {
  58. [S3C2443_CLKDIV0_ARMDIV_1 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 1,
  59. [S3C2443_CLKDIV0_ARMDIV_2 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 2,
  60. [S3C2443_CLKDIV0_ARMDIV_3 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 3,
  61. [S3C2443_CLKDIV0_ARMDIV_4 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 4,
  62. [S3C2443_CLKDIV0_ARMDIV_6 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 6,
  63. [S3C2443_CLKDIV0_ARMDIV_8 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 8,
  64. [S3C2443_CLKDIV0_ARMDIV_12 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 12,
  65. [S3C2443_CLKDIV0_ARMDIV_16 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 16,
  66. };
  67. /* hsspi
  68. *
  69. * high-speed spi clock, sourced from esysclk
  70. */
  71. static struct clksrc_clk clk_hsspi = {
  72. .clk = {
  73. .name = "hsspi-if",
  74. .parent = &clk_esysclk.clk,
  75. .ctrlbit = S3C2443_SCLKCON_HSSPICLK,
  76. .enable = s3c2443_clkcon_enable_s,
  77. },
  78. .reg_div = { .reg = S3C2443_CLKDIV1, .size = 2, .shift = 4 },
  79. };
  80. /* clk_hsmcc_div
  81. *
  82. * this clock is sourced from epll, and is fed through a divider,
  83. * to a mux controlled by sclkcon where either it or a extclk can
  84. * be fed to the hsmmc block
  85. */
  86. static struct clksrc_clk clk_hsmmc_div = {
  87. .clk = {
  88. .name = "hsmmc-div",
  89. .devname = "s3c-sdhci.1",
  90. .parent = &clk_esysclk.clk,
  91. },
  92. .reg_div = { .reg = S3C2443_CLKDIV1, .size = 2, .shift = 6 },
  93. };
  94. static int s3c2443_setparent_hsmmc(struct clk *clk, struct clk *parent)
  95. {
  96. unsigned long clksrc = __raw_readl(S3C2443_SCLKCON);
  97. clksrc &= ~(S3C2443_SCLKCON_HSMMCCLK_EXT |
  98. S3C2443_SCLKCON_HSMMCCLK_EPLL);
  99. if (parent == &clk_epll)
  100. clksrc |= S3C2443_SCLKCON_HSMMCCLK_EPLL;
  101. else if (parent == &clk_ext)
  102. clksrc |= S3C2443_SCLKCON_HSMMCCLK_EXT;
  103. else
  104. return -EINVAL;
  105. if (clk->usage > 0) {
  106. __raw_writel(clksrc, S3C2443_SCLKCON);
  107. }
  108. clk->parent = parent;
  109. return 0;
  110. }
  111. static int s3c2443_enable_hsmmc(struct clk *clk, int enable)
  112. {
  113. return s3c2443_setparent_hsmmc(clk, clk->parent);
  114. }
  115. static struct clk clk_hsmmc = {
  116. .name = "hsmmc-if",
  117. .devname = "s3c-sdhci.1",
  118. .parent = &clk_hsmmc_div.clk,
  119. .enable = s3c2443_enable_hsmmc,
  120. .ops = &(struct clk_ops) {
  121. .set_parent = s3c2443_setparent_hsmmc,
  122. },
  123. };
  124. /* standard clock definitions */
  125. static struct clk init_clocks_off[] = {
  126. {
  127. .name = "sdi",
  128. .parent = &clk_p,
  129. .enable = s3c2443_clkcon_enable_p,
  130. .ctrlbit = S3C2443_PCLKCON_SDI,
  131. }, {
  132. .name = "spi",
  133. .devname = "s3c2410-spi.0",
  134. .parent = &clk_p,
  135. .enable = s3c2443_clkcon_enable_p,
  136. .ctrlbit = S3C2443_PCLKCON_SPI0,
  137. }, {
  138. .name = "spi",
  139. .devname = "s3c2410-spi.1",
  140. .parent = &clk_p,
  141. .enable = s3c2443_clkcon_enable_p,
  142. .ctrlbit = S3C2443_PCLKCON_SPI1,
  143. }
  144. };
  145. /* clocks to add straight away */
  146. static struct clksrc_clk *clksrcs[] __initdata = {
  147. &clk_hsspi,
  148. &clk_hsmmc_div,
  149. };
  150. static struct clk *clks[] __initdata = {
  151. &clk_hsmmc,
  152. };
  153. void __init s3c2443_init_clocks(int xtal)
  154. {
  155. unsigned long epllcon = __raw_readl(S3C2443_EPLLCON);
  156. int ptr;
  157. clk_epll.rate = s3c2443_get_epll(epllcon, xtal);
  158. clk_epll.parent = &clk_epllref.clk;
  159. s3c2443_common_init_clocks(xtal, s3c2443_get_mpll,
  160. armdiv, ARRAY_SIZE(armdiv),
  161. S3C2443_CLKDIV0_ARMDIV_MASK);
  162. s3c24xx_register_clocks(clks, ARRAY_SIZE(clks));
  163. for (ptr = 0; ptr < ARRAY_SIZE(clksrcs); ptr++)
  164. s3c_register_clksrc(clksrcs[ptr], 1);
  165. /* We must be careful disabling the clocks we are not intending to
  166. * be using at boot time, as subsystems such as the LCD which do
  167. * their own DMA requests to the bus can cause the system to lockup
  168. * if they where in the middle of requesting bus access.
  169. *
  170. * Disabling the LCD clock if the LCD is active is very dangerous,
  171. * and therefore the bootloader should be careful to not enable
  172. * the LCD clock if it is not needed.
  173. */
  174. /* install (and disable) the clocks we do not need immediately */
  175. s3c_register_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
  176. s3c_disable_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
  177. s3c_pwmclk_init();
  178. }