| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* linux/arch/arm/mach-s3c2410/clock.c | 
 | 2 |  * | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 3 |  * Copyright (c) 2006 Simtec Electronics | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 |  *	Ben Dooks <ben@simtec.co.uk> | 
 | 5 |  * | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 6 |  * S3C2410,S3C2440,S3C2442 Clock control support | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
 | 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> | 
| Kay Sievers | edbaa60 | 2011-12-21 16:26:03 -0800 | [diff] [blame] | 29 | #include <linux/device.h> | 
| Russell King | f8ce254 | 2006-01-07 16:15:52 +0000 | [diff] [blame] | 30 | #include <linux/clk.h> | 
| Arjan van de Ven | 0043170 | 2006-01-12 18:42:23 +0000 | [diff] [blame] | 31 | #include <linux/mutex.h> | 
| Ben Dooks | 8e40a2f | 2006-03-20 17:10:04 +0000 | [diff] [blame] | 32 | #include <linux/delay.h> | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 33 | #include <linux/serial_core.h> | 
| Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 34 | #include <linux/io.h> | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 35 |  | 
 | 36 | #include <asm/mach/map.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 |  | 
| Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 38 | #include <mach/hardware.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 |  | 
| Ben Dooks | a2b7ba9 | 2008-10-07 22:26:09 +0100 | [diff] [blame] | 40 | #include <plat/regs-serial.h> | 
| Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 41 | #include <mach/regs-clock.h> | 
 | 42 | #include <mach/regs-gpio.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 |  | 
| Ben Dooks | a2b7ba9 | 2008-10-07 22:26:09 +0100 | [diff] [blame] | 44 | #include <plat/s3c2410.h> | 
| Ben Dooks | d5120ae | 2008-10-07 23:09:51 +0100 | [diff] [blame] | 45 | #include <plat/clock.h> | 
| Ben Dooks | a2b7ba9 | 2008-10-07 22:26:09 +0100 | [diff] [blame] | 46 | #include <plat/cpu.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 |  | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 48 | int s3c2410_clkcon_enable(struct clk *clk, int enable) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | { | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 50 | 	unsigned int clocks = clk->ctrlbit; | 
 | 51 | 	unsigned long clkcon; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 |  | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 53 | 	clkcon = __raw_readl(S3C2410_CLKCON); | 
| Ben Dooks | 3fc3e1c | 2006-03-20 17:10:07 +0000 | [diff] [blame] | 54 |  | 
 | 55 | 	if (enable) | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 56 | 		clkcon |= clocks; | 
| Ben Dooks | 3fc3e1c | 2006-03-20 17:10:07 +0000 | [diff] [blame] | 57 | 	else | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 58 | 		clkcon &= ~clocks; | 
| Ben Dooks | 3fc3e1c | 2006-03-20 17:10:07 +0000 | [diff] [blame] | 59 |  | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 60 | 	/* ensure none of the special function bits set */ | 
 | 61 | 	clkcon &= ~(S3C2410_CLKCON_IDLE|S3C2410_CLKCON_POWER); | 
 | 62 |  | 
 | 63 | 	__raw_writel(clkcon, S3C2410_CLKCON); | 
| Ben Dooks | 3fc3e1c | 2006-03-20 17:10:07 +0000 | [diff] [blame] | 64 |  | 
 | 65 | 	return 0; | 
 | 66 | } | 
 | 67 |  | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 68 | static int s3c2410_upll_enable(struct clk *clk, int enable) | 
| Ben Dooks | 3fc3e1c | 2006-03-20 17:10:07 +0000 | [diff] [blame] | 69 | { | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 70 | 	unsigned long clkslow = __raw_readl(S3C2410_CLKSLOW); | 
 | 71 | 	unsigned long orig = clkslow; | 
| Ben Dooks | 3fc3e1c | 2006-03-20 17:10:07 +0000 | [diff] [blame] | 72 |  | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 73 | 	if (enable) | 
 | 74 | 		clkslow &= ~S3C2410_CLKSLOW_UCLK_OFF; | 
| Ben Dooks | 3fc3e1c | 2006-03-20 17:10:07 +0000 | [diff] [blame] | 75 | 	else | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 76 | 		clkslow |= S3C2410_CLKSLOW_UCLK_OFF; | 
| Ben Dooks | 3fc3e1c | 2006-03-20 17:10:07 +0000 | [diff] [blame] | 77 |  | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 78 | 	__raw_writel(clkslow, S3C2410_CLKSLOW); | 
| Ben Dooks | 3fc3e1c | 2006-03-20 17:10:07 +0000 | [diff] [blame] | 79 |  | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 80 | 	/* if we started the UPLL, then allow to settle */ | 
| Ben Dooks | 3fc3e1c | 2006-03-20 17:10:07 +0000 | [diff] [blame] | 81 |  | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 82 | 	if (enable && (orig & S3C2410_CLKSLOW_UCLK_OFF)) | 
 | 83 | 		udelay(200); | 
 | 84 |  | 
 | 85 | 	return 0; | 
 | 86 | } | 
 | 87 |  | 
 | 88 | /* standard clock definitions */ | 
 | 89 |  | 
| Ben Dooks | 4e04691 | 2010-04-28 12:58:13 +0900 | [diff] [blame] | 90 | static struct clk init_clocks_off[] = { | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 91 | 	{ | 
 | 92 | 		.name		= "nand", | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 93 | 		.parent		= &clk_h, | 
 | 94 | 		.enable		= s3c2410_clkcon_enable, | 
 | 95 | 		.ctrlbit	= S3C2410_CLKCON_NAND, | 
 | 96 | 	}, { | 
 | 97 | 		.name		= "sdi", | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 98 | 		.parent		= &clk_p, | 
 | 99 | 		.enable		= s3c2410_clkcon_enable, | 
 | 100 | 		.ctrlbit	= S3C2410_CLKCON_SDI, | 
 | 101 | 	}, { | 
 | 102 | 		.name		= "adc", | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 103 | 		.parent		= &clk_p, | 
 | 104 | 		.enable		= s3c2410_clkcon_enable, | 
 | 105 | 		.ctrlbit	= S3C2410_CLKCON_ADC, | 
 | 106 | 	}, { | 
 | 107 | 		.name		= "i2c", | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 108 | 		.parent		= &clk_p, | 
 | 109 | 		.enable		= s3c2410_clkcon_enable, | 
 | 110 | 		.ctrlbit	= S3C2410_CLKCON_IIC, | 
 | 111 | 	}, { | 
 | 112 | 		.name		= "iis", | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 113 | 		.parent		= &clk_p, | 
 | 114 | 		.enable		= s3c2410_clkcon_enable, | 
 | 115 | 		.ctrlbit	= S3C2410_CLKCON_IIS, | 
 | 116 | 	}, { | 
 | 117 | 		.name		= "spi", | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 118 | 		.parent		= &clk_p, | 
 | 119 | 		.enable		= s3c2410_clkcon_enable, | 
 | 120 | 		.ctrlbit	= S3C2410_CLKCON_SPI, | 
 | 121 | 	} | 
 | 122 | }; | 
 | 123 |  | 
 | 124 | static struct clk init_clocks[] = { | 
 | 125 | 	{ | 
 | 126 | 		.name		= "lcd", | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 127 | 		.parent		= &clk_h, | 
 | 128 | 		.enable		= s3c2410_clkcon_enable, | 
 | 129 | 		.ctrlbit	= S3C2410_CLKCON_LCDC, | 
 | 130 | 	}, { | 
 | 131 | 		.name		= "gpio", | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 132 | 		.parent		= &clk_p, | 
 | 133 | 		.enable		= s3c2410_clkcon_enable, | 
 | 134 | 		.ctrlbit	= S3C2410_CLKCON_GPIO, | 
 | 135 | 	}, { | 
 | 136 | 		.name		= "usb-host", | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 137 | 		.parent		= &clk_h, | 
 | 138 | 		.enable		= s3c2410_clkcon_enable, | 
 | 139 | 		.ctrlbit	= S3C2410_CLKCON_USBH, | 
 | 140 | 	}, { | 
 | 141 | 		.name		= "usb-device", | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 142 | 		.parent		= &clk_h, | 
 | 143 | 		.enable		= s3c2410_clkcon_enable, | 
 | 144 | 		.ctrlbit	= S3C2410_CLKCON_USBD, | 
 | 145 | 	}, { | 
 | 146 | 		.name		= "timers", | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 147 | 		.parent		= &clk_p, | 
 | 148 | 		.enable		= s3c2410_clkcon_enable, | 
 | 149 | 		.ctrlbit	= S3C2410_CLKCON_PWMT, | 
 | 150 | 	}, { | 
 | 151 | 		.name		= "uart", | 
| Thomas Abraham | e83626f | 2011-06-14 19:12:26 +0900 | [diff] [blame] | 152 | 		.devname	= "s3c2410-uart.0", | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 153 | 		.parent		= &clk_p, | 
 | 154 | 		.enable		= s3c2410_clkcon_enable, | 
 | 155 | 		.ctrlbit	= S3C2410_CLKCON_UART0, | 
 | 156 | 	}, { | 
 | 157 | 		.name		= "uart", | 
| Thomas Abraham | e83626f | 2011-06-14 19:12:26 +0900 | [diff] [blame] | 158 | 		.devname	= "s3c2410-uart.1", | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 159 | 		.parent		= &clk_p, | 
 | 160 | 		.enable		= s3c2410_clkcon_enable, | 
 | 161 | 		.ctrlbit	= S3C2410_CLKCON_UART1, | 
 | 162 | 	}, { | 
 | 163 | 		.name		= "uart", | 
| Thomas Abraham | e83626f | 2011-06-14 19:12:26 +0900 | [diff] [blame] | 164 | 		.devname	= "s3c2410-uart.2", | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 165 | 		.parent		= &clk_p, | 
 | 166 | 		.enable		= s3c2410_clkcon_enable, | 
 | 167 | 		.ctrlbit	= S3C2410_CLKCON_UART2, | 
 | 168 | 	}, { | 
 | 169 | 		.name		= "rtc", | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 170 | 		.parent		= &clk_p, | 
 | 171 | 		.enable		= s3c2410_clkcon_enable, | 
 | 172 | 		.ctrlbit	= S3C2410_CLKCON_RTC, | 
 | 173 | 	}, { | 
 | 174 | 		.name		= "watchdog", | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 175 | 		.parent		= &clk_p, | 
 | 176 | 		.ctrlbit	= 0, | 
 | 177 | 	}, { | 
 | 178 | 		.name		= "usb-bus-host", | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 179 | 		.parent		= &clk_usb_bus, | 
 | 180 | 	}, { | 
 | 181 | 		.name		= "usb-bus-gadget", | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 182 | 		.parent		= &clk_usb_bus, | 
 | 183 | 	}, | 
 | 184 | }; | 
 | 185 |  | 
 | 186 | /* s3c2410_baseclk_add() | 
 | 187 |  * | 
 | 188 |  * Add all the clocks used by the s3c2410 or compatible CPUs | 
 | 189 |  * such as the S3C2440 and S3C2442. | 
 | 190 |  * | 
 | 191 |  * We cannot use a system device as we are needed before any | 
 | 192 |  * of the init-calls that initialise the devices are actually | 
 | 193 |  * done. | 
 | 194 | */ | 
 | 195 |  | 
 | 196 | int __init s3c2410_baseclk_add(void) | 
 | 197 | { | 
 | 198 | 	unsigned long clkslow = __raw_readl(S3C2410_CLKSLOW); | 
 | 199 | 	unsigned long clkcon  = __raw_readl(S3C2410_CLKCON); | 
 | 200 | 	struct clk *clkp; | 
 | 201 | 	struct clk *xtal; | 
 | 202 | 	int ret; | 
 | 203 | 	int ptr; | 
 | 204 |  | 
 | 205 | 	clk_upll.enable = s3c2410_upll_enable; | 
 | 206 |  | 
 | 207 | 	if (s3c24xx_register_clock(&clk_usb_bus) < 0) | 
 | 208 | 		printk(KERN_ERR "failed to register usb bus clock\n"); | 
 | 209 |  | 
 | 210 | 	/* register clocks from clock array */ | 
 | 211 |  | 
 | 212 | 	clkp = init_clocks; | 
 | 213 | 	for (ptr = 0; ptr < ARRAY_SIZE(init_clocks); ptr++, clkp++) { | 
 | 214 | 		/* ensure that we note the clock state */ | 
 | 215 |  | 
 | 216 | 		clkp->usage = clkcon & clkp->ctrlbit ? 1 : 0; | 
 | 217 |  | 
 | 218 | 		ret = s3c24xx_register_clock(clkp); | 
 | 219 | 		if (ret < 0) { | 
 | 220 | 			printk(KERN_ERR "Failed to register clock %s (%d)\n", | 
 | 221 | 			       clkp->name, ret); | 
 | 222 | 		} | 
| Ben Dooks | 3fc3e1c | 2006-03-20 17:10:07 +0000 | [diff] [blame] | 223 | 	} | 
 | 224 |  | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 225 | 	/* We must be careful disabling the clocks we are not intending to | 
| Robert P. J. Day | 3a4fa0a | 2007-10-19 23:10:43 +0200 | [diff] [blame] | 226 | 	 * be using at boot time, as subsystems such as the LCD which do | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 227 | 	 * their own DMA requests to the bus can cause the system to lockup | 
 | 228 | 	 * if they where in the middle of requesting bus access. | 
 | 229 | 	 * | 
 | 230 | 	 * Disabling the LCD clock if the LCD is active is very dangerous, | 
 | 231 | 	 * and therefore the bootloader should be careful to not enable | 
 | 232 | 	 * the LCD clock if it is not needed. | 
 | 233 | 	*/ | 
| Ben Dooks | 3fc3e1c | 2006-03-20 17:10:07 +0000 | [diff] [blame] | 234 |  | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 235 | 	/* install (and disable) the clocks we do not need immediately */ | 
| Ben Dooks | 3fc3e1c | 2006-03-20 17:10:07 +0000 | [diff] [blame] | 236 |  | 
| Ben Dooks | 4e04691 | 2010-04-28 12:58:13 +0900 | [diff] [blame] | 237 | 	s3c_register_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off)); | 
 | 238 | 	s3c_disable_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off)); | 
| Ben Dooks | 3fc3e1c | 2006-03-20 17:10:07 +0000 | [diff] [blame] | 239 |  | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 240 | 	/* show the clock-slow value */ | 
| Ben Dooks | 3fc3e1c | 2006-03-20 17:10:07 +0000 | [diff] [blame] | 241 |  | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 242 | 	xtal = clk_get(NULL, "xtal"); | 
| Ben Dooks | 3fc3e1c | 2006-03-20 17:10:07 +0000 | [diff] [blame] | 243 |  | 
| Ben Dooks | a21765a | 2007-02-11 18:31:01 +0100 | [diff] [blame] | 244 | 	printk("CLOCK: Slow mode (%ld.%ld MHz), %s, MPLL %s, UPLL %s\n", | 
 | 245 | 	       print_mhz(clk_get_rate(xtal) / | 
 | 246 | 			 ( 2 * S3C2410_CLKSLOW_GET_SLOWVAL(clkslow))), | 
 | 247 | 	       (clkslow & S3C2410_CLKSLOW_SLOW) ? "slow" : "fast", | 
 | 248 | 	       (clkslow & S3C2410_CLKSLOW_MPLL_OFF) ? "off" : "on", | 
 | 249 | 	       (clkslow & S3C2410_CLKSLOW_UCLK_OFF) ? "off" : "on"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 |  | 
| Ben Dooks | 9d325f2 | 2008-11-21 10:36:05 +0000 | [diff] [blame] | 251 | 	s3c_pwmclk_init(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | 	return 0; | 
 | 253 | } |