blob: 3701c5d9a3da6aca57b50c9bac3b652248cec727 [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
wdenk7ac16102004-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 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
wdenkc6097192002-11-03 00:24:07 +00009 */
10
11/* This code should work for both the S3C2400 and the S3C2410
12 * as they seem to have the same PLL and clock machinery inside.
13 * The different address mapping is handled by the s3c24xx.h files below.
14 */
15
16#include <common.h>
kevin.morfitt@fearnside-systems.co.uke0d81312009-11-17 18:30:34 +090017#ifdef CONFIG_S3C24X0
wdenk7ac16102004-08-01 22:48:16 +000018
kevin.morfitt@fearnside-systems.co.ukd1cacc72009-10-10 13:30:22 +090019#include <asm/io.h>
kevin.morfitt@fearnside-systems.co.uke0d81312009-11-17 18:30:34 +090020#include <asm/arch/s3c24x0_cpu.h>
wdenkc6097192002-11-03 00:24:07 +000021
22#define MPLL 0
23#define UPLL 1
24
25/* ------------------------------------------------------------------------- */
26/* NOTE: This describes the proper use of this file.
27 *
wdenk1272e232002-11-10 22:06:23 +000028 * CONFIG_SYS_CLK_FREQ should be defined as the input frequency of the PLL.
wdenkc6097192002-11-03 00:24:07 +000029 *
30 * get_FCLK(), get_HCLK(), get_PCLK() and get_UCLK() return the clock of
31 * the specified bus in HZ.
32 */
33/* ------------------------------------------------------------------------- */
34
35static ulong get_PLLCLK(int pllreg)
36{
kevin.morfitt@fearnside-systems.co.ukd1cacc72009-10-10 13:30:22 +090037 struct s3c24x0_clock_power *clk_power = s3c24x0_get_base_clock_power();
38 ulong r, m, p, s;
wdenkc6097192002-11-03 00:24:07 +000039
kevin.morfitt@fearnside-systems.co.ukd1cacc72009-10-10 13:30:22 +090040 if (pllreg == MPLL)
C Nauman383c43e2010-10-26 23:04:31 +090041 r = readl(&clk_power->mpllcon);
kevin.morfitt@fearnside-systems.co.ukd1cacc72009-10-10 13:30:22 +090042 else if (pllreg == UPLL)
C Nauman383c43e2010-10-26 23:04:31 +090043 r = readl(&clk_power->upllcon);
kevin.morfitt@fearnside-systems.co.ukd1cacc72009-10-10 13:30:22 +090044 else
45 hang();
wdenkc6097192002-11-03 00:24:07 +000046
kevin.morfitt@fearnside-systems.co.ukd1cacc72009-10-10 13:30:22 +090047 m = ((r & 0xFF000) >> 12) + 8;
48 p = ((r & 0x003F0) >> 4) + 2;
49 s = r & 0x3;
wdenkc6097192002-11-03 00:24:07 +000050
C Nauman383c43e2010-10-26 23:04:31 +090051#if defined(CONFIG_S3C2440)
52 if (pllreg == MPLL)
53 return 2 * m * (CONFIG_SYS_CLK_FREQ / (p << s));
54#endif
kevin.morfitt@fearnside-systems.co.ukd1cacc72009-10-10 13:30:22 +090055 return (CONFIG_SYS_CLK_FREQ * m) / (p << s);
C Nauman383c43e2010-10-26 23:04:31 +090056
wdenkc6097192002-11-03 00:24:07 +000057}
58
59/* return FCLK frequency */
60ulong get_FCLK(void)
61{
kevin.morfitt@fearnside-systems.co.ukd1cacc72009-10-10 13:30:22 +090062 return get_PLLCLK(MPLL);
wdenkc6097192002-11-03 00:24:07 +000063}
64
65/* return HCLK frequency */
66ulong get_HCLK(void)
67{
kevin.morfitt@fearnside-systems.co.ukd1cacc72009-10-10 13:30:22 +090068 struct s3c24x0_clock_power *clk_power = s3c24x0_get_base_clock_power();
C Nauman383c43e2010-10-26 23:04:31 +090069#ifdef CONFIG_S3C2440
70 switch (readl(&clk_power->clkdivn) & 0x6) {
71 default:
72 case 0:
73 return get_FCLK();
74 case 2:
75 return get_FCLK() / 2;
76 case 4:
77 return (readl(&clk_power->camdivn) & (1 << 9)) ?
78 get_FCLK() / 8 : get_FCLK() / 4;
79 case 6:
80 return (readl(&clk_power->camdivn) & (1 << 8)) ?
81 get_FCLK() / 6 : get_FCLK() / 3;
82 }
83#else
84 return (readl(&clk_power->clkdivn) & 2) ? get_FCLK() / 2 : get_FCLK();
85#endif
wdenkc6097192002-11-03 00:24:07 +000086}
87
88/* return PCLK frequency */
89ulong get_PCLK(void)
90{
kevin.morfitt@fearnside-systems.co.ukd1cacc72009-10-10 13:30:22 +090091 struct s3c24x0_clock_power *clk_power = s3c24x0_get_base_clock_power();
wdenkc6097192002-11-03 00:24:07 +000092
C Nauman383c43e2010-10-26 23:04:31 +090093 return (readl(&clk_power->clkdivn) & 1) ? get_HCLK() / 2 : get_HCLK();
wdenkc6097192002-11-03 00:24:07 +000094}
95
96/* return UCLK frequency */
97ulong get_UCLK(void)
98{
kevin.morfitt@fearnside-systems.co.ukd1cacc72009-10-10 13:30:22 +090099 return get_PLLCLK(UPLL);
wdenkc6097192002-11-03 00:24:07 +0000100}
wdenk7ac16102004-08-01 22:48:16 +0000101
kevin.morfitt@fearnside-systems.co.uke0d81312009-11-17 18:30:34 +0900102#endif /* CONFIG_S3C24X0 */