blob: 41d3dfd5dddbe0ab0cfb8818fb15d7edc3b6c9ea [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
70/* CPLL clock output */
71
72struct clk clk_fout_cpll = {
73 .name = "fout_cpll",
74 .id = -1,
75};
76
Kukjin Kim1a0e8a52010-01-14 08:13:37 +090077/* MPLL clock output
78 * No need .ctrlbit, this is always on
79*/
80struct clk clk_fout_mpll = {
81 .name = "fout_mpll",
82 .id = -1,
83};
84
85/* EPLL clock output */
86struct clk clk_fout_epll = {
87 .name = "fout_epll",
88 .id = -1,
89 .ctrlbit = (1 << 31),
90};
91
Kukjin Kim3109e552010-09-01 15:35:30 +090092/* DPLL clock output */
93struct clk clk_fout_dpll = {
94 .name = "fout_dpll",
95 .id = -1,
96 .ctrlbit = (1 << 31),
97};
98
Thomas Abrahamf445dbd2010-05-17 09:38:52 +090099/* VPLL clock output */
100struct clk clk_fout_vpll = {
101 .name = "fout_vpll",
102 .id = -1,
103 .ctrlbit = (1 << 31),
104};
105
Kukjin Kim1a0e8a52010-01-14 08:13:37 +0900106/* Possible clock sources for APLL Mux */
107static struct clk *clk_src_apll_list[] = {
108 [0] = &clk_fin_apll,
109 [1] = &clk_fout_apll,
110};
111
112struct clksrc_sources clk_src_apll = {
113 .sources = clk_src_apll_list,
114 .nr_sources = ARRAY_SIZE(clk_src_apll_list),
115};
116
Kukjin Kim87b3c6e2012-01-22 21:46:13 +0900117/* Possible clock sources for BPLL Mux */
118static struct clk *clk_src_bpll_list[] = {
119 [0] = &clk_fin_bpll,
120 [1] = &clk_fout_bpll,
121};
122
123struct clksrc_sources clk_src_bpll = {
124 .sources = clk_src_bpll_list,
125 .nr_sources = ARRAY_SIZE(clk_src_bpll_list),
126};
127
128/* Possible clock sources for CPLL Mux */
129static struct clk *clk_src_cpll_list[] = {
130 [0] = &clk_fin_cpll,
131 [1] = &clk_fout_cpll,
132};
133
134struct clksrc_sources clk_src_cpll = {
135 .sources = clk_src_cpll_list,
136 .nr_sources = ARRAY_SIZE(clk_src_cpll_list),
137};
138
Kukjin Kim1a0e8a52010-01-14 08:13:37 +0900139/* Possible clock sources for MPLL Mux */
140static struct clk *clk_src_mpll_list[] = {
141 [0] = &clk_fin_mpll,
142 [1] = &clk_fout_mpll,
143};
144
145struct clksrc_sources clk_src_mpll = {
146 .sources = clk_src_mpll_list,
147 .nr_sources = ARRAY_SIZE(clk_src_mpll_list),
148};
149
150/* Possible clock sources for EPLL Mux */
151static struct clk *clk_src_epll_list[] = {
152 [0] = &clk_fin_epll,
153 [1] = &clk_fout_epll,
154};
155
156struct clksrc_sources clk_src_epll = {
157 .sources = clk_src_epll_list,
158 .nr_sources = ARRAY_SIZE(clk_src_epll_list),
159};
160
Kukjin Kim3109e552010-09-01 15:35:30 +0900161/* Possible clock sources for DPLL Mux */
162static struct clk *clk_src_dpll_list[] = {
163 [0] = &clk_fin_dpll,
164 [1] = &clk_fout_dpll,
165};
166
167struct clksrc_sources clk_src_dpll = {
168 .sources = clk_src_dpll_list,
169 .nr_sources = ARRAY_SIZE(clk_src_dpll_list),
170};
171
Kukjin Kim0c1945d2010-02-24 16:40:36 +0900172struct clk clk_vpll = {
173 .name = "vpll",
174 .id = -1,
175};
176
Kukjin Kim1a0e8a52010-01-14 08:13:37 +0900177int s5p_gatectrl(void __iomem *reg, struct clk *clk, int enable)
178{
179 unsigned int ctrlbit = clk->ctrlbit;
180 u32 con;
181
182 con = __raw_readl(reg);
183 con = enable ? (con | ctrlbit) : (con & ~ctrlbit);
184 __raw_writel(con, reg);
185 return 0;
186}
187
Seungwhan Yound4b34c62010-10-14 10:39:08 +0900188int s5p_epll_enable(struct clk *clk, int enable)
189{
190 unsigned int ctrlbit = clk->ctrlbit;
191 unsigned int epll_con = __raw_readl(S5P_EPLL_CON) & ~ctrlbit;
192
193 if (enable)
194 __raw_writel(epll_con | ctrlbit, S5P_EPLL_CON);
195 else
196 __raw_writel(epll_con, S5P_EPLL_CON);
197
198 return 0;
199}
200
201unsigned long s5p_epll_get_rate(struct clk *clk)
202{
203 return clk->rate;
204}
205
Naveen Krishna Chatradhi65f5eaa2011-07-18 14:44:19 +0900206int s5p_spdif_set_rate(struct clk *clk, unsigned long rate)
207{
208 struct clk *pclk;
209 int ret;
210
211 pclk = clk_get_parent(clk);
212 if (IS_ERR(pclk))
213 return -EINVAL;
214
215 ret = pclk->ops->set_rate(pclk, rate);
216 clk_put(pclk);
217
218 return ret;
219}
220
221unsigned long s5p_spdif_get_rate(struct clk *clk)
222{
223 struct clk *pclk;
224 int rate;
225
226 pclk = clk_get_parent(clk);
227 if (IS_ERR(pclk))
228 return -EINVAL;
229
Naveen Krishna Chatradhi5d747c62011-08-19 20:52:29 +0900230 rate = pclk->ops->get_rate(pclk);
Naveen Krishna Chatradhi65f5eaa2011-07-18 14:44:19 +0900231 clk_put(pclk);
232
233 return rate;
234}
235
236struct clk_ops s5p_sclk_spdif_ops = {
237 .set_rate = s5p_spdif_set_rate,
238 .get_rate = s5p_spdif_get_rate,
239};
240
Kukjin Kim1a0e8a52010-01-14 08:13:37 +0900241static struct clk *s5p_clks[] __initdata = {
242 &clk_ext_xtal_mux,
243 &clk_48m,
Kukjin Kim0c1945d2010-02-24 16:40:36 +0900244 &s5p_clk_27m,
Kukjin Kim1a0e8a52010-01-14 08:13:37 +0900245 &clk_fout_apll,
246 &clk_fout_mpll,
247 &clk_fout_epll,
Kukjin Kim3109e552010-09-01 15:35:30 +0900248 &clk_fout_dpll,
Thomas Abrahamf445dbd2010-05-17 09:38:52 +0900249 &clk_fout_vpll,
Kukjin Kim0c1945d2010-02-24 16:40:36 +0900250 &clk_vpll,
Thomas Abraham8fb9d2d2010-05-28 11:41:16 +0900251 &clk_xusbxti,
Kukjin Kim1a0e8a52010-01-14 08:13:37 +0900252};
253
254void __init s5p_register_clocks(unsigned long xtal_freq)
255{
256 int ret;
257
258 clk_ext_xtal_mux.rate = xtal_freq;
259
260 ret = s3c24xx_register_clocks(s5p_clks, ARRAY_SIZE(s5p_clks));
261 if (ret > 0)
262 printk(KERN_ERR "Failed to register s5p clocks\n");
263}