blob: 872e68361eb44d8f289c963e0cf0456d01dc7822 [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#include <mach/pll.h>
29
Ben Dooks4b31d8b2008-10-21 14:07:00 +010030#include <plat/cpu.h>
31#include <plat/devs.h>
Ben Dooks62acb2f82010-01-26 14:53:19 +090032#include <plat/cpu-freq.h>
Ben Dooks4b31d8b2008-10-21 14:07:00 +010033#include <plat/clock.h>
Ben Dooks62acb2f82010-01-26 14:53:19 +090034#include <plat/clock-clksrc.h>
35
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",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100141 .parent = &clk_p,
142 .enable = s3c64xx_pclk_ctrl,
143 .ctrlbit = S3C_CLKCON_PCLK_IIC,
144 }, {
Ben Dooks400b11a2011-03-04 07:55:44 +0900145 .name = "i2c",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900146 .devname = "s3c2440-i2c.1",
Ben Dooks400b11a2011-03-04 07:55:44 +0900147 .parent = &clk_p,
148 .enable = s3c64xx_pclk_ctrl,
149 .ctrlbit = S3C6410_CLKCON_PCLK_I2C1,
150 }, {
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100151 .name = "iis",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900152 .devname = "samsung-i2s.0",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100153 .parent = &clk_p,
154 .enable = s3c64xx_pclk_ctrl,
155 .ctrlbit = S3C_CLKCON_PCLK_IIS0,
156 }, {
157 .name = "iis",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900158 .devname = "samsung-i2s.1",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100159 .parent = &clk_p,
160 .enable = s3c64xx_pclk_ctrl,
161 .ctrlbit = S3C_CLKCON_PCLK_IIS1,
162 }, {
Jassi Brar2e5070b2010-02-17 19:03:19 +0000163#ifdef CONFIG_CPU_S3C6410
164 .name = "iis",
Jassi Brar2e5070b2010-02-17 19:03:19 +0000165 .parent = &clk_p,
166 .enable = s3c64xx_pclk_ctrl,
167 .ctrlbit = S3C6410_CLKCON_PCLK_IIS2,
168 }, {
169#endif
Naveen Krishna Ch290d0982010-06-22 07:39:18 +0900170 .name = "keypad",
Naveen Krishna Ch290d0982010-06-22 07:39:18 +0900171 .parent = &clk_p,
172 .enable = s3c64xx_pclk_ctrl,
173 .ctrlbit = S3C_CLKCON_PCLK_KEYPAD,
174 }, {
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100175 .name = "spi",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900176 .devname = "s3c64xx-spi.0",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100177 .parent = &clk_p,
178 .enable = s3c64xx_pclk_ctrl,
179 .ctrlbit = S3C_CLKCON_PCLK_SPI0,
180 }, {
181 .name = "spi",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900182 .devname = "s3c64xx-spi.1",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100183 .parent = &clk_p,
184 .enable = s3c64xx_pclk_ctrl,
185 .ctrlbit = S3C_CLKCON_PCLK_SPI1,
186 }, {
Jassi Brar87315a82010-01-18 16:15:08 +0900187 .name = "spi_48m",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900188 .devname = "s3c64xx-spi.0",
Jassi Brar87315a82010-01-18 16:15:08 +0900189 .parent = &clk_48m,
190 .enable = s3c64xx_sclk_ctrl,
191 .ctrlbit = S3C_CLKCON_SCLK_SPI0_48,
192 }, {
193 .name = "spi_48m",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900194 .devname = "s3c64xx-spi.1",
Jassi Brar87315a82010-01-18 16:15:08 +0900195 .parent = &clk_48m,
196 .enable = s3c64xx_sclk_ctrl,
197 .ctrlbit = S3C_CLKCON_SCLK_SPI1_48,
198 }, {
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100199 .name = "48m",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900200 .devname = "s3c-sdhci.0",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100201 .parent = &clk_48m,
202 .enable = s3c64xx_sclk_ctrl,
203 .ctrlbit = S3C_CLKCON_SCLK_MMC0_48,
204 }, {
205 .name = "48m",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900206 .devname = "s3c-sdhci.1",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100207 .parent = &clk_48m,
208 .enable = s3c64xx_sclk_ctrl,
209 .ctrlbit = S3C_CLKCON_SCLK_MMC1_48,
210 }, {
211 .name = "48m",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900212 .devname = "s3c-sdhci.2",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100213 .parent = &clk_48m,
214 .enable = s3c64xx_sclk_ctrl,
215 .ctrlbit = S3C_CLKCON_SCLK_MMC2_48,
Mark Brown8f1ecf12009-04-28 16:06:24 +0100216 }, {
217 .name = "dma0",
Mark Brown8f1ecf12009-04-28 16:06:24 +0100218 .parent = &clk_h,
219 .enable = s3c64xx_hclk_ctrl,
220 .ctrlbit = S3C_CLKCON_HCLK_DMA0,
221 }, {
222 .name = "dma1",
Mark Brown8f1ecf12009-04-28 16:06:24 +0100223 .parent = &clk_h,
224 .enable = s3c64xx_hclk_ctrl,
225 .ctrlbit = S3C_CLKCON_HCLK_DMA1,
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100226 },
227};
228
229static struct clk init_clocks[] = {
230 {
231 .name = "lcd",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100232 .parent = &clk_h,
233 .enable = s3c64xx_hclk_ctrl,
234 .ctrlbit = S3C_CLKCON_HCLK_LCD,
235 }, {
236 .name = "gpio",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100237 .parent = &clk_p,
238 .enable = s3c64xx_pclk_ctrl,
239 .ctrlbit = S3C_CLKCON_PCLK_GPIO,
240 }, {
241 .name = "usb-host",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100242 .parent = &clk_h,
243 .enable = s3c64xx_hclk_ctrl,
Peter Korsgaard386f4352009-06-18 23:54:44 +0200244 .ctrlbit = S3C_CLKCON_HCLK_UHOST,
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100245 }, {
246 .name = "hsmmc",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900247 .devname = "s3c-sdhci.0",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100248 .parent = &clk_h,
249 .enable = s3c64xx_hclk_ctrl,
250 .ctrlbit = S3C_CLKCON_HCLK_HSMMC0,
251 }, {
252 .name = "hsmmc",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900253 .devname = "s3c-sdhci.1",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100254 .parent = &clk_h,
255 .enable = s3c64xx_hclk_ctrl,
256 .ctrlbit = S3C_CLKCON_HCLK_HSMMC1,
257 }, {
258 .name = "hsmmc",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900259 .devname = "s3c-sdhci.2",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100260 .parent = &clk_h,
261 .enable = s3c64xx_hclk_ctrl,
262 .ctrlbit = S3C_CLKCON_HCLK_HSMMC2,
263 }, {
Thomas Abraham5f4c5b22010-05-28 11:41:14 +0900264 .name = "otg",
Thomas Abraham5f4c5b22010-05-28 11:41:14 +0900265 .parent = &clk_h,
266 .enable = s3c64xx_hclk_ctrl,
267 .ctrlbit = S3C_CLKCON_HCLK_USB,
268 }, {
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100269 .name = "timers",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100270 .parent = &clk_p,
271 .enable = s3c64xx_pclk_ctrl,
272 .ctrlbit = S3C_CLKCON_PCLK_PWM,
273 }, {
274 .name = "uart",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900275 .devname = "s3c6400-uart.0",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100276 .parent = &clk_p,
277 .enable = s3c64xx_pclk_ctrl,
278 .ctrlbit = S3C_CLKCON_PCLK_UART0,
279 }, {
280 .name = "uart",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900281 .devname = "s3c6400-uart.1",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100282 .parent = &clk_p,
283 .enable = s3c64xx_pclk_ctrl,
284 .ctrlbit = S3C_CLKCON_PCLK_UART1,
285 }, {
286 .name = "uart",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900287 .devname = "s3c6400-uart.2",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100288 .parent = &clk_p,
289 .enable = s3c64xx_pclk_ctrl,
290 .ctrlbit = S3C_CLKCON_PCLK_UART2,
291 }, {
292 .name = "uart",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900293 .devname = "s3c6400-uart.3",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100294 .parent = &clk_p,
295 .enable = s3c64xx_pclk_ctrl,
296 .ctrlbit = S3C_CLKCON_PCLK_UART3,
297 }, {
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100298 .name = "watchdog",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100299 .parent = &clk_p,
300 .ctrlbit = S3C_CLKCON_PCLK_WDT,
301 }, {
302 .name = "ac97",
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100303 .parent = &clk_p,
304 .ctrlbit = S3C_CLKCON_PCLK_AC97,
Abhilash Kesavan0ab0b6d2010-06-08 16:55:45 +0900305 }, {
306 .name = "cfcon",
Abhilash Kesavan0ab0b6d2010-06-08 16:55:45 +0900307 .parent = &clk_h,
308 .enable = s3c64xx_hclk_ctrl,
309 .ctrlbit = S3C_CLKCON_HCLK_IHOST,
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100310 }
311};
312
Ben Dooks62acb2f82010-01-26 14:53:19 +0900313
314static struct clk clk_fout_apll = {
315 .name = "fout_apll",
Ben Dooks62acb2f82010-01-26 14:53:19 +0900316};
317
318static struct clk *clk_src_apll_list[] = {
319 [0] = &clk_fin_apll,
320 [1] = &clk_fout_apll,
321};
322
323static struct clksrc_sources clk_src_apll = {
324 .sources = clk_src_apll_list,
325 .nr_sources = ARRAY_SIZE(clk_src_apll_list),
326};
327
328static struct clksrc_clk clk_mout_apll = {
329 .clk = {
330 .name = "mout_apll",
Ben Dooks62acb2f82010-01-26 14:53:19 +0900331 },
332 .reg_src = { .reg = S3C_CLK_SRC, .shift = 0, .size = 1 },
333 .sources = &clk_src_apll,
334};
335
336static struct clk *clk_src_epll_list[] = {
337 [0] = &clk_fin_epll,
338 [1] = &clk_fout_epll,
339};
340
341static struct clksrc_sources clk_src_epll = {
342 .sources = clk_src_epll_list,
343 .nr_sources = ARRAY_SIZE(clk_src_epll_list),
344};
345
346static struct clksrc_clk clk_mout_epll = {
347 .clk = {
348 .name = "mout_epll",
Ben Dooks62acb2f82010-01-26 14:53:19 +0900349 },
350 .reg_src = { .reg = S3C_CLK_SRC, .shift = 2, .size = 1 },
351 .sources = &clk_src_epll,
352};
353
354static struct clk *clk_src_mpll_list[] = {
355 [0] = &clk_fin_mpll,
356 [1] = &clk_fout_mpll,
357};
358
359static struct clksrc_sources clk_src_mpll = {
360 .sources = clk_src_mpll_list,
361 .nr_sources = ARRAY_SIZE(clk_src_mpll_list),
362};
363
364static struct clksrc_clk clk_mout_mpll = {
365 .clk = {
366 .name = "mout_mpll",
Ben Dooks62acb2f82010-01-26 14:53:19 +0900367 },
368 .reg_src = { .reg = S3C_CLK_SRC, .shift = 1, .size = 1 },
369 .sources = &clk_src_mpll,
370};
371
372static unsigned int armclk_mask;
373
374static unsigned long s3c64xx_clk_arm_get_rate(struct clk *clk)
375{
376 unsigned long rate = clk_get_rate(clk->parent);
377 u32 clkdiv;
378
379 /* divisor mask starts at bit0, so no need to shift */
380 clkdiv = __raw_readl(S3C_CLK_DIV0) & armclk_mask;
381
382 return rate / (clkdiv + 1);
383}
384
385static unsigned long s3c64xx_clk_arm_round_rate(struct clk *clk,
386 unsigned long rate)
387{
388 unsigned long parent = clk_get_rate(clk->parent);
389 u32 div;
390
391 if (parent < rate)
392 return parent;
393
394 div = (parent / rate) - 1;
395 if (div > armclk_mask)
396 div = armclk_mask;
397
398 return parent / (div + 1);
399}
400
401static int s3c64xx_clk_arm_set_rate(struct clk *clk, unsigned long rate)
402{
403 unsigned long parent = clk_get_rate(clk->parent);
404 u32 div;
405 u32 val;
406
407 if (rate < parent / (armclk_mask + 1))
408 return -EINVAL;
409
410 rate = clk_round_rate(clk, rate);
411 div = clk_get_rate(clk->parent) / rate;
412
413 val = __raw_readl(S3C_CLK_DIV0);
414 val &= ~armclk_mask;
415 val |= (div - 1);
416 __raw_writel(val, S3C_CLK_DIV0);
417
418 return 0;
419
420}
421
422static struct clk clk_arm = {
423 .name = "armclk",
Ben Dooks62acb2f82010-01-26 14:53:19 +0900424 .parent = &clk_mout_apll.clk,
425 .ops = &(struct clk_ops) {
426 .get_rate = s3c64xx_clk_arm_get_rate,
427 .set_rate = s3c64xx_clk_arm_set_rate,
428 .round_rate = s3c64xx_clk_arm_round_rate,
429 },
430};
431
432static unsigned long s3c64xx_clk_doutmpll_get_rate(struct clk *clk)
433{
434 unsigned long rate = clk_get_rate(clk->parent);
435
436 printk(KERN_DEBUG "%s: parent is %ld\n", __func__, rate);
437
438 if (__raw_readl(S3C_CLK_DIV0) & S3C6400_CLKDIV0_MPLL_MASK)
439 rate /= 2;
440
441 return rate;
442}
443
444static struct clk_ops clk_dout_ops = {
445 .get_rate = s3c64xx_clk_doutmpll_get_rate,
446};
447
448static struct clk clk_dout_mpll = {
449 .name = "dout_mpll",
Ben Dooks62acb2f82010-01-26 14:53:19 +0900450 .parent = &clk_mout_mpll.clk,
451 .ops = &clk_dout_ops,
452};
453
454static struct clk *clkset_spi_mmc_list[] = {
455 &clk_mout_epll.clk,
456 &clk_dout_mpll,
457 &clk_fin_epll,
458 &clk_27m,
459};
460
461static struct clksrc_sources clkset_spi_mmc = {
462 .sources = clkset_spi_mmc_list,
463 .nr_sources = ARRAY_SIZE(clkset_spi_mmc_list),
464};
465
466static struct clk *clkset_irda_list[] = {
467 &clk_mout_epll.clk,
468 &clk_dout_mpll,
469 NULL,
470 &clk_27m,
471};
472
473static struct clksrc_sources clkset_irda = {
474 .sources = clkset_irda_list,
475 .nr_sources = ARRAY_SIZE(clkset_irda_list),
476};
477
478static struct clk *clkset_uart_list[] = {
479 &clk_mout_epll.clk,
480 &clk_dout_mpll,
481 NULL,
482 NULL
483};
484
485static struct clksrc_sources clkset_uart = {
486 .sources = clkset_uart_list,
487 .nr_sources = ARRAY_SIZE(clkset_uart_list),
488};
489
490static struct clk *clkset_uhost_list[] = {
491 &clk_48m,
492 &clk_mout_epll.clk,
493 &clk_dout_mpll,
494 &clk_fin_epll,
495};
496
497static struct clksrc_sources clkset_uhost = {
498 .sources = clkset_uhost_list,
499 .nr_sources = ARRAY_SIZE(clkset_uhost_list),
500};
501
502/* The peripheral clocks are all controlled via clocksource followed
503 * by an optional divider and gate stage. We currently roll this into
504 * one clock which hides the intermediate clock from the mux.
505 *
506 * Note, the JPEG clock can only be an even divider...
507 *
508 * The scaler and LCD clocks depend on the S3C64XX version, and also
509 * have a common parent divisor so are not included here.
510 */
511
512/* clocks that feed other parts of the clock source tree */
513
514static struct clk clk_iis_cd0 = {
515 .name = "iis_cdclk0",
Ben Dooks62acb2f82010-01-26 14:53:19 +0900516};
517
518static struct clk clk_iis_cd1 = {
519 .name = "iis_cdclk1",
Ben Dooks62acb2f82010-01-26 14:53:19 +0900520};
521
Jassi Brarbc8eb1e2010-03-09 15:10:32 +0900522static struct clk clk_iisv4_cd = {
523 .name = "iis_cdclk_v4",
Jassi Brarbc8eb1e2010-03-09 15:10:32 +0900524};
525
Ben Dooks62acb2f82010-01-26 14:53:19 +0900526static struct clk clk_pcm_cd = {
527 .name = "pcm_cdclk",
Ben Dooks62acb2f82010-01-26 14:53:19 +0900528};
529
530static struct clk *clkset_audio0_list[] = {
531 [0] = &clk_mout_epll.clk,
532 [1] = &clk_dout_mpll,
533 [2] = &clk_fin_epll,
534 [3] = &clk_iis_cd0,
535 [4] = &clk_pcm_cd,
536};
537
538static struct clksrc_sources clkset_audio0 = {
539 .sources = clkset_audio0_list,
540 .nr_sources = ARRAY_SIZE(clkset_audio0_list),
541};
542
543static struct clk *clkset_audio1_list[] = {
544 [0] = &clk_mout_epll.clk,
545 [1] = &clk_dout_mpll,
546 [2] = &clk_fin_epll,
547 [3] = &clk_iis_cd1,
548 [4] = &clk_pcm_cd,
549};
550
551static struct clksrc_sources clkset_audio1 = {
552 .sources = clkset_audio1_list,
553 .nr_sources = ARRAY_SIZE(clkset_audio1_list),
554};
555
Jassi Brar1aede2e2010-03-09 15:10:33 +0900556static struct clk *clkset_audio2_list[] = {
557 [0] = &clk_mout_epll.clk,
558 [1] = &clk_dout_mpll,
559 [2] = &clk_fin_epll,
560 [3] = &clk_iisv4_cd,
561 [4] = &clk_pcm_cd,
562};
563
564static struct clksrc_sources clkset_audio2 = {
565 .sources = clkset_audio2_list,
566 .nr_sources = ARRAY_SIZE(clkset_audio2_list),
567};
568
Ben Dooks62acb2f82010-01-26 14:53:19 +0900569static struct clk *clkset_camif_list[] = {
570 &clk_h2,
571};
572
573static struct clksrc_sources clkset_camif = {
574 .sources = clkset_camif_list,
575 .nr_sources = ARRAY_SIZE(clkset_camif_list),
576};
577
578static struct clksrc_clk clksrcs[] = {
579 {
580 .clk = {
581 .name = "mmc_bus",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900582 .devname = "s3c-sdhci.0",
Ben Dooks62acb2f82010-01-26 14:53:19 +0900583 .ctrlbit = S3C_CLKCON_SCLK_MMC0,
584 .enable = s3c64xx_sclk_ctrl,
585 },
586 .reg_src = { .reg = S3C_CLK_SRC, .shift = 18, .size = 2 },
587 .reg_div = { .reg = S3C_CLK_DIV1, .shift = 0, .size = 4 },
588 .sources = &clkset_spi_mmc,
589 }, {
590 .clk = {
591 .name = "mmc_bus",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900592 .devname = "s3c-sdhci.1",
Ben Dooks62acb2f82010-01-26 14:53:19 +0900593 .ctrlbit = S3C_CLKCON_SCLK_MMC1,
594 .enable = s3c64xx_sclk_ctrl,
595 },
596 .reg_src = { .reg = S3C_CLK_SRC, .shift = 20, .size = 2 },
597 .reg_div = { .reg = S3C_CLK_DIV1, .shift = 4, .size = 4 },
598 .sources = &clkset_spi_mmc,
599 }, {
600 .clk = {
601 .name = "mmc_bus",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900602 .devname = "s3c-sdhci.2",
Ben Dooks62acb2f82010-01-26 14:53:19 +0900603 .ctrlbit = S3C_CLKCON_SCLK_MMC2,
604 .enable = s3c64xx_sclk_ctrl,
605 },
606 .reg_src = { .reg = S3C_CLK_SRC, .shift = 22, .size = 2 },
607 .reg_div = { .reg = S3C_CLK_DIV1, .shift = 8, .size = 4 },
608 .sources = &clkset_spi_mmc,
609 }, {
610 .clk = {
611 .name = "usb-bus-host",
Ben Dooks62acb2f82010-01-26 14:53:19 +0900612 .ctrlbit = S3C_CLKCON_SCLK_UHOST,
613 .enable = s3c64xx_sclk_ctrl,
614 },
615 .reg_src = { .reg = S3C_CLK_SRC, .shift = 5, .size = 2 },
616 .reg_div = { .reg = S3C_CLK_DIV1, .shift = 20, .size = 4 },
617 .sources = &clkset_uhost,
618 }, {
619 .clk = {
620 .name = "uclk1",
Ben Dooks62acb2f82010-01-26 14:53:19 +0900621 .ctrlbit = S3C_CLKCON_SCLK_UART,
622 .enable = s3c64xx_sclk_ctrl,
623 },
624 .reg_src = { .reg = S3C_CLK_SRC, .shift = 13, .size = 1 },
625 .reg_div = { .reg = S3C_CLK_DIV2, .shift = 16, .size = 4 },
626 .sources = &clkset_uart,
627 }, {
628/* Where does UCLK0 come from? */
629 .clk = {
630 .name = "spi-bus",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900631 .devname = "s3c64xx-spi.0",
Ben Dooks62acb2f82010-01-26 14:53:19 +0900632 .ctrlbit = S3C_CLKCON_SCLK_SPI0,
633 .enable = s3c64xx_sclk_ctrl,
634 },
635 .reg_src = { .reg = S3C_CLK_SRC, .shift = 14, .size = 2 },
636 .reg_div = { .reg = S3C_CLK_DIV2, .shift = 0, .size = 4 },
637 .sources = &clkset_spi_mmc,
638 }, {
639 .clk = {
640 .name = "spi-bus",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900641 .devname = "s3c64xx-spi.1",
Ben Dooks62acb2f82010-01-26 14:53:19 +0900642 .enable = s3c64xx_sclk_ctrl,
643 },
644 .reg_src = { .reg = S3C_CLK_SRC, .shift = 16, .size = 2 },
645 .reg_div = { .reg = S3C_CLK_DIV2, .shift = 4, .size = 4 },
646 .sources = &clkset_spi_mmc,
647 }, {
648 .clk = {
649 .name = "audio-bus",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900650 .devname = "samsung-i2s.0",
Ben Dooks62acb2f82010-01-26 14:53:19 +0900651 .ctrlbit = S3C_CLKCON_SCLK_AUDIO0,
652 .enable = s3c64xx_sclk_ctrl,
653 },
654 .reg_src = { .reg = S3C_CLK_SRC, .shift = 7, .size = 3 },
655 .reg_div = { .reg = S3C_CLK_DIV2, .shift = 8, .size = 4 },
656 .sources = &clkset_audio0,
657 }, {
658 .clk = {
659 .name = "audio-bus",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900660 .devname = "samsung-i2s.1",
Ben Dooks62acb2f82010-01-26 14:53:19 +0900661 .ctrlbit = S3C_CLKCON_SCLK_AUDIO1,
662 .enable = s3c64xx_sclk_ctrl,
663 },
664 .reg_src = { .reg = S3C_CLK_SRC, .shift = 10, .size = 3 },
665 .reg_div = { .reg = S3C_CLK_DIV2, .shift = 12, .size = 4 },
666 .sources = &clkset_audio1,
667 }, {
668 .clk = {
Jassi Brar835879a2010-03-09 15:10:34 +0900669 .name = "audio-bus",
Thomas Abraham226e85f2011-06-14 19:12:26 +0900670 .devname = "samsung-i2s.2",
Jassi Brar835879a2010-03-09 15:10:34 +0900671 .ctrlbit = S3C6410_CLKCON_SCLK_AUDIO2,
672 .enable = s3c64xx_sclk_ctrl,
673 },
674 .reg_src = { .reg = S3C6410_CLK_SRC2, .shift = 0, .size = 3 },
675 .reg_div = { .reg = S3C_CLK_DIV2, .shift = 24, .size = 4 },
676 .sources = &clkset_audio2,
677 }, {
678 .clk = {
Ben Dooks62acb2f82010-01-26 14:53:19 +0900679 .name = "irda-bus",
Ben Dooks62acb2f82010-01-26 14:53:19 +0900680 .ctrlbit = S3C_CLKCON_SCLK_IRDA,
681 .enable = s3c64xx_sclk_ctrl,
682 },
683 .reg_src = { .reg = S3C_CLK_SRC, .shift = 24, .size = 2 },
684 .reg_div = { .reg = S3C_CLK_DIV2, .shift = 20, .size = 4 },
685 .sources = &clkset_irda,
686 }, {
687 .clk = {
688 .name = "camera",
Ben Dooks62acb2f82010-01-26 14:53:19 +0900689 .ctrlbit = S3C_CLKCON_SCLK_CAM,
690 .enable = s3c64xx_sclk_ctrl,
691 },
692 .reg_div = { .reg = S3C_CLK_DIV0, .shift = 20, .size = 4 },
693 .reg_src = { .reg = NULL, .shift = 0, .size = 0 },
694 .sources = &clkset_camif,
695 },
696};
697
698/* Clock initialisation code */
699
700static struct clksrc_clk *init_parents[] = {
701 &clk_mout_apll,
702 &clk_mout_epll,
703 &clk_mout_mpll,
704};
705
706#define GET_DIV(clk, field) ((((clk) & field##_MASK) >> field##_SHIFT) + 1)
707
708void __init_or_cpufreq s3c6400_setup_clocks(void)
709{
710 struct clk *xtal_clk;
711 unsigned long xtal;
712 unsigned long fclk;
713 unsigned long hclk;
714 unsigned long hclk2;
715 unsigned long pclk;
716 unsigned long epll;
717 unsigned long apll;
718 unsigned long mpll;
719 unsigned int ptr;
720 u32 clkdiv0;
721
722 printk(KERN_DEBUG "%s: registering clocks\n", __func__);
723
724 clkdiv0 = __raw_readl(S3C_CLK_DIV0);
725 printk(KERN_DEBUG "%s: clkdiv0 = %08x\n", __func__, clkdiv0);
726
727 xtal_clk = clk_get(NULL, "xtal");
728 BUG_ON(IS_ERR(xtal_clk));
729
730 xtal = clk_get_rate(xtal_clk);
731 clk_put(xtal_clk);
732
733 printk(KERN_DEBUG "%s: xtal is %ld\n", __func__, xtal);
734
735 /* For now assume the mux always selects the crystal */
736 clk_ext_xtal_mux.parent = xtal_clk;
737
738 epll = s3c6400_get_epll(xtal);
739 mpll = s3c6400_get_pll(xtal, __raw_readl(S3C_MPLL_CON));
740 apll = s3c6400_get_pll(xtal, __raw_readl(S3C_APLL_CON));
741
742 fclk = mpll;
743
744 printk(KERN_INFO "S3C64XX: PLL settings, A=%ld, M=%ld, E=%ld\n",
745 apll, mpll, epll);
746
Tomasz Figafb5d3752011-08-19 11:54:31 +0200747 if(__raw_readl(S3C64XX_OTHERS) & S3C64XX_OTHERS_SYNCMUXSEL)
748 /* Synchronous mode */
749 hclk2 = apll / GET_DIV(clkdiv0, S3C6400_CLKDIV0_HCLK2);
750 else
751 /* Asynchronous mode */
752 hclk2 = mpll / GET_DIV(clkdiv0, S3C6400_CLKDIV0_HCLK2);
753
Ben Dooks62acb2f82010-01-26 14:53:19 +0900754 hclk = hclk2 / GET_DIV(clkdiv0, S3C6400_CLKDIV0_HCLK);
755 pclk = hclk2 / GET_DIV(clkdiv0, S3C6400_CLKDIV0_PCLK);
756
757 printk(KERN_INFO "S3C64XX: HCLK2=%ld, HCLK=%ld, PCLK=%ld\n",
758 hclk2, hclk, pclk);
759
760 clk_fout_mpll.rate = mpll;
761 clk_fout_epll.rate = epll;
762 clk_fout_apll.rate = apll;
763
764 clk_h2.rate = hclk2;
765 clk_h.rate = hclk;
766 clk_p.rate = pclk;
767 clk_f.rate = fclk;
768
769 for (ptr = 0; ptr < ARRAY_SIZE(init_parents); ptr++)
770 s3c_set_clksrc(init_parents[ptr], true);
771
772 for (ptr = 0; ptr < ARRAY_SIZE(clksrcs); ptr++)
773 s3c_set_clksrc(&clksrcs[ptr], true);
774}
775
776static struct clk *clks1[] __initdata = {
777 &clk_ext_xtal_mux,
778 &clk_iis_cd0,
779 &clk_iis_cd1,
Jassi Brarbc8eb1e2010-03-09 15:10:32 +0900780 &clk_iisv4_cd,
Ben Dooks62acb2f82010-01-26 14:53:19 +0900781 &clk_pcm_cd,
782 &clk_mout_epll.clk,
783 &clk_mout_mpll.clk,
784 &clk_dout_mpll,
785 &clk_arm,
786};
787
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100788static struct clk *clks[] __initdata = {
789 &clk_ext,
790 &clk_epll,
791 &clk_27m,
792 &clk_48m,
Werner Almesbergera03f7da2009-03-05 11:43:13 +0800793 &clk_h2,
Maurus Cuelenaere05e021f2010-05-17 20:17:42 +0200794 &clk_xusbxti,
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100795};
796
Ben Dooks55bf9262010-01-26 15:10:38 +0900797/**
798 * s3c64xx_register_clocks - register clocks for s3c6400 and s3c6410
799 * @xtal: The rate for the clock crystal feeding the PLLs.
800 * @armclk_divlimit: Divisor mask for ARMCLK.
801 *
802 * Register the clocks for the S3C6400 and S3C6410 SoC range, such
803 * as ARMCLK as well as the necessary parent clocks.
804 *
805 * This call does not setup the clocks, which is left to the
806 * s3c6400_setup_clocks() call which may be needed by the cpufreq
807 * or resume code to re-set the clocks if the bootloader has changed
808 * them.
809 */
810void __init s3c64xx_register_clocks(unsigned long xtal,
811 unsigned armclk_divlimit)
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100812{
Ben Dooks55bf9262010-01-26 15:10:38 +0900813 armclk_mask = armclk_divlimit;
814
815 s3c24xx_register_baseclocks(xtal);
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100816 s3c24xx_register_clocks(clks, ARRAY_SIZE(clks));
Ben Dooks55bf9262010-01-26 15:10:38 +0900817
Ben Dooks1d9f13c2010-01-06 01:21:38 +0900818 s3c_register_clocks(init_clocks, ARRAY_SIZE(init_clocks));
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100819
Kukjin Kimcdb216d2011-01-04 18:27:18 +0900820 s3c_register_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
821 s3c_disable_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
Ben Dooks9d325f22008-11-21 10:36:05 +0000822
Ben Dooks55bf9262010-01-26 15:10:38 +0900823 s3c24xx_register_clocks(clks1, ARRAY_SIZE(clks1));
824 s3c_register_clksrc(clksrcs, ARRAY_SIZE(clksrcs));
Ben Dooks9d325f22008-11-21 10:36:05 +0000825 s3c_pwmclk_init();
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100826}