1 /* linux/arch/arm/mach-s3c2410/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/mach/map.h>
36 #include <asm/hardware.h>
39 #include <asm/arch/regs-serial.h>
40 #include <asm/arch/regs-clock.h>
41 #include <asm/arch/regs-gpio.h>
47 int s3c2410_clkcon_enable(struct clk
*clk
, int enable
)
49 unsigned int clocks
= clk
->ctrlbit
;
52 clkcon
= __raw_readl(S3C2410_CLKCON
);
59 /* ensure none of the special function bits set */
60 clkcon
&= ~(S3C2410_CLKCON_IDLE
|S3C2410_CLKCON_POWER
);
62 __raw_writel(clkcon
, S3C2410_CLKCON
);
67 static int s3c2410_upll_enable(struct clk
*clk
, int enable
)
69 unsigned long clkslow
= __raw_readl(S3C2410_CLKSLOW
);
70 unsigned long orig
= clkslow
;
73 clkslow
&= ~S3C2410_CLKSLOW_UCLK_OFF
;
75 clkslow
|= S3C2410_CLKSLOW_UCLK_OFF
;
77 __raw_writel(clkslow
, S3C2410_CLKSLOW
);
79 /* if we started the UPLL, then allow to settle */
81 if (enable
&& (orig
& S3C2410_CLKSLOW_UCLK_OFF
))
87 /* standard clock definitions */
89 static struct clk init_clocks_disable
[] = {
94 .enable
= s3c2410_clkcon_enable
,
95 .ctrlbit
= S3C2410_CLKCON_NAND
,
100 .enable
= s3c2410_clkcon_enable
,
101 .ctrlbit
= S3C2410_CLKCON_SDI
,
106 .enable
= s3c2410_clkcon_enable
,
107 .ctrlbit
= S3C2410_CLKCON_ADC
,
112 .enable
= s3c2410_clkcon_enable
,
113 .ctrlbit
= S3C2410_CLKCON_IIC
,
118 .enable
= s3c2410_clkcon_enable
,
119 .ctrlbit
= S3C2410_CLKCON_IIS
,
124 .enable
= s3c2410_clkcon_enable
,
125 .ctrlbit
= S3C2410_CLKCON_SPI
,
129 static struct clk init_clocks
[] = {
134 .enable
= s3c2410_clkcon_enable
,
135 .ctrlbit
= S3C2410_CLKCON_LCDC
,
140 .enable
= s3c2410_clkcon_enable
,
141 .ctrlbit
= S3C2410_CLKCON_GPIO
,
146 .enable
= s3c2410_clkcon_enable
,
147 .ctrlbit
= S3C2410_CLKCON_USBH
,
149 .name
= "usb-device",
152 .enable
= s3c2410_clkcon_enable
,
153 .ctrlbit
= S3C2410_CLKCON_USBD
,
158 .enable
= s3c2410_clkcon_enable
,
159 .ctrlbit
= S3C2410_CLKCON_PWMT
,
164 .enable
= s3c2410_clkcon_enable
,
165 .ctrlbit
= S3C2410_CLKCON_UART0
,
170 .enable
= s3c2410_clkcon_enable
,
171 .ctrlbit
= S3C2410_CLKCON_UART1
,
176 .enable
= s3c2410_clkcon_enable
,
177 .ctrlbit
= S3C2410_CLKCON_UART2
,
182 .enable
= s3c2410_clkcon_enable
,
183 .ctrlbit
= S3C2410_CLKCON_RTC
,
190 .name
= "usb-bus-host",
192 .parent
= &clk_usb_bus
,
194 .name
= "usb-bus-gadget",
196 .parent
= &clk_usb_bus
,
200 /* s3c2410_baseclk_add()
202 * Add all the clocks used by the s3c2410 or compatible CPUs
203 * such as the S3C2440 and S3C2442.
205 * We cannot use a system device as we are needed before any
206 * of the init-calls that initialise the devices are actually
210 int __init
s3c2410_baseclk_add(void)
212 unsigned long clkslow
= __raw_readl(S3C2410_CLKSLOW
);
213 unsigned long clkcon
= __raw_readl(S3C2410_CLKCON
);
219 clk_upll
.enable
= s3c2410_upll_enable
;
221 if (s3c24xx_register_clock(&clk_usb_bus
) < 0)
222 printk(KERN_ERR
"failed to register usb bus clock\n");
224 /* register clocks from clock array */
227 for (ptr
= 0; ptr
< ARRAY_SIZE(init_clocks
); ptr
++, clkp
++) {
228 /* ensure that we note the clock state */
230 clkp
->usage
= clkcon
& clkp
->ctrlbit
? 1 : 0;
232 ret
= s3c24xx_register_clock(clkp
);
234 printk(KERN_ERR
"Failed to register clock %s (%d)\n",
239 /* We must be careful disabling the clocks we are not intending to
240 * be using at boot time, as subsytems such as the LCD which do
241 * their own DMA requests to the bus can cause the system to lockup
242 * if they where in the middle of requesting bus access.
244 * Disabling the LCD clock if the LCD is active is very dangerous,
245 * and therefore the bootloader should be careful to not enable
246 * the LCD clock if it is not needed.
249 /* install (and disable) the clocks we do not need immediately */
251 clkp
= init_clocks_disable
;
252 for (ptr
= 0; ptr
< ARRAY_SIZE(init_clocks_disable
); ptr
++, clkp
++) {
254 ret
= s3c24xx_register_clock(clkp
);
256 printk(KERN_ERR
"Failed to register clock %s (%d)\n",
260 s3c2410_clkcon_enable(clkp
, 0);
263 /* show the clock-slow value */
265 xtal
= clk_get(NULL
, "xtal");
267 printk("CLOCK: Slow mode (%ld.%ld MHz), %s, MPLL %s, UPLL %s\n",
268 print_mhz(clk_get_rate(xtal
) /
269 ( 2 * S3C2410_CLKSLOW_GET_SLOWVAL(clkslow
))),
270 (clkslow
& S3C2410_CLKSLOW_SLOW
) ? "slow" : "fast",
271 (clkslow
& S3C2410_CLKSLOW_MPLL_OFF
) ? "off" : "on",
272 (clkslow
& S3C2410_CLKSLOW_UCLK_OFF
) ? "off" : "on");