blob: 4ca0759fa22877ea48cc3c7522bbfd11f7df3a6d [file] [log] [blame]
Kukjin Kim1a0e8a52010-01-14 08:13:37 +09001/* linux/arch/arm/plat-s5p/clock.c
2 *
3 * Copyright 2009 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com/
5 *
6 * S5P - Common clock support
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11*/
12
13#include <linux/init.h>
14#include <linux/module.h>
15#include <linux/kernel.h>
16#include <linux/list.h>
17#include <linux/errno.h>
18#include <linux/err.h>
19#include <linux/clk.h>
20#include <linux/sysdev.h>
21#include <linux/io.h>
22#include <asm/div64.h>
23
24#include <plat/clock.h>
25#include <plat/clock-clksrc.h>
26#include <plat/s5p-clock.h>
27
28/* fin_apll, fin_mpll and fin_epll are all the same clock, which we call
29 * clk_ext_xtal_mux.
30*/
31struct clk clk_ext_xtal_mux = {
32 .name = "ext_xtal",
33 .id = -1,
34};
35
Kukjin Kim0c1945d2010-02-24 16:40:36 +090036static struct clk s5p_clk_27m = {
37 .name = "clk_27m",
38 .id = -1,
39 .rate = 27000000,
40};
41
Kukjin Kim1a0e8a52010-01-14 08:13:37 +090042/* 48MHz USB Phy clock output */
43struct clk clk_48m = {
44 .name = "clk_48m",
45 .id = -1,
46 .rate = 48000000,
47};
48
49/* APLL clock output
50 * No need .ctrlbit, this is always on
51*/
52struct clk clk_fout_apll = {
53 .name = "fout_apll",
54 .id = -1,
55};
56
57/* MPLL clock output
58 * No need .ctrlbit, this is always on
59*/
60struct clk clk_fout_mpll = {
61 .name = "fout_mpll",
62 .id = -1,
63};
64
65/* EPLL clock output */
66struct clk clk_fout_epll = {
67 .name = "fout_epll",
68 .id = -1,
69 .ctrlbit = (1 << 31),
70};
71
Thomas Abrahamf445dbd2010-05-17 09:38:52 +090072/* VPLL clock output */
73struct clk clk_fout_vpll = {
74 .name = "fout_vpll",
75 .id = -1,
76 .ctrlbit = (1 << 31),
77};
78
Kukjin Kim1a0e8a52010-01-14 08:13:37 +090079/* ARM clock */
80struct clk clk_arm = {
81 .name = "armclk",
82 .id = -1,
83 .rate = 0,
84 .ctrlbit = 0,
85};
86
87/* Possible clock sources for APLL Mux */
88static struct clk *clk_src_apll_list[] = {
89 [0] = &clk_fin_apll,
90 [1] = &clk_fout_apll,
91};
92
93struct clksrc_sources clk_src_apll = {
94 .sources = clk_src_apll_list,
95 .nr_sources = ARRAY_SIZE(clk_src_apll_list),
96};
97
98/* Possible clock sources for MPLL Mux */
99static struct clk *clk_src_mpll_list[] = {
100 [0] = &clk_fin_mpll,
101 [1] = &clk_fout_mpll,
102};
103
104struct clksrc_sources clk_src_mpll = {
105 .sources = clk_src_mpll_list,
106 .nr_sources = ARRAY_SIZE(clk_src_mpll_list),
107};
108
109/* Possible clock sources for EPLL Mux */
110static struct clk *clk_src_epll_list[] = {
111 [0] = &clk_fin_epll,
112 [1] = &clk_fout_epll,
113};
114
115struct clksrc_sources clk_src_epll = {
116 .sources = clk_src_epll_list,
117 .nr_sources = ARRAY_SIZE(clk_src_epll_list),
118};
119
Kukjin Kim0c1945d2010-02-24 16:40:36 +0900120struct clk clk_vpll = {
121 .name = "vpll",
122 .id = -1,
123};
124
Kukjin Kim1a0e8a52010-01-14 08:13:37 +0900125int s5p_gatectrl(void __iomem *reg, struct clk *clk, int enable)
126{
127 unsigned int ctrlbit = clk->ctrlbit;
128 u32 con;
129
130 con = __raw_readl(reg);
131 con = enable ? (con | ctrlbit) : (con & ~ctrlbit);
132 __raw_writel(con, reg);
133 return 0;
134}
135
136static struct clk *s5p_clks[] __initdata = {
137 &clk_ext_xtal_mux,
138 &clk_48m,
Kukjin Kim0c1945d2010-02-24 16:40:36 +0900139 &s5p_clk_27m,
Kukjin Kim1a0e8a52010-01-14 08:13:37 +0900140 &clk_fout_apll,
141 &clk_fout_mpll,
142 &clk_fout_epll,
Thomas Abrahamf445dbd2010-05-17 09:38:52 +0900143 &clk_fout_vpll,
Kukjin Kim1a0e8a52010-01-14 08:13:37 +0900144 &clk_arm,
Kukjin Kim0c1945d2010-02-24 16:40:36 +0900145 &clk_vpll,
Kukjin Kim1a0e8a52010-01-14 08:13:37 +0900146};
147
148void __init s5p_register_clocks(unsigned long xtal_freq)
149{
150 int ret;
151
152 clk_ext_xtal_mux.rate = xtal_freq;
153
154 ret = s3c24xx_register_clocks(s5p_clks, ARRAY_SIZE(s5p_clks));
155 if (ret > 0)
156 printk(KERN_ERR "Failed to register s5p clocks\n");
157}