clock-s3c2443.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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/clock.h>
  38. #include <plat/clock-clksrc.h>
  39. #include <plat/cpu.h>
  40. /* We currently have to assume that the system is running
  41. * from the XTPll input, and that all ***REFCLKs are being
  42. * fed from it, as we cannot read the state of OM[4] from
  43. * software.
  44. *
  45. * It would be possible for each board initialisation to
  46. * set the correct muxing at initialisation
  47. */
  48. /* clock selections */
  49. /* armdiv
  50. *
  51. * this clock is sourced from msysclk and can have a number of
  52. * divider values applied to it to then be fed into armclk.
  53. * The real clock definition is done in s3c2443-clock.c,
  54. * only the armdiv divisor table must be defined here.
  55. */
  56. static unsigned int armdiv[16] = {
  57. [S3C2443_CLKDIV0_ARMDIV_1 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 1,
  58. [S3C2443_CLKDIV0_ARMDIV_2 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 2,
  59. [S3C2443_CLKDIV0_ARMDIV_3 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 3,
  60. [S3C2443_CLKDIV0_ARMDIV_4 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 4,
  61. [S3C2443_CLKDIV0_ARMDIV_6 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 6,
  62. [S3C2443_CLKDIV0_ARMDIV_8 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 8,
  63. [S3C2443_CLKDIV0_ARMDIV_12 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 12,
  64. [S3C2443_CLKDIV0_ARMDIV_16 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 16,
  65. };
  66. /* hsspi
  67. *
  68. * high-speed spi clock, sourced from esysclk
  69. */
  70. static struct clksrc_clk clk_hsspi = {
  71. .clk = {
  72. .name = "hsspi-if",
  73. .parent = &clk_esysclk.clk,
  74. .ctrlbit = S3C2443_SCLKCON_HSSPICLK,
  75. .enable = s3c2443_clkcon_enable_s,
  76. },
  77. .reg_div = { .reg = S3C2443_CLKDIV1, .size = 2, .shift = 4 },
  78. };
  79. /* clk_hsmcc_div
  80. *
  81. * this clock is sourced from epll, and is fed through a divider,
  82. * to a mux controlled by sclkcon where either it or a extclk can
  83. * be fed to the hsmmc block
  84. */
  85. static struct clksrc_clk clk_hsmmc_div = {
  86. .clk = {
  87. .name = "hsmmc-div",
  88. .devname = "s3c-sdhci.1",
  89. .parent = &clk_esysclk.clk,
  90. },
  91. .reg_div = { .reg = S3C2443_CLKDIV1, .size = 2, .shift = 6 },
  92. };
  93. static int s3c2443_setparent_hsmmc(struct clk *clk, struct clk *parent)
  94. {
  95. unsigned long clksrc = __raw_readl(S3C2443_SCLKCON);
  96. clksrc &= ~(S3C2443_SCLKCON_HSMMCCLK_EXT |
  97. S3C2443_SCLKCON_HSMMCCLK_EPLL);
  98. if (parent == &clk_epll)
  99. clksrc |= S3C2443_SCLKCON_HSMMCCLK_EPLL;
  100. else if (parent == &clk_ext)
  101. clksrc |= S3C2443_SCLKCON_HSMMCCLK_EXT;
  102. else
  103. return -EINVAL;
  104. if (clk->usage > 0) {
  105. __raw_writel(clksrc, S3C2443_SCLKCON);
  106. }
  107. clk->parent = parent;
  108. return 0;
  109. }
  110. static int s3c2443_enable_hsmmc(struct clk *clk, int enable)
  111. {
  112. return s3c2443_setparent_hsmmc(clk, clk->parent);
  113. }
  114. static struct clk clk_hsmmc = {
  115. .name = "hsmmc-if",
  116. .devname = "s3c-sdhci.1",
  117. .parent = &clk_hsmmc_div.clk,
  118. .enable = s3c2443_enable_hsmmc,
  119. .ops = &(struct clk_ops) {
  120. .set_parent = s3c2443_setparent_hsmmc,
  121. },
  122. };
  123. /* standard clock definitions */
  124. static struct clk init_clocks_off[] = {
  125. {
  126. .name = "sdi",
  127. .parent = &clk_p,
  128. .enable = s3c2443_clkcon_enable_p,
  129. .ctrlbit = S3C2443_PCLKCON_SDI,
  130. }, {
  131. .name = "spi",
  132. .devname = "s3c2410-spi.0",
  133. .parent = &clk_p,
  134. .enable = s3c2443_clkcon_enable_p,
  135. .ctrlbit = S3C2443_PCLKCON_SPI1,
  136. }
  137. };
  138. /* clocks to add straight away */
  139. static struct clksrc_clk *clksrcs[] __initdata = {
  140. &clk_hsspi,
  141. &clk_hsmmc_div,
  142. };
  143. static struct clk *clks[] __initdata = {
  144. &clk_hsmmc,
  145. };
  146. static struct clk_lookup s3c2443_clk_lookup[] = {
  147. CLKDEV_INIT("s3c-sdhci.1", "mmc_busclk.2", &clk_hsmmc),
  148. CLKDEV_INIT("s3c2443-spi.0", "spi_busclk2", &clk_hsspi.clk),
  149. };
  150. void __init s3c2443_init_clocks(int xtal)
  151. {
  152. unsigned long epllcon = __raw_readl(S3C2443_EPLLCON);
  153. int ptr;
  154. clk_epll.rate = s3c2443_get_epll(epllcon, xtal);
  155. clk_epll.parent = &clk_epllref.clk;
  156. s3c2443_common_init_clocks(xtal, s3c2443_get_mpll,
  157. armdiv, ARRAY_SIZE(armdiv),
  158. S3C2443_CLKDIV0_ARMDIV_MASK);
  159. s3c24xx_register_clocks(clks, ARRAY_SIZE(clks));
  160. for (ptr = 0; ptr < ARRAY_SIZE(clksrcs); ptr++)
  161. s3c_register_clksrc(clksrcs[ptr], 1);
  162. /* We must be careful disabling the clocks we are not intending to
  163. * be using at boot time, as subsystems such as the LCD which do
  164. * their own DMA requests to the bus can cause the system to lockup
  165. * if they where in the middle of requesting bus access.
  166. *
  167. * Disabling the LCD clock if the LCD is active is very dangerous,
  168. * and therefore the bootloader should be careful to not enable
  169. * the LCD clock if it is not needed.
  170. */
  171. /* install (and disable) the clocks we do not need immediately */
  172. s3c_register_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
  173. s3c_disable_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
  174. clkdev_add_table(s3c2443_clk_lookup, ARRAY_SIZE(s3c2443_clk_lookup));
  175. s3c_pwmclk_init();
  176. }