1 From 25db3804c7c9ed3ee5161b00b38de84b1d19f6a8 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 25/70] MIPS: lantiq: convert to clkdev api
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
11 Signed-off-by: John Crispin <blogic@openwrt.org>
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(-)
20 diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
21 index c1ceadb..1b78cd7 100644
22 --- a/arch/mips/Kconfig
23 +++ b/arch/mips/Kconfig
24 @@ -225,7 +225,8 @@ config LANTIQ
25 select ARCH_REQUIRE_GPIOLIB
29 + select HAVE_MACH_CLKDEV
30 + select CLKDEV_LOOKUP
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
41 #include <linux/irq.h>
42 +#include <linux/clk.h>
43 #include <linux/ioport.h>
45 /* generic reg access functions */
47 extern unsigned int ltq_get_cpu_ver(void);
48 extern unsigned int ltq_get_soc_type(void);
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
62 /* spinlock all ebu i/o */
63 extern spinlock_t ebu_lock;
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);
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);
76 /* find out what caused the last cpu reset */
77 extern int ltq_reset_cause(void);
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
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>
98 - unsigned long (*get_rate) (void);
100 +/* lantiq socs have 3 static clocks */
101 +static struct clk cpu_clk_generic[3];
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)
107 + cpu_clk_generic[0].rate = cpu;
108 + cpu_clk_generic[1].rate = fpi;
109 + cpu_clk_generic[2].rate = io;
112 -/* lantiq socs have 3 static clocks */
113 -static struct clk cpu_clk_generic[] = {
116 - .get_rate = ltq_get_cpu_hz,
119 - .get_rate = ltq_get_fpi_hz,
122 - .get_rate = ltq_get_io_region_clock,
127 +struct clk *clk_get_cpu(void)
129 + return &cpu_clk_generic[0];
132 +struct clk *clk_get_fpi(void)
134 - cpu_clk = cpu_clk_generic;
135 - cpu_clk_cnt = ARRAY_SIZE(cpu_clk_generic);
136 + return &cpu_clk_generic[1];
139 +struct clk *clk_get_io(void)
141 + return &cpu_clk_generic[2];
144 static inline int clk_good(struct clk *clk)
145 @@ -73,36 +70,49 @@ unsigned long clk_get_rate(struct clk *clk)
147 EXPORT_SYMBOL(clk_get_rate);
149 -struct clk *clk_get(struct device *dev, const char *id)
150 +int clk_enable(struct clk *clk)
153 + if (unlikely(!clk_good(clk)))
157 + return clk->enable(clk);
159 - for (i = 0; i < cpu_clk_cnt; i++)
160 - if (!strcmp(id, cpu_clk[i].name))
161 - return &cpu_clk[i];
163 - return ERR_PTR(-ENOENT);
166 -EXPORT_SYMBOL(clk_get);
167 +EXPORT_SYMBOL(clk_enable);
169 -void clk_put(struct clk *clk)
170 +void clk_disable(struct clk *clk)
173 + if (unlikely(!clk_good(clk)))
179 -EXPORT_SYMBOL(clk_put);
180 +EXPORT_SYMBOL(clk_disable);
182 -int clk_enable(struct clk *clk)
183 +int clk_activate(struct clk *clk)
187 + if (unlikely(!clk_good(clk)))
191 + return clk->activate(clk);
195 -EXPORT_SYMBOL(clk_enable);
196 +EXPORT_SYMBOL(clk_activate);
198 -void clk_disable(struct clk *clk)
199 +void clk_deactivate(struct clk *clk)
202 + if (unlikely(!clk_good(clk)))
205 + if (clk->deactivate)
206 + clk->deactivate(clk);
208 -EXPORT_SYMBOL(clk_disable);
209 +EXPORT_SYMBOL(clk_deactivate);
211 static inline u32 ltq_get_counter_resolution(void)
213 @@ -126,7 +136,7 @@ void __init plat_time_init(void)
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
230 -extern void clk_init(void);
231 +#include <linux/clkdev.h>
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);
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
261 + struct clk_lookup cl;
262 + unsigned long rate;
263 + unsigned long (*get_rate) (void);
264 + unsigned int module;
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);
273 +extern void clkdev_add_static(unsigned long cpu, unsigned long fpi,
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);
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);
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)
292 ltq_soc_detect(&soc_info);
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';