blob: 136c7794a6f51325cc0556194da952eefd42406b [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
wdenk281e00a2004-08-01 22:48:16 +00002 * (C) Copyright 2001-2004
wdenkc6097192002-11-03 00:24:07 +00003 * 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>
wdenk281e00a2004-08-01 22:48:16 +000033#if defined(CONFIG_S3C2400) || defined (CONFIG_S3C2410) || defined (CONFIG_TRAB)
34
kevin.morfitt@fearnside-systems.co.ukd67cce22009-10-10 13:30:22 +090035#include <asm/io.h>
36
wdenkc6097192002-11-03 00:24:07 +000037#if defined(CONFIG_S3C2400)
38#include <s3c2400.h>
39#elif defined(CONFIG_S3C2410)
40#include <s3c2410.h>
41#endif
42
43#define MPLL 0
44#define UPLL 1
45
46/* ------------------------------------------------------------------------- */
47/* NOTE: This describes the proper use of this file.
48 *
wdenk7f6c2cb2002-11-10 22:06:23 +000049 * CONFIG_SYS_CLK_FREQ should be defined as the input frequency of the PLL.
wdenkc6097192002-11-03 00:24:07 +000050 *
51 * get_FCLK(), get_HCLK(), get_PCLK() and get_UCLK() return the clock of
52 * the specified bus in HZ.
53 */
54/* ------------------------------------------------------------------------- */
55
56static ulong get_PLLCLK(int pllreg)
57{
kevin.morfitt@fearnside-systems.co.ukd67cce22009-10-10 13:30:22 +090058 struct s3c24x0_clock_power *clk_power = s3c24x0_get_base_clock_power();
59 ulong r, m, p, s;
wdenkc6097192002-11-03 00:24:07 +000060
kevin.morfitt@fearnside-systems.co.ukd67cce22009-10-10 13:30:22 +090061 if (pllreg == MPLL)
62 r = readl(&clk_power->MPLLCON);
63 else if (pllreg == UPLL)
64 r = readl(&clk_power->UPLLCON);
65 else
66 hang();
wdenkc6097192002-11-03 00:24:07 +000067
kevin.morfitt@fearnside-systems.co.ukd67cce22009-10-10 13:30:22 +090068 m = ((r & 0xFF000) >> 12) + 8;
69 p = ((r & 0x003F0) >> 4) + 2;
70 s = r & 0x3;
wdenkc6097192002-11-03 00:24:07 +000071
kevin.morfitt@fearnside-systems.co.ukd67cce22009-10-10 13:30:22 +090072 return (CONFIG_SYS_CLK_FREQ * m) / (p << s);
wdenkc6097192002-11-03 00:24:07 +000073}
74
75/* return FCLK frequency */
76ulong get_FCLK(void)
77{
kevin.morfitt@fearnside-systems.co.ukd67cce22009-10-10 13:30:22 +090078 return get_PLLCLK(MPLL);
wdenkc6097192002-11-03 00:24:07 +000079}
80
81/* return HCLK frequency */
82ulong get_HCLK(void)
83{
kevin.morfitt@fearnside-systems.co.ukd67cce22009-10-10 13:30:22 +090084 struct s3c24x0_clock_power *clk_power = s3c24x0_get_base_clock_power();
wdenkc6097192002-11-03 00:24:07 +000085
kevin.morfitt@fearnside-systems.co.ukd67cce22009-10-10 13:30:22 +090086 return (readl(&clk_power->CLKDIVN) & 2) ? get_FCLK() / 2 : get_FCLK();
wdenkc6097192002-11-03 00:24:07 +000087}
88
89/* return PCLK frequency */
90ulong get_PCLK(void)
91{
kevin.morfitt@fearnside-systems.co.ukd67cce22009-10-10 13:30:22 +090092 struct s3c24x0_clock_power *clk_power = s3c24x0_get_base_clock_power();
wdenkc6097192002-11-03 00:24:07 +000093
kevin.morfitt@fearnside-systems.co.ukd67cce22009-10-10 13:30:22 +090094 return (readl(&clk_power->CLKDIVN) & 1) ? get_HCLK() / 2 : get_HCLK();
wdenkc6097192002-11-03 00:24:07 +000095}
96
97/* return UCLK frequency */
98ulong get_UCLK(void)
99{
kevin.morfitt@fearnside-systems.co.ukd67cce22009-10-10 13:30:22 +0900100 return get_PLLCLK(UPLL);
wdenkc6097192002-11-03 00:24:07 +0000101}
wdenk281e00a2004-08-01 22:48:16 +0000102
kevin.morfitt@fearnside-systems.co.ukd67cce22009-10-10 13:30:22 +0900103#endif /* defined(CONFIG_S3C2400) ||
104 defined (CONFIG_S3C2410) ||
105 defined (CONFIG_TRAB) */