blob: 6fde910e414cf0c9cb4106b3338a51fd041a01a1 [file] [log] [blame]
Ben Dookscf18acf2008-10-21 14:07:02 +01001/* linux/arch/arm/plat-s3c64xx/s3c6400-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 * S3C6400 based common 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/kernel.h>
18#include <linux/list.h>
19#include <linux/errno.h>
20#include <linux/err.h>
21#include <linux/clk.h>
22#include <linux/sysdev.h>
23#include <linux/io.h>
24
25#include <mach/hardware.h>
26#include <mach/map.h>
27
28#include <plat/cpu-freq.h>
29
30#include <plat/regs-clock.h>
31#include <plat/clock.h>
32#include <plat/cpu.h>
33#include <plat/pll.h>
34
35/* fin_apll, fin_mpll and fin_epll are all the same clock, which we call
36 * ext_xtal_mux for want of an actual name from the manual.
37*/
38
Ben Dooks3782d362009-02-27 11:25:37 +000039static struct clk clk_ext_xtal_mux = {
Ben Dookscf18acf2008-10-21 14:07:02 +010040 .name = "ext_xtal",
41 .id = -1,
42};
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
Ben Dooks87d26d22010-01-07 11:05:55 +090049#define clk_fout_epll clk_epll
Ben Dookscf18acf2008-10-21 14:07:02 +010050
51struct clk_sources {
52 unsigned int nr_sources;
53 struct clk **sources;
54};
55
56struct clksrc_clk {
57 struct clk clk;
58 unsigned int mask;
59 unsigned int shift;
60
61 struct clk_sources *sources;
62
63 unsigned int divider_shift;
64 void __iomem *reg_divider;
65};
66
Ben Dooks3782d362009-02-27 11:25:37 +000067static struct clk clk_fout_apll = {
Ben Dookscf18acf2008-10-21 14:07:02 +010068 .name = "fout_apll",
69 .id = -1,
70};
71
72static struct clk *clk_src_apll_list[] = {
73 [0] = &clk_fin_apll,
74 [1] = &clk_fout_apll,
75};
76
77static struct clk_sources clk_src_apll = {
78 .sources = clk_src_apll_list,
79 .nr_sources = ARRAY_SIZE(clk_src_apll_list),
80};
81
Ben Dooks3782d362009-02-27 11:25:37 +000082static struct clksrc_clk clk_mout_apll = {
Ben Dookscf18acf2008-10-21 14:07:02 +010083 .clk = {
84 .name = "mout_apll",
85 .id = -1,
86 },
87 .shift = S3C6400_CLKSRC_APLL_MOUT_SHIFT,
88 .mask = S3C6400_CLKSRC_APLL_MOUT,
89 .sources = &clk_src_apll,
90};
91
Ben Dookscf18acf2008-10-21 14:07:02 +010092static struct clk *clk_src_epll_list[] = {
93 [0] = &clk_fin_epll,
94 [1] = &clk_fout_epll,
95};
96
97static struct clk_sources clk_src_epll = {
98 .sources = clk_src_epll_list,
99 .nr_sources = ARRAY_SIZE(clk_src_epll_list),
100};
101
Ben Dooks3782d362009-02-27 11:25:37 +0000102static struct clksrc_clk clk_mout_epll = {
Ben Dookscf18acf2008-10-21 14:07:02 +0100103 .clk = {
104 .name = "mout_epll",
105 .id = -1,
106 },
107 .shift = S3C6400_CLKSRC_EPLL_MOUT_SHIFT,
108 .mask = S3C6400_CLKSRC_EPLL_MOUT,
109 .sources = &clk_src_epll,
110};
111
112static struct clk *clk_src_mpll_list[] = {
113 [0] = &clk_fin_mpll,
114 [1] = &clk_fout_mpll,
115};
116
117static struct clk_sources clk_src_mpll = {
118 .sources = clk_src_mpll_list,
119 .nr_sources = ARRAY_SIZE(clk_src_mpll_list),
120};
121
Ben Dooks3782d362009-02-27 11:25:37 +0000122static struct clksrc_clk clk_mout_mpll = {
Ben Dookscf18acf2008-10-21 14:07:02 +0100123 .clk = {
124 .name = "mout_mpll",
125 .id = -1,
126 },
127 .shift = S3C6400_CLKSRC_MPLL_MOUT_SHIFT,
128 .mask = S3C6400_CLKSRC_MPLL_MOUT,
129 .sources = &clk_src_mpll,
130};
131
Ben Dooks496a3f02009-05-02 13:48:53 +0100132static unsigned int armclk_mask;
133
134static unsigned long s3c64xx_clk_arm_get_rate(struct clk *clk)
135{
136 unsigned long rate = clk_get_rate(clk->parent);
137 u32 clkdiv;
138
139 /* divisor mask starts at bit0, so no need to shift */
140 clkdiv = __raw_readl(S3C_CLK_DIV0) & armclk_mask;
141
142 return rate / (clkdiv + 1);
143}
144
145static unsigned long s3c64xx_clk_arm_round_rate(struct clk *clk,
146 unsigned long rate)
147{
148 unsigned long parent = clk_get_rate(clk->parent);
149 u32 div;
150
151 if (parent < rate)
Mark Brown1d91e1a2009-07-15 13:03:34 +0100152 return parent;
Ben Dooks496a3f02009-05-02 13:48:53 +0100153
154 div = (parent / rate) - 1;
155 if (div > armclk_mask)
156 div = armclk_mask;
157
158 return parent / (div + 1);
159}
160
161static int s3c64xx_clk_arm_set_rate(struct clk *clk, unsigned long rate)
162{
163 unsigned long parent = clk_get_rate(clk->parent);
164 u32 div;
165 u32 val;
166
167 if (rate < parent / (armclk_mask + 1))
168 return -EINVAL;
169
170 rate = clk_round_rate(clk, rate);
171 div = clk_get_rate(clk->parent) / rate;
172
173 val = __raw_readl(S3C_CLK_DIV0);
Mark Brown9b71de42009-07-15 13:03:35 +0100174 val &= ~armclk_mask;
Ben Dooks496a3f02009-05-02 13:48:53 +0100175 val |= (div - 1);
176 __raw_writel(val, S3C_CLK_DIV0);
177
178 return 0;
179
180}
181
182static struct clk clk_arm = {
183 .name = "armclk",
184 .id = -1,
185 .parent = &clk_mout_apll.clk,
186 .get_rate = s3c64xx_clk_arm_get_rate,
187 .set_rate = s3c64xx_clk_arm_set_rate,
188 .round_rate = s3c64xx_clk_arm_round_rate,
189};
190
Ben Dookscf18acf2008-10-21 14:07:02 +0100191static unsigned long s3c64xx_clk_doutmpll_get_rate(struct clk *clk)
192{
193 unsigned long rate = clk_get_rate(clk->parent);
194
Ben Dooks39669f52008-10-21 14:07:12 +0100195 printk(KERN_DEBUG "%s: parent is %ld\n", __func__, rate);
Ben Dookscf18acf2008-10-21 14:07:02 +0100196
197 if (__raw_readl(S3C_CLK_DIV0) & S3C6400_CLKDIV0_MPLL_MASK)
198 rate /= 2;
199
200 return rate;
201}
202
Ben Dooks3782d362009-02-27 11:25:37 +0000203static struct clk clk_dout_mpll = {
Ben Dookscf18acf2008-10-21 14:07:02 +0100204 .name = "dout_mpll",
205 .id = -1,
206 .parent = &clk_mout_mpll.clk,
207 .get_rate = s3c64xx_clk_doutmpll_get_rate,
208};
209
210static struct clk *clkset_spi_mmc_list[] = {
211 &clk_mout_epll.clk,
212 &clk_dout_mpll,
213 &clk_fin_epll,
214 &clk_27m,
215};
216
217static struct clk_sources clkset_spi_mmc = {
218 .sources = clkset_spi_mmc_list,
219 .nr_sources = ARRAY_SIZE(clkset_spi_mmc_list),
220};
221
222static struct clk *clkset_irda_list[] = {
223 &clk_mout_epll.clk,
224 &clk_dout_mpll,
225 NULL,
226 &clk_27m,
227};
228
229static struct clk_sources clkset_irda = {
230 .sources = clkset_irda_list,
231 .nr_sources = ARRAY_SIZE(clkset_irda_list),
232};
233
234static struct clk *clkset_uart_list[] = {
235 &clk_mout_epll.clk,
236 &clk_dout_mpll,
237 NULL,
238 NULL
239};
240
241static struct clk_sources clkset_uart = {
242 .sources = clkset_uart_list,
243 .nr_sources = ARRAY_SIZE(clkset_uart_list),
244};
245
246static struct clk *clkset_uhost_list[] = {
Ben Dooks41ba41d2009-02-26 23:00:34 +0000247 &clk_48m,
Ben Dookscf18acf2008-10-21 14:07:02 +0100248 &clk_mout_epll.clk,
249 &clk_dout_mpll,
250 &clk_fin_epll,
Ben Dookscf18acf2008-10-21 14:07:02 +0100251};
252
253static struct clk_sources clkset_uhost = {
254 .sources = clkset_uhost_list,
255 .nr_sources = ARRAY_SIZE(clkset_uhost_list),
256};
257
Ben Dookscf18acf2008-10-21 14:07:02 +0100258/* The peripheral clocks are all controlled via clocksource followed
259 * by an optional divider and gate stage. We currently roll this into
260 * one clock which hides the intermediate clock from the mux.
261 *
262 * Note, the JPEG clock can only be an even divider...
263 *
264 * The scaler and LCD clocks depend on the S3C64XX version, and also
265 * have a common parent divisor so are not included here.
266 */
267
268static inline struct clksrc_clk *to_clksrc(struct clk *clk)
269{
270 return container_of(clk, struct clksrc_clk, clk);
271}
272
273static unsigned long s3c64xx_getrate_clksrc(struct clk *clk)
274{
275 struct clksrc_clk *sclk = to_clksrc(clk);
276 unsigned long rate = clk_get_rate(clk->parent);
277 u32 clkdiv = __raw_readl(sclk->reg_divider);
278
279 clkdiv >>= sclk->divider_shift;
280 clkdiv &= 0xf;
281 clkdiv++;
282
283 rate /= clkdiv;
284 return rate;
285}
286
287static int s3c64xx_setrate_clksrc(struct clk *clk, unsigned long rate)
288{
289 struct clksrc_clk *sclk = to_clksrc(clk);
290 void __iomem *reg = sclk->reg_divider;
291 unsigned int div;
292 u32 val;
293
294 rate = clk_round_rate(clk, rate);
295 div = clk_get_rate(clk->parent) / rate;
Werner Almesbergerefeff562009-02-27 08:03:07 -0300296 if (div > 16)
297 return -EINVAL;
Ben Dookscf18acf2008-10-21 14:07:02 +0100298
299 val = __raw_readl(reg);
Thomas Abraham9adb15b2009-09-08 14:26:00 +0900300 val &= ~(0xf << sclk->divider_shift);
301 val |= (div - 1) << sclk->divider_shift;
Ben Dookscf18acf2008-10-21 14:07:02 +0100302 __raw_writel(val, reg);
303
304 return 0;
305}
306
307static int s3c64xx_setparent_clksrc(struct clk *clk, struct clk *parent)
308{
309 struct clksrc_clk *sclk = to_clksrc(clk);
310 struct clk_sources *srcs = sclk->sources;
311 u32 clksrc = __raw_readl(S3C_CLK_SRC);
312 int src_nr = -1;
313 int ptr;
314
315 for (ptr = 0; ptr < srcs->nr_sources; ptr++)
316 if (srcs->sources[ptr] == parent) {
317 src_nr = ptr;
318 break;
319 }
320
321 if (src_nr >= 0) {
322 clksrc &= ~sclk->mask;
323 clksrc |= src_nr << sclk->shift;
324
325 __raw_writel(clksrc, S3C_CLK_SRC);
Thomas Abraham6d025ac2009-09-08 14:30:48 +0900326
327 clk->parent = parent;
Ben Dookscf18acf2008-10-21 14:07:02 +0100328 return 0;
329 }
330
331 return -EINVAL;
332}
333
334static unsigned long s3c64xx_roundrate_clksrc(struct clk *clk,
335 unsigned long rate)
336{
337 unsigned long parent_rate = clk_get_rate(clk->parent);
338 int div;
339
340 if (rate > parent_rate)
341 rate = parent_rate;
342 else {
Thomas Abraham5e49bc42009-09-08 14:35:29 +0900343 div = parent_rate / rate;
Ben Dookscf18acf2008-10-21 14:07:02 +0100344
345 if (div == 0)
346 div = 1;
347 if (div > 16)
348 div = 16;
349
350 rate = parent_rate / div;
351 }
352
353 return rate;
354}
355
Ben Dooks83604932009-11-30 01:31:32 +0000356/* clocks that feed other parts of the clock source tree */
Ben Dookscf18acf2008-10-21 14:07:02 +0100357
358static struct clk clk_iis_cd0 = {
359 .name = "iis_cdclk0",
360 .id = -1,
361};
362
363static struct clk clk_iis_cd1 = {
364 .name = "iis_cdclk1",
365 .id = -1,
366};
367
368static struct clk clk_pcm_cd = {
369 .name = "pcm_cdclk",
370 .id = -1,
371};
372
373static struct clk *clkset_audio0_list[] = {
374 [0] = &clk_mout_epll.clk,
375 [1] = &clk_dout_mpll,
376 [2] = &clk_fin_epll,
377 [3] = &clk_iis_cd0,
378 [4] = &clk_pcm_cd,
379};
380
381static struct clk_sources clkset_audio0 = {
382 .sources = clkset_audio0_list,
383 .nr_sources = ARRAY_SIZE(clkset_audio0_list),
384};
385
Ben Dookscf18acf2008-10-21 14:07:02 +0100386static struct clk *clkset_audio1_list[] = {
387 [0] = &clk_mout_epll.clk,
388 [1] = &clk_dout_mpll,
389 [2] = &clk_fin_epll,
390 [3] = &clk_iis_cd1,
391 [4] = &clk_pcm_cd,
392};
393
394static struct clk_sources clkset_audio1 = {
395 .sources = clkset_audio1_list,
396 .nr_sources = ARRAY_SIZE(clkset_audio1_list),
397};
398
Werner Almesbergere2c977d2009-03-05 11:43:14 +0800399static struct clk *clkset_camif_list[] = {
400 &clk_h2,
401};
402
403static struct clk_sources clkset_camif = {
404 .sources = clkset_camif_list,
405 .nr_sources = ARRAY_SIZE(clkset_camif_list),
406};
407
Ben Dooks83604932009-11-30 01:31:32 +0000408static struct clksrc_clk clksrcs[] = {
409 {
410 .clk = {
411 .name = "mmc_bus",
412 .id = 0,
413 .ctrlbit = S3C_CLKCON_SCLK_MMC0,
414 .enable = s3c64xx_sclk_ctrl,
415 },
416 .shift = S3C6400_CLKSRC_MMC0_SHIFT,
417 .mask = S3C6400_CLKSRC_MMC0_MASK,
418 .sources = &clkset_spi_mmc,
419 .divider_shift = S3C6400_CLKDIV1_MMC0_SHIFT,
420 .reg_divider = S3C_CLK_DIV1,
421 }, {
422 .clk = {
423 .name = "mmc_bus",
424 .id = 1,
425 .ctrlbit = S3C_CLKCON_SCLK_MMC1,
426 .enable = s3c64xx_sclk_ctrl,
427 },
428 .shift = S3C6400_CLKSRC_MMC1_SHIFT,
429 .mask = S3C6400_CLKSRC_MMC1_MASK,
430 .sources = &clkset_spi_mmc,
431 .divider_shift = S3C6400_CLKDIV1_MMC1_SHIFT,
432 .reg_divider = S3C_CLK_DIV1,
433 }, {
434 .clk = {
435 .name = "mmc_bus",
436 .id = 2,
437 .ctrlbit = S3C_CLKCON_SCLK_MMC2,
438 .enable = s3c64xx_sclk_ctrl,
439 },
440 .shift = S3C6400_CLKSRC_MMC2_SHIFT,
441 .mask = S3C6400_CLKSRC_MMC2_MASK,
442 .sources = &clkset_spi_mmc,
443 .divider_shift = S3C6400_CLKDIV1_MMC2_SHIFT,
444 .reg_divider = S3C_CLK_DIV1,
445 }, {
446 .clk = {
447 .name = "usb-bus-host",
448 .id = -1,
449 .ctrlbit = S3C_CLKCON_SCLK_UHOST,
450 .enable = s3c64xx_sclk_ctrl,
451 },
452 .shift = S3C6400_CLKSRC_UHOST_SHIFT,
453 .mask = S3C6400_CLKSRC_UHOST_MASK,
454 .sources = &clkset_uhost,
455 .divider_shift = S3C6400_CLKDIV1_UHOST_SHIFT,
456 .reg_divider = S3C_CLK_DIV1,
457 }, {
458 .clk = {
459 .name = "uclk1",
460 .id = -1,
461 .ctrlbit = S3C_CLKCON_SCLK_UART,
462 .enable = s3c64xx_sclk_ctrl,
463 },
464 .shift = S3C6400_CLKSRC_UART_SHIFT,
465 .mask = S3C6400_CLKSRC_UART_MASK,
466 .sources = &clkset_uart,
467 .divider_shift = S3C6400_CLKDIV2_UART_SHIFT,
468 .reg_divider = S3C_CLK_DIV2,
469 }, {
470/* Where does UCLK0 come from? */
471 .clk = {
472 .name = "spi-bus",
473 .id = 0,
474 .ctrlbit = S3C_CLKCON_SCLK_SPI0,
475 .enable = s3c64xx_sclk_ctrl,
476 },
477 .shift = S3C6400_CLKSRC_SPI0_SHIFT,
478 .mask = S3C6400_CLKSRC_SPI0_MASK,
479 .sources = &clkset_spi_mmc,
480 .divider_shift = S3C6400_CLKDIV2_SPI0_SHIFT,
481 .reg_divider = S3C_CLK_DIV2,
482 }, {
483 .clk = {
484 .name = "spi-bus",
485 .id = 1,
486 .ctrlbit = S3C_CLKCON_SCLK_SPI1,
487 .enable = s3c64xx_sclk_ctrl,
488 },
489 .shift = S3C6400_CLKSRC_SPI1_SHIFT,
490 .mask = S3C6400_CLKSRC_SPI1_MASK,
491 .sources = &clkset_spi_mmc,
492 .divider_shift = S3C6400_CLKDIV2_SPI1_SHIFT,
493 .reg_divider = S3C_CLK_DIV2,
494 }, {
495 .clk = {
496 .name = "audio-bus",
497 .id = 0,
498 .ctrlbit = S3C_CLKCON_SCLK_AUDIO0,
499 .enable = s3c64xx_sclk_ctrl,
500 },
501 .shift = S3C6400_CLKSRC_AUDIO0_SHIFT,
502 .mask = S3C6400_CLKSRC_AUDIO0_MASK,
503 .sources = &clkset_audio0,
504 .divider_shift = S3C6400_CLKDIV2_AUDIO0_SHIFT,
505 .reg_divider = S3C_CLK_DIV2,
506 }, {
507 .clk = {
508 .name = "audio-bus",
509 .id = 1,
510 .ctrlbit = S3C_CLKCON_SCLK_AUDIO1,
511 .enable = s3c64xx_sclk_ctrl,
512 },
513 .shift = S3C6400_CLKSRC_AUDIO1_SHIFT,
514 .mask = S3C6400_CLKSRC_AUDIO1_MASK,
515 .sources = &clkset_audio1,
516 .divider_shift = S3C6400_CLKDIV2_AUDIO1_SHIFT,
517 .reg_divider = S3C_CLK_DIV2,
518 }, {
519 .clk = {
520 .name = "irda-bus",
521 .id = 0,
522 .ctrlbit = S3C_CLKCON_SCLK_IRDA,
523 .enable = s3c64xx_sclk_ctrl,
524 },
525 .shift = S3C6400_CLKSRC_IRDA_SHIFT,
526 .mask = S3C6400_CLKSRC_IRDA_MASK,
527 .sources = &clkset_irda,
528 .divider_shift = S3C6400_CLKDIV2_IRDA_SHIFT,
529 .reg_divider = S3C_CLK_DIV2,
530 }, {
531 .clk = {
532 .name = "camera",
533 .id = -1,
534 .ctrlbit = S3C_CLKCON_SCLK_CAM,
535 .enable = s3c64xx_sclk_ctrl,
536 },
537 .shift = 0,
538 .mask = 0,
539 .sources = &clkset_camif,
540 .divider_shift = S3C6400_CLKDIV0_CAM_SHIFT,
541 .reg_divider = S3C_CLK_DIV0,
Werner Almesbergere2c977d2009-03-05 11:43:14 +0800542 },
Werner Almesbergere2c977d2009-03-05 11:43:14 +0800543};
544
Ben Dookscf18acf2008-10-21 14:07:02 +0100545/* Clock initialisation code */
546
547static struct clksrc_clk *init_parents[] = {
548 &clk_mout_apll,
549 &clk_mout_epll,
550 &clk_mout_mpll,
Ben Dookscf18acf2008-10-21 14:07:02 +0100551};
552
553static void __init_or_cpufreq s3c6400_set_clksrc(struct clksrc_clk *clk)
554{
555 struct clk_sources *srcs = clk->sources;
556 u32 clksrc = __raw_readl(S3C_CLK_SRC);
557
558 clksrc &= clk->mask;
559 clksrc >>= clk->shift;
560
561 if (clksrc > srcs->nr_sources || !srcs->sources[clksrc]) {
562 printk(KERN_ERR "%s: bad source %d\n",
563 clk->clk.name, clksrc);
564 return;
565 }
566
567 clk->clk.parent = srcs->sources[clksrc];
568
569 printk(KERN_INFO "%s: source is %s (%d), rate is %ld\n",
570 clk->clk.name, clk->clk.parent->name, clksrc,
571 clk_get_rate(&clk->clk));
572}
573
574#define GET_DIV(clk, field) ((((clk) & field##_MASK) >> field##_SHIFT) + 1)
575
576void __init_or_cpufreq s3c6400_setup_clocks(void)
577{
578 struct clk *xtal_clk;
579 unsigned long xtal;
580 unsigned long fclk;
581 unsigned long hclk;
582 unsigned long hclk2;
583 unsigned long pclk;
584 unsigned long epll;
585 unsigned long apll;
586 unsigned long mpll;
587 unsigned int ptr;
588 u32 clkdiv0;
589
Ben Dooks39669f52008-10-21 14:07:12 +0100590 printk(KERN_DEBUG "%s: registering clocks\n", __func__);
Ben Dookscf18acf2008-10-21 14:07:02 +0100591
592 clkdiv0 = __raw_readl(S3C_CLK_DIV0);
Ben Dooks39669f52008-10-21 14:07:12 +0100593 printk(KERN_DEBUG "%s: clkdiv0 = %08x\n", __func__, clkdiv0);
Ben Dookscf18acf2008-10-21 14:07:02 +0100594
595 xtal_clk = clk_get(NULL, "xtal");
596 BUG_ON(IS_ERR(xtal_clk));
597
598 xtal = clk_get_rate(xtal_clk);
599 clk_put(xtal_clk);
600
Ben Dooks39669f52008-10-21 14:07:12 +0100601 printk(KERN_DEBUG "%s: xtal is %ld\n", __func__, xtal);
Ben Dookscf18acf2008-10-21 14:07:02 +0100602
Mark Browne179ac02009-10-21 18:17:58 +0100603 /* For now assume the mux always selects the crystal */
604 clk_ext_xtal_mux.parent = xtal_clk;
605
Ben Dookscf18acf2008-10-21 14:07:02 +0100606 epll = s3c6400_get_epll(xtal);
607 mpll = s3c6400_get_pll(xtal, __raw_readl(S3C_MPLL_CON));
608 apll = s3c6400_get_pll(xtal, __raw_readl(S3C_APLL_CON));
609
610 fclk = mpll;
611
612 printk(KERN_INFO "S3C64XX: PLL settings, A=%ld, M=%ld, E=%ld\n",
613 apll, mpll, epll);
614
615 hclk2 = mpll / GET_DIV(clkdiv0, S3C6400_CLKDIV0_HCLK2);
616 hclk = hclk2 / GET_DIV(clkdiv0, S3C6400_CLKDIV0_HCLK);
617 pclk = hclk2 / GET_DIV(clkdiv0, S3C6400_CLKDIV0_PCLK);
618
619 printk(KERN_INFO "S3C64XX: HCLK2=%ld, HCLK=%ld, PCLK=%ld\n",
620 hclk2, hclk, pclk);
621
622 clk_fout_mpll.rate = mpll;
623 clk_fout_epll.rate = epll;
624 clk_fout_apll.rate = apll;
625
Werner Almesbergera03f7da2009-03-05 11:43:13 +0800626 clk_h2.rate = hclk2;
Ben Dookscf18acf2008-10-21 14:07:02 +0100627 clk_h.rate = hclk;
628 clk_p.rate = pclk;
629 clk_f.rate = fclk;
630
631 for (ptr = 0; ptr < ARRAY_SIZE(init_parents); ptr++)
632 s3c6400_set_clksrc(init_parents[ptr]);
Ben Dooks83604932009-11-30 01:31:32 +0000633
634 for (ptr = 0; ptr < ARRAY_SIZE(clksrcs); ptr++)
635 s3c6400_set_clksrc(&clksrcs[ptr]);
Ben Dookscf18acf2008-10-21 14:07:02 +0100636}
637
638static struct clk *clks[] __initdata = {
639 &clk_ext_xtal_mux,
640 &clk_iis_cd0,
641 &clk_iis_cd1,
642 &clk_pcm_cd,
643 &clk_mout_epll.clk,
Ben Dookscf18acf2008-10-21 14:07:02 +0100644 &clk_mout_mpll.clk,
645 &clk_dout_mpll,
Ben Dooks496a3f02009-05-02 13:48:53 +0100646 &clk_arm,
Ben Dookscf18acf2008-10-21 14:07:02 +0100647};
648
Ben Dooks496a3f02009-05-02 13:48:53 +0100649/**
650 * s3c6400_register_clocks - register clocks for s3c6400 and above
651 * @armclk_divlimit: Divisor mask for ARMCLK
652 *
653 * Register the clocks for the S3C6400 and above SoC range, such
654 * as ARMCLK and the clocks which have divider chains attached.
655 *
656 * This call does not setup the clocks, which is left to the
657 * s3c6400_setup_clocks() call which may be needed by the cpufreq
658 * or resume code to re-set the clocks if the bootloader has changed
659 * them.
660 */
661void __init s3c6400_register_clocks(unsigned armclk_divlimit)
Ben Dookscf18acf2008-10-21 14:07:02 +0100662{
663 struct clk *clkp;
664 int ret;
665 int ptr;
666
Ben Dooks496a3f02009-05-02 13:48:53 +0100667 armclk_mask = armclk_divlimit;
668
Ben Dookscf18acf2008-10-21 14:07:02 +0100669 for (ptr = 0; ptr < ARRAY_SIZE(clks); ptr++) {
670 clkp = clks[ptr];
671 ret = s3c24xx_register_clock(clkp);
672 if (ret < 0) {
673 printk(KERN_ERR "Failed to register clock %s (%d)\n",
674 clkp->name, ret);
675 }
676 }
Ben Dooks83604932009-11-30 01:31:32 +0000677
678 for (ptr = 0; ptr < ARRAY_SIZE(clksrcs); ptr++) {
679 clkp = &clksrcs[ptr].clk;
680
681 /* all clksrc clocks have these */
682 clkp->get_rate = s3c64xx_getrate_clksrc;
683 clkp->set_rate = s3c64xx_setrate_clksrc;
684 clkp->set_parent = s3c64xx_setparent_clksrc;
685 clkp->round_rate = s3c64xx_roundrate_clksrc;
686
687 ret = s3c24xx_register_clock(clkp);
688 if (ret < 0) {
689 printk(KERN_ERR "Failed to register clock %s (%d)\n",
690 clkp->name, ret);
691 }
692 }
Ben Dookscf18acf2008-10-21 14:07:02 +0100693}