1 /* linux/arch/arm/mach-s3c2410/clock.c
3 * Copyright (c) 2006 Simtec Electronics
4 * Ben Dooks <ben@simtec.co.uk>
6 * S3C2410,S3C2440,S3C2442 Clock control support
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.
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.
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
23 #include <linux/init.h>
24 #include <linux/module.h>
25 #include <linux/kernel.h>
26 #include <linux/list.h>
27 #include <linux/errno.h>
28 #include <linux/err.h>
29 #include <linux/sysdev.h>
30 #include <linux/clk.h>
31 #include <linux/mutex.h>
32 #include <linux/delay.h>
34 #include <asm/hardware.h>
37 #include <asm/arch/regs-clock.h>
38 #include <asm/arch/regs-gpio.h>
43 int s3c2410_clkcon_enable(struct clk *clk, int enable)
45 unsigned int clocks = clk->ctrlbit;
48 clkcon = __raw_readl(S3C2410_CLKCON);
55 /* ensure none of the special function bits set */
56 clkcon &= ~(S3C2410_CLKCON_IDLE|S3C2410_CLKCON_POWER);
58 __raw_writel(clkcon, S3C2410_CLKCON);
63 static int s3c2410_upll_enable(struct clk *clk, int enable)
65 unsigned long clkslow = __raw_readl(S3C2410_CLKSLOW);
66 unsigned long orig = clkslow;
69 clkslow &= ~S3C2410_CLKSLOW_UCLK_OFF;
71 clkslow |= S3C2410_CLKSLOW_UCLK_OFF;
73 __raw_writel(clkslow, S3C2410_CLKSLOW);
75 /* if we started the UPLL, then allow to settle */
77 if (enable && (orig & S3C2410_CLKSLOW_UCLK_OFF))
83 /* standard clock definitions */
85 static struct clk init_clocks_disable[] = {
90 .enable = s3c2410_clkcon_enable,
91 .ctrlbit = S3C2410_CLKCON_NAND,
96 .enable = s3c2410_clkcon_enable,
97 .ctrlbit = S3C2410_CLKCON_SDI,
102 .enable = s3c2410_clkcon_enable,
103 .ctrlbit = S3C2410_CLKCON_ADC,
108 .enable = s3c2410_clkcon_enable,
109 .ctrlbit = S3C2410_CLKCON_IIC,
114 .enable = s3c2410_clkcon_enable,
115 .ctrlbit = S3C2410_CLKCON_IIS,
120 .enable = s3c2410_clkcon_enable,
121 .ctrlbit = S3C2410_CLKCON_SPI,
125 static struct clk init_clocks[] = {
130 .enable = s3c2410_clkcon_enable,
131 .ctrlbit = S3C2410_CLKCON_LCDC,
136 .enable = s3c2410_clkcon_enable,
137 .ctrlbit = S3C2410_CLKCON_GPIO,
142 .enable = s3c2410_clkcon_enable,
143 .ctrlbit = S3C2410_CLKCON_USBH,
145 .name = "usb-device",
148 .enable = s3c2410_clkcon_enable,
149 .ctrlbit = S3C2410_CLKCON_USBD,
154 .enable = s3c2410_clkcon_enable,
155 .ctrlbit = S3C2410_CLKCON_PWMT,
160 .enable = s3c2410_clkcon_enable,
161 .ctrlbit = S3C2410_CLKCON_UART0,
166 .enable = s3c2410_clkcon_enable,
167 .ctrlbit = S3C2410_CLKCON_UART1,
172 .enable = s3c2410_clkcon_enable,
173 .ctrlbit = S3C2410_CLKCON_UART2,
178 .enable = s3c2410_clkcon_enable,
179 .ctrlbit = S3C2410_CLKCON_RTC,
186 .name = "usb-bus-host",
188 .parent = &clk_usb_bus,
190 .name = "usb-bus-gadget",
192 .parent = &clk_usb_bus,
196 /* s3c2410_baseclk_add()
198 * Add all the clocks used by the s3c2410 or compatible CPUs
199 * such as the S3C2440 and S3C2442.
201 * We cannot use a system device as we are needed before any
202 * of the init-calls that initialise the devices are actually
206 int __init s3c2410_baseclk_add(void)
208 unsigned long clkslow = __raw_readl(S3C2410_CLKSLOW);
209 unsigned long clkcon = __raw_readl(S3C2410_CLKCON);
215 clk_upll.enable = s3c2410_upll_enable;
217 if (s3c24xx_register_clock(&clk_usb_bus) < 0)
218 printk(KERN_ERR "failed to register usb bus clock\n");
220 /* register clocks from clock array */
223 for (ptr = 0; ptr < ARRAY_SIZE(init_clocks); ptr++, clkp++) {
224 /* ensure that we note the clock state */
226 clkp->usage = clkcon & clkp->ctrlbit ? 1 : 0;
228 ret = s3c24xx_register_clock(clkp);
230 printk(KERN_ERR "Failed to register clock %s (%d)\n",
235 /* We must be careful disabling the clocks we are not intending to
236 * be using at boot time, as subsytems such as the LCD which do
237 * their own DMA requests to the bus can cause the system to lockup
238 * if they where in the middle of requesting bus access.
240 * Disabling the LCD clock if the LCD is active is very dangerous,
241 * and therefore the bootloader should be careful to not enable
242 * the LCD clock if it is not needed.
245 /* install (and disable) the clocks we do not need immediately */
247 clkp = init_clocks_disable;
248 for (ptr = 0; ptr < ARRAY_SIZE(init_clocks_disable); ptr++, clkp++) {
250 ret = s3c24xx_register_clock(clkp);
252 printk(KERN_ERR "Failed to register clock %s (%d)\n",
256 s3c2410_clkcon_enable(clkp, 0);
259 /* show the clock-slow value */
261 xtal = clk_get(NULL, "xtal");
263 printk("CLOCK: Slow mode (%ld.%ld MHz), %s, MPLL %s, UPLL %s\n",
264 print_mhz(clk_get_rate(xtal) /
265 ( 2 * S3C2410_CLKSLOW_GET_SLOWVAL(clkslow))),
266 (clkslow & S3C2410_CLKSLOW_SLOW) ? "slow" : "fast",
267 (clkslow & S3C2410_CLKSLOW_MPLL_OFF) ? "off" : "on",
268 (clkslow & S3C2410_CLKSLOW_UCLK_OFF) ? "off" : "on");