]>
git.ipfire.org Git - people/ms/u-boot.git/blob - arch/arm/cpu/armv7/s5pc2xx/clock.c
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 #ifndef CONFIG_SYS_CLK_FREQ_C210
30 #define CONFIG_SYS_CLK_FREQ_C210 24000000
33 /* s5pc210: return pll clock frequency */
34 static unsigned long s5pc210_get_pll_clk(int pllreg
)
36 struct s5pc210_clock
*clk
=
37 (struct s5pc210_clock
*)samsung_get_base_clock();
38 unsigned long r
, m
, p
, s
, k
= 0, mask
, fout
;
43 r
= readl(&clk
->apll_con0
);
46 r
= readl(&clk
->mpll_con0
);
49 r
= readl(&clk
->epll_con0
);
50 k
= readl(&clk
->epll_con1
);
53 r
= readl(&clk
->vpll_con0
);
54 k
= readl(&clk
->vpll_con1
);
57 printf("Unsupported PLL (%d)\n", pllreg
);
62 * APLL_CON: MIDV [25:16]
63 * MPLL_CON: MIDV [25:16]
64 * EPLL_CON: MIDV [24:16]
65 * VPLL_CON: MIDV [24:16]
67 if (pllreg
== APLL
|| pllreg
== MPLL
)
79 freq
= CONFIG_SYS_CLK_FREQ_C210
;
83 /* FOUT = (MDIV + K / 65536) * FIN / (PDIV * 2^SDIV) */
84 fout
= (m
+ k
/ 65536) * (freq
/ (p
* (1 << s
)));
85 } else if (pllreg
== VPLL
) {
87 /* FOUT = (MDIV + K / 1024) * FIN / (PDIV * 2^SDIV) */
88 fout
= (m
+ k
/ 1024) * (freq
/ (p
* (1 << s
)));
92 /* FOUT = MDIV * FIN / (PDIV * 2^(SDIV - 1)) */
93 fout
= m
* (freq
/ (p
* (1 << (s
- 1))));
99 /* s5pc210: return ARM clock frequency */
100 static unsigned long s5pc210_get_arm_clk(void)
102 struct s5pc210_clock
*clk
=
103 (struct s5pc210_clock
*)samsung_get_base_clock();
105 unsigned long dout_apll
;
106 unsigned int apll_ratio
;
108 div
= readl(&clk
->div_cpu0
);
110 /* APLL_RATIO: [26:24] */
111 apll_ratio
= (div
>> 24) & 0x7;
113 dout_apll
= get_pll_clk(APLL
) / (apll_ratio
+ 1);
118 /* s5pc210: return pwm clock frequency */
119 static unsigned long s5pc210_get_pwm_clk(void)
121 struct s5pc210_clock
*clk
=
122 (struct s5pc210_clock
*)samsung_get_base_clock();
123 unsigned long pclk
, sclk
;
127 if (s5p_get_cpu_rev() == 0) {
132 sel
= readl(&clk
->src_peril0
);
133 sel
= (sel
>> 24) & 0xf;
136 sclk
= get_pll_clk(MPLL
);
138 sclk
= get_pll_clk(EPLL
);
140 sclk
= get_pll_clk(VPLL
);
148 ratio
= readl(&clk
->div_peril3
);
150 } else if (s5p_get_cpu_rev() == 1) {
151 sclk
= get_pll_clk(MPLL
);
156 pclk
= sclk
/ (ratio
+ 1);
161 /* s5pc210: return uart clock frequency */
162 static unsigned long s5pc210_get_uart_clk(int dev_index
)
164 struct s5pc210_clock
*clk
=
165 (struct s5pc210_clock
*)samsung_get_base_clock();
166 unsigned long uclk
, sclk
;
179 sel
= readl(&clk
->src_peril0
);
180 sel
= (sel
>> (dev_index
<< 2)) & 0xf;
183 sclk
= get_pll_clk(MPLL
);
185 sclk
= get_pll_clk(EPLL
);
187 sclk
= get_pll_clk(VPLL
);
196 * UART3_RATIO [12:15]
197 * UART4_RATIO [16:19]
198 * UART5_RATIO [23:20]
200 ratio
= readl(&clk
->div_peril0
);
201 ratio
= (ratio
>> (dev_index
<< 2)) & 0xf;
203 uclk
= sclk
/ (ratio
+ 1);
208 /* s5pc210: set the mmc clock */
209 static void s5pc210_set_mmc_clk(int dev_index
, unsigned int div
)
211 struct s5pc210_clock
*clk
=
212 (struct s5pc210_clock
*)samsung_get_base_clock();
218 * MMC0_PRE_RATIO [15:8], MMC1_PRE_RATIO [31:24]
220 * MMC2_PRE_RATIO [15:8], MMC3_PRE_RATIO [31:24]
223 addr
= (unsigned int)&clk
->div_fsys1
;
225 addr
= (unsigned int)&clk
->div_fsys2
;
230 val
&= ~(0xff << ((dev_index
<< 4) + 8));
231 val
|= (div
& 0xff) << ((dev_index
<< 4) + 8);
235 unsigned long get_pll_clk(int pllreg
)
237 return s5pc210_get_pll_clk(pllreg
);
240 unsigned long get_arm_clk(void)
242 return s5pc210_get_arm_clk();
245 unsigned long get_pwm_clk(void)
247 return s5pc210_get_pwm_clk();
250 unsigned long get_uart_clk(int dev_index
)
252 return s5pc210_get_uart_clk(dev_index
);
255 void set_mmc_clk(int dev_index
, unsigned int div
)
257 s5pc210_set_mmc_clk(dev_index
, div
);