blob: 5e863bff5c7f0ae420fa2d1a98c05d4bcd771d13 [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 Stuebnerb681bfc2012-03-07 02:00:04 -0800171/* hclk divider
172 *
173 * divides the prediv and provides the hclk.
174 */
175
176static unsigned long s3c2443_hclkdiv_getrate(struct clk *clk)
177{
178 unsigned long rate = clk_get_rate(clk->parent);
179 unsigned long clkdiv0 = __raw_readl(S3C2443_CLKDIV0);
180
181 clkdiv0 &= S3C2443_CLKDIV0_HCLKDIV_MASK;
182
183 return rate / (clkdiv0 + 1);
184}
185
186static struct clk_ops clk_h_ops = {
187 .get_rate = s3c2443_hclkdiv_getrate,
188};
189
Heiko St?bneraab08ee2011-10-14 15:08:56 +0900190/* armdiv
191 *
192 * this clock is sourced from msysclk and can have a number of
193 * divider values applied to it to then be fed into armclk.
194*/
195
Heiko Stuebnerd9a3bfb2011-10-14 15:08:56 +0900196static unsigned int *armdiv;
197static int nr_armdiv;
198static int armdivmask;
199
Heiko St?bneraab08ee2011-10-14 15:08:56 +0900200static unsigned long s3c2443_armclk_roundrate(struct clk *clk,
201 unsigned long rate)
202{
203 unsigned long parent = clk_get_rate(clk->parent);
204 unsigned long calc;
205 unsigned best = 256; /* bigger than any value */
206 unsigned div;
207 int ptr;
208
Heiko Stuebnerf9f7c752011-10-14 15:08:56 +0900209 if (!nr_armdiv)
210 return -EINVAL;
211
Heiko St?bneraab08ee2011-10-14 15:08:56 +0900212 for (ptr = 0; ptr < nr_armdiv; ptr++) {
213 div = armdiv[ptr];
Heiko Stuebnerf9f7c752011-10-14 15:08:56 +0900214 if (div) {
Heiko Stuebner866a1c82011-10-14 15:08:57 +0900215 /* cpufreq provides 266mhz as 266666000 not 266666666 */
216 calc = (parent / div / 1000) * 1000;
Heiko Stuebnerf9f7c752011-10-14 15:08:56 +0900217 if (calc <= rate && div < best)
218 best = div;
219 }
Heiko St?bneraab08ee2011-10-14 15:08:56 +0900220 }
221
222 return parent / best;
223}
224
Heiko Stuebner5f33bd72011-10-14 15:08:56 +0900225static unsigned long s3c2443_armclk_getrate(struct clk *clk)
226{
227 unsigned long rate = clk_get_rate(clk->parent);
228 unsigned long clkcon0;
229 int val;
230
Heiko Stuebnerf9f7c752011-10-14 15:08:56 +0900231 if (!nr_armdiv || !armdivmask)
232 return -EINVAL;
233
Heiko Stuebner5f33bd72011-10-14 15:08:56 +0900234 clkcon0 = __raw_readl(S3C2443_CLKDIV0);
235 clkcon0 &= armdivmask;
236 val = clkcon0 >> S3C2443_CLKDIV0_ARMDIV_SHIFT;
237
238 return rate / armdiv[val];
239}
240
Heiko St?bneraab08ee2011-10-14 15:08:56 +0900241static int s3c2443_armclk_setrate(struct clk *clk, unsigned long rate)
242{
243 unsigned long parent = clk_get_rate(clk->parent);
244 unsigned long calc;
245 unsigned div;
246 unsigned best = 256; /* bigger than any value */
247 int ptr;
248 int val = -1;
249
Heiko Stuebnerf9f7c752011-10-14 15:08:56 +0900250 if (!nr_armdiv || !armdivmask)
251 return -EINVAL;
252
Heiko St?bneraab08ee2011-10-14 15:08:56 +0900253 for (ptr = 0; ptr < nr_armdiv; ptr++) {
254 div = armdiv[ptr];
Heiko Stuebnerf9f7c752011-10-14 15:08:56 +0900255 if (div) {
Heiko Stuebner866a1c82011-10-14 15:08:57 +0900256 /* cpufreq provides 266mhz as 266666000 not 266666666 */
257 calc = (parent / div / 1000) * 1000;
Heiko Stuebnerf9f7c752011-10-14 15:08:56 +0900258 if (calc <= rate && div < best) {
259 best = div;
260 val = ptr;
261 }
Heiko St?bneraab08ee2011-10-14 15:08:56 +0900262 }
263 }
264
265 if (val >= 0) {
266 unsigned long clkcon0;
267
268 clkcon0 = __raw_readl(S3C2443_CLKDIV0);
269 clkcon0 &= ~armdivmask;
270 clkcon0 |= val << S3C2443_CLKDIV0_ARMDIV_SHIFT;
271 __raw_writel(clkcon0, S3C2443_CLKDIV0);
272 }
273
274 return (val == -1) ? -EINVAL : 0;
275}
276
277static struct clk clk_armdiv = {
278 .name = "armdiv",
279 .parent = &clk_msysclk.clk,
280 .ops = &(struct clk_ops) {
281 .round_rate = s3c2443_armclk_roundrate,
Heiko Stuebner5f33bd72011-10-14 15:08:56 +0900282 .get_rate = s3c2443_armclk_getrate,
Heiko St?bneraab08ee2011-10-14 15:08:56 +0900283 .set_rate = s3c2443_armclk_setrate,
284 },
285};
286
287/* armclk
288 *
289 * this is the clock fed into the ARM core itself, from armdiv or from hclk.
290 */
291
292static struct clk *clk_arm_sources[] = {
293 [0] = &clk_armdiv,
294 [1] = &clk_h,
295};
296
297static struct clksrc_clk clk_arm = {
298 .clk = {
299 .name = "armclk",
300 },
301 .sources = &(struct clksrc_sources) {
302 .sources = clk_arm_sources,
303 .nr_sources = ARRAY_SIZE(clk_arm_sources),
304 },
305 .reg_src = { .reg = S3C2443_CLKDIV0, .size = 1, .shift = 13 },
306};
307
Ben Dooksaf337f32010-04-28 18:03:57 +0900308/* usbhost
309 *
310 * usb host bus-clock, usually 48MHz to provide USB bus clock timing
311*/
312
313static struct clksrc_clk clk_usb_bus_host = {
314 .clk = {
315 .name = "usb-bus-host-parent",
Ben Dooksaf337f32010-04-28 18:03:57 +0900316 .parent = &clk_esysclk.clk,
317 .ctrlbit = S3C2443_SCLKCON_USBHOST,
318 .enable = s3c2443_clkcon_enable_s,
319 },
320 .reg_div = { .reg = S3C2443_CLKDIV1, .size = 2, .shift = 4 },
321};
322
323/* common clksrc clocks */
324
325static struct clksrc_clk clksrc_clks[] = {
326 {
Ben Dooksaf337f32010-04-28 18:03:57 +0900327 /* camera interface bus-clock, divided down from esysclk */
328 .clk = {
329 .name = "camif-upll", /* same as 2440 name */
Ben Dooksaf337f32010-04-28 18:03:57 +0900330 .parent = &clk_esysclk.clk,
331 .ctrlbit = S3C2443_SCLKCON_CAMCLK,
332 .enable = s3c2443_clkcon_enable_s,
333 },
334 .reg_div = { .reg = S3C2443_CLKDIV1, .size = 4, .shift = 26 },
335 }, {
336 .clk = {
337 .name = "display-if",
Ben Dooksaf337f32010-04-28 18:03:57 +0900338 .parent = &clk_esysclk.clk,
339 .ctrlbit = S3C2443_SCLKCON_DISPCLK,
340 .enable = s3c2443_clkcon_enable_s,
341 },
342 .reg_div = { .reg = S3C2443_CLKDIV1, .size = 8, .shift = 16 },
343 },
344};
345
Thomas Abraham0cfb26e2011-10-24 12:08:42 +0200346static struct clksrc_clk clk_esys_uart = {
347 /* ART baud-rate clock sourced from esysclk via a divisor */
348 .clk = {
349 .name = "uartclk",
350 .parent = &clk_esysclk.clk,
351 },
352 .reg_div = { .reg = S3C2443_CLKDIV1, .size = 4, .shift = 8 },
353};
354
Heiko Stuebnere3b454f2011-09-27 08:44:37 +0900355static struct clk clk_i2s_ext = {
356 .name = "i2s-ext",
357};
358
359/* i2s_eplldiv
360 *
361 * This clock is the output from the I2S divisor of ESYSCLK, and is separate
362 * from the mux that comes after it (cannot merge into one single clock)
363*/
364
365static struct clksrc_clk clk_i2s_eplldiv = {
366 .clk = {
367 .name = "i2s-eplldiv",
368 .parent = &clk_esysclk.clk,
369 },
370 .reg_div = { .reg = S3C2443_CLKDIV1, .size = 4, .shift = 12, },
371};
372
373/* i2s-ref
374 *
375 * i2s bus reference clock, selectable from external, esysclk or epllref
376 *
377 * Note, this used to be two clocks, but was compressed into one.
378*/
379
380static struct clk *clk_i2s_srclist[] = {
381 [0] = &clk_i2s_eplldiv.clk,
382 [1] = &clk_i2s_ext,
383 [2] = &clk_epllref.clk,
384 [3] = &clk_epllref.clk,
385};
386
387static struct clksrc_clk clk_i2s = {
388 .clk = {
389 .name = "i2s-if",
390 .ctrlbit = S3C2443_SCLKCON_I2SCLK,
391 .enable = s3c2443_clkcon_enable_s,
392
393 },
394 .sources = &(struct clksrc_sources) {
395 .sources = clk_i2s_srclist,
396 .nr_sources = ARRAY_SIZE(clk_i2s_srclist),
397 },
398 .reg_src = { .reg = S3C2443_CLKSRC, .size = 2, .shift = 14 },
399};
Ben Dooksaf337f32010-04-28 18:03:57 +0900400
401static struct clk init_clocks_off[] = {
402 {
Heiko Stuebnere3b454f2011-09-27 08:44:37 +0900403 .name = "iis",
404 .parent = &clk_p,
405 .enable = s3c2443_clkcon_enable_p,
406 .ctrlbit = S3C2443_PCLKCON_IIS,
407 }, {
Heiko Stuebner8b069b72011-09-27 08:45:23 +0900408 .name = "hsspi",
409 .parent = &clk_p,
410 .enable = s3c2443_clkcon_enable_p,
411 .ctrlbit = S3C2443_PCLKCON_HSSPI,
412 }, {
Ben Dooksaf337f32010-04-28 18:03:57 +0900413 .name = "adc",
Ben Dooksaf337f32010-04-28 18:03:57 +0900414 .parent = &clk_p,
415 .enable = s3c2443_clkcon_enable_p,
416 .ctrlbit = S3C2443_PCLKCON_ADC,
417 }, {
418 .name = "i2c",
Ben Dooksaf337f32010-04-28 18:03:57 +0900419 .parent = &clk_p,
420 .enable = s3c2443_clkcon_enable_p,
421 .ctrlbit = S3C2443_PCLKCON_IIC,
422 }
423};
424
425static struct clk init_clocks[] = {
426 {
427 .name = "dma",
Ben Dooksaf337f32010-04-28 18:03:57 +0900428 .parent = &clk_h,
429 .enable = s3c2443_clkcon_enable_h,
430 .ctrlbit = S3C2443_HCLKCON_DMA0,
431 }, {
432 .name = "dma",
Ben Dooksaf337f32010-04-28 18:03:57 +0900433 .parent = &clk_h,
434 .enable = s3c2443_clkcon_enable_h,
435 .ctrlbit = S3C2443_HCLKCON_DMA1,
436 }, {
437 .name = "dma",
Ben Dooksaf337f32010-04-28 18:03:57 +0900438 .parent = &clk_h,
439 .enable = s3c2443_clkcon_enable_h,
440 .ctrlbit = S3C2443_HCLKCON_DMA2,
441 }, {
442 .name = "dma",
Ben Dooksaf337f32010-04-28 18:03:57 +0900443 .parent = &clk_h,
444 .enable = s3c2443_clkcon_enable_h,
445 .ctrlbit = S3C2443_HCLKCON_DMA3,
446 }, {
447 .name = "dma",
Ben Dooksaf337f32010-04-28 18:03:57 +0900448 .parent = &clk_h,
449 .enable = s3c2443_clkcon_enable_h,
450 .ctrlbit = S3C2443_HCLKCON_DMA4,
451 }, {
452 .name = "dma",
Ben Dooksaf337f32010-04-28 18:03:57 +0900453 .parent = &clk_h,
454 .enable = s3c2443_clkcon_enable_h,
455 .ctrlbit = S3C2443_HCLKCON_DMA5,
456 }, {
Ben Dooksaf337f32010-04-28 18:03:57 +0900457 .name = "gpio",
Ben Dooksaf337f32010-04-28 18:03:57 +0900458 .parent = &clk_p,
459 .enable = s3c2443_clkcon_enable_p,
460 .ctrlbit = S3C2443_PCLKCON_GPIO,
461 }, {
462 .name = "usb-host",
Ben Dooksaf337f32010-04-28 18:03:57 +0900463 .parent = &clk_h,
464 .enable = s3c2443_clkcon_enable_h,
465 .ctrlbit = S3C2443_HCLKCON_USBH,
466 }, {
467 .name = "usb-device",
Ben Dooksaf337f32010-04-28 18:03:57 +0900468 .parent = &clk_h,
469 .enable = s3c2443_clkcon_enable_h,
470 .ctrlbit = S3C2443_HCLKCON_USBD,
471 }, {
472 .name = "lcd",
Ben Dooksaf337f32010-04-28 18:03:57 +0900473 .parent = &clk_h,
474 .enable = s3c2443_clkcon_enable_h,
475 .ctrlbit = S3C2443_HCLKCON_LCDC,
476
477 }, {
478 .name = "timers",
Ben Dooksaf337f32010-04-28 18:03:57 +0900479 .parent = &clk_p,
480 .enable = s3c2443_clkcon_enable_p,
481 .ctrlbit = S3C2443_PCLKCON_PWMT,
482 }, {
483 .name = "cfc",
Ben Dooksaf337f32010-04-28 18:03:57 +0900484 .parent = &clk_h,
485 .enable = s3c2443_clkcon_enable_h,
486 .ctrlbit = S3C2443_HCLKCON_CFC,
487 }, {
488 .name = "ssmc",
Ben Dooksaf337f32010-04-28 18:03:57 +0900489 .parent = &clk_h,
490 .enable = s3c2443_clkcon_enable_h,
491 .ctrlbit = S3C2443_HCLKCON_SSMC,
492 }, {
493 .name = "uart",
Thomas Abrahame83626f2011-06-14 19:12:26 +0900494 .devname = "s3c2440-uart.0",
Ben Dooksaf337f32010-04-28 18:03:57 +0900495 .parent = &clk_p,
496 .enable = s3c2443_clkcon_enable_p,
497 .ctrlbit = S3C2443_PCLKCON_UART0,
498 }, {
499 .name = "uart",
Thomas Abrahame83626f2011-06-14 19:12:26 +0900500 .devname = "s3c2440-uart.1",
Ben Dooksaf337f32010-04-28 18:03:57 +0900501 .parent = &clk_p,
502 .enable = s3c2443_clkcon_enable_p,
503 .ctrlbit = S3C2443_PCLKCON_UART1,
504 }, {
505 .name = "uart",
Thomas Abrahame83626f2011-06-14 19:12:26 +0900506 .devname = "s3c2440-uart.2",
Ben Dooksaf337f32010-04-28 18:03:57 +0900507 .parent = &clk_p,
508 .enable = s3c2443_clkcon_enable_p,
509 .ctrlbit = S3C2443_PCLKCON_UART2,
510 }, {
511 .name = "uart",
Thomas Abrahame83626f2011-06-14 19:12:26 +0900512 .devname = "s3c2440-uart.3",
Ben Dooksaf337f32010-04-28 18:03:57 +0900513 .parent = &clk_p,
514 .enable = s3c2443_clkcon_enable_p,
515 .ctrlbit = S3C2443_PCLKCON_UART3,
516 }, {
517 .name = "rtc",
Ben Dooksaf337f32010-04-28 18:03:57 +0900518 .parent = &clk_p,
519 .enable = s3c2443_clkcon_enable_p,
520 .ctrlbit = S3C2443_PCLKCON_RTC,
521 }, {
522 .name = "watchdog",
Ben Dooksaf337f32010-04-28 18:03:57 +0900523 .parent = &clk_p,
524 .ctrlbit = S3C2443_PCLKCON_WDT,
525 }, {
526 .name = "ac97",
Ben Dooksaf337f32010-04-28 18:03:57 +0900527 .parent = &clk_p,
528 .ctrlbit = S3C2443_PCLKCON_AC97,
529 }, {
530 .name = "nand",
Ben Dooksaf337f32010-04-28 18:03:57 +0900531 .parent = &clk_h,
532 }, {
533 .name = "usb-bus-host",
Ben Dooksaf337f32010-04-28 18:03:57 +0900534 .parent = &clk_usb_bus_host.clk,
535 }
536};
537
Rajeshwari Shindea361d102011-10-24 17:05:58 +0200538static struct clk hsmmc1_clk = {
539 .name = "hsmmc",
540 .devname = "s3c-sdhci.1",
541 .parent = &clk_h,
542 .enable = s3c2443_clkcon_enable_h,
543 .ctrlbit = S3C2443_HCLKCON_HSMMC,
544};
545
Ben Dooksaf337f32010-04-28 18:03:57 +0900546/* EPLLCON compatible enough to get on/off information */
547
Heiko Stuebner33ccedf2011-10-14 15:08:57 +0900548void __init_or_cpufreq s3c2443_common_setup_clocks(pll_fn get_mpll)
Ben Dooksaf337f32010-04-28 18:03:57 +0900549{
550 unsigned long epllcon = __raw_readl(S3C2443_EPLLCON);
551 unsigned long mpllcon = __raw_readl(S3C2443_MPLLCON);
552 unsigned long clkdiv0 = __raw_readl(S3C2443_CLKDIV0);
553 struct clk *xtal_clk;
554 unsigned long xtal;
555 unsigned long pll;
556 unsigned long fclk;
557 unsigned long hclk;
558 unsigned long pclk;
559 int ptr;
560
561 xtal_clk = clk_get(NULL, "xtal");
562 xtal = clk_get_rate(xtal_clk);
563 clk_put(xtal_clk);
564
565 pll = get_mpll(mpllcon, xtal);
566 clk_msysclk.clk.rate = pll;
567
Heiko Stuebner33ccedf2011-10-14 15:08:57 +0900568 fclk = clk_get_rate(&clk_armdiv);
Heiko Stuebnerb681bfc2012-03-07 02:00:04 -0800569 hclk = clk_get_rate(&clk_h);
Ben Dooksaf337f32010-04-28 18:03:57 +0900570 pclk = hclk / ((clkdiv0 & S3C2443_CLKDIV0_HALF_PCLK) ? 2 : 1);
571
572 s3c24xx_setup_clocks(fclk, hclk, pclk);
573
574 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 +0900575 (mpllcon & S3C2443_PLLCON_OFF) ? "off" : "on",
Ben Dooksaf337f32010-04-28 18:03:57 +0900576 print_mhz(pll), print_mhz(fclk),
577 print_mhz(hclk), print_mhz(pclk));
578
579 for (ptr = 0; ptr < ARRAY_SIZE(clksrc_clks); ptr++)
580 s3c_set_clksrc(&clksrc_clks[ptr], true);
581
582 /* ensure usb bus clock is within correct rate of 48MHz */
583
584 if (clk_get_rate(&clk_usb_bus_host.clk) != (48 * 1000 * 1000)) {
585 printk(KERN_INFO "Warning: USB host bus not at 48MHz\n");
586 clk_set_rate(&clk_usb_bus_host.clk, 48*1000*1000);
587 }
588
589 printk("CPU: EPLL %s %ld.%03ld MHz, usb-bus %ld.%03ld MHz\n",
Heiko Stuebner8c3d7c32012-03-03 07:49:12 +0900590 (epllcon & S3C2443_PLLCON_OFF) ? "off" : "on",
Ben Dooksaf337f32010-04-28 18:03:57 +0900591 print_mhz(clk_get_rate(&clk_epll)),
592 print_mhz(clk_get_rate(&clk_usb_bus)));
593}
594
595static struct clk *clks[] __initdata = {
596 &clk_prediv,
597 &clk_mpllref,
598 &clk_mdivclk,
599 &clk_ext,
600 &clk_epll,
601 &clk_usb_bus,
Heiko St?bneraab08ee2011-10-14 15:08:56 +0900602 &clk_armdiv,
Rajeshwari Shindea361d102011-10-24 17:05:58 +0200603 &hsmmc1_clk,
Ben Dooksaf337f32010-04-28 18:03:57 +0900604};
605
606static struct clksrc_clk *clksrcs[] __initdata = {
Heiko Stuebnere3b454f2011-09-27 08:44:37 +0900607 &clk_i2s_eplldiv,
608 &clk_i2s,
Ben Dooksaf337f32010-04-28 18:03:57 +0900609 &clk_usb_bus_host,
610 &clk_epllref,
611 &clk_esysclk,
612 &clk_msysclk,
Heiko St?bneraab08ee2011-10-14 15:08:56 +0900613 &clk_arm,
Ben Dooksaf337f32010-04-28 18:03:57 +0900614};
615
Thomas Abraham0cfb26e2011-10-24 12:08:42 +0200616static struct clk_lookup s3c2443_clk_lookup[] = {
617 CLKDEV_INIT(NULL, "clk_uart_baud1", &s3c24xx_uclk),
618 CLKDEV_INIT(NULL, "clk_uart_baud2", &clk_p),
619 CLKDEV_INIT(NULL, "clk_uart_baud3", &clk_esys_uart.clk),
Rajeshwari Shindea361d102011-10-24 17:05:58 +0200620 CLKDEV_INIT("s3c-sdhci.1", "mmc_busclk.0", &hsmmc1_clk),
Thomas Abraham0cfb26e2011-10-24 12:08:42 +0200621};
622
Ben Dooksaf337f32010-04-28 18:03:57 +0900623void __init s3c2443_common_init_clocks(int xtal, pll_fn get_mpll,
Heiko Stuebnerd9a3bfb2011-10-14 15:08:56 +0900624 unsigned int *divs, int nr_divs,
625 int divmask)
Ben Dooksaf337f32010-04-28 18:03:57 +0900626{
627 int ptr;
628
Heiko Stuebnerd9a3bfb2011-10-14 15:08:56 +0900629 armdiv = divs;
630 nr_armdiv = nr_divs;
631 armdivmask = divmask;
632
Ben Dooksaf337f32010-04-28 18:03:57 +0900633 /* s3c2443 parents h and p clocks from prediv */
634 clk_h.parent = &clk_prediv;
Heiko Stuebnerb681bfc2012-03-07 02:00:04 -0800635 clk_h.ops = &clk_h_ops;
636
Ben Dooksaf337f32010-04-28 18:03:57 +0900637 clk_p.parent = &clk_prediv;
638
639 clk_usb_bus.parent = &clk_usb_bus_host.clk;
640 clk_epll.parent = &clk_epllref.clk;
641
642 s3c24xx_register_baseclocks(xtal);
643 s3c24xx_register_clocks(clks, ARRAY_SIZE(clks));
644
645 for (ptr = 0; ptr < ARRAY_SIZE(clksrcs); ptr++)
646 s3c_register_clksrc(clksrcs[ptr], 1);
647
648 s3c_register_clksrc(clksrc_clks, ARRAY_SIZE(clksrc_clks));
649 s3c_register_clocks(init_clocks, ARRAY_SIZE(init_clocks));
650
651 /* See s3c2443/etc notes on disabling clocks at init time */
652 s3c_register_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
653 s3c_disable_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
Thomas Abraham0cfb26e2011-10-24 12:08:42 +0200654 clkdev_add_table(s3c2443_clk_lookup, ARRAY_SIZE(s3c2443_clk_lookup));
Ben Dooksaf337f32010-04-28 18:03:57 +0900655
Heiko Stuebner33ccedf2011-10-14 15:08:57 +0900656 s3c2443_common_setup_clocks(get_mpll);
Ben Dooksaf337f32010-04-28 18:03:57 +0900657}