]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
clocksource: sirf: Remove hard-coded clock rate
authorYanchang Li <yl22@csr.com>
Tue, 11 Nov 2014 12:42:52 +0000 (20:42 +0800)
committerDaniel Lezcano <daniel.lezcano@linaro.org>
Wed, 19 Nov 2014 10:19:20 +0000 (11:19 +0100)
The customers may want to adjust the whole PLL and dividers according to
different user scenerios, and this causes the parent clock of sirf clocksource
not be divided exactly by the current hard-coded 1MHz clock rate.
This patch removes the hard-coded rate and makes the clocksource driver more
adaptive to the external changes.

Signed-off-by: Yanchang Li <yl22@csr.com>
Signed-off-by: Barry Song <Baohua.Song@csr.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
drivers/clocksource/timer-marco.c

index caf7a20304617f3153b0ea56564d702f2a3c0c42..361a789d4bee9403af6920bb0e6bbb1d22cbe3b5 100644 (file)
@@ -20,8 +20,6 @@
 #include <linux/of_address.h>
 #include <linux/sched_clock.h>
 
-#define MARCO_CLOCK_FREQ 1000000
-
 #define SIRFSOC_TIMER_32COUNTER_0_CTRL                 0x0000
 #define SIRFSOC_TIMER_32COUNTER_1_CTRL                 0x0004
 #define SIRFSOC_TIMER_MATCH_0                          0x0018
@@ -40,6 +38,8 @@
 
 #define SIRFSOC_TIMER_REG_CNT 6
 
+static unsigned long marco_timer_rate;
+
 static const u32 sirfsoc_timer_reg_list[SIRFSOC_TIMER_REG_CNT] = {
        SIRFSOC_TIMER_WATCHDOG_EN,
        SIRFSOC_TIMER_32COUNTER_0_CTRL,
@@ -195,7 +195,7 @@ static int sirfsoc_local_timer_setup(struct clock_event_device *ce)
        ce->rating = 200;
        ce->set_mode = sirfsoc_timer_set_mode;
        ce->set_next_event = sirfsoc_timer_set_next_event;
-       clockevents_calc_mult_shift(ce, MARCO_CLOCK_FREQ, 60);
+       clockevents_calc_mult_shift(ce, marco_timer_rate, 60);
        ce->max_delta_ns = clockevent_delta2ns(-2, ce);
        ce->min_delta_ns = clockevent_delta2ns(2, ce);
        ce->cpumask = cpumask_of(cpu);
@@ -257,7 +257,6 @@ static void __init sirfsoc_clockevent_init(void)
 /* initialize the kernel jiffy timer source */
 static void __init sirfsoc_marco_timer_init(struct device_node *np)
 {
-       unsigned long rate;
        u32 timer_div;
        struct clk *clk;
 
@@ -266,16 +265,12 @@ static void __init sirfsoc_marco_timer_init(struct device_node *np)
 
        BUG_ON(clk_prepare_enable(clk));
 
-       rate = clk_get_rate(clk);
-
-       BUG_ON(rate < MARCO_CLOCK_FREQ);
-       BUG_ON(rate % MARCO_CLOCK_FREQ);
+       marco_timer_rate = clk_get_rate(clk);
 
-       /* Initialize the timer dividers */
-       timer_div = rate / MARCO_CLOCK_FREQ - 1;
-       writel_relaxed(timer_div << 16, sirfsoc_timer_base + SIRFSOC_TIMER_64COUNTER_CTRL);
-       writel_relaxed(timer_div << 16, sirfsoc_timer_base + SIRFSOC_TIMER_32COUNTER_0_CTRL);
-       writel_relaxed(timer_div << 16, sirfsoc_timer_base + SIRFSOC_TIMER_32COUNTER_1_CTRL);
+       /* timer dividers: 0, not divided */
+       writel_relaxed(0, sirfsoc_timer_base + SIRFSOC_TIMER_64COUNTER_CTRL);
+       writel_relaxed(0, sirfsoc_timer_base + SIRFSOC_TIMER_32COUNTER_0_CTRL);
+       writel_relaxed(0, sirfsoc_timer_base + SIRFSOC_TIMER_32COUNTER_1_CTRL);
 
        /* Initialize timer counters to 0 */
        writel_relaxed(0, sirfsoc_timer_base + SIRFSOC_TIMER_64COUNTER_LOAD_LO);
@@ -288,7 +283,7 @@ static void __init sirfsoc_marco_timer_init(struct device_node *np)
        /* Clear all interrupts */
        writel_relaxed(0xFFFF, sirfsoc_timer_base + SIRFSOC_TIMER_INTR_STATUS);
 
-       BUG_ON(clocksource_register_hz(&sirfsoc_clocksource, MARCO_CLOCK_FREQ));
+       BUG_ON(clocksource_register_hz(&sirfsoc_clocksource, marco_timer_rate));
 
        sirfsoc_clockevent_init();
 }