]> git.sur5r.net Git - u-boot/blob - cpu/arm920t/speed.c
* Fix NSCU config; add ethernet wakeup code.
[u-boot] / cpu / arm920t / speed.c
1 /*
2  * (C) Copyright 2001-2002
3  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4  *
5  * (C) Copyright 2002
6  * David Mueller, ELSOFT AG, d.mueller@elsoft.ch
7  *
8  * See file CREDITS for list of people who contributed to this
9  * project.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License as
13  * published by the Free Software Foundation; either version 2 of
14  * the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24  * MA 02111-1307 USA
25  */
26
27 /* This code should work for both the S3C2400 and the S3C2410
28  * as they seem to have the same PLL and clock machinery inside.
29  * The different address mapping is handled by the s3c24xx.h files below.
30  */
31
32 #include <common.h>
33 #if defined(CONFIG_S3C2400)
34 #include <s3c2400.h>
35 #elif defined(CONFIG_S3C2410)
36 #include <s3c2410.h>
37 #endif
38
39 #define MPLL 0
40 #define UPLL 1
41
42 /* ------------------------------------------------------------------------- */
43 /* NOTE: This describes the proper use of this file.
44  *
45  * CONFIG_SYS_CLK_FREQ should be defined as the input frequency of the PLL.
46  *
47  * get_FCLK(), get_HCLK(), get_PCLK() and get_UCLK() return the clock of
48  * the specified bus in HZ.
49  */
50 /* ------------------------------------------------------------------------- */
51
52 static ulong get_PLLCLK(int pllreg)
53 {
54     S3C24X0_CLOCK_POWER * const clk_power = S3C24X0_GetBase_CLOCK_POWER();
55     ulong r, m, p, s;
56
57     if (pllreg == MPLL)
58         r = clk_power->MPLLCON;
59     else if (pllreg == UPLL)
60         r = clk_power->UPLLCON;
61     else
62         hang();
63
64     m = ((r & 0xFF000) >> 12) + 8;
65     p = ((r & 0x003F0) >> 4) + 2;
66     s = r & 0x3;
67
68     return((CONFIG_SYS_CLK_FREQ * m) / (p << s));
69 }
70
71 /* return FCLK frequency */
72 ulong get_FCLK(void)
73 {
74     return(get_PLLCLK(MPLL));
75 }
76
77 /* return HCLK frequency */
78 ulong get_HCLK(void)
79 {
80     S3C24X0_CLOCK_POWER * const clk_power = S3C24X0_GetBase_CLOCK_POWER();
81
82     return((clk_power->CLKDIVN & 0x2) ? get_FCLK()/2 : get_FCLK());
83 }
84
85 /* return PCLK frequency */
86 ulong get_PCLK(void)
87 {
88     S3C24X0_CLOCK_POWER * const clk_power = S3C24X0_GetBase_CLOCK_POWER();
89
90     return((clk_power->CLKDIVN & 0x1) ? get_HCLK()/2 : get_HCLK());
91 }
92
93 /* return UCLK frequency */
94 ulong get_UCLK(void)
95 {
96     return(get_PLLCLK(UPLL));
97 }