linux-mips
[Top] [All Lists]

[PATCH 3/6] MIPS: ath79: use a helper function to get system clock rates

To: Ralf Baechle <ralf@linux-mips.org>
Subject: [PATCH 3/6] MIPS: ath79: use a helper function to get system clock rates
From: Gabor Juhos <juhosg@openwrt.org>
Date: Wed, 28 Aug 2013 10:41:44 +0200
Cc: linux-mips@linux-mips.org, Gabor Juhos <juhosg@openwrt.org>
In-reply-to: <1377679307-429-1-git-send-email-juhosg@openwrt.org>
List-archive: <http://www.linux-mips.org/archives/linux-mips/>
List-help: <mailto:ecartis@linux-mips.org?Subject=help>
List-id: linux-mips <linux-mips.eddie.linux-mips.org>
List-owner: <mailto:ralf@linux-mips.org>
List-post: <mailto:linux-mips@linux-mips.org>
List-software: Ecartis version 1.0.0
List-subscribe: <mailto:ecartis@linux-mips.org?subject=subscribe%20linux-mips>
List-unsubscribe: <mailto:ecartis@linux-mips.org?subject=unsubscribe%20linux-mips>
Original-recipient: rfc822;linux-mips@linux-mips.org
References: <1377679307-429-1-git-send-email-juhosg@openwrt.org>
Sender: linux-mips-bounce@linux-mips.org
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>
---
 arch/mips/ath79/clock.c      |   16 ++++++++++++++++
 arch/mips/ath79/common.h     |    2 ++
 arch/mips/ath79/dev-common.c |   10 ++++------
 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 4378d63..c8351b4 100644
--- a/arch/mips/ath79/clock.c
+++ b/arch/mips/ath79/clock.c
@@ -400,6 +400,22 @@ void __init ath79_clocks_init(void)
                (ath79_ref_clk.rate / 1000) % 1000);
 }
 
+unsigned long __init
+ath79_get_sys_clk_rate(const char *id)
+{
+       struct clk *clk;
+       unsigned long rate;
+
+       clk = clk_get(NULL, id);
+       if (IS_ERR(clk))
+               panic("unable to get %s clock, err=%d", id, (int) PTR_ERR(clk));
+
+       rate = clk_get_rate(clk);
+       clk_put(clk);
+
+       return rate;
+}
+
 /*
  * Linux clock API
  */
diff --git a/arch/mips/ath79/common.h b/arch/mips/ath79/common.h
index 561906c..648d2da 100644
--- a/arch/mips/ath79/common.h
+++ b/arch/mips/ath79/common.h
@@ -21,6 +21,8 @@
 #define ATH79_MEM_SIZE_MAX     (128 * 1024 * 1024)
 
 void ath79_clocks_init(void);
+unsigned long ath79_get_sys_clk_rate(const char *id);
+
 void ath79_ddr_wb_flush(unsigned int reg);
 
 void ath79_gpio_function_enable(u32 mask);
diff --git a/arch/mips/ath79/dev-common.c b/arch/mips/ath79/dev-common.c
index a3a2741..c3b04c9 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 = {
 
 void __init ath79_register_uart(void)
 {
-       struct clk *clk;
+       unsigned long uart_clk_rate;
 
-       clk = clk_get(NULL, "uart");
-       if (IS_ERR(clk))
-               panic("unable to get UART clock, err=%ld", PTR_ERR(clk));
+       uart_clk_rate = ath79_get_sys_clk_rate("uart");
 
        if (soc_is_ar71xx() ||
            soc_is_ar724x() ||
            soc_is_ar913x() ||
            soc_is_ar934x() ||
            soc_is_qca955x()) {
-               ath79_uart_data[0].uartclk = clk_get_rate(clk);
+               ath79_uart_data[0].uartclk = uart_clk_rate;
                platform_device_register(&ath79_uart_device);
        } else if (soc_is_ar933x()) {
-               ar933x_uart_data.uartclk = clk_get_rate(clk);
+               ar933x_uart_data.uartclk = uart_clk_rate;
                platform_device_register(&ar933x_uart_device);
        } else {
                BUG();
diff --git a/arch/mips/ath79/setup.c b/arch/mips/ath79/setup.c
index 80f4ecd..e3b8345 100644
--- a/arch/mips/ath79/setup.c
+++ b/arch/mips/ath79/setup.c
@@ -209,13 +209,11 @@ void __init plat_mem_setup(void)
 
 void __init plat_time_init(void)
 {
-       struct clk *clk;
+       unsigned long cpu_clk_rate;
 
-       clk = clk_get(NULL, "cpu");
-       if (IS_ERR(clk))
-               panic("unable to get CPU clock, err=%ld", PTR_ERR(clk));
+       cpu_clk_rate = ath79_get_sys_clk_rate("cpu");
 
-       mips_hpt_frequency = clk_get_rate(clk) / 2;
+       mips_hpt_frequency = cpu_clk_rate / 2;
 }
 
 static int __init ath79_setup(void)
-- 
1.7.10

<Prev in Thread] Current Thread [Next in Thread>