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/delay.h>
33 #include <linux/serial_core.h>
36 #include <asm/mach/map.h>
38 #include <mach/hardware.h>
40 #include <mach/regs-s3c2443-clock.h>
42 #include <plat/cpu-freq.h>
44 #include <plat/s3c2443.h>
45 #include <plat/clock.h>
48 /* We currently have to assume that the system is running
49 * from the XTPll input, and that all ***REFCLKs are being
50 * fed from it, as we cannot read the state of OM[4] from
53 * It would be possible for each board initialisation to
54 * set the correct muxing at initialisation
57 static int s3c2443_clkcon_enable_h(struct clk *clk, int enable)
59 unsigned int clocks = clk->ctrlbit;
62 clkcon = __raw_readl(S3C2443_HCLKCON);
69 __raw_writel(clkcon, S3C2443_HCLKCON);
74 static int s3c2443_clkcon_enable_p(struct clk *clk, int enable)
76 unsigned int clocks = clk->ctrlbit;
79 clkcon = __raw_readl(S3C2443_PCLKCON);
86 __raw_writel(clkcon, S3C2443_PCLKCON);
91 static int s3c2443_clkcon_enable_s(struct clk *clk, int enable)
93 unsigned int clocks = clk->ctrlbit;
96 clkcon = __raw_readl(S3C2443_SCLKCON);
103 __raw_writel(clkcon, S3C2443_SCLKCON);
108 static unsigned long s3c2443_roundrate_clksrc(struct clk *clk,
112 unsigned long parent_rate = clk_get_rate(clk->parent);
115 if (rate > parent_rate)
118 /* note, we remove the +/- 1 calculations as they cancel out */
120 div = (rate / parent_rate);
127 return parent_rate / div;
130 static unsigned long s3c2443_roundrate_clksrc4(struct clk *clk,
133 return s3c2443_roundrate_clksrc(clk, rate, 4);
136 static unsigned long s3c2443_roundrate_clksrc16(struct clk *clk,
139 return s3c2443_roundrate_clksrc(clk, rate, 16);
142 static unsigned long s3c2443_roundrate_clksrc256(struct clk *clk,
145 return s3c2443_roundrate_clksrc(clk, rate, 256);
148 /* clock selections */
150 static struct clk clk_mpllref = {
157 static struct clk clk_mpll = {
159 .parent = &clk_mpllref,
164 static struct clk clk_i2s_ext = {
169 static int s3c2443_setparent_epllref(struct clk *clk, struct clk *parent)
171 unsigned long clksrc = __raw_readl(S3C2443_CLKSRC);
173 clksrc &= ~S3C2443_CLKSRC_EPLLREF_MASK;
175 if (parent == &clk_xtal)
176 clksrc |= S3C2443_CLKSRC_EPLLREF_XTAL;
177 else if (parent == &clk_ext)
178 clksrc |= S3C2443_CLKSRC_EPLLREF_EXTCLK;
179 else if (parent != &clk_mpllref)
182 __raw_writel(clksrc, S3C2443_CLKSRC);
183 clk->parent = parent;
188 static struct clk clk_epllref = {
191 .set_parent = s3c2443_setparent_epllref,
194 static unsigned long s3c2443_getrate_mdivclk(struct clk *clk)
196 unsigned long parent_rate = clk_get_rate(clk->parent);
197 unsigned long div = __raw_readl(S3C2443_CLKDIV0);
199 div &= S3C2443_CLKDIV0_EXTDIV_MASK;
200 div >>= (S3C2443_CLKDIV0_EXTDIV_SHIFT-1); /* x2 */
202 return parent_rate / (div + 1);
205 static struct clk clk_mdivclk = {
207 .parent = &clk_mpllref,
209 .get_rate = s3c2443_getrate_mdivclk,
212 static int s3c2443_setparent_msysclk(struct clk *clk, struct clk *parent)
214 unsigned long clksrc = __raw_readl(S3C2443_CLKSRC);
216 clksrc &= ~(S3C2443_CLKSRC_MSYSCLK_MPLL |
217 S3C2443_CLKSRC_EXTCLK_DIV);
219 if (parent == &clk_mpll)
220 clksrc |= S3C2443_CLKSRC_MSYSCLK_MPLL;
221 else if (parent == &clk_mdivclk)
222 clksrc |= S3C2443_CLKSRC_EXTCLK_DIV;
223 else if (parent != &clk_mpllref)
226 __raw_writel(clksrc, S3C2443_CLKSRC);
227 clk->parent = parent;
232 static struct clk clk_msysclk = {
236 .set_parent = s3c2443_setparent_msysclk,
241 * this clock is sourced from msysclk and can have a number of
242 * divider values applied to it to then be fed into armclk.
245 static struct clk clk_armdiv = {
248 .parent = &clk_msysclk,
253 * this is the clock fed into the ARM core itself, either from
254 * armdiv or from hclk.
257 static int s3c2443_setparent_armclk(struct clk *clk, struct clk *parent)
259 unsigned long clkdiv0;
261 clkdiv0 = __raw_readl(S3C2443_CLKDIV0);
263 if (parent == &clk_armdiv)
264 clkdiv0 &= ~S3C2443_CLKDIV0_DVS;
265 else if (parent == &clk_h)
266 clkdiv0 |= S3C2443_CLKDIV0_DVS;
270 __raw_writel(clkdiv0, S3C2443_CLKDIV0);
274 static struct clk clk_arm = {
277 .set_parent = s3c2443_setparent_armclk,
282 * this is sourced from either the EPLL or the EPLLref clock
285 static int s3c2443_setparent_esysclk(struct clk *clk, struct clk *parent)
287 unsigned long clksrc = __raw_readl(S3C2443_CLKSRC);
289 if (parent == &clk_epll)
290 clksrc |= S3C2443_CLKSRC_ESYSCLK_EPLL;
291 else if (parent == &clk_epllref)
292 clksrc &= ~S3C2443_CLKSRC_ESYSCLK_EPLL;
296 __raw_writel(clksrc, S3C2443_CLKSRC);
297 clk->parent = parent;
302 static struct clk clk_esysclk = {
306 .set_parent = s3c2443_setparent_esysclk,
311 * UART baud-rate clock sourced from esysclk via a divisor
314 static unsigned long s3c2443_getrate_uart(struct clk *clk)
316 unsigned long parent_rate = clk_get_rate(clk->parent);
317 unsigned long div = __raw_readl(S3C2443_CLKDIV1);
319 div &= S3C2443_CLKDIV1_UARTDIV_MASK;
320 div >>= S3C2443_CLKDIV1_UARTDIV_SHIFT;
322 return parent_rate / (div + 1);
326 static int s3c2443_setrate_uart(struct clk *clk, unsigned long rate)
328 unsigned long parent_rate = clk_get_rate(clk->parent);
329 unsigned long clkdivn = __raw_readl(S3C2443_CLKDIV1);
331 rate = s3c2443_roundrate_clksrc16(clk, rate);
332 rate = parent_rate / rate;
334 clkdivn &= ~S3C2443_CLKDIV1_UARTDIV_MASK;
335 clkdivn |= (rate - 1) << S3C2443_CLKDIV1_UARTDIV_SHIFT;
337 __raw_writel(clkdivn, S3C2443_CLKDIV1);
341 static struct clk clk_uart = {
344 .parent = &clk_esysclk,
345 .get_rate = s3c2443_getrate_uart,
346 .set_rate = s3c2443_setrate_uart,
347 .round_rate = s3c2443_roundrate_clksrc16,
352 * high-speed spi clock, sourced from esysclk
355 static unsigned long s3c2443_getrate_hsspi(struct clk *clk)
357 unsigned long parent_rate = clk_get_rate(clk->parent);
358 unsigned long div = __raw_readl(S3C2443_CLKDIV1);
360 div &= S3C2443_CLKDIV1_HSSPIDIV_MASK;
361 div >>= S3C2443_CLKDIV1_HSSPIDIV_SHIFT;
363 return parent_rate / (div + 1);
367 static int s3c2443_setrate_hsspi(struct clk *clk, unsigned long rate)
369 unsigned long parent_rate = clk_get_rate(clk->parent);
370 unsigned long clkdivn = __raw_readl(S3C2443_CLKDIV1);
372 rate = s3c2443_roundrate_clksrc4(clk, rate);
373 rate = parent_rate / rate;
375 clkdivn &= ~S3C2443_CLKDIV1_HSSPIDIV_MASK;
376 clkdivn |= (rate - 1) << S3C2443_CLKDIV1_HSSPIDIV_SHIFT;
378 __raw_writel(clkdivn, S3C2443_CLKDIV1);
382 static struct clk clk_hsspi = {
385 .parent = &clk_esysclk,
386 .ctrlbit = S3C2443_SCLKCON_HSSPICLK,
387 .enable = s3c2443_clkcon_enable_s,
388 .get_rate = s3c2443_getrate_hsspi,
389 .set_rate = s3c2443_setrate_hsspi,
390 .round_rate = s3c2443_roundrate_clksrc4,
395 * usb host bus-clock, usually 48MHz to provide USB bus clock timing
398 static unsigned long s3c2443_getrate_usbhost(struct clk *clk)
400 unsigned long parent_rate = clk_get_rate(clk->parent);
401 unsigned long div = __raw_readl(S3C2443_CLKDIV1);
403 div &= S3C2443_CLKDIV1_USBHOSTDIV_MASK;
404 div >>= S3C2443_CLKDIV1_USBHOSTDIV_SHIFT;
406 return parent_rate / (div + 1);
409 static int s3c2443_setrate_usbhost(struct clk *clk, unsigned long rate)
411 unsigned long parent_rate = clk_get_rate(clk->parent);
412 unsigned long clkdivn = __raw_readl(S3C2443_CLKDIV1);
414 rate = s3c2443_roundrate_clksrc4(clk, rate);
415 rate = parent_rate / rate;
417 clkdivn &= ~S3C2443_CLKDIV1_USBHOSTDIV_MASK;
418 clkdivn |= (rate - 1) << S3C2443_CLKDIV1_USBHOSTDIV_SHIFT;
420 __raw_writel(clkdivn, S3C2443_CLKDIV1);
424 static struct clk clk_usb_bus_host = {
425 .name = "usb-bus-host-parent",
427 .parent = &clk_esysclk,
428 .ctrlbit = S3C2443_SCLKCON_USBHOST,
429 .enable = s3c2443_clkcon_enable_s,
430 .get_rate = s3c2443_getrate_usbhost,
431 .set_rate = s3c2443_setrate_usbhost,
432 .round_rate = s3c2443_roundrate_clksrc4,
437 * this clock is sourced from epll, and is fed through a divider,
438 * to a mux controlled by sclkcon where either it or a extclk can
439 * be fed to the hsmmc block
442 static unsigned long s3c2443_getrate_hsmmc_div(struct clk *clk)
444 unsigned long parent_rate = clk_get_rate(clk->parent);
445 unsigned long div = __raw_readl(S3C2443_CLKDIV1);
447 div &= S3C2443_CLKDIV1_HSMMCDIV_MASK;
448 div >>= S3C2443_CLKDIV1_HSMMCDIV_SHIFT;
450 return parent_rate / (div + 1);
453 static int s3c2443_setrate_hsmmc_div(struct clk *clk, unsigned long rate)
455 unsigned long parent_rate = clk_get_rate(clk->parent);
456 unsigned long clkdivn = __raw_readl(S3C2443_CLKDIV1);
458 rate = s3c2443_roundrate_clksrc4(clk, rate);
459 rate = parent_rate / rate;
461 clkdivn &= ~S3C2443_CLKDIV1_HSMMCDIV_MASK;
462 clkdivn |= (rate - 1) << S3C2443_CLKDIV1_HSMMCDIV_SHIFT;
464 __raw_writel(clkdivn, S3C2443_CLKDIV1);
468 static struct clk clk_hsmmc_div = {
471 .parent = &clk_esysclk,
472 .get_rate = s3c2443_getrate_hsmmc_div,
473 .set_rate = s3c2443_setrate_hsmmc_div,
474 .round_rate = s3c2443_roundrate_clksrc4,
477 static int s3c2443_setparent_hsmmc(struct clk *clk, struct clk *parent)
479 unsigned long clksrc = __raw_readl(S3C2443_SCLKCON);
481 clksrc &= ~(S3C2443_SCLKCON_HSMMCCLK_EXT |
482 S3C2443_SCLKCON_HSMMCCLK_EPLL);
484 if (parent == &clk_epll)
485 clksrc |= S3C2443_SCLKCON_HSMMCCLK_EPLL;
486 else if (parent == &clk_ext)
487 clksrc |= S3C2443_SCLKCON_HSMMCCLK_EXT;
491 if (clk->usage > 0) {
492 __raw_writel(clksrc, S3C2443_SCLKCON);
495 clk->parent = parent;
499 static int s3c2443_enable_hsmmc(struct clk *clk, int enable)
501 return s3c2443_setparent_hsmmc(clk, clk->parent);
504 static struct clk clk_hsmmc = {
507 .parent = &clk_hsmmc_div,
508 .enable = s3c2443_enable_hsmmc,
509 .set_parent = s3c2443_setparent_hsmmc,
514 * this clock is the output from the i2s divisor of esysclk
517 static unsigned long s3c2443_getrate_i2s_eplldiv(struct clk *clk)
519 unsigned long parent_rate = clk_get_rate(clk->parent);
520 unsigned long div = __raw_readl(S3C2443_CLKDIV1);
522 div &= S3C2443_CLKDIV1_I2SDIV_MASK;
523 div >>= S3C2443_CLKDIV1_I2SDIV_SHIFT;
525 return parent_rate / (div + 1);
528 static int s3c2443_setrate_i2s_eplldiv(struct clk *clk, unsigned long rate)
530 unsigned long parent_rate = clk_get_rate(clk->parent);
531 unsigned long clkdivn = __raw_readl(S3C2443_CLKDIV1);
533 rate = s3c2443_roundrate_clksrc16(clk, rate);
534 rate = parent_rate / rate;
536 clkdivn &= ~S3C2443_CLKDIV1_I2SDIV_MASK;
537 clkdivn |= (rate - 1) << S3C2443_CLKDIV1_I2SDIV_SHIFT;
539 __raw_writel(clkdivn, S3C2443_CLKDIV1);
543 static struct clk clk_i2s_eplldiv = {
544 .name = "i2s-eplldiv",
546 .parent = &clk_esysclk,
547 .get_rate = s3c2443_getrate_i2s_eplldiv,
548 .set_rate = s3c2443_setrate_i2s_eplldiv,
549 .round_rate = s3c2443_roundrate_clksrc16,
554 * i2s bus reference clock, selectable from external, esysclk or epllref
557 static int s3c2443_setparent_i2s(struct clk *clk, struct clk *parent)
559 unsigned long clksrc = __raw_readl(S3C2443_CLKSRC);
561 clksrc &= ~S3C2443_CLKSRC_I2S_MASK;
563 if (parent == &clk_epllref)
564 clksrc |= S3C2443_CLKSRC_I2S_EPLLREF;
565 else if (parent == &clk_i2s_ext)
566 clksrc |= S3C2443_CLKSRC_I2S_EXT;
567 else if (parent != &clk_i2s_eplldiv)
570 clk->parent = parent;
571 __raw_writel(clksrc, S3C2443_CLKSRC);
576 static struct clk clk_i2s = {
579 .parent = &clk_i2s_eplldiv,
580 .ctrlbit = S3C2443_SCLKCON_I2SCLK,
581 .enable = s3c2443_clkcon_enable_s,
582 .set_parent = s3c2443_setparent_i2s,
587 * camera interface bus-clock, divided down from esysclk
590 static unsigned long s3c2443_getrate_cam(struct clk *clk)
592 unsigned long parent_rate = clk_get_rate(clk->parent);
593 unsigned long div = __raw_readl(S3C2443_CLKDIV1);
595 div &= S3C2443_CLKDIV1_CAMDIV_MASK;
596 div >>= S3C2443_CLKDIV1_CAMDIV_SHIFT;
598 return parent_rate / (div + 1);
601 static int s3c2443_setrate_cam(struct clk *clk, unsigned long rate)
603 unsigned long parent_rate = clk_get_rate(clk->parent);
604 unsigned long clkdiv1 = __raw_readl(S3C2443_CLKDIV1);
606 rate = s3c2443_roundrate_clksrc16(clk, rate);
607 rate = parent_rate / rate;
609 clkdiv1 &= ~S3C2443_CLKDIV1_CAMDIV_MASK;
610 clkdiv1 |= (rate - 1) << S3C2443_CLKDIV1_CAMDIV_SHIFT;
612 __raw_writel(clkdiv1, S3C2443_CLKDIV1);
616 static struct clk clk_cam = {
617 .name = "camif-upll", /* same as 2440 name */
619 .parent = &clk_esysclk,
620 .ctrlbit = S3C2443_SCLKCON_CAMCLK,
621 .enable = s3c2443_clkcon_enable_s,
622 .get_rate = s3c2443_getrate_cam,
623 .set_rate = s3c2443_setrate_cam,
624 .round_rate = s3c2443_roundrate_clksrc16,
629 * display interface clock, divided from esysclk
632 static unsigned long s3c2443_getrate_display(struct clk *clk)
634 unsigned long parent_rate = clk_get_rate(clk->parent);
635 unsigned long div = __raw_readl(S3C2443_CLKDIV1);
637 div &= S3C2443_CLKDIV1_DISPDIV_MASK;
638 div >>= S3C2443_CLKDIV1_DISPDIV_SHIFT;
640 return parent_rate / (div + 1);
643 static int s3c2443_setrate_display(struct clk *clk, unsigned long rate)
645 unsigned long parent_rate = clk_get_rate(clk->parent);
646 unsigned long clkdivn = __raw_readl(S3C2443_CLKDIV1);
648 rate = s3c2443_roundrate_clksrc256(clk, rate);
649 rate = parent_rate / rate;
651 clkdivn &= ~S3C2443_CLKDIV1_UARTDIV_MASK;
652 clkdivn |= (rate - 1) << S3C2443_CLKDIV1_UARTDIV_SHIFT;
654 __raw_writel(clkdivn, S3C2443_CLKDIV1);
658 static struct clk clk_display = {
659 .name = "display-if",
661 .parent = &clk_esysclk,
662 .ctrlbit = S3C2443_SCLKCON_DISPCLK,
663 .enable = s3c2443_clkcon_enable_s,
664 .get_rate = s3c2443_getrate_display,
665 .set_rate = s3c2443_setrate_display,
666 .round_rate = s3c2443_roundrate_clksrc256,
671 * this divides the msysclk down to pass to h/p/etc.
674 static unsigned long s3c2443_prediv_getrate(struct clk *clk)
676 unsigned long rate = clk_get_rate(clk->parent);
677 unsigned long clkdiv0 = __raw_readl(S3C2443_CLKDIV0);
679 clkdiv0 &= S3C2443_CLKDIV0_PREDIV_MASK;
680 clkdiv0 >>= S3C2443_CLKDIV0_PREDIV_SHIFT;
682 return rate / (clkdiv0 + 1);
685 static struct clk clk_prediv = {
688 .parent = &clk_msysclk,
689 .get_rate = s3c2443_prediv_getrate,
692 /* standard clock definitions */
694 static struct clk init_clocks_disable[] = {
703 .enable = s3c2443_clkcon_enable_p,
704 .ctrlbit = S3C2443_PCLKCON_SDI,
709 .enable = s3c2443_clkcon_enable_p,
710 .ctrlbit = S3C2443_PCLKCON_ADC,
715 .enable = s3c2443_clkcon_enable_p,
716 .ctrlbit = S3C2443_PCLKCON_IIC,
721 .enable = s3c2443_clkcon_enable_p,
722 .ctrlbit = S3C2443_PCLKCON_IIS,
727 .enable = s3c2443_clkcon_enable_p,
728 .ctrlbit = S3C2443_PCLKCON_SPI0,
733 .enable = s3c2443_clkcon_enable_p,
734 .ctrlbit = S3C2443_PCLKCON_SPI1,
738 static struct clk init_clocks[] = {
743 .enable = s3c2443_clkcon_enable_h,
744 .ctrlbit = S3C2443_HCLKCON_DMA0,
749 .enable = s3c2443_clkcon_enable_h,
750 .ctrlbit = S3C2443_HCLKCON_DMA1,
755 .enable = s3c2443_clkcon_enable_h,
756 .ctrlbit = S3C2443_HCLKCON_DMA2,
761 .enable = s3c2443_clkcon_enable_h,
762 .ctrlbit = S3C2443_HCLKCON_DMA3,
767 .enable = s3c2443_clkcon_enable_h,
768 .ctrlbit = S3C2443_HCLKCON_DMA4,
773 .enable = s3c2443_clkcon_enable_h,
774 .ctrlbit = S3C2443_HCLKCON_DMA5,
779 .enable = s3c2443_clkcon_enable_h,
780 .ctrlbit = S3C2443_HCLKCON_LCDC,
785 .enable = s3c2443_clkcon_enable_p,
786 .ctrlbit = S3C2443_PCLKCON_GPIO,
791 .enable = s3c2443_clkcon_enable_h,
792 .ctrlbit = S3C2443_HCLKCON_USBH,
794 .name = "usb-device",
797 .enable = s3c2443_clkcon_enable_h,
798 .ctrlbit = S3C2443_HCLKCON_USBD,
803 .enable = s3c2443_clkcon_enable_h,
804 .ctrlbit = S3C2443_HCLKCON_HSMMC,
809 .enable = s3c2443_clkcon_enable_h,
810 .ctrlbit = S3C2443_HCLKCON_CFC,
815 .enable = s3c2443_clkcon_enable_h,
816 .ctrlbit = S3C2443_HCLKCON_SSMC,
821 .enable = s3c2443_clkcon_enable_p,
822 .ctrlbit = S3C2443_PCLKCON_PWMT,
827 .enable = s3c2443_clkcon_enable_p,
828 .ctrlbit = S3C2443_PCLKCON_UART0,
833 .enable = s3c2443_clkcon_enable_p,
834 .ctrlbit = S3C2443_PCLKCON_UART1,
839 .enable = s3c2443_clkcon_enable_p,
840 .ctrlbit = S3C2443_PCLKCON_UART2,
845 .enable = s3c2443_clkcon_enable_p,
846 .ctrlbit = S3C2443_PCLKCON_UART3,
851 .enable = s3c2443_clkcon_enable_p,
852 .ctrlbit = S3C2443_PCLKCON_RTC,
857 .ctrlbit = S3C2443_PCLKCON_WDT,
859 .name = "usb-bus-host",
861 .parent = &clk_usb_bus_host,
866 .ctrlbit = S3C2443_PCLKCON_AC97,
870 /* clocks to add where we need to check their parentage */
872 /* s3c2443_clk_initparents
874 * Initialise the parents for the clocks that we get at start-time
877 static int __init clk_init_set_parent(struct clk *clk, struct clk *parent)
879 printk(KERN_DEBUG "clock %s: parent %s\n", clk->name, parent->name);
880 return clk_set_parent(clk, parent);
883 static void __init s3c2443_clk_initparents(void)
885 unsigned long clksrc = __raw_readl(S3C2443_CLKSRC);
888 switch (clksrc & S3C2443_CLKSRC_EPLLREF_MASK) {
889 case S3C2443_CLKSRC_EPLLREF_EXTCLK:
893 case S3C2443_CLKSRC_EPLLREF_XTAL:
898 case S3C2443_CLKSRC_EPLLREF_MPLLREF:
899 case S3C2443_CLKSRC_EPLLREF_MPLLREF2:
900 parent = &clk_mpllref;
904 clk_init_set_parent(&clk_epllref, parent);
906 switch (clksrc & S3C2443_CLKSRC_I2S_MASK) {
907 case S3C2443_CLKSRC_I2S_EXT:
908 parent = &clk_i2s_ext;
911 case S3C2443_CLKSRC_I2S_EPLLDIV:
913 parent = &clk_i2s_eplldiv;
916 case S3C2443_CLKSRC_I2S_EPLLREF:
917 case S3C2443_CLKSRC_I2S_EPLLREF3:
918 parent = &clk_epllref;
921 clk_init_set_parent(&clk_i2s, &clk_epllref);
925 parent = (clksrc & S3C2443_CLKSRC_ESYSCLK_EPLL) ?
926 &clk_epll : &clk_epllref;
928 clk_init_set_parent(&clk_esysclk, parent);
932 if (clksrc & S3C2443_CLKSRC_MSYSCLK_MPLL) {
935 parent = (clksrc & S3C2443_CLKSRC_EXTCLK_DIV) ?
936 &clk_mdivclk : &clk_mpllref;
939 clk_init_set_parent(&clk_msysclk, parent);
943 if (__raw_readl(S3C2443_CLKDIV0) & S3C2443_CLKDIV0_DVS)
946 parent = &clk_armdiv;
948 clk_init_set_parent(&clk_arm, parent);
951 /* armdiv divisor table */
953 static unsigned int armdiv[16] = {
954 [S3C2443_CLKDIV0_ARMDIV_1 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 1,
955 [S3C2443_CLKDIV0_ARMDIV_2 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 2,
956 [S3C2443_CLKDIV0_ARMDIV_3 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 3,
957 [S3C2443_CLKDIV0_ARMDIV_4 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 4,
958 [S3C2443_CLKDIV0_ARMDIV_6 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 6,
959 [S3C2443_CLKDIV0_ARMDIV_8 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 8,
960 [S3C2443_CLKDIV0_ARMDIV_12 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 12,
961 [S3C2443_CLKDIV0_ARMDIV_16 >> S3C2443_CLKDIV0_ARMDIV_SHIFT] = 16,
964 static inline unsigned int s3c2443_fclk_div(unsigned long clkcon0)
966 clkcon0 &= S3C2443_CLKDIV0_ARMDIV_MASK;
968 return armdiv[clkcon0 >> S3C2443_CLKDIV0_ARMDIV_SHIFT];
971 static inline unsigned long s3c2443_get_hdiv(unsigned long clkcon0)
973 clkcon0 &= S3C2443_CLKDIV0_HCLKDIV_MASK;
978 /* clocks to add straight away */
980 static struct clk *clks[] __initdata = {
1002 void __init_or_cpufreq s3c2443_setup_clocks(void)
1004 unsigned long mpllcon = __raw_readl(S3C2443_MPLLCON);
1005 unsigned long clkdiv0 = __raw_readl(S3C2443_CLKDIV0);
1006 struct clk *xtal_clk;
1013 xtal_clk = clk_get(NULL, "xtal");
1014 xtal = clk_get_rate(xtal_clk);
1017 pll = s3c2443_get_mpll(mpllcon, xtal);
1018 clk_msysclk.rate = pll;
1020 fclk = pll / s3c2443_fclk_div(clkdiv0);
1021 hclk = s3c2443_prediv_getrate(&clk_prediv);
1022 hclk /= s3c2443_get_hdiv(clkdiv0);
1023 pclk = hclk / ((clkdiv0 & S3C2443_CLKDIV0_HALF_PCLK) ? 2 : 1);
1025 s3c24xx_setup_clocks(fclk, hclk, pclk);
1027 printk("S3C2443: mpll %s %ld.%03ld MHz, cpu %ld.%03ld MHz, mem %ld.%03ld MHz, pclk %ld.%03ld MHz\n",
1028 (mpllcon & S3C2443_PLLCON_OFF) ? "off":"on",
1029 print_mhz(pll), print_mhz(fclk),
1030 print_mhz(hclk), print_mhz(pclk));
1032 s3c24xx_setup_clocks(fclk, hclk, pclk);
1035 void __init s3c2443_init_clocks(int xtal)
1038 unsigned long epllcon = __raw_readl(S3C2443_EPLLCON);
1042 /* s3c2443 parents h and p clocks from prediv */
1043 clk_h.parent = &clk_prediv;
1044 clk_p.parent = &clk_prediv;
1046 s3c24xx_register_baseclocks(xtal);
1047 s3c2443_setup_clocks();
1048 s3c2443_clk_initparents();
1050 for (ptr = 0; ptr < ARRAY_SIZE(clks); ptr++) {
1053 ret = s3c24xx_register_clock(clkp);
1055 printk(KERN_ERR "Failed to register clock %s (%d)\n",
1060 clk_epll.rate = s3c2443_get_epll(epllcon, xtal);
1061 clk_epll.parent = &clk_epllref;
1062 clk_usb_bus.parent = &clk_usb_bus_host;
1064 /* ensure usb bus clock is within correct rate of 48MHz */
1066 if (clk_get_rate(&clk_usb_bus_host) != (48 * 1000 * 1000)) {
1067 printk(KERN_INFO "Warning: USB host bus not at 48MHz\n");
1068 clk_set_rate(&clk_usb_bus_host, 48*1000*1000);
1071 printk("S3C2443: epll %s %ld.%03ld MHz, usb-bus %ld.%03ld MHz\n",
1072 (epllcon & S3C2443_PLLCON_OFF) ? "off":"on",
1073 print_mhz(clk_get_rate(&clk_epll)),
1074 print_mhz(clk_get_rate(&clk_usb_bus)));
1076 /* register clocks from clock array */
1079 for (ptr = 0; ptr < ARRAY_SIZE(init_clocks); ptr++, clkp++) {
1080 ret = s3c24xx_register_clock(clkp);
1082 printk(KERN_ERR "Failed to register clock %s (%d)\n",
1087 /* We must be careful disabling the clocks we are not intending to
1088 * be using at boot time, as subsystems such as the LCD which do
1089 * their own DMA requests to the bus can cause the system to lockup
1090 * if they where in the middle of requesting bus access.
1092 * Disabling the LCD clock if the LCD is active is very dangerous,
1093 * and therefore the bootloader should be careful to not enable
1094 * the LCD clock if it is not needed.
1097 /* install (and disable) the clocks we do not need immediately */
1099 clkp = init_clocks_disable;
1100 for (ptr = 0; ptr < ARRAY_SIZE(init_clocks_disable); ptr++, clkp++) {
1102 ret = s3c24xx_register_clock(clkp);
1104 printk(KERN_ERR "Failed to register clock %s (%d)\n",
1108 (clkp->enable)(clkp, 0);