s3c2410-clock.c 6.4 KB

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