clock-s3c2410.c 6.2 KB

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