aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/arm/plat-samsung/Kconfig5
-rw-r--r--arch/arm/plat-samsung/Makefile1
-rw-r--r--arch/arm/plat-samsung/clock-clksrc.c177
-rw-r--r--arch/arm/plat-samsung/include/plat/clock-clksrc.h75
4 files changed, 258 insertions, 0 deletions
diff --git a/arch/arm/plat-samsung/Kconfig b/arch/arm/plat-samsung/Kconfig
index 486a0d6301e7..e3ae68472ea7 100644
--- a/arch/arm/plat-samsung/Kconfig
+++ b/arch/arm/plat-samsung/Kconfig
@@ -13,5 +13,10 @@ config PLAT_SAMSUNG
13 13
14if PLAT_SAMSUNG 14if PLAT_SAMSUNG
15 15
16config SAMSUNG_CLKSRC
17 bool
18 help
19 Select the clock code for the clksrc implementation
20 used by newer systems such as the S3C64XX.
16 21
17endif 22endif
diff --git a/arch/arm/plat-samsung/Makefile b/arch/arm/plat-samsung/Makefile
index 4478b9f7dc34..ce736ce468fd 100644
--- a/arch/arm/plat-samsung/Makefile
+++ b/arch/arm/plat-samsung/Makefile
@@ -9,3 +9,4 @@ obj-m :=
9obj-n := dummy.o 9obj-n := dummy.o
10obj- := 10obj- :=
11 11
12obj-$(CONFIG_SAMSUNG_CLKSRC) += clock-clksrc.o
diff --git a/arch/arm/plat-samsung/clock-clksrc.c b/arch/arm/plat-samsung/clock-clksrc.c
new file mode 100644
index 000000000000..5872f0b62b7c
--- /dev/null
+++ b/arch/arm/plat-samsung/clock-clksrc.c
@@ -0,0 +1,177 @@
1/* linux/arch/arm/plat-samsung/clock-clksrc.c
2 *
3 * Copyright 2008 Simtec Electronics
4 * Ben Dooks <ben@simtec.co.uk>
5 * http://armlinux.simtec.co.uk/
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>
19#include <linux/sysdev.h>
20#include <linux/io.h>
21
22#include <plat/clock.h>
23#include <plat/clock-clksrc.h>
24#include <plat/cpu-freq.h>
25
26static inline struct clksrc_clk *to_clksrc(struct clk *clk)
27{
28 return container_of(clk, struct clksrc_clk, clk);
29}
30
31static inline u32 bit_mask(u32 shift, u32 nr_bits)
32{
33 u32 mask = 0xffffffff >> (32 - nr_bits);
34
35 return mask << shift;
36}
37
38static unsigned long s3c_getrate_clksrc(struct clk *clk)
39{
40 struct clksrc_clk *sclk = to_clksrc(clk);
41 unsigned long rate = clk_get_rate(clk->parent);
42 u32 clkdiv = __raw_readl(sclk->reg_div.reg);
43 u32 mask = bit_mask(sclk->reg_div.shift, sclk->reg_div.size);
44
45 clkdiv &= mask;
46 clkdiv >>= sclk->reg_div.shift;
47 clkdiv++;
48
49 rate /= clkdiv;
50 return rate;
51}
52
53static int s3c_setrate_clksrc(struct clk *clk, unsigned long rate)
54{
55 struct clksrc_clk *sclk = to_clksrc(clk);
56 void __iomem *reg = sclk->reg_div.reg;
57 unsigned int div;
58 u32 mask = bit_mask(sclk->reg_div.shift, sclk->reg_div.size);
59 u32 val;
60
61 rate = clk_round_rate(clk, rate);
62 div = clk_get_rate(clk->parent) / rate;
63 if (div > 16)
64 return -EINVAL;
65
66 val = __raw_readl(reg);
67 val &= ~mask;
68 val |= (div - 1) << sclk->reg_div.shift;
69 __raw_writel(val, reg);
70
71 return 0;
72}
73
74static int s3c_setparent_clksrc(struct clk *clk, struct clk *parent)
75{
76 struct clksrc_clk *sclk = to_clksrc(clk);
77 struct clksrc_sources *srcs = sclk->sources;
78 u32 clksrc = __raw_readl(sclk->reg_src.reg);
79 u32 mask = bit_mask(sclk->reg_src.shift, sclk->reg_src.size);
80 int src_nr = -1;
81 int ptr;
82
83 for (ptr = 0; ptr < srcs->nr_sources; ptr++)
84 if (srcs->sources[ptr] == parent) {
85 src_nr = ptr;
86 break;
87 }
88
89 if (src_nr >= 0 && sclk->reg_src.reg) {
90 clk->parent = parent;
91
92 clksrc &= ~mask;
93 clksrc |= src_nr << sclk->reg_src.shift;
94
95 __raw_writel(clksrc, sclk->reg_src.reg);
96 return 0;
97 }
98
99 return -EINVAL;
100}
101
102static unsigned long s3c_roundrate_clksrc(struct clk *clk,
103 unsigned long rate)
104{
105 unsigned long parent_rate = clk_get_rate(clk->parent);
106 int div;
107
108 if (rate >= parent_rate)
109 rate = parent_rate;
110 else {
111 div = parent_rate / rate;
112 if (parent_rate % rate)
113 div++;
114
115 if (div == 0)
116 div = 1;
117 if (div > 16)
118 div = 16;
119
120 rate = parent_rate / div;
121 }
122
123 return rate;
124}
125
126/* Clock initialisation code */
127
128void __init_or_cpufreq s3c_set_clksrc(struct clksrc_clk *clk)
129{
130 struct clksrc_sources *srcs = clk->sources;
131 u32 mask = bit_mask(clk->reg_src.shift, clk->reg_src.size);
132 u32 clksrc = 0;
133
134 if (clk->reg_src.reg)
135 clksrc = __raw_readl(clk->reg_src.reg);
136
137 clksrc &= mask;
138 clksrc >>= clk->reg_src.shift;
139
140 if (clksrc > srcs->nr_sources || !srcs->sources[clksrc]) {
141 printk(KERN_ERR "%s: bad source %d\n",
142 clk->clk.name, clksrc);
143 return;
144 }
145
146 clk->clk.parent = srcs->sources[clksrc];
147
148 printk(KERN_INFO "%s: source is %s (%d), rate is %ld\n",
149 clk->clk.name, clk->clk.parent->name, clksrc,
150 clk_get_rate(&clk->clk));
151}
152
153void __init s3c_register_clksrc(struct clksrc_clk *clksrc, int size)
154{
155 int ret;
156
157 for (; size > 0; size--, clksrc++) {
158 /* fill in the default functions */
159 if (!clksrc->clk.set_parent)
160 clksrc->clk.set_parent = s3c_setparent_clksrc;
161 if (!clksrc->clk.get_rate)
162 clksrc->clk.get_rate = s3c_getrate_clksrc;
163 if (!clksrc->clk.set_rate)
164 clksrc->clk.set_rate = s3c_setrate_clksrc;
165 if (!clksrc->clk.round_rate)
166 clksrc->clk.round_rate = s3c_roundrate_clksrc;
167
168 s3c_set_clksrc(clksrc);
169
170 ret = s3c24xx_register_clock(&clksrc->clk);
171
172 if (ret < 0) {
173 printk(KERN_ERR "%s: failed to register %s (%d)\n",
174 __func__, clksrc->clk.name, ret);
175 }
176 }
177}
diff --git a/arch/arm/plat-samsung/include/plat/clock-clksrc.h b/arch/arm/plat-samsung/include/plat/clock-clksrc.h
new file mode 100644
index 000000000000..283dfa028757
--- /dev/null
+++ b/arch/arm/plat-samsung/include/plat/clock-clksrc.h
@@ -0,0 +1,75 @@
1/* linux/arch/arm/plat-samsung/include/plat/clock-clksrc.h
2 *
3 * Parts taken from arch/arm/plat-s3c64xx/clock.c
4 * Copyright 2008 Openmoko, Inc.
5 * Copyright 2008 Simtec Electronics
6 * Ben Dooks <ben@simtec.co.uk>
7 * http://armlinux.simtec.co.uk/
8 *
9 * Copyright 2009 Ben Dooks <ben-linux@fluff.org>
10 * Copyright 2009 Harald Welte
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15*/
16
17/**
18 * struct clksrc_sources - list of sources for a given clock
19 * @sources: array of pointers to clocks
20 * @nr_sources: The size of @sources
21 */
22struct clksrc_sources {
23 unsigned int nr_sources;
24 struct clk **sources;
25};
26
27/**
28 * struct clksrc_reg - register definition for clock control bits
29 * @reg: pointer to the register in virtual memory.
30 * @shift: the shift in bits to where the bitfield is.
31 * @size: the size in bits of the bitfield.
32 *
33 * This specifies the size and position of the bits we are interested
34 * in within the register specified by @reg.
35 */
36struct clksrc_reg {
37 void __iomem *reg;
38 unsigned short shift;
39 unsigned short size;
40};
41
42/**
43 * struct clksrc_clk - class of clock for newer style samsung devices.
44 * @clk: the standard clock representation
45 * @sources: the sources for this clock
46 * @reg_src: the register definition for selecting the clock's source
47 * @reg_div: the register definition for the clock's output divisor
48 *
49 * This clock implements the features required by the newer SoCs where
50 * the standard clock block provides an input mux and a post-mux divisor
51 * to provide the periperhal's clock.
52 *
53 * The array of @sources provides the mapping of mux position to the
54 * clock, and @reg_src shows the code where to modify to change the mux
55 * position. The @reg_div defines how to change the divider settings on
56 * the output.
57 */
58struct clksrc_clk {
59 struct clk clk;
60 struct clksrc_sources *sources;
61
62 struct clksrc_reg reg_src;
63 struct clksrc_reg reg_div;
64};
65
66extern void s3c_set_clksrc(struct clksrc_clk *clk);
67
68/**
69 * s3c_register_clksrc() register clocks from an array of clksrc clocks
70 * @srcs: The array of clocks to register
71 * @size: The size of the @srcs array.
72 *
73 * Initialise and register the array of clocks described by @srcs.
74 */
75extern void s3c_register_clksrc(struct clksrc_clk *srcs, int size);