clock-s3c2410.c 6.2 KB

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