diff options
author | Gabor Juhos <juhosg@openwrt.org> | 2013-08-28 04:41:44 -0400 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2013-09-03 17:22:17 -0400 |
commit | 2310780244d5c3b6cc843d4cc0b63332016678a0 (patch) | |
tree | a5d9acd309caa01f549d4c895687fe91235e2805 /arch/mips | |
parent | 837f036c8ab201965b9fb0f6b743a415f555493f (diff) |
MIPS: ath79: Use a helper function to get system clock rates
The ath79 platform uses similar code to get the
rate of various clocks during init. Separate the
similar code into a new helper function and use
that to avoid code duplication.
Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/5778/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'arch/mips')
-rw-r--r-- | arch/mips/ath79/clock.c | 16 | ||||
-rw-r--r-- | arch/mips/ath79/common.h | 2 | ||||
-rw-r--r-- | arch/mips/ath79/dev-common.c | 10 | ||||
-rw-r--r-- | arch/mips/ath79/setup.c | 8 |
4 files changed, 25 insertions, 11 deletions
diff --git a/arch/mips/ath79/clock.c b/arch/mips/ath79/clock.c index 4378d63bc3ed..c8351b46e566 100644 --- a/arch/mips/ath79/clock.c +++ b/arch/mips/ath79/clock.c | |||
@@ -400,6 +400,22 @@ void __init ath79_clocks_init(void) | |||
400 | (ath79_ref_clk.rate / 1000) % 1000); | 400 | (ath79_ref_clk.rate / 1000) % 1000); |
401 | } | 401 | } |
402 | 402 | ||
403 | unsigned long __init | ||
404 | ath79_get_sys_clk_rate(const char *id) | ||
405 | { | ||
406 | struct clk *clk; | ||
407 | unsigned long rate; | ||
408 | |||
409 | clk = clk_get(NULL, id); | ||
410 | if (IS_ERR(clk)) | ||
411 | panic("unable to get %s clock, err=%d", id, (int) PTR_ERR(clk)); | ||
412 | |||
413 | rate = clk_get_rate(clk); | ||
414 | clk_put(clk); | ||
415 | |||
416 | return rate; | ||
417 | } | ||
418 | |||
403 | /* | 419 | /* |
404 | * Linux clock API | 420 | * Linux clock API |
405 | */ | 421 | */ |
diff --git a/arch/mips/ath79/common.h b/arch/mips/ath79/common.h index 561906c2345e..648d2dafbc56 100644 --- a/arch/mips/ath79/common.h +++ b/arch/mips/ath79/common.h | |||
@@ -21,6 +21,8 @@ | |||
21 | #define ATH79_MEM_SIZE_MAX (128 * 1024 * 1024) | 21 | #define ATH79_MEM_SIZE_MAX (128 * 1024 * 1024) |
22 | 22 | ||
23 | void ath79_clocks_init(void); | 23 | void ath79_clocks_init(void); |
24 | unsigned long ath79_get_sys_clk_rate(const char *id); | ||
25 | |||
24 | void ath79_ddr_wb_flush(unsigned int reg); | 26 | void ath79_ddr_wb_flush(unsigned int reg); |
25 | 27 | ||
26 | void ath79_gpio_function_enable(u32 mask); | 28 | void ath79_gpio_function_enable(u32 mask); |
diff --git a/arch/mips/ath79/dev-common.c b/arch/mips/ath79/dev-common.c index a3a2741d0688..c3b04c929f29 100644 --- a/arch/mips/ath79/dev-common.c +++ b/arch/mips/ath79/dev-common.c | |||
@@ -81,21 +81,19 @@ static struct platform_device ar933x_uart_device = { | |||
81 | 81 | ||
82 | void __init ath79_register_uart(void) | 82 | void __init ath79_register_uart(void) |
83 | { | 83 | { |
84 | struct clk *clk; | 84 | unsigned long uart_clk_rate; |
85 | 85 | ||
86 | clk = clk_get(NULL, "uart"); | 86 | uart_clk_rate = ath79_get_sys_clk_rate("uart"); |
87 | if (IS_ERR(clk)) | ||
88 | panic("unable to get UART clock, err=%ld", PTR_ERR(clk)); | ||
89 | 87 | ||
90 | if (soc_is_ar71xx() || | 88 | if (soc_is_ar71xx() || |
91 | soc_is_ar724x() || | 89 | soc_is_ar724x() || |
92 | soc_is_ar913x() || | 90 | soc_is_ar913x() || |
93 | soc_is_ar934x() || | 91 | soc_is_ar934x() || |
94 | soc_is_qca955x()) { | 92 | soc_is_qca955x()) { |
95 | ath79_uart_data[0].uartclk = clk_get_rate(clk); | 93 | ath79_uart_data[0].uartclk = uart_clk_rate; |
96 | platform_device_register(&ath79_uart_device); | 94 | platform_device_register(&ath79_uart_device); |
97 | } else if (soc_is_ar933x()) { | 95 | } else if (soc_is_ar933x()) { |
98 | ar933x_uart_data.uartclk = clk_get_rate(clk); | 96 | ar933x_uart_data.uartclk = uart_clk_rate; |
99 | platform_device_register(&ar933x_uart_device); | 97 | platform_device_register(&ar933x_uart_device); |
100 | } else { | 98 | } else { |
101 | BUG(); | 99 | BUG(); |
diff --git a/arch/mips/ath79/setup.c b/arch/mips/ath79/setup.c index 80f4ecd42b0d..e3b83456d64e 100644 --- a/arch/mips/ath79/setup.c +++ b/arch/mips/ath79/setup.c | |||
@@ -209,13 +209,11 @@ void __init plat_mem_setup(void) | |||
209 | 209 | ||
210 | void __init plat_time_init(void) | 210 | void __init plat_time_init(void) |
211 | { | 211 | { |
212 | struct clk *clk; | 212 | unsigned long cpu_clk_rate; |
213 | 213 | ||
214 | clk = clk_get(NULL, "cpu"); | 214 | cpu_clk_rate = ath79_get_sys_clk_rate("cpu"); |
215 | if (IS_ERR(clk)) | ||
216 | panic("unable to get CPU clock, err=%ld", PTR_ERR(clk)); | ||
217 | 215 | ||
218 | mips_hpt_frequency = clk_get_rate(clk) / 2; | 216 | mips_hpt_frequency = cpu_clk_rate / 2; |
219 | } | 217 | } |
220 | 218 | ||
221 | static int __init ath79_setup(void) | 219 | static int __init ath79_setup(void) |