blob: 52f079a691cb4627b66eb6fa4bb7ad2d14327e9a [file] [log] [blame]
Ben Dooks4b31d8b2008-10-21 14:07:00 +01001/* linux/arch/arm/plat-s3c64xx/clock.c
2 *
3 * Copyright 2008 Openmoko, Inc.
4 * Copyright 2008 Simtec Electronics
5 * Ben Dooks <ben@simtec.co.uk>
6 * http://armlinux.simtec.co.uk/
7 *
8 * S3C64XX Base clock support
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13*/
14
15#include <linux/init.h>
16#include <linux/module.h>
17#include <linux/interrupt.h>
18#include <linux/ioport.h>
Ben Dooks62acb2f82010-01-26 14:53:19 +090019#include <linux/clk.h>
20#include <linux/err.h>
Ben Dooks4b31d8b2008-10-21 14:07:00 +010021#include <linux/io.h>
22
23#include <mach/hardware.h>
24#include <mach/map.h>
25
Ben Dooks3501c9a2010-01-26 10:45:40 +090026#include <mach/regs-sys.h>
27#include <mach/regs-clock.h>
Ben Dooksf7be9ab2010-01-26 13:41:30 +090028
Ben Dooks4b31d8b2008-10-21 14:07:00 +010029#include <plat/cpu.h>
30#include <plat/devs.h>
Ben Dooks62acb2f82010-01-26 14:53:19 +090031#include <plat/cpu-freq.h>
Ben Dooks4b31d8b2008-10-21 14:07:00 +010032#include <plat/clock.h>
Ben Dooks62acb2f82010-01-26 14:53:19 +090033#include <plat/clock-clksrc.h>
Kukjin Kim52e329e2011-10-04 19:41:43 +090034#include <plat/pll.h>
Ben Dooks62acb2f82010-01-26 14:53:19 +090035
36/* fin_apll, fin_mpll and fin_epll are all the same clock, which we call
37 * ext_xtal_mux for want of an actual name from the manual.
38*/
39
40static struct clk clk_ext_xtal_mux = {
41 .name = "ext_xtal",
Ben Dooks62acb2f82010-01-26 14:53:19 +090042};
43
44#define clk_fin_apll clk_ext_xtal_mux
45#define clk_fin_mpll clk_ext_xtal_mux
46#define clk_fin_epll clk_ext_xtal_mux
47
48#define clk_fout_mpll clk_mpll
49#define clk_fout_epll clk_epll
Ben Dooks4b31d8b2008-10-21 14:07:00 +010050
Werner Almesbergera03f7da2009-03-05 11:43:13 +080051struct clk clk_h2 = {
52 .name = "hclk2",
Werner Almesbergera03f7da2009-03-05 11:43:13 +080053 .rate = 0,
54};
55
Ben Dooks4b31d8b2008-10-21 14:07:00 +010056struct clk clk_27m = {
57 .name = "clk_27m",
Ben Dooks4b31d8b2008-10-21 14:07:00 +010058 .rate = 27000000,
59};
60
Ben Dooks3627379f2008-10-31 16:14:36 +000061static int clk_48m_ctrl(struct clk *clk, int enable)
62{
63 unsigned long flags;
64 u32 val;
65
66 /* can't rely on clock lock, this register has other usages */
67 local_irq_save(flags);
68
69 val = __raw_readl(S3C64XX_OTHERS);
70 if (enable)
71 val |= S3C64XX_OTHERS_USBMASK;
72 else
73 val &= ~S3C64XX_OTHERS_USBMASK;
74
75 __raw_writel(val, S3C64XX_OTHERS);
76 local_irq_restore(flags);
77
78 return 0;
79}
80
Ben Dooks4b31d8b2008-10-21 14:07:00 +010081struct clk clk_48m = {
82 .name = "clk_48m",
Ben Dooks4b31d8b2008-10-21 14:07:00 +010083 .rate = 48000000,
Ben Dooks3627379f2008-10-31 16:14:36 +000084 .enable = clk_48m_ctrl,
Ben Dooks4b31d8b2008-10-21 14:07:00 +010085};
86
Maurus Cuelenaere05e021f2010-05-17 20:17:42 +020087struct clk clk_xusbxti = {
88 .name = "xusbxti",
Maurus Cuelenaere05e021f2010-05-17 20:17:42 +020089 .rate = 48000000,
90};
91
Ben Dooks4b31d8b2008-10-21 14:07:00 +010092static int inline s3c64xx_gate(void __iomem *reg,
93 struct clk *clk,
94 int enable)
95{
96 unsigned int ctrlbit = clk->ctrlbit;
97 u32 con;
98
99 con = __raw_readl(reg);
100
101 if (enable)
102 con |= ctrlbit;
103 else
104 con &= ~ctrlbit;
105
106 __raw_writel(con, reg);
107 return 0;
108}
109
110static int s3c64xx_pclk_ctrl(struct clk *clk, int enable)
111{
112 return s3c64xx_gate(S3C_PCLK_GATE, clk, enable);
113}
114
115static int s3c64xx_hclk_ctrl(struct clk *clk, int enable)
116{
117 return s3c64xx_gate(S3C_HCLK_GATE, clk, enable);
118}
119
Ben Dookscf18acf2008-10-21 14:07:02 +0100120int s3c64xx_sclk_ctrl(struct clk *clk, int enable)
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100121{
122 return s3c64xx_gate(S3C_SCLK_GATE, clk, enable);
123}
124
Kukjin Kimcdb216d2011-01-04 18:27:18 +0900125static struct clk init_clocks_off[] = {
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100126 {
127 .name = "nand",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100128 .parent = &clk_h,
129 }, {
Atul Dahiya32fc7fb2010-07-15 11:56:15 +0530130 .name = "rtc",
Atul Dahiya32fc7fb2010-07-15 11:56:15 +0530131 .parent = &clk_p,
132 .enable = s3c64xx_pclk_ctrl,
133 .ctrlbit = S3C_CLKCON_PCLK_RTC,
134 }, {
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100135 .name = "adc",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100136 .parent = &clk_p,
137 .enable = s3c64xx_pclk_ctrl,
138 .ctrlbit = S3C_CLKCON_PCLK_TSADC,
139 }, {
140 .name = "i2c",
Mark Brown5d3a2192012-01-27 14:43:44 +0900141#ifdef CONFIG_S3C_DEV_I2C1
142 .devname = "s3c2440-i2c.0",
143#else
144 .devname = "s3c2440-i2c",
145#endif
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100146 .parent = &clk_p,
147 .enable = s3c64xx_pclk_ctrl,
148 .ctrlbit = S3C_CLKCON_PCLK_IIC,
149 }, {
Ben Dooks400b11a2011-03-04 07:55:44 +0900150 .name = "i2c",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900151 .devname = "s3c2440-i2c.1",
Ben Dooks400b11a2011-03-04 07:55:44 +0900152 .parent = &clk_p,
153 .enable = s3c64xx_pclk_ctrl,
154 .ctrlbit = S3C6410_CLKCON_PCLK_I2C1,
155 }, {
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100156 .name = "iis",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900157 .devname = "samsung-i2s.0",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100158 .parent = &clk_p,
159 .enable = s3c64xx_pclk_ctrl,
160 .ctrlbit = S3C_CLKCON_PCLK_IIS0,
161 }, {
162 .name = "iis",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900163 .devname = "samsung-i2s.1",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100164 .parent = &clk_p,
165 .enable = s3c64xx_pclk_ctrl,
166 .ctrlbit = S3C_CLKCON_PCLK_IIS1,
167 }, {
Jassi Brar2e5070b2010-02-17 19:03:19 +0000168#ifdef CONFIG_CPU_S3C6410
169 .name = "iis",
Jassi Brar2e5070b2010-02-17 19:03:19 +0000170 .parent = &clk_p,
171 .enable = s3c64xx_pclk_ctrl,
172 .ctrlbit = S3C6410_CLKCON_PCLK_IIS2,
173 }, {
174#endif
Naveen Krishna Ch290d0982010-06-22 07:39:18 +0900175 .name = "keypad",
Naveen Krishna Ch290d0982010-06-22 07:39:18 +0900176 .parent = &clk_p,
177 .enable = s3c64xx_pclk_ctrl,
178 .ctrlbit = S3C_CLKCON_PCLK_KEYPAD,
179 }, {
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100180 .name = "spi",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900181 .devname = "s3c64xx-spi.0",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100182 .parent = &clk_p,
183 .enable = s3c64xx_pclk_ctrl,
184 .ctrlbit = S3C_CLKCON_PCLK_SPI0,
185 }, {
186 .name = "spi",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900187 .devname = "s3c64xx-spi.1",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100188 .parent = &clk_p,
189 .enable = s3c64xx_pclk_ctrl,
190 .ctrlbit = S3C_CLKCON_PCLK_SPI1,
191 }, {
192 .name = "48m",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900193 .devname = "s3c-sdhci.0",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100194 .parent = &clk_48m,
195 .enable = s3c64xx_sclk_ctrl,
196 .ctrlbit = S3C_CLKCON_SCLK_MMC0_48,
197 }, {
198 .name = "48m",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900199 .devname = "s3c-sdhci.1",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100200 .parent = &clk_48m,
201 .enable = s3c64xx_sclk_ctrl,
202 .ctrlbit = S3C_CLKCON_SCLK_MMC1_48,
203 }, {
204 .name = "48m",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900205 .devname = "s3c-sdhci.2",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100206 .parent = &clk_48m,
207 .enable = s3c64xx_sclk_ctrl,
208 .ctrlbit = S3C_CLKCON_SCLK_MMC2_48,
Mark Brown8f1ecf12009-04-28 16:06:24 +0100209 }, {
Mark Browned8d8aa2012-01-12 10:41:35 +0900210 .name = "ac97",
211 .parent = &clk_p,
212 .ctrlbit = S3C_CLKCON_PCLK_AC97,
213 }, {
214 .name = "cfcon",
215 .parent = &clk_h,
216 .enable = s3c64xx_hclk_ctrl,
217 .ctrlbit = S3C_CLKCON_HCLK_IHOST,
218 }, {
Mark Brown8f1ecf12009-04-28 16:06:24 +0100219 .name = "dma0",
Mark Brown8f1ecf12009-04-28 16:06:24 +0100220 .parent = &clk_h,
221 .enable = s3c64xx_hclk_ctrl,
222 .ctrlbit = S3C_CLKCON_HCLK_DMA0,
223 }, {
224 .name = "dma1",
Mark Brown8f1ecf12009-04-28 16:06:24 +0100225 .parent = &clk_h,
226 .enable = s3c64xx_hclk_ctrl,
227 .ctrlbit = S3C_CLKCON_HCLK_DMA1,
Mark Brown8942ad82012-01-27 14:42:19 +0900228 }, {
229 .name = "3dse",
230 .parent = &clk_h,
231 .enable = s3c64xx_hclk_ctrl,
232 .ctrlbit = S3C_CLKCON_HCLK_3DSE,
233 }, {
234 .name = "hclk_secur",
235 .parent = &clk_h,
236 .enable = s3c64xx_hclk_ctrl,
237 .ctrlbit = S3C_CLKCON_HCLK_SECUR,
238 }, {
239 .name = "sdma1",
240 .parent = &clk_h,
241 .enable = s3c64xx_hclk_ctrl,
242 .ctrlbit = S3C_CLKCON_HCLK_SDMA1,
243 }, {
244 .name = "sdma0",
245 .parent = &clk_h,
246 .enable = s3c64xx_hclk_ctrl,
247 .ctrlbit = S3C_CLKCON_HCLK_SDMA0,
248 }, {
249 .name = "hclk_jpeg",
250 .parent = &clk_h,
251 .enable = s3c64xx_hclk_ctrl,
252 .ctrlbit = S3C_CLKCON_HCLK_JPEG,
253 }, {
254 .name = "camif",
255 .parent = &clk_h,
256 .enable = s3c64xx_hclk_ctrl,
257 .ctrlbit = S3C_CLKCON_HCLK_CAMIF,
258 }, {
259 .name = "hclk_scaler",
260 .parent = &clk_h,
261 .enable = s3c64xx_hclk_ctrl,
262 .ctrlbit = S3C_CLKCON_HCLK_SCALER,
263 }, {
264 .name = "2d",
265 .parent = &clk_h,
266 .enable = s3c64xx_hclk_ctrl,
267 .ctrlbit = S3C_CLKCON_HCLK_2D,
268 }, {
269 .name = "tv",
270 .parent = &clk_h,
271 .enable = s3c64xx_hclk_ctrl,
272 .ctrlbit = S3C_CLKCON_HCLK_TV,
273 }, {
274 .name = "post0",
275 .parent = &clk_h,
276 .enable = s3c64xx_hclk_ctrl,
277 .ctrlbit = S3C_CLKCON_HCLK_POST0,
278 }, {
279 .name = "rot",
280 .parent = &clk_h,
281 .enable = s3c64xx_hclk_ctrl,
282 .ctrlbit = S3C_CLKCON_HCLK_ROT,
283 }, {
284 .name = "hclk_mfc",
285 .parent = &clk_h,
286 .enable = s3c64xx_hclk_ctrl,
287 .ctrlbit = S3C_CLKCON_HCLK_MFC,
288 }, {
289 .name = "pclk_mfc",
290 .parent = &clk_p,
291 .enable = s3c64xx_pclk_ctrl,
292 .ctrlbit = S3C_CLKCON_PCLK_MFC,
293 }, {
294 .name = "dac27",
295 .enable = s3c64xx_sclk_ctrl,
296 .ctrlbit = S3C_CLKCON_SCLK_DAC27,
297 }, {
298 .name = "tv27",
299 .enable = s3c64xx_sclk_ctrl,
300 .ctrlbit = S3C_CLKCON_SCLK_TV27,
301 }, {
302 .name = "scaler27",
303 .enable = s3c64xx_sclk_ctrl,
304 .ctrlbit = S3C_CLKCON_SCLK_SCALER27,
305 }, {
306 .name = "sclk_scaler",
307 .enable = s3c64xx_sclk_ctrl,
308 .ctrlbit = S3C_CLKCON_SCLK_SCALER,
309 }, {
310 .name = "post0_27",
311 .enable = s3c64xx_sclk_ctrl,
312 .ctrlbit = S3C_CLKCON_SCLK_POST0_27,
313 }, {
314 .name = "secur",
315 .enable = s3c64xx_sclk_ctrl,
316 .ctrlbit = S3C_CLKCON_SCLK_SECUR,
317 }, {
318 .name = "sclk_mfc",
319 .enable = s3c64xx_sclk_ctrl,
320 .ctrlbit = S3C_CLKCON_SCLK_MFC,
321 }, {
322 .name = "cam",
323 .enable = s3c64xx_sclk_ctrl,
324 .ctrlbit = S3C_CLKCON_SCLK_CAM,
325 }, {
326 .name = "sclk_jpeg",
327 .enable = s3c64xx_sclk_ctrl,
328 .ctrlbit = S3C_CLKCON_SCLK_JPEG,
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100329 },
330};
331
Padmavathi Vennaba479172011-11-02 20:04:08 +0900332static struct clk clk_48m_spi0 = {
333 .name = "spi_48m",
334 .devname = "s3c64xx-spi.0",
335 .parent = &clk_48m,
336 .enable = s3c64xx_sclk_ctrl,
337 .ctrlbit = S3C_CLKCON_SCLK_SPI0_48,
338};
339
340static struct clk clk_48m_spi1 = {
341 .name = "spi_48m",
342 .devname = "s3c64xx-spi.1",
343 .parent = &clk_48m,
344 .enable = s3c64xx_sclk_ctrl,
345 .ctrlbit = S3C_CLKCON_SCLK_SPI1_48,
346};
347
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100348static struct clk init_clocks[] = {
349 {
350 .name = "lcd",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100351 .parent = &clk_h,
352 .enable = s3c64xx_hclk_ctrl,
353 .ctrlbit = S3C_CLKCON_HCLK_LCD,
354 }, {
355 .name = "gpio",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100356 .parent = &clk_p,
357 .enable = s3c64xx_pclk_ctrl,
358 .ctrlbit = S3C_CLKCON_PCLK_GPIO,
359 }, {
360 .name = "usb-host",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100361 .parent = &clk_h,
362 .enable = s3c64xx_hclk_ctrl,
Peter Korsgaard386f4352009-06-18 23:54:44 +0200363 .ctrlbit = S3C_CLKCON_HCLK_UHOST,
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100364 }, {
Thomas Abraham5f4c5b22010-05-28 11:41:14 +0900365 .name = "otg",
Thomas Abraham5f4c5b22010-05-28 11:41:14 +0900366 .parent = &clk_h,
367 .enable = s3c64xx_hclk_ctrl,
368 .ctrlbit = S3C_CLKCON_HCLK_USB,
369 }, {
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100370 .name = "timers",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100371 .parent = &clk_p,
372 .enable = s3c64xx_pclk_ctrl,
373 .ctrlbit = S3C_CLKCON_PCLK_PWM,
374 }, {
375 .name = "uart",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900376 .devname = "s3c6400-uart.0",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100377 .parent = &clk_p,
378 .enable = s3c64xx_pclk_ctrl,
379 .ctrlbit = S3C_CLKCON_PCLK_UART0,
380 }, {
381 .name = "uart",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900382 .devname = "s3c6400-uart.1",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100383 .parent = &clk_p,
384 .enable = s3c64xx_pclk_ctrl,
385 .ctrlbit = S3C_CLKCON_PCLK_UART1,
386 }, {
387 .name = "uart",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900388 .devname = "s3c6400-uart.2",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100389 .parent = &clk_p,
390 .enable = s3c64xx_pclk_ctrl,
391 .ctrlbit = S3C_CLKCON_PCLK_UART2,
392 }, {
393 .name = "uart",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900394 .devname = "s3c6400-uart.3",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100395 .parent = &clk_p,
396 .enable = s3c64xx_pclk_ctrl,
397 .ctrlbit = S3C_CLKCON_PCLK_UART3,
398 }, {
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100399 .name = "watchdog",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100400 .parent = &clk_p,
401 .ctrlbit = S3C_CLKCON_PCLK_WDT,
Mark Browned8d8aa2012-01-12 10:41:35 +0900402 },
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100403};
404
Rajeshwari Shindea361d102011-10-24 17:05:58 +0200405static struct clk clk_hsmmc0 = {
406 .name = "hsmmc",
407 .devname = "s3c-sdhci.0",
408 .parent = &clk_h,
409 .enable = s3c64xx_hclk_ctrl,
410 .ctrlbit = S3C_CLKCON_HCLK_HSMMC0,
411};
412
413static struct clk clk_hsmmc1 = {
414 .name = "hsmmc",
415 .devname = "s3c-sdhci.1",
416 .parent = &clk_h,
417 .enable = s3c64xx_hclk_ctrl,
418 .ctrlbit = S3C_CLKCON_HCLK_HSMMC1,
419};
420
421static struct clk clk_hsmmc2 = {
422 .name = "hsmmc",
423 .devname = "s3c-sdhci.2",
424 .parent = &clk_h,
425 .enable = s3c64xx_hclk_ctrl,
426 .ctrlbit = S3C_CLKCON_HCLK_HSMMC2,
427};
Ben Dooks62acb2f82010-01-26 14:53:19 +0900428
429static struct clk clk_fout_apll = {
430 .name = "fout_apll",
Ben Dooks62acb2f82010-01-26 14:53:19 +0900431};
432
433static struct clk *clk_src_apll_list[] = {
434 [0] = &clk_fin_apll,
435 [1] = &clk_fout_apll,
436};
437
438static struct clksrc_sources clk_src_apll = {
439 .sources = clk_src_apll_list,
440 .nr_sources = ARRAY_SIZE(clk_src_apll_list),
441};
442
443static struct clksrc_clk clk_mout_apll = {
444 .clk = {
445 .name = "mout_apll",
Ben Dooks62acb2f82010-01-26 14:53:19 +0900446 },
447 .reg_src = { .reg = S3C_CLK_SRC, .shift = 0, .size = 1 },
448 .sources = &clk_src_apll,
449};
450
451static struct clk *clk_src_epll_list[] = {
452 [0] = &clk_fin_epll,
453 [1] = &clk_fout_epll,
454};
455
456static struct clksrc_sources clk_src_epll = {
457 .sources = clk_src_epll_list,
458 .nr_sources = ARRAY_SIZE(clk_src_epll_list),
459};
460
461static struct clksrc_clk clk_mout_epll = {
462 .clk = {
463 .name = "mout_epll",
Ben Dooks62acb2f82010-01-26 14:53:19 +0900464 },
465 .reg_src = { .reg = S3C_CLK_SRC, .shift = 2, .size = 1 },
466 .sources = &clk_src_epll,
467};
468
469static struct clk *clk_src_mpll_list[] = {
470 [0] = &clk_fin_mpll,
471 [1] = &clk_fout_mpll,
472};
473
474static struct clksrc_sources clk_src_mpll = {
475 .sources = clk_src_mpll_list,
476 .nr_sources = ARRAY_SIZE(clk_src_mpll_list),
477};
478
479static struct clksrc_clk clk_mout_mpll = {
480 .clk = {
481 .name = "mout_mpll",
Ben Dooks62acb2f82010-01-26 14:53:19 +0900482 },
483 .reg_src = { .reg = S3C_CLK_SRC, .shift = 1, .size = 1 },
484 .sources = &clk_src_mpll,
485};
486
487static unsigned int armclk_mask;
488
489static unsigned long s3c64xx_clk_arm_get_rate(struct clk *clk)
490{
491 unsigned long rate = clk_get_rate(clk->parent);
492 u32 clkdiv;
493
494 /* divisor mask starts at bit0, so no need to shift */
495 clkdiv = __raw_readl(S3C_CLK_DIV0) & armclk_mask;
496
497 return rate / (clkdiv + 1);
498}
499
500static unsigned long s3c64xx_clk_arm_round_rate(struct clk *clk,
501 unsigned long rate)
502{
503 unsigned long parent = clk_get_rate(clk->parent);
504 u32 div;
505
506 if (parent < rate)
507 return parent;
508
509 div = (parent / rate) - 1;
510 if (div > armclk_mask)
511 div = armclk_mask;
512
513 return parent / (div + 1);
514}
515
516static int s3c64xx_clk_arm_set_rate(struct clk *clk, unsigned long rate)
517{
518 unsigned long parent = clk_get_rate(clk->parent);
519 u32 div;
520 u32 val;
521
522 if (rate < parent / (armclk_mask + 1))
523 return -EINVAL;
524
525 rate = clk_round_rate(clk, rate);
526 div = clk_get_rate(clk->parent) / rate;
527
528 val = __raw_readl(S3C_CLK_DIV0);
529 val &= ~armclk_mask;
530 val |= (div - 1);
531 __raw_writel(val, S3C_CLK_DIV0);
532
533 return 0;
534
535}
536
537static struct clk clk_arm = {
538 .name = "armclk",
Ben Dooks62acb2f82010-01-26 14:53:19 +0900539 .parent = &clk_mout_apll.clk,
540 .ops = &(struct clk_ops) {
541 .get_rate = s3c64xx_clk_arm_get_rate,
542 .set_rate = s3c64xx_clk_arm_set_rate,
543 .round_rate = s3c64xx_clk_arm_round_rate,
544 },
545};
546
547static unsigned long s3c64xx_clk_doutmpll_get_rate(struct clk *clk)
548{
549 unsigned long rate = clk_get_rate(clk->parent);
550
551 printk(KERN_DEBUG "%s: parent is %ld\n", __func__, rate);
552
553 if (__raw_readl(S3C_CLK_DIV0) & S3C6400_CLKDIV0_MPLL_MASK)
554 rate /= 2;
555
556 return rate;
557}
558
559static struct clk_ops clk_dout_ops = {
560 .get_rate = s3c64xx_clk_doutmpll_get_rate,
561};
562
563static struct clk clk_dout_mpll = {
564 .name = "dout_mpll",
Ben Dooks62acb2f82010-01-26 14:53:19 +0900565 .parent = &clk_mout_mpll.clk,
566 .ops = &clk_dout_ops,
567};
568
569static struct clk *clkset_spi_mmc_list[] = {
570 &clk_mout_epll.clk,
571 &clk_dout_mpll,
572 &clk_fin_epll,
573 &clk_27m,
574};
575
576static struct clksrc_sources clkset_spi_mmc = {
577 .sources = clkset_spi_mmc_list,
578 .nr_sources = ARRAY_SIZE(clkset_spi_mmc_list),
579};
580
581static struct clk *clkset_irda_list[] = {
582 &clk_mout_epll.clk,
583 &clk_dout_mpll,
584 NULL,
585 &clk_27m,
586};
587
588static struct clksrc_sources clkset_irda = {
589 .sources = clkset_irda_list,
590 .nr_sources = ARRAY_SIZE(clkset_irda_list),
591};
592
593static struct clk *clkset_uart_list[] = {
594 &clk_mout_epll.clk,
595 &clk_dout_mpll,
596 NULL,
597 NULL
598};
599
600static struct clksrc_sources clkset_uart = {
601 .sources = clkset_uart_list,
602 .nr_sources = ARRAY_SIZE(clkset_uart_list),
603};
604
605static struct clk *clkset_uhost_list[] = {
606 &clk_48m,
607 &clk_mout_epll.clk,
608 &clk_dout_mpll,
609 &clk_fin_epll,
610};
611
612static struct clksrc_sources clkset_uhost = {
613 .sources = clkset_uhost_list,
614 .nr_sources = ARRAY_SIZE(clkset_uhost_list),
615};
616
617/* The peripheral clocks are all controlled via clocksource followed
618 * by an optional divider and gate stage. We currently roll this into
619 * one clock which hides the intermediate clock from the mux.
620 *
621 * Note, the JPEG clock can only be an even divider...
622 *
623 * The scaler and LCD clocks depend on the S3C64XX version, and also
624 * have a common parent divisor so are not included here.
625 */
626
627/* clocks that feed other parts of the clock source tree */
628
629static struct clk clk_iis_cd0 = {
630 .name = "iis_cdclk0",
Ben Dooks62acb2f82010-01-26 14:53:19 +0900631};
632
633static struct clk clk_iis_cd1 = {
634 .name = "iis_cdclk1",
Ben Dooks62acb2f82010-01-26 14:53:19 +0900635};
636
Jassi Brarbc8eb1e2010-03-09 15:10:32 +0900637static struct clk clk_iisv4_cd = {
638 .name = "iis_cdclk_v4",
Jassi Brarbc8eb1e2010-03-09 15:10:32 +0900639};
640
Ben Dooks62acb2f82010-01-26 14:53:19 +0900641static struct clk clk_pcm_cd = {
642 .name = "pcm_cdclk",
Ben Dooks62acb2f82010-01-26 14:53:19 +0900643};
644
645static struct clk *clkset_audio0_list[] = {
646 [0] = &clk_mout_epll.clk,
647 [1] = &clk_dout_mpll,
648 [2] = &clk_fin_epll,
649 [3] = &clk_iis_cd0,
650 [4] = &clk_pcm_cd,
651};
652
653static struct clksrc_sources clkset_audio0 = {
654 .sources = clkset_audio0_list,
655 .nr_sources = ARRAY_SIZE(clkset_audio0_list),
656};
657
658static struct clk *clkset_audio1_list[] = {
659 [0] = &clk_mout_epll.clk,
660 [1] = &clk_dout_mpll,
661 [2] = &clk_fin_epll,
662 [3] = &clk_iis_cd1,
663 [4] = &clk_pcm_cd,
664};
665
666static struct clksrc_sources clkset_audio1 = {
667 .sources = clkset_audio1_list,
668 .nr_sources = ARRAY_SIZE(clkset_audio1_list),
669};
670
Jassi Brar1aede2e2010-03-09 15:10:33 +0900671static struct clk *clkset_audio2_list[] = {
672 [0] = &clk_mout_epll.clk,
673 [1] = &clk_dout_mpll,
674 [2] = &clk_fin_epll,
675 [3] = &clk_iisv4_cd,
676 [4] = &clk_pcm_cd,
677};
678
679static struct clksrc_sources clkset_audio2 = {
680 .sources = clkset_audio2_list,
681 .nr_sources = ARRAY_SIZE(clkset_audio2_list),
682};
683
Ben Dooks62acb2f82010-01-26 14:53:19 +0900684static struct clk *clkset_camif_list[] = {
685 &clk_h2,
686};
687
688static struct clksrc_sources clkset_camif = {
689 .sources = clkset_camif_list,
690 .nr_sources = ARRAY_SIZE(clkset_camif_list),
691};
692
693static struct clksrc_clk clksrcs[] = {
694 {
695 .clk = {
Ben Dooks62acb2f82010-01-26 14:53:19 +0900696 .name = "usb-bus-host",
Ben Dooks62acb2f82010-01-26 14:53:19 +0900697 .ctrlbit = S3C_CLKCON_SCLK_UHOST,
698 .enable = s3c64xx_sclk_ctrl,
699 },
700 .reg_src = { .reg = S3C_CLK_SRC, .shift = 5, .size = 2 },
701 .reg_div = { .reg = S3C_CLK_DIV1, .shift = 20, .size = 4 },
702 .sources = &clkset_uhost,
703 }, {
704 .clk = {
Ben Dooks62acb2f82010-01-26 14:53:19 +0900705 .name = "audio-bus",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900706 .devname = "samsung-i2s.0",
Ben Dooks62acb2f82010-01-26 14:53:19 +0900707 .ctrlbit = S3C_CLKCON_SCLK_AUDIO0,
708 .enable = s3c64xx_sclk_ctrl,
709 },
710 .reg_src = { .reg = S3C_CLK_SRC, .shift = 7, .size = 3 },
711 .reg_div = { .reg = S3C_CLK_DIV2, .shift = 8, .size = 4 },
712 .sources = &clkset_audio0,
713 }, {
714 .clk = {
715 .name = "audio-bus",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900716 .devname = "samsung-i2s.1",
Ben Dooks62acb2f82010-01-26 14:53:19 +0900717 .ctrlbit = S3C_CLKCON_SCLK_AUDIO1,
718 .enable = s3c64xx_sclk_ctrl,
719 },
720 .reg_src = { .reg = S3C_CLK_SRC, .shift = 10, .size = 3 },
721 .reg_div = { .reg = S3C_CLK_DIV2, .shift = 12, .size = 4 },
722 .sources = &clkset_audio1,
723 }, {
724 .clk = {
Jassi Brar835879a2010-03-09 15:10:34 +0900725 .name = "audio-bus",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900726 .devname = "samsung-i2s.2",
Jassi Brar835879a2010-03-09 15:10:34 +0900727 .ctrlbit = S3C6410_CLKCON_SCLK_AUDIO2,
728 .enable = s3c64xx_sclk_ctrl,
729 },
730 .reg_src = { .reg = S3C6410_CLK_SRC2, .shift = 0, .size = 3 },
731 .reg_div = { .reg = S3C_CLK_DIV2, .shift = 24, .size = 4 },
732 .sources = &clkset_audio2,
733 }, {
734 .clk = {
Ben Dooks62acb2f82010-01-26 14:53:19 +0900735 .name = "irda-bus",
Ben Dooks62acb2f82010-01-26 14:53:19 +0900736 .ctrlbit = S3C_CLKCON_SCLK_IRDA,
737 .enable = s3c64xx_sclk_ctrl,
738 },
739 .reg_src = { .reg = S3C_CLK_SRC, .shift = 24, .size = 2 },
740 .reg_div = { .reg = S3C_CLK_DIV2, .shift = 20, .size = 4 },
741 .sources = &clkset_irda,
742 }, {
743 .clk = {
744 .name = "camera",
Ben Dooks62acb2f82010-01-26 14:53:19 +0900745 .ctrlbit = S3C_CLKCON_SCLK_CAM,
746 .enable = s3c64xx_sclk_ctrl,
747 },
748 .reg_div = { .reg = S3C_CLK_DIV0, .shift = 20, .size = 4 },
749 .reg_src = { .reg = NULL, .shift = 0, .size = 0 },
750 .sources = &clkset_camif,
751 },
752};
753
Thomas Abraham0cfb26e2011-10-24 12:08:42 +0200754/* Where does UCLK0 come from? */
755static struct clksrc_clk clk_sclk_uclk = {
756 .clk = {
757 .name = "uclk1",
758 .ctrlbit = S3C_CLKCON_SCLK_UART,
759 .enable = s3c64xx_sclk_ctrl,
760 },
761 .reg_src = { .reg = S3C_CLK_SRC, .shift = 13, .size = 1 },
762 .reg_div = { .reg = S3C_CLK_DIV2, .shift = 16, .size = 4 },
763 .sources = &clkset_uart,
764};
765
Rajeshwari Shindea361d102011-10-24 17:05:58 +0200766static struct clksrc_clk clk_sclk_mmc0 = {
767 .clk = {
768 .name = "mmc_bus",
769 .devname = "s3c-sdhci.0",
770 .ctrlbit = S3C_CLKCON_SCLK_MMC0,
771 .enable = s3c64xx_sclk_ctrl,
772 },
773 .reg_src = { .reg = S3C_CLK_SRC, .shift = 18, .size = 2 },
774 .reg_div = { .reg = S3C_CLK_DIV1, .shift = 0, .size = 4 },
775 .sources = &clkset_spi_mmc,
776};
777
778static struct clksrc_clk clk_sclk_mmc1 = {
779 .clk = {
780 .name = "mmc_bus",
781 .devname = "s3c-sdhci.1",
782 .ctrlbit = S3C_CLKCON_SCLK_MMC1,
783 .enable = s3c64xx_sclk_ctrl,
784 },
785 .reg_src = { .reg = S3C_CLK_SRC, .shift = 20, .size = 2 },
786 .reg_div = { .reg = S3C_CLK_DIV1, .shift = 4, .size = 4 },
787 .sources = &clkset_spi_mmc,
788};
789
790static struct clksrc_clk clk_sclk_mmc2 = {
791 .clk = {
792 .name = "mmc_bus",
793 .devname = "s3c-sdhci.2",
794 .ctrlbit = S3C_CLKCON_SCLK_MMC2,
795 .enable = s3c64xx_sclk_ctrl,
796 },
797 .reg_src = { .reg = S3C_CLK_SRC, .shift = 22, .size = 2 },
798 .reg_div = { .reg = S3C_CLK_DIV1, .shift = 8, .size = 4 },
799 .sources = &clkset_spi_mmc,
800};
801
Padmavathi Vennaba479172011-11-02 20:04:08 +0900802static struct clksrc_clk clk_sclk_spi0 = {
803 .clk = {
804 .name = "spi-bus",
805 .devname = "s3c64xx-spi.0",
806 .ctrlbit = S3C_CLKCON_SCLK_SPI0,
807 .enable = s3c64xx_sclk_ctrl,
808 },
809 .reg_src = { .reg = S3C_CLK_SRC, .shift = 14, .size = 2 },
810 .reg_div = { .reg = S3C_CLK_DIV2, .shift = 0, .size = 4 },
811 .sources = &clkset_spi_mmc,
812};
813
814static struct clksrc_clk clk_sclk_spi1 = {
815 .clk = {
816 .name = "spi-bus",
817 .devname = "s3c64xx-spi.1",
818 .ctrlbit = S3C_CLKCON_SCLK_SPI1,
819 .enable = s3c64xx_sclk_ctrl,
820 },
821 .reg_src = { .reg = S3C_CLK_SRC, .shift = 16, .size = 2 },
822 .reg_div = { .reg = S3C_CLK_DIV2, .shift = 4, .size = 4 },
823 .sources = &clkset_spi_mmc,
824};
825
Ben Dooks62acb2f82010-01-26 14:53:19 +0900826/* Clock initialisation code */
827
828static struct clksrc_clk *init_parents[] = {
829 &clk_mout_apll,
830 &clk_mout_epll,
831 &clk_mout_mpll,
832};
833
Thomas Abraham0cfb26e2011-10-24 12:08:42 +0200834static struct clksrc_clk *clksrc_cdev[] = {
835 &clk_sclk_uclk,
Rajeshwari Shindea361d102011-10-24 17:05:58 +0200836 &clk_sclk_mmc0,
837 &clk_sclk_mmc1,
838 &clk_sclk_mmc2,
Padmavathi Vennaba479172011-11-02 20:04:08 +0900839 &clk_sclk_spi0,
840 &clk_sclk_spi1,
Rajeshwari Shindea361d102011-10-24 17:05:58 +0200841};
842
843static struct clk *clk_cdev[] = {
844 &clk_hsmmc0,
845 &clk_hsmmc1,
846 &clk_hsmmc2,
Padmavathi Vennaba479172011-11-02 20:04:08 +0900847 &clk_48m_spi0,
848 &clk_48m_spi1,
Thomas Abraham0cfb26e2011-10-24 12:08:42 +0200849};
850
851static struct clk_lookup s3c64xx_clk_lookup[] = {
852 CLKDEV_INIT(NULL, "clk_uart_baud2", &clk_p),
853 CLKDEV_INIT(NULL, "clk_uart_baud3", &clk_sclk_uclk.clk),
Rajeshwari Shindea361d102011-10-24 17:05:58 +0200854 CLKDEV_INIT("s3c-sdhci.0", "mmc_busclk.0", &clk_hsmmc0),
855 CLKDEV_INIT("s3c-sdhci.1", "mmc_busclk.0", &clk_hsmmc1),
856 CLKDEV_INIT("s3c-sdhci.2", "mmc_busclk.0", &clk_hsmmc2),
857 CLKDEV_INIT("s3c-sdhci.0", "mmc_busclk.2", &clk_sclk_mmc0.clk),
858 CLKDEV_INIT("s3c-sdhci.1", "mmc_busclk.2", &clk_sclk_mmc1.clk),
859 CLKDEV_INIT("s3c-sdhci.2", "mmc_busclk.2", &clk_sclk_mmc2.clk),
Padmavathi Vennaba479172011-11-02 20:04:08 +0900860 CLKDEV_INIT(NULL, "spi_busclk0", &clk_p),
861 CLKDEV_INIT("s3c64xx-spi.0", "spi_busclk1", &clk_sclk_spi0.clk),
862 CLKDEV_INIT("s3c64xx-spi.0", "spi_busclk2", &clk_48m_spi0),
863 CLKDEV_INIT("s3c64xx-spi.1", "spi_busclk1", &clk_sclk_spi1.clk),
864 CLKDEV_INIT("s3c64xx-spi.1", "spi_busclk2", &clk_48m_spi1),
Thomas Abraham0cfb26e2011-10-24 12:08:42 +0200865};
866
Ben Dooks62acb2f82010-01-26 14:53:19 +0900867#define GET_DIV(clk, field) ((((clk) & field##_MASK) >> field##_SHIFT) + 1)
868
Kukjin Kimb024043b2011-12-22 23:27:42 +0100869void __init_or_cpufreq s3c64xx_setup_clocks(void)
Ben Dooks62acb2f82010-01-26 14:53:19 +0900870{
871 struct clk *xtal_clk;
872 unsigned long xtal;
873 unsigned long fclk;
874 unsigned long hclk;
875 unsigned long hclk2;
876 unsigned long pclk;
877 unsigned long epll;
878 unsigned long apll;
879 unsigned long mpll;
880 unsigned int ptr;
881 u32 clkdiv0;
882
883 printk(KERN_DEBUG "%s: registering clocks\n", __func__);
884
885 clkdiv0 = __raw_readl(S3C_CLK_DIV0);
886 printk(KERN_DEBUG "%s: clkdiv0 = %08x\n", __func__, clkdiv0);
887
888 xtal_clk = clk_get(NULL, "xtal");
889 BUG_ON(IS_ERR(xtal_clk));
890
891 xtal = clk_get_rate(xtal_clk);
892 clk_put(xtal_clk);
893
894 printk(KERN_DEBUG "%s: xtal is %ld\n", __func__, xtal);
895
896 /* For now assume the mux always selects the crystal */
897 clk_ext_xtal_mux.parent = xtal_clk;
898
Kukjin Kim52e329e2011-10-04 19:41:43 +0900899 epll = s3c_get_pll6553x(xtal, __raw_readl(S3C_EPLL_CON0),
900 __raw_readl(S3C_EPLL_CON1));
Ben Dooks62acb2f82010-01-26 14:53:19 +0900901 mpll = s3c6400_get_pll(xtal, __raw_readl(S3C_MPLL_CON));
902 apll = s3c6400_get_pll(xtal, __raw_readl(S3C_APLL_CON));
903
904 fclk = mpll;
905
906 printk(KERN_INFO "S3C64XX: PLL settings, A=%ld, M=%ld, E=%ld\n",
907 apll, mpll, epll);
908
Tomasz Figafb5d3752011-08-19 11:54:31 +0200909 if(__raw_readl(S3C64XX_OTHERS) & S3C64XX_OTHERS_SYNCMUXSEL)
910 /* Synchronous mode */
911 hclk2 = apll / GET_DIV(clkdiv0, S3C6400_CLKDIV0_HCLK2);
912 else
913 /* Asynchronous mode */
914 hclk2 = mpll / GET_DIV(clkdiv0, S3C6400_CLKDIV0_HCLK2);
915
Ben Dooks62acb2f82010-01-26 14:53:19 +0900916 hclk = hclk2 / GET_DIV(clkdiv0, S3C6400_CLKDIV0_HCLK);
917 pclk = hclk2 / GET_DIV(clkdiv0, S3C6400_CLKDIV0_PCLK);
918
919 printk(KERN_INFO "S3C64XX: HCLK2=%ld, HCLK=%ld, PCLK=%ld\n",
920 hclk2, hclk, pclk);
921
922 clk_fout_mpll.rate = mpll;
923 clk_fout_epll.rate = epll;
924 clk_fout_apll.rate = apll;
925
926 clk_h2.rate = hclk2;
927 clk_h.rate = hclk;
928 clk_p.rate = pclk;
929 clk_f.rate = fclk;
930
931 for (ptr = 0; ptr < ARRAY_SIZE(init_parents); ptr++)
932 s3c_set_clksrc(init_parents[ptr], true);
933
934 for (ptr = 0; ptr < ARRAY_SIZE(clksrcs); ptr++)
935 s3c_set_clksrc(&clksrcs[ptr], true);
936}
937
938static struct clk *clks1[] __initdata = {
939 &clk_ext_xtal_mux,
940 &clk_iis_cd0,
941 &clk_iis_cd1,
Jassi Brarbc8eb1e2010-03-09 15:10:32 +0900942 &clk_iisv4_cd,
Ben Dooks62acb2f82010-01-26 14:53:19 +0900943 &clk_pcm_cd,
944 &clk_mout_epll.clk,
945 &clk_mout_mpll.clk,
946 &clk_dout_mpll,
947 &clk_arm,
948};
949
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100950static struct clk *clks[] __initdata = {
951 &clk_ext,
952 &clk_epll,
953 &clk_27m,
954 &clk_48m,
Werner Almesbergera03f7da2009-03-05 11:43:13 +0800955 &clk_h2,
Maurus Cuelenaere05e021f2010-05-17 20:17:42 +0200956 &clk_xusbxti,
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100957};
958
Ben Dooks55bf9262010-01-26 15:10:38 +0900959/**
960 * s3c64xx_register_clocks - register clocks for s3c6400 and s3c6410
961 * @xtal: The rate for the clock crystal feeding the PLLs.
962 * @armclk_divlimit: Divisor mask for ARMCLK.
963 *
964 * Register the clocks for the S3C6400 and S3C6410 SoC range, such
965 * as ARMCLK as well as the necessary parent clocks.
966 *
967 * This call does not setup the clocks, which is left to the
Kukjin Kimb024043b2011-12-22 23:27:42 +0100968 * s3c64xx_setup_clocks() call which may be needed by the cpufreq
Ben Dooks55bf9262010-01-26 15:10:38 +0900969 * or resume code to re-set the clocks if the bootloader has changed
970 * them.
971 */
972void __init s3c64xx_register_clocks(unsigned long xtal,
973 unsigned armclk_divlimit)
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100974{
Thomas Abraham0cfb26e2011-10-24 12:08:42 +0200975 unsigned int cnt;
976
Ben Dooks55bf9262010-01-26 15:10:38 +0900977 armclk_mask = armclk_divlimit;
978
979 s3c24xx_register_baseclocks(xtal);
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100980 s3c24xx_register_clocks(clks, ARRAY_SIZE(clks));
Ben Dooks55bf9262010-01-26 15:10:38 +0900981
Ben Dooks1d9f13c2010-01-06 01:21:38 +0900982 s3c_register_clocks(init_clocks, ARRAY_SIZE(init_clocks));
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100983
Kukjin Kimcdb216d2011-01-04 18:27:18 +0900984 s3c_register_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
985 s3c_disable_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
Ben Dooks9d325f22008-11-21 10:36:05 +0000986
Rajeshwari Shindea361d102011-10-24 17:05:58 +0200987 s3c24xx_register_clocks(clk_cdev, ARRAY_SIZE(clk_cdev));
988 for (cnt = 0; cnt < ARRAY_SIZE(clk_cdev); cnt++)
989 s3c_disable_clocks(clk_cdev[cnt], 1);
990
Ben Dooks55bf9262010-01-26 15:10:38 +0900991 s3c24xx_register_clocks(clks1, ARRAY_SIZE(clks1));
992 s3c_register_clksrc(clksrcs, ARRAY_SIZE(clksrcs));
Thomas Abraham0cfb26e2011-10-24 12:08:42 +0200993 for (cnt = 0; cnt < ARRAY_SIZE(clksrc_cdev); cnt++)
994 s3c_register_clksrc(clksrc_cdev[cnt], 1);
995 clkdev_add_table(s3c64xx_clk_lookup, ARRAY_SIZE(s3c64xx_clk_lookup));
996
Ben Dooks9d325f22008-11-21 10:36:05 +0000997 s3c_pwmclk_init();
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100998}