blob: 7772f92d29050915261ec07770af9b4863a02c2b [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 Dooks62acb2f2010-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 Dooks62acb2f2010-01-26 14:53:19 +090032#include <plat/cpu-freq.h>
Ben Dooks4b31d8b2008-10-21 14:07:00 +010033#include <plat/clock.h>
Ben Dooks62acb2f2010-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",
42 .id = -1,
43};
44
45#define clk_fin_apll clk_ext_xtal_mux
46#define clk_fin_mpll clk_ext_xtal_mux
47#define clk_fin_epll clk_ext_xtal_mux
48
49#define clk_fout_mpll clk_mpll
50#define clk_fout_epll clk_epll
Ben Dooks4b31d8b2008-10-21 14:07:00 +010051
Werner Almesbergera03f7da2009-03-05 11:43:13 +080052struct clk clk_h2 = {
53 .name = "hclk2",
54 .id = -1,
55 .rate = 0,
56};
57
Ben Dooks4b31d8b2008-10-21 14:07:00 +010058struct clk clk_27m = {
59 .name = "clk_27m",
60 .id = -1,
61 .rate = 27000000,
62};
63
Ben Dooks3627379f2008-10-31 16:14:36 +000064static int clk_48m_ctrl(struct clk *clk, int enable)
65{
66 unsigned long flags;
67 u32 val;
68
69 /* can't rely on clock lock, this register has other usages */
70 local_irq_save(flags);
71
72 val = __raw_readl(S3C64XX_OTHERS);
73 if (enable)
74 val |= S3C64XX_OTHERS_USBMASK;
75 else
76 val &= ~S3C64XX_OTHERS_USBMASK;
77
78 __raw_writel(val, S3C64XX_OTHERS);
79 local_irq_restore(flags);
80
81 return 0;
82}
83
Ben Dooks4b31d8b2008-10-21 14:07:00 +010084struct clk clk_48m = {
85 .name = "clk_48m",
86 .id = -1,
87 .rate = 48000000,
Ben Dooks3627379f2008-10-31 16:14:36 +000088 .enable = clk_48m_ctrl,
Ben Dooks4b31d8b2008-10-21 14:07:00 +010089};
90
Maurus Cuelenaere05e021f2010-05-17 20:17:42 +020091struct clk clk_xusbxti = {
92 .name = "xusbxti",
93 .id = -1,
94 .rate = 48000000,
95};
96
Ben Dooks4b31d8b2008-10-21 14:07:00 +010097static int inline s3c64xx_gate(void __iomem *reg,
98 struct clk *clk,
99 int enable)
100{
101 unsigned int ctrlbit = clk->ctrlbit;
102 u32 con;
103
104 con = __raw_readl(reg);
105
106 if (enable)
107 con |= ctrlbit;
108 else
109 con &= ~ctrlbit;
110
111 __raw_writel(con, reg);
112 return 0;
113}
114
115static int s3c64xx_pclk_ctrl(struct clk *clk, int enable)
116{
117 return s3c64xx_gate(S3C_PCLK_GATE, clk, enable);
118}
119
120static int s3c64xx_hclk_ctrl(struct clk *clk, int enable)
121{
122 return s3c64xx_gate(S3C_HCLK_GATE, clk, enable);
123}
124
Ben Dookscf18acf2008-10-21 14:07:02 +0100125int s3c64xx_sclk_ctrl(struct clk *clk, int enable)
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100126{
127 return s3c64xx_gate(S3C_SCLK_GATE, clk, enable);
128}
129
130static struct clk init_clocks_disable[] = {
131 {
132 .name = "nand",
133 .id = -1,
134 .parent = &clk_h,
135 }, {
136 .name = "adc",
137 .id = -1,
138 .parent = &clk_p,
139 .enable = s3c64xx_pclk_ctrl,
140 .ctrlbit = S3C_CLKCON_PCLK_TSADC,
141 }, {
142 .name = "i2c",
143 .id = -1,
144 .parent = &clk_p,
145 .enable = s3c64xx_pclk_ctrl,
146 .ctrlbit = S3C_CLKCON_PCLK_IIC,
147 }, {
148 .name = "iis",
149 .id = 0,
150 .parent = &clk_p,
151 .enable = s3c64xx_pclk_ctrl,
152 .ctrlbit = S3C_CLKCON_PCLK_IIS0,
153 }, {
154 .name = "iis",
155 .id = 1,
156 .parent = &clk_p,
157 .enable = s3c64xx_pclk_ctrl,
158 .ctrlbit = S3C_CLKCON_PCLK_IIS1,
159 }, {
Jassi Brar2e5070b2010-02-17 19:03:19 +0000160#ifdef CONFIG_CPU_S3C6410
161 .name = "iis",
162 .id = -1, /* There's only one IISv4 port */
163 .parent = &clk_p,
164 .enable = s3c64xx_pclk_ctrl,
165 .ctrlbit = S3C6410_CLKCON_PCLK_IIS2,
166 }, {
167#endif
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100168 .name = "spi",
169 .id = 0,
170 .parent = &clk_p,
171 .enable = s3c64xx_pclk_ctrl,
172 .ctrlbit = S3C_CLKCON_PCLK_SPI0,
173 }, {
174 .name = "spi",
175 .id = 1,
176 .parent = &clk_p,
177 .enable = s3c64xx_pclk_ctrl,
178 .ctrlbit = S3C_CLKCON_PCLK_SPI1,
179 }, {
Jassi Brar87315a82010-01-18 16:15:08 +0900180 .name = "spi_48m",
181 .id = 0,
182 .parent = &clk_48m,
183 .enable = s3c64xx_sclk_ctrl,
184 .ctrlbit = S3C_CLKCON_SCLK_SPI0_48,
185 }, {
186 .name = "spi_48m",
187 .id = 1,
188 .parent = &clk_48m,
189 .enable = s3c64xx_sclk_ctrl,
190 .ctrlbit = S3C_CLKCON_SCLK_SPI1_48,
191 }, {
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100192 .name = "48m",
193 .id = 0,
194 .parent = &clk_48m,
195 .enable = s3c64xx_sclk_ctrl,
196 .ctrlbit = S3C_CLKCON_SCLK_MMC0_48,
197 }, {
198 .name = "48m",
199 .id = 1,
200 .parent = &clk_48m,
201 .enable = s3c64xx_sclk_ctrl,
202 .ctrlbit = S3C_CLKCON_SCLK_MMC1_48,
203 }, {
204 .name = "48m",
205 .id = 2,
206 .parent = &clk_48m,
207 .enable = s3c64xx_sclk_ctrl,
208 .ctrlbit = S3C_CLKCON_SCLK_MMC2_48,
Mark Brown8f1ecf12009-04-28 16:06:24 +0100209 }, {
210 .name = "dma0",
211 .id = -1,
212 .parent = &clk_h,
213 .enable = s3c64xx_hclk_ctrl,
214 .ctrlbit = S3C_CLKCON_HCLK_DMA0,
215 }, {
216 .name = "dma1",
217 .id = -1,
218 .parent = &clk_h,
219 .enable = s3c64xx_hclk_ctrl,
220 .ctrlbit = S3C_CLKCON_HCLK_DMA1,
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100221 },
222};
223
224static struct clk init_clocks[] = {
225 {
226 .name = "lcd",
227 .id = -1,
228 .parent = &clk_h,
229 .enable = s3c64xx_hclk_ctrl,
230 .ctrlbit = S3C_CLKCON_HCLK_LCD,
231 }, {
232 .name = "gpio",
233 .id = -1,
234 .parent = &clk_p,
235 .enable = s3c64xx_pclk_ctrl,
236 .ctrlbit = S3C_CLKCON_PCLK_GPIO,
237 }, {
238 .name = "usb-host",
239 .id = -1,
240 .parent = &clk_h,
241 .enable = s3c64xx_hclk_ctrl,
Peter Korsgaard386f4352009-06-18 23:54:44 +0200242 .ctrlbit = S3C_CLKCON_HCLK_UHOST,
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100243 }, {
244 .name = "hsmmc",
245 .id = 0,
246 .parent = &clk_h,
247 .enable = s3c64xx_hclk_ctrl,
248 .ctrlbit = S3C_CLKCON_HCLK_HSMMC0,
249 }, {
250 .name = "hsmmc",
251 .id = 1,
252 .parent = &clk_h,
253 .enable = s3c64xx_hclk_ctrl,
254 .ctrlbit = S3C_CLKCON_HCLK_HSMMC1,
255 }, {
256 .name = "hsmmc",
257 .id = 2,
258 .parent = &clk_h,
259 .enable = s3c64xx_hclk_ctrl,
260 .ctrlbit = S3C_CLKCON_HCLK_HSMMC2,
261 }, {
Thomas Abraham5f4c5b22010-05-28 11:41:14 +0900262 .name = "otg",
263 .id = -1,
264 .parent = &clk_h,
265 .enable = s3c64xx_hclk_ctrl,
266 .ctrlbit = S3C_CLKCON_HCLK_USB,
267 }, {
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100268 .name = "timers",
269 .id = -1,
270 .parent = &clk_p,
271 .enable = s3c64xx_pclk_ctrl,
272 .ctrlbit = S3C_CLKCON_PCLK_PWM,
273 }, {
274 .name = "uart",
275 .id = 0,
276 .parent = &clk_p,
277 .enable = s3c64xx_pclk_ctrl,
278 .ctrlbit = S3C_CLKCON_PCLK_UART0,
279 }, {
280 .name = "uart",
281 .id = 1,
282 .parent = &clk_p,
283 .enable = s3c64xx_pclk_ctrl,
284 .ctrlbit = S3C_CLKCON_PCLK_UART1,
285 }, {
286 .name = "uart",
287 .id = 2,
288 .parent = &clk_p,
289 .enable = s3c64xx_pclk_ctrl,
290 .ctrlbit = S3C_CLKCON_PCLK_UART2,
291 }, {
292 .name = "uart",
293 .id = 3,
294 .parent = &clk_p,
295 .enable = s3c64xx_pclk_ctrl,
296 .ctrlbit = S3C_CLKCON_PCLK_UART3,
297 }, {
298 .name = "rtc",
299 .id = -1,
300 .parent = &clk_p,
301 .enable = s3c64xx_pclk_ctrl,
302 .ctrlbit = S3C_CLKCON_PCLK_RTC,
303 }, {
304 .name = "watchdog",
305 .id = -1,
306 .parent = &clk_p,
307 .ctrlbit = S3C_CLKCON_PCLK_WDT,
308 }, {
309 .name = "ac97",
310 .id = -1,
311 .parent = &clk_p,
312 .ctrlbit = S3C_CLKCON_PCLK_AC97,
Abhilash Kesavan0ab0b6d2010-06-08 16:55:45 +0900313 }, {
314 .name = "cfcon",
315 .id = -1,
316 .parent = &clk_h,
317 .enable = s3c64xx_hclk_ctrl,
318 .ctrlbit = S3C_CLKCON_HCLK_IHOST,
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100319 }
320};
321
Ben Dooks62acb2f2010-01-26 14:53:19 +0900322
323static struct clk clk_fout_apll = {
324 .name = "fout_apll",
325 .id = -1,
326};
327
328static struct clk *clk_src_apll_list[] = {
329 [0] = &clk_fin_apll,
330 [1] = &clk_fout_apll,
331};
332
333static struct clksrc_sources clk_src_apll = {
334 .sources = clk_src_apll_list,
335 .nr_sources = ARRAY_SIZE(clk_src_apll_list),
336};
337
338static struct clksrc_clk clk_mout_apll = {
339 .clk = {
340 .name = "mout_apll",
341 .id = -1,
342 },
343 .reg_src = { .reg = S3C_CLK_SRC, .shift = 0, .size = 1 },
344 .sources = &clk_src_apll,
345};
346
347static struct clk *clk_src_epll_list[] = {
348 [0] = &clk_fin_epll,
349 [1] = &clk_fout_epll,
350};
351
352static struct clksrc_sources clk_src_epll = {
353 .sources = clk_src_epll_list,
354 .nr_sources = ARRAY_SIZE(clk_src_epll_list),
355};
356
357static struct clksrc_clk clk_mout_epll = {
358 .clk = {
359 .name = "mout_epll",
360 .id = -1,
361 },
362 .reg_src = { .reg = S3C_CLK_SRC, .shift = 2, .size = 1 },
363 .sources = &clk_src_epll,
364};
365
366static struct clk *clk_src_mpll_list[] = {
367 [0] = &clk_fin_mpll,
368 [1] = &clk_fout_mpll,
369};
370
371static struct clksrc_sources clk_src_mpll = {
372 .sources = clk_src_mpll_list,
373 .nr_sources = ARRAY_SIZE(clk_src_mpll_list),
374};
375
376static struct clksrc_clk clk_mout_mpll = {
377 .clk = {
378 .name = "mout_mpll",
379 .id = -1,
380 },
381 .reg_src = { .reg = S3C_CLK_SRC, .shift = 1, .size = 1 },
382 .sources = &clk_src_mpll,
383};
384
385static unsigned int armclk_mask;
386
387static unsigned long s3c64xx_clk_arm_get_rate(struct clk *clk)
388{
389 unsigned long rate = clk_get_rate(clk->parent);
390 u32 clkdiv;
391
392 /* divisor mask starts at bit0, so no need to shift */
393 clkdiv = __raw_readl(S3C_CLK_DIV0) & armclk_mask;
394
395 return rate / (clkdiv + 1);
396}
397
398static unsigned long s3c64xx_clk_arm_round_rate(struct clk *clk,
399 unsigned long rate)
400{
401 unsigned long parent = clk_get_rate(clk->parent);
402 u32 div;
403
404 if (parent < rate)
405 return parent;
406
407 div = (parent / rate) - 1;
408 if (div > armclk_mask)
409 div = armclk_mask;
410
411 return parent / (div + 1);
412}
413
414static int s3c64xx_clk_arm_set_rate(struct clk *clk, unsigned long rate)
415{
416 unsigned long parent = clk_get_rate(clk->parent);
417 u32 div;
418 u32 val;
419
420 if (rate < parent / (armclk_mask + 1))
421 return -EINVAL;
422
423 rate = clk_round_rate(clk, rate);
424 div = clk_get_rate(clk->parent) / rate;
425
426 val = __raw_readl(S3C_CLK_DIV0);
427 val &= ~armclk_mask;
428 val |= (div - 1);
429 __raw_writel(val, S3C_CLK_DIV0);
430
431 return 0;
432
433}
434
435static struct clk clk_arm = {
436 .name = "armclk",
437 .id = -1,
438 .parent = &clk_mout_apll.clk,
439 .ops = &(struct clk_ops) {
440 .get_rate = s3c64xx_clk_arm_get_rate,
441 .set_rate = s3c64xx_clk_arm_set_rate,
442 .round_rate = s3c64xx_clk_arm_round_rate,
443 },
444};
445
446static unsigned long s3c64xx_clk_doutmpll_get_rate(struct clk *clk)
447{
448 unsigned long rate = clk_get_rate(clk->parent);
449
450 printk(KERN_DEBUG "%s: parent is %ld\n", __func__, rate);
451
452 if (__raw_readl(S3C_CLK_DIV0) & S3C6400_CLKDIV0_MPLL_MASK)
453 rate /= 2;
454
455 return rate;
456}
457
458static struct clk_ops clk_dout_ops = {
459 .get_rate = s3c64xx_clk_doutmpll_get_rate,
460};
461
462static struct clk clk_dout_mpll = {
463 .name = "dout_mpll",
464 .id = -1,
465 .parent = &clk_mout_mpll.clk,
466 .ops = &clk_dout_ops,
467};
468
469static struct clk *clkset_spi_mmc_list[] = {
470 &clk_mout_epll.clk,
471 &clk_dout_mpll,
472 &clk_fin_epll,
473 &clk_27m,
474};
475
476static struct clksrc_sources clkset_spi_mmc = {
477 .sources = clkset_spi_mmc_list,
478 .nr_sources = ARRAY_SIZE(clkset_spi_mmc_list),
479};
480
481static struct clk *clkset_irda_list[] = {
482 &clk_mout_epll.clk,
483 &clk_dout_mpll,
484 NULL,
485 &clk_27m,
486};
487
488static struct clksrc_sources clkset_irda = {
489 .sources = clkset_irda_list,
490 .nr_sources = ARRAY_SIZE(clkset_irda_list),
491};
492
493static struct clk *clkset_uart_list[] = {
494 &clk_mout_epll.clk,
495 &clk_dout_mpll,
496 NULL,
497 NULL
498};
499
500static struct clksrc_sources clkset_uart = {
501 .sources = clkset_uart_list,
502 .nr_sources = ARRAY_SIZE(clkset_uart_list),
503};
504
505static struct clk *clkset_uhost_list[] = {
506 &clk_48m,
507 &clk_mout_epll.clk,
508 &clk_dout_mpll,
509 &clk_fin_epll,
510};
511
512static struct clksrc_sources clkset_uhost = {
513 .sources = clkset_uhost_list,
514 .nr_sources = ARRAY_SIZE(clkset_uhost_list),
515};
516
517/* The peripheral clocks are all controlled via clocksource followed
518 * by an optional divider and gate stage. We currently roll this into
519 * one clock which hides the intermediate clock from the mux.
520 *
521 * Note, the JPEG clock can only be an even divider...
522 *
523 * The scaler and LCD clocks depend on the S3C64XX version, and also
524 * have a common parent divisor so are not included here.
525 */
526
527/* clocks that feed other parts of the clock source tree */
528
529static struct clk clk_iis_cd0 = {
530 .name = "iis_cdclk0",
531 .id = -1,
532};
533
534static struct clk clk_iis_cd1 = {
535 .name = "iis_cdclk1",
536 .id = -1,
537};
538
Jassi Brarbc8eb1e2010-03-09 15:10:32 +0900539static struct clk clk_iisv4_cd = {
540 .name = "iis_cdclk_v4",
541 .id = -1,
542};
543
Ben Dooks62acb2f2010-01-26 14:53:19 +0900544static struct clk clk_pcm_cd = {
545 .name = "pcm_cdclk",
546 .id = -1,
547};
548
549static struct clk *clkset_audio0_list[] = {
550 [0] = &clk_mout_epll.clk,
551 [1] = &clk_dout_mpll,
552 [2] = &clk_fin_epll,
553 [3] = &clk_iis_cd0,
554 [4] = &clk_pcm_cd,
555};
556
557static struct clksrc_sources clkset_audio0 = {
558 .sources = clkset_audio0_list,
559 .nr_sources = ARRAY_SIZE(clkset_audio0_list),
560};
561
562static struct clk *clkset_audio1_list[] = {
563 [0] = &clk_mout_epll.clk,
564 [1] = &clk_dout_mpll,
565 [2] = &clk_fin_epll,
566 [3] = &clk_iis_cd1,
567 [4] = &clk_pcm_cd,
568};
569
570static struct clksrc_sources clkset_audio1 = {
571 .sources = clkset_audio1_list,
572 .nr_sources = ARRAY_SIZE(clkset_audio1_list),
573};
574
Jassi Brar1aede2e2010-03-09 15:10:33 +0900575static struct clk *clkset_audio2_list[] = {
576 [0] = &clk_mout_epll.clk,
577 [1] = &clk_dout_mpll,
578 [2] = &clk_fin_epll,
579 [3] = &clk_iisv4_cd,
580 [4] = &clk_pcm_cd,
581};
582
583static struct clksrc_sources clkset_audio2 = {
584 .sources = clkset_audio2_list,
585 .nr_sources = ARRAY_SIZE(clkset_audio2_list),
586};
587
Ben Dooks62acb2f2010-01-26 14:53:19 +0900588static struct clk *clkset_camif_list[] = {
589 &clk_h2,
590};
591
592static struct clksrc_sources clkset_camif = {
593 .sources = clkset_camif_list,
594 .nr_sources = ARRAY_SIZE(clkset_camif_list),
595};
596
597static struct clksrc_clk clksrcs[] = {
598 {
599 .clk = {
600 .name = "mmc_bus",
601 .id = 0,
602 .ctrlbit = S3C_CLKCON_SCLK_MMC0,
603 .enable = s3c64xx_sclk_ctrl,
604 },
605 .reg_src = { .reg = S3C_CLK_SRC, .shift = 18, .size = 2 },
606 .reg_div = { .reg = S3C_CLK_DIV1, .shift = 0, .size = 4 },
607 .sources = &clkset_spi_mmc,
608 }, {
609 .clk = {
610 .name = "mmc_bus",
611 .id = 1,
612 .ctrlbit = S3C_CLKCON_SCLK_MMC1,
613 .enable = s3c64xx_sclk_ctrl,
614 },
615 .reg_src = { .reg = S3C_CLK_SRC, .shift = 20, .size = 2 },
616 .reg_div = { .reg = S3C_CLK_DIV1, .shift = 4, .size = 4 },
617 .sources = &clkset_spi_mmc,
618 }, {
619 .clk = {
620 .name = "mmc_bus",
621 .id = 2,
622 .ctrlbit = S3C_CLKCON_SCLK_MMC2,
623 .enable = s3c64xx_sclk_ctrl,
624 },
625 .reg_src = { .reg = S3C_CLK_SRC, .shift = 22, .size = 2 },
626 .reg_div = { .reg = S3C_CLK_DIV1, .shift = 8, .size = 4 },
627 .sources = &clkset_spi_mmc,
628 }, {
629 .clk = {
630 .name = "usb-bus-host",
631 .id = -1,
632 .ctrlbit = S3C_CLKCON_SCLK_UHOST,
633 .enable = s3c64xx_sclk_ctrl,
634 },
635 .reg_src = { .reg = S3C_CLK_SRC, .shift = 5, .size = 2 },
636 .reg_div = { .reg = S3C_CLK_DIV1, .shift = 20, .size = 4 },
637 .sources = &clkset_uhost,
638 }, {
639 .clk = {
640 .name = "uclk1",
641 .id = -1,
642 .ctrlbit = S3C_CLKCON_SCLK_UART,
643 .enable = s3c64xx_sclk_ctrl,
644 },
645 .reg_src = { .reg = S3C_CLK_SRC, .shift = 13, .size = 1 },
646 .reg_div = { .reg = S3C_CLK_DIV2, .shift = 16, .size = 4 },
647 .sources = &clkset_uart,
648 }, {
649/* Where does UCLK0 come from? */
650 .clk = {
651 .name = "spi-bus",
652 .id = 0,
653 .ctrlbit = S3C_CLKCON_SCLK_SPI0,
654 .enable = s3c64xx_sclk_ctrl,
655 },
656 .reg_src = { .reg = S3C_CLK_SRC, .shift = 14, .size = 2 },
657 .reg_div = { .reg = S3C_CLK_DIV2, .shift = 0, .size = 4 },
658 .sources = &clkset_spi_mmc,
659 }, {
660 .clk = {
661 .name = "spi-bus",
662 .id = 1,
663 .ctrlbit = S3C_CLKCON_SCLK_SPI1,
664 .enable = s3c64xx_sclk_ctrl,
665 },
666 .reg_src = { .reg = S3C_CLK_SRC, .shift = 16, .size = 2 },
667 .reg_div = { .reg = S3C_CLK_DIV2, .shift = 4, .size = 4 },
668 .sources = &clkset_spi_mmc,
669 }, {
670 .clk = {
671 .name = "audio-bus",
672 .id = 0,
673 .ctrlbit = S3C_CLKCON_SCLK_AUDIO0,
674 .enable = s3c64xx_sclk_ctrl,
675 },
676 .reg_src = { .reg = S3C_CLK_SRC, .shift = 7, .size = 3 },
677 .reg_div = { .reg = S3C_CLK_DIV2, .shift = 8, .size = 4 },
678 .sources = &clkset_audio0,
679 }, {
680 .clk = {
681 .name = "audio-bus",
682 .id = 1,
683 .ctrlbit = S3C_CLKCON_SCLK_AUDIO1,
684 .enable = s3c64xx_sclk_ctrl,
685 },
686 .reg_src = { .reg = S3C_CLK_SRC, .shift = 10, .size = 3 },
687 .reg_div = { .reg = S3C_CLK_DIV2, .shift = 12, .size = 4 },
688 .sources = &clkset_audio1,
689 }, {
690 .clk = {
Jassi Brar835879a2010-03-09 15:10:34 +0900691 .name = "audio-bus",
692 .id = -1, /* There's only one IISv4 port */
693 .ctrlbit = S3C6410_CLKCON_SCLK_AUDIO2,
694 .enable = s3c64xx_sclk_ctrl,
695 },
696 .reg_src = { .reg = S3C6410_CLK_SRC2, .shift = 0, .size = 3 },
697 .reg_div = { .reg = S3C_CLK_DIV2, .shift = 24, .size = 4 },
698 .sources = &clkset_audio2,
699 }, {
700 .clk = {
Ben Dooks62acb2f2010-01-26 14:53:19 +0900701 .name = "irda-bus",
702 .id = 0,
703 .ctrlbit = S3C_CLKCON_SCLK_IRDA,
704 .enable = s3c64xx_sclk_ctrl,
705 },
706 .reg_src = { .reg = S3C_CLK_SRC, .shift = 24, .size = 2 },
707 .reg_div = { .reg = S3C_CLK_DIV2, .shift = 20, .size = 4 },
708 .sources = &clkset_irda,
709 }, {
710 .clk = {
711 .name = "camera",
712 .id = -1,
713 .ctrlbit = S3C_CLKCON_SCLK_CAM,
714 .enable = s3c64xx_sclk_ctrl,
715 },
716 .reg_div = { .reg = S3C_CLK_DIV0, .shift = 20, .size = 4 },
717 .reg_src = { .reg = NULL, .shift = 0, .size = 0 },
718 .sources = &clkset_camif,
719 },
720};
721
722/* Clock initialisation code */
723
724static struct clksrc_clk *init_parents[] = {
725 &clk_mout_apll,
726 &clk_mout_epll,
727 &clk_mout_mpll,
728};
729
730#define GET_DIV(clk, field) ((((clk) & field##_MASK) >> field##_SHIFT) + 1)
731
732void __init_or_cpufreq s3c6400_setup_clocks(void)
733{
734 struct clk *xtal_clk;
735 unsigned long xtal;
736 unsigned long fclk;
737 unsigned long hclk;
738 unsigned long hclk2;
739 unsigned long pclk;
740 unsigned long epll;
741 unsigned long apll;
742 unsigned long mpll;
743 unsigned int ptr;
744 u32 clkdiv0;
745
746 printk(KERN_DEBUG "%s: registering clocks\n", __func__);
747
748 clkdiv0 = __raw_readl(S3C_CLK_DIV0);
749 printk(KERN_DEBUG "%s: clkdiv0 = %08x\n", __func__, clkdiv0);
750
751 xtal_clk = clk_get(NULL, "xtal");
752 BUG_ON(IS_ERR(xtal_clk));
753
754 xtal = clk_get_rate(xtal_clk);
755 clk_put(xtal_clk);
756
757 printk(KERN_DEBUG "%s: xtal is %ld\n", __func__, xtal);
758
759 /* For now assume the mux always selects the crystal */
760 clk_ext_xtal_mux.parent = xtal_clk;
761
762 epll = s3c6400_get_epll(xtal);
763 mpll = s3c6400_get_pll(xtal, __raw_readl(S3C_MPLL_CON));
764 apll = s3c6400_get_pll(xtal, __raw_readl(S3C_APLL_CON));
765
766 fclk = mpll;
767
768 printk(KERN_INFO "S3C64XX: PLL settings, A=%ld, M=%ld, E=%ld\n",
769 apll, mpll, epll);
770
771 hclk2 = mpll / GET_DIV(clkdiv0, S3C6400_CLKDIV0_HCLK2);
772 hclk = hclk2 / GET_DIV(clkdiv0, S3C6400_CLKDIV0_HCLK);
773 pclk = hclk2 / GET_DIV(clkdiv0, S3C6400_CLKDIV0_PCLK);
774
775 printk(KERN_INFO "S3C64XX: HCLK2=%ld, HCLK=%ld, PCLK=%ld\n",
776 hclk2, hclk, pclk);
777
778 clk_fout_mpll.rate = mpll;
779 clk_fout_epll.rate = epll;
780 clk_fout_apll.rate = apll;
781
782 clk_h2.rate = hclk2;
783 clk_h.rate = hclk;
784 clk_p.rate = pclk;
785 clk_f.rate = fclk;
786
787 for (ptr = 0; ptr < ARRAY_SIZE(init_parents); ptr++)
788 s3c_set_clksrc(init_parents[ptr], true);
789
790 for (ptr = 0; ptr < ARRAY_SIZE(clksrcs); ptr++)
791 s3c_set_clksrc(&clksrcs[ptr], true);
792}
793
794static struct clk *clks1[] __initdata = {
795 &clk_ext_xtal_mux,
796 &clk_iis_cd0,
797 &clk_iis_cd1,
Jassi Brarbc8eb1e2010-03-09 15:10:32 +0900798 &clk_iisv4_cd,
Ben Dooks62acb2f2010-01-26 14:53:19 +0900799 &clk_pcm_cd,
800 &clk_mout_epll.clk,
801 &clk_mout_mpll.clk,
802 &clk_dout_mpll,
803 &clk_arm,
804};
805
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100806static struct clk *clks[] __initdata = {
807 &clk_ext,
808 &clk_epll,
809 &clk_27m,
810 &clk_48m,
Werner Almesbergera03f7da2009-03-05 11:43:13 +0800811 &clk_h2,
Maurus Cuelenaere05e021f2010-05-17 20:17:42 +0200812 &clk_xusbxti,
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100813};
814
Ben Dooks55bf9262010-01-26 15:10:38 +0900815/**
816 * s3c64xx_register_clocks - register clocks for s3c6400 and s3c6410
817 * @xtal: The rate for the clock crystal feeding the PLLs.
818 * @armclk_divlimit: Divisor mask for ARMCLK.
819 *
820 * Register the clocks for the S3C6400 and S3C6410 SoC range, such
821 * as ARMCLK as well as the necessary parent clocks.
822 *
823 * This call does not setup the clocks, which is left to the
824 * s3c6400_setup_clocks() call which may be needed by the cpufreq
825 * or resume code to re-set the clocks if the bootloader has changed
826 * them.
827 */
828void __init s3c64xx_register_clocks(unsigned long xtal,
829 unsigned armclk_divlimit)
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100830{
831 struct clk *clkp;
832 int ret;
833 int ptr;
834
Ben Dooks55bf9262010-01-26 15:10:38 +0900835 armclk_mask = armclk_divlimit;
836
837 s3c24xx_register_baseclocks(xtal);
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100838 s3c24xx_register_clocks(clks, ARRAY_SIZE(clks));
Ben Dooks55bf9262010-01-26 15:10:38 +0900839
Ben Dooks1d9f13c2010-01-06 01:21:38 +0900840 s3c_register_clocks(init_clocks, ARRAY_SIZE(init_clocks));
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100841
842 clkp = init_clocks_disable;
843 for (ptr = 0; ptr < ARRAY_SIZE(init_clocks_disable); ptr++, clkp++) {
844
845 ret = s3c24xx_register_clock(clkp);
846 if (ret < 0) {
847 printk(KERN_ERR "Failed to register clock %s (%d)\n",
848 clkp->name, ret);
849 }
850
851 (clkp->enable)(clkp, 0);
852 }
Ben Dooks9d325f22008-11-21 10:36:05 +0000853
Ben Dooks55bf9262010-01-26 15:10:38 +0900854 s3c24xx_register_clocks(clks1, ARRAY_SIZE(clks1));
855 s3c_register_clksrc(clksrcs, ARRAY_SIZE(clksrcs));
Ben Dooks9d325f22008-11-21 10:36:05 +0000856 s3c_pwmclk_init();
Ben Dooks4b31d8b2008-10-21 14:07:00 +0100857}