Blackfin: use common code for cycle->nanosecond conversion
authorYi Li <yi.li@analog.com>
Tue, 15 Sep 2009 08:55:47 +0000 (08:55 +0000)
committerMike Frysinger <vapier@gentoo.org>
Tue, 15 Dec 2009 05:13:43 +0000 (00:13 -0500)
No point in redefining things that common code already does for us.  Also
use CYC2NS_SCALE_FACTOR to better reflect reality and for better precision.

Signed-off-by: Yi Li <yi.li@analog.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
arch/blackfin/kernel/time-ts.c

index 2855f0ff865cb031c6abee98bd637de6b546b205..eef528389d2f5836d4ad039dd6642068ff7d9dad 100644 (file)
 
 #define CYC2NS_SCALE_FACTOR 10 /* 2^10, carefully chosen */
 
-static inline unsigned long cyc2ns_scale(unsigned long cpu_khz)
-{
-       return (1000000 << CYC2NS_SCALE_FACTOR) / cpu_khz;
-}
-
-static inline unsigned long long cycles_2_ns(cycle_t cyc, unsigned long cyc2ns_scale)
-{
-       return (cyc * cyc2ns_scale) >> CYC2NS_SCALE_FACTOR;
-}
-
 #if defined(CONFIG_CYCLES_CLOCKSOURCE)
 
-static unsigned long cycles_cyc2ns_scale;
-
 static notrace cycle_t bfin_read_cycles(struct clocksource *cs)
 {
        return __bfin_cycles_off + (get_cycles() << __bfin_cycles_mod);
@@ -70,19 +58,17 @@ static struct clocksource bfin_cs_cycles = {
        .rating         = 400,
        .read           = bfin_read_cycles,
        .mask           = CLOCKSOURCE_MASK(64),
-       .shift          = 22,
+       .shift          = CYC2NS_SCALE_FACTOR,
        .flags          = CLOCK_SOURCE_IS_CONTINUOUS,
 };
 
 static inline unsigned long long bfin_cs_cycles_sched_clock(void)
 {
-       return cycles_2_ns(bfin_read_cycles(&bfin_cs_cycles), cycles_cyc2ns_scale);
+       return cyc2ns(&bfin_cs_cycles, bfin_read_cycles(&bfin_cs_cycles));
 }
 
 static int __init bfin_cs_cycles_init(void)
 {
-       cycles_cyc2ns_scale = cyc2ns_scale(get_cclk() / 1000);
-
        bfin_cs_cycles.mult = \
                clocksource_hz2mult(get_cclk(), bfin_cs_cycles.shift);
 
@@ -97,8 +83,6 @@ static int __init bfin_cs_cycles_init(void)
 
 #ifdef CONFIG_GPTMR0_CLOCKSOURCE
 
-unsigned long gptimer0_cyc2ns_scale;
-
 void __init setup_gptimer0(void)
 {
        disable_gptimers(TIMER0bit);
@@ -121,19 +105,17 @@ static struct clocksource bfin_cs_gptimer0 = {
        .rating         = 350,
        .read           = bfin_read_gptimer0,
        .mask           = CLOCKSOURCE_MASK(32),
-       .shift          = 22,
+       .shift          = CYC2NS_SCALE_FACTOR,
        .flags          = CLOCK_SOURCE_IS_CONTINUOUS,
 };
 
 static inline unsigned long long bfin_cs_gptimer0_sched_clock(void)
 {
-       return cycles_2_ns(bfin_read_TIMER0_COUNTER(), gptimer0_cyc2ns_scale);
+       return cyc2ns(&bfin_cs_gptimer0, bfin_read_TIMER0_COUNTER());
 }
 
 static int __init bfin_cs_gptimer0_init(void)
 {
-       gptimer0_cyc2ns_scale = cyc2ns_scale(get_sclk() / 1000);
-
        setup_gptimer0();
 
        bfin_cs_gptimer0.mult = \