adds 3.3 patches and files
[openwrt/openwrt.git] / target / linux / lantiq / patches-3.3 / 0021-MIPS-lantiq-convert-to-clkdev-api.patch
1 From 69f1bf02b0c6b132140326320d26aa4e91bc3290 Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Thu, 8 Mar 2012 08:39:06 +0100
4 Subject: [PATCH 21/70] MIPS: lantiq: convert to clkdev api
5
6 * Change setup from HAVE_CLK -> HAVE_MACH_CLKDEV/CLKDEV_LOOKUP
7 * Add clk_activate/clk_deactivate
8 * Add better error paths to the clk_*() functions
9 * Change the way our static clocks are referenced
10
11 Signed-off-by: John Crispin <blogic@openwrt.org>
12 ---
13 arch/mips/Kconfig | 3 +-
14 arch/mips/include/asm/mach-lantiq/lantiq.h | 20 ++----
15 arch/mips/lantiq/clk.c | 96 +++++++++++++++------------
16 arch/mips/lantiq/clk.h | 52 ++++++++++++++-
17 arch/mips/lantiq/prom.c | 1 -
18 5 files changed, 111 insertions(+), 61 deletions(-)
19
20 diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
21 index 8ad52f4..df4e125 100644
22 --- a/arch/mips/Kconfig
23 +++ b/arch/mips/Kconfig
24 @@ -228,7 +228,8 @@ config LANTIQ
25 select ARCH_REQUIRE_GPIOLIB
26 select SWAP_IO_SPACE
27 select BOOT_RAW
28 - select HAVE_CLK
29 + select HAVE_MACH_CLKDEV
30 + select CLKDEV_LOOKUP
31 select HAVE_OPROFILE
32 select MIPS_MACHINE
33
34 diff --git a/arch/mips/include/asm/mach-lantiq/lantiq.h b/arch/mips/include/asm/mach-lantiq/lantiq.h
35 index 924b91a..622847f 100644
36 --- a/arch/mips/include/asm/mach-lantiq/lantiq.h
37 +++ b/arch/mips/include/asm/mach-lantiq/lantiq.h
38 @@ -9,6 +9,7 @@
39 #define _LANTIQ_H__
40
41 #include <linux/irq.h>
42 +#include <linux/clk.h>
43 #include <linux/ioport.h>
44
45 /* generic reg access functions */
46 @@ -22,18 +23,6 @@
47 extern unsigned int ltq_get_cpu_ver(void);
48 extern unsigned int ltq_get_soc_type(void);
49
50 -/* clock speeds */
51 -#define CLOCK_60M 60000000
52 -#define CLOCK_83M 83333333
53 -#define CLOCK_100M 100000000
54 -#define CLOCK_111M 111111111
55 -#define CLOCK_133M 133333333
56 -#define CLOCK_167M 166666667
57 -#define CLOCK_200M 200000000
58 -#define CLOCK_266M 266666666
59 -#define CLOCK_333M 333333333
60 -#define CLOCK_400M 400000000
61 -
62 /* spinlock all ebu i/o */
63 extern spinlock_t ebu_lock;
64
65 @@ -46,6 +35,13 @@ extern void ltq_disable_irq(struct irq_data *data);
66 extern void ltq_mask_and_ack_irq(struct irq_data *data);
67 extern void ltq_enable_irq(struct irq_data *data);
68
69 +/* clock handling */
70 +extern int clk_activate(struct clk *clk);
71 +extern void clk_deactivate(struct clk *clk);
72 +extern struct clk *clk_get_cpu(void);
73 +extern struct clk *clk_get_fpi(void);
74 +extern struct clk *clk_get_io(void);
75 +
76 /* find out what caused the last cpu reset */
77 extern int ltq_reset_cause(void);
78
79 diff --git a/arch/mips/lantiq/clk.c b/arch/mips/lantiq/clk.c
80 index 39eef7f..84a201e 100644
81 --- a/arch/mips/lantiq/clk.c
82 +++ b/arch/mips/lantiq/clk.c
83 @@ -12,6 +12,7 @@
84 #include <linux/kernel.h>
85 #include <linux/types.h>
86 #include <linux/clk.h>
87 +#include <linux/clkdev.h>
88 #include <linux/err.h>
89 #include <linux/list.h>
90
91 @@ -24,33 +25,29 @@
92 #include "clk.h"
93 #include "prom.h"
94
95 -struct clk {
96 - const char *name;
97 - unsigned long rate;
98 - unsigned long (*get_rate) (void);
99 -};
100 +/* lantiq socs have 3 static clocks */
101 +static struct clk cpu_clk_generic[3];
102
103 -static struct clk *cpu_clk;
104 -static int cpu_clk_cnt;
105 +void clkdev_add_static(unsigned long cpu, unsigned long fpi, unsigned long io)
106 +{
107 + cpu_clk_generic[0].rate = cpu;
108 + cpu_clk_generic[1].rate = fpi;
109 + cpu_clk_generic[2].rate = io;
110 +}
111
112 -/* lantiq socs have 3 static clocks */
113 -static struct clk cpu_clk_generic[] = {
114 - {
115 - .name = "cpu",
116 - .get_rate = ltq_get_cpu_hz,
117 - }, {
118 - .name = "fpi",
119 - .get_rate = ltq_get_fpi_hz,
120 - }, {
121 - .name = "io",
122 - .get_rate = ltq_get_io_region_clock,
123 - },
124 -};
125 -
126 -void clk_init(void)
127 +struct clk *clk_get_cpu(void)
128 +{
129 + return &cpu_clk_generic[0];
130 +}
131 +
132 +struct clk *clk_get_fpi(void)
133 {
134 - cpu_clk = cpu_clk_generic;
135 - cpu_clk_cnt = ARRAY_SIZE(cpu_clk_generic);
136 + return &cpu_clk_generic[1];
137 +}
138 +
139 +struct clk *clk_get_io(void)
140 +{
141 + return &cpu_clk_generic[2];
142 }
143
144 static inline int clk_good(struct clk *clk)
145 @@ -73,36 +70,49 @@ unsigned long clk_get_rate(struct clk *clk)
146 }
147 EXPORT_SYMBOL(clk_get_rate);
148
149 -struct clk *clk_get(struct device *dev, const char *id)
150 +int clk_enable(struct clk *clk)
151 {
152 - int i;
153 + if (unlikely(!clk_good(clk)))
154 + return -1;
155 +
156 + if (clk->enable)
157 + return clk->enable(clk);
158
159 - for (i = 0; i < cpu_clk_cnt; i++)
160 - if (!strcmp(id, cpu_clk[i].name))
161 - return &cpu_clk[i];
162 - BUG();
163 - return ERR_PTR(-ENOENT);
164 + return -1;
165 }
166 -EXPORT_SYMBOL(clk_get);
167 +EXPORT_SYMBOL(clk_enable);
168
169 -void clk_put(struct clk *clk)
170 +void clk_disable(struct clk *clk)
171 {
172 - /* not used */
173 + if (unlikely(!clk_good(clk)))
174 + return;
175 +
176 + if (clk->disable)
177 + clk->disable(clk);
178 }
179 -EXPORT_SYMBOL(clk_put);
180 +EXPORT_SYMBOL(clk_disable);
181
182 -int clk_enable(struct clk *clk)
183 +int clk_activate(struct clk *clk)
184 {
185 - /* not used */
186 - return 0;
187 + if (unlikely(!clk_good(clk)))
188 + return -1;
189 +
190 + if (clk->activate)
191 + return clk->activate(clk);
192 +
193 + return -1;
194 }
195 -EXPORT_SYMBOL(clk_enable);
196 +EXPORT_SYMBOL(clk_activate);
197
198 -void clk_disable(struct clk *clk)
199 +void clk_deactivate(struct clk *clk)
200 {
201 - /* not used */
202 + if (unlikely(!clk_good(clk)))
203 + return;
204 +
205 + if (clk->deactivate)
206 + clk->deactivate(clk);
207 }
208 -EXPORT_SYMBOL(clk_disable);
209 +EXPORT_SYMBOL(clk_deactivate);
210
211 static inline u32 ltq_get_counter_resolution(void)
212 {
213 @@ -126,7 +136,7 @@ void __init plat_time_init(void)
214
215 ltq_soc_init();
216
217 - clk = clk_get(0, "cpu");
218 + clk = clk_get_cpu();
219 mips_hpt_frequency = clk_get_rate(clk) / ltq_get_counter_resolution();
220 write_c0_compare(read_c0_count());
221 pr_info("CPU Clock: %ldMHz\n", clk_get_rate(clk) / 1000000);
222 diff --git a/arch/mips/lantiq/clk.h b/arch/mips/lantiq/clk.h
223 index 3328925..d047768 100644
224 --- a/arch/mips/lantiq/clk.h
225 +++ b/arch/mips/lantiq/clk.h
226 @@ -9,10 +9,54 @@
227 #ifndef _LTQ_CLK_H__
228 #define _LTQ_CLK_H__
229
230 -extern void clk_init(void);
231 +#include <linux/clkdev.h>
232
233 -extern unsigned long ltq_get_cpu_hz(void);
234 -extern unsigned long ltq_get_fpi_hz(void);
235 -extern unsigned long ltq_get_io_region_clock(void);
236 +/* clock speeds */
237 +#define CLOCK_60M 60000000
238 +#define CLOCK_62_5M 62500000
239 +#define CLOCK_83M 83333333
240 +#define CLOCK_83_5M 83500000
241 +#define CLOCK_98_304M 98304000
242 +#define CLOCK_100M 100000000
243 +#define CLOCK_111M 111111111
244 +#define CLOCK_125M 125000000
245 +#define CLOCK_133M 133333333
246 +#define CLOCK_150M 150000000
247 +#define CLOCK_166M 166666666
248 +#define CLOCK_167M 166666667
249 +#define CLOCK_196_608M 196608000
250 +#define CLOCK_200M 200000000
251 +#define CLOCK_250M 250000000
252 +#define CLOCK_266M 266666666
253 +#define CLOCK_300M 300000000
254 +#define CLOCK_333M 333333333
255 +#define CLOCK_393M 393215332
256 +#define CLOCK_400M 400000000
257 +#define CLOCK_500M 500000000
258 +#define CLOCK_600M 600000000
259 +
260 +struct clk {
261 + struct clk_lookup cl;
262 + unsigned long rate;
263 + unsigned long (*get_rate) (void);
264 + unsigned int module;
265 + unsigned int bits;
266 + int (*enable) (struct clk *clk);
267 + void (*disable) (struct clk *clk);
268 + int (*activate) (struct clk *clk);
269 + void (*deactivate) (struct clk *clk);
270 + void (*reboot) (struct clk *clk);
271 +};
272 +
273 +extern void clkdev_add_static(unsigned long cpu, unsigned long fpi,
274 + unsigned long io);
275 +
276 +extern unsigned long ltq_danube_cpu_hz(void);
277 +extern unsigned long ltq_danube_fpi_hz(void);
278 +extern unsigned long ltq_danube_io_region_clock(void);
279 +
280 +extern unsigned long ltq_vr9_cpu_hz(void);
281 +extern unsigned long ltq_vr9_fpi_hz(void);
282 +extern unsigned long ltq_vr9_io_region_clock(void);
283
284 #endif
285 diff --git a/arch/mips/lantiq/prom.c b/arch/mips/lantiq/prom.c
286 index acb8921..971554b 100644
287 --- a/arch/mips/lantiq/prom.c
288 +++ b/arch/mips/lantiq/prom.c
289 @@ -103,7 +103,6 @@ EXPORT_SYMBOL(ltq_remap_resource);
290 void __init prom_init(void)
291 {
292 ltq_soc_detect(&soc_info);
293 - clk_init();
294 snprintf(soc_info.sys_type, LTQ_SYS_TYPE_LEN - 1, "%s rev %s",
295 soc_info.name, soc_info.rev_type);
296 soc_info.sys_type[LTQ_SYS_TYPE_LEN - 1] = '\0';
297 --
298 1.7.9.1
299