1 /* linux/arch/arm/mach-s3c2443/clock.c
3 * Copyright (c) 2007 Simtec Electronics
4 * Ben Dooks <ben@simtec.co.uk>
6 * S3C2443 Clock control support
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <linux/init.h>
24 #include <linux/module.h>
25 #include <linux/kernel.h>
26 #include <linux/list.h>
27 #include <linux/errno.h>
28 #include <linux/err.h>
29 #include <linux/sysdev.h>
30 #include <linux/clk.h>
31 #include <linux/mutex.h>
32 #include <linux/serial_core.h>
35 #include <asm/mach/map.h>
37 #include <mach/hardware.h>
39 #include <mach/regs-s3c2443-clock.h>
41 #include <plat/cpu-freq.h>
43 #include <plat/s3c2443.h>
44 #include <plat/clock.h>
47 /* We currently have to assume that the system is running
48 * from the XTPll input, and that all ***REFCLKs are being
49 * fed from it, as we cannot read the state of OM[4] from
52 * It would be possible for each board initialisation to
53 * set the correct muxing at initialisation
56 static int s3c2443_clkcon_enable_h(struct clk *clk, int enable)
58 unsigned int clocks = clk->ctrlbit;
61 clkcon = __raw_readl(S3C2443_HCLKCON);
68 __raw_writel(clkcon, S3C2443_HCLKCON);
73 static int s3c2443_clkcon_enable_p(struct clk *clk, int enable)
75 unsigned int clocks = clk->ctrlbit;
78 clkcon = __raw_readl(S3C2443_PCLKCON);
85 __raw_writel(clkcon, S3C2443_PCLKCON);
90 static int s3c2443_clkcon_enable_s(struct clk *clk, int enable)
92 unsigned int clocks = clk->ctrlbit;
95 clkcon = __raw_readl(S3C2443_SCLKCON);
102 __raw_writel(clkcon, S3C2443_SCLKCON);
107 static unsigned long s3c2443_roundrate_clksrc(struct clk *clk,
111 unsigned long parent_rate = clk_get_rate(clk->parent);
114 if (rate > parent_rate)
117 /* note, we remove the +/- 1 calculations as they cancel out */
119 div = (rate / parent_rate);
126 return parent_rate / div;
129 static unsigned long s3c2443_roundrate_clksrc4(struct clk *clk,
132 return s3c2443_roundrate_clksrc(clk, rate, 4);
135 static unsigned long s3c2443_roundrate_clksrc16(struct clk *clk,
138 return s3c2443_roundrate_clksrc(clk, rate, 16);
141 static unsigned long s3c2443_roundrate_clksrc256(struct clk *clk,
144 return s3c2443_roundrate_clksrc(clk, rate, 256);
147 /* clock selections */
149 static struct clk clk_mpllref = {
156 static struct clk clk_mpll = {
158 .parent = &clk_mpllref,
163 static struct clk clk_i2s_ext = {
168 static int s3c2443_setparent_epllref(struct clk *clk, struct clk *parent)
170 unsigned long clksrc = __raw_readl(S3C2443_CLKSRC);
172 clksrc &= ~S3C2443_CLKSRC_EPLLREF_MASK;
174 if (parent == &clk_xtal)
175 clksrc |= S3C2443_CLKSRC_EPLLREF_XTAL;
176 else if (parent == &clk_ext)
177 clksrc |= S3C2443_CLKSRC_EPLLREF_EXTCLK;
178 else if (parent != &clk_mpllref)
181 __raw_writel(clksrc, S3C2443_CLKSRC);
182 clk->parent = parent;
187 static struct clk clk_epllref = {
190 .ops = &(struct clk_ops) {
191 .set_parent = s3c2443_setparent_epllref,
195 static unsigned long s3c2443_getrate_mdivclk(struct clk *clk)
197 unsigned long parent_rate = clk_get_rate(clk->parent);
198 unsigned long div = __raw_readl(S3C2443_CLKDIV0);
200 div &= S3C2443_CLKDIV0_EXTDIV_MASK;
201 div >>= (S3C2443_CLKDIV0_EXTDIV_SHIFT-1); /* x2 */
203 return parent_rate / (div + 1);
206 static struct clk clk_mdivclk = {
208 .parent = &clk_mpllref,
210 .ops = &(struct clk_ops) {
211 .get_rate = s3c2443_getrate_mdivclk,
215 static int s3c2443_setparent_msysclk(struct clk *clk, struct clk *parent)
217 unsigned long clksrc = __raw_readl(S3C2443_CLKSRC);
219 clksrc &= ~(S3C2443_CLKSRC_MSYSCLK_MPLL |
220 S3C2443_CLKSRC_EXTCLK_DIV);
222 if (parent == &clk_mpll)
223 clksrc |= S3C2443_CLKSRC_MSYSCLK_MPLL;
224 else if (parent == &clk_mdivclk)
225 clksrc |= S3C2443_CLKSRC_EXTCLK_DIV;
226 else if (parent != &clk_mpllref)
229 __raw_writel(clksrc, S3C2443_CLKSRC);
230 clk->parent = parent;
235 static struct clk clk_msysclk = {
239 .ops = &(struct clk_ops) {
240 .set_parent = s3c2443_setparent_msysclk,
246 * this clock is sourced from msysclk and can have a number of
247 * divider values applied to it to then be fed into armclk.
250 static struct clk clk_armdiv = {
253 .parent = &clk_msysclk,
258 * this is the clock fed into the ARM core itself, either from
259 * armdiv or from hclk.
262 static int s3c2443_setparent_armclk(struct clk *clk, struct clk *parent)
264 unsigned long clkdiv0;
266 clkdiv0 = __raw_readl(S3C2443_CLKDIV0);
268 if (parent == &clk_armdiv)
269 clkdiv0 &= ~S3C2443_CLKDIV0_DVS;
270 else if (parent == &clk_h)
271 clkdiv0 |= S3C2443_CLKDIV0_DVS;
275 __raw_writel(clkdiv0, S3C2443_CLKDIV0);
279 static struct clk clk_arm = {
282 .ops = &(struct clk_ops) {
283 .set_parent = s3c2443_setparent_armclk,
289 * this is sourced from either the EPLL or the EPLLref clock
292 static int s3c2443_setparent_esysclk(struct clk *clk, struct clk *parent)
294 unsigned long clksrc = __raw_readl(S3C2443_CLKSRC);
296 if (parent == &clk_epll)
297 clksrc |= S3C2443_CLKSRC_ESYSCLK_EPLL;
298 else if (parent == &clk_epllref)
299 clksrc &= ~S3C2443_CLKSRC_ESYSCLK_EPLL;
303 __raw_writel(clksrc, S3C2443_CLKSRC);
304 clk->parent = parent;
309 static struct clk clk_esysclk = {
313 .ops = &(struct clk_ops) {
314 .set_parent = s3c2443_setparent_esysclk,
320 * UART baud-rate clock sourced from esysclk via a divisor
323 static unsigned long s3c2443_getrate_uart(struct clk *clk)
325 unsigned long parent_rate = clk_get_rate(clk->parent);
326 unsigned long div = __raw_readl(S3C2443_CLKDIV1);
328 div &= S3C2443_CLKDIV1_UARTDIV_MASK;
329 div >>= S3C2443_CLKDIV1_UARTDIV_SHIFT;
331 return parent_rate / (div + 1);
335 static int s3c2443_setrate_uart(struct clk *clk, unsigned long rate)
337 unsigned long parent_rate = clk_get_rate(clk->parent);
338 unsigned long clkdivn = __raw_readl(S3C2443_CLKDIV1);
340 rate = s3c2443_roundrate_clksrc16(clk, rate);
341 rate = parent_rate / rate;
343 clkdivn &= ~S3C2443_CLKDIV1_UARTDIV_MASK;
344 clkdivn |= (rate - 1) << S3C2443_CLKDIV1_UARTDIV_SHIFT;
346 __raw_writel(clkdivn, S3C2443_CLKDIV1);
350 static struct clk clk_uart = {
353 .parent = &clk_esysclk,
354 .ops = &(struct clk_ops) {
355 .get_rate = s3c2443_getrate_uart,
356 .set_rate = s3c2443_setrate_uart,
357 .round_rate = s3c2443_roundrate_clksrc16,
363 * high-speed spi clock, sourced from esysclk
366 static unsigned long s3c2443_getrate_hsspi(struct clk *clk)
368 unsigned long parent_rate = clk_get_rate(clk->parent);
369 unsigned long div = __raw_readl(S3C2443_CLKDIV1);
371 div &= S3C2443_CLKDIV1_HSSPIDIV_MASK;
372 div >>= S3C2443_CLKDIV1_HSSPIDIV_SHIFT;
374 return parent_rate / (div + 1);
378 static int s3c2443_setrate_hsspi(struct clk *clk, unsigned long rate)
380 unsigned long parent_rate = clk_get_rate(clk->parent);
381 unsigned long clkdivn = __raw_readl(S3C2443_CLKDIV1);
383 rate = s3c2443_roundrate_clksrc4(clk, rate);
384 rate = parent_rate / rate;
386 clkdivn &= ~S3C2443_CLKDIV1_HSSPIDIV_MASK;
387 clkdivn |= (rate - 1) << S3C2443_CLKDIV1_HSSPIDIV_SHIFT;
389 __raw_writel(clkdivn, S3C2443_CLKDIV1);
393 static struct clk clk_hsspi = {
396 .parent = &clk_esysclk,
397 .ctrlbit = S3C2443_SCLKCON_HSSPICLK,
398 .enable = s3c2443_clkcon_enable_s,
399 .ops = &(struct clk_ops) {
400 .get_rate = s3c2443_getrate_hsspi,
401 .set_rate = s3c2443_setrate_hsspi,
402 .round_rate = s3c2443_roundrate_clksrc4,
408 * usb host bus-clock, usually 48MHz to provide USB bus clock timing
411 static unsigned long s3c2443_getrate_usbhost(struct clk *clk)
413 unsigned long parent_rate = clk_get_rate(clk->parent);
414 unsigned long div = __raw_readl(S3C2443_CLKDIV1);
416 div &= S3C2443_CLKDIV1_USBHOSTDIV_MASK;
417 div >>= S3C2443_CLKDIV1_USBHOSTDIV_SHIFT;
419 return parent_rate / (div + 1);
422 static int s3c2443_setrate_usbhost(struct clk *clk, unsigned long rate)
424 unsigned long parent_rate = clk_get_rate(clk->parent);
425 unsigned long clkdivn = __raw_readl(S3C2443_CLKDIV1);
427 rate = s3c2443_roundrate_clksrc4(clk, rate);
428 rate = parent_rate / rate;
430 clkdivn &= ~S3C2443_CLKDIV1_USBHOSTDIV_MASK;
431 clkdivn |= (rate - 1) << S3C2443_CLKDIV1_USBHOSTDIV_SHIFT;
433 __raw_writel(clkdivn, S3C2443_CLKDIV1);
437 static struct clk clk_usb_bus_host = {
438 .name = "usb-bus-host-parent",
440 .parent = &clk_esysclk,
441 .ctrlbit = S3C2443_SCLKCON_USBHOST,
442 .enable = s3c2443_clkcon_enable_s,
443 .ops = &(struct clk_ops) {
444 .get_rate = s3c2443_getrate_usbhost,
445 .set_rate = s3c2443_setrate_usbhost,
446 .round_rate = s3c2443_roundrate_clksrc4,
452 * this clock is sourced from epll, and is fed through a divider,
453 * to a mux controlled by sclkcon where either it or a extclk can
454 * be fed to the hsmmc block
457 static unsigned long s3c2443_getrate_hsmmc_div(struct clk *clk)
459 unsigned long parent_rate = clk_get_rate(clk->parent);
460 unsigned long div = __raw_readl(S3C2443_CLKDIV1);
462 div &= S3C2443_CLKDIV1_HSMMCDIV_MASK;
463 div >>= S3C2443_CLKDIV1_HSMMCDIV_SHIFT;
465 return parent_rate / (div + 1);
468 static int s3c2443_setrate_hsmmc_div(struct clk *clk, unsigned long rate)
470 unsigned long parent_rate = clk_get_rate(clk->parent);
471 unsigned long clkdivn = __raw_readl(S3C2443_CLKDIV1);
473 rate = s3c2443_roundrate_clksrc4(clk, rate);
474 rate = parent_rate / rate;
476 clkdivn &= ~S3C2443_CLKDIV1_HSMMCDIV_MASK;
477 clkdivn |= (rate - 1) << S3C2443_CLKDIV1_HSMMCDIV_SHIFT;
479 __raw_writel(clkdivn, S3C2443_CLKDIV1);
483 static struct clk clk_hsmmc_div = {
486 .parent = &clk_esysclk,
487 .ops = &(struct clk_ops) {
488 .get_rate = s3c2443_getrate_hsmmc_div,
489 .set_rate = s3c2443_setrate_hsmmc_div,
490 .round_rate = s3c2443_roundrate_clksrc4,
494 static int s3c2443_setparent_hsmmc(struct clk *clk, struct clk *parent)
496 unsigned long clksrc = __raw_readl(S3C2443_SCLKCON);
498 clksrc &= ~(S3C2443_SCLKCON_HSMMCCLK_EXT |
499 S3C2443_SCLKCON_HSMMCCLK_EPLL);
501 if (parent == &clk_epll)
502 clksrc |= S3C2443_SCLKCON_HSMMCCLK_EPLL;
503 else if (parent == &clk_ext)
504 clksrc |= S3C2443_SCLKCON_HSMMCCLK_EXT;
508 if (clk->usage > 0) {
509 __raw_writel(clksrc, S3C2443_SCLKCON);
512 clk->parent = parent;
516 static int s3c2443_enable_hsmmc(struct clk *clk, int enable)
518 return s3c2443_setparent_hsmmc(clk, clk->parent);
521 static struct clk clk_hsmmc = {
524 .parent = &clk_hsmmc_div,
525 .enable = s3c2443_enable_hsmmc,
526 .ops = &(struct clk_ops) {
527 .set_parent = s3c2443_setparent_hsmmc,
533 * this clock is the output from the i2s divisor of esysclk
536 static unsigned long s3c2443_getrate_i2s_eplldiv(struct clk *clk)
538 unsigned long parent_rate = clk_get_rate(clk->parent);
539 unsigned long div = __raw_readl(S3C2443_CLKDIV1);
541 div &= S3C2443_CLKDIV1_I2SDIV_MASK;
542 div >>= S3C2443_CLKDIV1_I2SDIV_SHIFT;
544 return parent_rate / (div + 1);
547 static int s3c2443_setrate_i2s_eplldiv(struct clk *clk, unsigned long rate)
549 unsigned long parent_rate = clk_get_rate(clk->parent);
550 unsigned long clkdivn = __raw_readl(S3C2443_CLKDIV1);
552 rate = s3c2443_roundrate_clksrc16(clk, rate);
553 rate = parent_rate / rate;
555 clkdivn &= ~S3C2443_CLKDIV1_I2SDIV_MASK;
556 clkdivn |= (rate - 1) << S3C2443_CLKDIV1_I2SDIV_SHIFT;
558 __raw_writel(clkdivn, S3C2443_CLKDIV1);
562 static struct clk clk_i2s_eplldiv = {
563 .name = "i2s-eplldiv",
565 .parent = &clk_esysclk,
566 .ops = &(struct clk_ops) {
567 .get_rate = s3c2443_getrate_i2s_eplldiv,
568 .set_rate = s3c2443_setrate_i2s_eplldiv,
569 .round_rate = s3c2443_roundrate_clksrc16,
575 * i2s bus reference clock, selectable from external, esysclk or epllref
578 static int s3c2443_setparent_i2s(struct clk *clk, struct clk *parent)
580 unsigned long clksrc = __raw_readl(S3C2443_CLKSRC);
582 clksrc &= ~S3C2443_CLKSRC_I2S_MASK;
584 if (parent == &clk_epllref)
585 clksrc |= S3C2443_CLKSRC_I2S_EPLLREF;
586 else if (parent == &clk_i2s_ext)
587 clksrc |= S3C2443_CLKSRC_I2S_EXT;
588 else if (parent != &clk_i2s_eplldiv)
591 clk->parent = parent;
592 __raw_writel(clksrc, S3C2443_CLKSRC);
597 static struct clk clk_i2s = {
600 .parent = &clk_i2s_eplldiv,
601 .ctrlbit = S3C2443_SCLKCON_I2SCLK,
602 .enable = s3c2443_clkcon_enable_s,
603 .ops = &(struct clk_ops) {
604 .set_parent = s3c2443_setparent_i2s,
610 * camera interface bus-clock, divided down from esysclk
613 static unsigned long s3c2443_getrate_cam(struct clk *clk)
615 unsigned long parent_rate = clk_get_rate(clk->parent);
616 unsigned long div = __raw_readl(S3C2443_CLKDIV1);
618 div &= S3C2443_CLKDIV1_CAMDIV_MASK;
619 div >>= S3C2443_CLKDIV1_CAMDIV_SHIFT;
621 return parent_rate / (div + 1);
624 static int s3c2443_setrate_cam(struct clk *clk, unsigned long rate)
626 unsigned long parent_rate = clk_get_rate(clk->parent);
627 unsigned long clkdiv1 = __raw_readl(S3C2443_CLKDIV1);
629 rate = s3c2443_roundrate_clksrc16(clk, rate);
630 rate = parent_rate / rate;
632 clkdiv1 &= ~S3C2443_CLKDIV1_CAMDIV_MASK;
633 clkdiv1 |= (rate - 1) << S3C2443_CLKDIV1_CAMDIV_SHIFT;
635 __raw_writel(clkdiv1, S3C2443_CLKDIV1);
639 static struct clk clk_cam = {
640 .name = "camif-upll", /* same as 2440 name */
642 .parent = &clk_esysclk,
643 .ctrlbit = S3C2443_SCLKCON_CAMCLK,
644 .enable = s3c2443_clkcon_enable_s,
645 .ops = &(struct clk_ops) {
646 .get_rate = s3c2443_getrate_cam,
647 .set_rate = s3c2443_setrate_cam,
648 .round_rate = s3c2443_roundrate_clksrc16,
654 * display interface clock, divided from esysclk
657 static unsigned long s3c2443_getrate_display(struct clk *clk)
659 unsigned long parent_rate = clk_get_rate(clk->parent);
660 unsigned long div = __raw_readl(S3C2443_CLKDIV1);
662 div &= S3C2443_CLKDIV1_DISPDIV_MASK;
663 div >>= S3C2443_CLKDIV1_DISPDIV_SHIFT;
665 return parent_rate / (div + 1);
668 static int s3c2443_setrate_display(struct clk *clk, unsigned long rate)
670 unsigned long parent_rate = clk_get_rate(clk->parent);
671 unsigned long clkdivn = __raw_readl(S3C2443_CLKDIV1);
673 rate = s3c2443_roundrate_clksrc256(clk, rate);
674 rate = parent_rate / rate;
676 clkdivn &= ~S3C2443_CLKDIV1_UARTDIV_MASK;
677 clkdivn |= (rate - 1) << S3C2443_CLKDIV1_UARTDIV_SHIFT;
679 __raw_writel(clkdivn, S3C2443_CLKDIV1);
683 static struct clk clk_display = {
684 .name = "display-if",
686 .parent = &clk_esysclk,
687 .ctrlbit = S3C2443_SCLKCON_DISPCLK,
688 .enable = s3c2443_clkcon_enable_s,
689 .ops = &(struct clk_ops) {
690 .get_rate = s3c2443_getrate_display,
691 .set_rate = s3c2443_setrate_display,
692 .round_rate = s3c2443_roundrate_clksrc256,
698 * this divides the msysclk down to pass to h/p/etc.
701 static unsigned long s3c2443_prediv_getrate(struct clk *clk)
703 unsigned long rate = clk_get_rate(clk->parent);
704 unsigned long clkdiv0 = __raw_readl(S3C2443_CLKDIV0);
706 clkdiv0 &= S3C2443_CLKDIV0_PREDIV_MASK;
707 clkdiv0 >>= S3C2443_CLKDIV0_PREDIV_SHIFT;
709 return rate / (clkdiv0 + 1);
712 static struct clk clk_prediv = {
715 .parent = &clk_msysclk,
716 .ops = &(struct clk_ops) {
717 .get_rate = s3c2443_prediv_getrate,
721 /* standard clock definitions */
723 static struct clk init_clocks_disable[] = {
732 .enable = s3c2443_clkcon_enable_p,
733 .ctrlbit = S3C2443_PCLKCON_SDI,
738 .enable = s3c2443_clkcon_enable_p,
739 .ctrlbit = S3C2443_PCLKCON_ADC,
744 .enable = s3c2443_clkcon_enable_p,
745 .ctrlbit = S3C2443_PCLKCON_IIC,
750 .enable = s3c2443_clkcon_enable_p,
751 .ctrlbit = S3C2443_PCLKCON_IIS,
756 .enable = s3c2443_clkcon_enable_p,
757 .ctrlbit = S3C2443_PCLKCON_SPI0,
762 .enable = s3c2443_clkcon_enable_p,
763 .ctrlbit = S3C2443_PCLKCON_SPI1,
767 static struct clk init_clocks[] = {
772 .enable = s3c2443_clkcon_enable_h,
773 .ctrlbit = S3C2443_HCLKCON_DMA0,
778 .enable = s3c2443_clkcon_enable_h,
779 .ctrlbit = S3C2443_HCLKCON_DMA1,
784 .enable = s3c2443_clkcon_enable_h,
785 .ctrlbit = S3C2443_HCLKCON_DMA2,
790 .enable = s3c2443_clkcon_enable_h,
791 .ctrlbit = S3C2443_HCLKCON_DMA3,
796 .enable = s3c2443_clkcon_enable_h,
797 .ctrlbit = S3C2443_HCLKCON_DMA4,
802 .enable = s3c2443_clkcon_enable_h,
803 .ctrlbit = S3C2443_HCLKCON_DMA5,
808 .enable = s3c2443_clkcon_enable_h,
809 .ctrlbit = S3C2443_HCLKCON_LCDC,
814 .enable = s3c2443_clkcon_enable_p,
815 .ctrlbit = S3C2443_PCLKCON_GPIO,
820 .enable = s3c2443_clkcon_enable_h,
821 .ctrlbit = S3C2443_HCLKCON_USBH,
823 .name = "usb-device",
826 .enable = s3c2443_clkcon_enable_h,
827 .ctrlbit = S3C2443_HCLKCON_USBD,
832 .enable = s3c2443_clkcon_enable_h,
833 .ctrlbit = S3C2443_HCLKCON_HSMMC,
838 .enable = s3c2443_clkcon_enable_h,
839 .ctrlbit = S3C2443_HCLKCON_CFC,
844 .enable = s3c2443_clkcon_enable_h,
845 .ctrlbit = S3C2443_HCLKCON_SSMC,
850 .enable = s3c2443_clkcon_enable_p,
851 .ctrlbit = S3C2443_PCLKCON_PWMT,
856 .enable = s3c2443_clkcon_enable_p,
857 .ctrlbit = S3C2443_PCLKCON_UART0,
862 .enable = s3c2443_clkcon_enable_p,
863 .ctrlbit = S3C2443_PCLKCON_UART1,
868 .enable = s3c2443_clkcon_enable_p,
869 .ctrlbit = S3C2443_PCLKCON_UART2,
874 .enable = s3c2443_clkcon_enable_p,
875 .ctrlbit = S3C2443_PCLKCON_UART3,
880 .enable = s3c2443_clkcon_enable_p,
881 .ctrlbit = S3C2443_PCLKCON_RTC,
886 .ctrlbit = S3C2443_PCLKCON_WDT,
888 .name = "usb-bus-host",
890 .parent = &clk_usb_bus_host,
895 .ctrlbit = S3C2443_PCLKCON_AC97,
899 /* clocks to add where we need to check their parentage */
901 /* s3c2443_clk_initparents
903 * Initialise the parents for the clocks that we get at start-time
906 static int __init clk_init_set_parent(struct clk *clk, struct clk *parent)
908 printk(KERN_DEBUG "clock %s: parent %s\n", clk->name, parent->name);
909 return clk_set_parent(clk, parent);
912 static void __init s3c2443_clk_initparents(void)
914 unsigned long clksrc = __raw_readl(S3C2443_CLKSRC);
917 switch (clksrc & S3C2443_CLKSRC_EPLLREF_MASK) {
918 case S3C2443_CLKSRC_EPLLREF_EXTCLK:
922 case S3C2443_CLKSRC_EPLLREF_XTAL:
927 case S3C2443_CLKSRC_EPLLREF_MPLLREF:
928 case S3C2443_CLKSRC_EPLLREF_MPLLREF2:
929 parent = &clk_mpllref;
933 clk_init_set_parent(&clk_epllref, parent);
935 switch (clksrc & S3C2443_CLKSRC_I2S_MASK) {
936 case S3C2443_CLKSRC_I2S_EXT:
937 parent = &clk_i2s_ext;
940 case S3C2443_CLKSRC_I2S_EPLLDIV:
942 parent = &clk_i2s_eplldiv;
945 case S3C2443_CLKSRC_I2S_EPLLREF:
946 case S3C2443_CLKSRC_I2S_EPLLREF3:
947 parent = &clk_epllref;
950 clk_init_set_parent(&clk_i2s, &clk_epllref);
954 parent = (clksrc & S3C2443_CLKSRC_ESYSCLK_EPLL) ?
955 &clk_epll : &clk_epllref;
957 clk_init_set_parent(&clk_esysclk, parent);
961 if (clksrc & S3C2443_CLKSRC_MSYSCLK_MPLL) {
964 parent = (clksrc & S3C2443_CLKSRC_EXTCLK_DIV) ?
965 &clk_mdivclk : &clk_mpllref;
968 clk_init_set_parent(&clk_msysclk, parent);
972 if (__raw_readl(S3C2443_CLKDIV0) & S3C2443_CLKDIV0_DVS)
975 parent = &clk_armdiv;
977 clk_init_set_parent(&clk_arm, parent);
980 /* armdiv divisor table */
982 static unsigned int armdiv[16] = {
983 [S3C2443_CLKDIV0_ARMDIV_1 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 1,
984 [S3C2443_CLKDIV0_ARMDIV_2 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 2,
985 [S3C2443_CLKDIV0_ARMDIV_3 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 3,
986 [S3C2443_CLKDIV0_ARMDIV_4 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 4,
987 [S3C2443_CLKDIV0_ARMDIV_6 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 6,
988 [S3C2443_CLKDIV0_ARMDIV_8 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 8,
989 [S3C2443_CLKDIV0_ARMDIV_12 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 12,
990 [S3C2443_CLKDIV0_ARMDIV_16 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 16,
993 static inline unsigned int s3c2443_fclk_div(unsigned long clkcon0)
995 clkcon0 &= S3C2443_CLKDIV0_ARMDIV_MASK;
997 return armdiv[clkcon0 >> S3C2443_CLKDIV0_ARMDIV_SHIFT];
1000 static inline unsigned long s3c2443_get_hdiv(unsigned long clkcon0)
1002 clkcon0 &= S3C2443_CLKDIV0_HCLKDIV_MASK;
1007 /* clocks to add straight away */
1009 static struct clk *clks[] __initdata = {
1031 void __init_or_cpufreq s3c2443_setup_clocks(void)
1033 unsigned long mpllcon = __raw_readl(S3C2443_MPLLCON);
1034 unsigned long clkdiv0 = __raw_readl(S3C2443_CLKDIV0);
1035 struct clk *xtal_clk;
1042 xtal_clk = clk_get(NULL, "xtal");
1043 xtal = clk_get_rate(xtal_clk);
1046 pll = s3c2443_get_mpll(mpllcon, xtal);
1047 clk_msysclk.rate = pll;
1049 fclk = pll / s3c2443_fclk_div(clkdiv0);
1050 hclk = s3c2443_prediv_getrate(&clk_prediv);
1051 hclk /= s3c2443_get_hdiv(clkdiv0);
1052 pclk = hclk / ((clkdiv0 & S3C2443_CLKDIV0_HALF_PCLK) ? 2 : 1);
1054 s3c24xx_setup_clocks(fclk, hclk, pclk);
1056 printk("S3C2443: mpll %s %ld.%03ld MHz, cpu %ld.%03ld MHz, mem %ld.%03ld MHz, pclk %ld.%03ld MHz\n",
1057 (mpllcon & S3C2443_PLLCON_OFF) ? "off":"on",
1058 print_mhz(pll), print_mhz(fclk),
1059 print_mhz(hclk), print_mhz(pclk));
1061 s3c24xx_setup_clocks(fclk, hclk, pclk);
1064 void __init s3c2443_init_clocks(int xtal)
1067 unsigned long epllcon = __raw_readl(S3C2443_EPLLCON);
1071 /* s3c2443 parents h and p clocks from prediv */
1072 clk_h.parent = &clk_prediv;
1073 clk_p.parent = &clk_prediv;
1075 s3c24xx_register_baseclocks(xtal);
1076 s3c2443_setup_clocks();
1077 s3c2443_clk_initparents();
1079 for (ptr = 0; ptr < ARRAY_SIZE(clks); ptr++) {
1082 ret = s3c24xx_register_clock(clkp);
1084 printk(KERN_ERR "Failed to register clock %s (%d)\n",
1089 clk_epll.rate = s3c2443_get_epll(epllcon, xtal);
1090 clk_epll.parent = &clk_epllref;
1091 clk_usb_bus.parent = &clk_usb_bus_host;
1093 /* ensure usb bus clock is within correct rate of 48MHz */
1095 if (clk_get_rate(&clk_usb_bus_host) != (48 * 1000 * 1000)) {
1096 printk(KERN_INFO "Warning: USB host bus not at 48MHz\n");
1097 clk_set_rate(&clk_usb_bus_host, 48*1000*1000);
1100 printk("S3C2443: epll %s %ld.%03ld MHz, usb-bus %ld.%03ld MHz\n",
1101 (epllcon & S3C2443_PLLCON_OFF) ? "off":"on",
1102 print_mhz(clk_get_rate(&clk_epll)),
1103 print_mhz(clk_get_rate(&clk_usb_bus)));
1105 /* register clocks from clock array */
1107 s3c_register_clocks(init_clocks, ARRAY_SIZE(init_clocks));
1109 /* We must be careful disabling the clocks we are not intending to
1110 * be using at boot time, as subsystems such as the LCD which do
1111 * their own DMA requests to the bus can cause the system to lockup
1112 * if they where in the middle of requesting bus access.
1114 * Disabling the LCD clock if the LCD is active is very dangerous,
1115 * and therefore the bootloader should be careful to not enable
1116 * the LCD clock if it is not needed.
1119 /* install (and disable) the clocks we do not need immediately */
1121 clkp = init_clocks_disable;
1122 for (ptr = 0; ptr < ARRAY_SIZE(init_clocks_disable); ptr++, clkp++) {
1124 ret = s3c24xx_register_clock(clkp);
1126 printk(KERN_ERR "Failed to register clock %s (%d)\n",
1130 (clkp->enable)(clkp, 0);