2 * arch/arm/mach-s3c24a0/clocks.c
4 * $Id: clocks.c,v 1.3 2006/12/12 13:38:48 gerg Exp $
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/module.h>
16 #include <asm/errno.h>
17 #include <asm/arch/clocks.h>
21 static unsigned long get_usb_clk_freq(int who
)
23 unsigned long val
= UPLLCON
;
25 if (CLKSRC
& (1<<7)) return 0; /* UPLL OFF */
26 val
= ((GET_MDIV(val
) + 8) * FIN
)/((GET_PDIV(val
) + 2) * (1 << GET_SDIV(val
)));
31 * CLKDIVN differs from S3C24A0X to S3C24A0A
35 static inline unsigned long
36 cal_bus_clk(unsigned long cpu_clk
, unsigned long ratio
, int who
)
38 unsigned long hclk
= 0;
39 unsigned long pclk
= 0;
42 return get_usb_clk_freq(GET_UPLL
);
44 switch (ratio
& 0x6) {
55 panic("Wrong Value in CLKDIVN");
57 switch (ratio
& 0x1) {
72 panic("Wrong Clock requested ");
78 * cpu clock = (((mdiv + 8) * FIN) / ((pdiv + 2) * (1 << sdiv)))
79 * FIN = Input Frequency (to CPU)
82 elfin_get_cpu_clk(void)
84 unsigned long val
= MPLLCON
;
86 return (((GET_MDIV(val
) + 8) * FIN
) / ((GET_PDIV(val
) + 2) * (1 << GET_SDIV(val
))));
88 EXPORT_SYMBOL(elfin_get_cpu_clk
);
91 elfin_get_bus_clk(int who
)
93 unsigned long cpu_clk
= elfin_get_cpu_clk();
94 unsigned long ratio
= CLKDIVN_BUS
;
96 return (cal_bus_clk(cpu_clk
, ratio
, who
));
98 EXPORT_SYMBOL(elfin_get_bus_clk
);
100 #define MEGA (1000 * 1000)
101 static int __init
elfin_cpu_init(void)
103 unsigned long freq
, hclk
, pclk
;
105 freq
= elfin_get_cpu_clk();
106 hclk
= elfin_get_bus_clk(GET_HCLK
);
107 pclk
= elfin_get_bus_clk(GET_PCLK
);
109 printk(KERN_INFO
"CPU clock = %ld.%03ld Mhz,", freq
/ MEGA
, freq
% MEGA
);
111 printk(" HCLK = %ld.%03ld Mhz, PCLK = %ld.%03ld Mhz\n",
112 hclk
/ MEGA
, hclk
% MEGA
, pclk
/ MEGA
, pclk
% MEGA
);
117 __initcall(elfin_cpu_init
);