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 .set_parent = s3c2443_setparent_epllref,
193 static unsigned long s3c2443_getrate_mdivclk(struct clk *clk)
195 unsigned long parent_rate = clk_get_rate(clk->parent);
196 unsigned long div = __raw_readl(S3C2443_CLKDIV0);
198 div &= S3C2443_CLKDIV0_EXTDIV_MASK;
199 div >>= (S3C2443_CLKDIV0_EXTDIV_SHIFT-1); /* x2 */
201 return parent_rate / (div + 1);
204 static struct clk clk_mdivclk = {
206 .parent = &clk_mpllref,
208 .get_rate = s3c2443_getrate_mdivclk,
211 static int s3c2443_setparent_msysclk(struct clk *clk, struct clk *parent)
213 unsigned long clksrc = __raw_readl(S3C2443_CLKSRC);
215 clksrc &= ~(S3C2443_CLKSRC_MSYSCLK_MPLL |
216 S3C2443_CLKSRC_EXTCLK_DIV);
218 if (parent == &clk_mpll)
219 clksrc |= S3C2443_CLKSRC_MSYSCLK_MPLL;
220 else if (parent == &clk_mdivclk)
221 clksrc |= S3C2443_CLKSRC_EXTCLK_DIV;
222 else if (parent != &clk_mpllref)
225 __raw_writel(clksrc, S3C2443_CLKSRC);
226 clk->parent = parent;
231 static struct clk clk_msysclk = {
235 .set_parent = s3c2443_setparent_msysclk,
240 * this clock is sourced from msysclk and can have a number of
241 * divider values applied to it to then be fed into armclk.
244 static struct clk clk_armdiv = {
247 .parent = &clk_msysclk,
252 * this is the clock fed into the ARM core itself, either from
253 * armdiv or from hclk.
256 static int s3c2443_setparent_armclk(struct clk *clk, struct clk *parent)
258 unsigned long clkdiv0;
260 clkdiv0 = __raw_readl(S3C2443_CLKDIV0);
262 if (parent == &clk_armdiv)
263 clkdiv0 &= ~S3C2443_CLKDIV0_DVS;
264 else if (parent == &clk_h)
265 clkdiv0 |= S3C2443_CLKDIV0_DVS;
269 __raw_writel(clkdiv0, S3C2443_CLKDIV0);
273 static struct clk clk_arm = {
276 .set_parent = s3c2443_setparent_armclk,
281 * this is sourced from either the EPLL or the EPLLref clock
284 static int s3c2443_setparent_esysclk(struct clk *clk, struct clk *parent)
286 unsigned long clksrc = __raw_readl(S3C2443_CLKSRC);
288 if (parent == &clk_epll)
289 clksrc |= S3C2443_CLKSRC_ESYSCLK_EPLL;
290 else if (parent == &clk_epllref)
291 clksrc &= ~S3C2443_CLKSRC_ESYSCLK_EPLL;
295 __raw_writel(clksrc, S3C2443_CLKSRC);
296 clk->parent = parent;
301 static struct clk clk_esysclk = {
305 .set_parent = s3c2443_setparent_esysclk,
310 * UART baud-rate clock sourced from esysclk via a divisor
313 static unsigned long s3c2443_getrate_uart(struct clk *clk)
315 unsigned long parent_rate = clk_get_rate(clk->parent);
316 unsigned long div = __raw_readl(S3C2443_CLKDIV1);
318 div &= S3C2443_CLKDIV1_UARTDIV_MASK;
319 div >>= S3C2443_CLKDIV1_UARTDIV_SHIFT;
321 return parent_rate / (div + 1);
325 static int s3c2443_setrate_uart(struct clk *clk, unsigned long rate)
327 unsigned long parent_rate = clk_get_rate(clk->parent);
328 unsigned long clkdivn = __raw_readl(S3C2443_CLKDIV1);
330 rate = s3c2443_roundrate_clksrc16(clk, rate);
331 rate = parent_rate / rate;
333 clkdivn &= ~S3C2443_CLKDIV1_UARTDIV_MASK;
334 clkdivn |= (rate - 1) << S3C2443_CLKDIV1_UARTDIV_SHIFT;
336 __raw_writel(clkdivn, S3C2443_CLKDIV1);
340 static struct clk clk_uart = {
343 .parent = &clk_esysclk,
344 .get_rate = s3c2443_getrate_uart,
345 .set_rate = s3c2443_setrate_uart,
346 .round_rate = s3c2443_roundrate_clksrc16,
351 * high-speed spi clock, sourced from esysclk
354 static unsigned long s3c2443_getrate_hsspi(struct clk *clk)
356 unsigned long parent_rate = clk_get_rate(clk->parent);
357 unsigned long div = __raw_readl(S3C2443_CLKDIV1);
359 div &= S3C2443_CLKDIV1_HSSPIDIV_MASK;
360 div >>= S3C2443_CLKDIV1_HSSPIDIV_SHIFT;
362 return parent_rate / (div + 1);
366 static int s3c2443_setrate_hsspi(struct clk *clk, unsigned long rate)
368 unsigned long parent_rate = clk_get_rate(clk->parent);
369 unsigned long clkdivn = __raw_readl(S3C2443_CLKDIV1);
371 rate = s3c2443_roundrate_clksrc4(clk, rate);
372 rate = parent_rate / rate;
374 clkdivn &= ~S3C2443_CLKDIV1_HSSPIDIV_MASK;
375 clkdivn |= (rate - 1) << S3C2443_CLKDIV1_HSSPIDIV_SHIFT;
377 __raw_writel(clkdivn, S3C2443_CLKDIV1);
381 static struct clk clk_hsspi = {
384 .parent = &clk_esysclk,
385 .ctrlbit = S3C2443_SCLKCON_HSSPICLK,
386 .enable = s3c2443_clkcon_enable_s,
387 .get_rate = s3c2443_getrate_hsspi,
388 .set_rate = s3c2443_setrate_hsspi,
389 .round_rate = s3c2443_roundrate_clksrc4,
394 * usb host bus-clock, usually 48MHz to provide USB bus clock timing
397 static unsigned long s3c2443_getrate_usbhost(struct clk *clk)
399 unsigned long parent_rate = clk_get_rate(clk->parent);
400 unsigned long div = __raw_readl(S3C2443_CLKDIV1);
402 div &= S3C2443_CLKDIV1_USBHOSTDIV_MASK;
403 div >>= S3C2443_CLKDIV1_USBHOSTDIV_SHIFT;
405 return parent_rate / (div + 1);
408 static int s3c2443_setrate_usbhost(struct clk *clk, unsigned long rate)
410 unsigned long parent_rate = clk_get_rate(clk->parent);
411 unsigned long clkdivn = __raw_readl(S3C2443_CLKDIV1);
413 rate = s3c2443_roundrate_clksrc4(clk, rate);
414 rate = parent_rate / rate;
416 clkdivn &= ~S3C2443_CLKDIV1_USBHOSTDIV_MASK;
417 clkdivn |= (rate - 1) << S3C2443_CLKDIV1_USBHOSTDIV_SHIFT;
419 __raw_writel(clkdivn, S3C2443_CLKDIV1);
423 static struct clk clk_usb_bus_host = {
424 .name = "usb-bus-host-parent",
426 .parent = &clk_esysclk,
427 .ctrlbit = S3C2443_SCLKCON_USBHOST,
428 .enable = s3c2443_clkcon_enable_s,
429 .get_rate = s3c2443_getrate_usbhost,
430 .set_rate = s3c2443_setrate_usbhost,
431 .round_rate = s3c2443_roundrate_clksrc4,
436 * this clock is sourced from epll, and is fed through a divider,
437 * to a mux controlled by sclkcon where either it or a extclk can
438 * be fed to the hsmmc block
441 static unsigned long s3c2443_getrate_hsmmc_div(struct clk *clk)
443 unsigned long parent_rate = clk_get_rate(clk->parent);
444 unsigned long div = __raw_readl(S3C2443_CLKDIV1);
446 div &= S3C2443_CLKDIV1_HSMMCDIV_MASK;
447 div >>= S3C2443_CLKDIV1_HSMMCDIV_SHIFT;
449 return parent_rate / (div + 1);
452 static int s3c2443_setrate_hsmmc_div(struct clk *clk, unsigned long rate)
454 unsigned long parent_rate = clk_get_rate(clk->parent);
455 unsigned long clkdivn = __raw_readl(S3C2443_CLKDIV1);
457 rate = s3c2443_roundrate_clksrc4(clk, rate);
458 rate = parent_rate / rate;
460 clkdivn &= ~S3C2443_CLKDIV1_HSMMCDIV_MASK;
461 clkdivn |= (rate - 1) << S3C2443_CLKDIV1_HSMMCDIV_SHIFT;
463 __raw_writel(clkdivn, S3C2443_CLKDIV1);
467 static struct clk clk_hsmmc_div = {
470 .parent = &clk_esysclk,
471 .get_rate = s3c2443_getrate_hsmmc_div,
472 .set_rate = s3c2443_setrate_hsmmc_div,
473 .round_rate = s3c2443_roundrate_clksrc4,
476 static int s3c2443_setparent_hsmmc(struct clk *clk, struct clk *parent)
478 unsigned long clksrc = __raw_readl(S3C2443_SCLKCON);
480 clksrc &= ~(S3C2443_SCLKCON_HSMMCCLK_EXT |
481 S3C2443_SCLKCON_HSMMCCLK_EPLL);
483 if (parent == &clk_epll)
484 clksrc |= S3C2443_SCLKCON_HSMMCCLK_EPLL;
485 else if (parent == &clk_ext)
486 clksrc |= S3C2443_SCLKCON_HSMMCCLK_EXT;
490 if (clk->usage > 0) {
491 __raw_writel(clksrc, S3C2443_SCLKCON);
494 clk->parent = parent;
498 static int s3c2443_enable_hsmmc(struct clk *clk, int enable)
500 return s3c2443_setparent_hsmmc(clk, clk->parent);
503 static struct clk clk_hsmmc = {
506 .parent = &clk_hsmmc_div,
507 .enable = s3c2443_enable_hsmmc,
508 .set_parent = s3c2443_setparent_hsmmc,
513 * this clock is the output from the i2s divisor of esysclk
516 static unsigned long s3c2443_getrate_i2s_eplldiv(struct clk *clk)
518 unsigned long parent_rate = clk_get_rate(clk->parent);
519 unsigned long div = __raw_readl(S3C2443_CLKDIV1);
521 div &= S3C2443_CLKDIV1_I2SDIV_MASK;
522 div >>= S3C2443_CLKDIV1_I2SDIV_SHIFT;
524 return parent_rate / (div + 1);
527 static int s3c2443_setrate_i2s_eplldiv(struct clk *clk, unsigned long rate)
529 unsigned long parent_rate = clk_get_rate(clk->parent);
530 unsigned long clkdivn = __raw_readl(S3C2443_CLKDIV1);
532 rate = s3c2443_roundrate_clksrc16(clk, rate);
533 rate = parent_rate / rate;
535 clkdivn &= ~S3C2443_CLKDIV1_I2SDIV_MASK;
536 clkdivn |= (rate - 1) << S3C2443_CLKDIV1_I2SDIV_SHIFT;
538 __raw_writel(clkdivn, S3C2443_CLKDIV1);
542 static struct clk clk_i2s_eplldiv = {
543 .name = "i2s-eplldiv",
545 .parent = &clk_esysclk,
546 .get_rate = s3c2443_getrate_i2s_eplldiv,
547 .set_rate = s3c2443_setrate_i2s_eplldiv,
548 .round_rate = s3c2443_roundrate_clksrc16,
553 * i2s bus reference clock, selectable from external, esysclk or epllref
556 static int s3c2443_setparent_i2s(struct clk *clk, struct clk *parent)
558 unsigned long clksrc = __raw_readl(S3C2443_CLKSRC);
560 clksrc &= ~S3C2443_CLKSRC_I2S_MASK;
562 if (parent == &clk_epllref)
563 clksrc |= S3C2443_CLKSRC_I2S_EPLLREF;
564 else if (parent == &clk_i2s_ext)
565 clksrc |= S3C2443_CLKSRC_I2S_EXT;
566 else if (parent != &clk_i2s_eplldiv)
569 clk->parent = parent;
570 __raw_writel(clksrc, S3C2443_CLKSRC);
575 static struct clk clk_i2s = {
578 .parent = &clk_i2s_eplldiv,
579 .ctrlbit = S3C2443_SCLKCON_I2SCLK,
580 .enable = s3c2443_clkcon_enable_s,
581 .set_parent = s3c2443_setparent_i2s,
586 * camera interface bus-clock, divided down from esysclk
589 static unsigned long s3c2443_getrate_cam(struct clk *clk)
591 unsigned long parent_rate = clk_get_rate(clk->parent);
592 unsigned long div = __raw_readl(S3C2443_CLKDIV1);
594 div &= S3C2443_CLKDIV1_CAMDIV_MASK;
595 div >>= S3C2443_CLKDIV1_CAMDIV_SHIFT;
597 return parent_rate / (div + 1);
600 static int s3c2443_setrate_cam(struct clk *clk, unsigned long rate)
602 unsigned long parent_rate = clk_get_rate(clk->parent);
603 unsigned long clkdiv1 = __raw_readl(S3C2443_CLKDIV1);
605 rate = s3c2443_roundrate_clksrc16(clk, rate);
606 rate = parent_rate / rate;
608 clkdiv1 &= ~S3C2443_CLKDIV1_CAMDIV_MASK;
609 clkdiv1 |= (rate - 1) << S3C2443_CLKDIV1_CAMDIV_SHIFT;
611 __raw_writel(clkdiv1, S3C2443_CLKDIV1);
615 static struct clk clk_cam = {
616 .name = "camif-upll", /* same as 2440 name */
618 .parent = &clk_esysclk,
619 .ctrlbit = S3C2443_SCLKCON_CAMCLK,
620 .enable = s3c2443_clkcon_enable_s,
621 .get_rate = s3c2443_getrate_cam,
622 .set_rate = s3c2443_setrate_cam,
623 .round_rate = s3c2443_roundrate_clksrc16,
628 * display interface clock, divided from esysclk
631 static unsigned long s3c2443_getrate_display(struct clk *clk)
633 unsigned long parent_rate = clk_get_rate(clk->parent);
634 unsigned long div = __raw_readl(S3C2443_CLKDIV1);
636 div &= S3C2443_CLKDIV1_DISPDIV_MASK;
637 div >>= S3C2443_CLKDIV1_DISPDIV_SHIFT;
639 return parent_rate / (div + 1);
642 static int s3c2443_setrate_display(struct clk *clk, unsigned long rate)
644 unsigned long parent_rate = clk_get_rate(clk->parent);
645 unsigned long clkdivn = __raw_readl(S3C2443_CLKDIV1);
647 rate = s3c2443_roundrate_clksrc256(clk, rate);
648 rate = parent_rate / rate;
650 clkdivn &= ~S3C2443_CLKDIV1_UARTDIV_MASK;
651 clkdivn |= (rate - 1) << S3C2443_CLKDIV1_UARTDIV_SHIFT;
653 __raw_writel(clkdivn, S3C2443_CLKDIV1);
657 static struct clk clk_display = {
658 .name = "display-if",
660 .parent = &clk_esysclk,
661 .ctrlbit = S3C2443_SCLKCON_DISPCLK,
662 .enable = s3c2443_clkcon_enable_s,
663 .get_rate = s3c2443_getrate_display,
664 .set_rate = s3c2443_setrate_display,
665 .round_rate = s3c2443_roundrate_clksrc256,
670 * this divides the msysclk down to pass to h/p/etc.
673 static unsigned long s3c2443_prediv_getrate(struct clk *clk)
675 unsigned long rate = clk_get_rate(clk->parent);
676 unsigned long clkdiv0 = __raw_readl(S3C2443_CLKDIV0);
678 clkdiv0 &= S3C2443_CLKDIV0_PREDIV_MASK;
679 clkdiv0 >>= S3C2443_CLKDIV0_PREDIV_SHIFT;
681 return rate / (clkdiv0 + 1);
684 static struct clk clk_prediv = {
687 .parent = &clk_msysclk,
688 .get_rate = s3c2443_prediv_getrate,
691 /* standard clock definitions */
693 static struct clk init_clocks_disable[] = {
702 .enable = s3c2443_clkcon_enable_p,
703 .ctrlbit = S3C2443_PCLKCON_SDI,
708 .enable = s3c2443_clkcon_enable_p,
709 .ctrlbit = S3C2443_PCLKCON_ADC,
714 .enable = s3c2443_clkcon_enable_p,
715 .ctrlbit = S3C2443_PCLKCON_IIC,
720 .enable = s3c2443_clkcon_enable_p,
721 .ctrlbit = S3C2443_PCLKCON_IIS,
726 .enable = s3c2443_clkcon_enable_p,
727 .ctrlbit = S3C2443_PCLKCON_SPI0,
732 .enable = s3c2443_clkcon_enable_p,
733 .ctrlbit = S3C2443_PCLKCON_SPI1,
737 static struct clk init_clocks[] = {
742 .enable = s3c2443_clkcon_enable_h,
743 .ctrlbit = S3C2443_HCLKCON_DMA0,
748 .enable = s3c2443_clkcon_enable_h,
749 .ctrlbit = S3C2443_HCLKCON_DMA1,
754 .enable = s3c2443_clkcon_enable_h,
755 .ctrlbit = S3C2443_HCLKCON_DMA2,
760 .enable = s3c2443_clkcon_enable_h,
761 .ctrlbit = S3C2443_HCLKCON_DMA3,
766 .enable = s3c2443_clkcon_enable_h,
767 .ctrlbit = S3C2443_HCLKCON_DMA4,
772 .enable = s3c2443_clkcon_enable_h,
773 .ctrlbit = S3C2443_HCLKCON_DMA5,
778 .enable = s3c2443_clkcon_enable_h,
779 .ctrlbit = S3C2443_HCLKCON_LCDC,
784 .enable = s3c2443_clkcon_enable_p,
785 .ctrlbit = S3C2443_PCLKCON_GPIO,
790 .enable = s3c2443_clkcon_enable_h,
791 .ctrlbit = S3C2443_HCLKCON_USBH,
793 .name = "usb-device",
796 .enable = s3c2443_clkcon_enable_h,
797 .ctrlbit = S3C2443_HCLKCON_USBD,
802 .enable = s3c2443_clkcon_enable_h,
803 .ctrlbit = S3C2443_HCLKCON_HSMMC,
808 .enable = s3c2443_clkcon_enable_h,
809 .ctrlbit = S3C2443_HCLKCON_CFC,
814 .enable = s3c2443_clkcon_enable_h,
815 .ctrlbit = S3C2443_HCLKCON_SSMC,
820 .enable = s3c2443_clkcon_enable_p,
821 .ctrlbit = S3C2443_PCLKCON_PWMT,
826 .enable = s3c2443_clkcon_enable_p,
827 .ctrlbit = S3C2443_PCLKCON_UART0,
832 .enable = s3c2443_clkcon_enable_p,
833 .ctrlbit = S3C2443_PCLKCON_UART1,
838 .enable = s3c2443_clkcon_enable_p,
839 .ctrlbit = S3C2443_PCLKCON_UART2,
844 .enable = s3c2443_clkcon_enable_p,
845 .ctrlbit = S3C2443_PCLKCON_UART3,
850 .enable = s3c2443_clkcon_enable_p,
851 .ctrlbit = S3C2443_PCLKCON_RTC,
856 .ctrlbit = S3C2443_PCLKCON_WDT,
858 .name = "usb-bus-host",
860 .parent = &clk_usb_bus_host,
865 .ctrlbit = S3C2443_PCLKCON_AC97,
869 /* clocks to add where we need to check their parentage */
871 /* s3c2443_clk_initparents
873 * Initialise the parents for the clocks that we get at start-time
876 static int __init clk_init_set_parent(struct clk *clk, struct clk *parent)
878 printk(KERN_DEBUG "clock %s: parent %s\n", clk->name, parent->name);
879 return clk_set_parent(clk, parent);
882 static void __init s3c2443_clk_initparents(void)
884 unsigned long clksrc = __raw_readl(S3C2443_CLKSRC);
887 switch (clksrc & S3C2443_CLKSRC_EPLLREF_MASK) {
888 case S3C2443_CLKSRC_EPLLREF_EXTCLK:
892 case S3C2443_CLKSRC_EPLLREF_XTAL:
897 case S3C2443_CLKSRC_EPLLREF_MPLLREF:
898 case S3C2443_CLKSRC_EPLLREF_MPLLREF2:
899 parent = &clk_mpllref;
903 clk_init_set_parent(&clk_epllref, parent);
905 switch (clksrc & S3C2443_CLKSRC_I2S_MASK) {
906 case S3C2443_CLKSRC_I2S_EXT:
907 parent = &clk_i2s_ext;
910 case S3C2443_CLKSRC_I2S_EPLLDIV:
912 parent = &clk_i2s_eplldiv;
915 case S3C2443_CLKSRC_I2S_EPLLREF:
916 case S3C2443_CLKSRC_I2S_EPLLREF3:
917 parent = &clk_epllref;
920 clk_init_set_parent(&clk_i2s, &clk_epllref);
924 parent = (clksrc & S3C2443_CLKSRC_ESYSCLK_EPLL) ?
925 &clk_epll : &clk_epllref;
927 clk_init_set_parent(&clk_esysclk, parent);
931 if (clksrc & S3C2443_CLKSRC_MSYSCLK_MPLL) {
934 parent = (clksrc & S3C2443_CLKSRC_EXTCLK_DIV) ?
935 &clk_mdivclk : &clk_mpllref;
938 clk_init_set_parent(&clk_msysclk, parent);
942 if (__raw_readl(S3C2443_CLKDIV0) & S3C2443_CLKDIV0_DVS)
945 parent = &clk_armdiv;
947 clk_init_set_parent(&clk_arm, parent);
950 /* armdiv divisor table */
952 static unsigned int armdiv[16] = {
953 [S3C2443_CLKDIV0_ARMDIV_1 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 1,
954 [S3C2443_CLKDIV0_ARMDIV_2 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 2,
955 [S3C2443_CLKDIV0_ARMDIV_3 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 3,
956 [S3C2443_CLKDIV0_ARMDIV_4 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 4,
957 [S3C2443_CLKDIV0_ARMDIV_6 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 6,
958 [S3C2443_CLKDIV0_ARMDIV_8 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 8,
959 [S3C2443_CLKDIV0_ARMDIV_12 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 12,
960 [S3C2443_CLKDIV0_ARMDIV_16 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 16,
963 static inline unsigned int s3c2443_fclk_div(unsigned long clkcon0)
965 clkcon0 &= S3C2443_CLKDIV0_ARMDIV_MASK;
967 return armdiv[clkcon0 >> S3C2443_CLKDIV0_ARMDIV_SHIFT];
970 static inline unsigned long s3c2443_get_hdiv(unsigned long clkcon0)
972 clkcon0 &= S3C2443_CLKDIV0_HCLKDIV_MASK;
977 /* clocks to add straight away */
979 static struct clk *clks[] __initdata = {
1001 void __init_or_cpufreq s3c2443_setup_clocks(void)
1003 unsigned long mpllcon = __raw_readl(S3C2443_MPLLCON);
1004 unsigned long clkdiv0 = __raw_readl(S3C2443_CLKDIV0);
1005 struct clk *xtal_clk;
1012 xtal_clk = clk_get(NULL, "xtal");
1013 xtal = clk_get_rate(xtal_clk);
1016 pll = s3c2443_get_mpll(mpllcon, xtal);
1017 clk_msysclk.rate = pll;
1019 fclk = pll / s3c2443_fclk_div(clkdiv0);
1020 hclk = s3c2443_prediv_getrate(&clk_prediv);
1021 hclk /= s3c2443_get_hdiv(clkdiv0);
1022 pclk = hclk / ((clkdiv0 & S3C2443_CLKDIV0_HALF_PCLK) ? 2 : 1);
1024 s3c24xx_setup_clocks(fclk, hclk, pclk);
1026 printk("S3C2443: mpll %s %ld.%03ld MHz, cpu %ld.%03ld MHz, mem %ld.%03ld MHz, pclk %ld.%03ld MHz\n",
1027 (mpllcon & S3C2443_PLLCON_OFF) ? "off":"on",
1028 print_mhz(pll), print_mhz(fclk),
1029 print_mhz(hclk), print_mhz(pclk));
1031 s3c24xx_setup_clocks(fclk, hclk, pclk);
1034 void __init s3c2443_init_clocks(int xtal)
1037 unsigned long epllcon = __raw_readl(S3C2443_EPLLCON);
1041 /* s3c2443 parents h and p clocks from prediv */
1042 clk_h.parent = &clk_prediv;
1043 clk_p.parent = &clk_prediv;
1045 s3c24xx_register_baseclocks(xtal);
1046 s3c2443_setup_clocks();
1047 s3c2443_clk_initparents();
1049 for (ptr = 0; ptr < ARRAY_SIZE(clks); ptr++) {
1052 ret = s3c24xx_register_clock(clkp);
1054 printk(KERN_ERR "Failed to register clock %s (%d)\n",
1059 clk_epll.rate = s3c2443_get_epll(epllcon, xtal);
1060 clk_epll.parent = &clk_epllref;
1061 clk_usb_bus.parent = &clk_usb_bus_host;
1063 /* ensure usb bus clock is within correct rate of 48MHz */
1065 if (clk_get_rate(&clk_usb_bus_host) != (48 * 1000 * 1000)) {
1066 printk(KERN_INFO "Warning: USB host bus not at 48MHz\n");
1067 clk_set_rate(&clk_usb_bus_host, 48*1000*1000);
1070 printk("S3C2443: epll %s %ld.%03ld MHz, usb-bus %ld.%03ld MHz\n",
1071 (epllcon & S3C2443_PLLCON_OFF) ? "off":"on",
1072 print_mhz(clk_get_rate(&clk_epll)),
1073 print_mhz(clk_get_rate(&clk_usb_bus)));
1075 /* register clocks from clock array */
1078 for (ptr = 0; ptr < ARRAY_SIZE(init_clocks); ptr++, clkp++) {
1079 ret = s3c24xx_register_clock(clkp);
1081 printk(KERN_ERR "Failed to register clock %s (%d)\n",
1086 /* We must be careful disabling the clocks we are not intending to
1087 * be using at boot time, as subsystems such as the LCD which do
1088 * their own DMA requests to the bus can cause the system to lockup
1089 * if they where in the middle of requesting bus access.
1091 * Disabling the LCD clock if the LCD is active is very dangerous,
1092 * and therefore the bootloader should be careful to not enable
1093 * the LCD clock if it is not needed.
1096 /* install (and disable) the clocks we do not need immediately */
1098 clkp = init_clocks_disable;
1099 for (ptr = 0; ptr < ARRAY_SIZE(init_clocks_disable); ptr++, clkp++) {
1101 ret = s3c24xx_register_clock(clkp);
1103 printk(KERN_ERR "Failed to register clock %s (%d)\n",
1107 (clkp->enable)(clkp, 0);