2 * Copyright (C) 2010 Samsung Electronics
3 * Minkyu Kang <mk7.kang@samsung.com>
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 #include <asm/arch/clock.h>
27 #include <asm/arch/clk.h>
29 /* exynos4: return pll clock frequency */
30 static unsigned long exynos4_get_pll_clk(int pllreg)
32 struct exynos4_clock *clk =
33 (struct exynos4_clock *)samsung_get_base_clock();
34 unsigned long r, m, p, s, k = 0, mask, fout;
39 r = readl(&clk->apll_con0);
42 r = readl(&clk->mpll_con0);
45 r = readl(&clk->epll_con0);
46 k = readl(&clk->epll_con1);
49 r = readl(&clk->vpll_con0);
50 k = readl(&clk->vpll_con1);
53 printf("Unsupported PLL (%d)\n", pllreg);
58 * APLL_CON: MIDV [25:16]
59 * MPLL_CON: MIDV [25:16]
60 * EPLL_CON: MIDV [24:16]
61 * VPLL_CON: MIDV [24:16]
63 if (pllreg == APLL || pllreg == MPLL)
75 freq = CONFIG_SYS_CLK_FREQ;
79 /* FOUT = (MDIV + K / 65536) * FIN / (PDIV * 2^SDIV) */
80 fout = (m + k / 65536) * (freq / (p * (1 << s)));
81 } else if (pllreg == VPLL) {
83 /* FOUT = (MDIV + K / 1024) * FIN / (PDIV * 2^SDIV) */
84 fout = (m + k / 1024) * (freq / (p * (1 << s)));
88 /* FOUT = MDIV * FIN / (PDIV * 2^(SDIV - 1)) */
89 fout = m * (freq / (p * (1 << (s - 1))));
95 /* exynos4: return ARM clock frequency */
96 static unsigned long exynos4_get_arm_clk(void)
98 struct exynos4_clock *clk =
99 (struct exynos4_clock *)samsung_get_base_clock();
101 unsigned long armclk;
102 unsigned int core_ratio;
103 unsigned int core2_ratio;
105 div = readl(&clk->div_cpu0);
107 /* CORE_RATIO: [2:0], CORE2_RATIO: [30:28] */
108 core_ratio = (div >> 0) & 0x7;
109 core2_ratio = (div >> 28) & 0x7;
111 armclk = get_pll_clk(APLL) / (core_ratio + 1);
112 armclk /= (core2_ratio + 1);
117 /* exynos4: return pwm clock frequency */
118 static unsigned long exynos4_get_pwm_clk(void)
120 struct exynos4_clock *clk =
121 (struct exynos4_clock *)samsung_get_base_clock();
122 unsigned long pclk, sclk;
126 if (s5p_get_cpu_rev() == 0) {
131 sel = readl(&clk->src_peril0);
132 sel = (sel >> 24) & 0xf;
135 sclk = get_pll_clk(MPLL);
137 sclk = get_pll_clk(EPLL);
139 sclk = get_pll_clk(VPLL);
147 ratio = readl(&clk->div_peril3);
149 } else if (s5p_get_cpu_rev() == 1) {
150 sclk = get_pll_clk(MPLL);
155 pclk = sclk / (ratio + 1);
160 /* exynos4: return uart clock frequency */
161 static unsigned long exynos4_get_uart_clk(int dev_index)
163 struct exynos4_clock *clk =
164 (struct exynos4_clock *)samsung_get_base_clock();
165 unsigned long uclk, sclk;
178 sel = readl(&clk->src_peril0);
179 sel = (sel >> (dev_index << 2)) & 0xf;
182 sclk = get_pll_clk(MPLL);
184 sclk = get_pll_clk(EPLL);
186 sclk = get_pll_clk(VPLL);
195 * UART3_RATIO [12:15]
196 * UART4_RATIO [16:19]
197 * UART5_RATIO [23:20]
199 ratio = readl(&clk->div_peril0);
200 ratio = (ratio >> (dev_index << 2)) & 0xf;
202 uclk = sclk / (ratio + 1);
207 /* exynos4: set the mmc clock */
208 static void exynos4_set_mmc_clk(int dev_index, unsigned int div)
210 struct exynos4_clock *clk =
211 (struct exynos4_clock *)samsung_get_base_clock();
217 * MMC0_PRE_RATIO [15:8], MMC1_PRE_RATIO [31:24]
219 * MMC2_PRE_RATIO [15:8], MMC3_PRE_RATIO [31:24]
222 addr = (unsigned int)&clk->div_fsys1;
224 addr = (unsigned int)&clk->div_fsys2;
229 val &= ~(0xff << ((dev_index << 4) + 8));
230 val |= (div & 0xff) << ((dev_index << 4) + 8);
234 unsigned long get_pll_clk(int pllreg)
236 return exynos4_get_pll_clk(pllreg);
239 unsigned long get_arm_clk(void)
241 return exynos4_get_arm_clk();
244 unsigned long get_pwm_clk(void)
246 return exynos4_get_pwm_clk();
249 unsigned long get_uart_clk(int dev_index)
251 return exynos4_get_uart_clk(dev_index);
254 void set_mmc_clk(int dev_index, unsigned int div)
256 exynos4_set_mmc_clk(dev_index, div);