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>
35 #include <asm/mach/map.h>
37 #include <asm/hardware.h>
40 #include <asm/arch/regs-s3c2443-clock.h>
42 #include <asm/plat-s3c24xx/s3c2443.h>
43 #include <asm/plat-s3c24xx/clock.h>
44 #include <asm/plat-s3c24xx/cpu.h>
46 /* We currently have to assume that the system is running
47 * from the XTPll input, and that all ***REFCLKs are being
48 * fed from it, as we cannot read the state of OM[4] from
51 * It would be possible for each board initialisation to
52 * set the correct muxing at initialisation
55 static int s3c2443_clkcon_enable_h(struct clk
*clk
, int enable
)
57 unsigned int clocks
= clk
->ctrlbit
;
60 clkcon
= __raw_readl(S3C2443_HCLKCON
);
67 __raw_writel(clkcon
, S3C2443_HCLKCON
);
72 static int s3c2443_clkcon_enable_p(struct clk
*clk
, int enable
)
74 unsigned int clocks
= clk
->ctrlbit
;
77 clkcon
= __raw_readl(S3C2443_PCLKCON
);
84 __raw_writel(clkcon
, S3C2443_HCLKCON
);
89 static int s3c2443_clkcon_enable_s(struct clk
*clk
, int enable
)
91 unsigned int clocks
= clk
->ctrlbit
;
94 clkcon
= __raw_readl(S3C2443_SCLKCON
);
101 __raw_writel(clkcon
, S3C2443_SCLKCON
);
106 static unsigned long s3c2443_roundrate_clksrc(struct clk
*clk
,
110 unsigned long parent_rate
= clk_get_rate(clk
->parent
);
113 if (rate
> parent_rate
)
116 /* note, we remove the +/- 1 calculations as they cancel out */
118 div
= (rate
/ parent_rate
);
125 return parent_rate
/ div
;
128 static unsigned long s3c2443_roundrate_clksrc4(struct clk
*clk
,
131 return s3c2443_roundrate_clksrc(clk
, rate
, 4);
134 static unsigned long s3c2443_roundrate_clksrc16(struct clk
*clk
,
137 return s3c2443_roundrate_clksrc(clk
, rate
, 16);
140 static unsigned long s3c2443_roundrate_clksrc256(struct clk
*clk
,
143 return s3c2443_roundrate_clksrc(clk
, rate
, 256);
146 /* clock selections */
148 /* CPU EXTCLK input */
149 static struct clk clk_ext
= {
154 static struct clk clk_mpllref
= {
161 static struct clk clk_mpll
= {
163 .parent
= &clk_mpllref
,
168 static struct clk clk_epllref
;
170 static struct clk clk_epll
= {
172 .parent
= &clk_epllref
,
176 static struct clk clk_i2s_ext
= {
181 static int s3c2443_setparent_epllref(struct clk
*clk
, struct clk
*parent
)
183 unsigned long clksrc
= __raw_readl(S3C2443_CLKSRC
);
185 clksrc
&= ~S3C2443_CLKSRC_EPLLREF_MASK
;
187 if (parent
== &clk_xtal
)
188 clksrc
|= S3C2443_CLKSRC_EPLLREF_XTAL
;
189 else if (parent
== &clk_ext
)
190 clksrc
|= S3C2443_CLKSRC_EPLLREF_EXTCLK
;
191 else if (parent
!= &clk_mpllref
)
194 __raw_writel(clksrc
, S3C2443_CLKSRC
);
195 clk
->parent
= parent
;
200 static struct clk clk_epllref
= {
203 .set_parent
= s3c2443_setparent_epllref
,
206 static unsigned long s3c2443_getrate_mdivclk(struct clk
*clk
)
208 unsigned long parent_rate
= clk_get_rate(clk
->parent
);
209 unsigned long div
= __raw_readl(S3C2443_CLKDIV0
);
211 div
&= S3C2443_CLKDIV0_EXTDIV_MASK
;
212 div
>>= (S3C2443_CLKDIV0_EXTDIV_SHIFT
-1); /* x2 */
214 return parent_rate
/ (div
+ 1);
217 static struct clk clk_mdivclk
= {
219 .parent
= &clk_mpllref
,
221 .get_rate
= s3c2443_getrate_mdivclk
,
225 static int s3c2443_setparent_msysclk(struct clk
*clk
, struct clk
*parent
)
227 unsigned long clksrc
= __raw_readl(S3C2443_CLKSRC
);
229 clksrc
&= ~(S3C2443_CLKSRC_MSYSCLK_MPLL
|
230 S3C2443_CLKSRC_EXTCLK_DIV
);
232 if (parent
== &clk_mpll
)
233 clksrc
|= S3C2443_CLKSRC_MSYSCLK_MPLL
;
234 else if (parent
== &clk_mdivclk
)
235 clksrc
|= S3C2443_CLKSRC_EXTCLK_DIV
;
236 else if (parent
!= &clk_mpllref
)
239 __raw_writel(clksrc
, S3C2443_CLKSRC
);
240 clk
->parent
= parent
;
245 static struct clk clk_msysclk
= {
249 .set_parent
= s3c2443_setparent_msysclk
,
255 * this is sourced from either the EPLL or the EPLLref clock
258 static int s3c2443_setparent_esysclk(struct clk
*clk
, struct clk
*parent
)
260 unsigned long clksrc
= __raw_readl(S3C2443_CLKSRC
);
262 if (parent
== &clk_epll
)
263 clksrc
|= S3C2443_CLKSRC_ESYSCLK_EPLL
;
264 else if (parent
== &clk_epllref
)
265 clksrc
&= ~S3C2443_CLKSRC_ESYSCLK_EPLL
;
269 __raw_writel(clksrc
, S3C2443_CLKSRC
);
270 clk
->parent
= parent
;
275 static struct clk clk_esysclk
= {
279 .set_parent
= s3c2443_setparent_esysclk
,
284 * UART baud-rate clock sourced from esysclk via a divisor
287 static unsigned long s3c2443_getrate_uart(struct clk
*clk
)
289 unsigned long parent_rate
= clk_get_rate(clk
->parent
);
290 unsigned long div
= __raw_readl(S3C2443_CLKDIV1
);
292 div
&= S3C2443_CLKDIV1_UARTDIV_MASK
;
293 div
>>= S3C2443_CLKDIV1_UARTDIV_SHIFT
;
295 return parent_rate
/ (div
+ 1);
299 static int s3c2443_setrate_uart(struct clk
*clk
, unsigned long rate
)
301 unsigned long parent_rate
= clk_get_rate(clk
->parent
);
302 unsigned long clkdivn
= __raw_readl(S3C2443_CLKDIV1
);
304 rate
= s3c2443_roundrate_clksrc16(clk
, rate
);
305 rate
= parent_rate
/ rate
;
307 clkdivn
&= ~S3C2443_CLKDIV1_UARTDIV_MASK
;
308 clkdivn
|= (rate
- 1) << S3C2443_CLKDIV1_UARTDIV_SHIFT
;
310 __raw_writel(clkdivn
, S3C2443_CLKDIV1
);
314 static struct clk clk_uart
= {
317 .parent
= &clk_esysclk
,
318 .get_rate
= s3c2443_getrate_uart
,
319 .set_rate
= s3c2443_setrate_uart
,
320 .round_rate
= s3c2443_roundrate_clksrc16
,
325 * high-speed spi clock, sourced from esysclk
328 static unsigned long s3c2443_getrate_hsspi(struct clk
*clk
)
330 unsigned long parent_rate
= clk_get_rate(clk
->parent
);
331 unsigned long div
= __raw_readl(S3C2443_CLKDIV1
);
333 div
&= S3C2443_CLKDIV1_HSSPIDIV_MASK
;
334 div
>>= S3C2443_CLKDIV1_HSSPIDIV_SHIFT
;
336 return parent_rate
/ (div
+ 1);
340 static int s3c2443_setrate_hsspi(struct clk
*clk
, unsigned long rate
)
342 unsigned long parent_rate
= clk_get_rate(clk
->parent
);
343 unsigned long clkdivn
= __raw_readl(S3C2443_CLKDIV1
);
345 rate
= s3c2443_roundrate_clksrc4(clk
, rate
);
346 rate
= parent_rate
/ rate
;
348 clkdivn
&= ~S3C2443_CLKDIV1_HSSPIDIV_MASK
;
349 clkdivn
|= (rate
- 1) << S3C2443_CLKDIV1_HSSPIDIV_SHIFT
;
351 __raw_writel(clkdivn
, S3C2443_CLKDIV1
);
355 static struct clk clk_hsspi
= {
358 .parent
= &clk_esysclk
,
359 .ctrlbit
= S3C2443_SCLKCON_HSSPICLK
,
360 .enable
= s3c2443_clkcon_enable_s
,
361 .get_rate
= s3c2443_getrate_hsspi
,
362 .set_rate
= s3c2443_setrate_hsspi
,
363 .round_rate
= s3c2443_roundrate_clksrc4
,
368 * usb host bus-clock, usually 48MHz to provide USB bus clock timing
371 static unsigned long s3c2443_getrate_usbhost(struct clk
*clk
)
373 unsigned long parent_rate
= clk_get_rate(clk
->parent
);
374 unsigned long div
= __raw_readl(S3C2443_CLKDIV1
);
376 div
&= S3C2443_CLKDIV1_USBHOSTDIV_MASK
;
377 div
>>= S3C2443_CLKDIV1_USBHOSTDIV_SHIFT
;
379 return parent_rate
/ (div
+ 1);
382 static int s3c2443_setrate_usbhost(struct clk
*clk
, unsigned long rate
)
384 unsigned long parent_rate
= clk_get_rate(clk
->parent
);
385 unsigned long clkdivn
= __raw_readl(S3C2443_CLKDIV1
);
387 rate
= s3c2443_roundrate_clksrc4(clk
, rate
);
388 rate
= parent_rate
/ rate
;
390 clkdivn
&= ~S3C2443_CLKDIV1_USBHOSTDIV_MASK
;
391 clkdivn
|= (rate
- 1) << S3C2443_CLKDIV1_USBHOSTDIV_SHIFT
;
393 __raw_writel(clkdivn
, S3C2443_CLKDIV1
);
397 static struct clk clk_usb_bus_host
= {
398 .name
= "usb-bus-host-parent",
400 .parent
= &clk_esysclk
,
401 .ctrlbit
= S3C2443_SCLKCON_USBHOST
,
402 .enable
= s3c2443_clkcon_enable_s
,
403 .get_rate
= s3c2443_getrate_usbhost
,
404 .set_rate
= s3c2443_setrate_usbhost
,
405 .round_rate
= s3c2443_roundrate_clksrc4
,
410 * this clock is sourced from epll, and is fed through a divider,
411 * to a mux controlled by sclkcon where either it or a extclk can
412 * be fed to the hsmmc block
415 static unsigned long s3c2443_getrate_hsmmc_div(struct clk
*clk
)
417 unsigned long parent_rate
= clk_get_rate(clk
->parent
);
418 unsigned long div
= __raw_readl(S3C2443_CLKDIV1
);
420 div
&= S3C2443_CLKDIV1_HSMMCDIV_MASK
;
421 div
>>= S3C2443_CLKDIV1_HSMMCDIV_SHIFT
;
423 return parent_rate
/ (div
+ 1);
426 static int s3c2443_setrate_hsmmc_div(struct clk
*clk
, unsigned long rate
)
428 unsigned long parent_rate
= clk_get_rate(clk
->parent
);
429 unsigned long clkdivn
= __raw_readl(S3C2443_CLKDIV1
);
431 rate
= s3c2443_roundrate_clksrc4(clk
, rate
);
432 rate
= parent_rate
/ rate
;
434 clkdivn
&= ~S3C2443_CLKDIV1_HSMMCDIV_MASK
;
435 clkdivn
|= (rate
- 1) << S3C2443_CLKDIV1_HSMMCDIV_SHIFT
;
437 __raw_writel(clkdivn
, S3C2443_CLKDIV1
);
441 static struct clk clk_hsmmc_div
= {
444 .parent
= &clk_esysclk
,
445 .get_rate
= s3c2443_getrate_hsmmc_div
,
446 .set_rate
= s3c2443_setrate_hsmmc_div
,
447 .round_rate
= s3c2443_roundrate_clksrc4
,
450 static int s3c2443_setparent_hsmmc(struct clk
*clk
, struct clk
*parent
)
452 unsigned long clksrc
= __raw_readl(S3C2443_SCLKCON
);
454 clksrc
&= ~(S3C2443_SCLKCON_HSMMCCLK_EXT
|
455 S3C2443_SCLKCON_HSMMCCLK_EPLL
);
457 if (parent
== &clk_epll
)
458 clksrc
|= S3C2443_SCLKCON_HSMMCCLK_EPLL
;
459 else if (parent
== &clk_ext
)
460 clksrc
|= S3C2443_SCLKCON_HSMMCCLK_EXT
;
464 if (clk
->usage
> 0) {
465 __raw_writel(clksrc
, S3C2443_SCLKCON
);
468 clk
->parent
= parent
;
472 static int s3c2443_enable_hsmmc(struct clk
*clk
, int enable
)
474 return s3c2443_setparent_hsmmc(clk
, clk
->parent
);
477 static struct clk clk_hsmmc
= {
480 .parent
= &clk_hsmmc_div
,
481 .enable
= s3c2443_enable_hsmmc
,
482 .set_parent
= s3c2443_setparent_hsmmc
,
487 * this clock is the output from the i2s divisor of esysclk
490 static unsigned long s3c2443_getrate_i2s_eplldiv(struct clk
*clk
)
492 unsigned long parent_rate
= clk_get_rate(clk
->parent
);
493 unsigned long div
= __raw_readl(S3C2443_CLKDIV1
);
495 div
&= S3C2443_CLKDIV1_I2SDIV_MASK
;
496 div
>>= S3C2443_CLKDIV1_I2SDIV_SHIFT
;
498 return parent_rate
/ (div
+ 1);
501 static int s3c2443_setrate_i2s_eplldiv(struct clk
*clk
, unsigned long rate
)
503 unsigned long parent_rate
= clk_get_rate(clk
->parent
);
504 unsigned long clkdivn
= __raw_readl(S3C2443_CLKDIV1
);
506 rate
= s3c2443_roundrate_clksrc16(clk
, rate
);
507 rate
= parent_rate
/ rate
;
509 clkdivn
&= ~S3C2443_CLKDIV1_I2SDIV_MASK
;
510 clkdivn
|= (rate
- 1) << S3C2443_CLKDIV1_I2SDIV_SHIFT
;
512 __raw_writel(clkdivn
, S3C2443_CLKDIV1
);
516 static struct clk clk_i2s_eplldiv
= {
517 .name
= "i2s-eplldiv",
519 .parent
= &clk_esysclk
,
520 .get_rate
= s3c2443_getrate_i2s_eplldiv
,
521 .set_rate
= s3c2443_setrate_i2s_eplldiv
,
522 .round_rate
= s3c2443_roundrate_clksrc16
,
527 * i2s bus reference clock, selectable from external, esysclk or epllref
530 static int s3c2443_setparent_i2s(struct clk
*clk
, struct clk
*parent
)
532 unsigned long clksrc
= __raw_readl(S3C2443_CLKSRC
);
534 clksrc
&= ~S3C2443_CLKSRC_I2S_MASK
;
536 if (parent
== &clk_epllref
)
537 clksrc
|= S3C2443_CLKSRC_I2S_EPLLREF
;
538 else if (parent
== &clk_i2s_ext
)
539 clksrc
|= S3C2443_CLKSRC_I2S_EXT
;
540 else if (parent
!= &clk_i2s_eplldiv
)
543 clk
->parent
= parent
;
544 __raw_writel(clksrc
, S3C2443_CLKSRC
);
549 static struct clk clk_i2s
= {
552 .parent
= &clk_i2s_eplldiv
,
553 .ctrlbit
= S3C2443_SCLKCON_I2SCLK
,
554 .enable
= s3c2443_clkcon_enable_s
,
555 .set_parent
= s3c2443_setparent_i2s
,
560 * camera interface bus-clock, divided down from esysclk
563 static unsigned long s3c2443_getrate_cam(struct clk
*clk
)
565 unsigned long parent_rate
= clk_get_rate(clk
->parent
);
566 unsigned long div
= __raw_readl(S3C2443_CLKDIV1
);
568 div
&= S3C2443_CLKDIV1_CAMDIV_MASK
;
569 div
>>= S3C2443_CLKDIV1_CAMDIV_SHIFT
;
571 return parent_rate
/ (div
+ 1);
574 static int s3c2443_setrate_cam(struct clk
*clk
, unsigned long rate
)
576 unsigned long parent_rate
= clk_get_rate(clk
->parent
);
577 unsigned long clkdiv1
= __raw_readl(S3C2443_CLKDIV1
);
579 rate
= s3c2443_roundrate_clksrc16(clk
, rate
);
580 rate
= parent_rate
/ rate
;
582 clkdiv1
&= ~S3C2443_CLKDIV1_CAMDIV_MASK
;
583 clkdiv1
|= (rate
- 1) << S3C2443_CLKDIV1_CAMDIV_SHIFT
;
585 __raw_writel(clkdiv1
, S3C2443_CLKDIV1
);
589 static struct clk clk_cam
= {
590 .name
= "camif-upll", /* same as 2440 name */
592 .parent
= &clk_esysclk
,
593 .ctrlbit
= S3C2443_SCLKCON_CAMCLK
,
594 .enable
= s3c2443_clkcon_enable_s
,
595 .get_rate
= s3c2443_getrate_cam
,
596 .set_rate
= s3c2443_setrate_cam
,
597 .round_rate
= s3c2443_roundrate_clksrc16
,
602 * display interface clock, divided from esysclk
605 static unsigned long s3c2443_getrate_display(struct clk
*clk
)
607 unsigned long parent_rate
= clk_get_rate(clk
->parent
);
608 unsigned long div
= __raw_readl(S3C2443_CLKDIV1
);
610 div
&= S3C2443_CLKDIV1_DISPDIV_MASK
;
611 div
>>= S3C2443_CLKDIV1_DISPDIV_SHIFT
;
613 return parent_rate
/ (div
+ 1);
616 static int s3c2443_setrate_display(struct clk
*clk
, unsigned long rate
)
618 unsigned long parent_rate
= clk_get_rate(clk
->parent
);
619 unsigned long clkdivn
= __raw_readl(S3C2443_CLKDIV1
);
621 rate
= s3c2443_roundrate_clksrc256(clk
, rate
);
622 rate
= parent_rate
/ rate
;
624 clkdivn
&= ~S3C2443_CLKDIV1_UARTDIV_MASK
;
625 clkdivn
|= (rate
- 1) << S3C2443_CLKDIV1_UARTDIV_SHIFT
;
627 __raw_writel(clkdivn
, S3C2443_CLKDIV1
);
631 static struct clk clk_display
= {
632 .name
= "display-if",
634 .parent
= &clk_esysclk
,
635 .ctrlbit
= S3C2443_SCLKCON_DISPCLK
,
636 .enable
= s3c2443_clkcon_enable_s
,
637 .get_rate
= s3c2443_getrate_display
,
638 .set_rate
= s3c2443_setrate_display
,
639 .round_rate
= s3c2443_roundrate_clksrc256
,
642 /* standard clock definitions */
644 static struct clk init_clocks_disable
[] = {
653 .enable
= s3c2443_clkcon_enable_p
,
654 .ctrlbit
= S3C2443_PCLKCON_SDI
,
659 .enable
= s3c2443_clkcon_enable_p
,
660 .ctrlbit
= S3C2443_PCLKCON_ADC
,
665 .enable
= s3c2443_clkcon_enable_p
,
666 .ctrlbit
= S3C2443_PCLKCON_IIC
,
671 .enable
= s3c2443_clkcon_enable_p
,
672 .ctrlbit
= S3C2443_PCLKCON_IIS
,
677 .enable
= s3c2443_clkcon_enable_p
,
678 .ctrlbit
= S3C2443_PCLKCON_SPI0
,
683 .enable
= s3c2443_clkcon_enable_p
,
684 .ctrlbit
= S3C2443_PCLKCON_SPI1
,
688 static struct clk init_clocks
[] = {
693 .enable
= s3c2443_clkcon_enable_h
,
694 .ctrlbit
= S3C2443_HCLKCON_DMA0
,
699 .enable
= s3c2443_clkcon_enable_h
,
700 .ctrlbit
= S3C2443_HCLKCON_DMA1
,
705 .enable
= s3c2443_clkcon_enable_h
,
706 .ctrlbit
= S3C2443_HCLKCON_DMA2
,
711 .enable
= s3c2443_clkcon_enable_h
,
712 .ctrlbit
= S3C2443_HCLKCON_DMA3
,
717 .enable
= s3c2443_clkcon_enable_h
,
718 .ctrlbit
= S3C2443_HCLKCON_DMA4
,
723 .enable
= s3c2443_clkcon_enable_h
,
724 .ctrlbit
= S3C2443_HCLKCON_DMA5
,
729 .enable
= s3c2443_clkcon_enable_h
,
730 .ctrlbit
= S3C2443_HCLKCON_LCDC
,
735 .enable
= s3c2443_clkcon_enable_p
,
736 .ctrlbit
= S3C2443_PCLKCON_GPIO
,
741 .enable
= s3c2443_clkcon_enable_h
,
742 .ctrlbit
= S3C2443_HCLKCON_USBH
,
744 .name
= "usb-device",
747 .enable
= s3c2443_clkcon_enable_h
,
748 .ctrlbit
= S3C2443_HCLKCON_USBD
,
753 .enable
= s3c2443_clkcon_enable_h
,
754 .ctrlbit
= S3C2443_HCLKCON_HSMMC
,
759 .enable
= s3c2443_clkcon_enable_h
,
760 .ctrlbit
= S3C2443_HCLKCON_CFC
,
765 .enable
= s3c2443_clkcon_enable_h
,
766 .ctrlbit
= S3C2443_HCLKCON_SSMC
,
771 .enable
= s3c2443_clkcon_enable_p
,
772 .ctrlbit
= S3C2443_PCLKCON_PWMT
,
777 .enable
= s3c2443_clkcon_enable_p
,
778 .ctrlbit
= S3C2443_PCLKCON_UART0
,
783 .enable
= s3c2443_clkcon_enable_p
,
784 .ctrlbit
= S3C2443_PCLKCON_UART1
,
789 .enable
= s3c2443_clkcon_enable_p
,
790 .ctrlbit
= S3C2443_PCLKCON_UART2
,
795 .enable
= s3c2443_clkcon_enable_p
,
796 .ctrlbit
= S3C2443_PCLKCON_UART3
,
801 .enable
= s3c2443_clkcon_enable_p
,
802 .ctrlbit
= S3C2443_PCLKCON_RTC
,
807 .ctrlbit
= S3C2443_PCLKCON_WDT
,
809 .name
= "usb-bus-host",
811 .parent
= &clk_usb_bus_host
,
816 .ctrlbit
= S3C2443_PCLKCON_AC97
,
820 /* clocks to add where we need to check their parentage */
822 /* s3c2443_clk_initparents
824 * Initialise the parents for the clocks that we get at start-time
827 static int __init
clk_init_set_parent(struct clk
*clk
, struct clk
*parent
)
829 printk(KERN_DEBUG
"clock %s: parent %s\n", clk
->name
, parent
->name
);
830 return clk_set_parent(clk
, parent
);
833 static void __init
s3c2443_clk_initparents(void)
835 unsigned long clksrc
= __raw_readl(S3C2443_CLKSRC
);
838 switch (clksrc
& S3C2443_CLKSRC_EPLLREF_MASK
) {
839 case S3C2443_CLKSRC_EPLLREF_EXTCLK
:
843 case S3C2443_CLKSRC_EPLLREF_XTAL
:
848 case S3C2443_CLKSRC_EPLLREF_MPLLREF
:
849 case S3C2443_CLKSRC_EPLLREF_MPLLREF2
:
850 parent
= &clk_mpllref
;
854 clk_init_set_parent(&clk_epllref
, parent
);
856 switch (clksrc
& S3C2443_CLKSRC_I2S_MASK
) {
857 case S3C2443_CLKSRC_I2S_EXT
:
858 parent
= &clk_i2s_ext
;
861 case S3C2443_CLKSRC_I2S_EPLLDIV
:
863 parent
= &clk_i2s_eplldiv
;
866 case S3C2443_CLKSRC_I2S_EPLLREF
:
867 case S3C2443_CLKSRC_I2S_EPLLREF3
:
868 parent
= &clk_epllref
;
871 clk_init_set_parent(&clk_i2s
, &clk_epllref
);
875 parent
= (clksrc
& S3C2443_CLKSRC_ESYSCLK_EPLL
) ?
876 &clk_epll
: &clk_epllref
;
878 clk_init_set_parent(&clk_esysclk
, parent
);
882 if (clksrc
& S3C2443_CLKSRC_MSYSCLK_MPLL
) {
885 parent
= (clksrc
& S3C2443_CLKSRC_EXTCLK_DIV
) ?
886 &clk_mdivclk
: &clk_mpllref
;
889 clk_init_set_parent(&clk_msysclk
, parent
);
892 /* armdiv divisor table */
894 static unsigned int armdiv
[16] = {
895 [S3C2443_CLKDIV0_ARMDIV_1
>> S3C2443_CLKDIV0_ARMDIV_SHIFT
] = 1,
896 [S3C2443_CLKDIV0_ARMDIV_2
>> S3C2443_CLKDIV0_ARMDIV_SHIFT
] = 2,
897 [S3C2443_CLKDIV0_ARMDIV_3
>> S3C2443_CLKDIV0_ARMDIV_SHIFT
] = 3,
898 [S3C2443_CLKDIV0_ARMDIV_4
>> S3C2443_CLKDIV0_ARMDIV_SHIFT
] = 4,
899 [S3C2443_CLKDIV0_ARMDIV_6
>> S3C2443_CLKDIV0_ARMDIV_SHIFT
] = 6,
900 [S3C2443_CLKDIV0_ARMDIV_8
>> S3C2443_CLKDIV0_ARMDIV_SHIFT
] = 8,
901 [S3C2443_CLKDIV0_ARMDIV_12
>> S3C2443_CLKDIV0_ARMDIV_SHIFT
] = 12,
902 [S3C2443_CLKDIV0_ARMDIV_16
>> S3C2443_CLKDIV0_ARMDIV_SHIFT
] = 16,
905 static inline unsigned int s3c2443_fclk_div(unsigned long clkcon0
)
907 clkcon0
&= S3C2443_CLKDIV0_ARMDIV_MASK
;
909 return armdiv
[clkcon0
>> S3C2443_CLKDIV0_ARMDIV_SHIFT
];
912 static inline unsigned long s3c2443_get_prediv(unsigned long clkcon0
)
914 clkcon0
&= S3C2443_CLKDIV0_PREDIV_MASK
;
915 clkcon0
>>= S3C2443_CLKDIV0_PREDIV_SHIFT
;
920 /* clocks to add straight away */
922 static struct clk
*clks
[] __initdata
= {
941 void __init
s3c2443_init_clocks(int xtal
)
943 unsigned long epllcon
= __raw_readl(S3C2443_EPLLCON
);
944 unsigned long mpllcon
= __raw_readl(S3C2443_MPLLCON
);
945 unsigned long clkdiv0
= __raw_readl(S3C2443_CLKDIV0
);
954 pll
= s3c2443_get_mpll(mpllcon
, xtal
);
956 fclk
= pll
/ s3c2443_fclk_div(clkdiv0
);
957 hclk
= fclk
/ s3c2443_get_prediv(clkdiv0
);
958 hclk
= hclk
/ ((clkdiv0
& S3C2443_CLKDIV0_HALF_HCLK
) ? 2 : 1);
959 pclk
= hclk
/ ((clkdiv0
& S3C2443_CLKDIV0_HALF_PCLK
) ? 2 : 1);
961 s3c24xx_setup_clocks(xtal
, fclk
, hclk
, pclk
);
963 printk("S3C2443: mpll %s %ld.%03ld MHz, cpu %ld.%03ld MHz, mem %ld.%03ld MHz, pclk %ld.%03ld MHz\n",
964 (mpllcon
& S3C2443_PLLCON_OFF
) ? "off":"on",
965 print_mhz(pll
), print_mhz(fclk
),
966 print_mhz(hclk
), print_mhz(pclk
));
968 s3c2443_clk_initparents();
970 for (ptr
= 0; ptr
< ARRAY_SIZE(clks
); ptr
++) {
973 ret
= s3c24xx_register_clock(clkp
);
975 printk(KERN_ERR
"Failed to register clock %s (%d)\n",
980 clk_epll
.rate
= s3c2443_get_epll(epllcon
, xtal
);
982 clk_usb_bus
.parent
= &clk_usb_bus_host
;
984 /* ensure usb bus clock is within correct rate of 48MHz */
986 if (clk_get_rate(&clk_usb_bus_host
) != (48 * 1000 * 1000)) {
987 printk(KERN_INFO
"Warning: USB host bus not at 48MHz\n");
988 clk_set_rate(&clk_usb_bus_host
, 48*1000*1000);
991 printk("S3C2443: epll %s %ld.%03ld MHz, usb-bus %ld.%03ld MHz\n",
992 (epllcon
& S3C2443_PLLCON_OFF
) ? "off":"on",
993 print_mhz(clk_get_rate(&clk_epll
)),
994 print_mhz(clk_get_rate(&clk_usb_bus
)));
996 /* register clocks from clock array */
999 for (ptr
= 0; ptr
< ARRAY_SIZE(init_clocks
); ptr
++, clkp
++) {
1000 ret
= s3c24xx_register_clock(clkp
);
1002 printk(KERN_ERR
"Failed to register clock %s (%d)\n",
1007 /* We must be careful disabling the clocks we are not intending to
1008 * be using at boot time, as subsystems such as the LCD which do
1009 * their own DMA requests to the bus can cause the system to lockup
1010 * if they where in the middle of requesting bus access.
1012 * Disabling the LCD clock if the LCD is active is very dangerous,
1013 * and therefore the bootloader should be careful to not enable
1014 * the LCD clock if it is not needed.
1017 /* install (and disable) the clocks we do not need immediately */
1019 clkp
= init_clocks_disable
;
1020 for (ptr
= 0; ptr
< ARRAY_SIZE(init_clocks_disable
); ptr
++, clkp
++) {
1022 ret
= s3c24xx_register_clock(clkp
);
1024 printk(KERN_ERR
"Failed to register clock %s (%d)\n",
1028 (clkp
->enable
)(clkp
, 0);