blob: 031a61899beffb07843c198a3237c385e5e2100a [file] [log] [blame]
Kukjin Kimbf46aae2012-04-15 21:13:29 -07001/*
Kukjin Kim1a0e8a52010-01-14 08:13:37 +09002 * Copyright 2009 Samsung Electronics Co., Ltd.
3 * http://www.samsung.com/
4 *
5 * S5P - Common clock support
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10*/
11
12#include <linux/init.h>
13#include <linux/module.h>
14#include <linux/kernel.h>
15#include <linux/list.h>
16#include <linux/errno.h>
17#include <linux/err.h>
18#include <linux/clk.h>
Kay Sieversedbaa602011-12-21 16:26:03 -080019#include <linux/device.h>
Kukjin Kim1a0e8a52010-01-14 08:13:37 +090020#include <linux/io.h>
21#include <asm/div64.h>
22
Seungwhan Yound4b34c62010-10-14 10:39:08 +090023#include <mach/regs-clock.h>
24
Kukjin Kim1a0e8a52010-01-14 08:13:37 +090025#include <plat/clock.h>
26#include <plat/clock-clksrc.h>
27#include <plat/s5p-clock.h>
28
29/* fin_apll, fin_mpll and fin_epll are all the same clock, which we call
30 * clk_ext_xtal_mux.
31*/
32struct clk clk_ext_xtal_mux = {
33 .name = "ext_xtal",
34 .id = -1,
35};
36
Thomas Abrahamf001d5b2010-04-19 20:05:08 +090037struct clk clk_xusbxti = {
38 .name = "xusbxti",
39 .id = -1,
40};
41
Thomas Abrahama443a632010-05-14 16:27:28 +090042struct clk s5p_clk_27m = {
Kukjin Kim0c1945d2010-02-24 16:40:36 +090043 .name = "clk_27m",
44 .id = -1,
45 .rate = 27000000,
46};
47
Kukjin Kim1a0e8a52010-01-14 08:13:37 +090048/* 48MHz USB Phy clock output */
49struct clk clk_48m = {
50 .name = "clk_48m",
51 .id = -1,
52 .rate = 48000000,
53};
54
55/* APLL clock output
56 * No need .ctrlbit, this is always on
57*/
58struct clk clk_fout_apll = {
59 .name = "fout_apll",
60 .id = -1,
61};
62
Kukjin Kim87b3c6e2012-01-22 21:46:13 +090063/* BPLL clock output */
64
65struct clk clk_fout_bpll = {
66 .name = "fout_bpll",
67 .id = -1,
68};
69
Kisoo Yu57b317f2012-04-24 14:54:15 -070070struct clk clk_fout_bpll_div2 = {
71 .name = "fout_bpll_div2",
72 .id = -1,
73};
74
Kukjin Kim87b3c6e2012-01-22 21:46:13 +090075/* CPLL clock output */
76
77struct clk clk_fout_cpll = {
78 .name = "fout_cpll",
79 .id = -1,
80};
81
Kukjin Kim1a0e8a52010-01-14 08:13:37 +090082/* MPLL clock output
83 * No need .ctrlbit, this is always on
84*/
85struct clk clk_fout_mpll = {
86 .name = "fout_mpll",
87 .id = -1,
88};
89
Kisoo Yu57b317f2012-04-24 14:54:15 -070090struct clk clk_fout_mpll_div2 = {
91 .name = "fout_mpll_div2",
92 .id = -1,
93};
94
Kukjin Kim1a0e8a52010-01-14 08:13:37 +090095/* EPLL clock output */
96struct clk clk_fout_epll = {
97 .name = "fout_epll",
98 .id = -1,
99 .ctrlbit = (1 << 31),
100};
101
Kukjin Kim3109e552010-09-01 15:35:30 +0900102/* DPLL clock output */
103struct clk clk_fout_dpll = {
104 .name = "fout_dpll",
105 .id = -1,
106 .ctrlbit = (1 << 31),
107};
108
Thomas Abrahamf445dbd2010-05-17 09:38:52 +0900109/* VPLL clock output */
110struct clk clk_fout_vpll = {
111 .name = "fout_vpll",
112 .id = -1,
113 .ctrlbit = (1 << 31),
114};
115
Kukjin Kim1a0e8a52010-01-14 08:13:37 +0900116/* Possible clock sources for APLL Mux */
117static struct clk *clk_src_apll_list[] = {
118 [0] = &clk_fin_apll,
119 [1] = &clk_fout_apll,
120};
121
122struct clksrc_sources clk_src_apll = {
123 .sources = clk_src_apll_list,
124 .nr_sources = ARRAY_SIZE(clk_src_apll_list),
125};
126
Kukjin Kim87b3c6e2012-01-22 21:46:13 +0900127/* Possible clock sources for BPLL Mux */
128static struct clk *clk_src_bpll_list[] = {
129 [0] = &clk_fin_bpll,
130 [1] = &clk_fout_bpll,
131};
132
133struct clksrc_sources clk_src_bpll = {
134 .sources = clk_src_bpll_list,
135 .nr_sources = ARRAY_SIZE(clk_src_bpll_list),
136};
137
Kisoo Yu57b317f2012-04-24 14:54:15 -0700138static struct clk *clk_src_bpll_fout_list[] = {
139 [0] = &clk_fout_bpll_div2,
140 [1] = &clk_fout_bpll,
141};
142
143struct clksrc_sources clk_src_bpll_fout = {
144 .sources = clk_src_bpll_fout_list,
145 .nr_sources = ARRAY_SIZE(clk_src_bpll_fout_list),
146};
147
Kukjin Kim87b3c6e2012-01-22 21:46:13 +0900148/* Possible clock sources for CPLL Mux */
149static struct clk *clk_src_cpll_list[] = {
150 [0] = &clk_fin_cpll,
151 [1] = &clk_fout_cpll,
152};
153
154struct clksrc_sources clk_src_cpll = {
155 .sources = clk_src_cpll_list,
156 .nr_sources = ARRAY_SIZE(clk_src_cpll_list),
157};
158
Kukjin Kim1a0e8a52010-01-14 08:13:37 +0900159/* Possible clock sources for MPLL Mux */
160static struct clk *clk_src_mpll_list[] = {
161 [0] = &clk_fin_mpll,
162 [1] = &clk_fout_mpll,
163};
164
165struct clksrc_sources clk_src_mpll = {
166 .sources = clk_src_mpll_list,
167 .nr_sources = ARRAY_SIZE(clk_src_mpll_list),
168};
169
Kisoo Yu57b317f2012-04-24 14:54:15 -0700170static struct clk *clk_src_mpll_fout_list[] = {
171 [0] = &clk_fout_mpll_div2,
172 [1] = &clk_fout_mpll,
173};
174
175struct clksrc_sources clk_src_mpll_fout = {
176 .sources = clk_src_mpll_fout_list,
177 .nr_sources = ARRAY_SIZE(clk_src_mpll_fout_list),
178};
179
Kukjin Kim1a0e8a52010-01-14 08:13:37 +0900180/* Possible clock sources for EPLL Mux */
181static struct clk *clk_src_epll_list[] = {
182 [0] = &clk_fin_epll,
183 [1] = &clk_fout_epll,
184};
185
186struct clksrc_sources clk_src_epll = {
187 .sources = clk_src_epll_list,
188 .nr_sources = ARRAY_SIZE(clk_src_epll_list),
189};
190
Kukjin Kim3109e552010-09-01 15:35:30 +0900191/* Possible clock sources for DPLL Mux */
192static struct clk *clk_src_dpll_list[] = {
193 [0] = &clk_fin_dpll,
194 [1] = &clk_fout_dpll,
195};
196
197struct clksrc_sources clk_src_dpll = {
198 .sources = clk_src_dpll_list,
199 .nr_sources = ARRAY_SIZE(clk_src_dpll_list),
200};
201
Kukjin Kim0c1945d2010-02-24 16:40:36 +0900202struct clk clk_vpll = {
203 .name = "vpll",
204 .id = -1,
205};
206
Kukjin Kim1a0e8a52010-01-14 08:13:37 +0900207int s5p_gatectrl(void __iomem *reg, struct clk *clk, int enable)
208{
209 unsigned int ctrlbit = clk->ctrlbit;
210 u32 con;
211
212 con = __raw_readl(reg);
213 con = enable ? (con | ctrlbit) : (con & ~ctrlbit);
214 __raw_writel(con, reg);
215 return 0;
216}
217
Seungwhan Yound4b34c62010-10-14 10:39:08 +0900218int s5p_epll_enable(struct clk *clk, int enable)
219{
220 unsigned int ctrlbit = clk->ctrlbit;
221 unsigned int epll_con = __raw_readl(S5P_EPLL_CON) & ~ctrlbit;
222
223 if (enable)
224 __raw_writel(epll_con | ctrlbit, S5P_EPLL_CON);
225 else
226 __raw_writel(epll_con, S5P_EPLL_CON);
227
228 return 0;
229}
230
231unsigned long s5p_epll_get_rate(struct clk *clk)
232{
233 return clk->rate;
234}
235
Naveen Krishna Chatradhi65f5eaa2011-07-18 14:44:19 +0900236int s5p_spdif_set_rate(struct clk *clk, unsigned long rate)
237{
238 struct clk *pclk;
239 int ret;
240
241 pclk = clk_get_parent(clk);
242 if (IS_ERR(pclk))
243 return -EINVAL;
244
245 ret = pclk->ops->set_rate(pclk, rate);
246 clk_put(pclk);
247
248 return ret;
249}
250
251unsigned long s5p_spdif_get_rate(struct clk *clk)
252{
253 struct clk *pclk;
254 int rate;
255
256 pclk = clk_get_parent(clk);
257 if (IS_ERR(pclk))
258 return -EINVAL;
259
Naveen Krishna Chatradhi5d747c62011-08-19 20:52:29 +0900260 rate = pclk->ops->get_rate(pclk);
Naveen Krishna Chatradhi65f5eaa2011-07-18 14:44:19 +0900261 clk_put(pclk);
262
263 return rate;
264}
265
266struct clk_ops s5p_sclk_spdif_ops = {
267 .set_rate = s5p_spdif_set_rate,
268 .get_rate = s5p_spdif_get_rate,
269};
270
Kukjin Kim1a0e8a52010-01-14 08:13:37 +0900271static struct clk *s5p_clks[] __initdata = {
272 &clk_ext_xtal_mux,
273 &clk_48m,
Kukjin Kim0c1945d2010-02-24 16:40:36 +0900274 &s5p_clk_27m,
Kukjin Kim1a0e8a52010-01-14 08:13:37 +0900275 &clk_fout_apll,
276 &clk_fout_mpll,
277 &clk_fout_epll,
Kukjin Kim3109e552010-09-01 15:35:30 +0900278 &clk_fout_dpll,
Thomas Abrahamf445dbd2010-05-17 09:38:52 +0900279 &clk_fout_vpll,
Kukjin Kim0c1945d2010-02-24 16:40:36 +0900280 &clk_vpll,
Thomas Abraham8fb9d2d2010-05-28 11:41:16 +0900281 &clk_xusbxti,
Kukjin Kim1a0e8a52010-01-14 08:13:37 +0900282};
283
284void __init s5p_register_clocks(unsigned long xtal_freq)
285{
286 int ret;
287
288 clk_ext_xtal_mux.rate = xtal_freq;
289
290 ret = s3c24xx_register_clocks(s5p_clks, ARRAY_SIZE(s5p_clks));
291 if (ret > 0)
292 printk(KERN_ERR "Failed to register s5p clocks\n");
293}