2 * Copyright 2009 Samsung Electronics Co., Ltd.
3 * http://www.samsung.com/
5 * S5P - Common clock support
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.
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>
19 #include <linux/device.h>
21 #include <asm/div64.h>
23 #include <mach/regs-clock.h>
25 #include <plat/clock.h>
26 #include <plat/clock-clksrc.h>
27 #include <plat/s5p-clock.h>
29 /* fin_apll, fin_mpll and fin_epll are all the same clock, which we call
32 struct clk clk_ext_xtal_mux = {
37 struct clk clk_xusbxti = {
42 struct clk s5p_clk_27m = {
48 /* 48MHz USB Phy clock output */
49 struct clk clk_48m = {
56 * No need .ctrlbit, this is always on
58 struct clk clk_fout_apll = {
63 /* BPLL clock output */
65 struct clk clk_fout_bpll = {
70 /* CPLL clock output */
72 struct clk clk_fout_cpll = {
78 * No need .ctrlbit, this is always on
80 struct clk clk_fout_mpll = {
85 /* EPLL clock output */
86 struct clk clk_fout_epll = {
92 /* DPLL clock output */
93 struct clk clk_fout_dpll = {
99 /* VPLL clock output */
100 struct clk clk_fout_vpll = {
103 .ctrlbit = (1 << 31),
106 /* Possible clock sources for APLL Mux */
107 static struct clk *clk_src_apll_list[] = {
109 [1] = &clk_fout_apll,
112 struct clksrc_sources clk_src_apll = {
113 .sources = clk_src_apll_list,
114 .nr_sources = ARRAY_SIZE(clk_src_apll_list),
117 /* Possible clock sources for BPLL Mux */
118 static struct clk *clk_src_bpll_list[] = {
120 [1] = &clk_fout_bpll,
123 struct clksrc_sources clk_src_bpll = {
124 .sources = clk_src_bpll_list,
125 .nr_sources = ARRAY_SIZE(clk_src_bpll_list),
128 /* Possible clock sources for CPLL Mux */
129 static struct clk *clk_src_cpll_list[] = {
131 [1] = &clk_fout_cpll,
134 struct clksrc_sources clk_src_cpll = {
135 .sources = clk_src_cpll_list,
136 .nr_sources = ARRAY_SIZE(clk_src_cpll_list),
139 /* Possible clock sources for MPLL Mux */
140 static struct clk *clk_src_mpll_list[] = {
142 [1] = &clk_fout_mpll,
145 struct clksrc_sources clk_src_mpll = {
146 .sources = clk_src_mpll_list,
147 .nr_sources = ARRAY_SIZE(clk_src_mpll_list),
150 /* Possible clock sources for EPLL Mux */
151 static struct clk *clk_src_epll_list[] = {
153 [1] = &clk_fout_epll,
156 struct clksrc_sources clk_src_epll = {
157 .sources = clk_src_epll_list,
158 .nr_sources = ARRAY_SIZE(clk_src_epll_list),
161 /* Possible clock sources for DPLL Mux */
162 static struct clk *clk_src_dpll_list[] = {
164 [1] = &clk_fout_dpll,
167 struct clksrc_sources clk_src_dpll = {
168 .sources = clk_src_dpll_list,
169 .nr_sources = ARRAY_SIZE(clk_src_dpll_list),
172 struct clk clk_vpll = {
177 int s5p_gatectrl(void __iomem *reg, struct clk *clk, int enable)
179 unsigned int ctrlbit = clk->ctrlbit;
182 con = __raw_readl(reg);
183 con = enable ? (con | ctrlbit) : (con & ~ctrlbit);
184 __raw_writel(con, reg);
188 int s5p_epll_enable(struct clk *clk, int enable)
190 unsigned int ctrlbit = clk->ctrlbit;
191 unsigned int epll_con = __raw_readl(S5P_EPLL_CON) & ~ctrlbit;
194 __raw_writel(epll_con | ctrlbit, S5P_EPLL_CON);
196 __raw_writel(epll_con, S5P_EPLL_CON);
201 unsigned long s5p_epll_get_rate(struct clk *clk)
206 int s5p_spdif_set_rate(struct clk *clk, unsigned long rate)
211 pclk = clk_get_parent(clk);
215 ret = pclk->ops->set_rate(pclk, rate);
221 unsigned long s5p_spdif_get_rate(struct clk *clk)
226 pclk = clk_get_parent(clk);
230 rate = pclk->ops->get_rate(pclk);
236 struct clk_ops s5p_sclk_spdif_ops = {
237 .set_rate = s5p_spdif_set_rate,
238 .get_rate = s5p_spdif_get_rate,
241 static struct clk *s5p_clks[] __initdata = {
254 void __init s5p_register_clocks(unsigned long xtal_freq)
258 clk_ext_xtal_mux.rate = xtal_freq;
260 ret = s3c24xx_register_clocks(s5p_clks, ARRAY_SIZE(s5p_clks));
262 printk(KERN_ERR "Failed to register s5p clocks\n");