MOXA linux-2.6.x / linux-2.6.19-uc1 from UC-7110-LX-BOOTLOADER-1.9_VERSION-4.2.tgz
[linux-2.6.19-moxart.git] / arch / arm / mach-s3c24a0 / clocks.c
blob3dee63b7d6e59f7d42083cc3e600851b4d965ca9
1 /*
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)));
27 return val;
30 /*
31 * CLKDIVN differs from S3C24A0X to S3C24A0A
32 * --SW.LEE
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;
41 if (who == GET_UPLL)
42 return get_usb_clk_freq(GET_UPLL);
44 switch (ratio & 0x6) {
45 case 0:
46 hclk = cpu_clk;
47 break;
48 case 2:
49 hclk = cpu_clk/2;
50 break;
51 case 4:
52 hclk = cpu_clk/4;
53 break;
54 default:
55 panic("Wrong Value in CLKDIVN");
57 switch (ratio & 0x1) {
58 case 0:
59 pclk = hclk;
60 break;
61 case 1:
62 pclk = hclk/2;
63 break;
66 if (who == GET_HCLK)
67 return hclk;
68 else {
69 if (who == GET_PCLK)
70 return pclk;
71 else
72 panic("Wrong Clock requested ");
78 * cpu clock = (((mdiv + 8) * FIN) / ((pdiv + 2) * (1 << sdiv)))
79 * FIN = Input Frequency (to CPU)
81 unsigned long
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);
90 unsigned long
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);
114 return 0;
117 __initcall(elfin_cpu_init);