s3c2410-clock.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /* linux/arch/arm/mach-s3c2410/clock.c
  2. *
  3. * Copyright (c) 2006 Simtec Electronics
  4. * Ben Dooks <ben@simtec.co.uk>
  5. *
  6. * S3C2410,S3C2440,S3C2442 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/delay.h>
  32. #include <linux/serial_core.h>
  33. #include <linux/io.h>
  34. #include <asm/mach/map.h>
  35. #include <mach/hardware.h>
  36. #include <plat/regs-serial.h>
  37. #include <mach/regs-clock.h>
  38. #include <mach/regs-gpio.h>
  39. #include <plat/s3c2410.h>
  40. #include <plat/clock.h>
  41. #include <plat/cpu.h>
  42. int s3c2410_clkcon_enable(struct clk *clk, int enable)
  43. {
  44. unsigned int clocks = clk->ctrlbit;
  45. unsigned long clkcon;
  46. clkcon = __raw_readl(S3C2410_CLKCON);
  47. if (enable)
  48. clkcon |= clocks;
  49. else
  50. clkcon &= ~clocks;
  51. /* ensure none of the special function bits set */
  52. clkcon &= ~(S3C2410_CLKCON_IDLE|S3C2410_CLKCON_POWER);
  53. __raw_writel(clkcon, S3C2410_CLKCON);
  54. return 0;
  55. }
  56. static int s3c2410_upll_enable(struct clk *clk, int enable)
  57. {
  58. unsigned long clkslow = __raw_readl(S3C2410_CLKSLOW);
  59. unsigned long orig = clkslow;
  60. if (enable)
  61. clkslow &= ~S3C2410_CLKSLOW_UCLK_OFF;
  62. else
  63. clkslow |= S3C2410_CLKSLOW_UCLK_OFF;
  64. __raw_writel(clkslow, S3C2410_CLKSLOW);
  65. /* if we started the UPLL, then allow to settle */
  66. if (enable && (orig & S3C2410_CLKSLOW_UCLK_OFF))
  67. udelay(200);
  68. return 0;
  69. }
  70. /* standard clock definitions */
  71. static struct clk init_clocks_off[] = {
  72. {
  73. .name = "nand",
  74. .parent = &clk_h,
  75. .enable = s3c2410_clkcon_enable,
  76. .ctrlbit = S3C2410_CLKCON_NAND,
  77. }, {
  78. .name = "sdi",
  79. .parent = &clk_p,
  80. .enable = s3c2410_clkcon_enable,
  81. .ctrlbit = S3C2410_CLKCON_SDI,
  82. }, {
  83. .name = "adc",
  84. .parent = &clk_p,
  85. .enable = s3c2410_clkcon_enable,
  86. .ctrlbit = S3C2410_CLKCON_ADC,
  87. }, {
  88. .name = "i2c",
  89. .parent = &clk_p,
  90. .enable = s3c2410_clkcon_enable,
  91. .ctrlbit = S3C2410_CLKCON_IIC,
  92. }, {
  93. .name = "iis",
  94. .parent = &clk_p,
  95. .enable = s3c2410_clkcon_enable,
  96. .ctrlbit = S3C2410_CLKCON_IIS,
  97. }, {
  98. .name = "spi",
  99. .parent = &clk_p,
  100. .enable = s3c2410_clkcon_enable,
  101. .ctrlbit = S3C2410_CLKCON_SPI,
  102. }
  103. };
  104. static struct clk init_clocks[] = {
  105. {
  106. .name = "lcd",
  107. .parent = &clk_h,
  108. .enable = s3c2410_clkcon_enable,
  109. .ctrlbit = S3C2410_CLKCON_LCDC,
  110. }, {
  111. .name = "gpio",
  112. .parent = &clk_p,
  113. .enable = s3c2410_clkcon_enable,
  114. .ctrlbit = S3C2410_CLKCON_GPIO,
  115. }, {
  116. .name = "usb-host",
  117. .parent = &clk_h,
  118. .enable = s3c2410_clkcon_enable,
  119. .ctrlbit = S3C2410_CLKCON_USBH,
  120. }, {
  121. .name = "usb-device",
  122. .parent = &clk_h,
  123. .enable = s3c2410_clkcon_enable,
  124. .ctrlbit = S3C2410_CLKCON_USBD,
  125. }, {
  126. .name = "timers",
  127. .parent = &clk_p,
  128. .enable = s3c2410_clkcon_enable,
  129. .ctrlbit = S3C2410_CLKCON_PWMT,
  130. }, {
  131. .name = "uart",
  132. .devname = "s3c2410-uart.0",
  133. .parent = &clk_p,
  134. .enable = s3c2410_clkcon_enable,
  135. .ctrlbit = S3C2410_CLKCON_UART0,
  136. }, {
  137. .name = "uart",
  138. .devname = "s3c2410-uart.1",
  139. .parent = &clk_p,
  140. .enable = s3c2410_clkcon_enable,
  141. .ctrlbit = S3C2410_CLKCON_UART1,
  142. }, {
  143. .name = "uart",
  144. .devname = "s3c2410-uart.2",
  145. .parent = &clk_p,
  146. .enable = s3c2410_clkcon_enable,
  147. .ctrlbit = S3C2410_CLKCON_UART2,
  148. }, {
  149. .name = "rtc",
  150. .parent = &clk_p,
  151. .enable = s3c2410_clkcon_enable,
  152. .ctrlbit = S3C2410_CLKCON_RTC,
  153. }, {
  154. .name = "watchdog",
  155. .parent = &clk_p,
  156. .ctrlbit = 0,
  157. }, {
  158. .name = "usb-bus-host",
  159. .parent = &clk_usb_bus,
  160. }, {
  161. .name = "usb-bus-gadget",
  162. .parent = &clk_usb_bus,
  163. },
  164. };
  165. /* s3c2410_baseclk_add()
  166. *
  167. * Add all the clocks used by the s3c2410 or compatible CPUs
  168. * such as the S3C2440 and S3C2442.
  169. *
  170. * We cannot use a system device as we are needed before any
  171. * of the init-calls that initialise the devices are actually
  172. * done.
  173. */
  174. int __init s3c2410_baseclk_add(void)
  175. {
  176. unsigned long clkslow = __raw_readl(S3C2410_CLKSLOW);
  177. unsigned long clkcon = __raw_readl(S3C2410_CLKCON);
  178. struct clk *clkp;
  179. struct clk *xtal;
  180. int ret;
  181. int ptr;
  182. clk_upll.enable = s3c2410_upll_enable;
  183. if (s3c24xx_register_clock(&clk_usb_bus) < 0)
  184. printk(KERN_ERR "failed to register usb bus clock\n");
  185. /* register clocks from clock array */
  186. clkp = init_clocks;
  187. for (ptr = 0; ptr < ARRAY_SIZE(init_clocks); ptr++, clkp++) {
  188. /* ensure that we note the clock state */
  189. clkp->usage = clkcon & clkp->ctrlbit ? 1 : 0;
  190. ret = s3c24xx_register_clock(clkp);
  191. if (ret < 0) {
  192. printk(KERN_ERR "Failed to register clock %s (%d)\n",
  193. clkp->name, ret);
  194. }
  195. }
  196. /* We must be careful disabling the clocks we are not intending to
  197. * be using at boot time, as subsystems such as the LCD which do
  198. * their own DMA requests to the bus can cause the system to lockup
  199. * if they where in the middle of requesting bus access.
  200. *
  201. * Disabling the LCD clock if the LCD is active is very dangerous,
  202. * and therefore the bootloader should be careful to not enable
  203. * the LCD clock if it is not needed.
  204. */
  205. /* install (and disable) the clocks we do not need immediately */
  206. s3c_register_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
  207. s3c_disable_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
  208. /* show the clock-slow value */
  209. xtal = clk_get(NULL, "xtal");
  210. printk("CLOCK: Slow mode (%ld.%ld MHz), %s, MPLL %s, UPLL %s\n",
  211. print_mhz(clk_get_rate(xtal) /
  212. ( 2 * S3C2410_CLKSLOW_GET_SLOWVAL(clkslow))),
  213. (clkslow & S3C2410_CLKSLOW_SLOW) ? "slow" : "fast",
  214. (clkslow & S3C2410_CLKSLOW_MPLL_OFF) ? "off" : "on",
  215. (clkslow & S3C2410_CLKSLOW_UCLK_OFF) ? "off" : "on");
  216. s3c_pwmclk_init();
  217. return 0;
  218. }