diff options
author | Gabor Juhos <juhosg@openwrt.org> | 2013-08-28 04:41:47 -0400 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2013-09-03 17:22:18 -0400 |
commit | 2c4f1ac5623750e715ae2a5fc7e0569999b9bfc5 (patch) | |
tree | 597a3bd6c681e40174abdafb82ad13e472957753 | |
parent | 6612a6885b47e73a55d159e5aa4654de89fbfc29 (diff) |
MIPS: ath79: Switch to the clkdev framework
The ath79 code uses static clock devices and
provides its own clk_{get,put} implementations.
Change the code to use dynamically allocated
clock devices and register the clocks within
the clkdev framework.
Additionally, remove the local clk_{get,put}
implementation. The clkdev framework has a
common implementation of those.
Also move the call of ath79_clock_init() from
plat_mem_init() to plat_time_init(). Otherwise
it would not be possible to use memory allocation
functions from ath79clock_init() becasuse the
memory subsystem is not yet initialized when
plat_mem_init() runs.
Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/5780/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
-rw-r--r-- | arch/mips/Kconfig | 1 | ||||
-rw-r--r-- | arch/mips/ath79/clock.c | 123 | ||||
-rw-r--r-- | arch/mips/ath79/setup.c | 3 |
3 files changed, 55 insertions, 72 deletions
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig index fdaf6280a39b..24727a082e19 100644 --- a/arch/mips/Kconfig +++ b/arch/mips/Kconfig | |||
@@ -95,6 +95,7 @@ config ATH79 | |||
95 | select CSRC_R4K | 95 | select CSRC_R4K |
96 | select DMA_NONCOHERENT | 96 | select DMA_NONCOHERENT |
97 | select HAVE_CLK | 97 | select HAVE_CLK |
98 | select CLKDEV_LOOKUP | ||
98 | select IRQ_CPU | 99 | select IRQ_CPU |
99 | select MIPS_MACHINE | 100 | select MIPS_MACHINE |
100 | select SYS_HAS_CPU_MIPS32_R2 | 101 | select SYS_HAS_CPU_MIPS32_R2 |
diff --git a/arch/mips/ath79/clock.c b/arch/mips/ath79/clock.c index 375cb77e7639..26479f437675 100644 --- a/arch/mips/ath79/clock.c +++ b/arch/mips/ath79/clock.c | |||
@@ -16,6 +16,7 @@ | |||
16 | #include <linux/init.h> | 16 | #include <linux/init.h> |
17 | #include <linux/err.h> | 17 | #include <linux/err.h> |
18 | #include <linux/clk.h> | 18 | #include <linux/clk.h> |
19 | #include <linux/clkdev.h> | ||
19 | 20 | ||
20 | #include <asm/div64.h> | 21 | #include <asm/div64.h> |
21 | 22 | ||
@@ -31,12 +32,21 @@ struct clk { | |||
31 | unsigned long rate; | 32 | unsigned long rate; |
32 | }; | 33 | }; |
33 | 34 | ||
34 | static struct clk ath79_ref_clk; | 35 | static void __init ath79_add_sys_clkdev(const char *id, unsigned long rate) |
35 | static struct clk ath79_cpu_clk; | 36 | { |
36 | static struct clk ath79_ddr_clk; | 37 | struct clk *clk; |
37 | static struct clk ath79_ahb_clk; | 38 | int err; |
38 | static struct clk ath79_wdt_clk; | 39 | |
39 | static struct clk ath79_uart_clk; | 40 | clk = kzalloc(sizeof(*clk), GFP_KERNEL); |
41 | if (!clk) | ||
42 | panic("failed to allocate %s clock structure", id); | ||
43 | |||
44 | clk->rate = rate; | ||
45 | |||
46 | err = clk_register_clkdev(clk, id, NULL); | ||
47 | if (err) | ||
48 | panic("unable to register %s clock device", id); | ||
49 | } | ||
40 | 50 | ||
41 | static void __init ar71xx_clocks_init(void) | 51 | static void __init ar71xx_clocks_init(void) |
42 | { | 52 | { |
@@ -64,13 +74,13 @@ static void __init ar71xx_clocks_init(void) | |||
64 | div = (((pll >> AR71XX_AHB_DIV_SHIFT) & AR71XX_AHB_DIV_MASK) + 1) * 2; | 74 | div = (((pll >> AR71XX_AHB_DIV_SHIFT) & AR71XX_AHB_DIV_MASK) + 1) * 2; |
65 | ahb_rate = cpu_rate / div; | 75 | ahb_rate = cpu_rate / div; |
66 | 76 | ||
67 | ath79_ref_clk.rate = ref_rate; | 77 | ath79_add_sys_clkdev("ref", ref_rate); |
68 | ath79_cpu_clk.rate = cpu_rate; | 78 | ath79_add_sys_clkdev("cpu", cpu_rate); |
69 | ath79_ddr_clk.rate = ddr_rate; | 79 | ath79_add_sys_clkdev("ddr", ddr_rate); |
70 | ath79_ahb_clk.rate = ahb_rate; | 80 | ath79_add_sys_clkdev("ahb", ahb_rate); |
71 | 81 | ||
72 | ath79_wdt_clk.rate = ath79_ahb_clk.rate; | 82 | clk_add_alias("wdt", NULL, "ahb", NULL); |
73 | ath79_uart_clk.rate = ath79_ahb_clk.rate; | 83 | clk_add_alias("uart", NULL, "ahb", NULL); |
74 | } | 84 | } |
75 | 85 | ||
76 | static void __init ar724x_clocks_init(void) | 86 | static void __init ar724x_clocks_init(void) |
@@ -100,13 +110,13 @@ static void __init ar724x_clocks_init(void) | |||
100 | div = (((pll >> AR724X_AHB_DIV_SHIFT) & AR724X_AHB_DIV_MASK) + 1) * 2; | 110 | div = (((pll >> AR724X_AHB_DIV_SHIFT) & AR724X_AHB_DIV_MASK) + 1) * 2; |
101 | ahb_rate = cpu_rate / div; | 111 | ahb_rate = cpu_rate / div; |
102 | 112 | ||
103 | ath79_ref_clk.rate = ref_rate; | 113 | ath79_add_sys_clkdev("ref", ref_rate); |
104 | ath79_cpu_clk.rate = cpu_rate; | 114 | ath79_add_sys_clkdev("cpu", cpu_rate); |
105 | ath79_ddr_clk.rate = ddr_rate; | 115 | ath79_add_sys_clkdev("ddr", ddr_rate); |
106 | ath79_ahb_clk.rate = ahb_rate; | 116 | ath79_add_sys_clkdev("ahb", ahb_rate); |
107 | 117 | ||
108 | ath79_wdt_clk.rate = ath79_ahb_clk.rate; | 118 | clk_add_alias("wdt", NULL, "ahb", NULL); |
109 | ath79_uart_clk.rate = ath79_ahb_clk.rate; | 119 | clk_add_alias("uart", NULL, "ahb", NULL); |
110 | } | 120 | } |
111 | 121 | ||
112 | static void __init ar913x_clocks_init(void) | 122 | static void __init ar913x_clocks_init(void) |
@@ -133,13 +143,13 @@ static void __init ar913x_clocks_init(void) | |||
133 | div = (((pll >> AR913X_AHB_DIV_SHIFT) & AR913X_AHB_DIV_MASK) + 1) * 2; | 143 | div = (((pll >> AR913X_AHB_DIV_SHIFT) & AR913X_AHB_DIV_MASK) + 1) * 2; |
134 | ahb_rate = cpu_rate / div; | 144 | ahb_rate = cpu_rate / div; |
135 | 145 | ||
136 | ath79_ref_clk.rate = ref_rate; | 146 | ath79_add_sys_clkdev("ref", ref_rate); |
137 | ath79_cpu_clk.rate = cpu_rate; | 147 | ath79_add_sys_clkdev("cpu", cpu_rate); |
138 | ath79_ddr_clk.rate = ddr_rate; | 148 | ath79_add_sys_clkdev("ddr", ddr_rate); |
139 | ath79_ahb_clk.rate = ahb_rate; | 149 | ath79_add_sys_clkdev("ahb", ahb_rate); |
140 | 150 | ||
141 | ath79_wdt_clk.rate = ath79_ahb_clk.rate; | 151 | clk_add_alias("wdt", NULL, "ahb", NULL); |
142 | ath79_uart_clk.rate = ath79_ahb_clk.rate; | 152 | clk_add_alias("uart", NULL, "ahb", NULL); |
143 | } | 153 | } |
144 | 154 | ||
145 | static void __init ar933x_clocks_init(void) | 155 | static void __init ar933x_clocks_init(void) |
@@ -195,13 +205,13 @@ static void __init ar933x_clocks_init(void) | |||
195 | ahb_rate = freq / t; | 205 | ahb_rate = freq / t; |
196 | } | 206 | } |
197 | 207 | ||
198 | ath79_ref_clk.rate = ref_rate; | 208 | ath79_add_sys_clkdev("ref", ref_rate); |
199 | ath79_cpu_clk.rate = cpu_rate; | 209 | ath79_add_sys_clkdev("cpu", cpu_rate); |
200 | ath79_ddr_clk.rate = ddr_rate; | 210 | ath79_add_sys_clkdev("ddr", ddr_rate); |
201 | ath79_ahb_clk.rate = ahb_rate; | 211 | ath79_add_sys_clkdev("ahb", ahb_rate); |
202 | 212 | ||
203 | ath79_wdt_clk.rate = ath79_ahb_clk.rate; | 213 | clk_add_alias("wdt", NULL, "ahb", NULL); |
204 | ath79_uart_clk.rate = ath79_ref_clk.rate; | 214 | clk_add_alias("uart", NULL, "ref", NULL); |
205 | } | 215 | } |
206 | 216 | ||
207 | static u32 __init ar934x_get_pll_freq(u32 ref, u32 ref_div, u32 nint, u32 nfrac, | 217 | static u32 __init ar934x_get_pll_freq(u32 ref, u32 ref_div, u32 nint, u32 nfrac, |
@@ -329,13 +339,13 @@ static void __init ar934x_clocks_init(void) | |||
329 | else | 339 | else |
330 | ahb_rate = cpu_pll / (postdiv + 1); | 340 | ahb_rate = cpu_pll / (postdiv + 1); |
331 | 341 | ||
332 | ath79_ref_clk.rate = ref_rate; | 342 | ath79_add_sys_clkdev("ref", ref_rate); |
333 | ath79_cpu_clk.rate = cpu_rate; | 343 | ath79_add_sys_clkdev("cpu", cpu_rate); |
334 | ath79_ddr_clk.rate = ddr_rate; | 344 | ath79_add_sys_clkdev("ddr", ddr_rate); |
335 | ath79_ahb_clk.rate = ahb_rate; | 345 | ath79_add_sys_clkdev("ahb", ahb_rate); |
336 | 346 | ||
337 | ath79_wdt_clk.rate = ath79_ref_clk.rate; | 347 | clk_add_alias("wdt", NULL, "ref", NULL); |
338 | ath79_uart_clk.rate = ath79_ref_clk.rate; | 348 | clk_add_alias("uart", NULL, "ref", NULL); |
339 | 349 | ||
340 | iounmap(dpll_base); | 350 | iounmap(dpll_base); |
341 | } | 351 | } |
@@ -416,13 +426,13 @@ static void __init qca955x_clocks_init(void) | |||
416 | else | 426 | else |
417 | ahb_rate = cpu_pll / (postdiv + 1); | 427 | ahb_rate = cpu_pll / (postdiv + 1); |
418 | 428 | ||
419 | ath79_ref_clk.rate = ref_rate; | 429 | ath79_add_sys_clkdev("ref", ref_rate); |
420 | ath79_cpu_clk.rate = cpu_rate; | 430 | ath79_add_sys_clkdev("cpu", cpu_rate); |
421 | ath79_ddr_clk.rate = ddr_rate; | 431 | ath79_add_sys_clkdev("ddr", ddr_rate); |
422 | ath79_ahb_clk.rate = ahb_rate; | 432 | ath79_add_sys_clkdev("ahb", ahb_rate); |
423 | 433 | ||
424 | ath79_wdt_clk.rate = ath79_ref_clk.rate; | 434 | clk_add_alias("wdt", NULL, "ref", NULL); |
425 | ath79_uart_clk.rate = ath79_ref_clk.rate; | 435 | clk_add_alias("uart", NULL, "ref", NULL); |
426 | } | 436 | } |
427 | 437 | ||
428 | void __init ath79_clocks_init(void) | 438 | void __init ath79_clocks_init(void) |
@@ -462,30 +472,6 @@ ath79_get_sys_clk_rate(const char *id) | |||
462 | /* | 472 | /* |
463 | * Linux clock API | 473 | * Linux clock API |
464 | */ | 474 | */ |
465 | struct clk *clk_get(struct device *dev, const char *id) | ||
466 | { | ||
467 | if (!strcmp(id, "ref")) | ||
468 | return &ath79_ref_clk; | ||
469 | |||
470 | if (!strcmp(id, "cpu")) | ||
471 | return &ath79_cpu_clk; | ||
472 | |||
473 | if (!strcmp(id, "ddr")) | ||
474 | return &ath79_ddr_clk; | ||
475 | |||
476 | if (!strcmp(id, "ahb")) | ||
477 | return &ath79_ahb_clk; | ||
478 | |||
479 | if (!strcmp(id, "wdt")) | ||
480 | return &ath79_wdt_clk; | ||
481 | |||
482 | if (!strcmp(id, "uart")) | ||
483 | return &ath79_uart_clk; | ||
484 | |||
485 | return ERR_PTR(-ENOENT); | ||
486 | } | ||
487 | EXPORT_SYMBOL(clk_get); | ||
488 | |||
489 | int clk_enable(struct clk *clk) | 475 | int clk_enable(struct clk *clk) |
490 | { | 476 | { |
491 | return 0; | 477 | return 0; |
@@ -502,8 +488,3 @@ unsigned long clk_get_rate(struct clk *clk) | |||
502 | return clk->rate; | 488 | return clk->rate; |
503 | } | 489 | } |
504 | EXPORT_SYMBOL(clk_get_rate); | 490 | EXPORT_SYMBOL(clk_get_rate); |
505 | |||
506 | void clk_put(struct clk *clk) | ||
507 | { | ||
508 | } | ||
509 | EXPORT_SYMBOL(clk_put); | ||
diff --git a/arch/mips/ath79/setup.c b/arch/mips/ath79/setup.c index c02d3459b3ea..64807a4809d0 100644 --- a/arch/mips/ath79/setup.c +++ b/arch/mips/ath79/setup.c | |||
@@ -200,7 +200,6 @@ void __init plat_mem_setup(void) | |||
200 | 200 | ||
201 | ath79_detect_sys_type(); | 201 | ath79_detect_sys_type(); |
202 | detect_memory_region(0, ATH79_MEM_SIZE_MIN, ATH79_MEM_SIZE_MAX); | 202 | detect_memory_region(0, ATH79_MEM_SIZE_MIN, ATH79_MEM_SIZE_MAX); |
203 | ath79_clocks_init(); | ||
204 | 203 | ||
205 | _machine_restart = ath79_restart; | 204 | _machine_restart = ath79_restart; |
206 | _machine_halt = ath79_halt; | 205 | _machine_halt = ath79_halt; |
@@ -214,6 +213,8 @@ void __init plat_time_init(void) | |||
214 | unsigned long ddr_clk_rate; | 213 | unsigned long ddr_clk_rate; |
215 | unsigned long ref_clk_rate; | 214 | unsigned long ref_clk_rate; |
216 | 215 | ||
216 | ath79_clocks_init(); | ||
217 | |||
217 | cpu_clk_rate = ath79_get_sys_clk_rate("cpu"); | 218 | cpu_clk_rate = ath79_get_sys_clk_rate("cpu"); |
218 | ahb_clk_rate = ath79_get_sys_clk_rate("ahb"); | 219 | ahb_clk_rate = ath79_get_sys_clk_rate("ahb"); |
219 | ddr_clk_rate = ath79_get_sys_clk_rate("ddr"); | 220 | ddr_clk_rate = ath79_get_sys_clk_rate("ddr"); |