blob: 274561677e5c288eff5d8f0396abcfa0f72d222e [file] [log] [blame]
Heiko Stuebner8c3d7c32012-03-03 07:49:12 +09001/*
2 * Common code for SoCs starting with the S3C2443
Ben Dooksaf337f32010-04-28 18:03:57 +09003 *
4 * Copyright (c) 2007, 2010 Simtec Electronics
5 * Ben Dooks <ben@simtec.co.uk>
6 *
Heiko Stuebner8c3d7c32012-03-03 07:49:12 +09007 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
Ben Dooksaf337f32010-04-28 18:03:57 +090016 */
17
18#include <linux/init.h>
19#include <linux/clk.h>
20#include <linux/io.h>
21
22#include <mach/regs-s3c2443-clock.h>
23
Ben Dooksaf337f32010-04-28 18:03:57 +090024#include <plat/clock.h>
25#include <plat/clock-clksrc.h>
26#include <plat/cpu.h>
27
28#include <plat/cpu-freq.h>
29
30
31static int s3c2443_gate(void __iomem *reg, struct clk *clk, int enable)
32{
33 u32 ctrlbit = clk->ctrlbit;
34 u32 con = __raw_readl(reg);
35
36 if (enable)
37 con |= ctrlbit;
38 else
39 con &= ~ctrlbit;
40
41 __raw_writel(con, reg);
42 return 0;
43}
44
45int s3c2443_clkcon_enable_h(struct clk *clk, int enable)
46{
47 return s3c2443_gate(S3C2443_HCLKCON, clk, enable);
48}
49
50int s3c2443_clkcon_enable_p(struct clk *clk, int enable)
51{
52 return s3c2443_gate(S3C2443_PCLKCON, clk, enable);
53}
54
55int s3c2443_clkcon_enable_s(struct clk *clk, int enable)
56{
57 return s3c2443_gate(S3C2443_SCLKCON, clk, enable);
58}
59
60/* mpllref is a direct descendant of clk_xtal by default, but it is not
61 * elided as the EPLL can be either sourced by the XTAL or EXTCLK and as
62 * such directly equating the two source clocks is impossible.
63 */
64struct clk clk_mpllref = {
65 .name = "mpllref",
66 .parent = &clk_xtal,
Ben Dooksaf337f32010-04-28 18:03:57 +090067};
68
69static struct clk *clk_epllref_sources[] = {
70 [0] = &clk_mpllref,
71 [1] = &clk_mpllref,
72 [2] = &clk_xtal,
73 [3] = &clk_ext,
74};
75
76struct clksrc_clk clk_epllref = {
77 .clk = {
78 .name = "epllref",
Ben Dooksaf337f32010-04-28 18:03:57 +090079 },
80 .sources = &(struct clksrc_sources) {
81 .sources = clk_epllref_sources,
82 .nr_sources = ARRAY_SIZE(clk_epllref_sources),
83 },
84 .reg_src = { .reg = S3C2443_CLKSRC, .size = 2, .shift = 7 },
85};
86
87/* esysclk
88 *
89 * this is sourced from either the EPLL or the EPLLref clock
90*/
91
92static struct clk *clk_sysclk_sources[] = {
93 [0] = &clk_epllref.clk,
94 [1] = &clk_epll,
95};
96
97struct clksrc_clk clk_esysclk = {
98 .clk = {
99 .name = "esysclk",
100 .parent = &clk_epll,
Ben Dooksaf337f32010-04-28 18:03:57 +0900101 },
102 .sources = &(struct clksrc_sources) {
103 .sources = clk_sysclk_sources,
104 .nr_sources = ARRAY_SIZE(clk_sysclk_sources),
105 },
106 .reg_src = { .reg = S3C2443_CLKSRC, .size = 1, .shift = 6 },
107};
108
109static unsigned long s3c2443_getrate_mdivclk(struct clk *clk)
110{
111 unsigned long parent_rate = clk_get_rate(clk->parent);
112 unsigned long div = __raw_readl(S3C2443_CLKDIV0);
113
114 div &= S3C2443_CLKDIV0_EXTDIV_MASK;
115 div >>= (S3C2443_CLKDIV0_EXTDIV_SHIFT-1); /* x2 */
116
117 return parent_rate / (div + 1);
118}
119
120static struct clk clk_mdivclk = {
121 .name = "mdivclk",
122 .parent = &clk_mpllref,
Ben Dooksaf337f32010-04-28 18:03:57 +0900123 .ops = &(struct clk_ops) {
124 .get_rate = s3c2443_getrate_mdivclk,
125 },
126};
127
128static struct clk *clk_msysclk_sources[] = {
129 [0] = &clk_mpllref,
130 [1] = &clk_mpll,
131 [2] = &clk_mdivclk,
132 [3] = &clk_mpllref,
133};
134
135struct clksrc_clk clk_msysclk = {
136 .clk = {
137 .name = "msysclk",
138 .parent = &clk_xtal,
Ben Dooksaf337f32010-04-28 18:03:57 +0900139 },
140 .sources = &(struct clksrc_sources) {
141 .sources = clk_msysclk_sources,
142 .nr_sources = ARRAY_SIZE(clk_msysclk_sources),
143 },
144 .reg_src = { .reg = S3C2443_CLKSRC, .size = 2, .shift = 3 },
145};
146
147/* prediv
148 *
149 * this divides the msysclk down to pass to h/p/etc.
150 */
151
152static unsigned long s3c2443_prediv_getrate(struct clk *clk)
153{
154 unsigned long rate = clk_get_rate(clk->parent);
155 unsigned long clkdiv0 = __raw_readl(S3C2443_CLKDIV0);
156
157 clkdiv0 &= S3C2443_CLKDIV0_PREDIV_MASK;
158 clkdiv0 >>= S3C2443_CLKDIV0_PREDIV_SHIFT;
159
160 return rate / (clkdiv0 + 1);
161}
162
163static struct clk clk_prediv = {
164 .name = "prediv",
Ben Dooksaf337f32010-04-28 18:03:57 +0900165 .parent = &clk_msysclk.clk,
166 .ops = &(struct clk_ops) {
167 .get_rate = s3c2443_prediv_getrate,
168 },
169};
170
Heiko St?bneraab08ee2011-10-14 15:08:56 +0900171/* armdiv
172 *
173 * this clock is sourced from msysclk and can have a number of
174 * divider values applied to it to then be fed into armclk.
175*/
176
Heiko Stuebnerd9a3bfb2011-10-14 15:08:56 +0900177static unsigned int *armdiv;
178static int nr_armdiv;
179static int armdivmask;
180
Heiko St?bneraab08ee2011-10-14 15:08:56 +0900181static unsigned long s3c2443_armclk_roundrate(struct clk *clk,
182 unsigned long rate)
183{
184 unsigned long parent = clk_get_rate(clk->parent);
185 unsigned long calc;
186 unsigned best = 256; /* bigger than any value */
187 unsigned div;
188 int ptr;
189
Heiko Stuebnerf9f7c752011-10-14 15:08:56 +0900190 if (!nr_armdiv)
191 return -EINVAL;
192
Heiko St?bneraab08ee2011-10-14 15:08:56 +0900193 for (ptr = 0; ptr < nr_armdiv; ptr++) {
194 div = armdiv[ptr];
Heiko Stuebnerf9f7c752011-10-14 15:08:56 +0900195 if (div) {
Heiko Stuebner866a1c82011-10-14 15:08:57 +0900196 /* cpufreq provides 266mhz as 266666000 not 266666666 */
197 calc = (parent / div / 1000) * 1000;
Heiko Stuebnerf9f7c752011-10-14 15:08:56 +0900198 if (calc <= rate && div < best)
199 best = div;
200 }
Heiko St?bneraab08ee2011-10-14 15:08:56 +0900201 }
202
203 return parent / best;
204}
205
Heiko Stuebner5f33bd72011-10-14 15:08:56 +0900206static unsigned long s3c2443_armclk_getrate(struct clk *clk)
207{
208 unsigned long rate = clk_get_rate(clk->parent);
209 unsigned long clkcon0;
210 int val;
211
Heiko Stuebnerf9f7c752011-10-14 15:08:56 +0900212 if (!nr_armdiv || !armdivmask)
213 return -EINVAL;
214
Heiko Stuebner5f33bd72011-10-14 15:08:56 +0900215 clkcon0 = __raw_readl(S3C2443_CLKDIV0);
216 clkcon0 &= armdivmask;
217 val = clkcon0 >> S3C2443_CLKDIV0_ARMDIV_SHIFT;
218
219 return rate / armdiv[val];
220}
221
Heiko St?bneraab08ee2011-10-14 15:08:56 +0900222static int s3c2443_armclk_setrate(struct clk *clk, unsigned long rate)
223{
224 unsigned long parent = clk_get_rate(clk->parent);
225 unsigned long calc;
226 unsigned div;
227 unsigned best = 256; /* bigger than any value */
228 int ptr;
229 int val = -1;
230
Heiko Stuebnerf9f7c752011-10-14 15:08:56 +0900231 if (!nr_armdiv || !armdivmask)
232 return -EINVAL;
233
Heiko St?bneraab08ee2011-10-14 15:08:56 +0900234 for (ptr = 0; ptr < nr_armdiv; ptr++) {
235 div = armdiv[ptr];
Heiko Stuebnerf9f7c752011-10-14 15:08:56 +0900236 if (div) {
Heiko Stuebner866a1c82011-10-14 15:08:57 +0900237 /* cpufreq provides 266mhz as 266666000 not 266666666 */
238 calc = (parent / div / 1000) * 1000;
Heiko Stuebnerf9f7c752011-10-14 15:08:56 +0900239 if (calc <= rate && div < best) {
240 best = div;
241 val = ptr;
242 }
Heiko St?bneraab08ee2011-10-14 15:08:56 +0900243 }
244 }
245
246 if (val >= 0) {
247 unsigned long clkcon0;
248
249 clkcon0 = __raw_readl(S3C2443_CLKDIV0);
250 clkcon0 &= ~armdivmask;
251 clkcon0 |= val << S3C2443_CLKDIV0_ARMDIV_SHIFT;
252 __raw_writel(clkcon0, S3C2443_CLKDIV0);
253 }
254
255 return (val == -1) ? -EINVAL : 0;
256}
257
258static struct clk clk_armdiv = {
259 .name = "armdiv",
260 .parent = &clk_msysclk.clk,
261 .ops = &(struct clk_ops) {
262 .round_rate = s3c2443_armclk_roundrate,
Heiko Stuebner5f33bd72011-10-14 15:08:56 +0900263 .get_rate = s3c2443_armclk_getrate,
Heiko St?bneraab08ee2011-10-14 15:08:56 +0900264 .set_rate = s3c2443_armclk_setrate,
265 },
266};
267
268/* armclk
269 *
270 * this is the clock fed into the ARM core itself, from armdiv or from hclk.
271 */
272
273static struct clk *clk_arm_sources[] = {
274 [0] = &clk_armdiv,
275 [1] = &clk_h,
276};
277
278static struct clksrc_clk clk_arm = {
279 .clk = {
280 .name = "armclk",
281 },
282 .sources = &(struct clksrc_sources) {
283 .sources = clk_arm_sources,
284 .nr_sources = ARRAY_SIZE(clk_arm_sources),
285 },
286 .reg_src = { .reg = S3C2443_CLKDIV0, .size = 1, .shift = 13 },
287};
288
Ben Dooksaf337f32010-04-28 18:03:57 +0900289/* usbhost
290 *
291 * usb host bus-clock, usually 48MHz to provide USB bus clock timing
292*/
293
294static struct clksrc_clk clk_usb_bus_host = {
295 .clk = {
296 .name = "usb-bus-host-parent",
Ben Dooksaf337f32010-04-28 18:03:57 +0900297 .parent = &clk_esysclk.clk,
298 .ctrlbit = S3C2443_SCLKCON_USBHOST,
299 .enable = s3c2443_clkcon_enable_s,
300 },
301 .reg_div = { .reg = S3C2443_CLKDIV1, .size = 2, .shift = 4 },
302};
303
304/* common clksrc clocks */
305
306static struct clksrc_clk clksrc_clks[] = {
307 {
Ben Dooksaf337f32010-04-28 18:03:57 +0900308 /* camera interface bus-clock, divided down from esysclk */
309 .clk = {
310 .name = "camif-upll", /* same as 2440 name */
Ben Dooksaf337f32010-04-28 18:03:57 +0900311 .parent = &clk_esysclk.clk,
312 .ctrlbit = S3C2443_SCLKCON_CAMCLK,
313 .enable = s3c2443_clkcon_enable_s,
314 },
315 .reg_div = { .reg = S3C2443_CLKDIV1, .size = 4, .shift = 26 },
316 }, {
317 .clk = {
318 .name = "display-if",
Ben Dooksaf337f32010-04-28 18:03:57 +0900319 .parent = &clk_esysclk.clk,
320 .ctrlbit = S3C2443_SCLKCON_DISPCLK,
321 .enable = s3c2443_clkcon_enable_s,
322 },
323 .reg_div = { .reg = S3C2443_CLKDIV1, .size = 8, .shift = 16 },
324 },
325};
326
Thomas Abraham0cfb26e2011-10-24 12:08:42 +0200327static struct clksrc_clk clk_esys_uart = {
328 /* ART baud-rate clock sourced from esysclk via a divisor */
329 .clk = {
330 .name = "uartclk",
331 .parent = &clk_esysclk.clk,
332 },
333 .reg_div = { .reg = S3C2443_CLKDIV1, .size = 4, .shift = 8 },
334};
335
Heiko Stuebnere3b454f2011-09-27 08:44:37 +0900336static struct clk clk_i2s_ext = {
337 .name = "i2s-ext",
338};
339
340/* i2s_eplldiv
341 *
342 * This clock is the output from the I2S divisor of ESYSCLK, and is separate
343 * from the mux that comes after it (cannot merge into one single clock)
344*/
345
346static struct clksrc_clk clk_i2s_eplldiv = {
347 .clk = {
348 .name = "i2s-eplldiv",
349 .parent = &clk_esysclk.clk,
350 },
351 .reg_div = { .reg = S3C2443_CLKDIV1, .size = 4, .shift = 12, },
352};
353
354/* i2s-ref
355 *
356 * i2s bus reference clock, selectable from external, esysclk or epllref
357 *
358 * Note, this used to be two clocks, but was compressed into one.
359*/
360
361static struct clk *clk_i2s_srclist[] = {
362 [0] = &clk_i2s_eplldiv.clk,
363 [1] = &clk_i2s_ext,
364 [2] = &clk_epllref.clk,
365 [3] = &clk_epllref.clk,
366};
367
368static struct clksrc_clk clk_i2s = {
369 .clk = {
370 .name = "i2s-if",
371 .ctrlbit = S3C2443_SCLKCON_I2SCLK,
372 .enable = s3c2443_clkcon_enable_s,
373
374 },
375 .sources = &(struct clksrc_sources) {
376 .sources = clk_i2s_srclist,
377 .nr_sources = ARRAY_SIZE(clk_i2s_srclist),
378 },
379 .reg_src = { .reg = S3C2443_CLKSRC, .size = 2, .shift = 14 },
380};
Ben Dooksaf337f32010-04-28 18:03:57 +0900381
382static struct clk init_clocks_off[] = {
383 {
Heiko Stuebnere3b454f2011-09-27 08:44:37 +0900384 .name = "iis",
385 .parent = &clk_p,
386 .enable = s3c2443_clkcon_enable_p,
387 .ctrlbit = S3C2443_PCLKCON_IIS,
388 }, {
Heiko Stuebner8b069b72011-09-27 08:45:23 +0900389 .name = "hsspi",
390 .parent = &clk_p,
391 .enable = s3c2443_clkcon_enable_p,
392 .ctrlbit = S3C2443_PCLKCON_HSSPI,
393 }, {
Ben Dooksaf337f32010-04-28 18:03:57 +0900394 .name = "adc",
Ben Dooksaf337f32010-04-28 18:03:57 +0900395 .parent = &clk_p,
396 .enable = s3c2443_clkcon_enable_p,
397 .ctrlbit = S3C2443_PCLKCON_ADC,
398 }, {
399 .name = "i2c",
Ben Dooksaf337f32010-04-28 18:03:57 +0900400 .parent = &clk_p,
401 .enable = s3c2443_clkcon_enable_p,
402 .ctrlbit = S3C2443_PCLKCON_IIC,
403 }
404};
405
406static struct clk init_clocks[] = {
407 {
408 .name = "dma",
Ben Dooksaf337f32010-04-28 18:03:57 +0900409 .parent = &clk_h,
410 .enable = s3c2443_clkcon_enable_h,
411 .ctrlbit = S3C2443_HCLKCON_DMA0,
412 }, {
413 .name = "dma",
Ben Dooksaf337f32010-04-28 18:03:57 +0900414 .parent = &clk_h,
415 .enable = s3c2443_clkcon_enable_h,
416 .ctrlbit = S3C2443_HCLKCON_DMA1,
417 }, {
418 .name = "dma",
Ben Dooksaf337f32010-04-28 18:03:57 +0900419 .parent = &clk_h,
420 .enable = s3c2443_clkcon_enable_h,
421 .ctrlbit = S3C2443_HCLKCON_DMA2,
422 }, {
423 .name = "dma",
Ben Dooksaf337f32010-04-28 18:03:57 +0900424 .parent = &clk_h,
425 .enable = s3c2443_clkcon_enable_h,
426 .ctrlbit = S3C2443_HCLKCON_DMA3,
427 }, {
428 .name = "dma",
Ben Dooksaf337f32010-04-28 18:03:57 +0900429 .parent = &clk_h,
430 .enable = s3c2443_clkcon_enable_h,
431 .ctrlbit = S3C2443_HCLKCON_DMA4,
432 }, {
433 .name = "dma",
Ben Dooksaf337f32010-04-28 18:03:57 +0900434 .parent = &clk_h,
435 .enable = s3c2443_clkcon_enable_h,
436 .ctrlbit = S3C2443_HCLKCON_DMA5,
437 }, {
Ben Dooksaf337f32010-04-28 18:03:57 +0900438 .name = "gpio",
Ben Dooksaf337f32010-04-28 18:03:57 +0900439 .parent = &clk_p,
440 .enable = s3c2443_clkcon_enable_p,
441 .ctrlbit = S3C2443_PCLKCON_GPIO,
442 }, {
443 .name = "usb-host",
Ben Dooksaf337f32010-04-28 18:03:57 +0900444 .parent = &clk_h,
445 .enable = s3c2443_clkcon_enable_h,
446 .ctrlbit = S3C2443_HCLKCON_USBH,
447 }, {
448 .name = "usb-device",
Ben Dooksaf337f32010-04-28 18:03:57 +0900449 .parent = &clk_h,
450 .enable = s3c2443_clkcon_enable_h,
451 .ctrlbit = S3C2443_HCLKCON_USBD,
452 }, {
453 .name = "lcd",
Ben Dooksaf337f32010-04-28 18:03:57 +0900454 .parent = &clk_h,
455 .enable = s3c2443_clkcon_enable_h,
456 .ctrlbit = S3C2443_HCLKCON_LCDC,
457
458 }, {
459 .name = "timers",
Ben Dooksaf337f32010-04-28 18:03:57 +0900460 .parent = &clk_p,
461 .enable = s3c2443_clkcon_enable_p,
462 .ctrlbit = S3C2443_PCLKCON_PWMT,
463 }, {
464 .name = "cfc",
Ben Dooksaf337f32010-04-28 18:03:57 +0900465 .parent = &clk_h,
466 .enable = s3c2443_clkcon_enable_h,
467 .ctrlbit = S3C2443_HCLKCON_CFC,
468 }, {
469 .name = "ssmc",
Ben Dooksaf337f32010-04-28 18:03:57 +0900470 .parent = &clk_h,
471 .enable = s3c2443_clkcon_enable_h,
472 .ctrlbit = S3C2443_HCLKCON_SSMC,
473 }, {
474 .name = "uart",
Thomas Abrahame83626f2011-06-14 19:12:26 +0900475 .devname = "s3c2440-uart.0",
Ben Dooksaf337f32010-04-28 18:03:57 +0900476 .parent = &clk_p,
477 .enable = s3c2443_clkcon_enable_p,
478 .ctrlbit = S3C2443_PCLKCON_UART0,
479 }, {
480 .name = "uart",
Thomas Abrahame83626f2011-06-14 19:12:26 +0900481 .devname = "s3c2440-uart.1",
Ben Dooksaf337f32010-04-28 18:03:57 +0900482 .parent = &clk_p,
483 .enable = s3c2443_clkcon_enable_p,
484 .ctrlbit = S3C2443_PCLKCON_UART1,
485 }, {
486 .name = "uart",
Thomas Abrahame83626f2011-06-14 19:12:26 +0900487 .devname = "s3c2440-uart.2",
Ben Dooksaf337f32010-04-28 18:03:57 +0900488 .parent = &clk_p,
489 .enable = s3c2443_clkcon_enable_p,
490 .ctrlbit = S3C2443_PCLKCON_UART2,
491 }, {
492 .name = "uart",
Thomas Abrahame83626f2011-06-14 19:12:26 +0900493 .devname = "s3c2440-uart.3",
Ben Dooksaf337f32010-04-28 18:03:57 +0900494 .parent = &clk_p,
495 .enable = s3c2443_clkcon_enable_p,
496 .ctrlbit = S3C2443_PCLKCON_UART3,
497 }, {
498 .name = "rtc",
Ben Dooksaf337f32010-04-28 18:03:57 +0900499 .parent = &clk_p,
500 .enable = s3c2443_clkcon_enable_p,
501 .ctrlbit = S3C2443_PCLKCON_RTC,
502 }, {
503 .name = "watchdog",
Ben Dooksaf337f32010-04-28 18:03:57 +0900504 .parent = &clk_p,
505 .ctrlbit = S3C2443_PCLKCON_WDT,
506 }, {
507 .name = "ac97",
Ben Dooksaf337f32010-04-28 18:03:57 +0900508 .parent = &clk_p,
509 .ctrlbit = S3C2443_PCLKCON_AC97,
510 }, {
511 .name = "nand",
Ben Dooksaf337f32010-04-28 18:03:57 +0900512 .parent = &clk_h,
513 }, {
514 .name = "usb-bus-host",
Ben Dooksaf337f32010-04-28 18:03:57 +0900515 .parent = &clk_usb_bus_host.clk,
516 }
517};
518
Rajeshwari Shindea361d102011-10-24 17:05:58 +0200519static struct clk hsmmc1_clk = {
520 .name = "hsmmc",
521 .devname = "s3c-sdhci.1",
522 .parent = &clk_h,
523 .enable = s3c2443_clkcon_enable_h,
524 .ctrlbit = S3C2443_HCLKCON_HSMMC,
525};
526
Ben Dooksaf337f32010-04-28 18:03:57 +0900527static inline unsigned long s3c2443_get_hdiv(unsigned long clkcon0)
528{
529 clkcon0 &= S3C2443_CLKDIV0_HCLKDIV_MASK;
530
531 return clkcon0 + 1;
532}
533
534/* EPLLCON compatible enough to get on/off information */
535
Heiko Stuebner33ccedf2011-10-14 15:08:57 +0900536void __init_or_cpufreq s3c2443_common_setup_clocks(pll_fn get_mpll)
Ben Dooksaf337f32010-04-28 18:03:57 +0900537{
538 unsigned long epllcon = __raw_readl(S3C2443_EPLLCON);
539 unsigned long mpllcon = __raw_readl(S3C2443_MPLLCON);
540 unsigned long clkdiv0 = __raw_readl(S3C2443_CLKDIV0);
541 struct clk *xtal_clk;
542 unsigned long xtal;
543 unsigned long pll;
544 unsigned long fclk;
545 unsigned long hclk;
546 unsigned long pclk;
547 int ptr;
548
549 xtal_clk = clk_get(NULL, "xtal");
550 xtal = clk_get_rate(xtal_clk);
551 clk_put(xtal_clk);
552
553 pll = get_mpll(mpllcon, xtal);
554 clk_msysclk.clk.rate = pll;
555
Heiko Stuebner33ccedf2011-10-14 15:08:57 +0900556 fclk = clk_get_rate(&clk_armdiv);
Ben Dooksaf337f32010-04-28 18:03:57 +0900557 hclk = s3c2443_prediv_getrate(&clk_prediv);
558 hclk /= s3c2443_get_hdiv(clkdiv0);
559 pclk = hclk / ((clkdiv0 & S3C2443_CLKDIV0_HALF_PCLK) ? 2 : 1);
560
561 s3c24xx_setup_clocks(fclk, hclk, pclk);
562
563 printk("CPU: MPLL %s %ld.%03ld MHz, cpu %ld.%03ld MHz, mem %ld.%03ld MHz, pclk %ld.%03ld MHz\n",
Heiko Stuebner8c3d7c32012-03-03 07:49:12 +0900564 (mpllcon & S3C2443_PLLCON_OFF) ? "off" : "on",
Ben Dooksaf337f32010-04-28 18:03:57 +0900565 print_mhz(pll), print_mhz(fclk),
566 print_mhz(hclk), print_mhz(pclk));
567
568 for (ptr = 0; ptr < ARRAY_SIZE(clksrc_clks); ptr++)
569 s3c_set_clksrc(&clksrc_clks[ptr], true);
570
571 /* ensure usb bus clock is within correct rate of 48MHz */
572
573 if (clk_get_rate(&clk_usb_bus_host.clk) != (48 * 1000 * 1000)) {
574 printk(KERN_INFO "Warning: USB host bus not at 48MHz\n");
575 clk_set_rate(&clk_usb_bus_host.clk, 48*1000*1000);
576 }
577
578 printk("CPU: EPLL %s %ld.%03ld MHz, usb-bus %ld.%03ld MHz\n",
Heiko Stuebner8c3d7c32012-03-03 07:49:12 +0900579 (epllcon & S3C2443_PLLCON_OFF) ? "off" : "on",
Ben Dooksaf337f32010-04-28 18:03:57 +0900580 print_mhz(clk_get_rate(&clk_epll)),
581 print_mhz(clk_get_rate(&clk_usb_bus)));
582}
583
584static struct clk *clks[] __initdata = {
585 &clk_prediv,
586 &clk_mpllref,
587 &clk_mdivclk,
588 &clk_ext,
589 &clk_epll,
590 &clk_usb_bus,
Heiko St?bneraab08ee2011-10-14 15:08:56 +0900591 &clk_armdiv,
Rajeshwari Shindea361d102011-10-24 17:05:58 +0200592 &hsmmc1_clk,
Ben Dooksaf337f32010-04-28 18:03:57 +0900593};
594
595static struct clksrc_clk *clksrcs[] __initdata = {
Heiko Stuebnere3b454f2011-09-27 08:44:37 +0900596 &clk_i2s_eplldiv,
597 &clk_i2s,
Ben Dooksaf337f32010-04-28 18:03:57 +0900598 &clk_usb_bus_host,
599 &clk_epllref,
600 &clk_esysclk,
601 &clk_msysclk,
Heiko St?bneraab08ee2011-10-14 15:08:56 +0900602 &clk_arm,
Ben Dooksaf337f32010-04-28 18:03:57 +0900603};
604
Thomas Abraham0cfb26e2011-10-24 12:08:42 +0200605static struct clk_lookup s3c2443_clk_lookup[] = {
606 CLKDEV_INIT(NULL, "clk_uart_baud1", &s3c24xx_uclk),
607 CLKDEV_INIT(NULL, "clk_uart_baud2", &clk_p),
608 CLKDEV_INIT(NULL, "clk_uart_baud3", &clk_esys_uart.clk),
Rajeshwari Shindea361d102011-10-24 17:05:58 +0200609 CLKDEV_INIT("s3c-sdhci.1", "mmc_busclk.0", &hsmmc1_clk),
Thomas Abraham0cfb26e2011-10-24 12:08:42 +0200610};
611
Ben Dooksaf337f32010-04-28 18:03:57 +0900612void __init s3c2443_common_init_clocks(int xtal, pll_fn get_mpll,
Heiko Stuebnerd9a3bfb2011-10-14 15:08:56 +0900613 unsigned int *divs, int nr_divs,
614 int divmask)
Ben Dooksaf337f32010-04-28 18:03:57 +0900615{
616 int ptr;
617
Heiko Stuebnerd9a3bfb2011-10-14 15:08:56 +0900618 armdiv = divs;
619 nr_armdiv = nr_divs;
620 armdivmask = divmask;
621
Ben Dooksaf337f32010-04-28 18:03:57 +0900622 /* s3c2443 parents h and p clocks from prediv */
623 clk_h.parent = &clk_prediv;
624 clk_p.parent = &clk_prediv;
625
626 clk_usb_bus.parent = &clk_usb_bus_host.clk;
627 clk_epll.parent = &clk_epllref.clk;
628
629 s3c24xx_register_baseclocks(xtal);
630 s3c24xx_register_clocks(clks, ARRAY_SIZE(clks));
631
632 for (ptr = 0; ptr < ARRAY_SIZE(clksrcs); ptr++)
633 s3c_register_clksrc(clksrcs[ptr], 1);
634
635 s3c_register_clksrc(clksrc_clks, ARRAY_SIZE(clksrc_clks));
636 s3c_register_clocks(init_clocks, ARRAY_SIZE(init_clocks));
637
638 /* See s3c2443/etc notes on disabling clocks at init time */
639 s3c_register_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
640 s3c_disable_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
Thomas Abraham0cfb26e2011-10-24 12:08:42 +0200641 clkdev_add_table(s3c2443_clk_lookup, ARRAY_SIZE(s3c2443_clk_lookup));
Ben Dooksaf337f32010-04-28 18:03:57 +0900642
Heiko Stuebner33ccedf2011-10-14 15:08:57 +0900643 s3c2443_common_setup_clocks(get_mpll);
Ben Dooksaf337f32010-04-28 18:03:57 +0900644}